integrate-sdk 0.9.3-dev.0 → 0.9.5-dev.0
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/adapters/auto-routes.js +720 -22
- package/dist/adapters/index.js +720 -22
- package/dist/adapters/nextjs.js +720 -22
- package/dist/adapters/node.js +720 -22
- package/dist/adapters/svelte-kit.js +720 -22
- package/dist/adapters/tanstack-start.js +720 -22
- package/dist/ai/anthropic.d.ts +11 -0
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +559 -9
- package/dist/ai/google.d.ts +11 -0
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +568 -9
- package/dist/ai/index.js +655 -15
- package/dist/ai/openai.d.ts +11 -0
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +557 -9
- package/dist/ai/trigger-tools.d.ts +7 -7
- package/dist/ai/trigger-tools.js +7 -7
- package/dist/ai/vercel-ai.d.ts +13 -0
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +543 -9
- package/dist/code-mode/executor.d.ts +99 -0
- package/dist/code-mode/executor.d.ts.map +1 -0
- package/dist/code-mode/executor.js +207 -0
- package/dist/code-mode/index.d.ts +12 -0
- package/dist/code-mode/index.d.ts.map +1 -0
- package/dist/code-mode/index.js +527 -0
- package/dist/code-mode/runtime-stub.d.ts +16 -0
- package/dist/code-mode/runtime-stub.d.ts.map +1 -0
- package/dist/code-mode/runtime-stub.js +72 -0
- package/dist/code-mode/tool-builder.d.ts +83 -0
- package/dist/code-mode/tool-builder.d.ts.map +1 -0
- package/dist/code-mode/tool-builder.js +524 -0
- package/dist/code-mode/type-generator.d.ts +22 -0
- package/dist/code-mode/type-generator.d.ts.map +1 -0
- package/dist/code-mode/type-generator.js +217 -0
- package/dist/index.js +720 -22
- package/dist/oauth.js +720 -22
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +731 -23
- package/dist/src/ai/anthropic.d.ts +11 -0
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts +11 -0
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts +11 -0
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/trigger-tools.d.ts +7 -7
- package/dist/src/ai/vercel-ai.d.ts +13 -0
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/code-mode/executor.d.ts +99 -0
- package/dist/src/code-mode/executor.d.ts.map +1 -0
- package/dist/src/code-mode/index.d.ts +12 -0
- package/dist/src/code-mode/index.d.ts.map +1 -0
- package/dist/src/code-mode/runtime-stub.d.ts +16 -0
- package/dist/src/code-mode/runtime-stub.d.ts.map +1 -0
- package/dist/src/code-mode/tool-builder.d.ts +83 -0
- package/dist/src/code-mode/tool-builder.d.ts.map +1 -0
- package/dist/src/code-mode/type-generator.d.ts +22 -0
- package/dist/src/code-mode/type-generator.d.ts.map +1 -0
- package/dist/src/config/types.d.ts +55 -0
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +15 -6
- package/server.ts +9 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Mode: Vercel Sandbox executor
|
|
3
|
+
*
|
|
4
|
+
* Spins up a Vercel Sandbox microVM per `execute_code` call, writes the
|
|
5
|
+
* runtime stub and wrapped user code into it, runs node against the user
|
|
6
|
+
* code, and returns captured stdout/stderr + parsed result.
|
|
7
|
+
*
|
|
8
|
+
* `@vercel/sandbox` is loaded lazily so importing code-mode utilities on the
|
|
9
|
+
* client / from the type generator does not force the dependency to exist.
|
|
10
|
+
*/
|
|
11
|
+
import type { MCPContext } from "../config/types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Shape the executor depends on — mirrors the subset of `@vercel/sandbox`
|
|
14
|
+
* we actually use. Declared structurally so we don't force the real package
|
|
15
|
+
* to be installed at type-check time.
|
|
16
|
+
*/
|
|
17
|
+
interface SandboxLike {
|
|
18
|
+
writeFiles(files: Array<{
|
|
19
|
+
path: string;
|
|
20
|
+
content: Buffer;
|
|
21
|
+
}>): Promise<void>;
|
|
22
|
+
runCommand(params: {
|
|
23
|
+
cmd: string;
|
|
24
|
+
args?: string[];
|
|
25
|
+
env?: Record<string, string>;
|
|
26
|
+
cwd?: string;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
exitCode: number;
|
|
29
|
+
stdout(): Promise<string>;
|
|
30
|
+
stderr(): Promise<string>;
|
|
31
|
+
}>;
|
|
32
|
+
stop(): Promise<unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface SandboxFactory {
|
|
35
|
+
create(options: {
|
|
36
|
+
runtime?: string;
|
|
37
|
+
timeout?: number;
|
|
38
|
+
resources?: {
|
|
39
|
+
vcpus?: number;
|
|
40
|
+
};
|
|
41
|
+
networkPolicy?: unknown;
|
|
42
|
+
}): Promise<SandboxLike>;
|
|
43
|
+
}
|
|
44
|
+
/** @internal — used by unit tests to stub the sandbox SDK. */
|
|
45
|
+
export declare function __setSandboxFactoryForTests(factory: SandboxFactory | null): void;
|
|
46
|
+
export interface ExecuteSandboxCodeOptions {
|
|
47
|
+
/** Source code the LLM produced. Treated as an async function body. */
|
|
48
|
+
code: string;
|
|
49
|
+
/** Fully-qualified MCP route URL, e.g. `https://myapp.com/api/integrate/mcp`. */
|
|
50
|
+
mcpUrl: string;
|
|
51
|
+
/** Session token forwarded as `Authorization: Bearer <token>` by the stub. */
|
|
52
|
+
sessionToken?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Provider OAuth tokens to forward as `x-integrate-tokens`. Same format the
|
|
55
|
+
* existing AI helpers pass to the `/api/integrate/mcp` route today.
|
|
56
|
+
*/
|
|
57
|
+
providerTokens?: Record<string, string>;
|
|
58
|
+
/** Comma-separated integration IDs (forwarded as `x-integrations`). */
|
|
59
|
+
integrationsHeader?: string;
|
|
60
|
+
/** Optional multi-tenant user context. Serialized to JSON for the sandbox. */
|
|
61
|
+
context?: MCPContext;
|
|
62
|
+
/** Sandbox runtime image. Defaults to `'node22'`. */
|
|
63
|
+
runtime?: "node24" | "node22";
|
|
64
|
+
/** Sandbox timeout in ms. Defaults to 60_000. */
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
/** vCPUs allocated to the sandbox. Defaults to 2. */
|
|
67
|
+
vcpus?: number;
|
|
68
|
+
/** Egress firewall. Defaults to an allow-list containing only the MCP host. */
|
|
69
|
+
networkPolicy?: "allow-all" | "deny-all" | {
|
|
70
|
+
allow?: string[];
|
|
71
|
+
subnets?: {
|
|
72
|
+
allow?: string[];
|
|
73
|
+
deny?: string[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface ExecuteSandboxCodeResult {
|
|
78
|
+
/** Whether the sandbox command exited with code 0. */
|
|
79
|
+
success: boolean;
|
|
80
|
+
/** Exit code from `node user.mjs`. */
|
|
81
|
+
exitCode: number;
|
|
82
|
+
/** Parsed return value, if the user code set one via `return`. */
|
|
83
|
+
result?: unknown;
|
|
84
|
+
/** Raw stdout stream (without the `__INTEGRATE_RESULT__` sentinel line). */
|
|
85
|
+
stdout: string;
|
|
86
|
+
/** Raw stderr stream. */
|
|
87
|
+
stderr: string;
|
|
88
|
+
/** Wall-clock duration in milliseconds. */
|
|
89
|
+
durationMs: number;
|
|
90
|
+
/** Error message if the sandbox itself failed (not user-code exit != 0). */
|
|
91
|
+
error?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Execute LLM-authored TypeScript/JS code inside a fresh Vercel Sandbox.
|
|
95
|
+
* Creates one sandbox per call and stops it in `finally`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function executeSandboxCode(options: ExecuteSandboxCodeOptions): Promise<ExecuteSandboxCodeResult>;
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +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runtime.mjs — generated by integrate-sdk code mode
|
|
3
|
+
const MCP_URL = process.env.INTEGRATE_MCP_URL;
|
|
4
|
+
const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
|
|
5
|
+
const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
|
|
6
|
+
const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
|
|
7
|
+
const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
|
|
8
|
+
|
|
9
|
+
if (!MCP_URL) {
|
|
10
|
+
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function camelToSnake(str) {
|
|
14
|
+
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function callTool(toolName, args) {
|
|
18
|
+
const headers = {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'x-integrate-code-mode': '1',
|
|
21
|
+
};
|
|
22
|
+
if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
|
|
23
|
+
if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
|
|
24
|
+
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
25
|
+
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
26
|
+
|
|
27
|
+
const res = await fetch(MCP_URL, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers,
|
|
30
|
+
body: JSON.stringify({ name: toolName, arguments: args || {} }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const text = await res.text();
|
|
34
|
+
let payload;
|
|
35
|
+
try {
|
|
36
|
+
payload = text ? JSON.parse(text) : null;
|
|
37
|
+
} catch {
|
|
38
|
+
payload = { content: [{ type: 'text', text }] };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
const message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
43
|
+
const err = new Error(message);
|
|
44
|
+
err.status = res.status;
|
|
45
|
+
err.toolName = toolName;
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return payload;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createIntegrationProxy(integrationId) {
|
|
53
|
+
return new Proxy({}, {
|
|
54
|
+
get(_target, methodName) {
|
|
55
|
+
if (typeof methodName !== 'string') return undefined;
|
|
56
|
+
return (args) => callTool(integrationId + '_' + camelToSnake(methodName), args);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const client = new Proxy({}, {
|
|
62
|
+
get(_target, integrationId) {
|
|
63
|
+
if (typeof integrationId !== 'string') return undefined;
|
|
64
|
+
return createIntegrationProxy(integrationId);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export { callTool };
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
// executor.ts
|
|
72
|
+
var sandboxFactoryOverride = null;
|
|
73
|
+
function __setSandboxFactoryForTests(factory) {
|
|
74
|
+
sandboxFactoryOverride = factory;
|
|
75
|
+
}
|
|
76
|
+
async function loadSandboxFactory() {
|
|
77
|
+
if (sandboxFactoryOverride)
|
|
78
|
+
return sandboxFactoryOverride;
|
|
79
|
+
try {
|
|
80
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
81
|
+
const pkg = "@" + "vercel/sandbox";
|
|
82
|
+
const mod = await dynamicImport(pkg);
|
|
83
|
+
return mod.Sandbox ?? mod.default?.Sandbox ?? mod;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw new Error("Code Mode requires the optional peer dependency `@vercel/sandbox`. " + "Install it with `npm install @vercel/sandbox` (or `bun add @vercel/sandbox`).");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var RESULT_SENTINEL = "__INTEGRATE_RESULT__";
|
|
89
|
+
function wrapUserCode(code) {
|
|
90
|
+
return `// user.mjs — wrapped by integrate-sdk code mode
|
|
91
|
+
import { client, callTool } from './runtime.mjs';
|
|
92
|
+
|
|
93
|
+
(async () => {
|
|
94
|
+
try {
|
|
95
|
+
const __result = await (async () => {
|
|
96
|
+
${code}
|
|
97
|
+
})();
|
|
98
|
+
if (typeof __result !== 'undefined') {
|
|
99
|
+
process.stdout.write('\\n' + ${JSON.stringify(RESULT_SENTINEL)} + JSON.stringify(__result) + '\\n');
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
const payload = {
|
|
103
|
+
message: err && err.message ? err.message : String(err),
|
|
104
|
+
name: err && err.name,
|
|
105
|
+
stack: err && err.stack,
|
|
106
|
+
toolName: err && err.toolName,
|
|
107
|
+
status: err && err.status,
|
|
108
|
+
};
|
|
109
|
+
process.stderr.write('\\n' + ${JSON.stringify(RESULT_SENTINEL)} + JSON.stringify({ error: payload }) + '\\n');
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
function defaultNetworkPolicy(mcpUrl) {
|
|
116
|
+
try {
|
|
117
|
+
const host = new URL(mcpUrl).hostname;
|
|
118
|
+
return { allow: [host] };
|
|
119
|
+
} catch {
|
|
120
|
+
return { allow: [] };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function extractResult(stream) {
|
|
124
|
+
const idx = stream.lastIndexOf(RESULT_SENTINEL);
|
|
125
|
+
if (idx === -1)
|
|
126
|
+
return { cleaned: stream };
|
|
127
|
+
const before = stream.slice(0, idx).replace(/\n$/, "");
|
|
128
|
+
const rest = stream.slice(idx + RESULT_SENTINEL.length);
|
|
129
|
+
const newlineIdx = rest.indexOf(`
|
|
130
|
+
`);
|
|
131
|
+
const payload = newlineIdx === -1 ? rest : rest.slice(0, newlineIdx);
|
|
132
|
+
const after = newlineIdx === -1 ? "" : rest.slice(newlineIdx + 1);
|
|
133
|
+
try {
|
|
134
|
+
return { cleaned: (before + after).trimEnd(), result: JSON.parse(payload) };
|
|
135
|
+
} catch {
|
|
136
|
+
return { cleaned: stream };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function executeSandboxCode(options) {
|
|
140
|
+
const startedAt = Date.now();
|
|
141
|
+
const runtime = options.runtime ?? "node22";
|
|
142
|
+
const timeoutMs = options.timeoutMs ?? 60000;
|
|
143
|
+
const networkPolicy = options.networkPolicy ?? defaultNetworkPolicy(options.mcpUrl);
|
|
144
|
+
let sandbox = null;
|
|
145
|
+
try {
|
|
146
|
+
const Sandbox = await loadSandboxFactory();
|
|
147
|
+
sandbox = await Sandbox.create({
|
|
148
|
+
runtime,
|
|
149
|
+
timeout: timeoutMs,
|
|
150
|
+
resources: options.vcpus ? { vcpus: options.vcpus } : undefined,
|
|
151
|
+
networkPolicy
|
|
152
|
+
});
|
|
153
|
+
const runtimeContent = Buffer.from(RUNTIME_STUB_SOURCE, "utf-8");
|
|
154
|
+
const userContent = Buffer.from(wrapUserCode(options.code), "utf-8");
|
|
155
|
+
await sandbox.writeFiles([
|
|
156
|
+
{ path: "runtime.mjs", content: runtimeContent },
|
|
157
|
+
{ path: "user.mjs", content: userContent }
|
|
158
|
+
]);
|
|
159
|
+
const env = {
|
|
160
|
+
INTEGRATE_MCP_URL: options.mcpUrl
|
|
161
|
+
};
|
|
162
|
+
if (options.sessionToken)
|
|
163
|
+
env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
|
|
164
|
+
if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
|
|
165
|
+
env.INTEGRATE_PROVIDER_TOKENS = JSON.stringify(options.providerTokens);
|
|
166
|
+
}
|
|
167
|
+
if (options.integrationsHeader)
|
|
168
|
+
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
169
|
+
if (options.context)
|
|
170
|
+
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
171
|
+
const cmd = await sandbox.runCommand({
|
|
172
|
+
cmd: "node",
|
|
173
|
+
args: ["user.mjs"],
|
|
174
|
+
env
|
|
175
|
+
});
|
|
176
|
+
const [stdoutRaw, stderrRaw] = await Promise.all([cmd.stdout(), cmd.stderr()]);
|
|
177
|
+
const stdoutExtract = extractResult(stdoutRaw);
|
|
178
|
+
const stderrExtract = extractResult(stderrRaw);
|
|
179
|
+
return {
|
|
180
|
+
success: cmd.exitCode === 0,
|
|
181
|
+
exitCode: cmd.exitCode,
|
|
182
|
+
result: stdoutExtract.result ?? stderrExtract.result,
|
|
183
|
+
stdout: stdoutExtract.cleaned,
|
|
184
|
+
stderr: stderrExtract.cleaned,
|
|
185
|
+
durationMs: Date.now() - startedAt
|
|
186
|
+
};
|
|
187
|
+
} catch (err) {
|
|
188
|
+
return {
|
|
189
|
+
success: false,
|
|
190
|
+
exitCode: -1,
|
|
191
|
+
stdout: "",
|
|
192
|
+
stderr: "",
|
|
193
|
+
durationMs: Date.now() - startedAt,
|
|
194
|
+
error: err instanceof Error ? err.message : String(err)
|
|
195
|
+
};
|
|
196
|
+
} finally {
|
|
197
|
+
if (sandbox) {
|
|
198
|
+
try {
|
|
199
|
+
await sandbox.stop();
|
|
200
|
+
} catch {}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export {
|
|
205
|
+
executeSandboxCode,
|
|
206
|
+
__setSandboxFactoryForTests
|
|
207
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Mode public surface
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the pieces needed to build the `execute_code` tool that AI
|
|
5
|
+
* helpers hand to the LLM and the server-side executor that runs that code
|
|
6
|
+
* in a Vercel Sandbox.
|
|
7
|
+
*/
|
|
8
|
+
export { generateCodeModeTypes, type GeneratedTypes, } from "./type-generator.js";
|
|
9
|
+
export { executeSandboxCode, __setSandboxFactoryForTests, type ExecuteSandboxCodeOptions, type ExecuteSandboxCodeResult, } from "./executor.js";
|
|
10
|
+
export { RUNTIME_STUB_SOURCE } from "./runtime-stub.js";
|
|
11
|
+
export { buildCodeModeTool, CODE_MODE_TOOL_NAME, type CodeModeToolOptions, type CodeModeToolDefinition, } from "./tool-builder.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code-mode/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,GACpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,GAC5B,MAAM,mBAAmB,CAAC"}
|