@ash-cloud/ash-ui 0.0.5 → 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 +207 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +163 -1
- package/dist/index.d.ts +163 -1
- package/dist/index.js +207 -1
- package/dist/index.js.map +1 -1
- package/dist/styles-full.css +1 -0
- package/dist/styles.css +1 -1
- package/package.json +6 -3
package/dist/index.d.cts
CHANGED
|
@@ -898,4 +898,166 @@ interface UseFileUploadReturn {
|
|
|
898
898
|
declare function useFileUpload({ maxFileSize, // 100MB
|
|
899
899
|
maxFiles, onValidationError, }?: UseFileUploadOptions): UseFileUploadReturn;
|
|
900
900
|
|
|
901
|
-
|
|
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
|
@@ -898,4 +898,166 @@ interface UseFileUploadReturn {
|
|
|
898
898
|
declare function useFileUpload({ maxFileSize, // 100MB
|
|
899
899
|
maxFiles, onValidationError, }?: UseFileUploadOptions): UseFileUploadReturn;
|
|
900
900
|
|
|
901
|
-
|
|
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.js
CHANGED
|
@@ -2967,7 +2967,213 @@ function useFileUpload({
|
|
|
2967
2967
|
openFilePicker
|
|
2968
2968
|
};
|
|
2969
2969
|
}
|
|
2970
|
+
function useAgentChat(options) {
|
|
2971
|
+
const {
|
|
2972
|
+
createStream,
|
|
2973
|
+
initialSessionId,
|
|
2974
|
+
initialEntries = [],
|
|
2975
|
+
onSessionStart,
|
|
2976
|
+
onSessionEnd,
|
|
2977
|
+
onError,
|
|
2978
|
+
onSandboxLog
|
|
2979
|
+
} = options;
|
|
2980
|
+
const [historyEntries, setHistoryEntries] = useState(initialEntries);
|
|
2981
|
+
const [streamingEntries, setStreamingEntries] = useState([]);
|
|
2982
|
+
const [isStreaming, setIsStreaming] = useState(false);
|
|
2983
|
+
const [error, setError] = useState(null);
|
|
2984
|
+
const [sessionId, setSessionId] = useState(initialSessionId || null);
|
|
2985
|
+
const abortControllerRef = useRef(null);
|
|
2986
|
+
const currentTextRef = useRef("");
|
|
2987
|
+
const currentTextIdRef = useRef(null);
|
|
2988
|
+
const pendingToolCallsRef = useRef(/* @__PURE__ */ new Map());
|
|
2989
|
+
const hadToolCallSinceTextRef = useRef(false);
|
|
2990
|
+
const entries = [...historyEntries, ...streamingEntries];
|
|
2991
|
+
const emitStreamingEntries = useCallback((newEntries) => {
|
|
2992
|
+
setStreamingEntries([...newEntries]);
|
|
2993
|
+
}, []);
|
|
2994
|
+
const createTextEntry = useCallback((id, content) => ({
|
|
2995
|
+
id,
|
|
2996
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2997
|
+
entryType: { type: "assistant_message" },
|
|
2998
|
+
content
|
|
2999
|
+
}), []);
|
|
3000
|
+
const resetStreamingState = useCallback(() => {
|
|
3001
|
+
currentTextRef.current = "";
|
|
3002
|
+
currentTextIdRef.current = null;
|
|
3003
|
+
pendingToolCallsRef.current.clear();
|
|
3004
|
+
hadToolCallSinceTextRef.current = false;
|
|
3005
|
+
setStreamingEntries([]);
|
|
3006
|
+
}, []);
|
|
3007
|
+
const processEvent = useCallback((event, streamEntries) => {
|
|
3008
|
+
const newEntries = [...streamEntries];
|
|
3009
|
+
switch (event.type) {
|
|
3010
|
+
case "session_start":
|
|
3011
|
+
if (event.sessionId) {
|
|
3012
|
+
setSessionId(event.sessionId);
|
|
3013
|
+
onSessionStart?.(event.sessionId);
|
|
3014
|
+
}
|
|
3015
|
+
break;
|
|
3016
|
+
case "text_delta":
|
|
3017
|
+
if (event.delta) {
|
|
3018
|
+
if (hadToolCallSinceTextRef.current && currentTextIdRef.current) {
|
|
3019
|
+
currentTextRef.current = "";
|
|
3020
|
+
currentTextIdRef.current = null;
|
|
3021
|
+
hadToolCallSinceTextRef.current = false;
|
|
3022
|
+
}
|
|
3023
|
+
currentTextRef.current += event.delta;
|
|
3024
|
+
if (!currentTextIdRef.current) {
|
|
3025
|
+
currentTextIdRef.current = `text-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
3026
|
+
newEntries.push(createTextEntry(currentTextIdRef.current, currentTextRef.current));
|
|
3027
|
+
} else {
|
|
3028
|
+
const entryIndex = newEntries.findIndex((e) => e.id === currentTextIdRef.current);
|
|
3029
|
+
if (entryIndex !== -1) {
|
|
3030
|
+
newEntries[entryIndex] = createTextEntry(currentTextIdRef.current, currentTextRef.current);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
break;
|
|
3035
|
+
case "tool_use":
|
|
3036
|
+
if (event.toolId && event.toolName) {
|
|
3037
|
+
currentTextRef.current = "";
|
|
3038
|
+
currentTextIdRef.current = null;
|
|
3039
|
+
hadToolCallSinceTextRef.current = true;
|
|
3040
|
+
const toolCall = createToolCall({
|
|
3041
|
+
id: event.toolId,
|
|
3042
|
+
name: event.toolName,
|
|
3043
|
+
input: event.input
|
|
3044
|
+
});
|
|
3045
|
+
const entry = {
|
|
3046
|
+
id: event.toolId,
|
|
3047
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3048
|
+
entryType: { type: "tool_call", toolCall },
|
|
3049
|
+
content: toolCall.summary
|
|
3050
|
+
};
|
|
3051
|
+
const entryIndex = newEntries.length;
|
|
3052
|
+
newEntries.push(entry);
|
|
3053
|
+
pendingToolCallsRef.current.set(event.toolId, { entryIndex, toolCall });
|
|
3054
|
+
}
|
|
3055
|
+
break;
|
|
3056
|
+
case "tool_result":
|
|
3057
|
+
if (event.toolId) {
|
|
3058
|
+
const pending = pendingToolCallsRef.current.get(event.toolId);
|
|
3059
|
+
if (pending) {
|
|
3060
|
+
const updatedToolCall = updateToolCallWithResult(
|
|
3061
|
+
pending.toolCall,
|
|
3062
|
+
event.toolResult,
|
|
3063
|
+
event.isError
|
|
3064
|
+
);
|
|
3065
|
+
const existingEntry = newEntries[pending.entryIndex];
|
|
3066
|
+
if (existingEntry && existingEntry.entryType.type === "tool_call") {
|
|
3067
|
+
newEntries[pending.entryIndex] = {
|
|
3068
|
+
...existingEntry,
|
|
3069
|
+
entryType: { type: "tool_call", toolCall: updatedToolCall }
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
pendingToolCallsRef.current.delete(event.toolId);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
break;
|
|
3076
|
+
case "sandbox_log":
|
|
3077
|
+
if (event.entry) {
|
|
3078
|
+
onSandboxLog?.(event.entry);
|
|
3079
|
+
}
|
|
3080
|
+
break;
|
|
3081
|
+
case "error":
|
|
3082
|
+
if (event.error) {
|
|
3083
|
+
setError(event.error);
|
|
3084
|
+
onError?.(event.error);
|
|
3085
|
+
newEntries.push({
|
|
3086
|
+
id: `error-${Date.now()}`,
|
|
3087
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3088
|
+
entryType: { type: "error", message: event.error, code: event.code },
|
|
3089
|
+
content: event.error
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
break;
|
|
3093
|
+
case "session_end":
|
|
3094
|
+
onSessionEnd?.(event.sessionId || sessionId || "", event.status || "completed");
|
|
3095
|
+
break;
|
|
3096
|
+
case "complete":
|
|
3097
|
+
if (newEntries.length > 0) {
|
|
3098
|
+
setHistoryEntries((prev) => [...prev, ...newEntries]);
|
|
3099
|
+
}
|
|
3100
|
+
resetStreamingState();
|
|
3101
|
+
return [];
|
|
3102
|
+
}
|
|
3103
|
+
return newEntries;
|
|
3104
|
+
}, [sessionId, onSessionStart, onSessionEnd, onError, onSandboxLog, createTextEntry, resetStreamingState]);
|
|
3105
|
+
const send = useCallback(async (prompt) => {
|
|
3106
|
+
if (isStreaming) return;
|
|
3107
|
+
setIsStreaming(true);
|
|
3108
|
+
setError(null);
|
|
3109
|
+
const userEntry = {
|
|
3110
|
+
id: `user-${Date.now()}`,
|
|
3111
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3112
|
+
entryType: { type: "user_message" },
|
|
3113
|
+
content: prompt
|
|
3114
|
+
};
|
|
3115
|
+
setHistoryEntries((prev) => [...prev, userEntry]);
|
|
3116
|
+
resetStreamingState();
|
|
3117
|
+
const controller = new AbortController();
|
|
3118
|
+
abortControllerRef.current = controller;
|
|
3119
|
+
let localStreamingEntries = [];
|
|
3120
|
+
try {
|
|
3121
|
+
const stream = createStream(prompt, sessionId || void 0);
|
|
3122
|
+
for await (const event of stream) {
|
|
3123
|
+
if (controller.signal.aborted) break;
|
|
3124
|
+
localStreamingEntries = processEvent(event, localStreamingEntries);
|
|
3125
|
+
emitStreamingEntries(localStreamingEntries);
|
|
3126
|
+
}
|
|
3127
|
+
if (localStreamingEntries.length > 0) {
|
|
3128
|
+
setHistoryEntries((prev) => [...prev, ...localStreamingEntries]);
|
|
3129
|
+
setStreamingEntries([]);
|
|
3130
|
+
}
|
|
3131
|
+
} catch (err) {
|
|
3132
|
+
if (err.name !== "AbortError") {
|
|
3133
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
3134
|
+
setError(errorMessage);
|
|
3135
|
+
onError?.(errorMessage);
|
|
3136
|
+
}
|
|
3137
|
+
} finally {
|
|
3138
|
+
setIsStreaming(false);
|
|
3139
|
+
abortControllerRef.current = null;
|
|
3140
|
+
resetStreamingState();
|
|
3141
|
+
}
|
|
3142
|
+
}, [isStreaming, sessionId, createStream, processEvent, emitStreamingEntries, resetStreamingState, onError]);
|
|
3143
|
+
const stop = useCallback(() => {
|
|
3144
|
+
if (abortControllerRef.current) {
|
|
3145
|
+
abortControllerRef.current.abort();
|
|
3146
|
+
}
|
|
3147
|
+
}, []);
|
|
3148
|
+
const clear = useCallback(() => {
|
|
3149
|
+
setHistoryEntries([]);
|
|
3150
|
+
resetStreamingState();
|
|
3151
|
+
setSessionId(initialSessionId || null);
|
|
3152
|
+
setError(null);
|
|
3153
|
+
}, [initialSessionId, resetStreamingState]);
|
|
3154
|
+
const setEntries = useCallback((newEntries) => {
|
|
3155
|
+
resetStreamingState();
|
|
3156
|
+
setHistoryEntries(newEntries);
|
|
3157
|
+
}, [resetStreamingState]);
|
|
3158
|
+
useEffect(() => {
|
|
3159
|
+
return () => {
|
|
3160
|
+
if (abortControllerRef.current) {
|
|
3161
|
+
abortControllerRef.current.abort();
|
|
3162
|
+
}
|
|
3163
|
+
};
|
|
3164
|
+
}, []);
|
|
3165
|
+
return {
|
|
3166
|
+
entries,
|
|
3167
|
+
isStreaming,
|
|
3168
|
+
error,
|
|
3169
|
+
sessionId,
|
|
3170
|
+
send,
|
|
3171
|
+
stop,
|
|
3172
|
+
clear,
|
|
3173
|
+
setEntries
|
|
3174
|
+
};
|
|
3175
|
+
}
|
|
2970
3176
|
|
|
2971
|
-
export { ActionIcon, AlertCircleIcon, AlertTriangleIcon, AssistantMessage, BotIcon, BrainIcon, BugIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleIcon, ClipboardListIcon, CodeBlock, CodeIcon, CompactToolStatusLine, CopyIcon, DEFAULT_DISPLAY_CONFIG, DisplayModeProvider, DisplayModeToggle, EditIcon, EnvVarsPanel, ErrorIcon, ErrorMessage, FileIcon, FilePlusIcon, FolderSearchIcon, GlobeIcon, InfoIcon, JsonDisplay, ListChecksIcon, LoaderIcon, LoadingIndicator, LogsPanel, MessageEntry, MessageList, MessageSquareIcon, MoonIcon, OptionCards, PaperclipIcon, PlugIcon, SearchIcon, SendIcon, SparklesIcon, SpinnerIcon, StatusIndicator, StepAccordion, StopCircleIcon, StreamingText, SunIcon, TerminalIcon, ThemeProvider, ThinkingMessage, TodoPanel, ToolCallCard, ToolCallMessage, ToolExecutionGroup, ToolIcon, TypewriterText, UserIcon, UserMessage, XCircleIcon, XIcon, allKeyframesCss, borderRadius, cn, colors, createToolCall, extractTextContent, extractToolCallsFromGroup, formatFileSize, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, groupEntriesForCompactMode, inlineStyles, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, keyframes, keyframesCss, mapToolToActionType, normalizeToolResult, parseCommandResult, parseMcpToolName, parseOptionsFromContent, shadows, spacing, tokensToCssVariables, transitions, truncate, typography, updateToolCallWithResult, useDisplayConfig, useDisplayMode, useFileUpload, useMessageQueue, useStopExecution, useTheme, widget, zIndex };
|
|
3177
|
+
export { ActionIcon, AlertCircleIcon, AlertTriangleIcon, AssistantMessage, BotIcon, BrainIcon, BugIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleIcon, ClipboardListIcon, CodeBlock, CodeIcon, CompactToolStatusLine, CopyIcon, DEFAULT_DISPLAY_CONFIG, DisplayModeProvider, DisplayModeToggle, EditIcon, EnvVarsPanel, ErrorIcon, ErrorMessage, FileIcon, FilePlusIcon, FolderSearchIcon, GlobeIcon, InfoIcon, JsonDisplay, ListChecksIcon, LoaderIcon, LoadingIndicator, LogsPanel, MessageEntry, MessageList, MessageSquareIcon, MoonIcon, OptionCards, PaperclipIcon, PlugIcon, SearchIcon, SendIcon, SparklesIcon, SpinnerIcon, StatusIndicator, StepAccordion, StopCircleIcon, StreamingText, SunIcon, TerminalIcon, ThemeProvider, ThinkingMessage, TodoPanel, ToolCallCard, ToolCallMessage, ToolExecutionGroup, ToolIcon, TypewriterText, UserIcon, UserMessage, XCircleIcon, XIcon, allKeyframesCss, borderRadius, cn, colors, createToolCall, extractTextContent, extractToolCallsFromGroup, formatFileSize, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, groupEntriesForCompactMode, inlineStyles, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, keyframes, keyframesCss, mapToolToActionType, normalizeToolResult, parseCommandResult, parseMcpToolName, parseOptionsFromContent, shadows, spacing, tokensToCssVariables, transitions, truncate, typography, updateToolCallWithResult, useAgentChat, useDisplayConfig, useDisplayMode, useFileUpload, useMessageQueue, useStopExecution, useTheme, widget, zIndex };
|
|
2972
3178
|
//# sourceMappingURL=index.js.map
|
|
2973
3179
|
//# sourceMappingURL=index.js.map
|