@clawos-dev/clawd 0.2.301 → 0.2.303
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
CHANGED
|
@@ -51855,6 +51855,7 @@ init_protocol();
|
|
|
51855
51855
|
var PROVISION_ERROR_SET = new Set(LARK_BOT_PROVISION_ERROR_REASONS);
|
|
51856
51856
|
var PROVISION_POLL_INTERVAL_MS = 2e3;
|
|
51857
51857
|
var PROVISION_MAX_CONSECUTIVE_FAILURES = 5;
|
|
51858
|
+
var PROVISION_POLL_MAX_MS = 60 * 60 * 1e3;
|
|
51858
51859
|
function normalizeProvisionReason(reason) {
|
|
51859
51860
|
return PROVISION_ERROR_SET.has(reason) ? reason : "lark_protocol_error";
|
|
51860
51861
|
}
|
|
@@ -51875,10 +51876,17 @@ function buildLarkBotHandlers(deps) {
|
|
|
51875
51876
|
};
|
|
51876
51877
|
const runProvisionPolling = async (personaId2, provisionId) => {
|
|
51877
51878
|
let failures = 0;
|
|
51879
|
+
const startedAt = now();
|
|
51878
51880
|
for (; ; ) {
|
|
51879
51881
|
await sleep2(pollIntervalMs);
|
|
51880
51882
|
const entry = inFlight.get(personaId2);
|
|
51881
51883
|
if (!entry || entry.cancelled) return;
|
|
51884
|
+
if (now() - startedAt >= PROVISION_POLL_MAX_MS) {
|
|
51885
|
+
inFlight.delete(personaId2);
|
|
51886
|
+
deps.logger?.warn(`larkBot provision poll deadline exceeded: ${personaId2}`);
|
|
51887
|
+
emit(personaId2, { state: "unbound", errorReason: "expired", groups: [] });
|
|
51888
|
+
return;
|
|
51889
|
+
}
|
|
51882
51890
|
let status2;
|
|
51883
51891
|
try {
|
|
51884
51892
|
status2 = await deps.cloud.provisionStatus(provisionId);
|
|
@@ -51895,16 +51903,7 @@ function buildLarkBotHandlers(deps) {
|
|
|
51895
51903
|
continue;
|
|
51896
51904
|
}
|
|
51897
51905
|
const current = inFlight.get(personaId2);
|
|
51898
|
-
if (!current || current.cancelled)
|
|
51899
|
-
if (status2.state === "success") {
|
|
51900
|
-
void deps.cloud.unbind(status2.appId).catch(
|
|
51901
|
-
(err) => deps.logger?.warn(
|
|
51902
|
-
`larkBot provision late-success cleanup unbind failed: ${err.message}`
|
|
51903
|
-
)
|
|
51904
|
-
);
|
|
51905
|
-
}
|
|
51906
|
-
return;
|
|
51907
|
-
}
|
|
51906
|
+
if (!current || current.cancelled) return;
|
|
51908
51907
|
if (status2.state === "pending") continue;
|
|
51909
51908
|
inFlight.delete(personaId2);
|
|
51910
51909
|
if (status2.state === "success") {
|
|
@@ -51972,10 +51971,25 @@ function buildLarkBotHandlers(deps) {
|
|
|
51972
51971
|
if (!entry) throw new Error(`larkBot provision not in flight: ${personaId2}`);
|
|
51973
51972
|
entry.cancelled = true;
|
|
51974
51973
|
if (entry.provisionId) {
|
|
51975
|
-
await deps.cloud.provisionCancel(entry.provisionId).catch(
|
|
51976
|
-
|
|
51977
|
-
|
|
51974
|
+
const result = await deps.cloud.provisionCancel(entry.provisionId).catch((err) => {
|
|
51975
|
+
deps.logger?.warn(`larkBot provisionCancel cloud failed: ${err.message}`);
|
|
51976
|
+
return { state: "cancelled" };
|
|
51977
|
+
});
|
|
51978
51978
|
inFlight.delete(personaId2);
|
|
51979
|
+
if (result.state === "success") {
|
|
51980
|
+
deps.store.write(personaId2, {
|
|
51981
|
+
appId: result.appId,
|
|
51982
|
+
botName: result.botName,
|
|
51983
|
+
boundAt: now()
|
|
51984
|
+
});
|
|
51985
|
+
emit(personaId2, {
|
|
51986
|
+
state: "bound",
|
|
51987
|
+
appId: result.appId,
|
|
51988
|
+
botName: result.botName,
|
|
51989
|
+
groups: groupsOf(personaId2)
|
|
51990
|
+
});
|
|
51991
|
+
return { response: { type: "larkBot:provisionCancel:ok" } };
|
|
51992
|
+
}
|
|
51979
51993
|
}
|
|
51980
51994
|
emit(personaId2, { state: "unbound", groups: [] });
|
|
51981
51995
|
return { response: { type: "larkBot:provisionCancel:ok" } };
|
|
@@ -52025,22 +52039,53 @@ function buildLarkBotHandlers(deps) {
|
|
|
52025
52039
|
};
|
|
52026
52040
|
}
|
|
52027
52041
|
const meta = deps.store.read(personaId2);
|
|
52028
|
-
|
|
52029
|
-
return {
|
|
52030
|
-
response: { type: "larkBot:status:ok", state: "unbound", groups: [] }
|
|
52031
|
-
};
|
|
52032
|
-
}
|
|
52042
|
+
let cloudReachable = false;
|
|
52033
52043
|
let cloudBinding;
|
|
52034
52044
|
try {
|
|
52035
52045
|
cloudBinding = (await deps.cloud.listBindings()).find((b2) => b2.personaId === personaId2);
|
|
52046
|
+
cloudReachable = true;
|
|
52036
52047
|
} catch (err) {
|
|
52037
52048
|
deps.logger?.warn(`larkBot status: cloud unreachable: ${err.message}`);
|
|
52038
52049
|
}
|
|
52050
|
+
if (!meta) {
|
|
52051
|
+
if (cloudBinding) {
|
|
52052
|
+
deps.store.write(personaId2, {
|
|
52053
|
+
appId: cloudBinding.appId,
|
|
52054
|
+
botName: cloudBinding.botName,
|
|
52055
|
+
boundAt: now()
|
|
52056
|
+
});
|
|
52057
|
+
const broken2 = cloudBinding.status === "broken";
|
|
52058
|
+
const result2 = {
|
|
52059
|
+
state: broken2 ? "broken" : "bound",
|
|
52060
|
+
appId: cloudBinding.appId,
|
|
52061
|
+
botName: cloudBinding.botName,
|
|
52062
|
+
...broken2 ? { brokenReason: cloudBinding.brokenReason ?? "unknown" } : {},
|
|
52063
|
+
groups: groupsOf(personaId2)
|
|
52064
|
+
};
|
|
52065
|
+
return { response: { type: "larkBot:status:ok", ...result2 } };
|
|
52066
|
+
}
|
|
52067
|
+
return {
|
|
52068
|
+
response: { type: "larkBot:status:ok", state: "unbound", groups: [] }
|
|
52069
|
+
};
|
|
52070
|
+
}
|
|
52071
|
+
if (cloudReachable && !cloudBinding) {
|
|
52072
|
+
deps.store.remove(personaId2);
|
|
52073
|
+
return {
|
|
52074
|
+
response: { type: "larkBot:status:ok", state: "unbound", groups: [] }
|
|
52075
|
+
};
|
|
52076
|
+
}
|
|
52077
|
+
if (cloudBinding && (cloudBinding.appId !== meta.appId || cloudBinding.botName !== meta.botName)) {
|
|
52078
|
+
deps.store.write(personaId2, {
|
|
52079
|
+
appId: cloudBinding.appId,
|
|
52080
|
+
botName: cloudBinding.botName,
|
|
52081
|
+
boundAt: now()
|
|
52082
|
+
});
|
|
52083
|
+
}
|
|
52039
52084
|
const broken = cloudBinding?.status === "broken";
|
|
52040
52085
|
const result = {
|
|
52041
52086
|
state: broken ? "broken" : "bound",
|
|
52042
|
-
appId: meta.appId,
|
|
52043
|
-
botName: meta.botName,
|
|
52087
|
+
appId: cloudBinding?.appId ?? meta.appId,
|
|
52088
|
+
botName: cloudBinding?.botName ?? meta.botName,
|
|
52044
52089
|
...broken ? { brokenReason: cloudBinding?.brokenReason ?? "unknown" } : {},
|
|
52045
52090
|
groups: groupsOf(personaId2)
|
|
52046
52091
|
};
|
|
@@ -52182,7 +52227,14 @@ function createLarkBotCloudClient(opts) {
|
|
|
52182
52227
|
return { state: "pending" };
|
|
52183
52228
|
},
|
|
52184
52229
|
async provisionCancel(provisionId) {
|
|
52185
|
-
await request(
|
|
52230
|
+
const json = await request(
|
|
52231
|
+
"DELETE",
|
|
52232
|
+
`/api/lark-bot/provision/${encodeURIComponent(provisionId)}`
|
|
52233
|
+
);
|
|
52234
|
+
if (json.state === "success") {
|
|
52235
|
+
return { state: "success", appId: String(json.appId), botName: String(json.botName) };
|
|
52236
|
+
}
|
|
52237
|
+
return { state: "cancelled" };
|
|
52186
52238
|
},
|
|
52187
52239
|
async reply(args) {
|
|
52188
52240
|
await request("POST", "/api/lark-bot/reply", { ...args });
|
|
@@ -59217,7 +59269,7 @@ function computeMethodAccess(args) {
|
|
|
59217
59269
|
}
|
|
59218
59270
|
|
|
59219
59271
|
// src/version.ts
|
|
59220
|
-
var version = "0.2.
|
|
59272
|
+
var version = "0.2.303".length > 0 ? "0.2.303" : "dev";
|
|
59221
59273
|
|
|
59222
59274
|
// src/cli-probe/probe.ts
|
|
59223
59275
|
var fs56 = __toESM(require("fs"), 1);
|
|
@@ -566,4 +566,4 @@ Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}};var Dn
|
|
|
566
566
|
The chosen QR Code version cannot contain this amount of data.
|
|
567
567
|
Minimum version required to store current data is: `+s+`.
|
|
568
568
|
`);const o=Yne(t,n,i),a=Tp.getSymbolSize(t),l=new zne(a);return Vne(l,t),qne(l),Kne(l,t),fg(l,n,0),t>=7&&Gne(l,t),Xne(l,o),isNaN(r)&&(r=ux.getBestMask(l,fg.bind(null,l,n))),ux.applyMask(r,l),fg(l,n,r),{modules:l,version:t,errorCorrectionLevel:n,maskPattern:r,segments:i}}qA.create=function(t,n){if(typeof t>"u"||t==="")throw new Error("No input text");let r=dg.M,i,s;return typeof n<"u"&&(r=dg.from(n.errorCorrectionLevel,dg.M),i=mf.from(n.version),s=ux.from(n.maskPattern),n.toSJISFunc&&Tp.setToSJISFunction(n.toSJISFunc)),Qne(t,i,r,s)};var s5={},Qy={};(function(e){function t(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let r=n.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+n);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(s){return[s,s]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,s=r.width&&r.width>=21?r.width:void 0,o=r.scale||4;return{width:s,scale:s?4:o,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const s=e.getScale(r,i);return Math.floor((r+i.margin*2)*s)},e.qrToImageData=function(r,i,s){const o=i.modules.size,a=i.modules.data,l=e.getScale(o,s),c=Math.floor((o+s.margin*2)*l),u=s.margin*l,d=[s.color.light,s.color.dark];for(let f=0;f<c;f++)for(let p=0;p<c;p++){let m=(f*c+p)*4,v=s.color.light;if(f>=u&&p>=u&&f<c-u&&p<c-u){const b=Math.floor((f-u)/l),x=Math.floor((p-u)/l);v=d[a[b*o+x]?1:0]}r[m++]=v.r,r[m++]=v.g,r[m++]=v.b,r[m]=v.a}}})(Qy);(function(e){const t=Qy;function n(i,s,o){i.clearRect(0,0,s.width,s.height),s.style||(s.style={}),s.height=o,s.width=o,s.style.height=o+"px",s.style.width=o+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(s,o,a){let l=a,c=o;typeof l>"u"&&(!o||!o.getContext)&&(l=o,o=void 0),o||(c=r()),l=t.getOptions(l);const u=t.getImageWidth(s.modules.size,l),d=c.getContext("2d"),f=d.createImageData(u,u);return t.qrToImageData(f.data,s,l),n(d,c,u),d.putImageData(f,0,0),c},e.renderToDataURL=function(s,o,a){let l=a;typeof l>"u"&&(!o||!o.getContext)&&(l=o,o=void 0),l||(l={});const c=e.render(s,o,l),u=l.type||"image/png",d=l.rendererOpts||{};return c.toDataURL(u,d.quality)}})(s5);var o5={};const Jne=Qy;function SC(e,t){const n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function pg(e,t,n){let r=e+t;return typeof n<"u"&&(r+=" "+n),r}function ere(e,t,n){let r="",i=0,s=!1,o=0;for(let a=0;a<e.length;a++){const l=Math.floor(a%t),c=Math.floor(a/t);!l&&!s&&(s=!0),e[a]?(o++,a>0&&l>0&&e[a-1]||(r+=s?pg("M",l+n,.5+c+n):pg("m",i,0),i=0,s=!1),l+1<t&&e[a+1]||(r+=pg("h",o),o=0)):i++}return r}o5.render=function(t,n,r){const i=Jne.getOptions(n),s=t.modules.size,o=t.modules.data,a=s+i.margin*2,l=i.color.light.a?"<path "+SC(i.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",c="<path "+SC(i.color.dark,"stroke")+' d="'+ere(o,s,i.margin)+'"/>',u='viewBox="0 0 '+a+" "+a+'"',f='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+u+' shape-rendering="crispEdges">'+l+c+`</svg>
|
|
569
|
-
`;return typeof r=="function"&&r(null,f),f};const tre=gne,hx=qA,a5=s5,nre=o5;function Jy(e,t,n,r,i){const s=[].slice.call(arguments,1),o=s.length,a=typeof s[o-1]=="function";if(!a&&!tre())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(i=n,n=t,t=r=void 0):o===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=n,n=t,t=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(n=t,t=r=void 0):o===2&&!t.getContext&&(r=n,n=t,t=void 0),new Promise(function(l,c){try{const u=hx.create(n,r);l(e(u,t,r))}catch(u){c(u)}})}try{const l=hx.create(n,r);i(null,e(l,t,r))}catch(l){i(l)}}Pu.create=hx.create;Pu.toCanvas=Jy.bind(null,a5.render);Pu.toDataURL=Jy.bind(null,a5.renderToDataURL);Pu.toString=Jy.bind(null,function(e,t,n){return nre.render(e,n)});const e1=qM,rre=KM,l5=g.forwardRef(({className:e,...t},n)=>h.jsx(jy,{ref:n,className:ne("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));l5.displayName=jy.displayName;const Pp=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(rre,{children:[h.jsx(l5,{}),h.jsxs(Ly,{ref:r,className:ne("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(GM,{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(Rn,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Pp.displayName=Ly.displayName;const Ip=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-col space-y-1.5 text-left",e),...t});Ip.displayName="DialogHeader";const t1=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-row justify-end gap-2",e),...t});t1.displayName="DialogFooter";const Rp=g.forwardRef(({className:e,...t},n)=>h.jsx(Dy,{ref:n,className:ne("text-lg font-semibold leading-none text-text-100",e),...t}));Rp.displayName=Dy.displayName;const c5=g.forwardRef(({className:e,...t},n)=>h.jsx(Oy,{ref:n,className:ne("text-sm text-text-300",e),...t}));c5.displayName=Oy.displayName;function ire({persona:e,open:t,onClose:n,onTogglePublic:r,guestShareUrl:i,onChangeIcon:s,onDelete:o,embedded:a,onLoadPersonality:l,onSavePersonality:c,onDirtyChange:u,initialPersonality:d,onShareCapability:f,readOnly:p=!1,onChangeTool:m,larkBot:v}){const[b,x]=g.useState(!1),[_,y]=g.useState(!1),w=()=>{i&&navigator.clipboard.writeText(i).then(()=>{y(!0),setTimeout(()=>y(!1),2e3)})},S=N=>{x(N),u==null||u(N)},C=()=>{b&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!a&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:C,"aria-hidden":"true"}),h.jsxs("aside",{className:a?"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(Qz,{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:C,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(Rn,{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(yz,{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(xz,{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:[f?h.jsxs("button",{type:"button",onClick:f,"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(E_,{className:"h-3.5 w-3.5"}),"分享"]}):null,o?h.jsx("button",{type:"button",onClick:o,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(N_,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),r?h.jsxs(h.Fragment,{children:[h.jsxs("section",{className:"flex items-center justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"公开访问"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"开启后这个 persona 才会出现在「邀请联系人」的可选列表里。关闭即拒所有新分享(已颁出的 token 不受影响)。"})]}),h.jsx(cre,{checked:e.public??!1,onChange:N=>r(N)})]}),e.public?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"guest-share-link",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(CT,{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:"访客分享链接"})]}),i?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("input",{readOnly:!0,value:i,onFocus:N=>N.currentTarget.select(),className:"min-w-0 flex-1 truncate rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"guest-share-link-input"}),h.jsx("button",{type:"button",onClick:w,className:"flex shrink-0 items-center gap-1 rounded border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200","data-testid":"guest-share-link-copy",children:_?h.jsxs(h.Fragment,{children:[h.jsx(ol,{className:"h-3 w-3"})," 已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(mu,{className:"h-3 w-3"})," 复制"]})})]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"任何 TTC 员工打开此链接(飞书登录)即可在该 persona 下交互。"})]}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"guest-share-link-no-tunnel",children:"需先开启 tunnel(公网访问)才能生成可分享给外部的链接。"})]}):null,h.jsx("hr",{className:"border-border"})]}):null,v?h.jsxs(h.Fragment,{children:[h.jsx(lre,{...v}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs("section",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"默认图标"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"新建该 persona 的 session 会默认继承此图标。"}),h.jsx(HI,{value:e.iconKey??null,onChange:s,tool:e.tool})]}):null,s?h.jsx("hr",{className:"border-border"}):null,m&&!p?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"Agent"}),h.jsx("div",{className:"flex gap-2",children:["claude","codex"].map(N=>h.jsx("button",{type:"button","data-testid":`persona-edit-tool-${N}`,onClick:()=>m(N),className:ne("flex-1 rounded-md border px-3 py-2 text-[12px]",(e.tool??"claude")===N?"border-accent bg-accent/10 text-accent":"border-bg-300 text-text-300"),children:N==="claude"?"Claude Code":"Codex"},N))}),h.jsx("span",{className:"text-[11px] text-text-400",children:"切换只影响之后新建的会话,已有会话保持原 tool。"})]}),h.jsx("hr",{className:"border-border"})]}):null,l?h.jsxs(h.Fragment,{children:[h.jsx(fre,{onLoad:l,...c?{onSave:c}:{},onDirtyChange:S,initialPersonality:d,readOnly:p}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(ure,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(dre,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(hre,{plugins:e.plugins??[]})]})]})]}):null}function sre({qrUrl:e,busy:t,onCancel:n}){const[r,i]=g.useState(null);return g.useEffect(()=>{let s=!1;return Pu.toDataURL(e,{width:240,margin:1}).then(o=>{s||i(o)}).catch(()=>{s||i(null)}),()=>{s=!0}},[e]),h.jsx(e1,{open:!0,onOpenChange:s=>s||n==null?void 0:n(),children:h.jsxs(Pp,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",children:[h.jsx(Ip,{children:h.jsx(Rp,{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 ore={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},are=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function lre({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=_=>{_&&(o(!0),l(null),_().catch(y=>l(y instanceof Error?y.message:String(y))).finally(()=>o(!1)))},b=()=>{m(null),v(t)},x=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(Yf,{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:[x,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:ore[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[are.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(sre,{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:_=>u(_.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:_=>f(_.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(_=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",_.chatName??_.chatId]},_.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:[x,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function cre({checked:e,onChange:t}){return h.jsx("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(!e),"data-testid":"persona-public-toggle",className:ne("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e?"bg-success":"bg-bg-300"),children:h.jsx("span",{className:ne("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5")})})}function ure({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(Id,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(Id,{label:"沙箱启用",value:mg((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(Id,{label:"沙箱内自动放行 Bash",value:mg((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(Id,{label:"允许非沙箱命令",value:mg((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(zl,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(zl,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(zl,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(zl,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(zl,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function mg(e){return e===!0?"是":e===!1?"否":"—"}function Id({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 zl({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 dre({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 hre({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 fre({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,x]=g.useState(null),_=st.useRef(e),y=st.useRef(t),w=st.useRef(n);st.useEffect(()=>{_.current=e,y.current=t,w.current=n});const S=st.useCallback(()=>{a(!1),p(null),_.current().then(L=>{c(L),d(L),a(!0)}).catch(L=>{p(L instanceof Error?L.message:String(L))})},[]);st.useEffect(()=>{s||S()},[s,S]);const C=!i&&o&&u!==l;st.useEffect(()=>{i||w.current(C)},[C,i]);const N=()=>{y.current&&(v(!0),x(null),y.current(u).then(()=>{c(u),v(!1)}).catch(L=>{x(L instanceof Error?L.message:String(L)),v(!1)}))},T=()=>{d(l),x(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:L=>d(L.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 pre={state:"unbound",groups:[]};function mre(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(pre)}};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 gre({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const{persona:l}=_T(e),c=g6(e),u=v6(),d=x6(),{httpBaseUrl:f}=Xf(),p=$i(),m=mre(a==="guest"?null:p,e),v=g.useMemo(()=>!(l!=null&&l.public)||!f||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(f)?null:`${f}/s/${e}`,[l==null?void 0:l.public,f,e]),b=g.useCallback(N=>{u(e,{public:N}).catch(T=>{Re("persona","togglePublic failed",T)})},[u,e]),x=g.useCallback(N=>{u(e,{iconKey:N}).catch(T=>{Re("persona","changeIcon failed",T)})},[u,e]),_=g.useCallback(N=>{u(e,{tool:N}).catch(T=>{Re("persona","changeTool failed",T)})},[u,e]),y=g.useCallback(()=>{l&&confirm(`删除 persona "${l.label}"?`)&&(d(e).catch(N=>{Re("persona","delete failed",N)}),n())},[l,d,e,n]),w=g.useCallback(async()=>c.loaded?c.personality:(await c.refresh()).personality,[c]),S=g.useCallback(async N=>{await u(e,{personality:N}),await c.refresh()},[u,e,c]);if(!l)return null;const C=a==="guest";return h.jsx(ire,{embedded:i,persona:{...l,skills:c.skills,plugins:c.plugins,sandboxSettings:c.sandboxSettings},open:t,onClose:n,onLoadPersonality:w,onDirtyChange:s,readOnly:C,...C?{}:{onTogglePublic:b,guestShareUrl:v,onChangeIcon:x,onChangeTool:_,onDelete:y,onSavePersonality:S,larkBot:{status:m.status,onProvision:m.provision,onCancelProvision:m.cancelProvision,onBindManual:m.bindManual,onUnbind:m.unbind},...o?{onShareCapability:o}:{}}})}function vre({api:e,open:t,onOpenChange:n,personaId:r,personaName:i,viewerRole:s}){return t?h.jsxs("div",{"data-testid":"persona-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-[420px] flex-col border-l border-border bg-elevated shadow-2xl",children:[h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[13px] font-semibold text-text-100",children:[h.jsx(T_,{className:"h-4 w-4 shrink-0"}),h.jsxs("span",{className:"truncate",title:i,children:["Persona · ",i]})]}),h.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-bg-200 hover:text-text-100","aria-label":"Close drawer",children:h.jsx(Rn,{className:"h-4 w-4"})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:h.jsx(gre,{personaId:r,open:!0,onClose:()=>n(!1),api:e,embedded:!0,...s?{viewerRole:s}:{}},r)})]}):null}function xre(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 _re(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 n1(e,t,n,r,i){const s=await e.attachmentSignUrl({sessionId:n,relPath:r,...i!==void 0?{ttlSeconds:i}:{}});return _re(s.url,xre(t.url))}async function yre(e,t,n,r,i=60){const s=window.open("about:blank","_blank");try{const o=await n1(e,t,n,r,i);s?s.location.href=o:window.open(o,"_blank")}catch(o){throw s&&s.close(),o}}async function bre(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 wre={...tu,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 Sre(e){const t=e.split("/");return t[t.length-1]||e}function u5({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:Sre(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(Qc,{remarkPlugins:[eu],components:wre,children:i})}):null})]})}function kre({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(u5,{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(CT,{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(Rn,{className:"h-4 w-4"})})]})})}):null}function Cre({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 Ere=6173,Nre=6182;function Tre({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=Ere;v<=Nre;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(e1,{open:e,onOpenChange:t,children:h.jsxs(Pp,{className:"max-w-md",children:[h.jsxs(Ip,{children:[h.jsxs(Rp,{children:["改端口 · ",n]}),h.jsxs(c5,{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(t1,{children:[h.jsx(ri,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ri,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const kC=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function Pre({currentStage:e,onCancel:t}){const n=kC.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:[kC.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(Zf,{className:"size-3.5"}):o?h.jsx(rr,{className:"size-3.5 animate-spin"}):h.jsx(wT,{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 Ire={build:"构建",deploy:"部署",verify:"验证"};function Rre({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(Uc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",Ire[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 Mre={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function Are({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(js,{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:["[",Mre[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(Rn,{className:"size-3.5"})})]})}const CC={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function jre({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(Hc,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(II,{children:[h.jsx(RI,{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(Yz,{className:"size-3.5"})})}),h.jsxs(Y_,{align:"end",children:[h.jsx(eo,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(eo,{disabled:!0,title:"rename not supported yet",onSelect:y=>y.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(Are,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((x=e.publishJob)==null?void 0:x.status)==="in-flight"?h.jsx(Pre,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((_=e.publishJob)==null?void 0:_.status)==="interrupted"?h.jsx(Rre,{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(Lre,{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(EC,{label:"等 tunnel 起来…",step:"-"}):h.jsx(EC,{label:CC[m].label,step:CC[m].step})}),h.jsx(Tre,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async y=>{await r(y)}})]})}function EC({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(rr,{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 Lre({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(js,{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 Dre({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(e1,{open:!!e,onOpenChange:s=>{s||(r(!1),t())},children:h.jsxs(Pp,{className:"max-w-lg",children:[h.jsx(Ip,{children:h.jsx(Rp,{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(t1,{children:[h.jsx(ri,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(ol,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(mu,{className:"size-3.5"}),"复制"]})}),h.jsx(ri,{onClick:t,children:"关闭"})]})]})})}function Ore(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 Bre={codex:"on-request",claude:"bypassPermissions"};function zre(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??Bre[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function $re(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...zre({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=>Re("quick-ask","fork rollback failed",o)),s}return i}async function Fre(e,t,n){return $re(e,t,n,{ephemeral:!0})}function Rd(e){return e!=null&&e.ephemeral!==!1}async function Hre(e,t){return!t.stillEphemeral||!t.nextHold?!1:(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0)}const Ure=300;function Wre(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function d5(e,t){const n=l_(),[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=Wre(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(()=>{})},Ure)},[n,e]);return g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),{initialSize:r??t,setSize:o,loading:r===null}}function Vre(){return{quickAsk:null,mds:[],active:null}}function qre(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function Kre(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function Gre(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 Xre(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function Yre(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 Zre(e,t){return{...e,active:t}}function Qre(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function h5(e){return e.quickAsk!==null||e.mds.length>0}function Jre(e){return e.split("/").pop()||e}function eie({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onToggleHold:a,holdIds:l}){if(!h5(e))return null;const c=[];e.quickAsk&&c.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(qh,{className:"w-3.5 h-3.5"})});for(const u of e.mds)c.push({id:{kind:"md",relPath:u},label:Jre(u),title:u,icon:h.jsx(Ls,{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(Q_,{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:c.map(u=>{const d=Qre(e.active,u.id),f=u.id==="quick-ask"?"quick-ask":`md:${u.id.relPath}`;return h.jsxs(J_,{children:[h.jsx(ey,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":d,"data-tab-title":u.title,onClick:()=>n(u.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",d?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[u.icon,h.jsx("span",{className:"truncate",children:u.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${u.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",d?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:p=>{p.stopPropagation(),u.id==="quick-ask"?r():i(u.id.relPath)},children:h.jsx(Rn,{className:"w-3 h-3"})}),d?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(hp,{side:"bottom",align:"start",className:"max-w-sm break-all",children:u.title})]},f)})})}),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(nie,{session:o,api:t,holdIds:l,...a?{onToggleHold:a}:{}})}):null,e.mds.map(u=>{const d=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===u;return h.jsx("div",{className:"absolute inset-0",style:{display:d?"block":"none"},children:h.jsx(u5,{relPath:u,loadMarkdown:s,showTitleBar:!1})},`md-body:${u}`)})]})]})}function tie({state:e,extras:t}){const{api:n,session:r,holdIds:i,onToggleHold:s}=t,o=$i(),[a,l]=g.useState(Vre()),c=g.useRef(a);c.current=a;const u=g.useRef(!1),d=g.useCallback(async N=>{const T=c.current.quickAsk,L=await Fre(n,r,N);if(L){if(u.current){n.sessionDelete(L.sessionId).catch(()=>{});return}Rd(T)&&n.sessionDelete(T.sessionId).catch(()=>{}),l(P=>qre(P,{sessionId:L.sessionId}))}},[n,r]),f=g.useCallback(async(N,T)=>{const L=c.current.quickAsk,P=(L==null?void 0:L.sessionId)===N;try{await Hre(n,{sessionId:N,stillEphemeral:P&&Rd(L),nextHold:T})&&l(R=>Xre(R))}catch(O){Re("quick-ask","promote failed",O);return}s==null||s(N,T)},[n,s]),p=g.useCallback(N=>{l(T=>Kre(T,N))},[]),m=g.useCallback(N=>{l(T=>Zre(T,N))},[]),v=g.useCallback(()=>{const N=c.current.quickAsk;Rd(N)&&n.sessionDelete(N.sessionId).catch(()=>{}),l(T=>Gre(T))},[n]),b=g.useCallback(N=>{l(T=>Yre(T,N))},[]);g.useEffect(()=>()=>{u.current=!0;const N=c.current.quickAsk;Rd(N)&&n.sessionDelete(N.sessionId).catch(()=>{})},[]);const x=oi("sessions")??[],_=a.quickAsk?x.find(N=>N.sessionId===a.quickAsk.sessionId)??{sessionId:a.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,y=g.useCallback(async N=>{const T=await n1(n,o,r.sessionId,N,60),L=await fetch(T);if(!L.ok)throw new Error(`fetch ${L.status} ${L.statusText}`);return L.text()},[n,o,r.sessionId]),w=h.jsx(r1,{state:e,extras:t,onQuickAskInternal:d,onPreviewMdInternal:p}),{initialSize:S,setSize:C}=d5("chat-panel-right-slot-width",480);return h5(a)?h.jsxs(cy,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Yc,{id:"chat",minSize:"400px",children:w}),h.jsx(dy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Yc,{id:"right-slot",defaultSize:`${S}px`,minSize:"360px",maxSize:"800px",onResize:N=>C(N.inPixels),children:h.jsx(eie,{state:a,api:n,onSwitchTab:m,onCloseQuickAsk:v,onCloseMd:b,loadMarkdown:y,quickAskSession:_,holdIds:i,onToggleHold:f})})]}):w}function nie({session:e,api:t,holdIds:n,onToggleHold:r}){const i=VA(e.sessionId);return h.jsx(r1,{state:i,extras:{session:e,api:t,holdIds:n,...r?{onToggleHold:r}:{}}})}function rie({extras:e}){const t=VA(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(r1,{state:t,extras:e});return h.jsx(iie,{state:t,chat:n,extras:e})}return h.jsx(tie,{state:t,extras:e})}function iie({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(L=>c(L.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(L=>f(L.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const O=P;O!=null&&O.project&&(O.project.name===a&&c(O.project),f(R=>{const I=R.findIndex(z=>z.name===O.project.name);if(I<0)return[...R,O.project];const D=R.slice();return D[I]=O.project,D}))}),[i,a]);const{host:m,scheme:v}=Ore(i.url,r==null?void 0:r.tunnelUrl),[b,x]=g.useState(void 0),[_,y]=g.useState(null);g.useEffect(()=>{const L=i.on("appBuilder:publish-progress",O=>{const R=O;!R||R.name!==a||R.status==="started"&&x(R.stage)}),P=i.on("appBuilder:publish-failed",O=>{const R=O;!R||R.name!==a||(x(void 0),y({stage:R.stage}))});return()=>{L(),P()}},[i,a]),g.useEffect(()=>{x(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(L){S({title:"发布请求失败",message:(L==null?void 0:L.message)??String(L)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(Cre,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(jre,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(L=>L.port),onUpdatePort:async L=>{await s.appBuilderUpdateProjectPort(a,L),p()},publishSlot:C,publishInFlightStage:b,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(L){S({title:"取消发布失败",message:(L==null?void 0:L.message)??String(L)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(L){S({title:"重新发布失败",message:(L==null?void 0:L.message)??String(L)})}},publishFailureBanner:_,onPublishFailureBannerClose:()=>y(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(Dre,{error:w,onClose:()=>S(null)})]})}function sie({headerMeta:e,connState:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onOpenConfig:s,onForceStop:o,cronActiveCount:a,onCronClick:l,lines:c,pendingPermissions:u,procAlive:d,rewindableUserMessageIds:f,onPermissionRespond:p,onPermissionInterrupt:m,onRewind:v,onFork:b,onQuickAsk:x,topSlot:_,realtimeQuestionAnswers:y,onSubmitQuestion:w,onCancelQuestion:S,liveQuestionToolUseIds:C,api:N,cwd:T,tool:L,sessionKey:P,onSend:O,awaitingUser:R,onAbort:I,onNewSession:D,onClearSession:z,chatRootRef:$,chatBodyRef:F,topSentinelRef:j,drawers:B,xtermSlot:E,fileSharingScope:H,onShareFile:q,onOpenInTab:M,onPreviewMarkdown:re,onOpenFiles:oe,onTogglePin:V,isHolded:pe,onToggleHold:Oe,personaName:ie,onOpenPersona:Ae}){return h.jsx(NZ,{children:h.jsxs("div",{ref:$,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(xQ,{meta:e,...L?{tool:L}:{},connState:t,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},...s?{onOpenConfig:s}:{},...o?{onForceStop:o}:{},cronActiveCount:a,...l?{onCronClick:l}:{},...oe?{onOpenFiles:oe}:{},...V?{onTogglePin:V}:{},isHolded:pe??!1,...Oe?{onToggleHold:Oe}:{},...ie?{personaName:ie}:{},...Ae?{onOpenPersona:Ae}:{}}),h.jsxs("div",{ref:F,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[j?h.jsx("div",{ref:j,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx(CM,{lines:c,...p?{onPermissionRespond:p}:{},...m&&d?{onPermissionInterrupt:m}:{},topSlot:_,...v?{onRewind:v}:{},rewindableUserMessageIds:f,...b?{onFork:b}:{},...x?{onQuickAsk:x}:{},realtimeQuestionAnswers:y,onSubmitQuestion:w,...S?{onCancelQuestion:S}:{},liveQuestionToolUseIds:C,...H?{fileSharingScope:H}:{},...q?{onShareFile:q}:{},...M?{onOpenInTab:M}:{},...re?{onPreviewMarkdown:re}:{}})]}),E,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(gQ,{meta:e,...N?{api:N}:{},cwd:T,...L?{tool:L}:{},sessionKey:P,onSend:O,awaitingUser:R,...I?{onAbort:I}:{},...D?{onNewSession:D}:{},...z?{onClearSession:z}:{}}),B]})})}function r1({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,models:o,liveGitBranch:a,liveWorktreeRoot:l,onNewSession:c,onTurnEnd:u,onOpenConfig:d,onFork:f,onQuickAsk:p,viewerRole:m,holdIds:v,onToggleHold:b}=t,{capabilities:x}=Gy(i.tool||"claude"),_=(x==null?void 0:x.features)??pT(i.tool),[y,w]=g.useState(null),[S,C]=g.useState(!1),[N,T]=g.useState(!1),L=Xf(),P=!!s&&L.actionsLevel==="owner"&&_.fileSharing,O=_T(i.ownerPersonaId??null).persona,R=(O==null?void 0:O.label)??null,I=!!R&&!!i.ownerPersonaId,D=g.useCallback(()=>{T(!1),C(!0)},[]),z=g.useCallback(()=>{C(!1),T(!0)},[]),$=g.useCallback((Z,xe)=>{w({kind:Z,text:xe}),setTimeout(()=>{w(ye=>(ye==null?void 0:ye.text)===xe?null:ye)},2e3)},[]),F=$i(),j=KB(),B=WA(i.sessionId,i.toolSessionId),{events:E,pendingQuestions:H,clearQuestion:q,markQuestionSubmitted:M,status:re}=B,oe=e.historyLoading,V=JM(re);g.useEffect(()=>{Re("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:re,procAlive:V})},[re,V,i.sessionId]);const pe=e.lines,Oe=e.pendingPermissions,ie=Oe[0]??null,Ae=g.useMemo(()=>AU(E),[E]),[Fe,We]=g.useState(!1),[ge,qe]=g.useState(null),[Gt,wt]=g.useState(()=>new Set);IU(s,i.sessionId,i.toolSessionId,_.observe);const Rt=g.useRef(i.sessionId);g.useEffect(()=>{if(Rt.current=i.sessionId,!_.rewind){qe(null);return}let Z=!1;return qe(null),(async()=>{try{const xe=await s.sessionRewindableMessageIds(i.sessionId);if(Z)return;qe(new Set(xe.userMessageIds))}catch{Z||qe(null)}})(),()=>{Z=!0}},[s,i.sessionId,_.rewind]);const ln=g.useCallback(()=>{const Z=i.sessionId;s.sessionRewindableMessageIds(Z).then(xe=>{Rt.current===Z&&qe(new Set(xe.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),Bt=g.useMemo(()=>{if(ge!==null){const Ze=new Set(ge);for(const pi of Gt)Ze.delete(pi);return Ze}const Z=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),xe=new Set;let ye=null;for(const Ze of pe)Ze.kind==="user-text"?ye=Ze.uuid??null:ye&&Ze.kind==="tool-call"&&Z.has(Ze.tool)&&!Gt.has(ye)&&xe.add(ye);return xe},[pe,Gt,ge]),at=g.useRef(u);at.current=u,RU(i.sessionId,i.toolSessionId,()=>{pn(null),wt(new Set)});const Ue=VQ({sessionStatus:re}),nt=g.useRef(null);g.useEffect(()=>{var ye;const Z=nt.current,xe=(Z==null?void 0:Z.sid)===i.sessionId;xe&&Z.phase===Ue||(nt.current={sid:i.sessionId,phase:Ue},Re("session-phase",Ue,{sid:i.sessionId,phase:Ue,prev:xe?Z.phase:null,desc:WQ[Ue]}),xe&&Z.phase==="turn-running"&&Ue!=="turn-running"&&((ye=at.current)==null||ye.call(at),ln()))},[Ue,i.sessionId,ln]);const mt=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Xt,pn]=g.useState(null),U=g.useCallback(Z=>{pn(Z)},[]),[Q,ve]=g.useState(!1),Se=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),ve(!1)},[s,i.sessionId]),J=g.useCallback(Z=>{s.pinSession(i.sessionId,Z).catch(xe=>{Re("chat-panel","pinSession failed",{err:xe==null?void 0:xe.message})})},[s,i.sessionId]),Ye=(v==null?void 0:v.has(i.sessionId))??!1,Yt=g.useCallback(Z=>{b==null||b(i.sessionId,Z)},[b,i.sessionId]),Zt=g.useRef(0),ue=g.useRef(null);g.useEffect(()=>{const Z=xe=>{if(xe.key!=="Escape")return;if(!V){Zt.current=0;return}if(xe.isComposing)return;const Ze=xe.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==ue.current)return;const pi=Date.now();pi-Zt.current<2e3?(Zt.current=0,ve(!0)):(Zt.current=pi,mt())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[mt,V]);const Te=g.useRef(null),Je=g.useRef(null),Ln=g.useRef(!0),Qt=g.useRef(null),fl=g.useRef(0),Bo=g.useRef(0);g.useEffect(()=>{Ln.current=!0,Qt.current=null,fl.current=0,Bo.current=0},[i.sessionId]),g.useEffect(()=>{We(!1)},[i.sessionId]);const Ru=g.useRef(e);Ru.current=e;const Mu=g.useCallback(()=>{var ye;const Z=Te.current;if(!Z||Qt.current!==null)return;const xe=Ru.current;xe.historyDone||xe.historyLoading||(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop},(ye=xe.loadMoreHistory)==null||ye.call(xe))},[]);g.useEffect(()=>{const Z=Te.current,xe=Je.current;if(!Z||!xe)return;const ye=new IntersectionObserver(Ze=>{for(const pi of Ze)pi.isIntersecting&&Mu()},{root:Z,threshold:0});return ye.observe(xe),()=>ye.disconnect()},[Mu]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=150,ye=Ze=>{Date.now()<Bo.current&&(Ze.preventDefault(),Bo.current=Date.now()+xe)};return Z.addEventListener("wheel",ye,{passive:!1}),()=>Z.removeEventListener("wheel",ye)},[]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=32,ye=()=>{const Ze=Z.scrollHeight-Z.scrollTop-Z.clientHeight;Ln.current=Ze<=xe};return Z.addEventListener("scroll",ye,{passive:!0}),()=>Z.removeEventListener("scroll",ye)},[]),g.useLayoutEffect(()=>{const Z=Te.current;if(!Z)return;const xe=fl.current,ye=pe.length;fl.current=ye;const Ze=Qt.current;if(Ze!==null&&ye>xe){Qt.current=null,Z.scrollTop=Z.scrollHeight-Ze.distFromBottom,Bo.current=Date.now()+200;return}Ze!==null&&(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop}),Ln.current&&(Z.scrollTop=Z.scrollHeight)},[pe,ie==null?void 0:ie.requestId]);const Mp=g.useMemo(()=>{const Z={};for(const[xe,ye]of Object.entries(H))ye.submittedAnswers&&(Z[xe]=ye.submittedAnswers);return Z},[H]),Ap=g.useMemo(()=>new Set(Object.keys(H)),[H]),Au=g.useCallback(async(Z,xe)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:Z,answers:xe}),M(Z,xe)}catch{}},[s,i.sessionId,M]),zo=g.useCallback(async Z=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:Z}),q(Z)}catch{}},[s,i.sessionId,q]),$o=g.useCallback(async(Z,xe)=>{var ye;if(ie)try{await((ye=e.respondPermission)==null?void 0:ye.call(e,ie.requestId,Z?"allow":"deny"))}catch{}},[e,ie]),pl=g.useCallback(async()=>{const Z=i.sessionId;try{await s.sessionStop(Z)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(Z)},[e,s,i.sessionId]),ml=g.useMemo(()=>oe&&pe.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(rr,{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 Z;return void((Z=e.loadMoreHistory)==null?void 0:Z.call(e))},disabled:oe,"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:oe?"加载中…":"Load earlier messages"})}),[oe,pe.length,e.historyDone,e.loadMoreHistory]),qi=e.meta,Ki=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(kQ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Xt&&_.rewind?h.jsx(EQ,{open:!0,onOpenChange:Z=>{Z||pn(null)},api:s,sessionId:i.sessionId,userMessageId:Xt,lines:pe,procAlive:V,onNoChanges:Z=>{wt(xe=>{if(xe.has(Z))return xe;const ye=new Set(xe);return ye.add(Z),ye})}}):null,Q?h.jsx(oie,{onConfirm:Se,onCancel:()=>ve(!1)}):null,h.jsx(UQ,{open:Fe,onClose:()=>We(!1),jobs:Ae})]}),gl={kind:"session",sessionId:i.sessionId},ju=g.useCallback(async Z=>{if(s)try{await yre(s,F,i.sessionId,Z)}catch(xe){const ye=xe.message;Re("chat-panel","open-in-tab failed",{err:ye}),$("err",`Open in tab 失败:${ye}`)}},[s,F,i.sessionId,$]),[zt,vl]=g.useState(!1),[xl,Tt]=g.useState(null),$t=g.useCallback(Z=>{if(r){r(Z);return}Tt(Z),vl(!0)},[r]),ar=g.useCallback(async Z=>{if(!s)throw new Error("daemon api not ready");const xe=await n1(s,F,i.sessionId,Z,60),ye=await fetch(xe);if(!ye.ok)throw new Error(`fetch ${ye.status} ${ye.statusText}`);return await ye.text()},[s,F,i.sessionId]),Dn=g.useCallback(async(Z,xe)=>{if(s)try{const{url:ye}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:Z,ttlSeconds:86400,...xe?{view:xe}:{}}),Ze=await bre(ye);$(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(ye){const Ze=ye.message;Re("chat-panel","share-file failed",{err:Ze}),$("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,$]);return h.jsxs(h.Fragment,{children:[h.jsx(sie,{headerMeta:qi,connState:e.connState,...o?{models:o}:{},...a!==void 0?{liveGitBranch:a}:{},...l!==void 0?{liveWorktreeRoot:l}:{},...d?{onOpenConfig:d}:{},onForceStop:()=>ve(!0),cronActiveCount:Ae.length,onCronClick:()=>We(!0),lines:pe,pendingPermissions:Oe,procAlive:V,rewindableUserMessageIds:Bt,onPermissionRespond:$o,onPermissionInterrupt:mt,onRewind:_.rewind?U:void 0,...f&&_.fork?{onFork:f}:{},...n&&_.fork?{onQuickAsk:n}:p&&_.fork?{onQuickAsk:p}:{},topSlot:ml,realtimeQuestionAnswers:Mp,onSubmitQuestion:Au,onCancelQuestion:zo,liveQuestionToolUseIds:Ap,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:Oe.length>0||Object.values(H).some(Z=>!Z.submittedAnswers),onAbort:mt,...c?{onNewSession:c}:{},onClearSession:pl,chatRootRef:ue,chatBodyRef:Te,topSentinelRef:Je,drawers:Ki,xtermSlot:j==="tui"&&V&&_.tui?h.jsx(sne,{sessionId:i.sessionId,client:F},i.sessionId):null,fileSharingScope:gl,...s?{onShareFile:Dn}:{},...s?{onOpenInTab:ju}:{},...s?{onPreviewMarkdown:$t}:{},...P?{onOpenFiles:D}:{},onTogglePin:J,isHolded:Ye,...b?{onToggleHold:Yt}:{},...I?{personaName:R}:{},...I?{onOpenPersona:z}:{}}),P&&s?h.jsx(dne,{api:s,open:S,onOpenChange:C,scope:gl,sessionId:i.sessionId,onShareFile:Dn,onOpenInTab:ju}):null,s?h.jsx(kre,{open:zt,onOpenChange:vl,relPath:xl,loadMarkdown:ar,onShare:xl?()=>void Dn(xl,"md-rendered"):void 0}):null,I&&s&&i.ownerPersonaId?h.jsx(vre,{api:s,open:N,onOpenChange:T,personaId:i.ownerPersonaId,personaName:R??"",...m?{viewerRole:m}:{}}):null,y?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:y.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:y.text}):null]})}function oie({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(Uc,{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 aie(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 lie({current:e,models:t,onSelect:n}){return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Model"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-model-selector",children:t.map(r=>{const i=(e||"")===r.id;return h.jsx("button",{type:"button",onClick:()=>n(r.id),"data-testid":`config-model-${r.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",i?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:r.label},r.id||"default")})})]})}function cie({current:e,modes:t,onSelect:n}){var i;const r=(i=t.find(s=>s.id===(e||"")))==null?void 0:i.description;return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Permission Mode"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-mode-selector",children:t.map(s=>{const o=(e||"")===s.id;return h.jsx("button",{type:"button",onClick:()=>n(s.id),"data-testid":`config-mode-${s.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",o?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:s.label},s.id||"default")})}),r?h.jsx("p",{className:"text-[11px] text-text-400 mt-1.5",children:r}):null]})}function uie({open:e,onOpenChange:t,session:n,onPatch:r,embedded:i=!1,viewerRole:s="owner"}){var m;const{capabilities:o}=Gy(e?n.tool||"claude":null),a=(o==null?void 0:o.models)??[],l=(o==null?void 0:o.permissionModes)??[],c=((m=o==null?void 0:o.configSchema.find(v=>v.name==="permissionMode"))==null?void 0:m.default)??"",u=n.permissionMode&&l.some(v=>v.id===n.permissionMode)?n.permissionMode:c,d=g.useMemo(()=>(o==null?void 0:o.configSchema.filter(v=>v.scope==="tool-specific"))??[],[o]),f=(o==null?void 0:o.toolSessionIdLabel)??"Tool Session ID";if(!e)return null;const p=h.jsxs("div",{className:"flex-1 min-h-0 flex flex-col px-4 py-4 gap-6 overflow-y-auto",children:[h.jsxs("div",{className:"shrink-0",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:"Working Directory"}),h.jsx("div",{className:"text-[12px] font-mono text-text-300 bg-bg-100 rounded-lg px-3 py-2 truncate","data-testid":"config-cwd",title:n.cwd,children:n.cwd})]}),h.jsx("div",{className:"shrink-0",children:h.jsx(lie,{current:n.model??"",models:a,onSelect:v=>void r({model:v})})}),h.jsx("div",{className:"shrink-0",children:h.jsx(cie,{current:u,modes:l,onSelect:v=>void r({permissionMode:v})})}),d.length>0?h.jsx("div",{className:"shrink-0",children:h.jsx(die,{fields:d,models:a,session:n,onPatch:r})}):null,h.jsx("div",{className:"shrink-0",children:h.jsx(NC,{testId:"config-session-id",label:"Clawd Session ID",value:n.sessionId})}),n.toolSessionId?h.jsx("div",{className:"shrink-0",children:h.jsx(NC,{testId:"config-tool-session-id",label:f,value:n.toolSessionId})}):null]});return i?h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col",children:[h.jsx("div",{className:"flex items-center px-4 py-3 border-b border-bg-300/30 shrink-0",children:h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"})}),p]}):h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col border-l border-bg-300/40 bg-bg-0 min-w-0",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"config-drawer-close",className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":"Close",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),p]})}function NC({testId:e,label:t,value:n}){const[r,i]=g.useState(!1),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const o=()=>{typeof navigator>"u"||!navigator.clipboard||navigator.clipboard.writeText(n).then(()=>{i(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>i(!1),2e3)},()=>{})};return h.jsxs("div",{"data-testid":e,children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:t}),h.jsxs("button",{type:"button",onClick:o,"data-testid":`${e}-copy`,title:r?"Copied":`Copy: ${n}`,className:"w-full flex items-center gap-2 text-[12px] font-mono text-text-300 bg-bg-100 hover:bg-bg-200 rounded-lg px-3 py-2 transition-colors cursor-pointer text-left group",children:[h.jsx("span",{className:"truncate flex-1 min-w-0","data-testid":`${e}-value`,children:n}),r?h.jsx(ol,{className:"w-3.5 h-3.5 shrink-0 text-accent"}):h.jsx(mu,{className:"w-3.5 h-3.5 shrink-0 opacity-60 group-hover:opacity-100 transition-opacity"})]})]})}function die({fields:e,models:t,session:n,onPatch:r}){return h.jsxs("div",{"data-testid":"config-advanced",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Advanced"}),h.jsx("div",{className:"space-y-3",children:e.map(i=>h.jsx(hie,{field:i,models:t,session:n,onPatch:r},i.name))})]})}function hie({field:e,models:t,session:n,onPatch:r}){const i=e.name==="effort"?aie(n.model??"",t,[e]):{options:e.options??[],defaultValue:e.default??""},s=i.options;if(e.type!=="select"||s.length===0)return null;const o=n[e.name]??"",a=s.some(l=>l.value===o)?o:i.defaultValue;return h.jsxs("div",{"data-testid":`config-advanced-${e.name}`,children:[h.jsx("div",{className:"text-[11px] text-text-400 mb-1.5",children:e.label}),h.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>{const c=a===l.value;return h.jsx("button",{type:"button","data-testid":`config-advanced-${e.name}-${l.value||"default"}`,onClick:()=>void r({[e.name]:l.value}),className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",c?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:l.label},l.value||"default")})})]})}function fie(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 pie(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 mie({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onConfigPatch:l,onFork:c,onQuickAsk:u,className:d,viewerRole:f="owner",holdIds:p,onToggleHold:m}){const{capabilities:v}=Gy(t.tool),[b,x]=g.useState(0),[_,y]=g.useState(!1),{initialSize:w,setSize:S}=d5("clawd:panel:config-px",360),{branch:C}=fie(e,t.cwd,b),{worktreeRoot:N}=pie(e,t.cwd,b),T=r>1,L=P=>{P==="desktop"?y(!0):a()};return h.jsxs("div",{className:`group/pane relative flex-1 ${d??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${T?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsxs(cy,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Yc,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(gie,{api:e,session:t,models:v==null?void 0:v.models,liveGitBranch:C,liveWorktreeRoot:N,onNewSession:o,onTurnEnd:()=>x(P=>P+1),onOpenConfig:L,onFork:c,onQuickAsk:u,viewerRole:f,holdIds:p,onToggleHold:m})})}),_&&h.jsxs(h.Fragment,{children:[h.jsx(dy,{className:"hidden md:block w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Yc,{id:"config",defaultSize:`${w}px`,minSize:"360px",maxSize:"560px",onResize:P=>S(P.inPixels),children:h.jsx("div",{className:"hidden md:flex h-full",children:h.jsx(uie,{open:_,onOpenChange:y,session:t,onPatch:l,viewerRole:f})})})]})]}),T&&h.jsx("button",{type:"button",onClick:P=>{P.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(Rn,{className:"w-3.5 h-3.5"})})]})}function gie({api:e,session:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onNewSession:s,onTurnEnd:o,onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:u,holdIds:d,onToggleHold:f}){return h.jsx(rie,{extras:{session:t,api:e,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},onNewSession:s,onTurnEnd:o,onOpenConfig:a,...l?{onFork:p=>{l(p)}}:{},...c?{onQuickAsk:p=>{c(p)}}:{},...u?{viewerRole:u}:{},...d?{holdIds:d}:{},...f?{onToggleHold:f}:{}}})}function vie({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,onConfigPatch:p}){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(GH,{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(mie,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},onConfigPatch:p,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 xie(){const e=$i(),t=g.useMemo(()=>new k_(e),[e]),n=p6(e),{sessions:r,refresh:i}=m6(n),{personas:s}=xT(),o=b6(),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]),x=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(S=>S===w?null:S)},[t,i]),_=g.useCallback(async(w,S)=>{await t.sessionUpdate(w,{label:S.label,iconKey:S.iconKey===null?"":S.iconKey}),await i()},[t,i]),y=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(C_.Provider,{value:o,children:h.jsx(vie,{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 x(w),onEditSession:(w,S)=>void _(w,S),onCloseSession:()=>v(null),onConfigPatch:async()=>{}})})}const TC="https://app.ttcadvisory.com";function _ie({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=`${TC}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==TC)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 fx="clawd-visitor:token";function yie(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function bie(){return{async getUrl(e){const t=localStorage.getItem(fx);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=yie(window.location,{});return await cT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function wie(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Sie(){const e=$i(),t=g.useMemo(()=>f6(e),[e]);return h.jsx(GB,{cache:t.cache,children:h.jsx(ZB,{children:h.jsx(xie,{})})})}function kie({host:e}){const[t]=g.useState(()=>localStorage.getItem(fx)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>wie(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return bie().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(xb,{host:e,children:h.jsx(Zb,{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(qB,{host:e,children:h.jsx(Sie,{})}):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(xb,{host:e,children:h.jsx(Zb,{children:h.jsx(_ie,{onAuthed:o=>{localStorage.setItem(fx,o),window.location.reload()}})})})}function Cie({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):Eie(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:ne("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 Eie(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 Nie({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(Tie,{status:t.status}),h.jsx("span",{className:ne("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 Tie({status:e}){return e==="completed"?h.jsx(Zf,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(rr,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(wT,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function Pie(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 Iie({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(Yf,{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 Rie(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 Mie={render:({input:e})=>st.createElement(Nie,{items:Pie(e)})},Aie={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=Rie(e);return st.createElement(Iie,{description:t,prompt:n,subagentType:r})}},f5={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Lie(e),c=l?st.createElement(Cie,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return st.createElement(_M,{tool:jie(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function jie(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Lie(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}}ku.register("claude","TodoWrite",Mie);ku.register("claude","Task",Aie);ku.register("claude","Edit",f5);ku.register("claude","Write",f5);const p5=document.getElementById("root");if(!p5)throw new Error("guest-main: #root not found");const Die=G4({});gg.createRoot(p5).render(h.jsx(st.StrictMode,{children:h.jsx(kie,{host:Die})}));
|
|
569
|
+
`;return typeof r=="function"&&r(null,f),f};const tre=gne,hx=qA,a5=s5,nre=o5;function Jy(e,t,n,r,i){const s=[].slice.call(arguments,1),o=s.length,a=typeof s[o-1]=="function";if(!a&&!tre())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(i=n,n=t,t=r=void 0):o===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=n,n=t,t=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(n=t,t=r=void 0):o===2&&!t.getContext&&(r=n,n=t,t=void 0),new Promise(function(l,c){try{const u=hx.create(n,r);l(e(u,t,r))}catch(u){c(u)}})}try{const l=hx.create(n,r);i(null,e(l,t,r))}catch(l){i(l)}}Pu.create=hx.create;Pu.toCanvas=Jy.bind(null,a5.render);Pu.toDataURL=Jy.bind(null,a5.renderToDataURL);Pu.toString=Jy.bind(null,function(e,t,n){return nre.render(e,n)});const e1=qM,rre=KM,l5=g.forwardRef(({className:e,...t},n)=>h.jsx(jy,{ref:n,className:ne("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));l5.displayName=jy.displayName;const Pp=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(rre,{children:[h.jsx(l5,{}),h.jsxs(Ly,{ref:r,className:ne("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(GM,{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(Rn,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Pp.displayName=Ly.displayName;const Ip=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-col space-y-1.5 text-left",e),...t});Ip.displayName="DialogHeader";const t1=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-row justify-end gap-2",e),...t});t1.displayName="DialogFooter";const Rp=g.forwardRef(({className:e,...t},n)=>h.jsx(Dy,{ref:n,className:ne("text-lg font-semibold leading-none text-text-100",e),...t}));Rp.displayName=Dy.displayName;const c5=g.forwardRef(({className:e,...t},n)=>h.jsx(Oy,{ref:n,className:ne("text-sm text-text-300",e),...t}));c5.displayName=Oy.displayName;function ire({persona:e,open:t,onClose:n,onTogglePublic:r,guestShareUrl:i,onChangeIcon:s,onDelete:o,embedded:a,onLoadPersonality:l,onSavePersonality:c,onDirtyChange:u,initialPersonality:d,onShareCapability:f,readOnly:p=!1,onChangeTool:m,larkBot:v}){const[b,x]=g.useState(!1),[_,y]=g.useState(!1),w=()=>{i&&navigator.clipboard.writeText(i).then(()=>{y(!0),setTimeout(()=>y(!1),2e3)})},S=N=>{x(N),u==null||u(N)},C=()=>{b&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!a&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:C,"aria-hidden":"true"}),h.jsxs("aside",{className:a?"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(Qz,{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:C,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(Rn,{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(yz,{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(xz,{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:[f?h.jsxs("button",{type:"button",onClick:f,"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(E_,{className:"h-3.5 w-3.5"}),"分享"]}):null,o?h.jsx("button",{type:"button",onClick:o,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(N_,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),r?h.jsxs(h.Fragment,{children:[h.jsxs("section",{className:"flex items-center justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"公开访问"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"开启后这个 persona 才会出现在「邀请联系人」的可选列表里。关闭即拒所有新分享(已颁出的 token 不受影响)。"})]}),h.jsx(cre,{checked:e.public??!1,onChange:N=>r(N)})]}),e.public?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"guest-share-link",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(CT,{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:"访客分享链接"})]}),i?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("input",{readOnly:!0,value:i,onFocus:N=>N.currentTarget.select(),className:"min-w-0 flex-1 truncate rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"guest-share-link-input"}),h.jsx("button",{type:"button",onClick:w,className:"flex shrink-0 items-center gap-1 rounded border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200","data-testid":"guest-share-link-copy",children:_?h.jsxs(h.Fragment,{children:[h.jsx(ol,{className:"h-3 w-3"})," 已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(mu,{className:"h-3 w-3"})," 复制"]})})]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"任何 TTC 员工打开此链接(飞书登录)即可在该 persona 下交互。"})]}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"guest-share-link-no-tunnel",children:"需先开启 tunnel(公网访问)才能生成可分享给外部的链接。"})]}):null,h.jsx("hr",{className:"border-border"})]}):null,v?h.jsxs(h.Fragment,{children:[h.jsx(lre,{...v}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs("section",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"默认图标"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"新建该 persona 的 session 会默认继承此图标。"}),h.jsx(HI,{value:e.iconKey??null,onChange:s,tool:e.tool})]}):null,s?h.jsx("hr",{className:"border-border"}):null,m&&!p?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"Agent"}),h.jsx("div",{className:"flex gap-2",children:["claude","codex"].map(N=>h.jsx("button",{type:"button","data-testid":`persona-edit-tool-${N}`,onClick:()=>m(N),className:ne("flex-1 rounded-md border px-3 py-2 text-[12px]",(e.tool??"claude")===N?"border-accent bg-accent/10 text-accent":"border-bg-300 text-text-300"),children:N==="claude"?"Claude Code":"Codex"},N))}),h.jsx("span",{className:"text-[11px] text-text-400",children:"切换只影响之后新建的会话,已有会话保持原 tool。"})]}),h.jsx("hr",{className:"border-border"})]}):null,l?h.jsxs(h.Fragment,{children:[h.jsx(fre,{onLoad:l,...c?{onSave:c}:{},onDirtyChange:S,initialPersonality:d,readOnly:p}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(ure,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(dre,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(hre,{plugins:e.plugins??[]})]})]})]}):null}function sre({qrUrl:e,busy:t,onCancel:n}){const[r,i]=g.useState(null);return g.useEffect(()=>{let s=!1;return Pu.toDataURL(e,{width:240,margin:1}).then(o=>{s||i(o)}).catch(()=>{s||i(null)}),()=>{s=!0}},[e]),h.jsx(e1,{open:!0,onOpenChange:s=>s||n==null?void 0:n(),children:h.jsxs(Pp,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",onInteractOutside:s=>s.preventDefault(),onEscapeKeyDown:s=>s.preventDefault(),children:[h.jsx(Ip,{children:h.jsx(Rp,{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 ore={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},are=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function lre({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=_=>{_&&(o(!0),l(null),_().catch(y=>l(y instanceof Error?y.message:String(y))).finally(()=>o(!1)))},b=()=>{m(null),v(t)},x=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(Yf,{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:[x,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:ore[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[are.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(sre,{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:_=>u(_.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:_=>f(_.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(_=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",_.chatName??_.chatId]},_.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:[x,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function cre({checked:e,onChange:t}){return h.jsx("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(!e),"data-testid":"persona-public-toggle",className:ne("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e?"bg-success":"bg-bg-300"),children:h.jsx("span",{className:ne("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5")})})}function ure({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(Id,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(Id,{label:"沙箱启用",value:mg((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(Id,{label:"沙箱内自动放行 Bash",value:mg((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(Id,{label:"允许非沙箱命令",value:mg((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(zl,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(zl,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(zl,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(zl,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(zl,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function mg(e){return e===!0?"是":e===!1?"否":"—"}function Id({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 zl({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 dre({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 hre({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 fre({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,x]=g.useState(null),_=st.useRef(e),y=st.useRef(t),w=st.useRef(n);st.useEffect(()=>{_.current=e,y.current=t,w.current=n});const S=st.useCallback(()=>{a(!1),p(null),_.current().then(L=>{c(L),d(L),a(!0)}).catch(L=>{p(L instanceof Error?L.message:String(L))})},[]);st.useEffect(()=>{s||S()},[s,S]);const C=!i&&o&&u!==l;st.useEffect(()=>{i||w.current(C)},[C,i]);const N=()=>{y.current&&(v(!0),x(null),y.current(u).then(()=>{c(u),v(!1)}).catch(L=>{x(L instanceof Error?L.message:String(L)),v(!1)}))},T=()=>{d(l),x(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:L=>d(L.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 pre={state:"unbound",groups:[]};function mre(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(pre)}};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 gre({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const{persona:l}=_T(e),c=g6(e),u=v6(),d=x6(),{httpBaseUrl:f}=Xf(),p=$i(),m=mre(a==="guest"?null:p,e),v=g.useMemo(()=>!(l!=null&&l.public)||!f||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(f)?null:`${f}/s/${e}`,[l==null?void 0:l.public,f,e]),b=g.useCallback(N=>{u(e,{public:N}).catch(T=>{Re("persona","togglePublic failed",T)})},[u,e]),x=g.useCallback(N=>{u(e,{iconKey:N}).catch(T=>{Re("persona","changeIcon failed",T)})},[u,e]),_=g.useCallback(N=>{u(e,{tool:N}).catch(T=>{Re("persona","changeTool failed",T)})},[u,e]),y=g.useCallback(()=>{l&&confirm(`删除 persona "${l.label}"?`)&&(d(e).catch(N=>{Re("persona","delete failed",N)}),n())},[l,d,e,n]),w=g.useCallback(async()=>c.loaded?c.personality:(await c.refresh()).personality,[c]),S=g.useCallback(async N=>{await u(e,{personality:N}),await c.refresh()},[u,e,c]);if(!l)return null;const C=a==="guest";return h.jsx(ire,{embedded:i,persona:{...l,skills:c.skills,plugins:c.plugins,sandboxSettings:c.sandboxSettings},open:t,onClose:n,onLoadPersonality:w,onDirtyChange:s,readOnly:C,...C?{}:{onTogglePublic:b,guestShareUrl:v,onChangeIcon:x,onChangeTool:_,onDelete:y,onSavePersonality:S,larkBot:{status:m.status,onProvision:m.provision,onCancelProvision:m.cancelProvision,onBindManual:m.bindManual,onUnbind:m.unbind},...o?{onShareCapability:o}:{}}})}function vre({api:e,open:t,onOpenChange:n,personaId:r,personaName:i,viewerRole:s}){return t?h.jsxs("div",{"data-testid":"persona-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-[420px] flex-col border-l border-border bg-elevated shadow-2xl",children:[h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[13px] font-semibold text-text-100",children:[h.jsx(T_,{className:"h-4 w-4 shrink-0"}),h.jsxs("span",{className:"truncate",title:i,children:["Persona · ",i]})]}),h.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-bg-200 hover:text-text-100","aria-label":"Close drawer",children:h.jsx(Rn,{className:"h-4 w-4"})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:h.jsx(gre,{personaId:r,open:!0,onClose:()=>n(!1),api:e,embedded:!0,...s?{viewerRole:s}:{}},r)})]}):null}function xre(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 _re(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 n1(e,t,n,r,i){const s=await e.attachmentSignUrl({sessionId:n,relPath:r,...i!==void 0?{ttlSeconds:i}:{}});return _re(s.url,xre(t.url))}async function yre(e,t,n,r,i=60){const s=window.open("about:blank","_blank");try{const o=await n1(e,t,n,r,i);s?s.location.href=o:window.open(o,"_blank")}catch(o){throw s&&s.close(),o}}async function bre(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 wre={...tu,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 Sre(e){const t=e.split("/");return t[t.length-1]||e}function u5({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:Sre(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(Qc,{remarkPlugins:[eu],components:wre,children:i})}):null})]})}function kre({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(u5,{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(CT,{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(Rn,{className:"h-4 w-4"})})]})})}):null}function Cre({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 Ere=6173,Nre=6182;function Tre({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=Ere;v<=Nre;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(e1,{open:e,onOpenChange:t,children:h.jsxs(Pp,{className:"max-w-md",children:[h.jsxs(Ip,{children:[h.jsxs(Rp,{children:["改端口 · ",n]}),h.jsxs(c5,{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(t1,{children:[h.jsx(ri,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ri,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const kC=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function Pre({currentStage:e,onCancel:t}){const n=kC.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:[kC.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(Zf,{className:"size-3.5"}):o?h.jsx(rr,{className:"size-3.5 animate-spin"}):h.jsx(wT,{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 Ire={build:"构建",deploy:"部署",verify:"验证"};function Rre({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(Uc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",Ire[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 Mre={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function Are({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(js,{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:["[",Mre[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(Rn,{className:"size-3.5"})})]})}const CC={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function jre({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(Hc,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(II,{children:[h.jsx(RI,{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(Yz,{className:"size-3.5"})})}),h.jsxs(Y_,{align:"end",children:[h.jsx(eo,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(eo,{disabled:!0,title:"rename not supported yet",onSelect:y=>y.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(Are,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((x=e.publishJob)==null?void 0:x.status)==="in-flight"?h.jsx(Pre,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((_=e.publishJob)==null?void 0:_.status)==="interrupted"?h.jsx(Rre,{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(Lre,{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(EC,{label:"等 tunnel 起来…",step:"-"}):h.jsx(EC,{label:CC[m].label,step:CC[m].step})}),h.jsx(Tre,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async y=>{await r(y)}})]})}function EC({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(rr,{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 Lre({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(js,{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 Dre({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(e1,{open:!!e,onOpenChange:s=>{s||(r(!1),t())},children:h.jsxs(Pp,{className:"max-w-lg",children:[h.jsx(Ip,{children:h.jsx(Rp,{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(t1,{children:[h.jsx(ri,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(ol,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(mu,{className:"size-3.5"}),"复制"]})}),h.jsx(ri,{onClick:t,children:"关闭"})]})]})})}function Ore(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 Bre={codex:"on-request",claude:"bypassPermissions"};function zre(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??Bre[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function $re(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...zre({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=>Re("quick-ask","fork rollback failed",o)),s}return i}async function Fre(e,t,n){return $re(e,t,n,{ephemeral:!0})}function Rd(e){return e!=null&&e.ephemeral!==!1}async function Hre(e,t){return!t.stillEphemeral||!t.nextHold?!1:(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0)}const Ure=300;function Wre(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function d5(e,t){const n=l_(),[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=Wre(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(()=>{})},Ure)},[n,e]);return g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),{initialSize:r??t,setSize:o,loading:r===null}}function Vre(){return{quickAsk:null,mds:[],active:null}}function qre(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function Kre(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function Gre(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 Xre(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function Yre(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 Zre(e,t){return{...e,active:t}}function Qre(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function h5(e){return e.quickAsk!==null||e.mds.length>0}function Jre(e){return e.split("/").pop()||e}function eie({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onToggleHold:a,holdIds:l}){if(!h5(e))return null;const c=[];e.quickAsk&&c.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(qh,{className:"w-3.5 h-3.5"})});for(const u of e.mds)c.push({id:{kind:"md",relPath:u},label:Jre(u),title:u,icon:h.jsx(Ls,{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(Q_,{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:c.map(u=>{const d=Qre(e.active,u.id),f=u.id==="quick-ask"?"quick-ask":`md:${u.id.relPath}`;return h.jsxs(J_,{children:[h.jsx(ey,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":d,"data-tab-title":u.title,onClick:()=>n(u.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",d?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[u.icon,h.jsx("span",{className:"truncate",children:u.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${u.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",d?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:p=>{p.stopPropagation(),u.id==="quick-ask"?r():i(u.id.relPath)},children:h.jsx(Rn,{className:"w-3 h-3"})}),d?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(hp,{side:"bottom",align:"start",className:"max-w-sm break-all",children:u.title})]},f)})})}),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(nie,{session:o,api:t,holdIds:l,...a?{onToggleHold:a}:{}})}):null,e.mds.map(u=>{const d=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===u;return h.jsx("div",{className:"absolute inset-0",style:{display:d?"block":"none"},children:h.jsx(u5,{relPath:u,loadMarkdown:s,showTitleBar:!1})},`md-body:${u}`)})]})]})}function tie({state:e,extras:t}){const{api:n,session:r,holdIds:i,onToggleHold:s}=t,o=$i(),[a,l]=g.useState(Vre()),c=g.useRef(a);c.current=a;const u=g.useRef(!1),d=g.useCallback(async N=>{const T=c.current.quickAsk,L=await Fre(n,r,N);if(L){if(u.current){n.sessionDelete(L.sessionId).catch(()=>{});return}Rd(T)&&n.sessionDelete(T.sessionId).catch(()=>{}),l(P=>qre(P,{sessionId:L.sessionId}))}},[n,r]),f=g.useCallback(async(N,T)=>{const L=c.current.quickAsk,P=(L==null?void 0:L.sessionId)===N;try{await Hre(n,{sessionId:N,stillEphemeral:P&&Rd(L),nextHold:T})&&l(R=>Xre(R))}catch(O){Re("quick-ask","promote failed",O);return}s==null||s(N,T)},[n,s]),p=g.useCallback(N=>{l(T=>Kre(T,N))},[]),m=g.useCallback(N=>{l(T=>Zre(T,N))},[]),v=g.useCallback(()=>{const N=c.current.quickAsk;Rd(N)&&n.sessionDelete(N.sessionId).catch(()=>{}),l(T=>Gre(T))},[n]),b=g.useCallback(N=>{l(T=>Yre(T,N))},[]);g.useEffect(()=>()=>{u.current=!0;const N=c.current.quickAsk;Rd(N)&&n.sessionDelete(N.sessionId).catch(()=>{})},[]);const x=oi("sessions")??[],_=a.quickAsk?x.find(N=>N.sessionId===a.quickAsk.sessionId)??{sessionId:a.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,y=g.useCallback(async N=>{const T=await n1(n,o,r.sessionId,N,60),L=await fetch(T);if(!L.ok)throw new Error(`fetch ${L.status} ${L.statusText}`);return L.text()},[n,o,r.sessionId]),w=h.jsx(r1,{state:e,extras:t,onQuickAskInternal:d,onPreviewMdInternal:p}),{initialSize:S,setSize:C}=d5("chat-panel-right-slot-width",480);return h5(a)?h.jsxs(cy,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Yc,{id:"chat",minSize:"400px",children:w}),h.jsx(dy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Yc,{id:"right-slot",defaultSize:`${S}px`,minSize:"360px",maxSize:"800px",onResize:N=>C(N.inPixels),children:h.jsx(eie,{state:a,api:n,onSwitchTab:m,onCloseQuickAsk:v,onCloseMd:b,loadMarkdown:y,quickAskSession:_,holdIds:i,onToggleHold:f})})]}):w}function nie({session:e,api:t,holdIds:n,onToggleHold:r}){const i=VA(e.sessionId);return h.jsx(r1,{state:i,extras:{session:e,api:t,holdIds:n,...r?{onToggleHold:r}:{}}})}function rie({extras:e}){const t=VA(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(r1,{state:t,extras:e});return h.jsx(iie,{state:t,chat:n,extras:e})}return h.jsx(tie,{state:t,extras:e})}function iie({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(L=>c(L.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(L=>f(L.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const O=P;O!=null&&O.project&&(O.project.name===a&&c(O.project),f(R=>{const I=R.findIndex(z=>z.name===O.project.name);if(I<0)return[...R,O.project];const D=R.slice();return D[I]=O.project,D}))}),[i,a]);const{host:m,scheme:v}=Ore(i.url,r==null?void 0:r.tunnelUrl),[b,x]=g.useState(void 0),[_,y]=g.useState(null);g.useEffect(()=>{const L=i.on("appBuilder:publish-progress",O=>{const R=O;!R||R.name!==a||R.status==="started"&&x(R.stage)}),P=i.on("appBuilder:publish-failed",O=>{const R=O;!R||R.name!==a||(x(void 0),y({stage:R.stage}))});return()=>{L(),P()}},[i,a]),g.useEffect(()=>{x(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(L){S({title:"发布请求失败",message:(L==null?void 0:L.message)??String(L)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(Cre,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(jre,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(L=>L.port),onUpdatePort:async L=>{await s.appBuilderUpdateProjectPort(a,L),p()},publishSlot:C,publishInFlightStage:b,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(L){S({title:"取消发布失败",message:(L==null?void 0:L.message)??String(L)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(L){S({title:"重新发布失败",message:(L==null?void 0:L.message)??String(L)})}},publishFailureBanner:_,onPublishFailureBannerClose:()=>y(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(Dre,{error:w,onClose:()=>S(null)})]})}function sie({headerMeta:e,connState:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onOpenConfig:s,onForceStop:o,cronActiveCount:a,onCronClick:l,lines:c,pendingPermissions:u,procAlive:d,rewindableUserMessageIds:f,onPermissionRespond:p,onPermissionInterrupt:m,onRewind:v,onFork:b,onQuickAsk:x,topSlot:_,realtimeQuestionAnswers:y,onSubmitQuestion:w,onCancelQuestion:S,liveQuestionToolUseIds:C,api:N,cwd:T,tool:L,sessionKey:P,onSend:O,awaitingUser:R,onAbort:I,onNewSession:D,onClearSession:z,chatRootRef:$,chatBodyRef:F,topSentinelRef:j,drawers:B,xtermSlot:E,fileSharingScope:H,onShareFile:q,onOpenInTab:M,onPreviewMarkdown:re,onOpenFiles:oe,onTogglePin:V,isHolded:pe,onToggleHold:Oe,personaName:ie,onOpenPersona:Ae}){return h.jsx(NZ,{children:h.jsxs("div",{ref:$,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(xQ,{meta:e,...L?{tool:L}:{},connState:t,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},...s?{onOpenConfig:s}:{},...o?{onForceStop:o}:{},cronActiveCount:a,...l?{onCronClick:l}:{},...oe?{onOpenFiles:oe}:{},...V?{onTogglePin:V}:{},isHolded:pe??!1,...Oe?{onToggleHold:Oe}:{},...ie?{personaName:ie}:{},...Ae?{onOpenPersona:Ae}:{}}),h.jsxs("div",{ref:F,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[j?h.jsx("div",{ref:j,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx(CM,{lines:c,...p?{onPermissionRespond:p}:{},...m&&d?{onPermissionInterrupt:m}:{},topSlot:_,...v?{onRewind:v}:{},rewindableUserMessageIds:f,...b?{onFork:b}:{},...x?{onQuickAsk:x}:{},realtimeQuestionAnswers:y,onSubmitQuestion:w,...S?{onCancelQuestion:S}:{},liveQuestionToolUseIds:C,...H?{fileSharingScope:H}:{},...q?{onShareFile:q}:{},...M?{onOpenInTab:M}:{},...re?{onPreviewMarkdown:re}:{}})]}),E,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(gQ,{meta:e,...N?{api:N}:{},cwd:T,...L?{tool:L}:{},sessionKey:P,onSend:O,awaitingUser:R,...I?{onAbort:I}:{},...D?{onNewSession:D}:{},...z?{onClearSession:z}:{}}),B]})})}function r1({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,models:o,liveGitBranch:a,liveWorktreeRoot:l,onNewSession:c,onTurnEnd:u,onOpenConfig:d,onFork:f,onQuickAsk:p,viewerRole:m,holdIds:v,onToggleHold:b}=t,{capabilities:x}=Gy(i.tool||"claude"),_=(x==null?void 0:x.features)??pT(i.tool),[y,w]=g.useState(null),[S,C]=g.useState(!1),[N,T]=g.useState(!1),L=Xf(),P=!!s&&L.actionsLevel==="owner"&&_.fileSharing,O=_T(i.ownerPersonaId??null).persona,R=(O==null?void 0:O.label)??null,I=!!R&&!!i.ownerPersonaId,D=g.useCallback(()=>{T(!1),C(!0)},[]),z=g.useCallback(()=>{C(!1),T(!0)},[]),$=g.useCallback((Z,xe)=>{w({kind:Z,text:xe}),setTimeout(()=>{w(ye=>(ye==null?void 0:ye.text)===xe?null:ye)},2e3)},[]),F=$i(),j=KB(),B=WA(i.sessionId,i.toolSessionId),{events:E,pendingQuestions:H,clearQuestion:q,markQuestionSubmitted:M,status:re}=B,oe=e.historyLoading,V=JM(re);g.useEffect(()=>{Re("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:re,procAlive:V})},[re,V,i.sessionId]);const pe=e.lines,Oe=e.pendingPermissions,ie=Oe[0]??null,Ae=g.useMemo(()=>AU(E),[E]),[Fe,We]=g.useState(!1),[ge,qe]=g.useState(null),[Gt,wt]=g.useState(()=>new Set);IU(s,i.sessionId,i.toolSessionId,_.observe);const Rt=g.useRef(i.sessionId);g.useEffect(()=>{if(Rt.current=i.sessionId,!_.rewind){qe(null);return}let Z=!1;return qe(null),(async()=>{try{const xe=await s.sessionRewindableMessageIds(i.sessionId);if(Z)return;qe(new Set(xe.userMessageIds))}catch{Z||qe(null)}})(),()=>{Z=!0}},[s,i.sessionId,_.rewind]);const ln=g.useCallback(()=>{const Z=i.sessionId;s.sessionRewindableMessageIds(Z).then(xe=>{Rt.current===Z&&qe(new Set(xe.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),Bt=g.useMemo(()=>{if(ge!==null){const Ze=new Set(ge);for(const pi of Gt)Ze.delete(pi);return Ze}const Z=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),xe=new Set;let ye=null;for(const Ze of pe)Ze.kind==="user-text"?ye=Ze.uuid??null:ye&&Ze.kind==="tool-call"&&Z.has(Ze.tool)&&!Gt.has(ye)&&xe.add(ye);return xe},[pe,Gt,ge]),at=g.useRef(u);at.current=u,RU(i.sessionId,i.toolSessionId,()=>{pn(null),wt(new Set)});const Ue=VQ({sessionStatus:re}),nt=g.useRef(null);g.useEffect(()=>{var ye;const Z=nt.current,xe=(Z==null?void 0:Z.sid)===i.sessionId;xe&&Z.phase===Ue||(nt.current={sid:i.sessionId,phase:Ue},Re("session-phase",Ue,{sid:i.sessionId,phase:Ue,prev:xe?Z.phase:null,desc:WQ[Ue]}),xe&&Z.phase==="turn-running"&&Ue!=="turn-running"&&((ye=at.current)==null||ye.call(at),ln()))},[Ue,i.sessionId,ln]);const mt=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Xt,pn]=g.useState(null),U=g.useCallback(Z=>{pn(Z)},[]),[Q,ve]=g.useState(!1),Se=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),ve(!1)},[s,i.sessionId]),J=g.useCallback(Z=>{s.pinSession(i.sessionId,Z).catch(xe=>{Re("chat-panel","pinSession failed",{err:xe==null?void 0:xe.message})})},[s,i.sessionId]),Ye=(v==null?void 0:v.has(i.sessionId))??!1,Yt=g.useCallback(Z=>{b==null||b(i.sessionId,Z)},[b,i.sessionId]),Zt=g.useRef(0),ue=g.useRef(null);g.useEffect(()=>{const Z=xe=>{if(xe.key!=="Escape")return;if(!V){Zt.current=0;return}if(xe.isComposing)return;const Ze=xe.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==ue.current)return;const pi=Date.now();pi-Zt.current<2e3?(Zt.current=0,ve(!0)):(Zt.current=pi,mt())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[mt,V]);const Te=g.useRef(null),Je=g.useRef(null),Ln=g.useRef(!0),Qt=g.useRef(null),fl=g.useRef(0),Bo=g.useRef(0);g.useEffect(()=>{Ln.current=!0,Qt.current=null,fl.current=0,Bo.current=0},[i.sessionId]),g.useEffect(()=>{We(!1)},[i.sessionId]);const Ru=g.useRef(e);Ru.current=e;const Mu=g.useCallback(()=>{var ye;const Z=Te.current;if(!Z||Qt.current!==null)return;const xe=Ru.current;xe.historyDone||xe.historyLoading||(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop},(ye=xe.loadMoreHistory)==null||ye.call(xe))},[]);g.useEffect(()=>{const Z=Te.current,xe=Je.current;if(!Z||!xe)return;const ye=new IntersectionObserver(Ze=>{for(const pi of Ze)pi.isIntersecting&&Mu()},{root:Z,threshold:0});return ye.observe(xe),()=>ye.disconnect()},[Mu]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=150,ye=Ze=>{Date.now()<Bo.current&&(Ze.preventDefault(),Bo.current=Date.now()+xe)};return Z.addEventListener("wheel",ye,{passive:!1}),()=>Z.removeEventListener("wheel",ye)},[]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=32,ye=()=>{const Ze=Z.scrollHeight-Z.scrollTop-Z.clientHeight;Ln.current=Ze<=xe};return Z.addEventListener("scroll",ye,{passive:!0}),()=>Z.removeEventListener("scroll",ye)},[]),g.useLayoutEffect(()=>{const Z=Te.current;if(!Z)return;const xe=fl.current,ye=pe.length;fl.current=ye;const Ze=Qt.current;if(Ze!==null&&ye>xe){Qt.current=null,Z.scrollTop=Z.scrollHeight-Ze.distFromBottom,Bo.current=Date.now()+200;return}Ze!==null&&(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop}),Ln.current&&(Z.scrollTop=Z.scrollHeight)},[pe,ie==null?void 0:ie.requestId]);const Mp=g.useMemo(()=>{const Z={};for(const[xe,ye]of Object.entries(H))ye.submittedAnswers&&(Z[xe]=ye.submittedAnswers);return Z},[H]),Ap=g.useMemo(()=>new Set(Object.keys(H)),[H]),Au=g.useCallback(async(Z,xe)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:Z,answers:xe}),M(Z,xe)}catch{}},[s,i.sessionId,M]),zo=g.useCallback(async Z=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:Z}),q(Z)}catch{}},[s,i.sessionId,q]),$o=g.useCallback(async(Z,xe)=>{var ye;if(ie)try{await((ye=e.respondPermission)==null?void 0:ye.call(e,ie.requestId,Z?"allow":"deny"))}catch{}},[e,ie]),pl=g.useCallback(async()=>{const Z=i.sessionId;try{await s.sessionStop(Z)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(Z)},[e,s,i.sessionId]),ml=g.useMemo(()=>oe&&pe.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(rr,{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 Z;return void((Z=e.loadMoreHistory)==null?void 0:Z.call(e))},disabled:oe,"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:oe?"加载中…":"Load earlier messages"})}),[oe,pe.length,e.historyDone,e.loadMoreHistory]),qi=e.meta,Ki=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(kQ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Xt&&_.rewind?h.jsx(EQ,{open:!0,onOpenChange:Z=>{Z||pn(null)},api:s,sessionId:i.sessionId,userMessageId:Xt,lines:pe,procAlive:V,onNoChanges:Z=>{wt(xe=>{if(xe.has(Z))return xe;const ye=new Set(xe);return ye.add(Z),ye})}}):null,Q?h.jsx(oie,{onConfirm:Se,onCancel:()=>ve(!1)}):null,h.jsx(UQ,{open:Fe,onClose:()=>We(!1),jobs:Ae})]}),gl={kind:"session",sessionId:i.sessionId},ju=g.useCallback(async Z=>{if(s)try{await yre(s,F,i.sessionId,Z)}catch(xe){const ye=xe.message;Re("chat-panel","open-in-tab failed",{err:ye}),$("err",`Open in tab 失败:${ye}`)}},[s,F,i.sessionId,$]),[zt,vl]=g.useState(!1),[xl,Tt]=g.useState(null),$t=g.useCallback(Z=>{if(r){r(Z);return}Tt(Z),vl(!0)},[r]),ar=g.useCallback(async Z=>{if(!s)throw new Error("daemon api not ready");const xe=await n1(s,F,i.sessionId,Z,60),ye=await fetch(xe);if(!ye.ok)throw new Error(`fetch ${ye.status} ${ye.statusText}`);return await ye.text()},[s,F,i.sessionId]),Dn=g.useCallback(async(Z,xe)=>{if(s)try{const{url:ye}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:Z,ttlSeconds:86400,...xe?{view:xe}:{}}),Ze=await bre(ye);$(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(ye){const Ze=ye.message;Re("chat-panel","share-file failed",{err:Ze}),$("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,$]);return h.jsxs(h.Fragment,{children:[h.jsx(sie,{headerMeta:qi,connState:e.connState,...o?{models:o}:{},...a!==void 0?{liveGitBranch:a}:{},...l!==void 0?{liveWorktreeRoot:l}:{},...d?{onOpenConfig:d}:{},onForceStop:()=>ve(!0),cronActiveCount:Ae.length,onCronClick:()=>We(!0),lines:pe,pendingPermissions:Oe,procAlive:V,rewindableUserMessageIds:Bt,onPermissionRespond:$o,onPermissionInterrupt:mt,onRewind:_.rewind?U:void 0,...f&&_.fork?{onFork:f}:{},...n&&_.fork?{onQuickAsk:n}:p&&_.fork?{onQuickAsk:p}:{},topSlot:ml,realtimeQuestionAnswers:Mp,onSubmitQuestion:Au,onCancelQuestion:zo,liveQuestionToolUseIds:Ap,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:Oe.length>0||Object.values(H).some(Z=>!Z.submittedAnswers),onAbort:mt,...c?{onNewSession:c}:{},onClearSession:pl,chatRootRef:ue,chatBodyRef:Te,topSentinelRef:Je,drawers:Ki,xtermSlot:j==="tui"&&V&&_.tui?h.jsx(sne,{sessionId:i.sessionId,client:F},i.sessionId):null,fileSharingScope:gl,...s?{onShareFile:Dn}:{},...s?{onOpenInTab:ju}:{},...s?{onPreviewMarkdown:$t}:{},...P?{onOpenFiles:D}:{},onTogglePin:J,isHolded:Ye,...b?{onToggleHold:Yt}:{},...I?{personaName:R}:{},...I?{onOpenPersona:z}:{}}),P&&s?h.jsx(dne,{api:s,open:S,onOpenChange:C,scope:gl,sessionId:i.sessionId,onShareFile:Dn,onOpenInTab:ju}):null,s?h.jsx(kre,{open:zt,onOpenChange:vl,relPath:xl,loadMarkdown:ar,onShare:xl?()=>void Dn(xl,"md-rendered"):void 0}):null,I&&s&&i.ownerPersonaId?h.jsx(vre,{api:s,open:N,onOpenChange:T,personaId:i.ownerPersonaId,personaName:R??"",...m?{viewerRole:m}:{}}):null,y?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:y.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:y.text}):null]})}function oie({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(Uc,{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 aie(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 lie({current:e,models:t,onSelect:n}){return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Model"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-model-selector",children:t.map(r=>{const i=(e||"")===r.id;return h.jsx("button",{type:"button",onClick:()=>n(r.id),"data-testid":`config-model-${r.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",i?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:r.label},r.id||"default")})})]})}function cie({current:e,modes:t,onSelect:n}){var i;const r=(i=t.find(s=>s.id===(e||"")))==null?void 0:i.description;return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Permission Mode"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-mode-selector",children:t.map(s=>{const o=(e||"")===s.id;return h.jsx("button",{type:"button",onClick:()=>n(s.id),"data-testid":`config-mode-${s.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",o?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:s.label},s.id||"default")})}),r?h.jsx("p",{className:"text-[11px] text-text-400 mt-1.5",children:r}):null]})}function uie({open:e,onOpenChange:t,session:n,onPatch:r,embedded:i=!1,viewerRole:s="owner"}){var m;const{capabilities:o}=Gy(e?n.tool||"claude":null),a=(o==null?void 0:o.models)??[],l=(o==null?void 0:o.permissionModes)??[],c=((m=o==null?void 0:o.configSchema.find(v=>v.name==="permissionMode"))==null?void 0:m.default)??"",u=n.permissionMode&&l.some(v=>v.id===n.permissionMode)?n.permissionMode:c,d=g.useMemo(()=>(o==null?void 0:o.configSchema.filter(v=>v.scope==="tool-specific"))??[],[o]),f=(o==null?void 0:o.toolSessionIdLabel)??"Tool Session ID";if(!e)return null;const p=h.jsxs("div",{className:"flex-1 min-h-0 flex flex-col px-4 py-4 gap-6 overflow-y-auto",children:[h.jsxs("div",{className:"shrink-0",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:"Working Directory"}),h.jsx("div",{className:"text-[12px] font-mono text-text-300 bg-bg-100 rounded-lg px-3 py-2 truncate","data-testid":"config-cwd",title:n.cwd,children:n.cwd})]}),h.jsx("div",{className:"shrink-0",children:h.jsx(lie,{current:n.model??"",models:a,onSelect:v=>void r({model:v})})}),h.jsx("div",{className:"shrink-0",children:h.jsx(cie,{current:u,modes:l,onSelect:v=>void r({permissionMode:v})})}),d.length>0?h.jsx("div",{className:"shrink-0",children:h.jsx(die,{fields:d,models:a,session:n,onPatch:r})}):null,h.jsx("div",{className:"shrink-0",children:h.jsx(NC,{testId:"config-session-id",label:"Clawd Session ID",value:n.sessionId})}),n.toolSessionId?h.jsx("div",{className:"shrink-0",children:h.jsx(NC,{testId:"config-tool-session-id",label:f,value:n.toolSessionId})}):null]});return i?h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col",children:[h.jsx("div",{className:"flex items-center px-4 py-3 border-b border-bg-300/30 shrink-0",children:h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"})}),p]}):h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col border-l border-bg-300/40 bg-bg-0 min-w-0",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"config-drawer-close",className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":"Close",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),p]})}function NC({testId:e,label:t,value:n}){const[r,i]=g.useState(!1),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const o=()=>{typeof navigator>"u"||!navigator.clipboard||navigator.clipboard.writeText(n).then(()=>{i(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>i(!1),2e3)},()=>{})};return h.jsxs("div",{"data-testid":e,children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:t}),h.jsxs("button",{type:"button",onClick:o,"data-testid":`${e}-copy`,title:r?"Copied":`Copy: ${n}`,className:"w-full flex items-center gap-2 text-[12px] font-mono text-text-300 bg-bg-100 hover:bg-bg-200 rounded-lg px-3 py-2 transition-colors cursor-pointer text-left group",children:[h.jsx("span",{className:"truncate flex-1 min-w-0","data-testid":`${e}-value`,children:n}),r?h.jsx(ol,{className:"w-3.5 h-3.5 shrink-0 text-accent"}):h.jsx(mu,{className:"w-3.5 h-3.5 shrink-0 opacity-60 group-hover:opacity-100 transition-opacity"})]})]})}function die({fields:e,models:t,session:n,onPatch:r}){return h.jsxs("div",{"data-testid":"config-advanced",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Advanced"}),h.jsx("div",{className:"space-y-3",children:e.map(i=>h.jsx(hie,{field:i,models:t,session:n,onPatch:r},i.name))})]})}function hie({field:e,models:t,session:n,onPatch:r}){const i=e.name==="effort"?aie(n.model??"",t,[e]):{options:e.options??[],defaultValue:e.default??""},s=i.options;if(e.type!=="select"||s.length===0)return null;const o=n[e.name]??"",a=s.some(l=>l.value===o)?o:i.defaultValue;return h.jsxs("div",{"data-testid":`config-advanced-${e.name}`,children:[h.jsx("div",{className:"text-[11px] text-text-400 mb-1.5",children:e.label}),h.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>{const c=a===l.value;return h.jsx("button",{type:"button","data-testid":`config-advanced-${e.name}-${l.value||"default"}`,onClick:()=>void r({[e.name]:l.value}),className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",c?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:l.label},l.value||"default")})})]})}function fie(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 pie(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 mie({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onConfigPatch:l,onFork:c,onQuickAsk:u,className:d,viewerRole:f="owner",holdIds:p,onToggleHold:m}){const{capabilities:v}=Gy(t.tool),[b,x]=g.useState(0),[_,y]=g.useState(!1),{initialSize:w,setSize:S}=d5("clawd:panel:config-px",360),{branch:C}=fie(e,t.cwd,b),{worktreeRoot:N}=pie(e,t.cwd,b),T=r>1,L=P=>{P==="desktop"?y(!0):a()};return h.jsxs("div",{className:`group/pane relative flex-1 ${d??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${T?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsxs(cy,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Yc,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(gie,{api:e,session:t,models:v==null?void 0:v.models,liveGitBranch:C,liveWorktreeRoot:N,onNewSession:o,onTurnEnd:()=>x(P=>P+1),onOpenConfig:L,onFork:c,onQuickAsk:u,viewerRole:f,holdIds:p,onToggleHold:m})})}),_&&h.jsxs(h.Fragment,{children:[h.jsx(dy,{className:"hidden md:block w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Yc,{id:"config",defaultSize:`${w}px`,minSize:"360px",maxSize:"560px",onResize:P=>S(P.inPixels),children:h.jsx("div",{className:"hidden md:flex h-full",children:h.jsx(uie,{open:_,onOpenChange:y,session:t,onPatch:l,viewerRole:f})})})]})]}),T&&h.jsx("button",{type:"button",onClick:P=>{P.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(Rn,{className:"w-3.5 h-3.5"})})]})}function gie({api:e,session:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onNewSession:s,onTurnEnd:o,onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:u,holdIds:d,onToggleHold:f}){return h.jsx(rie,{extras:{session:t,api:e,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},onNewSession:s,onTurnEnd:o,onOpenConfig:a,...l?{onFork:p=>{l(p)}}:{},...c?{onQuickAsk:p=>{c(p)}}:{},...u?{viewerRole:u}:{},...d?{holdIds:d}:{},...f?{onToggleHold:f}:{}}})}function vie({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,onConfigPatch:p}){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(GH,{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(mie,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},onConfigPatch:p,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 xie(){const e=$i(),t=g.useMemo(()=>new k_(e),[e]),n=p6(e),{sessions:r,refresh:i}=m6(n),{personas:s}=xT(),o=b6(),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]),x=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(S=>S===w?null:S)},[t,i]),_=g.useCallback(async(w,S)=>{await t.sessionUpdate(w,{label:S.label,iconKey:S.iconKey===null?"":S.iconKey}),await i()},[t,i]),y=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(C_.Provider,{value:o,children:h.jsx(vie,{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 x(w),onEditSession:(w,S)=>void _(w,S),onCloseSession:()=>v(null),onConfigPatch:async()=>{}})})}const TC="https://app.ttcadvisory.com";function _ie({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=`${TC}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==TC)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 fx="clawd-visitor:token";function yie(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function bie(){return{async getUrl(e){const t=localStorage.getItem(fx);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=yie(window.location,{});return await cT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function wie(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Sie(){const e=$i(),t=g.useMemo(()=>f6(e),[e]);return h.jsx(GB,{cache:t.cache,children:h.jsx(ZB,{children:h.jsx(xie,{})})})}function kie({host:e}){const[t]=g.useState(()=>localStorage.getItem(fx)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>wie(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return bie().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(xb,{host:e,children:h.jsx(Zb,{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(qB,{host:e,children:h.jsx(Sie,{})}):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(xb,{host:e,children:h.jsx(Zb,{children:h.jsx(_ie,{onAuthed:o=>{localStorage.setItem(fx,o),window.location.reload()}})})})}function Cie({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):Eie(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:ne("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 Eie(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 Nie({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(Tie,{status:t.status}),h.jsx("span",{className:ne("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 Tie({status:e}){return e==="completed"?h.jsx(Zf,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(rr,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(wT,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function Pie(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 Iie({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(Yf,{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 Rie(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 Mie={render:({input:e})=>st.createElement(Nie,{items:Pie(e)})},Aie={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=Rie(e);return st.createElement(Iie,{description:t,prompt:n,subagentType:r})}},f5={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Lie(e),c=l?st.createElement(Cie,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return st.createElement(_M,{tool:jie(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function jie(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Lie(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}}ku.register("claude","TodoWrite",Mie);ku.register("claude","Task",Aie);ku.register("claude","Edit",f5);ku.register("claude","Write",f5);const p5=document.getElementById("root");if(!p5)throw new Error("guest-main: #root not found");const Die=G4({});gg.createRoot(p5).render(h.jsx(st.StrictMode,{children:h.jsx(kie,{host:Die})}));
|
package/dist/share-ui/guest.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Clawd 分享</title>
|
|
7
|
-
<script type="module" crossorigin src="/share-ui/assets/guest-
|
|
7
|
+
<script type="module" crossorigin src="/share-ui/assets/guest-BNecVsu7.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/share-ui/assets/guest-ExdV_CFe.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body style="margin: 0">
|