integrate-sdk 0.9.13-dev.0 → 0.9.15-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 +178 -44818
- package/dist/adapters/base-handler.d.ts.map +1 -1
- package/dist/adapters/base-handler.js +838 -0
- package/dist/adapters/context-cookie.js +0 -18
- package/dist/adapters/index.js +3372 -45064
- package/dist/adapters/nextjs-oauth-redirect.js +0 -21
- package/dist/adapters/nextjs.js +282 -44594
- package/dist/adapters/node.js +33 -45452
- package/dist/adapters/session-detector.js +135 -54
- package/dist/adapters/solid-start.js +3634 -18
- package/dist/adapters/svelte-kit.js +3347 -45021
- package/dist/adapters/tanstack-start.js +7 -45473
- package/dist/ai/anthropic.js +13 -1
- package/dist/ai/google.js +13 -1
- package/dist/ai/index.js +13 -1
- package/dist/ai/openai.js +13 -1
- package/dist/ai/vercel-ai.js +13 -1
- package/dist/code-mode/executor.d.ts.map +1 -1
- package/dist/code-mode/executor.js +13 -1
- package/dist/code-mode/index.js +13 -1
- package/dist/code-mode/runtime-stub.d.ts +1 -1
- package/dist/code-mode/runtime-stub.d.ts.map +1 -1
- package/dist/code-mode/runtime-stub.js +8 -1
- package/dist/code-mode/tool-builder.js +13 -1
- package/dist/index.js +4196 -12593
- package/dist/oauth.js +21 -12219
- package/dist/react.js +14 -38
- package/dist/server.js +9280 -9622
- package/dist/src/adapters/base-handler.d.ts.map +1 -1
- package/dist/src/code-mode/executor.d.ts.map +1 -1
- package/dist/src/code-mode/runtime-stub.d.ts +1 -1
- package/dist/src/code-mode/runtime-stub.d.ts.map +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/server.d.ts +2 -0
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ai/anthropic.js
CHANGED
|
@@ -4677,7 +4677,14 @@ async function callTool(toolName, args) {
|
|
|
4677
4677
|
}
|
|
4678
4678
|
|
|
4679
4679
|
if (!res.ok) {
|
|
4680
|
-
|
|
4680
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
4681
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
4682
|
+
message =
|
|
4683
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
4684
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
4685
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
4686
|
+
'AI helper. Original upstream message: ' + text;
|
|
4687
|
+
}
|
|
4681
4688
|
const err = new Error(message);
|
|
4682
4689
|
err.status = res.status;
|
|
4683
4690
|
err.toolName = toolName;
|
|
@@ -4726,6 +4733,11 @@ async function isSandboxAvailable() {
|
|
|
4726
4733
|
_sandboxImportError = null;
|
|
4727
4734
|
return true;
|
|
4728
4735
|
}
|
|
4736
|
+
if (typeof window !== "undefined") {
|
|
4737
|
+
_sandboxAvailableCache = false;
|
|
4738
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
4739
|
+
return false;
|
|
4740
|
+
}
|
|
4729
4741
|
try {
|
|
4730
4742
|
await import("@vercel/sandbox");
|
|
4731
4743
|
_sandboxAvailableCache = true;
|
package/dist/ai/google.js
CHANGED
|
@@ -4677,7 +4677,14 @@ async function callTool(toolName, args) {
|
|
|
4677
4677
|
}
|
|
4678
4678
|
|
|
4679
4679
|
if (!res.ok) {
|
|
4680
|
-
|
|
4680
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
4681
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
4682
|
+
message =
|
|
4683
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
4684
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
4685
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
4686
|
+
'AI helper. Original upstream message: ' + text;
|
|
4687
|
+
}
|
|
4681
4688
|
const err = new Error(message);
|
|
4682
4689
|
err.status = res.status;
|
|
4683
4690
|
err.toolName = toolName;
|
|
@@ -4726,6 +4733,11 @@ async function isSandboxAvailable() {
|
|
|
4726
4733
|
_sandboxImportError = null;
|
|
4727
4734
|
return true;
|
|
4728
4735
|
}
|
|
4736
|
+
if (typeof window !== "undefined") {
|
|
4737
|
+
_sandboxAvailableCache = false;
|
|
4738
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
4739
|
+
return false;
|
|
4740
|
+
}
|
|
4729
4741
|
try {
|
|
4730
4742
|
await import("@vercel/sandbox");
|
|
4731
4743
|
_sandboxAvailableCache = true;
|
package/dist/ai/index.js
CHANGED
|
@@ -4677,7 +4677,14 @@ async function callTool(toolName, args) {
|
|
|
4677
4677
|
}
|
|
4678
4678
|
|
|
4679
4679
|
if (!res.ok) {
|
|
4680
|
-
|
|
4680
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
4681
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
4682
|
+
message =
|
|
4683
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
4684
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
4685
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
4686
|
+
'AI helper. Original upstream message: ' + text;
|
|
4687
|
+
}
|
|
4681
4688
|
const err = new Error(message);
|
|
4682
4689
|
err.status = res.status;
|
|
4683
4690
|
err.toolName = toolName;
|
|
@@ -4726,6 +4733,11 @@ async function isSandboxAvailable() {
|
|
|
4726
4733
|
_sandboxImportError = null;
|
|
4727
4734
|
return true;
|
|
4728
4735
|
}
|
|
4736
|
+
if (typeof window !== "undefined") {
|
|
4737
|
+
_sandboxAvailableCache = false;
|
|
4738
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
4739
|
+
return false;
|
|
4740
|
+
}
|
|
4729
4741
|
try {
|
|
4730
4742
|
await import("@vercel/sandbox");
|
|
4731
4743
|
_sandboxAvailableCache = true;
|
package/dist/ai/openai.js
CHANGED
|
@@ -4677,7 +4677,14 @@ async function callTool(toolName, args) {
|
|
|
4677
4677
|
}
|
|
4678
4678
|
|
|
4679
4679
|
if (!res.ok) {
|
|
4680
|
-
|
|
4680
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
4681
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
4682
|
+
message =
|
|
4683
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
4684
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
4685
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
4686
|
+
'AI helper. Original upstream message: ' + text;
|
|
4687
|
+
}
|
|
4681
4688
|
const err = new Error(message);
|
|
4682
4689
|
err.status = res.status;
|
|
4683
4690
|
err.toolName = toolName;
|
|
@@ -4726,6 +4733,11 @@ async function isSandboxAvailable() {
|
|
|
4726
4733
|
_sandboxImportError = null;
|
|
4727
4734
|
return true;
|
|
4728
4735
|
}
|
|
4736
|
+
if (typeof window !== "undefined") {
|
|
4737
|
+
_sandboxAvailableCache = false;
|
|
4738
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
4739
|
+
return false;
|
|
4740
|
+
}
|
|
4729
4741
|
try {
|
|
4730
4742
|
await import("@vercel/sandbox");
|
|
4731
4743
|
_sandboxAvailableCache = true;
|
package/dist/ai/vercel-ai.js
CHANGED
|
@@ -4677,7 +4677,14 @@ async function callTool(toolName, args) {
|
|
|
4677
4677
|
}
|
|
4678
4678
|
|
|
4679
4679
|
if (!res.ok) {
|
|
4680
|
-
|
|
4680
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
4681
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
4682
|
+
message =
|
|
4683
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
4684
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
4685
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
4686
|
+
'AI helper. Original upstream message: ' + text;
|
|
4687
|
+
}
|
|
4681
4688
|
const err = new Error(message);
|
|
4682
4689
|
err.status = res.status;
|
|
4683
4690
|
err.toolName = toolName;
|
|
@@ -4726,6 +4733,11 @@ async function isSandboxAvailable() {
|
|
|
4726
4733
|
_sandboxImportError = null;
|
|
4727
4734
|
return true;
|
|
4728
4735
|
}
|
|
4736
|
+
if (typeof window !== "undefined") {
|
|
4737
|
+
_sandboxAvailableCache = false;
|
|
4738
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
4739
|
+
return false;
|
|
4740
|
+
}
|
|
4729
4741
|
try {
|
|
4730
4742
|
await import("@vercel/sandbox");
|
|
4731
4743
|
_sandboxAvailableCache = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/code-mode/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD;;;;GAIG;AACH,UAAU,WAAW;IACnB,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,UAAU,CACR,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ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C,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,qDAAqD;IACrD,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,aAAa,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAA;KAAE,CAAC;CAClH;AAED,MAAM,WAAW,wBAAwB;IACvC,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA4DD;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAsE9G"}
|
|
@@ -60,7 +60,14 @@ async function callTool(toolName, args) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!res.ok) {
|
|
63
|
-
|
|
63
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
64
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
65
|
+
message =
|
|
66
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
67
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
68
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
69
|
+
'AI helper. Original upstream message: ' + text;
|
|
70
|
+
}
|
|
64
71
|
const err = new Error(message);
|
|
65
72
|
err.status = res.status;
|
|
66
73
|
err.toolName = toolName;
|
|
@@ -120,6 +127,11 @@ async function isSandboxAvailable() {
|
|
|
120
127
|
_sandboxImportError = null;
|
|
121
128
|
return true;
|
|
122
129
|
}
|
|
130
|
+
if (typeof window !== "undefined") {
|
|
131
|
+
_sandboxAvailableCache = false;
|
|
132
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
123
135
|
try {
|
|
124
136
|
await import("@vercel/sandbox");
|
|
125
137
|
_sandboxAvailableCache = true;
|
package/dist/code-mode/index.js
CHANGED
|
@@ -275,7 +275,14 @@ async function callTool(toolName, args) {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
if (!res.ok) {
|
|
278
|
-
|
|
278
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
279
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
280
|
+
message =
|
|
281
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
282
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
283
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
284
|
+
'AI helper. Original upstream message: ' + text;
|
|
285
|
+
}
|
|
279
286
|
const err = new Error(message);
|
|
280
287
|
err.status = res.status;
|
|
281
288
|
err.toolName = toolName;
|
|
@@ -335,6 +342,11 @@ async function isSandboxAvailable() {
|
|
|
335
342
|
_sandboxImportError = null;
|
|
336
343
|
return true;
|
|
337
344
|
}
|
|
345
|
+
if (typeof window !== "undefined") {
|
|
346
|
+
_sandboxAvailableCache = false;
|
|
347
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
338
350
|
try {
|
|
339
351
|
await import("@vercel/sandbox");
|
|
340
352
|
_sandboxAvailableCache = true;
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
* dependencies. It is NOT imported by the host SDK — it only ships as a
|
|
13
13
|
* literal payload to the sandbox.
|
|
14
14
|
*/
|
|
15
|
-
export declare const RUNTIME_STUB_SOURCE = "// runtime.mjs \u2014 generated by integrate-sdk code mode\nconst MCP_URL = process.env.INTEGRATE_MCP_URL;\nconst SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;\nconst API_KEY = process.env.INTEGRATE_API_KEY || '';\nconst PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';\nconst INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';\nconst CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';\n\nif (!MCP_URL) {\n throw new Error('INTEGRATE_MCP_URL is not set \u2014 the sandbox cannot reach the MCP route.');\n}\n\nfunction camelToSnake(str) {\n return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());\n}\n\nasync function callTool(toolName, args) {\n const headers = {\n 'Content-Type': 'application/json',\n 'x-integrate-code-mode': '1',\n };\n if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;\n if (API_KEY) headers['x-integrate-api-key'] = API_KEY;\n if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;\n if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;\n if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;\n\n const res = await fetch(MCP_URL, {\n method: 'POST',\n headers,\n body: JSON.stringify({ name: toolName, arguments: args || {} }),\n });\n\n const text = await res.text();\n let payload;\n try {\n payload = text ? JSON.parse(text) : null;\n } catch {\n payload = { content: [{ type: 'text', text }] };\n }\n\n if (!res.ok) {\n
|
|
15
|
+
export declare const RUNTIME_STUB_SOURCE = "// runtime.mjs \u2014 generated by integrate-sdk code mode\nconst MCP_URL = process.env.INTEGRATE_MCP_URL;\nconst SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;\nconst API_KEY = process.env.INTEGRATE_API_KEY || '';\nconst PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';\nconst INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';\nconst CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';\n\nif (!MCP_URL) {\n throw new Error('INTEGRATE_MCP_URL is not set \u2014 the sandbox cannot reach the MCP route.');\n}\n\nfunction camelToSnake(str) {\n return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());\n}\n\nasync function callTool(toolName, args) {\n const headers = {\n 'Content-Type': 'application/json',\n 'x-integrate-code-mode': '1',\n };\n if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;\n if (API_KEY) headers['x-integrate-api-key'] = API_KEY;\n if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;\n if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;\n if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;\n\n const res = await fetch(MCP_URL, {\n method: 'POST',\n headers,\n body: JSON.stringify({ name: toolName, arguments: args || {} }),\n });\n\n const text = await res.text();\n let payload;\n try {\n payload = text ? JSON.parse(text) : null;\n } catch {\n payload = { content: [{ type: 'text', text }] };\n }\n\n if (!res.ok) {\n let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;\n if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {\n message =\n 'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +\n 'The SDK route could not synthesize an Authorization header. Check the host-side ' +\n 'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +\n 'AI helper. Original upstream message: ' + text;\n }\n const err = new Error(message);\n err.status = res.status;\n err.toolName = toolName;\n throw err;\n }\n\n return payload;\n}\n\nfunction createIntegrationProxy(integrationId) {\n return new Proxy({}, {\n get(_target, methodName) {\n if (typeof methodName !== 'string') return undefined;\n return (args) => callTool(integrationId + '_' + camelToSnake(methodName), args);\n },\n });\n}\n\nexport const client = new Proxy({}, {\n get(_target, integrationId) {\n if (typeof integrationId !== 'string') return undefined;\n return createIntegrationProxy(integrationId);\n },\n});\n\nexport { callTool };\n";
|
|
16
16
|
//# sourceMappingURL=runtime-stub.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-stub.d.ts","sourceRoot":"","sources":["../../../src/code-mode/runtime-stub.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"runtime-stub.d.ts","sourceRoot":"","sources":["../../../src/code-mode/runtime-stub.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,mBAAmB,8rFA4E/B,CAAC"}
|
|
@@ -60,7 +60,14 @@ async function callTool(toolName, args) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!res.ok) {
|
|
63
|
-
|
|
63
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
64
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
65
|
+
message =
|
|
66
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
67
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
68
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
69
|
+
'AI helper. Original upstream message: ' + text;
|
|
70
|
+
}
|
|
64
71
|
const err = new Error(message);
|
|
65
72
|
err.status = res.status;
|
|
66
73
|
err.toolName = toolName;
|
|
@@ -275,7 +275,14 @@ async function callTool(toolName, args) {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
if (!res.ok) {
|
|
278
|
-
|
|
278
|
+
let message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;
|
|
279
|
+
if ((res.status === 401 || res.status === 403) && typeof text === 'string' && text.indexOf('Authorization header') !== -1) {
|
|
280
|
+
message =
|
|
281
|
+
'Code Mode callback was rejected by the MCP server (HTTP ' + res.status + '). ' +
|
|
282
|
+
'The SDK route could not synthesize an Authorization header. Check the host-side ' +
|
|
283
|
+
'createMCPServer config (apiKey, getProviderToken) or pass providerTokens to the ' +
|
|
284
|
+
'AI helper. Original upstream message: ' + text;
|
|
285
|
+
}
|
|
279
286
|
const err = new Error(message);
|
|
280
287
|
err.status = res.status;
|
|
281
288
|
err.toolName = toolName;
|
|
@@ -335,6 +342,11 @@ async function isSandboxAvailable() {
|
|
|
335
342
|
_sandboxImportError = null;
|
|
336
343
|
return true;
|
|
337
344
|
}
|
|
345
|
+
if (typeof window !== "undefined") {
|
|
346
|
+
_sandboxAvailableCache = false;
|
|
347
|
+
_sandboxImportError = new Error("Sandbox is not available in browser environments.");
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
338
350
|
try {
|
|
339
351
|
await import("@vercel/sandbox");
|
|
340
352
|
_sandboxAvailableCache = true;
|