Skip to content

fix(models): save a typed provider name with the Save button - #969

Merged
agegr merged 1 commit into
agegr:mainfrom
MohammadHijjawi97:fix-custom-provider-rename
Sep 30, 2026
Merged

agegr merged 1 commit into
agegr:mainfrom
MohammadHijjawi97:fix-custom-provider-rename

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown

Fixes #903

Problem

In Settings → Models, editing a custom provider's name and clicking the footer Save didn't persist the new name. The name field lived in ProviderDetail's local state, and only the separate Rename button moved the provider key in the draft. handleSave serialized the draft as-is.

Changes

  • The provider name field is now a draft owned by ModelsConfig. Save applies a pending name through the same path as Rename before writing models.json, so the enabledModels resync still receives the provider rename (and model renames under the new id).
  • The move and its rename tracking are extracted into a pure renameProviderEntry() helper in models-config-helpers.ts. It also refuses a name that another provider already has; previously Rename would silently overwrite that provider. Rename and Save now show a models.providerNameTaken error instead (en / zh-CN / zh-TW). This guard goes a little beyond the issue, so I can drop it if you'd prefer a narrower change.
  • The Rename button works as before.

Testing

  • New unit tests for renameProviderEntry, plus a source check that Save applies the pending name (components/ModelsConfig.test.mjs). Source assertions in components/EnabledModelsSection.test.mjs are updated to follow the moved code. The new tests fail without the change.
  • node --experimental-strip-types --test lib/i18n/*.test.mjs components/EnabledModelsSection.test.mjs components/ModelsConfig.test.mjs components/SettingsPanel.test.mjs: all pass.
  • tsc --noEmit and eslint on the changed files: clean.
  • Manually (next dev with a scratch PI_CODING_AGENT_DIR): renamed a provider in the field, clicked Save without Rename, and models.json contained the new name.

Note: demo/components/ModelsConfig.tsx is a hand-copied snapshot and still has the old behaviour. I left it unchanged.

The provider name field kept its value in ProviderDetail's local state,
and only the separate Rename button moved the provider in the draft. The
footer Save serialized the draft as-is, so a name typed without pressing
Rename was silently dropped.

The field now edits a draft owned by ModelsConfig. Save applies a pending
name through the same path as Rename before writing models.json, so the
enabledModels resync still receives the provider rename (and any model
renames under the new id). The move itself lives in renameProviderEntry(),
which also refuses an id another provider already has instead of letting
Object.fromEntries replace that provider; Rename and Save report it.

Fixes agegr#903

agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Reviewed. #903 reproduces on main: the name field is local state in ProviderDetail, and handleSave serializes config without it, so only Rename ever moved the key.

What I checked:

  • Save path. Save now goes through the same renameProviderEntry() path as Rename. It keeps the renamesRef / savedModelIdsRef bookkeeping that the enabledModels resync depends on. collectModelRenames(), savedProviders and savedModelIds are computed from the renamed draft, not the stale config, which is what makes the resync see the move.
  • Duplicate-name guard. Keep it. The old Object.fromEntries path silently dropped the other provider when the new id already existed.
  • Deleted provider. deleteProvider clears a pending draft for that provider, so Save can't resurrect a name for a provider that's gone.

Merged locally with current main (clean): tsc --noEmit, eslint, and the full unit suite (1327/1327) pass. LGTM 👍


Generated by Claude Code

@agegr
agegr merged commit bd85004 into agegr:main Sep 30, 2026
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…#907 agegr#941 agegr#946 agegr#961 agegr#968 agegr#969 agegr#1007 agegr#1008 agegr#1009 agegr#1010)

上游已把我们提前摘取的 agegr#884 / agegr#871 / agegr#996 / agegr#961 原样合并(agegr#961 逐字节相同),
agegr#967 与 agegr#963 由上游的 agegr#1009 / agegr#1008 接管。

冲突解决:
- demo/ 对齐上游 fe288c0,撤销 agegr#963 对 demo 的两处改动(`@/lib/chat-phase-label`
  在 demo/lib 下不存在,会打断 Pages 构建)。
- AGENTS.md:保留我们的 default-project 条目,open-folder 换成上游的
  open-in-explorer。
- MessageView.tsx / SessionSidebar.tsx / FileExplorer.tsx:以上游为准,
  DismissButton 采用上游的独立文件,保留我们的思考卡片与文件管理改动。
- SessionSidebar 移除引用已删函数的旧 agegr#951 工作区按钮(agegr#951 的其他入口另行收尾)。
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
The provider name field kept its value in ProviderDetail's local state,
and only the separate Rename button moved the provider in the draft. The
footer Save serialized the draft as-is, so a name typed without pressing
Rename was silently dropped.

The field now edits a draft owned by ModelsConfig. Save applies a pending
name through the same path as Rename before writing models.json, so the
enabledModels resync still receives the provider rename (and any model
renames under the new id). The move itself lives in renameProviderEntry(),
which also refuses an id another provider already has instead of letting
Object.fromEntries replace that provider; Rename and Save report it.

Fixes agegr#903
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
The provider name field kept its value in ProviderDetail's local state,
and only the separate Rename button moved the provider in the draft. The
footer Save serialized the draft as-is, so a name typed without pressing
Rename was silently dropped.

The field now edits a draft owned by ModelsConfig. Save applies a pending
name through the same path as Rename before writing models.json, so the
enabledModels resync still receives the provider rename (and any model
renames under the new id). The move itself lives in renameProviderEntry(),
which also refuses an id another provider already has instead of letting
Object.fromEntries replace that provider; Rename and Save report it.

Fixes agegr#903
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.

Bug: Custom Provider name change is not saved by the Save button

2 participants