integrate-sdk 0.9.5-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.
- package/dist/adapters/auto-routes.js +129 -10
- package/dist/adapters/index.js +129 -10
- package/dist/adapters/nextjs.js +129 -10
- package/dist/adapters/node.js +129 -10
- package/dist/adapters/svelte-kit.js +129 -10
- package/dist/adapters/tanstack-start.js +129 -10
- package/dist/ai/anthropic.d.ts +2 -2
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +64 -2
- package/dist/ai/google.d.ts +2 -2
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +64 -2
- package/dist/ai/index.js +103 -8
- package/dist/ai/openai.d.ts +2 -2
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +64 -2
- package/dist/ai/vercel-ai.d.ts +2 -2
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +64 -2
- package/dist/code-mode/executor.d.ts +5 -0
- package/dist/code-mode/executor.d.ts.map +1 -1
- package/dist/code-mode/executor.js +35 -0
- package/dist/code-mode/index.d.ts +1 -1
- package/dist/code-mode/index.d.ts.map +1 -1
- package/dist/code-mode/index.js +64 -0
- 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 +2 -0
- package/dist/code-mode/tool-builder.d.ts +17 -0
- package/dist/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/code-mode/tool-builder.js +67 -0
- package/dist/index.js +129 -10
- package/dist/oauth.js +129 -10
- package/dist/server.js +129 -10
- package/dist/src/ai/anthropic.d.ts +2 -2
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts +2 -2
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts +2 -2
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts +2 -2
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/code-mode/executor.d.ts +5 -0
- package/dist/src/code-mode/executor.d.ts.map +1 -1
- package/dist/src/code-mode/index.d.ts +1 -1
- package/dist/src/code-mode/index.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/code-mode/tool-builder.d.ts +17 -0
- package/dist/src/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +3 -6
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
|
|
3
3
|
const MCP_URL = process.env.INTEGRATE_MCP_URL;
|
|
4
4
|
const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
|
|
5
|
+
const API_KEY = process.env.INTEGRATE_API_KEY || '';
|
|
5
6
|
const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
|
|
6
7
|
const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
|
|
7
8
|
const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
|
|
@@ -20,6 +21,7 @@ async function callTool(toolName, args) {
|
|
|
20
21
|
'x-integrate-code-mode': '1',
|
|
21
22
|
};
|
|
22
23
|
if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
|
|
24
|
+
if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
|
|
23
25
|
if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
|
|
24
26
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
25
27
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
@@ -70,8 +72,37 @@ export { callTool };
|
|
|
70
72
|
|
|
71
73
|
// executor.ts
|
|
72
74
|
var sandboxFactoryOverride = null;
|
|
75
|
+
var _sandboxAvailableCache = null;
|
|
76
|
+
var _sandboxForcedUnavailableForTests = false;
|
|
73
77
|
function __setSandboxFactoryForTests(factory) {
|
|
74
78
|
sandboxFactoryOverride = factory;
|
|
79
|
+
_sandboxForcedUnavailableForTests = false;
|
|
80
|
+
_sandboxAvailableCache = null;
|
|
81
|
+
}
|
|
82
|
+
function __setSandboxUnavailableForTests(force) {
|
|
83
|
+
_sandboxForcedUnavailableForTests = force;
|
|
84
|
+
_sandboxAvailableCache = null;
|
|
85
|
+
}
|
|
86
|
+
async function isSandboxAvailable() {
|
|
87
|
+
if (_sandboxAvailableCache !== null)
|
|
88
|
+
return _sandboxAvailableCache;
|
|
89
|
+
if (_sandboxForcedUnavailableForTests) {
|
|
90
|
+
_sandboxAvailableCache = false;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (sandboxFactoryOverride) {
|
|
94
|
+
_sandboxAvailableCache = true;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
99
|
+
await dynamicImport("@" + "vercel/sandbox");
|
|
100
|
+
_sandboxAvailableCache = true;
|
|
101
|
+
return true;
|
|
102
|
+
} catch {
|
|
103
|
+
_sandboxAvailableCache = false;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
75
106
|
}
|
|
76
107
|
async function loadSandboxFactory() {
|
|
77
108
|
if (sandboxFactoryOverride)
|
|
@@ -159,6 +190,8 @@ async function executeSandboxCode(options) {
|
|
|
159
190
|
const env = {
|
|
160
191
|
INTEGRATE_MCP_URL: options.mcpUrl
|
|
161
192
|
};
|
|
193
|
+
if (options.apiKey)
|
|
194
|
+
env.INTEGRATE_API_KEY = options.apiKey;
|
|
162
195
|
if (options.sessionToken)
|
|
163
196
|
env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
|
|
164
197
|
if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
|
|
@@ -202,6 +235,8 @@ async function executeSandboxCode(options) {
|
|
|
202
235
|
}
|
|
203
236
|
}
|
|
204
237
|
export {
|
|
238
|
+
isSandboxAvailable,
|
|
205
239
|
executeSandboxCode,
|
|
240
|
+
__setSandboxUnavailableForTests,
|
|
206
241
|
__setSandboxFactoryForTests
|
|
207
242
|
};
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
export { generateCodeModeTypes, type GeneratedTypes, } from "./type-generator.js";
|
|
9
9
|
export { executeSandboxCode, __setSandboxFactoryForTests, type ExecuteSandboxCodeOptions, type ExecuteSandboxCodeResult, } from "./executor.js";
|
|
10
10
|
export { RUNTIME_STUB_SOURCE } from "./runtime-stub.js";
|
|
11
|
-
export { buildCodeModeTool, CODE_MODE_TOOL_NAME, type CodeModeToolOptions, type CodeModeToolDefinition, } from "./tool-builder.js";
|
|
11
|
+
export { buildCodeModeTool, canUseCodeMode, CODE_MODE_TOOL_NAME, type CodeModeToolOptions, type CodeModeToolDefinition, } from "./tool-builder.js";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code-mode/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,GACpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,GAC5B,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code-mode/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,GACpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,GAC5B,MAAM,mBAAmB,CAAC"}
|
package/dist/code-mode/index.js
CHANGED
|
@@ -217,6 +217,7 @@ function pascalCase(id) {
|
|
|
217
217
|
var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
|
|
218
218
|
const MCP_URL = process.env.INTEGRATE_MCP_URL;
|
|
219
219
|
const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
|
|
220
|
+
const API_KEY = process.env.INTEGRATE_API_KEY || '';
|
|
220
221
|
const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
|
|
221
222
|
const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
|
|
222
223
|
const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
|
|
@@ -235,6 +236,7 @@ async function callTool(toolName, args) {
|
|
|
235
236
|
'x-integrate-code-mode': '1',
|
|
236
237
|
};
|
|
237
238
|
if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
|
|
239
|
+
if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
|
|
238
240
|
if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
|
|
239
241
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
240
242
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
@@ -285,8 +287,37 @@ export { callTool };
|
|
|
285
287
|
|
|
286
288
|
// executor.ts
|
|
287
289
|
var sandboxFactoryOverride = null;
|
|
290
|
+
var _sandboxAvailableCache = null;
|
|
291
|
+
var _sandboxForcedUnavailableForTests = false;
|
|
288
292
|
function __setSandboxFactoryForTests(factory) {
|
|
289
293
|
sandboxFactoryOverride = factory;
|
|
294
|
+
_sandboxForcedUnavailableForTests = false;
|
|
295
|
+
_sandboxAvailableCache = null;
|
|
296
|
+
}
|
|
297
|
+
function __setSandboxUnavailableForTests(force) {
|
|
298
|
+
_sandboxForcedUnavailableForTests = force;
|
|
299
|
+
_sandboxAvailableCache = null;
|
|
300
|
+
}
|
|
301
|
+
async function isSandboxAvailable() {
|
|
302
|
+
if (_sandboxAvailableCache !== null)
|
|
303
|
+
return _sandboxAvailableCache;
|
|
304
|
+
if (_sandboxForcedUnavailableForTests) {
|
|
305
|
+
_sandboxAvailableCache = false;
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
if (sandboxFactoryOverride) {
|
|
309
|
+
_sandboxAvailableCache = true;
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
314
|
+
await dynamicImport("@" + "vercel/sandbox");
|
|
315
|
+
_sandboxAvailableCache = true;
|
|
316
|
+
return true;
|
|
317
|
+
} catch {
|
|
318
|
+
_sandboxAvailableCache = false;
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
290
321
|
}
|
|
291
322
|
async function loadSandboxFactory() {
|
|
292
323
|
if (sandboxFactoryOverride)
|
|
@@ -374,6 +405,8 @@ async function executeSandboxCode(options) {
|
|
|
374
405
|
const env = {
|
|
375
406
|
INTEGRATE_MCP_URL: options.mcpUrl
|
|
376
407
|
};
|
|
408
|
+
if (options.apiKey)
|
|
409
|
+
env.INTEGRATE_API_KEY = options.apiKey;
|
|
377
410
|
if (options.sessionToken)
|
|
378
411
|
env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
|
|
379
412
|
if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
|
|
@@ -465,6 +498,34 @@ function resolveCodeModeClientConfig(client) {
|
|
|
465
498
|
const oauthConfig = client.__oauthConfig;
|
|
466
499
|
return oauthConfig?.codeMode ?? {};
|
|
467
500
|
}
|
|
501
|
+
async function diagnoseCodeMode(client) {
|
|
502
|
+
if (!await isSandboxAvailable()) {
|
|
503
|
+
return { available: false, reason: "sandbox-missing" };
|
|
504
|
+
}
|
|
505
|
+
const serverConfig = resolveCodeModeClientConfig(client);
|
|
506
|
+
const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
|
|
507
|
+
if (!publicUrl) {
|
|
508
|
+
return { available: false, reason: "no-public-url" };
|
|
509
|
+
}
|
|
510
|
+
return { available: true };
|
|
511
|
+
}
|
|
512
|
+
async function canUseCodeMode(client) {
|
|
513
|
+
return (await diagnoseCodeMode(client)).available;
|
|
514
|
+
}
|
|
515
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
516
|
+
"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.",
|
|
517
|
+
"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."
|
|
518
|
+
};
|
|
519
|
+
var warnedCodeModeReasons = new Set;
|
|
520
|
+
function __resetCodeModeFallbackWarnings() {
|
|
521
|
+
warnedCodeModeReasons.clear();
|
|
522
|
+
}
|
|
523
|
+
function warnCodeModeFallback(reason) {
|
|
524
|
+
if (warnedCodeModeReasons.has(reason))
|
|
525
|
+
return;
|
|
526
|
+
warnedCodeModeReasons.add(reason);
|
|
527
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
528
|
+
}
|
|
468
529
|
function buildCodeModeTool(client, options) {
|
|
469
530
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
470
531
|
const generated = generateCodeModeTypes(tools);
|
|
@@ -477,6 +538,7 @@ ${generated.source}
|
|
|
477
538
|
\`\`\``;
|
|
478
539
|
const execute = async ({ code }) => {
|
|
479
540
|
const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
|
|
541
|
+
const apiKey = client.__oauthConfig?.apiKey;
|
|
480
542
|
if (!publicUrl) {
|
|
481
543
|
return {
|
|
482
544
|
success: false,
|
|
@@ -491,6 +553,7 @@ ${generated.source}
|
|
|
491
553
|
return executeSandboxCode({
|
|
492
554
|
code,
|
|
493
555
|
mcpUrl,
|
|
556
|
+
apiKey,
|
|
494
557
|
providerTokens,
|
|
495
558
|
context,
|
|
496
559
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
@@ -520,6 +583,7 @@ ${generated.source}
|
|
|
520
583
|
export {
|
|
521
584
|
generateCodeModeTypes,
|
|
522
585
|
executeSandboxCode,
|
|
586
|
+
canUseCodeMode,
|
|
523
587
|
buildCodeModeTool,
|
|
524
588
|
__setSandboxFactoryForTests,
|
|
525
589
|
RUNTIME_STUB_SOURCE,
|
|
@@ -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 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 (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 const message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;\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";
|
|
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 const message = (payload && (payload.error || payload.message)) || 'Tool call failed: HTTP ' + res.status;\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,qtEAqE/B,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
|
|
3
3
|
const MCP_URL = process.env.INTEGRATE_MCP_URL;
|
|
4
4
|
const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
|
|
5
|
+
const API_KEY = process.env.INTEGRATE_API_KEY || '';
|
|
5
6
|
const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
|
|
6
7
|
const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
|
|
7
8
|
const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
|
|
@@ -20,6 +21,7 @@ async function callTool(toolName, args) {
|
|
|
20
21
|
'x-integrate-code-mode': '1',
|
|
21
22
|
};
|
|
22
23
|
if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
|
|
24
|
+
if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
|
|
23
25
|
if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
|
|
24
26
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
25
27
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
@@ -74,6 +74,23 @@ 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
|
+
export declare function diagnoseCodeMode(client: MCPClient<any>): Promise<CodeModeDiagnosis>;
|
|
85
|
+
export declare function canUseCodeMode(client: MCPClient<any>): Promise<boolean>;
|
|
86
|
+
/** @internal — used by unit tests to reset the warn-once throttle. */
|
|
87
|
+
export declare function __resetCodeModeFallbackWarnings(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Called by AI helpers when auto-detection picks `tools` mode. Emits a
|
|
90
|
+
* throttled `console.warn` so operators can tell *why* Code Mode was
|
|
91
|
+
* silently downgraded. Each reason warns at most once per process.
|
|
92
|
+
*/
|
|
93
|
+
export declare function warnCodeModeFallback(reason: CodeModeUnavailableReason): void;
|
|
77
94
|
/**
|
|
78
95
|
* Build the `execute_code` tool definition. The returned `execute` function
|
|
79
96
|
* 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,
|
|
1
|
+
{"version":3,"file":"tool-builder.d.ts","sourceRoot":"","sources":["../../../src/code-mode/tool-builder.ts"],"names":[],"mappings":"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"}
|
|
@@ -217,6 +217,7 @@ function pascalCase(id) {
|
|
|
217
217
|
var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
|
|
218
218
|
const MCP_URL = process.env.INTEGRATE_MCP_URL;
|
|
219
219
|
const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
|
|
220
|
+
const API_KEY = process.env.INTEGRATE_API_KEY || '';
|
|
220
221
|
const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
|
|
221
222
|
const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
|
|
222
223
|
const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
|
|
@@ -235,6 +236,7 @@ async function callTool(toolName, args) {
|
|
|
235
236
|
'x-integrate-code-mode': '1',
|
|
236
237
|
};
|
|
237
238
|
if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
|
|
239
|
+
if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
|
|
238
240
|
if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
|
|
239
241
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
240
242
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
@@ -285,8 +287,37 @@ export { callTool };
|
|
|
285
287
|
|
|
286
288
|
// executor.ts
|
|
287
289
|
var sandboxFactoryOverride = null;
|
|
290
|
+
var _sandboxAvailableCache = null;
|
|
291
|
+
var _sandboxForcedUnavailableForTests = false;
|
|
288
292
|
function __setSandboxFactoryForTests(factory) {
|
|
289
293
|
sandboxFactoryOverride = factory;
|
|
294
|
+
_sandboxForcedUnavailableForTests = false;
|
|
295
|
+
_sandboxAvailableCache = null;
|
|
296
|
+
}
|
|
297
|
+
function __setSandboxUnavailableForTests(force) {
|
|
298
|
+
_sandboxForcedUnavailableForTests = force;
|
|
299
|
+
_sandboxAvailableCache = null;
|
|
300
|
+
}
|
|
301
|
+
async function isSandboxAvailable() {
|
|
302
|
+
if (_sandboxAvailableCache !== null)
|
|
303
|
+
return _sandboxAvailableCache;
|
|
304
|
+
if (_sandboxForcedUnavailableForTests) {
|
|
305
|
+
_sandboxAvailableCache = false;
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
if (sandboxFactoryOverride) {
|
|
309
|
+
_sandboxAvailableCache = true;
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
314
|
+
await dynamicImport("@" + "vercel/sandbox");
|
|
315
|
+
_sandboxAvailableCache = true;
|
|
316
|
+
return true;
|
|
317
|
+
} catch {
|
|
318
|
+
_sandboxAvailableCache = false;
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
290
321
|
}
|
|
291
322
|
async function loadSandboxFactory() {
|
|
292
323
|
if (sandboxFactoryOverride)
|
|
@@ -374,6 +405,8 @@ async function executeSandboxCode(options) {
|
|
|
374
405
|
const env = {
|
|
375
406
|
INTEGRATE_MCP_URL: options.mcpUrl
|
|
376
407
|
};
|
|
408
|
+
if (options.apiKey)
|
|
409
|
+
env.INTEGRATE_API_KEY = options.apiKey;
|
|
377
410
|
if (options.sessionToken)
|
|
378
411
|
env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
|
|
379
412
|
if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
|
|
@@ -465,6 +498,34 @@ function resolveCodeModeClientConfig(client) {
|
|
|
465
498
|
const oauthConfig = client.__oauthConfig;
|
|
466
499
|
return oauthConfig?.codeMode ?? {};
|
|
467
500
|
}
|
|
501
|
+
async function diagnoseCodeMode(client) {
|
|
502
|
+
if (!await isSandboxAvailable()) {
|
|
503
|
+
return { available: false, reason: "sandbox-missing" };
|
|
504
|
+
}
|
|
505
|
+
const serverConfig = resolveCodeModeClientConfig(client);
|
|
506
|
+
const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
|
|
507
|
+
if (!publicUrl) {
|
|
508
|
+
return { available: false, reason: "no-public-url" };
|
|
509
|
+
}
|
|
510
|
+
return { available: true };
|
|
511
|
+
}
|
|
512
|
+
async function canUseCodeMode(client) {
|
|
513
|
+
return (await diagnoseCodeMode(client)).available;
|
|
514
|
+
}
|
|
515
|
+
var CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
516
|
+
"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.",
|
|
517
|
+
"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."
|
|
518
|
+
};
|
|
519
|
+
var warnedCodeModeReasons = new Set;
|
|
520
|
+
function __resetCodeModeFallbackWarnings() {
|
|
521
|
+
warnedCodeModeReasons.clear();
|
|
522
|
+
}
|
|
523
|
+
function warnCodeModeFallback(reason) {
|
|
524
|
+
if (warnedCodeModeReasons.has(reason))
|
|
525
|
+
return;
|
|
526
|
+
warnedCodeModeReasons.add(reason);
|
|
527
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
528
|
+
}
|
|
468
529
|
function buildCodeModeTool(client, options) {
|
|
469
530
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
470
531
|
const generated = generateCodeModeTypes(tools);
|
|
@@ -477,6 +538,7 @@ ${generated.source}
|
|
|
477
538
|
\`\`\``;
|
|
478
539
|
const execute = async ({ code }) => {
|
|
479
540
|
const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
|
|
541
|
+
const apiKey = client.__oauthConfig?.apiKey;
|
|
480
542
|
if (!publicUrl) {
|
|
481
543
|
return {
|
|
482
544
|
success: false,
|
|
@@ -491,6 +553,7 @@ ${generated.source}
|
|
|
491
553
|
return executeSandboxCode({
|
|
492
554
|
code,
|
|
493
555
|
mcpUrl,
|
|
556
|
+
apiKey,
|
|
494
557
|
providerTokens,
|
|
495
558
|
context,
|
|
496
559
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
@@ -518,7 +581,11 @@ ${generated.source}
|
|
|
518
581
|
};
|
|
519
582
|
}
|
|
520
583
|
export {
|
|
584
|
+
warnCodeModeFallback,
|
|
521
585
|
resolveCodeModeClientConfig,
|
|
586
|
+
diagnoseCodeMode,
|
|
587
|
+
canUseCodeMode,
|
|
522
588
|
buildCodeModeTool,
|
|
589
|
+
__resetCodeModeFallbackWarnings,
|
|
523
590
|
CODE_MODE_TOOL_NAME
|
|
524
591
|
};
|
package/dist/index.js
CHANGED
|
@@ -8943,6 +8943,7 @@ var init_type_generator = __esm(() => {
|
|
|
8943
8943
|
var RUNTIME_STUB_SOURCE = `// runtime.mjs — generated by integrate-sdk code mode
|
|
8944
8944
|
const MCP_URL = process.env.INTEGRATE_MCP_URL;
|
|
8945
8945
|
const SESSION_TOKEN = process.env.INTEGRATE_SESSION_TOKEN;
|
|
8946
|
+
const API_KEY = process.env.INTEGRATE_API_KEY || '';
|
|
8946
8947
|
const PROVIDER_TOKENS = process.env.INTEGRATE_PROVIDER_TOKENS || '';
|
|
8947
8948
|
const INTEGRATIONS_HEADER = process.env.INTEGRATE_INTEGRATIONS || '';
|
|
8948
8949
|
const CONTEXT_JSON = process.env.INTEGRATE_CONTEXT || '';
|
|
@@ -8961,6 +8962,7 @@ async function callTool(toolName, args) {
|
|
|
8961
8962
|
'x-integrate-code-mode': '1',
|
|
8962
8963
|
};
|
|
8963
8964
|
if (SESSION_TOKEN) headers['Authorization'] = 'Bearer ' + SESSION_TOKEN;
|
|
8965
|
+
if (API_KEY) headers['x-integrate-api-key'] = API_KEY;
|
|
8964
8966
|
if (PROVIDER_TOKENS) headers['x-integrate-tokens'] = PROVIDER_TOKENS;
|
|
8965
8967
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
8966
8968
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
@@ -9012,11 +9014,40 @@ export { callTool };
|
|
|
9012
9014
|
// src/code-mode/executor.ts
|
|
9013
9015
|
var exports_executor = {};
|
|
9014
9016
|
__export(exports_executor, {
|
|
9017
|
+
isSandboxAvailable: () => isSandboxAvailable,
|
|
9015
9018
|
executeSandboxCode: () => executeSandboxCode,
|
|
9019
|
+
__setSandboxUnavailableForTests: () => __setSandboxUnavailableForTests,
|
|
9016
9020
|
__setSandboxFactoryForTests: () => __setSandboxFactoryForTests
|
|
9017
9021
|
});
|
|
9018
9022
|
function __setSandboxFactoryForTests(factory) {
|
|
9019
9023
|
sandboxFactoryOverride = factory;
|
|
9024
|
+
_sandboxForcedUnavailableForTests = false;
|
|
9025
|
+
_sandboxAvailableCache = null;
|
|
9026
|
+
}
|
|
9027
|
+
function __setSandboxUnavailableForTests(force) {
|
|
9028
|
+
_sandboxForcedUnavailableForTests = force;
|
|
9029
|
+
_sandboxAvailableCache = null;
|
|
9030
|
+
}
|
|
9031
|
+
async function isSandboxAvailable() {
|
|
9032
|
+
if (_sandboxAvailableCache !== null)
|
|
9033
|
+
return _sandboxAvailableCache;
|
|
9034
|
+
if (_sandboxForcedUnavailableForTests) {
|
|
9035
|
+
_sandboxAvailableCache = false;
|
|
9036
|
+
return false;
|
|
9037
|
+
}
|
|
9038
|
+
if (sandboxFactoryOverride) {
|
|
9039
|
+
_sandboxAvailableCache = true;
|
|
9040
|
+
return true;
|
|
9041
|
+
}
|
|
9042
|
+
try {
|
|
9043
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
9044
|
+
await dynamicImport("@" + "vercel/sandbox");
|
|
9045
|
+
_sandboxAvailableCache = true;
|
|
9046
|
+
return true;
|
|
9047
|
+
} catch {
|
|
9048
|
+
_sandboxAvailableCache = false;
|
|
9049
|
+
return false;
|
|
9050
|
+
}
|
|
9020
9051
|
}
|
|
9021
9052
|
async function loadSandboxFactory() {
|
|
9022
9053
|
if (sandboxFactoryOverride)
|
|
@@ -9103,6 +9134,8 @@ async function executeSandboxCode(options) {
|
|
|
9103
9134
|
const env = {
|
|
9104
9135
|
INTEGRATE_MCP_URL: options.mcpUrl
|
|
9105
9136
|
};
|
|
9137
|
+
if (options.apiKey)
|
|
9138
|
+
env.INTEGRATE_API_KEY = options.apiKey;
|
|
9106
9139
|
if (options.sessionToken)
|
|
9107
9140
|
env.INTEGRATE_SESSION_TOKEN = options.sessionToken;
|
|
9108
9141
|
if (options.providerTokens && Object.keys(options.providerTokens).length > 0) {
|
|
@@ -9145,7 +9178,7 @@ async function executeSandboxCode(options) {
|
|
|
9145
9178
|
}
|
|
9146
9179
|
}
|
|
9147
9180
|
}
|
|
9148
|
-
var sandboxFactoryOverride = null, RESULT_SENTINEL = "__INTEGRATE_RESULT__";
|
|
9181
|
+
var sandboxFactoryOverride = null, _sandboxAvailableCache = null, _sandboxForcedUnavailableForTests = false, RESULT_SENTINEL = "__INTEGRATE_RESULT__";
|
|
9149
9182
|
var init_executor = () => {};
|
|
9150
9183
|
|
|
9151
9184
|
// src/code-mode/tool-builder.ts
|
|
@@ -9153,6 +9186,23 @@ function resolveCodeModeClientConfig(client) {
|
|
|
9153
9186
|
const oauthConfig = client.__oauthConfig;
|
|
9154
9187
|
return oauthConfig?.codeMode ?? {};
|
|
9155
9188
|
}
|
|
9189
|
+
async function diagnoseCodeMode(client) {
|
|
9190
|
+
if (!await isSandboxAvailable()) {
|
|
9191
|
+
return { available: false, reason: "sandbox-missing" };
|
|
9192
|
+
}
|
|
9193
|
+
const serverConfig = resolveCodeModeClientConfig(client);
|
|
9194
|
+
const publicUrl = serverConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
|
|
9195
|
+
if (!publicUrl) {
|
|
9196
|
+
return { available: false, reason: "no-public-url" };
|
|
9197
|
+
}
|
|
9198
|
+
return { available: true };
|
|
9199
|
+
}
|
|
9200
|
+
function warnCodeModeFallback(reason) {
|
|
9201
|
+
if (warnedCodeModeReasons.has(reason))
|
|
9202
|
+
return;
|
|
9203
|
+
warnedCodeModeReasons.add(reason);
|
|
9204
|
+
console.warn(CODE_MODE_UNAVAILABLE_MESSAGES[reason]);
|
|
9205
|
+
}
|
|
9156
9206
|
function buildCodeModeTool(client, options) {
|
|
9157
9207
|
const { tools, providerTokens, context, integrationIds } = options;
|
|
9158
9208
|
const generated = generateCodeModeTypes(tools);
|
|
@@ -9165,6 +9215,7 @@ ${generated.source}
|
|
|
9165
9215
|
\`\`\``;
|
|
9166
9216
|
const execute = async ({ code }) => {
|
|
9167
9217
|
const publicUrl = sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl ?? getEnv("INTEGRATE_PUBLIC_URL");
|
|
9218
|
+
const apiKey = client.__oauthConfig?.apiKey;
|
|
9168
9219
|
if (!publicUrl) {
|
|
9169
9220
|
return {
|
|
9170
9221
|
success: false,
|
|
@@ -9179,6 +9230,7 @@ ${generated.source}
|
|
|
9179
9230
|
return executeSandboxCode({
|
|
9180
9231
|
code,
|
|
9181
9232
|
mcpUrl,
|
|
9233
|
+
apiKey,
|
|
9182
9234
|
providerTokens,
|
|
9183
9235
|
context,
|
|
9184
9236
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
@@ -9205,7 +9257,7 @@ ${generated.source}
|
|
|
9205
9257
|
execute
|
|
9206
9258
|
};
|
|
9207
9259
|
}
|
|
9208
|
-
var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS;
|
|
9260
|
+
var CODE_MODE_TOOL_NAME = "execute_code", DEFAULT_INSTRUCTIONS, CODE_MODE_UNAVAILABLE_MESSAGES, warnedCodeModeReasons;
|
|
9209
9261
|
var init_tool_builder = __esm(() => {
|
|
9210
9262
|
init_type_generator();
|
|
9211
9263
|
init_executor();
|
|
@@ -9230,6 +9282,11 @@ var init_tool_builder = __esm(() => {
|
|
|
9230
9282
|
"API surface:"
|
|
9231
9283
|
].join(`
|
|
9232
9284
|
`);
|
|
9285
|
+
CODE_MODE_UNAVAILABLE_MESSAGES = {
|
|
9286
|
+
"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.",
|
|
9287
|
+
"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."
|
|
9288
|
+
};
|
|
9289
|
+
warnedCodeModeReasons = new Set;
|
|
9233
9290
|
});
|
|
9234
9291
|
|
|
9235
9292
|
// src/ai/vercel-ai.ts
|
|
@@ -9256,8 +9313,19 @@ async function getVercelAITools(client, options) {
|
|
|
9256
9313
|
await ensureClientConnected(client);
|
|
9257
9314
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
9258
9315
|
const vercelTools = {};
|
|
9259
|
-
|
|
9260
|
-
if (mode
|
|
9316
|
+
let effectiveMode;
|
|
9317
|
+
if (options?.mode !== undefined) {
|
|
9318
|
+
effectiveMode = options.mode;
|
|
9319
|
+
} else {
|
|
9320
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
9321
|
+
if (diagnosis.available) {
|
|
9322
|
+
effectiveMode = "code";
|
|
9323
|
+
} else {
|
|
9324
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
9325
|
+
effectiveMode = "tools";
|
|
9326
|
+
}
|
|
9327
|
+
}
|
|
9328
|
+
if (effectiveMode === "code") {
|
|
9261
9329
|
const codeTool = buildCodeModeTool(client, {
|
|
9262
9330
|
tools: mcpTools,
|
|
9263
9331
|
providerTokens,
|
|
@@ -10715,8 +10783,19 @@ async function getOpenAITools(client, options) {
|
|
|
10715
10783
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
10716
10784
|
await ensureClientConnected(client);
|
|
10717
10785
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
10718
|
-
|
|
10719
|
-
|
|
10786
|
+
let effectiveMode;
|
|
10787
|
+
if (options?.mode !== undefined) {
|
|
10788
|
+
effectiveMode = options.mode;
|
|
10789
|
+
} else {
|
|
10790
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
10791
|
+
if (diagnosis.available) {
|
|
10792
|
+
effectiveMode = "code";
|
|
10793
|
+
} else {
|
|
10794
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
10795
|
+
effectiveMode = "tools";
|
|
10796
|
+
}
|
|
10797
|
+
}
|
|
10798
|
+
const openaiTools = effectiveMode === "code" ? (() => {
|
|
10720
10799
|
const codeTool = buildCodeModeTool(client, {
|
|
10721
10800
|
tools: mcpTools,
|
|
10722
10801
|
providerTokens,
|
|
@@ -10895,8 +10974,19 @@ async function getAnthropicTools(client, options) {
|
|
|
10895
10974
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
10896
10975
|
await ensureClientConnected(client);
|
|
10897
10976
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
10898
|
-
|
|
10899
|
-
|
|
10977
|
+
let effectiveMode;
|
|
10978
|
+
if (options?.mode !== undefined) {
|
|
10979
|
+
effectiveMode = options.mode;
|
|
10980
|
+
} else {
|
|
10981
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
10982
|
+
if (diagnosis.available) {
|
|
10983
|
+
effectiveMode = "code";
|
|
10984
|
+
} else {
|
|
10985
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
10986
|
+
effectiveMode = "tools";
|
|
10987
|
+
}
|
|
10988
|
+
}
|
|
10989
|
+
const anthropicTools = effectiveMode === "code" ? (() => {
|
|
10900
10990
|
const codeTool = buildCodeModeTool(client, {
|
|
10901
10991
|
tools: mcpTools,
|
|
10902
10992
|
providerTokens,
|
|
@@ -11084,9 +11174,20 @@ async function getGoogleTools(client, options) {
|
|
|
11084
11174
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
11085
11175
|
await ensureClientConnected(client);
|
|
11086
11176
|
const mcpTools = await client.getEnabledToolsAsync();
|
|
11087
|
-
|
|
11177
|
+
let effectiveMode;
|
|
11178
|
+
if (options?.mode !== undefined) {
|
|
11179
|
+
effectiveMode = options.mode;
|
|
11180
|
+
} else {
|
|
11181
|
+
const diagnosis = await diagnoseCodeMode(client);
|
|
11182
|
+
if (diagnosis.available) {
|
|
11183
|
+
effectiveMode = "code";
|
|
11184
|
+
} else {
|
|
11185
|
+
warnCodeModeFallback(diagnosis.reason);
|
|
11186
|
+
effectiveMode = "tools";
|
|
11187
|
+
}
|
|
11188
|
+
}
|
|
11088
11189
|
let googleTools;
|
|
11089
|
-
if (
|
|
11190
|
+
if (effectiveMode === "code") {
|
|
11090
11191
|
const TypeEnum = await getGoogleType();
|
|
11091
11192
|
const codeTool = buildCodeModeTool(client, {
|
|
11092
11193
|
tools: mcpTools,
|
|
@@ -11633,6 +11734,24 @@ function createMCPServer(config) {
|
|
|
11633
11734
|
} catch {}
|
|
11634
11735
|
}
|
|
11635
11736
|
}
|
|
11737
|
+
if (!authHeader && config.getProviderToken) {
|
|
11738
|
+
const codeModeHeader = webRequest.headers.get("x-integrate-code-mode");
|
|
11739
|
+
const contextHeader = webRequest.headers.get("x-integrate-context");
|
|
11740
|
+
const callbackApiKey = webRequest.headers.get("x-integrate-api-key");
|
|
11741
|
+
const toolName = typeof body?.name === "string" ? body.name : "";
|
|
11742
|
+
if (codeModeHeader === "1" && contextHeader && toolName && config.apiKey && callbackApiKey === config.apiKey) {
|
|
11743
|
+
try {
|
|
11744
|
+
const context2 = JSON.parse(contextHeader);
|
|
11745
|
+
const provider = toolName.split("_")[0];
|
|
11746
|
+
if (provider) {
|
|
11747
|
+
const tokenData = await config.getProviderToken(provider, undefined, context2);
|
|
11748
|
+
if (tokenData?.accessToken) {
|
|
11749
|
+
authHeader = `Bearer ${tokenData.accessToken}`;
|
|
11750
|
+
}
|
|
11751
|
+
}
|
|
11752
|
+
} catch {}
|
|
11753
|
+
}
|
|
11754
|
+
}
|
|
11636
11755
|
const { OAuthHandler: OAuthHandler2 } = await Promise.resolve().then(() => (init_base_handler(), exports_base_handler));
|
|
11637
11756
|
const oauthHandler = new OAuthHandler2({
|
|
11638
11757
|
providers,
|