@seclai/react 0.0.6 → 0.0.8

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) {
@@ -205,7 +544,8 @@ var IDLE = {
205
544
  steps: [],
206
545
  attachments: [],
207
546
  error: null,
208
- runId: null
547
+ runId: null,
548
+ startedAt: null
209
549
  };
210
550
  function toAttachments(files, runId, endpoints) {
211
551
  if (!files || !runId) return [];
@@ -283,17 +623,21 @@ function applyEvent(state, { event, data }, endpoints) {
283
623
  }
284
624
  }
285
625
  function useAgentRun(options = {}) {
286
- const { basePath, agentId } = options;
287
- const endpoints = (0, import_react2.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
288
- const [state, setState] = (0, import_react2.useState)(IDLE);
289
- const active = (0, import_react2.useRef)(null);
290
- (0, import_react2.useEffect)(() => () => active.current?.abort(), []);
291
- const start = (0, import_react2.useCallback)(
626
+ const { basePath, agentId, onEvent } = options;
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)(() => {
632
+ onEventRef.current = onEvent;
633
+ });
634
+ (0, import_react5.useEffect)(() => () => active.current?.abort(), []);
635
+ const start = (0, import_react5.useCallback)(
292
636
  async ({ input, uploadIds, sessionId }) => {
293
637
  active.current?.abort();
294
638
  const controller = new AbortController();
295
639
  active.current = controller;
296
- let current = { ...IDLE, status: "running" };
640
+ let current = { ...IDLE, status: "running", startedAt: Date.now() };
297
641
  const update = (next) => {
298
642
  current = next;
299
643
  if (active.current === controller) setState(next);
@@ -315,10 +659,18 @@ function useAgentRun(options = {}) {
315
659
  return current;
316
660
  }
317
661
  for await (const event of readSseStream(res.body)) {
662
+ if (controller.signal.aborted) break;
318
663
  update(applyEvent(current, event, endpoints));
664
+ try {
665
+ onEventRef.current?.(event);
666
+ } catch (err) {
667
+ console.error("useAgentRun: onEvent threw", err);
668
+ }
319
669
  if (current.status !== "running") break;
320
670
  }
321
- if (current.status === "running") {
671
+ if (controller.signal.aborted) {
672
+ if (current.status === "running") update({ ...current, status: "cancelled" });
673
+ } else if (current.status === "running") {
322
674
  update({
323
675
  ...current,
324
676
  status: "failed",
@@ -340,12 +692,18 @@ function useAgentRun(options = {}) {
340
692
  },
341
693
  [endpoints]
342
694
  );
343
- const cancel = (0, import_react2.useCallback)(() => active.current?.abort(), []);
344
- return { ...state, start, cancel };
695
+ const cancel = (0, import_react5.useCallback)(() => active.current?.abort(), []);
696
+ const reset = (0, import_react5.useCallback)(() => {
697
+ const controller = active.current;
698
+ active.current = null;
699
+ controller?.abort();
700
+ setState(IDLE);
701
+ }, []);
702
+ return { ...state, start, cancel, reset };
345
703
  }
346
704
 
347
705
  // src/AgentChat.tsx
348
- var import_jsx_runtime3 = require("react/jsx-runtime");
706
+ var import_jsx_runtime6 = require("react/jsx-runtime");
349
707
  function createSessionId() {
350
708
  if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
351
709
  return Array.from(
@@ -369,13 +727,13 @@ function plural(count, word) {
369
727
  }
370
728
  function FileChip({ name, tag, preview, status, error, onRemove }) {
371
729
  const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
372
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: "seclai-file", "data-status": status, children: [
373
- preview && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
374
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "seclai-file-text", children: [
375
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "seclai-file-name", title: name, children: name }),
376
- 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 })
377
735
  ] }),
378
- onRemove && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
736
+ onRemove && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
379
737
  "button",
380
738
  {
381
739
  type: "button",
@@ -388,8 +746,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
388
746
  ] });
389
747
  }
390
748
  function Turn({ turn, previews }) {
391
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: `seclai-turn seclai-turn-${turn.role}`, children: [
392
- 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)(
393
751
  FileChip,
394
752
  {
395
753
  name: file.name,
@@ -398,10 +756,10 @@ function Turn({ turn, previews }) {
398
756
  },
399
757
  file.uploadId
400
758
  )) }),
401
- turn.text && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MarkdownContent, { content: turn.text }),
402
- turn.attachments?.map((attachment) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MediaPreview, { attachment }, attachment.id)),
403
- turn.error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "seclai-error", role: "alert", children: turn.error }),
404
- 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." })
405
763
  ] });
406
764
  }
407
765
  function AttachControl({
@@ -411,9 +769,9 @@ function AttachControl({
411
769
  disabled,
412
770
  onFiles
413
771
  }) {
414
- 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: [
415
773
  label,
416
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
774
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
417
775
  "input",
418
776
  {
419
777
  type: "file",
@@ -437,19 +795,19 @@ function AgentChat({
437
795
  attachButtons,
438
796
  onBeforeSend
439
797
  }) {
440
- const endpoints = (0, import_react3.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
798
+ const endpoints = (0, import_react6.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
441
799
  const run = useAgentRun({ basePath, agentId });
442
800
  const { slots } = useAcceptedAttachments(endpoints);
443
- const [turns, setTurns] = (0, import_react3.useState)([]);
444
- const [message, setMessage] = (0, import_react3.useState)("");
445
- const [files, setFiles] = (0, import_react3.useState)([]);
446
- const [notice, setNotice] = (0, import_react3.useState)(null);
447
- const [dragging, setDragging] = (0, import_react3.useState)(false);
448
- const sessionId = (0, import_react3.useRef)(null);
449
- const nextTurnId = (0, import_react3.useRef)(0);
450
- const sentPreviews = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
451
- const pendingPreviews = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
452
- (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)(
453
811
  () => () => {
454
812
  pendingPreviews.current.forEach(revoke);
455
813
  sentPreviews.current.forEach(revoke);
@@ -597,19 +955,19 @@ function AgentChat({
597
955
  }
598
956
  } : {};
599
957
  const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
600
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "seclai-agent seclai-chat", children: [
601
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": running, children: [
602
- turns.map((turn) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Turn, { turn, previews: sentPreviews.current }, turn.id)),
603
- 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" }) })
604
962
  ] }),
605
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
963
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
606
964
  "form",
607
965
  {
608
966
  className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
609
967
  onSubmit,
610
968
  ...dropHandlers,
611
969
  children: [
612
- 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)(
613
971
  FileChip,
614
972
  {
615
973
  name: f.name,
@@ -621,7 +979,7 @@ function AgentChat({
621
979
  },
622
980
  f.localId
623
981
  )) }),
624
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
982
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
625
983
  "textarea",
626
984
  {
627
985
  rows: 2,
@@ -633,9 +991,9 @@ function AgentChat({
633
991
  onPaste: acceptsFiles ? onPaste : void 0
634
992
  }
635
993
  ),
636
- notice && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "seclai-error", role: "alert", children: notice }),
637
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "seclai-actions", children: [
638
- 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)(
639
997
  AttachControl,
640
998
  {
641
999
  label: button.label,
@@ -646,8 +1004,8 @@ function AgentChat({
646
1004
  },
647
1005
  `${button.label}\0${button.tag ?? ""}`
648
1006
  )),
649
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
650
- 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" })
651
1009
  ] })
652
1010
  ]
653
1011
  }
@@ -656,8 +1014,8 @@ function AgentChat({
656
1014
  }
657
1015
 
658
1016
  // src/AgentRunForm.tsx
659
- var import_react4 = require("react");
660
- var import_jsx_runtime4 = require("react/jsx-runtime");
1017
+ var import_react7 = require("react");
1018
+ var import_jsx_runtime7 = require("react/jsx-runtime");
661
1019
  function slotProblem(slot, count) {
662
1020
  const label = slot.label ?? slot.name;
663
1021
  const min = slot.min ?? 0;
@@ -668,13 +1026,13 @@ function slotProblem(slot, count) {
668
1026
  return null;
669
1027
  }
670
1028
  function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
671
- const endpoints = (0, import_react4.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
1029
+ const endpoints = (0, import_react7.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
672
1030
  const run = useAgentRun({ basePath, agentId });
673
1031
  const { slots, error: loadError } = useAcceptedAttachments(endpoints);
674
- const [input, setInput] = (0, import_react4.useState)("");
675
- const [files, setFiles] = (0, import_react4.useState)({});
676
- const [uploading, setUploading] = (0, import_react4.useState)(false);
677
- 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);
678
1036
  const selected = Object.values(files).flat();
679
1037
  const busy = uploading || run.status === "running";
680
1038
  async function submit(event) {
@@ -708,30 +1066,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
708
1066
  onFinish?.(result);
709
1067
  }
710
1068
  if (loadError) {
711
- 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 }) });
712
1070
  }
713
1071
  if (!slots) {
714
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-agent", children: [
715
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-notice", children: "Loading\u2026" }),
716
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
717
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", {}),
718
- /* @__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", {})
719
1077
  ] })
720
1078
  ] });
721
1079
  }
722
1080
  const error = formError ?? run.error;
723
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-agent", children: [
724
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { className: "seclai-form", onSubmit: submit, children: [
725
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "seclai-field", children: [
726
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: inputLabel }),
727
- /* @__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) })
728
1086
  ] }),
729
- slots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "seclai-field", children: [
730
- /* @__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: [
731
1089
  slot.label ?? slot.name,
732
1090
  (slot.min ?? 0) > 0 ? " (required)" : ""
733
1091
  ] }),
734
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1092
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
735
1093
  "input",
736
1094
  {
737
1095
  type: "file",
@@ -742,29 +1100,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
742
1100
  }
743
1101
  )
744
1102
  ] }, slot.name)),
745
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "seclai-actions", children: [
746
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
747
- 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" })
748
1106
  ] })
749
1107
  ] }),
750
- 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: [
751
1109
  step.name,
752
1110
  ": ",
753
1111
  step.message
754
1112
  ] }, step.id)) }),
755
- error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-error", role: "alert", children: error }),
756
- run.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "seclai-notice", children: "Stopped." }),
757
- (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: [
758
- run.text && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MarkdownContent, { content: run.text }),
759
- 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 })
760
1118
  ] })
761
1119
  ] });
762
1120
  }
763
1121
 
764
1122
  // src/SeclaiAgent.tsx
765
- var import_jsx_runtime5 = require("react/jsx-runtime");
1123
+ var import_jsx_runtime8 = require("react/jsx-runtime");
766
1124
  function SeclaiAgent({ mode, basePath, agentId }) {
767
- 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 });
768
1126
  }
769
1127
  // Annotate the CommonJS export names for ESM import in node:
770
1128
  0 && (module.exports = {
@@ -772,8 +1130,12 @@ function SeclaiAgent({ mode, basePath, agentId }) {
772
1130
  AgentRunForm,
773
1131
  DEFAULT_BASE_PATH,
774
1132
  MarkdownContent,
1133
+ MediaGallery,
775
1134
  MediaPreview,
1135
+ MediaSkeleton,
1136
+ MediaViewer,
776
1137
  SeclaiAgent,
1138
+ attachmentFileName,
777
1139
  createEndpoints,
778
1140
  fetchAttachmentReferences,
779
1141
  uploadFile,