refactor: move schema updates to executor

- Executor now updates TPM.js database directly when loading tools
- Update /api/tools/update-schema to use packageName+exportName lookup
- Remove schema update logic from HLLM proxy (no longer needed)
This commit is contained in:
Ajax Davis 2025-12-15 13:07:42 +10:00
parent 3f54f16573
commit feeb3cf3e8
2 changed files with 110 additions and 18 deletions

View file

@ -48,6 +48,45 @@ async function reportToolHealth(
}
}
/**
* Update tool schema in TPM.js database
* Non-blocking - fires and forgets to keep schemas up to date
*/
async function updateToolSchema(
packageName: string,
exportName: string,
description: string,
// biome-ignore lint/suspicious/noExplicitAny: JSON Schema can have any structure
inputSchema: any
): Promise<void> {
try {
const response = await fetch(`${TPMJS_API_URL}/api/tools/update-schema`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
packageName,
exportName,
description,
inputSchema,
}),
});
if (response.ok) {
const data = await response.json();
console.log(
`📋 Schema updated for ${packageName}/${exportName}:`,
data.updated ? 'UPDATED' : 'NO CHANGE'
);
} else {
const errorText = await response.text();
console.warn(`⚠️ Failed to update schema: ${response.status}`, errorText);
}
} catch (err) {
// Non-blocking - just log
console.error('❌ Failed to update tool schema:', err);
}
}
/**
* Sanitize JSON Schema to fix common issues
* - Replaces invalid type "None" with "object"
@ -354,6 +393,13 @@ async function loadAndDescribe(req: Request): Promise<Response> {
// Sanitize schema - fix common issues with invalid schemas
const sanitizedSchema = sanitizeJsonSchema(rawJsonSchema);
// Update TPM.js database with the schema (async, non-blocking)
updateToolSchema(packageName, exportName, toolModule.description, sanitizedSchema).catch(
(err) => {
console.warn('⚠️ Failed to update schema in database:', err);
}
);
return Response.json({
success: true,
tool: {