@chances-ai/ui-core 17.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/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/event-bus.d.ts +48 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +50 -0
- package/dist/event-bus.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 +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/theme.d.ts +113 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +117 -0
- package/dist/theme.js.map +1 -0
- package/dist/tool-line.d.ts +38 -0
- package/dist/tool-line.d.ts.map +1 -0
- package/dist/tool-line.js +172 -0
- package/dist/tool-line.js.map +1 -0
- package/dist/view-model.d.ts +233 -0
- package/dist/view-model.d.ts.map +1 -0
- package/dist/view-model.js +491 -0
- package/dist/view-model.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
/** Threshold above which a remove/add pair renders as whole-line (not word-level).
|
|
21
|
+
* Matches claude-code `StructuredDiff/Fallback.tsx` `CHANGE_THRESHOLD`. */
|
|
22
|
+
export declare const CHANGE_THRESHOLD = 0.4;
|
|
23
|
+
export interface WordSeg {
|
|
24
|
+
text: string;
|
|
25
|
+
/** True ⇒ this word was added (on an add row) or removed (on a remove row). */
|
|
26
|
+
changed: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface DiffRow {
|
|
29
|
+
kind: "add" | "remove" | "elision";
|
|
30
|
+
/** Code content with the `+`/`-`/space sigil stripped (the raw elision text
|
|
31
|
+
* for `kind:"elision"`). */
|
|
32
|
+
text: string;
|
|
33
|
+
/** Assigned line number, or null when unanchored (edit) or an elision row. */
|
|
34
|
+
lineNo: number | null;
|
|
35
|
+
/** Word-level segments when this row is part of a sub-threshold pair; null ⇒
|
|
36
|
+
* render the whole line with the line background. */
|
|
37
|
+
words: WordSeg[] | null;
|
|
38
|
+
}
|
|
39
|
+
export interface ParsedDiff {
|
|
40
|
+
rows: DiffRow[];
|
|
41
|
+
/** The hunk's old start line (1-based) parsed from the `@@` header, or null. */
|
|
42
|
+
startLine: number | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Detect whether a text block is a renderable diff (the non-diff guard, 5.9 §3):
|
|
46
|
+
* true only when it contains a `@@ -d +d @@` hunk header.
|
|
47
|
+
*/
|
|
48
|
+
export declare function looksLikeDiff(text: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Parse a `linesDiff` block. `anchored` (write=true, edit=false) controls
|
|
51
|
+
* whether line numbers are assigned. Returns rows in source order with
|
|
52
|
+
* word-level segments computed for sub-threshold remove/add pairs.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseDiff(text: string, opts: {
|
|
55
|
+
anchored: boolean;
|
|
56
|
+
}): ParsedDiff;
|
|
57
|
+
/**
|
|
58
|
+
* Word-level segments for one side of a pair. `side:"remove"` keeps common +
|
|
59
|
+
* removed words; `side:"add"` keeps common + added words. Returns null when the
|
|
60
|
+
* pair changed more than {@link CHANGE_THRESHOLD} of its total length (render
|
|
61
|
+
* whole-line instead).
|
|
62
|
+
*/
|
|
63
|
+
export declare function wordSegs(removeText: string, addText: string, side: "add" | "remove"): WordSeg[] | null;
|
|
64
|
+
//# sourceMappingURL=diff-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-model.d.ts","sourceRoot":"","sources":["../src/diff-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;4EAC4E;AAC5E,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;IACnC;iCAC6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;0DACsD;IACtD,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,gFAAgF;IAChF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAQD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAOD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,UAAU,CAuB/E;AAqED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAiBtG"}
|
|
@@ -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;QACzB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI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,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (v17 M1 / docs/6.1 §4) A browser-safe `AppEvent` pub/sub for the shared UI
|
|
3
|
+
* tier. `ChatViewModel.attach` consumes events through the structural
|
|
4
|
+
* {@link AppEventBus} interface (not the engine's nominal `EventBus` class), so
|
|
5
|
+
* BOTH inputs satisfy it:
|
|
6
|
+
* - the TUI passes the engine's `@chances-ai/runtime` `EventBus` (in-process,
|
|
7
|
+
* the engine emits straight onto it), and
|
|
8
|
+
* - the web/desktop client builds a {@link LocalEventBus} and emits AppEvents
|
|
9
|
+
* reverse-mapped from the wire (`client-core`).
|
|
10
|
+
*
|
|
11
|
+
* Why a second bus instead of importing the engine's: the engine's `EventBus`
|
|
12
|
+
* has `private` fields, so TS types it NOMINALLY — only a real instance is
|
|
13
|
+
* assignable to it, which would force the browser client to value-import
|
|
14
|
+
* `@chances-ai/runtime` (dragging node-bound modules into the bundle). Keeping
|
|
15
|
+
* `attach`'s parameter a structural interface lets the client supply this
|
|
16
|
+
* 15-line, dependency-free implementation and stay genuinely browser-safe (the
|
|
17
|
+
* established "type-only runtime" rule for this tier). The two buses are unified
|
|
18
|
+
* by {@link AppEventBus}; there is no logic to drift.
|
|
19
|
+
*/
|
|
20
|
+
import type { AppEvent, AppEventType } from "@chances-ai/runtime";
|
|
21
|
+
/** An AppEvent of a specific discriminant. */
|
|
22
|
+
type EventOf<T extends AppEventType> = Extract<AppEvent, {
|
|
23
|
+
type: T;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* The structural subset of an event bus `ChatViewModel.attach` needs: typed,
|
|
27
|
+
* per-discriminant subscription returning an unsubscribe. The engine's
|
|
28
|
+
* `EventBus` (more methods: `onAny`, `emit`) is assignable to this; so is
|
|
29
|
+
* {@link LocalEventBus}.
|
|
30
|
+
*/
|
|
31
|
+
export interface AppEventBus {
|
|
32
|
+
on<T extends AppEventType>(type: T, handler: (event: EventOf<T>) => void): () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A minimal, browser-safe {@link AppEventBus}. Structurally identical to the
|
|
36
|
+
* engine's `EventBus` (intentionally — it is the SAME 15-line primitive, not a
|
|
37
|
+
* fork of any logic) but with zero dependencies, so the web/desktop client can
|
|
38
|
+
* own one without importing the engine runtime.
|
|
39
|
+
*/
|
|
40
|
+
export declare class LocalEventBus implements AppEventBus {
|
|
41
|
+
private readonly handlers;
|
|
42
|
+
private readonly anyHandlers;
|
|
43
|
+
on<T extends AppEventType>(type: T, handler: (event: EventOf<T>) => void): () => void;
|
|
44
|
+
onAny(handler: (event: AppEvent) => void): () => void;
|
|
45
|
+
emit(event: AppEvent): void;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=event-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAElE,8CAA8C;AAC9C,KAAK,OAAO,CAAC,CAAC,SAAS,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,CAAC,SAAS,YAAY,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACvF;AAED;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuD;IAChF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;IAEhE,EAAE,CAAC,CAAC,SAAS,YAAY,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAWrF,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,MAAM,IAAI;IAKrD,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAI5B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (v17 M1 / docs/6.1 §4) A browser-safe `AppEvent` pub/sub for the shared UI
|
|
3
|
+
* tier. `ChatViewModel.attach` consumes events through the structural
|
|
4
|
+
* {@link AppEventBus} interface (not the engine's nominal `EventBus` class), so
|
|
5
|
+
* BOTH inputs satisfy it:
|
|
6
|
+
* - the TUI passes the engine's `@chances-ai/runtime` `EventBus` (in-process,
|
|
7
|
+
* the engine emits straight onto it), and
|
|
8
|
+
* - the web/desktop client builds a {@link LocalEventBus} and emits AppEvents
|
|
9
|
+
* reverse-mapped from the wire (`client-core`).
|
|
10
|
+
*
|
|
11
|
+
* Why a second bus instead of importing the engine's: the engine's `EventBus`
|
|
12
|
+
* has `private` fields, so TS types it NOMINALLY — only a real instance is
|
|
13
|
+
* assignable to it, which would force the browser client to value-import
|
|
14
|
+
* `@chances-ai/runtime` (dragging node-bound modules into the bundle). Keeping
|
|
15
|
+
* `attach`'s parameter a structural interface lets the client supply this
|
|
16
|
+
* 15-line, dependency-free implementation and stay genuinely browser-safe (the
|
|
17
|
+
* established "type-only runtime" rule for this tier). The two buses are unified
|
|
18
|
+
* by {@link AppEventBus}; there is no logic to drift.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* A minimal, browser-safe {@link AppEventBus}. Structurally identical to the
|
|
22
|
+
* engine's `EventBus` (intentionally — it is the SAME 15-line primitive, not a
|
|
23
|
+
* fork of any logic) but with zero dependencies, so the web/desktop client can
|
|
24
|
+
* own one without importing the engine runtime.
|
|
25
|
+
*/
|
|
26
|
+
export class LocalEventBus {
|
|
27
|
+
handlers = new Map();
|
|
28
|
+
anyHandlers = new Set();
|
|
29
|
+
on(type, handler) {
|
|
30
|
+
let set = this.handlers.get(type);
|
|
31
|
+
if (!set) {
|
|
32
|
+
set = new Set();
|
|
33
|
+
this.handlers.set(type, set);
|
|
34
|
+
}
|
|
35
|
+
const wrapped = handler;
|
|
36
|
+
set.add(wrapped);
|
|
37
|
+
return () => set.delete(wrapped);
|
|
38
|
+
}
|
|
39
|
+
onAny(handler) {
|
|
40
|
+
this.anyHandlers.add(handler);
|
|
41
|
+
return () => this.anyHandlers.delete(handler);
|
|
42
|
+
}
|
|
43
|
+
emit(event) {
|
|
44
|
+
for (const handler of this.handlers.get(event.type) ?? [])
|
|
45
|
+
handler(event);
|
|
46
|
+
for (const handler of this.anyHandlers)
|
|
47
|
+
handler(event);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=event-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAiBH;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACP,QAAQ,GAAG,IAAI,GAAG,EAA4C,CAAC;IAC/D,WAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEhE,EAAE,CAAyB,IAAO,EAAE,OAAoC;QACtE,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC/B,CAAC;QACD,MAAM,OAAO,GAAG,OAAgC,CAAC;QACjD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACjB,OAAO,GAAG,EAAE,CAAC,GAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAkC;QACtC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,CAAC,KAAe;QAClB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1E,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -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"}
|