fix(plugins): share tool-stream defaults and align xai sdk imports

This commit is contained in:
Vincent Koc
2026-04-14 16:23:29 +01:00
parent 50e5f95cc6
commit 9c42e6424d
17 changed files with 100 additions and 35 deletions

View File

@@ -215,4 +215,28 @@ describe("zai provider plugin", () => {
expect(capturedPayload).not.toHaveProperty("tool_stream");
});
it("defaults tool_stream extra params but preserves explicit values", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.prepareExtraParams?.({
provider: "zai",
modelId: "glm-4.7",
extraParams: { endpoint: "global" },
} as never),
).toEqual({
endpoint: "global",
tool_stream: true,
});
const explicit = { endpoint: "global", tool_stream: false };
expect(
provider.prepareExtraParams?.({
provider: "zai",
modelId: "glm-4.7",
extraParams: explicit,
} as never),
).toBe(explicit);
});
});

View File

@@ -21,6 +21,7 @@ import {
normalizeModelCompat,
} from "openclaw/plugin-sdk/provider-model-shared";
import { buildProviderStreamFamilyHooks } from "openclaw/plugin-sdk/provider-stream-family";
import { defaultToolStreamExtraParams } from "openclaw/plugin-sdk/provider-stream-shared";
import { fetchZaiUsage, resolveLegacyPiAgentAccessToken } from "openclaw/plugin-sdk/provider-usage";
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
import { detectZaiEndpoint, type ZaiEndpointId } from "./detect.js";
@@ -281,15 +282,7 @@ export default definePluginEntry({
],
resolveDynamicModel: (ctx) => resolveGlm5ForwardCompatModel(ctx),
...OPENAI_COMPATIBLE_REPLAY_HOOKS,
prepareExtraParams: (ctx) => {
if (ctx.extraParams?.tool_stream !== undefined) {
return ctx.extraParams;
}
return {
...ctx.extraParams,
tool_stream: true,
};
},
prepareExtraParams: (ctx) => defaultToolStreamExtraParams(ctx.extraParams),
...ZAI_TOOL_STREAM_HOOKS,
isBinaryThinking: () => true,
isModernModelRef: ({ modelId }) => {