fix(providers): route ClawRouter direct streams · openclaw/openclaw@d667dcf
vincentkoc
·
2026-06-17
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -57,6 +57,7 @@ describe("clawrouter provider plugin", () => {
|
57 | 57 | envVars: ["CLAWROUTER_API_KEY"], |
58 | 58 | isModernModelRef: expect.any(Function), |
59 | 59 | buildReplayPolicy: expect.any(Function), |
| 60 | +createStreamFn: expect.any(Function), |
60 | 61 | normalizeResolvedModel: expect.any(Function), |
61 | 62 | sanitizeReplayHistory: expect.any(Function), |
62 | 63 | wrapSimpleCompletionStreamFn: expect.any(Function), |
@@ -67,6 +68,17 @@ describe("clawrouter provider plugin", () => {
|
67 | 68 | label: "ClawRouter proxy key", |
68 | 69 | kind: "api_key", |
69 | 70 | }); |
| 71 | +expect( |
| 72 | +provider?.createStreamFn?.({ |
| 73 | +provider: "clawrouter", |
| 74 | +modelId: "anthropic/default", |
| 75 | +model: { |
| 76 | +provider: "clawrouter", |
| 77 | +api: "anthropic-messages", |
| 78 | +id: "anthropic/default", |
| 79 | +}, |
| 80 | +} as never), |
| 81 | +).toBeTypeOf("function"); |
70 | 82 | expect(provider?.wrapSimpleCompletionStreamFn).toBe(provider?.wrapStreamFn); |
71 | 83 | }); |
72 | 84 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ import {
|
13 | 13 | normalizeClawRouterApiBaseUrl, |
14 | 14 | normalizeClawRouterResolvedModel, |
15 | 15 | } from "./provider-catalog.js"; |
16 | | -import { wrapClawRouterProviderStream } from "./stream.js"; |
| 16 | +import { createClawRouterStreamFn, wrapClawRouterProviderStream } from "./stream.js"; |
17 | 17 | |
18 | 18 | const PROVIDER_ID = "clawrouter"; |
19 | 19 | const ENV_VAR = "CLAWROUTER_API_KEY"; |
@@ -99,6 +99,7 @@ export default definePluginEntry({
|
99 | 99 | const baseUrl = normalizeClawRouterApiBaseUrl(providerConfig.baseUrl); |
100 | 100 | return baseUrl !== providerConfig.baseUrl ? { ...providerConfig, baseUrl } : undefined; |
101 | 101 | }, |
| 102 | +createStreamFn: createClawRouterStreamFn, |
102 | 103 | normalizeResolvedModel: ({ model }) => normalizeClawRouterResolvedModel(model), |
103 | 104 | wrapSimpleCompletionStreamFn: wrapClawRouterProviderStream, |
104 | 105 | wrapStreamFn: wrapClawRouterProviderStream, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import type { StreamFn } from "openclaw/plugin-sdk/agent-core"; |
| 2 | +import { streamSimple } from "openclaw/plugin-sdk/llm"; |
2 | 3 | import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry"; |
3 | 4 | import { prepareClawRouterRequestModel } from "./provider-catalog.js"; |
4 | 5 | |
@@ -18,10 +19,7 @@ function withBearerAuthorization(
|
18 | 19 | return next; |
19 | 20 | } |
20 | 21 | |
21 | | -export function wrapClawRouterProviderStream( |
22 | | -ctx: ProviderWrapStreamFnContext, |
23 | | -): StreamFn | undefined { |
24 | | -const underlying = ctx.streamFn; |
| 22 | +function createClawRouterStreamWrapper(underlying: StreamFn | undefined): StreamFn | undefined { |
25 | 23 | if (!underlying) { |
26 | 24 | return undefined; |
27 | 25 | } |
@@ -40,3 +38,13 @@ export function wrapClawRouterProviderStream(
|
40 | 38 | ); |
41 | 39 | }; |
42 | 40 | } |
| 41 | + |
| 42 | +export function createClawRouterStreamFn(): StreamFn { |
| 43 | +return createClawRouterStreamWrapper(streamSimple) as StreamFn; |
| 44 | +} |
| 45 | + |
| 46 | +export function wrapClawRouterProviderStream( |
| 47 | +ctx: ProviderWrapStreamFnContext, |
| 48 | +): StreamFn | undefined { |
| 49 | +return createClawRouterStreamWrapper(ctx.streamFn); |
| 50 | +} |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。