integrate-sdk 0.9.4-dev.0 → 0.9.8-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.
Files changed (55) hide show
  1. package/dist/adapters/auto-routes.js +76 -16
  2. package/dist/adapters/index.js +76 -16
  3. package/dist/adapters/nextjs.js +76 -16
  4. package/dist/adapters/node.js +76 -16
  5. package/dist/adapters/svelte-kit.js +76 -16
  6. package/dist/adapters/tanstack-start.js +76 -16
  7. package/dist/ai/anthropic.d.ts +2 -2
  8. package/dist/ai/anthropic.d.ts.map +1 -1
  9. package/dist/ai/anthropic.js +45 -9
  10. package/dist/ai/google.d.ts +2 -2
  11. package/dist/ai/google.d.ts.map +1 -1
  12. package/dist/ai/google.js +45 -9
  13. package/dist/ai/index.js +51 -15
  14. package/dist/ai/openai.d.ts +2 -2
  15. package/dist/ai/openai.d.ts.map +1 -1
  16. package/dist/ai/openai.js +45 -9
  17. package/dist/ai/trigger-tools.d.ts +7 -7
  18. package/dist/ai/trigger-tools.js +7 -7
  19. package/dist/ai/vercel-ai.d.ts +2 -2
  20. package/dist/ai/vercel-ai.d.ts.map +1 -1
  21. package/dist/ai/vercel-ai.js +45 -9
  22. package/dist/code-mode/executor.d.ts +5 -0
  23. package/dist/code-mode/executor.d.ts.map +1 -1
  24. package/dist/code-mode/executor.js +35 -0
  25. package/dist/code-mode/index.d.ts +1 -1
  26. package/dist/code-mode/index.d.ts.map +1 -1
  27. package/dist/code-mode/index.js +43 -0
  28. package/dist/code-mode/runtime-stub.d.ts +1 -1
  29. package/dist/code-mode/runtime-stub.d.ts.map +1 -1
  30. package/dist/code-mode/runtime-stub.js +2 -0
  31. package/dist/code-mode/tool-builder.d.ts +1 -0
  32. package/dist/code-mode/tool-builder.d.ts.map +1 -1
  33. package/dist/code-mode/tool-builder.js +43 -0
  34. package/dist/index.js +76 -16
  35. package/dist/oauth.js +76 -16
  36. package/dist/server.js +76 -16
  37. package/dist/src/ai/anthropic.d.ts +2 -2
  38. package/dist/src/ai/anthropic.d.ts.map +1 -1
  39. package/dist/src/ai/google.d.ts +2 -2
  40. package/dist/src/ai/google.d.ts.map +1 -1
  41. package/dist/src/ai/openai.d.ts +2 -2
  42. package/dist/src/ai/openai.d.ts.map +1 -1
  43. package/dist/src/ai/trigger-tools.d.ts +7 -7
  44. package/dist/src/ai/vercel-ai.d.ts +2 -2
  45. package/dist/src/ai/vercel-ai.d.ts.map +1 -1
  46. package/dist/src/code-mode/executor.d.ts +5 -0
  47. package/dist/src/code-mode/executor.d.ts.map +1 -1
  48. package/dist/src/code-mode/index.d.ts +1 -1
  49. package/dist/src/code-mode/index.d.ts.map +1 -1
  50. package/dist/src/code-mode/runtime-stub.d.ts +1 -1
  51. package/dist/src/code-mode/runtime-stub.d.ts.map +1 -1
  52. package/dist/src/code-mode/tool-builder.d.ts +1 -0
  53. package/dist/src/code-mode/tool-builder.d.ts.map +1 -1
  54. package/dist/src/server.d.ts.map +1 -1
  55. package/package.json +3 -6
package/dist/ai/google.js CHANGED
@@ -4251,7 +4251,7 @@ function calculateHasMore(offset, returnedCount, total) {
4251
4251
  function createTriggerTools(config, context) {
4252
4252
  const { callbacks } = config;
4253
4253
  return {
4254
- create_trigger: {
4254
+ trigger_create: {
4255
4255
  description: "Schedule a tool to run at a specific time or on a recurring schedule. Use this when the user wants to do something later.",
4256
4256
  inputSchema: exports_external.object({
4257
4257
  name: exports_external.string().optional().describe("Human-readable trigger name"),
@@ -4285,7 +4285,7 @@ function createTriggerTools(config, context) {
4285
4285
  return callbacks.create(trigger, context);
4286
4286
  }
4287
4287
  },
4288
- list_triggers: {
4288
+ trigger_list: {
4289
4289
  description: "List all scheduled triggers with optional filtering by status or tool name",
4290
4290
  inputSchema: exports_external.object({
4291
4291
  status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
@@ -4309,7 +4309,7 @@ function createTriggerTools(config, context) {
4309
4309
  };
4310
4310
  }
4311
4311
  },
4312
- get_trigger: {
4312
+ trigger_get: {
4313
4313
  description: "Get details of a specific trigger by its ID",
4314
4314
  inputSchema: exports_external.object({
4315
4315
  triggerId: exports_external.string().describe("The trigger ID to retrieve")
@@ -4322,7 +4322,7 @@ function createTriggerTools(config, context) {
4322
4322
  return trigger;
4323
4323
  }
4324
4324
  },
4325
- update_trigger: {
4325
+ trigger_update: {
4326
4326
  description: "Update a trigger's properties like name, description, arguments, or schedule",
4327
4327
  inputSchema: exports_external.object({
4328
4328
  triggerId: exports_external.string().describe("The trigger ID to update"),
@@ -4349,7 +4349,7 @@ function createTriggerTools(config, context) {
4349
4349
  return callbacks.update(triggerId, updatesWithTimestamp, context);
4350
4350
  }
4351
4351
  },
4352
- delete_trigger: {
4352
+ trigger_delete: {
4353
4353
  description: "Delete a trigger permanently. This cannot be undone.",
4354
4354
  inputSchema: exports_external.object({
4355
4355
  triggerId: exports_external.string().describe("The trigger ID to delete")
@@ -4359,7 +4359,7 @@ function createTriggerTools(config, context) {
4359
4359
  return { success: true, message: `Trigger ${args.triggerId} deleted` };
4360
4360
  }
4361
4361
  },
4362
- pause_trigger: {
4362
+ trigger_pause: {
4363
4363
  description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
4364
4364
  inputSchema: exports_external.object({
4365
4365
  triggerId: exports_external.string().describe("The trigger ID to pause")
@@ -4379,7 +4379,7 @@ function createTriggerTools(config, context) {
4379
4379
  }, context);
4380
4380
  }
4381
4381
  },
4382
- resume_trigger: {
4382
+ trigger_resume: {
4383
4383
  description: "Resume a paused trigger to start executing it again on schedule",
4384
4384
  inputSchema: exports_external.object({
4385
4385
  triggerId: exports_external.string().describe("The trigger ID to resume")
@@ -4621,6 +4621,7 @@ function pascalCase(id) {
4621
4621
  var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
4622
4622
  const MCP_URL = process.env.INTEGRATE_MCP_URL;
4623
4623
  const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
4624
+ const API_KEY = process.env.INTEGRATE_API_KEY || '';
4624
4625
  const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
4625
4626
  const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
4626
4627
  const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
@@ -4639,6 +4640,7 @@ async function callTool(toolName, args) {
4639
4640
  'x-integrate-code-mode': '1',
4640
4641
  };
4641
4642
  if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
4643
+ if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
4642
4644
  if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
4643
4645
  if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
4644
4646
  if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
@@ -4689,6 +4691,29 @@ export { callTool };
4689
4691
 
4690
4692
  // ../code-mode/executor.ts
4691
4693
  var sandboxFactoryOverride = null;
4694
+ var _sandboxAvailableCache = null;
4695
+ var _sandboxForcedUnavailableForTests = false;
4696
+ async function isSandboxAvailable() {
4697
+ if (_sandboxAvailableCache !== null)
4698
+ return _sandboxAvailableCache;
4699
+ if (_sandboxForcedUnavailableForTests) {
4700
+ _sandboxAvailableCache = false;
4701
+ return false;
4702
+ }
4703
+ if (sandboxFactoryOverride) {
4704
+ _sandboxAvailableCache = true;
4705
+ return true;
4706
+ }
4707
+ try {
4708
+ const dynamicImport = new Function("specifier", "return import(specifier)");
4709
+ await dynamicImport("@" + "vercel/sandbox");
4710
+ _sandboxAvailableCache = true;
4711
+ return true;
4712
+ } catch {
4713
+ _sandboxAvailableCache = false;
4714
+ return false;
4715
+ }
4716
+ }
4692
4717
  async function loadSandboxFactory() {
4693
4718
  if (sandboxFactoryOverride)
4694
4719
  return sandboxFactoryOverride;
@@ -4775,6 +4800,8 @@ async function executeSandboxCode(options) {
4775
4800
  const env = {
4776
4801
  INTEGRATE_MCP_URL: options.mcpUrl
4777
4802
  };
4803
+ if (options.apiKey)
4804
+ env.INTEGRATE_API_KEY = options.apiKey;
4778
4805
  if (options.sessionToken)
4779
4806
  env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
4780
4807
  if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
@@ -4866,6 +4893,13 @@ function resolveCodeModeClientConfig(client) {
4866
4893
  const oauthConfig = client.__oauthConfig;
4867
4894
  return oauthConfig?.codeMode ?? {};
4868
4895
  }
4896
+ async function canUseCodeMode(client) {
4897
+ if (!await isSandboxAvailable())
4898
+ return false;
4899
+ const serverConfig = resolveCodeModeClientConfig(client);
4900
+ const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
4901
+ return !!publicUrl;
4902
+ }
4869
4903
  function buildCodeModeTool(client, options) {
4870
4904
  const { tools, providerTokens, context, integrationIds } = options;
4871
4905
  const generated = generateCodeModeTypes(tools);
@@ -4878,6 +4912,7 @@ ${generated.source}
4878
4912
  \`\`\``;
4879
4913
  const execute = async ({ code }) => {
4880
4914
  const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
4915
+ const apiKey = client.__oauthConfig?.apiKey;
4881
4916
  if (!publicUrl) {
4882
4917
  return {
4883
4918
  success: false,
@@ -4892,6 +4927,7 @@ ${generated.source}
4892
4927
  return executeSandboxCode({
4893
4928
  code,
4894
4929
  mcpUrl,
4930
+ apiKey,
4895
4931
  providerTokens,
4896
4932
  context,
4897
4933
  integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
@@ -5043,9 +5079,9 @@ async function getGoogleTools(client, options) {
5043
5079
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
5044
5080
  await ensureClientConnected(client);
5045
5081
  const mcpTools = await client.getEnabledToolsAsync();
5046
- const mode = options?.mode ?? "code";
5082
+ const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
5047
5083
  let googleTools;
5048
- if (mode === "code") {
5084
+ if (effectiveMode === "code") {
5049
5085
  const TypeEnum = await getGoogleType();
5050
5086
  const codeTool = buildCodeModeTool(client, {
5051
5087
  tools: mcpTools,
package/dist/ai/index.js CHANGED
@@ -4251,7 +4251,7 @@ function calculateHasMore(offset, returnedCount, total) {
4251
4251
  function createTriggerTools(config, context) {
4252
4252
  const { callbacks } = config;
4253
4253
  return {
4254
- create_trigger: {
4254
+ trigger_create: {
4255
4255
  description: "Schedule a tool to run at a specific time or on a recurring schedule. Use this when the user wants to do something later.",
4256
4256
  inputSchema: exports_external.object({
4257
4257
  name: exports_external.string().optional().describe("Human-readable trigger name"),
@@ -4285,7 +4285,7 @@ function createTriggerTools(config, context) {
4285
4285
  return callbacks.create(trigger, context);
4286
4286
  }
4287
4287
  },
4288
- list_triggers: {
4288
+ trigger_list: {
4289
4289
  description: "List all scheduled triggers with optional filtering by status or tool name",
4290
4290
  inputSchema: exports_external.object({
4291
4291
  status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
@@ -4309,7 +4309,7 @@ function createTriggerTools(config, context) {
4309
4309
  };
4310
4310
  }
4311
4311
  },
4312
- get_trigger: {
4312
+ trigger_get: {
4313
4313
  description: "Get details of a specific trigger by its ID",
4314
4314
  inputSchema: exports_external.object({
4315
4315
  triggerId: exports_external.string().describe("The trigger ID to retrieve")
@@ -4322,7 +4322,7 @@ function createTriggerTools(config, context) {
4322
4322
  return trigger;
4323
4323
  }
4324
4324
  },
4325
- update_trigger: {
4325
+ trigger_update: {
4326
4326
  description: "Update a trigger's properties like name, description, arguments, or schedule",
4327
4327
  inputSchema: exports_external.object({
4328
4328
  triggerId: exports_external.string().describe("The trigger ID to update"),
@@ -4349,7 +4349,7 @@ function createTriggerTools(config, context) {
4349
4349
  return callbacks.update(triggerId, updatesWithTimestamp, context);
4350
4350
  }
4351
4351
  },
4352
- delete_trigger: {
4352
+ trigger_delete: {
4353
4353
  description: "Delete a trigger permanently. This cannot be undone.",
4354
4354
  inputSchema: exports_external.object({
4355
4355
  triggerId: exports_external.string().describe("The trigger ID to delete")
@@ -4359,7 +4359,7 @@ function createTriggerTools(config, context) {
4359
4359
  return { success: true, message: `Trigger ${args.triggerId} deleted` };
4360
4360
  }
4361
4361
  },
4362
- pause_trigger: {
4362
+ trigger_pause: {
4363
4363
  description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
4364
4364
  inputSchema: exports_external.object({
4365
4365
  triggerId: exports_external.string().describe("The trigger ID to pause")
@@ -4379,7 +4379,7 @@ function createTriggerTools(config, context) {
4379
4379
  }, context);
4380
4380
  }
4381
4381
  },
4382
- resume_trigger: {
4382
+ trigger_resume: {
4383
4383
  description: "Resume a paused trigger to start executing it again on schedule",
4384
4384
  inputSchema: exports_external.object({
4385
4385
  triggerId: exports_external.string().describe("The trigger ID to resume")
@@ -4621,6 +4621,7 @@ function pascalCase(id) {
4621
4621
  var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
4622
4622
  const MCP_URL = process.env.INTEGRATE_MCP_URL;
4623
4623
  const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
4624
+ const API_KEY = process.env.INTEGRATE_API_KEY || '';
4624
4625
  const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
4625
4626
  const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
4626
4627
  const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
@@ -4639,6 +4640,7 @@ async function callTool(toolName, args) {
4639
4640
  'x-integrate-code-mode': '1',
4640
4641
  };
4641
4642
  if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
4643
+ if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
4642
4644
  if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
4643
4645
  if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
4644
4646
  if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
@@ -4689,6 +4691,29 @@ export { callTool };
4689
4691
 
4690
4692
  // ../code-mode/executor.ts
4691
4693
  var sandboxFactoryOverride = null;
4694
+ var _sandboxAvailableCache = null;
4695
+ var _sandboxForcedUnavailableForTests = false;
4696
+ async function isSandboxAvailable() {
4697
+ if (_sandboxAvailableCache !== null)
4698
+ return _sandboxAvailableCache;
4699
+ if (_sandboxForcedUnavailableForTests) {
4700
+ _sandboxAvailableCache = false;
4701
+ return false;
4702
+ }
4703
+ if (sandboxFactoryOverride) {
4704
+ _sandboxAvailableCache = true;
4705
+ return true;
4706
+ }
4707
+ try {
4708
+ const dynamicImport = new Function("specifier", "return import(specifier)");
4709
+ await dynamicImport("@" + "vercel/sandbox");
4710
+ _sandboxAvailableCache = true;
4711
+ return true;
4712
+ } catch {
4713
+ _sandboxAvailableCache = false;
4714
+ return false;
4715
+ }
4716
+ }
4692
4717
  async function loadSandboxFactory() {
4693
4718
  if (sandboxFactoryOverride)
4694
4719
  return sandboxFactoryOverride;
@@ -4775,6 +4800,8 @@ async function executeSandboxCode(options) {
4775
4800
  const env = {
4776
4801
  INTEGRATE_MCP_URL: options.mcpUrl
4777
4802
  };
4803
+ if (options.apiKey)
4804
+ env.INTEGRATE_API_KEY = options.apiKey;
4778
4805
  if (options.sessionToken)
4779
4806
  env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
4780
4807
  if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
@@ -4866,6 +4893,13 @@ function resolveCodeModeClientConfig(client) {
4866
4893
  const oauthConfig = client.__oauthConfig;
4867
4894
  return oauthConfig?.codeMode ?? {};
4868
4895
  }
4896
+ async function canUseCodeMode(client) {
4897
+ if (!await isSandboxAvailable())
4898
+ return false;
4899
+ const serverConfig = resolveCodeModeClientConfig(client);
4900
+ const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
4901
+ return !!publicUrl;
4902
+ }
4869
4903
  function buildCodeModeTool(client, options) {
4870
4904
  const { tools, providerTokens, context, integrationIds } = options;
4871
4905
  const generated = generateCodeModeTypes(tools);
@@ -4878,6 +4912,7 @@ ${generated.source}
4878
4912
  \`\`\``;
4879
4913
  const execute = async ({ code }) => {
4880
4914
  const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
4915
+ const apiKey = client.__oauthConfig?.apiKey;
4881
4916
  if (!publicUrl) {
4882
4917
  return {
4883
4918
  success: false,
@@ -4892,6 +4927,7 @@ ${generated.source}
4892
4927
  return executeSandboxCode({
4893
4928
  code,
4894
4929
  mcpUrl,
4930
+ apiKey,
4895
4931
  providerTokens,
4896
4932
  context,
4897
4933
  integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
@@ -4989,8 +5025,8 @@ async function getAnthropicTools(client, options) {
4989
5025
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
4990
5026
  await ensureClientConnected(client);
4991
5027
  const mcpTools = await client.getEnabledToolsAsync();
4992
- const mode = options?.mode ?? "code";
4993
- const anthropicTools = mode === "code" ? (() => {
5028
+ const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
5029
+ const anthropicTools = effectiveMode === "code" ? (() => {
4994
5030
  const codeTool = buildCodeModeTool(client, {
4995
5031
  tools: mcpTools,
4996
5032
  providerTokens,
@@ -5173,9 +5209,9 @@ async function getGoogleTools(client, options) {
5173
5209
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
5174
5210
  await ensureClientConnected(client);
5175
5211
  const mcpTools = await client.getEnabledToolsAsync();
5176
- const mode = options?.mode ?? "code";
5212
+ const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
5177
5213
  let googleTools;
5178
- if (mode === "code") {
5214
+ if (effectiveMode === "code") {
5179
5215
  const TypeEnum = await getGoogleType();
5180
5216
  const codeTool = buildCodeModeTool(client, {
5181
5217
  tools: mcpTools,
@@ -5299,8 +5335,8 @@ async function getVercelAITools(client, options) {
5299
5335
  await ensureClientConnected(client);
5300
5336
  const mcpTools = await client.getEnabledToolsAsync();
5301
5337
  const vercelTools = {};
5302
- const mode = options?.mode ?? "code";
5303
- if (mode === "code") {
5338
+ const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
5339
+ if (effectiveMode === "code") {
5304
5340
  const codeTool = buildCodeModeTool(client, {
5305
5341
  tools: mcpTools,
5306
5342
  providerTokens,
@@ -5349,8 +5385,8 @@ async function getOpenAITools(client, options) {
5349
5385
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
5350
5386
  await ensureClientConnected(client);
5351
5387
  const mcpTools = await client.getEnabledToolsAsync();
5352
- const mode = options?.mode ?? "code";
5353
- const openaiTools = mode === "code" ? (() => {
5388
+ const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
5389
+ const openaiTools = effectiveMode === "code" ? (() => {
5354
5390
  const codeTool = buildCodeModeTool(client, {
5355
5391
  tools: mcpTools,
5356
5392
  providerTokens,
@@ -34,12 +34,12 @@ export interface OpenAIToolsOptions extends AIToolsOptions {
34
34
  /**
35
35
  * How to expose MCP tools to the model.
36
36
  *
37
- * - `'code'` (default): Returns a single `execute_code` tool backed by a
37
+ * - `'code'`: Returns a single `execute_code` tool backed by a
38
38
  * Vercel Sandbox. The model writes TypeScript that calls the typed
39
39
  * `client.<integration>.<method>()` API and chains operations in one round-trip.
40
40
  * - `'tools'`: Legacy behavior — one OpenAI function tool per MCP tool.
41
41
  *
42
- * @default 'code'
42
+ * @default auto-detects `'code'` when sandbox + public URL are available, otherwise `'tools'`
43
43
  */
44
44
  mode?: 'code' | 'tools';
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/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EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAmEvB;AA0GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
@@ -4251,7 +4251,7 @@ function calculateHasMore(offset, returnedCount, total) {
4251
4251
  function createTriggerTools(config, context) {
4252
4252
  const { callbacks } = config;
4253
4253
  return {
4254
- create_trigger: {
4254
+ trigger_create: {
4255
4255
  description: "Schedule a tool to run at a specific time or on a recurring schedule. Use this when the user wants to do something later.",
4256
4256
  inputSchema: exports_external.object({
4257
4257
  name: exports_external.string().optional().describe("Human-readable trigger name"),
@@ -4285,7 +4285,7 @@ function createTriggerTools(config, context) {
4285
4285
  return callbacks.create(trigger, context);
4286
4286
  }
4287
4287
  },
4288
- list_triggers: {
4288
+ trigger_list: {
4289
4289
  description: "List all scheduled triggers with optional filtering by status or tool name",
4290
4290
  inputSchema: exports_external.object({
4291
4291
  status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
@@ -4309,7 +4309,7 @@ function createTriggerTools(config, context) {
4309
4309
  };
4310
4310
  }
4311
4311
  },
4312
- get_trigger: {
4312
+ trigger_get: {
4313
4313
  description: "Get details of a specific trigger by its ID",
4314
4314
  inputSchema: exports_external.object({
4315
4315
  triggerId: exports_external.string().describe("The trigger ID to retrieve")
@@ -4322,7 +4322,7 @@ function createTriggerTools(config, context) {
4322
4322
  return trigger;
4323
4323
  }
4324
4324
  },
4325
- update_trigger: {
4325
+ trigger_update: {
4326
4326
  description: "Update a trigger's properties like name, description, arguments, or schedule",
4327
4327
  inputSchema: exports_external.object({
4328
4328
  triggerId: exports_external.string().describe("The trigger ID to update"),
@@ -4349,7 +4349,7 @@ function createTriggerTools(config, context) {
4349
4349
  return callbacks.update(triggerId, updatesWithTimestamp, context);
4350
4350
  }
4351
4351
  },
4352
- delete_trigger: {
4352
+ trigger_delete: {
4353
4353
  description: "Delete a trigger permanently. This cannot be undone.",
4354
4354
  inputSchema: exports_external.object({
4355
4355
  triggerId: exports_external.string().describe("The trigger ID to delete")
@@ -4359,7 +4359,7 @@ function createTriggerTools(config, context) {
4359
4359
  return { success: true, message: `Trigger ${args.triggerId} deleted` };
4360
4360
  }
4361
4361
  },
4362
- pause_trigger: {
4362
+ trigger_pause: {
4363
4363
  description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
4364
4364
  inputSchema: exports_external.object({
4365
4365
  triggerId: exports_external.string().describe("The trigger ID to pause")
@@ -4379,7 +4379,7 @@ function createTriggerTools(config, context) {
4379
4379
  }, context);
4380
4380
  }
4381
4381
  },
4382
- resume_trigger: {
4382
+ trigger_resume: {
4383
4383
  description: "Resume a paused trigger to start executing it again on schedule",
4384
4384
  inputSchema: exports_external.object({
4385
4385
  triggerId: exports_external.string().describe("The trigger ID to resume")
@@ -4621,6 +4621,7 @@ function pascalCase(id) {
4621
4621
  var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
4622
4622
  const MCP_URL = process.env.INTEGRATE_MCP_URL;
4623
4623
  const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
4624
+ const API_KEY = process.env.INTEGRATE_API_KEY || '';
4624
4625
  const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
4625
4626
  const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
4626
4627
  const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
@@ -4639,6 +4640,7 @@ async function callTool(toolName, args) {
4639
4640
  'x-integrate-code-mode': '1',
4640
4641
  };
4641
4642
  if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
4643
+ if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
4642
4644
  if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
4643
4645
  if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
4644
4646
  if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
@@ -4689,6 +4691,29 @@ export { callTool };
4689
4691
 
4690
4692
  // ../code-mode/executor.ts
4691
4693
  var sandboxFactoryOverride = null;
4694
+ var _sandboxAvailableCache = null;
4695
+ var _sandboxForcedUnavailableForTests = false;
4696
+ async function isSandboxAvailable() {
4697
+ if (_sandboxAvailableCache !== null)
4698
+ return _sandboxAvailableCache;
4699
+ if (_sandboxForcedUnavailableForTests) {
4700
+ _sandboxAvailableCache = false;
4701
+ return false;
4702
+ }
4703
+ if (sandboxFactoryOverride) {
4704
+ _sandboxAvailableCache = true;
4705
+ return true;
4706
+ }
4707
+ try {
4708
+ const dynamicImport = new Function("specifier", "return import(specifier)");
4709
+ await dynamicImport("@" + "vercel/sandbox");
4710
+ _sandboxAvailableCache = true;
4711
+ return true;
4712
+ } catch {
4713
+ _sandboxAvailableCache = false;
4714
+ return false;
4715
+ }
4716
+ }
4692
4717
  async function loadSandboxFactory() {
4693
4718
  if (sandboxFactoryOverride)
4694
4719
  return sandboxFactoryOverride;
@@ -4775,6 +4800,8 @@ async function executeSandboxCode(options) {
4775
4800
  const env = {
4776
4801
  INTEGRATE_MCP_URL: options.mcpUrl
4777
4802
  };
4803
+ if (options.apiKey)
4804
+ env.INTEGRATE_API_KEY = options.apiKey;
4778
4805
  if (options.sessionToken)
4779
4806
  env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
4780
4807
  if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
@@ -4866,6 +4893,13 @@ function resolveCodeModeClientConfig(client) {
4866
4893
  const oauthConfig = client.__oauthConfig;
4867
4894
  return oauthConfig?.codeMode ?? {};
4868
4895
  }
4896
+ async function canUseCodeMode(client) {
4897
+ if (!await isSandboxAvailable())
4898
+ return false;
4899
+ const serverConfig = resolveCodeModeClientConfig(client);
4900
+ const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
4901
+ return !!publicUrl;
4902
+ }
4869
4903
  function buildCodeModeTool(client, options) {
4870
4904
  const { tools, providerTokens, context, integrationIds } = options;
4871
4905
  const generated = generateCodeModeTypes(tools);
@@ -4878,6 +4912,7 @@ ${generated.source}
4878
4912
  \`\`\``;
4879
4913
  const execute = async ({ code }) => {
4880
4914
  const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
4915
+ const apiKey = client.__oauthConfig?.apiKey;
4881
4916
  if (!publicUrl) {
4882
4917
  return {
4883
4918
  success: false,
@@ -4892,6 +4927,7 @@ ${generated.source}
4892
4927
  return executeSandboxCode({
4893
4928
  code,
4894
4929
  mcpUrl,
4930
+ apiKey,
4895
4931
  providerTokens,
4896
4932
  context,
4897
4933
  integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
@@ -4941,8 +4977,8 @@ async function getOpenAITools(client, options) {
4941
4977
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
4942
4978
  await ensureClientConnected(client);
4943
4979
  const mcpTools = await client.getEnabledToolsAsync();
4944
- const mode = options?.mode ?? "code";
4945
- const openaiTools = mode === "code" ? (() => {
4980
+ const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
4981
+ const openaiTools = effectiveMode === "code" ? (() => {
4946
4982
  const codeTool = buildCodeModeTool(client, {
4947
4983
  tools: mcpTools,
4948
4984
  providerTokens,
@@ -25,7 +25,7 @@ export interface TriggerToolsConfig {
25
25
  * @returns Object containing trigger management tools
26
26
  */
27
27
  export declare function createTriggerTools(config: TriggerToolsConfig, context?: MCPContext): {
28
- create_trigger: {
28
+ trigger_create: {
29
29
  description: string;
30
30
  inputSchema: z.ZodObject<{
31
31
  name: z.ZodOptional<z.ZodString>;
@@ -78,7 +78,7 @@ export declare function createTriggerTools(config: TriggerToolsConfig, context?:
78
78
  }>;
79
79
  execute: (args: any) => Promise<import("../index.js").Trigger>;
80
80
  };
81
- list_triggers: {
81
+ trigger_list: {
82
82
  description: string;
83
83
  inputSchema: z.ZodObject<{
84
84
  status: z.ZodOptional<z.ZodEnum<["active", "paused", "completed", "failed"]>>;
@@ -102,7 +102,7 @@ export declare function createTriggerTools(config: TriggerToolsConfig, context?:
102
102
  hasMore: boolean;
103
103
  }>;
104
104
  };
105
- get_trigger: {
105
+ trigger_get: {
106
106
  description: string;
107
107
  inputSchema: z.ZodObject<{
108
108
  triggerId: z.ZodString;
@@ -113,7 +113,7 @@ export declare function createTriggerTools(config: TriggerToolsConfig, context?:
113
113
  }>;
114
114
  execute: (args: any) => Promise<import("../index.js").Trigger>;
115
115
  };
116
- update_trigger: {
116
+ trigger_update: {
117
117
  description: string;
118
118
  inputSchema: z.ZodObject<{
119
119
  triggerId: z.ZodString;
@@ -166,7 +166,7 @@ export declare function createTriggerTools(config: TriggerToolsConfig, context?:
166
166
  }>;
167
167
  execute: (args: any) => Promise<import("../index.js").Trigger>;
168
168
  };
169
- delete_trigger: {
169
+ trigger_delete: {
170
170
  description: string;
171
171
  inputSchema: z.ZodObject<{
172
172
  triggerId: z.ZodString;
@@ -180,7 +180,7 @@ export declare function createTriggerTools(config: TriggerToolsConfig, context?:
180
180
  message: string;
181
181
  }>;
182
182
  };
183
- pause_trigger: {
183
+ trigger_pause: {
184
184
  description: string;
185
185
  inputSchema: z.ZodObject<{
186
186
  triggerId: z.ZodString;
@@ -191,7 +191,7 @@ export declare function createTriggerTools(config: TriggerToolsConfig, context?:
191
191
  }>;
192
192
  execute: (args: any) => Promise<import("../index.js").Trigger>;
193
193
  };
194
- resume_trigger: {
194
+ trigger_resume: {
195
195
  description: string;
196
196
  inputSchema: z.ZodObject<{
197
197
  triggerId: z.ZodString;
@@ -4043,7 +4043,7 @@ function calculateHasMore(offset, returnedCount, total) {
4043
4043
  function createTriggerTools(config, context) {
4044
4044
  const { callbacks } = config;
4045
4045
  return {
4046
- create_trigger: {
4046
+ trigger_create: {
4047
4047
  description: "Schedule a tool to run at a specific time or on a recurring schedule. Use this when the user wants to do something later.",
4048
4048
  inputSchema: exports_external.object({
4049
4049
  name: exports_external.string().optional().describe("Human-readable trigger name"),
@@ -4077,7 +4077,7 @@ function createTriggerTools(config, context) {
4077
4077
  return callbacks.create(trigger, context);
4078
4078
  }
4079
4079
  },
4080
- list_triggers: {
4080
+ trigger_list: {
4081
4081
  description: "List all scheduled triggers with optional filtering by status or tool name",
4082
4082
  inputSchema: exports_external.object({
4083
4083
  status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
@@ -4101,7 +4101,7 @@ function createTriggerTools(config, context) {
4101
4101
  };
4102
4102
  }
4103
4103
  },
4104
- get_trigger: {
4104
+ trigger_get: {
4105
4105
  description: "Get details of a specific trigger by its ID",
4106
4106
  inputSchema: exports_external.object({
4107
4107
  triggerId: exports_external.string().describe("The trigger ID to retrieve")
@@ -4114,7 +4114,7 @@ function createTriggerTools(config, context) {
4114
4114
  return trigger;
4115
4115
  }
4116
4116
  },
4117
- update_trigger: {
4117
+ trigger_update: {
4118
4118
  description: "Update a trigger's properties like name, description, arguments, or schedule",
4119
4119
  inputSchema: exports_external.object({
4120
4120
  triggerId: exports_external.string().describe("The trigger ID to update"),
@@ -4141,7 +4141,7 @@ function createTriggerTools(config, context) {
4141
4141
  return callbacks.update(triggerId, updatesWithTimestamp, context);
4142
4142
  }
4143
4143
  },
4144
- delete_trigger: {
4144
+ trigger_delete: {
4145
4145
  description: "Delete a trigger permanently. This cannot be undone.",
4146
4146
  inputSchema: exports_external.object({
4147
4147
  triggerId: exports_external.string().describe("The trigger ID to delete")
@@ -4151,7 +4151,7 @@ function createTriggerTools(config, context) {
4151
4151
  return { success: true, message: `Trigger ${args.triggerId} deleted` };
4152
4152
  }
4153
4153
  },
4154
- pause_trigger: {
4154
+ trigger_pause: {
4155
4155
  description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
4156
4156
  inputSchema: exports_external.object({
4157
4157
  triggerId: exports_external.string().describe("The trigger ID to pause")
@@ -4171,7 +4171,7 @@ function createTriggerTools(config, context) {
4171
4171
  }, context);
4172
4172
  }
4173
4173
  },
4174
- resume_trigger: {
4174
+ trigger_resume: {
4175
4175
  description: "Resume a paused trigger to start executing it again on schedule",
4176
4176
  inputSchema: exports_external.object({
4177
4177
  triggerId: exports_external.string().describe("The trigger ID to resume")
@@ -25,14 +25,14 @@ export interface VercelAIToolsOptions extends AIToolsOptions {
25
25
  /**
26
26
  * How to expose MCP tools to the model.
27
27
  *
28
- * - `'code'` (default): Returns a single `execute_code` tool. The model writes
28
+ * - `'code'`: Returns a single `execute_code` tool. The model writes
29
29
  * a TypeScript snippet that calls the typed `client.<integration>.<method>()`
30
30
  * API; the snippet runs in an isolated Vercel Sandbox and calls back into
31
31
  * `/api/integrate/mcp`. Chains multiple operations in one round-trip.
32
32
  * - `'tools'`: Legacy behavior — returns one AI tool per MCP tool. Use this
33
33
  * if you can't run `@vercel/sandbox` or need the model to see every tool.
34
34
  *
35
- * @default 'code'
35
+ * @default auto-detects `'code'` when sandbox + public URL are available, otherwise `'tools'`
36
36
  */
37
37
  mode?: 'code' | 'tools';
38
38
  }