Skip to content

Commit 1971456

Browse files
xavidopclaude
andauthored
Fix: Fix streaming response body type checking for Node.js compatibility (#292)
The 'in' operator fails when response.body is not a plain object (e.g., ReadableStream in Node.js). Added proper type checking before using the 'in' operator to prevent runtime errors. This resolves issues with streaming responses that contain ReadableStream bodies instead of plain objects. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
2 parents c9e6f9e + e033ef9 commit 1971456

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/github_llms.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,21 +1202,21 @@ export function githubModel(
12021202
}
12031203
return {
12041204
message:
1205-
"choices" in response.body
1205+
(typeof response.body === 'object' && response.body && "choices" in response.body)
12061206
? fromGithubChoice(
12071207
response.body.choices[0],
12081208
request.output?.format === "json",
12091209
).message
12101210
: { role: "model", content: [] },
12111211
usage: {
12121212
inputTokens:
1213-
"usage" in response.body ? response.body.usage?.prompt_tokens : 0,
1213+
(typeof response.body === 'object' && response.body && "usage" in response.body) ? response.body.usage?.prompt_tokens : 0,
12141214
outputTokens:
1215-
"usage" in response.body
1215+
(typeof response.body === 'object' && response.body && "usage" in response.body)
12161216
? response.body.usage?.completion_tokens
12171217
: 0,
12181218
totalTokens:
1219-
"usage" in response.body ? response.body.usage?.total_tokens : 0,
1219+
(typeof response.body === 'object' && response.body && "usage" in response.body) ? response.body.usage?.total_tokens : 0,
12201220
},
12211221
custom: response,
12221222
};

0 commit comments

Comments
 (0)