This repository has been archived on 2026-03-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw-extensions/wecom/node_modules/@mariozechner/pi-ai/dist/api-registry.js
T

44 lines
1.4 KiB
JavaScript

const apiProviderRegistry = new Map();
function wrapStream(api, stream) {
return (model, context, options) => {
if (model.api !== api) {
throw new Error(`Mismatched api: ${model.api} expected ${api}`);
}
return stream(model, context, options);
};
}
function wrapStreamSimple(api, streamSimple) {
return (model, context, options) => {
if (model.api !== api) {
throw new Error(`Mismatched api: ${model.api} expected ${api}`);
}
return streamSimple(model, context, options);
};
}
export function registerApiProvider(provider, sourceId) {
apiProviderRegistry.set(provider.api, {
provider: {
api: provider.api,
stream: wrapStream(provider.api, provider.stream),
streamSimple: wrapStreamSimple(provider.api, provider.streamSimple),
},
sourceId,
});
}
export function getApiProvider(api) {
return apiProviderRegistry.get(api)?.provider;
}
export function getApiProviders() {
return Array.from(apiProviderRegistry.values(), (entry) => entry.provider);
}
export function unregisterApiProviders(sourceId) {
for (const [api, entry] of apiProviderRegistry.entries()) {
if (entry.sourceId === sourceId) {
apiProviderRegistry.delete(api);
}
}
}
export function clearApiProviders() {
apiProviderRegistry.clear();
}
//# sourceMappingURL=api-registry.js.map