Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions openrouter/server/tools/llm-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export const createLLMStreamTool = (env: Env) =>
execute: async ({ context }) => {
const {
modelId,
callOptions: { abortSignal: _abortSignal, ...callOptions },
callOptions: { abortSignal: _abortSignal, ...callOptions } = {},
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Same issue: destructuring default = {} does not handle null values. Consider extracting callOptions first and using nullish coalescing: const { abortSignal: _abortSignal, ...callOptions } = context.callOptions ?? {};

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At openrouter/server/tools/llm-binding.ts, line 484:

<comment>Same issue: destructuring default `= {}` does not handle `null` values. Consider extracting `callOptions` first and using nullish coalescing: `const { abortSignal: _abortSignal, ...callOptions } = context.callOptions ?? {};`</comment>

<file context>
@@ -481,7 +481,7 @@ export const createLLMStreamTool = (env: Env) =&gt;
       const {
         modelId,
-        callOptions: { abortSignal: _abortSignal, ...callOptions },
+        callOptions: { abortSignal: _abortSignal, ...callOptions } = {},
       } = context;
       env.MESH_REQUEST_CONTEXT.ensureAuthenticated();
</file context>
Fix with Cubic

} = context;
env.MESH_REQUEST_CONTEXT.ensureAuthenticated();

Expand Down Expand Up @@ -516,7 +516,7 @@ export const createLLMGenerateTool = (env: Env) =>
execute: async ({ context }) => {
const {
modelId,
callOptions: { abortSignal: _abortSignal, ...callOptions },
callOptions: { abortSignal: _abortSignal, ...callOptions } = {},
} = context;
env.MESH_REQUEST_CONTEXT.ensureAuthenticated();

Expand All @@ -531,6 +531,12 @@ export const createLLMGenerateTool = (env: Env) =>
callOptions as LanguageModelV2CallOptions,
);

// Clean up response.body if it's a Uint8Array (raw HTTP response)
// This ensures JSON serialization works correctly over MCP
if (result?.response?.body instanceof Uint8Array) {
result.response.body = new TextDecoder().decode(result.response.body);
}

return result as unknown as z.infer<typeof GENERATE_BINDING.outputSchema>;
},
});
Expand Down
Loading