@adecore/agents-react 0.54.16 → 0.55.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.
- package/dist/agents/AgentModelLabel.d.ts +5 -0
- package/dist/agents/AgentModelLabel.js +32 -7
- package/dist/chat/account-choice.d.ts +1 -0
- package/dist/chat/account-choice.js +13 -4
- package/dist/chat/mentions.d.ts +24 -2
- package/dist/chat/mentions.js +84 -10
- package/dist/chat/subagent-list.d.ts +0 -1
- package/dist/chat/subagent-list.js +1 -9
- package/dist/chat/tag-suggestions.d.ts +22 -0
- package/dist/chat/tag-suggestions.js +71 -0
- package/dist/chat/ui/Composer.js +489 -447
- package/dist/chat/ui/ComposerInput.d.ts +1 -0
- package/dist/chat/ui/ComposerInput.js +9 -1
- package/dist/chat/ui/Markdown.js +41 -25
- package/dist/chat/ui/NamedChip.d.ts +5 -0
- package/dist/chat/ui/NamedChip.js +118 -0
- package/dist/chat/ui/Pickers.d.ts +0 -4
- package/dist/chat/ui/Pickers.js +1 -141
- package/dist/chat/ui/PromptEditor.js +2 -1
- package/dist/chat/ui/ReferenceChip.d.ts +3 -2
- package/dist/chat/ui/ReferenceChip.js +58 -36
- package/dist/chat/ui/RunSettings.d.ts +3 -2
- package/dist/chat/ui/RunSettings.js +386 -361
- package/dist/chat/ui/SubagentInfo.js +98 -114
- package/dist/chat/ui/SubagentTimeline.js +65 -43
- package/dist/chat/ui/Timeline.js +14 -8
- package/dist/chat/ui/chip-clipboard.js +10 -0
- package/dist/chat/ui/composer/ComposerControls.d.ts +6 -1
- package/dist/chat/ui/composer/ComposerControls.js +171 -158
- package/dist/chat/ui/composer/ComposerMenu.js +184 -55
- package/dist/chat/ui/composer/ComposerPlusMenu.d.ts +18 -0
- package/dist/chat/ui/composer/ComposerPlusMenu.js +400 -0
- package/dist/chat/ui/composer/ComposerStatusLine.d.ts +4 -0
- package/dist/chat/ui/composer/ComposerStatusLine.js +239 -0
- package/dist/chat/ui/composer/chips.d.ts +2 -0
- package/dist/chat/ui/composer/chips.js +66 -5
- package/dist/chat/ui/composer/insert.d.ts +1 -0
- package/dist/chat/ui/composer/insert.js +24 -0
- package/dist/chat/ui/composer/use-composer-menus.js +34 -17
- package/dist/chat/ui/composer/use-prompt-menus.d.ts +10 -2
- package/dist/chat/ui/composer/use-prompt-menus.js +290 -202
- package/dist/chat/ui/covered-bottom.d.ts +1 -0
- package/dist/chat/ui/covered-bottom.js +6 -0
- package/dist/chat/ui/named-chip-look.d.ts +14 -0
- package/dist/chat/ui/named-chip-look.js +72 -0
- package/dist/chat/ui/rehype-chips.js +13 -2
- package/dist/host-hooks.d.ts +2 -1
- package/dist/host-hooks.js +6 -0
- package/dist/host.d.ts +17 -0
- package/dist/index.d.ts +1 -1
- package/dist/locales/en/agent-chat.d.ts +14 -2
- package/dist/locales/en/agent-chat.js +16 -4
- package/dist/locales/nl/agent-chat.d.ts +14 -2
- package/dist/locales/nl/agent-chat.js +16 -4
- package/dist/state/chats.d.ts +1 -0
- package/dist/state/chats.js +45 -0
- package/package.json +9 -9
- package/src/agents/AgentModelLabel.tsx +10 -1
- package/src/chat/account-choice.ts +8 -0
- package/src/chat/mentions.ts +110 -13
- package/src/chat/subagent-list.ts +1 -14
- package/src/chat/tag-suggestions.ts +121 -0
- package/src/chat/ui/Composer.tsx +24 -12
- package/src/chat/ui/ComposerInput.tsx +13 -1
- package/src/chat/ui/Markdown.tsx +5 -0
- package/src/chat/ui/NamedChip.tsx +34 -0
- package/src/chat/ui/Pickers.tsx +1 -51
- package/src/chat/ui/PromptEditor.tsx +7 -1
- package/src/chat/ui/ReferenceChip.tsx +15 -4
- package/src/chat/ui/RunSettings.tsx +51 -29
- package/src/chat/ui/SubagentInfo.tsx +17 -17
- package/src/chat/ui/SubagentTimeline.tsx +7 -2
- package/src/chat/ui/Timeline.tsx +11 -5
- package/src/chat/ui/chip-clipboard.ts +8 -1
- package/src/chat/ui/composer/ComposerControls.tsx +24 -17
- package/src/chat/ui/composer/ComposerMenu.tsx +82 -15
- package/src/chat/ui/composer/ComposerPlusMenu.tsx +158 -0
- package/src/chat/ui/composer/ComposerStatusLine.tsx +94 -0
- package/src/chat/ui/composer/chips.ts +78 -7
- package/src/chat/ui/composer/insert.ts +12 -0
- package/src/chat/ui/composer/use-composer-menus.ts +5 -2
- package/src/chat/ui/composer/use-prompt-menus.ts +55 -10
- package/src/chat/ui/covered-bottom.ts +7 -0
- package/src/chat/ui/named-chip-look.ts +64 -0
- package/src/chat/ui/rehype-chips.ts +17 -2
- package/src/host-hooks.ts +11 -1
- package/src/host.ts +29 -0
- package/src/index.ts +2 -0
- package/src/locales/en/agent-chat.ts +16 -4
- package/src/locales/nl/agent-chat.ts +16 -4
- package/src/state/chats.ts +26 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Icon, Kbd, Menu, ScrollArea, Tooltip } from '@adecore/ui';
|
|
2
|
+
import { AtSign, Bookmark, BookmarkPlus, ChevronRight, Hash, Paperclip, Plus, SquareSlash, Trash2, Zap, type LucideIcon } from 'lucide-react';
|
|
3
|
+
import { useRef, type ReactNode } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { forgetStashed, STASH_SHORTCUT, useStash, type StashedPrompt } from '../../stash';
|
|
6
|
+
|
|
7
|
+
/* The sigils this chat answers, with the same conditions as the placeholder's key caps. */
|
|
8
|
+
export interface PlusMenuSigils {
|
|
9
|
+
mentionable: boolean;
|
|
10
|
+
referable: boolean;
|
|
11
|
+
hasSkills: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface SigilRow {
|
|
15
|
+
key: string;
|
|
16
|
+
icon: LucideIcon;
|
|
17
|
+
label: string;
|
|
18
|
+
/* The hue of the chip the sigil makes in the draft. */
|
|
19
|
+
tone?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ComposerPlusMenuProps {
|
|
23
|
+
writable: boolean;
|
|
24
|
+
attachable: boolean;
|
|
25
|
+
/* Whether the draft holds nothing: nothing to stash, and room for `/`, which only opens a command at the start. */
|
|
26
|
+
emptyDraft: boolean;
|
|
27
|
+
sigils: PlusMenuSigils;
|
|
28
|
+
onAttach(): void;
|
|
29
|
+
onRestore(prompt: StashedPrompt): void;
|
|
30
|
+
onStash(): void;
|
|
31
|
+
onSigil(sigil: string): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* Prompts put aside with Mod+S, on a shelf the whole app shares, since a stashed prompt usually moves
|
|
36
|
+
* to another chat. A draft's files are named on the row but not kept: their bytes never go to storage.
|
|
37
|
+
*/
|
|
38
|
+
function StashedPrompts({
|
|
39
|
+
prompts,
|
|
40
|
+
onRestore,
|
|
41
|
+
children
|
|
42
|
+
}: {
|
|
43
|
+
prompts: readonly StashedPrompt[];
|
|
44
|
+
onRestore(prompt: StashedPrompt): void;
|
|
45
|
+
/* The item that stashes the draft, under the prompts. */
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}) {
|
|
48
|
+
const { t } = useTranslation('agent-chat');
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Menu.Popup className="w-80">
|
|
52
|
+
<ScrollArea className="max-h-72">
|
|
53
|
+
{prompts.map((prompt) => (
|
|
54
|
+
<Menu.Row key={prompt.id} className="group/stash">
|
|
55
|
+
<Menu.Item className="flex-col items-start gap-0.5" label={prompt.text} onClick={() => onRestore(prompt)}>
|
|
56
|
+
<span className="line-clamp-2 whitespace-pre-wrap">{prompt.text || prompt.quote?.text || t('pickers.stash.noText')}</span>
|
|
57
|
+
{prompt.attachments.length > 0 && (
|
|
58
|
+
<span className="text-text-faint">{t('pickers.stash.files', { count: prompt.attachments.length })}</span>
|
|
59
|
+
)}
|
|
60
|
+
{prompt.chats.length > 0 && <span className="text-text-faint">{t('pickers.stash.chats', { count: prompt.chats.length })}</span>}
|
|
61
|
+
</Menu.Item>
|
|
62
|
+
<Menu.RowAction
|
|
63
|
+
icon={Trash2}
|
|
64
|
+
label={t('common.action.delete')}
|
|
65
|
+
closeOnClick={false}
|
|
66
|
+
className="opacity-0 group-hover/stash:opacity-100 data-[highlighted]:opacity-100"
|
|
67
|
+
onClick={() => forgetStashed(prompt.id)}
|
|
68
|
+
/>
|
|
69
|
+
</Menu.Row>
|
|
70
|
+
))}
|
|
71
|
+
</ScrollArea>
|
|
72
|
+
<Menu.Separator />
|
|
73
|
+
{children}
|
|
74
|
+
</Menu.Popup>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* The + under the box: attach, the stash, and the sigils that open a picker, for a person who does not know the keys. */
|
|
79
|
+
export function ComposerPlusMenu({ writable, attachable, emptyDraft, sigils, onAttach, onRestore, onStash, onSigil }: ComposerPlusMenuProps) {
|
|
80
|
+
const { t } = useTranslation('agent-chat');
|
|
81
|
+
const prompts = useStash((state) => state.prompts);
|
|
82
|
+
// A picked sigil puts the focus in the box, where its picker opens; the menu must not take it back to the +.
|
|
83
|
+
const handedOff = useRef(false);
|
|
84
|
+
|
|
85
|
+
const pickSigil = (sigil: string): void => {
|
|
86
|
+
handedOff.current = true;
|
|
87
|
+
onSigil(sigil);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const finalFocus = (): boolean => {
|
|
91
|
+
const back = !handedOff.current;
|
|
92
|
+
handedOff.current = false;
|
|
93
|
+
|
|
94
|
+
return back;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const stashItem = (
|
|
98
|
+
<Menu.Item disabled={emptyDraft} onClick={onStash}>
|
|
99
|
+
<Icon icon={BookmarkPlus} size={14} className="text-text-faint" />
|
|
100
|
+
{t('composer.plus.stash')}
|
|
101
|
+
<Kbd shortcut={STASH_SHORTCUT} />
|
|
102
|
+
</Menu.Item>
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const rows: SigilRow[] = [
|
|
106
|
+
...(sigils.mentionable ? [{ key: '@', icon: AtSign, label: t('composer.plus.mention'), tone: 'text-accent' }] : []),
|
|
107
|
+
...(sigils.referable ? [{ key: '#', icon: Hash, label: t('composer.plus.reference') }] : []),
|
|
108
|
+
...(sigils.hasSkills ? [{ key: '$', icon: Zap, label: t('composer.plus.skill'), tone: 'text-skill' }] : []),
|
|
109
|
+
{ key: '/', icon: SquareSlash, label: t('composer.plus.commands') }
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Menu.Root>
|
|
114
|
+
<Tooltip label={t('composer.plus.label')} name>
|
|
115
|
+
{/* The composer's controls are round, from attach to send, so this one keeps its own shape instead of `.icon-btn`'s. */}
|
|
116
|
+
<Menu.Trigger
|
|
117
|
+
disabled={!writable}
|
|
118
|
+
className="grid h-8 w-8 shrink-0 place-items-center rounded-full border border-border text-text-muted hover:bg-surface-hover-edged hover:text-text disabled:opacity-50 data-[popup-open]:bg-surface-hover data-[popup-open]:text-text"
|
|
119
|
+
>
|
|
120
|
+
<Icon icon={Plus} size={16} />
|
|
121
|
+
</Menu.Trigger>
|
|
122
|
+
</Tooltip>
|
|
123
|
+
<Menu.Popup side="top" sideOffset={8} align="start" className="w-64" finalFocus={finalFocus}>
|
|
124
|
+
{attachable && (
|
|
125
|
+
<Menu.Item onClick={onAttach}>
|
|
126
|
+
<Icon icon={Paperclip} size={14} className="text-text-faint" />
|
|
127
|
+
{t('composer.plus.attach')}
|
|
128
|
+
</Menu.Item>
|
|
129
|
+
)}
|
|
130
|
+
{/* Without a stashed prompt there is nothing to open, so stashing stands in the menu itself. */}
|
|
131
|
+
{prompts.length === 0 ? (
|
|
132
|
+
stashItem
|
|
133
|
+
) : (
|
|
134
|
+
<Menu.SubmenuRoot>
|
|
135
|
+
{/* The count sits against the chevron rather than halfway along the row. */}
|
|
136
|
+
<Menu.SubmenuTrigger chevron={false}>
|
|
137
|
+
<Icon icon={Bookmark} size={14} className="text-text-faint" />
|
|
138
|
+
{t('pickers.stash.title')}
|
|
139
|
+
<Menu.Hint className="tabular-nums">{prompts.length}</Menu.Hint>
|
|
140
|
+
<Icon icon={ChevronRight} size={14} className="-ml-1.5 text-text-faint" />
|
|
141
|
+
</Menu.SubmenuTrigger>
|
|
142
|
+
<StashedPrompts prompts={prompts} onRestore={onRestore}>
|
|
143
|
+
{stashItem}
|
|
144
|
+
</StashedPrompts>
|
|
145
|
+
</Menu.SubmenuRoot>
|
|
146
|
+
)}
|
|
147
|
+
<Menu.Separator />
|
|
148
|
+
{rows.map((row) => (
|
|
149
|
+
<Menu.Item key={row.key} disabled={row.key === '/' && !emptyDraft} onClick={() => pickSigil(row.key)}>
|
|
150
|
+
<Icon icon={row.icon} size={14} className={row.tone ?? 'text-text-faint'} />
|
|
151
|
+
{row.label}
|
|
152
|
+
<Kbd>{row.key}</Kbd>
|
|
153
|
+
</Menu.Item>
|
|
154
|
+
))}
|
|
155
|
+
</Menu.Popup>
|
|
156
|
+
</Menu.Root>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Icon, Popover, Tooltip } from '@adecore/ui';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import type { ComposerStatusItem } from '../../../host';
|
|
5
|
+
|
|
6
|
+
const ITEM = 'flex h-6 min-w-0 items-center gap-1.5 rounded-md text-xs text-text-muted';
|
|
7
|
+
|
|
8
|
+
function ItemFace({ item }: { item: ComposerStatusItem }) {
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<Icon icon={item.icon} size={14} className="shrink-0 text-text-faint" />
|
|
12
|
+
<span className="truncate">{item.label}</span>
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function StatusItem({ item }: { item: ComposerStatusItem }) {
|
|
18
|
+
if (item.details === undefined || item.details.length === 0) {
|
|
19
|
+
const face = (
|
|
20
|
+
<span className={ITEM}>
|
|
21
|
+
<ItemFace item={item} />
|
|
22
|
+
</span>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return item.tooltip === undefined ? face : <Tooltip label={item.tooltip}>{face}</Tooltip>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Popover.Root>
|
|
30
|
+
<Tooltip label={item.tooltip ?? item.label}>
|
|
31
|
+
<Popover.Trigger
|
|
32
|
+
className={clsx(
|
|
33
|
+
ITEM,
|
|
34
|
+
'-mx-1.5 px-1.5 hover:bg-surface-hover hover:text-text data-[popup-open]:bg-surface-hover data-[popup-open]:text-text'
|
|
35
|
+
)}
|
|
36
|
+
>
|
|
37
|
+
<ItemFace item={item} />
|
|
38
|
+
</Popover.Trigger>
|
|
39
|
+
</Tooltip>
|
|
40
|
+
<Popover.Popup side="top" className="max-w-120 min-w-56 p-1">
|
|
41
|
+
{item.details.map((detail, i) => (
|
|
42
|
+
<div key={i} className={clsx('flex items-start gap-2.5 px-2.5 py-1.5 text-sm', detail.muted ? 'text-text-muted' : 'text-text')}>
|
|
43
|
+
<span className="grid h-lh shrink-0 place-items-center">
|
|
44
|
+
<Icon icon={detail.icon} size={14} className="text-text-faint" />
|
|
45
|
+
</span>
|
|
46
|
+
<span className="flex min-w-0 grow flex-col">
|
|
47
|
+
<span className={clsx('break-words', detail.mono && 'font-mono')}>{detail.label}</span>
|
|
48
|
+
{detail.detail !== undefined && <span className="font-mono text-xs break-all text-text-faint">{detail.detail}</span>}
|
|
49
|
+
</span>
|
|
50
|
+
{detail.hint !== undefined && <span className="shrink-0 pl-3 text-xs/[inherit] text-text-faint">{detail.hint}</span>}
|
|
51
|
+
</div>
|
|
52
|
+
))}
|
|
53
|
+
</Popover.Popup>
|
|
54
|
+
</Popover.Root>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* The line under the card with the app's own items, such as the branch a chat works on. Without items there is no line. */
|
|
59
|
+
export function ComposerStatusLine({ items }: { items: readonly ComposerStatusItem[] }) {
|
|
60
|
+
const { t } = useTranslation('agent-chat');
|
|
61
|
+
|
|
62
|
+
if (items.length === 0) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const start = items.filter((item) => item.side !== 'end');
|
|
67
|
+
const end = items.filter((item) => item.side === 'end');
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
// Lined up with the text in the box: its padding, and the card's border. It reaches into the strip under
|
|
71
|
+
// the card, so it stands as far from the bottom as a popup of its items stands above it.
|
|
72
|
+
<div
|
|
73
|
+
role="group"
|
|
74
|
+
aria-label={t('composer.status.label')}
|
|
75
|
+
className="pointer-events-auto relative isolate -mb-1 flex min-w-0 items-center gap-3 pt-1.5 pr-5 pl-[calc(--spacing(5)+1px)] @max-md/composer-area:pl-[calc(--spacing(3.5)+1px)]"
|
|
76
|
+
>
|
|
77
|
+
{/* The thread scrolls on under the card, so it fades out under the card's lower edge and is gone by the line, across the strip the card sits in. */}
|
|
78
|
+
<span
|
|
79
|
+
aria-hidden="true"
|
|
80
|
+
className="pointer-events-none absolute -top-8 bottom-0 -inset-x-3 -z-10 bg-[linear-gradient(to_bottom,transparent,var(--surface)_--spacing(4))]"
|
|
81
|
+
/>
|
|
82
|
+
{start.map((item) => (
|
|
83
|
+
<StatusItem key={item.id} item={item} />
|
|
84
|
+
))}
|
|
85
|
+
{end.length > 0 && (
|
|
86
|
+
<span className="ml-auto flex min-w-0 items-center gap-3">
|
|
87
|
+
{end.map((item) => (
|
|
88
|
+
<StatusItem key={item.id} item={item} />
|
|
89
|
+
))}
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { AgentKind } from '@adecore/agent-contracts';
|
|
1
2
|
import { syntaxTree } from '@codemirror/language';
|
|
2
3
|
import { Facet, StateField, type EditorState, type Extension, type Range } from '@codemirror/state';
|
|
3
4
|
import { Decoration, EditorView, WidgetType, type DecorationSet } from '@codemirror/view';
|
|
4
5
|
import { createElement, Fragment, type ComponentType } from 'react';
|
|
5
6
|
import { createRoot, type Root } from 'react-dom/client';
|
|
7
|
+
import { CliMark } from '../../../agents/AgentModelLabel';
|
|
6
8
|
import type { ReferenceIconProps } from '../../../host';
|
|
7
9
|
import type { ReferableKind, ReferenceStep } from '../../chat-references';
|
|
8
|
-
import { chipRanges, type ReferenceToken } from '../../mentions';
|
|
10
|
+
import { chipRanges, withNamedChips, type ReferenceToken } from '../../mentions';
|
|
9
11
|
import { CHIP_IN_EDITOR, MENTION_TONE, REFERENCE_TONE, SKILL_TONE, TOKEN_ICON_IN_EDITOR } from '../chips';
|
|
12
|
+
import type { NamedChipLook, NamedChipLookup } from '../named-chip-look';
|
|
10
13
|
import { referenceGlyph } from '../reference-icons';
|
|
11
14
|
import { ReferenceTrail } from '../ReferenceTrail';
|
|
12
15
|
import { codeRanges } from './editor';
|
|
@@ -18,6 +21,8 @@ export interface ChipChoices {
|
|
|
18
21
|
references?: ReadonlyArray<ReferenceToken & { kind: ReferableKind | null; trail?: readonly ReferenceStep[] }>;
|
|
19
22
|
/* The host's mark of a reference, which the editor draws outside the host's provider. */
|
|
20
23
|
referenceIcon?: ComponentType<ReferenceIconProps> | null;
|
|
24
|
+
/* How a model or an account reads; without it a named chip shows its id. */
|
|
25
|
+
named?: NamedChipLookup | null;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
const NO_CHOICES: ChipChoices = { mentions: [], skills: [] };
|
|
@@ -81,13 +86,79 @@ class ReferenceIcon extends WidgetType {
|
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
/*
|
|
90
|
+
* A model or an account in place of its whole token: the CLI's mark in the color of the account it runs
|
|
91
|
+
* on, and the name the machine knows it by. The token is one atom, so the caret steps over it whole.
|
|
92
|
+
*/
|
|
93
|
+
class NamedChipWidget extends WidgetType {
|
|
94
|
+
readonly cli: AgentKind;
|
|
95
|
+
readonly look: NamedChipLook;
|
|
96
|
+
|
|
97
|
+
constructor(cli: AgentKind, look: NamedChipLook) {
|
|
98
|
+
super();
|
|
99
|
+
this.cli = cli;
|
|
100
|
+
this.look = look;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
override eq(other: NamedChipWidget): boolean {
|
|
104
|
+
return other.cli === this.cli && other.look.label === this.look.label && other.look.color === this.look.color;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
toDOM(): HTMLElement {
|
|
108
|
+
const chip = document.createElement('span');
|
|
109
|
+
const mark = document.createElement('span');
|
|
110
|
+
const root = createRoot(mark);
|
|
111
|
+
|
|
112
|
+
chip.className = `${REFERENCE_TONE} ${CHIP_IN_EDITOR}`;
|
|
113
|
+
mark.className = TOKEN_ICON_IN_EDITOR;
|
|
114
|
+
|
|
115
|
+
if (this.look.color !== undefined) {
|
|
116
|
+
mark.style.color = this.look.color;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
root.render(createElement(CliMark, { kind: this.cli, size: 12 }));
|
|
120
|
+
roots.set(chip, root);
|
|
121
|
+
chip.append(mark, this.look.label);
|
|
122
|
+
|
|
123
|
+
return chip;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override destroy(dom: HTMLElement): void {
|
|
127
|
+
const root = roots.get(dom);
|
|
128
|
+
roots.delete(dom);
|
|
129
|
+
queueMicrotask(() => root?.unmount());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface ChipMarks {
|
|
134
|
+
marks: DecorationSet;
|
|
135
|
+
/* The named chips, which the caret and a delete take whole. */
|
|
136
|
+
atoms: DecorationSet;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function chipMarks(state: EditorState): ChipMarks {
|
|
140
|
+
const { mentions, skills, references = [], referenceIcon = null, named = null } = state.facet(choices);
|
|
86
141
|
const tokens = new Map(references.map((token) => [token.id, token]));
|
|
87
142
|
const marks: Range<Decoration>[] = [];
|
|
143
|
+
const atoms: Range<Decoration>[] = [];
|
|
144
|
+
const text = state.doc.toString();
|
|
145
|
+
const code = codeRanges(state);
|
|
88
146
|
|
|
89
147
|
// `@a.ts` in backticks is code, not a mention.
|
|
90
|
-
for (const range of chipRanges(
|
|
148
|
+
for (const range of withNamedChips(text, chipRanges(text, mentions, skills, code, references), code)) {
|
|
149
|
+
if (range.kind === 'model' || range.kind === 'account') {
|
|
150
|
+
const slash = range.value.indexOf('/');
|
|
151
|
+
const cli = range.value.slice(0, slash);
|
|
152
|
+
const id = range.value.slice(slash + 1);
|
|
153
|
+
const look = named?.(range.kind, cli, id) ?? { label: id, color: undefined };
|
|
154
|
+
const atom = Decoration.replace({ widget: new NamedChipWidget(cli as AgentKind, look) }).range(range.from, range.to);
|
|
155
|
+
|
|
156
|
+
marks.push(atom);
|
|
157
|
+
atoms.push(atom);
|
|
158
|
+
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
91
162
|
if (range.kind !== 'reference') {
|
|
92
163
|
marks.push((range.kind === 'skill' ? skillMark : mentionMark).range(range.from, range.to));
|
|
93
164
|
|
|
@@ -104,17 +175,17 @@ function chipMarks(state: EditorState): DecorationSet {
|
|
|
104
175
|
}
|
|
105
176
|
}
|
|
106
177
|
|
|
107
|
-
return Decoration.set(marks, true);
|
|
178
|
+
return { marks: Decoration.set(marks, true), atoms: Decoration.set(atoms, true) };
|
|
108
179
|
}
|
|
109
180
|
|
|
110
|
-
const chipField = StateField.define<
|
|
181
|
+
const chipField = StateField.define<ChipMarks>({
|
|
111
182
|
create: chipMarks,
|
|
112
183
|
// The parser finishes a long text after the edit that asked for it, and a code span it finds then unmakes a chip.
|
|
113
184
|
update: (marks, tr) =>
|
|
114
185
|
tr.docChanged || tr.startState.facet(choices) !== tr.state.facet(choices) || syntaxTree(tr.startState) !== syntaxTree(tr.state)
|
|
115
186
|
? chipMarks(tr.state)
|
|
116
187
|
: marks,
|
|
117
|
-
provide: (field) => EditorView.decorations.from(field)
|
|
188
|
+
provide: (field) => [EditorView.decorations.from(field, (value) => value.marks), EditorView.atomicRanges.of((view) => view.state.field(field).atoms)]
|
|
118
189
|
});
|
|
119
190
|
|
|
120
191
|
/* Draws the chosen `@path`, `$name` and `#name` tokens as chips; a new `ChipChoices` object is what redraws them. */
|
|
@@ -22,3 +22,15 @@ export function insertAtSelection(state: EditorState, text: string): Transaction
|
|
|
22
22
|
|
|
23
23
|
return { changes: { from, to, insert }, selection: { anchor: from + insert.length }, scrollIntoView: true, userEvent: 'input' };
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/* A sigil typed at the caret, so the picker it opens reads what follows it: a word after it is pushed a space away. */
|
|
27
|
+
export function insertSigil(state: EditorState, sigil: string): TransactionSpec {
|
|
28
|
+
const { from, to } = state.selection.main;
|
|
29
|
+
const before = state.doc.sliceString(Math.max(0, from - 1), from);
|
|
30
|
+
const after = state.doc.sliceString(to, to + 1);
|
|
31
|
+
const lead = before !== '' && !isSpace(before) ? ' ' : '';
|
|
32
|
+
const trail = after !== '' && !isSpace(after) ? ' ' : '';
|
|
33
|
+
const caret = from + lead.length + sigil.length;
|
|
34
|
+
|
|
35
|
+
return { changes: { from, to, insert: `${lead}${sigil}${trail}` }, selection: { anchor: caret }, scrollIntoView: true, userEvent: 'input' };
|
|
36
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChatInfo, ChatSkill, ProviderCapabilities } from '@adecore/agent-contracts';
|
|
2
2
|
import { useEffect, useState, type RefObject } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
|
-
import { useHostReferables } from '../../../host-hooks';
|
|
4
|
+
import { useHostAccountRule, useHostReferables } from '../../../host-hooks';
|
|
5
5
|
import { useChatScope } from '../../../scope';
|
|
6
6
|
import type { ComposerInputHandle } from '../ComposerInput';
|
|
7
7
|
import type { ComposerDraft } from './use-composer-draft';
|
|
@@ -26,6 +26,7 @@ export function useComposerMenus({ chatId, info, capabilities, providerName, dra
|
|
|
26
26
|
const { t } = useTranslation('agent-chat');
|
|
27
27
|
const scope = useChatScope();
|
|
28
28
|
const referables = useHostReferables(scope.id, chatId);
|
|
29
|
+
const accountRule = useHostAccountRule(scope.id, chatId);
|
|
29
30
|
const [skills, setSkills] = useState<ChatSkill[]>([]);
|
|
30
31
|
|
|
31
32
|
/*
|
|
@@ -61,7 +62,9 @@ export function useComposerMenus({ chatId, info, capabilities, providerName, dra
|
|
|
61
62
|
providerName,
|
|
62
63
|
referables,
|
|
63
64
|
ownId: chatId,
|
|
64
|
-
label: t('composer.inputLabel')
|
|
65
|
+
label: t('composer.inputLabel'),
|
|
66
|
+
accountRule,
|
|
67
|
+
home: { provider: info.provider, account: info.account }
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -3,9 +3,13 @@ import { ensureSyntaxTree, syntaxTree } from '@codemirror/language';
|
|
|
3
3
|
import type { EditorState } from '@codemirror/state';
|
|
4
4
|
import { useEffect, useId, useState, type Dispatch, type RefObject, type SetStateAction } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import type { AccountRule } from '../../../agents/accounts';
|
|
6
7
|
import { useChatHost } from '../../../host';
|
|
7
8
|
import { useHostExpandingCommands } from '../../../host-hooks';
|
|
8
9
|
import { useChatScope } from '../../../scope';
|
|
10
|
+
import { useReportedModelsByProvider } from '../../../state/chats';
|
|
11
|
+
import { useProviderAccounts } from '../../../state/provider-accounts';
|
|
12
|
+
import { useProviders } from '../../../state/providers';
|
|
9
13
|
import { referenceSuggestions, referenceTokens, type Referable, type Referables } from '../../chat-references';
|
|
10
14
|
import type { ChatDraft } from '../../drafts';
|
|
11
15
|
import { usableSlashCommands } from '../../guards';
|
|
@@ -17,15 +21,21 @@ import {
|
|
|
17
21
|
insertMention,
|
|
18
22
|
insertReference,
|
|
19
23
|
insertSkill,
|
|
24
|
+
insertToken,
|
|
20
25
|
mentionPick,
|
|
26
|
+
namedChipToken,
|
|
21
27
|
NO_MENTION_SEARCH,
|
|
22
28
|
presentReferences,
|
|
23
29
|
queryOutsideChips,
|
|
30
|
+
withNamedChips,
|
|
24
31
|
type MentionQuery,
|
|
25
32
|
type MentionSearch,
|
|
33
|
+
type NamedPick,
|
|
26
34
|
type TextRange
|
|
27
35
|
} from '../../mentions';
|
|
36
|
+
import { accountSuggestions, modelSuggestions } from '../../tag-suggestions';
|
|
28
37
|
import type { ComposerInputHandle } from '../ComposerInput';
|
|
38
|
+
import { useNamedChipLookup, type NamedChipHome } from '../named-chip-look';
|
|
29
39
|
import { inCode } from './keys';
|
|
30
40
|
import { clampMenuIndex, composerMenuAria } from './menu-aria';
|
|
31
41
|
|
|
@@ -71,6 +81,10 @@ export interface PromptMenusInput<D extends PromptDraft> {
|
|
|
71
81
|
ownId?: string;
|
|
72
82
|
/* The editor's accessible name. */
|
|
73
83
|
label: string;
|
|
84
|
+
/* What the project says of accounts, for the accounts `@` offers. */
|
|
85
|
+
accountRule?: AccountRule | null;
|
|
86
|
+
/* The chat the prompt is written in, whose account a model it names runs on. */
|
|
87
|
+
home?: NamedChipHome | null;
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
const NO_COMMANDS: readonly string[] = [];
|
|
@@ -95,7 +109,9 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
95
109
|
providerName,
|
|
96
110
|
referables,
|
|
97
111
|
ownId,
|
|
98
|
-
label
|
|
112
|
+
label,
|
|
113
|
+
accountRule = null,
|
|
114
|
+
home = null
|
|
99
115
|
}: PromptMenusInput<D>) {
|
|
100
116
|
const { t } = useTranslation('agent-chat');
|
|
101
117
|
const scope = useChatScope();
|
|
@@ -105,6 +121,10 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
105
121
|
const [referenceQuery, setReferenceQuery] = useState<MentionQuery | null>(null);
|
|
106
122
|
const [skillQuery, setSkillQuery] = useState<MentionQuery | null>(null);
|
|
107
123
|
const [searched, setSearched] = useState<MentionSearch>(NO_MENTION_SEARCH);
|
|
124
|
+
const providers = useProviders((row) => row.providers);
|
|
125
|
+
const accounts = useProviderAccounts((row) => row.accounts);
|
|
126
|
+
const reportedOf = useReportedModelsByProvider();
|
|
127
|
+
const namedLook = useNamedChipLookup(home);
|
|
108
128
|
const text = draft.text;
|
|
109
129
|
|
|
110
130
|
// Every keystroke inside an `@word` searches again; a slow answer must not overwrite a newer one.
|
|
@@ -180,10 +200,14 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
180
200
|
|
|
181
201
|
const commandMenuOpen = commandQuery !== null && commands.length > 0;
|
|
182
202
|
const skillMenuOpen = !commandMenuOpen && skillQuery !== null && skillMatches.length > 0;
|
|
183
|
-
const mentionMenuOpen = !commandMenuOpen && !skillMenuOpen && mention !== null;
|
|
184
203
|
// Results belong to the query that asked for them; a closed picker shows none while the next answer is on its way.
|
|
185
|
-
const files = mention === null ? [] : searched.files;
|
|
186
|
-
const
|
|
204
|
+
const files = mention === null || cwd === null ? [] : searched.files;
|
|
205
|
+
const modelMatches = mention === null ? [] : modelSuggestions(providers, accounts, mention.query, reportedOf);
|
|
206
|
+
const accountMatches = mention === null ? [] : accountSuggestions(providers, accounts, accountRule, mention.query);
|
|
207
|
+
const named: NamedPick[] = [...modelMatches, ...accountMatches];
|
|
208
|
+
// Without files to search, `@` opens only once a model or an account matches.
|
|
209
|
+
const mentionMenuOpen = !commandMenuOpen && !skillMenuOpen && mention !== null && (cwd !== null || named.length > 0);
|
|
210
|
+
const mentionCount = files.length + named.length;
|
|
187
211
|
// A host with nothing to point at keeps `#fff` out of the way rather than saying nothing matches.
|
|
188
212
|
const offersReferences = referables.items.some((item) => !referables.chatsOnly || item.kind === 'chat');
|
|
189
213
|
const referenceMenuOpen = !commandMenuOpen && !skillMenuOpen && !mentionMenuOpen && referenceQuery !== null && offersReferences;
|
|
@@ -213,11 +237,10 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
213
237
|
const empty = selection.from === selection.to;
|
|
214
238
|
const tree = empty ? (ensureSyntaxTree(state, selection.from, 50) ?? syntaxTree(state)) : null;
|
|
215
239
|
const caret = tree !== null && !inCode(tree, value, selection.from) ? selection.from : null;
|
|
216
|
-
const chips = caret === null ? [] : chipRanges(value, draft.mentions, draft.skills, [], referenceChips);
|
|
240
|
+
const chips = caret === null ? [] : withNamedChips(value, chipRanges(value, draft.mentions, draft.skills, [], referenceChips));
|
|
217
241
|
const skill = caret === null ? null : queryOutsideChips(findSkillQuery(value, caret), chips);
|
|
218
242
|
setSkillQuery((current) => (sameQuery(current, skill) ? current : skill));
|
|
219
|
-
|
|
220
|
-
const next = caret === null || cwd === null ? null : queryOutsideChips(findMentionQuery(value, caret), chips);
|
|
243
|
+
const next = caret === null ? null : queryOutsideChips(findMentionQuery(value, caret), chips);
|
|
221
244
|
setMention((current) => (sameQuery(current, next) ? current : next));
|
|
222
245
|
const reference = caret === null ? null : queryOutsideChips(findReferenceQuery(value, caret), chips);
|
|
223
246
|
setReferenceQuery((current) => (sameQuery(current, reference) ? current : reference));
|
|
@@ -245,11 +268,29 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
245
268
|
moveCaret(result.caret);
|
|
246
269
|
};
|
|
247
270
|
|
|
271
|
+
/* A model or an account becomes its token, which a pattern finds again, so the draft keeps no list of them. */
|
|
272
|
+
const chooseNamed = (pick: NamedPick): void => {
|
|
273
|
+
if (!mention) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const result = insertToken(text, mention, '', namedChipToken(pick.kind, pick.cli, pick.id));
|
|
278
|
+
setText(result.text);
|
|
279
|
+
setMention(null);
|
|
280
|
+
moveCaret(result.caret);
|
|
281
|
+
};
|
|
282
|
+
|
|
248
283
|
const chooseMentionAt = (index: number): void => {
|
|
249
|
-
const
|
|
284
|
+
const pick = mention === null ? null : mentionPick(index, { query: searched.query, files }, mention.query, named);
|
|
285
|
+
|
|
286
|
+
if (pick === null) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
250
289
|
|
|
251
|
-
if (
|
|
252
|
-
chooseMention(path);
|
|
290
|
+
if (pick.kind === 'file') {
|
|
291
|
+
chooseMention(pick.path);
|
|
292
|
+
} else {
|
|
293
|
+
chooseNamed(pick);
|
|
253
294
|
}
|
|
254
295
|
};
|
|
255
296
|
|
|
@@ -378,6 +419,9 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
378
419
|
mentionMenuOpen,
|
|
379
420
|
mentionCount,
|
|
380
421
|
files,
|
|
422
|
+
modelMatches,
|
|
423
|
+
accountMatches,
|
|
424
|
+
namedLook,
|
|
381
425
|
referenceMenuOpen,
|
|
382
426
|
referenceMatches,
|
|
383
427
|
referables,
|
|
@@ -386,6 +430,7 @@ export function usePromptMenus<D extends PromptDraft>({
|
|
|
386
430
|
trackTriggers,
|
|
387
431
|
close,
|
|
388
432
|
chooseMention,
|
|
433
|
+
chooseNamed,
|
|
389
434
|
chooseMentionAt,
|
|
390
435
|
chooseReference,
|
|
391
436
|
chooseReferenceAt,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* How far up from its bottom the composer covers a view that stands in the thread's place, such as a
|
|
5
|
+
* sub-agent's conversation, so that view scrolls on under the card and fades out the way the thread does.
|
|
6
|
+
*/
|
|
7
|
+
export const CoveredBottomContext = createContext(0);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { UsageProviderSchema, type AgentKind, type ProviderAccounts, type ProviderInfo } from '@adecore/agent-contracts';
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { accountColor, accountName, accountsOfKind, topAccountEntry } from '../../agents/accounts';
|
|
4
|
+
import { useChatHost, type AccentChoice } from '../../host';
|
|
5
|
+
import { ChatScopeContext } from '../../scope';
|
|
6
|
+
import { useProviderAccountsStore } from '../../state/provider-accounts';
|
|
7
|
+
import { useProvidersStore } from '../../state/providers';
|
|
8
|
+
import { PROVIDER_COLORS } from '../../usage/format';
|
|
9
|
+
import type { NamedChipKind } from '../mentions';
|
|
10
|
+
|
|
11
|
+
/* How a named chip reads: the name the machine knows it by, else its id, and the color of the account it runs on. */
|
|
12
|
+
export interface NamedChipLook {
|
|
13
|
+
label: string;
|
|
14
|
+
color: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type NamedChipLookup = (kind: NamedChipKind, cli: string, id: string) => NamedChipLook;
|
|
18
|
+
|
|
19
|
+
/* The chat a chip is written in: a model chip of its CLI starts under its account, as an agent it opens inherits it. */
|
|
20
|
+
export interface NamedChipHome {
|
|
21
|
+
provider: AgentKind;
|
|
22
|
+
account: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const NO_PROVIDERS: ProviderInfo[] = [];
|
|
26
|
+
|
|
27
|
+
export function namedChipLookup(
|
|
28
|
+
providers: readonly ProviderInfo[],
|
|
29
|
+
accounts: ProviderAccounts | null,
|
|
30
|
+
accents: readonly AccentChoice[],
|
|
31
|
+
home: NamedChipHome | null
|
|
32
|
+
): NamedChipLookup {
|
|
33
|
+
const colorOf = (cli: string, accountId: string | undefined): string | undefined => {
|
|
34
|
+
const entries = accountsOfKind(accounts, cli as AgentKind);
|
|
35
|
+
const entry = accountId === undefined ? topAccountEntry(entries) : entries.find((candidate) => candidate.id === accountId);
|
|
36
|
+
const kind = UsageProviderSchema.safeParse(cli);
|
|
37
|
+
|
|
38
|
+
return accountColor(entry?.account.color, accents) ?? (kind.success ? PROVIDER_COLORS[kind.data] : undefined);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (kind, cli, id) => {
|
|
42
|
+
const provider = providers.find((entry) => entry.kind === cli);
|
|
43
|
+
|
|
44
|
+
if (kind === 'model') {
|
|
45
|
+
const account = home?.provider === cli ? (home.account ?? cli) : undefined;
|
|
46
|
+
|
|
47
|
+
return { label: provider?.models.find((model) => model.slug === id)?.name ?? id, color: colorOf(cli, account) };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const entry = accountsOfKind(accounts, cli as AgentKind).find((candidate) => candidate.id === id);
|
|
51
|
+
|
|
52
|
+
return { label: entry === undefined ? id : accountName(entry, provider?.name ?? cli), color: colorOf(cli, id) };
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* `namedChipLookup` for the machine in scope; outside a scope, every chip keeps its id. */
|
|
57
|
+
export function useNamedChipLookup(home: NamedChipHome | null = null): NamedChipLookup {
|
|
58
|
+
const scope = useContext(ChatScopeContext);
|
|
59
|
+
const { accents } = useChatHost();
|
|
60
|
+
const providers = useProvidersStore((s) => (scope === null ? NO_PROVIDERS : (s.byScope[scope.id]?.providers ?? NO_PROVIDERS)));
|
|
61
|
+
const accounts = useProviderAccountsStore((s) => (scope === null ? null : (s.byScope[scope.id]?.accounts ?? null)));
|
|
62
|
+
|
|
63
|
+
return namedChipLookup(providers, accounts, accents.all, home);
|
|
64
|
+
}
|