@seclai/react 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts 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
@@ -284,15 +312,36 @@ interface EndpointRequestOptions {
284
312
  * OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
285
313
  */
286
314
  declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }?: EndpointRequestOptions): Promise<AttachmentReferences>;
315
+ /** Options for {@link uploadFile}. */
316
+ interface UploadFileOptions extends EndpointRequestOptions {
317
+ /**
318
+ * Your app's data for this upload, for example the session it belongs to or
319
+ * the file's role. Added to the upload URL's query string, after any query
320
+ * the URL already has; the `upload` handler passes them to `authorizeUpload`
321
+ * and `upload.onUpload`. They are visible in the URL and in server logs, so
322
+ * keep secrets out of them.
323
+ */
324
+ params?: Record<string, string> | URLSearchParams;
325
+ }
287
326
  /**
288
327
  * Upload one file through the `upload` handler. Pass the returned `id` to
289
328
  * `start({ uploadIds })` from `useAgentRun`.
290
329
  *
291
- * @param options `signal` aborts the upload.
330
+ * The result is the handler's JSON response. When your `upload.onUpload`
331
+ * returns its own `Response`, name its type: `uploadFile<MyUpload>(…)`. The
332
+ * type isn't checked at run time.
333
+ *
334
+ * @param options `signal` aborts the upload. `params` is added to the upload
335
+ * URL's query string.
292
336
  * @throws An `Error` with the handler's error message when the response isn't
293
337
  * OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
338
+ *
339
+ * @example
340
+ * const upload = await uploadFile<MyUpload>(endpoints, file, {
341
+ * params: { sessionId, kind: "headshot" },
342
+ * });
294
343
  */
295
- declare function uploadFile(endpoints: AgentEndpoints, file: File, { signal }?: EndpointRequestOptions): Promise<UploadResult>;
344
+ declare function uploadFile<T = UploadResult>(endpoints: AgentEndpoints, file: File, { signal, params }?: UploadFileOptions): Promise<T>;
296
345
 
297
346
  /** A CSS aspect ratio: a number such as `16 / 9`, or a string such as `"16 / 9"`. */
298
347
  type MediaAspectRatio = number | string;
@@ -376,6 +425,36 @@ declare function MediaViewer({ attachments, index, onIndexChange, onClose }: Med
376
425
  * (or its id) with an extension from its mime type.
377
426
  */
378
427
  declare function attachmentFileName(attachment: AgentAttachment, number?: number): string;
428
+ /**
429
+ * Saves a file in the browser, through a temporary `<a download>`.
430
+ *
431
+ * - With a URL, a URL that isn't `http:`, `https:`, `blob:` or relative (such as
432
+ * `javascript:`) is skipped with a warning.
433
+ * - With a `Blob`, such as an image drawn on a canvas, it makes an object URL
434
+ * and revokes it 40 seconds later.
435
+ *
436
+ * Call it from an event handler. Without a `document`, as in server rendering,
437
+ * it does nothing.
438
+ */
439
+ declare function saveFile(urlOrBlob: string | Blob, filename: string): void;
440
+ /** A file for `saveFiles`: a URL or a `Blob`, and the name to save it as. */
441
+ interface SaveFilesEntry {
442
+ /** A URL, checked as `saveFile` checks it, or a `Blob`. */
443
+ source: string | Blob;
444
+ filename: string;
445
+ }
446
+ interface SaveFilesOptions {
447
+ /** How long to wait between files. Defaults to 400 ms. */
448
+ delayMs?: number;
449
+ /** Stops before the next file once aborted. */
450
+ signal?: AbortSignal;
451
+ }
452
+ /**
453
+ * Saves several files one after another with `saveFile`. Browsers block a burst
454
+ * of simultaneous downloads, so each one waits `delayMs` after the last. The
455
+ * promise resolves once the last file is started, or when `signal` aborts.
456
+ */
457
+ declare function saveFiles(files: readonly SaveFilesEntry[], { delayMs, signal }?: SaveFilesOptions): Promise<void>;
379
458
 
380
459
  interface MarkdownContentProps {
381
460
  content: string;
@@ -392,4 +471,4 @@ interface MarkdownContentProps {
392
471
  */
393
472
  declare function MarkdownContent({ content }: MarkdownContentProps): react.JSX.Element;
394
473
 
395
- 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, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunOptions, type UseAgentRunResult, attachmentFileName, createEndpoints, fetchAttachmentReferences, 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.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
@@ -284,15 +312,36 @@ interface EndpointRequestOptions {
284
312
  * OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
285
313
  */
286
314
  declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }?: EndpointRequestOptions): Promise<AttachmentReferences>;
315
+ /** Options for {@link uploadFile}. */
316
+ interface UploadFileOptions extends EndpointRequestOptions {
317
+ /**
318
+ * Your app's data for this upload, for example the session it belongs to or
319
+ * the file's role. Added to the upload URL's query string, after any query
320
+ * the URL already has; the `upload` handler passes them to `authorizeUpload`
321
+ * and `upload.onUpload`. They are visible in the URL and in server logs, so
322
+ * keep secrets out of them.
323
+ */
324
+ params?: Record<string, string> | URLSearchParams;
325
+ }
287
326
  /**
288
327
  * Upload one file through the `upload` handler. Pass the returned `id` to
289
328
  * `start({ uploadIds })` from `useAgentRun`.
290
329
  *
291
- * @param options `signal` aborts the upload.
330
+ * The result is the handler's JSON response. When your `upload.onUpload`
331
+ * returns its own `Response`, name its type: `uploadFile<MyUpload>(…)`. The
332
+ * type isn't checked at run time.
333
+ *
334
+ * @param options `signal` aborts the upload. `params` is added to the upload
335
+ * URL's query string.
292
336
  * @throws An `Error` with the handler's error message when the response isn't
293
337
  * OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
338
+ *
339
+ * @example
340
+ * const upload = await uploadFile<MyUpload>(endpoints, file, {
341
+ * params: { sessionId, kind: "headshot" },
342
+ * });
294
343
  */
295
- declare function uploadFile(endpoints: AgentEndpoints, file: File, { signal }?: EndpointRequestOptions): Promise<UploadResult>;
344
+ declare function uploadFile<T = UploadResult>(endpoints: AgentEndpoints, file: File, { signal, params }?: UploadFileOptions): Promise<T>;
296
345
 
297
346
  /** A CSS aspect ratio: a number such as `16 / 9`, or a string such as `"16 / 9"`. */
298
347
  type MediaAspectRatio = number | string;
@@ -376,6 +425,36 @@ declare function MediaViewer({ attachments, index, onIndexChange, onClose }: Med
376
425
  * (or its id) with an extension from its mime type.
377
426
  */
378
427
  declare function attachmentFileName(attachment: AgentAttachment, number?: number): string;
428
+ /**
429
+ * Saves a file in the browser, through a temporary `<a download>`.
430
+ *
431
+ * - With a URL, a URL that isn't `http:`, `https:`, `blob:` or relative (such as
432
+ * `javascript:`) is skipped with a warning.
433
+ * - With a `Blob`, such as an image drawn on a canvas, it makes an object URL
434
+ * and revokes it 40 seconds later.
435
+ *
436
+ * Call it from an event handler. Without a `document`, as in server rendering,
437
+ * it does nothing.
438
+ */
439
+ declare function saveFile(urlOrBlob: string | Blob, filename: string): void;
440
+ /** A file for `saveFiles`: a URL or a `Blob`, and the name to save it as. */
441
+ interface SaveFilesEntry {
442
+ /** A URL, checked as `saveFile` checks it, or a `Blob`. */
443
+ source: string | Blob;
444
+ filename: string;
445
+ }
446
+ interface SaveFilesOptions {
447
+ /** How long to wait between files. Defaults to 400 ms. */
448
+ delayMs?: number;
449
+ /** Stops before the next file once aborted. */
450
+ signal?: AbortSignal;
451
+ }
452
+ /**
453
+ * Saves several files one after another with `saveFile`. Browsers block a burst
454
+ * of simultaneous downloads, so each one waits `delayMs` after the last. The
455
+ * promise resolves once the last file is started, or when `signal` aborts.
456
+ */
457
+ declare function saveFiles(files: readonly SaveFilesEntry[], { delayMs, signal }?: SaveFilesOptions): Promise<void>;
379
458
 
380
459
  interface MarkdownContentProps {
381
460
  content: string;
@@ -392,4 +471,4 @@ interface MarkdownContentProps {
392
471
  */
393
472
  declare function MarkdownContent({ content }: MarkdownContentProps): react.JSX.Element;
394
473
 
395
- 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, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunOptions, type UseAgentRunResult, attachmentFileName, createEndpoints, fetchAttachmentReferences, 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 };