@vertesia/tools-sdk 1.3.0 → 1.4.0-dev.20260615.051508Z
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,8 +1,8 @@
|
|
|
1
|
-
import type { ToolDefinition, ToolUse } from
|
|
2
|
-
import { VertesiaClient } from
|
|
3
|
-
import { AgentToolDefinition, AuthTokenPayload, ProjectConfiguration, RenderingTemplateDefinition, ToolExecutionMetadata, ToolResult, ToolResultContent } from
|
|
1
|
+
import type { ToolDefinition, ToolUse } from '@llumiverse/common';
|
|
2
|
+
import type { VertesiaClient } from '@vertesia/client';
|
|
3
|
+
import type { AgentToolDefinition, AuthTokenPayload, MCPToolAnnotations, ProjectConfiguration, RenderingTemplateDefinition, ToolExecutionMetadata, ToolResult, ToolResultContent } from '@vertesia/common';
|
|
4
4
|
export type { ToolExecutionMetadata };
|
|
5
|
-
export type ICollection<T =
|
|
5
|
+
export type ICollection<T = object> = CollectionProperties & Iterable<T>;
|
|
6
6
|
export interface CollectionProperties {
|
|
7
7
|
/**
|
|
8
8
|
* A kebab case collection name. Must only contains alphanumeric and dash characters,
|
|
@@ -43,7 +43,7 @@ export interface ToolExecutionResult extends ToolResultContent {
|
|
|
43
43
|
/**
|
|
44
44
|
* Medata can be used to return more info on the tool execution like stats or user messages.
|
|
45
45
|
*/
|
|
46
|
-
meta?: Record<string,
|
|
46
|
+
meta?: Record<string, unknown>;
|
|
47
47
|
}
|
|
48
48
|
export interface ToolExecutionResponse extends ToolExecutionResult, ToolResult {
|
|
49
49
|
/**
|
|
@@ -67,32 +67,44 @@ export interface ToolExecutionResponseError {
|
|
|
67
67
|
/**
|
|
68
68
|
* Additional context information
|
|
69
69
|
*/
|
|
70
|
-
data?: Record<string,
|
|
70
|
+
data?: Record<string, unknown>;
|
|
71
71
|
}
|
|
72
|
-
export interface ToolExecutionPayload<ParamsT extends
|
|
72
|
+
export interface ToolExecutionPayload<ParamsT extends object = object> {
|
|
73
73
|
tool_use: ToolUse<ParamsT>;
|
|
74
74
|
/**
|
|
75
75
|
* Optional metadata related to the current execution request
|
|
76
76
|
*/
|
|
77
77
|
metadata?: ToolExecutionMetadata;
|
|
78
78
|
}
|
|
79
|
-
export type ToolFn<ParamsT extends
|
|
79
|
+
export type ToolFn<ParamsT extends object = object> = (payload: ToolExecutionPayload<ParamsT>, context: ToolExecutionContext) => Promise<ToolExecutionResult>;
|
|
80
80
|
export interface ToolUseContext {
|
|
81
81
|
project_id?: string;
|
|
82
82
|
account_id?: string;
|
|
83
83
|
project_name?: string;
|
|
84
84
|
project_ns?: string;
|
|
85
85
|
configuration?: ProjectConfiguration;
|
|
86
|
-
vars?: Record<string,
|
|
86
|
+
vars?: Record<string, unknown>;
|
|
87
87
|
}
|
|
88
|
-
export interface Tool<ParamsT extends
|
|
89
|
-
run:
|
|
88
|
+
export interface Tool<ParamsT extends object = object> extends ToolDefinition {
|
|
89
|
+
run(payload: ToolExecutionPayload<ParamsT>, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
90
90
|
/**
|
|
91
91
|
* Whether this tool is available by default.
|
|
92
92
|
* - true/undefined: Tool is always available to agents
|
|
93
|
-
* - false: Tool is only available when activated by a skill's
|
|
93
|
+
* - false: Tool is only available when activated by a skill's tools
|
|
94
94
|
*/
|
|
95
95
|
default?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* MCP-style annotations (destructiveHint, readOnlyHint, etc). Propagated
|
|
98
|
+
* into the AgentToolDefinition on catalog / package responses.
|
|
99
|
+
*/
|
|
100
|
+
annotations?: MCPToolAnnotations;
|
|
101
|
+
/**
|
|
102
|
+
* When true, agents must obtain explicit user confirmation via `ask_user`
|
|
103
|
+
* (Yes/No) before invoking this tool. If the user answers No, the tool
|
|
104
|
+
* must not run. Stronger than `annotations.destructiveHint` — this is a
|
|
105
|
+
* hard contract.
|
|
106
|
+
*/
|
|
107
|
+
requires_user_confirmation?: boolean;
|
|
96
108
|
/**
|
|
97
109
|
* Optional filter to check if the tool is enabled for the given project configuration.
|
|
98
110
|
* This can be used to dynamically enable/disable tools based on project settings, environment variables, or any other logic.
|
|
@@ -208,7 +220,7 @@ export interface SkillDefinition {
|
|
|
208
220
|
*/
|
|
209
221
|
input_schema?: {
|
|
210
222
|
type: 'object';
|
|
211
|
-
properties?: Record<string,
|
|
223
|
+
properties?: Record<string, unknown>;
|
|
212
224
|
required?: string[];
|
|
213
225
|
};
|
|
214
226
|
/**
|
|
@@ -220,9 +232,10 @@ export interface SkillDefinition {
|
|
|
220
232
|
*/
|
|
221
233
|
execution?: SkillExecution;
|
|
222
234
|
/**
|
|
223
|
-
*
|
|
235
|
+
* Tool names this skill enables (unlocks) when called. Matches the
|
|
236
|
+
* `tools:` key used in SKILL.md frontmatter.
|
|
224
237
|
*/
|
|
225
|
-
|
|
238
|
+
tools?: string[];
|
|
226
239
|
/**
|
|
227
240
|
* Scripts bundled with this skill (synced to sandbox when skill is used)
|
|
228
241
|
*/
|
|
@@ -255,7 +268,7 @@ export interface SkillExecutionPayload {
|
|
|
255
268
|
/**
|
|
256
269
|
* Data context for JST template rendering
|
|
257
270
|
*/
|
|
258
|
-
data?: Record<string,
|
|
271
|
+
data?: Record<string, unknown>;
|
|
259
272
|
/**
|
|
260
273
|
* Whether to execute the code template (if present)
|
|
261
274
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types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@@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAK5C;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAE3D;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAc/C"}
|
|
@@ -6,15 +6,21 @@
|
|
|
6
6
|
export function toPathName(name) {
|
|
7
7
|
let result = name;
|
|
8
8
|
if (result.includes(' ') || result.includes('_')) {
|
|
9
|
-
result = result
|
|
9
|
+
result = result
|
|
10
|
+
.split(/[\s_]+/)
|
|
11
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
12
|
+
.join('');
|
|
10
13
|
}
|
|
11
14
|
return result.replace(/[^a-zA-Z0-9$_\-@]/g, '-');
|
|
12
15
|
}
|
|
13
16
|
export function kebabCaseToTitle(name) {
|
|
14
|
-
return name
|
|
17
|
+
return name
|
|
18
|
+
.split('-')
|
|
19
|
+
.map((p) => p[0].toUpperCase() + p.substring(1))
|
|
20
|
+
.join(' ');
|
|
15
21
|
}
|
|
16
22
|
export function makeScriptUrl(origin, script) {
|
|
17
|
-
return join(origin, join(
|
|
23
|
+
return join(origin, join('/scripts', script));
|
|
18
24
|
}
|
|
19
25
|
export function join(left, right) {
|
|
20
26
|
if (left.endsWith('/')) {
|
|
@@ -29,10 +35,10 @@ export function join(left, right) {
|
|
|
29
35
|
return left + right;
|
|
30
36
|
}
|
|
31
37
|
else if (right.startsWith('./')) {
|
|
32
|
-
return left
|
|
38
|
+
return `${left}/${right.slice(2)}`;
|
|
33
39
|
}
|
|
34
40
|
else {
|
|
35
|
-
return left
|
|
41
|
+
return `${left}/${right}`;
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACnC,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,GAAG,MAAM;aACV,KAAK,CAAC,QAAQ,CAAC;aACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClD,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IACzC,OAAO,IAAI;SACN,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SAC/C,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,MAAc;IACxD,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,KAAa;IAC5C,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,GAAG,KAAK,CAAC;QACxB,CAAC;IACL,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,GAAG,KAAK,CAAC;IACxB,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,CAAC;SAAM,CAAC;QACJ,OAAO,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertesia/tools-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-dev.20260615.051508Z",
|
|
4
4
|
"description": "Tools SDK - utilities for building remote tools",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"lib",
|
|
9
10
|
"src"
|
|
10
11
|
],
|
|
11
12
|
"license": "Apache-2.0",
|
|
12
13
|
"exports": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"bin": {
|
|
18
|
-
"tools-sdk-copy-assets": "./lib/esm/copy-assets.js"
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
16
|
+
"default": "./lib/index.js"
|
|
17
|
+
}
|
|
19
18
|
},
|
|
20
19
|
"devDependencies": {
|
|
21
|
-
"@types/node": "^24.
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
},
|
|
26
|
-
"ts_dual_module": {
|
|
27
|
-
"outDir": "lib"
|
|
20
|
+
"@types/node": "^24.12.4",
|
|
21
|
+
"typescript": "^6.0.3",
|
|
22
|
+
"vitest": "^4.1.8",
|
|
23
|
+
"@vertesia/tsconfig": "0.1.0"
|
|
28
24
|
},
|
|
29
25
|
"peerDependencies": {
|
|
30
|
-
"hono": "^4.12.
|
|
26
|
+
"hono": "^4.12.23"
|
|
31
27
|
},
|
|
32
28
|
"dependencies": {
|
|
33
|
-
"jose": "^6.
|
|
34
|
-
"zod": "^4.3
|
|
29
|
+
"jose": "^6.2.3",
|
|
30
|
+
"zod": "^4.4.3",
|
|
35
31
|
"@llumiverse/common": "1.3.0",
|
|
36
|
-
"@vertesia/client": "1.
|
|
37
|
-
"@vertesia/common": "1.
|
|
32
|
+
"@vertesia/client": "1.4.0-dev.20260615.051508Z",
|
|
33
|
+
"@vertesia/common": "1.4.0-dev.20260615.051508Z"
|
|
38
34
|
},
|
|
39
35
|
"repository": {
|
|
40
36
|
"type": "git",
|
|
@@ -51,8 +47,10 @@
|
|
|
51
47
|
"typescript"
|
|
52
48
|
],
|
|
53
49
|
"scripts": {
|
|
50
|
+
"lint": "biome lint src",
|
|
54
51
|
"test": "vitest run",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
52
|
+
"typecheck:test": "tsc -p tsconfig.test.json --noEmit",
|
|
53
|
+
"build": "rm -rf ./lib ./tsconfig.tsbuildinfo && tsc",
|
|
54
|
+
"clean": "rm -rf ./node_modules ./lib ./tsconfig.tsbuildinfo"
|
|
57
55
|
}
|
|
58
56
|
}
|
|
@@ -1,38 +1,45 @@
|
|
|
1
|
-
import { RemoteActivityExecutionPayload } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { RemoteActivityExecutionPayload } from '@vertesia/common';
|
|
2
|
+
import type { Context } from 'hono';
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { ActivityCollection, type ActivityDefinition } from './ActivityCollection.js';
|
|
5
|
+
|
|
6
|
+
type MockContext = Context & {
|
|
7
|
+
json: ReturnType<typeof vi.fn>;
|
|
8
|
+
req: { header: ReturnType<typeof vi.fn>; url: string };
|
|
9
|
+
set: ReturnType<typeof vi.fn>;
|
|
10
|
+
};
|
|
4
11
|
|
|
5
|
-
vi.mock(
|
|
6
|
-
authorize: vi.fn().mockResolvedValue({ token:
|
|
12
|
+
vi.mock('./auth.js', () => ({
|
|
13
|
+
authorize: vi.fn().mockResolvedValue({ token: 'test-token' }),
|
|
7
14
|
}));
|
|
8
15
|
|
|
9
16
|
const mockActivity: ActivityDefinition = {
|
|
10
|
-
name:
|
|
11
|
-
title:
|
|
12
|
-
description:
|
|
17
|
+
name: 'analyze_sentiment',
|
|
18
|
+
title: 'Analyze Sentiment',
|
|
19
|
+
description: 'Analyzes text sentiment',
|
|
13
20
|
input_schema: {
|
|
14
|
-
type:
|
|
15
|
-
properties: { text: { type:
|
|
16
|
-
required: [
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: { text: { type: 'string' } },
|
|
23
|
+
required: ['text'],
|
|
17
24
|
},
|
|
18
25
|
output_schema: {
|
|
19
|
-
type:
|
|
20
|
-
properties: { score: { type:
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: { score: { type: 'number' } },
|
|
21
28
|
},
|
|
22
29
|
run: vi.fn().mockResolvedValue({ score: 0.95 }),
|
|
23
30
|
};
|
|
24
31
|
|
|
25
32
|
const mockFailingActivity: ActivityDefinition = {
|
|
26
|
-
name:
|
|
27
|
-
description:
|
|
28
|
-
run: vi.fn().mockRejectedValue(new Error(
|
|
33
|
+
name: 'fail_always',
|
|
34
|
+
description: 'Always fails',
|
|
35
|
+
run: vi.fn().mockRejectedValue(new Error('Intentional failure')),
|
|
29
36
|
};
|
|
30
37
|
|
|
31
38
|
function createCollection(activities: ActivityDefinition[] = [mockActivity]) {
|
|
32
39
|
return new ActivityCollection({
|
|
33
|
-
name:
|
|
34
|
-
title:
|
|
35
|
-
description:
|
|
40
|
+
name: 'test-collection',
|
|
41
|
+
title: 'Test Collection',
|
|
42
|
+
description: 'A test collection',
|
|
36
43
|
activities,
|
|
37
44
|
});
|
|
38
45
|
}
|
|
@@ -41,118 +48,112 @@ beforeEach(() => {
|
|
|
41
48
|
vi.clearAllMocks();
|
|
42
49
|
});
|
|
43
50
|
|
|
44
|
-
describe(
|
|
45
|
-
describe(
|
|
46
|
-
it(
|
|
51
|
+
describe('ActivityCollection', () => {
|
|
52
|
+
describe('getActivityDefinitions', () => {
|
|
53
|
+
it('returns correct metadata for all registered activities', () => {
|
|
47
54
|
const coll = createCollection([mockActivity, mockFailingActivity]);
|
|
48
55
|
const defs = coll.getActivityDefinitions();
|
|
49
56
|
|
|
50
57
|
expect(defs).toHaveLength(2);
|
|
51
58
|
expect(defs[0]).toEqual({
|
|
52
|
-
name:
|
|
53
|
-
title:
|
|
54
|
-
description:
|
|
59
|
+
name: 'analyze_sentiment',
|
|
60
|
+
title: 'Analyze Sentiment',
|
|
61
|
+
description: 'Analyzes text sentiment',
|
|
55
62
|
input_schema: mockActivity.input_schema,
|
|
56
63
|
output_schema: mockActivity.output_schema,
|
|
57
64
|
});
|
|
58
65
|
expect(defs[1]).toEqual({
|
|
59
|
-
name:
|
|
66
|
+
name: 'fail_always',
|
|
60
67
|
title: undefined,
|
|
61
|
-
description:
|
|
68
|
+
description: 'Always fails',
|
|
62
69
|
input_schema: undefined,
|
|
63
70
|
output_schema: undefined,
|
|
64
71
|
});
|
|
65
72
|
});
|
|
66
73
|
|
|
67
|
-
it(
|
|
74
|
+
it('returns empty array when no activities registered', () => {
|
|
68
75
|
const coll = createCollection([]);
|
|
69
76
|
expect(coll.getActivityDefinitions()).toEqual([]);
|
|
70
77
|
});
|
|
71
78
|
});
|
|
72
79
|
|
|
73
|
-
describe(
|
|
74
|
-
it(
|
|
80
|
+
describe('getActivity', () => {
|
|
81
|
+
it('returns the activity by name', () => {
|
|
75
82
|
const coll = createCollection();
|
|
76
|
-
const activity = coll.getActivity(
|
|
77
|
-
expect(activity.name).toBe(
|
|
83
|
+
const activity = coll.getActivity('analyze_sentiment');
|
|
84
|
+
expect(activity.name).toBe('analyze_sentiment');
|
|
78
85
|
expect(activity.run).toBeDefined();
|
|
79
86
|
});
|
|
80
87
|
|
|
81
|
-
it(
|
|
88
|
+
it('throws 404 for unknown activity name', () => {
|
|
82
89
|
const coll = createCollection();
|
|
83
|
-
expect(() => coll.getActivity(
|
|
90
|
+
expect(() => coll.getActivity('nonexistent')).toThrow();
|
|
84
91
|
});
|
|
85
92
|
});
|
|
86
93
|
|
|
87
|
-
describe(
|
|
88
|
-
it(
|
|
94
|
+
describe('iterator', () => {
|
|
95
|
+
it('iterates over all activities', () => {
|
|
89
96
|
const coll = createCollection([mockActivity, mockFailingActivity]);
|
|
90
|
-
const names = [...coll].map(a => a.name);
|
|
91
|
-
expect(names).toEqual([
|
|
97
|
+
const names = [...coll].map((a) => a.name);
|
|
98
|
+
expect(names).toEqual(['analyze_sentiment', 'fail_always']);
|
|
92
99
|
});
|
|
93
100
|
});
|
|
94
101
|
|
|
95
|
-
describe(
|
|
96
|
-
const createMockContext = () => {
|
|
102
|
+
describe('execute', () => {
|
|
103
|
+
const createMockContext = (): MockContext => {
|
|
97
104
|
const jsonFn = vi.fn().mockReturnThis();
|
|
98
105
|
return {
|
|
99
106
|
json: jsonFn,
|
|
100
107
|
req: {
|
|
101
|
-
header: vi.fn().mockReturnValue(
|
|
102
|
-
url:
|
|
108
|
+
header: vi.fn().mockReturnValue('Bearer test-token'),
|
|
109
|
+
url: 'http://localhost/api/activities',
|
|
103
110
|
},
|
|
104
111
|
set: vi.fn(),
|
|
105
|
-
} as
|
|
112
|
+
} as unknown as MockContext;
|
|
106
113
|
};
|
|
107
114
|
|
|
108
115
|
const payload: RemoteActivityExecutionPayload = {
|
|
109
|
-
activity_name:
|
|
110
|
-
params: { text:
|
|
116
|
+
activity_name: 'analyze_sentiment',
|
|
117
|
+
params: { text: 'Hello world' },
|
|
111
118
|
metadata: {
|
|
112
|
-
app_install_id:
|
|
119
|
+
app_install_id: 'install-1',
|
|
113
120
|
},
|
|
114
121
|
};
|
|
115
122
|
|
|
116
|
-
it(
|
|
123
|
+
it('calls the correct activity handler and returns result', async () => {
|
|
117
124
|
const coll = createCollection();
|
|
118
125
|
const ctx = createMockContext();
|
|
119
126
|
|
|
120
127
|
await coll.execute(ctx, payload);
|
|
121
128
|
|
|
122
|
-
expect(mockActivity.run).toHaveBeenCalledWith(
|
|
123
|
-
payload,
|
|
124
|
-
expect.objectContaining({ token: "test-token" }),
|
|
125
|
-
);
|
|
129
|
+
expect(mockActivity.run).toHaveBeenCalledWith(payload, expect.objectContaining({ token: 'test-token' }));
|
|
126
130
|
expect(ctx.json).toHaveBeenCalledWith({
|
|
127
131
|
result: { score: 0.95 },
|
|
128
132
|
is_error: false,
|
|
129
133
|
});
|
|
130
134
|
});
|
|
131
135
|
|
|
132
|
-
it(
|
|
136
|
+
it('returns is_error with message when activity throws', async () => {
|
|
133
137
|
const coll = createCollection([mockFailingActivity]);
|
|
134
138
|
const ctx = createMockContext();
|
|
135
139
|
|
|
136
140
|
const failPayload: RemoteActivityExecutionPayload = {
|
|
137
141
|
...payload,
|
|
138
|
-
activity_name:
|
|
142
|
+
activity_name: 'fail_always',
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
await coll.execute(ctx, failPayload);
|
|
142
146
|
|
|
143
|
-
expect(ctx.json).toHaveBeenCalledWith(
|
|
144
|
-
{ result: null, is_error: true, error: "Intentional failure" },
|
|
145
|
-
500,
|
|
146
|
-
);
|
|
147
|
+
expect(ctx.json).toHaveBeenCalledWith({ result: null, is_error: true, error: 'Intentional failure' }, 500);
|
|
147
148
|
});
|
|
148
149
|
|
|
149
|
-
it(
|
|
150
|
+
it('throws 404 when activity_name is not found', async () => {
|
|
150
151
|
const coll = createCollection();
|
|
151
152
|
const ctx = createMockContext();
|
|
152
153
|
|
|
153
154
|
const unknownPayload: RemoteActivityExecutionPayload = {
|
|
154
155
|
...payload,
|
|
155
|
-
activity_name:
|
|
156
|
+
activity_name: 'nonexistent',
|
|
156
157
|
};
|
|
157
158
|
|
|
158
159
|
await expect(coll.execute(ctx, unknownPayload)).rejects.toThrow();
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
RemoteActivityDefinition,
|
|
3
|
+
RemoteActivityExecutionPayload,
|
|
4
|
+
RemoteActivityExecutionResponse,
|
|
5
|
+
} from '@vertesia/common';
|
|
6
|
+
import type { Context } from 'hono';
|
|
7
|
+
import { HTTPException } from 'hono/http-exception';
|
|
8
|
+
import { authorize } from './auth.js';
|
|
9
|
+
import type { CollectionProperties, ICollection, ToolExecutionContext } from './types.js';
|
|
10
|
+
import { kebabCaseToTitle } from './utils.js';
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Context provided to activity handlers during execution.
|
|
@@ -14,15 +18,15 @@ export type ActivityExecutionContext = ToolExecutionContext;
|
|
|
14
18
|
/**
|
|
15
19
|
* Function signature for a remote activity handler.
|
|
16
20
|
*/
|
|
17
|
-
export type ActivityFn<ParamsT extends
|
|
21
|
+
export type ActivityFn<ParamsT extends object = Record<string, unknown>> = (
|
|
18
22
|
payload: RemoteActivityExecutionPayload<ParamsT>,
|
|
19
|
-
context: ActivityExecutionContext
|
|
20
|
-
) => Promise<
|
|
23
|
+
context: ActivityExecutionContext,
|
|
24
|
+
) => Promise<unknown>;
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* An activity definition within an ActivityCollection.
|
|
24
28
|
*/
|
|
25
|
-
export interface ActivityDefinition<ParamsT extends
|
|
29
|
+
export interface ActivityDefinition<ParamsT extends object = Record<string, unknown>> {
|
|
26
30
|
/** Activity name (snake_case) */
|
|
27
31
|
name: string;
|
|
28
32
|
/** Display title */
|
|
@@ -30,9 +34,9 @@ export interface ActivityDefinition<ParamsT extends Record<string, any> = Record
|
|
|
30
34
|
/** Description of what the activity does */
|
|
31
35
|
description?: string;
|
|
32
36
|
/** JSON Schema for the activity input parameters */
|
|
33
|
-
input_schema?: Record<string,
|
|
37
|
+
input_schema?: Record<string, unknown>;
|
|
34
38
|
/** JSON Schema for the activity output */
|
|
35
|
-
output_schema?: Record<string,
|
|
39
|
+
output_schema?: Record<string, unknown>;
|
|
36
40
|
/** The activity handler function */
|
|
37
41
|
run: ActivityFn<ParamsT>;
|
|
38
42
|
}
|
|
@@ -71,7 +75,7 @@ export class ActivityCollection implements ICollection<ActivityDefinition> {
|
|
|
71
75
|
return { value: activities[index++], done: false };
|
|
72
76
|
}
|
|
73
77
|
return { done: true, value: undefined };
|
|
74
|
-
}
|
|
78
|
+
},
|
|
75
79
|
};
|
|
76
80
|
}
|
|
77
81
|
|
|
@@ -79,7 +83,7 @@ export class ActivityCollection implements ICollection<ActivityDefinition> {
|
|
|
79
83
|
* Get activity definitions for discovery (metadata only, no run function).
|
|
80
84
|
*/
|
|
81
85
|
getActivityDefinitions(): RemoteActivityDefinition[] {
|
|
82
|
-
return Object.values(this.registry).map(activity => ({
|
|
86
|
+
return Object.values(this.registry).map((activity) => ({
|
|
83
87
|
name: activity.name,
|
|
84
88
|
title: activity.title,
|
|
85
89
|
description: activity.description,
|
|
@@ -92,7 +96,7 @@ export class ActivityCollection implements ICollection<ActivityDefinition> {
|
|
|
92
96
|
const activity = this.registry[name];
|
|
93
97
|
if (!activity) {
|
|
94
98
|
throw new HTTPException(404, {
|
|
95
|
-
message: `Activity not found: ${name}. Available: ${Object.keys(this.registry).join(', ')}
|
|
99
|
+
message: `Activity not found: ${name}. Available: ${Object.keys(this.registry).join(', ')}`,
|
|
96
100
|
});
|
|
97
101
|
}
|
|
98
102
|
return activity;
|
|
@@ -126,11 +130,14 @@ export class ActivityCollection implements ICollection<ActivityDefinition> {
|
|
|
126
130
|
metadata: payload.metadata,
|
|
127
131
|
error: message,
|
|
128
132
|
});
|
|
129
|
-
return ctx.json(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
return ctx.json(
|
|
134
|
+
{
|
|
135
|
+
result: null,
|
|
136
|
+
is_error: true,
|
|
137
|
+
error: message,
|
|
138
|
+
} satisfies RemoteActivityExecutionResponse,
|
|
139
|
+
500,
|
|
140
|
+
);
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InCodeTypeSpec } from
|
|
2
|
-
import { CollectionProperties, ICollection } from
|
|
3
|
-
import { kebabCaseToTitle } from
|
|
1
|
+
import type { InCodeTypeSpec } from '@vertesia/common';
|
|
2
|
+
import type { CollectionProperties, ICollection } from './types.js';
|
|
3
|
+
import { kebabCaseToTitle } from './utils.js';
|
|
4
4
|
|
|
5
5
|
export interface ContentTypesCollectionProps extends CollectionProperties {
|
|
6
6
|
types: InCodeTypeSpec[];
|
|
@@ -11,9 +11,7 @@ export class ContentTypesCollection implements ICollection<InCodeTypeSpec> {
|
|
|
11
11
|
title?: string;
|
|
12
12
|
icon?: string;
|
|
13
13
|
description?: string;
|
|
14
|
-
constructor({
|
|
15
|
-
name, title, icon, description, types
|
|
16
|
-
}: ContentTypesCollectionProps) {
|
|
14
|
+
constructor({ name, title, icon, description, types }: ContentTypesCollectionProps) {
|
|
17
15
|
this.name = name;
|
|
18
16
|
this.title = title || kebabCaseToTitle(name);
|
|
19
17
|
this.icon = icon;
|
|
@@ -36,7 +34,7 @@ export class ContentTypesCollection implements ICollection<InCodeTypeSpec> {
|
|
|
36
34
|
} else {
|
|
37
35
|
return { done: true, value: undefined };
|
|
38
36
|
}
|
|
39
|
-
}
|
|
37
|
+
},
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -45,7 +43,6 @@ export class ContentTypesCollection implements ICollection<InCodeTypeSpec> {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
getTypeByName(name: string): InCodeTypeSpec | undefined {
|
|
48
|
-
return this.types.find(type => type.name === name);
|
|
46
|
+
return this.types.find((type) => type.name === name);
|
|
49
47
|
}
|
|
50
|
-
|
|
51
48
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InteractionSpec } from
|
|
2
|
-
import { CollectionProperties, ICollection } from
|
|
3
|
-
import { kebabCaseToTitle } from
|
|
1
|
+
import type { InteractionSpec } from '@vertesia/common';
|
|
2
|
+
import type { CollectionProperties, ICollection } from './types.js';
|
|
3
|
+
import { kebabCaseToTitle } from './utils.js';
|
|
4
4
|
|
|
5
5
|
export interface InteractionCollectionProps extends CollectionProperties {
|
|
6
6
|
interactions: InteractionSpec[];
|
|
@@ -11,9 +11,7 @@ export class InteractionCollection implements ICollection<InteractionSpec> {
|
|
|
11
11
|
title?: string;
|
|
12
12
|
icon?: string;
|
|
13
13
|
description?: string;
|
|
14
|
-
constructor({
|
|
15
|
-
name, title, icon, description, interactions
|
|
16
|
-
}: InteractionCollectionProps) {
|
|
14
|
+
constructor({ name, title, icon, description, interactions }: InteractionCollectionProps) {
|
|
17
15
|
this.name = name;
|
|
18
16
|
this.title = title || kebabCaseToTitle(name);
|
|
19
17
|
this.icon = icon;
|
|
@@ -36,7 +34,7 @@ export class InteractionCollection implements ICollection<InteractionSpec> {
|
|
|
36
34
|
} else {
|
|
37
35
|
return { done: true, value: undefined };
|
|
38
36
|
}
|
|
39
|
-
}
|
|
37
|
+
},
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -45,6 +43,6 @@ export class InteractionCollection implements ICollection<InteractionSpec> {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
getInteractionByName(name: string): InteractionSpec | undefined {
|
|
48
|
-
return this.interactions.find(interaction => interaction.name === name);
|
|
46
|
+
return this.interactions.find((interaction) => interaction.name === name);
|
|
49
47
|
}
|
|
50
48
|
}
|