@yushaw/sanqian-chat 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.
@@ -61,6 +61,12 @@ interface ChatUiStrings {
61
61
  hitlInputRequest: string;
62
62
  hitlApprovalRequired: string;
63
63
  hitlInputRequired: string;
64
+ attachWindow: string;
65
+ detachWindow: string;
66
+ floatWindow: string;
67
+ embedWindow: string;
68
+ collapseSidebar: string;
69
+ history: string;
64
70
  }
65
71
  type ChatThemeMode = 'light' | 'dark' | 'auto';
66
72
  type ChatFontSize = 'small' | 'normal' | 'large' | 'extra-large';
@@ -158,6 +164,153 @@ interface FloatingWindowConfig {
158
164
  /** Optional full path for window state file */
159
165
  windowStatePath?: string;
160
166
  }
167
+ type ChatPanelMode = 'embedded' | 'floating';
168
+ type ChatPanelPosition = 'right' | 'left';
169
+ type AttachState = 'attached' | 'detached' | 'unavailable';
170
+ type AttachPosition = 'right' | 'left' | 'top' | 'bottom';
171
+ /**
172
+ * Window attachment configuration for floating mode
173
+ */
174
+ interface AttachConfig {
175
+ /**
176
+ * Target window to attach to (BrowserWindow instance)
177
+ */
178
+ window: unknown;
179
+ /**
180
+ * Attach position relative to target window
181
+ * @default 'right'
182
+ */
183
+ position?: AttachPosition;
184
+ /**
185
+ * Gap between windows (px)
186
+ * @default 0
187
+ */
188
+ gap?: number;
189
+ /**
190
+ * Sync height/width with target window
191
+ * @default true
192
+ */
193
+ syncSize?: boolean;
194
+ /**
195
+ * Behavior when target window is minimized
196
+ * @default 'hide'
197
+ */
198
+ onMinimize?: 'hide' | 'detach' | 'minimize';
199
+ /**
200
+ * Behavior when target window is closed
201
+ * @default 'hide'
202
+ */
203
+ onClose?: 'hide' | 'destroy';
204
+ /**
205
+ * Allow user to drag and detach
206
+ * @default true
207
+ */
208
+ allowDetach?: boolean;
209
+ /**
210
+ * Allow re-attach when dragged near target edge
211
+ * @default true
212
+ */
213
+ allowReattach?: boolean;
214
+ /**
215
+ * Distance threshold for re-attach (px)
216
+ * @default 20
217
+ */
218
+ reattachThreshold?: number;
219
+ }
220
+ /**
221
+ * ChatPanel configuration
222
+ */
223
+ interface ChatPanelConfig {
224
+ /**
225
+ * Host window (BaseWindow supports embedded, BrowserWindow floating only)
226
+ */
227
+ hostWindow: unknown;
228
+ /**
229
+ * Host window's main content view (required for embedded mode)
230
+ */
231
+ hostMainView?: unknown;
232
+ /**
233
+ * Initial mode
234
+ * @default 'embedded'
235
+ */
236
+ initialMode?: ChatPanelMode;
237
+ /**
238
+ * Embed position
239
+ * @default 'right'
240
+ */
241
+ position?: ChatPanelPosition;
242
+ /**
243
+ * Panel width
244
+ * @default 360
245
+ */
246
+ width?: number;
247
+ /**
248
+ * Minimum width
249
+ * @default 240
250
+ */
251
+ minWidth?: number;
252
+ /**
253
+ * Minimum host content width when showing panel.
254
+ * If window is too narrow, expand it to ensure main content has this width.
255
+ * Set to 0 to disable auto-expand.
256
+ * @default 0
257
+ */
258
+ minHostContentWidth?: number;
259
+ /**
260
+ * Allow resize
261
+ * @default true
262
+ */
263
+ resizable?: boolean;
264
+ /**
265
+ * Preload script path
266
+ */
267
+ preloadPath: string;
268
+ /**
269
+ * Renderer HTML path or URL
270
+ */
271
+ rendererPath: string;
272
+ /**
273
+ * Dev mode - load URL instead of file
274
+ */
275
+ devMode?: boolean;
276
+ /**
277
+ * SDK client getter
278
+ */
279
+ getClient: () => unknown;
280
+ /**
281
+ * Agent ID getter
282
+ */
283
+ getAgentId: () => string | null;
284
+ /**
285
+ * Layout change callback (for host app to adjust main content)
286
+ */
287
+ onLayoutChange?: (layout: {
288
+ mainWidth: number;
289
+ chatWidth: number;
290
+ chatVisible: boolean;
291
+ }) => void;
292
+ /**
293
+ * Shortcut configuration
294
+ */
295
+ shortcuts?: {
296
+ /** Toggle show/hide, false to disable */
297
+ toggle?: string | false;
298
+ /** Toggle mode, false to disable */
299
+ toggleMode?: string | false;
300
+ };
301
+ /**
302
+ * Floating window attach configuration
303
+ */
304
+ attach?: AttachConfig;
305
+ /**
306
+ * State persistence key
307
+ */
308
+ stateKey?: string;
309
+ /**
310
+ * UI config for renderer
311
+ */
312
+ uiConfig?: ChatUiConfigSerializable;
313
+ }
161
314
 
162
315
  /**
163
316
  * Chat Adapter Interface
@@ -390,6 +543,12 @@ interface Translations {
390
543
  delete: string;
391
544
  deleteConfirm: string;
392
545
  };
546
+ panel: {
547
+ attachWindow: string;
548
+ detachWindow: string;
549
+ floatWindow: string;
550
+ embedWindow: string;
551
+ };
393
552
  }
394
553
  interface I18nContextValue {
395
554
  locale: Locale;
@@ -516,6 +675,43 @@ declare function useIpcUiConfig(): ChatUiConfigSerializable | null;
516
675
 
517
676
  declare function useResolvedUiConfig(config?: ChatUiConfig): ChatUiConfig | undefined;
518
677
 
678
+ /**
679
+ * useChatPanel - Hook for ChatPanel state management
680
+ *
681
+ * Provides reactive access to panel mode, visibility, and width.
682
+ */
683
+
684
+ interface UseChatPanelReturn {
685
+ mode: ChatPanelMode;
686
+ visible: boolean;
687
+ width: number;
688
+ isEmbedded: boolean;
689
+ isFloating: boolean;
690
+ setMode: (mode: ChatPanelMode) => Promise<void>;
691
+ toggleMode: () => Promise<ChatPanelMode>;
692
+ show: () => Promise<void>;
693
+ hide: () => Promise<void>;
694
+ toggle: () => Promise<void>;
695
+ setWidth: (width: number, animate?: boolean) => Promise<void>;
696
+ onResizeEnd: () => Promise<void>;
697
+ }
698
+ declare function useChatPanel(): UseChatPanelReturn;
699
+
700
+ /**
701
+ * useAttachState - Hook for floating window attachment state
702
+ *
703
+ * Provides reactive access to attach/detach state in floating mode.
704
+ */
705
+
706
+ interface UseAttachStateReturn {
707
+ state: AttachState;
708
+ isAttached: boolean;
709
+ isAvailable: boolean;
710
+ isLoading: boolean;
711
+ toggle: () => Promise<AttachState>;
712
+ }
713
+ declare function useAttachState(): UseAttachStateReturn;
714
+
519
715
  /**
520
716
  * IPC Adapter
521
717
  *
@@ -738,6 +934,22 @@ interface HistoryListProps {
738
934
  }
739
935
  declare const HistoryList: react.NamedExoticComponent<HistoryListProps>;
740
936
 
937
+ interface HistoryModalProps {
938
+ /** Whether the modal is open */
939
+ isOpen: boolean;
940
+ /** Called when the modal should close */
941
+ onClose: () => void;
942
+ /** Modal title */
943
+ title?: string;
944
+ /** Close button label for accessibility */
945
+ closeLabel?: string;
946
+ /** Modal content */
947
+ children: ReactNode;
948
+ /** Dark mode */
949
+ isDarkMode?: boolean;
950
+ }
951
+ declare const HistoryModal: react.NamedExoticComponent<HistoryModalProps>;
952
+
741
953
  declare function resolveChatStrings(locale?: Locale, overrides?: Partial<ChatUiStrings>): ChatUiStrings;
742
954
 
743
955
  type AlertType = 'warning' | 'error';
@@ -841,6 +1053,93 @@ interface CompactChatProps {
841
1053
  }
842
1054
  declare const CompactChat: react.NamedExoticComponent<CompactChatProps>;
843
1055
 
1056
+ /**
1057
+ * ModeToggleButton - Toggle between embedded and floating mode
1058
+ */
1059
+ interface ModeToggleButtonProps {
1060
+ className?: string;
1061
+ locale?: 'en' | 'zh';
1062
+ }
1063
+ declare function ModeToggleButton({ className, locale }: ModeToggleButtonProps): react_jsx_runtime.JSX.Element;
1064
+
1065
+ /**
1066
+ * AttachButton - Toggle window attachment state (floating mode only)
1067
+ */
1068
+ interface AttachButtonProps {
1069
+ className?: string;
1070
+ locale?: 'en' | 'zh';
1071
+ }
1072
+ declare function AttachButton({ className, locale }: AttachButtonProps): react_jsx_runtime.JSX.Element | null;
1073
+
1074
+ /**
1075
+ * Resizer - Drag handle for adjusting panel width in embedded mode
1076
+ *
1077
+ * Features:
1078
+ * - Drag to resize
1079
+ * - Double-click to reset to default width
1080
+ * - Smooth hover feedback
1081
+ * - Visual indicator during drag
1082
+ */
1083
+ interface ResizerProps {
1084
+ /** Position of the resizer (which side of the panel) */
1085
+ position?: 'left' | 'right';
1086
+ /** Minimum width */
1087
+ minWidth?: number;
1088
+ /** Maximum width */
1089
+ maxWidth?: number;
1090
+ /** Default width (for double-click reset) */
1091
+ defaultWidth?: number;
1092
+ /** Additional class name */
1093
+ className?: string;
1094
+ }
1095
+ declare function Resizer({ position, minWidth, maxWidth, defaultWidth, className, }: ResizerProps): react_jsx_runtime.JSX.Element | null;
1096
+
1097
+ interface PanelControlsProps {
1098
+ /** Show mode toggle button (embedded <-> floating) */
1099
+ showModeToggle?: boolean;
1100
+ /** Show attach button (attached <-> detached in floating mode) */
1101
+ showAttachToggle?: boolean;
1102
+ /** Show resizer for width adjustment (embedded mode only) */
1103
+ showResizer?: boolean;
1104
+ /** Resizer position */
1105
+ resizerPosition?: 'left' | 'right';
1106
+ /** Resizer min width */
1107
+ resizerMinWidth?: number;
1108
+ /** Resizer max width */
1109
+ resizerMaxWidth?: number;
1110
+ /** Locale for i18n */
1111
+ locale?: 'en' | 'zh';
1112
+ }
1113
+ /**
1114
+ * Header buttons for panel mode/attach control
1115
+ */
1116
+ declare function PanelHeaderButtons({ showModeToggle, showAttachToggle, locale, }: Pick<PanelControlsProps, 'showModeToggle' | 'showAttachToggle' | 'locale'>): react_jsx_runtime.JSX.Element;
1117
+ /**
1118
+ * Panel resizer component wrapper
1119
+ */
1120
+ declare function PanelResizer({ showResizer, resizerPosition, resizerMinWidth, resizerMaxWidth, }: Pick<PanelControlsProps, 'showResizer' | 'resizerPosition' | 'resizerMinWidth' | 'resizerMaxWidth'>): react_jsx_runtime.JSX.Element | null;
1121
+ /**
1122
+ * Full panel controls - includes both header buttons and resizer
1123
+ *
1124
+ * Usage:
1125
+ * ```tsx
1126
+ * // In your chat component
1127
+ * <div className="relative">
1128
+ * <PanelControls.Resizer />
1129
+ * <header>
1130
+ * ...
1131
+ * <PanelControls.HeaderButtons />
1132
+ * </header>
1133
+ * </div>
1134
+ * ```
1135
+ */
1136
+ declare const PanelControls: {
1137
+ HeaderButtons: typeof PanelHeaderButtons;
1138
+ Resizer: typeof PanelResizer;
1139
+ ModeToggleButton: typeof ModeToggleButton;
1140
+ AttachButton: typeof AttachButton;
1141
+ };
1142
+
844
1143
  /**
845
1144
  * Tool Arguments Display Component
846
1145
  *
@@ -928,4 +1227,4 @@ declare function ensureChatBaseStyles(): void;
928
1227
  */
929
1228
  declare function ensureFullChatStyles(): void;
930
1229
 
931
- export { type AlertAction, AlertBanner, type AlertBannerProps, type AlertConfig, type AlertType, type ChatAdapter, type ChatAdapterConfig, type ChatFontSize, ChatInput, type ChatInputHandle, type ChatInputProps, type ChatThemeMode, type ChatUiConfig, type ChatUiConfigSerializable, type ChatUiStrings, CompactChat, type CompactChatProps, type ConnectionErrorCode, type ConnectionStatus, type ConversationDetail, type ConversationInfo, FloatingChat, type FloatingChatProps, type FloatingWindowConfig, HistoryList, type HistoryListProps, HitlCard, type HitlCardProps, type HitlInterruptData, I18nProvider, type I18nProviderProps, IntermediateSteps, type IntermediateStepsProps, type Locale, MarkdownRenderer, type MarkdownRendererProps, type MessageBlock, MessageBubble, type MessageBubbleProps, MessageList, type MessageListProps, type MessageRole, type ResolvedTheme, SanqianChat, SanqianChatMessage, type SanqianChatMessageProps, type SanqianChatProps, SanqianMessageList, type SanqianMessageListHandle, type SanqianMessageListProps, type SdkAdapterConfig, type SendMessage, type StreamEvent, StreamingTimeline, type StreamingTimelineProps, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThinkingSection, type ThinkingSectionProps, ToolArgumentsDisplay, type ToolArgumentsDisplayProps, type ToolCall, type ToolCallStatus, type Translations, type UseChatOptions, type UseChatReturn, type UseConnectionOptions, type UseConnectionReturn, type UseConversationsOptions, type UseConversationsReturn, type UseFocusPersistenceOptions, type WindowPosition, createChatAdapter, createIpcAdapter, createSdkAdapter, ensureChatBaseStyles, ensureFullChatStyles, getTranslations, resolveChatStrings, useChat, useChatStyles, useConnection, useConversations, useFocusPersistence, useI18n, useIpcUiConfig, useResolvedUiConfig, useStandaloneI18n, useStandaloneTheme, useTheme };
1230
+ export { type AlertAction, AlertBanner, type AlertBannerProps, type AlertConfig, type AlertType, AttachButton, type AttachButtonProps, type AttachConfig, type AttachPosition, type AttachState, type ChatAdapter, type ChatAdapterConfig, type ChatFontSize, ChatInput, type ChatInputHandle, type ChatInputProps, type ChatPanelConfig, type ChatPanelMode, type ChatPanelPosition, type ChatThemeMode, type ChatUiConfig, type ChatUiConfigSerializable, type ChatUiStrings, CompactChat, type CompactChatProps, type ConnectionErrorCode, type ConnectionStatus, type ConversationDetail, type ConversationInfo, FloatingChat, type FloatingChatProps, type FloatingWindowConfig, HistoryList, type HistoryListProps, HistoryModal, type HistoryModalProps, HitlCard, type HitlCardProps, type HitlInterruptData, I18nProvider, type I18nProviderProps, IntermediateSteps, type IntermediateStepsProps, type Locale, MarkdownRenderer, type MarkdownRendererProps, type MessageBlock, MessageBubble, type MessageBubbleProps, MessageList, type MessageListProps, type MessageRole, ModeToggleButton, type ModeToggleButtonProps, PanelControls, type PanelControlsProps, PanelHeaderButtons, PanelResizer, Resizer, type ResizerProps, type ResolvedTheme, SanqianChat, SanqianChatMessage, type SanqianChatMessageProps, type SanqianChatProps, SanqianMessageList, type SanqianMessageListHandle, type SanqianMessageListProps, type SdkAdapterConfig, type SendMessage, type StreamEvent, StreamingTimeline, type StreamingTimelineProps, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThinkingSection, type ThinkingSectionProps, ToolArgumentsDisplay, type ToolArgumentsDisplayProps, type ToolCall, type ToolCallStatus, type Translations, type UseAttachStateReturn, type UseChatOptions, type UseChatPanelReturn, type UseChatReturn, type UseConnectionOptions, type UseConnectionReturn, type UseConversationsOptions, type UseConversationsReturn, type UseFocusPersistenceOptions, type WindowPosition, createChatAdapter, createIpcAdapter, createSdkAdapter, ensureChatBaseStyles, ensureFullChatStyles, getTranslations, resolveChatStrings, useAttachState, useChat, useChatPanel, useChatStyles, useConnection, useConversations, useFocusPersistence, useI18n, useIpcUiConfig, useResolvedUiConfig, useStandaloneI18n, useStandaloneTheme, useTheme };