@adecore/agents-react 0.32.0 → 0.33.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/README.md +1 -1
- package/dist/chat/logic/workflow.d.ts +10 -0
- package/dist/chat/logic/workflow.js +91 -4
- package/dist/chat/ui/MermaidBlock.js +172 -136
- package/dist/chat/ui/mermaid.d.ts +8 -20
- package/dist/chat/ui/mermaid.js +40 -65
- package/dist/chat/ui/rows/WorkRows.d.ts +3 -0
- package/dist/chat/ui/rows/WorkRows.js +1 -1
- package/dist/chat/ui/rows/WorkflowRow.js +628 -168
- package/dist/locales/en/agent-chat.d.ts +8 -0
- package/dist/locales/en/agent-chat.js +9 -1
- package/dist/locales/nl/agent-chat.d.ts +8 -0
- package/dist/locales/nl/agent-chat.js +9 -1
- package/package.json +9 -9
- package/src/chat/logic/workflow.ts +86 -4
- package/src/chat/ui/MermaidBlock.tsx +55 -46
- package/src/chat/ui/mermaid.ts +52 -96
- package/src/chat/ui/rows/WorkRows.tsx +1 -1
- package/src/chat/ui/rows/WorkflowRow.tsx +144 -54
- package/src/locales/en/agent-chat.ts +9 -1
- package/src/locales/nl/agent-chat.ts +9 -1
|
@@ -177,6 +177,14 @@ declare const _default: {
|
|
|
177
177
|
waiting: string;
|
|
178
178
|
stopped: string;
|
|
179
179
|
stalled: string;
|
|
180
|
+
running: string;
|
|
181
|
+
done: string;
|
|
182
|
+
failed: string;
|
|
183
|
+
agents_one: string;
|
|
184
|
+
agents_other: string;
|
|
185
|
+
working: string;
|
|
186
|
+
finished: string;
|
|
187
|
+
failedCount: string;
|
|
180
188
|
};
|
|
181
189
|
};
|
|
182
190
|
work: {
|
|
@@ -176,7 +176,15 @@ export default {
|
|
|
176
176
|
notStarted: 'not started',
|
|
177
177
|
waiting: 'waiting',
|
|
178
178
|
stopped: 'stopped',
|
|
179
|
-
stalled: 'No progress for five minutes. It is still running, and you can stop it.'
|
|
179
|
+
stalled: 'No progress for five minutes. It is still running, and you can stop it.',
|
|
180
|
+
running: 'Workflow running',
|
|
181
|
+
done: 'Workflow done',
|
|
182
|
+
failed: 'Workflow failed',
|
|
183
|
+
agents_one: '{{count}} agent',
|
|
184
|
+
agents_other: '{{count}} agents',
|
|
185
|
+
working: '{{count}} working',
|
|
186
|
+
finished: '{{count}} done',
|
|
187
|
+
failedCount: '{{count}} failed'
|
|
180
188
|
}
|
|
181
189
|
},
|
|
182
190
|
work: {
|
|
@@ -177,6 +177,14 @@ declare const _default: {
|
|
|
177
177
|
waiting: string;
|
|
178
178
|
stopped: string;
|
|
179
179
|
stalled: string;
|
|
180
|
+
running: string;
|
|
181
|
+
done: string;
|
|
182
|
+
failed: string;
|
|
183
|
+
agents_one: string;
|
|
184
|
+
agents_other: string;
|
|
185
|
+
working: string;
|
|
186
|
+
finished: string;
|
|
187
|
+
failedCount: string;
|
|
180
188
|
};
|
|
181
189
|
};
|
|
182
190
|
work: {
|
|
@@ -176,7 +176,15 @@ export default {
|
|
|
176
176
|
notStarted: 'nog niet begonnen',
|
|
177
177
|
waiting: 'wacht',
|
|
178
178
|
stopped: 'gestopt',
|
|
179
|
-
stalled: 'Vijf minuten geen voortgang. Hij loopt nog, en je kunt hem stoppen.'
|
|
179
|
+
stalled: 'Vijf minuten geen voortgang. Hij loopt nog, en je kunt hem stoppen.',
|
|
180
|
+
running: 'Workflow loopt',
|
|
181
|
+
done: 'Workflow klaar',
|
|
182
|
+
failed: 'Workflow mislukt',
|
|
183
|
+
agents_one: '{{count}} agent',
|
|
184
|
+
agents_other: '{{count}} agents',
|
|
185
|
+
working: '{{count}} bezig',
|
|
186
|
+
finished: '{{count}} klaar',
|
|
187
|
+
failedCount: '{{count}} mislukt'
|
|
180
188
|
}
|
|
181
189
|
},
|
|
182
190
|
work: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agents-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@adecore/agent-contracts": "0.
|
|
71
|
-
"@adecore/editor": "0.
|
|
72
|
-
"@adecore/editor-react": "0.
|
|
73
|
-
"@adecore/intelligent-ui": "0.
|
|
74
|
-
"@adecore/merge": "0.
|
|
70
|
+
"@adecore/agent-contracts": "0.33.0",
|
|
71
|
+
"@adecore/editor": "0.33.0",
|
|
72
|
+
"@adecore/editor-react": "0.33.0",
|
|
73
|
+
"@adecore/intelligent-ui": "0.33.0",
|
|
74
|
+
"@adecore/merge": "0.33.0",
|
|
75
75
|
"@codemirror/commands": "^6.11.1",
|
|
76
76
|
"@codemirror/language": "^6.12.4",
|
|
77
77
|
"@codemirror/state": "^6.7.6",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"clsx": "^2.1.1",
|
|
85
85
|
"lucide-react": "^1.47.0",
|
|
86
86
|
"maplibre-gl": "^6.14.0",
|
|
87
|
-
"
|
|
87
|
+
"pele": "1.8.0",
|
|
88
88
|
"react-markdown": "^10.1.0",
|
|
89
89
|
"remark-breaks": "^4.0.0",
|
|
90
90
|
"remark-gfm": "^4.0.1",
|
|
@@ -94,14 +94,14 @@
|
|
|
94
94
|
"zustand": "^5.0.15"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@adecore/ui": "^0.
|
|
97
|
+
"@adecore/ui": "^0.33.0",
|
|
98
98
|
"i18next": "^26.4.2",
|
|
99
99
|
"react": "^19.3.0",
|
|
100
100
|
"react-dom": "^19.3.0",
|
|
101
101
|
"react-i18next": "^17.0.15"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"@adecore/ui": "0.
|
|
104
|
+
"@adecore/ui": "0.33.0",
|
|
105
105
|
"@types/bun": "^1.4.2",
|
|
106
106
|
"@types/react": "^19.3.0",
|
|
107
107
|
"@types/react-dom": "^19.3.0",
|
|
@@ -49,7 +49,6 @@ export function workflowPhases(workflow: ChatWorkflow, workflowRunning: boolean)
|
|
|
49
49
|
|
|
50
50
|
/* What the line of an agent that is not at work says about its time; one at work counts on by itself. */
|
|
51
51
|
export function workflowAgentTime(view: WorkflowAgentView): string | null {
|
|
52
|
-
const duration = view.agent.durationMs === null ? null : formatElapsedShort(view.agent.durationMs);
|
|
53
52
|
switch (view.state) {
|
|
54
53
|
case 'running':
|
|
55
54
|
return null;
|
|
@@ -59,8 +58,91 @@ export function workflowAgentTime(view: WorkflowAgentView): string | null {
|
|
|
59
58
|
return i18next.t('agent-chat:rows.workflow.stopped');
|
|
60
59
|
case 'done':
|
|
61
60
|
case 'failed':
|
|
62
|
-
return
|
|
63
|
-
? i18next.t(`agent-chat:common.status.${view.state}`)
|
|
64
|
-
: i18next.t(`agent-chat:rows.subagent.${view.state}In`, { duration });
|
|
61
|
+
return view.agent.durationMs === null ? null : formatElapsedShort(view.agent.durationMs);
|
|
65
62
|
}
|
|
66
63
|
}
|
|
64
|
+
|
|
65
|
+
export interface WorkflowAgentPreview {
|
|
66
|
+
/* The tool an agent at work last called, drawn apart from what it was called on. */
|
|
67
|
+
tool: string | null;
|
|
68
|
+
text: string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* The CLI's previews start with a markdown heading as often as not, which says nothing on one line. */
|
|
72
|
+
function firstLine(text: string | undefined): string | null {
|
|
73
|
+
const line = text
|
|
74
|
+
?.split('\n')
|
|
75
|
+
.map((part) => part.replace(/^#+\s*/, '').trim())
|
|
76
|
+
.find((part) => part !== '');
|
|
77
|
+
return line === undefined ? null : line;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* The second line of an agent: what it does while at work, what it answered once it stopped, what it was asked before. */
|
|
81
|
+
export function workflowAgentPreview(view: WorkflowAgentView): WorkflowAgentPreview {
|
|
82
|
+
const { agent } = view;
|
|
83
|
+
switch (view.state) {
|
|
84
|
+
case 'running':
|
|
85
|
+
return agent.lastTool === null
|
|
86
|
+
? { tool: null, text: firstLine(agent.promptPreview) }
|
|
87
|
+
: { tool: agent.lastTool, text: firstLine(agent.lastToolSummary) };
|
|
88
|
+
case 'waiting':
|
|
89
|
+
return { tool: null, text: firstLine(agent.promptPreview) };
|
|
90
|
+
case 'failed':
|
|
91
|
+
return { tool: null, text: firstLine(agent.error) ?? firstLine(agent.resultPreview) };
|
|
92
|
+
case 'done':
|
|
93
|
+
case 'stopped':
|
|
94
|
+
return { tool: null, text: firstLine(agent.resultPreview) ?? firstLine(agent.promptPreview) };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type WorkflowCounts = Record<WorkflowAgentState, number> & { total: number };
|
|
99
|
+
|
|
100
|
+
export function workflowCounts(phases: WorkflowPhaseView[]): WorkflowCounts {
|
|
101
|
+
const counts: WorkflowCounts = { total: 0, running: 0, waiting: 0, stopped: 0, done: 0, failed: 0 };
|
|
102
|
+
for (const view of phases.flatMap((phase) => phase.agents)) {
|
|
103
|
+
counts.total += 1;
|
|
104
|
+
counts[view.state] += 1;
|
|
105
|
+
}
|
|
106
|
+
return counts;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const META_START = /export\s+const\s+meta\s*=\s*\{/;
|
|
110
|
+
const DESCRIPTION = /\bdescription\s*:\s*(['"`])((?:\\.|(?!\1)[^\\])*)\1/;
|
|
111
|
+
|
|
112
|
+
/* The literal from its opening brace to the one that closes it, skipping braces inside strings. */
|
|
113
|
+
function metaLiteral(script: string): string | null {
|
|
114
|
+
const start = META_START.exec(script);
|
|
115
|
+
if (start === null) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const from = start.index + start[0].length - 1;
|
|
119
|
+
let depth = 0;
|
|
120
|
+
let quote: string | null = null;
|
|
121
|
+
for (let i = from; i < script.length; i++) {
|
|
122
|
+
const char = script[i]!;
|
|
123
|
+
if (quote !== null) {
|
|
124
|
+
if (char === '\\') {
|
|
125
|
+
i++;
|
|
126
|
+
} else if (char === quote) {
|
|
127
|
+
quote = null;
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
132
|
+
quote = char;
|
|
133
|
+
} else if (char === '{') {
|
|
134
|
+
depth++;
|
|
135
|
+
} else if (char === '}' && --depth === 0) {
|
|
136
|
+
return script.slice(from, i + 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* The script's `meta` is a pure literal by the CLI's own rule, so its description reads without running anything. A saved workflow called by name has no script here. */
|
|
143
|
+
export function workflowDescription(input: unknown): string | null {
|
|
144
|
+
const script = typeof input === 'object' && input !== null && 'script' in input ? input.script : undefined;
|
|
145
|
+
const meta = typeof script === 'string' ? metaLiteral(script) : null;
|
|
146
|
+
const found = meta === null ? undefined : DESCRIPTION.exec(meta)?.[2]?.replace(/\\(.)/g, '$1').trim();
|
|
147
|
+
return found ? found : null;
|
|
148
|
+
}
|
|
@@ -4,18 +4,21 @@ import { Code, Workflow } from 'lucide-react';
|
|
|
4
4
|
import { IconButton } from '@adecore/ui';
|
|
5
5
|
import { CodeBlock } from './CodeBlock';
|
|
6
6
|
import { CodeStreamingContext } from './code-streaming';
|
|
7
|
-
import {
|
|
7
|
+
import { DIAGRAM_TOKENS, GROUND_TOKEN, renderOptions, svgDataUrl, themedSvg, type DiagramFont } from './mermaid';
|
|
8
8
|
import { watchTheme } from './theme-watch';
|
|
9
9
|
import { useHostCodeMode } from '../../host-hooks';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface LaidOut {
|
|
12
|
+
svg: string;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
let queue: Promise<unknown> = Promise.resolve();
|
|
17
|
+
type Drawing = { state: 'drawing' } | { state: 'drawn'; image: LaidOut } | { state: 'failed' };
|
|
15
18
|
|
|
16
19
|
let probeCanvas: HTMLCanvasElement | null = null;
|
|
17
20
|
|
|
18
|
-
/* A token as an opaque `#rrggbb` over `ground`,
|
|
21
|
+
/* A token as an opaque `#rrggbb` over `ground`, so a border with an alpha mixes with the ground and not with what is under the image. */
|
|
19
22
|
function resolveColor(element: HTMLElement, token: string, ground: string): string {
|
|
20
23
|
probeCanvas ??= document.createElement('canvas');
|
|
21
24
|
probeCanvas.width = 1;
|
|
@@ -33,34 +36,41 @@ function resolveColor(element: HTMLElement, token: string, ground: string): stri
|
|
|
33
36
|
return `#${[red, green, blue].map((channel) => channel!.toString(16).padStart(2, '0')).join('')}`;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
function themeColors(element: HTMLElement): MermaidColors {
|
|
37
|
-
const ground = resolveColor(element, MERMAID_TOKENS.ground, '#808080');
|
|
38
|
-
const entries = Object.entries(MERMAID_TOKENS).map(([name, token]) => [name, name === 'ground' ? ground : resolveColor(element, token, ground)]);
|
|
39
|
-
return Object.fromEntries(entries) as unknown as MermaidColors;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
39
|
/* What a diagram reads of the theme where it stands. */
|
|
43
40
|
interface DiagramLook {
|
|
44
|
-
colors:
|
|
45
|
-
font:
|
|
41
|
+
colors: Record<string, string>;
|
|
42
|
+
font: DiagramFont;
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
function diagramLook(element: HTMLElement): DiagramLook {
|
|
49
46
|
const style = getComputedStyle(element);
|
|
50
|
-
|
|
47
|
+
const ground = resolveColor(element, GROUND_TOKEN, '#808080');
|
|
48
|
+
const colors = Object.fromEntries(
|
|
49
|
+
Object.entries(DIAGRAM_TOKENS).map(([name, token]) => [name, token === GROUND_TOKEN ? ground : resolveColor(element, token, ground)])
|
|
50
|
+
);
|
|
51
|
+
const font = {
|
|
52
|
+
family: style.fontFamily,
|
|
53
|
+
mono: style.getPropertyValue('--font-mono').trim() || 'monospace',
|
|
54
|
+
size: Number.parseFloat(style.fontSize) || 14
|
|
55
|
+
};
|
|
56
|
+
return { colors, font };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Keeps the look on screen when nothing of it changed, so a change of the root that leaves every color alone draws nothing again. */
|
|
60
|
+
function keepingSame(next: DiagramLook) {
|
|
61
|
+
return (current: DiagramLook | null) => (current !== null && JSON.stringify(current) === JSON.stringify(next) ? current : next);
|
|
51
62
|
}
|
|
52
63
|
|
|
53
|
-
async function
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return sizedSvg(svg);
|
|
64
|
+
async function layOut(id: string, source: string, font: DiagramFont): Promise<LaidOut> {
|
|
65
|
+
const { renderAsync } = await import('pele/lazy');
|
|
66
|
+
const { svg, width, height } = await renderAsync(source, renderOptions(font, id));
|
|
67
|
+
return { svg, width: Math.ceil(width), height: Math.ceil(height) };
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/*
|
|
61
|
-
* A ```mermaid fence, drawn as the diagram once the fence is closed.
|
|
62
|
-
*
|
|
63
|
-
* draw, it is the code block it would otherwise be.
|
|
71
|
+
* A ```mermaid fence, drawn as the diagram once the fence is closed. Pele loads on the first diagram of the
|
|
72
|
+
* page, and then only what a diagram of that kind needs. While the fence grows, and when the text is no diagram
|
|
73
|
+
* Pele can draw, it is the code block it would otherwise be.
|
|
64
74
|
*/
|
|
65
75
|
export function MermaidBlock({ code }: { code: string }) {
|
|
66
76
|
const { t } = useTranslation('agent-chat');
|
|
@@ -70,9 +80,14 @@ export function MermaidBlock({ code }: { code: string }) {
|
|
|
70
80
|
const frame = useRef<HTMLDivElement>(null);
|
|
71
81
|
const [source, setSource] = useState(false);
|
|
72
82
|
const [drawing, setDrawing] = useState<Drawing>({ state: 'drawing' });
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
const [look, setLook] = useState<DiagramLook | null>(null);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const element = frame.current;
|
|
87
|
+
if (element !== null) {
|
|
88
|
+
setLook(keepingSame(diagramLook(element)));
|
|
89
|
+
}
|
|
90
|
+
}, [dark]);
|
|
76
91
|
|
|
77
92
|
// An app may change its colors without turning light or dark, which only the root of the page tells.
|
|
78
93
|
useEffect(() => {
|
|
@@ -80,34 +95,28 @@ export function MermaidBlock({ code }: { code: string }) {
|
|
|
80
95
|
if (element === null) {
|
|
81
96
|
return;
|
|
82
97
|
}
|
|
83
|
-
return watchTheme(element.ownerDocument, () =>
|
|
84
|
-
if (drawnLook.current !== null && JSON.stringify(diagramLook(element)) !== drawnLook.current) {
|
|
85
|
-
setThemeRevision((revision) => revision + 1);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
98
|
+
return watchTheme(element.ownerDocument, () => setLook(keepingSame(diagramLook(element))));
|
|
88
99
|
}, []);
|
|
89
100
|
|
|
101
|
+
const fontFamily = look?.font.family;
|
|
102
|
+
const fontMono = look?.font.mono;
|
|
103
|
+
const fontSize = look?.font.size;
|
|
90
104
|
useEffect(() => {
|
|
91
|
-
|
|
92
|
-
if (streaming || element === null) {
|
|
105
|
+
if (streaming || fontFamily === undefined || fontMono === undefined || fontSize === undefined) {
|
|
93
106
|
return;
|
|
94
107
|
}
|
|
95
108
|
let cancelled = false;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
setDrawing((current) => (current.state === 'drawn' ? current : { state: 'drawing' }));
|
|
100
|
-
const drawn = queue.then(() => (cancelled ? null : drawDiagram(id, code, look, dark)));
|
|
101
|
-
queue = drawn.catch(() => undefined);
|
|
102
|
-
drawn.then(
|
|
103
|
-
(image) => !cancelled && setDrawing(image === null ? { state: 'failed' } : { state: 'drawn', image }),
|
|
109
|
+
// A diagram already drawn stays until the next one is there, so it does not blink.
|
|
110
|
+
layOut(id, code, { family: fontFamily, mono: fontMono, size: fontSize }).then(
|
|
111
|
+
(image) => !cancelled && setDrawing({ state: 'drawn', image }),
|
|
104
112
|
() => !cancelled && setDrawing({ state: 'failed' })
|
|
105
113
|
);
|
|
106
114
|
return () => {
|
|
107
115
|
cancelled = true;
|
|
108
116
|
};
|
|
109
|
-
}, [code,
|
|
117
|
+
}, [code, fontFamily, fontMono, fontSize, id, streaming]);
|
|
110
118
|
|
|
119
|
+
const image = drawing.state === 'drawn' && look !== null ? { ...drawing.image, svg: themedSvg(drawing.image.svg, look.colors) } : null;
|
|
111
120
|
const showsDiagram = !streaming && !source && drawing.state !== 'failed';
|
|
112
121
|
const toggle =
|
|
113
122
|
streaming || drawing.state === 'failed' ? undefined : (
|
|
@@ -127,12 +136,12 @@ export function MermaidBlock({ code }: { code: string }) {
|
|
|
127
136
|
actions={toggle}
|
|
128
137
|
view={
|
|
129
138
|
showsDiagram ? (
|
|
130
|
-
<div className="overflow-x-auto p-3" aria-busy={
|
|
131
|
-
{
|
|
139
|
+
<div className="overflow-x-auto p-3" aria-busy={image === null || undefined}>
|
|
140
|
+
{image !== null && (
|
|
132
141
|
<img
|
|
133
|
-
src={svgDataUrl(
|
|
134
|
-
width={
|
|
135
|
-
height={
|
|
142
|
+
src={svgDataUrl(image.svg)}
|
|
143
|
+
width={image.width}
|
|
144
|
+
height={image.height}
|
|
136
145
|
alt={t('code.mermaid.diagram')}
|
|
137
146
|
className="m-0 max-w-none"
|
|
138
147
|
draggable={false}
|
package/src/chat/ui/mermaid.ts
CHANGED
|
@@ -1,116 +1,72 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RenderOptions } from 'pele';
|
|
2
2
|
|
|
3
|
-
/* The
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
text: '--text',
|
|
21
|
-
line: '--text-muted',
|
|
22
|
-
cluster: '--surface',
|
|
23
|
-
clusterBorder: '--border',
|
|
24
|
-
note: '--accent-soft'
|
|
3
|
+
/* The variable of Pele each token of the theme fills. Borders carry an alpha, so every color is resolved over the ground. */
|
|
4
|
+
export const DIAGRAM_TOKENS: Readonly<Record<string, string>> = {
|
|
5
|
+
'--pele-bg': '--chat-code-bg',
|
|
6
|
+
'--pele-fg': '--text',
|
|
7
|
+
'--pele-muted': '--text-muted',
|
|
8
|
+
'--pele-line': '--text-muted',
|
|
9
|
+
'--pele-surface': '--surface-raised',
|
|
10
|
+
'--pele-surface-alt': '--surface',
|
|
11
|
+
'--pele-border': '--border-strong',
|
|
12
|
+
'--pele-accent': '--accent',
|
|
13
|
+
'--pele-critical': '--status-error',
|
|
14
|
+
'--pele-series-1': '--accent',
|
|
15
|
+
'--pele-series-2': '--chart-2',
|
|
16
|
+
'--pele-series-3': '--chart-3',
|
|
17
|
+
'--pele-series-4': '--chart-4',
|
|
18
|
+
'--pele-series-5': '--chart-5',
|
|
19
|
+
'--pele-series-6': '--chart-6'
|
|
25
20
|
};
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
'suppressErrorRendering',
|
|
35
|
-
'htmlLabels',
|
|
36
|
-
'theme',
|
|
37
|
-
'themeVariables',
|
|
38
|
-
'themeCSS',
|
|
39
|
-
'darkMode',
|
|
40
|
-
'fontFamily'
|
|
41
|
-
];
|
|
22
|
+
export const GROUND_TOKEN = DIAGRAM_TOKENS['--pele-bg']!;
|
|
23
|
+
|
|
24
|
+
export interface DiagramFont {
|
|
25
|
+
family: string;
|
|
26
|
+
mono: string;
|
|
27
|
+
size: number;
|
|
28
|
+
}
|
|
42
29
|
|
|
43
30
|
/*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
31
|
+
* At the size it was laid out at, since an image has no container to shrink to. No links and no images, and no
|
|
32
|
+
* math or icon resolver, which are the only markup Pele inserts unfiltered. What comes out is drawn as an image as
|
|
33
|
+
* well, which never runs script and loads nothing, whatever the text of the diagram says.
|
|
46
34
|
*/
|
|
47
|
-
export function
|
|
35
|
+
export function renderOptions(font: DiagramFont, idPrefix: string): RenderOptions {
|
|
48
36
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
htmlLabels: false,
|
|
52
|
-
suppressErrorRendering: true,
|
|
53
|
-
secure: SECURE_KEYS,
|
|
54
|
-
theme: 'base',
|
|
55
|
-
darkMode: dark,
|
|
37
|
+
responsive: false,
|
|
38
|
+
idPrefix,
|
|
56
39
|
fontFamily: font.family,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
background: colors.ground,
|
|
62
|
-
primaryColor: colors.node,
|
|
63
|
-
primaryTextColor: colors.text,
|
|
64
|
-
primaryBorderColor: colors.nodeBorder,
|
|
65
|
-
secondaryColor: colors.note,
|
|
66
|
-
tertiaryColor: colors.cluster,
|
|
67
|
-
mainBkg: colors.node,
|
|
68
|
-
nodeBorder: colors.nodeBorder,
|
|
69
|
-
textColor: colors.text,
|
|
70
|
-
titleColor: colors.text,
|
|
71
|
-
lineColor: colors.line,
|
|
72
|
-
clusterBkg: colors.cluster,
|
|
73
|
-
clusterBorder: colors.clusterBorder,
|
|
74
|
-
edgeLabelBackground: colors.ground,
|
|
75
|
-
noteBkgColor: colors.note,
|
|
76
|
-
noteTextColor: colors.text,
|
|
77
|
-
noteBorderColor: colors.nodeBorder
|
|
78
|
-
}
|
|
40
|
+
fontFamilyMono: font.mono,
|
|
41
|
+
fontSize: font.size,
|
|
42
|
+
links: false,
|
|
43
|
+
images: false
|
|
79
44
|
};
|
|
80
45
|
}
|
|
81
46
|
|
|
82
|
-
export interface SizedSvg {
|
|
83
|
-
svg: string;
|
|
84
|
-
width: number;
|
|
85
|
-
height: number;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
47
|
const ROOT = /<svg\b[^>]*>/;
|
|
89
|
-
const
|
|
90
|
-
|
|
48
|
+
const STYLE = /\sstyle="/;
|
|
49
|
+
|
|
50
|
+
function attributeText(value: string): string {
|
|
51
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
52
|
+
}
|
|
91
53
|
|
|
92
54
|
/*
|
|
93
|
-
* The
|
|
94
|
-
*
|
|
95
|
-
* without one.
|
|
55
|
+
* The drawing with the colors set on its root. An image does not see the variables of the page, so they are
|
|
56
|
+
* written in, and a change of the theme only writes them again.
|
|
96
57
|
*/
|
|
97
|
-
export function
|
|
58
|
+
export function themedSvg(svg: string, colors: Readonly<Record<string, string>>): string {
|
|
98
59
|
const root = ROOT.exec(svg);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
const [, , boxWidth, boxHeight] = viewBox[1]!
|
|
104
|
-
.trim()
|
|
105
|
-
.split(/[\s,]+/)
|
|
106
|
-
.map(Number);
|
|
107
|
-
if (!Number.isFinite(boxWidth) || !Number.isFinite(boxHeight) || boxWidth! <= 0 || boxHeight! <= 0) {
|
|
108
|
-
return null;
|
|
60
|
+
if (root === null) {
|
|
61
|
+
return svg;
|
|
109
62
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
63
|
+
const variables = attributeText(
|
|
64
|
+
Object.entries(colors)
|
|
65
|
+
.map(([name, value]) => `${name}:${value};`)
|
|
66
|
+
.join('')
|
|
67
|
+
);
|
|
68
|
+
const tag = STYLE.test(root[0]) ? root[0].replace(STYLE, (style) => style + variables) : root[0].replace(/^<svg\b/, `<svg style="${variables}"`);
|
|
69
|
+
return svg.slice(0, root.index) + tag + svg.slice(root.index + root[0].length);
|
|
114
70
|
}
|
|
115
71
|
|
|
116
72
|
export function svgDataUrl(svg: string): string {
|
|
@@ -283,7 +283,7 @@ function ToolOutput({ tool }: { tool: ChatToolItem }) {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
/* An opened call without a card: what it was asked in the foreground, what it answered muted below. */
|
|
286
|
-
function ToolBody({ tool }: { tool: ChatToolItem }) {
|
|
286
|
+
export function ToolBody({ tool }: { tool: ChatToolItem }) {
|
|
287
287
|
const patches = unifiedChanges(tool);
|
|
288
288
|
const changes = patches.length > 0 ? [] : fileChanges(tool.name, tool.input);
|
|
289
289
|
if (patches.length + changes.length > 0) {
|