Repository navigation
Conversation
|
@mturac is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughA new ChangesFallback provider per-model resolution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 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)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/providers/index.ts (1)
36-66: ⚖️ Poor tradeoffDeduplicate provider default model literals
Fallback model literals insrc/providers/index.ts(e.g."gpt-4o-mini","claude-sonnet-4-20250514","gemini-2.5-flash","MiniMax-M2.7", and OpenRouter"anthropic/claude-sonnet-4-20250514") repeat the sameenv[...] || ...defaults already set insrc/config.ts, risking drift. Reuse a shared default-model resolution/helper fromsrc/config.ts(or a shared module) instead of redeclaring per-provider defaults.🤖 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/index.ts` around lines 36 - 66, The provider-specific fallback model strings in the switch cases (e.g., the literals "gpt-4o-mini", "claude-sonnet-4-20250514", "gemini-2.5-flash", "MiniMax-M2.7", "anthropic/claude-sonnet-4-20250514") duplicate defaults already defined in src/config.ts and should be replaced by a single shared default resolver; import the shared default map or function from src/config.ts (e.g., DEFAULT_MODELS or getDefaultModel) into src/providers/index.ts and use it in each case instead of hardcoding literals (replace expressions like getEnvVar("OPENAI_MODEL") || "gpt-4o-mini" with getEnvVar("OPENAI_MODEL") || getDefaultModel("openai") or DEFAULT_MODELS.openai), leaving other fields (provider, maxTokens, baseURL) unchanged.
🤖 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/index.ts`:
- Around line 28-74: The switch in providerDefaultConfig (function
providerDefaultConfig) is non-exhaustive and can return undefined for
ProviderType "noop"; add a case for "noop" (returning a valid ProviderConfig) or
add a default/exhaustiveness guard (e.g., a never-typed default that throws) to
ensure a ProviderConfig is always returned; update the switch to include "noop"
(or a default that throws a descriptive error) so TS2366 is resolved and
unsupported providers cannot fall through to undefined.
---
Nitpick comments:
In `@src/providers/index.ts`:
- Around line 36-66: The provider-specific fallback model strings in the switch
cases (e.g., the literals "gpt-4o-mini", "claude-sonnet-4-20250514",
"gemini-2.5-flash", "MiniMax-M2.7", "anthropic/claude-sonnet-4-20250514")
duplicate defaults already defined in src/config.ts and should be replaced by a
single shared default resolver; import the shared default map or function from
src/config.ts (e.g., DEFAULT_MODELS or getDefaultModel) into
src/providers/index.ts and use it in each case instead of hardcoding literals
(replace expressions like getEnvVar("OPENAI_MODEL") || "gpt-4o-mini" with
getEnvVar("OPENAI_MODEL") || getDefaultModel("openai") or
DEFAULT_MODELS.openai), leaving other fields (provider, maxTokens, baseURL)
unchanged.
🪄 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: 978b7347-2c20-45b2-bd80-305aaf75f5a6
📒 Files selected for processing (2)
src/providers/index.tstest/provider-fallback-model.test.ts
| function providerDefaultConfig( | ||
| provider: FallbackConfig["providers"][number], | ||
| maxTokens: number, | ||
| ): ProviderConfig { | ||
| switch (provider) { | ||
| case "openai": | ||
| return { | ||
| provider, | ||
| model: getEnvVar("OPENAI_MODEL") || "gpt-4o-mini", | ||
| maxTokens, | ||
| baseURL: getEnvVar("OPENAI_BASE_URL"), | ||
| }; | ||
| case "minimax": | ||
| return { | ||
| provider, | ||
| model: getEnvVar("MINIMAX_MODEL") || "MiniMax-M2.7", | ||
| maxTokens, | ||
| }; | ||
| case "anthropic": | ||
| return { | ||
| provider, | ||
| model: getEnvVar("ANTHROPIC_MODEL") || "claude-sonnet-4-20250514", | ||
| maxTokens, | ||
| baseURL: getEnvVar("ANTHROPIC_BASE_URL"), | ||
| }; | ||
| case "gemini": | ||
| return { | ||
| provider, | ||
| model: getEnvVar("GEMINI_MODEL") || "gemini-2.5-flash", | ||
| maxTokens, | ||
| }; | ||
| case "openrouter": | ||
| return { | ||
| provider, | ||
| model: | ||
| getEnvVar("OPENROUTER_MODEL") || | ||
| "anthropic/claude-sonnet-4-20250514", | ||
| maxTokens, | ||
| }; | ||
| case "agent-sdk": | ||
| return { | ||
| provider, | ||
| model: "agent-sdk", | ||
| maxTokens, | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Resolve the full ProviderType union and tsconfig strictness to confirm exhaustiveness/compile impact.
echo "=== ProviderType definition ==="
ast-grep --pattern 'export type ProviderType = $$$'
rg -nP '\bProviderType\b\s*=' --type=ts -C2
echo "=== kimi-for-coding provider presence ==="
fd -i kimi --type f
rg -nP 'kimi-for-coding' --type=ts -C1
echo "=== tsconfig return/strict flags ==="
fd -g 'tsconfig*.json' --exec cat {}Repository: rohitg00/agentmemory
Length of output: 1799
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Show src/providers/index.ts around providerDefaultConfig ==="
nl -ba src/providers/index.ts | sed -n '1,220p'
echo "=== Find where providerDefaultConfig is called ==="
rg -n "providerDefaultConfig\s*\(" src/providers/index.ts src -S
echo "=== Find usages of 'noop' in code ==="
rg -n "\"noop\"" src -S
echo "=== Find createBaseProvider signature/handling for noop ==="
rg -n "function\s+createBaseProvider|createBaseProvider\s*\(" src/providers/index.ts src -SRepository: rohitg00/agentmemory
Length of output: 190
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Show src/providers/index.ts around providerDefaultConfig ==="
cat -n src/providers/index.ts | sed -n '1,220p'
echo "=== Find where providerDefaultConfig is called ==="
rg -n "providerDefaultConfig\s*\(" src/providers/index.ts src -S || true
echo "=== Find usages of 'noop' in code ==="
rg -n "\"noop\"" src -S || true
echo "=== Find createBaseProvider signature/handling for noop ==="
rg -n "function\s+createBaseProvider|createBaseProvider\s*\(" src/providers/index.ts src -S || trueRepository: rohitg00/agentmemory
Length of output: 7495
🏁 Script executed:
rg -n "noImplicitReturns|strictNullChecks|noImplicitAny" tsconfig*.json **/tsconfig*.json package.json
ls -laRepository: rohitg00/agentmemory
Length of output: 2581
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== tsconfig.json (relevant compilerOptions) ==="
cat tsconfig.json
echo "=== Any other tsconfig*.json ==="
fd -i "tsconfig*.json" . -a
echo "=== Grep for noImplicitReturns / noImplicitAny ==="
rg -n "noImplicitReturns|noImplicitAny" tsconfig*.json **/tsconfig*.json . || trueRepository: rohitg00/agentmemory
Length of output: 832
🏁 Script executed:
cat package.jsonRepository: rohitg00/agentmemory
Length of output: 2667
🏁 Script executed:
#!/bin/bash
set -euo pipefail
npx tsc -p tsconfig.json --noEmitRepository: rohitg00/agentmemory
Length of output: 50376
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== src/config.ts around the fallback/llm provider config (lines ~110-260) ==="
cat -n src/config.ts | sed -n '110,260p'
echo "=== src/config.ts where fallback providers are assembled (search for 'fallback' and 'providers') ==="
rg -n "FallbackConfig|fallbackConfig|providers:\s*\[|providers\.push|providers\s*:" src/config.ts src -S
echo "=== src/config.ts presence of 'noop' provider in any fallback list ==="
rg -n "\"noop\".*provider|provider:\s*\"noop\"|providers.*\"noop\"" src/config.ts src -SRepository: rohitg00/agentmemory
Length of output: 8225
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== src/config.ts loadFallbackConfig() (around 380-480) ==="
cat -n src/config.ts | sed -n '380,480p'
echo "=== src/config.ts: any mention of kimi-for-coding in fallback config ==="
rg -n "kimi-for-coding" src/config.ts src -S || trueRepository: rohitg00/agentmemory
Length of output: 2192
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== src/types.ts: ProviderConfig and Noop config types ==="
rg -n "export (type|interface) ProviderConfig|interface ProviderConfig|ProviderConfig" src/types.ts
cat -n src/types.ts | sed -n '110,210p'
echo "=== src/types.ts: NoopProvider / ProviderType related types ==="
cat -n src/types.ts | sed -n '130,190p'Repository: rohitg00/agentmemory
Length of output: 5131
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Locate kimi-for-coding provider files ==="
fd -i "kimi" src --type f || true
echo "=== Search for kimi-for-coding references ==="
rg -n "kimi-for-coding" src -S || true
echo "=== Search for KIMI_FOR_CODING_MODEL env var references ==="
rg -n "KIMI_FOR_CODING_MODEL" -S src || true
echo "=== Search for 'KimiForCodingProvider' ==="
rg -n "KimiForCodingProvider" src -S || trueRepository: rohitg00/agentmemory
Length of output: 259
🏁 Script executed:
ls -ლა src/providers
find src/providers -maxdepth 2 -type f -iname '*kimi*' -printRepository: rohitg00/agentmemory
Length of output: 128
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== src/providers directory ==="
ls -la src/providers
echo "=== kimi-related files under src/providers ==="
find src/providers -maxdepth 3 -type f \( -iname '*kimi*' -o -iname '*kimi-for*' \) -print
echo "=== any file names matching 'kimi' under src ==="
find src -maxdepth 5 -type f -iname '*kimi*' -printRepository: rohitg00/agentmemory
Length of output: 1122
🏁 Script executed:
cat tsdown.config.tsRepository: rohitg00/agentmemory
Length of output: 2192
🏁 Script executed:
#!/bin/bash
set -euo pipefail
npx tsc -p tsconfig.json --noEmit --pretty false 2>&1 \
| rg -n "TS2366|providerDefaultConfig|No default config" || trueRepository: rohitg00/agentmemory
Length of output: 197
Fix providerDefaultConfig() non-exhaustive switch causing TS2366
src/providers/index.ts’s providerDefaultConfig() returns ProviderConfig but the switch doesn’t handle ProviderType = ... | "noop", producing TS2366: Function lacks ending return statement. Add a "noop" case (and/or a default exhaustiveness guard like never) so unsupported providers can’t silently return undefined and be skipped by the surrounding try/catch.
🤖 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/index.ts` around lines 28 - 74, The switch in
providerDefaultConfig (function providerDefaultConfig) is non-exhaustive and can
return undefined for ProviderType "noop"; add a case for "noop" (returning a
valid ProviderConfig) or add a default/exhaustiveness guard (e.g., a never-typed
default that throws) to ensure a ProviderConfig is always returned; update the
switch to include "noop" (or a default that throws a descriptive error) so
TS2366 is resolved and unsupported providers cannot fall through to undefined.
|
Thanks @mturac — fallback provider default-model resolution shipped in v0.9.25 (PR #791 + release notes). Same approach: each fallback resolves its own env-driven default (OPENAI_MODEL / GEMINI_MODEL / ANTHROPIC_MODEL / MINIMAX_MODEL / OPENROUTER_MODEL). Closing because the fix is on main. |
Summary
Fixes #778
Validation
git diff --cached --checknpm test -- test/provider-fallback-model.test.tsnpm run buildSummary by CodeRabbit
Tests
Refactor