llmpt 1.3.4 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,16 +3,8 @@
3
3
  ## v1.3.4 (2026-06-16)
4
4
 
5
5
  ### 修复
6
- - Response Assistant:非流式响应中 `message.tool_calls` 现在正确提取并以 `tool_use` 块显示在 Response 区域
7
- - Markdown 渲染一致性:System Prompt / Messages / Response 全部使用相同字体(去掉 `sans` 差异),Thinking 统一用 `compact`(pre-wrap)模式避免 `<p>` margin 累积
8
- - `ThinkingBlock` / `ThinkingSection` 展开时统一走 `compact` 路径(与 `TextPane` 行为对齐)
9
-
10
- ---
11
-
12
- ## v1.3.3 (2026-06-16)
13
-
14
- ### 其他
15
- - 版本号修正(内部版本,无功能变更)
6
+ - Response Assistant:非流式 OpenAI 响应中 `message.tool_calls` 现在正确提取并在 Response 区域显示
7
+ - `tool_use` 块(Anthropic 及上述 OpenAI 转换)改为可折叠形式,默认收起,显示函数名 + 参数数量,右侧淡显 call id,展开后显示完整 JSON 参数
16
8
 
17
9
  ---
18
10
 
@@ -0,0 +1,21 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{C as t,D as n,E as r,O as i,S as a,T as o,_ as s,a as c,b as l,c as u,d,f,g as p,h as m,i as h,k as g,l as _,m as v,n as y,o as b,p as x,r as ee,s as te,t as S,u as ne,v as re,w as C,x as ie,y as ae}from"./react-vendor-BnH7jZBV.js";import{_ as w,a as T,b as E,c as D,d as O,f as k,g as A,h as j,i as M,l as oe,m as N,n as P,o as F,p as I,r as L,s as se,t as ce,u as R,v as z,y as B}from"./markdown-DsSlw-Z4.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var V=e(g(),1),H=e(i(),1),U=`/api`;async function W(e,t){let n=await fetch(`${U}${e}`,t);if(!n.ok)throw Error(`API error: ${n.status}`);return n.json()}var G={getTraces:e=>{let t=new URLSearchParams;e?.model&&t.set(`model`,e.model),e?.provider&&t.set(`provider`,e.provider),e?.status&&t.set(`status`,e.status),e?.keyword&&t.set(`keyword`,e.keyword),e?.limit&&t.set(`limit`,String(e.limit)),e?.offset&&t.set(`offset`,String(e.offset));let n=t.toString();return W(`/traces${n?`?`+n:``}`)},getTrace:e=>W(`/traces/${e}`),reloadTraces:()=>W(`/traces/reload`,{method:`POST`}),getTraceFiles:()=>W(`/traces/files`),deleteTraceFile:e=>W(`/traces/file/${encodeURIComponent(e)}`,{method:`DELETE`}),deleteTraces:(e=!1)=>W(`/traces${e?`?files=true`:``}`,{method:`DELETE`}),getProviders:()=>W(`/providers`),getStats:()=>W(`/stats`),getConfig:()=>W(`/config`)};function le({url:e,onEvent:t,reconnectInterval:n=3e3}){let r=(0,V.useRef)(null),[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(),s=(0,V.useRef)(t);s.current=t;let c=(0,V.useCallback)(()=>{try{let t=new WebSocket(e);t.onopen=()=>{a(!0),console.log(`[WS] Connected`)},t.onclose=()=>{a(!1),console.log(`[WS] Disconnected, reconnecting...`),o.current=setTimeout(c,n)},t.onerror=e=>{console.error(`[WS] Error:`,e),t.close()},t.onmessage=e=>{try{let t=JSON.parse(e.data);s.current?.(t)}catch{}},r.current=t}catch{o.current=setTimeout(c,n)}},[e,n]);return(0,V.useEffect)(()=>(c(),()=>{clearTimeout(o.current),r.current?.close()}),[c]),{connected:i,send:(0,V.useCallback)(e=>{r.current?.readyState===WebSocket.OPEN&&r.current.send(JSON.stringify(e))},[])}}var K=x();function q({content:e,children:t,placement:n=`top`,delay:r=300}){let[i,a]=(0,V.useState)(!1),{refs:o,floatingStyles:s,context:l}=h({open:i,onOpenChange:a,placement:n,whileElementsMounted:f,middleware:[ne(4),_({padding:8}),d({padding:8})]}),{getReferenceProps:p,getFloatingProps:m}=te([b(l,{move:!1,delay:{open:r,close:0}}),c(l),ee(l),u(l,{role:`tooltip`})]);return(0,K.jsxs)(K.Fragment,{children:[V.cloneElement(t,p({ref:o.setReference,...t.props})),i&&e!=null&&e!==``&&(0,K.jsx)(y,{children:(0,K.jsx)(`div`,{ref:o.setFloating,style:{...s,zIndex:9999,pointerEvents:`none`},...m(),children:(0,K.jsx)(`div`,{style:{background:`var(--bg-card)`,color:`var(--text-secondary)`,border:`1px solid var(--border)`,padding:`5px 9px`,borderRadius:`6px`,fontSize:`11.5px`,fontFamily:`var(--sans)`,fontWeight:400,lineHeight:1.5,letterSpacing:`0.01em`,maxWidth:`260px`,boxShadow:`var(--shadow-md)`},children:e})})})]})}function ue({traces:e,activeId:t,onSelect:n,loading:r,onDeleteFile:i}){let[s,c]=(0,V.useState)(`time`),[l,u]=(0,V.useState)(new Set);if(r)return(0,K.jsxs)(`div`,{className:`flex items-center justify-center flex-1 gap-2 text-sm`,style:{color:`var(--text-tertiary)`},children:[(0,K.jsx)(a,{size:14,className:`animate-spin`}),` 加载中…`]});if(e.length===0)return(0,K.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-sm`,style:{color:`var(--text-tertiary)`},children:`暂无请求`});let d=[...e].sort((e,t)=>{if(s===`model`)return(e.model||``).localeCompare(t.model||``);if(s===`status`){let n=e=>e===`streaming`?0:e===`error`?1:e===`pending`?2:3;return n(e.status)-n(t.status)}return 0}),f=d.findIndex(e=>e.id===t),m=d.length>1&&f>=0?Math.round(f/(d.length-1)*100):0,h=[];if(s===`time`){let e=[];for(let t of d)t.sourceFile&&!e.includes(t.sourceFile)&&e.push(t.sourceFile);let t=d.map((e,t)=>({trace:e,globalIdx:t+1})).filter(e=>!e.trace.sourceFile);t.length>0&&h.push({key:`__session__`,label:`当前会话`,fileName:null,items:t});for(let t of e){let e=d.map((e,t)=>({trace:e,globalIdx:t+1})).filter(e=>e.trace.sourceFile===t);if(e.length>0){let n=t.match(/traces-(\d{4}-\d{2}-\d{2})T(\d{2}-\d{2}-\d{2})/),r=n?`${n[1]} ${n[2].replace(/-/g,`:`)}`:t.replace(`.jsonl`,``);h.push({key:t,label:r,fileName:t,items:e})}}}else h.push({key:`__all__`,label:``,fileName:null,items:d.map((e,t)=>({trace:e,globalIdx:t+1}))});let g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(`div`,{className:`flex flex-col flex-1 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b flex-shrink-0`,style:{borderColor:`var(--border-light)`},children:[(0,K.jsx)(`span`,{className:`text-[10px]`,style:{color:`var(--text-tertiary)`},children:`排序`}),(0,K.jsx)(`div`,{className:`sidebar-sort-segment`,children:[`time`,`model`,`status`].map(e=>(0,K.jsx)(q,{content:e===`time`?`按请求时间(最新在前)`:e===`model`?`按模型名称字母`:`按状态(接收中→错误→完成)`,placement:`bottom`,delay:400,children:(0,K.jsx)(`button`,{className:`sidebar-sort-btn${s===e?` active`:``}`,onClick:()=>c(e),children:e===`time`?`时间`:e===`model`?`模型`:`状态`})},e))}),f>=0&&(0,K.jsxs)(`span`,{className:`ml-auto text-[10px]`,style:{color:`var(--text-tertiary)`},children:[f+1,`/`,d.length]})]}),f>=0&&(0,K.jsx)(`div`,{style:{height:`2px`,background:`var(--border)`},children:(0,K.jsx)(`div`,{style:{width:`${m}%`,height:`100%`,background:`var(--blue)`,transition:`width .2s`}})}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto sidebar-scroll`,children:h.map(e=>{let r=l.has(e.key),a=h.length>1,s=e.fileName!==null;return(0,K.jsxs)(V.Fragment,{children:[a&&(0,K.jsxs)(`div`,{className:`file-group-header${s?` history`:` session`}`,onClick:()=>g(e.key),children:[(0,K.jsx)(o,{size:12,className:`file-group-chevron flex-shrink-0`,style:{transform:r?`rotate(-90deg)`:`rotate(0deg)`}}),(0,K.jsx)(`span`,{className:`file-group-label`,children:e.label}),(0,K.jsx)(`span`,{className:`file-group-count`,children:e.items.length}),(()=>{let t=e.items.reduce((e,{trace:t})=>e+(t.usage?.promptTokens||0),0),n=e.items.reduce((e,{trace:t})=>e+(t.usage?.completionTokens||0),0),r=e.items.reduce((e,{trace:t})=>e+(t.usage?.reasoningTokens||0),0),i=e.items.reduce((e,{trace:t})=>e+(t.usage?.cacheReadTokens||0),0),a=e.items.reduce((e,{trace:t})=>e+(t.usage?.cacheWriteTokens||0),0),o=e.items.reduce((e,{trace:t})=>e+(t.usage?.cachedTokens||0),0),s=t+n;if(s===0)return null;let c=e=>e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e),l=e=>e.toLocaleString();return(0,K.jsx)(q,{content:(0,K.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`auto auto`,gap:`1px 10px`,fontSize:`11px`},children:[(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`输入`}),(0,K.jsx)(`span`,{style:{color:`var(--blue)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(t)}),(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`输出`}),(0,K.jsx)(`span`,{style:{color:`var(--green)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(n)}),r>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`推理`}),(0,K.jsx)(`span`,{style:{color:`var(--indigo)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(r)})]}),i+o>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`缓存命中`}),(0,K.jsx)(`span`,{style:{color:`var(--cyan)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(i+o)})]}),a>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`缓存写入`}),(0,K.jsx)(`span`,{style:{color:`var(--cyan)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(a)})]}),(0,K.jsx)(`span`,{style:{color:`var(--text-secondary)`,fontWeight:600,borderTop:`1px solid var(--border-light)`,paddingTop:`2px`,marginTop:`1px`},children:`合计`}),(0,K.jsx)(`span`,{style:{color:`var(--text)`,fontWeight:700,textAlign:`right`,fontFamily:`var(--mono)`,borderTop:`1px solid var(--border-light)`,paddingTop:`2px`,marginTop:`1px`},children:l(s)})]}),placement:`bottom`,delay:200,children:(0,K.jsx)(`span`,{className:`file-group-tokens`,onClick:e=>e.stopPropagation(),children:c(s)})})})(),e.fileName&&i&&(0,K.jsx)(q,{content:`删除:${e.fileName}`,placement:`bottom`,children:(0,K.jsx)(`button`,{className:`file-group-delete`,onClick:t=>{t.stopPropagation(),i(e.fileName)},children:(0,K.jsx)(p,{size:11})})})]}),!r&&e.items.map(({trace:e,globalIdx:r})=>(0,K.jsx)(de,{trace:e,isActive:e.id===t,onClick:()=>n(e.id),turnNumber:r},e.id))]},e.key)})})]})}function J(e){let t=(e||``).toLowerCase();return t.includes(`opus`)?{bg:`var(--purple-bg)`,fg:`var(--purple)`}:t.includes(`sonnet`)?{bg:`var(--blue-bg)`,fg:`var(--blue)`}:t.includes(`haiku`)||t.includes(`gpt-4`)?{bg:`var(--green-bg)`,fg:`var(--green)`}:t.includes(`gpt-3`)?{bg:`var(--amber-bg)`,fg:`var(--amber)`}:t.includes(`glm`)||t.includes(`zhipu`)||t.includes(`deepseek`)?{bg:`var(--blue-bg)`,fg:`var(--blue)`}:t.includes(`qwen`)?{bg:`var(--purple-bg)`,fg:`var(--purple)`}:t.includes(`llama`)?{bg:`var(--orange-bg)`,fg:`var(--orange)`}:t.includes(`mistral`)?{bg:`var(--amber-bg)`,fg:`var(--amber)`}:{bg:`var(--bg-code)`,fg:`var(--text-tertiary)`}}function de({trace:e,isActive:t,onClick:n,turnNumber:r}){let i=new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),o=e.duration>0?e.duration>=1e3?`${(e.duration/1e3).toFixed(1)}s`:`${e.duration}ms`:e.status===`streaming`?`...`:`-`,s=e.usage?.promptTokens||0,c=e.usage?.completionTokens||0,l=e.usage?.totalTokens||0,u=fe(e),d=J(e.model),f=(e.model||`unknown`).split(`/`).pop()||`unknown`,p=e.status===`streaming`,m=e.status===`error`,h=e.status===`pending`,g=m?`var(--red)`:p?`var(--blue)`:e.status===`completed`?`var(--green)`:`var(--amber)`;return(0,K.jsxs)(`div`,{onClick:n,className:`sidebar-item px-3 py-2 cursor-pointer border-b transition-colors`,style:{background:t?`var(--bg-active)`:`transparent`,borderColor:`var(--border-light)`},children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`font-mono flex-shrink-0 text-center`,style:{color:`var(--text-tertiary)`,fontSize:`11px`,fontWeight:700,minWidth:`20px`},children:[`#`,r]}),u?(0,K.jsx)(`span`,{className:`text-xs truncate flex-1`,style:{color:`var(--text)`},children:u}):(0,K.jsx)(`span`,{className:`text-xs truncate flex-1`,style:{color:`var(--text-tertiary)`,fontStyle:`italic`},children:`No content`}),(0,K.jsx)(`span`,{className:`text-[10px] flex-shrink-0 font-mono`,style:{color:`var(--text-tertiary)`},children:i})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center flex-shrink-0`,style:{minWidth:`20px`},children:p?(0,K.jsx)(a,{size:12,className:`animate-spin`,style:{color:`var(--blue)`}}):m?(0,K.jsx)(v,{size:14,strokeWidth:2.8,style:{color:`var(--red)`}}):h?(0,K.jsx)(`span`,{className:`rounded-full`,style:{width:`9px`,height:`9px`,background:`var(--amber)`,display:`inline-block`}}):(0,K.jsx)(`span`,{className:`rounded-full`,style:{width:`9px`,height:`9px`,background:g,display:`inline-block`}})}),(0,K.jsx)(q,{content:e.model,placement:`right`,delay:500,children:(0,K.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full truncate max-w-[90px]`,style:{background:d.bg,color:d.fg,lineHeight:`1.3`},children:f})}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5 flex-shrink-0 font-mono`,style:{color:`var(--text-tertiary)`,fontSize:`10px`},children:[l>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{style:{color:`var(--blue)`,fontWeight:600},children:[`↑`,s]}),(0,K.jsxs)(`span`,{style:{color:`var(--green)`,fontWeight:600},children:[`↓`,c]})]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(C,{size:9}),o]})]})]})]})}function fe(e){let t=e.request.body.messages;if(t){let e=[...t].reverse().find(e=>e.role===`user`);if(e)return(typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.filter(e=>typeof e==`object`&&e.type===`text`).map(e=>e.text||``).join(` `):``).replace(/\s+/g,` `).trim().slice(0,100)}return e.request.body.prompt?String(e.request.body.prompt).replace(/\s+/g,` `).trim().slice(0,100):``}z.registerLanguage(`javascript`,w),z.registerLanguage(`js`,w),z.registerLanguage(`jsx`,w),z.registerLanguage(`typescript`,A),z.registerLanguage(`ts`,A),z.registerLanguage(`tsx`,A),z.registerLanguage(`python`,j),z.registerLanguage(`py`,j),z.registerLanguage(`bash`,N),z.registerLanguage(`sh`,N),z.registerLanguage(`shell`,N),z.registerLanguage(`json`,I),z.registerLanguage(`css`,k),z.registerLanguage(`xml`,O),z.registerLanguage(`html`,O),z.registerLanguage(`markdown`,R),z.registerLanguage(`md`,R),z.registerLanguage(`sql`,oe),z.registerLanguage(`go`,D),z.registerLanguage(`rust`,se),z.registerLanguage(`java`,F),z.registerLanguage(`cpp`,T),z.registerLanguage(`c`,T),z.registerLanguage(`csharp`,M),z.registerLanguage(`yaml`,L),z.registerLanguage(`yml`,L),z.registerLanguage(`diff`,P),z.registerLanguage(`plaintext`,ce);function pe({inline:e,className:n,children:i,node:a,...o}){let[s,c]=(0,V.useState)(!1),l=String(i??``).replace(/\n$/,``),u=/language-(\w+)/.exec(n??``)?.[1]??``,d=e??(!n?.startsWith(`language-`)&&!l.includes(`
2
+ `)),f=(0,V.useCallback)(async()=>{try{await navigator.clipboard.writeText(l),c(!0),setTimeout(()=>c(!1),1500)}catch{}},[l]);if(d)return(0,K.jsx)(`code`,{className:n,...o,children:i});let p=``;try{p=u&&z.getLanguage(u)?z.highlight(l,{language:u,ignoreIllegals:!0}).value:z.highlightAuto(l).value}catch{p=l.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}return(0,K.jsxs)(`div`,{className:`md-code-wrapper`,children:[(0,K.jsxs)(`div`,{className:`md-code-header`,children:[u&&(0,K.jsx)(`span`,{className:`md-code-lang`,children:u}),(0,K.jsxs)(`button`,{className:`md-code-copy${s?` copied`:``}`,onClick:f,title:`复制代码`,children:[s?(0,K.jsx)(r,{size:11}):(0,K.jsx)(t,{size:11}),(0,K.jsx)(`span`,{children:s?`已复制`:`复制`})]})]}),(0,K.jsx)(`pre`,{className:`hljs md-code-pre`,children:(0,K.jsx)(`code`,{className:`hljs${u?` language-${u}`:``}`,dangerouslySetInnerHTML:{__html:B.sanitize(p)}})})]})}function me({text:e,isStreaming:t,className:n}){return e?(0,K.jsx)(`div`,{className:[`md-prose`,t?`streaming-cursor`:``,n??``].filter(Boolean).join(` `),children:(0,K.jsx)(S,{remarkPlugins:[E],components:{code:pe,a:({href:e,children:t,...n})=>(0,K.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,...n,children:t})},children:e})}):null}var he={};function ge({trace:e}){let t=e.response.status||0,n=t>=400||e.status===`error`,r=e.status===`streaming`,i=(0,V.useRef)(null);(0,V.useEffect)(()=>{r&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e.response,r]);let a=e.request.body.messages||[],o=Ne(e),s=a.filter(e=>e.role!==`system`&&e.role!==`developer`),c=Pe(e),l=Array.isArray(c)?c.filter(e=>e.type===`thinking`).map(e=>e.thinking||``).join(`
3
+
4
+ `):``,u=Array.isArray(c)?(()=>{let e=c.filter(e=>e.type!==`thinking`);return e.length===0?null:e.length===1&&e[0].type===`text`?e[0].text||null:e})():c,d=e.request.body.tools||[],f=e.toolCalls||[],p=e.usage;return(0,K.jsxs)(`div`,{ref:i,className:`detail-content`,children:[n&&(0,K.jsxs)(`div`,{className:`error-banner`,children:[(0,K.jsx)(`span`,{className:`eb-icon`,children:`⚠`}),(0,K.jsx)(`span`,{className:`eb-code`,children:t>=400?`HTTP ${t}`:e.error?.code||`Error`}),(0,K.jsx)(`span`,{className:`eb-sep`,children:`·`}),(0,K.jsx)(`span`,{className:`eb-message`,children:e.error?.message||`Unknown error`})]}),(0,K.jsx)(ve,{usage:p,duration:e.duration,ttfb:e.ttfb,isStreaming:r}),o&&(0,K.jsx)(Y,{title:`System Prompt`,defaultOpen:!1,copyText:o,badge:`system`,children:(0,K.jsx)(Ce,{text:o})}),s.length>0&&(0,K.jsx)(Y,{title:`Messages`,defaultOpen:!0,badge:`${s.length}`,copyText:s.map(e=>{let t=typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.map(e=>e.text||e.thinking||``).join(`
5
+ `):``;return`[${e.role.toUpperCase()}]\n${t}`}).join(`
6
+
7
+ ---
8
+
9
+ `),children:(0,K.jsx)(`div`,{className:`messages-list`,children:s.map((e,t)=>(0,K.jsx)(ye,{message:e},t))})}),(0,K.jsxs)(Y,{title:`Response`,defaultOpen:!0,badge:t?`${t}`:r?`live`:void 0,copyText:(u?typeof u==`string`?u:u.map(e=>e.text||``).join(`
10
+
11
+ `):``)||void 0,children:[l&&(0,K.jsx)(Ee,{content:l}),u?(0,K.jsx)(ye,{message:{role:`assistant`,content:u},isStreaming:r}):e.error?(0,K.jsxs)(`div`,{className:`msg system`,style:{marginBottom:0},children:[(0,K.jsx)(`span`,{className:`msg-role`,style:{background:`var(--red)`,color:`#fff`},children:`ERROR`}),(0,K.jsxs)(`div`,{className:`content-block`,children:[`[`,e.error.code,`] `,e.error.message]})]}):(0,K.jsx)(`div`,{style:{color:`var(--text-tertiary)`,fontSize:`13px`,padding:`4px 0`},children:r?(0,K.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:`8px`,color:`var(--text-tertiary)`,fontSize:`12px`},children:[`接收中 `,(0,K.jsxs)(`span`,{className:`streaming-dots`,children:[(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{})]})]}):`No response content`})]}),f.length>0&&(0,K.jsx)(Y,{title:`Tool Calls`,defaultOpen:!0,badge:`${f.length}`,copyText:f.map(e=>`${e.name}(${JSON.stringify(e.arguments,null,2)})`).join(`
12
+
13
+ `),children:(0,K.jsx)(`div`,{style:{display:`grid`,gap:`4px`},children:f.map((e,t)=>(0,K.jsx)(De,{toolCall:e},t))})}),d.length>0&&(0,K.jsx)(Y,{title:`Tools Definition`,defaultOpen:!1,badge:`${d.length}`,copyText:JSON.stringify(d,null,2),children:(0,K.jsx)(Oe,{tools:d})}),(0,K.jsx)(Y,{title:`Raw JSON`,defaultOpen:!1,copyText:JSON.stringify(e,null,2),children:(0,K.jsx)(Q,{data:e})})]})}function _e(e){return e>=1e3?`${(e/1e3).toFixed(2)}s`:`${e}ms`}function ve({usage:e,duration:t,ttfb:n,isStreaming:r}){let i=(e?.cachedTokens||0)+(e?.cacheReadTokens||0)+(e?.cacheWriteTokens||0)>0;return(0,K.jsx)(`div`,{className:`token-usage-bar`,children:(0,K.jsx)(`div`,{className:`token-bar`,children:r?(0,K.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:`6px`,fontSize:`11px`,color:`var(--text-tertiary)`},children:[`接收中 `,(0,K.jsxs)(`span`,{className:`streaming-dots`,children:[(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{})]})]}):e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`tok-group`,children:(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-label`,children:`合计`}),(0,K.jsx)(`span`,{className:`tok-val`,style:{color:`var(--text)`,fontSize:`12px`},children:e.totalTokens.toLocaleString()})]})}),(0,K.jsxs)(`span`,{className:`tok-group`,children:[(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-arrow`,style:{color:`var(--blue)`},children:`↑`}),(0,K.jsx)(`span`,{className:`tok-val`,children:e.promptTokens.toLocaleString()})]}),(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-arrow`,style:{color:`var(--green)`},children:`↓`}),(0,K.jsx)(`span`,{className:`tok-val`,children:e.completionTokens.toLocaleString()})]}),(e.reasoningTokens||0)>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--indigo)`}}),(0,K.jsx)(`span`,{className:`tok-label`,children:`推理`}),(0,K.jsx)(`span`,{className:`tok-val`,children:e.reasoningTokens.toLocaleString()})]})]}),i&&(0,K.jsxs)(`span`,{className:`tok-group`,children:[(e.cachedTokens||0)>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--cyan)`}}),(0,K.jsx)(`span`,{className:`tok-label`,children:`缓存命中`}),(0,K.jsx)(`span`,{className:`tok-val`,children:e.cachedTokens.toLocaleString()})]}),(e.cacheReadTokens||0)>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--cyan)`}}),(0,K.jsx)(`span`,{className:`tok-label`,children:`缓存读`}),(0,K.jsx)(`span`,{className:`tok-val`,children:e.cacheReadTokens.toLocaleString()})]}),(e.cacheWriteTokens||0)>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--amber)`}}),(0,K.jsx)(`span`,{className:`tok-label`,children:`缓存写`}),(0,K.jsx)(`span`,{className:`tok-val`,children:e.cacheWriteTokens.toLocaleString()})]})]}),(0,K.jsxs)(`span`,{className:`tok-group`,children:[n>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-label`,children:`首字`}),(0,K.jsx)(`span`,{className:`tok-val`,children:_e(n)})]}),t>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-label`,children:`耗时`}),(0,K.jsx)(`span`,{className:`tok-val`,children:_e(t)})]}),t>0&&(e.completionTokens||0)>0&&(0,K.jsxs)(`span`,{className:`tok-item`,children:[(0,K.jsx)(`span`,{className:`tok-label`,children:`速度`}),(0,K.jsxs)(`span`,{className:`tok-val`,children:[Math.round(e.completionTokens/(t/1e3)),` tok/s`]})]})]})]}):(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`,fontSize:`11px`},children:`无 token 数据`})})})}function Y({title:e,defaultOpen:t,badge:n,copyText:r,children:i}){let[a,o]=(0,V.useState)(he[e]??t);return(0,K.jsxs)(`div`,{className:`section`,children:[(0,K.jsxs)(`div`,{className:`section-header`,onClick:()=>{let t=!a;o(t),he[e]=t},children:[(0,K.jsx)(`span`,{className:`chevron${a?` open`:``}`,children:`▶`}),(0,K.jsx)(`span`,{className:`title`,children:e}),n&&(0,K.jsx)(`span`,{className:`badge`,children:n}),r!==void 0&&r!==``&&(0,K.jsx)(Z,{getText:()=>r,className:`copy-btn`,stopPropagation:!0})]}),a&&(0,K.jsx)(`div`,{className:`section-body open`,children:i})]})}function ye({message:e,isStreaming:t}){let n=e.role,r=e.content,i=n===`assistant`,a=typeof r==`string`,[o,s]=(0,V.useState)(i?`markdown`:`raw`),c=()=>typeof r==`string`?r:Array.isArray(r)?r.map(e=>e.text||e.thinking||``).filter(Boolean).join(`
14
+
15
+ `):``,l=n===`user`?`user`:n===`assistant`?`assistant`:n===`system`||n===`developer`?`system`:n===`tool`?`tool_result`:``,u=e.tool_calls;e.tool_call_id;let d=a?r.trim().length>0:Array.isArray(r)&&r.length>0,f=a&&r.trim().length>0,[p,m]=(0,V.useState)(n===`tool`);return(0,K.jsxs)(`div`,{className:`msg ${l}`,children:[(0,K.jsxs)(`div`,{className:`msg-header-row`,children:[(0,K.jsxs)(`span`,{className:`msg-role msg-role-toggle`,onClick:()=>m(e=>!e),title:p?`展开`:`收起`,children:[(0,K.jsx)(`span`,{className:`msg-collapse-arrow${p?``:` open`}`,children:`▶`}),n.toUpperCase()]}),f&&(0,K.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginLeft:`8px`,marginTop:0,display:p?`none`:void 0},children:[(0,K.jsx)(`button`,{className:`text-toggle-btn${o===`raw`?` active`:``}`,onClick:()=>s(`raw`),children:`原文`}),(0,K.jsx)(`button`,{className:`text-toggle-btn${o===`markdown`?` active`:``}`,onClick:()=>s(`markdown`),children:`渲染`})]}),(0,K.jsx)(`span`,{style:{marginLeft:`auto`},children:(0,K.jsx)(Z,{getText:c})})]}),!p&&(0,K.jsxs)(K.Fragment,{children:[a?(0,K.jsx)(we,{text:r,mode:o}):Array.isArray(r)?(0,K.jsx)(`div`,{children:r.map((e,n)=>(0,K.jsx)(xe,{block:e,isStreaming:t&&n===r.length-1},n))}):r?(0,K.jsx)(Q,{data:r}):null,u&&u.length>0&&(0,K.jsx)(`div`,{className:`msg-tool-calls`,children:u.map(e=>(0,K.jsx)(be,{toolCall:e},e.id))})]}),p&&(d||u&&u.length>0)&&(0,K.jsx)(`div`,{className:`msg-collapsed-hint`,children:[d?a?`${r.slice(0,60).replace(/\n/g,` `)}…`:`${r.length} 块`:``,u?.length?`${u.length} tool_call`:``].filter(Boolean).join(` · `)})]})}function be({toolCall:e}){let[t,n]=(0,V.useState)(!1),r=e.function.arguments;try{r=JSON.parse(e.function.arguments)}catch{}let i=typeof r==`object`&&r?Object.keys(r).length:0;return(0,K.jsxs)(`div`,{className:`tool-block`,children:[(0,K.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,K.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,K.jsx)(`span`,{className:`tb-name`,children:e.function.name}),!t&&i>0&&(0,K.jsxs)(`span`,{className:`tb-desc`,children:[`(`,i,` args)`]})]}),t&&(0,K.jsx)(`div`,{className:`tool-block-body open`,children:typeof r==`object`?(0,K.jsx)(Q,{data:r}):(0,K.jsx)(`pre`,{className:`text-raw`,children:String(r)})})]})}function xe({block:e,isStreaming:t}){let[n,r]=(0,V.useState)(`markdown`);if(e.type===`text`||e.type===`input_text`||e.type===`output_text`){let i=e.text||``;return(0,K.jsxs)(`div`,{className:`content-block`,children:[(0,K.jsx)(`div`,{className:`msg-header-row`,style:{marginBottom:`4px`},children:(0,K.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginTop:0},children:[(0,K.jsx)(`button`,{className:`text-toggle-btn${n===`raw`?` active`:``}`,onClick:()=>r(`raw`),children:`原文`}),(0,K.jsx)(`button`,{className:`text-toggle-btn${n===`markdown`?` active`:``}`,onClick:()=>r(`markdown`),children:`渲染`})]})}),(0,K.jsx)(X,{text:i,mode:n,isStreaming:t})]})}return e.type===`thinking`?(0,K.jsx)(Te,{content:e.thinking||``}):e.type===`tool_use`?(0,K.jsx)(Se,{block:e}):e.type===`tool_result`?(0,K.jsxs)(`div`,{className:`content-block block-framed`,style:{borderColor:`var(--purple)`,background:`var(--purple-bg)`},children:[(0,K.jsxs)(`span`,{className:`tool-use-label`,style:{color:`var(--purple)`,background:`color-mix(in srgb, var(--purple) 15%, transparent)`},children:[`↩ tool_result: `,e.tool_use_id||``]}),(0,K.jsx)(`div`,{className:`content-block-text`,children:typeof e.text==`string`?e.text:(0,K.jsx)(Q,{data:e.text})})]}):(0,K.jsx)(Q,{data:e})}function Se({block:e}){let[t,n]=(0,V.useState)(!1),r=e.input&&typeof e.input==`object`?Object.keys(e.input).length:0;return(0,K.jsxs)(`div`,{className:`tool-block`,style:{margin:`4px 0`},children:[(0,K.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,K.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,K.jsxs)(`span`,{className:`tb-name`,children:[`⚙ `,e.name||`tool_use`]}),!t&&r>0&&(0,K.jsxs)(`span`,{className:`tb-desc`,children:[`(`,r,` args)`]}),e.id&&(0,K.jsx)(`span`,{style:{marginLeft:`auto`,opacity:.45,fontSize:`11px`,fontFamily:`var(--mono)`},children:e.id})]}),t&&(0,K.jsx)(`div`,{className:`tool-block-body open`,children:(0,K.jsx)(Q,{data:e.input})})]})}function X({text:e,mode:t,isStreaming:n,sans:r,compact:i,className:a}){return e?(0,K.jsxs)(`div`,{className:`text-pane${a?` `+a:``}`,children:[(0,K.jsx)(`pre`,{className:`text-raw${r?` sans`:``}`,style:{display:t===`raw`?void 0:`none`},children:e}),(0,K.jsx)(`div`,{style:{display:t===`markdown`?void 0:`none`},children:i?(0,K.jsx)(`div`,{className:`text-raw sans`,style:{whiteSpace:`pre-wrap`},children:e}):(0,K.jsx)(me,{text:e,isStreaming:n})})]}):null}function Ce({text:e}){let[t,n]=(0,V.useState)(`raw`);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginBottom:`6px`},children:[(0,K.jsx)(`button`,{className:`text-toggle-btn${t===`raw`?` active`:``}`,onClick:()=>n(`raw`),children:`原文`}),(0,K.jsx)(`button`,{className:`text-toggle-btn${t===`markdown`?` active`:``}`,onClick:()=>n(`markdown`),children:`渲染`})]}),(0,K.jsx)(X,{text:e,mode:t,sans:!0})]})}function we({text:e,mode:t}){return e?(0,K.jsx)(X,{text:e,mode:t}):null}function Te({content:e}){let[t,n]=(0,V.useState)(!1),[r,i]=(0,V.useState)(`raw`),a=e.slice(0,80).replace(/\n/g,` `);return(0,K.jsxs)(`div`,{className:`thinking-block content-block`,children:[(0,K.jsxs)(`div`,{className:`thinking-block-header`,onClick:()=>n(e=>!e),children:[(0,K.jsxs)(`span`,{className:`thinking-label`,children:[(0,K.jsx)(`span`,{className:`thinking-arrow`,children:t?`▼`:`▶`}),(0,K.jsx)(`span`,{children:`Thinking`})]}),t?(0,K.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginTop:0,marginLeft:`4px`},onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`text-toggle-btn${r===`raw`?` active`:``}`,onClick:()=>i(`raw`),children:`原文`}),(0,K.jsx)(`button`,{className:`text-toggle-btn${r===`markdown`?` active`:``}`,onClick:()=>i(`markdown`),children:`渲染`})]}):(0,K.jsxs)(`span`,{className:`thinking-preview`,children:[a,`…`]}),(0,K.jsx)(Z,{getText:()=>e,stopPropagation:!0,className:`copy-btn`})]}),t&&(0,K.jsx)(X,{text:e,mode:r,sans:!0})]})}function Ee({content:e}){let[t,n]=(0,V.useState)(!1),[r,i]=(0,V.useState)(`raw`),a=e.slice(0,80).replace(/\n/g,` `);return(0,K.jsxs)(`div`,{className:`thinking-block content-block`,style:{marginBottom:`8px`},children:[(0,K.jsxs)(`div`,{className:`thinking-block-header`,onClick:()=>n(e=>!e),children:[(0,K.jsxs)(`span`,{className:`thinking-label`,children:[(0,K.jsx)(`span`,{className:`thinking-arrow`,children:t?`▼`:`▶`}),(0,K.jsx)(`span`,{children:`Thinking`})]}),t?(0,K.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginTop:0,marginLeft:`4px`},onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`text-toggle-btn${r===`raw`?` active`:``}`,onClick:()=>i(`raw`),children:`原文`}),(0,K.jsx)(`button`,{className:`text-toggle-btn${r===`markdown`?` active`:``}`,onClick:()=>i(`markdown`),children:`渲染`})]}):(0,K.jsxs)(`span`,{className:`thinking-preview`,children:[a,`…`]}),(0,K.jsx)(Z,{getText:()=>e,stopPropagation:!0,className:`copy-btn`})]}),t&&(0,K.jsx)(X,{text:e,mode:r,sans:!0})]})}function De({toolCall:e}){let[t,n]=(0,V.useState)(!1),r=typeof e.arguments==`object`?Object.keys(e.arguments||{}).length:0;return(0,K.jsxs)(`div`,{className:`tool-block`,children:[(0,K.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,K.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,K.jsx)(`span`,{className:`tb-name`,children:e.name}),!t&&r>0&&(0,K.jsxs)(`span`,{className:`tb-desc`,children:[`(`,r,` args)`]})]}),t&&(0,K.jsxs)(`div`,{className:`tool-block-body open`,children:[(0,K.jsx)(Q,{data:e.arguments}),e.result!==void 0&&(0,K.jsxs)(`div`,{style:{marginTop:`10px`,paddingTop:`10px`,borderTop:`1px solid var(--border-light)`},children:[(0,K.jsx)(`div`,{style:{fontSize:`11px`,fontWeight:600,color:`var(--orange)`,marginBottom:`6px`,textTransform:`uppercase`},children:`Result`}),(0,K.jsx)(Q,{data:e.result})]})]})]})}function Oe({tools:e}){return(0,K.jsx)(`div`,{style:{display:`grid`,gap:`4px`},children:e.map((e,t)=>(0,K.jsx)(ke,{tool:e},t))})}function ke({tool:e}){let[t,n]=(0,V.useState)(!1),r=e.function||e,i=r.name||e.name||`unknown`,a=r.description||e.description||``,o=r.parameters||e.input_schema||e.parameters,s=o?.required||[],c=o?.properties||{};return(0,K.jsxs)(`div`,{className:`tool-block`,children:[(0,K.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,K.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,K.jsx)(`span`,{className:`tb-name`,children:i}),(0,K.jsx)(`span`,{className:`tb-desc`,children:a})]}),t&&(0,K.jsxs)(`div`,{className:`tool-block-body open`,children:[a&&(0,K.jsx)(`div`,{className:`tb-full-desc`,children:a}),Object.keys(c).length>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`tb-params-title`,children:`Parameters`}),Object.entries(c).map(([e,t])=>(0,K.jsxs)(`div`,{className:`tb-param`,children:[(0,K.jsxs)(`div`,{className:`tb-param-row1`,children:[(0,K.jsx)(`span`,{className:`tb-pname`,children:e}),t.type&&(0,K.jsx)(`span`,{className:`tb-ptype`,children:t.type}),s.includes(e)&&(0,K.jsx)(`span`,{className:`tb-prequired`,children:`required`})]}),t.description&&(0,K.jsx)(`div`,{className:`tb-pdesc`,children:t.description})]},e))]}):o?(0,K.jsx)(Q,{data:o}):null]})]})}function Z({getText:e,className:n=`copy-btn`,stopPropagation:i=!1}){let[a,o]=(0,V.useState)(!1);return(0,K.jsx)(`button`,{className:`${n}${a?` copied`:``}`,onClick:async t=>{i&&t.stopPropagation();try{await navigator.clipboard.writeText(e()),o(!0),setTimeout(()=>o(!1),1500)}catch{}},"data-tip":`复制`,children:a?(0,K.jsx)(r,{size:10}):(0,K.jsx)(t,{size:10})})}var Ae=0;function Q({data:e}){return Ae=0,(0,K.jsx)(`div`,{className:`json-view`,children:$(e,0)})}var je=new Set([`chunks`,`headers`,`tools`]);function $(e,t,n){if(t>50)return(0,K.jsx)(`span`,{className:`json-punct`,children:`…`});if(e===null)return(0,K.jsx)(`span`,{className:`jnull`,children:`null`});if(e===void 0)return(0,K.jsx)(`span`,{className:`jnull`,children:`undefined`});if(typeof e==`boolean`)return(0,K.jsx)(`span`,{className:`jb`,children:String(e)});if(typeof e==`number`)return(0,K.jsx)(`span`,{className:`jn`,children:e});if(typeof e==`string`)return(0,K.jsxs)(`span`,{className:`js`,children:[`"`,e.length>300?e.slice(0,300)+`…`:e,`"`]});if(typeof e!=`object`)return(0,K.jsx)(`span`,{children:String(e)});let r=Array.isArray(e),i=r?e.map((e,t)=>[t,e]):Object.entries(e),a=i.length;if(a===0)return(0,K.jsx)(`span`,{className:`json-punct`,children:r?`[]`:`{}`});if(a<=3&&t<2&&i.every(([,e])=>typeof e!=`object`||!e)){let e=i.map(([e,n],i)=>(0,K.jsxs)(`span`,{children:[!r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`jk`,children:[`"`,String(e),`"`]}),(0,K.jsx)(`span`,{className:`json-punct`,children:`: `})]}),$(n,t+1),i<a-1&&(0,K.jsx)(`span`,{className:`json-punct`,children:`, `})]},String(e)));return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`json-punct`,children:r?`[`:`{`}),e,(0,K.jsx)(`span`,{className:`json-punct`,children:r?`]`:`}`})]})}let o=`jt`+ Ae++,s=`${a} ${r?`item`:`key`}${a===1?``:`s`}`,c=n!==void 0&&je.has(n),l=i.map(([e,n])=>(0,K.jsxs)(`div`,{className:`jt-line`,children:[!r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`jk`,children:[`"`,String(e),`"`]}),(0,K.jsx)(`span`,{className:`json-punct`,children:`: `})]}),$(n,t+1,String(e))]},String(e)));return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`jt-toggle${c?``:` jt-open`}`,onClick:e=>Me(e,o),style:{cursor:`pointer`},children:c?`▶`:`▼`}),(0,K.jsx)(`span`,{className:`json-punct`,children:r?`[`:`{`}),(0,K.jsxs)(`span`,{className:`jt-summary${c?` jt-show`:``}`,id:`${o}s`,children:[`… `,s]}),(0,K.jsx)(`div`,{className:`jt-children${c?``:` jt-open`}`,id:o,children:l}),(0,K.jsx)(`div`,{className:`jt-close${c?` jt-hidden`:``}`,id:`${o}c`,children:(0,K.jsx)(`span`,{className:`json-punct`,children:r?`]`:`}`})})]})}function Me(e,t){e.stopPropagation();let n=document.getElementById(t),r=document.getElementById(t+`s`),i=document.getElementById(t+`c`),a=e.currentTarget;n&&(n.classList.contains(`jt-open`)?(n.classList.remove(`jt-open`),a.classList.remove(`jt-open`),a.textContent=`▶`,r?.classList.add(`jt-show`),i?.classList.add(`jt-hidden`)):(n.classList.add(`jt-open`),a.classList.add(`jt-open`),a.textContent=`▼`,r?.classList.remove(`jt-show`),i?.classList.remove(`jt-hidden`)))}function Ne(e){let t=e.request.body,n=[];if(typeof t.system==`string`&&t.system.trim())n.push(t.system);else if(Array.isArray(t.system)){let e=t.system.map(e=>typeof e==`string`?e:e?.type===`text`&&e.text||``).filter(Boolean).join(`
16
+
17
+ `);e.trim()&&n.push(e)}let r=e.request.body.messages||[];for(let e of r)if(e.role===`system`||e.role===`developer`){let t=typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.map(e=>e.text||``).filter(Boolean).join(`
18
+
19
+ `):``;t.trim()&&n.push(t)}return n.length?n.join(`
20
+
21
+ `):null}function Pe(e){let t=e.response.body;if(!t)return null;if(t.choices&&Array.isArray(t.choices)&&t.choices.length>0){let e=t.choices[0].message;if(e){let t=e.content,n=e.reasoning_content,r=e.tool_calls,i=[];if(n&&i.push({type:`thinking`,thinking:n}),typeof t==`string`&&t.trim()?i.push({type:`text`,text:t}):Array.isArray(t)?i.push(...t):t!=null&&i.push({type:`text`,text:JSON.stringify(t)}),r&&r.length>0)for(let e of r){let t=e.function.arguments;try{t=JSON.parse(e.function.arguments)}catch{}i.push({type:`tool_use`,id:e.id,name:e.function.name,input:t})}if(i.length===1&&i[0].type===`text`)return i[0].text||null;if(i.length>0)return i}return null}if(t.content&&Array.isArray(t.content)){let e=t.content;return e.length===1&&e[0].type===`text`?e[0].text||null:e}return typeof t.text==`string`?t.text:null}function Fe({onClose:e}){let[t,n]=(0,V.useState)([]),[r,i]=(0,V.useState)(!0),[a,o]=(0,V.useState)(null);(0,V.useEffect)(()=>{Promise.all([G.getProviders().then(n).catch(()=>{}),G.getConfig().then(e=>o(e.proxy?.port??null)).catch(()=>{})]).finally(()=>i(!1))},[]);let s=a??(window.location.port?Number(window.location.port):void 0);return(0,K.jsxs)(`div`,{className:`p-5 space-y-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-base font-semibold`,children:`设置`}),(0,K.jsx)(`button`,{onClick:e,style:{color:`var(--text-tertiary)`},children:(0,K.jsx)(v,{size:16})})]}),(0,K.jsxs)(`div`,{className:`rounded-lg p-3`,style:{background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`代理服务器`}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-1.5 text-xs`,children:[(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`监听端口`}),(0,K.jsx)(`span`,{className:`font-mono`,style:{color:`var(--blue)`},children:s}),(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`OpenAI Base URL`}),(0,K.jsxs)(`span`,{className:`font-mono`,style:{color:`var(--blue)`},children:[`http://localhost:`,s,`/v1`]}),(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`Anthropic Base URL`}),(0,K.jsxs)(`span`,{className:`font-mono`,style:{color:`var(--blue)`},children:[`http://localhost:`,s]})]})]}),(0,K.jsxs)(`div`,{className:`rounded-lg p-3`,style:{background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium mb-1`,children:`上游服务商`}),(0,K.jsxs)(`p`,{className:`text-[11px] mb-3`,style:{color:`var(--text-tertiary)`},children:[`修改请编辑项目根目录的 `,(0,K.jsx)(`code`,{className:`font-mono px-1 py-0.5 rounded`,style:{background:`var(--bg-code)`},children:`.env`}),` 文件后重启服务`]}),r?(0,K.jsx)(`div`,{className:`text-sm`,style:{color:`var(--text-tertiary)`},children:`加载中…`}):t.length===0?(0,K.jsxs)(`div`,{className:`text-sm italic`,style:{color:`var(--text-tertiary)`},children:[`未检测到已配置的 Provider。请在 `,(0,K.jsx)(`code`,{className:`font-mono`,children:`.env`}),` 中设置 `,(0,K.jsx)(`code`,{className:`font-mono`,children:`OPENAI_API_KEY`}),` 等变量。`]}):(0,K.jsx)(`div`,{className:`space-y-1.5`,children:t.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded`,style:{border:`1px solid var(--border)`},children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full flex-shrink-0`,style:{background:`var(--green)`}}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium capitalize`,children:e.type}),(0,K.jsx)(`div`,{className:`text-[11px] font-mono truncate`,style:{color:`var(--text-tertiary)`},children:e.baseUrl})]}),e.apiKey&&(0,K.jsx)(`span`,{className:`text-[11px] font-mono flex-shrink-0`,style:{color:`var(--text-tertiary)`},children:e.apiKey})]},e.type))})]})]})}function Ie({open:e,title:t,message:n,confirmText:r=`确认`,cancelText:i=`取消`,danger:a=!1,onConfirm:o,onCancel:s}){let c=(0,V.useRef)(null);return(0,V.useEffect)(()=>{e&&c.current?.focus()},[e]),(0,V.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&s(),e.key===`Enter`&&o()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,o,s]),e?(0,K.jsx)(`div`,{className:`confirm-overlay`,onClick:s,children:(0,K.jsxs)(`div`,{className:`confirm-dialog`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`confirm-icon-row`,children:(0,K.jsx)(`span`,{className:`confirm-icon${a?` danger`:``}`,children:(0,K.jsx)(m,{size:20})})}),(0,K.jsx)(`div`,{className:`confirm-title`,children:t}),(0,K.jsx)(`div`,{className:`confirm-message`,children:n}),(0,K.jsxs)(`div`,{className:`confirm-actions`,children:[(0,K.jsx)(`button`,{className:`confirm-btn cancel`,onClick:s,children:i}),(0,K.jsx)(`button`,{ref:c,className:`confirm-btn ok${a?` danger`:``}`,onClick:o,children:r})]})]})}):null}function Le(){try{let e=localStorage.getItem(`lpt-theme`);if(e===`dark`||e===`light`)return e}catch{}return window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function Re(e){document.documentElement.setAttribute(`data-theme`,e);try{localStorage.setItem(`lpt-theme`,e)}catch{}}function ze(){let[e,t]=(0,V.useState)([]),[r,i]=(0,V.useState)(null),[a,c]=(0,V.useState)(null),[u,d]=(0,V.useState)(``),[f,m]=(0,V.useState)(`all`),[h,g]=(0,V.useState)(!1),[_,y]=(0,V.useState)({open:!1,title:``,message:``,onConfirm:()=>{}}),b=(e,t,n)=>{y({open:!0,title:e,message:t,onConfirm:n})},x=()=>y(e=>({...e,open:!1})),[ee,te]=(0,V.useState)(!0),[S,ne]=(0,V.useState)(Le),[C,w]=(0,V.useState)(320),T=(0,V.useRef)(!1),E=(0,V.useRef)(0),D=(0,V.useRef)(0),[O,k]=(0,V.useState)(!1),A=(0,V.useRef)(null),[j,M]=(0,V.useState)(!1);(0,V.useEffect)(()=>{Re(S)},[S]),(0,V.useEffect)(()=>{if(!O)return;let e=e=>{A.current&&!A.current.contains(e.target)&&k(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[O]);let oe=()=>ne(e=>e===`light`?`dark`:`light`),N=e.find(e=>e.id===a)||null,P=(0,V.useCallback)(async()=>{try{let[e,n]=await Promise.all([G.getTraces({keyword:u||void 0,limit:200}),G.getStats()]);t(e.traces),i(n)}catch{}finally{te(!1)}},[u]),F=(0,V.useCallback)(e=>{if(e.type===`trace:new`){let n=e.data;u||t(e=>[n,...e]),i(e=>e&&{...e,totalCalls:e.totalCalls+1})}else if(e.type===`trace:update`||e.type===`trace:complete`){let n=e.data;t(e=>e.map(e=>e.id===n.id?{...e,...n}:e)),e.type===`trace:complete`&&G.getStats().then(i).catch(()=>{})}},[u]),{connected:I}=le({url:`ws://${window.location.host}/ws`,onEvent:F});(0,V.useEffect)(()=>{P()},[P]);let L=e=>{T.current=!0,E.current=e.clientX,D.current=C,document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let t=e=>{if(!T.current)return;let t=e.clientX-E.current;w(Math.max(240,Math.min(600,D.current+t)))},n=()=>{T.current=!1,document.body.style.userSelect=``,document.body.style.cursor=``,document.removeEventListener(`mousemove`,t),document.removeEventListener(`mouseup`,n)};document.addEventListener(`mousemove`,t),document.addEventListener(`mouseup`,n)},se=r?.totalTokens??0,ce=r?.totalCalls??0,R=r?.avgDuration??0,z=e.reduce((e,t)=>e+(t.usage?.promptTokens||0),0),B=e.reduce((e,t)=>e+(t.usage?.completionTokens||0),0),H=f===`all`?e:e.filter(e=>e.status===f),U={};for(let t of e)t.model&&(U[t.model]=(U[t.model]||0)+1);let W=Object.entries(U).sort((e,t)=>t[1]-e[1]).slice(0,4),[J,de]=(0,V.useState)(null),fe=J?H.filter(e=>e.model===J):H,pe=e.filter(e=>e.status===`error`).length;return(0,K.jsxs)(`div`,{className:`flex flex-col h-screen overflow-hidden`,style:{background:`var(--bg)`,color:`var(--text)`},children:[(0,K.jsxs)(`header`,{className:`flex items-center gap-3 px-4 flex-shrink-0`,style:{background:`var(--bg-card)`,borderBottom:`1px solid var(--border)`,height:`52px`,zIndex:10},children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(n,{size:18,style:{color:`var(--blue)`}}),(0,K.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`LPT`})]}),(0,K.jsx)(`div`,{className:`w-px h-5 flex-shrink-0`,style:{background:`var(--border)`}}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] flex-shrink-0`,style:{color:`var(--text-tertiary)`},children:[(0,K.jsxs)(`span`,{children:[`请求 `,(0,K.jsx)(`b`,{className:`font-mono`,style:{color:`var(--text-secondary)`},children:ce})]}),(0,K.jsxs)(`span`,{children:[`Tokens `,(0,K.jsx)(`b`,{className:`font-mono`,style:{color:`var(--text-secondary)`},children:se.toLocaleString()})]}),z>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono`,style:{color:`var(--blue)`},children:[`↑`,(0,K.jsx)(`b`,{children:z.toLocaleString()})]}),B>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono`,style:{color:`var(--green)`},children:[`↓`,(0,K.jsx)(`b`,{children:B.toLocaleString()})]}),R>0&&(0,K.jsxs)(`span`,{children:[`均 `,R,`ms`]})]}),W.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-px h-5 flex-shrink-0`,style:{background:`var(--border)`}}),(0,K.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-hidden flex-1`,children:W.map(([e,t])=>(0,K.jsxs)(`button`,{onClick:()=>de(t=>t===e?null:e),className:`filter-chip${J===e?` active`:``}`,children:[e.split(`/`).pop()||e,(0,K.jsx)(`span`,{className:`chip-count`,children:t})]},e))})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] flex items-center gap-1`,style:{color:I?`var(--green)`:`var(--red)`},children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:I?`var(--green)`:`var(--red)`}}),I?`实时`:`离线`]}),(0,K.jsx)(q,{content:`从磁盘加载历史记录`,children:(0,K.jsxs)(`button`,{onClick:async()=>{M(!0),await G.reloadTraces().catch(()=>{}),await P(),M(!1)},className:`flex items-center gap-1 text-[11px] px-2 py-1 rounded border transition-colors`,style:{borderColor:`var(--border)`,color:j?`var(--blue)`:`var(--text-tertiary)`},disabled:j,children:[(0,K.jsx)(l,{size:12,style:{animation:j?`spin 1s linear infinite`:`none`}}),`加载记录`]})}),(0,K.jsxs)(`div`,{ref:A,className:`clear-split-btn`,style:{position:`relative`},children:[(0,K.jsx)(q,{content:`清空当前会话`,children:(0,K.jsxs)(`button`,{onClick:()=>{G.deleteTraces(!1).then(()=>{t([]),P()}),k(!1)},className:`clear-split-main`,children:[(0,K.jsx)(p,{size:12}),` 清空`]})}),(0,K.jsx)(`button`,{onClick:()=>k(e=>!e),className:`clear-split-arrow`,"aria-label":`更多清空选项`,children:(0,K.jsx)(o,{size:11})}),O&&(0,K.jsxs)(`div`,{className:`clear-dropdown`,children:[(0,K.jsx)(`div`,{className:`clear-dropdown-label`,children:`选择清空方式`}),(0,K.jsxs)(`button`,{className:`clear-dropdown-item`,onClick:()=>{G.deleteTraces(!1).then(()=>{t([]),P()}),k(!1)},children:[(0,K.jsx)(p,{size:12}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`clear-dropdown-item-title`,children:`清空当前会话`}),(0,K.jsx)(`div`,{className:`clear-dropdown-item-desc`,children:`仅清内存,文件保留,重启可恢复`})]})]}),(0,K.jsxs)(`button`,{className:`clear-dropdown-item danger`,onClick:()=>{k(!1),b(`永久删除所有文件`,`将永久删除所有 Trace 文件,无法恢复,确认吗?`,()=>{G.deleteTraces(!0).then(()=>{t([]),P()})})},children:[(0,K.jsx)(p,{size:12}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`clear-dropdown-item-title`,children:`永久删除所有文件`}),(0,K.jsx)(`div`,{className:`clear-dropdown-item-desc`,children:`删除磁盘 JSONL,重启不恢复`})]})]})]})]}),(0,K.jsx)(q,{content:S===`dark`?`浅色模式`:`深色模式`,children:(0,K.jsx)(`button`,{onClick:oe,className:`flex items-center justify-center w-7 h-7 rounded border transition-colors`,style:{borderColor:`var(--border)`,color:`var(--text-tertiary)`},children:S===`dark`?(0,K.jsx)(s,{size:13}):(0,K.jsx)(ie,{size:13})})}),(0,K.jsx)(q,{content:`Provider 与代理设置`,children:(0,K.jsxs)(`button`,{onClick:()=>g(!h),className:`flex items-center gap-1 text-[11px] px-2 py-1 rounded border transition-colors`,style:{borderColor:h?`var(--blue)`:`var(--border)`,color:h?`var(--blue)`:`var(--text-tertiary)`,background:h?`var(--blue-bg)`:`transparent`},children:[(0,K.jsx)(re,{size:12}),` 设置`]})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-1 overflow-hidden relative`,children:[h&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-20 flex`,style:{background:`rgba(0,0,0,0.15)`},onClick:()=>g(!1),children:(0,K.jsx)(`div`,{className:`ml-auto h-full overflow-auto`,style:{width:`420px`,background:`var(--bg-card)`,borderLeft:`1px solid var(--border)`},onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Fe,{onClose:()=>g(!1)})})}),(0,K.jsxs)(`div`,{className:`flex flex-col flex-shrink-0`,style:{width:`${C}px`,borderRight:`1px solid var(--border)`,background:`var(--bg-card)`},children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b flex-shrink-0`,style:{borderColor:`var(--border)`},children:[(0,K.jsx)(ae,{size:13,style:{color:`var(--text-tertiary)`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:`搜索消息、模型…`,value:u,onChange:e=>d(e.target.value),className:`flex-1 text-xs bg-transparent outline-none`,style:{color:`var(--text)`}}),u&&(0,K.jsx)(`button`,{onClick:()=>d(``),style:{color:`var(--text-tertiary)`},children:(0,K.jsx)(v,{size:11})}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[`all`,`error`].map(t=>(0,K.jsx)(q,{content:t===`all`?`显示全部请求`:`只看报错的请求`,placement:`bottom`,delay:400,children:(0,K.jsx)(`button`,{onClick:()=>m(t),className:`filter-chip${f===t?` active`:``}`,style:{fontSize:`10px`,padding:`2px 7px`},children:t===`all`?`全部 ${e.length}`:`✕ ${pe}`})},t))})]}),(0,K.jsx)(ue,{traces:fe,activeId:a,onSelect:e=>{c(e)},loading:ee,onDeleteFile:n=>{b(`删除记录文件`,`删除 ${n}?此操作不可恢复。`,async()=>{await G.deleteTraceFile(n).catch(()=>{}),t(e=>e.filter(e=>e.sourceFile!==n)),a&&e.find(e=>e.id===a)?.sourceFile===n&&c(null)})}})]}),(0,K.jsx)(`div`,{className:`resize-handle`,onMouseDown:L,style:{background:`var(--border-light)`}}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto detail-scroll`,style:{background:`var(--bg)`},children:N?(0,K.jsx)(ge,{trace:N},N.id):(0,K.jsx)(Be,{hasTraces:e.length>0})})]}),(0,K.jsx)(Ie,{open:_.open,title:_.title,message:_.message,confirmText:`确认删除`,danger:!0,onConfirm:()=>{x(),_.onConfirm()},onCancel:x})]})}function Be({hasTraces:e}){let t=window.location.port,r=t?`http://localhost:${t}`:window.location.origin;return e?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm`,style:{color:`var(--text-tertiary)`},children:`选择左侧一条请求查看详情`}):(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-5`,style:{padding:`40px`},children:[(0,K.jsx)(n,{size:28,style:{color:`var(--border)`}}),(0,K.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,K.jsx)(`div`,{style:{fontSize:`15px`,fontWeight:600,color:`var(--text)`,marginBottom:`6px`},children:`等待第一条请求…`}),(0,K.jsx)(`div`,{style:{fontSize:`12px`,color:`var(--text-tertiary)`,lineHeight:1.7},children:`设置以下环境变量,所有兼容 OpenAI 接口的工具都会被自动拦截`})]}),(0,K.jsxs)(`div`,{style:{background:`var(--bg-code)`,border:`1px solid var(--border)`,borderRadius:`8px`,padding:`14px 18px`,fontFamily:`var(--mono)`,fontSize:`13px`,lineHeight:2,minWidth:`340px`},children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{style:{color:`var(--amber)`},children:`export `}),(0,K.jsx)(`span`,{style:{color:`var(--blue)`},children:`OPENAI_BASE_URL`}),(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`=`}),(0,K.jsxs)(`span`,{style:{color:`var(--green)`},children:[`"`,r,`/v1"`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{style:{color:`var(--amber)`},children:`export `}),(0,K.jsx)(`span`,{style:{color:`var(--blue)`},children:`OPENAI_API_KEY`}),(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`=`}),(0,K.jsx)(`span`,{style:{color:`var(--green)`},children:`"any-key"`}),(0,K.jsx)(`span`,{style:{color:`var(--text-tertiary)`,fontStyle:`italic`,fontSize:`11px`},children:` # 代理不验证 key`})]})]}),(0,K.jsxs)(`div`,{style:{fontSize:`11px`,color:`var(--text-tertiary)`,lineHeight:1.7,textAlign:`center`,maxWidth:`320px`},children:[`上游 API 地址在 `,(0,K.jsx)(`span`,{style:{color:`var(--blue)`},children:`设置`}),` 中配置。 记录内容包括流式输出、工具调用与思考过程。`]})]})}H.createRoot(document.getElementById(`root`)).render((0,K.jsx)(V.StrictMode,{children:(0,K.jsx)(ze,{})}));
@@ -6,7 +6,7 @@
6
6
  <title>LLM Proxy Trace</title>
7
7
 
8
8
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2'><circle cx='12' cy='12' r='10'/><path d='M12 6v6l4 2'/></svg>" />
9
- <script type="module" crossorigin src="/assets/index-lc_TM1FG.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-DhD0ta31.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-QTnfLwEv.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/markdown-DsSlw-Z4.js">
12
12
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-BnH7jZBV.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llmpt",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "LLM Proxy Trace - local LLM proxy that captures full traces with real-time Web dashboard",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,21 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{C as t,D as n,E as r,O as i,S as a,T as o,_ as s,a as c,b as l,c as u,d,f,g as p,h as m,i as h,k as g,l as _,m as v,n as y,o as b,p as x,r as ee,s as te,t as S,u as ne,v as re,w as C,x as ie,y as ae}from"./react-vendor-BnH7jZBV.js";import{_ as w,a as T,b as E,c as D,d as O,f as k,g as A,h as j,i as M,l as oe,m as N,n as P,o as se,p as F,r as I,s as ce,t as le,u as L,v as R,y as z}from"./markdown-DsSlw-Z4.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var B=e(g(),1),V=e(i(),1),H=`/api`;async function U(e,t){let n=await fetch(`${H}${e}`,t);if(!n.ok)throw Error(`API error: ${n.status}`);return n.json()}var W={getTraces:e=>{let t=new URLSearchParams;e?.model&&t.set(`model`,e.model),e?.provider&&t.set(`provider`,e.provider),e?.status&&t.set(`status`,e.status),e?.keyword&&t.set(`keyword`,e.keyword),e?.limit&&t.set(`limit`,String(e.limit)),e?.offset&&t.set(`offset`,String(e.offset));let n=t.toString();return U(`/traces${n?`?`+n:``}`)},getTrace:e=>U(`/traces/${e}`),reloadTraces:()=>U(`/traces/reload`,{method:`POST`}),getTraceFiles:()=>U(`/traces/files`),deleteTraceFile:e=>U(`/traces/file/${encodeURIComponent(e)}`,{method:`DELETE`}),deleteTraces:(e=!1)=>U(`/traces${e?`?files=true`:``}`,{method:`DELETE`}),getProviders:()=>U(`/providers`),getStats:()=>U(`/stats`),getConfig:()=>U(`/config`)};function ue({url:e,onEvent:t,reconnectInterval:n=3e3}){let r=(0,B.useRef)(null),[i,a]=(0,B.useState)(!1),o=(0,B.useRef)(),s=(0,B.useRef)(t);s.current=t;let c=(0,B.useCallback)(()=>{try{let t=new WebSocket(e);t.onopen=()=>{a(!0),console.log(`[WS] Connected`)},t.onclose=()=>{a(!1),console.log(`[WS] Disconnected, reconnecting...`),o.current=setTimeout(c,n)},t.onerror=e=>{console.error(`[WS] Error:`,e),t.close()},t.onmessage=e=>{try{let t=JSON.parse(e.data);s.current?.(t)}catch{}},r.current=t}catch{o.current=setTimeout(c,n)}},[e,n]);return(0,B.useEffect)(()=>(c(),()=>{clearTimeout(o.current),r.current?.close()}),[c]),{connected:i,send:(0,B.useCallback)(e=>{r.current?.readyState===WebSocket.OPEN&&r.current.send(JSON.stringify(e))},[])}}var G=x();function K({content:e,children:t,placement:n=`top`,delay:r=300}){let[i,a]=(0,B.useState)(!1),{refs:o,floatingStyles:s,context:l}=h({open:i,onOpenChange:a,placement:n,whileElementsMounted:f,middleware:[ne(4),_({padding:8}),d({padding:8})]}),{getReferenceProps:p,getFloatingProps:m}=te([b(l,{move:!1,delay:{open:r,close:0}}),c(l),ee(l),u(l,{role:`tooltip`})]);return(0,G.jsxs)(G.Fragment,{children:[B.cloneElement(t,p({ref:o.setReference,...t.props})),i&&e!=null&&e!==``&&(0,G.jsx)(y,{children:(0,G.jsx)(`div`,{ref:o.setFloating,style:{...s,zIndex:9999,pointerEvents:`none`},...m(),children:(0,G.jsx)(`div`,{style:{background:`var(--bg-card)`,color:`var(--text-secondary)`,border:`1px solid var(--border)`,padding:`5px 9px`,borderRadius:`6px`,fontSize:`11.5px`,fontFamily:`var(--sans)`,fontWeight:400,lineHeight:1.5,letterSpacing:`0.01em`,maxWidth:`260px`,boxShadow:`var(--shadow-md)`},children:e})})})]})}function de({traces:e,activeId:t,onSelect:n,loading:r,onDeleteFile:i}){let[s,c]=(0,B.useState)(`time`),[l,u]=(0,B.useState)(new Set);if(r)return(0,G.jsxs)(`div`,{className:`flex items-center justify-center flex-1 gap-2 text-sm`,style:{color:`var(--text-tertiary)`},children:[(0,G.jsx)(a,{size:14,className:`animate-spin`}),` 加载中…`]});if(e.length===0)return(0,G.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-sm`,style:{color:`var(--text-tertiary)`},children:`暂无请求`});let d=[...e].sort((e,t)=>{if(s===`model`)return(e.model||``).localeCompare(t.model||``);if(s===`status`){let n=e=>e===`streaming`?0:e===`error`?1:e===`pending`?2:3;return n(e.status)-n(t.status)}return 0}),f=d.findIndex(e=>e.id===t),m=d.length>1&&f>=0?Math.round(f/(d.length-1)*100):0,h=[];if(s===`time`){let e=[];for(let t of d)t.sourceFile&&!e.includes(t.sourceFile)&&e.push(t.sourceFile);let t=d.map((e,t)=>({trace:e,globalIdx:t+1})).filter(e=>!e.trace.sourceFile);t.length>0&&h.push({key:`__session__`,label:`当前会话`,fileName:null,items:t});for(let t of e){let e=d.map((e,t)=>({trace:e,globalIdx:t+1})).filter(e=>e.trace.sourceFile===t);if(e.length>0){let n=t.match(/traces-(\d{4}-\d{2}-\d{2})T(\d{2}-\d{2}-\d{2})/),r=n?`${n[1]} ${n[2].replace(/-/g,`:`)}`:t.replace(`.jsonl`,``);h.push({key:t,label:r,fileName:t,items:e})}}}else h.push({key:`__all__`,label:``,fileName:null,items:d.map((e,t)=>({trace:e,globalIdx:t+1}))});let g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`flex flex-col flex-1 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b flex-shrink-0`,style:{borderColor:`var(--border-light)`},children:[(0,G.jsx)(`span`,{className:`text-[10px]`,style:{color:`var(--text-tertiary)`},children:`排序`}),(0,G.jsx)(`div`,{className:`sidebar-sort-segment`,children:[`time`,`model`,`status`].map(e=>(0,G.jsx)(K,{content:e===`time`?`按请求时间(最新在前)`:e===`model`?`按模型名称字母`:`按状态(接收中→错误→完成)`,placement:`bottom`,delay:400,children:(0,G.jsx)(`button`,{className:`sidebar-sort-btn${s===e?` active`:``}`,onClick:()=>c(e),children:e===`time`?`时间`:e===`model`?`模型`:`状态`})},e))}),f>=0&&(0,G.jsxs)(`span`,{className:`ml-auto text-[10px]`,style:{color:`var(--text-tertiary)`},children:[f+1,`/`,d.length]})]}),f>=0&&(0,G.jsx)(`div`,{style:{height:`2px`,background:`var(--border)`},children:(0,G.jsx)(`div`,{style:{width:`${m}%`,height:`100%`,background:`var(--blue)`,transition:`width .2s`}})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto sidebar-scroll`,children:h.map(e=>{let r=l.has(e.key),a=h.length>1,s=e.fileName!==null;return(0,G.jsxs)(B.Fragment,{children:[a&&(0,G.jsxs)(`div`,{className:`file-group-header${s?` history`:` session`}`,onClick:()=>g(e.key),children:[(0,G.jsx)(o,{size:12,className:`file-group-chevron flex-shrink-0`,style:{transform:r?`rotate(-90deg)`:`rotate(0deg)`}}),(0,G.jsx)(`span`,{className:`file-group-label`,children:e.label}),(0,G.jsx)(`span`,{className:`file-group-count`,children:e.items.length}),(()=>{let t=e.items.reduce((e,{trace:t})=>e+(t.usage?.promptTokens||0),0),n=e.items.reduce((e,{trace:t})=>e+(t.usage?.completionTokens||0),0),r=e.items.reduce((e,{trace:t})=>e+(t.usage?.reasoningTokens||0),0),i=e.items.reduce((e,{trace:t})=>e+(t.usage?.cacheReadTokens||0),0),a=e.items.reduce((e,{trace:t})=>e+(t.usage?.cacheWriteTokens||0),0),o=e.items.reduce((e,{trace:t})=>e+(t.usage?.cachedTokens||0),0),s=t+n;if(s===0)return null;let c=e=>e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e),l=e=>e.toLocaleString();return(0,G.jsx)(K,{content:(0,G.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`auto auto`,gap:`1px 10px`,fontSize:`11px`},children:[(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`输入`}),(0,G.jsx)(`span`,{style:{color:`var(--blue)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(t)}),(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`输出`}),(0,G.jsx)(`span`,{style:{color:`var(--green)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(n)}),r>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`推理`}),(0,G.jsx)(`span`,{style:{color:`var(--indigo)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(r)})]}),i+o>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`缓存命中`}),(0,G.jsx)(`span`,{style:{color:`var(--cyan)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(i+o)})]}),a>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`缓存写入`}),(0,G.jsx)(`span`,{style:{color:`var(--cyan)`,fontWeight:600,textAlign:`right`,fontFamily:`var(--mono)`},children:l(a)})]}),(0,G.jsx)(`span`,{style:{color:`var(--text-secondary)`,fontWeight:600,borderTop:`1px solid var(--border-light)`,paddingTop:`2px`,marginTop:`1px`},children:`合计`}),(0,G.jsx)(`span`,{style:{color:`var(--text)`,fontWeight:700,textAlign:`right`,fontFamily:`var(--mono)`,borderTop:`1px solid var(--border-light)`,paddingTop:`2px`,marginTop:`1px`},children:l(s)})]}),placement:`bottom`,delay:200,children:(0,G.jsx)(`span`,{className:`file-group-tokens`,onClick:e=>e.stopPropagation(),children:c(s)})})})(),e.fileName&&i&&(0,G.jsx)(K,{content:`删除:${e.fileName}`,placement:`bottom`,children:(0,G.jsx)(`button`,{className:`file-group-delete`,onClick:t=>{t.stopPropagation(),i(e.fileName)},children:(0,G.jsx)(p,{size:11})})})]}),!r&&e.items.map(({trace:e,globalIdx:r})=>(0,G.jsx)(fe,{trace:e,isActive:e.id===t,onClick:()=>n(e.id),turnNumber:r},e.id))]},e.key)})})]})}function q(e){let t=(e||``).toLowerCase();return t.includes(`opus`)?{bg:`var(--purple-bg)`,fg:`var(--purple)`}:t.includes(`sonnet`)?{bg:`var(--blue-bg)`,fg:`var(--blue)`}:t.includes(`haiku`)||t.includes(`gpt-4`)?{bg:`var(--green-bg)`,fg:`var(--green)`}:t.includes(`gpt-3`)?{bg:`var(--amber-bg)`,fg:`var(--amber)`}:t.includes(`glm`)||t.includes(`zhipu`)||t.includes(`deepseek`)?{bg:`var(--blue-bg)`,fg:`var(--blue)`}:t.includes(`qwen`)?{bg:`var(--purple-bg)`,fg:`var(--purple)`}:t.includes(`llama`)?{bg:`var(--orange-bg)`,fg:`var(--orange)`}:t.includes(`mistral`)?{bg:`var(--amber-bg)`,fg:`var(--amber)`}:{bg:`var(--bg-code)`,fg:`var(--text-tertiary)`}}function fe({trace:e,isActive:t,onClick:n,turnNumber:r}){let i=new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),o=e.duration>0?e.duration>=1e3?`${(e.duration/1e3).toFixed(1)}s`:`${e.duration}ms`:e.status===`streaming`?`...`:`-`,s=e.usage?.promptTokens||0,c=e.usage?.completionTokens||0,l=e.usage?.totalTokens||0,u=pe(e),d=q(e.model),f=(e.model||`unknown`).split(`/`).pop()||`unknown`,p=e.status===`streaming`,m=e.status===`error`,h=e.status===`pending`,g=m?`var(--red)`:p?`var(--blue)`:e.status===`completed`?`var(--green)`:`var(--amber)`;return(0,G.jsxs)(`div`,{onClick:n,className:`sidebar-item px-3 py-2 cursor-pointer border-b transition-colors`,style:{background:t?`var(--bg-active)`:`transparent`,borderColor:`var(--border-light)`},children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-mono flex-shrink-0 text-center`,style:{color:`var(--text-tertiary)`,fontSize:`11px`,fontWeight:700,minWidth:`20px`},children:[`#`,r]}),u?(0,G.jsx)(`span`,{className:`text-xs truncate flex-1`,style:{color:`var(--text)`},children:u}):(0,G.jsx)(`span`,{className:`text-xs truncate flex-1`,style:{color:`var(--text-tertiary)`,fontStyle:`italic`},children:`No content`}),(0,G.jsx)(`span`,{className:`text-[10px] flex-shrink-0 font-mono`,style:{color:`var(--text-tertiary)`},children:i})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center flex-shrink-0`,style:{minWidth:`20px`},children:p?(0,G.jsx)(a,{size:12,className:`animate-spin`,style:{color:`var(--blue)`}}):m?(0,G.jsx)(v,{size:14,strokeWidth:2.8,style:{color:`var(--red)`}}):h?(0,G.jsx)(`span`,{className:`rounded-full`,style:{width:`9px`,height:`9px`,background:`var(--amber)`,display:`inline-block`}}):(0,G.jsx)(`span`,{className:`rounded-full`,style:{width:`9px`,height:`9px`,background:g,display:`inline-block`}})}),(0,G.jsx)(K,{content:e.model,placement:`right`,delay:500,children:(0,G.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full truncate max-w-[90px]`,style:{background:d.bg,color:d.fg,lineHeight:`1.3`},children:f})}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5 flex-shrink-0 font-mono`,style:{color:`var(--text-tertiary)`,fontSize:`10px`},children:[l>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{style:{color:`var(--blue)`,fontWeight:600},children:[`↑`,s]}),(0,G.jsxs)(`span`,{style:{color:`var(--green)`,fontWeight:600},children:[`↓`,c]})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(C,{size:9}),o]})]})]})]})}function pe(e){let t=e.request.body.messages;if(t){let e=[...t].reverse().find(e=>e.role===`user`);if(e)return(typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.filter(e=>typeof e==`object`&&e.type===`text`).map(e=>e.text||``).join(` `):``).replace(/\s+/g,` `).trim().slice(0,100)}return e.request.body.prompt?String(e.request.body.prompt).replace(/\s+/g,` `).trim().slice(0,100):``}R.registerLanguage(`javascript`,w),R.registerLanguage(`js`,w),R.registerLanguage(`jsx`,w),R.registerLanguage(`typescript`,A),R.registerLanguage(`ts`,A),R.registerLanguage(`tsx`,A),R.registerLanguage(`python`,j),R.registerLanguage(`py`,j),R.registerLanguage(`bash`,N),R.registerLanguage(`sh`,N),R.registerLanguage(`shell`,N),R.registerLanguage(`json`,F),R.registerLanguage(`css`,k),R.registerLanguage(`xml`,O),R.registerLanguage(`html`,O),R.registerLanguage(`markdown`,L),R.registerLanguage(`md`,L),R.registerLanguage(`sql`,oe),R.registerLanguage(`go`,D),R.registerLanguage(`rust`,ce),R.registerLanguage(`java`,se),R.registerLanguage(`cpp`,T),R.registerLanguage(`c`,T),R.registerLanguage(`csharp`,M),R.registerLanguage(`yaml`,I),R.registerLanguage(`yml`,I),R.registerLanguage(`diff`,P),R.registerLanguage(`plaintext`,le);function me({inline:e,className:n,children:i,node:a,...o}){let[s,c]=(0,B.useState)(!1),l=String(i??``).replace(/\n$/,``),u=/language-(\w+)/.exec(n??``)?.[1]??``,d=e??(!n?.startsWith(`language-`)&&!l.includes(`
2
- `)),f=(0,B.useCallback)(async()=>{try{await navigator.clipboard.writeText(l),c(!0),setTimeout(()=>c(!1),1500)}catch{}},[l]);if(d)return(0,G.jsx)(`code`,{className:n,...o,children:i});let p=``;try{p=u&&R.getLanguage(u)?R.highlight(l,{language:u,ignoreIllegals:!0}).value:R.highlightAuto(l).value}catch{p=l.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}return(0,G.jsxs)(`div`,{className:`md-code-wrapper`,children:[(0,G.jsxs)(`div`,{className:`md-code-header`,children:[u&&(0,G.jsx)(`span`,{className:`md-code-lang`,children:u}),(0,G.jsxs)(`button`,{className:`md-code-copy${s?` copied`:``}`,onClick:f,title:`复制代码`,children:[s?(0,G.jsx)(r,{size:11}):(0,G.jsx)(t,{size:11}),(0,G.jsx)(`span`,{children:s?`已复制`:`复制`})]})]}),(0,G.jsx)(`pre`,{className:`hljs md-code-pre`,children:(0,G.jsx)(`code`,{className:`hljs${u?` language-${u}`:``}`,dangerouslySetInnerHTML:{__html:z.sanitize(p)}})})]})}function he({text:e,isStreaming:t,className:n}){return e?(0,G.jsx)(`div`,{className:[`md-prose`,t?`streaming-cursor`:``,n??``].filter(Boolean).join(` `),children:(0,G.jsx)(S,{remarkPlugins:[E],components:{code:me,a:({href:e,children:t,...n})=>(0,G.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,...n,children:t})},children:e})}):null}var ge={};function _e({trace:e}){let t=e.response.status||0,n=t>=400||e.status===`error`,r=e.status===`streaming`,i=(0,B.useRef)(null);(0,B.useEffect)(()=>{r&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e.response,r]);let a=e.request.body.messages||[],o=Me(e),s=a.filter(e=>e.role!==`system`&&e.role!==`developer`),c=Ne(e),l=Array.isArray(c)?c.filter(e=>e.type===`thinking`).map(e=>e.thinking||``).join(`
3
-
4
- `):``,u=Array.isArray(c)?(()=>{let e=c.filter(e=>e.type!==`thinking`);return e.length===0?null:e.length===1&&e[0].type===`text`?e[0].text||null:e})():c,d=e.request.body.tools||[],f=e.toolCalls||[],p=e.usage;return(0,G.jsxs)(`div`,{ref:i,className:`detail-content`,children:[n&&(0,G.jsxs)(`div`,{className:`error-banner`,children:[(0,G.jsx)(`span`,{className:`eb-icon`,children:`⚠`}),(0,G.jsx)(`span`,{className:`eb-code`,children:t>=400?`HTTP ${t}`:e.error?.code||`Error`}),(0,G.jsx)(`span`,{className:`eb-sep`,children:`·`}),(0,G.jsx)(`span`,{className:`eb-message`,children:e.error?.message||`Unknown error`})]}),(0,G.jsx)(ve,{usage:p,duration:e.duration,ttfb:e.ttfb,isStreaming:r}),o&&(0,G.jsx)(Y,{title:`System Prompt`,defaultOpen:!1,copyText:o,badge:`system`,children:(0,G.jsx)(Se,{text:o})}),s.length>0&&(0,G.jsx)(Y,{title:`Messages`,defaultOpen:!0,badge:`${s.length}`,copyText:s.map(e=>{let t=typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.map(e=>e.text||e.thinking||``).join(`
5
- `):``;return`[${e.role.toUpperCase()}]\n${t}`}).join(`
6
-
7
- ---
8
-
9
- `),children:(0,G.jsx)(`div`,{className:`messages-list`,children:s.map((e,t)=>(0,G.jsx)(ye,{message:e},t))})}),(0,G.jsxs)(Y,{title:`Response`,defaultOpen:!0,badge:t?`${t}`:r?`live`:void 0,copyText:(u?typeof u==`string`?u:u.map(e=>e.text||``).join(`
10
-
11
- `):``)||void 0,children:[l&&(0,G.jsx)(Te,{content:l}),u?(0,G.jsx)(ye,{message:{role:`assistant`,content:u},isStreaming:r}):e.error?(0,G.jsxs)(`div`,{className:`msg system`,style:{marginBottom:0},children:[(0,G.jsx)(`span`,{className:`msg-role`,style:{background:`var(--red)`,color:`#fff`},children:`ERROR`}),(0,G.jsxs)(`div`,{className:`content-block`,children:[`[`,e.error.code,`] `,e.error.message]})]}):(0,G.jsx)(`div`,{style:{color:`var(--text-tertiary)`,fontSize:`13px`,padding:`4px 0`},children:r?(0,G.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:`8px`,color:`var(--text-tertiary)`,fontSize:`12px`},children:[`接收中 `,(0,G.jsxs)(`span`,{className:`streaming-dots`,children:[(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{})]})]}):`No response content`})]}),f.length>0&&(0,G.jsx)(Y,{title:`Tool Calls`,defaultOpen:!0,badge:`${f.length}`,copyText:f.map(e=>`${e.name}(${JSON.stringify(e.arguments,null,2)})`).join(`
12
-
13
- `),children:(0,G.jsx)(`div`,{style:{display:`grid`,gap:`4px`},children:f.map((e,t)=>(0,G.jsx)(Ee,{toolCall:e},t))})}),d.length>0&&(0,G.jsx)(Y,{title:`Tools Definition`,defaultOpen:!1,badge:`${d.length}`,copyText:JSON.stringify(d,null,2),children:(0,G.jsx)(De,{tools:d})}),(0,G.jsx)(Y,{title:`Raw JSON`,defaultOpen:!1,copyText:JSON.stringify(e,null,2),children:(0,G.jsx)(Q,{data:e})})]})}function J(e){return e>=1e3?`${(e/1e3).toFixed(2)}s`:`${e}ms`}function ve({usage:e,duration:t,ttfb:n,isStreaming:r}){let i=(e?.cachedTokens||0)+(e?.cacheReadTokens||0)+(e?.cacheWriteTokens||0)>0;return(0,G.jsx)(`div`,{className:`token-usage-bar`,children:(0,G.jsx)(`div`,{className:`token-bar`,children:r?(0,G.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:`6px`,fontSize:`11px`,color:`var(--text-tertiary)`},children:[`接收中 `,(0,G.jsxs)(`span`,{className:`streaming-dots`,children:[(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{})]})]}):e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`tok-group`,children:(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-label`,children:`合计`}),(0,G.jsx)(`span`,{className:`tok-val`,style:{color:`var(--text)`,fontSize:`12px`},children:e.totalTokens.toLocaleString()})]})}),(0,G.jsxs)(`span`,{className:`tok-group`,children:[(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-arrow`,style:{color:`var(--blue)`},children:`↑`}),(0,G.jsx)(`span`,{className:`tok-val`,children:e.promptTokens.toLocaleString()})]}),(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-arrow`,style:{color:`var(--green)`},children:`↓`}),(0,G.jsx)(`span`,{className:`tok-val`,children:e.completionTokens.toLocaleString()})]}),(e.reasoningTokens||0)>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--indigo)`}}),(0,G.jsx)(`span`,{className:`tok-label`,children:`推理`}),(0,G.jsx)(`span`,{className:`tok-val`,children:e.reasoningTokens.toLocaleString()})]})]}),i&&(0,G.jsxs)(`span`,{className:`tok-group`,children:[(e.cachedTokens||0)>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--cyan)`}}),(0,G.jsx)(`span`,{className:`tok-label`,children:`缓存命中`}),(0,G.jsx)(`span`,{className:`tok-val`,children:e.cachedTokens.toLocaleString()})]}),(e.cacheReadTokens||0)>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--cyan)`}}),(0,G.jsx)(`span`,{className:`tok-label`,children:`缓存读`}),(0,G.jsx)(`span`,{className:`tok-val`,children:e.cacheReadTokens.toLocaleString()})]}),(e.cacheWriteTokens||0)>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-dot`,style:{background:`var(--amber)`}}),(0,G.jsx)(`span`,{className:`tok-label`,children:`缓存写`}),(0,G.jsx)(`span`,{className:`tok-val`,children:e.cacheWriteTokens.toLocaleString()})]})]}),(0,G.jsxs)(`span`,{className:`tok-group`,children:[n>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-label`,children:`首字`}),(0,G.jsx)(`span`,{className:`tok-val`,children:J(n)})]}),t>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-label`,children:`耗时`}),(0,G.jsx)(`span`,{className:`tok-val`,children:J(t)})]}),t>0&&(e.completionTokens||0)>0&&(0,G.jsxs)(`span`,{className:`tok-item`,children:[(0,G.jsx)(`span`,{className:`tok-label`,children:`速度`}),(0,G.jsxs)(`span`,{className:`tok-val`,children:[Math.round(e.completionTokens/(t/1e3)),` tok/s`]})]})]})]}):(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`,fontSize:`11px`},children:`无 token 数据`})})})}function Y({title:e,defaultOpen:t,badge:n,copyText:r,children:i}){let[a,o]=(0,B.useState)(ge[e]??t);return(0,G.jsxs)(`div`,{className:`section`,children:[(0,G.jsxs)(`div`,{className:`section-header`,onClick:()=>{let t=!a;o(t),ge[e]=t},children:[(0,G.jsx)(`span`,{className:`chevron${a?` open`:``}`,children:`▶`}),(0,G.jsx)(`span`,{className:`title`,children:e}),n&&(0,G.jsx)(`span`,{className:`badge`,children:n}),r!==void 0&&r!==``&&(0,G.jsx)(Z,{getText:()=>r,className:`copy-btn`,stopPropagation:!0})]}),a&&(0,G.jsx)(`div`,{className:`section-body open`,children:i})]})}function ye({message:e,isStreaming:t}){let n=e.role,r=e.content,i=n===`assistant`,a=typeof r==`string`,[o,s]=(0,B.useState)(i?`markdown`:`raw`),c=()=>typeof r==`string`?r:Array.isArray(r)?r.map(e=>e.text||e.thinking||``).filter(Boolean).join(`
14
-
15
- `):``,l=n===`user`?`user`:n===`assistant`?`assistant`:n===`system`||n===`developer`?`system`:n===`tool`?`tool_result`:``,u=e.tool_calls;e.tool_call_id;let d=a?r.trim().length>0:Array.isArray(r)&&r.length>0,f=a&&r.trim().length>0,[p,m]=(0,B.useState)(n===`tool`);return(0,G.jsxs)(`div`,{className:`msg ${l}`,children:[(0,G.jsxs)(`div`,{className:`msg-header-row`,children:[(0,G.jsxs)(`span`,{className:`msg-role msg-role-toggle`,onClick:()=>m(e=>!e),title:p?`展开`:`收起`,children:[(0,G.jsx)(`span`,{className:`msg-collapse-arrow${p?``:` open`}`,children:`▶`}),n.toUpperCase()]}),f&&(0,G.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginLeft:`8px`,marginTop:0,display:p?`none`:void 0},children:[(0,G.jsx)(`button`,{className:`text-toggle-btn${o===`raw`?` active`:``}`,onClick:()=>s(`raw`),children:`原文`}),(0,G.jsx)(`button`,{className:`text-toggle-btn${o===`markdown`?` active`:``}`,onClick:()=>s(`markdown`),children:`渲染`})]}),(0,G.jsx)(`span`,{style:{marginLeft:`auto`},children:(0,G.jsx)(Z,{getText:c})})]}),!p&&(0,G.jsxs)(G.Fragment,{children:[a?(0,G.jsx)(Ce,{text:r,mode:o}):Array.isArray(r)?(0,G.jsx)(`div`,{children:r.map((e,n)=>(0,G.jsx)(xe,{block:e,isStreaming:t&&n===r.length-1},n))}):r?(0,G.jsx)(Q,{data:r}):null,u&&u.length>0&&(0,G.jsx)(`div`,{className:`msg-tool-calls`,children:u.map(e=>(0,G.jsx)(be,{toolCall:e},e.id))})]}),p&&(d||u&&u.length>0)&&(0,G.jsx)(`div`,{className:`msg-collapsed-hint`,children:[d?a?`${r.slice(0,60).replace(/\n/g,` `)}…`:`${r.length} 块`:``,u?.length?`${u.length} tool_call`:``].filter(Boolean).join(` · `)})]})}function be({toolCall:e}){let[t,n]=(0,B.useState)(!1),r=e.function.arguments;try{r=JSON.parse(e.function.arguments)}catch{}let i=typeof r==`object`&&r?Object.keys(r).length:0;return(0,G.jsxs)(`div`,{className:`tool-block`,children:[(0,G.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,G.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,G.jsx)(`span`,{className:`tb-name`,children:e.function.name}),!t&&i>0&&(0,G.jsxs)(`span`,{className:`tb-desc`,children:[`(`,i,` args)`]})]}),t&&(0,G.jsx)(`div`,{className:`tool-block-body open`,children:typeof r==`object`?(0,G.jsx)(Q,{data:r}):(0,G.jsx)(`pre`,{className:`text-raw`,children:String(r)})})]})}function xe({block:e,isStreaming:t}){let[n,r]=(0,B.useState)(`markdown`);if(e.type===`text`||e.type===`input_text`||e.type===`output_text`){let i=e.text||``;return(0,G.jsxs)(`div`,{className:`content-block`,children:[(0,G.jsx)(`div`,{className:`msg-header-row`,style:{marginBottom:`4px`},children:(0,G.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginTop:0},children:[(0,G.jsx)(`button`,{className:`text-toggle-btn${n===`raw`?` active`:``}`,onClick:()=>r(`raw`),children:`原文`}),(0,G.jsx)(`button`,{className:`text-toggle-btn${n===`markdown`?` active`:``}`,onClick:()=>r(`markdown`),children:`渲染`})]})}),(0,G.jsx)(X,{text:i,mode:n,isStreaming:t})]})}return e.type===`thinking`?(0,G.jsx)(we,{content:e.thinking||``}):e.type===`tool_use`?(0,G.jsxs)(`div`,{className:`content-block block-framed`,children:[(0,G.jsxs)(`span`,{className:`tool-use-label`,children:[`⚙ `,e.name||`tool_use`]}),(0,G.jsx)(Q,{data:e.input})]}):e.type===`tool_result`?(0,G.jsxs)(`div`,{className:`content-block block-framed`,style:{borderColor:`var(--purple)`,background:`var(--purple-bg)`},children:[(0,G.jsxs)(`span`,{className:`tool-use-label`,style:{color:`var(--purple)`,background:`color-mix(in srgb, var(--purple) 15%, transparent)`},children:[`↩ tool_result: `,e.tool_use_id||``]}),(0,G.jsx)(`div`,{className:`content-block-text`,children:typeof e.text==`string`?e.text:(0,G.jsx)(Q,{data:e.text})})]}):(0,G.jsx)(Q,{data:e})}function X({text:e,mode:t,isStreaming:n,sans:r,compact:i,className:a}){return e?(0,G.jsxs)(`div`,{className:`text-pane${a?` `+a:``}`,children:[(0,G.jsx)(`pre`,{className:`text-raw${r?` sans`:``}`,style:{display:t===`raw`?void 0:`none`},children:e}),(0,G.jsx)(`div`,{style:{display:t===`markdown`?void 0:`none`},children:i?(0,G.jsx)(`div`,{className:`text-raw sans`,style:{whiteSpace:`pre-wrap`},children:e}):(0,G.jsx)(he,{text:e,isStreaming:n})})]}):null}function Se({text:e}){let[t,n]=(0,B.useState)(`raw`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginBottom:`6px`},children:[(0,G.jsx)(`button`,{className:`text-toggle-btn${t===`raw`?` active`:``}`,onClick:()=>n(`raw`),children:`原文`}),(0,G.jsx)(`button`,{className:`text-toggle-btn${t===`markdown`?` active`:``}`,onClick:()=>n(`markdown`),children:`渲染`})]}),(0,G.jsx)(X,{text:e,mode:t})]})}function Ce({text:e,mode:t}){return e?(0,G.jsx)(X,{text:e,mode:t}):null}function we({content:e}){let[t,n]=(0,B.useState)(!1),[r,i]=(0,B.useState)(`raw`),a=e.slice(0,80).replace(/\n/g,` `);return(0,G.jsxs)(`div`,{className:`thinking-block content-block`,children:[(0,G.jsxs)(`div`,{className:`thinking-block-header`,onClick:()=>n(e=>!e),children:[(0,G.jsxs)(`span`,{className:`thinking-label`,children:[(0,G.jsx)(`span`,{className:`thinking-arrow`,children:t?`▼`:`▶`}),(0,G.jsx)(`span`,{children:`Thinking`})]}),t?(0,G.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginTop:0,marginLeft:`4px`},onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{className:`text-toggle-btn${r===`raw`?` active`:``}`,onClick:()=>i(`raw`),children:`原文`}),(0,G.jsx)(`button`,{className:`text-toggle-btn${r===`markdown`?` active`:``}`,onClick:()=>i(`markdown`),children:`渲染`})]}):(0,G.jsxs)(`span`,{className:`thinking-preview`,children:[a,`…`]}),(0,G.jsx)(Z,{getText:()=>e,stopPropagation:!0,className:`copy-btn`})]}),t&&(0,G.jsx)(X,{text:e,mode:r,compact:!0})]})}function Te({content:e}){let[t,n]=(0,B.useState)(!1),[r,i]=(0,B.useState)(`raw`),a=e.slice(0,80).replace(/\n/g,` `);return(0,G.jsxs)(`div`,{className:`thinking-block content-block`,style:{marginBottom:`8px`},children:[(0,G.jsxs)(`div`,{className:`thinking-block-header`,onClick:()=>n(e=>!e),children:[(0,G.jsxs)(`span`,{className:`thinking-label`,children:[(0,G.jsx)(`span`,{className:`thinking-arrow`,children:t?`▼`:`▶`}),(0,G.jsx)(`span`,{children:`Thinking`})]}),t?(0,G.jsxs)(`div`,{className:`text-toggle-bar`,style:{marginTop:0,marginLeft:`4px`},onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{className:`text-toggle-btn${r===`raw`?` active`:``}`,onClick:()=>i(`raw`),children:`原文`}),(0,G.jsx)(`button`,{className:`text-toggle-btn${r===`markdown`?` active`:``}`,onClick:()=>i(`markdown`),children:`渲染`})]}):(0,G.jsxs)(`span`,{className:`thinking-preview`,children:[a,`…`]}),(0,G.jsx)(Z,{getText:()=>e,stopPropagation:!0,className:`copy-btn`})]}),t&&(0,G.jsx)(X,{text:e,mode:r,compact:!0})]})}function Ee({toolCall:e}){let[t,n]=(0,B.useState)(!1),r=typeof e.arguments==`object`?Object.keys(e.arguments||{}).length:0;return(0,G.jsxs)(`div`,{className:`tool-block`,children:[(0,G.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,G.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,G.jsx)(`span`,{className:`tb-name`,children:e.name}),!t&&r>0&&(0,G.jsxs)(`span`,{className:`tb-desc`,children:[`(`,r,` args)`]})]}),t&&(0,G.jsxs)(`div`,{className:`tool-block-body open`,children:[(0,G.jsx)(Q,{data:e.arguments}),e.result!==void 0&&(0,G.jsxs)(`div`,{style:{marginTop:`10px`,paddingTop:`10px`,borderTop:`1px solid var(--border-light)`},children:[(0,G.jsx)(`div`,{style:{fontSize:`11px`,fontWeight:600,color:`var(--orange)`,marginBottom:`6px`,textTransform:`uppercase`},children:`Result`}),(0,G.jsx)(Q,{data:e.result})]})]})]})}function De({tools:e}){return(0,G.jsx)(`div`,{style:{display:`grid`,gap:`4px`},children:e.map((e,t)=>(0,G.jsx)(Oe,{tool:e},t))})}function Oe({tool:e}){let[t,n]=(0,B.useState)(!1),r=e.function||e,i=r.name||e.name||`unknown`,a=r.description||e.description||``,o=r.parameters||e.input_schema||e.parameters,s=o?.required||[],c=o?.properties||{};return(0,G.jsxs)(`div`,{className:`tool-block`,children:[(0,G.jsxs)(`div`,{className:`tool-block-header`,onClick:()=>n(e=>!e),children:[(0,G.jsx)(`span`,{className:`tb-arrow${t?` open`:``}`,children:`▶`}),(0,G.jsx)(`span`,{className:`tb-name`,children:i}),(0,G.jsx)(`span`,{className:`tb-desc`,children:a})]}),t&&(0,G.jsxs)(`div`,{className:`tool-block-body open`,children:[a&&(0,G.jsx)(`div`,{className:`tb-full-desc`,children:a}),Object.keys(c).length>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`tb-params-title`,children:`Parameters`}),Object.entries(c).map(([e,t])=>(0,G.jsxs)(`div`,{className:`tb-param`,children:[(0,G.jsxs)(`div`,{className:`tb-param-row1`,children:[(0,G.jsx)(`span`,{className:`tb-pname`,children:e}),t.type&&(0,G.jsx)(`span`,{className:`tb-ptype`,children:t.type}),s.includes(e)&&(0,G.jsx)(`span`,{className:`tb-prequired`,children:`required`})]}),t.description&&(0,G.jsx)(`div`,{className:`tb-pdesc`,children:t.description})]},e))]}):o?(0,G.jsx)(Q,{data:o}):null]})]})}function Z({getText:e,className:n=`copy-btn`,stopPropagation:i=!1}){let[a,o]=(0,B.useState)(!1);return(0,G.jsx)(`button`,{className:`${n}${a?` copied`:``}`,onClick:async t=>{i&&t.stopPropagation();try{await navigator.clipboard.writeText(e()),o(!0),setTimeout(()=>o(!1),1500)}catch{}},"data-tip":`复制`,children:a?(0,G.jsx)(r,{size:10}):(0,G.jsx)(t,{size:10})})}var ke=0;function Q({data:e}){return ke=0,(0,G.jsx)(`div`,{className:`json-view`,children:$(e,0)})}var Ae=new Set([`chunks`,`headers`,`tools`]);function $(e,t,n){if(t>50)return(0,G.jsx)(`span`,{className:`json-punct`,children:`…`});if(e===null)return(0,G.jsx)(`span`,{className:`jnull`,children:`null`});if(e===void 0)return(0,G.jsx)(`span`,{className:`jnull`,children:`undefined`});if(typeof e==`boolean`)return(0,G.jsx)(`span`,{className:`jb`,children:String(e)});if(typeof e==`number`)return(0,G.jsx)(`span`,{className:`jn`,children:e});if(typeof e==`string`)return(0,G.jsxs)(`span`,{className:`js`,children:[`"`,e.length>300?e.slice(0,300)+`…`:e,`"`]});if(typeof e!=`object`)return(0,G.jsx)(`span`,{children:String(e)});let r=Array.isArray(e),i=r?e.map((e,t)=>[t,e]):Object.entries(e),a=i.length;if(a===0)return(0,G.jsx)(`span`,{className:`json-punct`,children:r?`[]`:`{}`});if(a<=3&&t<2&&i.every(([,e])=>typeof e!=`object`||!e)){let e=i.map(([e,n],i)=>(0,G.jsxs)(`span`,{children:[!r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`jk`,children:[`"`,String(e),`"`]}),(0,G.jsx)(`span`,{className:`json-punct`,children:`: `})]}),$(n,t+1),i<a-1&&(0,G.jsx)(`span`,{className:`json-punct`,children:`, `})]},String(e)));return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`json-punct`,children:r?`[`:`{`}),e,(0,G.jsx)(`span`,{className:`json-punct`,children:r?`]`:`}`})]})}let o=`jt`+ ke++,s=`${a} ${r?`item`:`key`}${a===1?``:`s`}`,c=n!==void 0&&Ae.has(n),l=i.map(([e,n])=>(0,G.jsxs)(`div`,{className:`jt-line`,children:[!r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`jk`,children:[`"`,String(e),`"`]}),(0,G.jsx)(`span`,{className:`json-punct`,children:`: `})]}),$(n,t+1,String(e))]},String(e)));return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`jt-toggle${c?``:` jt-open`}`,onClick:e=>je(e,o),style:{cursor:`pointer`},children:c?`▶`:`▼`}),(0,G.jsx)(`span`,{className:`json-punct`,children:r?`[`:`{`}),(0,G.jsxs)(`span`,{className:`jt-summary${c?` jt-show`:``}`,id:`${o}s`,children:[`… `,s]}),(0,G.jsx)(`div`,{className:`jt-children${c?``:` jt-open`}`,id:o,children:l}),(0,G.jsx)(`div`,{className:`jt-close${c?` jt-hidden`:``}`,id:`${o}c`,children:(0,G.jsx)(`span`,{className:`json-punct`,children:r?`]`:`}`})})]})}function je(e,t){e.stopPropagation();let n=document.getElementById(t),r=document.getElementById(t+`s`),i=document.getElementById(t+`c`),a=e.currentTarget;n&&(n.classList.contains(`jt-open`)?(n.classList.remove(`jt-open`),a.classList.remove(`jt-open`),a.textContent=`▶`,r?.classList.add(`jt-show`),i?.classList.add(`jt-hidden`)):(n.classList.add(`jt-open`),a.classList.add(`jt-open`),a.textContent=`▼`,r?.classList.remove(`jt-show`),i?.classList.remove(`jt-hidden`)))}function Me(e){let t=e.request.body,n=[];if(typeof t.system==`string`&&t.system.trim())n.push(t.system);else if(Array.isArray(t.system)){let e=t.system.map(e=>typeof e==`string`?e:e?.type===`text`&&e.text||``).filter(Boolean).join(`
16
-
17
- `);e.trim()&&n.push(e)}let r=e.request.body.messages||[];for(let e of r)if(e.role===`system`||e.role===`developer`){let t=typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.map(e=>e.text||``).filter(Boolean).join(`
18
-
19
- `):``;t.trim()&&n.push(t)}return n.length?n.join(`
20
-
21
- `):null}function Ne(e){let t=e.response.body;if(!t)return null;if(t.choices&&Array.isArray(t.choices)&&t.choices.length>0){let e=t.choices[0].message;if(e){let t=e.content,n=e.reasoning_content,r=e.tool_calls,i=[];if(n&&i.push({type:`thinking`,thinking:n}),typeof t==`string`&&t.trim()?i.push({type:`text`,text:t}):Array.isArray(t)?i.push(...t):t!=null&&i.push({type:`text`,text:JSON.stringify(t)}),r&&r.length>0)for(let e of r){let t=e.function.arguments;try{t=JSON.parse(e.function.arguments)}catch{}i.push({type:`tool_use`,id:e.id,name:e.function.name,input:t})}if(i.length===1&&i[0].type===`text`)return i[0].text||null;if(i.length>0)return i}return null}if(t.content&&Array.isArray(t.content)){let e=t.content;return e.length===1&&e[0].type===`text`?e[0].text||null:e}return typeof t.text==`string`?t.text:null}function Pe({onClose:e}){let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null);(0,B.useEffect)(()=>{Promise.all([W.getProviders().then(n).catch(()=>{}),W.getConfig().then(e=>o(e.proxy?.port??null)).catch(()=>{})]).finally(()=>i(!1))},[]);let s=a??(window.location.port?Number(window.location.port):void 0);return(0,G.jsxs)(`div`,{className:`p-5 space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold`,children:`设置`}),(0,G.jsx)(`button`,{onClick:e,style:{color:`var(--text-tertiary)`},children:(0,G.jsx)(v,{size:16})})]}),(0,G.jsxs)(`div`,{className:`rounded-lg p-3`,style:{background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`代理服务器`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-1.5 text-xs`,children:[(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`监听端口`}),(0,G.jsx)(`span`,{className:`font-mono`,style:{color:`var(--blue)`},children:s}),(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`OpenAI Base URL`}),(0,G.jsxs)(`span`,{className:`font-mono`,style:{color:`var(--blue)`},children:[`http://localhost:`,s,`/v1`]}),(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`Anthropic Base URL`}),(0,G.jsxs)(`span`,{className:`font-mono`,style:{color:`var(--blue)`},children:[`http://localhost:`,s]})]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg p-3`,style:{background:`var(--bg)`,border:`1px solid var(--border)`},children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium mb-1`,children:`上游服务商`}),(0,G.jsxs)(`p`,{className:`text-[11px] mb-3`,style:{color:`var(--text-tertiary)`},children:[`修改请编辑项目根目录的 `,(0,G.jsx)(`code`,{className:`font-mono px-1 py-0.5 rounded`,style:{background:`var(--bg-code)`},children:`.env`}),` 文件后重启服务`]}),r?(0,G.jsx)(`div`,{className:`text-sm`,style:{color:`var(--text-tertiary)`},children:`加载中…`}):t.length===0?(0,G.jsxs)(`div`,{className:`text-sm italic`,style:{color:`var(--text-tertiary)`},children:[`未检测到已配置的 Provider。请在 `,(0,G.jsx)(`code`,{className:`font-mono`,children:`.env`}),` 中设置 `,(0,G.jsx)(`code`,{className:`font-mono`,children:`OPENAI_API_KEY`}),` 等变量。`]}):(0,G.jsx)(`div`,{className:`space-y-1.5`,children:t.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded`,style:{border:`1px solid var(--border)`},children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full flex-shrink-0`,style:{background:`var(--green)`}}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium capitalize`,children:e.type}),(0,G.jsx)(`div`,{className:`text-[11px] font-mono truncate`,style:{color:`var(--text-tertiary)`},children:e.baseUrl})]}),e.apiKey&&(0,G.jsx)(`span`,{className:`text-[11px] font-mono flex-shrink-0`,style:{color:`var(--text-tertiary)`},children:e.apiKey})]},e.type))})]})]})}function Fe({open:e,title:t,message:n,confirmText:r=`确认`,cancelText:i=`取消`,danger:a=!1,onConfirm:o,onCancel:s}){let c=(0,B.useRef)(null);return(0,B.useEffect)(()=>{e&&c.current?.focus()},[e]),(0,B.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&s(),e.key===`Enter`&&o()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,o,s]),e?(0,G.jsx)(`div`,{className:`confirm-overlay`,onClick:s,children:(0,G.jsxs)(`div`,{className:`confirm-dialog`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`confirm-icon-row`,children:(0,G.jsx)(`span`,{className:`confirm-icon${a?` danger`:``}`,children:(0,G.jsx)(m,{size:20})})}),(0,G.jsx)(`div`,{className:`confirm-title`,children:t}),(0,G.jsx)(`div`,{className:`confirm-message`,children:n}),(0,G.jsxs)(`div`,{className:`confirm-actions`,children:[(0,G.jsx)(`button`,{className:`confirm-btn cancel`,onClick:s,children:i}),(0,G.jsx)(`button`,{ref:c,className:`confirm-btn ok${a?` danger`:``}`,onClick:o,children:r})]})]})}):null}function Ie(){try{let e=localStorage.getItem(`lpt-theme`);if(e===`dark`||e===`light`)return e}catch{}return window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function Le(e){document.documentElement.setAttribute(`data-theme`,e);try{localStorage.setItem(`lpt-theme`,e)}catch{}}function Re(){let[e,t]=(0,B.useState)([]),[r,i]=(0,B.useState)(null),[a,c]=(0,B.useState)(null),[u,d]=(0,B.useState)(``),[f,m]=(0,B.useState)(`all`),[h,g]=(0,B.useState)(!1),[_,y]=(0,B.useState)({open:!1,title:``,message:``,onConfirm:()=>{}}),b=(e,t,n)=>{y({open:!0,title:e,message:t,onConfirm:n})},x=()=>y(e=>({...e,open:!1})),[ee,te]=(0,B.useState)(!0),[S,ne]=(0,B.useState)(Ie),[C,w]=(0,B.useState)(320),T=(0,B.useRef)(!1),E=(0,B.useRef)(0),D=(0,B.useRef)(0),[O,k]=(0,B.useState)(!1),A=(0,B.useRef)(null),[j,M]=(0,B.useState)(!1);(0,B.useEffect)(()=>{Le(S)},[S]),(0,B.useEffect)(()=>{if(!O)return;let e=e=>{A.current&&!A.current.contains(e.target)&&k(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[O]);let oe=()=>ne(e=>e===`light`?`dark`:`light`),N=e.find(e=>e.id===a)||null,P=(0,B.useCallback)(async()=>{try{let[e,n]=await Promise.all([W.getTraces({keyword:u||void 0,limit:200}),W.getStats()]);t(e.traces),i(n)}catch{}finally{te(!1)}},[u]),se=(0,B.useCallback)(e=>{if(e.type===`trace:new`){let n=e.data;u||t(e=>[n,...e]),i(e=>e&&{...e,totalCalls:e.totalCalls+1})}else if(e.type===`trace:update`||e.type===`trace:complete`){let n=e.data;t(e=>e.map(e=>e.id===n.id?{...e,...n}:e)),e.type===`trace:complete`&&W.getStats().then(i).catch(()=>{})}},[u]),{connected:F}=ue({url:`ws://${window.location.host}/ws`,onEvent:se});(0,B.useEffect)(()=>{P()},[P]);let I=e=>{T.current=!0,E.current=e.clientX,D.current=C,document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let t=e=>{if(!T.current)return;let t=e.clientX-E.current;w(Math.max(240,Math.min(600,D.current+t)))},n=()=>{T.current=!1,document.body.style.userSelect=``,document.body.style.cursor=``,document.removeEventListener(`mousemove`,t),document.removeEventListener(`mouseup`,n)};document.addEventListener(`mousemove`,t),document.addEventListener(`mouseup`,n)},ce=r?.totalTokens??0,le=r?.totalCalls??0,L=r?.avgDuration??0,R=e.reduce((e,t)=>e+(t.usage?.promptTokens||0),0),z=e.reduce((e,t)=>e+(t.usage?.completionTokens||0),0),V=f===`all`?e:e.filter(e=>e.status===f),H={};for(let t of e)t.model&&(H[t.model]=(H[t.model]||0)+1);let U=Object.entries(H).sort((e,t)=>t[1]-e[1]).slice(0,4),[q,fe]=(0,B.useState)(null),pe=q?V.filter(e=>e.model===q):V,me=e.filter(e=>e.status===`error`).length;return(0,G.jsxs)(`div`,{className:`flex flex-col h-screen overflow-hidden`,style:{background:`var(--bg)`,color:`var(--text)`},children:[(0,G.jsxs)(`header`,{className:`flex items-center gap-3 px-4 flex-shrink-0`,style:{background:`var(--bg-card)`,borderBottom:`1px solid var(--border)`,height:`52px`,zIndex:10},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsx)(n,{size:18,style:{color:`var(--blue)`}}),(0,G.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:`LPT`})]}),(0,G.jsx)(`div`,{className:`w-px h-5 flex-shrink-0`,style:{background:`var(--border)`}}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] flex-shrink-0`,style:{color:`var(--text-tertiary)`},children:[(0,G.jsxs)(`span`,{children:[`请求 `,(0,G.jsx)(`b`,{className:`font-mono`,style:{color:`var(--text-secondary)`},children:le})]}),(0,G.jsxs)(`span`,{children:[`Tokens `,(0,G.jsx)(`b`,{className:`font-mono`,style:{color:`var(--text-secondary)`},children:ce.toLocaleString()})]}),R>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono`,style:{color:`var(--blue)`},children:[`↑`,(0,G.jsx)(`b`,{children:R.toLocaleString()})]}),z>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono`,style:{color:`var(--green)`},children:[`↓`,(0,G.jsx)(`b`,{children:z.toLocaleString()})]}),L>0&&(0,G.jsxs)(`span`,{children:[`均 `,L,`ms`]})]}),U.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-px h-5 flex-shrink-0`,style:{background:`var(--border)`}}),(0,G.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-hidden flex-1`,children:U.map(([e,t])=>(0,G.jsxs)(`button`,{onClick:()=>fe(t=>t===e?null:e),className:`filter-chip${q===e?` active`:``}`,children:[e.split(`/`).pop()||e,(0,G.jsx)(`span`,{className:`chip-count`,children:t})]},e))})]}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsxs)(`span`,{className:`text-[11px] flex items-center gap-1`,style:{color:F?`var(--green)`:`var(--red)`},children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full`,style:{background:F?`var(--green)`:`var(--red)`}}),F?`实时`:`离线`]}),(0,G.jsx)(K,{content:`从磁盘加载历史记录`,children:(0,G.jsxs)(`button`,{onClick:async()=>{M(!0),await W.reloadTraces().catch(()=>{}),await P(),M(!1)},className:`flex items-center gap-1 text-[11px] px-2 py-1 rounded border transition-colors`,style:{borderColor:`var(--border)`,color:j?`var(--blue)`:`var(--text-tertiary)`},disabled:j,children:[(0,G.jsx)(l,{size:12,style:{animation:j?`spin 1s linear infinite`:`none`}}),`加载记录`]})}),(0,G.jsxs)(`div`,{ref:A,className:`clear-split-btn`,style:{position:`relative`},children:[(0,G.jsx)(K,{content:`清空当前会话`,children:(0,G.jsxs)(`button`,{onClick:()=>{W.deleteTraces(!1).then(()=>{t([]),P()}),k(!1)},className:`clear-split-main`,children:[(0,G.jsx)(p,{size:12}),` 清空`]})}),(0,G.jsx)(`button`,{onClick:()=>k(e=>!e),className:`clear-split-arrow`,"aria-label":`更多清空选项`,children:(0,G.jsx)(o,{size:11})}),O&&(0,G.jsxs)(`div`,{className:`clear-dropdown`,children:[(0,G.jsx)(`div`,{className:`clear-dropdown-label`,children:`选择清空方式`}),(0,G.jsxs)(`button`,{className:`clear-dropdown-item`,onClick:()=>{W.deleteTraces(!1).then(()=>{t([]),P()}),k(!1)},children:[(0,G.jsx)(p,{size:12}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`clear-dropdown-item-title`,children:`清空当前会话`}),(0,G.jsx)(`div`,{className:`clear-dropdown-item-desc`,children:`仅清内存,文件保留,重启可恢复`})]})]}),(0,G.jsxs)(`button`,{className:`clear-dropdown-item danger`,onClick:()=>{k(!1),b(`永久删除所有文件`,`将永久删除所有 Trace 文件,无法恢复,确认吗?`,()=>{W.deleteTraces(!0).then(()=>{t([]),P()})})},children:[(0,G.jsx)(p,{size:12}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`clear-dropdown-item-title`,children:`永久删除所有文件`}),(0,G.jsx)(`div`,{className:`clear-dropdown-item-desc`,children:`删除磁盘 JSONL,重启不恢复`})]})]})]})]}),(0,G.jsx)(K,{content:S===`dark`?`浅色模式`:`深色模式`,children:(0,G.jsx)(`button`,{onClick:oe,className:`flex items-center justify-center w-7 h-7 rounded border transition-colors`,style:{borderColor:`var(--border)`,color:`var(--text-tertiary)`},children:S===`dark`?(0,G.jsx)(s,{size:13}):(0,G.jsx)(ie,{size:13})})}),(0,G.jsx)(K,{content:`Provider 与代理设置`,children:(0,G.jsxs)(`button`,{onClick:()=>g(!h),className:`flex items-center gap-1 text-[11px] px-2 py-1 rounded border transition-colors`,style:{borderColor:h?`var(--blue)`:`var(--border)`,color:h?`var(--blue)`:`var(--text-tertiary)`,background:h?`var(--blue-bg)`:`transparent`},children:[(0,G.jsx)(re,{size:12}),` 设置`]})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-1 overflow-hidden relative`,children:[h&&(0,G.jsx)(`div`,{className:`absolute inset-0 z-20 flex`,style:{background:`rgba(0,0,0,0.15)`},onClick:()=>g(!1),children:(0,G.jsx)(`div`,{className:`ml-auto h-full overflow-auto`,style:{width:`420px`,background:`var(--bg-card)`,borderLeft:`1px solid var(--border)`},onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Pe,{onClose:()=>g(!1)})})}),(0,G.jsxs)(`div`,{className:`flex flex-col flex-shrink-0`,style:{width:`${C}px`,borderRight:`1px solid var(--border)`,background:`var(--bg-card)`},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b flex-shrink-0`,style:{borderColor:`var(--border)`},children:[(0,G.jsx)(ae,{size:13,style:{color:`var(--text-tertiary)`}}),(0,G.jsx)(`input`,{type:`text`,placeholder:`搜索消息、模型…`,value:u,onChange:e=>d(e.target.value),className:`flex-1 text-xs bg-transparent outline-none`,style:{color:`var(--text)`}}),u&&(0,G.jsx)(`button`,{onClick:()=>d(``),style:{color:`var(--text-tertiary)`},children:(0,G.jsx)(v,{size:11})}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[`all`,`error`].map(t=>(0,G.jsx)(K,{content:t===`all`?`显示全部请求`:`只看报错的请求`,placement:`bottom`,delay:400,children:(0,G.jsx)(`button`,{onClick:()=>m(t),className:`filter-chip${f===t?` active`:``}`,style:{fontSize:`10px`,padding:`2px 7px`},children:t===`all`?`全部 ${e.length}`:`✕ ${me}`})},t))})]}),(0,G.jsx)(de,{traces:pe,activeId:a,onSelect:e=>{c(e)},loading:ee,onDeleteFile:n=>{b(`删除记录文件`,`删除 ${n}?此操作不可恢复。`,async()=>{await W.deleteTraceFile(n).catch(()=>{}),t(e=>e.filter(e=>e.sourceFile!==n)),a&&e.find(e=>e.id===a)?.sourceFile===n&&c(null)})}})]}),(0,G.jsx)(`div`,{className:`resize-handle`,onMouseDown:I,style:{background:`var(--border-light)`}}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto detail-scroll`,style:{background:`var(--bg)`},children:N?(0,G.jsx)(_e,{trace:N},N.id):(0,G.jsx)(ze,{hasTraces:e.length>0})})]}),(0,G.jsx)(Fe,{open:_.open,title:_.title,message:_.message,confirmText:`确认删除`,danger:!0,onConfirm:()=>{x(),_.onConfirm()},onCancel:x})]})}function ze({hasTraces:e}){let t=window.location.port,r=t?`http://localhost:${t}`:window.location.origin;return e?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm`,style:{color:`var(--text-tertiary)`},children:`选择左侧一条请求查看详情`}):(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-5`,style:{padding:`40px`},children:[(0,G.jsx)(n,{size:28,style:{color:`var(--border)`}}),(0,G.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,G.jsx)(`div`,{style:{fontSize:`15px`,fontWeight:600,color:`var(--text)`,marginBottom:`6px`},children:`等待第一条请求…`}),(0,G.jsx)(`div`,{style:{fontSize:`12px`,color:`var(--text-tertiary)`,lineHeight:1.7},children:`设置以下环境变量,所有兼容 OpenAI 接口的工具都会被自动拦截`})]}),(0,G.jsxs)(`div`,{style:{background:`var(--bg-code)`,border:`1px solid var(--border)`,borderRadius:`8px`,padding:`14px 18px`,fontFamily:`var(--mono)`,fontSize:`13px`,lineHeight:2,minWidth:`340px`},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{style:{color:`var(--amber)`},children:`export `}),(0,G.jsx)(`span`,{style:{color:`var(--blue)`},children:`OPENAI_BASE_URL`}),(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`=`}),(0,G.jsxs)(`span`,{style:{color:`var(--green)`},children:[`"`,r,`/v1"`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{style:{color:`var(--amber)`},children:`export `}),(0,G.jsx)(`span`,{style:{color:`var(--blue)`},children:`OPENAI_API_KEY`}),(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`},children:`=`}),(0,G.jsx)(`span`,{style:{color:`var(--green)`},children:`"any-key"`}),(0,G.jsx)(`span`,{style:{color:`var(--text-tertiary)`,fontStyle:`italic`,fontSize:`11px`},children:` # 代理不验证 key`})]})]}),(0,G.jsxs)(`div`,{style:{fontSize:`11px`,color:`var(--text-tertiary)`,lineHeight:1.7,textAlign:`center`,maxWidth:`320px`},children:[`上游 API 地址在 `,(0,G.jsx)(`span`,{style:{color:`var(--blue)`},children:`设置`}),` 中配置。 记录内容包括流式输出、工具调用与思考过程。`]})]})}V.createRoot(document.getElementById(`root`)).render((0,G.jsx)(B.StrictMode,{children:(0,G.jsx)(Re,{})}));