@standardagents/react 0.10.1-next.bbd142a → 0.11.0-next.ab7e1ea
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/LICENSE.txt +48 -0
- package/README.md +191 -312
- package/dist/index.d.ts +83 -170
- package/dist/index.js +354 -398
- package/dist/index.js.map +1 -1
- package/package.json +14 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,135 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
id: string;
|
|
6
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
7
|
-
content: string | null;
|
|
8
|
-
name?: string | null;
|
|
9
|
-
tool_calls?: string | null;
|
|
10
|
-
tool_call_id?: string | null;
|
|
11
|
-
log_id?: string | null;
|
|
12
|
-
created_at: number;
|
|
13
|
-
request_sent_at?: number | null;
|
|
14
|
-
response_completed_at?: number | null;
|
|
15
|
-
status?: "pending" | "completed" | "failed";
|
|
16
|
-
silent?: boolean;
|
|
17
|
-
tool_status?: "success" | "error" | null;
|
|
18
|
-
reasoning_content?: string | null;
|
|
19
|
-
reasoning_details?: string | null;
|
|
20
|
-
parent_id?: string | null;
|
|
21
|
-
depth?: number;
|
|
22
|
-
}
|
|
23
|
-
interface WorkItem {
|
|
24
|
-
id: string;
|
|
25
|
-
type: "tool_call" | "tool_result";
|
|
26
|
-
name?: string;
|
|
27
|
-
content: string | null;
|
|
28
|
-
status?: "pending" | "success" | "error" | null;
|
|
29
|
-
tool_call_id?: string;
|
|
30
|
-
}
|
|
31
|
-
interface WorkMessage {
|
|
32
|
-
id: string;
|
|
33
|
-
type: "workblock";
|
|
34
|
-
content: string | null;
|
|
35
|
-
reasoning_content?: string | null;
|
|
36
|
-
workItems: WorkItem[];
|
|
37
|
-
status: "pending" | "completed" | "failed";
|
|
38
|
-
created_at: number;
|
|
39
|
-
depth?: number;
|
|
40
|
-
}
|
|
41
|
-
type ThreadMessage = Message | WorkMessage;
|
|
42
|
-
interface AgentBuilderConfig {
|
|
43
|
-
endpoint: string;
|
|
44
|
-
}
|
|
45
|
-
interface UseThreadOptions {
|
|
46
|
-
preload?: boolean;
|
|
47
|
-
live?: boolean;
|
|
48
|
-
endpoint?: string;
|
|
49
|
-
stream?: boolean;
|
|
50
|
-
useWorkblocks?: boolean;
|
|
51
|
-
depth?: number;
|
|
52
|
-
}
|
|
53
|
-
interface GetMessagesOptions {
|
|
54
|
-
limit?: number;
|
|
55
|
-
offset?: number;
|
|
56
|
-
depth?: number;
|
|
57
|
-
includeSilent?: boolean;
|
|
58
|
-
}
|
|
59
|
-
interface MessageDataEvent {
|
|
60
|
-
type: "message_data";
|
|
61
|
-
message_id: string;
|
|
62
|
-
depth: number;
|
|
63
|
-
data: Message;
|
|
64
|
-
}
|
|
65
|
-
interface MessageChunkEvent {
|
|
66
|
-
type: "message_chunk";
|
|
67
|
-
message_id: string;
|
|
68
|
-
depth: number;
|
|
69
|
-
chunk: string;
|
|
70
|
-
}
|
|
71
|
-
interface ErrorEvent {
|
|
72
|
-
type: "error";
|
|
73
|
-
error: string;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Custom thread event emitted via emitThreadEvent on the backend
|
|
77
|
-
*/
|
|
78
|
-
interface ThreadEvent<T = unknown> {
|
|
79
|
-
type: "event";
|
|
80
|
-
eventType: string;
|
|
81
|
-
data: T;
|
|
82
|
-
timestamp: number;
|
|
83
|
-
}
|
|
84
|
-
type MessageStreamEvent = MessageDataEvent | MessageChunkEvent | ErrorEvent | ThreadEvent;
|
|
85
|
-
interface LogDataEvent {
|
|
86
|
-
type: "log_data";
|
|
87
|
-
log_id: string;
|
|
88
|
-
data: any;
|
|
89
|
-
}
|
|
90
|
-
interface CustomEvent {
|
|
91
|
-
type: "custom";
|
|
92
|
-
customType: string;
|
|
93
|
-
value: any;
|
|
94
|
-
timestamp: number;
|
|
95
|
-
}
|
|
96
|
-
interface StoppedByUserEvent {
|
|
97
|
-
type: "stopped_by_user";
|
|
98
|
-
timestamp: number;
|
|
99
|
-
}
|
|
100
|
-
type LogStreamEvent = LogDataEvent | CustomEvent | StoppedByUserEvent;
|
|
101
|
-
interface SendMessagePayload {
|
|
102
|
-
role: "user" | "assistant" | "system";
|
|
103
|
-
content: string;
|
|
104
|
-
silent?: boolean;
|
|
105
|
-
}
|
|
106
|
-
interface Thread {
|
|
107
|
-
id: string;
|
|
108
|
-
agent_id: string;
|
|
109
|
-
metadata?: Record<string, any>;
|
|
110
|
-
created_at: number;
|
|
111
|
-
}
|
|
112
|
-
interface MessageWebSocketCallbacks {
|
|
113
|
-
onMessage?: (event: MessageDataEvent) => void;
|
|
114
|
-
onChunk?: (event: MessageChunkEvent) => void;
|
|
115
|
-
onEvent?: (event: ThreadEvent) => void;
|
|
116
|
-
onError?: (event: ErrorEvent) => void;
|
|
117
|
-
onOpen?: () => void;
|
|
118
|
-
onClose?: () => void;
|
|
119
|
-
}
|
|
120
|
-
interface LogWebSocketCallbacks {
|
|
121
|
-
onLog?: (event: LogDataEvent) => void;
|
|
122
|
-
onCustom?: (event: CustomEvent) => void;
|
|
123
|
-
onStopped?: (event: StoppedByUserEvent) => void;
|
|
124
|
-
onOpen?: () => void;
|
|
125
|
-
onClose?: () => void;
|
|
126
|
-
}
|
|
127
|
-
interface ThreadProviderOptions {
|
|
128
|
-
/** Maximum message depth to fetch/stream */
|
|
129
|
-
depth?: number;
|
|
130
|
-
/** Whether to include silent messages */
|
|
131
|
-
includeSilent?: boolean;
|
|
132
|
-
}
|
|
3
|
+
import { AgentBuilderConfig, Message, ThreadMessage, ConnectionStatus as ConnectionStatus$1, SendMessagePayload, ThreadFile, PendingAttachment } from '@standardagents/client';
|
|
4
|
+
export { AgentBuilderClient, AgentBuilderConfig, AttachmentPayload, AttachmentRef, CreateThreadPayload, CustomEvent, ErrorEvent, FileUploadManager, GetMessagesOptions, LogDataEvent, LogStreamEvent, LogWebSocketCallbacks, Message, MessageChunkEvent, MessageDataEvent, MessageStreamEvent, MessageWebSocketCallbacks, PendingAttachment, SendMessagePayload, StoppedByUserEvent, Thread, ThreadConnectionCallbacks, ThreadConnectionManager, ThreadConnectionOptions, ThreadEvent, ThreadFile, ThreadMessage, WorkItem, WorkMessage, generatePendingFileId, isImageMimeType, messagesToFiles, parseAttachments, readFileAsDataUrl, transformToWorkblocks } from '@standardagents/client';
|
|
133
5
|
|
|
134
6
|
interface AgentBuilderProviderProps {
|
|
135
7
|
config: AgentBuilderConfig;
|
|
@@ -148,6 +20,19 @@ interface AgentBuilderProviderProps {
|
|
|
148
20
|
*/
|
|
149
21
|
declare function AgentBuilderProvider({ config, children }: AgentBuilderProviderProps): react_jsx_runtime.JSX.Element;
|
|
150
22
|
|
|
23
|
+
interface ThreadProviderOptions {
|
|
24
|
+
/** Whether to preload messages on mount (default: true) */
|
|
25
|
+
preload?: boolean;
|
|
26
|
+
/** Whether to connect to live updates (default: true) */
|
|
27
|
+
live?: boolean;
|
|
28
|
+
/** Transform messages to workblocks (default: false) */
|
|
29
|
+
useWorkblocks?: boolean;
|
|
30
|
+
/** Maximum message depth to fetch/stream (default: 0) */
|
|
31
|
+
depth?: number;
|
|
32
|
+
/** Whether to include silent messages (default: false) */
|
|
33
|
+
includeSilent?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
151
36
|
/**
|
|
152
37
|
* Event listener callback type
|
|
153
38
|
*/
|
|
@@ -155,25 +40,57 @@ type EventListener<T = unknown> = (data: T) => void;
|
|
|
155
40
|
/**
|
|
156
41
|
* WebSocket connection status
|
|
157
42
|
*/
|
|
158
|
-
type ConnectionStatus =
|
|
43
|
+
type ConnectionStatus = ConnectionStatus$1;
|
|
159
44
|
/**
|
|
160
|
-
* Thread context value
|
|
45
|
+
* Thread context value - the public interface returned by useThread()
|
|
161
46
|
*/
|
|
162
47
|
interface ThreadContextValue {
|
|
163
48
|
/** The thread ID */
|
|
164
49
|
threadId: string;
|
|
165
50
|
/** Current messages in the thread */
|
|
166
51
|
messages: Message[];
|
|
167
|
-
/**
|
|
52
|
+
/** Messages transformed to workblocks (if useWorkblocks is true) */
|
|
53
|
+
workblocks: ThreadMessage[];
|
|
54
|
+
/** Whether messages are currently loading (alias: isLoading) */
|
|
168
55
|
loading: boolean;
|
|
56
|
+
/** Whether messages are currently loading (alias for loading) */
|
|
57
|
+
isLoading: boolean;
|
|
169
58
|
/** Any error that occurred */
|
|
170
59
|
error: Error | null;
|
|
171
|
-
/** WebSocket connection status */
|
|
60
|
+
/** WebSocket connection status (alias: status) */
|
|
172
61
|
connectionStatus: ConnectionStatus;
|
|
173
|
-
/**
|
|
62
|
+
/** WebSocket connection status (alias for connectionStatus) */
|
|
63
|
+
status: ConnectionStatus;
|
|
64
|
+
/** Subscribe to a specific event type (alias: onEvent) */
|
|
174
65
|
subscribeToEvent: <T = unknown>(eventType: string, listener: EventListener<T>) => () => void;
|
|
66
|
+
/** Subscribe to a specific event type (alias for subscribeToEvent) */
|
|
67
|
+
onEvent: <T = unknown>(eventType: string, listener: EventListener<T>) => () => void;
|
|
175
68
|
/** Options passed to the provider */
|
|
176
69
|
options: ThreadProviderOptions;
|
|
70
|
+
/** Send a message to the thread (auto-includes pending attachments) */
|
|
71
|
+
sendMessage: (payload: Omit<SendMessagePayload, 'attachments'>) => Promise<Message>;
|
|
72
|
+
/** Stop the current execution */
|
|
73
|
+
stopExecution: () => Promise<void>;
|
|
74
|
+
/** All files in the thread (pending uploads + committed from messages) */
|
|
75
|
+
files: ThreadFile[];
|
|
76
|
+
/** Add files and start uploading immediately to filesystem */
|
|
77
|
+
addFiles: (files: File[] | FileList) => void;
|
|
78
|
+
/** Remove a pending file (cannot remove committed files) */
|
|
79
|
+
removeFile: (id: string) => void;
|
|
80
|
+
/** Get the full URL for a file */
|
|
81
|
+
getFileUrl: (file: ThreadFile) => string;
|
|
82
|
+
/** Get the thumbnail URL for an image file */
|
|
83
|
+
getThumbnailUrl: (file: ThreadFile) => string;
|
|
84
|
+
/** Get preview URL - localPreviewUrl for pending images, thumbnail for committed */
|
|
85
|
+
getPreviewUrl: (file: ThreadFile) => string | null;
|
|
86
|
+
/** Pending attachments to be sent with next message */
|
|
87
|
+
attachments: PendingAttachment[];
|
|
88
|
+
/** Add attachment(s) to be sent with next message (no upload, stored locally) */
|
|
89
|
+
addAttachment: (files: File | File[] | FileList) => void;
|
|
90
|
+
/** Remove a pending attachment */
|
|
91
|
+
removeAttachment: (id: string) => void;
|
|
92
|
+
/** Clear all pending attachments */
|
|
93
|
+
clearAttachments: () => void;
|
|
177
94
|
}
|
|
178
95
|
interface ThreadProviderProps {
|
|
179
96
|
/** The thread ID to connect to */
|
|
@@ -184,6 +101,8 @@ interface ThreadProviderProps {
|
|
|
184
101
|
preload?: boolean;
|
|
185
102
|
/** Whether to enable live updates via WebSocket (default: true) */
|
|
186
103
|
live?: boolean;
|
|
104
|
+
/** Transform messages to workblocks (default: false) */
|
|
105
|
+
useWorkblocks?: boolean;
|
|
187
106
|
/** Maximum message depth to fetch/stream (default: 0 for top-level only) */
|
|
188
107
|
depth?: number;
|
|
189
108
|
/** Whether to include silent messages (default: false) */
|
|
@@ -207,8 +126,10 @@ interface ThreadProviderProps {
|
|
|
207
126
|
* </AgentBuilderProvider>
|
|
208
127
|
* ```
|
|
209
128
|
*/
|
|
210
|
-
declare function ThreadProvider({ threadId, options, preload, live, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
|
|
129
|
+
declare function ThreadProvider({ threadId, options, preload, live, useWorkblocks, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
|
|
211
130
|
/**
|
|
131
|
+
* @deprecated Use `useThread()` instead.
|
|
132
|
+
*
|
|
212
133
|
* Hook to access the thread context.
|
|
213
134
|
* Must be used within a ThreadProvider.
|
|
214
135
|
*
|
|
@@ -222,23 +143,24 @@ declare function useThreadContext(): ThreadContextValue;
|
|
|
222
143
|
declare function useThreadId(): string;
|
|
223
144
|
|
|
224
145
|
/**
|
|
225
|
-
* Hook to
|
|
146
|
+
* Hook to access the thread context.
|
|
226
147
|
*
|
|
227
|
-
* Must be used within a ThreadProvider.
|
|
228
|
-
*
|
|
148
|
+
* Must be used within a ThreadProvider. Returns the full thread context
|
|
149
|
+
* including messages, actions, and file management.
|
|
229
150
|
*
|
|
230
|
-
* @
|
|
231
|
-
* @returns Array of messages (raw or transformed to workblocks)
|
|
151
|
+
* @returns The thread context value
|
|
232
152
|
*
|
|
233
153
|
* @example
|
|
234
154
|
* ```tsx
|
|
235
155
|
* function ChatMessages() {
|
|
236
|
-
*
|
|
237
|
-
* const messages = useThread()
|
|
156
|
+
* const { messages, sendMessage, files } = useThread()
|
|
238
157
|
*
|
|
239
158
|
* return (
|
|
240
159
|
* <div>
|
|
241
160
|
* {messages.map(msg => <Message key={msg.id} message={msg} />)}
|
|
161
|
+
* <button onClick={() => sendMessage({ role: 'user', content: 'Hello!' })}>
|
|
162
|
+
* Send
|
|
163
|
+
* </button>
|
|
242
164
|
* </div>
|
|
243
165
|
* )
|
|
244
166
|
* }
|
|
@@ -248,14 +170,8 @@ declare function useThreadId(): string;
|
|
|
248
170
|
* <ChatMessages />
|
|
249
171
|
* </ThreadProvider>
|
|
250
172
|
* ```
|
|
251
|
-
*
|
|
252
|
-
* @example
|
|
253
|
-
* ```tsx
|
|
254
|
-
* // Disable workblocks transformation
|
|
255
|
-
* const messages = useThread({ useWorkblocks: false })
|
|
256
|
-
* ```
|
|
257
173
|
*/
|
|
258
|
-
declare function useThread(
|
|
174
|
+
declare function useThread(): ThreadContextValue;
|
|
259
175
|
|
|
260
176
|
/**
|
|
261
177
|
* Hook to listen for custom events emitted from a thread via the stream WebSocket.
|
|
@@ -339,6 +255,8 @@ declare function onThreadEvent<T = unknown>(type: string, callback: (data: T) =>
|
|
|
339
255
|
declare function useThreadEvent<T = unknown>(type: string): T | null;
|
|
340
256
|
|
|
341
257
|
/**
|
|
258
|
+
* @deprecated Use `const { sendMessage } = useThread()` instead.
|
|
259
|
+
*
|
|
342
260
|
* Hook that returns a function to send messages to the current thread.
|
|
343
261
|
* Must be used within a ThreadProvider.
|
|
344
262
|
*
|
|
@@ -351,23 +269,20 @@ declare function useThreadEvent<T = unknown>(type: string): T | null;
|
|
|
351
269
|
*
|
|
352
270
|
* @example
|
|
353
271
|
* ```tsx
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* const handleSubmit = async (content: string) => {
|
|
358
|
-
* await sendMessage({
|
|
359
|
-
* role: 'user',
|
|
360
|
-
* content,
|
|
361
|
-
* })
|
|
362
|
-
* }
|
|
272
|
+
* // NEW - Recommended
|
|
273
|
+
* const { sendMessage } = useThread()
|
|
274
|
+
* await sendMessage({ role: 'user', content: 'Hello!' })
|
|
363
275
|
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
276
|
+
* // OLD - Deprecated
|
|
277
|
+
* const sendMessage = useSendMessage()
|
|
278
|
+
* await sendMessage({ role: 'user', content: 'Hello!' })
|
|
366
279
|
* ```
|
|
367
280
|
*/
|
|
368
281
|
declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Message>;
|
|
369
282
|
|
|
370
283
|
/**
|
|
284
|
+
* @deprecated Use `const { stopExecution } = useThread()` instead.
|
|
285
|
+
*
|
|
371
286
|
* Hook that returns a function to stop the current thread's execution.
|
|
372
287
|
* Must be used within a ThreadProvider.
|
|
373
288
|
*
|
|
@@ -380,15 +295,13 @@ declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Mess
|
|
|
380
295
|
*
|
|
381
296
|
* @example
|
|
382
297
|
* ```tsx
|
|
383
|
-
*
|
|
384
|
-
*
|
|
298
|
+
* // NEW - Recommended
|
|
299
|
+
* const { stopExecution } = useThread()
|
|
300
|
+
* await stopExecution()
|
|
385
301
|
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* </button>
|
|
390
|
-
* )
|
|
391
|
-
* }
|
|
302
|
+
* // OLD - Deprecated
|
|
303
|
+
* const stopThread = useStopThread()
|
|
304
|
+
* await stopThread()
|
|
392
305
|
* ```
|
|
393
306
|
*/
|
|
394
307
|
declare function useStopThread(): () => Promise<void>;
|
|
@@ -460,4 +373,4 @@ interface StopThreadOptions {
|
|
|
460
373
|
*/
|
|
461
374
|
declare function stopThread(id: string, options?: StopThreadOptions): Promise<void>;
|
|
462
375
|
|
|
463
|
-
export {
|
|
376
|
+
export { AgentBuilderProvider, type ConnectionStatus, type ThreadContextValue, ThreadProvider, type ThreadProviderOptions, onThreadEvent, sendMessage, stopThread, useSendMessage, useStopThread, useThread, useThreadContext, useThreadEvent, useThreadId };
|