@seclai/react 0.0.4 → 0.0.6
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 +59 -0
- package/dist/index.cjs +346 -81
- package/dist/index.d.cts +91 -3
- package/dist/index.d.ts +91 -3
- package/dist/index.js +343 -76
- package/dist/styles.css +134 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -56,15 +56,47 @@ interface AgentEndpointOptions {
|
|
|
56
56
|
agentId?: string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** A named attach button, such as "+ Headshot". */
|
|
60
|
+
interface AgentChatAttachButton {
|
|
61
|
+
label: string;
|
|
62
|
+
/** Stays with every file added through this button. See `onBeforeSend`. */
|
|
63
|
+
tag?: string;
|
|
64
|
+
}
|
|
65
|
+
/** A file the user sent with a message. */
|
|
66
|
+
interface AgentChatFile {
|
|
67
|
+
uploadId: string;
|
|
68
|
+
name: string;
|
|
69
|
+
contentType: string;
|
|
70
|
+
/** The tag of the attach button it was added with. Dropped and pasted files have none. */
|
|
71
|
+
tag?: string;
|
|
72
|
+
}
|
|
73
|
+
/** What `onBeforeSend` gets: the typed text and the files going with it. */
|
|
74
|
+
interface AgentChatMessage {
|
|
75
|
+
input: string;
|
|
76
|
+
files: AgentChatFile[];
|
|
77
|
+
}
|
|
59
78
|
interface AgentChatProps extends AgentEndpointOptions {
|
|
60
79
|
/** Placeholder for the message box. */
|
|
61
80
|
placeholder?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Named attach buttons, for agents that take files. Without them the chat shows
|
|
83
|
+
* one "Attach" button, and only when the agent accepts files.
|
|
84
|
+
*/
|
|
85
|
+
attachButtons?: AgentChatAttachButton[];
|
|
86
|
+
/**
|
|
87
|
+
* Called as a message is sent. Return a string to send that as the run's input
|
|
88
|
+
* in place of the typed text, for example to tell the agent which file is which
|
|
89
|
+
* from their tags. The transcript still shows what the user typed.
|
|
90
|
+
*/
|
|
91
|
+
onBeforeSend?(message: AgentChatMessage): string | void;
|
|
62
92
|
}
|
|
63
93
|
/**
|
|
64
94
|
* A multi-turn chat. Each message is its own run, and the agent ties them into a
|
|
65
|
-
* conversation through the session id in the run's metadata.
|
|
95
|
+
* conversation through the session id in the run's metadata. When the agent
|
|
96
|
+
* accepts files they can be attached, dropped or pasted, and each one uploads
|
|
97
|
+
* as soon as it's added.
|
|
66
98
|
*/
|
|
67
|
-
declare function AgentChat({ basePath, agentId, placeholder }: AgentChatProps): react.JSX.Element;
|
|
99
|
+
declare function AgentChat({ basePath, agentId, placeholder, attachButtons, onBeforeSend, }: AgentChatProps): react.JSX.Element;
|
|
68
100
|
|
|
69
101
|
interface AgentRunState {
|
|
70
102
|
status: AgentRunStatus;
|
|
@@ -118,6 +150,62 @@ interface SeclaiAgentProps extends AgentEndpointOptions {
|
|
|
118
150
|
declare function SeclaiAgent({ mode, basePath, agentId }: SeclaiAgentProps): react.JSX.Element;
|
|
119
151
|
|
|
120
152
|
declare const DEFAULT_BASE_PATH = "/api/seclai";
|
|
153
|
+
/**
|
|
154
|
+
* The URLs of the `@seclai/handlers` routes. Build it with
|
|
155
|
+
* {@link createEndpoints} rather than by hand: members may be added in later
|
|
156
|
+
* versions.
|
|
157
|
+
*/
|
|
158
|
+
interface AgentEndpoints {
|
|
159
|
+
/** `GET`: the files the agent accepts. See {@link fetchAttachmentReferences}. */
|
|
160
|
+
attachmentReferences: string;
|
|
161
|
+
/** `POST` multipart form data with a `file` field. See {@link uploadFile}. */
|
|
162
|
+
upload: string;
|
|
163
|
+
/** `POST` JSON `{ input, uploadIds, sessionId }`: streams the run as SSE. */
|
|
164
|
+
run: string;
|
|
165
|
+
/**
|
|
166
|
+
* The download proxy URL for a file a run produced. Use it in place of the
|
|
167
|
+
* API's `download_url`, which needs the API key the browser doesn't have.
|
|
168
|
+
*
|
|
169
|
+
* @param runId The run that produced the file.
|
|
170
|
+
* @param attachmentId The attachment's `id`.
|
|
171
|
+
* @param name Optional file name for the download. Left out when empty.
|
|
172
|
+
*/
|
|
173
|
+
download(runId: string, attachmentId: string, name?: string | null): string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build the handler URLs for an agent, the same way `useAgentRun` and the
|
|
177
|
+
* components do. Use it to link to stored attachments with `download`, rather
|
|
178
|
+
* than writing the URL format by hand.
|
|
179
|
+
*
|
|
180
|
+
* Trailing slashes on `basePath` are dropped and `agentId` is URL-encoded.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const endpoints = createEndpoints({ agentId: "my-agent" });
|
|
184
|
+
* endpoints.run; // "/api/seclai/my-agent/run"
|
|
185
|
+
* endpoints.download(runId, attachmentId, "report.pdf");
|
|
186
|
+
*/
|
|
187
|
+
declare function createEndpoints({ basePath, agentId, }?: AgentEndpointOptions): AgentEndpoints;
|
|
188
|
+
/** Per-call options for {@link uploadFile} and {@link fetchAttachmentReferences}. */
|
|
189
|
+
interface EndpointRequestOptions {
|
|
190
|
+
/** Aborts the request. */
|
|
191
|
+
signal?: AbortSignal;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Fetch the files the agent's trigger accepts, and whether it requires any.
|
|
195
|
+
*
|
|
196
|
+
* @throws An `Error` with the handler's error message when the response isn't
|
|
197
|
+
* OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
|
|
198
|
+
*/
|
|
199
|
+
declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }?: EndpointRequestOptions): Promise<AttachmentReferences>;
|
|
200
|
+
/**
|
|
201
|
+
* Upload one file through the `upload` handler. Pass the returned `id` to
|
|
202
|
+
* `start({ uploadIds })` from `useAgentRun`.
|
|
203
|
+
*
|
|
204
|
+
* @param options `signal` aborts the upload.
|
|
205
|
+
* @throws An `Error` with the handler's error message when the response isn't
|
|
206
|
+
* OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
|
|
207
|
+
*/
|
|
208
|
+
declare function uploadFile(endpoints: AgentEndpoints, file: File, { signal }?: EndpointRequestOptions): Promise<UploadResult>;
|
|
121
209
|
|
|
122
210
|
interface MarkdownContentProps {
|
|
123
211
|
content: string;
|
|
@@ -137,4 +225,4 @@ interface MediaPreviewProps {
|
|
|
137
225
|
*/
|
|
138
226
|
declare function MediaPreview({ attachment }: MediaPreviewProps): react.JSX.Element;
|
|
139
227
|
|
|
140
|
-
export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatProps, type AgentEndpointOptions, AgentRunForm, type AgentRunFormProps, type AgentRunState, type AgentRunStatus, type AgentRunStep, type AgentUiMode, type AttachmentReferences, DEFAULT_BASE_PATH, MarkdownContent, type MarkdownContentProps, MediaPreview, type MediaPreviewProps, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunResult, useAgentRun };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,15 +56,47 @@ interface AgentEndpointOptions {
|
|
|
56
56
|
agentId?: string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** A named attach button, such as "+ Headshot". */
|
|
60
|
+
interface AgentChatAttachButton {
|
|
61
|
+
label: string;
|
|
62
|
+
/** Stays with every file added through this button. See `onBeforeSend`. */
|
|
63
|
+
tag?: string;
|
|
64
|
+
}
|
|
65
|
+
/** A file the user sent with a message. */
|
|
66
|
+
interface AgentChatFile {
|
|
67
|
+
uploadId: string;
|
|
68
|
+
name: string;
|
|
69
|
+
contentType: string;
|
|
70
|
+
/** The tag of the attach button it was added with. Dropped and pasted files have none. */
|
|
71
|
+
tag?: string;
|
|
72
|
+
}
|
|
73
|
+
/** What `onBeforeSend` gets: the typed text and the files going with it. */
|
|
74
|
+
interface AgentChatMessage {
|
|
75
|
+
input: string;
|
|
76
|
+
files: AgentChatFile[];
|
|
77
|
+
}
|
|
59
78
|
interface AgentChatProps extends AgentEndpointOptions {
|
|
60
79
|
/** Placeholder for the message box. */
|
|
61
80
|
placeholder?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Named attach buttons, for agents that take files. Without them the chat shows
|
|
83
|
+
* one "Attach" button, and only when the agent accepts files.
|
|
84
|
+
*/
|
|
85
|
+
attachButtons?: AgentChatAttachButton[];
|
|
86
|
+
/**
|
|
87
|
+
* Called as a message is sent. Return a string to send that as the run's input
|
|
88
|
+
* in place of the typed text, for example to tell the agent which file is which
|
|
89
|
+
* from their tags. The transcript still shows what the user typed.
|
|
90
|
+
*/
|
|
91
|
+
onBeforeSend?(message: AgentChatMessage): string | void;
|
|
62
92
|
}
|
|
63
93
|
/**
|
|
64
94
|
* A multi-turn chat. Each message is its own run, and the agent ties them into a
|
|
65
|
-
* conversation through the session id in the run's metadata.
|
|
95
|
+
* conversation through the session id in the run's metadata. When the agent
|
|
96
|
+
* accepts files they can be attached, dropped or pasted, and each one uploads
|
|
97
|
+
* as soon as it's added.
|
|
66
98
|
*/
|
|
67
|
-
declare function AgentChat({ basePath, agentId, placeholder }: AgentChatProps): react.JSX.Element;
|
|
99
|
+
declare function AgentChat({ basePath, agentId, placeholder, attachButtons, onBeforeSend, }: AgentChatProps): react.JSX.Element;
|
|
68
100
|
|
|
69
101
|
interface AgentRunState {
|
|
70
102
|
status: AgentRunStatus;
|
|
@@ -118,6 +150,62 @@ interface SeclaiAgentProps extends AgentEndpointOptions {
|
|
|
118
150
|
declare function SeclaiAgent({ mode, basePath, agentId }: SeclaiAgentProps): react.JSX.Element;
|
|
119
151
|
|
|
120
152
|
declare const DEFAULT_BASE_PATH = "/api/seclai";
|
|
153
|
+
/**
|
|
154
|
+
* The URLs of the `@seclai/handlers` routes. Build it with
|
|
155
|
+
* {@link createEndpoints} rather than by hand: members may be added in later
|
|
156
|
+
* versions.
|
|
157
|
+
*/
|
|
158
|
+
interface AgentEndpoints {
|
|
159
|
+
/** `GET`: the files the agent accepts. See {@link fetchAttachmentReferences}. */
|
|
160
|
+
attachmentReferences: string;
|
|
161
|
+
/** `POST` multipart form data with a `file` field. See {@link uploadFile}. */
|
|
162
|
+
upload: string;
|
|
163
|
+
/** `POST` JSON `{ input, uploadIds, sessionId }`: streams the run as SSE. */
|
|
164
|
+
run: string;
|
|
165
|
+
/**
|
|
166
|
+
* The download proxy URL for a file a run produced. Use it in place of the
|
|
167
|
+
* API's `download_url`, which needs the API key the browser doesn't have.
|
|
168
|
+
*
|
|
169
|
+
* @param runId The run that produced the file.
|
|
170
|
+
* @param attachmentId The attachment's `id`.
|
|
171
|
+
* @param name Optional file name for the download. Left out when empty.
|
|
172
|
+
*/
|
|
173
|
+
download(runId: string, attachmentId: string, name?: string | null): string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build the handler URLs for an agent, the same way `useAgentRun` and the
|
|
177
|
+
* components do. Use it to link to stored attachments with `download`, rather
|
|
178
|
+
* than writing the URL format by hand.
|
|
179
|
+
*
|
|
180
|
+
* Trailing slashes on `basePath` are dropped and `agentId` is URL-encoded.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const endpoints = createEndpoints({ agentId: "my-agent" });
|
|
184
|
+
* endpoints.run; // "/api/seclai/my-agent/run"
|
|
185
|
+
* endpoints.download(runId, attachmentId, "report.pdf");
|
|
186
|
+
*/
|
|
187
|
+
declare function createEndpoints({ basePath, agentId, }?: AgentEndpointOptions): AgentEndpoints;
|
|
188
|
+
/** Per-call options for {@link uploadFile} and {@link fetchAttachmentReferences}. */
|
|
189
|
+
interface EndpointRequestOptions {
|
|
190
|
+
/** Aborts the request. */
|
|
191
|
+
signal?: AbortSignal;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Fetch the files the agent's trigger accepts, and whether it requires any.
|
|
195
|
+
*
|
|
196
|
+
* @throws An `Error` with the handler's error message when the response isn't
|
|
197
|
+
* OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
|
|
198
|
+
*/
|
|
199
|
+
declare function fetchAttachmentReferences(endpoints: AgentEndpoints, { signal }?: EndpointRequestOptions): Promise<AttachmentReferences>;
|
|
200
|
+
/**
|
|
201
|
+
* Upload one file through the `upload` handler. Pass the returned `id` to
|
|
202
|
+
* `start({ uploadIds })` from `useAgentRun`.
|
|
203
|
+
*
|
|
204
|
+
* @param options `signal` aborts the upload.
|
|
205
|
+
* @throws An `Error` with the handler's error message when the response isn't
|
|
206
|
+
* OK. Rejects as `fetch` does on a network failure or when `signal` aborts.
|
|
207
|
+
*/
|
|
208
|
+
declare function uploadFile(endpoints: AgentEndpoints, file: File, { signal }?: EndpointRequestOptions): Promise<UploadResult>;
|
|
121
209
|
|
|
122
210
|
interface MarkdownContentProps {
|
|
123
211
|
content: string;
|
|
@@ -137,4 +225,4 @@ interface MediaPreviewProps {
|
|
|
137
225
|
*/
|
|
138
226
|
declare function MediaPreview({ attachment }: MediaPreviewProps): react.JSX.Element;
|
|
139
227
|
|
|
140
|
-
export { type AcceptedAttachmentSlot, type AgentAttachment, AgentChat, type AgentChatProps, type AgentEndpointOptions, AgentRunForm, type AgentRunFormProps, type AgentRunState, type AgentRunStatus, type AgentRunStep, type AgentUiMode, type AttachmentReferences, DEFAULT_BASE_PATH, MarkdownContent, type MarkdownContentProps, MediaPreview, type MediaPreviewProps, SeclaiAgent, type SeclaiAgentProps, type StartRunOptions, type UploadResult, type UseAgentRunResult, useAgentRun };
|
|
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 };
|