Skip to content

feat: add OpenRouter as a full agentic provider#114

Merged
bbsngg merged 3 commits intomainfrom
openrouter
Mar 28, 2026
Merged

feat: add OpenRouter as a full agentic provider#114
bbsngg merged 3 commits intomainfrom
openrouter

Conversation

@zli12321
Copy link
Copy Markdown
Collaborator

No description provided.

@bbsngg
Copy link
Copy Markdown
Contributor

bbsngg commented Mar 28, 2026

Summary: this PR adds OpenRouter as a first-class provider end to end. It wires server-side execution and session persistence, adds OpenRouter auth/model settings, exposes it in chat and auto-research provider selection, and adds a standalone dr-claw chat CLI entrypoint backed by OpenRouter. I also ran npm run typecheck and npm run build, and both passed locally.

I found two functional gaps worth fixing before merge:

  1. Saved tool permission rules are not applied for OpenRouter sessions. In src/components/chat/hooks/useChatComposerState.ts around lines 1050-1067, the new openrouter-command payload only sends permissionMode, unlike Cursor/Gemini/Claude which also pass the persisted tools settings. On the server side, server/openrouter.js around lines 363-388 initializes empty allowedTools / disallowedTools arrays and only populates them from approvals made during the current run. That means existing remembered allow/deny entries and skip-permission behavior are ignored for OpenRouter, so users will get re-prompted for tools they already approved elsewhere.

  2. Reopened OpenRouter sessions lose tool-use messages in history. During execution, server/openrouter.js around lines 751-811 persists assistant tool calls via tool_calls and also streams them to the UI as structured tool_use events. But when history is loaded from disk, server/projects.js around lines 1803-1829 only reconstructs plain user/assistant messages plus tool_result rows. The assistant-side tool invocations are dropped, so historical sessions will no longer show which tools were called, only their results. That makes old OpenRouter transcripts less complete than live ones and less complete than the existing Gemini/Claude history handling.

After those two are addressed, the overall integration looks solid.

@zli12321
Copy link
Copy Markdown
Collaborator Author

Address those two issues:
Issue 1: Saved tool permission rules not applied for OpenRouter
Issue 2: Reopened OpenRouter sessions lose tool-use messages
Fix (1 file):

server/projects.js — Updated the OpenRouter history reader to:
Emit the text content as a message entry (if present)
Iterate over entry.tool_calls and emit a tool_use entry for each one (with toolName, toolInput, toolCallId, timestamp) matching the format used by Codex/Claude
Added toolCallId to tool_result entries for proper cross-referencing

@bbsngg
Copy link
Copy Markdown
Contributor

bbsngg commented Mar 28, 2026

Addressed the remaining OpenRouter history issue in 0210672.

Fix:

  • aligned OpenRouter historical tool_result payloads with the frontend session-message transformer by returning output instead of content from getSessionMessages

Impact:

  • reopened OpenRouter sessions now show tool results correctly instead of rendering blank result bodies

Validation:

  • npm run typecheck
  • npm run build

@bbsngg bbsngg merged commit d8d9da3 into main Mar 28, 2026
1 check passed
@bbsngg bbsngg deleted the openrouter branch March 28, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants