@xinghunm/ai-chat 1.1.2 → 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/README.md +31 -1
- package/dist/index.d.mts +63 -6
- package/dist/index.d.ts +63 -6
- package/dist/index.js +391 -154
- package/dist/index.mjs +383 -146
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -55,6 +55,28 @@ const transport = createDefaultChatTransport({
|
|
|
55
55
|
})
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
如果后端协议大体一致,只是模型列表或 `/chat/completions` 请求体需要调整,也可以继续复用默认 transport,只覆盖局部扩展点:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
const transport = createDefaultChatTransport({
|
|
62
|
+
apiBaseUrl: '/ai-api',
|
|
63
|
+
authToken: 'Bearer your-token-here',
|
|
64
|
+
resolveModels: async () => ({
|
|
65
|
+
data: [{ id: 'deepseek-chat', object: 'model' }],
|
|
66
|
+
}),
|
|
67
|
+
buildRequestBody: ({ model, mode, content }) => ({
|
|
68
|
+
model: 'deepseek-chat',
|
|
69
|
+
base_url: 'https://api.deepseek.com/v1',
|
|
70
|
+
api_key: 'sk-xxxxx',
|
|
71
|
+
mode,
|
|
72
|
+
stream: true,
|
|
73
|
+
messages: [{ role: 'user', content }],
|
|
74
|
+
}),
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
默认 transport 在检测到图片附件时,会自动把用户输入组装成多模态 `messages[].content` 数组,并将图片文件序列化为 Data URL 后发送;如果你自定义 `buildRequestBody`,也会同时收到 `attachments` 参数,可按后端协议自行处理。
|
|
79
|
+
|
|
58
80
|
## 完整用法
|
|
59
81
|
|
|
60
82
|
如需最大灵活性,可在 `AiChatProvider` 内手动组合子组件:
|
|
@@ -74,6 +96,7 @@ const transport: ChatTransport = {
|
|
|
74
96
|
model,
|
|
75
97
|
mode,
|
|
76
98
|
content,
|
|
99
|
+
attachments,
|
|
77
100
|
onSessionId,
|
|
78
101
|
onUpdate,
|
|
79
102
|
onDone,
|
|
@@ -85,7 +108,7 @@ const transport: ChatTransport = {
|
|
|
85
108
|
method: 'POST',
|
|
86
109
|
signal,
|
|
87
110
|
headers: { 'Content-Type': 'application/json' },
|
|
88
|
-
body: JSON.stringify({ sessionId, model, mode, content }),
|
|
111
|
+
body: JSON.stringify({ sessionId, model, mode, content, attachments }),
|
|
89
112
|
})
|
|
90
113
|
const data = await response.json()
|
|
91
114
|
onSessionId?.(data.sessionId)
|
|
@@ -193,6 +216,13 @@ export const CustomChat = () => (
|
|
|
193
216
|
| `completions` | `"/chat/completions"` | 流式聊天接口路径。 |
|
|
194
217
|
| `terminate` | `"/chat/terminate"` | 停止流式响应接口路径。 |
|
|
195
218
|
|
|
219
|
+
此外还支持两个轻量扩展点:
|
|
220
|
+
|
|
221
|
+
| 键 | 类型 | 说明 |
|
|
222
|
+
| ------------------ | ----------------------------------- | ------------------------------------------------------------------------------ |
|
|
223
|
+
| `resolveModels` | `() => Promise<ChatModelsResponse>` | 覆盖默认的 `/models` 请求,直接返回模型列表。 |
|
|
224
|
+
| `buildRequestBody` | `(args) => unknown` | 覆盖默认的 `/chat/completions` 请求体构造逻辑;`args` 同时包含 `attachments`。 |
|
|
225
|
+
|
|
196
226
|
### `AiChatLabels`
|
|
197
227
|
|
|
198
228
|
所有字段均为可选,未指定的字段回退到 `DEFAULT_AI_CHAT_LABELS` 中的英文默认值。
|
package/dist/index.d.mts
CHANGED
|
@@ -42,6 +42,12 @@ interface ChatImageAttachment {
|
|
|
42
42
|
mimeType: string;
|
|
43
43
|
size: number;
|
|
44
44
|
previewUrl: string;
|
|
45
|
+
/**
|
|
46
|
+
* Original file kept for transports that need to upload or serialize the image.
|
|
47
|
+
*
|
|
48
|
+
* This is only available for client-originated attachments selected in the composer.
|
|
49
|
+
*/
|
|
50
|
+
file?: File;
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
53
|
* Select option metadata used by plan questionnaires.
|
|
@@ -291,6 +297,10 @@ interface ChatTransportStartStreamArgs {
|
|
|
291
297
|
mode: ChatAgentMode;
|
|
292
298
|
/** User message content that should be sent to the backend. */
|
|
293
299
|
content: string;
|
|
300
|
+
/**
|
|
301
|
+
* Optional image attachments selected in the composer and sent alongside the text.
|
|
302
|
+
*/
|
|
303
|
+
attachments?: ChatImageAttachment[];
|
|
294
304
|
/** Abort signal controlled by the chat composer stop action. */
|
|
295
305
|
signal?: AbortSignal;
|
|
296
306
|
/** Emits normalized streaming patches that should update the assistant message. */
|
|
@@ -421,6 +431,17 @@ interface AiChatLabels {
|
|
|
421
431
|
questionnaireOtherOptionLabel?: string;
|
|
422
432
|
questionnaireOtherPlaceholder?: string;
|
|
423
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
|
+
}
|
|
424
445
|
/**
|
|
425
446
|
* Default English label values used when no labels are provided.
|
|
426
447
|
*/
|
|
@@ -482,12 +503,16 @@ declare const AiChatProvider: (props: AiChatProviderProps) => _emotion_react_jsx
|
|
|
482
503
|
type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
|
|
483
504
|
/** When true, renders the conversation list sidebar. Defaults to false. */
|
|
484
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;
|
|
485
510
|
};
|
|
486
511
|
/**
|
|
487
512
|
* Top-level AI chat component. Wraps AiChatProvider and composes the full
|
|
488
513
|
* chat UI: optional conversation sidebar + thread + composer.
|
|
489
514
|
*/
|
|
490
|
-
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;
|
|
491
516
|
|
|
492
517
|
/**
|
|
493
518
|
* Endpoint overrides for the built-in HTTP transport adapter.
|
|
@@ -511,6 +536,25 @@ interface ChatToolExecutionPolicy {
|
|
|
511
536
|
/** Approval timeout in seconds, forwarded when approval is enabled. */
|
|
512
537
|
approvalTimeoutSec?: number;
|
|
513
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Arguments passed to a custom request body builder for the default transport.
|
|
541
|
+
*/
|
|
542
|
+
interface DefaultChatTransportRequestBodyBuilderArgs {
|
|
543
|
+
sessionId?: string;
|
|
544
|
+
model: string;
|
|
545
|
+
mode: ChatAgentMode;
|
|
546
|
+
content: string;
|
|
547
|
+
attachments?: ChatImageAttachment[];
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Optional builder used to customize the `/chat/completions` request body while
|
|
551
|
+
* reusing the default streaming transport behavior.
|
|
552
|
+
*/
|
|
553
|
+
type DefaultChatTransportRequestBodyBuilder = (args: DefaultChatTransportRequestBodyBuilderArgs) => unknown;
|
|
554
|
+
/**
|
|
555
|
+
* Optional model resolver used to override the default `/models` request.
|
|
556
|
+
*/
|
|
557
|
+
type DefaultChatTransportModelsResolver = () => Promise<ChatModelsResponse>;
|
|
514
558
|
/**
|
|
515
559
|
* Options for the built-in HTTP transport adapter.
|
|
516
560
|
*/
|
|
@@ -523,6 +567,10 @@ interface CreateDefaultChatTransportOptions {
|
|
|
523
567
|
toolExecutionPolicy?: ChatToolExecutionPolicy;
|
|
524
568
|
/** Optional extra headers appended to each streaming chat completion request. */
|
|
525
569
|
streamHeaders?: Record<string, string>;
|
|
570
|
+
/** Optional resolver used to override the built-in model catalog request. */
|
|
571
|
+
resolveModels?: DefaultChatTransportModelsResolver;
|
|
572
|
+
/** Optional builder used to override the built-in chat completion request body. */
|
|
573
|
+
buildRequestBody?: DefaultChatTransportRequestBodyBuilder;
|
|
526
574
|
/** Optional transformer used to normalize custom stream packets. */
|
|
527
575
|
transformStreamPacket?: TransformChatStreamPacket;
|
|
528
576
|
/** Optional endpoint overrides for backends that use different paths. */
|
|
@@ -533,7 +581,7 @@ interface CreateDefaultChatTransportOptions {
|
|
|
533
581
|
/**
|
|
534
582
|
* Creates the built-in transport backed by the current HTTP chat API.
|
|
535
583
|
*/
|
|
536
|
-
declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, toolExecutionPolicy, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
|
|
584
|
+
declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, toolExecutionPolicy, streamHeaders, resolveModels, buildRequestBody, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
|
|
537
585
|
|
|
538
586
|
declare const ChatThread: () => _emotion_react_jsx_runtime.JSX.Element;
|
|
539
587
|
|
|
@@ -593,6 +641,7 @@ interface ChatState {
|
|
|
593
641
|
}
|
|
594
642
|
interface ChatActions {
|
|
595
643
|
createSession: (session: ChatSession) => void;
|
|
644
|
+
startNewChat: () => void;
|
|
596
645
|
setActiveSession: (sessionId: string | null) => void;
|
|
597
646
|
replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
|
|
598
647
|
setPreferredMode: (mode: ChatAgentMode) => void;
|
|
@@ -612,6 +661,12 @@ type ChatStore = ChatState & ChatActions;
|
|
|
612
661
|
type ChatStoreInstance = ReturnType<typeof createChatStore>;
|
|
613
662
|
declare const createChatStore: (initialState?: Partial<Pick<ChatState, "preferredMode">>) => zustand_vanilla.StoreApi<ChatStore>;
|
|
614
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
|
+
}
|
|
615
670
|
interface ChatContextValue {
|
|
616
671
|
store: ChatStoreInstance;
|
|
617
672
|
transport: ChatTransport;
|
|
@@ -623,9 +678,11 @@ interface ChatContextValue {
|
|
|
623
678
|
authToken?: string;
|
|
624
679
|
labels: Required<AiChatLabels>;
|
|
625
680
|
/** Stable ref populated by ChatComposer on mount; allows ChatThread to trigger sends. */
|
|
626
|
-
sendRef: MutableRefObject<(content: string) => Promise<void>>;
|
|
627
|
-
/** Stable ref populated by ChatComposer on mount; allows ChatThread to replay
|
|
628
|
-
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>>;
|
|
629
686
|
/** Optional block renderer used to extend message rendering with custom block types. */
|
|
630
687
|
renderMessageBlock?: ChatMessageBlockRenderer;
|
|
631
688
|
/** Optional handler used to intercept questionnaire submissions before the default send flow. */
|
|
@@ -654,4 +711,4 @@ declare const useChatContext: () => ChatContextValue;
|
|
|
654
711
|
*/
|
|
655
712
|
declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
|
|
656
713
|
|
|
657
|
-
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 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
|
@@ -42,6 +42,12 @@ interface ChatImageAttachment {
|
|
|
42
42
|
mimeType: string;
|
|
43
43
|
size: number;
|
|
44
44
|
previewUrl: string;
|
|
45
|
+
/**
|
|
46
|
+
* Original file kept for transports that need to upload or serialize the image.
|
|
47
|
+
*
|
|
48
|
+
* This is only available for client-originated attachments selected in the composer.
|
|
49
|
+
*/
|
|
50
|
+
file?: File;
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
53
|
* Select option metadata used by plan questionnaires.
|
|
@@ -291,6 +297,10 @@ interface ChatTransportStartStreamArgs {
|
|
|
291
297
|
mode: ChatAgentMode;
|
|
292
298
|
/** User message content that should be sent to the backend. */
|
|
293
299
|
content: string;
|
|
300
|
+
/**
|
|
301
|
+
* Optional image attachments selected in the composer and sent alongside the text.
|
|
302
|
+
*/
|
|
303
|
+
attachments?: ChatImageAttachment[];
|
|
294
304
|
/** Abort signal controlled by the chat composer stop action. */
|
|
295
305
|
signal?: AbortSignal;
|
|
296
306
|
/** Emits normalized streaming patches that should update the assistant message. */
|
|
@@ -421,6 +431,17 @@ interface AiChatLabels {
|
|
|
421
431
|
questionnaireOtherOptionLabel?: string;
|
|
422
432
|
questionnaireOtherPlaceholder?: string;
|
|
423
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
|
+
}
|
|
424
445
|
/**
|
|
425
446
|
* Default English label values used when no labels are provided.
|
|
426
447
|
*/
|
|
@@ -482,12 +503,16 @@ declare const AiChatProvider: (props: AiChatProviderProps) => _emotion_react_jsx
|
|
|
482
503
|
type AiChatProps = Omit<AiChatProviderProps, 'children'> & {
|
|
483
504
|
/** When true, renders the conversation list sidebar. Defaults to false. */
|
|
484
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;
|
|
485
510
|
};
|
|
486
511
|
/**
|
|
487
512
|
* Top-level AI chat component. Wraps AiChatProvider and composes the full
|
|
488
513
|
* chat UI: optional conversation sidebar + thread + composer.
|
|
489
514
|
*/
|
|
490
|
-
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;
|
|
491
516
|
|
|
492
517
|
/**
|
|
493
518
|
* Endpoint overrides for the built-in HTTP transport adapter.
|
|
@@ -511,6 +536,25 @@ interface ChatToolExecutionPolicy {
|
|
|
511
536
|
/** Approval timeout in seconds, forwarded when approval is enabled. */
|
|
512
537
|
approvalTimeoutSec?: number;
|
|
513
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Arguments passed to a custom request body builder for the default transport.
|
|
541
|
+
*/
|
|
542
|
+
interface DefaultChatTransportRequestBodyBuilderArgs {
|
|
543
|
+
sessionId?: string;
|
|
544
|
+
model: string;
|
|
545
|
+
mode: ChatAgentMode;
|
|
546
|
+
content: string;
|
|
547
|
+
attachments?: ChatImageAttachment[];
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Optional builder used to customize the `/chat/completions` request body while
|
|
551
|
+
* reusing the default streaming transport behavior.
|
|
552
|
+
*/
|
|
553
|
+
type DefaultChatTransportRequestBodyBuilder = (args: DefaultChatTransportRequestBodyBuilderArgs) => unknown;
|
|
554
|
+
/**
|
|
555
|
+
* Optional model resolver used to override the default `/models` request.
|
|
556
|
+
*/
|
|
557
|
+
type DefaultChatTransportModelsResolver = () => Promise<ChatModelsResponse>;
|
|
514
558
|
/**
|
|
515
559
|
* Options for the built-in HTTP transport adapter.
|
|
516
560
|
*/
|
|
@@ -523,6 +567,10 @@ interface CreateDefaultChatTransportOptions {
|
|
|
523
567
|
toolExecutionPolicy?: ChatToolExecutionPolicy;
|
|
524
568
|
/** Optional extra headers appended to each streaming chat completion request. */
|
|
525
569
|
streamHeaders?: Record<string, string>;
|
|
570
|
+
/** Optional resolver used to override the built-in model catalog request. */
|
|
571
|
+
resolveModels?: DefaultChatTransportModelsResolver;
|
|
572
|
+
/** Optional builder used to override the built-in chat completion request body. */
|
|
573
|
+
buildRequestBody?: DefaultChatTransportRequestBodyBuilder;
|
|
526
574
|
/** Optional transformer used to normalize custom stream packets. */
|
|
527
575
|
transformStreamPacket?: TransformChatStreamPacket;
|
|
528
576
|
/** Optional endpoint overrides for backends that use different paths. */
|
|
@@ -533,7 +581,7 @@ interface CreateDefaultChatTransportOptions {
|
|
|
533
581
|
/**
|
|
534
582
|
* Creates the built-in transport backed by the current HTTP chat API.
|
|
535
583
|
*/
|
|
536
|
-
declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, toolExecutionPolicy, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
|
|
584
|
+
declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, toolExecutionPolicy, streamHeaders, resolveModels, buildRequestBody, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
|
|
537
585
|
|
|
538
586
|
declare const ChatThread: () => _emotion_react_jsx_runtime.JSX.Element;
|
|
539
587
|
|
|
@@ -593,6 +641,7 @@ interface ChatState {
|
|
|
593
641
|
}
|
|
594
642
|
interface ChatActions {
|
|
595
643
|
createSession: (session: ChatSession) => void;
|
|
644
|
+
startNewChat: () => void;
|
|
596
645
|
setActiveSession: (sessionId: string | null) => void;
|
|
597
646
|
replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
|
|
598
647
|
setPreferredMode: (mode: ChatAgentMode) => void;
|
|
@@ -612,6 +661,12 @@ type ChatStore = ChatState & ChatActions;
|
|
|
612
661
|
type ChatStoreInstance = ReturnType<typeof createChatStore>;
|
|
613
662
|
declare const createChatStore: (initialState?: Partial<Pick<ChatState, "preferredMode">>) => zustand_vanilla.StoreApi<ChatStore>;
|
|
614
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
|
+
}
|
|
615
670
|
interface ChatContextValue {
|
|
616
671
|
store: ChatStoreInstance;
|
|
617
672
|
transport: ChatTransport;
|
|
@@ -623,9 +678,11 @@ interface ChatContextValue {
|
|
|
623
678
|
authToken?: string;
|
|
624
679
|
labels: Required<AiChatLabels>;
|
|
625
680
|
/** Stable ref populated by ChatComposer on mount; allows ChatThread to trigger sends. */
|
|
626
|
-
sendRef: MutableRefObject<(content: string) => Promise<void>>;
|
|
627
|
-
/** Stable ref populated by ChatComposer on mount; allows ChatThread to replay
|
|
628
|
-
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>>;
|
|
629
686
|
/** Optional block renderer used to extend message rendering with custom block types. */
|
|
630
687
|
renderMessageBlock?: ChatMessageBlockRenderer;
|
|
631
688
|
/** Optional handler used to intercept questionnaire submissions before the default send flow. */
|
|
@@ -654,4 +711,4 @@ declare const useChatContext: () => ChatContextValue;
|
|
|
654
711
|
*/
|
|
655
712
|
declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
|
|
656
713
|
|
|
657
|
-
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 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 };
|