@seclai/react 0.0.14 → 0.0.16

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
@@ -3,10 +3,10 @@
3
3
  // src/AgentChat.tsx
4
4
  import {
5
5
  Fragment as Fragment4,
6
- useEffect as useEffect6,
6
+ useEffect as useEffect7,
7
7
  useMemo as useMemo2,
8
8
  useRef as useRef5,
9
- useState as useState5
9
+ useState as useState6
10
10
  } from "react";
11
11
 
12
12
  // src/attachments.ts
@@ -46,10 +46,20 @@ async function readJson(res) {
46
46
  async function fetchAttachmentReferences(endpoints, { signal } = {}) {
47
47
  return readJson(await fetch(endpoints.attachmentReferences, { signal }));
48
48
  }
49
- async function uploadFile(endpoints, file, { signal } = {}) {
49
+ async function uploadFile(endpoints, file, { signal, params } = {}) {
50
50
  const form = new FormData();
51
51
  form.set("file", file);
52
- return readJson(await fetch(endpoints.upload, { method: "POST", body: form, signal }));
52
+ const url = params ? withQuery(endpoints.upload, params) : endpoints.upload;
53
+ return readJson(await fetch(url, { method: "POST", body: form, signal }));
54
+ }
55
+ function withQuery(url, params) {
56
+ const query = new URLSearchParams(params).toString();
57
+ if (!query) return url;
58
+ const hashAt = url.indexOf("#");
59
+ const base = hashAt < 0 ? url : url.slice(0, hashAt);
60
+ const hash = hashAt < 0 ? "" : url.slice(hashAt);
61
+ const separator = !base.includes("?") ? "?" : base.endsWith("?") || base.endsWith("&") ? "" : "&";
62
+ return `${base}${separator}${query}${hash}`;
53
63
  }
54
64
 
55
65
  // src/attachments.ts
@@ -265,11 +275,9 @@ function isSafeUrl(url) {
265
275
  return false;
266
276
  }
267
277
  }
268
- function triggerDownload(url, filename) {
269
- if (!isSafeUrl(url)) {
270
- console.warn(`seclai: not downloading ${filename}, its URL isn't http(s), blob or relative.`);
271
- return;
272
- }
278
+ var SAVE_FILES_DELAY_MS = 400;
279
+ var REVOKE_OBJECT_URL_DELAY_MS = 4e4;
280
+ function clickDownloadLink(url, filename) {
273
281
  const link = document.createElement("a");
274
282
  link.href = url;
275
283
  link.download = filename;
@@ -279,14 +287,39 @@ function triggerDownload(url, filename) {
279
287
  link.click();
280
288
  link.remove();
281
289
  }
282
- async function downloadSequentially(files, delayMs, signal) {
290
+ function saveFile(urlOrBlob, filename) {
291
+ if (typeof document === "undefined") return;
292
+ if (typeof urlOrBlob !== "string") {
293
+ const url = URL.createObjectURL(urlOrBlob);
294
+ clickDownloadLink(url, filename);
295
+ setTimeout(() => URL.revokeObjectURL(url), REVOKE_OBJECT_URL_DELAY_MS);
296
+ return;
297
+ }
298
+ if (!isSafeUrl(urlOrBlob)) {
299
+ console.warn(`seclai: not downloading ${filename}, its URL isn't http(s), blob or relative.`);
300
+ return;
301
+ }
302
+ clickDownloadLink(urlOrBlob, filename);
303
+ }
304
+ async function saveFiles(files, { delayMs = SAVE_FILES_DELAY_MS, signal } = {}) {
283
305
  for (const [i, file] of files.entries()) {
284
306
  if (signal?.aborted) return;
285
- if (i > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
307
+ if (i > 0) await wait(delayMs, signal);
286
308
  if (signal?.aborted) return;
287
- triggerDownload(file.url, file.filename);
309
+ saveFile(file.source, file.filename);
288
310
  }
289
311
  }
312
+ function wait(ms, signal) {
313
+ return new Promise((resolve) => {
314
+ const done = () => {
315
+ clearTimeout(timer);
316
+ signal?.removeEventListener("abort", done);
317
+ resolve();
318
+ };
319
+ const timer = setTimeout(done, ms);
320
+ signal?.addEventListener("abort", done, { once: true });
321
+ });
322
+ }
290
323
 
291
324
  // src/placeholders/MediaPreview.tsx
292
325
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -501,7 +534,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
501
534
 
502
535
  // src/media/MediaGallery.tsx
503
536
  import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
504
- var DOWNLOAD_ALL_DELAY_MS = 400;
537
+ var DOWNLOAD_ALL_DELAY_MS = SAVE_FILES_DELAY_MS;
505
538
  function MediaGallery({
506
539
  attachments,
507
540
  aspectRatio,
@@ -521,10 +554,9 @@ function MediaGallery({
521
554
  abort.current = controller;
522
555
  setDownloading(true);
523
556
  try {
524
- await downloadSequentially(
525
- images.map((image, i) => ({ url: image.url, filename: attachmentFileName(image, i + 1) })),
526
- DOWNLOAD_ALL_DELAY_MS,
527
- controller.signal
557
+ await saveFiles(
558
+ images.map((image, i) => ({ source: image.url, filename: attachmentFileName(image, i + 1) })),
559
+ { delayMs: DOWNLOAD_ALL_DELAY_MS, signal: controller.signal }
528
560
  );
529
561
  } finally {
530
562
  if (!controller.signal.aborted) setDownloading(false);
@@ -568,8 +600,80 @@ function MediaGallery({
568
600
  ] });
569
601
  }
570
602
 
603
+ // src/RunProgress.tsx
604
+ import { useEffect as useEffect5, useState as useState4 } from "react";
605
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
606
+ function useElapsed(startedAt, running) {
607
+ const [now, setNow] = useState4(null);
608
+ useEffect5(() => {
609
+ if (!running || startedAt === null) return;
610
+ let timer;
611
+ const tick = () => {
612
+ const time = Date.now();
613
+ setNow(time);
614
+ const into = ((time - startedAt) % 1e3 + 1e3) % 1e3;
615
+ timer = setTimeout(tick, 1e3 - into);
616
+ };
617
+ tick();
618
+ return () => clearTimeout(timer);
619
+ }, [running, startedAt]);
620
+ if (startedAt === null || now === null) return 0;
621
+ return Math.max(0, Math.floor((now - startedAt) / 1e3));
622
+ }
623
+ function formatClock(seconds) {
624
+ return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
625
+ }
626
+ function spokenDuration(seconds) {
627
+ const minutes = Math.floor(seconds / 60);
628
+ const rest = seconds % 60;
629
+ const unit = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
630
+ if (minutes === 0) return unit(rest, "second");
631
+ return rest === 0 ? unit(minutes, "minute") : `${unit(minutes, "minute")} ${unit(rest, "second")}`;
632
+ }
633
+ function RunProgress({ run, showSteps = true, message, className }) {
634
+ const running = run.status === "running";
635
+ const seconds = useElapsed(run.startedAt, running);
636
+ if (!running) return null;
637
+ const note = typeof message === "function" ? message(seconds) : message;
638
+ const last = run.steps.length - 1;
639
+ return /* @__PURE__ */ jsxs6(
640
+ "div",
641
+ {
642
+ className: className ? `seclai-run-progress ${className}` : "seclai-run-progress",
643
+ "aria-live": "polite",
644
+ children: [
645
+ showSteps && (run.steps.length === 0 ? /* @__PURE__ */ jsx6("p", { className: "seclai-notice", children: "Starting the run\u2026" }) : /* @__PURE__ */ jsx6("ol", { className: "seclai-steps", children: run.steps.map((step, i) => /* @__PURE__ */ jsxs6("li", { children: [
646
+ /* @__PURE__ */ jsx6("span", { className: "seclai-step-marker", "aria-hidden": "true", children: i === last ? "\u25CF" : "\u2713" }),
647
+ /* @__PURE__ */ jsx6("span", { className: "seclai-sr-only", children: i === last ? "In progress: " : "Done: " }),
648
+ /* @__PURE__ */ jsxs6("span", { children: [
649
+ /* @__PURE__ */ jsx6("span", { className: "seclai-step-name", children: step.name }),
650
+ step.message && /* @__PURE__ */ jsxs6("span", { className: "seclai-step-message", children: [
651
+ " \xB7 ",
652
+ step.message
653
+ ] })
654
+ ] })
655
+ ] }, step.id)) })),
656
+ /* @__PURE__ */ jsxs6("div", { className: "seclai-run-progress-note", children: [
657
+ /* @__PURE__ */ jsx6("span", { className: "seclai-run-progress-pulse", "aria-hidden": "true" }),
658
+ note != null && note !== false && note !== "" && /* @__PURE__ */ jsx6("span", { className: "seclai-run-progress-message", children: note }),
659
+ /* @__PURE__ */ jsx6(
660
+ "span",
661
+ {
662
+ className: "seclai-run-progress-clock",
663
+ role: "timer",
664
+ "aria-live": "off",
665
+ "aria-label": `${spokenDuration(seconds)} elapsed`,
666
+ children: formatClock(seconds)
667
+ }
668
+ )
669
+ ] })
670
+ ]
671
+ }
672
+ );
673
+ }
674
+
571
675
  // src/useAgentRun.ts
572
- import { useCallback, useEffect as useEffect5, useMemo, useRef as useRef4, useState as useState4 } from "react";
676
+ import { useCallback, useEffect as useEffect6, useMemo, useRef as useRef4, useState as useState5 } from "react";
573
677
 
574
678
  // src/sse.ts
575
679
  function parseData(data) {
@@ -716,13 +820,13 @@ function applyEvent(state, { event, data }, endpoints) {
716
820
  function useAgentRun(options = {}) {
717
821
  const { basePath, agentId, onEvent } = options;
718
822
  const endpoints = useMemo(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
719
- const [state, setState] = useState4(IDLE);
823
+ const [state, setState] = useState5(IDLE);
720
824
  const active = useRef4(null);
721
825
  const onEventRef = useRef4(onEvent);
722
- useEffect5(() => {
826
+ useEffect6(() => {
723
827
  onEventRef.current = onEvent;
724
828
  });
725
- useEffect5(() => () => active.current?.abort(), []);
829
+ useEffect6(() => () => active.current?.abort(), []);
726
830
  const start = useCallback(
727
831
  async ({ input, uploadIds, sessionId }) => {
728
832
  active.current?.abort();
@@ -794,7 +898,7 @@ function useAgentRun(options = {}) {
794
898
  }
795
899
 
796
900
  // src/AgentChat.tsx
797
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
901
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
798
902
  function createSessionId() {
799
903
  if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
800
904
  return Array.from(
@@ -818,13 +922,13 @@ function plural(count, word) {
818
922
  }
819
923
  function FileChip({ name, tag, preview, status, error, onRemove }) {
820
924
  const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
821
- return /* @__PURE__ */ jsxs6("li", { className: "seclai-file", "data-status": status, children: [
822
- preview && /* @__PURE__ */ jsx6("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
823
- /* @__PURE__ */ jsxs6("span", { className: "seclai-file-text", children: [
824
- /* @__PURE__ */ jsx6("span", { className: "seclai-file-name", title: name, children: name }),
825
- meta && /* @__PURE__ */ jsx6("span", { className: "seclai-file-meta", children: meta })
925
+ return /* @__PURE__ */ jsxs7("li", { className: "seclai-file", "data-status": status, children: [
926
+ preview && /* @__PURE__ */ jsx7("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
927
+ /* @__PURE__ */ jsxs7("span", { className: "seclai-file-text", children: [
928
+ /* @__PURE__ */ jsx7("span", { className: "seclai-file-name", title: name, children: name }),
929
+ meta && /* @__PURE__ */ jsx7("span", { className: "seclai-file-meta", children: meta })
826
930
  ] }),
827
- onRemove && /* @__PURE__ */ jsx6(
931
+ onRemove && /* @__PURE__ */ jsx7(
828
932
  "button",
829
933
  {
830
934
  type: "button",
@@ -837,8 +941,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
837
941
  ] });
838
942
  }
839
943
  function UserTurn({ message, previews }) {
840
- return /* @__PURE__ */ jsxs6("li", { className: "seclai-turn seclai-turn-user", children: [
841
- message.files.length > 0 && /* @__PURE__ */ jsx6("ul", { className: "seclai-files", "aria-label": "Attached files", children: message.files.map((file) => /* @__PURE__ */ jsx6(
944
+ return /* @__PURE__ */ jsxs7("li", { className: "seclai-turn seclai-turn-user", children: [
945
+ message.files.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-files", "aria-label": "Attached files", children: message.files.map((file) => /* @__PURE__ */ jsx7(
842
946
  FileChip,
843
947
  {
844
948
  name: file.name,
@@ -847,14 +951,14 @@ function UserTurn({ message, previews }) {
847
951
  },
848
952
  file.uploadId
849
953
  )) }),
850
- message.input && /* @__PURE__ */ jsx6(MarkdownContent, { content: message.input })
954
+ message.input && /* @__PURE__ */ jsx7(MarkdownContent, { content: message.input })
851
955
  ] });
852
956
  }
853
957
  function AssistantTurn({ turn, endpoints }) {
854
958
  const { runId } = turn;
855
- return /* @__PURE__ */ jsxs6("li", { className: "seclai-turn seclai-turn-assistant", children: [
856
- turn.output && /* @__PURE__ */ jsx6(MarkdownContent, { content: turn.output }),
857
- runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ jsx6(
959
+ return /* @__PURE__ */ jsxs7("li", { className: "seclai-turn seclai-turn-assistant", children: [
960
+ turn.output && /* @__PURE__ */ jsx7(MarkdownContent, { content: turn.output }),
961
+ runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ jsx7(
858
962
  MediaGallery,
859
963
  {
860
964
  attachments: turn.attachments.map(({ id, name, mime, bytes }) => ({
@@ -866,8 +970,8 @@ function AssistantTurn({ turn, endpoints }) {
866
970
  }))
867
971
  }
868
972
  ),
869
- turn.error && /* @__PURE__ */ jsx6("p", { className: "seclai-error", role: "alert", children: turn.error }),
870
- turn.status === "cancelled" && /* @__PURE__ */ jsx6("p", { className: "seclai-notice", children: "Stopped." })
973
+ turn.error && /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: turn.error }),
974
+ turn.status === "cancelled" && /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Stopped." })
871
975
  ] });
872
976
  }
873
977
  function toTurnAttachment({ id, name, mime, bytes }) {
@@ -880,9 +984,9 @@ function AttachControl({
880
984
  disabled,
881
985
  onFiles
882
986
  }) {
883
- return /* @__PURE__ */ jsxs6("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
987
+ return /* @__PURE__ */ jsxs7("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
884
988
  label,
885
- /* @__PURE__ */ jsx6(
989
+ /* @__PURE__ */ jsx7(
886
990
  "input",
887
991
  {
888
992
  type: "file",
@@ -912,7 +1016,7 @@ function AgentChat({
912
1016
  const endpoints = useMemo2(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
913
1017
  const run = useAgentRun({ basePath, agentId });
914
1018
  const { slots } = useAcceptedAttachments(endpoints);
915
- const [transcript, setTranscript] = useState5(() => ({
1019
+ const [transcript, setTranscript] = useState6(() => ({
916
1020
  sessionId,
917
1021
  epoch: 0,
918
1022
  turns: initialTurns ?? [],
@@ -920,10 +1024,10 @@ function AgentChat({
920
1024
  generatedSessionId: null,
921
1025
  runEpoch: null
922
1026
  }));
923
- const [message, setMessage] = useState5("");
924
- const [files, setFiles] = useState5([]);
925
- const [notice, setNotice] = useState5(null);
926
- const [dragging, setDragging] = useState5(false);
1027
+ const [message, setMessage] = useState6("");
1028
+ const [files, setFiles] = useState6([]);
1029
+ const [notice, setNotice] = useState6(null);
1030
+ const [dragging, setDragging] = useState6(false);
927
1031
  const generatedSessionId = useRef5(null);
928
1032
  const shownEpoch = useRef5(transcript.epoch);
929
1033
  const turnComplete = useRef5(onTurnComplete);
@@ -942,10 +1046,10 @@ function AgentChat({
942
1046
  }
943
1047
  );
944
1048
  }
945
- useEffect6(() => {
1049
+ useEffect7(() => {
946
1050
  turnComplete.current = onTurnComplete;
947
1051
  });
948
- useEffect6(() => {
1052
+ useEffect7(() => {
949
1053
  if (shownEpoch.current === transcript.epoch) return;
950
1054
  shownEpoch.current = transcript.epoch;
951
1055
  run.cancel();
@@ -958,7 +1062,7 @@ function AgentChat({
958
1062
  setFiles([]);
959
1063
  setNotice(null);
960
1064
  }, [transcript.epoch, run.cancel]);
961
- useEffect6(
1065
+ useEffect7(
962
1066
  () => () => {
963
1067
  pendingPreviews.current.forEach(revoke);
964
1068
  sentPreviews.current.forEach(revoke);
@@ -1114,29 +1218,29 @@ function AgentChat({
1114
1218
  }
1115
1219
  } : {};
1116
1220
  const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
1117
- return /* @__PURE__ */ jsxs6("div", { className: "seclai-agent seclai-chat", children: [
1118
- /* @__PURE__ */ jsxs6("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": streaming, children: [
1119
- transcript.turns.map((turn, i) => /* @__PURE__ */ jsxs6(Fragment4, { children: [
1120
- /* @__PURE__ */ jsx6(
1221
+ return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent seclai-chat", children: [
1222
+ /* @__PURE__ */ jsxs7("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": streaming, children: [
1223
+ transcript.turns.map((turn, i) => /* @__PURE__ */ jsxs7(Fragment4, { children: [
1224
+ /* @__PURE__ */ jsx7(
1121
1225
  UserTurn,
1122
1226
  {
1123
1227
  message: { input: turn.input, files: turn.files ?? [] },
1124
1228
  previews: sentPreviews.current
1125
1229
  }
1126
1230
  ),
1127
- /* @__PURE__ */ jsx6(AssistantTurn, { turn, endpoints })
1231
+ /* @__PURE__ */ jsx7(AssistantTurn, { turn, endpoints })
1128
1232
  ] }, `${transcript.epoch}:${i}`)),
1129
- transcript.pending && /* @__PURE__ */ jsx6(UserTurn, { message: transcript.pending, previews: sentPreviews.current }),
1130
- streaming && /* @__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" }) })
1233
+ transcript.pending && /* @__PURE__ */ jsx7(UserTurn, { message: transcript.pending, previews: sentPreviews.current }),
1234
+ streaming && /* @__PURE__ */ jsx7("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ jsx7(MarkdownContent, { content: run.text }) : /* @__PURE__ */ jsx7(RunProgress, { run }) })
1131
1235
  ] }),
1132
- /* @__PURE__ */ jsxs6(
1236
+ /* @__PURE__ */ jsxs7(
1133
1237
  "form",
1134
1238
  {
1135
1239
  className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
1136
1240
  onSubmit,
1137
1241
  ...dropHandlers,
1138
1242
  children: [
1139
- files.length > 0 && /* @__PURE__ */ jsx6("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx6(
1243
+ files.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx7(
1140
1244
  FileChip,
1141
1245
  {
1142
1246
  name: f.name,
@@ -1148,7 +1252,7 @@ function AgentChat({
1148
1252
  },
1149
1253
  f.localId
1150
1254
  )) }),
1151
- /* @__PURE__ */ jsx6(
1255
+ /* @__PURE__ */ jsx7(
1152
1256
  "textarea",
1153
1257
  {
1154
1258
  rows: 2,
@@ -1160,9 +1264,9 @@ function AgentChat({
1160
1264
  onPaste: acceptsFiles ? onPaste : void 0
1161
1265
  }
1162
1266
  ),
1163
- notice && /* @__PURE__ */ jsx6("p", { className: "seclai-error", role: "alert", children: notice }),
1164
- /* @__PURE__ */ jsxs6("div", { className: "seclai-actions", children: [
1165
- acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx6(
1267
+ notice && /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: notice }),
1268
+ /* @__PURE__ */ jsxs7("div", { className: "seclai-actions", children: [
1269
+ acceptsFiles && buttons.map((button) => /* @__PURE__ */ jsx7(
1166
1270
  AttachControl,
1167
1271
  {
1168
1272
  label: button.label,
@@ -1173,8 +1277,8 @@ function AgentChat({
1173
1277
  },
1174
1278
  `${button.label}\0${button.tag ?? ""}`
1175
1279
  )),
1176
- /* @__PURE__ */ jsx6("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
1177
- running && /* @__PURE__ */ jsx6("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1280
+ /* @__PURE__ */ jsx7("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
1281
+ running && /* @__PURE__ */ jsx7("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1178
1282
  ] })
1179
1283
  ]
1180
1284
  }
@@ -1183,8 +1287,8 @@ function AgentChat({
1183
1287
  }
1184
1288
 
1185
1289
  // src/AgentRunForm.tsx
1186
- import { useMemo as useMemo3, useState as useState6 } from "react";
1187
- import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1290
+ import { useMemo as useMemo3, useState as useState7 } from "react";
1291
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
1188
1292
  function slotProblem(slot, count) {
1189
1293
  const label = slot.label ?? slot.name;
1190
1294
  const min = slot.min ?? 0;
@@ -1198,10 +1302,10 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
1198
1302
  const endpoints = useMemo3(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
1199
1303
  const run = useAgentRun({ basePath, agentId });
1200
1304
  const { slots, error: loadError } = useAcceptedAttachments(endpoints);
1201
- const [input, setInput] = useState6("");
1202
- const [files, setFiles] = useState6({});
1203
- const [uploading, setUploading] = useState6(false);
1204
- const [formError, setFormError] = useState6(null);
1305
+ const [input, setInput] = useState7("");
1306
+ const [files, setFiles] = useState7({});
1307
+ const [uploading, setUploading] = useState7(false);
1308
+ const [formError, setFormError] = useState7(null);
1205
1309
  const selected = Object.values(files).flat();
1206
1310
  const busy = uploading || run.status === "running";
1207
1311
  async function submit(event) {
@@ -1235,30 +1339,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
1235
1339
  onFinish?.(result);
1236
1340
  }
1237
1341
  if (loadError) {
1238
- return /* @__PURE__ */ jsx7("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: loadError }) });
1342
+ return /* @__PURE__ */ jsx8("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: loadError }) });
1239
1343
  }
1240
1344
  if (!slots) {
1241
- return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent", children: [
1242
- /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Loading\u2026" }),
1243
- /* @__PURE__ */ jsxs7("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
1244
- /* @__PURE__ */ jsx7("span", {}),
1245
- /* @__PURE__ */ jsx7("span", {})
1345
+ return /* @__PURE__ */ jsxs8("div", { className: "seclai-agent", children: [
1346
+ /* @__PURE__ */ jsx8("p", { className: "seclai-notice", children: "Loading\u2026" }),
1347
+ /* @__PURE__ */ jsxs8("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
1348
+ /* @__PURE__ */ jsx8("span", {}),
1349
+ /* @__PURE__ */ jsx8("span", {})
1246
1350
  ] })
1247
1351
  ] });
1248
1352
  }
1249
1353
  const error = formError ?? run.error;
1250
- return /* @__PURE__ */ jsxs7("div", { className: "seclai-agent", children: [
1251
- /* @__PURE__ */ jsxs7("form", { className: "seclai-form", onSubmit: submit, children: [
1252
- /* @__PURE__ */ jsxs7("label", { className: "seclai-field", children: [
1253
- /* @__PURE__ */ jsx7("span", { children: inputLabel }),
1254
- /* @__PURE__ */ jsx7("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
1354
+ return /* @__PURE__ */ jsxs8("div", { className: "seclai-agent", children: [
1355
+ /* @__PURE__ */ jsxs8("form", { className: "seclai-form", onSubmit: submit, children: [
1356
+ /* @__PURE__ */ jsxs8("label", { className: "seclai-field", children: [
1357
+ /* @__PURE__ */ jsx8("span", { children: inputLabel }),
1358
+ /* @__PURE__ */ jsx8("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
1255
1359
  ] }),
1256
- slots.map((slot) => /* @__PURE__ */ jsxs7("label", { className: "seclai-field", children: [
1257
- /* @__PURE__ */ jsxs7("span", { children: [
1360
+ slots.map((slot) => /* @__PURE__ */ jsxs8("label", { className: "seclai-field", children: [
1361
+ /* @__PURE__ */ jsxs8("span", { children: [
1258
1362
  slot.label ?? slot.name,
1259
1363
  (slot.min ?? 0) > 0 ? " (required)" : ""
1260
1364
  ] }),
1261
- /* @__PURE__ */ jsx7(
1365
+ /* @__PURE__ */ jsx8(
1262
1366
  "input",
1263
1367
  {
1264
1368
  type: "file",
@@ -1269,29 +1373,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
1269
1373
  }
1270
1374
  )
1271
1375
  ] }, slot.name)),
1272
- /* @__PURE__ */ jsxs7("div", { className: "seclai-actions", children: [
1273
- /* @__PURE__ */ jsx7("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
1274
- run.status === "running" && /* @__PURE__ */ jsx7("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1376
+ /* @__PURE__ */ jsxs8("div", { className: "seclai-actions", children: [
1377
+ /* @__PURE__ */ jsx8("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
1378
+ run.status === "running" && /* @__PURE__ */ jsx8("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
1275
1379
  ] })
1276
1380
  ] }),
1277
- run.steps.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs7("li", { children: [
1381
+ run.steps.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs8("li", { children: [
1278
1382
  step.name,
1279
1383
  ": ",
1280
1384
  step.message
1281
1385
  ] }, step.id)) }),
1282
- error && /* @__PURE__ */ jsx7("p", { className: "seclai-error", role: "alert", children: error }),
1283
- run.status === "cancelled" && /* @__PURE__ */ jsx7("p", { className: "seclai-notice", children: "Stopped." }),
1284
- (run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs7("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
1285
- run.text && /* @__PURE__ */ jsx7(MarkdownContent, { content: run.text }),
1286
- run.attachments.length > 0 && /* @__PURE__ */ jsx7(MediaGallery, { attachments: run.attachments })
1386
+ error && /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: error }),
1387
+ run.status === "cancelled" && /* @__PURE__ */ jsx8("p", { className: "seclai-notice", children: "Stopped." }),
1388
+ (run.text || run.attachments.length > 0) && /* @__PURE__ */ jsxs8("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
1389
+ run.text && /* @__PURE__ */ jsx8(MarkdownContent, { content: run.text }),
1390
+ run.attachments.length > 0 && /* @__PURE__ */ jsx8(MediaGallery, { attachments: run.attachments })
1287
1391
  ] })
1288
1392
  ] });
1289
1393
  }
1290
1394
 
1291
1395
  // src/SeclaiAgent.tsx
1292
- import { jsx as jsx8 } from "react/jsx-runtime";
1396
+ import { jsx as jsx9 } from "react/jsx-runtime";
1293
1397
  function SeclaiAgent({ mode, basePath, agentId }) {
1294
- return mode === "chat" ? /* @__PURE__ */ jsx8(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx8(AgentRunForm, { basePath, agentId });
1398
+ return mode === "chat" ? /* @__PURE__ */ jsx9(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx9(AgentRunForm, { basePath, agentId });
1295
1399
  }
1296
1400
  export {
1297
1401
  AgentChat,
@@ -1302,10 +1406,14 @@ export {
1302
1406
  MediaPreview,
1303
1407
  MediaSkeleton,
1304
1408
  MediaViewer,
1409
+ RunProgress,
1305
1410
  SeclaiAgent,
1306
1411
  attachmentFileName,
1307
1412
  createEndpoints,
1308
1413
  fetchAttachmentReferences,
1414
+ saveFile,
1415
+ saveFiles,
1309
1416
  uploadFile,
1310
- useAgentRun
1417
+ useAgentRun,
1418
+ useElapsed
1311
1419
  };
package/dist/styles.css CHANGED
@@ -209,6 +209,59 @@
209
209
  color: var(--seclai-muted);
210
210
  }
211
211
 
212
+ .seclai-run-progress {
213
+ display: flex;
214
+ flex-direction: column;
215
+ gap: calc(var(--seclai-gap) / 2);
216
+ }
217
+
218
+ .seclai-run-progress .seclai-steps li {
219
+ display: flex;
220
+ gap: 8px;
221
+ }
222
+
223
+ .seclai-step-marker {
224
+ flex-shrink: 0;
225
+ color: var(--seclai-muted);
226
+ }
227
+
228
+ .seclai-steps li:last-child .seclai-step-marker {
229
+ color: var(--seclai-accent);
230
+ }
231
+
232
+ .seclai-step-name {
233
+ font-weight: 500;
234
+ }
235
+
236
+ .seclai-run-progress-note {
237
+ display: flex;
238
+ align-items: center;
239
+ gap: 8px;
240
+ padding: 8px 12px;
241
+ font-size: 0.875em;
242
+ color: var(--seclai-muted);
243
+ background: var(--seclai-surface);
244
+ border-radius: var(--seclai-radius);
245
+ }
246
+
247
+ .seclai-run-progress-pulse {
248
+ flex-shrink: 0;
249
+ width: 8px;
250
+ height: 8px;
251
+ background: var(--seclai-accent);
252
+ border-radius: 50%;
253
+ animation: seclai-pulse 1.6s ease-in-out infinite;
254
+ }
255
+
256
+ .seclai-run-progress-message {
257
+ flex: 1;
258
+ }
259
+
260
+ .seclai-run-progress-clock {
261
+ margin-inline-start: auto;
262
+ font-variant-numeric: tabular-nums;
263
+ }
264
+
212
265
  /* Output */
213
266
  .seclai-output,
214
267
  .seclai-turn {
@@ -252,8 +305,12 @@
252
305
  border-radius: var(--seclai-radius);
253
306
  }
254
307
 
255
- /* Hidden from view but not from the browser, so a wrapping label opens the picker. */
256
- .seclai-agent .seclai-sr-only {
308
+ /*
309
+ * Hidden from view but not from the browser or screen readers: a wrapping label
310
+ * still opens the picker, and step states are still read out.
311
+ */
312
+ .seclai-agent .seclai-sr-only,
313
+ .seclai-run-progress .seclai-sr-only {
257
314
  position: absolute;
258
315
  width: 1px;
259
316
  height: 1px;
@@ -800,7 +857,8 @@ button.seclai-media-frame:focus-visible {
800
857
  transform: none;
801
858
  }
802
859
 
803
- .seclai-skeleton > span {
860
+ .seclai-skeleton > span,
861
+ .seclai-run-progress-pulse {
804
862
  animation: none;
805
863
  }
806
864
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seclai/react",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "React components and hooks for running Seclai agents: run form, chat, and streaming output.",
5
5
  "license": "MIT",
6
6
  "type": "module",