(type: string, callback: (data: T) => void): void;
/**
* Hook to get the latest event data for a specific event type as React state.
* Returns the most recent event data, or null if no event has been received.
*
* Must be used within a ThreadProvider. Events are emitted from the backend
* using `emitThreadEvent(flow, 'event-type', data)`.
*
* @param type - The custom event type to filter for
* @returns The latest event data matching the specified type, or null if none received
*
* @example
* ```tsx
* function ProgressIndicator() {
* const progress = useThreadEvent<{ step: number; total: number }>('progress')
*
* if (!progress) return null
*
* return (
*
* Step {progress.step} of {progress.total}
*
* )
* }
* ```
*
* @example
* ```tsx
* function StatusDisplay() {
* const status = useThreadEvent<{ message: string }>('status')
*
* useEffect(() => {
* if (status) {
* console.log('Status updated:', status.message)
* }
* }, [status])
*
* return {status?.message ?? 'No status'}
* }
* ```
*/
declare function useThreadEvent(type: string): T | null;
/**
* @deprecated Use `const { sendMessage } = useThread()` instead.
*
* Hook that returns a function to send messages to the current thread.
* Must be used within a ThreadProvider.
*
* This hook automatically uses the thread ID from the ThreadProvider context,
* so you don't need to pass it manually.
*
* @returns A function that sends a message to the current thread
*
* @throws Error if used outside of ThreadProvider
*
* @example
* ```tsx
* // NEW - Recommended
* const { sendMessage } = useThread()
* await sendMessage({ role: 'user', content: 'Hello!' })
*
* // OLD - Deprecated
* const sendMessage = useSendMessage()
* await sendMessage({ role: 'user', content: 'Hello!' })
* ```
*/
declare function useSendMessage(): (payload: SendMessagePayload) => Promise;
/**
* @deprecated Use `const { stopExecution } = useThread()` instead.
*
* Hook that returns a function to stop the current thread's execution.
* Must be used within a ThreadProvider.
*
* This hook automatically uses the thread ID from the ThreadProvider context,
* so you don't need to pass it manually.
*
* @returns A function that stops the current thread's execution
*
* @throws Error if used outside of ThreadProvider
*
* @example
* ```tsx
* // NEW - Recommended
* const { stopExecution } = useThread()
* await stopExecution()
*
* // OLD - Deprecated
* const stopThread = useStopThread()
* await stopThread()
* ```
*/
declare function useStopThread(): () => Promise;
/**
* Send a message to a specific thread.
*
* This is a standalone function that sends messages to threads.
* It requires that an AgentBuilderProvider is mounted somewhere in your app
* to set the global endpoint configuration.
*
* @param id - The thread ID to send the message to
* @param payload - The message payload containing role, content, and optional silent flag
* @returns Promise resolving to the created message
*
* @throws Error if called before AgentBuilderProvider is mounted
*
* @example
* ```tsx
* import { sendMessage } from '@standardagents/react'
*
* await sendMessage('thread-123', {
* role: 'user',
* content: 'Hello, agent!',
* })
*
* // Send a silent message
* await sendMessage('thread-123', {
* role: 'user',
* content: 'Silent message',
* silent: true,
* })
* ```
*/
declare function sendMessage(id: string, payload: SendMessagePayload): Promise;
interface StopThreadOptions {
/**
* Override the endpoint URL for this request.
* If not provided, uses the endpoint from AgentBuilderProvider.
*/
endpoint?: string;
}
/**
* Stop execution of a thread.
*
* This is a standalone function that stops a running thread execution.
* It requires that an AgentBuilderProvider is mounted somewhere in your app
* to set the global endpoint configuration, or you can provide a custom endpoint.
*
* @param id - The thread ID to stop
* @param options - Optional configuration including custom endpoint
* @returns Promise that resolves when the thread is stopped
*
* @throws Error if called before AgentBuilderProvider is mounted and no endpoint is provided
*
* @example
* ```tsx
* import { stopThread } from '@standardagents/react'
*
* // Using global endpoint from AgentBuilderProvider
* await stopThread('thread-123')
*
* // Using custom endpoint
* await stopThread('thread-123', {
* endpoint: 'https://custom.example.com/api'
* })
* ```
*/
declare function stopThread(id: string, options?: StopThreadOptions): Promise;
export { AgentBuilderProvider, type ConnectionStatus, type ThreadContextValue, ThreadProvider, type ThreadProviderOptions, onThreadEvent, sendMessage, stopThread, useSendMessage, useStopThread, useThread, useThreadContext, useThreadEvent, useThreadId };