@adecore/agents-react 0.74.0 → 0.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,13 @@
1
- import { chipText, tokenizeChips, tokenizeNamedReferences } from '../mentions.js';
1
+ import { chipText, namedChipValue, tokenizeChips, tokenizeNamedReferences } from '../mentions.js';
2
2
  function valueOf(segment) {
3
3
  if (segment.kind === 'mention') {
4
4
  return segment.path;
5
5
  }
6
- if (segment.kind === 'model' || segment.kind === 'account') {
7
- return `${segment.cli}/${segment.id}`;
6
+ if (segment.kind === 'model') {
7
+ return namedChipValue(segment.cli, segment.id, segment.account);
8
+ }
9
+ if (segment.kind === 'account') {
10
+ return namedChipValue(segment.cli, segment.id);
8
11
  }
9
12
  return segment.kind === 'skill' ? segment.name : segment.id;
10
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents-react",
3
- "version": "0.74.0",
3
+ "version": "0.75.0",
4
4
  "description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -72,12 +72,12 @@
72
72
  "test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
73
73
  },
74
74
  "dependencies": {
75
- "@adecore/agent-contracts": "0.74.0",
76
- "@adecore/editor": "0.74.0",
77
- "@adecore/editor-react": "0.74.0",
78
- "@adecore/intelligent-ui": "0.74.0",
79
- "@adecore/merge": "0.74.0",
80
- "@adecore/utils": "0.74.0",
75
+ "@adecore/agent-contracts": "0.75.0",
76
+ "@adecore/editor": "0.75.0",
77
+ "@adecore/editor-react": "0.75.0",
78
+ "@adecore/intelligent-ui": "0.75.0",
79
+ "@adecore/merge": "0.75.0",
80
+ "@adecore/utils": "0.75.0",
81
81
  "@codemirror/commands": "^6.11.2",
82
82
  "@codemirror/language": "^6.13.1",
83
83
  "@codemirror/state": "^6.7.6",
@@ -101,14 +101,14 @@
101
101
  "zustand": "^5.1.0"
102
102
  },
103
103
  "peerDependencies": {
104
- "@adecore/ui": "^0.74.0",
104
+ "@adecore/ui": "^0.75.0",
105
105
  "i18next": "^26.4.2 || ^27.0.0",
106
106
  "react": "^19.3.0",
107
107
  "react-dom": "^19.3.0",
108
108
  "react-i18next": "^17.0.15 || ^18.0.0"
109
109
  },
110
110
  "devDependencies": {
111
- "@adecore/ui": "0.74.0",
111
+ "@adecore/ui": "0.75.0",
112
112
  "@types/bun": "^1.4.5",
113
113
  "@types/react": "^19.3.3",
114
114
  "@types/react-dom": "^19.3.0",
@@ -131,10 +131,14 @@ export type ChipSegment =
131
131
  | { kind: 'mention'; path: string }
132
132
  | { kind: 'skill'; name: string }
133
133
  | { kind: 'reference'; id: string; name: string }
134
- | { kind: 'model'; cli: string; id: string }
134
+ | { kind: 'model'; cli: string; id: string; account?: string }
135
135
  | { kind: 'account'; cli: string; id: string };
136
136
 
137
- /* A model or a provider account, spelled in the text as `@model:<cli>/<id>` or `@account:<cli>/<id>`. */
137
+ /*
138
+ * A model or a provider account, spelled in the text as `@model:<cli>/<id>` or `@account:<cli>/<id>`. A model
139
+ * on one account of its CLI is `@model:<cli>:<account>/<id>`; the account goes before the slash, since an id
140
+ * may hold slashes of its own.
141
+ */
138
142
  export type NamedChipKind = 'model' | 'account';
139
143
 
140
144
  function isBoundary(char: string | undefined): boolean {
@@ -235,6 +239,9 @@ export interface NamedPick {
235
239
  kind: NamedChipKind;
236
240
  cli: string;
237
241
  id: string;
242
+
243
+ /* The account a model runs on, when its CLI has a choice of them. */
244
+ account?: string;
238
245
  }
239
246
 
240
247
  type MentionPick = { kind: 'file'; path: string } | NamedPick;
@@ -316,8 +323,12 @@ export function chipText(segment: ChipSegment): string {
316
323
  return `#${segment.name}`;
317
324
  }
318
325
 
319
- if (segment.kind === 'model' || segment.kind === 'account') {
320
- return namedChipToken(segment.kind, segment.cli, segment.id);
326
+ if (segment.kind === 'model') {
327
+ return namedChipToken('model', segment.cli, segment.id, segment.account);
328
+ }
329
+
330
+ if (segment.kind === 'account') {
331
+ return namedChipToken('account', segment.cli, segment.id);
321
332
  }
322
333
 
323
334
  return segment.text;
@@ -342,23 +353,56 @@ export interface TextRange {
342
353
  to: number;
343
354
  }
344
355
 
345
- /* `value` is the path, the skill's name, a reference's id or a model's or account's `<cli>/<id>`; the range spans the name. */
356
+ /* `value` is the path, the skill's name, a reference's id or a named chip's `namedChipValue`; the range spans the name. */
346
357
  interface ChipRange extends TextRange {
347
358
  kind: 'mention' | 'skill' | 'reference' | NamedChipKind;
348
359
  value: string;
349
360
  }
350
361
 
351
- export function namedChipToken(kind: NamedChipKind, cli: string, id: string): string {
352
- return `@${kind}:${cli}/${id}`;
362
+ /* The token without its `@<kind>:`: `<cli>/<id>`, or `<cli>:<account>/<id>` for a model on one account. */
363
+ export function namedChipValue(cli: string, id: string, account?: string): string {
364
+ return `${namedChipHead(cli, account)}/${id}`;
353
365
  }
354
366
 
355
- /* The part of a named chip its CLI's mark stands in for: `@model:claude/`. */
356
- export function namedChipPrefix(kind: NamedChipKind, cli: string): string {
357
- return `@${kind}:${cli}/`;
367
+ export interface NamedChipParts {
368
+ cli: string;
369
+ id: string;
370
+ account: string | undefined;
358
371
  }
359
372
 
360
- // The id runs to whitespace or a backtick; a slash belongs to it (`openrouter/anthropic/claude`).
361
- const NAMED_CHIP = /@(model|account):([a-z0-9][a-z0-9-]*)\/([^\s`]+)/g;
373
+ /* What a `namedChipValue` holds, or null for one without a CLI. */
374
+ export function namedChipParts(value: string): NamedChipParts | null {
375
+ const slash = value.indexOf('/');
376
+
377
+ if (slash < 1) {
378
+ return null;
379
+ }
380
+
381
+ const head = value.slice(0, slash);
382
+ const colon = head.indexOf(':');
383
+
384
+ return {
385
+ cli: colon < 0 ? head : head.slice(0, colon),
386
+ id: value.slice(slash + 1),
387
+ account: colon < 0 ? undefined : head.slice(colon + 1)
388
+ };
389
+ }
390
+
391
+ function namedChipHead(cli: string, account: string | undefined): string {
392
+ return account === undefined ? cli : `${cli}:${account}`;
393
+ }
394
+
395
+ export function namedChipToken(kind: NamedChipKind, cli: string, id: string, account?: string): string {
396
+ return `@${kind}:${namedChipValue(cli, id, account)}`;
397
+ }
398
+
399
+ /* The part of a named chip its CLI's mark stands in for: `@model:claude/`, or `@model:claude:claude_work/`. */
400
+ export function namedChipPrefix(kind: NamedChipKind, cli: string, account?: string): string {
401
+ return `@${kind}:${namedChipHead(cli, account)}/`;
402
+ }
403
+
404
+ // The id runs to whitespace or a backtick; a slash belongs to it (`openrouter/anthropic/claude`). The account is spelled as `ProviderAccountIdSchema` spells it.
405
+ const NAMED_CHIP = /@(model|account):([a-z0-9][a-z0-9-]*)(?::([a-z][a-z0-9_-]{0,63}))?\/([^\s`]+)/g;
362
406
 
363
407
  // Punctuation after the id ends the sentence, except a `]` that closes a `[` in the id (`claude-opus-5-5[1m]`).
364
408
  function trimmedId(id: string): string {
@@ -381,14 +425,21 @@ export function namedChipRanges(text: string, excluded: readonly TextRange[] = [
381
425
 
382
426
  for (const found of text.matchAll(NAMED_CHIP)) {
383
427
  const from = found.index;
384
- const id = trimmedId(found[3]!);
385
- const to = from + found[0].length - (found[3]!.length - id.length);
428
+ const kind = found[1] as NamedChipKind;
429
+ const account = found[3];
430
+ const id = trimmedId(found[4]!);
431
+ const to = from + found[0].length - (found[4]!.length - id.length);
432
+
433
+ // An account runs on no other account.
434
+ if (id === '' || (kind === 'account' && account !== undefined)) {
435
+ continue;
436
+ }
386
437
 
387
- if (id === '' || (from > 0 && !REFERENCE_OPENER.test(text[from - 1]!)) || excluded.some((range) => from < range.to && to > range.from)) {
438
+ if ((from > 0 && !REFERENCE_OPENER.test(text[from - 1]!)) || excluded.some((range) => from < range.to && to > range.from)) {
388
439
  continue;
389
440
  }
390
441
 
391
- ranges.push({ from, to, kind: found[1] as NamedChipKind, value: `${found[2]}/${id}` });
442
+ ranges.push({ from, to, kind, value: namedChipValue(found[2]!, id, account) });
392
443
  }
393
444
 
394
445
  return ranges;
@@ -474,9 +525,9 @@ function segmentOf(text: string, range: ChipRange): ChipSegment {
474
525
  }
475
526
 
476
527
  if (range.kind === 'model' || range.kind === 'account') {
477
- const slash = range.value.indexOf('/');
528
+ const { cli, id, account } = namedChipParts(range.value)!;
478
529
 
479
- return { kind: range.kind, cli: range.value.slice(0, slash), id: range.value.slice(slash + 1) };
530
+ return range.kind === 'model' && account !== undefined ? { kind: 'model', cli, id, account } : { kind: range.kind, cli, id };
480
531
  }
481
532
 
482
533
  return { kind: 'reference', id: range.value, name: text.slice(range.from + 1, range.to) };
@@ -3,8 +3,9 @@ import { accountName, accountsOfKind, hasAccountChoice, projectOffered, type Acc
3
3
  import { modelRequirementOf } from '../agents/model-requirement';
4
4
  import type { AccountRule } from '../host/host';
5
5
  import type { NamedPick } from './mentions';
6
+ import type { NamedChipHome } from './ui/named-chip-look';
6
7
 
7
- const MODEL_SUGGESTIONS = 5;
8
+ const MODEL_SUGGESTIONS = 8;
8
9
  const ACCOUNT_SUGGESTIONS = 3;
9
10
 
10
11
  export interface ModelSuggestion extends NamedPick {
@@ -12,6 +13,9 @@ export interface ModelSuggestion extends NamedPick {
12
13
  cli: AgentKind;
13
14
  provider: ProviderInfo;
14
15
  model: ModelInfo;
16
+
17
+ /* The name of the account in `account`, which the row reads before the model's. */
18
+ accountName?: string;
15
19
  }
16
20
 
17
21
  export interface AccountSuggestion extends NamedPick {
@@ -56,28 +60,86 @@ export function signedIn(accounts: ProviderAccounts | null, kind: AgentKind): bo
56
60
  return entries.some((entry) => entry.account.enabled !== false && (entry.status === null || !UNUSABLE.has(entry.status.state)));
57
61
  }
58
62
 
63
+ interface ModelAccount {
64
+ id: string;
65
+ name: string;
66
+ }
67
+
68
+ /*
69
+ * The accounts a CLI's models are offered on, the chat's own first: the ready ones the project offers. None
70
+ * while fewer than two are, so a CLI without a choice keeps rows of the model alone.
71
+ */
72
+ function modelAccounts(provider: ProviderInfo, accounts: ProviderAccounts | null, rule: AccountRule | null, home: NamedChipHome | null): ModelAccount[] {
73
+ const entries = accountsOfKind(accounts, provider.kind);
74
+
75
+ if (!hasAccountChoice(entries)) {
76
+ return [];
77
+ }
78
+
79
+ const ready = projectOffered(entries, rule, provider.kind, undefined).filter((entry) => entry.account.enabled !== false && entry.status?.state === 'ready');
80
+
81
+ if (ready.length < 2) {
82
+ return [];
83
+ }
84
+
85
+ const first = home?.provider === provider.kind ? (home.account ?? provider.kind) : undefined;
86
+
87
+ return [...ready.filter((entry) => entry.id === first), ...ready.filter((entry) => entry.id !== first)].map((entry) => ({
88
+ id: entry.id,
89
+ name: accountName(entry, provider.name)
90
+ }));
91
+ }
92
+
59
93
  /*
60
94
  * The models the `@` list offers for a query: of a CLI that is installed, chats and is signed in, and
61
- * that the CLI is new enough for. Legacy models last, at most `MODEL_SUGGESTIONS`. A bare `@` offers none.
95
+ * that the CLI is new enough for. A CLI with a choice of accounts offers a row per account, found by the
96
+ * account's name too, and `<account>/<model>` narrows to both. Legacy models last, at most
97
+ * `MODEL_SUGGESTIONS`. A bare `@` offers none.
62
98
  */
63
99
  export function modelSuggestions(
64
100
  providers: readonly ProviderInfo[],
65
101
  accounts: ProviderAccounts | null,
66
102
  query: string,
67
- reportedOf: (kind: AgentKind) => ReadonlySet<string>
103
+ reportedOf: (kind: AgentKind) => ReadonlySet<string>,
104
+ rule: AccountRule | null = null,
105
+ home: NamedChipHome | null = null
68
106
  ): ModelSuggestion[] {
69
107
  if (query === '') {
70
108
  return [];
71
109
  }
72
110
 
73
- const found = inPickerOrder(providers.filter((entry) => entry.installed && entry.capabilities.chat && signedIn(accounts, entry.kind))).flatMap((provider) =>
74
- provider.models
75
- .filter(
76
- (model) =>
77
- (startsAWord(model.name, query) || startsAWord(model.slug, query)) &&
78
- modelRequirementOf(model, provider, reportedOf(provider.kind)) === null
79
- )
80
- .map((model): ModelSuggestion => ({ kind: 'model', cli: provider.kind, id: model.slug, provider, model }))
111
+ const slash = query.indexOf('/');
112
+ const modelMatches = (model: ModelInfo, words: string): boolean => startsAWord(model.name, words) || startsAWord(model.slug, words);
113
+
114
+ // A slash may belong to a model's id (`openrouter/anthropic/claude`), so the whole query still finds a model.
115
+ const accountMatches = (model: ModelInfo, account: ModelAccount): boolean => {
116
+ if (slash < 0) {
117
+ return startsAWord(account.name, query);
118
+ }
119
+
120
+ const rest = query.slice(slash + 1);
121
+
122
+ return startsAWord(account.name, query.slice(0, slash)) && (rest === '' || modelMatches(model, rest));
123
+ };
124
+
125
+ const found = inPickerOrder(providers.filter((entry) => entry.installed && entry.capabilities.chat && signedIn(accounts, entry.kind))).flatMap(
126
+ (provider) => {
127
+ const offered = modelAccounts(provider, accounts, rule, home);
128
+
129
+ return provider.models
130
+ .filter((model) => modelRequirementOf(model, provider, reportedOf(provider.kind)) === null)
131
+ .flatMap((model): ModelSuggestion[] => {
132
+ const row: ModelSuggestion = { kind: 'model', cli: provider.kind, id: model.slug, provider, model };
133
+
134
+ if (offered.length === 0) {
135
+ return modelMatches(model, query) ? [row] : [];
136
+ }
137
+
138
+ return offered
139
+ .filter((account) => modelMatches(model, query) || accountMatches(model, account))
140
+ .map((account) => ({ ...row, account: account.id, accountName: account.name }));
141
+ });
142
+ }
81
143
  );
82
144
 
83
145
  return [...found.filter((entry) => !entry.model.legacy), ...found.filter((entry) => entry.model.legacy)].slice(0, MODEL_SUGGESTIONS);
@@ -1,33 +1,33 @@
1
1
  import type { AgentKind } from '@adecore/agent-contracts';
2
2
  import { CliMark } from '../../agents/AgentModelLabel';
3
- import { namedChipPrefix, type NamedChipKind } from '../mentions';
3
+ import { namedChipParts, namedChipPrefix, type NamedChipKind } from '../mentions';
4
4
  import { REFERENCE_TONE, TOKEN_ICON_BOX } from './chips';
5
5
  import { useNamedChipLookup } from './named-chip-look';
6
6
  import { TokenChip } from './ReferenceChip';
7
7
 
8
8
  /*
9
9
  * A model or an account a message names, under its CLI's mark in the color of the account it runs on, and
10
- * the name the machine knows it by. An id the machine does not know keeps the id. A copy reads the token.
10
+ * the name the machine knows it by, after its account's when it names one. An id the machine does not know
11
+ * keeps the id. A copy reads the token.
11
12
  */
12
13
  export function NamedChip({ kind, value }: { kind: NamedChipKind; value: string }) {
13
14
  const lookup = useNamedChipLookup();
14
- const slash = value.indexOf('/');
15
- const cli = value.slice(0, slash);
16
- const id = value.slice(slash + 1);
17
- const { label, color } = lookup(kind, cli, id);
15
+ const { cli, id, account } = namedChipParts(value) ?? { cli: '', id: value, account: undefined };
16
+ const look = lookup(kind, cli, id, account);
18
17
 
19
18
  return (
20
19
  <TokenChip
21
20
  kind={kind}
22
21
  value={value}
23
- sigil={namedChipPrefix(kind, cli)}
22
+ sigil={namedChipPrefix(kind, cli, account)}
24
23
  icon={
25
- <span className={TOKEN_ICON_BOX} style={color === undefined ? undefined : { color }}>
24
+ <span className={TOKEN_ICON_BOX} style={look.color === undefined ? undefined : { color: look.color }}>
26
25
  <CliMark kind={cli as AgentKind} size={14} />
27
26
  </span>
28
27
  }
29
- label={label}
30
- spelled={label === id ? undefined : id}
28
+ label={look.label}
29
+ prefix={look.account}
30
+ spelled={look.label === id ? undefined : id}
31
31
  tone={REFERENCE_TONE}
32
32
  />
33
33
  );
@@ -18,6 +18,8 @@ interface TokenChipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children
18
18
  sigil?: string;
19
19
  icon: ReactNode;
20
20
  label: string;
21
+ /* Muted words read before the label, such as the account a model runs on. A selection copies the sigil instead. */
22
+ prefix?: string;
21
23
  /* What a selection copies in place of a label that is not the text, such as a model's id under its name. */
22
24
  spelled?: string;
23
25
  tone: string;
@@ -29,7 +31,7 @@ interface TokenChipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children
29
31
  * since a button is a box with a baseline of its own and would not sit on the line the others sit on.
30
32
  * It stays out of prose, whose margins on an image would lift a host's picture mark off the line.
31
33
  */
32
- export function TokenChip({ kind, value, sigil, icon, label, spelled, tone, onOpen, className, ...rest }: TokenChipProps) {
34
+ export function TokenChip({ kind, value, sigil, icon, label, prefix, spelled, tone, onOpen, className, ...rest }: TokenChipProps) {
33
35
  const onKeyDown = (e: KeyboardEvent<HTMLSpanElement>): void => {
34
36
  if (onOpen !== undefined && (e.key === 'Enter' || e.key === ' ')) {
35
37
  e.preventDefault();
@@ -57,6 +59,7 @@ export function TokenChip({ kind, value, sigil, icon, label, spelled, tone, onOp
57
59
  >
58
60
  {icon}
59
61
  {sigil !== undefined && <span className="sr-only">{sigil}</span>}
62
+ {prefix !== undefined && <span className="text-text-muted select-none">{`${prefix} / `}</span>}
60
63
  {spelled === undefined ? (
61
64
  label
62
65
  ) : (
@@ -5,12 +5,12 @@ import { referenceTokens } from '../chat-references';
5
5
  import {
6
6
  clipboardChipsOf,
7
7
  hasClipboardChips,
8
+ namedChipParts,
8
9
  tokenizeChips,
9
10
  tokenizeNamedReferences,
10
11
  writeClipboardChips,
11
12
  type ChipSegment,
12
- type ClipboardChips,
13
- type NamedChipKind
13
+ type ClipboardChips
14
14
  } from '../mentions';
15
15
  import type { ReferenceLookup } from './reference-lookup';
16
16
 
@@ -56,11 +56,15 @@ function segmentOf(chip: Element): ChipSegment | null {
56
56
 
57
57
  return name === null || name === '' ? null : { kind: 'reference', id: value, name };
58
58
  }
59
- case 'model':
59
+ case 'model': {
60
+ const parts = namedChipParts(value);
61
+
62
+ return parts === null ? null : { kind: 'model', cli: parts.cli, id: parts.id, ...(parts.account === undefined ? {} : { account: parts.account }) };
63
+ }
60
64
  case 'account': {
61
- const slash = value.indexOf('/');
65
+ const parts = namedChipParts(value);
62
66
 
63
- return slash < 1 ? null : { kind: chip.getAttribute('data-chip') as NamedChipKind, cli: value.slice(0, slash), id: value.slice(slash + 1) };
67
+ return parts === null ? null : { kind: 'account', cli: parts.cli, id: parts.id };
64
68
  }
65
69
  default:
66
70
  return null;
@@ -89,7 +89,7 @@ function SkillMenu({ menus }: { menus: Menus }) {
89
89
 
90
90
  /* The CLI's mark of a model or account row, in the color of the account it runs on, as its chip wears it. */
91
91
  function NamedMark({ menus, pick }: { menus: Menus; pick: ModelSuggestion | AccountSuggestion }) {
92
- const { color } = menus.namedLook(pick.kind, pick.cli, pick.id);
92
+ const { color } = menus.namedLook(pick.kind, pick.cli, pick.id, pick.account);
93
93
 
94
94
  return (
95
95
  <span className="flex shrink-0" style={color === undefined ? undefined : { color }}>
@@ -120,14 +120,17 @@ function MentionMenu({ menus, query }: { menus: Menus; query: string }) {
120
120
  <Menu.Label id={modelsLabelId}>{t('composer.mentions.models')}</Menu.Label>
121
121
  {modelMatches.map((match, index) => (
122
122
  <MenuOption
123
- key={`${match.cli}/${match.id}`}
123
+ key={`${match.cli}:${match.account ?? ''}/${match.id}`}
124
124
  menus={menus}
125
125
  index={index}
126
126
  className="items-center"
127
127
  onPick={() => menus.chooseNamed(match)}
128
128
  >
129
129
  <NamedMark menus={menus} pick={match} />
130
- <span className="truncate text-text">{match.model.name}</span>
130
+ <span className="truncate text-text">
131
+ {match.accountName !== undefined && <span className="text-text-muted">{`${match.accountName} / `}</span>}
132
+ {match.model.name}
133
+ </span>
131
134
  <ModelMarks model={match.model} />
132
135
  </MenuOption>
133
136
  ))}
@@ -8,7 +8,7 @@ import { MarkGlyph } from '../../../agents/AgentIcon';
8
8
  import { CliMark } from '../../../agents/AgentModelLabel';
9
9
  import type { HostSkill, ReferenceIconProps } from '../../../host/host';
10
10
  import type { ReferableKind, ReferenceStep } from '../../../host/references';
11
- import { chipRanges, withNamedChips, type ReferenceToken } from '../../mentions';
11
+ import { chipRanges, namedChipParts, withNamedChips, type ReferenceToken } from '../../mentions';
12
12
  import { CHIP_IN_EDITOR, MENTION_TONE, REFERENCE_TONE, SKILL_TONE, TOKEN_ICON_IN_EDITOR } from '../chips';
13
13
  import type { NamedChipLook, NamedChipLookup } from '../named-chip-look';
14
14
  import { referenceGlyph } from '../reference-icons';
@@ -103,7 +103,9 @@ class NamedChipWidget extends WidgetType {
103
103
  }
104
104
 
105
105
  override eq(other: NamedChipWidget): boolean {
106
- return other.cli === this.cli && other.look.label === this.look.label && other.look.color === this.look.color;
106
+ return (
107
+ other.cli === this.cli && other.look.label === this.look.label && other.look.color === this.look.color && other.look.account === this.look.account
108
+ );
107
109
  }
108
110
 
109
111
  toDOM(): HTMLElement {
@@ -120,7 +122,17 @@ class NamedChipWidget extends WidgetType {
120
122
 
121
123
  root.render(createElement(CliMark, { kind: this.cli, size: 12 }));
122
124
  roots.set(chip, root);
123
- chip.append(mark, this.look.label);
125
+ chip.append(mark);
126
+
127
+ if (this.look.account !== undefined) {
128
+ const account = document.createElement('span');
129
+
130
+ account.className = 'text-text-muted';
131
+ account.textContent = `${this.look.account} / `;
132
+ chip.append(account);
133
+ }
134
+
135
+ chip.append(this.look.label);
124
136
 
125
137
  return chip;
126
138
  }
@@ -184,10 +196,9 @@ function chipMarks(state: EditorState): ChipMarks {
184
196
  // `@a.ts` in backticks is code, not a mention.
185
197
  for (const range of withNamedChips(text, chipRanges(text, mentions, skills, code, references), code)) {
186
198
  if (range.kind === 'model' || range.kind === 'account') {
187
- const slash = range.value.indexOf('/');
188
- const cli = range.value.slice(0, slash);
189
- const id = range.value.slice(slash + 1);
190
- const look = named?.(range.kind, cli, id) ?? { label: id, color: undefined };
199
+ // A named range always holds a `<cli>/`, since the pattern that found it requires one.
200
+ const { cli, id, account } = namedChipParts(range.value)!;
201
+ const look = named?.(range.kind, cli, id, account) ?? { label: id, color: undefined, account };
191
202
  const atom = Decoration.replace({ widget: new NamedChipWidget(cli as AgentKind, look) }).range(range.from, range.to);
192
203
 
193
204
  marks.push(atom);
@@ -227,7 +227,7 @@ export function usePromptMenus<D extends PromptDraft>({
227
227
  const skillMenuOpen = !commandMenuOpen && skillQuery !== null && skillMatches.length > 0;
228
228
  // Results belong to the query that asked for them; a closed picker shows none while the next answer is on its way.
229
229
  const files = mention === null || cwd === null ? [] : searched.files;
230
- const modelMatches = mention === null ? [] : modelSuggestions(providers, accounts, mention.query, reportedOf);
230
+ const modelMatches = mention === null ? [] : modelSuggestions(providers, accounts, mention.query, reportedOf, accountRule, home);
231
231
  const accountMatches = mention === null ? [] : accountSuggestions(providers, accounts, accountRule, mention.query);
232
232
  const named: NamedPick[] = [...modelMatches, ...accountMatches];
233
233
  // Without files to search, `@` opens only once a model or an account matches.
@@ -299,7 +299,7 @@ export function usePromptMenus<D extends PromptDraft>({
299
299
  return;
300
300
  }
301
301
 
302
- const result = insertToken(text, mention, '', namedChipToken(pick.kind, pick.cli, pick.id));
302
+ const result = insertToken(text, mention, '', namedChipToken(pick.kind, pick.cli, pick.id, pick.account));
303
303
  setText(result.text);
304
304
  setMention(null);
305
305
  moveCaret(result.caret);
@@ -12,9 +12,12 @@ import type { NamedChipKind } from '../mentions';
12
12
  export interface NamedChipLook {
13
13
  label: string;
14
14
  color: string | undefined;
15
+
16
+ /* The name of the account a model chip names, which it reads before the model's. */
17
+ account?: string;
15
18
  }
16
19
 
17
- export type NamedChipLookup = (kind: NamedChipKind, cli: string, id: string) => NamedChipLook;
20
+ export type NamedChipLookup = (kind: NamedChipKind, cli: string, id: string, account?: string) => NamedChipLook;
18
21
 
19
22
  /* The chat a chip is written in: a model chip of its CLI starts under its account, as an agent it opens inherits it. */
20
23
  export interface NamedChipHome {
@@ -38,18 +41,26 @@ export function namedChipLookup(
38
41
  return accountColor(entry?.account.color, accents) ?? (kind.success ? PROVIDER_COLORS[kind.data] : undefined);
39
42
  };
40
43
 
41
- return (kind, cli, id) => {
42
- const provider = providers.find((entry) => entry.kind === cli);
44
+ const nameOf = (cli: string, accountId: string, providerName: string | undefined): string => {
45
+ const entry = accountsOfKind(accounts, cli as AgentKind).find((candidate) => candidate.id === accountId);
43
46
 
44
- if (kind === 'model') {
45
- const account = home?.provider === cli ? (home.account ?? cli) : undefined;
47
+ return entry === undefined ? accountId : accountName(entry, providerName ?? cli);
48
+ };
46
49
 
47
- return { label: provider?.models.find((model) => model.slug === id)?.name ?? id, color: colorOf(cli, account) };
50
+ return (kind, cli, id, account) => {
51
+ const provider = providers.find((entry) => entry.kind === cli);
52
+
53
+ if (kind === 'account') {
54
+ return { label: nameOf(cli, id, provider?.name), color: colorOf(cli, id) };
48
55
  }
49
56
 
50
- const entry = accountsOfKind(accounts, cli as AgentKind).find((candidate) => candidate.id === id);
57
+ const label = provider?.models.find((model) => model.slug === id)?.name ?? id;
58
+
59
+ if (account !== undefined) {
60
+ return { label, color: colorOf(cli, account), account: nameOf(cli, account, provider?.name) };
61
+ }
51
62
 
52
- return { label: entry === undefined ? id : accountName(entry, provider?.name ?? cli), color: colorOf(cli, id) };
63
+ return { label, color: colorOf(cli, home?.provider === cli ? (home.account ?? cli) : undefined) };
53
64
  };
54
65
  }
55
66
 
@@ -1,4 +1,4 @@
1
- import { chipText, tokenizeChips, tokenizeNamedReferences, type ChipSegment, type ReferenceToken } from '../mentions';
1
+ import { chipText, namedChipValue, tokenizeChips, tokenizeNamedReferences, type ChipSegment, type ReferenceToken } from '../mentions';
2
2
 
3
3
  /* Just the part of hast this plugin touches; the package's own types are not a dependency here. */
4
4
  interface HastText {
@@ -36,8 +36,12 @@ function valueOf(segment: Exclude<ChipSegment, { kind: 'text' }>): string {
36
36
  return segment.path;
37
37
  }
38
38
 
39
- if (segment.kind === 'model' || segment.kind === 'account') {
40
- return `${segment.cli}/${segment.id}`;
39
+ if (segment.kind === 'model') {
40
+ return namedChipValue(segment.cli, segment.id, segment.account);
41
+ }
42
+
43
+ if (segment.kind === 'account') {
44
+ return namedChipValue(segment.cli, segment.id);
41
45
  }
42
46
 
43
47
  return segment.kind === 'skill' ? segment.name : segment.id;