integrate-sdk 0.9.17-dev.0 → 0.9.19-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/index.js +6 -16
- package/dist/adapters/solid-start.js +6 -16
- package/dist/adapters/svelte-kit.js +6 -16
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +102 -27
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +107 -27
- package/dist/ai/index.js +139 -32
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +100 -27
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +97 -26
- 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 +90 -25
- package/dist/code-mode/tool-builder.d.ts +32 -4
- package/dist/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/code-mode/tool-builder.js +90 -25
- package/dist/code-mode/type-generator.d.ts +4 -0
- package/dist/code-mode/type-generator.d.ts.map +1 -1
- package/dist/code-mode/type-generator.js +33 -3
- package/dist/server.js +141 -33
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/code-mode/index.d.ts +1 -1
- package/dist/src/code-mode/index.d.ts.map +1 -1
- package/dist/src/code-mode/tool-builder.d.ts +32 -4
- package/dist/src/code-mode/tool-builder.d.ts.map +1 -1
- package/dist/src/code-mode/type-generator.d.ts +4 -0
- package/dist/src/code-mode/type-generator.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/adapters/index.js
CHANGED
|
@@ -1164,24 +1164,14 @@ var init_tool_builder = __esm(() => {
|
|
|
1164
1164
|
init_type_generator();
|
|
1165
1165
|
init_executor();
|
|
1166
1166
|
DEFAULT_INSTRUCTIONS = [
|
|
1167
|
-
"
|
|
1168
|
-
"
|
|
1169
|
-
"
|
|
1170
|
-
"
|
|
1171
|
-
"that is the whole point of this tool.",
|
|
1167
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
1168
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
1169
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
1170
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
1172
1171
|
"",
|
|
1173
|
-
"
|
|
1174
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
1175
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
1176
|
-
" the caller receives it as JSON.",
|
|
1177
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
1178
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
1179
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
1180
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
1181
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
1182
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
1172
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
1183
1173
|
"",
|
|
1184
|
-
"
|
|
1174
|
+
"Available methods:"
|
|
1185
1175
|
].join(`
|
|
1186
1176
|
`);
|
|
1187
1177
|
warnedCodeModeReasons = new Set;
|
|
@@ -1164,24 +1164,14 @@ var init_tool_builder = __esm(() => {
|
|
|
1164
1164
|
init_type_generator();
|
|
1165
1165
|
init_executor();
|
|
1166
1166
|
DEFAULT_INSTRUCTIONS = [
|
|
1167
|
-
"
|
|
1168
|
-
"
|
|
1169
|
-
"
|
|
1170
|
-
"
|
|
1171
|
-
"that is the whole point of this tool.",
|
|
1167
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
1168
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
1169
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
1170
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
1172
1171
|
"",
|
|
1173
|
-
"
|
|
1174
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
1175
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
1176
|
-
" the caller receives it as JSON.",
|
|
1177
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
1178
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
1179
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
1180
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
1181
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
1182
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
1172
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
1183
1173
|
"",
|
|
1184
|
-
"
|
|
1174
|
+
"Available methods:"
|
|
1185
1175
|
].join(`
|
|
1186
1176
|
`);
|
|
1187
1177
|
warnedCodeModeReasons = new Set;
|
|
@@ -1164,24 +1164,14 @@ var init_tool_builder = __esm(() => {
|
|
|
1164
1164
|
init_type_generator();
|
|
1165
1165
|
init_executor();
|
|
1166
1166
|
DEFAULT_INSTRUCTIONS = [
|
|
1167
|
-
"
|
|
1168
|
-
"
|
|
1169
|
-
"
|
|
1170
|
-
"
|
|
1171
|
-
"that is the whole point of this tool.",
|
|
1167
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
1168
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
1169
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
1170
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
1172
1171
|
"",
|
|
1173
|
-
"
|
|
1174
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
1175
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
1176
|
-
" the caller receives it as JSON.",
|
|
1177
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
1178
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
1179
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
1180
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
1181
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
1182
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
1172
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
1183
1173
|
"",
|
|
1184
|
-
"
|
|
1174
|
+
"Available methods:"
|
|
1185
1175
|
].join(`
|
|
1186
1176
|
`);
|
|
1187
1177
|
warnedCodeModeReasons = new Set;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/ai/anthropic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/ai/anthropic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAUjH,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AA+ID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,aAAa,EAAE,CAAC,CAmF1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpG,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAkC5I"}
|
package/dist/ai/anthropic.js
CHANGED
|
@@ -4584,6 +4584,8 @@ function generateCodeModeTypes(tools) {
|
|
|
4584
4584
|
const methodMap = {};
|
|
4585
4585
|
const integrationCounts = {};
|
|
4586
4586
|
const sections = [];
|
|
4587
|
+
const compactLines = [];
|
|
4588
|
+
const perIntegration = {};
|
|
4587
4589
|
const integrationIds = Object.keys(byIntegration).sort();
|
|
4588
4590
|
sections.push("/**");
|
|
4589
4591
|
sections.push(" * Integrate SDK — available APIs inside `execute_code`.");
|
|
@@ -4596,18 +4598,35 @@ function generateCodeModeTypes(tools) {
|
|
|
4596
4598
|
const integrationTools = byIntegration[integrationId].slice().sort((a, b) => a.name.localeCompare(b.name));
|
|
4597
4599
|
integrationCounts[integrationId] = integrationTools.length;
|
|
4598
4600
|
const interfaceName = pascalCase(integrationId) + "Client";
|
|
4601
|
+
const fullSections = [];
|
|
4602
|
+
fullSections.push(`export interface ${interfaceName} {`);
|
|
4599
4603
|
sections.push(`export interface ${interfaceName} {`);
|
|
4604
|
+
const compactMethods = [];
|
|
4600
4605
|
for (const tool of integrationTools) {
|
|
4601
4606
|
const methodName = toolNameToMethod(tool.name);
|
|
4602
4607
|
methodMap[`${integrationId}.${methodName}`] = tool.name;
|
|
4603
|
-
|
|
4608
|
+
const fullDesc = formatDescription(tool.description, " ");
|
|
4609
|
+
fullSections.push(fullDesc);
|
|
4610
|
+
sections.push(fullDesc);
|
|
4604
4611
|
const argType = argsType(tool.inputSchema);
|
|
4605
4612
|
const argIsOptional = !methodHasRequiredArgs(tool.inputSchema);
|
|
4606
4613
|
const paramName = argIsOptional ? "args?" : "args";
|
|
4607
|
-
|
|
4614
|
+
const fullLine = ` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`;
|
|
4615
|
+
fullSections.push(fullLine);
|
|
4616
|
+
sections.push(fullLine);
|
|
4617
|
+
const compactArgs = compactArgsSignature(tool.inputSchema);
|
|
4618
|
+
const compactParam = argIsOptional ? `args?: ${compactArgs}` : `args: ${compactArgs}`;
|
|
4619
|
+
compactMethods.push(` ${safeIdent(methodName)}(${compactParam}): Promise<ToolResult>`);
|
|
4608
4620
|
}
|
|
4609
4621
|
sections.push("}");
|
|
4610
4622
|
sections.push("");
|
|
4623
|
+
fullSections.push("}");
|
|
4624
|
+
perIntegration[integrationId] = fullSections.join(`
|
|
4625
|
+
`);
|
|
4626
|
+
compactLines.push(`client.${integrationId}:`);
|
|
4627
|
+
for (const m of compactMethods) {
|
|
4628
|
+
compactLines.push(m);
|
|
4629
|
+
}
|
|
4611
4630
|
}
|
|
4612
4631
|
sections.push("export interface ToolResult {");
|
|
4613
4632
|
sections.push(" content: Array<{ type: 'text' | 'image' | 'resource'; text?: string; data?: string; mimeType?: string; [key: string]: unknown }>;");
|
|
@@ -4625,11 +4644,22 @@ function generateCodeModeTypes(tools) {
|
|
|
4625
4644
|
sections.push("export declare const client: Client;");
|
|
4626
4645
|
return {
|
|
4627
4646
|
source: sections.filter((line, idx, arr) => !(line === "" && arr[idx - 1] === "")).join(`
|
|
4647
|
+
`),
|
|
4648
|
+
compact: compactLines.join(`
|
|
4628
4649
|
`),
|
|
4629
4650
|
methodMap,
|
|
4630
|
-
integrationCounts
|
|
4651
|
+
integrationCounts,
|
|
4652
|
+
perIntegration
|
|
4631
4653
|
};
|
|
4632
4654
|
}
|
|
4655
|
+
function compactArgsSignature(schema) {
|
|
4656
|
+
if (!schema || !schema.properties || Object.keys(schema.properties).length === 0) {
|
|
4657
|
+
return "{}";
|
|
4658
|
+
}
|
|
4659
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
4660
|
+
const params = Object.keys(schema.properties).map((key) => `${safeIdent(key)}${required.has(key) ? "" : "?"}`);
|
|
4661
|
+
return `{ ${params.join(", ")} }`;
|
|
4662
|
+
}
|
|
4633
4663
|
function pascalCase(id) {
|
|
4634
4664
|
return id.split(/[^A-Za-z0-9]/).filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("") || "Unknown";
|
|
4635
4665
|
}
|
|
@@ -4903,25 +4933,16 @@ function getEnv(key) {
|
|
|
4903
4933
|
|
|
4904
4934
|
// ../code-mode/tool-builder.ts
|
|
4905
4935
|
var CODE_MODE_TOOL_NAME = "execute_code";
|
|
4936
|
+
var TYPES_TOOL_NAME = "get_integration_types";
|
|
4906
4937
|
var DEFAULT_INSTRUCTIONS = [
|
|
4907
|
-
"
|
|
4908
|
-
"
|
|
4909
|
-
"
|
|
4910
|
-
"
|
|
4911
|
-
"that is the whole point of this tool.",
|
|
4938
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
4939
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
4940
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
4941
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
4912
4942
|
"",
|
|
4913
|
-
"
|
|
4914
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
4915
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
4916
|
-
" the caller receives it as JSON.",
|
|
4917
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
4918
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
4919
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
4920
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
4921
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
4922
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
4943
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
4923
4944
|
"",
|
|
4924
|
-
"
|
|
4945
|
+
"Available methods:"
|
|
4925
4946
|
].join(`
|
|
4926
4947
|
`);
|
|
4927
4948
|
function resolveCodeModeClientConfig(client) {
|
|
@@ -4963,10 +4984,7 @@ function buildCodeModeTool(client, options) {
|
|
|
4963
4984
|
const serverCodeModeConfig = resolveCodeModeClientConfig(client);
|
|
4964
4985
|
const sandboxOverrides = options.sandbox ?? {};
|
|
4965
4986
|
const description = `${DEFAULT_INSTRUCTIONS}
|
|
4966
|
-
|
|
4967
|
-
\`\`\`typescript
|
|
4968
|
-
${generated.source}
|
|
4969
|
-
\`\`\``;
|
|
4987
|
+
${generated.compact}`;
|
|
4970
4988
|
const execute = async ({ code }) => {
|
|
4971
4989
|
const publicUrl = resolveCodeModePublicUrl({
|
|
4972
4990
|
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
@@ -4983,11 +5001,33 @@ ${generated.source}
|
|
|
4983
5001
|
};
|
|
4984
5002
|
}
|
|
4985
5003
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5004
|
+
let resolvedTokens = providerTokens;
|
|
5005
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5006
|
+
const oauthManager = client.oauthManager;
|
|
5007
|
+
if (oauthManager) {
|
|
5008
|
+
resolvedTokens = {};
|
|
5009
|
+
const clientIntegrations = client.integrations || [];
|
|
5010
|
+
for (const integration of clientIntegrations) {
|
|
5011
|
+
if (integration.oauth) {
|
|
5012
|
+
const provider = integration.oauth.provider;
|
|
5013
|
+
try {
|
|
5014
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5015
|
+
if (tokenData?.accessToken) {
|
|
5016
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5017
|
+
}
|
|
5018
|
+
} catch {}
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5022
|
+
resolvedTokens = undefined;
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
4986
5026
|
return executeSandboxCode({
|
|
4987
5027
|
code,
|
|
4988
5028
|
mcpUrl,
|
|
4989
5029
|
apiKey,
|
|
4990
|
-
providerTokens,
|
|
5030
|
+
providerTokens: resolvedTokens,
|
|
4991
5031
|
context,
|
|
4992
5032
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
4993
5033
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
|
@@ -4996,7 +5036,8 @@ ${generated.source}
|
|
|
4996
5036
|
networkPolicy: sandboxOverrides.networkPolicy ?? serverCodeModeConfig.networkPolicy
|
|
4997
5037
|
});
|
|
4998
5038
|
};
|
|
4999
|
-
|
|
5039
|
+
const availableIntegrations = Object.keys(generated.perIntegration);
|
|
5040
|
+
const codeTool = {
|
|
5000
5041
|
name: CODE_MODE_TOOL_NAME,
|
|
5001
5042
|
description,
|
|
5002
5043
|
parameters: {
|
|
@@ -5012,6 +5053,29 @@ ${generated.source}
|
|
|
5012
5053
|
},
|
|
5013
5054
|
execute
|
|
5014
5055
|
};
|
|
5056
|
+
const typesTool = {
|
|
5057
|
+
name: TYPES_TOOL_NAME,
|
|
5058
|
+
description: "Get full TypeScript type definitions (method signatures, parameter types, JSDoc) for a specific integration. " + `Available integrations: ${availableIntegrations.join(", ")}.`,
|
|
5059
|
+
parameters: {
|
|
5060
|
+
type: "object",
|
|
5061
|
+
properties: {
|
|
5062
|
+
integration: {
|
|
5063
|
+
type: "string",
|
|
5064
|
+
description: `Integration name to get types for (${availableIntegrations.join(", ")}).`
|
|
5065
|
+
}
|
|
5066
|
+
},
|
|
5067
|
+
required: ["integration"],
|
|
5068
|
+
additionalProperties: false
|
|
5069
|
+
},
|
|
5070
|
+
execute: ({ integration }) => {
|
|
5071
|
+
const types2 = generated.perIntegration[integration];
|
|
5072
|
+
if (!types2) {
|
|
5073
|
+
return { error: `Unknown integration "${integration}".`, available: availableIntegrations };
|
|
5074
|
+
}
|
|
5075
|
+
return { types: types2 };
|
|
5076
|
+
}
|
|
5077
|
+
};
|
|
5078
|
+
return { codeTool, typesTool };
|
|
5015
5079
|
}
|
|
5016
5080
|
|
|
5017
5081
|
// anthropic.ts
|
|
@@ -5049,8 +5113,11 @@ async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
|
5049
5113
|
try {
|
|
5050
5114
|
let result;
|
|
5051
5115
|
if (toolUse.name === CODE_MODE_TOOL_NAME) {
|
|
5052
|
-
const codeTool = await getCodeModeTool();
|
|
5116
|
+
const { codeTool } = await getCodeModeTool();
|
|
5053
5117
|
result = await codeTool.execute(toolUse.input);
|
|
5118
|
+
} else if (toolUse.name === TYPES_TOOL_NAME) {
|
|
5119
|
+
const { typesTool } = await getCodeModeTool();
|
|
5120
|
+
result = typesTool.execute(toolUse.input);
|
|
5054
5121
|
} else if (triggerTools && triggerTools[toolUse.name]) {
|
|
5055
5122
|
result = await triggerTools[toolUse.name].execute(toolUse.input);
|
|
5056
5123
|
} else {
|
|
@@ -5097,7 +5164,7 @@ async function getAnthropicTools(client, options) {
|
|
|
5097
5164
|
}
|
|
5098
5165
|
}
|
|
5099
5166
|
const anthropicTools = effectiveMode === "code" ? (() => {
|
|
5100
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5167
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5101
5168
|
tools: mcpTools,
|
|
5102
5169
|
providerTokens,
|
|
5103
5170
|
context: options?.context,
|
|
@@ -5111,6 +5178,14 @@ async function getAnthropicTools(client, options) {
|
|
|
5111
5178
|
properties: codeTool.parameters.properties,
|
|
5112
5179
|
required: [...codeTool.parameters.required]
|
|
5113
5180
|
}
|
|
5181
|
+
}, {
|
|
5182
|
+
name: TYPES_TOOL_NAME,
|
|
5183
|
+
description: typesTool.description,
|
|
5184
|
+
input_schema: {
|
|
5185
|
+
type: "object",
|
|
5186
|
+
properties: typesTool.parameters.properties,
|
|
5187
|
+
required: [...typesTool.parameters.required]
|
|
5188
|
+
}
|
|
5114
5189
|
}];
|
|
5115
5190
|
})() : mcpTools.map((mcpTool) => convertMCPToolToAnthropic(mcpTool, client, finalOptions));
|
|
5116
5191
|
const triggerConfig = client.__triggerConfig;
|
package/dist/ai/google.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAajH,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EACnB,YAAY,EACZ,IAAI,EACL,MAAM,eAAe,CAAC;AAGvB,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC7C,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC9C,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAuB7B;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAsGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,aAAa,EAAE,kBAAkB,EAAE,GAAG,SAAS,GAAG,IAAI,EACtD,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,EAAE,CAAC,CA+DnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAqGvB"}
|
package/dist/ai/google.js
CHANGED
|
@@ -4584,6 +4584,8 @@ function generateCodeModeTypes(tools) {
|
|
|
4584
4584
|
const methodMap = {};
|
|
4585
4585
|
const integrationCounts = {};
|
|
4586
4586
|
const sections = [];
|
|
4587
|
+
const compactLines = [];
|
|
4588
|
+
const perIntegration = {};
|
|
4587
4589
|
const integrationIds = Object.keys(byIntegration).sort();
|
|
4588
4590
|
sections.push("/**");
|
|
4589
4591
|
sections.push(" * Integrate SDK — available APIs inside `execute_code`.");
|
|
@@ -4596,18 +4598,35 @@ function generateCodeModeTypes(tools) {
|
|
|
4596
4598
|
const integrationTools = byIntegration[integrationId].slice().sort((a, b) => a.name.localeCompare(b.name));
|
|
4597
4599
|
integrationCounts[integrationId] = integrationTools.length;
|
|
4598
4600
|
const interfaceName = pascalCase(integrationId) + "Client";
|
|
4601
|
+
const fullSections = [];
|
|
4602
|
+
fullSections.push(`export interface ${interfaceName} {`);
|
|
4599
4603
|
sections.push(`export interface ${interfaceName} {`);
|
|
4604
|
+
const compactMethods = [];
|
|
4600
4605
|
for (const tool of integrationTools) {
|
|
4601
4606
|
const methodName = toolNameToMethod(tool.name);
|
|
4602
4607
|
methodMap[`${integrationId}.${methodName}`] = tool.name;
|
|
4603
|
-
|
|
4608
|
+
const fullDesc = formatDescription(tool.description, " ");
|
|
4609
|
+
fullSections.push(fullDesc);
|
|
4610
|
+
sections.push(fullDesc);
|
|
4604
4611
|
const argType = argsType(tool.inputSchema);
|
|
4605
4612
|
const argIsOptional = !methodHasRequiredArgs(tool.inputSchema);
|
|
4606
4613
|
const paramName = argIsOptional ? "args?" : "args";
|
|
4607
|
-
|
|
4614
|
+
const fullLine = ` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`;
|
|
4615
|
+
fullSections.push(fullLine);
|
|
4616
|
+
sections.push(fullLine);
|
|
4617
|
+
const compactArgs = compactArgsSignature(tool.inputSchema);
|
|
4618
|
+
const compactParam = argIsOptional ? `args?: ${compactArgs}` : `args: ${compactArgs}`;
|
|
4619
|
+
compactMethods.push(` ${safeIdent(methodName)}(${compactParam}): Promise<ToolResult>`);
|
|
4608
4620
|
}
|
|
4609
4621
|
sections.push("}");
|
|
4610
4622
|
sections.push("");
|
|
4623
|
+
fullSections.push("}");
|
|
4624
|
+
perIntegration[integrationId] = fullSections.join(`
|
|
4625
|
+
`);
|
|
4626
|
+
compactLines.push(`client.${integrationId}:`);
|
|
4627
|
+
for (const m of compactMethods) {
|
|
4628
|
+
compactLines.push(m);
|
|
4629
|
+
}
|
|
4611
4630
|
}
|
|
4612
4631
|
sections.push("export interface ToolResult {");
|
|
4613
4632
|
sections.push(" content: Array<{ type: 'text' | 'image' | 'resource'; text?: string; data?: string; mimeType?: string; [key: string]: unknown }>;");
|
|
@@ -4625,11 +4644,22 @@ function generateCodeModeTypes(tools) {
|
|
|
4625
4644
|
sections.push("export declare const client: Client;");
|
|
4626
4645
|
return {
|
|
4627
4646
|
source: sections.filter((line, idx, arr) => !(line === "" && arr[idx - 1] === "")).join(`
|
|
4647
|
+
`),
|
|
4648
|
+
compact: compactLines.join(`
|
|
4628
4649
|
`),
|
|
4629
4650
|
methodMap,
|
|
4630
|
-
integrationCounts
|
|
4651
|
+
integrationCounts,
|
|
4652
|
+
perIntegration
|
|
4631
4653
|
};
|
|
4632
4654
|
}
|
|
4655
|
+
function compactArgsSignature(schema) {
|
|
4656
|
+
if (!schema || !schema.properties || Object.keys(schema.properties).length === 0) {
|
|
4657
|
+
return "{}";
|
|
4658
|
+
}
|
|
4659
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
4660
|
+
const params = Object.keys(schema.properties).map((key) => `${safeIdent(key)}${required.has(key) ? "" : "?"}`);
|
|
4661
|
+
return `{ ${params.join(", ")} }`;
|
|
4662
|
+
}
|
|
4633
4663
|
function pascalCase(id) {
|
|
4634
4664
|
return id.split(/[^A-Za-z0-9]/).filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("") || "Unknown";
|
|
4635
4665
|
}
|
|
@@ -4903,25 +4933,16 @@ function getEnv(key) {
|
|
|
4903
4933
|
|
|
4904
4934
|
// ../code-mode/tool-builder.ts
|
|
4905
4935
|
var CODE_MODE_TOOL_NAME = "execute_code";
|
|
4936
|
+
var TYPES_TOOL_NAME = "get_integration_types";
|
|
4906
4937
|
var DEFAULT_INSTRUCTIONS = [
|
|
4907
|
-
"
|
|
4908
|
-
"
|
|
4909
|
-
"
|
|
4910
|
-
"
|
|
4911
|
-
"that is the whole point of this tool.",
|
|
4938
|
+
"Write an async JS/TS snippet that runs in an isolated sandbox using `client.<integration>.<method>(args)`.",
|
|
4939
|
+
"Chain multiple operations in one snippet. Use `await`, `return <value>` for JSON output, `console.log()` for debug.",
|
|
4940
|
+
"Each method returns `ToolResult { content: [{ type, text? }], isError? }` — parse `result.content[0].text` as JSON.",
|
|
4941
|
+
"Only `client`, `callTool`, `fetch`, `console`, `JSON` are available (no npm imports).",
|
|
4912
4942
|
"",
|
|
4913
|
-
"
|
|
4914
|
-
"- The snippet is the body of an `async` function. Use `await` freely.",
|
|
4915
|
-
"- Use `return <value>` at the end to hand a structured result back to the caller;",
|
|
4916
|
-
" the caller receives it as JSON.",
|
|
4917
|
-
"- Use `console.log(...)` for intermediate observations you want to read later.",
|
|
4918
|
-
"- Throw / let errors propagate; the runtime will surface them with a non-zero exit.",
|
|
4919
|
-
"- Each method call returns an object of shape `ToolResult` (see types below).",
|
|
4920
|
-
" The payload usually lives in `result.content[0].text` as JSON — parse it if needed.",
|
|
4921
|
-
"- You cannot import npm packages. Only the pre-imported `client` and standard",
|
|
4922
|
-
" globals (`fetch`, `console`, `JSON`, ...) are available.",
|
|
4943
|
+
"Call `get_integration_types` with an integration name to get full parameter types before writing code.",
|
|
4923
4944
|
"",
|
|
4924
|
-
"
|
|
4945
|
+
"Available methods:"
|
|
4925
4946
|
].join(`
|
|
4926
4947
|
`);
|
|
4927
4948
|
function resolveCodeModeClientConfig(client) {
|
|
@@ -4963,10 +4984,7 @@ function buildCodeModeTool(client, options) {
|
|
|
4963
4984
|
const serverCodeModeConfig = resolveCodeModeClientConfig(client);
|
|
4964
4985
|
const sandboxOverrides = options.sandbox ?? {};
|
|
4965
4986
|
const description = `${DEFAULT_INSTRUCTIONS}
|
|
4966
|
-
|
|
4967
|
-
\`\`\`typescript
|
|
4968
|
-
${generated.source}
|
|
4969
|
-
\`\`\``;
|
|
4987
|
+
${generated.compact}`;
|
|
4970
4988
|
const execute = async ({ code }) => {
|
|
4971
4989
|
const publicUrl = resolveCodeModePublicUrl({
|
|
4972
4990
|
publicUrl: sandboxOverrides.publicUrl ?? serverCodeModeConfig.publicUrl
|
|
@@ -4983,11 +5001,33 @@ ${generated.source}
|
|
|
4983
5001
|
};
|
|
4984
5002
|
}
|
|
4985
5003
|
const mcpUrl = publicUrl.replace(/\/$/, "") + "/api/integrate/mcp";
|
|
5004
|
+
let resolvedTokens = providerTokens;
|
|
5005
|
+
if (!resolvedTokens || Object.keys(resolvedTokens).length === 0) {
|
|
5006
|
+
const oauthManager = client.oauthManager;
|
|
5007
|
+
if (oauthManager) {
|
|
5008
|
+
resolvedTokens = {};
|
|
5009
|
+
const clientIntegrations = client.integrations || [];
|
|
5010
|
+
for (const integration of clientIntegrations) {
|
|
5011
|
+
if (integration.oauth) {
|
|
5012
|
+
const provider = integration.oauth.provider;
|
|
5013
|
+
try {
|
|
5014
|
+
const tokenData = await oauthManager.getProviderToken(provider, undefined, context);
|
|
5015
|
+
if (tokenData?.accessToken) {
|
|
5016
|
+
resolvedTokens[provider] = tokenData.accessToken;
|
|
5017
|
+
}
|
|
5018
|
+
} catch {}
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
if (Object.keys(resolvedTokens).length === 0) {
|
|
5022
|
+
resolvedTokens = undefined;
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
4986
5026
|
return executeSandboxCode({
|
|
4987
5027
|
code,
|
|
4988
5028
|
mcpUrl,
|
|
4989
5029
|
apiKey,
|
|
4990
|
-
providerTokens,
|
|
5030
|
+
providerTokens: resolvedTokens,
|
|
4991
5031
|
context,
|
|
4992
5032
|
integrationsHeader: integrationIds && integrationIds.length > 0 ? integrationIds.join(",") : undefined,
|
|
4993
5033
|
runtime: sandboxOverrides.runtime ?? serverCodeModeConfig.runtime,
|
|
@@ -4996,7 +5036,8 @@ ${generated.source}
|
|
|
4996
5036
|
networkPolicy: sandboxOverrides.networkPolicy ?? serverCodeModeConfig.networkPolicy
|
|
4997
5037
|
});
|
|
4998
5038
|
};
|
|
4999
|
-
|
|
5039
|
+
const availableIntegrations = Object.keys(generated.perIntegration);
|
|
5040
|
+
const codeTool = {
|
|
5000
5041
|
name: CODE_MODE_TOOL_NAME,
|
|
5001
5042
|
description,
|
|
5002
5043
|
parameters: {
|
|
@@ -5012,6 +5053,29 @@ ${generated.source}
|
|
|
5012
5053
|
},
|
|
5013
5054
|
execute
|
|
5014
5055
|
};
|
|
5056
|
+
const typesTool = {
|
|
5057
|
+
name: TYPES_TOOL_NAME,
|
|
5058
|
+
description: "Get full TypeScript type definitions (method signatures, parameter types, JSDoc) for a specific integration. " + `Available integrations: ${availableIntegrations.join(", ")}.`,
|
|
5059
|
+
parameters: {
|
|
5060
|
+
type: "object",
|
|
5061
|
+
properties: {
|
|
5062
|
+
integration: {
|
|
5063
|
+
type: "string",
|
|
5064
|
+
description: `Integration name to get types for (${availableIntegrations.join(", ")}).`
|
|
5065
|
+
}
|
|
5066
|
+
},
|
|
5067
|
+
required: ["integration"],
|
|
5068
|
+
additionalProperties: false
|
|
5069
|
+
},
|
|
5070
|
+
execute: ({ integration }) => {
|
|
5071
|
+
const types2 = generated.perIntegration[integration];
|
|
5072
|
+
if (!types2) {
|
|
5073
|
+
return { error: `Unknown integration "${integration}".`, available: availableIntegrations };
|
|
5074
|
+
}
|
|
5075
|
+
return { types: types2 };
|
|
5076
|
+
}
|
|
5077
|
+
};
|
|
5078
|
+
return { codeTool, typesTool };
|
|
5015
5079
|
}
|
|
5016
5080
|
|
|
5017
5081
|
// google.ts
|
|
@@ -5117,8 +5181,11 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
5117
5181
|
const args = call.args || {};
|
|
5118
5182
|
let result;
|
|
5119
5183
|
if (call.name === CODE_MODE_TOOL_NAME) {
|
|
5120
|
-
const codeTool = await getCodeModeTool();
|
|
5184
|
+
const { codeTool } = await getCodeModeTool();
|
|
5121
5185
|
result = await codeTool.execute(args);
|
|
5186
|
+
} else if (call.name === TYPES_TOOL_NAME) {
|
|
5187
|
+
const { typesTool } = await getCodeModeTool();
|
|
5188
|
+
result = typesTool.execute(args);
|
|
5122
5189
|
} else if (triggerTools && triggerTools[call.name]) {
|
|
5123
5190
|
result = await triggerTools[call.name].execute(args);
|
|
5124
5191
|
} else {
|
|
@@ -5153,7 +5220,7 @@ async function getGoogleTools(client, options) {
|
|
|
5153
5220
|
let googleTools;
|
|
5154
5221
|
if (effectiveMode === "code") {
|
|
5155
5222
|
const TypeEnum = await getGoogleType();
|
|
5156
|
-
const codeTool = buildCodeModeTool(client, {
|
|
5223
|
+
const { codeTool, typesTool } = buildCodeModeTool(client, {
|
|
5157
5224
|
tools: mcpTools,
|
|
5158
5225
|
providerTokens,
|
|
5159
5226
|
context: options?.context,
|
|
@@ -5172,6 +5239,19 @@ async function getGoogleTools(client, options) {
|
|
|
5172
5239
|
},
|
|
5173
5240
|
required: ["code"]
|
|
5174
5241
|
}
|
|
5242
|
+
}, {
|
|
5243
|
+
name: TYPES_TOOL_NAME,
|
|
5244
|
+
description: typesTool.description,
|
|
5245
|
+
parameters: {
|
|
5246
|
+
type: TypeEnum.OBJECT,
|
|
5247
|
+
properties: {
|
|
5248
|
+
integration: {
|
|
5249
|
+
type: TypeEnum.STRING,
|
|
5250
|
+
description: typesTool.parameters.properties.integration.description
|
|
5251
|
+
}
|
|
5252
|
+
},
|
|
5253
|
+
required: ["integration"]
|
|
5254
|
+
}
|
|
5175
5255
|
}];
|
|
5176
5256
|
} else {
|
|
5177
5257
|
googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
|