@vertesia/tools-sdk 0.80.0-dev.20251121 → 0.80.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.
Files changed (61) hide show
  1. package/README.md +122 -0
  2. package/lib/cjs/InteractionCollection.js +118 -0
  3. package/lib/cjs/InteractionCollection.js.map +1 -1
  4. package/lib/cjs/SkillCollection.js +318 -0
  5. package/lib/cjs/SkillCollection.js.map +1 -0
  6. package/lib/cjs/ToolCollection.js +98 -0
  7. package/lib/cjs/ToolCollection.js.map +1 -1
  8. package/lib/cjs/copy-assets.js +84 -0
  9. package/lib/cjs/copy-assets.js.map +1 -0
  10. package/lib/cjs/index.js +6 -1
  11. package/lib/cjs/index.js.map +1 -1
  12. package/lib/cjs/server.js +327 -0
  13. package/lib/cjs/server.js.map +1 -0
  14. package/lib/cjs/site/styles.js +621 -0
  15. package/lib/cjs/site/styles.js.map +1 -0
  16. package/lib/cjs/site/templates.js +932 -0
  17. package/lib/cjs/site/templates.js.map +1 -0
  18. package/lib/esm/InteractionCollection.js +83 -0
  19. package/lib/esm/InteractionCollection.js.map +1 -1
  20. package/lib/esm/SkillCollection.js +311 -0
  21. package/lib/esm/SkillCollection.js.map +1 -0
  22. package/lib/esm/ToolCollection.js +64 -0
  23. package/lib/esm/ToolCollection.js.map +1 -1
  24. package/lib/esm/copy-assets.js +81 -0
  25. package/lib/esm/copy-assets.js.map +1 -0
  26. package/lib/esm/index.js +4 -0
  27. package/lib/esm/index.js.map +1 -1
  28. package/lib/esm/server.js +323 -0
  29. package/lib/esm/server.js.map +1 -0
  30. package/lib/esm/site/styles.js +618 -0
  31. package/lib/esm/site/styles.js.map +1 -0
  32. package/lib/esm/site/templates.js +920 -0
  33. package/lib/esm/site/templates.js.map +1 -0
  34. package/lib/types/InteractionCollection.d.ts +29 -0
  35. package/lib/types/InteractionCollection.d.ts.map +1 -1
  36. package/lib/types/SkillCollection.d.ts +111 -0
  37. package/lib/types/SkillCollection.d.ts.map +1 -0
  38. package/lib/types/ToolCollection.d.ts +18 -0
  39. package/lib/types/ToolCollection.d.ts.map +1 -1
  40. package/lib/types/copy-assets.d.ts +14 -0
  41. package/lib/types/copy-assets.d.ts.map +1 -0
  42. package/lib/types/index.d.ts +4 -0
  43. package/lib/types/index.d.ts.map +1 -1
  44. package/lib/types/server.d.ts +72 -0
  45. package/lib/types/server.d.ts.map +1 -0
  46. package/lib/types/site/styles.d.ts +5 -0
  47. package/lib/types/site/styles.d.ts.map +1 -0
  48. package/lib/types/site/templates.d.ts +54 -0
  49. package/lib/types/site/templates.d.ts.map +1 -0
  50. package/lib/types/types.d.ts +152 -0
  51. package/lib/types/types.d.ts.map +1 -1
  52. package/package.json +18 -5
  53. package/src/InteractionCollection.ts +90 -0
  54. package/src/SkillCollection.ts +389 -0
  55. package/src/ToolCollection.ts +68 -0
  56. package/src/copy-assets.ts +104 -0
  57. package/src/index.ts +4 -0
  58. package/src/server.ts +444 -0
  59. package/src/site/styles.ts +617 -0
  60. package/src/site/templates.ts +956 -0
  61. package/src/types.ts +162 -0
@@ -1,3 +1,6 @@
1
+ import { readdirSync, statSync, existsSync, readFileSync } from "fs";
2
+ import { join } from "path";
3
+ import { pathToFileURL } from "url";
1
4
  import { InteractionSpec } from "@vertesia/common";
2
5
  import { ICollection, CollectionProperties } from "./types.js";
3
6
  import { kebabCaseToTitle } from "./utils.js";
@@ -51,3 +54,90 @@ export class InteractionCollection implements ICollection<InteractionSpec> {
51
54
  return this.interactions.find(interaction => interaction.name === name);
52
55
  }
53
56
  }
57
+
58
+ /**
59
+ * Load all interactions from a directory.
60
+ * Scans for subdirectories containing index.ts/index.js files.
61
+ *
62
+ * Directory structure:
63
+ * ```
64
+ * interactions/
65
+ * nagare/
66
+ * extract-fund-actuals/
67
+ * index.ts # exports default InteractionSpec
68
+ * prompt.jst # prompt template (read via readPromptFile helper)
69
+ * parse-fund-document/
70
+ * index.ts
71
+ * prompt.md
72
+ * ```
73
+ *
74
+ * @param interactionsDir - Path to the interactions collection directory
75
+ * @returns Promise resolving to array of InteractionSpec objects
76
+ */
77
+ export async function loadInteractionsFromDirectory(interactionsDir: string): Promise<InteractionSpec[]> {
78
+ const interactions: InteractionSpec[] = [];
79
+
80
+ if (!existsSync(interactionsDir)) {
81
+ console.warn(`Interactions directory not found: ${interactionsDir}`);
82
+ return interactions;
83
+ }
84
+
85
+ let entries: string[];
86
+ try {
87
+ entries = readdirSync(interactionsDir);
88
+ } catch {
89
+ console.warn(`Could not read interactions directory: ${interactionsDir}`);
90
+ return interactions;
91
+ }
92
+
93
+ for (const entry of entries) {
94
+ // Skip hidden files and index files
95
+ if (entry.startsWith('.')) continue;
96
+ if (entry === 'index.ts' || entry === 'index.js') continue;
97
+
98
+ const entryPath = join(interactionsDir, entry);
99
+
100
+ try {
101
+ const stat = statSync(entryPath);
102
+ if (!stat.isDirectory()) continue;
103
+
104
+ // Look for index.ts or index.js in the subdirectory
105
+ const indexTs = join(entryPath, 'index.ts');
106
+ const indexJs = join(entryPath, 'index.js');
107
+ const indexPath = existsSync(indexTs) ? indexTs : existsSync(indexJs) ? indexJs : null;
108
+
109
+ if (!indexPath) {
110
+ continue; // No index file, skip
111
+ }
112
+
113
+ // Dynamic import
114
+ const fileUrl = pathToFileURL(indexPath).href;
115
+ const module = await import(fileUrl);
116
+
117
+ const interaction = module.default || module.interaction;
118
+
119
+ if (interaction && typeof interaction.name === 'string') {
120
+ interactions.push(interaction);
121
+ } else {
122
+ console.warn(`No valid InteractionSpec export found in ${entry}/index`);
123
+ }
124
+ } catch (err) {
125
+ console.warn(`Error loading interaction from ${entry}:`, err);
126
+ }
127
+ }
128
+
129
+ return interactions;
130
+ }
131
+
132
+ /**
133
+ * Helper to read a prompt file from the same directory as the interaction.
134
+ * Use this in interaction index.ts files to load prompt templates.
135
+ *
136
+ * @param dirname - Pass __dirname or dirname(fileURLToPath(import.meta.url))
137
+ * @param filename - Prompt filename (e.g., 'prompt.jst' or 'prompt.md')
138
+ * @returns File contents as string
139
+ */
140
+ export function readPromptFile(dirname: string, filename: string): string {
141
+ const filePath = join(dirname, filename);
142
+ return readFileSync(filePath, 'utf-8');
143
+ }
@@ -0,0 +1,389 @@
1
+ import { readdirSync, statSync, existsSync, readFileSync } from "fs";
2
+ import { join } from "path";
3
+ import { ToolDefinition } from "@llumiverse/common";
4
+ import { Context } from "hono";
5
+ import { HTTPException } from "hono/http-exception";
6
+ import type {
7
+ CollectionProperties,
8
+ ICollection,
9
+ SkillContentType,
10
+ SkillDefinition,
11
+ SkillExecutionResult,
12
+ ToolCollectionDefinition,
13
+ ToolExecutionPayload,
14
+ ToolExecutionResult,
15
+ } from "./types.js";
16
+ import { kebabCaseToTitle } from "./utils.js";
17
+
18
+ export interface SkillCollectionProperties extends CollectionProperties {
19
+ /**
20
+ * The skills in this collection
21
+ */
22
+ skills: SkillDefinition[];
23
+ }
24
+
25
+ /**
26
+ * Implements a skills collection endpoint.
27
+ * Skills provide contextual instructions to agents.
28
+ * They can be static (markdown) or dynamic (JST templates).
29
+ */
30
+ export class SkillCollection implements ICollection<SkillDefinition> {
31
+ /**
32
+ * A kebab case collection name
33
+ */
34
+ name: string;
35
+ /**
36
+ * Optional title for UI display
37
+ */
38
+ title?: string;
39
+ /**
40
+ * Optional icon for UI display
41
+ */
42
+ icon?: string;
43
+ /**
44
+ * A short description
45
+ */
46
+ description?: string;
47
+ /**
48
+ * The skills in this collection
49
+ */
50
+ private skills: Map<string, SkillDefinition>;
51
+
52
+ constructor({ name, title, icon, description, skills }: SkillCollectionProperties) {
53
+ this.name = name;
54
+ this.title = title || kebabCaseToTitle(name);
55
+ this.icon = icon;
56
+ this.description = description;
57
+ this.skills = new Map(skills.map(s => [s.name, s]));
58
+ }
59
+
60
+ [Symbol.iterator](): Iterator<SkillDefinition> {
61
+ return this.skills.values();
62
+ }
63
+
64
+ map<U>(callback: (skill: SkillDefinition, index: number) => U): U[] {
65
+ return Array.from(this.skills.values()).map(callback);
66
+ }
67
+
68
+ /**
69
+ * Get a skill by name
70
+ */
71
+ getSkill(name: string): SkillDefinition | undefined {
72
+ return this.skills.get(name);
73
+ }
74
+
75
+ /**
76
+ * Get all skill definitions
77
+ */
78
+ getSkillDefinitions(): SkillDefinition[] {
79
+ return Array.from(this.skills.values());
80
+ }
81
+
82
+ /**
83
+ * Get skills exposed as tool definitions.
84
+ * This allows skills to appear alongside regular tools.
85
+ * When called, they return rendered instructions.
86
+ */
87
+ getToolDefinitions(): ToolDefinition[] {
88
+ const defaultSchema: ToolDefinition['input_schema'] = {
89
+ type: 'object',
90
+ properties: {
91
+ context: {
92
+ type: "string",
93
+ description: "Additional context or specific requirements for this task"
94
+ }
95
+ }
96
+ };
97
+
98
+ return Array.from(this.skills.values()).map(skill => ({
99
+ name: `skill_${skill.name}`,
100
+ description: `[Skill] ${skill.description}. Returns contextual instructions for this task.`,
101
+ input_schema: skill.input_schema || defaultSchema
102
+ }));
103
+ }
104
+
105
+ /**
106
+ * Get as a tool collection definition (for listing alongside tools)
107
+ */
108
+ getAsToolCollection(baseUrl: string): ToolCollectionDefinition {
109
+ return {
110
+ title: this.title || this.name,
111
+ description: this.description || `Skills: ${this.name}`,
112
+ src: `${baseUrl}/api/skills/${this.name}`,
113
+ tools: this.getToolDefinitions()
114
+ };
115
+ }
116
+
117
+ /**
118
+ * Execute a skill - accepts standard tool execution payload.
119
+ * Returns rendered instructions in tool result format.
120
+ */
121
+ async execute(ctx: Context): Promise<Response> {
122
+ let payload: ToolExecutionPayload<Record<string, any>> | undefined;
123
+ try {
124
+ payload = await ctx.req.json() as ToolExecutionPayload<Record<string, any>>;
125
+ const toolName = payload.tool_use.tool_name;
126
+
127
+ // Extract skill name from tool name (remove "skill_" prefix if present)
128
+ const skillName = toolName.startsWith('skill_')
129
+ ? toolName.slice(6)
130
+ : toolName;
131
+
132
+ const skill = this.skills.get(skillName);
133
+
134
+ if (!skill) {
135
+ throw new HTTPException(404, {
136
+ message: `Skill not found: ${skillName}`
137
+ });
138
+ }
139
+
140
+ const data = payload.tool_use.tool_input || {};
141
+ const result = await this.renderSkill(skill, data);
142
+
143
+ // TODO: If skill.execution is set, run via Daytona
144
+
145
+ // Return in tool result format
146
+ return ctx.json({
147
+ tool_use_id: payload.tool_use.id,
148
+ is_error: false,
149
+ content: result.instructions,
150
+ meta: {
151
+ skill_name: skill.name,
152
+ content_type: skill.content_type,
153
+ execution: skill.execution,
154
+ }
155
+ } satisfies ToolExecutionResult & { tool_use_id: string });
156
+ } catch (err: any) {
157
+ const status = err.status || 500;
158
+ return ctx.json({
159
+ tool_use_id: payload?.tool_use?.id || "unknown",
160
+ is_error: true,
161
+ content: err.message || "Error executing skill",
162
+ }, status);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Render skill instructions (static or dynamic)
168
+ */
169
+ private async renderSkill(
170
+ skill: SkillDefinition,
171
+ _data: Record<string, unknown>
172
+ ): Promise<SkillExecutionResult> {
173
+ const instructions = skill.instructions;
174
+
175
+ if (skill.content_type === 'jst') {
176
+ // JST templates are not currently supported
177
+ throw new HTTPException(501, {
178
+ message: `JST templates are not currently supported. Use 'md' content type instead.`
179
+ });
180
+ }
181
+
182
+ return {
183
+ name: skill.name,
184
+ instructions,
185
+ };
186
+ }
187
+ }
188
+
189
+ // ================== Skill Parser ==================
190
+
191
+ interface SkillFrontmatter {
192
+ name: string;
193
+ title?: string;
194
+ description: string;
195
+ keywords?: string[];
196
+ tools?: string[];
197
+ data_patterns?: string[];
198
+ language?: string;
199
+ packages?: string[];
200
+ system_packages?: string[];
201
+ }
202
+
203
+ /**
204
+ * Parse a SKILL.md or SKILL.jst file content into a SkillDefinition.
205
+ *
206
+ * Format:
207
+ * ```
208
+ * ---
209
+ * name: skill-name
210
+ * description: Short description
211
+ * keywords: [keyword1, keyword2]
212
+ * tools: [tool1, tool2]
213
+ * language: python
214
+ * packages: [numpy, pandas]
215
+ * ---
216
+ *
217
+ * # Instructions
218
+ *
219
+ * Your markdown/jst content here...
220
+ * ```
221
+ */
222
+ export function parseSkillFile(
223
+ content: string,
224
+ contentType: SkillContentType
225
+ ): SkillDefinition {
226
+ // Parse YAML frontmatter
227
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
228
+
229
+ if (!frontmatterMatch) {
230
+ throw new Error("Invalid skill file: missing YAML frontmatter");
231
+ }
232
+
233
+ const [, yamlContent, body] = frontmatterMatch;
234
+ const frontmatter = parseYamlFrontmatter(yamlContent);
235
+ const instructions = body.trim();
236
+
237
+ if (!frontmatter.name) {
238
+ throw new Error("Skill file missing required 'name' field");
239
+ }
240
+ if (!frontmatter.description) {
241
+ throw new Error("Skill file missing required 'description' field");
242
+ }
243
+
244
+ const skill: SkillDefinition = {
245
+ name: frontmatter.name,
246
+ title: frontmatter.title,
247
+ description: frontmatter.description,
248
+ instructions,
249
+ content_type: contentType,
250
+ };
251
+
252
+ // Build context triggers
253
+ if (frontmatter.keywords || frontmatter.tools || frontmatter.data_patterns) {
254
+ skill.context_triggers = {
255
+ keywords: frontmatter.keywords,
256
+ tool_names: frontmatter.tools,
257
+ data_patterns: frontmatter.data_patterns,
258
+ };
259
+ }
260
+
261
+ // Build execution config
262
+ if (frontmatter.language) {
263
+ skill.execution = {
264
+ language: frontmatter.language,
265
+ packages: frontmatter.packages,
266
+ system_packages: frontmatter.system_packages,
267
+ };
268
+
269
+ // Extract code template from instructions if present
270
+ const codeBlockMatch = instructions.match(/```(?:python|javascript|typescript|js|ts|py)\n([\s\S]*?)```/);
271
+ if (codeBlockMatch) {
272
+ skill.execution.template = codeBlockMatch[1].trim();
273
+ }
274
+ }
275
+
276
+ // Related tools from frontmatter
277
+ if (frontmatter.tools) {
278
+ skill.related_tools = frontmatter.tools;
279
+ }
280
+
281
+ return skill;
282
+ }
283
+
284
+ /**
285
+ * Simple YAML frontmatter parser (handles basic key: value and arrays)
286
+ */
287
+ function parseYamlFrontmatter(yaml: string): SkillFrontmatter {
288
+ const result: Record<string, any> = {};
289
+ const lines = yaml.split('\n');
290
+
291
+ for (const line of lines) {
292
+ const trimmed = line.trim();
293
+ if (!trimmed || trimmed.startsWith('#')) continue;
294
+
295
+ const colonIndex = trimmed.indexOf(':');
296
+ if (colonIndex === -1) continue;
297
+
298
+ const key = trimmed.slice(0, colonIndex).trim();
299
+ let value = trimmed.slice(colonIndex + 1).trim();
300
+
301
+ // Handle array syntax: [item1, item2]
302
+ if (value.startsWith('[') && value.endsWith(']')) {
303
+ const items = value.slice(1, -1).split(',').map(s => s.trim());
304
+ result[key] = items.filter(s => s.length > 0);
305
+ } else {
306
+ // Remove quotes if present
307
+ if ((value.startsWith('"') && value.endsWith('"')) ||
308
+ (value.startsWith("'") && value.endsWith("'"))) {
309
+ value = value.slice(1, -1);
310
+ }
311
+ result[key] = value;
312
+ }
313
+ }
314
+
315
+ return result as SkillFrontmatter;
316
+ }
317
+
318
+ /**
319
+ * Helper to load skill from file path (for Node.js usage)
320
+ */
321
+ export async function loadSkillFromFile(
322
+ filePath: string,
323
+ fs: { readFile: (path: string, encoding: string) => Promise<string> }
324
+ ): Promise<SkillDefinition> {
325
+ const content = await fs.readFile(filePath, 'utf-8');
326
+ const contentType: SkillContentType = filePath.endsWith('.jst') ? 'jst' : 'md';
327
+ return parseSkillFile(content, contentType);
328
+ }
329
+
330
+ /**
331
+ * Load all skills from a directory.
332
+ * Scans for subdirectories containing SKILL.md files.
333
+ *
334
+ * Directory structure:
335
+ * ```
336
+ * skills/
337
+ * nagare/
338
+ * fund-onboarding/
339
+ * SKILL.md
340
+ * monte-carlo/
341
+ * SKILL.md
342
+ * ```
343
+ *
344
+ * @param dirPath - Path to the skills collection directory
345
+ * @returns Array of parsed skill definitions
346
+ */
347
+ export function loadSkillsFromDirectory(dirPath: string): SkillDefinition[] {
348
+ const skills: SkillDefinition[] = [];
349
+
350
+ let entries: string[];
351
+ try {
352
+ entries = readdirSync(dirPath);
353
+ } catch {
354
+ console.warn(`Could not read skills directory: ${dirPath}`);
355
+ return skills;
356
+ }
357
+
358
+ for (const entry of entries) {
359
+ const entryPath = join(dirPath, entry);
360
+
361
+ try {
362
+ const stat = statSync(entryPath);
363
+ if (!stat.isDirectory()) continue;
364
+
365
+ // Look for SKILL.md or SKILL.jst
366
+ const mdPath = join(entryPath, "SKILL.md");
367
+ const jstPath = join(entryPath, "SKILL.jst");
368
+
369
+ let content: string | undefined;
370
+ let contentType: SkillContentType = 'md';
371
+
372
+ if (existsSync(mdPath)) {
373
+ content = readFileSync(mdPath, "utf-8");
374
+ contentType = 'md';
375
+ } else if (existsSync(jstPath)) {
376
+ content = readFileSync(jstPath, "utf-8");
377
+ contentType = 'jst';
378
+ }
379
+
380
+ if (content) {
381
+ skills.push(parseSkillFile(content, contentType));
382
+ }
383
+ } catch (err) {
384
+ console.warn(`Error loading skill from ${entryPath}:`, err);
385
+ }
386
+ }
387
+
388
+ return skills;
389
+ }
@@ -1,3 +1,6 @@
1
+ import { readdirSync, statSync, existsSync } from "fs";
2
+ import { join } from "path";
3
+ import { pathToFileURL } from "url";
1
4
  import { Context } from "hono";
2
5
  import { HTTPException } from "hono/http-exception";
3
6
  import { authorize } from "./auth.js";
@@ -107,3 +110,68 @@ async function readPayload(ctx: Context) {
107
110
  }
108
111
  }
109
112
 
113
+ /**
114
+ * Load all tools from a directory.
115
+ * Scans for .js files and imports tools that match naming convention.
116
+ *
117
+ * Directory structure:
118
+ * ```
119
+ * collection/
120
+ * tools/
121
+ * SearchFundsTool.js # exports SearchFundsTool
122
+ * GetFundDetailsTool.js # exports GetFundDetailsTool
123
+ * ```
124
+ *
125
+ * Naming convention: File should export a Tool with name matching *Tool pattern.
126
+ *
127
+ * @param toolsDir - Path to the tools directory (e.g., /path/to/collection/tools)
128
+ * @returns Promise resolving to array of Tool objects
129
+ */
130
+ export async function loadToolsFromDirectory(toolsDir: string): Promise<Tool<any>[]> {
131
+ const tools: Tool<any>[] = [];
132
+
133
+ if (!existsSync(toolsDir)) {
134
+ console.warn(`Tools directory not found: ${toolsDir}`);
135
+ return tools;
136
+ }
137
+
138
+ let entries: string[];
139
+ try {
140
+ entries = readdirSync(toolsDir);
141
+ } catch {
142
+ console.warn(`Could not read tools directory: ${toolsDir}`);
143
+ return tools;
144
+ }
145
+
146
+ for (const entry of entries) {
147
+ // Only process .js and .ts files that end with Tool
148
+ if (!entry.endsWith('Tool.js') && !entry.endsWith('Tool.ts')) continue;
149
+ if (entry.endsWith('.d.ts')) continue;
150
+
151
+ const entryPath = join(toolsDir, entry);
152
+
153
+ try {
154
+ const stat = statSync(entryPath);
155
+ if (!stat.isFile()) continue;
156
+
157
+ // Dynamic import - need file:// URL for ESM
158
+ const fileUrl = pathToFileURL(entryPath).href;
159
+ const module = await import(fileUrl);
160
+
161
+ // Find exported Tool (named export matching filename or any Tool export)
162
+ const baseName = entry.replace(/\.(js|ts)$/, '');
163
+ const tool = module[baseName] || module.default;
164
+
165
+ if (tool && typeof tool.name === 'string' && typeof tool.run === 'function') {
166
+ tools.push(tool);
167
+ } else {
168
+ console.warn(`No valid Tool export found in ${entry}`);
169
+ }
170
+ } catch (err) {
171
+ console.warn(`Error loading tool from ${entry}:`, err);
172
+ }
173
+ }
174
+
175
+ return tools;
176
+ }
177
+
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Copy runtime assets (skill files, prompt files, scripts) to dist folder
4
+ * These files are read from disk at runtime and need to be deployed with the app
5
+ *
6
+ * Usage:
7
+ * npx tools-sdk-copy-assets [srcDir] [distDir]
8
+ *
9
+ * Or import and call directly:
10
+ * import { copyRuntimeAssets } from '@vertesia/tools-sdk';
11
+ * copyRuntimeAssets('./src', './dist');
12
+ */
13
+ import { existsSync, readdirSync, statSync, mkdirSync, copyFileSync } from "fs";
14
+ import { dirname, join } from "path";
15
+
16
+ /**
17
+ * Recursively copy files matching a filter
18
+ */
19
+ function copyFilesRecursive(src: string, dest: string, fileFilter: (filename: string) => boolean): void {
20
+ if (!existsSync(src)) return;
21
+
22
+ const entries = readdirSync(src);
23
+
24
+ for (const entry of entries) {
25
+ const srcPath = join(src, entry);
26
+ const destPath = join(dest, entry);
27
+ const stat = statSync(srcPath);
28
+
29
+ if (stat.isDirectory()) {
30
+ // Recurse into directories
31
+ copyFilesRecursive(srcPath, destPath, fileFilter);
32
+ } else if (fileFilter(entry)) {
33
+ // Copy matching files
34
+ mkdirSync(dirname(destPath), { recursive: true });
35
+ copyFileSync(srcPath, destPath);
36
+ }
37
+ }
38
+ }
39
+
40
+ export interface CopyAssetsOptions {
41
+ /** Source directory (default: './src') */
42
+ srcDir?: string;
43
+ /** Destination directory (default: './dist') */
44
+ distDir?: string;
45
+ /** Whether to log progress (default: true) */
46
+ verbose?: boolean;
47
+ }
48
+
49
+ /**
50
+ * Copy runtime assets (skills, interactions) from src to dist
51
+ */
52
+ export function copyRuntimeAssets(options: CopyAssetsOptions = {}): void {
53
+ const {
54
+ srcDir = './src',
55
+ distDir = './dist',
56
+ verbose = true
57
+ } = options;
58
+
59
+ if (verbose) {
60
+ console.log('Copying runtime assets to dist...');
61
+ }
62
+
63
+ // Copy skill files (SKILL.md, SKILL.jst, *.py)
64
+ const skillsSrc = join(srcDir, 'skills');
65
+ const skillsDest = join(distDir, 'skills');
66
+
67
+ if (existsSync(skillsSrc)) {
68
+ copyFilesRecursive(skillsSrc, skillsDest, (filename) => {
69
+ return filename === 'SKILL.md' ||
70
+ filename === 'SKILL.jst' ||
71
+ filename.endsWith('.py');
72
+ });
73
+ if (verbose) {
74
+ console.log(' ✓ Skills assets (SKILL.md, SKILL.jst, *.py)');
75
+ }
76
+ }
77
+
78
+ // Copy interaction prompt files (prompt.jst, prompt.md)
79
+ const interactionsSrc = join(srcDir, 'interactions');
80
+ const interactionsDest = join(distDir, 'interactions');
81
+
82
+ if (existsSync(interactionsSrc)) {
83
+ copyFilesRecursive(interactionsSrc, interactionsDest, (filename) => {
84
+ return filename === 'prompt.jst' ||
85
+ filename === 'prompt.md';
86
+ });
87
+ if (verbose) {
88
+ console.log(' ✓ Interaction assets (prompt.jst, prompt.md)');
89
+ }
90
+ }
91
+
92
+ if (verbose) {
93
+ console.log('Runtime assets copied successfully!');
94
+ }
95
+ }
96
+
97
+ // CLI entry point
98
+ if (typeof process !== 'undefined' && process.argv[1]?.includes('copy-assets')) {
99
+ const args = process.argv.slice(2);
100
+ const srcDir = args[0] || './src';
101
+ const distDir = args[1] || './dist';
102
+
103
+ copyRuntimeAssets({ srcDir, distDir });
104
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export { authorize, AuthSession } from "./auth.js";
2
2
  export * from "./InteractionCollection.js";
3
+ export * from "./SkillCollection.js";
3
4
  export * from "./ToolCollection.js";
4
5
  export * from "./ToolRegistry.js";
5
6
  export * from "./types.js";
7
+ export * from "./server.js";
8
+ export * from "./site/templates.js";
9
+ export { copyRuntimeAssets } from "./copy-assets.js";