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)}`;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { FEYNMAN_LOGO_HTML } from "../logo.mjs";
|
||||
import { patchPiExtensionLoaderSource } from "./lib/pi-extension-loader-patch.mjs";
|
||||
import { patchPiGoogleLegacySchemaSource } from "./lib/pi-google-legacy-schema-patch.mjs";
|
||||
import { PI_WEB_ACCESS_PATCH_TARGETS, patchPiWebAccessSource } from "./lib/pi-web-access-patch.mjs";
|
||||
import { PI_SUBAGENTS_PATCH_TARGETS, patchPiSubagentsSource } from "./lib/pi-subagents-patch.mjs";
|
||||
|
||||
@@ -616,6 +617,7 @@ if (existsSync(sessionSearchIndexerPath)) {
|
||||
}
|
||||
|
||||
const oauthPagePath = piAiRoot ? resolve(piAiRoot, "dist", "utils", "oauth", "oauth-page.js") : null;
|
||||
const googleSharedPath = piAiRoot ? resolve(piAiRoot, "dist", "providers", "google-shared.js") : null;
|
||||
|
||||
if (oauthPagePath && existsSync(oauthPagePath)) {
|
||||
let source = readFileSync(oauthPagePath, "utf8");
|
||||
@@ -628,6 +630,14 @@ if (oauthPagePath && existsSync(oauthPagePath)) {
|
||||
if (changed) writeFileSync(oauthPagePath, source, "utf8");
|
||||
}
|
||||
|
||||
if (googleSharedPath && existsSync(googleSharedPath)) {
|
||||
const source = readFileSync(googleSharedPath, "utf8");
|
||||
const patched = patchPiGoogleLegacySchemaSource(source);
|
||||
if (patched !== source) {
|
||||
writeFileSync(googleSharedPath, patched, "utf8");
|
||||
}
|
||||
}
|
||||
|
||||
const alphaHubAuthPath = findPackageRoot("@companion-ai/alpha-hub")
|
||||
? resolve(findPackageRoot("@companion-ai/alpha-hub"), "src", "lib", "auth.js")
|
||||
: null;
|
||||
|
||||
Reference in New Issue
Block a user