@xinghunm/ai-chat 1.4.4 → 1.6.0

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.mts CHANGED
@@ -69,6 +69,21 @@ interface ChatHistorySessionListHandlers {
69
69
  onSelectHistorySession?: (session: ChatSession) => Promise<ChatHistorySessionMessagesPage | ChatMessage[] | void> | ChatHistorySessionMessagesPage | ChatMessage[] | void;
70
70
  onLoadMoreHistoryMessages?: (args: ChatHistorySessionMessageLoadArgs) => Promise<ChatHistorySessionMessagesPage | void> | ChatHistorySessionMessagesPage | void;
71
71
  }
72
+ /**
73
+ * Arguments passed to custom history session action renderers.
74
+ */
75
+ interface ChatSessionItemActionRenderProps {
76
+ session: ChatSession;
77
+ isActive: boolean;
78
+ isStreaming: boolean;
79
+ selectSession: () => Promise<void>;
80
+ startNewChat: () => void;
81
+ stopSession: () => Promise<void>;
82
+ }
83
+ /**
84
+ * Optional renderer used to append custom actions to a history session item.
85
+ */
86
+ type ChatSessionItemActionsRenderer = (args: ChatSessionItemActionRenderProps) => ReactNode;
72
87
  /**
73
88
  * Client-side image attachment metadata kept in chat messages.
74
89
  */
@@ -144,7 +159,7 @@ interface PlanBooleanQuestion extends PlanQuestionBase {
144
159
  * Supported question variants in a plan questionnaire.
145
160
  */
146
161
  type PlanQuestion = PlanSingleSelectQuestion | PlanMultiSelectQuestion | PlanTextQuestion | PlanNumberQuestion | PlanBooleanQuestion;
147
- type PlanQuestionnaireStatus = 'expired' | 'failed';
162
+ type PlanQuestionnaireStatus = 'expired' | 'failed' | 'submitted';
148
163
  /**
149
164
  * Merge behavior applied when a keyed structured block is patched repeatedly.
150
165
  */
@@ -177,6 +192,10 @@ interface PlanQuestionnaire {
177
192
  answers?: Partial<Record<string, PlanQuestionnaireAnswerValue>>;
178
193
  status?: PlanQuestionnaireStatus;
179
194
  statusMessage?: string;
195
+ /**
196
+ * Timeout in seconds for the questionnaire interaction.
197
+ */
198
+ timeoutSec?: number;
180
199
  }
181
200
  interface PlanQuestionSubmissionDetail {
182
201
  questionId: string;
@@ -478,6 +497,7 @@ interface AiChatLabels {
478
497
  questionnaireMultiSelectHint?: string;
479
498
  questionnaireOtherOptionLabel?: string;
480
499
  questionnaireOtherPlaceholder?: string;
500
+ questionnaireExpired?: string;
481
501
  modelLoading?: string;
482
502
  modelLoadFailed?: string;
483
503
  modelUnavailable?: string;
@@ -487,6 +507,8 @@ interface AiChatLabels {
487
507
  sessionHistoryLoading?: string;
488
508
  sessionHistoryLoadFailed?: string;
489
509
  sessionHistoryEmpty?: string;
510
+ questionnaireTitle?: string;
511
+ questionnaireConfirmInTime?: string;
490
512
  }
491
513
  /**
492
514
  * State and actions exposed to custom new-chat trigger renderers.
@@ -499,6 +521,13 @@ interface NewChatTriggerRenderProps {
499
521
  stopActiveSession: () => Promise<void>;
500
522
  startNewChat: () => Promise<void>;
501
523
  }
524
+ /**
525
+ * State exposed to optional composer mode accessory renderers.
526
+ */
527
+ interface ChatComposerModeAccessoryRenderProps {
528
+ selectedMode: ChatAgentMode;
529
+ disabled: boolean;
530
+ }
502
531
  /**
503
532
  * Default English label values used when no labels are provided.
504
533
  */
@@ -525,6 +554,8 @@ interface AiChatProviderBaseProps {
525
554
  onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
526
555
  /** Optional callback used when the active historical session needs older messages. */
527
556
  onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
557
+ /** Optional renderer used to append custom actions to a history session item. */
558
+ renderSessionItemActions?: ChatSessionItemActionsRenderer;
528
559
  /**
529
560
  * Whether to enable image attachment uploads. Defaults to `true`.
530
561
  * Set to `false` to hide the upload button, disable paste-image handling,
@@ -584,12 +615,14 @@ type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
584
615
  * a streaming message, or an error to render.
585
616
  */
586
617
  onConversationStartedChange?: (started: boolean) => void;
618
+ /** Optional renderer used to append extra controls next to the mode selector. */
619
+ renderComposerModeAccessory?: (props: ChatComposerModeAccessoryRenderProps) => ReactNode;
587
620
  };
588
621
  /**
589
622
  * Top-level AI chat component. Wraps AiChatProvider and composes the full
590
623
  * chat UI: optional conversation sidebar + thread + composer.
591
624
  */
592
- declare const AiChat: ({ showConversationList, showNewChatButton, renderNewChatTrigger, showComposerOnlyBeforeFirstMessage, onConversationStartedChange, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
625
+ declare const AiChat: ({ showConversationList, showNewChatButton, renderNewChatTrigger, showComposerOnlyBeforeFirstMessage, onConversationStartedChange, renderComposerModeAccessory, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
593
626
 
594
627
  /**
595
628
  * Endpoint overrides for the built-in HTTP transport adapter.
@@ -707,6 +740,7 @@ interface ChatComposerViewProps {
707
740
  modelLoadingLabel: string;
708
741
  modelLoadFailedLabel: string;
709
742
  modelUnavailableLabel: string;
743
+ modeAccessory?: ReactNode;
710
744
  onValueChange: (value: string) => void;
711
745
  onPickImages: (files: FileList | File[]) => void;
712
746
  onPasteImages: (files: File[]) => void;
@@ -722,7 +756,9 @@ interface ChatComposerViewProps {
722
756
  /** Called to send a new user message. */
723
757
  onSend: () => void | Promise<void>;
724
758
  }
725
- declare const ChatComposer: () => _emotion_react_jsx_runtime.JSX.Element;
759
+ declare const ChatComposer: ({ renderModeAccessory, }?: {
760
+ renderModeAccessory?: (props: ChatComposerModeAccessoryRenderProps) => ReactNode;
761
+ }) => _emotion_react_jsx_runtime.JSX.Element;
726
762
 
727
763
  declare const ChatConversationList: () => _emotion_react_jsx_runtime.JSX.Element;
728
764
 
@@ -804,6 +840,10 @@ interface ChatContextValue {
804
840
  retryRef: MutableRefObject<(sessionId: string) => Promise<void>>;
805
841
  /** Stable ref populated by ChatComposer on mount; allows external controls to stop streaming. */
806
842
  stopRef: MutableRefObject<(sessionId: string) => Promise<void>>;
843
+ /** Current stop handler exposed as a plain function for render-time consumers. */
844
+ stopSession?: (sessionId: string) => Promise<void>;
845
+ /** Internal registration hook used by ChatComposer to refresh the stop handler. */
846
+ registerStopSession?: (handler: (sessionId: string) => Promise<void>) => void;
807
847
  /** Optional block renderer used to extend message rendering with custom block types. */
808
848
  renderMessageBlock?: ChatMessageBlockRenderer;
809
849
  /** Optional handler used to intercept questionnaire submissions before the default send flow. */
@@ -824,6 +864,8 @@ interface ChatContextValue {
824
864
  onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
825
865
  /** Host callback triggered when a historical session needs older messages. */
826
866
  onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
867
+ /** Optional renderer used to append custom actions to a history session item. */
868
+ renderSessionItemActions?: ChatSessionItemActionsRenderer;
827
869
  }
828
870
 
829
871
  /**
@@ -840,4 +882,4 @@ declare const useChatContext: () => ChatContextValue;
840
882
  */
841
883
  declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
842
884
 
843
- export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, type ChatConfirmationSubmitHandler, ChatConversationList, type ChatHistorySessionListHandlers, type ChatHistorySessionListState, type ChatHistorySessionMessageLoadArgs, type ChatHistorySessionMessagesPage, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, type ChatSessionMessageLoadStatus, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, type ChatSubmissionContext, ChatThread, type ChatToolExecutionPolicy, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type DefaultChatTransportModelsResolver, type DefaultChatTransportRequestBodyBuilder, type DefaultChatTransportRequestBodyBuilderArgs, type ExecutionConfirmationSubmission, type ExecutionProposal, type NewChatTriggerRenderProps, type PlanQuestionOption, type PlanQuestionSubmissionDetail, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
885
+ export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerModeAccessoryRenderProps, type ChatComposerViewProps, type ChatConfirmationSubmitHandler, ChatConversationList, type ChatHistorySessionListHandlers, type ChatHistorySessionListState, type ChatHistorySessionMessageLoadArgs, type ChatHistorySessionMessagesPage, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, type ChatSessionItemActionRenderProps, type ChatSessionItemActionsRenderer, type ChatSessionMessageLoadStatus, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, type ChatSubmissionContext, ChatThread, type ChatToolExecutionPolicy, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type DefaultChatTransportModelsResolver, type DefaultChatTransportRequestBodyBuilder, type DefaultChatTransportRequestBodyBuilderArgs, type ExecutionConfirmationSubmission, type ExecutionProposal, type NewChatTriggerRenderProps, type PlanQuestionOption, type PlanQuestionSubmissionDetail, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
package/dist/index.d.ts CHANGED
@@ -69,6 +69,21 @@ interface ChatHistorySessionListHandlers {
69
69
  onSelectHistorySession?: (session: ChatSession) => Promise<ChatHistorySessionMessagesPage | ChatMessage[] | void> | ChatHistorySessionMessagesPage | ChatMessage[] | void;
70
70
  onLoadMoreHistoryMessages?: (args: ChatHistorySessionMessageLoadArgs) => Promise<ChatHistorySessionMessagesPage | void> | ChatHistorySessionMessagesPage | void;
71
71
  }
72
+ /**
73
+ * Arguments passed to custom history session action renderers.
74
+ */
75
+ interface ChatSessionItemActionRenderProps {
76
+ session: ChatSession;
77
+ isActive: boolean;
78
+ isStreaming: boolean;
79
+ selectSession: () => Promise<void>;
80
+ startNewChat: () => void;
81
+ stopSession: () => Promise<void>;
82
+ }
83
+ /**
84
+ * Optional renderer used to append custom actions to a history session item.
85
+ */
86
+ type ChatSessionItemActionsRenderer = (args: ChatSessionItemActionRenderProps) => ReactNode;
72
87
  /**
73
88
  * Client-side image attachment metadata kept in chat messages.
74
89
  */
@@ -144,7 +159,7 @@ interface PlanBooleanQuestion extends PlanQuestionBase {
144
159
  * Supported question variants in a plan questionnaire.
145
160
  */
146
161
  type PlanQuestion = PlanSingleSelectQuestion | PlanMultiSelectQuestion | PlanTextQuestion | PlanNumberQuestion | PlanBooleanQuestion;
147
- type PlanQuestionnaireStatus = 'expired' | 'failed';
162
+ type PlanQuestionnaireStatus = 'expired' | 'failed' | 'submitted';
148
163
  /**
149
164
  * Merge behavior applied when a keyed structured block is patched repeatedly.
150
165
  */
@@ -177,6 +192,10 @@ interface PlanQuestionnaire {
177
192
  answers?: Partial<Record<string, PlanQuestionnaireAnswerValue>>;
178
193
  status?: PlanQuestionnaireStatus;
179
194
  statusMessage?: string;
195
+ /**
196
+ * Timeout in seconds for the questionnaire interaction.
197
+ */
198
+ timeoutSec?: number;
180
199
  }
181
200
  interface PlanQuestionSubmissionDetail {
182
201
  questionId: string;
@@ -478,6 +497,7 @@ interface AiChatLabels {
478
497
  questionnaireMultiSelectHint?: string;
479
498
  questionnaireOtherOptionLabel?: string;
480
499
  questionnaireOtherPlaceholder?: string;
500
+ questionnaireExpired?: string;
481
501
  modelLoading?: string;
482
502
  modelLoadFailed?: string;
483
503
  modelUnavailable?: string;
@@ -487,6 +507,8 @@ interface AiChatLabels {
487
507
  sessionHistoryLoading?: string;
488
508
  sessionHistoryLoadFailed?: string;
489
509
  sessionHistoryEmpty?: string;
510
+ questionnaireTitle?: string;
511
+ questionnaireConfirmInTime?: string;
490
512
  }
491
513
  /**
492
514
  * State and actions exposed to custom new-chat trigger renderers.
@@ -499,6 +521,13 @@ interface NewChatTriggerRenderProps {
499
521
  stopActiveSession: () => Promise<void>;
500
522
  startNewChat: () => Promise<void>;
501
523
  }
524
+ /**
525
+ * State exposed to optional composer mode accessory renderers.
526
+ */
527
+ interface ChatComposerModeAccessoryRenderProps {
528
+ selectedMode: ChatAgentMode;
529
+ disabled: boolean;
530
+ }
502
531
  /**
503
532
  * Default English label values used when no labels are provided.
504
533
  */
@@ -525,6 +554,8 @@ interface AiChatProviderBaseProps {
525
554
  onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
526
555
  /** Optional callback used when the active historical session needs older messages. */
527
556
  onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
557
+ /** Optional renderer used to append custom actions to a history session item. */
558
+ renderSessionItemActions?: ChatSessionItemActionsRenderer;
528
559
  /**
529
560
  * Whether to enable image attachment uploads. Defaults to `true`.
530
561
  * Set to `false` to hide the upload button, disable paste-image handling,
@@ -584,12 +615,14 @@ type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
584
615
  * a streaming message, or an error to render.
585
616
  */
586
617
  onConversationStartedChange?: (started: boolean) => void;
618
+ /** Optional renderer used to append extra controls next to the mode selector. */
619
+ renderComposerModeAccessory?: (props: ChatComposerModeAccessoryRenderProps) => ReactNode;
587
620
  };
588
621
  /**
589
622
  * Top-level AI chat component. Wraps AiChatProvider and composes the full
590
623
  * chat UI: optional conversation sidebar + thread + composer.
591
624
  */
592
- declare const AiChat: ({ showConversationList, showNewChatButton, renderNewChatTrigger, showComposerOnlyBeforeFirstMessage, onConversationStartedChange, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
625
+ declare const AiChat: ({ showConversationList, showNewChatButton, renderNewChatTrigger, showComposerOnlyBeforeFirstMessage, onConversationStartedChange, renderComposerModeAccessory, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
593
626
 
594
627
  /**
595
628
  * Endpoint overrides for the built-in HTTP transport adapter.
@@ -707,6 +740,7 @@ interface ChatComposerViewProps {
707
740
  modelLoadingLabel: string;
708
741
  modelLoadFailedLabel: string;
709
742
  modelUnavailableLabel: string;
743
+ modeAccessory?: ReactNode;
710
744
  onValueChange: (value: string) => void;
711
745
  onPickImages: (files: FileList | File[]) => void;
712
746
  onPasteImages: (files: File[]) => void;
@@ -722,7 +756,9 @@ interface ChatComposerViewProps {
722
756
  /** Called to send a new user message. */
723
757
  onSend: () => void | Promise<void>;
724
758
  }
725
- declare const ChatComposer: () => _emotion_react_jsx_runtime.JSX.Element;
759
+ declare const ChatComposer: ({ renderModeAccessory, }?: {
760
+ renderModeAccessory?: (props: ChatComposerModeAccessoryRenderProps) => ReactNode;
761
+ }) => _emotion_react_jsx_runtime.JSX.Element;
726
762
 
727
763
  declare const ChatConversationList: () => _emotion_react_jsx_runtime.JSX.Element;
728
764
 
@@ -804,6 +840,10 @@ interface ChatContextValue {
804
840
  retryRef: MutableRefObject<(sessionId: string) => Promise<void>>;
805
841
  /** Stable ref populated by ChatComposer on mount; allows external controls to stop streaming. */
806
842
  stopRef: MutableRefObject<(sessionId: string) => Promise<void>>;
843
+ /** Current stop handler exposed as a plain function for render-time consumers. */
844
+ stopSession?: (sessionId: string) => Promise<void>;
845
+ /** Internal registration hook used by ChatComposer to refresh the stop handler. */
846
+ registerStopSession?: (handler: (sessionId: string) => Promise<void>) => void;
807
847
  /** Optional block renderer used to extend message rendering with custom block types. */
808
848
  renderMessageBlock?: ChatMessageBlockRenderer;
809
849
  /** Optional handler used to intercept questionnaire submissions before the default send flow. */
@@ -824,6 +864,8 @@ interface ChatContextValue {
824
864
  onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
825
865
  /** Host callback triggered when a historical session needs older messages. */
826
866
  onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
867
+ /** Optional renderer used to append custom actions to a history session item. */
868
+ renderSessionItemActions?: ChatSessionItemActionsRenderer;
827
869
  }
828
870
 
829
871
  /**
@@ -840,4 +882,4 @@ declare const useChatContext: () => ChatContextValue;
840
882
  */
841
883
  declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
842
884
 
843
- export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, type ChatConfirmationSubmitHandler, ChatConversationList, type ChatHistorySessionListHandlers, type ChatHistorySessionListState, type ChatHistorySessionMessageLoadArgs, type ChatHistorySessionMessagesPage, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, type ChatSessionMessageLoadStatus, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, type ChatSubmissionContext, ChatThread, type ChatToolExecutionPolicy, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type DefaultChatTransportModelsResolver, type DefaultChatTransportRequestBodyBuilder, type DefaultChatTransportRequestBodyBuilderArgs, type ExecutionConfirmationSubmission, type ExecutionProposal, type NewChatTriggerRenderProps, type PlanQuestionOption, type PlanQuestionSubmissionDetail, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
885
+ export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerModeAccessoryRenderProps, type ChatComposerViewProps, type ChatConfirmationSubmitHandler, ChatConversationList, type ChatHistorySessionListHandlers, type ChatHistorySessionListState, type ChatHistorySessionMessageLoadArgs, type ChatHistorySessionMessagesPage, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, type ChatSessionItemActionRenderProps, type ChatSessionItemActionsRenderer, type ChatSessionMessageLoadStatus, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, type ChatSubmissionContext, ChatThread, type ChatToolExecutionPolicy, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type DefaultChatTransportModelsResolver, type DefaultChatTransportRequestBodyBuilder, type DefaultChatTransportRequestBodyBuilderArgs, type ExecutionConfirmationSubmission, type ExecutionProposal, type NewChatTriggerRenderProps, type PlanQuestionOption, type PlanQuestionSubmissionDetail, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };