-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom Tool.createFromFunc method
- Loading branch information
1 parent
4860dda
commit 4841ace
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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<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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |