@clawos-dev/clawd 0.2.326 → 0.2.327
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.
|
@@ -551,4 +551,4 @@ Minimum version required to store current data is: `+s+`.
|
|
|
551
551
|
|
|
552
552
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
553
553
|
|
|
554
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return g.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},hre="DialogDescriptionWarning",fre=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${fA(hre).contentName}}.`;return g.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},pre=eA,mre=rA,pA=iA,mA=sA,gA=aA,vA=cA,gre=dA;const e1=pre,vre=mre,_A=g.forwardRef(({className:e,...t},n)=>h.jsx(pA,{ref:n,className:le("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));_A.displayName=pA.displayName;const Np=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(vre,{children:[h.jsx(_A,{}),h.jsxs(mA,{ref:r,className:le("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(gre,{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(br,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Np.displayName=mA.displayName;const Tp=({className:e,...t})=>h.jsx("div",{className:le("flex flex-col space-y-1.5 text-left",e),...t});Tp.displayName="DialogHeader";const t1=({className:e,...t})=>h.jsx("div",{className:le("flex flex-row justify-end gap-2",e),...t});t1.displayName="DialogFooter";const Pp=g.forwardRef(({className:e,...t},n)=>h.jsx(gA,{ref:n,className:le("text-lg font-semibold leading-none text-text-100",e),...t}));Pp.displayName=gA.displayName;const xA=g.forwardRef(({className:e,...t},n)=>h.jsx(vA,{ref:n,className:le("text-sm text-text-300",e),...t}));xA.displayName=vA.displayName;function _re({persona:e,open:t,onClose:n,onTogglePublic:r,guestShareUrl:i,onDelete:s,embedded:o,onLoadPersonality:a,onSavePersonality:l,onDirtyChange:c,initialPersonality:u,onShareCapability:d,readOnly:f=!1,onChangeTool:p,larkBot:m}){const[v,b]=g.useState(!1),[_,x]=g.useState(!1),y=()=>{i&&navigator.clipboard.writeText(i).then(()=>{x(!0),setTimeout(()=>x(!1),2e3)})},w=C=>{b(C),c==null||c(C)},S=()=>{v&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!o&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:S,"aria-hidden":"true"}),h.jsxs("aside",{className:o?"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(i$,{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:S,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(br,{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(Nz,{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(Cz,{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:[d?h.jsxs("button",{type:"button",onClick:d,"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(Rx,{className:"h-3.5 w-3.5"}),"分享"]}):null,s?h.jsx("button",{type:"button",onClick:s,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(Mx,{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(Sre,{checked:e.public??!1,onChange:C=>r(C)})]}),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(IT,{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:C=>C.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:y,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(To,{className:"h-3 w-3"})," 已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(pu,{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,m?h.jsxs(h.Fragment,{children:[h.jsx(wre,{...m}),h.jsx("hr",{className:"border-border"})]}):null,p&&!f?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(C=>h.jsx("button",{type:"button","data-testid":`persona-edit-tool-${C}`,onClick:()=>p(C),className:le("flex-1 rounded-md border px-3 py-2 text-[12px]",(e.tool??"claude")===C?"border-accent bg-accent/10 text-accent":"border-bg-300 text-text-300"),children:C==="claude"?"Claude Code":"Codex"},C))}),h.jsx("span",{className:"text-[11px] text-text-400",children:"切换只影响之后新建的会话,已有会话保持原 tool。"})]}),h.jsx("hr",{className:"border-border"})]}):null,a?h.jsxs(h.Fragment,{children:[h.jsx(Nre,{onLoad:a,...l?{onSave:l}:{},onDirtyChange:w,initialPersonality:u,readOnly:f}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(kre,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(Cre,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(Ere,{plugins:e.plugins??[]})]})]})]}):null}function xre({qrUrl:e,busy:t,onCancel:n}){const[r,i]=g.useState(null);return g.useEffect(()=>{let s=!1;return Iu.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(Np,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",onInteractOutside:s=>s.preventDefault(),onEscapeKeyDown:s=>s.preventDefault(),children:[h.jsx(Tp,{children:h.jsx(Pp,{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 yre={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},bre=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function wre({status:e,onProvision:t,onCancelProvision:n,onBindManual:r,onUnbind:i}){const[s,o]=g.useState(!1),[a,l]=g.useState(null),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,m]=g.useState(null),v=x=>{x&&(o(!0),l(null),x().catch(y=>l(y instanceof Error?y.message:String(y))).finally(()=>o(!1)))},b=()=>{m(null),v(t)},_=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(Kf,{className:"h-3.5 w-3.5 text-text-400","aria-hidden":!0}),h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"飞书 Bot"})]});return e?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,e.state==="unbound"||e.state==="provisioning"?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"关联一个飞书 bot 后,这个 persona 就是它:拉进群后群成员 @ 它提问、或直接私聊它, 推理跑在你本机,回复自动发回去。"}),t?h.jsx("button",{type:"button",disabled:s||e.state==="provisioning",onClick:b,className:"self-start rounded border border-border bg-bg-200 px-3 py-1.5 text-[12px] font-medium text-text-100 hover:bg-bg-300 disabled:opacity-50","data-testid":"lark-bot-provision",children:e.state==="provisioning"?"等待扫码…":"扫码关联飞书 Bot"}):null,e.state==="unbound"&&e.errorReason&&!p?h.jsxs("div",{className:"flex flex-col gap-1.5 rounded border border-error bg-error-dim px-2 py-1.5","data-testid":"lark-bot-provision-error",children:[h.jsx("span",{className:"text-[11px] text-error",children:yre[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[bre.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(xre,{qrUrl:e.qrUrl,busy:s,onCancel:n?()=>v(n):void 0}):null,r&&e.state==="unbound"?h.jsxs("details",{"data-testid":"lark-bot-manual-details",children:[h.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400 hover:text-text-300",children:"已有飞书应用?手动填入凭证"}),h.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),h.jsx("input",{value:c,onChange:x=>u(x.target.value),placeholder:"App ID(cli_ 开头)",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-appid"}),h.jsx("input",{value:d,onChange:x=>f(x.target.value),type:"password",placeholder:"App Secret",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-secret"}),h.jsx("button",{type:"button",disabled:s||!c||!d,onClick:()=>v(()=>r({appId:c,appSecret:d})),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-manual-submit",children:s?"绑定中…":"绑定"})]})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.state==="broken"?h.jsxs("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-broken",children:["Bot 凭证失效:",e.brokenReason??"未知原因","。请解绑后重新填入有效凭证绑定。"]}):null,h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-200",children:[h.jsx("span",{className:"font-medium text-text-100",children:e.botName??"未命名 bot"}),e.appId?h.jsx("span",{className:"text-[11px] text-text-400",children:e.appId}):null]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"把 bot 拉进任意飞书群,群成员 @ 它即可提问。"}),e.groups.length>0?h.jsx("ul",{className:"flex flex-col gap-0.5","data-testid":"lark-bot-groups",children:e.groups.map(x=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",x.chatName??x.chatId]},x.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),i?h.jsx("button",{type:"button",disabled:s,onClick:()=>v(i),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-error hover:bg-error-dim disabled:opacity-50","data-testid":"lark-bot-unbind",children:"解绑"}):null]}):null,a?h.jsx("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-error",children:a}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function Sre({checked:e,onChange:t}){return h.jsx("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(!e),"data-testid":"persona-public-toggle",className:le("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:le("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5")})})}function kre({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(Pd,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(Pd,{label:"沙箱启用",value:xg((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(Pd,{label:"沙箱内自动放行 Bash",value:xg((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(Pd,{label:"允许非沙箱命令",value:xg((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(Ol,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(Ol,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(Ol,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(Ol,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(Ol,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function xg(e){return e===!0?"是":e===!1?"否":"—"}function Pd({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 Ol({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 Cre({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 Ere({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 Nre({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1}){const s=r!==void 0,[o,a]=g.useState(s),[l,c]=g.useState(s?r:""),[u,d]=g.useState(s?r:""),[f,p]=g.useState(null),[m,v]=g.useState(!1),[b,_]=g.useState(null),x=st.useRef(e),y=st.useRef(t),w=st.useRef(n);st.useEffect(()=>{x.current=e,y.current=t,w.current=n});const S=st.useCallback(()=>{a(!1),p(null),x.current().then(B=>{c(B),d(B),a(!0)}).catch(B=>{p(B instanceof Error?B.message:String(B))})},[]);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),_(null),y.current(u).then(()=>{c(u),v(!1)}).catch(B=>{_(B instanceof Error?B.message:String(B)),v(!1)}))},T=()=>{d(l),_(null)};return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-personality-section",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"人格 (Personality)"}),f?h.jsxs("div",{"data-testid":"persona-personality-load-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error flex items-center justify-between gap-2",children:[h.jsxs("span",{children:["加载失败:",f]}),h.jsx("button",{type:"button",onClick:S,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,b?h.jsxs("div",{"data-testid":"persona-personality-save-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",b]}):null,h.jsx("textarea",{"data-testid":"persona-personality-textarea",value:u,onChange:B=>d(B.target.value),readOnly:i,disabled:!i&&(!o||m),placeholder:o?"":"加载中…",rows:8,className:"min-h-[8rem] max-h-[18rem] resize-y rounded-md border border-border bg-bg-100 px-2 py-1.5 font-mono text-[11px] text-text-100 disabled:opacity-60"}),!i&&h.jsxs("p",{className:"text-[10px] text-text-400",children:["写入到 ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/CLAUDE.md"}),"。 修改只对新启动的 sub-session 生效。"]}),o&&C?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:T,disabled:m,className:"rounded-sm border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200 disabled:opacity-60",children:"放弃"}),h.jsx("button",{type:"button",onClick:N,disabled:m,"data-testid":"persona-personality-save-btn",className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:m?"保存中…":"保存"})]}):null]})}const Tre={state:"unbound",groups:[]};function Pre(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(Tre)}};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 Ire({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const{persona:l}=kT(e),c=TB(e),u=PB(),d=IB(),{httpBaseUrl:f}=qf(),p=$i(),m=Pre(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(C=>{u(e,{public:C}).catch(N=>{Le("persona","togglePublic failed",N)})},[u,e]),_=g.useCallback(C=>{u(e,{tool:C}).catch(N=>{Le("persona","changeTool failed",N)})},[u,e]),x=g.useCallback(()=>{l&&confirm(`删除 persona "${l.label}"?`)&&(d(e).catch(C=>{Le("persona","delete failed",C)}),n())},[l,d,e,n]),y=g.useCallback(async()=>c.loaded?c.personality:(await c.refresh()).personality,[c]),w=g.useCallback(async C=>{await u(e,{personality:C}),await c.refresh()},[u,e,c]);if(!l)return null;const S=a==="guest";return h.jsx(_re,{embedded:i,persona:{...l,skills:c.skills,plugins:c.plugins,sandboxSettings:c.sandboxSettings},open:t,onClose:n,onLoadPersonality:y,onDirtyChange:s,readOnly:S,...S?{}:{onTogglePublic:b,guestShareUrl:v,onChangeTool:_,onDelete:x,onSavePersonality:w,larkBot:{status:m.status,onProvision:m.provision,onCancelProvision:m.cancelProvision,onBindManual:m.bindManual,onUnbind:m.unbind},...o?{onShareCapability:o}:{}}})}function Rre(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 Mre(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 Mre(s.url,Rre(t.url))}async function Are(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 Lre(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 jre={...Qc,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 Dre(e){const t=e.split("/");return t[t.length-1]||e}function yA({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:Dre(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(Xc,{remarkPlugins:[Zc],components:jre,children:i})}):null})]})}function Ore({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(yA,{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(IT,{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(br,{className:"h-4 w-4"})})]})})}):null}function Bre({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 zre=6173,$re=6182;function Fre({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=zre;v<=$re;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(Np,{className:"max-w-md",children:[h.jsxs(Tp,{children:[h.jsxs(Pp,{children:["改端口 · ",n]}),h.jsxs(xA,{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(ni,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ni,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const PC=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function Hre({currentStage:e,onCancel:t}){const n=PC.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:[PC.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(Gf,{className:"size-3.5"}):o?h.jsx(er,{className:"size-3.5 animate-spin"}):h.jsx(NT,{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 Ure={build:"构建",deploy:"部署",verify:"验证"};function Wre({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(Hc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",Ure[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 Vre={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function qre({stage:e,onFocusChat:t,onClose:n}){return h.jsxs("div",{"data-testid":"publish-failed-banner",className:"flex items-center gap-2 border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[12px]",children:[h.jsx(As,{className:"size-3.5 text-destructive"}),h.jsxs("button",{type:"button",onClick:t,className:"flex-1 text-left text-text-200 hover:underline",children:["发布失败:",h.jsxs("strong",{className:"font-medium",children:["[",Vre[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(br,{className:"size-3.5"})})]})}const IC={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function Kre({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(Fc,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(ny,{children:[h.jsx(ry,{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(n$,{className:"size-3.5"})})}),h.jsxs(op,{align:"end",children:[h.jsx(bi,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(bi,{disabled:!0,title:"rename not supported yet",onSelect:y=>y.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(qre,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((_=e.publishJob)==null?void 0:_.status)==="in-flight"?h.jsx(Hre,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((x=e.publishJob)==null?void 0:x.status)==="interrupted"?h.jsx(Wre,{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(Gre,{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(RC,{label:"等 tunnel 起来…",step:"-"}):h.jsx(RC,{label:IC[m].label,step:IC[m].step})}),h.jsx(Fre,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async y=>{await r(y)}})]})}function RC({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(er,{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 Gre({reason:e}){return h.jsxs("div",{"data-testid":"preview-failed",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(As,{className:"size-6 text-destructive"}),h.jsx("div",{className:"text-[13px] text-text-200",children:"project 启动失败"}),h.jsx("div",{className:"max-w-[400px] text-[12px] text-text-400",children:e??"未知原因 —— 看 ~/.clawd/clawd.log 排查"}),h.jsx("div",{className:"mt-1 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度 / 跟它说怎么修"})]})}function Xre({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(Np,{className:"max-w-lg",children:[h.jsx(Tp,{children:h.jsx(Pp,{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(ni,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(To,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(pu,{className:"size-3.5"}),"复制"]})}),h.jsx(ni,{onClick:t,children:"关闭"})]})]})})}function Yre(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 Zre={codex:"on-request",claude:"bypassPermissions"};function Qre(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??Zre[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function Jre(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...Qre({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=>Le("quick-ask","fork rollback failed",o)),s}return i}async function eie(e,t,n){return Jre(e,t,n,{ephemeral:!0})}function Id(e){return e!=null&&e.ephemeral!==!1}async function tie(e,t){return t.stillEphemeral?(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0):!1}function nie(){return{quickAsk:null,mds:[],active:null}}function rie(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function iie(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function sie(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 oie(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function aie(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 lie(e,t){return{...e,active:t}}function cie(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function bA(e){return e.quickAsk!==null||e.mds.length>0}function uie(e){return e.split("/").pop()||e}function die({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onPromoteQuickAsk:a}){if(!bA(e))return null;const l=[];e.quickAsk&&l.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(r0,{className:"w-3.5 h-3.5"})});for(const c of e.mds)l.push({id:{kind:"md",relPath:c},label:uie(c),title:c,icon:h.jsx(Po,{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(L5,{delayDuration:200,skipDelayDuration:100,children:h.jsx("div",{className:["flex items-stretch h-9 border-b border-text-100/10 shrink-0 overflow-x-auto","[scrollbar-width:none] [-ms-overflow-style:none]","[&::-webkit-scrollbar]:hidden"].join(" "),role:"tablist",children:l.map(c=>{const u=cie(e.active,c.id),d=c.id==="quick-ask"?"quick-ask":`md:${c.id.relPath}`;return h.jsxs(j5,{children:[h.jsx(D5,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":u,"data-tab-title":c.title,onClick:()=>n(c.id),className:["group relative flex items-center gap-2 px-3 h-full cursor-pointer select-none","text-[12px] max-w-[180px] shrink-0 transition-colors duration-100",u?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[c.icon,h.jsx("span",{className:"truncate",children:c.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${c.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",u?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:f=>{f.stopPropagation(),c.id==="quick-ask"?r():i(c.id.relPath)},children:h.jsx(br,{className:"w-3 h-3"})}),u?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Vy,{side:"bottom",align:"start",className:"max-w-sm break-all",children:c.title})]},d)})})}),h.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[e.quickAsk&&o?h.jsx("div",{className:"absolute inset-0",style:{display:e.active==="quick-ask"?"block":"none"},children:h.jsx(fie,{session:o,api:t,...a?{onPromoteQuickAsk:a}:{}})}):null,e.mds.map(c=>{const u=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===c;return h.jsx("div",{className:"absolute inset-0",style:{display:u?"block":"none"},children:h.jsx(yA,{relPath:c,loadMarkdown:s,showTitleBar:!1})},`md-body:${c}`)})]})]})}function hie({state:e,extras:t}){const{api:n,session:r}=t,i=$i(),[s,o]=g.useState(nie()),a=g.useRef(s);a.current=s;const l=g.useRef(!1),c=g.useCallback(async S=>{const C=a.current.quickAsk,N=await eie(n,r,S);if(N){if(l.current){n.sessionDelete(N.sessionId).catch(()=>{});return}Id(C)&&n.sessionDelete(C.sessionId).catch(()=>{}),o(T=>rie(T,{sessionId:N.sessionId}))}},[n,r]),u=g.useCallback(async S=>{const C=a.current.quickAsk,N=(C==null?void 0:C.sessionId)===S;try{await tie(n,{sessionId:S,stillEphemeral:N&&Id(C)})&&o(B=>oie(B))}catch(T){Le("quick-ask","promote failed",T)}},[n]),d=g.useCallback(S=>{o(C=>iie(C,S))},[]),f=g.useCallback(S=>{o(C=>lie(C,S))},[]),p=g.useCallback(()=>{const S=a.current.quickAsk;Id(S)&&n.sessionDelete(S.sessionId).catch(()=>{}),o(C=>sie(C))},[n]),m=g.useCallback(S=>{o(C=>aie(C,S))},[]);g.useEffect(()=>()=>{l.current=!0;const S=a.current.quickAsk;Id(S)&&n.sessionDelete(S.sessionId).catch(()=>{})},[]);const v=si("sessions")??[],b=s.quickAsk?v.find(S=>S.sessionId===s.quickAsk.sessionId)??{sessionId:s.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,_=g.useCallback(async S=>{const C=await n1(n,i,r.sessionId,S,60),N=await fetch(C);if(!N.ok)throw new Error(`fetch ${N.status} ${N.statusText}`);return N.text()},[n,i,r.sessionId]),x=h.jsx(r1,{state:e,extras:t,onQuickAskInternal:c,onPreviewMdInternal:d}),{initialSize:y,setSize:w}=TM("chat-panel-right-slot-width",480);return h.jsxs(ap,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Ha,{id:"chat",minSize:"400px",children:x}),bA(s)?h.jsxs(h.Fragment,{children:[h.jsx(fy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Ha,{id:"right-slot",defaultSize:`${y}px`,minSize:"360px",maxSize:"800px",onResize:S=>w(S.inPixels),children:h.jsx(die,{state:s,api:n,onSwitchTab:f,onCloseQuickAsk:p,onCloseMd:m,loadMarkdown:_,quickAskSession:b,onPromoteQuickAsk:u})})]}):null]})}function fie({session:e,api:t,onPromoteQuickAsk:n}){const r=k5(e.sessionId);return h.jsx(r1,{state:r,extras:{session:e,api:t,...n?{onPromoteQuickAsk:n}:{}}})}function pie({extras:e}){const t=k5(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(r1,{state:t,extras:e});return h.jsx(mie,{state:t,chat:n,extras:e})}return h.jsx(hie,{state:t,extras:e})}function mie({state:e,chat:t,extras:n}){var T;const r=si("daemon-info"),i=$i(),s=n.api,o=n.session,a=o.appBuilderProject,[l,c]=g.useState(null),u=g.useCallback(()=>{s.appBuilderGetProject(o.sessionId).then(B=>c(B.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(B=>f(B.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const L=P;L!=null&&L.project&&(L.project.name===a&&c(L.project),f(I=>{const R=I.findIndex(z=>z.name===L.project.name);if(R<0)return[...I,L.project];const j=I.slice();return j[R]=L.project,j}))}),[i,a]);const{host:m,scheme:v}=Yre(i.url,r==null?void 0:r.tunnelUrl),[b,_]=g.useState(void 0),[x,y]=g.useState(null);g.useEffect(()=>{const B=i.on("appBuilder:publish-progress",L=>{const I=L;!I||I.name!==a||I.status==="started"&&_(I.stage)}),P=i.on("appBuilder:publish-failed",L=>{const I=L;!I||I.name!==a||(_(void 0),y({stage:I.stage}))});return()=>{B(),P()}},[i,a]),g.useEffect(()=>{_(void 0),y(null)},[a]);const[w,S]=g.useState(null),C=h.jsx("button",{type:"button",className:"rounded bg-accent-main-100 px-2.5 py-1 text-[12px] text-oncolor-100 hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",disabled:((T=l==null?void 0:l.publishJob)==null?void 0:T.status)==="in-flight",onClick:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"发布请求失败",message:(B==null?void 0:B.message)??String(B)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(Bre,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(Kre,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(B=>B.port),onUpdatePort:async B=>{await s.appBuilderUpdateProjectPort(a,B),p()},publishSlot:C,publishInFlightStage:b,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(B){S({title:"取消发布失败",message:(B==null?void 0:B.message)??String(B)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"重新发布失败",message:(B==null?void 0:B.message)??String(B)})}},publishFailureBanner:x,onPublishFailureBannerClose:()=>y(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(Xre,{error:w,onClose:()=>S(null)})]})}function gie({headerMeta:e,connState:t,liveWorktreeRoot:n,onOpenConfig:r,variant:i="full",ephemeral:s,onPromote:o,infoPanelOpen:a=!1,onToggleInfoPanel:l,infoPanel:c,infoPanelDefaultPx:u,onInfoPanelResize:d,lines:f,pendingPermissions:p,procAlive:m,rewindableUserMessageIds:v,onPermissionRespond:b,onPermissionInterrupt:_,onRewind:x,onFork:y,onQuickAsk:w,topSlot:S,realtimeQuestionAnswers:C,onSubmitQuestion:N,onCancelQuestion:T,liveQuestionToolUseIds:B,api:P,cwd:L,tool:I,sessionKey:R,onSend:j,awaitingUser:z,onAbort:$,onNewSession:F,onClearSession:O,configSlot:D,chatRootRef:E,chatBodyRef:H,topSentinelRef:V,drawers:A,xtermSlot:re,fileSharingScope:ie,onShareFile:G,onOpenInTab:ve,onPreviewMarkdown:Ie}){return h.jsx(mZ,{children:h.jsxs(ap,{orientation:"horizontal",className:"flex h-full min-w-0 min-h-0",children:[h.jsx(Ha,{id:"chat",minSize:"360px",children:h.jsxs("div",{ref:E,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(oQ,{meta:e,...I?{tool:I}:{},connState:t,variant:i,...n!==void 0?{liveWorktreeRoot:n}:{},...i==="full"&&r?{onOpenConfig:r}:{},...i==="full"&&l?{infoPanelOpen:a,onToggleInfoPanel:l}:{},...i==="quickask"?{ephemeral:s??!1,...o?{onPromote:o}:{}}:{}}),h.jsxs("div",{ref:H,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[V?h.jsx("div",{ref:V,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx(kM,{lines:f,...b?{onPermissionRespond:b}:{},..._&&m?{onPermissionInterrupt:_}:{},topSlot:S,...x?{onRewind:x}:{},rewindableUserMessageIds:v,...y?{onFork:y}:{},...w?{onQuickAsk:w}:{},realtimeQuestionAnswers:C,onSubmitQuestion:N,...T?{onCancelQuestion:T}:{},liveQuestionToolUseIds:B,...ie?{fileSharingScope:ie}:{},...G?{onShareFile:G}:{},...ve?{onOpenInTab:ve}:{},...Ie?{onPreviewMarkdown:Ie}:{}})]}),re,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(iQ,{meta:e,...P?{api:P}:{},cwd:L,...I?{tool:I}:{},sessionKey:R,onSend:j,awaitingUser:z,...$?{onAbort:$}:{},...F?{onNewSession:F}:{},...O?{onClearSession:O}:{},...D?{configSlot:D}:{}}),A]})}),a&&c?h.jsxs(h.Fragment,{children:[h.jsx(fy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Ha,{id:"session-info",defaultSize:`${u??320}px`,minSize:"280px",maxSize:"480px",...d?{onResize:oe=>d(oe.inPixels)}:{},children:c})]}):null]})})}function r1({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,liveGitBranch:o,liveWorktreeRoot:a,onNewSession:l,onTurnEnd:c,onOpenConfig:u,onFork:d,onQuickAsk:f,viewerRole:p,onPromoteQuickAsk:m,configSlot:v}=t,{capabilities:b}=S5(i.tool||"claude"),_=(b==null?void 0:b.features)??xT(i.tool),[x,y]=g.useState(null),[w,S]=g.useState(null),C=qf(),N=!!s&&C.actionsLevel==="owner"&&_.fileSharing,T=kT(i.ownerPersonaId??null).persona,B=(T==null?void 0:T.label)??null,P=!!B&&!!i.ownerPersonaId,L=g.useCallback((q,de)=>{y({kind:q,text:de}),setTimeout(()=>{y(pe=>(pe==null?void 0:pe.text)===de?null:pe)},2e3)},[]),I=$i(),R=sB(),j=w5(i.sessionId,i.toolSessionId),{events:z,pendingQuestions:$,clearQuestion:F,markQuestionSubmitted:O,status:D}=j,E=e.historyLoading,H=RM(D);g.useEffect(()=>{Le("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:D,procAlive:H})},[D,H,i.sessionId]);const V=e.lines,A=e.pendingPermissions,re=A[0]??null,ie=g.useMemo(()=>bU(z),[z]),[G,ve]=g.useState(null),[Ie,oe]=g.useState(()=>new Set);_U(s,i.sessionId,i.toolSessionId,_.observe);const je=g.useRef(i.sessionId);g.useEffect(()=>{if(je.current=i.sessionId,!_.rewind){ve(null);return}let q=!1;return ve(null),(async()=>{try{const de=await s.sessionRewindableMessageIds(i.sessionId);if(q)return;ve(new Set(de.userMessageIds))}catch{q||ve(null)}})(),()=>{q=!0}},[s,i.sessionId,_.rewind]);const Ke=g.useCallback(()=>{const q=i.sessionId;s.sessionRewindableMessageIds(q).then(de=>{je.current===q&&ve(new Set(de.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),Ue=g.useMemo(()=>{if(G!==null){const Ze=new Set(G);for(const qi of Ie)Ze.delete(qi);return Ze}const q=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),de=new Set;let pe=null;for(const Ze of V)Ze.kind==="user-text"?pe=Ze.uuid??null:pe&&Ze.kind==="tool-call"&&q.has(Ze.tool)&&!Ie.has(pe)&&de.add(pe);return de},[V,Ie,G]),_e=g.useRef(c);_e.current=c,xU(i.sessionId,i.toolSessionId,()=>{zt(null),oe(new Set)});const $e=kQ({sessionStatus:D}),un=g.useRef(null);g.useEffect(()=>{var pe;const q=un.current,de=(q==null?void 0:q.sid)===i.sessionId;de&&q.phase===$e||(un.current={sid:i.sessionId,phase:$e},Le("session-phase",$e,{sid:i.sessionId,phase:$e,prev:de?q.phase:null,desc:SQ[$e]}),de&&q.phase==="turn-running"&&$e!=="turn-running"&&((pe=_e.current)==null||pe.call(_e),Ke()))},[$e,i.sessionId,Ke]);const ht=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Nt,zt]=g.useState(null),$t=g.useCallback(q=>{zt(q)},[]),[Tt,Ye]=g.useState(!1),it=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),Ye(!1)},[s,i.sessionId]);g.useCallback(q=>{s.pinSession(i.sessionId,q).catch(de=>{Le("chat-panel","pinSession failed",{err:de==null?void 0:de.message})})},[s,i.sessionId]);const mt=m?"quickask":"full",[dn,bn]=g.useState(!1),{initialSize:U,setSize:Z}=TM("clawd:panel:session-info-px",320),xe=g.useRef(0),Te=g.useRef(null);g.useEffect(()=>{const q=de=>{if(de.key!=="Escape")return;if(!H){xe.current=0;return}if(de.isComposing)return;const Ze=de.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==Te.current)return;const qi=Date.now();qi-xe.current<2e3?(xe.current=0,Ye(!0)):(xe.current=qi,ht())};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[ht,H]);const Ae=g.useRef(null),Mt=g.useRef(null),Ft=g.useRef(!0),ne=g.useRef(null),te=g.useRef(0),ke=g.useRef(0);g.useEffect(()=>{Ft.current=!0,ne.current=null,te.current=0,ke.current=0},[i.sessionId]),g.useEffect(()=>{S(null)},[i.sessionId]);const tt=g.useRef(e);tt.current=e;const Fn=g.useCallback(()=>{var pe;const q=Ae.current;if(!q||ne.current!==null)return;const de=tt.current;de.historyDone||de.historyLoading||(ne.current={distFromBottom:q.scrollHeight-q.scrollTop},(pe=de.loadMoreHistory)==null||pe.call(de))},[]);g.useEffect(()=>{const q=Ae.current,de=Mt.current;if(!q||!de)return;const pe=new IntersectionObserver(Ze=>{for(const qi of Ze)qi.isIntersecting&&Fn()},{root:q,threshold:0});return pe.observe(de),()=>pe.disconnect()},[Fn]),g.useEffect(()=>{const q=Ae.current;if(!q)return;const de=150,pe=Ze=>{Date.now()<ke.current&&(Ze.preventDefault(),ke.current=Date.now()+de)};return q.addEventListener("wheel",pe,{passive:!1}),()=>q.removeEventListener("wheel",pe)},[]),g.useEffect(()=>{const q=Ae.current;if(!q)return;const de=32,pe=()=>{const Ze=q.scrollHeight-q.scrollTop-q.clientHeight;Ft.current=Ze<=de};return q.addEventListener("scroll",pe,{passive:!0}),()=>q.removeEventListener("scroll",pe)},[]),g.useLayoutEffect(()=>{const q=Ae.current;if(!q)return;const de=te.current,pe=V.length;te.current=pe;const Ze=ne.current;if(Ze!==null&&pe>de){ne.current=null,q.scrollTop=q.scrollHeight-Ze.distFromBottom,ke.current=Date.now()+200;return}Ze!==null&&(ne.current={distFromBottom:q.scrollHeight-q.scrollTop}),Ft.current&&(q.scrollTop=q.scrollHeight)},[V,re==null?void 0:re.requestId]);const Hn=g.useMemo(()=>{const q={};for(const[de,pe]of Object.entries($))pe.submittedAnswers&&(q[de]=pe.submittedAnswers);return q},[$]),Ip=g.useMemo(()=>new Set(Object.keys($)),[$]),Rp=g.useCallback(async(q,de)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:q,answers:de}),O(q,de)}catch{}},[s,i.sessionId,O]),Mp=g.useCallback(async q=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:q}),F(q)}catch{}},[s,i.sessionId,F]),Ap=g.useCallback(async(q,de)=>{var pe;if(re)try{await((pe=e.respondPermission)==null?void 0:pe.call(e,re.requestId,q?"allow":"deny"))}catch{}},[e,re]),Lp=g.useCallback(async()=>{const q=i.sessionId;try{await s.sessionStop(q)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(q)},[e,s,i.sessionId]),jp=g.useMemo(()=>E&&V.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(er,{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 q;return void((q=e.loadMoreHistory)==null?void 0:q.call(e))},disabled:E,"data-testid":"history-load-more",className:"text-[12px] text-text-400 hover:text-text-200 cursor-pointer px-3 py-1 rounded-md border border-bg-300 hover:bg-bg-100 transition-colors disabled:opacity-60",children:E?"加载中…":"Load earlier messages"})}),[E,V.length,e.historyDone,e.loadMoreHistory]),ml=e.meta,Oo=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(gQ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Nt&&_.rewind?h.jsx(_Q,{open:!0,onOpenChange:q=>{q||zt(null)},api:s,sessionId:i.sessionId,userMessageId:Nt,lines:V,procAlive:H,onNoChanges:q=>{oe(de=>{if(de.has(q))return de;const pe=new Set(de);return pe.add(q),pe})}}):null,Tt?h.jsx(vie,{onConfirm:it,onCancel:()=>Ye(!1)}):null]}),Bs={kind:"session",sessionId:i.sessionId},Bo=g.useCallback(async q=>{if(s)try{await Are(s,I,i.sessionId,q)}catch(de){const pe=de.message;Le("chat-panel","open-in-tab failed",{err:pe}),L("err",`Open in tab 失败:${pe}`)}},[s,I,i.sessionId,L]),[gl,fi]=g.useState(!1),[Or,Mu]=g.useState(null),Au=g.useCallback(q=>{if(r){r(q);return}Mu(q),fi(!0)},[r]),Ht=g.useCallback(async q=>{if(!s)throw new Error("daemon api not ready");const de=await n1(s,I,i.sessionId,q,60),pe=await fetch(de);if(!pe.ok)throw new Error(`fetch ${pe.status} ${pe.statusText}`);return await pe.text()},[s,I,i.sessionId]),zo=g.useCallback(async(q,de)=>{if(s)try{const{url:pe}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:q,ttlSeconds:86400,...de?{view:de}:{}}),Ze=await Lre(pe);L(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(pe){const Ze=pe.message;Le("chat-panel","share-file failed",{err:Ze}),L("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,L]),$o=g.useCallback(()=>S(null),[]),Pt=w==="files"&&N&&s?{title:"Edited Files",onBack:$o,content:h.jsx(hne,{api:s,scope:Bs,sessionId:i.sessionId,onShareFile:zo,onOpenInTab:Bo,onPreviewMarkdown:Au})}:w==="cron"?{title:`定时任务${ie.length?` (${ie.length})`:""}`,onBack:$o,content:h.jsx("div",{className:"p-3",children:h.jsx(wQ,{jobs:ie})})}:w==="persona"&&P&&s&&i.ownerPersonaId?{title:`Persona · ${B??""}`,onBack:$o,content:h.jsx(Ire,{personaId:i.ownerPersonaId,open:!0,onClose:$o,api:s,embedded:!0,...p?{viewerRole:p}:{}},i.ownerPersonaId)}:null;return h.jsxs(h.Fragment,{children:[h.jsx(gie,{headerMeta:ml,connState:e.connState,...a!==void 0?{liveWorktreeRoot:a}:{},...u?{onOpenConfig:u}:{},variant:mt,...mt==="quickask"?{ephemeral:i.ephemeral!==!1,onPromote:()=>void(m==null?void 0:m(i.sessionId))}:{infoPanelOpen:dn,onToggleInfoPanel:()=>bn(q=>!q),infoPanelDefaultPx:U,onInfoPanelResize:Z,infoPanel:h.jsx(cQ,{session:i,meta:ml,...o!==void 0?{liveGitBranch:o}:{},...a!==void 0?{liveWorktreeRoot:a}:{},...P?{personaName:B}:{},...P?{onOpenPersona:()=>S("persona")}:{},...N?{onOpenFiles:()=>S("files")}:{},cronActiveCount:ie.length,onCronClick:()=>S("cron"),onForceStop:()=>Ye(!0),...p?{viewerRole:p}:{},...b!=null&&b.toolSessionIdLabel?{toolSessionIdLabel:b.toolSessionIdLabel}:{},drill:Pt,onClose:()=>bn(!1)})},lines:V,pendingPermissions:A,procAlive:H,rewindableUserMessageIds:Ue,onPermissionRespond:Ap,onPermissionInterrupt:ht,onRewind:_.rewind?$t:void 0,...d&&_.fork?{onFork:d}:{},...n&&_.fork?{onQuickAsk:n}:f&&_.fork?{onQuickAsk:f}:{},topSlot:jp,realtimeQuestionAnswers:Hn,onSubmitQuestion:Rp,onCancelQuestion:Mp,liveQuestionToolUseIds:Ip,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:A.length>0||Object.values($).some(q=>!q.submittedAnswers),onAbort:ht,...l?{onNewSession:l}:{},onClearSession:Lp,...v?{configSlot:v}:{},chatRootRef:Te,chatBodyRef:Ae,topSentinelRef:Mt,drawers:Oo,xtermSlot:R==="tui"&&H&&_.tui?h.jsx(Bte,{sessionId:i.sessionId,client:I},i.sessionId):null,fileSharingScope:Bs,...s?{onShareFile:zo}:{},...s?{onOpenInTab:Bo}:{},...s?{onPreviewMarkdown:Au}:{}}),s?h.jsx(Ore,{open:gl,onOpenChange:fi,relPath:Or,loadMarkdown:Ht,onShare:Or?()=>void zo(Or,"md-rendered"):void 0}):null,x?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:x.kind==="ok"?"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-[12px] text-emerald-700 shadow-md dark:text-emerald-300":"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[12px] text-destructive shadow-md",children:x.text}):null]})}function vie({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(Hc,{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 _ie(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 wA(e,t,n){var l;if(!t)return n?wA(e,n):((l=(e??[]).find(c=>c.id===""))==null?void 0:l.label)??"未指定";const r=t.toLowerCase(),i=[["opus","Opus"],["fable","Fable"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[c,u]of i){if(!r.includes(c))continue;const d=r.match(new RegExp(`${c}-(\\d+)(?:-(\\d+))?`));return d?d[2]?`${u} ${d[1]}.${d[2]}`:`${u} ${d[1]}`:u}const s=e??[],o=s.find(c=>c.id===t);if(o)return o.label;const a=s.find(c=>c.id&&t.toLowerCase().includes(c.id.toLowerCase()));return a?a.label:t}function xie(e,t){var p,m,v,b;const{models:n,modes:r,configSchema:i}=t,s=_ie(e.model,n,i),o=s.options,a=o.some(_=>_.value===e.effort)?e.effort:s.defaultValue,l=a===""&&e.resolvedEffort?((p=o.find(_=>_.value===e.resolvedEffort))==null?void 0:p.label)??e.resolvedEffort:((m=o.find(_=>_.value===a))==null?void 0:m.label)??null,c=((v=i.find(_=>_.name==="permissionMode"))==null?void 0:v.default)??"",u=r.some(_=>_.id===e.permissionMode)?e.permissionMode:c,f=u===c?null:((b=r.find(_=>_.id===u))==null?void 0:b.label)??null;return{modelLabel:wA(n,e.model,e.resolvedModel),effortOptions:o,effortValue:a,effortLabel:l,modeValue:u,modeLabel:f,modeTone:f===null?null:u==="bypassPermissions"?"danger":"info"}}function yie({models:e=[],modes:t=[],configSchema:n=[],model:r,effort:i,permissionMode:s,resolvedModel:o,resolvedEffort:a,onPatch:l}){var f;const c=xie({model:r,effort:i,permissionMode:s,...o?{resolvedModel:o}:{},...a?{resolvedEffort:a}:{}},{models:e,modes:t,configSchema:n}),u=e.map(p=>{const m=p.id===""&&o?`${p.description?`${p.description};`:""}当前:${o}`:p.description;return{value:p.id,label:p.label,...m?{description:m}:{}}}),d=t.map(p=>({value:p.id,label:p.label,...p.description?{description:p.description}:{}}));return h.jsxs(ny,{children:[h.jsx(ry,{asChild:!0,children:h.jsxs("button",{type:"button","data-testid":"session-config-chip",title:"Model / reasoning effort / permission mode",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:[h.jsx("span",{className:"truncate max-w-[120px]","data-testid":"session-config-chip-model",children:c.modelLabel}),c.effortLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"truncate max-w-[80px]","data-testid":"session-config-chip-effort",children:c.effortLabel})]}):null,c.modeLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{"data-testid":"session-config-chip-mode","data-tone":c.modeTone,className:le("font-semibold",c.modeTone==="danger"?"text-red-400":"text-blue-400"),children:c.modeLabel})]}):null]})}),h.jsxs(op,{side:"top",align:"end",className:"w-[230px]","data-testid":"session-config-menu",children:[h.jsx(yg,{testid:"session-config-model",label:"Model",current:r,currentLabel:c.modelLabel,options:u,onSelect:p=>l({model:p})}),h.jsx(yg,{testid:"session-config-effort",label:"Reasoning effort",current:c.effortValue,currentLabel:c.effortLabel??"—",options:c.effortOptions,onSelect:p=>l({effort:p})}),d.length>0?h.jsx(yg,{testid:"session-config-mode",label:"Permission mode",current:c.modeValue,currentLabel:((f=t.find(p=>p.id===c.modeValue))==null?void 0:f.label)??"—",currentTone:c.modeTone,options:d,onSelect:p=>l({permissionMode:p})}):null]})]})}function yg({testid:e,label:t,current:n,currentLabel:r,currentTone:i,options:s,onSelect:o}){const a=s.length===0;return h.jsxs(xH,{children:[h.jsxs(FI,{"data-testid":e,disabled:a,className:"gap-2 text-[12px]",children:[h.jsx("span",{className:"flex-1 text-text-200",children:t}),h.jsx("span",{className:le("truncate max-w-[100px]",i==="danger"?"text-red-400 font-semibold":i==="info"?"text-blue-400 font-semibold":"text-text-400"),children:r}),h.jsx(jr,{className:"w-3.5 h-3.5 shrink-0 text-text-500"})]}),h.jsx(HI,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:s.map(l=>{const c=l.value===n;return h.jsxs(bi,{"data-testid":`${e}-option-${l.value||"default"}`,onSelect:()=>o(l.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsx("span",{className:le("block text-[12px]",c?"text-text-100 font-medium":"text-text-300"),children:l.label}),l.description?h.jsx("span",{className:"block text-[11px] text-text-400 mt-0.5",children:l.description}):null]}),c?h.jsx(To,{className:"w-3.5 h-3.5 shrink-0 text-accent mt-0.5"}):null]},l.value||"default")})})]})}function bie(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 wie(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 Sie({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onFork:l,onQuickAsk:c,className:u,viewerRole:d="owner"}){const{capabilities:f}=S5(t.tool),[p,m]=g.useState(0),{branch:v}=bie(e,t.cwd,p),{worktreeRoot:b}=wie(e,t.cwd,p),_=r>1,x=y=>{e.sessionUpdate(t.sessionId,y).catch(w=>{console.error("[session-config] session:update failed",t.sessionId,w)})};return h.jsxs("div",{className:`group/pane relative flex-1 ${u??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${_?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsx(ap,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:h.jsx(Ha,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(kie,{api:e,session:t,liveGitBranch:v,liveWorktreeRoot:b,onNewSession:o,onTurnEnd:()=>m(y=>y+1),onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:d,configSlot:f?h.jsx(yie,{models:f.models,modes:f.permissionModes,configSchema:f.configSchema,model:t.model??"",...t.resolvedModel?{resolvedModel:t.resolvedModel}:{},...t.resolvedEffort?{resolvedEffort:t.resolvedEffort}:{},effort:t.effort??"",permissionMode:t.permissionMode??"",onPatch:x}):null})})})}),_&&h.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),s()},className:"absolute top-1.5 right-1.5 z-10 p-1 rounded-md bg-bg-100/80 backdrop-blur-sm border border-border opacity-0 group-hover/pane:opacity-100 transition-opacity text-text-400 hover:text-text-100 hover:bg-bg-200","aria-label":"close pane","data-testid":`session-pane-close-${t.sessionId}`,children:h.jsx(br,{className:"w-3.5 h-3.5"})})]})}function kie({api:e,session:t,liveGitBranch:n,liveWorktreeRoot:r,onNewSession:i,onTurnEnd:s,onOpenConfig:o,onFork:a,onQuickAsk:l,viewerRole:c,configSlot:u}){return h.jsx(pie,{extras:{session:t,api:e,...n!==void 0?{liveGitBranch:n}:{},...r!==void 0?{liveWorktreeRoot:r}:{},onNewSession:i,onTurnEnd:s,onOpenConfig:o,...a?{onFork:d=>{a(d)}}:{},...l?{onQuickAsk:d=>{l(d)}}:{},...c?{viewerRole:c}:{},...u?{configSlot:u}:{}}})}function Cie({personas:e,sessions:t,api:n,selfPrincipalId:r,selectedPersonaId:i,selectedSessionId:s,selectedSession:o,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,onCloseSession:f}){return h.jsxs("div",{className:"flex h-screen min-h-0 bg-bg-50","data-testid":"guest-share-page",children:[h.jsx("aside",{className:"w-[280px] shrink-0 overflow-y-auto border-r border-border bg-bg-50",children:h.jsx(DH,{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(Sie,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},viewerRole:"guest"}):h.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-xs text-text-400","data-testid":"guest-share-empty",children:"选择左侧 persona 开始对话"})})]})}function Eie(){const e=$i(),t=g.useMemo(()=>new Tx(e),[e]),n=EB(e),{sessions:r,refresh:i}=NB(n),{personas:s}=ST(),o=AB(),a=g.useMemo(()=>{const w=window.location.pathname.match(/^\/s\/([^/]+)/);return w?decodeURIComponent(w[1]):null},[]),l=g.useMemo(()=>r.filter(w=>!w.ephemeral&&w.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(w=>w.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let w=!1;return e.request("whoami",{}).then(S=>{w||d(S.capability.id)}).catch(()=>{}),()=>{w=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const b=g.useCallback(async(w,S)=>{const C=await t.sessionCreate({ownerPersonaId:w,...S.trim()?{label:S.trim()}:{}});await i(),p(w),v(C.sessionId)},[t,i]),_=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(S=>S===w?null:S)},[t,i]),x=g.useCallback(async(w,S)=>{await t.sessionUpdate(w,{label:S.label}),await i()},[t,i]),y=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(Px.Provider,{value:o,children:h.jsx(Cie,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:y,onSelectPersona:p,onSelectSession:v,onCreateSession:(w,S)=>void b(w,S),onDeleteSession:w=>void _(w),onEditSession:(w,S)=>void x(w,S),onCloseSession:()=>v(null)})})}const MC="https://app.ttcadvisory.com";function Nie({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=`${MC}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==MC)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 v_="clawd-visitor:token";function Tie(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function Pie(){return{async getUrl(e){const t=localStorage.getItem(v_);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=Tie(window.location,{});return await pT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function Iie(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Rie(){const e=$i(),t=g.useMemo(()=>CB(e),[e]);return h.jsx(oB,{cache:t.cache,children:h.jsx(cB,{children:h.jsx(Eie,{})})})}function Mie({host:e}){const[t]=g.useState(()=>localStorage.getItem(v_)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>Iie(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return Pie().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(yb,{host:e,children:h.jsx(Jb,{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(iB,{host:e,children:h.jsx(Rie,{})}):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(yb,{host:e,children:h.jsx(Jb,{children:h.jsx(Nie,{onAuthed:o=>{localStorage.setItem(v_,o),window.location.reload()}})})})}function Aie({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):Lie(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:le("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 Lie(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 jie({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(Die,{status:t.status}),h.jsx("span",{className:le("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 Die({status:e}){return e==="completed"?h.jsx(Gf,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(er,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(NT,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function Oie(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 Bie({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(Kf,{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 zie(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 $ie={render:({input:e})=>st.createElement(jie,{items:Oie(e)})},Fie={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=zie(e);return st.createElement(Bie,{description:t,prompt:n,subagentType:r})}},SA={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Uie(e),c=l?st.createElement(Aie,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return st.createElement(_M,{tool:Hie(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function Hie(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Uie(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}}Cu.register("claude","TodoWrite",$ie);Cu.register("claude","Task",Fie);Cu.register("claude","Edit",SA);Cu.register("claude","Write",SA);const kA=document.getElementById("root");if(!kA)throw new Error("guest-main: #root not found");const Wie=iL({});bg.createRoot(kA).render(h.jsx(st.StrictMode,{children:h.jsx(Mie,{host:Wie})}));
|
|
554
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return g.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},hre="DialogDescriptionWarning",fre=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${fA(hre).contentName}}.`;return g.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},pre=eA,mre=rA,pA=iA,mA=sA,gA=aA,vA=cA,gre=dA;const e1=pre,vre=mre,_A=g.forwardRef(({className:e,...t},n)=>h.jsx(pA,{ref:n,className:le("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));_A.displayName=pA.displayName;const Np=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(vre,{children:[h.jsx(_A,{}),h.jsxs(mA,{ref:r,className:le("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(gre,{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(br,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Np.displayName=mA.displayName;const Tp=({className:e,...t})=>h.jsx("div",{className:le("flex flex-col space-y-1.5 text-left",e),...t});Tp.displayName="DialogHeader";const t1=({className:e,...t})=>h.jsx("div",{className:le("flex flex-row justify-end gap-2",e),...t});t1.displayName="DialogFooter";const Pp=g.forwardRef(({className:e,...t},n)=>h.jsx(gA,{ref:n,className:le("text-lg font-semibold leading-none text-text-100",e),...t}));Pp.displayName=gA.displayName;const xA=g.forwardRef(({className:e,...t},n)=>h.jsx(vA,{ref:n,className:le("text-sm text-text-300",e),...t}));xA.displayName=vA.displayName;function _re({persona:e,open:t,onClose:n,onTogglePublic:r,guestShareUrl:i,onDelete:s,embedded:o,onLoadPersonality:a,onSavePersonality:l,onDirtyChange:c,initialPersonality:u,onShareCapability:d,readOnly:f=!1,onChangeTool:p,larkBot:m}){const[v,b]=g.useState(!1),[_,x]=g.useState(!1),y=()=>{i&&navigator.clipboard.writeText(i).then(()=>{x(!0),setTimeout(()=>x(!1),2e3)})},w=C=>{b(C),c==null||c(C)},S=()=>{v&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!o&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:S,"aria-hidden":"true"}),h.jsxs("aside",{className:o?"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(i$,{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:S,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(br,{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(Nz,{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(Cz,{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:[d?h.jsxs("button",{type:"button",onClick:d,"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(Rx,{className:"h-3.5 w-3.5"}),"分享"]}):null,s?h.jsx("button",{type:"button",onClick:s,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(Mx,{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(Sre,{checked:e.public??!1,onChange:C=>r(C)})]}),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(IT,{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:C=>C.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:y,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(To,{className:"h-3 w-3"})," 已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(pu,{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,m?h.jsxs(h.Fragment,{children:[h.jsx(wre,{...m}),h.jsx("hr",{className:"border-border"})]}):null,p&&!f?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(C=>h.jsx("button",{type:"button","data-testid":`persona-edit-tool-${C}`,onClick:()=>p(C),className:le("flex-1 rounded-md border px-3 py-2 text-[12px]",(e.tool??"claude")===C?"border-accent bg-accent/10 text-accent":"border-bg-300 text-text-300"),children:C==="claude"?"Claude Code":"Codex"},C))}),h.jsx("span",{className:"text-[11px] text-text-400",children:"切换只影响之后新建的会话,已有会话保持原 tool。"})]}),h.jsx("hr",{className:"border-border"})]}):null,a?h.jsxs(h.Fragment,{children:[h.jsx(Nre,{onLoad:a,...l?{onSave:l}:{},onDirtyChange:w,initialPersonality:u,readOnly:f}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(kre,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(Cre,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(Ere,{plugins:e.plugins??[]})]})]})]}):null}function xre({qrUrl:e,busy:t,onCancel:n}){const[r,i]=g.useState(null);return g.useEffect(()=>{let s=!1;return Iu.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(Np,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",onInteractOutside:s=>s.preventDefault(),onEscapeKeyDown:s=>s.preventDefault(),children:[h.jsx(Tp,{children:h.jsx(Pp,{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 yre={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},bre=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function wre({status:e,onProvision:t,onCancelProvision:n,onBindManual:r,onUnbind:i}){const[s,o]=g.useState(!1),[a,l]=g.useState(null),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,m]=g.useState(null),v=x=>{x&&(o(!0),l(null),x().catch(y=>l(y instanceof Error?y.message:String(y))).finally(()=>o(!1)))},b=()=>{m(null),v(t)},_=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(Kf,{className:"h-3.5 w-3.5 text-text-400","aria-hidden":!0}),h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"飞书 Bot"})]});return e?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,e.state==="unbound"||e.state==="provisioning"?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"关联一个飞书 bot 后,这个 persona 就是它:拉进群后群成员 @ 它提问、或直接私聊它, 推理跑在你本机,回复自动发回去。"}),t?h.jsx("button",{type:"button",disabled:s||e.state==="provisioning",onClick:b,className:"self-start rounded border border-border bg-bg-200 px-3 py-1.5 text-[12px] font-medium text-text-100 hover:bg-bg-300 disabled:opacity-50","data-testid":"lark-bot-provision",children:e.state==="provisioning"?"等待扫码…":"扫码关联飞书 Bot"}):null,e.state==="unbound"&&e.errorReason&&!p?h.jsxs("div",{className:"flex flex-col gap-1.5 rounded border border-error bg-error-dim px-2 py-1.5","data-testid":"lark-bot-provision-error",children:[h.jsx("span",{className:"text-[11px] text-error",children:yre[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[bre.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(xre,{qrUrl:e.qrUrl,busy:s,onCancel:n?()=>v(n):void 0}):null,r&&e.state==="unbound"?h.jsxs("details",{"data-testid":"lark-bot-manual-details",children:[h.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400 hover:text-text-300",children:"已有飞书应用?手动填入凭证"}),h.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),h.jsx("input",{value:c,onChange:x=>u(x.target.value),placeholder:"App ID(cli_ 开头)",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-appid"}),h.jsx("input",{value:d,onChange:x=>f(x.target.value),type:"password",placeholder:"App Secret",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-secret"}),h.jsx("button",{type:"button",disabled:s||!c||!d,onClick:()=>v(()=>r({appId:c,appSecret:d})),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-manual-submit",children:s?"绑定中…":"绑定"})]})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.state==="broken"?h.jsxs("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-broken",children:["Bot 凭证失效:",e.brokenReason??"未知原因","。请解绑后重新填入有效凭证绑定。"]}):null,h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-200",children:[h.jsx("span",{className:"font-medium text-text-100",children:e.botName??"未命名 bot"}),e.appId?h.jsx("span",{className:"text-[11px] text-text-400",children:e.appId}):null]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"把 bot 拉进任意飞书群,群成员 @ 它即可提问。"}),e.groups.length>0?h.jsx("ul",{className:"flex flex-col gap-0.5","data-testid":"lark-bot-groups",children:e.groups.map(x=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",x.chatName??x.chatId]},x.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),i?h.jsx("button",{type:"button",disabled:s,onClick:()=>v(i),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-error hover:bg-error-dim disabled:opacity-50","data-testid":"lark-bot-unbind",children:"解绑"}):null]}):null,a?h.jsx("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-error",children:a}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[_,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function Sre({checked:e,onChange:t}){return h.jsx("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(!e),"data-testid":"persona-public-toggle",className:le("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:le("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5")})})}function kre({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(Pd,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(Pd,{label:"沙箱启用",value:xg((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(Pd,{label:"沙箱内自动放行 Bash",value:xg((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(Pd,{label:"允许非沙箱命令",value:xg((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(Ol,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(Ol,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(Ol,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(Ol,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(Ol,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function xg(e){return e===!0?"是":e===!1?"否":"—"}function Pd({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 Ol({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 Cre({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 Ere({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 Nre({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1}){const s=r!==void 0,[o,a]=g.useState(s),[l,c]=g.useState(s?r:""),[u,d]=g.useState(s?r:""),[f,p]=g.useState(null),[m,v]=g.useState(!1),[b,_]=g.useState(null),x=st.useRef(e),y=st.useRef(t),w=st.useRef(n);st.useEffect(()=>{x.current=e,y.current=t,w.current=n});const S=st.useCallback(()=>{a(!1),p(null),x.current().then(B=>{c(B),d(B),a(!0)}).catch(B=>{p(B instanceof Error?B.message:String(B))})},[]);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),_(null),y.current(u).then(()=>{c(u),v(!1)}).catch(B=>{_(B instanceof Error?B.message:String(B)),v(!1)}))},T=()=>{d(l),_(null)};return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-personality-section",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"人格 (Personality)"}),f?h.jsxs("div",{"data-testid":"persona-personality-load-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error flex items-center justify-between gap-2",children:[h.jsxs("span",{children:["加载失败:",f]}),h.jsx("button",{type:"button",onClick:S,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,b?h.jsxs("div",{"data-testid":"persona-personality-save-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",b]}):null,h.jsx("textarea",{"data-testid":"persona-personality-textarea",value:u,onChange:B=>d(B.target.value),readOnly:i,disabled:!i&&(!o||m),placeholder:o?"":"加载中…",rows:8,className:"min-h-[8rem] max-h-[18rem] resize-y rounded-md border border-border bg-bg-100 px-2 py-1.5 font-mono text-[11px] text-text-100 disabled:opacity-60"}),!i&&h.jsxs("p",{className:"text-[10px] text-text-400",children:["写入到 ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/CLAUDE.md"}),"。 修改只对新启动的 sub-session 生效。"]}),o&&C?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:T,disabled:m,className:"rounded-sm border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200 disabled:opacity-60",children:"放弃"}),h.jsx("button",{type:"button",onClick:N,disabled:m,"data-testid":"persona-personality-save-btn",className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:m?"保存中…":"保存"})]}):null]})}const Tre={state:"unbound",groups:[]};function Pre(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(Tre)}};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 Ire({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const{persona:l}=kT(e),c=TB(e),u=PB(),d=IB(),{httpBaseUrl:f}=qf(),p=$i(),m=Pre(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(C=>{u(e,{public:C}).catch(N=>{Le("persona","togglePublic failed",N)})},[u,e]),_=g.useCallback(C=>{u(e,{tool:C}).catch(N=>{Le("persona","changeTool failed",N)})},[u,e]),x=g.useCallback(()=>{l&&confirm(`删除 persona "${l.label}"?`)&&(d(e).catch(C=>{Le("persona","delete failed",C)}),n())},[l,d,e,n]),y=g.useCallback(async()=>c.loaded?c.personality:(await c.refresh()).personality,[c]),w=g.useCallback(async C=>{await u(e,{personality:C}),await c.refresh()},[u,e,c]);if(!l)return null;const S=a==="guest";return h.jsx(_re,{embedded:i,persona:{...l,skills:c.skills,plugins:c.plugins,sandboxSettings:c.sandboxSettings},open:t,onClose:n,onLoadPersonality:y,onDirtyChange:s,readOnly:S,...S?{}:{onTogglePublic:b,guestShareUrl:v,onChangeTool:_,onDelete:x,onSavePersonality:w,larkBot:{status:m.status,onProvision:m.provision,onCancelProvision:m.cancelProvision,onBindManual:m.bindManual,onUnbind:m.unbind},...o?{onShareCapability:o}:{}}})}function Rre(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 Mre(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 Mre(s.url,Rre(t.url))}async function Are(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 Lre(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 jre={...Qc,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 Dre(e){const t=e.split("/");return t[t.length-1]||e}function yA({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:Dre(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(Xc,{remarkPlugins:[Zc],components:jre,children:i})}):null})]})}function Ore({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(yA,{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(IT,{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(br,{className:"h-4 w-4"})})]})})}):null}function Bre({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 zre=6173,$re=6182;function Fre({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=zre;v<=$re;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(Np,{className:"max-w-md",children:[h.jsxs(Tp,{children:[h.jsxs(Pp,{children:["改端口 · ",n]}),h.jsxs(xA,{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(ni,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ni,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const PC=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function Hre({currentStage:e,onCancel:t}){const n=PC.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:[PC.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(Gf,{className:"size-3.5"}):o?h.jsx(er,{className:"size-3.5 animate-spin"}):h.jsx(NT,{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 Ure={build:"构建",deploy:"部署",verify:"验证"};function Wre({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(Hc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",Ure[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 Vre={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function qre({stage:e,onFocusChat:t,onClose:n}){return h.jsxs("div",{"data-testid":"publish-failed-banner",className:"flex items-center gap-2 border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[12px]",children:[h.jsx(As,{className:"size-3.5 text-destructive"}),h.jsxs("button",{type:"button",onClick:t,className:"flex-1 text-left text-text-200 hover:underline",children:["发布失败:",h.jsxs("strong",{className:"font-medium",children:["[",Vre[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(br,{className:"size-3.5"})})]})}const IC={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function Kre({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(Fc,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(ny,{children:[h.jsx(ry,{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(n$,{className:"size-3.5"})})}),h.jsxs(op,{align:"end",children:[h.jsx(bi,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(bi,{disabled:!0,title:"rename not supported yet",onSelect:y=>y.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(qre,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((_=e.publishJob)==null?void 0:_.status)==="in-flight"?h.jsx(Hre,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((x=e.publishJob)==null?void 0:x.status)==="interrupted"?h.jsx(Wre,{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(Gre,{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(RC,{label:"等 tunnel 起来…",step:"-"}):h.jsx(RC,{label:IC[m].label,step:IC[m].step})}),h.jsx(Fre,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async y=>{await r(y)}})]})}function RC({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(er,{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 Gre({reason:e}){return h.jsxs("div",{"data-testid":"preview-failed",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(As,{className:"size-6 text-destructive"}),h.jsx("div",{className:"text-[13px] text-text-200",children:"project 启动失败"}),h.jsx("div",{className:"max-w-[400px] text-[12px] text-text-400",children:e??"未知原因 —— 看 ~/.clawd/clawd.log 排查"}),h.jsx("div",{className:"mt-1 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度 / 跟它说怎么修"})]})}function Xre({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(Np,{className:"max-w-lg",children:[h.jsx(Tp,{children:h.jsx(Pp,{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(ni,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(To,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(pu,{className:"size-3.5"}),"复制"]})}),h.jsx(ni,{onClick:t,children:"关闭"})]})]})})}function Yre(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 Zre={codex:"on-request",claude:"bypassPermissions"};function Qre(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??Zre[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function Jre(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...Qre({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=>Le("quick-ask","fork rollback failed",o)),s}return i}async function eie(e,t,n){return Jre(e,t,n,{ephemeral:!0})}function Id(e){return e!=null&&e.ephemeral!==!1}async function tie(e,t){return t.stillEphemeral?(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0):!1}function nie(){return{quickAsk:null,mds:[],active:null}}function rie(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function iie(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function sie(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 oie(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function aie(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 lie(e,t){return{...e,active:t}}function cie(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function bA(e){return e.quickAsk!==null||e.mds.length>0}function uie(e){return e.split("/").pop()||e}function die({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onPromoteQuickAsk:a}){if(!bA(e))return null;const l=[];e.quickAsk&&l.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(r0,{className:"w-3.5 h-3.5"})});for(const c of e.mds)l.push({id:{kind:"md",relPath:c},label:uie(c),title:c,icon:h.jsx(Po,{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(L5,{delayDuration:200,skipDelayDuration:100,children:h.jsx("div",{className:["flex items-stretch h-9 border-b border-text-100/10 shrink-0 overflow-x-auto","[scrollbar-width:none] [-ms-overflow-style:none]","[&::-webkit-scrollbar]:hidden"].join(" "),role:"tablist",children:l.map(c=>{const u=cie(e.active,c.id),d=c.id==="quick-ask"?"quick-ask":`md:${c.id.relPath}`;return h.jsxs(j5,{children:[h.jsx(D5,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":u,"data-tab-title":c.title,onClick:()=>n(c.id),className:["group relative flex items-center gap-2 px-3 h-full cursor-pointer select-none","text-[12px] max-w-[180px] shrink-0 transition-colors duration-100",u?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[c.icon,h.jsx("span",{className:"truncate",children:c.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${c.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",u?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:f=>{f.stopPropagation(),c.id==="quick-ask"?r():i(c.id.relPath)},children:h.jsx(br,{className:"w-3 h-3"})}),u?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Vy,{side:"bottom",align:"start",className:"max-w-sm break-all",children:c.title})]},d)})})}),h.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[e.quickAsk&&o?h.jsx("div",{className:"absolute inset-0",style:{display:e.active==="quick-ask"?"block":"none"},children:h.jsx(fie,{session:o,api:t,...a?{onPromoteQuickAsk:a}:{}})}):null,e.mds.map(c=>{const u=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===c;return h.jsx("div",{className:"absolute inset-0",style:{display:u?"block":"none"},children:h.jsx(yA,{relPath:c,loadMarkdown:s,showTitleBar:!1})},`md-body:${c}`)})]})]})}function hie({state:e,extras:t}){const{api:n,session:r}=t,i=$i(),[s,o]=g.useState(nie()),a=g.useRef(s);a.current=s;const l=g.useRef(!1),c=g.useCallback(async S=>{const C=a.current.quickAsk,N=await eie(n,r,S);if(N){if(l.current){n.sessionDelete(N.sessionId).catch(()=>{});return}Id(C)&&n.sessionDelete(C.sessionId).catch(()=>{}),o(T=>rie(T,{sessionId:N.sessionId}))}},[n,r]),u=g.useCallback(async S=>{const C=a.current.quickAsk,N=(C==null?void 0:C.sessionId)===S;try{await tie(n,{sessionId:S,stillEphemeral:N&&Id(C)})&&o(B=>oie(B))}catch(T){Le("quick-ask","promote failed",T)}},[n]),d=g.useCallback(S=>{o(C=>iie(C,S))},[]),f=g.useCallback(S=>{o(C=>lie(C,S))},[]),p=g.useCallback(()=>{const S=a.current.quickAsk;Id(S)&&n.sessionDelete(S.sessionId).catch(()=>{}),o(C=>sie(C))},[n]),m=g.useCallback(S=>{o(C=>aie(C,S))},[]);g.useEffect(()=>()=>{l.current=!0;const S=a.current.quickAsk;Id(S)&&n.sessionDelete(S.sessionId).catch(()=>{})},[]);const v=si("sessions")??[],b=s.quickAsk?v.find(S=>S.sessionId===s.quickAsk.sessionId)??{sessionId:s.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,_=g.useCallback(async S=>{const C=await n1(n,i,r.sessionId,S,60),N=await fetch(C);if(!N.ok)throw new Error(`fetch ${N.status} ${N.statusText}`);return N.text()},[n,i,r.sessionId]),x=h.jsx(r1,{state:e,extras:t,onQuickAskInternal:c,onPreviewMdInternal:d}),{initialSize:y,setSize:w}=TM("chat-panel-right-slot-width",480);return h.jsxs(ap,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Ha,{id:"chat",minSize:"400px",children:x}),bA(s)?h.jsxs(h.Fragment,{children:[h.jsx(fy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Ha,{id:"right-slot",defaultSize:`${y}px`,minSize:"360px",maxSize:"800px",onResize:S=>w(S.inPixels),children:h.jsx(die,{state:s,api:n,onSwitchTab:f,onCloseQuickAsk:p,onCloseMd:m,loadMarkdown:_,quickAskSession:b,onPromoteQuickAsk:u})})]}):null]})}function fie({session:e,api:t,onPromoteQuickAsk:n}){const r=k5(e.sessionId);return h.jsx(r1,{state:r,extras:{session:e,api:t,...n?{onPromoteQuickAsk:n}:{}}})}function pie({extras:e}){const t=k5(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(r1,{state:t,extras:e});return h.jsx(mie,{state:t,chat:n,extras:e})}return h.jsx(hie,{state:t,extras:e})}function mie({state:e,chat:t,extras:n}){var T;const r=si("daemon-info"),i=$i(),s=n.api,o=n.session,a=o.appBuilderProject,[l,c]=g.useState(null),u=g.useCallback(()=>{s.appBuilderGetProject(o.sessionId).then(B=>c(B.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(B=>f(B.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const L=P;L!=null&&L.project&&(L.project.name===a&&c(L.project),f(I=>{const R=I.findIndex(z=>z.name===L.project.name);if(R<0)return[...I,L.project];const j=I.slice();return j[R]=L.project,j}))}),[i,a]);const{host:m,scheme:v}=Yre(i.url,r==null?void 0:r.tunnelUrl),[b,_]=g.useState(void 0),[x,y]=g.useState(null);g.useEffect(()=>{const B=i.on("appBuilder:publish-progress",L=>{const I=L;!I||I.name!==a||I.status==="started"&&_(I.stage)}),P=i.on("appBuilder:publish-failed",L=>{const I=L;!I||I.name!==a||(_(void 0),y({stage:I.stage}))});return()=>{B(),P()}},[i,a]),g.useEffect(()=>{_(void 0),y(null)},[a]);const[w,S]=g.useState(null),C=h.jsx("button",{type:"button",className:"rounded bg-accent-main-100 px-2.5 py-1 text-[12px] text-oncolor-100 hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",disabled:((T=l==null?void 0:l.publishJob)==null?void 0:T.status)==="in-flight",onClick:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"发布请求失败",message:(B==null?void 0:B.message)??String(B)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(Bre,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(Kre,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(B=>B.port),onUpdatePort:async B=>{await s.appBuilderUpdateProjectPort(a,B),p()},publishSlot:C,publishInFlightStage:b,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(B){S({title:"取消发布失败",message:(B==null?void 0:B.message)??String(B)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(B){S({title:"重新发布失败",message:(B==null?void 0:B.message)??String(B)})}},publishFailureBanner:x,onPublishFailureBannerClose:()=>y(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(Xre,{error:w,onClose:()=>S(null)})]})}function gie({headerMeta:e,connState:t,liveWorktreeRoot:n,onOpenConfig:r,variant:i="full",ephemeral:s,onPromote:o,infoPanelOpen:a=!1,onToggleInfoPanel:l,infoPanel:c,infoPanelDefaultPx:u,onInfoPanelResize:d,lines:f,pendingPermissions:p,procAlive:m,rewindableUserMessageIds:v,onPermissionRespond:b,onPermissionInterrupt:_,onRewind:x,onFork:y,onQuickAsk:w,topSlot:S,realtimeQuestionAnswers:C,onSubmitQuestion:N,onCancelQuestion:T,liveQuestionToolUseIds:B,api:P,cwd:L,tool:I,sessionKey:R,onSend:j,awaitingUser:z,onAbort:$,onNewSession:F,onClearSession:O,configSlot:D,chatRootRef:E,chatBodyRef:H,topSentinelRef:V,drawers:A,xtermSlot:re,fileSharingScope:ie,onShareFile:G,onOpenInTab:ve,onPreviewMarkdown:Ie}){return h.jsx(mZ,{children:h.jsxs(ap,{orientation:"horizontal",className:"flex h-full min-w-0 min-h-0",children:[h.jsx(Ha,{id:"chat",minSize:"360px",children:h.jsxs("div",{ref:E,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(oQ,{meta:e,...I?{tool:I}:{},connState:t,variant:i,...n!==void 0?{liveWorktreeRoot:n}:{},...i==="full"&&r?{onOpenConfig:r}:{},...i==="full"&&l?{infoPanelOpen:a,onToggleInfoPanel:l}:{},...i==="quickask"?{ephemeral:s??!1,...o?{onPromote:o}:{}}:{}}),h.jsxs("div",{ref:H,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[V?h.jsx("div",{ref:V,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx(kM,{lines:f,...b?{onPermissionRespond:b}:{},..._&&m?{onPermissionInterrupt:_}:{},topSlot:S,...x?{onRewind:x}:{},rewindableUserMessageIds:v,...y?{onFork:y}:{},...w?{onQuickAsk:w}:{},realtimeQuestionAnswers:C,onSubmitQuestion:N,...T?{onCancelQuestion:T}:{},liveQuestionToolUseIds:B,...ie?{fileSharingScope:ie}:{},...G?{onShareFile:G}:{},...ve?{onOpenInTab:ve}:{},...Ie?{onPreviewMarkdown:Ie}:{}})]}),re,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(iQ,{meta:e,...P?{api:P}:{},cwd:L,...I?{tool:I}:{},sessionKey:R,onSend:j,awaitingUser:z,...$?{onAbort:$}:{},...F?{onNewSession:F}:{},...O?{onClearSession:O}:{},...D?{configSlot:D}:{}}),A]})}),a&&c?h.jsxs(h.Fragment,{children:[h.jsx(fy,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Ha,{id:"session-info",defaultSize:`${u??320}px`,minSize:"280px",maxSize:"480px",...d?{onResize:oe=>d(oe.inPixels)}:{},children:c})]}):null]})})}function r1({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,liveGitBranch:o,liveWorktreeRoot:a,onNewSession:l,onTurnEnd:c,onOpenConfig:u,onFork:d,onQuickAsk:f,viewerRole:p,onPromoteQuickAsk:m,configSlot:v}=t,{capabilities:b}=S5(i.tool||"claude"),_=(b==null?void 0:b.features)??xT(i.tool),[x,y]=g.useState(null),[w,S]=g.useState(null),C=qf(),N=!!s&&C.actionsLevel==="owner"&&_.fileSharing,T=kT(i.ownerPersonaId??null).persona,B=(T==null?void 0:T.label)??null,P=!!B&&!!i.ownerPersonaId,L=g.useCallback((q,de)=>{y({kind:q,text:de}),setTimeout(()=>{y(pe=>(pe==null?void 0:pe.text)===de?null:pe)},2e3)},[]),I=$i(),R=sB(),j=w5(i.sessionId,i.toolSessionId),{events:z,pendingQuestions:$,clearQuestion:F,markQuestionSubmitted:O,status:D}=j,E=e.historyLoading,H=RM(D);g.useEffect(()=>{Le("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:D,procAlive:H})},[D,H,i.sessionId]);const V=e.lines,A=e.pendingPermissions,re=A[0]??null,ie=g.useMemo(()=>bU(z),[z]),[G,ve]=g.useState(null),[Ie,oe]=g.useState(()=>new Set);_U(s,i.sessionId,i.toolSessionId,_.observe);const je=g.useRef(i.sessionId);g.useEffect(()=>{if(je.current=i.sessionId,!_.rewind){ve(null);return}let q=!1;return ve(null),(async()=>{try{const de=await s.sessionRewindableMessageIds(i.sessionId);if(q)return;ve(new Set(de.userMessageIds))}catch{q||ve(null)}})(),()=>{q=!0}},[s,i.sessionId,_.rewind]);const Ke=g.useCallback(()=>{const q=i.sessionId;s.sessionRewindableMessageIds(q).then(de=>{je.current===q&&ve(new Set(de.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),Ue=g.useMemo(()=>{if(G!==null){const Ze=new Set(G);for(const qi of Ie)Ze.delete(qi);return Ze}const q=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),de=new Set;let pe=null;for(const Ze of V)Ze.kind==="user-text"?pe=Ze.uuid??null:pe&&Ze.kind==="tool-call"&&q.has(Ze.tool)&&!Ie.has(pe)&&de.add(pe);return de},[V,Ie,G]),_e=g.useRef(c);_e.current=c,xU(i.sessionId,i.toolSessionId,()=>{zt(null),oe(new Set)});const $e=kQ({sessionStatus:D}),un=g.useRef(null);g.useEffect(()=>{var pe;const q=un.current,de=(q==null?void 0:q.sid)===i.sessionId;de&&q.phase===$e||(un.current={sid:i.sessionId,phase:$e},Le("session-phase",$e,{sid:i.sessionId,phase:$e,prev:de?q.phase:null,desc:SQ[$e]}),de&&q.phase==="turn-running"&&$e!=="turn-running"&&((pe=_e.current)==null||pe.call(_e),Ke()))},[$e,i.sessionId,Ke]);const ht=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Nt,zt]=g.useState(null),$t=g.useCallback(q=>{zt(q)},[]),[Tt,Ye]=g.useState(!1),it=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),Ye(!1)},[s,i.sessionId]);g.useCallback(q=>{s.pinSession(i.sessionId,q).catch(de=>{Le("chat-panel","pinSession failed",{err:de==null?void 0:de.message})})},[s,i.sessionId]);const mt=m?"quickask":"full",[dn,bn]=g.useState(!1),{initialSize:U,setSize:Z}=TM("clawd:panel:session-info-px",320),xe=g.useRef(0),Te=g.useRef(null);g.useEffect(()=>{const q=de=>{if(de.key!=="Escape")return;if(!H){xe.current=0;return}if(de.isComposing)return;const Ze=de.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==Te.current)return;const qi=Date.now();qi-xe.current<2e3?(xe.current=0,Ye(!0)):(xe.current=qi,ht())};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[ht,H]);const Ae=g.useRef(null),Mt=g.useRef(null),Ft=g.useRef(!0),ne=g.useRef(null),te=g.useRef(0),ke=g.useRef(0);g.useEffect(()=>{Ft.current=!0,ne.current=null,te.current=0,ke.current=0},[i.sessionId]),g.useEffect(()=>{S(null)},[i.sessionId]);const tt=g.useRef(e);tt.current=e;const Fn=g.useCallback(()=>{var pe;const q=Ae.current;if(!q||ne.current!==null)return;const de=tt.current;de.historyDone||de.historyLoading||(ne.current={distFromBottom:q.scrollHeight-q.scrollTop},(pe=de.loadMoreHistory)==null||pe.call(de))},[]);g.useEffect(()=>{const q=Ae.current,de=Mt.current;if(!q||!de)return;const pe=new IntersectionObserver(Ze=>{for(const qi of Ze)qi.isIntersecting&&Fn()},{root:q,threshold:0});return pe.observe(de),()=>pe.disconnect()},[Fn]),g.useEffect(()=>{const q=Ae.current;if(!q)return;const de=150,pe=Ze=>{Date.now()<ke.current&&(Ze.preventDefault(),ke.current=Date.now()+de)};return q.addEventListener("wheel",pe,{passive:!1}),()=>q.removeEventListener("wheel",pe)},[]),g.useEffect(()=>{const q=Ae.current;if(!q)return;const de=32,pe=()=>{const Ze=q.scrollHeight-q.scrollTop-q.clientHeight;Ft.current=Ze<=de};return q.addEventListener("scroll",pe,{passive:!0}),()=>q.removeEventListener("scroll",pe)},[]),g.useLayoutEffect(()=>{const q=Ae.current;if(!q)return;const de=te.current,pe=V.length;te.current=pe;const Ze=ne.current;if(Ze!==null&&pe>de){ne.current=null,q.scrollTop=q.scrollHeight-Ze.distFromBottom,ke.current=Date.now()+200;return}Ze!==null&&(ne.current={distFromBottom:q.scrollHeight-q.scrollTop}),Ft.current&&(q.scrollTop=q.scrollHeight)},[V,re==null?void 0:re.requestId]);const Hn=g.useMemo(()=>{const q={};for(const[de,pe]of Object.entries($))pe.submittedAnswers&&(q[de]=pe.submittedAnswers);return q},[$]),Ip=g.useMemo(()=>new Set(Object.keys($)),[$]),Rp=g.useCallback(async(q,de)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:q,answers:de}),O(q,de)}catch{}},[s,i.sessionId,O]),Mp=g.useCallback(async q=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:q}),F(q)}catch{}},[s,i.sessionId,F]),Ap=g.useCallback(async(q,de)=>{var pe;if(re)try{await((pe=e.respondPermission)==null?void 0:pe.call(e,re.requestId,q?"allow":"deny"))}catch{}},[e,re]),Lp=g.useCallback(async()=>{const q=i.sessionId;try{await s.sessionStop(q)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(q)},[e,s,i.sessionId]),jp=g.useMemo(()=>E&&V.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(er,{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 q;return void((q=e.loadMoreHistory)==null?void 0:q.call(e))},disabled:E,"data-testid":"history-load-more",className:"text-[12px] text-text-400 hover:text-text-200 cursor-pointer px-3 py-1 rounded-md border border-bg-300 hover:bg-bg-100 transition-colors disabled:opacity-60",children:E?"加载中…":"Load earlier messages"})}),[E,V.length,e.historyDone,e.loadMoreHistory]),ml=e.meta,Oo=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(gQ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Nt&&_.rewind?h.jsx(_Q,{open:!0,onOpenChange:q=>{q||zt(null)},api:s,sessionId:i.sessionId,userMessageId:Nt,lines:V,procAlive:H,onNoChanges:q=>{oe(de=>{if(de.has(q))return de;const pe=new Set(de);return pe.add(q),pe})}}):null,Tt?h.jsx(vie,{onConfirm:it,onCancel:()=>Ye(!1)}):null]}),Bs={kind:"session",sessionId:i.sessionId},Bo=g.useCallback(async q=>{if(s)try{await Are(s,I,i.sessionId,q)}catch(de){const pe=de.message;Le("chat-panel","open-in-tab failed",{err:pe}),L("err",`Open in tab 失败:${pe}`)}},[s,I,i.sessionId,L]),[gl,fi]=g.useState(!1),[Or,Mu]=g.useState(null),Au=g.useCallback(q=>{if(r){r(q);return}Mu(q),fi(!0)},[r]),Ht=g.useCallback(async q=>{if(!s)throw new Error("daemon api not ready");const de=await n1(s,I,i.sessionId,q,60),pe=await fetch(de);if(!pe.ok)throw new Error(`fetch ${pe.status} ${pe.statusText}`);return await pe.text()},[s,I,i.sessionId]),zo=g.useCallback(async(q,de)=>{if(s)try{const{url:pe}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:q,ttlSeconds:86400,...de?{view:de}:{}}),Ze=await Lre(pe);L(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(pe){const Ze=pe.message;Le("chat-panel","share-file failed",{err:Ze}),L("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,L]),$o=g.useCallback(()=>S(null),[]),Pt=w==="files"&&N&&s?{title:"Edited Files",onBack:$o,content:h.jsx(hne,{api:s,scope:Bs,sessionId:i.sessionId,onShareFile:zo,onOpenInTab:Bo,onPreviewMarkdown:Au})}:w==="cron"?{title:`定时任务${ie.length?` (${ie.length})`:""}`,onBack:$o,content:h.jsx("div",{className:"p-3",children:h.jsx(wQ,{jobs:ie})})}:w==="persona"&&P&&s&&i.ownerPersonaId?{title:`Persona · ${B??""}`,onBack:$o,content:h.jsx(Ire,{personaId:i.ownerPersonaId,open:!0,onClose:$o,api:s,embedded:!0,...p?{viewerRole:p}:{}},i.ownerPersonaId)}:null;return h.jsxs(h.Fragment,{children:[h.jsx(gie,{headerMeta:ml,connState:e.connState,...a!==void 0?{liveWorktreeRoot:a}:{},...u?{onOpenConfig:u}:{},variant:mt,...mt==="quickask"?{ephemeral:i.ephemeral!==!1,onPromote:()=>void(m==null?void 0:m(i.sessionId))}:{infoPanelOpen:dn,onToggleInfoPanel:()=>bn(q=>!q),infoPanelDefaultPx:U,onInfoPanelResize:Z,infoPanel:h.jsx(cQ,{session:i,meta:ml,...o!==void 0?{liveGitBranch:o}:{},...a!==void 0?{liveWorktreeRoot:a}:{},...P?{personaName:B}:{},...P?{onOpenPersona:()=>S("persona")}:{},...N?{onOpenFiles:()=>S("files")}:{},cronActiveCount:ie.length,onCronClick:()=>S("cron"),onForceStop:()=>Ye(!0),...p?{viewerRole:p}:{},...b!=null&&b.toolSessionIdLabel?{toolSessionIdLabel:b.toolSessionIdLabel}:{},drill:Pt,onClose:()=>bn(!1)})},lines:V,pendingPermissions:A,procAlive:H,rewindableUserMessageIds:Ue,onPermissionRespond:Ap,onPermissionInterrupt:ht,onRewind:_.rewind?$t:void 0,...d&&_.fork?{onFork:d}:{},...n&&_.fork?{onQuickAsk:n}:f&&_.fork?{onQuickAsk:f}:{},topSlot:jp,realtimeQuestionAnswers:Hn,onSubmitQuestion:Rp,onCancelQuestion:Mp,liveQuestionToolUseIds:Ip,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:A.length>0||Object.values($).some(q=>!q.submittedAnswers),onAbort:ht,...l?{onNewSession:l}:{},onClearSession:Lp,...v?{configSlot:v}:{},chatRootRef:Te,chatBodyRef:Ae,topSentinelRef:Mt,drawers:Oo,xtermSlot:R==="tui"&&H&&_.tui?h.jsx(Bte,{sessionId:i.sessionId,client:I},i.sessionId):null,fileSharingScope:Bs,...s?{onShareFile:zo}:{},...s?{onOpenInTab:Bo}:{},...s?{onPreviewMarkdown:Au}:{}}),s?h.jsx(Ore,{open:gl,onOpenChange:fi,relPath:Or,loadMarkdown:Ht,onShare:Or?()=>void zo(Or,"md-rendered"):void 0}):null,x?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:x.kind==="ok"?"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-[12px] text-emerald-700 shadow-md dark:text-emerald-300":"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[12px] text-destructive shadow-md",children:x.text}):null]})}function vie({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(Hc,{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 _ie(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 wA(e,t,n){var l;if(!t)return n?wA(e,n):((l=(e??[]).find(c=>c.id===""))==null?void 0:l.label)??"未指定";const r=t.toLowerCase(),i=[["opus","Opus"],["fable","Fable"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[c,u]of i){if(!r.includes(c))continue;const d=r.match(new RegExp(`${c}-(\\d+)(?:-(\\d+))?`));return d?d[2]?`${u} ${d[1]}.${d[2]}`:`${u} ${d[1]}`:u}const s=e??[],o=s.find(c=>c.id===t);if(o)return o.label;const a=s.find(c=>c.id&&t.toLowerCase().includes(c.id.toLowerCase()));return a?a.label:t}function xie(e,t){var p,m,v,b;const{models:n,modes:r,configSchema:i}=t,s=_ie(e.model,n,i),o=s.options,a=o.some(_=>_.value===e.effort)?e.effort:s.defaultValue,l=e.effort===""&&e.resolvedEffort?((p=o.find(_=>_.value===e.resolvedEffort))==null?void 0:p.label)??e.resolvedEffort:((m=o.find(_=>_.value===a))==null?void 0:m.label)??null,c=((v=i.find(_=>_.name==="permissionMode"))==null?void 0:v.default)??"",u=r.some(_=>_.id===e.permissionMode)?e.permissionMode:c,f=u===c?null:((b=r.find(_=>_.id===u))==null?void 0:b.label)??null;return{modelLabel:wA(n,e.model,e.resolvedModel),effortOptions:o,effortValue:a,effortLabel:l,modeValue:u,modeLabel:f,modeTone:f===null?null:u==="bypassPermissions"?"danger":"info"}}function yie({models:e=[],modes:t=[],configSchema:n=[],model:r,effort:i,permissionMode:s,resolvedModel:o,resolvedEffort:a,onPatch:l}){var f;const c=xie({model:r,effort:i,permissionMode:s,...o?{resolvedModel:o}:{},...a?{resolvedEffort:a}:{}},{models:e,modes:t,configSchema:n}),u=e.map(p=>{const m=p.id===""&&o?`${p.description?`${p.description};`:""}当前:${o}`:p.description;return{value:p.id,label:p.label,...m?{description:m}:{}}}),d=t.map(p=>({value:p.id,label:p.label,...p.description?{description:p.description}:{}}));return h.jsxs(ny,{children:[h.jsx(ry,{asChild:!0,children:h.jsxs("button",{type:"button","data-testid":"session-config-chip",title:"Model / reasoning effort / permission mode",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:[h.jsx("span",{className:"truncate max-w-[120px]","data-testid":"session-config-chip-model",children:c.modelLabel}),c.effortLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"truncate max-w-[80px]","data-testid":"session-config-chip-effort",children:c.effortLabel})]}):null,c.modeLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{"data-testid":"session-config-chip-mode","data-tone":c.modeTone,className:le("font-semibold",c.modeTone==="danger"?"text-red-400":"text-blue-400"),children:c.modeLabel})]}):null]})}),h.jsxs(op,{side:"top",align:"end",className:"w-[230px]","data-testid":"session-config-menu",children:[h.jsx(yg,{testid:"session-config-model",label:"Model",current:r,currentLabel:c.modelLabel,options:u,onSelect:p=>l({model:p})}),h.jsx(yg,{testid:"session-config-effort",label:"Reasoning effort",current:c.effortValue,currentLabel:c.effortLabel??"—",options:c.effortOptions,onSelect:p=>l({effort:p})}),d.length>0?h.jsx(yg,{testid:"session-config-mode",label:"Permission mode",current:c.modeValue,currentLabel:((f=t.find(p=>p.id===c.modeValue))==null?void 0:f.label)??"—",currentTone:c.modeTone,options:d,onSelect:p=>l({permissionMode:p})}):null]})]})}function yg({testid:e,label:t,current:n,currentLabel:r,currentTone:i,options:s,onSelect:o}){const a=s.length===0;return h.jsxs(xH,{children:[h.jsxs(FI,{"data-testid":e,disabled:a,className:"gap-2 text-[12px]",children:[h.jsx("span",{className:"flex-1 text-text-200",children:t}),h.jsx("span",{className:le("truncate max-w-[100px]",i==="danger"?"text-red-400 font-semibold":i==="info"?"text-blue-400 font-semibold":"text-text-400"),children:r}),h.jsx(jr,{className:"w-3.5 h-3.5 shrink-0 text-text-500"})]}),h.jsx(HI,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:s.map(l=>{const c=l.value===n;return h.jsxs(bi,{"data-testid":`${e}-option-${l.value||"default"}`,onSelect:()=>o(l.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsx("span",{className:le("block text-[12px]",c?"text-text-100 font-medium":"text-text-300"),children:l.label}),l.description?h.jsx("span",{className:"block text-[11px] text-text-400 mt-0.5",children:l.description}):null]}),c?h.jsx(To,{className:"w-3.5 h-3.5 shrink-0 text-accent mt-0.5"}):null]},l.value||"default")})})]})}function bie(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 wie(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 Sie({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onFork:l,onQuickAsk:c,className:u,viewerRole:d="owner"}){const{capabilities:f}=S5(t.tool),[p,m]=g.useState(0),{branch:v}=bie(e,t.cwd,p),{worktreeRoot:b}=wie(e,t.cwd,p),_=r>1,x=y=>{e.sessionUpdate(t.sessionId,y).catch(w=>{console.error("[session-config] session:update failed",t.sessionId,w)})};return h.jsxs("div",{className:`group/pane relative flex-1 ${u??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${_?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsx(ap,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:h.jsx(Ha,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(kie,{api:e,session:t,liveGitBranch:v,liveWorktreeRoot:b,onNewSession:o,onTurnEnd:()=>m(y=>y+1),onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:d,configSlot:f?h.jsx(yie,{models:f.models,modes:f.permissionModes,configSchema:f.configSchema,model:t.model??"",...t.resolvedModel?{resolvedModel:t.resolvedModel}:{},...t.resolvedEffort?{resolvedEffort:t.resolvedEffort}:{},effort:t.effort??"",permissionMode:t.permissionMode??"",onPatch:x}):null})})})}),_&&h.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),s()},className:"absolute top-1.5 right-1.5 z-10 p-1 rounded-md bg-bg-100/80 backdrop-blur-sm border border-border opacity-0 group-hover/pane:opacity-100 transition-opacity text-text-400 hover:text-text-100 hover:bg-bg-200","aria-label":"close pane","data-testid":`session-pane-close-${t.sessionId}`,children:h.jsx(br,{className:"w-3.5 h-3.5"})})]})}function kie({api:e,session:t,liveGitBranch:n,liveWorktreeRoot:r,onNewSession:i,onTurnEnd:s,onOpenConfig:o,onFork:a,onQuickAsk:l,viewerRole:c,configSlot:u}){return h.jsx(pie,{extras:{session:t,api:e,...n!==void 0?{liveGitBranch:n}:{},...r!==void 0?{liveWorktreeRoot:r}:{},onNewSession:i,onTurnEnd:s,onOpenConfig:o,...a?{onFork:d=>{a(d)}}:{},...l?{onQuickAsk:d=>{l(d)}}:{},...c?{viewerRole:c}:{},...u?{configSlot:u}:{}}})}function Cie({personas:e,sessions:t,api:n,selfPrincipalId:r,selectedPersonaId:i,selectedSessionId:s,selectedSession:o,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,onCloseSession:f}){return h.jsxs("div",{className:"flex h-screen min-h-0 bg-bg-50","data-testid":"guest-share-page",children:[h.jsx("aside",{className:"w-[280px] shrink-0 overflow-y-auto border-r border-border bg-bg-50",children:h.jsx(DH,{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(Sie,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},viewerRole:"guest"}):h.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-xs text-text-400","data-testid":"guest-share-empty",children:"选择左侧 persona 开始对话"})})]})}function Eie(){const e=$i(),t=g.useMemo(()=>new Tx(e),[e]),n=EB(e),{sessions:r,refresh:i}=NB(n),{personas:s}=ST(),o=AB(),a=g.useMemo(()=>{const w=window.location.pathname.match(/^\/s\/([^/]+)/);return w?decodeURIComponent(w[1]):null},[]),l=g.useMemo(()=>r.filter(w=>!w.ephemeral&&w.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(w=>w.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let w=!1;return e.request("whoami",{}).then(S=>{w||d(S.capability.id)}).catch(()=>{}),()=>{w=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const b=g.useCallback(async(w,S)=>{const C=await t.sessionCreate({ownerPersonaId:w,...S.trim()?{label:S.trim()}:{}});await i(),p(w),v(C.sessionId)},[t,i]),_=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(S=>S===w?null:S)},[t,i]),x=g.useCallback(async(w,S)=>{await t.sessionUpdate(w,{label:S.label}),await i()},[t,i]),y=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(Px.Provider,{value:o,children:h.jsx(Cie,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:y,onSelectPersona:p,onSelectSession:v,onCreateSession:(w,S)=>void b(w,S),onDeleteSession:w=>void _(w),onEditSession:(w,S)=>void x(w,S),onCloseSession:()=>v(null)})})}const MC="https://app.ttcadvisory.com";function Nie({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=`${MC}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==MC)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 v_="clawd-visitor:token";function Tie(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function Pie(){return{async getUrl(e){const t=localStorage.getItem(v_);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=Tie(window.location,{});return await pT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function Iie(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Rie(){const e=$i(),t=g.useMemo(()=>CB(e),[e]);return h.jsx(oB,{cache:t.cache,children:h.jsx(cB,{children:h.jsx(Eie,{})})})}function Mie({host:e}){const[t]=g.useState(()=>localStorage.getItem(v_)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>Iie(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return Pie().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(yb,{host:e,children:h.jsx(Jb,{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(iB,{host:e,children:h.jsx(Rie,{})}):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(yb,{host:e,children:h.jsx(Jb,{children:h.jsx(Nie,{onAuthed:o=>{localStorage.setItem(v_,o),window.location.reload()}})})})}function Aie({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):Lie(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:le("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 Lie(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 jie({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(Die,{status:t.status}),h.jsx("span",{className:le("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 Die({status:e}){return e==="completed"?h.jsx(Gf,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(er,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(NT,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function Oie(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 Bie({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(Kf,{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 zie(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 $ie={render:({input:e})=>st.createElement(jie,{items:Oie(e)})},Fie={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=zie(e);return st.createElement(Bie,{description:t,prompt:n,subagentType:r})}},SA={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Uie(e),c=l?st.createElement(Aie,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return st.createElement(_M,{tool:Hie(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function Hie(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Uie(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}}Cu.register("claude","TodoWrite",$ie);Cu.register("claude","Task",Fie);Cu.register("claude","Edit",SA);Cu.register("claude","Write",SA);const kA=document.getElementById("root");if(!kA)throw new Error("guest-main: #root not found");const Wie=iL({});bg.createRoot(kA).render(h.jsx(st.StrictMode,{children:h.jsx(Mie,{host:Wie})}));
|
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-CbgzevyF.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/share-ui/assets/guest-CwoBAbh2.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body style="margin: 0">
|