@seclai/react 0.0.17 → 0.0.18

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/index.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use client";
2
+ import {
3
+ MAY_DEFINE,
4
+ holdBackPendingLine,
5
+ normalizeBullets,
6
+ normalizeNewlines
7
+ } from "./chunk-OFKVHNZ6.js";
8
+ import {
9
+ rehypeListBadges,
10
+ rehypeRawAsText,
11
+ rehypeTrimBlocks,
12
+ remarkHtmlBreaks,
13
+ remarkLineBreaks,
14
+ remarkListNumbers
15
+ } from "./chunk-VRNPDCWI.js";
2
16
 
3
17
  // src/AgentChat.tsx
4
18
  import {
@@ -6,7 +20,7 @@ import {
6
20
  useEffect as useEffect7,
7
21
  useMemo as useMemo2,
8
22
  useRef as useRef5,
9
- useState as useState6
23
+ useState as useState7
10
24
  } from "react";
11
25
 
12
26
  // src/attachments.ts
@@ -19,15 +33,15 @@ function createEndpoints({
19
33
  agentId
20
34
  } = {}) {
21
35
  const trimmed = basePath.replace(/\/+$/, "");
22
- const base = agentId ? `${trimmed}/${encodeURIComponent(agentId)}` : trimmed;
36
+ const base2 = agentId ? `${trimmed}/${encodeURIComponent(agentId)}` : trimmed;
23
37
  return {
24
- attachmentReferences: `${base}/attachment-references`,
25
- upload: `${base}/upload`,
26
- run: `${base}/run`,
38
+ attachmentReferences: `${base2}/attachment-references`,
39
+ upload: `${base2}/upload`,
40
+ run: `${base2}/run`,
27
41
  download(runId, attachmentId, name) {
28
42
  const params = new URLSearchParams({ runId, attachmentId });
29
43
  if (name) params.set("name", name);
30
- return `${base}/download?${params}`;
44
+ return `${base2}/download?${params}`;
31
45
  }
32
46
  };
33
47
  }
@@ -56,10 +70,10 @@ function withQuery(url, params) {
56
70
  const query = new URLSearchParams(params).toString();
57
71
  if (!query) return url;
58
72
  const hashAt = url.indexOf("#");
59
- const base = hashAt < 0 ? url : url.slice(0, hashAt);
73
+ const base2 = hashAt < 0 ? url : url.slice(0, hashAt);
60
74
  const hash = hashAt < 0 ? "" : url.slice(hashAt);
61
- const separator = !base.includes("?") ? "?" : base.endsWith("?") || base.endsWith("&") ? "" : "&";
62
- return `${base}${separator}${query}${hash}`;
75
+ const separator = !base2.includes("?") ? "?" : base2.endsWith("?") || base2.endsWith("&") ? "" : "&";
76
+ return `${base2}${separator}${query}${hash}`;
63
77
  }
64
78
 
65
79
  // src/attachments.ts
@@ -104,140 +118,451 @@ function messageFileLimits(slots) {
104
118
  return { max, contentTypes: anyType ? [] : [...types] };
105
119
  }
106
120
 
107
- // src/placeholders/MarkdownContent.tsx
108
- import { Fragment } from "react";
109
- import { jsx, jsxs } from "react/jsx-runtime";
110
- var ORDERED = /^(\s*)(\d{1,9})[.)]\s+(\S.*)$/;
111
- var BULLET = /^(\s*)[-*•]\s+(\S.*)$/;
112
- var BARE_MARKER = /^\s*(?:\d{1,9}[.)]?\s*|[-*•_][-*_\s]*)$/;
113
- var THEMATIC_BREAK = /^\s*([-*_])(?:[ \t]*\1){2,}[ \t]*$/;
114
- var NEST = 2;
115
- var FENCE = /^\s*(`{3,}(?!.*`)|~{3,})/;
116
- var CLOSING_FENCE = /^\s*(`{3,}|~{3,})\s*$/;
117
- function indentOf(space) {
118
- let width = 0;
119
- for (const char of space) width += char === " " ? 4 : 1;
120
- return width;
121
- }
122
- function parse(content) {
123
- const blocks = [];
124
- const open = [];
125
- let blank = true;
126
- let fence = null;
127
- const push = (block) => {
128
- blocks.push(block);
129
- open.length = 0;
130
- };
131
- for (const line of content.replace(/\r\n?/g, "\n").split("\n")) {
132
- const last = blocks.at(-1);
133
- if (fence && last?.type === "p") {
134
- last.lines.push(line);
135
- const closing = CLOSING_FENCE.exec(line)?.[1];
136
- if (closing && closing[0] === fence[0] && closing.length >= fence.length) fence = null;
137
- continue;
138
- }
139
- const opening = FENCE.exec(line);
140
- if (opening) {
141
- fence = opening[1];
142
- push({ type: "p", lines: [line], verbatim: true });
143
- blank = false;
144
- continue;
145
- }
146
- if (!line.trim()) {
147
- blank = true;
148
- continue;
149
- }
150
- if (THEMATIC_BREAK.test(line)) {
151
- push({ type: "hr" });
152
- blank = false;
153
- continue;
154
- }
155
- const ordered = ORDERED.exec(line);
156
- const bullet = ordered || BARE_MARKER.test(line) ? null : BULLET.exec(line);
157
- if (ordered || bullet) {
158
- const type = ordered ? "ol" : "ul";
159
- const item = ordered ? { n: Number(ordered[2]), indent: indentOf(ordered[1]), lines: [ordered[3]], lists: [] } : { indent: indentOf(bullet[1]), lines: [bullet[2]], lists: [] };
160
- let level = 0;
161
- while (level < open.length && item.indent >= open[level].items.at(-1).indent + NEST) level++;
162
- const list = open[level];
163
- if (list?.type === type) {
164
- list.items.push(item);
165
- open.length = level + 1;
121
+ // src/markdown/MarkdownContent.tsx
122
+ import { memo, useState as useState2 } from "react";
123
+ import Markdown from "react-markdown";
124
+ import rehypeSanitize from "rehype-sanitize";
125
+
126
+ // src/markdown/blocks.ts
127
+ var splitting = {
128
+ /**
129
+ * The shortest block, in characters. Blocks of a few nodes rather than one
130
+ * each keep down the number of blocks, which React compares on every token,
131
+ * while the last block stays quick to parse. Tests lower it to split at
132
+ * every node.
133
+ */
134
+ minBlock: 1024
135
+ };
136
+ var VOID = /* @__PURE__ */ new Set([
137
+ "area",
138
+ "base",
139
+ "br",
140
+ "col",
141
+ "embed",
142
+ "hr",
143
+ "img",
144
+ "input",
145
+ "link",
146
+ "meta",
147
+ "param",
148
+ "source",
149
+ "track",
150
+ "wbr"
151
+ ]);
152
+ var TAG = /<!--[\s\S]*?-->|<(\/?)([A-Za-z][A-Za-z0-9-]*)(?:=[ \t\n]*"[^"]*"|=[ \t\n]*'[^']*'|=(?![ \t\n]*["'])|[^<>=])*?(\/?)>/g;
153
+ var FOREIGN = /* @__PURE__ */ new Set(["svg", "math"]);
154
+ function trackHtml(node, open) {
155
+ if (node.type === "html") {
156
+ for (const match of node.value.matchAll(TAG)) {
157
+ const [, closing, name, selfClosing] = match;
158
+ if (!name) continue;
159
+ const tag = name.toLowerCase();
160
+ if (closing) {
161
+ const at = open.lastIndexOf(tag);
162
+ if (at !== -1) open.length = at;
166
163
  } else {
167
- const next = { type, items: [item] };
168
- (level > 0 ? open[level - 1].items.at(-1).lists : blocks).push(next);
169
- open.length = level;
170
- open.push(next);
164
+ const closed = VOID.has(tag) || !!selfClosing && (FOREIGN.has(tag) || open.some((name2) => FOREIGN.has(name2)));
165
+ if (!closed) open.push(tag);
171
166
  }
172
- } else if (!blank && open.length > 0 && !BARE_MARKER.test(line)) {
173
- open.at(-1).items.at(-1).lines.push(line.trim());
174
- } else if (!blank && last?.type === "p" && !last.verbatim) {
175
- last.lines.push(line);
176
- } else {
177
- push({ type: "p", lines: [line] });
178
167
  }
179
- blank = false;
168
+ return;
180
169
  }
181
- return blocks;
182
- }
183
- var INLINE = /(`[^`\n]+`)|\*\*(?!\s)((?:[^*`\n]|`[^`\n]*`)*?(?:[^\s*`]|`[^`\n]*`))\*\*/g;
184
- function inline(text) {
185
- const nodes = [];
186
- let at = 0;
187
- for (const match of text.matchAll(INLINE)) {
188
- if (match[2] === void 0) continue;
189
- const index = match.index;
190
- if (index > at) nodes.push(text.slice(at, index));
191
- nodes.push(/* @__PURE__ */ jsx("strong", { children: match[2] }, index));
192
- at = index + match[0].length;
170
+ if ("children" in node) for (const child of node.children) trackHtml(child, open);
171
+ }
172
+ function splitPoints(tree, source, rawHtml = true) {
173
+ const points = [];
174
+ const open = [];
175
+ let previousEnd = 0;
176
+ for (const [index, node] of tree.children.entries()) {
177
+ const start = node.position?.start.offset;
178
+ const end = node.position?.end.offset;
179
+ if (start === void 0 || end === void 0) return points;
180
+ const lineStart = source.lastIndexOf("\n", start - 1) + 1;
181
+ if (index > 0 && open.length === 0 && lineStart >= previousEnd && lineStart > (points.at(-1) ?? 0) && source.indexOf("\n", start) !== -1) {
182
+ points.push(lineStart);
183
+ }
184
+ if (rawHtml) trackHtml(node, open);
185
+ previousEnd = end;
186
+ }
187
+ return points;
188
+ }
189
+
190
+ // src/markdown/extensions.tsx
191
+ import { createContext, useContext } from "react";
192
+ import { jsx } from "react/jsx-runtime";
193
+ var ExtensionsContext = createContext([]);
194
+ function SeclaiMarkdownProvider({ extensions, children }) {
195
+ return /* @__PURE__ */ jsx(ExtensionsContext.Provider, { value: extensions, children });
196
+ }
197
+ function useMarkdownExtensions() {
198
+ return useContext(ExtensionsContext);
199
+ }
200
+
201
+ // src/markdown/gfm.ts
202
+ import { gfmFootnoteFromMarkdown } from "mdast-util-gfm-footnote";
203
+ import { gfmStrikethroughFromMarkdown } from "mdast-util-gfm-strikethrough";
204
+ import { gfmTableFromMarkdown } from "mdast-util-gfm-table";
205
+ import { gfmTaskListItemFromMarkdown } from "mdast-util-gfm-task-list-item";
206
+ import { gfm } from "micromark-extension-gfm";
207
+ function enterLiteralAutolink(token) {
208
+ this.enter({ type: "link", title: null, url: "", children: [] }, token);
209
+ }
210
+ function enterLiteralAutolinkValue(token) {
211
+ this.config.enter.autolinkProtocol.call(this, token);
212
+ }
213
+ function exitLiteralAutolinkHttp(token) {
214
+ this.config.exit.autolinkProtocol.call(this, token);
215
+ }
216
+ function exitLiteralAutolinkWww(token) {
217
+ this.config.exit.data.call(this, token);
218
+ const node = this.stack[this.stack.length - 1];
219
+ node.url = "http://" + this.sliceSerialize(token);
220
+ }
221
+ function exitLiteralAutolinkEmail(token) {
222
+ this.config.exit.autolinkEmail.call(this, token);
223
+ }
224
+ function exitLiteralAutolink(token) {
225
+ this.exit(token);
226
+ }
227
+ var autolinkLiteralFromMarkdown = {
228
+ enter: {
229
+ literalAutolink: enterLiteralAutolink,
230
+ literalAutolinkEmail: enterLiteralAutolinkValue,
231
+ literalAutolinkHttp: enterLiteralAutolinkValue,
232
+ literalAutolinkWww: enterLiteralAutolinkValue
233
+ },
234
+ exit: {
235
+ literalAutolink: exitLiteralAutolink,
236
+ literalAutolinkEmail: exitLiteralAutolinkEmail,
237
+ literalAutolinkHttp: exitLiteralAutolinkHttp,
238
+ literalAutolinkWww: exitLiteralAutolinkWww
193
239
  }
194
- if (at < text.length) nodes.push(text.slice(at));
195
- return nodes;
196
- }
197
- function withBreaks(lines, format) {
198
- return lines.map((line, i) => /* @__PURE__ */ jsxs(Fragment, { children: [
199
- i > 0 && /* @__PURE__ */ jsx("br", {}),
200
- format(line)
201
- ] }, i));
202
- }
203
- function renderList(list, key) {
204
- if (list.type === "ul") {
205
- return /* @__PURE__ */ jsx("ul", { children: list.items.map((item, i) => /* @__PURE__ */ jsxs("li", { children: [
206
- withBreaks(item.lines, inline),
207
- item.lists.map(renderList)
208
- ] }, i)) }, key);
240
+ };
241
+ function remarkGfm() {
242
+ const data = this.data();
243
+ (data.micromarkExtensions ??= []).push(gfm());
244
+ (data.fromMarkdownExtensions ??= []).push([
245
+ autolinkLiteralFromMarkdown,
246
+ gfmFootnoteFromMarkdown(),
247
+ gfmStrikethroughFromMarkdown(),
248
+ gfmTableFromMarkdown(),
249
+ gfmTaskListItemFromMarkdown()
250
+ ]);
251
+ }
252
+
253
+ // src/markdown/sanitize.ts
254
+ import { defaultSchema } from "rehype-sanitize";
255
+ var SVG_TAGS = [
256
+ "svg",
257
+ "g",
258
+ "defs",
259
+ "title",
260
+ "desc",
261
+ "path",
262
+ "rect",
263
+ "circle",
264
+ "ellipse",
265
+ "line",
266
+ "polyline",
267
+ "polygon",
268
+ "text",
269
+ "tspan",
270
+ "textPath",
271
+ "marker",
272
+ "symbol",
273
+ "use",
274
+ "clipPath",
275
+ "mask",
276
+ "pattern",
277
+ "linearGradient",
278
+ "radialGradient",
279
+ "stop",
280
+ "filter",
281
+ "feGaussianBlur",
282
+ "feOffset",
283
+ "feMerge",
284
+ "feMergeNode",
285
+ "feColorMatrix",
286
+ "feFlood",
287
+ "feComposite"
288
+ ];
289
+ var SVG_COMMON = [
290
+ "transform",
291
+ "fill",
292
+ "fillOpacity",
293
+ "fillRule",
294
+ "stroke",
295
+ "strokeWidth",
296
+ "strokeOpacity",
297
+ "strokeLinecap",
298
+ "strokeLinejoin",
299
+ "strokeDasharray",
300
+ "strokeDashoffset",
301
+ "strokeMiterlimit",
302
+ "opacity",
303
+ "clipPath",
304
+ "clipRule",
305
+ "mask",
306
+ "filter",
307
+ "vectorEffect",
308
+ "visibility",
309
+ "display"
310
+ ];
311
+ var TEXT = ["x", "y", "dx", "dy", "textAnchor", "dominantBaseline", "fontFamily", "fontSize", "fontWeight", "fontStyle"];
312
+ var BOX = ["x", "y", "width", "height"];
313
+ var GRADIENT = ["gradientUnits", "gradientTransform", "spreadMethod", "href"];
314
+ var svgAttributes = {
315
+ svg: ["xmlns", "viewBox", "preserveAspectRatio", "role", "ariaLabel", "ariaLabelledBy", "ariaDescribedBy"],
316
+ path: ["d", "pathLength"],
317
+ rect: [...BOX, "rx", "ry"],
318
+ circle: ["cx", "cy", "r"],
319
+ ellipse: ["cx", "cy", "rx", "ry"],
320
+ line: ["x1", "y1", "x2", "y2"],
321
+ polyline: ["points"],
322
+ polygon: ["points"],
323
+ text: [...TEXT, "alignmentBaseline", "letterSpacing", "wordSpacing", "writingMode"],
324
+ tspan: TEXT,
325
+ textPath: ["startOffset", "method", "spacing", "href"],
326
+ marker: ["markerUnits", "refX", "refY", "markerWidth", "markerHeight", "orient", "viewBox", "preserveAspectRatio"],
327
+ symbol: ["viewBox", "preserveAspectRatio"],
328
+ use: [...BOX, "href"],
329
+ clipPath: ["clipPathUnits"],
330
+ mask: [...BOX, "maskUnits", "maskContentUnits"],
331
+ pattern: [...BOX, "patternUnits", "patternContentUnits", "patternTransform", "viewBox", "preserveAspectRatio", "href"],
332
+ linearGradient: ["x1", "y1", "x2", "y2", ...GRADIENT],
333
+ radialGradient: ["cx", "cy", "r", "fx", "fy", "fr", ...GRADIENT],
334
+ stop: ["offset", "stopColor", "stopOpacity"],
335
+ filter: [...BOX, "filterUnits", "primitiveUnits"],
336
+ feGaussianBlur: ["in", "stdDeviation", "edgeMode", "result"],
337
+ feOffset: ["in", "dx", "dy", "result"],
338
+ feMerge: ["result"],
339
+ feMergeNode: ["in"],
340
+ feColorMatrix: ["in", "type", "values", "result"],
341
+ feFlood: [...BOX, "floodColor", "floodOpacity", "result"],
342
+ feComposite: ["in", "in2", "operator", "k1", "k2", "k3", "k4", "result"]
343
+ };
344
+ var DROPPED = /* @__PURE__ */ new Set(["accessKey", "tabIndex"]);
345
+ var base = defaultSchema.attributes ?? {};
346
+ var sanitizeSchema = {
347
+ ...defaultSchema,
348
+ tagNames: [...defaultSchema.tagNames ?? [], ...SVG_TAGS],
349
+ attributes: {
350
+ ...base,
351
+ "*": (base["*"] ?? []).filter((attribute) => typeof attribute !== "string" || !DROPPED.has(attribute)),
352
+ ...Object.fromEntries(SVG_TAGS.map((tag) => [tag, [...SVG_COMMON, ...svgAttributes[tag] ?? []]]))
353
+ },
354
+ protocols: {
355
+ ...defaultSchema.protocols,
356
+ href: ["http", "https", "mailto"],
357
+ src: ["http", "https"]
358
+ },
359
+ // Dropped with their content. Other disallowed elements, such as `form`, are
360
+ // unwrapped and their content kept.
361
+ strip: ["script", "style", "foreignObject", "iframe", "noscript", "template"]
362
+ };
363
+ var CLOBBER_PREFIX = defaultSchema.clobberPrefix ?? "user-content-";
364
+ var isElement = (node) => node.type === "element";
365
+ function walk(node, visit, inSvg = false) {
366
+ for (const child of node.children) {
367
+ if (!isElement(child)) continue;
368
+ const svg = inSvg || child.tagName === "svg";
369
+ visit(child, node, svg);
370
+ walk(child, visit, svg);
209
371
  }
210
- return (
211
- // `role="list"`: Safari drops the list role from a list styled with
212
- // `list-style: none`, which this one is, for its number badges.
213
- /* @__PURE__ */ jsx("ol", { start: list.items[0].n, role: "list", children: list.items.map((item, i) => /* @__PURE__ */ jsxs("li", { value: item.n, children: [
214
- /* @__PURE__ */ jsx("span", { className: "seclai-markdown-number", children: item.n }),
215
- /* @__PURE__ */ jsxs("div", { children: [
216
- withBreaks(item.lines, inline),
217
- item.lists.map(renderList)
218
- ] })
219
- ] }, i)) }, key)
220
- );
221
372
  }
222
- function MarkdownContent({ content }) {
223
- return /* @__PURE__ */ jsx("div", { className: "seclai-markdown", children: parse(content).map((block, i) => {
224
- switch (block.type) {
225
- case "ol":
226
- case "ul":
227
- return renderList(block, i);
228
- case "hr":
229
- return /* @__PURE__ */ jsx("hr", {}, i);
230
- default:
231
- return /* @__PURE__ */ jsx("p", { children: withBreaks(block.lines, block.verbatim ? (line) => line : inline) }, i);
373
+ var URL_REFERENCE = /url\(\s*(['"]?)([^)'"]*)\1\s*\)/gi;
374
+ function rehypeSafeReferences() {
375
+ return (tree) => {
376
+ walk(tree, (element, _parent, inSvg) => {
377
+ const { properties } = element;
378
+ for (const key of Object.keys(properties)) {
379
+ const value = properties[key];
380
+ if (typeof value !== "string") continue;
381
+ if (key === "href" || key === "xLinkHref") {
382
+ if (value.startsWith("#")) {
383
+ properties[key] = `#${CLOBBER_PREFIX}${value.slice(1)}`;
384
+ } else if (inSvg && element.tagName !== "a") {
385
+ delete properties[key];
386
+ }
387
+ continue;
388
+ }
389
+ if (inSvg && /url\(/i.test(value)) {
390
+ let external2 = false;
391
+ const rewritten = value.replace(URL_REFERENCE, (_, _quote, target) => {
392
+ if (!target.startsWith("#")) external2 = true;
393
+ return `url(#${CLOBBER_PREFIX}${target.slice(1)})`;
394
+ });
395
+ if (external2 || /url\(/i.test(rewritten.replace(URL_REFERENCE, ""))) delete properties[key];
396
+ else properties[key] = rewritten;
397
+ }
398
+ }
399
+ });
400
+ };
401
+ }
402
+ function rehypeImagesInLinks() {
403
+ return (tree) => {
404
+ const inLink = (node, linked) => {
405
+ node.children.forEach((child, index) => {
406
+ if (!isElement(child)) return;
407
+ if (linked && child.tagName === "img") {
408
+ const alt = child.properties.alt;
409
+ node.children[index] = { type: "text", value: typeof alt === "string" ? alt : "" };
410
+ return;
411
+ }
412
+ inLink(child, linked || child.tagName === "a");
413
+ });
414
+ };
415
+ inLink(tree, false);
416
+ };
417
+ }
418
+
419
+ // src/markdown/MarkdownContent.tsx
420
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
421
+ var SAFE_PROTOCOL = /^(?:https?|mailto)$/i;
422
+ function safeUrl(url) {
423
+ const colon = url.indexOf(":");
424
+ if (colon === -1) return url;
425
+ for (const char of ["/", "?", "#"]) {
426
+ const index = url.indexOf(char);
427
+ if (index !== -1 && index < colon) return url;
428
+ }
429
+ return SAFE_PROTOCOL.test(url.slice(0, colon)) ? url : void 0;
430
+ }
431
+ var isExternal = (href) => /^(?:https?:)?\/\//i.test(href);
432
+ var external = { target: "_blank", rel: "noopener noreferrer" };
433
+ function Link({ node: _node, href, children, ...props }) {
434
+ if (!href) return /* @__PURE__ */ jsx2(Fragment, { children });
435
+ return /* @__PURE__ */ jsx2("a", { ...props, href, ...isExternal(href) ? external : void 0, children });
436
+ }
437
+ function Image({ src, alt, title }) {
438
+ if (typeof src !== "string" || !src) return alt ? /* @__PURE__ */ jsx2(Fragment, { children: alt }) : null;
439
+ return /* @__PURE__ */ jsx2("a", { className: "seclai-markdown-image", href: src, title, ...isExternal(src) ? external : void 0, children: alt || src });
440
+ }
441
+ function Table({ node: _node, ...props }) {
442
+ return /* @__PURE__ */ jsx2("div", { className: "seclai-markdown-table", children: /* @__PURE__ */ jsx2("table", { ...props }) });
443
+ }
444
+ var components = { a: Link, img: Image, table: Table };
445
+ var pipelines = /* @__PURE__ */ new Map();
446
+ var extensionIds = /* @__PURE__ */ new WeakMap();
447
+ var nextExtensionId = 0;
448
+ function pipelineFor(extensions) {
449
+ const key = extensions.map((extension) => {
450
+ let id = extensionIds.get(extension);
451
+ if (id === void 0) extensionIds.set(extension, id = nextExtensionId++);
452
+ return id;
453
+ }).join(",");
454
+ const cached = pipelines.get(key);
455
+ if (cached) {
456
+ pipelines.delete(key);
457
+ pipelines.set(key, cached);
458
+ return cached;
459
+ }
460
+ const pipeline = {
461
+ remarkPlugins: [
462
+ remarkGfm,
463
+ ...extensions.flatMap((extension) => extension.remarkPlugins ?? []),
464
+ remarkListNumbers,
465
+ remarkLineBreaks,
466
+ remarkHtmlBreaks
467
+ ],
468
+ rehypePlugins: [
469
+ ...extensions.flatMap((extension) => extension.rehypePluginsBeforeSanitize ?? []),
470
+ rehypeRawAsText,
471
+ [rehypeSanitize, sanitizeSchema],
472
+ rehypeSafeReferences,
473
+ rehypeImagesInLinks,
474
+ rehypeListBadges,
475
+ rehypeTrimBlocks,
476
+ ...extensions.flatMap((extension) => extension.rehypePlugins ?? [])
477
+ ],
478
+ components: Object.assign({}, components, ...extensions.map((extension) => extension.components)),
479
+ transforms: extensions.flatMap((extension) => extension.transform ? [extension.transform] : []),
480
+ rawHtml: extensions.some((extension) => extension.rehypePluginsBeforeSanitize?.length)
481
+ };
482
+ if (pipelines.size >= 50) pipelines.delete(pipelines.keys().next().value);
483
+ pipelines.set(key, pipeline);
484
+ return pipeline;
485
+ }
486
+ function remarkOnTree(onTree) {
487
+ return (tree, file) => onTree(tree, String(file.value));
488
+ }
489
+ var Block = memo(
490
+ function Block2({ text, pipeline, onTree }) {
491
+ return /* @__PURE__ */ jsx2(
492
+ Markdown,
493
+ {
494
+ remarkPlugins: onTree ? [[remarkOnTree, onTree], ...pipeline.remarkPlugins] : pipeline.remarkPlugins,
495
+ rehypePlugins: pipeline.rehypePlugins,
496
+ components: pipeline.components,
497
+ urlTransform: safeUrl,
498
+ children: text
499
+ }
500
+ );
501
+ },
502
+ (a, b) => a.text === b.text && a.pipeline === b.pipeline && !a.onTree === !b.onTree
503
+ );
504
+ var Splitter = class {
505
+ doc = "";
506
+ pipeline;
507
+ /** Where each block after the first starts. */
508
+ starts = [];
509
+ /** How much of the text the splits depend on: up to the end of the last split's line. */
510
+ settled = 0;
511
+ update(doc, pipeline) {
512
+ const split = !MAY_DEFINE.test(doc);
513
+ if (!split || pipeline !== this.pipeline || !doc.startsWith(this.doc.slice(0, this.settled))) {
514
+ this.starts = [];
515
+ this.settled = 0;
232
516
  }
517
+ this.doc = doc;
518
+ this.pipeline = pipeline;
519
+ const starts = [0, ...this.starts];
520
+ if (!split) return { starts };
521
+ const tail = starts.at(-1);
522
+ const onTree = (tree, source) => {
523
+ if (this.doc !== doc) return;
524
+ for (const point of splitPoints(tree, source, pipeline.rawHtml)) {
525
+ const at = tail + point;
526
+ if (at - (this.starts.at(-1) ?? 0) < splitting.minBlock) continue;
527
+ this.starts.push(at);
528
+ this.settled = doc.indexOf("\n", at) + 1;
529
+ }
530
+ };
531
+ return { starts, onTree };
532
+ }
533
+ };
534
+ var MarkdownContent = memo(function MarkdownContent2({
535
+ content,
536
+ streaming = false,
537
+ extensions
538
+ }) {
539
+ const fromProvider = useMarkdownExtensions();
540
+ const pipeline = pipelineFor(extensions ?? fromProvider);
541
+ const [splitter] = useState2(() => new Splitter());
542
+ let doc = normalizeNewlines(content);
543
+ if (streaming) doc = holdBackPendingLine(doc);
544
+ doc = normalizeBullets(doc);
545
+ for (const transform of pipeline.transforms) doc = transform(doc);
546
+ const { starts, onTree } = splitter.update(doc, pipeline);
547
+ return /* @__PURE__ */ jsx2("div", { className: "seclai-markdown", children: starts.map((start, i) => {
548
+ const last = i === starts.length - 1;
549
+ return /* @__PURE__ */ jsx2(
550
+ Block,
551
+ {
552
+ text: doc.slice(start, last ? void 0 : starts[i + 1]),
553
+ pipeline,
554
+ onTree: last ? onTree : void 0
555
+ },
556
+ start
557
+ );
233
558
  }) });
234
- }
559
+ });
235
560
 
236
561
  // src/media/MediaGallery.tsx
237
- import { useEffect as useEffect4, useRef as useRef3, useState as useState3 } from "react";
562
+ import { useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
238
563
 
239
564
  // src/placeholders/MediaPreview.tsx
240
- import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
565
+ import { useEffect as useEffect2, useRef, useState as useState3 } from "react";
241
566
 
242
567
  // src/media/files.ts
243
568
  var EXTENSIONS = {
@@ -264,8 +589,8 @@ function extensionForMime(mime) {
264
589
  }
265
590
  function attachmentFileName(attachment, number) {
266
591
  if (attachment.name) return attachment.name;
267
- const base = number != null ? `image-${number}` : attachment.id;
268
- return `${base}.${extensionForMime(attachment.mime)}`;
592
+ const base2 = number != null ? `image-${number}` : attachment.id;
593
+ return `${base2}.${extensionForMime(attachment.mime)}`;
269
594
  }
270
595
  var SAFE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
271
596
  function isSafeUrl(url) {
@@ -322,7 +647,7 @@ function wait(ms, signal) {
322
647
  }
323
648
 
324
649
  // src/placeholders/MediaPreview.tsx
325
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
650
+ import { Fragment as Fragment2, jsx as jsx3, jsxs } from "react/jsx-runtime";
326
651
  function hasContent(node) {
327
652
  return node != null && node !== false && node !== "";
328
653
  }
@@ -336,12 +661,12 @@ function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }) {
336
661
  const filename = attachmentFileName(attachment, number);
337
662
  const extra = typeof actions === "function" ? actions(attachment) : actions;
338
663
  if (!isImage(attachment)) {
339
- return /* @__PURE__ */ jsx2("figure", { className: "seclai-media", children: /* @__PURE__ */ jsxs2("figcaption", { children: [
340
- /* @__PURE__ */ jsx2("a", { href: attachment.url, download: filename, children: attachment.name ?? filename }),
341
- hasContent(extra) && /* @__PURE__ */ jsx2("span", { className: "seclai-media-actions", children: extra })
664
+ return /* @__PURE__ */ jsx3("figure", { className: "seclai-media", children: /* @__PURE__ */ jsxs("figcaption", { children: [
665
+ /* @__PURE__ */ jsx3("a", { href: attachment.url, download: filename, children: attachment.name ?? filename }),
666
+ hasContent(extra) && /* @__PURE__ */ jsx3("span", { className: "seclai-media-actions", children: extra })
342
667
  ] }) });
343
668
  }
344
- return /* @__PURE__ */ jsx2(
669
+ return /* @__PURE__ */ jsx3(
345
670
  ImageCard,
346
671
  {
347
672
  attachment,
@@ -355,8 +680,8 @@ function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }) {
355
680
  }
356
681
  function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen }) {
357
682
  const img = useRef(null);
358
- const [natural, setNatural] = useState2(null);
359
- const [failed, setFailed] = useState2(false);
683
+ const [natural, setNatural] = useState3(null);
684
+ const [failed, setFailed] = useState3(false);
360
685
  const label = imageLabel(attachment, number);
361
686
  function measure() {
362
687
  const el = img.current;
@@ -373,8 +698,8 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
373
698
  else measure();
374
699
  }
375
700
  }, [attachment.url]);
376
- const frameContent = /* @__PURE__ */ jsxs2(Fragment2, { children: [
377
- failed ? /* @__PURE__ */ jsx2("span", { className: "seclai-media-error", children: "Couldn't load the image." }) : /* @__PURE__ */ jsx2(
701
+ const frameContent = /* @__PURE__ */ jsxs(Fragment2, { children: [
702
+ failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the image." }) : /* @__PURE__ */ jsx3(
378
703
  "img",
379
704
  {
380
705
  ref: img,
@@ -386,11 +711,11 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
386
711
  onError: () => setFailed(true)
387
712
  }
388
713
  ),
389
- number != null && /* @__PURE__ */ jsx2("span", { className: "seclai-media-badge", children: number })
714
+ number != null && /* @__PURE__ */ jsx3("span", { className: "seclai-media-badge", children: number })
390
715
  ] });
391
716
  const frameStyle = aspectRatioStyle(aspectRatio ?? natural ?? void 0);
392
- return /* @__PURE__ */ jsxs2("figure", { className: "seclai-media seclai-media-image", children: [
393
- onOpen ? /* @__PURE__ */ jsx2(
717
+ return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-image", children: [
718
+ onOpen ? /* @__PURE__ */ jsx3(
394
719
  "button",
395
720
  {
396
721
  type: "button",
@@ -401,27 +726,27 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
401
726
  onClick: onOpen,
402
727
  children: frameContent
403
728
  }
404
- ) : /* @__PURE__ */ jsx2("div", { className: "seclai-media-frame", style: frameStyle, children: frameContent }),
405
- /* @__PURE__ */ jsxs2("figcaption", { className: "seclai-media-bar", children: [
406
- /* @__PURE__ */ jsx2("a", { href: attachment.url, download: filename, "aria-label": `Download ${label}`, children: "Download" }),
407
- hasContent(extra) && /* @__PURE__ */ jsx2("span", { className: "seclai-media-actions", children: extra })
729
+ ) : /* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", style: frameStyle, children: frameContent }),
730
+ /* @__PURE__ */ jsxs("figcaption", { className: "seclai-media-bar", children: [
731
+ /* @__PURE__ */ jsx3("a", { href: attachment.url, download: filename, "aria-label": `Download ${label}`, children: "Download" }),
732
+ hasContent(extra) && /* @__PURE__ */ jsx3("span", { className: "seclai-media-actions", children: extra })
408
733
  ] })
409
734
  ] });
410
735
  }
411
736
 
412
737
  // src/media/MediaSkeleton.tsx
413
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
738
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
414
739
  function MediaSkeleton({ aspectRatio, number, label }) {
415
740
  const name = label ?? (number != null ? `Image ${number} is being generated` : "Image is being generated");
416
- return /* @__PURE__ */ jsxs3("div", { className: "seclai-media seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
417
- /* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio), children: number != null && /* @__PURE__ */ jsx3("span", { className: "seclai-media-badge", children: number }) }),
418
- /* @__PURE__ */ jsx3("div", { className: "seclai-media-bar", children: /* @__PURE__ */ jsx3("span", { className: "seclai-media-skeleton-line" }) })
741
+ return /* @__PURE__ */ jsxs2("div", { className: "seclai-media seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
742
+ /* @__PURE__ */ jsx4("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio), children: number != null && /* @__PURE__ */ jsx4("span", { className: "seclai-media-badge", children: number }) }),
743
+ /* @__PURE__ */ jsx4("div", { className: "seclai-media-bar", children: /* @__PURE__ */ jsx4("span", { className: "seclai-media-skeleton-line" }) })
419
744
  ] });
420
745
  }
421
746
 
422
747
  // src/media/MediaViewer.tsx
423
748
  import { useEffect as useEffect3, useId, useRef as useRef2 } from "react";
424
- import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
749
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
425
750
  function MediaViewer({ attachments, index, onIndexChange, onClose }) {
426
751
  const dialog = useRef2(null);
427
752
  const closeButton = useRef2(null);
@@ -482,7 +807,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
482
807
  }
483
808
  const number = index != null ? index + 1 : 0;
484
809
  const label = current ? imageLabel(current, number) : "";
485
- return /* @__PURE__ */ jsx4(
810
+ return /* @__PURE__ */ jsx5(
486
811
  "dialog",
487
812
  {
488
813
  ref: dialog,
@@ -492,19 +817,19 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
492
817
  onCancel,
493
818
  onClose: onDialogClose,
494
819
  onClick,
495
- children: current && /* @__PURE__ */ jsxs4("div", { className: "seclai-viewer-body", children: [
496
- /* @__PURE__ */ jsx4("img", { className: "seclai-viewer-image", src: current.url, alt: label }),
497
- /* @__PURE__ */ jsxs4("div", { className: "seclai-viewer-bar", children: [
498
- /* @__PURE__ */ jsxs4("p", { className: "seclai-viewer-title", id: titleId, children: [
820
+ children: current && /* @__PURE__ */ jsxs3("div", { className: "seclai-viewer-body", children: [
821
+ /* @__PURE__ */ jsx5("img", { className: "seclai-viewer-image", src: current.url, alt: label }),
822
+ /* @__PURE__ */ jsxs3("div", { className: "seclai-viewer-bar", children: [
823
+ /* @__PURE__ */ jsxs3("p", { className: "seclai-viewer-title", id: titleId, children: [
499
824
  label,
500
- attachments.length > 1 && /* @__PURE__ */ jsxs4("span", { className: "seclai-viewer-count", children: [
825
+ attachments.length > 1 && /* @__PURE__ */ jsxs3("span", { className: "seclai-viewer-count", children: [
501
826
  number,
502
827
  " of ",
503
828
  attachments.length
504
829
  ] })
505
830
  ] }),
506
- attachments.length > 1 && /* @__PURE__ */ jsxs4(Fragment3, { children: [
507
- /* @__PURE__ */ jsx4(
831
+ attachments.length > 1 && /* @__PURE__ */ jsxs3(Fragment3, { children: [
832
+ /* @__PURE__ */ jsx5(
508
833
  "button",
509
834
  {
510
835
  type: "button",
@@ -514,9 +839,9 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
514
839
  children: "Previous"
515
840
  }
516
841
  ),
517
- /* @__PURE__ */ jsx4("button", { type: "button", className: "seclai-button", "aria-disabled": atEnd, onClick: () => go(1), children: "Next" })
842
+ /* @__PURE__ */ jsx5("button", { type: "button", className: "seclai-button", "aria-disabled": atEnd, onClick: () => go(1), children: "Next" })
518
843
  ] }),
519
- /* @__PURE__ */ jsx4(
844
+ /* @__PURE__ */ jsx5(
520
845
  "a",
521
846
  {
522
847
  className: "seclai-button seclai-button-primary",
@@ -525,7 +850,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
525
850
  children: "Download"
526
851
  }
527
852
  ),
528
- /* @__PURE__ */ jsx4("button", { type: "button", className: "seclai-button", ref: closeButton, onClick: onClose, children: "Close" })
853
+ /* @__PURE__ */ jsx5("button", { type: "button", className: "seclai-button", ref: closeButton, onClick: onClose, children: "Close" })
529
854
  ] })
530
855
  ] })
531
856
  }
@@ -533,7 +858,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
533
858
  }
534
859
 
535
860
  // src/media/MediaGallery.tsx
536
- import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
861
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
537
862
  var DOWNLOAD_ALL_DELAY_MS = SAVE_FILES_DELAY_MS;
538
863
  function MediaGallery({
539
864
  attachments,
@@ -543,8 +868,8 @@ function MediaGallery({
543
868
  }) {
544
869
  const images = attachments.filter(isImage);
545
870
  const files = attachments.filter((attachment) => !isImage(attachment));
546
- const [viewing, setViewing] = useState3(null);
547
- const [downloading, setDownloading] = useState3(false);
871
+ const [viewing, setViewing] = useState4(null);
872
+ const [downloading, setDownloading] = useState4(false);
548
873
  const abort = useRef3(null);
549
874
  useEffect4(() => () => abort.current?.abort(), []);
550
875
  if (viewing != null && viewing >= images.length) setViewing(null);
@@ -563,9 +888,9 @@ function MediaGallery({
563
888
  }
564
889
  }
565
890
  const skeletons = Math.max(0, Math.floor(pending));
566
- return /* @__PURE__ */ jsxs5("div", { className: "seclai-gallery", children: [
567
- images.length + skeletons > 0 && /* @__PURE__ */ jsxs5("ul", { className: "seclai-gallery-grid", children: [
568
- images.map((image, i) => /* @__PURE__ */ jsx5("li", { children: /* @__PURE__ */ jsx5(
891
+ return /* @__PURE__ */ jsxs4("div", { className: "seclai-gallery", children: [
892
+ images.length + skeletons > 0 && /* @__PURE__ */ jsxs4("ul", { className: "seclai-gallery-grid", children: [
893
+ images.map((image, i) => /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6(
569
894
  MediaPreview,
570
895
  {
571
896
  attachment: image,
@@ -575,9 +900,9 @@ function MediaGallery({
575
900
  onOpen: () => setViewing(i)
576
901
  }
577
902
  ) }, image.id)),
578
- Array.from({ length: skeletons }, (_, i) => /* @__PURE__ */ jsx5("li", { children: /* @__PURE__ */ jsx5(MediaSkeleton, { aspectRatio, number: images.length + i + 1 }) }, `pending-${i}`))
903
+ Array.from({ length: skeletons }, (_, i) => /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6(MediaSkeleton, { aspectRatio, number: images.length + i + 1 }) }, `pending-${i}`))
579
904
  ] }),
580
- images.length > 1 && /* @__PURE__ */ jsx5("div", { className: "seclai-gallery-actions", children: /* @__PURE__ */ jsx5(
905
+ images.length > 1 && /* @__PURE__ */ jsx6("div", { className: "seclai-gallery-actions", children: /* @__PURE__ */ jsx6(
581
906
  "button",
582
907
  {
583
908
  type: "button",
@@ -587,8 +912,8 @@ function MediaGallery({
587
912
  children: downloading ? "Downloading\u2026" : `Download all ${images.length}`
588
913
  }
589
914
  ) }),
590
- files.map((file) => /* @__PURE__ */ jsx5(MediaPreview, { attachment: file }, file.id)),
591
- images.length > 0 && /* @__PURE__ */ jsx5(
915
+ files.map((file) => /* @__PURE__ */ jsx6(MediaPreview, { attachment: file }, file.id)),
916
+ images.length > 0 && /* @__PURE__ */ jsx6(
592
917
  MediaViewer,
593
918
  {
594
919
  attachments: images,
@@ -601,10 +926,10 @@ function MediaGallery({
601
926
  }
602
927
 
603
928
  // src/RunProgress.tsx
604
- import { useEffect as useEffect5, useState as useState4 } from "react";
605
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
929
+ import { useEffect as useEffect5, useState as useState5 } from "react";
930
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
606
931
  function useElapsed(startedAt, running) {
607
- const [now, setNow] = useState4(null);
932
+ const [now, setNow] = useState5(null);
608
933
  useEffect5(() => {
609
934
  if (!running || startedAt === null) return;
610
935
  let timer;
@@ -636,27 +961,27 @@ function RunProgress({ run, showSteps = true, message, className }) {
636
961
  if (!running) return null;
637
962
  const note = typeof message === "function" ? message(seconds) : message;
638
963
  const last = run.steps.length - 1;
639
- return /* @__PURE__ */ jsxs6(
964
+ return /* @__PURE__ */ jsxs5(
640
965
  "div",
641
966
  {
642
967
  className: className ? `seclai-run-progress ${className}` : "seclai-run-progress",
643
968
  "aria-live": "polite",
644
969
  children: [
645
- showSteps && (run.steps.length === 0 ? /* @__PURE__ */ jsx6("p", { className: "seclai-notice", children: "Starting the run\u2026" }) : /* @__PURE__ */ jsx6("ol", { className: "seclai-steps", children: run.steps.map((step, i) => /* @__PURE__ */ jsxs6("li", { children: [
646
- /* @__PURE__ */ jsx6("span", { className: "seclai-step-marker", "aria-hidden": "true", children: i === last ? "\u25CF" : "\u2713" }),
647
- /* @__PURE__ */ jsx6("span", { className: "seclai-sr-only", children: i === last ? "In progress: " : "Done: " }),
648
- /* @__PURE__ */ jsxs6("span", { children: [
649
- /* @__PURE__ */ jsx6("span", { className: "seclai-step-name", children: step.name }),
650
- step.message && /* @__PURE__ */ jsxs6("span", { className: "seclai-step-message", children: [
970
+ showSteps && (run.steps.length === 0 ? /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Starting the run\u2026" }) : /* @__PURE__ */ jsx7("ol", { className: "seclai-steps", children: run.steps.map((step, i) => /* @__PURE__ */ jsxs5("li", { children: [
971
+ /* @__PURE__ */ jsx7("span", { className: "seclai-step-marker", "aria-hidden": "true", children: i === last ? "\u25CF" : "\u2713" }),
972
+ /* @__PURE__ */ jsx7("span", { className: "seclai-sr-only", children: i === last ? "In progress: " : "Done: " }),
973
+ /* @__PURE__ */ jsxs5("span", { children: [
974
+ /* @__PURE__ */ jsx7("span", { className: "seclai-step-name", children: step.name }),
975
+ step.message && /* @__PURE__ */ jsxs5("span", { className: "seclai-step-message", children: [
651
976
  " \xB7 ",
652
977
  step.message
653
978
  ] })
654
979
  ] })
655
980
  ] }, step.id)) })),
656
- /* @__PURE__ */ jsxs6("div", { className: "seclai-run-progress-note", children: [
657
- /* @__PURE__ */ jsx6("span", { className: "seclai-run-progress-pulse", "aria-hidden": "true" }),
658
- note != null && note !== false && note !== "" && /* @__PURE__ */ jsx6("span", { className: "seclai-run-progress-message", children: note }),
659
- /* @__PURE__ */ jsx6(
981
+ /* @__PURE__ */ jsxs5("div", { className: "seclai-run-progress-note", children: [
982
+ /* @__PURE__ */ jsx7("span", { className: "seclai-run-progress-pulse", "aria-hidden": "true" }),
983
+ note != null && note !== false && note !== "" && /* @__PURE__ */ jsx7("span", { className: "seclai-run-progress-message", children: note }),
984
+ /* @__PURE__ */ jsx7(
660
985
  "span",
661
986
  {
662
987
  className: "seclai-run-progress-clock",
@@ -673,7 +998,7 @@ function RunProgress({ run, showSteps = true, message, className }) {
673
998
  }
674
999
 
675
1000
  // src/useAgentRun.ts
676
- import { useCallback, useEffect as useEffect6, useMemo, useRef as useRef4, useState as useState5 } from "react";
1001
+ import { useCallback, useEffect as useEffect6, useMemo, useRef as useRef4, useState as useState6 } from "react";
677
1002
 
678
1003
  // src/sse.ts
679
1004
  function parseData(data) {
@@ -820,7 +1145,7 @@ function applyEvent(state, { event, data }, endpoints) {
820
1145
  function useAgentRun(options = {}) {
821
1146
  const { basePath, agentId, onEvent } = options;
822
1147
  const endpoints = useMemo(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
823
- const [state, setState] = useState5(IDLE);
1148
+ const [state, setState] = useState6(IDLE);
824
1149
  const active = useRef4(null);
825
1150
  const onEventRef = useRef4(onEvent);
826
1151
  useEffect6(() => {
@@ -898,7 +1223,7 @@ function useAgentRun(options = {}) {
898
1223
  }
899
1224
 
900
1225
  // src/AgentChat.tsx
901
- import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1226
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
902
1227
  function createSessionId() {
903
1228
  if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
904
1229
  return Array.from(
@@ -922,13 +1247,13 @@ function plural(count, word) {
922
1247
  }
923
1248
  function FileChip({ name, tag, preview, status, error, onRemove }) {
924
1249
  const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
925
- return /* @__PURE__ */ jsxs7("li", { className: "seclai-file", "data-status": status, children: [
926
- preview && /* @__PURE__ */ jsx7("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
927
- /* @__PURE__ */ jsxs7("span", { className: "seclai-file-text", children: [
928
- /* @__PURE__ */ jsx7("span", { className: "seclai-file-name", title: name, children: name }),
929
- meta && /* @__PURE__ */ jsx7("span", { className: "seclai-file-meta", children: meta })
1250
+ return /* @__PURE__ */ jsxs6("li", { className: "seclai-file", "data-status": status, children: [
1251
+ preview && /* @__PURE__ */ jsx8("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
1252
+ /* @__PURE__ */ jsxs6("span", { className: "seclai-file-text", children: [
1253
+ /* @__PURE__ */ jsx8("span", { className: "seclai-file-name", title: name, children: name }),
1254
+ meta && /* @__PURE__ */ jsx8("span", { className: "seclai-file-meta", children: meta })
930
1255
  ] }),
931
- onRemove && /* @__PURE__ */ jsx7(
1256
+ onRemove && /* @__PURE__ */ jsx8(
932
1257
  "button",
933
1258
  {
934
1259
  type: "button",
@@ -941,8 +1266,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
941
1266
  ] });
942
1267
  }
943
1268
  function UserTurn({ message, previews }) {
944
- return /* @__PURE__ */ jsxs7("li", { className: "seclai-turn seclai-turn-user", children: [
945
- message.files.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-files", "aria-label": "Attached files", children: message.files.map((file) => /* @__PURE__ */ jsx7(
1269
+ return /* @__PURE__ */ jsxs6("li", { className: "seclai-turn seclai-turn-user", children: [
1270
+ message.files.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-files", "aria-label": "Attached files", children: message.files.map((file) => /* @__PURE__ */ jsx8(
946
1271
  FileChip,
947
1272
  {
948
1273
  name: file.name,
@@ -951,14 +1276,14 @@ function UserTurn({ message, previews }) {
951
1276
  },
952
1277
  file.uploadId
953
1278
  )) }),
954
- message.input && /* @__PURE__ */ jsx7(MarkdownContent, { content: message.input })
1279
+ message.input && /* @__PURE__ */ jsx8(MarkdownContent, { content: message.input })
955
1280
  ] });
956
1281
  }
957
1282
  function AssistantTurn({ turn, endpoints }) {
958
1283
  const { runId } = turn;
959
- return /* @__PURE__ */ jsxs7("li", { className: "seclai-turn seclai-turn-assistant", children: [
960
- turn.output && /* @__PURE__ */ jsx7(MarkdownContent, { content: turn.output }),
961
- runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ jsx7(
1284
+ return /* @__PURE__ */ jsxs6("li", { className: "seclai-turn seclai-turn-assistant", children: [
1285
+ turn.output && /* @__PURE__ */ jsx8(MarkdownContent, { content: turn.output }),
1286
+ runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ jsx8(
962
1287
  MediaGallery,
963
1288
  {
964
1289
  attachments: turn.attachments.map(({ id, name, mime, bytes }) => ({
@@ -970,8 +1295,8 @@ function AssistantTurn({ turn, endpoints }) {
970
1295
  }))
971
1296
  }
972
1297
  ),
973
- turn.error && /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: turn.error }),
974
- turn.status === "cancelled" && /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Stopped." })
1298
+ turn.error && /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: turn.error }),
1299
+ turn.status === "cancelled" && /* @__PURE__ */ jsx8("p", { className: "seclai-notice", children: "Stopped." })
975
1300
  ] });
976
1301
  }
977
1302
  function toTurnAttachment({ id, name, mime, bytes }) {
@@ -984,9 +1309,9 @@ function AttachControl({
984
1309
  disabled,
985
1310
  onFiles
986
1311
  }) {
987
- return /* @__PURE__ */ jsxs7("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
1312
+ return /* @__PURE__ */ jsxs6("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
988
1313
  label,
989
- /* @__PURE__ */ jsx7(
1314
+ /* @__PURE__ */ jsx8(
990
1315
  "input",
991
1316
  {
992
1317
  type: "file",
@@ -1016,7 +1341,7 @@ function AgentChat({
1016
1341
  const endpoints = useMemo2(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
1017
1342
  const run = useAgentRun({ basePath, agentId });
1018
1343
  const { slots } = useAcceptedAttachments(endpoints);
1019
- const [transcript, setTranscript] = useState6(() => ({
1344
+ const [transcript, setTranscript] = useState7(() => ({
1020
1345
  sessionId,
1021
1346
  epoch: 0,
1022
1347
  turns: initialTurns ?? [],
@@ -1024,10 +1349,10 @@ function AgentChat({
1024
1349
  generatedSessionId: null,
1025
1350
  runEpoch: null
1026
1351
  }));
1027
- const [message, setMessage] = useState6("");
1028
- const [files, setFiles] = useState6([]);
1029
- const [notice, setNotice] = useState6(null);
1030
- const [dragging, setDragging] = useState6(false);
1352
+ const [message, setMessage] = useState7("");
1353
+ const [files, setFiles] = useState7([]);
1354
+ const [notice, setNotice] = useState7(null);
1355
+ const [dragging, setDragging] = useState7(false);
1031
1356
  const generatedSessionId = useRef5(null);
1032
1357
  const shownEpoch = useRef5(transcript.epoch);
1033
1358
  const turnComplete = useRef5(onTurnComplete);
@@ -1218,29 +1543,29 @@ function AgentChat({
1218
1543
  }
1219
1544
  } : {};
1220
1545
  const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
1221
- return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent seclai-chat", children: [
1222
- /* @__PURE__ */ jsxs7("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": streaming, children: [
1223
- transcript.turns.map((turn, i) => /* @__PURE__ */ jsxs7(Fragment4, { children: [
1224
- /* @__PURE__ */ jsx7(
1546
+ return /* @__PURE__ */ jsxs6("div", { className: "seclai-agent seclai-chat", children: [
1547
+ /* @__PURE__ */ jsxs6("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": streaming, children: [
1548
+ transcript.turns.map((turn, i) => /* @__PURE__ */ jsxs6(Fragment4, { children: [
1549
+ /* @__PURE__ */ jsx8(
1225
1550
  UserTurn,
1226
1551
  {
1227
1552
  message: { input: turn.input, files: turn.files ?? [] },
1228
1553
  previews: sentPreviews.current
1229
1554
  }
1230
1555
  ),
1231
- /* @__PURE__ */ jsx7(AssistantTurn, { turn, endpoints })
1556
+ /* @__PURE__ */ jsx8(AssistantTurn, { turn, endpoints })
1232
1557
  ] }, `${transcript.epoch}:${i}`)),
1233
- transcript.pending && /* @__PURE__ */ jsx7(UserTurn, { message: transcript.pending, previews: sentPreviews.current }),
1234
- streaming && /* @__PURE__ */ jsx7("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ jsx7(MarkdownContent, { content: run.text }) : /* @__PURE__ */ jsx7(RunProgress, { run }) })
1558
+ transcript.pending && /* @__PURE__ */ jsx8(UserTurn, { message: transcript.pending, previews: sentPreviews.current }),
1559
+ streaming && /* @__PURE__ */ jsx8("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ jsx8(MarkdownContent, { content: run.text, streaming: true }) : /* @__PURE__ */ jsx8(RunProgress, { run }) })
1235
1560
  ] }),
1236
- /* @__PURE__ */ jsxs7(
1561
+ /* @__PURE__ */ jsxs6(
1237
1562
  "form",
1238
1563
  {
1239
1564
  className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
1240
1565
  onSubmit,
1241
1566
  ...dropHandlers,
1242
1567
  children: [
1243
- files.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx7(
1568
+ files.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx8(
1244
1569
  FileChip,
1245
1570
  {
1246
1571
  name: f.name,
@@ -1252,7 +1577,7 @@ function AgentChat({
1252
1577
  },
1253
1578
  f.localId
1254
1579
  )) }),
1255
- /* @__PURE__ */ jsx7(
1580
+ /* @__PURE__ */ jsx8(
1256
1581
  "textarea",
1257
1582
  {
1258
1583
  rows: 2,
@@ -1264,9 +1589,9 @@ function AgentChat({
1264
1589
  onPaste: acceptsFiles ? onPaste : void 0
1265
1590
  }
1266
1591
  ),
1267
- notice && /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: notice }),
1268
- /* @__PURE__ */ jsxs7("div", { className: "seclai-actions", children: [
1269
- acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx7(
1592
+ notice && /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: notice }),
1593
+ /* @__PURE__ */ jsxs6("div", { className: "seclai-actions", children: [
1594
+ acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx8(
1270
1595
  AttachControl,
1271
1596
  {
1272
1597
  label: button.label,
@@ -1277,8 +1602,8 @@ function AgentChat({
1277
1602
  },
1278
1603
  `${button.label}\0${button.tag ?? ""}`
1279
1604
  )),
1280
- /* @__PURE__ */ jsx7("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
1281
- running && /* @__PURE__ */ jsx7("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1605
+ /* @__PURE__ */ jsx8("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
1606
+ running && /* @__PURE__ */ jsx8("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1282
1607
  ] })
1283
1608
  ]
1284
1609
  }
@@ -1287,8 +1612,8 @@ function AgentChat({
1287
1612
  }
1288
1613
 
1289
1614
  // src/AgentRunForm.tsx
1290
- import { useMemo as useMemo3, useState as useState7 } from "react";
1291
- import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
1615
+ import { useMemo as useMemo3, useState as useState8 } from "react";
1616
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1292
1617
  function slotProblem(slot, count) {
1293
1618
  const label = slot.label ?? slot.name;
1294
1619
  const min = slot.min ?? 0;
@@ -1302,10 +1627,10 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
1302
1627
  const endpoints = useMemo3(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
1303
1628
  const run = useAgentRun({ basePath, agentId });
1304
1629
  const { slots, error: loadError } = useAcceptedAttachments(endpoints);
1305
- const [input, setInput] = useState7("");
1306
- const [files, setFiles] = useState7({});
1307
- const [uploading, setUploading] = useState7(false);
1308
- const [formError, setFormError] = useState7(null);
1630
+ const [input, setInput] = useState8("");
1631
+ const [files, setFiles] = useState8({});
1632
+ const [uploading, setUploading] = useState8(false);
1633
+ const [formError, setFormError] = useState8(null);
1309
1634
  const selected = Object.values(files).flat();
1310
1635
  const busy = uploading || run.status === "running";
1311
1636
  async function submit(event) {
@@ -1339,30 +1664,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
1339
1664
  onFinish?.(result);
1340
1665
  }
1341
1666
  if (loadError) {
1342
- return /* @__PURE__ */ jsx8("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: loadError }) });
1667
+ return /* @__PURE__ */ jsx9("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx9("p", { className: "seclai-error", role: "alert", children: loadError }) });
1343
1668
  }
1344
1669
  if (!slots) {
1345
- return /* @__PURE__ */ jsxs8("div", { className: "seclai-agent", children: [
1346
- /* @__PURE__ */ jsx8("p", { className: "seclai-notice", children: "Loading\u2026" }),
1347
- /* @__PURE__ */ jsxs8("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
1348
- /* @__PURE__ */ jsx8("span", {}),
1349
- /* @__PURE__ */ jsx8("span", {})
1670
+ return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent", children: [
1671
+ /* @__PURE__ */ jsx9("p", { className: "seclai-notice", children: "Loading\u2026" }),
1672
+ /* @__PURE__ */ jsxs7("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
1673
+ /* @__PURE__ */ jsx9("span", {}),
1674
+ /* @__PURE__ */ jsx9("span", {})
1350
1675
  ] })
1351
1676
  ] });
1352
1677
  }
1353
1678
  const error = formError ?? run.error;
1354
- return /* @__PURE__ */ jsxs8("div", { className: "seclai-agent", children: [
1355
- /* @__PURE__ */ jsxs8("form", { className: "seclai-form", onSubmit: submit, children: [
1356
- /* @__PURE__ */ jsxs8("label", { className: "seclai-field", children: [
1357
- /* @__PURE__ */ jsx8("span", { children: inputLabel }),
1358
- /* @__PURE__ */ jsx8("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
1679
+ return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent", children: [
1680
+ /* @__PURE__ */ jsxs7("form", { className: "seclai-form", onSubmit: submit, children: [
1681
+ /* @__PURE__ */ jsxs7("label", { className: "seclai-field", children: [
1682
+ /* @__PURE__ */ jsx9("span", { children: inputLabel }),
1683
+ /* @__PURE__ */ jsx9("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
1359
1684
  ] }),
1360
- slots.map((slot) => /* @__PURE__ */ jsxs8("label", { className: "seclai-field", children: [
1361
- /* @__PURE__ */ jsxs8("span", { children: [
1685
+ slots.map((slot) => /* @__PURE__ */ jsxs7("label", { className: "seclai-field", children: [
1686
+ /* @__PURE__ */ jsxs7("span", { children: [
1362
1687
  slot.label ?? slot.name,
1363
1688
  (slot.min ?? 0) > 0 ? " (required)" : ""
1364
1689
  ] }),
1365
- /* @__PURE__ */ jsx8(
1690
+ /* @__PURE__ */ jsx9(
1366
1691
  "input",
1367
1692
  {
1368
1693
  type: "file",
@@ -1373,29 +1698,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
1373
1698
  }
1374
1699
  )
1375
1700
  ] }, slot.name)),
1376
- /* @__PURE__ */ jsxs8("div", { className: "seclai-actions", children: [
1377
- /* @__PURE__ */ jsx8("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
1378
- run.status === "running" && /* @__PURE__ */ jsx8("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1701
+ /* @__PURE__ */ jsxs7("div", { className: "seclai-actions", children: [
1702
+ /* @__PURE__ */ jsx9("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
1703
+ run.status === "running" && /* @__PURE__ */ jsx9("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1379
1704
  ] })
1380
1705
  ] }),
1381
- run.steps.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs8("li", { children: [
1706
+ run.steps.length > 0 && /* @__PURE__ */ jsx9("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs7("li", { children: [
1382
1707
  step.name,
1383
1708
  ": ",
1384
1709
  step.message
1385
1710
  ] }, step.id)) }),
1386
- error && /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: error }),
1387
- run.status === "cancelled" && /* @__PURE__ */ jsx8("p", { className: "seclai-notice", children: "Stopped." }),
1388
- (run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs8("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
1389
- run.text && /* @__PURE__ */ jsx8(MarkdownContent, { content: run.text }),
1390
- run.attachments.length > 0 && /* @__PURE__ */ jsx8(MediaGallery, { attachments: run.attachments })
1711
+ error && /* @__PURE__ */ jsx9("p", { className: "seclai-error", role: "alert", children: error }),
1712
+ run.status === "cancelled" && /* @__PURE__ */ jsx9("p", { className: "seclai-notice", children: "Stopped." }),
1713
+ (run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs7("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
1714
+ run.text && /* @__PURE__ */ jsx9(MarkdownContent, { content: run.text, streaming: run.status === "running" }),
1715
+ run.attachments.length > 0 && /* @__PURE__ */ jsx9(MediaGallery, { attachments: run.attachments })
1391
1716
  ] })
1392
1717
  ] });
1393
1718
  }
1394
1719
 
1395
1720
  // src/SeclaiAgent.tsx
1396
- import { jsx as jsx9 } from "react/jsx-runtime";
1721
+ import { jsx as jsx10 } from "react/jsx-runtime";
1397
1722
  function SeclaiAgent({ mode, basePath, agentId }) {
1398
- return mode === "chat" ? /* @__PURE__ */ jsx9(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx9(AgentRunForm, { basePath, agentId });
1723
+ return mode === "chat" ? /* @__PURE__ */ jsx10(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx10(AgentRunForm, { basePath, agentId });
1399
1724
  }
1400
1725
  export {
1401
1726
  AgentChat,
@@ -1408,6 +1733,7 @@ export {
1408
1733
  MediaViewer,
1409
1734
  RunProgress,
1410
1735
  SeclaiAgent,
1736
+ SeclaiMarkdownProvider,
1411
1737
  attachmentFileName,
1412
1738
  createEndpoints,
1413
1739
  fetchAttachmentReferences,