@xinghunm/ai-chat 1.3.2 → 1.4.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/README.md +86 -30
- package/dist/index.d.mts +72 -1
- package/dist/index.d.ts +72 -1
- package/dist/index.js +550 -83
- package/dist/index.mjs +550 -83
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,53 @@ export const App = () => <AiChat transport={transport} />
|
|
|
39
39
|
<AiChat transport={transport} showConversationList />
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
接入历史会话列表时,`ai-chat` 不请求后端 API。宿主应用负责分页获取会话列表,并把已加载的数据传给组件;列表滚动到底部时,组件会触发 `onLoadMoreSessions`:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { useState } from 'react'
|
|
46
|
+
import type { ChatMessage, ChatSession } from '@xinghunm/ai-chat'
|
|
47
|
+
|
|
48
|
+
const [sessions, setSessions] = useState<ChatSession[]>([])
|
|
49
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
50
|
+
const [cursor, setCursor] = useState<string | null>(null)
|
|
51
|
+
|
|
52
|
+
const loadMoreSessions = async () => {
|
|
53
|
+
if (isLoading) return
|
|
54
|
+
|
|
55
|
+
setIsLoading(true)
|
|
56
|
+
const response = await fetch(`/chat/sessions?cursor=${cursor ?? ''}`)
|
|
57
|
+
const data = (await response.json()) as {
|
|
58
|
+
sessions: ChatSession[]
|
|
59
|
+
nextCursor: string | null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setSessions((current) => [...current, ...data.sessions])
|
|
63
|
+
setCursor(data.nextCursor)
|
|
64
|
+
setIsLoading(false)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const loadSessionMessages = async (session: ChatSession): Promise<ChatMessage[]> => {
|
|
68
|
+
const response = await fetch(`/chat/sessions/${session.sessionId}/messages`)
|
|
69
|
+
const data = (await response.json()) as { messages: ChatMessage[] }
|
|
70
|
+
return data.messages
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const App = () => (
|
|
74
|
+
<AiChat
|
|
75
|
+
transport={transport}
|
|
76
|
+
showConversationList
|
|
77
|
+
historySessionList={{
|
|
78
|
+
sessions,
|
|
79
|
+
isLoading,
|
|
80
|
+
hasMore: cursor !== null,
|
|
81
|
+
error: null,
|
|
82
|
+
}}
|
|
83
|
+
onLoadMoreSessions={loadMoreSessions}
|
|
84
|
+
onSelectHistorySession={loadSessionMessages}
|
|
85
|
+
/>
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
42
89
|
如果你还在使用内置默认协议,也可以继续传 `apiBaseUrl` 和 `authToken`。`AiChatProvider` 会在内部自动创建默认 transport,属于兼容模式。
|
|
43
90
|
|
|
44
91
|
如果只是路径不同,也不需要自己重写整个 transport,可以只覆盖默认 adapter 的 endpoints:
|
|
@@ -155,16 +202,19 @@ export const CustomChat = () => (
|
|
|
155
202
|
|
|
156
203
|
一体化 `AiChat` 组件的 Props,继承全部 `AiChatProviderProps`(不含 `children`)。
|
|
157
204
|
|
|
158
|
-
| 属性 | 类型
|
|
159
|
-
| ------------------------ |
|
|
160
|
-
| `transport` | `ChatTransport`
|
|
161
|
-
| `apiBaseUrl` | `string`
|
|
162
|
-
| `authToken` | `string`
|
|
163
|
-
| `defaultMode` | `ChatAgentMode`
|
|
164
|
-
| `labels` | `AiChatLabels`
|
|
165
|
-
| `showConversationList` | `boolean`
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
205
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
206
|
+
| ------------------------ | ---------------------------------------------------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------- |
|
|
207
|
+
| `transport` | `ChatTransport` | — | 推荐。由接入方提供的传输适配器。 |
|
|
208
|
+
| `apiBaseUrl` | `string` | — | 兼容模式。创建默认内置 transport。 |
|
|
209
|
+
| `authToken` | `string` | — | 兼容模式下默认 transport 使用的鉴权头。 |
|
|
210
|
+
| `defaultMode` | `ChatAgentMode` | `"agent"` | 新会话的初始 Agent 模式。 |
|
|
211
|
+
| `labels` | `AiChatLabels` | — | 可选的 UI 文案覆盖。 |
|
|
212
|
+
| `showConversationList` | `boolean` | `false` | 为 `true` 时渲染会话列表侧边栏。 |
|
|
213
|
+
| `historySessionList` | `ChatHistorySessionListState` | — | 受控历史会话列表状态。宿主应用负责请求后端并传入已加载会话。 |
|
|
214
|
+
| `onLoadMoreSessions` | `() => void \| Promise<void>` | — | 会话列表滚动到底部且 `hasMore` 为 `true` 时触发,由宿主应用加载下一页。 |
|
|
215
|
+
| `onSelectHistorySession` | `(session) => ChatMessage[] \| void \| Promise<ChatMessage[] \| void>` | — | 点击未加载过的历史会话时触发。返回消息数组时组件会写入内部 store;返回 `void` 时宿主自行控制。 |
|
|
216
|
+
| `messageRenderOrder` | `ChatMessageRenderOrder` | `"blocks-first"` | 混合纯文本与结构化 block 时的渲染顺序。默认结构化卡片在前;设为 `"timeline"` 时按时间线优先保留文本在前。 |
|
|
217
|
+
| `enableImageAttachments` | `boolean` | `true` | 为 `false` 时隐藏上传按钮、禁用粘贴图片,并使程序化调用 `pickImages`/`pasteImages` 变为 no-op。 |
|
|
168
218
|
|
|
169
219
|
### `AiChatProviderProps`
|
|
170
220
|
|
|
@@ -172,29 +222,35 @@ export const CustomChat = () => (
|
|
|
172
222
|
|
|
173
223
|
`AiChatProvider` 有两种接入方式,二选一:
|
|
174
224
|
|
|
175
|
-
| 属性 | 类型
|
|
176
|
-
| ------------------------ |
|
|
177
|
-
| `transport` | `ChatTransport`
|
|
178
|
-
| `defaultMode` | `ChatAgentMode`
|
|
179
|
-
| `labels` | `AiChatLabels`
|
|
180
|
-
| `renderMessageBlock` | `ChatMessageBlockRenderer`
|
|
181
|
-
| `messageRenderOrder` | `ChatMessageRenderOrder`
|
|
182
|
-
| `
|
|
183
|
-
| `
|
|
225
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
226
|
+
| ------------------------ | ---------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------ |
|
|
227
|
+
| `transport` | `ChatTransport` | 是 | 推荐。完全自定义的传输层。 |
|
|
228
|
+
| `defaultMode` | `ChatAgentMode` | 否 | 新会话的初始 Agent 模式。 |
|
|
229
|
+
| `labels` | `AiChatLabels` | 否 | 可选的 UI 文案覆盖。 |
|
|
230
|
+
| `renderMessageBlock` | `ChatMessageBlockRenderer` | 否 | 自定义消息 block 渲染器,用于承接 `type: "custom"` 等扩展。 |
|
|
231
|
+
| `messageRenderOrder` | `ChatMessageRenderOrder` | 否 | 混合纯文本与结构化 block 时的渲染顺序。默认 `"blocks-first"`,设为 `"timeline"` 可按时间线优先渲染文本片段。 |
|
|
232
|
+
| `historySessionList` | `ChatHistorySessionListState` | 否 | 受控历史会话列表状态。 |
|
|
233
|
+
| `onLoadMoreSessions` | `() => void \| Promise<void>` | 否 | 会话列表滚动到底部且仍有下一页时触发。 |
|
|
234
|
+
| `onSelectHistorySession` | `(session) => ChatMessage[] \| void \| Promise<ChatMessage[] \| void>` | 否 | 点击未加载过的历史会话时触发。 |
|
|
235
|
+
| `enableImageAttachments` | `boolean` | 否 | 为 `false` 时隐藏上传按钮、禁用粘贴图片,并使程序化调用 `pickImages`/`pasteImages` 变为 no-op。默认 `true`。 |
|
|
236
|
+
| `children` | `ReactNode` | 是 | Provider 内部渲染的子元素。 |
|
|
184
237
|
|
|
185
238
|
兼容模式:
|
|
186
239
|
|
|
187
|
-
| 属性 | 类型
|
|
188
|
-
| ------------------------ |
|
|
189
|
-
| `apiBaseUrl` | `string`
|
|
190
|
-
| `authToken` | `string`
|
|
191
|
-
| `transformStreamPacket` | `TransformChatStreamPacket`
|
|
192
|
-
| `defaultMode` | `ChatAgentMode`
|
|
193
|
-
| `labels` | `AiChatLabels`
|
|
194
|
-
| `renderMessageBlock` | `ChatMessageBlockRenderer`
|
|
195
|
-
| `messageRenderOrder` | `ChatMessageRenderOrder`
|
|
196
|
-
| `
|
|
197
|
-
| `
|
|
240
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
241
|
+
| ------------------------ | ---------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------ |
|
|
242
|
+
| `apiBaseUrl` | `string` | 是 | 默认 adapter 的基础 URL。 |
|
|
243
|
+
| `authToken` | `string` | 是 | 默认 adapter 使用的 Authorization 请求头值。 |
|
|
244
|
+
| `transformStreamPacket` | `TransformChatStreamPacket` | 否 | 默认 adapter 的流式包归一化扩展点。 |
|
|
245
|
+
| `defaultMode` | `ChatAgentMode` | 否 | 新会话的初始 Agent 模式。 |
|
|
246
|
+
| `labels` | `AiChatLabels` | 否 | 可选的 UI 文案覆盖。 |
|
|
247
|
+
| `renderMessageBlock` | `ChatMessageBlockRenderer` | 否 | 自定义消息 block 渲染器,用于承接 `type: "custom"` 等扩展。 |
|
|
248
|
+
| `messageRenderOrder` | `ChatMessageRenderOrder` | 否 | 混合纯文本与结构化 block 时的渲染顺序。默认 `"blocks-first"`,设为 `"timeline"` 可按时间线优先渲染文本片段。 |
|
|
249
|
+
| `historySessionList` | `ChatHistorySessionListState` | 否 | 受控历史会话列表状态。 |
|
|
250
|
+
| `onLoadMoreSessions` | `() => void \| Promise<void>` | 否 | 会话列表滚动到底部且仍有下一页时触发。 |
|
|
251
|
+
| `onSelectHistorySession` | `(session) => ChatMessage[] \| void \| Promise<ChatMessage[] \| void>` | 否 | 点击未加载过的历史会话时触发。 |
|
|
252
|
+
| `enableImageAttachments` | `boolean` | 否 | 为 `false` 时隐藏上传按钮、禁用粘贴图片,并使程序化调用 `pickImages`/`pasteImages` 变为 no-op。默认 `true`。 |
|
|
253
|
+
| `children` | `ReactNode` | 是 | Provider 内部渲染的子元素。 |
|
|
198
254
|
|
|
199
255
|
### `ChatTransport`
|
|
200
256
|
|
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,43 @@ interface ChatSession {
|
|
|
33
33
|
model: string;
|
|
34
34
|
mode?: ChatAgentMode;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Loading states for externally hydrated historical session messages.
|
|
38
|
+
*/
|
|
39
|
+
type ChatSessionMessageLoadStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
40
|
+
/**
|
|
41
|
+
* A page of historical messages for a selected chat session.
|
|
42
|
+
*/
|
|
43
|
+
interface ChatHistorySessionMessagesPage {
|
|
44
|
+
messages: ChatMessage[];
|
|
45
|
+
previousCursor: string | null;
|
|
46
|
+
hasMorePrevious?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Arguments passed when host applications load older messages for a session.
|
|
50
|
+
*/
|
|
51
|
+
interface ChatHistorySessionMessageLoadArgs {
|
|
52
|
+
session: ChatSession;
|
|
53
|
+
cursor?: string | null;
|
|
54
|
+
limit?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Controlled historical session list state provided by host applications.
|
|
58
|
+
*/
|
|
59
|
+
interface ChatHistorySessionListState {
|
|
60
|
+
sessions: ChatSession[];
|
|
61
|
+
isLoading?: boolean;
|
|
62
|
+
hasMore?: boolean;
|
|
63
|
+
error?: string | null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Host-provided callbacks used by the controlled historical session list.
|
|
67
|
+
*/
|
|
68
|
+
interface ChatHistorySessionListHandlers {
|
|
69
|
+
onLoadMoreSessions?: () => void | Promise<void>;
|
|
70
|
+
onSelectHistorySession?: (session: ChatSession) => Promise<ChatHistorySessionMessagesPage | ChatMessage[] | void> | ChatHistorySessionMessagesPage | ChatMessage[] | void;
|
|
71
|
+
onLoadMoreHistoryMessages?: (args: ChatHistorySessionMessageLoadArgs) => Promise<ChatHistorySessionMessagesPage | void> | ChatHistorySessionMessagesPage | void;
|
|
72
|
+
}
|
|
36
73
|
/**
|
|
37
74
|
* Client-side image attachment metadata kept in chat messages.
|
|
38
75
|
*/
|
|
@@ -447,6 +484,9 @@ interface AiChatLabels {
|
|
|
447
484
|
skillLoading?: string;
|
|
448
485
|
skillEmpty?: string;
|
|
449
486
|
removeSkillAriaLabel?: string;
|
|
487
|
+
sessionHistoryLoading?: string;
|
|
488
|
+
sessionHistoryLoadFailed?: string;
|
|
489
|
+
sessionHistoryEmpty?: string;
|
|
450
490
|
}
|
|
451
491
|
/**
|
|
452
492
|
* State and actions exposed to custom new-chat trigger renderers.
|
|
@@ -477,6 +517,14 @@ interface AiChatProviderBaseProps {
|
|
|
477
517
|
handleConfirmationSubmit?: ChatConfirmationSubmitHandler;
|
|
478
518
|
/** Optional render order used for mixed text and structured message blocks. */
|
|
479
519
|
messageRenderOrder?: ChatMessageRenderOrder;
|
|
520
|
+
/** Controlled historical session list state provided by the host application. */
|
|
521
|
+
historySessionList?: ChatHistorySessionListState;
|
|
522
|
+
/** Optional callback used when the conversation list needs another page. */
|
|
523
|
+
onLoadMoreSessions?: ChatHistorySessionListHandlers['onLoadMoreSessions'];
|
|
524
|
+
/** Optional callback used when selecting a historical session that needs messages. */
|
|
525
|
+
onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
|
|
526
|
+
/** Optional callback used when the active historical session needs older messages. */
|
|
527
|
+
onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
|
|
480
528
|
/**
|
|
481
529
|
* Whether to enable image attachment uploads. Defaults to `true`.
|
|
482
530
|
* Set to `false` to hide the upload button, disable paste-image handling,
|
|
@@ -687,6 +735,15 @@ interface ChatState {
|
|
|
687
735
|
isStreamingBySession: Record<string, boolean>;
|
|
688
736
|
isStoppingBySession: Record<string, boolean>;
|
|
689
737
|
errorBySession: Record<string, string | null>;
|
|
738
|
+
sessionMessageLoadStatusBySession: Record<string, ChatSessionMessageLoadStatus>;
|
|
739
|
+
sessionMessageLoadErrorBySession: Record<string, string | null>;
|
|
740
|
+
historyMessagePaginationBySession: Record<string, ChatHistoryMessagePaginationState>;
|
|
741
|
+
}
|
|
742
|
+
interface ChatHistoryMessagePaginationState {
|
|
743
|
+
previousCursor: string | null;
|
|
744
|
+
hasMorePrevious: boolean;
|
|
745
|
+
isLoadingPrevious: boolean;
|
|
746
|
+
error: string | null;
|
|
690
747
|
}
|
|
691
748
|
interface ChatActions {
|
|
692
749
|
createSession: (session: ChatSession) => void;
|
|
@@ -695,7 +752,13 @@ interface ChatActions {
|
|
|
695
752
|
replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
|
|
696
753
|
setPreferredMode: (mode: ChatAgentMode) => void;
|
|
697
754
|
setSessionMode: (sessionId: string, mode: ChatAgentMode) => void;
|
|
755
|
+
hydrateHistorySessions: (sessions: ChatSession[]) => void;
|
|
698
756
|
appendMessage: (sessionId: string, message: ChatMessage) => void;
|
|
757
|
+
hydrateHistorySessionMessages: (sessionId: string, messages: ChatMessage[]) => void;
|
|
758
|
+
hydrateHistorySessionMessagesPage: (sessionId: string, page: ChatHistorySessionMessagesPage) => void;
|
|
759
|
+
prependHistorySessionMessagesPage: (sessionId: string, page: ChatHistorySessionMessagesPage) => void;
|
|
760
|
+
setHistorySessionPreviousMessagesLoadStatus: (sessionId: string, isLoading: boolean, error?: string | null) => void;
|
|
761
|
+
setHistorySessionMessageLoadStatus: (sessionId: string, status: ChatSessionMessageLoadStatus, error?: string | null) => void;
|
|
699
762
|
startStreamingMessage: (sessionId: string, message: ChatMessage) => void;
|
|
700
763
|
updateStreamingMessage: (sessionId: string, content: string) => void;
|
|
701
764
|
patchStreamingMessage: (sessionId: string, patch: ChatStreamMessagePatch) => void;
|
|
@@ -746,6 +809,14 @@ interface ChatContextValue {
|
|
|
746
809
|
transformStreamPacket?: TransformChatStreamPacket;
|
|
747
810
|
/** Whether image attachments are enabled. Defaults to true. */
|
|
748
811
|
enableImageAttachments: boolean;
|
|
812
|
+
/** Controlled historical session list state provided by the host application. */
|
|
813
|
+
historySessionList?: ChatHistorySessionListState;
|
|
814
|
+
/** Host callback triggered when the conversation list needs another page. */
|
|
815
|
+
onLoadMoreSessions?: ChatHistorySessionListHandlers['onLoadMoreSessions'];
|
|
816
|
+
/** Host callback triggered when a historical session needs messages. */
|
|
817
|
+
onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
|
|
818
|
+
/** Host callback triggered when a historical session needs older messages. */
|
|
819
|
+
onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
|
|
749
820
|
}
|
|
750
821
|
|
|
751
822
|
/**
|
|
@@ -762,4 +833,4 @@ declare const useChatContext: () => ChatContextValue;
|
|
|
762
833
|
*/
|
|
763
834
|
declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
|
|
764
835
|
|
|
765
|
-
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 };
|
|
836
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,43 @@ interface ChatSession {
|
|
|
33
33
|
model: string;
|
|
34
34
|
mode?: ChatAgentMode;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Loading states for externally hydrated historical session messages.
|
|
38
|
+
*/
|
|
39
|
+
type ChatSessionMessageLoadStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
40
|
+
/**
|
|
41
|
+
* A page of historical messages for a selected chat session.
|
|
42
|
+
*/
|
|
43
|
+
interface ChatHistorySessionMessagesPage {
|
|
44
|
+
messages: ChatMessage[];
|
|
45
|
+
previousCursor: string | null;
|
|
46
|
+
hasMorePrevious?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Arguments passed when host applications load older messages for a session.
|
|
50
|
+
*/
|
|
51
|
+
interface ChatHistorySessionMessageLoadArgs {
|
|
52
|
+
session: ChatSession;
|
|
53
|
+
cursor?: string | null;
|
|
54
|
+
limit?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Controlled historical session list state provided by host applications.
|
|
58
|
+
*/
|
|
59
|
+
interface ChatHistorySessionListState {
|
|
60
|
+
sessions: ChatSession[];
|
|
61
|
+
isLoading?: boolean;
|
|
62
|
+
hasMore?: boolean;
|
|
63
|
+
error?: string | null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Host-provided callbacks used by the controlled historical session list.
|
|
67
|
+
*/
|
|
68
|
+
interface ChatHistorySessionListHandlers {
|
|
69
|
+
onLoadMoreSessions?: () => void | Promise<void>;
|
|
70
|
+
onSelectHistorySession?: (session: ChatSession) => Promise<ChatHistorySessionMessagesPage | ChatMessage[] | void> | ChatHistorySessionMessagesPage | ChatMessage[] | void;
|
|
71
|
+
onLoadMoreHistoryMessages?: (args: ChatHistorySessionMessageLoadArgs) => Promise<ChatHistorySessionMessagesPage | void> | ChatHistorySessionMessagesPage | void;
|
|
72
|
+
}
|
|
36
73
|
/**
|
|
37
74
|
* Client-side image attachment metadata kept in chat messages.
|
|
38
75
|
*/
|
|
@@ -447,6 +484,9 @@ interface AiChatLabels {
|
|
|
447
484
|
skillLoading?: string;
|
|
448
485
|
skillEmpty?: string;
|
|
449
486
|
removeSkillAriaLabel?: string;
|
|
487
|
+
sessionHistoryLoading?: string;
|
|
488
|
+
sessionHistoryLoadFailed?: string;
|
|
489
|
+
sessionHistoryEmpty?: string;
|
|
450
490
|
}
|
|
451
491
|
/**
|
|
452
492
|
* State and actions exposed to custom new-chat trigger renderers.
|
|
@@ -477,6 +517,14 @@ interface AiChatProviderBaseProps {
|
|
|
477
517
|
handleConfirmationSubmit?: ChatConfirmationSubmitHandler;
|
|
478
518
|
/** Optional render order used for mixed text and structured message blocks. */
|
|
479
519
|
messageRenderOrder?: ChatMessageRenderOrder;
|
|
520
|
+
/** Controlled historical session list state provided by the host application. */
|
|
521
|
+
historySessionList?: ChatHistorySessionListState;
|
|
522
|
+
/** Optional callback used when the conversation list needs another page. */
|
|
523
|
+
onLoadMoreSessions?: ChatHistorySessionListHandlers['onLoadMoreSessions'];
|
|
524
|
+
/** Optional callback used when selecting a historical session that needs messages. */
|
|
525
|
+
onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
|
|
526
|
+
/** Optional callback used when the active historical session needs older messages. */
|
|
527
|
+
onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
|
|
480
528
|
/**
|
|
481
529
|
* Whether to enable image attachment uploads. Defaults to `true`.
|
|
482
530
|
* Set to `false` to hide the upload button, disable paste-image handling,
|
|
@@ -687,6 +735,15 @@ interface ChatState {
|
|
|
687
735
|
isStreamingBySession: Record<string, boolean>;
|
|
688
736
|
isStoppingBySession: Record<string, boolean>;
|
|
689
737
|
errorBySession: Record<string, string | null>;
|
|
738
|
+
sessionMessageLoadStatusBySession: Record<string, ChatSessionMessageLoadStatus>;
|
|
739
|
+
sessionMessageLoadErrorBySession: Record<string, string | null>;
|
|
740
|
+
historyMessagePaginationBySession: Record<string, ChatHistoryMessagePaginationState>;
|
|
741
|
+
}
|
|
742
|
+
interface ChatHistoryMessagePaginationState {
|
|
743
|
+
previousCursor: string | null;
|
|
744
|
+
hasMorePrevious: boolean;
|
|
745
|
+
isLoadingPrevious: boolean;
|
|
746
|
+
error: string | null;
|
|
690
747
|
}
|
|
691
748
|
interface ChatActions {
|
|
692
749
|
createSession: (session: ChatSession) => void;
|
|
@@ -695,7 +752,13 @@ interface ChatActions {
|
|
|
695
752
|
replaceSessionId: (previousSessionId: string, nextSessionId: string) => void;
|
|
696
753
|
setPreferredMode: (mode: ChatAgentMode) => void;
|
|
697
754
|
setSessionMode: (sessionId: string, mode: ChatAgentMode) => void;
|
|
755
|
+
hydrateHistorySessions: (sessions: ChatSession[]) => void;
|
|
698
756
|
appendMessage: (sessionId: string, message: ChatMessage) => void;
|
|
757
|
+
hydrateHistorySessionMessages: (sessionId: string, messages: ChatMessage[]) => void;
|
|
758
|
+
hydrateHistorySessionMessagesPage: (sessionId: string, page: ChatHistorySessionMessagesPage) => void;
|
|
759
|
+
prependHistorySessionMessagesPage: (sessionId: string, page: ChatHistorySessionMessagesPage) => void;
|
|
760
|
+
setHistorySessionPreviousMessagesLoadStatus: (sessionId: string, isLoading: boolean, error?: string | null) => void;
|
|
761
|
+
setHistorySessionMessageLoadStatus: (sessionId: string, status: ChatSessionMessageLoadStatus, error?: string | null) => void;
|
|
699
762
|
startStreamingMessage: (sessionId: string, message: ChatMessage) => void;
|
|
700
763
|
updateStreamingMessage: (sessionId: string, content: string) => void;
|
|
701
764
|
patchStreamingMessage: (sessionId: string, patch: ChatStreamMessagePatch) => void;
|
|
@@ -746,6 +809,14 @@ interface ChatContextValue {
|
|
|
746
809
|
transformStreamPacket?: TransformChatStreamPacket;
|
|
747
810
|
/** Whether image attachments are enabled. Defaults to true. */
|
|
748
811
|
enableImageAttachments: boolean;
|
|
812
|
+
/** Controlled historical session list state provided by the host application. */
|
|
813
|
+
historySessionList?: ChatHistorySessionListState;
|
|
814
|
+
/** Host callback triggered when the conversation list needs another page. */
|
|
815
|
+
onLoadMoreSessions?: ChatHistorySessionListHandlers['onLoadMoreSessions'];
|
|
816
|
+
/** Host callback triggered when a historical session needs messages. */
|
|
817
|
+
onSelectHistorySession?: ChatHistorySessionListHandlers['onSelectHistorySession'];
|
|
818
|
+
/** Host callback triggered when a historical session needs older messages. */
|
|
819
|
+
onLoadMoreHistoryMessages?: ChatHistorySessionListHandlers['onLoadMoreHistoryMessages'];
|
|
749
820
|
}
|
|
750
821
|
|
|
751
822
|
/**
|
|
@@ -762,4 +833,4 @@ declare const useChatContext: () => ChatContextValue;
|
|
|
762
833
|
*/
|
|
763
834
|
declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
|
|
764
835
|
|
|
765
|
-
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 };
|
|
836
|
+
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 };
|