Skip to content

Commit

Permalink
attach custom tool client
Browse files Browse the repository at this point in the history
  • Loading branch information
carenthomas committed Jan 14, 2025
1 parent 4841ace commit 172255b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
src/wrapper
src/index.ts
37 changes: 0 additions & 37 deletions src/api/resources/tools/client/wrapper/Client.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/api/resources/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { Tools as ToolsType } from "./client/Client";
export { ToolsExtended as Tools } from "./client/wrapper/Client";
export * from "./client";
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
11 changes: 11 additions & 0 deletions src/wrapper/Client.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}
34 changes: 34 additions & 0 deletions src/wrapper/ToolsClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import dedent from 'dedent';

Check failure on line 1 in src/wrapper/ToolsClient.ts

View workflow job for this annotation

GitHub Actions / compile

Could not find a declaration file for module 'dedent'. '/home/runner/work/letta-node/letta-node/node_modules/dedent/dist/dedent.js' implicitly has an 'any' type.

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<Letta.LettaSchemasToolTool> {
const toolCreateRequest: Letta.ToolCreate = {
...request,
sourceCode: dedent(request.func.toString()),
};
return this.create(toolCreateRequest, requestOptions);
}
}

export interface ToolCreateFromFunction extends Omit<Letta.ToolCreate, "sourceCode"> {
func: Function;
}

0 comments on commit 172255b

Please sign in to comment.