mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
fix(providers): route ClawRouter direct streams
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user