cc-team-viewer 1.4.29 → 1.4.31
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.
|
@@ -425,7 +425,7 @@ Skill 描述未找到。请确保已经使用过该 skill,以便 cc-team-viewe
|
|
|
425
425
|
|
|
426
426
|
`;r&&(o+=`${r}
|
|
427
427
|
|
|
428
|
-
`),t.push({type:"markdown",text:o});const i=(e==null?void 0:e.input_schema)||(e==null?void 0:e.parameters)||null;return i&&t.push({type:"json",label:"Parameters",data:i}),t}function ZH(e){var t;if(typeof e=="string")return e.slice(0,60).replace(/\n/g," ");if(Array.isArray(e)){for(const n of e)if((n==null?void 0:n.type)==="text"&&((t=n.text)!=null&&t.trim()))return n.text.trim().slice(0,60).replace(/\n/g," ")}return""}function JH(e){var r;const t=[];let n=0;for(;n<e.length;){const o=e[n];if((o==null?void 0:o.role)!=="user"){n++;continue}const i=((r=e[n+1])==null?void 0:r.role)==="assistant"?e[n+1]:null;t.push({id:`turn__${n}`,isTurn:!0,turnIndex:t.length,timestamp:o._timestamp||null,assistantTimestamp:(i==null?void 0:i._timestamp)||null,userBlocks:Ah(o==null?void 0:o.content),assistantBlocks:i?Ah(i.content):null,preview:ZH(o==null?void 0:o.content)}),n+=i?2:1}return t}function Lh(e){try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}catch{return null}}function eV({text:e,compact:t}){const n=di(e);return t?C.jsx("div",{className:yt.textBlockCompact,children:C.jsx("div",{className:`chat-md ${yt.markdownBody}`,dangerouslySetInnerHTML:{__html:n}})}):C.jsxs("div",{className:yt.textBlock,children:[C.jsx("div",{className:yt.textBlockBar,children:C.jsx("span",{className:`${yt.blockTag} ${yt.blockTagText}`,children:"text"})}),C.jsx("div",{className:`chat-md ${yt.textBlockBody}`,dangerouslySetInnerHTML:{__html:n}})]})}function tV({block:e}){const[t,n]=d.useState(!0),r=e.text.length>60?e.text.slice(0,60).replace(/\n/g," ")+"…":e.text.replace(/\n/g," "),o=di(e.text);return C.jsxs("div",{className:yt.thinkingBlock,children:[C.jsxs("div",{className:yt.thinkingHeader,onClick:()=>n(i=>!i),children:[t?C.jsx(Ta,{className:yt.arrow}):C.jsx(Co,{className:yt.arrow}),C.jsx("span",{className:`${yt.blockTag} ${yt.blockTagThinking}`,children:"thinking"}),!t&&C.jsx("span",{className:yt.thinkingPreview,children:r})]}),t&&C.jsx("div",{className:yt.thinkingBody,children:C.jsx("div",{className:`chat-md ${yt.markdownBody}`,dangerouslySetInnerHTML:{__html:o}})})]})}function Zd({blocks:e,compact:t}){return!e||e.length===0?null:C.jsx(C.Fragment,{children:e.map((n,r)=>C.jsx(nV,{block:n,compact:t},r))})}function nV({block:e,compact:t}){var n;return e.type==="separator"?C.jsx("hr",{className:yt.blockSeparator}):e.type==="markdown"?(n=e.text)!=null&&n.trim()?C.jsx(eV,{text:e.text,compact:t}):null:e.type==="thinking"?C.jsx(tV,{block:e}):e.type==="tool_use"?C.jsxs("div",{className:yt.toolBlock,children:[C.jsxs("div",{className:yt.toolBlockHeader,children:[C.jsx("span",{className:yt.blockTag,children:"tool_use"}),C.jsx("span",{className:yt.toolName,children:e.name}),e.id&&C.jsx("span",{className:yt.toolId,children:e.id})]}),C.jsx("div",{className:yt.toolBlockBody,children:C.jsx(Qd,{data:e.input,defaultExpand:"root"})})]}):e.type==="tool_result"?C.jsxs("div",{className:`${yt.toolBlock} ${e.is_error?yt.toolBlockError:yt.toolBlockResult}`,children:[C.jsxs("div",{className:yt.toolBlockHeader,children:[C.jsx("span",{className:`${yt.blockTag} ${e.is_error?yt.blockTagError:yt.blockTagResult}`,children:"tool_result"}),e.tool_use_id&&C.jsx("span",{className:yt.toolId,children:e.tool_use_id}),e.is_error&&C.jsx("span",{className:yt.errorLabel,children:"error"})]}),C.jsx("div",{className:yt.toolBlockBody,children:C.jsx(Zd,{blocks:e.content,compact:!0})})]}):e.type==="json"?C.jsxs("div",{className:yt.jsonBlock,children:[e.label&&C.jsx("div",{className:yt.jsonBlockLabel,children:e.label}),C.jsx(Qd,{data:e.data,defaultExpand:"root"})]}):null}function rV({turn:e}){const t=e.timestamp?Lh(e.timestamp):null,n=e.assistantTimestamp?Lh(e.assistantTimestamp):null;return C.jsxs("div",{children:[C.jsxs("div",{className:yt.roleHeader,children:[C.jsx("span",{className:`${yt.roleBadge} ${yt.role_user}`,children:"user"}),C.jsx("span",{className:yt.roleLabel,children:`Turn ${e.turnIndex+1}`}),t&&C.jsx("span",{className:yt.contentTime,children:t})]}),C.jsx(Zd,{blocks:e.userBlocks}),e.assistantBlocks&&C.jsxs(C.Fragment,{children:[C.jsx("div",{className:yt.turnDivider}),C.jsxs("div",{className:yt.roleHeader,children:[C.jsx("span",{className:`${yt.roleBadge} ${yt.role_assistant}`,children:"assistant"}),n&&C.jsx("span",{className:yt.contentTime,children:n})]}),C.jsx(Zd,{blocks:e.assistantBlocks})]})]})}function oV({title:e,items:t,historyItems:n,onSelect:r,selectedId:o}){const[i,l]=d.useState(!0),[c,u]=d.useState(!1),f=t.length+((n==null?void 0:n.length)||0);function m(g){const h=o===g.id;return C.jsxs("div",{className:`${yt.item} ${h?yt.itemActive:""}`,onClick:()=>r(g),children:[C.jsxs("div",{className:yt.itemContent,children:[C.jsx("span",{className:yt.itemLabel,children:g.label}),g.sublabel&&!h&&C.jsx("div",{className:yt.itemSublabel,children:g.sublabel})]}),g.time&&C.jsx("span",{className:yt.itemTime,children:g.time})]},g.id)}return C.jsxs("div",{className:yt.section,children:[C.jsxs("div",{className:yt.sectionHeader,onClick:()=>l(g=>!g),children:[i?C.jsx(Ta,{className:yt.arrow}):C.jsx(Co,{className:yt.arrow}),C.jsx("span",{className:yt.sectionTitle,children:e}),C.jsx("span",{className:yt.sectionCount,children:f})]}),i&&C.jsxs("div",{className:yt.sectionBody,children:[n&&n.length>0&&C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:yt.historyToggle,onClick:()=>u(g=>!g),children:[c?C.jsx(Ta,{className:yt.arrow}):C.jsx(Co,{className:yt.arrow}),C.jsxs("span",{className:yt.historyToggleLabel,children:["历史"," (",n.length,")"]})]}),c&&n.map(m)]}),t.map(m)]})]})}function aV({body:e,response:t}){const[n,r]=d.useState(null),o=d.useMemo(()=>{if(!Array.isArray(e==null?void 0:e.messages))return[];const u=JH(e.messages);if(u.length===0)return u;const f=u[u.length-1],m=t!=null&&t.content?Ah(t.content):null;return[...u.slice(0,-1),{...f,assistantBlocks:m??f.assistantBlocks}]},[e,t]);if(d.useEffect(()=>{o.length>0?r(o[o.length-1]):r(null)},[e,t]),!e||typeof e!="object")return C.jsx("div",{className:yt.emptyWrap,children:C.jsx(lo,{description:"无数据"})});const i=[],l=YH(e.system);if(l!=null&&i.push({key:"system",title:"系统提示",items:[{id:"system__0",label:"系统提示",blocks:l}]}),o.length>0){const u=h=>({...h,label:`轮次 ${h.turnIndex+1}`,time:h.timestamp?Lh(h.timestamp):null,sublabel:h.preview||void 0}),f=h=>({...h,label:"当前轮次",sublabel:h.preview||void 0}),m=o.slice(0,-1).map(u),g=f(o[o.length-1]);i.push({key:"messages",title:"消息",historyItems:m.length>0?m:void 0,items:[g]})}if(Array.isArray(e.tools)&&e.tools.length>0&&i.push({key:"tools",title:"工具",items:e.tools.map((u,f)=>({id:`tool__${f}`,label:(u==null?void 0:u.name)||`Tool ${f}`,blocks:QH(u)}))}),i.length===0)return C.jsx("div",{className:yt.emptyWrap,children:C.jsx(lo,{description:"无字段"})});const c=n!=null&&n.isTurn?o.find(u=>u.id===n.id)??null:n;return C.jsxs("div",{className:yt.root,children:[C.jsx("div",{className:yt.sidebar,children:i.map(u=>C.jsx(oV,{title:u.title,items:u.items,historyItems:u.historyItems,selectedId:c==null?void 0:c.id,onSelect:f=>r(f)},u.key))}),C.jsx("div",{className:yt.content,children:c==null?C.jsx("div",{className:yt.contentEmpty,children:C.jsx(KH,{type:"secondary",children:"选择 Prompt"})}):C.jsx("div",{className:yt.contentInner,children:c.isTurn?C.jsx(rV,{turn:c}):C.jsxs(C.Fragment,{children:[c.role&&C.jsxs("div",{className:yt.roleHeader,children:[C.jsx("span",{className:`${yt.roleBadge} ${yt[`role_${c.role}`]||""}`,children:c.role}),C.jsx("span",{className:yt.roleLabel,children:c.label})]}),C.jsx(Zd,{blocks:c.blocks})]})},c.id)})]})}const iV="_container_i6t4e_1",sV="_emptyState_i6t4e_9",lV="_urlSection_i6t4e_16",cV="_urlLeft_i6t4e_23",uV="_tokenStatsBox_i6t4e_28",dV="_tokenGrid_i6t4e_35",fV="_tokenRows_i6t4e_45",mV="_tokenRow_i6t4e_45",pV="_tokenRowBorder_i6t4e_53",gV="_tokenLabel_i6t4e_57",hV="_tokenTd_i6t4e_64",vV="_tokenHitRate_i6t4e_73",bV="_tokenHitRateLabel_i6t4e_86",yV="_urlText_i6t4e_96",xV="_metaText_i6t4e_103",SV="_headersContainer_i6t4e_107",CV="_headerRow_i6t4e_111",wV="_headerKey_i6t4e_117",EV="_headerValue_i6t4e_122",_V="_streamingBox_i6t4e_127",$V="_rawTextPre_i6t4e_140",NV="_tabContent_i6t4e_153",RV="_bodyLabel_i6t4e_161",OV="_bodyHeader_i6t4e_165",IV="_diffSection_i6t4e_172",TV="_diffToggle_i6t4e_176",MV="_diffIcon_i6t4e_182",PV="_reminderSelect_i6t4e_208",Wt={container:iV,emptyState:sV,urlSection:lV,urlLeft:cV,tokenStatsBox:uV,tokenGrid:dV,tokenRows:fV,tokenRow:mV,tokenRowBorder:pV,tokenLabel:gV,tokenTd:hV,tokenHitRate:vV,tokenHitRateLabel:bV,urlText:yV,metaText:xV,headersContainer:SV,headerRow:CV,headerKey:wV,headerValue:EV,streamingBox:_V,rawTextPre:$V,tabContent:NV,bodyLabel:RV,bodyHeader:OV,diffSection:IV,diffToggle:TV,diffIcon:MV,reminderSelect:PV},{Text:ao,Paragraph:kV}=Ho;class jV extends Q.Component{constructor(t){super(t),this.state={bodyViewMode:{request:"json",response:"json",diff:"json"},diffExpanded:!1,requestHeadersExpanded:!1,responseHeadersExpanded:!1,diffTooltipDismissed:!1,reminderFilters:null}}componentDidMount(){fetch("/api/preferences").then(t=>t.json()).then(t=>{t.diffTooltipDismissed&&this.setState({diffTooltipDismissed:!0})}).catch(()=>{})}dismissDiffTooltip(){this.setState({diffTooltipDismissed:!0}),fetch("/api/preferences",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({diffTooltipDismissed:!0})}).catch(()=>{})}shouldComponentUpdate(t,n){if(t.request!==this.props.request){const r=ka(t.request);this.setState({diffExpanded:r&&!!t.expandDiff,requestHeadersExpanded:!1,responseHeadersExpanded:!1,reminderFilters:null})}return t.request!==this.props.request||t.currentTab!==this.props.currentTab||t.onTabChange!==this.props.onTabChange||t.selectedIndex!==this.props.selectedIndex||t.expandDiff!==this.props.expandDiff||n.bodyViewMode!==this.state.bodyViewMode||n.diffExpanded!==this.state.diffExpanded||n.requestHeadersExpanded!==this.state.requestHeadersExpanded||n.responseHeadersExpanded!==this.state.responseHeadersExpanded||n.diffTooltipDismissed!==this.state.diffTooltipDismissed||n.reminderFilters!==this.state.reminderFilters}toggleBodyViewMode(t){this.setState(n=>({bodyViewMode:{...n.bodyViewMode,[t]:n.bodyViewMode[t]==="json"?"text":"json"}}))}copyBody(t){var l;const{request:n}=this.props;if(!n)return;let r;if(t==="diff"?r=this._lastDiffResult:r=t==="request"?n.body:(l=n.response)==null?void 0:l.body,r==null)return;const o=typeof r=="object"?zi(r):r,i=typeof o=="string"?o:JSON.stringify(o,null,2);navigator.clipboard.writeText(i).then(()=>Av.success("复制成功"))}renderHeaders(t){return!t||Object.keys(t).length===0?C.jsx(ao,{type:"secondary",children:"无 Headers"}):C.jsx("div",{className:Wt.headersContainer,children:Object.entries(t).map(([n,r])=>C.jsxs("div",{className:Wt.headerRow,children:[C.jsx(ao,{code:!0,className:Wt.headerKey,children:n}),n==="authorization"&&C.jsx(Li,{doc:"TranslateContextPollution"}),C.jsx(ao,{type:"secondary",className:Wt.headerValue,children:String(r)})]},n))})}getRequestExpandNode(t,n){if(n!=="request"||!t||typeof t!="object")return;const{request:r,requests:o,selectedIndex:i}=this.props;if(!r)return;const l=o&&i!=null?o[i+1]:null,{type:c}=yc(r,l);let u=null;if(this.state.reminderFilters==="claudeMd"&&Array.isArray(t.messages)){u=new Set,u.add(t.messages);for(const g of t.messages){if(!g||typeof g!="object")continue;const h=g.content;if(typeof h=="string")Wd(h)&&u.add(g);else if(Array.isArray(h)){let v=!1;for(const b of h)b&&b.type==="text"&&Wd(b.text)&&(u.add(b),v=!0);v&&(u.add(g),u.add(h))}}}let f=null;if(this.state.reminderFilters==="skills"&&Array.isArray(t.messages)){f=new Set,f.add(t.messages);for(const g of t.messages){if(!g||typeof g!="object")continue;const h=g.content;if(typeof h=="string")Ud(h)&&f.add(g);else if(Array.isArray(h)){let v=!1;for(const b of h)b&&b.type==="text"&&Ud(b.text)&&(f.add(b),v=!0);v&&(f.add(g),f.add(h))}}}const m=u||f;if(c==="Preflight"){const g=new Set,h=v=>{v&&typeof v=="object"&&(g.add(v),Array.isArray(v)?v.forEach(h):Object.values(v).forEach(h))};return Array.isArray(t.messages)&&h(t.messages),Array.isArray(t.system)&&t.system.length>=3&&h(t.system[2]),(v,b,x)=>!!(v<2||g.has(b)||m&&m.has(b)||v===1&&x==="system")}if(c==="MainAgent"&&Array.isArray(t.messages)&&t.messages.length===1){const g=t.messages[0],h=g&&Array.isArray(g.content)?g.content:null,v=h&&h.length>0?h[h.length-1]:null,b=new Set,x=S=>{S&&typeof S=="object"&&(b.add(S),Array.isArray(S)?S.forEach(x):Object.values(S).forEach(x))};return v&&x(v),b.add(t.messages),g&&typeof g=="object"&&b.add(g),h&&b.add(h),(S,E,w)=>!!(S<2||b.has(E)||m&&m.has(E))}if(m)return(g,h,v)=>!!(g<2||m.has(h))}renderBody(t,n){const{bodyViewMode:r}=this.state;if(t==null)return C.jsx(ao,{type:"secondary",children:"无 Body"});if(typeof t=="string"&&t.includes("Streaming Response"))return C.jsx("div",{className:Wt.streamingBox,children:C.jsx(ao,{type:"secondary",children:"流式响应 — 此请求使用了 SSE 流式传输,响应内容无法完整捕获。"})});const o=typeof t=="object"?zi(t):t,i=r[n]==="json",l=this.getRequestExpandNode(o,n);return C.jsx("div",{children:i?C.jsx(Qd,{data:o,defaultExpand:n==="response"?"all":"root",expandNode:l}):C.jsx("pre",{className:Wt.rawTextPre,children:typeof o=="string"?o:JSON.stringify(o,null,2)})})}getPrevMainAgentRequest(){const{requests:t,selectedIndex:n}=this.props;if(!t||n==null)return null;for(let r=n-1;r>=0;r--)if(ka(t[r]))return t[r];return null}computeDiff(t,n){if(t==null||n==null||typeof t!="object"||typeof n!="object")return null;const r={},o=new Set([...Object.keys(t),...Object.keys(n)]);for(const i of o)if(!i.startsWith("_"))if(!(i in t))r[i]=n[i];else if(i in n){const l=JSON.stringify(t[i]),c=JSON.stringify(n[i]);l!==c&&(i==="messages"&&Array.isArray(t[i])&&Array.isArray(n[i])&&n[i].length>t[i].length?r[i]=n[i].slice(t[i].length):r[i]=n[i])}else continue;return Object.keys(r).length?r:null}render(){var h,v,b;const{request:t,currentTab:n,onTabChange:r}=this.props;if(!t)return C.jsx("div",{className:Wt.emptyState,children:C.jsx(lo,{description:"选择一个请求查看详情"})});const o=new Date(t.timestamp).toLocaleString("zh-CN"),i=t.response&&t.response.status<400;let l=null;if(ka(t)){const x=this.getPrevMainAgentRequest();if(x){const S=JSON.stringify(t.body).length,E=JSON.stringify(x.body).length;if(S<E)l=C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(va,{title:this.state.diffTooltipDismissed?null:C.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[C.jsx("span",{style:{flex:1},children:"为了避免看冗长的全文,所以为大家简化���示了 MainAgent 的增量部分,通常只有 message 增加"}),C.jsx(gi,{style:{cursor:"pointer",fontSize:10,marginTop:2,flexShrink:0},onClick:_=>{_.stopPropagation(),this.dismissDiffTooltip()}})]}),placement:"top",color:"#000",overlayStyle:{maxWidth:340},overlayInnerStyle:{fontSize:12,color:"#999"},children:[" ",C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(_=>({diffExpanded:!_.diffExpanded})),children:["Body Diff JSON ",C.jsx(Li,{doc:"BodyDiffJSON"})," ",this.state.diffExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]})]}),this.state.diffExpanded&&C.jsx(ao,{type:"secondary",children:"请求体大小减小,可能使用了 /clear、/compact 或 session 发生了变化"})]});else{const _=zi(this.computeDiff(x.body,t.body));_&&(this._lastDiffResult=_,l=C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(va,{title:this.state.diffTooltipDismissed?null:C.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[C.jsx("span",{style:{flex:1},children:"为了避免看冗长的全文,所以为大家简化���示了 MainAgent 的增量部分,通常只有 message 增加"}),C.jsx(gi,{style:{cursor:"pointer",fontSize:10,marginTop:2,flexShrink:0},onClick:R=>{R.stopPropagation(),this.dismissDiffTooltip()}})]}),placement:"top",color:"#000",overlayStyle:{maxWidth:340},overlayInnerStyle:{fontSize:12,color:"#999"},children:[" ",C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(R=>({diffExpanded:!R.diffExpanded})),children:["Body Diff JSON ",C.jsx(Li,{doc:"BodyDiffJSON"})," ",this.state.diffExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]}),this.state.diffExpanded&&C.jsxs(Ma,{size:"small",style:{marginLeft:"auto"},children:[C.jsx(br,{size:"small",icon:this.state.bodyViewMode.diff==="json"?C.jsx(tg,{}):C.jsx(gg,{}),onClick:()=>this.toggleBodyViewMode("diff"),children:this.state.bodyViewMode.diff==="json"?"Text":"JSON"}),C.jsx(br,{size:"small",icon:C.jsx(ec,{}),onClick:()=>this.copyBody("diff"),children:"复制"})]})]})]}),this.state.diffExpanded&&C.jsx(C.Fragment,{children:this.state.bodyViewMode.diff==="json"?C.jsx(Qd,{data:_,defaultExpand:"all"}):C.jsx("pre",{className:Wt.rawTextPre,children:JSON.stringify(_,null,2)})})]}))}}}const c=pz(t.body),u=gz(t.body),f=[{key:"request",label:"Request",children:C.jsxs("div",{className:Wt.tabContent,children:[C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(x=>({requestHeadersExpanded:!x.requestHeadersExpanded})),children:["Headers ",this.state.requestHeadersExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]}),this.state.requestHeadersExpanded&&this.renderHeaders(t.headers)]}),l,C.jsxs("div",{children:[C.jsxs("div",{className:Wt.bodyHeader,children:[C.jsx(ao,{strong:!0,className:Wt.bodyLabel,children:"Body"}),C.jsxs(Ma,{size:"small",children:[(c||u)&&C.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[C.jsx("span",{style:{color:"#888",fontSize:12,fontFamily:"monospace"},children:"system-reminder:"}),C.jsx(Yi,{size:"small",className:Wt.reminderSelect,placeholder:"filter",value:this.state.reminderFilters||void 0,onChange:x=>this.setState({reminderFilters:x||null}),options:[{label:"CLAUDE.md",value:"claudeMd",disabled:!c},{label:"Skills",value:"skills",disabled:!u}],popupMatchSelectWidth:!1,allowClear:!0})]}),C.jsx(br,{size:"small",icon:this.state.bodyViewMode.request==="json"?C.jsx(tg,{}):C.jsx(gg,{}),onClick:()=>this.toggleBodyViewMode("request"),children:this.state.bodyViewMode.request==="json"?"Text":"JSON"}),C.jsx(br,{size:"small",icon:C.jsx(ec,{}),onClick:()=>this.copyBody("request"),children:"复制"})]})]}),this.renderBody(t.body,"request")]})]})},{key:"response",label:"Response",children:C.jsx("div",{className:Wt.tabContent,children:t.response?C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(x=>({responseHeadersExpanded:!x.responseHeadersExpanded})),children:["Headers ",this.state.responseHeadersExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]}),this.state.responseHeadersExpanded&&this.renderHeaders(t.response.headers)]}),C.jsxs("div",{children:[C.jsxs("div",{className:Wt.bodyHeader,children:[C.jsx(ao,{strong:!0,className:Wt.bodyLabel,children:"Body"}),C.jsxs(Ma,{size:"small",children:[C.jsx(br,{size:"small",icon:this.state.bodyViewMode.response==="json"?C.jsx(tg,{}):C.jsx(gg,{}),onClick:()=>this.toggleBodyViewMode("response"),children:this.state.bodyViewMode.response==="json"?"Text":"JSON"}),C.jsx(br,{size:"small",icon:C.jsx(ec,{}),onClick:()=>this.copyBody("response"),children:"复制"})]})]}),this.renderBody(t.response.body,"response")]})]}):C.jsx(lo,{description:"响应数据未捕获"})})},{key:"context",label:"Context",children:C.jsx("div",{className:Wt.tabContent,style:{height:"calc(100vh - 220px)",minHeight:400},children:C.jsx(aV,{body:t.body,response:(h=t.response)==null?void 0:h.body})})}],m=(b=(v=t.response)==null?void 0:v.body)==null?void 0:b.usage,g=m?(()=>{const x=m.input_tokens||0,S=m.output_tokens||0,E=m.cache_creation_input_tokens||0,w=m.cache_read_input_tokens||0,_=x+E+w,R=_>0?(w/_*100).toFixed(1):"0.0";return{input:_,output:S,cacheCreate:E,cacheRead:w,hitRate:R}})():null;return C.jsxs("div",{className:Wt.container,children:[C.jsxs("div",{className:Wt.urlSection,children:[C.jsxs("div",{className:Wt.urlLeft,children:[C.jsx(kV,{className:Wt.urlText,ellipsis:{rows:2,expandable:!0},children:t.url}),C.jsxs(Ma,{size:"small",wrap:!0,children:[C.jsx(So,{color:t.method==="POST"?"blue":"green",children:t.method}),C.jsxs(ao,{type:"secondary",className:Wt.metaText,children:["🕐 ",o]}),t.duration&&C.jsxs(ao,{type:"secondary",className:Wt.metaText,children:["⏱️ ",t.duration,"ms"]}),t.response&&C.jsxs(So,{color:i?"success":"error",children:["HTTP ",t.response.status]})]})]}),g&&C.jsx("div",{className:Wt.tokenStatsBox,children:C.jsxs("div",{className:Wt.tokenGrid,children:[C.jsxs("div",{className:Wt.tokenRows,children:[C.jsxs("div",{className:Wt.tokenRow,children:[C.jsx("span",{className:Wt.tokenLabel,children:"Token"}),C.jsxs("span",{className:Wt.tokenTd,children:["input: ",hr(g.input)]}),C.jsxs("span",{className:Wt.tokenTd,children:["output: ",hr(g.output)]})]}),C.jsxs("div",{className:`${Wt.tokenRow} ${Wt.tokenRowBorder}`,children:[C.jsx("span",{className:Wt.tokenLabel,children:"Cache"}),C.jsxs("span",{className:Wt.tokenTd,children:["create: ",hr(g.cacheCreate)]}),C.jsxs("span",{className:Wt.tokenTd,children:["read: ",hr(g.cacheRead)]})]})]}),C.jsxs("div",{className:Wt.tokenHitRate,children:[C.jsxs("div",{children:[g.hitRate,"%"]}),C.jsx("div",{className:Wt.tokenHitRateLabel,children:"命中率"})]})]})})]}),C.jsx(yE,{activeKey:n,onChange:r,items:f,size:"small"})]})}}const AV="_resizer_yamj2_1",LV={resizer:AV};class BV extends Q.Component{constructor(t){super(t),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this)}handleMouseDown(t){t.preventDefault(),document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(t){this.props.onResize&&this.props.onResize(t.clientX)}handleMouseUp(){document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}componentWillUnmount(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}render(){return C.jsx("div",{onMouseDown:this.handleMouseDown,className:LV.resizer})}}const zV="_guideContainer_1vqkk_1",DV="_guideContent_1vqkk_9",FV="_guideTitle_1vqkk_14",HV="_mainContainer_1vqkk_61",VV="_leftPanel_1vqkk_67",WV="_leftPanelHeader_1vqkk_76",UV="_leftPanelCount_1vqkk_85",GV="_leftPanelBody_1vqkk_91",qV="_rightPanel_1vqkk_96",Ia={guideContainer:zV,guideContent:DV,guideTitle:FV,mainContainer:HV,leftPanel:VV,leftPanelHeader:WV,leftPanelCount:UV,leftPanelBody:GV,rightPanel:qV};function KV({requests:e,selectedIndex:t,currentTab:n,scrollCenter:r,onSelectRequest:o,onScrollDone:i,onTabChange:l,onViewInChat:c,expandDiff:u,leftPanelWidth:f,onResize:m,onBackToTeam:g}){const h=t!==null?e[t]:null;return console.log("[RawView] requests.length:",e.length),e.length===0?C.jsx("div",{className:Ia.guideContainer,children:C.jsx("div",{className:Ia.guideContent,children:C.jsx("h2",{className:Ia.guideTitle,children:"无数据"})})}):C.jsxs("div",{className:Ia.mainContainer,children:[C.jsxs("div",{className:Ia.leftPanel,style:{width:f},children:[C.jsxs("div",{className:Ia.leftPanelHeader,children:[C.jsx(br,{type:"text",size:"small",onClick:g,style:{marginRight:8},children:"← 监控"}),C.jsx("span",{children:"请求列表"}),C.jsx("span",{className:Ia.leftPanelCount,children:`总请求数: ${e.length}`})]}),C.jsx("div",{className:Ia.leftPanelBody,children:C.jsx(MF,{requests:e,selectedIndex:t,scrollCenter:r,onSelect:o,onScrollDone:i})})]}),C.jsx(BV,{onResize:m}),C.jsx("div",{className:Ia.rightPanel,children:C.jsx(jV,{request:h,requests:e,selectedIndex:t,currentTab:n,onTabChange:l,onViewInChat:c,expandDiff:u})})]})}const XV=["system-reminder","local-command-caveat","project-reminder","important-instruction-reminders","file-modified-reminder","todo-reminder","user-prompt-submit-hook","local-command-stdout","command-name","task-notification","environment_details","context"];function YV(e){if(!e)return{segments:[]};const t=new RegExp("<("+XV.join("|")+")\\b[^>]*>([\\s\\S]*?)</\\1>","gi"),n=[];let r=0,o;for(;(o=t.exec(e))!==null;){if(o.index>r){const i=e.slice(r,o.index).trim();i&&n.push({type:"text",content:i})}n.push({type:"system-tag",tag:o[1],content:o[2].trim()}),r=o.index+o[0].length}if(r<e.length){const i=e.slice(r).trim();i&&n.push({type:"text",content:i})}return{segments:n}}function QV(e){const{segments:t}=YV(e);return t.length===0?{segments:[]}:{segments:t}}class ZV{diff(t,n,r={}){let o;typeof r=="function"?(o=r,r={}):"callback"in r&&(o=r.callback);const i=this.castInput(t,r),l=this.castInput(n,r),c=this.removeEmpty(this.tokenize(i,r)),u=this.removeEmpty(this.tokenize(l,r));return this.diffWithOptionsObj(c,u,r,o)}diffWithOptionsObj(t,n,r,o){var i;const l=w=>{if(w=this.postProcess(w,r),o){setTimeout(function(){o(w)},0);return}else return w},c=n.length,u=t.length;let f=1,m=c+u;r.maxEditLength!=null&&(m=Math.min(m,r.maxEditLength));const g=(i=r.timeout)!==null&&i!==void 0?i:1/0,h=Date.now()+g,v=[{oldPos:-1,lastComponent:void 0}];let b=this.extractCommon(v[0],n,t,0,r);if(v[0].oldPos+1>=u&&b+1>=c)return l(this.buildValues(v[0].lastComponent,n,t));let x=-1/0,S=1/0;const E=()=>{for(let w=Math.max(x,-f);w<=Math.min(S,f);w+=2){let _;const R=v[w-1],N=v[w+1];R&&(v[w-1]=void 0);let O=!1;if(N){const P=N.oldPos-w;O=N&&0<=P&&P<c}const I=R&&R.oldPos+1<u;if(!O&&!I){v[w]=void 0;continue}if(!I||O&&R.oldPos<N.oldPos?_=this.addToPath(N,!0,!1,0,r):_=this.addToPath(R,!1,!0,1,r),b=this.extractCommon(_,n,t,w,r),_.oldPos+1>=u&&b+1>=c)return l(this.buildValues(_.lastComponent,n,t))||!0;v[w]=_,_.oldPos+1>=u&&(S=Math.min(S,w-1)),b+1>=c&&(x=Math.max(x,w+1))}f++};if(o)(function w(){setTimeout(function(){if(f>m||Date.now()>h)return o(void 0);E()||w()},0)})();else for(;f<=m&&Date.now()<=h;){const w=E();if(w)return w}}addToPath(t,n,r,o,i){const l=t.lastComponent;return l&&!i.oneChangePerToken&&l.added===n&&l.removed===r?{oldPos:t.oldPos+o,lastComponent:{count:l.count+1,added:n,removed:r,previousComponent:l.previousComponent}}:{oldPos:t.oldPos+o,lastComponent:{count:1,added:n,removed:r,previousComponent:l}}}extractCommon(t,n,r,o,i){const l=n.length,c=r.length;let u=t.oldPos,f=u-o,m=0;for(;f+1<l&&u+1<c&&this.equals(r[u+1],n[f+1],i);)f++,u++,m++,i.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return m&&!i.oneChangePerToken&&(t.lastComponent={count:m,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=u,f}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){const n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){const o=[];let i;for(;t;)o.push(t),i=t.previousComponent,delete t.previousComponent,t=i;o.reverse();const l=o.length;let c=0,u=0,f=0;for(;c<l;c++){const m=o[c];if(m.removed)m.value=this.join(r.slice(f,f+m.count)),f+=m.count;else{if(!m.added&&this.useLongestToken){let g=n.slice(u,u+m.count);g=g.map(function(h,v){const b=r[f+v];return b.length>h.length?b:h}),m.value=this.join(g)}else m.value=this.join(n.slice(u,u+m.count));u+=m.count,m.added||(f+=m.count)}}return o}}class JV extends ZV{constructor(){super(...arguments),this.tokenize=nW}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
|
|
428
|
+
`),t.push({type:"markdown",text:o});const i=(e==null?void 0:e.input_schema)||(e==null?void 0:e.parameters)||null;return i&&t.push({type:"json",label:"Parameters",data:i}),t}function ZH(e){var t;if(typeof e=="string")return e.slice(0,60).replace(/\n/g," ");if(Array.isArray(e)){for(const n of e)if((n==null?void 0:n.type)==="text"&&((t=n.text)!=null&&t.trim()))return n.text.trim().slice(0,60).replace(/\n/g," ")}return""}function JH(e){var r;const t=[];let n=0;for(;n<e.length;){const o=e[n];if((o==null?void 0:o.role)!=="user"){n++;continue}const i=((r=e[n+1])==null?void 0:r.role)==="assistant"?e[n+1]:null;t.push({id:`turn__${n}`,isTurn:!0,turnIndex:t.length,timestamp:o._timestamp||null,assistantTimestamp:(i==null?void 0:i._timestamp)||null,userBlocks:Ah(o==null?void 0:o.content),assistantBlocks:i?Ah(i.content):null,preview:ZH(o==null?void 0:o.content)}),n+=i?2:1}return t}function Lh(e){try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}catch{return null}}function eV({text:e,compact:t}){const n=di(e);return t?C.jsx("div",{className:yt.textBlockCompact,children:C.jsx("div",{className:`chat-md ${yt.markdownBody}`,dangerouslySetInnerHTML:{__html:n}})}):C.jsxs("div",{className:yt.textBlock,children:[C.jsx("div",{className:yt.textBlockBar,children:C.jsx("span",{className:`${yt.blockTag} ${yt.blockTagText}`,children:"text"})}),C.jsx("div",{className:`chat-md ${yt.textBlockBody}`,dangerouslySetInnerHTML:{__html:n}})]})}function tV({block:e}){const[t,n]=d.useState(!0),r=e.text.length>60?e.text.slice(0,60).replace(/\n/g," ")+"…":e.text.replace(/\n/g," "),o=di(e.text);return C.jsxs("div",{className:yt.thinkingBlock,children:[C.jsxs("div",{className:yt.thinkingHeader,onClick:()=>n(i=>!i),children:[t?C.jsx(Ta,{className:yt.arrow}):C.jsx(Co,{className:yt.arrow}),C.jsx("span",{className:`${yt.blockTag} ${yt.blockTagThinking}`,children:"thinking"}),!t&&C.jsx("span",{className:yt.thinkingPreview,children:r})]}),t&&C.jsx("div",{className:yt.thinkingBody,children:C.jsx("div",{className:`chat-md ${yt.markdownBody}`,dangerouslySetInnerHTML:{__html:o}})})]})}function Zd({blocks:e,compact:t}){return!e||e.length===0?null:C.jsx(C.Fragment,{children:e.map((n,r)=>C.jsx(nV,{block:n,compact:t},r))})}function nV({block:e,compact:t}){var n;return e.type==="separator"?C.jsx("hr",{className:yt.blockSeparator}):e.type==="markdown"?(n=e.text)!=null&&n.trim()?C.jsx(eV,{text:e.text,compact:t}):null:e.type==="thinking"?C.jsx(tV,{block:e}):e.type==="tool_use"?C.jsxs("div",{className:yt.toolBlock,children:[C.jsxs("div",{className:yt.toolBlockHeader,children:[C.jsx("span",{className:yt.blockTag,children:"tool_use"}),C.jsx("span",{className:yt.toolName,children:e.name}),e.id&&C.jsx("span",{className:yt.toolId,children:e.id})]}),C.jsx("div",{className:yt.toolBlockBody,children:C.jsx(Qd,{data:e.input,defaultExpand:"root"})})]}):e.type==="tool_result"?C.jsxs("div",{className:`${yt.toolBlock} ${e.is_error?yt.toolBlockError:yt.toolBlockResult}`,children:[C.jsxs("div",{className:yt.toolBlockHeader,children:[C.jsx("span",{className:`${yt.blockTag} ${e.is_error?yt.blockTagError:yt.blockTagResult}`,children:"tool_result"}),e.tool_use_id&&C.jsx("span",{className:yt.toolId,children:e.tool_use_id}),e.is_error&&C.jsx("span",{className:yt.errorLabel,children:"error"})]}),C.jsx("div",{className:yt.toolBlockBody,children:C.jsx(Zd,{blocks:e.content,compact:!0})})]}):e.type==="json"?C.jsxs("div",{className:yt.jsonBlock,children:[e.label&&C.jsx("div",{className:yt.jsonBlockLabel,children:e.label}),C.jsx(Qd,{data:e.data,defaultExpand:"root"})]}):null}function rV({turn:e}){const t=e.timestamp?Lh(e.timestamp):null,n=e.assistantTimestamp?Lh(e.assistantTimestamp):null;return C.jsxs("div",{children:[C.jsxs("div",{className:yt.roleHeader,children:[C.jsx("span",{className:`${yt.roleBadge} ${yt.role_user}`,children:"user"}),C.jsx("span",{className:yt.roleLabel,children:`Turn ${e.turnIndex+1}`}),t&&C.jsx("span",{className:yt.contentTime,children:t})]}),C.jsx(Zd,{blocks:e.userBlocks}),e.assistantBlocks&&C.jsxs(C.Fragment,{children:[C.jsx("div",{className:yt.turnDivider}),C.jsxs("div",{className:yt.roleHeader,children:[C.jsx("span",{className:`${yt.roleBadge} ${yt.role_assistant}`,children:"assistant"}),n&&C.jsx("span",{className:yt.contentTime,children:n})]}),C.jsx(Zd,{blocks:e.assistantBlocks})]})]})}function oV({title:e,items:t,historyItems:n,onSelect:r,selectedId:o}){const[i,l]=d.useState(!0),[c,u]=d.useState(!1),f=t.length+((n==null?void 0:n.length)||0);function m(g){const h=o===g.id;return C.jsxs("div",{className:`${yt.item} ${h?yt.itemActive:""}`,onClick:()=>r(g),children:[C.jsxs("div",{className:yt.itemContent,children:[C.jsx("span",{className:yt.itemLabel,children:g.label}),g.sublabel&&!h&&C.jsx("div",{className:yt.itemSublabel,children:g.sublabel})]}),g.time&&C.jsx("span",{className:yt.itemTime,children:g.time})]},g.id)}return C.jsxs("div",{className:yt.section,children:[C.jsxs("div",{className:yt.sectionHeader,onClick:()=>l(g=>!g),children:[i?C.jsx(Ta,{className:yt.arrow}):C.jsx(Co,{className:yt.arrow}),C.jsx("span",{className:yt.sectionTitle,children:e}),C.jsx("span",{className:yt.sectionCount,children:f})]}),i&&C.jsxs("div",{className:yt.sectionBody,children:[n&&n.length>0&&C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:yt.historyToggle,onClick:()=>u(g=>!g),children:[c?C.jsx(Ta,{className:yt.arrow}):C.jsx(Co,{className:yt.arrow}),C.jsxs("span",{className:yt.historyToggleLabel,children:["历史"," (",n.length,")"]})]}),c&&n.map(m)]}),t.map(m)]})]})}function aV({body:e,response:t}){const[n,r]=d.useState(null),o=d.useMemo(()=>{if(!Array.isArray(e==null?void 0:e.messages))return[];const u=JH(e.messages);if(u.length===0)return u;const f=u[u.length-1],m=t!=null&&t.content?Ah(t.content):null;return[...u.slice(0,-1),{...f,assistantBlocks:m??f.assistantBlocks}]},[e,t]);if(d.useEffect(()=>{o.length>0&&n===null&&r(o[o.length-1])},[o.length]),!e||typeof e!="object")return C.jsx("div",{className:yt.emptyWrap,children:C.jsx(lo,{description:"无数据"})});const i=[],l=YH(e.system);if(l!=null&&i.push({key:"system",title:"系统提示",items:[{id:"system__0",label:"系统提示",blocks:l}]}),o.length>0){const u=h=>({...h,label:`轮次 ${h.turnIndex+1}`,time:h.timestamp?Lh(h.timestamp):null,sublabel:h.preview||void 0}),f=h=>({...h,label:"当前轮次",sublabel:h.preview||void 0}),m=o.slice(0,-1).map(u),g=f(o[o.length-1]);i.push({key:"messages",title:"消息",historyItems:m.length>0?m:void 0,items:[g]})}if(Array.isArray(e.tools)&&e.tools.length>0&&i.push({key:"tools",title:"工具",items:e.tools.map((u,f)=>({id:`tool__${f}`,label:(u==null?void 0:u.name)||`Tool ${f}`,blocks:QH(u)}))}),i.length===0)return C.jsx("div",{className:yt.emptyWrap,children:C.jsx(lo,{description:"无字段"})});const c=n!=null&&n.isTurn?o.find(u=>u.id===n.id)??null:n;return C.jsxs("div",{className:yt.root,children:[C.jsx("div",{className:yt.sidebar,children:i.map(u=>C.jsx(oV,{title:u.title,items:u.items,historyItems:u.historyItems,selectedId:c==null?void 0:c.id,onSelect:f=>r(f)},u.key))}),C.jsx("div",{className:yt.content,children:c==null?C.jsx("div",{className:yt.contentEmpty,children:C.jsx(KH,{type:"secondary",children:"选择 Prompt"})}):C.jsx("div",{className:yt.contentInner,children:c.isTurn?C.jsx(rV,{turn:c}):C.jsxs(C.Fragment,{children:[c.role&&C.jsxs("div",{className:yt.roleHeader,children:[C.jsx("span",{className:`${yt.roleBadge} ${yt[`role_${c.role}`]||""}`,children:c.role}),C.jsx("span",{className:yt.roleLabel,children:c.label})]}),C.jsx(Zd,{blocks:c.blocks})]})},c.id)})]})}const iV="_container_i6t4e_1",sV="_emptyState_i6t4e_9",lV="_urlSection_i6t4e_16",cV="_urlLeft_i6t4e_23",uV="_tokenStatsBox_i6t4e_28",dV="_tokenGrid_i6t4e_35",fV="_tokenRows_i6t4e_45",mV="_tokenRow_i6t4e_45",pV="_tokenRowBorder_i6t4e_53",gV="_tokenLabel_i6t4e_57",hV="_tokenTd_i6t4e_64",vV="_tokenHitRate_i6t4e_73",bV="_tokenHitRateLabel_i6t4e_86",yV="_urlText_i6t4e_96",xV="_metaText_i6t4e_103",SV="_headersContainer_i6t4e_107",CV="_headerRow_i6t4e_111",wV="_headerKey_i6t4e_117",EV="_headerValue_i6t4e_122",_V="_streamingBox_i6t4e_127",$V="_rawTextPre_i6t4e_140",NV="_tabContent_i6t4e_153",RV="_bodyLabel_i6t4e_161",OV="_bodyHeader_i6t4e_165",IV="_diffSection_i6t4e_172",TV="_diffToggle_i6t4e_176",MV="_diffIcon_i6t4e_182",PV="_reminderSelect_i6t4e_208",Wt={container:iV,emptyState:sV,urlSection:lV,urlLeft:cV,tokenStatsBox:uV,tokenGrid:dV,tokenRows:fV,tokenRow:mV,tokenRowBorder:pV,tokenLabel:gV,tokenTd:hV,tokenHitRate:vV,tokenHitRateLabel:bV,urlText:yV,metaText:xV,headersContainer:SV,headerRow:CV,headerKey:wV,headerValue:EV,streamingBox:_V,rawTextPre:$V,tabContent:NV,bodyLabel:RV,bodyHeader:OV,diffSection:IV,diffToggle:TV,diffIcon:MV,reminderSelect:PV},{Text:ao,Paragraph:kV}=Ho;class jV extends Q.Component{constructor(t){super(t),this.state={bodyViewMode:{request:"json",response:"json",diff:"json"},diffExpanded:!1,requestHeadersExpanded:!1,responseHeadersExpanded:!1,diffTooltipDismissed:!1,reminderFilters:null}}componentDidMount(){fetch("/api/preferences").then(t=>t.json()).then(t=>{t.diffTooltipDismissed&&this.setState({diffTooltipDismissed:!0})}).catch(()=>{})}dismissDiffTooltip(){this.setState({diffTooltipDismissed:!0}),fetch("/api/preferences",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({diffTooltipDismissed:!0})}).catch(()=>{})}shouldComponentUpdate(t,n){if(t.request!==this.props.request){const r=ka(t.request);this.setState({diffExpanded:r&&!!t.expandDiff,requestHeadersExpanded:!1,responseHeadersExpanded:!1,reminderFilters:null})}return t.request!==this.props.request||t.currentTab!==this.props.currentTab||t.onTabChange!==this.props.onTabChange||t.selectedIndex!==this.props.selectedIndex||t.expandDiff!==this.props.expandDiff||n.bodyViewMode!==this.state.bodyViewMode||n.diffExpanded!==this.state.diffExpanded||n.requestHeadersExpanded!==this.state.requestHeadersExpanded||n.responseHeadersExpanded!==this.state.responseHeadersExpanded||n.diffTooltipDismissed!==this.state.diffTooltipDismissed||n.reminderFilters!==this.state.reminderFilters}toggleBodyViewMode(t){this.setState(n=>({bodyViewMode:{...n.bodyViewMode,[t]:n.bodyViewMode[t]==="json"?"text":"json"}}))}copyBody(t){var l;const{request:n}=this.props;if(!n)return;let r;if(t==="diff"?r=this._lastDiffResult:r=t==="request"?n.body:(l=n.response)==null?void 0:l.body,r==null)return;const o=typeof r=="object"?zi(r):r,i=typeof o=="string"?o:JSON.stringify(o,null,2);navigator.clipboard.writeText(i).then(()=>Av.success("复制成功"))}renderHeaders(t){return!t||Object.keys(t).length===0?C.jsx(ao,{type:"secondary",children:"无 Headers"}):C.jsx("div",{className:Wt.headersContainer,children:Object.entries(t).map(([n,r])=>C.jsxs("div",{className:Wt.headerRow,children:[C.jsx(ao,{code:!0,className:Wt.headerKey,children:n}),n==="authorization"&&C.jsx(Li,{doc:"TranslateContextPollution"}),C.jsx(ao,{type:"secondary",className:Wt.headerValue,children:String(r)})]},n))})}getRequestExpandNode(t,n){if(n!=="request"||!t||typeof t!="object")return;const{request:r,requests:o,selectedIndex:i}=this.props;if(!r)return;const l=o&&i!=null?o[i+1]:null,{type:c}=yc(r,l);let u=null;if(this.state.reminderFilters==="claudeMd"&&Array.isArray(t.messages)){u=new Set,u.add(t.messages);for(const g of t.messages){if(!g||typeof g!="object")continue;const h=g.content;if(typeof h=="string")Wd(h)&&u.add(g);else if(Array.isArray(h)){let v=!1;for(const b of h)b&&b.type==="text"&&Wd(b.text)&&(u.add(b),v=!0);v&&(u.add(g),u.add(h))}}}let f=null;if(this.state.reminderFilters==="skills"&&Array.isArray(t.messages)){f=new Set,f.add(t.messages);for(const g of t.messages){if(!g||typeof g!="object")continue;const h=g.content;if(typeof h=="string")Ud(h)&&f.add(g);else if(Array.isArray(h)){let v=!1;for(const b of h)b&&b.type==="text"&&Ud(b.text)&&(f.add(b),v=!0);v&&(f.add(g),f.add(h))}}}const m=u||f;if(c==="Preflight"){const g=new Set,h=v=>{v&&typeof v=="object"&&(g.add(v),Array.isArray(v)?v.forEach(h):Object.values(v).forEach(h))};return Array.isArray(t.messages)&&h(t.messages),Array.isArray(t.system)&&t.system.length>=3&&h(t.system[2]),(v,b,x)=>!!(v<2||g.has(b)||m&&m.has(b)||v===1&&x==="system")}if(c==="MainAgent"&&Array.isArray(t.messages)&&t.messages.length===1){const g=t.messages[0],h=g&&Array.isArray(g.content)?g.content:null,v=h&&h.length>0?h[h.length-1]:null,b=new Set,x=S=>{S&&typeof S=="object"&&(b.add(S),Array.isArray(S)?S.forEach(x):Object.values(S).forEach(x))};return v&&x(v),b.add(t.messages),g&&typeof g=="object"&&b.add(g),h&&b.add(h),(S,E,w)=>!!(S<2||b.has(E)||m&&m.has(E))}if(m)return(g,h,v)=>!!(g<2||m.has(h))}renderBody(t,n){const{bodyViewMode:r}=this.state;if(t==null)return C.jsx(ao,{type:"secondary",children:"无 Body"});if(typeof t=="string"&&t.includes("Streaming Response"))return C.jsx("div",{className:Wt.streamingBox,children:C.jsx(ao,{type:"secondary",children:"流式响应 — 此请求使用了 SSE 流式传输,响应内容无法完整捕获。"})});const o=typeof t=="object"?zi(t):t,i=r[n]==="json",l=this.getRequestExpandNode(o,n);return C.jsx("div",{children:i?C.jsx(Qd,{data:o,defaultExpand:n==="response"?"all":"root",expandNode:l}):C.jsx("pre",{className:Wt.rawTextPre,children:typeof o=="string"?o:JSON.stringify(o,null,2)})})}getPrevMainAgentRequest(){const{requests:t,selectedIndex:n}=this.props;if(!t||n==null)return null;for(let r=n-1;r>=0;r--)if(ka(t[r]))return t[r];return null}computeDiff(t,n){if(t==null||n==null||typeof t!="object"||typeof n!="object")return null;const r={},o=new Set([...Object.keys(t),...Object.keys(n)]);for(const i of o)if(!i.startsWith("_"))if(!(i in t))r[i]=n[i];else if(i in n){const l=JSON.stringify(t[i]),c=JSON.stringify(n[i]);l!==c&&(i==="messages"&&Array.isArray(t[i])&&Array.isArray(n[i])&&n[i].length>t[i].length?r[i]=n[i].slice(t[i].length):r[i]=n[i])}else continue;return Object.keys(r).length?r:null}render(){var h,v,b;const{request:t,currentTab:n,onTabChange:r}=this.props;if(!t)return C.jsx("div",{className:Wt.emptyState,children:C.jsx(lo,{description:"选择一个请求查看详情"})});const o=new Date(t.timestamp).toLocaleString("zh-CN"),i=t.response&&t.response.status<400;let l=null;if(ka(t)){const x=this.getPrevMainAgentRequest();if(x){const S=JSON.stringify(t.body).length,E=JSON.stringify(x.body).length;if(S<E)l=C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(va,{title:this.state.diffTooltipDismissed?null:C.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[C.jsx("span",{style:{flex:1},children:"为了避免看冗长的全文,所以为大家简化���示了 MainAgent 的增量部分,通常只有 message 增加"}),C.jsx(gi,{style:{cursor:"pointer",fontSize:10,marginTop:2,flexShrink:0},onClick:_=>{_.stopPropagation(),this.dismissDiffTooltip()}})]}),placement:"top",color:"#000",overlayStyle:{maxWidth:340},overlayInnerStyle:{fontSize:12,color:"#999"},children:[" ",C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(_=>({diffExpanded:!_.diffExpanded})),children:["Body Diff JSON ",C.jsx(Li,{doc:"BodyDiffJSON"})," ",this.state.diffExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]})]}),this.state.diffExpanded&&C.jsx(ao,{type:"secondary",children:"请求体大小减小,可能使用了 /clear、/compact 或 session 发生了变化"})]});else{const _=zi(this.computeDiff(x.body,t.body));_&&(this._lastDiffResult=_,l=C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(va,{title:this.state.diffTooltipDismissed?null:C.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[C.jsx("span",{style:{flex:1},children:"为了避免看冗长的全文,所以为大家简化���示了 MainAgent 的增量部分,通常只有 message 增加"}),C.jsx(gi,{style:{cursor:"pointer",fontSize:10,marginTop:2,flexShrink:0},onClick:R=>{R.stopPropagation(),this.dismissDiffTooltip()}})]}),placement:"top",color:"#000",overlayStyle:{maxWidth:340},overlayInnerStyle:{fontSize:12,color:"#999"},children:[" ",C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(R=>({diffExpanded:!R.diffExpanded})),children:["Body Diff JSON ",C.jsx(Li,{doc:"BodyDiffJSON"})," ",this.state.diffExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]}),this.state.diffExpanded&&C.jsxs(Ma,{size:"small",style:{marginLeft:"auto"},children:[C.jsx(br,{size:"small",icon:this.state.bodyViewMode.diff==="json"?C.jsx(tg,{}):C.jsx(gg,{}),onClick:()=>this.toggleBodyViewMode("diff"),children:this.state.bodyViewMode.diff==="json"?"Text":"JSON"}),C.jsx(br,{size:"small",icon:C.jsx(ec,{}),onClick:()=>this.copyBody("diff"),children:"复制"})]})]})]}),this.state.diffExpanded&&C.jsx(C.Fragment,{children:this.state.bodyViewMode.diff==="json"?C.jsx(Qd,{data:_,defaultExpand:"all"}):C.jsx("pre",{className:Wt.rawTextPre,children:JSON.stringify(_,null,2)})})]}))}}}const c=pz(t.body),u=gz(t.body),f=[{key:"request",label:"Request",children:C.jsxs("div",{className:Wt.tabContent,children:[C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(x=>({requestHeadersExpanded:!x.requestHeadersExpanded})),children:["Headers ",this.state.requestHeadersExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]}),this.state.requestHeadersExpanded&&this.renderHeaders(t.headers)]}),l,C.jsxs("div",{children:[C.jsxs("div",{className:Wt.bodyHeader,children:[C.jsx(ao,{strong:!0,className:Wt.bodyLabel,children:"Body"}),C.jsxs(Ma,{size:"small",children:[(c||u)&&C.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[C.jsx("span",{style:{color:"#888",fontSize:12,fontFamily:"monospace"},children:"system-reminder:"}),C.jsx(Yi,{size:"small",className:Wt.reminderSelect,placeholder:"filter",value:this.state.reminderFilters||void 0,onChange:x=>this.setState({reminderFilters:x||null}),options:[{label:"CLAUDE.md",value:"claudeMd",disabled:!c},{label:"Skills",value:"skills",disabled:!u}],popupMatchSelectWidth:!1,allowClear:!0})]}),C.jsx(br,{size:"small",icon:this.state.bodyViewMode.request==="json"?C.jsx(tg,{}):C.jsx(gg,{}),onClick:()=>this.toggleBodyViewMode("request"),children:this.state.bodyViewMode.request==="json"?"Text":"JSON"}),C.jsx(br,{size:"small",icon:C.jsx(ec,{}),onClick:()=>this.copyBody("request"),children:"复制"})]})]}),this.renderBody(t.body,"request")]})]})},{key:"response",label:"Response",children:C.jsx("div",{className:Wt.tabContent,children:t.response?C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:Wt.diffSection,children:[C.jsxs(ao,{strong:!0,className:Wt.diffToggle,onClick:()=>this.setState(x=>({responseHeadersExpanded:!x.responseHeadersExpanded})),children:["Headers ",this.state.responseHeadersExpanded?C.jsx(Ta,{className:Wt.diffIcon}):C.jsx(Co,{className:Wt.diffIcon})]}),this.state.responseHeadersExpanded&&this.renderHeaders(t.response.headers)]}),C.jsxs("div",{children:[C.jsxs("div",{className:Wt.bodyHeader,children:[C.jsx(ao,{strong:!0,className:Wt.bodyLabel,children:"Body"}),C.jsxs(Ma,{size:"small",children:[C.jsx(br,{size:"small",icon:this.state.bodyViewMode.response==="json"?C.jsx(tg,{}):C.jsx(gg,{}),onClick:()=>this.toggleBodyViewMode("response"),children:this.state.bodyViewMode.response==="json"?"Text":"JSON"}),C.jsx(br,{size:"small",icon:C.jsx(ec,{}),onClick:()=>this.copyBody("response"),children:"复制"})]})]}),this.renderBody(t.response.body,"response")]})]}):C.jsx(lo,{description:"响应数据未捕获"})})},{key:"context",label:"Context",children:C.jsx("div",{className:Wt.tabContent,style:{height:"calc(100vh - 220px)",minHeight:400},children:C.jsx(aV,{body:t.body,response:(h=t.response)==null?void 0:h.body})})}],m=(b=(v=t.response)==null?void 0:v.body)==null?void 0:b.usage,g=m?(()=>{const x=m.input_tokens||0,S=m.output_tokens||0,E=m.cache_creation_input_tokens||0,w=m.cache_read_input_tokens||0,_=x+E+w,R=_>0?(w/_*100).toFixed(1):"0.0";return{input:_,output:S,cacheCreate:E,cacheRead:w,hitRate:R}})():null;return C.jsxs("div",{className:Wt.container,children:[C.jsxs("div",{className:Wt.urlSection,children:[C.jsxs("div",{className:Wt.urlLeft,children:[C.jsx(kV,{className:Wt.urlText,ellipsis:{rows:2,expandable:!0},children:t.url}),C.jsxs(Ma,{size:"small",wrap:!0,children:[C.jsx(So,{color:t.method==="POST"?"blue":"green",children:t.method}),C.jsxs(ao,{type:"secondary",className:Wt.metaText,children:["🕐 ",o]}),t.duration&&C.jsxs(ao,{type:"secondary",className:Wt.metaText,children:["⏱️ ",t.duration,"ms"]}),t.response&&C.jsxs(So,{color:i?"success":"error",children:["HTTP ",t.response.status]})]})]}),g&&C.jsx("div",{className:Wt.tokenStatsBox,children:C.jsxs("div",{className:Wt.tokenGrid,children:[C.jsxs("div",{className:Wt.tokenRows,children:[C.jsxs("div",{className:Wt.tokenRow,children:[C.jsx("span",{className:Wt.tokenLabel,children:"Token"}),C.jsxs("span",{className:Wt.tokenTd,children:["input: ",hr(g.input)]}),C.jsxs("span",{className:Wt.tokenTd,children:["output: ",hr(g.output)]})]}),C.jsxs("div",{className:`${Wt.tokenRow} ${Wt.tokenRowBorder}`,children:[C.jsx("span",{className:Wt.tokenLabel,children:"Cache"}),C.jsxs("span",{className:Wt.tokenTd,children:["create: ",hr(g.cacheCreate)]}),C.jsxs("span",{className:Wt.tokenTd,children:["read: ",hr(g.cacheRead)]})]})]}),C.jsxs("div",{className:Wt.tokenHitRate,children:[C.jsxs("div",{children:[g.hitRate,"%"]}),C.jsx("div",{className:Wt.tokenHitRateLabel,children:"命中率"})]})]})})]}),C.jsx(yE,{activeKey:n,onChange:r,items:f,size:"small"})]})}}const AV="_resizer_yamj2_1",LV={resizer:AV};class BV extends Q.Component{constructor(t){super(t),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this)}handleMouseDown(t){t.preventDefault(),document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}handleMouseMove(t){this.props.onResize&&this.props.onResize(t.clientX)}handleMouseUp(){document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}componentWillUnmount(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}render(){return C.jsx("div",{onMouseDown:this.handleMouseDown,className:LV.resizer})}}const zV="_guideContainer_1vqkk_1",DV="_guideContent_1vqkk_9",FV="_guideTitle_1vqkk_14",HV="_mainContainer_1vqkk_61",VV="_leftPanel_1vqkk_67",WV="_leftPanelHeader_1vqkk_76",UV="_leftPanelCount_1vqkk_85",GV="_leftPanelBody_1vqkk_91",qV="_rightPanel_1vqkk_96",Ia={guideContainer:zV,guideContent:DV,guideTitle:FV,mainContainer:HV,leftPanel:VV,leftPanelHeader:WV,leftPanelCount:UV,leftPanelBody:GV,rightPanel:qV};function KV({requests:e,selectedIndex:t,currentTab:n,scrollCenter:r,onSelectRequest:o,onScrollDone:i,onTabChange:l,onViewInChat:c,expandDiff:u,leftPanelWidth:f,onResize:m,onBackToTeam:g}){const h=t!==null?e[t]:null;return console.log("[RawView] requests.length:",e.length),e.length===0?C.jsx("div",{className:Ia.guideContainer,children:C.jsx("div",{className:Ia.guideContent,children:C.jsx("h2",{className:Ia.guideTitle,children:"无数据"})})}):C.jsxs("div",{className:Ia.mainContainer,children:[C.jsxs("div",{className:Ia.leftPanel,style:{width:f},children:[C.jsxs("div",{className:Ia.leftPanelHeader,children:[C.jsx(br,{type:"text",size:"small",onClick:g,style:{marginRight:8},children:"← 监控"}),C.jsx("span",{children:"请求列表"}),C.jsx("span",{className:Ia.leftPanelCount,children:`总请求数: ${e.length}`})]}),C.jsx("div",{className:Ia.leftPanelBody,children:C.jsx(MF,{requests:e,selectedIndex:t,scrollCenter:r,onSelect:o,onScrollDone:i})})]}),C.jsx(BV,{onResize:m}),C.jsx("div",{className:Ia.rightPanel,children:C.jsx(jV,{request:h,requests:e,selectedIndex:t,currentTab:n,onTabChange:l,onViewInChat:c,expandDiff:u})})]})}const XV=["system-reminder","local-command-caveat","project-reminder","important-instruction-reminders","file-modified-reminder","todo-reminder","user-prompt-submit-hook","local-command-stdout","command-name","task-notification","environment_details","context"];function YV(e){if(!e)return{segments:[]};const t=new RegExp("<("+XV.join("|")+")\\b[^>]*>([\\s\\S]*?)</\\1>","gi"),n=[];let r=0,o;for(;(o=t.exec(e))!==null;){if(o.index>r){const i=e.slice(r,o.index).trim();i&&n.push({type:"text",content:i})}n.push({type:"system-tag",tag:o[1],content:o[2].trim()}),r=o.index+o[0].length}if(r<e.length){const i=e.slice(r).trim();i&&n.push({type:"text",content:i})}return{segments:n}}function QV(e){const{segments:t}=YV(e);return t.length===0?{segments:[]}:{segments:t}}class ZV{diff(t,n,r={}){let o;typeof r=="function"?(o=r,r={}):"callback"in r&&(o=r.callback);const i=this.castInput(t,r),l=this.castInput(n,r),c=this.removeEmpty(this.tokenize(i,r)),u=this.removeEmpty(this.tokenize(l,r));return this.diffWithOptionsObj(c,u,r,o)}diffWithOptionsObj(t,n,r,o){var i;const l=w=>{if(w=this.postProcess(w,r),o){setTimeout(function(){o(w)},0);return}else return w},c=n.length,u=t.length;let f=1,m=c+u;r.maxEditLength!=null&&(m=Math.min(m,r.maxEditLength));const g=(i=r.timeout)!==null&&i!==void 0?i:1/0,h=Date.now()+g,v=[{oldPos:-1,lastComponent:void 0}];let b=this.extractCommon(v[0],n,t,0,r);if(v[0].oldPos+1>=u&&b+1>=c)return l(this.buildValues(v[0].lastComponent,n,t));let x=-1/0,S=1/0;const E=()=>{for(let w=Math.max(x,-f);w<=Math.min(S,f);w+=2){let _;const R=v[w-1],N=v[w+1];R&&(v[w-1]=void 0);let O=!1;if(N){const P=N.oldPos-w;O=N&&0<=P&&P<c}const I=R&&R.oldPos+1<u;if(!O&&!I){v[w]=void 0;continue}if(!I||O&&R.oldPos<N.oldPos?_=this.addToPath(N,!0,!1,0,r):_=this.addToPath(R,!1,!0,1,r),b=this.extractCommon(_,n,t,w,r),_.oldPos+1>=u&&b+1>=c)return l(this.buildValues(_.lastComponent,n,t))||!0;v[w]=_,_.oldPos+1>=u&&(S=Math.min(S,w-1)),b+1>=c&&(x=Math.max(x,w+1))}f++};if(o)(function w(){setTimeout(function(){if(f>m||Date.now()>h)return o(void 0);E()||w()},0)})();else for(;f<=m&&Date.now()<=h;){const w=E();if(w)return w}}addToPath(t,n,r,o,i){const l=t.lastComponent;return l&&!i.oneChangePerToken&&l.added===n&&l.removed===r?{oldPos:t.oldPos+o,lastComponent:{count:l.count+1,added:n,removed:r,previousComponent:l.previousComponent}}:{oldPos:t.oldPos+o,lastComponent:{count:1,added:n,removed:r,previousComponent:l}}}extractCommon(t,n,r,o,i){const l=n.length,c=r.length;let u=t.oldPos,f=u-o,m=0;for(;f+1<l&&u+1<c&&this.equals(r[u+1],n[f+1],i);)f++,u++,m++,i.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return m&&!i.oneChangePerToken&&(t.lastComponent={count:m,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=u,f}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){const n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){const o=[];let i;for(;t;)o.push(t),i=t.previousComponent,delete t.previousComponent,t=i;o.reverse();const l=o.length;let c=0,u=0,f=0;for(;c<l;c++){const m=o[c];if(m.removed)m.value=this.join(r.slice(f,f+m.count)),f+=m.count;else{if(!m.added&&this.useLongestToken){let g=n.slice(u,u+m.count);g=g.map(function(h,v){const b=r[f+v];return b.length>h.length?b:h}),m.value=this.join(g)}else m.value=this.join(n.slice(u,u+m.count));u+=m.count,m.added||(f+=m.count)}}return o}}class JV extends ZV{constructor(){super(...arguments),this.tokenize=nW}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
|
|
429
429
|
`))&&(t=t.trim()),(!r.newlineIsToken||!n.includes(`
|
|
430
430
|
`))&&(n=n.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(t.endsWith(`
|
|
431
431
|
`)&&(t=t.slice(0,-1)),n.endsWith(`
|
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<title>Claude Code Viewer</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico?v=1">
|
|
8
8
|
<link rel="shortcut icon" href="/favicon.ico?v=1">
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-DA5iEoc6.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-DDdbZDlo.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
package/lib/updater.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
2
2
|
import { execSync } from 'node:child_process';
|
|
3
|
-
import { join } from 'node:path';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { dirname } from 'node:path';
|
|
@@ -14,8 +14,14 @@ const CACHE_FILE = join(CACHE_DIR, 'update-check.json');
|
|
|
14
14
|
const CC_SETTINGS_FILE = join(homedir(), '.claude', 'settings.json');
|
|
15
15
|
|
|
16
16
|
function getCurrentVersion() {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
try {
|
|
18
|
+
const pkgPath = resolve(__dirname, '..', 'package.json');
|
|
19
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
20
|
+
return pkg.version;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error('[CC Team Viewer] Failed to read package.json:', err.message);
|
|
23
|
+
return '0.0.0';
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
function parseVersion(ver) {
|
package/package.json
CHANGED
package/proxy/interceptor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// LLM Request Interceptor
|
|
2
2
|
// 拦截并记录所有Claude API请求
|
|
3
3
|
import './proxy-env.js';
|
|
4
|
-
import { appendFileSync, mkdirSync, readdirSync, readFileSync, writeFileSync, statSync, renameSync, unlinkSync, existsSync,
|
|
4
|
+
import { appendFileSync, mkdirSync, readdirSync, readFileSync, writeFileSync, statSync, renameSync, unlinkSync, existsSync, watch } from 'node:fs';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { dirname, join, basename } from 'node:path';
|
|
@@ -72,22 +72,25 @@ function loadTeamConfigs() {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// 监听团队配置目录变化,配置更新时立即刷新缓存
|
|
75
|
-
let
|
|
75
|
+
let teamsDirWatcher = null;
|
|
76
76
|
function setupTeamConfigWatcher() {
|
|
77
|
-
if (
|
|
77
|
+
if (teamsDirWatcher) return; // 已经启动了监听器
|
|
78
78
|
const teamsDir = join(homedir(), '.claude', 'teams');
|
|
79
|
-
if (!existsSync(teamsDir)) return;
|
|
80
79
|
|
|
80
|
+
// 即使目录不存在也创建监听器(后续创建会触发)
|
|
81
81
|
try {
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
if (
|
|
82
|
+
teamsDirWatcher = watch(teamsDir, { recursive: true }, (eventType, filename) => {
|
|
83
|
+
// 监听所有 config.json 文件的变化
|
|
84
|
+
if (filename && filename.endsWith('config.json')) {
|
|
85
|
+
logDebug(`Team config changed: ${filename}, invalidating cache...`);
|
|
85
86
|
teamConfigCache = null;
|
|
86
87
|
teamCacheTime = 0;
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
|
-
|
|
90
|
-
} catch {
|
|
90
|
+
logInfo('Team config watcher started');
|
|
91
|
+
} catch (err) {
|
|
92
|
+
logError(`Failed to watch teams dir: ${err.message}`);
|
|
93
|
+
}
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
// 启动时设置监听器
|
|
@@ -752,8 +755,17 @@ export function setupInterceptor() {
|
|
|
752
755
|
if (!toolsList.includes('Edit') || !toolsList.includes('Bash')) return false;
|
|
753
756
|
if (!toolsList.includes('Task') && !toolsList.includes('Agent')) return false;
|
|
754
757
|
}
|
|
755
|
-
// 排除 SubAgent
|
|
758
|
+
// 排除 SubAgent
|
|
759
|
+
// 1. 检查内置 specialist/general-agent 模式
|
|
756
760
|
if (/\b(\w+ )?specialist\b|general-purpose agent/i.test(sysText)) return false;
|
|
761
|
+
// 2. 检查自定义 agent(system 数组中包含 "# Agent:" 模式)
|
|
762
|
+
if (Array.isArray(body.system) && body.system.length > 1) {
|
|
763
|
+
// 检查非首个元素是否包含 "# Agent:" 模式(自定义 agent 定义)
|
|
764
|
+
const agentContent = body.system.slice(1).map(s => s?.text || '').join('');
|
|
765
|
+
if (/#\s+Agent:/i.test(agentContent)) return false;
|
|
766
|
+
}
|
|
767
|
+
// 3. 通用 fallback:检测任何 "# Agent:" 模式
|
|
768
|
+
if (/#\s+Agent:/i.test(sysText)) return false;
|
|
757
769
|
return true;
|
|
758
770
|
})();
|
|
759
771
|
|