@clawos-dev/clawd 0.2.337 → 0.2.338
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-BqQKZNBj.css +32 -0
- package/dist/share-ui/assets/{guest-x-l8SSXd.js → guest-DHI2n218.js} +2 -2
- package/dist/share-ui/guest.html +2 -2
- package/package.json +1 -1
- package/dist/share-ui/assets/guest-BfV5KskO.css +0 -32
|
@@ -503,7 +503,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
503
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 pX(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=hM.inlineCode(p,m,v);return v.stack.includes("tableCell")&&(b=b.replace(/\|/g,"\\$&")),b}}function tY(){return{exit:{taskListCheckValueChecked:vk,taskListCheckValueUnchecked:vk,paragraph:rY}}}function nY(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:iY}}}function vk(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function rY(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 iY(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=hM.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 sY(){return[OG(),iX(),lX(),GX(),tY()]}function oY(e){return{extensions:[BG(),sX(e),cX(),eY(e),nY()]}}const aY={tokenize:fY,partial:!0},fM={tokenize:pY,partial:!0},pM={tokenize:mY,partial:!0},mM={tokenize:gY,partial:!0},lY={tokenize:vY,partial:!0},gM={name:"wwwAutolink",tokenize:dY,previous:_M},vM={name:"protocolAutolink",tokenize:hY,previous:xM},Ui={name:"emailAutolink",tokenize:uY,previous:yM},di={};function cY(){return{text:di}}let Hs=48;for(;Hs<123;)di[Hs]=Ui,Hs++,Hs===58?Hs=65:Hs===91&&(Hs=97);di[43]=Ui;di[45]=Ui;di[46]=Ui;di[95]=Ui;di[72]=[Ui,vM];di[104]=[Ui,vM];di[87]=[Ui,gM];di[119]=[Ui,gM];function uY(e,t,n){const r=this;let i,s;return o;function o(d){return!T0(d)||!yM.call(r,r.previous)||jy(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(d))}function a(d){return T0(d)?(e.consume(d),a):d===64?(e.consume(d),l):n(d)}function l(d){return d===46?e.check(lY,u,c)(d):d===45||d===95||xn(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 dY(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!_M.call(r,r.previous)||jy(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(aY,e.attempt(fM,e.attempt(pM,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function hY(e,t,n){const r=this;let i="",s=!1;return o;function o(d){return(d===72||d===104)&&xM.call(r,r.previous)&&!jy(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||ef(d)||ot(d)||yo(d)||pp(d)?n(d):e.attempt(fM,e.attempt(pM,u),n)(d)}function u(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function fY(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 pY(e,t,n){let r,i,s;return o;function o(c){return c===46||c===95?e.check(mM,l,a)(c):c===null||ot(c)||yo(c)||c!==45&&pp(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 mY(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(mM,t,s)(o):o===null||ot(o)||yo(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function gY(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)||yo(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||ot(a)||yo(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 vY(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return xn(s)?n(s):t(s)}}function _M(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ot(e)}function xM(e){return!En(e)}function yM(e){return!(e===47||T0(e))}function T0(e){return e===43||e===45||e===46||e===95||xn(e)}function jy(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 _Y={tokenize:EY,partial:!0};function xY(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:SY,continuation:{tokenize:kY},exit:CY}},text:{91:{name:"gfmFootnoteCall",tokenize:wY},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:yY,resolveTo:bY}}}}function yY(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=Ar(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 bY(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 wY(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(Ar(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 SY(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=Ar(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),Ke(e,p,"gfmFootnoteDefinitionWhitespace")):n(m)}function p(m){return t(m)}}function kY(e,t,n){return e.check(Eu,t,e.attempt(_Y,t,n))}function CY(e){e.exit("gfmFootnoteDefinition")}function EY(e,t,n){const r=this;return Ke(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 NY(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,mp(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=Ha(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"),_=Ha(m);return b._open=!_||_===2&&!!v,b._close=!v||v===2&&!!_,a(m)}}}class TY{constructor(){this.map=[]}add(t,n,r){PY(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 PY(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 IY(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 RY(){return{flow:{null:{name:"table",tokenize:MY,resolveAll:AY}}}}function MY(e,t,n){const r=this;let i=0,s=0,o;return a;function a(P){let L=r.events.length-1;for(;L>-1;){const D=r.events[L][1].type;if(D==="lineEnding"||D==="linePrefix")L--;else break}const R=L>-1?r.events[L][1].type:null,I=R==="tableHead"||R==="tableRow"?C:l;return I===C&&r.parser.lazy[r.now().line]?n(P):I(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):we(P)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(P),e.exit("lineEnding"),p):n(P):He(P)?Ke(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,He(P)?Ke(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):S(P)}function v(P){return He(P)?Ke(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||we(P)?w(P):S(P)}function _(P){return P===45?(e.enter("tableDelimiterFiller"),x(P)):S(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 He(P)?Ke(e,w,"whitespace")(P):w(P)}function w(P){return P===124?m(P):P===null||we(P)?!o||i!==s?S(P):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(P)):S(P)}function S(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||we(P)?(e.exit("tableRow"),t(P)):He(P)?Ke(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 AY(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 TY;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=wd(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=wd(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=wd(f,t,s,i,n,d)):o[1]!==0&&(d=wd(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=IY(t.events,n))}return e}function wd(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Qo(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Qo(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=Qo(t.events,n[2]),u=Qo(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({},Qo(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function _k(e,t,n,r,i){const s=[],o=Qo(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 Qo(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const LY={name:"tasklistCheck",tokenize:DY};function jY(){return{text:{91:LY}}}function DY(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 we(l)?t(l):He(l)?e.check({tokenize:OY},t,n)(l):n(l)}}function OY(e,t,n){return Ke(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function BY(e){return IR([cY(),xY(),NY(e),RY(),jY()])}const zY={};function tu(e){const t=this,n=e||zY,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(BY(n)),s.push(sY()),o.push(oY(n))}const $Y=/<command-name>([\s\S]*?)<\/command-name>/i,FY=/<command-message>([\s\S]*?)<\/command-message>/i,HY=/<command-args>([\s\S]*?)<\/command-args>/i,UY=/<(local-command-[a-z]+|command-(?:stdout|stderr))>[\s\S]*?<\/\1>/gi;function xp(e){if(!e)return{commandName:null,commandMessage:null,commandArgs:null,body:""};const t=e.match($Y),n=e.match(FY),r=e.match(HY);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(UY,""),i=i.trim(),{commandName:t?t[1].trim():null,commandMessage:n?n[1].trim():null,commandArgs:r?r[1].trim():null,body:i}}const WY=/\.(png|jpe?g|webp|gif|svg)$/i;function VY(e,t){if((typeof t=="string"?t:null)!==e)return!1;try{const r=new URL(e);return WY.test(r.pathname)}catch{return!1}}function qY(e){try{return new URL(e).pathname.split("/").filter(Boolean).pop()??""}catch{return""}}const nu={a:({node:e,href:t,children:n,...r})=>typeof t=="string"&&VY(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:qY(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 KY({text:e,forkTarget:t}){const{body:n}=xp(e);return n?h.jsxs("div",{className:"group 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(Jc,{remarkPlugins:[tu],components:nu,children:n})}),t?h.jsxs("div",{className:"mt-1 flex flex-row items-center gap-1",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(Ax,{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(zz,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"问一下"})]}):null]}):null]}):null}function GY({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}function Dy(e){if(!e)return!1;const n=e.split("#")[0].split("?")[0].toLowerCase();return n.endsWith(".md")||n.endsWith(".markdown")}const XY=new Set(["Write","Edit","MultiEdit","NotebookEdit"]);function P0(e){return XY.has(e)}function YY({tool:e,relPath:t,scope:n,onShareFile:r}){if(!P0(e)||!t||!n||!r)return null;const i=Dy(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(Lx,{className:"h-3.5 w-3.5"})})})}function ZY(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 bM(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 QY({url:e,bearerToken:t,alt:n,className:r}){const i=bM(e,t);return h.jsxs("div",{"data-testid":"blob-image","data-state":i.kind,className:ae("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(As,{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 JY({url:e,bearerToken:t,className:n}){const r=bM(e,t);return h.jsxs("div",{"data-testid":"blob-video","data-state":r.kind,className:ae("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 eZ=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),tZ=new Set([".mp4",".webm",".mov"]),nZ=new Set([".pdf"]);function rZ(e){const t=e.lastIndexOf("."),n=t>=0?e.slice(t).toLowerCase():"";return eZ.has(n)?"image":tZ.has(n)?"video":nZ.has(n)?"pdf":"binary"}function wM(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function iZ({relPath:e,scope:t,size:n}){const r=Yf();if(r.actionsLevel==="none")return null;const i=pB(r,t,e);if(!i)return null;const s=rZ(e);return s==="image"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"image",className:"mt-2",children:h.jsx(QY,{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(JY,{url:i,bearerToken:r.httpToken})}):s==="pdf"?h.jsx(sZ,{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(To,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),h.jsx("span",{children:"·"}),h.jsx("span",{children:wM(n)})]}):null}function sZ({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(To,{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:wM(n)})]}):null,h.jsx(Vc,{className:"h-3 w-3"})]})}const oZ={Bash:BT,Read:To,Edit:OT,Write:Sz,Grep:Ew,Glob:Ew};function aZ(e){return oZ[e]??k$}function lZ(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 SM({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=aZ(e),m=lZ(t),v=ZY(t);return h.jsxs("div",{"data-testid":"msg-line-tool","data-tool":e,className:ae("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(As,{className:"w-4 h-4 text-destructive shrink-0"}):h.jsx(p,{className:ae("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||!P0(e)||!v)return null;const _=Dy(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(YY,{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&&P0(e)?h.jsx(iZ,{relPath:v,scope:o}):null]})}var cZ=Symbol.for("react.lazy"),sf=Ya[" use ".trim().toString()];function uZ(e){return typeof e=="object"&&e!==null&&"then"in e}function kM(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===cZ&&"_payload"in e&&uZ(e._payload)}function dZ(e){const t=fZ(e),n=g.forwardRef((r,i)=>{let{children:s,...o}=r;kM(s)&&typeof sf=="function"&&(s=sf(s._payload));const a=g.Children.toArray(s),l=a.find(mZ);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 hZ=dZ("Slot");function fZ(e){const t=g.forwardRef((n,r)=>{let{children:i,...s}=n;if(kM(i)&&typeof sf=="function"&&(i=sf(i._payload)),g.isValidElement(i)){const o=vZ(i),a=gZ(s,i.props);return i.type!==g.Fragment&&(a.ref=r?_u(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 pZ=Symbol("radix.slottable");function mZ(e){return g.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===pZ}function gZ(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 vZ(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,_Z=(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)},xZ=_Z("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"}}),ri=g.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},s)=>{const o=r?hZ:"button";return h.jsx(o,{ref:s,className:ae(xZ({variant:t,size:n}),e),...i})});ri.displayName="Button";function yZ({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(h$,{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(ri,{size:"sm",variant:"default",onClick:()=>n(!0,!1),"data-testid":"msg-line-permission-allow",children:"Allow"}),h.jsx(ri,{size:"sm",variant:"outline",onClick:()=>n(!0,!0),"data-testid":"msg-line-permission-allow-always",children:"Allow Always"}),h.jsx(ri,{size:"sm",variant:"destructive",onClick:()=>n(!1,!1),"data-testid":"msg-line-permission-deny",children:"Deny"})]})]})}function bZ({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(qc,{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 wZ(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 SZ(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 kZ=/\[skill:(.+?):(\/[^\]]+)\]/g;function CZ(e){const t=[],n=e.replace(kZ,(r,i)=>(t.push(i),""));return{skills:t,text:t.length>0?n.trim():e}}function EZ({text:e,senderDisplayName:t,rewindTarget:n}){const r=mR(e),{attachments:i,text:s}=wZ(r),{skills:o,text:a}=CZ(s),{commandName:l,body:c}=xp(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(NZ,{attachments:i}):null,o.length>0?h.jsx("div",{className:ae("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:ae("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 NZ({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(TZ,{attachment:t},t.url))})}function TZ({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(To,{className:"h-3.5 w-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"max-w-[140px] truncate",children:e.fileName})]})}const PZ={"task-notification":"子任务通知","slash-command":"斜杠命令","local-command":"本地命令输出","system-reminder":"系统提醒","skill-hint":"Skill 注入","meta-text":"系统消息","attachment-skills":"技能列表","attachment-deferred-tools":"Deferred 工具变更"},IZ={"task-notification":Cw,"slash-command":m$,"local-command":BT,"system-reminder":Cw,"skill-hint":s0,"meta-text":LT,"attachment-skills":s0,"attachment-deferred-tools":n$};function RZ({metaKind:e,text:t}){const[n,r]=g.useState(!1),i=IZ[e];if(e==="slash-command"){const{commandName:o,commandMessage:a,commandArgs:l,body:c}=xp(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:ae("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:PZ[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 MZ({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:ae("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(Fz,{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(LT,{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 $r(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 CM(e){var i,s,o;const t={};if(!e)return t;t.taskId=$r(e,"task-id"),t.toolUseId=$r(e,"tool-use-id"),t.outputFile=$r(e,"output-file"),t.status=$r(e,"status"),t.summary=$r(e,"summary"),t.result=$r(e,"result");const n=$r(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=$r(e,"worktree");if(r)t.worktreePath=$r(r,"worktreePath"),t.worktreeBranch=$r(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 AZ(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 LZ({text:e,taskId:t,parentToolUseId:n}){const r=g.useMemo(()=>CM(e),[e]),[i,s]=g.useState(!1),o=t??r.taskId,a=n??r.toolUseId,l=r.status==="failed"?h.jsx(As,{className:"w-3.5 h-3.5 text-error"}):r.status==="completed"?h.jsx(Qf,{className:"w-3.5 h-3.5 text-success"}):h.jsx(Zf,{className:"w-3.5 h-3.5 text-text-400"}),c=r.status??"unknown",u=AZ(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:ae("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(Ax,{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(Jc,{remarkPlugins:[tu],components:nu,children:r.result})}):h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细结果"})]}):null]})}const EM=g.createContext(null);function jZ({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(EM.Provider,{value:s,children:e})}function NM(){return g.useContext(EM)}function DZ(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
|
-
`):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 OZ(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 BZ={readCount:"read",searchCount:"search",bashCount:"bash",editFileCount:"edit",linesAdded:"+lines",linesRemoved:"-lines",otherToolCount:"other"};function zZ(e){if(!e)return[];const t=[];for(const[n,r]of Object.entries(e)){if(!r||r<=0)continue;const i=BZ[n]??n;t.push(`${i}:${r}`)}return t}function $Z({description:e,input:t,output:n,error:r,pending:i,notifications:s,toolResultExtra:o,progress:a}){const[l,c]=g.useState(!1),u=NM(),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(()=>DZ(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)),_=OZ((m==null?void 0:m.tokens)??(v==null?void 0:v.tokens)),x=zZ(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),S=(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:CM(T.text)})),[s]),N=r?h.jsx(As,{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(Qf,{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":S??"",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:ae("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(N$,{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,S&&(u!=null&&u.open)?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"open-subagent-btn-header","data-agent-id":S,"aria-label":"打开子 agent 对话",onClick:T=>{T.stopPropagation(),u.open(S,o==null?void 0:o.agentType)},onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.stopPropagation(),T.preventDefault(),u.open(S,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(Vc,{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,L=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"}),L?h.jsxs("span",{className:"tabular-nums",children:["· ",L]}):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(Jc,{remarkPlugins:[tu],components:nu,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(Jc,{remarkPlugins:[tu],components:nu,children:p})})]}):null,!p&&C.length===0&&!r&&!f?h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细信息"}):null,S&&(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":S,onClick:()=>u.open(S,o==null?void 0:o.agentType),className:ae("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(Vc,{className:"w-3 h-3"}),h.jsx("span",{children:"打开子 agent 对话"})]})}):null]}):null]})}function TM({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:ae("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(ll,{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:ae("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 FZ({todos:e,live:t}){return h.jsx(TM,{title:"Tasks",items:e,live:t,progressColor:"bg-green-500",listKind:"todo"})}function HZ({tasks:e,live:t}){return h.jsx(TM,{title:"Plan",items:e,live:t,progressColor:"bg-blue-500",listKind:"plan"})}function UZ(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 WZ(e){return(e.split("/").pop()??e)||e}function VZ({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(tz,{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(qZ,{memory:t},t.path))})]})}function qZ({memory:e}){const[t,n]=g.useState(!1),r=UZ(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:ae("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:WZ(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 KZ({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=(S,C)=>{const N={labels:new Set,freeText:""};if(!v||!i)return N;const T=i[S];if(typeof T!="string")return N;const B=T.split(",").map(I=>I.trim()).filter(Boolean),P=new Set(C.map(I=>I.label)),L=new Set,R=[];for(const I of B)P.has(I)?L.add(I):R.push(I);return{labels:L,freeText:R.join(", ")}},y=g.useMemo(()=>t.every(S=>{if((c[S.question]??"").trim().length>0)return!0;if(S.multiSelect){const N=a[S.question];return!!(N&&N.size>0)}return typeof s[S.question]=="string"&&s[S.question].length>0}),[t,s,a,c]),w=async()=>{if(!y||d||b||_||!n)return;const S={};for(const C of t){const N=(c[C.question]??"").trim();if(C.multiSelect){const T=a[C.question],B=T?C.options.filter(P=>T.has(P.label)).map(P=>P.label):[];if(N.length>0&&B.push(N),B.length===0)continue;S[C.question]=B.join(", ")}else if(N.length>0)S[C.question]=N;else{const T=s[C.question];typeof T=="string"&&(S[C.question]=T)}}f(!0);try{await n(S),m(!0)}finally{f(!1)}};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(dz,{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((S,C)=>{const N=`q-${C}`,T=`${e}-${C}`,B=x(S.question,S.options),P=b||_,L=c[S.question]??"",R=v?B.freeText:p?(c[S.question]??"").trim():"";return h.jsxs("div",{"data-testid":"msg-line-question-item",children:[S.question?h.jsx("div",{className:"text-text-200 mb-1.5",children:S.question}):null,h.jsx("div",{className:"flex flex-col gap-1",children:S.options.map((I,D)=>{var F;const z=`${N}-${D}`,$=v?B.labels.has(I.label):S.multiSelect?!!((F=a[S.question])!=null&&F.has(I.label)):s[S.question]===I.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:S.multiSelect?"checkbox":"radio",name:T,value:I.label,checked:$,disabled:b||_,onChange:()=>{b||_||(S.multiSelect?l(j=>{const O=new Set(j[S.question]??[]);return O.has(I.label)?O.delete(I.label):O.add(I.label),{...j,[S.question]:O}}):o(j=>({...j,[S.question]:I.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:I.label}),I.description?h.jsx("span",{className:"text-[12px] text-text-400 [overflow-wrap:anywhere]",children:I.description}):null]})]},z)})}),P?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:L,placeholder:"或自行输入回答...",onChange:I=>{const D=I.target.value;u(z=>({...z,[S.question]:D}))},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"})]},N)})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(ri,{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(ri,{size:"sm",variant:"ghost",onClick:()=>void r(),disabled:d,"data-testid":"msg-line-question-cancel",children:"跳过 / Skip"}):null]})]})}function GZ({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(KZ,{toolUseId:e,questions:t,onSubmit:i?a:void 0,...s?{onCancel:l}:{},submittedAnswers:o})}function XZ(){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 fl=XZ();function PM({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,turnCollapse:b}){const _=g.useMemo(()=>MU(e),[e]),x=g.useMemo(()=>b?jU(_,b):null,[_,b]),y={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};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,x!==null?x.map(w=>YZ(w,y)):_.map(w=>of(w,y))]})}function YZ(e,t){const n=`turn-${e.seq}`,r=e.query?of(e.query,t):null,i=e.process.map(o=>ZZ(o,t)),s=e.tail.map(o=>of(o,t));return e.status==="running"?h.jsxs(Je.Fragment,{children:[r,i,s]},n):h.jsxs(Je.Fragment,{children:[r,h.jsx(KU,{status:e.status,...e.durationMs!==void 0?{durationMs:e.durationMs}:{},children:i}),s]},n)}function ZZ(e,t){return e.kind==="tool-group"?h.jsx(WU,{items:e.items,renderItemDetail:n=>QZ(n,t)},`tool-group-${e.seq}`):of(e,t)}function QZ(e,t){const n=fl.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 of(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}=t,b=`${e.kind}-${e.seq}`;switch(e.kind){case"session-init":return null;case"user-text":{const _=typeof e.uuid=="string"?e.uuid:void 0,x=!!(n&&_&&(!r||r.has(_)));return h.jsx(EZ,{text:e.text,senderDisplayName:e.senderDisplayName,rewindTarget:x&&_&&n?{userMessageId:_,onRewind:n}:void 0},b)}case"user-meta":return h.jsx(RZ,{metaKind:e.metaKind,text:e.text},b);case"meta-text":return h.jsx(MZ,{text:e.text,metaSource:e.metaSource},b);case"agent-notification":return h.jsx(LZ,{text:e.text,taskId:e.taskId,parentToolUseId:e.parentToolUseId},b);case"assistant-text":{const _=typeof e.uuid=="string"?e.uuid:void 0,x=_&&(o||a)?{messageUuid:_,onFork:o,onQuickAsk:a}:void 0;return h.jsx(KY,{text:YU(e.text),forkTarget:x},b)}case"assistant-thinking":return h.jsx(GY,{text:e.text},b);case"permission-inline":return h.jsx(yZ,{tool:e.tool,input:e.input,onRespond:i??(()=>{}),onInterrupt:s},b);case"error":return h.jsx(bZ,{message:e.message},b);case"turn-end":return null;case"merged-tool":return JZ(e,b,{fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v});case"merged-agent":return h.jsx($Z,{description:e.description,input:e.input,output:e.output,error:e.error,pending:e.pending,notifications:e.notifications,toolResultExtra:e.toolResultExtra,progress:e.progress},b);case"plan-card":return h.jsx(HZ,{tasks:e.tasks},b);case"todo-checklist":return h.jsx(FZ,{todos:e.todos},b);case"memory-callout":return h.jsx(VZ,{memories:e.memories},b);case"question-card":{const _=d===void 0||d.has(e.toolUseId);return h.jsx(GZ,{toolUseId:e.toolUseId,questions:e.questions,historicalAnswers:e.submittedAnswers,realtimeAnswers:l==null?void 0:l[e.toolUseId],onSubmit:_?c:void 0,..._&&u?{onCancel:u}:{}},b)}default:return null}}function JZ(e,t,n){const r=fl.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(Je.Fragment,{children:i??h.jsx(SM,{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 eQ={builtin:"Commands",global:"Global",project:"Project",plugin:"Plugin"},Sk={builtin:0,global:1,project:2,plugin:3};function tQ({query:e,skills:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>IM(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(Je.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:eQ[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:ae("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 IM(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 nQ=g.createContext(null);function rQ(){return g.useContext(nQ)}const iQ={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 af(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 sQ(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 oQ(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 aQ(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 RM(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>oQ(i).includes(n)):e.slice();return r.sort((i,s)=>(kk[af(i)]??9)-(kk[af(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(()=>RM(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++){const f=af(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=af(c),m=aQ(c);return h.jsxs(Je.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:iQ[p]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":m.testid,onMouseEnter:()=>r(u),onClick:()=>i(c),className:ae("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]})]},sQ(c))})})}function lQ({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:ae("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:ae("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(To,{className:"h-3.5 w-3.5 text-text-400"})}),h.jsx("span",{className:ae("max-w-[120px] truncate text-text-200",s&&"text-text-400"),title:e.error??e.fileName,children:e.fileName}),i?h.jsx(As,{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(Sr,{className:"h-3 w-3"})})]})}function cQ({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(lQ,{attachment:r,onRemove:()=>t(r.id),onOpenPreview:n?()=>n(r):void 0},r.id))})}class Xl extends Error{constructor(t,n,r){super(n),this.code=t,this.status=r,this.name="UploadAttachmentError"}}async function uQ(e){if(!e.httpBaseUrl)throw new Xl("TUNNEL_NOT_READY","daemon httpBaseUrl unavailable");if(!e.httpToken)throw new Xl("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 Xl("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 Xl(i,s,r.status)}return await r.json()}const Ek=25*1024*1024,dQ="image/*,.txt,.md,.markdown,.csv,.json,.log,.yaml,.yml,.html,.xml,.pdf",hQ=["image/","text/"],fQ=new Set(["application/json","application/xml","application/x-yaml","application/yaml","application/pdf"]),pQ=new Set(["txt","md","markdown","csv","json","log","yaml","yml","html","xml","pdf"]);function mQ(e){var r;const t=(e.type||"").toLowerCase();if(t&&hQ.some(i=>t.startsWith(i))||t&&fQ.has(t))return!0;const n=((r=e.name.split(".").pop())==null?void 0:r.toLowerCase())??"";return n.length>0&&pQ.has(n)}let gQ=0;const vQ=()=>`att-${++gQ}-${Date.now()}`;function _Q(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 xQ(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:vQ(),fileName:d.name,mimeType:d.type||"application/octet-stream"};if(!mQ(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 _Q(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 uQ({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 Xl?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 I0=new Map,yQ=[];function Nk(e){if(e)return I0.get(e)}function Tk(e,t){e&&(t.draft.length===0&&t.attachments.length===0?I0.delete(e):I0.set(e,t))}function bQ(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 wQ({api:e,cwd:t,sessionKey:n,onSend:r,disabled:i,onNewSession:s,onClearSession:o,tool:a,spawnableContacts:l=yQ,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=Yf(),{attachments:S,setAttachments:C,addFiles:N,removeAttachment:T,clearAttachments:B}=xQ({httpBaseUrl:w.httpBaseUrl,httpToken:w.httpToken,sessionId:n,initial:(d==null?void 0:d.attachments)??[]}),[P,L]=g.useState([]),[R,I]=g.useState(!1),[D,z]=g.useState(0),[$,F]=g.useState(!1),[j,O]=g.useState([]),[E,H]=g.useState(!1),[V,A]=g.useState(0),[ne,se]=g.useState(!1),[G,ve]=g.useState([]),[Le,le]=g.useState(!1),[Ie,Re]=g.useState(null),[qe,_e]=g.useState(!1),$e=g.useRef(null),fn=g.useMemo(()=>{const oe=[];return s&&oe.push({name:"new",source:"builtin",description:"在当前目录下新建会话"}),o&&n&&oe.push({name:"clear",source:"builtin",description:"清除当前会话"}),oe},[s,o,n]),it=g.useMemo(()=>[...fn,...P],[fn,P]),Mt=g.useMemo(()=>{const oe=f.match(/^\/(\S*)$/);return oe?oe[1]:null},[f]),Xt=Mt!==null&&!$,At=g.useMemo(()=>Mt!==null?IM(it,Mt):[],[it,Mt]),bt=g.useMemo(()=>{const oe=f.match(/^@(\S*)$/);return oe?oe[1]:null},[f]),Ye=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})):[...j.map(oe=>({kind:"cc-agent",agent:oe})),...G.map(oe=>({kind:"persona",persona:oe})),...l.map(oe=>({kind:"contact",contact:oe}))],[Ie,u,j,G,l]),Tt=g.useMemo(()=>bt!==null?RM(st,bt):[],[st,bt]),Sn=g.useRef(f);g.useEffect(()=>{f!==Sn.current&&(F(!1),se(!1),Sn.current=f)},[f]);const sn=g.useCallback(()=>{F(!0)},[]),U=g.useCallback(()=>{se(!0)},[]),J=g.useRef(f),xe=g.useRef(S);g.useEffect(()=>{J.current=f},[f]),g.useEffect(()=>{xe.current=S},[S]);const Ce=g.useRef(n);g.useEffect(()=>{const oe=Ce.current;if(oe===n)return;Tk(oe,{draft:J.current,attachments:xe.current});const q=Nk(n);p((q==null?void 0:q.draft)??""),C((q==null?void 0:q.attachments)??[]),z(0),A(0),F(!1),se(!1),Re(null),$e.current=null,_e(!1),queueMicrotask(()=>{q!=null&&q.draft?MM(b.current):Go(b.current)}),Ce.current=n},[n,C]),g.useEffect(()=>()=>{Tk(Ce.current,{draft:J.current,attachments:xe.current})},[]),g.useEffect(()=>{z(0)},[Mt]),g.useEffect(()=>{A(0)},[bt]),g.useEffect(()=>{bt===null&&Ie&&(Re(null),$e.current=null,_e(!1))},[bt,Ie]),g.useEffect(()=>{if(!Xt||R)return;if(!e){I(!0);return}let oe=!1;return(async()=>{try{const q=await e.skillsList(t,a);oe||(L(q.skills??[]),I(!0))}catch{oe||I(!0)}})(),()=>{oe=!0}},[Xt,R,e,t,a]),g.useEffect(()=>{if(!Ye||E)return;if(!e){H(!0);return}let oe=!1;return(async()=>{try{const q=await e.agentsList(t,a);oe||(O(q.agents??[]),H(!0))}catch{oe||H(!0)}})(),()=>{oe=!0}},[Ye,E,e,t,a]),g.useEffect(()=>{if(!Ye||Le)return;if(!e){le(!0);return}let oe=!1;return(async()=>{try{const q=await e.personaList();oe||(ve((q.personas??[]).map(be=>({personaId:be.personaId,label:be.label}))),le(!0))}catch{oe||le(!0)}})(),()=>{oe=!0}},[Ye,Le,e]);const je=g.useCallback(oe=>{switch(oe.kind){case"persona":p(`@persona/${oe.persona.personaId} `);break;case"cc-agent":p(`@"${oe.agent.name} (agent)" `);break;case"contact":{const q=oe.contact.deviceId;Re({deviceId:q,displayName:oe.contact.displayName}),$e.current=q,_e(!0),Promise.resolve(c==null?void 0:c(q)).finally(()=>{$e.current===q&&_e(!1)}),p("@"),se(!1),setTimeout(()=>{var be;return(be=b.current)==null?void 0:be.focus()},0);return}case"remote-persona":p(`@persona/${oe.persona.personaId}@${oe.deviceId} `),Re(null);break}se(!1),setTimeout(()=>{var q;return(q=b.current)==null?void 0:q.focus()},0)},[c]),Lt=g.useCallback(()=>{Re(null),$e.current=null,_e(!1),p("@"),setTimeout(()=>{var oe;return(oe=b.current)==null?void 0:oe.focus()},0)},[]),on=g.useCallback(oe=>{if(oe.source==="builtin"&&oe.name==="new"&&s){p(""),B(),Go(b.current),s(t);return}if(oe.source==="builtin"&&oe.name==="clear"&&o){p(""),B(),Go(b.current),o();return}p(`/${oe.name} `),setTimeout(()=>{var q;return(q=b.current)==null?void 0:q.focus()},0)},[s,t,B,o]),wt=g.useCallback(async()=>{const oe=f.trim(),q=S.filter(be=>be.status==="done");if(!(!oe&&q.length===0)&&!(m||i)){if(oe==="/new"&&s){v(!0);try{await s(t),p(""),B(),Go(b.current)}finally{v(!1)}return}if(oe==="/clear"&&o){v(!0);try{await o(),p(""),B(),Go(b.current)}finally{v(!1)}return}v(!0);try{const be=a==="codex"?bQ(oe,P):oe,ct=SZ(be,S);await r(ct),p(""),B(),Go(b.current)}finally{v(!1)}}},[f,S,m,i,r,s,t,B,o,a,P]);return{draft:f,setDraft:p,sending:m,textareaRef:b,isComposingRef:_,onCompositionStart:x,onCompositionEnd:y,attachments:S,addFiles:N,removeAttachment:T,skillSelectorVisible:Xt,filteredSkills:At,slashQuery:Mt??"",activeSkillIdx:D,setActiveSkillIdx:z,selectSkill:on,dismissSkillSelector:sn,agentSelectorVisible:Ye,filteredAgents:Tt,mentionQuery:bt,activeAgentIdx:V,setActiveAgentIdx:A,selectAgent:je,dismissAgentSelector:U,drilldown:Ie,drilldownLoading:qe,exitDrilldown:Lt,doSend:wt}}const SQ=120;function MM(e){e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,SQ)}px`)}function Go(e){e&&(e.style.height="auto")}const kQ={spawnableContacts:[],ensureRemotePersonas:()=>Promise.resolve(),remotePersonasByDeviceId:new Map},CQ=g.createContext(kQ);function EQ(){return g.useContext(CQ)}function NQ({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(Jf,{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(xz,{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(Sr,{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,TQ=5e3;function Sd(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 PQ({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=EQ(),w=wQ({...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:S,setDraft:C,sending:N,textareaRef:T,attachments:B,addFiles:P,removeAttachment:L,skillSelectorVisible:R,filteredSkills:I,slashQuery:D,activeSkillIdx:z,setActiveSkillIdx:$,selectSkill:F,dismissSkillSelector:j,agentSelectorVisible:O,filteredAgents:E,mentionQuery:H,activeAgentIdx:V,setActiveAgentIdx:A,selectAgent:ne,dismissAgentSelector:se,drilldown:G,drilldownLoading:ve,exitDrilldown:Le,doSend:le}=w,Ie=rQ();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:Sd(document.activeElement)});let be=null,ct=null,an=null;const gl=setTimeout(()=>{if(be=T.current,!be){console.warn("[chat-focus] textarea 已不在,放弃聚焦",{sessionKey:s,signal:q});return}be.focus(),console.log("[chat-focus] focus() 已执行",{sessionKey:s,signal:q,landed:document.activeElement===be,activeElement:Sd(document.activeElement)}),ct=vl=>{const _l=Sd(vl.relatedTarget);setTimeout(()=>{console.warn("[chat-focus] STOLEN 输入框失焦",{sessionKey:s,signal:q,relatedTarget:_l,activeElementAfterTick:Sd(document.activeElement)})},0)},be.addEventListener("blur",ct,{once:!0}),an=setTimeout(()=>{be&&ct&&be.removeEventListener("blur",ct)},TQ)},Ik);return()=>{clearTimeout(gl),an&&clearTimeout(an),be&&ct&&be.removeEventListener("blur",ct)}},[Ie==null?void 0:Ie.signal]);const Re=!!t,qe=N||o||v,$e=(S.trim().length>0||B.some(q=>q.status==="done"))&&!o&&!N&&!c,fn=a??(c?"Answer the question above first...":qe?"Queue a message...":`Message ${Bx(r)}...`),it=g.useRef(!1),Mt=g.useCallback(()=>{it.current=!0},[]),Xt=g.useCallback(()=>{it.current=!1},[]),At=g.useCallback(q=>{if(R&&I.length>0){if(q.key==="ArrowDown")return q.preventDefault(),$(z>=I.length-1?0:z+1),!0;if(q.key==="ArrowUp")return q.preventDefault(),$(z<=0?I.length-1:z-1),!0;if(q.key==="Tab"||q.key==="Enter"&&!q.shiftKey){q.preventDefault();const be=I[z];return be&&F(be),!0}if(q.key==="Escape")return q.preventDefault(),j(),!0}return!1},[R,I,z,$,F,j]),bt=g.useCallback(q=>{if(O&&E.length>0){if(q.key==="ArrowDown")return q.preventDefault(),A(V>=E.length-1?0:V+1),!0;if(q.key==="ArrowUp")return q.preventDefault(),A(V<=0?E.length-1:V-1),!0;if(q.key==="Tab"||q.key==="Enter"&&!q.shiftKey){q.preventDefault();const be=E[V];return be&&ne(be),!0}if(q.key==="Escape")return q.preventDefault(),G?Le():se(),!0}return!1},[O,E,V,A,ne,se,G,Le]),Ye=g.useCallback(q=>{const be=q.nativeEvent;q.key==="Enter"&&YI({compositionActive:it.current,nativeIsComposing:be.isComposing,keyCode:be.keyCode})||At(q)||bt(q)||ZI({key:q.key,shiftKey:q.shiftKey,compositionActive:it.current,nativeIsComposing:be.isComposing,keyCode:be.keyCode})&&(q.preventDefault(),$e&&le())},[At,bt,$e,le]),st=g.useCallback(q=>{C(q.target.value),MM(q.target)},[C]),Tt=g.useCallback(q=>{q.target.files&&P(q.target.files),q.target.value=""},[P]),Sn=g.useCallback(q=>{if(!Re)return;const be=Array.from(q.clipboardData.items).map(ct=>ct.getAsFile()).filter(ct=>!!(ct&&ct.type.startsWith("image/")));be.length!==0&&(q.preventDefault(),P(be))},[P,Re]),[sn,U]=g.useState(null),J=g.useCallback(q=>{q.previewUrl&&U({url:q.previewUrl,name:q.fileName})},[]),[xe,Ce]=g.useState(!1),je=g.useCallback(q=>{Re&&(q.preventDefault(),Ce(!0))},[Re]),Lt=g.useCallback(()=>Ce(!1),[]),on=g.useCallback(q=>{Re&&(q.preventDefault(),Ce(!1),q.dataTransfer.files.length>0&&P(q.dataTransfer.files))},[P,Re]),wt=v&&!c&&typeof u=="function",oe=o||c;return h.jsxs("div",{"data-testid":"chat-input",className:ae("shrink-0 border-t border-bg-300/20 px-4 py-3",l),onDragOver:je,onDragLeave:Lt,onDrop:on,children:[h.jsxs("div",{className:"max-w-3xl mx-auto relative",children:[Re?h.jsx("input",{ref:x,type:"file",multiple:!0,accept:dQ,hidden:!0,onChange:Tt,"data-testid":"chat-input-file"}):null,h.jsxs("div",{"data-testid":"chat-input-bare",className:ae("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,R?h.jsx(tQ,{query:D,skills:I,activeIndex:z,onActiveIndexChange:$,onSelect:F}):null,O?G?!y.remotePersonasByDeviceId.has(G.deviceId)&&ve?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:A,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:A,onSelect:ne}):null,B.length>0?h.jsx(cQ,{attachments:B,onRemove:L,onOpenPreview:J}):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-100 px-3 pt-2 pb-4",children:m}):null,h.jsxs("div",{"data-testid":"bare-chat-input-frame",className:ae("relative flex flex-col gap-1 rounded-xl border border-border bg-bg-50 px-3 py-2 transition-colors duration-200",oe?"opacity-60":null,xe?"border-accent/60 bg-accent/5":null),children:[h.jsx("textarea",{ref:T,"data-testid":"chat-input-textarea",value:S,onChange:st,onKeyDown:Ye,onCompositionStart:Mt,onCompositionEnd:Xt,onPaste:Sn,placeholder:fn,disabled:oe,readOnly:oe,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:qe,"data-testid":"chat-input-attach","aria-label":"attach files",className:ae("flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors",qe?"cursor-default text-text-400/50":"cursor-pointer text-text-400 hover:bg-text-100/5 hover:text-text-200"),children:h.jsx(Gz,{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:ae("shrink-0 text-[11px] tabular-nums",_),children:["ctx:",b,"%"]}):null,p,wt?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:()=>{$e&&le()},disabled:!$e,"data-testid":"chat-input-send","aria-label":"send",className:ae("h-8 w-8 rounded-full flex items-center justify-center transition-colors",$e?"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(YB,{className:"w-4 h-4",strokeWidth:2.5})})]})]})]})]}),sn?h.jsx(NQ,{url:sn.url,fileName:sn.name,onClose:()=>U(null)}):null]})}function IQ(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function RQ({meta:e,tool:t,connState:n,variant:r="full",onOpenConfig:i,liveWorktreeRoot:s,infoPanelOpen:o=!1,onToggleInfoPanel:a,ephemeral:l=!1,onPromote:c,className:u}){const d=s??e.cwd??"",p=!!e.sessionLabel&&e.sessionLabel!==e.sessionId?e.sessionLabel:IQ(d),m=d;return r==="quickask"?h.jsxs("div",{"data-testid":"chat-header","data-variant":"quickask",className:ae("flex items-center shrink-0 px-3 py-2 gap-2",u),children:[c?h.jsx("button",{type:"button","data-testid":"chat-header-promote","data-promoted":l?"false":"true",disabled:!l,onClick:c,title:l?"保留为正式会话":"已保留为正式会话",className:ae("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md transition-colors",l?"text-text-500 hover:text-text-200 hover:bg-text-100/5 cursor-pointer":"text-amber-400"),children:h.jsx(rz,{className:ae("w-3.5 h-3.5",!l&&"fill-current")})}):null,h.jsx("span",{className:"font-semibold text-text-100 truncate text-[13px]","data-testid":"chat-header-worktree",title:m,children:p})]}):h.jsxs("div",{"data-testid":"chat-header","data-variant":"full",className:ae("relative flex items-center shrink-0 px-4 pr-[4.5rem] py-2.5",u),children:[h.jsx("span",{className:"font-semibold text-text-100 truncate text-[13px]","data-testid":"chat-header-worktree",title:m,children:p}),h.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 z-10 flex items-center gap-1",children:[a?h.jsx("button",{type:"button","aria-label":"Session info","data-testid":"chat-header-info-toggle","aria-pressed":o,onClick:a,title:"会话信息",className:ae("flex h-7 w-7 items-center justify-center rounded-md transition-colors duration-150 cursor-pointer outline-none",o?"text-accent bg-accent-dim":"bg-transparent text-text-300 hover:bg-bg-200 hover:text-text-100"),children:h.jsx(jT,{className:"w-4 h-4"})}):null,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(AT,{className:"w-4 h-4"})}):null]})]})}let MQ=null;function AQ(){return MQ}function Yl({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(Yl,{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(ll,{className:"w-3 h-3 shrink-0 text-accent"}):h.jsx(Jf,{className:"w-3 h-3 shrink-0 text-text-400 opacity-0 group-hover:opacity-100 transition-opacity"})]})})}function Qm({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 LQ({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,onClose: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 S=async()=>{if(!_)return;const C=AQ();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(GB,{className:"w-4 h-4"})}):h.jsx(jT,{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:"会话信息"}),h.jsx("button",{type:"button","data-testid":"session-info-close",onClick:p,"aria-label":"close session info",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:h.jsx(Sr,{className:"w-3.5 h-3.5"})})]}),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(Yl,{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(Ax,{className:"w-3 h-3 shrink-0 text-text-400"}),h.jsx("span",{className:"truncate",children:m})]})}):null,i&&s?h.jsx(Yl,{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(Yl,{label:"引擎",children:h.jsxs("span",{className:"inline-flex items-center gap-1.5","data-testid":"session-info-engine",children:[h.jsx(ep,{tool:e.tool,className:ae("w-3.5 h-3.5 shrink-0",tp(e.tool))}),h.jsxs("span",{className:"truncate",children:[Bx(e.tool),t.model?` · ${t.model}`:""]})]})}),h.jsx(Yl,{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(Qm,{icon:h.jsx(Ez,{className:"w-3.5 h-3.5"}),label:"Edited Files",onClick:o,testid:"session-info-files"}):null,a&&a>0&&l?h.jsx(Qm,{icon:h.jsx(pz,{className:"w-3.5 h-3.5"}),label:"定时任务",meta:String(a),onClick:l,testid:"session-info-cron"}):null,_?h.jsx(Qm,{icon:h.jsx(v$,{className:"w-3.5 h-3.5"}),label:"终端",meta:x,onClick:()=>void S(),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(Vz,{className:"w-3.5 h-3.5"}),h.jsx("span",{children:"强制停止"})]})}):null]})}const jQ=300;function DQ(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function AM(e,t){const n=mx(),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>{let a=!1;return(async()=>{try{const l=await n.kv.get(e);if(a)return;const c=DQ(l);typeof c=="number"&&Number.isFinite(c)&&c>0?i(c):i(t)}catch{a||i(t)}})(),()=>{a=!0}},[n,e,t]);const o=g.useCallback(a=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,n.kv.set(e,a).catch(()=>{})},jQ)},[n,e]);return g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),{initialSize:r??t,setSize:o,loading:r===null}}function OQ(e){return e==="TodoWrite"}function BQ(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 zQ(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":LM(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 LM(e,t,n,r,i,s){if(OQ(r)){const o=BQ(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(TU(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 $Q="AskUserQuestion";function jM(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=K6.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===$Q){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}LM(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}function FQ({api:e,cwd:t,toolSessionId:n}){const r=NM(),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?jM(o,0,"claude"):[],[o]);return!r||!i?null:h.jsxs("div",{"data-testid":"subagent-drawer","data-agent-id":i,className:ae("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(Sr,{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(As,{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(PM,{lines:f})})]})}function Ak(e,t){let n=0;for(const r of e.lines)r.startsWith(t)&&n++;return n}function HQ(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 UQ({open:e,onOpenChange:t,api:n,sessionId:r,userMessageId:i,lines:s,procAlive:o,onApplied:a,onNoChanges:l}){const c=g.useMemo(()=>HQ(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,S=!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(Sr,{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(qc,{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(VQ,{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(qc,{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:!S,onClick:()=>void y(),"data-testid":"rewind-apply",className:ae("h-8 px-3 rounded-md text-[12px] font-medium transition-colors",S?"bg-accent text-white hover:bg-accent-hover cursor-pointer":"bg-bg-200 text-text-400 cursor-not-allowed"),children:m?"回退中…":"确认回退"})]})]})]})}function WQ(e){return e.replace(/^\/Users\/[^/]+/,"~")}function VQ({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:WQ(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(qQ,{hunk:r},`${r.oldStart}-${r.oldLines}-${r.newStart}-${r.newLines}`))}):null]})}function qQ({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:ae("px-3 whitespace-pre",s),children:n.length>0?n:" "},r)})]})}function KQ({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 GQ={idle:"还没启动","turn-running":"正在 run 中","turn-idle":"进程活着,等输入",exited:"进程已退出",crashed:"启动失败 / 异常退出"};function XQ({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 YQ(e){return e==="running"||e==="observing"}function DM(e){return e==="running"||e==="running-idle"||e==="observing"}/**
|
|
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 OZ(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 BZ={readCount:"read",searchCount:"search",bashCount:"bash",editFileCount:"edit",linesAdded:"+lines",linesRemoved:"-lines",otherToolCount:"other"};function zZ(e){if(!e)return[];const t=[];for(const[n,r]of Object.entries(e)){if(!r||r<=0)continue;const i=BZ[n]??n;t.push(`${i}:${r}`)}return t}function $Z({description:e,input:t,output:n,error:r,pending:i,notifications:s,toolResultExtra:o,progress:a}){const[l,c]=g.useState(!1),u=NM(),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(()=>DZ(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)),_=OZ((m==null?void 0:m.tokens)??(v==null?void 0:v.tokens)),x=zZ(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),S=(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:CM(T.text)})),[s]),N=r?h.jsx(As,{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(Qf,{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":S??"",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:ae("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(N$,{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,S&&(u!=null&&u.open)?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"open-subagent-btn-header","data-agent-id":S,"aria-label":"打开子 agent 对话",onClick:T=>{T.stopPropagation(),u.open(S,o==null?void 0:o.agentType)},onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.stopPropagation(),T.preventDefault(),u.open(S,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(Vc,{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,L=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"}),L?h.jsxs("span",{className:"tabular-nums",children:["· ",L]}):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(Jc,{remarkPlugins:[tu],components:nu,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(Jc,{remarkPlugins:[tu],components:nu,children:p})})]}):null,!p&&C.length===0&&!r&&!f?h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细信息"}):null,S&&(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":S,onClick:()=>u.open(S,o==null?void 0:o.agentType),className:ae("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(Vc,{className:"w-3 h-3"}),h.jsx("span",{children:"打开子 agent 对话"})]})}):null]}):null]})}function TM({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:ae("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(ll,{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:ae("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 FZ({todos:e,live:t}){return h.jsx(TM,{title:"Tasks",items:e,live:t,progressColor:"bg-green-500",listKind:"todo"})}function HZ({tasks:e,live:t}){return h.jsx(TM,{title:"Plan",items:e,live:t,progressColor:"bg-blue-500",listKind:"plan"})}function UZ(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 WZ(e){return(e.split("/").pop()??e)||e}function VZ({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(tz,{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(qZ,{memory:t},t.path))})]})}function qZ({memory:e}){const[t,n]=g.useState(!1),r=UZ(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:ae("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:WZ(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 KZ({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=(S,C)=>{const N={labels:new Set,freeText:""};if(!v||!i)return N;const T=i[S];if(typeof T!="string")return N;const B=T.split(",").map(I=>I.trim()).filter(Boolean),P=new Set(C.map(I=>I.label)),L=new Set,R=[];for(const I of B)P.has(I)?L.add(I):R.push(I);return{labels:L,freeText:R.join(", ")}},y=g.useMemo(()=>t.every(S=>{if((c[S.question]??"").trim().length>0)return!0;if(S.multiSelect){const N=a[S.question];return!!(N&&N.size>0)}return typeof s[S.question]=="string"&&s[S.question].length>0}),[t,s,a,c]),w=async()=>{if(!y||d||b||_||!n)return;const S={};for(const C of t){const N=(c[C.question]??"").trim();if(C.multiSelect){const T=a[C.question],B=T?C.options.filter(P=>T.has(P.label)).map(P=>P.label):[];if(N.length>0&&B.push(N),B.length===0)continue;S[C.question]=B.join(", ")}else if(N.length>0)S[C.question]=N;else{const T=s[C.question];typeof T=="string"&&(S[C.question]=T)}}f(!0);try{await n(S),m(!0)}finally{f(!1)}};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(dz,{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((S,C)=>{const N=`q-${C}`,T=`${e}-${C}`,B=x(S.question,S.options),P=b||_,L=c[S.question]??"",R=v?B.freeText:p?(c[S.question]??"").trim():"";return h.jsxs("div",{"data-testid":"msg-line-question-item",children:[S.question?h.jsx("div",{className:"text-text-200 mb-1.5",children:S.question}):null,h.jsx("div",{className:"flex flex-col gap-1",children:S.options.map((I,D)=>{var F;const z=`${N}-${D}`,$=v?B.labels.has(I.label):S.multiSelect?!!((F=a[S.question])!=null&&F.has(I.label)):s[S.question]===I.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:S.multiSelect?"checkbox":"radio",name:T,value:I.label,checked:$,disabled:b||_,onChange:()=>{b||_||(S.multiSelect?l(j=>{const O=new Set(j[S.question]??[]);return O.has(I.label)?O.delete(I.label):O.add(I.label),{...j,[S.question]:O}}):o(j=>({...j,[S.question]:I.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:I.label}),I.description?h.jsx("span",{className:"text-[12px] text-text-400 [overflow-wrap:anywhere]",children:I.description}):null]})]},z)})}),P?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:L,placeholder:"或自行输入回答...",onChange:I=>{const D=I.target.value;u(z=>({...z,[S.question]:D}))},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"})]},N)})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(ri,{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(ri,{size:"sm",variant:"ghost",onClick:()=>void r(),disabled:d,"data-testid":"msg-line-question-cancel",children:"跳过 / Skip"}):null]})]})}function GZ({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(KZ,{toolUseId:e,questions:t,onSubmit:i?a:void 0,...s?{onCancel:l}:{},submittedAnswers:o})}function XZ(){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 fl=XZ();function PM({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,turnCollapse:b}){const _=g.useMemo(()=>MU(e),[e]),x=g.useMemo(()=>b?jU(_,b):null,[_,b]),y={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};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,x!==null?x.map(w=>YZ(w,y)):_.map(w=>of(w,y))]})}function YZ(e,t){const n=`turn-${e.seq}`,r=e.query?of(e.query,t):null,i=e.process.map(o=>ZZ(o,t)),s=e.tail.map(o=>of(o,t));return e.status==="running"?h.jsxs(Je.Fragment,{children:[r,i,s]},n):h.jsxs(Je.Fragment,{children:[r,h.jsx(KU,{status:e.status,...e.durationMs!==void 0?{durationMs:e.durationMs}:{},children:i}),s]},n)}function ZZ(e,t){return e.kind==="tool-group"?h.jsx(WU,{items:e.items,renderItemDetail:n=>QZ(n,t)},`tool-group-${e.seq}`):of(e,t)}function QZ(e,t){const n=fl.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 of(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}=t,b=`${e.kind}-${e.seq}`;switch(e.kind){case"session-init":return null;case"user-text":{const _=typeof e.uuid=="string"?e.uuid:void 0,x=!!(n&&_&&(!r||r.has(_)));return h.jsx(EZ,{text:e.text,senderDisplayName:e.senderDisplayName,rewindTarget:x&&_&&n?{userMessageId:_,onRewind:n}:void 0},b)}case"user-meta":return h.jsx(RZ,{metaKind:e.metaKind,text:e.text},b);case"meta-text":return h.jsx(MZ,{text:e.text,metaSource:e.metaSource},b);case"agent-notification":return h.jsx(LZ,{text:e.text,taskId:e.taskId,parentToolUseId:e.parentToolUseId},b);case"assistant-text":{const _=typeof e.uuid=="string"?e.uuid:void 0,x=_&&(o||a)?{messageUuid:_,onFork:o,onQuickAsk:a}:void 0;return h.jsx(KY,{text:YU(e.text),forkTarget:x},b)}case"assistant-thinking":return h.jsx(GY,{text:e.text},b);case"permission-inline":return h.jsx(yZ,{tool:e.tool,input:e.input,onRespond:i??(()=>{}),onInterrupt:s},b);case"error":return h.jsx(bZ,{message:e.message},b);case"turn-end":return null;case"merged-tool":return JZ(e,b,{fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v});case"merged-agent":return h.jsx($Z,{description:e.description,input:e.input,output:e.output,error:e.error,pending:e.pending,notifications:e.notifications,toolResultExtra:e.toolResultExtra,progress:e.progress},b);case"plan-card":return h.jsx(HZ,{tasks:e.tasks},b);case"todo-checklist":return h.jsx(FZ,{todos:e.todos},b);case"memory-callout":return h.jsx(VZ,{memories:e.memories},b);case"question-card":{const _=d===void 0||d.has(e.toolUseId);return h.jsx(GZ,{toolUseId:e.toolUseId,questions:e.questions,historicalAnswers:e.submittedAnswers,realtimeAnswers:l==null?void 0:l[e.toolUseId],onSubmit:_?c:void 0,..._&&u?{onCancel:u}:{}},b)}default:return null}}function JZ(e,t,n){const r=fl.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(Je.Fragment,{children:i??h.jsx(SM,{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 eQ={builtin:"Commands",global:"Global",project:"Project",plugin:"Plugin"},Sk={builtin:0,global:1,project:2,plugin:3};function tQ({query:e,skills:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>IM(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(Je.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:eQ[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:ae("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 IM(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 nQ=g.createContext(null);function rQ(){return g.useContext(nQ)}const iQ={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 af(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 sQ(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 oQ(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 aQ(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 RM(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>oQ(i).includes(n)):e.slice();return r.sort((i,s)=>(kk[af(i)]??9)-(kk[af(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(()=>RM(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++){const f=af(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=af(c),m=aQ(c);return h.jsxs(Je.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:iQ[p]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":m.testid,onMouseEnter:()=>r(u),onClick:()=>i(c),className:ae("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]})]},sQ(c))})})}function lQ({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:ae("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:ae("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(To,{className:"h-3.5 w-3.5 text-text-400"})}),h.jsx("span",{className:ae("max-w-[120px] truncate text-text-200",s&&"text-text-400"),title:e.error??e.fileName,children:e.fileName}),i?h.jsx(As,{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(Sr,{className:"h-3 w-3"})})]})}function cQ({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(lQ,{attachment:r,onRemove:()=>t(r.id),onOpenPreview:n?()=>n(r):void 0},r.id))})}class Xl extends Error{constructor(t,n,r){super(n),this.code=t,this.status=r,this.name="UploadAttachmentError"}}async function uQ(e){if(!e.httpBaseUrl)throw new Xl("TUNNEL_NOT_READY","daemon httpBaseUrl unavailable");if(!e.httpToken)throw new Xl("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 Xl("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 Xl(i,s,r.status)}return await r.json()}const Ek=25*1024*1024,dQ="image/*,.txt,.md,.markdown,.csv,.json,.log,.yaml,.yml,.html,.xml,.pdf",hQ=["image/","text/"],fQ=new Set(["application/json","application/xml","application/x-yaml","application/yaml","application/pdf"]),pQ=new Set(["txt","md","markdown","csv","json","log","yaml","yml","html","xml","pdf"]);function mQ(e){var r;const t=(e.type||"").toLowerCase();if(t&&hQ.some(i=>t.startsWith(i))||t&&fQ.has(t))return!0;const n=((r=e.name.split(".").pop())==null?void 0:r.toLowerCase())??"";return n.length>0&&pQ.has(n)}let gQ=0;const vQ=()=>`att-${++gQ}-${Date.now()}`;function _Q(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 xQ(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:vQ(),fileName:d.name,mimeType:d.type||"application/octet-stream"};if(!mQ(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 _Q(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 uQ({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 Xl?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 I0=new Map,yQ=[];function Nk(e){if(e)return I0.get(e)}function Tk(e,t){e&&(t.draft.length===0&&t.attachments.length===0?I0.delete(e):I0.set(e,t))}function bQ(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 wQ({api:e,cwd:t,sessionKey:n,onSend:r,disabled:i,onNewSession:s,onClearSession:o,tool:a,spawnableContacts:l=yQ,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=Yf(),{attachments:S,setAttachments:C,addFiles:N,removeAttachment:T,clearAttachments:B}=xQ({httpBaseUrl:w.httpBaseUrl,httpToken:w.httpToken,sessionId:n,initial:(d==null?void 0:d.attachments)??[]}),[P,L]=g.useState([]),[R,I]=g.useState(!1),[D,z]=g.useState(0),[$,F]=g.useState(!1),[j,O]=g.useState([]),[E,H]=g.useState(!1),[V,A]=g.useState(0),[ne,se]=g.useState(!1),[G,ve]=g.useState([]),[Le,le]=g.useState(!1),[Ie,Re]=g.useState(null),[qe,_e]=g.useState(!1),$e=g.useRef(null),fn=g.useMemo(()=>{const oe=[];return s&&oe.push({name:"new",source:"builtin",description:"在当前目录下新建会话"}),o&&n&&oe.push({name:"clear",source:"builtin",description:"清除当前会话"}),oe},[s,o,n]),it=g.useMemo(()=>[...fn,...P],[fn,P]),Mt=g.useMemo(()=>{const oe=f.match(/^\/(\S*)$/);return oe?oe[1]:null},[f]),Xt=Mt!==null&&!$,At=g.useMemo(()=>Mt!==null?IM(it,Mt):[],[it,Mt]),bt=g.useMemo(()=>{const oe=f.match(/^@(\S*)$/);return oe?oe[1]:null},[f]),Ye=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})):[...j.map(oe=>({kind:"cc-agent",agent:oe})),...G.map(oe=>({kind:"persona",persona:oe})),...l.map(oe=>({kind:"contact",contact:oe}))],[Ie,u,j,G,l]),Tt=g.useMemo(()=>bt!==null?RM(st,bt):[],[st,bt]),Sn=g.useRef(f);g.useEffect(()=>{f!==Sn.current&&(F(!1),se(!1),Sn.current=f)},[f]);const sn=g.useCallback(()=>{F(!0)},[]),U=g.useCallback(()=>{se(!0)},[]),J=g.useRef(f),xe=g.useRef(S);g.useEffect(()=>{J.current=f},[f]),g.useEffect(()=>{xe.current=S},[S]);const Ce=g.useRef(n);g.useEffect(()=>{const oe=Ce.current;if(oe===n)return;Tk(oe,{draft:J.current,attachments:xe.current});const q=Nk(n);p((q==null?void 0:q.draft)??""),C((q==null?void 0:q.attachments)??[]),z(0),A(0),F(!1),se(!1),Re(null),$e.current=null,_e(!1),queueMicrotask(()=>{q!=null&&q.draft?MM(b.current):Go(b.current)}),Ce.current=n},[n,C]),g.useEffect(()=>()=>{Tk(Ce.current,{draft:J.current,attachments:xe.current})},[]),g.useEffect(()=>{z(0)},[Mt]),g.useEffect(()=>{A(0)},[bt]),g.useEffect(()=>{bt===null&&Ie&&(Re(null),$e.current=null,_e(!1))},[bt,Ie]),g.useEffect(()=>{if(!Xt||R)return;if(!e){I(!0);return}let oe=!1;return(async()=>{try{const q=await e.skillsList(t,a);oe||(L(q.skills??[]),I(!0))}catch{oe||I(!0)}})(),()=>{oe=!0}},[Xt,R,e,t,a]),g.useEffect(()=>{if(!Ye||E)return;if(!e){H(!0);return}let oe=!1;return(async()=>{try{const q=await e.agentsList(t,a);oe||(O(q.agents??[]),H(!0))}catch{oe||H(!0)}})(),()=>{oe=!0}},[Ye,E,e,t,a]),g.useEffect(()=>{if(!Ye||Le)return;if(!e){le(!0);return}let oe=!1;return(async()=>{try{const q=await e.personaList();oe||(ve((q.personas??[]).map(be=>({personaId:be.personaId,label:be.label}))),le(!0))}catch{oe||le(!0)}})(),()=>{oe=!0}},[Ye,Le,e]);const je=g.useCallback(oe=>{switch(oe.kind){case"persona":p(`@persona/${oe.persona.personaId} `);break;case"cc-agent":p(`@"${oe.agent.name} (agent)" `);break;case"contact":{const q=oe.contact.deviceId;Re({deviceId:q,displayName:oe.contact.displayName}),$e.current=q,_e(!0),Promise.resolve(c==null?void 0:c(q)).finally(()=>{$e.current===q&&_e(!1)}),p("@"),se(!1),setTimeout(()=>{var be;return(be=b.current)==null?void 0:be.focus()},0);return}case"remote-persona":p(`@persona/${oe.persona.personaId}@${oe.deviceId} `),Re(null);break}se(!1),setTimeout(()=>{var q;return(q=b.current)==null?void 0:q.focus()},0)},[c]),Lt=g.useCallback(()=>{Re(null),$e.current=null,_e(!1),p("@"),setTimeout(()=>{var oe;return(oe=b.current)==null?void 0:oe.focus()},0)},[]),on=g.useCallback(oe=>{if(oe.source==="builtin"&&oe.name==="new"&&s){p(""),B(),Go(b.current),s(t);return}if(oe.source==="builtin"&&oe.name==="clear"&&o){p(""),B(),Go(b.current),o();return}p(`/${oe.name} `),setTimeout(()=>{var q;return(q=b.current)==null?void 0:q.focus()},0)},[s,t,B,o]),wt=g.useCallback(async()=>{const oe=f.trim(),q=S.filter(be=>be.status==="done");if(!(!oe&&q.length===0)&&!(m||i)){if(oe==="/new"&&s){v(!0);try{await s(t),p(""),B(),Go(b.current)}finally{v(!1)}return}if(oe==="/clear"&&o){v(!0);try{await o(),p(""),B(),Go(b.current)}finally{v(!1)}return}v(!0);try{const be=a==="codex"?bQ(oe,P):oe,ct=SZ(be,S);await r(ct),p(""),B(),Go(b.current)}finally{v(!1)}}},[f,S,m,i,r,s,t,B,o,a,P]);return{draft:f,setDraft:p,sending:m,textareaRef:b,isComposingRef:_,onCompositionStart:x,onCompositionEnd:y,attachments:S,addFiles:N,removeAttachment:T,skillSelectorVisible:Xt,filteredSkills:At,slashQuery:Mt??"",activeSkillIdx:D,setActiveSkillIdx:z,selectSkill:on,dismissSkillSelector:sn,agentSelectorVisible:Ye,filteredAgents:Tt,mentionQuery:bt,activeAgentIdx:V,setActiveAgentIdx:A,selectAgent:je,dismissAgentSelector:U,drilldown:Ie,drilldownLoading:qe,exitDrilldown:Lt,doSend:wt}}const SQ=120;function MM(e){e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,SQ)}px`)}function Go(e){e&&(e.style.height="auto")}const kQ={spawnableContacts:[],ensureRemotePersonas:()=>Promise.resolve(),remotePersonasByDeviceId:new Map},CQ=g.createContext(kQ);function EQ(){return g.useContext(CQ)}function NQ({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(Jf,{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(xz,{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(Sr,{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,TQ=5e3;function Sd(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 PQ({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=EQ(),w=wQ({...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:S,setDraft:C,sending:N,textareaRef:T,attachments:B,addFiles:P,removeAttachment:L,skillSelectorVisible:R,filteredSkills:I,slashQuery:D,activeSkillIdx:z,setActiveSkillIdx:$,selectSkill:F,dismissSkillSelector:j,agentSelectorVisible:O,filteredAgents:E,mentionQuery:H,activeAgentIdx:V,setActiveAgentIdx:A,selectAgent:ne,dismissAgentSelector:se,drilldown:G,drilldownLoading:ve,exitDrilldown:Le,doSend:le}=w,Ie=rQ();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:Sd(document.activeElement)});let be=null,ct=null,an=null;const gl=setTimeout(()=>{if(be=T.current,!be){console.warn("[chat-focus] textarea 已不在,放弃聚焦",{sessionKey:s,signal:q});return}be.focus(),console.log("[chat-focus] focus() 已执行",{sessionKey:s,signal:q,landed:document.activeElement===be,activeElement:Sd(document.activeElement)}),ct=vl=>{const _l=Sd(vl.relatedTarget);setTimeout(()=>{console.warn("[chat-focus] STOLEN 输入框失焦",{sessionKey:s,signal:q,relatedTarget:_l,activeElementAfterTick:Sd(document.activeElement)})},0)},be.addEventListener("blur",ct,{once:!0}),an=setTimeout(()=>{be&&ct&&be.removeEventListener("blur",ct)},TQ)},Ik);return()=>{clearTimeout(gl),an&&clearTimeout(an),be&&ct&&be.removeEventListener("blur",ct)}},[Ie==null?void 0:Ie.signal]);const Re=!!t,qe=N||o||v,$e=(S.trim().length>0||B.some(q=>q.status==="done"))&&!o&&!N&&!c,fn=a??(c?"Answer the question above first...":qe?"Queue a message...":`Message ${Bx(r)}...`),it=g.useRef(!1),Mt=g.useCallback(()=>{it.current=!0},[]),Xt=g.useCallback(()=>{it.current=!1},[]),At=g.useCallback(q=>{if(R&&I.length>0){if(q.key==="ArrowDown")return q.preventDefault(),$(z>=I.length-1?0:z+1),!0;if(q.key==="ArrowUp")return q.preventDefault(),$(z<=0?I.length-1:z-1),!0;if(q.key==="Tab"||q.key==="Enter"&&!q.shiftKey){q.preventDefault();const be=I[z];return be&&F(be),!0}if(q.key==="Escape")return q.preventDefault(),j(),!0}return!1},[R,I,z,$,F,j]),bt=g.useCallback(q=>{if(O&&E.length>0){if(q.key==="ArrowDown")return q.preventDefault(),A(V>=E.length-1?0:V+1),!0;if(q.key==="ArrowUp")return q.preventDefault(),A(V<=0?E.length-1:V-1),!0;if(q.key==="Tab"||q.key==="Enter"&&!q.shiftKey){q.preventDefault();const be=E[V];return be&&ne(be),!0}if(q.key==="Escape")return q.preventDefault(),G?Le():se(),!0}return!1},[O,E,V,A,ne,se,G,Le]),Ye=g.useCallback(q=>{const be=q.nativeEvent;q.key==="Enter"&&YI({compositionActive:it.current,nativeIsComposing:be.isComposing,keyCode:be.keyCode})||At(q)||bt(q)||ZI({key:q.key,shiftKey:q.shiftKey,compositionActive:it.current,nativeIsComposing:be.isComposing,keyCode:be.keyCode})&&(q.preventDefault(),$e&&le())},[At,bt,$e,le]),st=g.useCallback(q=>{C(q.target.value),MM(q.target)},[C]),Tt=g.useCallback(q=>{q.target.files&&P(q.target.files),q.target.value=""},[P]),Sn=g.useCallback(q=>{if(!Re)return;const be=Array.from(q.clipboardData.items).map(ct=>ct.getAsFile()).filter(ct=>!!(ct&&ct.type.startsWith("image/")));be.length!==0&&(q.preventDefault(),P(be))},[P,Re]),[sn,U]=g.useState(null),J=g.useCallback(q=>{q.previewUrl&&U({url:q.previewUrl,name:q.fileName})},[]),[xe,Ce]=g.useState(!1),je=g.useCallback(q=>{Re&&(q.preventDefault(),Ce(!0))},[Re]),Lt=g.useCallback(()=>Ce(!1),[]),on=g.useCallback(q=>{Re&&(q.preventDefault(),Ce(!1),q.dataTransfer.files.length>0&&P(q.dataTransfer.files))},[P,Re]),wt=v&&!c&&typeof u=="function",oe=o||c;return h.jsxs("div",{"data-testid":"chat-input",className:ae("shrink-0 border-t border-bg-300/20 px-4 py-3",l),onDragOver:je,onDragLeave:Lt,onDrop:on,children:[h.jsxs("div",{className:"max-w-3xl mx-auto relative",children:[Re?h.jsx("input",{ref:x,type:"file",multiple:!0,accept:dQ,hidden:!0,onChange:Tt,"data-testid":"chat-input-file"}):null,h.jsxs("div",{"data-testid":"chat-input-bare",className:ae("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,R?h.jsx(tQ,{query:D,skills:I,activeIndex:z,onActiveIndexChange:$,onSelect:F}):null,O?G?!y.remotePersonasByDeviceId.has(G.deviceId)&&ve?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:A,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:A,onSelect:ne}):null,B.length>0?h.jsx(cQ,{attachments:B,onRemove:L,onOpenPreview:J}):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:ae("relative flex flex-col gap-1 rounded-xl border border-border bg-bg-0 px-3 py-2 transition-colors duration-200",oe?"opacity-60":null,xe?"border-accent/60 bg-accent/5":null),children:[h.jsx("textarea",{ref:T,"data-testid":"chat-input-textarea",value:S,onChange:st,onKeyDown:Ye,onCompositionStart:Mt,onCompositionEnd:Xt,onPaste:Sn,placeholder:fn,disabled:oe,readOnly:oe,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:qe,"data-testid":"chat-input-attach","aria-label":"attach files",className:ae("flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors",qe?"cursor-default text-text-400/50":"cursor-pointer text-text-400 hover:bg-text-100/5 hover:text-text-200"),children:h.jsx(Gz,{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:ae("shrink-0 text-[11px] tabular-nums",_),children:["ctx:",b,"%"]}):null,p,wt?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:()=>{$e&&le()},disabled:!$e,"data-testid":"chat-input-send","aria-label":"send",className:ae("h-8 w-8 rounded-full flex items-center justify-center transition-colors",$e?"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(YB,{className:"w-4 h-4",strokeWidth:2.5})})]})]})]})]}),sn?h.jsx(NQ,{url:sn.url,fileName:sn.name,onClose:()=>U(null)}):null]})}function IQ(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function RQ({meta:e,tool:t,connState:n,variant:r="full",onOpenConfig:i,liveWorktreeRoot:s,infoPanelOpen:o=!1,onToggleInfoPanel:a,ephemeral:l=!1,onPromote:c,className:u}){const d=s??e.cwd??"",p=!!e.sessionLabel&&e.sessionLabel!==e.sessionId?e.sessionLabel:IQ(d),m=d;return r==="quickask"?h.jsxs("div",{"data-testid":"chat-header","data-variant":"quickask",className:ae("flex items-center shrink-0 px-3 py-2 gap-2",u),children:[c?h.jsx("button",{type:"button","data-testid":"chat-header-promote","data-promoted":l?"false":"true",disabled:!l,onClick:c,title:l?"保留为正式会话":"已保留为正式会话",className:ae("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md transition-colors",l?"text-text-500 hover:text-text-200 hover:bg-text-100/5 cursor-pointer":"text-amber-400"),children:h.jsx(rz,{className:ae("w-3.5 h-3.5",!l&&"fill-current")})}):null,h.jsx("span",{className:"font-semibold text-text-100 truncate text-[13px]","data-testid":"chat-header-worktree",title:m,children:p})]}):h.jsxs("div",{"data-testid":"chat-header","data-variant":"full",className:ae("relative flex items-center shrink-0 px-4 pr-[4.5rem] py-2.5",u),children:[h.jsx("span",{className:"font-semibold text-text-100 truncate text-[13px]","data-testid":"chat-header-worktree",title:m,children:p}),h.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 z-10 flex items-center gap-1",children:[a?h.jsx("button",{type:"button","aria-label":"Session info","data-testid":"chat-header-info-toggle","aria-pressed":o,onClick:a,title:"会话信息",className:ae("flex h-7 w-7 items-center justify-center rounded-md transition-colors duration-150 cursor-pointer outline-none",o?"text-accent bg-accent-dim":"bg-transparent text-text-300 hover:bg-bg-200 hover:text-text-100"),children:h.jsx(jT,{className:"w-4 h-4"})}):null,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(AT,{className:"w-4 h-4"})}):null]})]})}let MQ=null;function AQ(){return MQ}function Yl({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(Yl,{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(ll,{className:"w-3 h-3 shrink-0 text-accent"}):h.jsx(Jf,{className:"w-3 h-3 shrink-0 text-text-400 opacity-0 group-hover:opacity-100 transition-opacity"})]})})}function Qm({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 LQ({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,onClose: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 S=async()=>{if(!_)return;const C=AQ();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(GB,{className:"w-4 h-4"})}):h.jsx(jT,{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:"会话信息"}),h.jsx("button",{type:"button","data-testid":"session-info-close",onClick:p,"aria-label":"close session info",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:h.jsx(Sr,{className:"w-3.5 h-3.5"})})]}),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(Yl,{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(Ax,{className:"w-3 h-3 shrink-0 text-text-400"}),h.jsx("span",{className:"truncate",children:m})]})}):null,i&&s?h.jsx(Yl,{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(Yl,{label:"引擎",children:h.jsxs("span",{className:"inline-flex items-center gap-1.5","data-testid":"session-info-engine",children:[h.jsx(ep,{tool:e.tool,className:ae("w-3.5 h-3.5 shrink-0",tp(e.tool))}),h.jsxs("span",{className:"truncate",children:[Bx(e.tool),t.model?` · ${t.model}`:""]})]})}),h.jsx(Yl,{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(Qm,{icon:h.jsx(Ez,{className:"w-3.5 h-3.5"}),label:"Edited Files",onClick:o,testid:"session-info-files"}):null,a&&a>0&&l?h.jsx(Qm,{icon:h.jsx(pz,{className:"w-3.5 h-3.5"}),label:"定时任务",meta:String(a),onClick:l,testid:"session-info-cron"}):null,_?h.jsx(Qm,{icon:h.jsx(v$,{className:"w-3.5 h-3.5"}),label:"终端",meta:x,onClick:()=>void S(),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(Vz,{className:"w-3.5 h-3.5"}),h.jsx("span",{children:"强制停止"})]})}):null]})}const jQ=300;function DQ(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function AM(e,t){const n=mx(),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>{let a=!1;return(async()=>{try{const l=await n.kv.get(e);if(a)return;const c=DQ(l);typeof c=="number"&&Number.isFinite(c)&&c>0?i(c):i(t)}catch{a||i(t)}})(),()=>{a=!0}},[n,e,t]);const o=g.useCallback(a=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,n.kv.set(e,a).catch(()=>{})},jQ)},[n,e]);return g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),{initialSize:r??t,setSize:o,loading:r===null}}function OQ(e){return e==="TodoWrite"}function BQ(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 zQ(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":LM(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 LM(e,t,n,r,i,s){if(OQ(r)){const o=BQ(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(TU(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 $Q="AskUserQuestion";function jM(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=K6.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===$Q){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}LM(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}function FQ({api:e,cwd:t,toolSessionId:n}){const r=NM(),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?jM(o,0,"claude"):[],[o]);return!r||!i?null:h.jsxs("div",{"data-testid":"subagent-drawer","data-agent-id":i,className:ae("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(Sr,{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(As,{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(PM,{lines:f})})]})}function Ak(e,t){let n=0;for(const r of e.lines)r.startsWith(t)&&n++;return n}function HQ(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 UQ({open:e,onOpenChange:t,api:n,sessionId:r,userMessageId:i,lines:s,procAlive:o,onApplied:a,onNoChanges:l}){const c=g.useMemo(()=>HQ(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,S=!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(Sr,{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(qc,{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(VQ,{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(qc,{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:!S,onClick:()=>void y(),"data-testid":"rewind-apply",className:ae("h-8 px-3 rounded-md text-[12px] font-medium transition-colors",S?"bg-accent text-white hover:bg-accent-hover cursor-pointer":"bg-bg-200 text-text-400 cursor-not-allowed"),children:m?"回退中…":"确认回退"})]})]})]})}function WQ(e){return e.replace(/^\/Users\/[^/]+/,"~")}function VQ({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:WQ(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(qQ,{hunk:r},`${r.oldStart}-${r.oldLines}-${r.newStart}-${r.newLines}`))}):null]})}function qQ({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:ae("px-3 whitespace-pre",s),children:n.length>0?n:" "},r)})]})}function KQ({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 GQ={idle:"还没启动","turn-running":"正在 run 中","turn-idle":"进程活着,等输入",exited:"进程已退出",crashed:"启动失败 / 异常退出"};function XQ({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 YQ(e){return e==="running"||e==="observing"}function DM(e){return e==="running"||e==="running-idle"||e==="observing"}/**
|
|
507
507
|
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
508
508
|
* @license MIT
|
|
509
509
|
*
|
|
@@ -551,4 +551,4 @@ Minimum version required to store current data is: `+s+`.
|
|
|
551
551
|
|
|
552
552
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
553
553
|
|
|
554
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return g.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Ore="DialogDescriptionWarning",Bre=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${vA(Ore).contentName}}.`;return g.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},zre=iA,$re=aA,_A=lA,xA=cA,yA=dA,bA=fA,Fre=mA;const i1=zre,Hre=$re,wA=g.forwardRef(({className:e,...t},n)=>h.jsx(_A,{ref:n,className:ae("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));wA.displayName=_A.displayName;const Mp=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(Hre,{children:[h.jsx(wA,{}),h.jsxs(xA,{ref:r,className:ae("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2","gap-4 rounded-lg border border-border bg-elevated p-6 shadow-lg",e),...n,children:[t,h.jsxs(Fre,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-accent",children:[h.jsx(Sr,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mp.displayName=xA.displayName;const Ap=({className:e,...t})=>h.jsx("div",{className:ae("flex flex-col space-y-1.5 text-left",e),...t});Ap.displayName="DialogHeader";const s1=({className:e,...t})=>h.jsx("div",{className:ae("flex flex-row justify-end gap-2",e),...t});s1.displayName="DialogFooter";const Lp=g.forwardRef(({className:e,...t},n)=>h.jsx(yA,{ref:n,className:ae("text-lg font-semibold leading-none text-text-100",e),...t}));Lp.displayName=yA.displayName;const SA=g.forwardRef(({className:e,...t},n)=>h.jsx(bA,{ref:n,className:ae("text-sm text-text-300",e),...t}));SA.displayName=bA.displayName;function Ure({persona:e,open:t,onClose:n,onDelete:r,embedded:i,onLoadPersonality:s,onSavePersonality:o,onDirtyChange:a,initialPersonality:l,onShareCapability:c,readOnly:u=!1,larkBot:d}){const[f,p]=g.useState(!1),m=b=>{p(b),a==null||a(b)},v=()=>{f&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!i&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:v,"aria-hidden":"true"}),h.jsxs("aside",{className:i?"flex h-full w-full flex-col bg-bg-0":"absolute right-0 top-0 z-40 flex h-full w-[420px] flex-col bg-bg-0 border-l border-border shadow-xl","data-testid":"persona-settings-drawer",children:[h.jsxs("header",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[h.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[h.jsx(c$,{className:"h-4 w-4 text-text-300"}),h.jsx("span",{className:"text-[13px] font-medium text-text-100 truncate",children:"Persona 设置"})]}),h.jsx("button",{type:"button",onClick:v,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(Sr,{className:"h-4 w-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto p-6 flex flex-col gap-4",children:[h.jsxs("header",{className:"flex items-start justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("h2",{className:"text-lg font-semibold text-text-100 truncate",children:e.label}),e.public?h.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-bg-200 px-1.5 py-0.5 text-[10px] text-text-200",children:[h.jsx(Rz,{className:"h-3 w-3"})," 公开"]}):h.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-error-dim px-1.5 py-0.5 text-[10px] text-error",children:[h.jsx(Pz,{className:"h-3 w-3"})," 已关闭"]})]}),h.jsx("span",{className:"font-mono text-[11px] text-text-400 truncate","data-testid":"persona-id-subtitle",children:e.personaId})]}),h.jsxs("div",{className:"flex items-center gap-1",children:[c?h.jsxs("button",{type:"button",onClick:c,"aria-label":"分享给他人",title:"分享给他人",className:"inline-flex items-center gap-1 rounded-sm px-2 py-1.5 text-xs text-text-200 hover:bg-bg-200 hover:text-text-100",children:[h.jsx(Lx,{className:"h-3.5 w-3.5"}),"分享"]}):null,r?h.jsx("button",{type:"button",onClick:r,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(jx,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),d?h.jsxs(h.Fragment,{children:[h.jsx(Kre,{...d}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs(h.Fragment,{children:[h.jsx(Zre,{onLoad:s,...o?{onSave:o}:{},onDirtyChange:m,initialPersonality:l,readOnly:u}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(Gre,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(Xre,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(Yre,{plugins:e.plugins??[]})]})]})]}):null}function Wre({qrUrl:e,busy:t,onCancel:n}){const[r,i]=g.useState(null);return g.useEffect(()=>{let s=!1;return Mu.toDataURL(e,{width:240,margin:1}).then(o=>{s||i(o)}).catch(()=>{s||i(null)}),()=>{s=!0}},[e]),h.jsx(i1,{open:!0,onOpenChange:s=>s||n==null?void 0:n(),children:h.jsxs(Mp,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",onInteractOutside:s=>s.preventDefault(),onEscapeKeyDown:s=>s.preventDefault(),children:[h.jsx(Ap,{children:h.jsx(Lp,{children:"扫码关联飞书 Bot"})}),h.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r?h.jsx("img",{src:r,alt:"飞书扫码创建应用二维码",className:"h-60 w-60 rounded bg-white p-2","data-testid":"lark-bot-qr-img"}):h.jsx("div",{className:"flex h-60 w-60 items-center justify-center text-[12px] text-text-400",children:"二维码生成中…"}),h.jsx("span",{className:"text-center text-[12px] text-text-300",children:"用手机飞书扫码,按页面提示创建应用。确认后自动完成关联。"}),n?h.jsx("button",{type:"button",disabled:t,onClick:n,className:"rounded border border-border px-3 py-1.5 text-[12px] text-text-300 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-provision-cancel",children:"取消"}):null]})]})})}const Vre={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},qre=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function Kre({status:e,onProvision:t,onCancelProvision:n,onBindManual:r,onUnbind:i}){const[s,o]=g.useState(!1),[a,l]=g.useState(null),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,m]=g.useState(null),v=x=>{x&&(o(!0),l(null),x().catch(y=>l(y instanceof Error?y.message:String(y))).finally(()=>o(!1)))},b=()=>{m(null),v(t)},_=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(Zf,{className:"h-3.5 w-3.5 text-text-400","aria-hidden":!0}),h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"飞书 Bot"})]});return e?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,e.state==="unbound"||e.state==="provisioning"?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"关联一个飞书 bot 后,这个 persona 就是它:拉进群后群成员 @ 它提问、或直接私聊它, 推理跑在你本机,回复自动发回去。"}),t?h.jsx("button",{type:"button",disabled:s||e.state==="provisioning",onClick:b,className:"self-start rounded border border-border bg-bg-200 px-3 py-1.5 text-[12px] font-medium text-text-100 hover:bg-bg-300 disabled:opacity-50","data-testid":"lark-bot-provision",children:e.state==="provisioning"?"等待扫码…":"扫码关联飞书 Bot"}):null,e.state==="unbound"&&e.errorReason&&!p?h.jsxs("div",{className:"flex flex-col gap-1.5 rounded border border-error bg-error-dim px-2 py-1.5","data-testid":"lark-bot-provision-error",children:[h.jsx("span",{className:"text-[11px] text-error",children:Vre[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[qre.has(e.errorReason)&&t?h.jsx("button",{type:"button",disabled:s,onClick:b,className:"rounded border border-border px-2 py-1 text-[11px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-provision-retry",children:"重新扫码"}):null,h.jsx("button",{type:"button",onClick:()=>m(e.errorReason??null),className:"rounded border border-border px-2 py-1 text-[11px] text-text-300 hover:bg-bg-200","data-testid":"lark-bot-provision-error-dismiss",children:"知道了"})]})]}):null,e.state==="provisioning"&&e.qrUrl?h.jsx(Wre,{qrUrl:e.qrUrl,busy:s,onCancel:n?()=>v(n):void 0}):null,r&&e.state==="unbound"?h.jsxs("details",{"data-testid":"lark-bot-manual-details",children:[h.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400 hover:text-text-300",children:"已有飞书应用?手动填入凭证"}),h.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),h.jsx("input",{value:c,onChange:x=>u(x.target.value),placeholder:"App ID(cli_ 开头)",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-appid"}),h.jsx("input",{value:d,onChange:x=>f(x.target.value),type:"password",placeholder:"App Secret",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-secret"}),h.jsx("button",{type:"button",disabled:s||!c||!d,onClick:()=>v(()=>r({appId:c,appSecret:d})),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-manual-submit",children:s?"绑定中…":"绑定"})]})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.state==="broken"?h.jsxs("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-broken",children:["Bot 凭证失效:",e.brokenReason??"未知原因","。请解绑后重新填入有效凭证绑定。"]}):null,h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-200",children:[h.jsx("span",{className:"font-medium text-text-100",children:e.botName??"未命名 bot"}),e.appId?h.jsx("span",{className:"text-[11px] text-text-400",children:e.appId}):null]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"把 bot 拉进任意飞书群,群成员 @ 它即可提问。"}),e.groups.length>0?h.jsx("ul",{className:"flex flex-col gap-0.5","data-testid":"lark-bot-groups",children:e.groups.map(x=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",x.chatName??x.chatId]},x.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),i?h.jsx("button",{type:"button",disabled:s,onClick:()=>v(i),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-error hover:bg-error-dim disabled:opacity-50","data-testid":"lark-bot-unbind",children:"解绑"}):null]}):null,a?h.jsx("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-error",children:a}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function Gre({settings:e}){var t,n,r,i,s,o,a,l,c,u,d,f,p;return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-sandbox-setting-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Sandbox Setting"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"约束此 persona 的沙箱权限(只读,需通过文件修改)。"})]}),e==null?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-sandbox-setting-empty",children:"暂无 sandbox 配置"}):h.jsxs("div",{className:"flex flex-col gap-1.5 rounded-md border border-border bg-bg-100 px-3 py-2",children:[h.jsx(Md,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(Md,{label:"沙箱启用",value:bg((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(Md,{label:"沙箱内自动放行 Bash",value:bg((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(Md,{label:"允许非沙箱命令",value:bg((i=e.sandbox)==null?void 0:i.allowUnsandboxedCommands)}),h.jsxs("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border pt-1.5",children:[h.jsx(Fl,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(Fl,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(Fl,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(Fl,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(Fl,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function bg(e){return e===!0?"是":e===!1?"否":"—"}function Md({label:e,value:t}){return h.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px]",children:[h.jsx("span",{className:"text-text-300",children:e}),h.jsx("span",{className:"font-mono text-text-100",children:t})]})}function Fl({label:e,paths:t}){const n=!t||t.length===0;return h.jsxs("div",{className:"flex flex-col gap-1",children:[h.jsx("span",{className:"text-[11px] text-text-300",children:e}),n?h.jsx("span",{className:"text-[11px] text-text-400",children:"—"}):h.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((r,i)=>h.jsx("span",{className:"rounded-sm border border-border bg-bg-0 px-1.5 py-0.5 font-mono text-[11px] text-text-200",children:r},`${e}-${i}-${r}`))})]})}function Xre({skills:e}){return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-skills-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Persona Skills"}),h.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[10px] text-text-300",children:e.length})]}),h.jsxs("span",{className:"text-[11px] text-text-400",children:["此 persona 私有 skills(来自"," ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/.claude/skills/"}),")。"]})]}),e.length===0?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-skills-empty",children:"暂无 skills"}):h.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border bg-bg-100",children:e.map(t=>h.jsxs("li",{className:"flex flex-col gap-0.5 px-3 py-2","data-testid":"persona-skill-row",children:[h.jsx("span",{className:"font-mono text-[13px] text-text-100",children:t.name}),t.description?h.jsx("span",{className:"text-[12px] text-text-300",children:t.description}):h.jsx("span",{className:"text-[11px] text-text-400 italic",children:"无描述"})]},t.name))})]})}function Yre({plugins:e}){return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-plugins-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Enabled Plugins"}),h.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[10px] text-text-300",children:e.length})]}),h.jsxs("span",{className:"text-[11px] text-text-400",children:["此 persona 已启用的插件(来自"," ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/.claude/settings.json"})," ","的 ",h.jsx("code",{className:"font-mono",children:"enabledPlugins"}),")。"]})]}),e.length===0?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-plugins-empty",children:"暂无启用插件"}):h.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border bg-bg-100",children:e.map(t=>h.jsx("li",{className:"flex flex-col gap-0.5 px-3 py-2","data-testid":"persona-plugin-row",children:h.jsx("span",{className:"font-mono text-[13px] text-text-100",children:t.id})},t.id))})]})}function Zre({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1}){const s=r!==void 0,[o,a]=g.useState(s),[l,c]=g.useState(s?r:""),[u,d]=g.useState(s?r:""),[f,p]=g.useState(null),[m,v]=g.useState(!1),[b,_]=g.useState(null),x=Je.useRef(e),y=Je.useRef(t),w=Je.useRef(n);Je.useEffect(()=>{x.current=e,y.current=t,w.current=n});const S=Je.useCallback(()=>{a(!1),p(null),x.current().then(B=>{c(B),d(B),a(!0)}).catch(B=>{p(B instanceof Error?B.message:String(B))})},[]);Je.useEffect(()=>{s||S()},[s,S]);const C=!i&&o&&u!==l;Je.useEffect(()=>{i||w.current(C)},[C,i]);const N=()=>{y.current&&(v(!0),_(null),y.current(u).then(()=>{c(u),v(!1)}).catch(B=>{_(B instanceof Error?B.message:String(B)),v(!1)}))},T=()=>{d(l),_(null)};return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-personality-section",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"人格 (Personality)"}),f?h.jsxs("div",{"data-testid":"persona-personality-load-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error flex items-center justify-between gap-2",children:[h.jsxs("span",{children:["加载失败:",f]}),h.jsx("button",{type:"button",onClick:S,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,b?h.jsxs("div",{"data-testid":"persona-personality-save-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",b]}):null,h.jsx("textarea",{"data-testid":"persona-personality-textarea",value:u,onChange:B=>d(B.target.value),readOnly:i,disabled:!i&&(!o||m),placeholder:o?"":"加载中…",rows:8,className:"min-h-[8rem] max-h-[18rem] resize-y rounded-md border border-border bg-bg-100 px-2 py-1.5 font-mono text-[11px] text-text-100 disabled:opacity-60"}),!i&&h.jsxs("p",{className:"text-[10px] text-text-400",children:["写入到 ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/CLAUDE.md"}),"。 修改只对新启动的 sub-session 生效。"]}),o&&C?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:T,disabled:m,className:"rounded-sm border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200 disabled:opacity-60",children:"放弃"}),h.jsx("button",{type:"button",onClick:N,disabled:m,"data-testid":"persona-personality-save-btn",className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:m?"保存中…":"保存"})]}):null]})}const Qre={state:"unbound",groups:[]};function Jre(e,t){const[n,r]=g.useState(null);g.useEffect(()=>{if(!e)return;let l=!1;r(null);const c=async()=>{try{const f=await e.request("larkBot:status",{personaId:t});l||r(f)}catch{l||r(Qre)}};c();const u=e.on("larkBot:state",f=>{const p=f;if(p.personaId!==t)return;const{personaId:m,...v}=p;r(v)}),d=e.on("daemon:connected",()=>{c()});return()=>{l=!0,u(),d()}},[e,t]);const i=g.useCallback(async()=>{e&&await e.request("larkBot:provision",{personaId:t})},[e,t]),s=g.useCallback(async()=>{e&&await e.request("larkBot:provisionCancel",{personaId:t})},[e,t]),o=g.useCallback(async l=>{e&&await e.request("larkBot:bindManual",{personaId:t,...l})},[e,t]),a=g.useCallback(async()=>{e&&await e.request("larkBot:unbind",{personaId:t})},[e,t]);return{status:n,provision:i,cancelProvision:s,bindManual:o,unbind:a}}function eie(e,t="owner"){const{persona:n}=PT(e),r=MB(e),i=AB(),s=LB(),{httpBaseUrl:o}=Yf(),a=$i(),l=Jre(t==="guest"?null:a,e),{capabilities:c}=Ky((n==null?void 0:n.tool)??"claude"),u=g.useMemo(()=>!(n!=null&&n.public)||!o||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(o)?null:`${o}/s/${e}`,[n==null?void 0:n.public,o,e]),d=g.useCallback((y,w)=>{i(e,w).catch(S=>{Be("persona",`${y} failed`,S)})},[i,e]),f=g.useCallback(y=>d("togglePublic",{public:y}),[d]),p=g.useCallback(y=>d("changeTool",{tool:y}),[d]),m=g.useCallback(y=>d("changeModel",{model:y}),[d]),v=g.useCallback(y=>d("changeEffort",{effort:y}),[d]),b=g.useCallback(()=>!n||!confirm(`删除 persona "${n.label}"?`)?!1:(s(e).catch(y=>{Be("persona","delete failed",y)}),!0),[n,s,e]),_=g.useCallback(async()=>r.loaded?r.personality:(await r.refresh()).personality,[r]),x=g.useCallback(async y=>{await i(e,{personality:y}),await r.refresh()},[i,e,r]);return{persona:n,detail:r,models:(c==null?void 0:c.models)??[],configSchema:(c==null?void 0:c.configSchema)??[],larkBot:l,guestShareUrl:u,changeTool:p,changeModel:m,changeEffort:v,togglePublic:f,remove:b,loadPersonality:_,savePersonality:x}}function tie({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const l=eie(e,a),{persona:c,detail:u}=l,d=g.useCallback(()=>{l.remove()&&n()},[l,n]);if(!c)return null;const f=a==="guest";return h.jsx(Ure,{embedded:i,persona:{...c,skills:u.skills,plugins:u.plugins,sandboxSettings:u.sandboxSettings},open:t,onClose:n,onLoadPersonality:l.loadPersonality,onDirtyChange:s,readOnly:f,...f?{}:{onTogglePublic:l.togglePublic,guestShareUrl:l.guestShareUrl,onChangeTool:l.changeTool,onChangeModel:l.changeModel,onChangeEffort:l.changeEffort,models:l.models,configSchema:l.configSchema,onDelete:d,onSavePersonality:l.savePersonality,larkBot:{status:l.larkBot.status,onProvision:l.larkBot.provision,onCancelProvision:l.larkBot.cancelProvision,onBindManual:l.larkBot.bindManual,onUnbind:l.larkBot.unbind},...o?{onShareCapability:o}:{}}})}function nie(e){try{const t=new URL(e);return t.protocol==="ws:"?t.protocol="http:":t.protocol==="wss:"&&(t.protocol="https:"),`${t.protocol}//${t.host}`}catch{return e}}function rie(e,t){try{const n=new URL(e),r=new URL(t);return n.protocol=r.protocol,n.host=r.host,n.toString()}catch{return e}}async function o1(e,t,n,r,i){const s=await e.attachmentSignUrl({sessionId:n,relPath:r,...i!==void 0?{ttlSeconds:i}:{}});return rie(s.url,nie(t.url))}async function iie(e,t,n,r,i=60){const s=window.open("about:blank","_blank");try{const o=await o1(e,t,n,r,i);s?s.location.href=o:window.open(o,"_blank")}catch(o){throw s&&s.close(),o}}async function sie(e){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{const n=document.createElement("textarea");n.value=e,n.style.position="fixed",n.style.left="-9999px",n.style.top="0",n.setAttribute("readonly",""),document.body.appendChild(n),n.select();const r=document.execCommand("copy");return document.body.removeChild(n),r}catch{return!1}}const oie={...nu,h1:({node:e,...t})=>h.jsx("h1",{...t,className:"mt-4 mb-3 text-[18px] font-semibold leading-tight text-text-100"}),h2:({node:e,...t})=>h.jsx("h2",{...t,className:"mt-4 mb-2 text-[16px] font-semibold leading-tight text-text-100"}),h3:({node:e,...t})=>h.jsx("h3",{...t,className:"mt-3 mb-2 text-[14px] font-semibold leading-tight text-text-100"}),h4:({node:e,...t})=>h.jsx("h4",{...t,className:"mt-3 mb-1 text-[13px] font-semibold text-text-100"}),h5:({node:e,...t})=>h.jsx("h5",{...t,className:"mt-2 mb-1 text-[12px] font-semibold text-text-100"}),h6:({node:e,...t})=>h.jsx("h6",{...t,className:"mt-2 mb-1 text-[12px] font-semibold text-text-300"}),p:({node:e,...t})=>h.jsx("p",{...t,className:"my-2 leading-relaxed"}),ul:({node:e,...t})=>h.jsx("ul",{...t,className:"my-2 list-disc space-y-1 pl-5"}),ol:({node:e,...t})=>h.jsx("ol",{...t,className:"my-2 list-decimal space-y-1 pl-5"}),li:({node:e,...t})=>h.jsx("li",{...t,className:"leading-relaxed"}),blockquote:({node:e,...t})=>h.jsx("blockquote",{...t,className:"my-2 border-l-2 border-border pl-3 italic text-text-300"}),code:({node:e,className:t,children:n,...r})=>t?h.jsx("code",{...r,className:`${t} font-mono text-[12px]`,children:n}):h.jsx("code",{...r,className:"rounded bg-bg-50 px-1 py-0.5 font-mono text-[12px] text-text-100",children:n}),pre:({node:e,...t})=>h.jsx("pre",{...t,className:"my-2 overflow-auto rounded border border-border bg-bg-0 p-3 text-[12px] font-mono text-text-100"}),hr:({node:e,...t})=>h.jsx("hr",{...t,className:"my-3 border-border"}),table:({node:e,...t})=>h.jsx("table",{...t,className:"my-2 w-full border-collapse text-[12px]"}),thead:({node:e,...t})=>h.jsx("thead",{...t,className:"bg-bg-50"}),th:({node:e,...t})=>h.jsx("th",{...t,className:"border border-border px-2 py-1 text-left font-semibold"}),td:({node:e,...t})=>h.jsx("td",{...t,className:"border border-border px-2 py-1"}),strong:({node:e,...t})=>h.jsx("strong",{...t,className:"font-semibold text-text-100"}),em:({node:e,...t})=>h.jsx("em",{...t,className:"italic"})};function aie(e){const t=e.split("/");return t[t.length-1]||e}function kA({relPath:e,loadMarkdown:t,headerRight:n,showTitleBar:r=!1}){const[i,s]=g.useState(null),[o,a]=g.useState(null),[l,c]=g.useState(!1);return g.useEffect(()=>{if(!e)return;let u=!1;return c(!0),a(null),s(null),(async()=>{try{const d=await t(e);if(u)return;s(d)}catch(d){if(u)return;a(d.message||String(d))}finally{u||c(!1)}})(),()=>{u=!0}},[e,t]),h.jsxs("div",{className:"flex flex-col h-full",children:[r&&e?h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[h.jsx("div",{"data-testid":"md-preview-title",className:"truncate text-[13px] font-medium text-text-100",title:e,children:aie(e)}),h.jsx("div",{className:"flex items-center gap-1",children:n})]}):null,h.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 text-[13px] text-text-100",children:l?h.jsx("div",{"data-testid":"md-preview-loading",className:"text-text-400",children:"Loading…"}):o?h.jsx("div",{"data-testid":"md-preview-error",className:"text-destructive whitespace-pre-wrap",children:o}):i!==null?h.jsx("div",{"data-testid":"md-preview-content",className:"max-w-none",children:h.jsx(Jc,{remarkPlugins:[tu],components:oie,children:i})}):null})]})}function lie({open:e,onOpenChange:t,relPath:n,loadMarkdown:r,onShare:i}){return e?h.jsx("div",{"data-testid":"md-preview-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-1/2 max-w-[900px] flex-col border-l border-border bg-elevated shadow-2xl",children:h.jsx(kA,{relPath:n,loadMarkdown:r,showTitleBar:!0,headerRight:h.jsxs(h.Fragment,{children:[i?h.jsx("button",{type:"button","data-testid":"md-preview-share","aria-label":"Share rendered preview link",onClick:i,className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-400 hover:bg-bg-50 hover:text-text-200",children:h.jsx(Dz,{className:"h-4 w-4"})}):null,h.jsx("button",{type:"button","aria-label":"Close preview",onClick:()=>t(!1),className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-400 hover:bg-bg-50 hover:text-text-200",children:h.jsx(Sr,{className:"h-4 w-4"})})]})})}):null}function cie({left:e,right:t,stage:n,onExpand:r,onCollapse:i}){const s=n==="stopped",[o,a]=g.useState(!1);async function l(){if(!o){a(!0);try{await r()}catch{}finally{a(!1)}}}async function c(){if(!o){a(!0);try{await i()}catch{}finally{a(!1)}}}return h.jsxs("div",{className:"flex h-full w-full min-h-0","data-testid":"two-pane-layout",children:[h.jsxs("div",{className:"relative flex min-w-0 flex-1 flex-col","data-testid":"two-pane-left",children:[s&&h.jsx("button",{type:"button",disabled:o,className:"absolute right-14 top-2 z-10 rounded border border-border bg-elevated px-2 py-1 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed",onClick:l,children:o?"启动中…":"展开预览"}),e]}),!s&&h.jsxs("div",{className:"flex w-1/2 min-w-[320px] flex-col border-l border-bg-200","data-testid":"two-pane-right",children:[h.jsx("div",{className:"flex items-center justify-end gap-2 border-b border-bg-200 bg-bg-50 px-2 py-1",children:h.jsx("button",{type:"button",disabled:o,className:"rounded px-2 py-1 text-[12px] text-text-300 hover:bg-bg-100 disabled:opacity-50",onClick:c,children:"收起预览"})}),h.jsx("div",{className:"min-h-0 flex-1",children:t})]})]})}const uie=6173,die=6182;function hie({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=uie;v<=die;v++)(v===r||!i.includes(v))&&o.push(v);const[a,l]=g.useState(r),[c,u]=g.useState(!1),[d,f]=g.useState(null),p=a!==r&&!c;async function m(){if(p){u(!0),f(null);try{await s(a),t(!1)}catch(v){f((v==null?void 0:v.message)??String(v))}finally{u(!1)}}}return h.jsx(i1,{open:e,onOpenChange:t,children:h.jsxs(Mp,{className:"max-w-md",children:[h.jsxs(Ap,{children:[h.jsxs(Lp,{children:["改端口 · ",n]}),h.jsxs(SA,{children:["手改通常发生在系统其他进程占了默认分配的端口、dev server 起不来时。 提交后 daemon 会停 dev server → 写 ",h.jsx("code",{className:"mx-1 rounded bg-bg-100 px-1 py-0.5 text-[11px]",children:".clawd-project.json"})," → 用新端口重新起。"]})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx("label",{className:"text-xs text-text-400",children:"新端口(仅显示段内可用 + 当前端口)"}),h.jsx("select",{className:"h-9 rounded-md border border-border bg-elevated px-3 py-1 text-sm text-text-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",value:a,onChange:v=>l(Number(v.target.value)),disabled:c,children:o.map(v=>h.jsxs("option",{value:v,children:[v,v===r?"(当前)":""]},v))}),o.length===1&&h.jsx("div",{className:"text-[11px] text-text-400",children:"端口段已全被其它 project 占用,没有可换的;先删一个 idle project 释放端口。"}),d&&h.jsx("div",{className:"rounded border border-destructive/30 bg-destructive/5 px-3 py-2 text-[12px] text-destructive",children:d})]}),h.jsxs(s1,{children:[h.jsx(ri,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ri,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const LC=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function fie({currentStage:e,onCancel:t}){const n=LC.findIndex(r=>r.stage===e);return h.jsxs("div",{"data-testid":"publish-progress",className:"flex items-center gap-3 border-b border-bg-200 bg-bg-50 px-3 py-1.5 text-[12px]",children:[LC.map((r,i)=>{const s=i<n,o=i===n,a=s?"text-text-300":o?"text-text-200":"text-text-500/50";return h.jsxs("span",{className:`flex items-center gap-1 ${a}`,children:[s?h.jsx(Qf,{className:"size-3.5"}):o?h.jsx(In,{className:"size-3.5 animate-spin"}):h.jsx(MT,{className:"size-3.5"}),h.jsxs("span",{children:[r.label,o?"中…":""]})]},r.stage)}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const pie={build:"构建",deploy:"部署",verify:"验证"};function mie({stage:e,onRetry:t,onDismiss:n}){return h.jsxs("div",{"data-testid":"publish-interrupted-banner",className:"flex items-center gap-2 border-b border-yellow-400/40 bg-yellow-400/10 px-3 py-1.5 text-[12px]",children:[h.jsx(qc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",pie[e],"]"]})," ","阶段被中断(daemon 重启)"]}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded bg-accent-main-100 px-2 py-0.5 text-[11px] text-oncolor-100 hover:opacity-90",children:"重新发布"}),h.jsx("button",{type:"button",onClick:n,className:"rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const gie={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function vie({stage:e,onFocusChat:t,onClose:n}){return h.jsxs("div",{"data-testid":"publish-failed-banner",className:"flex items-center gap-2 border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[12px]",children:[h.jsx(As,{className:"size-3.5 text-destructive"}),h.jsxs("button",{type:"button",onClick:t,className:"flex-1 text-left text-text-200 hover:underline",children:["发布失败:",h.jsxs("strong",{className:"font-medium",children:["[",gie[e],"]"]})," ","已通知 assistant 接管 →"]}),h.jsx("button",{type:"button",onClick:n,"aria-label":"关闭失败提示",className:"rounded p-0.5 text-text-400 hover:bg-bg-100 hover:text-text-200",children:h.jsx(Sr,{className:"size-3.5"})})]})}const jC={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function _ie({project:e,previewHost:t,previewScheme:n,onUpdatePort:r,allUsedPorts:i,publishSlot:s,publishInFlightStage:o,onDismissPublishJob:a,onRetryPublish:l,publishFailureBanner:c,onPublishFailureBannerClose:u,onPublishFailureBannerFocusChat:d}){var _,x;const[f,p]=g.useState(!1);if(!e)return h.jsx("div",{className:"flex h-full w-full items-center justify-center p-6 text-center text-[13px] text-text-400",children:"未绑定 project"});const m=e.stage??(e.isRunning?"running":"stopped"),v=t?`${n}://${t}/preview/${e.port}/`:null,b=e.prodUrl??null;return h.jsxs("div",{className:"flex h-full w-full flex-col","data-testid":"preview-pane",children:[h.jsxs("header",{className:"flex items-center justify-between gap-2 border-b border-bg-200 bg-bg-50 px-3 py-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[h.jsx("span",{className:"font-medium text-text-200",children:e.name}),h.jsx("span",{className:"rounded bg-bg-100 px-1.5 py-0.5 text-[11px] text-text-400",children:e.port}),h.jsx("span",{className:"text-[10px] uppercase tracking-wider text-text-500",children:m==="running"?"dev":m})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[b?h.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",title:`打开线上:${b}`,className:"inline-flex items-center gap-1 rounded border border-bg-200 px-2 py-0.5 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Vc,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(sy,{children:[h.jsx(oy,{asChild:!0,children:h.jsx("button",{type:"button","aria-label":"Project settings",className:"rounded p-1 text-text-400 hover:bg-bg-100",children:h.jsx(a$,{className:"size-3.5"})})}),h.jsxs(dp,{align:"end",children:[h.jsx(bi,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(bi,{disabled:!0,title:"rename not supported yet",onSelect:y=>y.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(vie,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((_=e.publishJob)==null?void 0:_.status)==="in-flight"?h.jsx(fie,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((x=e.publishJob)==null?void 0:x.status)==="interrupted"?h.jsx(mie,{stage:e.publishJob.stage,onRetry:()=>void(l==null?void 0:l()),onDismiss:()=>void(a==null?void 0:a())}):null,h.jsx("div",{className:"min-h-0 flex-1",children:m==="failed"?h.jsx(xie,{reason:e.stageReason}):m==="stopped"?null:m==="running"?v?h.jsx("iframe",{"data-testid":"preview-iframe",className:"size-full border-0 bg-white",src:v,title:"preview"}):h.jsx(DC,{label:"等 tunnel 起来…",step:"-"}):h.jsx(DC,{label:jC[m].label,step:jC[m].step})}),h.jsx(hie,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async y=>{await r(y)}})]})}function DC({label:e,step:t}){return h.jsxs("div",{"data-testid":"preview-spinner",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(In,{className:"size-6 animate-spin text-accent-main-100"}),h.jsx("div",{className:"text-[13px] text-text-200",children:e}),h.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-500",children:t}),h.jsx("div",{className:"mt-2 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度"})]})}function xie({reason:e}){return h.jsxs("div",{"data-testid":"preview-failed",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(As,{className:"size-6 text-destructive"}),h.jsx("div",{className:"text-[13px] text-text-200",children:"project 启动失败"}),h.jsx("div",{className:"max-w-[400px] text-[12px] text-text-400",children:e??"未知原因 —— 看 ~/.clawd/clawd.log 排查"}),h.jsx("div",{className:"mt-1 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度 / 跟它说怎么修"})]})}function yie({error:e,onClose:t}){const[n,r]=g.useState(!1),i=async()=>{var a;if(!e)return;const s=e.message;let o=!1;try{(a=navigator.clipboard)!=null&&a.writeText&&(await navigator.clipboard.writeText(s),o=!0)}catch{o=!1}if(!o){const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();try{document.execCommand("copy"),o=!0}catch{o=!1}finally{document.body.removeChild(l)}}o&&(r(!0),setTimeout(()=>r(!1),1500))};return h.jsx(i1,{open:!!e,onOpenChange:s=>{s||(r(!1),t())},children:h.jsxs(Mp,{className:"max-w-lg",children:[h.jsx(Ap,{children:h.jsx(Lp,{children:(e==null?void 0:e.title)??"错误"})}),h.jsx("pre",{"data-testid":"rpc-error-message",className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded border border-bg-200 bg-bg-50 px-3 py-2 text-[12px] text-text-200",children:(e==null?void 0:e.message)??""}),h.jsxs(s1,{children:[h.jsx(ri,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(ll,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(Jf,{className:"size-3.5"}),"复制"]})}),h.jsx(ri,{onClick:t,children:"关闭"})]})]})})}function bie(e,t){for(const n of[e,t])if(n)try{const r=new URL(n),i=r.protocol==="https:"||r.protocol==="wss:"?"https":"http";return{host:r.host,scheme:i}}catch{}return{host:null,scheme:"https"}}const wie={codex:"on-request",claude:"bypassPermissions"};function Sie(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??wie[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function kie(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...Sie({cwd:t.cwd,sourceSessionId:t.sessionId,sourcePermissionMode:t.permissionMode,sourceOwnerPersonaId:t.ownerPersonaId,sourceTool:t.tool}),...r.ephemeral?{ephemeral:!0}:{}});try{const{forkedToolSessionId:s}=await e.sessionFork({cwd:t.cwd,toolSessionId:t.toolSessionId,messageUuid:n,targetCwd:i.cwd});await e.sessionResume(i.sessionId,s)}catch(s){throw e.sessionDelete(i.sessionId).catch(o=>Be("quick-ask","fork rollback failed",o)),s}return i}async function Cie(e,t,n){return kie(e,t,n,{ephemeral:!0})}function Ad(e){return e!=null&&e.ephemeral!==!1}async function Eie(e,t){return t.stillEphemeral?(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0):!1}function Nie(){return{quickAsk:null,mds:[],active:null}}function Tie(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function Pie(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function Iie(e){if(!e.quickAsk)return e;const t=e.active==="quick-ask",n=e.mds[0],r=t?n?{kind:"md",relPath:n}:null:e.active;return{...e,quickAsk:null,active:r}}function Rie(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function Mie(e,t){const n=e.mds.indexOf(t);if(n<0)return e;const r=e.mds.filter(l=>l!==t);if(!(e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===t))return{...e,mds:r};const s=r[n],o=n>0?r[n-1]:void 0;let a=null;return s?a={kind:"md",relPath:s}:o?a={kind:"md",relPath:o}:e.quickAsk&&(a="quick-ask"),{...e,mds:r,active:a}}function Aie(e,t){return{...e,active:t}}function Lie(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function CA(e){return e.quickAsk!==null||e.mds.length>0}function jie(e){return e.split("/").pop()||e}function Die({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onPromoteQuickAsk:a}){if(!CA(e))return null;const l=[];e.quickAsk&&l.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(s0,{className:"w-3.5 h-3.5"})});for(const c of e.mds)l.push({id:{kind:"md",relPath:c},label:jie(c),title:c,icon:h.jsx(To,{className:"w-3.5 h-3.5"})});return h.jsxs("div",{className:"flex flex-col h-full bg-bg-0 border-l border-text-100/10",children:[h.jsx(B5,{delayDuration:200,skipDelayDuration:100,children:h.jsx("div",{className:["flex items-stretch h-9 border-b border-text-100/10 shrink-0 overflow-x-auto","[scrollbar-width:none] [-ms-overflow-style:none]","[&::-webkit-scrollbar]:hidden"].join(" "),role:"tablist",children:l.map(c=>{const u=Lie(e.active,c.id),d=c.id==="quick-ask"?"quick-ask":`md:${c.id.relPath}`;return h.jsxs(z5,{children:[h.jsx($5,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":u,"data-tab-title":c.title,onClick:()=>n(c.id),className:["group relative flex items-center gap-2 px-3 h-full cursor-pointer select-none","text-[12px] max-w-[180px] shrink-0 transition-colors duration-100",u?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[c.icon,h.jsx("span",{className:"truncate",children:c.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${c.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",u?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:f=>{f.stopPropagation(),c.id==="quick-ask"?r():i(c.id.relPath)},children:h.jsx(Sr,{className:"w-3 h-3"})}),u?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Xy,{side:"bottom",align:"start",className:"max-w-sm break-all",children:c.title})]},d)})})}),h.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[e.quickAsk&&o?h.jsx("div",{className:"absolute inset-0",style:{display:e.active==="quick-ask"?"block":"none"},children:h.jsx($ie,{session:o,api:t,...a?{onPromoteQuickAsk:a}:{}})}):null,e.mds.map(c=>{const u=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===c;return h.jsx("div",{className:"absolute inset-0",style:{display:u?"block":"none"},children:h.jsx(kA,{relPath:c,loadMarkdown:s,showTitleBar:!1})},`md-body:${c}`)})]})]})}function Oie({state:e,extras:t}){const{api:n,session:r}=t,i=$i(),[s,o]=g.useState(Nie()),a=g.useRef(s);a.current=s;const l=g.useRef(!1),c=g.useCallback(async S=>{const C=a.current.quickAsk,N=await Cie(n,r,S);if(N){if(l.current){n.sessionDelete(N.sessionId).catch(()=>{});return}Ad(C)&&n.sessionDelete(C.sessionId).catch(()=>{}),o(T=>Tie(T,{sessionId:N.sessionId}))}},[n,r]),u=g.useCallback(async S=>{const C=a.current.quickAsk,N=(C==null?void 0:C.sessionId)===S;try{await Eie(n,{sessionId:S,stillEphemeral:N&&Ad(C)})&&o(B=>Rie(B))}catch(T){Be("quick-ask","promote failed",T)}},[n]),d=g.useCallback(S=>{o(C=>Pie(C,S))},[]),f=g.useCallback(S=>{o(C=>Aie(C,S))},[]),p=g.useCallback(()=>{const S=a.current.quickAsk;Ad(S)&&n.sessionDelete(S.sessionId).catch(()=>{}),o(C=>Iie(C))},[n]),m=g.useCallback(S=>{o(C=>Mie(C,S))},[]);g.useEffect(()=>()=>{l.current=!0;const S=a.current.quickAsk;Ad(S)&&n.sessionDelete(S.sessionId).catch(()=>{})},[]);const v=oi("sessions")??[],b=s.quickAsk?v.find(S=>S.sessionId===s.quickAsk.sessionId)??{sessionId:s.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,_=g.useCallback(async S=>{const C=await o1(n,i,r.sessionId,S,60),N=await fetch(C);if(!N.ok)throw new Error(`fetch ${N.status} ${N.statusText}`);return N.text()},[n,i,r.sessionId]),x=h.jsx(a1,{state:e,extras:t,onQuickAskInternal:c,onPreviewMdInternal:d}),{initialSize:y,setSize:w}=AM("chat-panel-right-slot-width",480);return h.jsxs(hp,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Fa,{id:"chat",minSize:"400px",children:x}),CA(s)?h.jsxs(h.Fragment,{children:[h.jsx(gy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fa,{id:"right-slot",defaultSize:`${y}px`,minSize:"360px",maxSize:"800px",onResize:S=>w(S.inPixels),children:h.jsx(Die,{state:s,api:n,onSwitchTab:f,onCloseQuickAsk:p,onCloseMd:m,loadMarkdown:_,quickAskSession:b,onPromoteQuickAsk:u})})]}):null]})}const Bie={implicitCloseOnUserText:!1},zie={implicitCloseOnUserText:!0};function $ie({session:e,api:t,onPromoteQuickAsk:n}){const r=T5(e.sessionId);return h.jsx(a1,{state:r,extras:{session:e,api:t,...n?{onPromoteQuickAsk:n}:{}}})}function Fie({extras:e}){const t=T5(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(a1,{state:t,extras:e});return h.jsx(Hie,{state:t,chat:n,extras:e})}return h.jsx(Oie,{state:t,extras:e})}function Hie({state:e,chat:t,extras:n}){var T;const r=oi("daemon-info"),i=$i(),s=n.api,o=n.session,a=o.appBuilderProject,[l,c]=g.useState(null),u=g.useCallback(()=>{s.appBuilderGetProject(o.sessionId).then(B=>c(B.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(B=>f(B.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const L=P;L!=null&&L.project&&(L.project.name===a&&c(L.project),f(R=>{const I=R.findIndex(z=>z.name===L.project.name);if(I<0)return[...R,L.project];const D=R.slice();return D[I]=L.project,D}))}),[i,a]);const{host:m,scheme:v}=bie(i.url,r==null?void 0:r.tunnelUrl),[b,_]=g.useState(void 0),[x,y]=g.useState(null);g.useEffect(()=>{const B=i.on("appBuilder:publish-progress",L=>{const R=L;!R||R.name!==a||R.status==="started"&&_(R.stage)}),P=i.on("appBuilder:publish-failed",L=>{const R=L;!R||R.name!==a||(_(void 0),y({stage:R.stage}))});return()=>{B(),P()}},[i,a]),g.useEffect(()=>{_(void 0),y(null)},[a]);const[w,S]=g.useState(null),C=h.jsx("button",{type:"button",className:"rounded bg-accent-main-100 px-2.5 py-1 text-[12px] text-oncolor-100 hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",disabled:((T=l==null?void 0:l.publishJob)==null?void 0:T.status)==="in-flight",onClick:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"发布请求失败",message:(B==null?void 0:B.message)??String(B)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(cie,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(_ie,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(B=>B.port),onUpdatePort:async B=>{await s.appBuilderUpdateProjectPort(a,B),p()},publishSlot:C,publishInFlightStage:b,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(B){S({title:"取消发布失败",message:(B==null?void 0:B.message)??String(B)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"重新发布失败",message:(B==null?void 0:B.message)??String(B)})}},publishFailureBanner:x,onPublishFailureBannerClose:()=>y(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(yie,{error:w,onClose:()=>S(null)})]})}function Uie({headerMeta:e,connState:t,liveWorktreeRoot:n,onOpenConfig:r,variant:i="full",ephemeral:s,onPromote:o,infoPanelOpen:a=!1,onToggleInfoPanel:l,infoPanel:c,infoPanelDefaultPx:u,onInfoPanelResize:d,lines:f,pendingPermissions:p,procAlive:m,rewindableUserMessageIds:v,onPermissionRespond:b,onPermissionInterrupt:_,onRewind:x,onFork:y,onQuickAsk:w,topSlot:S,realtimeQuestionAnswers:C,onSubmitQuestion:N,onCancelQuestion:T,liveQuestionToolUseIds:B,api:P,cwd:L,tool:R,sessionKey:I,onSend:D,awaitingUser:z,onAbort:$,onNewSession:F,onClearSession:j,configSlot:O,chatRootRef:E,chatBodyRef:H,topSentinelRef:V,drawers:A,xtermSlot:ne,fileSharingScope:se,onShareFile:G,onOpenInTab:ve,onPreviewMarkdown:Le}){return h.jsx(jZ,{children:h.jsxs(hp,{orientation:"horizontal",className:"flex h-full min-w-0 min-h-0",children:[h.jsx(Fa,{id:"chat",minSize:"360px",children:h.jsxs("div",{ref:E,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(RQ,{meta:e,...R?{tool:R}:{},connState:t,variant:i,...n!==void 0?{liveWorktreeRoot:n}:{},...i==="full"&&r?{onOpenConfig:r}:{},...i==="full"&&l?{infoPanelOpen:a,onToggleInfoPanel:l}:{},...i==="quickask"?{ephemeral:s??!1,...o?{onPromote:o}:{}}:{}}),h.jsxs("div",{ref:H,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[V?h.jsx("div",{ref:V,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx(PM,{lines:f,...b?{onPermissionRespond:b}:{},..._&&m?{onPermissionInterrupt:_}:{},topSlot:S,...x?{onRewind:x}:{},rewindableUserMessageIds:v,...y?{onFork:y}:{},...w?{onQuickAsk:w}:{},realtimeQuestionAnswers:C,onSubmitQuestion:N,...T?{onCancelQuestion:T}:{},liveQuestionToolUseIds:B,...se?{fileSharingScope:se}:{},...G?{onShareFile:G}:{},...ve?{onOpenInTab:ve}:{},...Le?{onPreviewMarkdown:Le}:{},...i==="full"?{turnCollapse:R==="codex"?zie:Bie}:{}})]}),ne,e.larkChatName?h.jsx("div",{className:"mx-3 mb-3 rounded-lg border border-border bg-bg-200 px-3 py-2 text-[12px] text-text-400","data-testid":"lark-readonly-notice",children:e.larkChatType==="p2p"?`此会话由与「${e.larkChatName}」的飞书私聊驱动——对方消息触发,这里仅供观察。`:`此会话由飞书群「${e.larkChatName}」驱动——群成员 @ bot 提问触发,这里仅供观察。`}):h.jsx(PQ,{meta:e,...P?{api:P}:{},cwd:L,...R?{tool:R}:{},sessionKey:I,onSend:D,awaitingUser:z,...$?{onAbort:$}:{},...F?{onNewSession:F}:{},...j?{onClearSession:j}:{},...O?{configSlot:O}:{}}),A]})}),a&&c?h.jsxs(h.Fragment,{children:[h.jsx(gy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fa,{id:"session-info",defaultSize:`${u??320}px`,minSize:"280px",maxSize:"480px",...d?{onResize:le=>d(le.inPixels)}:{},children:c})]}):null]})})}function a1({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,liveGitBranch:o,liveWorktreeRoot:a,onNewSession:l,onTurnEnd:c,onOpenConfig:u,onFork:d,onQuickAsk:f,viewerRole:p,onPromoteQuickAsk:m,configSlot:v}=t,{capabilities:b}=Ky(i.tool||"claude"),_=(b==null?void 0:b.features)??kT(i.tool),[x,y]=g.useState(null),[w,S]=g.useState(null),C=Yf(),N=!!s&&C.actionsLevel==="owner"&&_.fileSharing,T=PT(i.ownerPersonaId??null).persona,B=(T==null?void 0:T.label)??null,P=!!B&&!!i.ownerPersonaId,L=g.useCallback((K,de)=>{y({kind:K,text:de}),setTimeout(()=>{y(pe=>(pe==null?void 0:pe.text)===de?null:pe)},2e3)},[]),R=$i(),I=cB(),D=N5(i.sessionId,i.toolSessionId),{events:z,pendingQuestions:$,clearQuestion:F,markQuestionSubmitted:j,status:O}=D,E=e.historyLoading,H=DM(O);g.useEffect(()=>{Be("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:O,procAlive:H})},[O,H,i.sessionId]);const V=e.lines,A=e.pendingPermissions,ne=A[0]??null,se=g.useMemo(()=>EU(z),[z]),[G,ve]=g.useState(null),[Le,le]=g.useState(()=>new Set);SU(s,i.sessionId,i.toolSessionId,_.observe);const Ie=g.useRef(i.sessionId);g.useEffect(()=>{if(Ie.current=i.sessionId,!_.rewind){ve(null);return}let K=!1;return ve(null),(async()=>{try{const de=await s.sessionRewindableMessageIds(i.sessionId);if(K)return;ve(new Set(de.userMessageIds))}catch{K||ve(null)}})(),()=>{K=!0}},[s,i.sessionId,_.rewind]);const Re=g.useCallback(()=>{const K=i.sessionId;s.sessionRewindableMessageIds(K).then(de=>{Ie.current===K&&ve(new Set(de.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),qe=g.useMemo(()=>{if(G!==null){const Ze=new Set(G);for(const qi of Le)Ze.delete(qi);return Ze}const K=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),de=new Set;let pe=null;for(const Ze of V)Ze.kind==="user-text"?pe=Ze.uuid??null:pe&&Ze.kind==="tool-call"&&K.has(Ze.tool)&&!Le.has(pe)&&de.add(pe);return de},[V,Le,G]),_e=g.useRef(c);_e.current=c,kU(i.sessionId,i.toolSessionId,()=>{Xt(null),le(new Set)});const $e=XQ({sessionStatus:O}),fn=g.useRef(null);g.useEffect(()=>{var pe;const K=fn.current,de=(K==null?void 0:K.sid)===i.sessionId;de&&K.phase===$e||(fn.current={sid:i.sessionId,phase:$e},Be("session-phase",$e,{sid:i.sessionId,phase:$e,prev:de?K.phase:null,desc:GQ[$e]}),de&&K.phase==="turn-running"&&$e!=="turn-running"&&((pe=_e.current)==null||pe.call(_e),Re()))},[$e,i.sessionId,Re]);const it=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Mt,Xt]=g.useState(null),At=g.useCallback(K=>{Xt(K)},[]),[bt,Ye]=g.useState(!1),st=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),Ye(!1)},[s,i.sessionId]);g.useCallback(K=>{s.pinSession(i.sessionId,K).catch(de=>{Be("chat-panel","pinSession failed",{err:de==null?void 0:de.message})})},[s,i.sessionId]);const Tt=m?"quickask":"full",[Sn,sn]=g.useState(!1),{initialSize:U,setSize:J}=AM("clawd:panel:session-info-px",320),xe=g.useRef(0),Ce=g.useRef(null);g.useEffect(()=>{const K=de=>{if(de.key!=="Escape")return;if(!H){xe.current=0;return}if(de.isComposing)return;const Ze=de.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==Ce.current)return;const qi=Date.now();qi-xe.current<2e3?(xe.current=0,Ye(!0)):(xe.current=qi,it())};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[it,H]);const je=g.useRef(null),Lt=g.useRef(null),on=g.useRef(!0),wt=g.useRef(null),oe=g.useRef(0),q=g.useRef(0);g.useEffect(()=>{on.current=!0,wt.current=null,oe.current=0,q.current=0},[i.sessionId]),g.useEffect(()=>{S(null)},[i.sessionId]);const be=g.useRef(e);be.current=e;const ct=g.useCallback(()=>{var pe;const K=je.current;if(!K||wt.current!==null)return;const de=be.current;de.historyDone||de.historyLoading||(wt.current={distFromBottom:K.scrollHeight-K.scrollTop},(pe=de.loadMoreHistory)==null||pe.call(de))},[]);g.useEffect(()=>{const K=je.current,de=Lt.current;if(!K||!de)return;const pe=new IntersectionObserver(Ze=>{for(const qi of Ze)qi.isIntersecting&&ct()},{root:K,threshold:0});return pe.observe(de),()=>pe.disconnect()},[ct]),g.useEffect(()=>{const K=je.current;if(!K)return;const de=150,pe=Ze=>{Date.now()<q.current&&(Ze.preventDefault(),q.current=Date.now()+de)};return K.addEventListener("wheel",pe,{passive:!1}),()=>K.removeEventListener("wheel",pe)},[]),g.useEffect(()=>{const K=je.current;if(!K)return;const de=32,pe=()=>{const Ze=K.scrollHeight-K.scrollTop-K.clientHeight;on.current=Ze<=de};return K.addEventListener("scroll",pe,{passive:!0}),()=>K.removeEventListener("scroll",pe)},[]),g.useLayoutEffect(()=>{const K=je.current;if(!K)return;const de=oe.current,pe=V.length;oe.current=pe;const Ze=wt.current;if(Ze!==null&&pe>de){wt.current=null,K.scrollTop=K.scrollHeight-Ze.distFromBottom,q.current=Date.now()+200;return}Ze!==null&&(wt.current={distFromBottom:K.scrollHeight-K.scrollTop}),on.current&&(K.scrollTop=K.scrollHeight)},[V,ne==null?void 0:ne.requestId]);const an=g.useMemo(()=>{const K={};for(const[de,pe]of Object.entries($))pe.submittedAnswers&&(K[de]=pe.submittedAnswers);return K},[$]),gl=g.useMemo(()=>new Set(Object.keys($)),[$]),vl=g.useCallback(async(K,de)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:K,answers:de}),j(K,de)}catch{}},[s,i.sessionId,j]),_l=g.useCallback(async K=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:K}),F(K)}catch{}},[s,i.sessionId,F]),jp=g.useCallback(async(K,de)=>{var pe;if(ne)try{await((pe=e.respondPermission)==null?void 0:pe.call(e,ne.requestId,K?"allow":"deny"))}catch{}},[e,ne]),Dp=g.useCallback(async()=>{const K=i.sessionId;try{await s.sessionStop(K)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(K)},[e,s,i.sessionId]),Op=g.useMemo(()=>E&&V.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(In,{className:"w-4 h-4 text-text-400 animate-spin"})}):e.historyDone?null:h.jsx("div",{className:"flex justify-center py-2",children:h.jsx("button",{type:"button",onClick:()=>{var K;return void((K=e.loadMoreHistory)==null?void 0:K.call(e))},disabled:E,"data-testid":"history-load-more",className:"text-[12px] text-text-400 hover:text-text-200 cursor-pointer px-3 py-1 rounded-md border border-bg-300 hover:bg-bg-100 transition-colors disabled:opacity-60",children:E?"加载中…":"Load earlier messages"})}),[E,V.length,e.historyDone,e.loadMoreHistory]),xl=e.meta,Do=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(FQ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Mt&&_.rewind?h.jsx(UQ,{open:!0,onOpenChange:K=>{K||Xt(null)},api:s,sessionId:i.sessionId,userMessageId:Mt,lines:V,procAlive:H,onNoChanges:K=>{le(de=>{if(de.has(K))return de;const pe=new Set(de);return pe.add(K),pe})}}):null,bt?h.jsx(Wie,{onConfirm:st,onCancel:()=>Ye(!1)}):null]}),Bs={kind:"session",sessionId:i.sessionId},Oo=g.useCallback(async K=>{if(s)try{await iie(s,R,i.sessionId,K)}catch(de){const pe=de.message;Be("chat-panel","open-in-tab failed",{err:pe}),L("err",`Open in tab 失败:${pe}`)}},[s,R,i.sessionId,L]),[yl,fi]=g.useState(!1),[Br,Lu]=g.useState(null),ju=g.useCallback(K=>{if(r){r(K);return}Lu(K),fi(!0)},[r]),Ft=g.useCallback(async K=>{if(!s)throw new Error("daemon api not ready");const de=await o1(s,R,i.sessionId,K,60),pe=await fetch(de);if(!pe.ok)throw new Error(`fetch ${pe.status} ${pe.statusText}`);return await pe.text()},[s,R,i.sessionId]),Bo=g.useCallback(async(K,de)=>{if(s)try{const{url:pe}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:K,ttlSeconds:86400,...de?{view:de}:{}}),Ze=await sie(pe);L(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(pe){const Ze=pe.message;Be("chat-panel","share-file failed",{err:Ze}),L("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,L]),zo=g.useCallback(()=>S(null),[]),Pt=w==="files"&&N&&s?{title:"Edited Files",onBack:zo,content:h.jsx(One,{api:s,scope:Bs,sessionId:i.sessionId,onShareFile:Bo,onOpenInTab:Oo,onPreviewMarkdown:ju})}:w==="cron"?{title:`定时任务${se.length?` (${se.length})`:""}`,onBack:zo,content:h.jsx("div",{className:"p-3",children:h.jsx(KQ,{jobs:se})})}:w==="persona"&&P&&s&&i.ownerPersonaId?{title:`Persona · ${B??""}`,onBack:zo,content:h.jsx(tie,{personaId:i.ownerPersonaId,open:!0,onClose:zo,api:s,embedded:!0,...p?{viewerRole:p}:{}},i.ownerPersonaId)}:null;return h.jsxs(h.Fragment,{children:[h.jsx(Uie,{headerMeta:xl,connState:e.connState,...a!==void 0?{liveWorktreeRoot:a}:{},...u?{onOpenConfig:u}:{},variant:Tt,...Tt==="quickask"?{ephemeral:i.ephemeral!==!1,onPromote:()=>void(m==null?void 0:m(i.sessionId))}:{infoPanelOpen:Sn,onToggleInfoPanel:()=>sn(K=>!K),infoPanelDefaultPx:U,onInfoPanelResize:J,infoPanel:h.jsx(LQ,{session:i,meta:xl,...o!==void 0?{liveGitBranch:o}:{},...a!==void 0?{liveWorktreeRoot:a}:{},...P?{personaName:B}:{},...P?{onOpenPersona:()=>S("persona")}:{},...N?{onOpenFiles:()=>S("files")}:{},cronActiveCount:se.length,onCronClick:()=>S("cron"),onForceStop:()=>Ye(!0),...p?{viewerRole:p}:{},...b!=null&&b.toolSessionIdLabel?{toolSessionIdLabel:b.toolSessionIdLabel}:{},drill:Pt,onClose:()=>sn(!1)})},lines:V,pendingPermissions:A,procAlive:H,rewindableUserMessageIds:qe,onPermissionRespond:jp,onPermissionInterrupt:it,onRewind:_.rewind?At:void 0,...d&&_.fork?{onFork:d}:{},...n&&_.fork?{onQuickAsk:n}:f&&_.fork?{onQuickAsk:f}:{},topSlot:Op,realtimeQuestionAnswers:an,onSubmitQuestion:vl,onCancelQuestion:_l,liveQuestionToolUseIds:gl,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:A.length>0||Object.values($).some(K=>!K.submittedAnswers),onAbort:it,...l?{onNewSession:l}:{},onClearSession:Dp,...v?{configSlot:v}:{},chatRootRef:Ce,chatBodyRef:je,topSentinelRef:Lt,drawers:Do,xtermSlot:I==="tui"&&H&&_.tui?h.jsx(cne,{sessionId:i.sessionId,client:R},i.sessionId):null,fileSharingScope:Bs,...s?{onShareFile:Bo}:{},...s?{onOpenInTab:Oo}:{},...s?{onPreviewMarkdown:ju}:{}}),s?h.jsx(lie,{open:yl,onOpenChange:fi,relPath:Br,loadMarkdown:Ft,onShare:Br?()=>void Bo(Br,"md-rendered"):void 0}):null,x?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:x.kind==="ok"?"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-[12px] text-emerald-700 shadow-md dark:text-emerald-300":"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[12px] text-destructive shadow-md",children:x.text}):null]})}function Wie({onConfirm:e,onCancel:t}){return h.jsx("div",{role:"dialog","aria-modal":"true","data-testid":"force-stop-confirm",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:t,children:h.jsxs("div",{className:"max-w-sm w-[92%] rounded-lg border border-red-400/40 bg-bg-0 p-4 shadow-xl",onClick:n=>n.stopPropagation(),children:[h.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[h.jsx(qc,{className:"w-5 h-5 text-red-500 shrink-0 mt-0.5"}),h.jsx("div",{className:"text-[14px] text-text-100",children:"强制停止会话进程?会丢失 initialize / 预热缓存,下一次发送需要重新 spawn。"})]}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:t,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","data-testid":"force-stop-confirm-ok",onClick:e,className:"h-8 px-3 rounded-md bg-red-500 text-white text-[12px] font-medium hover:bg-red-600 cursor-pointer",children:"强制停止"})]})]})})}function Vie(e,t,n){const r=e?t.find(s=>s.id===e):void 0;if(r!=null&&r.efforts&&r.efforts.length>0)return{options:r.efforts,defaultValue:r.defaultEffort??""};const i=n.find(s=>s.name==="effort");return{options:(i==null?void 0:i.options)??[],defaultValue:typeof(i==null?void 0:i.default)=="string"?i.default:""}}function qie(e,t,n){var l;if(!t)return((l=(e??[]).find(c=>c.id===""))==null?void 0:l.label)??"未指定";const r=t.toLowerCase(),i=[["opus","Opus"],["fable","Fable"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[c,u]of i){if(!r.includes(c))continue;const d=r.match(new RegExp(`${c}-(\\d+)(?:-(\\d+))?`));return d?d[2]?`${u} ${d[1]}.${d[2]}`:`${u} ${d[1]}`:u}const s=e??[],o=s.find(c=>c.id===t);if(o)return o.label;const a=s.find(c=>c.id&&t.toLowerCase().includes(c.id.toLowerCase()));return a?a.label:t}function Kie(e,t){var m,v,b,_;const{models:n,modes:r,configSchema:i}=t,s=e.resolvedModel??e.model,o=Vie(s,n,i),a=o.options,l=a.some(x=>x.value===e.effort)?e.effort:o.defaultValue,c=e.effort===""&&e.resolvedEffort?((m=a.find(x=>x.value===e.resolvedEffort))==null?void 0:m.label)??e.resolvedEffort:((v=a.find(x=>x.value===l))==null?void 0:v.label)??null,u=((b=i.find(x=>x.name==="permissionMode"))==null?void 0:b.default)??"",d=r.some(x=>x.id===e.permissionMode)?e.permissionMode:u,p=d===u?null:((_=r.find(x=>x.id===d))==null?void 0:_.label)??null;return{modelLabel:qie(n,s),effortOptions:a,effortValue:l,effortLabel:c,modeValue:d,modeLabel:p,modeTone:p===null?null:d==="bypassPermissions"?"danger":"info"}}function Gie({models:e=[],modes:t=[],configSchema:n=[],model:r,resolvedModel:i,resolvedEffort:s,effort:o,permissionMode:a,onPatch:l}){var p;const c=Kie({model:r,resolvedModel:i,resolvedEffort:s,effort:o,permissionMode:a},{models:e,modes:t,configSchema:n}),u=i??r,d=e.map(m=>{const v=m.id===""&&i?`${m.description?`${m.description};`:""}当前:${i}`:m.description;return{value:m.id,label:m.label,...v?{description:v}:{}}}),f=t.map(m=>({value:m.id,label:m.label,...m.description?{description:m.description}:{}}));return h.jsxs(sy,{children:[h.jsx(oy,{asChild:!0,children:h.jsxs("button",{type:"button","data-testid":"session-config-chip",title:"Model / reasoning effort / permission mode",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:[h.jsx("span",{className:"truncate max-w-[120px]","data-testid":"session-config-chip-model",children:u||c.modelLabel}),c.effortLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"truncate max-w-[80px]","data-testid":"session-config-chip-effort",children:c.effortLabel})]}):null,c.modeLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{"data-testid":"session-config-chip-mode","data-tone":c.modeTone,className:ae("font-semibold",c.modeTone==="danger"?"text-red-400":"text-blue-400"),children:c.modeLabel})]}):null]})}),h.jsxs(dp,{side:"top",align:"end",className:"w-[230px]","data-testid":"session-config-menu",children:[h.jsx(wg,{testid:"session-config-model",label:"Model",current:r,currentLabel:c.modelLabel,options:d,onSelect:m=>l({model:m})}),h.jsx(wg,{testid:"session-config-effort",label:"Reasoning effort",current:c.effortValue,currentLabel:c.effortLabel??"—",options:c.effortOptions,onSelect:m=>l({effort:m})}),f.length>0?h.jsx(wg,{testid:"session-config-mode",label:"Permission mode",current:c.modeValue,currentLabel:((p=t.find(m=>m.id===c.modeValue))==null?void 0:p.label)??"—",currentTone:c.modeTone,options:f,onSelect:m=>l({permissionMode:m})}):null]})]})}function wg({testid:e,label:t,current:n,currentLabel:r,currentTone:i,options:s,onSelect:o}){const a=s.length===0;return h.jsxs(kH,{children:[h.jsxs(VI,{"data-testid":e,disabled:a,className:"gap-2 text-[12px]",children:[h.jsx("span",{className:"flex-1 text-text-200",children:t}),h.jsx("span",{className:ae("truncate max-w-[100px]",i==="danger"?"text-red-400 font-semibold":i==="info"?"text-blue-400 font-semibold":"text-text-400"),children:r}),h.jsx(Un,{className:"w-3.5 h-3.5 shrink-0 text-text-500"})]}),h.jsx(qI,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:s.map(l=>{const c=l.value===n;return h.jsxs(bi,{"data-testid":`${e}-option-${l.value||"default"}`,onSelect:()=>o(l.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsx("span",{className:ae("block text-[12px]",c?"text-text-100 font-medium":"text-text-300"),children:l.label}),l.description?h.jsx("span",{className:"block text-[11px] text-text-400 mt-0.5",children:l.description}):null]}),c?h.jsx(ll,{className:"w-3.5 h-3.5 shrink-0 text-accent mt-0.5"}):null]},l.value||"default")})})]})}function Xie(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitBranch(t);i(l.branch??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{branch:r,loading:s,refresh:()=>void a()}}function Yie(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitRoot(t);i(l.gitRoot??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{worktreeRoot:r,loading:s,refresh:()=>void a()}}function Zie({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onFork:l,onQuickAsk:c,className:u,viewerRole:d="owner"}){const{capabilities:f}=Ky(t.tool),[p,m]=g.useState(0),{branch:v}=Xie(e,t.cwd,p),{worktreeRoot:b}=Yie(e,t.cwd,p),_=r>1,x=y=>{e.sessionUpdate(t.sessionId,y).catch(w=>{console.error("[session-config] session:update failed",t.sessionId,w)})};return h.jsxs("div",{className:`group/pane relative flex-1 ${u??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${_?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsx(hp,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:h.jsx(Fa,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(Qie,{api:e,session:t,liveGitBranch:v,liveWorktreeRoot:b,onNewSession:o,onTurnEnd:()=>m(y=>y+1),onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:d,configSlot:f?h.jsx(Gie,{models:f.models,modes:f.permissionModes,configSchema:f.configSchema,model:t.model??"",...t.resolvedModel?{resolvedModel:t.resolvedModel}:{},...t.resolvedEffort?{resolvedEffort:t.resolvedEffort}:{},effort:t.effort??"",permissionMode:t.permissionMode??"",onPatch:x}):null})})})}),_&&h.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),s()},className:"absolute top-1.5 right-1.5 z-10 p-1 rounded-md bg-bg-100/80 backdrop-blur-sm border border-border opacity-0 group-hover/pane:opacity-100 transition-opacity text-text-400 hover:text-text-100 hover:bg-bg-200","aria-label":"close pane","data-testid":`session-pane-close-${t.sessionId}`,children:h.jsx(Sr,{className:"w-3.5 h-3.5"})})]})}function Qie({api:e,session:t,liveGitBranch:n,liveWorktreeRoot:r,onNewSession:i,onTurnEnd:s,onOpenConfig:o,onFork:a,onQuickAsk:l,viewerRole:c,configSlot:u}){return h.jsx(Fie,{extras:{session:t,api:e,...n!==void 0?{liveGitBranch:n}:{},...r!==void 0?{liveWorktreeRoot:r}:{},onNewSession:i,onTurnEnd:s,onOpenConfig:o,...a?{onFork:d=>{a(d)}}:{},...l?{onQuickAsk:d=>{l(d)}}:{},...c?{viewerRole:c}:{},...u?{configSlot:u}:{}}})}function Jie({personas:e,sessions:t,api:n,selfPrincipalId:r,selectedPersonaId:i,selectedSessionId:s,selectedSession:o,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,onCloseSession:f}){return h.jsxs("div",{className:"flex h-screen min-h-0 bg-bg-50","data-testid":"guest-share-page",children:[h.jsx("aside",{className:"w-[280px] shrink-0 overflow-y-auto border-r border-border bg-bg-50",children:h.jsx(FH,{personas:e,sessions:t,activePersonaId:i,activeSessionId:s,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,showCopyResume:!1,treatSessionsAsRoots:!0,...r?{ownerPrincipalId:r}:{},isPersonaExpanded:()=>!0})}),h.jsx("main",{className:"flex-1 min-w-0 min-h-0 flex",children:o?h.jsx(Zie,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},viewerRole:"guest"}):h.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-xs text-text-400","data-testid":"guest-share-empty",children:"选择左侧 persona 开始对话"})})]})}function ese(){const e=$i(),t=g.useMemo(()=>new Rx(e),[e]),n=IB(e),{sessions:r,refresh:i}=RB(n),{personas:s}=TT(),o=OB(),a=g.useMemo(()=>{const w=window.location.pathname.match(/^\/s\/([^/]+)/);return w?decodeURIComponent(w[1]):null},[]),l=g.useMemo(()=>r.filter(w=>!w.ephemeral&&w.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(w=>w.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let w=!1;return e.request("whoami",{}).then(S=>{w||d(S.capability.id)}).catch(()=>{}),()=>{w=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const b=g.useCallback(async(w,S)=>{const C=await t.sessionCreate({ownerPersonaId:w,...S.trim()?{label:S.trim()}:{}});await i(),p(w),v(C.sessionId)},[t,i]),_=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(S=>S===w?null:S)},[t,i]),x=g.useCallback(async(w,S)=>{await t.sessionUpdate(w,{label:S.label}),await i()},[t,i]),y=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(Mx.Provider,{value:o,children:h.jsx(Jie,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:y,onSelectPersona:p,onSelectSession:v,onCreateSession:(w,S)=>void b(w,S),onDeleteSession:w=>void _(w),onEditSession:(w,S)=>void x(w,S),onCloseSession:()=>v(null)})})}const OC="https://app.ttcadvisory.com";function tse({onAuthed:e}){const[t,n]=g.useState(!1),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&window.removeEventListener("message",s.current)},[]);const o=g.useCallback(()=>{s.current&&(window.removeEventListener("message",s.current),s.current=null),n(!0),i(null);const a=window.location.origin,l=`${OC}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==OC)return;const f=d.data;if((f==null?void 0:f.type)==="AUTH_CANCEL"){u(),n(!1);return}if(!((f==null?void 0:f.type)!=="AUTH_SUCCESS"||!f.token)){u();try{const p=await fetch(`${window.location.origin}/share/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ttcToken:f.token})});if(!p.ok){const v=await p.json().catch(()=>({}));throw new Error(v.code??`exchange failed (${p.status})`)}const m=await p.json();if(!m.visitorToken)throw new Error("no visitorToken in response");e(m.visitorToken)}catch(p){i(p instanceof Error?p.message:String(p)),n(!1)}}},u=()=>{window.removeEventListener("message",c),s.current=null};s.current=d=>void c(d),window.addEventListener("message",s.current),window.open(l,"ttc-login","width=480,height=640")},[e]);return h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 font-sans text-text-100","data-testid":"guest-login",children:h.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-3 rounded-lg border border-border bg-bg-100 px-5 py-6",children:[h.jsx("h1",{className:"text-base font-semibold",children:"登录后进入分享"}),h.jsx("p",{className:"text-[11px] leading-snug text-text-400",children:"使用飞书账号登录,即可在浏览器里与分享给你的 persona 交互,无需安装。"}),r?h.jsxs("p",{className:"text-[11px] leading-snug text-error","data-testid":"guest-login-error",children:["登录失败:",r]}):null,h.jsx("button",{type:"button",disabled:t,onClick:()=>o(),"data-testid":"guest-login-button",className:"w-full rounded border border-border bg-bg-50 px-2 py-1.5 text-xs text-text-200 transition-colors hover:bg-text-100/5 hover:text-text-100 disabled:opacity-50",children:t?"请在弹窗中完成授权…":"飞书登录"})]})})}const y_="clawd-visitor:token";function nse(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function rse(){return{async getUrl(e){const t=localStorage.getItem(y_);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=nse(window.location,{});return await xT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function ise(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function sse(){const e=$i(),t=g.useMemo(()=>PB(e),[e]);return h.jsx(uB,{cache:t.cache,children:h.jsx(fB,{children:h.jsx(ese,{})})})}function ose({host:e}){const[t]=g.useState(()=>localStorage.getItem(y_)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>ise(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return rse().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(kb,{host:e,children:h.jsx(rw,{children:i?h.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-center text-xs text-error","data-testid":"guest-share-connect-error",children:["连接失败:",i]}):n?h.jsx(lB,{host:e,children:h.jsx(sse,{})}):h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-xs text-text-400",children:"正在连接…"})})}):h.jsx(kb,{host:e,children:h.jsx(rw,{children:h.jsx(tse,{onAuthed:o=>{localStorage.setItem(y_,o),window.location.reload()}})})})}function ase({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):lse(t??"",n??""),[t,n,r]);return h.jsxs("div",{"data-testid":"inline-diff",className:"min-w-0 max-w-full rounded-lg border border-bg-300/60 bg-bg-50 overflow-hidden text-[12px] font-mono",children:[h.jsx("div",{className:"flex min-w-0 items-center gap-2 px-3 py-1.5 border-b border-bg-300/40 bg-bg-100/30",children:h.jsx("span",{className:"min-w-0 text-text-400 truncate",title:e,children:e})}),h.jsx("div",{className:"max-h-[320px] max-w-full overflow-auto",children:i.map((s,o)=>h.jsxs("div",{"data-testid":`diff-line-${s.type}`,className:ae("flex min-w-max gap-2 px-3 py-0.5 whitespace-pre",s.type==="add"?"bg-success/10 text-success":s.type==="remove"?"bg-error/10 text-error":"text-text-300"),children:[h.jsx("span",{className:"w-3 shrink-0 select-none opacity-60",children:s.type==="add"?"+":s.type==="remove"?"-":" "}),h.jsx("span",{className:"flex-1",children:s.text||" "})]},o))})]})}function lse(e,t){const n=e.split(/\r?\n/),r=t.split(/\r?\n/),i=n.length,s=r.length,o=Array.from({length:i+1},()=>new Array(s+1).fill(0));for(let u=i-1;u>=0;u--)for(let d=s-1;d>=0;d--)o[u][d]=n[u]===r[d]?o[u+1][d+1]+1:Math.max(o[u+1][d],o[u][d+1]);const a=[];let l=0,c=0;for(;l<i&&c<s;)n[l]===r[c]?(a.push({type:"equal",text:n[l]}),l++,c++):o[l+1][c]>=o[l][c+1]?(a.push({type:"remove",text:n[l]}),l++):(a.push({type:"add",text:r[c]}),c++);for(;l<i;)a.push({type:"remove",text:n[l++]});for(;c<s;)a.push({type:"add",text:r[c++]});return a}function cse({items:e}){return e.length===0?null:h.jsxs("div",{"data-testid":"todo-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1.5",children:"Todos"}),h.jsx("ul",{className:"flex flex-col gap-1",children:e.map((t,n)=>{const r=t.status==="in_progress"&&t.activeForm||t.content;return h.jsxs("li",{"data-testid":`todo-item-${t.status}`,className:"flex items-start gap-2",children:[h.jsx(use,{status:t.status}),h.jsx("span",{className:ae("flex-1 leading-snug",t.status==="completed"?"text-text-400 line-through":t.status==="in_progress"?"text-text-100 font-medium":"text-text-200"),children:r})]},n)})})]})}function use({status:e}){return e==="completed"?h.jsx(Qf,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(In,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(MT,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function dse(e){const t=e??{};return Array.isArray(t.todos)?t.todos.map(n=>{if(!n||typeof n!="object")return null;const r=n,i=typeof r.content=="string"?r.content:"",s=r.status==="pending"||r.status==="in_progress"||r.status==="completed"?r.status:"pending",o=typeof r.activeForm=="string"?r.activeForm:void 0;return{content:i,status:s,activeForm:o}}).filter(n=>n!==null):[]}function hse({description:e,prompt:t,subagentType:n}){return h.jsxs("div",{"data-testid":"task-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsxs("div",{className:"flex items-center gap-2 text-text-200 font-medium",children:[h.jsx(Zf,{className:"w-3.5 h-3.5 text-accent shrink-0"}),h.jsx("span",{className:"truncate",children:e||"subagent task"}),n?h.jsx("span",{className:"shrink-0 px-1.5 py-0.5 rounded-md text-[10px] font-mono bg-accent/10 text-accent",children:n}):null]}),t?h.jsx("div",{className:"mt-1 text-[12px] text-text-400 leading-snug line-clamp-3",children:t}):null]})}function fse(e){const t=e??{};return{description:typeof t.description=="string"?t.description:"",prompt:typeof t.prompt=="string"?t.prompt:void 0,subagentType:typeof t.subagent_type=="string"?t.subagent_type:void 0}}const pse={render:({input:e})=>Je.createElement(cse,{items:dse(e)})},mse={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=fse(e);return Je.createElement(hse,{description:t,prompt:n,subagentType:r})}},EA={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=vse(e),c=l?Je.createElement(ase,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return Je.createElement(SM,{tool:gse(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function gse(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function vse(e){const t=e??{},n=typeof t.file_path=="string"?t.file_path:null;if(!n)return null;const r=typeof t.old_string=="string"?t.old_string:void 0,i=typeof t.new_string=="string"?t.new_string:void 0,s=typeof t.content=="string"?t.content:void 0;return r==null&&i==null&&s==null?null:{filePath:n,oldString:r,newString:i,content:s}}fl.register("claude","TodoWrite",pse);fl.register("claude","Task",mse);fl.register("claude","Edit",EA);fl.register("claude","Write",EA);const NA=document.getElementById("root");if(!NA)throw new Error("guest-main: #root not found");const _se=aL({});Sg.createRoot(NA).render(h.jsx(Je.StrictMode,{children:h.jsx(ose,{host:_se})}));
|
|
554
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return g.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Ore="DialogDescriptionWarning",Bre=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${vA(Ore).contentName}}.`;return g.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},zre=iA,$re=aA,_A=lA,xA=cA,yA=dA,bA=fA,Fre=mA;const i1=zre,Hre=$re,wA=g.forwardRef(({className:e,...t},n)=>h.jsx(_A,{ref:n,className:ae("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));wA.displayName=_A.displayName;const Mp=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(Hre,{children:[h.jsx(wA,{}),h.jsxs(xA,{ref:r,className:ae("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2","gap-4 rounded-lg border border-border bg-elevated p-6 shadow-lg",e),...n,children:[t,h.jsxs(Fre,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-accent",children:[h.jsx(Sr,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mp.displayName=xA.displayName;const Ap=({className:e,...t})=>h.jsx("div",{className:ae("flex flex-col space-y-1.5 text-left",e),...t});Ap.displayName="DialogHeader";const s1=({className:e,...t})=>h.jsx("div",{className:ae("flex flex-row justify-end gap-2",e),...t});s1.displayName="DialogFooter";const Lp=g.forwardRef(({className:e,...t},n)=>h.jsx(yA,{ref:n,className:ae("text-lg font-semibold leading-none text-text-100",e),...t}));Lp.displayName=yA.displayName;const SA=g.forwardRef(({className:e,...t},n)=>h.jsx(bA,{ref:n,className:ae("text-sm text-text-300",e),...t}));SA.displayName=bA.displayName;function Ure({persona:e,open:t,onClose:n,onDelete:r,embedded:i,onLoadPersonality:s,onSavePersonality:o,onDirtyChange:a,initialPersonality:l,onShareCapability:c,readOnly:u=!1,larkBot:d}){const[f,p]=g.useState(!1),m=b=>{p(b),a==null||a(b)},v=()=>{f&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!i&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:v,"aria-hidden":"true"}),h.jsxs("aside",{className:i?"flex h-full w-full flex-col bg-bg-0":"absolute right-0 top-0 z-40 flex h-full w-[420px] flex-col bg-bg-0 border-l border-border shadow-xl","data-testid":"persona-settings-drawer",children:[h.jsxs("header",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[h.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[h.jsx(c$,{className:"h-4 w-4 text-text-300"}),h.jsx("span",{className:"text-[13px] font-medium text-text-100 truncate",children:"Persona 设置"})]}),h.jsx("button",{type:"button",onClick:v,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(Sr,{className:"h-4 w-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto p-6 flex flex-col gap-4",children:[h.jsxs("header",{className:"flex items-start justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("h2",{className:"text-lg font-semibold text-text-100 truncate",children:e.label}),e.public?h.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-bg-200 px-1.5 py-0.5 text-[10px] text-text-200",children:[h.jsx(Rz,{className:"h-3 w-3"})," 公开"]}):h.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-error-dim px-1.5 py-0.5 text-[10px] text-error",children:[h.jsx(Pz,{className:"h-3 w-3"})," 已关闭"]})]}),h.jsx("span",{className:"font-mono text-[11px] text-text-400 truncate","data-testid":"persona-id-subtitle",children:e.personaId})]}),h.jsxs("div",{className:"flex items-center gap-1",children:[c?h.jsxs("button",{type:"button",onClick:c,"aria-label":"分享给他人",title:"分享给他人",className:"inline-flex items-center gap-1 rounded-sm px-2 py-1.5 text-xs text-text-200 hover:bg-bg-200 hover:text-text-100",children:[h.jsx(Lx,{className:"h-3.5 w-3.5"}),"分享"]}):null,r?h.jsx("button",{type:"button",onClick:r,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(jx,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),d?h.jsxs(h.Fragment,{children:[h.jsx(Kre,{...d}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs(h.Fragment,{children:[h.jsx(Zre,{onLoad:s,...o?{onSave:o}:{},onDirtyChange:m,initialPersonality:l,readOnly:u}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(Gre,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(Xre,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(Yre,{plugins:e.plugins??[]})]})]})]}):null}function Wre({qrUrl:e,busy:t,onCancel:n}){const[r,i]=g.useState(null);return g.useEffect(()=>{let s=!1;return Mu.toDataURL(e,{width:240,margin:1}).then(o=>{s||i(o)}).catch(()=>{s||i(null)}),()=>{s=!0}},[e]),h.jsx(i1,{open:!0,onOpenChange:s=>s||n==null?void 0:n(),children:h.jsxs(Mp,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",onInteractOutside:s=>s.preventDefault(),onEscapeKeyDown:s=>s.preventDefault(),children:[h.jsx(Ap,{children:h.jsx(Lp,{children:"扫码关联飞书 Bot"})}),h.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r?h.jsx("img",{src:r,alt:"飞书扫码创建应用二维码",className:"h-60 w-60 rounded bg-white p-2","data-testid":"lark-bot-qr-img"}):h.jsx("div",{className:"flex h-60 w-60 items-center justify-center text-[12px] text-text-400",children:"二维码生成中…"}),h.jsx("span",{className:"text-center text-[12px] text-text-300",children:"用手机飞书扫码,按页面提示创建应用。确认后自动完成关联。"}),n?h.jsx("button",{type:"button",disabled:t,onClick:n,className:"rounded border border-border px-3 py-1.5 text-[12px] text-text-300 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-provision-cancel",children:"取消"}):null]})]})})}const Vre={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},qre=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function Kre({status:e,onProvision:t,onCancelProvision:n,onBindManual:r,onUnbind:i}){const[s,o]=g.useState(!1),[a,l]=g.useState(null),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,m]=g.useState(null),v=x=>{x&&(o(!0),l(null),x().catch(y=>l(y instanceof Error?y.message:String(y))).finally(()=>o(!1)))},b=()=>{m(null),v(t)},_=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(Zf,{className:"h-3.5 w-3.5 text-text-400","aria-hidden":!0}),h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"飞书 Bot"})]});return e?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,e.state==="unbound"||e.state==="provisioning"?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"关联一个飞书 bot 后,这个 persona 就是它:拉进群后群成员 @ 它提问、或直接私聊它, 推理跑在你本机,回复自动发回去。"}),t?h.jsx("button",{type:"button",disabled:s||e.state==="provisioning",onClick:b,className:"self-start rounded border border-border bg-bg-200 px-3 py-1.5 text-[12px] font-medium text-text-100 hover:bg-bg-300 disabled:opacity-50","data-testid":"lark-bot-provision",children:e.state==="provisioning"?"等待扫码…":"扫码关联飞书 Bot"}):null,e.state==="unbound"&&e.errorReason&&!p?h.jsxs("div",{className:"flex flex-col gap-1.5 rounded border border-error bg-error-dim px-2 py-1.5","data-testid":"lark-bot-provision-error",children:[h.jsx("span",{className:"text-[11px] text-error",children:Vre[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[qre.has(e.errorReason)&&t?h.jsx("button",{type:"button",disabled:s,onClick:b,className:"rounded border border-border px-2 py-1 text-[11px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-provision-retry",children:"重新扫码"}):null,h.jsx("button",{type:"button",onClick:()=>m(e.errorReason??null),className:"rounded border border-border px-2 py-1 text-[11px] text-text-300 hover:bg-bg-200","data-testid":"lark-bot-provision-error-dismiss",children:"知道了"})]})]}):null,e.state==="provisioning"&&e.qrUrl?h.jsx(Wre,{qrUrl:e.qrUrl,busy:s,onCancel:n?()=>v(n):void 0}):null,r&&e.state==="unbound"?h.jsxs("details",{"data-testid":"lark-bot-manual-details",children:[h.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400 hover:text-text-300",children:"已有飞书应用?手动填入凭证"}),h.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),h.jsx("input",{value:c,onChange:x=>u(x.target.value),placeholder:"App ID(cli_ 开头)",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-appid"}),h.jsx("input",{value:d,onChange:x=>f(x.target.value),type:"password",placeholder:"App Secret",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-secret"}),h.jsx("button",{type:"button",disabled:s||!c||!d,onClick:()=>v(()=>r({appId:c,appSecret:d})),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-manual-submit",children:s?"绑定中…":"绑定"})]})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.state==="broken"?h.jsxs("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-broken",children:["Bot 凭证失效:",e.brokenReason??"未知原因","。请解绑后重新填入有效凭证绑定。"]}):null,h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-200",children:[h.jsx("span",{className:"font-medium text-text-100",children:e.botName??"未命名 bot"}),e.appId?h.jsx("span",{className:"text-[11px] text-text-400",children:e.appId}):null]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"把 bot 拉进任意飞书群,群成员 @ 它即可提问。"}),e.groups.length>0?h.jsx("ul",{className:"flex flex-col gap-0.5","data-testid":"lark-bot-groups",children:e.groups.map(x=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",x.chatName??x.chatId]},x.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),i?h.jsx("button",{type:"button",disabled:s,onClick:()=>v(i),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-error hover:bg-error-dim disabled:opacity-50","data-testid":"lark-bot-unbind",children:"解绑"}):null]}):null,a?h.jsx("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-error",children:a}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function Gre({settings:e}){var t,n,r,i,s,o,a,l,c,u,d,f,p;return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-sandbox-setting-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Sandbox Setting"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"约束此 persona 的沙箱权限(只读,需通过文件修改)。"})]}),e==null?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-sandbox-setting-empty",children:"暂无 sandbox 配置"}):h.jsxs("div",{className:"flex flex-col gap-1.5 rounded-md border border-border bg-bg-100 px-3 py-2",children:[h.jsx(Md,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(Md,{label:"沙箱启用",value:bg((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(Md,{label:"沙箱内自动放行 Bash",value:bg((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(Md,{label:"允许非沙箱命令",value:bg((i=e.sandbox)==null?void 0:i.allowUnsandboxedCommands)}),h.jsxs("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border pt-1.5",children:[h.jsx(Fl,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(Fl,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(Fl,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(Fl,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(Fl,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function bg(e){return e===!0?"是":e===!1?"否":"—"}function Md({label:e,value:t}){return h.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px]",children:[h.jsx("span",{className:"text-text-300",children:e}),h.jsx("span",{className:"font-mono text-text-100",children:t})]})}function Fl({label:e,paths:t}){const n=!t||t.length===0;return h.jsxs("div",{className:"flex flex-col gap-1",children:[h.jsx("span",{className:"text-[11px] text-text-300",children:e}),n?h.jsx("span",{className:"text-[11px] text-text-400",children:"—"}):h.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((r,i)=>h.jsx("span",{className:"rounded-sm border border-border bg-bg-0 px-1.5 py-0.5 font-mono text-[11px] text-text-200",children:r},`${e}-${i}-${r}`))})]})}function Xre({skills:e}){return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-skills-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Persona Skills"}),h.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[10px] text-text-300",children:e.length})]}),h.jsxs("span",{className:"text-[11px] text-text-400",children:["此 persona 私有 skills(来自"," ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/.claude/skills/"}),")。"]})]}),e.length===0?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-skills-empty",children:"暂无 skills"}):h.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border bg-bg-100",children:e.map(t=>h.jsxs("li",{className:"flex flex-col gap-0.5 px-3 py-2","data-testid":"persona-skill-row",children:[h.jsx("span",{className:"font-mono text-[13px] text-text-100",children:t.name}),t.description?h.jsx("span",{className:"text-[12px] text-text-300",children:t.description}):h.jsx("span",{className:"text-[11px] text-text-400 italic",children:"无描述"})]},t.name))})]})}function Yre({plugins:e}){return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-plugins-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Enabled Plugins"}),h.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[10px] text-text-300",children:e.length})]}),h.jsxs("span",{className:"text-[11px] text-text-400",children:["此 persona 已启用的插件(来自"," ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/.claude/settings.json"})," ","的 ",h.jsx("code",{className:"font-mono",children:"enabledPlugins"}),")。"]})]}),e.length===0?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-plugins-empty",children:"暂无启用插件"}):h.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border bg-bg-100",children:e.map(t=>h.jsx("li",{className:"flex flex-col gap-0.5 px-3 py-2","data-testid":"persona-plugin-row",children:h.jsx("span",{className:"font-mono text-[13px] text-text-100",children:t.id})},t.id))})]})}function Zre({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1}){const s=r!==void 0,[o,a]=g.useState(s),[l,c]=g.useState(s?r:""),[u,d]=g.useState(s?r:""),[f,p]=g.useState(null),[m,v]=g.useState(!1),[b,_]=g.useState(null),x=Je.useRef(e),y=Je.useRef(t),w=Je.useRef(n);Je.useEffect(()=>{x.current=e,y.current=t,w.current=n});const S=Je.useCallback(()=>{a(!1),p(null),x.current().then(B=>{c(B),d(B),a(!0)}).catch(B=>{p(B instanceof Error?B.message:String(B))})},[]);Je.useEffect(()=>{s||S()},[s,S]);const C=!i&&o&&u!==l;Je.useEffect(()=>{i||w.current(C)},[C,i]);const N=()=>{y.current&&(v(!0),_(null),y.current(u).then(()=>{c(u),v(!1)}).catch(B=>{_(B instanceof Error?B.message:String(B)),v(!1)}))},T=()=>{d(l),_(null)};return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-personality-section",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"人格 (Personality)"}),f?h.jsxs("div",{"data-testid":"persona-personality-load-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error flex items-center justify-between gap-2",children:[h.jsxs("span",{children:["加载失败:",f]}),h.jsx("button",{type:"button",onClick:S,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,b?h.jsxs("div",{"data-testid":"persona-personality-save-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",b]}):null,h.jsx("textarea",{"data-testid":"persona-personality-textarea",value:u,onChange:B=>d(B.target.value),readOnly:i,disabled:!i&&(!o||m),placeholder:o?"":"加载中…",rows:8,className:"min-h-[8rem] max-h-[18rem] resize-y rounded-md border border-border bg-bg-100 px-2 py-1.5 font-mono text-[11px] text-text-100 disabled:opacity-60"}),!i&&h.jsxs("p",{className:"text-[10px] text-text-400",children:["写入到 ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/CLAUDE.md"}),"。 修改只对新启动的 sub-session 生效。"]}),o&&C?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:T,disabled:m,className:"rounded-sm border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200 disabled:opacity-60",children:"放弃"}),h.jsx("button",{type:"button",onClick:N,disabled:m,"data-testid":"persona-personality-save-btn",className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:m?"保存中…":"保存"})]}):null]})}const Qre={state:"unbound",groups:[]};function Jre(e,t){const[n,r]=g.useState(null);g.useEffect(()=>{if(!e)return;let l=!1;r(null);const c=async()=>{try{const f=await e.request("larkBot:status",{personaId:t});l||r(f)}catch{l||r(Qre)}};c();const u=e.on("larkBot:state",f=>{const p=f;if(p.personaId!==t)return;const{personaId:m,...v}=p;r(v)}),d=e.on("daemon:connected",()=>{c()});return()=>{l=!0,u(),d()}},[e,t]);const i=g.useCallback(async()=>{e&&await e.request("larkBot:provision",{personaId:t})},[e,t]),s=g.useCallback(async()=>{e&&await e.request("larkBot:provisionCancel",{personaId:t})},[e,t]),o=g.useCallback(async l=>{e&&await e.request("larkBot:bindManual",{personaId:t,...l})},[e,t]),a=g.useCallback(async()=>{e&&await e.request("larkBot:unbind",{personaId:t})},[e,t]);return{status:n,provision:i,cancelProvision:s,bindManual:o,unbind:a}}function eie(e,t="owner"){const{persona:n}=PT(e),r=MB(e),i=AB(),s=LB(),{httpBaseUrl:o}=Yf(),a=$i(),l=Jre(t==="guest"?null:a,e),{capabilities:c}=Ky((n==null?void 0:n.tool)??"claude"),u=g.useMemo(()=>!(n!=null&&n.public)||!o||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(o)?null:`${o}/s/${e}`,[n==null?void 0:n.public,o,e]),d=g.useCallback((y,w)=>{i(e,w).catch(S=>{Be("persona",`${y} failed`,S)})},[i,e]),f=g.useCallback(y=>d("togglePublic",{public:y}),[d]),p=g.useCallback(y=>d("changeTool",{tool:y}),[d]),m=g.useCallback(y=>d("changeModel",{model:y}),[d]),v=g.useCallback(y=>d("changeEffort",{effort:y}),[d]),b=g.useCallback(()=>!n||!confirm(`删除 persona "${n.label}"?`)?!1:(s(e).catch(y=>{Be("persona","delete failed",y)}),!0),[n,s,e]),_=g.useCallback(async()=>r.loaded?r.personality:(await r.refresh()).personality,[r]),x=g.useCallback(async y=>{await i(e,{personality:y}),await r.refresh()},[i,e,r]);return{persona:n,detail:r,models:(c==null?void 0:c.models)??[],configSchema:(c==null?void 0:c.configSchema)??[],larkBot:l,guestShareUrl:u,changeTool:p,changeModel:m,changeEffort:v,togglePublic:f,remove:b,loadPersonality:_,savePersonality:x}}function tie({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const l=eie(e,a),{persona:c,detail:u}=l,d=g.useCallback(()=>{l.remove()&&n()},[l,n]);if(!c)return null;const f=a==="guest";return h.jsx(Ure,{embedded:i,persona:{...c,skills:u.skills,plugins:u.plugins,sandboxSettings:u.sandboxSettings},open:t,onClose:n,onLoadPersonality:l.loadPersonality,onDirtyChange:s,readOnly:f,...f?{}:{onTogglePublic:l.togglePublic,guestShareUrl:l.guestShareUrl,onChangeTool:l.changeTool,onChangeModel:l.changeModel,onChangeEffort:l.changeEffort,models:l.models,configSchema:l.configSchema,onDelete:d,onSavePersonality:l.savePersonality,larkBot:{status:l.larkBot.status,onProvision:l.larkBot.provision,onCancelProvision:l.larkBot.cancelProvision,onBindManual:l.larkBot.bindManual,onUnbind:l.larkBot.unbind},...o?{onShareCapability:o}:{}}})}function nie(e){try{const t=new URL(e);return t.protocol==="ws:"?t.protocol="http:":t.protocol==="wss:"&&(t.protocol="https:"),`${t.protocol}//${t.host}`}catch{return e}}function rie(e,t){try{const n=new URL(e),r=new URL(t);return n.protocol=r.protocol,n.host=r.host,n.toString()}catch{return e}}async function o1(e,t,n,r,i){const s=await e.attachmentSignUrl({sessionId:n,relPath:r,...i!==void 0?{ttlSeconds:i}:{}});return rie(s.url,nie(t.url))}async function iie(e,t,n,r,i=60){const s=window.open("about:blank","_blank");try{const o=await o1(e,t,n,r,i);s?s.location.href=o:window.open(o,"_blank")}catch(o){throw s&&s.close(),o}}async function sie(e){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{const n=document.createElement("textarea");n.value=e,n.style.position="fixed",n.style.left="-9999px",n.style.top="0",n.setAttribute("readonly",""),document.body.appendChild(n),n.select();const r=document.execCommand("copy");return document.body.removeChild(n),r}catch{return!1}}const oie={...nu,h1:({node:e,...t})=>h.jsx("h1",{...t,className:"mt-4 mb-3 text-[18px] font-semibold leading-tight text-text-100"}),h2:({node:e,...t})=>h.jsx("h2",{...t,className:"mt-4 mb-2 text-[16px] font-semibold leading-tight text-text-100"}),h3:({node:e,...t})=>h.jsx("h3",{...t,className:"mt-3 mb-2 text-[14px] font-semibold leading-tight text-text-100"}),h4:({node:e,...t})=>h.jsx("h4",{...t,className:"mt-3 mb-1 text-[13px] font-semibold text-text-100"}),h5:({node:e,...t})=>h.jsx("h5",{...t,className:"mt-2 mb-1 text-[12px] font-semibold text-text-100"}),h6:({node:e,...t})=>h.jsx("h6",{...t,className:"mt-2 mb-1 text-[12px] font-semibold text-text-300"}),p:({node:e,...t})=>h.jsx("p",{...t,className:"my-2 leading-relaxed"}),ul:({node:e,...t})=>h.jsx("ul",{...t,className:"my-2 list-disc space-y-1 pl-5"}),ol:({node:e,...t})=>h.jsx("ol",{...t,className:"my-2 list-decimal space-y-1 pl-5"}),li:({node:e,...t})=>h.jsx("li",{...t,className:"leading-relaxed"}),blockquote:({node:e,...t})=>h.jsx("blockquote",{...t,className:"my-2 border-l-2 border-border pl-3 italic text-text-300"}),code:({node:e,className:t,children:n,...r})=>t?h.jsx("code",{...r,className:`${t} font-mono text-[12px]`,children:n}):h.jsx("code",{...r,className:"rounded bg-bg-50 px-1 py-0.5 font-mono text-[12px] text-text-100",children:n}),pre:({node:e,...t})=>h.jsx("pre",{...t,className:"my-2 overflow-auto rounded border border-border bg-bg-0 p-3 text-[12px] font-mono text-text-100"}),hr:({node:e,...t})=>h.jsx("hr",{...t,className:"my-3 border-border"}),table:({node:e,...t})=>h.jsx("table",{...t,className:"my-2 w-full border-collapse text-[12px]"}),thead:({node:e,...t})=>h.jsx("thead",{...t,className:"bg-bg-50"}),th:({node:e,...t})=>h.jsx("th",{...t,className:"border border-border px-2 py-1 text-left font-semibold"}),td:({node:e,...t})=>h.jsx("td",{...t,className:"border border-border px-2 py-1"}),strong:({node:e,...t})=>h.jsx("strong",{...t,className:"font-semibold text-text-100"}),em:({node:e,...t})=>h.jsx("em",{...t,className:"italic"})};function aie(e){const t=e.split("/");return t[t.length-1]||e}function kA({relPath:e,loadMarkdown:t,headerRight:n,showTitleBar:r=!1}){const[i,s]=g.useState(null),[o,a]=g.useState(null),[l,c]=g.useState(!1);return g.useEffect(()=>{if(!e)return;let u=!1;return c(!0),a(null),s(null),(async()=>{try{const d=await t(e);if(u)return;s(d)}catch(d){if(u)return;a(d.message||String(d))}finally{u||c(!1)}})(),()=>{u=!0}},[e,t]),h.jsxs("div",{className:"flex flex-col h-full",children:[r&&e?h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[h.jsx("div",{"data-testid":"md-preview-title",className:"truncate text-[13px] font-medium text-text-100",title:e,children:aie(e)}),h.jsx("div",{className:"flex items-center gap-1",children:n})]}):null,h.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 text-[13px] text-text-100",children:l?h.jsx("div",{"data-testid":"md-preview-loading",className:"text-text-400",children:"Loading…"}):o?h.jsx("div",{"data-testid":"md-preview-error",className:"text-destructive whitespace-pre-wrap",children:o}):i!==null?h.jsx("div",{"data-testid":"md-preview-content",className:"max-w-none",children:h.jsx(Jc,{remarkPlugins:[tu],components:oie,children:i})}):null})]})}function lie({open:e,onOpenChange:t,relPath:n,loadMarkdown:r,onShare:i}){return e?h.jsx("div",{"data-testid":"md-preview-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-1/2 max-w-[900px] flex-col border-l border-border bg-elevated shadow-2xl",children:h.jsx(kA,{relPath:n,loadMarkdown:r,showTitleBar:!0,headerRight:h.jsxs(h.Fragment,{children:[i?h.jsx("button",{type:"button","data-testid":"md-preview-share","aria-label":"Share rendered preview link",onClick:i,className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-400 hover:bg-bg-50 hover:text-text-200",children:h.jsx(Dz,{className:"h-4 w-4"})}):null,h.jsx("button",{type:"button","aria-label":"Close preview",onClick:()=>t(!1),className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-400 hover:bg-bg-50 hover:text-text-200",children:h.jsx(Sr,{className:"h-4 w-4"})})]})})}):null}function cie({left:e,right:t,stage:n,onExpand:r,onCollapse:i}){const s=n==="stopped",[o,a]=g.useState(!1);async function l(){if(!o){a(!0);try{await r()}catch{}finally{a(!1)}}}async function c(){if(!o){a(!0);try{await i()}catch{}finally{a(!1)}}}return h.jsxs("div",{className:"flex h-full w-full min-h-0","data-testid":"two-pane-layout",children:[h.jsxs("div",{className:"relative flex min-w-0 flex-1 flex-col","data-testid":"two-pane-left",children:[s&&h.jsx("button",{type:"button",disabled:o,className:"absolute right-14 top-2 z-10 rounded border border-border bg-elevated px-2 py-1 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed",onClick:l,children:o?"启动中…":"展开预览"}),e]}),!s&&h.jsxs("div",{className:"flex w-1/2 min-w-[320px] flex-col border-l border-bg-200","data-testid":"two-pane-right",children:[h.jsx("div",{className:"flex items-center justify-end gap-2 border-b border-bg-200 bg-bg-50 px-2 py-1",children:h.jsx("button",{type:"button",disabled:o,className:"rounded px-2 py-1 text-[12px] text-text-300 hover:bg-bg-100 disabled:opacity-50",onClick:c,children:"收起预览"})}),h.jsx("div",{className:"min-h-0 flex-1",children:t})]})]})}const uie=6173,die=6182;function hie({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=uie;v<=die;v++)(v===r||!i.includes(v))&&o.push(v);const[a,l]=g.useState(r),[c,u]=g.useState(!1),[d,f]=g.useState(null),p=a!==r&&!c;async function m(){if(p){u(!0),f(null);try{await s(a),t(!1)}catch(v){f((v==null?void 0:v.message)??String(v))}finally{u(!1)}}}return h.jsx(i1,{open:e,onOpenChange:t,children:h.jsxs(Mp,{className:"max-w-md",children:[h.jsxs(Ap,{children:[h.jsxs(Lp,{children:["改端口 · ",n]}),h.jsxs(SA,{children:["手改通常发生在系统其他进程占了默认分配的端口、dev server 起不来时。 提交后 daemon 会停 dev server → 写 ",h.jsx("code",{className:"mx-1 rounded bg-bg-100 px-1 py-0.5 text-[11px]",children:".clawd-project.json"})," → 用新端口重新起。"]})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx("label",{className:"text-xs text-text-400",children:"新端口(仅显示段内可用 + 当前端口)"}),h.jsx("select",{className:"h-9 rounded-md border border-border bg-elevated px-3 py-1 text-sm text-text-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",value:a,onChange:v=>l(Number(v.target.value)),disabled:c,children:o.map(v=>h.jsxs("option",{value:v,children:[v,v===r?"(当前)":""]},v))}),o.length===1&&h.jsx("div",{className:"text-[11px] text-text-400",children:"端口段已全被其它 project 占用,没有可换的;先删一个 idle project 释放端口。"}),d&&h.jsx("div",{className:"rounded border border-destructive/30 bg-destructive/5 px-3 py-2 text-[12px] text-destructive",children:d})]}),h.jsxs(s1,{children:[h.jsx(ri,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ri,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const LC=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function fie({currentStage:e,onCancel:t}){const n=LC.findIndex(r=>r.stage===e);return h.jsxs("div",{"data-testid":"publish-progress",className:"flex items-center gap-3 border-b border-bg-200 bg-bg-50 px-3 py-1.5 text-[12px]",children:[LC.map((r,i)=>{const s=i<n,o=i===n,a=s?"text-text-300":o?"text-text-200":"text-text-500/50";return h.jsxs("span",{className:`flex items-center gap-1 ${a}`,children:[s?h.jsx(Qf,{className:"size-3.5"}):o?h.jsx(In,{className:"size-3.5 animate-spin"}):h.jsx(MT,{className:"size-3.5"}),h.jsxs("span",{children:[r.label,o?"中…":""]})]},r.stage)}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const pie={build:"构建",deploy:"部署",verify:"验证"};function mie({stage:e,onRetry:t,onDismiss:n}){return h.jsxs("div",{"data-testid":"publish-interrupted-banner",className:"flex items-center gap-2 border-b border-yellow-400/40 bg-yellow-400/10 px-3 py-1.5 text-[12px]",children:[h.jsx(qc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",pie[e],"]"]})," ","阶段被中断(daemon 重启)"]}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded bg-accent-main-100 px-2 py-0.5 text-[11px] text-oncolor-100 hover:opacity-90",children:"重新发布"}),h.jsx("button",{type:"button",onClick:n,className:"rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const gie={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function vie({stage:e,onFocusChat:t,onClose:n}){return h.jsxs("div",{"data-testid":"publish-failed-banner",className:"flex items-center gap-2 border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[12px]",children:[h.jsx(As,{className:"size-3.5 text-destructive"}),h.jsxs("button",{type:"button",onClick:t,className:"flex-1 text-left text-text-200 hover:underline",children:["发布失败:",h.jsxs("strong",{className:"font-medium",children:["[",gie[e],"]"]})," ","已通知 assistant 接管 →"]}),h.jsx("button",{type:"button",onClick:n,"aria-label":"关闭失败提示",className:"rounded p-0.5 text-text-400 hover:bg-bg-100 hover:text-text-200",children:h.jsx(Sr,{className:"size-3.5"})})]})}const jC={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function _ie({project:e,previewHost:t,previewScheme:n,onUpdatePort:r,allUsedPorts:i,publishSlot:s,publishInFlightStage:o,onDismissPublishJob:a,onRetryPublish:l,publishFailureBanner:c,onPublishFailureBannerClose:u,onPublishFailureBannerFocusChat:d}){var _,x;const[f,p]=g.useState(!1);if(!e)return h.jsx("div",{className:"flex h-full w-full items-center justify-center p-6 text-center text-[13px] text-text-400",children:"未绑定 project"});const m=e.stage??(e.isRunning?"running":"stopped"),v=t?`${n}://${t}/preview/${e.port}/`:null,b=e.prodUrl??null;return h.jsxs("div",{className:"flex h-full w-full flex-col","data-testid":"preview-pane",children:[h.jsxs("header",{className:"flex items-center justify-between gap-2 border-b border-bg-200 bg-bg-50 px-3 py-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[h.jsx("span",{className:"font-medium text-text-200",children:e.name}),h.jsx("span",{className:"rounded bg-bg-100 px-1.5 py-0.5 text-[11px] text-text-400",children:e.port}),h.jsx("span",{className:"text-[10px] uppercase tracking-wider text-text-500",children:m==="running"?"dev":m})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[b?h.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",title:`打开线上:${b}`,className:"inline-flex items-center gap-1 rounded border border-bg-200 px-2 py-0.5 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Vc,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(sy,{children:[h.jsx(oy,{asChild:!0,children:h.jsx("button",{type:"button","aria-label":"Project settings",className:"rounded p-1 text-text-400 hover:bg-bg-100",children:h.jsx(a$,{className:"size-3.5"})})}),h.jsxs(dp,{align:"end",children:[h.jsx(bi,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(bi,{disabled:!0,title:"rename not supported yet",onSelect:y=>y.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(vie,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((_=e.publishJob)==null?void 0:_.status)==="in-flight"?h.jsx(fie,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((x=e.publishJob)==null?void 0:x.status)==="interrupted"?h.jsx(mie,{stage:e.publishJob.stage,onRetry:()=>void(l==null?void 0:l()),onDismiss:()=>void(a==null?void 0:a())}):null,h.jsx("div",{className:"min-h-0 flex-1",children:m==="failed"?h.jsx(xie,{reason:e.stageReason}):m==="stopped"?null:m==="running"?v?h.jsx("iframe",{"data-testid":"preview-iframe",className:"size-full border-0 bg-white",src:v,title:"preview"}):h.jsx(DC,{label:"等 tunnel 起来…",step:"-"}):h.jsx(DC,{label:jC[m].label,step:jC[m].step})}),h.jsx(hie,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async y=>{await r(y)}})]})}function DC({label:e,step:t}){return h.jsxs("div",{"data-testid":"preview-spinner",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(In,{className:"size-6 animate-spin text-accent-main-100"}),h.jsx("div",{className:"text-[13px] text-text-200",children:e}),h.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-500",children:t}),h.jsx("div",{className:"mt-2 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度"})]})}function xie({reason:e}){return h.jsxs("div",{"data-testid":"preview-failed",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(As,{className:"size-6 text-destructive"}),h.jsx("div",{className:"text-[13px] text-text-200",children:"project 启动失败"}),h.jsx("div",{className:"max-w-[400px] text-[12px] text-text-400",children:e??"未知原因 —— 看 ~/.clawd/clawd.log 排查"}),h.jsx("div",{className:"mt-1 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度 / 跟它说怎么修"})]})}function yie({error:e,onClose:t}){const[n,r]=g.useState(!1),i=async()=>{var a;if(!e)return;const s=e.message;let o=!1;try{(a=navigator.clipboard)!=null&&a.writeText&&(await navigator.clipboard.writeText(s),o=!0)}catch{o=!1}if(!o){const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();try{document.execCommand("copy"),o=!0}catch{o=!1}finally{document.body.removeChild(l)}}o&&(r(!0),setTimeout(()=>r(!1),1500))};return h.jsx(i1,{open:!!e,onOpenChange:s=>{s||(r(!1),t())},children:h.jsxs(Mp,{className:"max-w-lg",children:[h.jsx(Ap,{children:h.jsx(Lp,{children:(e==null?void 0:e.title)??"错误"})}),h.jsx("pre",{"data-testid":"rpc-error-message",className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded border border-bg-200 bg-bg-50 px-3 py-2 text-[12px] text-text-200",children:(e==null?void 0:e.message)??""}),h.jsxs(s1,{children:[h.jsx(ri,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(ll,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(Jf,{className:"size-3.5"}),"复制"]})}),h.jsx(ri,{onClick:t,children:"关闭"})]})]})})}function bie(e,t){for(const n of[e,t])if(n)try{const r=new URL(n),i=r.protocol==="https:"||r.protocol==="wss:"?"https":"http";return{host:r.host,scheme:i}}catch{}return{host:null,scheme:"https"}}const wie={codex:"on-request",claude:"bypassPermissions"};function Sie(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??wie[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function kie(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...Sie({cwd:t.cwd,sourceSessionId:t.sessionId,sourcePermissionMode:t.permissionMode,sourceOwnerPersonaId:t.ownerPersonaId,sourceTool:t.tool}),...r.ephemeral?{ephemeral:!0}:{}});try{const{forkedToolSessionId:s}=await e.sessionFork({cwd:t.cwd,toolSessionId:t.toolSessionId,messageUuid:n,targetCwd:i.cwd});await e.sessionResume(i.sessionId,s)}catch(s){throw e.sessionDelete(i.sessionId).catch(o=>Be("quick-ask","fork rollback failed",o)),s}return i}async function Cie(e,t,n){return kie(e,t,n,{ephemeral:!0})}function Ad(e){return e!=null&&e.ephemeral!==!1}async function Eie(e,t){return t.stillEphemeral?(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0):!1}function Nie(){return{quickAsk:null,mds:[],active:null}}function Tie(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function Pie(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function Iie(e){if(!e.quickAsk)return e;const t=e.active==="quick-ask",n=e.mds[0],r=t?n?{kind:"md",relPath:n}:null:e.active;return{...e,quickAsk:null,active:r}}function Rie(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function Mie(e,t){const n=e.mds.indexOf(t);if(n<0)return e;const r=e.mds.filter(l=>l!==t);if(!(e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===t))return{...e,mds:r};const s=r[n],o=n>0?r[n-1]:void 0;let a=null;return s?a={kind:"md",relPath:s}:o?a={kind:"md",relPath:o}:e.quickAsk&&(a="quick-ask"),{...e,mds:r,active:a}}function Aie(e,t){return{...e,active:t}}function Lie(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function CA(e){return e.quickAsk!==null||e.mds.length>0}function jie(e){return e.split("/").pop()||e}function Die({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onPromoteQuickAsk:a}){if(!CA(e))return null;const l=[];e.quickAsk&&l.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(s0,{className:"w-3.5 h-3.5"})});for(const c of e.mds)l.push({id:{kind:"md",relPath:c},label:jie(c),title:c,icon:h.jsx(To,{className:"w-3.5 h-3.5"})});return h.jsxs("div",{className:"flex flex-col h-full bg-bg-50/60 border-l border-border-strong",children:[h.jsx(B5,{delayDuration:200,skipDelayDuration:100,children:h.jsx("div",{className:["flex items-stretch h-9 border-b border-text-100/10 shrink-0 overflow-x-auto","[scrollbar-width:none] [-ms-overflow-style:none]","[&::-webkit-scrollbar]:hidden"].join(" "),role:"tablist",children:l.map(c=>{const u=Lie(e.active,c.id),d=c.id==="quick-ask"?"quick-ask":`md:${c.id.relPath}`;return h.jsxs(z5,{children:[h.jsx($5,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":u,"data-tab-title":c.title,onClick:()=>n(c.id),className:["group relative flex items-center gap-2 px-3 h-full cursor-pointer select-none","text-[12px] max-w-[180px] shrink-0 transition-colors duration-100",u?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[c.icon,h.jsx("span",{className:"truncate",children:c.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${c.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",u?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:f=>{f.stopPropagation(),c.id==="quick-ask"?r():i(c.id.relPath)},children:h.jsx(Sr,{className:"w-3 h-3"})}),u?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Xy,{side:"bottom",align:"start",className:"max-w-sm break-all",children:c.title})]},d)})})}),h.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[e.quickAsk&&o?h.jsx("div",{className:"absolute inset-0",style:{display:e.active==="quick-ask"?"block":"none"},children:h.jsx($ie,{session:o,api:t,...a?{onPromoteQuickAsk:a}:{}})}):null,e.mds.map(c=>{const u=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===c;return h.jsx("div",{className:"absolute inset-0",style:{display:u?"block":"none"},children:h.jsx(kA,{relPath:c,loadMarkdown:s,showTitleBar:!1})},`md-body:${c}`)})]})]})}function Oie({state:e,extras:t}){const{api:n,session:r}=t,i=$i(),[s,o]=g.useState(Nie()),a=g.useRef(s);a.current=s;const l=g.useRef(!1),c=g.useCallback(async S=>{const C=a.current.quickAsk,N=await Cie(n,r,S);if(N){if(l.current){n.sessionDelete(N.sessionId).catch(()=>{});return}Ad(C)&&n.sessionDelete(C.sessionId).catch(()=>{}),o(T=>Tie(T,{sessionId:N.sessionId}))}},[n,r]),u=g.useCallback(async S=>{const C=a.current.quickAsk,N=(C==null?void 0:C.sessionId)===S;try{await Eie(n,{sessionId:S,stillEphemeral:N&&Ad(C)})&&o(B=>Rie(B))}catch(T){Be("quick-ask","promote failed",T)}},[n]),d=g.useCallback(S=>{o(C=>Pie(C,S))},[]),f=g.useCallback(S=>{o(C=>Aie(C,S))},[]),p=g.useCallback(()=>{const S=a.current.quickAsk;Ad(S)&&n.sessionDelete(S.sessionId).catch(()=>{}),o(C=>Iie(C))},[n]),m=g.useCallback(S=>{o(C=>Mie(C,S))},[]);g.useEffect(()=>()=>{l.current=!0;const S=a.current.quickAsk;Ad(S)&&n.sessionDelete(S.sessionId).catch(()=>{})},[]);const v=oi("sessions")??[],b=s.quickAsk?v.find(S=>S.sessionId===s.quickAsk.sessionId)??{sessionId:s.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,_=g.useCallback(async S=>{const C=await o1(n,i,r.sessionId,S,60),N=await fetch(C);if(!N.ok)throw new Error(`fetch ${N.status} ${N.statusText}`);return N.text()},[n,i,r.sessionId]),x=h.jsx(a1,{state:e,extras:t,onQuickAskInternal:c,onPreviewMdInternal:d}),{initialSize:y,setSize:w}=AM("chat-panel-right-slot-width",480);return h.jsxs(hp,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Fa,{id:"chat",minSize:"400px",children:x}),CA(s)?h.jsxs(h.Fragment,{children:[h.jsx(gy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fa,{id:"right-slot",defaultSize:`${y}px`,minSize:"360px",maxSize:"800px",onResize:S=>w(S.inPixels),children:h.jsx(Die,{state:s,api:n,onSwitchTab:f,onCloseQuickAsk:p,onCloseMd:m,loadMarkdown:_,quickAskSession:b,onPromoteQuickAsk:u})})]}):null]})}const Bie={implicitCloseOnUserText:!1},zie={implicitCloseOnUserText:!0};function $ie({session:e,api:t,onPromoteQuickAsk:n}){const r=T5(e.sessionId);return h.jsx(a1,{state:r,extras:{session:e,api:t,...n?{onPromoteQuickAsk:n}:{}}})}function Fie({extras:e}){const t=T5(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(a1,{state:t,extras:e});return h.jsx(Hie,{state:t,chat:n,extras:e})}return h.jsx(Oie,{state:t,extras:e})}function Hie({state:e,chat:t,extras:n}){var T;const r=oi("daemon-info"),i=$i(),s=n.api,o=n.session,a=o.appBuilderProject,[l,c]=g.useState(null),u=g.useCallback(()=>{s.appBuilderGetProject(o.sessionId).then(B=>c(B.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(B=>f(B.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const L=P;L!=null&&L.project&&(L.project.name===a&&c(L.project),f(R=>{const I=R.findIndex(z=>z.name===L.project.name);if(I<0)return[...R,L.project];const D=R.slice();return D[I]=L.project,D}))}),[i,a]);const{host:m,scheme:v}=bie(i.url,r==null?void 0:r.tunnelUrl),[b,_]=g.useState(void 0),[x,y]=g.useState(null);g.useEffect(()=>{const B=i.on("appBuilder:publish-progress",L=>{const R=L;!R||R.name!==a||R.status==="started"&&_(R.stage)}),P=i.on("appBuilder:publish-failed",L=>{const R=L;!R||R.name!==a||(_(void 0),y({stage:R.stage}))});return()=>{B(),P()}},[i,a]),g.useEffect(()=>{_(void 0),y(null)},[a]);const[w,S]=g.useState(null),C=h.jsx("button",{type:"button",className:"rounded bg-accent-main-100 px-2.5 py-1 text-[12px] text-oncolor-100 hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",disabled:((T=l==null?void 0:l.publishJob)==null?void 0:T.status)==="in-flight",onClick:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"发布请求失败",message:(B==null?void 0:B.message)??String(B)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(cie,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(_ie,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(B=>B.port),onUpdatePort:async B=>{await s.appBuilderUpdateProjectPort(a,B),p()},publishSlot:C,publishInFlightStage:b,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(B){S({title:"取消发布失败",message:(B==null?void 0:B.message)??String(B)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"重新发布失败",message:(B==null?void 0:B.message)??String(B)})}},publishFailureBanner:x,onPublishFailureBannerClose:()=>y(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(yie,{error:w,onClose:()=>S(null)})]})}function Uie({headerMeta:e,connState:t,liveWorktreeRoot:n,onOpenConfig:r,variant:i="full",ephemeral:s,onPromote:o,infoPanelOpen:a=!1,onToggleInfoPanel:l,infoPanel:c,infoPanelDefaultPx:u,onInfoPanelResize:d,lines:f,pendingPermissions:p,procAlive:m,rewindableUserMessageIds:v,onPermissionRespond:b,onPermissionInterrupt:_,onRewind:x,onFork:y,onQuickAsk:w,topSlot:S,realtimeQuestionAnswers:C,onSubmitQuestion:N,onCancelQuestion:T,liveQuestionToolUseIds:B,api:P,cwd:L,tool:R,sessionKey:I,onSend:D,awaitingUser:z,onAbort:$,onNewSession:F,onClearSession:j,configSlot:O,chatRootRef:E,chatBodyRef:H,topSentinelRef:V,drawers:A,xtermSlot:ne,fileSharingScope:se,onShareFile:G,onOpenInTab:ve,onPreviewMarkdown:Le}){return h.jsx(jZ,{children:h.jsxs(hp,{orientation:"horizontal",className:"flex h-full min-w-0 min-h-0",children:[h.jsx(Fa,{id:"chat",minSize:"360px",children:h.jsxs("div",{ref:E,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-100",children:[h.jsx(RQ,{meta:e,...R?{tool:R}:{},connState:t,variant:i,...n!==void 0?{liveWorktreeRoot:n}:{},...i==="full"&&r?{onOpenConfig:r}:{},...i==="full"&&l?{infoPanelOpen:a,onToggleInfoPanel:l}:{},...i==="quickask"?{ephemeral:s??!1,...o?{onPromote:o}:{}}:{}}),h.jsxs("div",{ref:H,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[V?h.jsx("div",{ref:V,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx(PM,{lines:f,...b?{onPermissionRespond:b}:{},..._&&m?{onPermissionInterrupt:_}:{},topSlot:S,...x?{onRewind:x}:{},rewindableUserMessageIds:v,...y?{onFork:y}:{},...w?{onQuickAsk:w}:{},realtimeQuestionAnswers:C,onSubmitQuestion:N,...T?{onCancelQuestion:T}:{},liveQuestionToolUseIds:B,...se?{fileSharingScope:se}:{},...G?{onShareFile:G}:{},...ve?{onOpenInTab:ve}:{},...Le?{onPreviewMarkdown:Le}:{},...i==="full"?{turnCollapse:R==="codex"?zie:Bie}:{}})]}),ne,e.larkChatName?h.jsx("div",{className:"mx-3 mb-3 rounded-lg border border-border bg-bg-200 px-3 py-2 text-[12px] text-text-400","data-testid":"lark-readonly-notice",children:e.larkChatType==="p2p"?`此会话由与「${e.larkChatName}」的飞书私聊驱动——对方消息触发,这里仅供观察。`:`此会话由飞书群「${e.larkChatName}」驱动——群成员 @ bot 提问触发,这里仅供观察。`}):h.jsx(PQ,{meta:e,...P?{api:P}:{},cwd:L,...R?{tool:R}:{},sessionKey:I,onSend:D,awaitingUser:z,...$?{onAbort:$}:{},...F?{onNewSession:F}:{},...j?{onClearSession:j}:{},...O?{configSlot:O}:{}}),A]})}),a&&c?h.jsxs(h.Fragment,{children:[h.jsx(gy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fa,{id:"session-info",defaultSize:`${u??320}px`,minSize:"280px",maxSize:"480px",...d?{onResize:le=>d(le.inPixels)}:{},children:c})]}):null]})})}function a1({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,liveGitBranch:o,liveWorktreeRoot:a,onNewSession:l,onTurnEnd:c,onOpenConfig:u,onFork:d,onQuickAsk:f,viewerRole:p,onPromoteQuickAsk:m,configSlot:v}=t,{capabilities:b}=Ky(i.tool||"claude"),_=(b==null?void 0:b.features)??kT(i.tool),[x,y]=g.useState(null),[w,S]=g.useState(null),C=Yf(),N=!!s&&C.actionsLevel==="owner"&&_.fileSharing,T=PT(i.ownerPersonaId??null).persona,B=(T==null?void 0:T.label)??null,P=!!B&&!!i.ownerPersonaId,L=g.useCallback((K,de)=>{y({kind:K,text:de}),setTimeout(()=>{y(pe=>(pe==null?void 0:pe.text)===de?null:pe)},2e3)},[]),R=$i(),I=cB(),D=N5(i.sessionId,i.toolSessionId),{events:z,pendingQuestions:$,clearQuestion:F,markQuestionSubmitted:j,status:O}=D,E=e.historyLoading,H=DM(O);g.useEffect(()=>{Be("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:O,procAlive:H})},[O,H,i.sessionId]);const V=e.lines,A=e.pendingPermissions,ne=A[0]??null,se=g.useMemo(()=>EU(z),[z]),[G,ve]=g.useState(null),[Le,le]=g.useState(()=>new Set);SU(s,i.sessionId,i.toolSessionId,_.observe);const Ie=g.useRef(i.sessionId);g.useEffect(()=>{if(Ie.current=i.sessionId,!_.rewind){ve(null);return}let K=!1;return ve(null),(async()=>{try{const de=await s.sessionRewindableMessageIds(i.sessionId);if(K)return;ve(new Set(de.userMessageIds))}catch{K||ve(null)}})(),()=>{K=!0}},[s,i.sessionId,_.rewind]);const Re=g.useCallback(()=>{const K=i.sessionId;s.sessionRewindableMessageIds(K).then(de=>{Ie.current===K&&ve(new Set(de.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),qe=g.useMemo(()=>{if(G!==null){const Ze=new Set(G);for(const qi of Le)Ze.delete(qi);return Ze}const K=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),de=new Set;let pe=null;for(const Ze of V)Ze.kind==="user-text"?pe=Ze.uuid??null:pe&&Ze.kind==="tool-call"&&K.has(Ze.tool)&&!Le.has(pe)&&de.add(pe);return de},[V,Le,G]),_e=g.useRef(c);_e.current=c,kU(i.sessionId,i.toolSessionId,()=>{Xt(null),le(new Set)});const $e=XQ({sessionStatus:O}),fn=g.useRef(null);g.useEffect(()=>{var pe;const K=fn.current,de=(K==null?void 0:K.sid)===i.sessionId;de&&K.phase===$e||(fn.current={sid:i.sessionId,phase:$e},Be("session-phase",$e,{sid:i.sessionId,phase:$e,prev:de?K.phase:null,desc:GQ[$e]}),de&&K.phase==="turn-running"&&$e!=="turn-running"&&((pe=_e.current)==null||pe.call(_e),Re()))},[$e,i.sessionId,Re]);const it=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Mt,Xt]=g.useState(null),At=g.useCallback(K=>{Xt(K)},[]),[bt,Ye]=g.useState(!1),st=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),Ye(!1)},[s,i.sessionId]);g.useCallback(K=>{s.pinSession(i.sessionId,K).catch(de=>{Be("chat-panel","pinSession failed",{err:de==null?void 0:de.message})})},[s,i.sessionId]);const Tt=m?"quickask":"full",[Sn,sn]=g.useState(!1),{initialSize:U,setSize:J}=AM("clawd:panel:session-info-px",320),xe=g.useRef(0),Ce=g.useRef(null);g.useEffect(()=>{const K=de=>{if(de.key!=="Escape")return;if(!H){xe.current=0;return}if(de.isComposing)return;const Ze=de.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==Ce.current)return;const qi=Date.now();qi-xe.current<2e3?(xe.current=0,Ye(!0)):(xe.current=qi,it())};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[it,H]);const je=g.useRef(null),Lt=g.useRef(null),on=g.useRef(!0),wt=g.useRef(null),oe=g.useRef(0),q=g.useRef(0);g.useEffect(()=>{on.current=!0,wt.current=null,oe.current=0,q.current=0},[i.sessionId]),g.useEffect(()=>{S(null)},[i.sessionId]);const be=g.useRef(e);be.current=e;const ct=g.useCallback(()=>{var pe;const K=je.current;if(!K||wt.current!==null)return;const de=be.current;de.historyDone||de.historyLoading||(wt.current={distFromBottom:K.scrollHeight-K.scrollTop},(pe=de.loadMoreHistory)==null||pe.call(de))},[]);g.useEffect(()=>{const K=je.current,de=Lt.current;if(!K||!de)return;const pe=new IntersectionObserver(Ze=>{for(const qi of Ze)qi.isIntersecting&&ct()},{root:K,threshold:0});return pe.observe(de),()=>pe.disconnect()},[ct]),g.useEffect(()=>{const K=je.current;if(!K)return;const de=150,pe=Ze=>{Date.now()<q.current&&(Ze.preventDefault(),q.current=Date.now()+de)};return K.addEventListener("wheel",pe,{passive:!1}),()=>K.removeEventListener("wheel",pe)},[]),g.useEffect(()=>{const K=je.current;if(!K)return;const de=32,pe=()=>{const Ze=K.scrollHeight-K.scrollTop-K.clientHeight;on.current=Ze<=de};return K.addEventListener("scroll",pe,{passive:!0}),()=>K.removeEventListener("scroll",pe)},[]),g.useLayoutEffect(()=>{const K=je.current;if(!K)return;const de=oe.current,pe=V.length;oe.current=pe;const Ze=wt.current;if(Ze!==null&&pe>de){wt.current=null,K.scrollTop=K.scrollHeight-Ze.distFromBottom,q.current=Date.now()+200;return}Ze!==null&&(wt.current={distFromBottom:K.scrollHeight-K.scrollTop}),on.current&&(K.scrollTop=K.scrollHeight)},[V,ne==null?void 0:ne.requestId]);const an=g.useMemo(()=>{const K={};for(const[de,pe]of Object.entries($))pe.submittedAnswers&&(K[de]=pe.submittedAnswers);return K},[$]),gl=g.useMemo(()=>new Set(Object.keys($)),[$]),vl=g.useCallback(async(K,de)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:K,answers:de}),j(K,de)}catch{}},[s,i.sessionId,j]),_l=g.useCallback(async K=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:K}),F(K)}catch{}},[s,i.sessionId,F]),jp=g.useCallback(async(K,de)=>{var pe;if(ne)try{await((pe=e.respondPermission)==null?void 0:pe.call(e,ne.requestId,K?"allow":"deny"))}catch{}},[e,ne]),Dp=g.useCallback(async()=>{const K=i.sessionId;try{await s.sessionStop(K)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(K)},[e,s,i.sessionId]),Op=g.useMemo(()=>E&&V.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(In,{className:"w-4 h-4 text-text-400 animate-spin"})}):e.historyDone?null:h.jsx("div",{className:"flex justify-center py-2",children:h.jsx("button",{type:"button",onClick:()=>{var K;return void((K=e.loadMoreHistory)==null?void 0:K.call(e))},disabled:E,"data-testid":"history-load-more",className:"text-[12px] text-text-400 hover:text-text-200 cursor-pointer px-3 py-1 rounded-md border border-bg-300 hover:bg-bg-100 transition-colors disabled:opacity-60",children:E?"加载中…":"Load earlier messages"})}),[E,V.length,e.historyDone,e.loadMoreHistory]),xl=e.meta,Do=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(FQ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Mt&&_.rewind?h.jsx(UQ,{open:!0,onOpenChange:K=>{K||Xt(null)},api:s,sessionId:i.sessionId,userMessageId:Mt,lines:V,procAlive:H,onNoChanges:K=>{le(de=>{if(de.has(K))return de;const pe=new Set(de);return pe.add(K),pe})}}):null,bt?h.jsx(Wie,{onConfirm:st,onCancel:()=>Ye(!1)}):null]}),Bs={kind:"session",sessionId:i.sessionId},Oo=g.useCallback(async K=>{if(s)try{await iie(s,R,i.sessionId,K)}catch(de){const pe=de.message;Be("chat-panel","open-in-tab failed",{err:pe}),L("err",`Open in tab 失败:${pe}`)}},[s,R,i.sessionId,L]),[yl,fi]=g.useState(!1),[Br,Lu]=g.useState(null),ju=g.useCallback(K=>{if(r){r(K);return}Lu(K),fi(!0)},[r]),Ft=g.useCallback(async K=>{if(!s)throw new Error("daemon api not ready");const de=await o1(s,R,i.sessionId,K,60),pe=await fetch(de);if(!pe.ok)throw new Error(`fetch ${pe.status} ${pe.statusText}`);return await pe.text()},[s,R,i.sessionId]),Bo=g.useCallback(async(K,de)=>{if(s)try{const{url:pe}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:K,ttlSeconds:86400,...de?{view:de}:{}}),Ze=await sie(pe);L(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(pe){const Ze=pe.message;Be("chat-panel","share-file failed",{err:Ze}),L("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,L]),zo=g.useCallback(()=>S(null),[]),Pt=w==="files"&&N&&s?{title:"Edited Files",onBack:zo,content:h.jsx(One,{api:s,scope:Bs,sessionId:i.sessionId,onShareFile:Bo,onOpenInTab:Oo,onPreviewMarkdown:ju})}:w==="cron"?{title:`定时任务${se.length?` (${se.length})`:""}`,onBack:zo,content:h.jsx("div",{className:"p-3",children:h.jsx(KQ,{jobs:se})})}:w==="persona"&&P&&s&&i.ownerPersonaId?{title:`Persona · ${B??""}`,onBack:zo,content:h.jsx(tie,{personaId:i.ownerPersonaId,open:!0,onClose:zo,api:s,embedded:!0,...p?{viewerRole:p}:{}},i.ownerPersonaId)}:null;return h.jsxs(h.Fragment,{children:[h.jsx(Uie,{headerMeta:xl,connState:e.connState,...a!==void 0?{liveWorktreeRoot:a}:{},...u?{onOpenConfig:u}:{},variant:Tt,...Tt==="quickask"?{ephemeral:i.ephemeral!==!1,onPromote:()=>void(m==null?void 0:m(i.sessionId))}:{infoPanelOpen:Sn,onToggleInfoPanel:()=>sn(K=>!K),infoPanelDefaultPx:U,onInfoPanelResize:J,infoPanel:h.jsx(LQ,{session:i,meta:xl,...o!==void 0?{liveGitBranch:o}:{},...a!==void 0?{liveWorktreeRoot:a}:{},...P?{personaName:B}:{},...P?{onOpenPersona:()=>S("persona")}:{},...N?{onOpenFiles:()=>S("files")}:{},cronActiveCount:se.length,onCronClick:()=>S("cron"),onForceStop:()=>Ye(!0),...p?{viewerRole:p}:{},...b!=null&&b.toolSessionIdLabel?{toolSessionIdLabel:b.toolSessionIdLabel}:{},drill:Pt,onClose:()=>sn(!1)})},lines:V,pendingPermissions:A,procAlive:H,rewindableUserMessageIds:qe,onPermissionRespond:jp,onPermissionInterrupt:it,onRewind:_.rewind?At:void 0,...d&&_.fork?{onFork:d}:{},...n&&_.fork?{onQuickAsk:n}:f&&_.fork?{onQuickAsk:f}:{},topSlot:Op,realtimeQuestionAnswers:an,onSubmitQuestion:vl,onCancelQuestion:_l,liveQuestionToolUseIds:gl,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:A.length>0||Object.values($).some(K=>!K.submittedAnswers),onAbort:it,...l?{onNewSession:l}:{},onClearSession:Dp,...v?{configSlot:v}:{},chatRootRef:Ce,chatBodyRef:je,topSentinelRef:Lt,drawers:Do,xtermSlot:I==="tui"&&H&&_.tui?h.jsx(cne,{sessionId:i.sessionId,client:R},i.sessionId):null,fileSharingScope:Bs,...s?{onShareFile:Bo}:{},...s?{onOpenInTab:Oo}:{},...s?{onPreviewMarkdown:ju}:{}}),s?h.jsx(lie,{open:yl,onOpenChange:fi,relPath:Br,loadMarkdown:Ft,onShare:Br?()=>void Bo(Br,"md-rendered"):void 0}):null,x?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:x.kind==="ok"?"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-[12px] text-emerald-700 shadow-md dark:text-emerald-300":"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[12px] text-destructive shadow-md",children:x.text}):null]})}function Wie({onConfirm:e,onCancel:t}){return h.jsx("div",{role:"dialog","aria-modal":"true","data-testid":"force-stop-confirm",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:t,children:h.jsxs("div",{className:"max-w-sm w-[92%] rounded-lg border border-red-400/40 bg-bg-0 p-4 shadow-xl",onClick:n=>n.stopPropagation(),children:[h.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[h.jsx(qc,{className:"w-5 h-5 text-red-500 shrink-0 mt-0.5"}),h.jsx("div",{className:"text-[14px] text-text-100",children:"强制停止会话进程?会丢失 initialize / 预热缓存,下一次发送需要重新 spawn。"})]}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:t,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","data-testid":"force-stop-confirm-ok",onClick:e,className:"h-8 px-3 rounded-md bg-red-500 text-white text-[12px] font-medium hover:bg-red-600 cursor-pointer",children:"强制停止"})]})]})})}function Vie(e,t,n){const r=e?t.find(s=>s.id===e):void 0;if(r!=null&&r.efforts&&r.efforts.length>0)return{options:r.efforts,defaultValue:r.defaultEffort??""};const i=n.find(s=>s.name==="effort");return{options:(i==null?void 0:i.options)??[],defaultValue:typeof(i==null?void 0:i.default)=="string"?i.default:""}}function qie(e,t,n){var l;if(!t)return((l=(e??[]).find(c=>c.id===""))==null?void 0:l.label)??"未指定";const r=t.toLowerCase(),i=[["opus","Opus"],["fable","Fable"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[c,u]of i){if(!r.includes(c))continue;const d=r.match(new RegExp(`${c}-(\\d+)(?:-(\\d+))?`));return d?d[2]?`${u} ${d[1]}.${d[2]}`:`${u} ${d[1]}`:u}const s=e??[],o=s.find(c=>c.id===t);if(o)return o.label;const a=s.find(c=>c.id&&t.toLowerCase().includes(c.id.toLowerCase()));return a?a.label:t}function Kie(e,t){var m,v,b,_;const{models:n,modes:r,configSchema:i}=t,s=e.resolvedModel??e.model,o=Vie(s,n,i),a=o.options,l=a.some(x=>x.value===e.effort)?e.effort:o.defaultValue,c=e.effort===""&&e.resolvedEffort?((m=a.find(x=>x.value===e.resolvedEffort))==null?void 0:m.label)??e.resolvedEffort:((v=a.find(x=>x.value===l))==null?void 0:v.label)??null,u=((b=i.find(x=>x.name==="permissionMode"))==null?void 0:b.default)??"",d=r.some(x=>x.id===e.permissionMode)?e.permissionMode:u,p=d===u?null:((_=r.find(x=>x.id===d))==null?void 0:_.label)??null;return{modelLabel:qie(n,s),effortOptions:a,effortValue:l,effortLabel:c,modeValue:d,modeLabel:p,modeTone:p===null?null:d==="bypassPermissions"?"danger":"info"}}function Gie({models:e=[],modes:t=[],configSchema:n=[],model:r,resolvedModel:i,resolvedEffort:s,effort:o,permissionMode:a,onPatch:l}){var p;const c=Kie({model:r,resolvedModel:i,resolvedEffort:s,effort:o,permissionMode:a},{models:e,modes:t,configSchema:n}),u=i??r,d=e.map(m=>{const v=m.id===""&&i?`${m.description?`${m.description};`:""}当前:${i}`:m.description;return{value:m.id,label:m.label,...v?{description:v}:{}}}),f=t.map(m=>({value:m.id,label:m.label,...m.description?{description:m.description}:{}}));return h.jsxs(sy,{children:[h.jsx(oy,{asChild:!0,children:h.jsxs("button",{type:"button","data-testid":"session-config-chip",title:"Model / reasoning effort / permission mode",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:[h.jsx("span",{className:"truncate max-w-[120px]","data-testid":"session-config-chip-model",children:u||c.modelLabel}),c.effortLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"truncate max-w-[80px]","data-testid":"session-config-chip-effort",children:c.effortLabel})]}):null,c.modeLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{"data-testid":"session-config-chip-mode","data-tone":c.modeTone,className:ae("font-semibold",c.modeTone==="danger"?"text-red-400":"text-blue-400"),children:c.modeLabel})]}):null]})}),h.jsxs(dp,{side:"top",align:"end",className:"w-[230px]","data-testid":"session-config-menu",children:[h.jsx(wg,{testid:"session-config-model",label:"Model",current:r,currentLabel:c.modelLabel,options:d,onSelect:m=>l({model:m})}),h.jsx(wg,{testid:"session-config-effort",label:"Reasoning effort",current:c.effortValue,currentLabel:c.effortLabel??"—",options:c.effortOptions,onSelect:m=>l({effort:m})}),f.length>0?h.jsx(wg,{testid:"session-config-mode",label:"Permission mode",current:c.modeValue,currentLabel:((p=t.find(m=>m.id===c.modeValue))==null?void 0:p.label)??"—",currentTone:c.modeTone,options:f,onSelect:m=>l({permissionMode:m})}):null]})]})}function wg({testid:e,label:t,current:n,currentLabel:r,currentTone:i,options:s,onSelect:o}){const a=s.length===0;return h.jsxs(kH,{children:[h.jsxs(VI,{"data-testid":e,disabled:a,className:"gap-2 text-[12px]",children:[h.jsx("span",{className:"flex-1 text-text-200",children:t}),h.jsx("span",{className:ae("truncate max-w-[100px]",i==="danger"?"text-red-400 font-semibold":i==="info"?"text-blue-400 font-semibold":"text-text-400"),children:r}),h.jsx(Un,{className:"w-3.5 h-3.5 shrink-0 text-text-500"})]}),h.jsx(qI,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:s.map(l=>{const c=l.value===n;return h.jsxs(bi,{"data-testid":`${e}-option-${l.value||"default"}`,onSelect:()=>o(l.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsx("span",{className:ae("block text-[12px]",c?"text-text-100 font-medium":"text-text-300"),children:l.label}),l.description?h.jsx("span",{className:"block text-[11px] text-text-400 mt-0.5",children:l.description}):null]}),c?h.jsx(ll,{className:"w-3.5 h-3.5 shrink-0 text-accent mt-0.5"}):null]},l.value||"default")})})]})}function Xie(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitBranch(t);i(l.branch??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{branch:r,loading:s,refresh:()=>void a()}}function Yie(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitRoot(t);i(l.gitRoot??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{worktreeRoot:r,loading:s,refresh:()=>void a()}}function Zie({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onFork:l,onQuickAsk:c,className:u,viewerRole:d="owner"}){const{capabilities:f}=Ky(t.tool),[p,m]=g.useState(0),{branch:v}=Xie(e,t.cwd,p),{worktreeRoot:b}=Yie(e,t.cwd,p),_=r>1,x=y=>{e.sessionUpdate(t.sessionId,y).catch(w=>{console.error("[session-config] session:update failed",t.sessionId,w)})};return h.jsxs("div",{className:`group/pane relative flex-1 ${u??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${_?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsx(hp,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:h.jsx(Fa,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(Qie,{api:e,session:t,liveGitBranch:v,liveWorktreeRoot:b,onNewSession:o,onTurnEnd:()=>m(y=>y+1),onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:d,configSlot:f?h.jsx(Gie,{models:f.models,modes:f.permissionModes,configSchema:f.configSchema,model:t.model??"",...t.resolvedModel?{resolvedModel:t.resolvedModel}:{},...t.resolvedEffort?{resolvedEffort:t.resolvedEffort}:{},effort:t.effort??"",permissionMode:t.permissionMode??"",onPatch:x}):null})})})}),_&&h.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),s()},className:"absolute top-1.5 right-1.5 z-10 p-1 rounded-md bg-bg-100/80 backdrop-blur-sm border border-border opacity-0 group-hover/pane:opacity-100 transition-opacity text-text-400 hover:text-text-100 hover:bg-bg-200","aria-label":"close pane","data-testid":`session-pane-close-${t.sessionId}`,children:h.jsx(Sr,{className:"w-3.5 h-3.5"})})]})}function Qie({api:e,session:t,liveGitBranch:n,liveWorktreeRoot:r,onNewSession:i,onTurnEnd:s,onOpenConfig:o,onFork:a,onQuickAsk:l,viewerRole:c,configSlot:u}){return h.jsx(Fie,{extras:{session:t,api:e,...n!==void 0?{liveGitBranch:n}:{},...r!==void 0?{liveWorktreeRoot:r}:{},onNewSession:i,onTurnEnd:s,onOpenConfig:o,...a?{onFork:d=>{a(d)}}:{},...l?{onQuickAsk:d=>{l(d)}}:{},...c?{viewerRole:c}:{},...u?{configSlot:u}:{}}})}function Jie({personas:e,sessions:t,api:n,selfPrincipalId:r,selectedPersonaId:i,selectedSessionId:s,selectedSession:o,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,onCloseSession:f}){return h.jsxs("div",{className:"flex h-screen min-h-0 bg-bg-50","data-testid":"guest-share-page",children:[h.jsx("aside",{className:"w-[280px] shrink-0 overflow-y-auto border-r border-border bg-bg-50",children:h.jsx(FH,{personas:e,sessions:t,activePersonaId:i,activeSessionId:s,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,showCopyResume:!1,treatSessionsAsRoots:!0,...r?{ownerPrincipalId:r}:{},isPersonaExpanded:()=>!0})}),h.jsx("main",{className:"flex-1 min-w-0 min-h-0 flex",children:o?h.jsx(Zie,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},viewerRole:"guest"}):h.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-xs text-text-400","data-testid":"guest-share-empty",children:"选择左侧 persona 开始对话"})})]})}function ese(){const e=$i(),t=g.useMemo(()=>new Rx(e),[e]),n=IB(e),{sessions:r,refresh:i}=RB(n),{personas:s}=TT(),o=OB(),a=g.useMemo(()=>{const w=window.location.pathname.match(/^\/s\/([^/]+)/);return w?decodeURIComponent(w[1]):null},[]),l=g.useMemo(()=>r.filter(w=>!w.ephemeral&&w.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(w=>w.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let w=!1;return e.request("whoami",{}).then(S=>{w||d(S.capability.id)}).catch(()=>{}),()=>{w=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const b=g.useCallback(async(w,S)=>{const C=await t.sessionCreate({ownerPersonaId:w,...S.trim()?{label:S.trim()}:{}});await i(),p(w),v(C.sessionId)},[t,i]),_=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(S=>S===w?null:S)},[t,i]),x=g.useCallback(async(w,S)=>{await t.sessionUpdate(w,{label:S.label}),await i()},[t,i]),y=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(Mx.Provider,{value:o,children:h.jsx(Jie,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:y,onSelectPersona:p,onSelectSession:v,onCreateSession:(w,S)=>void b(w,S),onDeleteSession:w=>void _(w),onEditSession:(w,S)=>void x(w,S),onCloseSession:()=>v(null)})})}const OC="https://app.ttcadvisory.com";function tse({onAuthed:e}){const[t,n]=g.useState(!1),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&window.removeEventListener("message",s.current)},[]);const o=g.useCallback(()=>{s.current&&(window.removeEventListener("message",s.current),s.current=null),n(!0),i(null);const a=window.location.origin,l=`${OC}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==OC)return;const f=d.data;if((f==null?void 0:f.type)==="AUTH_CANCEL"){u(),n(!1);return}if(!((f==null?void 0:f.type)!=="AUTH_SUCCESS"||!f.token)){u();try{const p=await fetch(`${window.location.origin}/share/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ttcToken:f.token})});if(!p.ok){const v=await p.json().catch(()=>({}));throw new Error(v.code??`exchange failed (${p.status})`)}const m=await p.json();if(!m.visitorToken)throw new Error("no visitorToken in response");e(m.visitorToken)}catch(p){i(p instanceof Error?p.message:String(p)),n(!1)}}},u=()=>{window.removeEventListener("message",c),s.current=null};s.current=d=>void c(d),window.addEventListener("message",s.current),window.open(l,"ttc-login","width=480,height=640")},[e]);return h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 font-sans text-text-100","data-testid":"guest-login",children:h.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-3 rounded-lg border border-border bg-bg-100 px-5 py-6",children:[h.jsx("h1",{className:"text-base font-semibold",children:"登录后进入分享"}),h.jsx("p",{className:"text-[11px] leading-snug text-text-400",children:"使用飞书账号登录,即可在浏览器里与分享给你的 persona 交互,无需安装。"}),r?h.jsxs("p",{className:"text-[11px] leading-snug text-error","data-testid":"guest-login-error",children:["登录失败:",r]}):null,h.jsx("button",{type:"button",disabled:t,onClick:()=>o(),"data-testid":"guest-login-button",className:"w-full rounded border border-border bg-bg-50 px-2 py-1.5 text-xs text-text-200 transition-colors hover:bg-text-100/5 hover:text-text-100 disabled:opacity-50",children:t?"请在弹窗中完成授权…":"飞书登录"})]})})}const y_="clawd-visitor:token";function nse(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function rse(){return{async getUrl(e){const t=localStorage.getItem(y_);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=nse(window.location,{});return await xT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function ise(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function sse(){const e=$i(),t=g.useMemo(()=>PB(e),[e]);return h.jsx(uB,{cache:t.cache,children:h.jsx(fB,{children:h.jsx(ese,{})})})}function ose({host:e}){const[t]=g.useState(()=>localStorage.getItem(y_)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>ise(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return rse().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(kb,{host:e,children:h.jsx(rw,{children:i?h.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-center text-xs text-error","data-testid":"guest-share-connect-error",children:["连接失败:",i]}):n?h.jsx(lB,{host:e,children:h.jsx(sse,{})}):h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-xs text-text-400",children:"正在连接…"})})}):h.jsx(kb,{host:e,children:h.jsx(rw,{children:h.jsx(tse,{onAuthed:o=>{localStorage.setItem(y_,o),window.location.reload()}})})})}function ase({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):lse(t??"",n??""),[t,n,r]);return h.jsxs("div",{"data-testid":"inline-diff",className:"min-w-0 max-w-full rounded-lg border border-bg-300/60 bg-bg-50 overflow-hidden text-[12px] font-mono",children:[h.jsx("div",{className:"flex min-w-0 items-center gap-2 px-3 py-1.5 border-b border-bg-300/40 bg-bg-100/30",children:h.jsx("span",{className:"min-w-0 text-text-400 truncate",title:e,children:e})}),h.jsx("div",{className:"max-h-[320px] max-w-full overflow-auto",children:i.map((s,o)=>h.jsxs("div",{"data-testid":`diff-line-${s.type}`,className:ae("flex min-w-max gap-2 px-3 py-0.5 whitespace-pre",s.type==="add"?"bg-success/10 text-success":s.type==="remove"?"bg-error/10 text-error":"text-text-300"),children:[h.jsx("span",{className:"w-3 shrink-0 select-none opacity-60",children:s.type==="add"?"+":s.type==="remove"?"-":" "}),h.jsx("span",{className:"flex-1",children:s.text||" "})]},o))})]})}function lse(e,t){const n=e.split(/\r?\n/),r=t.split(/\r?\n/),i=n.length,s=r.length,o=Array.from({length:i+1},()=>new Array(s+1).fill(0));for(let u=i-1;u>=0;u--)for(let d=s-1;d>=0;d--)o[u][d]=n[u]===r[d]?o[u+1][d+1]+1:Math.max(o[u+1][d],o[u][d+1]);const a=[];let l=0,c=0;for(;l<i&&c<s;)n[l]===r[c]?(a.push({type:"equal",text:n[l]}),l++,c++):o[l+1][c]>=o[l][c+1]?(a.push({type:"remove",text:n[l]}),l++):(a.push({type:"add",text:r[c]}),c++);for(;l<i;)a.push({type:"remove",text:n[l++]});for(;c<s;)a.push({type:"add",text:r[c++]});return a}function cse({items:e}){return e.length===0?null:h.jsxs("div",{"data-testid":"todo-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1.5",children:"Todos"}),h.jsx("ul",{className:"flex flex-col gap-1",children:e.map((t,n)=>{const r=t.status==="in_progress"&&t.activeForm||t.content;return h.jsxs("li",{"data-testid":`todo-item-${t.status}`,className:"flex items-start gap-2",children:[h.jsx(use,{status:t.status}),h.jsx("span",{className:ae("flex-1 leading-snug",t.status==="completed"?"text-text-400 line-through":t.status==="in_progress"?"text-text-100 font-medium":"text-text-200"),children:r})]},n)})})]})}function use({status:e}){return e==="completed"?h.jsx(Qf,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(In,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(MT,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function dse(e){const t=e??{};return Array.isArray(t.todos)?t.todos.map(n=>{if(!n||typeof n!="object")return null;const r=n,i=typeof r.content=="string"?r.content:"",s=r.status==="pending"||r.status==="in_progress"||r.status==="completed"?r.status:"pending",o=typeof r.activeForm=="string"?r.activeForm:void 0;return{content:i,status:s,activeForm:o}}).filter(n=>n!==null):[]}function hse({description:e,prompt:t,subagentType:n}){return h.jsxs("div",{"data-testid":"task-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsxs("div",{className:"flex items-center gap-2 text-text-200 font-medium",children:[h.jsx(Zf,{className:"w-3.5 h-3.5 text-accent shrink-0"}),h.jsx("span",{className:"truncate",children:e||"subagent task"}),n?h.jsx("span",{className:"shrink-0 px-1.5 py-0.5 rounded-md text-[10px] font-mono bg-accent/10 text-accent",children:n}):null]}),t?h.jsx("div",{className:"mt-1 text-[12px] text-text-400 leading-snug line-clamp-3",children:t}):null]})}function fse(e){const t=e??{};return{description:typeof t.description=="string"?t.description:"",prompt:typeof t.prompt=="string"?t.prompt:void 0,subagentType:typeof t.subagent_type=="string"?t.subagent_type:void 0}}const pse={render:({input:e})=>Je.createElement(cse,{items:dse(e)})},mse={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=fse(e);return Je.createElement(hse,{description:t,prompt:n,subagentType:r})}},EA={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=vse(e),c=l?Je.createElement(ase,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return Je.createElement(SM,{tool:gse(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function gse(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function vse(e){const t=e??{},n=typeof t.file_path=="string"?t.file_path:null;if(!n)return null;const r=typeof t.old_string=="string"?t.old_string:void 0,i=typeof t.new_string=="string"?t.new_string:void 0,s=typeof t.content=="string"?t.content:void 0;return r==null&&i==null&&s==null?null:{filePath:n,oldString:r,newString:i,content:s}}fl.register("claude","TodoWrite",pse);fl.register("claude","Task",mse);fl.register("claude","Edit",EA);fl.register("claude","Write",EA);const NA=document.getElementById("root");if(!NA)throw new Error("guest-main: #root not found");const _se=aL({});Sg.createRoot(NA).render(h.jsx(Je.StrictMode,{children:h.jsx(ose,{host:_se})}));
|