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.
- package/dist/adapters/auto-routes.js +96 -14
- package/dist/adapters/index.js +96 -14
- package/dist/adapters/nextjs.js +96 -14
- package/dist/adapters/node.js +96 -14
- package/dist/adapters/svelte-kit.js +96 -14
- package/dist/adapters/tanstack-start.js +96 -14
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +39 -8
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +39 -8
- package/dist/ai/index.js +75 -11
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +39 -8
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +39 -8
- package/dist/code-mode/index.js +33 -7
- package/dist/code-mode/tool-builder.d.ts +25 -1
- package/dist/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/code-mode/tool-builder.js +37 -7
- package/dist/index.js +96 -14
- package/dist/oauth.js +96 -14
- package/dist/server.js +96 -14
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/code-mode/tool-builder.d.ts +25 -1
- package/dist/src/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +2 -2
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ai/google.js
CHANGED
|
@@ -4893,12 +4893,30 @@ function resolveCodeModeClientConfig(client) {
|
|
|
4893
4893
|
const oauthConfig = client.__oauthConfig;
|
|
4894
4894
|
return oauthConfig?.codeMode ?? {};
|
|
4895
4895
|
}
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4896
|
+
function resolveCodeModePublicUrl(serverConfig = {}) {
|
|
4897
|
+
return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
|
|
4898
|
+
}
|
|
4899
|
+
async function diagnoseCodeMode(client) {
|
|
4900
|
+
if (!await isSandboxAvailable()) {
|
|
4901
|
+
return { available: false, reason: "sandbox-missing" };
|
|
4902
|
+
}
|
|
4899
4903
|
const serverConfig = resolveCodeModeClientConfig(client);
|
|
4900
|
-
const publicUrl = serverConfig
|
|
4901
|
-
|
|
4904
|
+
const publicUrl = resolveCodeModePublicUrl(serverConfig);
|
|
4905
|
+
if (!publicUrl) {
|
|
4906
|
+
return { available: false, reason: "no-public-url" };
|
|
4907
|
+
}
|
|
4908
|
+
return { available: true };
|
|
4909
|
+
}
|
|
4910
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
4911
|
+
"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.",
|
|
4912
|
+
"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."
|
|
4913
|
+
};
|
|
4914
|
+
var warnedCodeModeReasons = new Set;
|
|
4915
|
+
function warnCodeModeFallback(reason) {
|
|
4916
|
+
if (warnedCodeModeReasons.has(reason))
|
|
4917
|
+
return;
|
|
4918
|
+
warnedCodeModeReasons.add(reason);
|
|
4919
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
4902
4920
|
}
|
|
4903
4921
|
function buildCodeModeTool(client, options) {
|
|
4904
4922
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
@@ -4911,7 +4929,9 @@ function buildCodeModeTool(client, options) {
|
|
|
4911
4929
|
${generated.source}
|
|
4912
4930
|
\`\`\``;
|
|
4913
4931
|
const execute = async ({ code }) => {
|
|
4914
|
-
const publicUrl =
|
|
4932
|
+
const publicUrl = resolveCodeModePublicUrl({
|
|
4933
|
+
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
4934
|
+
});
|
|
4915
4935
|
const apiKey = client.__oauthConfig?.apiKey;
|
|
4916
4936
|
if (!publicUrl) {
|
|
4917
4937
|
return {
|
|
@@ -4920,7 +4940,7 @@ ${generated.source}
|
|
|
4920
4940
|
stdout: "",
|
|
4921
4941
|
stderr: "",
|
|
4922
4942
|
durationMs: 0,
|
|
4923
|
-
error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the
|
|
4943
|
+
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."
|
|
4924
4944
|
};
|
|
4925
4945
|
}
|
|
4926
4946
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
@@ -5079,7 +5099,18 @@ async function getGoogleTools(client, options) {
|
|
|
5079
5099
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
5080
5100
|
await ensureClientConnected(client);
|
|
5081
5101
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
5082
|
-
|
|
5102
|
+
let effectiveMode;
|
|
5103
|
+
if (options?.mode !== undefined) {
|
|
5104
|
+
effectiveMode = options.mode;
|
|
5105
|
+
} else {
|
|
5106
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5107
|
+
if (diagnosis.available) {
|
|
5108
|
+
effectiveMode = "code";
|
|
5109
|
+
} else {
|
|
5110
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5111
|
+
effectiveMode = "tools";
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5083
5114
|
let googleTools;
|
|
5084
5115
|
if (effectiveMode === "code") {
|
|
5085
5116
|
const TypeEnum = await getGoogleType();
|
package/dist/ai/index.js
CHANGED
|
@@ -4893,12 +4893,30 @@ function resolveCodeModeClientConfig(client) {
|
|
|
4893
4893
|
const oauthConfig = client.__oauthConfig;
|
|
4894
4894
|
return oauthConfig?.codeMode ?? {};
|
|
4895
4895
|
}
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4896
|
+
function resolveCodeModePublicUrl(serverConfig = {}) {
|
|
4897
|
+
return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
|
|
4898
|
+
}
|
|
4899
|
+
async function diagnoseCodeMode(client) {
|
|
4900
|
+
if (!await isSandboxAvailable()) {
|
|
4901
|
+
return { available: false, reason: "sandbox-missing" };
|
|
4902
|
+
}
|
|
4899
4903
|
const serverConfig = resolveCodeModeClientConfig(client);
|
|
4900
|
-
const publicUrl = serverConfig
|
|
4901
|
-
|
|
4904
|
+
const publicUrl = resolveCodeModePublicUrl(serverConfig);
|
|
4905
|
+
if (!publicUrl) {
|
|
4906
|
+
return { available: false, reason: "no-public-url" };
|
|
4907
|
+
}
|
|
4908
|
+
return { available: true };
|
|
4909
|
+
}
|
|
4910
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
4911
|
+
"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.",
|
|
4912
|
+
"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."
|
|
4913
|
+
};
|
|
4914
|
+
var warnedCodeModeReasons = new Set;
|
|
4915
|
+
function warnCodeModeFallback(reason) {
|
|
4916
|
+
if (warnedCodeModeReasons.has(reason))
|
|
4917
|
+
return;
|
|
4918
|
+
warnedCodeModeReasons.add(reason);
|
|
4919
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
4902
4920
|
}
|
|
4903
4921
|
function buildCodeModeTool(client, options) {
|
|
4904
4922
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
@@ -4911,7 +4929,9 @@ function buildCodeModeTool(client, options) {
|
|
|
4911
4929
|
${generated.source}
|
|
4912
4930
|
\`\`\``;
|
|
4913
4931
|
const execute = async ({ code }) => {
|
|
4914
|
-
const publicUrl =
|
|
4932
|
+
const publicUrl = resolveCodeModePublicUrl({
|
|
4933
|
+
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
4934
|
+
});
|
|
4915
4935
|
const apiKey = client.__oauthConfig?.apiKey;
|
|
4916
4936
|
if (!publicUrl) {
|
|
4917
4937
|
return {
|
|
@@ -4920,7 +4940,7 @@ ${generated.source}
|
|
|
4920
4940
|
stdout: "",
|
|
4921
4941
|
stderr: "",
|
|
4922
4942
|
durationMs: 0,
|
|
4923
|
-
error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the
|
|
4943
|
+
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."
|
|
4924
4944
|
};
|
|
4925
4945
|
}
|
|
4926
4946
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
@@ -5025,7 +5045,18 @@ async function getAnthropicTools(client, options) {
|
|
|
5025
5045
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
5026
5046
|
await ensureClientConnected(client);
|
|
5027
5047
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
5028
|
-
|
|
5048
|
+
let effectiveMode;
|
|
5049
|
+
if (options?.mode !== undefined) {
|
|
5050
|
+
effectiveMode = options.mode;
|
|
5051
|
+
} else {
|
|
5052
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5053
|
+
if (diagnosis.available) {
|
|
5054
|
+
effectiveMode = "code";
|
|
5055
|
+
} else {
|
|
5056
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5057
|
+
effectiveMode = "tools";
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5029
5060
|
const anthropicTools = effectiveMode === "code" ? (() => {
|
|
5030
5061
|
const codeTool = buildCodeModeTool(client, {
|
|
5031
5062
|
tools: mcpTools,
|
|
@@ -5209,7 +5240,18 @@ async function getGoogleTools(client, options) {
|
|
|
5209
5240
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
5210
5241
|
await ensureClientConnected(client);
|
|
5211
5242
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
5212
|
-
|
|
5243
|
+
let effectiveMode;
|
|
5244
|
+
if (options?.mode !== undefined) {
|
|
5245
|
+
effectiveMode = options.mode;
|
|
5246
|
+
} else {
|
|
5247
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5248
|
+
if (diagnosis.available) {
|
|
5249
|
+
effectiveMode = "code";
|
|
5250
|
+
} else {
|
|
5251
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5252
|
+
effectiveMode = "tools";
|
|
5253
|
+
}
|
|
5254
|
+
}
|
|
5213
5255
|
let googleTools;
|
|
5214
5256
|
if (effectiveMode === "code") {
|
|
5215
5257
|
const TypeEnum = await getGoogleType();
|
|
@@ -5335,7 +5377,18 @@ async function getVercelAITools(client, options) {
|
|
|
5335
5377
|
await ensureClientConnected(client);
|
|
5336
5378
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
5337
5379
|
const vercelTools = {};
|
|
5338
|
-
|
|
5380
|
+
let effectiveMode;
|
|
5381
|
+
if (options?.mode !== undefined) {
|
|
5382
|
+
effectiveMode = options.mode;
|
|
5383
|
+
} else {
|
|
5384
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5385
|
+
if (diagnosis.available) {
|
|
5386
|
+
effectiveMode = "code";
|
|
5387
|
+
} else {
|
|
5388
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5389
|
+
effectiveMode = "tools";
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5339
5392
|
if (effectiveMode === "code") {
|
|
5340
5393
|
const codeTool = buildCodeModeTool(client, {
|
|
5341
5394
|
tools: mcpTools,
|
|
@@ -5385,7 +5438,18 @@ async function getOpenAITools(client, options) {
|
|
|
5385
5438
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
5386
5439
|
await ensureClientConnected(client);
|
|
5387
5440
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
5388
|
-
|
|
5441
|
+
let effectiveMode;
|
|
5442
|
+
if (options?.mode !== undefined) {
|
|
5443
|
+
effectiveMode = options.mode;
|
|
5444
|
+
} else {
|
|
5445
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5446
|
+
if (diagnosis.available) {
|
|
5447
|
+
effectiveMode = "code";
|
|
5448
|
+
} else {
|
|
5449
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5450
|
+
effectiveMode = "tools";
|
|
5451
|
+
}
|
|
5452
|
+
}
|
|
5389
5453
|
const openaiTools = effectiveMode === "code" ? (() => {
|
|
5390
5454
|
const codeTool = buildCodeModeTool(client, {
|
|
5391
5455
|
tools: mcpTools,
|
package/dist/ai/openai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AASjH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,U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
@@ -4893,12 +4893,30 @@ function resolveCodeModeClientConfig(client) {
|
|
|
4893
4893
|
const oauthConfig = client.__oauthConfig;
|
|
4894
4894
|
return oauthConfig?.codeMode ?? {};
|
|
4895
4895
|
}
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4896
|
+
function resolveCodeModePublicUrl(serverConfig = {}) {
|
|
4897
|
+
return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
|
|
4898
|
+
}
|
|
4899
|
+
async function diagnoseCodeMode(client) {
|
|
4900
|
+
if (!await isSandboxAvailable()) {
|
|
4901
|
+
return { available: false, reason: "sandbox-missing" };
|
|
4902
|
+
}
|
|
4899
4903
|
const serverConfig = resolveCodeModeClientConfig(client);
|
|
4900
|
-
const publicUrl = serverConfig
|
|
4901
|
-
|
|
4904
|
+
const publicUrl = resolveCodeModePublicUrl(serverConfig);
|
|
4905
|
+
if (!publicUrl) {
|
|
4906
|
+
return { available: false, reason: "no-public-url" };
|
|
4907
|
+
}
|
|
4908
|
+
return { available: true };
|
|
4909
|
+
}
|
|
4910
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
4911
|
+
"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.",
|
|
4912
|
+
"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."
|
|
4913
|
+
};
|
|
4914
|
+
var warnedCodeModeReasons = new Set;
|
|
4915
|
+
function warnCodeModeFallback(reason) {
|
|
4916
|
+
if (warnedCodeModeReasons.has(reason))
|
|
4917
|
+
return;
|
|
4918
|
+
warnedCodeModeReasons.add(reason);
|
|
4919
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
4902
4920
|
}
|
|
4903
4921
|
function buildCodeModeTool(client, options) {
|
|
4904
4922
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
@@ -4911,7 +4929,9 @@ function buildCodeModeTool(client, options) {
|
|
|
4911
4929
|
${generated.source}
|
|
4912
4930
|
\`\`\``;
|
|
4913
4931
|
const execute = async ({ code }) => {
|
|
4914
|
-
const publicUrl =
|
|
4932
|
+
const publicUrl = resolveCodeModePublicUrl({
|
|
4933
|
+
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
4934
|
+
});
|
|
4915
4935
|
const apiKey = client.__oauthConfig?.apiKey;
|
|
4916
4936
|
if (!publicUrl) {
|
|
4917
4937
|
return {
|
|
@@ -4920,7 +4940,7 @@ ${generated.source}
|
|
|
4920
4940
|
stdout: "",
|
|
4921
4941
|
stderr: "",
|
|
4922
4942
|
durationMs: 0,
|
|
4923
|
-
error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the
|
|
4943
|
+
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."
|
|
4924
4944
|
};
|
|
4925
4945
|
}
|
|
4926
4946
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
@@ -4977,7 +4997,18 @@ async function getOpenAITools(client, options) {
|
|
|
4977
4997
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4978
4998
|
await ensureClientConnected(client);
|
|
4979
4999
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
4980
|
-
|
|
5000
|
+
let effectiveMode;
|
|
5001
|
+
if (options?.mode !== undefined) {
|
|
5002
|
+
effectiveMode = options.mode;
|
|
5003
|
+
} else {
|
|
5004
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5005
|
+
if (diagnosis.available) {
|
|
5006
|
+
effectiveMode = "code";
|
|
5007
|
+
} else {
|
|
5008
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5009
|
+
effectiveMode = "tools";
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
4981
5012
|
const openaiTools = effectiveMode === "code" ? (() => {
|
|
4982
5013
|
const codeTool = buildCodeModeTool(client, {
|
|
4983
5014
|
tools: mcpTools,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../../src/ai/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../../src/ai/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AASpB;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AA+BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,oBAAoB,gCAkE/B"}
|
package/dist/ai/vercel-ai.js
CHANGED
|
@@ -4893,12 +4893,30 @@ function resolveCodeModeClientConfig(client) {
|
|
|
4893
4893
|
const oauthConfig = client.__oauthConfig;
|
|
4894
4894
|
return oauthConfig?.codeMode ?? {};
|
|
4895
4895
|
}
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4896
|
+
function resolveCodeModePublicUrl(serverConfig = {}) {
|
|
4897
|
+
return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
|
|
4898
|
+
}
|
|
4899
|
+
async function diagnoseCodeMode(client) {
|
|
4900
|
+
if (!await isSandboxAvailable()) {
|
|
4901
|
+
return { available: false, reason: "sandbox-missing" };
|
|
4902
|
+
}
|
|
4899
4903
|
const serverConfig = resolveCodeModeClientConfig(client);
|
|
4900
|
-
const publicUrl = serverConfig
|
|
4901
|
-
|
|
4904
|
+
const publicUrl = resolveCodeModePublicUrl(serverConfig);
|
|
4905
|
+
if (!publicUrl) {
|
|
4906
|
+
return { available: false, reason: "no-public-url" };
|
|
4907
|
+
}
|
|
4908
|
+
return { available: true };
|
|
4909
|
+
}
|
|
4910
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
4911
|
+
"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.",
|
|
4912
|
+
"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."
|
|
4913
|
+
};
|
|
4914
|
+
var warnedCodeModeReasons = new Set;
|
|
4915
|
+
function warnCodeModeFallback(reason) {
|
|
4916
|
+
if (warnedCodeModeReasons.has(reason))
|
|
4917
|
+
return;
|
|
4918
|
+
warnedCodeModeReasons.add(reason);
|
|
4919
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
4902
4920
|
}
|
|
4903
4921
|
function buildCodeModeTool(client, options) {
|
|
4904
4922
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
@@ -4911,7 +4929,9 @@ function buildCodeModeTool(client, options) {
|
|
|
4911
4929
|
${generated.source}
|
|
4912
4930
|
\`\`\``;
|
|
4913
4931
|
const execute = async ({ code }) => {
|
|
4914
|
-
const publicUrl =
|
|
4932
|
+
const publicUrl = resolveCodeModePublicUrl({
|
|
4933
|
+
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
4934
|
+
});
|
|
4915
4935
|
const apiKey = client.__oauthConfig?.apiKey;
|
|
4916
4936
|
if (!publicUrl) {
|
|
4917
4937
|
return {
|
|
@@ -4920,7 +4940,7 @@ ${generated.source}
|
|
|
4920
4940
|
stdout: "",
|
|
4921
4941
|
stderr: "",
|
|
4922
4942
|
durationMs: 0,
|
|
4923
|
-
error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the
|
|
4943
|
+
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."
|
|
4924
4944
|
};
|
|
4925
4945
|
}
|
|
4926
4946
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
@@ -4979,7 +4999,18 @@ async function getVercelAITools(client, options) {
|
|
|
4979
4999
|
await ensureClientConnected(client);
|
|
4980
5000
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
4981
5001
|
const vercelTools = {};
|
|
4982
|
-
|
|
5002
|
+
let effectiveMode;
|
|
5003
|
+
if (options?.mode !== undefined) {
|
|
5004
|
+
effectiveMode = options.mode;
|
|
5005
|
+
} else {
|
|
5006
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
5007
|
+
if (diagnosis.available) {
|
|
5008
|
+
effectiveMode = "code";
|
|
5009
|
+
} else {
|
|
5010
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
5011
|
+
effectiveMode = "tools";
|
|
5012
|
+
}
|
|
5013
|
+
}
|
|
4983
5014
|
if (effectiveMode === "code") {
|
|
4984
5015
|
const codeTool = buildCodeModeTool(client, {
|
|
4985
5016
|
tools: mcpTools,
|
package/dist/code-mode/index.js
CHANGED
|
@@ -498,12 +498,36 @@ function resolveCodeModeClientConfig(client) {
|
|
|
498
498
|
const oauthConfig = client.__oauthConfig;
|
|
499
499
|
return oauthConfig?.codeMode ?? {};
|
|
500
500
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
501
|
+
function resolveCodeModePublicUrl(serverConfig = {}) {
|
|
502
|
+
return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
|
|
503
|
+
}
|
|
504
|
+
async function diagnoseCodeMode(client) {
|
|
505
|
+
if (!await isSandboxAvailable()) {
|
|
506
|
+
return { available: false, reason: "sandbox-missing" };
|
|
507
|
+
}
|
|
504
508
|
const serverConfig = resolveCodeModeClientConfig(client);
|
|
505
|
-
const publicUrl = serverConfig
|
|
506
|
-
|
|
509
|
+
const publicUrl = resolveCodeModePublicUrl(serverConfig);
|
|
510
|
+
if (!publicUrl) {
|
|
511
|
+
return { available: false, reason: "no-public-url" };
|
|
512
|
+
}
|
|
513
|
+
return { available: true };
|
|
514
|
+
}
|
|
515
|
+
async function canUseCodeMode(client) {
|
|
516
|
+
return (await diagnoseCodeMode(client)).available;
|
|
517
|
+
}
|
|
518
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
519
|
+
"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.",
|
|
520
|
+
"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."
|
|
521
|
+
};
|
|
522
|
+
var warnedCodeModeReasons = new Set;
|
|
523
|
+
function __resetCodeModeFallbackWarnings() {
|
|
524
|
+
warnedCodeModeReasons.clear();
|
|
525
|
+
}
|
|
526
|
+
function warnCodeModeFallback(reason) {
|
|
527
|
+
if (warnedCodeModeReasons.has(reason))
|
|
528
|
+
return;
|
|
529
|
+
warnedCodeModeReasons.add(reason);
|
|
530
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
507
531
|
}
|
|
508
532
|
function buildCodeModeTool(client, options) {
|
|
509
533
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
@@ -516,7 +540,9 @@ function buildCodeModeTool(client, options) {
|
|
|
516
540
|
${generated.source}
|
|
517
541
|
\`\`\``;
|
|
518
542
|
const execute = async ({ code }) => {
|
|
519
|
-
const publicUrl =
|
|
543
|
+
const publicUrl = resolveCodeModePublicUrl({
|
|
544
|
+
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
545
|
+
});
|
|
520
546
|
const apiKey = client.__oauthConfig?.apiKey;
|
|
521
547
|
if (!publicUrl) {
|
|
522
548
|
return {
|
|
@@ -525,7 +551,7 @@ ${generated.source}
|
|
|
525
551
|
stdout: "",
|
|
526
552
|
stderr: "",
|
|
527
553
|
durationMs: 0,
|
|
528
|
-
error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the
|
|
554
|
+
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."
|
|
529
555
|
};
|
|
530
556
|
}
|
|
531
557
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
@@ -27,7 +27,7 @@ export interface CodeModeToolOptions {
|
|
|
27
27
|
/**
|
|
28
28
|
* Sandbox + callback overrides. Everything is optional — defaults come
|
|
29
29
|
* from the server client's `__oauthConfig.codeMode` block (set by
|
|
30
|
-
* `createMCPServer`) or from `
|
|
30
|
+
* `createMCPServer`) or from `INTEGRATE_URL`.
|
|
31
31
|
*/
|
|
32
32
|
sandbox?: {
|
|
33
33
|
publicUrl?: string;
|
|
@@ -74,7 +74,31 @@ export declare function resolveCodeModeClientConfig(client: MCPClient<any>): {
|
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
|
+
export type CodeModeUnavailableReason = "sandbox-missing" | "no-public-url";
|
|
78
|
+
export type CodeModeDiagnosis = {
|
|
79
|
+
available: true;
|
|
80
|
+
} | {
|
|
81
|
+
available: false;
|
|
82
|
+
reason: CodeModeUnavailableReason;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Resolve the public URL the sandbox should call back into. Precedence:
|
|
86
|
+
* 1. Explicit `codeMode.publicUrl` on the server config
|
|
87
|
+
* 2. `INTEGRATE_URL` env var (same variable used for OAuth redirect auto-detect)
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveCodeModePublicUrl(serverConfig?: {
|
|
90
|
+
publicUrl?: string;
|
|
91
|
+
}): string | undefined;
|
|
92
|
+
export declare function diagnoseCodeMode(client: MCPClient<any>): Promise<CodeModeDiagnosis>;
|
|
77
93
|
export declare function canUseCodeMode(client: MCPClient<any>): Promise<boolean>;
|
|
94
|
+
/** @internal — used by unit tests to reset the warn-once throttle. */
|
|
95
|
+
export declare function __resetCodeModeFallbackWarnings(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Called by AI helpers when auto-detection picks `tools` mode. Emits a
|
|
98
|
+
* throttled `console.warn` so operators can tell *why* Code Mode was
|
|
99
|
+
* silently downgraded. Each reason warns at most once per process.
|
|
100
|
+
*/
|
|
101
|
+
export declare function warnCodeModeFallback(reason: CodeModeUnavailableReason): void;
|
|
78
102
|
/**
|
|
79
103
|
* Build the `execute_code` tool definition. The returned `execute` function
|
|
80
104
|
* is what the AI provider SDK ultimately invokes when the model picks the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-builder.d.ts","sourceRoot":"","sources":["../../../src/code-mode/tool-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,iCAAiC;IACjC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,aAAa,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG;YAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE;gBAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE,CAAA;SAAE,CAAC;KAClH,CAAC;CACH;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE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E,mBAAmB,GAC3B,sBAAsB,CA8DxB"}
|
|
@@ -498,12 +498,36 @@ function resolveCodeModeClientConfig(client) {
|
|
|
498
498
|
const oauthConfig = client.__oauthConfig;
|
|
499
499
|
return oauthConfig?.codeMode ?? {};
|
|
500
500
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
501
|
+
function resolveCodeModePublicUrl(serverConfig = {}) {
|
|
502
|
+
return serverConfig.publicUrl ?? getEnv("INTEGRATE_URL");
|
|
503
|
+
}
|
|
504
|
+
async function diagnoseCodeMode(client) {
|
|
505
|
+
if (!await isSandboxAvailable()) {
|
|
506
|
+
return { available: false, reason: "sandbox-missing" };
|
|
507
|
+
}
|
|
504
508
|
const serverConfig = resolveCodeModeClientConfig(client);
|
|
505
|
-
const publicUrl = serverConfig
|
|
506
|
-
|
|
509
|
+
const publicUrl = resolveCodeModePublicUrl(serverConfig);
|
|
510
|
+
if (!publicUrl) {
|
|
511
|
+
return { available: false, reason: "no-public-url" };
|
|
512
|
+
}
|
|
513
|
+
return { available: true };
|
|
514
|
+
}
|
|
515
|
+
async function canUseCodeMode(client) {
|
|
516
|
+
return (await diagnoseCodeMode(client)).available;
|
|
517
|
+
}
|
|
518
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
519
|
+
"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.",
|
|
520
|
+
"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."
|
|
521
|
+
};
|
|
522
|
+
var warnedCodeModeReasons = new Set;
|
|
523
|
+
function __resetCodeModeFallbackWarnings() {
|
|
524
|
+
warnedCodeModeReasons.clear();
|
|
525
|
+
}
|
|
526
|
+
function warnCodeModeFallback(reason) {
|
|
527
|
+
if (warnedCodeModeReasons.has(reason))
|
|
528
|
+
return;
|
|
529
|
+
warnedCodeModeReasons.add(reason);
|
|
530
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
507
531
|
}
|
|
508
532
|
function buildCodeModeTool(client, options) {
|
|
509
533
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
@@ -516,7 +540,9 @@ function buildCodeModeTool(client, options) {
|
|
|
516
540
|
${generated.source}
|
|
517
541
|
\`\`\``;
|
|
518
542
|
const execute = async ({ code }) => {
|
|
519
|
-
const publicUrl =
|
|
543
|
+
const publicUrl = resolveCodeModePublicUrl({
|
|
544
|
+
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
545
|
+
});
|
|
520
546
|
const apiKey = client.__oauthConfig?.apiKey;
|
|
521
547
|
if (!publicUrl) {
|
|
522
548
|
return {
|
|
@@ -525,7 +551,7 @@ ${generated.source}
|
|
|
525
551
|
stdout: "",
|
|
526
552
|
stderr: "",
|
|
527
553
|
durationMs: 0,
|
|
528
|
-
error: "Code Mode requires `codeMode.publicUrl` in createMCPServer config (or the
|
|
554
|
+
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."
|
|
529
555
|
};
|
|
530
556
|
}
|
|
531
557
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
@@ -560,8 +586,12 @@ ${generated.source}
|
|
|
560
586
|
};
|
|
561
587
|
}
|
|
562
588
|
export {
|
|
589
|
+
warnCodeModeFallback,
|
|
590
|
+
resolveCodeModePublicUrl,
|
|
563
591
|
resolveCodeModeClientConfig,
|
|
592
|
+
diagnoseCodeMode,
|
|
564
593
|
canUseCodeMode,
|
|
565
594
|
buildCodeModeTool,
|
|
595
|
+
__resetCodeModeFallbackWarnings,
|
|
566
596
|
CODE_MODE_TOOL_NAME
|
|
567
597
|
};
|