Repository navigation
feat: add Moonshot web search provider support - #20
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Moonshot (Kimi) as a first-class web-search provider by introducing a Moonshot adapter using chat completions + built-in tool calls, extending provider detection, and updating OpenAI-compatible helpers/error messaging so responses can include text + citations.
Changes:
- Added a new
moonshotprovider adapter that executes web search via Moonshot chat completions. - Extended provider detection/resolution to recognize Moonshot (including OpenAI-compatible models) and resolve base URLs from provider options or model API URL.
- Added shared helpers to extract chat-completions output text + citation hits, and updated docs/error messages to mention Moonshot.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Extends provider typings to include moonshot and its resolution entry. |
| src/providers/shared/openai-compatible.ts | Adds chat-completions text + citation extraction helpers for Moonshot-style responses. |
| src/providers/registry.ts | Extends provider-type detection to identify Moonshot (incl. OpenAI-compatible package + provider ID). |
| src/providers/moonshot/index.ts | Implements Moonshot web search execution via /chat/completions and built-in tool calls. |
| src/providers/index.ts | Registers the Moonshot adapter in the provider dispatch map. |
| src/index.ts | Updates provider-type detection flow to use model+provider context and recognizes Moonshot resolutions. |
| src/config.ts | Adds Moonshot to scanning/resolution; resolves baseURL from provider options or model API URL; updates user-facing errors. |
| README.md | Documents Moonshot (Kimi) as a supported provider. |
Comments suppressed due to low confidence (1)
src/config.ts:289
- This error message now lists Moonshot as a supported provider, but the guidance below still says to add an “Anthropic or OpenAI provider” and only includes Anthropic/OpenAI JSON examples. Update the wording (and ideally add a Moonshot example) so the remediation steps match the supported-provider list.
`Error: web-search requires an Anthropic, OpenAI (API key or ChatGPT OAuth), Moonshot, or GitHub Copilot provider.
No supported provider credentials (API key or OAuth) were found.
To fix this, add an Anthropic or OpenAI provider to your opencode.json:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const scan = state[providerType]; | ||
| if (!scan.credentials) { | ||
| scan.credentials = extractCredentials(provider, providerType); | ||
| scan.credentials = extractCredentials(provider, providerType, model); | ||
| } |
There was a problem hiding this comment.
processProviderModel only sets scan.credentials once, using the first matching model encountered. If provider.options.baseURL is unset and the first model lacks model.api.url (but a later model has it), scan.credentials.baseURL will stay undefined and Moonshot/OpenAI-compatible calls may fail. Consider updating the scan logic to fill in baseURL once it becomes available (e.g., update credentials when baseURL is still undefined/empty), or resolve the baseURL by scanning all models first before freezing credentials.
| for (const toolCall of toolCalls) { | ||
| appendToolResultMessage(messages, toolCall); | ||
| } | ||
|
|
||
| return executeSearchTurn(client, model, messages, query); |
There was a problem hiding this comment.
executeSearchTurn can loop indefinitely if the model keeps returning finish_reason: "tool_calls" (or repeatedly emits tool calls with no terminal assistant message). Add an explicit max turn/iteration limit and return a structured error when exceeded to avoid runaway API usage and hanging requests.
| | Provider | What you need | | ||
| | ---------------- | ------------------------------------------------------------------------ | | ||
| | Anthropic | An Anthropic provider/model in OpenCode with built-in web search support | | ||
| | Moonshot (Kimi) | A Moonshot API key configured in OpenCode | |
There was a problem hiding this comment.
The Moonshot row has trailing whitespace after “OpenCode”, which can create noisy diffs and inconsistent markdown rendering. Trim the extra spaces in that table cell.
| | Moonshot (Kimi) | A Moonshot API key configured in OpenCode | | |
| | Moonshot (Kimi) | A Moonshot API key configured in OpenCode | |
- bound Moonshot search loop with MAX_SEARCH_TURNS to prevent runaway tool-call recursion - backfill provider baseURL from later models when not set on the first match - mention Moonshot in no-provider error remediation guidance and add JSON example - trim trailing whitespace in Moonshot README table row
Summary
Validation
Closes #16