UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) 2.63 kB
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { a as createLazyRuntimeSurface, r as createLazyRuntimeModule } from "./lazy-runtime-CgCh8H_K.js"; import "./string-coerce-runtime-GQa0ehRA.js"; import "./provider-model-shared-fX-Ywqb3.js"; import "./provider-catalog-shared-B4jeC2Nd.js"; import { t as buildOpenAIReplayPolicy } from "./replay-policy-JEpwmvIo.js"; import { t as resolveOpenAITransportTurnState } from "./transport-policy-BwAot0Pm.js"; //#region extensions/openai/shared.ts const OPENAI_API_BASE_URL = "https://api.openai.com/v1"; const OPENAI_DEFAULT_RUNTIME_CONTEXT_TOKENS = 272e3; function resolveConfiguredOpenAIBaseUrl(cfg) { return normalizeOptionalString(cfg?.models?.providers?.openai?.baseUrl) ?? OPENAI_API_BASE_URL; } function hasSupportedOpenAIResponsesTransport(transport) { return transport === "auto" || transport === "sse" || transport === "websocket" || transport === "websocket-cached"; } function defaultOpenAIResponsesExtraParams(extraParams, options) { const hasSupportedTransport = hasSupportedOpenAIResponsesTransport(extraParams?.transport); const defaultTransport = options?.transport ?? "auto"; if (hasSupportedTransport) return extraParams; return { ...extraParams, transport: defaultTransport }; } const resolveOpenAIResponsesTransportTurnState = (ctx) => resolveOpenAITransportTurnState(ctx); const loadResponsesStream = createLazyRuntimeModule(() => import("./extensions/openai/responses-stream.runtime.js")); const wrapOpenAIResponsesProviderStreamFn = (ctx) => { const loadStream = createLazyRuntimeSurface(loadResponsesStream, (runtime) => runtime.wrapOpenAIResponsesStream(ctx)); return async (...args) => (await loadStream())(...args); }; function buildOpenAIResponsesProviderHooks(options) { return { buildReplayPolicy: buildOpenAIReplayPolicy, prepareExtraParams: (ctx) => defaultOpenAIResponsesExtraParams(ctx.extraParams, options), wrapStreamFn: wrapOpenAIResponsesProviderStreamFn, resolveTransportTurnState: resolveOpenAIResponsesTransportTurnState }; } function buildOpenAISyntheticCatalogEntry(template, entry) { if (!template) return; return { ...template, id: entry.id, name: entry.id, reasoning: entry.reasoning, input: [...entry.input], contextWindow: entry.contextWindow, ...entry.contextTokens === void 0 ? {} : { contextTokens: entry.contextTokens }, ...entry.cost === void 0 ? {} : { cost: entry.cost } }; } //#endregion export { resolveConfiguredOpenAIBaseUrl as i, buildOpenAIResponsesProviderHooks as n, buildOpenAISyntheticCatalogEntry as r, OPENAI_DEFAULT_RUNTIME_CONTEXT_TOKENS as t };