fix(providers): route ClawRouter direct streams

This commit is contained in:
Vincent Koc
2026-06-17 08:12:43 +08:00
committed by Vincent Koc
parent ad81cb44ba
commit d667dcfb90
3 changed files with 26 additions and 5 deletions
+12
View File
@@ -57,6 +57,7 @@ describe("clawrouter provider plugin", () => {
envVars: ["CLAWROUTER_API_KEY"],
isModernModelRef: expect.any(Function),
buildReplayPolicy: expect.any(Function),
createStreamFn: expect.any(Function),
normalizeResolvedModel: expect.any(Function),
sanitizeReplayHistory: expect.any(Function),
wrapSimpleCompletionStreamFn: expect.any(Function),
@@ -67,6 +68,17 @@ describe("clawrouter provider plugin", () => {
label: "ClawRouter proxy key",
kind: "api_key",
});
expect(
provider?.createStreamFn?.({
provider: "clawrouter",
modelId: "anthropic/default",
model: {
provider: "clawrouter",
api: "anthropic-messages",
id: "anthropic/default",
},
} as never),
).toBeTypeOf("function");
expect(provider?.wrapSimpleCompletionStreamFn).toBe(provider?.wrapStreamFn);
});
+2 -1
View File
@@ -13,7 +13,7 @@ import {
normalizeClawRouterApiBaseUrl,
normalizeClawRouterResolvedModel,
} from "./provider-catalog.js";
import { wrapClawRouterProviderStream } from "./stream.js";
import { createClawRouterStreamFn, wrapClawRouterProviderStream } from "./stream.js";
const PROVIDER_ID = "clawrouter";
const ENV_VAR = "CLAWROUTER_API_KEY";
@@ -99,6 +99,7 @@ export default definePluginEntry({
const baseUrl = normalizeClawRouterApiBaseUrl(providerConfig.baseUrl);
return baseUrl !== providerConfig.baseUrl ? { ...providerConfig, baseUrl } : undefined;
},
createStreamFn: createClawRouterStreamFn,
normalizeResolvedModel: ({ model }) => normalizeClawRouterResolvedModel(model),
wrapSimpleCompletionStreamFn: wrapClawRouterProviderStream,
wrapStreamFn: wrapClawRouterProviderStream,
+12 -4
View File
@@ -1,4 +1,5 @@
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
import { streamSimple } from "openclaw/plugin-sdk/llm";
import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry";
import { prepareClawRouterRequestModel } from "./provider-catalog.js";
@@ -18,10 +19,7 @@ function withBearerAuthorization(
return next;
}
export function wrapClawRouterProviderStream(
ctx: ProviderWrapStreamFnContext,
): StreamFn | undefined {
const underlying = ctx.streamFn;
function createClawRouterStreamWrapper(underlying: StreamFn | undefined): StreamFn | undefined {
if (!underlying) {
return undefined;
}
@@ -40,3 +38,13 @@ export function wrapClawRouterProviderStream(
);
};
}
export function createClawRouterStreamFn(): StreamFn {
return createClawRouterStreamWrapper(streamSimple) as StreamFn;
}
export function wrapClawRouterProviderStream(
ctx: ProviderWrapStreamFnContext,
): StreamFn | undefined {
return createClawRouterStreamWrapper(ctx.streamFn);
}