fix(providers): handle proxied DeepSeek V4 replay

This commit is contained in:
Peter Steinberger
2026-04-25 19:23:06 +01:00
parent b8a41739d5
commit 31456e3326
7 changed files with 254 additions and 2 deletions

View File

@@ -35,4 +35,60 @@ describe("venice provider plugin", () => {
} as never),
).toBeUndefined();
});
it("fills missing DeepSeek V4 reasoning_content on Venice replay turns", async () => {
const provider = await registerSingleProviderPlugin(plugin);
const capturedPayloads: Record<string, unknown>[] = [];
const baseStreamFn = (_model: unknown, _context: unknown, options: unknown) => {
const payload = {
model: "deepseek-v4-pro",
thinking: { type: "enabled" },
reasoning_effort: "high",
messages: [
{
role: "assistant",
tool_calls: [
{
id: "call_1",
type: "function",
function: { name: "read", arguments: "{}" },
},
],
},
],
};
(options as { onPayload?: (payload: Record<string, unknown>) => void })?.onPayload?.(payload);
capturedPayloads.push(payload);
return {} as never;
};
const streamFn = provider.wrapStreamFn?.({
streamFn: baseStreamFn as never,
providerId: "venice",
modelId: "deepseek-v4-pro",
thinkingLevel: "high",
} as never);
expect(streamFn).toBeTypeOf("function");
await streamFn?.({ provider: "venice", id: "deepseek-v4-pro" } as never, {} as never, {});
expect(capturedPayloads).toEqual([
{
model: "deepseek-v4-pro",
messages: [
{
role: "assistant",
tool_calls: [
{
id: "call_1",
type: "function",
function: { name: "read", arguments: "{}" },
},
],
reasoning_content: "",
},
],
},
]);
});
});

View File

@@ -3,6 +3,7 @@ import { applyXaiModelCompat } from "openclaw/plugin-sdk/provider-tools";
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
import { applyVeniceConfig, VENICE_DEFAULT_MODEL_REF } from "./onboard.js";
import { buildVeniceProvider } from "./provider-catalog.js";
import { createVeniceDeepSeekV4Wrapper } from "./stream.js";
const PROVIDER_ID = "venice";
@@ -44,5 +45,6 @@ export default defineSingleProviderPluginEntry({
},
normalizeResolvedModel: ({ modelId, model }) =>
isXaiBackedVeniceModel(modelId) ? applyXaiModelCompat(model) : undefined,
wrapStreamFn: (ctx) => createVeniceDeepSeekV4Wrapper(ctx.streamFn, ctx.thinkingLevel),
},
});

View File

@@ -0,0 +1,37 @@
import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry";
import { createPayloadPatchStreamWrapper } from "openclaw/plugin-sdk/provider-stream-shared";
function isVeniceDeepSeekV4ModelId(modelId: unknown): boolean {
return modelId === "deepseek-v4-flash" || modelId === "deepseek-v4-pro";
}
function ensureVeniceDeepSeekV4Replay(payload: Record<string, unknown>): void {
delete payload.thinking;
delete payload.reasoning;
delete payload.reasoning_effort;
if (!Array.isArray(payload.messages)) {
return;
}
for (const message of payload.messages) {
if (!message || typeof message !== "object") {
continue;
}
const record = message as Record<string, unknown>;
if (record.role === "assistant" && Array.isArray(record.tool_calls)) {
record.reasoning_content ??= "";
}
}
}
export function createVeniceDeepSeekV4Wrapper(
baseStreamFn: ProviderWrapStreamFnContext["streamFn"],
thinkingLevel: ProviderWrapStreamFnContext["thinkingLevel"],
): ProviderWrapStreamFnContext["streamFn"] {
void thinkingLevel;
return createPayloadPatchStreamWrapper(baseStreamFn, ({ payload, model }) => {
if (model.provider === "venice" && isVeniceDeepSeekV4ModelId(model.id)) {
ensureVeniceDeepSeekV4Replay(payload);
}
});
}