integrate-sdk 0.9.17-dev.0 → 0.9.19-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/index.js +6 -16
- package/dist/adapters/solid-start.js +6 -16
- package/dist/adapters/svelte-kit.js +6 -16
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +102 -27
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +107 -27
- package/dist/ai/index.js +139 -32
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +100 -27
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +97 -26
- package/dist/code-mode/index.d.ts +1 -1
- package/dist/code-mode/index.d.ts.map +1 -1
- package/dist/code-mode/index.js +90 -25
- package/dist/code-mode/tool-builder.d.ts +32 -4
- package/dist/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/code-mode/tool-builder.js +90 -25
- package/dist/code-mode/type-generator.d.ts +4 -0
- package/dist/code-mode/type-generator.d.ts.map +1 -1
- package/dist/code-mode/type-generator.js +33 -3
- package/dist/server.js +141 -33
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/code-mode/index.d.ts +1 -1
- package/dist/src/code-mode/index.d.ts.map +1 -1
- package/dist/src/code-mode/tool-builder.d.ts +32 -4
- package/dist/src/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/src/code-mode/type-generator.d.ts +4 -0
- package/dist/src/code-mode/type-generator.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ai/vercel-ai.js
CHANGED
|
@@ -4584,6 +4584,8 @@ function generateCodeModeTypes(tools) {
|
|
|
4584
4584
|
const methodMap = {};
|
|
4585
4585
|
const integrationCounts = {};
|
|
4586
4586
|
const sections = [];
|
|
4587
|
+
const compactLines = [];
|
|
4588
|
+
const perIntegration = {};
|
|
4587
4589
|
const integrationIds = Object.keys(byIntegration).sort();
|
|
4588
4590
|
sections.push("/**");
|
|
4589
4591
|
sections.push(" * Integrate SDK — available APIs inside `execute_code`.");
|
|
@@ -4596,18 +4598,35 @@ function generateCodeModeTypes(tools) {
|
|
|
4596
4598
|
const integrationTools = byIntegration[integrationId].slice().sort((a, b) => a.name.localeCompare(b.name));
|
|
4597
4599
|
integrationCounts[integrationId] = integrationTools.length;
|
|
4598
4600
|
const interfaceName = pascalCase(integrationId) + "Client";
|
|
4601
|
+
const fullSections = [];
|
|
4602
|
+
fullSections.push(`export interface ${interfaceName} {`);
|
|
4599
4603
|
sections.push(`export interface ${interfaceName} {`);
|
|
4604
|
+
const compactMethods = [];
|
|
4600
4605
|
for (const tool of integrationTools) {
|
|
4601
4606
|
const methodName = toolNameToMethod(tool.name);
|
|
4602
4607
|
methodMap[`${integrationId}.${methodName}`] = tool.name;
|
|
4603
|
-
|
|
4608
|
+
const fullDesc = formatDescription(tool.description, " ");
|
|
4609
|
+
fullSections.push(fullDesc);
|
|
4610
|
+
sections.push(fullDesc);
|
|
4604
4611
|
const argType = argsType(tool.inputSchema);
|
|
4605
4612
|
const argIsOptional = !methodHasRequiredArgs(tool.inputSchema);
|
|
4606
4613
|
const paramName = argIsOptional ? "args?" : "args";
|
|
4607
|
-
|
|
4614
|
+
const fullLine = ` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`;
|
|
4615
|
+
fullSections.push(fullLine);
|
|
4616
|
+
sections.push(fullLine);
|
|
4617
|
+
const compactArgs = compactArgsSignature(tool.inputSchema);
|
|
4618
|
+
const compactParam = argIsOptional ? `args?: ${compactArgs}` : `args: ${compactArgs}`;
|
|
4619
|
+
compactMethods.push(` ${safeIdent(methodName)}(${compactParam}): Promise<ToolResult>`);
|
|
4608
4620
|
}
|
|
4609
4621
|
sections.push("}");
|
|
4610
4622
|
sections.push("");
|
|
4623
|
+
fullSections.push("}");
|
|
4624
|
+
perIntegration[integrationId] = fullSections.join(`
|
|
4625
|
+
`);
|
|
4626
|
+
compactLines.push(`client.${integrationId}:`);
|
|
4627
|
+
for (const m of compactMethods) {
|
|
4628
|
+
compactLines.push(m);
|
|
4629
|
+
}
|
|
4611
4630
|
}
|
|
4612
4631
|
sections.push("export interface ToolResult {");
|
|
4613
4632
|
sections.push(" content: Array<{ type: 'text' | 'image' | 'resource'; text?: string; data?: string; mimeType?: string; [key: string]: unknown }>;");
|
|
@@ -4625,11 +4644,22 @@ function generateCodeModeTypes(tools) {
|
|
|
4625
4644
|
sections.push("export declare const client: Client;");
|
|
4626
4645
|
return {
|
|
4627
4646
|
source: sections.filter((line, idx, arr) => !(line === "" && arr[idx - 1] === "")).join(`
|
|
4647
|
+
`),
|
|
4648
|
+
compact: compactLines.join(`
|
|
4628
4649
|
`),
|
|
4629
4650
|
methodMap,
|
|
4630
|
-
integrationCounts
|
|
4651
|
+
integrationCounts,
|
|
4652
|
+
perIntegration
|
|
4631
4653
|
};
|
|
4632
4654
|
}
|
|
4655
|
+
function compactArgsSignature(schema) {
|
|
4656
|
+
if (!schema || !schema.properties || Object.keys(schema.properties).length === 0) {
|
|
4657
|
+
return "{}";
|
|
4658
|
+
}
|
|
4659
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
4660
|
+
const params = Object.keys(schema.properties).map((key) => `${safeIdent(key)}${required.has(key) ? "" : "?"}`);
|
|
4661
|
+
return `{ ${params.join(", ")} }`;
|
|
4662
|
+
}
|
|
4633
4663
|
function pascalCase(id) {
|
|
4634
4664
|
return id.split(/[^A-Za-z0-9]/).filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("") || "Unknown";
|
|
4635
4665
|
}
|
|
@@ -4903,25 +4933,16 @@ function getEnv(key) {
|
|
|
4903
4933
|
|
|
4904
4934
|
// ../code-mode/tool-builder.ts
|
|
4905
4935
|
var CODE_MODE_TOOL_NAME = "execute_code";
|
|
4936
|
+
var TYPES_TOOL_NAME = "get_integration_types";
|
|
4906
4937
|
var DEFAULT_INSTRUCTIONS = [
|
|
4907
|
-
"
|
|
4908
|
-
"
|
|
4909
|
-
"
|
|
4910
|
-
"
|
|
4911
|
-
"that is the whole point of this tool.",
|
|
4938
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
4939
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
4940
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
4941
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
4912
4942
|
"",
|
|
4913
|
-
"
|
|
4914
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
4915
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
4916
|
-
" the caller receives it as JSON.",
|
|
4917
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
4918
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
4919
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
4920
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
4921
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
4922
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
4943
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
4923
4944
|
"",
|
|
4924
|
-
"
|
|
4945
|
+
"Available methods:"
|
|
4925
4946
|
].join(`
|
|
4926
4947
|
`);
|
|
4927
4948
|
function resolveCodeModeClientConfig(client) {
|
|
@@ -4963,10 +4984,7 @@ function buildCodeModeTool(client, options) {
|
|
|
4963
4984
|
const serverCodeModeConfig = resolveCodeModeClientConfig(client);
|
|
4964
4985
|
const sandboxOverrides = options.sandbox ?? {};
|
|
4965
4986
|
const description = `${DEFAULT_INSTRUCTIONS}
|
|
4966
|
-
|
|
4967
|
-
\`\`\`typescript
|
|
4968
|
-
${generated.source}
|
|
4969
|
-
\`\`\``;
|
|
4987
|
+
${generated.compact}`;
|
|
4970
4988
|
const execute = async ({ code }) => {
|
|
4971
4989
|
const publicUrl = resolveCodeModePublicUrl({
|
|
4972
4990
|
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
@@ -4983,11 +5001,33 @@ ${generated.source}
|
|
|
4983
5001
|
};
|
|
4984
5002
|
}
|
|
4985
5003
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5004
|
+
let resolvedTokens = providerTokens;
|
|
5005
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5006
|
+
const oauthManager = client.oauthManager;
|
|
5007
|
+
if (oauthManager) {
|
|
5008
|
+
resolvedTokens = {};
|
|
5009
|
+
const clientIntegrations = client.integrations || [];
|
|
5010
|
+
for (const integration of clientIntegrations) {
|
|
5011
|
+
if (integration.oauth) {
|
|
5012
|
+
const provider = integration.oauth.provider;
|
|
5013
|
+
try {
|
|
5014
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5015
|
+
if (tokenData?.accessToken) {
|
|
5016
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5017
|
+
}
|
|
5018
|
+
} catch {}
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5022
|
+
resolvedTokens = undefined;
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
4986
5026
|
return executeSandboxCode({
|
|
4987
5027
|
code,
|
|
4988
5028
|
mcpUrl,
|
|
4989
5029
|
apiKey,
|
|
4990
|
-
providerTokens,
|
|
5030
|
+
providerTokens: resolvedTokens,
|
|
4991
5031
|
context,
|
|
4992
5032
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
4993
5033
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
|
@@ -4996,7 +5036,8 @@ ${generated.source}
|
|
|
4996
5036
|
networkPolicy: sandboxOverrides.networkPolicy ?? serverCodeModeConfig.networkPolicy
|
|
4997
5037
|
});
|
|
4998
5038
|
};
|
|
4999
|
-
|
|
5039
|
+
const availableIntegrations = Object.keys(generated.perIntegration);
|
|
5040
|
+
const codeTool = {
|
|
5000
5041
|
name: CODE_MODE_TOOL_NAME,
|
|
5001
5042
|
description,
|
|
5002
5043
|
parameters: {
|
|
@@ -5012,6 +5053,29 @@ ${generated.source}
|
|
|
5012
5053
|
},
|
|
5013
5054
|
execute
|
|
5014
5055
|
};
|
|
5056
|
+
const typesTool = {
|
|
5057
|
+
name: TYPES_TOOL_NAME,
|
|
5058
|
+
description: "Get full TypeScript type definitions (method signatures, parameter types, JSDoc) for a specific integration. " + `Available integrations: ${availableIntegrations.join(", ")}.`,
|
|
5059
|
+
parameters: {
|
|
5060
|
+
type: "object",
|
|
5061
|
+
properties: {
|
|
5062
|
+
integration: {
|
|
5063
|
+
type: "string",
|
|
5064
|
+
description: `Integration name to get types for (${availableIntegrations.join(", ")}).`
|
|
5065
|
+
}
|
|
5066
|
+
},
|
|
5067
|
+
required: ["integration"],
|
|
5068
|
+
additionalProperties: false
|
|
5069
|
+
},
|
|
5070
|
+
execute: ({ integration }) => {
|
|
5071
|
+
const types2 = generated.perIntegration[integration];
|
|
5072
|
+
if (!types2) {
|
|
5073
|
+
return { error: `Unknown integration "${integration}".`, available: availableIntegrations };
|
|
5074
|
+
}
|
|
5075
|
+
return { types: types2 };
|
|
5076
|
+
}
|
|
5077
|
+
};
|
|
5078
|
+
return { codeTool, typesTool };
|
|
5015
5079
|
}
|
|
5016
5080
|
|
|
5017
5081
|
// vercel-ai.ts
|
|
@@ -5051,7 +5115,7 @@ async function getVercelAITools(client, options) {
|
|
|
5051
5115
|
}
|
|
5052
5116
|
}
|
|
5053
5117
|
if (effectiveMode === "code") {
|
|
5054
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5118
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5055
5119
|
tools: mcpTools,
|
|
5056
5120
|
providerTokens,
|
|
5057
5121
|
context: options?.context,
|
|
@@ -5064,6 +5128,13 @@ async function getVercelAITools(client, options) {
|
|
|
5064
5128
|
}),
|
|
5065
5129
|
execute: async (args) => codeTool.execute(args)
|
|
5066
5130
|
};
|
|
5131
|
+
vercelTools[TYPES_TOOL_NAME] = {
|
|
5132
|
+
description: typesTool.description,
|
|
5133
|
+
inputSchema: exports_external.object({
|
|
5134
|
+
integration: exports_external.string().describe(typesTool.parameters.properties.integration.description)
|
|
5135
|
+
}),
|
|
5136
|
+
execute: async (args) => typesTool.execute(args)
|
|
5137
|
+
};
|
|
5067
5138
|
} else {
|
|
5068
5139
|
for (const mcpTool of mcpTools) {
|
|
5069
5140
|
vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client, finalOptions);
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
export { generateCodeModeTypes, type GeneratedTypes, } from "./type-generator.js";
|
|
9
9
|
export { executeSandboxCode, __setSandboxFactoryForTests, type ExecuteSandboxCodeOptions, type ExecuteSandboxCodeResult, } from "./executor.js";
|
|
10
10
|
export { RUNTIME_STUB_SOURCE } from "./runtime-stub.js";
|
|
11
|
-
export { buildCodeModeTool, canUseCodeMode, CODE_MODE_TOOL_NAME, type CodeModeToolOptions, type CodeModeToolDefinition, } from "./tool-builder.js";
|
|
11
|
+
export { buildCodeModeTool, canUseCodeMode, CODE_MODE_TOOL_NAME, TYPES_TOOL_NAME, type CodeModeToolOptions, type CodeModeToolDefinition, type TypesToolDefinition, type CodeModeTools, } from "./tool-builder.js";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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,cAAc,EACd,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,
|
|
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,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,aAAa,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/code-mode/index.js
CHANGED
|
@@ -182,6 +182,8 @@ function generateCodeModeTypes(tools) {
|
|
|
182
182
|
const methodMap = {};
|
|
183
183
|
const integrationCounts = {};
|
|
184
184
|
const sections = [];
|
|
185
|
+
const compactLines = [];
|
|
186
|
+
const perIntegration = {};
|
|
185
187
|
const integrationIds = Object.keys(byIntegration).sort();
|
|
186
188
|
sections.push("/**");
|
|
187
189
|
sections.push(" * Integrate SDK — available APIs inside `execute_code`.");
|
|
@@ -194,18 +196,35 @@ function generateCodeModeTypes(tools) {
|
|
|
194
196
|
const integrationTools = byIntegration[integrationId].slice().sort((a, b) => a.name.localeCompare(b.name));
|
|
195
197
|
integrationCounts[integrationId] = integrationTools.length;
|
|
196
198
|
const interfaceName = pascalCase(integrationId) + "Client";
|
|
199
|
+
const fullSections = [];
|
|
200
|
+
fullSections.push(`export interface ${interfaceName} {`);
|
|
197
201
|
sections.push(`export interface ${interfaceName} {`);
|
|
202
|
+
const compactMethods = [];
|
|
198
203
|
for (const tool of integrationTools) {
|
|
199
204
|
const methodName = toolNameToMethod(tool.name);
|
|
200
205
|
methodMap[`${integrationId}.${methodName}`] = tool.name;
|
|
201
|
-
|
|
206
|
+
const fullDesc = formatDescription(tool.description, " ");
|
|
207
|
+
fullSections.push(fullDesc);
|
|
208
|
+
sections.push(fullDesc);
|
|
202
209
|
const argType = argsType(tool.inputSchema);
|
|
203
210
|
const argIsOptional = !methodHasRequiredArgs(tool.inputSchema);
|
|
204
211
|
const paramName = argIsOptional ? "args?" : "args";
|
|
205
|
-
|
|
212
|
+
const fullLine = ` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`;
|
|
213
|
+
fullSections.push(fullLine);
|
|
214
|
+
sections.push(fullLine);
|
|
215
|
+
const compactArgs = compactArgsSignature(tool.inputSchema);
|
|
216
|
+
const compactParam = argIsOptional ? `args?: ${compactArgs}` : `args: ${compactArgs}`;
|
|
217
|
+
compactMethods.push(` ${safeIdent(methodName)}(${compactParam}): Promise<ToolResult>`);
|
|
206
218
|
}
|
|
207
219
|
sections.push("}");
|
|
208
220
|
sections.push("");
|
|
221
|
+
fullSections.push("}");
|
|
222
|
+
perIntegration[integrationId] = fullSections.join(`
|
|
223
|
+
`);
|
|
224
|
+
compactLines.push(`client.${integrationId}:`);
|
|
225
|
+
for (const m of compactMethods) {
|
|
226
|
+
compactLines.push(m);
|
|
227
|
+
}
|
|
209
228
|
}
|
|
210
229
|
sections.push("export interface ToolResult {");
|
|
211
230
|
sections.push(" content: Array<{ type: 'text' | 'image' | 'resource'; text?: string; data?: string; mimeType?: string; [key: string]: unknown }>;");
|
|
@@ -223,11 +242,22 @@ function generateCodeModeTypes(tools) {
|
|
|
223
242
|
sections.push("export declare const client: Client;");
|
|
224
243
|
return {
|
|
225
244
|
source: sections.filter((line, idx, arr) => !(line === "" && arr[idx - 1] === "")).join(`
|
|
245
|
+
`),
|
|
246
|
+
compact: compactLines.join(`
|
|
226
247
|
`),
|
|
227
248
|
methodMap,
|
|
228
|
-
integrationCounts
|
|
249
|
+
integrationCounts,
|
|
250
|
+
perIntegration
|
|
229
251
|
};
|
|
230
252
|
}
|
|
253
|
+
function compactArgsSignature(schema) {
|
|
254
|
+
if (!schema || !schema.properties || Object.keys(schema.properties).length === 0) {
|
|
255
|
+
return "{}";
|
|
256
|
+
}
|
|
257
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
258
|
+
const params = Object.keys(schema.properties).map((key) => `${safeIdent(key)}${required.has(key) ? "" : "?"}`);
|
|
259
|
+
return `{ ${params.join(", ")} }`;
|
|
260
|
+
}
|
|
231
261
|
function pascalCase(id) {
|
|
232
262
|
return id.split(/[^A-Za-z0-9]/).filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("") || "Unknown";
|
|
233
263
|
}
|
|
@@ -512,25 +542,16 @@ function getEnv(key) {
|
|
|
512
542
|
|
|
513
543
|
// tool-builder.ts
|
|
514
544
|
var CODE_MODE_TOOL_NAME = "execute_code";
|
|
545
|
+
var TYPES_TOOL_NAME = "get_integration_types";
|
|
515
546
|
var DEFAULT_INSTRUCTIONS = [
|
|
516
|
-
"
|
|
517
|
-
"
|
|
518
|
-
"
|
|
519
|
-
"
|
|
520
|
-
"that is the whole point of this tool.",
|
|
547
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
548
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
549
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
550
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
521
551
|
"",
|
|
522
|
-
"
|
|
523
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
524
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
525
|
-
" the caller receives it as JSON.",
|
|
526
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
527
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
528
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
529
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
530
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
531
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
552
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
532
553
|
"",
|
|
533
|
-
"
|
|
554
|
+
"Available methods:"
|
|
534
555
|
].join(`
|
|
535
556
|
`);
|
|
536
557
|
function resolveCodeModeClientConfig(client) {
|
|
@@ -578,10 +599,7 @@ function buildCodeModeTool(client, options) {
|
|
|
578
599
|
const serverCodeModeConfig = resolveCodeModeClientConfig(client);
|
|
579
600
|
const sandboxOverrides = options.sandbox ?? {};
|
|
580
601
|
const description = `${DEFAULT_INSTRUCTIONS}
|
|
581
|
-
|
|
582
|
-
\`\`\`typescript
|
|
583
|
-
${generated.source}
|
|
584
|
-
\`\`\``;
|
|
602
|
+
${generated.compact}`;
|
|
585
603
|
const execute = async ({ code }) => {
|
|
586
604
|
const publicUrl = resolveCodeModePublicUrl({
|
|
587
605
|
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
@@ -598,11 +616,33 @@ ${generated.source}
|
|
|
598
616
|
};
|
|
599
617
|
}
|
|
600
618
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
619
|
+
let resolvedTokens = providerTokens;
|
|
620
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
621
|
+
const oauthManager = client.oauthManager;
|
|
622
|
+
if (oauthManager) {
|
|
623
|
+
resolvedTokens = {};
|
|
624
|
+
const clientIntegrations = client.integrations || [];
|
|
625
|
+
for (const integration of clientIntegrations) {
|
|
626
|
+
if (integration.oauth) {
|
|
627
|
+
const provider = integration.oauth.provider;
|
|
628
|
+
try {
|
|
629
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
630
|
+
if (tokenData?.accessToken) {
|
|
631
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
632
|
+
}
|
|
633
|
+
} catch {}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
637
|
+
resolvedTokens = undefined;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
601
641
|
return executeSandboxCode({
|
|
602
642
|
code,
|
|
603
643
|
mcpUrl,
|
|
604
644
|
apiKey,
|
|
605
|
-
providerTokens,
|
|
645
|
+
providerTokens: resolvedTokens,
|
|
606
646
|
context,
|
|
607
647
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
608
648
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
|
@@ -611,7 +651,8 @@ ${generated.source}
|
|
|
611
651
|
networkPolicy: sandboxOverrides.networkPolicy ?? serverCodeModeConfig.networkPolicy
|
|
612
652
|
});
|
|
613
653
|
};
|
|
614
|
-
|
|
654
|
+
const availableIntegrations = Object.keys(generated.perIntegration);
|
|
655
|
+
const codeTool = {
|
|
615
656
|
name: CODE_MODE_TOOL_NAME,
|
|
616
657
|
description,
|
|
617
658
|
parameters: {
|
|
@@ -627,6 +668,29 @@ ${generated.source}
|
|
|
627
668
|
},
|
|
628
669
|
execute
|
|
629
670
|
};
|
|
671
|
+
const typesTool = {
|
|
672
|
+
name: TYPES_TOOL_NAME,
|
|
673
|
+
description: "Get full TypeScript type definitions (method signatures, parameter types, JSDoc) for a specific integration. " + `Available integrations: ${availableIntegrations.join(", ")}.`,
|
|
674
|
+
parameters: {
|
|
675
|
+
type: "object",
|
|
676
|
+
properties: {
|
|
677
|
+
integration: {
|
|
678
|
+
type: "string",
|
|
679
|
+
description: `Integration name to get types for (${availableIntegrations.join(", ")}).`
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
required: ["integration"],
|
|
683
|
+
additionalProperties: false
|
|
684
|
+
},
|
|
685
|
+
execute: ({ integration }) => {
|
|
686
|
+
const types = generated.perIntegration[integration];
|
|
687
|
+
if (!types) {
|
|
688
|
+
return { error: `Unknown integration "${integration}".`, available: availableIntegrations };
|
|
689
|
+
}
|
|
690
|
+
return { types };
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
return { codeTool, typesTool };
|
|
630
694
|
}
|
|
631
695
|
export {
|
|
632
696
|
generateCodeModeTypes,
|
|
@@ -634,6 +698,7 @@ export {
|
|
|
634
698
|
canUseCodeMode,
|
|
635
699
|
buildCodeModeTool,
|
|
636
700
|
__setSandboxFactoryForTests,
|
|
701
|
+
TYPES_TOOL_NAME,
|
|
637
702
|
RUNTIME_STUB_SOURCE,
|
|
638
703
|
CODE_MODE_TOOL_NAME
|
|
639
704
|
};
|
|
@@ -12,6 +12,7 @@ import type { MCPContext } from "../config/types.js";
|
|
|
12
12
|
import type { MCPTool } from "../protocol/messages.js";
|
|
13
13
|
import { type ExecuteSandboxCodeResult } from "./executor.js";
|
|
14
14
|
export declare const CODE_MODE_TOOL_NAME = "execute_code";
|
|
15
|
+
export declare const TYPES_TOOL_NAME = "get_integration_types";
|
|
15
16
|
export interface CodeModeToolOptions {
|
|
16
17
|
/** Enabled MCP tools (already fetched by the caller). */
|
|
17
18
|
tools: MCPTool[];
|
|
@@ -61,6 +62,33 @@ export interface CodeModeToolDefinition {
|
|
|
61
62
|
code: string;
|
|
62
63
|
}) => Promise<ExecuteSandboxCodeResult>;
|
|
63
64
|
}
|
|
65
|
+
export interface TypesToolDefinition {
|
|
66
|
+
name: string;
|
|
67
|
+
description: string;
|
|
68
|
+
parameters: {
|
|
69
|
+
type: "object";
|
|
70
|
+
properties: {
|
|
71
|
+
integration: {
|
|
72
|
+
type: "string";
|
|
73
|
+
description: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
required: ["integration"];
|
|
77
|
+
additionalProperties: false;
|
|
78
|
+
};
|
|
79
|
+
execute: (input: {
|
|
80
|
+
integration: string;
|
|
81
|
+
}) => {
|
|
82
|
+
types: string;
|
|
83
|
+
} | {
|
|
84
|
+
error: string;
|
|
85
|
+
available: string[];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface CodeModeTools {
|
|
89
|
+
codeTool: CodeModeToolDefinition;
|
|
90
|
+
typesTool: TypesToolDefinition;
|
|
91
|
+
}
|
|
64
92
|
export declare function resolveCodeModeClientConfig(client: MCPClient<any>): {
|
|
65
93
|
publicUrl?: string;
|
|
66
94
|
runtime?: "node24" | "node22";
|
|
@@ -100,9 +128,9 @@ export declare function __resetCodeModeFallbackWarnings(): void;
|
|
|
100
128
|
*/
|
|
101
129
|
export declare function warnCodeModeFallback(reason: CodeModeUnavailableReason): void;
|
|
102
130
|
/**
|
|
103
|
-
* Build the `execute_code`
|
|
104
|
-
*
|
|
105
|
-
*
|
|
131
|
+
* Build the `execute_code` and `get_integration_types` tool definitions.
|
|
132
|
+
* The compact method listing goes in execute_code's description; full
|
|
133
|
+
* TypeScript types are served on demand via get_integration_types.
|
|
106
134
|
*/
|
|
107
|
-
export declare function buildCodeModeTool(client: MCPClient<any>, options: CodeModeToolOptions):
|
|
135
|
+
export declare function buildCodeModeTool(client: MCPClient<any>, options: CodeModeToolOptions): CodeModeTools;
|
|
108
136
|
//# sourceMappingURL=tool-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-builder.d.ts","sourceRoot":"","sources":["../../../src/code-mode/tool-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAIL,KAAK,wBAAwB,EAC9B,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-builder.d.ts","sourceRoot":"","sources":["../../../src/code-mode/tool-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAIL,KAAK,wBAAwB,EAC9B,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,eAAe,0BAA0B,CAAC;AAEvD,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,iCAAiC;IACjC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;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