1import{o as d}from"./socket-sender-n02SHk12.js";import{t as c}from"./chunk-C1Fl7IZA.js";import"./supabase-client-DxxLNWj6.js";import"./jsx-runtime-BQRNzMtc.js";import"./preload-helper-ckwbz45p.js";import"./vanilla-BXWV201_.js";function p(n){return n.serverAckedAt===null?"pre_server_ack":n.firstTokenSeen?"mid_stream":"pre_first_token"}function _(n,t,e){const r=t.serverAckedAt!==null?t.serverAckedAt-t.sentAt:null,o=t.firstTokenSeen&&t.ttftMs!==null?e-t.sentAt-t.ttftMs:0,a=o>0?t.totalChars/o*1e3:null;return{request_id:n,model:t.model,server_ack_ms:r,active_gen_started_seen:t.serverAckedAt!==null,ttft_ms:t.ttftMs,max_chunk_gap_ms:t.maxChunkGapMs,total_chunks:t.totalChunks,long_gap_count:t.longGapCount,had_first_token:t.firstTokenSeen,total_chars:t.totalChars,chars_per_sec:a}}const g=5e3,v=120*1e3,s=new Map,w=64;let A=!1;function m(n){n.watchdog&&(clearTimeout(n.watchdog),n.watchdog=null)}function f(n,t){m(t),t.watchdog=setTimeout(()=>{const e=performance.now();c("chat.stranded",{..._(n,t,e),phase:p(t),elapsed_ms:e-t.sentAt}),s.delete(n)},v)}function C(){if(s.size===0)return;const n=performance.now();for(const[t,e]of s)c("chat.in_flight",{..._(t,e,n),phase:p(e),elapsed_ms:n-e.sentAt})}function E(){A||(A=!0,d("active_gen:started",n=>{const t=n.request_id;if(!t)return;const e=s.get(t);!e||e.serverAckedAt!==null||(e.serverAckedAt=performance.now(),f(t,e))}),d("active_gen:text_chunk",n=>{const t=n.request_id;if(!t)return;const e=s.get(t);if(!e)return;const r=n.delta||"";if(!r)return;const o=performance.now(),a=o-e.lastChunkAt;if(e.lastChunkAt=o,e.totalChunks+=1,e.totalChars+=r.length,e.firstTokenSeen)a>e.maxChunkGapMs&&(e.maxChunkGapMs=a),a>g&&(e.longGapCount+=1);else{const i=o-e.sentAt;e.firstTokenSeen=!0,e.ttftMs=i;const l=e.serverAckedAt!==null?e.serverAckedAt-e.sentAt:null;c("chat.first_token",{request_id:t,model:e.model,ttft_ms:i,server_ack_ms:l,active_gen_started_seen:e.serverAckedAt!==null})}f(t,e)}),d("active_gen:terminal",n=>{const t=n.request_id;if(!t)return;const e=s.get(t);if(!e)return;m(e);const r=performance.now(),o=r-e.sentAt;c("chat.complete",{..._(t,e,r),outcome:n.outcome,total_ms:o,had_error:!!n.error}),s.delete(t)}),typeof window<"u"&&window.addEventListener("pagehide",C))}function D(n){const{requestId:t,model:e,contentLength:r,imageCount:o,hasWorkflowContext:a,conversationId:i}=n;if(!t)return;if(s.size>=w){const u=s.keys().next().value;if(u!==void 0){const k=s.get(u);k&&m(k),s.delete(u)}}const l=performance.now(),h={sentAt:l,model:e,serverAckedAt:null,firstTokenSeen:!1,ttftMs:null,lastChunkAt:l,maxChunkGapMs:0,totalChunks:0,longGapCount:0,totalChars:0,watchdog:null};s.set(t,h),f(t,h),c("chat.send_started",{request_id:t,model:e,content_length:r,image_count:o,has_workflow_context:a,conversation_id:i})}export{E as installChatTelemetry,D as trackChatSendStarted};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.