@ai-matrx/chat 0.7.2 → 0.7.4
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 +16 -0
- package/dist/agents/addressing/agentAddress.d.ts +8 -0
- package/dist/agents/addressing/agentAddress.js +1 -0
- package/dist/agents/addressing/useAgentHref.js +8 -1
- package/dist/agents/components/conversation-history/ConversationHistorySidebar.d.ts +7 -0
- package/dist/agents/components/conversation-history/ConversationHistorySidebar.js +13 -7
- package/dist/agents/components/shared/assistant-message-layout.d.ts +21 -0
- package/dist/agents/components/shared/assistant-message-layout.js +6 -0
- package/dist/agents/hooks/useCreatorOwnershipSync.js +3 -1
- package/dist/agents/redux/conversation-history/thunks.js +2 -1
- package/dist/agents/redux/execution-system/instance-resources/rendered-artifact-draft.d.ts +23 -0
- package/dist/agents/redux/execution-system/instance-resources/rendered-artifact-draft.js +100 -0
- package/dist/agents/redux/execution-system/instance-user-input/composer-draft.middleware.js +9 -0
- package/dist/agents/redux/execution-system/instance-user-input/useComposerDraftRestore.js +3 -1
- package/dist/agents/redux/execution-system/thunks/execute-instance.thunk.js +1 -1
- package/dist/agents/redux/execution-system/thunks/execute-manual-instance.thunk.js +1 -1
- package/dist/agents/redux/execution-system/thunks/frozen-submission.d.ts +5 -0
- package/dist/agents/redux/execution-system/thunks/frozen-submission.js +2 -1
- package/dist/agents/redux/execution-system/utils/content-prefilter.d.ts +50 -0
- package/dist/agents/redux/execution-system/utils/content-prefilter.js +243 -0
- package/dist/agents/redux/execution-system/utils/stream-block-accumulator.d.ts +335 -65
- package/dist/agents/redux/execution-system/utils/stream-block-accumulator.js +1909 -224
- package/dist/agents/ui-first-tools/ui/PendingAsksZone.js +4 -4
- package/dist/conversation/hooks/useDomCapturePrint.js +13 -2
- package/dist/conversation/utils/frame-print.js +20 -2
- package/dist/conversation/utils/isolate-for-capture.d.ts +19 -0
- package/dist/conversation/utils/isolate-for-capture.js +55 -0
- package/dist/host/admin-seat.d.ts +19 -0
- package/dist/host/admin-seat.js +8 -0
- package/dist/tool-call-visualization/renderers/agent-call/AgentCallInline.js +6 -3
- package/dist/ui/markdown-stream/EnhancedChatMarkdown.js +5 -1
- package/package.json +5 -5
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { OUR_FILE_URL_MARKERS } from "@ai-matrx/media/files/engine";
|
|
2
|
+
const Candidate = {
|
|
3
|
+
NONE: 0,
|
|
4
|
+
TEXT: 0,
|
|
5
|
+
// No special block detected — plain text
|
|
6
|
+
CODE: 1 << 0,
|
|
7
|
+
// ``` or ~~~ fenced code block
|
|
8
|
+
XML_SIMPLE: 1 << 1,
|
|
9
|
+
// <thinking>, <flashcards>, etc.
|
|
10
|
+
XML_ATTR: 1 << 2,
|
|
11
|
+
// <decision prompt="...">, <artifact ...>
|
|
12
|
+
TABLE: 1 << 3,
|
|
13
|
+
// | col | col |
|
|
14
|
+
IMAGE: 1 << 4,
|
|
15
|
+
//  or [Image URL: ...]
|
|
16
|
+
VIDEO: 1 << 5,
|
|
17
|
+
// [Video URL: ...]
|
|
18
|
+
DIVIDER: 1 << 7,
|
|
19
|
+
// *** or # ===
|
|
20
|
+
TREE: 1 << 8,
|
|
21
|
+
// Box-drawing / ASCII tree characters
|
|
22
|
+
BARE_JSON: 1 << 9,
|
|
23
|
+
// { "key": ... } JSON object without code fences
|
|
24
|
+
AUDIO: 1 << 10,
|
|
25
|
+
// [Audio URL: ...] or a standalone …/clip.mp3 link
|
|
26
|
+
MATRX_FILE: 1 << 11
|
|
27
|
+
// link/URL to one of OUR files (signed S3 / CDN / public / share)
|
|
28
|
+
};
|
|
29
|
+
const AUDIO_EXT_RE = /\.(mp3|wav|m4a|aac|ogg|oga|opus|flac|weba|webm)(\?[^\s)]*)?$/i;
|
|
30
|
+
function isStandaloneAudioLink(trimmed) {
|
|
31
|
+
const link = trimmed.match(/^!?\[.*?\]\((https?:\/\/[^\s)]+)\)$/);
|
|
32
|
+
if (link) return AUDIO_EXT_RE.test(link[1]);
|
|
33
|
+
if (/^https?:\/\/[^\s)]+$/.test(trimmed)) return AUDIO_EXT_RE.test(trimmed);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function mightBeOurFile(trimmed) {
|
|
37
|
+
const markers = OUR_FILE_URL_MARKERS;
|
|
38
|
+
for (let mi = 0; mi < markers.length; mi++) {
|
|
39
|
+
if (trimmed.includes(markers[mi])) return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const SIMPLE_XML_TAGS = /* @__PURE__ */ new Set([
|
|
44
|
+
"thinking",
|
|
45
|
+
"think",
|
|
46
|
+
"reasoning",
|
|
47
|
+
"info",
|
|
48
|
+
"task",
|
|
49
|
+
"database",
|
|
50
|
+
"private",
|
|
51
|
+
"plan",
|
|
52
|
+
"event",
|
|
53
|
+
"tool",
|
|
54
|
+
"questionnaire",
|
|
55
|
+
"flashcards",
|
|
56
|
+
"cooking_recipe",
|
|
57
|
+
"timeline",
|
|
58
|
+
"progress_tracker",
|
|
59
|
+
"troubleshooting",
|
|
60
|
+
"resources",
|
|
61
|
+
"research"
|
|
62
|
+
]);
|
|
63
|
+
const ATTR_XML_TAGS = /* @__PURE__ */ new Set([
|
|
64
|
+
"decision",
|
|
65
|
+
"artifact",
|
|
66
|
+
// Editor pill tags — carry attributes (file, line, severity, language, …)
|
|
67
|
+
// so they're classified as ATTR. The chat-markdown renderer parses them
|
|
68
|
+
// back into chips on load.
|
|
69
|
+
"editor_error",
|
|
70
|
+
"editor_code_snippet"
|
|
71
|
+
]);
|
|
72
|
+
const ALL_XML_TAGS = /* @__PURE__ */ new Set([...SIMPLE_XML_TAGS, ...ATTR_XML_TAGS]);
|
|
73
|
+
const TREE_CHARS = /* @__PURE__ */ new Set([
|
|
74
|
+
"\u251C",
|
|
75
|
+
"\u2514",
|
|
76
|
+
"\u2502",
|
|
77
|
+
"\u250C",
|
|
78
|
+
"\u2510",
|
|
79
|
+
"\u2518",
|
|
80
|
+
"\u252C",
|
|
81
|
+
"\u2534",
|
|
82
|
+
"\u2524",
|
|
83
|
+
"\u253C",
|
|
84
|
+
"\u2500"
|
|
85
|
+
]);
|
|
86
|
+
function classifyLine(line, trimmed) {
|
|
87
|
+
let flags = Candidate.NONE;
|
|
88
|
+
const len = trimmed.length;
|
|
89
|
+
if (len === 0) return flags;
|
|
90
|
+
const first = trimmed[0];
|
|
91
|
+
if (first === "`" || first === "~") {
|
|
92
|
+
if (len >= 3 && trimmed[1] === first && trimmed[2] === first) {
|
|
93
|
+
flags |= Candidate.CODE;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (first === "{") {
|
|
97
|
+
flags |= Candidate.BARE_JSON;
|
|
98
|
+
}
|
|
99
|
+
if (first === "|") {
|
|
100
|
+
if (trimmed.indexOf("|", 1) !== -1) {
|
|
101
|
+
flags |= Candidate.TABLE;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (first === "!" && len >= 2 && trimmed[1] === "[") {
|
|
105
|
+
flags |= Candidate.IMAGE;
|
|
106
|
+
}
|
|
107
|
+
if (first === "*" || first === "#") {
|
|
108
|
+
if (first === "*") {
|
|
109
|
+
if (isStarDivider(trimmed)) {
|
|
110
|
+
flags |= Candidate.DIVIDER;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
if (len >= 4 && trimmed.indexOf("=") !== -1) {
|
|
114
|
+
flags |= Candidate.DIVIDER;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (TREE_CHARS.has(first)) {
|
|
119
|
+
flags |= Candidate.TREE;
|
|
120
|
+
}
|
|
121
|
+
let searchFrom = 0;
|
|
122
|
+
while (searchFrom < len) {
|
|
123
|
+
const ltPos = trimmed.indexOf("<", searchFrom);
|
|
124
|
+
if (ltPos === -1) break;
|
|
125
|
+
if (ltPos + 2 < len && trimmed[ltPos + 1] === "<" && trimmed[ltPos + 2] === "<") {
|
|
126
|
+
searchFrom = ltPos + 3;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (ltPos + 1 < len) {
|
|
130
|
+
const next = trimmed[ltPos + 1];
|
|
131
|
+
if (isLetter(next)) {
|
|
132
|
+
const tagName = extractTagName(trimmed, ltPos + 1);
|
|
133
|
+
if (tagName) {
|
|
134
|
+
if (SIMPLE_XML_TAGS.has(tagName)) {
|
|
135
|
+
flags |= Candidate.XML_SIMPLE;
|
|
136
|
+
}
|
|
137
|
+
if (ATTR_XML_TAGS.has(tagName)) {
|
|
138
|
+
flags |= Candidate.XML_ATTR;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
searchFrom = ltPos + 1;
|
|
144
|
+
}
|
|
145
|
+
if (!(flags & Candidate.IMAGE) || !(flags & Candidate.VIDEO) || !(flags & Candidate.AUDIO)) {
|
|
146
|
+
const bracketIdx = trimmed.indexOf("[");
|
|
147
|
+
if (bracketIdx !== -1) {
|
|
148
|
+
if (bracketIdx + 10 < len) {
|
|
149
|
+
const after = trimmed[bracketIdx + 1];
|
|
150
|
+
if (after === "I" && trimmed.substring(bracketIdx + 1, bracketIdx + 11) === "Image URL:") {
|
|
151
|
+
flags |= Candidate.IMAGE;
|
|
152
|
+
} else if (after === "V" && trimmed.substring(bracketIdx + 1, bracketIdx + 11) === "Video URL:") {
|
|
153
|
+
flags |= Candidate.VIDEO;
|
|
154
|
+
} else if (after === "A" && trimmed.substring(bracketIdx + 1, bracketIdx + 11) === "Audio URL:") {
|
|
155
|
+
flags |= Candidate.AUDIO;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!(flags & Candidate.AUDIO) && (first === "[" || first === "!" || first === "h") && isStandaloneAudioLink(trimmed)) {
|
|
161
|
+
flags |= Candidate.AUDIO;
|
|
162
|
+
}
|
|
163
|
+
if (!(flags & Candidate.TABLE) && first !== "|") {
|
|
164
|
+
if (trimmed.indexOf("|") !== -1) {
|
|
165
|
+
const firstPipe = trimmed.indexOf("|");
|
|
166
|
+
if (firstPipe !== -1 && trimmed.indexOf("|", firstPipe + 1) !== -1) {
|
|
167
|
+
flags |= Candidate.TABLE;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!(flags & Candidate.TREE)) {
|
|
172
|
+
for (let ci = 1; ci < len; ci++) {
|
|
173
|
+
if (TREE_CHARS.has(trimmed[ci])) {
|
|
174
|
+
flags |= Candidate.TREE;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (!(flags & Candidate.TREE) && (first === " " || first === " " || first === "\u2502" || first === "|" || first === "+")) {
|
|
180
|
+
if (looksLikeAsciiTree(trimmed)) {
|
|
181
|
+
flags |= Candidate.TREE;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!(flags & Candidate.MATRX_FILE) && mightBeOurFile(trimmed)) {
|
|
185
|
+
flags |= Candidate.MATRX_FILE;
|
|
186
|
+
}
|
|
187
|
+
return flags;
|
|
188
|
+
}
|
|
189
|
+
function isLetter(ch) {
|
|
190
|
+
const c = ch.charCodeAt(0);
|
|
191
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
192
|
+
}
|
|
193
|
+
function extractTagName(str, start) {
|
|
194
|
+
let end = start;
|
|
195
|
+
while (end < str.length) {
|
|
196
|
+
const c = str.charCodeAt(end);
|
|
197
|
+
if (c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 95) {
|
|
198
|
+
end++;
|
|
199
|
+
} else {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (end === start) return null;
|
|
204
|
+
return str.substring(start, end).toLowerCase();
|
|
205
|
+
}
|
|
206
|
+
function isStarDivider(trimmed) {
|
|
207
|
+
let starCount = 0;
|
|
208
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
209
|
+
const ch = trimmed[i];
|
|
210
|
+
if (ch === "*") {
|
|
211
|
+
starCount++;
|
|
212
|
+
} else if (ch !== " ") {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return starCount >= 3;
|
|
217
|
+
}
|
|
218
|
+
function looksLikeAsciiTree(trimmed) {
|
|
219
|
+
let i = 0;
|
|
220
|
+
while (i < trimmed.length) {
|
|
221
|
+
const ch2 = trimmed[i];
|
|
222
|
+
if (ch2 === " " || ch2 === " " || ch2 === "\u2502" || ch2 === "|") {
|
|
223
|
+
i++;
|
|
224
|
+
} else {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (i >= trimmed.length) return false;
|
|
229
|
+
const ch = trimmed[i];
|
|
230
|
+
return ch === "\u251C" || ch === "\u2514" || ch === "+";
|
|
231
|
+
}
|
|
232
|
+
function isPlainText(flags) {
|
|
233
|
+
return flags === Candidate.NONE;
|
|
234
|
+
}
|
|
235
|
+
function hasCandidate(flags, candidate) {
|
|
236
|
+
return (flags & candidate) !== 0;
|
|
237
|
+
}
|
|
238
|
+
export {
|
|
239
|
+
Candidate,
|
|
240
|
+
classifyLine,
|
|
241
|
+
hasCandidate,
|
|
242
|
+
isPlainText
|
|
243
|
+
};
|
|
@@ -1,87 +1,357 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* StreamBlockAccumulator —
|
|
2
|
+
* StreamBlockAccumulator — Incremental block detection for streaming text.
|
|
3
3
|
*
|
|
4
|
-
* Sits inside the processStream() closure and ingests rAF-batched text
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* always draw the same blocks).
|
|
4
|
+
* Sits inside the processStream() closure and ingests rAF-batched text
|
|
5
|
+
* deltas. For each delta it runs the cheap content-prefilter (classifyLine)
|
|
6
|
+
* to detect block boundaries and emits upsertRenderBlock dispatches so
|
|
7
|
+
* Redux stores typed RenderBlockPayloads incrementally.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - tool boundaries (`breakTextBlock`): each text run is split on its own, as reload splits
|
|
17
|
-
* each run's stored text;
|
|
18
|
-
* - provider-retry rewind and the reasoning-boundary diagnostics.
|
|
9
|
+
* 97% of lines are plain text — they append to the current text block
|
|
10
|
+
* with zero regex or parsing. The remaining 3% trigger boundary
|
|
11
|
+
* transitions (code fences, XML tags, tables, images, etc.).
|
|
12
|
+
*
|
|
13
|
+
* Key constraint: each character is processed exactly once. The
|
|
14
|
+
* accumulator never re-reads completed blocks.
|
|
19
15
|
*/
|
|
20
16
|
import type { RenderBlockPayload } from "@ai-matrx/agents/generated/stream-events";
|
|
21
17
|
type DispatchFn = (action: unknown) => unknown;
|
|
22
|
-
type UpsertAction = (payload: {
|
|
23
|
-
requestId: string;
|
|
24
|
-
block: RenderBlockPayload;
|
|
25
|
-
}) => unknown;
|
|
26
18
|
export declare class StreamBlockAccumulator {
|
|
27
|
-
private
|
|
28
|
-
private
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
|
|
19
|
+
private requestId;
|
|
20
|
+
private currentBlockIndex;
|
|
21
|
+
private currentBlockType;
|
|
22
|
+
private currentBlockContent;
|
|
23
|
+
/**
|
|
24
|
+
* Number of lines appended to the current block. Used to preserve LEADING
|
|
25
|
+
* blank lines: the first appended line is written verbatim (even if it's an
|
|
26
|
+
* empty string), and every subsequent line is joined with "\n". Without this
|
|
27
|
+
* counter, appending "" to an empty `currentBlockContent` was a no-op, which
|
|
28
|
+
* silently swallowed a block's first blank line and produced a 1-byte drift
|
|
29
|
+
* vs the V2 splitter / Python server (which keep that blank line).
|
|
30
|
+
*/
|
|
31
|
+
private currentBlockLineCount;
|
|
32
|
+
private pendingLineFragment;
|
|
33
|
+
/**
|
|
34
|
+
* True once the block at the current index has been dispatched to Redux —
|
|
35
|
+
* including speculative streaming projections of `pendingLineFragment`
|
|
36
|
+
* (see `emitCurrentBlock`). Reset whenever a new block is opened. Used by
|
|
37
|
+
* `closeCurrentBlock` to retract a speculative block whose line turned out
|
|
38
|
+
* to be a different typed block (see the bare-JSON duplication note there).
|
|
39
|
+
*/
|
|
40
|
+
private currentBlockEmitted;
|
|
41
|
+
/**
|
|
42
|
+
* THE DATA KEEPS ITS KINDS. A JSON wrapper that holds kinds is drawn as its
|
|
43
|
+
* kinds plus a residual (A7) — the residual is the wrapper's data WITH ITS
|
|
44
|
+
* KINDS REMOVED, so it is a display projection, never the answer. Every
|
|
45
|
+
* such split remembers the bytes it was cut from, keyed by its first block
|
|
46
|
+
* index, so data capture (`deriveAnswerDataText`) reads what the model wrote.
|
|
47
|
+
* Live only; a rewind forgets every split at or past its boundary.
|
|
48
|
+
*/
|
|
49
|
+
private wrapperSplits;
|
|
50
|
+
private subState;
|
|
51
|
+
/**
|
|
52
|
+
* URL + label for the current `audio` block. The accumulator's single-line
|
|
53
|
+
* media blocks (image/video) leave `data` null, which is why the legacy
|
|
54
|
+
* client image/video markdown path never populated `src`. Audio MUST carry
|
|
55
|
+
* its URL on `data.src` or BlockRenderer's `audio` case renders nothing —
|
|
56
|
+
* so we stash the extracted link here and emit it via buildBlockData.
|
|
57
|
+
*/
|
|
58
|
+
private pendingMediaData;
|
|
59
|
+
private ingestCount;
|
|
60
|
+
private emitCount;
|
|
61
|
+
/** Live kind-parser session for the OPEN JSON region (fence or bare). */
|
|
62
|
+
private irSession;
|
|
63
|
+
/** Lines fed to the session for this region (drives the "\n" separators). */
|
|
64
|
+
private irRegionLineCount;
|
|
65
|
+
/** How many chars of the current pendingLineFragment were already fed. */
|
|
66
|
+
private irFedFragmentLen;
|
|
67
|
+
/** Final envelope of the region being closed — consumed by the complete emit. */
|
|
68
|
+
private irEnvelope;
|
|
69
|
+
/**
|
|
70
|
+
* True only between seeing a LITERAL closing fence line and the block's
|
|
71
|
+
* emit (set in the code_fence close branch). Stream-death finalize never
|
|
72
|
+
* sets it, so the fence-surface convergence hook fires exclusively on
|
|
73
|
+
* genuinely completed fence regions.
|
|
74
|
+
*/
|
|
75
|
+
private fenceClosedCleanly;
|
|
76
|
+
/**
|
|
77
|
+
* True once a simple-XML region's LITERAL closing tag has been seen — the twin
|
|
78
|
+
* of `fenceClosedCleanly`. Never set by stream-death `finalize()`, so a
|
|
79
|
+
* truncated region keeps today's legacy rendering (no envelope).
|
|
80
|
+
*
|
|
81
|
+
* MUST NOT be re-derived by scanning `currentBlockContent` for the closing
|
|
82
|
+
* tag: the accumulator STRIPS the literal tag text out of a simple-XML
|
|
83
|
+
* block's content (so `</reasoning>` can't leak into visible chat), which
|
|
84
|
+
* silently killed the XML keystone once already. The state machine already
|
|
85
|
+
* knows when the region closed; ask it, don't re-parse its output.
|
|
86
|
+
*/
|
|
87
|
+
private xmlClosedCleanly;
|
|
88
|
+
/**
|
|
89
|
+
* True while the OPEN ir region is the JSON BODY of an attribute-XML block
|
|
90
|
+
* (`<artifact …>{"__kind":…}</artifact>`) rather than a block that IS the
|
|
91
|
+
* JSON region. Two consequences, both required:
|
|
92
|
+
*
|
|
93
|
+
* - the parity check is skipped — it compares the envelope against
|
|
94
|
+
* `JSON.parse(currentBlockContent)`, and an attr-XML block's content is
|
|
95
|
+
* the tag chrome PLUS the body, which never parses as JSON. Without this
|
|
96
|
+
* every wrapped payload would fire a false "stream parity" alarm.
|
|
97
|
+
* - the fragment feed stays off the closing-tag line (see `ingest`).
|
|
98
|
+
*/
|
|
99
|
+
private irRegionIsXmlBody;
|
|
100
|
+
/** Every session identity opened during this stream (disposed at finalize). */
|
|
101
|
+
private irIdentities;
|
|
102
|
+
/**
|
|
103
|
+
* True only for the closeCurrentBlock call that closes the FIRST HALF of a
|
|
104
|
+
* region split by a tool boundary (breakTextBlock keeps the region open in
|
|
105
|
+
* a fresh block). Metadata built during that close must not report
|
|
106
|
+
* `isComplete: true` — the region genuinely continues.
|
|
107
|
+
*/
|
|
108
|
+
private regionContinuesAfterClose;
|
|
109
|
+
private upsertAction;
|
|
110
|
+
/** Same-line remainders are queued, never recursively reclassified. */
|
|
111
|
+
private lineQueue;
|
|
112
|
+
/**
|
|
113
|
+
* The current line held a kind object that broke into prose
|
|
114
|
+
* (`{"__kind":"note","title":"Hi" and then…`, L-4 round 9): it is prose to
|
|
115
|
+
* its end — no opener re-reads it as JSON — and the prose leaf reads the
|
|
116
|
+
* broken object as its one-line label, exactly as a reload does.
|
|
117
|
+
*/
|
|
118
|
+
private kindLineIsProse;
|
|
119
|
+
private isProcessingLineQueue;
|
|
120
|
+
/** Incomplete generic XML must never promote embedded JSON on finalize. */
|
|
121
|
+
private genericXmlRecoverySuppressed;
|
|
122
|
+
/**
|
|
123
|
+
* The unused text slot opened after a clean container close is omitted.
|
|
124
|
+
*
|
|
125
|
+
* A completed bare JSON root opens a fresh text slot so subsequent source
|
|
126
|
+
* can continue in document order. If the stream ends there, emitting that
|
|
127
|
+
* slot creates a second, empty terminal block after the actual answer.
|
|
128
|
+
*/
|
|
129
|
+
private suppressEmptyTrailingSlot;
|
|
130
|
+
/** Lifts JSON regions out of blockquotes before the line machine (V1). */
|
|
131
|
+
private quoteLift;
|
|
132
|
+
/** Un-escapes a markdown-escaped kind (`"\_\_kind"`) before the quote lift (P8). */
|
|
133
|
+
private kindUnescape;
|
|
134
|
+
/** Drops the `` wrapper of a kind written as image alt text (P9). */
|
|
135
|
+
private imageAlt;
|
|
136
|
+
constructor(requestId: string, upsertAction: (payload: {
|
|
137
|
+
requestId: string;
|
|
138
|
+
block: RenderBlockPayload;
|
|
139
|
+
}) => unknown);
|
|
140
|
+
/**
|
|
141
|
+
* Ingest a text delta (the rAF-batched textBuffer content).
|
|
142
|
+
* Processes only complete lines; the trailing fragment is held until the
|
|
143
|
+
* next call or finalize().
|
|
144
|
+
*/
|
|
43
145
|
ingest(delta: string, dispatch: DispatchFn): void;
|
|
44
|
-
/**
|
|
146
|
+
/** Release what the quote lift still holds (stream end or a hard boundary). */
|
|
147
|
+
private flushQuoteLift;
|
|
148
|
+
private ingestText;
|
|
149
|
+
/**
|
|
150
|
+
* Flush remaining content and mark the final block as complete.
|
|
151
|
+
* Called once after the stream loop ends.
|
|
152
|
+
*/
|
|
45
153
|
finalize(dispatch: DispatchFn): void;
|
|
46
154
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
155
|
+
* Forget every in-flight parser/block byte at and after a durable content
|
|
156
|
+
* boundary. Redux owns removal of the already-dispatched suffix; this resets
|
|
157
|
+
* the local streaming state so the replacement provider attempt cannot
|
|
158
|
+
* concatenate onto or resurrect the failed attempt.
|
|
49
159
|
*/
|
|
160
|
+
/** The source bytes behind every live A7 wrapper split (see `wrapperSplits`). */
|
|
50
161
|
getWrapperSplitSources(): Array<{
|
|
51
162
|
blockIds: string[];
|
|
52
163
|
source: string;
|
|
53
164
|
}>;
|
|
54
|
-
/**
|
|
55
|
-
* Forget every in-flight byte at and after a durable content boundary (a provider retry).
|
|
56
|
-
* Redux owns removal of the already-dispatched suffix; the replacement attempt starts a fresh
|
|
57
|
-
* run at `blockCount`.
|
|
58
|
-
*/
|
|
59
165
|
rewindToBlockCount(blockCount: number): void;
|
|
60
166
|
/**
|
|
61
|
-
* Close the current text
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
167
|
+
* Close the current text block at an interleaved-content boundary — a tool
|
|
168
|
+
* call that lands BETWEEN two text runs. The NEXT text run then opens a
|
|
169
|
+
* FRESH render block instead of appending onto the block that held the text
|
|
170
|
+
* BEFORE the tool.
|
|
171
|
+
*
|
|
172
|
+
* Why this exists: the accumulator lives for the whole stream and is never
|
|
173
|
+
* otherwise told about tool calls. Without this break, "text → tool → text"
|
|
174
|
+
* collapses both runs into a single `client_block_N`. The timeline still
|
|
175
|
+
* records a `text_end` for the second run, but its
|
|
176
|
+
* `[blockStartIndex, blockEndIndex)` range comes out EMPTY (no new blockId
|
|
177
|
+
* was pushed), so `selectUnifiedSlots` emits `[merged_text, tool]` — the
|
|
178
|
+
* tool card renders AFTER all the text, destroying chronological order.
|
|
179
|
+
* (The persisted/DB path is unaffected because it rebuilds each run's text
|
|
180
|
+
* from `text_end.rawText`, which is why a reload renders correctly.)
|
|
181
|
+
*
|
|
182
|
+
* Call this once per tool event, BEFORE the tool's `appendTimeline` dispatch
|
|
183
|
+
* and AFTER the pre-tool text has been flushed into the accumulator
|
|
184
|
+
* (process-stream's `dispatchBatch()` does that flush). It is a no-op when
|
|
185
|
+
* there is nothing open to break (back-to-back tool events, a tool with no
|
|
186
|
+
* preceding text, a tool right after a media block), so it is always safe.
|
|
65
187
|
*/
|
|
66
188
|
breakTextBlock(dispatch: DispatchFn): void;
|
|
67
|
-
private
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
/** Feed the open region's new bytes; reopen when the block is a different region. */
|
|
71
|
-
private feedRegion;
|
|
72
|
-
private openRegion;
|
|
73
|
-
/** End the open region; its final envelope is kept for the block it belongs to. */
|
|
74
|
-
private closeRegion;
|
|
75
|
-
private dropRegion;
|
|
76
|
-
private disposeAll;
|
|
77
|
-
/** `{` (or `[{`) with no key yet may become a JSON region next frame: draw nothing yet. */
|
|
78
|
-
private holdsNascentJson;
|
|
79
|
-
private frontMatterStillOpen;
|
|
80
|
-
private emit;
|
|
81
|
-
/** `data` as the renderer has always read it: a code block's language, a media block's link. */
|
|
82
|
-
private dataFor;
|
|
83
|
-
private signatureOf;
|
|
84
|
-
private retract;
|
|
189
|
+
private orphanReasoningCloseReported;
|
|
190
|
+
private unclosedReasoningReported;
|
|
191
|
+
private reportOrphanReasoningClose;
|
|
85
192
|
private reportUnclosedReasoningRegion;
|
|
193
|
+
private get currentBlockId();
|
|
194
|
+
private processLine;
|
|
195
|
+
/** The open bare-JSON region on this line is prose after all: drop its parse, keep its block as text. */
|
|
196
|
+
private demoteKindLineToProse;
|
|
197
|
+
/** Process queued lines in order (re-entrant calls return; the outer loop drains). */
|
|
198
|
+
private drainLineQueue;
|
|
199
|
+
/** Lines this accumulator has read (the first may open front matter). */
|
|
200
|
+
private linesRead;
|
|
201
|
+
private processLineNow;
|
|
202
|
+
/** Set while the next bare-JSON region opens as an array element (A6). */
|
|
203
|
+
private nextBareJsonInArray;
|
|
204
|
+
/** Set while the next bare-JSON region is a kind split out of a section (A8). */
|
|
205
|
+
private nextBareJsonResumeXml;
|
|
206
|
+
/** True while a split kind's earlier lines replay into its region (the XML tracker already saw them). */
|
|
207
|
+
private replayingSplitKind;
|
|
208
|
+
/**
|
|
209
|
+
* Track a JSON object inside a simple XML section; split it out the moment
|
|
210
|
+
* it carries a `__kind` key (A8). `line` is the section body part of a
|
|
211
|
+
* line. Returns true when the line was consumed by the split.
|
|
212
|
+
*/
|
|
213
|
+
private trackXmlKindCandidate;
|
|
214
|
+
/**
|
|
215
|
+
* Close the section's part before the kind (trimmed, like the reload's
|
|
216
|
+
* piece), then replay the kind's lines so far as a bare-JSON region that
|
|
217
|
+
* resumes the section when it balances (A8).
|
|
218
|
+
*/
|
|
219
|
+
private splitKindOutOfXmlSection;
|
|
220
|
+
/** The section a kind was split out of continues in a fresh block (A8). */
|
|
221
|
+
private resumeXmlSection;
|
|
222
|
+
/**
|
|
223
|
+
* Track a JSON object or JSON-family fence inside a generic XML container
|
|
224
|
+
* (an XML TAG — structure, ruling (b), round 3); split it out the moment its
|
|
225
|
+
* text carries a `__kind` key (X1). Returns true when the line was consumed.
|
|
226
|
+
*/
|
|
227
|
+
private trackGenericXmlKindCandidate;
|
|
228
|
+
/**
|
|
229
|
+
* Close the XML card's part before the kind, then replay the kind's lines
|
|
230
|
+
* so far as its own region (bare JSON or the JSON fence) that resumes the
|
|
231
|
+
* container when it closes (X1). The reload's recovery splits the same bytes.
|
|
232
|
+
*/
|
|
233
|
+
private splitKindOutOfGenericXml;
|
|
234
|
+
/** The fragment twin of the generic-XML split (X1): `<output>\n{"__kind":…` with no newline yet. */
|
|
235
|
+
private maybeSplitKindFromGenericXmlFragment;
|
|
236
|
+
/**
|
|
237
|
+
* The fragment twin of the section split: a newline-less kind object inside
|
|
238
|
+
* a simple section (`<info>{"__kind":…`) leaves it as soon as `__kind` is
|
|
239
|
+
* visible, and the fragment opens the region below (A8).
|
|
240
|
+
*/
|
|
241
|
+
private maybeSplitKindFromXmlFragment;
|
|
242
|
+
/**
|
|
243
|
+
* The held array start is a kind array: close the prose before it, drop the
|
|
244
|
+
* `[`, and replay the held lines as array content (A6).
|
|
245
|
+
*/
|
|
246
|
+
private commitKindArray;
|
|
247
|
+
/** Not a kind array after all: the held lines are ordinary lines, in order. */
|
|
248
|
+
private releaseHeldArray;
|
|
249
|
+
/**
|
|
250
|
+
* Array content between (or opening) elements: `,` and whitespace are
|
|
251
|
+
* chrome, `]` ends the array, `{` opens the next element as its own
|
|
252
|
+
* bare-JSON region. Anything else ends the array as ordinary source.
|
|
253
|
+
*/
|
|
254
|
+
private continueKindArray;
|
|
255
|
+
/**
|
|
256
|
+
* The fragment twin of the array entry in processLineNow: a newline-less
|
|
257
|
+
* `[{"__kind":…` decides on its first key while it streams (A6).
|
|
258
|
+
*/
|
|
259
|
+
private maybeEnterKindArrayFromFragment;
|
|
260
|
+
/** The fragment twin of the complete-line split in processLineNow (A5). */
|
|
261
|
+
private maybeSplitProseBeforeKindFragment;
|
|
262
|
+
/**
|
|
263
|
+
* Open a bare_json region directly from the trailing line fragment — the
|
|
264
|
+
* newline-less minified JSON case (`{"__kind":…}` streamed as one line with
|
|
265
|
+
* no `\n` until the end). Without this, processLine (which only sees COMPLETE
|
|
266
|
+
* lines) never opens the region and the raw JSON projects as a text block
|
|
267
|
+
* until finalize — the "shows the whole JSON, converts only when done" bug.
|
|
268
|
+
*
|
|
269
|
+
* Mirrors processLine's bare-JSON branch but fragment-driven: it commits the
|
|
270
|
+
* moment the fragment reveals `{ "key":` (unambiguous JSON), retracting the
|
|
271
|
+
* speculative text projection of those same chars, and lets the existing
|
|
272
|
+
* fragment-feed path (in ingest) and finalize/newline completion carry the
|
|
273
|
+
* region the rest of the way. openBraces/closeBraces start at 0 — the
|
|
274
|
+
* completing line counts them exactly once (see the bare_json substate case).
|
|
275
|
+
*/
|
|
276
|
+
private maybeOpenBareJsonFromFragment;
|
|
277
|
+
private processSubStateLine;
|
|
278
|
+
private openXmlTagBlock;
|
|
279
|
+
private irOpenRegion;
|
|
280
|
+
/**
|
|
281
|
+
* Feed region text. `part` is either the unfed remainder of a completing
|
|
282
|
+
* line (isLineComplete) or a pendingLineFragment delta (streaming chars of
|
|
283
|
+
* a line that hasn't finished — how minified single-line JSON gets live
|
|
284
|
+
* parsing instead of waiting for a newline).
|
|
285
|
+
*/
|
|
286
|
+
private irWriteLinePart;
|
|
287
|
+
/** Complete a region line, accounting for any fragment chars already fed. */
|
|
288
|
+
private irFeedLine;
|
|
289
|
+
/** End the open region: final envelope + shadow parity telemetry. */
|
|
290
|
+
private irCloseRegion;
|
|
291
|
+
/**
|
|
292
|
+
* Open an ir region for the JSON BODY of an attribute-XML block.
|
|
293
|
+
*
|
|
294
|
+
* THE WRAPPED-PAYLOAD CLASS. A structured-output agent whose answer is
|
|
295
|
+
* wrapped by the artifact system arrives as
|
|
296
|
+
*
|
|
297
|
+
* <artifact type="flashcards" id="…" title="…">
|
|
298
|
+
* {"__kind":"flashcard_set","cards":[…]}
|
|
299
|
+
* </artifact>
|
|
300
|
+
*
|
|
301
|
+
* The accumulator opens ir regions for fences and for bare JSON, but an
|
|
302
|
+
* attr-XML region swallowed every body line whole — no region, no
|
|
303
|
+
* `metadata.__ir`, so `selectKindEnvelope` answered null for the entire run
|
|
304
|
+
* AND after it. Every surface reading the envelope (the flashcard
|
|
305
|
+
* card-by-card preview, D170's `<image_prompt>` step) therefore showed a
|
|
306
|
+
* spinner over a stream that was arriving perfectly. The wrapper is not the
|
|
307
|
+
* payload: parse the body exactly as a bare JSON region.
|
|
308
|
+
*
|
|
309
|
+
* Rendering is deliberately UNCHANGED — the artifact block keeps the
|
|
310
|
+
* artifact renderer (kind-route.ts refuses to re-type an artifact); the
|
|
311
|
+
* envelope is attached for selectors, which is what was missing.
|
|
312
|
+
*
|
|
313
|
+
* `part` is a whole body line (isLineComplete) or the streaming fragment of
|
|
314
|
+
* one, so a minified single-line body parses live instead of at the close.
|
|
315
|
+
*/
|
|
316
|
+
private maybeOpenXmlBodyIrRegion;
|
|
317
|
+
private irParityCheck;
|
|
318
|
+
/** Dispose all sessions this stream opened (finalize-time cleanup). */
|
|
319
|
+
private irDisposeAll;
|
|
320
|
+
private appendToCurrentBlock;
|
|
321
|
+
private closeCurrentBlock;
|
|
322
|
+
/**
|
|
323
|
+
* A surrounding Markdown/code/XML classification never outranks an inner
|
|
324
|
+
* complete object carrying `__kind`. Replace the formerly monolithic Redux
|
|
325
|
+
* block with lossless container fragments plus independently routable JSON
|
|
326
|
+
* blocks. The first fragment reuses the already-streamed block id; later
|
|
327
|
+
* fragments take consecutive ids, so the next ordinary openBlock continues
|
|
328
|
+
* at the correct document position.
|
|
329
|
+
*/
|
|
330
|
+
private emitRecoveredEmbeddedKindBlocks;
|
|
331
|
+
/**
|
|
332
|
+
* Overwrites the block at the current index with an empty, completed payload
|
|
333
|
+
* so a previously-projected speculative streaming block is removed from the
|
|
334
|
+
* rendered output. Keyed by `currentBlockId`, so it replaces the exact
|
|
335
|
+
* Redux entry the speculative projection created.
|
|
336
|
+
*/
|
|
337
|
+
private retractCurrentBlock;
|
|
338
|
+
private openBlock;
|
|
339
|
+
private emitCurrentBlock;
|
|
340
|
+
/**
|
|
341
|
+
* Builds metadata for the block currently being emitted.
|
|
342
|
+
*
|
|
343
|
+
* Critical for attribute-XML tags (`<decision>`, `<artifact>`, `<editor_*>`):
|
|
344
|
+
* BlockRenderer reads `metadata.decision` / `metadata.artifactId` /
|
|
345
|
+
* `metadata.rawXml` etc. and falls back to raw-markdown rendering when those
|
|
346
|
+
* are missing — which is exactly the bug we're fixing (decision tags
|
|
347
|
+
* appearing as plain text mid-stream because metadata was hard-coded to
|
|
348
|
+
* `undefined` here previously).
|
|
349
|
+
*
|
|
350
|
+
* For simple XML tags we emit `{ isComplete, rawXml }` so consumers (loaders,
|
|
351
|
+
* inline-edit flows) can both gate on completion and round-trip the source.
|
|
352
|
+
*/
|
|
353
|
+
private buildBlockMetadata;
|
|
354
|
+
private buildXmlBlockMetadata;
|
|
355
|
+
private buildBlockData;
|
|
86
356
|
}
|
|
87
357
|
export {};
|