@standardagents/react 0.10.1-next.bbd142a → 0.11.0-next.99fb790

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.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
- 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
- }
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,59 @@ type EventListener<T = unknown> = (data: T) => void;
155
40
  /**
156
41
  * WebSocket connection status
157
42
  */
158
- type ConnectionStatus = 'connecting' | 'connected' | 'disconnected';
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
- /** Whether messages are currently loading */
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
- /** Subscribe to a specific event type */
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
+ /** Delete a message from the thread (optimistically removes from UI) */
75
+ deleteMessage: (messageId: string) => Promise<void>;
76
+ /** All files in the thread (pending uploads + committed from messages) */
77
+ files: ThreadFile[];
78
+ /** Add files and start uploading immediately to filesystem */
79
+ addFiles: (files: File[] | FileList) => void;
80
+ /** Remove a pending file (cannot remove committed files) */
81
+ removeFile: (id: string) => void;
82
+ /** Get the full URL for a file */
83
+ getFileUrl: (file: ThreadFile) => string;
84
+ /** Get the thumbnail URL for an image file */
85
+ getThumbnailUrl: (file: ThreadFile) => string;
86
+ /** Get preview URL - localPreviewUrl for pending images, thumbnail for committed */
87
+ getPreviewUrl: (file: ThreadFile) => string | null;
88
+ /** Pending attachments to be sent with next message */
89
+ attachments: PendingAttachment[];
90
+ /** Add attachment(s) to be sent with next message (no upload, stored locally) */
91
+ addAttachment: (files: File | File[] | FileList) => void;
92
+ /** Remove a pending attachment */
93
+ removeAttachment: (id: string) => void;
94
+ /** Clear all pending attachments */
95
+ clearAttachments: () => void;
177
96
  }
178
97
  interface ThreadProviderProps {
179
98
  /** The thread ID to connect to */
@@ -184,6 +103,8 @@ interface ThreadProviderProps {
184
103
  preload?: boolean;
185
104
  /** Whether to enable live updates via WebSocket (default: true) */
186
105
  live?: boolean;
106
+ /** Transform messages to workblocks (default: false) */
107
+ useWorkblocks?: boolean;
187
108
  /** Maximum message depth to fetch/stream (default: 0 for top-level only) */
188
109
  depth?: number;
189
110
  /** Whether to include silent messages (default: false) */
@@ -207,8 +128,10 @@ interface ThreadProviderProps {
207
128
  * </AgentBuilderProvider>
208
129
  * ```
209
130
  */
210
- declare function ThreadProvider({ threadId, options, preload, live, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
131
+ declare function ThreadProvider({ threadId, options, preload, live, useWorkblocks, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
211
132
  /**
133
+ * @deprecated Use `useThread()` instead.
134
+ *
212
135
  * Hook to access the thread context.
213
136
  * Must be used within a ThreadProvider.
214
137
  *
@@ -222,23 +145,24 @@ declare function useThreadContext(): ThreadContextValue;
222
145
  declare function useThreadId(): string;
223
146
 
224
147
  /**
225
- * Hook to get messages from a thread.
148
+ * Hook to access the thread context.
226
149
  *
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.
150
+ * Must be used within a ThreadProvider. Returns the full thread context
151
+ * including messages, actions, and file management.
229
152
  *
230
- * @param options - Configuration options
231
- * @returns Array of messages (raw or transformed to workblocks)
153
+ * @returns The thread context value
232
154
  *
233
155
  * @example
234
156
  * ```tsx
235
157
  * function ChatMessages() {
236
- * // Basic usage - returns messages from context
237
- * const messages = useThread()
158
+ * const { messages, sendMessage, files } = useThread()
238
159
  *
239
160
  * return (
240
161
  * <div>
241
162
  * {messages.map(msg => <Message key={msg.id} message={msg} />)}
163
+ * <button onClick={() => sendMessage({ role: 'user', content: 'Hello!' })}>
164
+ * Send
165
+ * </button>
242
166
  * </div>
243
167
  * )
244
168
  * }
@@ -248,14 +172,8 @@ declare function useThreadId(): string;
248
172
  * <ChatMessages />
249
173
  * </ThreadProvider>
250
174
  * ```
251
- *
252
- * @example
253
- * ```tsx
254
- * // Disable workblocks transformation
255
- * const messages = useThread({ useWorkblocks: false })
256
- * ```
257
175
  */
258
- declare function useThread(options?: UseThreadOptions): ThreadMessage[];
176
+ declare function useThread(): ThreadContextValue;
259
177
 
260
178
  /**
261
179
  * Hook to listen for custom events emitted from a thread via the stream WebSocket.
@@ -339,6 +257,8 @@ declare function onThreadEvent<T = unknown>(type: string, callback: (data: T) =>
339
257
  declare function useThreadEvent<T = unknown>(type: string): T | null;
340
258
 
341
259
  /**
260
+ * @deprecated Use `const { sendMessage } = useThread()` instead.
261
+ *
342
262
  * Hook that returns a function to send messages to the current thread.
343
263
  * Must be used within a ThreadProvider.
344
264
  *
@@ -351,23 +271,20 @@ declare function useThreadEvent<T = unknown>(type: string): T | null;
351
271
  *
352
272
  * @example
353
273
  * ```tsx
354
- * function ChatInput() {
355
- * const sendMessage = useSendMessage()
356
- *
357
- * const handleSubmit = async (content: string) => {
358
- * await sendMessage({
359
- * role: 'user',
360
- * content,
361
- * })
362
- * }
274
+ * // NEW - Recommended
275
+ * const { sendMessage } = useThread()
276
+ * await sendMessage({ role: 'user', content: 'Hello!' })
363
277
  *
364
- * return <input onSubmit={handleSubmit} />
365
- * }
278
+ * // OLD - Deprecated
279
+ * const sendMessage = useSendMessage()
280
+ * await sendMessage({ role: 'user', content: 'Hello!' })
366
281
  * ```
367
282
  */
368
283
  declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Message>;
369
284
 
370
285
  /**
286
+ * @deprecated Use `const { stopExecution } = useThread()` instead.
287
+ *
371
288
  * Hook that returns a function to stop the current thread's execution.
372
289
  * Must be used within a ThreadProvider.
373
290
  *
@@ -380,15 +297,13 @@ declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Mess
380
297
  *
381
298
  * @example
382
299
  * ```tsx
383
- * function StopButton() {
384
- * const stopThread = useStopThread()
300
+ * // NEW - Recommended
301
+ * const { stopExecution } = useThread()
302
+ * await stopExecution()
385
303
  *
386
- * return (
387
- * <button onClick={() => stopThread()}>
388
- * Stop
389
- * </button>
390
- * )
391
- * }
304
+ * // OLD - Deprecated
305
+ * const stopThread = useStopThread()
306
+ * await stopThread()
392
307
  * ```
393
308
  */
394
309
  declare function useStopThread(): () => Promise<void>;
@@ -460,4 +375,4 @@ interface StopThreadOptions {
460
375
  */
461
376
  declare function stopThread(id: string, options?: StopThreadOptions): Promise<void>;
462
377
 
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 };
378
+ export { AgentBuilderProvider, type ConnectionStatus, type ThreadContextValue, ThreadProvider, type ThreadProviderOptions, onThreadEvent, sendMessage, stopThread, useSendMessage, useStopThread, useThread, useThreadContext, useThreadEvent, useThreadId };