@seclai/react 0.0.17 → 0.0.19
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 +149 -24
- package/dist/chunk-OFKVHNZ6.js +117 -0
- package/dist/chunk-VRNPDCWI.js +134 -0
- package/dist/extensions-D2MHwNt1.d.ts +49 -0
- package/dist/html.d.ts +22 -0
- package/dist/html.js +11 -0
- package/dist/index.d.ts +79 -29
- package/dist/index.js +773 -297
- package/dist/math.d.ts +22 -0
- package/dist/math.js +106 -0
- package/dist/mermaid.d.ts +30 -0
- package/dist/mermaid.js +126 -0
- package/dist/styles.css +274 -15
- package/package.json +46 -2
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
|
|
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
|
|
36
|
+
const base2 = agentId ? `${trimmed}/${encodeURIComponent(agentId)}` : trimmed;
|
|
23
37
|
return {
|
|
24
|
-
attachmentReferences: `${
|
|
25
|
-
upload: `${
|
|
26
|
-
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 `${
|
|
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
|
|
73
|
+
const base2 = hashAt < 0 ? url : url.slice(0, hashAt);
|
|
60
74
|
const hash = hashAt < 0 ? "" : url.slice(hashAt);
|
|
61
|
-
const separator = !
|
|
62
|
-
return `${
|
|
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,448 @@ function messageFileLimits(slots) {
|
|
|
104
118
|
return { max, contentTypes: anyType ? [] : [...types] };
|
|
105
119
|
}
|
|
106
120
|
|
|
107
|
-
// src/
|
|
108
|
-
import {
|
|
109
|
-
import
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
continue;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
168
|
-
|
|
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
|
-
|
|
168
|
+
return;
|
|
180
169
|
}
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
let
|
|
187
|
-
for (const
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
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;
|
|
193
186
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
|
209
239
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
);
|
|
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
|
+
]);
|
|
221
251
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
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
|
|
238
|
-
|
|
239
|
-
// src/placeholders/MediaPreview.tsx
|
|
240
|
-
import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
562
|
+
import { useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
241
563
|
|
|
242
564
|
// src/media/files.ts
|
|
243
565
|
var EXTENSIONS = {
|
|
@@ -251,11 +573,22 @@ var EXTENSIONS = {
|
|
|
251
573
|
"text/markdown": "md",
|
|
252
574
|
"application/octet-stream": "bin"
|
|
253
575
|
};
|
|
576
|
+
function baseMime(mime) {
|
|
577
|
+
return mime.split(";")[0].trim().toLowerCase();
|
|
578
|
+
}
|
|
254
579
|
function isImage(attachment) {
|
|
255
|
-
return attachment.mime
|
|
580
|
+
return baseMime(attachment.mime).startsWith("image/");
|
|
581
|
+
}
|
|
582
|
+
function mediaKind(attachment) {
|
|
583
|
+
const type = baseMime(attachment.mime);
|
|
584
|
+
if (type.startsWith("image/")) return "image";
|
|
585
|
+
if (type.startsWith("audio/")) return "audio";
|
|
586
|
+
if (type.startsWith("video/")) return "video";
|
|
587
|
+
if (type === "application/pdf") return "pdf";
|
|
588
|
+
return null;
|
|
256
589
|
}
|
|
257
590
|
function extensionForMime(mime) {
|
|
258
|
-
const type = mime
|
|
591
|
+
const type = baseMime(mime);
|
|
259
592
|
const known = EXTENSIONS[type];
|
|
260
593
|
if (known) return known;
|
|
261
594
|
const subtype = type.split("/")[1] ?? "";
|
|
@@ -264,8 +597,8 @@ function extensionForMime(mime) {
|
|
|
264
597
|
}
|
|
265
598
|
function attachmentFileName(attachment, number) {
|
|
266
599
|
if (attachment.name) return attachment.name;
|
|
267
|
-
const
|
|
268
|
-
return `${
|
|
600
|
+
const base2 = number != null ? `${mediaKind(attachment) ?? "file"}-${number}` : attachment.id;
|
|
601
|
+
return `${base2}.${extensionForMime(attachment.mime)}`;
|
|
269
602
|
}
|
|
270
603
|
var SAFE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
|
|
271
604
|
function isSafeUrl(url) {
|
|
@@ -321,43 +654,75 @@ function wait(ms, signal) {
|
|
|
321
654
|
});
|
|
322
655
|
}
|
|
323
656
|
|
|
324
|
-
// src/
|
|
325
|
-
import {
|
|
657
|
+
// src/media/MediaPreview.tsx
|
|
658
|
+
import { useEffect as useEffect2, useRef, useState as useState3 } from "react";
|
|
659
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
326
660
|
function hasContent(node) {
|
|
327
661
|
return node != null && node !== false && node !== "";
|
|
328
662
|
}
|
|
329
663
|
function aspectRatioStyle(ratio) {
|
|
330
664
|
return ratio == null ? void 0 : { aspectRatio: String(ratio) };
|
|
331
665
|
}
|
|
332
|
-
|
|
333
|
-
|
|
666
|
+
var KIND_LABELS = {
|
|
667
|
+
image: "Image",
|
|
668
|
+
audio: "Audio",
|
|
669
|
+
video: "Video",
|
|
670
|
+
pdf: "PDF"
|
|
671
|
+
};
|
|
672
|
+
function kindLabel(attachment) {
|
|
673
|
+
const kind = mediaKind(attachment);
|
|
674
|
+
return kind ? KIND_LABELS[kind] : "File";
|
|
675
|
+
}
|
|
676
|
+
function mediaLabel(attachment, number) {
|
|
677
|
+
if (attachment.name) return attachment.name;
|
|
678
|
+
const kind = kindLabel(attachment);
|
|
679
|
+
return number != null ? `${kind} ${number}` : kind;
|
|
334
680
|
}
|
|
335
681
|
function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }) {
|
|
336
682
|
const filename = attachmentFileName(attachment, number);
|
|
337
683
|
const extra = typeof actions === "function" ? actions(attachment) : actions;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
684
|
+
const card = { attachment, number, filename, extra };
|
|
685
|
+
switch (mediaKind(attachment)) {
|
|
686
|
+
case "image":
|
|
687
|
+
return /* @__PURE__ */ jsx3(ImageCard, { ...card, aspectRatio, onOpen });
|
|
688
|
+
case "video":
|
|
689
|
+
return /* @__PURE__ */ jsx3(VideoCard, { ...card, aspectRatio });
|
|
690
|
+
case "audio":
|
|
691
|
+
return /* @__PURE__ */ jsx3(AudioCard, { ...card });
|
|
692
|
+
case "pdf":
|
|
693
|
+
return /* @__PURE__ */ jsx3(PdfCard, { ...card });
|
|
694
|
+
default:
|
|
695
|
+
return /* @__PURE__ */ jsx3("figure", { className: "seclai-media", children: /* @__PURE__ */ jsxs("figcaption", { children: [
|
|
696
|
+
/* @__PURE__ */ jsx3("a", { href: attachment.url, download: filename, children: attachment.name || filename }),
|
|
697
|
+
hasContent(extra) && /* @__PURE__ */ jsx3("span", { className: "seclai-media-actions", children: extra })
|
|
698
|
+
] }) });
|
|
343
699
|
}
|
|
344
|
-
return /* @__PURE__ */ jsx2(
|
|
345
|
-
ImageCard,
|
|
346
|
-
{
|
|
347
|
-
attachment,
|
|
348
|
-
aspectRatio,
|
|
349
|
-
number,
|
|
350
|
-
filename,
|
|
351
|
-
extra,
|
|
352
|
-
onOpen
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
700
|
}
|
|
356
|
-
function
|
|
701
|
+
function Badge({ number }) {
|
|
702
|
+
return number != null ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-badge", children: number }) : null;
|
|
703
|
+
}
|
|
704
|
+
function CardBar({ attachment, number, filename, extra }) {
|
|
705
|
+
return /* @__PURE__ */ jsxs("figcaption", { className: "seclai-media-bar", children: [
|
|
706
|
+
/* @__PURE__ */ jsx3("a", { href: attachment.url, download: filename, "aria-label": `Download ${mediaLabel(attachment, number)}`, children: "Download" }),
|
|
707
|
+
hasContent(extra) && /* @__PURE__ */ jsx3("span", { className: "seclai-media-actions", children: extra })
|
|
708
|
+
] });
|
|
709
|
+
}
|
|
710
|
+
function CardHead({ attachment, number }) {
|
|
711
|
+
return /* @__PURE__ */ jsxs("div", { className: "seclai-media-head", children: [
|
|
712
|
+
/* @__PURE__ */ jsx3(Badge, { number }),
|
|
713
|
+
/* @__PURE__ */ jsx3("span", { className: "seclai-media-title", children: attachment.name || kindLabel(attachment) })
|
|
714
|
+
] });
|
|
715
|
+
}
|
|
716
|
+
function ImageCard({
|
|
717
|
+
aspectRatio,
|
|
718
|
+
onOpen,
|
|
719
|
+
...card
|
|
720
|
+
}) {
|
|
721
|
+
const { attachment, number } = card;
|
|
357
722
|
const img = useRef(null);
|
|
358
|
-
const [natural, setNatural] =
|
|
359
|
-
const [failed, setFailed] =
|
|
360
|
-
const label =
|
|
723
|
+
const [natural, setNatural] = useState3(null);
|
|
724
|
+
const [failed, setFailed] = useState3(false);
|
|
725
|
+
const label = mediaLabel(attachment, number);
|
|
361
726
|
function measure() {
|
|
362
727
|
const el = img.current;
|
|
363
728
|
if (el && el.naturalWidth > 0 && el.naturalHeight > 0) {
|
|
@@ -373,8 +738,8 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
|
|
|
373
738
|
else measure();
|
|
374
739
|
}
|
|
375
740
|
}, [attachment.url]);
|
|
376
|
-
const frameContent = /* @__PURE__ */
|
|
377
|
-
failed ? /* @__PURE__ */
|
|
741
|
+
const frameContent = /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
742
|
+
failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the image." }) : /* @__PURE__ */ jsx3(
|
|
378
743
|
"img",
|
|
379
744
|
{
|
|
380
745
|
ref: img,
|
|
@@ -386,11 +751,11 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
|
|
|
386
751
|
onError: () => setFailed(true)
|
|
387
752
|
}
|
|
388
753
|
),
|
|
389
|
-
|
|
754
|
+
/* @__PURE__ */ jsx3(Badge, { number })
|
|
390
755
|
] });
|
|
391
756
|
const frameStyle = aspectRatioStyle(aspectRatio ?? natural ?? void 0);
|
|
392
|
-
return /* @__PURE__ */
|
|
393
|
-
onOpen ? /* @__PURE__ */
|
|
757
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-image", children: [
|
|
758
|
+
onOpen ? /* @__PURE__ */ jsx3(
|
|
394
759
|
"button",
|
|
395
760
|
{
|
|
396
761
|
type: "button",
|
|
@@ -401,28 +766,126 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
|
|
|
401
766
|
onClick: onOpen,
|
|
402
767
|
children: frameContent
|
|
403
768
|
}
|
|
404
|
-
) : /* @__PURE__ */
|
|
405
|
-
/* @__PURE__ */
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
769
|
+
) : /* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", style: frameStyle, children: frameContent }),
|
|
770
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
771
|
+
] });
|
|
772
|
+
}
|
|
773
|
+
function VideoCard({ aspectRatio, ...card }) {
|
|
774
|
+
const { attachment, number } = card;
|
|
775
|
+
const video = useRef(null);
|
|
776
|
+
const [natural, setNatural] = useState3(null);
|
|
777
|
+
const [failed, setFailed] = useState3(false);
|
|
778
|
+
function measure() {
|
|
779
|
+
const el = video.current;
|
|
780
|
+
if (el && el.videoWidth > 0 && el.videoHeight > 0) {
|
|
781
|
+
setNatural(`${el.videoWidth} / ${el.videoHeight}`);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
useEffect2(() => {
|
|
785
|
+
setNatural(null);
|
|
786
|
+
setFailed(false);
|
|
787
|
+
const el = video.current;
|
|
788
|
+
if (el?.error) setFailed(true);
|
|
789
|
+
else if (el && el.readyState >= HTMLMediaElement.HAVE_METADATA) measure();
|
|
790
|
+
}, [attachment.url]);
|
|
791
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-video", children: [
|
|
792
|
+
/* @__PURE__ */ jsxs("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio ?? natural ?? void 0), children: [
|
|
793
|
+
failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the video." }) : /* @__PURE__ */ jsx3(
|
|
794
|
+
"video",
|
|
795
|
+
{
|
|
796
|
+
ref: video,
|
|
797
|
+
src: attachment.url,
|
|
798
|
+
controls: true,
|
|
799
|
+
preload: "metadata",
|
|
800
|
+
playsInline: true,
|
|
801
|
+
"aria-label": mediaLabel(attachment, number),
|
|
802
|
+
onLoadedMetadata: measure,
|
|
803
|
+
onError: () => setFailed(true)
|
|
804
|
+
}
|
|
805
|
+
),
|
|
806
|
+
/* @__PURE__ */ jsx3(Badge, { number })
|
|
807
|
+
] }),
|
|
808
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
809
|
+
] });
|
|
810
|
+
}
|
|
811
|
+
function AudioCard(card) {
|
|
812
|
+
const { attachment, number } = card;
|
|
813
|
+
const audio = useRef(null);
|
|
814
|
+
const [failed, setFailed] = useState3(false);
|
|
815
|
+
useEffect2(() => {
|
|
816
|
+
setFailed(audio.current?.error != null);
|
|
817
|
+
}, [attachment.url]);
|
|
818
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-audio", children: [
|
|
819
|
+
/* @__PURE__ */ jsx3(CardHead, { attachment, number }),
|
|
820
|
+
/* @__PURE__ */ jsx3("div", { className: "seclai-media-body", children: failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the audio." }) : /* @__PURE__ */ jsx3(
|
|
821
|
+
"audio",
|
|
822
|
+
{
|
|
823
|
+
ref: audio,
|
|
824
|
+
src: attachment.url,
|
|
825
|
+
controls: true,
|
|
826
|
+
preload: "metadata",
|
|
827
|
+
"aria-label": mediaLabel(attachment, number),
|
|
828
|
+
onError: () => setFailed(true)
|
|
829
|
+
}
|
|
830
|
+
) }),
|
|
831
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
832
|
+
] });
|
|
833
|
+
}
|
|
834
|
+
function PdfCard(card) {
|
|
835
|
+
const { attachment, number, filename } = card;
|
|
836
|
+
const object = useRef(null);
|
|
837
|
+
const [failed, setFailed] = useState3(false);
|
|
838
|
+
const label = mediaLabel(attachment, number);
|
|
839
|
+
useEffect2(() => setFailed(false), [attachment.url]);
|
|
840
|
+
useEffect2(() => {
|
|
841
|
+
const el = object.current;
|
|
842
|
+
if (!el) return;
|
|
843
|
+
const fail = () => setFailed(true);
|
|
844
|
+
el.addEventListener("error", fail);
|
|
845
|
+
return () => el.removeEventListener("error", fail);
|
|
846
|
+
}, [attachment.url, failed]);
|
|
847
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-pdf", children: [
|
|
848
|
+
/* @__PURE__ */ jsx3(CardHead, { attachment, number }),
|
|
849
|
+
/* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", children: failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the PDF." }) : (
|
|
850
|
+
// Keyed on the URL: browsers don't reliably reload an <object> whose
|
|
851
|
+
// data changes.
|
|
852
|
+
/* @__PURE__ */ jsx3(
|
|
853
|
+
"object",
|
|
854
|
+
{
|
|
855
|
+
ref: object,
|
|
856
|
+
type: "application/pdf",
|
|
857
|
+
data: attachment.url,
|
|
858
|
+
"aria-label": label,
|
|
859
|
+
children: /* @__PURE__ */ jsxs("span", { className: "seclai-media-fallback", children: [
|
|
860
|
+
"This browser can't show the PDF here.",
|
|
861
|
+
" ",
|
|
862
|
+
/* @__PURE__ */ jsxs("a", { href: attachment.url, download: filename, children: [
|
|
863
|
+
"Download ",
|
|
864
|
+
label
|
|
865
|
+
] })
|
|
866
|
+
] })
|
|
867
|
+
},
|
|
868
|
+
attachment.url
|
|
869
|
+
)
|
|
870
|
+
) }),
|
|
871
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
409
872
|
] });
|
|
410
873
|
}
|
|
411
874
|
|
|
412
875
|
// src/media/MediaSkeleton.tsx
|
|
413
|
-
import { jsx as
|
|
876
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
414
877
|
function MediaSkeleton({ aspectRatio, number, label }) {
|
|
415
878
|
const name = label ?? (number != null ? `Image ${number} is being generated` : "Image is being generated");
|
|
416
|
-
return /* @__PURE__ */
|
|
417
|
-
/* @__PURE__ */
|
|
418
|
-
/* @__PURE__ */
|
|
879
|
+
return /* @__PURE__ */ jsxs2("div", { className: "seclai-media seclai-media-card seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
|
|
880
|
+
/* @__PURE__ */ jsx4("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio), children: number != null && /* @__PURE__ */ jsx4("span", { className: "seclai-media-badge", children: number }) }),
|
|
881
|
+
/* @__PURE__ */ jsx4("div", { className: "seclai-media-bar", children: /* @__PURE__ */ jsx4("span", { className: "seclai-media-skeleton-line" }) })
|
|
419
882
|
] });
|
|
420
883
|
}
|
|
421
884
|
|
|
422
885
|
// src/media/MediaViewer.tsx
|
|
423
886
|
import { useEffect as useEffect3, useId, useRef as useRef2 } from "react";
|
|
424
|
-
import { Fragment as Fragment3, jsx as
|
|
425
|
-
function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
887
|
+
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
888
|
+
function MediaViewer({ attachments, numbers, index, onIndexChange, onClose }) {
|
|
426
889
|
const dialog = useRef2(null);
|
|
427
890
|
const closeButton = useRef2(null);
|
|
428
891
|
const returnFocus = useRef2(null);
|
|
@@ -480,9 +943,10 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
480
943
|
function onClick(event) {
|
|
481
944
|
if (event.target === event.currentTarget) onClose();
|
|
482
945
|
}
|
|
483
|
-
const
|
|
484
|
-
const
|
|
485
|
-
|
|
946
|
+
const position = index != null ? index + 1 : 0;
|
|
947
|
+
const number = index != null ? numbers?.[index] ?? position : 0;
|
|
948
|
+
const label = current ? mediaLabel(current, number) : "";
|
|
949
|
+
return /* @__PURE__ */ jsx5(
|
|
486
950
|
"dialog",
|
|
487
951
|
{
|
|
488
952
|
ref: dialog,
|
|
@@ -492,19 +956,19 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
492
956
|
onCancel,
|
|
493
957
|
onClose: onDialogClose,
|
|
494
958
|
onClick,
|
|
495
|
-
children: current && /* @__PURE__ */
|
|
496
|
-
/* @__PURE__ */
|
|
497
|
-
/* @__PURE__ */
|
|
498
|
-
/* @__PURE__ */
|
|
959
|
+
children: current && /* @__PURE__ */ jsxs3("div", { className: "seclai-viewer-body", children: [
|
|
960
|
+
/* @__PURE__ */ jsx5("img", { className: "seclai-viewer-image", src: current.url, alt: label }),
|
|
961
|
+
/* @__PURE__ */ jsxs3("div", { className: "seclai-viewer-bar", children: [
|
|
962
|
+
/* @__PURE__ */ jsxs3("p", { className: "seclai-viewer-title", id: titleId, children: [
|
|
499
963
|
label,
|
|
500
|
-
attachments.length > 1 && /* @__PURE__ */
|
|
501
|
-
|
|
964
|
+
attachments.length > 1 && /* @__PURE__ */ jsxs3("span", { className: "seclai-viewer-count", children: [
|
|
965
|
+
position,
|
|
502
966
|
" of ",
|
|
503
967
|
attachments.length
|
|
504
968
|
] })
|
|
505
969
|
] }),
|
|
506
|
-
attachments.length > 1 && /* @__PURE__ */
|
|
507
|
-
/* @__PURE__ */
|
|
970
|
+
attachments.length > 1 && /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
971
|
+
/* @__PURE__ */ jsx5(
|
|
508
972
|
"button",
|
|
509
973
|
{
|
|
510
974
|
type: "button",
|
|
@@ -514,9 +978,9 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
514
978
|
children: "Previous"
|
|
515
979
|
}
|
|
516
980
|
),
|
|
517
|
-
/* @__PURE__ */
|
|
981
|
+
/* @__PURE__ */ jsx5("button", { type: "button", className: "seclai-button", "aria-disabled": atEnd, onClick: () => go(1), children: "Next" })
|
|
518
982
|
] }),
|
|
519
|
-
/* @__PURE__ */
|
|
983
|
+
/* @__PURE__ */ jsx5(
|
|
520
984
|
"a",
|
|
521
985
|
{
|
|
522
986
|
className: "seclai-button seclai-button-primary",
|
|
@@ -525,7 +989,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
525
989
|
children: "Download"
|
|
526
990
|
}
|
|
527
991
|
),
|
|
528
|
-
/* @__PURE__ */
|
|
992
|
+
/* @__PURE__ */ jsx5("button", { type: "button", className: "seclai-button", ref: closeButton, onClick: onClose, children: "Close" })
|
|
529
993
|
] })
|
|
530
994
|
] })
|
|
531
995
|
}
|
|
@@ -533,7 +997,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
533
997
|
}
|
|
534
998
|
|
|
535
999
|
// src/media/MediaGallery.tsx
|
|
536
|
-
import { jsx as
|
|
1000
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
537
1001
|
var DOWNLOAD_ALL_DELAY_MS = SAVE_FILES_DELAY_MS;
|
|
538
1002
|
function MediaGallery({
|
|
539
1003
|
attachments,
|
|
@@ -541,10 +1005,17 @@ function MediaGallery({
|
|
|
541
1005
|
pending = 0,
|
|
542
1006
|
actions
|
|
543
1007
|
}) {
|
|
544
|
-
const
|
|
545
|
-
const files = attachments.filter((attachment) =>
|
|
546
|
-
const
|
|
547
|
-
const
|
|
1008
|
+
const cards = attachments.filter((attachment) => mediaKind(attachment) != null);
|
|
1009
|
+
const files = attachments.filter((attachment) => mediaKind(attachment) == null);
|
|
1010
|
+
const images = [];
|
|
1011
|
+
const imageNumbers = [];
|
|
1012
|
+
const viewerIndexes = cards.map((card, i) => {
|
|
1013
|
+
if (!isImage(card)) return null;
|
|
1014
|
+
imageNumbers.push(i + 1);
|
|
1015
|
+
return images.push(card) - 1;
|
|
1016
|
+
});
|
|
1017
|
+
const [viewing, setViewing] = useState4(null);
|
|
1018
|
+
const [downloading, setDownloading] = useState4(false);
|
|
548
1019
|
const abort = useRef3(null);
|
|
549
1020
|
useEffect4(() => () => abort.current?.abort(), []);
|
|
550
1021
|
if (viewing != null && viewing >= images.length) setViewing(null);
|
|
@@ -555,7 +1026,7 @@ function MediaGallery({
|
|
|
555
1026
|
setDownloading(true);
|
|
556
1027
|
try {
|
|
557
1028
|
await saveFiles(
|
|
558
|
-
|
|
1029
|
+
cards.map((card, i) => ({ source: card.url, filename: attachmentFileName(card, i + 1) })),
|
|
559
1030
|
{ delayMs: DOWNLOAD_ALL_DELAY_MS, signal: controller.signal }
|
|
560
1031
|
);
|
|
561
1032
|
} finally {
|
|
@@ -563,35 +1034,39 @@ function MediaGallery({
|
|
|
563
1034
|
}
|
|
564
1035
|
}
|
|
565
1036
|
const skeletons = Math.max(0, Math.floor(pending));
|
|
566
|
-
return /* @__PURE__ */
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
{
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
1037
|
+
return /* @__PURE__ */ jsxs4("div", { className: "seclai-gallery", children: [
|
|
1038
|
+
cards.length + skeletons > 0 && /* @__PURE__ */ jsxs4("ul", { className: "seclai-gallery-grid", children: [
|
|
1039
|
+
cards.map((card, i) => {
|
|
1040
|
+
const image = viewerIndexes[i];
|
|
1041
|
+
return /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6(
|
|
1042
|
+
MediaPreview,
|
|
1043
|
+
{
|
|
1044
|
+
attachment: card,
|
|
1045
|
+
aspectRatio,
|
|
1046
|
+
number: i + 1,
|
|
1047
|
+
actions: actions?.(card, i + 1),
|
|
1048
|
+
onOpen: image != null ? () => setViewing(image) : void 0
|
|
1049
|
+
}
|
|
1050
|
+
) }, card.id);
|
|
1051
|
+
}),
|
|
1052
|
+
Array.from({ length: skeletons }, (_, i) => /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6(MediaSkeleton, { aspectRatio, number: cards.length + i + 1 }) }, `pending-${i}`))
|
|
579
1053
|
] }),
|
|
580
|
-
|
|
1054
|
+
cards.length > 1 && /* @__PURE__ */ jsx6("div", { className: "seclai-gallery-actions", children: /* @__PURE__ */ jsx6(
|
|
581
1055
|
"button",
|
|
582
1056
|
{
|
|
583
1057
|
type: "button",
|
|
584
1058
|
className: "seclai-button",
|
|
585
1059
|
"aria-disabled": downloading,
|
|
586
1060
|
onClick: downloadAll,
|
|
587
|
-
children: downloading ? "Downloading\u2026" : `Download all ${
|
|
1061
|
+
children: downloading ? "Downloading\u2026" : `Download all ${cards.length}`
|
|
588
1062
|
}
|
|
589
1063
|
) }),
|
|
590
|
-
files.map((file) => /* @__PURE__ */
|
|
591
|
-
images.length > 0 && /* @__PURE__ */
|
|
1064
|
+
files.map((file) => /* @__PURE__ */ jsx6(MediaPreview, { attachment: file }, file.id)),
|
|
1065
|
+
images.length > 0 && /* @__PURE__ */ jsx6(
|
|
592
1066
|
MediaViewer,
|
|
593
1067
|
{
|
|
594
1068
|
attachments: images,
|
|
1069
|
+
numbers: imageNumbers,
|
|
595
1070
|
index: viewing,
|
|
596
1071
|
onIndexChange: setViewing,
|
|
597
1072
|
onClose: () => setViewing(null)
|
|
@@ -601,10 +1076,10 @@ function MediaGallery({
|
|
|
601
1076
|
}
|
|
602
1077
|
|
|
603
1078
|
// src/RunProgress.tsx
|
|
604
|
-
import { useEffect as useEffect5, useState as
|
|
605
|
-
import { jsx as
|
|
1079
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
1080
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
606
1081
|
function useElapsed(startedAt, running) {
|
|
607
|
-
const [now, setNow] =
|
|
1082
|
+
const [now, setNow] = useState5(null);
|
|
608
1083
|
useEffect5(() => {
|
|
609
1084
|
if (!running || startedAt === null) return;
|
|
610
1085
|
let timer;
|
|
@@ -636,27 +1111,27 @@ function RunProgress({ run, showSteps = true, message, className }) {
|
|
|
636
1111
|
if (!running) return null;
|
|
637
1112
|
const note = typeof message === "function" ? message(seconds) : message;
|
|
638
1113
|
const last = run.steps.length - 1;
|
|
639
|
-
return /* @__PURE__ */
|
|
1114
|
+
return /* @__PURE__ */ jsxs5(
|
|
640
1115
|
"div",
|
|
641
1116
|
{
|
|
642
1117
|
className: className ? `seclai-run-progress ${className}` : "seclai-run-progress",
|
|
643
1118
|
"aria-live": "polite",
|
|
644
1119
|
children: [
|
|
645
|
-
showSteps && (run.steps.length === 0 ? /* @__PURE__ */
|
|
646
|
-
/* @__PURE__ */
|
|
647
|
-
/* @__PURE__ */
|
|
648
|
-
/* @__PURE__ */
|
|
649
|
-
/* @__PURE__ */
|
|
650
|
-
step.message && /* @__PURE__ */
|
|
1120
|
+
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: [
|
|
1121
|
+
/* @__PURE__ */ jsx7("span", { className: "seclai-step-marker", "aria-hidden": "true", children: i === last ? "\u25CF" : "\u2713" }),
|
|
1122
|
+
/* @__PURE__ */ jsx7("span", { className: "seclai-sr-only", children: i === last ? "In progress: " : "Done: " }),
|
|
1123
|
+
/* @__PURE__ */ jsxs5("span", { children: [
|
|
1124
|
+
/* @__PURE__ */ jsx7("span", { className: "seclai-step-name", children: step.name }),
|
|
1125
|
+
step.message && /* @__PURE__ */ jsxs5("span", { className: "seclai-step-message", children: [
|
|
651
1126
|
" \xB7 ",
|
|
652
1127
|
step.message
|
|
653
1128
|
] })
|
|
654
1129
|
] })
|
|
655
1130
|
] }, step.id)) })),
|
|
656
|
-
/* @__PURE__ */
|
|
657
|
-
/* @__PURE__ */
|
|
658
|
-
note != null && note !== false && note !== "" && /* @__PURE__ */
|
|
659
|
-
/* @__PURE__ */
|
|
1131
|
+
/* @__PURE__ */ jsxs5("div", { className: "seclai-run-progress-note", children: [
|
|
1132
|
+
/* @__PURE__ */ jsx7("span", { className: "seclai-run-progress-pulse", "aria-hidden": "true" }),
|
|
1133
|
+
note != null && note !== false && note !== "" && /* @__PURE__ */ jsx7("span", { className: "seclai-run-progress-message", children: note }),
|
|
1134
|
+
/* @__PURE__ */ jsx7(
|
|
660
1135
|
"span",
|
|
661
1136
|
{
|
|
662
1137
|
className: "seclai-run-progress-clock",
|
|
@@ -673,7 +1148,7 @@ function RunProgress({ run, showSteps = true, message, className }) {
|
|
|
673
1148
|
}
|
|
674
1149
|
|
|
675
1150
|
// src/useAgentRun.ts
|
|
676
|
-
import { useCallback, useEffect as useEffect6, useMemo, useRef as useRef4, useState as
|
|
1151
|
+
import { useCallback, useEffect as useEffect6, useMemo, useRef as useRef4, useState as useState6 } from "react";
|
|
677
1152
|
|
|
678
1153
|
// src/sse.ts
|
|
679
1154
|
function parseData(data) {
|
|
@@ -820,7 +1295,7 @@ function applyEvent(state, { event, data }, endpoints) {
|
|
|
820
1295
|
function useAgentRun(options = {}) {
|
|
821
1296
|
const { basePath, agentId, onEvent } = options;
|
|
822
1297
|
const endpoints = useMemo(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
823
|
-
const [state, setState] =
|
|
1298
|
+
const [state, setState] = useState6(IDLE);
|
|
824
1299
|
const active = useRef4(null);
|
|
825
1300
|
const onEventRef = useRef4(onEvent);
|
|
826
1301
|
useEffect6(() => {
|
|
@@ -898,7 +1373,7 @@ function useAgentRun(options = {}) {
|
|
|
898
1373
|
}
|
|
899
1374
|
|
|
900
1375
|
// src/AgentChat.tsx
|
|
901
|
-
import { jsx as
|
|
1376
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
902
1377
|
function createSessionId() {
|
|
903
1378
|
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
904
1379
|
return Array.from(
|
|
@@ -922,13 +1397,13 @@ function plural(count, word) {
|
|
|
922
1397
|
}
|
|
923
1398
|
function FileChip({ name, tag, preview, status, error, onRemove }) {
|
|
924
1399
|
const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
|
|
925
|
-
return /* @__PURE__ */
|
|
926
|
-
preview && /* @__PURE__ */
|
|
927
|
-
/* @__PURE__ */
|
|
928
|
-
/* @__PURE__ */
|
|
929
|
-
meta && /* @__PURE__ */
|
|
1400
|
+
return /* @__PURE__ */ jsxs6("li", { className: "seclai-file", "data-status": status, children: [
|
|
1401
|
+
preview && /* @__PURE__ */ jsx8("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
|
|
1402
|
+
/* @__PURE__ */ jsxs6("span", { className: "seclai-file-text", children: [
|
|
1403
|
+
/* @__PURE__ */ jsx8("span", { className: "seclai-file-name", title: name, children: name }),
|
|
1404
|
+
meta && /* @__PURE__ */ jsx8("span", { className: "seclai-file-meta", children: meta })
|
|
930
1405
|
] }),
|
|
931
|
-
onRemove && /* @__PURE__ */
|
|
1406
|
+
onRemove && /* @__PURE__ */ jsx8(
|
|
932
1407
|
"button",
|
|
933
1408
|
{
|
|
934
1409
|
type: "button",
|
|
@@ -941,8 +1416,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
|
|
|
941
1416
|
] });
|
|
942
1417
|
}
|
|
943
1418
|
function UserTurn({ message, previews }) {
|
|
944
|
-
return /* @__PURE__ */
|
|
945
|
-
message.files.length > 0 && /* @__PURE__ */
|
|
1419
|
+
return /* @__PURE__ */ jsxs6("li", { className: "seclai-turn seclai-turn-user", children: [
|
|
1420
|
+
message.files.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-files", "aria-label": "Attached files", children: message.files.map((file) => /* @__PURE__ */ jsx8(
|
|
946
1421
|
FileChip,
|
|
947
1422
|
{
|
|
948
1423
|
name: file.name,
|
|
@@ -951,14 +1426,14 @@ function UserTurn({ message, previews }) {
|
|
|
951
1426
|
},
|
|
952
1427
|
file.uploadId
|
|
953
1428
|
)) }),
|
|
954
|
-
message.input && /* @__PURE__ */
|
|
1429
|
+
message.input && /* @__PURE__ */ jsx8(MarkdownContent, { content: message.input })
|
|
955
1430
|
] });
|
|
956
1431
|
}
|
|
957
1432
|
function AssistantTurn({ turn, endpoints }) {
|
|
958
1433
|
const { runId } = turn;
|
|
959
|
-
return /* @__PURE__ */
|
|
960
|
-
turn.output && /* @__PURE__ */
|
|
961
|
-
runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */
|
|
1434
|
+
return /* @__PURE__ */ jsxs6("li", { className: "seclai-turn seclai-turn-assistant", children: [
|
|
1435
|
+
turn.output && /* @__PURE__ */ jsx8(MarkdownContent, { content: turn.output }),
|
|
1436
|
+
runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ jsx8(
|
|
962
1437
|
MediaGallery,
|
|
963
1438
|
{
|
|
964
1439
|
attachments: turn.attachments.map(({ id, name, mime, bytes }) => ({
|
|
@@ -970,8 +1445,8 @@ function AssistantTurn({ turn, endpoints }) {
|
|
|
970
1445
|
}))
|
|
971
1446
|
}
|
|
972
1447
|
),
|
|
973
|
-
turn.error && /* @__PURE__ */
|
|
974
|
-
turn.status === "cancelled" && /* @__PURE__ */
|
|
1448
|
+
turn.error && /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: turn.error }),
|
|
1449
|
+
turn.status === "cancelled" && /* @__PURE__ */ jsx8("p", { className: "seclai-notice", children: "Stopped." })
|
|
975
1450
|
] });
|
|
976
1451
|
}
|
|
977
1452
|
function toTurnAttachment({ id, name, mime, bytes }) {
|
|
@@ -984,9 +1459,9 @@ function AttachControl({
|
|
|
984
1459
|
disabled,
|
|
985
1460
|
onFiles
|
|
986
1461
|
}) {
|
|
987
|
-
return /* @__PURE__ */
|
|
1462
|
+
return /* @__PURE__ */ jsxs6("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
|
|
988
1463
|
label,
|
|
989
|
-
/* @__PURE__ */
|
|
1464
|
+
/* @__PURE__ */ jsx8(
|
|
990
1465
|
"input",
|
|
991
1466
|
{
|
|
992
1467
|
type: "file",
|
|
@@ -1016,7 +1491,7 @@ function AgentChat({
|
|
|
1016
1491
|
const endpoints = useMemo2(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
1017
1492
|
const run = useAgentRun({ basePath, agentId });
|
|
1018
1493
|
const { slots } = useAcceptedAttachments(endpoints);
|
|
1019
|
-
const [transcript, setTranscript] =
|
|
1494
|
+
const [transcript, setTranscript] = useState7(() => ({
|
|
1020
1495
|
sessionId,
|
|
1021
1496
|
epoch: 0,
|
|
1022
1497
|
turns: initialTurns ?? [],
|
|
@@ -1024,10 +1499,10 @@ function AgentChat({
|
|
|
1024
1499
|
generatedSessionId: null,
|
|
1025
1500
|
runEpoch: null
|
|
1026
1501
|
}));
|
|
1027
|
-
const [message, setMessage] =
|
|
1028
|
-
const [files, setFiles] =
|
|
1029
|
-
const [notice, setNotice] =
|
|
1030
|
-
const [dragging, setDragging] =
|
|
1502
|
+
const [message, setMessage] = useState7("");
|
|
1503
|
+
const [files, setFiles] = useState7([]);
|
|
1504
|
+
const [notice, setNotice] = useState7(null);
|
|
1505
|
+
const [dragging, setDragging] = useState7(false);
|
|
1031
1506
|
const generatedSessionId = useRef5(null);
|
|
1032
1507
|
const shownEpoch = useRef5(transcript.epoch);
|
|
1033
1508
|
const turnComplete = useRef5(onTurnComplete);
|
|
@@ -1218,29 +1693,29 @@ function AgentChat({
|
|
|
1218
1693
|
}
|
|
1219
1694
|
} : {};
|
|
1220
1695
|
const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
|
|
1221
|
-
return /* @__PURE__ */
|
|
1222
|
-
/* @__PURE__ */
|
|
1223
|
-
transcript.turns.map((turn, i) => /* @__PURE__ */
|
|
1224
|
-
/* @__PURE__ */
|
|
1696
|
+
return /* @__PURE__ */ jsxs6("div", { className: "seclai-agent seclai-chat", children: [
|
|
1697
|
+
/* @__PURE__ */ jsxs6("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": streaming, children: [
|
|
1698
|
+
transcript.turns.map((turn, i) => /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
|
1699
|
+
/* @__PURE__ */ jsx8(
|
|
1225
1700
|
UserTurn,
|
|
1226
1701
|
{
|
|
1227
1702
|
message: { input: turn.input, files: turn.files ?? [] },
|
|
1228
1703
|
previews: sentPreviews.current
|
|
1229
1704
|
}
|
|
1230
1705
|
),
|
|
1231
|
-
/* @__PURE__ */
|
|
1706
|
+
/* @__PURE__ */ jsx8(AssistantTurn, { turn, endpoints })
|
|
1232
1707
|
] }, `${transcript.epoch}:${i}`)),
|
|
1233
|
-
transcript.pending && /* @__PURE__ */
|
|
1234
|
-
streaming && /* @__PURE__ */
|
|
1708
|
+
transcript.pending && /* @__PURE__ */ jsx8(UserTurn, { message: transcript.pending, previews: sentPreviews.current }),
|
|
1709
|
+
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
1710
|
] }),
|
|
1236
|
-
/* @__PURE__ */
|
|
1711
|
+
/* @__PURE__ */ jsxs6(
|
|
1237
1712
|
"form",
|
|
1238
1713
|
{
|
|
1239
1714
|
className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
|
|
1240
1715
|
onSubmit,
|
|
1241
1716
|
...dropHandlers,
|
|
1242
1717
|
children: [
|
|
1243
|
-
files.length > 0 && /* @__PURE__ */
|
|
1718
|
+
files.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx8(
|
|
1244
1719
|
FileChip,
|
|
1245
1720
|
{
|
|
1246
1721
|
name: f.name,
|
|
@@ -1252,7 +1727,7 @@ function AgentChat({
|
|
|
1252
1727
|
},
|
|
1253
1728
|
f.localId
|
|
1254
1729
|
)) }),
|
|
1255
|
-
/* @__PURE__ */
|
|
1730
|
+
/* @__PURE__ */ jsx8(
|
|
1256
1731
|
"textarea",
|
|
1257
1732
|
{
|
|
1258
1733
|
rows: 2,
|
|
@@ -1264,9 +1739,9 @@ function AgentChat({
|
|
|
1264
1739
|
onPaste: acceptsFiles ? onPaste : void 0
|
|
1265
1740
|
}
|
|
1266
1741
|
),
|
|
1267
|
-
notice && /* @__PURE__ */
|
|
1268
|
-
/* @__PURE__ */
|
|
1269
|
-
acceptsFiles && buttons.map((button) => /* @__PURE__ */
|
|
1742
|
+
notice && /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: notice }),
|
|
1743
|
+
/* @__PURE__ */ jsxs6("div", { className: "seclai-actions", children: [
|
|
1744
|
+
acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx8(
|
|
1270
1745
|
AttachControl,
|
|
1271
1746
|
{
|
|
1272
1747
|
label: button.label,
|
|
@@ -1277,8 +1752,8 @@ function AgentChat({
|
|
|
1277
1752
|
},
|
|
1278
1753
|
`${button.label}\0${button.tag ?? ""}`
|
|
1279
1754
|
)),
|
|
1280
|
-
/* @__PURE__ */
|
|
1281
|
-
running && /* @__PURE__ */
|
|
1755
|
+
/* @__PURE__ */ jsx8("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
|
|
1756
|
+
running && /* @__PURE__ */ jsx8("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
|
|
1282
1757
|
] })
|
|
1283
1758
|
]
|
|
1284
1759
|
}
|
|
@@ -1287,8 +1762,8 @@ function AgentChat({
|
|
|
1287
1762
|
}
|
|
1288
1763
|
|
|
1289
1764
|
// src/AgentRunForm.tsx
|
|
1290
|
-
import { useMemo as useMemo3, useState as
|
|
1291
|
-
import { jsx as
|
|
1765
|
+
import { useMemo as useMemo3, useState as useState8 } from "react";
|
|
1766
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1292
1767
|
function slotProblem(slot, count) {
|
|
1293
1768
|
const label = slot.label ?? slot.name;
|
|
1294
1769
|
const min = slot.min ?? 0;
|
|
@@ -1302,10 +1777,10 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1302
1777
|
const endpoints = useMemo3(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
1303
1778
|
const run = useAgentRun({ basePath, agentId });
|
|
1304
1779
|
const { slots, error: loadError } = useAcceptedAttachments(endpoints);
|
|
1305
|
-
const [input, setInput] =
|
|
1306
|
-
const [files, setFiles] =
|
|
1307
|
-
const [uploading, setUploading] =
|
|
1308
|
-
const [formError, setFormError] =
|
|
1780
|
+
const [input, setInput] = useState8("");
|
|
1781
|
+
const [files, setFiles] = useState8({});
|
|
1782
|
+
const [uploading, setUploading] = useState8(false);
|
|
1783
|
+
const [formError, setFormError] = useState8(null);
|
|
1309
1784
|
const selected = Object.values(files).flat();
|
|
1310
1785
|
const busy = uploading || run.status === "running";
|
|
1311
1786
|
async function submit(event) {
|
|
@@ -1339,30 +1814,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1339
1814
|
onFinish?.(result);
|
|
1340
1815
|
}
|
|
1341
1816
|
if (loadError) {
|
|
1342
|
-
return /* @__PURE__ */
|
|
1817
|
+
return /* @__PURE__ */ jsx9("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx9("p", { className: "seclai-error", role: "alert", children: loadError }) });
|
|
1343
1818
|
}
|
|
1344
1819
|
if (!slots) {
|
|
1345
|
-
return /* @__PURE__ */
|
|
1346
|
-
/* @__PURE__ */
|
|
1347
|
-
/* @__PURE__ */
|
|
1348
|
-
/* @__PURE__ */
|
|
1349
|
-
/* @__PURE__ */
|
|
1820
|
+
return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent", children: [
|
|
1821
|
+
/* @__PURE__ */ jsx9("p", { className: "seclai-notice", children: "Loading\u2026" }),
|
|
1822
|
+
/* @__PURE__ */ jsxs7("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
|
|
1823
|
+
/* @__PURE__ */ jsx9("span", {}),
|
|
1824
|
+
/* @__PURE__ */ jsx9("span", {})
|
|
1350
1825
|
] })
|
|
1351
1826
|
] });
|
|
1352
1827
|
}
|
|
1353
1828
|
const error = formError ?? run.error;
|
|
1354
|
-
return /* @__PURE__ */
|
|
1355
|
-
/* @__PURE__ */
|
|
1356
|
-
/* @__PURE__ */
|
|
1357
|
-
/* @__PURE__ */
|
|
1358
|
-
/* @__PURE__ */
|
|
1829
|
+
return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent", children: [
|
|
1830
|
+
/* @__PURE__ */ jsxs7("form", { className: "seclai-form", onSubmit: submit, children: [
|
|
1831
|
+
/* @__PURE__ */ jsxs7("label", { className: "seclai-field", children: [
|
|
1832
|
+
/* @__PURE__ */ jsx9("span", { children: inputLabel }),
|
|
1833
|
+
/* @__PURE__ */ jsx9("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
|
|
1359
1834
|
] }),
|
|
1360
|
-
slots.map((slot) => /* @__PURE__ */
|
|
1361
|
-
/* @__PURE__ */
|
|
1835
|
+
slots.map((slot) => /* @__PURE__ */ jsxs7("label", { className: "seclai-field", children: [
|
|
1836
|
+
/* @__PURE__ */ jsxs7("span", { children: [
|
|
1362
1837
|
slot.label ?? slot.name,
|
|
1363
1838
|
(slot.min ?? 0) > 0 ? " (required)" : ""
|
|
1364
1839
|
] }),
|
|
1365
|
-
/* @__PURE__ */
|
|
1840
|
+
/* @__PURE__ */ jsx9(
|
|
1366
1841
|
"input",
|
|
1367
1842
|
{
|
|
1368
1843
|
type: "file",
|
|
@@ -1373,29 +1848,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1373
1848
|
}
|
|
1374
1849
|
)
|
|
1375
1850
|
] }, slot.name)),
|
|
1376
|
-
/* @__PURE__ */
|
|
1377
|
-
/* @__PURE__ */
|
|
1378
|
-
run.status === "running" && /* @__PURE__ */
|
|
1851
|
+
/* @__PURE__ */ jsxs7("div", { className: "seclai-actions", children: [
|
|
1852
|
+
/* @__PURE__ */ jsx9("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
|
|
1853
|
+
run.status === "running" && /* @__PURE__ */ jsx9("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
|
|
1379
1854
|
] })
|
|
1380
1855
|
] }),
|
|
1381
|
-
run.steps.length > 0 && /* @__PURE__ */
|
|
1856
|
+
run.steps.length > 0 && /* @__PURE__ */ jsx9("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs7("li", { children: [
|
|
1382
1857
|
step.name,
|
|
1383
1858
|
": ",
|
|
1384
1859
|
step.message
|
|
1385
1860
|
] }, step.id)) }),
|
|
1386
|
-
error && /* @__PURE__ */
|
|
1387
|
-
run.status === "cancelled" && /* @__PURE__ */
|
|
1388
|
-
(run.text || run.attachments.length > 0) && /* @__PURE__ */
|
|
1389
|
-
run.text && /* @__PURE__ */
|
|
1390
|
-
run.attachments.length > 0 && /* @__PURE__ */
|
|
1861
|
+
error && /* @__PURE__ */ jsx9("p", { className: "seclai-error", role: "alert", children: error }),
|
|
1862
|
+
run.status === "cancelled" && /* @__PURE__ */ jsx9("p", { className: "seclai-notice", children: "Stopped." }),
|
|
1863
|
+
(run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs7("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
|
|
1864
|
+
run.text && /* @__PURE__ */ jsx9(MarkdownContent, { content: run.text, streaming: run.status === "running" }),
|
|
1865
|
+
run.attachments.length > 0 && /* @__PURE__ */ jsx9(MediaGallery, { attachments: run.attachments })
|
|
1391
1866
|
] })
|
|
1392
1867
|
] });
|
|
1393
1868
|
}
|
|
1394
1869
|
|
|
1395
1870
|
// src/SeclaiAgent.tsx
|
|
1396
|
-
import { jsx as
|
|
1871
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1397
1872
|
function SeclaiAgent({ mode, basePath, agentId }) {
|
|
1398
|
-
return mode === "chat" ? /* @__PURE__ */
|
|
1873
|
+
return mode === "chat" ? /* @__PURE__ */ jsx10(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx10(AgentRunForm, { basePath, agentId });
|
|
1399
1874
|
}
|
|
1400
1875
|
export {
|
|
1401
1876
|
AgentChat,
|
|
@@ -1408,6 +1883,7 @@ export {
|
|
|
1408
1883
|
MediaViewer,
|
|
1409
1884
|
RunProgress,
|
|
1410
1885
|
SeclaiAgent,
|
|
1886
|
+
SeclaiMarkdownProvider,
|
|
1411
1887
|
attachmentFileName,
|
|
1412
1888
|
createEndpoints,
|
|
1413
1889
|
fetchAttachmentReferences,
|