Skip to content

Commit d8d178b

Browse files
cxbAsDevclaude
andcommitted
fix(plugins): use shared readProviderJsonResponse for embeddings API
Replace custom readJsonResponse with the shared readProviderJsonResponse from provider-http-errors, which already includes the standard 16 MB bounded read via readResponseWithLimit. This avoids duplicating the bounded-read pattern and keeps the embeddings provider aligned with provider HTTP guardrails. Co-Authored-By: Claude <[email protected]>
1 parent 9e3a917 commit d8d178b

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/plugins/openai-compatible-embedding-provider.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// Builds OpenAI-compatible embedding provider entries for plugins.
21
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
2+
// Builds OpenAI-compatible embedding provider entries for plugins.
3+
import { readProviderJsonResponse } from "../agents/provider-http-errors.js";
34
import { normalizeSecretInputString } from "../config/types.secrets.js";
45
import { resolveConfiguredSecretInputString } from "../gateway/resolve-configured-secret-input-string.js";
56
import { fetchWithSsrFGuard } from "../infra/net/fetch-guard.js";
@@ -284,13 +285,7 @@ function readEmbeddingVectors(
284285
});
285286
}
286287

287-
async function readJsonResponse(response: Response): Promise<unknown> {
288-
try {
289-
return await response.json();
290-
} catch (cause) {
291-
throw new Error("openai-compatible embeddings failed: malformed JSON response", { cause });
292-
}
293-
}
288+
const EMBEDDINGS_LABEL = "openai-compatible embeddings failed";
294289

295290
function concatBytes(chunks: Uint8Array[], totalLength: number): Uint8Array {
296291
const combined = new Uint8Array(totalLength);
@@ -386,7 +381,10 @@ async function postEmbeddingRequest(params: {
386381
throw await createEmbeddingHttpError(response);
387382
}
388383
return readEmbeddingVectors(
389-
(await readJsonResponse(response)) as OpenAICompatibleEmbeddingResponse,
384+
(await readProviderJsonResponse(
385+
response,
386+
EMBEDDINGS_LABEL,
387+
)) as OpenAICompatibleEmbeddingResponse,
390388
input.length,
391389
);
392390
} finally {

0 commit comments

Comments
 (0)