feat(provider): add kimi-for-coding provider#394
Conversation
|
@beyond-infra is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds AnthropicCompatibleProvider to centralize Anthropic /v1/messages handling, refactors MinimaxProvider to extend it, introduces KimiForCodingProvider (wired into the provider factory and ProviderType), updates config detection, and adds tests validating base URL resolution, request shape, and error handling; also updates prompts, embedding local config, architecture doc, and viewer styling. ChangesAnthropic-compatible provider abstraction and Kimi integration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a5d039f to
18c7c6b
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/providers/kimi-for-coding.ts (1)
4-12: ⚡ Quick winReduce inline explanatory block comments and keep this self-descriptive.
This block is mostly “WHAT” documentation and can drift; prefer concise naming here and move operational notes/env-var docs to README/provider docs.
♻️ Suggested trim
-/** - * Kimi for Coding provider. - * - * Kimi's Coding Plan endpoint rejects the default Anthropic SDK User-Agent - * with HTTP 429 "engine overloaded". We pass a whitelisted User-Agent header. - * - * Required env var: KIMI_API_KEY - * Optional env vars: KIMI_BASE_URL (default: https://api.kimi.com/coding) - */ +/** Kimi for Coding provider. */As per coding guidelines, "Avoid code comments explaining WHAT — use clear naming instead".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/providers/kimi-for-coding.ts` around lines 4 - 12, The large explanatory block comment at the top of src/providers/kimi-for-coding.ts should be trimmed to a short self-descriptive header (e.g., "Kimi for Coding provider") and any operational details (env var requirements like KIMI_API_KEY, KIMI_BASE_URL and the User-Agent workaround) should be moved to the provider README or external docs; update the file header to a one-line description and remove the WHAT-focused paragraphs so the code stays self-descriptive while operational notes live in documentation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/providers/anthropic-compatible.ts`:
- Line 48: Both fetch calls in the anthropic-compatible provider (describeImage
and call) can hang; add a timeout using AbortController and apply it to both
functions (or import and reuse the existing fetchWithTimeout helper introduced
for minimax.ts) so every fetch is aborted after a configured timeout.
Specifically, update describeImage and call to create an AbortController, start
a timer that calls controller.abort() after the desired timeout, pass signal:
controller.signal into the fetch options, clear the timer on success/failure,
and surface a clear timeout error; prefer reusing the shared fetchWithTimeout
helper if available to avoid duplication.
- Around line 42-117: describeImage and call duplicate the same /v1/messages
fetch, header, error, JSON parse and text extraction logic; extract a shared
helper (e.g., requestMessage or postMessage) into the base class that accepts
the request body payload (or parameters to construct it) and returns the
extracted text string. Move repeated use of this.baseUrl, this.apiKey,
this.extraHeaders, this.errorPrefix, this.model and this.maxTokens into that
helper so describeImage and call only build their specific body (image+prompt vs
system+messages) and invoke the helper; ensure the helper preserves the existing
error formatting, JSON -> AnthropicMessageResponse parsing, and find((b) =>
b.type === "text") extraction so future changes (timeouts/retries/logging) are
applied once.
---
Nitpick comments:
In `@src/providers/kimi-for-coding.ts`:
- Around line 4-12: The large explanatory block comment at the top of
src/providers/kimi-for-coding.ts should be trimmed to a short self-descriptive
header (e.g., "Kimi for Coding provider") and any operational details (env var
requirements like KIMI_API_KEY, KIMI_BASE_URL and the User-Agent workaround)
should be moved to the provider README or external docs; update the file header
to a one-line description and remove the WHAT-focused paragraphs so the code
stays self-descriptive while operational notes live in documentation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e298018f-5080-4398-9fbd-fcb1a59479fe
📒 Files selected for processing (7)
src/providers/anthropic-compatible.tssrc/providers/index.tssrc/providers/kimi-for-coding.tssrc/providers/minimax.tssrc/types.tstest/kimi-for-coding-e2e.test.tstest/kimi-for-coding-provider.test.ts
| prompt: string, | ||
| ): Promise<string> { | ||
| const url = `${this.baseUrl}/v1/messages`; | ||
| const response = await fetch(url, { |
There was a problem hiding this comment.
Add a request timeout — both fetch calls can hang indefinitely.
Neither describeImage (line 48) nor call (line 93) sets an AbortController / timeout, so a stalled remote endpoint will block the calling code with no upper bound. The PR description itself notes that PR #379 introduces fetchWithTimeout for minimax.ts and recommends folding that into this shared base — please do so here so both Minimax and Kimi inherit the protection from day one, rather than relying on a follow-up merge.
🛡️ Sketch using AbortController
+ private timeoutMs: number;
constructor(
name: string,
apiKey: string,
model: string,
maxTokens: number,
baseUrl: string,
extraHeaders: Record<string, string> = {},
errorPrefix: string = "API",
+ timeoutMs: number = 60_000,
) {
...
+ this.timeoutMs = timeoutMs;
}
- const response = await fetch(url, {
- method: "POST",
- headers: { ... },
- body: JSON.stringify({ ... }),
- });
+ const controller = new AbortController();
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
+ let response: Response;
+ try {
+ response = await fetch(url, {
+ method: "POST",
+ headers: { ... },
+ body: JSON.stringify({ ... }),
+ signal: controller.signal,
+ });
+ } finally {
+ clearTimeout(timer);
+ }Also applies to: 93-93
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/providers/anthropic-compatible.ts` at line 48, Both fetch calls in the
anthropic-compatible provider (describeImage and call) can hang; add a timeout
using AbortController and apply it to both functions (or import and reuse the
existing fetchWithTimeout helper introduced for minimax.ts) so every fetch is
aborted after a configured timeout. Specifically, update describeImage and call
to create an AbortController, start a timer that calls controller.abort() after
the desired timeout, pass signal: controller.signal into the fetch options,
clear the timer on success/failure, and surface a clear timeout error; prefer
reusing the shared fetchWithTimeout helper if available to avoid duplication.
18c7c6b to
f246283
Compare
|
@coderabbitai Thanks for the review. Both issues have been addressed in the latest commit (
Re: fetch timeout — This is intentionally deferred to #379 ( |
|
Tip For best results, initiate chat on the files or code changes.
Both changes look great based on the summary:
The fetch-timeout deferral to (◕‿◕✿) 🐇 |
Add support for Kimi for Coding (Moonshot AI Coding Plan) via their Anthropic-compatible endpoint at https://api.kimi.com/coding. Key points: - Requires whitelisted User-Agent (KimiCLI/1.5) to avoid HTTP 429 "engine overloaded" errors. - Extracts shared AnthropicCompatibleProvider base class to eliminate ~60 lines of duplication with MinimaxProvider. - Adds describeImage support that MinimaxProvider was missing. Env vars: KIMI_API_KEY (required) KIMI_BASE_URL (optional, default: https://api.kimi.com/coding) KIMI_MODEL (optional, default: kimi-k2) Tests: - test/kimi-for-coding-provider.test.ts — base URL resolution - test/kimi-for-coding-e2e.test.ts — request shape + error handling Signed-off-by: beyond-infra <beyond.infra.github@gmail.com>
f246283 to
5af5cd8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/config.ts`:
- Around line 90-96: The default model for the KIMI provider is incorrect: when
hasRealValue(env["KIMI_FOR_CODING_API_KEY"]) yields true, the code returns
model: env["KIMI_FOR_CODING_MODEL"] || "kimi-for-coding" which contradicts the
PR spec; change the fallback to "kimi-k2" so the returned object (provider:
"kimi-for-coding", model: env["KIMI_FOR_CODING_MODEL"] || "kimi-k2", maxTokens)
uses the documented default model identifier; update only that default string
where env["KIMI_FOR_CODING_MODEL"] is used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ac10ab94-274a-46af-a51e-8c6c1e2aeffe
📒 Files selected for processing (8)
src/config.tssrc/providers/anthropic-compatible.tssrc/providers/index.tssrc/providers/kimi-for-coding.tssrc/providers/minimax.tssrc/types.tstest/kimi-for-coding-e2e.test.tstest/kimi-for-coding-provider.test.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- src/types.ts
- src/providers/kimi-for-coding.ts
- src/providers/index.ts
- test/kimi-for-coding-e2e.test.ts
- src/providers/anthropic-compatible.ts
- test/kimi-for-coding-provider.test.ts
- src/providers/minimax.ts
| if (hasRealValue(env["KIMI_FOR_CODING_API_KEY"])) { | ||
| return { | ||
| provider: "kimi-for-coding", | ||
| model: env["KIMI_FOR_CODING_MODEL"] || "kimi-for-coding", | ||
| maxTokens, | ||
| }; | ||
| } |
There was a problem hiding this comment.
Incorrect default model name contradicts PR objectives.
Line 93 sets the default model to "kimi-for-coding", but the PR objectives explicitly state: "KIMI_FOR_CODING_MODEL — optional, default kimi-k2". This mismatch would cause API requests to fail if the wrong model identifier is used.
🐛 Proposed fix to align with documented default
if (hasRealValue(env["KIMI_FOR_CODING_API_KEY"])) {
return {
provider: "kimi-for-coding",
- model: env["KIMI_FOR_CODING_MODEL"] || "kimi-for-coding",
+ model: env["KIMI_FOR_CODING_MODEL"] || "kimi-k2",
maxTokens,
};
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (hasRealValue(env["KIMI_FOR_CODING_API_KEY"])) { | |
| return { | |
| provider: "kimi-for-coding", | |
| model: env["KIMI_FOR_CODING_MODEL"] || "kimi-for-coding", | |
| maxTokens, | |
| }; | |
| } | |
| if (hasRealValue(env["KIMI_FOR_CODING_API_KEY"])) { | |
| return { | |
| provider: "kimi-for-coding", | |
| model: env["KIMI_FOR_CODING_MODEL"] || "kimi-k2", | |
| maxTokens, | |
| }; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/config.ts` around lines 90 - 96, The default model for the KIMI provider
is incorrect: when hasRealValue(env["KIMI_FOR_CODING_API_KEY"]) yields true, the
code returns model: env["KIMI_FOR_CODING_MODEL"] || "kimi-for-coding" which
contradicts the PR spec; change the fallback to "kimi-k2" so the returned object
(provider: "kimi-for-coding", model: env["KIMI_FOR_CODING_MODEL"] || "kimi-k2",
maxTokens) uses the documented default model identifier; update only that
default string where env["KIMI_FOR_CODING_MODEL"] is used.
|
@coderabbitai Thanks for the review. Re: default model — we intentionally use as the fallback, not . This matches the upstream pi-mono project's model registry (see ), where is the default model ID for the provider. and are alternative models in the same provider family. The PR description has been updated to reflect this. |
|
Tip For best results, initiate chat on the files or code changes.
Noted and recorded below. (◕‿◕✿) 🐇 ✏️ Learnings added
|
- graph-extraction.ts: enforce attribute-based XML format for LLMs that default to nested tags (e.g. kimi-for-coding). Add CRITICAL instruction and explicit ban on <id>, <name>, <type> child tags. - local.ts: prefer local models, disable remote fetches to support air-gapped or proxy-restricted environments. - viewer/index.html: include KIMI_FOR_CODING_API_KEY in provider key hints and update embedding provider guidance.
Add ARCHITECTURE.md with ASCII diagrams covering:
- Overall system architecture (3-tier: Claude Code / Worker / iii-engine)
- Data flow: write path (Hook → Compress → Index → Store)
read path (MCP → Hybrid Search → Enrich → Return)
- Index building: BM25 + Vector (384-dim) + Graph extraction
- Triple-stream search: BM25 + Vector + Graph with RRF fusion
- Claude Code integration points (SessionStart/ToolUse/PostToolUse/PreToolUse/SessionEnd)
- Component interaction diagram
…ed visual hierarchy - Replace brutalist hard borders with soft shadows and rounded corners - Add CSS variables for shadows (--shadow-sm/md/lg/xl) and border radius - Modernize color palette with softer tones and better contrast - Improve header with glassmorphism backdrop-filter effect - Redesign stat cards with hover animations and accent top border - Update badges with pill shapes, subtle backgrounds, and hover effects - Enhance tables with rounded headers, hover states, and better spacing - Add hover effects to cards, timeline items, and activity feed items - Improve graph controls with grouped container and better tooltips - Modernize modal with backdrop blur and larger border radius - Update dark mode with deeper backgrounds and refined shadows - Add smooth transitions throughout for better interactivity
UI ImprovementsUpdated the viewer UI with a modernized visual design: Changes
All existing functionality is preserved. Purely visual/CSS improvements. |
|
Closing this PR. Will reopen with a cleaner approach. |
Summary
Add support for Kimi for Coding (Moonshot AI Coding Plan) via their Anthropic-compatible endpoint at
https://api.kimi.com/coding.Key Changes
kimi-for-codingwithKIMI_FOR_CODING_API_KEYenv varAnthropicCompatibleProviderto eliminate ~60 lines of duplication withMinimaxProviderKimiCLI/1.5describeImagesupport: Added to bothKimiForCodingProviderandMinimaxProvider(was missing)Env Vars
KIMI_FOR_CODING_API_KEYKIMI_FOR_CODING_BASE_URLhttps://api.kimi.com/codingKIMI_FOR_CODING_MODELkimi-k2Tests
test/kimi-for-coding-provider.test.ts— base URL resolution (default + env override)test/kimi-for-coding-e2e.test.ts— mock fetch verifies headers, body shape, and error handlingCompatibility Notes
This PR touches
src/types.ts(ProviderType) andsrc/providers/index.ts(createBaseProvider), which may conflict with other open provider PRs:If any of these merge first, this PR will need a rebase.
Additionally, #379 (AbortController timeout) adds
fetchWithTimeouttominimax.ts. Since this PR extracts a sharedAnthropicCompatibleProviderbase class, the timeout logic from #379 should ideally be merged into the base class rather than per-provider. Happy to coordinate with #379's author if both PRs are accepted.Verification
npm run buildpassesSummary by CodeRabbit
New Features
Refactor
Tests
Documentation
Style