Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/v1/_lib/proxy/stream-gate/frame-classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ const STREAM_SIGNALS: Record<ProtocolFamily, StreamSignal> = {
"openai-chat": {
contentRules: [
{
// chunk 无事件名;delta 携带 content/tool_calls/refusal/audio 即内容
// chunk 无事件名;delta 携带 content/reasoning/tool_calls/refusal/audio 即内容
anyPaths: [
"choices.#.delta.content",
"choices.#.delta.reasoning_content",
"choices.#.delta.tool_calls.#.function.arguments",
"choices.#.delta.function_call.arguments",
"choices.#.delta.refusal",
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/proxy/stream-gate-content-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@ describe("runStreamContentGate", () => {
}
});

it("openai-chat: DeepSeek reasoning_content commits before the default event cap", async () => {
const reasoningFrames = Array.from(
{ length: 65 },
(_, index) =>
`data: {"choices":[{"delta":{"reasoning_content":"reasoning step ${index}"}}]}\n\n`
);
const reader = readerFromChunks(reasoningFrames);
const result = await runStreamContentGate(reader, {
...GATE_OPTIONS,
family: "openai-chat",
});

expect(result.committed).toBe(true);
if (!result.committed) return;
expect(await drainPrefix(result.prefixChunks)).toBe(reasoningFrames[0]);
expect(result.readerDone).toBe(false);
});

it("gemini: usage-only chunks buffer until content commits", async () => {
const reader = readerFromChunks([
'data: {"usageMetadata":{"totalTokenCount":1}}\n\n',
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/proxy/stream-gate-forwarder-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,31 @@ describe("F1 stream content gate x ProxyForwarder sequential path", () => {
}
);

test("Replay owner 将 OpenAI-compatible DeepSeek reasoning_content 视为首个有效内容", async () => {
const provider = createProvider({
id: 1,
name: "deepseek-reasoning",
providerType: "openai-compatible",
});
const session = createSession();
session.setProvider(provider);
attachReplayOwner(session, REPLAY_GATE_CASES[1]);

const reasoningFrames = Array.from({ length: 65 }, (_, index) =>
sseFrame(null, { choices: [{ delta: { reasoning_content: `reasoning step ${index}` } }] })
);
const doForward = spyOnDoForward();
doForward.mockImplementationOnce(async () => createSseResponse(reasoningFrames));

const response = await ProxyForwarder.send(session);
const text = await response.text();

expect(doForward).toHaveBeenCalledTimes(1);
expect(text).toBe(reasoningFrames.join(""));
expect(mocks.pickRandomProviderWithExclusion).not.toHaveBeenCalled();
expect(mocks.recordFailure).not.toHaveBeenCalled();
});

test("Replay owner 在所有 precommit attempt 失败后立即释放所有权", async () => {
const provider = createProvider({ id: 1, name: "replay-only", providerType: "codex" });
const session = createSession();
Expand Down
14 changes: 12 additions & 2 deletions tests/unit/proxy/stream-gate-frame-classifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,17 @@ describe("classifyFrame: anthropic", () => {
});

describe("classifyFrame: openai-chat", () => {
it("content: delta content / tool arguments / refusal / audio", () => {
it("content: delta content / reasoning / tool arguments / refusal / audio", () => {
expect(classifyFrame("openai-chat", null, '{"choices":[{"delta":{"content":"hi"}}]}')).toBe(
"content"
);
expect(
classifyFrame(
"openai-chat",
null,
'{"choices":[{"delta":{"reasoning_content":"reasoning step"}}]}'
)
).toBe("content");
expect(
classifyFrame(
"openai-chat",
Expand Down Expand Up @@ -197,10 +204,13 @@ describe("classifyFrame: openai-chat", () => {
).toBe("neutral");
});

it("neutral: empty string content delta", () => {
it("neutral: empty string content or reasoning delta", () => {
expect(classifyFrame("openai-chat", null, '{"choices":[{"delta":{"content":""}}]}')).toBe(
"neutral"
);
expect(
classifyFrame("openai-chat", null, '{"choices":[{"delta":{"reasoning_content":""}}]}')
).toBe("neutral");
});

it("error: in-stream error payload", () => {
Expand Down
Loading