{"version":3,"file":"models-store.d.ts","sourceRoot":"","sources":["../../src/core/models-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAM3E,qBAAa,8BAA+B,YAAW,WAAW;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAEzD,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAEpE;IAEK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtE;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9C;CACD;AAED,8EAA8E;AAC9E,qBAAa,eAAgB,YAAW,WAAW;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,YAAY,IAAI,GAAE,MAAiD,EAElE;IAED,OAAO,CAAC,KAAK;IAIP,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAIpE;IAEK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMtE;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM9C;CACD","sourcesContent":["import { join } from \"node:path\";\nimport type { ModelsStore, ModelsStoreEntry } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { type AuthStorageBackend, FileAuthStorageBackend } from \"./auth-storage.ts\";\n\ntype StoredModels = Record<string, ModelsStoreEntry>;\n\nexport class InMemoryCodingAgentModelsStore implements ModelsStore {\n\tprivate readonly entries = new Map<string, ModelsStoreEntry>();\n\n\tasync read(providerId: string): Promise<ModelsStoreEntry | undefined> {\n\t\treturn this.entries.get(providerId);\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry): Promise<void> {\n\t\tthis.entries.set(providerId, entry);\n\t}\n\n\tasync delete(providerId: string): Promise<void> {\n\t\tthis.entries.delete(providerId);\n\t}\n}\n\n/** Locked JSON-backed storage for dynamically refreshed provider catalogs. */\nexport class FileModelsStore implements ModelsStore {\n\tprivate readonly storage: AuthStorageBackend;\n\n\tconstructor(path: string = join(getAgentDir(), \"models-store.json\")) {\n\t\tthis.storage = new FileAuthStorageBackend(path);\n\t}\n\n\tprivate parse(content: string | undefined): StoredModels {\n\t\treturn content ? (JSON.parse(content) as StoredModels) : {};\n\t}\n\n\tasync read(providerId: string): Promise<ModelsStoreEntry | undefined> {\n\t\treturn this.storage.withLock((content) => ({\n\t\t\tresult: structuredClone(this.parse(content)[providerId]),\n\t\t}));\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry): Promise<void> {\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst current = this.parse(content);\n\t\t\tcurrent[providerId] = structuredClone(entry);\n\t\t\treturn { result: undefined, next: JSON.stringify(current, null, 2) };\n\t\t});\n\t}\n\n\tasync delete(providerId: string): Promise<void> {\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst current = this.parse(content);\n\t\t\tdelete current[providerId];\n\t\t\treturn { result: undefined, next: JSON.stringify(current, null, 2) };\n\t\t});\n\t}\n}\n"]}