@ash-cloud/ash-ui 0.2.4 → 0.2.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 +209 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +206 -14
- package/dist/index.js.map +1 -1
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/types.cjs +5 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +26 -2
- package/dist/types.d.ts +26 -2
- package/dist/types.js +5 -2
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React$1, { ReactNode, ComponentType, DragEvent, ChangeEvent, ClipboardEvent } from 'react';
|
|
3
|
-
import { ToolInvocation, RichContent, MarkdownComponents, MentionProps, TodoStatus, TodoItem, FileAttachment as FileAttachment$2, LogEntry, ToolStatus, ActionType, NormalizedEntry, Message as Message$1 } from './types.cjs';
|
|
4
|
-
export { MessageAttachment as AIMessageAttachment, AIMessageRole, AgentToolAction, AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_STYLE_CONFIG, ErrorEntry, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, MessageMetadata, MessageStyleConfig, MessageVariant, NormalizedEntryType, NormalizedToolCall, RenderMetadataFunction, RichContentSegment, RichMentionSegment, RichTextSegment, SearchAction, ThinkingEntry, TodoWriteAction, ToolCallEntry, ToolInvocationState, ToolResult, TypographyScale, UserMessageEntry, WebFetchAction, WebSearchAction, WidgetAction, WidgetEntry, WidgetRenderFunction, WidgetRenderProps, isAgentToolAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, messageToNormalizedEntry, messagesToNormalizedEntries, normalizedEntriesToMessages, normalizedEntryToMessage } from './types.cjs';
|
|
3
|
+
import { ToolInvocation, RichContent, MarkdownComponents, MentionProps, ChatDisplayMode, ToolDescriptionMap, TodoStatus, TodoItem, FileAttachment as FileAttachment$2, LogEntry, ToolStatus, ActionType, NormalizedEntry, Message as Message$1 } from './types.cjs';
|
|
4
|
+
export { MessageAttachment as AIMessageAttachment, AIMessageRole, AgentToolAction, AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_STYLE_CONFIG, ErrorEntry, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, MessageMetadata, MessageStyleConfig, MessageVariant, NormalizedEntryType, NormalizedToolCall, RenderMetadataFunction, RichContentSegment, RichMentionSegment, RichTextSegment, SearchAction, SystemMessageEntry, ThinkingEntry, TodoWriteAction, ToolCallEntry, ToolInvocationState, ToolResult, TypographyScale, UserMessageEntry, WebFetchAction, WebSearchAction, WidgetAction, WidgetEntry, WidgetRenderFunction, WidgetRenderProps, isAgentToolAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isSystemMessage, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, messageToNormalizedEntry, messagesToNormalizedEntries, normalizedEntriesToMessages, normalizedEntryToMessage } from './types.cjs';
|
|
5
5
|
import { ParsedOption } from './utils.cjs';
|
|
6
6
|
export { ParsedOptionsResult, ToolUseInput, cn, createToolCall, extractTextContent, formatElapsedTime, formatFileSize, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, mapToolToActionType, normalizeToolResult, parseCommandResult, parseMcpToolName, parseOptionsFromContent, truncate, updateToolCallWithResult } from './utils.cjs';
|
|
7
7
|
export { AlertCircleIcon, AlertTriangleIcon, ArrowUpIcon, BotIcon, BrainIcon, BugIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleIcon, ClipboardListIcon, ClockIcon, CodeIcon, CopyIcon, EditIcon, ErrorIcon, FileIcon, FilePlusIcon, FolderSearchIcon, GlobeIcon, HomeIcon, IconProps, InfoIcon, ListChecksIcon, LoaderIcon, MessageSquareIcon, MicrophoneIcon, MoonIcon, PaperclipIcon, PlugIcon, SearchIcon, SendIcon, SparklesIcon, SpinnerIcon, StopCircleIcon, SunIcon, TerminalIcon, ToolIcon, UserIcon, XCircleIcon, XIcon } from './icons.cjs';
|
|
@@ -232,6 +232,38 @@ interface ToolListProps {
|
|
|
232
232
|
}
|
|
233
233
|
declare function ToolList({ toolInvocations, className, defaultExpanded, variant, }: ToolListProps): react_jsx_runtime.JSX.Element | null;
|
|
234
234
|
|
|
235
|
+
interface ChatDisplayModeContextValue {
|
|
236
|
+
/** Current display mode */
|
|
237
|
+
mode: ChatDisplayMode;
|
|
238
|
+
/** Toggle between user and debug */
|
|
239
|
+
toggleMode: () => void;
|
|
240
|
+
/** Set mode directly */
|
|
241
|
+
setMode: (mode: ChatDisplayMode) => void;
|
|
242
|
+
/** Consumer-provided user-friendly tool descriptions */
|
|
243
|
+
toolDescriptions: ToolDescriptionMap;
|
|
244
|
+
/** Get user-friendly description for a tool call */
|
|
245
|
+
getUserDescription: (toolName: string, input?: unknown) => string | null;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Access the current chat display mode context.
|
|
249
|
+
* Returns a graceful fallback to 'debug' mode if no provider exists.
|
|
250
|
+
*/
|
|
251
|
+
declare function useChatDisplayMode(): ChatDisplayModeContextValue;
|
|
252
|
+
interface ChatDisplayModeProviderProps {
|
|
253
|
+
children: ReactNode;
|
|
254
|
+
/** Initial mode (default: 'user') */
|
|
255
|
+
defaultMode?: ChatDisplayMode;
|
|
256
|
+
/** localStorage key for persisting preference (default: 'ash-display-mode') */
|
|
257
|
+
storageKey?: string;
|
|
258
|
+
/** Consumer-provided user-friendly tool descriptions */
|
|
259
|
+
toolDescriptions?: ToolDescriptionMap;
|
|
260
|
+
}
|
|
261
|
+
declare function ChatDisplayModeProvider({ children, defaultMode, storageKey, toolDescriptions, }: ChatDisplayModeProviderProps): react_jsx_runtime.JSX.Element;
|
|
262
|
+
interface DisplayModeToggleProps {
|
|
263
|
+
className?: string;
|
|
264
|
+
}
|
|
265
|
+
declare function DisplayModeToggle({ className }: DisplayModeToggleProps): react_jsx_runtime.JSX.Element;
|
|
266
|
+
|
|
235
267
|
interface ReasoningContextValue {
|
|
236
268
|
/** Whether the reasoning panel is open */
|
|
237
269
|
isOpen: boolean;
|
|
@@ -1059,6 +1091,7 @@ interface StreamEvent {
|
|
|
1059
1091
|
text?: string;
|
|
1060
1092
|
/** Message content array (for 'message' events) */
|
|
1061
1093
|
content?: unknown;
|
|
1094
|
+
requestId?: string;
|
|
1062
1095
|
toolId?: string;
|
|
1063
1096
|
toolName?: string;
|
|
1064
1097
|
input?: unknown;
|
|
@@ -1071,6 +1104,8 @@ interface StreamEvent {
|
|
|
1071
1104
|
result?: string;
|
|
1072
1105
|
totalCost?: number;
|
|
1073
1106
|
totalTokens?: number;
|
|
1107
|
+
stop_reason?: string;
|
|
1108
|
+
stop_sequence?: string;
|
|
1074
1109
|
/** SSE event ID (sequence number from relay) for reconnection */
|
|
1075
1110
|
id?: string;
|
|
1076
1111
|
entry?: {
|
|
@@ -1081,6 +1116,12 @@ interface StreamEvent {
|
|
|
1081
1116
|
data?: Record<string, unknown>;
|
|
1082
1117
|
};
|
|
1083
1118
|
}
|
|
1119
|
+
interface ToolPermissionRequest {
|
|
1120
|
+
requestId: string;
|
|
1121
|
+
sessionId: string;
|
|
1122
|
+
toolName: string;
|
|
1123
|
+
input?: unknown;
|
|
1124
|
+
}
|
|
1084
1125
|
/**
|
|
1085
1126
|
* Async generator that yields StreamEvent objects
|
|
1086
1127
|
*/
|
|
@@ -1095,6 +1136,8 @@ interface CreateStreamOptions {
|
|
|
1095
1136
|
metadata?: Record<string, unknown>;
|
|
1096
1137
|
/** Session context from onBeforeSend/middleware */
|
|
1097
1138
|
sessionContext?: string;
|
|
1139
|
+
/** Message role. When 'system', the message is stored as a system message. */
|
|
1140
|
+
role?: 'user' | 'system';
|
|
1098
1141
|
}
|
|
1099
1142
|
/**
|
|
1100
1143
|
* Function that creates a stream of events
|
|
@@ -1204,6 +1247,15 @@ interface UseAgentChatOptions {
|
|
|
1204
1247
|
* Callback for sandbox log events
|
|
1205
1248
|
*/
|
|
1206
1249
|
onSandboxLog?: (entry: NonNullable<StreamEvent['entry']>) => void;
|
|
1250
|
+
/**
|
|
1251
|
+
* Callback to approve/deny tool usage requests.
|
|
1252
|
+
* When provided, tool permission events will be resolved automatically.
|
|
1253
|
+
*/
|
|
1254
|
+
canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Function to resolve a tool permission request (sends the decision to the server).
|
|
1257
|
+
*/
|
|
1258
|
+
resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
|
|
1207
1259
|
/**
|
|
1208
1260
|
* Callback when reconnection is attempted
|
|
1209
1261
|
*/
|
|
@@ -1296,9 +1348,15 @@ interface UseAgentChatReturn {
|
|
|
1296
1348
|
*/
|
|
1297
1349
|
sessionId: string | null;
|
|
1298
1350
|
/**
|
|
1299
|
-
* Send a message to the agent
|
|
1351
|
+
* Send a message to the agent.
|
|
1352
|
+
* @param prompt - The message text
|
|
1353
|
+
* @param options - Optional send options
|
|
1354
|
+
* @param options.role - Message role. Defaults to 'user'. Use 'system' to send
|
|
1355
|
+
* without creating a user entry (for context injections, auto-notifications).
|
|
1300
1356
|
*/
|
|
1301
|
-
send: (prompt: string
|
|
1357
|
+
send: (prompt: string, options?: {
|
|
1358
|
+
role?: 'user' | 'system';
|
|
1359
|
+
}) => Promise<void>;
|
|
1302
1360
|
/**
|
|
1303
1361
|
* Stop the current streaming request
|
|
1304
1362
|
*/
|
|
@@ -1409,6 +1467,15 @@ interface UseChatOptions {
|
|
|
1409
1467
|
* Callback when a tool is called
|
|
1410
1468
|
*/
|
|
1411
1469
|
onToolCall?: (handler: ToolCallHandler) => void;
|
|
1470
|
+
/**
|
|
1471
|
+
* Callback to approve/deny tool usage requests.
|
|
1472
|
+
* When provided, tool permission events will be resolved automatically.
|
|
1473
|
+
*/
|
|
1474
|
+
canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
|
|
1475
|
+
/**
|
|
1476
|
+
* Function to resolve a tool permission request (sends the decision to the server).
|
|
1477
|
+
*/
|
|
1478
|
+
resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
|
|
1412
1479
|
/**
|
|
1413
1480
|
* Callback when streaming finishes
|
|
1414
1481
|
*/
|
|
@@ -1581,4 +1648,4 @@ interface UseLongTextConversionReturn {
|
|
|
1581
1648
|
*/
|
|
1582
1649
|
declare function useLongTextConversion({ threshold, filenameTemplate, onConversion, }?: LongTextConversionOptions): UseLongTextConversionReturn;
|
|
1583
1650
|
|
|
1584
|
-
export { Message$1 as AIMessage, ActionIcon, type ActionIconProps, ActionType, type StreamEvent as AgentStreamEvent, Attachment, type AttachmentFile, AttachmentInfo, type AttachmentInfoProps, AttachmentPreview, type AttachmentPreviewProps, type AttachmentProps, AttachmentRemove, type AttachmentRemoveProps, Attachments, type AttachmentsProps, type BeforeSendContext, type BeforeSendResult, type FileAttachment as ChatFileAttachment, type ChatMiddleware, type ChatRequestOptions, CodeBlock, type CodeBlockProps, Conversation, ConversationContent, type ConversationContentProps, ConversationEmptyState, type ConversationEmptyStateProps, ConversationLoadMore, type ConversationLoadMoreProps, type ConversationProps, ConversationScrollButton, type ConversationScrollButtonProps, type ConversionInfo, type CreateMessage, type CreateStreamFn, type CreateStreamOptions, EnvVarsPanel, type EnvVarsPanelProps, FileAttachment$2 as FileAttachment, FileBadgeCompact, type FileBadgeProps, type FileAttachment as HookFileAttachment, JsonDisplay, type JsonDisplayProps, LazyMarkdown, type LazyMarkdownProps, LoadingDots, type LoadingDotsProps, LoadingSpinner, type LoadingSpinnerProps, LogEntry, LogsPanel, type LogsPanelProps, type LongTextConversionOptions, MarkdownComponents, Mention, MentionProps, Message, MessageAction, type MessageActionProps, MessageActions, type MessageActionsProps, MessageAvatar, type MessageAvatarProps, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, MessageShimmer, type MessageShimmerProps, MessageTimestamp, type MessageTimestampProps, type MiddlewareRequest, type MiddlewareRequestResult, NormalizedEntry, OptionCards, type OptionCardsProps, ParsedOption, type QueuedMessage, Reasoning, ReasoningContent, type ReasoningContentProps, type ReasoningProps, ReasoningTrigger, type ReasoningTriggerProps, RichContent, type RichContentProps, RichContentRenderer, Shimmer, ShimmerBlock, type ShimmerBlockProps, ShimmerLine, type ShimmerLineProps, type ShimmerProps, ShimmerText, type ShimmerTextProps, StatusIndicator, type StatusIndicatorProps, type StreamGenerator, Task, TaskContent, type TaskContentProps, TaskItem, type TaskItemProps, TaskList, type TaskListProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type TextAttachment, ThinkingIndicator, type ThinkingIndicatorProps, TodoItem, TodoStatus, Tool, type ToolCallHandler, ToolHeader, type ToolHeaderProps, ToolInput, type ToolInputProps, ToolInvocation, ToolList, type ToolListProps, ToolOutput, type ToolOutputProps, type ToolProps, ToolStatus, type ToolVariant, type UseAgentChatOptions, type UseAgentChatReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseLongTextConversionReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UseStopExecutionOptions, type UseStopExecutionReturn, applyEventMiddleware, applyRequestMiddleware, callMiddlewareComplete, callMiddlewareError, formatFileSize as formatFileSizeHook, useAgentChat, useAttachment, useChat, useConversation, useFileUpload, useLongTextConversion, useMessage, useMessageQueue, useReasoning, useStopExecution, useTask, useTool };
|
|
1651
|
+
export { Message$1 as AIMessage, ActionIcon, type ActionIconProps, ActionType, type StreamEvent as AgentStreamEvent, Attachment, type AttachmentFile, AttachmentInfo, type AttachmentInfoProps, AttachmentPreview, type AttachmentPreviewProps, type AttachmentProps, AttachmentRemove, type AttachmentRemoveProps, Attachments, type AttachmentsProps, type BeforeSendContext, type BeforeSendResult, ChatDisplayMode, ChatDisplayModeProvider, type ChatDisplayModeProviderProps, type FileAttachment as ChatFileAttachment, type ChatMiddleware, type ChatRequestOptions, CodeBlock, type CodeBlockProps, Conversation, ConversationContent, type ConversationContentProps, ConversationEmptyState, type ConversationEmptyStateProps, ConversationLoadMore, type ConversationLoadMoreProps, type ConversationProps, ConversationScrollButton, type ConversationScrollButtonProps, type ConversionInfo, type CreateMessage, type CreateStreamFn, type CreateStreamOptions, DisplayModeToggle, type DisplayModeToggleProps, EnvVarsPanel, type EnvVarsPanelProps, FileAttachment$2 as FileAttachment, FileBadgeCompact, type FileBadgeProps, type FileAttachment as HookFileAttachment, JsonDisplay, type JsonDisplayProps, LazyMarkdown, type LazyMarkdownProps, LoadingDots, type LoadingDotsProps, LoadingSpinner, type LoadingSpinnerProps, LogEntry, LogsPanel, type LogsPanelProps, type LongTextConversionOptions, MarkdownComponents, Mention, MentionProps, Message, MessageAction, type MessageActionProps, MessageActions, type MessageActionsProps, MessageAvatar, type MessageAvatarProps, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, MessageShimmer, type MessageShimmerProps, MessageTimestamp, type MessageTimestampProps, type MiddlewareRequest, type MiddlewareRequestResult, NormalizedEntry, OptionCards, type OptionCardsProps, ParsedOption, type QueuedMessage, Reasoning, ReasoningContent, type ReasoningContentProps, type ReasoningProps, ReasoningTrigger, type ReasoningTriggerProps, RichContent, type RichContentProps, RichContentRenderer, Shimmer, ShimmerBlock, type ShimmerBlockProps, ShimmerLine, type ShimmerLineProps, type ShimmerProps, ShimmerText, type ShimmerTextProps, StatusIndicator, type StatusIndicatorProps, type StreamGenerator, Task, TaskContent, type TaskContentProps, TaskItem, type TaskItemProps, TaskList, type TaskListProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type TextAttachment, ThinkingIndicator, type ThinkingIndicatorProps, TodoItem, TodoStatus, Tool, type ToolCallHandler, ToolDescriptionMap, ToolHeader, type ToolHeaderProps, ToolInput, type ToolInputProps, ToolInvocation, ToolList, type ToolListProps, ToolOutput, type ToolOutputProps, type ToolProps, ToolStatus, type ToolVariant, type UseAgentChatOptions, type UseAgentChatReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseLongTextConversionReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UseStopExecutionOptions, type UseStopExecutionReturn, applyEventMiddleware, applyRequestMiddleware, callMiddlewareComplete, callMiddlewareError, formatFileSize as formatFileSizeHook, useAgentChat, useAttachment, useChat, useChatDisplayMode, useConversation, useFileUpload, useLongTextConversion, useMessage, useMessageQueue, useReasoning, useStopExecution, useTask, useTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React$1, { ReactNode, ComponentType, DragEvent, ChangeEvent, ClipboardEvent } from 'react';
|
|
3
|
-
import { ToolInvocation, RichContent, MarkdownComponents, MentionProps, TodoStatus, TodoItem, FileAttachment as FileAttachment$2, LogEntry, ToolStatus, ActionType, NormalizedEntry, Message as Message$1 } from './types.js';
|
|
4
|
-
export { MessageAttachment as AIMessageAttachment, AIMessageRole, AgentToolAction, AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_STYLE_CONFIG, ErrorEntry, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, MessageMetadata, MessageStyleConfig, MessageVariant, NormalizedEntryType, NormalizedToolCall, RenderMetadataFunction, RichContentSegment, RichMentionSegment, RichTextSegment, SearchAction, ThinkingEntry, TodoWriteAction, ToolCallEntry, ToolInvocationState, ToolResult, TypographyScale, UserMessageEntry, WebFetchAction, WebSearchAction, WidgetAction, WidgetEntry, WidgetRenderFunction, WidgetRenderProps, isAgentToolAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, messageToNormalizedEntry, messagesToNormalizedEntries, normalizedEntriesToMessages, normalizedEntryToMessage } from './types.js';
|
|
3
|
+
import { ToolInvocation, RichContent, MarkdownComponents, MentionProps, ChatDisplayMode, ToolDescriptionMap, TodoStatus, TodoItem, FileAttachment as FileAttachment$2, LogEntry, ToolStatus, ActionType, NormalizedEntry, Message as Message$1 } from './types.js';
|
|
4
|
+
export { MessageAttachment as AIMessageAttachment, AIMessageRole, AgentToolAction, AssistantMessageEntry, CommandRunAction, CommandRunResult, DEFAULT_STYLE_CONFIG, ErrorEntry, FileEditAction, FileReadAction, FileWriteAction, GenericToolAction, GlobAction, LogCategory, LogLevel, McpToolAction, MessageMetadata, MessageStyleConfig, MessageVariant, NormalizedEntryType, NormalizedToolCall, RenderMetadataFunction, RichContentSegment, RichMentionSegment, RichTextSegment, SearchAction, SystemMessageEntry, ThinkingEntry, TodoWriteAction, ToolCallEntry, ToolInvocationState, ToolResult, TypographyScale, UserMessageEntry, WebFetchAction, WebSearchAction, WidgetAction, WidgetEntry, WidgetRenderFunction, WidgetRenderProps, isAgentToolAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isSystemMessage, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, messageToNormalizedEntry, messagesToNormalizedEntries, normalizedEntriesToMessages, normalizedEntryToMessage } from './types.js';
|
|
5
5
|
import { ParsedOption } from './utils.js';
|
|
6
6
|
export { ParsedOptionsResult, ToolUseInput, cn, createToolCall, extractTextContent, formatElapsedTime, formatFileSize, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, mapToolToActionType, normalizeToolResult, parseCommandResult, parseMcpToolName, parseOptionsFromContent, truncate, updateToolCallWithResult } from './utils.js';
|
|
7
7
|
export { AlertCircleIcon, AlertTriangleIcon, ArrowUpIcon, BotIcon, BrainIcon, BugIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleIcon, ClipboardListIcon, ClockIcon, CodeIcon, CopyIcon, EditIcon, ErrorIcon, FileIcon, FilePlusIcon, FolderSearchIcon, GlobeIcon, HomeIcon, IconProps, InfoIcon, ListChecksIcon, LoaderIcon, MessageSquareIcon, MicrophoneIcon, MoonIcon, PaperclipIcon, PlugIcon, SearchIcon, SendIcon, SparklesIcon, SpinnerIcon, StopCircleIcon, SunIcon, TerminalIcon, ToolIcon, UserIcon, XCircleIcon, XIcon } from './icons.js';
|
|
@@ -232,6 +232,38 @@ interface ToolListProps {
|
|
|
232
232
|
}
|
|
233
233
|
declare function ToolList({ toolInvocations, className, defaultExpanded, variant, }: ToolListProps): react_jsx_runtime.JSX.Element | null;
|
|
234
234
|
|
|
235
|
+
interface ChatDisplayModeContextValue {
|
|
236
|
+
/** Current display mode */
|
|
237
|
+
mode: ChatDisplayMode;
|
|
238
|
+
/** Toggle between user and debug */
|
|
239
|
+
toggleMode: () => void;
|
|
240
|
+
/** Set mode directly */
|
|
241
|
+
setMode: (mode: ChatDisplayMode) => void;
|
|
242
|
+
/** Consumer-provided user-friendly tool descriptions */
|
|
243
|
+
toolDescriptions: ToolDescriptionMap;
|
|
244
|
+
/** Get user-friendly description for a tool call */
|
|
245
|
+
getUserDescription: (toolName: string, input?: unknown) => string | null;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Access the current chat display mode context.
|
|
249
|
+
* Returns a graceful fallback to 'debug' mode if no provider exists.
|
|
250
|
+
*/
|
|
251
|
+
declare function useChatDisplayMode(): ChatDisplayModeContextValue;
|
|
252
|
+
interface ChatDisplayModeProviderProps {
|
|
253
|
+
children: ReactNode;
|
|
254
|
+
/** Initial mode (default: 'user') */
|
|
255
|
+
defaultMode?: ChatDisplayMode;
|
|
256
|
+
/** localStorage key for persisting preference (default: 'ash-display-mode') */
|
|
257
|
+
storageKey?: string;
|
|
258
|
+
/** Consumer-provided user-friendly tool descriptions */
|
|
259
|
+
toolDescriptions?: ToolDescriptionMap;
|
|
260
|
+
}
|
|
261
|
+
declare function ChatDisplayModeProvider({ children, defaultMode, storageKey, toolDescriptions, }: ChatDisplayModeProviderProps): react_jsx_runtime.JSX.Element;
|
|
262
|
+
interface DisplayModeToggleProps {
|
|
263
|
+
className?: string;
|
|
264
|
+
}
|
|
265
|
+
declare function DisplayModeToggle({ className }: DisplayModeToggleProps): react_jsx_runtime.JSX.Element;
|
|
266
|
+
|
|
235
267
|
interface ReasoningContextValue {
|
|
236
268
|
/** Whether the reasoning panel is open */
|
|
237
269
|
isOpen: boolean;
|
|
@@ -1059,6 +1091,7 @@ interface StreamEvent {
|
|
|
1059
1091
|
text?: string;
|
|
1060
1092
|
/** Message content array (for 'message' events) */
|
|
1061
1093
|
content?: unknown;
|
|
1094
|
+
requestId?: string;
|
|
1062
1095
|
toolId?: string;
|
|
1063
1096
|
toolName?: string;
|
|
1064
1097
|
input?: unknown;
|
|
@@ -1071,6 +1104,8 @@ interface StreamEvent {
|
|
|
1071
1104
|
result?: string;
|
|
1072
1105
|
totalCost?: number;
|
|
1073
1106
|
totalTokens?: number;
|
|
1107
|
+
stop_reason?: string;
|
|
1108
|
+
stop_sequence?: string;
|
|
1074
1109
|
/** SSE event ID (sequence number from relay) for reconnection */
|
|
1075
1110
|
id?: string;
|
|
1076
1111
|
entry?: {
|
|
@@ -1081,6 +1116,12 @@ interface StreamEvent {
|
|
|
1081
1116
|
data?: Record<string, unknown>;
|
|
1082
1117
|
};
|
|
1083
1118
|
}
|
|
1119
|
+
interface ToolPermissionRequest {
|
|
1120
|
+
requestId: string;
|
|
1121
|
+
sessionId: string;
|
|
1122
|
+
toolName: string;
|
|
1123
|
+
input?: unknown;
|
|
1124
|
+
}
|
|
1084
1125
|
/**
|
|
1085
1126
|
* Async generator that yields StreamEvent objects
|
|
1086
1127
|
*/
|
|
@@ -1095,6 +1136,8 @@ interface CreateStreamOptions {
|
|
|
1095
1136
|
metadata?: Record<string, unknown>;
|
|
1096
1137
|
/** Session context from onBeforeSend/middleware */
|
|
1097
1138
|
sessionContext?: string;
|
|
1139
|
+
/** Message role. When 'system', the message is stored as a system message. */
|
|
1140
|
+
role?: 'user' | 'system';
|
|
1098
1141
|
}
|
|
1099
1142
|
/**
|
|
1100
1143
|
* Function that creates a stream of events
|
|
@@ -1204,6 +1247,15 @@ interface UseAgentChatOptions {
|
|
|
1204
1247
|
* Callback for sandbox log events
|
|
1205
1248
|
*/
|
|
1206
1249
|
onSandboxLog?: (entry: NonNullable<StreamEvent['entry']>) => void;
|
|
1250
|
+
/**
|
|
1251
|
+
* Callback to approve/deny tool usage requests.
|
|
1252
|
+
* When provided, tool permission events will be resolved automatically.
|
|
1253
|
+
*/
|
|
1254
|
+
canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Function to resolve a tool permission request (sends the decision to the server).
|
|
1257
|
+
*/
|
|
1258
|
+
resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
|
|
1207
1259
|
/**
|
|
1208
1260
|
* Callback when reconnection is attempted
|
|
1209
1261
|
*/
|
|
@@ -1296,9 +1348,15 @@ interface UseAgentChatReturn {
|
|
|
1296
1348
|
*/
|
|
1297
1349
|
sessionId: string | null;
|
|
1298
1350
|
/**
|
|
1299
|
-
* Send a message to the agent
|
|
1351
|
+
* Send a message to the agent.
|
|
1352
|
+
* @param prompt - The message text
|
|
1353
|
+
* @param options - Optional send options
|
|
1354
|
+
* @param options.role - Message role. Defaults to 'user'. Use 'system' to send
|
|
1355
|
+
* without creating a user entry (for context injections, auto-notifications).
|
|
1300
1356
|
*/
|
|
1301
|
-
send: (prompt: string
|
|
1357
|
+
send: (prompt: string, options?: {
|
|
1358
|
+
role?: 'user' | 'system';
|
|
1359
|
+
}) => Promise<void>;
|
|
1302
1360
|
/**
|
|
1303
1361
|
* Stop the current streaming request
|
|
1304
1362
|
*/
|
|
@@ -1409,6 +1467,15 @@ interface UseChatOptions {
|
|
|
1409
1467
|
* Callback when a tool is called
|
|
1410
1468
|
*/
|
|
1411
1469
|
onToolCall?: (handler: ToolCallHandler) => void;
|
|
1470
|
+
/**
|
|
1471
|
+
* Callback to approve/deny tool usage requests.
|
|
1472
|
+
* When provided, tool permission events will be resolved automatically.
|
|
1473
|
+
*/
|
|
1474
|
+
canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
|
|
1475
|
+
/**
|
|
1476
|
+
* Function to resolve a tool permission request (sends the decision to the server).
|
|
1477
|
+
*/
|
|
1478
|
+
resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
|
|
1412
1479
|
/**
|
|
1413
1480
|
* Callback when streaming finishes
|
|
1414
1481
|
*/
|
|
@@ -1581,4 +1648,4 @@ interface UseLongTextConversionReturn {
|
|
|
1581
1648
|
*/
|
|
1582
1649
|
declare function useLongTextConversion({ threshold, filenameTemplate, onConversion, }?: LongTextConversionOptions): UseLongTextConversionReturn;
|
|
1583
1650
|
|
|
1584
|
-
export { Message$1 as AIMessage, ActionIcon, type ActionIconProps, ActionType, type StreamEvent as AgentStreamEvent, Attachment, type AttachmentFile, AttachmentInfo, type AttachmentInfoProps, AttachmentPreview, type AttachmentPreviewProps, type AttachmentProps, AttachmentRemove, type AttachmentRemoveProps, Attachments, type AttachmentsProps, type BeforeSendContext, type BeforeSendResult, type FileAttachment as ChatFileAttachment, type ChatMiddleware, type ChatRequestOptions, CodeBlock, type CodeBlockProps, Conversation, ConversationContent, type ConversationContentProps, ConversationEmptyState, type ConversationEmptyStateProps, ConversationLoadMore, type ConversationLoadMoreProps, type ConversationProps, ConversationScrollButton, type ConversationScrollButtonProps, type ConversionInfo, type CreateMessage, type CreateStreamFn, type CreateStreamOptions, EnvVarsPanel, type EnvVarsPanelProps, FileAttachment$2 as FileAttachment, FileBadgeCompact, type FileBadgeProps, type FileAttachment as HookFileAttachment, JsonDisplay, type JsonDisplayProps, LazyMarkdown, type LazyMarkdownProps, LoadingDots, type LoadingDotsProps, LoadingSpinner, type LoadingSpinnerProps, LogEntry, LogsPanel, type LogsPanelProps, type LongTextConversionOptions, MarkdownComponents, Mention, MentionProps, Message, MessageAction, type MessageActionProps, MessageActions, type MessageActionsProps, MessageAvatar, type MessageAvatarProps, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, MessageShimmer, type MessageShimmerProps, MessageTimestamp, type MessageTimestampProps, type MiddlewareRequest, type MiddlewareRequestResult, NormalizedEntry, OptionCards, type OptionCardsProps, ParsedOption, type QueuedMessage, Reasoning, ReasoningContent, type ReasoningContentProps, type ReasoningProps, ReasoningTrigger, type ReasoningTriggerProps, RichContent, type RichContentProps, RichContentRenderer, Shimmer, ShimmerBlock, type ShimmerBlockProps, ShimmerLine, type ShimmerLineProps, type ShimmerProps, ShimmerText, type ShimmerTextProps, StatusIndicator, type StatusIndicatorProps, type StreamGenerator, Task, TaskContent, type TaskContentProps, TaskItem, type TaskItemProps, TaskList, type TaskListProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type TextAttachment, ThinkingIndicator, type ThinkingIndicatorProps, TodoItem, TodoStatus, Tool, type ToolCallHandler, ToolHeader, type ToolHeaderProps, ToolInput, type ToolInputProps, ToolInvocation, ToolList, type ToolListProps, ToolOutput, type ToolOutputProps, type ToolProps, ToolStatus, type ToolVariant, type UseAgentChatOptions, type UseAgentChatReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseLongTextConversionReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UseStopExecutionOptions, type UseStopExecutionReturn, applyEventMiddleware, applyRequestMiddleware, callMiddlewareComplete, callMiddlewareError, formatFileSize as formatFileSizeHook, useAgentChat, useAttachment, useChat, useConversation, useFileUpload, useLongTextConversion, useMessage, useMessageQueue, useReasoning, useStopExecution, useTask, useTool };
|
|
1651
|
+
export { Message$1 as AIMessage, ActionIcon, type ActionIconProps, ActionType, type StreamEvent as AgentStreamEvent, Attachment, type AttachmentFile, AttachmentInfo, type AttachmentInfoProps, AttachmentPreview, type AttachmentPreviewProps, type AttachmentProps, AttachmentRemove, type AttachmentRemoveProps, Attachments, type AttachmentsProps, type BeforeSendContext, type BeforeSendResult, ChatDisplayMode, ChatDisplayModeProvider, type ChatDisplayModeProviderProps, type FileAttachment as ChatFileAttachment, type ChatMiddleware, type ChatRequestOptions, CodeBlock, type CodeBlockProps, Conversation, ConversationContent, type ConversationContentProps, ConversationEmptyState, type ConversationEmptyStateProps, ConversationLoadMore, type ConversationLoadMoreProps, type ConversationProps, ConversationScrollButton, type ConversationScrollButtonProps, type ConversionInfo, type CreateMessage, type CreateStreamFn, type CreateStreamOptions, DisplayModeToggle, type DisplayModeToggleProps, EnvVarsPanel, type EnvVarsPanelProps, FileAttachment$2 as FileAttachment, FileBadgeCompact, type FileBadgeProps, type FileAttachment as HookFileAttachment, JsonDisplay, type JsonDisplayProps, LazyMarkdown, type LazyMarkdownProps, LoadingDots, type LoadingDotsProps, LoadingSpinner, type LoadingSpinnerProps, LogEntry, LogsPanel, type LogsPanelProps, type LongTextConversionOptions, MarkdownComponents, Mention, MentionProps, Message, MessageAction, type MessageActionProps, MessageActions, type MessageActionsProps, MessageAvatar, type MessageAvatarProps, MessageContent, type MessageContentProps, type MessageProps, MessageResponse, type MessageResponseProps, MessageShimmer, type MessageShimmerProps, MessageTimestamp, type MessageTimestampProps, type MiddlewareRequest, type MiddlewareRequestResult, NormalizedEntry, OptionCards, type OptionCardsProps, ParsedOption, type QueuedMessage, Reasoning, ReasoningContent, type ReasoningContentProps, type ReasoningProps, ReasoningTrigger, type ReasoningTriggerProps, RichContent, type RichContentProps, RichContentRenderer, Shimmer, ShimmerBlock, type ShimmerBlockProps, ShimmerLine, type ShimmerLineProps, type ShimmerProps, ShimmerText, type ShimmerTextProps, StatusIndicator, type StatusIndicatorProps, type StreamGenerator, Task, TaskContent, type TaskContentProps, TaskItem, type TaskItemProps, TaskList, type TaskListProps, type TaskProps, TaskTrigger, type TaskTriggerProps, type TextAttachment, ThinkingIndicator, type ThinkingIndicatorProps, TodoItem, TodoStatus, Tool, type ToolCallHandler, ToolDescriptionMap, ToolHeader, type ToolHeaderProps, ToolInput, type ToolInputProps, ToolInvocation, ToolList, type ToolListProps, ToolOutput, type ToolOutputProps, type ToolProps, ToolStatus, type ToolVariant, type UseAgentChatOptions, type UseAgentChatReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseLongTextConversionReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UseStopExecutionOptions, type UseStopExecutionReturn, applyEventMiddleware, applyRequestMiddleware, callMiddlewareComplete, callMiddlewareError, formatFileSize as formatFileSizeHook, useAgentChat, useAttachment, useChat, useChatDisplayMode, useConversation, useFileUpload, useLongTextConversion, useMessage, useMessageQueue, useReasoning, useStopExecution, useTask, useTool };
|
package/dist/index.js
CHANGED
|
@@ -1267,6 +1267,128 @@ function JsonDisplay({ value, maxHeight, className }) {
|
|
|
1267
1267
|
const formatted = JSON.stringify(value, null, 2);
|
|
1268
1268
|
return /* @__PURE__ */ jsx(CodeBlock, { maxHeight, className, children: formatted });
|
|
1269
1269
|
}
|
|
1270
|
+
var ChatDisplayModeContext = createContext(null);
|
|
1271
|
+
function useChatDisplayMode() {
|
|
1272
|
+
const ctx = useContext(ChatDisplayModeContext);
|
|
1273
|
+
if (!ctx) {
|
|
1274
|
+
return {
|
|
1275
|
+
mode: "debug",
|
|
1276
|
+
toggleMode: () => {
|
|
1277
|
+
},
|
|
1278
|
+
setMode: () => {
|
|
1279
|
+
},
|
|
1280
|
+
toolDescriptions: {},
|
|
1281
|
+
getUserDescription: () => null
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
return ctx;
|
|
1285
|
+
}
|
|
1286
|
+
function ChatDisplayModeProvider({
|
|
1287
|
+
children,
|
|
1288
|
+
defaultMode = "user",
|
|
1289
|
+
storageKey = "ash-display-mode",
|
|
1290
|
+
toolDescriptions = {}
|
|
1291
|
+
}) {
|
|
1292
|
+
const [mode, setModeState] = useState(() => {
|
|
1293
|
+
if (typeof window !== "undefined") {
|
|
1294
|
+
const stored = localStorage.getItem(storageKey);
|
|
1295
|
+
if (stored === "user" || stored === "debug") return stored;
|
|
1296
|
+
}
|
|
1297
|
+
return defaultMode;
|
|
1298
|
+
});
|
|
1299
|
+
useEffect(() => {
|
|
1300
|
+
if (typeof window !== "undefined") {
|
|
1301
|
+
localStorage.setItem(storageKey, mode);
|
|
1302
|
+
}
|
|
1303
|
+
}, [mode, storageKey]);
|
|
1304
|
+
const toggleMode = () => setModeState((m) => m === "user" ? "debug" : "user");
|
|
1305
|
+
const setMode = (m) => setModeState(m);
|
|
1306
|
+
const getUserDescription = (toolName, input) => {
|
|
1307
|
+
if (toolDescriptions[toolName]) {
|
|
1308
|
+
const desc = toolDescriptions[toolName];
|
|
1309
|
+
return typeof desc === "function" ? desc(input) : desc;
|
|
1310
|
+
}
|
|
1311
|
+
for (const [pattern, desc] of Object.entries(toolDescriptions)) {
|
|
1312
|
+
if (toolName.includes(pattern)) {
|
|
1313
|
+
return typeof desc === "function" ? desc(input) : desc;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
return null;
|
|
1317
|
+
};
|
|
1318
|
+
return /* @__PURE__ */ jsx(
|
|
1319
|
+
ChatDisplayModeContext.Provider,
|
|
1320
|
+
{
|
|
1321
|
+
value: {
|
|
1322
|
+
mode,
|
|
1323
|
+
toggleMode,
|
|
1324
|
+
setMode,
|
|
1325
|
+
toolDescriptions,
|
|
1326
|
+
getUserDescription
|
|
1327
|
+
},
|
|
1328
|
+
children
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
function DisplayModeToggle({ className }) {
|
|
1333
|
+
const { mode, toggleMode } = useChatDisplayMode();
|
|
1334
|
+
return /* @__PURE__ */ jsxs(
|
|
1335
|
+
"button",
|
|
1336
|
+
{
|
|
1337
|
+
onClick: toggleMode,
|
|
1338
|
+
className: cn("ash-display-mode-toggle", className),
|
|
1339
|
+
title: mode === "user" ? "Switch to debug mode" : "Switch to user mode",
|
|
1340
|
+
children: [
|
|
1341
|
+
/* @__PURE__ */ jsx("span", { className: "ash-display-mode-icon", children: mode === "user" ? /* @__PURE__ */ jsxs(
|
|
1342
|
+
"svg",
|
|
1343
|
+
{
|
|
1344
|
+
className: "w-4 h-4",
|
|
1345
|
+
fill: "none",
|
|
1346
|
+
stroke: "currentColor",
|
|
1347
|
+
viewBox: "0 0 24 24",
|
|
1348
|
+
children: [
|
|
1349
|
+
/* @__PURE__ */ jsx(
|
|
1350
|
+
"path",
|
|
1351
|
+
{
|
|
1352
|
+
strokeLinecap: "round",
|
|
1353
|
+
strokeLinejoin: "round",
|
|
1354
|
+
strokeWidth: 2,
|
|
1355
|
+
d: "M15 12a3 3 0 11-6 0 3 3 0 016 0z"
|
|
1356
|
+
}
|
|
1357
|
+
),
|
|
1358
|
+
/* @__PURE__ */ jsx(
|
|
1359
|
+
"path",
|
|
1360
|
+
{
|
|
1361
|
+
strokeLinecap: "round",
|
|
1362
|
+
strokeLinejoin: "round",
|
|
1363
|
+
strokeWidth: 2,
|
|
1364
|
+
d: "M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
|
|
1365
|
+
}
|
|
1366
|
+
)
|
|
1367
|
+
]
|
|
1368
|
+
}
|
|
1369
|
+
) : /* @__PURE__ */ jsx(
|
|
1370
|
+
"svg",
|
|
1371
|
+
{
|
|
1372
|
+
className: "w-4 h-4",
|
|
1373
|
+
fill: "none",
|
|
1374
|
+
stroke: "currentColor",
|
|
1375
|
+
viewBox: "0 0 24 24",
|
|
1376
|
+
children: /* @__PURE__ */ jsx(
|
|
1377
|
+
"path",
|
|
1378
|
+
{
|
|
1379
|
+
strokeLinecap: "round",
|
|
1380
|
+
strokeLinejoin: "round",
|
|
1381
|
+
strokeWidth: 2,
|
|
1382
|
+
d: "M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"
|
|
1383
|
+
}
|
|
1384
|
+
)
|
|
1385
|
+
}
|
|
1386
|
+
) }),
|
|
1387
|
+
/* @__PURE__ */ jsx("span", { className: "ash-display-mode-label", children: mode === "user" ? "User" : "Debug" })
|
|
1388
|
+
]
|
|
1389
|
+
}
|
|
1390
|
+
);
|
|
1391
|
+
}
|
|
1270
1392
|
var ToolContext = createContext(null);
|
|
1271
1393
|
function useTool() {
|
|
1272
1394
|
const context = useContext(ToolContext);
|
|
@@ -1283,6 +1405,7 @@ function Tool({
|
|
|
1283
1405
|
variant = "default"
|
|
1284
1406
|
}) {
|
|
1285
1407
|
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
|
1408
|
+
const { mode, getUserDescription } = useChatDisplayMode();
|
|
1286
1409
|
const toggleExpanded = () => setIsExpanded((prev) => !prev);
|
|
1287
1410
|
const contextValue = {
|
|
1288
1411
|
toolInvocation,
|
|
@@ -1294,6 +1417,27 @@ function Tool({
|
|
|
1294
1417
|
const isErrorResult = Boolean(
|
|
1295
1418
|
toolInvocation.result && typeof toolInvocation.result === "object" && "error" in toolInvocation.result
|
|
1296
1419
|
);
|
|
1420
|
+
if (mode === "user") {
|
|
1421
|
+
const userDesc = getUserDescription(toolInvocation.toolName, toolInvocation.args) || formatToolName(toolInvocation.toolName);
|
|
1422
|
+
return /* @__PURE__ */ jsxs(
|
|
1423
|
+
"div",
|
|
1424
|
+
{
|
|
1425
|
+
className: cn(
|
|
1426
|
+
"ash-tool ash-tool-user-mode",
|
|
1427
|
+
"flex items-center gap-2 px-3 py-1.5",
|
|
1428
|
+
"text-[var(--ash-font-size-xs,11px)]",
|
|
1429
|
+
"text-[var(--ash-text-muted,rgba(255,255,255,0.5))]",
|
|
1430
|
+
className
|
|
1431
|
+
),
|
|
1432
|
+
"data-tool-name": toolInvocation.toolName,
|
|
1433
|
+
"data-tool-state": toolInvocation.state,
|
|
1434
|
+
children: [
|
|
1435
|
+
/* @__PURE__ */ jsx(StatusIndicator, { status, size: "xs" }),
|
|
1436
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: userDesc })
|
|
1437
|
+
]
|
|
1438
|
+
}
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1297
1441
|
return /* @__PURE__ */ jsx(ToolContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
1298
1442
|
"div",
|
|
1299
1443
|
{
|
|
@@ -3128,6 +3272,9 @@ function isErrorEntry(entry) {
|
|
|
3128
3272
|
function isWidgetEntry(entry) {
|
|
3129
3273
|
return entry.type === "widget";
|
|
3130
3274
|
}
|
|
3275
|
+
function isSystemMessage(entry) {
|
|
3276
|
+
return entry.type === "system_message";
|
|
3277
|
+
}
|
|
3131
3278
|
var DEFAULT_STYLE_CONFIG = {
|
|
3132
3279
|
userVariant: "bubble",
|
|
3133
3280
|
assistantVariant: "bubble",
|
|
@@ -3261,7 +3408,7 @@ function messageToNormalizedEntry(message) {
|
|
|
3261
3408
|
return {
|
|
3262
3409
|
id,
|
|
3263
3410
|
timestamp,
|
|
3264
|
-
entryType: { type: "
|
|
3411
|
+
entryType: { type: "system_message" },
|
|
3265
3412
|
content
|
|
3266
3413
|
};
|
|
3267
3414
|
}
|
|
@@ -3664,6 +3811,8 @@ function useAgentChat(options) {
|
|
|
3664
3811
|
onSessionEnd,
|
|
3665
3812
|
onError,
|
|
3666
3813
|
onSandboxLog,
|
|
3814
|
+
canUseTool,
|
|
3815
|
+
resolveToolPermission,
|
|
3667
3816
|
onReconnect,
|
|
3668
3817
|
maxReconnectAttempts = 3,
|
|
3669
3818
|
reconnectBaseDelay = 1e3,
|
|
@@ -3697,6 +3846,23 @@ function useAgentChat(options) {
|
|
|
3697
3846
|
const emitStreamingEntries = useCallback((newEntries) => {
|
|
3698
3847
|
setStreamingEntries([...newEntries]);
|
|
3699
3848
|
}, []);
|
|
3849
|
+
const handleToolPermission = useCallback(async (event) => {
|
|
3850
|
+
if (event.type !== "tool_permission") return;
|
|
3851
|
+
if (!canUseTool) return;
|
|
3852
|
+
if (!event.requestId || !event.sessionId || !event.toolName) return;
|
|
3853
|
+
const request = {
|
|
3854
|
+
requestId: event.requestId,
|
|
3855
|
+
sessionId: event.sessionId,
|
|
3856
|
+
toolName: event.toolName,
|
|
3857
|
+
input: event.input
|
|
3858
|
+
};
|
|
3859
|
+
const allow = await canUseTool(request);
|
|
3860
|
+
if (!resolveToolPermission) {
|
|
3861
|
+
console.warn("[useAgentChat] resolveToolPermission not provided for tool permission response");
|
|
3862
|
+
return;
|
|
3863
|
+
}
|
|
3864
|
+
await resolveToolPermission(request, allow);
|
|
3865
|
+
}, [canUseTool, resolveToolPermission]);
|
|
3700
3866
|
const createTextEntry = useCallback((id, content) => ({
|
|
3701
3867
|
id,
|
|
3702
3868
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -3855,6 +4021,7 @@ function useAgentChat(options) {
|
|
|
3855
4021
|
for await (const event of stream) {
|
|
3856
4022
|
if (controller.signal.aborted) break;
|
|
3857
4023
|
eventCountRef.current++;
|
|
4024
|
+
await handleToolPermission(event);
|
|
3858
4025
|
localStreamingEntries = processEvent(event, localStreamingEntries);
|
|
3859
4026
|
emitStreamingEntries(localStreamingEntries);
|
|
3860
4027
|
if (event.type === "complete" || event.type === "session_end" || event.type === "error") {
|
|
@@ -3888,9 +4055,10 @@ function useAgentChat(options) {
|
|
|
3888
4055
|
}
|
|
3889
4056
|
return false;
|
|
3890
4057
|
}
|
|
3891
|
-
}, [subscribeToSession, maxReconnectAttempts, reconnectBaseDelay, onReconnect, processEvent, emitStreamingEntries]);
|
|
3892
|
-
const send = useCallback(async (prompt) => {
|
|
4058
|
+
}, [subscribeToSession, maxReconnectAttempts, reconnectBaseDelay, onReconnect, processEvent, emitStreamingEntries, handleToolPermission]);
|
|
4059
|
+
const send = useCallback(async (prompt, sendOptions) => {
|
|
3893
4060
|
if (isStreaming) return;
|
|
4061
|
+
const role = sendOptions?.role ?? "user";
|
|
3894
4062
|
let finalPrompt = prompt;
|
|
3895
4063
|
let additionalMetadata = {};
|
|
3896
4064
|
let additionalContext;
|
|
@@ -3936,13 +4104,15 @@ function useAgentChat(options) {
|
|
|
3936
4104
|
setError(null);
|
|
3937
4105
|
reconnectAttemptsRef.current = 0;
|
|
3938
4106
|
eventCountRef.current = 0;
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
4107
|
+
if (role !== "system") {
|
|
4108
|
+
const userEntry = {
|
|
4109
|
+
id: `user-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
4110
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4111
|
+
entryType: { type: "user_message" },
|
|
4112
|
+
content: prompt
|
|
4113
|
+
};
|
|
4114
|
+
setHistoryEntries((prev) => [...prev, userEntry]);
|
|
4115
|
+
}
|
|
3946
4116
|
resetStreamingState();
|
|
3947
4117
|
const controller = new AbortController();
|
|
3948
4118
|
abortControllerRef.current = controller;
|
|
@@ -3952,7 +4122,8 @@ function useAgentChat(options) {
|
|
|
3952
4122
|
const stream = createStream(finalPrompt, sessionId || void 0, {
|
|
3953
4123
|
signal: controller.signal,
|
|
3954
4124
|
metadata: Object.keys(additionalMetadata).length > 0 ? additionalMetadata : void 0,
|
|
3955
|
-
sessionContext: additionalContext
|
|
4125
|
+
sessionContext: additionalContext,
|
|
4126
|
+
role: role !== "user" ? role : void 0
|
|
3956
4127
|
});
|
|
3957
4128
|
for await (const event of stream) {
|
|
3958
4129
|
if (controller.signal.aborted) break;
|
|
@@ -3967,6 +4138,7 @@ function useAgentChat(options) {
|
|
|
3967
4138
|
console.error("[useAgentChat] onEvent error:", err);
|
|
3968
4139
|
}
|
|
3969
4140
|
}
|
|
4141
|
+
await handleToolPermission(event);
|
|
3970
4142
|
let processedEvent = event;
|
|
3971
4143
|
if (middleware?.length) {
|
|
3972
4144
|
processedEvent = await applyEventMiddleware(middleware, event);
|
|
@@ -4016,7 +4188,7 @@ function useAgentChat(options) {
|
|
|
4016
4188
|
abortControllerRef.current = null;
|
|
4017
4189
|
resetStreamingState();
|
|
4018
4190
|
}
|
|
4019
|
-
}, [isStreaming, sessionId, historyEntries, streamingEntries, createStream, subscribeToSession, processEvent, emitStreamingEntries, resetStreamingState, onError, attemptReconnect, onBeforeSend, onEvent, middleware]);
|
|
4191
|
+
}, [isStreaming, sessionId, historyEntries, streamingEntries, createStream, subscribeToSession, processEvent, emitStreamingEntries, resetStreamingState, onError, attemptReconnect, onBeforeSend, onEvent, middleware, handleToolPermission]);
|
|
4020
4192
|
const stop = useCallback(() => {
|
|
4021
4193
|
reconnectAttemptsRef.current = maxReconnectAttempts + 1;
|
|
4022
4194
|
setIsReconnecting(false);
|
|
@@ -4067,6 +4239,8 @@ function useChat(options) {
|
|
|
4067
4239
|
initialSessionId,
|
|
4068
4240
|
initialMessages = [],
|
|
4069
4241
|
onToolCall,
|
|
4242
|
+
canUseTool,
|
|
4243
|
+
resolveToolPermission,
|
|
4070
4244
|
onFinish,
|
|
4071
4245
|
onError,
|
|
4072
4246
|
onSessionStart,
|
|
@@ -4101,6 +4275,23 @@ function useChat(options) {
|
|
|
4101
4275
|
return prev;
|
|
4102
4276
|
});
|
|
4103
4277
|
}, []);
|
|
4278
|
+
const handleToolPermission = useCallback(async (event) => {
|
|
4279
|
+
if (event.type !== "tool_permission") return;
|
|
4280
|
+
if (!canUseTool) return;
|
|
4281
|
+
if (!event.requestId || !event.sessionId || !event.toolName) return;
|
|
4282
|
+
const request = {
|
|
4283
|
+
requestId: event.requestId,
|
|
4284
|
+
sessionId: event.sessionId,
|
|
4285
|
+
toolName: event.toolName,
|
|
4286
|
+
input: event.input
|
|
4287
|
+
};
|
|
4288
|
+
const allow = await canUseTool(request);
|
|
4289
|
+
if (!resolveToolPermission) {
|
|
4290
|
+
console.warn("[useChat] resolveToolPermission not provided for tool permission response");
|
|
4291
|
+
return;
|
|
4292
|
+
}
|
|
4293
|
+
await resolveToolPermission(request, allow);
|
|
4294
|
+
}, [canUseTool, resolveToolPermission]);
|
|
4104
4295
|
const processEvent = useCallback((event) => {
|
|
4105
4296
|
switch (event.type) {
|
|
4106
4297
|
case "session_start":
|
|
@@ -4220,6 +4411,7 @@ function useChat(options) {
|
|
|
4220
4411
|
const stream = createStream(finalPrompt, sessionIdRef.current || void 0, streamOptions);
|
|
4221
4412
|
for await (const event of stream) {
|
|
4222
4413
|
if (controller.signal.aborted) break;
|
|
4414
|
+
await handleToolPermission(event);
|
|
4223
4415
|
let processedEvent = event;
|
|
4224
4416
|
if (middleware?.length) {
|
|
4225
4417
|
processedEvent = await applyEventMiddleware(middleware, event);
|
|
@@ -4249,7 +4441,7 @@ function useChat(options) {
|
|
|
4249
4441
|
abortControllerRef.current = null;
|
|
4250
4442
|
currentAssistantMessageRef.current = null;
|
|
4251
4443
|
}
|
|
4252
|
-
}, [isLoading, createStream, processEvent, middleware, onError]);
|
|
4444
|
+
}, [isLoading, createStream, processEvent, middleware, onError, handleToolPermission]);
|
|
4253
4445
|
const stop = useCallback(() => {
|
|
4254
4446
|
reconnectAttemptsRef.current = maxReconnectAttempts + 1;
|
|
4255
4447
|
setIsReconnecting(false);
|
|
@@ -4378,6 +4570,6 @@ function useLongTextConversion({
|
|
|
4378
4570
|
};
|
|
4379
4571
|
}
|
|
4380
4572
|
|
|
4381
|
-
export { ActionIcon, AlertCircleIcon, AlertTriangleIcon, ArrowUpIcon, Attachment, AttachmentInfo, AttachmentPreview, AttachmentRemove, Attachments, BotIcon, BrainIcon, BugIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleIcon, ClipboardListIcon, ClockIcon, CodeBlock, CodeIcon, Conversation, ConversationContent, ConversationEmptyState, ConversationLoadMore, ConversationScrollButton, CopyIcon, DEFAULT_STYLE_CONFIG, EditIcon, EnvVarsPanel, ErrorIcon, FileBadgeCompact, FileIcon, FilePlusIcon, FolderSearchIcon, GlobeIcon, HomeIcon, InfoIcon, JsonDisplay, LazyMarkdown, ListChecksIcon, LoaderIcon, LoadingDots, LoadingSpinner, LogsPanel, Mention, Message, MessageAction, MessageActions, MessageAvatar, MessageContent, MessageResponse, MessageShimmer, MessageSquareIcon, MessageTimestamp, MicrophoneIcon, MoonIcon, OptionCards, PaperclipIcon, PlugIcon, Reasoning, ReasoningContent, ReasoningTrigger, RichContentRenderer, SearchIcon, SendIcon, Shimmer, ShimmerBlock, ShimmerLine, ShimmerText, SparklesIcon, SpinnerIcon, StatusIndicator, StopCircleIcon, SunIcon, Task, TaskContent, TaskItem, TaskList, TaskTrigger, TerminalIcon, ThinkingIndicator, Tool, ToolHeader, ToolIcon, ToolInput, ToolList, ToolOutput, UserIcon, XCircleIcon, XIcon, allKeyframesCss, applyEventMiddleware, applyRequestMiddleware, borderRadius, callMiddlewareComplete, callMiddlewareError, cn, colors, createToolCall, cssVars, extractTextContent, formatElapsedTime, formatFileSize, formatFileSize2 as formatFileSizeHook, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, inlineStyles, isAgentToolAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, keyframes, keyframesCss, mapToolToActionType, messageToNormalizedEntry, messagesToNormalizedEntries, normalizeToolResult, normalizedEntriesToMessages, normalizedEntryToMessage, parseCommandResult, parseMcpToolName, parseOptionsFromContent, shadows, spacing, tokensToCssVariables, transitions, truncate, typography, updateToolCallWithResult, useAgentChat, useAttachment, useChat, useConversation, useFileUpload, useLongTextConversion, useMessage, useMessageQueue, useReasoning, useStopExecution, useTask, useTool, widget, zIndex };
|
|
4573
|
+
export { ActionIcon, AlertCircleIcon, AlertTriangleIcon, ArrowUpIcon, Attachment, AttachmentInfo, AttachmentPreview, AttachmentRemove, Attachments, BotIcon, BrainIcon, BugIcon, ChatDisplayModeProvider, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleIcon, ClipboardListIcon, ClockIcon, CodeBlock, CodeIcon, Conversation, ConversationContent, ConversationEmptyState, ConversationLoadMore, ConversationScrollButton, CopyIcon, DEFAULT_STYLE_CONFIG, DisplayModeToggle, EditIcon, EnvVarsPanel, ErrorIcon, FileBadgeCompact, FileIcon, FilePlusIcon, FolderSearchIcon, GlobeIcon, HomeIcon, InfoIcon, JsonDisplay, LazyMarkdown, ListChecksIcon, LoaderIcon, LoadingDots, LoadingSpinner, LogsPanel, Mention, Message, MessageAction, MessageActions, MessageAvatar, MessageContent, MessageResponse, MessageShimmer, MessageSquareIcon, MessageTimestamp, MicrophoneIcon, MoonIcon, OptionCards, PaperclipIcon, PlugIcon, Reasoning, ReasoningContent, ReasoningTrigger, RichContentRenderer, SearchIcon, SendIcon, Shimmer, ShimmerBlock, ShimmerLine, ShimmerText, SparklesIcon, SpinnerIcon, StatusIndicator, StopCircleIcon, SunIcon, Task, TaskContent, TaskItem, TaskList, TaskTrigger, TerminalIcon, ThinkingIndicator, Tool, ToolHeader, ToolIcon, ToolInput, ToolList, ToolOutput, UserIcon, XCircleIcon, XIcon, allKeyframesCss, applyEventMiddleware, applyRequestMiddleware, borderRadius, callMiddlewareComplete, callMiddlewareError, cn, colors, createToolCall, cssVars, extractTextContent, formatElapsedTime, formatFileSize, formatFileSize2 as formatFileSizeHook, formatTimestamp, formatToolName, generateToolSummary, getActionIcon, getActionLabel, inlineStyles, isAgentToolAction, isCommandRunAction, isErrorEntry, isFileEditAction, isFileReadAction, isFileWriteAction, isGenericToolAction, isGlobAction, isMcpToolAction, isSearchAction, isSystemMessage, isTodoWriteAction, isToolCallEntry, isWebFetchAction, isWebSearchAction, isWidgetEntry, keyframes, keyframesCss, mapToolToActionType, messageToNormalizedEntry, messagesToNormalizedEntries, normalizeToolResult, normalizedEntriesToMessages, normalizedEntryToMessage, parseCommandResult, parseMcpToolName, parseOptionsFromContent, shadows, spacing, tokensToCssVariables, transitions, truncate, typography, updateToolCallWithResult, useAgentChat, useAttachment, useChat, useChatDisplayMode, useConversation, useFileUpload, useLongTextConversion, useMessage, useMessageQueue, useReasoning, useStopExecution, useTask, useTool, widget, zIndex };
|
|
4382
4574
|
//# sourceMappingURL=index.js.map
|
|
4383
4575
|
//# sourceMappingURL=index.js.map
|