integrate-sdk 0.9.8-dev.0 → 0.9.9-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.
@@ -8784,12 +8784,22 @@ function resolveCodeModeClientConfig(client) {
8784
8784
  const oauthConfig = client.__oauthConfig;
8785
8785
  return oauthConfig?.codeMode ?? {};
8786
8786
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8787
+ async function diagnoseCodeMode(client) {
8788
+ if (!await isSandboxAvailable()) {
8789
+ return { available: false, reason: "sandbox-missing" };
8790
+ }
8790
8791
  const serverConfig = resolveCodeModeClientConfig(client);
8791
8792
  const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8793
+ if (!publicUrl) {
8794
+ return { available: false, reason: "no-public-url" };
8795
+ }
8796
+ return { available: true };
8797
+ }
8798
+ function warnCodeModeFallback(reason) {
8799
+ if (warnedCodeModeReasons.has(reason))
8800
+ return;
8801
+ warnedCodeModeReasons.add(reason);
8802
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8803
  }
8794
8804
  function buildCodeModeTool(client, options) {
8795
8805
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8845,7 +8855,7 @@ ${generated.source}
8845
8855
  execute
8846
8856
  };
8847
8857
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8858
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8859
  var init_tool_builder = __esm(() => {
8850
8860
  init_type_generator();
8851
8861
  init_executor();
@@ -8870,6 +8880,11 @@ var init_tool_builder = __esm(() => {
8870
8880
  "API surface:"
8871
8881
  ].join(`
8872
8882
  `);
8883
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8884
+ "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.",
8885
+ "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_PUBLIC_URL` env var."
8886
+ };
8887
+ warnedCodeModeReasons = new Set;
8873
8888
  });
8874
8889
 
8875
8890
  // ../ai/vercel-ai.ts
@@ -8896,7 +8911,18 @@ async function getVercelAITools(client, options) {
8896
8911
  await ensureClientConnected(client);
8897
8912
  const mcpTools = await client.getEnabledToolsAsync();
8898
8913
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8914
+ let effectiveMode;
8915
+ if (options?.mode !== undefined) {
8916
+ effectiveMode = options.mode;
8917
+ } else {
8918
+ const diagnosis = await diagnoseCodeMode(client);
8919
+ if (diagnosis.available) {
8920
+ effectiveMode = "code";
8921
+ } else {
8922
+ warnCodeModeFallback(diagnosis.reason);
8923
+ effectiveMode = "tools";
8924
+ }
8925
+ }
8900
8926
  if (effectiveMode === "code") {
8901
8927
  const codeTool = buildCodeModeTool(client, {
8902
8928
  tools: mcpTools,
@@ -10355,7 +10381,18 @@ async function getOpenAITools(client, options) {
10355
10381
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10382
  await ensureClientConnected(client);
10357
10383
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10384
+ let effectiveMode;
10385
+ if (options?.mode !== undefined) {
10386
+ effectiveMode = options.mode;
10387
+ } else {
10388
+ const diagnosis = await diagnoseCodeMode(client);
10389
+ if (diagnosis.available) {
10390
+ effectiveMode = "code";
10391
+ } else {
10392
+ warnCodeModeFallback(diagnosis.reason);
10393
+ effectiveMode = "tools";
10394
+ }
10395
+ }
10359
10396
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10397
  const codeTool = buildCodeModeTool(client, {
10361
10398
  tools: mcpTools,
@@ -10535,7 +10572,18 @@ async function getAnthropicTools(client, options) {
10535
10572
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10573
  await ensureClientConnected(client);
10537
10574
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10575
+ let effectiveMode;
10576
+ if (options?.mode !== undefined) {
10577
+ effectiveMode = options.mode;
10578
+ } else {
10579
+ const diagnosis = await diagnoseCodeMode(client);
10580
+ if (diagnosis.available) {
10581
+ effectiveMode = "code";
10582
+ } else {
10583
+ warnCodeModeFallback(diagnosis.reason);
10584
+ effectiveMode = "tools";
10585
+ }
10586
+ }
10539
10587
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10588
  const codeTool = buildCodeModeTool(client, {
10541
10589
  tools: mcpTools,
@@ -10724,7 +10772,18 @@ async function getGoogleTools(client, options) {
10724
10772
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10773
  await ensureClientConnected(client);
10726
10774
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10775
+ let effectiveMode;
10776
+ if (options?.mode !== undefined) {
10777
+ effectiveMode = options.mode;
10778
+ } else {
10779
+ const diagnosis = await diagnoseCodeMode(client);
10780
+ if (diagnosis.available) {
10781
+ effectiveMode = "code";
10782
+ } else {
10783
+ warnCodeModeFallback(diagnosis.reason);
10784
+ effectiveMode = "tools";
10785
+ }
10786
+ }
10728
10787
  let googleTools;
10729
10788
  if (effectiveMode === "code") {
10730
10789
  const TypeEnum = await getGoogleType();
@@ -8784,12 +8784,22 @@ function resolveCodeModeClientConfig(client) {
8784
8784
  const oauthConfig = client.__oauthConfig;
8785
8785
  return oauthConfig?.codeMode ?? {};
8786
8786
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8787
+ async function diagnoseCodeMode(client) {
8788
+ if (!await isSandboxAvailable()) {
8789
+ return { available: false, reason: "sandbox-missing" };
8790
+ }
8790
8791
  const serverConfig = resolveCodeModeClientConfig(client);
8791
8792
  const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8793
+ if (!publicUrl) {
8794
+ return { available: false, reason: "no-public-url" };
8795
+ }
8796
+ return { available: true };
8797
+ }
8798
+ function warnCodeModeFallback(reason) {
8799
+ if (warnedCodeModeReasons.has(reason))
8800
+ return;
8801
+ warnedCodeModeReasons.add(reason);
8802
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8803
  }
8794
8804
  function buildCodeModeTool(client, options) {
8795
8805
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8845,7 +8855,7 @@ ${generated.source}
8845
8855
  execute
8846
8856
  };
8847
8857
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8858
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8859
  var init_tool_builder = __esm(() => {
8850
8860
  init_type_generator();
8851
8861
  init_executor();
@@ -8870,6 +8880,11 @@ var init_tool_builder = __esm(() => {
8870
8880
  "API surface:"
8871
8881
  ].join(`
8872
8882
  `);
8883
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8884
+ "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.",
8885
+ "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_PUBLIC_URL` env var."
8886
+ };
8887
+ warnedCodeModeReasons = new Set;
8873
8888
  });
8874
8889
 
8875
8890
  // ../ai/vercel-ai.ts
@@ -8896,7 +8911,18 @@ async function getVercelAITools(client, options) {
8896
8911
  await ensureClientConnected(client);
8897
8912
  const mcpTools = await client.getEnabledToolsAsync();
8898
8913
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8914
+ let effectiveMode;
8915
+ if (options?.mode !== undefined) {
8916
+ effectiveMode = options.mode;
8917
+ } else {
8918
+ const diagnosis = await diagnoseCodeMode(client);
8919
+ if (diagnosis.available) {
8920
+ effectiveMode = "code";
8921
+ } else {
8922
+ warnCodeModeFallback(diagnosis.reason);
8923
+ effectiveMode = "tools";
8924
+ }
8925
+ }
8900
8926
  if (effectiveMode === "code") {
8901
8927
  const codeTool = buildCodeModeTool(client, {
8902
8928
  tools: mcpTools,
@@ -10355,7 +10381,18 @@ async function getOpenAITools(client, options) {
10355
10381
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10382
  await ensureClientConnected(client);
10357
10383
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10384
+ let effectiveMode;
10385
+ if (options?.mode !== undefined) {
10386
+ effectiveMode = options.mode;
10387
+ } else {
10388
+ const diagnosis = await diagnoseCodeMode(client);
10389
+ if (diagnosis.available) {
10390
+ effectiveMode = "code";
10391
+ } else {
10392
+ warnCodeModeFallback(diagnosis.reason);
10393
+ effectiveMode = "tools";
10394
+ }
10395
+ }
10359
10396
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10397
  const codeTool = buildCodeModeTool(client, {
10361
10398
  tools: mcpTools,
@@ -10535,7 +10572,18 @@ async function getAnthropicTools(client, options) {
10535
10572
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10573
  await ensureClientConnected(client);
10537
10574
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10575
+ let effectiveMode;
10576
+ if (options?.mode !== undefined) {
10577
+ effectiveMode = options.mode;
10578
+ } else {
10579
+ const diagnosis = await diagnoseCodeMode(client);
10580
+ if (diagnosis.available) {
10581
+ effectiveMode = "code";
10582
+ } else {
10583
+ warnCodeModeFallback(diagnosis.reason);
10584
+ effectiveMode = "tools";
10585
+ }
10586
+ }
10539
10587
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10588
  const codeTool = buildCodeModeTool(client, {
10541
10589
  tools: mcpTools,
@@ -10724,7 +10772,18 @@ async function getGoogleTools(client, options) {
10724
10772
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10773
  await ensureClientConnected(client);
10726
10774
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10775
+ let effectiveMode;
10776
+ if (options?.mode !== undefined) {
10777
+ effectiveMode = options.mode;
10778
+ } else {
10779
+ const diagnosis = await diagnoseCodeMode(client);
10780
+ if (diagnosis.available) {
10781
+ effectiveMode = "code";
10782
+ } else {
10783
+ warnCodeModeFallback(diagnosis.reason);
10784
+ effectiveMode = "tools";
10785
+ }
10786
+ }
10728
10787
  let googleTools;
10729
10788
  if (effectiveMode === "code") {
10730
10789
  const TypeEnum = await getGoogleType();
@@ -8784,12 +8784,22 @@ function resolveCodeModeClientConfig(client) {
8784
8784
  const oauthConfig = client.__oauthConfig;
8785
8785
  return oauthConfig?.codeMode ?? {};
8786
8786
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8787
+ async function diagnoseCodeMode(client) {
8788
+ if (!await isSandboxAvailable()) {
8789
+ return { available: false, reason: "sandbox-missing" };
8790
+ }
8790
8791
  const serverConfig = resolveCodeModeClientConfig(client);
8791
8792
  const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8793
+ if (!publicUrl) {
8794
+ return { available: false, reason: "no-public-url" };
8795
+ }
8796
+ return { available: true };
8797
+ }
8798
+ function warnCodeModeFallback(reason) {
8799
+ if (warnedCodeModeReasons.has(reason))
8800
+ return;
8801
+ warnedCodeModeReasons.add(reason);
8802
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8803
  }
8794
8804
  function buildCodeModeTool(client, options) {
8795
8805
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8845,7 +8855,7 @@ ${generated.source}
8845
8855
  execute
8846
8856
  };
8847
8857
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8858
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8859
  var init_tool_builder = __esm(() => {
8850
8860
  init_type_generator();
8851
8861
  init_executor();
@@ -8870,6 +8880,11 @@ var init_tool_builder = __esm(() => {
8870
8880
  "API surface:"
8871
8881
  ].join(`
8872
8882
  `);
8883
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8884
+ "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.",
8885
+ "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_PUBLIC_URL` env var."
8886
+ };
8887
+ warnedCodeModeReasons = new Set;
8873
8888
  });
8874
8889
 
8875
8890
  // ../ai/vercel-ai.ts
@@ -8896,7 +8911,18 @@ async function getVercelAITools(client, options) {
8896
8911
  await ensureClientConnected(client);
8897
8912
  const mcpTools = await client.getEnabledToolsAsync();
8898
8913
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8914
+ let effectiveMode;
8915
+ if (options?.mode !== undefined) {
8916
+ effectiveMode = options.mode;
8917
+ } else {
8918
+ const diagnosis = await diagnoseCodeMode(client);
8919
+ if (diagnosis.available) {
8920
+ effectiveMode = "code";
8921
+ } else {
8922
+ warnCodeModeFallback(diagnosis.reason);
8923
+ effectiveMode = "tools";
8924
+ }
8925
+ }
8900
8926
  if (effectiveMode === "code") {
8901
8927
  const codeTool = buildCodeModeTool(client, {
8902
8928
  tools: mcpTools,
@@ -10355,7 +10381,18 @@ async function getOpenAITools(client, options) {
10355
10381
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10382
  await ensureClientConnected(client);
10357
10383
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10384
+ let effectiveMode;
10385
+ if (options?.mode !== undefined) {
10386
+ effectiveMode = options.mode;
10387
+ } else {
10388
+ const diagnosis = await diagnoseCodeMode(client);
10389
+ if (diagnosis.available) {
10390
+ effectiveMode = "code";
10391
+ } else {
10392
+ warnCodeModeFallback(diagnosis.reason);
10393
+ effectiveMode = "tools";
10394
+ }
10395
+ }
10359
10396
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10397
  const codeTool = buildCodeModeTool(client, {
10361
10398
  tools: mcpTools,
@@ -10535,7 +10572,18 @@ async function getAnthropicTools(client, options) {
10535
10572
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10573
  await ensureClientConnected(client);
10537
10574
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10575
+ let effectiveMode;
10576
+ if (options?.mode !== undefined) {
10577
+ effectiveMode = options.mode;
10578
+ } else {
10579
+ const diagnosis = await diagnoseCodeMode(client);
10580
+ if (diagnosis.available) {
10581
+ effectiveMode = "code";
10582
+ } else {
10583
+ warnCodeModeFallback(diagnosis.reason);
10584
+ effectiveMode = "tools";
10585
+ }
10586
+ }
10539
10587
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10588
  const codeTool = buildCodeModeTool(client, {
10541
10589
  tools: mcpTools,
@@ -10724,7 +10772,18 @@ async function getGoogleTools(client, options) {
10724
10772
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10773
  await ensureClientConnected(client);
10726
10774
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10775
+ let effectiveMode;
10776
+ if (options?.mode !== undefined) {
10777
+ effectiveMode = options.mode;
10778
+ } else {
10779
+ const diagnosis = await diagnoseCodeMode(client);
10780
+ if (diagnosis.available) {
10781
+ effectiveMode = "code";
10782
+ } else {
10783
+ warnCodeModeFallback(diagnosis.reason);
10784
+ effectiveMode = "tools";
10785
+ }
10786
+ }
10728
10787
  let googleTools;
10729
10788
  if (effectiveMode === "code") {
10730
10789
  const TypeEnum = await getGoogleType();
@@ -8784,12 +8784,22 @@ function resolveCodeModeClientConfig(client) {
8784
8784
  const oauthConfig = client.__oauthConfig;
8785
8785
  return oauthConfig?.codeMode ?? {};
8786
8786
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8787
+ async function diagnoseCodeMode(client) {
8788
+ if (!await isSandboxAvailable()) {
8789
+ return { available: false, reason: "sandbox-missing" };
8790
+ }
8790
8791
  const serverConfig = resolveCodeModeClientConfig(client);
8791
8792
  const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8793
+ if (!publicUrl) {
8794
+ return { available: false, reason: "no-public-url" };
8795
+ }
8796
+ return { available: true };
8797
+ }
8798
+ function warnCodeModeFallback(reason) {
8799
+ if (warnedCodeModeReasons.has(reason))
8800
+ return;
8801
+ warnedCodeModeReasons.add(reason);
8802
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8803
  }
8794
8804
  function buildCodeModeTool(client, options) {
8795
8805
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8845,7 +8855,7 @@ ${generated.source}
8845
8855
  execute
8846
8856
  };
8847
8857
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8858
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8859
  var init_tool_builder = __esm(() => {
8850
8860
  init_type_generator();
8851
8861
  init_executor();
@@ -8870,6 +8880,11 @@ var init_tool_builder = __esm(() => {
8870
8880
  "API surface:"
8871
8881
  ].join(`
8872
8882
  `);
8883
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8884
+ "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.",
8885
+ "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_PUBLIC_URL` env var."
8886
+ };
8887
+ warnedCodeModeReasons = new Set;
8873
8888
  });
8874
8889
 
8875
8890
  // ../ai/vercel-ai.ts
@@ -8896,7 +8911,18 @@ async function getVercelAITools(client, options) {
8896
8911
  await ensureClientConnected(client);
8897
8912
  const mcpTools = await client.getEnabledToolsAsync();
8898
8913
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8914
+ let effectiveMode;
8915
+ if (options?.mode !== undefined) {
8916
+ effectiveMode = options.mode;
8917
+ } else {
8918
+ const diagnosis = await diagnoseCodeMode(client);
8919
+ if (diagnosis.available) {
8920
+ effectiveMode = "code";
8921
+ } else {
8922
+ warnCodeModeFallback(diagnosis.reason);
8923
+ effectiveMode = "tools";
8924
+ }
8925
+ }
8900
8926
  if (effectiveMode === "code") {
8901
8927
  const codeTool = buildCodeModeTool(client, {
8902
8928
  tools: mcpTools,
@@ -10355,7 +10381,18 @@ async function getOpenAITools(client, options) {
10355
10381
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10382
  await ensureClientConnected(client);
10357
10383
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10384
+ let effectiveMode;
10385
+ if (options?.mode !== undefined) {
10386
+ effectiveMode = options.mode;
10387
+ } else {
10388
+ const diagnosis = await diagnoseCodeMode(client);
10389
+ if (diagnosis.available) {
10390
+ effectiveMode = "code";
10391
+ } else {
10392
+ warnCodeModeFallback(diagnosis.reason);
10393
+ effectiveMode = "tools";
10394
+ }
10395
+ }
10359
10396
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10397
  const codeTool = buildCodeModeTool(client, {
10361
10398
  tools: mcpTools,
@@ -10535,7 +10572,18 @@ async function getAnthropicTools(client, options) {
10535
10572
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10573
  await ensureClientConnected(client);
10537
10574
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10575
+ let effectiveMode;
10576
+ if (options?.mode !== undefined) {
10577
+ effectiveMode = options.mode;
10578
+ } else {
10579
+ const diagnosis = await diagnoseCodeMode(client);
10580
+ if (diagnosis.available) {
10581
+ effectiveMode = "code";
10582
+ } else {
10583
+ warnCodeModeFallback(diagnosis.reason);
10584
+ effectiveMode = "tools";
10585
+ }
10586
+ }
10539
10587
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10588
  const codeTool = buildCodeModeTool(client, {
10541
10589
  tools: mcpTools,
@@ -10724,7 +10772,18 @@ async function getGoogleTools(client, options) {
10724
10772
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10773
  await ensureClientConnected(client);
10726
10774
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10775
+ let effectiveMode;
10776
+ if (options?.mode !== undefined) {
10777
+ effectiveMode = options.mode;
10778
+ } else {
10779
+ const diagnosis = await diagnoseCodeMode(client);
10780
+ if (diagnosis.available) {
10781
+ effectiveMode = "code";
10782
+ } else {
10783
+ warnCodeModeFallback(diagnosis.reason);
10784
+ effectiveMode = "tools";
10785
+ }
10786
+ }
10728
10787
  let googleTools;
10729
10788
  if (effectiveMode === "code") {
10730
10789
  const TypeEnum = await getGoogleType();
@@ -8784,12 +8784,22 @@ function resolveCodeModeClientConfig(client) {
8784
8784
  const oauthConfig = client.__oauthConfig;
8785
8785
  return oauthConfig?.codeMode ?? {};
8786
8786
  }
8787
- async function canUseCodeMode(client) {
8788
- if (!await isSandboxAvailable())
8789
- return false;
8787
+ async function diagnoseCodeMode(client) {
8788
+ if (!await isSandboxAvailable()) {
8789
+ return { available: false, reason: "sandbox-missing" };
8790
+ }
8790
8791
  const serverConfig = resolveCodeModeClientConfig(client);
8791
8792
  const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
8792
- return !!publicUrl;
8793
+ if (!publicUrl) {
8794
+ return { available: false, reason: "no-public-url" };
8795
+ }
8796
+ return { available: true };
8797
+ }
8798
+ function warnCodeModeFallback(reason) {
8799
+ if (warnedCodeModeReasons.has(reason))
8800
+ return;
8801
+ warnedCodeModeReasons.add(reason);
8802
+ console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
8793
8803
  }
8794
8804
  function buildCodeModeTool(client, options) {
8795
8805
  const { tools, providerTokens, context, integrationIds } = options;
@@ -8845,7 +8855,7 @@ ${generated.source}
8845
8855
  execute
8846
8856
  };
8847
8857
  }
8848
- var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
8858
+ var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
8849
8859
  var init_tool_builder = __esm(() => {
8850
8860
  init_type_generator();
8851
8861
  init_executor();
@@ -8870,6 +8880,11 @@ var init_tool_builder = __esm(() => {
8870
8880
  "API surface:"
8871
8881
  ].join(`
8872
8882
  `);
8883
+ CODE_MODE_UNAVAILABLE_MESSAGES = {
8884
+ "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.",
8885
+ "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_PUBLIC_URL` env var."
8886
+ };
8887
+ warnedCodeModeReasons = new Set;
8873
8888
  });
8874
8889
 
8875
8890
  // ../ai/vercel-ai.ts
@@ -8896,7 +8911,18 @@ async function getVercelAITools(client, options) {
8896
8911
  await ensureClientConnected(client);
8897
8912
  const mcpTools = await client.getEnabledToolsAsync();
8898
8913
  const vercelTools = {};
8899
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
8914
+ let effectiveMode;
8915
+ if (options?.mode !== undefined) {
8916
+ effectiveMode = options.mode;
8917
+ } else {
8918
+ const diagnosis = await diagnoseCodeMode(client);
8919
+ if (diagnosis.available) {
8920
+ effectiveMode = "code";
8921
+ } else {
8922
+ warnCodeModeFallback(diagnosis.reason);
8923
+ effectiveMode = "tools";
8924
+ }
8925
+ }
8900
8926
  if (effectiveMode === "code") {
8901
8927
  const codeTool = buildCodeModeTool(client, {
8902
8928
  tools: mcpTools,
@@ -10355,7 +10381,18 @@ async function getOpenAITools(client, options) {
10355
10381
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10356
10382
  await ensureClientConnected(client);
10357
10383
  const mcpTools = await client.getEnabledToolsAsync();
10358
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10384
+ let effectiveMode;
10385
+ if (options?.mode !== undefined) {
10386
+ effectiveMode = options.mode;
10387
+ } else {
10388
+ const diagnosis = await diagnoseCodeMode(client);
10389
+ if (diagnosis.available) {
10390
+ effectiveMode = "code";
10391
+ } else {
10392
+ warnCodeModeFallback(diagnosis.reason);
10393
+ effectiveMode = "tools";
10394
+ }
10395
+ }
10359
10396
  const openaiTools = effectiveMode === "code" ? (() => {
10360
10397
  const codeTool = buildCodeModeTool(client, {
10361
10398
  tools: mcpTools,
@@ -10535,7 +10572,18 @@ async function getAnthropicTools(client, options) {
10535
10572
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10536
10573
  await ensureClientConnected(client);
10537
10574
  const mcpTools = await client.getEnabledToolsAsync();
10538
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10575
+ let effectiveMode;
10576
+ if (options?.mode !== undefined) {
10577
+ effectiveMode = options.mode;
10578
+ } else {
10579
+ const diagnosis = await diagnoseCodeMode(client);
10580
+ if (diagnosis.available) {
10581
+ effectiveMode = "code";
10582
+ } else {
10583
+ warnCodeModeFallback(diagnosis.reason);
10584
+ effectiveMode = "tools";
10585
+ }
10586
+ }
10539
10587
  const anthropicTools = effectiveMode === "code" ? (() => {
10540
10588
  const codeTool = buildCodeModeTool(client, {
10541
10589
  tools: mcpTools,
@@ -10724,7 +10772,18 @@ async function getGoogleTools(client, options) {
10724
10772
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
10725
10773
  await ensureClientConnected(client);
10726
10774
  const mcpTools = await client.getEnabledToolsAsync();
10727
- const effectiveMode = options?.mode !== undefined ? options.mode : await canUseCodeMode(client) ? "code" : "tools";
10775
+ let effectiveMode;
10776
+ if (options?.mode !== undefined) {
10777
+ effectiveMode = options.mode;
10778
+ } else {
10779
+ const diagnosis = await diagnoseCodeMode(client);
10780
+ if (diagnosis.available) {
10781
+ effectiveMode = "code";
10782
+ } else {
10783
+ warnCodeModeFallback(diagnosis.reason);
10784
+ effectiveMode = "tools";
10785
+ }
10786
+ }
10728
10787
  let googleTools;
10729
10788
  if (effectiveMode === "code") {
10730
10789
  const TypeEnum = await getGoogleType();