@xinghunm/ai-chat 1.2.0 → 1.2.1

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
@@ -431,6 +431,17 @@ interface AiChatLabels {
431
431
  questionnaireOtherOptionLabel?: string;
432
432
  questionnaireOtherPlaceholder?: string;
433
433
  }
434
+ /**
435
+ * State and actions exposed to custom new-chat trigger renderers.
436
+ */
437
+ interface NewChatTriggerRenderProps {
438
+ activeSessionId: string | null;
439
+ isStreaming: boolean;
440
+ isStopping: boolean;
441
+ createNewSession: () => void;
442
+ stopActiveSession: () => Promise<void>;
443
+ startNewChat: () => Promise<void>;
444
+ }
434
445
  /**
435
446
  * Default English label values used when no labels are provided.
436
447
  */
@@ -492,12 +503,16 @@ declare const AiChatProvider: (props: AiChatProviderProps) => _emotion_react_jsx
492
503
  type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
493
504
  /** When true, renders the conversation list sidebar. Defaults to false. */
494
505
  showConversationList?: boolean;
506
+ /** When true, renders a lightweight new-chat button without the full conversation list. */
507
+ showNewChatButton?: boolean;
508
+ /** Optional renderer used to override the lightweight new-chat trigger UI. */
509
+ renderNewChatTrigger?: (props: NewChatTriggerRenderProps) => ReactNode;
495
510
  };
496
511
  /**
497
512
  * Top-level AI chat component. Wraps AiChatProvider and composes the full
498
513
  * chat UI: optional conversation sidebar + thread + composer.
499
514
  */
500
- declare const AiChat: ({ showConversationList, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
515
+ declare const AiChat: ({ showConversationList, showNewChatButton, renderNewChatTrigger, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
501
516
 
502
517
  /**
503
518
  * Endpoint overrides for the built-in HTTP transport adapter.
@@ -626,6 +641,7 @@ interface ChatState {
626
641
  }
627
642
  interface ChatActions {
628
643
  createSession: (session: ChatSession) => void;
644
+ startNewChat: () => void;
629
645
  setActiveSession: (sessionId: string | null) => void;
630
646
  replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
631
647
  setPreferredMode: (mode: ChatAgentMode) => void;
@@ -645,6 +661,12 @@ type ChatStore = ChatState & ChatActions;
645
661
  type ChatStoreInstance = ReturnType<typeof createChatStore>;
646
662
  declare const createChatStore: (initialState?: Partial<Pick<ChatState, "preferredMode">>) => zustand_vanilla.StoreApi<ChatStore>;
647
663
 
664
+ interface ChatSendRefOptions {
665
+ /** Explicit target session for programmatic sends triggered from a thread card. */
666
+ sessionId?: string;
667
+ /** Whether to consume the composer attachment draft. Defaults to true for composer sends. */
668
+ includeComposerAttachments?: boolean;
669
+ }
648
670
  interface ChatContextValue {
649
671
  store: ChatStoreInstance;
650
672
  transport: ChatTransport;
@@ -656,9 +678,11 @@ interface ChatContextValue {
656
678
  authToken?: string;
657
679
  labels: Required<AiChatLabels>;
658
680
  /** Stable ref populated by ChatComposer on mount; allows ChatThread to trigger sends. */
659
- sendRef: MutableRefObject<(content: string) => Promise<void>>;
660
- /** Stable ref populated by ChatComposer on mount; allows ChatThread to replay the last request. */
661
- retryRef: MutableRefObject<() => Promise<void>>;
681
+ sendRef: MutableRefObject<(content: string, options?: ChatSendRefOptions) => Promise<void>>;
682
+ /** Stable ref populated by ChatComposer on mount; allows ChatThread to replay a session request. */
683
+ retryRef: MutableRefObject<(sessionId: string) => Promise<void>>;
684
+ /** Stable ref populated by ChatComposer on mount; allows external controls to stop streaming. */
685
+ stopRef: MutableRefObject<(sessionId: string) => Promise<void>>;
662
686
  /** Optional block renderer used to extend message rendering with custom block types. */
663
687
  renderMessageBlock?: ChatMessageBlockRenderer;
664
688
  /** Optional handler used to intercept questionnaire submissions before the default send flow. */
@@ -687,4 +711,4 @@ declare const useChatContext: () => ChatContextValue;
687
711
  */
688
712
  declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
689
713
 
690
- 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 ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, 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 PlanQuestionOption, type PlanQuestionSubmissionDetail, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
714
+ 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 ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, 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
@@ -431,6 +431,17 @@ interface AiChatLabels {
431
431
  questionnaireOtherOptionLabel?: string;
432
432
  questionnaireOtherPlaceholder?: string;
433
433
  }
434
+ /**
435
+ * State and actions exposed to custom new-chat trigger renderers.
436
+ */
437
+ interface NewChatTriggerRenderProps {
438
+ activeSessionId: string | null;
439
+ isStreaming: boolean;
440
+ isStopping: boolean;
441
+ createNewSession: () => void;
442
+ stopActiveSession: () => Promise<void>;
443
+ startNewChat: () => Promise<void>;
444
+ }
434
445
  /**
435
446
  * Default English label values used when no labels are provided.
436
447
  */
@@ -492,12 +503,16 @@ declare const AiChatProvider: (props: AiChatProviderProps) => _emotion_react_jsx
492
503
  type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
493
504
  /** When true, renders the conversation list sidebar. Defaults to false. */
494
505
  showConversationList?: boolean;
506
+ /** When true, renders a lightweight new-chat button without the full conversation list. */
507
+ showNewChatButton?: boolean;
508
+ /** Optional renderer used to override the lightweight new-chat trigger UI. */
509
+ renderNewChatTrigger?: (props: NewChatTriggerRenderProps) => ReactNode;
495
510
  };
496
511
  /**
497
512
  * Top-level AI chat component. Wraps AiChatProvider and composes the full
498
513
  * chat UI: optional conversation sidebar + thread + composer.
499
514
  */
500
- declare const AiChat: ({ showConversationList, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
515
+ declare const AiChat: ({ showConversationList, showNewChatButton, renderNewChatTrigger, ...providerProps }: AiChatProps) => _emotion_react_jsx_runtime.JSX.Element;
501
516
 
502
517
  /**
503
518
  * Endpoint overrides for the built-in HTTP transport adapter.
@@ -626,6 +641,7 @@ interface ChatState {
626
641
  }
627
642
  interface ChatActions {
628
643
  createSession: (session: ChatSession) => void;
644
+ startNewChat: () => void;
629
645
  setActiveSession: (sessionId: string | null) => void;
630
646
  replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
631
647
  setPreferredMode: (mode: ChatAgentMode) => void;
@@ -645,6 +661,12 @@ type ChatStore = ChatState & ChatActions;
645
661
  type ChatStoreInstance = ReturnType<typeof createChatStore>;
646
662
  declare const createChatStore: (initialState?: Partial<Pick<ChatState, "preferredMode">>) => zustand_vanilla.StoreApi<ChatStore>;
647
663
 
664
+ interface ChatSendRefOptions {
665
+ /** Explicit target session for programmatic sends triggered from a thread card. */
666
+ sessionId?: string;
667
+ /** Whether to consume the composer attachment draft. Defaults to true for composer sends. */
668
+ includeComposerAttachments?: boolean;
669
+ }
648
670
  interface ChatContextValue {
649
671
  store: ChatStoreInstance;
650
672
  transport: ChatTransport;
@@ -656,9 +678,11 @@ interface ChatContextValue {
656
678
  authToken?: string;
657
679
  labels: Required<AiChatLabels>;
658
680
  /** Stable ref populated by ChatComposer on mount; allows ChatThread to trigger sends. */
659
- sendRef: MutableRefObject<(content: string) => Promise<void>>;
660
- /** Stable ref populated by ChatComposer on mount; allows ChatThread to replay the last request. */
661
- retryRef: MutableRefObject<() => Promise<void>>;
681
+ sendRef: MutableRefObject<(content: string, options?: ChatSendRefOptions) => Promise<void>>;
682
+ /** Stable ref populated by ChatComposer on mount; allows ChatThread to replay a session request. */
683
+ retryRef: MutableRefObject<(sessionId: string) => Promise<void>>;
684
+ /** Stable ref populated by ChatComposer on mount; allows external controls to stop streaming. */
685
+ stopRef: MutableRefObject<(sessionId: string) => Promise<void>>;
662
686
  /** Optional block renderer used to extend message rendering with custom block types. */
663
687
  renderMessageBlock?: ChatMessageBlockRenderer;
664
688
  /** Optional handler used to intercept questionnaire submissions before the default send flow. */
@@ -687,4 +711,4 @@ declare const useChatContext: () => ChatContextValue;
687
711
  */
688
712
  declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
689
713
 
690
- 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 ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, 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 PlanQuestionOption, type PlanQuestionSubmissionDetail, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
714
+ 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 ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, 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 };