@ash-cloud/ash-ui 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -18,6 +18,10 @@ interface ConversationContextValue {
18
18
  autoScroll: boolean;
19
19
  /** Set auto-scroll state */
20
20
  setAutoScroll: (value: boolean) => void;
21
+ /** Whether more messages exist above */
22
+ hasMore: boolean;
23
+ /** Whether older messages are currently being fetched */
24
+ isLoadingMore: boolean;
21
25
  }
22
26
  declare function useConversation(): ConversationContextValue;
23
27
  interface ConversationProps {
@@ -29,8 +33,16 @@ interface ConversationProps {
29
33
  autoScroll?: boolean;
30
34
  /** Threshold in pixels to consider "at bottom" */
31
35
  scrollThreshold?: number;
32
- }
33
- declare function Conversation({ children, className, autoScroll: initialAutoScroll, scrollThreshold, }: ConversationProps): react_jsx_runtime.JSX.Element;
36
+ /** Called when user scrolls near the top to load older messages */
37
+ onLoadMore?: () => void;
38
+ /** Whether more messages exist above */
39
+ hasMore?: boolean;
40
+ /** Whether older messages are currently being fetched */
41
+ isLoadingMore?: boolean;
42
+ /** Pixels from top to trigger onLoadMore (default: 100) */
43
+ loadMoreThreshold?: number;
44
+ }
45
+ declare function Conversation({ children, className, autoScroll: initialAutoScroll, scrollThreshold, onLoadMore, hasMore, isLoadingMore, loadMoreThreshold, }: ConversationProps): react_jsx_runtime.JSX.Element;
34
46
  interface ConversationContentProps {
35
47
  /** Child elements */
36
48
  children: ReactNode;
@@ -52,6 +64,11 @@ interface ConversationScrollButtonProps {
52
64
  label?: string;
53
65
  }
54
66
  declare function ConversationScrollButton({ className, label, }: ConversationScrollButtonProps): react_jsx_runtime.JSX.Element | null;
67
+ interface ConversationLoadMoreProps {
68
+ /** Additional class name */
69
+ className?: string;
70
+ }
71
+ declare function ConversationLoadMore({ className, }: ConversationLoadMoreProps): react_jsx_runtime.JSX.Element | null;
55
72
 
56
73
  interface MessageContextValue {
57
74
  /** Message role */
@@ -1042,6 +1059,7 @@ interface StreamEvent {
1042
1059
  text?: string;
1043
1060
  /** Message content array (for 'message' events) */
1044
1061
  content?: unknown;
1062
+ requestId?: string;
1045
1063
  toolId?: string;
1046
1064
  toolName?: string;
1047
1065
  input?: unknown;
@@ -1054,6 +1072,8 @@ interface StreamEvent {
1054
1072
  result?: string;
1055
1073
  totalCost?: number;
1056
1074
  totalTokens?: number;
1075
+ stop_reason?: string;
1076
+ stop_sequence?: string;
1057
1077
  /** SSE event ID (sequence number from relay) for reconnection */
1058
1078
  id?: string;
1059
1079
  entry?: {
@@ -1064,6 +1084,12 @@ interface StreamEvent {
1064
1084
  data?: Record<string, unknown>;
1065
1085
  };
1066
1086
  }
1087
+ interface ToolPermissionRequest {
1088
+ requestId: string;
1089
+ sessionId: string;
1090
+ toolName: string;
1091
+ input?: unknown;
1092
+ }
1067
1093
  /**
1068
1094
  * Async generator that yields StreamEvent objects
1069
1095
  */
@@ -1187,6 +1213,15 @@ interface UseAgentChatOptions {
1187
1213
  * Callback for sandbox log events
1188
1214
  */
1189
1215
  onSandboxLog?: (entry: NonNullable<StreamEvent['entry']>) => void;
1216
+ /**
1217
+ * Callback to approve/deny tool usage requests.
1218
+ * When provided, tool permission events will be resolved automatically.
1219
+ */
1220
+ canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
1221
+ /**
1222
+ * Function to resolve a tool permission request (sends the decision to the server).
1223
+ */
1224
+ resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
1190
1225
  /**
1191
1226
  * Callback when reconnection is attempted
1192
1227
  */
@@ -1392,6 +1427,15 @@ interface UseChatOptions {
1392
1427
  * Callback when a tool is called
1393
1428
  */
1394
1429
  onToolCall?: (handler: ToolCallHandler) => void;
1430
+ /**
1431
+ * Callback to approve/deny tool usage requests.
1432
+ * When provided, tool permission events will be resolved automatically.
1433
+ */
1434
+ canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
1435
+ /**
1436
+ * Function to resolve a tool permission request (sends the decision to the server).
1437
+ */
1438
+ resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
1395
1439
  /**
1396
1440
  * Callback when streaming finishes
1397
1441
  */
@@ -1564,4 +1608,4 @@ interface UseLongTextConversionReturn {
1564
1608
  */
1565
1609
  declare function useLongTextConversion({ threshold, filenameTemplate, onConversion, }?: LongTextConversionOptions): UseLongTextConversionReturn;
1566
1610
 
1567
- 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, 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 };
1611
+ 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 };
package/dist/index.d.ts CHANGED
@@ -18,6 +18,10 @@ interface ConversationContextValue {
18
18
  autoScroll: boolean;
19
19
  /** Set auto-scroll state */
20
20
  setAutoScroll: (value: boolean) => void;
21
+ /** Whether more messages exist above */
22
+ hasMore: boolean;
23
+ /** Whether older messages are currently being fetched */
24
+ isLoadingMore: boolean;
21
25
  }
22
26
  declare function useConversation(): ConversationContextValue;
23
27
  interface ConversationProps {
@@ -29,8 +33,16 @@ interface ConversationProps {
29
33
  autoScroll?: boolean;
30
34
  /** Threshold in pixels to consider "at bottom" */
31
35
  scrollThreshold?: number;
32
- }
33
- declare function Conversation({ children, className, autoScroll: initialAutoScroll, scrollThreshold, }: ConversationProps): react_jsx_runtime.JSX.Element;
36
+ /** Called when user scrolls near the top to load older messages */
37
+ onLoadMore?: () => void;
38
+ /** Whether more messages exist above */
39
+ hasMore?: boolean;
40
+ /** Whether older messages are currently being fetched */
41
+ isLoadingMore?: boolean;
42
+ /** Pixels from top to trigger onLoadMore (default: 100) */
43
+ loadMoreThreshold?: number;
44
+ }
45
+ declare function Conversation({ children, className, autoScroll: initialAutoScroll, scrollThreshold, onLoadMore, hasMore, isLoadingMore, loadMoreThreshold, }: ConversationProps): react_jsx_runtime.JSX.Element;
34
46
  interface ConversationContentProps {
35
47
  /** Child elements */
36
48
  children: ReactNode;
@@ -52,6 +64,11 @@ interface ConversationScrollButtonProps {
52
64
  label?: string;
53
65
  }
54
66
  declare function ConversationScrollButton({ className, label, }: ConversationScrollButtonProps): react_jsx_runtime.JSX.Element | null;
67
+ interface ConversationLoadMoreProps {
68
+ /** Additional class name */
69
+ className?: string;
70
+ }
71
+ declare function ConversationLoadMore({ className, }: ConversationLoadMoreProps): react_jsx_runtime.JSX.Element | null;
55
72
 
56
73
  interface MessageContextValue {
57
74
  /** Message role */
@@ -1042,6 +1059,7 @@ interface StreamEvent {
1042
1059
  text?: string;
1043
1060
  /** Message content array (for 'message' events) */
1044
1061
  content?: unknown;
1062
+ requestId?: string;
1045
1063
  toolId?: string;
1046
1064
  toolName?: string;
1047
1065
  input?: unknown;
@@ -1054,6 +1072,8 @@ interface StreamEvent {
1054
1072
  result?: string;
1055
1073
  totalCost?: number;
1056
1074
  totalTokens?: number;
1075
+ stop_reason?: string;
1076
+ stop_sequence?: string;
1057
1077
  /** SSE event ID (sequence number from relay) for reconnection */
1058
1078
  id?: string;
1059
1079
  entry?: {
@@ -1064,6 +1084,12 @@ interface StreamEvent {
1064
1084
  data?: Record<string, unknown>;
1065
1085
  };
1066
1086
  }
1087
+ interface ToolPermissionRequest {
1088
+ requestId: string;
1089
+ sessionId: string;
1090
+ toolName: string;
1091
+ input?: unknown;
1092
+ }
1067
1093
  /**
1068
1094
  * Async generator that yields StreamEvent objects
1069
1095
  */
@@ -1187,6 +1213,15 @@ interface UseAgentChatOptions {
1187
1213
  * Callback for sandbox log events
1188
1214
  */
1189
1215
  onSandboxLog?: (entry: NonNullable<StreamEvent['entry']>) => void;
1216
+ /**
1217
+ * Callback to approve/deny tool usage requests.
1218
+ * When provided, tool permission events will be resolved automatically.
1219
+ */
1220
+ canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
1221
+ /**
1222
+ * Function to resolve a tool permission request (sends the decision to the server).
1223
+ */
1224
+ resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
1190
1225
  /**
1191
1226
  * Callback when reconnection is attempted
1192
1227
  */
@@ -1392,6 +1427,15 @@ interface UseChatOptions {
1392
1427
  * Callback when a tool is called
1393
1428
  */
1394
1429
  onToolCall?: (handler: ToolCallHandler) => void;
1430
+ /**
1431
+ * Callback to approve/deny tool usage requests.
1432
+ * When provided, tool permission events will be resolved automatically.
1433
+ */
1434
+ canUseTool?: (request: ToolPermissionRequest) => boolean | Promise<boolean>;
1435
+ /**
1436
+ * Function to resolve a tool permission request (sends the decision to the server).
1437
+ */
1438
+ resolveToolPermission?: (request: ToolPermissionRequest, allow: boolean) => Promise<void>;
1395
1439
  /**
1396
1440
  * Callback when streaming finishes
1397
1441
  */
@@ -1564,4 +1608,4 @@ interface UseLongTextConversionReturn {
1564
1608
  */
1565
1609
  declare function useLongTextConversion({ threshold, filenameTemplate, onConversion, }?: LongTextConversionOptions): UseLongTextConversionReturn;
1566
1610
 
1567
- 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, 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 };
1611
+ 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 };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, lazy, useContext, useRef, useState, useCallback, useEffect, useMemo, Suspense } from 'react';
1
+ import { createContext, lazy, useContext, useRef, useState, useCallback, useEffect, useLayoutEffect, useMemo, Suspense } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
 
4
4
  // src/components/Conversation.tsx
@@ -421,11 +421,17 @@ function Conversation({
421
421
  children,
422
422
  className,
423
423
  autoScroll: initialAutoScroll = true,
424
- scrollThreshold = 100
424
+ scrollThreshold = 100,
425
+ onLoadMore,
426
+ hasMore = false,
427
+ isLoadingMore = false,
428
+ loadMoreThreshold = 100
425
429
  }) {
426
430
  const containerRef = useRef(null);
427
431
  const [isScrolledUp, setIsScrolledUp] = useState(false);
428
432
  const [autoScroll, setAutoScroll] = useState(initialAutoScroll);
433
+ const prevScrollHeightRef = useRef(0);
434
+ const wasLoadingMoreRef = useRef(false);
429
435
  const scrollToBottom = useCallback((behavior = "smooth") => {
430
436
  if (containerRef.current) {
431
437
  containerRef.current.scrollTo({
@@ -443,7 +449,26 @@ function Conversation({
443
449
  if (isAtBottom && !autoScroll) {
444
450
  setAutoScroll(true);
445
451
  }
446
- }, [scrollThreshold, autoScroll]);
452
+ if (scrollTop < loadMoreThreshold && hasMore && !isLoadingMore && onLoadMore) {
453
+ onLoadMore();
454
+ }
455
+ }, [scrollThreshold, autoScroll, loadMoreThreshold, hasMore, isLoadingMore, onLoadMore]);
456
+ useEffect(() => {
457
+ if (isLoadingMore && !wasLoadingMoreRef.current && containerRef.current) {
458
+ prevScrollHeightRef.current = containerRef.current.scrollHeight;
459
+ }
460
+ wasLoadingMoreRef.current = isLoadingMore;
461
+ }, [isLoadingMore]);
462
+ useLayoutEffect(() => {
463
+ if (!isLoadingMore && prevScrollHeightRef.current > 0 && containerRef.current) {
464
+ const newScrollHeight = containerRef.current.scrollHeight;
465
+ const scrollDelta = newScrollHeight - prevScrollHeightRef.current;
466
+ if (scrollDelta > 0) {
467
+ containerRef.current.scrollTop += scrollDelta;
468
+ }
469
+ prevScrollHeightRef.current = 0;
470
+ }
471
+ }, [isLoadingMore]);
447
472
  useEffect(() => {
448
473
  if (autoScroll && !isScrolledUp) {
449
474
  scrollToBottom("instant");
@@ -454,7 +479,9 @@ function Conversation({
454
479
  scrollToBottom,
455
480
  isScrolledUp,
456
481
  autoScroll,
457
- setAutoScroll
482
+ setAutoScroll,
483
+ hasMore,
484
+ isLoadingMore
458
485
  };
459
486
  return /* @__PURE__ */ jsx(ConversationContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
460
487
  "div",
@@ -552,6 +579,50 @@ function ConversationScrollButton({
552
579
  }
553
580
  );
554
581
  }
582
+ function ConversationLoadMore({
583
+ className
584
+ }) {
585
+ const { hasMore, isLoadingMore } = useConversation();
586
+ if (!hasMore && !isLoadingMore) return null;
587
+ return /* @__PURE__ */ jsx(
588
+ "div",
589
+ {
590
+ className: cn(
591
+ "ash-conversation-load-more flex items-center justify-center py-3",
592
+ className
593
+ ),
594
+ children: isLoadingMore && /* @__PURE__ */ jsxs(
595
+ "svg",
596
+ {
597
+ className: "w-5 h-5 animate-spin text-[var(--ash-text-muted,rgba(255,255,255,0.5))]",
598
+ fill: "none",
599
+ viewBox: "0 0 24 24",
600
+ children: [
601
+ /* @__PURE__ */ jsx(
602
+ "circle",
603
+ {
604
+ className: "opacity-25",
605
+ cx: "12",
606
+ cy: "12",
607
+ r: "10",
608
+ stroke: "currentColor",
609
+ strokeWidth: "4"
610
+ }
611
+ ),
612
+ /* @__PURE__ */ jsx(
613
+ "path",
614
+ {
615
+ className: "opacity-75",
616
+ fill: "currentColor",
617
+ d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
618
+ }
619
+ )
620
+ ]
621
+ }
622
+ )
623
+ }
624
+ );
625
+ }
555
626
  var ReactMarkdown = lazy(() => import('react-markdown'));
556
627
  function LazyMarkdown({ children, fallback, components, className }) {
557
628
  const [mounted, setMounted] = useState(false);
@@ -3593,6 +3664,8 @@ function useAgentChat(options) {
3593
3664
  onSessionEnd,
3594
3665
  onError,
3595
3666
  onSandboxLog,
3667
+ canUseTool,
3668
+ resolveToolPermission,
3596
3669
  onReconnect,
3597
3670
  maxReconnectAttempts = 3,
3598
3671
  reconnectBaseDelay = 1e3,
@@ -3626,6 +3699,23 @@ function useAgentChat(options) {
3626
3699
  const emitStreamingEntries = useCallback((newEntries) => {
3627
3700
  setStreamingEntries([...newEntries]);
3628
3701
  }, []);
3702
+ const handleToolPermission = useCallback(async (event) => {
3703
+ if (event.type !== "tool_permission") return;
3704
+ if (!canUseTool) return;
3705
+ if (!event.requestId || !event.sessionId || !event.toolName) return;
3706
+ const request = {
3707
+ requestId: event.requestId,
3708
+ sessionId: event.sessionId,
3709
+ toolName: event.toolName,
3710
+ input: event.input
3711
+ };
3712
+ const allow = await canUseTool(request);
3713
+ if (!resolveToolPermission) {
3714
+ console.warn("[useAgentChat] resolveToolPermission not provided for tool permission response");
3715
+ return;
3716
+ }
3717
+ await resolveToolPermission(request, allow);
3718
+ }, [canUseTool, resolveToolPermission]);
3629
3719
  const createTextEntry = useCallback((id, content) => ({
3630
3720
  id,
3631
3721
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3784,6 +3874,7 @@ function useAgentChat(options) {
3784
3874
  for await (const event of stream) {
3785
3875
  if (controller.signal.aborted) break;
3786
3876
  eventCountRef.current++;
3877
+ await handleToolPermission(event);
3787
3878
  localStreamingEntries = processEvent(event, localStreamingEntries);
3788
3879
  emitStreamingEntries(localStreamingEntries);
3789
3880
  if (event.type === "complete" || event.type === "session_end" || event.type === "error") {
@@ -3817,7 +3908,7 @@ function useAgentChat(options) {
3817
3908
  }
3818
3909
  return false;
3819
3910
  }
3820
- }, [subscribeToSession, maxReconnectAttempts, reconnectBaseDelay, onReconnect, processEvent, emitStreamingEntries]);
3911
+ }, [subscribeToSession, maxReconnectAttempts, reconnectBaseDelay, onReconnect, processEvent, emitStreamingEntries, handleToolPermission]);
3821
3912
  const send = useCallback(async (prompt) => {
3822
3913
  if (isStreaming) return;
3823
3914
  let finalPrompt = prompt;
@@ -3896,6 +3987,7 @@ function useAgentChat(options) {
3896
3987
  console.error("[useAgentChat] onEvent error:", err);
3897
3988
  }
3898
3989
  }
3990
+ await handleToolPermission(event);
3899
3991
  let processedEvent = event;
3900
3992
  if (middleware?.length) {
3901
3993
  processedEvent = await applyEventMiddleware(middleware, event);
@@ -3945,7 +4037,7 @@ function useAgentChat(options) {
3945
4037
  abortControllerRef.current = null;
3946
4038
  resetStreamingState();
3947
4039
  }
3948
- }, [isStreaming, sessionId, historyEntries, streamingEntries, createStream, subscribeToSession, processEvent, emitStreamingEntries, resetStreamingState, onError, attemptReconnect, onBeforeSend, onEvent, middleware]);
4040
+ }, [isStreaming, sessionId, historyEntries, streamingEntries, createStream, subscribeToSession, processEvent, emitStreamingEntries, resetStreamingState, onError, attemptReconnect, onBeforeSend, onEvent, middleware, handleToolPermission]);
3949
4041
  const stop = useCallback(() => {
3950
4042
  reconnectAttemptsRef.current = maxReconnectAttempts + 1;
3951
4043
  setIsReconnecting(false);
@@ -3996,6 +4088,8 @@ function useChat(options) {
3996
4088
  initialSessionId,
3997
4089
  initialMessages = [],
3998
4090
  onToolCall,
4091
+ canUseTool,
4092
+ resolveToolPermission,
3999
4093
  onFinish,
4000
4094
  onError,
4001
4095
  onSessionStart,
@@ -4030,6 +4124,23 @@ function useChat(options) {
4030
4124
  return prev;
4031
4125
  });
4032
4126
  }, []);
4127
+ const handleToolPermission = useCallback(async (event) => {
4128
+ if (event.type !== "tool_permission") return;
4129
+ if (!canUseTool) return;
4130
+ if (!event.requestId || !event.sessionId || !event.toolName) return;
4131
+ const request = {
4132
+ requestId: event.requestId,
4133
+ sessionId: event.sessionId,
4134
+ toolName: event.toolName,
4135
+ input: event.input
4136
+ };
4137
+ const allow = await canUseTool(request);
4138
+ if (!resolveToolPermission) {
4139
+ console.warn("[useChat] resolveToolPermission not provided for tool permission response");
4140
+ return;
4141
+ }
4142
+ await resolveToolPermission(request, allow);
4143
+ }, [canUseTool, resolveToolPermission]);
4033
4144
  const processEvent = useCallback((event) => {
4034
4145
  switch (event.type) {
4035
4146
  case "session_start":
@@ -4149,6 +4260,7 @@ function useChat(options) {
4149
4260
  const stream = createStream(finalPrompt, sessionIdRef.current || void 0, streamOptions);
4150
4261
  for await (const event of stream) {
4151
4262
  if (controller.signal.aborted) break;
4263
+ await handleToolPermission(event);
4152
4264
  let processedEvent = event;
4153
4265
  if (middleware?.length) {
4154
4266
  processedEvent = await applyEventMiddleware(middleware, event);
@@ -4178,7 +4290,7 @@ function useChat(options) {
4178
4290
  abortControllerRef.current = null;
4179
4291
  currentAssistantMessageRef.current = null;
4180
4292
  }
4181
- }, [isLoading, createStream, processEvent, middleware, onError]);
4293
+ }, [isLoading, createStream, processEvent, middleware, onError, handleToolPermission]);
4182
4294
  const stop = useCallback(() => {
4183
4295
  reconnectAttemptsRef.current = maxReconnectAttempts + 1;
4184
4296
  setIsReconnecting(false);
@@ -4307,6 +4419,6 @@ function useLongTextConversion({
4307
4419
  };
4308
4420
  }
4309
4421
 
4310
- 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, 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 };
4422
+ 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 };
4311
4423
  //# sourceMappingURL=index.js.map
4312
4424
  //# sourceMappingURL=index.js.map