@slopus/happy-agent-client 0.0.115 → 0.0.118
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/HappyAgentClient.d.ts +1 -2
- package/dist/HappyAgentClient.d.ts.map +1 -1
- package/dist/HappyAgentClient.js +0 -8
- package/dist/HappyAgentClient.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/markdownBlocks.d.ts +9 -0
- package/dist/markdownBlocks.d.ts.map +1 -1
- package/dist/markdownBlocks.js +14 -6
- package/dist/markdownBlocks.js.map +1 -1
- package/dist/mediaLayoutBlocks.d.ts +41 -0
- package/dist/mediaLayoutBlocks.d.ts.map +1 -0
- package/dist/mediaLayoutBlocks.js +237 -0
- package/dist/mediaLayoutBlocks.js.map +1 -0
- package/dist/mediaLayoutHtml.d.ts +41 -0
- package/dist/mediaLayoutHtml.d.ts.map +1 -0
- package/dist/mediaLayoutHtml.js +316 -0
- package/dist/mediaLayoutHtml.js.map +1 -0
- package/dist/mediaLayoutHtmlStyle.d.ts +16 -0
- package/dist/mediaLayoutHtmlStyle.d.ts.map +1 -0
- package/dist/mediaLayoutHtmlStyle.js +44 -0
- package/dist/mediaLayoutHtmlStyle.js.map +1 -0
- package/dist/protocol/messages.d.ts +51 -0
- package/dist/protocol/messages.d.ts.map +1 -1
- package/dist/protocol/messages.js +13 -0
- package/dist/protocol/messages.js.map +1 -1
- package/dist/protocol/spaces.d.ts +13 -5
- package/dist/protocol/spaces.d.ts.map +1 -1
- package/dist/protocol/spaces.js +10 -7
- package/dist/protocol/spaces.js.map +1 -1
- package/package.json +3 -2
package/dist/markdownBlocks.js
CHANGED
|
@@ -23,14 +23,12 @@ export function textBlocks(markdown) {
|
|
|
23
23
|
fence = undefined;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
const open =
|
|
27
|
-
|
|
28
|
-
const info = open?.[2] ?? "";
|
|
29
|
-
if (marker !== undefined && !(marker.startsWith("`") && info.includes("`"))) {
|
|
26
|
+
const open = fenceOpening(line);
|
|
27
|
+
if (open !== undefined) {
|
|
30
28
|
if (blockStart !== undefined)
|
|
31
29
|
blocks.push({ start: blockStart, end: lineStart });
|
|
32
30
|
blockStart = undefined;
|
|
33
|
-
fence =
|
|
31
|
+
fence = open;
|
|
34
32
|
}
|
|
35
33
|
else if (BLANK_LINE.test(line)) {
|
|
36
34
|
if (blockStart !== undefined)
|
|
@@ -47,7 +45,17 @@ export function textBlocks(markdown) {
|
|
|
47
45
|
blocks.push({ start: blockStart, end: markdown.length });
|
|
48
46
|
return blocks;
|
|
49
47
|
}
|
|
50
|
-
|
|
48
|
+
/** The fence `line` opens, or `undefined` when it opens none. */
|
|
49
|
+
export function fenceOpening(line) {
|
|
50
|
+
const open = FENCE_OPEN.exec(line);
|
|
51
|
+
const marker = open?.[1];
|
|
52
|
+
const info = open?.[2] ?? "";
|
|
53
|
+
if (marker === undefined || (marker.startsWith("`") && info.includes("`")))
|
|
54
|
+
return undefined;
|
|
55
|
+
return { marker: marker.charAt(0), length: marker.length };
|
|
56
|
+
}
|
|
57
|
+
/** Whether `line` closes the open `fence`. */
|
|
58
|
+
export function isFenceClose(line, fence) {
|
|
51
59
|
const close = /^[ \t]*(?:>[ \t]?)*[ \t]*(`+|~+)[ \t\r]*$/.exec(line)?.[1];
|
|
52
60
|
return close !== undefined && close.charAt(0) === fence.marker && close.length >= fence.length;
|
|
53
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownBlocks.js","sourceRoot":"","sources":["../sources/markdownBlocks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,GAAG,6CAA6C,CAAC;AACjE,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB;IACvC,MAAM,MAAM,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, such as
|
|
4
|
+
* `<div style="display: grid; grid-template-columns: 1fr 1fr"><img src="a.png"><img src="b.png"></div>`.
|
|
5
|
+
* This finds the blocks; `parseMediaLayoutHtml` reads each one, and a client resolves every
|
|
6
|
+
* `<img src>` to an earlier media item with `mediaSourceMatches`. Nothing is ever loaded from
|
|
7
|
+
* `src`.
|
|
8
|
+
*
|
|
9
|
+
* A block starts at the start of a line, indented at most three spaces, with `<div`, `<section`,
|
|
10
|
+
* `<figure`, `<p`, or `<img`, outside fenced code and outside a code span. It runs until its root
|
|
11
|
+
* element closes, counting only that tag, so blank lines inside it never end it, and then takes
|
|
12
|
+
* the rest of the line it closes on. A block holding no `<img>` is ordinary Markdown.
|
|
13
|
+
*/
|
|
14
|
+
import type { MediaItemSource } from "./protocol/messages.js";
|
|
15
|
+
/**
|
|
16
|
+
* Markdown split around its layout blocks; the segments' text joined in order is the input.
|
|
17
|
+
* A `layout` segment that is not `complete` is always the last: its root element never closed,
|
|
18
|
+
* either because the text is still streaming or because the agent never closed it.
|
|
19
|
+
*/
|
|
20
|
+
export type MediaLayoutBlockSegment = {
|
|
21
|
+
type: "markdown";
|
|
22
|
+
text: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "layout";
|
|
25
|
+
html: string;
|
|
26
|
+
complete: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** Splits Markdown into Markdown and the layout blocks in it. Empty Markdown is omitted. */
|
|
29
|
+
export declare function splitMediaLayoutBlocks(markdown: string): MediaLayoutBlockSegment[];
|
|
30
|
+
/**
|
|
31
|
+
* Markdown without its complete layout blocks, for a surface that cannot show them, such as a
|
|
32
|
+
* chat service the reply is relayed to. The blank lines around a removed block close up to one.
|
|
33
|
+
* An incomplete block is broken HTML rather than a layout, so it stays as written.
|
|
34
|
+
*/
|
|
35
|
+
export declare function stripMediaLayoutBlocks(markdown: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether an `<img src>` in a layout block names the media item with this source: `src` equals
|
|
38
|
+
* the path the agent wrote or its absolute path, exactly. An item without a source never matches.
|
|
39
|
+
*/
|
|
40
|
+
export declare function mediaSourceMatches(source: MediaItemSource | undefined, src: string): boolean;
|
|
41
|
+
//# sourceMappingURL=mediaLayoutBlocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaLayoutBlocks.d.ts","sourceRoot":"","sources":["../sources/mediaLayoutBlocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAC7B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAQ1D,4FAA4F;AAC5F,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,uBAAuB,EAAE,CAgElF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB/D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5F"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media layout blocks: plain HTML an agent writes in its Markdown reply to arrange media it
|
|
3
|
+
* already showed in the conversation, such as
|
|
4
|
+
* `<div style="display: grid; grid-template-columns: 1fr 1fr"><img src="a.png"><img src="b.png"></div>`.
|
|
5
|
+
* This finds the blocks; `parseMediaLayoutHtml` reads each one, and a client resolves every
|
|
6
|
+
* `<img src>` to an earlier media item with `mediaSourceMatches`. Nothing is ever loaded from
|
|
7
|
+
* `src`.
|
|
8
|
+
*
|
|
9
|
+
* A block starts at the start of a line, indented at most three spaces, with `<div`, `<section`,
|
|
10
|
+
* `<figure`, `<p`, or `<img`, outside fenced code and outside a code span. It runs until its root
|
|
11
|
+
* element closes, counting only that tag, so blank lines inside it never end it, and then takes
|
|
12
|
+
* the rest of the line it closes on. A block holding no `<img>` is ordinary Markdown.
|
|
13
|
+
*/
|
|
14
|
+
import { fenceOpening, isFenceClose, skipCodeSpan } from "./markdownBlocks.js";
|
|
15
|
+
const BLOCK_TAGS = ["div", "section", "figure", "p", "img"];
|
|
16
|
+
const BLOCK_START = /^ {0,3}<(div|section|figure|p|img)(?=[\t\n\f\r />]|$)/iu;
|
|
17
|
+
const PARTIAL_START = /^ {0,3}<([a-z]*)$/iu;
|
|
18
|
+
const BLANK_LINE = /^[ \t\r]*$/u;
|
|
19
|
+
const TAG_NAME = /[A-Za-z][A-Za-z0-9-]*/uy;
|
|
20
|
+
/** Splits Markdown into Markdown and the layout blocks in it. Empty Markdown is omitted. */
|
|
21
|
+
export function splitMediaLayoutBlocks(markdown) {
|
|
22
|
+
const segments = [];
|
|
23
|
+
const pushMarkdown = (text) => {
|
|
24
|
+
if (text === "")
|
|
25
|
+
return;
|
|
26
|
+
const last = segments[segments.length - 1];
|
|
27
|
+
if (last?.type === "markdown")
|
|
28
|
+
last.text += text;
|
|
29
|
+
else
|
|
30
|
+
segments.push({ type: "markdown", text });
|
|
31
|
+
};
|
|
32
|
+
let markdownStart = 0;
|
|
33
|
+
let lineStart = 0;
|
|
34
|
+
let fence;
|
|
35
|
+
// Where the code span covering the current paragraph's text ends; nothing starts before it.
|
|
36
|
+
let codeUntil = 0;
|
|
37
|
+
while (lineStart < markdown.length) {
|
|
38
|
+
const newline = markdown.indexOf("\n", lineStart);
|
|
39
|
+
const lineEnd = newline === -1 ? markdown.length : newline + 1;
|
|
40
|
+
const line = markdown.slice(lineStart, newline === -1 ? markdown.length : newline);
|
|
41
|
+
if (fence !== undefined) {
|
|
42
|
+
if (isFenceClose(line, fence))
|
|
43
|
+
fence = undefined;
|
|
44
|
+
lineStart = lineEnd;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const opening = fenceOpening(line);
|
|
48
|
+
if (opening !== undefined) {
|
|
49
|
+
fence = opening;
|
|
50
|
+
lineStart = lineEnd;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (BLANK_LINE.test(line)) {
|
|
54
|
+
lineStart = lineEnd;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (lineStart >= codeUntil) {
|
|
58
|
+
const start = BLOCK_START.exec(line);
|
|
59
|
+
if (start !== null) {
|
|
60
|
+
const tag = (start[1] ?? "").toLowerCase();
|
|
61
|
+
const block = scanBlock(markdown, lineStart + start[0].length - tag.length - 1, tag);
|
|
62
|
+
pushMarkdown(markdown.slice(markdownStart, lineStart));
|
|
63
|
+
const html = markdown.slice(lineStart, block.end);
|
|
64
|
+
if (!block.complete) {
|
|
65
|
+
segments.push({ type: "layout", html, complete: false });
|
|
66
|
+
return segments;
|
|
67
|
+
}
|
|
68
|
+
if (block.image)
|
|
69
|
+
segments.push({ type: "layout", html, complete: true });
|
|
70
|
+
else
|
|
71
|
+
pushMarkdown(html);
|
|
72
|
+
markdownStart = block.end;
|
|
73
|
+
lineStart = block.end;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (newline === -1 && isPartialStart(line)) {
|
|
77
|
+
pushMarkdown(markdown.slice(markdownStart, lineStart));
|
|
78
|
+
segments.push({ type: "layout", html: line, complete: false });
|
|
79
|
+
return segments;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
codeUntil = skipCodeSpans(markdown, Math.max(lineStart, codeUntil), lineEnd, codeUntil);
|
|
83
|
+
lineStart = lineEnd;
|
|
84
|
+
}
|
|
85
|
+
pushMarkdown(markdown.slice(markdownStart));
|
|
86
|
+
return segments;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Markdown without its complete layout blocks, for a surface that cannot show them, such as a
|
|
90
|
+
* chat service the reply is relayed to. The blank lines around a removed block close up to one.
|
|
91
|
+
* An incomplete block is broken HTML rather than a layout, so it stays as written.
|
|
92
|
+
*/
|
|
93
|
+
export function stripMediaLayoutBlocks(markdown) {
|
|
94
|
+
let text = "";
|
|
95
|
+
let removed = false;
|
|
96
|
+
for (const segment of splitMediaLayoutBlocks(markdown)) {
|
|
97
|
+
if (segment.type === "layout" && segment.complete) {
|
|
98
|
+
removed = true;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
let part = segment.type === "markdown" ? segment.text : segment.html;
|
|
102
|
+
if (removed) {
|
|
103
|
+
part = part.replace(/^(?:[ \t]*\r?\n)+/u, "");
|
|
104
|
+
if (part === "")
|
|
105
|
+
continue;
|
|
106
|
+
text = text === "" ? "" : `${text.replace(/(?:\r?\n[ \t]*)+$/u, "")}\n\n`;
|
|
107
|
+
removed = false;
|
|
108
|
+
}
|
|
109
|
+
text += part;
|
|
110
|
+
}
|
|
111
|
+
return removed ? text.replace(/\s+$/u, "") : text;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether an `<img src>` in a layout block names the media item with this source: `src` equals
|
|
115
|
+
* the path the agent wrote or its absolute path, exactly. An item without a source never matches.
|
|
116
|
+
*/
|
|
117
|
+
export function mediaSourceMatches(source, src) {
|
|
118
|
+
return source !== undefined && (src === source.path || src === source.absolutePath);
|
|
119
|
+
}
|
|
120
|
+
/** Whether a final line without its newline could still become a block start. */
|
|
121
|
+
function isPartialStart(line) {
|
|
122
|
+
const name = PARTIAL_START.exec(line)?.[1]?.toLowerCase();
|
|
123
|
+
return name !== undefined && BLOCK_TAGS.some((tag) => tag.startsWith(name));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Where the block whose root `tag` opens at `start` ends: after the line its root element closes
|
|
127
|
+
* on. Comments and quoted attribute values are skipped. Incomplete when the root never closes, or
|
|
128
|
+
* a tag or comment is cut off.
|
|
129
|
+
*/
|
|
130
|
+
function scanBlock(markdown, start, tag) {
|
|
131
|
+
const incomplete = { end: markdown.length, complete: false, image: false };
|
|
132
|
+
let depth = 0;
|
|
133
|
+
let image = false;
|
|
134
|
+
let index = start;
|
|
135
|
+
while (index < markdown.length) {
|
|
136
|
+
if (markdown[index] !== "<") {
|
|
137
|
+
index += 1;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (markdown.startsWith("<!--", index)) {
|
|
141
|
+
const close = markdown.indexOf("-->", index + 4);
|
|
142
|
+
if (close === -1)
|
|
143
|
+
return incomplete;
|
|
144
|
+
index = close + 3;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const closing = markdown[index + 1] === "/";
|
|
148
|
+
TAG_NAME.lastIndex = index + (closing ? 2 : 1);
|
|
149
|
+
const name = TAG_NAME.exec(markdown)?.[0].toLowerCase();
|
|
150
|
+
if (name === undefined) {
|
|
151
|
+
index += 1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const tagEnd = closing
|
|
155
|
+
? markdown.indexOf(">", TAG_NAME.lastIndex)
|
|
156
|
+
: openTagEnd(markdown, TAG_NAME.lastIndex);
|
|
157
|
+
if (tagEnd === -1)
|
|
158
|
+
return incomplete;
|
|
159
|
+
index = tagEnd + 1;
|
|
160
|
+
if (!closing && name === "img")
|
|
161
|
+
image = true;
|
|
162
|
+
if (name !== tag)
|
|
163
|
+
continue;
|
|
164
|
+
if (closing)
|
|
165
|
+
depth -= 1;
|
|
166
|
+
else if (tag !== "img")
|
|
167
|
+
depth += 1;
|
|
168
|
+
if (depth > 0)
|
|
169
|
+
continue;
|
|
170
|
+
const newline = markdown.indexOf("\n", index);
|
|
171
|
+
return { end: newline === -1 ? markdown.length : newline + 1, complete: true, image };
|
|
172
|
+
}
|
|
173
|
+
return incomplete;
|
|
174
|
+
}
|
|
175
|
+
/** The index of the `>` ending an open tag whose attributes start at `index`, or -1. */
|
|
176
|
+
function openTagEnd(markdown, index) {
|
|
177
|
+
let position = index;
|
|
178
|
+
let afterEquals = false;
|
|
179
|
+
while (position < markdown.length) {
|
|
180
|
+
const character = markdown[position];
|
|
181
|
+
if (character === ">")
|
|
182
|
+
return position;
|
|
183
|
+
if ((character === '"' || character === "'") && afterEquals) {
|
|
184
|
+
const close = markdown.indexOf(character, position + 1);
|
|
185
|
+
if (close === -1)
|
|
186
|
+
return -1;
|
|
187
|
+
position = close + 1;
|
|
188
|
+
afterEquals = false;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (character === "=")
|
|
192
|
+
afterEquals = true;
|
|
193
|
+
else if (!/\s/u.test(character ?? ""))
|
|
194
|
+
afterEquals = false;
|
|
195
|
+
position += 1;
|
|
196
|
+
}
|
|
197
|
+
return -1;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Skips the code spans that open in `[from, lineEnd)`, returning where the last one ends, or
|
|
201
|
+
* `codeUntil` when none opens. A span is bounded by its paragraph, which a blank line or a fence
|
|
202
|
+
* ends.
|
|
203
|
+
*/
|
|
204
|
+
function skipCodeSpans(markdown, from, lineEnd, codeUntil) {
|
|
205
|
+
let until = codeUntil;
|
|
206
|
+
let index = from;
|
|
207
|
+
let end;
|
|
208
|
+
while (index < lineEnd) {
|
|
209
|
+
const character = markdown[index];
|
|
210
|
+
if (character === "\\") {
|
|
211
|
+
index += 2;
|
|
212
|
+
}
|
|
213
|
+
else if (character === "`") {
|
|
214
|
+
end ??= paragraphEnd(markdown, lineEnd);
|
|
215
|
+
index = skipCodeSpan(markdown, index, end, false);
|
|
216
|
+
until = index;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
index += 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return until;
|
|
223
|
+
}
|
|
224
|
+
function paragraphEnd(markdown, from) {
|
|
225
|
+
let lineStart = from;
|
|
226
|
+
while (lineStart < markdown.length) {
|
|
227
|
+
const newline = markdown.indexOf("\n", lineStart);
|
|
228
|
+
const line = markdown.slice(lineStart, newline === -1 ? markdown.length : newline);
|
|
229
|
+
if (BLANK_LINE.test(line) || fenceOpening(line) !== undefined)
|
|
230
|
+
return lineStart;
|
|
231
|
+
if (newline === -1)
|
|
232
|
+
return markdown.length;
|
|
233
|
+
lineStart = newline + 1;
|
|
234
|
+
}
|
|
235
|
+
return markdown.length;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=mediaLayoutBlocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaLayoutBlocks.js","sourceRoot":"","sources":["../sources/mediaLayoutBlocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAsB,MAAM,qBAAqB,CAAC;AAYnG,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAU,CAAC;AACrE,MAAM,WAAW,GAAG,yDAAyD,CAAC;AAC9E,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,UAAU,GAAG,aAAa,CAAC;AACjC,MAAM,QAAQ,GAAG,yBAAyB,CAAC;AAE3C,4FAA4F;AAC5F,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACnD,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAC/C,MAAM,YAAY,GAAG,CAAC,IAAY,EAAQ,EAAE;QACxC,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO;QACxB,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC3C,IAAI,IAAI,EAAE,IAAI,KAAK,UAAU;YAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;;YAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC;IACF,IAAI,aAAa,GAAG,CAAC,CAA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IAAI,CAAC,CAAC;QACf,CAAC;aAAM,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YAC3B,GAAG,KAAK,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACxC,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAClD,KAAK,GAAG,KAAK,CAAC;QAClB,CAAC;aAAM,CAAC;YACJ,KAAK,IAAI,CAAC,CAAC;QACf,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,YAAY,CAAC,QAAgB,EAAE,IAAY;IAChD,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,OAAO,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACnF,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAChF,IAAI,OAAO,KAAK,CAAC,CAAC;YAAE,OAAO,QAAQ,CAAC,MAAM,CAAC;QAC3C,SAAS,GAAG,OAAO,GAAG,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,QAAQ,CAAC,MAAM,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media layout HTML: the small subset of HTML and CSS an agent writes to arrange media it showed,
|
|
3
|
+
* either as `present_files`' `layout` argument or as a block in its Markdown reply. This one
|
|
4
|
+
* parser turns it into the typed tree clients render, so the daemon and every client agree on
|
|
5
|
+
* exactly what a layout means. No HTML ever reaches a renderer.
|
|
6
|
+
*/
|
|
7
|
+
import type { MediaLayoutNode } from "./protocol/messages.js";
|
|
8
|
+
/** The most layout HTML that is read, in UTF-16 code units; a longer layout is not used. */
|
|
9
|
+
export declare const MAX_MEDIA_LAYOUT_HTML_LENGTH: number;
|
|
10
|
+
/**
|
|
11
|
+
* Names the media an `<img src>` refers to as an index into the caller's own list of items, or
|
|
12
|
+
* `undefined` when it names nothing. The parser never loads `src` itself.
|
|
13
|
+
*/
|
|
14
|
+
export type MediaLayoutSourceResolver = (src: string) => number | undefined;
|
|
15
|
+
/** What layout HTML became. */
|
|
16
|
+
export interface ParsedMediaLayoutHtml {
|
|
17
|
+
/** The typed tree; each item node's `index` is what the resolver returned for its `src`. */
|
|
18
|
+
readonly root: MediaLayoutNode[];
|
|
19
|
+
/** The indexes the tree places, in order, each once. */
|
|
20
|
+
readonly placed: readonly number[];
|
|
21
|
+
/** Short descriptions of what was left out, such as `position on <div>`, for the agent. */
|
|
22
|
+
readonly ignored: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Whether content was lost to a limit: the whole HTML was too long, or nodes or text beyond
|
|
25
|
+
* the tree's bounds were dropped. Unsupported markup left out on purpose does not count.
|
|
26
|
+
*/
|
|
27
|
+
readonly truncated: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Turn media layout HTML into the typed tree a client renders.
|
|
31
|
+
*
|
|
32
|
+
* The HTML is parsed by parse5, a spec-compliant parser, so tags, attributes, and entities mean
|
|
33
|
+
* what a browser would take them to mean, and malformed markup is repaired the way a browser
|
|
34
|
+
* repairs it. The tree is then rebuilt from what the subset allows, and nothing fails: a tag the
|
|
35
|
+
* subset lacks is unwrapped and its content kept, a tag that runs, loads, or embeds something is
|
|
36
|
+
* left out with its content, other attributes and declarations are left out, and an image whose
|
|
37
|
+
* `src` the resolver does not know, or whose item is already placed, is left out. Everything left
|
|
38
|
+
* out is reported. Deciding what a layout that places nothing means is the caller's.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseMediaLayoutHtml(source: string, resolve: MediaLayoutSourceResolver): ParsedMediaLayoutHtml;
|
|
41
|
+
//# sourceMappingURL=mediaLayoutHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaLayoutHtml.d.ts","sourceRoot":"","sources":["../sources/mediaLayoutHtml.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AAK9E,4FAA4F;AAC5F,eAAO,MAAM,4BAA4B,QAAY,CAAC;AA2DtD;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE5E,+BAA+B;AAC/B,MAAM,WAAW,qBAAqB;IAClC,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC;IACjC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,2FAA2F;IAC3F,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC/B;AAWD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,yBAAyB,GACnC,qBAAqB,CAuCvB"}
|