@ash-cloud/ash-ui 0.0.4 → 0.0.6
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.cjs +240 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +189 -4
- package/dist/index.d.ts +189 -4
- package/dist/index.js +239 -2
- package/dist/index.js.map +1 -1
- package/dist/styles-full.css +1 -0
- package/dist/styles.css +1 -1
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +87 -2
- package/dist/types.d.ts +87 -2
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.cts +1 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +6 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { NormalizedToolCall, NormalizedEntry, ToolDisplayConfig, LogEntry, ToolDisplayMode, TodoItem, ToolStatus, ActionType } from './types.cjs';
|
|
3
|
-
export { AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_DISPLAY_CONFIG, ErrorEntry, FileAttachment, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, NormalizedEntryType, SearchAction, ThinkingEntry, TodoStatus, TodoWriteAction, ToolCallEntry, ToolExecutionGroup as ToolExecutionGroupType, ToolResult, UserMessageEntry, WebFetchAction, WebSearchAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction } from './types.cjs';
|
|
2
|
+
import { NormalizedToolCall, NormalizedEntry, ToolDisplayConfig, WidgetRenderFunction, WidgetAction, LogEntry, ToolDisplayMode, TodoItem, ToolStatus, ActionType } from './types.cjs';
|
|
3
|
+
export { AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_DISPLAY_CONFIG, ErrorEntry, FileAttachment, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, NormalizedEntryType, SearchAction, ThinkingEntry, TodoStatus, TodoWriteAction, ToolCallEntry, ToolExecutionGroup as ToolExecutionGroupType, ToolResult, UserMessageEntry, WebFetchAction, WebSearchAction, WidgetEntry, WidgetRenderProps, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry } from './types.cjs';
|
|
4
4
|
import { ReactNode, DragEvent, ChangeEvent } from 'react';
|
|
5
5
|
import { ParsedOption } from './utils.cjs';
|
|
6
6
|
export { GroupedEntry, ParsedOptionsResult, ToolUseInput, cn, createToolCall, extractTextContent, extractToolCallsFromGroup, formatFileSize, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, groupEntriesForCompactMode, mapToolToActionType, normalizeToolResult, parseCommandResult, parseMcpToolName, parseOptionsFromContent, truncate, updateToolCallWithResult } from './utils.cjs';
|
|
@@ -41,6 +41,29 @@ interface MessageListProps {
|
|
|
41
41
|
displayConfig?: ToolDisplayConfig;
|
|
42
42
|
/** Callback when user selects an option from assistant message */
|
|
43
43
|
onOptionSelect?: (optionText: string) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Custom render function for widget entries.
|
|
46
|
+
* When provided, widget entries will be rendered using this function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <MessageList
|
|
51
|
+
* entries={entries}
|
|
52
|
+
* renderWidget={({ widgetType, widgetData, onAction }) => {
|
|
53
|
+
* if (widgetType === 'image-grid') {
|
|
54
|
+
* return <ImageGrid data={widgetData} onSelect={onAction} />;
|
|
55
|
+
* }
|
|
56
|
+
* return null;
|
|
57
|
+
* }}
|
|
58
|
+
* />
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
renderWidget?: WidgetRenderFunction;
|
|
62
|
+
/**
|
|
63
|
+
* Callback for widget interactions (e.g., selection, submit).
|
|
64
|
+
* Called when widgets dispatch actions via their onAction callback.
|
|
65
|
+
*/
|
|
66
|
+
onWidgetAction?: (action: WidgetAction) => void;
|
|
44
67
|
/** Additional class names */
|
|
45
68
|
className?: string;
|
|
46
69
|
}
|
|
@@ -64,7 +87,7 @@ interface MessageListProps {
|
|
|
64
87
|
* <MessageList entries={entries} displayConfig={{ mode: 'compact' }} />
|
|
65
88
|
* ```
|
|
66
89
|
*/
|
|
67
|
-
declare function MessageList({ entries, loading, streamingContent, displayConfig: displayConfigProp, onOptionSelect, className, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
90
|
+
declare function MessageList({ entries, loading, streamingContent, displayConfig: displayConfigProp, onOptionSelect, renderWidget, onWidgetAction, className, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
68
91
|
|
|
69
92
|
interface UserMessageProps {
|
|
70
93
|
entry: NormalizedEntry;
|
|
@@ -875,4 +898,166 @@ interface UseFileUploadReturn {
|
|
|
875
898
|
declare function useFileUpload({ maxFileSize, // 100MB
|
|
876
899
|
maxFiles, onValidationError, }?: UseFileUploadOptions): UseFileUploadReturn;
|
|
877
900
|
|
|
878
|
-
|
|
901
|
+
/**
|
|
902
|
+
* useAgentChat - A React hook for streaming agent conversations
|
|
903
|
+
*
|
|
904
|
+
* This hook handles all the complexity of streaming agent responses:
|
|
905
|
+
* - Real-time text streaming via text_delta events
|
|
906
|
+
* - Tool call tracking and correlation
|
|
907
|
+
* - Proper deduplication (no duplicate messages)
|
|
908
|
+
* - Seamless transition from streaming to finalized state
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```tsx
|
|
912
|
+
* import { useAgentChat } from '@ash-cloud/ash-ui';
|
|
913
|
+
* import { AgentCloudClient } from '@ash-cloud/client';
|
|
914
|
+
*
|
|
915
|
+
* const client = new AgentCloudClient({ apiKey: '...' });
|
|
916
|
+
*
|
|
917
|
+
* function Chat() {
|
|
918
|
+
* const {
|
|
919
|
+
* entries,
|
|
920
|
+
* isStreaming,
|
|
921
|
+
* error,
|
|
922
|
+
* sessionId,
|
|
923
|
+
* send,
|
|
924
|
+
* stop,
|
|
925
|
+
* } = useAgentChat({
|
|
926
|
+
* client,
|
|
927
|
+
* agentId: 'my-agent-id',
|
|
928
|
+
* });
|
|
929
|
+
*
|
|
930
|
+
* return (
|
|
931
|
+
* <div>
|
|
932
|
+
* <MessageList entries={entries} loading={isStreaming} />
|
|
933
|
+
* <input onSubmit={(e) => send(e.target.value)} />
|
|
934
|
+
* </div>
|
|
935
|
+
* );
|
|
936
|
+
* }
|
|
937
|
+
* ```
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Stream event type - matches @ash-cloud/client StreamEvent
|
|
942
|
+
* We define it here to avoid a hard dependency on the client package
|
|
943
|
+
*/
|
|
944
|
+
interface StreamEvent {
|
|
945
|
+
type: string;
|
|
946
|
+
sessionId?: string;
|
|
947
|
+
claudeSessionId?: string;
|
|
948
|
+
delta?: string;
|
|
949
|
+
text?: string;
|
|
950
|
+
toolId?: string;
|
|
951
|
+
toolName?: string;
|
|
952
|
+
input?: unknown;
|
|
953
|
+
toolResult?: unknown;
|
|
954
|
+
isError?: boolean;
|
|
955
|
+
error?: string;
|
|
956
|
+
code?: string;
|
|
957
|
+
status?: string;
|
|
958
|
+
result?: string;
|
|
959
|
+
totalCost?: number;
|
|
960
|
+
totalTokens?: number;
|
|
961
|
+
entry?: {
|
|
962
|
+
timestamp: string;
|
|
963
|
+
level: string;
|
|
964
|
+
category: string;
|
|
965
|
+
message: string;
|
|
966
|
+
data?: Record<string, unknown>;
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Async generator that yields StreamEvent objects
|
|
971
|
+
*/
|
|
972
|
+
type StreamGenerator = AsyncGenerator<StreamEvent, void, unknown>;
|
|
973
|
+
/**
|
|
974
|
+
* Function that creates a stream of events
|
|
975
|
+
* This matches the signature of client.agents.run() and client.sessions.send()
|
|
976
|
+
*/
|
|
977
|
+
type CreateStreamFn = (prompt: string, sessionId?: string) => StreamGenerator;
|
|
978
|
+
/**
|
|
979
|
+
* Options for useAgentChat
|
|
980
|
+
*/
|
|
981
|
+
interface UseAgentChatOptions {
|
|
982
|
+
/**
|
|
983
|
+
* Function to create a stream of events.
|
|
984
|
+
* Can wrap client.agents.run() or client.sessions.send()
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```tsx
|
|
988
|
+
* createStream: (prompt, sessionId) => {
|
|
989
|
+
* if (sessionId) {
|
|
990
|
+
* return client.sessions.send(sessionId, prompt);
|
|
991
|
+
* }
|
|
992
|
+
* return client.agents.run(agentId, prompt);
|
|
993
|
+
* }
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
createStream: CreateStreamFn;
|
|
997
|
+
/**
|
|
998
|
+
* Initial session ID (for resuming a conversation)
|
|
999
|
+
*/
|
|
1000
|
+
initialSessionId?: string;
|
|
1001
|
+
/**
|
|
1002
|
+
* Initial entries to display (e.g., from loading history)
|
|
1003
|
+
*/
|
|
1004
|
+
initialEntries?: NormalizedEntry[];
|
|
1005
|
+
/**
|
|
1006
|
+
* Callback when session starts
|
|
1007
|
+
*/
|
|
1008
|
+
onSessionStart?: (sessionId: string) => void;
|
|
1009
|
+
/**
|
|
1010
|
+
* Callback when session ends
|
|
1011
|
+
*/
|
|
1012
|
+
onSessionEnd?: (sessionId: string, status: string) => void;
|
|
1013
|
+
/**
|
|
1014
|
+
* Callback when an error occurs
|
|
1015
|
+
*/
|
|
1016
|
+
onError?: (error: string) => void;
|
|
1017
|
+
/**
|
|
1018
|
+
* Callback for sandbox log events
|
|
1019
|
+
*/
|
|
1020
|
+
onSandboxLog?: (entry: NonNullable<StreamEvent['entry']>) => void;
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Return type for useAgentChat
|
|
1024
|
+
*/
|
|
1025
|
+
interface UseAgentChatReturn {
|
|
1026
|
+
/**
|
|
1027
|
+
* All entries to display (history + streaming content)
|
|
1028
|
+
* This is the single source of truth for rendering
|
|
1029
|
+
*/
|
|
1030
|
+
entries: NormalizedEntry[];
|
|
1031
|
+
/**
|
|
1032
|
+
* Whether a message is currently being streamed
|
|
1033
|
+
*/
|
|
1034
|
+
isStreaming: boolean;
|
|
1035
|
+
/**
|
|
1036
|
+
* Current error message (if any)
|
|
1037
|
+
*/
|
|
1038
|
+
error: string | null;
|
|
1039
|
+
/**
|
|
1040
|
+
* Current session ID
|
|
1041
|
+
*/
|
|
1042
|
+
sessionId: string | null;
|
|
1043
|
+
/**
|
|
1044
|
+
* Send a message to the agent
|
|
1045
|
+
*/
|
|
1046
|
+
send: (prompt: string) => Promise<void>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Stop the current streaming request
|
|
1049
|
+
*/
|
|
1050
|
+
stop: () => void;
|
|
1051
|
+
/**
|
|
1052
|
+
* Clear all entries and start fresh
|
|
1053
|
+
*/
|
|
1054
|
+
clear: () => void;
|
|
1055
|
+
/**
|
|
1056
|
+
* Set entries from external source (e.g., loading from server)
|
|
1057
|
+
* This replaces all entries and clears streaming state
|
|
1058
|
+
*/
|
|
1059
|
+
setEntries: (entries: NormalizedEntry[]) => void;
|
|
1060
|
+
}
|
|
1061
|
+
declare function useAgentChat(options: UseAgentChatOptions): UseAgentChatReturn;
|
|
1062
|
+
|
|
1063
|
+
export { ActionIcon, type ActionIconProps, ActionType, type StreamEvent as AgentStreamEvent, AssistantMessage, type AssistantMessageProps, type FileAttachment as ChatFileAttachment, CodeBlock, type CodeBlockProps, CompactToolStatusLine, type CompactToolStatusLineProps, type CreateStreamFn, type DisplayModeContextType, DisplayModeProvider, type DisplayModeProviderProps, DisplayModeToggle, type DisplayModeToggleProps, EnvVarsPanel, type EnvVarsPanelProps, ErrorMessage, type ErrorMessageProps, JsonDisplay, type JsonDisplayProps, LoadingIndicator, type LoadingIndicatorProps, LogEntry, LogsPanel, type LogsPanelProps, MessageEntry, type MessageEntryProps, MessageList, type MessageListProps, NormalizedEntry, NormalizedToolCall, OptionCards, type OptionCardsProps, ParsedOption, type QueuedMessage, StatusIndicator, type StatusIndicatorProps, StepAccordion, type StepAccordionProps, type StepStatus, type StreamGenerator, StreamingText, type StreamingTextProps, type Theme, type ThemeContextType, ThemeProvider, type ThemeProviderProps, ThinkingMessage, type ThinkingMessageProps, TodoItem, TodoPanel, type TodoPanelProps, ToolCallCard, type ToolCallCardProps, ToolCallMessage, type ToolCallMessageProps, ToolDisplayConfig, ToolDisplayMode, ToolExecutionGroup, type ToolExecutionGroupProps, ToolStatus, TypewriterText, type TypewriterTextProps, type UseAgentChatOptions, type UseAgentChatReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UseStopExecutionOptions, type UseStopExecutionReturn, UserMessage, type UserMessageProps, WidgetAction, WidgetRenderFunction, useAgentChat, useDisplayConfig, useDisplayMode, useFileUpload, useMessageQueue, useStopExecution, useTheme };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { NormalizedToolCall, NormalizedEntry, ToolDisplayConfig, LogEntry, ToolDisplayMode, TodoItem, ToolStatus, ActionType } from './types.js';
|
|
3
|
-
export { AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_DISPLAY_CONFIG, ErrorEntry, FileAttachment, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, NormalizedEntryType, SearchAction, ThinkingEntry, TodoStatus, TodoWriteAction, ToolCallEntry, ToolExecutionGroup as ToolExecutionGroupType, ToolResult, UserMessageEntry, WebFetchAction, WebSearchAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction } from './types.js';
|
|
2
|
+
import { NormalizedToolCall, NormalizedEntry, ToolDisplayConfig, WidgetRenderFunction, WidgetAction, LogEntry, ToolDisplayMode, TodoItem, ToolStatus, ActionType } from './types.js';
|
|
3
|
+
export { AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_DISPLAY_CONFIG, ErrorEntry, FileAttachment, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, NormalizedEntryType, SearchAction, ThinkingEntry, TodoStatus, TodoWriteAction, ToolCallEntry, ToolExecutionGroup as ToolExecutionGroupType, ToolResult, UserMessageEntry, WebFetchAction, WebSearchAction, WidgetEntry, WidgetRenderProps, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry } from './types.js';
|
|
4
4
|
import { ReactNode, DragEvent, ChangeEvent } from 'react';
|
|
5
5
|
import { ParsedOption } from './utils.js';
|
|
6
6
|
export { GroupedEntry, ParsedOptionsResult, ToolUseInput, cn, createToolCall, extractTextContent, extractToolCallsFromGroup, formatFileSize, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, groupEntriesForCompactMode, mapToolToActionType, normalizeToolResult, parseCommandResult, parseMcpToolName, parseOptionsFromContent, truncate, updateToolCallWithResult } from './utils.js';
|
|
@@ -41,6 +41,29 @@ interface MessageListProps {
|
|
|
41
41
|
displayConfig?: ToolDisplayConfig;
|
|
42
42
|
/** Callback when user selects an option from assistant message */
|
|
43
43
|
onOptionSelect?: (optionText: string) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Custom render function for widget entries.
|
|
46
|
+
* When provided, widget entries will be rendered using this function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <MessageList
|
|
51
|
+
* entries={entries}
|
|
52
|
+
* renderWidget={({ widgetType, widgetData, onAction }) => {
|
|
53
|
+
* if (widgetType === 'image-grid') {
|
|
54
|
+
* return <ImageGrid data={widgetData} onSelect={onAction} />;
|
|
55
|
+
* }
|
|
56
|
+
* return null;
|
|
57
|
+
* }}
|
|
58
|
+
* />
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
renderWidget?: WidgetRenderFunction;
|
|
62
|
+
/**
|
|
63
|
+
* Callback for widget interactions (e.g., selection, submit).
|
|
64
|
+
* Called when widgets dispatch actions via their onAction callback.
|
|
65
|
+
*/
|
|
66
|
+
onWidgetAction?: (action: WidgetAction) => void;
|
|
44
67
|
/** Additional class names */
|
|
45
68
|
className?: string;
|
|
46
69
|
}
|
|
@@ -64,7 +87,7 @@ interface MessageListProps {
|
|
|
64
87
|
* <MessageList entries={entries} displayConfig={{ mode: 'compact' }} />
|
|
65
88
|
* ```
|
|
66
89
|
*/
|
|
67
|
-
declare function MessageList({ entries, loading, streamingContent, displayConfig: displayConfigProp, onOptionSelect, className, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
90
|
+
declare function MessageList({ entries, loading, streamingContent, displayConfig: displayConfigProp, onOptionSelect, renderWidget, onWidgetAction, className, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
68
91
|
|
|
69
92
|
interface UserMessageProps {
|
|
70
93
|
entry: NormalizedEntry;
|
|
@@ -875,4 +898,166 @@ interface UseFileUploadReturn {
|
|
|
875
898
|
declare function useFileUpload({ maxFileSize, // 100MB
|
|
876
899
|
maxFiles, onValidationError, }?: UseFileUploadOptions): UseFileUploadReturn;
|
|
877
900
|
|
|
878
|
-
|
|
901
|
+
/**
|
|
902
|
+
* useAgentChat - A React hook for streaming agent conversations
|
|
903
|
+
*
|
|
904
|
+
* This hook handles all the complexity of streaming agent responses:
|
|
905
|
+
* - Real-time text streaming via text_delta events
|
|
906
|
+
* - Tool call tracking and correlation
|
|
907
|
+
* - Proper deduplication (no duplicate messages)
|
|
908
|
+
* - Seamless transition from streaming to finalized state
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```tsx
|
|
912
|
+
* import { useAgentChat } from '@ash-cloud/ash-ui';
|
|
913
|
+
* import { AgentCloudClient } from '@ash-cloud/client';
|
|
914
|
+
*
|
|
915
|
+
* const client = new AgentCloudClient({ apiKey: '...' });
|
|
916
|
+
*
|
|
917
|
+
* function Chat() {
|
|
918
|
+
* const {
|
|
919
|
+
* entries,
|
|
920
|
+
* isStreaming,
|
|
921
|
+
* error,
|
|
922
|
+
* sessionId,
|
|
923
|
+
* send,
|
|
924
|
+
* stop,
|
|
925
|
+
* } = useAgentChat({
|
|
926
|
+
* client,
|
|
927
|
+
* agentId: 'my-agent-id',
|
|
928
|
+
* });
|
|
929
|
+
*
|
|
930
|
+
* return (
|
|
931
|
+
* <div>
|
|
932
|
+
* <MessageList entries={entries} loading={isStreaming} />
|
|
933
|
+
* <input onSubmit={(e) => send(e.target.value)} />
|
|
934
|
+
* </div>
|
|
935
|
+
* );
|
|
936
|
+
* }
|
|
937
|
+
* ```
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Stream event type - matches @ash-cloud/client StreamEvent
|
|
942
|
+
* We define it here to avoid a hard dependency on the client package
|
|
943
|
+
*/
|
|
944
|
+
interface StreamEvent {
|
|
945
|
+
type: string;
|
|
946
|
+
sessionId?: string;
|
|
947
|
+
claudeSessionId?: string;
|
|
948
|
+
delta?: string;
|
|
949
|
+
text?: string;
|
|
950
|
+
toolId?: string;
|
|
951
|
+
toolName?: string;
|
|
952
|
+
input?: unknown;
|
|
953
|
+
toolResult?: unknown;
|
|
954
|
+
isError?: boolean;
|
|
955
|
+
error?: string;
|
|
956
|
+
code?: string;
|
|
957
|
+
status?: string;
|
|
958
|
+
result?: string;
|
|
959
|
+
totalCost?: number;
|
|
960
|
+
totalTokens?: number;
|
|
961
|
+
entry?: {
|
|
962
|
+
timestamp: string;
|
|
963
|
+
level: string;
|
|
964
|
+
category: string;
|
|
965
|
+
message: string;
|
|
966
|
+
data?: Record<string, unknown>;
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Async generator that yields StreamEvent objects
|
|
971
|
+
*/
|
|
972
|
+
type StreamGenerator = AsyncGenerator<StreamEvent, void, unknown>;
|
|
973
|
+
/**
|
|
974
|
+
* Function that creates a stream of events
|
|
975
|
+
* This matches the signature of client.agents.run() and client.sessions.send()
|
|
976
|
+
*/
|
|
977
|
+
type CreateStreamFn = (prompt: string, sessionId?: string) => StreamGenerator;
|
|
978
|
+
/**
|
|
979
|
+
* Options for useAgentChat
|
|
980
|
+
*/
|
|
981
|
+
interface UseAgentChatOptions {
|
|
982
|
+
/**
|
|
983
|
+
* Function to create a stream of events.
|
|
984
|
+
* Can wrap client.agents.run() or client.sessions.send()
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```tsx
|
|
988
|
+
* createStream: (prompt, sessionId) => {
|
|
989
|
+
* if (sessionId) {
|
|
990
|
+
* return client.sessions.send(sessionId, prompt);
|
|
991
|
+
* }
|
|
992
|
+
* return client.agents.run(agentId, prompt);
|
|
993
|
+
* }
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
createStream: CreateStreamFn;
|
|
997
|
+
/**
|
|
998
|
+
* Initial session ID (for resuming a conversation)
|
|
999
|
+
*/
|
|
1000
|
+
initialSessionId?: string;
|
|
1001
|
+
/**
|
|
1002
|
+
* Initial entries to display (e.g., from loading history)
|
|
1003
|
+
*/
|
|
1004
|
+
initialEntries?: NormalizedEntry[];
|
|
1005
|
+
/**
|
|
1006
|
+
* Callback when session starts
|
|
1007
|
+
*/
|
|
1008
|
+
onSessionStart?: (sessionId: string) => void;
|
|
1009
|
+
/**
|
|
1010
|
+
* Callback when session ends
|
|
1011
|
+
*/
|
|
1012
|
+
onSessionEnd?: (sessionId: string, status: string) => void;
|
|
1013
|
+
/**
|
|
1014
|
+
* Callback when an error occurs
|
|
1015
|
+
*/
|
|
1016
|
+
onError?: (error: string) => void;
|
|
1017
|
+
/**
|
|
1018
|
+
* Callback for sandbox log events
|
|
1019
|
+
*/
|
|
1020
|
+
onSandboxLog?: (entry: NonNullable<StreamEvent['entry']>) => void;
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Return type for useAgentChat
|
|
1024
|
+
*/
|
|
1025
|
+
interface UseAgentChatReturn {
|
|
1026
|
+
/**
|
|
1027
|
+
* All entries to display (history + streaming content)
|
|
1028
|
+
* This is the single source of truth for rendering
|
|
1029
|
+
*/
|
|
1030
|
+
entries: NormalizedEntry[];
|
|
1031
|
+
/**
|
|
1032
|
+
* Whether a message is currently being streamed
|
|
1033
|
+
*/
|
|
1034
|
+
isStreaming: boolean;
|
|
1035
|
+
/**
|
|
1036
|
+
* Current error message (if any)
|
|
1037
|
+
*/
|
|
1038
|
+
error: string | null;
|
|
1039
|
+
/**
|
|
1040
|
+
* Current session ID
|
|
1041
|
+
*/
|
|
1042
|
+
sessionId: string | null;
|
|
1043
|
+
/**
|
|
1044
|
+
* Send a message to the agent
|
|
1045
|
+
*/
|
|
1046
|
+
send: (prompt: string) => Promise<void>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Stop the current streaming request
|
|
1049
|
+
*/
|
|
1050
|
+
stop: () => void;
|
|
1051
|
+
/**
|
|
1052
|
+
* Clear all entries and start fresh
|
|
1053
|
+
*/
|
|
1054
|
+
clear: () => void;
|
|
1055
|
+
/**
|
|
1056
|
+
* Set entries from external source (e.g., loading from server)
|
|
1057
|
+
* This replaces all entries and clears streaming state
|
|
1058
|
+
*/
|
|
1059
|
+
setEntries: (entries: NormalizedEntry[]) => void;
|
|
1060
|
+
}
|
|
1061
|
+
declare function useAgentChat(options: UseAgentChatOptions): UseAgentChatReturn;
|
|
1062
|
+
|
|
1063
|
+
export { ActionIcon, type ActionIconProps, ActionType, type StreamEvent as AgentStreamEvent, AssistantMessage, type AssistantMessageProps, type FileAttachment as ChatFileAttachment, CodeBlock, type CodeBlockProps, CompactToolStatusLine, type CompactToolStatusLineProps, type CreateStreamFn, type DisplayModeContextType, DisplayModeProvider, type DisplayModeProviderProps, DisplayModeToggle, type DisplayModeToggleProps, EnvVarsPanel, type EnvVarsPanelProps, ErrorMessage, type ErrorMessageProps, JsonDisplay, type JsonDisplayProps, LoadingIndicator, type LoadingIndicatorProps, LogEntry, LogsPanel, type LogsPanelProps, MessageEntry, type MessageEntryProps, MessageList, type MessageListProps, NormalizedEntry, NormalizedToolCall, OptionCards, type OptionCardsProps, ParsedOption, type QueuedMessage, StatusIndicator, type StatusIndicatorProps, StepAccordion, type StepAccordionProps, type StepStatus, type StreamGenerator, StreamingText, type StreamingTextProps, type Theme, type ThemeContextType, ThemeProvider, type ThemeProviderProps, ThinkingMessage, type ThinkingMessageProps, TodoItem, TodoPanel, type TodoPanelProps, ToolCallCard, type ToolCallCardProps, ToolCallMessage, type ToolCallMessageProps, ToolDisplayConfig, ToolDisplayMode, ToolExecutionGroup, type ToolExecutionGroupProps, ToolStatus, TypewriterText, type TypewriterTextProps, type UseAgentChatOptions, type UseAgentChatReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UseStopExecutionOptions, type UseStopExecutionReturn, UserMessage, type UserMessageProps, WidgetAction, WidgetRenderFunction, useAgentChat, useDisplayConfig, useDisplayMode, useFileUpload, useMessageQueue, useStopExecution, useTheme };
|