@@ -284,7 +284,8 @@ export const useChat = defineStore('chat', {
284284
285285
286286 // 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)
288289 if ( data . type === 'message' ) {
289290
290291 if ( content . tool_approval_request ) {
@@ -310,7 +311,7 @@ export const useChat = defineStore('chat', {
310311 }
311312 }
312313
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)
314315 if ( data . type === 'tool' ) {
315316 const toolCallId = content . tool_call_id ;
316317 if ( ! toolCallId ) {
@@ -336,13 +337,51 @@ export const useChat = defineStore('chat', {
336337
337338 }
338339
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 ) {
340342 this . currentAssistantMessage . loading = false ;
341343 // Append content to the current assistant message
342344 this . currentAssistantMessage . content += data . content ;
343345 // Force Vue to detect the change
344346 this . messages = [ ...this . messages ] ;
345347 }
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+ }
346385 } catch ( e ) {
347386 throw new Error ( `${ e } ` ) ;
348387 }
0 commit comments