-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fbfcdd
commit dd58085
Showing
8 changed files
with
240 additions
and
202 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,12 +1,19 @@ | ||
import type { CoreTool } from "../tool" | ||
import type { CoreTool } from '../tool'; | ||
|
||
// Creates a safe execution ground for the code | ||
export const createFunction = (tools: Record<string, CoreTool>, code: string) => { | ||
const data = Object.entries(tools).reduce((acc, [key, value]) => ({ ...acc, [key]: value.execute }), {}) | ||
export const createFunction = ( | ||
tools: Record<string, CoreTool>, | ||
code: string, | ||
) => { | ||
const data = Object.entries(tools).reduce( | ||
(acc, [key, value]) => ({ ...acc, [key]: value.execute }), | ||
{}, | ||
); | ||
|
||
return async () => await new Function(main(code)).apply(data, []) | ||
} | ||
return async () => await new Function(main(code)).apply(data, []); | ||
}; | ||
|
||
// Don't remove this. | ||
// This is the only reason why async and sync function works inside `new Function()` | ||
const main = (code:string) => `const main = async () => {\n${code}\n}\nreturn main()` | ||
const main = (code: string) => | ||
`const main = async () => {\n${code}\n}\nreturn main()`; |
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
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
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 @@ | ||
export { generateCode as experimental_generateCode } from './generate-code'; | ||
export { generateCode as experimental_generateCode } from './generate-code'; |
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
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,9 +1,9 @@ | ||
import type { ZodSchema } from "zod" | ||
import { printNode, zodToTs } from "zod-to-ts" | ||
import type { ZodSchema } from 'zod'; | ||
import { printNode, zodToTs } from 'zod-to-ts'; | ||
|
||
// This function is used to convert zod schema to type definition string | ||
export const generateZodTypeString = (zod: ZodSchema, K: string) => { | ||
const { node: type } = zodToTs(zod, K as string); | ||
const typeString = printNode(type); | ||
return typeString | ||
}; | ||
return typeString; | ||
}; |
Oops, something went wrong.