@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/README.md +61 -16
- package/dist/index.cjs +218 -106
- package/dist/index.d.cts +82 -3
- package/dist/index.d.ts +82 -3
- package/dist/index.js +201 -93
- package/dist/styles.css +61 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -29,17 +29,21 @@ __export(index_exports, {
|
|
|
29
29
|
MediaPreview: () => MediaPreview,
|
|
30
30
|
MediaSkeleton: () => MediaSkeleton,
|
|
31
31
|
MediaViewer: () => MediaViewer,
|
|
32
|
+
RunProgress: () => RunProgress,
|
|
32
33
|
SeclaiAgent: () => SeclaiAgent,
|
|
33
34
|
attachmentFileName: () => attachmentFileName,
|
|
34
35
|
createEndpoints: () => createEndpoints,
|
|
35
36
|
fetchAttachmentReferences: () => fetchAttachmentReferences,
|
|
37
|
+
saveFile: () => saveFile,
|
|
38
|
+
saveFiles: () => saveFiles,
|
|
36
39
|
uploadFile: () => uploadFile,
|
|
37
|
-
useAgentRun: () => useAgentRun
|
|
40
|
+
useAgentRun: () => useAgentRun,
|
|
41
|
+
useElapsed: () => useElapsed
|
|
38
42
|
});
|
|
39
43
|
module.exports = __toCommonJS(index_exports);
|
|
40
44
|
|
|
41
45
|
// src/AgentChat.tsx
|
|
42
|
-
var
|
|
46
|
+
var import_react8 = require("react");
|
|
43
47
|
|
|
44
48
|
// src/attachments.ts
|
|
45
49
|
var import_react = require("react");
|
|
@@ -78,10 +82,20 @@ async function readJson(res) {
|
|
|
78
82
|
async function fetchAttachmentReferences(endpoints, { signal } = {}) {
|
|
79
83
|
return readJson(await fetch(endpoints.attachmentReferences, { signal }));
|
|
80
84
|
}
|
|
81
|
-
async function uploadFile(endpoints, file, { signal } = {}) {
|
|
85
|
+
async function uploadFile(endpoints, file, { signal, params } = {}) {
|
|
82
86
|
const form = new FormData();
|
|
83
87
|
form.set("file", file);
|
|
84
|
-
|
|
88
|
+
const url = params ? withQuery(endpoints.upload, params) : endpoints.upload;
|
|
89
|
+
return readJson(await fetch(url, { method: "POST", body: form, signal }));
|
|
90
|
+
}
|
|
91
|
+
function withQuery(url, params) {
|
|
92
|
+
const query = new URLSearchParams(params).toString();
|
|
93
|
+
if (!query) return url;
|
|
94
|
+
const hashAt = url.indexOf("#");
|
|
95
|
+
const base = hashAt < 0 ? url : url.slice(0, hashAt);
|
|
96
|
+
const hash = hashAt < 0 ? "" : url.slice(hashAt);
|
|
97
|
+
const separator = !base.includes("?") ? "?" : base.endsWith("?") || base.endsWith("&") ? "" : "&";
|
|
98
|
+
return `${base}${separator}${query}${hash}`;
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
// src/attachments.ts
|
|
@@ -297,11 +311,9 @@ function isSafeUrl(url) {
|
|
|
297
311
|
return false;
|
|
298
312
|
}
|
|
299
313
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
314
|
+
var SAVE_FILES_DELAY_MS = 400;
|
|
315
|
+
var REVOKE_OBJECT_URL_DELAY_MS = 4e4;
|
|
316
|
+
function clickDownloadLink(url, filename) {
|
|
305
317
|
const link = document.createElement("a");
|
|
306
318
|
link.href = url;
|
|
307
319
|
link.download = filename;
|
|
@@ -311,14 +323,39 @@ function triggerDownload(url, filename) {
|
|
|
311
323
|
link.click();
|
|
312
324
|
link.remove();
|
|
313
325
|
}
|
|
314
|
-
|
|
326
|
+
function saveFile(urlOrBlob, filename) {
|
|
327
|
+
if (typeof document === "undefined") return;
|
|
328
|
+
if (typeof urlOrBlob !== "string") {
|
|
329
|
+
const url = URL.createObjectURL(urlOrBlob);
|
|
330
|
+
clickDownloadLink(url, filename);
|
|
331
|
+
setTimeout(() => URL.revokeObjectURL(url), REVOKE_OBJECT_URL_DELAY_MS);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (!isSafeUrl(urlOrBlob)) {
|
|
335
|
+
console.warn(`seclai: not downloading ${filename}, its URL isn't http(s), blob or relative.`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
clickDownloadLink(urlOrBlob, filename);
|
|
339
|
+
}
|
|
340
|
+
async function saveFiles(files, { delayMs = SAVE_FILES_DELAY_MS, signal } = {}) {
|
|
315
341
|
for (const [i, file] of files.entries()) {
|
|
316
342
|
if (signal?.aborted) return;
|
|
317
|
-
if (i > 0) await
|
|
343
|
+
if (i > 0) await wait(delayMs, signal);
|
|
318
344
|
if (signal?.aborted) return;
|
|
319
|
-
|
|
345
|
+
saveFile(file.source, file.filename);
|
|
320
346
|
}
|
|
321
347
|
}
|
|
348
|
+
function wait(ms, signal) {
|
|
349
|
+
return new Promise((resolve) => {
|
|
350
|
+
const done = () => {
|
|
351
|
+
clearTimeout(timer);
|
|
352
|
+
signal?.removeEventListener("abort", done);
|
|
353
|
+
resolve();
|
|
354
|
+
};
|
|
355
|
+
const timer = setTimeout(done, ms);
|
|
356
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
357
|
+
});
|
|
358
|
+
}
|
|
322
359
|
|
|
323
360
|
// src/placeholders/MediaPreview.tsx
|
|
324
361
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -533,7 +570,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
533
570
|
|
|
534
571
|
// src/media/MediaGallery.tsx
|
|
535
572
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
536
|
-
var DOWNLOAD_ALL_DELAY_MS =
|
|
573
|
+
var DOWNLOAD_ALL_DELAY_MS = SAVE_FILES_DELAY_MS;
|
|
537
574
|
function MediaGallery({
|
|
538
575
|
attachments,
|
|
539
576
|
aspectRatio,
|
|
@@ -553,10 +590,9 @@ function MediaGallery({
|
|
|
553
590
|
abort.current = controller;
|
|
554
591
|
setDownloading(true);
|
|
555
592
|
try {
|
|
556
|
-
await
|
|
557
|
-
images.map((image, i) => ({
|
|
558
|
-
DOWNLOAD_ALL_DELAY_MS,
|
|
559
|
-
controller.signal
|
|
593
|
+
await saveFiles(
|
|
594
|
+
images.map((image, i) => ({ source: image.url, filename: attachmentFileName(image, i + 1) })),
|
|
595
|
+
{ delayMs: DOWNLOAD_ALL_DELAY_MS, signal: controller.signal }
|
|
560
596
|
);
|
|
561
597
|
} finally {
|
|
562
598
|
if (!controller.signal.aborted) setDownloading(false);
|
|
@@ -600,8 +636,80 @@ function MediaGallery({
|
|
|
600
636
|
] });
|
|
601
637
|
}
|
|
602
638
|
|
|
603
|
-
// src/
|
|
639
|
+
// src/RunProgress.tsx
|
|
604
640
|
var import_react6 = require("react");
|
|
641
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
642
|
+
function useElapsed(startedAt, running) {
|
|
643
|
+
const [now, setNow] = (0, import_react6.useState)(null);
|
|
644
|
+
(0, import_react6.useEffect)(() => {
|
|
645
|
+
if (!running || startedAt === null) return;
|
|
646
|
+
let timer;
|
|
647
|
+
const tick = () => {
|
|
648
|
+
const time = Date.now();
|
|
649
|
+
setNow(time);
|
|
650
|
+
const into = ((time - startedAt) % 1e3 + 1e3) % 1e3;
|
|
651
|
+
timer = setTimeout(tick, 1e3 - into);
|
|
652
|
+
};
|
|
653
|
+
tick();
|
|
654
|
+
return () => clearTimeout(timer);
|
|
655
|
+
}, [running, startedAt]);
|
|
656
|
+
if (startedAt === null || now === null) return 0;
|
|
657
|
+
return Math.max(0, Math.floor((now - startedAt) / 1e3));
|
|
658
|
+
}
|
|
659
|
+
function formatClock(seconds) {
|
|
660
|
+
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
661
|
+
}
|
|
662
|
+
function spokenDuration(seconds) {
|
|
663
|
+
const minutes = Math.floor(seconds / 60);
|
|
664
|
+
const rest = seconds % 60;
|
|
665
|
+
const unit = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
666
|
+
if (minutes === 0) return unit(rest, "second");
|
|
667
|
+
return rest === 0 ? unit(minutes, "minute") : `${unit(minutes, "minute")} ${unit(rest, "second")}`;
|
|
668
|
+
}
|
|
669
|
+
function RunProgress({ run, showSteps = true, message, className }) {
|
|
670
|
+
const running = run.status === "running";
|
|
671
|
+
const seconds = useElapsed(run.startedAt, running);
|
|
672
|
+
if (!running) return null;
|
|
673
|
+
const note = typeof message === "function" ? message(seconds) : message;
|
|
674
|
+
const last = run.steps.length - 1;
|
|
675
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
676
|
+
"div",
|
|
677
|
+
{
|
|
678
|
+
className: className ? `seclai-run-progress ${className}` : "seclai-run-progress",
|
|
679
|
+
"aria-live": "polite",
|
|
680
|
+
children: [
|
|
681
|
+
showSteps && (run.steps.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "seclai-notice", children: "Starting the run\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ol", { className: "seclai-steps", children: run.steps.map((step, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { children: [
|
|
682
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-step-marker", "aria-hidden": "true", children: i === last ? "\u25CF" : "\u2713" }),
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-sr-only", children: i === last ? "In progress: " : "Done: " }),
|
|
684
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
685
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-step-name", children: step.name }),
|
|
686
|
+
step.message && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "seclai-step-message", children: [
|
|
687
|
+
" \xB7 ",
|
|
688
|
+
step.message
|
|
689
|
+
] })
|
|
690
|
+
] })
|
|
691
|
+
] }, step.id)) })),
|
|
692
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "seclai-run-progress-note", children: [
|
|
693
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-run-progress-pulse", "aria-hidden": "true" }),
|
|
694
|
+
note != null && note !== false && note !== "" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "seclai-run-progress-message", children: note }),
|
|
695
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
696
|
+
"span",
|
|
697
|
+
{
|
|
698
|
+
className: "seclai-run-progress-clock",
|
|
699
|
+
role: "timer",
|
|
700
|
+
"aria-live": "off",
|
|
701
|
+
"aria-label": `${spokenDuration(seconds)} elapsed`,
|
|
702
|
+
children: formatClock(seconds)
|
|
703
|
+
}
|
|
704
|
+
)
|
|
705
|
+
] })
|
|
706
|
+
]
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/useAgentRun.ts
|
|
712
|
+
var import_react7 = require("react");
|
|
605
713
|
|
|
606
714
|
// src/sse.ts
|
|
607
715
|
function parseData(data) {
|
|
@@ -747,15 +855,15 @@ function applyEvent(state, { event, data }, endpoints) {
|
|
|
747
855
|
}
|
|
748
856
|
function useAgentRun(options = {}) {
|
|
749
857
|
const { basePath, agentId, onEvent } = options;
|
|
750
|
-
const endpoints = (0,
|
|
751
|
-
const [state, setState] = (0,
|
|
752
|
-
const active = (0,
|
|
753
|
-
const onEventRef = (0,
|
|
754
|
-
(0,
|
|
858
|
+
const endpoints = (0, import_react7.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
859
|
+
const [state, setState] = (0, import_react7.useState)(IDLE);
|
|
860
|
+
const active = (0, import_react7.useRef)(null);
|
|
861
|
+
const onEventRef = (0, import_react7.useRef)(onEvent);
|
|
862
|
+
(0, import_react7.useEffect)(() => {
|
|
755
863
|
onEventRef.current = onEvent;
|
|
756
864
|
});
|
|
757
|
-
(0,
|
|
758
|
-
const start = (0,
|
|
865
|
+
(0, import_react7.useEffect)(() => () => active.current?.abort(), []);
|
|
866
|
+
const start = (0, import_react7.useCallback)(
|
|
759
867
|
async ({ input, uploadIds, sessionId }) => {
|
|
760
868
|
active.current?.abort();
|
|
761
869
|
const controller = new AbortController();
|
|
@@ -815,8 +923,8 @@ function useAgentRun(options = {}) {
|
|
|
815
923
|
},
|
|
816
924
|
[endpoints]
|
|
817
925
|
);
|
|
818
|
-
const cancel = (0,
|
|
819
|
-
const reset = (0,
|
|
926
|
+
const cancel = (0, import_react7.useCallback)(() => active.current?.abort(), []);
|
|
927
|
+
const reset = (0, import_react7.useCallback)(() => {
|
|
820
928
|
const controller = active.current;
|
|
821
929
|
active.current = null;
|
|
822
930
|
controller?.abort();
|
|
@@ -826,7 +934,7 @@ function useAgentRun(options = {}) {
|
|
|
826
934
|
}
|
|
827
935
|
|
|
828
936
|
// src/AgentChat.tsx
|
|
829
|
-
var
|
|
937
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
830
938
|
function createSessionId() {
|
|
831
939
|
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
832
940
|
return Array.from(
|
|
@@ -850,13 +958,13 @@ function plural(count, word) {
|
|
|
850
958
|
}
|
|
851
959
|
function FileChip({ name, tag, preview, status, error, onRemove }) {
|
|
852
960
|
const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
|
|
853
|
-
return /* @__PURE__ */ (0,
|
|
854
|
-
preview && /* @__PURE__ */ (0,
|
|
855
|
-
/* @__PURE__ */ (0,
|
|
856
|
-
/* @__PURE__ */ (0,
|
|
857
|
-
meta && /* @__PURE__ */ (0,
|
|
961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "seclai-file", "data-status": status, children: [
|
|
962
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { className: "seclai-file-thumb", src: preview, alt: "" }),
|
|
963
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "seclai-file-text", children: [
|
|
964
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "seclai-file-name", title: name, children: name }),
|
|
965
|
+
meta && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "seclai-file-meta", children: meta })
|
|
858
966
|
] }),
|
|
859
|
-
onRemove && /* @__PURE__ */ (0,
|
|
967
|
+
onRemove && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
860
968
|
"button",
|
|
861
969
|
{
|
|
862
970
|
type: "button",
|
|
@@ -869,8 +977,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
|
|
|
869
977
|
] });
|
|
870
978
|
}
|
|
871
979
|
function UserTurn({ message, previews }) {
|
|
872
|
-
return /* @__PURE__ */ (0,
|
|
873
|
-
message.files.length > 0 && /* @__PURE__ */ (0,
|
|
980
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "seclai-turn seclai-turn-user", children: [
|
|
981
|
+
message.files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "seclai-files", "aria-label": "Attached files", children: message.files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
874
982
|
FileChip,
|
|
875
983
|
{
|
|
876
984
|
name: file.name,
|
|
@@ -879,14 +987,14 @@ function UserTurn({ message, previews }) {
|
|
|
879
987
|
},
|
|
880
988
|
file.uploadId
|
|
881
989
|
)) }),
|
|
882
|
-
message.input && /* @__PURE__ */ (0,
|
|
990
|
+
message.input && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MarkdownContent, { content: message.input })
|
|
883
991
|
] });
|
|
884
992
|
}
|
|
885
993
|
function AssistantTurn({ turn, endpoints }) {
|
|
886
994
|
const { runId } = turn;
|
|
887
|
-
return /* @__PURE__ */ (0,
|
|
888
|
-
turn.output && /* @__PURE__ */ (0,
|
|
889
|
-
runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ (0,
|
|
995
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "seclai-turn seclai-turn-assistant", children: [
|
|
996
|
+
turn.output && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MarkdownContent, { content: turn.output }),
|
|
997
|
+
runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
890
998
|
MediaGallery,
|
|
891
999
|
{
|
|
892
1000
|
attachments: turn.attachments.map(({ id, name, mime, bytes }) => ({
|
|
@@ -898,8 +1006,8 @@ function AssistantTurn({ turn, endpoints }) {
|
|
|
898
1006
|
}))
|
|
899
1007
|
}
|
|
900
1008
|
),
|
|
901
|
-
turn.error && /* @__PURE__ */ (0,
|
|
902
|
-
turn.status === "cancelled" && /* @__PURE__ */ (0,
|
|
1009
|
+
turn.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-error", role: "alert", children: turn.error }),
|
|
1010
|
+
turn.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-notice", children: "Stopped." })
|
|
903
1011
|
] });
|
|
904
1012
|
}
|
|
905
1013
|
function toTurnAttachment({ id, name, mime, bytes }) {
|
|
@@ -912,9 +1020,9 @@ function AttachControl({
|
|
|
912
1020
|
disabled,
|
|
913
1021
|
onFiles
|
|
914
1022
|
}) {
|
|
915
|
-
return /* @__PURE__ */ (0,
|
|
1023
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
|
|
916
1024
|
label,
|
|
917
|
-
/* @__PURE__ */ (0,
|
|
1025
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
918
1026
|
"input",
|
|
919
1027
|
{
|
|
920
1028
|
type: "file",
|
|
@@ -941,10 +1049,10 @@ function AgentChat({
|
|
|
941
1049
|
initialTurns,
|
|
942
1050
|
onTurnComplete
|
|
943
1051
|
}) {
|
|
944
|
-
const endpoints = (0,
|
|
1052
|
+
const endpoints = (0, import_react8.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
945
1053
|
const run = useAgentRun({ basePath, agentId });
|
|
946
1054
|
const { slots } = useAcceptedAttachments(endpoints);
|
|
947
|
-
const [transcript, setTranscript] = (0,
|
|
1055
|
+
const [transcript, setTranscript] = (0, import_react8.useState)(() => ({
|
|
948
1056
|
sessionId,
|
|
949
1057
|
epoch: 0,
|
|
950
1058
|
turns: initialTurns ?? [],
|
|
@@ -952,15 +1060,15 @@ function AgentChat({
|
|
|
952
1060
|
generatedSessionId: null,
|
|
953
1061
|
runEpoch: null
|
|
954
1062
|
}));
|
|
955
|
-
const [message, setMessage] = (0,
|
|
956
|
-
const [files, setFiles] = (0,
|
|
957
|
-
const [notice, setNotice] = (0,
|
|
958
|
-
const [dragging, setDragging] = (0,
|
|
959
|
-
const generatedSessionId = (0,
|
|
960
|
-
const shownEpoch = (0,
|
|
961
|
-
const turnComplete = (0,
|
|
962
|
-
const sentPreviews = (0,
|
|
963
|
-
const pendingPreviews = (0,
|
|
1063
|
+
const [message, setMessage] = (0, import_react8.useState)("");
|
|
1064
|
+
const [files, setFiles] = (0, import_react8.useState)([]);
|
|
1065
|
+
const [notice, setNotice] = (0, import_react8.useState)(null);
|
|
1066
|
+
const [dragging, setDragging] = (0, import_react8.useState)(false);
|
|
1067
|
+
const generatedSessionId = (0, import_react8.useRef)(null);
|
|
1068
|
+
const shownEpoch = (0, import_react8.useRef)(transcript.epoch);
|
|
1069
|
+
const turnComplete = (0, import_react8.useRef)(onTurnComplete);
|
|
1070
|
+
const sentPreviews = (0, import_react8.useRef)(/* @__PURE__ */ new Map());
|
|
1071
|
+
const pendingPreviews = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
|
|
964
1072
|
if (transcript.sessionId !== sessionId) {
|
|
965
1073
|
const adopting = transcript.sessionId === void 0 && sessionId !== void 0 && sessionId === transcript.generatedSessionId;
|
|
966
1074
|
setTranscript(
|
|
@@ -974,10 +1082,10 @@ function AgentChat({
|
|
|
974
1082
|
}
|
|
975
1083
|
);
|
|
976
1084
|
}
|
|
977
|
-
(0,
|
|
1085
|
+
(0, import_react8.useEffect)(() => {
|
|
978
1086
|
turnComplete.current = onTurnComplete;
|
|
979
1087
|
});
|
|
980
|
-
(0,
|
|
1088
|
+
(0, import_react8.useEffect)(() => {
|
|
981
1089
|
if (shownEpoch.current === transcript.epoch) return;
|
|
982
1090
|
shownEpoch.current = transcript.epoch;
|
|
983
1091
|
run.cancel();
|
|
@@ -990,7 +1098,7 @@ function AgentChat({
|
|
|
990
1098
|
setFiles([]);
|
|
991
1099
|
setNotice(null);
|
|
992
1100
|
}, [transcript.epoch, run.cancel]);
|
|
993
|
-
(0,
|
|
1101
|
+
(0, import_react8.useEffect)(
|
|
994
1102
|
() => () => {
|
|
995
1103
|
pendingPreviews.current.forEach(revoke);
|
|
996
1104
|
sentPreviews.current.forEach(revoke);
|
|
@@ -1146,29 +1254,29 @@ function AgentChat({
|
|
|
1146
1254
|
}
|
|
1147
1255
|
} : {};
|
|
1148
1256
|
const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
|
|
1149
|
-
return /* @__PURE__ */ (0,
|
|
1150
|
-
/* @__PURE__ */ (0,
|
|
1151
|
-
transcript.turns.map((turn, i) => /* @__PURE__ */ (0,
|
|
1152
|
-
/* @__PURE__ */ (0,
|
|
1257
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-agent seclai-chat", children: [
|
|
1258
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("ul", { className: "seclai-turns", "aria-live": "polite", "aria-busy": streaming, children: [
|
|
1259
|
+
transcript.turns.map((turn, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react8.Fragment, { children: [
|
|
1260
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1153
1261
|
UserTurn,
|
|
1154
1262
|
{
|
|
1155
1263
|
message: { input: turn.input, files: turn.files ?? [] },
|
|
1156
1264
|
previews: sentPreviews.current
|
|
1157
1265
|
}
|
|
1158
1266
|
),
|
|
1159
|
-
/* @__PURE__ */ (0,
|
|
1267
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AssistantTurn, { turn, endpoints })
|
|
1160
1268
|
] }, `${transcript.epoch}:${i}`)),
|
|
1161
|
-
transcript.pending && /* @__PURE__ */ (0,
|
|
1162
|
-
streaming && /* @__PURE__ */ (0,
|
|
1269
|
+
transcript.pending && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UserTurn, { message: transcript.pending, previews: sentPreviews.current }),
|
|
1270
|
+
streaming && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { className: "seclai-turn seclai-turn-assistant", children: run.text ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MarkdownContent, { content: run.text }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(RunProgress, { run }) })
|
|
1163
1271
|
] }),
|
|
1164
|
-
/* @__PURE__ */ (0,
|
|
1272
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1165
1273
|
"form",
|
|
1166
1274
|
{
|
|
1167
1275
|
className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
|
|
1168
1276
|
onSubmit,
|
|
1169
1277
|
...dropHandlers,
|
|
1170
1278
|
children: [
|
|
1171
|
-
files.length > 0 && /* @__PURE__ */ (0,
|
|
1279
|
+
files.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1172
1280
|
FileChip,
|
|
1173
1281
|
{
|
|
1174
1282
|
name: f.name,
|
|
@@ -1180,7 +1288,7 @@ function AgentChat({
|
|
|
1180
1288
|
},
|
|
1181
1289
|
f.localId
|
|
1182
1290
|
)) }),
|
|
1183
|
-
/* @__PURE__ */ (0,
|
|
1291
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1184
1292
|
"textarea",
|
|
1185
1293
|
{
|
|
1186
1294
|
rows: 2,
|
|
@@ -1192,9 +1300,9 @@ function AgentChat({
|
|
|
1192
1300
|
onPaste: acceptsFiles ? onPaste : void 0
|
|
1193
1301
|
}
|
|
1194
1302
|
),
|
|
1195
|
-
notice && /* @__PURE__ */ (0,
|
|
1196
|
-
/* @__PURE__ */ (0,
|
|
1197
|
-
acceptsFiles && buttons.map((button) => /* @__PURE__ */ (0,
|
|
1303
|
+
notice && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "seclai-error", role: "alert", children: notice }),
|
|
1304
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "seclai-actions", children: [
|
|
1305
|
+
acceptsFiles && buttons.map((button) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1198
1306
|
AttachControl,
|
|
1199
1307
|
{
|
|
1200
1308
|
label: button.label,
|
|
@@ -1205,8 +1313,8 @@ function AgentChat({
|
|
|
1205
1313
|
},
|
|
1206
1314
|
`${button.label}\0${button.tag ?? ""}`
|
|
1207
1315
|
)),
|
|
1208
|
-
/* @__PURE__ */ (0,
|
|
1209
|
-
running && /* @__PURE__ */ (0,
|
|
1316
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: !canSend, children: "Send" }),
|
|
1317
|
+
running && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
|
|
1210
1318
|
] })
|
|
1211
1319
|
]
|
|
1212
1320
|
}
|
|
@@ -1215,8 +1323,8 @@ function AgentChat({
|
|
|
1215
1323
|
}
|
|
1216
1324
|
|
|
1217
1325
|
// src/AgentRunForm.tsx
|
|
1218
|
-
var
|
|
1219
|
-
var
|
|
1326
|
+
var import_react9 = require("react");
|
|
1327
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1220
1328
|
function slotProblem(slot, count) {
|
|
1221
1329
|
const label = slot.label ?? slot.name;
|
|
1222
1330
|
const min = slot.min ?? 0;
|
|
@@ -1227,13 +1335,13 @@ function slotProblem(slot, count) {
|
|
|
1227
1335
|
return null;
|
|
1228
1336
|
}
|
|
1229
1337
|
function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
1230
|
-
const endpoints = (0,
|
|
1338
|
+
const endpoints = (0, import_react9.useMemo)(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
1231
1339
|
const run = useAgentRun({ basePath, agentId });
|
|
1232
1340
|
const { slots, error: loadError } = useAcceptedAttachments(endpoints);
|
|
1233
|
-
const [input, setInput] = (0,
|
|
1234
|
-
const [files, setFiles] = (0,
|
|
1235
|
-
const [uploading, setUploading] = (0,
|
|
1236
|
-
const [formError, setFormError] = (0,
|
|
1341
|
+
const [input, setInput] = (0, import_react9.useState)("");
|
|
1342
|
+
const [files, setFiles] = (0, import_react9.useState)({});
|
|
1343
|
+
const [uploading, setUploading] = (0, import_react9.useState)(false);
|
|
1344
|
+
const [formError, setFormError] = (0, import_react9.useState)(null);
|
|
1237
1345
|
const selected = Object.values(files).flat();
|
|
1238
1346
|
const busy = uploading || run.status === "running";
|
|
1239
1347
|
async function submit(event) {
|
|
@@ -1267,30 +1375,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1267
1375
|
onFinish?.(result);
|
|
1268
1376
|
}
|
|
1269
1377
|
if (loadError) {
|
|
1270
|
-
return /* @__PURE__ */ (0,
|
|
1378
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "seclai-agent", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "seclai-error", role: "alert", children: loadError }) });
|
|
1271
1379
|
}
|
|
1272
1380
|
if (!slots) {
|
|
1273
|
-
return /* @__PURE__ */ (0,
|
|
1274
|
-
/* @__PURE__ */ (0,
|
|
1275
|
-
/* @__PURE__ */ (0,
|
|
1276
|
-
/* @__PURE__ */ (0,
|
|
1277
|
-
/* @__PURE__ */ (0,
|
|
1381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "seclai-agent", children: [
|
|
1382
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "seclai-notice", children: "Loading\u2026" }),
|
|
1383
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "seclai-skeleton", "aria-hidden": "true", children: [
|
|
1384
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", {}),
|
|
1385
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", {})
|
|
1278
1386
|
] })
|
|
1279
1387
|
] });
|
|
1280
1388
|
}
|
|
1281
1389
|
const error = formError ?? run.error;
|
|
1282
|
-
return /* @__PURE__ */ (0,
|
|
1283
|
-
/* @__PURE__ */ (0,
|
|
1284
|
-
/* @__PURE__ */ (0,
|
|
1285
|
-
/* @__PURE__ */ (0,
|
|
1286
|
-
/* @__PURE__ */ (0,
|
|
1390
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "seclai-agent", children: [
|
|
1391
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("form", { className: "seclai-form", onSubmit: submit, children: [
|
|
1392
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: "seclai-field", children: [
|
|
1393
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: inputLabel }),
|
|
1394
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("textarea", { rows: 4, value: input, onChange: (e) => setInput(e.target.value) })
|
|
1287
1395
|
] }),
|
|
1288
|
-
slots.map((slot) => /* @__PURE__ */ (0,
|
|
1289
|
-
/* @__PURE__ */ (0,
|
|
1396
|
+
slots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: "seclai-field", children: [
|
|
1397
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { children: [
|
|
1290
1398
|
slot.label ?? slot.name,
|
|
1291
1399
|
(slot.min ?? 0) > 0 ? " (required)" : ""
|
|
1292
1400
|
] }),
|
|
1293
|
-
/* @__PURE__ */ (0,
|
|
1401
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1294
1402
|
"input",
|
|
1295
1403
|
{
|
|
1296
1404
|
type: "file",
|
|
@@ -1301,29 +1409,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1301
1409
|
}
|
|
1302
1410
|
)
|
|
1303
1411
|
] }, slot.name)),
|
|
1304
|
-
/* @__PURE__ */ (0,
|
|
1305
|
-
/* @__PURE__ */ (0,
|
|
1306
|
-
run.status === "running" && /* @__PURE__ */ (0,
|
|
1412
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "seclai-actions", children: [
|
|
1413
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "submit", className: "seclai-button seclai-button-primary", disabled: busy, children: uploading ? "Uploading\u2026" : "Run" }),
|
|
1414
|
+
run.status === "running" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "seclai-button", onClick: run.cancel, children: "Stop" })
|
|
1307
1415
|
] })
|
|
1308
1416
|
] }),
|
|
1309
|
-
run.steps.length > 0 && /* @__PURE__ */ (0,
|
|
1417
|
+
run.steps.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { children: [
|
|
1310
1418
|
step.name,
|
|
1311
1419
|
": ",
|
|
1312
1420
|
step.message
|
|
1313
1421
|
] }, step.id)) }),
|
|
1314
|
-
error && /* @__PURE__ */ (0,
|
|
1315
|
-
run.status === "cancelled" && /* @__PURE__ */ (0,
|
|
1316
|
-
(run.text || run.attachments.length > 0) && /* @__PURE__ */ (0,
|
|
1317
|
-
run.text && /* @__PURE__ */ (0,
|
|
1318
|
-
run.attachments.length > 0 && /* @__PURE__ */ (0,
|
|
1422
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "seclai-error", role: "alert", children: error }),
|
|
1423
|
+
run.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "seclai-notice", children: "Stopped." }),
|
|
1424
|
+
(run.text || run.attachments.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "seclai-output", "aria-live": "polite", "aria-busy": run.status === "running", children: [
|
|
1425
|
+
run.text && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MarkdownContent, { content: run.text }),
|
|
1426
|
+
run.attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MediaGallery, { attachments: run.attachments })
|
|
1319
1427
|
] })
|
|
1320
1428
|
] });
|
|
1321
1429
|
}
|
|
1322
1430
|
|
|
1323
1431
|
// src/SeclaiAgent.tsx
|
|
1324
|
-
var
|
|
1432
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1325
1433
|
function SeclaiAgent({ mode, basePath, agentId }) {
|
|
1326
|
-
return mode === "chat" ? /* @__PURE__ */ (0,
|
|
1434
|
+
return mode === "chat" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AgentChat, { basePath, agentId }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AgentRunForm, { basePath, agentId });
|
|
1327
1435
|
}
|
|
1328
1436
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1329
1437
|
0 && (module.exports = {
|
|
@@ -1335,10 +1443,14 @@ function SeclaiAgent({ mode, basePath, agentId }) {
|
|
|
1335
1443
|
MediaPreview,
|
|
1336
1444
|
MediaSkeleton,
|
|
1337
1445
|
MediaViewer,
|
|
1446
|
+
RunProgress,
|
|
1338
1447
|
SeclaiAgent,
|
|
1339
1448
|
attachmentFileName,
|
|
1340
1449
|
createEndpoints,
|
|
1341
1450
|
fetchAttachmentReferences,
|
|
1451
|
+
saveFile,
|
|
1452
|
+
saveFiles,
|
|
1342
1453
|
uploadFile,
|
|
1343
|
-
useAgentRun
|
|
1454
|
+
useAgentRun,
|
|
1455
|
+
useElapsed
|
|
1344
1456
|
});
|