integrate-sdk 0.9.18-dev.0 → 0.9.20-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/ai/anthropic.js +73 -1
- package/dist/ai/google.js +73 -1
- package/dist/ai/index.js +73 -1
- package/dist/ai/openai.js +73 -1
- package/dist/ai/vercel-ai.js +73 -1
- package/dist/code-mode/executor.d.ts.map +1 -1
- package/dist/code-mode/executor.js +33 -0
- package/dist/code-mode/index.js +126 -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 +23 -0
- package/dist/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/code-mode/tool-builder.js +126 -1
- package/dist/server.js +143 -54
- 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/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ai/anthropic.js
CHANGED
|
@@ -4677,6 +4677,19 @@ if (!MCP_URL) {
|
|
|
4677
4677
|
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
4678
4678
|
}
|
|
4679
4679
|
|
|
4680
|
+
// Diagnostic: log sandbox env summary to stderr so it shows up in the
|
|
4681
|
+
// execute_code result's stderr field for debugging auth issues.
|
|
4682
|
+
console.error('[sandbox-diag] MCP_URL=' + MCP_URL);
|
|
4683
|
+
console.error('[sandbox-diag] HAS_API_KEY=' + !!API_KEY);
|
|
4684
|
+
console.error('[sandbox-diag] HAS_SESSION_TOKEN=' + !!SESSION_TOKEN);
|
|
4685
|
+
console.error('[sandbox-diag] HAS_PROVIDER_TOKENS=' + !!PROVIDER_TOKENS);
|
|
4686
|
+
if (PROVIDER_TOKENS) {
|
|
4687
|
+
try {
|
|
4688
|
+
const _keys = Object.keys(JSON.parse(PROVIDER_TOKENS));
|
|
4689
|
+
console.error('[sandbox-diag] PROVIDER_TOKEN_KEYS=' + _keys.join(','));
|
|
4690
|
+
} catch { console.error('[sandbox-diag] PROVIDER_TOKENS is not valid JSON'); }
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4680
4693
|
function camelToSnake(str) {
|
|
4681
4694
|
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
4682
4695
|
}
|
|
@@ -4692,6 +4705,14 @@ async function callTool(toolName, args) {
|
|
|
4692
4705
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
4693
4706
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
4694
4707
|
|
|
4708
|
+
console.error('[sandbox-diag] callTool: ' + toolName + ' → ' + MCP_URL);
|
|
4709
|
+
console.error('[sandbox-diag] headers: ' + JSON.stringify({
|
|
4710
|
+
hasAuth: !!headers['Authorization'],
|
|
4711
|
+
hasApiKey: !!headers['x-integrate-api-key'],
|
|
4712
|
+
hasTokens: !!headers['x-integrate-tokens'],
|
|
4713
|
+
hasCodeMode: !!headers['x-integrate-code-mode'],
|
|
4714
|
+
}));
|
|
4715
|
+
|
|
4695
4716
|
const res = await fetch(MCP_URL, {
|
|
4696
4717
|
method: 'POST',
|
|
4697
4718
|
headers,
|
|
@@ -4699,6 +4720,8 @@ async function callTool(toolName, args) {
|
|
|
4699
4720
|
});
|
|
4700
4721
|
|
|
4701
4722
|
const text = await res.text();
|
|
4723
|
+
console.error('[sandbox-diag] response: HTTP ' + res.status + ' len=' + text.length);
|
|
4724
|
+
|
|
4702
4725
|
let payload;
|
|
4703
4726
|
try {
|
|
4704
4727
|
payload = text ? JSON.parse(text) : null;
|
|
@@ -4876,6 +4899,16 @@ async function executeSandboxCode(options) {
|
|
|
4876
4899
|
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
4877
4900
|
if (options.context)
|
|
4878
4901
|
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
4902
|
+
console.debug("[integrate-sdk] Sandbox env:", JSON.stringify({
|
|
4903
|
+
mcpUrl: options.mcpUrl,
|
|
4904
|
+
hasApiKey: !!options.apiKey,
|
|
4905
|
+
hasSessionToken: !!options.sessionToken,
|
|
4906
|
+
providerTokenKeys: options.providerTokens ? Object.keys(options.providerTokens) : [],
|
|
4907
|
+
hasIntegrations: !!options.integrationsHeader,
|
|
4908
|
+
hasContext: !!options.context,
|
|
4909
|
+
runtime,
|
|
4910
|
+
timeoutMs
|
|
4911
|
+
}));
|
|
4879
4912
|
const cmd = await sandbox.runCommand({
|
|
4880
4913
|
cmd: "node",
|
|
4881
4914
|
args: ["user.mjs"],
|
|
@@ -5001,11 +5034,50 @@ ${generated.compact}`;
|
|
|
5001
5034
|
};
|
|
5002
5035
|
}
|
|
5003
5036
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5037
|
+
let resolvedTokens = providerTokens;
|
|
5038
|
+
let tokenSource = resolvedTokens && Object.keys(resolvedTokens).length > 0 ? "build-time" : "none";
|
|
5039
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5040
|
+
try {
|
|
5041
|
+
resolvedTokens = await getProviderTokens();
|
|
5042
|
+
if (resolvedTokens && Object.keys(resolvedTokens).length > 0) {
|
|
5043
|
+
tokenSource = "request-header";
|
|
5044
|
+
}
|
|
5045
|
+
} catch {}
|
|
5046
|
+
}
|
|
5047
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5048
|
+
const oauthManager = client.oauthManager;
|
|
5049
|
+
if (oauthManager) {
|
|
5050
|
+
resolvedTokens = {};
|
|
5051
|
+
const clientIntegrations = client.integrations || [];
|
|
5052
|
+
for (const integration of clientIntegrations) {
|
|
5053
|
+
if (integration.oauth) {
|
|
5054
|
+
const provider = integration.oauth.provider;
|
|
5055
|
+
try {
|
|
5056
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5057
|
+
if (tokenData?.accessToken) {
|
|
5058
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5059
|
+
}
|
|
5060
|
+
} catch {}
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5064
|
+
resolvedTokens = undefined;
|
|
5065
|
+
} else {
|
|
5066
|
+
tokenSource = "oauthManager";
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
console.debug("[integrate-sdk] execute_code token resolution:", JSON.stringify({
|
|
5071
|
+
source: tokenSource,
|
|
5072
|
+
keys: resolvedTokens ? Object.keys(resolvedTokens) : [],
|
|
5073
|
+
hasApiKey: !!apiKey,
|
|
5074
|
+
mcpUrl
|
|
5075
|
+
}));
|
|
5004
5076
|
return executeSandboxCode({
|
|
5005
5077
|
code,
|
|
5006
5078
|
mcpUrl,
|
|
5007
5079
|
apiKey,
|
|
5008
|
-
providerTokens,
|
|
5080
|
+
providerTokens: resolvedTokens,
|
|
5009
5081
|
context,
|
|
5010
5082
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
5011
5083
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
package/dist/ai/google.js
CHANGED
|
@@ -4677,6 +4677,19 @@ if (!MCP_URL) {
|
|
|
4677
4677
|
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
4678
4678
|
}
|
|
4679
4679
|
|
|
4680
|
+
// Diagnostic: log sandbox env summary to stderr so it shows up in the
|
|
4681
|
+
// execute_code result's stderr field for debugging auth issues.
|
|
4682
|
+
console.error('[sandbox-diag] MCP_URL=' + MCP_URL);
|
|
4683
|
+
console.error('[sandbox-diag] HAS_API_KEY=' + !!API_KEY);
|
|
4684
|
+
console.error('[sandbox-diag] HAS_SESSION_TOKEN=' + !!SESSION_TOKEN);
|
|
4685
|
+
console.error('[sandbox-diag] HAS_PROVIDER_TOKENS=' + !!PROVIDER_TOKENS);
|
|
4686
|
+
if (PROVIDER_TOKENS) {
|
|
4687
|
+
try {
|
|
4688
|
+
const _keys = Object.keys(JSON.parse(PROVIDER_TOKENS));
|
|
4689
|
+
console.error('[sandbox-diag] PROVIDER_TOKEN_KEYS=' + _keys.join(','));
|
|
4690
|
+
} catch { console.error('[sandbox-diag] PROVIDER_TOKENS is not valid JSON'); }
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4680
4693
|
function camelToSnake(str) {
|
|
4681
4694
|
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
4682
4695
|
}
|
|
@@ -4692,6 +4705,14 @@ async function callTool(toolName, args) {
|
|
|
4692
4705
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
4693
4706
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
4694
4707
|
|
|
4708
|
+
console.error('[sandbox-diag] callTool: ' + toolName + ' → ' + MCP_URL);
|
|
4709
|
+
console.error('[sandbox-diag] headers: ' + JSON.stringify({
|
|
4710
|
+
hasAuth: !!headers['Authorization'],
|
|
4711
|
+
hasApiKey: !!headers['x-integrate-api-key'],
|
|
4712
|
+
hasTokens: !!headers['x-integrate-tokens'],
|
|
4713
|
+
hasCodeMode: !!headers['x-integrate-code-mode'],
|
|
4714
|
+
}));
|
|
4715
|
+
|
|
4695
4716
|
const res = await fetch(MCP_URL, {
|
|
4696
4717
|
method: 'POST',
|
|
4697
4718
|
headers,
|
|
@@ -4699,6 +4720,8 @@ async function callTool(toolName, args) {
|
|
|
4699
4720
|
});
|
|
4700
4721
|
|
|
4701
4722
|
const text = await res.text();
|
|
4723
|
+
console.error('[sandbox-diag] response: HTTP ' + res.status + ' len=' + text.length);
|
|
4724
|
+
|
|
4702
4725
|
let payload;
|
|
4703
4726
|
try {
|
|
4704
4727
|
payload = text ? JSON.parse(text) : null;
|
|
@@ -4876,6 +4899,16 @@ async function executeSandboxCode(options) {
|
|
|
4876
4899
|
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
4877
4900
|
if (options.context)
|
|
4878
4901
|
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
4902
|
+
console.debug("[integrate-sdk] Sandbox env:", JSON.stringify({
|
|
4903
|
+
mcpUrl: options.mcpUrl,
|
|
4904
|
+
hasApiKey: !!options.apiKey,
|
|
4905
|
+
hasSessionToken: !!options.sessionToken,
|
|
4906
|
+
providerTokenKeys: options.providerTokens ? Object.keys(options.providerTokens) : [],
|
|
4907
|
+
hasIntegrations: !!options.integrationsHeader,
|
|
4908
|
+
hasContext: !!options.context,
|
|
4909
|
+
runtime,
|
|
4910
|
+
timeoutMs
|
|
4911
|
+
}));
|
|
4879
4912
|
const cmd = await sandbox.runCommand({
|
|
4880
4913
|
cmd: "node",
|
|
4881
4914
|
args: ["user.mjs"],
|
|
@@ -5001,11 +5034,50 @@ ${generated.compact}`;
|
|
|
5001
5034
|
};
|
|
5002
5035
|
}
|
|
5003
5036
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5037
|
+
let resolvedTokens = providerTokens;
|
|
5038
|
+
let tokenSource = resolvedTokens && Object.keys(resolvedTokens).length > 0 ? "build-time" : "none";
|
|
5039
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5040
|
+
try {
|
|
5041
|
+
resolvedTokens = await getProviderTokens();
|
|
5042
|
+
if (resolvedTokens && Object.keys(resolvedTokens).length > 0) {
|
|
5043
|
+
tokenSource = "request-header";
|
|
5044
|
+
}
|
|
5045
|
+
} catch {}
|
|
5046
|
+
}
|
|
5047
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5048
|
+
const oauthManager = client.oauthManager;
|
|
5049
|
+
if (oauthManager) {
|
|
5050
|
+
resolvedTokens = {};
|
|
5051
|
+
const clientIntegrations = client.integrations || [];
|
|
5052
|
+
for (const integration of clientIntegrations) {
|
|
5053
|
+
if (integration.oauth) {
|
|
5054
|
+
const provider = integration.oauth.provider;
|
|
5055
|
+
try {
|
|
5056
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5057
|
+
if (tokenData?.accessToken) {
|
|
5058
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5059
|
+
}
|
|
5060
|
+
} catch {}
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5064
|
+
resolvedTokens = undefined;
|
|
5065
|
+
} else {
|
|
5066
|
+
tokenSource = "oauthManager";
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
console.debug("[integrate-sdk] execute_code token resolution:", JSON.stringify({
|
|
5071
|
+
source: tokenSource,
|
|
5072
|
+
keys: resolvedTokens ? Object.keys(resolvedTokens) : [],
|
|
5073
|
+
hasApiKey: !!apiKey,
|
|
5074
|
+
mcpUrl
|
|
5075
|
+
}));
|
|
5004
5076
|
return executeSandboxCode({
|
|
5005
5077
|
code,
|
|
5006
5078
|
mcpUrl,
|
|
5007
5079
|
apiKey,
|
|
5008
|
-
providerTokens,
|
|
5080
|
+
providerTokens: resolvedTokens,
|
|
5009
5081
|
context,
|
|
5010
5082
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
5011
5083
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
package/dist/ai/index.js
CHANGED
|
@@ -4677,6 +4677,19 @@ if (!MCP_URL) {
|
|
|
4677
4677
|
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
4678
4678
|
}
|
|
4679
4679
|
|
|
4680
|
+
// Diagnostic: log sandbox env summary to stderr so it shows up in the
|
|
4681
|
+
// execute_code result's stderr field for debugging auth issues.
|
|
4682
|
+
console.error('[sandbox-diag] MCP_URL=' + MCP_URL);
|
|
4683
|
+
console.error('[sandbox-diag] HAS_API_KEY=' + !!API_KEY);
|
|
4684
|
+
console.error('[sandbox-diag] HAS_SESSION_TOKEN=' + !!SESSION_TOKEN);
|
|
4685
|
+
console.error('[sandbox-diag] HAS_PROVIDER_TOKENS=' + !!PROVIDER_TOKENS);
|
|
4686
|
+
if (PROVIDER_TOKENS) {
|
|
4687
|
+
try {
|
|
4688
|
+
const _keys = Object.keys(JSON.parse(PROVIDER_TOKENS));
|
|
4689
|
+
console.error('[sandbox-diag] PROVIDER_TOKEN_KEYS=' + _keys.join(','));
|
|
4690
|
+
} catch { console.error('[sandbox-diag] PROVIDER_TOKENS is not valid JSON'); }
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4680
4693
|
function camelToSnake(str) {
|
|
4681
4694
|
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
4682
4695
|
}
|
|
@@ -4692,6 +4705,14 @@ async function callTool(toolName, args) {
|
|
|
4692
4705
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
4693
4706
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
4694
4707
|
|
|
4708
|
+
console.error('[sandbox-diag] callTool: ' + toolName + ' → ' + MCP_URL);
|
|
4709
|
+
console.error('[sandbox-diag] headers: ' + JSON.stringify({
|
|
4710
|
+
hasAuth: !!headers['Authorization'],
|
|
4711
|
+
hasApiKey: !!headers['x-integrate-api-key'],
|
|
4712
|
+
hasTokens: !!headers['x-integrate-tokens'],
|
|
4713
|
+
hasCodeMode: !!headers['x-integrate-code-mode'],
|
|
4714
|
+
}));
|
|
4715
|
+
|
|
4695
4716
|
const res = await fetch(MCP_URL, {
|
|
4696
4717
|
method: 'POST',
|
|
4697
4718
|
headers,
|
|
@@ -4699,6 +4720,8 @@ async function callTool(toolName, args) {
|
|
|
4699
4720
|
});
|
|
4700
4721
|
|
|
4701
4722
|
const text = await res.text();
|
|
4723
|
+
console.error('[sandbox-diag] response: HTTP ' + res.status + ' len=' + text.length);
|
|
4724
|
+
|
|
4702
4725
|
let payload;
|
|
4703
4726
|
try {
|
|
4704
4727
|
payload = text ? JSON.parse(text) : null;
|
|
@@ -4876,6 +4899,16 @@ async function executeSandboxCode(options) {
|
|
|
4876
4899
|
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
4877
4900
|
if (options.context)
|
|
4878
4901
|
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
4902
|
+
console.debug("[integrate-sdk] Sandbox env:", JSON.stringify({
|
|
4903
|
+
mcpUrl: options.mcpUrl,
|
|
4904
|
+
hasApiKey: !!options.apiKey,
|
|
4905
|
+
hasSessionToken: !!options.sessionToken,
|
|
4906
|
+
providerTokenKeys: options.providerTokens ? Object.keys(options.providerTokens) : [],
|
|
4907
|
+
hasIntegrations: !!options.integrationsHeader,
|
|
4908
|
+
hasContext: !!options.context,
|
|
4909
|
+
runtime,
|
|
4910
|
+
timeoutMs
|
|
4911
|
+
}));
|
|
4879
4912
|
const cmd = await sandbox.runCommand({
|
|
4880
4913
|
cmd: "node",
|
|
4881
4914
|
args: ["user.mjs"],
|
|
@@ -5001,11 +5034,50 @@ ${generated.compact}`;
|
|
|
5001
5034
|
};
|
|
5002
5035
|
}
|
|
5003
5036
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5037
|
+
let resolvedTokens = providerTokens;
|
|
5038
|
+
let tokenSource = resolvedTokens && Object.keys(resolvedTokens).length > 0 ? "build-time" : "none";
|
|
5039
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5040
|
+
try {
|
|
5041
|
+
resolvedTokens = await getProviderTokens();
|
|
5042
|
+
if (resolvedTokens && Object.keys(resolvedTokens).length > 0) {
|
|
5043
|
+
tokenSource = "request-header";
|
|
5044
|
+
}
|
|
5045
|
+
} catch {}
|
|
5046
|
+
}
|
|
5047
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5048
|
+
const oauthManager = client.oauthManager;
|
|
5049
|
+
if (oauthManager) {
|
|
5050
|
+
resolvedTokens = {};
|
|
5051
|
+
const clientIntegrations = client.integrations || [];
|
|
5052
|
+
for (const integration of clientIntegrations) {
|
|
5053
|
+
if (integration.oauth) {
|
|
5054
|
+
const provider = integration.oauth.provider;
|
|
5055
|
+
try {
|
|
5056
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5057
|
+
if (tokenData?.accessToken) {
|
|
5058
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5059
|
+
}
|
|
5060
|
+
} catch {}
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5064
|
+
resolvedTokens = undefined;
|
|
5065
|
+
} else {
|
|
5066
|
+
tokenSource = "oauthManager";
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
console.debug("[integrate-sdk] execute_code token resolution:", JSON.stringify({
|
|
5071
|
+
source: tokenSource,
|
|
5072
|
+
keys: resolvedTokens ? Object.keys(resolvedTokens) : [],
|
|
5073
|
+
hasApiKey: !!apiKey,
|
|
5074
|
+
mcpUrl
|
|
5075
|
+
}));
|
|
5004
5076
|
return executeSandboxCode({
|
|
5005
5077
|
code,
|
|
5006
5078
|
mcpUrl,
|
|
5007
5079
|
apiKey,
|
|
5008
|
-
providerTokens,
|
|
5080
|
+
providerTokens: resolvedTokens,
|
|
5009
5081
|
context,
|
|
5010
5082
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
5011
5083
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
package/dist/ai/openai.js
CHANGED
|
@@ -4677,6 +4677,19 @@ if (!MCP_URL) {
|
|
|
4677
4677
|
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
4678
4678
|
}
|
|
4679
4679
|
|
|
4680
|
+
// Diagnostic: log sandbox env summary to stderr so it shows up in the
|
|
4681
|
+
// execute_code result's stderr field for debugging auth issues.
|
|
4682
|
+
console.error('[sandbox-diag] MCP_URL=' + MCP_URL);
|
|
4683
|
+
console.error('[sandbox-diag] HAS_API_KEY=' + !!API_KEY);
|
|
4684
|
+
console.error('[sandbox-diag] HAS_SESSION_TOKEN=' + !!SESSION_TOKEN);
|
|
4685
|
+
console.error('[sandbox-diag] HAS_PROVIDER_TOKENS=' + !!PROVIDER_TOKENS);
|
|
4686
|
+
if (PROVIDER_TOKENS) {
|
|
4687
|
+
try {
|
|
4688
|
+
const _keys = Object.keys(JSON.parse(PROVIDER_TOKENS));
|
|
4689
|
+
console.error('[sandbox-diag] PROVIDER_TOKEN_KEYS=' + _keys.join(','));
|
|
4690
|
+
} catch { console.error('[sandbox-diag] PROVIDER_TOKENS is not valid JSON'); }
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4680
4693
|
function camelToSnake(str) {
|
|
4681
4694
|
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
4682
4695
|
}
|
|
@@ -4692,6 +4705,14 @@ async function callTool(toolName, args) {
|
|
|
4692
4705
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
4693
4706
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
4694
4707
|
|
|
4708
|
+
console.error('[sandbox-diag] callTool: ' + toolName + ' → ' + MCP_URL);
|
|
4709
|
+
console.error('[sandbox-diag] headers: ' + JSON.stringify({
|
|
4710
|
+
hasAuth: !!headers['Authorization'],
|
|
4711
|
+
hasApiKey: !!headers['x-integrate-api-key'],
|
|
4712
|
+
hasTokens: !!headers['x-integrate-tokens'],
|
|
4713
|
+
hasCodeMode: !!headers['x-integrate-code-mode'],
|
|
4714
|
+
}));
|
|
4715
|
+
|
|
4695
4716
|
const res = await fetch(MCP_URL, {
|
|
4696
4717
|
method: 'POST',
|
|
4697
4718
|
headers,
|
|
@@ -4699,6 +4720,8 @@ async function callTool(toolName, args) {
|
|
|
4699
4720
|
});
|
|
4700
4721
|
|
|
4701
4722
|
const text = await res.text();
|
|
4723
|
+
console.error('[sandbox-diag] response: HTTP ' + res.status + ' len=' + text.length);
|
|
4724
|
+
|
|
4702
4725
|
let payload;
|
|
4703
4726
|
try {
|
|
4704
4727
|
payload = text ? JSON.parse(text) : null;
|
|
@@ -4876,6 +4899,16 @@ async function executeSandboxCode(options) {
|
|
|
4876
4899
|
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
4877
4900
|
if (options.context)
|
|
4878
4901
|
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
4902
|
+
console.debug("[integrate-sdk] Sandbox env:", JSON.stringify({
|
|
4903
|
+
mcpUrl: options.mcpUrl,
|
|
4904
|
+
hasApiKey: !!options.apiKey,
|
|
4905
|
+
hasSessionToken: !!options.sessionToken,
|
|
4906
|
+
providerTokenKeys: options.providerTokens ? Object.keys(options.providerTokens) : [],
|
|
4907
|
+
hasIntegrations: !!options.integrationsHeader,
|
|
4908
|
+
hasContext: !!options.context,
|
|
4909
|
+
runtime,
|
|
4910
|
+
timeoutMs
|
|
4911
|
+
}));
|
|
4879
4912
|
const cmd = await sandbox.runCommand({
|
|
4880
4913
|
cmd: "node",
|
|
4881
4914
|
args: ["user.mjs"],
|
|
@@ -5001,11 +5034,50 @@ ${generated.compact}`;
|
|
|
5001
5034
|
};
|
|
5002
5035
|
}
|
|
5003
5036
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5037
|
+
let resolvedTokens = providerTokens;
|
|
5038
|
+
let tokenSource = resolvedTokens && Object.keys(resolvedTokens).length > 0 ? "build-time" : "none";
|
|
5039
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5040
|
+
try {
|
|
5041
|
+
resolvedTokens = await getProviderTokens();
|
|
5042
|
+
if (resolvedTokens && Object.keys(resolvedTokens).length > 0) {
|
|
5043
|
+
tokenSource = "request-header";
|
|
5044
|
+
}
|
|
5045
|
+
} catch {}
|
|
5046
|
+
}
|
|
5047
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5048
|
+
const oauthManager = client.oauthManager;
|
|
5049
|
+
if (oauthManager) {
|
|
5050
|
+
resolvedTokens = {};
|
|
5051
|
+
const clientIntegrations = client.integrations || [];
|
|
5052
|
+
for (const integration of clientIntegrations) {
|
|
5053
|
+
if (integration.oauth) {
|
|
5054
|
+
const provider = integration.oauth.provider;
|
|
5055
|
+
try {
|
|
5056
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5057
|
+
if (tokenData?.accessToken) {
|
|
5058
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5059
|
+
}
|
|
5060
|
+
} catch {}
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5064
|
+
resolvedTokens = undefined;
|
|
5065
|
+
} else {
|
|
5066
|
+
tokenSource = "oauthManager";
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
console.debug("[integrate-sdk] execute_code token resolution:", JSON.stringify({
|
|
5071
|
+
source: tokenSource,
|
|
5072
|
+
keys: resolvedTokens ? Object.keys(resolvedTokens) : [],
|
|
5073
|
+
hasApiKey: !!apiKey,
|
|
5074
|
+
mcpUrl
|
|
5075
|
+
}));
|
|
5004
5076
|
return executeSandboxCode({
|
|
5005
5077
|
code,
|
|
5006
5078
|
mcpUrl,
|
|
5007
5079
|
apiKey,
|
|
5008
|
-
providerTokens,
|
|
5080
|
+
providerTokens: resolvedTokens,
|
|
5009
5081
|
context,
|
|
5010
5082
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
5011
5083
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
package/dist/ai/vercel-ai.js
CHANGED
|
@@ -4677,6 +4677,19 @@ if (!MCP_URL) {
|
|
|
4677
4677
|
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
4678
4678
|
}
|
|
4679
4679
|
|
|
4680
|
+
// Diagnostic: log sandbox env summary to stderr so it shows up in the
|
|
4681
|
+
// execute_code result's stderr field for debugging auth issues.
|
|
4682
|
+
console.error('[sandbox-diag] MCP_URL=' + MCP_URL);
|
|
4683
|
+
console.error('[sandbox-diag] HAS_API_KEY=' + !!API_KEY);
|
|
4684
|
+
console.error('[sandbox-diag] HAS_SESSION_TOKEN=' + !!SESSION_TOKEN);
|
|
4685
|
+
console.error('[sandbox-diag] HAS_PROVIDER_TOKENS=' + !!PROVIDER_TOKENS);
|
|
4686
|
+
if (PROVIDER_TOKENS) {
|
|
4687
|
+
try {
|
|
4688
|
+
const _keys = Object.keys(JSON.parse(PROVIDER_TOKENS));
|
|
4689
|
+
console.error('[sandbox-diag] PROVIDER_TOKEN_KEYS=' + _keys.join(','));
|
|
4690
|
+
} catch { console.error('[sandbox-diag] PROVIDER_TOKENS is not valid JSON'); }
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4680
4693
|
function camelToSnake(str) {
|
|
4681
4694
|
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
4682
4695
|
}
|
|
@@ -4692,6 +4705,14 @@ async function callTool(toolName, args) {
|
|
|
4692
4705
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
4693
4706
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
4694
4707
|
|
|
4708
|
+
console.error('[sandbox-diag] callTool: ' + toolName + ' → ' + MCP_URL);
|
|
4709
|
+
console.error('[sandbox-diag] headers: ' + JSON.stringify({
|
|
4710
|
+
hasAuth: !!headers['Authorization'],
|
|
4711
|
+
hasApiKey: !!headers['x-integrate-api-key'],
|
|
4712
|
+
hasTokens: !!headers['x-integrate-tokens'],
|
|
4713
|
+
hasCodeMode: !!headers['x-integrate-code-mode'],
|
|
4714
|
+
}));
|
|
4715
|
+
|
|
4695
4716
|
const res = await fetch(MCP_URL, {
|
|
4696
4717
|
method: 'POST',
|
|
4697
4718
|
headers,
|
|
@@ -4699,6 +4720,8 @@ async function callTool(toolName, args) {
|
|
|
4699
4720
|
});
|
|
4700
4721
|
|
|
4701
4722
|
const text = await res.text();
|
|
4723
|
+
console.error('[sandbox-diag] response: HTTP ' + res.status + ' len=' + text.length);
|
|
4724
|
+
|
|
4702
4725
|
let payload;
|
|
4703
4726
|
try {
|
|
4704
4727
|
payload = text ? JSON.parse(text) : null;
|
|
@@ -4876,6 +4899,16 @@ async function executeSandboxCode(options) {
|
|
|
4876
4899
|
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
4877
4900
|
if (options.context)
|
|
4878
4901
|
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
4902
|
+
console.debug("[integrate-sdk] Sandbox env:", JSON.stringify({
|
|
4903
|
+
mcpUrl: options.mcpUrl,
|
|
4904
|
+
hasApiKey: !!options.apiKey,
|
|
4905
|
+
hasSessionToken: !!options.sessionToken,
|
|
4906
|
+
providerTokenKeys: options.providerTokens ? Object.keys(options.providerTokens) : [],
|
|
4907
|
+
hasIntegrations: !!options.integrationsHeader,
|
|
4908
|
+
hasContext: !!options.context,
|
|
4909
|
+
runtime,
|
|
4910
|
+
timeoutMs
|
|
4911
|
+
}));
|
|
4879
4912
|
const cmd = await sandbox.runCommand({
|
|
4880
4913
|
cmd: "node",
|
|
4881
4914
|
args: ["user.mjs"],
|
|
@@ -5001,11 +5034,50 @@ ${generated.compact}`;
|
|
|
5001
5034
|
};
|
|
5002
5035
|
}
|
|
5003
5036
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5037
|
+
let resolvedTokens = providerTokens;
|
|
5038
|
+
let tokenSource = resolvedTokens && Object.keys(resolvedTokens).length > 0 ? "build-time" : "none";
|
|
5039
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5040
|
+
try {
|
|
5041
|
+
resolvedTokens = await getProviderTokens();
|
|
5042
|
+
if (resolvedTokens && Object.keys(resolvedTokens).length > 0) {
|
|
5043
|
+
tokenSource = "request-header";
|
|
5044
|
+
}
|
|
5045
|
+
} catch {}
|
|
5046
|
+
}
|
|
5047
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5048
|
+
const oauthManager = client.oauthManager;
|
|
5049
|
+
if (oauthManager) {
|
|
5050
|
+
resolvedTokens = {};
|
|
5051
|
+
const clientIntegrations = client.integrations || [];
|
|
5052
|
+
for (const integration of clientIntegrations) {
|
|
5053
|
+
if (integration.oauth) {
|
|
5054
|
+
const provider = integration.oauth.provider;
|
|
5055
|
+
try {
|
|
5056
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5057
|
+
if (tokenData?.accessToken) {
|
|
5058
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5059
|
+
}
|
|
5060
|
+
} catch {}
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5064
|
+
resolvedTokens = undefined;
|
|
5065
|
+
} else {
|
|
5066
|
+
tokenSource = "oauthManager";
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
console.debug("[integrate-sdk] execute_code token resolution:", JSON.stringify({
|
|
5071
|
+
source: tokenSource,
|
|
5072
|
+
keys: resolvedTokens ? Object.keys(resolvedTokens) : [],
|
|
5073
|
+
hasApiKey: !!apiKey,
|
|
5074
|
+
mcpUrl
|
|
5075
|
+
}));
|
|
5004
5076
|
return executeSandboxCode({
|
|
5005
5077
|
code,
|
|
5006
5078
|
mcpUrl,
|
|
5007
5079
|
apiKey,
|
|
5008
|
-
providerTokens,
|
|
5080
|
+
providerTokens: resolvedTokens,
|
|
5009
5081
|
context,
|
|
5010
5082
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
5011
5083
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
|
@@ -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,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,GACA,OAAO,CAAC;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1B,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;KAC3B,CAAC,CAAC;IACH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED,UAAU,cAAc;IACtB,MAAM,CAAC,OAAO,EAAE;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,GAAG,OAAO,CAAC,WAAW,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,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,CAsF9G"}
|
|
@@ -30,6 +30,19 @@ if (!MCP_URL) {
|
|
|
30
30
|
throw new Error('INTEGRATE_MCP_URL is not set — the sandbox cannot reach the MCP route.');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// Diagnostic: log sandbox env summary to stderr so it shows up in the
|
|
34
|
+
// execute_code result's stderr field for debugging auth issues.
|
|
35
|
+
console.error('[sandbox-diag] MCP_URL=' + MCP_URL);
|
|
36
|
+
console.error('[sandbox-diag] HAS_API_KEY=' + !!API_KEY);
|
|
37
|
+
console.error('[sandbox-diag] HAS_SESSION_TOKEN=' + !!SESSION_TOKEN);
|
|
38
|
+
console.error('[sandbox-diag] HAS_PROVIDER_TOKENS=' + !!PROVIDER_TOKENS);
|
|
39
|
+
if (PROVIDER_TOKENS) {
|
|
40
|
+
try {
|
|
41
|
+
const _keys = Object.keys(JSON.parse(PROVIDER_TOKENS));
|
|
42
|
+
console.error('[sandbox-diag] PROVIDER_TOKEN_KEYS=' + _keys.join(','));
|
|
43
|
+
} catch { console.error('[sandbox-diag] PROVIDER_TOKENS is not valid JSON'); }
|
|
44
|
+
}
|
|
45
|
+
|
|
33
46
|
function camelToSnake(str) {
|
|
34
47
|
return str.replace(/[A-Z]/g, (letter) => '_' + letter.toLowerCase());
|
|
35
48
|
}
|
|
@@ -45,6 +58,14 @@ async function callTool(toolName, args) {
|
|
|
45
58
|
if (INTEGRATIONS_HEADER) headers['x-integrations'] = INTEGRATIONS_HEADER;
|
|
46
59
|
if (CONTEXT_JSON) headers['x-integrate-context'] = CONTEXT_JSON;
|
|
47
60
|
|
|
61
|
+
console.error('[sandbox-diag] callTool: ' + toolName + ' → ' + MCP_URL);
|
|
62
|
+
console.error('[sandbox-diag] headers: ' + JSON.stringify({
|
|
63
|
+
hasAuth: !!headers['Authorization'],
|
|
64
|
+
hasApiKey: !!headers['x-integrate-api-key'],
|
|
65
|
+
hasTokens: !!headers['x-integrate-tokens'],
|
|
66
|
+
hasCodeMode: !!headers['x-integrate-code-mode'],
|
|
67
|
+
}));
|
|
68
|
+
|
|
48
69
|
const res = await fetch(MCP_URL, {
|
|
49
70
|
method: 'POST',
|
|
50
71
|
headers,
|
|
@@ -52,6 +73,8 @@ async function callTool(toolName, args) {
|
|
|
52
73
|
});
|
|
53
74
|
|
|
54
75
|
const text = await res.text();
|
|
76
|
+
console.error('[sandbox-diag] response: HTTP ' + res.status + ' len=' + text.length);
|
|
77
|
+
|
|
55
78
|
let payload;
|
|
56
79
|
try {
|
|
57
80
|
payload = text ? JSON.parse(text) : null;
|
|
@@ -240,6 +263,16 @@ async function executeSandboxCode(options) {
|
|
|
240
263
|
env.INTEGRATE_INTEGRATIONS = options.integrationsHeader;
|
|
241
264
|
if (options.context)
|
|
242
265
|
env.INTEGRATE_CONTEXT = JSON.stringify(options.context);
|
|
266
|
+
console.debug("[integrate-sdk] Sandbox env:", JSON.stringify({
|
|
267
|
+
mcpUrl: options.mcpUrl,
|
|
268
|
+
hasApiKey: !!options.apiKey,
|
|
269
|
+
hasSessionToken: !!options.sessionToken,
|
|
270
|
+
providerTokenKeys: options.providerTokens ? Object.keys(options.providerTokens) : [],
|
|
271
|
+
hasIntegrations: !!options.integrationsHeader,
|
|
272
|
+
hasContext: !!options.context,
|
|
273
|
+
runtime,
|
|
274
|
+
timeoutMs
|
|
275
|
+
}));
|
|
243
276
|
const cmd = await sandbox.runCommand({
|
|
244
277
|
cmd: "node",
|
|
245
278
|
args: ["user.mjs"],
|