@adecore/agents-react 0.70.1 → 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/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/host/host.d.ts +2 -1
- package/dist/locales/en/agent-chat.d.ts +56 -0
- package/dist/locales/en/agent-chat.js +57 -1
- package/dist/locales/nl/agent-chat.d.ts +56 -0
- package/dist/locales/nl/agent-chat.js +57 -1
- package/dist/theme.css +6 -0
- package/package.json +9 -9
- 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/host/host.ts +4 -0
- package/src/locales/en/agent-chat.ts +57 -1
- package/src/locales/nl/agent-chat.ts +57 -1
- package/src/theme.css +6 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { UiProps } from '@adecore/intelligent-ui';
|
|
2
|
+
import { FileIcon, MiddleTruncate, Tooltip } from '@adecore/ui';
|
|
3
|
+
import { formatNumber } from '@adecore/ui/format';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { uiLinkAction } from '../link-action';
|
|
8
|
+
import { uiChildrenOf, uiNodeLabel } from '../node-text';
|
|
9
|
+
import type { UiRendererProps } from '../render-context';
|
|
10
|
+
|
|
11
|
+
export function ChangesRenderer({ node, children }: UiRendererProps<UiProps<'Changes'>>) {
|
|
12
|
+
const { t } = useTranslation('agent-chat');
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ul
|
|
16
|
+
aria-label={t('blocks.changes.label', { count: uiChildrenOf(node, 'Change').length })}
|
|
17
|
+
className="chat-ui-nodes chat-ui-flat flex flex-col rounded-xl bg-ui-tile p-1.5"
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</ul>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* The share of added against removed lines, drawn only; the two numbers beside it say it in words. */
|
|
25
|
+
function ChangeBar({ added, removed }: { added: number; removed: number }) {
|
|
26
|
+
const total = added + removed;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<span aria-hidden className="flex h-1.5 w-12 shrink-0 overflow-hidden rounded-full bg-track">
|
|
30
|
+
{total > 0 && (
|
|
31
|
+
<>
|
|
32
|
+
<span className="bg-positive" style={{ width: `${(added / total) * 100}%` }} />
|
|
33
|
+
<span className="bg-status-error" style={{ width: `${(removed / total) * 100}%` }} />
|
|
34
|
+
</>
|
|
35
|
+
)}
|
|
36
|
+
</span>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* One changed file as a row that opens its diff the way a Diff chip does, once the host says it can. Until
|
|
42
|
+
* then, and for a file it cannot open, the row is text with the reason on its path. The note stands under
|
|
43
|
+
* the row, outside the button, since its prose may hold a link of its own.
|
|
44
|
+
*/
|
|
45
|
+
export function ChangeRenderer({ node, children, context }: UiRendererProps<UiProps<'Change'>>) {
|
|
46
|
+
const { t } = useTranslation('agent-chat');
|
|
47
|
+
const { path, added, removed, state } = node.props;
|
|
48
|
+
const { open, reason } = uiLinkAction(t, { type: 'Diff', path }, context);
|
|
49
|
+
const counted = added !== undefined || removed !== undefined;
|
|
50
|
+
|
|
51
|
+
const name: ReactNode =
|
|
52
|
+
open !== null || reason === null ? (
|
|
53
|
+
<MiddleTruncate text={path} className="min-w-0 grow font-mono text-code text-text" />
|
|
54
|
+
) : (
|
|
55
|
+
<Tooltip label={reason}>
|
|
56
|
+
<span tabIndex={0} className="min-w-0 grow truncate rounded-sm font-mono text-code text-text-muted">
|
|
57
|
+
{path}
|
|
58
|
+
</span>
|
|
59
|
+
</Tooltip>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const row = (
|
|
63
|
+
<>
|
|
64
|
+
<FileIcon path={path} size={14} className="shrink-0" />
|
|
65
|
+
{name}
|
|
66
|
+
{state !== undefined && <span className="shrink-0 text-2xs text-text-muted">{t(`blocks.changes.state.${state}`)}</span>}
|
|
67
|
+
{counted && (
|
|
68
|
+
<>
|
|
69
|
+
<span className="min-w-8 shrink-0 text-right text-2xs text-positive tabular-nums">
|
|
70
|
+
<span aria-hidden>+{formatNumber(added ?? 0)}</span>
|
|
71
|
+
<span className="sr-only">{t('blocks.changes.added', { count: added ?? 0 })}</span>
|
|
72
|
+
</span>
|
|
73
|
+
<span className="min-w-8 shrink-0 text-right text-2xs text-status-error tabular-nums">
|
|
74
|
+
<span aria-hidden>-{formatNumber(removed ?? 0)}</span>
|
|
75
|
+
<span className="sr-only">{t('blocks.changes.removed', { count: removed ?? 0 })}</span>
|
|
76
|
+
</span>
|
|
77
|
+
<ChangeBar added={added ?? 0} removed={removed ?? 0} />
|
|
78
|
+
</>
|
|
79
|
+
)}
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const shape = 'flex min-h-8.5 w-full min-w-0 items-center gap-2.5 rounded-lg px-1.5 text-left text-xs';
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<li className="flex min-w-0 flex-col">
|
|
87
|
+
{open === null ? (
|
|
88
|
+
<div className={shape}>{row}</div>
|
|
89
|
+
) : (
|
|
90
|
+
<button type="button" className={clsx(shape, 'hover:bg-text/4')} onClick={open}>
|
|
91
|
+
{row}
|
|
92
|
+
</button>
|
|
93
|
+
)}
|
|
94
|
+
{uiNodeLabel(node) !== '' && <p className="pr-1.5 pb-1.5 pl-7.5 text-2xs wrap-break-word text-text-muted">{children}</p>}
|
|
95
|
+
</li>
|
|
96
|
+
);
|
|
97
|
+
}
|