import{Zma as f}from"./cli-0.5.4-aacw1src.mjs";function j(q){return typeof q==="number"&&Number.isFinite(q)?q:0}function V(q,z){let B=q;for(let K of z){if(B==null||typeof B!=="object")return;B=B[K]}return B}function k(q){if(!q)return!1;let z="";try{z=new URL(q).hostname.toLowerCase()}catch{}if(!z){let W=q.toLowerCase();return W.includes("localhost")||W.includes("127.0.0.1")||W.includes("::1")}let B=z.startsWith("[")&&z.endsWith("]")?z.slice(1,-1):z;if(B==="localhost"||B.endsWith(".localhost")||B.endsWith(".local")||B.endsWith(".lan")||B.endsWith(".internal")||B.endsWith(".intranet")||B.endsWith(".home.arpa"))return!0;let K=B.match(x);if(K){let W=Number(K[1]),$=Number(K[2]);if(W===10)return!0;if(W===172&&$>=16&&$<=31)return!0;if(W===192&&$===168)return!0;if(W===127)return!0;if(W===169&&$===254)return!0;if(W===100&&$>=64&&$<=127)return!0}if(B==="::1"||B==="::")return!0;if(B.startsWith("fe80:")||L.test(B)||Y.test(B))return!0;return!1}function C(q,z){if(q==="github")return z?.githubNativeAnthropic?"copilot-claude":"copilot";if(q==="firstParty"||q==="bedrock"||q==="vertex"||q==="foundry")return"anthropic";if(q==="gemini")return"gemini";if(q==="codex")return"codex";if(q==="openai"){let B=z?.openAiBaseUrl??"";if(k(B))return"self-hosted";let K=B.toLowerCase();if(K.includes(":11434"))return"ollama";if(K.includes("moonshot")||K.includes("kimi"))return"kimi";if(K.includes("deepseek"))return"deepseek";return"openai"}return"openai"}function A(q){if(!q||typeof q!=="object")return 0;let z=q,B=j(z.cache_read_input_tokens);if(B>0)return B;let K=j(V(q,["input_tokens_details","cached_tokens"]))||j(V(q,["prompt_tokens_details","cached_tokens"]));if(K>0)return K;let W=j(z.cached_tokens);if(W>0)return W;let $=j(z.prompt_cache_hit_tokens);if($>0)return $;let Q=j(z.cached_content_token_count);if(Q>0)return Q;return 0}function M(q){let z=A(q),B=q??{},K=j(B.input_tokens)||j(B.prompt_tokens),W=K>=z?K-z:K,$=j(B.output_tokens)||j(B.completion_tokens);return{input_tokens:W,output_tokens:$,cache_creation_input_tokens:0,cache_read_input_tokens:z}}function U(q,z){if(!q||typeof q!=="object")return G;let B=q,K=j(B.cache_read_input_tokens),W=j(B.cache_creation_input_tokens),$=j(B.input_tokens);if(z==="copilot"||z==="ollama")return G;if(z==="self-hosted"&&K===0&&W===0)return G;let Q=K+W+$;return{read:K,created:W,total:Q,hitRate:Q>0?Math.min(1,K/Q):null,supported:!0}}function w(q){if(!q)return"[Cache: N/A]";if(!q.supported)return"[Cache: N/A]";if(q.read===0&&q.created===0)return"[Cache: cold]";let z=[`${H(q.read)} read`];if(q.hitRate!==null)z.push(`hit ${Math.round(q.hitRate*100)}%`);return`[Cache: ${z.join(" • ")}]`}function I(q){if(!q)return"[Cache: N/A]";if(!q.supported)return"[Cache: N/A]";let z=[`read=${H(q.read)}`,`created=${H(q.created)}`];if(q.hitRate!==null)z.push(`hit=${Math.round(q.hitRate*100)}%`);else z.push("hit=n/a");return`[Cache: ${z.join(" ")}]`}function H(q){if(q<1000)return String(q);if(q<1e6)return`${(q/1000).toFixed(1).replace(F,"")}k`;return`${(q/1e6).toFixed(1).replace(F,"")}m`}function Z(q,z){if(!q.supported&&!z.supported)return G;if(!q.supported)return z;if(!z.supported)return q;let B=q.read+z.read,K=q.created+z.created,W=q.total+z.total;return{read:B,created:K,total:W,hitRate:W>0?B/W:null,supported:!0}}var G,x,L,Y,F;var y=f(()=>{G={read:0,created:0,total:0,hitRate:null,supported:!1};x=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,L=/^fc[0-9a-f]{0,2}:/,Y=/^fd[0-9a-f]{0,2}:/,F=/\.0$/});function O(q){return{currentTurn:X,session:X,history:Array(q),historyWriteIdx:0,historySize:0,historyMax:q}}function _(q,z){J.currentTurn=Z(J.currentTurn,q),J.session=Z(J.session,q);let B={timestamp:Date.now(),label:z,metrics:q};if(J.history[J.historyWriteIdx]=B,J.historyWriteIdx=(J.historyWriteIdx+1)%J.historyMax,J.historySize<J.historyMax)J.historySize++}function E(){J.currentTurn=X}function g(){J.currentTurn=X,J.session=X,J.history=Array(J.historyMax),J.historyWriteIdx=0,J.historySize=0}function N(){return J.currentTurn}function R(){return J.session}function b(){if(J.historySize<J.historyMax)return J.history.slice(0,J.historySize);let q=J.history.slice(J.historyWriteIdx),z=J.history.slice(0,J.historyWriteIdx);return q.concat(z)}var D=500,X,J;var S=f(()=>{y();X={read:0,created:0,total:0,hitRate:null,supported:!1};J=O(D)});
export{C as mU,M as nU,U as oU,w as pU,I as qU,y as rU,_ as sU,E as tU,g as uU,N as vU,R as wU,b as xU,S as yU};
