@slashfi/agents-sdk 0.20.0 → 0.22.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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Serialized Agent Definition
3
+ *
4
+ * Pure-data, JSON-serializable representation of an agent.
5
+ * No execute functions, no runtime hooks — just schemas and metadata.
6
+ *
7
+ * This is the universal IR:
8
+ * - Codegen produces it (MCP introspection → SerializedAgentDefinition)
9
+ * - Registry stores it (JSON in DB or filesystem)
10
+ * - API serves it (GET /agents/:name → SerializedAgentDefinition)
11
+ * - createClient() hydrates it (definition → typed proxy with real calls)
12
+ */
13
+ import type { JsonSchema, SecurityScheme } from "./types.js";
14
+ export interface SerializedTool {
15
+ /** Tool name (unique within agent) */
16
+ name: string;
17
+ /** Short description for tool discovery */
18
+ description: string;
19
+ /** JSON Schema for input parameters */
20
+ inputSchema: JsonSchema;
21
+ /** JSON Schema for output (optional) */
22
+ outputSchema?: JsonSchema;
23
+ }
24
+ export interface SerializedAgentDefinition {
25
+ /** Agent path (e.g., 'notion', 'linear', 'github') */
26
+ path: string;
27
+ /** Human-readable name */
28
+ name: string;
29
+ /** Short description */
30
+ description: string;
31
+ /** Version of the definition */
32
+ version: string;
33
+ /** Visibility level */
34
+ visibility: "public" | "private";
35
+ /** Auth requirements */
36
+ auth?: SecurityScheme;
37
+ /** MCP server source command (e.g., 'npx @notionhq/notion-mcp-server') */
38
+ serverSource?: string;
39
+ /** Server info from MCP introspection */
40
+ serverInfo?: {
41
+ name: string;
42
+ version: string;
43
+ };
44
+ /** Tool definitions (schemas only, no execute) */
45
+ tools: SerializedTool[];
46
+ /** ISO timestamp of when this was generated */
47
+ generatedAt?: string;
48
+ /** SDK version used for codegen */
49
+ sdkVersion?: string;
50
+ }
51
+ import type { AgentDefinition, ToolContext, ToolDefinition } from "./types.js";
52
+ /**
53
+ * Serialize an AgentDefinition to its pure-data representation.
54
+ * Strips execute functions, runtime hooks, listeners, etc.
55
+ */
56
+ export declare function serializeAgent(agent: AgentDefinition, meta?: {
57
+ serverSource?: string;
58
+ version?: string;
59
+ }): SerializedAgentDefinition;
60
+ /**
61
+ * Serialize a single ToolDefinition to its pure-data representation.
62
+ */
63
+ export declare function serializeTool(tool: ToolDefinition<ToolContext, unknown, unknown>): SerializedTool;
64
+ //# sourceMappingURL=serialized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialized.d.ts","sourceRoot":"","sources":["../src/serialized.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAM7D,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,WAAW,EAAE,UAAU,CAAC;IACxB,wCAAwC;IACxC,YAAY,CAAC,EAAE,UAAU,CAAC;CAC3B;AAMD,MAAM,WAAW,yBAAyB;IACxC,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjC,wBAAwB;IACxB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,UAAU,CAAC,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,kDAAkD;IAClD,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE/E;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD,yBAAyB,CAY3B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,GAClD,cAAc,CAOhB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Serialized Agent Definition
3
+ *
4
+ * Pure-data, JSON-serializable representation of an agent.
5
+ * No execute functions, no runtime hooks — just schemas and metadata.
6
+ *
7
+ * This is the universal IR:
8
+ * - Codegen produces it (MCP introspection → SerializedAgentDefinition)
9
+ * - Registry stores it (JSON in DB or filesystem)
10
+ * - API serves it (GET /agents/:name → SerializedAgentDefinition)
11
+ * - createClient() hydrates it (definition → typed proxy with real calls)
12
+ */
13
+ /**
14
+ * Serialize an AgentDefinition to its pure-data representation.
15
+ * Strips execute functions, runtime hooks, listeners, etc.
16
+ */
17
+ export function serializeAgent(agent, meta) {
18
+ return {
19
+ path: agent.path,
20
+ name: agent.config?.name ?? agent.path,
21
+ description: agent.config?.description ?? "",
22
+ version: meta?.version ?? "1.0.0",
23
+ visibility: agent.visibility ?? "public",
24
+ auth: agent.config?.security,
25
+ serverSource: meta?.serverSource,
26
+ tools: agent.tools.map(serializeTool),
27
+ generatedAt: new Date().toISOString(),
28
+ };
29
+ }
30
+ /**
31
+ * Serialize a single ToolDefinition to its pure-data representation.
32
+ */
33
+ export function serializeTool(tool) {
34
+ return {
35
+ name: tool.name,
36
+ description: tool.description,
37
+ inputSchema: tool.inputSchema,
38
+ ...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
39
+ };
40
+ }
41
+ //# sourceMappingURL=serialized.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialized.js","sourceRoot":"","sources":["../src/serialized.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAyDH;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,IAAkD;IAElD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI;QACtC,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,IAAI,EAAE;QAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,OAAO;QACjC,UAAU,EAAG,KAAK,CAAC,UAAmC,IAAI,QAAQ;QAClE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ;QAC5B,YAAY,EAAE,IAAI,EAAE,YAAY;QAChC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC;QACrC,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAmD;IAEnD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slashfi/agents-sdk",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "author": "Slash Financial",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "main": "dist/index.js",
10
10
  "bin": {
11
- "agents-sdk": "./src/cli.ts"
11
+ "adk": "./src/adk.ts",
12
+ "agents-sdk": "./src/adk.ts"
12
13
  },
13
14
  "devDependencies": {
14
15
  "@biomejs/biome": "^1.9.4",
package/src/adk.ts ADDED
@@ -0,0 +1,398 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * ADK CLI — Agent Development Kit
4
+ *
5
+ * Unified CLI for building, testing, and publishing agent definitions.
6
+ *
7
+ * Commands:
8
+ * codegen Generate agent definitions from an MCP server (full codegen)
9
+ * introspect Introspect an MCP server → agent.json (lightweight)
10
+ * pack Generate publishable @agentdef/* package from agent.json
11
+ * publish Pack + npm publish to @agentdef/*
12
+ * use Execute a tool on a generated agent
13
+ * list List all generated agents
14
+ *
15
+ * @example
16
+ * ```bash
17
+ * # Full codegen from MCP server
18
+ * adk codegen --server 'npx @mcp/notion' --name notion --out ./agents/@notion
19
+ *
20
+ * # Lightweight introspect → agent.json
21
+ * adk introspect --server 'npx @notionhq/notion-mcp-server' --name notion
22
+ *
23
+ * # Build + publish
24
+ * adk pack
25
+ * adk publish
26
+ *
27
+ * # Use a tool
28
+ * adk use notion search_pages '{"query": "hello"}'
29
+ * adk use notion --list
30
+ * ```
31
+ */
32
+
33
+ import { existsSync, readdirSync } from "node:fs";
34
+ import { join, resolve } from "node:path";
35
+ import { codegen, listAgentTools, useAgent } from "./codegen.js";
36
+ import type { CodegenManifest } from "./codegen.js";
37
+ import { pack, publish } from "./pack.js";
38
+
39
+ const args = process.argv.slice(2);
40
+ const command = args[0];
41
+
42
+ // ============================================
43
+ // Helpers
44
+ // ============================================
45
+
46
+ function getArg(flag: string): string | undefined {
47
+ const idx = args.indexOf(flag);
48
+ if (idx === -1 || idx + 1 >= args.length) return undefined;
49
+ return args[idx + 1];
50
+ }
51
+
52
+ function hasFlag(flag: string): boolean {
53
+ return args.includes(flag);
54
+ }
55
+
56
+ function getAgentsDir(): string {
57
+ return resolve(process.env.AGENTS_SDK_DIR ?? "./agents");
58
+ }
59
+
60
+ function findAgentDir(name: string): string | null {
61
+ const agentsDir = getAgentsDir();
62
+
63
+ const exactPath = resolve(name);
64
+ if (existsSync(join(exactPath, ".codegen-manifest.json"))) return exactPath;
65
+
66
+ const withAt = join(agentsDir, `@${name}`);
67
+ if (existsSync(join(withAt, ".codegen-manifest.json"))) return withAt;
68
+
69
+ const withoutAt = join(agentsDir, name);
70
+ if (existsSync(join(withoutAt, ".codegen-manifest.json"))) return withoutAt;
71
+
72
+ return null;
73
+ }
74
+
75
+ function printUsage() {
76
+ console.log(`
77
+ adk — Agent Development Kit
78
+
79
+ Usage:
80
+ adk codegen [options] Generate agent from MCP server (full codegen)
81
+ adk introspect [options] Introspect MCP server → agent.json
82
+ adk pack [options] Generate publishable package from agent.json
83
+ adk publish [options] Pack + npm publish to @agentdef/*
84
+ adk use <agent> [options] Execute a tool on a generated agent
85
+ adk list List all generated agents
86
+
87
+ Codegen options:
88
+ --server <source> MCP server (command string or URL)
89
+ --name <name> Agent name (default: derived from server)
90
+ --out <dir> Output directory (default: ./agents/@<name>)
91
+ --path <path> Agent path override
92
+ --no-cli Skip CLI generation
93
+ --no-types Skip TypeScript interface generation
94
+ --visibility <level> Agent visibility (public|internal|private)
95
+
96
+ Introspect options:
97
+ --server <cmd> MCP server command to introspect
98
+ --name <name> Agent name for output
99
+ --out <path> Output path (default: ./<name>.json)
100
+
101
+ Pack / Publish options:
102
+ --agent <path> Path to agent.json (default: ./agent.json)
103
+ --out <dir> Output directory (default: ./dist)
104
+ --scope <scope> npm scope (default: @agentdef)
105
+ --previous <path> Previous agent.json for diff
106
+ --dry-run Don't actually publish (publish only)
107
+ --tag <tag> npm dist-tag (default: latest)
108
+ --access <level> npm access: public | restricted (default: public)
109
+
110
+ Use options:
111
+ adk use <agent> <tool> [params_json]
112
+ adk use <agent> --list List tools on the agent
113
+
114
+ Examples:
115
+ adk codegen --server 'npx @mcp/notion' --name notion
116
+ adk introspect --server 'npx @notionhq/notion-mcp-server' --name notion
117
+ adk pack --agent ./agent.json
118
+ adk publish --dry-run
119
+ adk use notion search_pages '{"query": "hello"}'
120
+ `);
121
+ }
122
+
123
+ // ============================================
124
+ // Commands
125
+ // ============================================
126
+
127
+ async function runCodegen() {
128
+ const server = getArg("--server");
129
+ const name = getArg("--name");
130
+ const outDir = getArg("--out");
131
+ const agentPath = getArg("--path");
132
+ const visibility = getArg("--visibility") as
133
+ | "public"
134
+ | "internal"
135
+ | "private"
136
+ | undefined;
137
+ const noCli = hasFlag("--no-cli");
138
+ const noTypes = hasFlag("--no-types");
139
+
140
+ if (!server) {
141
+ console.error(
142
+ "Error: --server is required.\n" +
143
+ " Example: adk codegen --server 'npx @mcp/notion' --name notion",
144
+ );
145
+ process.exit(1);
146
+ }
147
+
148
+ const resolvedOutDir =
149
+ outDir ??
150
+ join(
151
+ getAgentsDir(),
152
+ `@${(name ?? "mcp-agent").toLowerCase().replace(/[^a-z0-9-]/g, "-")}`,
153
+ );
154
+
155
+ console.log(`Connecting to MCP server: ${server}`);
156
+ console.log(`Output: ${resolvedOutDir}\n`);
157
+
158
+ try {
159
+ const result = await codegen({
160
+ server,
161
+ outDir: resolvedOutDir,
162
+ agentPath,
163
+ name,
164
+ cli: !noCli,
165
+ types: !noTypes,
166
+ visibility,
167
+ });
168
+
169
+ console.log(
170
+ `\x1b[32m\u2713\x1b[0m Generated ${result.toolCount} tools from ${result.serverInfo.name ?? "MCP server"}`,
171
+ );
172
+ console.log("\nFiles:");
173
+ for (const f of result.files) {
174
+ console.log(` ${f}`);
175
+ }
176
+ console.log(
177
+ `\nUse: adk use ${name ?? result.serverInfo.name ?? "<agent>"} --list`,
178
+ );
179
+ } catch (err) {
180
+ console.error(
181
+ `\x1b[31mError:\x1b[0m ${err instanceof Error ? err.message : String(err)}`,
182
+ );
183
+ process.exit(1);
184
+ }
185
+ }
186
+
187
+ async function runIntrospect() {
188
+ const server = getArg("--server");
189
+ const name = getArg("--name");
190
+ const out = getArg("--out") || (name ? `./${name}.json` : undefined);
191
+
192
+ if (!server || !name) {
193
+ console.error(
194
+ "Usage: adk introspect --server <cmd> --name <name> [--out <path>]",
195
+ );
196
+ process.exit(1);
197
+ }
198
+
199
+ const { introspectMcp } = await import("./introspect.js");
200
+ await introspectMcp({ server, name, out });
201
+ }
202
+
203
+ function runPack() {
204
+ const agentFile = getArg("--agent") || "./agent.json";
205
+ const outDir = getArg("--out") || "./dist";
206
+ const scope = getArg("--scope") || "@agentdef";
207
+ const previousAgentFile = getArg("--previous");
208
+
209
+ if (!existsSync(resolve(agentFile))) {
210
+ console.error(`agent.json not found at ${resolve(agentFile)}`);
211
+ console.error("Run 'adk introspect' first, or specify --agent <path>");
212
+ process.exit(1);
213
+ }
214
+
215
+ const result = pack({ agentFile, outDir, scope, previousAgentFile });
216
+ console.log(`\n\u2705 Packed ${result.packageName}@${result.version}`);
217
+ console.log(` Hash: ${result.hash}`);
218
+ console.log(` Tools: ${result.meta.toolCount}`);
219
+ console.log(` Size: ${(result.meta.sizeBytes / 1024).toFixed(1)}KB`);
220
+ console.log(` Output: ${result.packageDir}`);
221
+ if (result.meta.changes) {
222
+ const c = result.meta.changes;
223
+ if (c.toolsAdded.length > 0)
224
+ console.log(` Added: ${c.toolsAdded.join(", ")}`);
225
+ if (c.toolsRemoved.length > 0)
226
+ console.log(` Removed: ${c.toolsRemoved.join(", ")}`);
227
+ if (c.toolsModified.length > 0)
228
+ console.log(` Modified: ${c.toolsModified.join(", ")}`);
229
+ }
230
+ }
231
+
232
+ function runPublish() {
233
+ const agentFile = getArg("--agent") || "./agent.json";
234
+ const outDir = getArg("--out") || "./dist";
235
+ const scope = getArg("--scope") || "@agentdef";
236
+ const previousAgentFile = getArg("--previous");
237
+ const dryRun = hasFlag("--dry-run");
238
+ const tag = getArg("--tag");
239
+ const access = getArg("--access") as "public" | "restricted" | undefined;
240
+ const registry = getArg("--registry");
241
+
242
+ if (!existsSync(resolve(agentFile))) {
243
+ console.error(`agent.json not found at ${resolve(agentFile)}`);
244
+ console.error("Run 'adk introspect' first, or specify --agent <path>");
245
+ process.exit(1);
246
+ }
247
+
248
+ try {
249
+ const result = publish({
250
+ agentFile,
251
+ outDir,
252
+ scope,
253
+ previousAgentFile,
254
+ dryRun,
255
+ tag,
256
+ access,
257
+ registry,
258
+ });
259
+ console.log(
260
+ `\n\u2705 Published ${result.packageName}@${result.version} (hash: ${result.hash})`,
261
+ );
262
+ } catch (err) {
263
+ console.error(err instanceof Error ? err.message : String(err));
264
+ process.exit(1);
265
+ }
266
+ }
267
+
268
+ async function runUse() {
269
+ const agentName = args[1];
270
+
271
+ if (!agentName) {
272
+ console.error(
273
+ "Error: agent name required.\n" +
274
+ " Example: adk use notion search_pages '{...}'",
275
+ );
276
+ process.exit(1);
277
+ }
278
+
279
+ const agentDir = findAgentDir(agentName);
280
+ if (!agentDir) {
281
+ console.error(
282
+ `Error: agent '${agentName}' not found.\n` +
283
+ ` Looked in: ${getAgentsDir()}\n` +
284
+ ` Generate first: adk codegen --server '...' --name ${agentName}`,
285
+ );
286
+ process.exit(1);
287
+ }
288
+
289
+ if (hasFlag("--list")) {
290
+ const tools = listAgentTools(agentDir);
291
+ console.log(`Tools for ${agentName}:\n`);
292
+ for (const t of tools) {
293
+ console.log(` ${t.name.padEnd(30)} ${t.description ?? ""}`);
294
+ }
295
+ return;
296
+ }
297
+
298
+ const toolName = args[2];
299
+ if (!toolName) {
300
+ console.error(
301
+ `Error: tool name required.\n Example: adk use ${agentName} <tool> [params]\n List tools: adk use ${agentName} --list`,
302
+ );
303
+ process.exit(1);
304
+ }
305
+
306
+ const paramsStr = args[3];
307
+ const params = paramsStr ? JSON.parse(paramsStr) : {};
308
+
309
+ try {
310
+ const result = await useAgent({
311
+ agentDir,
312
+ tool: toolName,
313
+ params,
314
+ });
315
+ console.log(JSON.stringify(result, null, 2));
316
+ } catch (err) {
317
+ console.error(
318
+ `\x1b[31mError:\x1b[0m ${err instanceof Error ? err.message : String(err)}`,
319
+ );
320
+ process.exit(1);
321
+ }
322
+ }
323
+
324
+ function runList() {
325
+ const agentsDir = getAgentsDir();
326
+
327
+ if (!existsSync(agentsDir)) {
328
+ console.log("No generated agents found.");
329
+ return;
330
+ }
331
+
332
+ const entries = readdirSync(agentsDir);
333
+ const agents: { name: string; tools: number; server?: string }[] = [];
334
+
335
+ for (const entry of entries) {
336
+ const manifestPath = join(agentsDir, entry, ".codegen-manifest.json");
337
+ if (existsSync(manifestPath)) {
338
+ try {
339
+ const manifest: CodegenManifest = JSON.parse(
340
+ require("node:fs").readFileSync(manifestPath, "utf-8"),
341
+ );
342
+ agents.push({
343
+ name: manifest.agentPath,
344
+ tools: manifest.tools.length,
345
+ server: manifest.serverInfo.name,
346
+ });
347
+ } catch {
348
+ agents.push({ name: entry, tools: 0 });
349
+ }
350
+ }
351
+ }
352
+
353
+ if (agents.length === 0) {
354
+ console.log("No generated agents found.");
355
+ return;
356
+ }
357
+
358
+ console.log("Generated agents:\n");
359
+ for (const a of agents) {
360
+ console.log(
361
+ ` ${a.name.padEnd(25)} ${String(a.tools).padEnd(5)} tools${a.server ? ` (${a.server})` : ""}`,
362
+ );
363
+ }
364
+ }
365
+
366
+ // ============================================
367
+ // Main
368
+ // ============================================
369
+
370
+ switch (command) {
371
+ case "codegen":
372
+ await runCodegen();
373
+ break;
374
+ case "introspect":
375
+ await runIntrospect();
376
+ break;
377
+ case "pack":
378
+ runPack();
379
+ break;
380
+ case "publish":
381
+ runPublish();
382
+ break;
383
+ case "use":
384
+ await runUse();
385
+ break;
386
+ case "list":
387
+ runList();
388
+ break;
389
+ case "--help":
390
+ case "-h":
391
+ case undefined:
392
+ printUsage();
393
+ break;
394
+ default:
395
+ console.error(`Unknown command: ${command}`);
396
+ printUsage();
397
+ process.exit(1);
398
+ }