@lobehub/lobehub 2.0.0-next.35 → 2.0.0-next.37

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/changelog/v1.json +18 -0
  3. package/next.config.ts +5 -6
  4. package/package.json +2 -2
  5. package/packages/agent-runtime/src/core/__tests__/runtime.test.ts +112 -77
  6. package/packages/agent-runtime/src/core/runtime.ts +63 -18
  7. package/packages/agent-runtime/src/types/generalAgent.ts +55 -0
  8. package/packages/agent-runtime/src/types/index.ts +1 -0
  9. package/packages/agent-runtime/src/types/instruction.ts +10 -3
  10. package/packages/const/src/user.ts +0 -1
  11. package/packages/context-engine/src/processors/GroupMessageFlatten.ts +8 -6
  12. package/packages/context-engine/src/processors/__tests__/GroupMessageFlatten.test.ts +12 -12
  13. package/packages/conversation-flow/src/__tests__/fixtures/inputs/branch/assistant-group-branches.json +249 -0
  14. package/packages/conversation-flow/src/__tests__/fixtures/inputs/branch/index.ts +4 -0
  15. package/packages/conversation-flow/src/__tests__/fixtures/inputs/branch/multi-assistant-group.json +260 -0
  16. package/packages/conversation-flow/src/__tests__/fixtures/outputs/branch/active-index-1.json +4 -0
  17. package/packages/conversation-flow/src/__tests__/fixtures/outputs/branch/assistant-group-branches.json +481 -0
  18. package/packages/conversation-flow/src/__tests__/fixtures/outputs/branch/conversation.json +5 -1
  19. package/packages/conversation-flow/src/__tests__/fixtures/outputs/branch/index.ts +4 -0
  20. package/packages/conversation-flow/src/__tests__/fixtures/outputs/branch/multi-assistant-group.json +407 -0
  21. package/packages/conversation-flow/src/__tests__/fixtures/outputs/branch/nested.json +18 -2
  22. package/packages/conversation-flow/src/__tests__/fixtures/outputs/complex-scenario.json +25 -3
  23. package/packages/conversation-flow/src/__tests__/parse.test.ts +12 -0
  24. package/packages/conversation-flow/src/index.ts +1 -1
  25. package/packages/conversation-flow/src/transformation/FlatListBuilder.ts +112 -34
  26. package/packages/conversation-flow/src/types/flatMessageList.ts +0 -12
  27. package/packages/conversation-flow/src/{types.ts → types/index.ts} +3 -14
  28. package/packages/database/src/models/__tests__/apiKey.test.ts +444 -0
  29. package/packages/database/src/models/message.ts +18 -19
  30. package/packages/types/src/aiChat.ts +2 -0
  31. package/packages/types/src/importer.ts +2 -2
  32. package/packages/types/src/message/ui/chat.ts +17 -1
  33. package/packages/types/src/message/ui/extra.ts +2 -2
  34. package/packages/types/src/message/ui/params.ts +2 -2
  35. package/packages/types/src/user/preference.ts +0 -4
  36. package/packages/utils/src/tokenizer/index.ts +3 -11
  37. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatInput/Desktop/MessageFromUrl.tsx +3 -3
  38. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatInput/V1Mobile/index.tsx +1 -1
  39. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatInput/V1Mobile/useSend.ts +3 -3
  40. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatInput/useSend.ts +6 -6
  41. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatList/Content.tsx +5 -3
  42. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatList/WelcomeChatItem/AgentWelcome/OpeningQuestions.tsx +2 -2
  43. package/src/app/[variants]/(main)/chat/components/conversation/features/ChatList/WelcomeChatItem/GroupWelcome/GroupUsageSuggest.tsx +2 -2
  44. package/src/app/[variants]/(main)/labs/page.tsx +0 -9
  45. package/src/features/ChatInput/ActionBar/STT/browser.tsx +3 -3
  46. package/src/features/ChatInput/ActionBar/STT/openai.tsx +3 -3
  47. package/src/features/Conversation/Error/AccessCodeForm.tsx +1 -1
  48. package/src/features/Conversation/Error/ChatInvalidApiKey.tsx +1 -1
  49. package/src/features/Conversation/Error/ClerkLogin/index.tsx +1 -1
  50. package/src/features/Conversation/Error/OAuthForm.tsx +1 -1
  51. package/src/features/Conversation/Error/index.tsx +0 -5
  52. package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +13 -10
  53. package/src/features/Conversation/Messages/Assistant/Extra/index.test.tsx +3 -8
  54. package/src/features/Conversation/Messages/Assistant/Extra/index.tsx +2 -6
  55. package/src/features/Conversation/Messages/Assistant/MessageContent.tsx +7 -9
  56. package/src/features/Conversation/Messages/Assistant/Tool/Inspector/PluginResult.tsx +2 -2
  57. package/src/features/Conversation/Messages/Assistant/Tool/Inspector/PluginState.tsx +2 -2
  58. package/src/features/Conversation/Messages/Assistant/Tool/Render/PluginSettings.tsx +4 -1
  59. package/src/features/Conversation/Messages/Assistant/Tool/Render/index.tsx +2 -3
  60. package/src/features/Conversation/Messages/Assistant/index.tsx +57 -60
  61. package/src/features/Conversation/Messages/Default.tsx +1 -0
  62. package/src/features/Conversation/Messages/Group/Actions/WithContentId.tsx +38 -10
  63. package/src/features/Conversation/Messages/Group/Actions/index.tsx +1 -1
  64. package/src/features/Conversation/Messages/Group/ContentBlock.tsx +1 -3
  65. package/src/features/Conversation/Messages/Group/GroupChildren.tsx +12 -12
  66. package/src/features/Conversation/Messages/Group/MessageContent.tsx +7 -1
  67. package/src/features/Conversation/Messages/Group/Tool/Render/PluginSettings.tsx +1 -1
  68. package/src/features/Conversation/Messages/Group/index.tsx +2 -1
  69. package/src/features/Conversation/Messages/Supervisor/index.tsx +2 -2
  70. package/src/features/Conversation/Messages/User/{Actions.tsx → Actions/ActionsBar.tsx} +26 -25
  71. package/src/features/Conversation/Messages/User/Actions/MessageBranch.tsx +107 -0
  72. package/src/features/Conversation/Messages/User/Actions/index.tsx +42 -0
  73. package/src/features/Conversation/Messages/User/index.tsx +43 -44
  74. package/src/features/Conversation/Messages/index.tsx +3 -3
  75. package/src/features/Conversation/components/AutoScroll.tsx +3 -3
  76. package/src/features/Conversation/components/Extras/Usage/UsageDetail/AnimatedNumber.tsx +55 -0
  77. package/src/features/Conversation/components/Extras/Usage/UsageDetail/index.tsx +5 -2
  78. package/src/features/Conversation/components/VirtualizedList/index.tsx +29 -20
  79. package/src/features/Conversation/hooks/useChatListActionsBar.tsx +8 -10
  80. package/src/features/Portal/Thread/Chat/ChatInput/useSend.ts +3 -3
  81. package/src/hooks/useHotkeys/chatScope.ts +15 -7
  82. package/src/libs/trpc/client/lambda.ts +4 -3
  83. package/src/server/routers/lambda/__tests__/aiChat.test.ts +1 -1
  84. package/src/server/routers/lambda/__tests__/integration/message.integration.test.ts +0 -26
  85. package/src/server/routers/lambda/aiChat.ts +3 -2
  86. package/src/server/routers/lambda/message.ts +8 -16
  87. package/src/server/services/message/__tests__/index.test.ts +29 -39
  88. package/src/server/services/message/index.ts +41 -36
  89. package/src/services/electron/desktopNotification.ts +6 -6
  90. package/src/services/electron/file.ts +6 -6
  91. package/src/services/file/ClientS3/index.ts +8 -8
  92. package/src/services/message/__tests__/metadata-race-condition.test.ts +157 -0
  93. package/src/services/message/index.ts +21 -15
  94. package/src/services/upload.ts +11 -11
  95. package/src/services/utils/abortableRequest.test.ts +161 -0
  96. package/src/services/utils/abortableRequest.ts +67 -0
  97. package/src/store/chat/agents/GeneralChatAgent.ts +137 -0
  98. package/src/store/chat/agents/createAgentExecutors.ts +395 -0
  99. package/src/store/chat/helpers.test.ts +0 -99
  100. package/src/store/chat/helpers.ts +0 -11
  101. package/src/store/chat/slices/aiChat/actions/__tests__/conversationControl.test.ts +332 -0
  102. package/src/store/chat/slices/aiChat/actions/__tests__/conversationLifecycle.test.ts +257 -0
  103. package/src/store/chat/slices/aiChat/actions/__tests__/helpers.ts +11 -2
  104. package/src/store/chat/slices/aiChat/actions/__tests__/rag.test.ts +6 -6
  105. package/src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.ts +391 -0
  106. package/src/store/chat/slices/aiChat/actions/__tests__/streamingStates.test.ts +179 -0
  107. package/src/store/chat/slices/aiChat/actions/conversationControl.ts +157 -0
  108. package/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts +329 -0
  109. package/src/store/chat/slices/aiChat/actions/generateAIGroupChat.ts +14 -14
  110. package/src/store/chat/slices/aiChat/actions/index.ts +12 -6
  111. package/src/store/chat/slices/aiChat/actions/rag.ts +9 -6
  112. package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +604 -0
  113. package/src/store/chat/slices/aiChat/actions/streamingStates.ts +84 -0
  114. package/src/store/chat/slices/builtinTool/actions/__tests__/localSystem.test.ts +4 -4
  115. package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +11 -11
  116. package/src/store/chat/slices/builtinTool/actions/interpreter.ts +8 -8
  117. package/src/store/chat/slices/builtinTool/actions/localSystem.ts +2 -2
  118. package/src/store/chat/slices/builtinTool/actions/search.ts +8 -8
  119. package/src/store/chat/slices/message/action.test.ts +79 -68
  120. package/src/store/chat/slices/message/actions/index.ts +39 -0
  121. package/src/store/chat/slices/message/actions/internals.ts +77 -0
  122. package/src/store/chat/slices/message/actions/optimisticUpdate.ts +260 -0
  123. package/src/store/chat/slices/message/actions/publicApi.ts +224 -0
  124. package/src/store/chat/slices/message/actions/query.ts +120 -0
  125. package/src/store/chat/slices/message/actions/runtimeState.ts +108 -0
  126. package/src/store/chat/slices/message/initialState.ts +13 -0
  127. package/src/store/chat/slices/message/reducer.test.ts +48 -370
  128. package/src/store/chat/slices/message/reducer.ts +17 -81
  129. package/src/store/chat/slices/message/selectors/chat.test.ts +13 -50
  130. package/src/store/chat/slices/message/selectors/chat.ts +78 -242
  131. package/src/store/chat/slices/message/selectors/dbMessage.ts +140 -0
  132. package/src/store/chat/slices/message/selectors/displayMessage.ts +301 -0
  133. package/src/store/chat/slices/message/selectors/messageState.ts +5 -2
  134. package/src/store/chat/slices/plugin/action.test.ts +62 -64
  135. package/src/store/chat/slices/plugin/action.ts +34 -28
  136. package/src/store/chat/slices/thread/action.test.ts +28 -31
  137. package/src/store/chat/slices/thread/action.ts +13 -10
  138. package/src/store/chat/slices/thread/selectors/index.ts +8 -6
  139. package/src/store/chat/slices/topic/reducer.ts +11 -3
  140. package/src/store/chat/store.ts +1 -1
  141. package/src/store/user/slices/preference/selectors/labPrefer.ts +0 -3
  142. package/packages/database/src/models/__tests__/message.grouping.test.ts +0 -812
  143. package/packages/database/src/utils/__tests__/groupMessages.test.ts +0 -1132
  144. package/packages/database/src/utils/groupMessages.ts +0 -361
  145. package/packages/utils/src/tokenizer/client.ts +0 -35
  146. package/packages/utils/src/tokenizer/estimated.ts +0 -4
  147. package/packages/utils/src/tokenizer/server.ts +0 -11
  148. package/packages/utils/src/tokenizer/tokenizer.worker.ts +0 -12
  149. package/src/app/(backend)/webapi/tokenizer/index.test.ts +0 -32
  150. package/src/app/(backend)/webapi/tokenizer/route.ts +0 -8
  151. package/src/features/Conversation/Error/InvalidAccessCode.tsx +0 -79
  152. package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChat.test.ts +0 -975
  153. package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +0 -1050
  154. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +0 -720
  155. package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +0 -849
  156. package/src/store/chat/slices/message/action.ts +0 -629
@@ -0,0 +1,407 @@
1
+ {
2
+ "contextTree": [
3
+ {
4
+ "id": "msg-user-1",
5
+ "type": "message"
6
+ },
7
+ {
8
+ "activeBranchIndex": 2,
9
+ "branches": [
10
+ [
11
+ {
12
+ "children": [
13
+ {
14
+ "id": "msg-assistant-1",
15
+ "tools": ["msg-tool-1"],
16
+ "type": "message"
17
+ },
18
+ {
19
+ "id": "msg-assistant-2",
20
+ "tools": ["msg-tool-2"],
21
+ "type": "message"
22
+ },
23
+ {
24
+ "id": "msg-assistant-3",
25
+ "type": "message"
26
+ }
27
+ ],
28
+ "id": "msg-assistant-1",
29
+ "type": "assistantGroup"
30
+ }
31
+ ],
32
+ [
33
+ {
34
+ "children": [
35
+ {
36
+ "id": "msg-assistant-4",
37
+ "tools": ["msg-tool-3", "msg-tool-4"],
38
+ "type": "message"
39
+ },
40
+ {
41
+ "id": "msg-assistant-5",
42
+ "type": "message"
43
+ }
44
+ ],
45
+ "id": "msg-assistant-4",
46
+ "type": "assistantGroup"
47
+ }
48
+ ],
49
+ [
50
+ {
51
+ "children": [
52
+ {
53
+ "id": "msg-assistant-6",
54
+ "tools": ["msg-tool-5"],
55
+ "type": "message"
56
+ },
57
+ {
58
+ "id": "msg-assistant-7",
59
+ "type": "message"
60
+ }
61
+ ],
62
+ "id": "msg-assistant-6",
63
+ "type": "assistantGroup"
64
+ }
65
+ ]
66
+ ],
67
+ "id": "branch-msg-user-1-0",
68
+ "parentMessageId": "msg-user-1",
69
+ "type": "branch"
70
+ }
71
+ ],
72
+ "flatList": [
73
+ {
74
+ "content": "杭州和北京天气如何",
75
+ "createdAt": 1704067200000,
76
+ "id": "msg-user-1",
77
+ "meta": {},
78
+ "metadata": {
79
+ "activeBranchIndex": 2
80
+ },
81
+ "parentId": null,
82
+ "role": "user",
83
+ "updatedAt": 1704067200000,
84
+ "branch": {
85
+ "activeBranchIndex": 2,
86
+ "count": 3
87
+ }
88
+ },
89
+ {
90
+ "id": "msg-assistant-6",
91
+ "role": "assistantGroup",
92
+ "content": "",
93
+ "parentId": "msg-user-1",
94
+ "createdAt": 1704067240000,
95
+ "updatedAt": 1704067240000,
96
+ "meta": {},
97
+ "children": [
98
+ {
99
+ "content": "",
100
+ "id": "msg-assistant-6",
101
+ "tools": [
102
+ {
103
+ "apiName": "search",
104
+ "arguments": "{\"query\":\"杭州 天气 现在 北京 天气 现在\"}",
105
+ "id": "call-5",
106
+ "identifier": "lobe-web-browsing",
107
+ "type": "builtin",
108
+ "result": {
109
+ "content": "<searchResults>\n <item title=\"Weather Portal\" url=\"https://weather3.example.com/\">Weather data...</item>\n</searchResults>",
110
+ "id": "msg-tool-5",
111
+ "state": {
112
+ "query": "杭州 天气 现在 北京 天气 现在",
113
+ "results": [
114
+ {
115
+ "title": "Weather Portal",
116
+ "url": "https://weather3.example.com/"
117
+ }
118
+ ]
119
+ }
120
+ },
121
+ "result_msg_id": "msg-tool-5"
122
+ }
123
+ ],
124
+ "usage": {
125
+ "totalInputTokens": 3441,
126
+ "totalOutputTokens": 186,
127
+ "totalTokens": 3627
128
+ }
129
+ },
130
+ {
131
+ "content": "好的——我可以立刻去查并把结果发给你。",
132
+ "id": "msg-assistant-7",
133
+ "usage": {
134
+ "totalInputTokens": 7604,
135
+ "totalOutputTokens": 584,
136
+ "totalTokens": 8188
137
+ }
138
+ }
139
+ ],
140
+ "usage": {
141
+ "totalInputTokens": 11045,
142
+ "totalOutputTokens": 770,
143
+ "totalTokens": 11815
144
+ }
145
+ }
146
+ ],
147
+ "messageMap": {
148
+ "msg-assistant-1": {
149
+ "content": "",
150
+ "createdAt": 1704067202000,
151
+ "id": "msg-assistant-1",
152
+ "meta": {},
153
+ "metadata": {
154
+ "totalInputTokens": 3441,
155
+ "totalOutputTokens": 310,
156
+ "totalTokens": 3751
157
+ },
158
+ "parentId": "msg-user-1",
159
+ "role": "assistant",
160
+ "tools": [
161
+ {
162
+ "apiName": "search",
163
+ "arguments": "{\"query\":\"杭州 北京 天气 现在\"}",
164
+ "id": "call-1",
165
+ "identifier": "lobe-web-browsing",
166
+ "type": "builtin"
167
+ }
168
+ ],
169
+ "updatedAt": 1704067202000
170
+ },
171
+ "msg-assistant-2": {
172
+ "content": "",
173
+ "createdAt": 1704067208000,
174
+ "id": "msg-assistant-2",
175
+ "meta": {},
176
+ "metadata": {
177
+ "totalInputTokens": 4128,
178
+ "totalOutputTokens": 183,
179
+ "totalTokens": 4311
180
+ },
181
+ "parentId": "msg-tool-1",
182
+ "role": "assistant",
183
+ "tools": [
184
+ {
185
+ "apiName": "search",
186
+ "arguments": "{\"query\":\"杭州 天气 北京 天气\"}",
187
+ "id": "call-2",
188
+ "identifier": "lobe-web-browsing",
189
+ "type": "builtin"
190
+ }
191
+ ],
192
+ "updatedAt": 1704067208000
193
+ },
194
+ "msg-assistant-3": {
195
+ "content": "你是想看现在的实时天气,还是未来几天的天气预报?",
196
+ "createdAt": 1704067214000,
197
+ "id": "msg-assistant-3",
198
+ "meta": {},
199
+ "metadata": {
200
+ "totalInputTokens": 6135,
201
+ "totalOutputTokens": 508,
202
+ "totalTokens": 6643
203
+ },
204
+ "parentId": "msg-tool-2",
205
+ "reasoning": {
206
+ "content": "用户询问天气,我需要确认他们想要的是实时天气还是预报。"
207
+ },
208
+ "role": "assistant",
209
+ "updatedAt": 1704067214000
210
+ },
211
+ "msg-assistant-4": {
212
+ "content": "",
213
+ "createdAt": 1704067220000,
214
+ "id": "msg-assistant-4",
215
+ "meta": {},
216
+ "metadata": {
217
+ "totalInputTokens": 3440,
218
+ "totalOutputTokens": 369,
219
+ "totalTokens": 3809
220
+ },
221
+ "parentId": "msg-user-1",
222
+ "role": "assistant",
223
+ "tools": [
224
+ {
225
+ "apiName": "search",
226
+ "arguments": "{\"query\":\"!google 杭州 天气\"}",
227
+ "id": "call-3",
228
+ "identifier": "lobe-web-browsing",
229
+ "type": "builtin"
230
+ },
231
+ {
232
+ "apiName": "search",
233
+ "arguments": "{\"query\":\"!google 北京 天气\"}",
234
+ "id": "call-4",
235
+ "identifier": "lobe-web-browsing",
236
+ "type": "builtin"
237
+ }
238
+ ],
239
+ "updatedAt": 1704067220000
240
+ },
241
+ "msg-assistant-5": {
242
+ "content": "我可以帮你查天气 —— 想确认一下你的偏好再去查实时数据。",
243
+ "createdAt": 1704067229000,
244
+ "id": "msg-assistant-5",
245
+ "meta": {},
246
+ "metadata": {
247
+ "totalInputTokens": 6425,
248
+ "totalOutputTokens": 675,
249
+ "totalTokens": 7100
250
+ },
251
+ "parentId": "msg-tool-4",
252
+ "role": "assistant",
253
+ "updatedAt": 1704067229000
254
+ },
255
+ "msg-assistant-6": {
256
+ "content": "",
257
+ "createdAt": 1704067240000,
258
+ "id": "msg-assistant-6",
259
+ "meta": {},
260
+ "metadata": {
261
+ "totalInputTokens": 3441,
262
+ "totalOutputTokens": 186,
263
+ "totalTokens": 3627
264
+ },
265
+ "parentId": "msg-user-1",
266
+ "role": "assistant",
267
+ "tools": [
268
+ {
269
+ "apiName": "search",
270
+ "arguments": "{\"query\":\"杭州 天气 现在 北京 天气 现在\"}",
271
+ "id": "call-5",
272
+ "identifier": "lobe-web-browsing",
273
+ "type": "builtin"
274
+ }
275
+ ],
276
+ "updatedAt": 1704067240000
277
+ },
278
+ "msg-assistant-7": {
279
+ "content": "好的——我可以立刻去查并把结果发给你。",
280
+ "createdAt": 1704067246000,
281
+ "id": "msg-assistant-7",
282
+ "meta": {},
283
+ "metadata": {
284
+ "totalInputTokens": 7604,
285
+ "totalOutputTokens": 584,
286
+ "totalTokens": 8188
287
+ },
288
+ "parentId": "msg-tool-5",
289
+ "role": "assistant",
290
+ "updatedAt": 1704067246000
291
+ },
292
+ "msg-tool-1": {
293
+ "content": "<searchResults>\n <item title=\"Weather Site\" url=\"https://weather.example.com/\">Weather information...</item>\n</searchResults>",
294
+ "createdAt": 1704067205000,
295
+ "id": "msg-tool-1",
296
+ "meta": {},
297
+ "parentId": "msg-assistant-1",
298
+ "plugin": {
299
+ "apiName": "search",
300
+ "identifier": "lobe-web-browsing",
301
+ "type": "builtin"
302
+ },
303
+ "pluginState": {
304
+ "query": "杭州 北京 天气 现在",
305
+ "results": [
306
+ {
307
+ "content": "Weather information...",
308
+ "title": "Weather Site",
309
+ "url": "https://weather.example.com/"
310
+ }
311
+ ]
312
+ },
313
+ "role": "tool",
314
+ "tool_call_id": "call-1",
315
+ "updatedAt": 1704067205000
316
+ },
317
+ "msg-tool-2": {
318
+ "content": "<searchResults>\n <item title=\"Weather Info\" url=\"https://weather2.example.com/\">More weather...</item>\n</searchResults>",
319
+ "createdAt": 1704067211000,
320
+ "id": "msg-tool-2",
321
+ "meta": {},
322
+ "parentId": "msg-assistant-2",
323
+ "plugin": {
324
+ "apiName": "search",
325
+ "identifier": "lobe-web-browsing",
326
+ "type": "builtin"
327
+ },
328
+ "role": "tool",
329
+ "tool_call_id": "call-2",
330
+ "updatedAt": 1704067211000
331
+ },
332
+ "msg-tool-3": {
333
+ "content": "<searchResults />",
334
+ "createdAt": 1704067223000,
335
+ "id": "msg-tool-3",
336
+ "meta": {},
337
+ "parentId": "msg-assistant-4",
338
+ "plugin": {
339
+ "apiName": "search",
340
+ "identifier": "lobe-web-browsing",
341
+ "type": "builtin"
342
+ },
343
+ "pluginState": {
344
+ "query": "!google 杭州 天气",
345
+ "results": []
346
+ },
347
+ "role": "tool",
348
+ "tool_call_id": "call-3",
349
+ "updatedAt": 1704067223000
350
+ },
351
+ "msg-tool-4": {
352
+ "content": "<searchResults />",
353
+ "createdAt": 1704067226000,
354
+ "id": "msg-tool-4",
355
+ "meta": {},
356
+ "parentId": "msg-assistant-4",
357
+ "plugin": {
358
+ "apiName": "search",
359
+ "identifier": "lobe-web-browsing",
360
+ "type": "builtin"
361
+ },
362
+ "pluginState": {
363
+ "query": "!google 北京 天气",
364
+ "results": []
365
+ },
366
+ "role": "tool",
367
+ "tool_call_id": "call-4",
368
+ "updatedAt": 1704067226000
369
+ },
370
+ "msg-tool-5": {
371
+ "content": "<searchResults>\n <item title=\"Weather Portal\" url=\"https://weather3.example.com/\">Weather data...</item>\n</searchResults>",
372
+ "createdAt": 1704067243000,
373
+ "id": "msg-tool-5",
374
+ "meta": {},
375
+ "parentId": "msg-assistant-6",
376
+ "plugin": {
377
+ "apiName": "search",
378
+ "identifier": "lobe-web-browsing",
379
+ "type": "builtin"
380
+ },
381
+ "pluginState": {
382
+ "query": "杭州 天气 现在 北京 天气 现在",
383
+ "results": [
384
+ {
385
+ "title": "Weather Portal",
386
+ "url": "https://weather3.example.com/"
387
+ }
388
+ ]
389
+ },
390
+ "role": "tool",
391
+ "tool_call_id": "call-5",
392
+ "updatedAt": 1704067243000
393
+ },
394
+ "msg-user-1": {
395
+ "content": "杭州和北京天气如何",
396
+ "createdAt": 1704067200000,
397
+ "id": "msg-user-1",
398
+ "meta": {},
399
+ "metadata": {
400
+ "activeBranchIndex": 2
401
+ },
402
+ "parentId": null,
403
+ "role": "user",
404
+ "updatedAt": 1704067200000
405
+ }
406
+ }
407
+ }
@@ -111,7 +111,11 @@
111
111
  "parentId": null,
112
112
  "createdAt": 1704067200000,
113
113
  "updatedAt": 1704067200000,
114
- "meta": {}
114
+ "meta": {},
115
+ "branch": {
116
+ "activeBranchIndex": 0,
117
+ "count": 3
118
+ }
115
119
  },
116
120
  {
117
121
  "id": "msg-302",
@@ -138,6 +142,10 @@
138
142
  "meta": {},
139
143
  "metadata": {
140
144
  "activeBranchIndex": 1
145
+ },
146
+ "branch": {
147
+ "activeBranchIndex": 1,
148
+ "count": 2
141
149
  }
142
150
  },
143
151
  {
@@ -162,7 +170,11 @@
162
170
  "parentId": "msg-307",
163
171
  "createdAt": 1704067220000,
164
172
  "updatedAt": 1704067220000,
165
- "meta": {}
173
+ "meta": {},
174
+ "branch": {
175
+ "activeBranchIndex": 0,
176
+ "count": 2
177
+ }
166
178
  },
167
179
  {
168
180
  "id": "msg-311",
@@ -189,6 +201,10 @@
189
201
  "meta": {},
190
202
  "metadata": {
191
203
  "activeBranchIndex": 1
204
+ },
205
+ "branch": {
206
+ "activeBranchIndex": 1,
207
+ "count": 2
192
208
  }
193
209
  },
194
210
  {
@@ -62,6 +62,9 @@
62
62
  {
63
63
  "content": "I'll help you debug the code. Let me first check the syntax and run some analysis.",
64
64
  "id": "msg-502",
65
+ "performance": {
66
+ "tps": 45
67
+ },
65
68
  "tools": [
66
69
  {
67
70
  "id": "tool-lint",
@@ -93,9 +96,24 @@
93
96
  },
94
97
  "result_msg_id": "msg-504"
95
98
  }
96
- ]
99
+ ],
100
+ "usage": {
101
+ "totalInputTokens": 32,
102
+ "totalOutputTokens": 48,
103
+ "totalTokens": 80,
104
+ "cost": 0.00024
105
+ }
97
106
  }
98
- ]
107
+ ],
108
+ "performance": {
109
+ "tps": 45
110
+ },
111
+ "usage": {
112
+ "totalInputTokens": 32,
113
+ "totalOutputTokens": 48,
114
+ "totalTokens": 80,
115
+ "cost": 0.00024
116
+ }
99
117
  },
100
118
  {
101
119
  "id": "msg-505",
@@ -104,7 +122,11 @@
104
122
  "parentId": "msg-504",
105
123
  "createdAt": 1704067210000,
106
124
  "updatedAt": 1704067210000,
107
- "meta": {}
125
+ "meta": {},
126
+ "branch": {
127
+ "activeBranchIndex": 0,
128
+ "count": 2
129
+ }
108
130
  },
109
131
  {
110
132
  "id": "msg-506",
@@ -71,6 +71,18 @@ describe('parse', () => {
71
71
 
72
72
  expect(serializeParseResult(result)).toEqual(outputs.branch.nested);
73
73
  });
74
+
75
+ it('should handle multiple assistant group branches', () => {
76
+ const result = parse(inputs.branch.multiAssistantGroup);
77
+
78
+ expect(serializeParseResult(result)).toEqual(outputs.branch.multiAssistantGroup);
79
+ });
80
+
81
+ it('should handle assistant group with branches', () => {
82
+ const result = parse(inputs.branch.assistantGroupBranches);
83
+
84
+ expect(serializeParseResult(result)).toEqual(outputs.branch.assistantGroupBranches);
85
+ });
74
86
  });
75
87
 
76
88
  describe('Compare Mode', () => {
@@ -11,7 +11,7 @@ export type {
11
11
  } from './types';
12
12
 
13
13
  // Flat Message List Types - for virtual list rendering
14
- export type { BranchMetadata, FlatMessage, FlatMessageExtra, FlatMessageRole } from './types';
14
+ export type { FlatMessage, FlatMessageExtra, FlatMessageRole } from './types';
15
15
 
16
16
  // Shared Types
17
17
  export type { HelperMaps, IdNode, Message, MessageGroupMetadata, ParseResult } from './types';