Files
openclaw/src/agents/custom-api-registry.ts
Vincent Koc 7e946b3c6c fix(ollama): register custom api for compaction and summarization (#39332)
* fix(agents): add custom api registry helper

* fix(ollama): register native api for embedded runs

* fix(ollama): register custom api before compaction

* fix(tts): register custom api before summarization

* changelog: note ollama compaction registration fix

* fix(ollama): honor resolved base urls in custom api paths
2026-03-07 17:40:34 -08:00

36 lines
992 B
TypeScript

import type { StreamFn } from "@mariozechner/pi-agent-core";
import {
getApiProvider,
registerApiProvider,
type Api,
type StreamOptions,
} from "@mariozechner/pi-ai";
const CUSTOM_API_SOURCE_PREFIX = "openclaw-custom-api:";
export function getCustomApiRegistrySourceId(api: Api): string {
return `${CUSTOM_API_SOURCE_PREFIX}${api}`;
}
export function ensureCustomApiRegistered(api: Api, streamFn: StreamFn): boolean {
if (getApiProvider(api)) {
return false;
}
registerApiProvider(
{
api,
stream: (model, context, options) =>
streamFn(model, context, options) as unknown as ReturnType<
NonNullable<ReturnType<typeof getApiProvider>>["stream"]
>,
streamSimple: (model, context, options) =>
streamFn(model, context, options as StreamOptions) as unknown as ReturnType<
NonNullable<ReturnType<typeof getApiProvider>>["stream"]
>,
},
getCustomApiRegistrySourceId(api),
);
return true;
}