fix(openai): wrap malformed embedding batch jsonl

This commit is contained in:
Vincent Koc
2026-05-14 19:43:34 +08:00
parent d9c6036a8f
commit 8813b79990
3 changed files with 19 additions and 2 deletions

View File

@@ -62,6 +62,7 @@ Docs: https://docs.openclaw.ai
- Node host: report malformed built-in invoke `paramsJSON` with stable invalid-request errors instead of leaking raw parser failures.
- Amazon Bedrock embeddings: report malformed provider response JSON with provider-owned errors instead of leaking raw parser failures.
- QQBot: report malformed access-token JSON with provider-owned errors instead of leaking raw parser failures.
- OpenAI embeddings: report malformed batch output JSONL with provider-owned errors instead of leaking raw parser failures.
- Models config/auth: stop inferring provider env-var markers from broad `^[A-Z_][A-Z0-9_]*$` strings, and resolve config-backed provider `apiKey` values only through structured env SecretRefs (`secrets.providers[id]` / `secrets.defaults`), so unrelated env vars cannot accidentally become provider credentials. Thanks @sallyom.
- Media fetch: skip allocating and buffering the response body for bodyless media responses (HEAD probes and 204-style empty bodies), avoiding wasted heap on streams that carry no payload. Thanks @shakkernerd.
- CLI/onboarding: forward provider-specific auth flags (e.g. `--openai-api-key`) through the onboarding wizard so they reach provider auth methods via `ctx.opts`, letting `--openai-api-key "$OPENAI_API_KEY"` skip the redundant "use existing env var?" prompt in non-interactive harnesses. (#81669) Thanks @sjf.

View File

@@ -0,0 +1,10 @@
import { describe, expect, it } from "vitest";
import { parseOpenAiBatchOutput } from "./embedding-batch.js";
describe("OpenAI embedding batch output", () => {
it("wraps malformed JSONL output", () => {
expect(() => parseOpenAiBatchOutput('{"custom_id":"ok"}\n{not json')).toThrow(
"OpenAI embedding batch output contained malformed JSONL",
);
});
});

View File

@@ -122,7 +122,7 @@ async function fetchOpenAiBatchResource<T>(params: {
});
}
function parseOpenAiBatchOutput(text: string): OpenAiBatchOutputLine[] {
export function parseOpenAiBatchOutput(text: string): OpenAiBatchOutputLine[] {
if (!text.trim()) {
return [];
}
@@ -130,7 +130,13 @@ function parseOpenAiBatchOutput(text: string): OpenAiBatchOutputLine[] {
.split("\n")
.map((line) => line.trim())
.filter(Boolean)
.map((line) => JSON.parse(line) as OpenAiBatchOutputLine);
.map((line) => {
try {
return JSON.parse(line) as OpenAiBatchOutputLine;
} catch {
throw new Error("OpenAI embedding batch output contained malformed JSONL");
}
});
}
async function readOpenAiBatchError(params: {