@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/dist/index.d.cts DELETED
@@ -1,446 +0,0 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
-
4
- /**
5
- * The handlers' wire format, declared here rather than imported from
6
- * `@seclai/handlers` or `@seclai/sdk` so the browser bundle stays free of both.
7
- * Only the fields this package reads are listed.
8
- */
9
- /** A file slot declared by the agent's trigger. */
10
- interface AcceptedAttachmentSlot {
11
- name: string;
12
- label?: string | null;
13
- min?: number;
14
- max?: number | null;
15
- content_types?: string[];
16
- name_pattern?: string | null;
17
- }
18
- /** The response from the `attachment-references` endpoint. */
19
- interface AttachmentReferences {
20
- requires_uploads: boolean;
21
- accepted_attachments?: AcceptedAttachmentSlot[];
22
- }
23
- /** The response from the `upload` endpoint. */
24
- interface UploadResult {
25
- id: string;
26
- status: string;
27
- filename: string;
28
- content_type: string;
29
- file_size: number;
30
- }
31
- /** A file produced by a run, with a `url` that goes through the download proxy. */
32
- interface AgentAttachment {
33
- id: string;
34
- name: string | null;
35
- mime: string;
36
- bytes: number | null;
37
- url: string;
38
- }
39
- /** The latest progress for one step of a run. */
40
- interface AgentRunStep {
41
- id: string;
42
- name: string;
43
- message: string;
44
- }
45
- type AgentRunStatus = "idle" | "running" | "completed" | "failed" | "cancelled";
46
- /** What the agent UI boots in: a one-shot form, or a multi-turn chat. */
47
- type AgentUiMode = "form" | "chat";
48
- /** Where the handlers are mounted. */
49
- interface AgentEndpointOptions {
50
- /** Base path the handlers are mounted under. Defaults to `/api/seclai`. */
51
- basePath?: string;
52
- /**
53
- * Adds the agent id to the path, for a server that hosts several agents:
54
- * `${basePath}/${agentId}/run`. Leave it out when the server has just one. The
55
- * server still decides which agents it serves.
56
- */
57
- agentId?: string;
58
- }
59
-
60
- /** A named attach button, such as "+ Headshot". */
61
- interface AgentChatAttachButton {
62
- label: string;
63
- /** Stays with every file added through this button. See `onBeforeSend`. */
64
- tag?: string;
65
- }
66
- /** A file the user sent with a message. */
67
- interface AgentChatFile {
68
- uploadId: string;
69
- name: string;
70
- contentType: string;
71
- /** The tag of the attach button it was added with. Dropped and pasted files have none. */
72
- tag?: string;
73
- }
74
- /** What `onBeforeSend` gets: the typed text and the files going with it. */
75
- interface AgentChatMessage {
76
- input: string;
77
- files: AgentChatFile[];
78
- }
79
- interface AgentChatProps extends AgentEndpointOptions {
80
- /** Placeholder for the message box. */
81
- placeholder?: string;
82
- /**
83
- * Named attach buttons, for agents that take files. Without them the chat shows
84
- * one "Attach" button, and only when the agent accepts files.
85
- */
86
- attachButtons?: AgentChatAttachButton[];
87
- /**
88
- * Called as a message is sent. Return a string to send that as the run's input
89
- * in place of the typed text, for example to tell the agent which file is which
90
- * from their tags. The transcript still shows what the user typed.
91
- */
92
- onBeforeSend?(message: AgentChatMessage): string | void;
93
- /**
94
- * The session id sent with every run, which keys the agent's conversation
95
- * memory. Leave it out and the chat makes one up on the first message.
96
- *
97
- * Changing it switches to another conversation: the transcript resets to
98
- * `initialTurns`, the composer clears, and a reply still streaming stops.
99
- * Remounting with a `key` does the same. Passing the id the chat generated,
100
- * after starting without one, adopts it and resets nothing. For a new chat,
101
- * prefer generating the id up front and passing it from the start.
102
- */
103
- sessionId?: string;
104
- /**
105
- * Exchanges to show when the chat mounts, or when `sessionId` changes, such as
106
- * the ones `onTurnComplete` gave you. Read only then: later changes are
107
- * ignored, as with an input's `defaultValue`.
108
- */
109
- initialTurns?: AgentChatTurn[];
110
- /**
111
- * Called once per run, when it completes, fails or is cancelled, with the
112
- * exchange as plain data to save and pass back as `initialTurns`. A run cut
113
- * short by a `sessionId` change or an unmount still reports, as cancelled,
114
- * through the latest callback: save under `context.sessionId`, not a session
115
- * id captured from the surrounding scope.
116
- */
117
- onTurnComplete?(turn: AgentChatTurn, context: {
118
- sessionId: string;
119
- }): void;
120
- }
121
- /** A file an agent produced, without its URL, which is rebuilt from `runId` and `id`. */
122
- interface AgentChatAttachment {
123
- id: string;
124
- name: string | null;
125
- mime: string;
126
- bytes: number | null;
127
- }
128
- /**
129
- * One exchange: a message and the agent's reply. It's plain, serializable data,
130
- * so `onTurnComplete` output can be stored and passed back as `initialTurns`.
131
- */
132
- interface AgentChatTurn {
133
- /** What the user typed. */
134
- input: string;
135
- /** What was sent as the run's input, when `onBeforeSend` changed it. */
136
- sentInput?: string;
137
- /** Files sent with the message. Restored ones show without thumbnails. */
138
- files?: AgentChatFile[];
139
- /** The reply. For a failed or cancelled run, whatever had streamed. */
140
- output: string;
141
- /** Files the agent produced. Shown only when `runId` is set. */
142
- attachments?: AgentChatAttachment[];
143
- runId?: string | null;
144
- status: "completed" | "failed" | "cancelled";
145
- error?: string | null;
146
- }
147
- /**
148
- * A multi-turn chat. Each message is its own run, and the agent ties them into a
149
- * conversation through the session id in the run's metadata. When the agent
150
- * accepts files they can be attached, dropped or pasted, and each one uploads
151
- * as soon as it's added.
152
- *
153
- * Pass `sessionId` and `initialTurns` to reopen a saved conversation, and save
154
- * each exchange from `onTurnComplete`.
155
- */
156
- declare function AgentChat({ basePath, agentId, placeholder, attachButtons, onBeforeSend, sessionId, initialTurns, onTurnComplete, }: AgentChatProps): react.JSX.Element;
157
-
158
- interface SseEvent {
159
- event: string;
160
- data: unknown;
161
- }
162
-
163
- interface AgentRunState {
164
- status: AgentRunStatus;
165
- /** Streamed tokens while running; the run's final `output` once it completes. */
166
- text: string;
167
- /** Latest progress per step, in the order the steps started. */
168
- steps: AgentRunStep[];
169
- attachments: AgentAttachment[];
170
- error: string | null;
171
- runId: string | null;
172
- /**
173
- * When the current run started, from `Date.now()`. Kept once the run ends, so
174
- * a UI can show how long it took. `null` until `start` is called, and again
175
- * after `reset`.
176
- */
177
- startedAt: number | null;
178
- }
179
- /** One event from the run stream: the SSE event name and its parsed JSON data. */
180
- type AgentRunEvent = SseEvent;
181
- interface UseAgentRunOptions extends AgentEndpointOptions {
182
- /**
183
- * Called with each event read from the run stream, in order, as the hook
184
- * applies it to the state. The latest callback is always used, so it can be
185
- * an inline function. Events from a cancelled, reset or superseded run are
186
- * not passed on. If it throws, the error is logged with `console.error` and
187
- * the run carries on.
188
- */
189
- onEvent?(event: AgentRunEvent): void;
190
- }
191
- interface StartRunOptions {
192
- input?: string;
193
- uploadIds?: string[];
194
- /** Keys a conversation: sent to the agent as `metadata.session_id`. */
195
- sessionId?: string;
196
- }
197
- interface UseAgentRunResult extends AgentRunState {
198
- /**
199
- * Start a run, cancelling any run in progress. Resolves with the final state
200
- * and never rejects: failures are reported through `status` and `error`.
201
- */
202
- start(options: StartRunOptions): Promise<AgentRunState>;
203
- /**
204
- * Stop streaming this run. This closes the connection but does not cancel the
205
- * run on Seclai, which may carry on and use credits.
206
- */
207
- cancel(): void;
208
- /**
209
- * Return to `idle` and clear the state, stopping any stream in progress as
210
- * `cancel` does. Like `cancel`, it doesn't stop the run on Seclai. A pending
211
- * `start` still resolves, with `status: "cancelled"` and the run's last
212
- * `text`, `runId` and `startedAt`, while the hook itself shows `idle`.
213
- */
214
- reset(): void;
215
- }
216
- /** Run an agent through the handlers' `run` endpoint and track the event stream. */
217
- declare function useAgentRun(options?: UseAgentRunOptions): UseAgentRunResult;
218
-
219
- interface AgentRunFormProps extends AgentEndpointOptions {
220
- /** Label for the text input. */
221
- inputLabel?: string;
222
- /** Called when a run finishes, whether it succeeded or not. */
223
- onFinish?(result: AgentRunState): void;
224
- }
225
- /**
226
- * A form built from what the agent accepts: a text input plus one file input per
227
- * declared attachment. It uploads the files, then runs with text and files
228
- * together and shows the output.
229
- */
230
- declare function AgentRunForm({ basePath, agentId, inputLabel, onFinish }: AgentRunFormProps): react.JSX.Element;
231
-
232
- interface SeclaiAgentProps extends AgentEndpointOptions {
233
- /** `form` for a one-shot run, `chat` for a multi-turn conversation. */
234
- mode: AgentUiMode;
235
- }
236
- /** Boots the agent UI from its mode, and its agent id when the server hosts several. */
237
- declare function SeclaiAgent({ mode, basePath, agentId }: SeclaiAgentProps): react.JSX.Element;
238
-
239
- declare const DEFAULT_BASE_PATH = "/api/seclai";
240
- /**
241
- * The URLs of the `@seclai/handlers` routes. Build it with
242
- * {@link createEndpoints} rather than by hand: members may be added in later
243
- * versions.
244
- */
245
- interface AgentEndpoints {
246
- /** `GET`: the files the agent accepts. See {@link fetchAttachmentReferences}. */
247
- attachmentReferences: string;
248
- /** `POST` multipart form data with a `file` field. See {@link uploadFile}. */
249
- upload: string;
250
- /** `POST` JSON `{ input, uploadIds, sessionId }`: streams the run as SSE. */
251
- run: string;
252
- /**
253
- * The download proxy URL for a file a run produced. Use it in place of the
254
- * API's `download_url`, which needs the API key the browser doesn't have.
255
- *
256
- * @param runId The run that produced the file.
257
- * @param attachmentId The attachment's `id`.
258
- * @param name Optional file name for the download. Left out when empty.
259
- */
260
- download(runId: string, attachmentId: string, name?: string | null): string;
261
- }
262
- /**
263
- * Build the handler URLs for an agent, the same way `useAgentRun` and the
264
- * components do. Use it to link to stored attachments with `download`, rather
265
- * than writing the URL format by hand.
266
- *
267
- * Trailing slashes on `basePath` are dropped and `agentId` is URL-encoded.
268
- *
269
- * @example
270
- * const endpoints = createEndpoints({ agentId: "my-agent" });
271
- * endpoints.run; // "/api/seclai/my-agent/run"
272
- * endpoints.download(runId, attachmentId, "report.pdf");
273
- */
274
- declare function createEndpoints({ basePath, agentId, }?: AgentEndpointOptions): AgentEndpoints;
275
- /** Per-call options for {@link uploadFile} and {@link fetchAttachmentReferences}. */
276
- interface EndpointRequestOptions {
277
- /** Aborts the request. */
278
- signal?: AbortSignal;
279
- }
280
- /**
281
- * Fetch the files the agent's trigger accepts, and whether it requires any.
282
- *
283
- * @throws An `Error` with the handler's error message when the response isn't
284
- * OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
285
- */
286
- declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }?: EndpointRequestOptions): Promise<AttachmentReferences>;
287
- /** Options for {@link uploadFile}. */
288
- interface UploadFileOptions extends EndpointRequestOptions {
289
- /**
290
- * Your app's data for this upload, for example the session it belongs to or
291
- * the file's role. Added to the upload URL's query string, after any query
292
- * the URL already has; the `upload` handler passes them to `authorizeUpload`
293
- * and `upload.onUpload`. They are visible in the URL and in server logs, so
294
- * keep secrets out of them.
295
- */
296
- params?: Record<string, string> | URLSearchParams;
297
- }
298
- /**
299
- * Upload one file through the `upload` handler. Pass the returned `id` to
300
- * `start({ uploadIds })` from `useAgentRun`.
301
- *
302
- * The result is the handler's JSON response. When your `upload.onUpload`
303
- * returns its own `Response`, name its type: `uploadFile<MyUpload>(…)`. The
304
- * type isn't checked at run time.
305
- *
306
- * @param options `signal` aborts the upload. `params` is added to the upload
307
- * URL's query string.
308
- * @throws An `Error` with the handler's error message when the response isn't
309
- * OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
310
- *
311
- * @example
312
- * const upload = await uploadFile<MyUpload>(endpoints, file, {
313
- * params: { sessionId, kind: "headshot" },
314
- * });
315
- */
316
- declare function uploadFile<T = UploadResult>(endpoints: AgentEndpoints, file: File, { signal, params }?: UploadFileOptions): Promise<T>;
317
-
318
- /** A CSS aspect ratio: a number such as `16 / 9`, or a string such as `"16 / 9"`. */
319
- type MediaAspectRatio = number | string;
320
- interface MediaPreviewProps {
321
- attachment: AgentAttachment;
322
- /**
323
- * The image frame's aspect ratio. Without it the frame takes the image's own
324
- * ratio once it loads, and `--seclai-media-aspect-ratio` (square by default)
325
- * until then.
326
- */
327
- aspectRatio?: MediaAspectRatio;
328
- /** A badge on the image, matching the agent's numbered list ("1.", "2."). */
329
- number?: number;
330
- /** App-specific buttons, shown after the download link. A function gets the attachment. */
331
- actions?: ReactNode | ((attachment: AgentAttachment) => ReactNode);
332
- /** Makes the image a button, for opening a full-size viewer. */
333
- onOpen?(): void;
334
- }
335
- /**
336
- * Shows a file from a run. An image gets a card with a fixed-ratio frame and a
337
- * download link. Anything else is a download link for now: audio, video and PDF
338
- * previews are coming in a later version.
339
- */
340
- declare function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }: MediaPreviewProps): react.JSX.Element;
341
-
342
- interface MediaGalleryProps {
343
- /** A run's attachments. Images become numbered cards; other files follow as download links. */
344
- attachments: AgentAttachment[];
345
- /** Every card's aspect ratio. Without it each card takes its image's own ratio. */
346
- aspectRatio?: MediaAspectRatio;
347
- /**
348
- * Skeleton cards to show after the images, for images still being generated.
349
- * They're numbered on from the last image.
350
- */
351
- pending?: number;
352
- /** App-specific buttons for each card. Gets the attachment and its 1-based number. */
353
- actions?(attachment: AgentAttachment, number: number): ReactNode;
354
- }
355
- /**
356
- * Lays out a run's images as numbered cards that open a full-size viewer, with
357
- * "Download all" when there's more than one. Files that aren't images are shown
358
- * after them with `MediaPreview`.
359
- */
360
- declare function MediaGallery({ attachments, aspectRatio, pending, actions, }: MediaGalleryProps): react.JSX.Element;
361
-
362
- interface MediaSkeletonProps {
363
- /** The frame's aspect ratio. Defaults to `--seclai-media-aspect-ratio`, square unless you set it. */
364
- aspectRatio?: MediaAspectRatio;
365
- /** A badge, for the number the image will have once it arrives. */
366
- number?: number;
367
- /** What a screen reader hears. Defaults to "Image <number> is being generated". */
368
- label?: string;
369
- }
370
- /**
371
- * A placeholder card for an image that hasn't arrived yet, the same shape as a
372
- * `MediaPreview` card, so the layout doesn't jump when it does. It pulses unless
373
- * the user prefers reduced motion.
374
- */
375
- declare function MediaSkeleton({ aspectRatio, number, label }: MediaSkeletonProps): react.JSX.Element;
376
-
377
- interface MediaViewerProps {
378
- /** The images to page through, in order. Image `i` is numbered `i + 1`. */
379
- attachments: AgentAttachment[];
380
- /** The image showing, or `null` when the viewer is closed. */
381
- index: number | null;
382
- /** Called with the new index when the user goes to the previous or next image. */
383
- onIndexChange(index: number): void;
384
- /** Called when the user closes the viewer: Escape, the close button or a click on the backdrop. */
385
- onClose(): void;
386
- }
387
- /**
388
- * A full-size image viewer in a modal `<dialog>`, with previous and next (also on
389
- * the arrow keys) and a download button. It's controlled: pass the `index` to
390
- * show, and `null` to close it. Focus moves into the viewer when it opens and
391
- * back to where it was when it closes.
392
- */
393
- declare function MediaViewer({ attachments, index, onIndexChange, onClose }: MediaViewerProps): react.JSX.Element;
394
-
395
- /**
396
- * The filename to save an attachment as: its own name, or else `image-<number>`
397
- * (or its id) with an extension from its mime type.
398
- */
399
- declare function attachmentFileName(attachment: AgentAttachment, number?: number): string;
400
- /**
401
- * Saves a file in the browser, through a temporary `<a download>`.
402
- *
403
- * - With a URL, a URL that isn't `http:`, `https:`, `blob:` or relative (such as
404
- * `javascript:`) is skipped with a warning.
405
- * - With a `Blob`, such as an image drawn on a canvas, it makes an object URL
406
- * and revokes it 40 seconds later.
407
- *
408
- * Call it from an event handler. Without a `document`, as in server rendering,
409
- * it does nothing.
410
- */
411
- declare function saveFile(urlOrBlob: string | Blob, filename: string): void;
412
- /** A file for `saveFiles`: a URL or a `Blob`, and the name to save it as. */
413
- interface SaveFilesEntry {
414
- /** A URL, checked as `saveFile` checks it, or a `Blob`. */
415
- source: string | Blob;
416
- filename: string;
417
- }
418
- interface SaveFilesOptions {
419
- /** How long to wait between files. Defaults to 400 ms. */
420
- delayMs?: number;
421
- /** Stops before the next file once aborted. */
422
- signal?: AbortSignal;
423
- }
424
- /**
425
- * Saves several files one after another with `saveFile`. Browsers block a burst
426
- * of simultaneous downloads, so each one waits `delayMs` after the last. The
427
- * promise resolves once the last file is started, or when `signal` aborts.
428
- */
429
- declare function saveFiles(files: readonly SaveFilesEntry[], { delayMs, signal }?: SaveFilesOptions): Promise<void>;
430
-
431
- interface MarkdownContentProps {
432
- content: string;
433
- }
434
- /**
435
- * Shows agent output. It renders paragraphs (a single newline is a line
436
- * break), numbered lists that keep the agent's own numbers, bulleted lists,
437
- * lists nested under an item by indenting them, horizontal rules (`---`,
438
- * `***`, `___`) and `**bold**`. Everything else, such as headings, code, links
439
- * and tables, shows as the text it is. It never renders HTML. It also works on
440
- * text that's still streaming: a half-written list item, rule or `**` shows as
441
- * text until it's complete. Tables, maths and diagrams are coming in a later
442
- * version.
443
- */
444
- declare function MarkdownContent({ content }: MarkdownContentProps): react.JSX.Element;
445
-
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 };