UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.07 kB
import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{o as providerModelEntries,s as resolveConfiguredModelCatalogOwnership}from"./legacy-config-migrations.runtime.models.catalog-gvwJ8aO8.mjs";import path from"node:path";import{isDeepStrictEqual}from"node:util"; //!src/commands/doctor/shared/model-metadata-corruption-repair.ts const GENERATED_MODEL_FALLBACK={cost:{input:0,output:0,cacheRead:0,cacheWrite:0},input:[`text`],maxTokens:8192,reasoning:false};const GENERATED_MODEL_FIELDS=[`cost`,`input`,`maxTokens`,`reasoning`];function hasGeneratedFallbackFingerprint(e){return GENERATED_MODEL_FIELDS.every(t=>Object.hasOwn(e,t)&&isDeepStrictEqual(e[t],GENERATED_MODEL_FALLBACK[t]))}function isHistoricalMaterializingWriter(e){const t=e.argv.some((t,n)=>t===`update`&&e.argv[n+1]===`finalize`);const n=e.origin===`doctor`&&e.argv.includes(`doctor`)&&(e.argv.includes(`--fix`)||e.argv.includes(`--yes`));return t||n}function hasAuditProvenance(e){const t=path.resolve(e.configPath);return e.auditRecords.some(n=>n.event===`config.write`&&(n.result===`rename`||n.result===`copy-fallback`)&&path.resolve(n.configPath)===t&&n.nextHash===e.currentHash&&isHistoricalMaterializingWriter(n)&&GENERATED_MODEL_FIELDS.every(t=>n.changedPaths?.some(n=>n===`${e.modelPath}.${t}`||n.startsWith(`${e.modelPath}.${t}.`))))}function repairGeneratedModelMetadataCorruption(e){let t;let n;const r=[];const i=[];for(const{providerId:a,provider:o,modelIndex:s,model:c}of providerModelEntries(e.config.models?.providers)){const l=typeof c.id===`string`?c.id:``;if(!l||!hasGeneratedFallbackFingerprint(c))continue;const u=asNullableRecord(asNullableRecord(asNullableRecord(e.authoredRoot)?.models)?.providers)?.[a];const d=asNullableRecord(u)?.models;const f=Array.isArray(d)?asNullableRecord(d[s]):void 0;const p=f?.id===l?f:void 0;const m=resolveConfiguredModelCatalogOwnership({providerId:a,provider:o,model:c});if(!m||GENERATED_MODEL_FIELDS.every(e=>isDeepStrictEqual(m.catalogRow[e],GENERATED_MODEL_FALLBACK[e])))continue;const h=`models.providers.${a}.models[${s}]`;if(!m.ownsRoute){i.push(`${h} matches the historical generated model-metadata fingerprint, but its configured API route is not owned by the shipped provider catalog. It was left unchanged.`);continue}if(!(p&&hasGeneratedFallbackFingerprint(p)&&e.currentHash&&hasAuditProvenance({auditRecords:n??=e.loadAuditRecords(),configPath:e.configPath,currentHash:e.currentHash,modelPath:h}))){i.push(`${h} matches the historical generated model-metadata fingerprint, but Doctor could not prove the responsible config write. It was left unchanged. If the provider catalog should own these capabilities, remove cost, input, maxTokens, and reasoning from this model entry.`);continue}const g=(t??=structuredClone(e.config)).models.providers[a].models[s];for(const e of GENERATED_MODEL_FIELDS)Reflect.deleteProperty(g,e);r.push(`Removed audit-proven generated model metadata from ${h}: cost, input, maxTokens, reasoning.`)}return{config:t??e.config,changes:r,warnings:i}}export{repairGeneratedModelMetadataCorruption};