mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 01:30:21 +00:00
fix(plugin-sdk): unblock gateway test surfaces
This commit is contained in:
@@ -5,6 +5,24 @@ import {
|
||||
composeProviderStreamWrappers,
|
||||
} from "./provider-stream.js";
|
||||
|
||||
function requireWrapStreamFn(
|
||||
wrapStreamFn: ReturnType<typeof buildProviderStreamFamilyHooks>["wrapStreamFn"],
|
||||
) {
|
||||
expect(wrapStreamFn).toBeTypeOf("function");
|
||||
if (!wrapStreamFn) {
|
||||
throw new Error("expected wrapStreamFn to be defined");
|
||||
}
|
||||
return wrapStreamFn;
|
||||
}
|
||||
|
||||
function requireStreamFn(streamFn: StreamFn | null | undefined) {
|
||||
expect(streamFn).toBeTypeOf("function");
|
||||
if (!streamFn) {
|
||||
throw new Error("expected wrapped streamFn to be defined");
|
||||
}
|
||||
return streamFn;
|
||||
}
|
||||
|
||||
describe("composeProviderStreamWrappers", () => {
|
||||
it("applies wrappers left to right", async () => {
|
||||
const order: string[] = [];
|
||||
@@ -51,19 +69,17 @@ describe("buildProviderStreamFamilyHooks", () => {
|
||||
>;
|
||||
options?.onPayload?.(payload as never, model as never);
|
||||
capturedPayload = payload;
|
||||
capturedHeaders = options?.headers as Record<string, string> | undefined;
|
||||
capturedHeaders = options?.headers;
|
||||
return {} as never;
|
||||
};
|
||||
|
||||
const googleHooks = buildProviderStreamFamilyHooks("google-thinking");
|
||||
googleHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "high",
|
||||
} as never)(
|
||||
{ api: "google-generative-ai", id: "gemini-3.1-pro-preview" } as never,
|
||||
{} as never,
|
||||
{},
|
||||
);
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(googleHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "high",
|
||||
} as never),
|
||||
)({ api: "google-generative-ai", id: "gemini-3.1-pro-preview" } as never, {} as never, {});
|
||||
expect(capturedPayload).toMatchObject({
|
||||
config: { thinkingConfig: { thinkingLevel: "HIGH" } },
|
||||
});
|
||||
@@ -73,10 +89,12 @@ describe("buildProviderStreamFamilyHooks", () => {
|
||||
expect(googleThinkingConfig).not.toHaveProperty("thinkingBudget");
|
||||
|
||||
const minimaxHooks = buildProviderStreamFamilyHooks("minimax-fast-mode");
|
||||
minimaxHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: { fastMode: true },
|
||||
} as never)(
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(minimaxHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: { fastMode: true },
|
||||
} as never),
|
||||
)(
|
||||
{
|
||||
api: "anthropic-messages",
|
||||
provider: "minimax",
|
||||
@@ -88,26 +106,26 @@ describe("buildProviderStreamFamilyHooks", () => {
|
||||
expect(capturedModelId).toBe("MiniMax-M2.7-highspeed");
|
||||
|
||||
const moonshotHooks = buildProviderStreamFamilyHooks("moonshot-thinking");
|
||||
moonshotHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "off",
|
||||
} as never)(
|
||||
{ api: "openai-completions", id: "kimi-k2.5" } as never,
|
||||
{} as never,
|
||||
{},
|
||||
);
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(moonshotHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "off",
|
||||
} as never),
|
||||
)({ api: "openai-completions", id: "kimi-k2.5" } as never, {} as never, {});
|
||||
expect(capturedPayload).toMatchObject({
|
||||
config: { thinkingConfig: { thinkingBudget: -1 } },
|
||||
thinking: { type: "disabled" },
|
||||
});
|
||||
|
||||
const openAiHooks = buildProviderStreamFamilyHooks("openai-responses-defaults");
|
||||
openAiHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: { serviceTier: "flex" },
|
||||
config: {},
|
||||
agentDir: "/tmp/provider-stream-test",
|
||||
} as never)(
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(openAiHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: { serviceTier: "flex" },
|
||||
config: {},
|
||||
agentDir: "/tmp/provider-stream-test",
|
||||
} as never),
|
||||
)(
|
||||
{
|
||||
api: "openai-responses",
|
||||
provider: "openai",
|
||||
@@ -124,40 +142,48 @@ describe("buildProviderStreamFamilyHooks", () => {
|
||||
expect(capturedHeaders).toBeDefined();
|
||||
|
||||
const openRouterHooks = buildProviderStreamFamilyHooks("openrouter-thinking");
|
||||
openRouterHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "high",
|
||||
modelId: "openai/gpt-5.4",
|
||||
} as never)({ provider: "openrouter", id: "openai/gpt-5.4" } as never, {} as never, {});
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(openRouterHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "high",
|
||||
modelId: "openai/gpt-5.4",
|
||||
} as never),
|
||||
)({ provider: "openrouter", id: "openai/gpt-5.4" } as never, {} as never, {});
|
||||
expect(capturedPayload).toMatchObject({
|
||||
config: { thinkingConfig: { thinkingBudget: -1 } },
|
||||
reasoning: { effort: "high" },
|
||||
});
|
||||
|
||||
openRouterHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "high",
|
||||
modelId: "x-ai/grok-3",
|
||||
} as never)({ provider: "openrouter", id: "x-ai/grok-3" } as never, {} as never, {});
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(openRouterHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
thinkingLevel: "high",
|
||||
modelId: "x-ai/grok-3",
|
||||
} as never),
|
||||
)({ provider: "openrouter", id: "x-ai/grok-3" } as never, {} as never, {});
|
||||
expect(capturedPayload).toMatchObject({
|
||||
config: { thinkingConfig: { thinkingBudget: -1 } },
|
||||
});
|
||||
expect(capturedPayload).not.toHaveProperty("reasoning");
|
||||
|
||||
const toolStreamHooks = buildProviderStreamFamilyHooks("tool-stream-default-on");
|
||||
toolStreamHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: {},
|
||||
} as never)({ id: "glm-4.7" } as never, {} as never, {});
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(toolStreamHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: {},
|
||||
} as never),
|
||||
)({ id: "glm-4.7" } as never, {} as never, {});
|
||||
expect(capturedPayload).toMatchObject({
|
||||
config: { thinkingConfig: { thinkingBudget: -1 } },
|
||||
tool_stream: true,
|
||||
});
|
||||
|
||||
toolStreamHooks.wrapStreamFn?.({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: { tool_stream: false },
|
||||
} as never)({ id: "glm-4.7" } as never, {} as never, {});
|
||||
void requireStreamFn(
|
||||
requireWrapStreamFn(toolStreamHooks.wrapStreamFn)({
|
||||
streamFn: baseStreamFn,
|
||||
extraParams: { tool_stream: false },
|
||||
} as never),
|
||||
)({ id: "glm-4.7" } as never, {} as never, {});
|
||||
expect(capturedPayload).toMatchObject({
|
||||
config: { thinkingConfig: { thinkingBudget: -1 } },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user