freestyle-sandboxes 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/index.cjs +27 -23
- package/dist/ai/index.d.cts +9 -1
- package/dist/ai/index.d.mts +9 -1
- package/dist/ai/index.mjs +26 -24
- package/dist/mastra/index.cjs +37 -0
- package/dist/mastra/index.d.cts +45 -0
- package/dist/mastra/index.d.mts +45 -0
- package/dist/mastra/index.mjs +35 -0
- package/package.json +12 -1
- package/src/ai/index.ts +33 -29
- package/src/mastra/index.ts +38 -0
package/dist/ai/index.cjs
CHANGED
|
@@ -5,6 +5,29 @@ var ai = require('ai');
|
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
require('@hey-api/client-fetch');
|
|
7
7
|
|
|
8
|
+
const executeCodeSchema = zod.z.object({
|
|
9
|
+
script: zod.z.string().describe(`
|
|
10
|
+
The JavaScript or TypeScript script to execute, must be in the format of:
|
|
11
|
+
|
|
12
|
+
import { someModule } from "someModule";
|
|
13
|
+
export default () => {
|
|
14
|
+
... your code here ...
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
or for async functions:
|
|
19
|
+
|
|
20
|
+
import { someModule } from "someModule";
|
|
21
|
+
|
|
22
|
+
export default async () => {
|
|
23
|
+
... your code here ...
|
|
24
|
+
return output;
|
|
25
|
+
}
|
|
26
|
+
`)
|
|
27
|
+
});
|
|
28
|
+
const executeCodeDescription = (envVars, nodeModules) => `Execute a JavaScript or TypeScript script.
|
|
29
|
+
${envVars.length > 0 ? `You can use the following environment variables: ${envVars}` : ""}
|
|
30
|
+
${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`;
|
|
8
31
|
const executeTool = (config) => {
|
|
9
32
|
const api = new index.FreestyleSandboxes({
|
|
10
33
|
...config
|
|
@@ -12,29 +35,8 @@ const executeTool = (config) => {
|
|
|
12
35
|
const envVars = Object.keys(config.envVars ?? {}).join(", ");
|
|
13
36
|
const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
|
|
14
37
|
return ai.tool({
|
|
15
|
-
description:
|
|
16
|
-
|
|
17
|
-
${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`,
|
|
18
|
-
parameters: zod.z.object({
|
|
19
|
-
script: zod.z.string().describe(`
|
|
20
|
-
The JavaScript or TypeScript script to execute, must be in the format of:
|
|
21
|
-
|
|
22
|
-
import { someModule } from "someModule";
|
|
23
|
-
export default () => {
|
|
24
|
-
... your code here ...
|
|
25
|
-
return output;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
or for async functions:
|
|
29
|
-
|
|
30
|
-
import { someModule } from "someModule";
|
|
31
|
-
|
|
32
|
-
export default async () => {
|
|
33
|
-
... your code here ...
|
|
34
|
-
return output;
|
|
35
|
-
}
|
|
36
|
-
`)
|
|
37
|
-
}),
|
|
38
|
+
description: executeCodeDescription(envVars, nodeModules),
|
|
39
|
+
parameters: executeCodeSchema,
|
|
38
40
|
execute: async ({ script }) => {
|
|
39
41
|
try {
|
|
40
42
|
const res = await api.executeScript(script, config);
|
|
@@ -92,4 +94,6 @@ Error: ${e.message}`;
|
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
exports.deployWebTool = deployWebTool;
|
|
97
|
+
exports.executeCodeDescription = executeCodeDescription;
|
|
98
|
+
exports.executeCodeSchema = executeCodeSchema;
|
|
95
99
|
exports.executeTool = executeTool;
|
package/dist/ai/index.d.cts
CHANGED
|
@@ -2,6 +2,14 @@ import * as ai from 'ai';
|
|
|
2
2
|
import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BtK6PMQy.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
declare const executeCodeSchema: z.ZodObject<{
|
|
6
|
+
script: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
script?: string;
|
|
9
|
+
}, {
|
|
10
|
+
script?: string;
|
|
11
|
+
}>;
|
|
12
|
+
declare const executeCodeDescription: (envVars: string, nodeModules: string) => string;
|
|
5
13
|
/**
|
|
6
14
|
* Execute a JavaScript or TypeScript script
|
|
7
15
|
*
|
|
@@ -42,4 +50,4 @@ declare const deployWebTool: (config: FreestyleExecuteScriptParamsConfiguration
|
|
|
42
50
|
}, options: ai.ToolExecutionOptions) => PromiseLike<string | FreestyleDeployWebSuccessResponse>;
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
export { deployWebTool, executeTool };
|
|
53
|
+
export { deployWebTool, executeCodeDescription, executeCodeSchema, executeTool };
|
package/dist/ai/index.d.mts
CHANGED
|
@@ -2,6 +2,14 @@ import * as ai from 'ai';
|
|
|
2
2
|
import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BtK6PMQy.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
declare const executeCodeSchema: z.ZodObject<{
|
|
6
|
+
script: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
script?: string;
|
|
9
|
+
}, {
|
|
10
|
+
script?: string;
|
|
11
|
+
}>;
|
|
12
|
+
declare const executeCodeDescription: (envVars: string, nodeModules: string) => string;
|
|
5
13
|
/**
|
|
6
14
|
* Execute a JavaScript or TypeScript script
|
|
7
15
|
*
|
|
@@ -42,4 +50,4 @@ declare const deployWebTool: (config: FreestyleExecuteScriptParamsConfiguration
|
|
|
42
50
|
}, options: ai.ToolExecutionOptions) => PromiseLike<string | FreestyleDeployWebSuccessResponse>;
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
export { deployWebTool, executeTool };
|
|
53
|
+
export { deployWebTool, executeCodeDescription, executeCodeSchema, executeTool };
|
package/dist/ai/index.mjs
CHANGED
|
@@ -3,6 +3,29 @@ import { tool } from 'ai';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import '@hey-api/client-fetch';
|
|
5
5
|
|
|
6
|
+
const executeCodeSchema = z.object({
|
|
7
|
+
script: z.string().describe(`
|
|
8
|
+
The JavaScript or TypeScript script to execute, must be in the format of:
|
|
9
|
+
|
|
10
|
+
import { someModule } from "someModule";
|
|
11
|
+
export default () => {
|
|
12
|
+
... your code here ...
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
or for async functions:
|
|
17
|
+
|
|
18
|
+
import { someModule } from "someModule";
|
|
19
|
+
|
|
20
|
+
export default async () => {
|
|
21
|
+
... your code here ...
|
|
22
|
+
return output;
|
|
23
|
+
}
|
|
24
|
+
`)
|
|
25
|
+
});
|
|
26
|
+
const executeCodeDescription = (envVars, nodeModules) => `Execute a JavaScript or TypeScript script.
|
|
27
|
+
${envVars.length > 0 ? `You can use the following environment variables: ${envVars}` : ""}
|
|
28
|
+
${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`;
|
|
6
29
|
const executeTool = (config) => {
|
|
7
30
|
const api = new FreestyleSandboxes({
|
|
8
31
|
...config
|
|
@@ -10,29 +33,8 @@ const executeTool = (config) => {
|
|
|
10
33
|
const envVars = Object.keys(config.envVars ?? {}).join(", ");
|
|
11
34
|
const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
|
|
12
35
|
return tool({
|
|
13
|
-
description:
|
|
14
|
-
|
|
15
|
-
${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`,
|
|
16
|
-
parameters: z.object({
|
|
17
|
-
script: z.string().describe(`
|
|
18
|
-
The JavaScript or TypeScript script to execute, must be in the format of:
|
|
19
|
-
|
|
20
|
-
import { someModule } from "someModule";
|
|
21
|
-
export default () => {
|
|
22
|
-
... your code here ...
|
|
23
|
-
return output;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
or for async functions:
|
|
27
|
-
|
|
28
|
-
import { someModule } from "someModule";
|
|
29
|
-
|
|
30
|
-
export default async () => {
|
|
31
|
-
... your code here ...
|
|
32
|
-
return output;
|
|
33
|
-
}
|
|
34
|
-
`)
|
|
35
|
-
}),
|
|
36
|
+
description: executeCodeDescription(envVars, nodeModules),
|
|
37
|
+
parameters: executeCodeSchema,
|
|
36
38
|
execute: async ({ script }) => {
|
|
37
39
|
try {
|
|
38
40
|
const res = await api.executeScript(script, config);
|
|
@@ -89,4 +91,4 @@ Error: ${e.message}`;
|
|
|
89
91
|
});
|
|
90
92
|
};
|
|
91
93
|
|
|
92
|
-
export { deployWebTool, executeTool };
|
|
94
|
+
export { deployWebTool, executeCodeDescription, executeCodeSchema, executeTool };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@mastra/core');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
var index = require('../ai/index.cjs');
|
|
6
|
+
var index$1 = require('../index.cjs');
|
|
7
|
+
require('ai');
|
|
8
|
+
require('@hey-api/client-fetch');
|
|
9
|
+
|
|
10
|
+
const executeTool = (config) => {
|
|
11
|
+
const description = index.executeCodeDescription(
|
|
12
|
+
Object.keys(config.envVars ?? {}).join(", "),
|
|
13
|
+
Object.keys(config.nodeModules ?? {}).join(", ")
|
|
14
|
+
);
|
|
15
|
+
const client = new index$1.FreestyleSandboxes({
|
|
16
|
+
apiKey: config.apiKey
|
|
17
|
+
});
|
|
18
|
+
return core.createTool({
|
|
19
|
+
id: "Execute a TypeScript or JavaScript Script",
|
|
20
|
+
description,
|
|
21
|
+
inputSchema: index.executeCodeSchema,
|
|
22
|
+
execute: async ({ context: { script } }) => {
|
|
23
|
+
return await client.executeScript(script, config);
|
|
24
|
+
},
|
|
25
|
+
outputSchema: zod.z.object({
|
|
26
|
+
logs: zod.z.array(
|
|
27
|
+
zod.z.object({
|
|
28
|
+
message: zod.z.string(),
|
|
29
|
+
type: zod.z.string()
|
|
30
|
+
})
|
|
31
|
+
),
|
|
32
|
+
result: zod.z.unknown()
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.executeTool = executeTool;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as _mastra_core from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { F as FreestyleExecuteScriptParamsConfiguration } from '../types.gen-BtK6PMQy.js';
|
|
4
|
+
|
|
5
|
+
declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
}) => _mastra_core.Tool<"Execute a TypeScript or JavaScript Script", z.ZodObject<{
|
|
8
|
+
script: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
script?: string;
|
|
11
|
+
}, {
|
|
12
|
+
script?: string;
|
|
13
|
+
}>, z.ZodObject<{
|
|
14
|
+
logs: z.ZodArray<z.ZodObject<{
|
|
15
|
+
message: z.ZodString;
|
|
16
|
+
type: z.ZodString;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
message?: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
}, {
|
|
21
|
+
message?: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
}>, "many">;
|
|
24
|
+
result: z.ZodUnknown;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
logs?: {
|
|
27
|
+
message?: string;
|
|
28
|
+
type?: string;
|
|
29
|
+
}[];
|
|
30
|
+
result?: unknown;
|
|
31
|
+
}, {
|
|
32
|
+
logs?: {
|
|
33
|
+
message?: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
}[];
|
|
36
|
+
result?: unknown;
|
|
37
|
+
}>, _mastra_core.ToolExecutionContext<z.ZodObject<{
|
|
38
|
+
script: z.ZodString;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
script?: string;
|
|
41
|
+
}, {
|
|
42
|
+
script?: string;
|
|
43
|
+
}>, _mastra_core.WorkflowContext<any>>>;
|
|
44
|
+
|
|
45
|
+
export { executeTool };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as _mastra_core from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { F as FreestyleExecuteScriptParamsConfiguration } from '../types.gen-BtK6PMQy.js';
|
|
4
|
+
|
|
5
|
+
declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
}) => _mastra_core.Tool<"Execute a TypeScript or JavaScript Script", z.ZodObject<{
|
|
8
|
+
script: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
script?: string;
|
|
11
|
+
}, {
|
|
12
|
+
script?: string;
|
|
13
|
+
}>, z.ZodObject<{
|
|
14
|
+
logs: z.ZodArray<z.ZodObject<{
|
|
15
|
+
message: z.ZodString;
|
|
16
|
+
type: z.ZodString;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
message?: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
}, {
|
|
21
|
+
message?: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
}>, "many">;
|
|
24
|
+
result: z.ZodUnknown;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
logs?: {
|
|
27
|
+
message?: string;
|
|
28
|
+
type?: string;
|
|
29
|
+
}[];
|
|
30
|
+
result?: unknown;
|
|
31
|
+
}, {
|
|
32
|
+
logs?: {
|
|
33
|
+
message?: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
}[];
|
|
36
|
+
result?: unknown;
|
|
37
|
+
}>, _mastra_core.ToolExecutionContext<z.ZodObject<{
|
|
38
|
+
script: z.ZodString;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
script?: string;
|
|
41
|
+
}, {
|
|
42
|
+
script?: string;
|
|
43
|
+
}>, _mastra_core.WorkflowContext<any>>>;
|
|
44
|
+
|
|
45
|
+
export { executeTool };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { executeCodeDescription, executeCodeSchema } from '../ai/index.mjs';
|
|
4
|
+
import { FreestyleSandboxes } from '../index.mjs';
|
|
5
|
+
import 'ai';
|
|
6
|
+
import '@hey-api/client-fetch';
|
|
7
|
+
|
|
8
|
+
const executeTool = (config) => {
|
|
9
|
+
const description = executeCodeDescription(
|
|
10
|
+
Object.keys(config.envVars ?? {}).join(", "),
|
|
11
|
+
Object.keys(config.nodeModules ?? {}).join(", ")
|
|
12
|
+
);
|
|
13
|
+
const client = new FreestyleSandboxes({
|
|
14
|
+
apiKey: config.apiKey
|
|
15
|
+
});
|
|
16
|
+
return createTool({
|
|
17
|
+
id: "Execute a TypeScript or JavaScript Script",
|
|
18
|
+
description,
|
|
19
|
+
inputSchema: executeCodeSchema,
|
|
20
|
+
execute: async ({ context: { script } }) => {
|
|
21
|
+
return await client.executeScript(script, config);
|
|
22
|
+
},
|
|
23
|
+
outputSchema: z.object({
|
|
24
|
+
logs: z.array(
|
|
25
|
+
z.object({
|
|
26
|
+
message: z.string(),
|
|
27
|
+
type: z.string()
|
|
28
|
+
})
|
|
29
|
+
),
|
|
30
|
+
result: z.unknown()
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { executeTool };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "freestyle-sandboxes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -25,6 +25,16 @@
|
|
|
25
25
|
"types": "./dist/ai/index.d.mts",
|
|
26
26
|
"default": "./dist/ai/index.mjs"
|
|
27
27
|
}
|
|
28
|
+
},
|
|
29
|
+
"./mastra": {
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/mastra/index.d.cts",
|
|
32
|
+
"default": "./dist/mastra/index.cjs"
|
|
33
|
+
},
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/mastra/index.d.mts",
|
|
36
|
+
"default": "./dist/mastra/index.mjs"
|
|
37
|
+
}
|
|
28
38
|
}
|
|
29
39
|
},
|
|
30
40
|
"scripts": {
|
|
@@ -41,6 +51,7 @@
|
|
|
41
51
|
},
|
|
42
52
|
"dependencies": {
|
|
43
53
|
"@hey-api/client-fetch": "^0.5.7",
|
|
54
|
+
"@mastra/core": "^0.1.27-alpha.66",
|
|
44
55
|
"ai": "^4.0.25",
|
|
45
56
|
"humanlayer": "^0.7.0",
|
|
46
57
|
"openai": "^4.77.3",
|
package/src/ai/index.ts
CHANGED
|
@@ -3,6 +3,37 @@ import { FreestyleSandboxes } from "..";
|
|
|
3
3
|
import { tool } from "ai";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
|
+
export const executeCodeSchema = z.object({
|
|
7
|
+
script: z.string().describe(`
|
|
8
|
+
The JavaScript or TypeScript script to execute, must be in the format of:
|
|
9
|
+
|
|
10
|
+
import { someModule } from "someModule";
|
|
11
|
+
export default () => {
|
|
12
|
+
... your code here ...
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
or for async functions:
|
|
17
|
+
|
|
18
|
+
import { someModule } from "someModule";
|
|
19
|
+
|
|
20
|
+
export default async () => {
|
|
21
|
+
... your code here ...
|
|
22
|
+
return output;
|
|
23
|
+
}
|
|
24
|
+
`),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const executeCodeDescription = (envVars: string, nodeModules: string) =>
|
|
28
|
+
`Execute a JavaScript or TypeScript script.\n${
|
|
29
|
+
envVars.length > 0
|
|
30
|
+
? `You can use the following environment variables: ${envVars}`
|
|
31
|
+
: ""
|
|
32
|
+
}\n${
|
|
33
|
+
nodeModules.length > 0
|
|
34
|
+
? `You can use the following node modules: ${nodeModules}`
|
|
35
|
+
: "You cannot use any node modules."
|
|
36
|
+
}`;
|
|
6
37
|
/**
|
|
7
38
|
* Execute a JavaScript or TypeScript script
|
|
8
39
|
*
|
|
@@ -23,35 +54,8 @@ export const executeTool = (
|
|
|
23
54
|
const envVars = Object.keys(config.envVars ?? {}).join(", ");
|
|
24
55
|
const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
|
|
25
56
|
return tool({
|
|
26
|
-
description:
|
|
27
|
-
|
|
28
|
-
? `You can use the following environment variables: ${envVars}`
|
|
29
|
-
: ""
|
|
30
|
-
}\n${
|
|
31
|
-
nodeModules.length > 0
|
|
32
|
-
? `You can use the following node modules: ${nodeModules}`
|
|
33
|
-
: "You cannot use any node modules."
|
|
34
|
-
}`,
|
|
35
|
-
parameters: z.object({
|
|
36
|
-
script: z.string().describe(`
|
|
37
|
-
The JavaScript or TypeScript script to execute, must be in the format of:
|
|
38
|
-
|
|
39
|
-
import { someModule } from "someModule";
|
|
40
|
-
export default () => {
|
|
41
|
-
... your code here ...
|
|
42
|
-
return output;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
or for async functions:
|
|
46
|
-
|
|
47
|
-
import { someModule } from "someModule";
|
|
48
|
-
|
|
49
|
-
export default async () => {
|
|
50
|
-
... your code here ...
|
|
51
|
-
return output;
|
|
52
|
-
}
|
|
53
|
-
`),
|
|
54
|
-
}),
|
|
57
|
+
description: executeCodeDescription(envVars, nodeModules),
|
|
58
|
+
parameters: executeCodeSchema,
|
|
55
59
|
execute: async ({ script }) => {
|
|
56
60
|
try {
|
|
57
61
|
const res = await api.executeScript(script, config);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createTool } from "@mastra/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { executeCodeDescription, executeCodeSchema } from "../ai";
|
|
4
|
+
import { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
|
|
5
|
+
import { FreestyleSandboxes } from "..";
|
|
6
|
+
|
|
7
|
+
export const executeTool = (
|
|
8
|
+
config: FreestyleExecuteScriptParamsConfiguration & {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
}
|
|
11
|
+
) => {
|
|
12
|
+
const description = executeCodeDescription(
|
|
13
|
+
Object.keys(config.envVars ?? {}).join(", "),
|
|
14
|
+
Object.keys(config.nodeModules ?? {}).join(", ")
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const client = new FreestyleSandboxes({
|
|
18
|
+
apiKey: config.apiKey,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return createTool({
|
|
22
|
+
id: "Execute a TypeScript or JavaScript Script",
|
|
23
|
+
description,
|
|
24
|
+
inputSchema: executeCodeSchema,
|
|
25
|
+
execute: async ({ context: { script } }) => {
|
|
26
|
+
return await client.executeScript(script, config);
|
|
27
|
+
},
|
|
28
|
+
outputSchema: z.object({
|
|
29
|
+
logs: z.array(
|
|
30
|
+
z.object({
|
|
31
|
+
message: z.string(),
|
|
32
|
+
type: z.string(),
|
|
33
|
+
})
|
|
34
|
+
),
|
|
35
|
+
result: z.unknown(),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
};
|