@seclai/react 0.0.7 → 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.js CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  // src/AgentChat.tsx
4
4
  import {
5
- useEffect as useEffect3,
5
+ useEffect as useEffect6,
6
6
  useMemo as useMemo2,
7
- useRef as useRef2,
8
- useState as useState3
7
+ useRef as useRef5,
8
+ useState as useState5
9
9
  } from "react";
10
10
 
11
11
  // src/attachments.ts
@@ -99,18 +99,353 @@ function MarkdownContent({ content }) {
99
99
  return /* @__PURE__ */ jsx("div", { className: "seclai-markdown", children: content });
100
100
  }
101
101
 
102
+ // src/media/MediaGallery.tsx
103
+ import { useEffect as useEffect4, useRef as useRef3, useState as useState3 } from "react";
104
+
105
+ // src/placeholders/MediaPreview.tsx
106
+ import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
107
+
108
+ // src/media/files.ts
109
+ var EXTENSIONS = {
110
+ "image/jpeg": "jpg",
111
+ "image/svg+xml": "svg",
112
+ "image/x-icon": "ico",
113
+ "image/vnd.microsoft.icon": "ico",
114
+ "audio/mpeg": "mp3",
115
+ "video/quicktime": "mov",
116
+ "text/plain": "txt",
117
+ "text/markdown": "md",
118
+ "application/octet-stream": "bin"
119
+ };
120
+ function isImage(attachment) {
121
+ return attachment.mime.toLowerCase().startsWith("image/");
122
+ }
123
+ function extensionForMime(mime) {
124
+ const type = mime.split(";")[0].trim().toLowerCase();
125
+ const known = EXTENSIONS[type];
126
+ if (known) return known;
127
+ const subtype = type.split("/")[1] ?? "";
128
+ const ext = (subtype.split("+").at(-1) ?? "").replace(/^x-/, "");
129
+ return /^[a-z0-9]{1,5}$/.test(ext) ? ext : "bin";
130
+ }
131
+ function attachmentFileName(attachment, number) {
132
+ if (attachment.name) return attachment.name;
133
+ const base = number != null ? `image-${number}` : attachment.id;
134
+ return `${base}.${extensionForMime(attachment.mime)}`;
135
+ }
136
+ var SAFE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
137
+ function isSafeUrl(url) {
138
+ try {
139
+ return SAFE_PROTOCOLS.has(new URL(url, document.baseURI).protocol);
140
+ } catch {
141
+ return false;
142
+ }
143
+ }
144
+ function triggerDownload(url, filename) {
145
+ if (!isSafeUrl(url)) {
146
+ console.warn(`seclai: not downloading ${filename}, its URL isn't http(s), blob or relative.`);
147
+ return;
148
+ }
149
+ const link = document.createElement("a");
150
+ link.href = url;
151
+ link.download = filename;
152
+ link.rel = "noopener";
153
+ link.style.display = "none";
154
+ document.body.append(link);
155
+ link.click();
156
+ link.remove();
157
+ }
158
+ async function downloadSequentially(files, delayMs, signal) {
159
+ for (const [i, file] of files.entries()) {
160
+ if (signal?.aborted) return;
161
+ if (i > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
162
+ if (signal?.aborted) return;
163
+ triggerDownload(file.url, file.filename);
164
+ }
165
+ }
166
+
102
167
  // src/placeholders/MediaPreview.tsx
103
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
104
- function MediaPreview({ attachment }) {
105
- const name = attachment.name ?? attachment.id;
106
- return /* @__PURE__ */ jsxs("figure", { className: "seclai-media", children: [
107
- attachment.mime.startsWith("image/") && /* @__PURE__ */ jsx2("img", { src: attachment.url, alt: name }),
108
- /* @__PURE__ */ jsx2("figcaption", { children: /* @__PURE__ */ jsx2("a", { href: attachment.url, download: name, children: name }) })
168
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
169
+ function hasContent(node) {
170
+ return node != null && node !== false && node !== "";
171
+ }
172
+ function aspectRatioStyle(ratio) {
173
+ return ratio == null ? void 0 : { aspectRatio: String(ratio) };
174
+ }
175
+ function imageLabel(attachment, number) {
176
+ return attachment.name ?? (number != null ? `Image ${number}` : "Image");
177
+ }
178
+ function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }) {
179
+ const filename = attachmentFileName(attachment, number);
180
+ const extra = typeof actions === "function" ? actions(attachment) : actions;
181
+ if (!isImage(attachment)) {
182
+ return /* @__PURE__ */ jsx2("figure", { className: "seclai-media", children: /* @__PURE__ */ jsxs("figcaption", { children: [
183
+ /* @__PURE__ */ jsx2("a", { href: attachment.url, download: filename, children: attachment.name ?? filename }),
184
+ hasContent(extra) && /* @__PURE__ */ jsx2("span", { className: "seclai-media-actions", children: extra })
185
+ ] }) });
186
+ }
187
+ return /* @__PURE__ */ jsx2(
188
+ ImageCard,
189
+ {
190
+ attachment,
191
+ aspectRatio,
192
+ number,
193
+ filename,
194
+ extra,
195
+ onOpen
196
+ }
197
+ );
198
+ }
199
+ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen }) {
200
+ const img = useRef(null);
201
+ const [natural, setNatural] = useState2(null);
202
+ const [failed, setFailed] = useState2(false);
203
+ const label = imageLabel(attachment, number);
204
+ function measure() {
205
+ const el = img.current;
206
+ if (el && el.naturalWidth > 0 && el.naturalHeight > 0) {
207
+ setNatural(`${el.naturalWidth} / ${el.naturalHeight}`);
208
+ }
209
+ }
210
+ useEffect2(() => {
211
+ setNatural(null);
212
+ setFailed(false);
213
+ const el = img.current;
214
+ if (el?.complete) {
215
+ if (el.naturalWidth === 0) setFailed(true);
216
+ else measure();
217
+ }
218
+ }, [attachment.url]);
219
+ const frameContent = /* @__PURE__ */ jsxs(Fragment, { children: [
220
+ failed ? /* @__PURE__ */ jsx2("span", { className: "seclai-media-error", children: "Couldn't load the image." }) : /* @__PURE__ */ jsx2(
221
+ "img",
222
+ {
223
+ ref: img,
224
+ src: attachment.url,
225
+ alt: label,
226
+ loading: "lazy",
227
+ decoding: "async",
228
+ onLoad: measure,
229
+ onError: () => setFailed(true)
230
+ }
231
+ ),
232
+ number != null && /* @__PURE__ */ jsx2("span", { className: "seclai-media-badge", children: number })
233
+ ] });
234
+ const frameStyle = aspectRatioStyle(aspectRatio ?? natural ?? void 0);
235
+ return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-image", children: [
236
+ onOpen ? /* @__PURE__ */ jsx2(
237
+ "button",
238
+ {
239
+ type: "button",
240
+ className: "seclai-media-frame",
241
+ style: frameStyle,
242
+ "aria-label": `Open ${label} full size`,
243
+ "aria-haspopup": "dialog",
244
+ onClick: onOpen,
245
+ children: frameContent
246
+ }
247
+ ) : /* @__PURE__ */ jsx2("div", { className: "seclai-media-frame", style: frameStyle, children: frameContent }),
248
+ /* @__PURE__ */ jsxs("figcaption", { className: "seclai-media-bar", children: [
249
+ /* @__PURE__ */ jsx2("a", { href: attachment.url, download: filename, "aria-label": `Download ${label}`, children: "Download" }),
250
+ hasContent(extra) && /* @__PURE__ */ jsx2("span", { className: "seclai-media-actions", children: extra })
251
+ ] })
252
+ ] });
253
+ }
254
+
255
+ // src/media/MediaSkeleton.tsx
256
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
257
+ function MediaSkeleton({ aspectRatio, number, label }) {
258
+ const name = label ?? (number != null ? `Image ${number} is being generated` : "Image is being generated");
259
+ return /* @__PURE__ */ jsxs2("div", { className: "seclai-media seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
260
+ /* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio), children: number != null && /* @__PURE__ */ jsx3("span", { className: "seclai-media-badge", children: number }) }),
261
+ /* @__PURE__ */ jsx3("div", { className: "seclai-media-bar", children: /* @__PURE__ */ jsx3("span", { className: "seclai-media-skeleton-line" }) })
262
+ ] });
263
+ }
264
+
265
+ // src/media/MediaViewer.tsx
266
+ import { useEffect as useEffect3, useId, useRef as useRef2 } from "react";
267
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
268
+ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
269
+ const dialog = useRef2(null);
270
+ const closeButton = useRef2(null);
271
+ const returnFocus = useRef2(null);
272
+ const isOpen = useRef2(false);
273
+ const titleId = useId();
274
+ const current = index != null ? attachments[index] : void 0;
275
+ const open = current != null;
276
+ isOpen.current = open;
277
+ useEffect3(() => {
278
+ const el = dialog.current;
279
+ if (!el) return;
280
+ if (open && !el.open) {
281
+ returnFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
282
+ el.showModal();
283
+ closeButton.current?.focus();
284
+ } else if (!open && el.open) {
285
+ el.close();
286
+ restoreFocus();
287
+ }
288
+ }, [open]);
289
+ useEffect3(
290
+ () => () => {
291
+ if (isOpen.current) restoreFocus();
292
+ },
293
+ []
294
+ );
295
+ function restoreFocus() {
296
+ const target = returnFocus.current;
297
+ returnFocus.current = null;
298
+ if (target?.isConnected) target.focus();
299
+ }
300
+ const last = attachments.length - 1;
301
+ const atStart = index == null || index <= 0;
302
+ const atEnd = index == null || index >= last;
303
+ function go(step) {
304
+ if (index == null) return;
305
+ const next = index + step;
306
+ if (next >= 0 && next <= last) onIndexChange(next);
307
+ }
308
+ function onKeyDown(event) {
309
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight" && event.key !== "Escape") return;
310
+ event.preventDefault();
311
+ event.stopPropagation();
312
+ if (event.key === "ArrowLeft") go(-1);
313
+ else if (event.key === "ArrowRight") go(1);
314
+ else onClose();
315
+ }
316
+ function onCancel(event) {
317
+ event.preventDefault();
318
+ onClose();
319
+ }
320
+ function onDialogClose() {
321
+ if (isOpen.current) onClose();
322
+ }
323
+ function onClick(event) {
324
+ if (event.target === event.currentTarget) onClose();
325
+ }
326
+ const number = index != null ? index + 1 : 0;
327
+ const label = current ? imageLabel(current, number) : "";
328
+ return /* @__PURE__ */ jsx4(
329
+ "dialog",
330
+ {
331
+ ref: dialog,
332
+ className: "seclai-viewer",
333
+ "aria-labelledby": titleId,
334
+ onKeyDown,
335
+ onCancel,
336
+ onClose: onDialogClose,
337
+ onClick,
338
+ children: current && /* @__PURE__ */ jsxs3("div", { className: "seclai-viewer-body", children: [
339
+ /* @__PURE__ */ jsx4("img", { className: "seclai-viewer-image", src: current.url, alt: label }),
340
+ /* @__PURE__ */ jsxs3("div", { className: "seclai-viewer-bar", children: [
341
+ /* @__PURE__ */ jsxs3("p", { className: "seclai-viewer-title", id: titleId, children: [
342
+ label,
343
+ attachments.length > 1 && /* @__PURE__ */ jsxs3("span", { className: "seclai-viewer-count", children: [
344
+ number,
345
+ " of ",
346
+ attachments.length
347
+ ] })
348
+ ] }),
349
+ attachments.length > 1 && /* @__PURE__ */ jsxs3(Fragment2, { children: [
350
+ /* @__PURE__ */ jsx4(
351
+ "button",
352
+ {
353
+ type: "button",
354
+ className: "seclai-button",
355
+ "aria-disabled": atStart,
356
+ onClick: () => go(-1),
357
+ children: "Previous"
358
+ }
359
+ ),
360
+ /* @__PURE__ */ jsx4("button", { type: "button", className: "seclai-button", "aria-disabled": atEnd, onClick: () => go(1), children: "Next" })
361
+ ] }),
362
+ /* @__PURE__ */ jsx4(
363
+ "a",
364
+ {
365
+ className: "seclai-button seclai-button-primary",
366
+ href: current.url,
367
+ download: attachmentFileName(current, number),
368
+ children: "Download"
369
+ }
370
+ ),
371
+ /* @__PURE__ */ jsx4("button", { type: "button", className: "seclai-button", ref: closeButton, onClick: onClose, children: "Close" })
372
+ ] })
373
+ ] })
374
+ }
375
+ );
376
+ }
377
+
378
+ // src/media/MediaGallery.tsx
379
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
380
+ var DOWNLOAD_ALL_DELAY_MS = 400;
381
+ function MediaGallery({
382
+ attachments,
383
+ aspectRatio,
384
+ pending = 0,
385
+ actions
386
+ }) {
387
+ const images = attachments.filter(isImage);
388
+ const files = attachments.filter((attachment) => !isImage(attachment));
389
+ const [viewing, setViewing] = useState3(null);
390
+ const [downloading, setDownloading] = useState3(false);
391
+ const abort = useRef3(null);
392
+ useEffect4(() => () => abort.current?.abort(), []);
393
+ if (viewing != null && viewing >= images.length) setViewing(null);
394
+ async function downloadAll() {
395
+ if (downloading) return;
396
+ const controller = new AbortController();
397
+ abort.current = controller;
398
+ setDownloading(true);
399
+ try {
400
+ await downloadSequentially(
401
+ images.map((image, i) => ({ url: image.url, filename: attachmentFileName(image, i + 1) })),
402
+ DOWNLOAD_ALL_DELAY_MS,
403
+ controller.signal
404
+ );
405
+ } finally {
406
+ if (!controller.signal.aborted) setDownloading(false);
407
+ }
408
+ }
409
+ const skeletons = Math.max(0, Math.floor(pending));
410
+ return /* @__PURE__ */ jsxs4("div", { className: "seclai-gallery", children: [
411
+ images.length + skeletons > 0 && /* @__PURE__ */ jsxs4("ul", { className: "seclai-gallery-grid", children: [
412
+ images.map((image, i) => /* @__PURE__ */ jsx5("li", { children: /* @__PURE__ */ jsx5(
413
+ MediaPreview,
414
+ {
415
+ attachment: image,
416
+ aspectRatio,
417
+ number: i + 1,
418
+ actions: actions?.(image, i + 1),
419
+ onOpen: () => setViewing(i)
420
+ }
421
+ ) }, image.id)),
422
+ Array.from({ length: skeletons }, (_, i) => /* @__PURE__ */ jsx5("li", { children: /* @__PURE__ */ jsx5(MediaSkeleton, { aspectRatio, number: images.length + i + 1 }) }, `pending-${i}`))
423
+ ] }),
424
+ images.length > 1 && /* @__PURE__ */ jsx5("div", { className: "seclai-gallery-actions", children: /* @__PURE__ */ jsx5(
425
+ "button",
426
+ {
427
+ type: "button",
428
+ className: "seclai-button",
429
+ "aria-disabled": downloading,
430
+ onClick: downloadAll,
431
+ children: downloading ? "Downloading\u2026" : `Download all ${images.length}`
432
+ }
433
+ ) }),
434
+ files.map((file) => /* @__PURE__ */ jsx5(MediaPreview, { attachment: file }, file.id)),
435
+ images.length > 0 && /* @__PURE__ */ jsx5(
436
+ MediaViewer,
437
+ {
438
+ attachments: images,
439
+ index: viewing,
440
+ onIndexChange: setViewing,
441
+ onClose: () => setViewing(null)
442
+ }
443
+ )
109
444
  ] });
110
445
  }
111
446
 
112
447
  // src/useAgentRun.ts
113
- import { useCallback, useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
448
+ import { useCallback, useEffect as useEffect5, useMemo, useRef as useRef4, useState as useState4 } from "react";
114
449
 
115
450
  // src/sse.ts
116
451
  function parseData(data) {
@@ -257,13 +592,13 @@ function applyEvent(state, { event, data }, endpoints) {
257
592
  function useAgentRun(options = {}) {
258
593
  const { basePath, agentId, onEvent } = options;
259
594
  const endpoints = useMemo(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
260
- const [state, setState] = useState2(IDLE);
261
- const active = useRef(null);
262
- const onEventRef = useRef(onEvent);
263
- useEffect2(() => {
595
+ const [state, setState] = useState4(IDLE);
596
+ const active = useRef4(null);
597
+ const onEventRef = useRef4(onEvent);
598
+ useEffect5(() => {
264
599
  onEventRef.current = onEvent;
265
600
  });
266
- useEffect2(() => () => active.current?.abort(), []);
601
+ useEffect5(() => () => active.current?.abort(), []);
267
602
  const start = useCallback(
268
603
  async ({ input, uploadIds, sessionId }) => {
269
604
  active.current?.abort();
@@ -335,7 +670,7 @@ function useAgentRun(options = {}) {
335
670
  }
336
671
 
337
672
  // src/AgentChat.tsx
338
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
673
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
339
674
  function createSessionId() {
340
675
  if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
341
676
  return Array.from(
@@ -359,13 +694,13 @@ function plural(count, word) {
359
694
  }
360
695
  function FileChip({ name, tag, preview, status, error, onRemove }) {
361
696
  const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
362
- return /* @__PURE__ */ jsxs2("li", { className: "seclai-file", "data-status": status, children: [
363
- preview && /* @__PURE__ */ jsx3("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
364
- /* @__PURE__ */ jsxs2("span", { className: "seclai-file-text", children: [
365
- /* @__PURE__ */ jsx3("span", { className: "seclai-file-name", title: name, children: name }),
366
- meta && /* @__PURE__ */ jsx3("span", { className: "seclai-file-meta", children: meta })
697
+ return /* @__PURE__ */ jsxs5("li", { className: "seclai-file", "data-status": status, children: [
698
+ preview && /* @__PURE__ */ jsx6("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
699
+ /* @__PURE__ */ jsxs5("span", { className: "seclai-file-text", children: [
700
+ /* @__PURE__ */ jsx6("span", { className: "seclai-file-name", title: name, children: name }),
701
+ meta && /* @__PURE__ */ jsx6("span", { className: "seclai-file-meta", children: meta })
367
702
  ] }),
368
- onRemove && /* @__PURE__ */ jsx3(
703
+ onRemove && /* @__PURE__ */ jsx6(
369
704
  "button",
370
705
  {
371
706
  type: "button",
@@ -378,8 +713,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
378
713
  ] });
379
714
  }
380
715
  function Turn({ turn, previews }) {
381
- return /* @__PURE__ */ jsxs2("li", { className: `seclai-turn seclai-turn-${turn.role}`, children: [
382
- turn.files && turn.files.length > 0 && /* @__PURE__ */ jsx3("ul", { className: "seclai-files", "aria-label": "Attached files", children: turn.files.map((file) => /* @__PURE__ */ jsx3(
716
+ return /* @__PURE__ */ jsxs5("li", { className: `seclai-turn seclai-turn-${turn.role}`, children: [
717
+ turn.files && turn.files.length > 0 && /* @__PURE__ */ jsx6("ul", { className: "seclai-files", "aria-label": "Attached files", children: turn.files.map((file) => /* @__PURE__ */ jsx6(
383
718
  FileChip,
384
719
  {
385
720
  name: file.name,
@@ -388,10 +723,10 @@ function Turn({ turn, previews }) {
388
723
  },
389
724
  file.uploadId
390
725
  )) }),
391
- turn.text && /* @__PURE__ */ jsx3(MarkdownContent, { content: turn.text }),
392
- turn.attachments?.map((attachment) => /* @__PURE__ */ jsx3(MediaPreview, { attachment }, attachment.id)),
393
- turn.error && /* @__PURE__ */ jsx3("p", { className: "seclai-error", role: "alert", children: turn.error }),
394
- turn.cancelled && /* @__PURE__ */ jsx3("p", { className: "seclai-notice", children: "Stopped." })
726
+ turn.text && /* @__PURE__ */ jsx6(MarkdownContent, { content: turn.text }),
727
+ turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ jsx6(MediaGallery, { attachments: turn.attachments }),
728
+ turn.error && /* @__PURE__ */ jsx6("p", { className: "seclai-error", role: "alert", children: turn.error }),
729
+ turn.cancelled && /* @__PURE__ */ jsx6("p", { className: "seclai-notice", children: "Stopped." })
395
730
  ] });
396
731
  }
397
732
  function AttachControl({
@@ -401,9 +736,9 @@ function AttachControl({
401
736
  disabled,
402
737
  onFiles
403
738
  }) {
404
- return /* @__PURE__ */ jsxs2("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
739
+ return /* @__PURE__ */ jsxs5("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
405
740
  label,
406
- /* @__PURE__ */ jsx3(
741
+ /* @__PURE__ */ jsx6(
407
742
  "input",
408
743
  {
409
744
  type: "file",
@@ -430,16 +765,16 @@ function AgentChat({
430
765
  const endpoints = useMemo2(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
431
766
  const run = useAgentRun({ basePath, agentId });
432
767
  const { slots } = useAcceptedAttachments(endpoints);
433
- const [turns, setTurns] = useState3([]);
434
- const [message, setMessage] = useState3("");
435
- const [files, setFiles] = useState3([]);
436
- const [notice, setNotice] = useState3(null);
437
- const [dragging, setDragging] = useState3(false);
438
- const sessionId = useRef2(null);
439
- const nextTurnId = useRef2(0);
440
- const sentPreviews = useRef2(/* @__PURE__ */ new Map());
441
- const pendingPreviews = useRef2(/* @__PURE__ */ new Set());
442
- useEffect3(
768
+ const [turns, setTurns] = useState5([]);
769
+ const [message, setMessage] = useState5("");
770
+ const [files, setFiles] = useState5([]);
771
+ const [notice, setNotice] = useState5(null);
772
+ const [dragging, setDragging] = useState5(false);
773
+ const sessionId = useRef5(null);
774
+ const nextTurnId = useRef5(0);
775
+ const sentPreviews = useRef5(/* @__PURE__ */ new Map());
776
+ const pendingPreviews = useRef5(/* @__PURE__ */ new Set());
777
+ useEffect6(
443
778
  () => () => {
444
779
  pendingPreviews.current.forEach(revoke);
445
780
  sentPreviews.current.forEach(revoke);
@@ -587,19 +922,19 @@ function AgentChat({
587
922
  }
588
923
  } : {};
589
924
  const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
590
- return /* @__PURE__ */ jsxs2("div", { className: "seclai-agent seclai-chat", children: [
591
- /* @__PURE__ */ jsxs2("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": running, children: [
592
- turns.map((turn) => /* @__PURE__ */ jsx3(Turn, { turn, previews: sentPreviews.current }, turn.id)),
593
- running && /* @__PURE__ */ jsx3("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ jsx3(MarkdownContent, { content: run.text }) : /* @__PURE__ */ jsx3("p", { className: "seclai-notice", children: "Thinking\u2026" }) })
925
+ return /* @__PURE__ */ jsxs5("div", { className: "seclai-agent seclai-chat", children: [
926
+ /* @__PURE__ */ jsxs5("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": running, children: [
927
+ turns.map((turn) => /* @__PURE__ */ jsx6(Turn, { turn, previews: sentPreviews.current }, turn.id)),
928
+ running && /* @__PURE__ */ jsx6("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ jsx6(MarkdownContent, { content: run.text }) : /* @__PURE__ */ jsx6("p", { className: "seclai-notice", children: "Thinking\u2026" }) })
594
929
  ] }),
595
- /* @__PURE__ */ jsxs2(
930
+ /* @__PURE__ */ jsxs5(
596
931
  "form",
597
932
  {
598
933
  className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
599
934
  onSubmit,
600
935
  ...dropHandlers,
601
936
  children: [
602
- files.length > 0 && /* @__PURE__ */ jsx3("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx3(
937
+ files.length > 0 && /* @__PURE__ */ jsx6("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx6(
603
938
  FileChip,
604
939
  {
605
940
  name: f.name,
@@ -611,7 +946,7 @@ function AgentChat({
611
946
  },
612
947
  f.localId
613
948
  )) }),
614
- /* @__PURE__ */ jsx3(
949
+ /* @__PURE__ */ jsx6(
615
950
  "textarea",
616
951
  {
617
952
  rows: 2,
@@ -623,9 +958,9 @@ function AgentChat({
623
958
  onPaste: acceptsFiles ? onPaste : void 0
624
959
  }
625
960
  ),
626
- notice && /* @__PURE__ */ jsx3("p", { className: "seclai-error", role: "alert", children: notice }),
627
- /* @__PURE__ */ jsxs2("div", { className: "seclai-actions", children: [
628
- acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx3(
961
+ notice && /* @__PURE__ */ jsx6("p", { className: "seclai-error", role: "alert", children: notice }),
962
+ /* @__PURE__ */ jsxs5("div", { className: "seclai-actions", children: [
963
+ acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx6(
629
964
  AttachControl,
630
965
  {
631
966
  label: button.label,
@@ -636,8 +971,8 @@ function AgentChat({
636
971
  },
637
972
  `${button.label}\0${button.tag ?? ""}`
638
973
  )),
639
- /* @__PURE__ */ jsx3("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
640
- running && /* @__PURE__ */ jsx3("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
974
+ /* @__PURE__ */ jsx6("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
975
+ running && /* @__PURE__ */ jsx6("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
641
976
  ] })
642
977
  ]
643
978
  }
@@ -646,8 +981,8 @@ function AgentChat({
646
981
  }
647
982
 
648
983
  // src/AgentRunForm.tsx
649
- import { useMemo as useMemo3, useState as useState4 } from "react";
650
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
984
+ import { useMemo as useMemo3, useState as useState6 } from "react";
985
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
651
986
  function slotProblem(slot, count) {
652
987
  const label = slot.label ?? slot.name;
653
988
  const min = slot.min ?? 0;
@@ -661,10 +996,10 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
661
996
  const endpoints = useMemo3(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
662
997
  const run = useAgentRun({ basePath, agentId });
663
998
  const { slots, error: loadError } = useAcceptedAttachments(endpoints);
664
- const [input, setInput] = useState4("");
665
- const [files, setFiles] = useState4({});
666
- const [uploading, setUploading] = useState4(false);
667
- const [formError, setFormError] = useState4(null);
999
+ const [input, setInput] = useState6("");
1000
+ const [files, setFiles] = useState6({});
1001
+ const [uploading, setUploading] = useState6(false);
1002
+ const [formError, setFormError] = useState6(null);
668
1003
  const selected = Object.values(files).flat();
669
1004
  const busy = uploading || run.status === "running";
670
1005
  async function submit(event) {
@@ -698,30 +1033,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
698
1033
  onFinish?.(result);
699
1034
  }
700
1035
  if (loadError) {
701
- return /* @__PURE__ */ jsx4("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx4("p", { className: "seclai-error", role: "alert", children: loadError }) });
1036
+ return /* @__PURE__ */ jsx7("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: loadError }) });
702
1037
  }
703
1038
  if (!slots) {
704
- return /* @__PURE__ */ jsxs3("div", { className: "seclai-agent", children: [
705
- /* @__PURE__ */ jsx4("p", { className: "seclai-notice", children: "Loading\u2026" }),
706
- /* @__PURE__ */ jsxs3("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
707
- /* @__PURE__ */ jsx4("span", {}),
708
- /* @__PURE__ */ jsx4("span", {})
1039
+ return /* @__PURE__ */ jsxs6("div", { className: "seclai-agent", children: [
1040
+ /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Loading\u2026" }),
1041
+ /* @__PURE__ */ jsxs6("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
1042
+ /* @__PURE__ */ jsx7("span", {}),
1043
+ /* @__PURE__ */ jsx7("span", {})
709
1044
  ] })
710
1045
  ] });
711
1046
  }
712
1047
  const error = formError ?? run.error;
713
- return /* @__PURE__ */ jsxs3("div", { className: "seclai-agent", children: [
714
- /* @__PURE__ */ jsxs3("form", { className: "seclai-form", onSubmit: submit, children: [
715
- /* @__PURE__ */ jsxs3("label", { className: "seclai-field", children: [
716
- /* @__PURE__ */ jsx4("span", { children: inputLabel }),
717
- /* @__PURE__ */ jsx4("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
1048
+ return /* @__PURE__ */ jsxs6("div", { className: "seclai-agent", children: [
1049
+ /* @__PURE__ */ jsxs6("form", { className: "seclai-form", onSubmit: submit, children: [
1050
+ /* @__PURE__ */ jsxs6("label", { className: "seclai-field", children: [
1051
+ /* @__PURE__ */ jsx7("span", { children: inputLabel }),
1052
+ /* @__PURE__ */ jsx7("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
718
1053
  ] }),
719
- slots.map((slot) => /* @__PURE__ */ jsxs3("label", { className: "seclai-field", children: [
720
- /* @__PURE__ */ jsxs3("span", { children: [
1054
+ slots.map((slot) => /* @__PURE__ */ jsxs6("label", { className: "seclai-field", children: [
1055
+ /* @__PURE__ */ jsxs6("span", { children: [
721
1056
  slot.label ?? slot.name,
722
1057
  (slot.min ?? 0) > 0 ? " (required)" : ""
723
1058
  ] }),
724
- /* @__PURE__ */ jsx4(
1059
+ /* @__PURE__ */ jsx7(
725
1060
  "input",
726
1061
  {
727
1062
  type: "file",
@@ -732,37 +1067,41 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
732
1067
  }
733
1068
  )
734
1069
  ] }, slot.name)),
735
- /* @__PURE__ */ jsxs3("div", { className: "seclai-actions", children: [
736
- /* @__PURE__ */ jsx4("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
737
- run.status === "running" && /* @__PURE__ */ jsx4("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1070
+ /* @__PURE__ */ jsxs6("div", { className: "seclai-actions", children: [
1071
+ /* @__PURE__ */ jsx7("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
1072
+ run.status === "running" && /* @__PURE__ */ jsx7("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
738
1073
  ] })
739
1074
  ] }),
740
- run.steps.length > 0 && /* @__PURE__ */ jsx4("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs3("li", { children: [
1075
+ run.steps.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs6("li", { children: [
741
1076
  step.name,
742
1077
  ": ",
743
1078
  step.message
744
1079
  ] }, step.id)) }),
745
- error && /* @__PURE__ */ jsx4("p", { className: "seclai-error", role: "alert", children: error }),
746
- run.status === "cancelled" && /* @__PURE__ */ jsx4("p", { className: "seclai-notice", children: "Stopped." }),
747
- (run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs3("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
748
- run.text && /* @__PURE__ */ jsx4(MarkdownContent, { content: run.text }),
749
- run.attachments.map((attachment) => /* @__PURE__ */ jsx4(MediaPreview, { attachment }, attachment.id))
1080
+ error && /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: error }),
1081
+ run.status === "cancelled" && /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Stopped." }),
1082
+ (run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs6("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
1083
+ run.text && /* @__PURE__ */ jsx7(MarkdownContent, { content: run.text }),
1084
+ run.attachments.length > 0 && /* @__PURE__ */ jsx7(MediaGallery, { attachments: run.attachments })
750
1085
  ] })
751
1086
  ] });
752
1087
  }
753
1088
 
754
1089
  // src/SeclaiAgent.tsx
755
- import { jsx as jsx5 } from "react/jsx-runtime";
1090
+ import { jsx as jsx8 } from "react/jsx-runtime";
756
1091
  function SeclaiAgent({ mode, basePath, agentId }) {
757
- return mode === "chat" ? /* @__PURE__ */ jsx5(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx5(AgentRunForm, { basePath, agentId });
1092
+ return mode === "chat" ? /* @__PURE__ */ jsx8(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx8(AgentRunForm, { basePath, agentId });
758
1093
  }
759
1094
  export {
760
1095
  AgentChat,
761
1096
  AgentRunForm,
762
1097
  DEFAULT_BASE_PATH,
763
1098
  MarkdownContent,
1099
+ MediaGallery,
764
1100
  MediaPreview,
1101
+ MediaSkeleton,
1102
+ MediaViewer,
765
1103
  SeclaiAgent,
1104
+ attachmentFileName,
766
1105
  createEndpoints,
767
1106
  fetchAttachmentReferences,
768
1107
  uploadFile,