@standardagents/react 0.9.17 → 0.10.1-dev.114898

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 } from '@standardagents/client';
4
+ export { AgentBuilderClient, AgentBuilderConfig, AttachmentRef, CreateThreadPayload, CustomEvent, ErrorEvent, FileUploadManager, GetMessagesOptions, LogDataEvent, LogStreamEvent, LogWebSocketCallbacks, Message, MessageChunkEvent, MessageDataEvent, MessageStreamEvent, MessageWebSocketCallbacks, 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,49 @@ 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 */
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;
177
86
  }
178
87
  interface ThreadProviderProps {
179
88
  /** The thread ID to connect to */
@@ -184,6 +93,8 @@ interface ThreadProviderProps {
184
93
  preload?: boolean;
185
94
  /** Whether to enable live updates via WebSocket (default: true) */
186
95
  live?: boolean;
96
+ /** Transform messages to workblocks (default: false) */
97
+ useWorkblocks?: boolean;
187
98
  /** Maximum message depth to fetch/stream (default: 0 for top-level only) */
188
99
  depth?: number;
189
100
  /** Whether to include silent messages (default: false) */
@@ -207,8 +118,10 @@ interface ThreadProviderProps {
207
118
  * </AgentBuilderProvider>
208
119
  * ```
209
120
  */
210
- declare function ThreadProvider({ threadId, options, preload, live, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
121
+ declare function ThreadProvider({ threadId, options, preload, live, useWorkblocks, depth, includeSilent, endpoint: endpointOverride, children, }: ThreadProviderProps): react_jsx_runtime.JSX.Element;
211
122
  /**
123
+ * @deprecated Use `useThread()` instead.
124
+ *
212
125
  * Hook to access the thread context.
213
126
  * Must be used within a ThreadProvider.
214
127
  *
@@ -222,23 +135,24 @@ declare function useThreadContext(): ThreadContextValue;
222
135
  declare function useThreadId(): string;
223
136
 
224
137
  /**
225
- * Hook to get messages from a thread.
138
+ * Hook to access the thread context.
226
139
  *
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.
140
+ * Must be used within a ThreadProvider. Returns the full thread context
141
+ * including messages, actions, and file management.
229
142
  *
230
- * @param options - Configuration options
231
- * @returns Array of messages (raw or transformed to workblocks)
143
+ * @returns The thread context value
232
144
  *
233
145
  * @example
234
146
  * ```tsx
235
147
  * function ChatMessages() {
236
- * // Basic usage - returns messages from context
237
- * const messages = useThread()
148
+ * const { messages, sendMessage, files } = useThread()
238
149
  *
239
150
  * return (
240
151
  * <div>
241
152
  * {messages.map(msg => <Message key={msg.id} message={msg} />)}
153
+ * <button onClick={() => sendMessage({ role: 'user', content: 'Hello!' })}>
154
+ * Send
155
+ * </button>
242
156
  * </div>
243
157
  * )
244
158
  * }
@@ -248,14 +162,8 @@ declare function useThreadId(): string;
248
162
  * <ChatMessages />
249
163
  * </ThreadProvider>
250
164
  * ```
251
- *
252
- * @example
253
- * ```tsx
254
- * // Disable workblocks transformation
255
- * const messages = useThread({ useWorkblocks: false })
256
- * ```
257
165
  */
258
- declare function useThread(options?: UseThreadOptions): ThreadMessage[];
166
+ declare function useThread(): ThreadContextValue;
259
167
 
260
168
  /**
261
169
  * Hook to listen for custom events emitted from a thread via the stream WebSocket.
@@ -339,6 +247,8 @@ declare function onThreadEvent<T = unknown>(type: string, callback: (data: T) =>
339
247
  declare function useThreadEvent<T = unknown>(type: string): T | null;
340
248
 
341
249
  /**
250
+ * @deprecated Use `const { sendMessage } = useThread()` instead.
251
+ *
342
252
  * Hook that returns a function to send messages to the current thread.
343
253
  * Must be used within a ThreadProvider.
344
254
  *
@@ -351,23 +261,20 @@ declare function useThreadEvent<T = unknown>(type: string): T | null;
351
261
  *
352
262
  * @example
353
263
  * ```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
- * }
264
+ * // NEW - Recommended
265
+ * const { sendMessage } = useThread()
266
+ * await sendMessage({ role: 'user', content: 'Hello!' })
363
267
  *
364
- * return <input onSubmit={handleSubmit} />
365
- * }
268
+ * // OLD - Deprecated
269
+ * const sendMessage = useSendMessage()
270
+ * await sendMessage({ role: 'user', content: 'Hello!' })
366
271
  * ```
367
272
  */
368
273
  declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Message>;
369
274
 
370
275
  /**
276
+ * @deprecated Use `const { stopExecution } = useThread()` instead.
277
+ *
371
278
  * Hook that returns a function to stop the current thread's execution.
372
279
  * Must be used within a ThreadProvider.
373
280
  *
@@ -380,15 +287,13 @@ declare function useSendMessage(): (payload: SendMessagePayload) => Promise<Mess
380
287
  *
381
288
  * @example
382
289
  * ```tsx
383
- * function StopButton() {
384
- * const stopThread = useStopThread()
290
+ * // NEW - Recommended
291
+ * const { stopExecution } = useThread()
292
+ * await stopExecution()
385
293
  *
386
- * return (
387
- * <button onClick={() => stopThread()}>
388
- * Stop
389
- * </button>
390
- * )
391
- * }
294
+ * // OLD - Deprecated
295
+ * const stopThread = useStopThread()
296
+ * await stopThread()
392
297
  * ```
393
298
  */
394
299
  declare function useStopThread(): () => Promise<void>;
@@ -460,4 +365,4 @@ interface StopThreadOptions {
460
365
  */
461
366
  declare function stopThread(id: string, options?: StopThreadOptions): Promise<void>;
462
367
 
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 };
368
+ export { AgentBuilderProvider, type ConnectionStatus, type ThreadContextValue, ThreadProvider, type ThreadProviderOptions, onThreadEvent, sendMessage, stopThread, useSendMessage, useStopThread, useThread, useThreadContext, useThreadEvent, useThreadId };