Skip to content

Commit c372cb4

Browse files
patel-lyzrclaude
andcommitted
fix(gateway): guard indexed message access for noUncheckedIndexedAccess
`body.messages[i]` is `| undefined` under the package's strict tsconfig — broke the Docker image build (tsc) after the latest-user-message block fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d892c20 commit c372cb4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

packages/llm-proxy-openai/src/proxy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ async function redactAnthropicRequest(
327327
// Index of the most recent user message — the only span allowed to block.
328328
let lastUserIdx = -1;
329329
for (let i = body.messages.length - 1; i >= 0; i--) {
330-
if (body.messages[i].role === "user") { lastUserIdx = i; break; }
330+
if (body.messages[i]?.role === "user") { lastUserIdx = i; break; }
331331
}
332332

333333
// system prompt — redact only, never block
@@ -344,6 +344,7 @@ async function redactAnthropicRequest(
344344
// messages — redact all; honour `block` only for the latest user message
345345
for (let i = 0; i < body.messages.length; i++) {
346346
const msg = body.messages[i];
347+
if (!msg) continue;
347348
const canBlock = i === lastUserIdx;
348349
if (typeof msg.content === "string") {
349350
const r = await redact(msg.content);

0 commit comments

Comments
 (0)