integrate-sdk 0.9.3-dev.0 → 0.9.4-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 +713 -15
- package/dist/adapters/index.js +713 -15
- package/dist/adapters/nextjs.js +713 -15
- package/dist/adapters/node.js +713 -15
- package/dist/adapters/svelte-kit.js +713 -15
- package/dist/adapters/tanstack-start.js +713 -15
- package/dist/ai/anthropic.d.ts +11 -0
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +552 -2
- package/dist/ai/google.d.ts +11 -0
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +561 -2
- package/dist/ai/index.js +648 -8
- package/dist/ai/openai.d.ts +11 -0
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +550 -2
- package/dist/ai/vercel-ai.d.ts +13 -0
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +536 -2
- package/dist/code-mode/executor.d.ts +99 -0
- package/dist/code-mode/executor.d.ts.map +1 -0
- package/dist/code-mode/executor.js +207 -0
- package/dist/code-mode/index.d.ts +12 -0
- package/dist/code-mode/index.d.ts.map +1 -0
- package/dist/code-mode/index.js +527 -0
- package/dist/code-mode/runtime-stub.d.ts +16 -0
- package/dist/code-mode/runtime-stub.d.ts.map +1 -0
- package/dist/code-mode/runtime-stub.js +72 -0
- package/dist/code-mode/tool-builder.d.ts +83 -0
- package/dist/code-mode/tool-builder.d.ts.map +1 -0
- package/dist/code-mode/tool-builder.js +524 -0
- package/dist/code-mode/type-generator.d.ts +22 -0
- package/dist/code-mode/type-generator.d.ts.map +1 -0
- package/dist/code-mode/type-generator.js +217 -0
- package/dist/index.js +713 -15
- package/dist/oauth.js +713 -15
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +724 -16
- package/dist/src/ai/anthropic.d.ts +11 -0
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts +11 -0
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts +11 -0
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts +13 -0
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/code-mode/executor.d.ts +99 -0
- package/dist/src/code-mode/executor.d.ts.map +1 -0
- package/dist/src/code-mode/index.d.ts +12 -0
- package/dist/src/code-mode/index.d.ts.map +1 -0
- package/dist/src/code-mode/runtime-stub.d.ts +16 -0
- package/dist/src/code-mode/runtime-stub.d.ts.map +1 -0
- package/dist/src/code-mode/tool-builder.d.ts +83 -0
- package/dist/src/code-mode/tool-builder.d.ts.map +1 -0
- package/dist/src/code-mode/type-generator.d.ts +22 -0
- package/dist/src/code-mode/type-generator.d.ts.map +1 -0
- package/dist/src/config/types.d.ts +55 -0
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +15 -6
- package/server.ts +9 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// ../utils/naming.ts
|
|
2
|
+
function snakeToCamel(str) {
|
|
3
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
4
|
+
}
|
|
5
|
+
function toolNameToMethod(toolName) {
|
|
6
|
+
const withoutPrefix = toolName.replace(/^[^_]+_/, "");
|
|
7
|
+
return snakeToCamel(withoutPrefix);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// type-generator.ts
|
|
11
|
+
var RESERVED_TS = new Set([
|
|
12
|
+
"break",
|
|
13
|
+
"case",
|
|
14
|
+
"catch",
|
|
15
|
+
"class",
|
|
16
|
+
"const",
|
|
17
|
+
"continue",
|
|
18
|
+
"debugger",
|
|
19
|
+
"default",
|
|
20
|
+
"delete",
|
|
21
|
+
"do",
|
|
22
|
+
"else",
|
|
23
|
+
"enum",
|
|
24
|
+
"export",
|
|
25
|
+
"extends",
|
|
26
|
+
"false",
|
|
27
|
+
"finally",
|
|
28
|
+
"for",
|
|
29
|
+
"function",
|
|
30
|
+
"if",
|
|
31
|
+
"import",
|
|
32
|
+
"in",
|
|
33
|
+
"instanceof",
|
|
34
|
+
"new",
|
|
35
|
+
"null",
|
|
36
|
+
"return",
|
|
37
|
+
"super",
|
|
38
|
+
"switch",
|
|
39
|
+
"this",
|
|
40
|
+
"throw",
|
|
41
|
+
"true",
|
|
42
|
+
"try",
|
|
43
|
+
"typeof",
|
|
44
|
+
"var",
|
|
45
|
+
"void",
|
|
46
|
+
"while",
|
|
47
|
+
"with",
|
|
48
|
+
"as",
|
|
49
|
+
"implements",
|
|
50
|
+
"interface",
|
|
51
|
+
"let",
|
|
52
|
+
"package",
|
|
53
|
+
"private",
|
|
54
|
+
"protected",
|
|
55
|
+
"public",
|
|
56
|
+
"static",
|
|
57
|
+
"yield"
|
|
58
|
+
]);
|
|
59
|
+
function safeIdent(name) {
|
|
60
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) || RESERVED_TS.has(name)) {
|
|
61
|
+
return JSON.stringify(name);
|
|
62
|
+
}
|
|
63
|
+
return name;
|
|
64
|
+
}
|
|
65
|
+
function integrationFromToolName(toolName) {
|
|
66
|
+
const idx = toolName.indexOf("_");
|
|
67
|
+
return idx === -1 ? toolName : toolName.slice(0, idx);
|
|
68
|
+
}
|
|
69
|
+
function jsonSchemaToTs(schema, indent) {
|
|
70
|
+
if (!schema || typeof schema !== "object")
|
|
71
|
+
return "unknown";
|
|
72
|
+
const s = schema;
|
|
73
|
+
if (Array.isArray(s.enum) && s.enum.length > 0) {
|
|
74
|
+
return s.enum.map((v) => typeof v === "string" ? JSON.stringify(v) : typeof v === "number" || typeof v === "boolean" ? String(v) : "unknown").join(" | ");
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(s.type)) {
|
|
77
|
+
return s.type.map((t2) => jsonSchemaToTs({ ...s, type: t2 }, indent)).join(" | ");
|
|
78
|
+
}
|
|
79
|
+
const t = s.type;
|
|
80
|
+
switch (t) {
|
|
81
|
+
case "string":
|
|
82
|
+
return "string";
|
|
83
|
+
case "number":
|
|
84
|
+
case "integer":
|
|
85
|
+
return "number";
|
|
86
|
+
case "boolean":
|
|
87
|
+
return "boolean";
|
|
88
|
+
case "null":
|
|
89
|
+
return "null";
|
|
90
|
+
case "array": {
|
|
91
|
+
const items = s.items;
|
|
92
|
+
if (Array.isArray(items))
|
|
93
|
+
return "unknown[]";
|
|
94
|
+
const inner = jsonSchemaToTs(items, indent);
|
|
95
|
+
return /[|&]/.test(inner) ? `Array<${inner}>` : `${inner}[]`;
|
|
96
|
+
}
|
|
97
|
+
case "object":
|
|
98
|
+
return objectShape(s, indent);
|
|
99
|
+
default:
|
|
100
|
+
if (s.properties && typeof s.properties === "object")
|
|
101
|
+
return objectShape(s, indent);
|
|
102
|
+
return "unknown";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function objectShape(schema, indent) {
|
|
106
|
+
const props = schema.properties && typeof schema.properties === "object" ? schema.properties : {};
|
|
107
|
+
const keys = Object.keys(props);
|
|
108
|
+
if (keys.length === 0) {
|
|
109
|
+
return schema.additionalProperties === false ? "Record<string, never>" : "Record<string, unknown>";
|
|
110
|
+
}
|
|
111
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
112
|
+
const inner = indent + " ";
|
|
113
|
+
const lines = ["{"];
|
|
114
|
+
for (const key of keys) {
|
|
115
|
+
const prop = props[key];
|
|
116
|
+
const desc = prop && typeof prop.description === "string" ? prop.description : undefined;
|
|
117
|
+
if (desc)
|
|
118
|
+
lines.push(`${inner}/** ${desc.replace(/\*\//g, "*\\/")} */`);
|
|
119
|
+
const optional = required.has(key) ? "" : "?";
|
|
120
|
+
const type = jsonSchemaToTs(prop, inner);
|
|
121
|
+
lines.push(`${inner}${safeIdent(key)}${optional}: ${type};`);
|
|
122
|
+
}
|
|
123
|
+
lines.push(`${indent}}`);
|
|
124
|
+
return lines.join(`
|
|
125
|
+
`);
|
|
126
|
+
}
|
|
127
|
+
function argsType(schema) {
|
|
128
|
+
if (!schema)
|
|
129
|
+
return "Record<string, unknown>";
|
|
130
|
+
const hasProps = schema.properties && Object.keys(schema.properties).length > 0;
|
|
131
|
+
if (!hasProps)
|
|
132
|
+
return "Record<string, unknown>";
|
|
133
|
+
return objectShape(schema, " ");
|
|
134
|
+
}
|
|
135
|
+
function methodHasRequiredArgs(schema) {
|
|
136
|
+
if (!schema || !schema.properties)
|
|
137
|
+
return false;
|
|
138
|
+
const req = Array.isArray(schema.required) ? schema.required : [];
|
|
139
|
+
return req.length > 0;
|
|
140
|
+
}
|
|
141
|
+
function formatDescription(desc, indent) {
|
|
142
|
+
if (!desc)
|
|
143
|
+
return "";
|
|
144
|
+
const cleaned = desc.replace(/\*\//g, "*\\/").trim();
|
|
145
|
+
if (!cleaned.includes(`
|
|
146
|
+
`))
|
|
147
|
+
return `${indent}/** ${cleaned} */
|
|
148
|
+
`;
|
|
149
|
+
const lines = cleaned.split(`
|
|
150
|
+
`).map((l) => `${indent} * ${l}`).join(`
|
|
151
|
+
`);
|
|
152
|
+
return `${indent}/**
|
|
153
|
+
${lines}
|
|
154
|
+
${indent} */
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
function generateCodeModeTypes(tools) {
|
|
158
|
+
const byIntegration = {};
|
|
159
|
+
for (const tool of tools) {
|
|
160
|
+
const integration = integrationFromToolName(tool.name);
|
|
161
|
+
(byIntegration[integration] ??= []).push(tool);
|
|
162
|
+
}
|
|
163
|
+
const methodMap = {};
|
|
164
|
+
const integrationCounts = {};
|
|
165
|
+
const sections = [];
|
|
166
|
+
const integrationIds = Object.keys(byIntegration).sort();
|
|
167
|
+
sections.push("/**");
|
|
168
|
+
sections.push(" * Integrate SDK — available APIs inside `execute_code`.");
|
|
169
|
+
sections.push(" * Every method is async and returns the MCP tool-call response.");
|
|
170
|
+
sections.push(" * Call them via the exported `client` object, e.g.");
|
|
171
|
+
sections.push(" * const repos = await client.github.listRepos();");
|
|
172
|
+
sections.push(" */");
|
|
173
|
+
sections.push("");
|
|
174
|
+
for (const integrationId of integrationIds) {
|
|
175
|
+
const integrationTools = byIntegration[integrationId].slice().sort((a, b) => a.name.localeCompare(b.name));
|
|
176
|
+
integrationCounts[integrationId] = integrationTools.length;
|
|
177
|
+
const interfaceName = pascalCase(integrationId) + "Client";
|
|
178
|
+
sections.push(`export interface ${interfaceName} {`);
|
|
179
|
+
for (const tool of integrationTools) {
|
|
180
|
+
const methodName = toolNameToMethod(tool.name);
|
|
181
|
+
methodMap[`${integrationId}.${methodName}`] = tool.name;
|
|
182
|
+
sections.push(formatDescription(tool.description, " "));
|
|
183
|
+
const argType = argsType(tool.inputSchema);
|
|
184
|
+
const argIsOptional = !methodHasRequiredArgs(tool.inputSchema);
|
|
185
|
+
const paramName = argIsOptional ? "args?" : "args";
|
|
186
|
+
sections.push(` ${safeIdent(methodName)}(${paramName}: ${argType}): Promise<ToolResult>;`);
|
|
187
|
+
}
|
|
188
|
+
sections.push("}");
|
|
189
|
+
sections.push("");
|
|
190
|
+
}
|
|
191
|
+
sections.push("export interface ToolResult {");
|
|
192
|
+
sections.push(" content: Array<{ type: 'text' | 'image' | 'resource'; text?: string; data?: string; mimeType?: string; [key: string]: unknown }>;");
|
|
193
|
+
sections.push(" isError?: boolean;");
|
|
194
|
+
sections.push(" structuredContent?: Record<string, unknown>;");
|
|
195
|
+
sections.push("}");
|
|
196
|
+
sections.push("");
|
|
197
|
+
sections.push("export interface Client {");
|
|
198
|
+
for (const integrationId of integrationIds) {
|
|
199
|
+
const interfaceName = pascalCase(integrationId) + "Client";
|
|
200
|
+
sections.push(` ${safeIdent(integrationId)}: ${interfaceName};`);
|
|
201
|
+
}
|
|
202
|
+
sections.push("}");
|
|
203
|
+
sections.push("");
|
|
204
|
+
sections.push("export declare const client: Client;");
|
|
205
|
+
return {
|
|
206
|
+
source: sections.filter((line, idx, arr) => !(line === "" && arr[idx - 1] === "")).join(`
|
|
207
|
+
`),
|
|
208
|
+
methodMap,
|
|
209
|
+
integrationCounts
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function pascalCase(id) {
|
|
213
|
+
return id.split(/[^A-Za-z0-9]/).filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("") || "Unknown";
|
|
214
|
+
}
|
|
215
|
+
export {
|
|
216
|
+
generateCodeModeTypes
|
|
217
|
+
};
|