@@ -284,7 +284,8 @@ export const useChat = defineStore('chat', {
284
284
285
285
286
286
// This is where we process different types of messages from Opey by their 'type' field
287
- // Process pending tool calls
287
+ // Support both legacy ('message','tool','token') and new streaming types
288
+ // Pending tool calls (legacy)
288
289
if ( data . type === 'message' ) {
289
290
290
291
if ( content . tool_approval_request ) {
@@ -310,7 +311,7 @@ export const useChat = defineStore('chat', {
310
311
}
311
312
}
312
313
313
- // Now we handle the actual messages from the completed/ failed tool calls
314
+ // Now we handle the actual messages from the completed/ failed tool calls (legacy)
314
315
if ( data . type === 'tool' ) {
315
316
const toolCallId = content . tool_call_id ;
316
317
if ( ! toolCallId ) {
@@ -336,13 +337,51 @@ export const useChat = defineStore('chat', {
336
337
337
338
}
338
339
339
- if ( data . type === 'assistant_complete' && data . content ) {
340
+ // Assistant token streaming (legacy and new)
341
+ if ( ( data . type === 'token' || data . type === 'assistant_token' ) && data . content ) {
340
342
this . currentAssistantMessage . loading = false ;
341
343
// Append content to the current assistant message
342
344
this . currentAssistantMessage . content += data . content ;
343
345
// Force Vue to detect the change
344
346
this . messages = [ ...this . messages ] ;
345
347
}
348
+
349
+ // Assistant final content (new API emits assistant_complete)
350
+ if ( data . type === 'assistant_complete' && data . content ) {
351
+ this . currentAssistantMessage . loading = false ;
352
+ this . currentAssistantMessage . content += data . content ;
353
+ this . messages = [ ...this . messages ] ;
354
+ }
355
+
356
+ // New API: Tool lifecycle events mapping to UI model
357
+ if ( data . type === 'tool_start' ) {
358
+ const toolMessage : OpeyToolCall = {
359
+ status : 'pending' ,
360
+ toolCall : {
361
+ id : data . tool_call_id ,
362
+ name : data . tool_name ,
363
+ args : data . tool_input ,
364
+ }
365
+ } as unknown as OpeyToolCall ;
366
+ this . currentAssistantMessage . toolCalls . push ( toolMessage )
367
+ this . messages = [ ...this . messages ] ;
368
+ }
369
+ if ( data . type === 'tool_end' ) {
370
+ const toolMessage = this . getToolCallById ( data . tool_call_id )
371
+ if ( toolMessage ) {
372
+ toolMessage . status = data . status === 'error' ? 'error' : 'success'
373
+ toolMessage . output = data . tool_output
374
+ this . messages = [ ...this . messages ] ;
375
+ }
376
+ }
377
+ if ( data . type === 'approval_request' ) {
378
+ // Mark awaiting approval on matched tool call if present
379
+ const toolMessage = this . getToolCallById ( data . tool_call_id )
380
+ if ( toolMessage ) {
381
+ toolMessage . status = 'awaiting_approval'
382
+ this . messages = [ ...this . messages ] ;
383
+ }
384
+ }
346
385
} catch ( e ) {
347
386
throw new Error ( `${ e } ` ) ;
348
387
}
0 commit comments