integrate-sdk 0.9.17-dev.0 → 0.9.18-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/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
- sections.push(formatDescription(tool.description, " "));
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
- sections.push(` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`);
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
- "You are given a single tool: `execute_code`. Instead of calling individual MCP tools,",
4908
- "you write a short async TypeScript/JavaScript snippet that uses the typed `client`",
4909
- "object below, and the snippet runs in an isolated sandbox which dispatches the actual",
4910
- "tool calls. Chain multiple operations together in one snippet whenever possible —",
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
- "Rules:",
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
- "API surface:"
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
@@ -4996,7 +5014,8 @@ ${generated.source}
4996
5014
  networkPolicy: sandboxOverrides.networkPolicy ?? serverCodeModeConfig.networkPolicy
4997
5015
  });
4998
5016
  };
4999
- return {
5017
+ const availableIntegrations = Object.keys(generated.perIntegration);
5018
+ const codeTool = {
5000
5019
  name: CODE_MODE_TOOL_NAME,
5001
5020
  description,
5002
5021
  parameters: {
@@ -5012,6 +5031,29 @@ ${generated.source}
5012
5031
  },
5013
5032
  execute
5014
5033
  };
5034
+ const typesTool = {
5035
+ name: TYPES_TOOL_NAME,
5036
+ description: "Get full TypeScript type definitions (method signatures, parameter types, JSDoc) for a specific integration. " + `Available integrations: ${availableIntegrations.join(", ")}.`,
5037
+ parameters: {
5038
+ type: "object",
5039
+ properties: {
5040
+ integration: {
5041
+ type: "string",
5042
+ description: `Integration name to get types for (${availableIntegrations.join(", ")}).`
5043
+ }
5044
+ },
5045
+ required: ["integration"],
5046
+ additionalProperties: false
5047
+ },
5048
+ execute: ({ integration }) => {
5049
+ const types2 = generated.perIntegration[integration];
5050
+ if (!types2) {
5051
+ return { error: `Unknown integration "${integration}".`, available: availableIntegrations };
5052
+ }
5053
+ return { types: types2 };
5054
+ }
5055
+ };
5056
+ return { codeTool, typesTool };
5015
5057
  }
5016
5058
 
5017
5059
  // anthropic.ts
@@ -5049,8 +5091,11 @@ async function handleAnthropicToolCalls(client, messageContent, options) {
5049
5091
  try {
5050
5092
  let result;
5051
5093
  if (toolUse.name === CODE_MODE_TOOL_NAME) {
5052
- const codeTool = await getCodeModeTool();
5094
+ const { codeTool } = await getCodeModeTool();
5053
5095
  result = await codeTool.execute(toolUse.input);
5096
+ } else if (toolUse.name === TYPES_TOOL_NAME) {
5097
+ const { typesTool } = await getCodeModeTool();
5098
+ result = typesTool.execute(toolUse.input);
5054
5099
  } else if (triggerTools && triggerTools[toolUse.name]) {
5055
5100
  result = await triggerTools[toolUse.name].execute(toolUse.input);
5056
5101
  } else {
@@ -5097,7 +5142,7 @@ async function getAnthropicTools(client, options) {
5097
5142
  }
5098
5143
  }
5099
5144
  const anthropicTools = effectiveMode === "code" ? (() => {
5100
- const codeTool = buildCodeModeTool(client, {
5145
+ const { codeTool, typesTool } = buildCodeModeTool(client, {
5101
5146
  tools: mcpTools,
5102
5147
  providerTokens,
5103
5148
  context: options?.context,
@@ -5111,6 +5156,14 @@ async function getAnthropicTools(client, options) {
5111
5156
  properties: codeTool.parameters.properties,
5112
5157
  required: [...codeTool.parameters.required]
5113
5158
  }
5159
+ }, {
5160
+ name: TYPES_TOOL_NAME,
5161
+ description: typesTool.description,
5162
+ input_schema: {
5163
+ type: "object",
5164
+ properties: typesTool.parameters.properties,
5165
+ required: [...typesTool.parameters.required]
5166
+ }
5114
5167
  }];
5115
5168
  })() : mcpTools.map((mcpTool) => convertMCPToolToAnthropic(mcpTool, client, finalOptions));
5116
5169
  const triggerConfig = client.__triggerConfig;
@@ -5258,8 +5311,11 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
5258
5311
  const args = call.args || {};
5259
5312
  let result;
5260
5313
  if (call.name === CODE_MODE_TOOL_NAME) {
5261
- const codeTool = await getCodeModeTool();
5314
+ const { codeTool } = await getCodeModeTool();
5262
5315
  result = await codeTool.execute(args);
5316
+ } else if (call.name === TYPES_TOOL_NAME) {
5317
+ const { typesTool } = await getCodeModeTool();
5318
+ result = typesTool.execute(args);
5263
5319
  } else if (triggerTools && triggerTools[call.name]) {
5264
5320
  result = await triggerTools[call.name].execute(args);
5265
5321
  } else {
@@ -5294,7 +5350,7 @@ async function getGoogleTools(client, options) {
5294
5350
  let googleTools;
5295
5351
  if (effectiveMode === "code") {
5296
5352
  const TypeEnum = await getGoogleType();
5297
- const codeTool = buildCodeModeTool(client, {
5353
+ const { codeTool, typesTool } = buildCodeModeTool(client, {
5298
5354
  tools: mcpTools,
5299
5355
  providerTokens,
5300
5356
  context: options?.context,
@@ -5313,6 +5369,19 @@ async function getGoogleTools(client, options) {
5313
5369
  },
5314
5370
  required: ["code"]
5315
5371
  }
5372
+ }, {
5373
+ name: TYPES_TOOL_NAME,
5374
+ description: typesTool.description,
5375
+ parameters: {
5376
+ type: TypeEnum.OBJECT,
5377
+ properties: {
5378
+ integration: {
5379
+ type: TypeEnum.STRING,
5380
+ description: typesTool.parameters.properties.integration.description
5381
+ }
5382
+ },
5383
+ required: ["integration"]
5384
+ }
5316
5385
  }];
5317
5386
  } else {
5318
5387
  googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
@@ -5429,7 +5498,7 @@ async function getVercelAITools(client, options) {
5429
5498
  }
5430
5499
  }
5431
5500
  if (effectiveMode === "code") {
5432
- const codeTool = buildCodeModeTool(client, {
5501
+ const { codeTool, typesTool } = buildCodeModeTool(client, {
5433
5502
  tools: mcpTools,
5434
5503
  providerTokens,
5435
5504
  context: options?.context,
@@ -5442,6 +5511,13 @@ async function getVercelAITools(client, options) {
5442
5511
  }),
5443
5512
  execute: async (args) => codeTool.execute(args)
5444
5513
  };
5514
+ vercelTools[TYPES_TOOL_NAME] = {
5515
+ description: typesTool.description,
5516
+ inputSchema: exports_external.object({
5517
+ integration: exports_external.string().describe(typesTool.parameters.properties.integration.description)
5518
+ }),
5519
+ execute: async (args) => typesTool.execute(args)
5520
+ };
5445
5521
  } else {
5446
5522
  for (const mcpTool of mcpTools) {
5447
5523
  vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client, finalOptions);
@@ -5490,7 +5566,7 @@ async function getOpenAITools(client, options) {
5490
5566
  }
5491
5567
  }
5492
5568
  const openaiTools = effectiveMode === "code" ? (() => {
5493
- const codeTool = buildCodeModeTool(client, {
5569
+ const { codeTool, typesTool } = buildCodeModeTool(client, {
5494
5570
  tools: mcpTools,
5495
5571
  providerTokens,
5496
5572
  context: options?.context,
@@ -5502,6 +5578,12 @@ async function getOpenAITools(client, options) {
5502
5578
  description: codeTool.description,
5503
5579
  parameters: codeTool.parameters,
5504
5580
  strict: options?.strict ?? null
5581
+ }, {
5582
+ type: "function",
5583
+ name: TYPES_TOOL_NAME,
5584
+ description: typesTool.description,
5585
+ parameters: typesTool.parameters,
5586
+ strict: options?.strict ?? null
5505
5587
  }];
5506
5588
  })() : mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
5507
5589
  const triggerConfig = client.__triggerConfig;
@@ -5552,8 +5634,11 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
5552
5634
  const args = JSON.parse(toolCall.arguments);
5553
5635
  let result;
5554
5636
  if (toolCall.name === CODE_MODE_TOOL_NAME) {
5555
- const codeTool = await getCodeModeTool();
5637
+ const { codeTool } = await getCodeModeTool();
5556
5638
  result = await codeTool.execute(args);
5639
+ } else if (toolCall.name === TYPES_TOOL_NAME) {
5640
+ const { typesTool } = await getCodeModeTool();
5641
+ result = typesTool.execute(args);
5557
5642
  } else if (triggerTools && triggerTools[toolCall.name]) {
5558
5643
  result = await triggerTools[toolCall.name].execute(args);
5559
5644
  } else {
@@ -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;AASjH,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;IAC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AE,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
- sections.push(formatDescription(tool.description, " "));
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
- sections.push(` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`);
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
- "You are given a single tool: `execute_code`. Instead of calling individual MCP tools,",
4908
- "you write a short async TypeScript/JavaScript snippet that uses the typed `client`",
4909
- "object below, and the snippet runs in an isolated sandbox which dispatches the actual",
4910
- "tool calls. Chain multiple operations together in one snippet whenever possible —",
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
- "Rules:",
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
- "API surface:"
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
@@ -4996,7 +5014,8 @@ ${generated.source}
4996
5014
  networkPolicy: sandboxOverrides.networkPolicy ?? serverCodeModeConfig.networkPolicy
4997
5015
  });
4998
5016
  };
4999
- return {
5017
+ const availableIntegrations = Object.keys(generated.perIntegration);
5018
+ const codeTool = {
5000
5019
  name: CODE_MODE_TOOL_NAME,
5001
5020
  description,
5002
5021
  parameters: {
@@ -5012,6 +5031,29 @@ ${generated.source}
5012
5031
  },
5013
5032
  execute
5014
5033
  };
5034
+ const typesTool = {
5035
+ name: TYPES_TOOL_NAME,
5036
+ description: "Get full TypeScript type definitions (method signatures, parameter types, JSDoc) for a specific integration. " + `Available integrations: ${availableIntegrations.join(", ")}.`,
5037
+ parameters: {
5038
+ type: "object",
5039
+ properties: {
5040
+ integration: {
5041
+ type: "string",
5042
+ description: `Integration name to get types for (${availableIntegrations.join(", ")}).`
5043
+ }
5044
+ },
5045
+ required: ["integration"],
5046
+ additionalProperties: false
5047
+ },
5048
+ execute: ({ integration }) => {
5049
+ const types2 = generated.perIntegration[integration];
5050
+ if (!types2) {
5051
+ return { error: `Unknown integration "${integration}".`, available: availableIntegrations };
5052
+ }
5053
+ return { types: types2 };
5054
+ }
5055
+ };
5056
+ return { codeTool, typesTool };
5015
5057
  }
5016
5058
 
5017
5059
  // openai.ts
@@ -5049,7 +5091,7 @@ async function getOpenAITools(client, options) {
5049
5091
  }
5050
5092
  }
5051
5093
  const openaiTools = effectiveMode === "code" ? (() => {
5052
- const codeTool = buildCodeModeTool(client, {
5094
+ const { codeTool, typesTool } = buildCodeModeTool(client, {
5053
5095
  tools: mcpTools,
5054
5096
  providerTokens,
5055
5097
  context: options?.context,
@@ -5061,6 +5103,12 @@ async function getOpenAITools(client, options) {
5061
5103
  description: codeTool.description,
5062
5104
  parameters: codeTool.parameters,
5063
5105
  strict: options?.strict ?? null
5106
+ }, {
5107
+ type: "function",
5108
+ name: TYPES_TOOL_NAME,
5109
+ description: typesTool.description,
5110
+ parameters: typesTool.parameters,
5111
+ strict: options?.strict ?? null
5064
5112
  }];
5065
5113
  })() : mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
5066
5114
  const triggerConfig = client.__triggerConfig;
@@ -5111,8 +5159,11 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
5111
5159
  const args = JSON.parse(toolCall.arguments);
5112
5160
  let result;
5113
5161
  if (toolCall.name === CODE_MODE_TOOL_NAME) {
5114
- const codeTool = await getCodeModeTool();
5162
+ const { codeTool } = await getCodeModeTool();
5115
5163
  result = await codeTool.execute(args);
5164
+ } else if (toolCall.name === TYPES_TOOL_NAME) {
5165
+ const { typesTool } = await getCodeModeTool();
5166
+ result = typesTool.execute(args);
5116
5167
  } else if (triggerTools && triggerTools[toolCall.name]) {
5117
5168
  result = await triggerTools[toolCall.name].execute(args);
5118
5169
  } 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;AASpB;;;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;AAC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