mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-02 02:57:51 +00:00
refactor(providers): compose provider stream wrappers
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
|
||||
import { DEFAULT_CONTEXT_TOKENS } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import {
|
||||
composeProviderStreamWrappers,
|
||||
getOpenRouterModelCapabilities,
|
||||
loadOpenRouterModelCapabilities,
|
||||
createOpenRouterSystemCacheWrapper,
|
||||
@@ -145,20 +146,21 @@ export default definePluginEntry({
|
||||
buildReplayPolicy: ({ modelId }) => buildOpenRouterReplayPolicy(modelId),
|
||||
isModernModelRef: () => true,
|
||||
wrapStreamFn: (ctx) => {
|
||||
let streamFn = ctx.streamFn;
|
||||
const providerRouting =
|
||||
ctx.extraParams?.provider != null && typeof ctx.extraParams.provider === "object"
|
||||
? (ctx.extraParams.provider as Record<string, unknown>)
|
||||
: undefined;
|
||||
if (providerRouting) {
|
||||
streamFn = injectOpenRouterRouting(streamFn, providerRouting);
|
||||
}
|
||||
const skipReasoningInjection =
|
||||
ctx.modelId === "auto" || isProxyReasoningUnsupported(ctx.modelId);
|
||||
const openRouterThinkingLevel = skipReasoningInjection ? undefined : ctx.thinkingLevel;
|
||||
streamFn = createOpenRouterWrapper(streamFn, openRouterThinkingLevel);
|
||||
streamFn = createOpenRouterSystemCacheWrapper(streamFn);
|
||||
return streamFn;
|
||||
return composeProviderStreamWrappers(
|
||||
ctx.streamFn,
|
||||
providerRouting
|
||||
? (streamFn) => injectOpenRouterRouting(streamFn, providerRouting)
|
||||
: undefined,
|
||||
(streamFn) => createOpenRouterWrapper(streamFn, openRouterThinkingLevel),
|
||||
(streamFn) => createOpenRouterSystemCacheWrapper(streamFn),
|
||||
);
|
||||
},
|
||||
isCacheTtlEligible: (ctx) => isOpenRouterCacheTtlModel(ctx.modelId),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user