

























@@ -466,6 +466,63 @@ describe("openai transport stream", () => {
466466});
467467});
468468469+it("skips null and non-object OpenAI-compatible stream chunks", async () => {
470+const model = {
471+id: "glm-5",
472+name: "GLM-5",
473+api: "openai-completions",
474+provider: "vllm",
475+baseUrl: "http://localhost:8000/v1",
476+reasoning: false,
477+input: ["text"],
478+cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
479+contextWindow: 128000,
480+maxTokens: 4096,
481+} satisfies Model<"openai-completions">;
482+const output = {
483+role: "assistant" as const,
484+content: [],
485+api: model.api,
486+provider: model.provider,
487+model: model.id,
488+usage: {
489+input: 0,
490+output: 0,
491+cacheRead: 0,
492+cacheWrite: 0,
493+totalTokens: 0,
494+cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
495+},
496+stopReason: "stop",
497+timestamp: Date.now(),
498+};
499+const stream: { push(event: unknown): void } = { push() {} };
500+501+async function* mockStream() {
502+yield null as never;
503+yield "not-a-chunk" as never;
504+yield {
505+id: "chatcmpl-vllm",
506+object: "chat.completion.chunk" as const,
507+created: 1775425651,
508+model: "glm-5",
509+choices: [
510+{
511+index: 0,
512+delta: { role: "assistant" as const, content: "ok" },
513+logprobs: null,
514+finish_reason: "stop" as const,
515+},
516+],
517+};
518+}
519+520+await __testing.processOpenAICompletionsStream(mockStream(), output, model, stream);
521+522+expect(output.content).toContainEqual({ type: "text", text: "ok" });
523+expect(output.stopReason).toBe("stop");
524+});
525+469526it("keeps OpenRouter thinking format for declared OpenRouter providers on custom proxy URLs", async () => {
470527const streamFn = buildTransportAwareSimpleStreamFn(
471528attachModelProviderRequestTransport(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。