integrate-sdk 0.9.8-dev.0 → 0.9.10-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.
@@ -8780,16 +8780,46 @@ var sandboxFactoryOverride = null, _sandboxAvailableCache = null, _sandboxForced
8780
8780
  var init_executor = () => {};
8781
8781
 
8782
8782
  // ../code-mode/tool-builder.ts
8783
+ var exports_tool_builder = {};
8784
+ __export(exports_tool_builder, {
8785
+ warnCodeModeFallback: () => warnCodeModeFallback,
8786
+ resolveCodeModePublicUrl: () => resolveCodeModePublicUrl,
8787
+ resolveCodeModeClientConfig: () => resolveCodeModeClientConfig,
8788
+ diagnoseCodeMode: () => diagnoseCodeMode,
8789
+ canUseCodeMode: () => canUseCodeMode,
8790
+ buildCodeModeTool: () => buildCodeModeTool,
8791
+ __resetCodeModeFallbackWarnings: () => __resetCodeModeFallbackWarnings,
8792
+ CODE_MODE_TOOL_NAME: () => CODE_MODE_TOOL_NAME
8793
+ });
8783
8794
  function resolveCodeModeClientConfig(client) {
8784
8795
  const oauthConfig = client.__oauthConfig;
8785
8796
  return oauthConfig?.codeMode ?? {};
8786
8797
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8798
+ function resolveCodeModePublicUrl(serverConfig = {}) {
8799
+ return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
8800
+ }
8801
+ async function diagnoseCodeMode(client) {
8802
+ if (!await isSandboxAvailable()) {
8803
+ return { available: false, reason: "sandbox-missing" };
8804
+ }
8790
8805
  const serverConfig = resolveCodeModeClientConfig(client);
8791
- const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8806
+ const publicUrl = resolveCodeModePublicUrl(serverConfig);
8807
+ if (!publicUrl) {
8808
+ return { available: false, reason: "no-public-url" };
8809
+ }
8810
+ return { available: true };
8811
+ }
8812
+ async function canUseCodeMode(client) {
8813
+ return (await diagnoseCodeMode(client)).available;
8814
+ }
8815
+ function __resetCodeModeFallbackWarnings() {
8816
+ warnedCodeModeReasons.clear();
8817
+ }
8818
+ function warnCodeModeFallback(reason) {
8819
+ if (warnedCodeModeReasons.has(reason))
8820
+ return;
8821
+ warnedCodeModeReasons.add(reason);
8822
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8823
  }
8794
8824
  function buildCodeModeTool(client, options) {
8795
8825
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8802,7 +8832,9 @@ function buildCodeModeTool(client, options) {
8802
8832
  ${generated.source}
8803
8833
  \`\`\``;
8804
8834
  const execute = async ({ code }) => {
8805
- const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8835
+ const publicUrl = resolveCodeModePublicUrl({
8836
+ publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
8837
+ });
8806
8838
  const apiKey = client.__oauthConfig?.apiKey;
8807
8839
  if (!publicUrl) {
8808
8840
  return {
@@ -8811,7 +8843,7 @@ ${generated.source}
8811
8843
  stdout: "",
8812
8844
  stderr: "",
8813
8845
  durationMs: 0,
8814
- error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_PUBLIC_URL env var). " + "The sandbox uses it to call back into /api/integrate/mcp."
8846
+ error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_URL env var). " + "The sandbox uses it to call back into /api/integrate/mcp."
8815
8847
  };
8816
8848
  }
8817
8849
  const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
@@ -8845,7 +8877,7 @@ ${generated.source}
8845
8877
  execute
8846
8878
  };
8847
8879
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8880
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8881
  var init_tool_builder = __esm(() => {
8850
8882
  init_type_generator();
8851
8883
  init_executor();
@@ -8870,6 +8902,11 @@ var init_tool_builder = __esm(() => {
8870
8902
  "API surface:"
8871
8903
  ].join(`
8872
8904
  `);
8905
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8906
+ "sandbox-missing": "[integrate-sdk] Code Mode unavailable (reason: sandbox-missing) — falling back to tool mode. " + "Install `@vercel/sandbox` (e.g. `bun add @vercel/sandbox`) to enable Code Mode.",
8907
+ "no-public-url": "[integrate-sdk] Code Mode unavailable (reason: no-public-url) — falling back to tool mode. " + "Set `codeMode.publicUrl` on your server config or the `INTEGRATE_URL` env var."
8908
+ };
8909
+ warnedCodeModeReasons = new Set;
8873
8910
  });
8874
8911
 
8875
8912
  // ../ai/vercel-ai.ts
@@ -8896,7 +8933,18 @@ async function getVercelAITools(client, options) {
8896
8933
  await ensureClientConnected(client);
8897
8934
  const mcpTools = await client.getEnabledToolsAsync();
8898
8935
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8936
+ let effectiveMode;
8937
+ if (options?.mode !== undefined) {
8938
+ effectiveMode = options.mode;
8939
+ } else {
8940
+ const diagnosis = await diagnoseCodeMode(client);
8941
+ if (diagnosis.available) {
8942
+ effectiveMode = "code";
8943
+ } else {
8944
+ warnCodeModeFallback(diagnosis.reason);
8945
+ effectiveMode = "tools";
8946
+ }
8947
+ }
8900
8948
  if (effectiveMode === "code") {
8901
8949
  const codeTool = buildCodeModeTool(client, {
8902
8950
  tools: mcpTools,
@@ -10355,7 +10403,18 @@ async function getOpenAITools(client, options) {
10355
10403
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10404
  await ensureClientConnected(client);
10357
10405
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10406
+ let effectiveMode;
10407
+ if (options?.mode !== undefined) {
10408
+ effectiveMode = options.mode;
10409
+ } else {
10410
+ const diagnosis = await diagnoseCodeMode(client);
10411
+ if (diagnosis.available) {
10412
+ effectiveMode = "code";
10413
+ } else {
10414
+ warnCodeModeFallback(diagnosis.reason);
10415
+ effectiveMode = "tools";
10416
+ }
10417
+ }
10359
10418
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10419
  const codeTool = buildCodeModeTool(client, {
10361
10420
  tools: mcpTools,
@@ -10535,7 +10594,18 @@ async function getAnthropicTools(client, options) {
10535
10594
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10595
  await ensureClientConnected(client);
10537
10596
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10597
+ let effectiveMode;
10598
+ if (options?.mode !== undefined) {
10599
+ effectiveMode = options.mode;
10600
+ } else {
10601
+ const diagnosis = await diagnoseCodeMode(client);
10602
+ if (diagnosis.available) {
10603
+ effectiveMode = "code";
10604
+ } else {
10605
+ warnCodeModeFallback(diagnosis.reason);
10606
+ effectiveMode = "tools";
10607
+ }
10608
+ }
10539
10609
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10610
  const codeTool = buildCodeModeTool(client, {
10541
10611
  tools: mcpTools,
@@ -10724,7 +10794,18 @@ async function getGoogleTools(client, options) {
10724
10794
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10795
  await ensureClientConnected(client);
10726
10796
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10797
+ let effectiveMode;
10798
+ if (options?.mode !== undefined) {
10799
+ effectiveMode = options.mode;
10800
+ } else {
10801
+ const diagnosis = await diagnoseCodeMode(client);
10802
+ if (diagnosis.available) {
10803
+ effectiveMode = "code";
10804
+ } else {
10805
+ warnCodeModeFallback(diagnosis.reason);
10806
+ effectiveMode = "tools";
10807
+ }
10808
+ }
10728
10809
  let googleTools;
10729
10810
  if (effectiveMode === "code") {
10730
10811
  const TypeEnum = await getGoogleType();
@@ -11318,11 +11399,12 @@ function createMCPServer(config) {
11318
11399
  return Response.json({ error: "`code` is required and must be a non-empty string." }, { status: 400 });
11319
11400
  }
11320
11401
  const { executeSandboxCode: executeSandboxCode2 } = await Promise.resolve().then(() => (init_executor(), exports_executor));
11402
+ const { resolveCodeModePublicUrl: resolveCodeModePublicUrl2 } = await Promise.resolve().then(() => (init_tool_builder(), exports_tool_builder));
11321
11403
  const codeModeConfig = config.codeMode ?? {};
11322
- const publicUrl = codeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
11404
+ const publicUrl = resolveCodeModePublicUrl2(codeModeConfig);
11323
11405
  if (!publicUrl) {
11324
11406
  return Response.json({
11325
- error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_PUBLIC_URL env var). Set it to the public origin where /api/integrate/mcp is reachable."
11407
+ error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_URL env var). Set it to the public origin where /api/integrate/mcp is reachable."
11326
11408
  }, { status: 500 });
11327
11409
  }
11328
11410
  let contextOverride = body.context;
@@ -8780,16 +8780,46 @@ var sandboxFactoryOverride = null, _sandboxAvailableCache = null, _sandboxForced
8780
8780
  var init_executor = () => {};
8781
8781
 
8782
8782
  // ../code-mode/tool-builder.ts
8783
+ var exports_tool_builder = {};
8784
+ __export(exports_tool_builder, {
8785
+ warnCodeModeFallback: () => warnCodeModeFallback,
8786
+ resolveCodeModePublicUrl: () => resolveCodeModePublicUrl,
8787
+ resolveCodeModeClientConfig: () => resolveCodeModeClientConfig,
8788
+ diagnoseCodeMode: () => diagnoseCodeMode,
8789
+ canUseCodeMode: () => canUseCodeMode,
8790
+ buildCodeModeTool: () => buildCodeModeTool,
8791
+ __resetCodeModeFallbackWarnings: () => __resetCodeModeFallbackWarnings,
8792
+ CODE_MODE_TOOL_NAME: () => CODE_MODE_TOOL_NAME
8793
+ });
8783
8794
  function resolveCodeModeClientConfig(client) {
8784
8795
  const oauthConfig = client.__oauthConfig;
8785
8796
  return oauthConfig?.codeMode ?? {};
8786
8797
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8798
+ function resolveCodeModePublicUrl(serverConfig = {}) {
8799
+ return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
8800
+ }
8801
+ async function diagnoseCodeMode(client) {
8802
+ if (!await isSandboxAvailable()) {
8803
+ return { available: false, reason: "sandbox-missing" };
8804
+ }
8790
8805
  const serverConfig = resolveCodeModeClientConfig(client);
8791
- const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8806
+ const publicUrl = resolveCodeModePublicUrl(serverConfig);
8807
+ if (!publicUrl) {
8808
+ return { available: false, reason: "no-public-url" };
8809
+ }
8810
+ return { available: true };
8811
+ }
8812
+ async function canUseCodeMode(client) {
8813
+ return (await diagnoseCodeMode(client)).available;
8814
+ }
8815
+ function __resetCodeModeFallbackWarnings() {
8816
+ warnedCodeModeReasons.clear();
8817
+ }
8818
+ function warnCodeModeFallback(reason) {
8819
+ if (warnedCodeModeReasons.has(reason))
8820
+ return;
8821
+ warnedCodeModeReasons.add(reason);
8822
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8823
  }
8794
8824
  function buildCodeModeTool(client, options) {
8795
8825
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8802,7 +8832,9 @@ function buildCodeModeTool(client, options) {
8802
8832
  ${generated.source}
8803
8833
  \`\`\``;
8804
8834
  const execute = async ({ code }) => {
8805
- const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8835
+ const publicUrl = resolveCodeModePublicUrl({
8836
+ publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
8837
+ });
8806
8838
  const apiKey = client.__oauthConfig?.apiKey;
8807
8839
  if (!publicUrl) {
8808
8840
  return {
@@ -8811,7 +8843,7 @@ ${generated.source}
8811
8843
  stdout: "",
8812
8844
  stderr: "",
8813
8845
  durationMs: 0,
8814
- error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_PUBLIC_URL env var). " + "The sandbox uses it to call back into /api/integrate/mcp."
8846
+ error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_URL env var). " + "The sandbox uses it to call back into /api/integrate/mcp."
8815
8847
  };
8816
8848
  }
8817
8849
  const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
@@ -8845,7 +8877,7 @@ ${generated.source}
8845
8877
  execute
8846
8878
  };
8847
8879
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8880
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8881
  var init_tool_builder = __esm(() => {
8850
8882
  init_type_generator();
8851
8883
  init_executor();
@@ -8870,6 +8902,11 @@ var init_tool_builder = __esm(() => {
8870
8902
  "API surface:"
8871
8903
  ].join(`
8872
8904
  `);
8905
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8906
+ "sandbox-missing": "[integrate-sdk] Code Mode unavailable (reason: sandbox-missing) — falling back to tool mode. " + "Install `@vercel/sandbox` (e.g. `bun add @vercel/sandbox`) to enable Code Mode.",
8907
+ "no-public-url": "[integrate-sdk] Code Mode unavailable (reason: no-public-url) — falling back to tool mode. " + "Set `codeMode.publicUrl` on your server config or the `INTEGRATE_URL` env var."
8908
+ };
8909
+ warnedCodeModeReasons = new Set;
8873
8910
  });
8874
8911
 
8875
8912
  // ../ai/vercel-ai.ts
@@ -8896,7 +8933,18 @@ async function getVercelAITools(client, options) {
8896
8933
  await ensureClientConnected(client);
8897
8934
  const mcpTools = await client.getEnabledToolsAsync();
8898
8935
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8936
+ let effectiveMode;
8937
+ if (options?.mode !== undefined) {
8938
+ effectiveMode = options.mode;
8939
+ } else {
8940
+ const diagnosis = await diagnoseCodeMode(client);
8941
+ if (diagnosis.available) {
8942
+ effectiveMode = "code";
8943
+ } else {
8944
+ warnCodeModeFallback(diagnosis.reason);
8945
+ effectiveMode = "tools";
8946
+ }
8947
+ }
8900
8948
  if (effectiveMode === "code") {
8901
8949
  const codeTool = buildCodeModeTool(client, {
8902
8950
  tools: mcpTools,
@@ -10355,7 +10403,18 @@ async function getOpenAITools(client, options) {
10355
10403
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10404
  await ensureClientConnected(client);
10357
10405
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10406
+ let effectiveMode;
10407
+ if (options?.mode !== undefined) {
10408
+ effectiveMode = options.mode;
10409
+ } else {
10410
+ const diagnosis = await diagnoseCodeMode(client);
10411
+ if (diagnosis.available) {
10412
+ effectiveMode = "code";
10413
+ } else {
10414
+ warnCodeModeFallback(diagnosis.reason);
10415
+ effectiveMode = "tools";
10416
+ }
10417
+ }
10359
10418
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10419
  const codeTool = buildCodeModeTool(client, {
10361
10420
  tools: mcpTools,
@@ -10535,7 +10594,18 @@ async function getAnthropicTools(client, options) {
10535
10594
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10595
  await ensureClientConnected(client);
10537
10596
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10597
+ let effectiveMode;
10598
+ if (options?.mode !== undefined) {
10599
+ effectiveMode = options.mode;
10600
+ } else {
10601
+ const diagnosis = await diagnoseCodeMode(client);
10602
+ if (diagnosis.available) {
10603
+ effectiveMode = "code";
10604
+ } else {
10605
+ warnCodeModeFallback(diagnosis.reason);
10606
+ effectiveMode = "tools";
10607
+ }
10608
+ }
10539
10609
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10610
  const codeTool = buildCodeModeTool(client, {
10541
10611
  tools: mcpTools,
@@ -10724,7 +10794,18 @@ async function getGoogleTools(client, options) {
10724
10794
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10795
  await ensureClientConnected(client);
10726
10796
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10797
+ let effectiveMode;
10798
+ if (options?.mode !== undefined) {
10799
+ effectiveMode = options.mode;
10800
+ } else {
10801
+ const diagnosis = await diagnoseCodeMode(client);
10802
+ if (diagnosis.available) {
10803
+ effectiveMode = "code";
10804
+ } else {
10805
+ warnCodeModeFallback(diagnosis.reason);
10806
+ effectiveMode = "tools";
10807
+ }
10808
+ }
10728
10809
  let googleTools;
10729
10810
  if (effectiveMode === "code") {
10730
10811
  const TypeEnum = await getGoogleType();
@@ -11318,11 +11399,12 @@ function createMCPServer(config) {
11318
11399
  return Response.json({ error: "`code` is required and must be a non-empty string." }, { status: 400 });
11319
11400
  }
11320
11401
  const { executeSandboxCode: executeSandboxCode2 } = await Promise.resolve().then(() => (init_executor(), exports_executor));
11402
+ const { resolveCodeModePublicUrl: resolveCodeModePublicUrl2 } = await Promise.resolve().then(() => (init_tool_builder(), exports_tool_builder));
11321
11403
  const codeModeConfig = config.codeMode ?? {};
11322
- const publicUrl = codeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
11404
+ const publicUrl = resolveCodeModePublicUrl2(codeModeConfig);
11323
11405
  if (!publicUrl) {
11324
11406
  return Response.json({
11325
- error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_PUBLIC_URL env var). Set it to the public origin where /api/integrate/mcp is reachable."
11407
+ error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_URL env var). Set it to the public origin where /api/integrate/mcp is reachable."
11326
11408
  }, { status: 500 });
11327
11409
  }
11328
11410
  let contextOverride = body.context;
@@ -8780,16 +8780,46 @@ var sandboxFactoryOverride = null, _sandboxAvailableCache = null, _sandboxForced
8780
8780
  var init_executor = () => {};
8781
8781
 
8782
8782
  // ../code-mode/tool-builder.ts
8783
+ var exports_tool_builder = {};
8784
+ __export(exports_tool_builder, {
8785
+ warnCodeModeFallback: () => warnCodeModeFallback,
8786
+ resolveCodeModePublicUrl: () => resolveCodeModePublicUrl,
8787
+ resolveCodeModeClientConfig: () => resolveCodeModeClientConfig,
8788
+ diagnoseCodeMode: () => diagnoseCodeMode,
8789
+ canUseCodeMode: () => canUseCodeMode,
8790
+ buildCodeModeTool: () => buildCodeModeTool,
8791
+ __resetCodeModeFallbackWarnings: () => __resetCodeModeFallbackWarnings,
8792
+ CODE_MODE_TOOL_NAME: () => CODE_MODE_TOOL_NAME
8793
+ });
8783
8794
  function resolveCodeModeClientConfig(client) {
8784
8795
  const oauthConfig = client.__oauthConfig;
8785
8796
  return oauthConfig?.codeMode ?? {};
8786
8797
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8798
+ function resolveCodeModePublicUrl(serverConfig = {}) {
8799
+ return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
8800
+ }
8801
+ async function diagnoseCodeMode(client) {
8802
+ if (!await isSandboxAvailable()) {
8803
+ return { available: false, reason: "sandbox-missing" };
8804
+ }
8790
8805
  const serverConfig = resolveCodeModeClientConfig(client);
8791
- const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8806
+ const publicUrl = resolveCodeModePublicUrl(serverConfig);
8807
+ if (!publicUrl) {
8808
+ return { available: false, reason: "no-public-url" };
8809
+ }
8810
+ return { available: true };
8811
+ }
8812
+ async function canUseCodeMode(client) {
8813
+ return (await diagnoseCodeMode(client)).available;
8814
+ }
8815
+ function __resetCodeModeFallbackWarnings() {
8816
+ warnedCodeModeReasons.clear();
8817
+ }
8818
+ function warnCodeModeFallback(reason) {
8819
+ if (warnedCodeModeReasons.has(reason))
8820
+ return;
8821
+ warnedCodeModeReasons.add(reason);
8822
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8823
  }
8794
8824
  function buildCodeModeTool(client, options) {
8795
8825
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8802,7 +8832,9 @@ function buildCodeModeTool(client, options) {
8802
8832
  ${generated.source}
8803
8833
  \`\`\``;
8804
8834
  const execute = async ({ code }) => {
8805
- const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8835
+ const publicUrl = resolveCodeModePublicUrl({
8836
+ publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
8837
+ });
8806
8838
  const apiKey = client.__oauthConfig?.apiKey;
8807
8839
  if (!publicUrl) {
8808
8840
  return {
@@ -8811,7 +8843,7 @@ ${generated.source}
8811
8843
  stdout: "",
8812
8844
  stderr: "",
8813
8845
  durationMs: 0,
8814
- error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_PUBLIC_URL env var). " + "The sandbox uses it to call back into /api/integrate/mcp."
8846
+ error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_URL env var). " + "The sandbox uses it to call back into /api/integrate/mcp."
8815
8847
  };
8816
8848
  }
8817
8849
  const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
@@ -8845,7 +8877,7 @@ ${generated.source}
8845
8877
  execute
8846
8878
  };
8847
8879
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8880
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8881
  var init_tool_builder = __esm(() => {
8850
8882
  init_type_generator();
8851
8883
  init_executor();
@@ -8870,6 +8902,11 @@ var init_tool_builder = __esm(() => {
8870
8902
  "API surface:"
8871
8903
  ].join(`
8872
8904
  `);
8905
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8906
+ "sandbox-missing": "[integrate-sdk] Code Mode unavailable (reason: sandbox-missing) — falling back to tool mode. " + "Install `@vercel/sandbox` (e.g. `bun add @vercel/sandbox`) to enable Code Mode.",
8907
+ "no-public-url": "[integrate-sdk] Code Mode unavailable (reason: no-public-url) — falling back to tool mode. " + "Set `codeMode.publicUrl` on your server config or the `INTEGRATE_URL` env var."
8908
+ };
8909
+ warnedCodeModeReasons = new Set;
8873
8910
  });
8874
8911
 
8875
8912
  // ../ai/vercel-ai.ts
@@ -8896,7 +8933,18 @@ async function getVercelAITools(client, options) {
8896
8933
  await ensureClientConnected(client);
8897
8934
  const mcpTools = await client.getEnabledToolsAsync();
8898
8935
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8936
+ let effectiveMode;
8937
+ if (options?.mode !== undefined) {
8938
+ effectiveMode = options.mode;
8939
+ } else {
8940
+ const diagnosis = await diagnoseCodeMode(client);
8941
+ if (diagnosis.available) {
8942
+ effectiveMode = "code";
8943
+ } else {
8944
+ warnCodeModeFallback(diagnosis.reason);
8945
+ effectiveMode = "tools";
8946
+ }
8947
+ }
8900
8948
  if (effectiveMode === "code") {
8901
8949
  const codeTool = buildCodeModeTool(client, {
8902
8950
  tools: mcpTools,
@@ -10355,7 +10403,18 @@ async function getOpenAITools(client, options) {
10355
10403
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10404
  await ensureClientConnected(client);
10357
10405
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10406
+ let effectiveMode;
10407
+ if (options?.mode !== undefined) {
10408
+ effectiveMode = options.mode;
10409
+ } else {
10410
+ const diagnosis = await diagnoseCodeMode(client);
10411
+ if (diagnosis.available) {
10412
+ effectiveMode = "code";
10413
+ } else {
10414
+ warnCodeModeFallback(diagnosis.reason);
10415
+ effectiveMode = "tools";
10416
+ }
10417
+ }
10359
10418
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10419
  const codeTool = buildCodeModeTool(client, {
10361
10420
  tools: mcpTools,
@@ -10535,7 +10594,18 @@ async function getAnthropicTools(client, options) {
10535
10594
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10595
  await ensureClientConnected(client);
10537
10596
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10597
+ let effectiveMode;
10598
+ if (options?.mode !== undefined) {
10599
+ effectiveMode = options.mode;
10600
+ } else {
10601
+ const diagnosis = await diagnoseCodeMode(client);
10602
+ if (diagnosis.available) {
10603
+ effectiveMode = "code";
10604
+ } else {
10605
+ warnCodeModeFallback(diagnosis.reason);
10606
+ effectiveMode = "tools";
10607
+ }
10608
+ }
10539
10609
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10610
  const codeTool = buildCodeModeTool(client, {
10541
10611
  tools: mcpTools,
@@ -10724,7 +10794,18 @@ async function getGoogleTools(client, options) {
10724
10794
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10795
  await ensureClientConnected(client);
10726
10796
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10797
+ let effectiveMode;
10798
+ if (options?.mode !== undefined) {
10799
+ effectiveMode = options.mode;
10800
+ } else {
10801
+ const diagnosis = await diagnoseCodeMode(client);
10802
+ if (diagnosis.available) {
10803
+ effectiveMode = "code";
10804
+ } else {
10805
+ warnCodeModeFallback(diagnosis.reason);
10806
+ effectiveMode = "tools";
10807
+ }
10808
+ }
10728
10809
  let googleTools;
10729
10810
  if (effectiveMode === "code") {
10730
10811
  const TypeEnum = await getGoogleType();
@@ -11318,11 +11399,12 @@ function createMCPServer(config) {
11318
11399
  return Response.json({ error: "`code` is required and must be a non-empty string." }, { status: 400 });
11319
11400
  }
11320
11401
  const { executeSandboxCode: executeSandboxCode2 } = await Promise.resolve().then(() => (init_executor(), exports_executor));
11402
+ const { resolveCodeModePublicUrl: resolveCodeModePublicUrl2 } = await Promise.resolve().then(() => (init_tool_builder(), exports_tool_builder));
11321
11403
  const codeModeConfig = config.codeMode ?? {};
11322
- const publicUrl = codeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
11404
+ const publicUrl = resolveCodeModePublicUrl2(codeModeConfig);
11323
11405
  if (!publicUrl) {
11324
11406
  return Response.json({
11325
- error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_PUBLIC_URL env var). Set it to the public origin where /api/integrate/mcp is reachable."
11407
+ error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the INTEGRATE_URL env var). Set it to the public origin where /api/integrate/mcp is reachable."
11326
11408
  }, { status: 500 });
11327
11409
  }
11328
11410
  let contextOverride = body.context;