@seclai/react 0.0.15 → 0.0.17
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 +31 -15
- package/dist/index.d.ts +29 -1
- package/dist/index.js +152 -78
- package/dist/styles.css +61 -3
- package/package.json +4 -11
- package/dist/index.cjs +0 -1380
- package/dist/index.d.cts +0 -446
package/README.md
CHANGED
|
@@ -10,6 +10,14 @@ npm install @seclai/react
|
|
|
10
10
|
|
|
11
11
|
`react` and `react-dom` 18 or later are peer dependencies. Mount the handlers on your server first: see the [`@seclai/handlers` README](https://www.npmjs.com/package/@seclai/handlers#usage).
|
|
12
12
|
|
|
13
|
+
### Module format
|
|
14
|
+
|
|
15
|
+
`@seclai/react` ships as ES modules only. Bundlers and `import` work as usual. CommonJS code, such as a server-rendering setup, can `require` it on Node 22.12 or later; Node 22.12 and Node 23.0 to 23.4 print an `ExperimentalWarning` the first time, and Node 22.13+ and 23.5+ don't.
|
|
16
|
+
|
|
17
|
+
In a TypeScript CommonJS project, set `module` to `nodenext` (TypeScript 5.8+) or `node20` (TypeScript 5.9+), so the compiler allows that `require`. With `node16` or `node18` it reports error TS1479 on the import. `commonjs` with `moduleResolution` `node10` and the `bundler` setting work as they are.
|
|
18
|
+
|
|
19
|
+
Jest's default CommonJS mode doesn't transform packages in `node_modules`, so tell it to transform this one, for example with `transformIgnorePatterns: ["/node_modules/(?!(\\.pnpm/)?@seclai[/+])"]` (the `.pnpm` part covers pnpm's layout), using a transform that converts ES modules to CommonJS, such as `babel-jest` with `@babel/preset-env`. Vitest needs no setup.
|
|
20
|
+
|
|
13
21
|
## Usage
|
|
14
22
|
|
|
15
23
|
```tsx
|
|
@@ -32,6 +40,7 @@ export function App() {
|
|
|
32
40
|
- **`AgentRunForm`** builds a text input and file inputs from the agent's accepted attachments, uploads the files, then runs with text and files together.
|
|
33
41
|
- **`AgentChat`** sends each message as a run with a shared session id and streams the reply.
|
|
34
42
|
- **`SeclaiAgent`** renders one of the two based on `mode`.
|
|
43
|
+
- **`RunProgress`** shows a running run's steps and elapsed time. See [below](#runprogress).
|
|
35
44
|
|
|
36
45
|
### Files in `AgentChat`
|
|
37
46
|
|
|
@@ -133,28 +142,35 @@ await start({ input: "Hello", uploadIds: ["..."], sessionId: "..." });
|
|
|
133
142
|
|
|
134
143
|
Options also take `basePath` and `agentId`, as the components do.
|
|
135
144
|
|
|
136
|
-
|
|
145
|
+
### `RunProgress`
|
|
146
|
+
|
|
147
|
+
Runs that generate images can take a minute or two. `RunProgress` shows a running run's steps and the time elapsed, and renders nothing otherwise:
|
|
137
148
|
|
|
138
149
|
```tsx
|
|
139
|
-
|
|
140
|
-
const [now, setNow] = useState(Date.now());
|
|
141
|
-
useEffect(() => {
|
|
142
|
-
const timer = setInterval(() => setNow(Date.now()), 1000);
|
|
143
|
-
return () => clearInterval(timer);
|
|
144
|
-
}, []);
|
|
145
|
-
const seconds = Math.max(0, Math.floor((now - startedAt) / 1000));
|
|
146
|
-
return <>{Math.floor(seconds / 60)}:{String(seconds % 60).padStart(2, "0")}</>;
|
|
147
|
-
}
|
|
150
|
+
import { RunProgress, useAgentRun } from "@seclai/react";
|
|
148
151
|
|
|
149
152
|
const run = useAgentRun();
|
|
150
153
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
)}
|
|
154
|
+
<RunProgress
|
|
155
|
+
run={run}
|
|
156
|
+
message={(seconds) => (seconds < 150 ? "Generating images usually takes a minute or two." : "Still working…")}
|
|
157
|
+
/>
|
|
156
158
|
```
|
|
157
159
|
|
|
160
|
+
- It shows "Starting the run…" until the first step, then each step's name and message, with ✓ for finished steps and ● for the current one.
|
|
161
|
+
- The clock reads `m:ss`, and screen readers get "42 seconds elapsed". Steps and the message are announced as they change, but the clock isn't, so keep the seconds out of `message`.
|
|
162
|
+
- `run` needs only `status`, `steps` and `startedAt`, so a plain object works too.
|
|
163
|
+
- `AgentChat` shows it until the reply starts streaming.
|
|
164
|
+
|
|
165
|
+
| Prop | |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `run` | Required. `{ status, steps, startedAt }`, such as a `useAgentRun` result |
|
|
168
|
+
| `showSteps` | Show the step list. Defaults to `true` |
|
|
169
|
+
| `message` | A note next to the clock: a node, or `(seconds) => ReactNode` |
|
|
170
|
+
| `className` | Added to the outer element |
|
|
171
|
+
|
|
172
|
+
For just the clock, `useElapsed(startedAt, running)` returns whole seconds since `startedAt`, ticking while `running`. It's 0 on the first render, so server and client markup match.
|
|
173
|
+
|
|
158
174
|
### Building your own UI
|
|
159
175
|
|
|
160
176
|
To upload files and run the agent from your own UI, use the helpers the components are built on:
|
package/dist/index.d.ts
CHANGED
|
@@ -236,6 +236,34 @@ interface SeclaiAgentProps extends AgentEndpointOptions {
|
|
|
236
236
|
/** Boots the agent UI from its mode, and its agent id when the server hosts several. */
|
|
237
237
|
declare function SeclaiAgent({ mode, basePath, agentId }: SeclaiAgentProps): react.JSX.Element;
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Whole seconds since `startedAt` (a `Date.now()` value, such as `useAgentRun`'s
|
|
241
|
+
* `startedAt`), updated every second while `running`. It's 0 when `startedAt` is
|
|
242
|
+
* `null`, and on the first render, so server and client render the same markup;
|
|
243
|
+
* the real value follows in an effect. When `running` turns false it keeps its
|
|
244
|
+
* last value and stops the timer.
|
|
245
|
+
*/
|
|
246
|
+
declare function useElapsed(startedAt: number | null, running: boolean): number;
|
|
247
|
+
/** The fields `RunProgress` reads. A `useAgentRun` result fits, as does a plain object. */
|
|
248
|
+
type RunProgressRun = Pick<AgentRunState, "status" | "steps" | "startedAt">;
|
|
249
|
+
interface RunProgressProps {
|
|
250
|
+
run: RunProgressRun;
|
|
251
|
+
/** Show the step list. Defaults to true. */
|
|
252
|
+
showSteps?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* A note shown next to the clock, or a function of the seconds elapsed, for a
|
|
255
|
+
* note that changes as the run goes on. It's read out when it changes, so
|
|
256
|
+
* don't put the seconds in it.
|
|
257
|
+
*/
|
|
258
|
+
message?: ReactNode | ((seconds: number) => ReactNode);
|
|
259
|
+
className?: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* A running run's steps and elapsed time. Renders nothing unless
|
|
263
|
+
* `run.status` is `"running"`.
|
|
264
|
+
*/
|
|
265
|
+
declare function RunProgress({ run, showSteps, message, className }: RunProgressProps): react.JSX.Element | null;
|
|
266
|
+
|
|
239
267
|
declare const DEFAULT_BASE_PATH = "/api/seclai";
|
|
240
268
|
/**
|
|
241
269
|
* The URLs of the `@seclai/handlers` routes. Build it with
|
|
@@ -443,4 +471,4 @@ interface MarkdownContentProps {
|
|
|
443
471
|
*/
|
|
444
472
|
declare function MarkdownContent({ content }: MarkdownContentProps): react.JSX.Element;
|
|
445
473
|
|
|
446
|
-
export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatAttachButton, type AgentChatAttachment, type AgentChatFile, type AgentChatMessage, type AgentChatProps, type AgentChatTurn, type AgentEndpointOptions, type AgentEndpoints, type AgentRunEvent, AgentRunForm, type AgentRunFormProps, type AgentRunState, type AgentRunStatus, type AgentRunStep, type AgentUiMode, type AttachmentReferences, DEFAULT_BASE_PATH, type EndpointRequestOptions, MarkdownContent, type MarkdownContentProps, type MediaAspectRatio, MediaGallery, type MediaGalleryProps, MediaPreview, type MediaPreviewProps, MediaSkeleton, type MediaSkeletonProps, MediaViewer, type MediaViewerProps, type SaveFilesEntry, type SaveFilesOptions, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadFileOptions, type UploadResult, type UseAgentRunOptions, type UseAgentRunResult, attachmentFileName, createEndpoints, fetchAttachmentReferences, saveFile, saveFiles, uploadFile, useAgentRun };
|
|
474
|
+
export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatAttachButton, type AgentChatAttachment, type AgentChatFile, type AgentChatMessage, type AgentChatProps, type AgentChatTurn, type AgentEndpointOptions, type AgentEndpoints, type AgentRunEvent, AgentRunForm, type AgentRunFormProps, type AgentRunState, type AgentRunStatus, type AgentRunStep, type AgentUiMode, type AttachmentReferences, DEFAULT_BASE_PATH, type EndpointRequestOptions, MarkdownContent, type MarkdownContentProps, type MediaAspectRatio, MediaGallery, type MediaGalleryProps, MediaPreview, type MediaPreviewProps, MediaSkeleton, type MediaSkeletonProps, MediaViewer, type MediaViewerProps, RunProgress, type RunProgressProps, type RunProgressRun, type SaveFilesEntry, type SaveFilesOptions, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadFileOptions, type UploadResult, type UseAgentRunOptions, type UseAgentRunResult, attachmentFileName, createEndpoints, fetchAttachmentReferences, saveFile, saveFiles, uploadFile, useAgentRun, useElapsed };
|
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
|
|
6
|
+
useEffect as useEffect7,
|
|
7
7
|
useMemo as useMemo2,
|
|
8
8
|
useRef as useRef5,
|
|
9
|
-
useState as
|
|
9
|
+
useState as useState6
|
|
10
10
|
} from "react";
|
|
11
11
|
|
|
12
12
|
// src/attachments.ts
|
|
@@ -600,8 +600,80 @@ function MediaGallery({
|
|
|
600
600
|
] });
|
|
601
601
|
}
|
|
602
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
|
+
|
|
603
675
|
// src/useAgentRun.ts
|
|
604
|
-
import { useCallback, useEffect as
|
|
676
|
+
import { useCallback, useEffect as useEffect6, useMemo, useRef as useRef4, useState as useState5 } from "react";
|
|
605
677
|
|
|
606
678
|
// src/sse.ts
|
|
607
679
|
function parseData(data) {
|
|
@@ -748,13 +820,13 @@ function applyEvent(state, { event, data }, endpoints) {
|
|
|
748
820
|
function useAgentRun(options = {}) {
|
|
749
821
|
const { basePath, agentId, onEvent } = options;
|
|
750
822
|
const endpoints = useMemo(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
751
|
-
const [state, setState] =
|
|
823
|
+
const [state, setState] = useState5(IDLE);
|
|
752
824
|
const active = useRef4(null);
|
|
753
825
|
const onEventRef = useRef4(onEvent);
|
|
754
|
-
|
|
826
|
+
useEffect6(() => {
|
|
755
827
|
onEventRef.current = onEvent;
|
|
756
828
|
});
|
|
757
|
-
|
|
829
|
+
useEffect6(() => () => active.current?.abort(), []);
|
|
758
830
|
const start = useCallback(
|
|
759
831
|
async ({ input, uploadIds, sessionId }) => {
|
|
760
832
|
active.current?.abort();
|
|
@@ -826,7 +898,7 @@ function useAgentRun(options = {}) {
|
|
|
826
898
|
}
|
|
827
899
|
|
|
828
900
|
// src/AgentChat.tsx
|
|
829
|
-
import { jsx as
|
|
901
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
830
902
|
function createSessionId() {
|
|
831
903
|
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
832
904
|
return Array.from(
|
|
@@ -850,13 +922,13 @@ function plural(count, word) {
|
|
|
850
922
|
}
|
|
851
923
|
function FileChip({ name, tag, preview, status, error, onRemove }) {
|
|
852
924
|
const meta = status === "uploading" ? "Uploading\u2026" : status === "error" ? error : tag;
|
|
853
|
-
return /* @__PURE__ */
|
|
854
|
-
preview && /* @__PURE__ */
|
|
855
|
-
/* @__PURE__ */
|
|
856
|
-
/* @__PURE__ */
|
|
857
|
-
meta && /* @__PURE__ */
|
|
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 })
|
|
858
930
|
] }),
|
|
859
|
-
onRemove && /* @__PURE__ */
|
|
931
|
+
onRemove && /* @__PURE__ */ jsx7(
|
|
860
932
|
"button",
|
|
861
933
|
{
|
|
862
934
|
type: "button",
|
|
@@ -869,8 +941,8 @@ function FileChip({ name, tag, preview, status, error, onRemove }) {
|
|
|
869
941
|
] });
|
|
870
942
|
}
|
|
871
943
|
function UserTurn({ message, previews }) {
|
|
872
|
-
return /* @__PURE__ */
|
|
873
|
-
message.files.length > 0 && /* @__PURE__ */
|
|
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(
|
|
874
946
|
FileChip,
|
|
875
947
|
{
|
|
876
948
|
name: file.name,
|
|
@@ -879,14 +951,14 @@ function UserTurn({ message, previews }) {
|
|
|
879
951
|
},
|
|
880
952
|
file.uploadId
|
|
881
953
|
)) }),
|
|
882
|
-
message.input && /* @__PURE__ */
|
|
954
|
+
message.input && /* @__PURE__ */ jsx7(MarkdownContent, { content: message.input })
|
|
883
955
|
] });
|
|
884
956
|
}
|
|
885
957
|
function AssistantTurn({ turn, endpoints }) {
|
|
886
958
|
const { runId } = turn;
|
|
887
|
-
return /* @__PURE__ */
|
|
888
|
-
turn.output && /* @__PURE__ */
|
|
889
|
-
runId && turn.attachments && turn.attachments.length > 0 && /* @__PURE__ */
|
|
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(
|
|
890
962
|
MediaGallery,
|
|
891
963
|
{
|
|
892
964
|
attachments: turn.attachments.map(({ id, name, mime, bytes }) => ({
|
|
@@ -898,8 +970,8 @@ function AssistantTurn({ turn, endpoints }) {
|
|
|
898
970
|
}))
|
|
899
971
|
}
|
|
900
972
|
),
|
|
901
|
-
turn.error && /* @__PURE__ */
|
|
902
|
-
turn.status === "cancelled" && /* @__PURE__ */
|
|
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." })
|
|
903
975
|
] });
|
|
904
976
|
}
|
|
905
977
|
function toTurnAttachment({ id, name, mime, bytes }) {
|
|
@@ -912,9 +984,9 @@ function AttachControl({
|
|
|
912
984
|
disabled,
|
|
913
985
|
onFiles
|
|
914
986
|
}) {
|
|
915
|
-
return /* @__PURE__ */
|
|
987
|
+
return /* @__PURE__ */ jsxs7("label", { className: "seclai-button seclai-attach", "aria-disabled": disabled || void 0, children: [
|
|
916
988
|
label,
|
|
917
|
-
/* @__PURE__ */
|
|
989
|
+
/* @__PURE__ */ jsx7(
|
|
918
990
|
"input",
|
|
919
991
|
{
|
|
920
992
|
type: "file",
|
|
@@ -944,7 +1016,7 @@ function AgentChat({
|
|
|
944
1016
|
const endpoints = useMemo2(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
945
1017
|
const run = useAgentRun({ basePath, agentId });
|
|
946
1018
|
const { slots } = useAcceptedAttachments(endpoints);
|
|
947
|
-
const [transcript, setTranscript] =
|
|
1019
|
+
const [transcript, setTranscript] = useState6(() => ({
|
|
948
1020
|
sessionId,
|
|
949
1021
|
epoch: 0,
|
|
950
1022
|
turns: initialTurns ?? [],
|
|
@@ -952,10 +1024,10 @@ function AgentChat({
|
|
|
952
1024
|
generatedSessionId: null,
|
|
953
1025
|
runEpoch: null
|
|
954
1026
|
}));
|
|
955
|
-
const [message, setMessage] =
|
|
956
|
-
const [files, setFiles] =
|
|
957
|
-
const [notice, setNotice] =
|
|
958
|
-
const [dragging, setDragging] =
|
|
1027
|
+
const [message, setMessage] = useState6("");
|
|
1028
|
+
const [files, setFiles] = useState6([]);
|
|
1029
|
+
const [notice, setNotice] = useState6(null);
|
|
1030
|
+
const [dragging, setDragging] = useState6(false);
|
|
959
1031
|
const generatedSessionId = useRef5(null);
|
|
960
1032
|
const shownEpoch = useRef5(transcript.epoch);
|
|
961
1033
|
const turnComplete = useRef5(onTurnComplete);
|
|
@@ -974,10 +1046,10 @@ function AgentChat({
|
|
|
974
1046
|
}
|
|
975
1047
|
);
|
|
976
1048
|
}
|
|
977
|
-
|
|
1049
|
+
useEffect7(() => {
|
|
978
1050
|
turnComplete.current = onTurnComplete;
|
|
979
1051
|
});
|
|
980
|
-
|
|
1052
|
+
useEffect7(() => {
|
|
981
1053
|
if (shownEpoch.current === transcript.epoch) return;
|
|
982
1054
|
shownEpoch.current = transcript.epoch;
|
|
983
1055
|
run.cancel();
|
|
@@ -990,7 +1062,7 @@ function AgentChat({
|
|
|
990
1062
|
setFiles([]);
|
|
991
1063
|
setNotice(null);
|
|
992
1064
|
}, [transcript.epoch, run.cancel]);
|
|
993
|
-
|
|
1065
|
+
useEffect7(
|
|
994
1066
|
() => () => {
|
|
995
1067
|
pendingPreviews.current.forEach(revoke);
|
|
996
1068
|
sentPreviews.current.forEach(revoke);
|
|
@@ -1146,29 +1218,29 @@ function AgentChat({
|
|
|
1146
1218
|
}
|
|
1147
1219
|
} : {};
|
|
1148
1220
|
const buttons = attachButtons?.length ? attachButtons : [{ label: "Attach" }];
|
|
1149
|
-
return /* @__PURE__ */
|
|
1150
|
-
/* @__PURE__ */
|
|
1151
|
-
transcript.turns.map((turn, i) => /* @__PURE__ */
|
|
1152
|
-
/* @__PURE__ */
|
|
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(
|
|
1153
1225
|
UserTurn,
|
|
1154
1226
|
{
|
|
1155
1227
|
message: { input: turn.input, files: turn.files ?? [] },
|
|
1156
1228
|
previews: sentPreviews.current
|
|
1157
1229
|
}
|
|
1158
1230
|
),
|
|
1159
|
-
/* @__PURE__ */
|
|
1231
|
+
/* @__PURE__ */ jsx7(AssistantTurn, { turn, endpoints })
|
|
1160
1232
|
] }, `${transcript.epoch}:${i}`)),
|
|
1161
|
-
transcript.pending && /* @__PURE__ */
|
|
1162
|
-
streaming && /* @__PURE__ */
|
|
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 }) })
|
|
1163
1235
|
] }),
|
|
1164
|
-
/* @__PURE__ */
|
|
1236
|
+
/* @__PURE__ */ jsxs7(
|
|
1165
1237
|
"form",
|
|
1166
1238
|
{
|
|
1167
1239
|
className: dragging ? "seclai-form seclai-dropping" : "seclai-form",
|
|
1168
1240
|
onSubmit,
|
|
1169
1241
|
...dropHandlers,
|
|
1170
1242
|
children: [
|
|
1171
|
-
files.length > 0 && /* @__PURE__ */
|
|
1243
|
+
files.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "seclai-files", "aria-label": "Files to send", children: files.map((f) => /* @__PURE__ */ jsx7(
|
|
1172
1244
|
FileChip,
|
|
1173
1245
|
{
|
|
1174
1246
|
name: f.name,
|
|
@@ -1180,7 +1252,7 @@ function AgentChat({
|
|
|
1180
1252
|
},
|
|
1181
1253
|
f.localId
|
|
1182
1254
|
)) }),
|
|
1183
|
-
/* @__PURE__ */
|
|
1255
|
+
/* @__PURE__ */ jsx7(
|
|
1184
1256
|
"textarea",
|
|
1185
1257
|
{
|
|
1186
1258
|
rows: 2,
|
|
@@ -1192,9 +1264,9 @@ function AgentChat({
|
|
|
1192
1264
|
onPaste: acceptsFiles ? onPaste : void 0
|
|
1193
1265
|
}
|
|
1194
1266
|
),
|
|
1195
|
-
notice && /* @__PURE__ */
|
|
1196
|
-
/* @__PURE__ */
|
|
1197
|
-
acceptsFiles && buttons.map((button) => /* @__PURE__ */
|
|
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(
|
|
1198
1270
|
AttachControl,
|
|
1199
1271
|
{
|
|
1200
1272
|
label: button.label,
|
|
@@ -1205,8 +1277,8 @@ function AgentChat({
|
|
|
1205
1277
|
},
|
|
1206
1278
|
`${button.label}\0${button.tag ?? ""}`
|
|
1207
1279
|
)),
|
|
1208
|
-
/* @__PURE__ */
|
|
1209
|
-
running && /* @__PURE__ */
|
|
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" })
|
|
1210
1282
|
] })
|
|
1211
1283
|
]
|
|
1212
1284
|
}
|
|
@@ -1215,8 +1287,8 @@ function AgentChat({
|
|
|
1215
1287
|
}
|
|
1216
1288
|
|
|
1217
1289
|
// src/AgentRunForm.tsx
|
|
1218
|
-
import { useMemo as useMemo3, useState as
|
|
1219
|
-
import { jsx as
|
|
1290
|
+
import { useMemo as useMemo3, useState as useState7 } from "react";
|
|
1291
|
+
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1220
1292
|
function slotProblem(slot, count) {
|
|
1221
1293
|
const label = slot.label ?? slot.name;
|
|
1222
1294
|
const min = slot.min ?? 0;
|
|
@@ -1230,10 +1302,10 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1230
1302
|
const endpoints = useMemo3(() => createEndpoints({ basePath, agentId }), [basePath, agentId]);
|
|
1231
1303
|
const run = useAgentRun({ basePath, agentId });
|
|
1232
1304
|
const { slots, error: loadError } = useAcceptedAttachments(endpoints);
|
|
1233
|
-
const [input, setInput] =
|
|
1234
|
-
const [files, setFiles] =
|
|
1235
|
-
const [uploading, setUploading] =
|
|
1236
|
-
const [formError, setFormError] =
|
|
1305
|
+
const [input, setInput] = useState7("");
|
|
1306
|
+
const [files, setFiles] = useState7({});
|
|
1307
|
+
const [uploading, setUploading] = useState7(false);
|
|
1308
|
+
const [formError, setFormError] = useState7(null);
|
|
1237
1309
|
const selected = Object.values(files).flat();
|
|
1238
1310
|
const busy = uploading || run.status === "running";
|
|
1239
1311
|
async function submit(event) {
|
|
@@ -1267,30 +1339,30 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1267
1339
|
onFinish?.(result);
|
|
1268
1340
|
}
|
|
1269
1341
|
if (loadError) {
|
|
1270
|
-
return /* @__PURE__ */
|
|
1342
|
+
return /* @__PURE__ */ jsx8("div", { className: "seclai-agent", children: /* @__PURE__ */ jsx8("p", { className: "seclai-error", role: "alert", children: loadError }) });
|
|
1271
1343
|
}
|
|
1272
1344
|
if (!slots) {
|
|
1273
|
-
return /* @__PURE__ */
|
|
1274
|
-
/* @__PURE__ */
|
|
1275
|
-
/* @__PURE__ */
|
|
1276
|
-
/* @__PURE__ */
|
|
1277
|
-
/* @__PURE__ */
|
|
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", {})
|
|
1278
1350
|
] })
|
|
1279
1351
|
] });
|
|
1280
1352
|
}
|
|
1281
1353
|
const error = formError ?? run.error;
|
|
1282
|
-
return /* @__PURE__ */
|
|
1283
|
-
/* @__PURE__ */
|
|
1284
|
-
/* @__PURE__ */
|
|
1285
|
-
/* @__PURE__ */
|
|
1286
|
-
/* @__PURE__ */
|
|
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) })
|
|
1287
1359
|
] }),
|
|
1288
|
-
slots.map((slot) => /* @__PURE__ */
|
|
1289
|
-
/* @__PURE__ */
|
|
1360
|
+
slots.map((slot) => /* @__PURE__ */ jsxs8("label", { className: "seclai-field", children: [
|
|
1361
|
+
/* @__PURE__ */ jsxs8("span", { children: [
|
|
1290
1362
|
slot.label ?? slot.name,
|
|
1291
1363
|
(slot.min ?? 0) > 0 ? " (required)" : ""
|
|
1292
1364
|
] }),
|
|
1293
|
-
/* @__PURE__ */
|
|
1365
|
+
/* @__PURE__ */ jsx8(
|
|
1294
1366
|
"input",
|
|
1295
1367
|
{
|
|
1296
1368
|
type: "file",
|
|
@@ -1301,29 +1373,29 @@ function AgentRunForm({ basePath, agentId, inputLabel = "Input", onFinish }) {
|
|
|
1301
1373
|
}
|
|
1302
1374
|
)
|
|
1303
1375
|
] }, slot.name)),
|
|
1304
|
-
/* @__PURE__ */
|
|
1305
|
-
/* @__PURE__ */
|
|
1306
|
-
run.status === "running" && /* @__PURE__ */
|
|
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" })
|
|
1307
1379
|
] })
|
|
1308
1380
|
] }),
|
|
1309
|
-
run.steps.length > 0 && /* @__PURE__ */
|
|
1381
|
+
run.steps.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "seclai-steps", children: run.steps.map((step) => /* @__PURE__ */ jsxs8("li", { children: [
|
|
1310
1382
|
step.name,
|
|
1311
1383
|
": ",
|
|
1312
1384
|
step.message
|
|
1313
1385
|
] }, step.id)) }),
|
|
1314
|
-
error && /* @__PURE__ */
|
|
1315
|
-
run.status === "cancelled" && /* @__PURE__ */
|
|
1316
|
-
(run.text || run.attachments.length > 0) && /* @__PURE__ */
|
|
1317
|
-
run.text && /* @__PURE__ */
|
|
1318
|
-
run.attachments.length > 0 && /* @__PURE__ */
|
|
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 })
|
|
1319
1391
|
] })
|
|
1320
1392
|
] });
|
|
1321
1393
|
}
|
|
1322
1394
|
|
|
1323
1395
|
// src/SeclaiAgent.tsx
|
|
1324
|
-
import { jsx as
|
|
1396
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1325
1397
|
function SeclaiAgent({ mode, basePath, agentId }) {
|
|
1326
|
-
return mode === "chat" ? /* @__PURE__ */
|
|
1398
|
+
return mode === "chat" ? /* @__PURE__ */ jsx9(AgentChat, { basePath, agentId }) : /* @__PURE__ */ jsx9(AgentRunForm, { basePath, agentId });
|
|
1327
1399
|
}
|
|
1328
1400
|
export {
|
|
1329
1401
|
AgentChat,
|
|
@@ -1334,6 +1406,7 @@ export {
|
|
|
1334
1406
|
MediaPreview,
|
|
1335
1407
|
MediaSkeleton,
|
|
1336
1408
|
MediaViewer,
|
|
1409
|
+
RunProgress,
|
|
1337
1410
|
SeclaiAgent,
|
|
1338
1411
|
attachmentFileName,
|
|
1339
1412
|
createEndpoints,
|
|
@@ -1341,5 +1414,6 @@ export {
|
|
|
1341
1414
|
saveFile,
|
|
1342
1415
|
saveFiles,
|
|
1343
1416
|
uploadFile,
|
|
1344
|
-
useAgentRun
|
|
1417
|
+
useAgentRun,
|
|
1418
|
+
useElapsed
|
|
1345
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
|
-
/*
|
|
256
|
-
|
|
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
|
}
|