Skip to content

feat: add Moonshot web search provider support - #20

Merged
emilsvennesson merged 2 commits into
mainfrom
feat/moonshot-web-search
Apr 29, 2026
Merged

emilsvennesson merged 2 commits into
mainfrom
feat/moonshot-web-search

Conversation

@emilsvennesson

Copy link
Copy Markdown
Owner

Summary

  • add a Moonshot provider adapter that executes web search via Moonshot chat completions and builtin tool calls
  • extend provider detection and resolution to recognize Moonshot and resolve base URLs from provider options or model API URL
  • update shared OpenAI-compatible helpers and docs so Moonshot responses expose answer text and citations consistently

Validation

  • bun run check

Closes #16

Copilot AI review requested due to automatic review settings April 29, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 moonshot provider 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.

Comment thread src/config.ts
Comment on lines 177 to 180
const scan = state[providerType];
if (!scan.credentials) {
scan.credentials = extractCredentials(provider, providerType);
scan.credentials = extractCredentials(provider, providerType, model);
}

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread src/providers/moonshot/index.ts Outdated
Comment on lines +212 to +216
for (const toolCall of toolCalls) {
appendToolResultMessage(messages, toolCall);
}

return executeSearchTurn(client, model, messages, query);

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread README.md Outdated
| 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 |

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
| Moonshot (Kimi) | A Moonshot API key configured in OpenCode |
| Moonshot (Kimi) | A Moonshot API key configured in OpenCode |

Copilot uses AI. Check for mistakes.
- 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
@emilsvennesson
emilsvennesson merged commit cff9fcb into main Apr 29, 2026
1 check passed
@emilsvennesson
emilsvennesson deleted the feat/moonshot-web-search branch April 29, 2026 18:37
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.

Kimi web search support

2 participants