@adecore/agents-react 0.47.0 → 0.48.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 (52) hide show
  1. package/dist/agents/accounts.d.ts +9 -1
  2. package/dist/agents/accounts.js +31 -7
  3. package/dist/chat/account-choice.d.ts +5 -4
  4. package/dist/chat/account-choice.js +47 -39
  5. package/dist/chat/preferences.d.ts +2 -2
  6. package/dist/chat/preferences.js +11 -5
  7. package/dist/chat/ui/AccountPill.js +9 -6
  8. package/dist/chat/ui/LimitState.js +180 -172
  9. package/dist/chat/ui/UnifiedDiff.js +22 -19
  10. package/dist/chat/ui/composer/ComposerControls.js +1 -1
  11. package/dist/chat/ui/composer/use-chat-controls.js +70 -67
  12. package/dist/chat/ui/diff/EditorEditDiff.d.ts +3 -1
  13. package/dist/chat/ui/diff/EditorEditDiff.js +24 -18
  14. package/dist/chat/ui/diff/EditorPatchDiff.d.ts +3 -1
  15. package/dist/chat/ui/diff/EditorPatchDiff.js +4 -2
  16. package/dist/chat/ui/diff/diff-props.d.ts +2 -0
  17. package/dist/host-hooks.d.ts +3 -0
  18. package/dist/host-hooks.js +8 -0
  19. package/dist/host.d.ts +3 -0
  20. package/dist/locales/en/agent-providers.d.ts +5 -0
  21. package/dist/locales/en/agent-providers.js +8 -3
  22. package/dist/locales/nl/agent-providers.d.ts +5 -0
  23. package/dist/locales/nl/agent-providers.js +8 -3
  24. package/dist/providers/AccountOrderList.d.ts +10 -0
  25. package/dist/providers/AccountOrderList.js +158 -0
  26. package/dist/providers/CliDetail.js +55 -61
  27. package/dist/providers/account-actions.d.ts +1 -0
  28. package/dist/providers/account-actions.js +39 -0
  29. package/dist/providers/index.d.ts +1 -1
  30. package/dist/providers/index.js +1 -1
  31. package/dist/usage/limit-groups.js +6 -1
  32. package/package.json +8 -8
  33. package/src/agents/accounts.ts +42 -6
  34. package/src/chat/account-choice.ts +31 -10
  35. package/src/chat/preferences.ts +33 -8
  36. package/src/chat/ui/AccountPill.tsx +3 -3
  37. package/src/chat/ui/LimitState.tsx +4 -2
  38. package/src/chat/ui/UnifiedDiff.tsx +12 -1
  39. package/src/chat/ui/composer/ComposerControls.tsx +1 -1
  40. package/src/chat/ui/composer/use-chat-controls.ts +4 -1
  41. package/src/chat/ui/diff/EditorEditDiff.tsx +9 -4
  42. package/src/chat/ui/diff/EditorPatchDiff.tsx +5 -1
  43. package/src/chat/ui/diff/diff-props.ts +3 -0
  44. package/src/host-hooks.ts +13 -0
  45. package/src/host.ts +8 -0
  46. package/src/locales/en/agent-providers.ts +8 -3
  47. package/src/locales/nl/agent-providers.ts +8 -3
  48. package/src/providers/AccountOrderList.tsx +124 -0
  49. package/src/providers/CliDetail.tsx +33 -28
  50. package/src/providers/account-actions.ts +30 -0
  51. package/src/providers/index.ts +11 -1
  52. package/src/usage/limit-groups.ts +8 -1
@@ -0,0 +1,158 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useState } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { ChevronRight, GripVertical } from 'lucide-react';
5
+ import { Icon, Pill, Tooltip } from '@adecore/ui';
6
+ import { AccountDot } from '../agents/AccountDot.js';
7
+ import { ACCOUNT_TONE_CLASSES, accountName, accountStatusLine, movedIds, topAccountEntry } from '../agents/accounts.js';
8
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
9
+ const DRAG_TYPE = 'application/x-adecore-account';
10
+ /* The accounts of one CLI in the person's order, dragged by their handle or moved with Alt+Up and Alt+Down; the top one that is on is tagged as the default. */
11
+ export function AccountOrderList(t0) {
12
+ const $ = _c(13);
13
+ const {
14
+ entries,
15
+ providerName,
16
+ login,
17
+ onReorder,
18
+ onPickAccount
19
+ } = t0;
20
+ const {
21
+ t
22
+ } = useTranslation("agent-providers");
23
+ const [dragged, setDragged] = useState(null);
24
+ const [over, setOver] = useState(null);
25
+ let t1;
26
+ if ($[0] !== dragged || $[1] !== entries || $[2] !== login || $[3] !== onPickAccount || $[4] !== onReorder || $[5] !== over || $[6] !== providerName || $[7] !== t) {
27
+ const ids = entries.map(_temp);
28
+ let t2;
29
+ if ($[9] !== entries) {
30
+ t2 = topAccountEntry(entries);
31
+ $[9] = entries;
32
+ $[10] = t2;
33
+ } else {
34
+ t2 = $[10];
35
+ }
36
+ const top = t2;
37
+ const reorder = entries.length >= 2 ? onReorder : null;
38
+ const move = (id, to) => {
39
+ const next = movedIds(ids, id, to);
40
+ if (reorder !== null && next.some((candidate, index) => candidate !== ids[index])) {
41
+ reorder(next);
42
+ }
43
+ };
44
+ const onKeyDown = (event, id_0, index_0) => {
45
+ if (reorder === null || !event.altKey || event.key !== "ArrowUp" && event.key !== "ArrowDown") {
46
+ return;
47
+ }
48
+ event.preventDefault();
49
+ move(id_0, event.key === "ArrowUp" ? index_0 - 1 : index_0 + 1);
50
+ };
51
+ const placeOf = _temp2;
52
+ const onDrop = (event_1, index_2) => {
53
+ event_1.preventDefault();
54
+ const id_1 = event_1.dataTransfer.getData(DRAG_TYPE);
55
+ const from = ids.indexOf(id_1);
56
+ const place = placeOf(event_1, index_2);
57
+ setDragged(null);
58
+ setOver(null);
59
+ if (from !== -1) {
60
+ move(id_1, place > from ? place - 1 : place);
61
+ }
62
+ };
63
+ t1 = entries.map((entry_0, index_3) => {
64
+ const status = accountStatusLine(entry_0.status, login === "terminal");
65
+ const name = accountName(entry_0, providerName);
66
+ return /*#__PURE__*/_jsxs("div", {
67
+ className: `relative flex w-full min-w-0 items-center first:rounded-t-xl last:rounded-b-xl hover:bg-surface-hover ${dragged === entry_0.id ? "opacity-50" : ""}`,
68
+ onDragOver: event_2 => {
69
+ if (dragged !== null) {
70
+ event_2.preventDefault();
71
+ setOver(placeOf(event_2, index_3));
72
+ }
73
+ },
74
+ onDrop: event_3 => onDrop(event_3, index_3),
75
+ children: [over === index_3 && /*#__PURE__*/_jsx("span", {
76
+ "aria-hidden": true,
77
+ className: "absolute inset-x-3 top-0 h-0.5 rounded-full bg-accent"
78
+ }), over === index_3 + 1 && index_3 === entries.length - 1 && /*#__PURE__*/_jsx("span", {
79
+ "aria-hidden": true,
80
+ className: "absolute inset-x-3 bottom-0 h-0.5 rounded-full bg-accent"
81
+ }), reorder !== null && /*#__PURE__*/_jsx(Tooltip, {
82
+ label: t("cli.reorderHandle", {
83
+ account: name
84
+ }),
85
+ children: /*#__PURE__*/_jsx("span", {
86
+ "aria-hidden": true,
87
+ draggable: true,
88
+ className: "flex shrink-0 cursor-grab items-center self-stretch pl-3 text-text-faint",
89
+ onDragStart: event_4 => {
90
+ event_4.dataTransfer.setData(DRAG_TYPE, entry_0.id);
91
+ event_4.dataTransfer.effectAllowed = "move";
92
+ setDragged(entry_0.id);
93
+ },
94
+ onDragEnd: () => {
95
+ setDragged(null);
96
+ setOver(null);
97
+ },
98
+ children: /*#__PURE__*/_jsx(Icon, {
99
+ icon: GripVertical,
100
+ size: 14
101
+ })
102
+ })
103
+ }), /*#__PURE__*/_jsxs("button", {
104
+ type: "button",
105
+ "aria-keyshortcuts": reorder === null ? undefined : "Alt+ArrowUp Alt+ArrowDown",
106
+ className: `flex min-w-0 grow items-center gap-3 py-3 pr-4.5 text-left ${reorder === null ? "pl-4.5" : "pl-2.5"}`,
107
+ onClick: () => onPickAccount(entry_0.id),
108
+ onKeyDown: event_5 => onKeyDown(event_5, entry_0.id, index_3),
109
+ children: [/*#__PURE__*/_jsx(AccountDot, {
110
+ color: entry_0.account.color
111
+ }), /*#__PURE__*/_jsx("span", {
112
+ className: "min-w-0 truncate text-sm text-text",
113
+ children: name
114
+ }), entries.length >= 2 && entry_0.id === top?.id && /*#__PURE__*/_jsx(Pill, {
115
+ size: "sm",
116
+ children: t("cli.defaultTag")
117
+ }), /*#__PURE__*/_jsx("span", {
118
+ className: `ml-auto shrink-0 text-xs ${ACCOUNT_TONE_CLASSES[status.tone]}`,
119
+ children: status.text
120
+ }), /*#__PURE__*/_jsx(Icon, {
121
+ icon: ChevronRight,
122
+ size: 14,
123
+ className: "shrink-0 text-text-faint"
124
+ })]
125
+ })]
126
+ }, entry_0.id);
127
+ });
128
+ $[0] = dragged;
129
+ $[1] = entries;
130
+ $[2] = login;
131
+ $[3] = onPickAccount;
132
+ $[4] = onReorder;
133
+ $[5] = over;
134
+ $[6] = providerName;
135
+ $[7] = t;
136
+ $[8] = t1;
137
+ } else {
138
+ t1 = $[8];
139
+ }
140
+ let t2;
141
+ if ($[11] !== t1) {
142
+ t2 = /*#__PURE__*/_jsx(_Fragment, {
143
+ children: t1
144
+ });
145
+ $[11] = t1;
146
+ $[12] = t2;
147
+ } else {
148
+ t2 = $[12];
149
+ }
150
+ return t2;
151
+ }
152
+ function _temp2(event_0, index_1) {
153
+ const box = event_0.currentTarget.getBoundingClientRect();
154
+ return event_0.clientY > box.top + box.height / 2 ? index_1 + 1 : index_1;
155
+ }
156
+ function _temp(entry) {
157
+ return entry.id;
158
+ }
@@ -1,18 +1,22 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import { useTranslation } from 'react-i18next';
3
- import { ChevronRight, Plus } from 'lucide-react';
4
- import { AccountDot } from '../agents/AccountDot.js';
3
+ import { Plus } from 'lucide-react';
5
4
  import { ModelOptionControl } from '../agents/ModelOptionControl.js';
6
5
  import { carryOptions } from '../agents/model-options.js';
7
6
  import { optionWord } from '../agents/option-words.js';
8
- import { ACCOUNT_TONE_CLASSES, accountName, accountStatusLine, offeredAccounts } from '../agents/accounts.js';
7
+ import { AccountDot } from '../agents/AccountDot.js';
8
+ import { accountName, offeredAccounts } from '../agents/accounts.js';
9
9
  import { accountFor, forgetChatSelection, rememberChatAccount, rememberChatSelection, selectionFor, useChatPreferences } from '../chat/preferences.js';
10
+ import { knownAccounts, useProviderAccounts } from '../state/provider-accounts.js';
11
+ import { useChatHost } from '../host.js';
12
+ import { useHostCanReorderAccounts } from '../host-hooks.js';
10
13
  import { useChatScope } from '../scope.js';
14
+ import { reorderAccounts } from './account-actions.js';
15
+ import { AccountOrderList } from './AccountOrderList.js';
11
16
  import { providerAbilities } from './provider-abilities.js';
12
17
  import { DetailHeader, SettingsRow, SettingsSection } from '@adecore/ui/settings';
13
18
  import { Button, Icon, Select } from '@adecore/ui';
14
19
  import { CliTile } from './parts.js';
15
- import { knownAccounts, useProviderAccounts } from '../state/provider-accounts.js';
16
20
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
17
21
  const PROVIDER_DEFAULT = '';
18
22
  /* One row per knob the chosen model exposes; the composer's option picker shows the same descriptors. */
@@ -85,7 +89,7 @@ function ModelOptionRows(t0) {
85
89
  }
86
90
  /* One CLI: what it is, what a new chat of it starts with unless `defaults` is off, and its accounts. */
87
91
  export function CliDetail(t0) {
88
- const $ = _c(49);
92
+ const $ = _c(53);
89
93
  const {
90
94
  provider,
91
95
  entries,
@@ -97,9 +101,9 @@ export function CliDetail(t0) {
97
101
  const {
98
102
  t
99
103
  } = useTranslation("agent-providers");
100
- const {
101
- id: scopeId
102
- } = useChatScope();
104
+ const scope = useChatScope();
105
+ const host = useChatHost();
106
+ const canReorder = useHostCanReorderAccounts(scope.id);
103
107
  const preferences = useChatPreferences();
104
108
  let t1;
105
109
  if ($[0] !== preferences || $[1] !== provider.kind) {
@@ -129,14 +133,14 @@ export function CliDetail(t0) {
129
133
  t2 = $[5];
130
134
  }
131
135
  const model = t2;
136
+ const canAddAccount = login !== null;
137
+ const ordered = canReorder && entries !== null && entries.length >= 2;
132
138
  const machineAccounts = useProviderAccounts(knownAccounts);
133
- let canAddAccount;
134
139
  let t3;
135
140
  let t4;
136
- if ($[8] !== defaults || $[9] !== entries || $[10] !== login || $[11] !== machineAccounts || $[12] !== model || $[13] !== onAddAccount || $[14] !== preferences || $[15] !== provider || $[16] !== scopeId || $[17] !== selection?.options || $[18] !== t) {
137
- const picked = accountFor(preferences, scopeId, provider.kind, machineAccounts) ?? provider.kind;
138
- const choosable = offeredAccounts(entries ?? [], picked);
139
- canAddAccount = login !== null;
141
+ if ($[8] !== canAddAccount || $[9] !== canReorder || $[10] !== defaults || $[11] !== entries || $[12] !== machineAccounts || $[13] !== model || $[14] !== onAddAccount || $[15] !== preferences || $[16] !== provider || $[17] !== scope.id || $[18] !== selection?.options || $[19] !== t) {
142
+ const picked = accountFor(preferences, scope.id, provider.kind, machineAccounts) ?? provider.kind;
143
+ const choosable = canReorder ? [] : offeredAccounts(entries ?? [], picked);
140
144
  let t5;
141
145
  if ($[22] !== provider.kind) {
142
146
  t5 = /*#__PURE__*/_jsx(CliTile, {
@@ -203,7 +207,7 @@ export function CliDetail(t0) {
203
207
  }
204
208
  t4 = defaults && /*#__PURE__*/_jsxs(SettingsSection, {
205
209
  title: t("cli.defaults.title"),
206
- description: t("cli.defaults.description"),
210
+ description: t(canReorder ? "cli.defaults.description" : "cli.defaults.descriptionWithAccount"),
207
211
  children: [choosable.length > 0 && /*#__PURE__*/_jsx(SettingsRow, {
208
212
  searchId: "providers.defaults.account",
209
213
  label: t("cli.defaults.account"),
@@ -221,7 +225,7 @@ export function CliDetail(t0) {
221
225
  className: "size-2"
222
226
  })
223
227
  })),
224
- onValueChange: id => rememberChatAccount(scopeId, provider.kind, id)
228
+ onValueChange: id => rememberChatAccount(scope.id, provider.kind, id)
225
229
  })
226
230
  }), provider.models.length > 0 && /*#__PURE__*/_jsx(SettingsRow, {
227
231
  searchId: "providers.defaults.model",
@@ -258,78 +262,68 @@ export function CliDetail(t0) {
258
262
  label: t("cli.defaults.usesCliDefault")
259
263
  })]
260
264
  });
261
- $[8] = defaults;
262
- $[9] = entries;
263
- $[10] = login;
264
- $[11] = machineAccounts;
265
- $[12] = model;
266
- $[13] = onAddAccount;
267
- $[14] = preferences;
268
- $[15] = provider;
269
- $[16] = scopeId;
270
- $[17] = selection?.options;
271
- $[18] = t;
272
- $[19] = canAddAccount;
265
+ $[8] = canAddAccount;
266
+ $[9] = canReorder;
267
+ $[10] = defaults;
268
+ $[11] = entries;
269
+ $[12] = machineAccounts;
270
+ $[13] = model;
271
+ $[14] = onAddAccount;
272
+ $[15] = preferences;
273
+ $[16] = provider;
274
+ $[17] = scope.id;
275
+ $[18] = selection?.options;
276
+ $[19] = t;
273
277
  $[20] = t3;
274
278
  $[21] = t4;
275
279
  } else {
276
- canAddAccount = $[19];
277
280
  t3 = $[20];
278
281
  t4 = $[21];
279
282
  }
280
283
  let t5;
281
- if ($[38] !== canAddAccount || $[39] !== entries || $[40] !== login || $[41] !== onPickAccount || $[42] !== provider.name || $[43] !== t) {
284
+ if ($[38] !== canAddAccount || $[39] !== entries || $[40] !== host || $[41] !== login || $[42] !== onPickAccount || $[43] !== ordered || $[44] !== provider.kind || $[45] !== provider.name || $[46] !== scope || $[47] !== t) {
282
285
  t5 = entries === null ? /*#__PURE__*/_jsx("p", {
283
286
  className: "text-xs text-text-faint",
284
287
  children: t("list.noAccounts")
285
288
  }) : /*#__PURE__*/_jsx(SettingsSection, {
286
289
  title: t("cli.accounts"),
290
+ description: ordered ? t("cli.accountsOrder") : undefined,
287
291
  footer: canAddAccount ? undefined : t("cli.onlyDefault", {
288
292
  provider: provider.name
289
293
  }),
290
- children: entries.map(entry_3 => {
291
- const status = accountStatusLine(entry_3.status, login === "terminal");
292
- return /*#__PURE__*/_jsxs("button", {
293
- type: "button",
294
- className: "flex w-full min-w-0 items-center gap-3 px-4.5 py-3 text-left first:rounded-t-xl last:rounded-b-xl hover:bg-surface-hover",
295
- onClick: () => onPickAccount(entry_3.id),
296
- children: [/*#__PURE__*/_jsx(AccountDot, {
297
- color: entry_3.account.color
298
- }), /*#__PURE__*/_jsx("span", {
299
- className: "min-w-0 grow truncate text-sm text-text",
300
- children: accountName(entry_3, provider.name)
301
- }), /*#__PURE__*/_jsx("span", {
302
- className: `shrink-0 text-xs ${ACCOUNT_TONE_CLASSES[status.tone]}`,
303
- children: status.text
304
- }), /*#__PURE__*/_jsx(Icon, {
305
- icon: ChevronRight,
306
- size: 14,
307
- className: "shrink-0 text-text-faint"
308
- })]
309
- }, entry_3.id);
294
+ children: /*#__PURE__*/_jsx(AccountOrderList, {
295
+ entries: entries,
296
+ providerName: provider.name,
297
+ login: login,
298
+ onReorder: ordered ? ids => void reorderAccounts(scope, host, provider.kind, ids) : null,
299
+ onPickAccount: onPickAccount
310
300
  })
311
301
  });
312
302
  $[38] = canAddAccount;
313
303
  $[39] = entries;
314
- $[40] = login;
315
- $[41] = onPickAccount;
316
- $[42] = provider.name;
317
- $[43] = t;
318
- $[44] = t5;
304
+ $[40] = host;
305
+ $[41] = login;
306
+ $[42] = onPickAccount;
307
+ $[43] = ordered;
308
+ $[44] = provider.kind;
309
+ $[45] = provider.name;
310
+ $[46] = scope;
311
+ $[47] = t;
312
+ $[48] = t5;
319
313
  } else {
320
- t5 = $[44];
314
+ t5 = $[48];
321
315
  }
322
316
  let t6;
323
- if ($[45] !== t3 || $[46] !== t4 || $[47] !== t5) {
317
+ if ($[49] !== t3 || $[50] !== t4 || $[51] !== t5) {
324
318
  t6 = /*#__PURE__*/_jsxs(_Fragment, {
325
319
  children: [t3, t4, t5]
326
320
  });
327
- $[45] = t3;
328
- $[46] = t4;
329
- $[47] = t5;
330
- $[48] = t6;
321
+ $[49] = t3;
322
+ $[50] = t4;
323
+ $[51] = t5;
324
+ $[52] = t6;
331
325
  } else {
332
- t6 = $[48];
326
+ t6 = $[52];
333
327
  }
334
328
  return t6;
335
329
  }
@@ -4,5 +4,6 @@ import type { ChatScope } from '../scope.js';
4
4
  export declare function saveAccounts(scope: ChatScope, host: Pick<ChatHost, 'notify'>, accounts: ProviderAccountMap): Promise<boolean>;
5
5
  export declare function saveAccount(scope: ChatScope, host: Pick<ChatHost, 'notify'>, id: string, account: ProviderAccount): Promise<boolean>;
6
6
  export declare function removeAccount(scope: ChatScope, host: Pick<ChatHost, 'notify'>, id: string, kind: AgentKind): Promise<void>;
7
+ export declare function reorderAccounts(scope: ChatScope, host: Pick<ChatHost, 'notify'>, kind: AgentKind, ids: readonly string[]): Promise<void>;
7
8
  export declare function createAccount(scope: ChatScope, kind: AgentKind, label: string, color: string): Promise<string>;
8
9
  export declare function linkAccount(scope: ChatScope, id: string, account: ProviderAccount): Promise<void>;
@@ -52,6 +52,45 @@ export async function removeAccount(scope, host, id, kind) {
52
52
  rememberChatAccount(scope.id, kind, null);
53
53
  }
54
54
  }
55
+ /* Puts the accounts of one CLI in this order, showing it at once; a refusal puts the host's order back and says why. */
56
+ export async function reorderAccounts(scope, host, kind, ids) {
57
+ const store = useProviderAccountsStore.getState();
58
+ const before = providerAccountsOf(scope.id).accounts;
59
+ if (before !== null) {
60
+ const accounts = {
61
+ ...before.accounts
62
+ };
63
+ for (const [order, id] of ids.entries()) {
64
+ const account = accounts[id];
65
+ if (account !== undefined) {
66
+ accounts[id] = {
67
+ ...account,
68
+ order
69
+ };
70
+ }
71
+ }
72
+ store.set(scope.id, {
73
+ ...before,
74
+ accounts
75
+ });
76
+ }
77
+ try {
78
+ store.set(scope.id, await linkTo(scope).request('accounts.reorder', {
79
+ kind,
80
+ ids: [...ids]
81
+ }));
82
+ } catch (e) {
83
+ if (before !== null) {
84
+ store.set(scope.id, before);
85
+ }
86
+ host.notify({
87
+ id: `providers-reorder-${scope.id}`,
88
+ kind: 'error',
89
+ title: words('account.reorderFailed'),
90
+ description: errorMessage(e)
91
+ });
92
+ }
93
+ }
55
94
  /* An account in a folder the host makes for it; answers its id. Throws what the host said, for the form to show. */
56
95
  export async function createAccount(scope, kind, label, color) {
57
96
  const {
@@ -3,7 +3,7 @@ export { AgentIcon } from '../agents/AgentIcon.js';
3
3
  export { AgentModelLabel } from '../agents/AgentModelLabel.js';
4
4
  export { ModelOptionControl } from '../agents/ModelOptionControl.js';
5
5
  export { ProviderLogo } from '../agents/ProviderLogo.js';
6
- export { type AccountEntry, accountsOfKind, ACCOUNT_TONE_CLASSES, accountStatusLine, canContinueOn, type AccountTone } from '../agents/accounts.js';
6
+ export { type AccountEntry, type AccountRule, accountsOfKind, ACCOUNT_TONE_CLASSES, accountStatusLine, canContinueOn, projectDefault, topAccountEntry, type AccountTone } from '../agents/accounts.js';
7
7
  export { modelName, useModelName, shortModelName } from '../agents/model-name.js';
8
8
  export { carryOptions } from '../agents/model-options.js';
9
9
  export { type ModelRequirement } from '../agents/model-requirement.js';
@@ -4,7 +4,7 @@ export { AgentIcon } from '../agents/AgentIcon.js';
4
4
  export { AgentModelLabel } from '../agents/AgentModelLabel.js';
5
5
  export { ModelOptionControl } from '../agents/ModelOptionControl.js';
6
6
  export { ProviderLogo } from '../agents/ProviderLogo.js';
7
- export { accountsOfKind, ACCOUNT_TONE_CLASSES, accountStatusLine, canContinueOn } from '../agents/accounts.js';
7
+ export { accountsOfKind, ACCOUNT_TONE_CLASSES, accountStatusLine, canContinueOn, projectDefault, topAccountEntry } from '../agents/accounts.js';
8
8
  export { modelName, useModelName, shortModelName } from '../agents/model-name.js';
9
9
  export { carryOptions } from '../agents/model-options.js';
10
10
  export {} from '../agents/model-requirement.js';
@@ -42,7 +42,12 @@ export function limitGroups(snapshot, accounts) {
42
42
  entry: null,
43
43
  status: account.status
44
44
  }));
45
- const rows = [...read, ...unread];
45
+ // In the person's order, as every other list of accounts; a read account the list does not know yet goes last.
46
+ const place = id => {
47
+ const index = known.findIndex(account => account.id === id);
48
+ return index === -1 ? known.length : index;
49
+ };
50
+ const rows = [...read, ...unread].sort((a, b) => place(a.id) - place(b.id));
46
51
  return rows.length === 0 ? [] : [{
47
52
  kind,
48
53
  accounts: rows
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents-react",
3
- "version": "0.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -72,11 +72,11 @@
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.47.0",
76
- "@adecore/editor": "0.47.0",
77
- "@adecore/editor-react": "0.47.0",
78
- "@adecore/intelligent-ui": "0.47.0",
79
- "@adecore/merge": "0.47.0",
75
+ "@adecore/agent-contracts": "0.48.0",
76
+ "@adecore/editor": "0.48.0",
77
+ "@adecore/editor-react": "0.48.0",
78
+ "@adecore/intelligent-ui": "0.48.0",
79
+ "@adecore/merge": "0.48.0",
80
80
  "@codemirror/commands": "^6.11.1",
81
81
  "@codemirror/language": "^6.13.1",
82
82
  "@codemirror/state": "^6.7.6",
@@ -100,14 +100,14 @@
100
100
  "zustand": "^5.0.16"
101
101
  },
102
102
  "peerDependencies": {
103
- "@adecore/ui": "^0.47.0",
103
+ "@adecore/ui": "^0.48.0",
104
104
  "i18next": "^26.4.2",
105
105
  "react": "^19.3.0",
106
106
  "react-dom": "^19.3.0",
107
107
  "react-i18next": "^17.0.15"
108
108
  },
109
109
  "devDependencies": {
110
- "@adecore/ui": "0.47.0",
110
+ "@adecore/ui": "0.48.0",
111
111
  "@types/bun": "^1.4.4",
112
112
  "@types/react": "^19.3.0",
113
113
  "@types/react-dom": "^19.3.0",
@@ -1,5 +1,5 @@
1
1
  import i18next from 'i18next';
2
- import type { AgentKind, ProviderAccount, ProviderAccounts, ProviderAccountStatus } from '@adecore/agent-contracts';
2
+ import { orderedAccountIds, type AgentKind, type ProviderAccount, type ProviderAccounts, type ProviderAccountStatus } from '@adecore/agent-contracts';
3
3
  import type { AccentChoice, ChatHost } from '../host';
4
4
 
5
5
  /*
@@ -24,7 +24,7 @@ export interface AccountEntry {
24
24
  isDefault: boolean;
25
25
  }
26
26
 
27
- /* The accounts of one CLI, its default one first and the others in the order the machine keeps them. */
27
+ /* The accounts of one CLI in the person's order, the one every list and menu shows. */
28
28
  export function accountsOfKind(accounts: ProviderAccounts | null, kind: AgentKind): AccountEntry[] {
29
29
  if (accounts === null) {
30
30
  return [];
@@ -32,10 +32,46 @@ export function accountsOfKind(accounts: ProviderAccounts | null, kind: AgentKin
32
32
 
33
33
  const statuses = new Map(accounts.statuses.map((status) => [status.id, status]));
34
34
 
35
- return Object.entries(accounts.accounts)
36
- .filter(([, account]) => account.kind === kind)
37
- .map(([id, account]) => ({ id, account, status: statuses.get(id) ?? null, isDefault: id === kind }))
38
- .sort((a, b) => Number(b.isDefault) - Number(a.isDefault));
35
+ return orderedAccountIds(accounts.accounts, kind).flatMap((id) => {
36
+ const account = accounts.accounts[id];
37
+
38
+ return account === undefined ? [] : [{ id, account, status: statuses.get(id) ?? null, isDefault: id === kind }];
39
+ });
40
+ }
41
+
42
+ /* The account a new chat of this CLI starts on when nothing names one, as the machine decides it. */
43
+ export function topAccountEntry(entries: readonly AccountEntry[]): AccountEntry | null {
44
+ return entries.find((entry) => entry.account.enabled !== false) ?? null;
45
+ }
46
+
47
+ /* The ids of an order with one moved to another place, clamped to the ends. */
48
+ export function movedIds(ids: readonly string[], id: string, to: number): string[] {
49
+ const rest = ids.filter((candidate) => candidate !== id);
50
+ const place = Math.max(0, Math.min(to, rest.length));
51
+
52
+ return [...rest.slice(0, place), id, ...rest.slice(place)];
53
+ }
54
+
55
+ /* What a project says about the accounts of each CLI: the one its new chats start on, and those it never offers. */
56
+ export type AccountRule = Partial<Record<string, { default?: string; off?: readonly string[] }>>;
57
+
58
+ /* The accounts a project offers, as `offeredAccounts` gives them; the one in use stays even when the project turned it off. */
59
+ export function projectOffered(
60
+ entries: readonly AccountEntry[],
61
+ rule: AccountRule | null | undefined,
62
+ kind: AgentKind,
63
+ current: string | undefined
64
+ ): AccountEntry[] {
65
+ const off = rule?.[kind]?.off ?? [];
66
+
67
+ return entries.filter((entry) => !off.includes(entry.id) || entry.id === current);
68
+ }
69
+
70
+ /* The project's own default account of a CLI, while the machine still has it and it is on. */
71
+ export function projectDefault(entries: readonly AccountEntry[], rule: AccountRule | null | undefined, kind: AgentKind): string | null {
72
+ const id = rule?.[kind]?.default;
73
+
74
+ return entries.some((entry) => entry.id === id && entry.account.enabled !== false) ? (id ?? null) : null;
39
75
  }
40
76
 
41
77
  /* A default account nobody named goes by its CLI's name. */
@@ -1,11 +1,22 @@
1
1
  import type { AgentKind, ProviderAccounts } from '@adecore/agent-contracts';
2
- import { accountName, accountsOfKind, hasAccountChoice, offeredAccounts, type AccountEntry } from '../agents/accounts';
2
+ import {
3
+ accountName,
4
+ accountsOfKind,
5
+ hasAccountChoice,
6
+ offeredAccounts,
7
+ projectDefault,
8
+ projectOffered,
9
+ type AccountEntry,
10
+ type AccountRule
11
+ } from '../agents/accounts';
12
+ import { useHostAccountRule } from '../host-hooks';
13
+ import { useChatScope } from '../scope';
3
14
  import { useProviderAccounts, type ProviderAccountsRow } from '../state/provider-accounts';
4
15
  import { useProviders } from '../state/providers';
5
16
 
6
17
  export interface AccountChoice {
7
18
  accounts: ProviderAccounts;
8
- /* The accounts a person may pick for this CLI: those that are on, and the one in use. */
19
+ /* The accounts a person may pick for this CLI: those that are on and the chat's project offers, and the one in use. */
9
20
  offered: AccountEntry[];
10
21
  /* The account the chat runs under, by id; the CLI's kind for its default account. */
11
22
  currentId: string;
@@ -19,7 +30,9 @@ export interface AccountChoice {
19
30
  * The accounts of a chat's CLI on the machine in scope and the one the chat runs under, or null while
20
31
  * the CLI has fewer than two accounts that are on: with one there is nothing to choose or tell apart.
21
32
  */
22
- export function useAccountChoice(kind: AgentKind | null, account: string | undefined): AccountChoice | null {
33
+ export function useAccountChoice(kind: AgentKind | null, account: string | undefined, chatId: string): AccountChoice | null {
34
+ const scope = useChatScope();
35
+ const rule = useHostAccountRule(scope.id, chatId);
23
36
  const accounts = useProviderAccounts((row) => row.accounts);
24
37
  const providerName = useProviders((row) => row.providers.find((entry) => entry.kind === kind)?.name) ?? kind ?? '';
25
38
 
@@ -37,7 +50,7 @@ export function useAccountChoice(kind: AgentKind | null, account: string | undef
37
50
 
38
51
  return {
39
52
  accounts,
40
- offered: offeredAccounts(entries, currentId),
53
+ offered: projectOffered(offeredAccounts(entries, currentId), rule, kind, currentId),
41
54
  currentId,
42
55
  current: entries.find((entry) => entry.id === currentId) ?? null,
43
56
  providerName,
@@ -54,14 +67,21 @@ export function useAccountChoice(kind: AgentKind | null, account: string | undef
54
67
  export type NewAccountChoice =
55
68
  | { status: 'loading' }
56
69
  | { status: 'unsupported' }
57
- | { status: 'ready'; offered: AccountEntry[]; providerName: string; nameOf(entry: AccountEntry): string };
70
+ | {
71
+ status: 'ready';
72
+ offered: AccountEntry[];
73
+ /* The account the project starts new chats of this CLI on, by id; null leaves it to the order. */
74
+ projectDefault: string | null;
75
+ providerName: string;
76
+ nameOf(entry: AccountEntry): string;
77
+ };
58
78
 
59
79
  // One object each, so a render that changes nothing hands back the same answer.
60
80
  const LOADING: NewAccountChoice = { status: 'loading' };
61
81
  const UNSUPPORTED: NewAccountChoice = { status: 'unsupported' };
62
82
 
63
83
  /* `useNewAccountChoice` without React, for its tests. */
64
- export function newAccountChoiceOf(row: ProviderAccountsRow, kind: AgentKind | null, providerName: string): NewAccountChoice {
84
+ export function newAccountChoiceOf(row: ProviderAccountsRow, kind: AgentKind | null, providerName: string, rule: AccountRule | null = null): NewAccountChoice {
65
85
  if (kind === null || !row.loaded) {
66
86
  return LOADING;
67
87
  }
@@ -75,16 +95,17 @@ export function newAccountChoiceOf(row: ProviderAccountsRow, kind: AgentKind | n
75
95
 
76
96
  return {
77
97
  status: 'ready',
78
- offered: offeredAccounts(entries, undefined),
98
+ offered: projectOffered(offeredAccounts(entries, undefined), rule, kind, undefined),
99
+ projectDefault: projectDefault(entries, rule, kind),
79
100
  providerName,
80
101
  nameOf: (entry: AccountEntry) => accountName(entry, providerName)
81
102
  };
82
103
  }
83
104
 
84
- /* The accounts a new chat or agent of this CLI may start under on the machine in scope. */
85
- export function useNewAccountChoice(kind: AgentKind | null): NewAccountChoice {
105
+ /* The accounts a new chat or agent of this CLI may start under on the machine in scope, within what the project of that start says. */
106
+ export function useNewAccountChoice(kind: AgentKind | null, rule: AccountRule | null = null): NewAccountChoice {
86
107
  const row = useProviderAccounts((entry) => entry);
87
108
  const providerName = useProviders((entry) => entry.providers.find((provider) => provider.kind === kind)?.name) ?? kind ?? '';
88
109
 
89
- return newAccountChoiceOf(row, kind, providerName);
110
+ return newAccountChoiceOf(row, kind, providerName, rule);
90
111
  }