@vertesia/tools-sdk 0.82.0 → 0.82.2

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 (80) hide show
  1. package/lib/cjs/InteractionCollection.js +164 -0
  2. package/lib/cjs/InteractionCollection.js.map +1 -0
  3. package/lib/cjs/SkillCollection.js +318 -0
  4. package/lib/cjs/SkillCollection.js.map +1 -0
  5. package/lib/cjs/ToolCollection.js +192 -0
  6. package/lib/cjs/ToolCollection.js.map +1 -0
  7. package/lib/cjs/ToolRegistry.js +44 -0
  8. package/lib/cjs/ToolRegistry.js.map +1 -0
  9. package/lib/cjs/auth.js +89 -0
  10. package/lib/cjs/auth.js.map +1 -0
  11. package/lib/cjs/build/validate.js +7 -0
  12. package/lib/cjs/build/validate.js.map +1 -0
  13. package/lib/cjs/copy-assets.js +84 -0
  14. package/lib/cjs/copy-assets.js.map +1 -0
  15. package/lib/cjs/index.js +30 -0
  16. package/lib/cjs/index.js.map +1 -0
  17. package/lib/cjs/package.json +3 -0
  18. package/lib/cjs/server.js +327 -0
  19. package/lib/cjs/server.js.map +1 -0
  20. package/lib/cjs/site/styles.js +621 -0
  21. package/lib/cjs/site/styles.js.map +1 -0
  22. package/lib/cjs/site/templates.js +932 -0
  23. package/lib/cjs/site/templates.js.map +1 -0
  24. package/lib/cjs/types.js +3 -0
  25. package/lib/cjs/types.js.map +1 -0
  26. package/lib/cjs/utils.js +7 -0
  27. package/lib/cjs/utils.js.map +1 -0
  28. package/lib/esm/InteractionCollection.js +125 -0
  29. package/lib/esm/InteractionCollection.js.map +1 -0
  30. package/lib/esm/SkillCollection.js +311 -0
  31. package/lib/esm/SkillCollection.js.map +1 -0
  32. package/lib/esm/ToolCollection.js +154 -0
  33. package/lib/esm/ToolCollection.js.map +1 -0
  34. package/lib/esm/ToolRegistry.js +39 -0
  35. package/lib/esm/ToolRegistry.js.map +1 -0
  36. package/lib/esm/auth.js +82 -0
  37. package/lib/esm/auth.js.map +1 -0
  38. package/lib/esm/build/validate.js +4 -0
  39. package/lib/esm/build/validate.js.map +1 -0
  40. package/lib/esm/copy-assets.js +81 -0
  41. package/lib/esm/copy-assets.js.map +1 -0
  42. package/lib/esm/index.js +10 -0
  43. package/lib/esm/index.js.map +1 -0
  44. package/lib/esm/server.js +323 -0
  45. package/lib/esm/server.js.map +1 -0
  46. package/lib/esm/site/styles.js +618 -0
  47. package/lib/esm/site/styles.js.map +1 -0
  48. package/lib/esm/site/templates.js +920 -0
  49. package/lib/esm/site/templates.js.map +1 -0
  50. package/lib/esm/types.js +2 -0
  51. package/lib/esm/types.js.map +1 -0
  52. package/lib/esm/utils.js +4 -0
  53. package/lib/esm/utils.js.map +1 -0
  54. package/lib/types/InteractionCollection.d.ts +48 -0
  55. package/lib/types/InteractionCollection.d.ts.map +1 -0
  56. package/lib/types/SkillCollection.d.ts +111 -0
  57. package/lib/types/SkillCollection.d.ts.map +1 -0
  58. package/lib/types/ToolCollection.d.ts +61 -0
  59. package/lib/types/ToolCollection.d.ts.map +1 -0
  60. package/lib/types/ToolRegistry.d.ts +15 -0
  61. package/lib/types/ToolRegistry.d.ts.map +1 -0
  62. package/lib/types/auth.d.ts +20 -0
  63. package/lib/types/auth.d.ts.map +1 -0
  64. package/lib/types/build/validate.d.ts +2 -0
  65. package/lib/types/build/validate.d.ts.map +1 -0
  66. package/lib/types/copy-assets.d.ts +14 -0
  67. package/lib/types/copy-assets.d.ts.map +1 -0
  68. package/lib/types/index.d.ts +10 -0
  69. package/lib/types/index.d.ts.map +1 -0
  70. package/lib/types/server.d.ts +72 -0
  71. package/lib/types/server.d.ts.map +1 -0
  72. package/lib/types/site/styles.d.ts +5 -0
  73. package/lib/types/site/styles.d.ts.map +1 -0
  74. package/lib/types/site/templates.d.ts +54 -0
  75. package/lib/types/site/templates.d.ts.map +1 -0
  76. package/lib/types/types.d.ts +262 -0
  77. package/lib/types/types.d.ts.map +1 -0
  78. package/lib/types/utils.d.ts +2 -0
  79. package/lib/types/utils.d.ts.map +1 -0
  80. package/package.json +4 -4
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.InteractionCollection = void 0;
37
+ exports.loadInteractionsFromDirectory = loadInteractionsFromDirectory;
38
+ exports.readPromptFile = readPromptFile;
39
+ const fs_1 = require("fs");
40
+ const path_1 = require("path");
41
+ const url_1 = require("url");
42
+ const utils_js_1 = require("./utils.js");
43
+ class InteractionCollection {
44
+ interactions;
45
+ name;
46
+ title;
47
+ icon;
48
+ description;
49
+ constructor({ name, title, icon, description, interactions }) {
50
+ this.name = name;
51
+ this.title = title || (0, utils_js_1.kebabCaseToTitle)(name);
52
+ this.icon = icon;
53
+ this.description = description;
54
+ this.interactions = interactions;
55
+ }
56
+ addInteraction(interaction) {
57
+ this.interactions.push(interaction);
58
+ }
59
+ getInteractions() {
60
+ return this.interactions;
61
+ }
62
+ [Symbol.iterator]() {
63
+ let index = 0;
64
+ const interactions = this.interactions;
65
+ return {
66
+ next() {
67
+ if (index < interactions.length) {
68
+ return { value: interactions[index++], done: false };
69
+ }
70
+ else {
71
+ return { done: true, value: undefined };
72
+ }
73
+ }
74
+ };
75
+ }
76
+ map(callback) {
77
+ return this.interactions.map(callback);
78
+ }
79
+ getInteractionByName(name) {
80
+ return this.interactions.find(interaction => interaction.name === name);
81
+ }
82
+ }
83
+ exports.InteractionCollection = InteractionCollection;
84
+ /**
85
+ * Load all interactions from a directory.
86
+ * Scans for subdirectories containing index.ts/index.js files.
87
+ *
88
+ * Directory structure:
89
+ * ```
90
+ * interactions/
91
+ * nagare/
92
+ * extract-fund-actuals/
93
+ * index.ts # exports default InteractionSpec
94
+ * prompt.jst # prompt template (read via readPromptFile helper)
95
+ * parse-fund-document/
96
+ * index.ts
97
+ * prompt.md
98
+ * ```
99
+ *
100
+ * @param interactionsDir - Path to the interactions collection directory
101
+ * @returns Promise resolving to array of InteractionSpec objects
102
+ */
103
+ async function loadInteractionsFromDirectory(interactionsDir) {
104
+ const interactions = [];
105
+ if (!(0, fs_1.existsSync)(interactionsDir)) {
106
+ console.warn(`Interactions directory not found: ${interactionsDir}`);
107
+ return interactions;
108
+ }
109
+ let entries;
110
+ try {
111
+ entries = (0, fs_1.readdirSync)(interactionsDir);
112
+ }
113
+ catch {
114
+ console.warn(`Could not read interactions directory: ${interactionsDir}`);
115
+ return interactions;
116
+ }
117
+ for (const entry of entries) {
118
+ // Skip hidden files and index files
119
+ if (entry.startsWith('.'))
120
+ continue;
121
+ if (entry === 'index.ts' || entry === 'index.js')
122
+ continue;
123
+ const entryPath = (0, path_1.join)(interactionsDir, entry);
124
+ try {
125
+ const stat = (0, fs_1.statSync)(entryPath);
126
+ if (!stat.isDirectory())
127
+ continue;
128
+ // Look for index.ts or index.js in the subdirectory
129
+ const indexTs = (0, path_1.join)(entryPath, 'index.ts');
130
+ const indexJs = (0, path_1.join)(entryPath, 'index.js');
131
+ const indexPath = (0, fs_1.existsSync)(indexTs) ? indexTs : (0, fs_1.existsSync)(indexJs) ? indexJs : null;
132
+ if (!indexPath) {
133
+ continue; // No index file, skip
134
+ }
135
+ // Dynamic import
136
+ const fileUrl = (0, url_1.pathToFileURL)(indexPath).href;
137
+ const module = await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
138
+ const interaction = module.default || module.interaction;
139
+ if (interaction && typeof interaction.name === 'string') {
140
+ interactions.push(interaction);
141
+ }
142
+ else {
143
+ console.warn(`No valid InteractionSpec export found in ${entry}/index`);
144
+ }
145
+ }
146
+ catch (err) {
147
+ console.warn(`Error loading interaction from ${entry}:`, err);
148
+ }
149
+ }
150
+ return interactions;
151
+ }
152
+ /**
153
+ * Helper to read a prompt file from the same directory as the interaction.
154
+ * Use this in interaction index.ts files to load prompt templates.
155
+ *
156
+ * @param dirname - Pass __dirname or dirname(fileURLToPath(import.meta.url))
157
+ * @param filename - Prompt filename (e.g., 'prompt.jst' or 'prompt.md')
158
+ * @returns File contents as string
159
+ */
160
+ function readPromptFile(dirname, filename) {
161
+ const filePath = (0, path_1.join)(dirname, filename);
162
+ return (0, fs_1.readFileSync)(filePath, 'utf-8');
163
+ }
164
+ //# sourceMappingURL=InteractionCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InteractionCollection.js","sourceRoot":"","sources":["../../src/InteractionCollection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,sEAqDC;AAUD,wCAGC;AA9ID,2BAAqE;AACrE,+BAA4B;AAC5B,6BAAoC;AAGpC,yCAA8C;AAK9C,MAAa,qBAAqB;IAC9B,YAAY,CAAoB;IAChC,IAAI,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CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAEvF,IAAI,CAAC,SAAS,EAAE,CAAC;gBACb,SAAS,CAAC,sBAAsB;YACpC,CAAC;YAED,iBAAiB;YACjB,MAAM,OAAO,GAAG,IAAA,mBAAa,EAAC,SAAS,CAAC,CAAC,IAAI,CAAC;YAC9C,MAAM,MAAM,GAAG,yBAAa,OAAO,uCAAC,CAAC;YAErC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,WAAW,CAAC;YAEzD,IAAI,WAAW,IAAI,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtD,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,4CAA4C,KAAK,QAAQ,CAAC,CAAC;YAC5E,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,kCAAkC,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;IAED,OAAO,YAAY,CAAC;AACxB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,OAAe,EAAE,QAAgB;IAC5D,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,OAAO,IAAA,iBAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SkillCollection = void 0;
4
+ exports.parseSkillFile = parseSkillFile;
5
+ exports.loadSkillFromFile = loadSkillFromFile;
6
+ exports.loadSkillsFromDirectory = loadSkillsFromDirectory;
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const http_exception_1 = require("hono/http-exception");
10
+ const utils_js_1 = require("./utils.js");
11
+ /**
12
+ * Implements a skills collection endpoint.
13
+ * Skills provide contextual instructions to agents.
14
+ * They can be static (markdown) or dynamic (JST templates).
15
+ */
16
+ class SkillCollection {
17
+ /**
18
+ * A kebab case collection name
19
+ */
20
+ name;
21
+ /**
22
+ * Optional title for UI display
23
+ */
24
+ title;
25
+ /**
26
+ * Optional icon for UI display
27
+ */
28
+ icon;
29
+ /**
30
+ * A short description
31
+ */
32
+ description;
33
+ /**
34
+ * The skills in this collection
35
+ */
36
+ skills;
37
+ constructor({ name, title, icon, description, skills }) {
38
+ this.name = name;
39
+ this.title = title || (0, utils_js_1.kebabCaseToTitle)(name);
40
+ this.icon = icon;
41
+ this.description = description;
42
+ this.skills = new Map(skills.map(s => [s.name, s]));
43
+ }
44
+ [Symbol.iterator]() {
45
+ return this.skills.values();
46
+ }
47
+ map(callback) {
48
+ return Array.from(this.skills.values()).map(callback);
49
+ }
50
+ /**
51
+ * Get a skill by name
52
+ */
53
+ getSkill(name) {
54
+ return this.skills.get(name);
55
+ }
56
+ /**
57
+ * Get all skill definitions
58
+ */
59
+ getSkillDefinitions() {
60
+ return Array.from(this.skills.values());
61
+ }
62
+ /**
63
+ * Get skills exposed as tool definitions.
64
+ * This allows skills to appear alongside regular tools.
65
+ * When called, they return rendered instructions.
66
+ */
67
+ getToolDefinitions() {
68
+ const defaultSchema = {
69
+ type: 'object',
70
+ properties: {
71
+ context: {
72
+ type: "string",
73
+ description: "Additional context or specific requirements for this task"
74
+ }
75
+ }
76
+ };
77
+ return Array.from(this.skills.values()).map(skill => ({
78
+ name: `skill_${skill.name}`,
79
+ description: `[Skill] ${skill.description}. Returns contextual instructions for this task.`,
80
+ input_schema: skill.input_schema || defaultSchema
81
+ }));
82
+ }
83
+ /**
84
+ * Get as a tool collection definition (for listing alongside tools)
85
+ */
86
+ getAsToolCollection(baseUrl) {
87
+ return {
88
+ title: this.title || this.name,
89
+ description: this.description || `Skills: ${this.name}`,
90
+ src: `${baseUrl}/api/skills/${this.name}`,
91
+ tools: this.getToolDefinitions()
92
+ };
93
+ }
94
+ /**
95
+ * Execute a skill - accepts standard tool execution payload.
96
+ * Returns rendered instructions in tool result format.
97
+ */
98
+ async execute(ctx) {
99
+ let payload;
100
+ try {
101
+ payload = await ctx.req.json();
102
+ const toolName = payload.tool_use.tool_name;
103
+ // Extract skill name from tool name (remove "skill_" prefix if present)
104
+ const skillName = toolName.startsWith('skill_')
105
+ ? toolName.slice(6)
106
+ : toolName;
107
+ const skill = this.skills.get(skillName);
108
+ if (!skill) {
109
+ throw new http_exception_1.HTTPException(404, {
110
+ message: `Skill not found: ${skillName}`
111
+ });
112
+ }
113
+ const data = payload.tool_use.tool_input || {};
114
+ const result = await this.renderSkill(skill, data);
115
+ // TODO: If skill.execution is set, run via Daytona
116
+ // Return in tool result format
117
+ return ctx.json({
118
+ tool_use_id: payload.tool_use.id,
119
+ is_error: false,
120
+ content: result.instructions,
121
+ meta: {
122
+ skill_name: skill.name,
123
+ content_type: skill.content_type,
124
+ execution: skill.execution,
125
+ }
126
+ });
127
+ }
128
+ catch (err) {
129
+ const status = err.status || 500;
130
+ return ctx.json({
131
+ tool_use_id: payload?.tool_use?.id || "unknown",
132
+ is_error: true,
133
+ content: err.message || "Error executing skill",
134
+ }, status);
135
+ }
136
+ }
137
+ /**
138
+ * Render skill instructions (static or dynamic)
139
+ */
140
+ async renderSkill(skill, _data) {
141
+ const instructions = skill.instructions;
142
+ if (skill.content_type === 'jst') {
143
+ // JST templates are not currently supported
144
+ throw new http_exception_1.HTTPException(501, {
145
+ message: `JST templates are not currently supported. Use 'md' content type instead.`
146
+ });
147
+ }
148
+ return {
149
+ name: skill.name,
150
+ instructions,
151
+ };
152
+ }
153
+ }
154
+ exports.SkillCollection = SkillCollection;
155
+ /**
156
+ * Parse a SKILL.md or SKILL.jst file content into a SkillDefinition.
157
+ *
158
+ * Format:
159
+ * ```
160
+ * ---
161
+ * name: skill-name
162
+ * description: Short description
163
+ * keywords: [keyword1, keyword2]
164
+ * tools: [tool1, tool2]
165
+ * language: python
166
+ * packages: [numpy, pandas]
167
+ * ---
168
+ *
169
+ * # Instructions
170
+ *
171
+ * Your markdown/jst content here...
172
+ * ```
173
+ */
174
+ function parseSkillFile(content, contentType) {
175
+ // Parse YAML frontmatter
176
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
177
+ if (!frontmatterMatch) {
178
+ throw new Error("Invalid skill file: missing YAML frontmatter");
179
+ }
180
+ const [, yamlContent, body] = frontmatterMatch;
181
+ const frontmatter = parseYamlFrontmatter(yamlContent);
182
+ const instructions = body.trim();
183
+ if (!frontmatter.name) {
184
+ throw new Error("Skill file missing required 'name' field");
185
+ }
186
+ if (!frontmatter.description) {
187
+ throw new Error("Skill file missing required 'description' field");
188
+ }
189
+ const skill = {
190
+ name: frontmatter.name,
191
+ title: frontmatter.title,
192
+ description: frontmatter.description,
193
+ instructions,
194
+ content_type: contentType,
195
+ };
196
+ // Build context triggers
197
+ if (frontmatter.keywords || frontmatter.tools || frontmatter.data_patterns) {
198
+ skill.context_triggers = {
199
+ keywords: frontmatter.keywords,
200
+ tool_names: frontmatter.tools,
201
+ data_patterns: frontmatter.data_patterns,
202
+ };
203
+ }
204
+ // Build execution config
205
+ if (frontmatter.language) {
206
+ skill.execution = {
207
+ language: frontmatter.language,
208
+ packages: frontmatter.packages,
209
+ system_packages: frontmatter.system_packages,
210
+ };
211
+ // Extract code template from instructions if present
212
+ const codeBlockMatch = instructions.match(/```(?:python|javascript|typescript|js|ts|py)\n([\s\S]*?)```/);
213
+ if (codeBlockMatch) {
214
+ skill.execution.template = codeBlockMatch[1].trim();
215
+ }
216
+ }
217
+ // Related tools from frontmatter
218
+ if (frontmatter.tools) {
219
+ skill.related_tools = frontmatter.tools;
220
+ }
221
+ return skill;
222
+ }
223
+ /**
224
+ * Simple YAML frontmatter parser (handles basic key: value and arrays)
225
+ */
226
+ function parseYamlFrontmatter(yaml) {
227
+ const result = {};
228
+ const lines = yaml.split('\n');
229
+ for (const line of lines) {
230
+ const trimmed = line.trim();
231
+ if (!trimmed || trimmed.startsWith('#'))
232
+ continue;
233
+ const colonIndex = trimmed.indexOf(':');
234
+ if (colonIndex === -1)
235
+ continue;
236
+ const key = trimmed.slice(0, colonIndex).trim();
237
+ let value = trimmed.slice(colonIndex + 1).trim();
238
+ // Handle array syntax: [item1, item2]
239
+ if (value.startsWith('[') && value.endsWith(']')) {
240
+ const items = value.slice(1, -1).split(',').map(s => s.trim());
241
+ result[key] = items.filter(s => s.length > 0);
242
+ }
243
+ else {
244
+ // Remove quotes if present
245
+ if ((value.startsWith('"') && value.endsWith('"')) ||
246
+ (value.startsWith("'") && value.endsWith("'"))) {
247
+ value = value.slice(1, -1);
248
+ }
249
+ result[key] = value;
250
+ }
251
+ }
252
+ return result;
253
+ }
254
+ /**
255
+ * Helper to load skill from file path (for Node.js usage)
256
+ */
257
+ async function loadSkillFromFile(filePath, fs) {
258
+ const content = await fs.readFile(filePath, 'utf-8');
259
+ const contentType = filePath.endsWith('.jst') ? 'jst' : 'md';
260
+ return parseSkillFile(content, contentType);
261
+ }
262
+ /**
263
+ * Load all skills from a directory.
264
+ * Scans for subdirectories containing SKILL.md files.
265
+ *
266
+ * Directory structure:
267
+ * ```
268
+ * skills/
269
+ * nagare/
270
+ * fund-onboarding/
271
+ * SKILL.md
272
+ * monte-carlo/
273
+ * SKILL.md
274
+ * ```
275
+ *
276
+ * @param dirPath - Path to the skills collection directory
277
+ * @returns Array of parsed skill definitions
278
+ */
279
+ function loadSkillsFromDirectory(dirPath) {
280
+ const skills = [];
281
+ let entries;
282
+ try {
283
+ entries = (0, fs_1.readdirSync)(dirPath);
284
+ }
285
+ catch {
286
+ console.warn(`Could not read skills directory: ${dirPath}`);
287
+ return skills;
288
+ }
289
+ for (const entry of entries) {
290
+ const entryPath = (0, path_1.join)(dirPath, entry);
291
+ try {
292
+ const stat = (0, fs_1.statSync)(entryPath);
293
+ if (!stat.isDirectory())
294
+ continue;
295
+ // Look for SKILL.md or SKILL.jst
296
+ const mdPath = (0, path_1.join)(entryPath, "SKILL.md");
297
+ const jstPath = (0, path_1.join)(entryPath, "SKILL.jst");
298
+ let content;
299
+ let contentType = 'md';
300
+ if ((0, fs_1.existsSync)(mdPath)) {
301
+ content = (0, fs_1.readFileSync)(mdPath, "utf-8");
302
+ contentType = 'md';
303
+ }
304
+ else if ((0, fs_1.existsSync)(jstPath)) {
305
+ content = (0, fs_1.readFileSync)(jstPath, "utf-8");
306
+ contentType = 'jst';
307
+ }
308
+ if (content) {
309
+ skills.push(parseSkillFile(content, contentType));
310
+ }
311
+ }
312
+ catch (err) {
313
+ console.warn(`Error loading skill from ${entryPath}:`, err);
314
+ }
315
+ }
316
+ return skills;
317
+ }
318
+ //# sourceMappingURL=SkillCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SkillCollection.js","sourceRoot":"","sources":["../../src/SkillCollection.ts"],"names":[],"mappings":";;;AA6NA,wCA4DC;AAuCD,8CAOC;AAmBD,0DA0CC;AApYD,2BAAqE;AACrE,+BAA4B;AAG5B,wDAAoD;AAWpD,yCAA8C;AAS9C;;;;GAIG;AACH,MAAa,eAAe;IACxB;;OAEG;IACH,IAAI,CAAS;IACb;;OAEG;IACH,KAAK,CAAU;IACf;;OAEG;IACH,IAAI,CAAU;IACd;;OAEG;IACH,WAAW,CAAU;IACrB;;OAEG;IACK,MAAM,CAA+B;IAE7C,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAA6B;QAC7E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,IAAA,2BAAgB,EAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,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AAE;gBAAE,SAAS;YAElC,iCAAiC;YACjC,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YAC3C,MAAM,OAAO,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAE7C,IAAI,OAA2B,CAAC;YAChC,IAAI,WAAW,GAAqB,IAAI,CAAC;YAEzC,IAAI,IAAA,eAAU,EAAC,MAAM,CAAC,EAAE,CAAC;gBACrB,OAAO,GAAG,IAAA,iBAAY,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACxC,WAAW,GAAG,IAAI,CAAC;YACvB,CAAC;iBAAM,IAAI,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE,CAAC;gBAC7B,OAAO,GAAG,IAAA,iBAAY,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACzC,WAAW,GAAG,KAAK,CAAC;YACxB,CAAC;YAED,IAAI,OAAO,EAAE,CAAC;gBACV,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;YACtD,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,4BAA4B,SAAS,GAAG,EAAE,GAAG,CAAC,CAAC;QAChE,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ToolCollection = void 0;
37
+ exports.loadToolsFromDirectory = loadToolsFromDirectory;
38
+ const fs_1 = require("fs");
39
+ const path_1 = require("path");
40
+ const url_1 = require("url");
41
+ const http_exception_1 = require("hono/http-exception");
42
+ const auth_js_1 = require("./auth.js");
43
+ const ToolRegistry_js_1 = require("./ToolRegistry.js");
44
+ const utils_js_1 = require("./utils.js");
45
+ /**
46
+ * Implements a tools collection endpoint
47
+ */
48
+ class ToolCollection {
49
+ /**
50
+ * A kebab case collection name. Must only contains alphanumeric and dash characters,
51
+ * The name can be used to generate the path where the collection is exposed.
52
+ * Example: my-collection
53
+ */
54
+ name;
55
+ /**
56
+ * Optional title for UI display.
57
+ * If not provided the title will be generated form the kebab case name by replacing - with spaces and upper casing first letter in words.
58
+ */
59
+ title;
60
+ /**
61
+ * Optional icon for UI display
62
+ */
63
+ icon;
64
+ /**
65
+ * A short description
66
+ */
67
+ description;
68
+ /**
69
+ * The tool registry
70
+ */
71
+ tools;
72
+ constructor({ name, title, icon, description, tools }) {
73
+ this.name = name;
74
+ this.title = title || (0, utils_js_1.kebabCaseToTitle)(name);
75
+ this.icon = icon;
76
+ this.description = description;
77
+ this.tools = new ToolRegistry_js_1.ToolRegistry(tools);
78
+ }
79
+ [Symbol.iterator]() {
80
+ let index = 0;
81
+ const tools = this.tools.getTools();
82
+ return {
83
+ next() {
84
+ if (index < tools.length) {
85
+ return { value: tools[index++], done: false };
86
+ }
87
+ else {
88
+ return { done: true, value: undefined };
89
+ }
90
+ }
91
+ };
92
+ }
93
+ map(callback) {
94
+ return this.tools.getTools().map(callback);
95
+ }
96
+ async execute(ctx) {
97
+ let payload;
98
+ try {
99
+ payload = await readPayload(ctx);
100
+ const session = await (0, auth_js_1.authorize)(ctx);
101
+ const r = await this.tools.runTool(payload, session);
102
+ return ctx.json({
103
+ ...r,
104
+ tool_use_id: payload.tool_use.id
105
+ });
106
+ }
107
+ catch (err) { // HTTPException ?
108
+ const status = err.status || 500;
109
+ return ctx.json({
110
+ tool_use_id: payload?.tool_use.id || "undefined",
111
+ error: err.message || "Error executing tool",
112
+ status
113
+ }, status);
114
+ }
115
+ }
116
+ getToolDefinitions() {
117
+ return this.tools.getDefinitions();
118
+ }
119
+ }
120
+ exports.ToolCollection = ToolCollection;
121
+ async function readPayload(ctx) {
122
+ try {
123
+ return await ctx.req.json();
124
+ }
125
+ catch (err) {
126
+ throw new http_exception_1.HTTPException(500, {
127
+ message: "Failed to load execution request payload: " + err.message
128
+ });
129
+ }
130
+ }
131
+ /**
132
+ * Load all tools from a directory.
133
+ * Scans for .js files and imports tools that match naming convention.
134
+ *
135
+ * Directory structure:
136
+ * ```
137
+ * collection/
138
+ * tools/
139
+ * SearchFundsTool.js # exports SearchFundsTool
140
+ * GetFundDetailsTool.js # exports GetFundDetailsTool
141
+ * ```
142
+ *
143
+ * Naming convention: File should export a Tool with name matching *Tool pattern.
144
+ *
145
+ * @param toolsDir - Path to the tools directory (e.g., /path/to/collection/tools)
146
+ * @returns Promise resolving to array of Tool objects
147
+ */
148
+ async function loadToolsFromDirectory(toolsDir) {
149
+ const tools = [];
150
+ if (!(0, fs_1.existsSync)(toolsDir)) {
151
+ console.warn(`Tools directory not found: ${toolsDir}`);
152
+ return tools;
153
+ }
154
+ let entries;
155
+ try {
156
+ entries = (0, fs_1.readdirSync)(toolsDir);
157
+ }
158
+ catch {
159
+ console.warn(`Could not read tools directory: ${toolsDir}`);
160
+ return tools;
161
+ }
162
+ for (const entry of entries) {
163
+ // Only process .js and .ts files that end with Tool
164
+ if (!entry.endsWith('Tool.js') && !entry.endsWith('Tool.ts'))
165
+ continue;
166
+ if (entry.endsWith('.d.ts'))
167
+ continue;
168
+ const entryPath = (0, path_1.join)(toolsDir, entry);
169
+ try {
170
+ const stat = (0, fs_1.statSync)(entryPath);
171
+ if (!stat.isFile())
172
+ continue;
173
+ // Dynamic import - need file:// URL for ESM
174
+ const fileUrl = (0, url_1.pathToFileURL)(entryPath).href;
175
+ const module = await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
176
+ // Find exported Tool (named export matching filename or any Tool export)
177
+ const baseName = entry.replace(/\.(js|ts)$/, '');
178
+ const tool = module[baseName] || module.default;
179
+ if (tool && typeof tool.name === 'string' && typeof tool.run === 'function') {
180
+ tools.push(tool);
181
+ }
182
+ else {
183
+ console.warn(`No valid Tool export found in ${entry}`);
184
+ }
185
+ }
186
+ catch (err) {
187
+ console.warn(`Error loading tool from ${entry}:`, err);
188
+ }
189
+ }
190
+ return tools;
191
+ }
192
+ //# sourceMappingURL=ToolCollection.js.map