@adecore/agents-react 0.46.3 → 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.
- package/dist/agents/accounts.d.ts +9 -1
- package/dist/agents/accounts.js +31 -7
- package/dist/chat/account-choice.d.ts +5 -4
- package/dist/chat/account-choice.js +47 -39
- package/dist/chat/index.d.ts +1 -0
- package/dist/chat/index.js +1 -0
- package/dist/chat/logic/scrubber.js +12 -0
- package/dist/chat/logic/timeline-copy.js +2 -0
- package/dist/chat/logic/timeline.d.ts +6 -1
- package/dist/chat/logic/timeline.js +36 -10
- package/dist/chat/preferences.d.ts +2 -2
- package/dist/chat/preferences.js +11 -5
- package/dist/chat/ui/AccountPill.js +9 -6
- package/dist/chat/ui/ChatActivity.d.ts +2 -1
- package/dist/chat/ui/ChatActivity.js +295 -61
- package/dist/chat/ui/Composer.d.ts +2 -1
- package/dist/chat/ui/Composer.js +492 -486
- package/dist/chat/ui/LimitState.js +180 -172
- package/dist/chat/ui/PromptEditor.js +4 -1
- package/dist/chat/ui/ReferenceChip.d.ts +2 -1
- package/dist/chat/ui/ReferenceChip.js +135 -100
- package/dist/chat/ui/UnifiedDiff.js +22 -19
- package/dist/chat/ui/composer/ComposerControls.js +1 -1
- package/dist/chat/ui/composer/ComposerMenu.js +17 -11
- package/dist/chat/ui/composer/chips.d.ts +3 -0
- package/dist/chat/ui/composer/chips.js +14 -10
- package/dist/chat/ui/composer/use-chat-controls.js +70 -67
- package/dist/chat/ui/diff/EditorEditDiff.d.ts +3 -1
- package/dist/chat/ui/diff/EditorEditDiff.js +24 -18
- package/dist/chat/ui/diff/EditorPatchDiff.d.ts +3 -1
- package/dist/chat/ui/diff/EditorPatchDiff.js +4 -2
- package/dist/chat/ui/diff/diff-props.d.ts +2 -0
- package/dist/chat/ui/reference-icons.d.ts +3 -0
- package/dist/chat/ui/reference-icons.js +15 -2
- package/dist/chat/ui/rows/MessageRows.d.ts +6 -1
- package/dist/chat/ui/rows/MessageRows.js +166 -10
- package/dist/chat/ui/rows/RowContainer.js +21 -22
- package/dist/chat/ui/rows/Rows.js +37 -19
- package/dist/chat/ui/rows/WorkflowRow.d.ts +2 -1
- package/dist/chat/ui/rows/WorkflowRow.js +197 -191
- package/dist/chat/ui/rows/row-rhythm.d.ts +1 -0
- package/dist/chat/ui/rows/row-rhythm.js +12 -3
- package/dist/chat/workflow-list.d.ts +12 -0
- package/dist/chat/workflow-list.js +54 -0
- package/dist/host-hooks.d.ts +3 -0
- package/dist/host-hooks.js +8 -0
- package/dist/host.d.ts +11 -1
- package/dist/index.d.ts +1 -1
- package/dist/locales/en/agent-chat.d.ts +9 -0
- package/dist/locales/en/agent-chat.js +9 -0
- package/dist/locales/en/agent-providers.d.ts +5 -0
- package/dist/locales/en/agent-providers.js +8 -3
- package/dist/locales/nl/agent-chat.d.ts +9 -0
- package/dist/locales/nl/agent-chat.js +9 -0
- package/dist/locales/nl/agent-providers.d.ts +5 -0
- package/dist/locales/nl/agent-providers.js +8 -3
- package/dist/providers/AccountOrderList.d.ts +10 -0
- package/dist/providers/AccountOrderList.js +158 -0
- package/dist/providers/CliDetail.js +55 -61
- package/dist/providers/account-actions.d.ts +1 -0
- package/dist/providers/account-actions.js +39 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/usage/limit-groups.js +6 -1
- package/package.json +8 -8
- package/src/agents/accounts.ts +42 -6
- package/src/chat/account-choice.ts +31 -10
- package/src/chat/index.ts +1 -0
- package/src/chat/logic/scrubber.ts +5 -0
- package/src/chat/logic/timeline-copy.ts +2 -0
- package/src/chat/logic/timeline.ts +33 -2
- package/src/chat/preferences.ts +33 -8
- package/src/chat/ui/AccountPill.tsx +3 -3
- package/src/chat/ui/ChatActivity.tsx +52 -6
- package/src/chat/ui/Composer.tsx +19 -3
- package/src/chat/ui/LimitState.tsx +4 -2
- package/src/chat/ui/PromptEditor.tsx +3 -1
- package/src/chat/ui/ReferenceChip.tsx +15 -5
- package/src/chat/ui/UnifiedDiff.tsx +12 -1
- package/src/chat/ui/composer/ComposerControls.tsx +1 -1
- package/src/chat/ui/composer/ComposerMenu.tsx +4 -2
- package/src/chat/ui/composer/chips.ts +15 -9
- package/src/chat/ui/composer/use-chat-controls.ts +4 -1
- package/src/chat/ui/diff/EditorEditDiff.tsx +9 -4
- package/src/chat/ui/diff/EditorPatchDiff.tsx +5 -1
- package/src/chat/ui/diff/diff-props.ts +3 -0
- package/src/chat/ui/reference-icons.ts +13 -1
- package/src/chat/ui/rows/MessageRows.tsx +35 -0
- package/src/chat/ui/rows/RowContainer.tsx +2 -2
- package/src/chat/ui/rows/Rows.tsx +3 -0
- package/src/chat/ui/rows/WorkflowRow.tsx +9 -4
- package/src/chat/ui/rows/row-rhythm.ts +12 -3
- package/src/chat/workflow-list.ts +65 -0
- package/src/host-hooks.ts +13 -0
- package/src/host.ts +23 -1
- package/src/index.ts +1 -0
- package/src/locales/en/agent-chat.ts +9 -0
- package/src/locales/en/agent-providers.ts +8 -3
- package/src/locales/nl/agent-chat.ts +9 -0
- package/src/locales/nl/agent-providers.ts +8 -3
- package/src/providers/AccountOrderList.tsx +124 -0
- package/src/providers/CliDetail.tsx +33 -28
- package/src/providers/account-actions.ts +30 -0
- package/src/providers/index.ts +11 -1
- package/src/usage/limit-groups.ts +8 -1
package/src/host.ts
CHANGED
|
@@ -23,7 +23,8 @@ import type {
|
|
|
23
23
|
RuntimeMode
|
|
24
24
|
} from '@adecore/agent-contracts';
|
|
25
25
|
import { isApplePlatform } from '@adecore/ui';
|
|
26
|
-
import type {
|
|
26
|
+
import type { AccountRule } from './agents/accounts';
|
|
27
|
+
import type { ReferableKind, Referables } from './chat/chat-references';
|
|
27
28
|
import type { TimelineRow } from './chat/logic/timeline';
|
|
28
29
|
import type { FindReveal } from './chat/ui/find-reveal';
|
|
29
30
|
import type { PromptAction } from './prompts/logic/prompts';
|
|
@@ -172,6 +173,14 @@ export interface ComposerSlotProps {
|
|
|
172
173
|
insert(text: string): void;
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
/* What an app's own mark of a `#` reference gets: what it points at, and the size and class of the mark it stands in for. */
|
|
177
|
+
export interface ReferenceIconProps {
|
|
178
|
+
id: string;
|
|
179
|
+
kind: ReferableKind;
|
|
180
|
+
size: number;
|
|
181
|
+
className?: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
175
184
|
/* What an app's own bar over the composer gets: the chat it stands on, which may be one the bar has nothing for. */
|
|
176
185
|
export interface ComposerHeaderSlotProps {
|
|
177
186
|
scopeId: string;
|
|
@@ -439,12 +448,25 @@ export interface ChatHost {
|
|
|
439
448
|
useReferableChats(): ReadonlyArray<{ id: string; title: string }>;
|
|
440
449
|
/* The views and nodes a message of this chat may point at with `#`, under the names they have right now. */
|
|
441
450
|
useReferables?(scopeId: string, chatId: string): Referables;
|
|
451
|
+
/*
|
|
452
|
+
* The mark of a view or node a `#` points at, in the picker, the composer and a sent message, such as the icon
|
|
453
|
+
* a person chose for it. Drawn in the composer's editor outside this provider, so it reads no context of its
|
|
454
|
+
* own; left out, every reference wears the mark of its kind.
|
|
455
|
+
*/
|
|
456
|
+
ReferenceIcon?: ComponentType<ReferenceIconProps> | null;
|
|
442
457
|
/* Opens a view or zooms to a node a message points at; left out, a chip opens nothing. */
|
|
443
458
|
openReference?(scopeId: string, id: string): void;
|
|
444
459
|
/* Opens the CLI's own login for an account, somewhere the app can run a command; null offers none. */
|
|
445
460
|
openLogin: ((scopeId: string, kind: AgentKind, accountId: string, name: string) => Promise<void>) | null;
|
|
446
461
|
/* Why a login cannot start from here right now, or null when it can. */
|
|
447
462
|
useLoginBlocked(scopeId: string): string | null;
|
|
463
|
+
/* Whether the machine in scope keeps a person's order of the accounts (`accounts.reorder`); left out, it does. */
|
|
464
|
+
useCanReorderAccounts?(scopeId: string): boolean;
|
|
465
|
+
/*
|
|
466
|
+
* What the project of a chat says about its accounts: per CLI the account its new chats start on and
|
|
467
|
+
* the accounts it never offers. Left out, or null, every account that is on is offered.
|
|
468
|
+
*/
|
|
469
|
+
useAccountRule?(scopeId: string, chatId: string): AccountRule | null;
|
|
448
470
|
/*
|
|
449
471
|
* Runs a command a provider's install page shows, its install or its sign-in, where a person sees it run,
|
|
450
472
|
* such as in a new terminal on the scope's machine; left out, the page offers to copy the command only.
|
package/src/index.ts
CHANGED
|
@@ -120,6 +120,10 @@ export default {
|
|
|
120
120
|
showLess: 'Show less',
|
|
121
121
|
quoteGone: 'Quoted reply no longer in this chat.'
|
|
122
122
|
},
|
|
123
|
+
message: {
|
|
124
|
+
heading: 'Message from {{name}}',
|
|
125
|
+
unnamed: 'another node'
|
|
126
|
+
},
|
|
123
127
|
report: {
|
|
124
128
|
heading: 'Report'
|
|
125
129
|
},
|
|
@@ -416,6 +420,11 @@ export default {
|
|
|
416
420
|
monitors_other: '{{count}} monitors',
|
|
417
421
|
pausedUntil: 'paused until {{time}}',
|
|
418
422
|
progress: '{{done}} of {{total}} sub-agents done',
|
|
423
|
+
workflow: 'Workflow',
|
|
424
|
+
workflows_one: '{{count}} workflow',
|
|
425
|
+
workflows_other: '{{count}} workflows',
|
|
426
|
+
workflowProgress: '{{name}} · {{done}}/{{total}}',
|
|
427
|
+
workflowStalled: '{{name}} · no progress',
|
|
419
428
|
needsYou_one: '{{count}} needs you',
|
|
420
429
|
needsYou_other: '{{count}} need you',
|
|
421
430
|
took: {
|
|
@@ -75,7 +75,8 @@ export default {
|
|
|
75
75
|
onlyDefault: '{{provider}} supports only its default account.',
|
|
76
76
|
defaults: {
|
|
77
77
|
title: 'Defaults for new chats',
|
|
78
|
-
description: 'Picking a model
|
|
78
|
+
description: 'Picking a model in a chat also changes its default here.',
|
|
79
|
+
descriptionWithAccount: 'Picking a model or account in a chat also changes its default here.',
|
|
79
80
|
account: 'Account',
|
|
80
81
|
accountFor: 'Default account for {{provider}}',
|
|
81
82
|
model: 'Model',
|
|
@@ -85,7 +86,10 @@ export default {
|
|
|
85
86
|
providerDefault: 'Provider default',
|
|
86
87
|
legacyModel: '{{name}} (legacy)'
|
|
87
88
|
},
|
|
88
|
-
accounts: 'Accounts'
|
|
89
|
+
accounts: 'Accounts',
|
|
90
|
+
accountsOrder: 'New chats and agents start on the top account that is on.',
|
|
91
|
+
defaultTag: 'Default',
|
|
92
|
+
reorderHandle: 'Move {{account}}. Alt+Up and Alt+Down move it too.'
|
|
89
93
|
},
|
|
90
94
|
account: {
|
|
91
95
|
kind: '{{provider}} account',
|
|
@@ -144,7 +148,8 @@ export default {
|
|
|
144
148
|
confirmDescription: 'Its folder and login stay at {{folder}}.',
|
|
145
149
|
confirm: 'Remove account'
|
|
146
150
|
},
|
|
147
|
-
saveFailed: 'Could not save the account'
|
|
151
|
+
saveFailed: 'Could not save the account',
|
|
152
|
+
reorderFailed: 'Could not change the order of the accounts'
|
|
148
153
|
},
|
|
149
154
|
add: {
|
|
150
155
|
title: 'Add {{provider}} account',
|
|
@@ -120,6 +120,10 @@ export default {
|
|
|
120
120
|
showLess: 'Minder tonen',
|
|
121
121
|
quoteGone: 'Geciteerd antwoord staat niet meer in deze chat.'
|
|
122
122
|
},
|
|
123
|
+
message: {
|
|
124
|
+
heading: 'Bericht van {{name}}',
|
|
125
|
+
unnamed: 'een andere node'
|
|
126
|
+
},
|
|
123
127
|
report: {
|
|
124
128
|
heading: 'Rapport'
|
|
125
129
|
},
|
|
@@ -416,6 +420,11 @@ export default {
|
|
|
416
420
|
monitors_other: '{{count}} monitors',
|
|
417
421
|
pausedUntil: 'gepauzeerd tot {{time}}',
|
|
418
422
|
progress: '{{done}} van {{total}} sub-agents klaar',
|
|
423
|
+
workflow: 'Workflow',
|
|
424
|
+
workflows_one: '{{count}} workflow',
|
|
425
|
+
workflows_other: '{{count}} workflows',
|
|
426
|
+
workflowProgress: '{{name}} · {{done}}/{{total}}',
|
|
427
|
+
workflowStalled: '{{name}} · geen voortgang',
|
|
419
428
|
needsYou_one: '{{count}} vraagt aandacht',
|
|
420
429
|
needsYou_other: '{{count}} vragen aandacht',
|
|
421
430
|
took: {
|
|
@@ -75,7 +75,8 @@ export default {
|
|
|
75
75
|
onlyDefault: '{{provider}} kent alleen zijn standaardaccount.',
|
|
76
76
|
defaults: {
|
|
77
77
|
title: 'Standaarden voor nieuwe chats',
|
|
78
|
-
description: 'Een model
|
|
78
|
+
description: 'Een model kiezen in een chat verandert hier ook de standaard.',
|
|
79
|
+
descriptionWithAccount: 'Een model of account kiezen in een chat verandert hier ook de standaard.',
|
|
79
80
|
account: 'Account',
|
|
80
81
|
accountFor: 'Standaardaccount voor {{provider}}',
|
|
81
82
|
model: 'Model',
|
|
@@ -85,7 +86,10 @@ export default {
|
|
|
85
86
|
providerDefault: 'Standaard van de provider',
|
|
86
87
|
legacyModel: '{{name}} (legacy)'
|
|
87
88
|
},
|
|
88
|
-
accounts: 'Accounts'
|
|
89
|
+
accounts: 'Accounts',
|
|
90
|
+
accountsOrder: 'Nieuwe chats en agents starten op het bovenste account dat aanstaat.',
|
|
91
|
+
defaultTag: 'Standaard',
|
|
92
|
+
reorderHandle: 'Verplaats {{account}}. Alt+Omhoog en Alt+Omlaag verplaatsen het ook.'
|
|
89
93
|
},
|
|
90
94
|
account: {
|
|
91
95
|
kind: '{{provider}}-account',
|
|
@@ -144,7 +148,8 @@ export default {
|
|
|
144
148
|
confirmDescription: 'De map en de login blijven in {{folder}}.',
|
|
145
149
|
confirm: 'Account verwijderen'
|
|
146
150
|
},
|
|
147
|
-
saveFailed: 'Kon het account niet opslaan'
|
|
151
|
+
saveFailed: 'Kon het account niet opslaan',
|
|
152
|
+
reorderFailed: 'Kon de volgorde van de accounts niet wijzigen'
|
|
148
153
|
},
|
|
149
154
|
add: {
|
|
150
155
|
title: '{{provider}}-account toevoegen',
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useState, type DragEvent, type KeyboardEvent } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { ChevronRight, GripVertical } from 'lucide-react';
|
|
4
|
+
import { Icon, Pill, Tooltip } from '@adecore/ui';
|
|
5
|
+
import { AccountDot } from '../agents/AccountDot';
|
|
6
|
+
import { ACCOUNT_TONE_CLASSES, accountName, accountStatusLine, movedIds, topAccountEntry, type AccountEntry, type AccountLogin } from '../agents/accounts';
|
|
7
|
+
|
|
8
|
+
const DRAG_TYPE = 'application/x-adecore-account';
|
|
9
|
+
|
|
10
|
+
interface AccountOrderListProps {
|
|
11
|
+
entries: readonly AccountEntry[];
|
|
12
|
+
providerName: string;
|
|
13
|
+
login: AccountLogin;
|
|
14
|
+
/* Null while the machine keeps no order, which draws the rows without handles. */
|
|
15
|
+
onReorder: ((ids: string[]) => void) | null;
|
|
16
|
+
onPickAccount(id: string): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* 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. */
|
|
20
|
+
export function AccountOrderList({ entries, providerName, login, onReorder, onPickAccount }: AccountOrderListProps) {
|
|
21
|
+
const { t } = useTranslation('agent-providers');
|
|
22
|
+
const [dragged, setDragged] = useState<string | null>(null);
|
|
23
|
+
const [over, setOver] = useState<number | null>(null);
|
|
24
|
+
const ids = entries.map((entry) => entry.id);
|
|
25
|
+
const top = topAccountEntry(entries);
|
|
26
|
+
const reorder = entries.length >= 2 ? onReorder : null;
|
|
27
|
+
|
|
28
|
+
const move = (id: string, to: number): void => {
|
|
29
|
+
const next = movedIds(ids, id, to);
|
|
30
|
+
|
|
31
|
+
if (reorder !== null && next.some((candidate, index) => candidate !== ids[index])) {
|
|
32
|
+
reorder(next);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const onKeyDown = (event: KeyboardEvent, id: string, index: number): void => {
|
|
37
|
+
if (reorder === null || !event.altKey || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown')) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
move(id, event.key === 'ArrowUp' ? index - 1 : index + 1);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const placeOf = (event: DragEvent, index: number): number => {
|
|
46
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
47
|
+
|
|
48
|
+
return event.clientY > box.top + box.height / 2 ? index + 1 : index;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const onDrop = (event: DragEvent, index: number): void => {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
const id = event.dataTransfer.getData(DRAG_TYPE);
|
|
54
|
+
const from = ids.indexOf(id);
|
|
55
|
+
const place = placeOf(event, index);
|
|
56
|
+
setDragged(null);
|
|
57
|
+
setOver(null);
|
|
58
|
+
|
|
59
|
+
if (from !== -1) {
|
|
60
|
+
move(id, place > from ? place - 1 : place);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
{entries.map((entry, index) => {
|
|
67
|
+
const status = accountStatusLine(entry.status, login === 'terminal');
|
|
68
|
+
const name = accountName(entry, providerName);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
key={entry.id}
|
|
73
|
+
className={`relative flex w-full min-w-0 items-center first:rounded-t-xl last:rounded-b-xl hover:bg-surface-hover ${dragged === entry.id ? 'opacity-50' : ''}`}
|
|
74
|
+
onDragOver={(event) => {
|
|
75
|
+
if (dragged !== null) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
setOver(placeOf(event, index));
|
|
78
|
+
}
|
|
79
|
+
}}
|
|
80
|
+
onDrop={(event) => onDrop(event, index)}
|
|
81
|
+
>
|
|
82
|
+
{over === index && <span aria-hidden className="absolute inset-x-3 top-0 h-0.5 rounded-full bg-accent" />}
|
|
83
|
+
{over === index + 1 && index === entries.length - 1 && (
|
|
84
|
+
<span aria-hidden className="absolute inset-x-3 bottom-0 h-0.5 rounded-full bg-accent" />
|
|
85
|
+
)}
|
|
86
|
+
{reorder !== null && (
|
|
87
|
+
<Tooltip label={t('cli.reorderHandle', { account: name })}>
|
|
88
|
+
<span
|
|
89
|
+
aria-hidden
|
|
90
|
+
draggable
|
|
91
|
+
className="flex shrink-0 cursor-grab items-center self-stretch pl-3 text-text-faint"
|
|
92
|
+
onDragStart={(event) => {
|
|
93
|
+
event.dataTransfer.setData(DRAG_TYPE, entry.id);
|
|
94
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
95
|
+
setDragged(entry.id);
|
|
96
|
+
}}
|
|
97
|
+
onDragEnd={() => {
|
|
98
|
+
setDragged(null);
|
|
99
|
+
setOver(null);
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<Icon icon={GripVertical} size={14} />
|
|
103
|
+
</span>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
)}
|
|
106
|
+
<button
|
|
107
|
+
type="button"
|
|
108
|
+
aria-keyshortcuts={reorder === null ? undefined : 'Alt+ArrowUp Alt+ArrowDown'}
|
|
109
|
+
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'}`}
|
|
110
|
+
onClick={() => onPickAccount(entry.id)}
|
|
111
|
+
onKeyDown={(event) => onKeyDown(event, entry.id, index)}
|
|
112
|
+
>
|
|
113
|
+
<AccountDot color={entry.account.color} />
|
|
114
|
+
<span className="min-w-0 truncate text-sm text-text">{name}</span>
|
|
115
|
+
{entries.length >= 2 && entry.id === top?.id && <Pill size="sm">{t('cli.defaultTag')}</Pill>}
|
|
116
|
+
<span className={`ml-auto shrink-0 text-xs ${ACCOUNT_TONE_CLASSES[status.tone]}`}>{status.text}</span>
|
|
117
|
+
<Icon icon={ChevronRight} size={14} className="shrink-0 text-text-faint" />
|
|
118
|
+
</button>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
})}
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { useTranslation } from 'react-i18next';
|
|
2
|
-
import {
|
|
2
|
+
import { Plus } from 'lucide-react';
|
|
3
3
|
import type { AgentKind, ModelInfo, ProviderInfo } from '@adecore/agent-contracts';
|
|
4
|
-
import { AccountDot } from '../agents/AccountDot';
|
|
5
4
|
import { ModelOptionControl } from '../agents/ModelOptionControl';
|
|
6
5
|
import { carryOptions } from '../agents/model-options';
|
|
7
6
|
import { optionWord } from '../agents/option-words';
|
|
8
|
-
import {
|
|
7
|
+
import { AccountDot } from '../agents/AccountDot';
|
|
8
|
+
import { accountName, offeredAccounts, type AccountEntry, type AccountLogin } from '../agents/accounts';
|
|
9
9
|
import { accountFor, forgetChatSelection, rememberChatAccount, rememberChatSelection, selectionFor, useChatPreferences } from '../chat/preferences';
|
|
10
|
+
import { knownAccounts, useProviderAccounts } from '../state/provider-accounts';
|
|
11
|
+
import { useChatHost } from '../host';
|
|
12
|
+
import { useHostCanReorderAccounts } from '../host-hooks';
|
|
10
13
|
import { useChatScope } from '../scope';
|
|
14
|
+
import { reorderAccounts } from './account-actions';
|
|
15
|
+
import { AccountOrderList } from './AccountOrderList';
|
|
11
16
|
import { providerAbilities } from './provider-abilities';
|
|
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';
|
|
15
|
-
import { knownAccounts, useProviderAccounts } from '../state/provider-accounts';
|
|
16
20
|
|
|
17
21
|
const PROVIDER_DEFAULT = '';
|
|
18
22
|
|
|
@@ -50,14 +54,18 @@ interface CliDetailProps {
|
|
|
50
54
|
/* One CLI: what it is, what a new chat of it starts with unless `defaults` is off, and its accounts. */
|
|
51
55
|
export function CliDetail({ provider, entries, defaults, login, onAddAccount, onPickAccount }: CliDetailProps) {
|
|
52
56
|
const { t } = useTranslation('agent-providers');
|
|
53
|
-
const
|
|
57
|
+
const scope = useChatScope();
|
|
58
|
+
const host = useChatHost();
|
|
59
|
+
const canReorder = useHostCanReorderAccounts(scope.id);
|
|
54
60
|
const preferences = useChatPreferences();
|
|
55
61
|
const selection = selectionFor(preferences, provider.kind);
|
|
56
62
|
const model = provider.models.find((entry) => entry.slug === selection?.model);
|
|
57
|
-
const machineAccounts = useProviderAccounts(knownAccounts);
|
|
58
|
-
const picked = accountFor(preferences, scopeId, provider.kind, machineAccounts) ?? provider.kind;
|
|
59
|
-
const choosable = offeredAccounts(entries ?? [], picked);
|
|
60
63
|
const canAddAccount = login !== null;
|
|
64
|
+
const ordered = canReorder && entries !== null && entries.length >= 2;
|
|
65
|
+
// A machine that keeps no order of its accounts starts a new chat on the account picked here.
|
|
66
|
+
const machineAccounts = useProviderAccounts(knownAccounts);
|
|
67
|
+
const picked = accountFor(preferences, scope.id, provider.kind, machineAccounts) ?? provider.kind;
|
|
68
|
+
const choosable = canReorder ? [] : offeredAccounts(entries ?? [], picked);
|
|
61
69
|
|
|
62
70
|
return (
|
|
63
71
|
<>
|
|
@@ -75,7 +83,10 @@ export function CliDetail({ provider, entries, defaults, login, onAddAccount, on
|
|
|
75
83
|
}
|
|
76
84
|
/>
|
|
77
85
|
{defaults && (
|
|
78
|
-
<SettingsSection
|
|
86
|
+
<SettingsSection
|
|
87
|
+
title={t('cli.defaults.title')}
|
|
88
|
+
description={t(canReorder ? 'cli.defaults.description' : 'cli.defaults.descriptionWithAccount')}
|
|
89
|
+
>
|
|
79
90
|
{choosable.length > 0 && (
|
|
80
91
|
<SettingsRow
|
|
81
92
|
searchId="providers.defaults.account"
|
|
@@ -90,7 +101,7 @@ export function CliDetail({ provider, entries, defaults, login, onAddAccount, on
|
|
|
90
101
|
label: accountName(entry, provider.name),
|
|
91
102
|
icon: <AccountDot color={entry.account.color} className="size-2" />
|
|
92
103
|
}))}
|
|
93
|
-
onValueChange={(id) => rememberChatAccount(
|
|
104
|
+
onValueChange={(id) => rememberChatAccount(scope.id, provider.kind, id)}
|
|
94
105
|
/>
|
|
95
106
|
}
|
|
96
107
|
/>
|
|
@@ -134,24 +145,18 @@ export function CliDetail({ provider, entries, defaults, login, onAddAccount, on
|
|
|
134
145
|
{entries === null ? (
|
|
135
146
|
<p className="text-xs text-text-faint">{t('list.noAccounts')}</p>
|
|
136
147
|
) : (
|
|
137
|
-
<SettingsSection
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
<span className="min-w-0 grow truncate text-sm text-text">{accountName(entry, provider.name)}</span>
|
|
150
|
-
<span className={`shrink-0 text-xs ${ACCOUNT_TONE_CLASSES[status.tone]}`}>{status.text}</span>
|
|
151
|
-
<Icon icon={ChevronRight} size={14} className="shrink-0 text-text-faint" />
|
|
152
|
-
</button>
|
|
153
|
-
);
|
|
154
|
-
})}
|
|
148
|
+
<SettingsSection
|
|
149
|
+
title={t('cli.accounts')}
|
|
150
|
+
description={ordered ? t('cli.accountsOrder') : undefined}
|
|
151
|
+
footer={canAddAccount ? undefined : t('cli.onlyDefault', { provider: provider.name })}
|
|
152
|
+
>
|
|
153
|
+
<AccountOrderList
|
|
154
|
+
entries={entries}
|
|
155
|
+
providerName={provider.name}
|
|
156
|
+
login={login}
|
|
157
|
+
onReorder={ordered ? (ids) => void reorderAccounts(scope, host, provider.kind, ids) : null}
|
|
158
|
+
onPickAccount={onPickAccount}
|
|
159
|
+
/>
|
|
155
160
|
</SettingsSection>
|
|
156
161
|
)}
|
|
157
162
|
</>
|
|
@@ -54,6 +54,36 @@ export async function removeAccount(scope: ChatScope, host: Pick<ChatHost, 'noti
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/* Puts the accounts of one CLI in this order, showing it at once; a refusal puts the host's order back and says why. */
|
|
58
|
+
export async function reorderAccounts(scope: ChatScope, host: Pick<ChatHost, 'notify'>, kind: AgentKind, ids: readonly string[]): Promise<void> {
|
|
59
|
+
const store = useProviderAccountsStore.getState();
|
|
60
|
+
const before = providerAccountsOf(scope.id).accounts;
|
|
61
|
+
|
|
62
|
+
if (before !== null) {
|
|
63
|
+
const accounts = { ...before.accounts };
|
|
64
|
+
|
|
65
|
+
for (const [order, id] of ids.entries()) {
|
|
66
|
+
const account = accounts[id];
|
|
67
|
+
|
|
68
|
+
if (account !== undefined) {
|
|
69
|
+
accounts[id] = { ...account, order };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
store.set(scope.id, { ...before, accounts });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
store.set(scope.id, await linkTo(scope).request('accounts.reorder', { kind, ids: [...ids] }));
|
|
78
|
+
} catch (e) {
|
|
79
|
+
if (before !== null) {
|
|
80
|
+
store.set(scope.id, before);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
host.notify({ id: `providers-reorder-${scope.id}`, kind: 'error', title: words('account.reorderFailed'), description: errorMessage(e) });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
57
87
|
/* An account in a folder the host makes for it; answers its id. Throws what the host said, for the form to show. */
|
|
58
88
|
export async function createAccount(scope: ChatScope, kind: AgentKind, label: string, color: string): Promise<string> {
|
|
59
89
|
const { id, ...accounts } = await linkTo(scope).request('accounts.create', { kind, label, color });
|
package/src/providers/index.ts
CHANGED
|
@@ -4,7 +4,17 @@ export { AgentIcon } from '../agents/AgentIcon';
|
|
|
4
4
|
export { AgentModelLabel } from '../agents/AgentModelLabel';
|
|
5
5
|
export { ModelOptionControl } from '../agents/ModelOptionControl';
|
|
6
6
|
export { ProviderLogo } from '../agents/ProviderLogo';
|
|
7
|
-
export {
|
|
7
|
+
export {
|
|
8
|
+
type AccountEntry,
|
|
9
|
+
type AccountRule,
|
|
10
|
+
accountsOfKind,
|
|
11
|
+
ACCOUNT_TONE_CLASSES,
|
|
12
|
+
accountStatusLine,
|
|
13
|
+
canContinueOn,
|
|
14
|
+
projectDefault,
|
|
15
|
+
topAccountEntry,
|
|
16
|
+
type AccountTone
|
|
17
|
+
} from '../agents/accounts';
|
|
8
18
|
export { modelName, useModelName, shortModelName } from '../agents/model-name';
|
|
9
19
|
export { carryOptions } from '../agents/model-options';
|
|
10
20
|
export { type ModelRequirement } from '../agents/model-requirement';
|
|
@@ -82,7 +82,14 @@ export function limitGroups(snapshot: UsageLimitsSnapshot, accounts: ProviderAcc
|
|
|
82
82
|
status: account.status
|
|
83
83
|
}));
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
// In the person's order, as every other list of accounts; a read account the list does not know yet goes last.
|
|
86
|
+
const place = (id: string): number => {
|
|
87
|
+
const index = known.findIndex((account) => account.id === id);
|
|
88
|
+
|
|
89
|
+
return index === -1 ? known.length : index;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const rows = [...read, ...unread].sort((a, b) => place(a.id) - place(b.id));
|
|
86
93
|
|
|
87
94
|
return rows.length === 0 ? [] : [{ kind, accounts: rows }];
|
|
88
95
|
});
|