@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
package/src/chat/mentions.ts
CHANGED
|
@@ -117,7 +117,12 @@ export type ChipSegment =
|
|
|
117
117
|
| { kind: 'text'; text: string }
|
|
118
118
|
| { kind: 'mention'; path: string }
|
|
119
119
|
| { kind: 'skill'; name: string }
|
|
120
|
-
| { kind: 'reference'; id: string; name: string }
|
|
120
|
+
| { kind: 'reference'; id: string; name: string }
|
|
121
|
+
| { kind: 'model'; cli: string; id: string }
|
|
122
|
+
| { kind: 'account'; cli: string; id: string };
|
|
123
|
+
|
|
124
|
+
/* A model or a provider account, spelled in the text as `@model:<cli>/<id>` or `@account:<cli>/<id>`. */
|
|
125
|
+
export type NamedChipKind = 'model' | 'account';
|
|
121
126
|
|
|
122
127
|
function isBoundary(char: string | undefined): boolean {
|
|
123
128
|
return char === undefined || /\s/.test(char);
|
|
@@ -176,13 +181,13 @@ export function findSkillQuery(text: string, caret: number): MentionQuery | null
|
|
|
176
181
|
}
|
|
177
182
|
|
|
178
183
|
/*
|
|
179
|
-
* The `#word` the caret sits in
|
|
180
|
-
* `#
|
|
184
|
+
* The `#word` the caret sits in, open from the bare sigil on. The name has to start with a letter, so
|
|
185
|
+
* a `# ` heading and `#123` close it again and stay text. A name with a space is found by its first word.
|
|
181
186
|
*/
|
|
182
187
|
export function findReferenceQuery(text: string, caret: number): MentionQuery | null {
|
|
183
188
|
const found = findQuery(text, caret, '#');
|
|
184
189
|
|
|
185
|
-
return found === null || !/^\p{L}/u.test(found.query) ? null : found;
|
|
190
|
+
return found === null || (found.query !== '' && !/^\p{L}/u.test(found.query)) ? null : found;
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
/* Replaces the `<sigil>query` under the caret with the chosen token and a space, and says where the caret goes. */
|
|
@@ -213,13 +218,28 @@ export interface MentionSearch {
|
|
|
213
218
|
|
|
214
219
|
export const NO_MENTION_SEARCH: MentionSearch = { query: null, files: [] };
|
|
215
220
|
|
|
216
|
-
/*
|
|
217
|
-
export
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
/* A row of the `@` list above the files: a model or an account, which become a named chip. */
|
|
222
|
+
export interface NamedPick {
|
|
223
|
+
kind: NamedChipKind;
|
|
224
|
+
cli: string;
|
|
225
|
+
id: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type MentionPick = { kind: 'file'; path: string } | NamedPick;
|
|
229
|
+
|
|
230
|
+
/*
|
|
231
|
+
* What Enter or Tab takes from the `@` list at `index`: `named` first, then the files. Those answer the
|
|
232
|
+
* query typed now, so they are always taken; files still on screen from an older query never are.
|
|
233
|
+
*/
|
|
234
|
+
export function mentionPick(index: number, search: MentionSearch, query: string, named: readonly NamedPick[] = []): MentionPick | null {
|
|
235
|
+
const count = named.length + search.files.length;
|
|
236
|
+
const at = index < count ? index : 0;
|
|
237
|
+
|
|
238
|
+
if (at < named.length) {
|
|
239
|
+
return named[at] ?? null;
|
|
220
240
|
}
|
|
221
241
|
|
|
222
|
-
return search.
|
|
242
|
+
return search.query === query ? { kind: 'file', path: search.files[at - named.length]! } : null;
|
|
223
243
|
}
|
|
224
244
|
|
|
225
245
|
function findToken(text: string, sigil: string, value: string, from: number): number {
|
|
@@ -284,6 +304,10 @@ export function chipText(segment: ChipSegment): string {
|
|
|
284
304
|
return `#${segment.name}`;
|
|
285
305
|
}
|
|
286
306
|
|
|
307
|
+
if (segment.kind === 'model' || segment.kind === 'account') {
|
|
308
|
+
return namedChipToken(segment.kind, segment.cli, segment.id);
|
|
309
|
+
}
|
|
310
|
+
|
|
287
311
|
return segment.text;
|
|
288
312
|
}
|
|
289
313
|
|
|
@@ -306,12 +330,79 @@ export interface TextRange {
|
|
|
306
330
|
to: number;
|
|
307
331
|
}
|
|
308
332
|
|
|
309
|
-
/* `value` is the path, the skill's name
|
|
333
|
+
/* `value` is the path, the skill's name, a reference's id or a model's or account's `<cli>/<id>`; the range spans the name. */
|
|
310
334
|
export interface ChipRange extends TextRange {
|
|
311
|
-
kind: 'mention' | 'skill' | 'reference';
|
|
335
|
+
kind: 'mention' | 'skill' | 'reference' | NamedChipKind;
|
|
312
336
|
value: string;
|
|
313
337
|
}
|
|
314
338
|
|
|
339
|
+
export function namedChipToken(kind: NamedChipKind, cli: string, id: string): string {
|
|
340
|
+
return `@${kind}:${cli}/${id}`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* The part of a named chip its CLI's mark stands in for: `@model:claude/`. */
|
|
344
|
+
export function namedChipPrefix(kind: NamedChipKind, cli: string): string {
|
|
345
|
+
return `@${kind}:${cli}/`;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// The id runs to whitespace or a backtick; a slash belongs to it (`openrouter/anthropic/claude`).
|
|
349
|
+
const NAMED_CHIP = /@(model|account):([a-z0-9][a-z0-9-]*)\/([^\s`]+)/g;
|
|
350
|
+
|
|
351
|
+
// Punctuation after the id ends the sentence, except a `]` that closes a `[` in the id (`claude-opus-5-5[1m]`).
|
|
352
|
+
function trimmedId(id: string): string {
|
|
353
|
+
let end = id.length;
|
|
354
|
+
|
|
355
|
+
while (end > 0 && TOKEN_END.test(id[end - 1]!) && !(id[end - 1] === ']' && id.lastIndexOf('[', end - 1) >= 0)) {
|
|
356
|
+
end -= 1;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return id.slice(0, end);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/*
|
|
363
|
+
* Where the text spells a model or an account, found by the pattern alone, so these chips need no list
|
|
364
|
+
* in a draft or on an item. The token opens a word or follows an opening bracket or quote; one that
|
|
365
|
+
* overlaps an excluded range (a code span, say) is text.
|
|
366
|
+
*/
|
|
367
|
+
export function namedChipRanges(text: string, excluded: readonly TextRange[] = []): ChipRange[] {
|
|
368
|
+
const ranges: ChipRange[] = [];
|
|
369
|
+
|
|
370
|
+
for (const found of text.matchAll(NAMED_CHIP)) {
|
|
371
|
+
const from = found.index;
|
|
372
|
+
const id = trimmedId(found[3]!);
|
|
373
|
+
const to = from + found[0].length - (found[3]!.length - id.length);
|
|
374
|
+
|
|
375
|
+
if (id === '' || (from > 0 && !REFERENCE_OPENER.test(text[from - 1]!)) || excluded.some((range) => from < range.to && to > range.from)) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
ranges.push({ from, to, kind: found[1] as NamedChipKind, value: `${found[2]}/${id}` });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return ranges;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/* The picked chips and the named ones together, in text order; where two overlap, the one that starts first stays. */
|
|
386
|
+
export function withNamedChips(text: string, picked: readonly ChipRange[], excluded: readonly TextRange[] = []): ChipRange[] {
|
|
387
|
+
const named = namedChipRanges(text, excluded);
|
|
388
|
+
|
|
389
|
+
if (named.length === 0) {
|
|
390
|
+
return [...picked];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const merged: ChipRange[] = [];
|
|
394
|
+
|
|
395
|
+
for (const range of [...picked, ...named].sort((a, b) => a.from - b.from || b.to - a.to)) {
|
|
396
|
+
const last = merged.at(-1);
|
|
397
|
+
|
|
398
|
+
if (last === undefined || range.from >= last.to) {
|
|
399
|
+
merged.push(range);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return merged;
|
|
404
|
+
}
|
|
405
|
+
|
|
315
406
|
/*
|
|
316
407
|
* Where the chosen mentions, skills and references sit in the text, in text order; longer values win
|
|
317
408
|
* when one prefixes another. A token that overlaps an excluded range (a code span, say) is text.
|
|
@@ -370,12 +461,18 @@ function segmentOf(text: string, range: ChipRange): ChipSegment {
|
|
|
370
461
|
return { kind: 'skill', name: range.value };
|
|
371
462
|
}
|
|
372
463
|
|
|
464
|
+
if (range.kind === 'model' || range.kind === 'account') {
|
|
465
|
+
const slash = range.value.indexOf('/');
|
|
466
|
+
|
|
467
|
+
return { kind: range.kind, cli: range.value.slice(0, slash), id: range.value.slice(slash + 1) };
|
|
468
|
+
}
|
|
469
|
+
|
|
373
470
|
return { kind: 'reference', id: range.value, name: text.slice(range.from + 1, range.to) };
|
|
374
471
|
}
|
|
375
472
|
|
|
376
|
-
/* Splits the text so a renderer can draw the mentions, skills and
|
|
473
|
+
/* Splits the text so a renderer can draw the mentions, skills, references, models and accounts as chips. */
|
|
377
474
|
export function tokenizeChips(text: string, mentions: string[], skills: string[] = [], references: readonly ReferenceToken[] = []): ChipSegment[] {
|
|
378
|
-
return segmentsOf(text, chipRanges(text, mentions, skills, [], references));
|
|
475
|
+
return segmentsOf(text, withNamedChips(text, chipRanges(text, mentions, skills, [], references)));
|
|
379
476
|
}
|
|
380
477
|
|
|
381
478
|
// What a `#` may follow in a text nobody typed through the picker: a space, or an opening bracket or quote.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { activeSubagents, type ChatInfo, type ChatItem, type ChatSubagentItem } from '@adecore/agent-contracts';
|
|
2
|
-
import { formatMoment, formatElapsedShort
|
|
2
|
+
import { formatMoment, formatElapsedShort } from '@adecore/ui/format';
|
|
3
3
|
import i18next from 'i18next';
|
|
4
4
|
import type { StatusWord } from '../agents/status-look';
|
|
5
5
|
import type { SubagentTask } from '../host';
|
|
@@ -8,19 +8,6 @@ export function subagentTitle(item: ChatSubagentItem): string {
|
|
|
8
8
|
return item.description || item.summary || item.subagentType || i18next.t('agent-chat:rows.subagent.label');
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
/* What the bar over a sub-agent's conversation says of it beside its state and its time; the model is named by the caller, which has the catalog. */
|
|
12
|
-
export function subagentFacts(item: ChatSubagentItem, modelName: string | null): string[] {
|
|
13
|
-
return [
|
|
14
|
-
modelName,
|
|
15
|
-
item.subagentType,
|
|
16
|
-
item.background ? i18next.t('agent-chat:rows.subagent.background') : null,
|
|
17
|
-
item.usage !== null && item.usage.totalTokens > 0
|
|
18
|
-
? i18next.t('agent-chat:subagents.info.tokens', { tokens: formatTokens(item.usage.totalTokens) })
|
|
19
|
-
: null,
|
|
20
|
-
item.usage !== null && item.usage.toolUses > 0 ? i18next.t('agent-chat:group.toolCalls', { count: item.usage.toolUses }) : null
|
|
21
|
-
].filter((fact): fact is string => fact !== null && fact !== '');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
11
|
/* The task a row stands for, whose id the host wrote into the row's own. */
|
|
25
12
|
export function taskIdOf(item: ChatSubagentItem): string | null {
|
|
26
13
|
return item.origin === 'ruimte' && item.id.startsWith('task-') ? item.id.slice(5) : null;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { AgentKind, ModelInfo, ProviderAccounts, ProviderAccountState, ProviderInfo } from '@adecore/agent-contracts';
|
|
2
|
+
import { accountName, accountsOfKind, hasAccountChoice, projectOffered, type AccountEntry, type AccountRule } from '../agents/accounts';
|
|
3
|
+
import { modelRequirementOf } from '../agents/model-requirement';
|
|
4
|
+
import { inPickerOrder } from './logic/picker-entries';
|
|
5
|
+
import type { NamedPick } from './mentions';
|
|
6
|
+
|
|
7
|
+
export const MODEL_SUGGESTIONS = 5;
|
|
8
|
+
export const ACCOUNT_SUGGESTIONS = 3;
|
|
9
|
+
|
|
10
|
+
export interface ModelSuggestion extends NamedPick {
|
|
11
|
+
kind: 'model';
|
|
12
|
+
cli: AgentKind;
|
|
13
|
+
provider: ProviderInfo;
|
|
14
|
+
model: ModelInfo;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AccountSuggestion extends NamedPick {
|
|
18
|
+
kind: 'account';
|
|
19
|
+
cli: AgentKind;
|
|
20
|
+
provider: ProviderInfo;
|
|
21
|
+
entry: AccountEntry;
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A CLI no model runs under while its accounts say this.
|
|
26
|
+
const UNUSABLE: ReadonlySet<ProviderAccountState> = new Set(['signed-out', 'not-found', 'folder-missing', 'failed']);
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Whether the query opens a word of the text: `op` and `opus-5` in "Opus 5.5" or `claude-opus-5-5`, never
|
|
30
|
+
* `pus`. A vendor is no word of a model, so `@open` keeps finding files.
|
|
31
|
+
*/
|
|
32
|
+
export function startsAWord(text: string, query: string): boolean {
|
|
33
|
+
const haystack = text.toLowerCase();
|
|
34
|
+
const needle = query.toLowerCase();
|
|
35
|
+
let index = needle === '' ? -1 : haystack.indexOf(needle);
|
|
36
|
+
|
|
37
|
+
while (index >= 0) {
|
|
38
|
+
if (index === 0 || !/[\p{L}\p{N}]/u.test(haystack[index - 1]!)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
index = haystack.indexOf(needle, index + 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Whether a CLI can run a model now: one of its enabled accounts is signed in, or it keeps no accounts at all. */
|
|
49
|
+
export function signedIn(accounts: ProviderAccounts | null, kind: AgentKind): boolean {
|
|
50
|
+
const entries = accountsOfKind(accounts, kind);
|
|
51
|
+
|
|
52
|
+
if (entries.length === 0) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return entries.some((entry) => entry.account.enabled !== false && (entry.status === null || !UNUSABLE.has(entry.status.state)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* The models the `@` list offers for a query: of a CLI that is installed, chats and is signed in, and
|
|
61
|
+
* that the CLI is new enough for. Legacy models last, at most `MODEL_SUGGESTIONS`. A bare `@` offers none.
|
|
62
|
+
*/
|
|
63
|
+
export function modelSuggestions(
|
|
64
|
+
providers: readonly ProviderInfo[],
|
|
65
|
+
accounts: ProviderAccounts | null,
|
|
66
|
+
query: string,
|
|
67
|
+
reportedOf: (kind: AgentKind) => ReadonlySet<string>
|
|
68
|
+
): ModelSuggestion[] {
|
|
69
|
+
if (query === '') {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const found = inPickerOrder(providers.filter((entry) => entry.installed && entry.capabilities.chat && signedIn(accounts, entry.kind))).flatMap((provider) =>
|
|
74
|
+
provider.models
|
|
75
|
+
.filter(
|
|
76
|
+
(model) =>
|
|
77
|
+
(startsAWord(model.name, query) || startsAWord(model.slug, query)) &&
|
|
78
|
+
modelRequirementOf(model, provider, reportedOf(provider.kind)) === null
|
|
79
|
+
)
|
|
80
|
+
.map((model): ModelSuggestion => ({ kind: 'model', cli: provider.kind, id: model.slug, provider, model }))
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return [...found.filter((entry) => !entry.model.legacy), ...found.filter((entry) => entry.model.legacy)].slice(0, MODEL_SUGGESTIONS);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
* The accounts the `@` list offers for a query, by the name a person sees: those that are ready, of a CLI
|
|
88
|
+
* with a choice of account, that the project offers. At most `ACCOUNT_SUGGESTIONS`.
|
|
89
|
+
*/
|
|
90
|
+
export function accountSuggestions(
|
|
91
|
+
providers: readonly ProviderInfo[],
|
|
92
|
+
accounts: ProviderAccounts | null,
|
|
93
|
+
rule: AccountRule | null,
|
|
94
|
+
query: string
|
|
95
|
+
): AccountSuggestion[] {
|
|
96
|
+
if (query === '' || accounts === null) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return inPickerOrder(providers.filter((entry) => entry.installed && entry.capabilities.chat))
|
|
101
|
+
.flatMap((provider) => {
|
|
102
|
+
const entries = accountsOfKind(accounts, provider.kind);
|
|
103
|
+
|
|
104
|
+
if (!hasAccountChoice(entries)) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return projectOffered(entries, rule, provider.kind, undefined)
|
|
109
|
+
.filter((entry) => entry.account.enabled !== false && entry.status?.state === 'ready')
|
|
110
|
+
.map((entry): AccountSuggestion => ({
|
|
111
|
+
kind: 'account',
|
|
112
|
+
cli: provider.kind,
|
|
113
|
+
id: entry.id,
|
|
114
|
+
provider,
|
|
115
|
+
entry,
|
|
116
|
+
name: accountName(entry, provider.name)
|
|
117
|
+
}))
|
|
118
|
+
.filter((suggestion) => startsAWord(suggestion.name, query));
|
|
119
|
+
})
|
|
120
|
+
.slice(0, ACCOUNT_SUGGESTIONS);
|
|
121
|
+
}
|
package/src/chat/ui/Composer.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { ChevronDown } from 'lucide-react';
|
|
|
6
6
|
import { useEffect, useRef, useState, useSyncExternalStore, type MouseEvent, type PointerEvent } from 'react';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { useChatHost } from '../../host';
|
|
9
|
-
import { useHostComposerSendActions, useHostExtraPrompts, useHostSendDelivery } from '../../host-hooks';
|
|
9
|
+
import { useHostComposerSendActions, useHostComposerStatus, useHostExtraPrompts, useHostSendDelivery } from '../../host-hooks';
|
|
10
10
|
import { canSteer } from '../../providers/provider-abilities';
|
|
11
11
|
import { useChatScope } from '../../scope';
|
|
12
12
|
import { useProviders } from '../../state/providers';
|
|
@@ -22,6 +22,7 @@ import { ChatActivity } from './ChatActivity';
|
|
|
22
22
|
import { chipDecorations } from './composer/chips';
|
|
23
23
|
import { ComposerControls } from './composer/ComposerControls';
|
|
24
24
|
import { ComposerMenu } from './composer/ComposerMenu';
|
|
25
|
+
import { ComposerStatusLine } from './composer/ComposerStatusLine';
|
|
25
26
|
import { DraftAttachments, DraftQuote } from './composer/DraftParts';
|
|
26
27
|
import { composerKeyHandler } from './composer/key-handler';
|
|
27
28
|
import { useHintedPlaceholder } from './composer/placeholder';
|
|
@@ -141,6 +142,7 @@ export function Composer({
|
|
|
141
142
|
const [sentFor, setSentFor] = useState<string | null>(null);
|
|
142
143
|
const extraPrompts = useHostExtraPrompts(scope.id, chatId);
|
|
143
144
|
const sendActions = useHostComposerSendActions(scope.id, chatId);
|
|
145
|
+
const statusItems = useHostComposerStatus(scope.id, chatId);
|
|
144
146
|
|
|
145
147
|
const { submit, continueTurn, restoreStashed, toggleStash } = useComposerSubmit({
|
|
146
148
|
chatId,
|
|
@@ -189,16 +191,16 @@ export function Composer({
|
|
|
189
191
|
|
|
190
192
|
const pending = usePendingRequests(chatId);
|
|
191
193
|
const compactionOffer = useCompactionOffer(chatId, info, capabilities?.compaction);
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
disabled,
|
|
195
|
-
readOnly,
|
|
196
|
-
mentionable: capabilities?.mentions !== false,
|
|
197
|
-
referable: menus.offersViews,
|
|
198
|
-
hasSkills: menus.hasSkills
|
|
199
|
-
});
|
|
194
|
+
const sigils = { mentionable: capabilities?.mentions !== false, referable: menus.offersViews, hasSkills: menus.hasSkills };
|
|
195
|
+
const placeholder = useHintedPlaceholder({ chatId, disabled, readOnly, ...sigils });
|
|
200
196
|
const editorExtensions = [
|
|
201
|
-
chipDecorations({
|
|
197
|
+
chipDecorations({
|
|
198
|
+
mentions: draft.mentions,
|
|
199
|
+
skills: draft.skills,
|
|
200
|
+
references: menus.referenceChips,
|
|
201
|
+
referenceIcon: host.ReferenceIcon,
|
|
202
|
+
named: menus.namedLook
|
|
203
|
+
}),
|
|
202
204
|
LEAVE_DROPS_TO_THE_CARD
|
|
203
205
|
];
|
|
204
206
|
|
|
@@ -245,7 +247,7 @@ export function Composer({
|
|
|
245
247
|
};
|
|
246
248
|
|
|
247
249
|
return (
|
|
248
|
-
<div className="chat-composer-content pointer-events-none relative z-10 w-full">
|
|
250
|
+
<div className="chat-composer-content pointer-events-none relative z-10 @container/composer-area w-full">
|
|
249
251
|
{/* Over the composer rather than in the thread, since the composer's height is the one it always clears.
|
|
250
252
|
A read-only composer sits under something that stands in the thread's place, whose end is not this one. */}
|
|
251
253
|
{!atEnd && !readOnly && (
|
|
@@ -263,7 +265,8 @@ export function Composer({
|
|
|
263
265
|
<ChatActivity chatId={chatId} workflows={workflowPill} />
|
|
264
266
|
<div
|
|
265
267
|
className={clsx(
|
|
266
|
-
|
|
268
|
+
// Above the status line, whose fade starts under the card's lower edge.
|
|
269
|
+
'@container/composer pointer-events-auto relative z-1 flex flex-col overflow-hidden rounded-2xl border shadow-float backdrop-blur-[14px] focus-ring-within',
|
|
267
270
|
files.dragging
|
|
268
271
|
? 'border-accent bg-[color-mix(in_srgb,var(--accent-soft)_60%,var(--surface-raised))]'
|
|
269
272
|
: 'border-border bg-[color-mix(in_srgb,var(--surface-raised)_92%,transparent)]'
|
|
@@ -365,6 +368,8 @@ export function Composer({
|
|
|
365
368
|
providerFixed={providerFixed}
|
|
366
369
|
writable={writable}
|
|
367
370
|
attachable={capabilities?.attachments !== false}
|
|
371
|
+
emptyDraft={empty}
|
|
372
|
+
sigils={sigils}
|
|
368
373
|
controls={controls}
|
|
369
374
|
send={{
|
|
370
375
|
visible: !busy || !empty,
|
|
@@ -392,6 +397,12 @@ export function Composer({
|
|
|
392
397
|
inputRef.current?.focus();
|
|
393
398
|
}}
|
|
394
399
|
onRestore={restoreStashed}
|
|
400
|
+
onStash={toggleStash}
|
|
401
|
+
onSigil={(sigil) => {
|
|
402
|
+
if (writable) {
|
|
403
|
+
inputRef.current?.insertSigil(sigil);
|
|
404
|
+
}
|
|
405
|
+
}}
|
|
395
406
|
insert={(added) => {
|
|
396
407
|
if (writable) {
|
|
397
408
|
inputRef.current?.insert(added);
|
|
@@ -401,6 +412,7 @@ export function Composer({
|
|
|
401
412
|
</div>
|
|
402
413
|
</PromptComposer>
|
|
403
414
|
</div>
|
|
415
|
+
<ComposerStatusLine items={statusItems} />
|
|
404
416
|
<PromptDialog
|
|
405
417
|
open={controls.confirmClear}
|
|
406
418
|
title={t('composer.clear.title')}
|
|
@@ -4,7 +4,7 @@ import { EditorView, placeholder as placeholderText } from '@codemirror/view';
|
|
|
4
4
|
import { useImperativeHandle, useLayoutEffect, useRef, useState, type Ref } from 'react';
|
|
5
5
|
import { useChatHost } from '../../host';
|
|
6
6
|
import { composerEditorExtensions, externalChange } from './composer/editor';
|
|
7
|
-
import { insertAtSelection } from './composer/insert';
|
|
7
|
+
import { insertAtSelection, insertSigil } from './composer/insert';
|
|
8
8
|
|
|
9
9
|
export interface ComposerInputHandle {
|
|
10
10
|
focus(): void;
|
|
@@ -12,6 +12,8 @@ export interface ComposerInputHandle {
|
|
|
12
12
|
setCaret(pos: number): void;
|
|
13
13
|
/* Types text in over the selection (`insertAtSelection`) and gives the editor the focus. */
|
|
14
14
|
insert(text: string): void;
|
|
15
|
+
/* Types a sigil at the caret (`insertSigil`), which opens its picker, and gives the editor the focus. */
|
|
16
|
+
insertSigil(sigil: string): void;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export interface InputSelection {
|
|
@@ -218,6 +220,16 @@ export function ComposerInput({
|
|
|
218
220
|
|
|
219
221
|
view.dispatch(insertAtSelection(view.state, text));
|
|
220
222
|
view.focus();
|
|
223
|
+
},
|
|
224
|
+
insertSigil: (sigil: string) => {
|
|
225
|
+
const view = viewRef.current;
|
|
226
|
+
|
|
227
|
+
if (!view) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
view.focus();
|
|
232
|
+
view.dispatch(insertSigil(view.state, sigil));
|
|
221
233
|
}
|
|
222
234
|
}),
|
|
223
235
|
[]
|
package/src/chat/ui/Markdown.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import { DisplayImage } from './DisplayImage';
|
|
|
15
15
|
import { useFileLinkCwd, useFileLinkScopeId, useFileLinkTarget, useOpenFileLink } from './file-links';
|
|
16
16
|
import { createMarkdownBlockSplitter } from './markdown-blocks';
|
|
17
17
|
import { MermaidBlock } from './MermaidBlock';
|
|
18
|
+
import { NamedChip } from './NamedChip';
|
|
18
19
|
import { ReferenceLookupContext } from './reference-lookup';
|
|
19
20
|
import { ReferenceChip, TokenChip } from './ReferenceChip';
|
|
20
21
|
import { rehypeChips, rehypeNamedReferences, type ChipOptions, type NamedReferenceOptions } from './rehype-chips';
|
|
@@ -358,6 +359,10 @@ function Chip({ kind, value }: { kind: string; value: string }) {
|
|
|
358
359
|
return <ReferenceChip id={value} />;
|
|
359
360
|
}
|
|
360
361
|
|
|
362
|
+
if (kind === 'model' || kind === 'account') {
|
|
363
|
+
return <NamedChip kind={kind} value={value} />;
|
|
364
|
+
}
|
|
365
|
+
|
|
361
366
|
if (kind === 'skill') {
|
|
362
367
|
return (
|
|
363
368
|
<TokenChip
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AgentKind } from '@adecore/agent-contracts';
|
|
2
|
+
import { CliMark } from '../../agents/AgentModelLabel';
|
|
3
|
+
import { namedChipPrefix, type NamedChipKind } from '../mentions';
|
|
4
|
+
import { REFERENCE_TONE, TOKEN_ICON_BOX } from './chips';
|
|
5
|
+
import { useNamedChipLookup } from './named-chip-look';
|
|
6
|
+
import { TokenChip } from './ReferenceChip';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* A model or an account a message names, under its CLI's mark in the color of the account it runs on, and
|
|
10
|
+
* the name the machine knows it by. An id the machine does not know keeps the id. A copy reads the token.
|
|
11
|
+
*/
|
|
12
|
+
export function NamedChip({ kind, value }: { kind: NamedChipKind; value: string }) {
|
|
13
|
+
const lookup = useNamedChipLookup();
|
|
14
|
+
const slash = value.indexOf('/');
|
|
15
|
+
const cli = value.slice(0, slash);
|
|
16
|
+
const id = value.slice(slash + 1);
|
|
17
|
+
const { label, color } = lookup(kind, cli, id);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<TokenChip
|
|
21
|
+
kind={kind}
|
|
22
|
+
value={value}
|
|
23
|
+
sigil={namedChipPrefix(kind, cli)}
|
|
24
|
+
icon={
|
|
25
|
+
<span className={TOKEN_ICON_BOX} style={color === undefined ? undefined : { color }}>
|
|
26
|
+
<CliMark kind={cli as AgentKind} size={14} />
|
|
27
|
+
</span>
|
|
28
|
+
}
|
|
29
|
+
label={label}
|
|
30
|
+
spelled={label === id ? undefined : id}
|
|
31
|
+
tone={REFERENCE_TONE}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/chat/ui/Pickers.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentKind, ModelSelection, ProviderInfo, UsageProvider } from '@adecore/agent-contracts';
|
|
2
2
|
import { Button, Icon, IconButton, Menu, Popover, ScrollArea, Tooltip } from '@adecore/ui';
|
|
3
|
-
import {
|
|
3
|
+
import { ChevronDown, ChevronRight, Search, Star } from 'lucide-react';
|
|
4
4
|
import { useContext, useEffect, useRef, useState, type ReactNode, type RefObject } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { AgentIcon } from '../../agents/AgentIcon';
|
|
@@ -13,7 +13,6 @@ import { ChatScopeContext } from '../../scope';
|
|
|
13
13
|
import { useReportedModels } from '../../state/chats';
|
|
14
14
|
import { inPickerOrder, pickerEntriesOf, separatesGroups, type PickerEntry } from '../logic/picker-entries';
|
|
15
15
|
import { favoriteModelsOf, toggleFavoriteModel, useChatPreferences } from '../preferences';
|
|
16
|
-
import { forgetStashed, STASH_SHORTCUT, useStash, type StashedPrompt } from '../stash';
|
|
17
16
|
import { ModelMarks } from './ModelMarks';
|
|
18
17
|
|
|
19
18
|
const triggerClass =
|
|
@@ -341,52 +340,3 @@ export function ModelPicker({
|
|
|
341
340
|
</Popover.Root>
|
|
342
341
|
);
|
|
343
342
|
}
|
|
344
|
-
|
|
345
|
-
/*
|
|
346
|
-
* Prompts put aside with Cmd+S, on a shelf the whole app shares, since a stashed prompt usually moves
|
|
347
|
-
* to another chat. A draft's files are named on the row but not kept: their bytes never go to storage.
|
|
348
|
-
*/
|
|
349
|
-
export function StashPicker({ onRestore }: { onRestore(prompt: StashedPrompt): void }) {
|
|
350
|
-
const { t } = useTranslation('agent-chat');
|
|
351
|
-
const prompts = useStash((s) => s.prompts);
|
|
352
|
-
|
|
353
|
-
if (prompts.length === 0) {
|
|
354
|
-
return null;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return (
|
|
358
|
-
<Popover.Root>
|
|
359
|
-
<Tooltip label={t('pickers.stash.title')} kbd={STASH_SHORTCUT}>
|
|
360
|
-
<Popover.Trigger className={triggerClass}>
|
|
361
|
-
<Icon icon={Bookmark} size={12} />
|
|
362
|
-
<span className="tabular-nums">{prompts.length}</span>
|
|
363
|
-
</Popover.Trigger>
|
|
364
|
-
</Tooltip>
|
|
365
|
-
<Popover.Popup variant="picker" side="top" className="w-80">
|
|
366
|
-
<ScrollArea className="max-h-72" viewportClassName="p-1">
|
|
367
|
-
{prompts.map((prompt) => (
|
|
368
|
-
<div key={prompt.id} className="group/stash flex items-start gap-1">
|
|
369
|
-
<Popover.Close
|
|
370
|
-
className="flex min-w-0 grow flex-col gap-0.5 rounded-md px-2 py-1.5 text-left text-xs text-text-muted hover:bg-surface-hover hover:text-text"
|
|
371
|
-
onClick={() => onRestore(prompt)}
|
|
372
|
-
>
|
|
373
|
-
<span className="line-clamp-2 whitespace-pre-wrap">{prompt.text || prompt.quote?.text || t('pickers.stash.noText')}</span>
|
|
374
|
-
{prompt.attachments.length > 0 && (
|
|
375
|
-
<span className="text-text-faint">{t('pickers.stash.files', { count: prompt.attachments.length })}</span>
|
|
376
|
-
)}
|
|
377
|
-
{prompt.chats.length > 0 && <span className="text-text-faint">{t('pickers.stash.chats', { count: prompt.chats.length })}</span>}
|
|
378
|
-
</Popover.Close>
|
|
379
|
-
<IconButton
|
|
380
|
-
icon={Trash2}
|
|
381
|
-
size="xs"
|
|
382
|
-
label={t('common.action.delete')}
|
|
383
|
-
className="mt-1 opacity-0 group-hover/stash:opacity-100 focus-visible:opacity-100"
|
|
384
|
-
onClick={() => forgetStashed(prompt.id)}
|
|
385
|
-
/>
|
|
386
|
-
</div>
|
|
387
|
-
))}
|
|
388
|
-
</ScrollArea>
|
|
389
|
-
</Popover.Popup>
|
|
390
|
-
</Popover.Root>
|
|
391
|
-
);
|
|
392
|
-
}
|
|
@@ -79,7 +79,13 @@ export function PromptEditor({
|
|
|
79
79
|
label
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
const extensions = chipDecorations({
|
|
82
|
+
const extensions = chipDecorations({
|
|
83
|
+
mentions: value.mentions,
|
|
84
|
+
skills: value.skills,
|
|
85
|
+
references: menus.referenceChips,
|
|
86
|
+
referenceIcon: host.ReferenceIcon,
|
|
87
|
+
named: menus.namedLook
|
|
88
|
+
});
|
|
83
89
|
|
|
84
90
|
const onKeyDown = (e: KeyboardEvent): boolean => {
|
|
85
91
|
if (e.isComposing) {
|
|
@@ -11,13 +11,15 @@ import { ReferenceTrail } from './ReferenceTrail';
|
|
|
11
11
|
|
|
12
12
|
interface TokenChipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
|
|
13
13
|
/* `gone` for a reference that stands for nothing any more, which a copy leaves as text. */
|
|
14
|
-
kind: 'mention' | 'skill' | 'reference' | 'gone';
|
|
15
|
-
/* The path, the skill's name
|
|
14
|
+
kind: 'mention' | 'skill' | 'reference' | 'gone' | 'model' | 'account';
|
|
15
|
+
/* The path, the skill's name, the reference's id or a model's or account's `<cli>/<id>`. */
|
|
16
16
|
value?: string;
|
|
17
17
|
/* The sigil the mark stands in for. Hidden, but a selection copies it with the name. */
|
|
18
18
|
sigil?: string;
|
|
19
19
|
icon: ReactNode;
|
|
20
20
|
label: string;
|
|
21
|
+
/* What a selection copies in place of a label that is not the text, such as a model's id under its name. */
|
|
22
|
+
spelled?: string;
|
|
21
23
|
tone: string;
|
|
22
24
|
onOpen?: () => void;
|
|
23
25
|
}
|
|
@@ -27,7 +29,7 @@ interface TokenChipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children
|
|
|
27
29
|
* since a button is a box with a baseline of its own and would not sit on the line the others sit on.
|
|
28
30
|
* It stays out of prose, whose margins on an image would lift a host's picture mark off the line.
|
|
29
31
|
*/
|
|
30
|
-
export function TokenChip({ kind, value, sigil, icon, label, tone, onOpen, className, ...rest }: TokenChipProps) {
|
|
32
|
+
export function TokenChip({ kind, value, sigil, icon, label, spelled, tone, onOpen, className, ...rest }: TokenChipProps) {
|
|
31
33
|
const onKeyDown = (e: KeyboardEvent<HTMLSpanElement>): void => {
|
|
32
34
|
if (onOpen !== undefined && (e.key === 'Enter' || e.key === ' ')) {
|
|
33
35
|
e.preventDefault();
|
|
@@ -55,7 +57,16 @@ export function TokenChip({ kind, value, sigil, icon, label, tone, onOpen, class
|
|
|
55
57
|
>
|
|
56
58
|
{icon}
|
|
57
59
|
{sigil !== undefined && <span className="sr-only">{sigil}</span>}
|
|
58
|
-
{
|
|
60
|
+
{spelled === undefined ? (
|
|
61
|
+
label
|
|
62
|
+
) : (
|
|
63
|
+
<>
|
|
64
|
+
<span aria-hidden className="sr-only">
|
|
65
|
+
{spelled}
|
|
66
|
+
</span>
|
|
67
|
+
<span className="select-none">{label}</span>
|
|
68
|
+
</>
|
|
69
|
+
)}
|
|
59
70
|
</span>
|
|
60
71
|
);
|
|
61
72
|
}
|