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/index.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
|
// anthropic.ts
|
|
@@ -5049,8 +5113,11 @@ async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
|
5049
5113
|
try {
|
|
5050
5114
|
let result;
|
|
5051
5115
|
if (toolUse.name === CODE_MODE_TOOL_NAME) {
|
|
5052
|
-
const codeTool = await getCodeModeTool();
|
|
5116
|
+
const { codeTool } = await getCodeModeTool();
|
|
5053
5117
|
result = await codeTool.execute(toolUse.input);
|
|
5118
|
+
} else if (toolUse.name === TYPES_TOOL_NAME) {
|
|
5119
|
+
const { typesTool } = await getCodeModeTool();
|
|
5120
|
+
result = typesTool.execute(toolUse.input);
|
|
5054
5121
|
} else if (triggerTools && triggerTools[toolUse.name]) {
|
|
5055
5122
|
result = await triggerTools[toolUse.name].execute(toolUse.input);
|
|
5056
5123
|
} else {
|
|
@@ -5097,7 +5164,7 @@ async function getAnthropicTools(client, options) {
|
|
|
5097
5164
|
}
|
|
5098
5165
|
}
|
|
5099
5166
|
const anthropicTools = effectiveMode === "code" ? (() => {
|
|
5100
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5167
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5101
5168
|
tools: mcpTools,
|
|
5102
5169
|
providerTokens,
|
|
5103
5170
|
context: options?.context,
|
|
@@ -5111,6 +5178,14 @@ async function getAnthropicTools(client, options) {
|
|
|
5111
5178
|
properties: codeTool.parameters.properties,
|
|
5112
5179
|
required: [...codeTool.parameters.required]
|
|
5113
5180
|
}
|
|
5181
|
+
}, {
|
|
5182
|
+
name: TYPES_TOOL_NAME,
|
|
5183
|
+
description: typesTool.description,
|
|
5184
|
+
input_schema: {
|
|
5185
|
+
type: "object",
|
|
5186
|
+
properties: typesTool.parameters.properties,
|
|
5187
|
+
required: [...typesTool.parameters.required]
|
|
5188
|
+
}
|
|
5114
5189
|
}];
|
|
5115
5190
|
})() : mcpTools.map((mcpTool) => convertMCPToolToAnthropic(mcpTool, client, finalOptions));
|
|
5116
5191
|
const triggerConfig = client.__triggerConfig;
|
|
@@ -5258,8 +5333,11 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
5258
5333
|
const args = call.args || {};
|
|
5259
5334
|
let result;
|
|
5260
5335
|
if (call.name === CODE_MODE_TOOL_NAME) {
|
|
5261
|
-
const codeTool = await getCodeModeTool();
|
|
5336
|
+
const { codeTool } = await getCodeModeTool();
|
|
5262
5337
|
result = await codeTool.execute(args);
|
|
5338
|
+
} else if (call.name === TYPES_TOOL_NAME) {
|
|
5339
|
+
const { typesTool } = await getCodeModeTool();
|
|
5340
|
+
result = typesTool.execute(args);
|
|
5263
5341
|
} else if (triggerTools && triggerTools[call.name]) {
|
|
5264
5342
|
result = await triggerTools[call.name].execute(args);
|
|
5265
5343
|
} else {
|
|
@@ -5294,7 +5372,7 @@ async function getGoogleTools(client, options) {
|
|
|
5294
5372
|
let googleTools;
|
|
5295
5373
|
if (effectiveMode === "code") {
|
|
5296
5374
|
const TypeEnum = await getGoogleType();
|
|
5297
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5375
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5298
5376
|
tools: mcpTools,
|
|
5299
5377
|
providerTokens,
|
|
5300
5378
|
context: options?.context,
|
|
@@ -5313,6 +5391,19 @@ async function getGoogleTools(client, options) {
|
|
|
5313
5391
|
},
|
|
5314
5392
|
required: ["code"]
|
|
5315
5393
|
}
|
|
5394
|
+
}, {
|
|
5395
|
+
name: TYPES_TOOL_NAME,
|
|
5396
|
+
description: typesTool.description,
|
|
5397
|
+
parameters: {
|
|
5398
|
+
type: TypeEnum.OBJECT,
|
|
5399
|
+
properties: {
|
|
5400
|
+
integration: {
|
|
5401
|
+
type: TypeEnum.STRING,
|
|
5402
|
+
description: typesTool.parameters.properties.integration.description
|
|
5403
|
+
}
|
|
5404
|
+
},
|
|
5405
|
+
required: ["integration"]
|
|
5406
|
+
}
|
|
5316
5407
|
}];
|
|
5317
5408
|
} else {
|
|
5318
5409
|
googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
|
|
@@ -5429,7 +5520,7 @@ async function getVercelAITools(client, options) {
|
|
|
5429
5520
|
}
|
|
5430
5521
|
}
|
|
5431
5522
|
if (effectiveMode === "code") {
|
|
5432
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5523
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5433
5524
|
tools: mcpTools,
|
|
5434
5525
|
providerTokens,
|
|
5435
5526
|
context: options?.context,
|
|
@@ -5442,6 +5533,13 @@ async function getVercelAITools(client, options) {
|
|
|
5442
5533
|
}),
|
|
5443
5534
|
execute: async (args) => codeTool.execute(args)
|
|
5444
5535
|
};
|
|
5536
|
+
vercelTools[TYPES_TOOL_NAME] = {
|
|
5537
|
+
description: typesTool.description,
|
|
5538
|
+
inputSchema: exports_external.object({
|
|
5539
|
+
integration: exports_external.string().describe(typesTool.parameters.properties.integration.description)
|
|
5540
|
+
}),
|
|
5541
|
+
execute: async (args) => typesTool.execute(args)
|
|
5542
|
+
};
|
|
5445
5543
|
} else {
|
|
5446
5544
|
for (const mcpTool of mcpTools) {
|
|
5447
5545
|
vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client, finalOptions);
|
|
@@ -5490,7 +5588,7 @@ async function getOpenAITools(client, options) {
|
|
|
5490
5588
|
}
|
|
5491
5589
|
}
|
|
5492
5590
|
const openaiTools = effectiveMode === "code" ? (() => {
|
|
5493
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5591
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5494
5592
|
tools: mcpTools,
|
|
5495
5593
|
providerTokens,
|
|
5496
5594
|
context: options?.context,
|
|
@@ -5502,6 +5600,12 @@ async function getOpenAITools(client, options) {
|
|
|
5502
5600
|
description: codeTool.description,
|
|
5503
5601
|
parameters: codeTool.parameters,
|
|
5504
5602
|
strict: options?.strict ?? null
|
|
5603
|
+
}, {
|
|
5604
|
+
type: "function",
|
|
5605
|
+
name: TYPES_TOOL_NAME,
|
|
5606
|
+
description: typesTool.description,
|
|
5607
|
+
parameters: typesTool.parameters,
|
|
5608
|
+
strict: options?.strict ?? null
|
|
5505
5609
|
}];
|
|
5506
5610
|
})() : mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
|
|
5507
5611
|
const triggerConfig = client.__triggerConfig;
|
|
@@ -5552,8 +5656,11 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
5552
5656
|
const args = JSON.parse(toolCall.arguments);
|
|
5553
5657
|
let result;
|
|
5554
5658
|
if (toolCall.name === CODE_MODE_TOOL_NAME) {
|
|
5555
|
-
const codeTool = await getCodeModeTool();
|
|
5659
|
+
const { codeTool } = await getCodeModeTool();
|
|
5556
5660
|
result = await codeTool.execute(args);
|
|
5661
|
+
} else if (toolCall.name === TYPES_TOOL_NAME) {
|
|
5662
|
+
const { typesTool } = await getCodeModeTool();
|
|
5663
|
+
result = typesTool.execute(args);
|
|
5557
5664
|
} else if (triggerTools && triggerTools[toolCall.name]) {
|
|
5558
5665
|
result = await triggerTools[toolCall.name].execute(args);
|
|
5559
5666
|
} else {
|
package/dist/ai/openai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAUjH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE;QACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,GAAG,IAAI,CAAC;IACT,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAiCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAiFvB;AA6GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,QAAQ,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC,CAAA;CAAE,EAChE,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,GAAG;IAAE,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAyB3H"}
|
package/dist/ai/openai.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
|
// openai.ts
|
|
@@ -5049,7 +5113,7 @@ async function getOpenAITools(client, options) {
|
|
|
5049
5113
|
}
|
|
5050
5114
|
}
|
|
5051
5115
|
const openaiTools = effectiveMode === "code" ? (() => {
|
|
5052
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5116
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5053
5117
|
tools: mcpTools,
|
|
5054
5118
|
providerTokens,
|
|
5055
5119
|
context: options?.context,
|
|
@@ -5061,6 +5125,12 @@ async function getOpenAITools(client, options) {
|
|
|
5061
5125
|
description: codeTool.description,
|
|
5062
5126
|
parameters: codeTool.parameters,
|
|
5063
5127
|
strict: options?.strict ?? null
|
|
5128
|
+
}, {
|
|
5129
|
+
type: "function",
|
|
5130
|
+
name: TYPES_TOOL_NAME,
|
|
5131
|
+
description: typesTool.description,
|
|
5132
|
+
parameters: typesTool.parameters,
|
|
5133
|
+
strict: options?.strict ?? null
|
|
5064
5134
|
}];
|
|
5065
5135
|
})() : mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
|
|
5066
5136
|
const triggerConfig = client.__triggerConfig;
|
|
@@ -5111,8 +5181,11 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
5111
5181
|
const args = JSON.parse(toolCall.arguments);
|
|
5112
5182
|
let result;
|
|
5113
5183
|
if (toolCall.name === CODE_MODE_TOOL_NAME) {
|
|
5114
|
-
const codeTool = await getCodeModeTool();
|
|
5184
|
+
const { codeTool } = await getCodeModeTool();
|
|
5115
5185
|
result = await codeTool.execute(args);
|
|
5186
|
+
} else if (toolCall.name === TYPES_TOOL_NAME) {
|
|
5187
|
+
const { typesTool } = await getCodeModeTool();
|
|
5188
|
+
result = typesTool.execute(args);
|
|
5116
5189
|
} else if (triggerTools && triggerTools[toolCall.name]) {
|
|
5117
5190
|
result = await triggerTools[toolCall.name].execute(args);
|
|
5118
5191
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../../src/ai/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../../src/ai/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AAUpB;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AA+BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,oBAAoB,gCAyE/B"}
|