Skip to content

Commit 03233bf

Browse files
committed
Update useChatStore.ts
1 parent 4d20303 commit 03233bf

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

web/src/stores/useChatStore.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ChatMessage {
1212
id: string
1313
/** 消息角色:user / assistant / tool */
1414
role: 'user' | 'assistant' | 'tool'
15-
/** 消息类型:text / thinking / tool_call / code / welcome / system / verification / acceptance */
15+
/** 消息类型:text / thinking / tool_call / code / welcome / system / acceptance */
1616
type: 'text' | 'thinking' | 'tool_call' | 'code' | 'welcome' | 'system' | 'acceptance'
1717
/** 文本内容 */
1818
content: string
@@ -22,9 +22,9 @@ export interface ChatMessage {
2222
toolArgs?: string
2323
toolResult?: string
2424
toolStatus?: 'running' | 'done' | 'error'
25-
/** Acceptance 决策数据(仅 type === 'acceptance' 使用) */
25+
/** Acceptance 决策数据,仅 `type === 'acceptance'` 时使用 */
2626
acceptanceData?: AcceptanceDecidedPayload
27-
/** Thinking 数据(仅 type === 'thinking' 使用) */
27+
/** Thinking 附加数据,仅 `type === 'thinking'` 时使用 */
2828
thinkingData?: { collapsed: boolean }
2929
/** 代码语言 */
3030
language?: string
@@ -42,27 +42,27 @@ interface ChatState {
4242
messages: ChatMessage[]
4343
/** 是否正在生成 */
4444
isGenerating: boolean
45-
/** 当前会话是否正在执行上下文压缩 */
45+
/** 当前会话是否正在执行上下文压缩 */
4646
isCompacting: boolean
47-
/** 当前压缩触发模式,用于展示压缩来源 */
47+
/** 当前压缩触发模式,用于展示压缩来源 */
4848
compactMode: string
49-
/** 压缩期间展示给用户的持续状态文案 */
49+
/** 压缩期间展示给用户的持续状态文案 */
5050
compactMessage: string
51-
/** 当前 AI 回复缓冲 ID(流式追加用) */
51+
/** 当前 AI 回复缓冲 ID,用于流式追加 */
5252
streamingMessageId: string
5353
/** 当前 thinking 流式消息 ID */
5454
streamingThinkingMessageId: string
5555
/** 权限请求列表 */
5656
permissionRequests: PermissionRequestPayload[]
57-
/** 当前待回答 ask_user 问题(v1 单活跃) */
57+
/** 当前待回答 ask_user 问题 */
5858
pendingUserQuestion: PendingUserQuestionSnapshot | null
5959
/** Token 用量 */
6060
tokenUsage: TokenUsage | null
6161
/** 当前运行阶段 */
6262
phase: string
6363
/** 停止原因 */
6464
stopReason: string
65-
/** 会话切换中标记eventBridge 据此丢弃中间窗口期事件 */
65+
/** 会话切换中标记eventBridge 据此丢弃中间窗口期事件 */
6666
isTransitioning: boolean
6767
/** 当前 Agent 工作模式 */
6868
agentMode: 'build' | 'plan'
@@ -73,28 +73,27 @@ interface ChatState {
7373
addMessage: (msg: ChatMessage) => void
7474
setMessages: (messages: ChatMessage[]) => void
7575
removeMessage: (id: string) => void
76-
/** 从指定消息(含)开始截断 messages 数组并清理生成相关状态 */
76+
/** 从指定消息开始截断 messages,并清理生成相关状态 */
7777
truncateFromMessage: (messageId: string) => void
7878
appendChunk: (text: string) => void
79-
/** 原子操作:创建流式 assistant 消息 + 加入列表 + 设置 streamingMessageId */
79+
/** 原子操作:创建流式 assistant 消息并设置 streamingMessageId */
8080
startStreamingMessage: () => string
8181
finalizeMessage: (id: string, content: string) => void
8282
/** 创建流式 thinking 消息并设置 streamingThinkingMessageId */
8383
startThinkingMessage: () => string
84-
/** 追加 thinking 文本到当前流式 thinking 消息 */
84+
/** 追加 thinking 文本到当前流式消息 */
8585
appendThinkingChunk: (text: string) => void
86-
/** 终结 thinking 消息(collapsed=true)并清空 streamingThinkingMessageId */
86+
/** 终结 thinking 消息并清空 streamingThinkingMessageId */
8787
finalizeThinkingMessage: () => void
8888
updateToolCall: (toolCallId: string, result: string, status: ChatMessage['toolStatus']) => boolean
8989
appendToolOutput: (toolCallId: string, chunk: string) => void
90-
/** 将所有运行中的工具条目标记为指定状态,用于终止事件兜底收敛 UI */
90+
/** 将所有运行中的工具条目标记为指定状态,用于终止事件兜底收敛 UI */
9191
finalizeRunningToolCalls: (status: 'done' | 'error') => void
92-
/** 更新一条 verification 消息的 data(verification 进行中持续更新同一条消息) */
9392
setGenerating: (v: boolean) => void
9493
startCompacting: (mode?: string, message?: string) => void
9594
finishCompacting: () => void
9695
setStreamingMessageId: (id: string) => void
97-
/** 重置生成状态:终结当前流式消息 + 清除 isGenerating */
96+
/** 重置生成状态:终结当前流式消息并清除 isGenerating */
9897
resetGeneratingState: () => void
9998
setTransitioning: (v: boolean) => void
10099
addPermissionRequest: (req: PermissionRequestPayload) => void
@@ -138,7 +137,7 @@ export function createAssistantMessage(): ChatMessage {
138137
}
139138
}
140139

141-
/** 创建系统消息用于展示 slash command 执行结果 */
140+
/** 创建系统消息用于展示 slash command 执行结果 */
142141
export function createSystemMessage(text: string): ChatMessage {
143142
return {
144143
id: nextMsgId(),
@@ -227,7 +226,7 @@ export const useChatStore = create<ChatState>((set) => ({
227226
}
228227
}),
229228

230-
/** 原子操作:创建消息 + 加入列表 + 设置 streamingMessageId,避免竞态 */
229+
/** 原子操作:创建消息并设置 streamingMessageId,避免竞态 */
231230
startStreamingMessage: () => {
232231
const msg = createAssistantMessage()
233232
set((s) => ({
@@ -325,7 +324,7 @@ export const useChatStore = create<ChatState>((set) => ({
325324
}),
326325
setStreamingMessageId: (streamingMessageId) => set({ streamingMessageId }),
327326

328-
/** 重置生成状态:终结当前流式消息 + 清除 isGenerating */
327+
/** 重置生成状态:终结当前流式消息并清除 isGenerating */
329328
resetGeneratingState: () =>
330329
set((s) => {
331330
let msgs = s.messages
@@ -389,7 +388,7 @@ export const useChatStore = create<ChatState>((set) => ({
389388
setAgentMode: (agentMode) => set({ agentMode }),
390389
setPermissionMode: (permissionMode) => set({ permissionMode }),
391390

392-
/** 清理全部聊天状态,包括权限请求、token用量等。同时重置 eventBridge 模块级游标,避免跨会话泄漏 */
391+
/** 清理全部聊天状态,并重置 eventBridge 游标,避免跨会话泄漏 */
393392
clearMessages: () => {
394393
resetEventBridgeCursors()
395394
set({

0 commit comments

Comments
 (0)