@standardagents/react 0.10.1-dev.b8746e9 → 0.10.1-next.bbd142a
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 +312 -191
- package/dist/index.d.ts +170 -75
- package/dist/index.js +399 -237
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,135 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
interface Message {
|
|
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
|
+
}
|
|
5
133
|
|
|
6
134
|
interface AgentBuilderProviderProps {
|
|
7
135
|
config: AgentBuilderConfig;
|
|
@@ -20,19 +148,6 @@ interface AgentBuilderProviderProps {
|
|
|
20
148
|
*/
|
|
21
149
|
declare function AgentBuilderProvider({ config, children }: AgentBuilderProviderProps): react_jsx_runtime.JSX.Element;
|
|
22
150
|
|
|
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
|
-
|
|
36
151
|
/**
|
|
37
152
|
* Event listener callback type
|
|
38
153
|
*/
|
|
@@ -40,49 +155,25 @@ type EventListener<T = unknown> = (data: T) => void;
|
|
|
40
155
|
/**
|
|
41
156
|
* WebSocket connection status
|
|
42
157
|
*/
|
|
43
|
-
type ConnectionStatus =
|
|
158
|
+
type ConnectionStatus = 'connecting' | 'connected' | 'disconnected';
|
|
44
159
|
/**
|
|
45
|
-
* Thread context value
|
|
160
|
+
* Thread context value
|
|
46
161
|
*/
|
|
47
162
|
interface ThreadContextValue {
|
|
48
163
|
/** The thread ID */
|
|
49
164
|
threadId: string;
|
|
50
165
|
/** Current messages in the thread */
|
|
51
166
|
messages: Message[];
|
|
52
|
-
/**
|
|
53
|
-
workblocks: ThreadMessage[];
|
|
54
|
-
/** Whether messages are currently loading (alias: isLoading) */
|
|
167
|
+
/** Whether messages are currently loading */
|
|
55
168
|
loading: boolean;
|
|
56
|
-
/** Whether messages are currently loading (alias for loading) */
|
|
57
|
-
isLoading: boolean;
|
|
58
169
|
/** Any error that occurred */
|
|
59
170
|
error: Error | null;
|
|
60
|
-
/** WebSocket connection status
|
|
171
|
+
/** WebSocket connection status */
|
|
61
172
|
connectionStatus: ConnectionStatus;
|
|
62
|
-
/**
|
|
63
|
-
status: ConnectionStatus;
|
|
64
|
-
/** Subscribe to a specific event type (alias: onEvent) */
|
|
173
|
+
/** Subscribe to a specific event type */
|
|
65
174
|
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;
|
|
68
175
|
/** Options passed to the provider */
|
|
69
176
|
options: ThreadProviderOptions;
|
|
70
|
-
/** Send a message to the thread */
|
|
71
|
-
sendMessage: (payload: SendMessagePayload) => 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 */
|
|
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
177
|
}
|
|
87
178
|
interface ThreadProviderProps {
|
|
88
179
|
/** The thread ID to connect to */
|
|
@@ -93,8 +184,6 @@ interface ThreadProviderProps {
|
|
|
93
184
|
preload?: boolean;
|
|
94
185
|
/** Whether to enable live updates via WebSocket (default: true) */
|
|
95
186
|
live?: boolean;
|
|
96
|
-
/** Transform messages to workblocks (default: false) */
|
|
97
|
-
useWorkblocks?: boolean;
|
|
98
187
|
/** Maximum message depth to fetch/stream (default: 0 for top-level only) */
|
|
99
188
|
depth?: number;
|
|
100
189
|
/** Whether to include silent messages (default: false) */
|
|
@@ -118,10 +207,8 @@ interface ThreadProviderProps {
|
|
|
118
207
|
* </AgentBuilderProvider>
|
|
119
208
|
* ```
|
|
120
209
|
*/
|
|
121
|
-
declare function ThreadProvider({ threadId, options, preload, live,
|
|
210
|
+
declare function ThreadProvider({ threadId, options, preload, live, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
|
|
122
211
|
/**
|
|
123
|
-
* @deprecated Use `useThread()` instead.
|
|
124
|
-
*
|
|
125
212
|
* Hook to access the thread context.
|
|
126
213
|
* Must be used within a ThreadProvider.
|
|
127
214
|
*
|
|
@@ -135,24 +222,23 @@ declare function useThreadContext(): ThreadContextValue;
|
|
|
135
222
|
declare function useThreadId(): string;
|
|
136
223
|
|
|
137
224
|
/**
|
|
138
|
-
* Hook to
|
|
225
|
+
* Hook to get messages from a thread.
|
|
139
226
|
*
|
|
140
|
-
* Must be used within a ThreadProvider.
|
|
141
|
-
*
|
|
227
|
+
* Must be used within a ThreadProvider. The thread ID and WebSocket connection
|
|
228
|
+
* are managed by the ThreadProvider, so this hook simply returns the messages.
|
|
142
229
|
*
|
|
143
|
-
* @
|
|
230
|
+
* @param options - Configuration options
|
|
231
|
+
* @returns Array of messages (raw or transformed to workblocks)
|
|
144
232
|
*
|
|
145
233
|
* @example
|
|
146
234
|
* ```tsx
|
|
147
235
|
* function ChatMessages() {
|
|
148
|
-
*
|
|
236
|
+
* // Basic usage - returns messages from context
|
|
237
|
+
* const messages = useThread()
|
|
149
238
|
*
|
|
150
239
|
* return (
|
|
151
240
|
* <div>
|
|
152
241
|
* {messages.map(msg => <Message key={msg.id} message={msg} />)}
|
|
153
|
-
* <button onClick={() => sendMessage({ role: 'user', content: 'Hello!' })}>
|
|
154
|
-
* Send
|
|
155
|
-
* </button>
|
|
156
242
|
* </div>
|
|
157
243
|
* )
|
|
158
244
|
* }
|
|
@@ -162,8 +248,14 @@ declare function useThreadId(): string;
|
|
|
162
248
|
* <ChatMessages />
|
|
163
249
|
* </ThreadProvider>
|
|
164
250
|
* ```
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```tsx
|
|
254
|
+
* // Disable workblocks transformation
|
|
255
|
+
* const messages = useThread({ useWorkblocks: false })
|
|
256
|
+
* ```
|
|
165
257
|
*/
|
|
166
|
-
declare function useThread():
|
|
258
|
+
declare function useThread(options?: UseThreadOptions): ThreadMessage[];
|
|
167
259
|
|
|
168
260
|
/**
|
|
169
261
|
* Hook to listen for custom events emitted from a thread via the stream WebSocket.
|
|
@@ -247,8 +339,6 @@ declare function onThreadEvent<T = unknown>(type: string, callback: (data: T) =>
|
|
|
247
339
|
declare function useThreadEvent<T = unknown>(type: string): T | null;
|
|
248
340
|
|
|
249
341
|
/**
|
|
250
|
-
* @deprecated Use `const { sendMessage } = useThread()` instead.
|
|
251
|
-
*
|
|
252
342
|
* Hook that returns a function to send messages to the current thread.
|
|
253
343
|
* Must be used within a ThreadProvider.
|
|
254
344
|
*
|
|
@@ -261,20 +351,23 @@ declare function useThreadEvent<T = unknown>(type: string): T | null;
|
|
|
261
351
|
*
|
|
262
352
|
* @example
|
|
263
353
|
* ```tsx
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
354
|
+
* function ChatInput() {
|
|
355
|
+
* const sendMessage = useSendMessage()
|
|
356
|
+
*
|
|
357
|
+
* const handleSubmit = async (content: string) => {
|
|
358
|
+
* await sendMessage({
|
|
359
|
+
* role: 'user',
|
|
360
|
+
* content,
|
|
361
|
+
* })
|
|
362
|
+
* }
|
|
267
363
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* await sendMessage({ role: 'user', content: 'Hello!' })
|
|
364
|
+
* return <input onSubmit={handleSubmit} />
|
|
365
|
+
* }
|
|
271
366
|
* ```
|
|
272
367
|
*/
|
|
273
368
|
declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Message>;
|
|
274
369
|
|
|
275
370
|
/**
|
|
276
|
-
* @deprecated Use `const { stopExecution } = useThread()` instead.
|
|
277
|
-
*
|
|
278
371
|
* Hook that returns a function to stop the current thread's execution.
|
|
279
372
|
* Must be used within a ThreadProvider.
|
|
280
373
|
*
|
|
@@ -287,13 +380,15 @@ declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Mess
|
|
|
287
380
|
*
|
|
288
381
|
* @example
|
|
289
382
|
* ```tsx
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* await stopExecution()
|
|
383
|
+
* function StopButton() {
|
|
384
|
+
* const stopThread = useStopThread()
|
|
293
385
|
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
386
|
+
* return (
|
|
387
|
+
* <button onClick={() => stopThread()}>
|
|
388
|
+
* Stop
|
|
389
|
+
* </button>
|
|
390
|
+
* )
|
|
391
|
+
* }
|
|
297
392
|
* ```
|
|
298
393
|
*/
|
|
299
394
|
declare function useStopThread(): () => Promise<void>;
|
|
@@ -365,4 +460,4 @@ interface StopThreadOptions {
|
|
|
365
460
|
*/
|
|
366
461
|
declare function stopThread(id: string, options?: StopThreadOptions): Promise<void>;
|
|
367
462
|
|
|
368
|
-
export { AgentBuilderProvider, type ConnectionStatus, type
|
|
463
|
+
export { type AgentBuilderConfig, AgentBuilderProvider, type ConnectionStatus, type CustomEvent, type ErrorEvent, type GetMessagesOptions, type LogDataEvent, type LogStreamEvent, type LogWebSocketCallbacks, type Message, type MessageChunkEvent, type MessageDataEvent, type MessageStreamEvent, type MessageWebSocketCallbacks, type SendMessagePayload, type StoppedByUserEvent, type Thread, type ThreadEvent, type ThreadMessage, ThreadProvider, type ThreadProviderOptions, type UseThreadOptions, type WorkItem, type WorkMessage, onThreadEvent, sendMessage, stopThread, useSendMessage, useStopThread, useThread, useThreadContext, useThreadEvent, useThreadId };
|