@adecore/agents-react 0.67.1 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/agents/AgentIcon.d.ts +7 -0
  2. package/dist/agents/AgentIcon.js +70 -31
  3. package/dist/chat/logic/timeline.d.ts +2 -0
  4. package/dist/chat/logic/timeline.js +47 -0
  5. package/dist/chat/subagent-list.d.ts +1 -2
  6. package/dist/chat/ui/Composer.js +491 -447
  7. package/dist/chat/ui/Markdown.d.ts +1 -1
  8. package/dist/chat/ui/Markdown.js +277 -203
  9. package/dist/chat/ui/PromptEditor.d.ts +3 -1
  10. package/dist/chat/ui/PromptEditor.js +4 -1
  11. package/dist/chat/ui/Timeline.js +5 -4
  12. package/dist/chat/ui/composer/ComposerMenu.js +22 -12
  13. package/dist/chat/ui/composer/chips.d.ts +2 -1
  14. package/dist/chat/ui/composer/chips.js +44 -1
  15. package/dist/chat/ui/composer/key-handler.d.ts +2 -0
  16. package/dist/chat/ui/composer/key-handler.js +12 -2
  17. package/dist/chat/ui/composer/placeholder.d.ts +2 -1
  18. package/dist/chat/ui/composer/placeholder.js +31 -10
  19. package/dist/chat/ui/composer/use-composer-menus.js +49 -39
  20. package/dist/chat/ui/composer/use-prompt-menus.d.ts +10 -7
  21. package/dist/chat/ui/composer/use-prompt-menus.js +183 -157
  22. package/dist/chat/ui/composer/use-prompt-suggestion.d.ts +16 -0
  23. package/dist/chat/ui/composer/use-prompt-suggestion.js +55 -0
  24. package/dist/chat/ui/index.d.ts +1 -1
  25. package/dist/chat/ui/index.js +1 -1
  26. package/dist/chat/ui/markdown-cache.d.ts +4 -0
  27. package/dist/chat/ui/markdown-cache.js +47 -0
  28. package/dist/chat/ui/reference-lookup.d.ts +2 -1
  29. package/dist/chat/ui/reference-lookup.js +1 -1
  30. package/dist/chat/ui/rows/SubagentRow.js +26 -24
  31. package/dist/chat/ui/rows/TaskRow.d.ts +11 -1
  32. package/dist/chat/ui/rows/TaskRow.js +281 -197
  33. package/dist/chat/ui/thread-references.js +12 -9
  34. package/dist/chat-client.d.ts +3 -1
  35. package/dist/chat-client.js +82 -30
  36. package/dist/chat-sink.d.ts +1 -0
  37. package/dist/host/host-hooks.d.ts +4 -1
  38. package/dist/host/host-hooks.js +11 -0
  39. package/dist/host/host.d.ts +18 -0
  40. package/dist/index.d.ts +1 -1
  41. package/dist/locales/en/agent-chat.d.ts +1 -0
  42. package/dist/locales/en/agent-chat.js +2 -1
  43. package/dist/locales/nl/agent-chat.d.ts +1 -0
  44. package/dist/locales/nl/agent-chat.js +2 -1
  45. package/dist/state/chats.d.ts +2 -0
  46. package/dist/state/chats.js +21 -5
  47. package/dist/theme.css +6 -0
  48. package/package.json +9 -9
  49. package/src/agents/AgentIcon.tsx +6 -2
  50. package/src/chat/logic/timeline.ts +63 -0
  51. package/src/chat/subagent-list.ts +1 -4
  52. package/src/chat/ui/Composer.tsx +15 -2
  53. package/src/chat/ui/Markdown.tsx +97 -55
  54. package/src/chat/ui/PromptEditor.tsx +7 -2
  55. package/src/chat/ui/Timeline.tsx +17 -14
  56. package/src/chat/ui/composer/ComposerMenu.tsx +14 -6
  57. package/src/chat/ui/composer/chips.ts +51 -2
  58. package/src/chat/ui/composer/key-handler.ts +17 -2
  59. package/src/chat/ui/composer/placeholder.ts +14 -3
  60. package/src/chat/ui/composer/use-composer-menus.ts +8 -3
  61. package/src/chat/ui/composer/use-prompt-menus.ts +33 -4
  62. package/src/chat/ui/composer/use-prompt-suggestion.ts +36 -0
  63. package/src/chat/ui/index.ts +1 -1
  64. package/src/chat/ui/markdown-cache.ts +60 -0
  65. package/src/chat/ui/reference-lookup.ts +4 -2
  66. package/src/chat/ui/rows/SubagentRow.tsx +1 -1
  67. package/src/chat/ui/rows/TaskRow.tsx +54 -9
  68. package/src/chat/ui/thread-references.ts +4 -2
  69. package/src/chat-client.ts +79 -22
  70. package/src/chat-sink.ts +6 -1
  71. package/src/host/host-hooks.ts +19 -1
  72. package/src/host/host.ts +41 -0
  73. package/src/index.ts +3 -0
  74. package/src/locales/en/agent-chat.ts +2 -1
  75. package/src/locales/nl/agent-chat.ts +2 -1
  76. package/src/state/chats.ts +22 -6
  77. package/src/theme.css +6 -0
@@ -3,7 +3,7 @@ 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 { useChatHost, type AccountRule } from '../../../host/host';
6
+ import { useChatHost, type AccountRule, type HostSkill } from '../../../host/host';
7
7
  import { useHostExpandingCommands } from '../../../host/host-hooks';
8
8
  import { type Referable, type Referables } from '../../../host/references';
9
9
  import { useChatScope } from '../../../scope';
@@ -61,12 +61,21 @@ export interface ComposerCommand {
61
61
  skill: boolean;
62
62
  }
63
63
 
64
+ /* A row of the `$` menu; `host` is set for a skill of the host's own, which shows its title under its mark. */
65
+ export interface SkillMatch {
66
+ name: string;
67
+ description: string;
68
+ host: HostSkill | null;
69
+ }
70
+
64
71
  interface PromptMenusInput<D extends PromptDraft> {
65
72
  draft: PromptDraftBox<D>;
66
73
  inputRef: RefObject<ComposerInputHandle | null>;
67
74
  /* Where `@` searches for files; null offers none. */
68
75
  cwd: string | null;
69
76
  skills: readonly ChatSkill[];
77
+ /* The host's own skills, offered above the CLI's. */
78
+ hostSkills?: readonly HostSkill[];
70
79
  slashCommands: readonly string[];
71
80
  /* Commands the box runs itself, named in `composer.commands`; the rest go to the CLI as text. */
72
81
  localCommands?: readonly string[];
@@ -85,6 +94,24 @@ interface PromptMenusInput<D extends PromptDraft> {
85
94
  }
86
95
 
87
96
  const NO_COMMANDS: readonly string[] = [];
97
+ const NO_HOST_SKILLS: readonly HostSkill[] = [];
98
+ const SKILL_RESULTS = 8;
99
+
100
+ /* The host's skills first, found by title or name, then the CLI's; a CLI skill under a host skill's name is the host's. */
101
+ function skillMatchesOf(query: string, skills: readonly ChatSkill[], hostSkills: readonly HostSkill[]): SkillMatch[] {
102
+ const wanted = query.toLowerCase();
103
+ const own = new Set(hostSkills.map((skill) => skill.name));
104
+
105
+ const hosted = hostSkills
106
+ .filter((skill) => skill.title.toLowerCase().includes(wanted) || skill.name.toLowerCase().includes(wanted))
107
+ .map((skill) => ({ name: skill.name, description: skill.description, host: skill }));
108
+
109
+ const cli = skills
110
+ .filter((skill) => !own.has(skill.name) && skill.name.toLowerCase().includes(wanted))
111
+ .map((skill) => ({ name: skill.name, description: skill.description, host: null }));
112
+
113
+ return [...hosted, ...cli].slice(0, SKILL_RESULTS);
114
+ }
88
115
 
89
116
  function sameQuery(left: MentionQuery | null, right: MentionQuery | null): boolean {
90
117
  return left?.start === right?.start && left?.query === right?.query;
@@ -100,6 +127,7 @@ export function usePromptMenus<D extends PromptDraft>({
100
127
  inputRef,
101
128
  cwd,
102
129
  skills,
130
+ hostSkills = NO_HOST_SKILLS,
103
131
  slashCommands,
104
132
  localCommands = NO_COMMANDS,
105
133
  goals,
@@ -193,7 +221,7 @@ export function usePromptMenus<D extends PromptDraft>({
193
221
  };
194
222
 
195
223
  const commands = commandQuery === null ? [] : commandsOf(commandQuery);
196
- const skillMatches = skillQuery === null ? [] : skills.filter((skill) => skill.name.toLowerCase().includes(skillQuery.query.toLowerCase())).slice(0, 8);
224
+ const skillMatches = skillQuery === null ? [] : skillMatchesOf(skillQuery.query, skills, hostSkills);
197
225
 
198
226
  const commandMenuOpen = commandQuery !== null && commands.length > 0;
199
227
  const skillMenuOpen = !commandMenuOpen && skillQuery !== null && skillMatches.length > 0;
@@ -403,10 +431,11 @@ export function usePromptMenus<D extends PromptDraft>({
403
431
  activeIndex,
404
432
  inputAria,
405
433
  menuOpen,
406
- hasSkills: skills.length > 0,
434
+ hasSkills: skills.length > 0 || hostSkills.length > 0,
407
435
  // While only chats can be pointed at, the hint that names views would promise what `#` does not open.
408
436
  offersViews: offersReferences && !referables.chatsOnly,
409
- skillNames: skills.map((skill) => skill.name),
437
+ skillNames: [...hostSkills.map((skill) => skill.name), ...skills.map((skill) => skill.name)],
438
+ hostSkills,
410
439
  commandQuery,
411
440
  commands,
412
441
  commandMenuOpen,
@@ -0,0 +1,36 @@
1
+ import { useState } from 'react';
2
+ import type { ChatThreadInfo } from '../../../chat-sink';
3
+ import { useChatRow } from '../../../state/chats';
4
+
5
+ export interface PromptSuggestion {
6
+ text: string;
7
+ accept(): void;
8
+ dismiss(): void;
9
+ }
10
+
11
+ interface SuggestionInput {
12
+ chatId: string;
13
+ info: Pick<ChatThreadInfo, 'activeTurnId'>;
14
+ // Whether the box holds nothing a person typed or attached.
15
+ empty: boolean;
16
+ writable: boolean;
17
+ // Whether a prompt card waits on the person, which the suggestion never stands in front of.
18
+ asked: boolean;
19
+ fill(text: string): void;
20
+ }
21
+
22
+ /* The next prompt the CLI predicted, while the box is empty and nothing else asks for the person. */
23
+ export function usePromptSuggestion({ chatId, info, empty, writable, asked, fill }: SuggestionInput): PromptSuggestion | null {
24
+ const suggestion = useChatRow(chatId, (row) => row?.suggestion ?? null);
25
+ const [dismissed, setDismissed] = useState<string | null>(null);
26
+
27
+ if (suggestion === null || suggestion === dismissed || !empty || !writable || asked || info.activeTurnId !== null) {
28
+ return null;
29
+ }
30
+
31
+ return {
32
+ text: suggestion,
33
+ accept: () => fill(suggestion),
34
+ dismiss: () => setDismissed(suggestion)
35
+ };
36
+ }
@@ -43,7 +43,7 @@ export { uiTableColumns, type UiTableColumn } from './intelligent-ui/table-data'
43
43
  export { ForksRow } from './rows/ForksRow';
44
44
  export { GeneratedImageRow } from './rows/GeneratedImageRow';
45
45
  export { ReportRow, NoteRow, AgentTurnRow, CompactionRow } from './rows/MessageRows';
46
- export { TaskRow } from './rows/TaskRow';
46
+ export { TaskRow, TaskRowHead } from './rows/TaskRow';
47
47
  export { WorkRow, WorkGroupRow, WorkingRow } from './rows/WorkRows';
48
48
  export { WorkflowRow } from './rows/WorkflowRow';
49
49
  export { WorkflowAgentLine } from './WorkflowAgentLine';
@@ -0,0 +1,60 @@
1
+ import type { ReactElement } from 'react';
2
+ import ReactMarkdown, { type Options } from 'react-markdown';
3
+
4
+ // What the cache may hold, counted in the characters of its keys, which hold the text. A parsed tree
5
+ // takes some tens of bytes per character, so this keeps it to a few tens of megabytes.
6
+ const MAX_CHARACTERS = 500_000;
7
+ const MAX_ENTRIES = 1000;
8
+
9
+ const parsed = new Map<string, ReactElement>();
10
+ let characters = 0;
11
+
12
+ function remember(key: string, element: ReactElement): void {
13
+ parsed.set(key, element);
14
+ characters += key.length;
15
+
16
+ for (const [oldest] of parsed) {
17
+ if (characters <= MAX_CHARACTERS && parsed.size <= MAX_ENTRIES) {
18
+ break;
19
+ }
20
+
21
+ parsed.delete(oldest);
22
+ characters -= oldest.length;
23
+ }
24
+ }
25
+
26
+ /*
27
+ * Markdown drawn as react-markdown draws it, parsed once for a text a thread showed before, so a
28
+ * thread that mounts again (another chat in the same place, and back) parses none of it. `variant`
29
+ * names everything of `options` besides the text (plugins, their options, components); null leaves
30
+ * the cache out, for text that is still growing. react-markdown's own `Markdown` uses no hooks, so it
31
+ * is called as the function it is, and a parsed tree is the same elements wherever it is drawn: its
32
+ * components read their context when they render.
33
+ */
34
+ export function parseMarkdown(variant: string | null, options: Options): ReactElement {
35
+ if (variant === null) {
36
+ return ReactMarkdown(options);
37
+ }
38
+
39
+ const key = `${variant}\u0000${options.children ?? ''}`;
40
+ const known = parsed.get(key);
41
+
42
+ if (known !== undefined) {
43
+ // Taken out and put back, so the Map's order stays the order of last use.
44
+ parsed.delete(key);
45
+ parsed.set(key, known);
46
+
47
+ return known;
48
+ }
49
+
50
+ const element = ReactMarkdown(options);
51
+ remember(key, element);
52
+
53
+ return element;
54
+ }
55
+
56
+ /* Empties the cache, for a test that counts parses from a clean start. */
57
+ export function forgetParsedMarkdown(): void {
58
+ parsed.clear();
59
+ characters = 0;
60
+ }
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react';
2
- import type { OutsideReference } from '../../host/host';
2
+ import type { HostSkill, OutsideReference } from '../../host/host';
3
3
  import type { Referable } from '../../host/references';
4
4
 
5
5
  export interface ReferenceLookup {
@@ -10,7 +10,9 @@ export interface ReferenceLookup {
10
10
  outside?(id: string): OutsideReference | null;
11
11
  /* What a person pointed at with `#` in this thread, which a reply wins over another of the same name. */
12
12
  referenced?: readonly string[];
13
+ /* The host's own skills of this chat, whose chips show their title under the host's mark. */
14
+ skills?: readonly HostSkill[];
13
15
  }
14
16
 
15
- /* What the views and nodes of a message stand for now, handed down by the row that draws it. */
17
+ /* What the views, nodes and host skills of a message stand for now, handed down by the row that draws it. */
16
18
  export const ReferenceLookupContext = createContext<ReferenceLookup>({ items: [], open: null });
@@ -171,7 +171,7 @@ export function SubagentRow({
171
171
  return (
172
172
  <div data-find-item={item.id}>
173
173
  {item.origin === HOST_TASK_ORIGIN ? (
174
- <TaskRow item={item} task={task} open={expanded} onPress={press} />
174
+ <TaskRow chatId={chatId} item={item} task={task} open={expanded} onPress={press} />
175
175
  ) : (
176
176
  <ToggleLine
177
177
  icon={<Icon icon={Bot} size={12} />}
@@ -6,11 +6,12 @@ import { Bot, ChevronRight } from 'lucide-react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { AgentIcon } from '../../../agents/AgentIcon';
8
8
  import { modelName, shortModelName } from '../../../agents/model-name';
9
- import type { SubagentTask } from '../../../host/host';
9
+ import type { SubagentTask, TaskRowState } from '../../../host/host';
10
+ import { useHostTaskRow } from '../../../host/host-hooks';
10
11
  import { useChatScope } from '../../../scope';
11
12
  import { useChats } from '../../../state/chats';
12
13
  import { useProviders } from '../../../state/providers';
13
- import { taskRowStateOf, type TaskRowState } from '../../subagent-list';
14
+ import { taskRowStateOf } from '../../subagent-list';
14
15
  import { ROW_GUTTER } from '../icons';
15
16
 
16
17
  const DOT: Record<TaskRowState, string> = {
@@ -37,27 +38,71 @@ function Elapsed({ startedAt }: { startedAt: number }) {
37
38
  return <span ref={ref} className="shrink-0 text-xs text-text-faint tabular-nums" />;
38
39
  }
39
40
 
40
- function StateLine({ state, task }: { state: TaskRowState; task: SubagentTask | null }) {
41
+ function StateLine({ state, task, line }: { state: TaskRowState; task: SubagentTask | null; line: string | undefined }) {
41
42
  const { t } = useTranslation('agent-chat');
42
43
  const until = state === 'paused' ? task?.paused?.until : undefined;
43
44
  const now = useNow(60_000, until !== undefined);
44
45
 
45
46
  return (
46
47
  <span className={clsx('truncate text-2xs', STATE_TONE[state])}>
47
- {until === undefined ? t(`rows.task.${state}`) : t('rows.task.pausedUntil', { time: formatMoment(until, now) })}
48
+ {line ?? (until === undefined ? t(`rows.task.${state}`) : t('rows.task.pausedUntil', { time: formatMoment(until, now) }))}
48
49
  </span>
49
50
  );
50
51
  }
51
52
 
53
+ function useTaskChild(item: ChatSubagentItem) {
54
+ const { keyOf } = useChatScope();
55
+
56
+ return useChats((s) => (item.childId === undefined ? undefined : s.statusByKey[keyOf(item.childId)]?.info));
57
+ }
58
+
59
+ interface TaskRowProps {
60
+ /* The chat whose thread holds the row. */
61
+ chatId: string;
62
+ item: ChatSubagentItem;
63
+ task: SubagentTask | null;
64
+ open: boolean;
65
+ onPress(): void;
66
+ }
67
+
52
68
  /*
53
69
  * The row of a task given to another node: that agent's mark and model, what the task is about and
54
70
  * where it stands, read from the status every client gets of the child's chat. A child without one,
55
- * a terminal or a node that is gone, keeps the task's own words.
71
+ * a terminal or a node that is gone, keeps the task's own words. A host may draw the row itself
72
+ * (`useTaskRow`).
56
73
  */
57
- export function TaskRow({ item, task, open, onPress }: { item: ChatSubagentItem; task: SubagentTask | null; open: boolean; onPress(): void }) {
74
+ export function TaskRow({ chatId, item, task, open, onPress }: TaskRowProps) {
75
+ const { id } = useChatScope();
76
+ const state = taskRowStateOf(item, task, useTaskChild(item));
77
+ const drawn = useHostTaskRow({ scopeId: id, chatId, item, task, state, open, onPress });
78
+
79
+ if (drawn !== null && drawn !== undefined) {
80
+ return drawn;
81
+ }
82
+
83
+ return <TaskRowHead item={item} task={task} open={open} onPress={onPress} />;
84
+ }
85
+
86
+ /*
87
+ * The line of a task's row on its own: the agent's mark with its state, the task, its time and the
88
+ * way into its conversation. `line` takes the place of the words under the task, in the same tone,
89
+ * for a host that knows better what the agent does now.
90
+ */
91
+ export function TaskRowHead({
92
+ item,
93
+ task,
94
+ open,
95
+ onPress,
96
+ line
97
+ }: {
98
+ item: ChatSubagentItem;
99
+ task: SubagentTask | null;
100
+ open: boolean;
101
+ onPress(): void;
102
+ line?: string;
103
+ }) {
58
104
  const { t } = useTranslation('agent-chat');
59
- const { keyOf } = useChatScope();
60
- const child = useChats((s) => (item.childId === undefined ? undefined : s.statusByKey[keyOf(item.childId)]?.info));
105
+ const child = useTaskChild(item);
61
106
  const provider = child?.provider;
62
107
  const slug = child?.model ?? child?.selection.model ?? null;
63
108
 
@@ -87,7 +132,7 @@ export function TaskRow({ item, task, open, onPress }: { item: ChatSubagentItem;
87
132
  <span data-find-field="summary" className="truncate text-xs font-medium text-text">
88
133
  {model === null ? title : t('rows.task.named', { model, title })}
89
134
  </span>
90
- <StateLine state={state} task={task} />
135
+ <StateLine state={state} task={task} line={line} />
91
136
  </span>
92
137
  <span className="flex h-5 shrink-0 items-center gap-2">
93
138
  {(state === 'running' || state === 'waiting') && startedAt > 0 && <Elapsed startedAt={startedAt} />}
@@ -1,6 +1,6 @@
1
1
  import type { ChatThreadItem } from '../../chat-sink';
2
2
  import { useChatHost } from '../../host/host';
3
- import { useHostReferables } from '../../host/host-hooks';
3
+ import { useHostReferables, useHostSkills } from '../../host/host-hooks';
4
4
  import { useChatScope } from '../../scope';
5
5
  import { useChatRow } from '../../state/chats';
6
6
  import type { ReferenceLookup } from './reference-lookup';
@@ -48,12 +48,14 @@ export function useReferenceLookup(chatId: string): ReferenceLookup {
48
48
  export function useReferenceLookupIn(scopeId: string, chatId: string): ReferenceLookup {
49
49
  const { openReference, outsideReference } = useChatHost();
50
50
  const referables = useHostReferables(scopeId, chatId);
51
+ const skills = useHostSkills(scopeId, chatId);
51
52
  const key = useChatRow(chatId, (chat) => threadReferencedKey(chat?.structure));
52
53
 
53
54
  return {
54
55
  items: referables.items,
55
56
  open: openReference ? (id: string) => openReference(scopeId, id) : null,
56
57
  ...(outsideReference ? { outside: (id: string) => outsideReference(scopeId, id) } : {}),
57
- referenced: key === '' ? [] : key.split('\n')
58
+ referenced: key === '' ? [] : key.split('\n'),
59
+ skills
58
60
  };
59
61
  }
@@ -14,7 +14,7 @@ import type {
14
14
  import type { Tolerant } from '@adecore/agent-contracts/tolerance';
15
15
  import type { ChatSink } from './chat-sink';
16
16
  import { MountedRegistry, type MountedEntry } from './mounted-registry';
17
- import { errorCode, isConnectionError, type ChatTransport, type ChatTransportStatus } from './transport';
17
+ import { errorCode, isConnectionError, type ChatRequestMap, type ChatTransport, type ChatTransportStatus } from './transport';
18
18
 
19
19
  interface ChatOpenOptions {
20
20
  /* Which agent CLI answers; a chat that exists on the host keeps its own. */
@@ -72,6 +72,7 @@ export class ChatClient {
72
72
  private readonly earlier = new Map<string, Promise<void>>();
73
73
  private readonly observers = new Map<string, number>();
74
74
  private readonly inspections = new Map<string, Promise<Tolerant<ChatAttachResult>>>();
75
+ private readonly skillLists = new Map<string, Promise<ChatSkill[]>>();
75
76
  private preferences: ChatPreferencesPayload | null = null;
76
77
  private checkpoints = new WeakMap<object, number>();
77
78
 
@@ -93,6 +94,7 @@ export class ChatClient {
93
94
  transport.on('chat.status', ({ chatId, info }) => this.sink.status(chatId, info)),
94
95
  transport.on('chat.bookmarks', ({ chatId, bookmarks }) => this.sink.bookmarks(chatId, bookmarks)),
95
96
  transport.on('chat.visuals', ({ chatId, visuals }) => this.sink.visuals(chatId, visuals)),
97
+ transport.on('chat.suggestion', ({ chatId, suggestion }) => this.sink.suggestion?.(chatId, suggestion)),
96
98
  transport.subscribeStatus((status) => this.onStatus(status))
97
99
  );
98
100
 
@@ -274,11 +276,34 @@ export class ChatClient {
274
276
  return visuals;
275
277
  }
276
278
 
277
- /* What this chat's CLI would run as a skill, for the composer's `$` picker. */
278
- async listSkills(chatId: string): Promise<ChatSkill[]> {
279
- const { skills } = await this.transport.request('skills.list', { chatId });
279
+ /*
280
+ * What this chat's CLI would run as a skill, for the composer's `$` picker. Chats the caller gives
281
+ * the same `alike` key share a request still on the wire, so a project that opens several chats in
282
+ * one folder asks once; an answer is never kept after it came. A shared request that failed is
283
+ * asked again for this chat alone, since it may have failed for the other chat only.
284
+ */
285
+ listSkills(chatId: string, alike?: string): Promise<ChatSkill[]> {
286
+ const ask = async (): Promise<ChatSkill[]> => (await this.transport.request('skills.list', { chatId })).skills;
287
+
288
+ if (alike === undefined) {
289
+ return ask();
290
+ }
291
+
292
+ const pending = this.skillLists.get(alike);
293
+
294
+ if (pending !== undefined) {
295
+ return pending.catch(ask);
296
+ }
297
+
298
+ const request = ask().finally(() => {
299
+ if (this.skillLists.get(alike) === request) {
300
+ this.skillLists.delete(alike);
301
+ }
302
+ });
303
+
304
+ this.skillLists.set(alike, request);
280
305
 
281
- return skills;
306
+ return request;
282
307
  }
283
308
 
284
309
  /* Starts the chat over; refused with `chat-busy` while a turn runs, unless `force` stops that turn. */
@@ -302,11 +327,12 @@ export class ChatClient {
302
327
 
303
328
  /*
304
329
  * What every chat on this machine is doing right now. `chat.status` only carries a change, so a
305
- * window that just opened or came back from a lost socket asks for the standing answer.
330
+ * window that just opened or came back from a lost socket asks for the standing answer. It leaves
331
+ * out the commands, which the sink keeps from the attach of a chat that has them.
306
332
  */
307
333
  async loadStatuses(): Promise<void> {
308
334
  try {
309
- const { chats } = await this.transport.request('chat.list', {});
335
+ const { chats } = await this.transport.request('chat.list', { omitCommands: true });
310
336
 
311
337
  for (const info of chats) {
312
338
  this.sink.status(info.chatId, info);
@@ -395,25 +421,13 @@ export class ChatClient {
395
421
  return;
396
422
  }
397
423
 
398
- if (!entry.observerOnly) {
399
- await this.transport.request('chat.create', {
400
- chatId,
401
- provider: entry.provider,
402
- account: entry.account,
403
- cwd: entry.cwd,
404
- resume: entry.resume,
405
- selection: entry.selection,
406
- runtimeMode: entry.runtimeMode
407
- });
408
- }
424
+ const since = this.sequence(chatId);
425
+ const result = await this.openOnHost(chatId, entry, since);
409
426
 
410
- // Closed or opened again in the meantime: an opening that is still there attaches itself.
411
- if (this.mounted.get(chatId) !== entry) {
427
+ if (result === null) {
412
428
  return;
413
429
  }
414
430
 
415
- const since = this.sequence(chatId);
416
- const result = await this.transport.request('chat.attach', { chatId, historyLimit: HISTORY_PAGE, ...(since === undefined ? {} : { since }) });
417
431
  const current = this.mounted.get(chatId);
418
432
 
419
433
  if (current !== entry) {
@@ -461,6 +475,49 @@ export class ChatClient {
461
475
  // A host without bookmarks or visuals sends none, and then this chat has none.
462
476
  this.sink.bookmarks(chatId, result.bookmarks ?? []);
463
477
  this.sink.visuals(chatId, result.visuals ?? []);
478
+ this.sink.suggestion?.(chatId, result.suggestion ?? null);
479
+ }
480
+
481
+ /*
482
+ * Makes the chat and attaches it in one request. A host that predates `create` on `chat.attach`
483
+ * ignores it and refuses a chat it does not have yet, which is then made with `chat.create` first.
484
+ * Null when the chat was closed or opened again before that attach: an opening still there attaches itself.
485
+ */
486
+ private async openOnHost(chatId: string, entry: Mounted, since: number | undefined): Promise<ChatRequestMap['chat.attach']['result'] | null> {
487
+ const read = { chatId, historyLimit: HISTORY_PAGE, ...(since === undefined ? {} : { since }) };
488
+
489
+ if (entry.observerOnly) {
490
+ return this.transport.request('chat.attach', read);
491
+ }
492
+
493
+ const create = {
494
+ provider: entry.provider,
495
+ account: entry.account,
496
+ cwd: entry.cwd,
497
+ resume: entry.resume,
498
+ selection: entry.selection,
499
+ runtimeMode: entry.runtimeMode
500
+ };
501
+
502
+ try {
503
+ return await this.transport.request('chat.attach', { ...read, create });
504
+ } catch (e) {
505
+ if (errorCode(e) !== 'chat-not-found') {
506
+ throw e;
507
+ }
508
+ }
509
+
510
+ if (this.mounted.get(chatId) !== entry) {
511
+ return null;
512
+ }
513
+
514
+ await this.transport.request('chat.create', { chatId, ...create });
515
+
516
+ if (this.mounted.get(chatId) !== entry) {
517
+ return null;
518
+ }
519
+
520
+ return this.transport.request('chat.attach', read);
464
521
  }
465
522
 
466
523
  private sequence(chatId: string): number | undefined {
package/src/chat-sink.ts CHANGED
@@ -41,9 +41,14 @@ export interface ChatSink {
41
41
  apply(chatId: string, event: ChatThreadEvent): void;
42
42
  /* A reconnect can publish its complete replay at once; absent sinks receive each event through apply. */
43
43
  replay?(chatId: string, events: readonly ChatThreadEvent[]): void;
44
- /* What a chat is doing, for a thread nobody in this window has open. */
44
+ /*
45
+ * What a chat is doing, for a thread nobody in this window has open. Its `slashCommands` may be empty
46
+ * and its `skills` absent when it came from a list that left them out, so a sink keeps the ones it holds.
47
+ */
45
48
  status(chatId: string, info: ChatThreadInfo): void;
46
49
  bookmarks(chatId: string, bookmarks: ChatBookmark[]): void;
47
50
  visuals(chatId: string, visuals: ChatVisual[]): void;
51
+ /* The next prompt the CLI predicted; a sink without it shows none. */
52
+ suggestion?(chatId: string, suggestion: string | null): void;
48
53
  forget(chatId: string): void;
49
54
  }
@@ -4,8 +4,9 @@
4
4
  * hooks are called through these wrappers only. `ChatHostProvider` pins its host, so they never change.
5
5
  */
6
6
  import type { ProviderPlatform } from '@adecore/agent-contracts';
7
+ import type { ReactNode } from 'react';
7
8
  import type { AccountRule } from './host';
8
- import { useChatHost, type ChatHost, type CommandLook, type ComposerStatusItem, type UnknownItemWords } from './host';
9
+ import { useChatHost, type ChatHost, type CommandLook, type ComposerStatusItem, type HostSkill, type HostTaskRow, type UnknownItemWords } from './host';
9
10
  import { referablesOfChats, type Referables } from './references';
10
11
 
11
12
  export function useHostCodeMode(): 'light' | 'dark' {
@@ -82,6 +83,23 @@ export function useHostExpandingCommands(): ReturnType<NonNullable<ChatHost['use
82
83
  return useExpanding();
83
84
  }
84
85
 
86
+ const NO_SKILLS: readonly HostSkill[] = [];
87
+ const noSkills = (): readonly HostSkill[] => NO_SKILLS;
88
+
89
+ export function useHostSkills(scopeId: string, chatId: string): readonly HostSkill[] {
90
+ const useSkills = useChatHost().useSkills ?? noSkills;
91
+
92
+ return useSkills(scopeId, chatId);
93
+ }
94
+
95
+ const noTaskRow = (): ReactNode => null;
96
+
97
+ export function useHostTaskRow(row: HostTaskRow): ReactNode {
98
+ const useTaskRow = useChatHost().useTaskRow ?? noTaskRow;
99
+
100
+ return useTaskRow(row);
101
+ }
102
+
85
103
  const noPlatform = (): ProviderPlatform | null => null;
86
104
 
87
105
  export function useHostMachinePlatform(scopeId: string): ProviderPlatform | null {
package/src/host/host.ts CHANGED
@@ -130,6 +130,23 @@ export interface SubagentTask {
130
130
  paused?: { until?: number };
131
131
  }
132
132
 
133
+ /* Where a task's row says its agent stands: the task's own state, or `waiting` while the agent waits on a person. */
134
+ export type TaskRowState = 'running' | 'paused' | 'done' | 'failed' | 'cancelled' | 'waiting';
135
+
136
+ /* What the row of a task given to another agent stands on, for a host that draws that row itself. */
137
+ export interface HostTaskRow {
138
+ scopeId: string;
139
+ /* The chat whose thread holds the row. */
140
+ chatId: string;
141
+ item: ChatSubagentItem;
142
+ task: SubagentTask | null;
143
+ state: TaskRowState;
144
+ /* Whether the row's work is folded out under it. */
145
+ open: boolean;
146
+ /* What pressing the row does: open the agent's conversation, or fold its work out. */
147
+ onPress(): void;
148
+ }
149
+
133
150
  /* What a find in a thread needs of it, and what it hands back to draw. */
134
151
  export interface TimelineFindOptions {
135
152
  chatId: string;
@@ -464,6 +481,18 @@ export interface AgentMark {
464
481
  fillRule?: 'nonzero' | 'evenodd';
465
482
  }
466
483
 
484
+ /*
485
+ * A skill of the host's own, picked after `$` like a CLI's. The text holds `$<name>`, which is what is
486
+ * sent, copied and pasted; the menu and the chip show `title` under the host's mark.
487
+ */
488
+ export interface HostSkill {
489
+ readonly name: string;
490
+ readonly title: string;
491
+ /* The hint beside the title in the menu; empty for none. */
492
+ readonly description: string;
493
+ readonly icon: AgentMark;
494
+ }
495
+
467
496
  /* The words of the row an item of a newer host gets, such as naming the app a person updates. */
468
497
  export interface UnknownItemWords {
469
498
  /* For an item that only shows something. */
@@ -483,12 +512,24 @@ export interface ChatHost {
483
512
  /* Commands of the host's own after `/`, which turn into the prompt instead of reaching the CLI. */
484
513
  useExpandingCommands?(): readonly { name: string; hint: string; expand(args: string): Promise<string> }[];
485
514
 
515
+ /*
516
+ * Skills of the host's own for a chat, offered after `$` above the CLI's. Hand back an empty list while it
517
+ * loads or when it failed, and the same array while none changed; left out, only the CLI's skills show.
518
+ */
519
+ useSkills?(scopeId: string, chatId: string): readonly HostSkill[];
520
+
486
521
  /* Under an empty thread's own words. */
487
522
  renderEmptyThread?(chatId: string): ReactNode;
488
523
 
489
524
  /* Over a tool call's body. */
490
525
  renderToolActions?(tool: { name: string; input: unknown; output: string | null; state: string }, chatId: string | undefined): ReactNode;
491
526
 
527
+ /*
528
+ * The row of a task given to another agent, drawn by the host; null keeps the standard row. `TaskRowHead`
529
+ * draws that row's own line, for a host that builds on it rather than replacing all of it.
530
+ */
531
+ useTaskRow?(row: HostTaskRow): ReactNode;
532
+
492
533
  /* A tool call the host draws itself, under its line; null leaves it to the thread. */
493
534
  renderToolResult?(tool: { name: string; input: unknown; output: string | null; state: string }, chatId: string | undefined): ReactNode;
494
535
 
package/src/index.ts CHANGED
@@ -5,6 +5,8 @@ export {
5
5
  type ShellCodeBlockContext,
6
6
  type ChatPlace,
7
7
  type SubagentTask,
8
+ type TaskRowState,
9
+ type HostTaskRow,
8
10
  type TimelineFindOptions,
9
11
  type TimelineFind,
10
12
  type ComposerDictationProps,
@@ -33,6 +35,7 @@ export {
33
35
  type ToolLookMatch,
34
36
  ChatHostProvider,
35
37
  type AgentMark,
38
+ type HostSkill,
36
39
  type ChatHostLayer,
37
40
  useChatHost
38
41
  } from './host/host';
@@ -397,7 +397,8 @@ export default {
397
397
  files: 'files',
398
398
  references: 'views',
399
399
  skills: 'skills',
400
- readOnly: 'Go back to the main agent to write'
400
+ readOnly: 'Go back to the main agent to write',
401
+ suggestion: 'to fill in'
401
402
  },
402
403
  jumpToEnd: 'Jump to end',
403
404
  mentions: {
@@ -397,7 +397,8 @@ export default {
397
397
  files: 'bestanden',
398
398
  references: 'weergaven',
399
399
  skills: 'skills',
400
- readOnly: 'Ga terug naar de main agent om te schrijven'
400
+ readOnly: 'Ga terug naar de main agent om te schrijven',
401
+ suggestion: 'om in te vullen'
401
402
  },
402
403
  jumpToEnd: 'Naar het einde',
403
404
  mentions: {