@vinkius-core/mcp-fusion 0.1.0
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/LICENSE +190 -0
- package/README.md +391 -0
- package/dist/src/AbstractBase.d.ts +24 -0
- package/dist/src/AbstractBase.d.ts.map +1 -0
- package/dist/src/AbstractBase.js +63 -0
- package/dist/src/AbstractBase.js.map +1 -0
- package/dist/src/AbstractLeaf.d.ts +12 -0
- package/dist/src/AbstractLeaf.d.ts.map +1 -0
- package/dist/src/AbstractLeaf.js +32 -0
- package/dist/src/AbstractLeaf.js.map +1 -0
- package/dist/src/Annotations.d.ts +15 -0
- package/dist/src/Annotations.d.ts.map +1 -0
- package/dist/src/Annotations.js +29 -0
- package/dist/src/Annotations.js.map +1 -0
- package/dist/src/Group.d.ts +32 -0
- package/dist/src/Group.d.ts.map +1 -0
- package/dist/src/Group.js +131 -0
- package/dist/src/Group.js.map +1 -0
- package/dist/src/Icon.d.ts +19 -0
- package/dist/src/Icon.d.ts.map +1 -0
- package/dist/src/Icon.js +33 -0
- package/dist/src/Icon.js.map +1 -0
- package/dist/src/Prompt.d.ts +11 -0
- package/dist/src/Prompt.d.ts.map +1 -0
- package/dist/src/Prompt.js +28 -0
- package/dist/src/Prompt.js.map +1 -0
- package/dist/src/PromptArgument.d.ts +10 -0
- package/dist/src/PromptArgument.d.ts.map +1 -0
- package/dist/src/PromptArgument.js +20 -0
- package/dist/src/PromptArgument.js.map +1 -0
- package/dist/src/Resource.d.ts +19 -0
- package/dist/src/Resource.d.ts.map +1 -0
- package/dist/src/Resource.js +34 -0
- package/dist/src/Resource.js.map +1 -0
- package/dist/src/Role.d.ts +5 -0
- package/dist/src/Role.d.ts.map +1 -0
- package/dist/src/Role.js +6 -0
- package/dist/src/Role.js.map +1 -0
- package/dist/src/Tool.d.ts +16 -0
- package/dist/src/Tool.d.ts.map +1 -0
- package/dist/src/Tool.js +28 -0
- package/dist/src/Tool.js.map +1 -0
- package/dist/src/ToolAnnotations.d.ts +23 -0
- package/dist/src/ToolAnnotations.d.ts.map +1 -0
- package/dist/src/ToolAnnotations.js +44 -0
- package/dist/src/ToolAnnotations.js.map +1 -0
- package/dist/src/converters/GroupConverter.d.ts +14 -0
- package/dist/src/converters/GroupConverter.d.ts.map +1 -0
- package/dist/src/converters/GroupConverter.js +13 -0
- package/dist/src/converters/GroupConverter.js.map +1 -0
- package/dist/src/converters/PromptConverter.d.ts +14 -0
- package/dist/src/converters/PromptConverter.d.ts.map +1 -0
- package/dist/src/converters/PromptConverter.js +13 -0
- package/dist/src/converters/PromptConverter.js.map +1 -0
- package/dist/src/converters/ResourceConverter.d.ts +14 -0
- package/dist/src/converters/ResourceConverter.d.ts.map +1 -0
- package/dist/src/converters/ResourceConverter.js +13 -0
- package/dist/src/converters/ResourceConverter.js.map +1 -0
- package/dist/src/converters/ToolAnnotationsConverter.d.ts +16 -0
- package/dist/src/converters/ToolAnnotationsConverter.d.ts.map +1 -0
- package/dist/src/converters/ToolAnnotationsConverter.js +23 -0
- package/dist/src/converters/ToolAnnotationsConverter.js.map +1 -0
- package/dist/src/converters/ToolConverter.d.ts +14 -0
- package/dist/src/converters/ToolConverter.d.ts.map +1 -0
- package/dist/src/converters/ToolConverter.js +13 -0
- package/dist/src/converters/ToolConverter.js.map +1 -0
- package/dist/src/converters/index.d.ts +6 -0
- package/dist/src/converters/index.d.ts.map +1 -0
- package/dist/src/converters/index.js +6 -0
- package/dist/src/converters/index.js.map +1 -0
- package/dist/src/framework/GroupedToolBuilder.d.ts +137 -0
- package/dist/src/framework/GroupedToolBuilder.d.ts.map +1 -0
- package/dist/src/framework/GroupedToolBuilder.js +289 -0
- package/dist/src/framework/GroupedToolBuilder.js.map +1 -0
- package/dist/src/framework/ResponseHelper.d.ts +43 -0
- package/dist/src/framework/ResponseHelper.d.ts.map +1 -0
- package/dist/src/framework/ResponseHelper.js +49 -0
- package/dist/src/framework/ResponseHelper.js.map +1 -0
- package/dist/src/framework/ToolBuilder.d.ts +46 -0
- package/dist/src/framework/ToolBuilder.d.ts.map +1 -0
- package/dist/src/framework/ToolBuilder.js +2 -0
- package/dist/src/framework/ToolBuilder.js.map +1 -0
- package/dist/src/framework/ToolRegistry.d.ts +85 -0
- package/dist/src/framework/ToolRegistry.d.ts.map +1 -0
- package/dist/src/framework/ToolRegistry.js +153 -0
- package/dist/src/framework/ToolRegistry.js.map +1 -0
- package/dist/src/framework/index.d.ts +9 -0
- package/dist/src/framework/index.d.ts.map +1 -0
- package/dist/src/framework/index.js +8 -0
- package/dist/src/framework/index.js.map +1 -0
- package/dist/src/framework/strategies/AnnotationAggregator.d.ts +11 -0
- package/dist/src/framework/strategies/AnnotationAggregator.d.ts.map +1 -0
- package/dist/src/framework/strategies/AnnotationAggregator.js +25 -0
- package/dist/src/framework/strategies/AnnotationAggregator.js.map +1 -0
- package/dist/src/framework/strategies/DescriptionGenerator.d.ts +12 -0
- package/dist/src/framework/strategies/DescriptionGenerator.d.ts.map +1 -0
- package/dist/src/framework/strategies/DescriptionGenerator.js +70 -0
- package/dist/src/framework/strategies/DescriptionGenerator.js.map +1 -0
- package/dist/src/framework/strategies/MiddlewareCompiler.d.ts +13 -0
- package/dist/src/framework/strategies/MiddlewareCompiler.d.ts.map +1 -0
- package/dist/src/framework/strategies/MiddlewareCompiler.js +24 -0
- package/dist/src/framework/strategies/MiddlewareCompiler.js.map +1 -0
- package/dist/src/framework/strategies/SchemaGenerator.d.ts +15 -0
- package/dist/src/framework/strategies/SchemaGenerator.d.ts.map +1 -0
- package/dist/src/framework/strategies/SchemaGenerator.js +97 -0
- package/dist/src/framework/strategies/SchemaGenerator.js.map +1 -0
- package/dist/src/framework/strategies/SchemaUtils.d.ts +7 -0
- package/dist/src/framework/strategies/SchemaUtils.d.ts.map +1 -0
- package/dist/src/framework/strategies/SchemaUtils.js +17 -0
- package/dist/src/framework/strategies/SchemaUtils.js.map +1 -0
- package/dist/src/framework/strategies/ToonDescriptionGenerator.d.ts +3 -0
- package/dist/src/framework/strategies/ToonDescriptionGenerator.d.ts.map +1 -0
- package/dist/src/framework/strategies/ToonDescriptionGenerator.js +53 -0
- package/dist/src/framework/strategies/ToonDescriptionGenerator.js.map +1 -0
- package/dist/src/framework/strategies/Types.d.ts +34 -0
- package/dist/src/framework/strategies/Types.d.ts.map +1 -0
- package/dist/src/framework/strategies/Types.js +2 -0
- package/dist/src/framework/strategies/Types.js.map +1 -0
- package/dist/src/framework/strategies/index.d.ts +12 -0
- package/dist/src/framework/strategies/index.d.ts.map +1 -0
- package/dist/src/framework/strategies/index.js +11 -0
- package/dist/src/framework/strategies/index.js.map +1 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/AbstractBase.test.d.ts +2 -0
- package/dist/tests/AbstractBase.test.d.ts.map +1 -0
- package/dist/tests/AbstractBase.test.js +130 -0
- package/dist/tests/AbstractBase.test.js.map +1 -0
- package/dist/tests/AbstractLeaf.test.d.ts +2 -0
- package/dist/tests/AbstractLeaf.test.d.ts.map +1 -0
- package/dist/tests/AbstractLeaf.test.js +65 -0
- package/dist/tests/AbstractLeaf.test.js.map +1 -0
- package/dist/tests/Annotations.test.d.ts +2 -0
- package/dist/tests/Annotations.test.d.ts.map +1 -0
- package/dist/tests/Annotations.test.js +34 -0
- package/dist/tests/Annotations.test.js.map +1 -0
- package/dist/tests/BarrelExport.test.d.ts +2 -0
- package/dist/tests/BarrelExport.test.d.ts.map +1 -0
- package/dist/tests/BarrelExport.test.js +42 -0
- package/dist/tests/BarrelExport.test.js.map +1 -0
- package/dist/tests/Converters.test.d.ts +2 -0
- package/dist/tests/Converters.test.d.ts.map +1 -0
- package/dist/tests/Converters.test.js +193 -0
- package/dist/tests/Converters.test.js.map +1 -0
- package/dist/tests/Group.test.d.ts +2 -0
- package/dist/tests/Group.test.d.ts.map +1 -0
- package/dist/tests/Group.test.js +257 -0
- package/dist/tests/Group.test.js.map +1 -0
- package/dist/tests/Icon.test.d.ts +2 -0
- package/dist/tests/Icon.test.d.ts.map +1 -0
- package/dist/tests/Icon.test.js +44 -0
- package/dist/tests/Icon.test.js.map +1 -0
- package/dist/tests/Prompt.test.d.ts +2 -0
- package/dist/tests/Prompt.test.d.ts.map +1 -0
- package/dist/tests/Prompt.test.js +63 -0
- package/dist/tests/Prompt.test.js.map +1 -0
- package/dist/tests/PromptArgument.test.d.ts +2 -0
- package/dist/tests/PromptArgument.test.d.ts.map +1 -0
- package/dist/tests/PromptArgument.test.js +37 -0
- package/dist/tests/PromptArgument.test.js.map +1 -0
- package/dist/tests/Resource.test.d.ts +2 -0
- package/dist/tests/Resource.test.d.ts.map +1 -0
- package/dist/tests/Resource.test.js +61 -0
- package/dist/tests/Resource.test.js.map +1 -0
- package/dist/tests/Role.test.d.ts +2 -0
- package/dist/tests/Role.test.d.ts.map +1 -0
- package/dist/tests/Role.test.js +17 -0
- package/dist/tests/Role.test.js.map +1 -0
- package/dist/tests/Tool.test.d.ts +2 -0
- package/dist/tests/Tool.test.d.ts.map +1 -0
- package/dist/tests/Tool.test.js +62 -0
- package/dist/tests/Tool.test.js.map +1 -0
- package/dist/tests/ToolAnnotations.test.d.ts +2 -0
- package/dist/tests/ToolAnnotations.test.d.ts.map +1 -0
- package/dist/tests/ToolAnnotations.test.js +55 -0
- package/dist/tests/ToolAnnotations.test.js.map +1 -0
- package/dist/tests/framework/AdversarialQA.test.d.ts +2 -0
- package/dist/tests/framework/AdversarialQA.test.d.ts.map +1 -0
- package/dist/tests/framework/AdversarialQA.test.js +906 -0
- package/dist/tests/framework/AdversarialQA.test.js.map +1 -0
- package/dist/tests/framework/GroupedToolBuilder.test.d.ts +2 -0
- package/dist/tests/framework/GroupedToolBuilder.test.d.ts.map +1 -0
- package/dist/tests/framework/GroupedToolBuilder.test.js +712 -0
- package/dist/tests/framework/GroupedToolBuilder.test.js.map +1 -0
- package/dist/tests/framework/LargeScaleScenarios.test.d.ts +2 -0
- package/dist/tests/framework/LargeScaleScenarios.test.d.ts.map +1 -0
- package/dist/tests/framework/LargeScaleScenarios.test.js +1043 -0
- package/dist/tests/framework/LargeScaleScenarios.test.js.map +1 -0
- package/dist/tests/framework/McpServerAdapter.test.d.ts +2 -0
- package/dist/tests/framework/McpServerAdapter.test.d.ts.map +1 -0
- package/dist/tests/framework/McpServerAdapter.test.js +380 -0
- package/dist/tests/framework/McpServerAdapter.test.js.map +1 -0
- package/dist/tests/framework/ResponseHelper.test.d.ts +2 -0
- package/dist/tests/framework/ResponseHelper.test.d.ts.map +1 -0
- package/dist/tests/framework/ResponseHelper.test.js +202 -0
- package/dist/tests/framework/ResponseHelper.test.js.map +1 -0
- package/dist/tests/framework/SecurityDeep.test.d.ts +2 -0
- package/dist/tests/framework/SecurityDeep.test.d.ts.map +1 -0
- package/dist/tests/framework/SecurityDeep.test.js +825 -0
- package/dist/tests/framework/SecurityDeep.test.js.map +1 -0
- package/dist/tests/framework/ToolRegistry.test.d.ts +2 -0
- package/dist/tests/framework/ToolRegistry.test.d.ts.map +1 -0
- package/dist/tests/framework/ToolRegistry.test.js +152 -0
- package/dist/tests/framework/ToolRegistry.test.js.map +1 -0
- package/dist/tests/framework/ToonDescription.test.d.ts +2 -0
- package/dist/tests/framework/ToonDescription.test.d.ts.map +1 -0
- package/dist/tests/framework/ToonDescription.test.js +287 -0
- package/dist/tests/framework/ToonDescription.test.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ListToolsRequestSchema, CallToolRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { error } from './ResponseHelper.js';
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// ToolRegistry
|
|
5
|
+
// ============================================================================
|
|
6
|
+
export class ToolRegistry {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._builders = new Map();
|
|
9
|
+
}
|
|
10
|
+
/** Register a tool builder. Throws on duplicate name. */
|
|
11
|
+
register(builder) {
|
|
12
|
+
const name = builder.getName();
|
|
13
|
+
if (this._builders.has(name)) {
|
|
14
|
+
throw new Error(`Tool "${name}" is already registered.`);
|
|
15
|
+
}
|
|
16
|
+
// Ensure tool is built (triggers validation + caching)
|
|
17
|
+
builder.buildToolDefinition();
|
|
18
|
+
this._builders.set(name, builder);
|
|
19
|
+
}
|
|
20
|
+
/** Register multiple builders at once */
|
|
21
|
+
registerAll(...builders) {
|
|
22
|
+
for (const builder of builders) {
|
|
23
|
+
this.register(builder);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Get all tool definitions */
|
|
27
|
+
getAllTools() {
|
|
28
|
+
return Array.from(this._builders.values())
|
|
29
|
+
.map(b => b.buildToolDefinition());
|
|
30
|
+
}
|
|
31
|
+
/** Get tool definitions filtered by tags */
|
|
32
|
+
getTools(filter) {
|
|
33
|
+
return Array.from(this._builders.values())
|
|
34
|
+
.filter(builder => {
|
|
35
|
+
const builderTags = builder.getTags();
|
|
36
|
+
// If tags filter specified, builder must have ALL of them
|
|
37
|
+
if (filter.tags && filter.tags.length > 0) {
|
|
38
|
+
if (!filter.tags.every(t => builderTags.includes(t))) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// If exclude filter specified, builder must not have ANY of them
|
|
43
|
+
if (filter.exclude && filter.exclude.length > 0) {
|
|
44
|
+
if (filter.exclude.some(t => builderTags.includes(t))) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
})
|
|
50
|
+
.map(b => b.buildToolDefinition());
|
|
51
|
+
}
|
|
52
|
+
/** Route a call to the correct builder */
|
|
53
|
+
async routeCall(ctx, name, args) {
|
|
54
|
+
const builder = this._builders.get(name);
|
|
55
|
+
if (!builder) {
|
|
56
|
+
const available = Array.from(this._builders.keys()).join(', ');
|
|
57
|
+
return error(`Unknown tool: "${name}". Available tools: ${available}`);
|
|
58
|
+
}
|
|
59
|
+
return builder.execute(ctx, args);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Attach this registry to an MCP Server — 1-line integration.
|
|
63
|
+
*
|
|
64
|
+
* Supports both:
|
|
65
|
+
* - `Server` (low-level): `import { Server } from '@modelcontextprotocol/sdk/server/index.js'`
|
|
66
|
+
* - `McpServer` (high-level): `import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'`
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Minimal — void context
|
|
71
|
+
* registry.attachToServer(server);
|
|
72
|
+
*
|
|
73
|
+
* // With tag filtering
|
|
74
|
+
* registry.attachToServer(server, { filter: { tags: ['public'] } });
|
|
75
|
+
*
|
|
76
|
+
* // With per-request context
|
|
77
|
+
* registry.attachToServer(server, {
|
|
78
|
+
* contextFactory: (extra) => ({ session: extra })
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @returns A detach function to remove the handlers.
|
|
83
|
+
*/
|
|
84
|
+
attachToServer(server, options = {}) {
|
|
85
|
+
// Resolve the low-level Server instance
|
|
86
|
+
const resolved = this._resolveServer(server);
|
|
87
|
+
const { filter, contextFactory } = options;
|
|
88
|
+
// ── tools/list handler ────────────────────────────────────────
|
|
89
|
+
const listHandler = () => {
|
|
90
|
+
const tools = filter
|
|
91
|
+
? this.getTools(filter)
|
|
92
|
+
: this.getAllTools();
|
|
93
|
+
return { tools };
|
|
94
|
+
};
|
|
95
|
+
// ── tools/call handler ────────────────────────────────────────
|
|
96
|
+
const callHandler = async (request, extra) => {
|
|
97
|
+
const { name, arguments: args = {} } = request.params;
|
|
98
|
+
const ctx = contextFactory
|
|
99
|
+
? contextFactory(extra)
|
|
100
|
+
: undefined;
|
|
101
|
+
return this.routeCall(ctx, name, args);
|
|
102
|
+
};
|
|
103
|
+
// Register both handlers
|
|
104
|
+
resolved.setRequestHandler(ListToolsRequestSchema, listHandler);
|
|
105
|
+
resolved.setRequestHandler(CallToolRequestSchema, callHandler);
|
|
106
|
+
// Return detach function
|
|
107
|
+
return () => {
|
|
108
|
+
// Reset handlers to no-op
|
|
109
|
+
resolved.setRequestHandler(ListToolsRequestSchema, () => ({ tools: [] }));
|
|
110
|
+
resolved.setRequestHandler(CallToolRequestSchema, async () => error('Tool handlers have been detached'));
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Check if a tool is registered */
|
|
114
|
+
has(name) {
|
|
115
|
+
return this._builders.has(name);
|
|
116
|
+
}
|
|
117
|
+
/** Remove all registered tools */
|
|
118
|
+
clear() {
|
|
119
|
+
this._builders.clear();
|
|
120
|
+
}
|
|
121
|
+
/** Get count of registered tools */
|
|
122
|
+
get size() {
|
|
123
|
+
return this._builders.size;
|
|
124
|
+
}
|
|
125
|
+
// ── Private ──────────────────────────────────────────────────────
|
|
126
|
+
/**
|
|
127
|
+
* Resolve the low-level Server instance from either a `Server` or `McpServer`.
|
|
128
|
+
*
|
|
129
|
+
* Uses duck-typing to detect the server type:
|
|
130
|
+
* - `McpServer` has a `.server` property that exposes the low-level `Server`
|
|
131
|
+
* - `Server` has `setRequestHandler` directly
|
|
132
|
+
*/
|
|
133
|
+
_resolveServer(server) {
|
|
134
|
+
if (!server || typeof server !== 'object') {
|
|
135
|
+
throw new Error('attachToServer() requires a Server or McpServer instance.');
|
|
136
|
+
}
|
|
137
|
+
// McpServer wraps a Server at `.server`
|
|
138
|
+
const maybeHigh = server;
|
|
139
|
+
if ('server' in maybeHigh &&
|
|
140
|
+
maybeHigh.server &&
|
|
141
|
+
typeof maybeHigh.server === 'object' &&
|
|
142
|
+
'setRequestHandler' in maybeHigh.server) {
|
|
143
|
+
return maybeHigh.server;
|
|
144
|
+
}
|
|
145
|
+
// Low-level Server has setRequestHandler directly
|
|
146
|
+
if ('setRequestHandler' in server) {
|
|
147
|
+
return server;
|
|
148
|
+
}
|
|
149
|
+
throw new Error('attachToServer() requires a Server or McpServer instance. ' +
|
|
150
|
+
'The provided object does not have setRequestHandler().');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=ToolRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolRegistry.js","sourceRoot":"","sources":["../../../src/framework/ToolRegistry.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,sBAAsB,EACtB,qBAAqB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAqB,KAAK,EAAE,MAAM,qBAAqB,CAAC;AA2C/D,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,MAAM,OAAO,YAAY;IAAzB;QACY,cAAS,GAAG,IAAI,GAAG,EAAiC,CAAC;IAsLjE,CAAC;IApLG,yDAAyD;IACzD,QAAQ,CAAC,OAA8B;QACnC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,0BAA0B,CAAC,CAAC;QAC7D,CAAC;QACD,uDAAuD;QACvD,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,yCAAyC;IACzC,WAAW,CAAC,GAAG,QAAiC;QAC5C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;IAED,+BAA+B;IAC/B,WAAW;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;aACrC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,4CAA4C;IAC5C,QA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ToolResponse } from './ResponseHelper.js';
|
|
5
|
+
export { GroupedToolBuilder, ActionGroupBuilder, type ActionConfig, type MiddlewareFn, type GroupConfigurator, } from './GroupedToolBuilder.js';
|
|
6
|
+
export { type ToolBuilder, type ActionMetadata } from './ToolBuilder.js';
|
|
7
|
+
export { ToolRegistry, type ToolFilter, type AttachOptions, type DetachFn } from './ToolRegistry.js';
|
|
8
|
+
export { generateToonDescription } from './strategies/index.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/framework/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACH,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,iBAAiB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework — Barrel Export
|
|
3
|
+
*/
|
|
4
|
+
export { success, error, required, toonSuccess } from './ResponseHelper.js';
|
|
5
|
+
export { GroupedToolBuilder, ActionGroupBuilder, } from './GroupedToolBuilder.js';
|
|
6
|
+
export { ToolRegistry } from './ToolRegistry.js';
|
|
7
|
+
export { generateToonDescription } from './strategies/index.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/framework/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAqB,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACH,kBAAkB,EAClB,kBAAkB,GAIrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAsD,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnnotationAggregator — Tool Annotation Aggregation Strategy
|
|
3
|
+
*
|
|
4
|
+
* Aggregates per-action hints (readOnly, destructive, idempotent)
|
|
5
|
+
* into a single annotation record, with explicit overrides.
|
|
6
|
+
*
|
|
7
|
+
* Pure-function module: no state, no side effects.
|
|
8
|
+
*/
|
|
9
|
+
import type { InternalAction } from './Types.js';
|
|
10
|
+
export declare function aggregateAnnotations<TContext>(actions: readonly InternalAction<TContext>[], explicitAnnotations: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
11
|
+
//# sourceMappingURL=AnnotationAggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnotationAggregator.d.ts","sourceRoot":"","sources":["../../../../src/framework/strategies/AnnotationAggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,wBAAgB,oBAAoB,CAAC,QAAQ,EACzC,OAAO,EAAE,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,EAC5C,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACzD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BzB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// ── Public API ───────────────────────────────────────────
|
|
2
|
+
export function aggregateAnnotations(actions, explicitAnnotations) {
|
|
3
|
+
const result = {};
|
|
4
|
+
// Copy explicit annotations
|
|
5
|
+
if (explicitAnnotations) {
|
|
6
|
+
Object.assign(result, explicitAnnotations);
|
|
7
|
+
}
|
|
8
|
+
// Per-action aggregation (only override if not explicitly set)
|
|
9
|
+
if ((explicitAnnotations === null || explicitAnnotations === void 0 ? void 0 : explicitAnnotations.readOnlyHint) === undefined) {
|
|
10
|
+
const allReadOnly = actions.length > 0 &&
|
|
11
|
+
actions.every(a => a.readOnly === true);
|
|
12
|
+
result.readOnlyHint = allReadOnly;
|
|
13
|
+
}
|
|
14
|
+
if ((explicitAnnotations === null || explicitAnnotations === void 0 ? void 0 : explicitAnnotations.destructiveHint) === undefined) {
|
|
15
|
+
const anyDestructive = actions.some(a => a.destructive === true);
|
|
16
|
+
result.destructiveHint = anyDestructive;
|
|
17
|
+
}
|
|
18
|
+
if ((explicitAnnotations === null || explicitAnnotations === void 0 ? void 0 : explicitAnnotations.idempotentHint) === undefined) {
|
|
19
|
+
const allIdempotent = actions.length > 0 &&
|
|
20
|
+
actions.every(a => a.idempotent === true);
|
|
21
|
+
result.idempotentHint = allIdempotent;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=AnnotationAggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnotationAggregator.js","sourceRoot":"","sources":["../../../../src/framework/strategies/AnnotationAggregator.ts"],"names":[],"mappings":"AAUA,4DAA4D;AAE5D,MAAM,UAAU,oBAAoB,CAChC,OAA4C,EAC5C,mBAAwD;IAExD,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,4BAA4B;IAC5B,IAAI,mBAAmB,EAAE,CAAC;QACtB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC/C,CAAC;IAED,+DAA+D;IAC/D,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,YAAY,MAAK,SAAS,EAAE,CAAC;QAClD,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,YAAY,GAAG,WAAW,CAAC;IACtC,CAAC;IAED,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,eAAe,MAAK,SAAS,EAAE,CAAC;QACrD,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC;QACjE,MAAM,CAAC,eAAe,GAAG,cAAc,CAAC;IAC5C,CAAC;IAED,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,cAAc,MAAK,SAAS,EAAE,CAAC;QACpD,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC;YACpC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC;QAC9C,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC;IAC1C,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DescriptionGenerator — LLM-friendly Tool Description Strategy
|
|
3
|
+
*
|
|
4
|
+
* Generates 3-layer descriptions from action metadata:
|
|
5
|
+
* - Layer 1: Tool summary + module/action listing
|
|
6
|
+
* - Layer 2: Workflow section with required params and destructive warnings
|
|
7
|
+
*
|
|
8
|
+
* Pure-function module: no state, no side effects.
|
|
9
|
+
*/
|
|
10
|
+
import type { InternalAction } from './Types.js';
|
|
11
|
+
export declare function generateDescription<TContext>(actions: readonly InternalAction<TContext>[], name: string, description: string | undefined, hasGroup: boolean): string;
|
|
12
|
+
//# sourceMappingURL=DescriptionGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescriptionGenerator.d.ts","sourceRoot":"","sources":["../../../../src/framework/strategies/DescriptionGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKjD,wBAAgB,mBAAmB,CAAC,QAAQ,EACxC,OAAO,EAAE,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,EAC5C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,QAAQ,EAAE,OAAO,GAClB,MAAM,CA8BR"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getActionRequiredFields } from './SchemaUtils.js';
|
|
2
|
+
// ── Public API ───────────────────────────────────────────
|
|
3
|
+
export function generateDescription(actions, name, description, hasGroup) {
|
|
4
|
+
const lines = [];
|
|
5
|
+
// Layer 1: Tool description + action/module summary
|
|
6
|
+
if (hasGroup) {
|
|
7
|
+
const groups = getGroupSummaries(actions);
|
|
8
|
+
const moduleList = groups
|
|
9
|
+
.map(g => `${g.name} (${g.actions.join(',')})`)
|
|
10
|
+
.join(' | ');
|
|
11
|
+
lines.push(`${description || name}. ` +
|
|
12
|
+
`Modules: ${moduleList}`);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const actionNames = actions.map(a => a.key);
|
|
16
|
+
lines.push(`${description || name}. ` +
|
|
17
|
+
`Actions: ${actionNames.join(', ')}`);
|
|
18
|
+
}
|
|
19
|
+
// Layer 2: Workflow section
|
|
20
|
+
const workflowLines = generateWorkflowLines(actions);
|
|
21
|
+
if (workflowLines.length > 0) {
|
|
22
|
+
lines.push('');
|
|
23
|
+
lines.push('Workflow:');
|
|
24
|
+
lines.push(...workflowLines);
|
|
25
|
+
}
|
|
26
|
+
return lines.join('\n');
|
|
27
|
+
}
|
|
28
|
+
// ── Internal helpers ─────────────────────────────────────
|
|
29
|
+
function generateWorkflowLines(actions) {
|
|
30
|
+
const lines = [];
|
|
31
|
+
for (const action of actions) {
|
|
32
|
+
const requiredFields = getActionRequiredFields(action);
|
|
33
|
+
const isDestructive = action.destructive === true;
|
|
34
|
+
if (!action.description && requiredFields.length === 0 && !isDestructive) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
let line = `- '${action.key}': `;
|
|
38
|
+
if (action.description) {
|
|
39
|
+
line += action.description;
|
|
40
|
+
}
|
|
41
|
+
if (requiredFields.length > 0) {
|
|
42
|
+
line += action.description ? '. Requires: ' : 'Requires: ';
|
|
43
|
+
line += requiredFields.join(', ');
|
|
44
|
+
}
|
|
45
|
+
if (isDestructive) {
|
|
46
|
+
line += ' ⚠️ DESTRUCTIVE';
|
|
47
|
+
}
|
|
48
|
+
lines.push(line);
|
|
49
|
+
}
|
|
50
|
+
return lines;
|
|
51
|
+
}
|
|
52
|
+
function getGroupSummaries(actions) {
|
|
53
|
+
const groups = new Map();
|
|
54
|
+
for (const action of actions) {
|
|
55
|
+
if (!action.groupName)
|
|
56
|
+
continue;
|
|
57
|
+
let group = groups.get(action.groupName);
|
|
58
|
+
if (!group) {
|
|
59
|
+
group = { description: action.groupDescription || '', actions: [] };
|
|
60
|
+
groups.set(action.groupName, group);
|
|
61
|
+
}
|
|
62
|
+
group.actions.push(action.actionName);
|
|
63
|
+
}
|
|
64
|
+
return Array.from(groups.entries()).map(([name, data]) => ({
|
|
65
|
+
name,
|
|
66
|
+
description: data.description,
|
|
67
|
+
actions: data.actions,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=DescriptionGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescriptionGenerator.js","sourceRoot":"","sources":["../../../../src/framework/strategies/DescriptionGenerator.ts"],"names":[],"mappings":"AAUA,OA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BAAgB,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;YACpE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI;QACJ,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;KACxB,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MiddlewareCompiler — Middleware Chain Pre-Compilation Strategy
|
|
3
|
+
*
|
|
4
|
+
* Wraps middlewares right-to-left around each action handler,
|
|
5
|
+
* producing a ready-to-execute chain per action key.
|
|
6
|
+
*
|
|
7
|
+
* Pure-function module: no state, no side effects.
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolResponse } from '../ResponseHelper.js';
|
|
10
|
+
import type { InternalAction, MiddlewareFn } from './Types.js';
|
|
11
|
+
export type CompiledChain<TContext> = Map<string, (ctx: TContext, args: Record<string, unknown>) => Promise<ToolResponse>>;
|
|
12
|
+
export declare function compileMiddlewareChains<TContext>(actions: readonly InternalAction<TContext>[], middlewares: readonly MiddlewareFn<TContext>[]): CompiledChain<TContext>;
|
|
13
|
+
//# sourceMappingURL=MiddlewareCompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareCompiler.d.ts","sourceRoot":"","sources":["../../../../src/framework/strategies/MiddlewareCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/D,MAAM,MAAM,aAAa,CAAC,QAAQ,IAAI,GAAG,CACrC,MAAM,EACN,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,CAC1E,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,QAAQ,EAC5C,OAAO,EAAE,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,EAC5C,WAAW,EAAE,SAAS,YAAY,CAAC,QAAQ,CAAC,EAAE,GAC/C,aAAa,CAAC,QAAQ,CAAC,CA4BzB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function compileMiddlewareChains(actions, middlewares) {
|
|
2
|
+
var _a;
|
|
3
|
+
const compiled = new Map();
|
|
4
|
+
for (const action of actions) {
|
|
5
|
+
// Build the chain: global middlewares → group/action middlewares → handler
|
|
6
|
+
let chain = action.handler;
|
|
7
|
+
// Per-action/group middleware (innermost, closest to handler)
|
|
8
|
+
const actionMws = (_a = action.middlewares) !== null && _a !== void 0 ? _a : [];
|
|
9
|
+
for (let i = actionMws.length - 1; i >= 0; i--) {
|
|
10
|
+
const mw = actionMws[i];
|
|
11
|
+
const nextFn = chain;
|
|
12
|
+
chain = (ctx, args) => mw(ctx, args, () => nextFn(ctx, args));
|
|
13
|
+
}
|
|
14
|
+
// Global middleware (outermost)
|
|
15
|
+
for (let i = middlewares.length - 1; i >= 0; i--) {
|
|
16
|
+
const mw = middlewares[i];
|
|
17
|
+
const nextFn = chain;
|
|
18
|
+
chain = (ctx, args) => mw(ctx, args, () => nextFn(ctx, args));
|
|
19
|
+
}
|
|
20
|
+
compiled.set(action.key, chain);
|
|
21
|
+
}
|
|
22
|
+
return compiled;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=MiddlewareCompiler.js.map
|
|
@@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AAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SchemaGenerator — JSON Schema Input Schema Strategy
|
|
3
|
+
*
|
|
4
|
+
* Generates MCP-compatible inputSchema from Zod definitions:
|
|
5
|
+
* - Discriminator enum from action keys
|
|
6
|
+
* - Common + per-action schema merging
|
|
7
|
+
* - Per-field annotations (required-for / optional-for)
|
|
8
|
+
*
|
|
9
|
+
* Pure-function module: no state, no side effects.
|
|
10
|
+
*/
|
|
11
|
+
import type { ZodObject, ZodRawShape } from 'zod';
|
|
12
|
+
import type { Tool as McpTool } from '@modelcontextprotocol/sdk/types.js';
|
|
13
|
+
import type { InternalAction } from './Types.js';
|
|
14
|
+
export declare function generateInputSchema<TContext>(actions: readonly InternalAction<TContext>[], discriminator: string, hasGroup: boolean, commonSchema: ZodObject<ZodRawShape> | undefined): McpTool['inputSchema'];
|
|
15
|
+
//# sourceMappingURL=SchemaGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaGenerator.d.ts","sourceRoot":"","sources":["../../../../src/framework/strategies/SchemaGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAElD,OAAO,KAAK,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,wBAAgB,mBAAmB,CAAC,QAAQ,EACxC,OAAO,EAAE,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,EAC5C,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,GACjD,OAAO,CAAC,aAAa,CAAC,CA0FxB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
2
|
+
// ── Public API ───────────────────────────────────────────
|
|
3
|
+
export function generateInputSchema(actions, discriminator, hasGroup, commonSchema) {
|
|
4
|
+
const actionKeys = actions.map(a => a.key);
|
|
5
|
+
const properties = {};
|
|
6
|
+
const topLevelRequired = [discriminator];
|
|
7
|
+
// Discriminator field with enum
|
|
8
|
+
properties[discriminator] = {
|
|
9
|
+
type: 'string',
|
|
10
|
+
enum: actionKeys,
|
|
11
|
+
description: hasGroup
|
|
12
|
+
? `Module and operation (module.${discriminator} format)`
|
|
13
|
+
: 'Which operation to perform',
|
|
14
|
+
};
|
|
15
|
+
// Track field → action keys mapping for annotations
|
|
16
|
+
const fieldActions = new Map();
|
|
17
|
+
// Common schema fields
|
|
18
|
+
const commonRequiredFields = new Set();
|
|
19
|
+
if (commonSchema) {
|
|
20
|
+
const jsonSchema = zodToJsonSchema(commonSchema, { target: 'jsonSchema7' });
|
|
21
|
+
const schemaObj = jsonSchema;
|
|
22
|
+
const schemaProps = (schemaObj.properties || {});
|
|
23
|
+
const schemaRequired = (schemaObj.required || []);
|
|
24
|
+
for (const field of schemaRequired) {
|
|
25
|
+
commonRequiredFields.add(field);
|
|
26
|
+
topLevelRequired.push(field);
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of Object.entries(schemaProps)) {
|
|
29
|
+
properties[key] = value;
|
|
30
|
+
fieldActions.set(key, {
|
|
31
|
+
keys: [...actionKeys],
|
|
32
|
+
requiredIn: commonRequiredFields.has(key) ? [...actionKeys] : [],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Per-action schema fields
|
|
37
|
+
for (const action of actions) {
|
|
38
|
+
if (!action.schema)
|
|
39
|
+
continue;
|
|
40
|
+
const jsonSchema = zodToJsonSchema(action.schema, { target: 'jsonSchema7' });
|
|
41
|
+
const schemaObj = jsonSchema;
|
|
42
|
+
const schemaProps = (schemaObj.properties || {});
|
|
43
|
+
const schemaRequired = (schemaObj.required || []);
|
|
44
|
+
const requiredSet = new Set(schemaRequired);
|
|
45
|
+
for (const [key, value] of Object.entries(schemaProps)) {
|
|
46
|
+
// First declaration wins
|
|
47
|
+
if (!properties[key]) {
|
|
48
|
+
properties[key] = value;
|
|
49
|
+
}
|
|
50
|
+
let tracking = fieldActions.get(key);
|
|
51
|
+
if (!tracking) {
|
|
52
|
+
tracking = { keys: [], requiredIn: [] };
|
|
53
|
+
fieldActions.set(key, tracking);
|
|
54
|
+
}
|
|
55
|
+
tracking.keys.push(action.key);
|
|
56
|
+
if (requiredSet.has(key)) {
|
|
57
|
+
tracking.requiredIn.push(action.key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Apply per-field annotations
|
|
62
|
+
for (const [key, tracking] of fieldActions.entries()) {
|
|
63
|
+
if (commonRequiredFields.has(key)) {
|
|
64
|
+
annotateField(properties, key, '(always required)');
|
|
65
|
+
}
|
|
66
|
+
else if (tracking.requiredIn.length > 0 && tracking.requiredIn.length === tracking.keys.length) {
|
|
67
|
+
annotateField(properties, key, `Required for: ${tracking.requiredIn.join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
else if (tracking.requiredIn.length > 0) {
|
|
70
|
+
const optionalIn = tracking.keys.filter(k => !tracking.requiredIn.includes(k));
|
|
71
|
+
let annotation = `Required for: ${tracking.requiredIn.join(', ')}`;
|
|
72
|
+
if (optionalIn.length > 0) {
|
|
73
|
+
annotation += `. For: ${optionalIn.join(', ')}`;
|
|
74
|
+
}
|
|
75
|
+
annotateField(properties, key, annotation);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
annotateField(properties, key, `For: ${tracking.keys.join(', ')}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties,
|
|
84
|
+
required: topLevelRequired,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// ── Internal helpers ─────────────────────────────────────
|
|
88
|
+
function annotateField(properties, key, annotation) {
|
|
89
|
+
const field = properties[key];
|
|
90
|
+
if (!field)
|
|
91
|
+
return;
|
|
92
|
+
const existingDesc = field.description || '';
|
|
93
|
+
field.description = existingDesc
|
|
94
|
+
? `${existingDesc}. ${annotation}`
|
|
95
|
+
: annotation;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=SchemaGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaGenerator.js","sourceRoot":"","sources":["../../../../src/framework/strategies/SchemaGenerator.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,4DAA4D;AAE5D,MAAM,UAAU,mBAAmB,CAC/B,OAA4C,EAC5C,aAAqB,EACrB,QAAiB,EACjB,YAAgD;IAEhD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,MAAM,gBAAgB,GAAa,CAAC,aAAa,CAAC,CAAC;IAEnD,gCAAgC;IAChC,UAAU,CAAC,aAAa,CAAC,GAAG;QACxB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,QAAQ;YACjB,CAAC,CAAC,gCAAgC,aAAa,UAAU;YACzD,CAAC,CAAC,4BAA4B;KACrC,CAAC;IAEF,oDAAoD;IACpD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoD,CAAC;IAEjF,uBAAuB;IACvB,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/C,IAAI,YAAY,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,eAAe,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,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an action's Zod schema.
|
|
4
|
+
* Returns an empty array if the action has no schema.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getActionRequiredFields<TContext>(action: InternalAction<TContext>): string[];
|
|
7
|
+
//# sourceMappingURL=SchemaUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaUtils.d.ts","sourceRoot":"","sources":["../../../../src/framework/strategies/SchemaUtils.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,MAAM,EAAE,CAU5F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the list of required field names from an action's Zod schema.
|
|
3
|
+
* Returns an empty array if the action has no schema.
|
|
4
|
+
*/
|
|
5
|
+
export function getActionRequiredFields(action) {
|
|
6
|
+
if (!action.schema)
|
|
7
|
+
return [];
|
|
8
|
+
const shape = action.schema.shape;
|
|
9
|
+
const required = [];
|
|
10
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
11
|
+
if (!(fieldSchema.isOptional())) {
|
|
12
|
+
required.push(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return required;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=SchemaUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../../../../src/framework/strategies/SchemaUtils.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAW,MAAgC;IAC9E,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IAClC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,IAAI,CAAC,CAAE,WAA4B,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;YAChD,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { InternalAction } from './Types.js';
|
|
2
|
+
export declare function generateToonDescription<TContext>(actions: readonly InternalAction<TContext>[], name: string, description: string | undefined, hasGroup: boolean): string;
|
|
3
|
+
//# sourceMappingURL=ToonDescriptionGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToonDescriptionGenerator.d.ts","sourceRoot":"","sources":["../../../../src/framework/strategies/ToonDescriptionGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKjD,wBAAgB,uBAAuB,CAAC,QAAQ,EAC5C,OAAO,EAAE,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,EAC5C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,QAAQ,EAAE,OAAO,GAClB,MAAM,CAeR"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { encode } from '@toon-format/toon';
|
|
2
|
+
import { getActionRequiredFields } from './SchemaUtils.js';
|
|
3
|
+
// ── Public API ───────────────────────────────────────────
|
|
4
|
+
export function generateToonDescription(actions, name, description, hasGroup) {
|
|
5
|
+
const lines = [];
|
|
6
|
+
// Layer 1: Tool summary (always human-readable)
|
|
7
|
+
lines.push(description || name);
|
|
8
|
+
lines.push('');
|
|
9
|
+
// Layer 2: Action metadata in TOON tabular format
|
|
10
|
+
if (hasGroup) {
|
|
11
|
+
lines.push(encodeGroupedActions(actions));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
lines.push(encodeFlatActions(actions));
|
|
15
|
+
}
|
|
16
|
+
return lines.join('\n');
|
|
17
|
+
}
|
|
18
|
+
function encodeFlatActions(actions) {
|
|
19
|
+
const rows = actions.map(a => buildActionRow(a.key, a));
|
|
20
|
+
return encode(rows, { delimiter: '|' });
|
|
21
|
+
}
|
|
22
|
+
function encodeGroupedActions(actions) {
|
|
23
|
+
// Group actions by their groupName
|
|
24
|
+
const groups = new Map();
|
|
25
|
+
for (const action of actions) {
|
|
26
|
+
const key = action.groupName || '_ungrouped';
|
|
27
|
+
let list = groups.get(key);
|
|
28
|
+
if (!list) {
|
|
29
|
+
list = [];
|
|
30
|
+
groups.set(key, list);
|
|
31
|
+
}
|
|
32
|
+
list.push(action);
|
|
33
|
+
}
|
|
34
|
+
// Build a structure that TOON can encode efficiently
|
|
35
|
+
const groupData = {};
|
|
36
|
+
for (const [groupName, groupActions] of groups) {
|
|
37
|
+
groupData[groupName] = groupActions.map(a => buildActionRow(a.actionName, a));
|
|
38
|
+
}
|
|
39
|
+
return encode(groupData, { delimiter: '|' });
|
|
40
|
+
}
|
|
41
|
+
function buildActionRow(key, action) {
|
|
42
|
+
const required = getActionRequiredFields(action);
|
|
43
|
+
const row = {
|
|
44
|
+
action: key,
|
|
45
|
+
desc: action.description || '',
|
|
46
|
+
required: required.join(','),
|
|
47
|
+
};
|
|
48
|
+
if (action.destructive) {
|
|
49
|
+
row.destructive = true;
|
|
50
|
+
}
|
|
51
|
+
return row;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=ToonDescriptionGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToonDescriptionGenerator.js","sourceRoot":"","sources":["../../../../src/framework/strategies/ToonDescriptionGenerator.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,uBAAuB,E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