@@ -1685,27 +1685,6 @@ export const useCopilotStore = create<CopilotStore>()(
16851685 } ) . catch ( ( ) => { } )
16861686 } catch { }
16871687 }
1688-
1689- // Optimistic stats: mark aborted for the in-flight user message
1690- try {
1691- const { currentChat : cc , currentUserMessageId, messageMetaById } = get ( ) as any
1692- if ( cc ?. id && currentUserMessageId ) {
1693- const meta = messageMetaById ?. [ currentUserMessageId ] || null
1694- const agentDepth = meta ?. depth
1695- const maxEnabled = meta ?. maxEnabled
1696- fetch ( '/api/copilot/stats' , {
1697- method : 'POST' ,
1698- headers : { 'Content-Type' : 'application/json' } ,
1699- body : JSON . stringify ( {
1700- chatId : cc . id ,
1701- messageId : currentUserMessageId ,
1702- ...( typeof agentDepth === 'number' ? { depth : agentDepth } : { } ) ,
1703- ...( typeof maxEnabled === 'boolean' ? { maxEnabled } : { } ) ,
1704- aborted : true ,
1705- } ) ,
1706- } ) . catch ( ( ) => { } )
1707- }
1708- } catch { }
17091688 } catch {
17101689 set ( { isSendingMessage : false , isAborting : false , abortController : null } )
17111690 }
@@ -2113,47 +2092,7 @@ export const useCopilotStore = create<CopilotStore>()(
21132092
21142093 // Post copilot_stats record (input/output tokens can be null for now)
21152094 try {
2116- const { messageMetaById } = get ( ) as any
2117- const meta =
2118- ( messageMetaById && ( messageMetaById as any ) [ triggerUserMessageId || '' ] ) || null
2119- const agentDepth = meta ?. depth ?? get ( ) . agentDepth
2120- const maxEnabled = meta ?. maxEnabled ?? ( agentDepth >= 2 && ! get ( ) . agentPrefetch )
2121- const { useWorkflowDiffStore } = await import ( '@/stores/workflow-diff/store' )
2122- const diffState = useWorkflowDiffStore . getState ( ) as any
2123- const diffCreated = ! ! diffState ?. isShowingDiff
2124- const diffAccepted = false // acceptance may arrive earlier or later via diff store
2125- const endMs = Date . now ( )
2126- const duration = Math . max ( 0 , endMs - startTimeMs )
2127- const chatIdToUse = get ( ) . currentChat ?. id || context . newChatId
2128- // Prefer provided trigger user message id; fallback to last user message
2129- let userMessageIdToUse = triggerUserMessageId
2130- if ( ! userMessageIdToUse ) {
2131- const msgs = get ( ) . messages
2132- for ( let i = msgs . length - 1 ; i >= 0 ; i -- ) {
2133- const m = msgs [ i ]
2134- if ( m . role === 'user' ) {
2135- userMessageIdToUse = m . id
2136- break
2137- }
2138- }
2139- }
2140- if ( chatIdToUse ) {
2141- fetch ( '/api/copilot/stats' , {
2142- method : 'POST' ,
2143- headers : { 'Content-Type' : 'application/json' } ,
2144- body : JSON . stringify ( {
2145- chatId : chatIdToUse ,
2146- messageId : userMessageIdToUse || assistantMessageId ,
2147- depth : agentDepth ,
2148- maxEnabled,
2149- diffCreated,
2150- diffAccepted,
2151- duration : duration ?? null ,
2152- inputTokens : null ,
2153- outputTokens : null ,
2154- } ) ,
2155- } ) . catch ( ( ) => { } )
2156- }
2095+ // Removed: stats sending now occurs only on accept/reject with minimal payload
21572096 } catch { }
21582097 } finally {
21592098 clearTimeout ( timeoutId )
0 commit comments