Skip to content

Commit c8e9bec

Browse files
feat(spec, plugin-chatbot): AI model entries carry an optional tierLabel, and the closed model picker shows it (#37519)
Fixes #35578 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:AI 对话的模型选择器在收起时,若服务端给出了档位名,只显示「快速」这样的档位名,而不再显示被截断的「Fast · Claude Haiku…」;展开列表不变。今天云端尚未提供档位名,所以用户暂时看不到差别。 - 为什么做:属于 AI 对话界面体验收尾,替模型选择器收起时文字被截断的问题解决;档位名由云端 AI 服务填写,另起一张云端卡跟进。 - 出错会怎样:最坏情况是收起的选择器显示档位名不对或仍显示完整名称,不影响所选模型与发送;可直接撤回本次合并。 - 要你做什么:无。 ## What changes - **Spec** (`packages/spec/src/api/protocol.zod.ts`): the object arm of the `AiModelsResponseSchema` model entry gains an optional `tierLabel`, a non-empty string naming the model's tier alone, in the language the response is served in. Nothing else in the schema moves; the bare-string arm stays. - Name precedent: a `NOUNLabel` display string next to a plain `label`, as with `pluralLabel` beside `label` on object definitions (`packages/spec/src/data`) and `confirmLabel` and `addLabel` in the UI schemas. It is a display string, not a tier id. The tier word is operator text inside cloud's `sys_ai_model.label` (cloud ADR-0028 D5, D8; not the plan tiers on `available_for_plans`), so an id would make the open-source console carry cloud's tier names and their translations. `label` is already a server-supplied display string, so a sibling display string keeps the producer and the consumer as they are today. - `.min(1)`: an empty tier name is not spec-legal. This follows the `costMultiplier` precedent, where the spec states the domain and the console keeps the value only as the spec declares it. - **Console** (`ui/packages/plugin-chatbot`): - `ChatbotModelOption.tierLabel?` is added. - `useAiModels` keeps a served `tierLabel` only when it is a non-empty string, mirroring `costMultiplierOf`. - `ModelPicker`'s closed trigger shows `tierLabel` when the model in force carries one, and otherwise shows `label` (then the id) as before. The trigger's `title` and the open list's row keep the full `label`, so the model's name is still on hover and the choice is still made from the full names. - Every chat host renders this one picker: the full-page AI chat, the chat dock and the Studio copilot. - Docs: `content/docs/frontend/plugins/plugin-chatbot.mdx` gains one sentence under **Model Picker** (the closed picker shows `tierLabel` when served), per the `ui/` docs-driven rule. This page is outside the claim's declared file surface, and the report names the addition. - Generated: `content/docs/references/api/protocol.mdx`, regenerated by `gen:docs`. No other artefact went stale (`check:generated`: all 14 up to date). - Changeset `.changeset/35578-model-tier-label.md`, `patch` on `@objectstack/spec` and `@object-ui/plugin-chatbot` (the kind is `none`). - Out of scope, per the card's route: step 2, cloud `service-ai` filling `tierLabel`. The seat files that cloud card. Until it lands, the picker looks as it does today. **Read first, by risk:** 1. `ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx`, the `inForce` / `shown` pair in `ModelPicker`. The trigger's text and its `title` now come from different values. 2. `packages/spec/src/api/protocol.zod.ts`, the `tierLabel` line in the model entry. This is the contract addition the L2 review weighs. 3. `ui/packages/plugin-chatbot/src/useAiModels.ts`, `tierLabelOf` in `normalize`. ## Tests Code and tests measured at `8a2ba56c`. The head `02da5d4e` adds only the docs sentence, after which the 28 derived doc-reading families were re-run at `02da5d4e`, all with exit 0. - `packages/spec/src/api/protocol.test.ts` ("validates AI operations"): an entry with `tierLabel` parses and keeps the key. `''`, `3` and `null` are refused. - `ChatbotEnhanced.modelPicker-11865.test.tsx`, a new top-level describe in the picker's shared harness: - a model with a tier name: the trigger reads the tier name only, its `title` is the full label, and the list rows are unchanged; - a model without one: the trigger reads its label, as before; - a pick from the list still writes the model id. - `useAiModels.noAiService-12508.test.tsx`, a new top-level describe: a served non-empty `tierLabel` is kept. It is left off an entry with none, with `''`, or with a number. <details><summary>Local runs (exit captured before any pipe; lock VERDICT lines)</summary> - `pnpm --filter @objectstack/spec test && pnpm --filter @objectstack/spec typecheck`: VERDICT command-exit 0. Test Files 898 passed (898), Tests 28488 passed, 1 todo. `check:test-typecheck: OK`. - `pnpm --filter @object-ui/plugin-chatbot test && pnpm --filter @object-ui/plugin-chatbot type-check`: VERDICT command-exit 0. Test Files 103 passed (103), Tests 1079 passed (1079). This ran after building the package's dependency closure (`turbo run build --filter=@object-ui/plugin-chatbot^...`, 53 tasks, exit 0). The first run, before that build, failed 72 files on an unresolved `@objectstack/formula`, a missing dist rather than this diff. - `pnpm --filter @objectstack/spec check:generated`: exit 1 before `gen:docs` (only `content/docs/references/**` was stale) and exit 0 after it ("All 14 generated artifacts are up to date"). - eslint over the six changed source files: exit 0, 0 errors. The 13 warnings are in lines this diff does not touch. </details> <details><summary>Ablations (scripts/ablation-replace.mjs; each leg landed on disk and restored to the HEAD blob)</summary> - `ModelPicker`: `shown` was replaced by `inForce`. Exactly one test went red ("a model with a tier name: the trigger reads the tier name only…"), with 19 passed: the fallback rows stay green. Restored: the blob equals HEAD (`76aa66d3d4e8`). - `useAiModels`: `tierLabel` was forced to `undefined`. The tier-name pin went red, with 3 passed. Restored: the blob equals HEAD (`0137560494e6`). - Spec: `.min(1)` was dropped. Red with `tierLabel "" is refused: expected true to be false`, 266 passed. Restored: the blob equals HEAD (`1c68b3370e1d`). </details> <details><summary>Derived gate families (dispatch-gates --commands, reconciled with --ran)</summary> - `dispatch-gates --ran`: 117 derived families accounted for. 113 ran, all with exit 0. 4 are NOT MEASURED (exit 3, a prerequisite this shared box lacks): - `check-plugin-teardown-shape.mjs --self-test`: the checkout is shallow and cannot reach the pinned fixture commit; - `spec check:skill-examples`: `packages/client-react/dist` is unbuilt, and the build could not take the shared lock (queue-timeout behind another session's dogfood run); - `check:dual-build-cjs-loads`: many packages have no dist; - `check:type-check-debt`: its re-measure build hit the lock queue-timeout. CI measures all four. - Local-only family `check-dev-prereqs.mjs`: exit 1, because packages across the workspace are unbuilt on this box. That is local state, outside this diff. - `check:skill-frame-freshness`: exit 0. - The reconciliation printed a STALE TREE note: origin/main moved 7 commits during the run, and the 3 changed files were all `scripts/pm/*`, none read by these paths. </details> ## Acceptance notes - **The key lands before its producer.** The dispatch leaves that judgement to the L2 contract review. Until cloud `service-ai` writes `tierLabel`, no response carries it, so the change is inert at runtime. Both sides are pinned: tiered, and untiered as before. - **Display string vs tier id.** The card allowed either. A display string was chosen for the reasons under What changes: the tier vocabulary is cloud's, and the console then needs no closed tier enum and no translations for it. The contract review on this head kept `tierLabel` (7190559193). Step 2, cloud fills it: objectstack-ai/cloud#5022. - The trigger's `title` stays the full `label`. Before this change it equalled the trigger text, and with a tier name the two now differ on purpose. ## Verification Two-minute check: `pnpm --filter @object-ui/plugin-chatbot exec vitest run --root ../.. packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.modelPicker-11865.test.tsx`. Expect 20 passed, including "the closed picker shows the tier name alone when the model carries one". ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; eslint over the changed files has 0 errors (the repo-wide `pnpm lint` is CI's run). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [ ] The *Before Submitting* list in CONTRIBUTING.md is done, except the repo-wide `pnpm lint`, which is CI's run. Dispatched by repo:objectstack#6 (claim comment 7184739601), session `session_01Q4EjjQkY5yXZrN9BEA3rEK`. --- _Generated by [Claude Code](https://claude.ai/code/session_01Q4EjjQkY5yXZrN9BEA3rEK)_ <!-- signed: repo:objectstack#6 · hotlong · session_01Q4EjjQkY5yXZrN9BEA3rEK --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 276174a commit c8e9bec

9 files changed

Lines changed: 111 additions & 3 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@object-ui/plugin-chatbot': patch
4+
---
5+
6+
feat(spec, plugin-chatbot): an AI model entry may carry its tier name, and the closed model picker shows it alone
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
- **`AiModelsResponseSchema`** (`@objectstack/spec`): the model entry gains an optional `tierLabel`, a non-empty string naming the model's tier alone (for example `Fast`), in the language the response is served in. Nothing is removed or narrowed; the bare-string model entry stays, and an entry without `tierLabel` parses as before.
12+
- **The closed model picker** (`@object-ui/plugin-chatbot`, so the full-page AI chat, the console chat dock and the Studio copilot): when the model in force carries a `tierLabel`, the closed picker reads that tier name only, instead of the longer `label` that may also name the model (`Fast · Claude Haiku 5.5`). The full `label` stays the picker's tooltip and the text of its row in the open list, where the choice is made. A model without one shows its `label`, as before. `ChatbotModelOption` gains the optional `tierLabel`, and `useAiModels` keeps a served `tierLabel` only when it is a non-empty string.
13+
- The tier name is filled by the AI service that answers `GET /api/v1/ai/models` (cloud `service-ai`); until it does, the picker looks as it does today.

‎content/docs/frontend/plugins/plugin-chatbot.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ const schema: ChatbotSchema = {
168168
the composer shows a model picker. A model whose entry carries a
169169
`costMultiplier` shows it as `×N` beside its label; with the allowance usage
170170
served (`GET /api/v1/ai/usage`) the list notes the share left; a pick at
171-
`×20` or above asks once before it applies
171+
`×20` or above asks once before it applies. Closed, the picker shows the
172+
model's `tierLabel` (its tier name alone) when the entry carries one, and
173+
its `label` otherwise; the open list always shows the `label`
172174
- **Lightweight**: Pure React components with minimal dependencies
173175

174176
## Schema API

‎content/docs/references/api/protocol.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const result = AiAgentCapabilitiesSchema.parse(data);
224224

225225
| Property | Type | Required | Description |
226226
| :--- | :--- | :--- | :--- |
227-
| **models** | `(string \| { id: string; label: string; default: boolean; costMultiplier?: number })[]` | ✅ | Models this system offers |
227+
| **models** | `(string \| { id: string; label: string; tierLabel?: string; default: boolean; … })[]` | ✅ | Models this system offers |
228228
| **defaultModel** | `string` | optional | Default model id, when the service reports one |
229229

230230
### Nested Shape: `AiModelsResponse.models[number]`
@@ -233,6 +233,7 @@ const result = AiAgentCapabilitiesSchema.parse(data);
233233
| :--- | :--- | :--- | :--- |
234234
| **id** | `string` | ✅ | Model id |
235235
| **label** | `string` | ✅ | Display label for the picker |
236+
| **tierLabel** | `string` | optional | Display name of the model's tier alone (for example 'Fast'), in the language the response is served in. The closed picker shows it in place of `label`, which may also carry the model's name; the open list keeps `label`. Optional: absent, the picker shows `label` as before. |
236237
| **default** | `boolean` | ✅ | Whether this is the environment default |
237238
| **costMultiplier** | `number` | optional | Factor by which one message on this model draws on the AI allowance, compared with one message on the environment's default model: 20 means one message here uses as much allowance as 20 on the default. Normalised to the default: the entry with `default: true` carries 1, and every other entry carries its model's cost weight divided by the default model's cost weight. Written by cloud service-ai's GET /api/v1/ai/models; absent when the service reports none, and then nothing is shown for it. |
238239

‎packages/spec/src/api/protocol.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ describe('ObjectStack Protocol', () => {
390390
`costMultiplier ${String(bad)} is refused`,
391391
).toBe(false);
392392
}
393+
// objectstack#35578 — the optional tier display name the closed picker shows in place of `label`
394+
const withTier = AiModelsResponseSchema.safeParse({ models: [{ ...entry, tierLabel: '快速' }] });
395+
expect(withTier.success).toBe(true);
396+
expect(withTier.data?.models[0]).toEqual({ ...entry, tierLabel: '快速' });
397+
for (const bad of ['', 3, null]) {
398+
expect(
399+
AiModelsResponseSchema.safeParse({ models: [{ ...entry, tierLabel: bad }] }).success,
400+
`tierLabel ${JSON.stringify(bad)} is refused`,
401+
).toBe(false);
402+
}
393403

394404
// conversations
395405
expect(CreateAiConversationRequestSchema.safeParse({ title: 'Q3 pipeline', metadata: { source: 'sdk' } }).success).toBe(true);

‎packages/spec/src/api/protocol.zod.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,11 @@ export const AiModelsResponseSchema = lazySchema(() => z.object({
45884588
z.object({
45894589
id: z.string().describe('Model id'),
45904590
label: z.string().describe('Display label for the picker'),
4591+
tierLabel: z.string().min(1).optional().describe(
4592+
"Display name of the model's tier alone (for example 'Fast'), in the language the response is "
4593+
+ "served in. The closed picker shows it in place of `label`, which may also carry the model's name; the "
4594+
+ 'open list keeps `label`. Optional: absent, the picker shows `label` as before.',
4595+
),
45914596
default: z.boolean().describe('Whether this is the environment default'),
45924597
costMultiplier: z.number().positive().optional().describe(
45934598
'Factor by which one message on this model draws on the AI allowance, compared with one message on the '

‎ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,13 @@ export interface ChatbotModelOption {
11941194
* draws it as `×N` beside the label; absent → nothing is drawn.
11951195
*/
11961196
costMultiplier?: number;
1197+
/**
1198+
* objectstack#35578 — the display name of the model's tier alone ('Fast'),
1199+
* `AiModelsResponseSchema`'s `tierLabel`. The closed picker shows it in place
1200+
* of `label`; the open list keeps `label`. Absent → the closed picker shows
1201+
* `label`, as before.
1202+
*/
1203+
tierLabel?: string;
11971204
}
11981205

11991206
/** A record-write card value as a person reads it: nothing, a list, or the value itself. */
@@ -1277,6 +1284,9 @@ function drawnMultiplierOf(model: ChatbotModelOption): number | undefined {
12771284
* dropped. Every chat host renders this picker, so none can skip the question.
12781285
* - objectstack#35445: the closed trigger shows the model's label alone. The
12791286
* multiplier stays on the list rows, where the choice is made.
1287+
* - objectstack#35578: a model that carries a `tierLabel` shows it on the closed
1288+
* trigger in place of its label (the tier name alone); the label stays
1289+
* the trigger's title and the list row's text. Without one, the label as above.
12801290
*/
12811291
function ModelPicker({
12821292
label,
@@ -1304,7 +1314,10 @@ function ModelPicker({
13041314
// now draws it below the threshold or with no multiplier: drop the pick.
13051315
if (confirmingId !== null && confirming === undefined) setConfirmingId(null);
13061316
const at = models.findIndex((m) => m.id === value);
1317+
// The model in force's full name (the title, and the list row's text) and what
1318+
// the closed trigger shows: its tier name alone when it carries one.
13071319
const inForce = at !== -1 ? (models[at].label ?? models[at].id) : value;
1320+
const shown = at !== -1 ? (models[at].tierLabel ?? inForce) : value;
13081321
// The drawn value is already rounded (drawnMultiplierOf); this only spells it,
13091322
// with as many decimals as that rounding kept.
13101323
const multiplierText = (n: number) =>
@@ -1345,7 +1358,7 @@ function ModelPicker({
13451358
nothing else: no provider, no cost figure (the list, where the
13461359
choice is made, carries those). Truncated, with the name on its title. */}
13471360
<SelectValue>
1348-
<span className="truncate" data-testid="model-picker-value">{inForce}</span>
1361+
<span className="truncate" data-testid="model-picker-value">{shown}</span>
13491362
</SelectValue>
13501363
</SelectTrigger>
13511364
<SelectContent>

‎ui/packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.modelPicker-11865.test.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,31 @@ describe('the composer footer reads in one line and names its 「+」 (objectsta
176176
expect(within(trigger).getByTestId('model-picker-value')).toHaveClass('truncate');
177177
});
178178
});
179+
180+
describe('the closed picker shows the tier name alone when the model carries one (objectstack#35578)', () => {
181+
// The composite label cloud serves (tier · model name), beside the tier name alone.
182+
const TIERED = [
183+
{ id: 'haiku', label: 'Fast · Claude Haiku 5.5', tierLabel: 'Fast' },
184+
{ id: 'sonnet', label: 'Advanced · Claude Sonnet 5' },
185+
];
186+
187+
it('a model with a tier name: the trigger reads the tier name only; its full label is the title and the list row', async () => {
188+
const { trigger } = mount('haiku', { models: TIERED });
189+
expect(within(trigger()).getByTestId('model-picker-value').textContent).toBe('Fast');
190+
expect(trigger()).toHaveAttribute('title', 'Fast · Claude Haiku 5.5');
191+
const options = await openPicker(trigger());
192+
expect(options.map((o) => o.textContent)).toEqual(['Fast · Claude Haiku 5.5', 'Advanced · Claude Sonnet 5']);
193+
});
194+
195+
it('a model without one: the trigger reads its label, as before', () => {
196+
const { trigger } = mount('sonnet', { models: TIERED });
197+
expect(within(trigger()).getByTestId('model-picker-value').textContent).toBe('Advanced · Claude Sonnet 5');
198+
expect(trigger()).toHaveAttribute('title', 'Advanced · Claude Sonnet 5');
199+
});
200+
201+
it('picking from the list still writes the model id', async () => {
202+
const { onModelChange, trigger } = mount('haiku', { models: TIERED });
203+
await pick(trigger(), 'Advanced · Claude Sonnet 5');
204+
expect(onModelChange.mock.calls).toEqual([['sonnet']]);
205+
});
206+
});

‎ui/packages/plugin-chatbot/src/__tests__/useAiModels.noAiService-12508.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,27 @@ describe('useAiModels — a 501 means no AI service for the session (objectui#12
8888
hook.unmount();
8989
});
9090
});
91+
92+
describe('useAiModels — a served tier name reaches the picker as the spec declares it (objectstack#35578)', () => {
93+
it('keeps a non-empty `tierLabel`, and leaves it off an entry that has none or an off-spec one', async () => {
94+
answer = () =>
95+
json(200, {
96+
models: [
97+
{ id: 'haiku', label: 'Fast · Claude Haiku 5.5', default: true, tierLabel: 'Fast' },
98+
{ id: 'sonnet', label: 'Advanced · Claude Sonnet 5', default: false },
99+
{ id: 'blank', label: 'Blank', default: false, tierLabel: '' },
100+
{ id: 'num', label: 'Num', default: false, tierLabel: 3 },
101+
],
102+
});
103+
const hook = renderHook(() => useAiModels({ apiBase: API }));
104+
await pastRetries();
105+
106+
expect(hook.result.current.models).toEqual([
107+
{ id: 'haiku', label: 'Fast · Claude Haiku 5.5', tierLabel: 'Fast' },
108+
{ id: 'sonnet', label: 'Advanced · Claude Sonnet 5' },
109+
{ id: 'blank', label: 'Blank' },
110+
{ id: 'num', label: 'Num' },
111+
]);
112+
hook.unmount();
113+
});
114+
});

‎ui/packages/plugin-chatbot/src/useAiModels.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ interface RawModel {
4242
label?: string;
4343
default?: boolean;
4444
costMultiplier?: unknown;
45+
tierLabel?: unknown;
4546
[key: string]: unknown;
4647
}
4748

@@ -69,15 +70,26 @@ function costMultiplierOf(value: unknown): number | undefined {
6970
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : undefined;
7071
}
7172

73+
/**
74+
* objectstack#35578 — `tierLabel` is kept only as the spec declares it
75+
* (`AiModelsResponseSchema`: a non-empty string). Anything else is no tier
76+
* name, so the closed picker shows the label rather than a blank.
77+
*/
78+
function tierLabelOf(value: unknown): string | undefined {
79+
return typeof value === 'string' && value.length > 0 ? value : undefined;
80+
}
81+
7282
function normalize(raw: RawModel[]): ChatbotModelOption[] {
7383
return raw
7484
.filter((m) => typeof m?.id === 'string' && (m.id as string).length > 0)
7585
.map((m) => {
7686
const costMultiplier = costMultiplierOf(m.costMultiplier);
87+
const tierLabel = tierLabelOf(m.tierLabel);
7788
return {
7889
id: m.id as string,
7990
label: m.label || (m.id as string),
8091
...(costMultiplier !== undefined ? { costMultiplier } : {}),
92+
...(tierLabel !== undefined ? { tierLabel } : {}),
8193
};
8294
});
8395
}

0 commit comments

Comments
 (0)