@clawos-dev/clawd 0.2.345 → 0.2.346
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/dist/cli.cjs +1 -1
- package/dist/share-md-viewer-error.html +1 -1
- package/dist/share-md-viewer.html +1 -1
- package/dist/share-ui/assets/{guest-0_9EtohG.js → guest-CuCYJfhF.js} +1 -1
- package/dist/share-ui/assets/{guest-DcTfIUG3.css → guest-D76btdbG.css} +1 -1
- package/dist/share-ui/guest.html +2 -2
- package/package.json +1 -1
|
@@ -500,7 +500,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
500
500
|
`))+1))}const o="#".repeat(i),a=n.enter("headingAtx"),l=n.enter("phrasing");s.move(o+" ");let c=n.containerPhrasing(e,{before:"# ",after:`
|
|
501
501
|
`,...s.current()});return/^[\t ]/.test(c)&&(c=tu(c.charCodeAt(0))+c.slice(1)),c=c?o+" "+c:o,n.options.closeAtx&&(c+=" "+o),l(),a(),c}sM.peek=DX;function sM(e){return e.value||""}function DX(){return"<"}oM.peek=OX;function oM(e,t,n,r){const i=Ly(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("image");let a=n.enter("label");const l=n.createTracker(r);let c=l.move("![");return c+=l.move(n.safe(e.alt,{before:c,after:"]",...l.current()})),c+=l.move("]("),a(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(e.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(e.url,{before:c,after:e.title?" ":")",...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),c+=l.move(" "+i),c+=l.move(n.safe(e.title,{before:c,after:i,...l.current()})),c+=l.move(i),a()),c+=l.move(")"),o(),c}function OX(){return"!"}aM.peek=BX;function aM(e,t,n,r){const i=e.referenceType,s=n.enter("imageReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("![");const c=n.safe(e.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),o();const u=n.stack;n.stack=[],o=n.enter("reference");const d=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=u,s(),i==="full"||!c||c!==d?l+=a.move(d+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function BX(){return"!"}lM.peek=zX;function lM(e,t,n){let r=e.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const o=n.unsafe[s],a=n.compilePattern(o);let l;if(o.atBreak)for(;l=a.exec(r);){let c=l.index;r.charCodeAt(c)===10&&r.charCodeAt(c-1)===13&&c--,r=r.slice(0,c)+" "+r.slice(l.index+1)}}return i+r+i}function zX(){return"`"}function cM(e,t){const n=Cy(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}uM.peek=$X;function uM(e,t,n,r){const i=Ly(n),s=i==='"'?"Quote":"Apostrophe",o=n.createTracker(r);let a,l;if(cM(e,n)){const u=n.stack;n.stack=[],a=n.enter("autolink");let d=o.move("<");return d+=o.move(n.containerPhrasing(e,{before:d,after:">",...o.current()})),d+=o.move(">"),a(),n.stack=u,d}a=n.enter("link"),l=n.enter("label");let c=o.move("[");return c+=o.move(n.containerPhrasing(e,{before:c,after:"](",...o.current()})),c+=o.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),c+=o.move("<"),c+=o.move(n.safe(e.url,{before:c,after:">",...o.current()})),c+=o.move(">")):(l=n.enter("destinationRaw"),c+=o.move(n.safe(e.url,{before:c,after:e.title?" ":")",...o.current()}))),l(),e.title&&(l=n.enter(`title${s}`),c+=o.move(" "+i),c+=o.move(n.safe(e.title,{before:c,after:i,...o.current()})),c+=o.move(i),l()),c+=o.move(")"),a(),c}function $X(e,t,n){return cM(e,n)?"<":"["}dM.peek=FX;function dM(e,t,n,r){const i=e.referenceType,s=n.enter("linkReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("[");const c=n.containerPhrasing(e,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),o();const u=n.stack;n.stack=[],o=n.enter("reference");const d=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=u,s(),i==="full"||!c||c!==d?l+=a.move(d+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function FX(){return"["}function jy(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function HX(e){const t=jy(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function UX(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function hM(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function WX(e,t,n,r){const i=n.enter("list"),s=n.bulletCurrent;let o=e.ordered?UX(n):jy(n);const a=e.ordered?o==="."?")":".":HX(n);let l=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){const u=e.children?e.children[0]:void 0;if((o==="*"||o==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),hM(n)===o&&u){let d=-1;for(;++d<e.children.length;){const f=e.children[d];if(f&&f.type==="listItem"&&f.children&&f.children[0]&&f.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(o=a),n.bulletCurrent=o;const c=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=s,i(),c}function VX(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function qX(e,t,n,r){const i=VX(n);let s=n.bulletCurrent||jy(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let o=s.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const a=n.createTracker(r);a.move(s+" ".repeat(o-s.length)),a.shift(o);const l=n.enter("listItem"),c=n.indentLines(n.containerFlow(e,a.current()),u);return l(),c;function u(d,f,p){return f?(p?"":" ".repeat(o))+d:(p?s:s+" ".repeat(o-s.length))+d}}function KX(e,t,n,r){const i=n.enter("paragraph"),s=n.enter("phrasing"),o=n.containerPhrasing(e,r);return s(),i(),o}const GX=_p(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function XX(e,t,n,r){return(e.children.some(function(o){return GX(o)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function YX(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}fM.peek=QX;function fM(e,t,n,r){const i=YX(n),s=n.enter("strong"),o=n.createTracker(r),a=o.move(i+i);let l=o.move(n.containerPhrasing(e,{after:i,before:a,...o.current()}));const c=l.charCodeAt(0),u=of(r.before.charCodeAt(r.before.length-1),c,i);u.inside&&(l=tu(c)+l.slice(1));const d=l.charCodeAt(l.length-1),f=of(r.after.charCodeAt(0),d,i);f.inside&&(l=l.slice(0,-1)+tu(d));const p=o.move(i+i);return s(),n.attentionEncodeSurroundingInfo={after:f.outside,before:u.outside},a+l+p}function QX(e,t,n){return n.options.strong||"*"}function ZX(e,t,n,r){return n.safe(e.value,r)}function JX(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function eY(e,t,n){const r=(hM(n)+(n.options.ruleSpaces?" ":"")).repeat(JX(n));return n.options.ruleSpaces?r.slice(0,-1):r}const pM={blockquote:SX,break:mk,code:PX,definition:RX,emphasis:iM,hardBreak:mk,heading:jX,html:sM,image:oM,imageReference:aM,inlineCode:lM,link:uM,linkReference:dM,list:WX,listItem:qX,paragraph:KX,root:XX,strong:fM,text:ZX,thematicBreak:eY};function tY(){return{enter:{table:nY,tableData:gk,tableHeader:gk,tableRow:iY},exit:{codeText:sY,table:rY,tableData:Qm,tableHeader:Qm,tableRow:Qm}}}function nY(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function rY(e){this.exit(e),this.data.inTable=void 0}function iY(e){this.enter({type:"tableRow",children:[]},e)}function Qm(e){this.exit(e)}function gk(e){this.enter({type:"tableCell",children:[]},e)}function sY(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,oY));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function oY(e,t){return t==="|"?t:e}function aY(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
502
502
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:f,table:o,tableCell:l,tableRow:a}};function o(p,m,v,b){return c(u(p,v,b),p.align)}function a(p,m,v,b){const _=d(p,v,b),x=c([_]);return x.slice(0,x.indexOf(`
|
|
503
|
-
`))}function l(p,m,v,b){const _=v.enter("tableCell"),x=v.enter("phrasing"),y=v.containerPhrasing(p,{...b,before:s,after:s});return x(),_(),y}function c(p,m){return bX(p,{align:m,alignDelimiters:r,padding:n,stringLength:i})}function u(p,m,v){const b=p.children;let _=-1;const x=[],y=m.enter("table");for(;++_<b.length;)x[_]=d(b[_],m,v);return y(),x}function d(p,m,v){const b=p.children;let _=-1;const x=[],y=m.enter("tableRow");for(;++_<b.length;)x[_]=l(b[_],p,m,v);return y(),x}function f(p,m,v){let b=pM.inlineCode(p,m,v);return v.stack.includes("tableCell")&&(b=b.replace(/\|/g,"\\$&")),b}}function lY(){return{exit:{taskListCheckValueChecked:vk,taskListCheckValueUnchecked:vk,paragraph:uY}}}function cY(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:dY}}}function vk(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function uY(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function dY(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=pM.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+o}}function hY(){return[WG(),dX(),mX(),tY(),lY()]}function fY(e){return{extensions:[VG(),hX(e),gX(),aY(e),cY()]}}const pY={tokenize:yY,partial:!0},mM={tokenize:bY,partial:!0},gM={tokenize:wY,partial:!0},vM={tokenize:SY,partial:!0},mY={tokenize:kY,partial:!0},_M={name:"wwwAutolink",tokenize:_Y,previous:yM},xM={name:"protocolAutolink",tokenize:xY,previous:bM},Fi={name:"emailAutolink",tokenize:vY,previous:wM},di={};function gY(){return{text:di}}let Ws=48;for(;Ws<123;)di[Ws]=Fi,Ws++,Ws===58?Ws=65:Ws===91&&(Ws=97);di[43]=Fi;di[45]=Fi;di[46]=Fi;di[95]=Fi;di[72]=[Fi,xM];di[104]=[Fi,xM];di[87]=[Fi,_M];di[119]=[Fi,_M];function vY(e,t,n){const r=this;let i,s;return o;function o(d){return!P0(d)||!wM.call(r,r.previous)||Dy(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(d))}function a(d){return P0(d)?(e.consume(d),a):d===64?(e.consume(d),l):n(d)}function l(d){return d===46?e.check(mY,u,c)(d):d===45||d===95||yn(d)?(s=!0,e.consume(d),l):u(d)}function c(d){return e.consume(d),i=!0,l}function u(d){return s&&i&&En(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function _Y(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!yM.call(r,r.previous)||Dy(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(pY,e.attempt(mM,e.attempt(gM,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function xY(e,t,n){const r=this;let i="",s=!1;return o;function o(d){return(d===72||d===104)&&bM.call(r,r.previous)&&!Dy(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(d),e.consume(d),a):n(d)}function a(d){if(En(d)&&i.length<5)return i+=String.fromCodePoint(d),e.consume(d),a;if(d===58){const f=i.toLowerCase();if(f==="http"||f==="https")return e.consume(d),l}return n(d)}function l(d){return d===47?(e.consume(d),s?c:(s=!0,l)):n(d)}function c(d){return d===null||nf(d)||ot(d)||wo(d)||mp(d)?n(d):e.attempt(mM,e.attempt(gM,u),n)(d)}function u(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function yY(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function bY(e,t,n){let r,i,s;return o;function o(c){return c===46||c===95?e.check(vM,l,a)(c):c===null||ot(c)||wo(c)||c!==45&&mp(c)?l(c):(s=!0,e.consume(c),o)}function a(c){return c===95?r=!0:(i=r,r=void 0),e.consume(c),o}function l(c){return i||r||!s?n(c):t(c)}}function wY(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(vM,t,s)(o):o===null||ot(o)||wo(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function SY(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||ot(a)||wo(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||ot(a)||wo(a)?t(a):r(a)}function s(a){return En(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):En(a)?(e.consume(a),o):n(a)}}function kY(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return yn(s)?n(s):t(s)}}function yM(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ot(e)}function bM(e){return!En(e)}function wM(e){return!(e===47||P0(e))}function P0(e){return e===43||e===45||e===46||e===95||yn(e)}function Dy(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const CY={tokenize:AY,partial:!0};function EY(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:IY,continuation:{tokenize:RY},exit:MY}},text:{91:{name:"gfmFootnoteCall",tokenize:PY},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:NY,resolveTo:TY}}}}function NY(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const c=Mr(r.sliceSerialize({start:o.end,end:r.now()}));return c.codePointAt(0)!==94||!s.includes(c.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function TY(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function PY(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),l}function l(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(d){if(s>999||d===93&&!o||d===null||d===91||ot(d))return n(d);if(d===93){e.exit("chunkString");const f=e.exit("gfmFootnoteCallString");return i.includes(Mr(r.sliceSerialize(f)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return ot(d)||(o=!0),s++,e.consume(d),d===92?u:c}function u(d){return d===91||d===92||d===93?(e.consume(d),s++,c):c(d)}}function IY(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",u):n(m)}function u(m){if(o>999||m===93&&!a||m===null||m===91||ot(m))return n(m);if(m===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return s=Mr(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),f}return ot(m)||(a=!0),o++,e.consume(m),m===92?d:u}function d(m){return m===91||m===92||m===93?(e.consume(m),o++,u):u(m)}function f(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),i.includes(s)||i.push(s),Ge(e,p,"gfmFootnoteDefinitionWhitespace")):n(m)}function p(m){return t(m)}}function RY(e,t,n){return e.check(Eu,t,e.attempt(CY,t,n))}function MY(e){e.exit("gfmFootnoteDefinition")}function AY(e,t,n){const r=this;return Ge(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function LY(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let c=l;for(;c--;)if(o[c][0]==="exit"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[c][1].end.offset-o[c][1].start.offset){o[l][1].type="strikethroughSequence",o[c][1].type="strikethroughSequence";const u={type:"strikethrough",start:Object.assign({},o[c][1].start),end:Object.assign({},o[l][1].end)},d={type:"strikethroughText",start:Object.assign({},o[c][1].end),end:Object.assign({},o[l][1].start)},f=[["enter",u,a],["enter",o[c][1],a],["exit",o[c][1],a],["enter",d,a]],p=a.parser.constructs.insideSpan.null;p&&er(f,f.length,0,gp(p,o.slice(c+1,l),a)),er(f,f.length,0,[["exit",d,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",u,a]]),er(o,c-1,l-c+3,f),l=c+f.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const c=this.previous,u=this.events;let d=0;return f;function f(m){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(m):(o.enter("strikethroughSequenceTemporary"),p(m))}function p(m){const v=Ua(c);if(m===126)return d>1?l(m):(o.consume(m),d++,p);if(d<2&&!n)return l(m);const b=o.exit("strikethroughSequenceTemporary"),_=Ua(m);return b._open=!_||_===2&&!!v,b._close=!v||v===2&&!!_,a(m)}}}class jY{constructor(){this.map=[]}add(t,n,r){DY(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function DY(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function OY(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function BY(){return{flow:{null:{name:"table",tokenize:zY,resolveAll:$Y}}}}function zY(e,t,n){const r=this;let i=0,s=0,o;return a;function a(P){let A=r.events.length-1;for(;A>-1;){const j=r.events[A][1].type;if(j==="lineEnding"||j==="linePrefix")A--;else break}const I=A>-1?r.events[A][1].type:null,R=I==="tableHead"||I==="tableRow"?C:l;return R===C&&r.parser.lazy[r.now().line]?n(P):R(P)}function l(P){return e.enter("tableHead"),e.enter("tableRow"),c(P)}function c(P){return P===124||(o=!0,s+=1),u(P)}function u(P){return P===null?n(P):be(P)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(P),e.exit("lineEnding"),p):n(P):Ue(P)?Ge(e,u,"whitespace")(P):(s+=1,o&&(o=!1,i+=1),P===124?(e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),o=!0,u):(e.enter("data"),d(P)))}function d(P){return P===null||P===124||ot(P)?(e.exit("data"),u(P)):(e.consume(P),P===92?f:d)}function f(P){return P===92||P===124?(e.consume(P),d):d(P)}function p(P){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(P):(e.enter("tableDelimiterRow"),o=!1,Ue(P)?Ge(e,m,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(P):m(P))}function m(P){return P===45||P===58?b(P):P===124?(o=!0,e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),v):k(P)}function v(P){return Ue(P)?Ge(e,b,"whitespace")(P):b(P)}function b(P){return P===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(P),e.exit("tableDelimiterMarker"),_):P===45?(s+=1,_(P)):P===null||be(P)?w(P):k(P)}function _(P){return P===45?(e.enter("tableDelimiterFiller"),x(P)):k(P)}function x(P){return P===45?(e.consume(P),x):P===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(P),e.exit("tableDelimiterMarker"),y):(e.exit("tableDelimiterFiller"),y(P))}function y(P){return Ue(P)?Ge(e,w,"whitespace")(P):w(P)}function w(P){return P===124?m(P):P===null||be(P)?!o||i!==s?k(P):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(P)):k(P)}function k(P){return n(P)}function C(P){return e.enter("tableRow"),N(P)}function N(P){return P===124?(e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),N):P===null||be(P)?(e.exit("tableRow"),t(P)):Ue(P)?Ge(e,N,"whitespace")(P):(e.enter("data"),T(P))}function T(P){return P===null||P===124||ot(P)?(e.exit("data"),N(P)):(e.consume(P),P===92?B:T)}function B(P){return P===92||P===124?(e.consume(P),T):T(P)}}function $Y(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,c,u,d;const f=new jY;for(;++n<e.length;){const p=e[n],m=p[1];p[0]==="enter"?m.type==="tableHead"?(a=!1,l!==0&&(_k(f,t,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[["enter",c,t]])):m.type==="tableRow"||m.type==="tableDelimiterRow"?(r=!0,d=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[["enter",u,t]])),i=m.type==="tableDelimiterRow"?2:u?3:1):i&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],d=Sd(f,t,s,i,void 0,d),s=[0,0,0,0]),o[2]=n)):m.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],d=Sd(f,t,s,i,void 0,d)),s=o,o=[s[1],n,0,0])):m.type==="tableHead"?(a=!0,l=n):m.type==="tableRow"||m.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],d=Sd(f,t,s,i,n,d)):o[1]!==0&&(d=Sd(f,t,o,i,n,d)),i=0):i&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&_k(f,t,l,c,u),f.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=OY(t.events,n))}return e}function Sd(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},ea(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=ea(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const c=ea(t.events,n[2]),u=ea(t.events,n[3]),d={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const f=t.events[n[2]],p=t.events[n[3]];if(f[1].end=Object.assign({},p[1].end),f[1].type="chunkText",f[1].contentType="text",n[3]>n[2]+1){const m=n[2]+1,v=n[3]-n[2]-1;e.add(m,v,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return i!==void 0&&(s.end=Object.assign({},ea(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function _k(e,t,n,r,i){const s=[],o=ea(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function ea(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const FY={name:"tasklistCheck",tokenize:UY};function HY(){return{text:{91:FY}}}function UY(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return ot(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return be(l)?t(l):Ue(l)?e.check({tokenize:WY},t,n)(l):n(l)}}function WY(e,t,n){return Ge(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function VY(e){return RR([gY(),EY(),LY(e),BY(),HY()])}const qY={};function nu(e){const t=this,n=e||qY,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(VY(n)),s.push(hY()),o.push(fY(n))}const KY=/<command-name>([\s\S]*?)<\/command-name>/i,GY=/<command-message>([\s\S]*?)<\/command-message>/i,XY=/<command-args>([\s\S]*?)<\/command-args>/i,YY=/<(local-command-[a-z]+|command-(?:stdout|stderr))>[\s\S]*?<\/\1>/gi;function yp(e){if(!e)return{commandName:null,commandMessage:null,commandArgs:null,body:""};const t=e.match(KY),n=e.match(GY),r=e.match(XY);let i=e;return t&&(i=i.replace(t[0],"")),n&&(i=i.replace(n[0],"")),r&&(i=i.replace(r[0],"")),i=i.replace(YY,""),i=i.trim(),{commandName:t?t[1].trim():null,commandMessage:n?n[1].trim():null,commandArgs:r?r[1].trim():null,body:i}}function bp(e){if(!e)return!1;const n=e.split("#")[0].split("?")[0].toLowerCase();return n.endsWith(".md")||n.endsWith(".markdown")}function QY(e){if(!e)return null;let t;if(e.startsWith("file://")){const n=e.slice(7);t=n.startsWith("/")?n:`/${n.split("/").slice(1).join("/")}`}else{if(/^[a-z][a-z0-9+.-]*:/i.test(e))return null;if(e.startsWith("/"))t=e;else return null}try{return decodeURIComponent(t)}catch{return t}}const ZY=/\.(png|jpe?g|webp|gif|svg)$/i;function JY(e,t){if((typeof t=="string"?t:null)!==e)return!1;try{const r=new URL(e);return ZY.test(r.pathname)}catch{return!1}}function eQ(e){try{return new URL(e).pathname.split("/").filter(Boolean).pop()??""}catch{return""}}const So={a:({node:e,href:t,children:n,...r})=>typeof t=="string"&&JY(t,n)?h.jsxs("span",{className:"my-1 inline-flex flex-col items-start gap-1 align-top",children:[h.jsx("img",{src:t,alt:eQ(t),className:"max-w-full h-auto rounded border border-border"}),h.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"max-w-full truncate text-[11px] text-text-300 underline decoration-dotted underline-offset-2 hover:text-text-100",children:t})]}):h.jsx("a",{...r,href:t,target:"_blank",rel:"noopener noreferrer",children:n})};function tQ(e){return e.startsWith("file://")?e:JR(e)}function nQ(e){return{...So,a:t=>{const{href:n,children:r}=t,i=typeof n=="string"?QY(n):null;if(i===null){const s=So.a;return h.jsx(s,{...t})}return h.jsx("a",{href:n,"data-testid":"assistant-file-link",title:i,onClick:s=>{s.preventDefault(),e(i)},children:r})}}}function rQ({text:e,forkTarget:t,onOpenFilePath:n}){const{body:r}=yp(e),i=Ze.useMemo(()=>n?nQ(n):So,[n]);return r?h.jsxs("div",{className:"group relative flex min-w-0 max-w-full flex-col items-start","data-testid":"msg-line-assistant-wrapper",children:[h.jsx("div",{"data-testid":"msg-line-assistant",className:"assistant-markdown w-full min-w-0 max-w-full py-1 break-words",children:h.jsx(eu,{remarkPlugins:[nu],components:i,...n?{urlTransform:tQ}:{},children:r})}),t?h.jsxs("div",{className:"mt-1 flex flex-row items-center gap-1 md:absolute md:top-full md:mt-0 md:pt-0.5",children:[t.onFork?h.jsxs("button",{type:"button","data-testid":"assistant-msg-fork","aria-label":"fork from this message",title:"从这条消息派生新 session(截断之后的对话)",onClick:()=>t.onFork(t.messageUuid),className:"inline-flex items-center justify-start gap-1 h-7 w-7 md:h-6 md:w-auto md:px-1.5 rounded-md text-[11px] text-text-400/60 md:text-text-400 hover:bg-text-100/5 hover:text-text-200 md:opacity-0 md:group-hover:opacity-100 md:transition-opacity cursor-pointer",children:[h.jsx(Lx,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"Fork"})]}):null,t.onQuickAsk?h.jsxs("button",{type:"button","data-testid":"assistant-msg-quick-ask","aria-label":"quick ask from this message",title:"快速问答:从这条消息派生临时会话,关闭即删",onClick:()=>t.onQuickAsk(t.messageUuid),className:"inline-flex items-center justify-start gap-1 h-7 w-7 md:h-6 md:w-auto md:px-1.5 rounded-md text-[11px] text-text-400/60 md:text-text-400 hover:bg-text-100/5 hover:text-text-200 md:opacity-0 md:group-hover:opacity-100 md:transition-opacity cursor-pointer",children:[h.jsx(Hz,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"问一下"})]}):null]}):null]}):null}function iQ({text:e}){const[t,n]=g.useState(!1);return e?h.jsxs("div",{"data-testid":"msg-line-thinking",className:"text-[12px] text-text-400",children:[h.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"flex items-center gap-1 hover:text-text-300 transition-colors cursor-pointer","aria-expanded":t,"data-testid":"msg-line-thinking-toggle",children:[t?h.jsx(ir,{className:"w-3 h-3"}):h.jsx(Un,{className:"w-3 h-3"}),h.jsx("span",{children:"💭 Thinking"})]}),t?h.jsx("div",{className:"ml-4 mt-1 italic text-text-400 whitespace-pre-wrap break-words",children:e}):null]}):null}const sQ=new Set(["Write","Edit","MultiEdit","NotebookEdit"]);function I0(e){return sQ.has(e)}function oQ({tool:e,relPath:t,scope:n,onShareFile:r}){if(!I0(e)||!t||!n||!r)return null;const i=bp(t)?"md-rendered":"raw";return h.jsx("span",{"data-testid":"file-edit-hover-row",className:"inline-flex shrink-0 items-center gap-1",children:h.jsx("span",{role:"button",tabIndex:0,"data-testid":"file-edit-share-btn","aria-label":"Share link",title:"Share link",onClick:s=>{s.stopPropagation(),r(t,i)},onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.stopPropagation(),s.preventDefault(),r(t,i))},className:"inline-flex h-3.5 w-3.5 items-center justify-center text-text-400 hover:text-text-200 cursor-pointer",children:h.jsx(jx,{className:"h-3.5 w-3.5"})})})}function aQ(e){if(!e||typeof e!="object")return null;const t=e;return typeof t.file_path=="string"&&t.file_path||typeof t.notebook_path=="string"&&t.notebook_path||typeof t.path=="string"&&t.path||null||null}function SM(e,t){const[n,r]=g.useState({kind:"idle"});return g.useEffect(()=>{let i=!1,s=null;r({kind:"loading"});const o={};return t&&(o.Authorization=`Bearer ${t}`),fetch(e,{headers:o,credentials:"omit"}).then(async a=>{if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.blob()}).then(a=>{if(i)return;const l=URL.createObjectURL(a);s=l,r({kind:"ready",objectUrl:l})}).catch(a=>{i||r({kind:"error",message:a.message})}),()=>{i=!0,s&&URL.revokeObjectURL(s)}},[e,t]),n}function lQ({url:e,bearerToken:t,alt:n,className:r}){const i=SM(e,t);return h.jsxs("div",{"data-testid":"blob-image","data-state":i.kind,className:fe("relative inline-flex items-center justify-center rounded-md border border-border bg-bg-0",r),children:[i.kind==="loading"?h.jsx("div",{className:"flex h-24 w-32 items-center justify-center",children:h.jsx(In,{className:"h-4 w-4 animate-spin text-text-400"})}):null,i.kind==="error"?h.jsxs("div",{className:"flex h-24 w-32 items-center justify-center gap-1 px-2 text-[11px] text-text-400",children:[h.jsx(Ls,{className:"h-3 w-3"}),h.jsx("span",{title:i.message,children:"加载失败"})]}):null,i.kind==="ready"?h.jsx("img",{src:i.objectUrl,alt:n,className:"block max-h-[180px] max-w-[420px] rounded-md object-contain"}):null]})}function cQ({url:e,bearerToken:t,className:n}){const r=SM(e,t);return h.jsxs("div",{"data-testid":"blob-video","data-state":r.kind,className:fe("relative inline-flex items-center justify-center rounded-md border border-border bg-bg-0",n),children:[r.kind==="loading"?h.jsx(In,{className:"h-4 w-4 animate-spin text-text-400"}):null,r.kind==="error"?h.jsx("span",{className:"px-2 text-[11px] text-text-400",children:"加载失败"}):null,r.kind==="ready"?h.jsx("video",{src:r.objectUrl,controls:!0,className:"block max-h-[240px] max-w-[420px] rounded-md"}):null]})}const uQ=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),dQ=new Set([".mp4",".webm",".mov"]),hQ=new Set([".pdf"]);function fQ(e){const t=e.lastIndexOf("."),n=t>=0?e.slice(t).toLowerCase():"";return uQ.has(n)?"image":dQ.has(n)?"video":hQ.has(n)?"pdf":"binary"}function kM(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function pQ({relPath:e,scope:t,size:n}){const r=Zf();if(r.actionsLevel==="none")return null;const i=vB(r,t,e);if(!i)return null;const s=fQ(e);return s==="image"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"image",className:"mt-2",children:h.jsx(lQ,{url:i,bearerToken:r.httpToken,alt:e})}):s==="video"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"video",className:"mt-2",children:h.jsx(cQ,{url:i,bearerToken:r.httpToken})}):s==="pdf"?h.jsx(mQ,{relPath:e,url:i,size:n}):typeof n=="number"&&n>=1024*1024?h.jsxs("div",{"data-testid":"file-edit-inline-preview","data-kind":"binary",className:"mt-2 inline-flex items-center gap-1.5 rounded border border-border bg-bg-50 px-2 py-1 text-[11px] text-text-400",children:[h.jsx(Ro,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),h.jsx("span",{children:"·"}),h.jsx("span",{children:kM(n)})]}):null}function mQ({relPath:e,url:t,size:n}){return h.jsxs("a",{"data-testid":"file-edit-inline-preview","data-kind":"pdf",href:t,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex items-center gap-1.5 rounded border border-border bg-bg-50 px-2 py-1 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Ro,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),typeof n=="number"?h.jsxs(h.Fragment,{children:[h.jsx("span",{children:"·"}),h.jsx("span",{children:kM(n)})]}):null,h.jsx(qc,{className:"h-3 w-3"})]})}const gQ={Bash:BT,Read:Ro,Edit:OT,Write:Ez,Grep:Ew,Glob:Ew};function vQ(e){return gQ[e]??N$}function _Q(e){if(!e||typeof e!="object")return"";const t=e,n=t.command??t.file_path??t.path??t.pattern??t.query??t.url??t.description;if(typeof n=="string")return n;for(const r of Object.values(t))if(typeof r=="string"&&r)return r;return""}function CM({tool:e,input:t,output:n,error:r,pending:i=!1,expandedBody:s,fileScope:o,onOpenInTab:a,onPreviewMarkdown:l,onShareFile:c}){const[u,d]=g.useState(!1),f=!!r,p=vQ(e),m=_Q(t),v=aQ(t);return h.jsxs("div",{"data-testid":"msg-line-tool","data-tool":e,className:fe("group min-w-0 max-w-full rounded-md border px-3 py-2 text-[13px]",f?"border-destructive/40 bg-destructive/5":"border-border bg-bg-50"),children:[h.jsxs("button",{type:"button",onClick:()=>d(b=>!b),"aria-expanded":u,"data-testid":"msg-line-tool-header",className:"flex w-full items-center gap-2 text-left cursor-pointer min-w-0",children:[f?h.jsx(Ls,{className:"w-4 h-4 text-destructive shrink-0"}):h.jsx(p,{className:fe("w-4 h-4 shrink-0",i?"text-text-400":"text-text-300")}),h.jsx("span",{className:"font-medium text-text-100 shrink-0",children:e}),m?(()=>{if(f||!I0(e)||!v)return null;const _=bp(v)&&l?l:a;return _?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"msg-line-tool-preview","data-clickable":"true",title:m,onClick:x=>{x.stopPropagation(),_(v)},onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.stopPropagation(),x.preventDefault(),_(v))},className:"text-[12px] text-accent font-mono truncate min-w-0 max-w-full cursor-pointer underline underline-offset-2 hover:opacity-80",children:m}):null})()??h.jsx("span",{"data-testid":"msg-line-tool-preview",className:"text-[12px] text-text-400 font-mono truncate min-w-0 max-w-full",title:m,children:m}):null,h.jsx("span",{"aria-hidden":"true","data-testid":"msg-line-tool-header-spacer",className:"flex-1 min-w-0 self-stretch"}),i?h.jsx(In,{"data-testid":"msg-line-tool-pending",className:"w-3 h-3 text-text-400 animate-spin shrink-0"}):null,!f&&o?h.jsx(oQ,{tool:e,relPath:v,scope:o,...c?{onShareFile:c}:{}}):null]}),u?s!==void 0?h.jsxs("div",{"data-testid":"msg-line-tool-body",className:"mt-2 min-w-0 text-[12px]",children:[s,f?h.jsxs("div",{className:"mt-2",children:[h.jsx("div",{className:"text-destructive mb-0.5",children:"error"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-destructive/40 rounded p-2 overflow-auto text-destructive",children:String(r)})]}):null]}):h.jsxs("div",{"data-testid":"msg-line-tool-body",className:"mt-2 min-w-0 space-y-1 text-[12px]",children:[h.jsxs("div",{children:[h.jsx("div",{className:"text-text-400 mb-0.5",children:"input"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 overflow-auto text-text-200",children:JSON.stringify(t,null,2)})]}),n!==void 0?h.jsxs("div",{children:[h.jsx("div",{className:"text-text-400 mb-0.5",children:"output"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 overflow-auto text-text-200",children:typeof n=="string"?n:JSON.stringify(n,null,2)})]}):null,f?h.jsxs("div",{children:[h.jsx("div",{className:"text-destructive mb-0.5",children:"error"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-destructive/40 rounded p-2 overflow-auto text-destructive",children:String(r)})]}):null]}):null,!f&&o&&v&&I0(e)?h.jsx(pQ,{relPath:v,scope:o}):null]})}var xQ=Symbol.for("react.lazy"),af=Qa[" use ".trim().toString()];function yQ(e){return typeof e=="object"&&e!==null&&"then"in e}function EM(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===xQ&&"_payload"in e&&yQ(e._payload)}function bQ(e){const t=SQ(e),n=g.forwardRef((r,i)=>{let{children:s,...o}=r;EM(s)&&typeof af=="function"&&(s=af(s._payload));const a=g.Children.toArray(s),l=a.find(CQ);if(l){const c=l.props.children,u=a.map(d=>d===l?g.Children.count(c)>1?g.Children.only(null):g.isValidElement(c)?c.props.children:null:d);return h.jsx(t,{...o,ref:i,children:g.isValidElement(c)?g.cloneElement(c,void 0,u):null})}return h.jsx(t,{...o,ref:i,children:s})});return n.displayName=`${e}.Slot`,n}var wQ=bQ("Slot");function SQ(e){const t=g.forwardRef((n,r)=>{let{children:i,...s}=n;if(EM(i)&&typeof af=="function"&&(i=af(i._payload)),g.isValidElement(i)){const o=NQ(i),a=EQ(s,i.props);return i.type!==g.Fragment&&(a.ref=r?vu(r,o):o),g.cloneElement(i,a)}return g.Children.count(i)>1?g.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var kQ=Symbol("radix.slottable");function CQ(e){return g.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===kQ}function EQ(e,t){const n={...t};for(const r in t){const i=e[r],s=t[r];/^on[A-Z]/.test(r)?i&&s?n[r]=(...a)=>{const l=s(...a);return i(...a),l}:i&&(n[r]=i):r==="style"?n[r]={...i,...s}:r==="className"&&(n[r]=[i,s].filter(Boolean).join(" "))}return{...e,...n}}function NQ(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}const xk=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,yk=HT,TQ=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return yk(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(c=>{const u=n==null?void 0:n[c],d=s==null?void 0:s[c];if(u===null)return null;const f=xk(u)||xk(d);return i[c][f]}),a=n&&Object.entries(n).reduce((c,u)=>{let[d,f]=u;return f===void 0||(c[d]=f),c},{}),l=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((c,u)=>{let{class:d,className:f,...p}=u;return Object.entries(p).every(m=>{let[v,b]=m;return Array.isArray(b)?b.includes({...s,...a}[v]):{...s,...a}[v]===b})?[...c,d,f]:c},[]);return yk(e,o,l,n==null?void 0:n.class,n==null?void 0:n.className)},PQ=TQ("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-accent text-accent-contrast hover:bg-accent-hover",destructive:"bg-destructive text-white hover:bg-destructive-hover",outline:"border border-border bg-transparent text-text-100 hover:bg-bg-200",ghost:"bg-transparent text-text-200 hover:bg-bg-200 hover:text-text-100"},size:{sm:"h-8 px-3 text-xs",md:"h-9 px-4",lg:"h-11 px-6 text-base"}},defaultVariants:{variant:"default",size:"md"}}),ni=g.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},s)=>{const o=r?wQ:"button";return h.jsx(o,{ref:s,className:fe(PQ({variant:t,size:n}),e),...i})});ni.displayName="Button";function IQ({tool:e,input:t,onRespond:n,onInterrupt:r}){return h.jsxs("div",{"data-testid":"msg-line-permission",className:"min-w-0 max-w-full rounded-md border border-warning/40 bg-warning-dim/60 px-3 py-2.5 text-[13px]",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 mb-1.5",children:[h.jsx(m$,{className:"w-4 h-4 text-warning shrink-0"}),h.jsxs("span",{className:"min-w-0 font-medium text-text-100 truncate",children:["权限请求:",e]}),r?h.jsx("button",{type:"button",onClick:r,"data-testid":"msg-line-permission-interrupt","aria-label":"interrupt current turn",title:"中断当前轮次(不杀进程)",className:"ml-auto h-6 w-6 rounded-md flex items-center justify-center text-text-400 hover:bg-text-100/10 hover:text-text-200 transition-colors cursor-pointer",children:h.jsx(DT,{className:"w-3.5 h-3.5",strokeWidth:2})}):null]}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 mb-2 max-h-[140px] overflow-auto text-[12px] text-text-200",children:JSON.stringify(t,null,2)}),h.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.jsx(ni,{size:"sm",variant:"default",onClick:()=>n(!0,!1),"data-testid":"msg-line-permission-allow",children:"Allow"}),h.jsx(ni,{size:"sm",variant:"outline",onClick:()=>n(!0,!0),"data-testid":"msg-line-permission-allow-always",children:"Allow Always"}),h.jsx(ni,{size:"sm",variant:"destructive",onClick:()=>n(!1,!1),"data-testid":"msg-line-permission-deny",children:"Deny"})]})]})}function RQ({message:e}){return h.jsxs("div",{"data-testid":"msg-line-error",className:"flex min-w-0 max-w-full items-start gap-2 text-destructive text-[13px] rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2",children:[h.jsx(Kc,{className:"w-4 h-4 shrink-0 mt-0.5"}),h.jsx("span",{className:"min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}const bk=/\[attachment:(image|file):([^\]]+)\]/g;function MQ(e){const t=[];let n;for(;(n=bk.exec(e))!==null;){const i=n[2],s=decodeURIComponent(i.split("/").pop()??"file");t.push({type:n[1],url:i,fileName:s})}const r=e.replace(bk,"").trim();return{attachments:t,text:r}}function AQ(e,t){const n=t.filter(i=>i.status==="done"&&i.url);return n.length===0?e:n.map(i=>`[attachment:${i.mimeType.startsWith("image/")?"image":"file"}:${i.url}]`).join(`
|
|
503
|
+
`))}function l(p,m,v,b){const _=v.enter("tableCell"),x=v.enter("phrasing"),y=v.containerPhrasing(p,{...b,before:s,after:s});return x(),_(),y}function c(p,m){return bX(p,{align:m,alignDelimiters:r,padding:n,stringLength:i})}function u(p,m,v){const b=p.children;let _=-1;const x=[],y=m.enter("table");for(;++_<b.length;)x[_]=d(b[_],m,v);return y(),x}function d(p,m,v){const b=p.children;let _=-1;const x=[],y=m.enter("tableRow");for(;++_<b.length;)x[_]=l(b[_],p,m,v);return y(),x}function f(p,m,v){let b=pM.inlineCode(p,m,v);return v.stack.includes("tableCell")&&(b=b.replace(/\|/g,"\\$&")),b}}function lY(){return{exit:{taskListCheckValueChecked:vk,taskListCheckValueUnchecked:vk,paragraph:uY}}}function cY(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:dY}}}function vk(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function uY(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function dY(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=pM.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+o}}function hY(){return[WG(),dX(),mX(),tY(),lY()]}function fY(e){return{extensions:[VG(),hX(e),gX(),aY(e),cY()]}}const pY={tokenize:yY,partial:!0},mM={tokenize:bY,partial:!0},gM={tokenize:wY,partial:!0},vM={tokenize:SY,partial:!0},mY={tokenize:kY,partial:!0},_M={name:"wwwAutolink",tokenize:_Y,previous:yM},xM={name:"protocolAutolink",tokenize:xY,previous:bM},Fi={name:"emailAutolink",tokenize:vY,previous:wM},di={};function gY(){return{text:di}}let Ws=48;for(;Ws<123;)di[Ws]=Fi,Ws++,Ws===58?Ws=65:Ws===91&&(Ws=97);di[43]=Fi;di[45]=Fi;di[46]=Fi;di[95]=Fi;di[72]=[Fi,xM];di[104]=[Fi,xM];di[87]=[Fi,_M];di[119]=[Fi,_M];function vY(e,t,n){const r=this;let i,s;return o;function o(d){return!P0(d)||!wM.call(r,r.previous)||Dy(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(d))}function a(d){return P0(d)?(e.consume(d),a):d===64?(e.consume(d),l):n(d)}function l(d){return d===46?e.check(mY,u,c)(d):d===45||d===95||yn(d)?(s=!0,e.consume(d),l):u(d)}function c(d){return e.consume(d),i=!0,l}function u(d){return s&&i&&En(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function _Y(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!yM.call(r,r.previous)||Dy(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(pY,e.attempt(mM,e.attempt(gM,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function xY(e,t,n){const r=this;let i="",s=!1;return o;function o(d){return(d===72||d===104)&&bM.call(r,r.previous)&&!Dy(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(d),e.consume(d),a):n(d)}function a(d){if(En(d)&&i.length<5)return i+=String.fromCodePoint(d),e.consume(d),a;if(d===58){const f=i.toLowerCase();if(f==="http"||f==="https")return e.consume(d),l}return n(d)}function l(d){return d===47?(e.consume(d),s?c:(s=!0,l)):n(d)}function c(d){return d===null||nf(d)||ot(d)||wo(d)||mp(d)?n(d):e.attempt(mM,e.attempt(gM,u),n)(d)}function u(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function yY(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function bY(e,t,n){let r,i,s;return o;function o(c){return c===46||c===95?e.check(vM,l,a)(c):c===null||ot(c)||wo(c)||c!==45&&mp(c)?l(c):(s=!0,e.consume(c),o)}function a(c){return c===95?r=!0:(i=r,r=void 0),e.consume(c),o}function l(c){return i||r||!s?n(c):t(c)}}function wY(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(vM,t,s)(o):o===null||ot(o)||wo(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function SY(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||ot(a)||wo(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||ot(a)||wo(a)?t(a):r(a)}function s(a){return En(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):En(a)?(e.consume(a),o):n(a)}}function kY(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return yn(s)?n(s):t(s)}}function yM(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ot(e)}function bM(e){return!En(e)}function wM(e){return!(e===47||P0(e))}function P0(e){return e===43||e===45||e===46||e===95||yn(e)}function Dy(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const CY={tokenize:AY,partial:!0};function EY(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:IY,continuation:{tokenize:RY},exit:MY}},text:{91:{name:"gfmFootnoteCall",tokenize:PY},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:NY,resolveTo:TY}}}}function NY(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const c=Mr(r.sliceSerialize({start:o.end,end:r.now()}));return c.codePointAt(0)!==94||!s.includes(c.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function TY(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function PY(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),l}function l(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(d){if(s>999||d===93&&!o||d===null||d===91||ot(d))return n(d);if(d===93){e.exit("chunkString");const f=e.exit("gfmFootnoteCallString");return i.includes(Mr(r.sliceSerialize(f)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return ot(d)||(o=!0),s++,e.consume(d),d===92?u:c}function u(d){return d===91||d===92||d===93?(e.consume(d),s++,c):c(d)}}function IY(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",u):n(m)}function u(m){if(o>999||m===93&&!a||m===null||m===91||ot(m))return n(m);if(m===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return s=Mr(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),f}return ot(m)||(a=!0),o++,e.consume(m),m===92?d:u}function d(m){return m===91||m===92||m===93?(e.consume(m),o++,u):u(m)}function f(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),i.includes(s)||i.push(s),Ge(e,p,"gfmFootnoteDefinitionWhitespace")):n(m)}function p(m){return t(m)}}function RY(e,t,n){return e.check(Eu,t,e.attempt(CY,t,n))}function MY(e){e.exit("gfmFootnoteDefinition")}function AY(e,t,n){const r=this;return Ge(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function LY(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let c=l;for(;c--;)if(o[c][0]==="exit"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[c][1].end.offset-o[c][1].start.offset){o[l][1].type="strikethroughSequence",o[c][1].type="strikethroughSequence";const u={type:"strikethrough",start:Object.assign({},o[c][1].start),end:Object.assign({},o[l][1].end)},d={type:"strikethroughText",start:Object.assign({},o[c][1].end),end:Object.assign({},o[l][1].start)},f=[["enter",u,a],["enter",o[c][1],a],["exit",o[c][1],a],["enter",d,a]],p=a.parser.constructs.insideSpan.null;p&&er(f,f.length,0,gp(p,o.slice(c+1,l),a)),er(f,f.length,0,[["exit",d,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",u,a]]),er(o,c-1,l-c+3,f),l=c+f.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const c=this.previous,u=this.events;let d=0;return f;function f(m){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(m):(o.enter("strikethroughSequenceTemporary"),p(m))}function p(m){const v=Ua(c);if(m===126)return d>1?l(m):(o.consume(m),d++,p);if(d<2&&!n)return l(m);const b=o.exit("strikethroughSequenceTemporary"),_=Ua(m);return b._open=!_||_===2&&!!v,b._close=!v||v===2&&!!_,a(m)}}}class jY{constructor(){this.map=[]}add(t,n,r){DY(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function DY(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function OY(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function BY(){return{flow:{null:{name:"table",tokenize:zY,resolveAll:$Y}}}}function zY(e,t,n){const r=this;let i=0,s=0,o;return a;function a(P){let A=r.events.length-1;for(;A>-1;){const j=r.events[A][1].type;if(j==="lineEnding"||j==="linePrefix")A--;else break}const I=A>-1?r.events[A][1].type:null,R=I==="tableHead"||I==="tableRow"?C:l;return R===C&&r.parser.lazy[r.now().line]?n(P):R(P)}function l(P){return e.enter("tableHead"),e.enter("tableRow"),c(P)}function c(P){return P===124||(o=!0,s+=1),u(P)}function u(P){return P===null?n(P):be(P)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(P),e.exit("lineEnding"),p):n(P):Ue(P)?Ge(e,u,"whitespace")(P):(s+=1,o&&(o=!1,i+=1),P===124?(e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),o=!0,u):(e.enter("data"),d(P)))}function d(P){return P===null||P===124||ot(P)?(e.exit("data"),u(P)):(e.consume(P),P===92?f:d)}function f(P){return P===92||P===124?(e.consume(P),d):d(P)}function p(P){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(P):(e.enter("tableDelimiterRow"),o=!1,Ue(P)?Ge(e,m,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(P):m(P))}function m(P){return P===45||P===58?b(P):P===124?(o=!0,e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),v):k(P)}function v(P){return Ue(P)?Ge(e,b,"whitespace")(P):b(P)}function b(P){return P===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(P),e.exit("tableDelimiterMarker"),_):P===45?(s+=1,_(P)):P===null||be(P)?w(P):k(P)}function _(P){return P===45?(e.enter("tableDelimiterFiller"),x(P)):k(P)}function x(P){return P===45?(e.consume(P),x):P===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(P),e.exit("tableDelimiterMarker"),y):(e.exit("tableDelimiterFiller"),y(P))}function y(P){return Ue(P)?Ge(e,w,"whitespace")(P):w(P)}function w(P){return P===124?m(P):P===null||be(P)?!o||i!==s?k(P):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(P)):k(P)}function k(P){return n(P)}function C(P){return e.enter("tableRow"),N(P)}function N(P){return P===124?(e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),N):P===null||be(P)?(e.exit("tableRow"),t(P)):Ue(P)?Ge(e,N,"whitespace")(P):(e.enter("data"),T(P))}function T(P){return P===null||P===124||ot(P)?(e.exit("data"),N(P)):(e.consume(P),P===92?B:T)}function B(P){return P===92||P===124?(e.consume(P),T):T(P)}}function $Y(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,c,u,d;const f=new jY;for(;++n<e.length;){const p=e[n],m=p[1];p[0]==="enter"?m.type==="tableHead"?(a=!1,l!==0&&(_k(f,t,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[["enter",c,t]])):m.type==="tableRow"||m.type==="tableDelimiterRow"?(r=!0,d=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[["enter",u,t]])),i=m.type==="tableDelimiterRow"?2:u?3:1):i&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],d=Sd(f,t,s,i,void 0,d),s=[0,0,0,0]),o[2]=n)):m.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],d=Sd(f,t,s,i,void 0,d)),s=o,o=[s[1],n,0,0])):m.type==="tableHead"?(a=!0,l=n):m.type==="tableRow"||m.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],d=Sd(f,t,s,i,n,d)):o[1]!==0&&(d=Sd(f,t,o,i,n,d)),i=0):i&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&_k(f,t,l,c,u),f.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=OY(t.events,n))}return e}function Sd(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},ea(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=ea(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const c=ea(t.events,n[2]),u=ea(t.events,n[3]),d={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const f=t.events[n[2]],p=t.events[n[3]];if(f[1].end=Object.assign({},p[1].end),f[1].type="chunkText",f[1].contentType="text",n[3]>n[2]+1){const m=n[2]+1,v=n[3]-n[2]-1;e.add(m,v,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return i!==void 0&&(s.end=Object.assign({},ea(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function _k(e,t,n,r,i){const s=[],o=ea(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function ea(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const FY={name:"tasklistCheck",tokenize:UY};function HY(){return{text:{91:FY}}}function UY(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return ot(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return be(l)?t(l):Ue(l)?e.check({tokenize:WY},t,n)(l):n(l)}}function WY(e,t,n){return Ge(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function VY(e){return RR([gY(),EY(),LY(e),BY(),HY()])}const qY={};function nu(e){const t=this,n=e||qY,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(VY(n)),s.push(hY()),o.push(fY(n))}const KY=/<command-name>([\s\S]*?)<\/command-name>/i,GY=/<command-message>([\s\S]*?)<\/command-message>/i,XY=/<command-args>([\s\S]*?)<\/command-args>/i,YY=/<(local-command-[a-z]+|command-(?:stdout|stderr))>[\s\S]*?<\/\1>/gi;function yp(e){if(!e)return{commandName:null,commandMessage:null,commandArgs:null,body:""};const t=e.match(KY),n=e.match(GY),r=e.match(XY);let i=e;return t&&(i=i.replace(t[0],"")),n&&(i=i.replace(n[0],"")),r&&(i=i.replace(r[0],"")),i=i.replace(YY,""),i=i.trim(),{commandName:t?t[1].trim():null,commandMessage:n?n[1].trim():null,commandArgs:r?r[1].trim():null,body:i}}function bp(e){if(!e)return!1;const n=e.split("#")[0].split("?")[0].toLowerCase();return n.endsWith(".md")||n.endsWith(".markdown")}function QY(e){if(!e)return null;let t;if(e.startsWith("file://")){const n=e.slice(7);t=n.startsWith("/")?n:`/${n.split("/").slice(1).join("/")}`}else{if(/^[a-z][a-z0-9+.-]*:/i.test(e))return null;if(e.startsWith("/"))t=e;else return null}try{return decodeURIComponent(t)}catch{return t}}const ZY=/\.(png|jpe?g|webp|gif|svg)$/i;function JY(e,t){if((typeof t=="string"?t:null)!==e)return!1;try{const r=new URL(e);return ZY.test(r.pathname)}catch{return!1}}function eQ(e){try{return new URL(e).pathname.split("/").filter(Boolean).pop()??""}catch{return""}}const So={a:({node:e,href:t,children:n,...r})=>typeof t=="string"&&JY(t,n)?h.jsxs("span",{className:"my-1 inline-flex flex-col items-start gap-1 align-top",children:[h.jsx("img",{src:t,alt:eQ(t),className:"max-w-full h-auto rounded border border-border"}),h.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"max-w-full truncate text-[11px] text-text-300 underline decoration-dotted underline-offset-2 hover:text-text-100",children:t})]}):h.jsx("a",{...r,href:t,target:"_blank",rel:"noopener noreferrer",children:n})};function tQ(e){return e.startsWith("file://")?e:JR(e)}function nQ(e){return{...So,a:t=>{const{href:n,children:r}=t,i=typeof n=="string"?QY(n):null;if(i===null){const s=So.a;return h.jsx(s,{...t})}return h.jsx("a",{href:n,"data-testid":"assistant-file-link",title:i,onClick:s=>{s.preventDefault(),e(i)},children:r})}}}function rQ({text:e,forkTarget:t,onOpenFilePath:n}){const{body:r}=yp(e),i=Ze.useMemo(()=>n?nQ(n):So,[n]);return r?h.jsxs("div",{className:"group relative flex min-w-0 max-w-full flex-col items-start","data-testid":"msg-line-assistant-wrapper",children:[h.jsx("div",{"data-testid":"msg-line-assistant",className:"assistant-markdown w-full min-w-0 max-w-full py-1 break-words",children:h.jsx(eu,{remarkPlugins:[nu],components:i,...n?{urlTransform:tQ}:{},children:r})}),t?h.jsxs("div",{className:"mt-1 flex flex-row items-center gap-1 md:absolute md:top-full md:mt-0 md:pt-0.5 md:z-10 md:rounded-md md:pointer-events-none md:group-hover:pointer-events-auto md:group-hover:bg-bg-100",children:[t.onFork?h.jsxs("button",{type:"button","data-testid":"assistant-msg-fork","aria-label":"fork from this message",title:"从这条消息派生新 session(截断之后的对话)",onClick:()=>t.onFork(t.messageUuid),className:"inline-flex items-center justify-start gap-1 h-7 w-7 md:h-6 md:w-auto md:px-1.5 rounded-md text-[11px] text-text-400/60 md:text-text-400 hover:bg-text-100/5 hover:text-text-200 md:opacity-0 md:group-hover:opacity-100 md:transition-opacity cursor-pointer",children:[h.jsx(Lx,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"Fork"})]}):null,t.onQuickAsk?h.jsxs("button",{type:"button","data-testid":"assistant-msg-quick-ask","aria-label":"quick ask from this message",title:"快速问答:从这条消息派生临时会话,关闭即删",onClick:()=>t.onQuickAsk(t.messageUuid),className:"inline-flex items-center justify-start gap-1 h-7 w-7 md:h-6 md:w-auto md:px-1.5 rounded-md text-[11px] text-text-400/60 md:text-text-400 hover:bg-text-100/5 hover:text-text-200 md:opacity-0 md:group-hover:opacity-100 md:transition-opacity cursor-pointer",children:[h.jsx(Hz,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"问一下"})]}):null]}):null]}):null}function iQ({text:e}){const[t,n]=g.useState(!1);return e?h.jsxs("div",{"data-testid":"msg-line-thinking",className:"text-[12px] text-text-400",children:[h.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"flex items-center gap-1 hover:text-text-300 transition-colors cursor-pointer","aria-expanded":t,"data-testid":"msg-line-thinking-toggle",children:[t?h.jsx(ir,{className:"w-3 h-3"}):h.jsx(Un,{className:"w-3 h-3"}),h.jsx("span",{children:"💭 Thinking"})]}),t?h.jsx("div",{className:"ml-4 mt-1 italic text-text-400 whitespace-pre-wrap break-words",children:e}):null]}):null}const sQ=new Set(["Write","Edit","MultiEdit","NotebookEdit"]);function I0(e){return sQ.has(e)}function oQ({tool:e,relPath:t,scope:n,onShareFile:r}){if(!I0(e)||!t||!n||!r)return null;const i=bp(t)?"md-rendered":"raw";return h.jsx("span",{"data-testid":"file-edit-hover-row",className:"inline-flex shrink-0 items-center gap-1",children:h.jsx("span",{role:"button",tabIndex:0,"data-testid":"file-edit-share-btn","aria-label":"Share link",title:"Share link",onClick:s=>{s.stopPropagation(),r(t,i)},onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.stopPropagation(),s.preventDefault(),r(t,i))},className:"inline-flex h-3.5 w-3.5 items-center justify-center text-text-400 hover:text-text-200 cursor-pointer",children:h.jsx(jx,{className:"h-3.5 w-3.5"})})})}function aQ(e){if(!e||typeof e!="object")return null;const t=e;return typeof t.file_path=="string"&&t.file_path||typeof t.notebook_path=="string"&&t.notebook_path||typeof t.path=="string"&&t.path||null||null}function SM(e,t){const[n,r]=g.useState({kind:"idle"});return g.useEffect(()=>{let i=!1,s=null;r({kind:"loading"});const o={};return t&&(o.Authorization=`Bearer ${t}`),fetch(e,{headers:o,credentials:"omit"}).then(async a=>{if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.blob()}).then(a=>{if(i)return;const l=URL.createObjectURL(a);s=l,r({kind:"ready",objectUrl:l})}).catch(a=>{i||r({kind:"error",message:a.message})}),()=>{i=!0,s&&URL.revokeObjectURL(s)}},[e,t]),n}function lQ({url:e,bearerToken:t,alt:n,className:r}){const i=SM(e,t);return h.jsxs("div",{"data-testid":"blob-image","data-state":i.kind,className:fe("relative inline-flex items-center justify-center rounded-md border border-border bg-bg-0",r),children:[i.kind==="loading"?h.jsx("div",{className:"flex h-24 w-32 items-center justify-center",children:h.jsx(In,{className:"h-4 w-4 animate-spin text-text-400"})}):null,i.kind==="error"?h.jsxs("div",{className:"flex h-24 w-32 items-center justify-center gap-1 px-2 text-[11px] text-text-400",children:[h.jsx(Ls,{className:"h-3 w-3"}),h.jsx("span",{title:i.message,children:"加载失败"})]}):null,i.kind==="ready"?h.jsx("img",{src:i.objectUrl,alt:n,className:"block max-h-[180px] max-w-[420px] rounded-md object-contain"}):null]})}function cQ({url:e,bearerToken:t,className:n}){const r=SM(e,t);return h.jsxs("div",{"data-testid":"blob-video","data-state":r.kind,className:fe("relative inline-flex items-center justify-center rounded-md border border-border bg-bg-0",n),children:[r.kind==="loading"?h.jsx(In,{className:"h-4 w-4 animate-spin text-text-400"}):null,r.kind==="error"?h.jsx("span",{className:"px-2 text-[11px] text-text-400",children:"加载失败"}):null,r.kind==="ready"?h.jsx("video",{src:r.objectUrl,controls:!0,className:"block max-h-[240px] max-w-[420px] rounded-md"}):null]})}const uQ=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),dQ=new Set([".mp4",".webm",".mov"]),hQ=new Set([".pdf"]);function fQ(e){const t=e.lastIndexOf("."),n=t>=0?e.slice(t).toLowerCase():"";return uQ.has(n)?"image":dQ.has(n)?"video":hQ.has(n)?"pdf":"binary"}function kM(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function pQ({relPath:e,scope:t,size:n}){const r=Zf();if(r.actionsLevel==="none")return null;const i=vB(r,t,e);if(!i)return null;const s=fQ(e);return s==="image"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"image",className:"mt-2",children:h.jsx(lQ,{url:i,bearerToken:r.httpToken,alt:e})}):s==="video"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"video",className:"mt-2",children:h.jsx(cQ,{url:i,bearerToken:r.httpToken})}):s==="pdf"?h.jsx(mQ,{relPath:e,url:i,size:n}):typeof n=="number"&&n>=1024*1024?h.jsxs("div",{"data-testid":"file-edit-inline-preview","data-kind":"binary",className:"mt-2 inline-flex items-center gap-1.5 rounded border border-border bg-bg-50 px-2 py-1 text-[11px] text-text-400",children:[h.jsx(Ro,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),h.jsx("span",{children:"·"}),h.jsx("span",{children:kM(n)})]}):null}function mQ({relPath:e,url:t,size:n}){return h.jsxs("a",{"data-testid":"file-edit-inline-preview","data-kind":"pdf",href:t,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex items-center gap-1.5 rounded border border-border bg-bg-50 px-2 py-1 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Ro,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),typeof n=="number"?h.jsxs(h.Fragment,{children:[h.jsx("span",{children:"·"}),h.jsx("span",{children:kM(n)})]}):null,h.jsx(qc,{className:"h-3 w-3"})]})}const gQ={Bash:BT,Read:Ro,Edit:OT,Write:Ez,Grep:Ew,Glob:Ew};function vQ(e){return gQ[e]??N$}function _Q(e){if(!e||typeof e!="object")return"";const t=e,n=t.command??t.file_path??t.path??t.pattern??t.query??t.url??t.description;if(typeof n=="string")return n;for(const r of Object.values(t))if(typeof r=="string"&&r)return r;return""}function CM({tool:e,input:t,output:n,error:r,pending:i=!1,expandedBody:s,fileScope:o,onOpenInTab:a,onPreviewMarkdown:l,onShareFile:c}){const[u,d]=g.useState(!1),f=!!r,p=vQ(e),m=_Q(t),v=aQ(t);return h.jsxs("div",{"data-testid":"msg-line-tool","data-tool":e,className:fe("group min-w-0 max-w-full rounded-md border px-3 py-2 text-[13px]",f?"border-destructive/40 bg-destructive/5":"border-border bg-bg-50"),children:[h.jsxs("button",{type:"button",onClick:()=>d(b=>!b),"aria-expanded":u,"data-testid":"msg-line-tool-header",className:"flex w-full items-center gap-2 text-left cursor-pointer min-w-0",children:[f?h.jsx(Ls,{className:"w-4 h-4 text-destructive shrink-0"}):h.jsx(p,{className:fe("w-4 h-4 shrink-0",i?"text-text-400":"text-text-300")}),h.jsx("span",{className:"font-medium text-text-100 shrink-0",children:e}),m?(()=>{if(f||!I0(e)||!v)return null;const _=bp(v)&&l?l:a;return _?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"msg-line-tool-preview","data-clickable":"true",title:m,onClick:x=>{x.stopPropagation(),_(v)},onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.stopPropagation(),x.preventDefault(),_(v))},className:"text-[12px] text-accent font-mono truncate min-w-0 max-w-full cursor-pointer underline underline-offset-2 hover:opacity-80",children:m}):null})()??h.jsx("span",{"data-testid":"msg-line-tool-preview",className:"text-[12px] text-text-400 font-mono truncate min-w-0 max-w-full",title:m,children:m}):null,h.jsx("span",{"aria-hidden":"true","data-testid":"msg-line-tool-header-spacer",className:"flex-1 min-w-0 self-stretch"}),i?h.jsx(In,{"data-testid":"msg-line-tool-pending",className:"w-3 h-3 text-text-400 animate-spin shrink-0"}):null,!f&&o?h.jsx(oQ,{tool:e,relPath:v,scope:o,...c?{onShareFile:c}:{}}):null]}),u?s!==void 0?h.jsxs("div",{"data-testid":"msg-line-tool-body",className:"mt-2 min-w-0 text-[12px]",children:[s,f?h.jsxs("div",{className:"mt-2",children:[h.jsx("div",{className:"text-destructive mb-0.5",children:"error"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-destructive/40 rounded p-2 overflow-auto text-destructive",children:String(r)})]}):null]}):h.jsxs("div",{"data-testid":"msg-line-tool-body",className:"mt-2 min-w-0 space-y-1 text-[12px]",children:[h.jsxs("div",{children:[h.jsx("div",{className:"text-text-400 mb-0.5",children:"input"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 overflow-auto text-text-200",children:JSON.stringify(t,null,2)})]}),n!==void 0?h.jsxs("div",{children:[h.jsx("div",{className:"text-text-400 mb-0.5",children:"output"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 overflow-auto text-text-200",children:typeof n=="string"?n:JSON.stringify(n,null,2)})]}):null,f?h.jsxs("div",{children:[h.jsx("div",{className:"text-destructive mb-0.5",children:"error"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-destructive/40 rounded p-2 overflow-auto text-destructive",children:String(r)})]}):null]}):null,!f&&o&&v&&I0(e)?h.jsx(pQ,{relPath:v,scope:o}):null]})}var xQ=Symbol.for("react.lazy"),af=Qa[" use ".trim().toString()];function yQ(e){return typeof e=="object"&&e!==null&&"then"in e}function EM(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===xQ&&"_payload"in e&&yQ(e._payload)}function bQ(e){const t=SQ(e),n=g.forwardRef((r,i)=>{let{children:s,...o}=r;EM(s)&&typeof af=="function"&&(s=af(s._payload));const a=g.Children.toArray(s),l=a.find(CQ);if(l){const c=l.props.children,u=a.map(d=>d===l?g.Children.count(c)>1?g.Children.only(null):g.isValidElement(c)?c.props.children:null:d);return h.jsx(t,{...o,ref:i,children:g.isValidElement(c)?g.cloneElement(c,void 0,u):null})}return h.jsx(t,{...o,ref:i,children:s})});return n.displayName=`${e}.Slot`,n}var wQ=bQ("Slot");function SQ(e){const t=g.forwardRef((n,r)=>{let{children:i,...s}=n;if(EM(i)&&typeof af=="function"&&(i=af(i._payload)),g.isValidElement(i)){const o=NQ(i),a=EQ(s,i.props);return i.type!==g.Fragment&&(a.ref=r?vu(r,o):o),g.cloneElement(i,a)}return g.Children.count(i)>1?g.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var kQ=Symbol("radix.slottable");function CQ(e){return g.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===kQ}function EQ(e,t){const n={...t};for(const r in t){const i=e[r],s=t[r];/^on[A-Z]/.test(r)?i&&s?n[r]=(...a)=>{const l=s(...a);return i(...a),l}:i&&(n[r]=i):r==="style"?n[r]={...i,...s}:r==="className"&&(n[r]=[i,s].filter(Boolean).join(" "))}return{...e,...n}}function NQ(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}const xk=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,yk=HT,TQ=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return yk(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(c=>{const u=n==null?void 0:n[c],d=s==null?void 0:s[c];if(u===null)return null;const f=xk(u)||xk(d);return i[c][f]}),a=n&&Object.entries(n).reduce((c,u)=>{let[d,f]=u;return f===void 0||(c[d]=f),c},{}),l=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((c,u)=>{let{class:d,className:f,...p}=u;return Object.entries(p).every(m=>{let[v,b]=m;return Array.isArray(b)?b.includes({...s,...a}[v]):{...s,...a}[v]===b})?[...c,d,f]:c},[]);return yk(e,o,l,n==null?void 0:n.class,n==null?void 0:n.className)},PQ=TQ("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-accent text-accent-contrast hover:bg-accent-hover",destructive:"bg-destructive text-white hover:bg-destructive-hover",outline:"border border-border bg-transparent text-text-100 hover:bg-bg-200",ghost:"bg-transparent text-text-200 hover:bg-bg-200 hover:text-text-100"},size:{sm:"h-8 px-3 text-xs",md:"h-9 px-4",lg:"h-11 px-6 text-base"}},defaultVariants:{variant:"default",size:"md"}}),ni=g.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},s)=>{const o=r?wQ:"button";return h.jsx(o,{ref:s,className:fe(PQ({variant:t,size:n}),e),...i})});ni.displayName="Button";function IQ({tool:e,input:t,onRespond:n,onInterrupt:r}){return h.jsxs("div",{"data-testid":"msg-line-permission",className:"min-w-0 max-w-full rounded-md border border-warning/40 bg-warning-dim/60 px-3 py-2.5 text-[13px]",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 mb-1.5",children:[h.jsx(m$,{className:"w-4 h-4 text-warning shrink-0"}),h.jsxs("span",{className:"min-w-0 font-medium text-text-100 truncate",children:["权限请求:",e]}),r?h.jsx("button",{type:"button",onClick:r,"data-testid":"msg-line-permission-interrupt","aria-label":"interrupt current turn",title:"中断当前轮次(不杀进程)",className:"ml-auto h-6 w-6 rounded-md flex items-center justify-center text-text-400 hover:bg-text-100/10 hover:text-text-200 transition-colors cursor-pointer",children:h.jsx(DT,{className:"w-3.5 h-3.5",strokeWidth:2})}):null]}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 mb-2 max-h-[140px] overflow-auto text-[12px] text-text-200",children:JSON.stringify(t,null,2)}),h.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.jsx(ni,{size:"sm",variant:"default",onClick:()=>n(!0,!1),"data-testid":"msg-line-permission-allow",children:"Allow"}),h.jsx(ni,{size:"sm",variant:"outline",onClick:()=>n(!0,!0),"data-testid":"msg-line-permission-allow-always",children:"Allow Always"}),h.jsx(ni,{size:"sm",variant:"destructive",onClick:()=>n(!1,!1),"data-testid":"msg-line-permission-deny",children:"Deny"})]})]})}function RQ({message:e}){return h.jsxs("div",{"data-testid":"msg-line-error",className:"flex min-w-0 max-w-full items-start gap-2 text-destructive text-[13px] rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2",children:[h.jsx(Kc,{className:"w-4 h-4 shrink-0 mt-0.5"}),h.jsx("span",{className:"min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}const bk=/\[attachment:(image|file):([^\]]+)\]/g;function MQ(e){const t=[];let n;for(;(n=bk.exec(e))!==null;){const i=n[2],s=decodeURIComponent(i.split("/").pop()??"file");t.push({type:n[1],url:i,fileName:s})}const r=e.replace(bk,"").trim();return{attachments:t,text:r}}function AQ(e,t){const n=t.filter(i=>i.status==="done"&&i.url);return n.length===0?e:n.map(i=>`[attachment:${i.mimeType.startsWith("image/")?"image":"file"}:${i.url}]`).join(`
|
|
504
504
|
`)+`
|
|
505
505
|
`+e}const LQ=/\[skill:(.+?):(\/[^\]]+)\]/g;function jQ(e){const t=[],n=e.replace(LQ,(r,i)=>(t.push(i),""));return{skills:t,text:t.length>0?n.trim():e}}function DQ({text:e,senderDisplayName:t,rewindTarget:n}){const r=gR(e),{attachments:i,text:s}=MQ(r),{skills:o,text:a}=jQ(s),{commandName:l,body:c}=yp(a),u=c.length>0;return u||i.length>0||!!l||o.length>0?(l||o.length>0)&&!u&&i.length===0?h.jsxs("div",{className:"flex min-w-0 max-w-full justify-end gap-1.5 py-2 mt-2","data-testid":"msg-line-user",children:[o.map((f,p)=>h.jsxs("span",{"data-testid":"user-skill-chip",className:"inline-flex items-center rounded-md bg-bg-200/60 px-2 py-0.5 text-[11px] font-mono text-text-300",children:["/",f]},`${f}-${p}`)),l?h.jsx("span",{className:"inline-flex items-center rounded-md bg-bg-200/60 px-2 py-0.5 text-[11px] font-mono text-text-300",children:l}):null]}):h.jsxs("div",{className:"group flex min-w-0 max-w-full flex-col items-end py-2 mt-2","data-testid":"msg-line-user",children:[h.jsxs("div",{className:"min-w-0 max-w-[85%] rounded-2xl rounded-br-sm bg-accent px-3.5 py-2 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:[i.length>0?h.jsx(OQ,{attachments:i}):null,o.length>0?h.jsx("div",{className:fe("flex flex-wrap gap-1.5",(u||l)&&"mb-1.5"),children:o.map((f,p)=>h.jsxs("span",{"data-testid":"user-skill-chip",className:"inline-flex items-center rounded-md bg-white/15 px-2 py-0.5 text-[11px] font-mono text-white/90",children:["/",f]},`${f}-${p}`))}):null,l?h.jsx("div",{className:fe("flex",u&&"mb-1.5"),children:h.jsx("span",{"data-testid":"user-command-chip",className:"inline-flex items-center rounded-md bg-white/15 px-2 py-0.5 text-[11px] font-mono text-white/90",children:l})}):null,u?h.jsx("div",{className:"text-[14px] text-white font-medium leading-relaxed",children:c}):null]}),t?h.jsx("div",{"data-testid":"user-msg-sender-label",className:"mt-1 text-[11px] text-text-400",children:t}):null,n?h.jsxs("button",{type:"button","data-testid":"user-msg-rewind","aria-label":"rewind to this message",title:"回退到这条消息(会撤销之后 CC 的文件编辑)",onClick:()=>n.onRewind(n.userMessageId),className:"mt-1 inline-flex items-center gap-1 h-6 px-1.5 rounded-md text-[11px] text-text-400 hover:bg-text-100/5 hover:text-text-200 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:[h.jsx(zT,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{children:"Rewind"})]}):null]}):null}function OQ({attachments:e}){return h.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1.5","data-testid":"user-attachment-row",children:e.map(t=>h.jsx(BQ,{attachment:t},t.url))})}function BQ({attachment:e}){return e.type==="image"?h.jsx("img",{src:e.url,alt:e.fileName,"data-testid":"user-attachment-image",className:"h-16 w-16 rounded object-cover shrink-0 border border-bg-300/50"}):h.jsxs("div",{"data-testid":"user-attachment-file",className:"flex items-center gap-1.5 rounded-md border border-bg-300 bg-bg-100/60 px-2 py-1 text-[12px] text-text-200",children:[h.jsx(Ro,{className:"h-3.5 w-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"max-w-[140px] truncate",children:e.fileName})]})}const zQ={"task-notification":"子任务通知","slash-command":"斜杠命令","local-command":"本地命令输出","system-reminder":"系统提醒","skill-hint":"Skill 注入","meta-text":"系统消息","attachment-skills":"技能列表","attachment-deferred-tools":"Deferred 工具变更"},$Q={"task-notification":Cw,"slash-command":_$,"local-command":BT,"system-reminder":Cw,"skill-hint":o0,"meta-text":jT,"attachment-skills":o0,"attachment-deferred-tools":s$};function FQ({metaKind:e,text:t}){const[n,r]=g.useState(!1),i=$Q[e];if(e==="slash-command"){const{commandName:o,commandMessage:a,commandArgs:l,body:c}=yp(t),u=o??(a?`/${a}`:null),d=!!(l&&l.length>0),f=c.length>0;return!u&&!d&&!f?null:h.jsxs("div",{"data-testid":"msg-line-user-meta","data-meta-kind":e,className:"flex min-w-0 max-w-full flex-col items-end gap-0.5 py-1",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 max-w-full",children:[u?h.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-md bg-bg-200/60 px-2 py-0.5 text-[11px] font-mono text-text-300 shrink-0",children:[h.jsx(i,{className:"w-3 h-3 opacity-70"}),u]}):null,d?h.jsx("span",{"data-testid":"user-meta-command-args",className:"min-w-0 text-[12px] text-text-200 whitespace-pre-wrap break-words max-w-[70ch] [overflow-wrap:anywhere]",children:l}):null]}),f?h.jsx("span",{className:"ml-2 max-w-[60%] truncate text-[11px] text-text-400",children:c}):null]})}const s=t.replace(/\s+/g," ").trim().slice(0,80);return h.jsxs("div",{"data-testid":"msg-line-user-meta","data-meta-kind":e,className:"flex min-w-0 max-w-full flex-col items-start gap-1 py-1",children:[h.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>r(o=>!o),className:fe("group inline-flex items-center gap-1.5 rounded-md border border-bg-200/60 bg-bg-100/40","px-2 py-1 text-[11px] text-text-400 hover:bg-bg-200/40 transition-colors max-w-full"),children:[h.jsx(i,{className:"w-3 h-3 opacity-70 shrink-0"}),h.jsx("span",{className:"font-medium shrink-0",children:zQ[e]}),h.jsx("span",{className:"truncate text-text-400/80 max-w-[60ch]",children:s}),n?h.jsx(ir,{className:"w-3 h-3 opacity-60 shrink-0"}):h.jsx(Un,{className:"w-3 h-3 opacity-60 shrink-0"})]}),n?h.jsx("pre",{"data-testid":"user-meta-body",className:"w-full max-w-full whitespace-pre-wrap break-words text-[11px] text-text-400 bg-bg-50/60 rounded-md p-2 border border-bg-200/60 [overflow-wrap:anywhere]",children:t}):null]})}function HQ({text:e,metaSource:t}){return t==="owner"?h.jsx("div",{className:"flex min-w-0 max-w-full flex-col items-start py-1.5","data-testid":"msg-line-owner-meta",children:h.jsxs("div",{className:fe("inline-flex min-w-0 max-w-[85%] items-start gap-2 rounded-md","border-l-[3px] border-accent bg-accent-dim px-3 py-2"),children:[h.jsx(Wz,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-accent","aria-label":"补充信息"}),h.jsx("span",{className:"min-w-0 text-[12px] leading-relaxed text-text-100 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}):h.jsxs("div",{className:"flex min-w-0 max-w-full items-start gap-1.5 py-1 text-[11px] text-text-400","data-testid":"msg-line-cc-meta",children:[h.jsx(jT,{className:"mt-0.5 h-3 w-3 shrink-0"}),h.jsx("span",{className:"min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}function zr(e,t){const r=new RegExp(`<${t}\\b[^>]*>([\\s\\S]*?)</${t}>`,"i").exec(e);if(!r)return;const i=r[1].trim();return i||void 0}function Zm(e,t){const r=new RegExp(`${t}\\s*=\\s*"([^"]+)"`,"i").exec(e);if(!r)return;const i=Number(r[1]);return Number.isFinite(i)?i:void 0}function NM(e){var i,s,o;const t={};if(!e)return t;t.taskId=zr(e,"task-id"),t.toolUseId=zr(e,"tool-use-id"),t.outputFile=zr(e,"output-file"),t.status=zr(e,"status"),t.summary=zr(e,"summary"),t.result=zr(e,"result");const n=zr(e,"usage");if(n){const a=(i=/<total_tokens>\s*(\d+)\s*<\/total_tokens>/i.exec(n))==null?void 0:i[1],l=(s=/<tool_uses>\s*(\d+)\s*<\/tool_uses>/i.exec(n))==null?void 0:s[1],c=(o=/<duration_ms>\s*(\d+)\s*<\/duration_ms>/i.exec(n))==null?void 0:o[1];a&&(t.totalTokens=Number(a)),l&&(t.toolUses=Number(l)),c&&(t.durationMs=Number(c))}const r=zr(e,"worktree");if(r)t.worktreePath=zr(r,"worktreePath"),t.worktreeBranch=zr(r,"worktreeBranch");else{const a=/<worktree\b([^>]*)\/>/i.exec(e);if(a){const l=a[1],c=/worktreePath\s*=\s*"([^"]+)"/i.exec(l),u=/worktreeBranch\s*=\s*"([^"]+)"/i.exec(l);c&&(t.worktreePath=c[1]),u&&(t.worktreeBranch=u[1])}}if(t.totalTokens===void 0&&t.toolUses===void 0&&t.durationMs===void 0){const a=Zm(e,"total_tokens"),l=Zm(e,"tool_uses"),c=Zm(e,"duration_ms");a!==void 0&&(t.totalTokens=a),l!==void 0&&(t.toolUses=l),c!==void 0&&(t.durationMs=c)}return t}function UQ(e){if(!e||!Number.isFinite(e))return null;if(e<1e3)return`${e}ms`;const t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;const n=Math.floor(t/60),r=Math.round(t-n*60);return`${n}m${r.toString().padStart(2,"0")}s`}function WQ({text:e,taskId:t,parentToolUseId:n}){const r=g.useMemo(()=>NM(e),[e]),[i,s]=g.useState(!1),o=t??r.taskId,a=n??r.toolUseId,l=r.status==="failed"?h.jsx(Ls,{className:"w-3.5 h-3.5 text-error"}):r.status==="completed"?h.jsx(ep,{className:"w-3.5 h-3.5 text-success"}):h.jsx(Jf,{className:"w-3.5 h-3.5 text-text-400"}),c=r.status??"unknown",u=UQ(r.durationMs);return h.jsxs("div",{"data-testid":"msg-line-agent-notification","data-task-id":o??"","data-parent-tool-use-id":a??"",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/40",children:[h.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>s(d=>!d),className:fe("flex w-full min-w-0 items-start gap-2 px-2.5 py-1.5 text-left text-[12px]","hover:bg-bg-200/40 rounded-md transition-colors"),children:[h.jsx("span",{className:"mt-[2px] shrink-0",children:l}),h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsxs("span",{className:"flex items-center gap-2 flex-wrap",children:[h.jsx("span",{className:"font-medium text-text-200",children:"子任务"}),h.jsx("span",{className:"text-text-400 text-[11px] font-mono",children:o?o.slice(0,12):"未知"}),h.jsx("span",{className:"text-text-400 text-[11px] uppercase tracking-wide",children:c}),u?h.jsxs("span",{className:"text-text-400 text-[11px] tabular-nums",children:["· ",u]}):null,r.totalTokens?h.jsxs("span",{className:"text-text-400 text-[11px] tabular-nums",children:["· ",r.totalTokens," tok"]}):null,r.toolUses?h.jsxs("span",{className:"text-text-400 text-[11px] tabular-nums",children:["· ",r.toolUses," tools"]}):null]}),r.summary?h.jsx("span",{className:"block truncate text-text-300 text-[12px] mt-0.5",children:r.summary}):null]}),i?h.jsx(ir,{className:"w-3.5 h-3.5 mt-[3px] text-text-400 shrink-0"}):h.jsx(Un,{className:"w-3.5 h-3.5 mt-[3px] text-text-400 shrink-0"})]}),i?h.jsxs("div",{"data-testid":"agent-notification-body",className:"min-w-0 border-t border-bg-200/60 px-3 py-2 text-[12px] text-text-300 space-y-2",children:[r.worktreePath||r.worktreeBranch?h.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-400",children:[h.jsx(Lx,{className:"w-3 h-3"}),r.worktreeBranch?h.jsx("span",{className:"font-mono",children:r.worktreeBranch}):null,r.worktreePath?h.jsx("span",{className:"truncate font-mono",children:r.worktreePath}):null]}):null,r.outputFile?h.jsxs("div",{className:"text-[11px] text-text-400",children:[h.jsx("span",{children:"输出文件:"}),h.jsx("span",{className:"font-mono",children:r.outputFile})]}):null,a?h.jsxs("div",{className:"text-[11px] text-text-400",children:[h.jsx("span",{children:"父工具调用:"}),h.jsx("span",{className:"font-mono",children:a})]}):null,r.result?h.jsx("div",{"data-testid":"agent-notification-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(eu,{remarkPlugins:[nu],components:So,children:r.result})}):h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细结果"})]}):null]})}const TM=g.createContext(null);function VQ({children:e}){const[t,n]=g.useState({agentId:null}),r=g.useCallback((o,a)=>{n({agentId:o,agentType:a})},[]),i=g.useCallback(()=>{n(o=>({agentId:null,agentType:o.agentType}))},[]),s=g.useMemo(()=>({state:t,open:r,close:i}),[t,r,i]);return h.jsx(TM.Provider,{value:s,children:e})}function PM(){return g.useContext(TM)}function qQ(e){if(e==null)return null;if(typeof e=="string")return e;if(Array.isArray(e)){const t=[];for(const n of e)if(n&&typeof n=="object"){const r=n;r.type==="text"&&typeof r.text=="string"&&t.push(r.text)}else typeof n=="string"&&t.push(n);return t.length?t.join(`
|
|
506
506
|
`):null}if(typeof e=="object"){const t=e;if(typeof t.text=="string")return t.text}return null}function wk(e){if(!e||!Number.isFinite(e))return null;if(e<1e3)return`${e}ms`;const t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;const n=Math.floor(t/60),r=Math.round(t-n*60);return`${n}m${r.toString().padStart(2,"0")}s`}function KQ(e){return!e||!Number.isFinite(e)?null:e<1e3?`${e} tok`:e<1e4?`${(e/1e3).toFixed(1)}k tok`:`${Math.round(e/1e3)}k tok`}const GQ={readCount:"read",searchCount:"search",bashCount:"bash",editFileCount:"edit",linesAdded:"+lines",linesRemoved:"-lines",otherToolCount:"other"};function XQ(e){if(!e)return[];const t=[];for(const[n,r]of Object.entries(e)){if(!r||r<=0)continue;const i=GQ[n]??n;t.push(`${i}:${r}`)}return t}function YQ({description:e,input:t,output:n,error:r,pending:i,notifications:s,toolResultExtra:o,progress:a}){const[l,c]=g.useState(!1),u=PM(),d=g.useMemo(()=>{if(!t||typeof t!="object")return null;const T=t;return typeof T.prompt=="string"?T.prompt:null},[t]),f=(o==null?void 0:o.prompt)??d,p=g.useMemo(()=>qQ(n),[n]),m=o==null?void 0:o.stats,v=a==null?void 0:a.stats,b=wk((m==null?void 0:m.durationMs)??(v==null?void 0:v.durationMs)),_=KQ((m==null?void 0:m.tokens)??(v==null?void 0:v.tokens)),x=XQ(m==null?void 0:m.toolStats),y=i&&(a!=null&&a.lastToolName)?`now:${a.lastToolName}`:null,w=!!(o!=null&&o.agentType||b||_||x.length>0||y),k=(o==null?void 0:o.agentId)??(a==null?void 0:a.agentId),C=g.useMemo(()=>s.map(T=>({taskId:T.taskId,text:T.text,parsed:NM(T.text)})),[s]),N=r?h.jsx(Ls,{className:"w-3.5 h-3.5 text-error"}):i?h.jsx(In,{className:"w-3.5 h-3.5 text-blue-400 animate-spin"}):h.jsx(ep,{className:"w-3.5 h-3.5 text-green-500"});return h.jsxs("div",{"data-testid":"msg-line-agent-call","data-pending":i?"true":"false","data-has-error":r?"true":"false","data-notification-count":s.length,"data-has-stats":w?"true":"false","data-agent-id":k??"",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/30",children:[h.jsxs("button",{type:"button","aria-expanded":l,onClick:()=>c(T=>!T),className:fe("flex w-full min-w-0 items-center gap-2 px-2.5 py-1.5 text-left text-[13px]","hover:bg-bg-200/40 rounded-md transition-colors"),children:[h.jsx("span",{className:"w-5 h-5 flex items-center justify-center text-[10px] rounded bg-violet-500/10 text-violet-500 shrink-0","aria-hidden":!0,children:h.jsx(I$,{className:"w-3 h-3"})}),h.jsx("span",{className:"shrink-0",children:N}),h.jsx("span",{className:"flex-1 min-w-0 truncate font-medium text-text-200",children:e}),w?null:s.length>0?h.jsxs("span",{className:"text-[11px] text-text-400 tabular-nums shrink-0",children:[s.length," 次通知"]}):null,k&&(u!=null&&u.open)?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"open-subagent-btn-header","data-agent-id":k,"aria-label":"打开子 agent 对话",onClick:T=>{T.stopPropagation(),u.open(k,o==null?void 0:o.agentType)},onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.stopPropagation(),T.preventDefault(),u.open(k,o==null?void 0:o.agentType))},className:"shrink-0 inline-flex items-center justify-center w-3.5 h-3.5 text-text-400 hover:text-text-200",children:h.jsx(qc,{className:"w-3.5 h-3.5"})}):null,l?h.jsx(ir,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(Un,{className:"w-3.5 h-3.5 text-text-400 shrink-0"})]}),i&&(a!=null&&a.description)?h.jsx("div",{"data-testid":"agent-call-progress-desc",className:"px-3 pt-0 pb-1 text-[12px] text-text-300 truncate",children:a.description}):null,w?h.jsxs("div",{"data-testid":"agent-call-stats",className:"flex items-center gap-1.5 flex-wrap px-3 pb-1.5 pt-0 text-[11px] text-text-400",children:[o!=null&&o.agentType?h.jsx("span",{"data-testid":"agent-call-stats-type",className:"inline-flex items-center rounded-sm bg-violet-500/10 px-1.5 py-0.5 text-violet-400 font-medium",children:o.agentType}):null,b?h.jsx("span",{className:"tabular-nums",children:b}):null,_?h.jsx("span",{className:"tabular-nums",children:_}):null,y?h.jsx("span",{"data-testid":"agent-call-stats-now",className:"font-mono tabular-nums text-blue-400",children:y}):null,x.map(T=>h.jsx("span",{className:"font-mono tabular-nums text-text-400/80",children:T},T)),s.length>0?h.jsxs("span",{className:"tabular-nums text-text-400/70",children:["· ",s.length," 次通知"]}):null]}):null,l?h.jsxs("div",{"data-testid":"agent-call-body",className:"min-w-0 border-t border-bg-200/60 px-3 py-2 space-y-3",children:[r?h.jsx("div",{className:"text-[12px] text-error whitespace-pre-wrap",children:r}):null,C.map((T,B)=>{const P=T.parsed,A=wk(P.durationMs);return h.jsxs("div",{"data-testid":"agent-call-notification","data-task-id":T.taskId??"",className:"min-w-0 rounded-md border border-bg-200/60 bg-bg-0/40 p-2 space-y-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-400 flex-wrap",children:[h.jsx("span",{className:"font-mono",children:(T.taskId??P.taskId??"未知").slice(0,12)}),h.jsx("span",{className:"uppercase tracking-wide",children:P.status??"unknown"}),A?h.jsxs("span",{className:"tabular-nums",children:["· ",A]}):null,P.totalTokens?h.jsxs("span",{className:"tabular-nums",children:["· ",P.totalTokens," tok"]}):null,P.toolUses?h.jsxs("span",{className:"tabular-nums",children:["· ",P.toolUses," tools"]}):null,P.worktreeBranch?h.jsxs("span",{className:"font-mono",children:["· ",P.worktreeBranch]}):null]}),P.summary?h.jsx("div",{className:"text-[12px] text-text-300",children:P.summary}):null,P.result?h.jsx("div",{"data-testid":"agent-call-notification-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(eu,{remarkPlugins:[nu],components:So,children:P.result})}):null]},`${T.taskId??"n"}-${B}`)}),f?h.jsxs("div",{"data-testid":"agent-call-prompt-block",className:"min-w-0 space-y-1",children:[h.jsx("div",{className:"text-[11px] text-text-400 font-medium",children:"任务指令"}),h.jsx("pre",{"data-testid":"agent-call-prompt",className:"max-w-full whitespace-pre-wrap break-words text-[11px] text-text-300 bg-bg-50/60 rounded p-2 border border-bg-200/60 max-h-64 overflow-auto [overflow-wrap:anywhere]",children:f})]}):null,p?h.jsxs("div",{"data-testid":"agent-call-result-block",className:"min-w-0 space-y-1",children:[h.jsx("div",{className:"text-[11px] text-text-400 font-medium",children:"子 agent 报告"}),h.jsx("div",{"data-testid":"agent-call-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(eu,{remarkPlugins:[nu],components:So,children:p})})]}):null,!p&&C.length===0&&!r&&!f?h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细信息"}):null,k&&(u!=null&&u.open)?h.jsx("div",{className:"flex justify-end",children:h.jsxs("button",{type:"button","data-testid":"open-subagent-btn","data-agent-id":k,onClick:()=>u.open(k,o==null?void 0:o.agentType),className:fe("inline-flex items-center gap-1 rounded-md border border-bg-200/60","bg-bg-100/40 hover:bg-bg-200/40 transition-colors","px-2 py-1 text-[11px] text-text-300"),children:[h.jsx(qc,{className:"w-3 h-3"}),h.jsx("span",{children:"打开子 agent 对话"})]})}):null]}):null]})}function IM({title:e,items:t,live:n,progressColor:r="bg-green-500",listKind:i,children:s}){const[o,a]=g.useState(!!n),l=t.length,c=t.filter(d=>d.status==="completed").length,u=l>0?Math.round(c/l*100):0;return h.jsxs("div",{"data-testid":"msg-line-checklist","data-list-kind":i,className:"min-w-0 max-w-full py-1",children:[h.jsxs("button",{type:"button",onClick:()=>a(d=>!d),"aria-expanded":o,className:"flex items-center gap-2.5 w-full text-left rounded-md px-1.5 py-1 hover:bg-text-100/5 cursor-pointer",children:[o?h.jsx(ir,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(Un,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"text-[13px] font-medium text-text-200",children:e}),h.jsxs("span",{className:"text-[11px] text-text-400 tabular-nums",children:[c,"/",l]}),h.jsx("div",{className:"flex-1 max-w-[120px] h-1.5 rounded-full bg-text-100/10 overflow-hidden",children:h.jsx("div",{className:fe("h-full rounded-full transition-all duration-300",r),style:{width:`${u}%`}})})]}),o?h.jsxs("div",{"data-testid":"checklist-body",className:"ml-6 mt-0.5",children:[h.jsx("div",{className:"space-y-px",children:t.map((d,f)=>h.jsxs("div",{className:"flex min-w-0 items-start gap-2 py-0.5 px-1",children:[h.jsx("span",{className:"w-4 h-4 mt-0.5 flex items-center justify-center shrink-0",children:d.status==="completed"?h.jsx(ul,{className:"w-3.5 h-3.5 text-green-500"}):d.status==="in_progress"&&n?h.jsx(In,{className:"w-3.5 h-3.5 text-blue-400 animate-spin"}):h.jsx("span",{className:"w-2 h-2 rounded-full border border-text-400/40"})}),h.jsx("span",{className:fe("min-w-0 text-[13px] leading-snug break-words [overflow-wrap:anywhere]",d.status==="completed"?"text-text-400 line-through":"text-text-200"),children:d.status==="in_progress"&&d.activeForm?d.activeForm:d.content})]},`${f}-${d.content}`))}),s]}):null]})}function QQ({todos:e,live:t}){return h.jsx(IM,{title:"Tasks",items:e,live:t,progressColor:"bg-green-500",listKind:"todo"})}function ZQ({tasks:e,live:t}){return h.jsx(IM,{title:"Plan",items:e,live:t,progressColor:"bg-blue-500",listKind:"plan"})}function JQ(e){if(!e||!Number.isFinite(e))return null;const t=Date.now()-e;if(t<0)return null;const n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const i=Math.floor(r/60);if(i<24)return`${i}h ago`;const s=Math.floor(i/24);if(s<7)return`${s}d ago`;const o=Math.floor(s/7);return o<5?`${o}w ago`:new Date(e).toISOString().slice(0,10)}function eZ(e){return(e.split("/").pop()??e)||e}function tZ({memories:e}){return!e||e.length===0?null:h.jsxs("div",{"data-testid":"memory-callout",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/30",children:[h.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[12px] text-text-300 border-b border-bg-200/60",children:[h.jsx(iz,{className:"w-3.5 h-3.5 text-amber-500 shrink-0"}),h.jsx("span",{className:"font-medium",children:"项目记忆"}),h.jsxs("span",{className:"text-text-400 tabular-nums",children:["· ",e.length]})]}),h.jsx("ul",{className:"divide-y divide-bg-200/40",children:e.map(t=>h.jsx(nZ,{memory:t},t.path))})]})}function nZ({memory:e}){const[t,n]=g.useState(!1),r=JQ(e.mtimeMs),i=e.content.replace(/\s+/g," ").trim().slice(0,80);return h.jsxs("li",{className:"px-2.5 py-1.5",children:[h.jsxs("button",{type:"button","aria-expanded":t,onClick:()=>n(s=>!s),className:fe("flex w-full items-center gap-1.5 text-left text-[12px]","hover:bg-bg-200/30 rounded-sm py-0.5"),children:[t?h.jsx(ir,{className:"w-3 h-3 text-text-400 shrink-0"}):h.jsx(Un,{className:"w-3 h-3 text-text-400 shrink-0"}),h.jsx("span",{className:"font-mono text-text-300 shrink-0 max-w-[20ch] truncate",title:e.path,children:eZ(e.path)}),h.jsx("span",{className:"flex-1 min-w-0 truncate text-text-400/80",children:i}),r?h.jsx("span",{className:"shrink-0 text-[11px] text-text-400 tabular-nums",children:r}):null]}),t?h.jsx("pre",{"data-testid":"memory-callout-body",className:"mt-1 max-w-full whitespace-pre-wrap break-words text-[12px] text-text-300 bg-bg-50/60 rounded-md p-2 border border-bg-200/60 [overflow-wrap:anywhere]",children:e.content}):null]})}function rZ({toolUseId:e,questions:t,onSubmit:n,onCancel:r,submittedAnswers:i}){const[s,o]=g.useState({}),[a,l]=g.useState({}),[c,u]=g.useState({}),[d,f]=g.useState(!1),[p,m]=g.useState(!1),v=i!==void 0&&Object.keys(i).length>0,b=v||p,_=!n&&!v,x=(C,N)=>{const T={labels:new Set,freeText:""};if(!v||!i)return T;const B=i[C];if(typeof B!="string")return T;const P=B.split(",").map(j=>j.trim()).filter(Boolean),A=new Set(N.map(j=>j.label)),I=new Set,R=[];for(const j of P)A.has(j)?I.add(j):R.push(j);return{labels:I,freeText:R.join(", ")}},y=g.useMemo(()=>t.every(C=>{if((c[C.question]??"").trim().length>0)return!0;if(C.multiSelect){const T=a[C.question];return!!(T&&T.size>0)}return typeof s[C.question]=="string"&&s[C.question].length>0}),[t,s,a,c]),w=async()=>{if(!y||d||b||_||!n)return;const C={};for(const N of t){const T=(c[N.question]??"").trim();if(N.multiSelect){const B=a[N.question],P=B?N.options.filter(A=>B.has(A.label)).map(A=>A.label):[];if(T.length>0&&P.push(T),P.length===0)continue;C[N.question]=P.join(", ")}else if(T.length>0)C[N.question]=T;else{const B=s[N.question];typeof B=="string"&&(C[N.question]=B)}}f(!0);try{await n(C),m(!0)}finally{f(!1)}},k=ku(()=>{w()});return h.jsxs("div",{"data-testid":"msg-line-question","data-tool-use-id":e,className:"min-w-0 max-w-full rounded-md border border-accent/40 bg-accent/5 px-3 py-2.5 text-[13px]",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 mb-2",children:[h.jsx(pz,{className:"w-4 h-4 text-accent shrink-0"}),h.jsx("span",{className:"min-w-0 font-medium text-text-100",children:"需要你的回答 / Need your answer"}),t.length>1?h.jsxs("span",{className:"ml-auto text-[12px] text-text-400","data-testid":"msg-line-question-count",children:[t.length," 个问题"]}):null]}),h.jsx("div",{className:"flex flex-col gap-3 mb-3",children:t.map((C,N)=>{const T=`q-${N}`,B=`${e}-${N}`,P=x(C.question,C.options),A=b||_,I=c[C.question]??"",R=v?P.freeText:p?(c[C.question]??"").trim():"";return h.jsxs("div",{"data-testid":"msg-line-question-item",children:[C.question?h.jsx("div",{className:"text-text-200 mb-1.5",children:C.question}):null,h.jsx("div",{className:"flex flex-col gap-1",children:C.options.map((j,z)=>{var D;const $=`${T}-${z}`,F=v?P.labels.has(j.label):C.multiSelect?!!((D=a[C.question])!=null&&D.has(j.label)):s[C.question]===j.label;return h.jsxs("label",{className:"flex min-w-0 items-start gap-2 cursor-pointer select-none py-1 px-2 rounded hover:bg-bg-100",children:[h.jsx("input",{type:C.multiSelect?"checkbox":"radio",name:B,value:j.label,checked:F,disabled:b||_,onChange:()=>{b||_||(C.multiSelect?l(O=>{const E=new Set(O[C.question]??[]);return E.has(j.label)?E.delete(j.label):E.add(j.label),{...O,[C.question]:E}}):o(O=>({...O,[C.question]:j.label})))},className:"mt-0.5","data-testid":"msg-line-question-option"}),h.jsxs("span",{className:"flex min-w-0 flex-col",children:[h.jsx("span",{className:"text-text-100 [overflow-wrap:anywhere]",children:j.label}),j.description?h.jsx("span",{className:"text-[12px] text-text-400 [overflow-wrap:anywhere]",children:j.description}):null]})]},$)})}),A?R.length>0?h.jsx("div",{className:"mt-2 rounded-lg border border-accent/15 bg-bg-100/60 px-3 py-2 text-[13px] leading-relaxed text-text-200 [overflow-wrap:anywhere]","data-testid":"msg-line-question-freetext-result",children:R}):null:h.jsx("textarea",{rows:3,value:I,placeholder:"或自行输入回答...",onChange:j=>{const z=j.target.value;u($=>({...$,[C.question]:z}))},...k,className:"mt-2 w-full resize-y rounded-lg border border-accent/20 bg-bg-000/60 px-3 py-2 text-[13px] leading-relaxed text-text-100 placeholder:text-text-400 outline-none transition-colors focus:border-accent/60 focus:bg-bg-000","data-testid":"msg-line-question-freetext"})]},T)})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(ni,{size:"sm",variant:"default",onClick:()=>void w(),disabled:!y||d||b||_,"data-testid":"msg-line-question-submit",children:b?"已提交 / Submitted":_?"已结束 / Ended":"提交 / Submit"}),r&&!b&&!_?h.jsx(ni,{size:"sm",variant:"ghost",onClick:()=>void r(),disabled:d,"data-testid":"msg-line-question-cancel",children:"跳过 / Skip"}):null]})]})}function iZ({toolUseId:e,questions:t,historicalAnswers:n,realtimeAnswers:r,onSubmit:i,onCancel:s}){const o=r??n,a=g.useCallback(async c=>{i&&await i(e,c)},[i,e]),l=g.useCallback(async()=>{s&&await s(e)},[s,e]);return h.jsx(rZ,{toolUseId:e,questions:t,onSubmit:i?a:void 0,...s?{onCancel:l}:{},submittedAnswers:o})}function sZ(){const e=new Map,t=(n,r)=>`${n}::${r}`;return{register(n,r,i){e.set(t(n,r),i)},resolve(n,r){return n?e.get(t(n,r))??null:null},reset(){e.clear()}}}const ml=sZ();function RM({lines:e,onPermissionRespond:t,onPermissionInterrupt:n,topSlot:r,onRewind:i,rewindableUserMessageIds:s,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v,onOpenFilePath:b,turnCollapse:_}){const x=g.useMemo(()=>$U(e),[e]),y=g.useMemo(()=>_?UU(x,_):null,[x,_]),w={onRewind:i,rewindableUserMessageIds:s,onPermissionRespond:t,onPermissionInterrupt:n,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v,onOpenFilePath:b};return h.jsxs("div",{"data-testid":"message-list",className:"flex w-full min-w-0 max-w-full flex-col gap-2 px-4 py-3",children:[r,y!==null?y.map(k=>oZ(k,w)):x.map(k=>lf(k,w))]})}function oZ(e,t){const n=`turn-${e.seq}`,r=e.query?lf(e.query,t):null,i=e.process.map(o=>aZ(o,t)),s=e.tail.map(o=>lf(o,t));return e.status==="running"?h.jsxs(Ze.Fragment,{children:[r,i,s]},n):h.jsxs(Ze.Fragment,{children:[r,h.jsx(tW,{status:e.status,...e.durationMs!==void 0?{durationMs:e.durationMs}:{},children:i}),s]},n)}function aZ(e,t){return e.kind==="tool-group"?h.jsx(ZU,{items:e.items,renderItemDetail:n=>lZ(n,t)},`tool-group-${e.seq}`):lf(e,t)}function lZ(e,t){const n=ml.resolve(e.toolKind,e.tool);return n?n.render({input:e.input,output:e.output,error:e.error,pending:e.pending,toolUseId:e.toolUseId,...t.fileSharingScope?{fileScope:t.fileSharingScope}:{},...t.onShareFile?{onShareFile:t.onShareFile}:{},...t.onOpenInTab?{onOpenInTab:t.onOpenInTab}:{},...t.onPreviewMarkdown?{onPreviewMarkdown:t.onPreviewMarkdown}:{}}):null}function lf(e,t){const{onRewind:n,rewindableUserMessageIds:r,onPermissionRespond:i,onPermissionInterrupt:s,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v,onOpenFilePath:b}=t,_=`${e.kind}-${e.seq}`;switch(e.kind){case"session-init":return null;case"user-text":{const x=typeof e.uuid=="string"?e.uuid:void 0,y=!!(n&&x&&(!r||r.has(x)));return h.jsx(DQ,{text:e.text,senderDisplayName:e.senderDisplayName,rewindTarget:y&&x&&n?{userMessageId:x,onRewind:n}:void 0},_)}case"user-meta":return h.jsx(FQ,{metaKind:e.metaKind,text:e.text},_);case"meta-text":return h.jsx(HQ,{text:e.text,metaSource:e.metaSource},_);case"agent-notification":return h.jsx(WQ,{text:e.text,taskId:e.taskId,parentToolUseId:e.parentToolUseId},_);case"assistant-text":{const x=typeof e.uuid=="string"?e.uuid:void 0,y=x&&(o||a)?{messageUuid:x,onFork:o,onQuickAsk:a}:void 0;return h.jsx(rQ,{text:iW(e.text),forkTarget:y,...b?{onOpenFilePath:b}:{}},_)}case"assistant-thinking":return h.jsx(iQ,{text:e.text},_);case"permission-inline":return h.jsx(IQ,{tool:e.tool,input:e.input,onRespond:i??(()=>{}),onInterrupt:s},_);case"error":return h.jsx(RQ,{message:e.message},_);case"turn-end":return null;case"merged-tool":return cZ(e,_,{fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v});case"merged-agent":return h.jsx(YQ,{description:e.description,input:e.input,output:e.output,error:e.error,pending:e.pending,notifications:e.notifications,toolResultExtra:e.toolResultExtra,progress:e.progress},_);case"plan-card":return h.jsx(ZQ,{tasks:e.tasks},_);case"todo-checklist":return h.jsx(QQ,{todos:e.todos},_);case"memory-callout":return h.jsx(tZ,{memories:e.memories},_);case"question-card":{const x=d===void 0||d.has(e.toolUseId);return h.jsx(iZ,{toolUseId:e.toolUseId,questions:e.questions,historicalAnswers:e.submittedAnswers,realtimeAnswers:l==null?void 0:l[e.toolUseId],onSubmit:x?c:void 0,...x&&u?{onCancel:u}:{}},_)}default:return null}}function cZ(e,t,n){const r=ml.resolve(e.toolKind,e.tool),i=r?r.render({input:e.input,output:e.output,error:e.error,pending:e.pending,toolUseId:e.toolUseId,...n.fileSharingScope?{fileScope:n.fileSharingScope}:{},...n.onShareFile?{onShareFile:n.onShareFile}:{},...n.onOpenInTab?{onOpenInTab:n.onOpenInTab}:{},...n.onPreviewMarkdown?{onPreviewMarkdown:n.onPreviewMarkdown}:{}}):null;return h.jsx(Ze.Fragment,{children:i??h.jsx(CM,{tool:e.tool,input:e.input,output:e.output,error:e.error,pending:e.pending,...n.fileSharingScope?{fileScope:n.fileSharingScope}:{},...n.onShareFile?{onShareFile:n.onShareFile}:{},...n.onOpenInTab?{onOpenInTab:n.onOpenInTab}:{},...n.onPreviewMarkdown?{onPreviewMarkdown:n.onPreviewMarkdown}:{}})},t)}const uZ={builtin:"Commands",global:"Global",project:"Project",plugin:"Plugin"},Sk={builtin:0,global:1,project:2,plugin:3};function dZ({query:e,skills:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>MM(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++)a[d].source!==u&&(c.add(d),u=a[d].source);return c},[a]);return g.useEffect(()=>{a.length===0&&(s==null||s())},[a.length,s]),g.useEffect(()=>{var c;try{(c=o.current)==null||c.scrollIntoView({block:"nearest"})}catch{}},[n]),a.length===0?null:h.jsx("div",{"data-testid":"cc-skill-selector",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 max-h-[320px] overflow-y-auto rounded-2xl border border-bg-300 bg-bg-50 shadow-lg",children:a.map((c,u)=>{const d=u===n,f=l.has(u);return h.jsxs(Ze.Fragment,{children:[f?h.jsx("div",{className:"sticky top-0 z-10 bg-bg-50/95 backdrop-blur-sm px-4 py-2 text-[10px] font-semibold uppercase tracking-wider text-text-400/70 border-b border-bg-200/60",children:uZ[c.source]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":`cc-skill-item-${c.name}`,onMouseEnter:()=>r(u),onClick:()=>i(c),className:fe("flex items-center gap-2.5 px-4 py-2 cursor-pointer transition-colors duration-75",d?"bg-[var(--text-100-dim)]":"hover:bg-bg-100/60"),children:[h.jsxs("code",{className:"text-[12px] font-mono font-semibold text-text-100 shrink-0",children:["/",c.name]}),c.description?h.jsx("span",{className:"text-[11px] text-text-300 truncate ml-auto",children:c.description}):null]})]},`${c.source}/${c.name}`)})})}function MM(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>i.name.toLowerCase().includes(n)||(i.description??"").toLowerCase().includes(n)):e.slice();return r.sort((i,s)=>(Sk[i.source]??9)-(Sk[s.source]??9)),r.slice(0,30)}const hZ=g.createContext(null);function fZ(){return g.useContext(hZ)}const pZ={builtin:"Built-in",global:"Global",project:"Project",policy:"Policy",plugin:"Plugin",persona:"My personas",contact:"People","remote-persona":"Remote personas"},kk={builtin:0,global:1,project:2,policy:3,plugin:4,persona:5,contact:6,"remote-persona":7};function cf(e){switch(e.kind){case"persona":return"persona";case"contact":return"contact";case"remote-persona":return"remote-persona";case"cc-agent":return e.agent.source}}function mZ(e){switch(e.kind){case"persona":return`persona/${e.persona.personaId}`;case"contact":return`contact/${e.contact.deviceId}`;case"remote-persona":return`remote/${e.deviceId}/${e.persona.personaId}`;case"cc-agent":return`${e.agent.source}/${e.agent.name}`}}function gZ(e){switch(e.kind){case"persona":return`${e.persona.personaId} ${e.persona.label}`.toLowerCase();case"contact":return`${e.contact.displayName} ${e.contact.deviceId}`.toLowerCase();case"remote-persona":return`${e.persona.personaId} ${e.persona.label}`.toLowerCase();case"cc-agent":{const t=e.agent;return`${t.name} ${t.description??""} ${t.whenToUse??""}`.toLowerCase()}}}function vZ(e){switch(e.kind){case"persona":return{displayName:`@persona/${e.persona.personaId}`,description:e.persona.label,testid:`cc-agent-item-persona-${e.persona.personaId}`};case"contact":return{displayName:`@${e.contact.displayName}`,description:e.contact.deviceId,testid:`cc-agent-item-contact-${e.contact.deviceId}`};case"remote-persona":return{displayName:`@persona/${e.persona.personaId}`,description:e.persona.label,testid:`cc-agent-item-remote-${e.deviceId}-${e.persona.personaId}`};case"cc-agent":return{displayName:`@${e.agent.name}`,description:e.agent.description,whenToUse:e.agent.whenToUse,plugin:e.agent.plugin,testid:`cc-agent-item-${e.agent.name}`}}}function AM(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>gZ(i).includes(n)):e.slice();return r.sort((i,s)=>(kk[cf(i)]??9)-(kk[cf(s)]??9)),r.slice(0,30)}function Ck({query:e,entries:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>AM(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++){const f=cf(a[d]);f!==u&&(c.add(d),u=f)}return c},[a]);return g.useEffect(()=>{a.length===0&&(s==null||s())},[a.length,s]),g.useEffect(()=>{var c;try{(c=o.current)==null||c.scrollIntoView({block:"nearest"})}catch{}},[n]),a.length===0?null:h.jsx("div",{"data-testid":"cc-agent-selector",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 max-h-[320px] overflow-y-auto rounded-2xl border border-bg-300 bg-bg-50 shadow-lg",children:a.map((c,u)=>{const d=u===n,f=l.has(u),p=cf(c),m=vZ(c);return h.jsxs(Ze.Fragment,{children:[f?h.jsx("div",{"data-testid":`cc-agent-group-header-${p}`,"data-source":p,className:"sticky top-0 z-10 bg-bg-50/95 backdrop-blur-sm px-4 py-2 text-[10px] font-semibold uppercase tracking-wider text-text-400/70 border-b border-bg-200/60",children:pZ[p]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":m.testid,onMouseEnter:()=>r(u),onClick:()=>i(c),className:fe("flex items-center gap-2.5 px-4 py-2 cursor-pointer transition-colors duration-75",d?"bg-[var(--text-100-dim)]":"hover:bg-bg-100/60"),children:[h.jsx("code",{className:"text-[12px] font-mono font-semibold text-text-100 shrink-0",children:m.displayName}),m.description?h.jsx("span",{className:"text-[11px] text-text-300 truncate ml-2",children:m.description}):null,m.whenToUse?h.jsx("span",{className:"text-[10px] text-text-400/70 italic truncate ml-auto",children:m.whenToUse}):null,m.plugin?h.jsx("span",{className:"text-[10px] text-text-400/70 ml-2 shrink-0",children:m.plugin}):null]})]},mZ(c))})})}function _Z({attachment:e,onRemove:t,onOpenPreview:n}){const r=e.mimeType.startsWith("image/"),i=e.status==="error",s=e.status==="uploading",o=r&&e.status==="done"&&!!e.previewUrl&&!!n;return h.jsxs("div",{"data-testid":`attachment-pill-${e.id}`,className:fe("group relative flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[12px] transition-colors",i?"border-red-400/40 bg-red-500/5":"border-bg-300 bg-bg-100"),children:[r&&e.previewUrl?h.jsxs("div",{className:"relative h-7 w-7 shrink-0",children:[h.jsx("img",{src:e.previewUrl,alt:e.fileName,onClick:o?n:void 0,"data-testid":`attachment-thumb-${e.id}`,className:fe("h-7 w-7 rounded object-cover",o&&"cursor-pointer hover:opacity-80",s&&"opacity-40")}),s?h.jsx(In,{"data-testid":`attachment-spinner-${e.id}`,className:"absolute inset-0 m-auto h-3.5 w-3.5 animate-spin text-text-200"}):null]}):h.jsx("div",{className:"relative flex h-7 w-7 items-center justify-center rounded bg-text-100/5 shrink-0",children:s?h.jsx(In,{"data-testid":`attachment-spinner-${e.id}`,className:"h-3.5 w-3.5 animate-spin text-text-400"}):h.jsx(Ro,{className:"h-3.5 w-3.5 text-text-400"})}),h.jsx("span",{className:fe("max-w-[120px] truncate text-text-200",s&&"text-text-400"),title:e.error??e.fileName,children:e.fileName}),i?h.jsx(Ls,{className:"h-3 w-3 text-red-400 shrink-0"}):null,h.jsx("button",{type:"button",onClick:t,"data-testid":`attachment-remove-${e.id}`,className:"flex h-4 w-4 items-center justify-center rounded-full text-text-400 hover:text-text-100 hover:bg-text-100/10 transition-colors cursor-pointer shrink-0","aria-label":"remove",children:h.jsx(Dr,{className:"h-3 w-3"})})]})}function xZ({attachments:e,onRemove:t,onOpenPreview:n}){return e.length===0?null:h.jsx("div",{"data-testid":"attachment-row",className:"flex flex-wrap gap-1.5 mb-2 px-1",children:e.map(r=>h.jsx(_Z,{attachment:r,onRemove:()=>t(r.id),onOpenPreview:n?()=>n(r):void 0},r.id))})}class Yl extends Error{constructor(t,n,r){super(n),this.code=t,this.status=r,this.name="UploadAttachmentError"}}async function yZ(e){if(!e.httpBaseUrl)throw new Yl("TUNNEL_NOT_READY","daemon httpBaseUrl unavailable");if(!e.httpToken)throw new Yl("NO_AUTH","daemon httpToken unavailable");const t=new URLSearchParams({sessionId:e.sessionId,fileName:e.file.name,mimeType:e.file.type||"application/octet-stream"}),n=`${e.httpBaseUrl.replace(/\/$/,"")}/attachments/upload?${t.toString()}`;let r;try{r=await fetch(n,{method:"POST",headers:{Authorization:`Bearer ${e.httpToken}`,"Content-Type":e.file.type||"application/octet-stream"},body:e.file})}catch(i){throw new Yl("NETWORK_ERROR",i.message)}if(!r.ok){let i="UPLOAD_FAILED",s=`HTTP ${r.status}`;try{const o=await r.json();o.code&&(i=o.code),o.message&&(s=o.message)}catch{}throw new Yl(i,s,r.status)}return await r.json()}const Ek=25*1024*1024,bZ="image/*,.txt,.md,.markdown,.csv,.json,.log,.yaml,.yml,.html,.xml,.pdf",wZ=["image/","text/"],SZ=new Set(["application/json","application/xml","application/x-yaml","application/yaml","application/pdf"]),kZ=new Set(["txt","md","markdown","csv","json","log","yaml","yml","html","xml","pdf"]);function CZ(e){var r;const t=(e.type||"").toLowerCase();if(t&&wZ.some(i=>t.startsWith(i))||t&&SZ.has(t))return!0;const n=((r=e.name.split(".").pop())==null?void 0:r.toLowerCase())??"";return n.length>0&&kZ.has(n)}let EZ=0;const NZ=()=>`att-${++EZ}-${Date.now()}`;function TZ(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(typeof r.result=="string"?r.result:""),r.onerror=()=>n(r.error??new Error("read failed")),r.readAsDataURL(e)})}function PZ(e){const[t,n]=g.useState(e.initial??[]),r=g.useCallback(async o=>{const a=Array.from(o);if(a.length===0)return;const l=[],c=[],u=[];for(const d of a){const f={id:NZ(),fileName:d.name,mimeType:d.type||"application/octet-stream"};if(!CZ(d)){c.push({...f,url:null,status:"error",error:"不支持的文件类型"});continue}if(d.size>Ek){c.push({...f,url:null,status:"error",error:`超过 ${Math.round(Ek/1024/1024)}MB 上限`});continue}if(e.sessionId==null){u.push({id:f.id,file:d,mimeType:f.mimeType}),c.push({...f,url:null,status:"uploading"});continue}const p=f.mimeType.startsWith("image/")?URL.createObjectURL(d):void 0;c.push({...f,url:null,status:"uploading",...p?{previewUrl:p}:{}}),l.push({id:f.id,file:d})}n(d=>[...d,...c]);for(const d of u)try{const f=await TZ(d.file);n(p=>p.map(m=>m.id===d.id?{...m,url:f,status:"done",...d.mimeType.startsWith("image/")?{previewUrl:f}:{}}:m))}catch(f){n(p=>p.map(m=>m.id===d.id?{...m,status:"error",error:f.message??"read failed"}:m))}l.length!==0&&await Promise.all(l.map(async d=>{try{const f=await yZ({httpBaseUrl:e.httpBaseUrl,httpToken:e.httpToken,sessionId:e.sessionId,file:d.file});n(p=>p.map(m=>m.id===d.id?{...m,url:f.url,status:"done"}:m))}catch(f){const p=f instanceof Yl?f.code:"UPLOAD_FAILED",m=f.message??"upload failed";n(v=>v.map(b=>b.id===d.id?{...b,status:"error",error:`${p}: ${m}`}:b))}}))},[e.sessionId,e.httpBaseUrl,e.httpToken]),i=g.useCallback(o=>{n(a=>a.filter(l=>l.id!==o))},[]),s=g.useCallback(()=>{n([])},[]);return{attachments:t,setAttachments:n,addFiles:r,removeAttachment:i,clearAttachments:s}}const R0=new Map,IZ=[];function Nk(e){if(e)return R0.get(e)}function Tk(e,t){e&&(t.draft.length===0&&t.attachments.length===0?R0.delete(e):R0.set(e,t))}function RZ(e,t){return e.replace(/(^|\s)\/(\S+)/g,(n,r,i)=>{const s=t.find(o=>o.name===i&&o.path);return s!=null&&s.path?`${r}[skill:${i}:${s.path}]`:n})}function MZ({api:e,cwd:t,sessionKey:n,onSend:r,disabled:i,onNewSession:s,onClearSession:o,tool:a,spawnableContacts:l=IZ,ensureRemotePersonas:c,remotePersonasByDeviceId:u}){const d=Nk(n),[f,p]=g.useState((d==null?void 0:d.draft)??""),[m,v]=g.useState(!1),b=g.useRef(null),_=g.useRef(!1),x=g.useCallback(()=>{_.current=!0},[]),y=g.useCallback(()=>{_.current=!1},[]),w=Zf(),{attachments:k,setAttachments:C,addFiles:N,removeAttachment:T,clearAttachments:B}=PZ({httpBaseUrl:w.httpBaseUrl,httpToken:w.httpToken,sessionId:n,initial:(d==null?void 0:d.attachments)??[]}),[P,A]=g.useState([]),[I,R]=g.useState(!1),[j,z]=g.useState(0),[$,F]=g.useState(!1),[D,O]=g.useState([]),[E,H]=g.useState(!1),[V,L]=g.useState(0),[ne,ae]=g.useState(!1),[G,ye]=g.useState([]),[Fe,ue]=g.useState(!1),[Ie,Re]=g.useState(null),[Ke,ve]=g.useState(!1),ze=g.useRef(null),fn=g.useMemo(()=>{const se=[];return s&&se.push({name:"new",source:"builtin",description:"在当前目录下新建会话"}),o&&n&&se.push({name:"clear",source:"builtin",description:"清除当前会话"}),se},[s,o,n]),it=g.useMemo(()=>[...fn,...P],[fn,P]),Rt=g.useMemo(()=>{const se=f.match(/^\/(\S*)$/);return se?se[1]:null},[f]),Gt=Rt!==null&&!$,Mt=g.useMemo(()=>Rt!==null?MM(it,Rt):[],[it,Rt]),bt=g.useMemo(()=>{const se=f.match(/^@(\S*)$/);return se?se[1]:null},[f]),Qe=bt!==null&&!ne,st=g.useMemo(()=>Ie?((u==null?void 0:u.get(Ie.deviceId))??[]).map(q=>({kind:"remote-persona",persona:q,deviceId:Ie.deviceId})):[...D.map(se=>({kind:"cc-agent",agent:se})),...G.map(se=>({kind:"persona",persona:se})),...l.map(se=>({kind:"contact",contact:se}))],[Ie,u,D,G,l]),wt=g.useMemo(()=>bt!==null?AM(st,bt):[],[st,bt]),pn=g.useRef(f);g.useEffect(()=>{f!==pn.current&&(F(!1),ae(!1),pn.current=f)},[f]);const on=g.useCallback(()=>{F(!0)},[]),U=g.useCallback(()=>{ae(!0)},[]),Z=g.useRef(f),_e=g.useRef(k);g.useEffect(()=>{Z.current=f},[f]),g.useEffect(()=>{_e.current=k},[k]);const ke=g.useRef(n);g.useEffect(()=>{const se=ke.current;if(se===n)return;Tk(se,{draft:Z.current,attachments:_e.current});const q=Nk(n);p((q==null?void 0:q.draft)??""),C((q==null?void 0:q.attachments)??[]),z(0),L(0),F(!1),ae(!1),Re(null),ze.current=null,ve(!1),queueMicrotask(()=>{q!=null&&q.draft?LM(b.current):Yo(b.current)}),ke.current=n},[n,C]),g.useEffect(()=>()=>{Tk(ke.current,{draft:Z.current,attachments:_e.current})},[]),g.useEffect(()=>{z(0)},[Rt]),g.useEffect(()=>{L(0)},[bt]),g.useEffect(()=>{bt===null&&Ie&&(Re(null),ze.current=null,ve(!1))},[bt,Ie]),g.useEffect(()=>{if(!Gt||I)return;if(!e){R(!0);return}let se=!1;return(async()=>{try{const q=await e.skillsList(t,a);se||(A(q.skills??[]),R(!0))}catch{se||R(!0)}})(),()=>{se=!0}},[Gt,I,e,t,a]),g.useEffect(()=>{if(!Qe||E)return;if(!e){H(!0);return}let se=!1;return(async()=>{try{const q=await e.agentsList(t,a);se||(O(q.agents??[]),H(!0))}catch{se||H(!0)}})(),()=>{se=!0}},[Qe,E,e,t,a]),g.useEffect(()=>{if(!Qe||Fe)return;if(!e){ue(!0);return}let se=!1;return(async()=>{try{const q=await e.personaList();se||(ye((q.personas??[]).map(we=>({personaId:we.personaId,label:we.label}))),ue(!0))}catch{se||ue(!0)}})(),()=>{se=!0}},[Qe,Fe,e]);const He=g.useCallback(se=>{switch(se.kind){case"persona":p(`@persona/${se.persona.personaId} `);break;case"cc-agent":p(`@"${se.agent.name} (agent)" `);break;case"contact":{const q=se.contact.deviceId;Re({deviceId:q,displayName:se.contact.displayName}),ze.current=q,ve(!0),Promise.resolve(c==null?void 0:c(q)).finally(()=>{ze.current===q&&ve(!1)}),p("@"),ae(!1),setTimeout(()=>{var we;return(we=b.current)==null?void 0:we.focus()},0);return}case"remote-persona":p(`@persona/${se.persona.personaId}@${se.deviceId} `),Re(null);break}ae(!1),setTimeout(()=>{var q;return(q=b.current)==null?void 0:q.focus()},0)},[c]),Tt=g.useCallback(()=>{Re(null),ze.current=null,ve(!1),p("@"),setTimeout(()=>{var se;return(se=b.current)==null?void 0:se.focus()},0)},[]),Xt=g.useCallback(se=>{if(se.source==="builtin"&&se.name==="new"&&s){p(""),B(),Yo(b.current),s(t);return}if(se.source==="builtin"&&se.name==="clear"&&o){p(""),B(),Yo(b.current),o();return}p(`/${se.name} `),setTimeout(()=>{var q;return(q=b.current)==null?void 0:q.focus()},0)},[s,t,B,o]),Yt=g.useCallback(async()=>{const se=f.trim(),q=k.filter(we=>we.status==="done");if(!(!se&&q.length===0)&&!(m||i)){if(se==="/new"&&s){v(!0);try{await s(t),p(""),B(),Yo(b.current)}finally{v(!1)}return}if(se==="/clear"&&o){v(!0);try{await o(),p(""),B(),Yo(b.current)}finally{v(!1)}return}v(!0);try{const we=a==="codex"?RZ(se,P):se,ht=AQ(we,k);await r(ht),p(""),B(),Yo(b.current)}finally{v(!1)}}},[f,k,m,i,r,s,t,B,o,a,P]);return{draft:f,setDraft:p,sending:m,textareaRef:b,isComposingRef:_,onCompositionStart:x,onCompositionEnd:y,attachments:k,addFiles:N,removeAttachment:T,skillSelectorVisible:Gt,filteredSkills:Mt,slashQuery:Rt??"",activeSkillIdx:j,setActiveSkillIdx:z,selectSkill:Xt,dismissSkillSelector:on,agentSelectorVisible:Qe,filteredAgents:wt,mentionQuery:bt,activeAgentIdx:V,setActiveAgentIdx:L,selectAgent:He,dismissAgentSelector:U,drilldown:Ie,drilldownLoading:Ke,exitDrilldown:Tt,doSend:Yt}}const AZ=120;function LM(e){e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,AZ)}px`)}function Yo(e){e&&(e.style.height="auto")}const LZ={spawnableContacts:[],ensureRemotePersonas:()=>Promise.resolve(),remotePersonasByDeviceId:new Map},jZ=g.createContext(LZ);function DZ(){return g.useContext(jZ)}function OZ({url:e,fileName:t,onClose:n}){const[r,i]=g.useState(!1);g.useEffect(()=>{const o=a=>{a.key==="Escape"&&n()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[n]);const s=async()=>{try{const a=await(await fetch(e)).blob();await navigator.clipboard.write([new ClipboardItem({[a.type]:a})]),i(!0),setTimeout(()=>i(!1),2e3)}catch{Pk(e,t)}};return h.jsx("div",{"data-testid":"image-lightbox",className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60",onClick:n,role:"dialog","aria-modal":"true",children:h.jsxs("div",{className:"relative",onClick:o=>o.stopPropagation(),children:[h.jsx("img",{src:e,alt:t,className:"max-h-[90vh] max-w-[92vw] rounded-lg object-contain shadow-2xl"}),h.jsxs("div",{className:"absolute right-2 top-2 flex items-center gap-1.5",children:[h.jsxs("button",{type:"button",onClick:s,"data-testid":"image-lightbox-copy",className:"flex cursor-pointer items-center gap-1 rounded-full border border-bg-300 bg-bg-50/95 px-2 py-0.5 text-[11px] font-medium text-text-200 shadow transition-colors hover:bg-bg-100",children:[h.jsx(tp,{className:"h-3 w-3"}),r?"Copied":"Copy"]}),h.jsxs("button",{type:"button",onClick:()=>Pk(e,t),"data-testid":"image-lightbox-save",className:"flex cursor-pointer items-center gap-1 rounded-full border border-bg-300 bg-bg-50/95 px-2 py-0.5 text-[11px] font-medium text-text-200 shadow transition-colors hover:bg-bg-100",children:[h.jsx(wz,{className:"h-3.5 w-3.5"}),"Save"]}),h.jsx("button",{type:"button",onClick:n,"data-testid":"image-lightbox-close","aria-label":"close",className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border border-bg-300 bg-bg-50/95 text-text-300 transition-colors hover:bg-bg-100 hover:text-text-100",children:h.jsx(Dr,{className:"h-3 w-3"})})]})]})})}function Pk(e,t){const n=document.createElement("a");n.href=e,n.download=t||"image",n.click()}const Ik=1e3,BZ=5e3;function kd(e){if(!e)return"null";if(e===document.body)return"body";const t=e.getAttribute("data-testid"),n=typeof e.className=="string"&&e.className.trim()?`.${e.className.trim().split(/\s+/).slice(0,3).join(".")}`:"";return`${e.tagName.toLowerCase()}${e.id?`#${e.id}`:""}${t?`[${t}]`:""}${n}`}function zZ({meta:e,api:t,cwd:n,tool:r,onSend:i,sessionKey:s,disabled:o=!1,placeholder:a,className:l,awaitingUser:c=!1,onAbort:u,onNewSession:d,onClearSession:f,configSlot:p,aboveSlot:m}){const v=(e==null?void 0:e.streamInProgress)??!1,b=(e==null?void 0:e.contextPct)??null,_=b==null?"":b>=80?"text-red-400":b>=50?"text-amber-400":"text-text-500",x=g.useRef(null),y=DZ(),w=MZ({...t?{api:t}:{},cwd:n,...r?{tool:r}:{},sessionKey:s,onSend:i,disabled:o,...d?{onNewSession:d}:{},...f?{onClearSession:f}:{},spawnableContacts:y.spawnableContacts,ensureRemotePersonas:y.ensureRemotePersonas,remotePersonasByDeviceId:y.remotePersonasByDeviceId}),{draft:k,setDraft:C,sending:N,textareaRef:T,attachments:B,addFiles:P,removeAttachment:A,skillSelectorVisible:I,filteredSkills:R,slashQuery:j,activeSkillIdx:z,setActiveSkillIdx:$,selectSkill:F,dismissSkillSelector:D,agentSelectorVisible:O,filteredAgents:E,mentionQuery:H,activeAgentIdx:V,setActiveAgentIdx:L,selectAgent:ne,dismissAgentSelector:ae,drilldown:G,drilldownLoading:ye,exitDrilldown:Fe,doSend:ue}=w,Ie=fZ();g.useEffect(()=>{if(!Ie||Ie.signal===0||s===null||Ie.sessionId!==s)return;const{signal:q}=Ie;console.log("[chat-focus] 收到聚焦信号",{sessionKey:s,signal:q,delayMs:Ik,activeElement:kd(document.activeElement)});let we=null,ht=null,an=null;const _l=setTimeout(()=>{if(we=T.current,!we){console.warn("[chat-focus] textarea 已不在,放弃聚焦",{sessionKey:s,signal:q});return}we.focus(),console.log("[chat-focus] focus() 已执行",{sessionKey:s,signal:q,landed:document.activeElement===we,activeElement:kd(document.activeElement)}),ht=xl=>{const zo=kd(xl.relatedTarget);setTimeout(()=>{console.warn("[chat-focus] STOLEN 输入框失焦",{sessionKey:s,signal:q,relatedTarget:zo,activeElementAfterTick:kd(document.activeElement)})},0)},we.addEventListener("blur",ht,{once:!0}),an=setTimeout(()=>{we&&ht&&we.removeEventListener("blur",ht)},BZ)},Ik);return()=>{clearTimeout(_l),an&&clearTimeout(an),we&&ht&&we.removeEventListener("blur",ht)}},[Ie==null?void 0:Ie.signal]);const Re=!!t,Ke=N||o||v,ze=(k.trim().length>0||B.some(q=>q.status==="done"))&&!o&&!N&&!c,fn=a??(c?"Answer the question above first...":Ke?"Queue a message...":`Message ${zx(r)}...`),it=g.useRef(!1),Rt=g.useCallback(()=>{it.current=!0},[]),Gt=g.useCallback(()=>{it.current=!1},[]),Mt=g.useCallback(q=>{if(I&&R.length>0){if(q.key==="ArrowDown")return q.preventDefault(),$(z>=R.length-1?0:z+1),!0;if(q.key==="ArrowUp")return q.preventDefault(),$(z<=0?R.length-1:z-1),!0;if(q.key==="Tab"||q.key==="Enter"&&!q.shiftKey){q.preventDefault();const we=R[z];return we&&F(we),!0}if(q.key==="Escape")return q.preventDefault(),D(),!0}return!1},[I,R,z,$,F,D]),bt=g.useCallback(q=>{if(O&&E.length>0){if(q.key==="ArrowDown")return q.preventDefault(),L(V>=E.length-1?0:V+1),!0;if(q.key==="ArrowUp")return q.preventDefault(),L(V<=0?E.length-1:V-1),!0;if(q.key==="Tab"||q.key==="Enter"&&!q.shiftKey){q.preventDefault();const we=E[V];return we&&ne(we),!0}if(q.key==="Escape")return q.preventDefault(),G?Fe():ae(),!0}return!1},[O,E,V,L,ne,ae,G,Fe]),Qe=g.useCallback(q=>{const we=q.nativeEvent;q.key==="Enter"&&GI({compositionActive:it.current,nativeIsComposing:we.isComposing,keyCode:we.keyCode})||Mt(q)||bt(q)||XI({key:q.key,shiftKey:q.shiftKey,compositionActive:it.current,nativeIsComposing:we.isComposing,keyCode:we.keyCode})&&(q.preventDefault(),ze&&ue())},[Mt,bt,ze,ue]),st=g.useCallback(q=>{C(q.target.value),LM(q.target)},[C]),wt=g.useCallback(q=>{q.target.files&&P(q.target.files),q.target.value=""},[P]),pn=g.useCallback(q=>{if(!Re)return;const we=Array.from(q.clipboardData.items).map(ht=>ht.getAsFile()).filter(ht=>!!(ht&&ht.type.startsWith("image/")));we.length!==0&&(q.preventDefault(),P(we))},[P,Re]),[on,U]=g.useState(null),Z=g.useCallback(q=>{q.previewUrl&&U({url:q.previewUrl,name:q.fileName})},[]),[_e,ke]=g.useState(!1),He=g.useCallback(q=>{Re&&(q.preventDefault(),ke(!0))},[Re]),Tt=g.useCallback(()=>ke(!1),[]),Xt=g.useCallback(q=>{Re&&(q.preventDefault(),ke(!1),q.dataTransfer.files.length>0&&P(q.dataTransfer.files))},[P,Re]),Yt=v&&!c&&typeof u=="function",se=o||c;return h.jsxs("div",{"data-testid":"chat-input",className:fe("shrink-0 border-t border-bg-300/20 px-4 py-3",l),onDragOver:He,onDragLeave:Tt,onDrop:Xt,children:[h.jsxs("div",{className:"max-w-3xl mx-auto relative",children:[Re?h.jsx("input",{ref:x,type:"file",multiple:!0,accept:bZ,hidden:!0,onChange:wt,"data-testid":"chat-input-file"}):null,h.jsxs("div",{"data-testid":"chat-input-bare",className:fe("flex flex-col gap-2"),children:[c||N||v?h.jsxs("div",{"data-testid":"chat-input-status-bar",className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsxs("div",{className:"flex gap-1",children:[h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"0ms"}}),h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"150ms"}}),h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"300ms"}})]}),h.jsx("span",{children:c?"Waiting for your answer":`${r==="codex"?"Codex":"Claude"} is working`})]}):null,I?h.jsx(dZ,{query:j,skills:R,activeIndex:z,onActiveIndexChange:$,onSelect:F}):null,O?G?!y.remotePersonasByDeviceId.has(G.deviceId)&&ye?h.jsx("div",{"data-testid":"cc-agent-remote-loading",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 rounded-2xl border border-bg-300 bg-bg-50 px-4 py-3 text-[12px] text-text-300 shadow-lg",children:`正在加载 @${G.displayName} 的 persona…`}):E.length>0?h.jsx(Ck,{query:H??"",entries:E,activeIndex:V,onActiveIndexChange:L,onSelect:ne}):h.jsx("div",{"data-testid":"cc-agent-remote-empty",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 rounded-2xl border border-bg-300 bg-bg-50 px-4 py-3 text-[12px] text-text-300 shadow-lg",children:`@${G.displayName} 暂无可派活的 persona(可能离线或未公开)`}):h.jsx(Ck,{query:H??"",entries:E,activeIndex:V,onActiveIndexChange:L,onSelect:ne}):null,B.length>0?h.jsx(xZ,{attachments:B,onRemove:A,onOpenPreview:Z}):null,m?h.jsx("div",{"data-testid":"chat-input-above-slot",className:"mx-2 -mb-3 rounded-t-xl border border-b-0 border-border bg-bg-0 px-3 pt-2 pb-4",children:m}):null,h.jsxs("div",{"data-testid":"bare-chat-input-frame",className:fe("relative flex flex-col gap-1 rounded-xl border border-border bg-bg-0 px-3 py-2 transition-colors duration-200",se?"opacity-60":null,_e?"border-accent/60 bg-accent/5":null),children:[h.jsx("textarea",{ref:T,"data-testid":"chat-input-textarea",value:k,onChange:st,onKeyDown:Qe,onCompositionStart:Rt,onCompositionEnd:Gt,onPaste:pn,placeholder:fn,disabled:se,readOnly:se,rows:1,className:"w-full resize-none bg-transparent border-0 outline-none text-[14px] text-text-100 placeholder:text-text-400 leading-relaxed py-1 min-h-[22px] max-h-[120px] overflow-y-auto disabled:cursor-not-allowed"}),h.jsxs("div",{className:"flex items-center gap-1.5",children:[Re?h.jsx("button",{type:"button",onClick:()=>{var q;return(q=x.current)==null?void 0:q.click()},disabled:Ke,"data-testid":"chat-input-attach","aria-label":"attach files",className:fe("flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors",Ke?"cursor-default text-text-400/50":"cursor-pointer text-text-400 hover:bg-text-100/5 hover:text-text-200"),children:h.jsx(Qz,{className:"h-4 w-4"})}):null,h.jsx("div",{className:"flex-1 min-w-0"}),b!=null?h.jsxs("span",{"data-testid":"chat-input-ctx",className:fe("shrink-0 text-[11px] tabular-nums",_),children:["ctx:",b,"%"]}):null,p,Yt?h.jsx("button",{type:"button",onClick:u,"data-testid":"chat-input-abort","aria-label":"interrupt",title:"中断当前轮次(不杀进程)",className:"h-8 w-8 rounded-full flex items-center justify-center border border-text-400/40 text-text-400 hover:bg-text-100/5 hover:text-text-100 transition-colors cursor-pointer",children:h.jsx(DT,{className:"w-3.5 h-3.5",strokeWidth:2.5})}):null,h.jsx("button",{type:"button",onClick:()=>{ze&&ue()},disabled:!ze,"data-testid":"chat-input-send","aria-label":"send",className:fe("h-8 w-8 rounded-full flex items-center justify-center transition-colors",ze?"bg-accent text-white hover:bg-accent-hover cursor-pointer shadow-sm":"bg-[var(--text-400-dim)] text-[var(--text-400-dim-fg)] cursor-default"),children:h.jsx(JB,{className:"w-4 h-4",strokeWidth:2.5})})]})]})]})]}),on?h.jsx(OZ,{url:on.url,fileName:on.name,onClose:()=>U(null)}):null]})}function $Z(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function FZ({meta:e,tool:t,connState:n,variant:r="full",onOpenConfig:i,liveWorktreeRoot:s,ephemeral:o=!1,onPromote:a,className:l}){const c=s??e.cwd??"",d=!!e.sessionLabel&&e.sessionLabel!==e.sessionId?e.sessionLabel:$Z(c),f=c;return r==="quickask"?h.jsxs("div",{"data-testid":"chat-header","data-variant":"quickask",className:fe("flex items-center shrink-0 px-3 py-2 gap-2",l),children:[a?h.jsx("button",{type:"button","data-testid":"chat-header-promote","data-promoted":o?"false":"true",disabled:!o,onClick:a,title:o?"保留为正式会话":"已保留为正式会话",className:fe("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md transition-colors",o?"text-text-500 hover:text-text-200 hover:bg-text-100/5 cursor-pointer":"text-amber-400"),children:h.jsx(oz,{className:fe("w-3.5 h-3.5",!o&&"fill-current")})}):null,h.jsx("span",{className:"font-semibold text-text-100 truncate text-[13px]","data-testid":"chat-header-worktree",title:f,children:d})]}):h.jsxs("div",{"data-testid":"chat-header","data-variant":"full",className:fe("relative flex items-center shrink-0 px-4 pr-[4.5rem] md:pr-4 py-2.5",l),children:[h.jsx("span",{className:"font-semibold text-text-100 truncate text-[13px]","data-testid":"chat-header-worktree",title:f,children:d}),h.jsx("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 z-10 flex items-center gap-1",children:i?h.jsx("button",{type:"button","aria-label":"Session settings","data-testid":"chat-header-settings-mobile",onClick:i,title:"Session settings",className:"flex md:hidden h-7 w-7 items-center justify-center rounded-md bg-transparent text-text-300 transition-colors duration-150 hover:bg-bg-200 hover:text-text-100 cursor-pointer outline-none",children:h.jsx(LT,{className:"w-4 h-4"})}):null})]})}let HZ=null;function UZ(){return HZ}function Ql({label:e,labelTitle:t,children:n}){return h.jsxs("div",{className:"flex items-start gap-2 px-2 py-1",children:[h.jsx("span",{className:"w-14 shrink-0 truncate text-[11px] text-text-400 pt-0.5",...t?{title:t}:{},children:e}),h.jsx("span",{className:"flex-1 min-w-0 text-[12px] text-text-100",children:n})]})}function Rk({label:e,labelTitle:t,value:n,testid:r}){const[i,s]=g.useState(!1),o=g.useRef(null);g.useEffect(()=>()=>{o.current&&clearTimeout(o.current)},[]);const a=()=>{typeof navigator>"u"||!navigator.clipboard||navigator.clipboard.writeText(n).then(()=>{s(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>s(!1),2e3)},()=>{})};return h.jsx(Ql,{label:e,labelTitle:t,children:h.jsxs("button",{type:"button",onClick:a,"data-testid":r,title:i?"已复制":`复制:${n}`,className:"w-full flex items-center gap-1.5 text-left group cursor-pointer",children:[h.jsx("span",{className:"font-mono text-[11px] text-text-300 truncate flex-1 min-w-0",children:n}),i?h.jsx(ul,{className:"w-3 h-3 shrink-0 text-accent"}):h.jsx(tp,{className:"w-3 h-3 shrink-0 text-text-400 opacity-0 group-hover:opacity-100 transition-opacity"})]})})}function Jm({icon:e,label:t,meta:n,onClick:r,testid:i}){return h.jsxs("button",{type:"button","data-testid":i,onClick:r,className:"w-full flex items-center gap-2.5 px-2 py-1.5 rounded-md hover:bg-text-100/5 cursor-pointer text-left",children:[h.jsx("span",{className:"w-4 h-4 shrink-0 text-text-300 inline-flex items-center justify-center",children:e}),h.jsx("span",{className:"flex-1 text-[12.5px] text-text-100",children:t}),n?h.jsx("span",{className:"shrink-0 text-[11px] text-text-400 font-mono",children:n}):null]})}function WZ({session:e,meta:t,liveGitBranch:n,liveWorktreeRoot:r,personaName:i,onOpenPersona:s,onOpenFiles:o,cronActiveCount:a,onCronClick:l,onForceStop:c,viewerRole:u="owner",toolSessionIdLabel:d="tool session id",drill:f=null,onCollapse:p}){const m=n!==void 0?n:t.gitBranch??null,v=t.procAlive??!1,b=iP(e),_=b!=null&&e.originOwnerPrincipalId==null&&u!=="guest",[x,y]=g.useState(null),w=g.useRef(null);g.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const k=async()=>{if(!_)return;const C=UZ();let N;try{C||(await navigator.clipboard.writeText(b),N="命令已复制")}catch{N="操作失败"}y(N),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>y(null),2500)};return h.jsxs("div",{"data-testid":"session-info-panel",className:"h-full min-w-0 border-l border-border bg-bg-100 flex flex-col",children:[h.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b border-border shrink-0",children:[f?h.jsx("button",{type:"button","data-testid":"session-info-back",onClick:f.onBack,"aria-label":"返回会话信息",className:"p-1 -ml-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:h.jsx(QB,{className:"w-4 h-4"})}):p?h.jsx("button",{type:"button","data-testid":"session-info-collapse",onClick:p,"aria-label":"collapse session info",title:"收起会话信息",className:"p-1 -ml-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:h.jsx(Sm,{className:"w-4 h-4"})}):h.jsx(Sm,{className:"w-4 h-4 text-text-300"}),h.jsx("span",{className:"flex-1 text-[13px] font-medium text-text-100 truncate",children:f?f.title:"会话信息"}),f&&p?h.jsx("button",{type:"button","data-testid":"session-info-collapse",onClick:p,"aria-label":"collapse session info",title:"收起会话信息",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:h.jsx(Sm,{className:"w-4 h-4"})}):null]}),f?h.jsx("div",{"data-testid":"session-info-drill",className:"flex-1 min-h-0 overflow-y-auto",children:f.content}):h.jsxs("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:[m?h.jsx(Ql,{label:"分支",children:h.jsxs("span",{"data-testid":"session-info-branch",className:"inline-flex items-center gap-1 font-mono text-[11.5px] min-w-0",title:r??void 0,children:[h.jsx(Lx,{className:"w-3 h-3 shrink-0 text-text-400"}),h.jsx("span",{className:"truncate",children:m})]})}):null,i&&s?h.jsx(Ql,{label:"persona",children:h.jsxs("button",{type:"button","data-testid":"session-info-persona",onClick:s,className:"inline-flex items-center gap-1 hover:text-accent cursor-pointer",children:[h.jsx($T,{className:"w-3 h-3"}),h.jsx("span",{className:"truncate",children:i})]})}):null,h.jsx(Ql,{label:"引擎",children:h.jsxs("span",{className:"inline-flex items-center gap-1.5","data-testid":"session-info-engine",children:[h.jsx(np,{tool:e.tool,className:fe("w-3.5 h-3.5 shrink-0",rp(e.tool))}),h.jsxs("span",{className:"truncate",children:[zx(e.tool),t.model?` · ${t.model}`:""]})]})}),h.jsx(Ql,{label:"cwd",children:h.jsx("span",{"data-testid":"session-info-cwd",className:"font-mono text-[11px] text-text-300 truncate block",title:e.cwd,children:e.cwd})}),h.jsx(Rk,{label:"session id",value:e.sessionId,testid:"session-info-session-id"}),e.toolSessionId?h.jsx(Rk,{label:`${e.tool||"claude"} id`,labelTitle:d,value:e.toolSessionId,testid:"session-info-tool-session-id"}):null,h.jsx("div",{className:"my-2 border-t border-border"}),o?h.jsx(Jm,{icon:h.jsx(Pz,{className:"w-3.5 h-3.5"}),label:"Edited Files",onClick:o,testid:"session-info-files"}):null,a&&a>0&&l?h.jsx(Jm,{icon:h.jsx(vz,{className:"w-3.5 h-3.5"}),label:"定时任务",meta:String(a),onClick:l,testid:"session-info-cron"}):null,_?h.jsx(Jm,{icon:h.jsx(y$,{className:"w-3.5 h-3.5"}),label:"终端",meta:x,onClick:()=>void k(),testid:"session-info-terminal"}):null]}),v&&c?h.jsx("div",{className:"shrink-0 border-t border-border px-3 py-2.5",children:h.jsxs("button",{type:"button","data-testid":"session-info-force-stop",onClick:c,title:e.tool==="codex"?"强制停止 Codex 进程":"强制停止 Claude Code 进程(会丢失 initialize / 预热缓存)",className:"inline-flex items-center gap-1.5 h-6 px-2.5 rounded-md text-text-400 hover:bg-red-500/10 hover:text-red-400 transition-colors text-[12px] cursor-pointer",children:[h.jsx(Gz,{className:"w-3.5 h-3.5"}),h.jsx("span",{children:"强制停止"})]})}):null]})}const VZ=g.createContext({container:null});function qZ(){return g.useContext(VZ)}function KZ(e){return e==="TodoWrite"}function GZ(e){if(!e||typeof e!="object")return null;const t=e;if(!Array.isArray(t.todos))return null;const n=[];for(const r of t.todos){if(!r||typeof r!="object")continue;const i=r,s=typeof i.content=="string"?i.content:"";if(!s)continue;const o=i.status==="in_progress"||i.status==="completed"?i.status:"pending",a=typeof i.activeForm=="string"?i.activeForm:void 0;n.push({content:s,status:o,activeForm:a})}return n}function XZ(e,t,n){const r=[],i=new Map;for(let s=0;s<e.length;s++){const o=e[s],a=typeof o.seq=="number"?o.seq:s;switch(o.kind){case"session_init":r.push({kind:"session-init",seq:a,toolSessionId:o.toolSessionId});break;case"text":Mk(r,a,"assistant-text",o.text,o.partialId,o.uuid);break;case"thinking":Mk(r,a,"assistant-thinking",o.text,o.partialId);break;case"user_text":{o.meta==="task-notification"?r.push({kind:"agent-notification",seq:a,text:o.text,taskId:o.taskId,parentToolUseId:o.parentToolUseId}):o.meta?r.push({kind:"user-meta",seq:a,metaKind:o.meta,text:o.text}):r.push({kind:"user-text",seq:a,text:o.text,uuid:o.uuid,...o.sender&&o.sender.principal!=="owner"?{senderDisplayName:o.sender.displayName}:{}});break}case"tool_call":jM(r,a,o.toolUseId,o.tool,o.input,o.toolKind);break;case"tool_result":{const l=i.get(o.toolUseId);if(l!==void 0){if(o.askQuestionAnswers){const u=r[l];u.submittedAnswers=o.askQuestionAnswers}i.delete(o.toolUseId);break}const c={kind:"tool-result",seq:a,toolUseId:o.toolUseId,output:o.output,error:o.error};o.toolResultExtra&&(c.toolResultExtra=o.toolResultExtra),r.push(c);break}case"attachment_memories":r.push({kind:"memory-callout",seq:a,memories:o.memories});break;case"permission_request":{if(!t||o.requestId!==t)break;r.push({kind:"permission-inline",seq:a,requestId:o.requestId,tool:o.tool,input:o.input});break}case"ask_user_question":i.set(o.toolUseId,r.length),r.push({kind:"question-card",seq:a,toolUseId:o.toolUseId,questions:o.questions});break;case"turn_end":{const l={kind:"turn-end",seq:a};o.durationMs!==void 0&&(l.durationMs=o.durationMs),o.reason!==void 0&&(l.reason=o.reason),r.push(l);break}case"subagent_progress":{const l={kind:"agent-progress",seq:a,toolUseId:o.toolUseId,agentId:o.agentId,status:o.status};o.description&&(l.description=o.description),o.lastToolName&&(l.lastToolName=o.lastToolName),o.prompt&&(l.prompt=o.prompt),o.stats&&(l.stats=o.stats),r.push(l);break}case"error":r.push({kind:"error",seq:a,message:o.message});break}}return r}function jM(e,t,n,r,i,s){if(KZ(r)){const o=GZ(i);if(o){e.push({kind:"todo-checklist",seq:t,toolUseId:n,todos:o});return}}if(r==="Agent"){const o=i??{},a=typeof o.description=="string"&&o.description?o.description:typeof o.subagent_type=="string"&&o.subagent_type?o.subagent_type:"Subagent";e.push({kind:"agent-call",seq:t,toolUseId:n,description:a,input:i});return}if(DU(r)){e.push({kind:"task-event",seq:t,toolUseId:n,name:r,input:i});return}e.push({kind:"tool-call",seq:t,toolUseId:n,tool:r,toolKind:s,input:i})}function Mk(e,t,n,r,i,s){let o=-1;for(let c=e.length-1;c>=0;c--)if(e[c].kind===n){o=c;break}const a=o>=0?e[o]:null;if(i){if(a&&a.partialId===i){const u=n==="assistant-text"?{kind:n,seq:a.seq,text:a.text+r,partialId:i,...s?{uuid:s}:{}}:{kind:n,seq:a.seq,text:a.text+r,partialId:i};e[o]=u;return}const c=n==="assistant-text"?{kind:n,seq:t,text:r,partialId:i,...s?{uuid:s}:{}}:{kind:n,seq:t,text:r,partialId:i};e.push(c);return}if(a&&a.partialId){const c=n==="assistant-text"?{kind:n,seq:a.seq,text:r,...s?{uuid:s}:{}}:{kind:n,seq:a.seq,text:r};e[o]=c;return}const l=n==="assistant-text"?{kind:n,seq:t,text:r,...s?{uuid:s}:{}}:{kind:n,seq:t,text:r};e.push(l)}const YZ="AskUserQuestion";function DM(e,t=0,n){var o;const r=[],i=new Map;let s=t;for(const a of e){const l=s++,c=a.toolUseId??`hist-${l}`;switch(a.kind){case"user-text":if(a.meta==="task-notification")r.push({kind:"agent-notification",seq:l,text:a.text??"",taskId:a.taskId,parentToolUseId:a.parentToolUseId});else if(a.meta)r.push({kind:"user-meta",seq:l,metaKind:a.meta,text:a.text??""});else{const u=(o=X6.exec(a.text??""))==null?void 0:o[1];r.push({kind:"user-text",seq:l,text:a.text??"",uuid:a.uuid,...u?{senderDisplayName:u}:{}})}break;case"assistant-text":r.push({kind:"assistant-text",seq:l,text:a.text??"",uuid:a.uuid});break;case"tool_call":{if(a.tool===YZ){const u=a.input??{},d=Array.isArray(u.questions)?u.questions:[];i.set(c,r.length),r.push({kind:"question-card",seq:l,toolUseId:c,questions:d});break}jM(r,l,c,a.tool??"",a.input,n);break}case"tool_result":{const u=i.get(c);if(u!==void 0){if(a.askQuestionAnswers){const f=r[u];f.submittedAnswers=a.askQuestionAnswers}i.delete(c);break}const d={kind:"tool-result",seq:l,toolUseId:c,output:a.output};a.error!==void 0&&(d.error=a.error),a.toolResultExtra&&(d.toolResultExtra=a.toolResultExtra),r.push(d);break}case"attachment_memories":a.memories&&a.memories.length>0&&r.push({kind:"memory-callout",seq:l,memories:a.memories});break;case"summary":break;case"turn-end":{const u={kind:"turn-end",seq:l};typeof a.durationMs=="number"&&(u.durationMs=a.durationMs),r.push(u);break}}}return r}const QZ=5e5;function ZZ(e){const t=QZ-e.length;return e.map(n=>({...n,seq:n.seq+t}))}function JZ({api:e,cwd:t,toolSessionId:n}){const r=PM(),i=(r==null?void 0:r.state.agentId)??null,s=r==null?void 0:r.state.agentType,[o,a]=g.useState([]),[l,c]=g.useState(!1),[u,d]=g.useState(null);g.useEffect(()=>{if(!i)return;let p=!1;return c(!0),d(null),a([]),e.historySubagentRead({cwd:t,toolSessionId:n,subagentId:i}).then(m=>{p||a(m.messages??[])}).catch(m=>{p||d(m instanceof Error?m.message:String(m))}).finally(()=>{p||c(!1)}),()=>{p=!0}},[i,t,n,e]);const f=g.useMemo(()=>o.length>0?DM(o,0,"claude"):[],[o]);return!r||!i?null:h.jsxs("div",{"data-testid":"subagent-drawer","data-agent-id":i,className:fe("fixed inset-y-0 right-0 z-50 w-[min(560px,92vw)]","flex flex-col border-l border-bg-200/60 bg-bg-50 shadow-xl"),style:{paddingTop:"env(safe-area-inset-top)"},children:[h.jsxs("div",{className:"flex flex-col gap-0.5 px-3 py-2 border-b border-bg-200/60",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s?h.jsx("span",{className:"inline-flex items-center rounded-sm bg-violet-500/10 px-1.5 py-0.5 text-[11px] text-violet-400 font-medium",children:s}):null,h.jsx("span",{className:"font-mono text-[11px] text-text-400 truncate",title:i,children:i})]}),h.jsx("button",{type:"button","aria-label":"关闭",onClick:()=>r.close(),className:"p-1 rounded hover:bg-bg-200/50 text-text-400 hover:text-text-200",children:h.jsx(Dr,{className:"w-4 h-4"})})]}),!l&&!u&&o.length>0?h.jsxs("div",{className:"text-[11px] text-text-400",children:[o.length," 条消息 · 首条为主会话派发的任务指令"]}):null]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 py-2",children:l?h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsx(In,{className:"w-3.5 h-3.5 animate-spin"}),h.jsx("span",{children:"加载中…"})]}):u?h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-error",children:[h.jsx(Ls,{className:"w-3.5 h-3.5"}),h.jsx("span",{children:u})]}):f.length===0?h.jsx("div",{className:"text-[12px] text-text-400 italic",children:"无消息"}):h.jsx(RM,{lines:f})})]})}function Ak(e,t){let n=0;for(const r of e.lines)r.startsWith(t)&&n++;return n}function eJ(e,t){const n=e.findIndex(c=>c.kind==="user-text"&&c.uuid===t);if(n<0)return{userMessageId:t,files:[],totalInsertions:0,totalDeletions:0,anchorFound:!1};let r=e.length;for(let c=n+1;c<e.length;c++)if(e[c].kind==="user-text"){r=c;break}const i=[],s=new Map;for(let c=n+1;c<r;c++){const u=e[c];if(u.kind!=="tool-result")continue;const d=u.toolResultExtra;if(!(d!=null&&d.filePath)||!d.structuredPatch||d.structuredPatch.length===0)continue;const f=d.filePath;let p=s.get(f);p||(p={filePath:f,hunks:[],insertions:0,deletions:0},s.set(f,p),i.push(f));for(const m of d.structuredPatch)p.hunks.push(m),p.insertions+=Ak(m,"+"),p.deletions+=Ak(m,"-")}const o=i.map(c=>s.get(c)),a=o.reduce((c,u)=>c+u.insertions,0),l=o.reduce((c,u)=>c+u.deletions,0);return{userMessageId:t,files:o,totalInsertions:a,totalDeletions:l,anchorFound:!0}}function tJ({open:e,onOpenChange:t,api:n,sessionId:r,userMessageId:i,lines:s,procAlive:o,onApplied:a,onNoChanges:l}){const c=g.useMemo(()=>eJ(s,i),[s,i]),[u,d]=g.useState(null),[f,p]=g.useState(!1),[m,v]=g.useState(!1),[b,_]=g.useState(null);g.useEffect(()=>{if(!e)return;let C=!1;return p(!0),d(null),(async()=>{try{const N=await n.sessionRewindDiff({sessionId:r,userMessageId:i});C||(d(N),!N.canRewind&&!N.error&&N.files.length===0&&(l==null||l(i)))}catch{C||d(null)}finally{C||p(!1)}})(),()=>{C=!0}},[e,n,r,i]);const x=g.useMemo(()=>{if(u){const C=!u.canRewind&&!u.error&&u.files.length===0;if(u.canRewind||C)return{source:"rpc",anchorFound:!0,files:u.files.map(N=>({filePath:N.filePath,hunks:N.hunks,insertions:N.insertions,deletions:N.deletions})),totalInsertions:u.totalInsertions,totalDeletions:u.totalDeletions}}return{source:"local",anchorFound:c.anchorFound,files:c.files,totalInsertions:c.totalInsertions,totalDeletions:c.totalDeletions,rpcError:u==null?void 0:u.error}},[u,c]),y=g.useCallback(async()=>{v(!0),_(null);try{const C=await n.sessionRewind({sessionId:r,userMessageId:i,dryRun:!1});if(!C.canRewind){_(C.error??"回退失败");return}a==null||a(),t(!1)}catch(C){_(C.message||"回退失败")}finally{v(!1)}},[n,r,i,a,t]);if(!e)return null;const w=x.files.length>0,k=!f&&!m&&x.anchorFound&&w&&!b;return h.jsxs("div",{"data-testid":"rewind-preview-drawer",className:"fixed right-0 top-0 bottom-0 z-40 flex flex-col border-l border-bg-300/40 bg-bg-0 shadow-xl",style:{width:480,minWidth:480},children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(zT,{className:"w-4 h-4 text-text-300"}),h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Rewind 预览"})]}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"rewind-drawer-close",className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:bg-text-100/5 hover:text-text-200 cursor-pointer","aria-label":"close",children:h.jsx(Dr,{className:"w-4 h-4"})})]}),b?h.jsxs("div",{"data-testid":"rewind-error-banner",className:"mx-4 mt-3 flex items-start gap-2 rounded-md border border-red-400/40 bg-red-500/10 px-3 py-2 text-[12px] text-red-400",children:[h.jsx(Kc,{className:"w-4 h-4 shrink-0 mt-0.5"}),h.jsx("span",{children:b})]}):null,h.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-3",children:f?h.jsxs("div",{"data-testid":"rewind-loading",className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsx(In,{className:"w-3.5 h-3.5 animate-spin"}),h.jsx("span",{children:"正在读取快照…"})]}):x.anchorFound?w?h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":"rewind-summary",className:"rounded-md border border-bg-300 bg-bg-100/40 px-3 py-2 text-[12px] text-text-200",children:[h.jsxs("div",{children:["将回退 ",h.jsx("span",{className:"font-semibold text-text-100",children:x.files.length})," ","个文件,",h.jsxs("span",{className:"text-green-500 font-mono",children:["+",x.totalInsertions]})," / ",h.jsxs("span",{className:"text-red-400 font-mono",children:["-",x.totalDeletions]})]}),x.source==="local"?h.jsx("div",{"data-testid":"rewind-source-hint",className:"mt-1 text-text-400 text-[11px]",children:"基于对话里 tool_result 估算(未读到 CC 快照,数字可能与实际磁盘略有差异)"}):null]}),x.files.map(C=>h.jsx(rJ,{file:C},C.filePath))]}):h.jsxs("div",{"data-testid":"rewind-no-changes",className:"rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300 space-y-1",children:[h.jsx("div",{children:"磁盘上的文件已经和这个时刻的快照完全一致——没有需要回退的改动。"}),h.jsx("div",{className:"text-text-400 text-[11px]",children:"可能这条消息之后 Claude 没落盘编辑,或之前已经 rewind 过了。"})]}):h.jsx("div",{"data-testid":"rewind-no-anchor",className:"rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300",children:"未能在当前消息流中找到对应的用户消息(可能已被历史裁剪)。"})}),h.jsxs("div",{className:"flex flex-col gap-2 px-4 py-3 border-t border-bg-300/30 shrink-0",children:[w&&x.anchorFound&&!o?h.jsxs("div",{"data-testid":"rewind-needs-cc",className:"flex items-start gap-2 rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300",children:[h.jsx(Kc,{className:"w-4 h-4 shrink-0 mt-0.5 text-warning"}),h.jsx("span",{children:'Claude Code 进程当前未运行。点击"确认回退"时会自动启动它再执行 — 可能需要等一两秒。'})]}):null,h.jsxs("div",{className:"flex items-center justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:()=>t(!1),className:"h-8 px-3 rounded-md text-[12px] text-text-300 hover:bg-text-100/5 cursor-pointer",children:"取消"}),h.jsx("button",{type:"button",disabled:!k,onClick:()=>void y(),"data-testid":"rewind-apply",className:fe("h-8 px-3 rounded-md text-[12px] font-medium transition-colors",k?"bg-accent text-white hover:bg-accent-hover cursor-pointer":"bg-bg-200 text-text-400 cursor-not-allowed"),children:m?"回退中…":"确认回退"})]})]})]})}function nJ(e){return e.replace(/^\/Users\/[^/]+/,"~")}function rJ({file:e}){const[t,n]=g.useState(!0);return h.jsxs("div",{"data-testid":"rewind-file-block","data-file":e.filePath,className:"rounded-md border border-bg-300 overflow-hidden bg-bg-0",children:[h.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"w-full flex items-center gap-1.5 px-3 py-2 text-[12px] hover:bg-text-100/5 cursor-pointer",children:[t?h.jsx(ir,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(Un,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"font-mono text-text-200 truncate flex-1 text-left",title:e.filePath,children:nJ(e.filePath)}),h.jsxs("span",{className:"font-mono shrink-0 text-text-400",children:[h.jsxs("span",{className:"text-green-500",children:["+",e.insertions]})," ",h.jsxs("span",{className:"text-red-400",children:["-",e.deletions]})]})]}),t?h.jsx("div",{className:"border-t border-bg-300",children:e.hunks.map(r=>h.jsx(iJ,{hunk:r},`${r.oldStart}-${r.oldLines}-${r.newStart}-${r.newLines}`))}):null]})}function iJ({hunk:e}){const t=`@@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@`;return h.jsxs("div",{className:"text-[11px] font-mono leading-relaxed",children:[h.jsx("div",{className:"px-3 py-1 text-text-400 bg-bg-100/40 border-b border-bg-300",children:t}),e.lines.map((n,r)=>{const i=n.charAt(0),s=i==="+"?"bg-green-500/10 text-green-300":i==="-"?"bg-red-500/10 text-red-300":"text-text-300";return h.jsx("div",{className:fe("px-3 whitespace-pre",s),children:n.length>0?n:" "},r)})]})}function sJ({jobs:e}){return e.length===0?h.jsx("div",{"data-testid":"cron-job-list-empty",className:"px-4 py-3 text-sm text-text-500",children:"当前会话暂无活跃 cron 任务"}):h.jsx("ul",{"data-testid":"cron-job-list",className:"flex flex-col gap-2",children:e.map(t=>h.jsxs("li",{"data-testid":`cron-job-${t.id}`,className:"flex flex-col gap-1 rounded-md border border-border px-3 py-2",children:[h.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[h.jsx("span",{className:"font-mono text-text-300",children:t.id}),h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"text-text-400",children:t.humanSchedule}),t.recurring?h.jsx("span",{"data-testid":`cron-job-${t.id}-recurring-badge`,className:"ml-auto rounded-md bg-accent-dim px-2 py-0.5 text-accent",children:"recurring"}):null]}),h.jsx("div",{className:"text-sm text-text-200 truncate",title:t.prompt,children:t.prompt})]},t.id))})}const oJ={idle:"还没启动","turn-running":"正在 run 中","turn-idle":"进程活着,等输入",exited:"进程已退出",crashed:"启动失败 / 异常退出"};function aJ({sessionStatus:e}){switch(e){case"idle":return"idle";case"running":return"turn-running";case"running-idle":return"turn-idle";case"observing":return"turn-running";case"stopped":return"exited";case"error":return"crashed"}}function lJ(e){return e==="running"||e==="observing"}function OM(e){return e==="running"||e==="running-idle"||e==="observing"}/**
|