@oh-my-pi/pi-tui 18.11.0 → 18.11.2
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/CHANGELOG.md +52 -146
- package/dist/types/apps/git/git-tui.d.ts +16 -2
- package/dist/types/autocomplete.d.ts +2 -0
- package/dist/types/charts/chart-svg.d.ts +7 -13
- package/dist/types/chat/table-chart.d.ts +11 -15
- package/dist/types/chrome/transcript-container.d.ts +2 -0
- package/dist/types/components/image.d.ts +2 -0
- package/dist/types/components/markdown.d.ts +37 -0
- package/dist/types/native/blobs.d.ts +11 -11
- package/dist/types/overlays/agent-hub-projection.d.ts +10 -5
- package/dist/types/overlays/job-tree.d.ts +50 -0
- package/dist/types/overlays/jobs-panel.d.ts +24 -11
- package/dist/types/prompt/composer.d.ts +20 -0
- package/dist/types/prompt/custom-editor.d.ts +2 -0
- package/dist/types/prompt/image-references.d.ts +22 -0
- package/dist/types/prompt/macos-spelling.d.ts +2 -1
- package/dist/types/prompt/prose-gate.d.ts +3 -0
- package/dist/types/prompt/queued-messages.d.ts +1 -1
- package/dist/types/prompt/typing-word.d.ts +25 -0
- package/dist/types/render/hyperlink.d.ts +2 -0
- package/dist/types/render/utils.d.ts +1 -1
- package/dist/types/status-line/context-usage.d.ts +3 -0
- package/dist/types/status-line/host.d.ts +6 -4
- package/dist/types/status-line/startup.d.ts +6 -6
- package/dist/types/stdin-buffer.d.ts +7 -0
- package/dist/types/terminal.d.ts +8 -4
- package/dist/types/tools/eval.d.ts +5 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- package/dist/types/tools/read.d.ts +5 -4
- package/dist/types/tui.d.ts +10 -0
- package/package.json +9 -9
- package/src/apps/git/git-tui.ts +27 -10
- package/src/apps/git/sidebar.ts +5 -1
- package/src/autocomplete.ts +21 -19
- package/src/bracketed-paste.ts +9 -2
- package/src/charts/chart-svg.ts +19 -22
- package/src/chat/assistant-message.ts +37 -12
- package/src/chat/bash-execution.ts +7 -2
- package/src/chat/image-loading.ts +4 -6
- package/src/chat/read-tool-group.ts +1 -0
- package/src/chat/table-chart.ts +24 -57
- package/src/chat/tool-execution.ts +11 -4
- package/src/chat/user-message.ts +22 -15
- package/src/chrome/transcript-container.ts +10 -0
- package/src/components/editor.ts +12 -12
- package/src/components/image.ts +23 -6
- package/src/components/markdown.ts +375 -6
- package/src/components/settings-list.ts +2 -4
- package/src/native/blobs.ts +22 -6
- package/src/native/reconcile.ts +19 -15
- package/src/overlays/agent-hub-projection.ts +63 -12
- package/src/overlays/btw-history-panel.ts +30 -23
- package/src/overlays/extensions/extension-list.ts +4 -6
- package/src/overlays/job-tree.ts +177 -0
- package/src/overlays/jobs-panel.ts +107 -49
- package/src/overlays/settings-selector.ts +3 -0
- package/src/prompt/composer.ts +180 -23
- package/src/prompt/custom-editor.ts +19 -1
- package/src/prompt/image-references.ts +79 -2
- package/src/prompt/macos-spelling.ts +28 -5
- package/src/prompt/prose-gate.ts +3 -0
- package/src/prompt/queued-messages.ts +9 -2
- package/src/prompt/typing-word.ts +59 -0
- package/src/render/code-cell.ts +8 -1
- package/src/render/hyperlink.ts +5 -0
- package/src/render/utils.ts +1 -1
- package/src/render/width-aware-text.ts +6 -5
- package/src/status-line/component.ts +22 -10
- package/src/status-line/context-usage.ts +22 -16
- package/src/status-line/footer.ts +18 -35
- package/src/status-line/host.ts +6 -1
- package/src/status-line/startup.ts +6 -6
- package/src/stdin-buffer.ts +11 -1
- package/src/terminal.ts +136 -42
- package/src/tools/ast-grep.ts +2 -2
- package/src/tools/edit.ts +16 -1
- package/src/tools/eval.ts +51 -11
- package/src/tools/grouped-file-output.ts +6 -1
- package/src/tools/read.ts +6 -5
- package/src/tools/write.ts +1 -1
- package/src/tui.ts +61 -30
- package/src/utils.ts +5 -3
package/src/charts/chart-svg.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Draws a {@link ChartSpec} as a standalone SVG document colored only with
|
|
3
3
|
* figure tokens — `var(--fg)`, `var(--muted)`, `var(--border)`,
|
|
4
4
|
* `var(--accent)`, `var(--surface)`, `var(--c1)`…`var(--c6)` — on a
|
|
5
|
-
* transparent background — the token vocabulary of assistant ```svg figures
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* transparent background — the token vocabulary of assistant ```svg figures:
|
|
6
|
+
* the host resolves them against the live theme (`prepareSvg`) for the
|
|
7
|
+
* rasterized terminal image, and a TSP terminal draws the chart as an ```svg
|
|
8
|
+
* figure in the palette it shows. The root carries {@link chartAlt} as its
|
|
9
|
+
* `aria-label`.
|
|
8
10
|
*
|
|
9
11
|
* Styled after Apple's charts and Tern's UI: a UI sans (Geist where Tern
|
|
10
12
|
* provides it), muted labels, hairline gridlines that recede behind the
|
|
@@ -236,15 +238,8 @@ interface Tier {
|
|
|
236
238
|
readonly high: number;
|
|
237
239
|
}
|
|
238
240
|
|
|
239
|
-
/**
|
|
240
|
-
export
|
|
241
|
-
readonly svg: string;
|
|
242
|
-
readonly width: number;
|
|
243
|
-
readonly height: number;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/** The SVG document for `spec`. */
|
|
247
|
-
export function renderChartSvg(spec: ChartSpec): ChartSvg {
|
|
241
|
+
/** The SVG document for `spec`, labeled for screen readers with {@link chartAlt}. */
|
|
242
|
+
export function renderChartSvg(spec: ChartSpec): string {
|
|
248
243
|
const layer = drawChart(spec);
|
|
249
244
|
const header = drawHeader(spec, layer);
|
|
250
245
|
const head = matrixHead(spec);
|
|
@@ -268,8 +263,8 @@ export function renderChartSvg(spec: ChartSpec): ChartSvg {
|
|
|
268
263
|
height += 20;
|
|
269
264
|
}
|
|
270
265
|
height = Math.ceil(height + PAD);
|
|
271
|
-
|
|
272
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${WIDTH}" height="${height}" viewBox="0 0 ${WIDTH} ${height}" font-family="${FONT}" font-size="${LABEL_SIZE}">`,
|
|
266
|
+
return [
|
|
267
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${WIDTH}" height="${height}" viewBox="0 0 ${WIDTH} ${height}" role="img" aria-label="${escapeXml(chartAlt(spec))}" font-family="${FONT}" font-size="${LABEL_SIZE}">`,
|
|
273
268
|
layer.body.includes(`url(#${INK_MASK})`) ? INK_DEFS : "",
|
|
274
269
|
`<g transform="translate(0 ${PAD})">${header.body}</g>`,
|
|
275
270
|
head.body && `<g transform="translate(0 ${num(PAD + header.height)})">${head.body}</g>`,
|
|
@@ -278,11 +273,10 @@ export function renderChartSvg(spec: ChartSpec): ChartSvg {
|
|
|
278
273
|
caption,
|
|
279
274
|
"</svg>",
|
|
280
275
|
].join("");
|
|
281
|
-
return { svg, width: WIDTH, height };
|
|
282
276
|
}
|
|
283
277
|
|
|
284
|
-
/** One-line description of the chart, for screen readers
|
|
285
|
-
|
|
278
|
+
/** One-line description of the chart, for screen readers. */
|
|
279
|
+
function chartAlt(spec: ChartSpec): string {
|
|
286
280
|
const joint =
|
|
287
281
|
spec.kind === "stacked" ? " + " : spec.kind === "slope" ? " → " : spec.kind === "butterfly" ? " vs " : ", ";
|
|
288
282
|
const names = spec.series.map(entry => entry.name).join(joint);
|
|
@@ -4432,6 +4426,13 @@ function token(name: string): string {
|
|
|
4432
4426
|
return `var(--${name})`;
|
|
4433
4427
|
}
|
|
4434
4428
|
|
|
4429
|
+
/** `raw` safe as XML text or a double-quoted attribute value. */
|
|
4430
|
+
function escapeXml(raw: string): string {
|
|
4431
|
+
return raw.replace(/[&<>"]/g, char =>
|
|
4432
|
+
char === "&" ? "&" : char === "<" ? "<" : char === ">" ? ">" : """,
|
|
4433
|
+
);
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4435
4436
|
function num(value: number): string {
|
|
4436
4437
|
return Number(value.toFixed(1)).toString();
|
|
4437
4438
|
}
|
|
@@ -4469,10 +4470,6 @@ function text(x: number, y: number, content: string | readonly TextRun[], style:
|
|
|
4469
4470
|
style.weight ? `font-weight="${style.weight}"` : "",
|
|
4470
4471
|
style.italic ? `font-style="italic"` : "",
|
|
4471
4472
|
].filter(Boolean);
|
|
4472
|
-
const escape = (raw: string) =>
|
|
4473
|
-
raw.replace(/[&<>"]/g, char =>
|
|
4474
|
-
char === "&" ? "&" : char === "<" ? "<" : char === ">" ? ">" : """,
|
|
4475
|
-
);
|
|
4476
4473
|
const body = runs
|
|
4477
4474
|
.filter(run => run.content)
|
|
4478
4475
|
.map(run => {
|
|
@@ -4480,7 +4477,7 @@ function text(x: number, y: number, content: string | readonly TextRun[], style:
|
|
|
4480
4477
|
run.fill ? ` fill="${token(run.fill)}"` : "",
|
|
4481
4478
|
run.weight ? ` font-weight="${run.weight}"` : "",
|
|
4482
4479
|
].join("");
|
|
4483
|
-
return own ? `<tspan${own}>${
|
|
4480
|
+
return own ? `<tspan${own}>${escapeXml(run.content)}</tspan>` : escapeXml(run.content);
|
|
4484
4481
|
})
|
|
4485
4482
|
.join("");
|
|
4486
4483
|
return `<text ${attrs.join(" ")}>${body}</text>`;
|
|
@@ -4,9 +4,11 @@ import { Image, type ImageBudget } from "../components/image";
|
|
|
4
4
|
import { ImageProtocol, TERMINAL } from "../terminal-capabilities";
|
|
5
5
|
import {
|
|
6
6
|
type DefaultTextStyle,
|
|
7
|
+
holdPartialTableRow,
|
|
7
8
|
Markdown,
|
|
8
9
|
type MarkdownTheme,
|
|
9
10
|
rewriteMarkdownLinkDestinations,
|
|
11
|
+
speculativeStreamingSource,
|
|
10
12
|
streamingMarkdownSource,
|
|
11
13
|
} from "../components/markdown";
|
|
12
14
|
import { Spacer } from "../components/spacer";
|
|
@@ -21,6 +23,7 @@ import { hasTranscriptActions, runTranscriptAction } from "./transcript-actions"
|
|
|
21
23
|
import type { DescribeContext, NativeChild, NativeNode, NativeUiEvent } from "../native/node";
|
|
22
24
|
import { isNativeRendering } from "../native/state";
|
|
23
25
|
import { NativeImageCache, nativeMediaNode } from "../native/blobs";
|
|
26
|
+
import { linkedImageText } from "../prompt/image-references";
|
|
24
27
|
import { Memo } from "../native/memo";
|
|
25
28
|
import { EMPTY_LINK_TARGETS, resolveImageOptions } from "../render/render-utils";
|
|
26
29
|
import { WidthAwareText } from "../render";
|
|
@@ -36,7 +39,7 @@ import { formatTurnUsage, type TurnUsageSummary } from "../overlays/usage-row";
|
|
|
36
39
|
import { FigureMarkdown } from "./figure-markdown";
|
|
37
40
|
import { svgFigureRendering } from "./svg-figure";
|
|
38
41
|
import { hasSvgFence } from "./svg-source";
|
|
39
|
-
import {
|
|
42
|
+
import { chartFence, hasChartTable, lookupTableChart, splitTableCharts } from "./table-chart";
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
45
|
* Max wrapped rows of a turn-ending provider error rendered inline in the
|
|
@@ -867,7 +870,13 @@ export class AssistantMessageComponent extends Container {
|
|
|
867
870
|
: {
|
|
868
871
|
text: source,
|
|
869
872
|
stream,
|
|
870
|
-
|
|
873
|
+
// A streaming node renders its open link or math span as already closed, as the TUI does.
|
|
874
|
+
node: node(
|
|
875
|
+
"md",
|
|
876
|
+
stream ? { text: speculativeStreamingSource(source), stream: true } : { text: source },
|
|
877
|
+
undefined,
|
|
878
|
+
key,
|
|
879
|
+
),
|
|
871
880
|
};
|
|
872
881
|
parts.set(slot, entry);
|
|
873
882
|
return entry.node;
|
|
@@ -891,7 +900,9 @@ export class AssistantMessageComponent extends Container {
|
|
|
891
900
|
const streaming = live && index === tailIndex;
|
|
892
901
|
if (content.type === "text" && canonicalizeMessage(content.text)) {
|
|
893
902
|
answered = true;
|
|
894
|
-
|
|
903
|
+
// A native terminal sizes table columns by every row it gets: send a growing row once
|
|
904
|
+
// its line ends. Hold before trimming, which would drop the newline ending a finished row.
|
|
905
|
+
const source = (streaming ? holdPartialTableRow(content.text) : content.text).trim();
|
|
895
906
|
// The terminal renders this source itself and would resolve a relative
|
|
896
907
|
// link against its own idea of the cwd: hand it the session-resolved
|
|
897
908
|
// targets (resolved once the segment closes, so never while streaming).
|
|
@@ -908,7 +919,7 @@ export class AssistantMessageComponent extends Container {
|
|
|
908
919
|
children.push(markdown(`t${index}`, `t${index}`, linked(source, streaming), streaming));
|
|
909
920
|
continue;
|
|
910
921
|
}
|
|
911
|
-
// A chart follows its table as an
|
|
922
|
+
// A chart follows its table as an ```svg figure the terminal colors; the prose splits around it.
|
|
912
923
|
const segments = splitTableCharts(source, streaming);
|
|
913
924
|
segments.forEach((segment, part) => {
|
|
914
925
|
const slot = part === 0 ? `t${index}` : `t${index}.${part}`;
|
|
@@ -919,7 +930,7 @@ export class AssistantMessageComponent extends Container {
|
|
|
919
930
|
}
|
|
920
931
|
const chart = lookupTableChart(segment.table);
|
|
921
932
|
if (chart instanceof Promise) this.#awaitChart(chart);
|
|
922
|
-
else if (chart) children.push(
|
|
933
|
+
else if (chart) children.push(markdown(slot, slot, chartFence(chart), false));
|
|
923
934
|
});
|
|
924
935
|
} else if (content.type === "thinking") {
|
|
925
936
|
const display = resolveThinkingDisplay(content, this.#proseOnlyThinking);
|
|
@@ -987,7 +998,14 @@ export class AssistantMessageComponent extends Container {
|
|
|
987
998
|
for (const [toolCallId, images] of this.#toolImagesByCallId) {
|
|
988
999
|
if (media && this.#toolMediaPathByCallId.has(toolCallId)) continue;
|
|
989
1000
|
images.forEach((image, index) => {
|
|
990
|
-
children.push(
|
|
1001
|
+
children.push(
|
|
1002
|
+
this.#nativeImages.get(
|
|
1003
|
+
`r${toolCallId}:${index}`,
|
|
1004
|
+
image.data,
|
|
1005
|
+
image.mimeType,
|
|
1006
|
+
this.#toolMediaPathByCallId.get(toolCallId),
|
|
1007
|
+
),
|
|
1008
|
+
);
|
|
991
1009
|
});
|
|
992
1010
|
}
|
|
993
1011
|
}
|
|
@@ -1600,12 +1618,15 @@ export class AssistantMessageComponent extends Container {
|
|
|
1600
1618
|
}
|
|
1601
1619
|
}
|
|
1602
1620
|
|
|
1603
|
-
#renderImageEntries(
|
|
1621
|
+
#renderImageEntries(
|
|
1622
|
+
entries: Array<{ image: ImageContent; key: string; sourcePath?: string }>,
|
|
1623
|
+
withLeadingSpacer: boolean,
|
|
1624
|
+
): void {
|
|
1604
1625
|
if (!this.#showImages || entries.length === 0) return;
|
|
1605
1626
|
this.#convertImagesForKitty(entries);
|
|
1606
1627
|
|
|
1607
1628
|
if (withLeadingSpacer) this.#contentContainer.addChild(new Spacer(1));
|
|
1608
|
-
for (const { image, key } of entries) {
|
|
1629
|
+
for (const { image, key, sourcePath } of entries) {
|
|
1609
1630
|
let displayImage: ImageContent | undefined = image;
|
|
1610
1631
|
if (TERMINAL.imageProtocol === ImageProtocol.Kitty && image.mimeType !== "image/png") {
|
|
1611
1632
|
displayImage = this.#kittyConversion(image);
|
|
@@ -1619,6 +1640,7 @@ export class AssistantMessageComponent extends Container {
|
|
|
1619
1640
|
{ fallbackColor: (text: string) => theme.fg("toolOutput", text) },
|
|
1620
1641
|
{
|
|
1621
1642
|
...resolveImageOptions(),
|
|
1643
|
+
sourcePath,
|
|
1622
1644
|
budget: this.#imageBudget,
|
|
1623
1645
|
imageKey: key,
|
|
1624
1646
|
requestRender: this.#onImageUpdate,
|
|
@@ -1627,15 +1649,18 @@ export class AssistantMessageComponent extends Container {
|
|
|
1627
1649
|
);
|
|
1628
1650
|
continue;
|
|
1629
1651
|
}
|
|
1630
|
-
this.#contentContainer.addChild(
|
|
1652
|
+
this.#contentContainer.addChild(
|
|
1653
|
+
new Text(theme.fg("toolOutput", linkedImageText(`[Image: ${image.mimeType}]`, image, sourcePath)), 1, 0),
|
|
1654
|
+
);
|
|
1631
1655
|
}
|
|
1632
1656
|
}
|
|
1633
1657
|
|
|
1634
1658
|
#renderToolImages(): void {
|
|
1635
1659
|
if (!this.#showToolResultImages) return;
|
|
1636
|
-
const entries = Array.from(this.#toolImagesByCallId.entries()).flatMap(([toolCallId, images]) =>
|
|
1637
|
-
|
|
1638
|
-
|
|
1660
|
+
const entries = Array.from(this.#toolImagesByCallId.entries()).flatMap(([toolCallId, images]) => {
|
|
1661
|
+
const sourcePath = this.#toolMediaPathByCallId.get(toolCallId);
|
|
1662
|
+
return images.map((image, index) => ({ image, key: `${toolCallId}:${index}`, sourcePath }));
|
|
1663
|
+
});
|
|
1639
1664
|
this.#renderImageEntries(entries, true);
|
|
1640
1665
|
}
|
|
1641
1666
|
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import { span, text } from "../native/describe";
|
|
32
32
|
import { type DescribeContext, type NativeNode, type NativeUiEvent, rootToggleExpanded } from "../native/node";
|
|
33
33
|
import { NativeImageCache } from "../native/blobs";
|
|
34
|
+
import { imageLinksEnabled, linkedImageSpan, linkedImageText } from "../prompt/image-references";
|
|
34
35
|
import { Memo } from "../native/memo";
|
|
35
36
|
|
|
36
37
|
const STREAMING_LINE_CAP = PREVIEW_LINES * 5;
|
|
@@ -172,14 +173,18 @@ export class BashExecutionComponent extends Container {
|
|
|
172
173
|
this.#expanded,
|
|
173
174
|
this.#showImages,
|
|
174
175
|
this.#images.length,
|
|
176
|
+
// Image nodes and placeholders carry links only under an enabled policy.
|
|
177
|
+
imageLinksEnabled(),
|
|
175
178
|
];
|
|
176
179
|
return this.#native.get(key, () => {
|
|
177
180
|
const images = this.#images.map((image, index) =>
|
|
178
181
|
this.#showImages
|
|
179
182
|
? this.#nativeImages.get(`img${index}`, image.data, image.mimeType)
|
|
180
183
|
: text([
|
|
181
|
-
|
|
184
|
+
linkedImageSpan(
|
|
182
185
|
imageFallback(image.mimeType, getImageDimensions(image.data, image.mimeType) ?? undefined),
|
|
186
|
+
image,
|
|
187
|
+
undefined,
|
|
183
188
|
"muted",
|
|
184
189
|
),
|
|
185
190
|
]),
|
|
@@ -418,7 +423,7 @@ export class BashExecutionComponent extends Container {
|
|
|
418
423
|
} else {
|
|
419
424
|
const dimensions = getImageDimensions(image.data, image.mimeType) ?? undefined;
|
|
420
425
|
this.#contentContainer.addChild(
|
|
421
|
-
new Text(theme.fg("muted", imageFallback(image.mimeType, dimensions)), 1, 0),
|
|
426
|
+
new Text(theme.fg("muted", linkedImageText(imageFallback(image.mimeType, dimensions), image)), 1, 0),
|
|
422
427
|
);
|
|
423
428
|
}
|
|
424
429
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ImageContent, Model } from "@oh-my-pi/pi-ai";
|
|
2
|
-
import { formatBytes, parseImageMetadata, SUPPORTED_IMAGE_MIME_TYPES } from "@oh-my-pi/pi-utils";
|
|
2
|
+
import { decodeBase64ImageData, formatBytes, parseImageMetadata, SUPPORTED_IMAGE_MIME_TYPES } from "@oh-my-pi/pi-utils";
|
|
3
3
|
|
|
4
4
|
export const MAX_IMAGE_INPUT_BYTES = 20 * 1024 * 1024;
|
|
5
5
|
|
|
@@ -83,11 +83,9 @@ const DECODE_PROBE_EDGE_PX = 1;
|
|
|
83
83
|
* truth on both sides. Callers on hot paths must cache the verdict.
|
|
84
84
|
*/
|
|
85
85
|
export async function imageDecodeFailureReason(image: ImageContent): Promise<string | null> {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const bytes =
|
|
89
|
-
if (bytes.length === 0) return "empty image data";
|
|
90
|
-
if (bytes.toString("base64").replace(/=+$/, "") !== normalizedData) return "invalid base64 image data";
|
|
86
|
+
const decoded = decodeBase64ImageData(image.data);
|
|
87
|
+
if (decoded.reason !== undefined) return decoded.reason;
|
|
88
|
+
const { bytes } = decoded;
|
|
91
89
|
const detected = parseImageMetadata(bytes);
|
|
92
90
|
if (detected && detected.mimeType !== image.mimeType.toLowerCase()) {
|
|
93
91
|
return `declared ${image.mimeType} but contains ${detected.mimeType}`;
|
package/src/chat/table-chart.ts
CHANGED
|
@@ -5,24 +5,19 @@
|
|
|
5
5
|
* and draws that chart — locally under `always`, through the host's
|
|
6
6
|
* model-backed {@link TableChartPlanner} under `smart` for the tables
|
|
7
7
|
* {@link shouldJudge} picks — and caches it per table source. {@link TableChartFigure} shows it
|
|
8
|
-
* as a rasterized
|
|
9
|
-
* terminal the SVG
|
|
10
|
-
*
|
|
8
|
+
* as a terminal image rasterized in omp's theme; {@link chartFence} hands a
|
|
9
|
+
* TSP terminal the SVG as an ```svg fence, which it draws in the palette it
|
|
10
|
+
* shows. Either way a chart follows theme switches like the prose around it.
|
|
11
11
|
*/
|
|
12
12
|
import { logger } from "@oh-my-pi/pi-utils";
|
|
13
13
|
import type { Token, Tokens } from "@oh-my-pi/pi-utils/marked";
|
|
14
14
|
import { type ChartPlan, buildChart, planChart, shouldJudge, worthCharting } from "../charts/chart-plan";
|
|
15
|
-
import {
|
|
15
|
+
import { renderChartSvg } from "../charts/chart-svg";
|
|
16
16
|
import { analyzeTable, type TableAnalysis } from "../charts/table-data";
|
|
17
17
|
import type { ImageBudget } from "../components/image";
|
|
18
18
|
import { lexDocument } from "../components/markdown";
|
|
19
|
-
import { keyed } from "../native/describe";
|
|
20
|
-
import { nativeImageNode } from "../native/blobs";
|
|
21
|
-
import type { NativeNode } from "../native/node";
|
|
22
|
-
import { getThemeEpoch } from "../theme";
|
|
23
19
|
import type { Component } from "../tui";
|
|
24
|
-
import { SvgFigure
|
|
25
|
-
import { prepareSvg } from "./svg-source";
|
|
20
|
+
import { SvgFigure } from "./svg-figure";
|
|
26
21
|
|
|
27
22
|
/**
|
|
28
23
|
* `smart`: a model refines the local guess where meaning decides (kind,
|
|
@@ -47,18 +42,11 @@ export interface TableChartRequest {
|
|
|
47
42
|
*/
|
|
48
43
|
export type TableChartPlanner = (request: TableChartRequest) => Promise<ChartPlan | null>;
|
|
49
44
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/** Size in SVG user units. */
|
|
56
|
-
readonly width: number;
|
|
57
|
-
readonly height: number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** The chart under a table: drawn, none, or a smart pick on its way (the promise settles once the cache holds it). */
|
|
61
|
-
export type ChartLookup = TableChart | null | Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* The chart under a table: its SVG, colored with figure tokens (`var(--accent)`, …)
|
|
47
|
+
* still to resolve; none; or a smart pick on its way (the promise settles once the cache holds it).
|
|
48
|
+
*/
|
|
49
|
+
export type ChartLookup = string | null | Promise<void>;
|
|
62
50
|
|
|
63
51
|
/** One run of a Markdown block: prose (ending at a charted table), or the chart drawn after that table. */
|
|
64
52
|
export type ChartSegment =
|
|
@@ -67,8 +55,6 @@ export type ChartSegment =
|
|
|
67
55
|
|
|
68
56
|
/** Tables cached per source; a long session keeps its recent charts without growing without bound. */
|
|
69
57
|
const CACHE_LIMIT = 256;
|
|
70
|
-
/** SVG user units per terminal column (16 per row on 1:2 cells), sizing native images. */
|
|
71
|
-
const UNITS_PER_COLUMN = 8;
|
|
72
58
|
/** A GFM delimiter row (`|---|:--:|`), the cheap test before lexing a block. */
|
|
73
59
|
const DELIMITER_ROW = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*\|/m;
|
|
74
60
|
|
|
@@ -78,20 +64,14 @@ interface ChartEntry {
|
|
|
78
64
|
readonly guess: ChartPlan | undefined;
|
|
79
65
|
/** The host's planner picks this table's chart. */
|
|
80
66
|
readonly smart: boolean;
|
|
81
|
-
/** `undefined` until drawn (or judged chartless). */
|
|
82
|
-
chart?:
|
|
67
|
+
/** The chart's SVG; `undefined` until drawn (or judged chartless). */
|
|
68
|
+
chart?: string | null;
|
|
83
69
|
pending?: Promise<void>;
|
|
84
70
|
}
|
|
85
71
|
|
|
86
72
|
let chartMode: TableChartMode = "off";
|
|
87
73
|
let chartPlanner: TableChartPlanner | undefined;
|
|
88
74
|
const charts = new Map<string, ChartEntry>();
|
|
89
|
-
/** The theme-resolved image node owning a chart's native bytes. */
|
|
90
|
-
const kNativeImage = Symbol("tableChart.nativeImage");
|
|
91
|
-
|
|
92
|
-
interface NativeTagged extends TableChart {
|
|
93
|
-
[kNativeImage]?: { epoch: number; image: NativeNode };
|
|
94
|
-
}
|
|
95
75
|
|
|
96
76
|
/** Set how tables become charts (the host's `tui.autoGraph`) and its `smart` planner; the host rebuilds the transcript after. */
|
|
97
77
|
export function setTableCharts(mode: TableChartMode, planner?: TableChartPlanner): void {
|
|
@@ -188,34 +168,21 @@ function chartEntry(table: Tokens.Table): ChartEntry {
|
|
|
188
168
|
* Draw `plan`. A guess must also pass {@link worthCharting}; a model's pick
|
|
189
169
|
* already judged the chart worth drawing.
|
|
190
170
|
*/
|
|
191
|
-
function drawChart(analysis: TableAnalysis, plan: ChartPlan, guessed = false):
|
|
171
|
+
function drawChart(analysis: TableAnalysis, plan: ChartPlan, guessed = false): string | null {
|
|
192
172
|
const spec = buildChart(analysis, plan);
|
|
193
173
|
if (!spec || (guessed && !worthCharting(spec))) return null;
|
|
194
|
-
return
|
|
174
|
+
return renderChartSvg(spec);
|
|
195
175
|
}
|
|
196
176
|
|
|
197
177
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
178
|
+
* Chart `svg` as a Markdown ```svg fence, for a TSP terminal's `md` node. Its
|
|
179
|
+
* figure tokens stay unresolved: the terminal draws the fence as a figure in
|
|
180
|
+
* the palette it shows the prose in, so the chart cannot fall out of step with
|
|
181
|
+
* the page when omp's own idea of the appearance does, and a theme switch
|
|
182
|
+
* recolors it without a resend.
|
|
200
183
|
*/
|
|
201
|
-
export function
|
|
202
|
-
|
|
203
|
-
const tagged: NativeTagged = chart;
|
|
204
|
-
let entry = tagged[kNativeImage];
|
|
205
|
-
if (entry?.epoch !== epoch) {
|
|
206
|
-
const svg = prepareSvg(chart.svg, svgFigurePalette());
|
|
207
|
-
entry = {
|
|
208
|
-
epoch,
|
|
209
|
-
image: nativeImageNode(new TextEncoder().encode(svg), "image/svg+xml", {
|
|
210
|
-
alt: chart.alt,
|
|
211
|
-
w: chart.width,
|
|
212
|
-
h: chart.height,
|
|
213
|
-
max: { w: `${Math.round(chart.width / UNITS_PER_COLUMN)}ch` },
|
|
214
|
-
}),
|
|
215
|
-
};
|
|
216
|
-
tagged[kNativeImage] = entry;
|
|
217
|
-
}
|
|
218
|
-
return keyed(entry.image, key);
|
|
184
|
+
export function chartFence(svg: string): string {
|
|
185
|
+
return `\`\`\`svg\n${svg}\n\`\`\``;
|
|
219
186
|
}
|
|
220
187
|
|
|
221
188
|
export interface TableChartFigureOptions {
|
|
@@ -235,8 +202,8 @@ export class TableChartFigure implements Component {
|
|
|
235
202
|
readonly #options: TableChartFigureOptions;
|
|
236
203
|
readonly #figure: SvgFigure;
|
|
237
204
|
#table: Tokens.Table | undefined;
|
|
238
|
-
/** `undefined` while not looked up or waiting for a pick. */
|
|
239
|
-
#chart:
|
|
205
|
+
/** The chart's SVG; `undefined` while not looked up or waiting for a pick. */
|
|
206
|
+
#chart: string | null | undefined;
|
|
240
207
|
#waiting = false;
|
|
241
208
|
#disposed = false;
|
|
242
209
|
|
|
@@ -289,6 +256,6 @@ export class TableChartFigure implements Component {
|
|
|
289
256
|
return;
|
|
290
257
|
}
|
|
291
258
|
this.#chart = found;
|
|
292
|
-
if (found) this.#figure.update(found
|
|
259
|
+
if (found) this.#figure.update(found, true);
|
|
293
260
|
}
|
|
294
261
|
}
|
|
@@ -33,6 +33,7 @@ import { plainText } from "../native/spans";
|
|
|
33
33
|
import { diagnosticsSection, displayPath, toolHead } from "../tools/native-view";
|
|
34
34
|
import type { FileDiagnosticsResult } from "../tools/lsp";
|
|
35
35
|
import { NativeImageCache, readMediaPath, shownMedia } from "../native/blobs";
|
|
36
|
+
import { imageLinksEnabled, linkedImageText } from "../prompt/image-references";
|
|
36
37
|
import { Memo } from "../native/memo";
|
|
37
38
|
import { type EditMode, type PerFileDiffPreview, renderStreamingFallback } from "../tools/edit";
|
|
38
39
|
import { taskCardAgentIds } from "../tools/task";
|
|
@@ -1255,7 +1256,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
1255
1256
|
const images: NativeNode[] = [];
|
|
1256
1257
|
this.#getAllImageBlocks().forEach((image, index) => {
|
|
1257
1258
|
if (!image.data || !image.mimeType) return;
|
|
1258
|
-
const described = this.#nativeImages.get(`img${index}`, image.data, image.mimeType);
|
|
1259
|
+
const described = this.#nativeImages.get(`img${index}`, image.data, image.mimeType, mediaPath);
|
|
1259
1260
|
if (!shown.blobs.has((described.p as { blob?: string } | undefined)?.blob ?? "")) images.push(described);
|
|
1260
1261
|
});
|
|
1261
1262
|
return images;
|
|
@@ -1287,7 +1288,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
1287
1288
|
// TUI startup, so a result rendered before it lands must re-shape once it
|
|
1288
1289
|
// does (it gates Image children vs text fallback in #rebuildDisplay); keyed
|
|
1289
1290
|
// here for the same reason markdown.ts keys its render cache on it.
|
|
1290
|
-
const key = `${this.#resultVersion}|${this.#expanded}|${this.#isPartial}|${this.#argsComplete ? "1" : "0"}|${this.#executionStarted ? "1" : "0"}|${this.#spinnerFrame ?? "-"}|${this.#showImages}|${getThemeEpoch()}|${this.#displayInputVersion}|${TERMINAL.imageProtocol ?? "-"}|${this.#imageSizeKey()}`;
|
|
1291
|
+
const key = `${this.#resultVersion}|${this.#expanded}|${this.#isPartial}|${this.#argsComplete ? "1" : "0"}|${this.#executionStarted ? "1" : "0"}|${this.#spinnerFrame ?? "-"}|${this.#showImages}|${getThemeEpoch()}|${this.#displayInputVersion}|${TERMINAL.imageProtocol ?? "-"}|${this.#imageSizeKey()}|${imageLinksEnabled()}`;
|
|
1291
1292
|
if (key === this.#lastDisplayKey && this.#displayBuilt) return;
|
|
1292
1293
|
this.#lastDisplayKey = key;
|
|
1293
1294
|
|
|
@@ -1694,6 +1695,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
1694
1695
|
|
|
1695
1696
|
if (this.#result) {
|
|
1696
1697
|
const imageBlocks = this.#getAllImageBlocks();
|
|
1698
|
+
const sourcePath = readMediaPath(this.#result.details);
|
|
1697
1699
|
|
|
1698
1700
|
for (let i = 0; i < imageBlocks.length; i++) {
|
|
1699
1701
|
const img = imageBlocks[i];
|
|
@@ -1721,6 +1723,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
1721
1723
|
{ fallbackColor: (s: string) => theme.fg("toolOutput", s) },
|
|
1722
1724
|
{
|
|
1723
1725
|
...resolveImageOptions(),
|
|
1726
|
+
sourcePath,
|
|
1724
1727
|
budget: this.#ui.imageBudget,
|
|
1725
1728
|
imageKey: `te${this.#instanceId}:${i}`,
|
|
1726
1729
|
requestRender: () => this.#ui.requestRender(),
|
|
@@ -1859,7 +1862,8 @@ export class ToolExecutionComponent extends Container {
|
|
|
1859
1862
|
|
|
1860
1863
|
#getTextOutput(): string {
|
|
1861
1864
|
if (!this.#result) return "";
|
|
1862
|
-
|
|
1865
|
+
// Image placeholders embed a link only under an enabled hyperlink policy.
|
|
1866
|
+
const key = `${this.#resultVersion}|${this.#showImages}|${TERMINAL.imageProtocol ?? "-"}|${imageLinksEnabled()}`;
|
|
1863
1867
|
if (key === this.#textOutputKey) return this.#textOutput;
|
|
1864
1868
|
|
|
1865
1869
|
const textBlocks = this.#result.content.filter(c => c.type === "text");
|
|
@@ -1876,7 +1880,10 @@ export class ToolExecutionComponent extends Container {
|
|
|
1876
1880
|
.map(img => {
|
|
1877
1881
|
const mimeType = String(img.mimeType);
|
|
1878
1882
|
const dims = img.data ? (getImageDimensions(img.data, mimeType) ?? undefined) : undefined;
|
|
1879
|
-
|
|
1883
|
+
const placeholder = imageFallback(mimeType, dims);
|
|
1884
|
+
return img.data
|
|
1885
|
+
? linkedImageText(placeholder, { data: img.data, mimeType }, readMediaPath(this.#result?.details))
|
|
1886
|
+
: placeholder;
|
|
1880
1887
|
})
|
|
1881
1888
|
.join("\n");
|
|
1882
1889
|
output = output ? `${output}\n${imageIndicators}` : imageIndicators;
|
package/src/chat/user-message.ts
CHANGED
|
@@ -18,12 +18,12 @@ import {
|
|
|
18
18
|
skillChipStyle,
|
|
19
19
|
} from "../prompt/composer-attachments";
|
|
20
20
|
import { MODEL_MENTION_TAG_RE } from "../prompt/model-mention-syntax";
|
|
21
|
-
import { expandKeyHint, fileHyperlink } from "../render";
|
|
22
|
-
import { imageReferenceHyperlink } from "../prompt/image-references";
|
|
21
|
+
import { expandKeyHint, fileHyperlink, fileLinkSpan } from "../render";
|
|
22
|
+
import { imageLinksEnabled, imageReferenceHyperlink } from "../prompt/image-references";
|
|
23
23
|
import { highlightMagicKeywords } from "../prompt/magic-keywords";
|
|
24
24
|
import type { ReactionTarget } from "./reaction";
|
|
25
25
|
import { card, md, node, row, span, text } from "../native/describe";
|
|
26
|
-
import { base64ImageNode } from "../native/blobs";
|
|
26
|
+
import { base64ImageNode, openableImageProps } from "../native/blobs";
|
|
27
27
|
import { hasTranscriptActions, runTranscriptAction } from "./transcript-actions";
|
|
28
28
|
import {
|
|
29
29
|
type DescribeContext,
|
|
@@ -145,8 +145,9 @@ export class UserMessageComponent extends Container implements ReactionTarget, T
|
|
|
145
145
|
readonly #tokens: RegExp;
|
|
146
146
|
#reaction: string | undefined;
|
|
147
147
|
#native: NativeNode | undefined;
|
|
148
|
-
/** The terminal's clock {@link #native} was described with. */
|
|
148
|
+
/** The terminal's clock and the image link policy {@link #native} was described with. */
|
|
149
149
|
#nativeHour12: boolean | undefined;
|
|
150
|
+
#nativeLinked = false;
|
|
150
151
|
|
|
151
152
|
constructor(text: string, options: UserBubbleOptions = {}) {
|
|
152
153
|
super();
|
|
@@ -204,8 +205,11 @@ export class UserMessageComponent extends Container implements ReactionTarget, T
|
|
|
204
205
|
override describe(cx?: DescribeContext): NativeNode {
|
|
205
206
|
// The terminal's clock: Bun's own default locale ignores the user's.
|
|
206
207
|
const hour12 = cx?.hour12;
|
|
207
|
-
|
|
208
|
+
// Chip marks and thumbnails carry links only under an enabled policy.
|
|
209
|
+
const linked = imageLinksEnabled();
|
|
210
|
+
if (this.#native && this.#nativeHour12 === hour12 && this.#nativeLinked === linked) return this.#native;
|
|
208
211
|
this.#nativeHour12 = hour12;
|
|
212
|
+
this.#nativeLinked = linked;
|
|
209
213
|
const children: NativeChild[] = [];
|
|
210
214
|
if (!this.#synthetic && hasTranscriptActions()) {
|
|
211
215
|
const tools: NativeChild[] = [
|
|
@@ -253,16 +257,14 @@ export class UserMessageComponent extends Container implements ReactionTarget, T
|
|
|
253
257
|
this.#images.forEach((image, i) => {
|
|
254
258
|
if (!image.mimeType.startsWith("image/")) return;
|
|
255
259
|
const label = `#${i + 1}`;
|
|
256
|
-
const
|
|
257
|
-
// A click zooms the image in the terminal; the file opens from its context menu.
|
|
258
|
-
const open = link ? { href: link, actions: { menu: ["open"] } } : {};
|
|
260
|
+
const open = openableImageProps(linked ? this.#imageLinks?.[i] : undefined);
|
|
259
261
|
thumbs.push(base64ImageNode(image.data, image.mimeType, { alt: label, title: label, ...open }, label));
|
|
260
262
|
});
|
|
261
263
|
}
|
|
262
264
|
if (thumbs.length > 0) {
|
|
263
265
|
children.push(row(thumbs, { gap: "sm", wrap: true, align: "start", role: "omp.user.images" }));
|
|
264
266
|
}
|
|
265
|
-
const marks = this.#synthetic ? [] : tokenMarks(this.#text, this.#tokens);
|
|
267
|
+
const marks = this.#synthetic ? [] : tokenMarks(this.#text, this.#tokens, this.#imageLinks);
|
|
266
268
|
children.push(md(this.#text, marks.length > 0 ? { marks } : undefined));
|
|
267
269
|
const badges: NativeChild[] = [];
|
|
268
270
|
if (this.#liveSteered) {
|
|
@@ -359,13 +361,13 @@ export class UserMessageComponent extends Container implements ReactionTarget, T
|
|
|
359
361
|
/**
|
|
360
362
|
* The composer tokens in `text` as `md` marks, styled as the composer
|
|
361
363
|
* decorates them (`CustomEditor.describeDecorations`), so a sent prompt keeps
|
|
362
|
-
* its chips highlighted.
|
|
364
|
+
* its chips highlighted. Image and video chips link to their file, as in text mode.
|
|
363
365
|
*/
|
|
364
|
-
function tokenMarks(text: string, tokens: RegExp): TspSpan[] {
|
|
366
|
+
function tokenMarks(text: string, tokens: RegExp, imageLinks: readonly (string | undefined)[] | undefined): TspSpan[] {
|
|
365
367
|
// One mark per distinct token: Tern styles every occurrence of its text.
|
|
366
|
-
const
|
|
368
|
+
const marks = new Map<string, TspSpan>();
|
|
367
369
|
const mark = (s: string) => (label: string) => {
|
|
368
|
-
|
|
370
|
+
marks.set(label, { t: label, s });
|
|
369
371
|
return "";
|
|
370
372
|
};
|
|
371
373
|
renderPlaceholders(
|
|
@@ -374,11 +376,16 @@ function tokenMarks(text: string, tokens: RegExp): TspSpan[] {
|
|
|
374
376
|
renderText: () => "",
|
|
375
377
|
renderSkill: mark("customMessageLabel strong"),
|
|
376
378
|
renderMention: mark("statusLineModel strong"),
|
|
377
|
-
renderReference:
|
|
379
|
+
renderReference: (label, kind, index) => {
|
|
380
|
+
const s = "accent strong";
|
|
381
|
+
const link = kind === "image" || kind === "video" ? imageLinks?.[index - 1] : undefined;
|
|
382
|
+
marks.set(label, link ? fileLinkSpan(link, label, s) : { t: label, s });
|
|
383
|
+
return "";
|
|
384
|
+
},
|
|
378
385
|
},
|
|
379
386
|
tokens,
|
|
380
387
|
);
|
|
381
|
-
return [...
|
|
388
|
+
return [...marks.values()];
|
|
382
389
|
}
|
|
383
390
|
|
|
384
391
|
/**
|
|
@@ -412,6 +412,16 @@ export class TranscriptContainer extends Container {
|
|
|
412
412
|
return this.#entries.map(entry => entry.emitted);
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
/** Whether any block is still streaming or otherwise unfinalized. */
|
|
416
|
+
hasActiveBlock(): boolean {
|
|
417
|
+
this.#syncEntries();
|
|
418
|
+
this.#settleFinalized();
|
|
419
|
+
for (let index = this.#frontier; index < this.#entries.length; index++) {
|
|
420
|
+
if (this.#entries[index]!.state === "active") return true;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
|
|
415
425
|
/** Whether visible active capacity and live-block memory permit another admission. */
|
|
416
426
|
canAdmit(rows: number): boolean {
|
|
417
427
|
const active = this.#entries.filter(entry => entry.state === "active").length;
|