triage remaining tracker fixes

This commit is contained in:
Advait Paliwal
2026-04-09 10:34:29 -07:00
parent 96234425ba
commit bfa538fa00
9 changed files with 157 additions and 1 deletions

View File

@@ -0,0 +1 @@
export function patchPiGoogleLegacySchemaSource(source: string): string;

View File

@@ -0,0 +1,44 @@
const HELPER = [
"function normalizeLegacyToolSchema(schema) {",
" if (Array.isArray(schema)) return schema.map((item) => normalizeLegacyToolSchema(item));",
' if (!schema || typeof schema !== "object") return schema;',
" const normalized = {};",
" for (const [key, value] of Object.entries(schema)) {",
' if (key === "const") {',
" normalized.enum = [value];",
" continue;",
" }",
" normalized[key] = normalizeLegacyToolSchema(value);",
" }",
" return normalized;",
"}",
].join("\n");
const ORIGINAL =
' ...(useParameters ? { parameters: tool.parameters } : { parametersJsonSchema: tool.parameters }),';
const PATCHED = [
" ...(useParameters",
" ? { parameters: normalizeLegacyToolSchema(tool.parameters) }",
" : { parametersJsonSchema: tool.parameters }),",
].join("\n");
export function patchPiGoogleLegacySchemaSource(source) {
let patched = source;
if (patched.includes("function normalizeLegacyToolSchema(schema) {")) {
return patched;
}
if (!patched.includes(ORIGINAL)) {
return source;
}
patched = patched.replace(ORIGINAL, PATCHED);
const marker = "export function convertTools(tools, useParameters = false) {";
const markerIndex = patched.indexOf(marker);
if (markerIndex === -1) {
return source;
}
return `${patched.slice(0, markerIndex)}${HELPER}\n\n${patched.slice(markerIndex)}`;
}