Skip to content

♻️ refactor(locales): split model-runtime errors into modelRuntime namespace#15269

Merged
arvinxx merged 1 commit into
canaryfrom
arvinxu/feat/i18n-modelRuntime-namespace
May 28, 2026
Merged

♻️ refactor(locales): split model-runtime errors into modelRuntime namespace#15269
arvinxx merged 1 commit into
canaryfrom
arvinxu/feat/i18n-modelRuntime-namespace

Conversation

@arvinxx

@arvinxx arvinxx commented May 27, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

Stacks on top of #15262. Base this PR there until #15262 merges, then it auto-rebases onto canary.

🔀 Description of Change

Until now every runtime error code (InvalidProviderAPIKey, ProviderBizError, ExceededContextWindow, …) lived under error.response.<X> — mixed in one file with HTTP statuses (response.400-524), Plugin* errors, Cloud-only business errors (FreePlanLimit, SubscriptionPlanLimit…), and GoogleAIBlockReason.* subkeys. The response. prefix is a lobehub-specific convention with no relationship to the underlying ErrorCode, which is awkward for external consumers and noisy for maintainers.

This PR carves out a dedicated modelRuntime i18next namespace driven by ERROR_CODE_SPECS.

New files:

  • src/locales/default/modelRuntime.ts — 34 keys, one per AgentRuntimeErrorType (plus the deprecated QuotaLimitReached alias kept for backward compat). Key = bare ErrorCode, no response. prefix.
  • locales/en-US/modelRuntime.json — generated.
  • src/utils/locale/runtimeErrorMessage.tsgetRuntimeErrorMessage(t, code, vars). Routes via getErrorCodeSpec(code): returns t('modelRuntime:<code>') when the code is in ERROR_CODE_SPECS, otherwise falls back to t('response.<code>').

Pruned files:

  • src/locales/default/error.ts — model-runtime keys removed. The file retains HTTP statuses, Plugin* errors, Cloud-only business errors, GoogleAIBlockReason.*, and UI-flow strings.
  • locales/en-US/error.json — regenerated.

Registered the new namespace in src/locales/default/index.ts so it appears in the typed DefaultResources map.

UI consumer migrations (5 dynamic lookup sites):

  • features/Conversation/Messages/AssistantGroup/Tool/Detail/ErrorResponse.tsx
  • features/Conversation/Error/index.tsx
  • routes/(main)/settings/provider/features/ProviderConfig/Checker.tsx (also static t('response.ConnectionCheckFailed'))
  • routes/(main)/(create)/video/features/GenerationFeed/VideoErrorItem.tsx
  • routes/(main)/(create)/image/features/GenerationFeed/GenerationItem/ErrorState.tsx

Each consumer adds 'modelRuntime' to its useTranslation() namespace list and replaces t(\response.${type}`)withgetRuntimeErrorMessage(t, type, vars)`.

components/Error/Description.tsx (HTTP status renderer) intentionally stays on response.<X> — its inputs are always HTTP status numbers, never runtime ErrorCodes.

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

```bash
bun run type-check # passes
cd packages/model-runtime && bunx vitest run src/ # 164 files / 3908 pass / 1 skip
```

📸 Screenshots / Videos

N/A (no visual changes — message text identical, only the i18n key path differs).

📝 Additional Information

Migration is forward-only for error.ts: the keys removed from error.ts are not aliased back under response.* after this PR. The getRuntimeErrorMessage helper handles the routing so consumers don't see the difference. If any third-party code reaches into defaultErrorLocale['response.X'] for a model-runtime code, it will break — grep checked and no such consumers were found.

Other locales need regenerating: only en-US/modelRuntime.json is generated by this PR. pnpm i18n will auto-translate to the other 17 locales (slow, calls LLM — left as a separate step).

Note on stacking: while this PR is open against arvinxu/feat/unified-error-codes, the diff only shows the i18n changes. Once #15262 merges, GitHub will auto-retarget the base to canary (or rebase manually).

🤖 Generated with Claude Code

@sourcery-ai sourcery-ai Bot 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.

Sorry @arvinxx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@vercel

vercel Bot commented May 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment May 27, 2026 5:37pm

Request Review

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. i18n labels May 27, 2026
@arvinxx arvinxx force-pushed the arvinxu/feat/unified-error-codes branch from bf71dc4 to 77fc962 Compare May 27, 2026 16:00
@arvinxx arvinxx force-pushed the arvinxu/feat/i18n-modelRuntime-namespace branch from 9d3d23a to 3052f04 Compare May 27, 2026 16:01
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.94%. Comparing base (c4b1475) to head (d1b418a).
⚠️ Report is 1 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15269      +/-   ##
==========================================
- Coverage   70.95%   70.94%   -0.01%     
==========================================
  Files        3160     3161       +1     
  Lines      317287   317232      -55     
  Branches    34491    28754    -5737     
==========================================
- Hits       225127   225075      -52     
+ Misses      91991    91988       -3     
  Partials      169      169              
Flag Coverage Δ
app 61.70% <73.91%> (-0.01%) ⬇️
database 92.22% <ø> (ø)
packages/agent-runtime 80.48% <ø> (ø)
packages/builtin-tool-lobe-agent 19.87% <ø> (ø)
packages/context-engine 84.13% <ø> (ø)
packages/conversation-flow 91.28% <ø> (ø)
packages/file-loaders 87.89% <ø> (ø)
packages/memory-user-memory 74.99% <ø> (ø)
packages/model-bank 99.99% <ø> (ø)
packages/model-runtime 84.55% <ø> (ø)
packages/prompts 72.67% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/types 35.38% <ø> (ø)
packages/utils 88.47% <ø> (ø)
packages/web-crawler 88.08% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 67.71% <ø> (ø)
Services 54.64% <ø> (ø)
Server 72.25% <ø> (+<0.01%) ⬆️
Libs 56.97% <ø> (ø)
Utils 86.02% <92.30%> (+0.08%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arvinxx arvinxx force-pushed the arvinxu/feat/i18n-modelRuntime-namespace branch from 3052f04 to e1bbc80 Compare May 27, 2026 16:26
Base automatically changed from arvinxu/feat/unified-error-codes to canary May 27, 2026 16:55
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 27, 2026
…mespace

Until now, every runtime error code (InvalidProviderAPIKey, ProviderBizError,
ExceededContextWindow, …) lived under `error.response.<X>` — mixed in the
same file with HTTP statuses, Plugin*, Cloud business errors, and
GoogleAIBlockReason subkeys. The `response.` prefix is a lobehub-specific
convention that has nothing to do with the underlying ErrorCode, which
made it awkward for external consumers and noisy for maintainers.

This change carves out a dedicated `modelRuntime` i18next namespace:

- `src/locales/default/modelRuntime.ts` — 34 keys, one per
  `AgentRuntimeErrorType` (or deprecated alias `QuotaLimitReached`).
  Key = the bare ErrorCode (no `response.` prefix).
- `src/locales/default/error.ts` — runtime keys removed. The file keeps
  HTTP statuses (response.400 - response.524), Plugin*, Cloud-only
  business errors (FreePlanLimit, SubscriptionPlanLimit, etc.),
  GoogleAIBlockReason.*, and the various UI-flow strings.
- Registered `modelRuntime` in `src/locales/default/index.ts` so the
  namespace appears in the typed resources map.
- Generated `locales/en-US/modelRuntime.json` + updated
  `locales/en-US/error.json` — other languages need `pnpm i18n`.

New helper `src/utils/locale/runtimeErrorMessage.ts`:

```ts
getRuntimeErrorMessage(t, code, vars)
```

Routes via `getErrorCodeSpec(code)`: returns `t('modelRuntime:<code>')`
when the code is in `ERROR_CODE_SPECS`, otherwise falls back to
`t('response.<code>')`. Callers add `'modelRuntime'` to their
`useTranslation()` namespace list.

UI consumer migrations (5 dynamic lookup sites):

- `features/Conversation/Messages/AssistantGroup/Tool/Detail/ErrorResponse.tsx`
- `features/Conversation/Error/index.tsx`
- `routes/(main)/settings/provider/features/ProviderConfig/Checker.tsx`
  (incl. the static `t('response.ConnectionCheckFailed')` call)
- `routes/(main)/(create)/video/features/GenerationFeed/VideoErrorItem.tsx`
- `routes/(main)/(create)/image/features/GenerationFeed/GenerationItem/ErrorState.tsx`

`Description.tsx` (HTTP status renderer) stays on `response.<X>` since
its inputs are always HTTP status numbers, never runtime ErrorCodes.

Stacks on top of #15262 (the unified errors PR introduces
`getErrorCodeSpec` / `ERROR_CODE_SPECS`); base this PR there until
#15262 merges, then it auto-rebases onto canary.

Tests: lobehub type-check clean; model-runtime 3908 pass / 1 skip / 164 files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@arvinxx arvinxx force-pushed the arvinxu/feat/i18n-modelRuntime-namespace branch from e1bbc80 to d1b418a Compare May 27, 2026 16:58
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels May 27, 2026
@arvinxx arvinxx merged commit 4c29515 into canary May 28, 2026
48 of 50 checks passed
@arvinxx arvinxx deleted the arvinxu/feat/i18n-modelRuntime-namespace branch May 28, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant