fix(pi): serialize managed provider catalog writes
This commit is contained in:
@@ -22,6 +22,7 @@ import { getImportedModelProfile } from '../../../shared/imported-model-profile'
|
||||
const PI_ENV_PREFIX = 'MAKELORE_PI';
|
||||
const WORKS_SQUARE_AI_GATEWAY_CREDENTIAL_MODE = 'works_square_ai_gateway';
|
||||
const WORKS_SQUARE_AI_GATEWAY_PROXY_CREDENTIAL_MODE = 'works_square_ai_gateway_proxy';
|
||||
const providerCatalogWriteTails = new Map<string, Promise<void>>();
|
||||
|
||||
export const PI_PROVIDER_APIS = [
|
||||
'openai-completions',
|
||||
@@ -469,7 +470,18 @@ export async function writePiProviderCatalog(
|
||||
modelRef?: ProductModelRef,
|
||||
): Promise<void> {
|
||||
if (modelRef) selectPiProviderModel(catalog, modelRef);
|
||||
await atomicWriteJson(filePath, catalog.modelsFile);
|
||||
const previous = providerCatalogWriteTails.get(filePath) ?? Promise.resolve();
|
||||
const write = previous
|
||||
.catch(() => undefined)
|
||||
.then(async () => await atomicWriteJson(filePath, catalog.modelsFile));
|
||||
providerCatalogWriteTails.set(filePath, write);
|
||||
try {
|
||||
await write;
|
||||
} finally {
|
||||
if (providerCatalogWriteTails.get(filePath) === write) {
|
||||
providerCatalogWriteTails.delete(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function replaceCredentialEnvReferences(value: string, credential: string | null): string {
|
||||
|
||||
Reference in New Issue
Block a user