♻️ refactor(locales): split model-runtime errors into modelRuntime namespace#15269
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
bf71dc4 to
77fc962
Compare
9d3d23a to
3052f04
Compare
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
3052f04 to
e1bbc80
Compare
…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>
e1bbc80 to
d1b418a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💻 Change Type
🔗 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 undererror.response.<X>— mixed in one file with HTTP statuses (response.400-524), Plugin* errors, Cloud-only business errors (FreePlanLimit,SubscriptionPlanLimit…), andGoogleAIBlockReason.*subkeys. Theresponse.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
modelRuntimei18next namespace driven byERROR_CODE_SPECS.New files:
src/locales/default/modelRuntime.ts— 34 keys, one perAgentRuntimeErrorType(plus the deprecatedQuotaLimitReachedalias kept for backward compat). Key = bare ErrorCode, noresponse.prefix.locales/en-US/modelRuntime.json— generated.src/utils/locale/runtimeErrorMessage.ts—getRuntimeErrorMessage(t, code, vars). Routes viagetErrorCodeSpec(code): returnst('modelRuntime:<code>')when the code is inERROR_CODE_SPECS, otherwise falls back tot('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.tsso it appears in the typedDefaultResourcesmap.UI consumer migrations (5 dynamic lookup sites):
features/Conversation/Messages/AssistantGroup/Tool/Detail/ErrorResponse.tsxfeatures/Conversation/Error/index.tsxroutes/(main)/settings/provider/features/ProviderConfig/Checker.tsx(also statict('response.ConnectionCheckFailed'))routes/(main)/(create)/video/features/GenerationFeed/VideoErrorItem.tsxroutes/(main)/(create)/image/features/GenerationFeed/GenerationItem/ErrorState.tsxEach consumer adds
'modelRuntime'to itsuseTranslation()namespace list and replacest(\response.${type}`)withgetRuntimeErrorMessage(t, type, vars)`.components/Error/Description.tsx(HTTP status renderer) intentionally stays onresponse.<X>— its inputs are always HTTP status numbers, never runtime ErrorCodes.🧪 How to Test
```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 fromerror.tsare not aliased back underresponse.*after this PR. ThegetRuntimeErrorMessagehelper handles the routing so consumers don't see the difference. If any third-party code reaches intodefaultErrorLocale['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.jsonis generated by this PR.pnpm i18nwill 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 tocanary(or rebase manually).🤖 Generated with Claude Code