triage remaining tracker fixes
This commit is contained in:
1
scripts/lib/pi-google-legacy-schema-patch.d.mts
Normal file
1
scripts/lib/pi-google-legacy-schema-patch.d.mts
Normal file
@@ -0,0 +1 @@
|
||||
export function patchPiGoogleLegacySchemaSource(source: string): string;
|
||||
44
scripts/lib/pi-google-legacy-schema-patch.mjs
Normal file
44
scripts/lib/pi-google-legacy-schema-patch.mjs
Normal 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)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user