@seclai/react 0.0.7 → 0.0.9

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.cjs CHANGED
@@ -25,8 +25,12 @@ __export(index_exports, {
25
25
  AgentRunForm: () => AgentRunForm,
26
26
  DEFAULT_BASE_PATH: () => DEFAULT_BASE_PATH,
27
27
  MarkdownContent: () => MarkdownContent,
28
+ MediaGallery: () => MediaGallery,
28
29
  MediaPreview: () => MediaPreview,
30
+ MediaSkeleton: () => MediaSkeleton,
31
+ MediaViewer: () => MediaViewer,
29
32
  SeclaiAgent: () => SeclaiAgent,
33
+ attachmentFileName: () => attachmentFileName,
30
34
  createEndpoints: () => createEndpoints,
31
35
  fetchAttachmentReferences: () => fetchAttachmentReferences,
32
36
  uploadFile: () => uploadFile,
@@ -35,7 +39,7 @@ __export(index_exports, {
35
39
  module.exports = __toCommonJS(index_exports);
36
40
 
37
41
  // src/AgentChat.tsx
38
- var import_react3 = require("react");
42
+ var import_react6 = require("react");
39
43
 
40
44
  // src/attachments.ts
41
45
  var import_react = require("react");
@@ -128,18 +132,353 @@ function MarkdownContent({ content }) {
128
132
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "seclai-markdown", children: content });
129
133
  }
130
134
 
135
+ // src/media/MediaGallery.tsx
136
+ var import_react4 = require("react");
137
+
138
+ // src/placeholders/MediaPreview.tsx
139
+ var import_react2 = require("react");
140
+
141
+ // src/media/files.ts
142
+ var EXTENSIONS = {
143
+ "image/jpeg": "jpg",
144
+ "image/svg+xml": "svg",
145
+ "image/x-icon": "ico",
146
+ "image/vnd.microsoft.icon": "ico",
147
+ "audio/mpeg": "mp3",
148
+ "video/quicktime": "mov",
149
+ "text/plain": "txt",
150
+ "text/markdown": "md",
151
+ "application/octet-stream": "bin"
152
+ };
153
+ function isImage(attachment) {
154
+ return attachment.mime.toLowerCase().startsWith("image/");
155
+ }
156
+ function extensionForMime(mime) {
157
+ const type = mime.split(";")[0].trim().toLowerCase();
158
+ const known = EXTENSIONS[type];
159
+ if (known) return known;
160
+ const subtype = type.split("/")[1] ?? "";
161
+ const ext = (subtype.split("+").at(-1) ?? "").replace(/^x-/, "");
162
+ return /^[a-z0-9]{1,5}$/.test(ext) ? ext : "bin";
163
+ }
164
+ function attachmentFileName(attachment, number) {
165
+ if (attachment.name) return attachment.name;
166
+ const base = number != null ? `image-${number}` : attachment.id;
167
+ return `${base}.${extensionForMime(attachment.mime)}`;
168
+ }
169
+ var SAFE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
170
+ function isSafeUrl(url) {
171
+ try {
172
+ return SAFE_PROTOCOLS.has(new URL(url, document.baseURI).protocol);
173
+ } catch {
174
+ return false;
175
+ }
176
+ }
177
+ function triggerDownload(url, filename) {
178
+ if (!isSafeUrl(url)) {
179
+ console.warn(`seclai: not downloading ${filename}, its URL isn't http(s), blob or relative.`);
180
+ return;
181
+ }
182
+ const link = document.createElement("a");
183
+ link.href = url;
184
+ link.download = filename;
185
+ link.rel = "noopener";
186
+ link.style.display = "none";
187
+ document.body.append(link);
188
+ link.click();
189
+ link.remove();
190
+ }
191
+ async function downloadSequentially(files, delayMs, signal) {
192
+ for (const [i, file] of files.entries()) {
193
+ if (signal?.aborted) return;
194
+ if (i > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
195
+ if (signal?.aborted) return;
196
+ triggerDownload(file.url, file.filename);
197
+ }
198
+ }
199
+
131
200
  // src/placeholders/MediaPreview.tsx
132
201
  var import_jsx_runtime2 = require("react/jsx-runtime");
133
- function MediaPreview({ attachment }) {
134
- const name = attachment.name ?? attachment.id;
135
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figure", { className: "seclai-media", children: [
136
- attachment.mime.startsWith("image/") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: attachment.url, alt: name }),
137
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("figcaption", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: attachment.url, download: name, children: name }) })
202
+ function hasContent(node) {
203
+ return node != null && node !== false && node !== "";
204
+ }
205
+ function aspectRatioStyle(ratio) {
206
+ return ratio == null ? void 0 : { aspectRatio: String(ratio) };
207
+ }
208
+ function imageLabel(attachment, number) {
209
+ return attachment.name ?? (number != null ? `Image ${number}` : "Image");
210
+ }
211
+ function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }) {
212
+ const filename = attachmentFileName(attachment, number);
213
+ const extra = typeof actions === "function" ? actions(attachment) : actions;
214
+ if (!isImage(attachment)) {
215
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("figure", { className: "seclai-media", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figcaption", { children: [
216
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: attachment.url, download: filename, children: attachment.name ?? filename }),
217
+ hasContent(extra) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "seclai-media-actions", children: extra })
218
+ ] }) });
219
+ }
220
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
221
+ ImageCard,
222
+ {
223
+ attachment,
224
+ aspectRatio,
225
+ number,
226
+ filename,
227
+ extra,
228
+ onOpen
229
+ }
230
+ );
231
+ }
232
+ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen }) {
233
+ const img = (0, import_react2.useRef)(null);
234
+ const [natural, setNatural] = (0, import_react2.useState)(null);
235
+ const [failed, setFailed] = (0, import_react2.useState)(false);
236
+ const label = imageLabel(attachment, number);
237
+ function measure() {
238
+ const el = img.current;
239
+ if (el && el.naturalWidth > 0 && el.naturalHeight > 0) {
240
+ setNatural(`${el.naturalWidth} / ${el.naturalHeight}`);
241
+ }
242
+ }
243
+ (0, import_react2.useEffect)(() => {
244
+ setNatural(null);
245
+ setFailed(false);
246
+ const el = img.current;
247
+ if (el?.complete) {
248
+ if (el.naturalWidth === 0) setFailed(true);
249
+ else measure();
250
+ }
251
+ }, [attachment.url]);
252
+ const frameContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
253
+ failed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "seclai-media-error", children: "Couldn't load the image." }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
254
+ "img",
255
+ {
256
+ ref: img,
257
+ src: attachment.url,
258
+ alt: label,
259
+ loading: "lazy",
260
+ decoding: "async",
261
+ onLoad: measure,
262
+ onError: () => setFailed(true)
263
+ }
264
+ ),
265
+ number != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "seclai-media-badge", children: number })
266
+ ] });
267
+ const frameStyle = aspectRatioStyle(aspectRatio ?? natural ?? void 0);
268
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figure", { className: "seclai-media seclai-media-image", children: [
269
+ onOpen ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
270
+ "button",
271
+ {
272
+ type: "button",
273
+ className: "seclai-media-frame",
274
+ style: frameStyle,
275
+ "aria-label": `Open ${label} full size`,
276
+ "aria-haspopup": "dialog",
277
+ onClick: onOpen,
278
+ children: frameContent
279
+ }
280
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "seclai-media-frame", style: frameStyle, children: frameContent }),
281
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figcaption", { className: "seclai-media-bar", children: [
282
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: attachment.url, download: filename, "aria-label": `Download ${label}`, children: "Download" }),
283
+ hasContent(extra) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "seclai-media-actions", children: extra })
284
+ ] })
285
+ ] });
286
+ }
287
+
288
+ // src/media/MediaSkeleton.tsx
289
+ var import_jsx_runtime3 = require("react/jsx-runtime");
290
+ function MediaSkeleton({ aspectRatio, number, label }) {
291
+ const name = label ?? (number != null ? `Image ${number} is being generated` : "Image is being generated");
292
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "seclai-media seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
293
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio), children: number != null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "seclai-media-badge", children: number }) }),
294
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "seclai-media-bar", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "seclai-media-skeleton-line" }) })
295
+ ] });
296
+ }
297
+
298
+ // src/media/MediaViewer.tsx
299
+ var import_react3 = require("react");
300
+ var import_jsx_runtime4 = require("react/jsx-runtime");
301
+ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
302
+ const dialog = (0, import_react3.useRef)(null);
303
+ const closeButton = (0, import_react3.useRef)(null);
304
+ const returnFocus = (0, import_react3.useRef)(null);
305
+ const isOpen = (0, import_react3.useRef)(false);
306
+ const titleId = (0, import_react3.useId)();
307
+ const current = index != null ? attachments[index] : void 0;
308
+ const open = current != null;
309
+ isOpen.current = open;
310
+ (0, import_react3.useEffect)(() => {
311
+ const el = dialog.current;
312
+ if (!el) return;
313
+ if (open && !el.open) {
314
+ returnFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
315
+ el.showModal();
316
+ closeButton.current?.focus();
317
+ } else if (!open && el.open) {
318
+ el.close();
319
+ restoreFocus();
320
+ }
321
+ }, [open]);
322
+ (0, import_react3.useEffect)(
323
+ () => () => {
324
+ if (isOpen.current) restoreFocus();
325
+ },
326
+ []
327
+ );
328
+ function restoreFocus() {
329
+ const target = returnFocus.current;
330
+ returnFocus.current = null;
331
+ if (target?.isConnected) target.focus();
332
+ }
333
+ const last = attachments.length - 1;
334
+ const atStart = index == null || index <= 0;
335
+ const atEnd = index == null || index >= last;
336
+ function go(step) {
337
+ if (index == null) return;
338
+ const next = index + step;
339
+ if (next >= 0 && next <= last) onIndexChange(next);
340
+ }
341
+ function onKeyDown(event) {
342
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight" && event.key !== "Escape") return;
343
+ event.preventDefault();
344
+ event.stopPropagation();
345
+ if (event.key === "ArrowLeft") go(-1);
346
+ else if (event.key === "ArrowRight") go(1);
347
+ else onClose();
348
+ }
349
+ function onCancel(event) {
350
+ event.preventDefault();
351
+ onClose();
352
+ }
353
+ function onDialogClose() {
354
+ if (isOpen.current) onClose();
355
+ }
356
+ function onClick(event) {
357
+ if (event.target === event.currentTarget) onClose();
358
+ }
359
+ const number = index != null ? index + 1 : 0;
360
+ const label = current ? imageLabel(current, number) : "";
361
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
362
+ "dialog",
363
+ {
364
+ ref: dialog,
365
+ className: "seclai-viewer",
366
+ "aria-labelledby": titleId,
367
+ onKeyDown,
368
+ onCancel,
369
+ onClose: onDialogClose,
370
+ onClick,
371
+ children: current && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-viewer-body", children: [
372
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { className: "seclai-viewer-image", src: current.url, alt: label }),
373
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-viewer-bar", children: [
374
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "seclai-viewer-title", id: titleId, children: [
375
+ label,
376
+ attachments.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "seclai-viewer-count", children: [
377
+ number,
378
+ " of ",
379
+ attachments.length
380
+ ] })
381
+ ] }),
382
+ attachments.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
383
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
384
+ "button",
385
+ {
386
+ type: "button",
387
+ className: "seclai-button",
388
+ "aria-disabled": atStart,
389
+ onClick: () => go(-1),
390
+ children: "Previous"
391
+ }
392
+ ),
393
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "seclai-button", "aria-disabled": atEnd, onClick: () => go(1), children: "Next" })
394
+ ] }),
395
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
396
+ "a",
397
+ {
398
+ className: "seclai-button seclai-button-primary",
399
+ href: current.url,
400
+ download: attachmentFileName(current, number),
401
+ children: "Download"
402
+ }
403
+ ),
404
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "seclai-button", ref: closeButton, onClick: onClose, children: "Close" })
405
+ ] })
406
+ ] })
407
+ }
408
+ );
409
+ }
410
+
411
+ // src/media/MediaGallery.tsx
412
+ var import_jsx_runtime5 = require("react/jsx-runtime");
413
+ var DOWNLOAD_ALL_DELAY_MS = 400;
414
+ function MediaGallery({
415
+ attachments,
416
+ aspectRatio,
417
+ pending = 0,
418
+ actions
419
+ }) {
420
+ const images = attachments.filter(isImage);
421
+ const files = attachments.filter((attachment) => !isImage(attachment));
422
+ const [viewing, setViewing] = (0, import_react4.useState)(null);
423
+ const [downloading, setDownloading] = (0, import_react4.useState)(false);
424
+ const abort = (0, import_react4.useRef)(null);
425
+ (0, import_react4.useEffect)(() => () => abort.current?.abort(), []);
426
+ if (viewing != null && viewing >= images.length) setViewing(null);
427
+ async function downloadAll() {
428
+ if (downloading) return;
429
+ const controller = new AbortController();
430
+ abort.current = controller;
431
+ setDownloading(true);
432
+ try {
433
+ await downloadSequentially(
434
+ images.map((image, i) => ({ url: image.url, filename: attachmentFileName(image, i + 1) })),
435
+ DOWNLOAD_ALL_DELAY_MS,
436
+ controller.signal
437
+ );
438
+ } finally {
439
+ if (!controller.signal.aborted) setDownloading(false);
440
+ }
441
+ }
442
+ const skeletons = Math.max(0, Math.floor(pending));
443
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "seclai-gallery", children: [
444
+ images.length + skeletons > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("ul", { className: "seclai-gallery-grid", children: [
445
+ images.map((image, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
446
+ MediaPreview,
447
+ {
448
+ attachment: image,
449
+ aspectRatio,
450
+ number: i + 1,
451
+ actions: actions?.(image, i + 1),
452
+ onOpen: () => setViewing(i)
453
+ }
454
+ ) }, image.id)),
455
+ Array.from({ length: skeletons }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MediaSkeleton, { aspectRatio, number: images.length + i + 1 }) }, `pending-${i}`))
456
+ ] }),
457
+ images.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "seclai-gallery-actions", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
458
+ "button",
459
+ {
460
+ type: "button",
461
+ className: "seclai-button",
462
+ "aria-disabled": downloading,
463
+ onClick: downloadAll,
464
+ children: downloading ? "Downloading\u2026" : `Download all ${images.length}`
465
+ }
466
+ ) }),
467
+ files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MediaPreview, { attachment: file }, file.id)),
468
+ images.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
469
+ MediaViewer,
470
+ {
471
+ attachments: images,
472
+ index: viewing,
473
+ onIndexChange: setViewing,
474
+ onClose: () => setViewing(null)
475
+ }
476
+ )
138
477
  ] });
139
478
  }
140
479
 
141
480
  // src/useAgentRun.ts
142
- var import_react2 = require("react");
481
+ var import_react5 = require("react");
143
482
 
144
483
  // src/sse.ts
145
484
  function parseData(data) {
@@ -285,15 +624,15 @@ function applyEvent(state, { event, data }, endpoints) {
285
624
  }
286
625
  function useAgentRun(options = {}) {
287
626
  const { basePath, agentId, onEvent } = options;
288
- const endpoints = (0, import_react2.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
289
- const [state, setState] = (0, import_react2.useState)(IDLE);
290
- const active = (0, import_react2.useRef)(null);
291
- const onEventRef = (0, import_react2.useRef)(onEvent);
292
- (0, import_react2.useEffect)(() => {
627
+ const endpoints = (0, import_react5.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
628
+ const [state, setState] = (0, import_react5.useState)(IDLE);
629
+ const active = (0, import_react5.useRef)(null);
630
+ const onEventRef = (0, import_react5.useRef)(onEvent);
631
+ (0, import_react5.useEffect)(() => {
293
632
  onEventRef.current = onEvent;
294
633
  });
295
- (0, import_react2.useEffect)(() => () => active.current?.abort(), []);
296
- const start = (0, import_react2.useCallback)(
634
+ (0, import_react5.useEffect)(() => () => active.current?.abort(), []);
635
+ const start = (0, import_react5.useCallback)(
297
636
  async ({ input, uploadIds, sessionId }) => {
298
637
  active.current?.abort();
299
638
  const controller = new AbortController();
@@ -353,8 +692,8 @@ function useAgentRun(options = {}) {
353
692
  },
354
693
  [endpoints]
355
694
  );
356
- const cancel = (0, import_react2.useCallback)(() => active.current?.abort(), []);
357
- const reset = (0, import_react2.useCallback)(() => {
695
+ const cancel = (0, import_react5.useCallback)(() => active.current?.abort(), []);
696
+ const reset = (0, import_react5.useCallback)(() => {
358
697
  const controller = active.current;
359
698
  active.current = null;
360
699
  controller?.abort();
@@ -364,7 +703,7 @@ function useAgentRun(options = {}) {
364
703
  }
365
704
 
366
705
  // src/AgentChat.tsx
367
- var import_jsx_runtime3 = require("react/jsx-runtime");
706
+ var import_jsx_runtime6 = require("react/jsx-runtime");
368
707
  function createSessionId() {
369
708
  if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
370
709
  return Array.from(
@@ -388,13 +727,13 @@ function plural(count, word) {
388
727
  }
389
728
  function FileChip({ name, tag, preview, status, error, onRemove }) {
390
729
  const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
391
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: "seclai-file", "data-status": status, children: [
392
- preview && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
393
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "seclai-file-text", children: [
394
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "seclai-file-name", title: name, children: name }),
395
- meta && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "seclai-file-meta", children: meta })
730
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "seclai-file", "data-status": status, children: [
731
+ preview && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
732
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "seclai-file-text", children: [
733
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-file-name", title: name, children: name }),
734
+ meta && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-file-meta", children: meta })
396
735
  ] }),
397
- onRemove && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
736
+ onRemove && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
398
737
  "button",
399
738
  {
400
739
  type: "button",
@@ -407,8 +746,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
407
746
  ] });
408
747
  }
409
748
  function Turn({ turn, previews }) {
410
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: `seclai-turn seclai-turn-${turn.role}`, children: [
411
- turn.files && turn.files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "seclai-files", "aria-label": "Attached files", children: turn.files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
749
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: `seclai-turn seclai-turn-${turn.role}`, children: [
750
+ turn.files && turn.files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "seclai-files", "aria-label": "Attached files", children: turn.files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
412
751
  FileChip,
413
752
  {
414
753
  name: file.name,
@@ -417,10 +756,10 @@ function Turn({ turn, previews }) {
417
756
  },
418
757
  file.uploadId
419
758
  )) }),
420
- turn.text && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MarkdownContent, { content: turn.text }),
421
- turn.attachments?.map((attachment) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MediaPreview, { attachment }, attachment.id)),
422
- turn.error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "seclai-error", role: "alert", children: turn.error }),
423
- turn.cancelled && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "seclai-notice", children: "Stopped." })
759
+ turn.text && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MarkdownContent, { content: turn.text }),
760
+ turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MediaGallery, { attachments: turn.attachments }),
761
+ turn.error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "seclai-error", role: "alert", children: turn.error }),
762
+ turn.cancelled && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "seclai-notice", children: "Stopped." })
424
763
  ] });
425
764
  }
426
765
  function AttachControl({
@@ -430,9 +769,9 @@ function AttachControl({
430
769
  disabled,
431
770
  onFiles
432
771
  }) {
433
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
772
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
434
773
  label,
435
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
774
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
436
775
  "input",
437
776
  {
438
777
  type: "file",
@@ -456,19 +795,19 @@ function AgentChat({
456
795
  attachButtons,
457
796
  onBeforeSend
458
797
  }) {
459
- const endpoints = (0, import_react3.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
798
+ const endpoints = (0, import_react6.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
460
799
  const run = useAgentRun({ basePath, agentId });
461
800
  const { slots } = useAcceptedAttachments(endpoints);
462
- const [turns, setTurns] = (0, import_react3.useState)([]);
463
- const [message, setMessage] = (0, import_react3.useState)("");
464
- const [files, setFiles] = (0, import_react3.useState)([]);
465
- const [notice, setNotice] = (0, import_react3.useState)(null);
466
- const [dragging, setDragging] = (0, import_react3.useState)(false);
467
- const sessionId = (0, import_react3.useRef)(null);
468
- const nextTurnId = (0, import_react3.useRef)(0);
469
- const sentPreviews = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
470
- const pendingPreviews = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
471
- (0, import_react3.useEffect)(
801
+ const [turns, setTurns] = (0, import_react6.useState)([]);
802
+ const [message, setMessage] = (0, import_react6.useState)("");
803
+ const [files, setFiles] = (0, import_react6.useState)([]);
804
+ const [notice, setNotice] = (0, import_react6.useState)(null);
805
+ const [dragging, setDragging] = (0, import_react6.useState)(false);
806
+ const sessionId = (0, import_react6.useRef)(null);
807
+ const nextTurnId = (0, import_react6.useRef)(0);
808
+ const sentPreviews = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
809
+ const pendingPreviews = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
810
+ (0, import_react6.useEffect)(
472
811
  () => () => {
473
812
  pendingPreviews.current.forEach(revoke);
474
813
  sentPreviews.current.forEach(revoke);
@@ -616,19 +955,19 @@ function AgentChat({
616
955
  }
617
956
  } : {};
618
957
  const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
619
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "seclai-agent seclai-chat", children: [
620
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": running, children: [
621
- turns.map((turn) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Turn, { turn, previews: sentPreviews.current }, turn.id)),
622
- running && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MarkdownContent, { content: run.text }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "seclai-notice", children: "Thinking\u2026" }) })
958
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "seclai-agent seclai-chat", children: [
959
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": running, children: [
960
+ turns.map((turn) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Turn, { turn, previews: sentPreviews.current }, turn.id)),
961
+ running && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MarkdownContent, { content: run.text }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "seclai-notice", children: "Thinking\u2026" }) })
623
962
  ] }),
624
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
963
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
625
964
  "form",
626
965
  {
627
966
  className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
628
967
  onSubmit,
629
968
  ...dropHandlers,
630
969
  children: [
631
- files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
970
+ files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
632
971
  FileChip,
633
972
  {
634
973
  name: f.name,
@@ -640,7 +979,7 @@ function AgentChat({
640
979
  },
641
980
  f.localId
642
981
  )) }),
643
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
982
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
644
983
  "textarea",
645
984
  {
646
985
  rows: 2,
@@ -652,9 +991,9 @@ function AgentChat({
652
991
  onPaste: acceptsFiles ? onPaste : void 0
653
992
  }
654
993
  ),
655
- notice && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "seclai-error", role: "alert", children: notice }),
656
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "seclai-actions", children: [
657
- acceptsFiles && buttons.map((button) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
994
+ notice && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "seclai-error", role: "alert", children: notice }),
995
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "seclai-actions", children: [
996
+ acceptsFiles && buttons.map((button) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
658
997
  AttachControl,
659
998
  {
660
999
  label: button.label,
@@ -665,8 +1004,8 @@ function AgentChat({
665
1004
  },
666
1005
  `${button.label}\0${button.tag ?? ""}`
667
1006
  )),
668
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
669
- running && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1007
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
1008
+ running && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
670
1009
  ] })
671
1010
  ]
672
1011
  }
@@ -675,8 +1014,8 @@ function AgentChat({
675
1014
  }
676
1015
 
677
1016
  // src/AgentRunForm.tsx
678
- var import_react4 = require("react");
679
- var import_jsx_runtime4 = require("react/jsx-runtime");
1017
+ var import_react7 = require("react");
1018
+ var import_jsx_runtime7 = require("react/jsx-runtime");
680
1019
  function slotProblem(slot, count) {
681
1020
  const label = slot.label ?? slot.name;
682
1021
  const min = slot.min ?? 0;
@@ -687,13 +1026,13 @@ function slotProblem(slot, count) {
687
1026
  return null;
688
1027
  }
689
1028
  function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
690
- const endpoints = (0, import_react4.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
1029
+ const endpoints = (0, import_react7.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
691
1030
  const run = useAgentRun({ basePath, agentId });
692
1031
  const { slots, error: loadError } = useAcceptedAttachments(endpoints);
693
- const [input, setInput] = (0, import_react4.useState)("");
694
- const [files, setFiles] = (0, import_react4.useState)({});
695
- const [uploading, setUploading] = (0, import_react4.useState)(false);
696
- const [formError, setFormError] = (0, import_react4.useState)(null);
1032
+ const [input, setInput] = (0, import_react7.useState)("");
1033
+ const [files, setFiles] = (0, import_react7.useState)({});
1034
+ const [uploading, setUploading] = (0, import_react7.useState)(false);
1035
+ const [formError, setFormError] = (0, import_react7.useState)(null);
697
1036
  const selected = Object.values(files).flat();
698
1037
  const busy = uploading || run.status === "running";
699
1038
  async function submit(event) {
@@ -727,30 +1066,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
727
1066
  onFinish?.(result);
728
1067
  }
729
1068
  if (loadError) {
730
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "seclai-agent", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-error", role: "alert", children: loadError }) });
1069
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "seclai-agent", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-error", role: "alert", children: loadError }) });
731
1070
  }
732
1071
  if (!slots) {
733
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-agent", children: [
734
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-notice", children: "Loading\u2026" }),
735
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
736
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", {}),
737
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", {})
1072
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-agent", children: [
1073
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-notice", children: "Loading\u2026" }),
1074
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
1075
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", {}),
1076
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", {})
738
1077
  ] })
739
1078
  ] });
740
1079
  }
741
1080
  const error = formError ?? run.error;
742
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-agent", children: [
743
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { className: "seclai-form", onSubmit: submit, children: [
744
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "seclai-field", children: [
745
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: inputLabel }),
746
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
1081
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-agent", children: [
1082
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("form", { className: "seclai-form", onSubmit: submit, children: [
1083
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "seclai-field", children: [
1084
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: inputLabel }),
1085
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
747
1086
  ] }),
748
- slots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "seclai-field", children: [
749
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
1087
+ slots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "seclai-field", children: [
1088
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
750
1089
  slot.label ?? slot.name,
751
1090
  (slot.min ?? 0) > 0 ? " (required)" : ""
752
1091
  ] }),
753
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1092
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
754
1093
  "input",
755
1094
  {
756
1095
  type: "file",
@@ -761,29 +1100,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
761
1100
  }
762
1101
  )
763
1102
  ] }, slot.name)),
764
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-actions", children: [
765
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
766
- run.status === "running" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1103
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-actions", children: [
1104
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
1105
+ run.status === "running" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
767
1106
  ] })
768
1107
  ] }),
769
- run.steps.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
1108
+ run.steps.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { children: [
770
1109
  step.name,
771
1110
  ": ",
772
1111
  step.message
773
1112
  ] }, step.id)) }),
774
- error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-error", role: "alert", children: error }),
775
- run.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-notice", children: "Stopped." }),
776
- (run.text || run.attachments.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
777
- run.text && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MarkdownContent, { content: run.text }),
778
- run.attachments.map((attachment) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MediaPreview, { attachment }, attachment.id))
1113
+ error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-error", role: "alert", children: error }),
1114
+ run.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-notice", children: "Stopped." }),
1115
+ (run.text || run.attachments.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
1116
+ run.text && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MarkdownContent, { content: run.text }),
1117
+ run.attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MediaGallery, { attachments: run.attachments })
779
1118
  ] })
780
1119
  ] });
781
1120
  }
782
1121
 
783
1122
  // src/SeclaiAgent.tsx
784
- var import_jsx_runtime5 = require("react/jsx-runtime");
1123
+ var import_jsx_runtime8 = require("react/jsx-runtime");
785
1124
  function SeclaiAgent({ mode, basePath, agentId }) {
786
- return mode === "chat" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AgentChat, { basePath, agentId }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AgentRunForm, { basePath, agentId });
1125
+ return mode === "chat" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AgentChat, { basePath, agentId }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AgentRunForm, { basePath, agentId });
787
1126
  }
788
1127
  // Annotate the CommonJS export names for ESM import in node:
789
1128
  0 && (module.exports = {
@@ -791,8 +1130,12 @@ function SeclaiAgent({ mode, basePath, agentId }) {
791
1130
  AgentRunForm,
792
1131
  DEFAULT_BASE_PATH,
793
1132
  MarkdownContent,
1133
+ MediaGallery,
794
1134
  MediaPreview,
1135
+ MediaSkeleton,
1136
+ MediaViewer,
795
1137
  SeclaiAgent,
1138
+ attachmentFileName,
796
1139
  createEndpoints,
797
1140
  fetchAttachmentReferences,
798
1141
  uploadFile,