Skip to content

Commit

Permalink
Add custom Tool.createFromFunc method
Browse files Browse the repository at this point in the history
  • Loading branch information
carenthomas committed Jan 14, 2025
1 parent 4860dda commit 4841ace
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Specify files that shouldn't be modified by Fern

tests/custom.test.ts
.github/workflows/ci.yml
.github/workflows/ci.yml
src/api/resources/tools/client/wrapper/Client.ts
src/api/resources/tools/index.ts
37 changes: 37 additions & 0 deletions src/api/resources/tools/client/wrapper/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import prettier from "prettier";

Check failure on line 1 in src/api/resources/tools/client/wrapper/Client.ts

View workflow job for this annotation

GitHub Actions / compile

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

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<LettaSchemasToolTool> {
const toolCreateRequest: ToolCreate = {
...request,
sourceCode: prettier.format(request.func.toString(), {
parser: "typescript",
tabWidth: 4,
}),
};
return this.create(toolCreateRequest, requestOptions);
}
}

export interface ToolCreateFromFunc extends Omit<ToolCreate, "sourceCode"> {
func: (...args: any[]) => any;
}
3 changes: 2 additions & 1 deletion src/api/resources/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./client";
export type { Tools as ToolsType } from "./client/Client";
export { ToolsExtended as Tools } from "./client/wrapper/Client";

0 comments on commit 4841ace

Please sign in to comment.