@chances-ai/tui 12.0.0 → 14.0.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/api-key-prompt.d.ts +1 -0
- package/dist/api-key-prompt.d.ts.map +1 -1
- package/dist/api-key-prompt.js +3 -1
- package/dist/api-key-prompt.js.map +1 -1
- package/dist/app.d.ts +14 -16
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +87 -69
- package/dist/app.js.map +1 -1
- package/dist/code-view.d.ts +9 -0
- package/dist/code-view.d.ts.map +1 -0
- package/dist/code-view.js +28 -0
- package/dist/code-view.js.map +1 -0
- package/dist/diff-model.d.ts +64 -0
- package/dist/diff-model.d.ts.map +1 -0
- package/dist/diff-model.js +156 -0
- package/dist/diff-model.js.map +1 -0
- package/dist/diff-view.d.ts +13 -0
- package/dist/diff-view.d.ts.map +1 -0
- package/dist/diff-view.js +60 -0
- package/dist/diff-view.js.map +1 -0
- package/dist/frame-scheduler.d.ts +44 -0
- package/dist/frame-scheduler.d.ts.map +1 -0
- package/dist/frame-scheduler.js +58 -0
- package/dist/frame-scheduler.js.map +1 -0
- package/dist/highlight-to-segments.d.ts +18 -0
- package/dist/highlight-to-segments.d.ts.map +1 -0
- package/dist/highlight-to-segments.js +224 -0
- package/dist/highlight-to-segments.js.map +1 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/markdown.d.ts +5 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +117 -0
- package/dist/markdown.js.map +1 -0
- package/dist/model-picker.d.ts +1 -0
- package/dist/model-picker.d.ts.map +1 -1
- package/dist/model-picker.js +4 -2
- package/dist/model-picker.js.map +1 -1
- package/dist/progress.d.ts +41 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +122 -0
- package/dist/progress.js.map +1 -0
- package/dist/session-picker.d.ts +1 -0
- package/dist/session-picker.d.ts.map +1 -1
- package/dist/session-picker.js +4 -2
- package/dist/session-picker.js.map +1 -1
- package/dist/theme-context.d.ts +25 -0
- package/dist/theme-context.d.ts.map +1 -0
- package/dist/theme-context.js +24 -0
- package/dist/theme-context.js.map +1 -0
- package/dist/theme.d.ts +106 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +116 -0
- package/dist/theme.js.map +1 -0
- package/dist/tool-line.d.ts +33 -0
- package/dist/tool-line.d.ts.map +1 -0
- package/dist/tool-line.js +168 -0
- package/dist/tool-line.js.map +1 -0
- package/dist/tool-message.d.ts +18 -0
- package/dist/tool-message.d.ts.map +1 -0
- package/dist/tool-message.js +37 -0
- package/dist/tool-message.js.map +1 -0
- package/dist/view-model.d.ts +135 -3
- package/dist/view-model.d.ts.map +1 -1
- package/dist/view-model.js +292 -31
- package/dist/view-model.js.map +1 -1
- package/package.json +10 -6
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (5.9 / v14) Pure parser that turns the `linesDiff` text block (carried in a
|
|
3
|
+
* write/edit `tool:permission` summary — see `view-model.ts`) into structured,
|
|
4
|
+
* renderable rows. NO React/Ink here — this is the correctness core, fully
|
|
5
|
+
* unit-tested in isolation.
|
|
6
|
+
*
|
|
7
|
+
* `linesDiff` (`packages/tools/src/diff.ts`) emits, in order:
|
|
8
|
+
* `@@ -start,rem +start,add @@`
|
|
9
|
+
* `- <removed line>` × rem
|
|
10
|
+
* `+ <added line>` × add
|
|
11
|
+
* — i.e. ALL removes then ALL adds, NO context lines; with a `… (N lines
|
|
12
|
+
* elided)` marker injected in the middle when the block exceeds its 14-body-row
|
|
13
|
+
* cap (so a full block is up to 15 lines incl. the header — codex R1 SHOULD-5).
|
|
14
|
+
*
|
|
15
|
+
* Line numbers (codex R1 MUST-1): `write` diffs are whole-file-anchored
|
|
16
|
+
* (`linesDiff(before, content)`), so `@@ -start` is the real file line — render
|
|
17
|
+
* the gutter. `edit` diffs are `find`↔`replace` snippets, so `@@ -1` is
|
|
18
|
+
* snippet-relative — the caller passes `anchored: false` and no gutter is shown.
|
|
19
|
+
*/
|
|
20
|
+
import { diffWordsWithSpace } from "diff";
|
|
21
|
+
/** Threshold above which a remove/add pair renders as whole-line (not word-level).
|
|
22
|
+
* Matches claude-code `StructuredDiff/Fallback.tsx` `CHANGE_THRESHOLD`. */
|
|
23
|
+
export const CHANGE_THRESHOLD = 0.4;
|
|
24
|
+
const HUNK_RE = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
|
|
25
|
+
// Anchored + exact: `linesDiff` emits the marker as `… (N lines elided)`. A
|
|
26
|
+
// loose `lines elided)` alternative (codex R2 SHOULD-4) would misclassify a
|
|
27
|
+
// real source line that merely contains that phrase.
|
|
28
|
+
const ELISION_RE = /^… \(\d+ lines elided\)$/;
|
|
29
|
+
/**
|
|
30
|
+
* Detect whether a text block is a renderable diff (the non-diff guard, 5.9 §3):
|
|
31
|
+
* true only when it contains a `@@ -d +d @@` hunk header.
|
|
32
|
+
*/
|
|
33
|
+
export function looksLikeDiff(text) {
|
|
34
|
+
return text.split("\n").some((l) => HUNK_RE.test(l));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse a `linesDiff` block. `anchored` (write=true, edit=false) controls
|
|
38
|
+
* whether line numbers are assigned. Returns rows in source order with
|
|
39
|
+
* word-level segments computed for sub-threshold remove/add pairs.
|
|
40
|
+
*/
|
|
41
|
+
export function parseDiff(text, opts) {
|
|
42
|
+
const lines = text.split("\n");
|
|
43
|
+
let startLine = null;
|
|
44
|
+
const raw = [];
|
|
45
|
+
for (const line of lines) {
|
|
46
|
+
const hunk = HUNK_RE.exec(line);
|
|
47
|
+
if (hunk) {
|
|
48
|
+
if (startLine === null)
|
|
49
|
+
startLine = Number(hunk[1]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (ELISION_RE.test(line)) {
|
|
53
|
+
raw.push({ kind: "elision", text: line });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (line.startsWith("- "))
|
|
57
|
+
raw.push({ kind: "remove", text: line.slice(2) });
|
|
58
|
+
else if (line.startsWith("+ "))
|
|
59
|
+
raw.push({ kind: "add", text: line.slice(2) });
|
|
60
|
+
else if (line === "-" || line === "+")
|
|
61
|
+
raw.push({ kind: line === "+" ? "add" : "remove", text: "" });
|
|
62
|
+
// Anything else (stray context / blank) is ignored: linesDiff never emits it.
|
|
63
|
+
}
|
|
64
|
+
const rows = numberAndPair(raw, startLine ?? 1, opts.anchored);
|
|
65
|
+
return { rows, startLine };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Assign line numbers (anchored only) and compute word-level pairing. Mirrors
|
|
69
|
+
* claude-code's `numberDiffLines` + `processAdjacentLines`: a run of removes
|
|
70
|
+
* followed by a run of adds pairs index-wise; the line counter rewinds by the
|
|
71
|
+
* number of removes so the matching add reuses the same displayed number.
|
|
72
|
+
*/
|
|
73
|
+
function numberAndPair(raw, startLine, anchored) {
|
|
74
|
+
const out = [];
|
|
75
|
+
let i = 0;
|
|
76
|
+
let lineNo = startLine;
|
|
77
|
+
while (i < raw.length) {
|
|
78
|
+
const cur = raw[i];
|
|
79
|
+
if (cur.kind === "elision") {
|
|
80
|
+
out.push({ kind: "elision", text: cur.text, lineNo: null, words: null });
|
|
81
|
+
i++;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (cur.kind === "remove") {
|
|
85
|
+
// Collect the remove run, then the following add run.
|
|
86
|
+
const removes = [];
|
|
87
|
+
while (i < raw.length && raw[i].kind === "remove")
|
|
88
|
+
removes.push(raw[i++]);
|
|
89
|
+
const adds = [];
|
|
90
|
+
while (i < raw.length && raw[i].kind === "add")
|
|
91
|
+
adds.push(raw[i++]);
|
|
92
|
+
const removeBase = lineNo;
|
|
93
|
+
removes.forEach((r, k) => {
|
|
94
|
+
const paired = adds[k];
|
|
95
|
+
out.push({
|
|
96
|
+
kind: "remove",
|
|
97
|
+
text: r.text,
|
|
98
|
+
lineNo: anchored ? removeBase + k : null,
|
|
99
|
+
words: paired ? wordSegs(r.text, paired.text, "remove") : null,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
// Rewind: removed lines don't exist in the new file — adds reuse the numbers.
|
|
103
|
+
adds.forEach((a, k) => {
|
|
104
|
+
const paired = removes[k];
|
|
105
|
+
out.push({
|
|
106
|
+
kind: "add",
|
|
107
|
+
text: a.text,
|
|
108
|
+
lineNo: anchored ? removeBase + k : null,
|
|
109
|
+
// wordSegs always takes (removeText, addText); here the add's pair is
|
|
110
|
+
// the remove at the same index.
|
|
111
|
+
words: paired ? wordSegs(paired.text, a.text, "add") : null,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
lineNo = removeBase + Math.max(removes.length, adds.length);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// A lone add run (pure insertion, no preceding removes).
|
|
118
|
+
if (cur.kind === "add") {
|
|
119
|
+
while (i < raw.length && raw[i].kind === "add") {
|
|
120
|
+
const a = raw[i++];
|
|
121
|
+
out.push({ kind: "add", text: a.text, lineNo: anchored ? lineNo++ : null, words: null });
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
i++;
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Word-level segments for one side of a pair. `side:"remove"` keeps common +
|
|
131
|
+
* removed words; `side:"add"` keeps common + added words. Returns null when the
|
|
132
|
+
* pair changed more than {@link CHANGE_THRESHOLD} of its total length (render
|
|
133
|
+
* whole-line instead).
|
|
134
|
+
*/
|
|
135
|
+
export function wordSegs(removeText, addText, side) {
|
|
136
|
+
const parts = diffWordsWithSpace(removeText, addText);
|
|
137
|
+
const total = removeText.length + addText.length;
|
|
138
|
+
const changedLen = parts.reduce((sum, p) => (p.added || p.removed ? sum + p.value.length : sum), 0);
|
|
139
|
+
if (total === 0 || changedLen / total > CHANGE_THRESHOLD)
|
|
140
|
+
return null;
|
|
141
|
+
const segs = [];
|
|
142
|
+
for (const p of parts) {
|
|
143
|
+
if (side === "remove") {
|
|
144
|
+
if (p.added)
|
|
145
|
+
continue;
|
|
146
|
+
segs.push({ text: p.value, changed: !!p.removed });
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (p.removed)
|
|
150
|
+
continue;
|
|
151
|
+
segs.push({ text: p.value, changed: !!p.added });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return segs;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=diff-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-model.js","sourceRoot":"","sources":["../src/diff-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAE1C;4EAC4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AA0BpC,MAAM,OAAO,GAAG,yCAAyC,CAAC;AAC1D,4EAA4E;AAC5E,4EAA4E;AAC5E,qDAAqD;AACrD,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAA2B;IACjE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,SAAS,GAAkB,IAAI,CAAC;IACpC,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;Q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OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
export interface DiffViewProps {
|
|
3
|
+
/** The raw `linesDiff` text (from the stashed `tool:permission` summary). */
|
|
4
|
+
diff: string;
|
|
5
|
+
/** True for `write` (whole-file-anchored line numbers); false for `edit`
|
|
6
|
+
* (snippet-relative — no gutter, codex R1 MUST-1). */
|
|
7
|
+
anchored: boolean;
|
|
8
|
+
/** Render width for full-line background padding. Defaults to the terminal
|
|
9
|
+
* columns (or 80). */
|
|
10
|
+
width?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function DiffView({ diff, anchored, width }: DiffViewProps): JSX.Element;
|
|
13
|
+
//# sourceMappingURL=diff-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-view.d.ts","sourceRoot":"","sources":["../src/diff-view.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAKjC,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,EAAE,OAAO,CAAC;IAClB;2BACuB;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAOD,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAgB9E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* (5.9 / v14) Render a `linesDiff` block as claude-code's structured diff:
|
|
4
|
+
* per-row `<lineNo> <sigil> <code>` with a full-line background, word-level
|
|
5
|
+
* emphasis on sub-threshold pairs. Pure parsing lives in `diff-model.ts`; this
|
|
6
|
+
* file is the Ink view only.
|
|
7
|
+
*
|
|
8
|
+
* Notes:
|
|
9
|
+
* - `linesDiff` emits no context lines, so every row is add/remove — there is
|
|
10
|
+
* no context-line syntax highlighting to do here (a lever if context is ever
|
|
11
|
+
* added). Readability comes from the +/- background + word emphasis.
|
|
12
|
+
* - Each text run carries an EXPLICIT backgroundColor (word-bg for changed
|
|
13
|
+
* words, else the line-bg) so Ink leaves no un-painted gaps between runs.
|
|
14
|
+
* - Under `NO_COLOR` every theme bg is undefined ⇒ no background; the `+`/`-`
|
|
15
|
+
* sigils alone carry the add/remove meaning.
|
|
16
|
+
*/
|
|
17
|
+
import { Box, Text } from "ink";
|
|
18
|
+
import stringWidth from "string-width";
|
|
19
|
+
import { parseDiff } from "./diff-model.js";
|
|
20
|
+
import { useTheme } from "./theme-context.js";
|
|
21
|
+
function defaultWidth() {
|
|
22
|
+
const cols = process.stdout?.columns;
|
|
23
|
+
return typeof cols === "number" && cols > 0 ? cols : 80;
|
|
24
|
+
}
|
|
25
|
+
export function DiffView({ diff, anchored, width }) {
|
|
26
|
+
const { theme } = useTheme();
|
|
27
|
+
const { rows } = parseDiff(diff, { anchored });
|
|
28
|
+
const totalWidth = width ?? defaultWidth();
|
|
29
|
+
const gutterWidth = anchored
|
|
30
|
+
? Math.max(0, ...rows.map((r) => (r.lineNo === null ? 0 : String(r.lineNo).length)))
|
|
31
|
+
: 0;
|
|
32
|
+
return (_jsx(Box, { flexDirection: "column", children: rows.map((row, i) => (_jsx(DiffLine, { row: row, gutterWidth: gutterWidth, width: totalWidth, theme: theme }, i))) }));
|
|
33
|
+
}
|
|
34
|
+
function DiffLine({ row, gutterWidth, width, theme, }) {
|
|
35
|
+
if (row.kind === "elision") {
|
|
36
|
+
return (_jsxs(Text, { dimColor: true, children: [" ", row.text] }));
|
|
37
|
+
}
|
|
38
|
+
const isAdd = row.kind === "add";
|
|
39
|
+
const lineBg = isAdd ? theme.diffAddedBg : theme.diffRemovedBg;
|
|
40
|
+
const wordBg = isAdd ? theme.diffAddedWordBg : theme.diffRemovedWordBg;
|
|
41
|
+
const sigil = isAdd ? "+" : "-";
|
|
42
|
+
const gutter = gutterWidth > 0 ? `${row.lineNo === null ? "" : String(row.lineNo)}`.padStart(gutterWidth) : "";
|
|
43
|
+
const prefix = gutterWidth > 0 ? `${gutter} ${sigil} ` : `${sigil} `;
|
|
44
|
+
// Build the content runs (word-level or whole-line), each with explicit bg.
|
|
45
|
+
const runs = [];
|
|
46
|
+
let consumed = stringWidth(prefix);
|
|
47
|
+
if (row.words) {
|
|
48
|
+
row.words.forEach((w, i) => {
|
|
49
|
+
runs.push(_jsx(Text, { backgroundColor: w.changed ? wordBg : lineBg, children: w.text }, i));
|
|
50
|
+
consumed += stringWidth(w.text);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
runs.push(_jsx(Text, { backgroundColor: lineBg, children: row.text }, "c"));
|
|
55
|
+
consumed += stringWidth(row.text);
|
|
56
|
+
}
|
|
57
|
+
const pad = Math.max(0, width - consumed);
|
|
58
|
+
return (_jsxs(Text, { backgroundColor: lineBg, children: [_jsx(Text, { dimColor: true, children: prefix }), runs, pad > 0 ? " ".repeat(pad) : ""] }));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=diff-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-view.js","sourceRoot":"","sources":["../src/diff-view.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAEhC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAgB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAa9C,SAAS,YAAY;IACnB,MAAM,IAAI,GAAG,OA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I,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,IAAI,CACP,KAAC,IAAI,IAAS,eAAe,EAAE,MAAM,YAClC,GAAG,CAAC,IAAI,IADD,GAAG,CAEN,CACR,CAAC;QACF,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC;IAE1C,OAAO,CACL,MAAC,IAAI,IAAC,eAAe,EAAE,MAAM,aAC3B,KAAC,IAAI,IAAC,QAAQ,kBAAE,MAAM,GAAQ,EAC7B,IAAI,EACJ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAC1B,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (5.8 / v13) Frame-coalescing scheduler.
|
|
3
|
+
*
|
|
4
|
+
* Streaming `assistant:delta` events arrive one-per-token (engine.ts emits a
|
|
5
|
+
* bump per stream chunk). Before v13 each one drove a full React re-render of
|
|
6
|
+
* the whole scrollback. The view-model now routes delta-driven re-renders
|
|
7
|
+
* through `schedule()` so at most ONE render happens per ~16 ms frame, while
|
|
8
|
+
* structural events (a finished message, a tool call/result, turn end) still
|
|
9
|
+
* flush immediately via the view-model's force-flush path (which `cancel()`s
|
|
10
|
+
* any pending frame first).
|
|
11
|
+
*
|
|
12
|
+
* The scheduler is injectable so tests run deterministically with no timers:
|
|
13
|
+
* inject {@link ManualFrameScheduler}, drive events, then `flush()` — the
|
|
14
|
+
* assertion is "N deltas → exactly one notification", which a real
|
|
15
|
+
* `setTimeout` clock can't express without flakiness.
|
|
16
|
+
*/
|
|
17
|
+
/** Opaque handle returned by {@link FrameScheduler.schedule}; pass it back to
|
|
18
|
+
* `cancel()`. Callers must not inspect it. */
|
|
19
|
+
export type FrameHandle = unknown;
|
|
20
|
+
export interface FrameScheduler {
|
|
21
|
+
/** Run `cb` on a later frame; returns a handle for {@link cancel}. */
|
|
22
|
+
schedule(cb: () => void): FrameHandle;
|
|
23
|
+
/** Cancel a scheduled `cb` if it has not run yet. Idempotent. */
|
|
24
|
+
cancel(handle: FrameHandle): void;
|
|
25
|
+
}
|
|
26
|
+
/** Default production scheduler: a single `setTimeout` per coalescing window. */
|
|
27
|
+
export declare const defaultFrameScheduler: FrameScheduler;
|
|
28
|
+
/**
|
|
29
|
+
* Deterministic scheduler for tests. `schedule()` enqueues a callback (no
|
|
30
|
+
* timer), `cancel()` removes it, `flush()` runs all queued callbacks in FIFO
|
|
31
|
+
* order and clears the queue. `pending` exposes the queue depth so a test can
|
|
32
|
+
* assert coalescing ("after N deltas, exactly one callback is queued").
|
|
33
|
+
*/
|
|
34
|
+
export declare class ManualFrameScheduler implements FrameScheduler {
|
|
35
|
+
private readonly queue;
|
|
36
|
+
private nextId;
|
|
37
|
+
schedule(cb: () => void): FrameHandle;
|
|
38
|
+
cancel(handle: FrameHandle): void;
|
|
39
|
+
/** Number of callbacks queued but not yet run or cancelled. */
|
|
40
|
+
get pending(): number;
|
|
41
|
+
/** Run every queued callback (FIFO) and clear the queue. */
|
|
42
|
+
flush(): void;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=frame-scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-scheduler.d.ts","sourceRoot":"","sources":["../src/frame-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;+CAC+C;AAC/C,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;AAElC,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC;IACtC,iEAAiE;IACjE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CACnC;AAMD,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,EAAE,cAKnC,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAK;IAEnB,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,WAAW;IAMrC,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIjC,+DAA+D;IAC/D,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,4DAA4D;IAC5D,KAAK,IAAI,IAAI;CAKd"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (5.8 / v13) Frame-coalescing scheduler.
|
|
3
|
+
*
|
|
4
|
+
* Streaming `assistant:delta` events arrive one-per-token (engine.ts emits a
|
|
5
|
+
* bump per stream chunk). Before v13 each one drove a full React re-render of
|
|
6
|
+
* the whole scrollback. The view-model now routes delta-driven re-renders
|
|
7
|
+
* through `schedule()` so at most ONE render happens per ~16 ms frame, while
|
|
8
|
+
* structural events (a finished message, a tool call/result, turn end) still
|
|
9
|
+
* flush immediately via the view-model's force-flush path (which `cancel()`s
|
|
10
|
+
* any pending frame first).
|
|
11
|
+
*
|
|
12
|
+
* The scheduler is injectable so tests run deterministically with no timers:
|
|
13
|
+
* inject {@link ManualFrameScheduler}, drive events, then `flush()` — the
|
|
14
|
+
* assertion is "N deltas → exactly one notification", which a real
|
|
15
|
+
* `setTimeout` clock can't express without flakiness.
|
|
16
|
+
*/
|
|
17
|
+
/** ~1 frame at 60fps. One coalesced render per frame is imperceptible while
|
|
18
|
+
* capping re-renders during a fast token stream. */
|
|
19
|
+
const FRAME_MS = 16;
|
|
20
|
+
/** Default production scheduler: a single `setTimeout` per coalescing window. */
|
|
21
|
+
export const defaultFrameScheduler = {
|
|
22
|
+
schedule: (cb) => setTimeout(cb, FRAME_MS),
|
|
23
|
+
cancel: (handle) => {
|
|
24
|
+
if (handle !== undefined)
|
|
25
|
+
clearTimeout(handle);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Deterministic scheduler for tests. `schedule()` enqueues a callback (no
|
|
30
|
+
* timer), `cancel()` removes it, `flush()` runs all queued callbacks in FIFO
|
|
31
|
+
* order and clears the queue. `pending` exposes the queue depth so a test can
|
|
32
|
+
* assert coalescing ("after N deltas, exactly one callback is queued").
|
|
33
|
+
*/
|
|
34
|
+
export class ManualFrameScheduler {
|
|
35
|
+
queue = new Map();
|
|
36
|
+
nextId = 1;
|
|
37
|
+
schedule(cb) {
|
|
38
|
+
const id = this.nextId++;
|
|
39
|
+
this.queue.set(id, cb);
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
cancel(handle) {
|
|
43
|
+
if (typeof handle === "number")
|
|
44
|
+
this.queue.delete(handle);
|
|
45
|
+
}
|
|
46
|
+
/** Number of callbacks queued but not yet run or cancelled. */
|
|
47
|
+
get pending() {
|
|
48
|
+
return this.queue.size;
|
|
49
|
+
}
|
|
50
|
+
/** Run every queued callback (FIFO) and clear the queue. */
|
|
51
|
+
flush() {
|
|
52
|
+
const callbacks = [...this.queue.values()];
|
|
53
|
+
this.queue.clear();
|
|
54
|
+
for (const cb of callbacks)
|
|
55
|
+
cb();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=frame-scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-scheduler.js","sourceRoot":"","sources":["../src/frame-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAaH;qDACqD;AACrD,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAmB;IACnD,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC;IAC1C,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QACjB,IAAI,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,MAAuC,CAAC,CAAC;IAClF,CAAC;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IACd,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC/C,MAAM,GAAG,CAAC,CAAC;IAEnB,QAAQ,CAAC,EAAc;QACrB,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,CAAC,MAAmB;QACxB,IAAI,OAAO,MAAM,KAAK,QAAQ;YAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED,+DAA+D;IAC/D,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,4DAA4D;IAC5D,KAAK;QACH,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,KAAK,MAAM,EAAE,IAAI,SAAS;YAAE,EAAE,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Theme } from "./theme.js";
|
|
2
|
+
/** Stable highlight scopes we color. Everything else → `"plain"` (no color). */
|
|
3
|
+
export type HlScope = "plain" | "keyword" | "string" | "comment" | "number" | "function" | "type" | "literal" | "attr";
|
|
4
|
+
export interface Segment {
|
|
5
|
+
text: string;
|
|
6
|
+
scope: HlScope;
|
|
7
|
+
}
|
|
8
|
+
/** scope → theme color role (used by views to pick the `<Text color>`). */
|
|
9
|
+
export declare const SCOPE_TO_THEME: Record<HlScope, keyof Theme | undefined>;
|
|
10
|
+
/** Resolve a user-supplied language label to a registered grammar, or null. */
|
|
11
|
+
export declare function resolveLanguage(lang: string | undefined): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Highlight `code` as `lang` into themed segments. Unknown/absent language or
|
|
14
|
+
* any highlighter error → a single `"plain"` segment with the original code
|
|
15
|
+
* (callers render it as plain text).
|
|
16
|
+
*/
|
|
17
|
+
export declare function highlightToSegments(code: string, lang: string | undefined): Segment[];
|
|
18
|
+
//# sourceMappingURL=highlight-to-segments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlight-to-segments.d.ts","sourceRoot":"","sources":["../src/highlight-to-segments.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA4ExC,gFAAgF;AAChF,MAAM,MAAM,OAAO,GACf,OAAO,GACP,SAAS,GACT,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,UAAU,GACV,MAAM,GACN,SAAS,GACT,MAAM,CAAC;AAEX,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AA6CD,2EAA2E;AAC3E,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,KAAK,GAAG,SAAS,CAUnE,CAAC;AAgBF,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAMvE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,EAAE,CAWrF"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (5.9 / v14) Terminal syntax highlighting, pi-style: drive highlight.js
|
|
3
|
+
* directly (NOT `cli-highlight`, which drags in `parse5` + `yargs` — codex R1
|
|
4
|
+
* UNVERIFIABLE-2), then map its `<span class="hljs-…">` HTML to flat, themed
|
|
5
|
+
* segments with a tiny stack scanner. Pure `(code, lang) → Segment[]`, so it is
|
|
6
|
+
* fully unit-testable without Ink and degrades to a single plain segment on
|
|
7
|
+
* unknown language / highlighter throw.
|
|
8
|
+
*
|
|
9
|
+
* Only a curated language set is registered (via `highlight.js/lib/core`) to
|
|
10
|
+
* keep the `bun build --compile` binary small.
|
|
11
|
+
*/
|
|
12
|
+
import hljs from "highlight.js/lib/core";
|
|
13
|
+
// -- curated language registration ------------------------------------------
|
|
14
|
+
import bash from "highlight.js/lib/languages/bash";
|
|
15
|
+
import c from "highlight.js/lib/languages/c";
|
|
16
|
+
import cpp from "highlight.js/lib/languages/cpp";
|
|
17
|
+
import css from "highlight.js/lib/languages/css";
|
|
18
|
+
import diff from "highlight.js/lib/languages/diff";
|
|
19
|
+
import dockerfile from "highlight.js/lib/languages/dockerfile";
|
|
20
|
+
import go from "highlight.js/lib/languages/go";
|
|
21
|
+
import java from "highlight.js/lib/languages/java";
|
|
22
|
+
import javascript from "highlight.js/lib/languages/javascript";
|
|
23
|
+
import json from "highlight.js/lib/languages/json";
|
|
24
|
+
import markdown from "highlight.js/lib/languages/markdown";
|
|
25
|
+
import python from "highlight.js/lib/languages/python";
|
|
26
|
+
import ruby from "highlight.js/lib/languages/ruby";
|
|
27
|
+
import rust from "highlight.js/lib/languages/rust";
|
|
28
|
+
import sql from "highlight.js/lib/languages/sql";
|
|
29
|
+
import toml from "highlight.js/lib/languages/ini";
|
|
30
|
+
import typescript from "highlight.js/lib/languages/typescript";
|
|
31
|
+
import xml from "highlight.js/lib/languages/xml";
|
|
32
|
+
import yaml from "highlight.js/lib/languages/yaml";
|
|
33
|
+
let registered = false;
|
|
34
|
+
function ensureRegistered() {
|
|
35
|
+
if (registered)
|
|
36
|
+
return;
|
|
37
|
+
registered = true;
|
|
38
|
+
const langs = {
|
|
39
|
+
bash,
|
|
40
|
+
c,
|
|
41
|
+
cpp,
|
|
42
|
+
css,
|
|
43
|
+
diff,
|
|
44
|
+
dockerfile,
|
|
45
|
+
go,
|
|
46
|
+
java,
|
|
47
|
+
javascript,
|
|
48
|
+
json,
|
|
49
|
+
markdown,
|
|
50
|
+
python,
|
|
51
|
+
ruby,
|
|
52
|
+
rust,
|
|
53
|
+
sql,
|
|
54
|
+
toml,
|
|
55
|
+
typescript,
|
|
56
|
+
xml,
|
|
57
|
+
yaml,
|
|
58
|
+
};
|
|
59
|
+
for (const [name, def] of Object.entries(langs))
|
|
60
|
+
hljs.registerLanguage(name, def);
|
|
61
|
+
}
|
|
62
|
+
/** Common aliases highlight.js's curated set doesn't auto-register for us. */
|
|
63
|
+
const ALIASES = {
|
|
64
|
+
ts: "typescript",
|
|
65
|
+
tsx: "typescript",
|
|
66
|
+
js: "javascript",
|
|
67
|
+
jsx: "javascript",
|
|
68
|
+
mjs: "javascript",
|
|
69
|
+
cjs: "javascript",
|
|
70
|
+
py: "python",
|
|
71
|
+
rb: "ruby",
|
|
72
|
+
rs: "rust",
|
|
73
|
+
sh: "bash",
|
|
74
|
+
shell: "bash",
|
|
75
|
+
zsh: "bash",
|
|
76
|
+
yml: "yaml",
|
|
77
|
+
html: "xml",
|
|
78
|
+
htm: "xml",
|
|
79
|
+
svg: "xml",
|
|
80
|
+
golang: "go",
|
|
81
|
+
"c++": "cpp",
|
|
82
|
+
ini: "toml",
|
|
83
|
+
dockerfile: "dockerfile",
|
|
84
|
+
md: "markdown",
|
|
85
|
+
};
|
|
86
|
+
/** hljs class (without the `hljs-` prefix) → our scope. Unmapped → "plain". */
|
|
87
|
+
function classToScope(cls) {
|
|
88
|
+
// A span class may be multi-token, e.g. "hljs-title function_"; check each.
|
|
89
|
+
const tokens = cls.split(/\s+/);
|
|
90
|
+
for (const raw of tokens) {
|
|
91
|
+
const t = raw.replace(/^hljs-/, "");
|
|
92
|
+
switch (t) {
|
|
93
|
+
case "keyword":
|
|
94
|
+
return "keyword";
|
|
95
|
+
case "string":
|
|
96
|
+
case "regexp":
|
|
97
|
+
case "char":
|
|
98
|
+
case "char.escape":
|
|
99
|
+
case "subst":
|
|
100
|
+
return "string";
|
|
101
|
+
case "comment":
|
|
102
|
+
case "quote":
|
|
103
|
+
return "comment";
|
|
104
|
+
case "number":
|
|
105
|
+
return "number";
|
|
106
|
+
case "title":
|
|
107
|
+
case "built_in":
|
|
108
|
+
return "function";
|
|
109
|
+
case "type":
|
|
110
|
+
case "class":
|
|
111
|
+
case "title.class":
|
|
112
|
+
return "type";
|
|
113
|
+
case "literal":
|
|
114
|
+
return "literal";
|
|
115
|
+
case "attr":
|
|
116
|
+
case "attribute":
|
|
117
|
+
case "property":
|
|
118
|
+
case "selector-tag":
|
|
119
|
+
case "selector-class":
|
|
120
|
+
case "name":
|
|
121
|
+
return "attr";
|
|
122
|
+
default:
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return "plain";
|
|
127
|
+
}
|
|
128
|
+
/** scope → theme color role (used by views to pick the `<Text color>`). */
|
|
129
|
+
export const SCOPE_TO_THEME = {
|
|
130
|
+
plain: undefined,
|
|
131
|
+
keyword: "synKeyword",
|
|
132
|
+
string: "synString",
|
|
133
|
+
comment: "synComment",
|
|
134
|
+
number: "synNumber",
|
|
135
|
+
function: "synFunction",
|
|
136
|
+
type: "synType",
|
|
137
|
+
literal: "synLiteral",
|
|
138
|
+
attr: "synAttr",
|
|
139
|
+
};
|
|
140
|
+
const ENTITIES = {
|
|
141
|
+
"&": "&",
|
|
142
|
+
"<": "<",
|
|
143
|
+
">": ">",
|
|
144
|
+
""": '"',
|
|
145
|
+
"'": "'",
|
|
146
|
+
"'": "'",
|
|
147
|
+
"'": "'",
|
|
148
|
+
};
|
|
149
|
+
function decodeEntities(s) {
|
|
150
|
+
return s.replace(/&(?:amp|lt|gt|quot|apos|#x27|#39);/g, (m) => ENTITIES[m] ?? m);
|
|
151
|
+
}
|
|
152
|
+
/** Resolve a user-supplied language label to a registered grammar, or null. */
|
|
153
|
+
export function resolveLanguage(lang) {
|
|
154
|
+
if (!lang)
|
|
155
|
+
return null;
|
|
156
|
+
ensureRegistered();
|
|
157
|
+
const norm = lang.trim().toLowerCase();
|
|
158
|
+
const aliased = ALIASES[norm] ?? norm;
|
|
159
|
+
return hljs.getLanguage(aliased) ? aliased : null;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Highlight `code` as `lang` into themed segments. Unknown/absent language or
|
|
163
|
+
* any highlighter error → a single `"plain"` segment with the original code
|
|
164
|
+
* (callers render it as plain text).
|
|
165
|
+
*/
|
|
166
|
+
export function highlightToSegments(code, lang) {
|
|
167
|
+
const resolved = resolveLanguage(lang);
|
|
168
|
+
if (!resolved)
|
|
169
|
+
return [{ text: code, scope: "plain" }];
|
|
170
|
+
let html;
|
|
171
|
+
try {
|
|
172
|
+
html = hljs.highlight(code, { language: resolved, ignoreIllegals: true }).value;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return [{ text: code, scope: "plain" }];
|
|
176
|
+
}
|
|
177
|
+
return scanHtml(html);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Flatten highlight.js HTML into segments. Maintains a scope stack; the
|
|
181
|
+
* innermost open span wins for the text between tags. Closing more spans than
|
|
182
|
+
* are open (defensive) is ignored.
|
|
183
|
+
*/
|
|
184
|
+
function scanHtml(html) {
|
|
185
|
+
const segs = [];
|
|
186
|
+
const stack = [];
|
|
187
|
+
// The final `(<)` alternative captures a stray `<` that starts neither a
|
|
188
|
+
// recognized span open/close — emitted as literal text so no source char is
|
|
189
|
+
// silently dropped if highlight.js ever produces unexpected markup (codex R2
|
|
190
|
+
// SHOULD-5). highlight.js escapes real `<` in source to `<`, so this only
|
|
191
|
+
// fires defensively.
|
|
192
|
+
const re = /<span class="([^"]*)">|<\/span>|([^<]+)|(<)/g;
|
|
193
|
+
const push = (raw) => {
|
|
194
|
+
const text = decodeEntities(raw);
|
|
195
|
+
if (text.length > 0)
|
|
196
|
+
segs.push({ text, scope: stack[stack.length - 1] ?? "plain" });
|
|
197
|
+
};
|
|
198
|
+
let m = re.exec(html);
|
|
199
|
+
while (m !== null) {
|
|
200
|
+
if (m[1] !== undefined)
|
|
201
|
+
stack.push(classToScope(m[1]));
|
|
202
|
+
else if (m[2] !== undefined)
|
|
203
|
+
push(m[2]);
|
|
204
|
+
else if (m[3] !== undefined)
|
|
205
|
+
push(m[3]); // stray "<"
|
|
206
|
+
else
|
|
207
|
+
stack.pop();
|
|
208
|
+
m = re.exec(html);
|
|
209
|
+
}
|
|
210
|
+
return coalesce(segs);
|
|
211
|
+
}
|
|
212
|
+
/** Merge adjacent same-scope segments so the renderer emits fewer `<Text>`. */
|
|
213
|
+
function coalesce(segs) {
|
|
214
|
+
const out = [];
|
|
215
|
+
for (const s of segs) {
|
|
216
|
+
const last = out[out.length - 1];
|
|
217
|
+
if (last && last.scope === s.scope)
|
|
218
|
+
last.text += s.text;
|
|
219
|
+
else
|
|
220
|
+
out.push({ ...s });
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=highlight-to-segments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlight-to-segments.js","sourceRoot":"","sources":["../src/highlight-to-segments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAGzC,8EAA8E;AAC9E,OAAO,IAAI,MAAM,iCAAiC,CAAC;AACnD,OAAO,CAAC,MAAM,8BAA8B,CAAC;AAC7C,OAAO,GAAG,MAAM,gCAAgC,CAAC;AACjD,OAAO,GAAG,MAAM,gCAAgC,CAAC;AACjD,OAAO,IAAI,MAAM,iCAAiC,CAAC;AACnD,OAAO,UAAU,MAAM,uCAAuC,CAAC;AAC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AAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAClD,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS;YAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACnC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS;YAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;;YAChD,KAAK,CAAC,GAAG,EAAE,CAAC;QACjB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,+EAA+E;AAC/E,SAAS,QAAQ,CAAC,IAAe;IAC/B,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK;YAAE,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC;;YACnD,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,18 @@ export { ModalController, type OpenModal } from "./modal.js";
|
|
|
7
7
|
export { ModelPicker, type PickableModel } from "./model-picker.js";
|
|
8
8
|
export { SessionPicker, type PickableSession } from "./session-picker.js";
|
|
9
9
|
export { ApiKeyPrompt } from "./api-key-prompt.js";
|
|
10
|
+
export { ThemeProvider, useTheme } from "./theme-context.js";
|
|
11
|
+
export { resolveTheme, type Theme, type ThemeSetting, GLYPHS } from "./theme.js";
|
|
12
|
+
export { Markdown } from "./markdown.js";
|
|
13
|
+
export { CodeView } from "./code-view.js";
|
|
14
|
+
export { DiffView } from "./diff-view.js";
|
|
15
|
+
export { ToolMessage } from "./tool-message.js";
|
|
16
|
+
export { Progress } from "./progress.js";
|
|
17
|
+
/** (5.9) Rendering options forwarded into the chat's `ThemeProvider`. */
|
|
18
|
+
export interface ChatRenderOptions {
|
|
19
|
+
themeSetting?: import("./theme.js").ThemeSetting;
|
|
20
|
+
syntaxHighlight?: boolean;
|
|
21
|
+
}
|
|
10
22
|
export interface ChatHandle {
|
|
11
23
|
vm: ChatViewModel;
|
|
12
24
|
waitUntilExit: () => Promise<void>;
|
|
@@ -20,5 +32,5 @@ export interface ChatHandle {
|
|
|
20
32
|
* `modal` is the controller slash commands use to open pickers; pass the
|
|
21
33
|
* same instance to `dispatchSlash(name, args, { openModal: modal.open })`.
|
|
22
34
|
*/
|
|
23
|
-
export declare function renderChat(vm: ChatViewModel, onSubmit: (prompt: string) => Promise<void>, onSlash?: (line: string) => Promise<void>, modal?: ModalController, availableSlashCommands?: import("./app.js").SlashSuggestion[], availableResources?: import("./app.js").ResourceSuggestion[]): ChatHandle;
|
|
35
|
+
export declare function renderChat(vm: ChatViewModel, onSubmit: (prompt: string) => Promise<void>, onSlash?: (line: string) => Promise<void>, modal?: ModalController, availableSlashCommands?: import("./app.js").SlashSuggestion[], availableResources?: import("./app.js").ResourceSuggestion[], options?: ChatRenderOptions): ChatHandle;
|
|
24
36
|
//# sourceMappingURL=index.d.ts.map
|