@adecore/agents-react 0.47.0 → 0.48.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 (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
@@ -1,4 +1,4 @@
1
- import type { AgentKind, ProviderAccount, ProviderAccounts, ProviderAccountStatus } from '@adecore/agent-contracts';
1
+ import { type AgentKind, type ProviderAccount, type ProviderAccounts, type ProviderAccountStatus } from '@adecore/agent-contracts';
2
2
  import type { AccentChoice, ChatHost } from '../host.js';
3
3
  export declare function accountColor(color: string | undefined, accents: readonly AccentChoice[]): string | undefined;
4
4
  export declare const FOLDER_VARIABLES: Partial<Record<AgentKind, string>>;
@@ -9,6 +9,14 @@ export interface AccountEntry {
9
9
  isDefault: boolean;
10
10
  }
11
11
  export declare function accountsOfKind(accounts: ProviderAccounts | null, kind: AgentKind): AccountEntry[];
12
+ export declare function topAccountEntry(entries: readonly AccountEntry[]): AccountEntry | null;
13
+ export declare function movedIds(ids: readonly string[], id: string, to: number): string[];
14
+ export type AccountRule = Partial<Record<string, {
15
+ default?: string;
16
+ off?: readonly string[];
17
+ }>>;
18
+ export declare function projectOffered(entries: readonly AccountEntry[], rule: AccountRule | null | undefined, kind: AgentKind, current: string | undefined): AccountEntry[];
19
+ export declare function projectDefault(entries: readonly AccountEntry[], rule: AccountRule | null | undefined, kind: AgentKind): string | null;
12
20
  export declare function accountName(entry: Pick<AccountEntry, 'id' | 'account' | 'isDefault'>, providerName: string): string;
13
21
  export type AccountLogin = 'terminal' | 'chat' | null;
14
22
  export declare function accountLoginOf(accounts: ProviderAccounts | null | undefined, kind: AgentKind): AccountLogin;
@@ -1,4 +1,5 @@
1
1
  import i18next from 'i18next';
2
+ import { orderedAccountIds } from '@adecore/agent-contracts';
2
3
  /*
3
4
  * An account wears one of the host's accents, so the app paints from one palette. A color that is none
4
5
  * of them (an older name, or one written by hand) reads as undefined, and the dot takes the accent.
@@ -14,18 +15,41 @@ export const FOLDER_VARIABLES = {
14
15
  claude: 'CLAUDE_CONFIG_DIR',
15
16
  codex: 'CODEX_HOME'
16
17
  };
17
- /* The accounts of one CLI, its default one first and the others in the order the machine keeps them. */
18
+ /* The accounts of one CLI in the person's order, the one every list and menu shows. */
18
19
  export function accountsOfKind(accounts, kind) {
19
20
  if (accounts === null) {
20
21
  return [];
21
22
  }
22
23
  const statuses = new Map(accounts.statuses.map(status => [status.id, status]));
23
- return Object.entries(accounts.accounts).filter(([, account]) => account.kind === kind).map(([id, account]) => ({
24
- id,
25
- account,
26
- status: statuses.get(id) ?? null,
27
- isDefault: id === kind
28
- })).sort((a, b) => Number(b.isDefault) - Number(a.isDefault));
24
+ return orderedAccountIds(accounts.accounts, kind).flatMap(id => {
25
+ const account = accounts.accounts[id];
26
+ return account === undefined ? [] : [{
27
+ id,
28
+ account,
29
+ status: statuses.get(id) ?? null,
30
+ isDefault: id === kind
31
+ }];
32
+ });
33
+ }
34
+ /* The account a new chat of this CLI starts on when nothing names one, as the machine decides it. */
35
+ export function topAccountEntry(entries) {
36
+ return entries.find(entry => entry.account.enabled !== false) ?? null;
37
+ }
38
+ /* The ids of an order with one moved to another place, clamped to the ends. */
39
+ export function movedIds(ids, id, to) {
40
+ const rest = ids.filter(candidate => candidate !== id);
41
+ const place = Math.max(0, Math.min(to, rest.length));
42
+ return [...rest.slice(0, place), id, ...rest.slice(place)];
43
+ }
44
+ /* The accounts a project offers, as `offeredAccounts` gives them; the one in use stays even when the project turned it off. */
45
+ export function projectOffered(entries, rule, kind, current) {
46
+ const off = rule?.[kind]?.off ?? [];
47
+ return entries.filter(entry => !off.includes(entry.id) || entry.id === current);
48
+ }
49
+ /* The project's own default account of a CLI, while the machine still has it and it is on. */
50
+ export function projectDefault(entries, rule, kind) {
51
+ const id = rule?.[kind]?.default;
52
+ return entries.some(entry => entry.id === id && entry.account.enabled !== false) ? id ?? null : null;
29
53
  }
30
54
  /* A default account nobody named goes by its CLI's name. */
31
55
  export function accountName(entry, providerName) {
@@ -1,5 +1,5 @@
1
1
  import type { AgentKind, ProviderAccounts } from '@adecore/agent-contracts';
2
- import { type AccountEntry } from '../agents/accounts.js';
2
+ import { type AccountEntry, type AccountRule } from '../agents/accounts.js';
3
3
  import { type ProviderAccountsRow } from '../state/provider-accounts.js';
4
4
  export interface AccountChoice {
5
5
  accounts: ProviderAccounts;
@@ -9,7 +9,7 @@ export interface AccountChoice {
9
9
  providerName: string;
10
10
  nameOf(entry: AccountEntry): string;
11
11
  }
12
- export declare function useAccountChoice(kind: AgentKind | null, account: string | undefined): AccountChoice | null;
12
+ export declare function useAccountChoice(kind: AgentKind | null, account: string | undefined, chatId: string): AccountChoice | null;
13
13
  export type NewAccountChoice = {
14
14
  status: 'loading';
15
15
  } | {
@@ -17,8 +17,9 @@ export type NewAccountChoice = {
17
17
  } | {
18
18
  status: 'ready';
19
19
  offered: AccountEntry[];
20
+ projectDefault: string | null;
20
21
  providerName: string;
21
22
  nameOf(entry: AccountEntry): string;
22
23
  };
23
- export declare function newAccountChoiceOf(row: ProviderAccountsRow, kind: AgentKind | null, providerName: string): NewAccountChoice;
24
- export declare function useNewAccountChoice(kind: AgentKind | null): NewAccountChoice;
24
+ export declare function newAccountChoiceOf(row: ProviderAccountsRow, kind: AgentKind | null, providerName: string, rule?: AccountRule | null): NewAccountChoice;
25
+ export declare function useNewAccountChoice(kind: AgentKind | null, rule?: AccountRule | null): NewAccountChoice;
@@ -1,13 +1,17 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
- import { accountName, accountsOfKind, hasAccountChoice, offeredAccounts } from '../agents/accounts.js';
2
+ import { accountName, accountsOfKind, hasAccountChoice, offeredAccounts, projectDefault, projectOffered } from '../agents/accounts.js';
3
+ import { useHostAccountRule } from '../host-hooks.js';
4
+ import { useChatScope } from '../scope.js';
3
5
  import { useProviderAccounts } from '../state/provider-accounts.js';
4
6
  import { useProviders } from '../state/providers.js';
5
7
  /*
6
8
  * The accounts of a chat's CLI on the machine in scope and the one the chat runs under, or null while
7
9
  * the CLI has fewer than two accounts that are on: with one there is nothing to choose or tell apart.
8
10
  */
9
- export function useAccountChoice(kind, account) {
10
- const $ = _c(17);
11
+ export function useAccountChoice(kind, account, chatId) {
12
+ const $ = _c(18);
13
+ const scope = useChatScope();
14
+ const rule = useHostAccountRule(scope.id, chatId);
11
15
  const accounts = useProviderAccounts(_temp);
12
16
  const providerName = useProviders(row_0 => row_0.providers.find(entry => entry.kind === kind)?.name) ?? kind ?? "";
13
17
  if (kind === null || accounts === null) {
@@ -18,7 +22,7 @@ export function useAccountChoice(kind, account) {
18
22
  let t2;
19
23
  let t3;
20
24
  let t4;
21
- if ($[0] !== account || $[1] !== accounts || $[2] !== kind) {
25
+ if ($[0] !== account || $[1] !== accounts || $[2] !== kind || $[3] !== rule) {
22
26
  t4 = Symbol.for("react.early_return_sentinel");
23
27
  bb0: {
24
28
  const entries = accountsOfKind(accounts, kind);
@@ -28,38 +32,39 @@ export function useAccountChoice(kind, account) {
28
32
  }
29
33
  const currentId = account ?? kind;
30
34
  t0 = accounts;
31
- t1 = offeredAccounts(entries, currentId);
35
+ t1 = projectOffered(offeredAccounts(entries, currentId), rule, kind, currentId);
32
36
  t2 = currentId;
33
37
  t3 = entries.find(entry_0 => entry_0.id === currentId) ?? null;
34
38
  }
35
39
  $[0] = account;
36
40
  $[1] = accounts;
37
41
  $[2] = kind;
38
- $[3] = t0;
39
- $[4] = t1;
40
- $[5] = t2;
41
- $[6] = t3;
42
- $[7] = t4;
42
+ $[3] = rule;
43
+ $[4] = t0;
44
+ $[5] = t1;
45
+ $[6] = t2;
46
+ $[7] = t3;
47
+ $[8] = t4;
43
48
  } else {
44
- t0 = $[3];
45
- t1 = $[4];
46
- t2 = $[5];
47
- t3 = $[6];
48
- t4 = $[7];
49
+ t0 = $[4];
50
+ t1 = $[5];
51
+ t2 = $[6];
52
+ t3 = $[7];
53
+ t4 = $[8];
49
54
  }
50
55
  if (t4 !== Symbol.for("react.early_return_sentinel")) {
51
56
  return t4;
52
57
  }
53
58
  let t5;
54
- if ($[8] !== providerName) {
59
+ if ($[9] !== providerName) {
55
60
  t5 = entry_1 => accountName(entry_1, providerName);
56
- $[8] = providerName;
57
- $[9] = t5;
61
+ $[9] = providerName;
62
+ $[10] = t5;
58
63
  } else {
59
- t5 = $[9];
64
+ t5 = $[10];
60
65
  }
61
66
  let t6;
62
- if ($[10] !== providerName || $[11] !== t0 || $[12] !== t1 || $[13] !== t2 || $[14] !== t3 || $[15] !== t5) {
67
+ if ($[11] !== providerName || $[12] !== t0 || $[13] !== t1 || $[14] !== t2 || $[15] !== t3 || $[16] !== t5) {
63
68
  t6 = {
64
69
  accounts: t0,
65
70
  offered: t1,
@@ -68,15 +73,15 @@ export function useAccountChoice(kind, account) {
68
73
  providerName,
69
74
  nameOf: t5
70
75
  };
71
- $[10] = providerName;
72
- $[11] = t0;
73
- $[12] = t1;
74
- $[13] = t2;
75
- $[14] = t3;
76
- $[15] = t5;
77
- $[16] = t6;
76
+ $[11] = providerName;
77
+ $[12] = t0;
78
+ $[13] = t1;
79
+ $[14] = t2;
80
+ $[15] = t3;
81
+ $[16] = t5;
82
+ $[17] = t6;
78
83
  } else {
79
- t6 = $[16];
84
+ t6 = $[17];
80
85
  }
81
86
  return t6;
82
87
  }
@@ -91,7 +96,7 @@ const UNSUPPORTED = {
91
96
  status: 'unsupported'
92
97
  };
93
98
  /* `useNewAccountChoice` without React, for its tests. */
94
- export function newAccountChoiceOf(row, kind, providerName) {
99
+ export function newAccountChoiceOf(row, kind, providerName, rule = null) {
95
100
  if (kind === null || !row.loaded) {
96
101
  return LOADING;
97
102
  }
@@ -102,27 +107,30 @@ export function newAccountChoiceOf(row, kind, providerName) {
102
107
  }
103
108
  return {
104
109
  status: 'ready',
105
- offered: offeredAccounts(entries, undefined),
110
+ offered: projectOffered(offeredAccounts(entries, undefined), rule, kind, undefined),
111
+ projectDefault: projectDefault(entries, rule, kind),
106
112
  providerName,
107
113
  nameOf: entry => accountName(entry, providerName)
108
114
  };
109
115
  }
110
- /* The accounts a new chat or agent of this CLI may start under on the machine in scope. */
111
- export function useNewAccountChoice(kind) {
112
- const $ = _c(4);
116
+ /* 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. */
117
+ export function useNewAccountChoice(kind, t0) {
118
+ const $ = _c(5);
119
+ const rule = t0 === undefined ? null : t0;
113
120
  const row = useProviderAccounts(_temp2);
114
121
  const providerName = useProviders(entry_0 => entry_0.providers.find(provider => provider.kind === kind)?.name) ?? kind ?? "";
115
- let t0;
116
- if ($[0] !== kind || $[1] !== providerName || $[2] !== row) {
117
- t0 = newAccountChoiceOf(row, kind, providerName);
122
+ let t1;
123
+ if ($[0] !== kind || $[1] !== providerName || $[2] !== row || $[3] !== rule) {
124
+ t1 = newAccountChoiceOf(row, kind, providerName, rule);
118
125
  $[0] = kind;
119
126
  $[1] = providerName;
120
127
  $[2] = row;
121
- $[3] = t0;
128
+ $[3] = rule;
129
+ $[4] = t1;
122
130
  } else {
123
- t0 = $[3];
131
+ t1 = $[4];
124
132
  }
125
- return t0;
133
+ return t1;
126
134
  }
127
135
  function _temp2(entry) {
128
136
  return entry;
@@ -1,4 +1,4 @@
1
- import type { AgentKind, ChatPreferencesPayload, ModelSelection, ProviderInfo, ProviderAccounts, RuntimeMode } from '@adecore/agent-contracts';
1
+ import { type AgentKind, type ChatPreferencesPayload, type ModelSelection, type ProviderInfo, type ProviderAccounts, type RuntimeMode } from '@adecore/agent-contracts';
2
2
  import { type ChatReadingWidth } from './reading-width.js';
3
3
  import { type ChatSendKey } from './send-key.js';
4
4
  export interface ChatPreferences {
@@ -20,7 +20,7 @@ export declare function startingSelection(preferences: ChatPreferences, provider
20
20
  export declare function withSelection(preferences: ChatPreferences, provider: AgentKind, selection: ModelSelection): ChatPreferences;
21
21
  export declare function accountFor(preferences: ChatPreferences, scopeId: string, provider: AgentKind, accounts?: ProviderAccounts | null): string | null;
22
22
  export declare function withAccount(preferences: ChatPreferences, scopeId: string, provider: AgentKind, account: string | null): ChatPreferences;
23
- export declare function chatPreferencesPayload(preferences: ChatPreferences, scopeId: string, accounts?: ProviderAccounts | null): ChatPreferencesPayload;
23
+ export declare function chatPreferencesPayload(preferences: ChatPreferences, scopeId: string, accounts?: ProviderAccounts | null, ordered?: boolean): ChatPreferencesPayload;
24
24
  export declare const useChatPreferences: import("zustand").UseBoundStore<import("zustand").StoreApi<ChatPreferences>>;
25
25
  export declare function readChatPreferences(): ChatPreferences;
26
26
  export declare let CHAT_PREFERENCES_KEY: string;
@@ -1,4 +1,5 @@
1
1
  import { chatStorageKey, chatStorageLegacyKeys, createChatStore, onChatStorageConfiguration } from '../storage.js';
2
+ import { topAccountOf } from '@adecore/agent-contracts';
2
3
  import { persistedJson } from './persisted-json.js';
3
4
  import { DEFAULT_READING_WIDTH, isChatReadingWidth } from './reading-width.js';
4
5
  import { DEFAULT_SEND_KEY, isChatSendKey } from './send-key.js';
@@ -118,11 +119,16 @@ export function withAccount(preferences, scopeId, provider, account) {
118
119
  }
119
120
  };
120
121
  }
121
- /* What a machine starts a chat with when it starts one with no client mounting it; `accounts` as `accountFor` takes them. */
122
- export function chatPreferencesPayload(preferences, scopeId, accounts) {
123
- const picks = Object.keys(preferences.accountByMachine[scopeId] ?? {}).flatMap(provider => {
124
- const account = accountFor(preferences, scopeId, provider, accounts);
125
- return account === null ? [] : [[provider, account]];
122
+ /*
123
+ * What a machine starts a chat with when it starts one with no client mounting it; `accounts` as
124
+ * `accountFor` takes them. A machine that keeps an order of the accounts (`ordered`) starts on its top
125
+ * account, which this sends too; an older one still starts on the account picked here.
126
+ */
127
+ export function chatPreferencesPayload(preferences, scopeId, accounts, ordered = false) {
128
+ const kinds = ordered ? [...new Set(Object.values(accounts?.accounts ?? {}).map(account => account.kind))] : Object.keys(preferences.accountByMachine[scopeId] ?? {});
129
+ const picks = kinds.flatMap(provider => {
130
+ const account = ordered ? accounts ? topAccountOf(accounts.accounts, provider) : null : accountFor(preferences, scopeId, provider, accounts);
131
+ return account === null || ordered && account === provider ? [] : [[provider, account]];
126
132
  });
127
133
  return {
128
134
  runtimeMode: preferences.runtimeMode,
@@ -9,13 +9,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
9
9
  function AccountPillOf(t0) {
10
10
  const $ = _c(16);
11
11
  const {
12
+ chatId,
12
13
  provider,
13
14
  account
14
15
  } = t0;
15
16
  const {
16
17
  t
17
18
  } = useTranslation("agent-chat");
18
- const choice = useAccountChoice(provider, account);
19
+ const choice = useAccountChoice(provider, account, chatId);
19
20
  if (choice === null) {
20
21
  return null;
21
22
  }
@@ -91,7 +92,7 @@ function AccountPillOf(t0) {
91
92
  }
92
93
  /* Which account a chat node runs under, from the status every client gets; only while its CLI has a choice of accounts. */
93
94
  export function AccountPill(t0) {
94
- const $ = _c(9);
95
+ const $ = _c(10);
95
96
  const {
96
97
  chatId
97
98
  } = t0;
@@ -119,16 +120,18 @@ export function AccountPill(t0) {
119
120
  }
120
121
  const account = useChats(t2);
121
122
  let t3;
122
- if ($[6] !== account || $[7] !== provider) {
123
+ if ($[6] !== account || $[7] !== chatId || $[8] !== provider) {
123
124
  t3 = provider === undefined ? null : /*#__PURE__*/_jsx(AccountPillOf, {
125
+ chatId: chatId,
124
126
  provider: provider,
125
127
  account: account
126
128
  });
127
129
  $[6] = account;
128
- $[7] = provider;
129
- $[8] = t3;
130
+ $[7] = chatId;
131
+ $[8] = provider;
132
+ $[9] = t3;
130
133
  } else {
131
- t3 = $[8];
134
+ t3 = $[9];
132
135
  }
133
136
  return t3;
134
137
  }