@seclai/react 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react from 'react';
2
+ import { ReactNode } from 'react';
2
3
 
3
4
  /**
4
5
  * The handlers' wire format, declared here rather than imported from
@@ -98,6 +99,11 @@ interface AgentChatProps extends AgentEndpointOptions {
98
99
  */
99
100
  declare function AgentChat({ basePath, agentId, placeholder, attachButtons, onBeforeSend, }: AgentChatProps): react.JSX.Element;
100
101
 
102
+ interface SseEvent {
103
+ event: string;
104
+ data: unknown;
105
+ }
106
+
101
107
  interface AgentRunState {
102
108
  status: AgentRunStatus;
103
109
  /** Streamed tokens while running; the run's final `output` once it completes. */
@@ -107,6 +113,24 @@ interface AgentRunState {
107
113
  attachments: AgentAttachment[];
108
114
  error: string | null;
109
115
  runId: string | null;
116
+ /**
117
+ * When the current run started, from `Date.now()`. Kept once the run ends, so
118
+ * a UI can show how long it took. `null` until `start` is called, and again
119
+ * after `reset`.
120
+ */
121
+ startedAt: number | null;
122
+ }
123
+ /** One event from the run stream: the SSE event name and its parsed JSON data. */
124
+ type AgentRunEvent = SseEvent;
125
+ interface UseAgentRunOptions extends AgentEndpointOptions {
126
+ /**
127
+ * Called with each event read from the run stream, in order, as the hook
128
+ * applies it to the state. The latest callback is always used, so it can be
129
+ * an inline function. Events from a cancelled, reset or superseded run are
130
+ * not passed on. If it throws, the error is logged with `console.error` and
131
+ * the run carries on.
132
+ */
133
+ onEvent?(event: AgentRunEvent): void;
110
134
  }
111
135
  interface StartRunOptions {
112
136
  input?: string;
@@ -125,9 +149,16 @@ interface UseAgentRunResult extends AgentRunState {
125
149
  * run on Seclai, which may carry on and use credits.
126
150
  */
127
151
  cancel(): void;
152
+ /**
153
+ * Return to `idle` and clear the state, stopping any stream in progress as
154
+ * `cancel` does. Like `cancel`, it doesn't stop the run on Seclai. A pending
155
+ * `start` still resolves, with `status: "cancelled"` and the run's last
156
+ * `text`, `runId` and `startedAt`, while the hook itself shows `idle`.
157
+ */
158
+ reset(): void;
128
159
  }
129
160
  /** Run an agent through the handlers' `run` endpoint and track the event stream. */
130
- declare function useAgentRun(options?: AgentEndpointOptions): UseAgentRunResult;
161
+ declare function useAgentRun(options?: UseAgentRunOptions): UseAgentRunResult;
131
162
 
132
163
  interface AgentRunFormProps extends AgentEndpointOptions {
133
164
  /** Label for the text input. */
@@ -207,6 +238,89 @@ declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }
207
238
  */
208
239
  declare function uploadFile(endpoints: AgentEndpoints, file: File, { signal }?: EndpointRequestOptions): Promise<UploadResult>;
209
240
 
241
+ /** A CSS aspect ratio: a number such as `16 / 9`, or a string such as `"16 / 9"`. */
242
+ type MediaAspectRatio = number | string;
243
+ interface MediaPreviewProps {
244
+ attachment: AgentAttachment;
245
+ /**
246
+ * The image frame's aspect ratio. Without it the frame takes the image's own
247
+ * ratio once it loads, and `--seclai-media-aspect-ratio` (square by default)
248
+ * until then.
249
+ */
250
+ aspectRatio?: MediaAspectRatio;
251
+ /** A badge on the image, matching the agent's numbered list ("1.", "2."). */
252
+ number?: number;
253
+ /** App-specific buttons, shown after the download link. A function gets the attachment. */
254
+ actions?: ReactNode | ((attachment: AgentAttachment) => ReactNode);
255
+ /** Makes the image a button, for opening a full-size viewer. */
256
+ onOpen?(): void;
257
+ }
258
+ /**
259
+ * Shows a file from a run. An image gets a card with a fixed-ratio frame and a
260
+ * download link. Anything else is a download link for now: audio, video and PDF
261
+ * previews are coming in a later version.
262
+ */
263
+ declare function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }: MediaPreviewProps): react.JSX.Element;
264
+
265
+ interface MediaGalleryProps {
266
+ /** A run's attachments. Images become numbered cards; other files follow as download links. */
267
+ attachments: AgentAttachment[];
268
+ /** Every card's aspect ratio. Without it each card takes its image's own ratio. */
269
+ aspectRatio?: MediaAspectRatio;
270
+ /**
271
+ * Skeleton cards to show after the images, for images still being generated.
272
+ * They're numbered on from the last image.
273
+ */
274
+ pending?: number;
275
+ /** App-specific buttons for each card. Gets the attachment and its 1-based number. */
276
+ actions?(attachment: AgentAttachment, number: number): ReactNode;
277
+ }
278
+ /**
279
+ * Lays out a run's images as numbered cards that open a full-size viewer, with
280
+ * "Download all" when there's more than one. Files that aren't images are shown
281
+ * after them with `MediaPreview`.
282
+ */
283
+ declare function MediaGallery({ attachments, aspectRatio, pending, actions, }: MediaGalleryProps): react.JSX.Element;
284
+
285
+ interface MediaSkeletonProps {
286
+ /** The frame's aspect ratio. Defaults to `--seclai-media-aspect-ratio`, square unless you set it. */
287
+ aspectRatio?: MediaAspectRatio;
288
+ /** A badge, for the number the image will have once it arrives. */
289
+ number?: number;
290
+ /** What a screen reader hears. Defaults to "Image <number> is being generated". */
291
+ label?: string;
292
+ }
293
+ /**
294
+ * A placeholder card for an image that hasn't arrived yet, the same shape as a
295
+ * `MediaPreview` card, so the layout doesn't jump when it does. It pulses unless
296
+ * the user prefers reduced motion.
297
+ */
298
+ declare function MediaSkeleton({ aspectRatio, number, label }: MediaSkeletonProps): react.JSX.Element;
299
+
300
+ interface MediaViewerProps {
301
+ /** The images to page through, in order. Image `i` is numbered `i + 1`. */
302
+ attachments: AgentAttachment[];
303
+ /** The image showing, or `null` when the viewer is closed. */
304
+ index: number | null;
305
+ /** Called with the new index when the user goes to the previous or next image. */
306
+ onIndexChange(index: number): void;
307
+ /** Called when the user closes the viewer: Escape, the close button or a click on the backdrop. */
308
+ onClose(): void;
309
+ }
310
+ /**
311
+ * A full-size image viewer in a modal `<dialog>`, with previous and next (also on
312
+ * the arrow keys) and a download button. It's controlled: pass the `index` to
313
+ * show, and `null` to close it. Focus moves into the viewer when it opens and
314
+ * back to where it was when it closes.
315
+ */
316
+ declare function MediaViewer({ attachments, index, onIndexChange, onClose }: MediaViewerProps): react.JSX.Element;
317
+
318
+ /**
319
+ * The filename to save an attachment as: its own name, or else `image-<number>`
320
+ * (or its id) with an extension from its mime type.
321
+ */
322
+ declare function attachmentFileName(attachment: AgentAttachment, number?: number): string;
323
+
210
324
  interface MarkdownContentProps {
211
325
  content: string;
212
326
  }
@@ -216,13 +330,4 @@ interface MarkdownContentProps {
216
330
  */
217
331
  declare function MarkdownContent({ content }: MarkdownContentProps): react.JSX.Element;
218
332
 
219
- interface MediaPreviewProps {
220
- attachment: AgentAttachment;
221
- }
222
- /**
223
- * Shows a file from a run. For now images show inline and everything else is a
224
- * download link. Audio, video and PDF previews are coming in a later version.
225
- */
226
- declare function MediaPreview({ attachment }: MediaPreviewProps): react.JSX.Element;
227
-
228
- export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatAttachButton, type AgentChatFile, type AgentChatMessage, type AgentChatProps, type AgentEndpointOptions, type AgentEndpoints, AgentRunForm, type AgentRunFormProps, type AgentRunState, type AgentRunStatus, type AgentRunStep, type AgentUiMode, type AttachmentReferences, DEFAULT_BASE_PATH, type EndpointRequestOptions, MarkdownContent, type MarkdownContentProps, MediaPreview, type MediaPreviewProps, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunResult, createEndpoints, fetchAttachmentReferences, uploadFile, useAgentRun };
333
+ export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatAttachButton, type AgentChatFile, type AgentChatMessage, type AgentChatProps, 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, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunOptions, type UseAgentRunResult, attachmentFileName, createEndpoints, fetchAttachmentReferences, uploadFile, useAgentRun };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react from 'react';
2
+ import { ReactNode } from 'react';
2
3
 
3
4
  /**
4
5
  * The handlers' wire format, declared here rather than imported from
@@ -98,6 +99,11 @@ interface AgentChatProps extends AgentEndpointOptions {
98
99
  */
99
100
  declare function AgentChat({ basePath, agentId, placeholder, attachButtons, onBeforeSend, }: AgentChatProps): react.JSX.Element;
100
101
 
102
+ interface SseEvent {
103
+ event: string;
104
+ data: unknown;
105
+ }
106
+
101
107
  interface AgentRunState {
102
108
  status: AgentRunStatus;
103
109
  /** Streamed tokens while running; the run's final `output` once it completes. */
@@ -107,6 +113,24 @@ interface AgentRunState {
107
113
  attachments: AgentAttachment[];
108
114
  error: string | null;
109
115
  runId: string | null;
116
+ /**
117
+ * When the current run started, from `Date.now()`. Kept once the run ends, so
118
+ * a UI can show how long it took. `null` until `start` is called, and again
119
+ * after `reset`.
120
+ */
121
+ startedAt: number | null;
122
+ }
123
+ /** One event from the run stream: the SSE event name and its parsed JSON data. */
124
+ type AgentRunEvent = SseEvent;
125
+ interface UseAgentRunOptions extends AgentEndpointOptions {
126
+ /**
127
+ * Called with each event read from the run stream, in order, as the hook
128
+ * applies it to the state. The latest callback is always used, so it can be
129
+ * an inline function. Events from a cancelled, reset or superseded run are
130
+ * not passed on. If it throws, the error is logged with `console.error` and
131
+ * the run carries on.
132
+ */
133
+ onEvent?(event: AgentRunEvent): void;
110
134
  }
111
135
  interface StartRunOptions {
112
136
  input?: string;
@@ -125,9 +149,16 @@ interface UseAgentRunResult extends AgentRunState {
125
149
  * run on Seclai, which may carry on and use credits.
126
150
  */
127
151
  cancel(): void;
152
+ /**
153
+ * Return to `idle` and clear the state, stopping any stream in progress as
154
+ * `cancel` does. Like `cancel`, it doesn't stop the run on Seclai. A pending
155
+ * `start` still resolves, with `status: "cancelled"` and the run's last
156
+ * `text`, `runId` and `startedAt`, while the hook itself shows `idle`.
157
+ */
158
+ reset(): void;
128
159
  }
129
160
  /** Run an agent through the handlers' `run` endpoint and track the event stream. */
130
- declare function useAgentRun(options?: AgentEndpointOptions): UseAgentRunResult;
161
+ declare function useAgentRun(options?: UseAgentRunOptions): UseAgentRunResult;
131
162
 
132
163
  interface AgentRunFormProps extends AgentEndpointOptions {
133
164
  /** Label for the text input. */
@@ -207,6 +238,89 @@ declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }
207
238
  */
208
239
  declare function uploadFile(endpoints: AgentEndpoints, file: File, { signal }?: EndpointRequestOptions): Promise<UploadResult>;
209
240
 
241
+ /** A CSS aspect ratio: a number such as `16 / 9`, or a string such as `"16 / 9"`. */
242
+ type MediaAspectRatio = number | string;
243
+ interface MediaPreviewProps {
244
+ attachment: AgentAttachment;
245
+ /**
246
+ * The image frame's aspect ratio. Without it the frame takes the image's own
247
+ * ratio once it loads, and `--seclai-media-aspect-ratio` (square by default)
248
+ * until then.
249
+ */
250
+ aspectRatio?: MediaAspectRatio;
251
+ /** A badge on the image, matching the agent's numbered list ("1.", "2."). */
252
+ number?: number;
253
+ /** App-specific buttons, shown after the download link. A function gets the attachment. */
254
+ actions?: ReactNode | ((attachment: AgentAttachment) => ReactNode);
255
+ /** Makes the image a button, for opening a full-size viewer. */
256
+ onOpen?(): void;
257
+ }
258
+ /**
259
+ * Shows a file from a run. An image gets a card with a fixed-ratio frame and a
260
+ * download link. Anything else is a download link for now: audio, video and PDF
261
+ * previews are coming in a later version.
262
+ */
263
+ declare function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }: MediaPreviewProps): react.JSX.Element;
264
+
265
+ interface MediaGalleryProps {
266
+ /** A run's attachments. Images become numbered cards; other files follow as download links. */
267
+ attachments: AgentAttachment[];
268
+ /** Every card's aspect ratio. Without it each card takes its image's own ratio. */
269
+ aspectRatio?: MediaAspectRatio;
270
+ /**
271
+ * Skeleton cards to show after the images, for images still being generated.
272
+ * They're numbered on from the last image.
273
+ */
274
+ pending?: number;
275
+ /** App-specific buttons for each card. Gets the attachment and its 1-based number. */
276
+ actions?(attachment: AgentAttachment, number: number): ReactNode;
277
+ }
278
+ /**
279
+ * Lays out a run's images as numbered cards that open a full-size viewer, with
280
+ * "Download all" when there's more than one. Files that aren't images are shown
281
+ * after them with `MediaPreview`.
282
+ */
283
+ declare function MediaGallery({ attachments, aspectRatio, pending, actions, }: MediaGalleryProps): react.JSX.Element;
284
+
285
+ interface MediaSkeletonProps {
286
+ /** The frame's aspect ratio. Defaults to `--seclai-media-aspect-ratio`, square unless you set it. */
287
+ aspectRatio?: MediaAspectRatio;
288
+ /** A badge, for the number the image will have once it arrives. */
289
+ number?: number;
290
+ /** What a screen reader hears. Defaults to "Image <number> is being generated". */
291
+ label?: string;
292
+ }
293
+ /**
294
+ * A placeholder card for an image that hasn't arrived yet, the same shape as a
295
+ * `MediaPreview` card, so the layout doesn't jump when it does. It pulses unless
296
+ * the user prefers reduced motion.
297
+ */
298
+ declare function MediaSkeleton({ aspectRatio, number, label }: MediaSkeletonProps): react.JSX.Element;
299
+
300
+ interface MediaViewerProps {
301
+ /** The images to page through, in order. Image `i` is numbered `i + 1`. */
302
+ attachments: AgentAttachment[];
303
+ /** The image showing, or `null` when the viewer is closed. */
304
+ index: number | null;
305
+ /** Called with the new index when the user goes to the previous or next image. */
306
+ onIndexChange(index: number): void;
307
+ /** Called when the user closes the viewer: Escape, the close button or a click on the backdrop. */
308
+ onClose(): void;
309
+ }
310
+ /**
311
+ * A full-size image viewer in a modal `<dialog>`, with previous and next (also on
312
+ * the arrow keys) and a download button. It's controlled: pass the `index` to
313
+ * show, and `null` to close it. Focus moves into the viewer when it opens and
314
+ * back to where it was when it closes.
315
+ */
316
+ declare function MediaViewer({ attachments, index, onIndexChange, onClose }: MediaViewerProps): react.JSX.Element;
317
+
318
+ /**
319
+ * The filename to save an attachment as: its own name, or else `image-<number>`
320
+ * (or its id) with an extension from its mime type.
321
+ */
322
+ declare function attachmentFileName(attachment: AgentAttachment, number?: number): string;
323
+
210
324
  interface MarkdownContentProps {
211
325
  content: string;
212
326
  }
@@ -216,13 +330,4 @@ interface MarkdownContentProps {
216
330
  */
217
331
  declare function MarkdownContent({ content }: MarkdownContentProps): react.JSX.Element;
218
332
 
219
- interface MediaPreviewProps {
220
- attachment: AgentAttachment;
221
- }
222
- /**
223
- * Shows a file from a run. For now images show inline and everything else is a
224
- * download link. Audio, video and PDF previews are coming in a later version.
225
- */
226
- declare function MediaPreview({ attachment }: MediaPreviewProps): react.JSX.Element;
227
-
228
- export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatAttachButton, type AgentChatFile, type AgentChatMessage, type AgentChatProps, type AgentEndpointOptions, type AgentEndpoints, AgentRunForm, type AgentRunFormProps, type AgentRunState, type AgentRunStatus, type AgentRunStep, type AgentUiMode, type AttachmentReferences, DEFAULT_BASE_PATH, type EndpointRequestOptions, MarkdownContent, type MarkdownContentProps, MediaPreview, type MediaPreviewProps, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunResult, createEndpoints, fetchAttachmentReferences, uploadFile, useAgentRun };
333
+ export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatAttachButton, type AgentChatFile, type AgentChatMessage, type AgentChatProps, 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, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunOptions, type UseAgentRunResult, attachmentFileName, createEndpoints, fetchAttachmentReferences, uploadFile, useAgentRun };