Files
openclaw/src/agents/simple-completion-transport.ts
2026-03-27 05:38:58 +00:00

30 lines
1.1 KiB
TypeScript

import { getApiProvider, type Api, type Model } from "@mariozechner/pi-ai";
import type { OpenClawConfig } from "../config/config.js";
import { createAnthropicVertexStreamFnForModel } from "./anthropic-vertex-stream.js";
import { ensureCustomApiRegistered } from "./custom-api-registry.js";
import { registerProviderStreamForModel } from "./provider-stream.js";
function resolveAnthropicVertexSimpleApi(baseUrl?: string): Api {
const suffix = baseUrl?.trim() ? encodeURIComponent(baseUrl.trim()) : "default";
return `openclaw-anthropic-vertex-simple:${suffix}`;
}
export function prepareModelForSimpleCompletion<TApi extends Api>(params: {
model: Model<TApi>;
cfg?: OpenClawConfig;
}): Model<Api> {
const { model, cfg } = params;
// Only provider-owned custom APIs need runtime stream registration here.
if (!getApiProvider(model.api) && registerProviderStreamForModel({ model, cfg })) {
return model;
}
if (model.provider === "anthropic-vertex") {
const api = resolveAnthropicVertexSimpleApi(model.baseUrl);
ensureCustomApiRegistered(api, createAnthropicVertexStreamFnForModel(model));
return { ...model, api };
}
return model;
}