Skip to content

Commit f25e957

Browse files
committed
Feat: Add ai tool and actions improvements
1 parent 0c8b883 commit f25e957

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

packages/exec0-ai/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@exec0/ai-tool",
3+
"version": "0.1.0",
4+
"description": "Ai tool for Agent Code Execution",
5+
"main": "src/index.ts",
6+
"type": "module",
7+
"files": [
8+
"src/index.ts"
9+
],
10+
"publishConfig": {
11+
"access": "public"
12+
},
13+
"dependencies": {
14+
"@exec0/sdk": "^0.1.2",
15+
"ai": "^5.0.113",
16+
"zod": "^4.1.13"
17+
}
18+
}

packages/exec0-ai/src/index.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import {
2+
executeJavaScript,
3+
executePython,
4+
executeTypeScript,
5+
} from "@exec0/sdk";
6+
import { tool } from "ai";
7+
import { z } from "zod";
8+
9+
const DEFAULT_TIMEOUT = 20000;
10+
11+
export const exec0Tools = {
12+
executePython: tool({
13+
description:
14+
"Execute Python code and return the output. Use only Python standard library",
15+
inputSchema: z.object({
16+
code: z.string().min(1).describe("Python code to execute"),
17+
}),
18+
execute: async ({ code }) => {
19+
try {
20+
const result = await executePython({
21+
code,
22+
timeout: DEFAULT_TIMEOUT,
23+
});
24+
return {
25+
success: true,
26+
output: result.data.output,
27+
executionTime: result.data.executionTime,
28+
error: result.data.error,
29+
};
30+
} catch (error) {
31+
return {
32+
success: false,
33+
error: error instanceof Error ? error.message : "Unknown error",
34+
};
35+
}
36+
},
37+
}),
38+
39+
executeJavaScript: tool({
40+
description:
41+
"Execute JavaScript code and return the output. Use only JavaScript standard library",
42+
inputSchema: z.object({
43+
code: z.string().min(1).describe("JavaScript code to execute"),
44+
}),
45+
execute: async ({ code }) => {
46+
try {
47+
const result = await executeJavaScript({
48+
code,
49+
timeout: DEFAULT_TIMEOUT,
50+
});
51+
return {
52+
success: true,
53+
output: result.data.output,
54+
executionTime: result.data.executionTime,
55+
error: result.data.error,
56+
};
57+
} catch (error) {
58+
return {
59+
success: false,
60+
error: error instanceof Error ? error.message : "Unknown error",
61+
};
62+
}
63+
},
64+
}),
65+
66+
executeTypeScript: tool({
67+
description:
68+
"Execute TypeScript code and return the output. Use only TypeScript standard library",
69+
inputSchema: z.object({
70+
code: z.string().min(1).describe("TypeScript code to execute"),
71+
}),
72+
execute: async ({ code }) => {
73+
try {
74+
const result = await executeTypeScript({
75+
code,
76+
timeout: DEFAULT_TIMEOUT,
77+
});
78+
return {
79+
success: true,
80+
output: result.data.output,
81+
executionTime: result.data.executionTime,
82+
error: result.data.error,
83+
};
84+
} catch (error) {
85+
return {
86+
success: false,
87+
error: error instanceof Error ? error.message : "Unknown error",
88+
};
89+
}
90+
},
91+
}),
92+
};

0 commit comments

Comments
 (0)