@vertesia/tools-sdk 0.81.1 → 1.0.0-dev.20260203.130115Z

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 (101) hide show
  1. package/package.json +9 -8
  2. package/src/ContentTypesCollection.ts +51 -0
  3. package/src/InteractionCollection.ts +1 -94
  4. package/src/SkillCollection.ts +88 -15
  5. package/src/ToolCollection.ts +65 -17
  6. package/src/ToolRegistry.ts +101 -9
  7. package/src/auth.ts +37 -6
  8. package/src/index.ts +7 -3
  9. package/src/server/app-package.ts +102 -0
  10. package/src/server/conyent-types.ts +71 -0
  11. package/src/server/interactions.ts +100 -0
  12. package/src/server/mcp.ts +51 -0
  13. package/src/server/site.ts +53 -0
  14. package/src/server/skills.ts +133 -0
  15. package/src/server/tools.ts +128 -0
  16. package/src/server/types.ts +87 -0
  17. package/src/server/widgets.ts +38 -0
  18. package/src/server.ts +80 -359
  19. package/src/site/styles.ts +71 -0
  20. package/src/site/templates.ts +215 -119
  21. package/src/types.ts +22 -18
  22. package/src/utils.ts +20 -0
  23. package/lib/cjs/InteractionCollection.js +0 -164
  24. package/lib/cjs/InteractionCollection.js.map +0 -1
  25. package/lib/cjs/SkillCollection.js +0 -318
  26. package/lib/cjs/SkillCollection.js.map +0 -1
  27. package/lib/cjs/ToolCollection.js +0 -192
  28. package/lib/cjs/ToolCollection.js.map +0 -1
  29. package/lib/cjs/ToolRegistry.js +0 -44
  30. package/lib/cjs/ToolRegistry.js.map +0 -1
  31. package/lib/cjs/auth.js +0 -89
  32. package/lib/cjs/auth.js.map +0 -1
  33. package/lib/cjs/build/validate.js +0 -7
  34. package/lib/cjs/build/validate.js.map +0 -1
  35. package/lib/cjs/copy-assets.js +0 -84
  36. package/lib/cjs/copy-assets.js.map +0 -1
  37. package/lib/cjs/index.js +0 -30
  38. package/lib/cjs/index.js.map +0 -1
  39. package/lib/cjs/package.json +0 -3
  40. package/lib/cjs/server.js +0 -327
  41. package/lib/cjs/server.js.map +0 -1
  42. package/lib/cjs/site/styles.js +0 -621
  43. package/lib/cjs/site/styles.js.map +0 -1
  44. package/lib/cjs/site/templates.js +0 -932
  45. package/lib/cjs/site/templates.js.map +0 -1
  46. package/lib/cjs/types.js +0 -3
  47. package/lib/cjs/types.js.map +0 -1
  48. package/lib/cjs/utils.js +0 -7
  49. package/lib/cjs/utils.js.map +0 -1
  50. package/lib/esm/InteractionCollection.js +0 -125
  51. package/lib/esm/InteractionCollection.js.map +0 -1
  52. package/lib/esm/SkillCollection.js +0 -311
  53. package/lib/esm/SkillCollection.js.map +0 -1
  54. package/lib/esm/ToolCollection.js +0 -154
  55. package/lib/esm/ToolCollection.js.map +0 -1
  56. package/lib/esm/ToolRegistry.js +0 -39
  57. package/lib/esm/ToolRegistry.js.map +0 -1
  58. package/lib/esm/auth.js +0 -82
  59. package/lib/esm/auth.js.map +0 -1
  60. package/lib/esm/build/validate.js +0 -4
  61. package/lib/esm/build/validate.js.map +0 -1
  62. package/lib/esm/copy-assets.js +0 -81
  63. package/lib/esm/copy-assets.js.map +0 -1
  64. package/lib/esm/index.js +0 -10
  65. package/lib/esm/index.js.map +0 -1
  66. package/lib/esm/server.js +0 -323
  67. package/lib/esm/server.js.map +0 -1
  68. package/lib/esm/site/styles.js +0 -618
  69. package/lib/esm/site/styles.js.map +0 -1
  70. package/lib/esm/site/templates.js +0 -920
  71. package/lib/esm/site/templates.js.map +0 -1
  72. package/lib/esm/types.js +0 -2
  73. package/lib/esm/types.js.map +0 -1
  74. package/lib/esm/utils.js +0 -4
  75. package/lib/esm/utils.js.map +0 -1
  76. package/lib/types/InteractionCollection.d.ts +0 -48
  77. package/lib/types/InteractionCollection.d.ts.map +0 -1
  78. package/lib/types/SkillCollection.d.ts +0 -111
  79. package/lib/types/SkillCollection.d.ts.map +0 -1
  80. package/lib/types/ToolCollection.d.ts +0 -61
  81. package/lib/types/ToolCollection.d.ts.map +0 -1
  82. package/lib/types/ToolRegistry.d.ts +0 -15
  83. package/lib/types/ToolRegistry.d.ts.map +0 -1
  84. package/lib/types/auth.d.ts +0 -20
  85. package/lib/types/auth.d.ts.map +0 -1
  86. package/lib/types/build/validate.d.ts +0 -2
  87. package/lib/types/build/validate.d.ts.map +0 -1
  88. package/lib/types/copy-assets.d.ts +0 -14
  89. package/lib/types/copy-assets.d.ts.map +0 -1
  90. package/lib/types/index.d.ts +0 -10
  91. package/lib/types/index.d.ts.map +0 -1
  92. package/lib/types/server.d.ts +0 -72
  93. package/lib/types/server.d.ts.map +0 -1
  94. package/lib/types/site/styles.d.ts +0 -5
  95. package/lib/types/site/styles.d.ts.map +0 -1
  96. package/lib/types/site/templates.d.ts +0 -54
  97. package/lib/types/site/templates.d.ts.map +0 -1
  98. package/lib/types/types.d.ts +0 -262
  99. package/lib/types/types.d.ts.map +0 -1
  100. package/lib/types/utils.d.ts +0 -2
  101. package/lib/types/utils.d.ts.map +0 -1
@@ -0,0 +1,128 @@
1
+ import { Context, Hono } from "hono";
2
+ import { HTTPException } from "hono/http-exception";
3
+ import { ToolCollection } from "../ToolCollection.js";
4
+ import { ToolCollectionDefinition, ToolDefinition } from "../types.js";
5
+ import { ToolContext, ToolServerConfig } from "./types.js";
6
+
7
+ export function createToolsRoute(app: Hono, basePath: string, config: ToolServerConfig) {
8
+ const { tools = [] } = config;
9
+
10
+ // Build a map of tool name -> collection for routing
11
+ const toolToCollection = new Map<string, ToolCollection>();
12
+ for (const coll of tools) {
13
+ for (const toolDef of coll.getToolDefinitions()) {
14
+ toolToCollection.set(toolDef.name, coll);
15
+ }
16
+ }
17
+
18
+ // GET /api/tools - Returns all tools from all collections
19
+ // Query params:
20
+ // - defaultOnly=true: Only return tools with default !== false
21
+ // - unlocked=tool1,tool2: Comma-separated list of unlocked tool names
22
+
23
+ app.get(basePath, (c) => {
24
+ const url = new URL(c.req.url);
25
+ const defaultOnly = c.req.query('defaultOnly') === 'true';
26
+ const unlockedParam = c.req.query('unlocked');
27
+ const unlockedTools = unlockedParam ? unlockedParam.split(',').map(t => t.trim()).filter(Boolean) : [];
28
+
29
+ const filterOptions = defaultOnly ? { defaultOnly, unlockedTools } : undefined;
30
+
31
+ const allTools: ToolDefinition[] = [];
32
+ let reserveToolCount = 0;
33
+
34
+ for (const coll of tools) {
35
+ allTools.push(...coll.getToolDefinitions(filterOptions));
36
+ if (defaultOnly) {
37
+ reserveToolCount += coll.getReserveTools(unlockedTools).length;
38
+ }
39
+ }
40
+
41
+ return c.json({
42
+ src: `${url.origin}${url.pathname}`,
43
+ title: 'All Tools',
44
+ description: 'All available tools across all collections',
45
+ tools: allTools,
46
+ reserveToolCount: defaultOnly ? reserveToolCount : undefined,
47
+ collections: tools.map(t => ({
48
+ name: t.name,
49
+ title: t.title,
50
+ description: t.description,
51
+ })),
52
+ } satisfies ToolCollectionDefinition & { collections: any[]; reserveToolCount?: number });
53
+ });
54
+
55
+ // POST /api/tools - Route to the correct collection based on tool_name
56
+ app.post(basePath, async (c) => {
57
+ const ctx = c as unknown as ToolContext;
58
+
59
+ // Payload is already parsed and validated by middleware
60
+ if (!ctx.payload) {
61
+ throw new HTTPException(400, {
62
+ message: 'Invalid or missing tool execution payload. Expected { tool_use: { id, tool_name, tool_input? }, metadata? }'
63
+ });
64
+ }
65
+
66
+ const toolName = ctx.payload.tool_use.tool_name;
67
+
68
+ // Find the collection for this tool
69
+ const collection = toolToCollection.get(toolName);
70
+ if (!collection) {
71
+ throw new HTTPException(404, {
72
+ message: `Tool not found: ${toolName}. Available tools: ${Array.from(toolToCollection.keys()).join(', ')}`
73
+ });
74
+ }
75
+
76
+ // Delegate to the collection's execute method with pre-parsed payload
77
+ return collection.execute(c, ctx.payload);
78
+ });
79
+
80
+ // Create tool collection endpoints
81
+ for (const coll of tools) {
82
+ app.route(`${basePath}/${coll.name}`, createToolEndpoints(coll));
83
+ }
84
+ }
85
+
86
+ function createToolEndpoints(coll: ToolCollection): Hono {
87
+ const endpoint = new Hono();
88
+
89
+ endpoint.post('/', (c: Context) => {
90
+ return coll.execute(c);
91
+ });
92
+
93
+ // GET /api/tools/{collection}
94
+ // Query params:
95
+ // - import: Return import source URL instead of API URL
96
+ // - defaultOnly=true: Only return tools with default !== false
97
+ // - unlocked=tool1,tool2: Comma-separated list of unlocked tool names
98
+ endpoint.get('/', (c) => {
99
+ const importSourceUrl = c.req.query('import') != null;
100
+ const defaultOnly = c.req.query('defaultOnly') === 'true';
101
+ const unlockedParam = c.req.query('unlocked');
102
+ const unlockedTools = unlockedParam ? unlockedParam.split(',').map(t => t.trim()).filter(Boolean) : [];
103
+
104
+ const filterOptions = defaultOnly ? { defaultOnly, unlockedTools } : undefined;
105
+ const url = new URL(c.req.url);
106
+
107
+ const response: ToolCollectionDefinition & { reserveToolCount?: number } = {
108
+ src: importSourceUrl
109
+ ? `${url.origin}/libs/vertesia-tools-${coll.name}.js`
110
+ : `${url.origin}${url.pathname}`,
111
+ title: coll.title || coll.name,
112
+ description: coll.description || '',
113
+ tools: coll.getToolDefinitions(filterOptions)
114
+ };
115
+
116
+ // Include reserve count when filtering
117
+ if (defaultOnly) {
118
+ response.reserveToolCount = coll.getReserveTools(unlockedTools).length;
119
+ }
120
+
121
+ return c.json(response);
122
+ });
123
+
124
+ return endpoint;
125
+ }
126
+
127
+
128
+
@@ -0,0 +1,87 @@
1
+ import { Context } from "hono";
2
+ import { InteractionCollection } from "../InteractionCollection.js";
3
+ import { SkillCollection } from "../SkillCollection.js";
4
+ import { ToolCollection } from "../ToolCollection.js";
5
+ import { ToolExecutionPayload } from "../types.js";
6
+ import { JSONSchema } from "@llumiverse/common";
7
+ import { AppUIConfig } from "@vertesia/common";
8
+ import { ContentTypesCollection } from "../ContentTypesCollection.js";
9
+
10
+ /**
11
+ * Extended context with parsed payload for tool/skill execution
12
+ */
13
+ export interface ToolContext extends Context {
14
+ /** The parsed request payload */
15
+ payload?: ToolExecutionPayload<any>;
16
+ /** The tool_use.id from the payload */
17
+ toolUseId?: string;
18
+ /** The tool_use.tool_name from the payload */
19
+ toolName?: string;
20
+ }
21
+
22
+ /**
23
+ * MCP Provider interface for server configuration
24
+ */
25
+ export interface MCPProviderConfig {
26
+ name: string;
27
+ description?: string;
28
+ createMCPConnection: (session: any, config: Record<string, any>) => Promise<{
29
+ name: string;
30
+ url: string;
31
+ token: string;
32
+ }>;
33
+ }
34
+
35
+ /**
36
+ * Server configuration options
37
+ */
38
+ export interface ToolServerConfig {
39
+ /**
40
+ * Server title for HTML pages (default: 'Tools Server')
41
+ */
42
+ title?: string;
43
+ /**
44
+ * API prefix (default: '/api')
45
+ */
46
+ prefix?: string;
47
+ /**
48
+ * Tool collections to expose
49
+ */
50
+ tools?: ToolCollection[];
51
+ /**
52
+ * Interaction collections to expose
53
+ */
54
+ interactions?: InteractionCollection[];
55
+ /**
56
+ * Content type collections to expose
57
+ */
58
+ types?: ContentTypesCollection[];
59
+ /**
60
+ * Skill collections to expose
61
+ */
62
+ skills?: SkillCollection[];
63
+ /**
64
+ * MCP providers to expose
65
+ */
66
+ mcpProviders?: MCPProviderConfig[];
67
+
68
+ /**
69
+ * A JSON schema defining settings for the application using this server
70
+ */
71
+ settings?: JSONSchema;
72
+
73
+ /**
74
+ * The UI configuration for the application using this server
75
+ */
76
+ uiConfig?: AppUIConfig;
77
+
78
+ /**
79
+ * Disable HTML pages (default: false)
80
+ */
81
+ disableHtml?: boolean;
82
+ /**
83
+ * Hide UI app links on the index page (default: false)
84
+ */
85
+ hideUILinks?: boolean;
86
+ }
87
+
@@ -0,0 +1,38 @@
1
+ import { Hono } from "hono";
2
+ import { ToolServerConfig } from "./types.js";
3
+
4
+ export interface WidgetInfo {
5
+ collection: string;
6
+ skill: string;
7
+ url: string;
8
+ }
9
+
10
+ export function createWidgetsRoute(app: Hono, basePath: string, config: ToolServerConfig) {
11
+
12
+ const { skills = [] } = config;
13
+
14
+ // GET /api/widgets - Returns all widgets from all skill collections
15
+ app.get(basePath, (c) => {
16
+ const url = new URL(c.req.url);
17
+
18
+ const widgets: Record<string, WidgetInfo> = {};
19
+ for (const coll of skills) {
20
+ const collWidgets = coll.getWidgets();
21
+ for (const widget of collWidgets) {
22
+ widgets[widget.name] = {
23
+ collection: coll.name,
24
+ skill: widget.skill,
25
+ url: `${url.origin}/widgets/${widget.name}.js`,
26
+ }
27
+ }
28
+ }
29
+
30
+ return c.json({
31
+ title: 'All Widgets',
32
+ description: 'All available widgets across all skill collections',
33
+ widgets,
34
+ });
35
+
36
+ });
37
+
38
+ }