@frontmcp/plugins 0.4.1 → 0.5.1
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/package.json +8 -3
- package/src/cache/cache.plugin.js +27 -25
- package/src/cache/cache.plugin.js.map +1 -1
- package/src/cache/providers/cache-memory.provider.js +2 -1
- package/src/cache/providers/cache-memory.provider.js.map +1 -1
- package/src/cache/providers/cache-redis.provider.js +1 -0
- package/src/cache/providers/cache-redis.provider.js.map +1 -1
- package/src/codecall/README.md +999 -0
- package/src/codecall/codecall.plugin.d.ts +41 -0
- package/src/codecall/codecall.plugin.js +152 -0
- package/src/codecall/codecall.plugin.js.map +1 -0
- package/src/codecall/codecall.symbol.d.ts +106 -0
- package/src/codecall/codecall.symbol.js +4 -0
- package/src/codecall/codecall.symbol.js.map +1 -0
- package/src/codecall/codecall.types.d.ts +289 -0
- package/src/codecall/codecall.types.js +258 -0
- package/src/codecall/codecall.types.js.map +1 -0
- package/src/codecall/errors/index.d.ts +1 -0
- package/src/codecall/errors/index.js +6 -0
- package/src/codecall/errors/index.js.map +1 -0
- package/src/codecall/errors/tool-call.errors.d.ts +79 -0
- package/src/codecall/errors/tool-call.errors.js +119 -0
- package/src/codecall/errors/tool-call.errors.js.map +1 -0
- package/src/codecall/index.d.ts +2 -0
- package/src/codecall/index.js +8 -0
- package/src/codecall/index.js.map +1 -0
- package/src/codecall/providers/code-call.config.d.ts +29 -0
- package/src/codecall/providers/code-call.config.js +120 -0
- package/src/codecall/providers/code-call.config.js.map +1 -0
- package/src/codecall/security/index.d.ts +2 -0
- package/src/codecall/security/index.js +7 -0
- package/src/codecall/security/index.js.map +1 -0
- package/src/codecall/security/self-reference-guard.d.ts +32 -0
- package/src/codecall/security/self-reference-guard.js +70 -0
- package/src/codecall/security/self-reference-guard.js.map +1 -0
- package/src/codecall/security/tool-access-control.service.d.ts +104 -0
- package/src/codecall/security/tool-access-control.service.js +170 -0
- package/src/codecall/security/tool-access-control.service.js.map +1 -0
- package/src/codecall/services/audit-logger.service.d.ts +186 -0
- package/src/codecall/services/audit-logger.service.js +322 -0
- package/src/codecall/services/audit-logger.service.js.map +1 -0
- package/src/codecall/services/enclave.service.d.ts +62 -0
- package/src/codecall/services/enclave.service.js +214 -0
- package/src/codecall/services/enclave.service.js.map +1 -0
- package/src/codecall/services/error-enrichment.service.d.ts +94 -0
- package/src/codecall/services/error-enrichment.service.js +387 -0
- package/src/codecall/services/error-enrichment.service.js.map +1 -0
- package/src/codecall/services/index.d.ts +6 -0
- package/src/codecall/services/index.js +13 -0
- package/src/codecall/services/index.js.map +1 -0
- package/src/codecall/services/output-sanitizer.d.ts +86 -0
- package/src/codecall/services/output-sanitizer.js +260 -0
- package/src/codecall/services/output-sanitizer.js.map +1 -0
- package/src/codecall/services/synonym-expansion.service.d.ts +66 -0
- package/src/codecall/services/synonym-expansion.service.js +374 -0
- package/src/codecall/services/synonym-expansion.service.js.map +1 -0
- package/src/codecall/services/tool-search.service.d.ts +175 -0
- package/src/codecall/services/tool-search.service.js +587 -0
- package/src/codecall/services/tool-search.service.js.map +1 -0
- package/src/codecall/tools/describe.schema.d.ts +28 -0
- package/src/codecall/tools/describe.schema.js +67 -0
- package/src/codecall/tools/describe.schema.js.map +1 -0
- package/src/codecall/tools/describe.tool.d.ts +35 -0
- package/src/codecall/tools/describe.tool.js +207 -0
- package/src/codecall/tools/describe.tool.js.map +1 -0
- package/src/codecall/tools/execute.schema.d.ts +115 -0
- package/src/codecall/tools/execute.schema.js +116 -0
- package/src/codecall/tools/execute.schema.js.map +1 -0
- package/src/codecall/tools/execute.tool.d.ts +5 -0
- package/src/codecall/tools/execute.tool.js +238 -0
- package/src/codecall/tools/execute.tool.js.map +1 -0
- package/src/codecall/tools/index.d.ts +4 -0
- package/src/codecall/tools/index.js +13 -0
- package/src/codecall/tools/index.js.map +1 -0
- package/src/codecall/tools/invoke.schema.d.ts +99 -0
- package/src/codecall/tools/invoke.schema.js +27 -0
- package/src/codecall/tools/invoke.schema.js.map +1 -0
- package/src/codecall/tools/invoke.tool.d.ts +13 -0
- package/src/codecall/tools/invoke.tool.js +70 -0
- package/src/codecall/tools/invoke.tool.js.map +1 -0
- package/src/codecall/tools/search.schema.d.ts +30 -0
- package/src/codecall/tools/search.schema.js +60 -0
- package/src/codecall/tools/search.schema.js.map +1 -0
- package/src/codecall/tools/search.tool.d.ts +5 -0
- package/src/codecall/tools/search.tool.js +108 -0
- package/src/codecall/tools/search.tool.js.map +1 -0
- package/src/codecall/utils/describe.utils.d.ts +86 -0
- package/src/codecall/utils/describe.utils.js +531 -0
- package/src/codecall/utils/describe.utils.js.map +1 -0
- package/src/codecall/utils/index.d.ts +2 -0
- package/src/codecall/utils/index.js +7 -0
- package/src/codecall/utils/index.js.map +1 -0
- package/src/codecall/utils/mcp-result.d.ts +6 -0
- package/src/codecall/utils/mcp-result.js +36 -0
- package/src/codecall/utils/mcp-result.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: libs/plugins/src/codecall/utils/describe.utils.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.detectToolIntent = detectToolIntent;
|
|
5
|
+
exports.jsonSchemaToSignature = jsonSchemaToSignature;
|
|
6
|
+
exports.jsonSchemaToNaturalLanguage = jsonSchemaToNaturalLanguage;
|
|
7
|
+
exports.generateBasicExample = generateBasicExample;
|
|
8
|
+
exports.hasPaginationParams = hasPaginationParams;
|
|
9
|
+
exports.hasFilterParams = hasFilterParams;
|
|
10
|
+
exports.getFilterProperties = getFilterProperties;
|
|
11
|
+
exports.generatePaginationExample = generatePaginationExample;
|
|
12
|
+
exports.generateFilterExample = generateFilterExample;
|
|
13
|
+
exports.generateCreateExample = generateCreateExample;
|
|
14
|
+
exports.generateGetExample = generateGetExample;
|
|
15
|
+
exports.generateListExample = generateListExample;
|
|
16
|
+
exports.generateUpdateExample = generateUpdateExample;
|
|
17
|
+
exports.generateDeleteExample = generateDeleteExample;
|
|
18
|
+
exports.generateSearchExample = generateSearchExample;
|
|
19
|
+
exports.generateSmartExample = generateSmartExample;
|
|
20
|
+
/**
|
|
21
|
+
* Patterns for detecting tool intent from the action verb.
|
|
22
|
+
* These patterns use the same synonym groups as the search service.
|
|
23
|
+
*/
|
|
24
|
+
const INTENT_PATTERNS = {
|
|
25
|
+
create: /^(create|add|new|insert|make|append|register|generate|produce|build|construct|provision|instantiate|define|compose|draft)/i,
|
|
26
|
+
delete: /^(delete|remove|destroy|drop|erase|clear|purge|discard|eliminate|unbind|unregister)/i,
|
|
27
|
+
get: /^(get|fetch|retrieve|read|obtain|load|pull|access|grab|receive)/i,
|
|
28
|
+
update: /^(update|edit|modify|change|patch|set|alter|revise|adjust|amend|correct|fix|refresh|sync|upgrade|downgrade)/i,
|
|
29
|
+
list: /^(list|all|index|enumerate|show|display|view|browse|scan|inventory)/i,
|
|
30
|
+
search: /^(search|find|query|lookup|locate|discover|explore|seek|match|filter)/i,
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Detect the intent of a tool from its name.
|
|
34
|
+
* Extracts the action verb from tool names like "users:create" or "orders:list".
|
|
35
|
+
*/
|
|
36
|
+
function detectToolIntent(toolName, description) {
|
|
37
|
+
// Extract action verb from tool name (e.g., "users:create" -> "create")
|
|
38
|
+
const parts = toolName.split(':');
|
|
39
|
+
const actionPart = parts.length > 1 ? parts[parts.length - 1] : toolName;
|
|
40
|
+
// Check each intent pattern
|
|
41
|
+
for (const [intent, pattern] of Object.entries(INTENT_PATTERNS)) {
|
|
42
|
+
if (pattern.test(actionPart)) {
|
|
43
|
+
return intent;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Fallback: check description for clues
|
|
47
|
+
if (description) {
|
|
48
|
+
const descLower = description.toLowerCase();
|
|
49
|
+
if (/creates?\s|adding\s|inserts?/i.test(descLower))
|
|
50
|
+
return 'create';
|
|
51
|
+
if (/deletes?\s|removes?\s|destroys?/i.test(descLower))
|
|
52
|
+
return 'delete';
|
|
53
|
+
if (/gets?\s|fetche?s?\s|retrieves?/i.test(descLower))
|
|
54
|
+
return 'get';
|
|
55
|
+
if (/updates?\s|modif(?:y|ies)\s|edits?/i.test(descLower))
|
|
56
|
+
return 'update';
|
|
57
|
+
if (/lists?\s|shows?\s|displays?/i.test(descLower))
|
|
58
|
+
return 'list';
|
|
59
|
+
if (/search(?:es)?\s|find(?:s)?\s|quer(?:y|ies)/i.test(descLower))
|
|
60
|
+
return 'search';
|
|
61
|
+
}
|
|
62
|
+
return 'unknown';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generate a TypeScript-like function signature from a JSON Schema.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* Input: { type: 'object', properties: { id: { type: 'string' }, limit: { type: 'number' } }, required: ['id'] }
|
|
69
|
+
* Output: "(id: string, limit?: number) => unknown"
|
|
70
|
+
*/
|
|
71
|
+
function jsonSchemaToSignature(toolName, inputSchema, outputSchema) {
|
|
72
|
+
const inputPart = schemaToTypeString(inputSchema, 'input');
|
|
73
|
+
const outputPart = schemaToTypeString(outputSchema, 'output');
|
|
74
|
+
return `callTool('${toolName}', ${inputPart}) => Promise<${outputPart}>`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert JSON Schema to a TypeScript-like type string.
|
|
78
|
+
*/
|
|
79
|
+
function schemaToTypeString(schema, context) {
|
|
80
|
+
if (!schema) {
|
|
81
|
+
return context === 'input' ? '{}' : 'unknown';
|
|
82
|
+
}
|
|
83
|
+
if (schema.type === 'object' && schema.properties) {
|
|
84
|
+
const props = [];
|
|
85
|
+
const required = new Set(schema.required || []);
|
|
86
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
87
|
+
if (typeof propSchema === 'boolean')
|
|
88
|
+
continue;
|
|
89
|
+
const isRequired = required.has(key);
|
|
90
|
+
const typeStr = getTypeString(propSchema);
|
|
91
|
+
props.push(`${key}${isRequired ? '' : '?'}: ${typeStr}`);
|
|
92
|
+
}
|
|
93
|
+
if (props.length === 0) {
|
|
94
|
+
return '{}';
|
|
95
|
+
}
|
|
96
|
+
return `{ ${props.join(', ')} }`;
|
|
97
|
+
}
|
|
98
|
+
return getTypeString(schema);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get a simple type string for a schema.
|
|
102
|
+
*/
|
|
103
|
+
function getTypeString(schema) {
|
|
104
|
+
if (schema.enum) {
|
|
105
|
+
return schema.enum.map((v) => JSON.stringify(v)).join(' | ');
|
|
106
|
+
}
|
|
107
|
+
if (schema.type) {
|
|
108
|
+
if (Array.isArray(schema.type)) {
|
|
109
|
+
return schema.type.join(' | ');
|
|
110
|
+
}
|
|
111
|
+
switch (schema.type) {
|
|
112
|
+
case 'string':
|
|
113
|
+
return 'string';
|
|
114
|
+
case 'number':
|
|
115
|
+
case 'integer':
|
|
116
|
+
return 'number';
|
|
117
|
+
case 'boolean':
|
|
118
|
+
return 'boolean';
|
|
119
|
+
case 'null':
|
|
120
|
+
return 'null';
|
|
121
|
+
case 'array':
|
|
122
|
+
if (schema.items && typeof schema.items !== 'boolean') {
|
|
123
|
+
return `${getTypeString(schema.items)}[]`;
|
|
124
|
+
}
|
|
125
|
+
return 'unknown[]';
|
|
126
|
+
case 'object':
|
|
127
|
+
if (schema.properties) {
|
|
128
|
+
return schemaToTypeString(schema, 'input');
|
|
129
|
+
}
|
|
130
|
+
return 'Record<string, unknown>';
|
|
131
|
+
default:
|
|
132
|
+
return 'unknown';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (schema.oneOf || schema.anyOf) {
|
|
136
|
+
// We've confirmed at least one is truthy, so use non-null assertion
|
|
137
|
+
const options = (schema.oneOf ?? schema.anyOf);
|
|
138
|
+
return options
|
|
139
|
+
.filter((s) => typeof s !== 'boolean')
|
|
140
|
+
.map((s) => getTypeString(s))
|
|
141
|
+
.join(' | ');
|
|
142
|
+
}
|
|
143
|
+
return 'unknown';
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Generate a natural language summary of a schema.
|
|
147
|
+
*/
|
|
148
|
+
function jsonSchemaToNaturalLanguage(schema, direction) {
|
|
149
|
+
if (!schema) {
|
|
150
|
+
return direction === 'input' ? 'No input parameters' : 'Returns unspecified data';
|
|
151
|
+
}
|
|
152
|
+
if (schema.description) {
|
|
153
|
+
return schema.description;
|
|
154
|
+
}
|
|
155
|
+
if (schema.type === 'object' && schema.properties) {
|
|
156
|
+
const required = new Set(schema.required || []);
|
|
157
|
+
const props = Object.entries(schema.properties);
|
|
158
|
+
if (props.length === 0) {
|
|
159
|
+
return direction === 'input' ? 'No parameters required' : 'Returns an empty object';
|
|
160
|
+
}
|
|
161
|
+
const requiredProps = props.filter(([key]) => required.has(key));
|
|
162
|
+
const optionalProps = props.filter(([key]) => !required.has(key));
|
|
163
|
+
const parts = [];
|
|
164
|
+
if (requiredProps.length > 0) {
|
|
165
|
+
parts.push(`Required: ${requiredProps.map(([k]) => k).join(', ')}`);
|
|
166
|
+
}
|
|
167
|
+
if (optionalProps.length > 0) {
|
|
168
|
+
parts.push(`Optional: ${optionalProps.map(([k]) => k).join(', ')}`);
|
|
169
|
+
}
|
|
170
|
+
return parts.join('. ');
|
|
171
|
+
}
|
|
172
|
+
return direction === 'input' ? `Takes a ${schema.type || 'value'}` : `Returns a ${schema.type || 'value'}`;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Generate a basic usage example for a tool.
|
|
176
|
+
*/
|
|
177
|
+
function generateBasicExample(toolName, inputSchema) {
|
|
178
|
+
const params = generateSampleParams(inputSchema);
|
|
179
|
+
const paramsStr = params ? JSON.stringify(params, null, 2) : '{}';
|
|
180
|
+
return {
|
|
181
|
+
description: `Basic usage of ${toolName}`,
|
|
182
|
+
code: `const result = await callTool('${toolName}', ${paramsStr});
|
|
183
|
+
return result;`,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Generate sample parameters from a schema.
|
|
188
|
+
*/
|
|
189
|
+
function generateSampleParams(schema) {
|
|
190
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const params = {};
|
|
194
|
+
const required = new Set(schema.required || []);
|
|
195
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
196
|
+
if (typeof propSchema === 'boolean')
|
|
197
|
+
continue;
|
|
198
|
+
// Only include required params and a couple optional ones for example
|
|
199
|
+
if (!required.has(key))
|
|
200
|
+
continue;
|
|
201
|
+
params[key] = getSampleValue(propSchema, key);
|
|
202
|
+
}
|
|
203
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Generate a sample value for a schema property.
|
|
207
|
+
*/
|
|
208
|
+
function getSampleValue(schema, key) {
|
|
209
|
+
if (schema.default !== undefined) {
|
|
210
|
+
return schema.default;
|
|
211
|
+
}
|
|
212
|
+
if (schema.enum && schema.enum.length > 0) {
|
|
213
|
+
return schema.enum[0];
|
|
214
|
+
}
|
|
215
|
+
if (schema.const !== undefined) {
|
|
216
|
+
return schema.const;
|
|
217
|
+
}
|
|
218
|
+
const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
219
|
+
switch (type) {
|
|
220
|
+
case 'string':
|
|
221
|
+
// Generate contextual sample based on key name
|
|
222
|
+
if (key.toLowerCase().includes('id'))
|
|
223
|
+
return 'abc123';
|
|
224
|
+
if (key.toLowerCase().includes('email'))
|
|
225
|
+
return 'user@example.com';
|
|
226
|
+
if (key.toLowerCase().includes('name'))
|
|
227
|
+
return 'Example';
|
|
228
|
+
if (key.toLowerCase().includes('url'))
|
|
229
|
+
return 'https://example.com';
|
|
230
|
+
return 'string';
|
|
231
|
+
case 'number':
|
|
232
|
+
case 'integer':
|
|
233
|
+
if (key.toLowerCase().includes('limit'))
|
|
234
|
+
return 10;
|
|
235
|
+
if (key.toLowerCase().includes('offset'))
|
|
236
|
+
return 0;
|
|
237
|
+
if (key.toLowerCase().includes('page'))
|
|
238
|
+
return 1;
|
|
239
|
+
return 0;
|
|
240
|
+
case 'boolean':
|
|
241
|
+
return true;
|
|
242
|
+
case 'array':
|
|
243
|
+
return [];
|
|
244
|
+
case 'object':
|
|
245
|
+
return {};
|
|
246
|
+
default:
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Check if a schema has pagination parameters.
|
|
252
|
+
*/
|
|
253
|
+
function hasPaginationParams(schema) {
|
|
254
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const props = Object.keys(schema.properties);
|
|
258
|
+
return props.some((p) => ['limit', 'offset', 'page', 'pageSize', 'cursor'].includes(p.toLowerCase()));
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Check if a schema has filter-like parameters.
|
|
262
|
+
*/
|
|
263
|
+
function hasFilterParams(schema) {
|
|
264
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
const props = Object.keys(schema.properties);
|
|
268
|
+
return props.some((p) => p.toLowerCase().includes('filter') ||
|
|
269
|
+
p.toLowerCase().includes('query') ||
|
|
270
|
+
p.toLowerCase().includes('search') ||
|
|
271
|
+
p.toLowerCase() === 'status' ||
|
|
272
|
+
p.toLowerCase() === 'type' ||
|
|
273
|
+
p.toLowerCase() === 'role');
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get filter-like property names from a schema.
|
|
277
|
+
*/
|
|
278
|
+
function getFilterProperties(schema) {
|
|
279
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
return Object.keys(schema.properties).filter((p) => p.toLowerCase().includes('filter') ||
|
|
283
|
+
p.toLowerCase().includes('query') ||
|
|
284
|
+
p.toLowerCase().includes('search') ||
|
|
285
|
+
p.toLowerCase() === 'status' ||
|
|
286
|
+
p.toLowerCase() === 'type' ||
|
|
287
|
+
p.toLowerCase() === 'role');
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Generate a pagination example for a tool.
|
|
291
|
+
*/
|
|
292
|
+
function generatePaginationExample(toolName) {
|
|
293
|
+
return {
|
|
294
|
+
description: `Pagination example for ${toolName}`,
|
|
295
|
+
code: `// Fetch first page
|
|
296
|
+
const page1 = await callTool('${toolName}', { limit: 10, offset: 0 });
|
|
297
|
+
|
|
298
|
+
// Fetch second page
|
|
299
|
+
const page2 = await callTool('${toolName}', { limit: 10, offset: 10 });
|
|
300
|
+
|
|
301
|
+
// Combine results
|
|
302
|
+
return [...page1.items, ...page2.items];`,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Generate a filter example for a tool.
|
|
307
|
+
*/
|
|
308
|
+
function generateFilterExample(toolName, filterProp) {
|
|
309
|
+
return {
|
|
310
|
+
description: `Filter by ${filterProp}`,
|
|
311
|
+
code: `const filtered = await callTool('${toolName}', { ${filterProp}: 'value' });
|
|
312
|
+
return filtered.items || filtered;`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
// ==========================================
|
|
316
|
+
// Intent-Specific Example Generators
|
|
317
|
+
// ==========================================
|
|
318
|
+
/**
|
|
319
|
+
* Extract entity name from tool name (e.g., "users:create" -> "user")
|
|
320
|
+
*/
|
|
321
|
+
function extractEntityName(toolName) {
|
|
322
|
+
const parts = toolName.split(':');
|
|
323
|
+
const entity = parts.length > 1 ? parts[0] : toolName;
|
|
324
|
+
// Singularize simple plurals
|
|
325
|
+
return entity.endsWith('s') && !entity.endsWith('ss') ? entity.slice(0, -1) : entity;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Generate a create example for a tool.
|
|
329
|
+
* Shows required parameters with contextual sample values.
|
|
330
|
+
*/
|
|
331
|
+
function generateCreateExample(toolName, inputSchema) {
|
|
332
|
+
const entity = extractEntityName(toolName);
|
|
333
|
+
const params = generateSampleParams(inputSchema);
|
|
334
|
+
const paramsStr = params ? JSON.stringify(params, null, 2) : '{ /* required fields */ }';
|
|
335
|
+
return {
|
|
336
|
+
description: `Create a new ${entity}`,
|
|
337
|
+
code: `const result = await callTool('${toolName}', ${paramsStr});
|
|
338
|
+
return result;`,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Generate a get (retrieve single item) example for a tool.
|
|
343
|
+
*/
|
|
344
|
+
function generateGetExample(toolName, inputSchema) {
|
|
345
|
+
const entity = extractEntityName(toolName);
|
|
346
|
+
const idParam = findIdParameter(inputSchema);
|
|
347
|
+
if (idParam) {
|
|
348
|
+
return {
|
|
349
|
+
description: `Get ${entity} by ${idParam}`,
|
|
350
|
+
code: `const ${entity} = await callTool('${toolName}', { ${idParam}: 'abc123' });
|
|
351
|
+
return ${entity};`,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
// Fallback to basic example if no ID parameter found
|
|
355
|
+
const params = generateSampleParams(inputSchema);
|
|
356
|
+
const paramsStr = params ? JSON.stringify(params, null, 2) : '{}';
|
|
357
|
+
return {
|
|
358
|
+
description: `Get ${entity} details`,
|
|
359
|
+
code: `const ${entity} = await callTool('${toolName}', ${paramsStr});
|
|
360
|
+
return ${entity};`,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Generate a list example for a tool.
|
|
365
|
+
*/
|
|
366
|
+
function generateListExample(toolName, inputSchema) {
|
|
367
|
+
const entity = extractEntityName(toolName);
|
|
368
|
+
return {
|
|
369
|
+
description: `List all ${entity}s`,
|
|
370
|
+
code: `const result = await callTool('${toolName}', {});
|
|
371
|
+
return result.items || result;`,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Generate an update example for a tool.
|
|
376
|
+
*/
|
|
377
|
+
function generateUpdateExample(toolName, inputSchema) {
|
|
378
|
+
const entity = extractEntityName(toolName);
|
|
379
|
+
const idParam = findIdParameter(inputSchema);
|
|
380
|
+
// Generate sample update fields (excluding ID fields)
|
|
381
|
+
const updateFields = generateUpdateFields(inputSchema);
|
|
382
|
+
const fieldsStr = updateFields
|
|
383
|
+
? JSON.stringify(updateFields, null, 2).replace(/\n/g, '\n ')
|
|
384
|
+
: '{ /* fields to update */ }';
|
|
385
|
+
if (idParam) {
|
|
386
|
+
return {
|
|
387
|
+
description: `Update ${entity} by ${idParam}`,
|
|
388
|
+
code: `const updated = await callTool('${toolName}', {
|
|
389
|
+
${idParam}: 'abc123',
|
|
390
|
+
...${fieldsStr}
|
|
391
|
+
});
|
|
392
|
+
return updated;`,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
description: `Update ${entity}`,
|
|
397
|
+
code: `const updated = await callTool('${toolName}', ${fieldsStr});
|
|
398
|
+
return updated;`,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Generate a delete example for a tool.
|
|
403
|
+
*/
|
|
404
|
+
function generateDeleteExample(toolName, inputSchema) {
|
|
405
|
+
const entity = extractEntityName(toolName);
|
|
406
|
+
const idParam = findIdParameter(inputSchema);
|
|
407
|
+
if (idParam) {
|
|
408
|
+
return {
|
|
409
|
+
description: `Delete ${entity} by ${idParam}`,
|
|
410
|
+
code: `const result = await callTool('${toolName}', { ${idParam}: 'abc123' });
|
|
411
|
+
return result;`,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
const params = generateSampleParams(inputSchema);
|
|
415
|
+
const paramsStr = params ? JSON.stringify(params, null, 2) : '{ /* identifier */ }';
|
|
416
|
+
return {
|
|
417
|
+
description: `Delete ${entity}`,
|
|
418
|
+
code: `const result = await callTool('${toolName}', ${paramsStr});
|
|
419
|
+
return result;`,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Generate a search example for a tool.
|
|
424
|
+
*/
|
|
425
|
+
function generateSearchExample(toolName, inputSchema) {
|
|
426
|
+
const entity = extractEntityName(toolName);
|
|
427
|
+
const queryParam = findQueryParameter(inputSchema);
|
|
428
|
+
if (queryParam) {
|
|
429
|
+
return {
|
|
430
|
+
description: `Search for ${entity}s`,
|
|
431
|
+
code: `const results = await callTool('${toolName}', { ${queryParam}: 'search term' });
|
|
432
|
+
return results.items || results;`,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
description: `Search for ${entity}s`,
|
|
437
|
+
code: `const results = await callTool('${toolName}', { query: 'search term' });
|
|
438
|
+
return results.items || results;`,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Find an ID-like parameter in the schema.
|
|
443
|
+
*/
|
|
444
|
+
function findIdParameter(schema) {
|
|
445
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
const props = Object.keys(schema.properties);
|
|
449
|
+
const required = new Set(schema.required || []);
|
|
450
|
+
// Prioritize required ID fields
|
|
451
|
+
const idPatterns = ['id', 'Id', 'ID', '_id', 'uuid', 'key'];
|
|
452
|
+
for (const pattern of idPatterns) {
|
|
453
|
+
const found = props.find((p) => (p === pattern || p.endsWith(pattern)) && required.has(p));
|
|
454
|
+
if (found)
|
|
455
|
+
return found;
|
|
456
|
+
}
|
|
457
|
+
// Fall back to any ID-like field
|
|
458
|
+
for (const pattern of idPatterns) {
|
|
459
|
+
const found = props.find((p) => p === pattern || p.endsWith(pattern));
|
|
460
|
+
if (found)
|
|
461
|
+
return found;
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Find a query-like parameter in the schema.
|
|
467
|
+
*/
|
|
468
|
+
function findQueryParameter(schema) {
|
|
469
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
const props = Object.keys(schema.properties);
|
|
473
|
+
const queryPatterns = ['query', 'search', 'q', 'term', 'keyword', 'filter'];
|
|
474
|
+
for (const pattern of queryPatterns) {
|
|
475
|
+
const found = props.find((p) => p.toLowerCase() === pattern || p.toLowerCase().includes(pattern));
|
|
476
|
+
if (found)
|
|
477
|
+
return found;
|
|
478
|
+
}
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Generate sample update fields (excluding ID-like fields).
|
|
483
|
+
*/
|
|
484
|
+
function generateUpdateFields(schema) {
|
|
485
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
const fields = {};
|
|
489
|
+
const idPatterns = ['id', 'Id', 'ID', '_id', 'uuid', 'key'];
|
|
490
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
491
|
+
if (typeof propSchema === 'boolean')
|
|
492
|
+
continue;
|
|
493
|
+
// Skip ID-like fields
|
|
494
|
+
const isIdField = idPatterns.some((p) => key === p || key.endsWith(p));
|
|
495
|
+
if (isIdField)
|
|
496
|
+
continue;
|
|
497
|
+
// Include a few non-ID fields for the update example
|
|
498
|
+
if (Object.keys(fields).length < 2) {
|
|
499
|
+
fields[key] = getSampleValue(propSchema, key);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return Object.keys(fields).length > 0 ? fields : null;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Smart example generator that uses intent detection.
|
|
506
|
+
* This is the main entry point for generating examples.
|
|
507
|
+
*/
|
|
508
|
+
function generateSmartExample(toolName, inputSchema, description) {
|
|
509
|
+
const intent = detectToolIntent(toolName, description);
|
|
510
|
+
switch (intent) {
|
|
511
|
+
case 'create':
|
|
512
|
+
return generateCreateExample(toolName, inputSchema);
|
|
513
|
+
case 'get':
|
|
514
|
+
return generateGetExample(toolName, inputSchema);
|
|
515
|
+
case 'list':
|
|
516
|
+
// For list tools, still use pagination example if available
|
|
517
|
+
return hasPaginationParams(inputSchema)
|
|
518
|
+
? generatePaginationExample(toolName)
|
|
519
|
+
: generateListExample(toolName, inputSchema);
|
|
520
|
+
case 'update':
|
|
521
|
+
return generateUpdateExample(toolName, inputSchema);
|
|
522
|
+
case 'delete':
|
|
523
|
+
return generateDeleteExample(toolName, inputSchema);
|
|
524
|
+
case 'search':
|
|
525
|
+
return generateSearchExample(toolName, inputSchema);
|
|
526
|
+
default:
|
|
527
|
+
// Fallback to basic example for unknown intents
|
|
528
|
+
return generateBasicExample(toolName, inputSchema);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
//# sourceMappingURL=describe.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.utils.js","sourceRoot":"","sources":["../../../../src/codecall/utils/describe.utils.ts"],"names":[],"mappings":";AAAA,0DAA0D;;AAuC1D,4CAwBC;AASD,sDAKC;AAqFD,kEAqCC;AAKD,oDASC;AA4ED,kDAOC;AAKD,0CAeC;AAKD,kDAcC;AAKD,8DAYC;AAKD,sDAMC;AAoBD,sDAUC;AAKD,gDAqBC;AAKD,kDAQC;AAKD,sDA0BC;AAKD,sDAoBC;AAKD,sDAiBC;AA+ED,oDA2BC;AAplBD;;;GAGG;AACH,MAAM,eAAe,GAA8D;IACjF,MAAM,EACJ,4HAA4H;IAC9H,MAAM,EAAE,sFAAsF;IAC9F,GAAG,EAAE,kEAAkE;IACvE,MAAM,EACJ,8GAA8G;IAChH,IAAI,EAAE,sEAAsE;IAC5E,MAAM,EAAE,wEAAwE;CACjF,CAAC;AAEF;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,QAAgB,EAAE,WAAoB;IACrE,wEAAwE;IACxE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,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K;YACR,OAAO,kBAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACnD,KAAK,MAAM;YACT,4DAA4D;YAC5D,OAAO,mBAAmB,CAAC,WAAW,CAAC;gBACrC,CAAC,CAAC,yBAAyB,CAAC,QAAQ,CAAC;gBACrC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACjD,KAAK,QAAQ;YACX,OAAO,qBAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACtD,KAAK,QAAQ;YACX,OAAO,qBAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACtD,KAAK,QAAQ;YACX,OAAO,qBAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACtD;YACE,gDAAgD;YAChD,OAAO,oBAAoB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;AACH,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/utils/describe.utils.ts\n\nimport type { JSONSchema } from 'zod/v4/core';\n\n/** JSON Schema type from Zod v4 */\ntype JsonSchema = JSONSchema.JSONSchema;\n\n/**\n * Tool example for describe output\n */\nexport interface ToolUsageExample {\n description: string;\n code: string;\n}\n\n/**\n * Detected intent of a tool based on its name and description.\n */\nexport type ToolIntent = 'create' | 'list' | 'get' | 'update' | 'delete' | 'search' | 'action' | 'unknown';\n\n/**\n * Patterns for detecting tool intent from the action verb.\n * These patterns use the same synonym groups as the search service.\n */\nconst INTENT_PATTERNS: Record<Exclude<ToolIntent, 'action' | 'unknown'>, RegExp> = {\n create:\n /^(create|add|new|insert|make|append|register|generate|produce|build|construct|provision|instantiate|define|compose|draft)/i,\n delete: /^(delete|remove|destroy|drop|erase|clear|purge|discard|eliminate|unbind|unregister)/i,\n get: /^(get|fetch|retrieve|read|obtain|load|pull|access|grab|receive)/i,\n update:\n /^(update|edit|modify|change|patch|set|alter|revise|adjust|amend|correct|fix|refresh|sync|upgrade|downgrade)/i,\n list: /^(list|all|index|enumerate|show|display|view|browse|scan|inventory)/i,\n search: /^(search|find|query|lookup|locate|discover|explore|seek|match|filter)/i,\n};\n\n/**\n * Detect the intent of a tool from its name.\n * Extracts the action verb from tool names like \"users:create\" or \"orders:list\".\n */\nexport function detectToolIntent(toolName: string, description?: string): ToolIntent {\n // Extract action verb from tool name (e.g., \"users:create\" -> \"create\")\n const parts = toolName.split(':');\n const actionPart = parts.length > 1 ? parts[parts.length - 1] : toolName;\n\n // Check each intent pattern\n for (const [intent, pattern] of Object.entries(INTENT_PATTERNS) as [ToolIntent, RegExp][]) {\n if (pattern.test(actionPart)) {\n return intent;\n }\n }\n\n // Fallback: check description for clues\n if (description) {\n const descLower = description.toLowerCase();\n if (/creates?\\s|adding\\s|inserts?/i.test(descLower)) return 'create';\n if (/deletes?\\s|removes?\\s|destroys?/i.test(descLower)) return 'delete';\n if (/gets?\\s|fetche?s?\\s|retrieves?/i.test(descLower)) return 'get';\n if (/updates?\\s|modif(?:y|ies)\\s|edits?/i.test(descLower)) return 'update';\n if (/lists?\\s|shows?\\s|displays?/i.test(descLower)) return 'list';\n if (/search(?:es)?\\s|find(?:s)?\\s|quer(?:y|ies)/i.test(descLower)) return 'search';\n }\n\n return 'unknown';\n}\n\n/**\n * Generate a TypeScript-like function signature from a JSON Schema.\n *\n * @example\n * Input: { type: 'object', properties: { id: { type: 'string' }, limit: { type: 'number' } }, required: ['id'] }\n * Output: \"(id: string, limit?: number) => unknown\"\n */\nexport function jsonSchemaToSignature(toolName: string, inputSchema?: JsonSchema, outputSchema?: JsonSchema): string {\n const inputPart = schemaToTypeString(inputSchema, 'input');\n const outputPart = schemaToTypeString(outputSchema, 'output');\n\n return `callTool('${toolName}', ${inputPart}) => Promise<${outputPart}>`;\n}\n\n/**\n * Convert JSON Schema to a TypeScript-like type string.\n */\nfunction schemaToTypeString(schema: JsonSchema | undefined | null, context: 'input' | 'output'): string {\n if (!schema) {\n return context === 'input' ? '{}' : 'unknown';\n }\n\n if (schema.type === 'object' && schema.properties) {\n const props: string[] = [];\n const required = new Set(schema.required || []);\n\n for (const [key, propSchema] of Object.entries(schema.properties)) {\n if (typeof propSchema === 'boolean') continue;\n\n const isRequired = required.has(key);\n const typeStr = getTypeString(propSchema);\n props.push(`${key}${isRequired ? '' : '?'}: ${typeStr}`);\n }\n\n if (props.length === 0) {\n return '{}';\n }\n\n return `{ ${props.join(', ')} }`;\n }\n\n return getTypeString(schema);\n}\n\n/**\n * Get a simple type string for a schema.\n */\nfunction getTypeString(schema: JsonSchema): string {\n if (schema.enum) {\n return schema.enum.map((v) => JSON.stringify(v)).join(' | ');\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n return schema.type.join(' | ');\n }\n\n switch (schema.type) {\n case 'string':\n return 'string';\n case 'number':\n case 'integer':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'null':\n return 'null';\n case 'array':\n if (schema.items && typeof schema.items !== 'boolean') {\n return `${getTypeString(schema.items as JsonSchema)}[]`;\n }\n return 'unknown[]';\n case 'object':\n if (schema.properties) {\n return schemaToTypeString(schema, 'input');\n }\n return 'Record<string, unknown>';\n default:\n return 'unknown';\n }\n }\n\n if (schema.oneOf || schema.anyOf) {\n // We've confirmed at least one is truthy, so use non-null assertion\n const options = (schema.oneOf ?? schema.anyOf)!;\n return options\n .filter((s): s is JsonSchema => typeof s !== 'boolean')\n .map((s) => getTypeString(s))\n .join(' | ');\n }\n\n return 'unknown';\n}\n\n/**\n * Generate a natural language summary of a schema.\n */\nexport function jsonSchemaToNaturalLanguage(\n schema: JsonSchema | undefined | null,\n direction: 'input' | 'output',\n): string {\n if (!schema) {\n return direction === 'input' ? 'No input parameters' : 'Returns unspecified data';\n }\n\n if (schema.description) {\n return schema.description;\n }\n\n if (schema.type === 'object' && schema.properties) {\n const required = new Set(schema.required || []);\n const props = Object.entries(schema.properties);\n\n if (props.length === 0) {\n return direction === 'input' ? 'No parameters required' : 'Returns an empty object';\n }\n\n const requiredProps = props.filter(([key]) => required.has(key));\n const optionalProps = props.filter(([key]) => !required.has(key));\n\n const parts: string[] = [];\n\n if (requiredProps.length > 0) {\n parts.push(`Required: ${requiredProps.map(([k]) => k).join(', ')}`);\n }\n\n if (optionalProps.length > 0) {\n parts.push(`Optional: ${optionalProps.map(([k]) => k).join(', ')}`);\n }\n\n return parts.join('. ');\n }\n\n return direction === 'input' ? `Takes a ${schema.type || 'value'}` : `Returns a ${schema.type || 'value'}`;\n}\n\n/**\n * Generate a basic usage example for a tool.\n */\nexport function generateBasicExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const params = generateSampleParams(inputSchema);\n const paramsStr = params ? JSON.stringify(params, null, 2) : '{}';\n\n return {\n description: `Basic usage of ${toolName}`,\n code: `const result = await callTool('${toolName}', ${paramsStr});\nreturn result;`,\n };\n}\n\n/**\n * Generate sample parameters from a schema.\n */\nfunction generateSampleParams(schema?: JsonSchema): Record<string, unknown> | null {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return null;\n }\n\n const params: Record<string, unknown> = {};\n const required = new Set(schema.required || []);\n\n for (const [key, propSchema] of Object.entries(schema.properties)) {\n if (typeof propSchema === 'boolean') continue;\n\n // Only include required params and a couple optional ones for example\n if (!required.has(key)) continue;\n\n params[key] = getSampleValue(propSchema, key);\n }\n\n return Object.keys(params).length > 0 ? params : null;\n}\n\n/**\n * Generate a sample value for a schema property.\n */\nfunction getSampleValue(schema: JsonSchema, key: string): unknown {\n if (schema.default !== undefined) {\n return schema.default;\n }\n\n if (schema.enum && schema.enum.length > 0) {\n return schema.enum[0];\n }\n\n if (schema.const !== undefined) {\n return schema.const;\n }\n\n const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;\n\n switch (type) {\n case 'string':\n // Generate contextual sample based on key name\n if (key.toLowerCase().includes('id')) return 'abc123';\n if (key.toLowerCase().includes('email')) return 'user@example.com';\n if (key.toLowerCase().includes('name')) return 'Example';\n if (key.toLowerCase().includes('url')) return 'https://example.com';\n return 'string';\n\n case 'number':\n case 'integer':\n if (key.toLowerCase().includes('limit')) return 10;\n if (key.toLowerCase().includes('offset')) return 0;\n if (key.toLowerCase().includes('page')) return 1;\n return 0;\n\n case 'boolean':\n return true;\n\n case 'array':\n return [];\n\n case 'object':\n return {};\n\n default:\n return null;\n }\n}\n\n/**\n * Check if a schema has pagination parameters.\n */\nexport function hasPaginationParams(schema?: JsonSchema): boolean {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return false;\n }\n\n const props = Object.keys(schema.properties);\n return props.some((p) => ['limit', 'offset', 'page', 'pageSize', 'cursor'].includes(p.toLowerCase()));\n}\n\n/**\n * Check if a schema has filter-like parameters.\n */\nexport function hasFilterParams(schema?: JsonSchema): boolean {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return false;\n }\n\n const props = Object.keys(schema.properties);\n return props.some(\n (p) =>\n p.toLowerCase().includes('filter') ||\n p.toLowerCase().includes('query') ||\n p.toLowerCase().includes('search') ||\n p.toLowerCase() === 'status' ||\n p.toLowerCase() === 'type' ||\n p.toLowerCase() === 'role',\n );\n}\n\n/**\n * Get filter-like property names from a schema.\n */\nexport function getFilterProperties(schema?: JsonSchema): string[] {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return [];\n }\n\n return Object.keys(schema.properties).filter(\n (p) =>\n p.toLowerCase().includes('filter') ||\n p.toLowerCase().includes('query') ||\n p.toLowerCase().includes('search') ||\n p.toLowerCase() === 'status' ||\n p.toLowerCase() === 'type' ||\n p.toLowerCase() === 'role',\n );\n}\n\n/**\n * Generate a pagination example for a tool.\n */\nexport function generatePaginationExample(toolName: string): ToolUsageExample {\n return {\n description: `Pagination example for ${toolName}`,\n code: `// Fetch first page\nconst page1 = await callTool('${toolName}', { limit: 10, offset: 0 });\n\n// Fetch second page\nconst page2 = await callTool('${toolName}', { limit: 10, offset: 10 });\n\n// Combine results\nreturn [...page1.items, ...page2.items];`,\n };\n}\n\n/**\n * Generate a filter example for a tool.\n */\nexport function generateFilterExample(toolName: string, filterProp: string): ToolUsageExample {\n return {\n description: `Filter by ${filterProp}`,\n code: `const filtered = await callTool('${toolName}', { ${filterProp}: 'value' });\nreturn filtered.items || filtered;`,\n };\n}\n\n// ==========================================\n// Intent-Specific Example Generators\n// ==========================================\n\n/**\n * Extract entity name from tool name (e.g., \"users:create\" -> \"user\")\n */\nfunction extractEntityName(toolName: string): string {\n const parts = toolName.split(':');\n const entity = parts.length > 1 ? parts[0] : toolName;\n // Singularize simple plurals\n return entity.endsWith('s') && !entity.endsWith('ss') ? entity.slice(0, -1) : entity;\n}\n\n/**\n * Generate a create example for a tool.\n * Shows required parameters with contextual sample values.\n */\nexport function generateCreateExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const entity = extractEntityName(toolName);\n const params = generateSampleParams(inputSchema);\n const paramsStr = params ? JSON.stringify(params, null, 2) : '{ /* required fields */ }';\n\n return {\n description: `Create a new ${entity}`,\n code: `const result = await callTool('${toolName}', ${paramsStr});\nreturn result;`,\n };\n}\n\n/**\n * Generate a get (retrieve single item) example for a tool.\n */\nexport function generateGetExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const entity = extractEntityName(toolName);\n const idParam = findIdParameter(inputSchema);\n\n if (idParam) {\n return {\n description: `Get ${entity} by ${idParam}`,\n code: `const ${entity} = await callTool('${toolName}', { ${idParam}: 'abc123' });\nreturn ${entity};`,\n };\n }\n\n // Fallback to basic example if no ID parameter found\n const params = generateSampleParams(inputSchema);\n const paramsStr = params ? JSON.stringify(params, null, 2) : '{}';\n\n return {\n description: `Get ${entity} details`,\n code: `const ${entity} = await callTool('${toolName}', ${paramsStr});\nreturn ${entity};`,\n };\n}\n\n/**\n * Generate a list example for a tool.\n */\nexport function generateListExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const entity = extractEntityName(toolName);\n\n return {\n description: `List all ${entity}s`,\n code: `const result = await callTool('${toolName}', {});\nreturn result.items || result;`,\n };\n}\n\n/**\n * Generate an update example for a tool.\n */\nexport function generateUpdateExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const entity = extractEntityName(toolName);\n const idParam = findIdParameter(inputSchema);\n\n // Generate sample update fields (excluding ID fields)\n const updateFields = generateUpdateFields(inputSchema);\n const fieldsStr = updateFields\n ? JSON.stringify(updateFields, null, 2).replace(/\\n/g, '\\n ')\n : '{ /* fields to update */ }';\n\n if (idParam) {\n return {\n description: `Update ${entity} by ${idParam}`,\n code: `const updated = await callTool('${toolName}', {\n ${idParam}: 'abc123',\n ...${fieldsStr}\n});\nreturn updated;`,\n };\n }\n\n return {\n description: `Update ${entity}`,\n code: `const updated = await callTool('${toolName}', ${fieldsStr});\nreturn updated;`,\n };\n}\n\n/**\n * Generate a delete example for a tool.\n */\nexport function generateDeleteExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const entity = extractEntityName(toolName);\n const idParam = findIdParameter(inputSchema);\n\n if (idParam) {\n return {\n description: `Delete ${entity} by ${idParam}`,\n code: `const result = await callTool('${toolName}', { ${idParam}: 'abc123' });\nreturn result;`,\n };\n }\n\n const params = generateSampleParams(inputSchema);\n const paramsStr = params ? JSON.stringify(params, null, 2) : '{ /* identifier */ }';\n\n return {\n description: `Delete ${entity}`,\n code: `const result = await callTool('${toolName}', ${paramsStr});\nreturn result;`,\n };\n}\n\n/**\n * Generate a search example for a tool.\n */\nexport function generateSearchExample(toolName: string, inputSchema?: JsonSchema): ToolUsageExample {\n const entity = extractEntityName(toolName);\n const queryParam = findQueryParameter(inputSchema);\n\n if (queryParam) {\n return {\n description: `Search for ${entity}s`,\n code: `const results = await callTool('${toolName}', { ${queryParam}: 'search term' });\nreturn results.items || results;`,\n };\n }\n\n return {\n description: `Search for ${entity}s`,\n code: `const results = await callTool('${toolName}', { query: 'search term' });\nreturn results.items || results;`,\n };\n}\n\n/**\n * Find an ID-like parameter in the schema.\n */\nfunction findIdParameter(schema?: JsonSchema): string | null {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return null;\n }\n\n const props = Object.keys(schema.properties);\n const required = new Set(schema.required || []);\n\n // Prioritize required ID fields\n const idPatterns = ['id', 'Id', 'ID', '_id', 'uuid', 'key'];\n for (const pattern of idPatterns) {\n const found = props.find((p) => (p === pattern || p.endsWith(pattern)) && required.has(p));\n if (found) return found;\n }\n\n // Fall back to any ID-like field\n for (const pattern of idPatterns) {\n const found = props.find((p) => p === pattern || p.endsWith(pattern));\n if (found) return found;\n }\n\n return null;\n}\n\n/**\n * Find a query-like parameter in the schema.\n */\nfunction findQueryParameter(schema?: JsonSchema): string | null {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return null;\n }\n\n const props = Object.keys(schema.properties);\n const queryPatterns = ['query', 'search', 'q', 'term', 'keyword', 'filter'];\n\n for (const pattern of queryPatterns) {\n const found = props.find((p) => p.toLowerCase() === pattern || p.toLowerCase().includes(pattern));\n if (found) return found;\n }\n\n return null;\n}\n\n/**\n * Generate sample update fields (excluding ID-like fields).\n */\nfunction generateUpdateFields(schema?: JsonSchema): Record<string, unknown> | null {\n if (!schema || schema.type !== 'object' || !schema.properties) {\n return null;\n }\n\n const fields: Record<string, unknown> = {};\n const idPatterns = ['id', 'Id', 'ID', '_id', 'uuid', 'key'];\n\n for (const [key, propSchema] of Object.entries(schema.properties)) {\n if (typeof propSchema === 'boolean') continue;\n\n // Skip ID-like fields\n const isIdField = idPatterns.some((p) => key === p || key.endsWith(p));\n if (isIdField) continue;\n\n // Include a few non-ID fields for the update example\n if (Object.keys(fields).length < 2) {\n fields[key] = getSampleValue(propSchema, key);\n }\n }\n\n return Object.keys(fields).length > 0 ? fields : null;\n}\n\n/**\n * Smart example generator that uses intent detection.\n * This is the main entry point for generating examples.\n */\nexport function generateSmartExample(\n toolName: string,\n inputSchema?: JsonSchema,\n description?: string,\n): ToolUsageExample {\n const intent = detectToolIntent(toolName, description);\n\n switch (intent) {\n case 'create':\n return generateCreateExample(toolName, inputSchema);\n case 'get':\n return generateGetExample(toolName, inputSchema);\n case 'list':\n // For list tools, still use pagination example if available\n return hasPaginationParams(inputSchema)\n ? generatePaginationExample(toolName)\n : generateListExample(toolName, inputSchema);\n case 'update':\n return generateUpdateExample(toolName, inputSchema);\n case 'delete':\n return generateDeleteExample(toolName, inputSchema);\n case 'search':\n return generateSearchExample(toolName, inputSchema);\n default:\n // Fallback to basic example for unknown intents\n return generateBasicExample(toolName, inputSchema);\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: libs/plugins/src/codecall/utils/index.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./describe.utils"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./mcp-result"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codecall/utils/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAEjD,2DAAiC;AACjC,uDAA6B","sourcesContent":["// file: libs/plugins/src/codecall/utils/index.ts\n\nexport * from './describe.utils';\nexport * from './mcp-result';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the actual result from a CallToolResult.
|
|
4
|
+
* MCP returns results wrapped in content array format.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractResultFromCallToolResult(mcpResult: CallToolResult): unknown;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: libs/plugins/src/codecall/utils/mcp-result.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.extractResultFromCallToolResult = extractResultFromCallToolResult;
|
|
5
|
+
/**
|
|
6
|
+
* Extract the actual result from a CallToolResult.
|
|
7
|
+
* MCP returns results wrapped in content array format.
|
|
8
|
+
*/
|
|
9
|
+
function extractResultFromCallToolResult(mcpResult) {
|
|
10
|
+
// MCP CallToolResult has { content: [...], isError?: boolean }
|
|
11
|
+
if (mcpResult.isError) {
|
|
12
|
+
// If it's an error, extract the error message from content
|
|
13
|
+
const errorContent = mcpResult.content?.[0];
|
|
14
|
+
if (errorContent && 'text' in errorContent) {
|
|
15
|
+
throw new Error(errorContent.text);
|
|
16
|
+
}
|
|
17
|
+
throw new Error('Tool execution failed');
|
|
18
|
+
}
|
|
19
|
+
// For successful results, try to extract the actual data
|
|
20
|
+
const content = mcpResult.content;
|
|
21
|
+
if (!content || content.length === 0) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
// If there's a single text content, try to parse as JSON
|
|
25
|
+
if (content.length === 1 && content[0].type === 'text') {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(content[0].text);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return content[0].text;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Return the raw content for complex results
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=mcp-result.js.map
|