feat: migrate chat to openrouter. - #152
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of UI/security correctness issues in the changed CSS/HTML (status text visibility fallback and key input masking) that should be addressed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR migrates the in-app AI chat feature from GitHub Models to OpenRouter, introducing a dedicated chat module with OpenRouter BYOK (bring your own key) handling while keeping GitHub PAT usage scoped to PR/repository workflows.
Changes:
- Replace GitHub Models chat transport with OpenRouter chat completions + model catalog loading.
- Add OpenRouter key UI/storage (localStorage) and gate chat composer/model picker on key presence.
- Refactor chat drawer into smaller modules (request runner, message renderer, proposal actions) and update Playwright coverage + docs.
File summaries
| File | Description |
|---|---|
| src/styles/ai-controls.css | Adds OpenRouter key section styling and pending-status shimmer animation. |
| src/modules/github/chat/drawer.js | Removes the old GitHub-models chat drawer implementation. |
| src/modules/github/api/core.js | Drops GitHub-chat-specific header helper no longer needed. |
| src/modules/github/api/constants.js | Removes GitHub Models chat constants/model lists. |
| src/modules/chat/workspace-actions.js | Renames/generalizes workspace actions for the new chat module. |
| src/modules/chat/utils.js | Switches defaults/error handling to OpenRouter-oriented semantics (key vs token). |
| src/modules/chat/tab-target-resolver.js | New shared resolver for mapping proposal targets to open tabs. |
| src/modules/chat/tab-scoped-undo-state.js | New shared per-tab undo snapshot store for apply/undo. |
| src/modules/chat/request-runner.js | New OpenRouter request orchestration (stream + fallback) with tool gating. |
| src/modules/chat/proposals.js | Adds allowMarkdownFallback guard for proposal extraction. |
| src/modules/chat/proposal-actions.js | Extracts apply/undo proposal logic from drawer into a dedicated module. |
| src/modules/chat/payload.js | Adds “explicit edit intent” gating for tool enablement and updates system prompt guidance. |
| src/modules/chat/model-picker.js | Adds model picker with free/paid grouping and optional catalog loading. |
| src/modules/chat/message-renderer.js | Extracts message rendering + streaming update behavior from drawer. |
| src/modules/chat/key-store.js | Adds OpenRouter key persistence/masking helpers (localStorage). |
| src/modules/chat/key-controls.js | Adds key connect/remove UI behavior and key-change notifications. |
| src/modules/chat/drawer.js | New top-level chat drawer wiring the new modules together. |
| src/modules/chat/drawer-events.js | Centralizes chat drawer DOM event handling and action dispatch. |
| src/modules/chat/api/request.js | Adds OpenRouter request headers + error parsing helpers. |
| src/modules/chat/api/models.js | Adds OpenRouter model catalog fetch + normalization logic. |
| src/modules/chat/api/constants.js | Defines OpenRouter endpoints and fallback model catalog. |
| src/modules/chat/api/completions.js | Migrates chat completions implementation to OpenRouter endpoints. |
| src/modules/chat/active-tab-context.js | Extracts active-tab context builder for payload editor context. |
| src/modules/app-core/github-workflows.js | Removes chat wiring from GitHub workflows (PR/BYOT-only). |
| src/modules/app-core/github-workflows-setup.js | Removes chat-specific dependencies from GitHub workflow setup. |
| src/modules/app-core/github-pr-context-ui.js | Renames token visibility sync to PR-surface-only behavior. |
| src/modules/app-core/chat-workflows.js | Adds dedicated initializer for chat drawer wiring in app-core. |
| src/modules/app-core/app-bindings-startup.js | Updates startup to use new PR-surface visibility sync. |
| src/index.html | Updates chat drawer markup for OpenRouter key controls and relocates chat toggle. |
| src/app.js | Switches to new chat workflows + workspace actions; wires OpenRouter key elements. |
| README.md | Adds docs link and clarifies PAT vs OpenRouter key responsibilities. |
| playwright/helpers/app-test-helpers.ts | Adds helpers to connect OpenRouter key and tightens selectors. |
| playwright/github-byot-ai.spec.ts | Updates BYOT visibility expectations (chat available without PAT) and removes old GitHub-chat tests. |
| playwright/chat/ai-chat.spec.ts | Adds comprehensive OpenRouter-based chat coverage (key gating, streaming/fallback, proposals). |
| docs/openrouter-byok.md | New OpenRouter BYOK setup guide. |
| docs/next-steps.md | Updates guidance and adds a future item for safe Markdown rendering in chat. |
| docs/localstorage-state.md | Documents the new OpenRouter key localStorage entry. |
| docs/byot.md | Clarifies BYOT scope (PR/repo workflows only) and points chat to OpenRouter BYOK. |
| docs/ai-chat-context-and-payload-strategy.md | Updates implementation references to the new chat module paths. |
Review details
- Files reviewed: 36/39 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.