@compilr-dev/sdk 0.1.14 → 0.1.15
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.
|
@@ -27,7 +27,7 @@ export interface MetaToolStats {
|
|
|
27
27
|
export interface MetaTools {
|
|
28
28
|
/** Lists available tools by category */
|
|
29
29
|
listToolsTool: Tool;
|
|
30
|
-
/** Returns
|
|
30
|
+
/** Returns compact parameter info for a tool */
|
|
31
31
|
getToolInfoTool: Tool;
|
|
32
32
|
/** Executes any registered tool by name */
|
|
33
33
|
useToolTool: Tool;
|
|
@@ -91,4 +91,4 @@ export declare class MetaToolsRegistry {
|
|
|
91
91
|
* Create the three meta-tools + fallback handler, all bound to a registry instance.
|
|
92
92
|
*/
|
|
93
93
|
export declare function createMetaTools(registry: MetaToolsRegistry): MetaTools;
|
|
94
|
-
export declare const META_TOOLS_SYSTEM_PROMPT_PREFIX = "\n## Tool Index (Specialized Tools)\n\nThese tools are called **exactly like direct tools** \u2014 just use the tool name with parameters. No special syntax or wrapper needed. The system routes them automatically.\n\n**IMPORTANT \u2014 These are CLI system tools, NOT your project's backend. Never use localhost/curl to access them.**\n\n**Parameter Rules:**\n- For **zero-parameter calls**: call the tool directly (e.g., `workitem_query()`, `git_status()`).\n- For **calls WITH parameters**: you MUST call `get_tool_info(\"tool_name\")` first to get
|
|
94
|
+
export declare const META_TOOLS_SYSTEM_PROMPT_PREFIX = "\n## Tool Index (Specialized Tools)\n\nThese tools are called **exactly like direct tools** \u2014 just use the tool name with parameters. No special syntax or wrapper needed. The system routes them automatically.\n\n**IMPORTANT \u2014 These are CLI system tools, NOT your project's backend. Never use localhost/curl to access them.**\n\n**Parameter Rules:**\n- For **zero-parameter calls**: call the tool directly (e.g., `workitem_query()`, `git_status()`).\n- For **calls WITH parameters**: you MUST call `get_tool_info(\"tool_name\")` first to get parameter details. The signatures below are summaries only \u2014 do NOT guess parameter structure from them.\n- After a failed tool call, always call `get_tool_info()` before retrying.\n\n";
|
|
@@ -187,7 +187,7 @@ export function createMetaTools(registry) {
|
|
|
187
187
|
// -------------------------------------------------------------------------
|
|
188
188
|
const getToolInfoTool = defineTool({
|
|
189
189
|
name: 'get_tool_info',
|
|
190
|
-
description: "Get
|
|
190
|
+
description: "Get a tool's parameter signature and descriptions. " +
|
|
191
191
|
'MUST be called before passing any parameters to a Tool Index tool. ' +
|
|
192
192
|
'Zero-parameter calls do not need this.',
|
|
193
193
|
inputSchema: {
|
|
@@ -211,11 +211,7 @@ export function createMetaTools(registry) {
|
|
|
211
211
|
`Available tools include: ${availableTools.join(', ')}... ` +
|
|
212
212
|
`Check the Tool Index for the full list.`));
|
|
213
213
|
}
|
|
214
|
-
return Promise.resolve(createSuccessResult(
|
|
215
|
-
name: tool.definition.name,
|
|
216
|
-
description: tool.definition.description,
|
|
217
|
-
parameters: tool.definition.inputSchema,
|
|
218
|
-
}));
|
|
214
|
+
return Promise.resolve(createSuccessResult(buildCompactSchema(tool)));
|
|
219
215
|
},
|
|
220
216
|
});
|
|
221
217
|
// -------------------------------------------------------------------------
|
|
@@ -267,9 +263,8 @@ export function createMetaTools(registry) {
|
|
|
267
263
|
// 2. Validate args
|
|
268
264
|
const validationError = registry.validateArgs(tool_name, args);
|
|
269
265
|
if (validationError) {
|
|
270
|
-
return createErrorResult(`Invalid arguments for '${tool_name}': ${validationError}
|
|
271
|
-
`Expected
|
|
272
|
-
`Hint: Call get_tool_info("${tool_name}") to see full parameter details.`);
|
|
266
|
+
return createErrorResult(`Invalid arguments for '${tool_name}': ${validationError}.\n` +
|
|
267
|
+
`Expected:\n${buildCompactSchema(tool)}`);
|
|
273
268
|
}
|
|
274
269
|
// 3. Execute the tool
|
|
275
270
|
try {
|
|
@@ -347,7 +342,7 @@ These tools are called **exactly like direct tools** — just use the tool name
|
|
|
347
342
|
|
|
348
343
|
**Parameter Rules:**
|
|
349
344
|
- For **zero-parameter calls**: call the tool directly (e.g., \`workitem_query()\`, \`git_status()\`).
|
|
350
|
-
- For **calls WITH parameters**: you MUST call \`get_tool_info("tool_name")\` first to get
|
|
345
|
+
- For **calls WITH parameters**: you MUST call \`get_tool_info("tool_name")\` first to get parameter details. The signatures below are summaries only — do NOT guess parameter structure from them.
|
|
351
346
|
- After a failed tool call, always call \`get_tool_info()\` before retrying.
|
|
352
347
|
|
|
353
348
|
`;
|
|
@@ -372,6 +367,22 @@ function getCategoryName(prefix) {
|
|
|
372
367
|
};
|
|
373
368
|
return categoryMap[prefix] ?? 'Other';
|
|
374
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Resolve a compact type string from a JSON Schema property.
|
|
372
|
+
*/
|
|
373
|
+
function resolveCompactType(prop) {
|
|
374
|
+
const type = typeof prop.type === 'string' ? prop.type : 'any';
|
|
375
|
+
if (type === 'array') {
|
|
376
|
+
const items = prop.items;
|
|
377
|
+
const itemType = typeof items?.type === 'string' ? items.type : 'any';
|
|
378
|
+
return `${itemType}[]`;
|
|
379
|
+
}
|
|
380
|
+
if (type === 'boolean')
|
|
381
|
+
return 'bool';
|
|
382
|
+
if (type === 'integer')
|
|
383
|
+
return 'int';
|
|
384
|
+
return type;
|
|
385
|
+
}
|
|
375
386
|
/**
|
|
376
387
|
* Build a concise signature for a tool.
|
|
377
388
|
* e.g., "git_commit(message: string, files?: string[]) - Create a commit"
|
|
@@ -383,7 +394,7 @@ function buildToolSignature(tool) {
|
|
|
383
394
|
const required = new Set(schema.required ?? []);
|
|
384
395
|
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
385
396
|
const isRequired = required.has(name);
|
|
386
|
-
const type = prop
|
|
397
|
+
const type = resolveCompactType(prop);
|
|
387
398
|
params.push(isRequired ? `${name}: ${type}` : `${name}?: ${type}`);
|
|
388
399
|
}
|
|
389
400
|
}
|
|
@@ -391,6 +402,51 @@ function buildToolSignature(tool) {
|
|
|
391
402
|
const desc = tool.definition.description.split('.')[0]; // First sentence
|
|
392
403
|
return `${tool.definition.name}(${paramsStr}) - ${desc}`;
|
|
393
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Build a compact schema string for get_tool_info responses.
|
|
407
|
+
* Includes signature, full description, and per-parameter details.
|
|
408
|
+
*
|
|
409
|
+
* Example output:
|
|
410
|
+
* git_commit(message: string, files?: string[], amend?: bool)
|
|
411
|
+
* Create a git commit with the specified message.
|
|
412
|
+
* - message: The commit message (required)
|
|
413
|
+
* - files: Files to stage before committing
|
|
414
|
+
* - amend: Amend the last commit instead of creating new
|
|
415
|
+
*/
|
|
416
|
+
function buildCompactSchema(tool) {
|
|
417
|
+
const schema = tool.definition.inputSchema;
|
|
418
|
+
const required = new Set(schema.required ?? []);
|
|
419
|
+
const params = [];
|
|
420
|
+
const paramDetails = [];
|
|
421
|
+
if (schema.properties) {
|
|
422
|
+
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
423
|
+
const isRequired = required.has(name);
|
|
424
|
+
const type = resolveCompactType(prop);
|
|
425
|
+
params.push(isRequired ? `${name}: ${type}` : `${name}?: ${type}`);
|
|
426
|
+
// Build parameter detail line
|
|
427
|
+
const desc = prop.description;
|
|
428
|
+
const enumValues = prop.enum;
|
|
429
|
+
let detail = `- ${name}`;
|
|
430
|
+
if (desc) {
|
|
431
|
+
detail += `: ${desc}`;
|
|
432
|
+
}
|
|
433
|
+
if (enumValues) {
|
|
434
|
+
detail += ` (${enumValues.map((v) => `"${v}"`).join('|')})`;
|
|
435
|
+
}
|
|
436
|
+
if (isRequired) {
|
|
437
|
+
detail += ' (required)';
|
|
438
|
+
}
|
|
439
|
+
paramDetails.push(detail);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const paramsStr = params.join(', ');
|
|
443
|
+
const lines = [`${tool.definition.name}(${paramsStr})`];
|
|
444
|
+
lines.push(` ${tool.definition.description}`);
|
|
445
|
+
for (const detail of paramDetails) {
|
|
446
|
+
lines.push(` ${detail}`);
|
|
447
|
+
}
|
|
448
|
+
return lines.join('\n');
|
|
449
|
+
}
|
|
394
450
|
/**
|
|
395
451
|
* Format AJV validation errors into a readable string.
|
|
396
452
|
*/
|