@adecore/agents-react 0.74.1 → 0.75.1

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 (53) hide show
  1. package/dist/chat/logic/timeline.js +3 -0
  2. package/dist/chat/mentions.d.ts +11 -2
  3. package/dist/chat/mentions.js +57 -18
  4. package/dist/chat/stop-task.d.ts +1 -0
  5. package/dist/chat/stop-task.js +34 -0
  6. package/dist/chat/tag-suggestions.d.ts +3 -1
  7. package/dist/chat/tag-suggestions.js +54 -10
  8. package/dist/chat/ui/ChatActivity.js +20 -42
  9. package/dist/chat/ui/Composer.js +397 -381
  10. package/dist/chat/ui/NamedChip.js +49 -44
  11. package/dist/chat/ui/ReferenceChip.d.ts +2 -1
  12. package/dist/chat/ui/ReferenceChip.js +64 -48
  13. package/dist/chat/ui/chip-clipboard.js +17 -6
  14. package/dist/chat/ui/composer/ComposerMenu.js +28 -24
  15. package/dist/chat/ui/composer/QueuedMessages.d.ts +5 -1
  16. package/dist/chat/ui/composer/QueuedMessages.js +60 -30
  17. package/dist/chat/ui/composer/chips.js +19 -8
  18. package/dist/chat/ui/composer/use-prompt-menus.js +138 -137
  19. package/dist/chat/ui/named-chip-look.d.ts +2 -1
  20. package/dist/chat/ui/named-chip-look.js +18 -8
  21. package/dist/chat/ui/rehype-chips.js +6 -3
  22. package/dist/chat/ui/rows/MessageRows.d.ts +6 -2
  23. package/dist/chat/ui/rows/MessageRows.js +122 -45
  24. package/dist/chat/ui/rows/Rows.js +65 -61
  25. package/dist/chat/waiting-on.d.ts +6 -0
  26. package/dist/chat/waiting-on.js +13 -2
  27. package/dist/host/timeline-row.d.ts +1 -0
  28. package/dist/locales/en/agent-chat.d.ts +4 -0
  29. package/dist/locales/en/agent-chat.js +5 -1
  30. package/dist/locales/nl/agent-chat.d.ts +4 -0
  31. package/dist/locales/nl/agent-chat.js +5 -1
  32. package/package.json +9 -9
  33. package/src/chat/logic/timeline.ts +2 -1
  34. package/src/chat/mentions.ts +69 -18
  35. package/src/chat/stop-task.ts +17 -0
  36. package/src/chat/tag-suggestions.ts +73 -11
  37. package/src/chat/ui/ChatActivity.tsx +2 -10
  38. package/src/chat/ui/Composer.tsx +3 -0
  39. package/src/chat/ui/NamedChip.tsx +10 -10
  40. package/src/chat/ui/ReferenceChip.tsx +4 -1
  41. package/src/chat/ui/chip-clipboard.ts +9 -5
  42. package/src/chat/ui/composer/ComposerMenu.tsx +6 -3
  43. package/src/chat/ui/composer/QueuedMessages.tsx +21 -1
  44. package/src/chat/ui/composer/chips.ts +18 -7
  45. package/src/chat/ui/composer/use-prompt-menus.ts +2 -2
  46. package/src/chat/ui/named-chip-look.ts +19 -8
  47. package/src/chat/ui/rehype-chips.ts +7 -3
  48. package/src/chat/ui/rows/MessageRows.tsx +34 -3
  49. package/src/chat/ui/rows/Rows.tsx +1 -1
  50. package/src/chat/waiting-on.ts +13 -2
  51. package/src/host/timeline-row.ts +1 -1
  52. package/src/locales/en/agent-chat.ts +5 -1
  53. package/src/locales/nl/agent-chat.ts +5 -1
@@ -424,6 +424,9 @@ function rowsForItems(items, options, children) {
424
424
  }),
425
425
  ...(item.said === undefined ? {} : {
426
426
  said: item.said
427
+ }),
428
+ ...(item.stops === undefined ? {} : {
429
+ stops: item.stops
427
430
  })
428
431
  });
429
432
  }
@@ -39,6 +39,7 @@ export type ChipSegment = {
39
39
  kind: 'model';
40
40
  cli: string;
41
41
  id: string;
42
+ account?: string;
42
43
  } | {
43
44
  kind: 'account';
44
45
  cli: string;
@@ -74,6 +75,7 @@ export interface NamedPick {
74
75
  kind: NamedChipKind;
75
76
  cli: string;
76
77
  id: string;
78
+ account?: string;
77
79
  }
78
80
  type MentionPick = {
79
81
  kind: 'file';
@@ -93,8 +95,15 @@ interface ChipRange extends TextRange {
93
95
  kind: 'mention' | 'skill' | 'reference' | NamedChipKind;
94
96
  value: string;
95
97
  }
96
- export declare function namedChipToken(kind: NamedChipKind, cli: string, id: string): string;
97
- export declare function namedChipPrefix(kind: NamedChipKind, cli: string): string;
98
+ export declare function namedChipValue(cli: string, id: string, account?: string): string;
99
+ export interface NamedChipParts {
100
+ cli: string;
101
+ id: string;
102
+ account: string | undefined;
103
+ }
104
+ export declare function namedChipParts(value: string): NamedChipParts | null;
105
+ export declare function namedChipToken(kind: NamedChipKind, cli: string, id: string, account?: string): string;
106
+ export declare function namedChipPrefix(kind: NamedChipKind, cli: string, account?: string): string;
98
107
  export declare function namedChipRanges(text: string, excluded?: readonly TextRange[]): ChipRange[];
99
108
  export declare function withNamedChips(text: string, picked: readonly ChipRange[], excluded?: readonly TextRange[]): ChipRange[];
100
109
  export declare function chipRanges(text: string, mentions: string[], skills?: string[], excluded?: readonly TextRange[], references?: readonly ReferenceToken[]): ChipRange[];
@@ -239,8 +239,11 @@ export function chipText(segment) {
239
239
  if (segment.kind === 'reference') {
240
240
  return `#${segment.name}`;
241
241
  }
242
- if (segment.kind === 'model' || segment.kind === 'account') {
243
- return namedChipToken(segment.kind, segment.cli, segment.id);
242
+ if (segment.kind === 'model') {
243
+ return namedChipToken('model', segment.cli, segment.id, segment.account);
244
+ }
245
+ if (segment.kind === 'account') {
246
+ return namedChipToken('account', segment.cli, segment.id);
244
247
  }
245
248
  return segment.text;
246
249
  }
@@ -255,15 +258,36 @@ export function pastedMentions(text) {
255
258
  }
256
259
  return [...new Set(tokens.map(token => token.slice(1)))];
257
260
  }
258
- export function namedChipToken(kind, cli, id) {
259
- return `@${kind}:${cli}/${id}`;
261
+ /* The token without its `@<kind>:`: `<cli>/<id>`, or `<cli>:<account>/<id>` for a model on one account. */
262
+ export function namedChipValue(cli, id, account) {
263
+ return `${namedChipHead(cli, account)}/${id}`;
264
+ }
265
+ /* What a `namedChipValue` holds, or null for one without a CLI. */
266
+ export function namedChipParts(value) {
267
+ const slash = value.indexOf('/');
268
+ if (slash < 1) {
269
+ return null;
270
+ }
271
+ const head = value.slice(0, slash);
272
+ const colon = head.indexOf(':');
273
+ return {
274
+ cli: colon < 0 ? head : head.slice(0, colon),
275
+ id: value.slice(slash + 1),
276
+ account: colon < 0 ? undefined : head.slice(colon + 1)
277
+ };
278
+ }
279
+ function namedChipHead(cli, account) {
280
+ return account === undefined ? cli : `${cli}:${account}`;
260
281
  }
261
- /* The part of a named chip its CLI's mark stands in for: `@model:claude/`. */
262
- export function namedChipPrefix(kind, cli) {
263
- return `@${kind}:${cli}/`;
282
+ export function namedChipToken(kind, cli, id, account) {
283
+ return `@${kind}:${namedChipValue(cli, id, account)}`;
264
284
  }
265
- // The id runs to whitespace or a backtick; a slash belongs to it (`openrouter/anthropic/claude`).
266
- const NAMED_CHIP = /@(model|account):([a-z0-9][a-z0-9-]*)\/([^\s`]+)/g;
285
+ /* The part of a named chip its CLI's mark stands in for: `@model:claude/`, or `@model:claude:claude_work/`. */
286
+ export function namedChipPrefix(kind, cli, account) {
287
+ return `@${kind}:${namedChipHead(cli, account)}/`;
288
+ }
289
+ // The id runs to whitespace or a backtick; a slash belongs to it (`openrouter/anthropic/claude`). The account is spelled as `ProviderAccountIdSchema` spells it.
290
+ const NAMED_CHIP = /@(model|account):([a-z0-9][a-z0-9-]*)(?::([a-z][a-z0-9_-]{0,63}))?\/([^\s`]+)/g;
267
291
  // Punctuation after the id ends the sentence, except a `]` that closes a `[` in the id (`claude-opus-5-5[1m]`).
268
292
  function trimmedId(id) {
269
293
  let end = id.length;
@@ -281,16 +305,22 @@ export function namedChipRanges(text, excluded = []) {
281
305
  const ranges = [];
282
306
  for (const found of text.matchAll(NAMED_CHIP)) {
283
307
  const from = found.index;
284
- const id = trimmedId(found[3]);
285
- const to = from + found[0].length - (found[3].length - id.length);
286
- if (id === '' || from > 0 && !REFERENCE_OPENER.test(text[from - 1]) || excluded.some(range => from < range.to && to > range.from)) {
308
+ const kind = found[1];
309
+ const account = found[3];
310
+ const id = trimmedId(found[4]);
311
+ const to = from + found[0].length - (found[4].length - id.length);
312
+ // An account runs on no other account.
313
+ if (id === '' || kind === 'account' && account !== undefined) {
314
+ continue;
315
+ }
316
+ if (from > 0 && !REFERENCE_OPENER.test(text[from - 1]) || excluded.some(range => from < range.to && to > range.from)) {
287
317
  continue;
288
318
  }
289
319
  ranges.push({
290
320
  from,
291
321
  to,
292
- kind: found[1],
293
- value: `${found[2]}/${id}`
322
+ kind,
323
+ value: namedChipValue(found[2], id, account)
294
324
  });
295
325
  }
296
326
  return ranges;
@@ -373,11 +403,20 @@ function segmentOf(text, range) {
373
403
  };
374
404
  }
375
405
  if (range.kind === 'model' || range.kind === 'account') {
376
- const slash = range.value.indexOf('/');
377
- return {
406
+ const {
407
+ cli,
408
+ id,
409
+ account
410
+ } = namedChipParts(range.value);
411
+ return range.kind === 'model' && account !== undefined ? {
412
+ kind: 'model',
413
+ cli,
414
+ id,
415
+ account
416
+ } : {
378
417
  kind: range.kind,
379
- cli: range.value.slice(0, slash),
380
- id: range.value.slice(slash + 1)
418
+ cli,
419
+ id
381
420
  };
382
421
  }
383
422
  return {
@@ -0,0 +1 @@
1
+ export declare function useStopTask(chatId: string): (taskId: string) => void;
@@ -0,0 +1,34 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useTranslation } from 'react-i18next';
3
+ import { useChatHost } from '../host/host.js';
4
+ import { useChatActions } from './actions.js';
5
+ /* Stops a command or monitor a chat runs in the background, and tells the person when the host refused. */
6
+ export function useStopTask(chatId) {
7
+ const $ = _c(5);
8
+ const host = useChatHost();
9
+ const {
10
+ t
11
+ } = useTranslation("agent-chat");
12
+ const actions = useChatActions();
13
+ let t0;
14
+ if ($[0] !== actions || $[1] !== chatId || $[2] !== host || $[3] !== t) {
15
+ t0 = taskId => {
16
+ actions.stopTask(chatId, taskId).catch(error => {
17
+ const description = error instanceof Error ? error.message : t("subagents.noAnswer");
18
+ host.notify({
19
+ kind: "error",
20
+ title: t("activity.stopFailed"),
21
+ description
22
+ });
23
+ });
24
+ };
25
+ $[0] = actions;
26
+ $[1] = chatId;
27
+ $[2] = host;
28
+ $[3] = t;
29
+ $[4] = t0;
30
+ } else {
31
+ t0 = $[4];
32
+ }
33
+ return t0;
34
+ }
@@ -2,11 +2,13 @@ import { type AgentKind, type ModelInfo, type ProviderAccounts, type ProviderInf
2
2
  import { type AccountEntry } from '../agents/accounts.js';
3
3
  import type { AccountRule } from '../host/host.js';
4
4
  import type { NamedPick } from './mentions.js';
5
+ import type { NamedChipHome } from './ui/named-chip-look.js';
5
6
  export interface ModelSuggestion extends NamedPick {
6
7
  kind: 'model';
7
8
  cli: AgentKind;
8
9
  provider: ProviderInfo;
9
10
  model: ModelInfo;
11
+ accountName?: string;
10
12
  }
11
13
  export interface AccountSuggestion extends NamedPick {
12
14
  kind: 'account';
@@ -17,5 +19,5 @@ export interface AccountSuggestion extends NamedPick {
17
19
  }
18
20
  export declare function startsAWord(text: string, query: string): boolean;
19
21
  export declare function signedIn(accounts: ProviderAccounts | null, kind: AgentKind): boolean;
20
- export declare function modelSuggestions(providers: readonly ProviderInfo[], accounts: ProviderAccounts | null, query: string, reportedOf: (kind: AgentKind) => ReadonlySet<string>): ModelSuggestion[];
22
+ export declare function modelSuggestions(providers: readonly ProviderInfo[], accounts: ProviderAccounts | null, query: string, reportedOf: (kind: AgentKind) => ReadonlySet<string>, rule?: AccountRule | null, home?: NamedChipHome | null): ModelSuggestion[];
21
23
  export declare function accountSuggestions(providers: readonly ProviderInfo[], accounts: ProviderAccounts | null, rule: AccountRule | null, query: string): AccountSuggestion[];
@@ -1,7 +1,7 @@
1
1
  import { inPickerOrder } from '@adecore/agent-contracts';
2
2
  import { accountName, accountsOfKind, hasAccountChoice, projectOffered } from '../agents/accounts.js';
3
3
  import { modelRequirementOf } from '../agents/model-requirement.js';
4
- const MODEL_SUGGESTIONS = 5;
4
+ const MODEL_SUGGESTIONS = 8;
5
5
  const ACCOUNT_SUGGESTIONS = 3;
6
6
  // A CLI no model runs under while its accounts say this.
7
7
  const UNUSABLE = new Set(['signed-out', 'not-found', 'folder-missing', 'failed']);
@@ -29,21 +29,65 @@ export function signedIn(accounts, kind) {
29
29
  }
30
30
  return entries.some(entry => entry.account.enabled !== false && (entry.status === null || !UNUSABLE.has(entry.status.state)));
31
31
  }
32
+ /*
33
+ * The accounts a CLI's models are offered on, the chat's own first: the ready ones the project offers. None
34
+ * while fewer than two are, so a CLI without a choice keeps rows of the model alone.
35
+ */
36
+ function modelAccounts(provider, accounts, rule, home) {
37
+ const entries = accountsOfKind(accounts, provider.kind);
38
+ if (!hasAccountChoice(entries)) {
39
+ return [];
40
+ }
41
+ const ready = projectOffered(entries, rule, provider.kind, undefined).filter(entry => entry.account.enabled !== false && entry.status?.state === 'ready');
42
+ if (ready.length < 2) {
43
+ return [];
44
+ }
45
+ const first = home?.provider === provider.kind ? home.account ?? provider.kind : undefined;
46
+ return [...ready.filter(entry => entry.id === first), ...ready.filter(entry => entry.id !== first)].map(entry => ({
47
+ id: entry.id,
48
+ name: accountName(entry, provider.name)
49
+ }));
50
+ }
32
51
  /*
33
52
  * 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.
53
+ * that the CLI is new enough for. A CLI with a choice of accounts offers a row per account, found by the
54
+ * account's name too, and `<account>/<model>` narrows to both. Legacy models last, at most
55
+ * `MODEL_SUGGESTIONS`. A bare `@` offers none.
35
56
  */
36
- export function modelSuggestions(providers, accounts, query, reportedOf) {
57
+ export function modelSuggestions(providers, accounts, query, reportedOf, rule = null, home = null) {
37
58
  if (query === '') {
38
59
  return [];
39
60
  }
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
- })));
61
+ const slash = query.indexOf('/');
62
+ const modelMatches = (model, words) => startsAWord(model.name, words) || startsAWord(model.slug, words);
63
+ // A slash may belong to a model's id (`openrouter/anthropic/claude`), so the whole query still finds a model.
64
+ const accountMatches = (model, account) => {
65
+ if (slash < 0) {
66
+ return startsAWord(account.name, query);
67
+ }
68
+ const rest = query.slice(slash + 1);
69
+ return startsAWord(account.name, query.slice(0, slash)) && (rest === '' || modelMatches(model, rest));
70
+ };
71
+ const found = inPickerOrder(providers.filter(entry => entry.installed && entry.capabilities.chat && signedIn(accounts, entry.kind))).flatMap(provider => {
72
+ const offered = modelAccounts(provider, accounts, rule, home);
73
+ return provider.models.filter(model => modelRequirementOf(model, provider, reportedOf(provider.kind)) === null).flatMap(model => {
74
+ const row = {
75
+ kind: 'model',
76
+ cli: provider.kind,
77
+ id: model.slug,
78
+ provider,
79
+ model
80
+ };
81
+ if (offered.length === 0) {
82
+ return modelMatches(model, query) ? [row] : [];
83
+ }
84
+ return offered.filter(account => modelMatches(model, query) || accountMatches(model, account)).map(account => ({
85
+ ...row,
86
+ account: account.id,
87
+ accountName: account.name
88
+ }));
89
+ });
90
+ });
47
91
  return [...found.filter(entry => !entry.model.legacy), ...found.filter(entry => entry.model.legacy)].slice(0, MODEL_SUGGESTIONS);
48
92
  }
49
93
  /*
@@ -11,8 +11,8 @@ import { useChatHost } from '../../host/host.js';
11
11
  import { useHostTask, useHostTasks } from '../../host/host-hooks.js';
12
12
  import { useChatScope } from '../../scope.js';
13
13
  import { useChatRow, useChats } from '../../state/chats.js';
14
- import { useChatActions } from '../actions.js';
15
14
  import { backgroundCounts, backgroundTaskName, backgroundTaskTime } from '../activity.js';
15
+ import { useStopTask } from '../stop-task.js';
16
16
  import { badgeCountOf, entryTimeOf, flyoutSubagents, progressOf, statusWordOf, subagentTitle, summaryWordOf, taskRowStateOf } from '../subagent-list.js';
17
17
  import { useSubagentSupport } from '../subagent-support.js';
18
18
  import { canOpenSubagent, crumbOf, openFromMain, useSubagentTrail } from '../subagent-view.js';
@@ -852,43 +852,21 @@ function SubagentEntry(t0) {
852
852
  }
853
853
  /* Only drawn while the flyout is open, so the clock ticks for nobody otherwise. */
854
854
  function BackgroundTaskRows(t0) {
855
- const $ = _c(14);
855
+ const $ = _c(9);
856
856
  const {
857
857
  chatId,
858
858
  tasks
859
859
  } = t0;
860
- const host = useChatHost();
861
860
  const {
862
861
  t
863
862
  } = useTranslation("agent-chat");
864
863
  const now = useNow(1000);
865
- const actions = useChatActions();
864
+ const stop = useStopTask(chatId);
866
865
  let t1;
867
- if ($[0] !== actions || $[1] !== chatId || $[2] !== host || $[3] !== t) {
868
- t1 = function stop(taskId) {
869
- actions.stopTask(chatId, taskId).catch(e => {
870
- const description = e instanceof Error ? e.message : t("subagents.noAnswer");
871
- host.notify({
872
- kind: "error",
873
- title: t("activity.stopFailed"),
874
- description
875
- });
876
- });
877
- };
878
- $[0] = actions;
879
- $[1] = chatId;
880
- $[2] = host;
881
- $[3] = t;
882
- $[4] = t1;
883
- } else {
884
- t1 = $[4];
885
- }
886
- const stop = t1;
887
- let t2;
888
- if ($[5] !== now || $[6] !== stop || $[7] !== t || $[8] !== tasks) {
889
- let t3;
890
- if ($[10] !== now || $[11] !== stop || $[12] !== t) {
891
- t3 = task => /*#__PURE__*/_jsx(ActivityRow, {
866
+ if ($[0] !== now || $[1] !== stop || $[2] !== t || $[3] !== tasks) {
867
+ let t2;
868
+ if ($[5] !== now || $[6] !== stop || $[7] !== t) {
869
+ t2 = task => /*#__PURE__*/_jsx(ActivityRow, {
892
870
  icon: /*#__PURE__*/_jsx(Icon, {
893
871
  icon: scheduledWakeupAt(task) !== null ? Clock : task.kind === "shell" ? SquareTerminal : Activity,
894
872
  size: 14,
@@ -905,21 +883,21 @@ function BackgroundTaskRows(t0) {
905
883
  onClick: () => stop(task.id)
906
884
  })
907
885
  }, task.id);
908
- $[10] = now;
909
- $[11] = stop;
910
- $[12] = t;
911
- $[13] = t3;
886
+ $[5] = now;
887
+ $[6] = stop;
888
+ $[7] = t;
889
+ $[8] = t2;
912
890
  } else {
913
- t3 = $[13];
891
+ t2 = $[8];
914
892
  }
915
- t2 = tasks.map(t3);
916
- $[5] = now;
917
- $[6] = stop;
918
- $[7] = t;
919
- $[8] = tasks;
920
- $[9] = t2;
893
+ t1 = tasks.map(t2);
894
+ $[0] = now;
895
+ $[1] = stop;
896
+ $[2] = t;
897
+ $[3] = tasks;
898
+ $[4] = t1;
921
899
  } else {
922
- t2 = $[9];
900
+ t1 = $[4];
923
901
  }
924
- return t2;
902
+ return t1;
925
903
  }