@vertesia/tools-sdk 1.3.0 → 1.4.0-dev.20260615.042549Z
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.
- package/lib/{types/ActivityCollection.d.ts → ActivityCollection.d.ts} +7 -7
- package/lib/ActivityCollection.d.ts.map +1 -0
- package/lib/{esm/ActivityCollection.js → ActivityCollection.js} +6 -6
- package/lib/ActivityCollection.js.map +1 -0
- package/lib/{types/ContentTypesCollection.d.ts → ContentTypesCollection.d.ts} +2 -2
- package/lib/ContentTypesCollection.d.ts.map +1 -0
- package/lib/{esm/ContentTypesCollection.js → ContentTypesCollection.js} +3 -3
- package/lib/ContentTypesCollection.js.map +1 -0
- package/lib/{types/InteractionCollection.d.ts → InteractionCollection.d.ts} +2 -2
- package/lib/InteractionCollection.d.ts.map +1 -0
- package/lib/{esm/InteractionCollection.js → InteractionCollection.js} +3 -3
- package/lib/InteractionCollection.js.map +1 -0
- package/lib/{types/RenderingTemplateCollection.d.ts → RenderingTemplateCollection.d.ts} +1 -1
- package/lib/RenderingTemplateCollection.d.ts.map +1 -0
- package/lib/{esm/RenderingTemplateCollection.js → RenderingTemplateCollection.js} +3 -3
- package/lib/RenderingTemplateCollection.js.map +1 -0
- package/lib/{types/SkillCollection.d.ts → SkillCollection.d.ts} +5 -5
- package/lib/SkillCollection.d.ts.map +1 -0
- package/lib/{esm/SkillCollection.js → SkillCollection.js} +68 -51
- package/lib/SkillCollection.js.map +1 -0
- package/lib/{types/ToolCollection.d.ts → ToolCollection.d.ts} +10 -10
- package/lib/ToolCollection.d.ts.map +1 -0
- package/lib/{esm/ToolCollection.js → ToolCollection.js} +21 -18
- package/lib/ToolCollection.js.map +1 -0
- package/lib/ToolRegistry.d.ts +22 -0
- package/lib/ToolRegistry.d.ts.map +1 -0
- package/lib/{esm/ToolRegistry.js → ToolRegistry.js} +6 -36
- package/lib/ToolRegistry.js.map +1 -0
- package/lib/{types/auth.d.ts → auth.d.ts} +5 -5
- package/lib/auth.d.ts.map +1 -0
- package/lib/{esm/auth.js → auth.js} +23 -17
- package/lib/auth.js.map +1 -0
- package/lib/build/validate.d.ts.map +1 -0
- package/lib/build/validate.js.map +1 -0
- package/lib/copy-assets.d.ts.map +1 -0
- package/lib/{esm/copy-assets.js → copy-assets.js} +4 -7
- package/lib/copy-assets.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/server/activities.d.ts +4 -0
- package/lib/server/activities.d.ts.map +1 -0
- package/lib/{esm/server → server}/activities.js +12 -9
- package/lib/server/activities.js.map +1 -0
- package/lib/server/app-package.d.ts +12 -0
- package/lib/server/app-package.d.ts.map +1 -0
- package/lib/server/app-package.js +197 -0
- package/lib/server/app-package.js.map +1 -0
- package/lib/server/content-types.d.ts +4 -0
- package/lib/server/content-types.d.ts.map +1 -0
- package/lib/server/content-types.js +100 -0
- package/lib/server/content-types.js.map +1 -0
- package/lib/server/dashboards.d.ts +4 -0
- package/lib/server/dashboards.d.ts.map +1 -0
- package/lib/server/dashboards.js +25 -0
- package/lib/server/dashboards.js.map +1 -0
- package/lib/server/interactions.d.ts +4 -0
- package/lib/server/interactions.d.ts.map +1 -0
- package/lib/{esm/server → server}/interactions.js +16 -16
- package/lib/server/interactions.js.map +1 -0
- package/lib/server/mcp.d.ts +4 -0
- package/lib/server/mcp.d.ts.map +1 -0
- package/lib/{esm/server → server}/mcp.js +5 -4
- package/lib/server/mcp.js.map +1 -0
- package/lib/server/processes.d.ts +4 -0
- package/lib/server/processes.d.ts.map +1 -0
- package/lib/server/processes.js +26 -0
- package/lib/server/processes.js.map +1 -0
- package/lib/server/site.d.ts +4 -0
- package/lib/server/site.d.ts.map +1 -0
- package/lib/{esm/server → server}/site.js +4 -2
- package/lib/server/site.js.map +1 -0
- package/lib/server/skills.d.ts +4 -0
- package/lib/server/skills.d.ts.map +1 -0
- package/lib/{esm/server → server}/skills.js +14 -12
- package/lib/server/skills.js.map +1 -0
- package/lib/server/templates.d.ts +4 -0
- package/lib/server/templates.d.ts.map +1 -0
- package/lib/{esm/server → server}/templates.js +10 -10
- package/lib/server/templates.js.map +1 -0
- package/lib/server/tools.d.ts +4 -0
- package/lib/server/tools.d.ts.map +1 -0
- package/lib/{esm/server → server}/tools.js +7 -9
- package/lib/server/tools.js.map +1 -0
- package/lib/{types/server → server}/types.d.ts +21 -16
- package/lib/server/types.d.ts.map +1 -0
- package/lib/{cjs → server}/types.js.map +1 -1
- package/lib/server/widgets.d.ts +4 -0
- package/lib/server/widgets.d.ts.map +1 -0
- package/lib/server/widgets.js.map +1 -0
- package/lib/{types/server.d.ts → server.d.ts} +3 -3
- package/lib/server.d.ts.map +1 -0
- package/lib/{esm/server.js → server.js} +28 -22
- package/lib/server.js.map +1 -0
- package/lib/site/styles.d.ts.map +1 -0
- package/lib/{esm/site → site}/styles.js.map +1 -1
- package/lib/{types/site → site}/templates.d.ts +9 -9
- package/lib/site/templates.d.ts.map +1 -0
- package/lib/{esm/site → site}/templates.js +152 -98
- package/lib/site/templates.js.map +1 -0
- package/lib/{types/types.d.ts → types.d.ts} +29 -16
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/{esm/utils.js → utils.js} +11 -5
- package/lib/utils.js.map +1 -0
- package/package.json +20 -22
- package/src/ActivityCollection.test.ts +60 -59
- package/src/ActivityCollection.ts +27 -20
- package/src/ContentTypesCollection.ts +6 -9
- package/src/InteractionCollection.ts +6 -8
- package/src/RenderingTemplateCollection.ts +49 -51
- package/src/SkillCollection.ts +91 -72
- package/src/ToolCollection.ts +52 -43
- package/src/ToolRegistry.ts +20 -50
- package/src/auth.ts +35 -27
- package/src/copy-assets.ts +5 -12
- package/src/index.ts +15 -15
- package/src/server/activities.test.ts +70 -67
- package/src/server/activities.ts +17 -13
- package/src/server/app-package.test.ts +140 -0
- package/src/server/app-package.ts +115 -52
- package/src/server/content-types.test.ts +64 -0
- package/src/server/content-types.ts +53 -25
- package/src/server/dashboards.ts +31 -0
- package/src/server/interactions.ts +29 -28
- package/src/server/mcp.ts +16 -16
- package/src/server/processes.ts +35 -0
- package/src/server/site.ts +7 -15
- package/src/server/skills.ts +19 -18
- package/src/server/templates.ts +82 -80
- package/src/server/tools.ts +12 -16
- package/src/server/types.ts +29 -20
- package/src/server/widgets.ts +5 -9
- package/src/server.ts +55 -47
- package/src/site/styles.ts +1 -1
- package/src/site/templates.ts +259 -157
- package/src/types.ts +55 -31
- package/src/utils.ts +11 -6
- package/lib/cjs/ActivityCollection.js +0 -93
- package/lib/cjs/ActivityCollection.js.map +0 -1
- package/lib/cjs/ContentTypesCollection.js +0 -43
- package/lib/cjs/ContentTypesCollection.js.map +0 -1
- package/lib/cjs/InteractionCollection.js +0 -43
- package/lib/cjs/InteractionCollection.js.map +0 -1
- package/lib/cjs/RenderingTemplateCollection.js +0 -43
- package/lib/cjs/RenderingTemplateCollection.js.map +0 -1
- package/lib/cjs/SkillCollection.js +0 -384
- package/lib/cjs/SkillCollection.js.map +0 -1
- package/lib/cjs/ToolCollection.js +0 -221
- package/lib/cjs/ToolCollection.js.map +0 -1
- package/lib/cjs/ToolRegistry.js +0 -95
- package/lib/cjs/ToolRegistry.js.map +0 -1
- package/lib/cjs/auth.js +0 -131
- package/lib/cjs/auth.js.map +0 -1
- package/lib/cjs/build/validate.js +0 -7
- package/lib/cjs/build/validate.js.map +0 -1
- package/lib/cjs/copy-assets.js +0 -84
- package/lib/cjs/copy-assets.js.map +0 -1
- package/lib/cjs/index.js +0 -34
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/server/activities.js +0 -103
- package/lib/cjs/server/activities.js.map +0 -1
- package/lib/cjs/server/app-package.js +0 -154
- package/lib/cjs/server/app-package.js.map +0 -1
- package/lib/cjs/server/content-types.js +0 -73
- package/lib/cjs/server/content-types.js.map +0 -1
- package/lib/cjs/server/interactions.js +0 -101
- package/lib/cjs/server/interactions.js.map +0 -1
- package/lib/cjs/server/mcp.js +0 -45
- package/lib/cjs/server/mcp.js.map +0 -1
- package/lib/cjs/server/site.js +0 -48
- package/lib/cjs/server/site.js.map +0 -1
- package/lib/cjs/server/skills.js +0 -124
- package/lib/cjs/server/skills.js.map +0 -1
- package/lib/cjs/server/templates.js +0 -67
- package/lib/cjs/server/templates.js.map +0 -1
- package/lib/cjs/server/tools.js +0 -87
- package/lib/cjs/server/tools.js.map +0 -1
- package/lib/cjs/server/types.js +0 -3
- package/lib/cjs/server/types.js.map +0 -1
- package/lib/cjs/server/widgets.js +0 -27
- package/lib/cjs/server/widgets.js.map +0 -1
- package/lib/cjs/server.js +0 -142
- package/lib/cjs/server.js.map +0 -1
- package/lib/cjs/site/styles.js +0 -692
- package/lib/cjs/site/styles.js.map +0 -1
- package/lib/cjs/site/templates.js +0 -1320
- package/lib/cjs/site/templates.js.map +0 -1
- package/lib/cjs/types.js +0 -3
- package/lib/cjs/utils.js +0 -44
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/ActivityCollection.js.map +0 -1
- package/lib/esm/ContentTypesCollection.js.map +0 -1
- package/lib/esm/InteractionCollection.js.map +0 -1
- package/lib/esm/RenderingTemplateCollection.js.map +0 -1
- package/lib/esm/SkillCollection.js.map +0 -1
- package/lib/esm/ToolCollection.js.map +0 -1
- package/lib/esm/ToolRegistry.js.map +0 -1
- package/lib/esm/auth.js.map +0 -1
- package/lib/esm/build/validate.js.map +0 -1
- package/lib/esm/copy-assets.js.map +0 -1
- package/lib/esm/index.js +0 -14
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/server/activities.js.map +0 -1
- package/lib/esm/server/app-package.js +0 -151
- package/lib/esm/server/app-package.js.map +0 -1
- package/lib/esm/server/content-types.js +0 -70
- package/lib/esm/server/content-types.js.map +0 -1
- package/lib/esm/server/interactions.js.map +0 -1
- package/lib/esm/server/mcp.js.map +0 -1
- package/lib/esm/server/site.js.map +0 -1
- package/lib/esm/server/skills.js.map +0 -1
- package/lib/esm/server/templates.js.map +0 -1
- package/lib/esm/server/tools.js.map +0 -1
- package/lib/esm/server/types.js.map +0 -1
- package/lib/esm/server/widgets.js.map +0 -1
- package/lib/esm/server.js.map +0 -1
- package/lib/esm/site/templates.js.map +0 -1
- package/lib/esm/types.js.map +0 -1
- package/lib/esm/utils.js.map +0 -1
- package/lib/types/ActivityCollection.d.ts.map +0 -1
- package/lib/types/ContentTypesCollection.d.ts.map +0 -1
- package/lib/types/InteractionCollection.d.ts.map +0 -1
- package/lib/types/RenderingTemplateCollection.d.ts.map +0 -1
- package/lib/types/SkillCollection.d.ts.map +0 -1
- package/lib/types/ToolCollection.d.ts.map +0 -1
- package/lib/types/ToolRegistry.d.ts +0 -22
- package/lib/types/ToolRegistry.d.ts.map +0 -1
- package/lib/types/auth.d.ts.map +0 -1
- package/lib/types/build/validate.d.ts.map +0 -1
- package/lib/types/copy-assets.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -14
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/server/activities.d.ts +0 -4
- package/lib/types/server/activities.d.ts.map +0 -1
- package/lib/types/server/app-package.d.ts +0 -4
- package/lib/types/server/app-package.d.ts.map +0 -1
- package/lib/types/server/content-types.d.ts +0 -4
- package/lib/types/server/content-types.d.ts.map +0 -1
- package/lib/types/server/interactions.d.ts +0 -4
- package/lib/types/server/interactions.d.ts.map +0 -1
- package/lib/types/server/mcp.d.ts +0 -4
- package/lib/types/server/mcp.d.ts.map +0 -1
- package/lib/types/server/site.d.ts +0 -4
- package/lib/types/server/site.d.ts.map +0 -1
- package/lib/types/server/skills.d.ts +0 -4
- package/lib/types/server/skills.d.ts.map +0 -1
- package/lib/types/server/templates.d.ts +0 -4
- package/lib/types/server/templates.d.ts.map +0 -1
- package/lib/types/server/tools.d.ts +0 -4
- package/lib/types/server/tools.d.ts.map +0 -1
- package/lib/types/server/types.d.ts.map +0 -1
- package/lib/types/server/widgets.d.ts +0 -4
- package/lib/types/server/widgets.d.ts.map +0 -1
- package/lib/types/server.d.ts.map +0 -1
- package/lib/types/site/styles.d.ts.map +0 -1
- package/lib/types/site/templates.d.ts.map +0 -1
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils.d.ts.map +0 -1
- /package/lib/{types/build → build}/validate.d.ts +0 -0
- /package/lib/{esm/build → build}/validate.js +0 -0
- /package/lib/{types/copy-assets.d.ts → copy-assets.d.ts} +0 -0
- /package/lib/{esm/server → server}/types.js +0 -0
- /package/lib/{esm/server → server}/widgets.js +0 -0
- /package/lib/{types/site → site}/styles.d.ts +0 -0
- /package/lib/{esm/site → site}/styles.js +0 -0
- /package/lib/{esm/types.js → types.js} +0 -0
- /package/lib/{types/utils.d.ts → utils.d.ts} +0 -0
|
@@ -1,51 +1,49 @@
|
|
|
1
|
-
import { CollectionProperties, ICollection, RenderingTemplateDefinition } from
|
|
2
|
-
import { kebabCaseToTitle } from
|
|
3
|
-
|
|
4
|
-
export interface RenderingTemplateCollectionProps extends CollectionProperties {
|
|
5
|
-
templates: RenderingTemplateDefinition[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class RenderingTemplateCollection implements ICollection<RenderingTemplateDefinition> {
|
|
9
|
-
templates: RenderingTemplateDefinition[];
|
|
10
|
-
name: string;
|
|
11
|
-
title?: string;
|
|
12
|
-
icon?: string;
|
|
13
|
-
description?: string;
|
|
14
|
-
|
|
15
|
-
constructor({
|
|
16
|
-
name
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
import type { CollectionProperties, ICollection, RenderingTemplateDefinition } from './types.js';
|
|
2
|
+
import { kebabCaseToTitle } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export interface RenderingTemplateCollectionProps extends CollectionProperties {
|
|
5
|
+
templates: RenderingTemplateDefinition[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class RenderingTemplateCollection implements ICollection<RenderingTemplateDefinition> {
|
|
9
|
+
templates: RenderingTemplateDefinition[];
|
|
10
|
+
name: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
|
|
15
|
+
constructor({ name, title, icon, description, templates }: RenderingTemplateCollectionProps) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.title = title || kebabCaseToTitle(name);
|
|
18
|
+
this.icon = icon;
|
|
19
|
+
this.description = description;
|
|
20
|
+
this.templates = templates;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getTemplateDefinitions() {
|
|
24
|
+
return this.templates;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getTemplate(name: string): RenderingTemplateDefinition | undefined {
|
|
28
|
+
return this.templates.find((t) => t.name === name);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
[Symbol.iterator](): Iterator<RenderingTemplateDefinition> {
|
|
32
|
+
let index = 0;
|
|
33
|
+
const templates = this.templates;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
next(): IteratorResult<RenderingTemplateDefinition> {
|
|
37
|
+
if (index < templates.length) {
|
|
38
|
+
return { value: templates[index++], done: false };
|
|
39
|
+
} else {
|
|
40
|
+
return { done: true, value: undefined };
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
map<U>(callback: (template: RenderingTemplateDefinition, index: number) => U): U[] {
|
|
47
|
+
return this.templates.map(callback);
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/SkillCollection.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { ToolDefinition } from '@llumiverse/common';
|
|
4
|
+
import type { AgentToolDefinition } from '@vertesia/common';
|
|
5
|
+
import type { Context } from 'hono';
|
|
6
|
+
import { HTTPException } from 'hono/http-exception';
|
|
7
|
+
import type { ToolContext } from './server/types.js';
|
|
7
8
|
import type {
|
|
8
9
|
CollectionProperties,
|
|
9
10
|
ICollection,
|
|
@@ -14,9 +15,8 @@ import type {
|
|
|
14
15
|
ToolExecutionPayload,
|
|
15
16
|
ToolExecutionResult,
|
|
16
17
|
ToolUseContext,
|
|
17
|
-
} from
|
|
18
|
-
import { kebabCaseToTitle } from
|
|
19
|
-
import { AgentToolDefinition } from "@vertesia/common";
|
|
18
|
+
} from './types.js';
|
|
19
|
+
import { kebabCaseToTitle } from './utils.js';
|
|
20
20
|
|
|
21
21
|
export interface SkillCollectionProperties extends CollectionProperties {
|
|
22
22
|
/**
|
|
@@ -57,7 +57,7 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
57
57
|
this.title = title || kebabCaseToTitle(name);
|
|
58
58
|
this.icon = icon;
|
|
59
59
|
this.description = description;
|
|
60
|
-
this.skills = new Map(skills.map(s => [s.name, s]));
|
|
60
|
+
this.skills = new Map(skills.map((s) => [s.name, s]));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
[Symbol.iterator](): Iterator<SkillDefinition> {
|
|
@@ -86,31 +86,31 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
86
86
|
* Get skills exposed as tool definitions.
|
|
87
87
|
* This allows skills to appear alongside regular tools.
|
|
88
88
|
* When called, they return rendered instructions.
|
|
89
|
-
* Includes
|
|
89
|
+
* Includes tools for dynamic tool discovery.
|
|
90
90
|
*/
|
|
91
91
|
getToolDefinitions(filterContext?: ToolUseContext): AgentToolDefinition[] {
|
|
92
92
|
const defaultSchema: ToolDefinition['input_schema'] = {
|
|
93
93
|
type: 'object',
|
|
94
94
|
properties: {
|
|
95
95
|
context: {
|
|
96
|
-
type:
|
|
97
|
-
description:
|
|
98
|
-
}
|
|
99
|
-
}
|
|
96
|
+
type: 'string',
|
|
97
|
+
description: 'Additional context or specific requirements for this task',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
let skills = Array.from(this.skills.values());
|
|
103
103
|
if (filterContext) {
|
|
104
|
-
skills = skills.filter(skill => {
|
|
104
|
+
skills = skills.filter((skill) => {
|
|
105
105
|
return skill.isEnabled ? skill.isEnabled(filterContext) : true;
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
return skills.map(skill => {
|
|
109
|
+
return skills.map((skill) => {
|
|
110
110
|
// Build description with related tools info if available
|
|
111
111
|
let description = `[Skill] ${skill.description}. Returns contextual instructions for this task.`;
|
|
112
|
-
if (skill.
|
|
113
|
-
description += ` Unlocks tools: ${skill.
|
|
112
|
+
if (skill.tools && skill.tools.length > 0) {
|
|
113
|
+
description += ` Unlocks tools: ${skill.tools.join(', ')}.`;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
return {
|
|
@@ -118,7 +118,7 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
118
118
|
name: `learn_${skill.name}`,
|
|
119
119
|
description,
|
|
120
120
|
input_schema: skill.input_schema || defaultSchema,
|
|
121
|
-
|
|
121
|
+
tools: skill.tools,
|
|
122
122
|
category: this.name,
|
|
123
123
|
};
|
|
124
124
|
});
|
|
@@ -132,7 +132,7 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
132
132
|
title: this.title || this.name,
|
|
133
133
|
description: this.description || `Skills: ${this.name}`,
|
|
134
134
|
src: `${baseUrl}/api/skills/${this.name}`,
|
|
135
|
-
tools: this.getToolDefinitions()
|
|
135
|
+
tools: this.getToolDefinitions(),
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -164,43 +164,41 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
164
164
|
* @param ctx - Hono context
|
|
165
165
|
* @param preParsedPayload - Optional pre-parsed payload (used when routing from root endpoint)
|
|
166
166
|
*/
|
|
167
|
-
async execute(ctx: Context, preParsedPayload?: ToolExecutionPayload
|
|
167
|
+
async execute(ctx: Context, preParsedPayload?: ToolExecutionPayload): Promise<Response> {
|
|
168
168
|
const toolCtx = ctx as ToolContext;
|
|
169
|
-
|
|
169
|
+
const payload = preParsedPayload ?? toolCtx.payload;
|
|
170
170
|
try {
|
|
171
171
|
if (!payload) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
throw new HTTPException(400, {
|
|
177
|
-
message: 'Invalid or missing skill execution payload. Expected { tool_use: { id, tool_name, tool_input? }, metadata? }'
|
|
178
|
-
});
|
|
179
|
-
}
|
|
172
|
+
throw new HTTPException(400, {
|
|
173
|
+
message:
|
|
174
|
+
'Invalid or missing skill execution payload. Expected { tool_use: { id, tool_name, tool_input? }, metadata? }',
|
|
175
|
+
});
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
const toolName = payload.tool_use.tool_name;
|
|
183
179
|
|
|
184
180
|
// Extract skill name from tool name (remove "learn_" prefix if present)
|
|
185
|
-
const skillName = toolName.startsWith('learn_')
|
|
186
|
-
? toolName.replace('learn_', '')
|
|
187
|
-
: toolName;
|
|
181
|
+
const skillName = toolName.startsWith('learn_') ? toolName.replace('learn_', '') : toolName;
|
|
188
182
|
|
|
189
183
|
const skill = this.skills.get(skillName);
|
|
190
184
|
|
|
191
185
|
if (!skill) {
|
|
192
|
-
console.warn(
|
|
186
|
+
console.warn('[SkillCollection] Skill not found', {
|
|
193
187
|
collection: this.name,
|
|
194
188
|
requestedSkill: skillName,
|
|
195
189
|
toolName,
|
|
196
190
|
availableSkills: Array.from(this.skills.keys()),
|
|
197
191
|
});
|
|
198
192
|
throw new HTTPException(404, {
|
|
199
|
-
message: `Skill not found: ${skillName}
|
|
193
|
+
message: `Skill not found: ${skillName}`,
|
|
200
194
|
});
|
|
201
195
|
}
|
|
202
196
|
|
|
203
|
-
const
|
|
197
|
+
const input = payload.tool_use.tool_input;
|
|
198
|
+
const data =
|
|
199
|
+
typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
200
|
+
? (input as Record<string, unknown>)
|
|
201
|
+
: {};
|
|
204
202
|
const result = await this.renderSkill(skill, data);
|
|
205
203
|
|
|
206
204
|
// TODO: If skill.execution is set, run via Daytona
|
|
@@ -214,46 +212,48 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
214
212
|
skill_name: skill.name,
|
|
215
213
|
content_type: skill.content_type,
|
|
216
214
|
execution: skill.execution,
|
|
217
|
-
}
|
|
215
|
+
},
|
|
218
216
|
} satisfies ToolExecutionResult & { tool_use_id: string });
|
|
219
|
-
} catch (err:
|
|
220
|
-
const status = err.status
|
|
217
|
+
} catch (err: unknown) {
|
|
218
|
+
const status = err instanceof HTTPException ? err.status : 500;
|
|
219
|
+
const message = err instanceof Error ? err.message : 'Error executing skill';
|
|
220
|
+
const stack = err instanceof Error ? err.stack : undefined;
|
|
221
221
|
const toolName = payload?.tool_use?.tool_name;
|
|
222
222
|
const toolUseId = payload?.tool_use?.id;
|
|
223
223
|
|
|
224
224
|
if (status >= 500) {
|
|
225
|
-
console.error(
|
|
225
|
+
console.error('[SkillCollection] Skill execution failed', {
|
|
226
226
|
collection: this.name,
|
|
227
227
|
skill: toolName,
|
|
228
228
|
toolUseId,
|
|
229
|
-
error:
|
|
229
|
+
error: message,
|
|
230
230
|
status,
|
|
231
231
|
toolInput: payload?.tool_use?.tool_input,
|
|
232
|
-
stack
|
|
232
|
+
stack,
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
return ctx.json(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
return ctx.json(
|
|
237
|
+
{
|
|
238
|
+
tool_use_id: toolUseId || 'unknown',
|
|
239
|
+
is_error: true,
|
|
240
|
+
content: message,
|
|
241
|
+
},
|
|
242
|
+
status,
|
|
243
|
+
);
|
|
241
244
|
}
|
|
242
245
|
}
|
|
243
246
|
|
|
244
247
|
/**
|
|
245
248
|
* Render skill instructions (static or dynamic)
|
|
246
249
|
*/
|
|
247
|
-
private async renderSkill(
|
|
248
|
-
skill: SkillDefinition,
|
|
249
|
-
_data: Record<string, unknown>
|
|
250
|
-
): Promise<SkillExecutionResult> {
|
|
250
|
+
private async renderSkill(skill: SkillDefinition, _data: Record<string, unknown>): Promise<SkillExecutionResult> {
|
|
251
251
|
const instructions = skill.instructions;
|
|
252
252
|
|
|
253
253
|
if (skill.content_type === 'jst') {
|
|
254
254
|
// JST templates are not currently supported
|
|
255
255
|
throw new HTTPException(501, {
|
|
256
|
-
message: `JST templates are not currently supported. Use 'md' content type instead
|
|
256
|
+
message: `JST templates are not currently supported. Use 'md' content type instead.`,
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -267,9 +267,9 @@ export class SkillCollection implements ICollection<SkillDefinition> {
|
|
|
267
267
|
// ================== Skill Parser ==================
|
|
268
268
|
|
|
269
269
|
interface SkillFrontmatter {
|
|
270
|
-
name
|
|
270
|
+
name?: string;
|
|
271
271
|
title?: string;
|
|
272
|
-
description
|
|
272
|
+
description?: string;
|
|
273
273
|
keywords?: string[];
|
|
274
274
|
tools?: string[];
|
|
275
275
|
data_patterns?: string[];
|
|
@@ -299,15 +299,12 @@ interface SkillFrontmatter {
|
|
|
299
299
|
* Your markdown/jst content here...
|
|
300
300
|
* ```
|
|
301
301
|
*/
|
|
302
|
-
export function parseSkillFile(
|
|
303
|
-
content: string,
|
|
304
|
-
contentType: SkillContentType
|
|
305
|
-
): SkillDefinition {
|
|
302
|
+
export function parseSkillFile(content: string, contentType: SkillContentType): SkillDefinition {
|
|
306
303
|
// Parse YAML frontmatter
|
|
307
304
|
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
308
305
|
|
|
309
306
|
if (!frontmatterMatch) {
|
|
310
|
-
throw new Error(
|
|
307
|
+
throw new Error('Invalid skill file: missing YAML frontmatter');
|
|
311
308
|
}
|
|
312
309
|
|
|
313
310
|
const [, yamlContent, body] = frontmatterMatch;
|
|
@@ -357,7 +354,7 @@ export function parseSkillFile(
|
|
|
357
354
|
|
|
358
355
|
// Related tools from frontmatter
|
|
359
356
|
if (frontmatter.tools) {
|
|
360
|
-
skill.
|
|
357
|
+
skill.tools = frontmatter.tools;
|
|
361
358
|
}
|
|
362
359
|
|
|
363
360
|
return skill;
|
|
@@ -367,7 +364,7 @@ export function parseSkillFile(
|
|
|
367
364
|
* Simple YAML frontmatter parser (handles basic key: value and arrays)
|
|
368
365
|
*/
|
|
369
366
|
function parseYamlFrontmatter(yaml: string): SkillFrontmatter {
|
|
370
|
-
const result: Record<string,
|
|
367
|
+
const result: Record<string, unknown> = {};
|
|
371
368
|
const lines = yaml.split('\n');
|
|
372
369
|
|
|
373
370
|
for (const line of lines) {
|
|
@@ -382,19 +379,41 @@ function parseYamlFrontmatter(yaml: string): SkillFrontmatter {
|
|
|
382
379
|
|
|
383
380
|
// Handle array syntax: [item1, item2]
|
|
384
381
|
if (value.startsWith('[') && value.endsWith(']')) {
|
|
385
|
-
const items = value
|
|
386
|
-
|
|
382
|
+
const items = value
|
|
383
|
+
.slice(1, -1)
|
|
384
|
+
.split(',')
|
|
385
|
+
.map((s) => s.trim());
|
|
386
|
+
result[key] = items.filter((s) => s.length > 0);
|
|
387
387
|
} else {
|
|
388
388
|
// Remove quotes if present
|
|
389
|
-
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
390
|
-
(value.startsWith("'") && value.endsWith("'"))) {
|
|
389
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
391
390
|
value = value.slice(1, -1);
|
|
392
391
|
}
|
|
393
392
|
result[key] = value;
|
|
394
393
|
}
|
|
395
394
|
}
|
|
396
395
|
|
|
397
|
-
return
|
|
396
|
+
return {
|
|
397
|
+
name: asString(result.name),
|
|
398
|
+
title: asString(result.title),
|
|
399
|
+
description: asString(result.description),
|
|
400
|
+
keywords: asStringArray(result.keywords),
|
|
401
|
+
tools: asStringArray(result.tools),
|
|
402
|
+
data_patterns: asStringArray(result.data_patterns),
|
|
403
|
+
language: asString(result.language),
|
|
404
|
+
packages: asStringArray(result.packages),
|
|
405
|
+
system_packages: asStringArray(result.system_packages),
|
|
406
|
+
widgets: asStringArray(result.widgets),
|
|
407
|
+
scripts: asStringArray(result.scripts),
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function asString(value: unknown): string | undefined {
|
|
412
|
+
return typeof value === 'string' ? value : undefined;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function asStringArray(value: unknown): string[] | undefined {
|
|
416
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : undefined;
|
|
398
417
|
}
|
|
399
418
|
|
|
400
419
|
/**
|
|
@@ -402,7 +421,7 @@ function parseYamlFrontmatter(yaml: string): SkillFrontmatter {
|
|
|
402
421
|
*/
|
|
403
422
|
export async function loadSkillFromFile(
|
|
404
423
|
filePath: string,
|
|
405
|
-
fs: { readFile: (path: string, encoding: string) => Promise<string> }
|
|
424
|
+
fs: { readFile: (path: string, encoding: string) => Promise<string> },
|
|
406
425
|
): Promise<SkillDefinition> {
|
|
407
426
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
408
427
|
const contentType: SkillContentType = filePath.endsWith('.jst') ? 'jst' : 'md';
|
|
@@ -445,17 +464,17 @@ export function loadSkillsFromDirectory(dirPath: string): SkillDefinition[] {
|
|
|
445
464
|
if (!stat.isDirectory()) continue;
|
|
446
465
|
|
|
447
466
|
// Look for SKILL.md or SKILL.jst
|
|
448
|
-
const mdPath = join(entryPath,
|
|
449
|
-
const jstPath = join(entryPath,
|
|
467
|
+
const mdPath = join(entryPath, 'SKILL.md');
|
|
468
|
+
const jstPath = join(entryPath, 'SKILL.jst');
|
|
450
469
|
|
|
451
470
|
let content: string | undefined;
|
|
452
471
|
let contentType: SkillContentType = 'md';
|
|
453
472
|
|
|
454
473
|
if (existsSync(mdPath)) {
|
|
455
|
-
content = readFileSync(mdPath,
|
|
474
|
+
content = readFileSync(mdPath, 'utf-8');
|
|
456
475
|
contentType = 'md';
|
|
457
476
|
} else if (existsSync(jstPath)) {
|
|
458
|
-
content = readFileSync(jstPath,
|
|
477
|
+
content = readFileSync(jstPath, 'utf-8');
|
|
459
478
|
contentType = 'jst';
|
|
460
479
|
}
|
|
461
480
|
|
package/src/ToolCollection.ts
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { authorize } from
|
|
8
|
-
import { ToolContext } from
|
|
9
|
-
import { ToolRegistry } from
|
|
10
|
-
import type {
|
|
11
|
-
|
|
1
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import type { AgentToolDefinition } from '@vertesia/common';
|
|
5
|
+
import type { Context } from 'hono';
|
|
6
|
+
import { HTTPException } from 'hono/http-exception';
|
|
7
|
+
import { authorize } from './auth.js';
|
|
8
|
+
import type { ToolContext } from './server/types.js';
|
|
9
|
+
import { ToolRegistry } from './ToolRegistry.js';
|
|
10
|
+
import type {
|
|
11
|
+
CollectionProperties,
|
|
12
|
+
ICollection,
|
|
13
|
+
Tool,
|
|
14
|
+
ToolExecutionPayload,
|
|
15
|
+
ToolExecutionResponse,
|
|
16
|
+
ToolExecutionResponseError,
|
|
17
|
+
ToolUseContext,
|
|
18
|
+
} from './types.js';
|
|
19
|
+
import { kebabCaseToTitle } from './utils.js';
|
|
12
20
|
|
|
13
21
|
export interface ToolCollectionProperties extends CollectionProperties {
|
|
14
22
|
/**
|
|
15
23
|
* The tools
|
|
16
24
|
*/
|
|
17
|
-
tools: Tool
|
|
25
|
+
tools: Tool[];
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
/**
|
|
21
29
|
* Implements a tools collection endpoint
|
|
22
30
|
*/
|
|
23
|
-
export class ToolCollection implements ICollection<Tool
|
|
24
|
-
|
|
31
|
+
export class ToolCollection implements ICollection<Tool> {
|
|
25
32
|
/**
|
|
26
33
|
* A kebab case collection name. Must only contains alphanumeric and dash characters,
|
|
27
34
|
* The name can be used to generate the path where the collection is exposed.
|
|
@@ -29,7 +36,7 @@ export class ToolCollection implements ICollection<Tool<any>> {
|
|
|
29
36
|
*/
|
|
30
37
|
name: string;
|
|
31
38
|
/**
|
|
32
|
-
* Optional title for UI display.
|
|
39
|
+
* Optional title for UI display.
|
|
33
40
|
* If not provided the title will be generated form the kebab case name by replacing - with spaces and upper casing first letter in words.
|
|
34
41
|
*/
|
|
35
42
|
title?: string;
|
|
@@ -38,7 +45,7 @@ export class ToolCollection implements ICollection<Tool<any>> {
|
|
|
38
45
|
*/
|
|
39
46
|
icon?: string;
|
|
40
47
|
/**
|
|
41
|
-
* A short description
|
|
48
|
+
* A short description
|
|
42
49
|
*/
|
|
43
50
|
description?: string;
|
|
44
51
|
/**
|
|
@@ -46,9 +53,7 @@ export class ToolCollection implements ICollection<Tool<any>> {
|
|
|
46
53
|
*/
|
|
47
54
|
tools: ToolRegistry;
|
|
48
55
|
|
|
49
|
-
constructor({
|
|
50
|
-
name, title, icon, description, tools
|
|
51
|
-
}: ToolCollectionProperties) {
|
|
56
|
+
constructor({ name, title, icon, description, tools }: ToolCollectionProperties) {
|
|
52
57
|
this.name = name;
|
|
53
58
|
this.title = title || kebabCaseToTitle(name);
|
|
54
59
|
this.icon = icon;
|
|
@@ -57,27 +62,27 @@ export class ToolCollection implements ICollection<Tool<any>> {
|
|
|
57
62
|
this.tools = new ToolRegistry(name, tools);
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
[Symbol.iterator](): Iterator<Tool
|
|
65
|
+
[Symbol.iterator](): Iterator<Tool> {
|
|
61
66
|
let index = 0;
|
|
62
67
|
const tools = this.tools.getTools();
|
|
63
68
|
|
|
64
69
|
return {
|
|
65
|
-
next(): IteratorResult<Tool
|
|
70
|
+
next(): IteratorResult<Tool> {
|
|
66
71
|
if (index < tools.length) {
|
|
67
72
|
return { value: tools[index++], done: false };
|
|
68
73
|
} else {
|
|
69
74
|
return { done: true, value: undefined };
|
|
70
75
|
}
|
|
71
|
-
}
|
|
76
|
+
},
|
|
72
77
|
};
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
map<U>(callback: (tool: Tool
|
|
80
|
+
map<U>(callback: (tool: Tool, index: number) => U): U[] {
|
|
76
81
|
return this.tools.getTools().map(callback);
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
async execute(ctx: Context, preParsedPayload?: ToolExecutionPayload
|
|
80
|
-
let payload: ToolExecutionPayload
|
|
84
|
+
async execute(ctx: Context, preParsedPayload?: ToolExecutionPayload): Promise<Response> {
|
|
85
|
+
let payload: ToolExecutionPayload | undefined = preParsedPayload;
|
|
81
86
|
try {
|
|
82
87
|
if (!payload) {
|
|
83
88
|
payload = await readPayload(ctx);
|
|
@@ -99,27 +104,33 @@ export class ToolCollection implements ICollection<Tool<any>> {
|
|
|
99
104
|
const r = await this.tools.runTool(payload, session);
|
|
100
105
|
return ctx.json({
|
|
101
106
|
...r,
|
|
102
|
-
tool_use_id: payload.tool_use.id
|
|
107
|
+
tool_use_id: payload.tool_use.id,
|
|
103
108
|
} satisfies ToolExecutionResponse);
|
|
104
|
-
} catch (err:
|
|
105
|
-
|
|
109
|
+
} catch (err: unknown) {
|
|
110
|
+
// HTTPException ?
|
|
111
|
+
const status = err instanceof HTTPException ? err.status : 500;
|
|
112
|
+
const message = err instanceof Error ? err.message : 'Error executing tool';
|
|
113
|
+
const stack = err instanceof Error ? err.stack : undefined;
|
|
106
114
|
const toolName = payload?.tool_use?.tool_name;
|
|
107
115
|
const toolUseId = payload?.tool_use?.id;
|
|
108
116
|
|
|
109
|
-
console.error(
|
|
117
|
+
console.error('[ToolCollection] Tool execution failed', {
|
|
110
118
|
collection: this.name,
|
|
111
119
|
tool: toolName,
|
|
112
120
|
toolUseId,
|
|
113
|
-
error:
|
|
121
|
+
error: message,
|
|
114
122
|
status,
|
|
115
|
-
stack
|
|
123
|
+
stack,
|
|
116
124
|
});
|
|
117
125
|
|
|
118
|
-
return ctx.json(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
return ctx.json(
|
|
127
|
+
{
|
|
128
|
+
tool_use_id: toolUseId || 'undefined',
|
|
129
|
+
error: message,
|
|
130
|
+
status,
|
|
131
|
+
} satisfies ToolExecutionResponseError,
|
|
132
|
+
status,
|
|
133
|
+
);
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
|
|
@@ -131,11 +142,9 @@ export class ToolCollection implements ICollection<Tool<any>> {
|
|
|
131
142
|
getToolDefinitions(context?: ToolUseContext): AgentToolDefinition[] {
|
|
132
143
|
return this.tools.getDefinitions(context);
|
|
133
144
|
}
|
|
134
|
-
|
|
135
145
|
}
|
|
136
146
|
|
|
137
|
-
|
|
138
|
-
function readPayload(ctx: Context): ToolExecutionPayload<any> {
|
|
147
|
+
function readPayload(ctx: Context): ToolExecutionPayload {
|
|
139
148
|
const toolCtx = ctx as ToolContext;
|
|
140
149
|
|
|
141
150
|
// Check if body was already parsed and validated by middleware
|
|
@@ -145,7 +154,8 @@ function readPayload(ctx: Context): ToolExecutionPayload<any> {
|
|
|
145
154
|
|
|
146
155
|
// If no payload, middleware couldn't parse/validate - return error
|
|
147
156
|
throw new HTTPException(400, {
|
|
148
|
-
message:
|
|
157
|
+
message:
|
|
158
|
+
'Invalid or missing tool execution payload. Expected { tool_use: { id, tool_name, tool_input? }, metadata? }',
|
|
149
159
|
});
|
|
150
160
|
}
|
|
151
161
|
|
|
@@ -166,8 +176,8 @@ function readPayload(ctx: Context): ToolExecutionPayload<any> {
|
|
|
166
176
|
* @param toolsDir - Path to the tools directory (e.g., /path/to/collection/tools)
|
|
167
177
|
* @returns Promise resolving to array of Tool objects
|
|
168
178
|
*/
|
|
169
|
-
export async function loadToolsFromDirectory(toolsDir: string): Promise<Tool
|
|
170
|
-
const tools: Tool
|
|
179
|
+
export async function loadToolsFromDirectory(toolsDir: string): Promise<Tool[]> {
|
|
180
|
+
const tools: Tool[] = [];
|
|
171
181
|
|
|
172
182
|
if (!existsSync(toolsDir)) {
|
|
173
183
|
console.warn(`Tools directory not found: ${toolsDir}`);
|
|
@@ -213,4 +223,3 @@ export async function loadToolsFromDirectory(toolsDir: string): Promise<Tool<any
|
|
|
213
223
|
|
|
214
224
|
return tools;
|
|
215
225
|
}
|
|
216
|
-
|