@adecore/agents-react 0.70.0 → 0.71.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/chat/logic/fork.js +1 -0
- package/dist/chat/logic/thread-cards.js +1 -0
- package/dist/chat/logic/timeline.js +7 -0
- package/dist/chat/ui/CodeBlock.d.ts +6 -1
- package/dist/chat/ui/CodeBlock.js +39 -23
- package/dist/chat/ui/intelligent-ui/UiReply.js +11 -2
- package/dist/chat/ui/intelligent-ui/key-caps.d.ts +1 -0
- package/dist/chat/ui/intelligent-ui/key-caps.js +45 -0
- package/dist/chat/ui/intelligent-ui/link-action.d.ts +9 -0
- package/dist/chat/ui/intelligent-ui/link-action.js +32 -0
- package/dist/chat/ui/intelligent-ui/node-text.js +1 -1
- package/dist/chat/ui/intelligent-ui/patch-clip.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/patch-clip.js +64 -0
- package/dist/chat/ui/intelligent-ui/registry.js +31 -5
- package/dist/chat/ui/intelligent-ui/render-context.d.ts +13 -0
- package/dist/chat/ui/intelligent-ui/renderers/alternatives.d.ts +6 -0
- package/dist/chat/ui/intelligent-ui/renderers/alternatives.js +296 -0
- package/dist/chat/ui/intelligent-ui/renderers/changes.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/renderers/changes.js +266 -0
- package/dist/chat/ui/intelligent-ui/renderers/chart.js +522 -371
- package/dist/chat/ui/intelligent-ui/renderers/content.d.ts +1 -1
- package/dist/chat/ui/intelligent-ui/renderers/content.js +94 -43
- package/dist/chat/ui/intelligent-ui/renderers/data.js +478 -245
- package/dist/chat/ui/intelligent-ui/renderers/diff.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/renderers/diff.js +427 -0
- package/dist/chat/ui/intelligent-ui/renderers/inputs.d.ts +1 -0
- package/dist/chat/ui/intelligent-ui/renderers/inputs.js +354 -110
- package/dist/chat/ui/intelligent-ui/renderers/keys.d.ts +3 -0
- package/dist/chat/ui/intelligent-ui/renderers/keys.js +60 -0
- package/dist/chat/ui/intelligent-ui/renderers/links.d.ts +13 -2
- package/dist/chat/ui/intelligent-ui/renderers/links.js +65 -85
- package/dist/chat/ui/intelligent-ui/renderers/meter.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/renderers/meter.js +371 -0
- package/dist/chat/ui/intelligent-ui/renderers/quote.d.ts +3 -0
- package/dist/chat/ui/intelligent-ui/renderers/quote.js +123 -0
- package/dist/chat/ui/intelligent-ui/renderers/radio.d.ts +3 -0
- package/dist/chat/ui/intelligent-ui/renderers/radio.js +205 -0
- package/dist/chat/ui/intelligent-ui/renderers/structure.d.ts +2 -0
- package/dist/chat/ui/intelligent-ui/renderers/structure.js +156 -45
- package/dist/chat/ui/intelligent-ui/renderers/text.js +365 -215
- package/dist/chat/ui/intelligent-ui/renderers/tree.d.ts +5 -0
- package/dist/chat/ui/intelligent-ui/renderers/tree.js +284 -0
- package/dist/chat/ui/intelligent-ui/table-data.d.ts +9 -2
- package/dist/chat/ui/intelligent-ui/table-data.js +68 -3
- package/dist/chat/ui/intelligent-ui/tones.d.ts +1 -1
- package/dist/chat/ui/intelligent-ui/tones.js +7 -7
- package/dist/chat/ui/intelligent-ui/use-ui-diffs.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/use-ui-diffs.js +201 -0
- package/dist/chat/ui/rows/MessageRows.d.ts +4 -1
- package/dist/chat/ui/rows/MessageRows.js +92 -1
- package/dist/chat/ui/rows/Rows.js +45 -31
- package/dist/host/host.d.ts +2 -1
- package/dist/host/timeline-row.d.ts +5 -1
- package/dist/locales/en/agent-chat.d.ts +62 -0
- package/dist/locales/en/agent-chat.js +63 -1
- package/dist/locales/nl/agent-chat.d.ts +62 -0
- package/dist/locales/nl/agent-chat.js +63 -1
- package/dist/theme.css +6 -0
- package/package.json +9 -9
- package/src/chat/logic/fork.ts +1 -0
- package/src/chat/logic/thread-cards.ts +1 -0
- package/src/chat/logic/timeline.ts +4 -0
- package/src/chat/ui/CodeBlock.tsx +38 -18
- package/src/chat/ui/intelligent-ui/UiReply.tsx +13 -2
- package/src/chat/ui/intelligent-ui/key-caps.ts +51 -0
- package/src/chat/ui/intelligent-ui/link-action.ts +32 -0
- package/src/chat/ui/intelligent-ui/node-text.ts +1 -0
- package/src/chat/ui/intelligent-ui/patch-clip.ts +83 -0
- package/src/chat/ui/intelligent-ui/registry.ts +31 -4
- package/src/chat/ui/intelligent-ui/render-context.ts +21 -0
- package/src/chat/ui/intelligent-ui/renderers/alternatives.tsx +76 -0
- package/src/chat/ui/intelligent-ui/renderers/changes.tsx +97 -0
- package/src/chat/ui/intelligent-ui/renderers/chart.tsx +122 -46
- package/src/chat/ui/intelligent-ui/renderers/content.tsx +27 -7
- package/src/chat/ui/intelligent-ui/renderers/data.tsx +165 -52
- package/src/chat/ui/intelligent-ui/renderers/diff.tsx +144 -0
- package/src/chat/ui/intelligent-ui/renderers/inputs.tsx +111 -19
- package/src/chat/ui/intelligent-ui/renderers/keys.tsx +26 -0
- package/src/chat/ui/intelligent-ui/renderers/links.tsx +40 -24
- package/src/chat/ui/intelligent-ui/renderers/meter.tsx +105 -0
- package/src/chat/ui/intelligent-ui/renderers/quote.tsx +29 -0
- package/src/chat/ui/intelligent-ui/renderers/radio.tsx +130 -0
- package/src/chat/ui/intelligent-ui/renderers/structure.tsx +54 -7
- package/src/chat/ui/intelligent-ui/renderers/text.tsx +70 -36
- package/src/chat/ui/intelligent-ui/renderers/tree.tsx +85 -0
- package/src/chat/ui/intelligent-ui/table-data.ts +84 -6
- package/src/chat/ui/intelligent-ui/tones.ts +7 -7
- package/src/chat/ui/intelligent-ui/use-ui-diffs.ts +119 -0
- package/src/chat/ui/rows/MessageRows.tsx +23 -0
- package/src/chat/ui/rows/Rows.tsx +3 -0
- package/src/host/host.ts +4 -0
- package/src/host/timeline-row.ts +3 -0
- package/src/locales/en/agent-chat.ts +63 -1
- package/src/locales/nl/agent-chat.ts +63 -1
- package/src/theme.css +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agents-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@adecore/agent-contracts": "0.
|
|
76
|
-
"@adecore/editor": "0.
|
|
77
|
-
"@adecore/editor-react": "0.
|
|
78
|
-
"@adecore/intelligent-ui": "0.
|
|
79
|
-
"@adecore/merge": "0.
|
|
80
|
-
"@adecore/utils": "0.
|
|
75
|
+
"@adecore/agent-contracts": "0.71.0",
|
|
76
|
+
"@adecore/editor": "0.71.0",
|
|
77
|
+
"@adecore/editor-react": "0.71.0",
|
|
78
|
+
"@adecore/intelligent-ui": "0.71.0",
|
|
79
|
+
"@adecore/merge": "0.71.0",
|
|
80
|
+
"@adecore/utils": "0.71.0",
|
|
81
81
|
"@codemirror/commands": "^6.11.1",
|
|
82
82
|
"@codemirror/language": "^6.13.1",
|
|
83
83
|
"@codemirror/state": "^6.7.6",
|
|
@@ -101,14 +101,14 @@
|
|
|
101
101
|
"zustand": "^5.1.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@adecore/ui": "^0.
|
|
104
|
+
"@adecore/ui": "^0.71.0",
|
|
105
105
|
"i18next": "^26.4.2 || ^27.0.0",
|
|
106
106
|
"react": "^19.3.0",
|
|
107
107
|
"react-dom": "^19.3.0",
|
|
108
108
|
"react-i18next": "^17.0.15 || ^18.0.0"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"@adecore/ui": "0.
|
|
111
|
+
"@adecore/ui": "0.71.0",
|
|
112
112
|
"@types/bun": "^1.4.4",
|
|
113
113
|
"@types/react": "^19.3.0",
|
|
114
114
|
"@types/react-dom": "^19.3.0",
|
package/src/chat/logic/fork.ts
CHANGED
|
@@ -443,6 +443,10 @@ function rowsForItems(items: ChatThreadItem[], options: TimelineOptions, childre
|
|
|
443
443
|
...(item.postTokens === undefined ? {} : { postTokens: item.postTokens })
|
|
444
444
|
});
|
|
445
445
|
|
|
446
|
+
break;
|
|
447
|
+
case 'secret':
|
|
448
|
+
rows.push({ kind: 'secret', id: item.id, item });
|
|
449
|
+
|
|
446
450
|
break;
|
|
447
451
|
case 'unknown':
|
|
448
452
|
rows.push({ kind: 'unknown', id: item.id, item, waits: waitsOnTheHost(item) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ButtonGroup, IconButton, ScrollArea } from '@adecore/ui';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import { Check, Copy } from 'lucide-react';
|
|
4
|
-
import { Fragment, memo, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
4
|
+
import { Fragment, memo, useContext, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { useChatHost } from '../../host/host';
|
|
7
7
|
import { IncrementalLines, type CodeToken } from './code-lines';
|
|
@@ -12,15 +12,26 @@ import { WHOLE_FADE_CLASS } from './rehype-fade';
|
|
|
12
12
|
|
|
13
13
|
const COPIED_MS = 1500;
|
|
14
14
|
|
|
15
|
-
/*
|
|
16
|
-
|
|
15
|
+
/* Which lines of a block are numbered and marked. */
|
|
16
|
+
export interface CodeBlockLines {
|
|
17
|
+
/* The number of the first line. With it every line shows its number. */
|
|
18
|
+
start?: number;
|
|
19
|
+
|
|
20
|
+
/* The numbers of the lines to mark, counted from `start`, or from 1 without it. */
|
|
21
|
+
marked?: readonly number[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* A line whose tokens did not change keeps its elements, so a selection in it survives the next delta. A line not highlighted yet is its text. */
|
|
25
|
+
const CodeLine = memo(function CodeLine({ tokens, number, marked }: { tokens: CodeToken[] | string; number?: number; marked?: boolean }) {
|
|
17
26
|
return (
|
|
18
|
-
<span className="line">
|
|
19
|
-
{tokens
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
<span className="line" data-line={number} data-marked={marked ? '' : undefined}>
|
|
28
|
+
{typeof tokens === 'string'
|
|
29
|
+
? tokens
|
|
30
|
+
: tokens.map((token, index) => (
|
|
31
|
+
<span key={index} style={tokenStyle(token)}>
|
|
32
|
+
{token.content}
|
|
33
|
+
</span>
|
|
34
|
+
))}
|
|
24
35
|
</span>
|
|
25
36
|
);
|
|
26
37
|
});
|
|
@@ -29,9 +40,9 @@ const CodeLine = memo(function CodeLine({ tokens }: { tokens: CodeToken[] }) {
|
|
|
29
40
|
* A fenced block, highlighted a line at a time. Until shiki and the grammar are there it holds its
|
|
30
41
|
* place invisibly, so bare code never turns colored. An open fence is tokenized as it grows, and
|
|
31
42
|
* closing it does not draw it again. `view` takes the place of the code, such as what the code draws,
|
|
32
|
-
* and Copy still copies the code.
|
|
43
|
+
* and Copy still copies the code. `lines` numbers and marks lines; a number is never part of a selection.
|
|
33
44
|
*/
|
|
34
|
-
export function CodeBlock({ code, lang, actions, view }: { code: string; lang: string; actions?: ReactNode; view?: ReactNode }) {
|
|
45
|
+
export function CodeBlock({ code, lang, actions, view, lines }: { code: string; lang: string; actions?: ReactNode; view?: ReactNode; lines?: CodeBlockLines }) {
|
|
35
46
|
const { t } = useTranslation('agent-chat');
|
|
36
47
|
const theme = useCodeTheme();
|
|
37
48
|
const { custom } = useChatHost().code;
|
|
@@ -44,8 +55,8 @@ export function CodeBlock({ code, lang, actions, view }: { code: string; lang: s
|
|
|
44
55
|
const tokenizer = highlighter.tokenizer(lang, theme);
|
|
45
56
|
// Only a block that had to wait fades in; one drawn highlighted from its first frame just stands there.
|
|
46
57
|
const [waited] = useState(tokenizer === null);
|
|
47
|
-
const
|
|
48
|
-
const tokens = useMemo(() =>
|
|
58
|
+
const incremental = useMemo(() => (tokenizer ? new IncrementalLines(tokenizer.tokenize) : null), [tokenizer]);
|
|
59
|
+
const tokens = useMemo(() => incremental?.update(code, !streaming) ?? null, [incremental, code, streaming]);
|
|
49
60
|
|
|
50
61
|
useEffect(() => {
|
|
51
62
|
if (copyState !== 'copied') {
|
|
@@ -93,6 +104,10 @@ export function CodeBlock({ code, lang, actions, view }: { code: string; lang: s
|
|
|
93
104
|
}, [highlighter, lang, theme, custom, tokenizer]);
|
|
94
105
|
|
|
95
106
|
const pending = (tokenizer === null || tokens === null) && loaded !== 'failed';
|
|
107
|
+
// Numbered or marked code is drawn a line at a time before it is highlighted too, so a line never changes its box.
|
|
108
|
+
const drawn: readonly (CodeToken[] | string)[] | null = tokens ?? (lines === undefined ? null : code.split('\n'));
|
|
109
|
+
const first = lines?.start ?? 1;
|
|
110
|
+
const digits = lines?.start === undefined || drawn === null ? undefined : String(first + drawn.length - 1).length;
|
|
96
111
|
|
|
97
112
|
return (
|
|
98
113
|
<div className="chat-code" data-copy-state={copyState}>
|
|
@@ -102,16 +117,21 @@ export function CodeBlock({ code, lang, actions, view }: { code: string; lang: s
|
|
|
102
117
|
render={<pre />}
|
|
103
118
|
viewportClassName={clsx(pending && 'invisible', !pending && tokens !== null && waited && WHOLE_FADE_CLASS)}
|
|
104
119
|
aria-hidden={pending || undefined}
|
|
105
|
-
|
|
120
|
+
data-lined={lines === undefined ? undefined : ''}
|
|
121
|
+
style={{ color: tokenizer?.fg, '--chat-code-digits': digits } as CSSProperties}
|
|
106
122
|
>
|
|
107
123
|
<code>
|
|
108
|
-
{
|
|
124
|
+
{drawn === null
|
|
109
125
|
? code
|
|
110
|
-
:
|
|
126
|
+
: drawn.map((line, index) => (
|
|
111
127
|
// Lines only ever grow at the end, so the place of a line is a stable key.
|
|
112
128
|
<Fragment key={index}>
|
|
113
|
-
<CodeLine
|
|
114
|
-
|
|
129
|
+
<CodeLine
|
|
130
|
+
tokens={line}
|
|
131
|
+
number={lines?.start === undefined ? undefined : first + index}
|
|
132
|
+
marked={lines?.marked?.includes(first + index)}
|
|
133
|
+
/>
|
|
134
|
+
{index < drawn.length - 1 && '\n'}
|
|
115
135
|
</Fragment>
|
|
116
136
|
))}
|
|
117
137
|
</code>
|
|
@@ -38,6 +38,7 @@ import { UiSourceCitation } from './renderers/content';
|
|
|
38
38
|
import { uiReplyParts } from './reply-parts';
|
|
39
39
|
import { UiBlockFrame } from './UiBlockFrame';
|
|
40
40
|
import { UiFallbackPart } from './UiFallbackPart';
|
|
41
|
+
import { useUiDiffs } from './use-ui-diffs';
|
|
41
42
|
import { useUiLinks } from './use-ui-links';
|
|
42
43
|
import { useUiQueries, useUiLiveValues } from './use-ui-queries';
|
|
43
44
|
|
|
@@ -68,12 +69,13 @@ const BLOCK = '$block';
|
|
|
68
69
|
* Parents whose text is read as written: code, a short tag, and the labels of controls, whose
|
|
69
70
|
* accessible name and sent text are that same string.
|
|
70
71
|
*/
|
|
71
|
-
const LITERAL_PARENTS = new Set(['CodeBlock', 'Tag', 'Choice', 'Item', 'Switch', 'Slider', 'Segmented', 'Option', 'Button', 'Column']);
|
|
72
|
+
const LITERAL_PARENTS = new Set(['CodeBlock', 'Tag', 'Choice', 'Item', 'Switch', 'Slider', 'Segmented', 'Option', 'Button', 'Column', 'Leaf']);
|
|
72
73
|
|
|
73
74
|
/* Parents that stack their children, where a run of text and inline nodes is one paragraph. */
|
|
74
75
|
const PARAGRAPHS: Readonly<Record<string, string>> = {
|
|
75
76
|
[BLOCK]: 'text-xs text-text',
|
|
76
77
|
Tab: 'text-xs text-text',
|
|
78
|
+
Pane: 'text-xs text-text',
|
|
77
79
|
Section: 'text-xs text-text-muted'
|
|
78
80
|
};
|
|
79
81
|
|
|
@@ -279,7 +281,14 @@ function isInline(node: UiViewNode): boolean {
|
|
|
279
281
|
return true;
|
|
280
282
|
}
|
|
281
283
|
|
|
282
|
-
|
|
284
|
+
if (node.error !== undefined) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// An open Diff is a tile of its own, also while its host has not answered or never will.
|
|
289
|
+
const chip = LINKS.has(node.type) && node.children.length === 0 && !(node.type === 'Diff' && node.props.open === true);
|
|
290
|
+
|
|
291
|
+
return node.type === 'Tag' || node.type === 'Keys' || chip;
|
|
283
292
|
}
|
|
284
293
|
|
|
285
294
|
function isBlank(node: UiViewNode): boolean {
|
|
@@ -525,6 +534,7 @@ function UiBlockBody({
|
|
|
525
534
|
[sources, element]
|
|
526
535
|
);
|
|
527
536
|
|
|
537
|
+
const diff = useUiDiffs(block, state, context, queries.reads, evaluation.nodes);
|
|
528
538
|
const { liveValue, liveNode } = useUiLiveValues(block, evaluation.nodes, queries.currentReadings);
|
|
529
539
|
const sendChoice = host.intelligentUi?.sendChoice;
|
|
530
540
|
const place = useMemo(() => placeReader(frozen, block.revision, unrecorded), [frozen, block.revision, unrecorded]);
|
|
@@ -532,6 +542,7 @@ function UiBlockBody({
|
|
|
532
542
|
const rendering: UiRenderContext = {
|
|
533
543
|
...context,
|
|
534
544
|
...links,
|
|
545
|
+
diff,
|
|
535
546
|
place,
|
|
536
547
|
answer,
|
|
537
548
|
failedChoiceId,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { shortcut, shortcutParts } from '@adecore/ui';
|
|
2
|
+
|
|
3
|
+
/* How an agent may write a key, by its lower case, as the word a shortcut is parsed from. */
|
|
4
|
+
const KEY_WORDS: Readonly<Record<string, string>> = {
|
|
5
|
+
mod: 'Mod',
|
|
6
|
+
ctrl: 'Ctrl',
|
|
7
|
+
control: 'Ctrl',
|
|
8
|
+
alt: 'Alt',
|
|
9
|
+
option: 'Alt',
|
|
10
|
+
opt: 'Alt',
|
|
11
|
+
shift: 'Shift',
|
|
12
|
+
meta: 'Meta',
|
|
13
|
+
cmd: 'Meta',
|
|
14
|
+
command: 'Meta',
|
|
15
|
+
enter: 'Enter',
|
|
16
|
+
return: 'Enter',
|
|
17
|
+
escape: 'Escape',
|
|
18
|
+
esc: 'Escape',
|
|
19
|
+
backspace: 'Backspace',
|
|
20
|
+
delete: 'Delete',
|
|
21
|
+
del: 'Delete',
|
|
22
|
+
tab: 'Tab',
|
|
23
|
+
space: 'Space',
|
|
24
|
+
left: 'ArrowLeft',
|
|
25
|
+
right: 'ArrowRight',
|
|
26
|
+
up: 'ArrowUp',
|
|
27
|
+
down: 'ArrowDown',
|
|
28
|
+
arrowleft: 'ArrowLeft',
|
|
29
|
+
arrowright: 'ArrowRight',
|
|
30
|
+
arrowup: 'ArrowUp',
|
|
31
|
+
arrowdown: 'ArrowDown'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* The caps of a shortcut written as `mod+K`, the way this platform prints them. Keys a shortcut cannot
|
|
36
|
+
* hold, such as two letters or a key it has no name for, stand as written, with only `mod` translated.
|
|
37
|
+
*/
|
|
38
|
+
export function uiKeyCaps(text: string, apple: boolean): string[] {
|
|
39
|
+
const written = text.trim();
|
|
40
|
+
// A trailing `++` is the plus key itself, which a plain split would read as two empty words.
|
|
41
|
+
const words = (written.endsWith('++') ? [...written.slice(0, -2).split('+'), '+'] : written === '+' ? ['+'] : written.split('+'))
|
|
42
|
+
.map((word) => word.trim())
|
|
43
|
+
.filter((word) => word !== '')
|
|
44
|
+
.map((word) => KEY_WORDS[word.toLowerCase()] ?? (/^f\d{1,2}$/i.test(word) ? word.toUpperCase() : word));
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
return shortcutParts(shortcut(words.join('+')), apple);
|
|
48
|
+
} catch {
|
|
49
|
+
return words.map((word) => (word === 'Mod' ? (apple ? '⌘' : 'Ctrl') : word));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TFunction } from 'i18next';
|
|
2
|
+
import { uiReasonText } from './node-text';
|
|
3
|
+
import type { UiLink, UiLinkTarget, UiRenderContext } from './render-context';
|
|
4
|
+
|
|
5
|
+
export const UI_PLAIN_LINK: UiLink = { state: 'plain' };
|
|
6
|
+
|
|
7
|
+
export function uiBaseName(path: string): string {
|
|
8
|
+
const trimmed = path.replace(/\/+$/, '');
|
|
9
|
+
|
|
10
|
+
return trimmed.slice(trimmed.lastIndexOf('/') + 1) || path;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* Why the host leaves a link as text, for its tooltip; null where no host checks links at all. */
|
|
14
|
+
export function uiPlainLinkReason(t: TFunction<'agent-chat'>, link: UiLink, context: UiRenderContext): string | null {
|
|
15
|
+
return uiReasonText(t, link.code, link.reason) ?? (context.link === undefined ? null : t('blocks.outsideProject'));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* A link that is a whole row rather than a chip, such as a changed file: `open` once the host can open the
|
|
20
|
+
* target, otherwise the reason it stays text.
|
|
21
|
+
*/
|
|
22
|
+
export function uiLinkAction(t: TFunction<'agent-chat'>, target: UiLinkTarget, context: UiRenderContext): { open: (() => void) | null; reason: string | null } {
|
|
23
|
+
const link = context.link?.(target) ?? UI_PLAIN_LINK;
|
|
24
|
+
|
|
25
|
+
if (link.state === 'plain') {
|
|
26
|
+
return { open: null, reason: uiPlainLinkReason(t, link, context) };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { openLink } = context;
|
|
30
|
+
|
|
31
|
+
return { open: openLink === undefined ? null : () => openLink(target), reason: null };
|
|
32
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/;
|
|
2
|
+
|
|
3
|
+
interface OpenHunk {
|
|
4
|
+
/* Where its header stands in the kept lines. */
|
|
5
|
+
at: number;
|
|
6
|
+
oldStart: number;
|
|
7
|
+
newStart: number;
|
|
8
|
+
/* The counts its header was written with. */
|
|
9
|
+
oldWritten: number;
|
|
10
|
+
newWritten: number;
|
|
11
|
+
rest: string;
|
|
12
|
+
old: number;
|
|
13
|
+
new: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* A side the cut left without lines names the line before it, as a hunk that never had lines on that side does. */
|
|
17
|
+
function side(start: number, count: number, written: number): string {
|
|
18
|
+
return `${count === 0 && written > 0 ? Math.max(0, start - 1) : start},${count}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* A unified patch cut to its first `limit` lines of change and context. The file header stays, and the hunk
|
|
23
|
+
* the cut falls in gets the counts of what is left of it, so the shorter patch still parses as a whole one.
|
|
24
|
+
*/
|
|
25
|
+
export function uiClipPatch(patch: string, limit: number): { patch: string; clipped: boolean } {
|
|
26
|
+
const lines = patch.split('\n');
|
|
27
|
+
const kept: string[] = [];
|
|
28
|
+
let hunk: OpenHunk | null = null;
|
|
29
|
+
let count = 0;
|
|
30
|
+
|
|
31
|
+
for (const [index, line] of lines.entries()) {
|
|
32
|
+
const header = HUNK.exec(line);
|
|
33
|
+
|
|
34
|
+
if (header !== null) {
|
|
35
|
+
if (count >= limit) {
|
|
36
|
+
return { patch: kept.join('\n'), clipped: true };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
hunk = {
|
|
40
|
+
at: kept.length,
|
|
41
|
+
oldStart: Number(header[1]),
|
|
42
|
+
newStart: Number(header[3]),
|
|
43
|
+
oldWritten: Number(header[2] ?? 1),
|
|
44
|
+
newWritten: Number(header[4] ?? 1),
|
|
45
|
+
rest: header[5] ?? '',
|
|
46
|
+
old: 0,
|
|
47
|
+
new: 0
|
|
48
|
+
};
|
|
49
|
+
kept.push(line);
|
|
50
|
+
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A stripped empty line inside a hunk is context; the one a final newline leaves at the very end is not.
|
|
55
|
+
const body = hunk !== null && (/^[ +-]/.test(line) || (line === '' && index < lines.length - 1));
|
|
56
|
+
|
|
57
|
+
if (hunk === null || (!body && !line.startsWith('\\'))) {
|
|
58
|
+
hunk = null;
|
|
59
|
+
kept.push(line);
|
|
60
|
+
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!body) {
|
|
65
|
+
kept.push(line);
|
|
66
|
+
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (count >= limit) {
|
|
71
|
+
kept[hunk.at] = `@@ -${side(hunk.oldStart, hunk.old, hunk.oldWritten)} +${side(hunk.newStart, hunk.new, hunk.newWritten)} @@${hunk.rest}`;
|
|
72
|
+
|
|
73
|
+
return { patch: kept.join('\n'), clipped: true };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
hunk.old += line.startsWith('+') ? 0 : 1;
|
|
77
|
+
hunk.new += line.startsWith('-') ? 0 : 1;
|
|
78
|
+
count += 1;
|
|
79
|
+
kept.push(line);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { patch, clipped: false };
|
|
83
|
+
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import type { UiRenderers } from './render-context';
|
|
2
|
+
import { AlternativeRenderer, AlternativesRenderer, ConRenderer, ProRenderer } from './renderers/alternatives';
|
|
3
|
+
import { ChangeRenderer, ChangesRenderer } from './renderers/changes';
|
|
2
4
|
import { ChartRenderer } from './renderers/chart';
|
|
3
5
|
import { ChoiceRenderer, ChoicesRenderer } from './renderers/choices';
|
|
4
6
|
import { CodeBlockRenderer, CompareRenderer, GalleryRenderer, ImageRenderer, ModelRenderer, SourceRenderer, SourcesRenderer } from './renderers/content';
|
|
5
7
|
import { EntityListRenderer, EntryRenderer, StatRenderer, StatsRenderer, TableRenderer } from './renderers/data';
|
|
8
|
+
import { DiffRenderer } from './renderers/diff';
|
|
6
9
|
import {
|
|
7
10
|
ButtonRenderer,
|
|
8
11
|
ChecklistRenderer,
|
|
9
12
|
ItemRenderer,
|
|
13
|
+
NumberFieldRenderer,
|
|
10
14
|
SegmentedRenderer,
|
|
11
15
|
SelectRenderer,
|
|
12
16
|
SliderRenderer,
|
|
13
17
|
SwitchRenderer,
|
|
14
18
|
TextFieldRenderer
|
|
15
19
|
} from './renderers/inputs';
|
|
16
|
-
import {
|
|
20
|
+
import { KeysRenderer } from './renderers/keys';
|
|
21
|
+
import { CommitRenderer, FileRenderer, NodeRenderer } from './renderers/links';
|
|
17
22
|
import { MapRenderer } from './renderers/map';
|
|
18
|
-
import {
|
|
23
|
+
import { MeterRenderer, PartsRenderer } from './renderers/meter';
|
|
24
|
+
import { QuoteRenderer } from './renderers/quote';
|
|
25
|
+
import { RadioRenderer } from './renderers/radio';
|
|
26
|
+
import { ColumnsRenderer, PaneRenderer, SectionRenderer, SectionsRenderer, TabRenderer, TabsRenderer } from './renderers/structure';
|
|
19
27
|
import {
|
|
20
28
|
CalloutRenderer,
|
|
21
29
|
EventRenderer,
|
|
@@ -26,12 +34,13 @@ import {
|
|
|
26
34
|
TagRenderer,
|
|
27
35
|
TimelineRenderer
|
|
28
36
|
} from './renderers/text';
|
|
37
|
+
import { BranchRenderer, LeafRenderer, TreeRenderer } from './renderers/tree';
|
|
29
38
|
|
|
30
39
|
/*
|
|
31
40
|
* A renderer for every component of the catalog; a name missing here fails the typecheck. Null draws
|
|
32
41
|
* nothing for the node itself: the runtime resolves Show and Each before rendering, and Column,
|
|
33
|
-
* Option and Place are metadata their parent reads from its node (a table its columns, Segmented
|
|
34
|
-
* Select their options, a map its places).
|
|
42
|
+
* Option, Part and Place are metadata their parent reads from its node (a table its columns, Segmented,
|
|
43
|
+
* Select and Radio their options, a bar its parts, a map its places).
|
|
35
44
|
*/
|
|
36
45
|
export const UI_RENDERERS: UiRenderers = {
|
|
37
46
|
Summary: SummaryRenderer,
|
|
@@ -44,6 +53,9 @@ export const UI_RENDERERS: UiRenderers = {
|
|
|
44
53
|
Event: EventRenderer,
|
|
45
54
|
Stats: StatsRenderer,
|
|
46
55
|
Stat: StatRenderer,
|
|
56
|
+
Meter: MeterRenderer,
|
|
57
|
+
Parts: PartsRenderer,
|
|
58
|
+
Part: null,
|
|
47
59
|
EntityList: EntityListRenderer,
|
|
48
60
|
Entry: EntryRenderer,
|
|
49
61
|
Table: TableRenderer,
|
|
@@ -53,7 +65,18 @@ export const UI_RENDERERS: UiRenderers = {
|
|
|
53
65
|
Tab: TabRenderer,
|
|
54
66
|
Sections: SectionsRenderer,
|
|
55
67
|
Section: SectionRenderer,
|
|
68
|
+
Columns: ColumnsRenderer,
|
|
69
|
+
Pane: PaneRenderer,
|
|
70
|
+
Alternatives: AlternativesRenderer,
|
|
71
|
+
Alternative: AlternativeRenderer,
|
|
72
|
+
Pro: ProRenderer,
|
|
73
|
+
Con: ConRenderer,
|
|
74
|
+
Tree: TreeRenderer,
|
|
75
|
+
Branch: BranchRenderer,
|
|
76
|
+
Leaf: LeafRenderer,
|
|
56
77
|
CodeBlock: CodeBlockRenderer,
|
|
78
|
+
Quote: QuoteRenderer,
|
|
79
|
+
Keys: KeysRenderer,
|
|
57
80
|
Image: ImageRenderer,
|
|
58
81
|
Gallery: GalleryRenderer,
|
|
59
82
|
Compare: CompareRenderer,
|
|
@@ -64,6 +87,8 @@ export const UI_RENDERERS: UiRenderers = {
|
|
|
64
87
|
Source: SourceRenderer,
|
|
65
88
|
File: FileRenderer,
|
|
66
89
|
Diff: DiffRenderer,
|
|
90
|
+
Changes: ChangesRenderer,
|
|
91
|
+
Change: ChangeRenderer,
|
|
67
92
|
Commit: CommitRenderer,
|
|
68
93
|
Node: NodeRenderer,
|
|
69
94
|
Checklist: ChecklistRenderer,
|
|
@@ -72,8 +97,10 @@ export const UI_RENDERERS: UiRenderers = {
|
|
|
72
97
|
Slider: SliderRenderer,
|
|
73
98
|
Segmented: SegmentedRenderer,
|
|
74
99
|
Select: SelectRenderer,
|
|
100
|
+
Radio: RadioRenderer,
|
|
75
101
|
Option: null,
|
|
76
102
|
TextField: TextFieldRenderer,
|
|
103
|
+
NumberField: NumberFieldRenderer,
|
|
77
104
|
Button: ButtonRenderer,
|
|
78
105
|
Show: null,
|
|
79
106
|
Each: null,
|
|
@@ -15,8 +15,27 @@ export interface UiLink {
|
|
|
15
15
|
reason?: string;
|
|
16
16
|
/* The stable code of that reason, which a client words itself where it knows it. */
|
|
17
17
|
code?: string;
|
|
18
|
+
|
|
19
|
+
/* What the target is doing, for a node that is an agent or a chat: `running`, `needsYou` or `done`. Any other value draws nothing. */
|
|
20
|
+
status?: string;
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
/* What the host answered for an open Diff: nothing yet, the change as a unified patch, or why there is none. */
|
|
24
|
+
export type UiDiff =
|
|
25
|
+
| { state: 'reading' }
|
|
26
|
+
| {
|
|
27
|
+
state: 'patch';
|
|
28
|
+
patch: string;
|
|
29
|
+
/* The host cut the patch short. */
|
|
30
|
+
truncated: boolean;
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
state: 'refused';
|
|
34
|
+
reason?: string;
|
|
35
|
+
/* The stable code of that reason, which a client words itself where it knows it. */
|
|
36
|
+
code?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
20
39
|
/* The point a Place stands at, in decimal degrees. */
|
|
21
40
|
export interface UiPlacePoint {
|
|
22
41
|
lat: number;
|
|
@@ -72,6 +91,8 @@ export interface UiRenderContext {
|
|
|
72
91
|
live?: UiLiveStatus | null;
|
|
73
92
|
link?(target: UiLinkTarget): UiLink;
|
|
74
93
|
openLink?(target: UiLinkTarget): void;
|
|
94
|
+
/* The change the host read for the open Diff `nodeId`. Undefined, like the callback itself, for a Diff that stays a chip. */
|
|
95
|
+
diff?(nodeId: string): UiDiff | undefined;
|
|
75
96
|
openUrl?(url: string): void;
|
|
76
97
|
onChoose?(nodeId: string): void;
|
|
77
98
|
/* Why the choices are closed while `onChoose` is absent, such as live data still being read; without it they say they are not available. */
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { UiProps } from '@adecore/intelligent-ui';
|
|
2
|
+
import { Icon, Pill } from '@adecore/ui';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { Minus, Plus, type LucideIcon } from 'lucide-react';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { uiChildrenOf } from '../node-text';
|
|
8
|
+
import type { UiRendererProps } from '../render-context';
|
|
9
|
+
|
|
10
|
+
/* Cards side by side, stacked in a narrow block; three stand in one row only where the block is wide enough for them. */
|
|
11
|
+
export function AlternativesRenderer({ node, children }: UiRendererProps<UiProps<'Alternatives'>>) {
|
|
12
|
+
const { t } = useTranslation('agent-chat');
|
|
13
|
+
const count = uiChildrenOf(node, 'Alternative').length;
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div role="group" aria-label={t('blocks.alternatives.label', { count })} className="@container">
|
|
17
|
+
<div className={clsx('chat-ui-nodes grid gap-2 @min-[420px]:grid-cols-2', count === 3 && '@min-[640px]:grid-cols-3')}>{children}</div>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* It only shows: a person chooses with a Choice under it. The description and the points come in the order
|
|
24
|
+
* they were written, so the first point keeps its distance from the words above it by its place among them.
|
|
25
|
+
*/
|
|
26
|
+
export function AlternativeRenderer({ node, children }: UiRendererProps<UiProps<'Alternative'>>) {
|
|
27
|
+
const { t } = useTranslation('agent-chat');
|
|
28
|
+
const { title, recommended } = node.props;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<section
|
|
32
|
+
aria-label={title}
|
|
33
|
+
className={clsx('flex min-w-0 flex-col gap-2 rounded-xl bg-ui-tile p-3', recommended === true && 'ring-2 ring-accent ring-inset')}
|
|
34
|
+
>
|
|
35
|
+
<div className="flex items-start gap-2">
|
|
36
|
+
<div className="min-w-0 grow text-xs font-semibold wrap-break-word text-text">{title}</div>
|
|
37
|
+
{recommended === true && (
|
|
38
|
+
<Pill shape="tag" size="sm" tone="accent" className="shrink-0">
|
|
39
|
+
{t('blocks.alternatives.recommended')}
|
|
40
|
+
</Pill>
|
|
41
|
+
)}
|
|
42
|
+
</div>
|
|
43
|
+
<div className="text-xs wrap-break-word text-text-muted [&>div]:mt-1 [&>div:first-of-type]:mt-2">{children}</div>
|
|
44
|
+
</section>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function Point({ icon, tone, said, children }: { icon: LucideIcon; tone: string; said: string; children: ReactNode }) {
|
|
49
|
+
return (
|
|
50
|
+
<div className="flex items-start gap-1.5 text-2xs text-text">
|
|
51
|
+
<Icon icon={icon} size={12} className={clsx('mt-1 shrink-0', tone)} />
|
|
52
|
+
<span className="sr-only">{said}</span>
|
|
53
|
+
<span className="min-w-0">{children}</span>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function ProRenderer({ children }: UiRendererProps<UiProps<'Pro'>>) {
|
|
59
|
+
const { t } = useTranslation('agent-chat');
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Point icon={Plus} tone="text-positive" said={t('blocks.alternatives.pro')}>
|
|
63
|
+
{children}
|
|
64
|
+
</Point>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function ConRenderer({ children }: UiRendererProps<UiProps<'Con'>>) {
|
|
69
|
+
const { t } = useTranslation('agent-chat');
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Point icon={Minus} tone="text-status-error" said={t('blocks.alternatives.con')}>
|
|
73
|
+
{children}
|
|
74
|
+
</Point>
|
|
75
|
+
);
|
|
76
|
+
}
|