@adecore/agents-react 0.67.1 → 0.69.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/AgentIcon.d.ts +7 -0
- package/dist/agents/AgentIcon.js +70 -31
- package/dist/chat/logic/timeline.d.ts +2 -0
- package/dist/chat/logic/timeline.js +47 -0
- package/dist/chat/subagent-list.d.ts +1 -2
- package/dist/chat/ui/Composer.js +491 -447
- package/dist/chat/ui/Markdown.d.ts +1 -1
- package/dist/chat/ui/Markdown.js +277 -203
- package/dist/chat/ui/PromptEditor.d.ts +3 -1
- package/dist/chat/ui/PromptEditor.js +4 -1
- package/dist/chat/ui/Timeline.js +5 -4
- package/dist/chat/ui/composer/ComposerMenu.js +22 -12
- package/dist/chat/ui/composer/chips.d.ts +2 -1
- package/dist/chat/ui/composer/chips.js +44 -1
- package/dist/chat/ui/composer/key-handler.d.ts +2 -0
- package/dist/chat/ui/composer/key-handler.js +12 -2
- package/dist/chat/ui/composer/placeholder.d.ts +2 -1
- package/dist/chat/ui/composer/placeholder.js +31 -10
- package/dist/chat/ui/composer/use-composer-menus.js +49 -39
- package/dist/chat/ui/composer/use-prompt-menus.d.ts +10 -7
- package/dist/chat/ui/composer/use-prompt-menus.js +183 -157
- package/dist/chat/ui/composer/use-prompt-suggestion.d.ts +16 -0
- package/dist/chat/ui/composer/use-prompt-suggestion.js +55 -0
- package/dist/chat/ui/index.d.ts +1 -1
- package/dist/chat/ui/index.js +1 -1
- package/dist/chat/ui/markdown-cache.d.ts +4 -0
- package/dist/chat/ui/markdown-cache.js +47 -0
- package/dist/chat/ui/reference-lookup.d.ts +2 -1
- package/dist/chat/ui/reference-lookup.js +1 -1
- package/dist/chat/ui/rows/SubagentRow.js +26 -24
- package/dist/chat/ui/rows/TaskRow.d.ts +11 -1
- package/dist/chat/ui/rows/TaskRow.js +281 -197
- package/dist/chat/ui/thread-references.js +12 -9
- package/dist/chat-client.d.ts +3 -1
- package/dist/chat-client.js +82 -30
- package/dist/chat-sink.d.ts +1 -0
- package/dist/host/host-hooks.d.ts +4 -1
- package/dist/host/host-hooks.js +11 -0
- package/dist/host/host.d.ts +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/locales/en/agent-chat.d.ts +1 -0
- package/dist/locales/en/agent-chat.js +2 -1
- package/dist/locales/nl/agent-chat.d.ts +1 -0
- package/dist/locales/nl/agent-chat.js +2 -1
- package/dist/state/chats.d.ts +2 -0
- package/dist/state/chats.js +21 -5
- package/dist/theme.css +6 -0
- package/package.json +9 -9
- package/src/agents/AgentIcon.tsx +6 -2
- package/src/chat/logic/timeline.ts +63 -0
- package/src/chat/subagent-list.ts +1 -4
- package/src/chat/ui/Composer.tsx +15 -2
- package/src/chat/ui/Markdown.tsx +97 -55
- package/src/chat/ui/PromptEditor.tsx +7 -2
- package/src/chat/ui/Timeline.tsx +17 -14
- package/src/chat/ui/composer/ComposerMenu.tsx +14 -6
- package/src/chat/ui/composer/chips.ts +51 -2
- package/src/chat/ui/composer/key-handler.ts +17 -2
- package/src/chat/ui/composer/placeholder.ts +14 -3
- package/src/chat/ui/composer/use-composer-menus.ts +8 -3
- package/src/chat/ui/composer/use-prompt-menus.ts +33 -4
- package/src/chat/ui/composer/use-prompt-suggestion.ts +36 -0
- package/src/chat/ui/index.ts +1 -1
- package/src/chat/ui/markdown-cache.ts +60 -0
- package/src/chat/ui/reference-lookup.ts +4 -2
- package/src/chat/ui/rows/SubagentRow.tsx +1 -1
- package/src/chat/ui/rows/TaskRow.tsx +54 -9
- package/src/chat/ui/thread-references.ts +4 -2
- package/src/chat-client.ts +79 -22
- package/src/chat-sink.ts +6 -1
- package/src/host/host-hooks.ts +19 -1
- package/src/host/host.ts +41 -0
- package/src/index.ts +3 -0
- package/src/locales/en/agent-chat.ts +2 -1
- package/src/locales/nl/agent-chat.ts +2 -1
- package/src/state/chats.ts +22 -6
- package/src/theme.css +6 -0
package/src/chat/ui/Markdown.tsx
CHANGED
|
@@ -3,9 +3,10 @@ import clsx from 'clsx';
|
|
|
3
3
|
import { Zap } from 'lucide-react';
|
|
4
4
|
import { createContext, memo, useContext, useState, type ComponentProps, type MouseEvent, type ReactNode } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
|
-
import
|
|
6
|
+
import type { Components, ExtraProps, Options } from 'react-markdown';
|
|
7
7
|
import remarkBreaks from 'remark-breaks';
|
|
8
8
|
import remarkGfm from 'remark-gfm';
|
|
9
|
+
import { MarkGlyph } from '../../agents/AgentIcon';
|
|
9
10
|
import { useChatHost, type ChatHost, type FileRef, type ShellCodeBlockContext } from '../../host/host';
|
|
10
11
|
import type { ReferenceToken } from '../mentions';
|
|
11
12
|
import { MENTION_TONE, SKILL_TONE, TOKEN_ICON } from './chips';
|
|
@@ -14,6 +15,7 @@ import { CodeBlock } from './CodeBlock';
|
|
|
14
15
|
import { DisplayImage } from './DisplayImage';
|
|
15
16
|
import { useFileLinkCwd, useFileLinkScopeId, useFileLinkTarget, useOpenFileLink } from './file-links';
|
|
16
17
|
import { createMarkdownBlockSplitter } from './markdown-blocks';
|
|
18
|
+
import { parseMarkdown } from './markdown-cache';
|
|
17
19
|
import { MermaidBlock } from './MermaidBlock';
|
|
18
20
|
import { NamedChip } from './NamedChip';
|
|
19
21
|
import { ReferenceLookupContext } from './reference-lookup';
|
|
@@ -363,16 +365,7 @@ function Chip({ kind, value }: { kind: string; value: string }) {
|
|
|
363
365
|
}
|
|
364
366
|
|
|
365
367
|
if (kind === 'skill') {
|
|
366
|
-
return
|
|
367
|
-
<TokenChip
|
|
368
|
-
kind="skill"
|
|
369
|
-
value={value}
|
|
370
|
-
sigil="$"
|
|
371
|
-
icon={<Icon icon={Zap} size={14} className={clsx(TOKEN_ICON, 'opacity-85')} />}
|
|
372
|
-
label={value}
|
|
373
|
-
tone={SKILL_TONE}
|
|
374
|
-
/>
|
|
375
|
-
);
|
|
368
|
+
return <SkillChip name={value} />;
|
|
376
369
|
}
|
|
377
370
|
|
|
378
371
|
return (
|
|
@@ -390,6 +383,36 @@ function Chip({ kind, value }: { kind: string; value: string }) {
|
|
|
390
383
|
);
|
|
391
384
|
}
|
|
392
385
|
|
|
386
|
+
/* A host's own skill shows its title under the host's mark, while a selection still copies `$name`. */
|
|
387
|
+
function SkillChip({ name }: { name: string }) {
|
|
388
|
+
const host = useContext(ReferenceLookupContext).skills?.find((skill) => skill.name === name);
|
|
389
|
+
|
|
390
|
+
if (host !== undefined) {
|
|
391
|
+
return (
|
|
392
|
+
<TokenChip
|
|
393
|
+
kind="skill"
|
|
394
|
+
value={name}
|
|
395
|
+
sigil="$"
|
|
396
|
+
icon={<MarkGlyph mark={host.icon} size={14} decorative className={clsx(TOKEN_ICON, 'opacity-85')} />}
|
|
397
|
+
label={host.title}
|
|
398
|
+
spelled={host.title === name ? undefined : name}
|
|
399
|
+
tone={SKILL_TONE}
|
|
400
|
+
/>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return (
|
|
405
|
+
<TokenChip
|
|
406
|
+
kind="skill"
|
|
407
|
+
value={name}
|
|
408
|
+
sigil="$"
|
|
409
|
+
icon={<Icon icon={Zap} size={14} className={clsx(TOKEN_ICON, 'opacity-85')} />}
|
|
410
|
+
label={name}
|
|
411
|
+
tone={SKILL_TONE}
|
|
412
|
+
/>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
393
416
|
type ChipSpanProps = ComponentProps<'span'> & ExtraProps & { 'data-chip'?: string; 'data-value'?: string };
|
|
394
417
|
|
|
395
418
|
/* A span the chip plugins made is a chip; any other, such as a fading word, stays the span it was. */
|
|
@@ -409,8 +432,22 @@ const MESSAGE_PLUGINS = [remarkGfm, remarkHtmlAsText, remarkBreaks];
|
|
|
409
432
|
const FADE_PLUGINS = [rehypeFadeWords];
|
|
410
433
|
const NO_PLUGINS: typeof FADE_PLUGINS = [];
|
|
411
434
|
|
|
435
|
+
const namesKeys = new WeakMap<readonly ReferenceToken[], string>();
|
|
436
|
+
|
|
437
|
+
/* What of the named references the chip plugin reads, as the part of a cache key it decides. */
|
|
438
|
+
function namesKey(items: readonly ReferenceToken[]): string {
|
|
439
|
+
let key = namesKeys.get(items);
|
|
440
|
+
|
|
441
|
+
if (key === undefined) {
|
|
442
|
+
key = items.map((item) => `${item.id}\u0001${item.name}`).join('\u0002');
|
|
443
|
+
namesKeys.set(items, key);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return key;
|
|
447
|
+
}
|
|
448
|
+
|
|
412
449
|
/* One block of a reply. It renders no element of its own, so prose keeps its first and last margins. */
|
|
413
|
-
const ReplyBlock = memo(function ReplyBlock({ text, fade, open
|
|
450
|
+
const ReplyBlock = memo(function ReplyBlock({ text, fade, open }: { text: string; fade: boolean; open: boolean }) {
|
|
414
451
|
const { items, referenced } = useContext(ReferenceLookupContext);
|
|
415
452
|
// Chips first, so the fade wraps the words around a chip and never cuts a name in two.
|
|
416
453
|
const named: NamedReferenceOptions = { items, referenced };
|
|
@@ -418,15 +455,14 @@ const ReplyBlock = memo(function ReplyBlock({ text, fade, open, reply }: { text:
|
|
|
418
455
|
const rehypePlugins: Options['rehypePlugins'] =
|
|
419
456
|
items.length === 0 ? (fade ? FADE_PLUGINS : NO_PLUGINS) : [[rehypeNamedReferences, named], ...(fade ? FADE_PLUGINS : [])];
|
|
420
457
|
|
|
458
|
+
// A block that fades is one being written, which no other mount of the thread draws again.
|
|
459
|
+
const variant = fade ? null : items.length === 0 ? 'reply' : `reply\u0003${namesKey(items)}\u0003${(referenced ?? []).join('\u0002')}`;
|
|
460
|
+
|
|
421
461
|
return (
|
|
422
462
|
// A context rather than a second set of components. A component that changed would mount the
|
|
423
463
|
// code block again the moment its fence closes, and it would lose the lines it already has.
|
|
424
464
|
<CodeStreamingContext.Provider value={open}>
|
|
425
|
-
|
|
426
|
-
<ReactMarkdown remarkPlugins={REPLY_PLUGINS} rehypePlugins={rehypePlugins} components={replyComponents}>
|
|
427
|
-
{text}
|
|
428
|
-
</ReactMarkdown>
|
|
429
|
-
</ShellCodeBlockReplyContext.Provider>
|
|
465
|
+
{parseMarkdown(variant, { remarkPlugins: REPLY_PLUGINS, rehypePlugins, components: replyComponents, children: text })}
|
|
430
466
|
</CodeStreamingContext.Provider>
|
|
431
467
|
);
|
|
432
468
|
});
|
|
@@ -436,23 +472,12 @@ const ReplyBlock = memo(function ReplyBlock({ text, fade, open, reply }: { text:
|
|
|
436
472
|
* added to a long fence costs no more than one added to a short one. It is the same tree whether the
|
|
437
473
|
* fence is open or closed, so closing it keeps the lines its code block already has.
|
|
438
474
|
*/
|
|
439
|
-
const ReplyFence = memo(function ReplyFence({
|
|
440
|
-
|
|
441
|
-
body,
|
|
442
|
-
source,
|
|
443
|
-
open,
|
|
444
|
-
reply
|
|
445
|
-
}: {
|
|
446
|
-
info: string;
|
|
447
|
-
body: string;
|
|
448
|
-
source: string;
|
|
449
|
-
open: boolean;
|
|
450
|
-
reply?: ShellCodeBlockReply;
|
|
451
|
-
}) {
|
|
475
|
+
const ReplyFence = memo(function ReplyFence({ info, body, source, open }: { info: string; body: string; source: string; open: boolean }) {
|
|
476
|
+
const reply = useContext(ShellCodeBlockReplyContext);
|
|
452
477
|
const { renderCodeFence, renderShellCodeBlock } = useChatHost();
|
|
453
478
|
// The class markdown gives the code, read back the way a parsed fence's is.
|
|
454
479
|
const lang = languageOf(`language-${info.split(/[ \t]/, 1)[0]}`);
|
|
455
|
-
const shell = reply ===
|
|
480
|
+
const shell = reply === null ? null : shellFence(source);
|
|
456
481
|
// The host gets a fence only once it closed, so it never draws a body that is still being written.
|
|
457
482
|
const drawn = open ? null : renderCodeFence?.(lang, body);
|
|
458
483
|
|
|
@@ -465,7 +490,7 @@ const ReplyFence = memo(function ReplyFence({
|
|
|
465
490
|
{lang === 'mermaid' ? (
|
|
466
491
|
<Diagram code={body} />
|
|
467
492
|
) : (
|
|
468
|
-
<CodeBlock code={body} lang={lang} actions={shellCodeBlockActions(reply
|
|
493
|
+
<CodeBlock code={body} lang={lang} actions={shellCodeBlockActions(reply, shell, renderShellCodeBlock)} />
|
|
469
494
|
)}
|
|
470
495
|
</CodeStreamingContext.Provider>
|
|
471
496
|
);
|
|
@@ -490,24 +515,37 @@ export const ReplyMarkdown = memo(function ReplyMarkdown({
|
|
|
490
515
|
}) {
|
|
491
516
|
const [split] = useState(createMarkdownBlockSplitter);
|
|
492
517
|
const blocks = split(text);
|
|
518
|
+
// Words that faded in keep their spans once the reveal is over. Taking them away would parse every
|
|
519
|
+
// block again in one frame, for a page that looks the same, since the last fade has ended by then.
|
|
520
|
+
const [faded, setFaded] = useState(streaming);
|
|
521
|
+
|
|
522
|
+
if (streaming && !faded) {
|
|
523
|
+
setFaded(true);
|
|
524
|
+
}
|
|
493
525
|
|
|
494
526
|
return (
|
|
495
|
-
<div
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
527
|
+
<div
|
|
528
|
+
className="chat-markdown prose prose-sm max-w-none text-sm"
|
|
529
|
+
data-arriving={arriving || undefined}
|
|
530
|
+
data-faded-in={(faded && !streaming) || undefined}
|
|
531
|
+
>
|
|
532
|
+
{/* A context, so the reply ending reaches its shell fences without drawing every block again. */}
|
|
533
|
+
<ShellCodeBlockReplyContext.Provider value={reply ?? null}>
|
|
534
|
+
{blocks.map((block, index) =>
|
|
535
|
+
// Blocks only ever grow at the end, so the place of a block is a stable key.
|
|
536
|
+
block.fence !== undefined ? (
|
|
537
|
+
<ReplyFence
|
|
538
|
+
key={index}
|
|
539
|
+
info={block.fence.info}
|
|
540
|
+
body={block.fence.body}
|
|
541
|
+
source={block.fence.source}
|
|
542
|
+
open={streaming && !block.fence.closed}
|
|
543
|
+
/>
|
|
544
|
+
) : (
|
|
545
|
+
<ReplyBlock key={index} text={block.text} fade={streaming || faded} open={streaming && block.openFence} />
|
|
546
|
+
)
|
|
547
|
+
)}
|
|
548
|
+
</ShellCodeBlockReplyContext.Provider>
|
|
511
549
|
</div>
|
|
512
550
|
);
|
|
513
551
|
});
|
|
@@ -527,13 +565,17 @@ export const MessageMarkdown = memo(function MessageMarkdown({
|
|
|
527
565
|
skills?: string[];
|
|
528
566
|
references?: readonly ReferenceToken[];
|
|
529
567
|
}) {
|
|
530
|
-
const
|
|
568
|
+
const chips: ChipOptions = { mentions, skills, references };
|
|
569
|
+
const rehypePlugins: [typeof rehypeChips, ChipOptions][] = [[rehypeChips, chips]];
|
|
531
570
|
|
|
532
571
|
return (
|
|
533
572
|
<div className="chat-markdown prose prose-sm max-w-none text-sm">
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
573
|
+
{parseMarkdown(`message\u0003${JSON.stringify(chips)}`, {
|
|
574
|
+
remarkPlugins: MESSAGE_PLUGINS,
|
|
575
|
+
rehypePlugins,
|
|
576
|
+
components: replyComponents,
|
|
577
|
+
children: text
|
|
578
|
+
})}
|
|
537
579
|
</div>
|
|
538
580
|
);
|
|
539
581
|
});
|
|
@@ -558,12 +600,12 @@ export const Markdown = memo(function Markdown({
|
|
|
558
600
|
componentOverrides?: Components;
|
|
559
601
|
}) {
|
|
560
602
|
const renderComponents = { ...(fileLinks ? components : plainComponents), ...componentOverrides };
|
|
603
|
+
// Plugins and components a caller hands in have no name to key a parsed tree on.
|
|
604
|
+
const variant = rehypePlugins === undefined && componentOverrides === undefined ? `markdown\u0003${breaks}\u0003${fileLinks}` : null;
|
|
561
605
|
|
|
562
606
|
return (
|
|
563
607
|
<div className="chat-markdown prose prose-sm max-w-none text-sm" data-muted={muted || undefined}>
|
|
564
|
-
|
|
565
|
-
{text}
|
|
566
|
-
</ReactMarkdown>
|
|
608
|
+
{parseMarkdown(variant, { remarkPlugins: breaks ? PLUGINS_WITH_BREAKS : PLUGINS, rehypePlugins, components: renderComponents, children: text })}
|
|
567
609
|
</div>
|
|
568
610
|
);
|
|
569
611
|
});
|
|
@@ -2,7 +2,7 @@ import type { ChatSkill } from '@adecore/agent-contracts';
|
|
|
2
2
|
import { Surface } from '@adecore/ui';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { useLayoutEffect, useRef, type SetStateAction } from 'react';
|
|
5
|
-
import { useChatHost } from '../../host/host';
|
|
5
|
+
import { useChatHost, type HostSkill } from '../../host/host';
|
|
6
6
|
import type { Referables } from '../../host/references';
|
|
7
7
|
import { chipDecorations } from './composer/chips';
|
|
8
8
|
import { ComposerMenu } from './composer/ComposerMenu';
|
|
@@ -17,6 +17,8 @@ interface PromptEditorProps {
|
|
|
17
17
|
label: string;
|
|
18
18
|
placeholder: string;
|
|
19
19
|
skills: readonly ChatSkill[];
|
|
20
|
+
/* The host's own skills, offered above the CLI's. */
|
|
21
|
+
hostSkills?: readonly HostSkill[];
|
|
20
22
|
/* What the CLI answers after `/`, besides `/goal` where `goals` is set. */
|
|
21
23
|
slashCommands?: readonly string[];
|
|
22
24
|
goals?: boolean;
|
|
@@ -40,6 +42,7 @@ export function PromptEditor({
|
|
|
40
42
|
label,
|
|
41
43
|
placeholder,
|
|
42
44
|
skills,
|
|
45
|
+
hostSkills,
|
|
43
46
|
slashCommands = NO_COMMANDS,
|
|
44
47
|
goals = false,
|
|
45
48
|
cwd,
|
|
@@ -72,6 +75,7 @@ export function PromptEditor({
|
|
|
72
75
|
inputRef,
|
|
73
76
|
cwd,
|
|
74
77
|
skills,
|
|
78
|
+
hostSkills,
|
|
75
79
|
slashCommands,
|
|
76
80
|
goals,
|
|
77
81
|
providerName,
|
|
@@ -84,7 +88,8 @@ export function PromptEditor({
|
|
|
84
88
|
skills: value.skills,
|
|
85
89
|
references: menus.referenceChips,
|
|
86
90
|
referenceIcon: host.ReferenceIcon,
|
|
87
|
-
named: menus.namedLook
|
|
91
|
+
named: menus.namedLook,
|
|
92
|
+
hostSkills: menus.hostSkills
|
|
88
93
|
});
|
|
89
94
|
|
|
90
95
|
const onKeyDown = (e: KeyboardEvent): boolean => {
|
package/src/chat/ui/Timeline.tsx
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
EARLIER_ROW
|
|
42
42
|
} from '../logic/scrubber';
|
|
43
43
|
import { timedRowsOf, withTimedRows } from '../logic/thread-cards';
|
|
44
|
-
import { deriveTimelineRows, findSubagentBranch } from '../logic/timeline';
|
|
44
|
+
import { createRowKeeper, deriveTimelineRows, findSubagentBranch } from '../logic/timeline';
|
|
45
45
|
import {
|
|
46
46
|
EMPTY_TARGET,
|
|
47
47
|
readTimelineTarget,
|
|
@@ -305,26 +305,29 @@ export function Timeline({
|
|
|
305
305
|
}, [scope, chatId, cursor]);
|
|
306
306
|
|
|
307
307
|
const hideTools = useHostHidesToolCalls(scopeId, chatId);
|
|
308
|
+
const [keepRows] = useState(createRowKeeper);
|
|
308
309
|
|
|
309
310
|
const threadRows = useMemo(() => {
|
|
310
311
|
if (!order || !items) {
|
|
311
312
|
return [];
|
|
312
313
|
}
|
|
313
314
|
|
|
314
|
-
return
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
315
|
+
return keepRows(
|
|
316
|
+
deriveTimelineRows(
|
|
317
|
+
order.map((id) => items[id]!),
|
|
318
|
+
{
|
|
319
|
+
expandedGroups: groups.ids,
|
|
320
|
+
expandedTurns: turns.ids,
|
|
321
|
+
expandedSubagents: subagents.ids,
|
|
322
|
+
activeTurnId,
|
|
323
|
+
forkedTurns,
|
|
324
|
+
commandLooks: host.commandLooks,
|
|
325
|
+
toolLooks: host.toolLooks,
|
|
326
|
+
hideTools
|
|
327
|
+
}
|
|
328
|
+
)
|
|
326
329
|
);
|
|
327
|
-
}, [order, items, groups.ids, turns.ids, subagents.ids, activeTurnId, forkedTurns, host.commandLooks, host.toolLooks, hideTools]);
|
|
330
|
+
}, [keepRows, order, items, groups.ids, turns.ids, subagents.ids, activeTurnId, forkedTurns, host.commandLooks, host.toolLooks, hideTools]);
|
|
328
331
|
|
|
329
332
|
const cards = useHostThreadCards(scopeId, chatId);
|
|
330
333
|
const drawsVisuals = host.visuals !== null;
|
|
@@ -3,6 +3,7 @@ import clsx from 'clsx';
|
|
|
3
3
|
import { SquareSlash, Zap } from 'lucide-react';
|
|
4
4
|
import type { ReactNode } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { MarkGlyph } from '../../../agents/AgentIcon';
|
|
6
7
|
import { CliMark } from '../../../agents/AgentModelLabel';
|
|
7
8
|
import { useChatHost } from '../../../host/host';
|
|
8
9
|
import type { Referable } from '../../../host/references';
|
|
@@ -67,12 +68,19 @@ function SkillMenu({ menus }: { menus: Menus }) {
|
|
|
67
68
|
return (
|
|
68
69
|
<div id={menus.listId} role="listbox" aria-label={t('composer.menu.skills')} className="border-b border-border px-1.5 py-1.5">
|
|
69
70
|
{menus.skillMatches.map((skill, index) => (
|
|
70
|
-
<MenuOption key={skill.name} menus={menus} index={index} className="items-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
<MenuOption key={skill.name} menus={menus} index={index} className="items-center" onPick={() => menus.chooseSkill(skill.name)}>
|
|
72
|
+
{skill.host === null ? (
|
|
73
|
+
<>
|
|
74
|
+
<Icon icon={Zap} size={12} className="shrink-0 text-skill" />
|
|
75
|
+
<span className="shrink-0 font-mono text-text">${skill.name}</span>
|
|
76
|
+
</>
|
|
77
|
+
) : (
|
|
78
|
+
<>
|
|
79
|
+
<MarkGlyph mark={skill.host.icon} size={12} decorative className="shrink-0 text-skill" />
|
|
80
|
+
<span className="shrink-0 text-text">{skill.host.title}</span>
|
|
81
|
+
</>
|
|
82
|
+
)}
|
|
83
|
+
{skill.description !== '' && <span className="min-w-0 truncate text-text-faint">{skill.description}</span>}
|
|
76
84
|
</MenuOption>
|
|
77
85
|
))}
|
|
78
86
|
</div>
|
|
@@ -4,8 +4,9 @@ import { Facet, StateField, type EditorState, type Extension, type Range } from
|
|
|
4
4
|
import { Decoration, EditorView, WidgetType, type DecorationSet } from '@codemirror/view';
|
|
5
5
|
import { createElement, Fragment, type ComponentType } from 'react';
|
|
6
6
|
import { createRoot, type Root } from 'react-dom/client';
|
|
7
|
+
import { MarkGlyph } from '../../../agents/AgentIcon';
|
|
7
8
|
import { CliMark } from '../../../agents/AgentModelLabel';
|
|
8
|
-
import type { ReferenceIconProps } from '../../../host/host';
|
|
9
|
+
import type { HostSkill, ReferenceIconProps } from '../../../host/host';
|
|
9
10
|
import type { ReferableKind, ReferenceStep } from '../../../host/references';
|
|
10
11
|
import { chipRanges, withNamedChips, type ReferenceToken } from '../../mentions';
|
|
11
12
|
import { CHIP_IN_EDITOR, MENTION_TONE, REFERENCE_TONE, SKILL_TONE, TOKEN_ICON_IN_EDITOR } from '../chips';
|
|
@@ -23,6 +24,8 @@ interface ChipChoices {
|
|
|
23
24
|
referenceIcon?: ComponentType<ReferenceIconProps> | null;
|
|
24
25
|
/* How a model or an account reads; without it a named chip shows its id. */
|
|
25
26
|
named?: NamedChipLookup | null;
|
|
27
|
+
/* The host's own skills, whose chips show their title under the host's mark. */
|
|
28
|
+
hostSkills?: readonly HostSkill[];
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
const NO_CHOICES: ChipChoices = { mentions: [], skills: [] };
|
|
@@ -129,6 +132,40 @@ class NamedChipWidget extends WidgetType {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
|
|
135
|
+
/* A skill of the host's own in place of its `$name`: the host's mark and the title. One atom, like a named chip. */
|
|
136
|
+
class HostSkillWidget extends WidgetType {
|
|
137
|
+
readonly skill: HostSkill;
|
|
138
|
+
|
|
139
|
+
constructor(skill: HostSkill) {
|
|
140
|
+
super();
|
|
141
|
+
this.skill = skill;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
override eq(other: HostSkillWidget): boolean {
|
|
145
|
+
return other.skill.name === this.skill.name && other.skill.title === this.skill.title && other.skill.icon.path === this.skill.icon.path;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
toDOM(): HTMLElement {
|
|
149
|
+
const chip = document.createElement('span');
|
|
150
|
+
const mark = document.createElement('span');
|
|
151
|
+
const root = createRoot(mark);
|
|
152
|
+
|
|
153
|
+
chip.className = `${SKILL_TONE} ${CHIP_IN_EDITOR}`;
|
|
154
|
+
mark.className = TOKEN_ICON_IN_EDITOR;
|
|
155
|
+
root.render(createElement(MarkGlyph, { mark: this.skill.icon, size: 12, decorative: true }));
|
|
156
|
+
roots.set(chip, root);
|
|
157
|
+
chip.append(mark, this.skill.title);
|
|
158
|
+
|
|
159
|
+
return chip;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
override destroy(dom: HTMLElement): void {
|
|
163
|
+
const root = roots.get(dom);
|
|
164
|
+
roots.delete(dom);
|
|
165
|
+
queueMicrotask(() => root?.unmount());
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
132
169
|
interface ChipMarks {
|
|
133
170
|
marks: DecorationSet;
|
|
134
171
|
/* The named chips, which the caret and a delete take whole. */
|
|
@@ -136,8 +173,9 @@ interface ChipMarks {
|
|
|
136
173
|
}
|
|
137
174
|
|
|
138
175
|
function chipMarks(state: EditorState): ChipMarks {
|
|
139
|
-
const { mentions, skills, references = [], referenceIcon = null, named = null } = state.facet(choices);
|
|
176
|
+
const { mentions, skills, references = [], referenceIcon = null, named = null, hostSkills = [] } = state.facet(choices);
|
|
140
177
|
const tokens = new Map(references.map((token) => [token.id, token]));
|
|
178
|
+
const hosted = new Map(hostSkills.map((skill) => [skill.name, skill]));
|
|
141
179
|
const marks: Range<Decoration>[] = [];
|
|
142
180
|
const atoms: Range<Decoration>[] = [];
|
|
143
181
|
const text = state.doc.toString();
|
|
@@ -158,6 +196,17 @@ function chipMarks(state: EditorState): ChipMarks {
|
|
|
158
196
|
continue;
|
|
159
197
|
}
|
|
160
198
|
|
|
199
|
+
const hostSkill = range.kind === 'skill' ? hosted.get(range.value) : undefined;
|
|
200
|
+
|
|
201
|
+
if (hostSkill !== undefined) {
|
|
202
|
+
const atom = Decoration.replace({ widget: new HostSkillWidget(hostSkill) }).range(range.from, range.to);
|
|
203
|
+
|
|
204
|
+
marks.push(atom);
|
|
205
|
+
atoms.push(atom);
|
|
206
|
+
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
|
|
161
210
|
if (range.kind !== 'reference') {
|
|
162
211
|
marks.push((range.kind === 'skill' ? skillMark : mentionMark).range(range.from, range.to));
|
|
163
212
|
|
|
@@ -10,6 +10,7 @@ import { pageTimeline } from '../../timeline-scroll';
|
|
|
10
10
|
import { enterAction, inCode, inFenceBody, inOpenFence, listItemAt, recallDirection, tabSpaces } from './keys';
|
|
11
11
|
import type { ComposerMenus } from './use-composer-menus';
|
|
12
12
|
import type { PromptHistory } from './use-prompt-history';
|
|
13
|
+
import type { PromptSuggestion } from './use-prompt-suggestion';
|
|
13
14
|
|
|
14
15
|
const SEND_HOW: Readonly<Record<'send' | 'send-alternate' | 'send-and-new', ComposerSend>> = {
|
|
15
16
|
send: 'default',
|
|
@@ -25,6 +26,7 @@ interface KeyHandlerInput {
|
|
|
25
26
|
menus: ComposerMenus;
|
|
26
27
|
history: PromptHistory;
|
|
27
28
|
noteKey(e: KeyboardEvent): void;
|
|
29
|
+
suggestion: PromptSuggestion | null;
|
|
28
30
|
toggleStash(): void;
|
|
29
31
|
submit(how: ComposerSend): void;
|
|
30
32
|
}
|
|
@@ -156,13 +158,20 @@ function enter(e: KeyboardEvent, view: EditorView, { host, sendKey, submit }: Ke
|
|
|
156
158
|
|
|
157
159
|
/* Runs before the editor's own keymap; true means the key is handled and its default prevented. */
|
|
158
160
|
export function composerKeyHandler(input: KeyHandlerInput): (e: KeyboardEvent, view: EditorView) => boolean {
|
|
159
|
-
const { chatId, host, text, history } = input;
|
|
161
|
+
const { chatId, host, text, history, suggestion } = input;
|
|
160
162
|
|
|
161
163
|
return (e, view) => {
|
|
162
164
|
input.noteKey(e);
|
|
163
165
|
|
|
164
|
-
// Escape leaves the node, unless it first has a
|
|
166
|
+
// Escape leaves the node, unless it first has a predicted prompt to wave off or a recalled one to put back.
|
|
165
167
|
if (e.key === 'Escape' && !e.isComposing) {
|
|
168
|
+
if (suggestion !== null) {
|
|
169
|
+
suggestion.dismiss();
|
|
170
|
+
e.stopPropagation();
|
|
171
|
+
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
166
175
|
if (!history.leave()) {
|
|
167
176
|
return false;
|
|
168
177
|
}
|
|
@@ -203,6 +212,12 @@ export function composerKeyHandler(input: KeyHandlerInput): (e: KeyboardEvent, v
|
|
|
203
212
|
return true;
|
|
204
213
|
}
|
|
205
214
|
|
|
215
|
+
if (e.key === 'Tab' && !e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey && suggestion !== null) {
|
|
216
|
+
suggestion.accept();
|
|
217
|
+
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
|
|
206
221
|
if (e.key === 'Enter') {
|
|
207
222
|
return enter(e, view, input);
|
|
208
223
|
}
|
|
@@ -51,10 +51,14 @@ interface PlaceholderInput extends HintConditions {
|
|
|
51
51
|
chatId: string;
|
|
52
52
|
disabled: boolean;
|
|
53
53
|
readOnly: boolean;
|
|
54
|
+
suggestion: string | null;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
/*
|
|
57
|
-
|
|
57
|
+
/*
|
|
58
|
+
* What the empty box says: why nothing can be written, the next prompt the CLI predicted and the key that fills it in,
|
|
59
|
+
* or the host's words and the keys that open a picker.
|
|
60
|
+
*/
|
|
61
|
+
export function useHintedPlaceholder({ chatId, disabled, readOnly, suggestion, mentionable, referable, hasSkills }: PlaceholderInput): string | HTMLElement {
|
|
58
62
|
const { t } = useTranslation('agent-chat');
|
|
59
63
|
const scope = useChatScope();
|
|
60
64
|
const lead = useHostComposerPlaceholder(scope.id, chatId);
|
|
@@ -68,10 +72,17 @@ export function useHintedPlaceholder({ chatId, disabled, readOnly, mentionable,
|
|
|
68
72
|
return t('composer.placeholder.readOnly');
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
if (suggestion !== null) {
|
|
76
|
+
const predicted = hintedPlaceholder(suggestion, '', [{ key: 'Tab', label: t('composer.placeholder.suggestion') }]);
|
|
77
|
+
predicted.classList.add('composer-suggestion');
|
|
78
|
+
|
|
79
|
+
return predicted;
|
|
80
|
+
}
|
|
81
|
+
|
|
71
82
|
return hintedPlaceholder(
|
|
72
83
|
lead ?? t('composer.placeholder.lead'),
|
|
73
84
|
t('composer.placeholder.joiner'),
|
|
74
85
|
placeholderHints(t, { mentionable, referable, hasSkills })
|
|
75
86
|
);
|
|
76
|
-
}, [disabled, readOnly, lead, mentionable, referable, hasSkills, t]);
|
|
87
|
+
}, [disabled, readOnly, suggestion, lead, mentionable, referable, hasSkills, t]);
|
|
77
88
|
}
|
|
@@ -2,7 +2,7 @@ import type { ChatSkill, ProviderCapabilities } from '@adecore/agent-contracts';
|
|
|
2
2
|
import { useEffect, useState, type RefObject } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import type { ChatThreadInfo } from '../../../chat-sink';
|
|
5
|
-
import { useHostAccountRule, useHostReferables } from '../../../host/host-hooks';
|
|
5
|
+
import { useHostAccountRule, useHostReferables, useHostSkills } from '../../../host/host-hooks';
|
|
6
6
|
import { useChatScope } from '../../../scope';
|
|
7
7
|
import type { ComposerInputHandle } from '../ComposerInput';
|
|
8
8
|
import type { ComposerDraft } from './use-composer-draft';
|
|
@@ -28,6 +28,7 @@ export function useComposerMenus({ chatId, info, capabilities, providerName, dra
|
|
|
28
28
|
const scope = useChatScope();
|
|
29
29
|
const referables = useHostReferables(scope.id, chatId);
|
|
30
30
|
const accountRule = useHostAccountRule(scope.id, chatId);
|
|
31
|
+
const hostSkills = useHostSkills(scope.id, chatId);
|
|
31
32
|
const [skills, setSkills] = useState<ChatSkill[]>([]);
|
|
32
33
|
|
|
33
34
|
/*
|
|
@@ -36,9 +37,12 @@ export function useComposerMenus({ chatId, info, capabilities, providerName, dra
|
|
|
36
37
|
*/
|
|
37
38
|
useEffect(() => {
|
|
38
39
|
let stale = false;
|
|
40
|
+
// Without a process, the host answers from its scan of the folder, narrowed to what the CLI announced,
|
|
41
|
+
// so chats alike in those share a request. A running CLI may answer for itself.
|
|
42
|
+
const alike = info.running ? undefined : JSON.stringify([info.provider, info.cwd, info.skills ?? null]);
|
|
39
43
|
|
|
40
44
|
scope.chats
|
|
41
|
-
.listSkills(chatId)
|
|
45
|
+
.listSkills(chatId, alike)
|
|
42
46
|
.then((found) => {
|
|
43
47
|
if (!stale) {
|
|
44
48
|
setSkills(found);
|
|
@@ -49,7 +53,7 @@ export function useComposerMenus({ chatId, info, capabilities, providerName, dra
|
|
|
49
53
|
return () => {
|
|
50
54
|
stale = true;
|
|
51
55
|
};
|
|
52
|
-
}, [scope, chatId, info.skills, info.running]);
|
|
56
|
+
}, [scope, chatId, info.provider, info.cwd, info.skills, info.running]);
|
|
53
57
|
|
|
54
58
|
return usePromptMenus({
|
|
55
59
|
draft,
|
|
@@ -57,6 +61,7 @@ export function useComposerMenus({ chatId, info, capabilities, providerName, dra
|
|
|
57
61
|
// A CLI that does not expand `@path` gets the text as it is, so the picker stays out of the way.
|
|
58
62
|
cwd: capabilities?.mentions === false ? null : info.cwd,
|
|
59
63
|
skills,
|
|
64
|
+
hostSkills,
|
|
60
65
|
slashCommands: info.slashCommands,
|
|
61
66
|
localCommands: LOCAL_COMMANDS,
|
|
62
67
|
goals: capabilities?.goals !== undefined,
|