@vertesia/tools-sdk 0.24.0-dev.202601221707

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 (144) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +122 -0
  3. package/lib/cjs/InteractionCollection.js +164 -0
  4. package/lib/cjs/InteractionCollection.js.map +1 -0
  5. package/lib/cjs/SkillCollection.js +376 -0
  6. package/lib/cjs/SkillCollection.js.map +1 -0
  7. package/lib/cjs/ToolCollection.js +228 -0
  8. package/lib/cjs/ToolCollection.js.map +1 -0
  9. package/lib/cjs/ToolRegistry.js +111 -0
  10. package/lib/cjs/ToolRegistry.js.map +1 -0
  11. package/lib/cjs/auth.js +104 -0
  12. package/lib/cjs/auth.js.map +1 -0
  13. package/lib/cjs/build/validate.js +7 -0
  14. package/lib/cjs/build/validate.js.map +1 -0
  15. package/lib/cjs/copy-assets.js +84 -0
  16. package/lib/cjs/copy-assets.js.map +1 -0
  17. package/lib/cjs/index.js +31 -0
  18. package/lib/cjs/index.js.map +1 -0
  19. package/lib/cjs/package.json +3 -0
  20. package/lib/cjs/server/interactions.js +66 -0
  21. package/lib/cjs/server/interactions.js.map +1 -0
  22. package/lib/cjs/server/mcp.js +45 -0
  23. package/lib/cjs/server/mcp.js.map +1 -0
  24. package/lib/cjs/server/site.js +30 -0
  25. package/lib/cjs/server/site.js.map +1 -0
  26. package/lib/cjs/server/skills.js +114 -0
  27. package/lib/cjs/server/skills.js.map +1 -0
  28. package/lib/cjs/server/tools.js +104 -0
  29. package/lib/cjs/server/tools.js.map +1 -0
  30. package/lib/cjs/server/types.js +3 -0
  31. package/lib/cjs/server/types.js.map +1 -0
  32. package/lib/cjs/server/widgets.js +27 -0
  33. package/lib/cjs/server/widgets.js.map +1 -0
  34. package/lib/cjs/server.js +132 -0
  35. package/lib/cjs/server.js.map +1 -0
  36. package/lib/cjs/site/styles.js +621 -0
  37. package/lib/cjs/site/styles.js.map +1 -0
  38. package/lib/cjs/site/templates.js +968 -0
  39. package/lib/cjs/site/templates.js.map +1 -0
  40. package/lib/cjs/types.js +3 -0
  41. package/lib/cjs/types.js.map +1 -0
  42. package/lib/cjs/utils.js +31 -0
  43. package/lib/cjs/utils.js.map +1 -0
  44. package/lib/esm/InteractionCollection.js +125 -0
  45. package/lib/esm/InteractionCollection.js.map +1 -0
  46. package/lib/esm/SkillCollection.js +369 -0
  47. package/lib/esm/SkillCollection.js.map +1 -0
  48. package/lib/esm/ToolCollection.js +190 -0
  49. package/lib/esm/ToolCollection.js.map +1 -0
  50. package/lib/esm/ToolRegistry.js +106 -0
  51. package/lib/esm/ToolRegistry.js.map +1 -0
  52. package/lib/esm/auth.js +97 -0
  53. package/lib/esm/auth.js.map +1 -0
  54. package/lib/esm/build/validate.js +4 -0
  55. package/lib/esm/build/validate.js.map +1 -0
  56. package/lib/esm/copy-assets.js +81 -0
  57. package/lib/esm/copy-assets.js.map +1 -0
  58. package/lib/esm/index.js +11 -0
  59. package/lib/esm/index.js.map +1 -0
  60. package/lib/esm/server/interactions.js +63 -0
  61. package/lib/esm/server/interactions.js.map +1 -0
  62. package/lib/esm/server/mcp.js +42 -0
  63. package/lib/esm/server/mcp.js.map +1 -0
  64. package/lib/esm/server/site.js +27 -0
  65. package/lib/esm/server/site.js.map +1 -0
  66. package/lib/esm/server/skills.js +111 -0
  67. package/lib/esm/server/skills.js.map +1 -0
  68. package/lib/esm/server/tools.js +101 -0
  69. package/lib/esm/server/tools.js.map +1 -0
  70. package/lib/esm/server/types.js +2 -0
  71. package/lib/esm/server/types.js.map +1 -0
  72. package/lib/esm/server/widgets.js +24 -0
  73. package/lib/esm/server/widgets.js.map +1 -0
  74. package/lib/esm/server.js +128 -0
  75. package/lib/esm/server.js.map +1 -0
  76. package/lib/esm/site/styles.js +618 -0
  77. package/lib/esm/site/styles.js.map +1 -0
  78. package/lib/esm/site/templates.js +956 -0
  79. package/lib/esm/site/templates.js.map +1 -0
  80. package/lib/esm/types.js +2 -0
  81. package/lib/esm/types.js.map +1 -0
  82. package/lib/esm/utils.js +26 -0
  83. package/lib/esm/utils.js.map +1 -0
  84. package/lib/types/InteractionCollection.d.ts +48 -0
  85. package/lib/types/InteractionCollection.d.ts.map +1 -0
  86. package/lib/types/SkillCollection.d.ts +118 -0
  87. package/lib/types/SkillCollection.d.ts.map +1 -0
  88. package/lib/types/ToolCollection.d.ts +72 -0
  89. package/lib/types/ToolCollection.d.ts.map +1 -0
  90. package/lib/types/ToolRegistry.d.ts +41 -0
  91. package/lib/types/ToolRegistry.d.ts.map +1 -0
  92. package/lib/types/auth.d.ts +32 -0
  93. package/lib/types/auth.d.ts.map +1 -0
  94. package/lib/types/build/validate.d.ts +2 -0
  95. package/lib/types/build/validate.d.ts.map +1 -0
  96. package/lib/types/copy-assets.d.ts +14 -0
  97. package/lib/types/copy-assets.d.ts.map +1 -0
  98. package/lib/types/index.d.ts +11 -0
  99. package/lib/types/index.d.ts.map +1 -0
  100. package/lib/types/server/interactions.d.ts +4 -0
  101. package/lib/types/server/interactions.d.ts.map +1 -0
  102. package/lib/types/server/mcp.d.ts +4 -0
  103. package/lib/types/server/mcp.d.ts.map +1 -0
  104. package/lib/types/server/site.d.ts +4 -0
  105. package/lib/types/server/site.d.ts.map +1 -0
  106. package/lib/types/server/skills.d.ts +4 -0
  107. package/lib/types/server/skills.d.ts.map +1 -0
  108. package/lib/types/server/tools.d.ts +4 -0
  109. package/lib/types/server/tools.d.ts.map +1 -0
  110. package/lib/types/server/types.d.ts +62 -0
  111. package/lib/types/server/types.d.ts.map +1 -0
  112. package/lib/types/server/widgets.d.ts +9 -0
  113. package/lib/types/server/widgets.d.ts.map +1 -0
  114. package/lib/types/server.d.ts +27 -0
  115. package/lib/types/server.d.ts.map +1 -0
  116. package/lib/types/site/styles.d.ts +5 -0
  117. package/lib/types/site/styles.d.ts.map +1 -0
  118. package/lib/types/site/templates.d.ts +54 -0
  119. package/lib/types/site/templates.d.ts.map +1 -0
  120. package/lib/types/types.d.ts +280 -0
  121. package/lib/types/types.d.ts.map +1 -0
  122. package/lib/types/utils.d.ts +4 -0
  123. package/lib/types/utils.d.ts.map +1 -0
  124. package/package.json +58 -0
  125. package/src/InteractionCollection.ts +143 -0
  126. package/src/SkillCollection.ts +461 -0
  127. package/src/ToolCollection.ts +223 -0
  128. package/src/ToolRegistry.ts +135 -0
  129. package/src/auth.ts +123 -0
  130. package/src/build/validate.ts +3 -0
  131. package/src/copy-assets.ts +104 -0
  132. package/src/index.ts +12 -0
  133. package/src/server/interactions.ts +79 -0
  134. package/src/server/mcp.ts +51 -0
  135. package/src/server/site.ts +46 -0
  136. package/src/server/skills.ts +133 -0
  137. package/src/server/tools.ts +128 -0
  138. package/src/server/types.ts +65 -0
  139. package/src/server/widgets.ts +38 -0
  140. package/src/server.ts +160 -0
  141. package/src/site/styles.ts +617 -0
  142. package/src/site/templates.ts +994 -0
  143. package/src/types.ts +303 -0
  144. package/src/utils.ts +23 -0
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Composable
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # @vertesia/tools-sdk
2
+
3
+ SDK for building remote tools, interactions, and skills that integrate with the Vertesia platform. Built on top of [Hono](https://hono.dev/) for lightweight, high-performance HTTP servers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vertesia/tools-sdk hono
9
+ # or
10
+ pnpm add @vertesia/tools-sdk hono
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { createToolServer, ToolCollection } from "@vertesia/tools-sdk";
17
+
18
+ // Define a tool collection
19
+ const myTools = new ToolCollection({
20
+ name: "my-tools",
21
+ description: "My custom tools",
22
+ tools: [
23
+ {
24
+ name: "hello",
25
+ description: "Says hello",
26
+ parameters: {
27
+ type: "object",
28
+ properties: {
29
+ name: { type: "string", description: "Name to greet" },
30
+ },
31
+ required: ["name"],
32
+ },
33
+ execute: async ({ name }) => {
34
+ return { message: `Hello, ${name}!` };
35
+ },
36
+ },
37
+ ],
38
+ });
39
+
40
+ // Create the server
41
+ const server = createToolServer({
42
+ title: "My Tools Server",
43
+ tools: [myTools],
44
+ });
45
+
46
+ export default server;
47
+ ```
48
+
49
+ ## Features
50
+
51
+ ### Tool Collections
52
+
53
+ Define collections of tools that can be called remotely:
54
+
55
+ ```typescript
56
+ import { ToolCollection } from "@vertesia/tools-sdk";
57
+
58
+ const tools = new ToolCollection({
59
+ name: "utilities",
60
+ description: "Utility tools",
61
+ tools: [/* tool definitions */],
62
+ });
63
+ ```
64
+
65
+ ### Skill Collections
66
+
67
+ Define skills that can be executed by agents:
68
+
69
+ ```typescript
70
+ import { SkillCollection } from "@vertesia/tools-sdk";
71
+
72
+ const skills = new SkillCollection({
73
+ name: "my-skills",
74
+ description: "Custom skills",
75
+ skills: [/* skill definitions */],
76
+ });
77
+ ```
78
+
79
+ ### Interaction Collections
80
+
81
+ Expose interactions for execution:
82
+
83
+ ```typescript
84
+ import { InteractionCollection } from "@vertesia/tools-sdk";
85
+
86
+ const interactions = new InteractionCollection({
87
+ name: "my-interactions",
88
+ interactions: [/* interaction refs */],
89
+ });
90
+ ```
91
+
92
+ ### Server Configuration
93
+
94
+ ```typescript
95
+ const server = createToolServer({
96
+ title: "My Server", // HTML page title
97
+ prefix: "/api", // API route prefix (default: '/api')
98
+ tools: [toolCollection], // Tool collections
99
+ skills: [skillCollection], // Skill collections
100
+ interactions: [interactionCollection], // Interaction collections
101
+ disableHtml: false, // Disable HTML documentation pages
102
+ });
103
+ ```
104
+
105
+ ### Authentication
106
+
107
+ The SDK includes built-in JWT authentication:
108
+
109
+ ```typescript
110
+ import { authorize } from "@vertesia/tools-sdk";
111
+
112
+ // In your route handler
113
+ const session = await authorize(request);
114
+ ```
115
+
116
+ ## API Reference
117
+
118
+ For detailed API documentation, visit [docs.vertesiahq.com](https://docs.vertesiahq.com).
119
+
120
+ ## License
121
+
122
+ Apache-2.0
@@ -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"],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 0;
4
+ exports.parseSkillFile = parseSkillFile;
5
+ exports.loadSkillFromFile = loadSkillFromFile;
6
+ exports.loadSkillsFromDirectory = loadSkillsFromDirectory;
7
+ const fs_1 = require("fs");
8
+ const http_exception_1 = require("hono/http-exception");
9
+ const path_1 = require("path");
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
+ * Includes related_tools for dynamic tool discovery.
67
+ */
68
+ getToolDefinitions() {
69
+ const defaultSchema = {
70
+ type: 'object',
71
+ properties: {
72
+ context: {
73
+ type: "string",
74
+ description: "Additional context or specific requirements for this task"
75
+ }
76
+ }
77
+ };
78
+ return Array.from(this.skills.values()).map(skill => {
79
+ // Build description with related tools info if available
80
+ let description = `[Skill] ${skill.description}. Returns contextual instructions for this task.`;
81
+ if (skill.related_tools && skill.related_tools.length > 0) {
82
+ description += ` Unlocks tools: ${skill.related_tools.join(', ')}.`;
83
+ }
84
+ return {
85
+ name: `learn_${skill.name}`,
86
+ description,
87
+ input_schema: skill.input_schema || defaultSchema,
88
+ related_tools: skill.related_tools,
89
+ };
90
+ });
91
+ }
92
+ /**
93
+ * Get as a tool collection definition (for listing alongside tools)
94
+ */
95
+ getAsToolCollection(baseUrl) {
96
+ return {
97
+ title: this.title || this.name,
98
+ description: this.description || `Skills: ${this.name}`,
99
+ src: `${baseUrl}/api/skills/${this.name}`,
100
+ tools: this.getToolDefinitions()
101
+ };
102
+ }
103
+ getWidgets() {
104
+ const out = [];
105
+ for (const skill of this.skills.values()) {
106
+ if (skill.widgets) {
107
+ for (const widget of skill.widgets) {
108
+ out.push({
109
+ name: widget,
110
+ skill: skill.name,
111
+ });
112
+ }
113
+ }
114
+ }
115
+ return Array.from(out);
116
+ }
117
+ /**
118
+ * Execute a skill - accepts standard tool execution payload.
119
+ * Returns rendered instructions in tool result format.
120
+ *
121
+ * @param ctx - Hono context
122
+ * @param preParsedPayload - Optional pre-parsed payload (used when routing from root endpoint)
123
+ */
124
+ async execute(ctx, preParsedPayload) {
125
+ const toolCtx = ctx;
126
+ let payload = preParsedPayload;
127
+ try {
128
+ if (!payload) {
129
+ // Check if body was already parsed and validated by middleware
130
+ if (toolCtx.payload) {
131
+ payload = toolCtx.payload;
132
+ }
133
+ else {
134
+ throw new http_exception_1.HTTPException(400, {
135
+ message: 'Invalid or missing skill execution payload. Expected { tool_use: { id, tool_name, tool_input? }, metadata? }'
136
+ });
137
+ }
138
+ }
139
+ const toolName = payload.tool_use.tool_name;
140
+ // Extract skill name from tool name (remove "learn_" prefix if present)
141
+ const skillName = toolName.startsWith('learn_')
142
+ ? toolName.replace('learn_', '')
143
+ : toolName;
144
+ const skill = this.skills.get(skillName);
145
+ if (!skill) {
146
+ console.warn("[SkillCollection] Skill not found", {
147
+ collection: this.name,
148
+ requestedSkill: skillName,
149
+ toolName,
150
+ availableSkills: Array.from(this.skills.keys()),
151
+ });
152
+ throw new http_exception_1.HTTPException(404, {
153
+ message: `Skill not found: ${skillName}`
154
+ });
155
+ }
156
+ const data = payload.tool_use.tool_input || {};
157
+ const result = await this.renderSkill(skill, data);
158
+ // TODO: If skill.execution is set, run via Daytona
159
+ // Return in tool result format
160
+ return ctx.json({
161
+ tool_use_id: payload.tool_use.id,
162
+ is_error: false,
163
+ content: result.instructions,
164
+ meta: {
165
+ skill_name: skill.name,
166
+ content_type: skill.content_type,
167
+ execution: skill.execution,
168
+ }
169
+ });
170
+ }
171
+ catch (err) {
172
+ const status = err.status || 500;
173
+ const toolName = payload?.tool_use?.tool_name;
174
+ const toolUseId = payload?.tool_use?.id;
175
+ if (status >= 500) {
176
+ console.error("[SkillCollection] Skill execution failed", {
177
+ collection: this.name,
178
+ skill: toolName,
179
+ toolUseId,
180
+ error: err.message,
181
+ status,
182
+ toolInput: payload?.tool_use?.tool_input,
183
+ stack: err.stack,
184
+ });
185
+ }
186
+ return ctx.json({
187
+ tool_use_id: toolUseId || "unknown",
188
+ is_error: true,
189
+ content: err.message || "Error executing skill",
190
+ }, status);
191
+ }
192
+ }
193
+ /**
194
+ * Render skill instructions (static or dynamic)
195
+ */
196
+ async renderSkill(skill, _data) {
197
+ const instructions = skill.instructions;
198
+ if (skill.content_type === 'jst') {
199
+ // JST templates are not currently supported
200
+ throw new http_exception_1.HTTPException(501, {
201
+ message: `JST templates are not currently supported. Use 'md' content type instead.`
202
+ });
203
+ }
204
+ return {
205
+ name: skill.name,
206
+ instructions,
207
+ };
208
+ }
209
+ }
210
+ exports.SkillCollection = SkillCollection;
211
+ /**
212
+ * Parse a SKILL.md or SKILL.jst file content into a SkillDefinition.
213
+ *
214
+ * Format:
215
+ * ```
216
+ * ---
217
+ * name: skill-name
218
+ * description: Short description
219
+ * keywords: [keyword1, keyword2]
220
+ * tools: [tool1, tool2]
221
+ * language: python
222
+ * packages: [numpy, pandas]
223
+ * ---
224
+ *
225
+ * # Instructions
226
+ *
227
+ * Your markdown/jst content here...
228
+ * ```
229
+ */
230
+ function parseSkillFile(content, contentType) {
231
+ // Parse YAML frontmatter
232
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
233
+ if (!frontmatterMatch) {
234
+ throw new Error("Invalid skill file: missing YAML frontmatter");
235
+ }
236
+ const [, yamlContent, body] = frontmatterMatch;
237
+ const frontmatter = parseYamlFrontmatter(yamlContent);
238
+ const instructions = body.trim();
239
+ if (!frontmatter.name) {
240
+ throw new Error("Skill file missing required 'name' field");
241
+ }
242
+ if (!frontmatter.description) {
243
+ throw new Error("Skill file missing required 'description' field");
244
+ }
245
+ const skill = {
246
+ name: frontmatter.name,
247
+ title: frontmatter.title,
248
+ description: frontmatter.description,
249
+ instructions,
250
+ content_type: contentType,
251
+ widgets: frontmatter.widgets || undefined,
252
+ scripts: frontmatter.scripts || undefined,
253
+ };
254
+ // Build context triggers
255
+ if (frontmatter.keywords || frontmatter.tools || frontmatter.data_patterns) {
256
+ skill.context_triggers = {
257
+ keywords: frontmatter.keywords,
258
+ tool_names: frontmatter.tools,
259
+ data_patterns: frontmatter.data_patterns,
260
+ };
261
+ }
262
+ // Build execution config
263
+ if (frontmatter.language) {
264
+ skill.execution = {
265
+ language: frontmatter.language,
266
+ packages: frontmatter.packages,
267
+ system_packages: frontmatter.system_packages,
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
+ // Related tools from frontmatter
276
+ if (frontmatter.tools) {
277
+ skill.related_tools = frontmatter.tools;
278
+ }
279
+ return skill;
280
+ }
281
+ /**
282
+ * Simple YAML frontmatter parser (handles basic key: value and arrays)
283
+ */
284
+ function parseYamlFrontmatter(yaml) {
285
+ const result = {};
286
+ const lines = yaml.split('\n');
287
+ for (const line of lines) {
288
+ const trimmed = line.trim();
289
+ if (!trimmed || trimmed.startsWith('#'))
290
+ continue;
291
+ const colonIndex = trimmed.indexOf(':');
292
+ if (colonIndex === -1)
293
+ continue;
294
+ const key = trimmed.slice(0, colonIndex).trim();
295
+ let value = trimmed.slice(colonIndex + 1).trim();
296
+ // Handle array syntax: [item1, item2]
297
+ if (value.startsWith('[') && value.endsWith(']')) {
298
+ const items = value.slice(1, -1).split(',').map(s => s.trim());
299
+ result[key] = items.filter(s => s.length > 0);
300
+ }
301
+ else {
302
+ // Remove quotes if present
303
+ if ((value.startsWith('"') && value.endsWith('"')) ||
304
+ (value.startsWith("'") && value.endsWith("'"))) {
305
+ value = value.slice(1, -1);
306
+ }
307
+ result[key] = value;
308
+ }
309
+ }
310
+ return result;
311
+ }
312
+ /**
313
+ * Helper to load skill from file path (for Node.js usage)
314
+ */
315
+ async function loadSkillFromFile(filePath, fs) {
316
+ const content = await fs.readFile(filePath, 'utf-8');
317
+ const contentType = filePath.endsWith('.jst') ? 'jst' : 'md';
318
+ return parseSkillFile(content, contentType);
319
+ }
320
+ /**
321
+ * Load all skills from a directory.
322
+ * Scans for subdirectories containing SKILL.md files.
323
+ *
324
+ * Directory structure:
325
+ * ```
326
+ * skills/
327
+ * nagare/
328
+ * fund-onboarding/
329
+ * SKILL.md
330
+ * monte-carlo/
331
+ * SKILL.md
332
+ * ```
333
+ *
334
+ * @param dirPath - Path to the skills collection directory
335
+ * @returns Array of parsed skill definitions
336
+ */
337
+ function loadSkillsFromDirectory(dirPath) {
338
+ const skills = [];
339
+ let entries;
340
+ try {
341
+ entries = (0, fs_1.readdirSync)(dirPath);
342
+ }
343
+ catch {
344
+ console.warn(`Could not read skills directory: ${dirPath}`);
345
+ return skills;
346
+ }
347
+ for (const entry of entries) {
348
+ const entryPath = (0, path_1.join)(dirPath, entry);
349
+ try {
350
+ const stat = (0, fs_1.statSync)(entryPath);
351
+ if (!stat.isDirectory())
352
+ continue;
353
+ // Look for SKILL.md or SKILL.jst
354
+ const mdPath = (0, path_1.join)(entryPath, "SKILL.md");
355
+ const jstPath = (0, path_1.join)(entryPath, "SKILL.jst");
356
+ let content;
357
+ let contentType = 'md';
358
+ if ((0, fs_1.existsSync)(mdPath)) {
359
+ content = (0, fs_1.readFileSync)(mdPath, "utf-8");
360
+ contentType = 'md';
361
+ }
362
+ else if ((0, fs_1.existsSync)(jstPath)) {
363
+ content = (0, fs_1.readFileSync)(jstPath, "utf-8");
364
+ contentType = 'jst';
365
+ }
366
+ if (content) {
367
+ skills.push(parseSkillFile(content, contentType));
368
+ }
369
+ }
370
+ catch (err) {
371
+ console.warn(`Error loading skill from ${entryPath}:`, err);
372
+ }
373
+ }
374
+ return skills;
375
+ }
376
+ //# sourceMappingURL=SkillCollection.js.map