diff --git a/.fernignore b/.fernignore index 7677897..5ff3f7c 100644 --- a/.fernignore +++ b/.fernignore @@ -2,5 +2,5 @@ tests/custom.test.ts .github/workflows/ci.yml -src/api/resources/tools/client/wrapper/Client.ts -src/api/resources/tools/index.ts \ No newline at end of file +src/wrapper +src/index.ts \ No newline at end of file diff --git a/src/api/resources/tools/client/wrapper/Client.ts b/src/api/resources/tools/client/wrapper/Client.ts deleted file mode 100644 index 3042a5a..0000000 --- a/src/api/resources/tools/client/wrapper/Client.ts +++ /dev/null @@ -1,37 +0,0 @@ -import prettier from "prettier"; - -import { Tools as ToolsBase } from "../Client"; -import { ToolCreate, LettaSchemasToolTool } from "../../../../types"; - -export class ToolsExtended extends ToolsBase { - /** - * Create a new tool - * - * @param {ToolCreateFromFunc} request - * @param {Tools.RequestOptions} requestOptions - Request-specific configuration. - * - * @throws {@link Letta.UnprocessableEntityError} - * - * @example - * await client.tools.create({ - * sourceCode: "source_code" - * }) - */ - public async createFromFunc( - request: ToolCreateFromFunc, - requestOptions?: ToolsBase.RequestOptions - ): Promise { - const toolCreateRequest: ToolCreate = { - ...request, - sourceCode: prettier.format(request.func.toString(), { - parser: "typescript", - tabWidth: 4, - }), - }; - return this.create(toolCreateRequest, requestOptions); - } -} - -export interface ToolCreateFromFunc extends Omit { - func: (...args: any[]) => any; -} diff --git a/src/api/resources/tools/index.ts b/src/api/resources/tools/index.ts index cb607d2..6c5a93f 100644 --- a/src/api/resources/tools/index.ts +++ b/src/api/resources/tools/index.ts @@ -1,2 +1 @@ -export type { Tools as ToolsType } from "./client/Client"; -export { ToolsExtended as Tools } from "./client/wrapper/Client"; +export * from "./client"; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5731679..d1a0e99 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ export * as Letta from "./api"; -export { LettaClient } from "./Client"; +export { LettaClient } from "./wrapper/Client"; export { LettaEnvironment } from "./environments"; export { LettaError, LettaTimeoutError } from "./errors"; diff --git a/src/wrapper/Client.ts b/src/wrapper/Client.ts new file mode 100644 index 0000000..0e572f6 --- /dev/null +++ b/src/wrapper/Client.ts @@ -0,0 +1,11 @@ +import { LettaClient as FernClient } from "../Client"; +import { Tools } from "./ToolsClient"; + +export class LettaClient extends FernClient { + + protected _tools: Tools | undefined; + + public get tools(): Tools { + return (this._tools ??= new Tools(this._options)); + } +} diff --git a/src/wrapper/ToolsClient.ts b/src/wrapper/ToolsClient.ts new file mode 100644 index 0000000..ed522f9 --- /dev/null +++ b/src/wrapper/ToolsClient.ts @@ -0,0 +1,34 @@ +import dedent from 'dedent'; + +import { Letta } from ".."; +import { Tools as FernTools } from "../api/resources/tools/client/Client"; + +export class Tools extends FernTools { + /** + * Create a new tool from a function + * + * @param {ToolCreateFromFunction} request + * @param {Tools.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Letta.UnprocessableEntityError} + * + * @example + * await client.tools.create({ + * func: tool_implementation + * }) + */ + public async createFromFunction( + request: ToolCreateFromFunction, + requestOptions?: FernTools.RequestOptions + ): Promise { + const toolCreateRequest: Letta.ToolCreate = { + ...request, + sourceCode: dedent(request.func.toString()), + }; + return this.create(toolCreateRequest, requestOptions); + } +} + +export interface ToolCreateFromFunction extends Omit { + func: Function; +} \ No newline at end of file