@slashfi/agents-sdk 0.50.6 → 0.60.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,158 @@
1
+ /**
2
+ * Ref Materialization — Download agent docs to local filesystem.
3
+ *
4
+ * When `adk ref add` succeeds, materialize the agent's tool schemas,
5
+ * resources (skills), and generate TypeScript type definitions locally.
6
+ *
7
+ * Files are written under the adk config dir at refs/<name>/.
8
+ */
9
+
10
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
11
+ import { dirname, join } from "node:path";
12
+ import type { Adk } from "./config-store.js";
13
+ // No init imports needed — materialize is self-contained
14
+
15
+ // ============================================
16
+ // Types
17
+ // ============================================
18
+
19
+ interface ToolSchema {
20
+ name: string;
21
+ description?: string;
22
+ inputSchema?: Record<string, unknown>;
23
+ outputSchema?: Record<string, unknown>;
24
+ }
25
+
26
+ interface MaterializeResult {
27
+ toolCount: number;
28
+ skillCount: number;
29
+ typesGenerated: boolean;
30
+ }
31
+
32
+ // ============================================
33
+ // Helpers
34
+ // ============================================
35
+
36
+ function ensureWrite(path: string, content: string): void {
37
+ const dir = dirname(path);
38
+ if (!existsSync(dir)) {
39
+ mkdirSync(dir, { recursive: true });
40
+ }
41
+ writeFileSync(path, content, "utf-8");
42
+ }
43
+
44
+ /** Generate a .d.ts file from tool schemas. */
45
+ function generateTypes(refName: string, tools: ToolSchema[]): string {
46
+ const lines: string[] = [
47
+ `// Auto-generated by adk ref add`,
48
+ `// Agent: ${refName}`,
49
+ `// Tools: ${tools.length}`,
50
+ ``,
51
+ `export interface ${pascalCase(refName)}Tools {`,
52
+ ];
53
+
54
+ for (const tool of tools) {
55
+ lines.push(` /** ${tool.description ?? tool.name} */`);
56
+ lines.push(` ${JSON.stringify(tool.name)}: {`);
57
+ lines.push(` name: ${JSON.stringify(tool.name)};`);
58
+ if (tool.description) {
59
+ lines.push(` description: ${JSON.stringify(tool.description)};`);
60
+ }
61
+ lines.push(` params: Record<string, unknown>;`);
62
+ lines.push(` };`);
63
+ }
64
+
65
+ lines.push(`}`);
66
+ lines.push(``);
67
+ lines.push(`export declare const tools: (keyof ${pascalCase(refName)}Tools)[];`);
68
+ lines.push(``);
69
+ return lines.join("\n");
70
+ }
71
+
72
+ function pascalCase(s: string): string {
73
+ return s
74
+ .replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase())
75
+ .replace(/^./, (c) => c.toUpperCase());
76
+ }
77
+
78
+ // ============================================
79
+ // Materialize
80
+ // ============================================
81
+
82
+ export async function materializeRef(
83
+ adk: Adk,
84
+ refName: string,
85
+ configDir: string,
86
+ ): Promise<MaterializeResult> {
87
+ const refDir = join(configDir, "refs", refName);
88
+ const toolsDir = join(refDir, "tools");
89
+ const skillsDir = join(refDir, "skills");
90
+ const typesDir = join(refDir, "types");
91
+
92
+ let toolCount = 0;
93
+ let skillCount = 0;
94
+ let typesGenerated = false;
95
+
96
+ // 1. Fetch and write tool schemas
97
+ try {
98
+ const info = await adk.ref.inspect(refName, { full: true });
99
+ if (info?.tools && info.tools.length > 0) {
100
+ const tools: ToolSchema[] = info.tools.map((t: any) => ({
101
+ name: t.name,
102
+ description: t.description,
103
+ inputSchema: t.inputSchema,
104
+ outputSchema: t.outputSchema,
105
+ }));
106
+
107
+ for (const tool of tools) {
108
+ const safeName = tool.name.replace(/[^a-zA-Z0-9_-]/g, "_");
109
+ ensureWrite(
110
+ join(toolsDir, `${safeName}.tool.json`),
111
+ JSON.stringify(tool, null, 2),
112
+ );
113
+ }
114
+ toolCount = tools.length;
115
+
116
+ // Write agent.json metadata
117
+ ensureWrite(
118
+ join(refDir, "agent.json"),
119
+ JSON.stringify({
120
+ name: refName,
121
+ description: info.description,
122
+ toolCount: tools.length,
123
+ tools: tools.map((t) => t.name),
124
+ materializedAt: new Date().toISOString(),
125
+ }, null, 2),
126
+ );
127
+
128
+ // Generate .d.ts
129
+ ensureWrite(
130
+ join(typesDir, `${refName}.d.ts`),
131
+ generateTypes(refName, tools),
132
+ );
133
+ typesGenerated = true;
134
+ }
135
+ } catch {
136
+ // inspect failed — agent might not be reachable yet (needs auth)
137
+ }
138
+
139
+ // 2. Fetch and write resources (skills)
140
+ try {
141
+ const resourcesResult = await adk.ref.resources(refName);
142
+ const response = resourcesResult as any;
143
+ if (response?.result?.resources) {
144
+ for (const resource of response.result.resources) {
145
+ if (resource.uri && resource.text) {
146
+ const filename = resource.uri.split("/").pop() ?? "resource.md";
147
+ ensureWrite(join(skillsDir, filename), resource.text);
148
+ skillCount++;
149
+ }
150
+ }
151
+ }
152
+ } catch {
153
+ // resources fetch failed — might not be supported
154
+ }
155
+
156
+ return { toolCount, skillCount, typesGenerated };
157
+ }
158
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "claude",
3
+ "defaultPath": "~/.claude/skills",
4
+ "filename": "adk/SKILL.md"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "codex",
3
+ "defaultPath": ".agents/skills",
4
+ "filename": "adk/SKILL.md"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "copilot",
3
+ "defaultPath": ".github/skills",
4
+ "filename": "adk/SKILL.md"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "cursor",
3
+ "defaultPath": ".agents/skills",
4
+ "filename": "adk/SKILL.md"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "hermes",
3
+ "defaultPath": "~/.hermes/skills",
4
+ "filename": "adk/SKILL.md"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "windsurf",
3
+ "defaultPath": ".windsurf/skills",
4
+ "filename": "adk/SKILL.md"
5
+ }