-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecbox-worker.ts
More file actions
57 lines (53 loc) · 1.44 KB
/
execbox-worker.ts
File metadata and controls
57 lines (53 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { resolveProvider } from "@execbox/core";
import { QuickJsExecutor } from "@execbox/quickjs";
async function main(): Promise<void> {
const provider = resolveProvider({
name: "tools",
tools: {
add: {
description: "Add two numbers together.",
inputSchema: {
type: "object",
required: ["x", "y"],
properties: {
x: { type: "number" },
y: { type: "number" },
},
},
execute: async (input) => {
const { x, y } = input as { x: number; y: number };
return { sum: x + y };
},
},
logValue: {
description: "Echo a message for console capture.",
inputSchema: {
type: "object",
required: ["message"],
properties: {
message: { type: "string" },
},
},
execute: async (input) => {
const { message } = input as { message: string };
return { message };
},
},
},
});
const executor = new QuickJsExecutor({
host: "worker",
});
const result = await executor.execute(
`
const sum = await tools.add({ x: 2, y: 5 });
const echoed = await tools.logValue({ message: "captured from worker sandbox" });
console.log(echoed.message);
({ sum: sum.sum });
`,
[provider],
);
console.log("worker example result");
console.log(JSON.stringify(result, null, 2));
}
void main();