@adecore/agents-react 0.54.15 → 0.55.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.
Files changed (91) hide show
  1. package/dist/agents/AgentModelLabel.d.ts +5 -0
  2. package/dist/agents/AgentModelLabel.js +32 -7
  3. package/dist/chat/account-choice.d.ts +1 -0
  4. package/dist/chat/account-choice.js +13 -4
  5. package/dist/chat/mentions.d.ts +24 -2
  6. package/dist/chat/mentions.js +84 -10
  7. package/dist/chat/subagent-list.d.ts +0 -1
  8. package/dist/chat/subagent-list.js +1 -9
  9. package/dist/chat/tag-suggestions.d.ts +22 -0
  10. package/dist/chat/tag-suggestions.js +71 -0
  11. package/dist/chat/ui/Composer.js +489 -447
  12. package/dist/chat/ui/ComposerInput.d.ts +1 -0
  13. package/dist/chat/ui/ComposerInput.js +9 -1
  14. package/dist/chat/ui/Markdown.js +41 -25
  15. package/dist/chat/ui/NamedChip.d.ts +5 -0
  16. package/dist/chat/ui/NamedChip.js +118 -0
  17. package/dist/chat/ui/Pickers.d.ts +0 -4
  18. package/dist/chat/ui/Pickers.js +1 -141
  19. package/dist/chat/ui/PromptEditor.js +2 -1
  20. package/dist/chat/ui/ReferenceChip.d.ts +3 -2
  21. package/dist/chat/ui/ReferenceChip.js +58 -36
  22. package/dist/chat/ui/RunSettings.d.ts +3 -2
  23. package/dist/chat/ui/RunSettings.js +386 -361
  24. package/dist/chat/ui/SubagentInfo.js +98 -114
  25. package/dist/chat/ui/SubagentTimeline.js +65 -43
  26. package/dist/chat/ui/Timeline.js +14 -8
  27. package/dist/chat/ui/chip-clipboard.js +10 -0
  28. package/dist/chat/ui/composer/ComposerControls.d.ts +6 -1
  29. package/dist/chat/ui/composer/ComposerControls.js +171 -158
  30. package/dist/chat/ui/composer/ComposerMenu.js +187 -55
  31. package/dist/chat/ui/composer/ComposerPlusMenu.d.ts +18 -0
  32. package/dist/chat/ui/composer/ComposerPlusMenu.js +400 -0
  33. package/dist/chat/ui/composer/ComposerStatusLine.d.ts +4 -0
  34. package/dist/chat/ui/composer/ComposerStatusLine.js +239 -0
  35. package/dist/chat/ui/composer/chips.d.ts +2 -0
  36. package/dist/chat/ui/composer/chips.js +66 -5
  37. package/dist/chat/ui/composer/insert.d.ts +1 -0
  38. package/dist/chat/ui/composer/insert.js +24 -0
  39. package/dist/chat/ui/composer/use-composer-menus.js +34 -17
  40. package/dist/chat/ui/composer/use-prompt-menus.d.ts +10 -2
  41. package/dist/chat/ui/composer/use-prompt-menus.js +290 -202
  42. package/dist/chat/ui/covered-bottom.d.ts +1 -0
  43. package/dist/chat/ui/covered-bottom.js +6 -0
  44. package/dist/chat/ui/named-chip-look.d.ts +14 -0
  45. package/dist/chat/ui/named-chip-look.js +72 -0
  46. package/dist/chat/ui/rehype-chips.js +13 -2
  47. package/dist/host-hooks.d.ts +2 -1
  48. package/dist/host-hooks.js +6 -0
  49. package/dist/host.d.ts +17 -0
  50. package/dist/index.d.ts +1 -1
  51. package/dist/locales/en/agent-chat.d.ts +14 -2
  52. package/dist/locales/en/agent-chat.js +16 -4
  53. package/dist/locales/nl/agent-chat.d.ts +14 -2
  54. package/dist/locales/nl/agent-chat.js +16 -4
  55. package/dist/state/chats.d.ts +1 -0
  56. package/dist/state/chats.js +45 -0
  57. package/package.json +9 -9
  58. package/src/agents/AgentModelLabel.tsx +10 -1
  59. package/src/chat/account-choice.ts +8 -0
  60. package/src/chat/mentions.ts +110 -13
  61. package/src/chat/subagent-list.ts +1 -14
  62. package/src/chat/tag-suggestions.ts +121 -0
  63. package/src/chat/ui/Composer.tsx +24 -12
  64. package/src/chat/ui/ComposerInput.tsx +13 -1
  65. package/src/chat/ui/Markdown.tsx +5 -0
  66. package/src/chat/ui/NamedChip.tsx +34 -0
  67. package/src/chat/ui/Pickers.tsx +1 -51
  68. package/src/chat/ui/PromptEditor.tsx +7 -1
  69. package/src/chat/ui/ReferenceChip.tsx +15 -4
  70. package/src/chat/ui/RunSettings.tsx +51 -29
  71. package/src/chat/ui/SubagentInfo.tsx +17 -17
  72. package/src/chat/ui/SubagentTimeline.tsx +7 -2
  73. package/src/chat/ui/Timeline.tsx +11 -5
  74. package/src/chat/ui/chip-clipboard.ts +8 -1
  75. package/src/chat/ui/composer/ComposerControls.tsx +24 -17
  76. package/src/chat/ui/composer/ComposerMenu.tsx +83 -15
  77. package/src/chat/ui/composer/ComposerPlusMenu.tsx +158 -0
  78. package/src/chat/ui/composer/ComposerStatusLine.tsx +94 -0
  79. package/src/chat/ui/composer/chips.ts +78 -7
  80. package/src/chat/ui/composer/insert.ts +12 -0
  81. package/src/chat/ui/composer/use-composer-menus.ts +5 -2
  82. package/src/chat/ui/composer/use-prompt-menus.ts +55 -10
  83. package/src/chat/ui/covered-bottom.ts +7 -0
  84. package/src/chat/ui/named-chip-look.ts +64 -0
  85. package/src/chat/ui/rehype-chips.ts +17 -2
  86. package/src/host-hooks.ts +11 -1
  87. package/src/host.ts +29 -0
  88. package/src/index.ts +2 -0
  89. package/src/locales/en/agent-chat.ts +16 -4
  90. package/src/locales/nl/agent-chat.ts +16 -4
  91. package/src/state/chats.ts +26 -0
@@ -6,5 +6,10 @@ interface AgentModelLabelProps {
6
6
  size?: number;
7
7
  className?: string;
8
8
  }
9
+ export declare function CliMark({ kind, size, className }: {
10
+ kind: AgentKind;
11
+ size?: number;
12
+ className?: string;
13
+ }): import("react").JSX.Element;
9
14
  export declare function AgentModelLabel({ provider, model, scopeId, size, className }: AgentModelLabelProps): import("react").JSX.Element;
10
15
  export {};
@@ -7,11 +7,40 @@ import { AgentIcon } from './AgentIcon.js';
7
7
  import { modelName } from './model-name.js';
8
8
  import { hasProviderLogo } from './provider-paths.js';
9
9
  import { ProviderLogo } from './ProviderLogo.js';
10
+ /* A CLI's mark: the provider's own logo where there is one, its icon otherwise. */
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ export function CliMark(t0) {
13
+ const $ = _c(4);
14
+ const {
15
+ kind,
16
+ size: t1,
17
+ className
18
+ } = t0;
19
+ const size = t1 === undefined ? 14 : t1;
20
+ let t2;
21
+ if ($[0] !== className || $[1] !== kind || $[2] !== size) {
22
+ t2 = hasProviderLogo(kind) ? /*#__PURE__*/_jsx(ProviderLogo, {
23
+ provider: kind,
24
+ size: size,
25
+ className: className
26
+ }) : /*#__PURE__*/_jsx(AgentIcon, {
27
+ kind: kind,
28
+ size: size,
29
+ className: clsx("shrink-0", className)
30
+ });
31
+ $[0] = className;
32
+ $[1] = kind;
33
+ $[2] = size;
34
+ $[3] = t2;
35
+ } else {
36
+ t2 = $[3];
37
+ }
38
+ return t2;
39
+ }
10
40
  /*
11
41
  * Who answered or will answer, in one line: the CLI's mark and the model, named the way the machine's
12
42
  * catalog names it, as a row of facts writes it ("made by", "runs as").
13
43
  */
14
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
44
  export function AgentModelLabel(t0) {
16
45
  const $ = _c(19);
17
46
  const {
@@ -56,13 +85,9 @@ export function AgentModelLabel(t0) {
56
85
  }
57
86
  let t5;
58
87
  if ($[10] !== provider || $[11] !== size) {
59
- t5 = hasProviderLogo(provider) ? /*#__PURE__*/_jsx(ProviderLogo, {
60
- provider: provider,
61
- size: size
62
- }) : /*#__PURE__*/_jsx(AgentIcon, {
88
+ t5 = /*#__PURE__*/_jsx(CliMark, {
63
89
  kind: provider,
64
- size: size,
65
- className: "shrink-0"
90
+ size: size
66
91
  });
67
92
  $[10] = provider;
68
93
  $[11] = size;
@@ -9,6 +9,7 @@ export interface AccountChoice {
9
9
  providerName: string;
10
10
  nameOf(entry: AccountEntry): string;
11
11
  }
12
+ export declare function useAccountColorId(kind: AgentKind, account: string | undefined): string | undefined;
12
13
  export declare function useAccountChoice(kind: AgentKind | null, account: string | undefined, chatId: string): AccountChoice | null;
13
14
  export type NewAccountChoice = {
14
15
  status: 'loading';
@@ -4,15 +4,24 @@ import { useHostAccountRule } from '../host-hooks.js';
4
4
  import { useChatScope } from '../scope.js';
5
5
  import { useProviderAccounts } from '../state/provider-accounts.js';
6
6
  import { useProviders } from '../state/providers.js';
7
+ /* The color a person gave the account the chat runs under, also when it is the CLI's only one. */
8
+ export function useAccountColorId(kind, account) {
9
+ const accounts = useProviderAccounts(_temp);
10
+ const currentId = account ?? kind;
11
+ return accounts?.accounts[currentId]?.color;
12
+ }
7
13
  /*
8
14
  * The accounts of a chat's CLI on the machine in scope and the one the chat runs under, or null while
9
15
  * the CLI has fewer than two accounts that are on: with one there is nothing to choose or tell apart.
10
16
  */
17
+ function _temp(row) {
18
+ return row.accounts;
19
+ }
11
20
  export function useAccountChoice(kind, account, chatId) {
12
21
  const $ = _c(18);
13
22
  const scope = useChatScope();
14
23
  const rule = useHostAccountRule(scope.id, chatId);
15
- const accounts = useProviderAccounts(_temp);
24
+ const accounts = useProviderAccounts(_temp2);
16
25
  const providerName = useProviders(row_0 => row_0.providers.find(entry => entry.kind === kind)?.name) ?? kind ?? "";
17
26
  if (kind === null || accounts === null) {
18
27
  return null;
@@ -86,7 +95,7 @@ export function useAccountChoice(kind, account, chatId) {
86
95
  return t6;
87
96
  }
88
97
  // One object each, so a render that changes nothing hands back the same answer.
89
- function _temp(row) {
98
+ function _temp2(row) {
90
99
  return row.accounts;
91
100
  }
92
101
  const LOADING = {
@@ -117,7 +126,7 @@ export function newAccountChoiceOf(row, kind, providerName, rule = null) {
117
126
  export function useNewAccountChoice(kind, t0) {
118
127
  const $ = _c(5);
119
128
  const rule = t0 === undefined ? null : t0;
120
- const row = useProviderAccounts(_temp2);
129
+ const row = useProviderAccounts(_temp3);
121
130
  const providerName = useProviders(entry_0 => entry_0.providers.find(provider => provider.kind === kind)?.name) ?? kind ?? "";
122
131
  let t1;
123
132
  if ($[0] !== kind || $[1] !== providerName || $[2] !== row || $[3] !== rule) {
@@ -132,6 +141,6 @@ export function useNewAccountChoice(kind, t0) {
132
141
  }
133
142
  return t1;
134
143
  }
135
- function _temp2(entry) {
144
+ function _temp3(entry) {
136
145
  return entry;
137
146
  }
@@ -36,7 +36,16 @@ export type ChipSegment = {
36
36
  kind: 'reference';
37
37
  id: string;
38
38
  name: string;
39
+ } | {
40
+ kind: 'model';
41
+ cli: string;
42
+ id: string;
43
+ } | {
44
+ kind: 'account';
45
+ cli: string;
46
+ id: string;
39
47
  };
48
+ export type NamedChipKind = 'model' | 'account';
40
49
  export declare function queryOutsideChips(query: MentionQuery | null, chips: readonly ChipRange[]): MentionQuery | null;
41
50
  export declare function findMentionQuery(text: string, caret: number): MentionQuery | null;
42
51
  export declare function findSkillQuery(text: string, caret: number): MentionQuery | null;
@@ -62,7 +71,16 @@ export interface MentionSearch {
62
71
  files: string[];
63
72
  }
64
73
  export declare const NO_MENTION_SEARCH: MentionSearch;
65
- export declare function mentionPick(index: number, search: MentionSearch, query: string): string | null;
74
+ export interface NamedPick {
75
+ kind: NamedChipKind;
76
+ cli: string;
77
+ id: string;
78
+ }
79
+ export type MentionPick = {
80
+ kind: 'file';
81
+ path: string;
82
+ } | NamedPick;
83
+ export declare function mentionPick(index: number, search: MentionSearch, query: string, named?: readonly NamedPick[]): MentionPick | null;
66
84
  export declare function presentMentions(text: string, chosen: string[]): string[];
67
85
  export declare function presentSkills(text: string, chosen: string[]): string[];
68
86
  export declare function presentReferences(text: string, ids: readonly string[], tokens: readonly ReferenceToken[]): string[];
@@ -73,9 +91,13 @@ export interface TextRange {
73
91
  to: number;
74
92
  }
75
93
  export interface ChipRange extends TextRange {
76
- kind: 'mention' | 'skill' | 'reference';
94
+ kind: 'mention' | 'skill' | 'reference' | NamedChipKind;
77
95
  value: string;
78
96
  }
97
+ export declare function namedChipToken(kind: NamedChipKind, cli: string, id: string): string;
98
+ export declare function namedChipPrefix(kind: NamedChipKind, cli: string): string;
99
+ export declare function namedChipRanges(text: string, excluded?: readonly TextRange[]): ChipRange[];
100
+ export declare function withNamedChips(text: string, picked: readonly ChipRange[], excluded?: readonly TextRange[]): ChipRange[];
79
101
  export declare function chipRanges(text: string, mentions: string[], skills?: string[], excluded?: readonly TextRange[], references?: readonly ReferenceToken[]): ChipRange[];
80
102
  export declare function tokenizeChips(text: string, mentions: string[], skills?: string[], references?: readonly ReferenceToken[]): ChipSegment[];
81
103
  export declare function namedReferenceRanges(text: string, items: readonly ReferenceToken[], referenced?: readonly string[], excluded?: readonly TextRange[]): ChipRange[];
@@ -136,12 +136,12 @@ export function findSkillQuery(text, caret) {
136
136
  return found === null || found.query !== '' && !/^[A-Za-z]/.test(found.query) ? null : found;
137
137
  }
138
138
  /*
139
- * The `#word` the caret sits in. It opens only once a letter follows the sigil, so a `# ` heading,
140
- * `#123` and a bare `#` stay text. A name with a space is found by its first word.
139
+ * The `#word` the caret sits in, open from the bare sigil on. The name has to start with a letter, so
140
+ * a `# ` heading and `#123` close it again and stay text. A name with a space is found by its first word.
141
141
  */
142
142
  export function findReferenceQuery(text, caret) {
143
143
  const found = findQuery(text, caret, '#');
144
- return found === null || !/^\p{L}/u.test(found.query) ? null : found;
144
+ return found === null || found.query !== '' && !/^\p{L}/u.test(found.query) ? null : found;
145
145
  }
146
146
  /* Replaces the `<sigil>query` under the caret with the chosen token and a space, and says where the caret goes. */
147
147
  export function insertToken(text, query, sigil, value) {
@@ -165,12 +165,20 @@ export const NO_MENTION_SEARCH = {
165
165
  query: null,
166
166
  files: []
167
167
  };
168
- /* The path Enter or Tab takes from the `@` list at `index`. Files still on screen from an older query are never taken. */
169
- export function mentionPick(index, search, query) {
170
- if (search.query !== query) {
171
- return null;
168
+ /*
169
+ * What Enter or Tab takes from the `@` list at `index`: `named` first, then the files. Those answer the
170
+ * query typed now, so they are always taken; files still on screen from an older query never are.
171
+ */
172
+ export function mentionPick(index, search, query, named = []) {
173
+ const count = named.length + search.files.length;
174
+ const at = index < count ? index : 0;
175
+ if (at < named.length) {
176
+ return named[at] ?? null;
172
177
  }
173
- return search.files[index] ?? search.files[0] ?? null;
178
+ return search.query === query ? {
179
+ kind: 'file',
180
+ path: search.files[at - named.length]
181
+ } : null;
174
182
  }
175
183
  function findToken(text, sigil, value, from) {
176
184
  const token = `${sigil}${value}`;
@@ -220,6 +228,9 @@ export function chipText(segment) {
220
228
  if (segment.kind === 'reference') {
221
229
  return `#${segment.name}`;
222
230
  }
231
+ if (segment.kind === 'model' || segment.kind === 'account') {
232
+ return namedChipToken(segment.kind, segment.cli, segment.id);
233
+ }
223
234
  return segment.text;
224
235
  }
225
236
  /*
@@ -233,6 +244,61 @@ export function pastedMentions(text) {
233
244
  }
234
245
  return [...new Set(tokens.map(token => token.slice(1)))];
235
246
  }
247
+ export function namedChipToken(kind, cli, id) {
248
+ return `@${kind}:${cli}/${id}`;
249
+ }
250
+ /* The part of a named chip its CLI's mark stands in for: `@model:claude/`. */
251
+ export function namedChipPrefix(kind, cli) {
252
+ return `@${kind}:${cli}/`;
253
+ }
254
+ // The id runs to whitespace or a backtick; a slash belongs to it (`openrouter/anthropic/claude`).
255
+ const NAMED_CHIP = /@(model|account):([a-z0-9][a-z0-9-]*)\/([^\s`]+)/g;
256
+ // Punctuation after the id ends the sentence, except a `]` that closes a `[` in the id (`claude-opus-5-5[1m]`).
257
+ function trimmedId(id) {
258
+ let end = id.length;
259
+ while (end > 0 && TOKEN_END.test(id[end - 1]) && !(id[end - 1] === ']' && id.lastIndexOf('[', end - 1) >= 0)) {
260
+ end -= 1;
261
+ }
262
+ return id.slice(0, end);
263
+ }
264
+ /*
265
+ * Where the text spells a model or an account, found by the pattern alone, so these chips need no list
266
+ * in a draft or on an item. The token opens a word or follows an opening bracket or quote; one that
267
+ * overlaps an excluded range (a code span, say) is text.
268
+ */
269
+ export function namedChipRanges(text, excluded = []) {
270
+ const ranges = [];
271
+ for (const found of text.matchAll(NAMED_CHIP)) {
272
+ const from = found.index;
273
+ const id = trimmedId(found[3]);
274
+ const to = from + found[0].length - (found[3].length - id.length);
275
+ if (id === '' || from > 0 && !REFERENCE_OPENER.test(text[from - 1]) || excluded.some(range => from < range.to && to > range.from)) {
276
+ continue;
277
+ }
278
+ ranges.push({
279
+ from,
280
+ to,
281
+ kind: found[1],
282
+ value: `${found[2]}/${id}`
283
+ });
284
+ }
285
+ return ranges;
286
+ }
287
+ /* The picked chips and the named ones together, in text order; where two overlap, the one that starts first stays. */
288
+ export function withNamedChips(text, picked, excluded = []) {
289
+ const named = namedChipRanges(text, excluded);
290
+ if (named.length === 0) {
291
+ return [...picked];
292
+ }
293
+ const merged = [];
294
+ for (const range of [...picked, ...named].sort((a, b) => a.from - b.from || b.to - a.to)) {
295
+ const last = merged.at(-1);
296
+ if (last === undefined || range.from >= last.to) {
297
+ merged.push(range);
298
+ }
299
+ }
300
+ return merged;
301
+ }
236
302
  /*
237
303
  * Where the chosen mentions, skills and references sit in the text, in text order; longer values win
238
304
  * when one prefixes another. A token that overlaps an excluded range (a code span, say) is text.
@@ -295,15 +361,23 @@ function segmentOf(text, range) {
295
361
  name: range.value
296
362
  };
297
363
  }
364
+ if (range.kind === 'model' || range.kind === 'account') {
365
+ const slash = range.value.indexOf('/');
366
+ return {
367
+ kind: range.kind,
368
+ cli: range.value.slice(0, slash),
369
+ id: range.value.slice(slash + 1)
370
+ };
371
+ }
298
372
  return {
299
373
  kind: 'reference',
300
374
  id: range.value,
301
375
  name: text.slice(range.from + 1, range.to)
302
376
  };
303
377
  }
304
- /* Splits the text so a renderer can draw the mentions, skills and references as chips. */
378
+ /* Splits the text so a renderer can draw the mentions, skills, references, models and accounts as chips. */
305
379
  export function tokenizeChips(text, mentions, skills = [], references = []) {
306
- return segmentsOf(text, chipRanges(text, mentions, skills, [], references));
380
+ return segmentsOf(text, withNamedChips(text, chipRanges(text, mentions, skills, [], references)));
307
381
  }
308
382
  // What a `#` may follow in a text nobody typed through the picker: a space, or an opening bracket or quote.
309
383
  const REFERENCE_OPENER = /[\s([{"'“‘]/;
@@ -2,7 +2,6 @@ import { type ChatInfo, type ChatItem, type ChatSubagentItem } from '@adecore/ag
2
2
  import type { StatusWord } from '../agents/status-look.js';
3
3
  import type { SubagentTask } from '../host.js';
4
4
  export declare function subagentTitle(item: ChatSubagentItem): string;
5
- export declare function subagentFacts(item: ChatSubagentItem, modelName: string | null): string[];
6
5
  export declare function taskIdOf(item: ChatSubagentItem): string | null;
7
6
  export declare function statusWordOf(item: ChatSubagentItem, task: SubagentTask | null): StatusWord;
8
7
  export type TaskRowState = StatusWord | 'waiting';
@@ -1,17 +1,9 @@
1
1
  import { activeSubagents } from '@adecore/agent-contracts';
2
- import { formatMoment, formatElapsedShort, formatTokens } from '@adecore/ui/format';
2
+ import { formatMoment, formatElapsedShort } from '@adecore/ui/format';
3
3
  import i18next from 'i18next';
4
4
  export function subagentTitle(item) {
5
5
  return item.description || item.summary || item.subagentType || i18next.t('agent-chat:rows.subagent.label');
6
6
  }
7
- /* What the bar over a sub-agent's conversation says of it beside its state and its time; the model is named by the caller, which has the catalog. */
8
- export function subagentFacts(item, modelName) {
9
- return [modelName, item.subagentType, item.background ? i18next.t('agent-chat:rows.subagent.background') : null, item.usage !== null && item.usage.totalTokens > 0 ? i18next.t('agent-chat:subagents.info.tokens', {
10
- tokens: formatTokens(item.usage.totalTokens)
11
- }) : null, item.usage !== null && item.usage.toolUses > 0 ? i18next.t('agent-chat:group.toolCalls', {
12
- count: item.usage.toolUses
13
- }) : null].filter(fact => fact !== null && fact !== '');
14
- }
15
7
  /* The task a row stands for, whose id the host wrote into the row's own. */
16
8
  export function taskIdOf(item) {
17
9
  return item.origin === 'ruimte' && item.id.startsWith('task-') ? item.id.slice(5) : null;
@@ -0,0 +1,22 @@
1
+ import type { AgentKind, ModelInfo, ProviderAccounts, ProviderInfo } from '@adecore/agent-contracts';
2
+ import { type AccountEntry, type AccountRule } from '../agents/accounts.js';
3
+ import type { NamedPick } from './mentions.js';
4
+ export declare const MODEL_SUGGESTIONS = 5;
5
+ export declare const ACCOUNT_SUGGESTIONS = 3;
6
+ export interface ModelSuggestion extends NamedPick {
7
+ kind: 'model';
8
+ cli: AgentKind;
9
+ provider: ProviderInfo;
10
+ model: ModelInfo;
11
+ }
12
+ export interface AccountSuggestion extends NamedPick {
13
+ kind: 'account';
14
+ cli: AgentKind;
15
+ provider: ProviderInfo;
16
+ entry: AccountEntry;
17
+ name: string;
18
+ }
19
+ export declare function startsAWord(text: string, query: string): boolean;
20
+ export declare function signedIn(accounts: ProviderAccounts | null, kind: AgentKind): boolean;
21
+ export declare function modelSuggestions(providers: readonly ProviderInfo[], accounts: ProviderAccounts | null, query: string, reportedOf: (kind: AgentKind) => ReadonlySet<string>): ModelSuggestion[];
22
+ export declare function accountSuggestions(providers: readonly ProviderInfo[], accounts: ProviderAccounts | null, rule: AccountRule | null, query: string): AccountSuggestion[];
@@ -0,0 +1,71 @@
1
+ import { accountName, accountsOfKind, hasAccountChoice, projectOffered } from '../agents/accounts.js';
2
+ import { modelRequirementOf } from '../agents/model-requirement.js';
3
+ import { inPickerOrder } from './logic/picker-entries.js';
4
+ export const MODEL_SUGGESTIONS = 5;
5
+ export const ACCOUNT_SUGGESTIONS = 3;
6
+ // A CLI no model runs under while its accounts say this.
7
+ const UNUSABLE = new Set(['signed-out', 'not-found', 'folder-missing', 'failed']);
8
+ /*
9
+ * Whether the query opens a word of the text: `op` and `opus-5` in "Opus 5.5" or `claude-opus-5-5`, never
10
+ * `pus`. A vendor is no word of a model, so `@open` keeps finding files.
11
+ */
12
+ export function startsAWord(text, query) {
13
+ const haystack = text.toLowerCase();
14
+ const needle = query.toLowerCase();
15
+ let index = needle === '' ? -1 : haystack.indexOf(needle);
16
+ while (index >= 0) {
17
+ if (index === 0 || !/[\p{L}\p{N}]/u.test(haystack[index - 1])) {
18
+ return true;
19
+ }
20
+ index = haystack.indexOf(needle, index + 1);
21
+ }
22
+ return false;
23
+ }
24
+ /* Whether a CLI can run a model now: one of its enabled accounts is signed in, or it keeps no accounts at all. */
25
+ export function signedIn(accounts, kind) {
26
+ const entries = accountsOfKind(accounts, kind);
27
+ if (entries.length === 0) {
28
+ return true;
29
+ }
30
+ return entries.some(entry => entry.account.enabled !== false && (entry.status === null || !UNUSABLE.has(entry.status.state)));
31
+ }
32
+ /*
33
+ * The models the `@` list offers for a query: of a CLI that is installed, chats and is signed in, and
34
+ * that the CLI is new enough for. Legacy models last, at most `MODEL_SUGGESTIONS`. A bare `@` offers none.
35
+ */
36
+ export function modelSuggestions(providers, accounts, query, reportedOf) {
37
+ if (query === '') {
38
+ return [];
39
+ }
40
+ const found = inPickerOrder(providers.filter(entry => entry.installed && entry.capabilities.chat && signedIn(accounts, entry.kind))).flatMap(provider => provider.models.filter(model => (startsAWord(model.name, query) || startsAWord(model.slug, query)) && modelRequirementOf(model, provider, reportedOf(provider.kind)) === null).map(model => ({
41
+ kind: 'model',
42
+ cli: provider.kind,
43
+ id: model.slug,
44
+ provider,
45
+ model
46
+ })));
47
+ return [...found.filter(entry => !entry.model.legacy), ...found.filter(entry => entry.model.legacy)].slice(0, MODEL_SUGGESTIONS);
48
+ }
49
+ /*
50
+ * The accounts the `@` list offers for a query, by the name a person sees: those that are ready, of a CLI
51
+ * with a choice of account, that the project offers. At most `ACCOUNT_SUGGESTIONS`.
52
+ */
53
+ export function accountSuggestions(providers, accounts, rule, query) {
54
+ if (query === '' || accounts === null) {
55
+ return [];
56
+ }
57
+ return inPickerOrder(providers.filter(entry => entry.installed && entry.capabilities.chat)).flatMap(provider => {
58
+ const entries = accountsOfKind(accounts, provider.kind);
59
+ if (!hasAccountChoice(entries)) {
60
+ return [];
61
+ }
62
+ return projectOffered(entries, rule, provider.kind, undefined).filter(entry => entry.account.enabled !== false && entry.status?.state === 'ready').map(entry => ({
63
+ kind: 'account',
64
+ cli: provider.kind,
65
+ id: entry.id,
66
+ provider,
67
+ entry,
68
+ name: accountName(entry, provider.name)
69
+ })).filter(suggestion => startsAWord(suggestion.name, query));
70
+ }).slice(0, ACCOUNT_SUGGESTIONS);
71
+ }