@kingsoftcloud/agentkit-personal-assistant 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
- (()=>{var Fe=Object.freeze({width:1280,height:800});function je(t={}){let g=Number(t.width)||Fe.width,l=Number(t.height)||Fe.height;return!Number.isFinite(g)||!Number.isFinite(l)||g<=0||l<=0?Fe:Object.freeze({width:Math.round(g),height:Math.round(l)})}function Je({clientX:t,clientY:g,rect:l,display:c=Fe}){let n=je(c),s=Number(l?.width)||n.width,o=Number(l?.height)||n.height,r=Number(l?.left)||0,u=Number(l?.top)||0,d=Math.min(s/n.width,o/n.height),E=r+(s-n.width*d)/2,A=u+(o-n.height*d)/2,w=Math.max(0,Math.min(n.width-1,Math.round((Number(t)-E)/d))),T=Math.max(0,Math.min(n.height-1,Math.round((Number(g)-A)/d)));return{x:w,y:T}}function Ze({send:t,changed:g=()=>{},failed:l=()=>{},setTimer:c=setTimeout,clearTimer:n=clearTimeout}={}){let s=!1,o=0,r="observe",u=!1,d=[],E="",A,w=()=>g({phase:r,readOnly:r!=="controlling",controlEpoch:o,available:s}),T=()=>{n(A),A=void 0;let m=E;E="",m&&r==="controlling"&&t({type:"input",controlEpoch:o,event:{type:"text",text:m}})},D=m=>{m.type==="text"?(E.length+m.text.length>16384&&T(),E+=m.text,A||(A=c(T,30))):(T(),t({type:"input",controlEpoch:o,event:m}))},S=()=>{r="acquiring",w(),t({type:"control.acquire",controlEpoch:o})},U=m=>{if(m.type==="pointermove"&&d.at(-1)?.type==="pointermove")d[d.length-1]=m;else if(d.length<32)d.push(m);else return $.release(),l("\u63A5\u7BA1\u671F\u95F4\u8F93\u5165\u8FC7\u5FEB\uFF0C\u8BF7\u91CD\u65B0\u70B9\u51FB\u4E91\u7535\u8111"),!1;return!0},$={get snapshot(){return{phase:r,readOnly:r!=="controlling",controlEpoch:o,available:s}},reset(m={}){n(A),A=void 0,E="",d=[],s=m.controlAvailable===!0,o=Number.isSafeInteger(m.controlEpoch)?m.controlEpoch:0,r=m.readOnly===!1?"controlling":"observe",u=r==="controlling",w()},input(m){return r==="controlling"?(D(m),!0):(!u||r==="observe")&&(m.type==="pointermove"||["button","key"].includes(m.type)&&m.action==="up")||m.type==="pointermove"&&r==="observe"?!1:s?(u=!0,U(m)?(r==="observe"&&S(),!0):!1):(m.type!=="pointermove"&&l("\u5F53\u524D\u4E3A\u53EA\u8BFB\u65C1\u89C2\uFF0C\u9F20\u6807\u548C\u952E\u76D8\u4E0D\u4F1A\u53D1\u9001\u5230\u4E91\u7535\u8111"),!1)},acquire(){return s?(u=!0,r==="observe"&&S(),!0):!1},release(){u=!1,d=[],r==="controlling"&&(T(),r="releasing",w(),t({type:"control.release",controlEpoch:o}))},accept(m){if(!Number.isSafeInteger(m.controlEpoch)||m.controlEpoch<o)return;if(m.controlEpoch!==o&&(n(A),A=void 0,E=""),o=m.controlEpoch,s=m.controlAvailable===!0,m.readOnly){r!=="releasing"&&(u=!1,d=[]),r="observe",w(),u&&s&&S();return}if(!u){d=[],r="releasing",w(),t({type:"control.release",controlEpoch:o});return}r="controlling",w();let ae=d;d=[];for(let X of ae)D(X)},reject(m){Number.isSafeInteger(m.controlEpoch)&&m.controlEpoch<o||(u=!1,d=[],n(A),A=void 0,E="",Number.isSafeInteger(m.controlEpoch)&&m.controlEpoch>=o&&(o=m.controlEpoch),r=m.readOnly===!1?"controlling":"observe",w(),l(m.message||"\u63A7\u5236\u6743\u6682\u4E0D\u53EF\u7528\uFF0C\u4ECD\u53EF\u7EE7\u7EED\u65C1\u89C2"))},dispose(){$.release(),n(A),A=void 0,E="",d=[]}};return $}var he=(t,g,l)=>Object.assign(new Error(g),{code:t,cause:l}),Et=t=>{try{return new TextEncoder().encode(t).length}catch{return t.length}},et=t=>typeof t=="string"?t:String(t?.text??"");async function We({clipboard:t}={}){let g=t||globalThis.navigator?.clipboard;if(!g||typeof g.readText!="function")throw he("CLIPBOARD_UNAVAILABLE","\u5F53\u524D\u73AF\u5883\u4E0D\u5141\u8BB8\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u70B9\u300C\u7C98\u8D34\u300D\u6309\u94AE\u518D\u8BD5");try{let l=await g.readText();return typeof l=="string"?l:""}catch(l){throw he("CLIPBOARD_READ_DENIED","\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u6309 \u2318V / Ctrl+V \u518D\u8BD5",l)}}async function vt(t,{clipboard:g}={}){let l=g||globalThis.navigator?.clipboard;if(!l||typeof l.writeText!="function")throw he("CLIPBOARD_UNAVAILABLE","\u5F53\u524D\u73AF\u5883\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u624B\u52A8\u590D\u5236");try{await l.writeText(String(t??""))}catch(c){throw he("CLIPBOARD_WRITE_DENIED","\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u91CD\u8BD5",c)}}function Tt(){return Object.freeze([Object.freeze({type:"key",action:"down",key:"Control_L"}),Object.freeze({type:"key",action:"down",key:"v"}),Object.freeze({type:"key",action:"up",key:"v"}),Object.freeze({type:"key",action:"up",key:"Control_L"})])}function Me(t){let g=String(t?.code||"");return["COMPUTER_LEASE_REQUIRED","DESKTOP_CONTROL_GRANT_REQUIRED","DESKTOP_READ_ONLY","DESKTOP_CONTROL_EPOCH_CHANGED"].includes(g)?"\u9700\u8981\u5148\u70B9\u753B\u9762\u63A5\u7BA1\u4E91\u7535\u8111\uFF0C\u624D\u80FD\u8BFB\u5199\u4E91\u7AEF\u526A\u8D34\u677F":["DESKTOP_SESSION_IDLE","DESKTOP_SESSION_NOT_FOUND","CLIPBOARD_CLOSED"].includes(g)?"\u4E91\u7535\u8111\u5DF2\u7A7A\u95F2\u6216\u65AD\u5F00\uFF0C\u8BF7\u5148\u6062\u590D\u753B\u9762\u518D\u8BD5":g==="CLIPBOARD_TEXT_TOO_LARGE"?"\u526A\u8D34\u677F\u5185\u5BB9\u8D85\u8FC7 64 KiB\uFF0C\u4E91\u7535\u8111\u526A\u8D34\u677F\u653E\u4E0D\u4E0B":["DESKTOP_UNAVAILABLE","DESKTOP_FRAME_FAILED","DESKTOP_SESSION_FAILED"].includes(g)?"\u4E91\u7535\u8111\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5":["CLIPBOARD_FAILED","CLOUD_SESSION_FAILED"].includes(g)?"\u526A\u8D34\u677F\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5":g==="CLIPBOARD_TEXT_INVALID"?"\u526A\u8D34\u677F\u5185\u5BB9\u683C\u5F0F\u4E0D\u88AB\u4E91\u7AEF\u63A5\u53D7\uFF0C\u8BF7\u91CD\u8BD5":t?.message?String(t.message):g?`\u526A\u8D34\u677F\u64CD\u4F5C\u5931\u8D25\uFF08${g}\uFF09`:"\u526A\u8D34\u677F\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"}var kt=0,At=()=>{let t=globalThis.crypto?.randomUUID?.();return t?`clip-${t}`:`clip-${Date.now().toString(36)}-${kt+=1}`};function tt({send:t,timeoutMs:g=5e3,controlEpoch:l,setTimer:c=setTimeout,clearTimer:n=clearTimeout}={}){let s=new Map,o=(u,d)=>{s.delete(u.id),n(u.timer),d()},r=(u,d)=>new Promise((E,A)=>{let w=At(),T=c(()=>{let U=s.get(w);U&&o(U,()=>A(he("CLIPBOARD_TIMEOUT","\u4E91\u7AEF\u52A9\u7406\u7248\u672C\u8F83\u65E7\uFF0C\u526A\u8D34\u677F\u901A\u9053\u672A\u542F\u7528\uFF08\u91CD\u65B0\u90E8\u7F72\u540E\u53EF\u7528\uFF09")))},g);s.set(w,{id:w,timer:T,resolve:E,reject:U=>A(U)});let D=!1,S;try{S=typeof l=="function"?l():void 0}catch{S=void 0}try{D=t({type:u,requestId:w,...Number.isSafeInteger(S)?{controlEpoch:S}:{},...d})!==!1}catch(U){o(s.get(w),()=>A(he("CLIPBOARD_UNAVAILABLE","\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u526A\u8D34\u677F\u6682\u4E0D\u53EF\u7528",U)));return}D||o(s.get(w),()=>A(he("CLIPBOARD_UNAVAILABLE","\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u526A\u8D34\u677F\u6682\u4E0D\u53EF\u7528")))});return Object.freeze({read:()=>r("clipboard.read").then(u=>({text:et(u)})),write:u=>r("clipboard.write",{text:String(u)}).then(d=>({written:d?.written!==!1})),accept(u){if(!u||u.type!=="clipboard.response")return!1;let d=s.get(String(u.requestId||""));return d?(o(d,()=>{u.ok!==!1?d.resolve(u.value):d.reject(he(u.error?.code||"CLIPBOARD_FAILED",u.error?.message||"",u.error))}),!0):!1},rejectAll(u=he("CLIPBOARD_CLOSED","\u4E91\u7535\u8111\u8FDE\u63A5\u5DF2\u65AD\u5F00\uFF0C\u526A\u8D34\u677F\u64CD\u4F5C\u672A\u5B8C\u6210")){for(let d of[...s.values()])o(d,()=>d.reject(u))},get size(){return s.size}})}function nt(t){return!t||String(t.key??"").toLowerCase()!=="v"||t.altKey||t.shiftKey||t.isComposing||t.nativeEvent?.isComposing?!1:t.metaKey===!0||t.ctrlKey===!0}function rt(t){return!t||String(t.key??"").toLowerCase()!=="c"||t.altKey||t.shiftKey||t.isComposing||t.nativeEvent?.isComposing?!1:t.metaKey===!0||t.ctrlKey===!0}async function ot({readLocal:t,writeCloud:g,sendKeys:l,notify:c=()=>{}}={}){let n=t||(()=>We()),s="";try{s=await n()}catch(o){return c(Me(o)||"\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u6309 \u2318V / Ctrl+V \u518D\u8BD5"),{ok:!1,code:o?.code||"CLIPBOARD_READ_FAILED"}}if(!s)return c("\u672C\u5730\u526A\u8D34\u677F\u662F\u7A7A\u7684\uFF0C\u6CA1\u6709\u53EF\u7C98\u8D34\u7684\u5185\u5BB9"),{ok:!1,code:"CLIPBOARD_EMPTY"};if(Et(s)>65536)return c("\u526A\u8D34\u677F\u5185\u5BB9\u8D85\u8FC7 64 KiB\uFF0C\u4E91\u7535\u8111\u526A\u8D34\u677F\u653E\u4E0D\u4E0B"),{ok:!1,code:"CLIPBOARD_TOO_LARGE"};try{await g(s)}catch(o){return c(Me(o)||"\u5199\u5165\u4E91\u7535\u8111\u526A\u8D34\u677F\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_WRITE_FAILED"}}if(typeof l=="function"){let o=!1;try{o=l(Tt())!==!1}catch(r){return{ok:!0,code:"CLIPBOARD_KEY_FAILED",error:r}}if(!o)return c("\u5DF2\u5199\u5165\u4E91\u7535\u8111\u526A\u8D34\u677F\uFF0C\u4F46\u5F53\u524D\u6CA1\u6709\u63A7\u5236\u6743\uFF1B\u63A5\u7BA1\u4E91\u7535\u8111\u540E\u518D\u6309 Ctrl+V"),{ok:!0,code:"CLIPBOARD_KEY_NOT_SENT"}}return c("\u5DF2\u7C98\u8D34\u5230\u4E91\u7535\u8111"),{ok:!0}}async function st({readCloud:t,writeLocal:g,notify:l=()=>{}}={}){let c=g||(o=>vt(o)),n;try{n=await t()}catch(o){return l(Me(o)||"\u8BFB\u53D6\u4E91\u7535\u8111\u526A\u8D34\u677F\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_READ_FAILED"}}let s=et(n);if(!s)return l("\u4E91\u7535\u8111\u526A\u8D34\u677F\u662F\u7A7A\u7684\uFF0C\u6CA1\u6709\u53EF\u590D\u5236\u7684\u5185\u5BB9"),{ok:!1,code:"CLIPBOARD_EMPTY"};try{await c(s)}catch(o){return l(Me(o)||"\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_WRITE_FAILED"}}return l("\u5DF2\u590D\u5236\u5230\u672C\u5730"),{ok:!0,text:s}}var _t=/^```\s*([\w+#.-]*)\s*$/u,Ct=/^(#{1,6})\s+(.*)$/u,at=/^\s*[-*+]\s+(.*)$/u,it=/^\s*(\d{1,3})[.)]\s+(.*)$/u,qe=/^\s*>\s?(.*)$/u,Rt=/^\s*([-*_])\s*(?:\1\s*){2,}$/u;function Dt(t){let l=(typeof t=="string"?t.replace(/\r\n?/gu,`
1
+ (()=>{var qe=Object.freeze({width:1280,height:800});function Qe(t={}){let g=Number(t.width)||qe.width,d=Number(t.height)||qe.height;return!Number.isFinite(g)||!Number.isFinite(d)||g<=0||d<=0?qe:Object.freeze({width:Math.round(g),height:Math.round(d)})}function ot({clientX:t,clientY:g,rect:d,display:r=qe}){let n=Qe(r),a=Number(d?.width)||n.width,s=Number(d?.height)||n.height,o=Number(d?.left)||0,f=Number(d?.top)||0,p=Math.min(a/n.width,s/n.height),E=o+(a-n.width*p)/2,D=f+(s-n.height*p)/2,S=Math.max(0,Math.min(n.width-1,Math.round((Number(t)-E)/p))),R=Math.max(0,Math.min(n.height-1,Math.round((Number(g)-D)/p)));return{x:S,y:R}}function st({send:t,changed:g=()=>{},failed:d=()=>{},setTimer:r=setTimeout,clearTimer:n=clearTimeout}={}){let a=!1,s=0,o="observe",f=!1,p=[],E="",D,S=()=>g({phase:o,readOnly:o!=="controlling",controlEpoch:s,available:a}),R=()=>{n(D),D=void 0;let v=E;E="",v&&o==="controlling"&&t({type:"input",controlEpoch:s,event:{type:"text",text:v}})},N=v=>{v.type==="text"?(E.length+v.text.length>16384&&R(),E+=v.text,D||(D=r(R,30))):(R(),t({type:"input",controlEpoch:s,event:v}))},T=()=>{o="acquiring",S(),t({type:"control.acquire",controlEpoch:s})},$=v=>{if(v.type==="pointermove"&&p.at(-1)?.type==="pointermove")p[p.length-1]=v;else if(p.length<32)p.push(v);else return ee.release(),d("\u63A5\u7BA1\u671F\u95F4\u8F93\u5165\u8FC7\u5FEB\uFF0C\u8BF7\u91CD\u65B0\u70B9\u51FB\u4E91\u7535\u8111"),!1;return!0},ee={get snapshot(){return{phase:o,readOnly:o!=="controlling",controlEpoch:s,available:a}},reset(v={}){n(D),D=void 0,E="",p=[],a=v.controlAvailable===!0,s=Number.isSafeInteger(v.controlEpoch)?v.controlEpoch:0,o=v.readOnly===!1?"controlling":"observe",f=o==="controlling",S()},input(v){return o==="controlling"?(N(v),!0):(!f||o==="observe")&&(v.type==="pointermove"||["button","key"].includes(v.type)&&v.action==="up")||v.type==="pointermove"&&o==="observe"?!1:a?(f=!0,$(v)?(o==="observe"&&T(),!0):!1):(v.type!=="pointermove"&&d("\u5F53\u524D\u4E3A\u53EA\u8BFB\u65C1\u89C2\uFF0C\u9F20\u6807\u548C\u952E\u76D8\u4E0D\u4F1A\u53D1\u9001\u5230\u4E91\u7535\u8111"),!1)},acquire(){return a?(f=!0,o==="observe"&&T(),!0):!1},release(){f=!1,p=[],o==="controlling"&&(R(),o="releasing",S(),t({type:"control.release",controlEpoch:s}))},accept(v){if(!Number.isSafeInteger(v.controlEpoch)||v.controlEpoch<s)return;if(v.controlEpoch!==s&&(n(D),D=void 0,E=""),s=v.controlEpoch,a=v.controlAvailable===!0,v.readOnly){o!=="releasing"&&(f=!1,p=[]),o="observe",S(),f&&a&&T();return}if(!f){p=[],o="releasing",S(),t({type:"control.release",controlEpoch:s});return}o="controlling",S();let ge=p;p=[];for(let X of ge)N(X)},reject(v){Number.isSafeInteger(v.controlEpoch)&&v.controlEpoch<s||(f=!1,p=[],n(D),D=void 0,E="",Number.isSafeInteger(v.controlEpoch)&&v.controlEpoch>=s&&(s=v.controlEpoch),o=v.readOnly===!1?"controlling":"observe",S(),d(v.message||"\u63A7\u5236\u6743\u6682\u4E0D\u53EF\u7528\uFF0C\u4ECD\u53EF\u7EE7\u7EED\u65C1\u89C2"))},dispose(){ee.release(),n(D),D=void 0,E="",p=[]}};return ee}var Re=(t,g,d)=>Object.assign(new Error(g),{code:t,cause:d}),Pt=t=>{try{return new TextEncoder().encode(t).length}catch{return t.length}},at=t=>typeof t=="string"?t:String(t?.text??"");async function Xe({clipboard:t}={}){let g=t||globalThis.navigator?.clipboard;if(!g||typeof g.readText!="function")throw Re("CLIPBOARD_UNAVAILABLE","\u5F53\u524D\u73AF\u5883\u4E0D\u5141\u8BB8\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u70B9\u300C\u7C98\u8D34\u300D\u6309\u94AE\u518D\u8BD5");try{let d=await g.readText();return typeof d=="string"?d:""}catch(d){throw Re("CLIPBOARD_READ_DENIED","\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u6309 \u2318V / Ctrl+V \u518D\u8BD5",d)}}async function Bt(t,{clipboard:g}={}){let d=g||globalThis.navigator?.clipboard;if(!d||typeof d.writeText!="function")throw Re("CLIPBOARD_UNAVAILABLE","\u5F53\u524D\u73AF\u5883\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u624B\u52A8\u590D\u5236");try{await d.writeText(String(t??""))}catch(r){throw Re("CLIPBOARD_WRITE_DENIED","\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u91CD\u8BD5",r)}}function zt(){return Object.freeze([Object.freeze({type:"key",action:"down",key:"Control_L"}),Object.freeze({type:"key",action:"down",key:"v"}),Object.freeze({type:"key",action:"up",key:"v"}),Object.freeze({type:"key",action:"up",key:"Control_L"})])}function Ke(t){let g=String(t?.code||"");return["COMPUTER_LEASE_REQUIRED","DESKTOP_CONTROL_GRANT_REQUIRED","DESKTOP_READ_ONLY","DESKTOP_CONTROL_EPOCH_CHANGED"].includes(g)?"\u9700\u8981\u5148\u70B9\u753B\u9762\u63A5\u7BA1\u4E91\u7535\u8111\uFF0C\u624D\u80FD\u8BFB\u5199\u4E91\u7AEF\u526A\u8D34\u677F":["DESKTOP_SESSION_IDLE","DESKTOP_SESSION_NOT_FOUND","CLIPBOARD_CLOSED"].includes(g)?"\u4E91\u7535\u8111\u5DF2\u7A7A\u95F2\u6216\u65AD\u5F00\uFF0C\u8BF7\u5148\u6062\u590D\u753B\u9762\u518D\u8BD5":g==="CLIPBOARD_TEXT_TOO_LARGE"?"\u526A\u8D34\u677F\u5185\u5BB9\u8D85\u8FC7 64 KiB\uFF0C\u4E91\u7535\u8111\u526A\u8D34\u677F\u653E\u4E0D\u4E0B":["DESKTOP_UNAVAILABLE","DESKTOP_FRAME_FAILED","DESKTOP_SESSION_FAILED"].includes(g)?"\u4E91\u7535\u8111\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5":["CLIPBOARD_FAILED","CLOUD_SESSION_FAILED"].includes(g)?"\u526A\u8D34\u677F\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5":g==="CLIPBOARD_TEXT_INVALID"?"\u526A\u8D34\u677F\u5185\u5BB9\u683C\u5F0F\u4E0D\u88AB\u4E91\u7AEF\u63A5\u53D7\uFF0C\u8BF7\u91CD\u8BD5":t?.message?String(t.message):g?`\u526A\u8D34\u677F\u64CD\u4F5C\u5931\u8D25\uFF08${g}\uFF09`:"\u526A\u8D34\u677F\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"}var Ut=0,Ft=()=>{let t=globalThis.crypto?.randomUUID?.();return t?`clip-${t}`:`clip-${Date.now().toString(36)}-${Ut+=1}`};function it({send:t,timeoutMs:g=5e3,controlEpoch:d,setTimer:r=setTimeout,clearTimer:n=clearTimeout}={}){let a=new Map,s=(f,p)=>{a.delete(f.id),n(f.timer),p()},o=(f,p)=>new Promise((E,D)=>{let S=Ft(),R=r(()=>{let $=a.get(S);$&&s($,()=>D(Re("CLIPBOARD_TIMEOUT","\u4E91\u7AEF\u52A9\u7406\u7248\u672C\u8F83\u65E7\uFF0C\u526A\u8D34\u677F\u901A\u9053\u672A\u542F\u7528\uFF08\u91CD\u65B0\u90E8\u7F72\u540E\u53EF\u7528\uFF09")))},g);a.set(S,{id:S,timer:R,resolve:E,reject:$=>D($)});let N=!1,T;try{T=typeof d=="function"?d():void 0}catch{T=void 0}try{N=t({type:f,requestId:S,...Number.isSafeInteger(T)?{controlEpoch:T}:{},...p})!==!1}catch($){s(a.get(S),()=>D(Re("CLIPBOARD_UNAVAILABLE","\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u526A\u8D34\u677F\u6682\u4E0D\u53EF\u7528",$)));return}N||s(a.get(S),()=>D(Re("CLIPBOARD_UNAVAILABLE","\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u526A\u8D34\u677F\u6682\u4E0D\u53EF\u7528")))});return Object.freeze({read:()=>o("clipboard.read").then(f=>({text:at(f)})),write:f=>o("clipboard.write",{text:String(f)}).then(p=>({written:p?.written!==!1})),accept(f){if(!f||f.type!=="clipboard.response")return!1;let p=a.get(String(f.requestId||""));return p?(s(p,()=>{f.ok!==!1?p.resolve(f.value):p.reject(Re(f.error?.code||"CLIPBOARD_FAILED",f.error?.message||"",f.error))}),!0):!1},rejectAll(f=Re("CLIPBOARD_CLOSED","\u4E91\u7535\u8111\u8FDE\u63A5\u5DF2\u65AD\u5F00\uFF0C\u526A\u8D34\u677F\u64CD\u4F5C\u672A\u5B8C\u6210")){for(let p of[...a.values()])s(p,()=>p.reject(f))},get size(){return a.size}})}function lt(t){return!t||String(t.key??"").toLowerCase()!=="v"||t.altKey||t.shiftKey||t.isComposing||t.nativeEvent?.isComposing?!1:t.metaKey===!0||t.ctrlKey===!0}function ct(t){return!t||String(t.key??"").toLowerCase()!=="c"||t.altKey||t.shiftKey||t.isComposing||t.nativeEvent?.isComposing?!1:t.metaKey===!0||t.ctrlKey===!0}async function dt({readLocal:t,writeCloud:g,sendKeys:d,notify:r=()=>{}}={}){let n=t||(()=>Xe()),a="";try{a=await n()}catch(s){return r(Ke(s)||"\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u8BFB\u53D6\u526A\u8D34\u677F\uFF0C\u8BF7\u6309 \u2318V / Ctrl+V \u518D\u8BD5"),{ok:!1,code:s?.code||"CLIPBOARD_READ_FAILED"}}if(!a)return r("\u672C\u5730\u526A\u8D34\u677F\u662F\u7A7A\u7684\uFF0C\u6CA1\u6709\u53EF\u7C98\u8D34\u7684\u5185\u5BB9"),{ok:!1,code:"CLIPBOARD_EMPTY"};if(Pt(a)>65536)return r("\u526A\u8D34\u677F\u5185\u5BB9\u8D85\u8FC7 64 KiB\uFF0C\u4E91\u7535\u8111\u526A\u8D34\u677F\u653E\u4E0D\u4E0B"),{ok:!1,code:"CLIPBOARD_TOO_LARGE"};try{await g(a)}catch(s){return r(Ke(s)||"\u5199\u5165\u4E91\u7535\u8111\u526A\u8D34\u677F\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_WRITE_FAILED"}}if(typeof d=="function"){let s=!1;try{s=d(zt())!==!1}catch(o){return{ok:!0,code:"CLIPBOARD_KEY_FAILED",error:o}}if(!s)return r("\u5DF2\u5199\u5165\u4E91\u7535\u8111\u526A\u8D34\u677F\uFF0C\u4F46\u5F53\u524D\u6CA1\u6709\u63A7\u5236\u6743\uFF1B\u63A5\u7BA1\u4E91\u7535\u8111\u540E\u518D\u6309 Ctrl+V"),{ok:!0,code:"CLIPBOARD_KEY_NOT_SENT"}}return r("\u5DF2\u7C98\u8D34\u5230\u4E91\u7535\u8111"),{ok:!0}}async function ut({readCloud:t,writeLocal:g,notify:d=()=>{}}={}){let r=g||(s=>Bt(s)),n;try{n=await t()}catch(s){return d(Ke(s)||"\u8BFB\u53D6\u4E91\u7535\u8111\u526A\u8D34\u677F\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_READ_FAILED"}}let a=at(n);if(!a)return d("\u4E91\u7535\u8111\u526A\u8D34\u677F\u662F\u7A7A\u7684\uFF0C\u6CA1\u6709\u53EF\u590D\u5236\u7684\u5185\u5BB9"),{ok:!1,code:"CLIPBOARD_EMPTY"};try{await r(a)}catch(s){return d(Ke(s)||"\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_WRITE_FAILED"}}return d("\u5DF2\u590D\u5236\u5230\u672C\u5730"),{ok:!0,text:a}}var Mt=/^```\s*([\w+#.-]*)\s*$/u,$t=/^(#{1,6})\s+(.*)$/u,pt=/^\s*[-*+]\s+(.*)$/u,ft=/^\s*(\d{1,3})[.)]\s+(.*)$/u,Ge=/^\s*>\s?(.*)$/u,jt=/^\s*([-*_])\s*(?:\1\s*){2,}$/u;function Wt(t){let d=(typeof t=="string"?t.replace(/\r\n?/gu,`
2
2
  `):"").split(`
3
- `),c=[],n=0,s=r=>{r.length!==0&&(c.push({type:"paragraph",text:r.join(`
4
- `)}),r.length=0)},o=[];for(;n<l.length;){let r=l[n],u=_t.exec(r);if(u){s(o);let T=[];for(n+=1;n<l.length&&!/^```\s*$/u.test(l[n]);)T.push(l[n]),n+=1;n+=1,c.push({type:"code",lang:u[1]||"",text:T.join(`
5
- `)});continue}if(r.trim()===""){s(o),n+=1;continue}let d=Ct.exec(r);if(d){s(o),c.push({type:"heading",level:d[1].length,text:d[2].trim()}),n+=1;continue}if(Rt.test(r)){s(o),c.push({type:"rule"}),n+=1;continue}let E=qe.exec(r);if(E){s(o);let T=[E[1]];for(n+=1;n<l.length&&qe.test(l[n]);)T.push(qe.exec(l[n])[1]),n+=1;c.push({type:"quote",text:T.join(`
6
- `)});continue}let A=at.exec(r),w=it.exec(r);if(A||w){s(o);let T={type:w?"ordered":"unordered",items:[],start:w?Number(w[1]):1};for(;n<l.length;){let D=at.exec(l[n]),S=it.exec(l[n]);if(!D&&!S)break;T.items.push((D?D[1]:S[2]).trim()),n+=1}c.push(T);continue}o.push(r),n+=1}return s(o),c}function Lt(t){let g=typeof t=="string"?t:"",l=[],c=s=>{s&&l.push({type:"text",text:s})},n=g;for(;n.length>0;){let s=/^`([^`]+)`/u.exec(n);if(s){l.push({type:"code",text:s[1]}),n=n.slice(s[0].length);continue}let o=/^\*\*([^*\n]+)\*\*/u.exec(n)||/^__([^_\n]+)__/u.exec(n);if(o){l.push({type:"strong",text:o[1]}),n=n.slice(o[0].length);continue}let r=/^\*([^*\s][^*\n]*)\*/u.exec(n)||/^_([^_\s][^_\n]*)_/u.exec(n);if(r){l.push({type:"em",text:r[1]}),n=n.slice(r[0].length);continue}let u=/^\[([^\]]+)\]\(([^)\s]+)\)/u.exec(n);if(u){l.push({type:"link",text:u[1],href:u[2]}),n=n.slice(u[0].length);continue}let d=n.slice(1).search(/[`*_[\]\n]/u),E=d<0?n.length:d+1;c(n.slice(0,E)),n=n.slice(E)}return l.reduce((s,o)=>{let r=s[s.length-1];return o.type==="text"&&r&&r.type==="text"?s[s.length-1]={type:"text",text:r.text+o.text}:s.push(o),s},[])}function lt(t,g,l={}){let c=Dt(g);if(c.length===0)return null;let n=(s,o)=>Lt(s).map((r,u)=>{let d=`${o}-i${u}`;return r.type==="code"?t("code",{key:d,style:l.inlineCode},r.text):r.type==="strong"?t("strong",{key:d},r.text):r.type==="em"?t("em",{key:d},r.text):r.type==="link"?/^(https?:|mailto:|cloud-file:)/iu.test(r.href)?t("a",{key:d,href:r.href,target:"_blank",rel:"noreferrer noopener",style:l.link},r.text):t("span",{key:d},r.text):t("span",{key:d},r.text)});return c.map((s,o)=>{let r=`b${o}`;if(s.type==="code")return t("pre",{key:r,style:l.codeBlock},t("code",null,s.text));if(s.type==="heading")return t("div",{key:r,style:{...l.heading,...s.level<=2?l.headingStrong:null}},n(s.text,r));if(s.type==="rule")return t("hr",{key:r,style:l.rule});if(s.type==="quote")return t("blockquote",{key:r,style:l.quote},n(s.text,r));if(s.type==="unordered"||s.type==="ordered"){let u=s.type==="ordered"?"ol":"ul";return t(u,{key:r,style:l.list,start:s.type==="ordered"&&s.start!==1?s.start:void 0},s.items.map((d,E)=>t("li",{key:`${r}-l${E}`},n(d,`${r}-l${E}`))))}return t("p",{key:r,style:l.paragraph},n(s.text,r))})}var Ot="\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u4F60\uFF1F",Nt=400,Pt=8,ct=1500,x={page:{flex:"1 1 0px",height:"100%",maxHeight:"100%",minHeight:0,minWidth:0,overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column",fontSize:13,color:"var(--dsw-alias-label-primary, #17202c)",background:"var(--dsw-alias-bg-layer-1, #fff)"},header:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:10,padding:"10px 16px",borderBottom:"1px solid var(--dsw-alias-border-default, #d8dee8)",flex:"none"},title:{margin:0,fontSize:14,fontWeight:600},status:{color:"var(--dsw-alias-label-secondary, #536174)",fontSize:12},spacer:{marginLeft:"auto"},ghost:{border:"1px solid var(--dsw-alias-border-default, #d8dee8)",background:"transparent",color:"inherit",borderRadius:8,padding:"5px 10px",cursor:"pointer",font:"inherit",fontSize:12},scroller:{flex:"1 1 0px",minHeight:0,minWidth:0,overflowY:"auto",overflowX:"hidden",overscrollBehavior:"contain",boxSizing:"border-box",padding:"20px 16px 8px"},thread:{maxWidth:720,margin:"0 auto",display:"flex",flexDirection:"column",gap:14},row:{display:"flex",flexDirection:"column",gap:4,alignItems:"flex-start"},rowUser:{display:"flex",flexDirection:"column",gap:4,alignItems:"flex-end"},who:{fontSize:11,color:"var(--dsw-alias-label-secondary, #536174)"},bubble:{maxWidth:"86%",padding:"9px 12px",borderRadius:12,lineHeight:1.7,overflowWrap:"anywhere",display:"flex",flexDirection:"column",gap:8,background:"color-mix(in srgb, currentColor 5%, transparent)"},paragraph:{margin:0,whiteSpace:"pre-wrap"},heading:{fontWeight:600,fontSize:13.5},headingStrong:{fontSize:15},list:{margin:0,paddingLeft:20,display:"flex",flexDirection:"column",gap:4},codeBlock:{margin:0,padding:"10px 12px",borderRadius:8,overflowX:"auto",fontSize:12,lineHeight:1.65,background:"color-mix(in srgb, currentColor 9%, transparent)",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},inlineCode:{padding:"1px 5px",borderRadius:5,fontSize:12,background:"color-mix(in srgb, currentColor 9%, transparent)",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},quote:{margin:0,paddingLeft:10,borderLeft:"3px solid var(--dsw-alias-border-default, #d8dee8)",color:"var(--dsw-alias-label-secondary, #536174)"},rule:{border:"none",borderTop:"1px solid var(--dsw-alias-border-default, #d8dee8)",margin:"2px 0",width:"100%"},link:{color:"#2f6bff",textDecoration:"none"},bubbleUser:{maxWidth:"86%",padding:"9px 12px",borderRadius:12,lineHeight:1.7,whiteSpace:"pre-wrap",overflowWrap:"anywhere",background:"color-mix(in srgb, #2f6bff 12%, transparent)"},pulse:{animation:"pa-awaiting 1.2s ease-in-out infinite"},step:{fontSize:12,color:"var(--dsw-alias-label-secondary, #536174)",lineHeight:1.7,overflowWrap:"anywhere"},centered:{flex:1,display:"grid",placeItems:"center",padding:24,textAlign:"center"},centeredInner:{maxWidth:420,display:"flex",flexDirection:"column",gap:10,alignItems:"center"},composer:{flex:"0 0 auto",minWidth:0,boxSizing:"border-box",padding:"8px 16px 14px"},composerInner:{maxWidth:720,minWidth:0,margin:"0 auto",display:"flex",flexDirection:"column",gap:6,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:16,padding:"10px 10px 8px 12px",background:"var(--dsw-alias-bg-layer-1, #fff)"},textarea:{flex:1,width:"100%",minWidth:0,boxSizing:"border-box",minHeight:24,maxHeight:200,resize:"none",border:"none",outline:"none",background:"transparent",color:"inherit",font:"inherit",fontSize:13,lineHeight:1.7},composerBar:{display:"flex",alignItems:"center",gap:8},iconButton:{flex:"none",width:28,height:28,display:"grid",placeItems:"center",cursor:"pointer",border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:999,background:"transparent",color:"var(--dsw-alias-label-secondary, #536174)",padding:0},send:{flex:"none",width:28,height:28,display:"grid",placeItems:"center",border:"none",borderRadius:999,cursor:"pointer",padding:0,background:"var(--dsw-alias-label-primary, #17202c)",color:"var(--dsw-alias-bg-layer-1, #fff)"},sendDisabled:{background:"var(--dsw-alias-border-default, #d8dee8)",color:"var(--dsw-alias-label-secondary, #536174)",cursor:"default"},sendQueued:{flex:"none",width:28,height:28,display:"grid",placeItems:"center",borderRadius:999,cursor:"pointer",padding:0,border:"1px dashed var(--dsw-alias-label-primary, #17202c)",background:"transparent",color:"var(--dsw-alias-label-primary, #17202c)"},queueBadge:{flex:"none",borderRadius:999,padding:"1px 8px",fontSize:11,lineHeight:"18px",background:"color-mix(in srgb, #946200 14%, transparent)",color:"#946200"},queueBubble:{maxWidth:"86%",padding:"9px 12px",borderRadius:12,lineHeight:1.7,whiteSpace:"pre-wrap",overflowWrap:"anywhere",border:"1px dashed color-mix(in srgb, currentColor 35%, transparent)",background:"color-mix(in srgb, currentColor 4%, transparent)",color:"var(--dsw-alias-label-secondary, #536174)"},queueRow:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},queueHint:{fontSize:11,color:"var(--dsw-alias-label-secondary, #536174)"},queueCancel:{border:"none",background:"transparent",cursor:"pointer",padding:"2px 4px",borderRadius:6,color:"var(--dsw-alias-label-secondary, #536174)",display:"inline-flex",alignItems:"center",gap:3,font:"inherit",fontSize:11},queueNotice:{maxWidth:720,margin:"0 auto 6px",fontSize:12,color:"#946200",lineHeight:1.6},attach:{flex:"none",display:"flex",alignItems:"center",gap:6,padding:"3px 8px 3px 4px",borderRadius:8,background:"var(--dsw-alias-bg-layer-2, #f4f6fa)",fontSize:11,maxWidth:180},attachName:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},attachThumb:{width:20,height:20,borderRadius:4,objectFit:"cover",flex:"none"},attachRow:{display:"flex",flexWrap:"wrap",gap:6}},Y=t=>typeof t=="string"?t:"",Bt=t=>t("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},t("path",{d:"M12 19V5M5 12l7-7 7 7"})),Ft=t=>t("svg",{width:15,height:15,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round","aria-hidden":!0},t("path",{d:"M12 5v14M5 12h14"})),dt=t=>t("svg",{width:10,height:10,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.4,strokeLinecap:"round","aria-hidden":!0},t("path",{d:"M6 6l12 12M18 6L6 18"}));function ut({React:t,request:g,scope:l,onOpenComputer:c=null}={}){if(!t)return"\u4E2A\u4EBA\u52A9\u7406\u5BF9\u8BDD\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00";let{createElement:n,useCallback:s,useEffect:o,useRef:r,useState:u}=t,[d,E]=u("loading"),[A,w]=u(""),[T,D]=u([]),[S,U]=u(""),[$,m]=u([]),[ae,X]=u(""),[z,R]=u([]),L=r(null),[F,M]=u(!1),[j,re]=u(!1),[Qe,Le]=u(""),[oe,Te]=u([]),[ke,se]=u(""),ye=r(0),ue=r(new Map),O=r([]),ie=r(!1),W=r(null),G=r(!1);G.current=F;let xe=r(!1);xe.current=j;let Ae=r("loading");Ae.current=d;let ee=r(0),q=r(!0),b=r(null),pe=r(!0),J=r("");J.current=S;let te=s(async(i,y={})=>{if(typeof g!="function")throw new Error("Studio Host \u5C1A\u672A\u8FDE\u63A5");return g(i,y)},[g]),we=s(i=>{!Array.isArray(i)||i.length===0||m(y=>{let h=[...y];for(let f of i)if(!(!f||typeof f!="object")){if(f.type==="message"){let v=Y(f.id)||`local-${h.length}`,I=Y(f.role)||"assistant",C=Y(f.text),P=h.findIndex(H=>H.id===v),B={id:v,role:I,text:C,done:f.done!==!1,clientTurnId:f.clientTurnId,status:"accepted"};if(P>=0)h[P]={...h[P],...B};else if(I==="user"){let H=h.findIndex(Pe=>Pe.role==="user"&&f.clientTurnId&&Pe.clientTurnId===f.clientTurnId);H>=0?h[H]={...B}:h.push(B)}else h.push(B)}else if(f.type==="delta"){let v=Y(f.id)||`local-${h.length}`,I=h.findIndex(C=>C.id===v);I>=0?h[I]={...h[I],text:h[I].text+Y(f.text)}:h.push({id:v,role:"assistant",text:Y(f.text),done:!1})}else if(f.type==="step"&&Y(f.text)){let v={id:Y(f.id),role:"step",text:Y(f.text),done:!0},I=h.findIndex(C=>C.id===v.id);I>=0?h[I]=v:h.push(v)}}return h})},[]),le=s(async i=>{if(!i)return;let y=J.current;if(y&&y!==i&&O.current.length>0){let f=O.current.length;O.current=[],Te([]),W.current&&(clearTimeout(W.current),W.current=null),se(`\u5DF2\u5207\u6362\u4F1A\u8BDD\uFF0C${f} \u6761\u6392\u961F\u6D88\u606F\u672A\u53D1\u9001\uFF0C\u5DF2\u53D6\u6D88`)}else y&&y!==i&&se("");J.current=i;let h=++ee.current;U(i),E("loading"),w(""),ye.current=0,pe.current=!0,m([]);try{let f=await te("personal-assistant.session.snapshot",{sessionId:i});if(!q.current||J.current!==i||h!==ee.current)return;ye.current=Number(f?.cursor)||0;let v=Array.isArray(f?.messages)?f.messages:[];m(v.map((I,C)=>({id:Y(I?.id)||`history-${C}`,role:Y(I?.role)||"assistant",text:Y(I?.text),done:!0}))),re(f.turns?.some(I=>["queued","running"].includes(I.status))||!1),E("ready")}catch(f){if(!q.current||h!==ee.current)return;E("error"),w(f?.message||"\u65E0\u6CD5\u8BFB\u53D6\u4F1A\u8BDD\u5185\u5BB9")}},[te]),Ie=s(async()=>{if(E("loading"),w(""),!!q.current)try{let i=await te("personal-assistant.sessions.list");if(!q.current)return;let y=Array.isArray(i?.sessions)?i.sessions:[];if(D(y),y.length>0){await le(Y(y[0].sessionId));return}let h=await te("personal-assistant.session.create",{});if(!q.current)return;let f=Y(h?.sessionId);D(f?[{sessionId:f,title:Y(h?.title)||"\u65B0\u4F1A\u8BDD"}]:[]),await le(f)}catch(i){if(!q.current)return;E("error"),w(i?.message||"\u4F1A\u8BDD\u901A\u9053\u6682\u65F6\u4E0D\u53EF\u7528")}},[te,le]);o(()=>(q.current=!0,Ie(),()=>{q.current=!1,W.current&&(clearTimeout(W.current),W.current=null)}),[Ie]),o(()=>{if(d!=="ready"||!S)return;let i=!1,y=null,h=async()=>{try{let f=await te("personal-assistant.session.events",{sessionId:S,cursor:ye.current});if(i)return;if(ye.current=Number(f?.cursor??ye.current)||0,we(f?.events),Array.isArray(f.turns)){re(f.turns.some(P=>["queued","running"].includes(P.status)));let v=f.turns.findLast(P=>["queued","running"].includes(P.status)),I={cloud_computer:"\u64CD\u4F5C\u4E91\u7535\u8111",cloud_workspace:"\u5904\u7406\u4E91\u7AEF\u6587\u4EF6",cloud_bash:"\u6267\u884C\u4E91\u7AEF\u547D\u4EE4",cloud_run_code:"\u8FD0\u884C\u4E91\u7AEF\u4EE3\u7801",assistant_schedule:"\u8BBE\u7F6E\u4E91\u7AEF\u4EFB\u52A1"},C=v?.progress?.tool;Le(C?`${v.progress.state==="running"?"\u6B63\u5728":"\u5DF2\u5B8C\u6210"}${I[C]||(C.startsWith("cloud_browser_")?"\u64CD\u4F5C\u4E91\u7AEF\u6D4F\u89C8\u5668":"\u6267\u884C\u5DE5\u5177")}`:""),we(f.turns.filter(P=>["failed","interrupted","cancelled"].includes(P.status)).map(P=>({type:"step",id:`turn-status-${P.turnId}`,text:`\u4EFB\u52A1${P.status==="failed"?"\u5931\u8D25":"\u5DF2\u4E2D\u65AD"}\uFF1A${P.error||"\u8BF7\u68C0\u67E5\u4EFB\u52A1\u72B6\u6001\u540E\u91CD\u8BD5"}`})))}w("")}catch(f){if(!i){if(f.code==="SESSION_CURSOR_STALE"){le(S);return}w(f.message||"\u4E91\u7AEF\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u6B63\u5728\u6062\u590D\uFF1B\u4EFB\u52A1\u4E0D\u4F1A\u6539\u5230\u672C\u673A\u6267\u884C")}}i||(y=setTimeout(h,600))};return y=setTimeout(h,200),()=>{i=!0,clearTimeout(y)}},[d,S,te,we,le]),o(()=>{let i=b.current;i&&pe.current&&(i.scrollTop=i.scrollHeight)},[$,j]);let ze=async i=>{let y=Array.from(i.target.files||[]);i.target.value="";let h=[];for(let f of y.slice(0,4)){if(!f||f.size>512*1024){w("\u6BCF\u4E2A\u9644\u4EF6\u6700\u591A 512 KiB\uFF0C\u8BF7\u5148\u538B\u7F29\u6216\u62C6\u5206\u6587\u4EF6");continue}let v=await new Promise(I=>{let C=new FileReader;C.onload=()=>I(String(C.result||"")),C.onerror=()=>I(""),C.readAsDataURL(f)});v&&h.push({id:`${Date.now()}-${f.name}`,name:f.name,mimeType:f.type||"application/octet-stream",size:f.size,dataUrl:v})}h.length&&R(f=>[...f,...h].slice(0,4))},ne=i=>{O.current=i,Te(i)},_e=()=>{W.current&&(clearTimeout(W.current),W.current=null)},Z=i=>Number(i?.status)===409||/SESSION_BUSY|active turn|正忙|处理中/u.test(`${i?.code||""} ${i?.message||""}`),Se=async(i,{restoreDraft:y=!1}={})=>{ue.current.set(i.clientTurnId,i),pe.current=!0,M(!0),w(""),re(!0),m(f=>f.some(v=>v.clientTurnId===i.clientTurnId)?f.map(v=>v.clientTurnId===i.clientTurnId?{...v,status:"pending"}:v):[...f,{id:`local-user-${i.clientTurnId}`,clientTurnId:i.clientTurnId,role:"user",text:i.text,done:!1,status:"pending"}]);let h=i;try{let f=Array.isArray(h.attachments)?h.attachments:[];if(f.length===0&&Array.isArray(h.uploads)&&h.uploads.length>0){let I=[];for(let C of h.uploads)I.push(await te("personal-assistant.file.upload",{sessionId:h.sessionId,name:C.name,dataUrl:C.dataUrl}));f=I.map(({path:C,name:P,mediaType:B,bytes:H})=>({path:C,name:P,mediaType:B,bytes:H})),h={...h,attachments:f,uploads:[]},ue.current.set(h.clientTurnId,h)}let v=await te("personal-assistant.turn.submit",{sessionId:h.sessionId,text:h.text,clientTurnId:h.clientTurnId,attachments:f});return q.current?(ue.current.delete(h.clientTurnId),m(I=>I.map(C=>C.clientTurnId===h.clientTurnId?{...C,status:"accepted",turnId:v.turnId}:C)),{ok:!0,item:h}):{ok:!0,item:h}}catch(f){return q.current?(re(Z(f)),y&&!Z(f)&&X(v=>v||h.text),m(v=>v.map(I=>I.clientTurnId===h.clientTurnId?{...I,status:"failed",failure:f.message||"\u53D1\u9001\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u91CD\u8BD5\u5C06\u590D\u7528\u539F\u6807\u8BC6"}:I)),{ok:!1,failure:f,item:h}):{ok:!1,failure:f,item:h}}finally{q.current&&M(!1)}},Ce=(i,y)=>{let h=(i.attempts||0)+1;if(ue.current.delete(i.clientTurnId),m(v=>v.filter(I=>I.clientTurnId!==i.clientTurnId)),h>Pt){se(`\u6392\u961F\u6D88\u606F\u591A\u6B21\u672A\u53D1\u51FA\uFF08${y?.message||"\u4E91\u7535\u8111\u4ECD\u5FD9"}\uFF09\uFF0C\u5DF2\u653E\u56DE\u8F93\u5165\u6846\uFF0C\u8BF7\u624B\u52A8\u91CD\u8BD5`),X(v=>v||i.text);return}ne([{...i,attempts:h},...O.current]);let f=(ct*Math.min(h,3)/1e3).toFixed(1);se(`\u4E91\u7535\u8111\u4ECD\u5728\u5904\u7406\u4E0A\u4E00\u8F6E\uFF0C\u6D88\u606F\u5DF2\u6392\u961F\uFF0C\u7EA6 ${f} \u79D2\u540E\u81EA\u52A8\u91CD\u53D1`),_e(),W.current=setTimeout(()=>{W.current=null,Oe(!0)},ct*Math.min(h,3))},Oe=async i=>{let y=J.current;if(ie.current||!q.current||Ae.current!=="ready"||!y||G.current||!i&&xe.current)return!1;let h=O.current[0];if(!h)return!1;if(h.sessionId!==y)return ne([]),se("\u4F1A\u8BDD\u5DF2\u53D8\u5316\uFF0C\u6392\u961F\u6D88\u606F\u672A\u53D1\u9001"),!1;ie.current=!0,ne(O.current.slice(1));try{let f=await Se(h);return f.ok?!0:(Z(f.failure)?Ce(f.item||h,f.failure):se(`\u6392\u961F\u6D88\u606F\u53D1\u9001\u5931\u8D25\uFF1A${f.failure?.message||"\u8BF7\u70B9\u51FB\u91CD\u8BD5"}`),!1)}finally{ie.current=!1}},$e=i=>{ue.current.delete(i),ne(O.current.filter(y=>y.clientTurnId!==i)),se("\u5DF2\u64A4\u56DE\u6392\u961F\u6D88\u606F")},Ee=async(i=null)=>{if(d!=="ready"||!S)return;if(i){F||Se(i,{restoreDraft:!0});return}let y=ae.trim()||(z.length?"\u8BF7\u67E5\u770B\u9644\u4EF6\u3002":"");if(!y)return;let h=z.map(({name:v,mimeType:I,size:C,dataUrl:P})=>({name:v,mimeType:I,size:C,dataUrl:P}));if(F||j){ne([...O.current,{clientTurnId:crypto.randomUUID(),text:y,sessionId:S,uploads:h,attempts:0,queuedAt:Date.now()}]),pe.current=!0,X(""),R([]),w(""),se("");return}X(""),R([]),w(""),se("");let f=await Se({clientTurnId:crypto.randomUUID(),text:y,sessionId:S,uploads:h,attempts:0},{restoreDraft:!0});!f.ok&&Z(f.failure)&&Ce(f.item,f.failure)};o(()=>{if(d!=="ready"||!S||F||j||oe.length===0)return;let i=setTimeout(()=>{Oe(!1)},Nt);return()=>clearTimeout(i)},[d,S,F,j,oe]),o(()=>{if(oe.length===0||typeof window>"u"||typeof window.addEventListener!="function")return;let i=y=>{y.preventDefault(),y.returnValue=""};return window.addEventListener("beforeunload",i),()=>window.removeEventListener("beforeunload",i)},[oe.length]);let Ne=n("header",{style:x.header},n("h1",{style:x.title},"\u4E2A\u4EBA\u52A9\u7406"),n("span",{style:x.status},d==="ready"?"\u4E91\u7AEF\u5E38\u9A7B\uFF0C\u5173\u6389\u7A97\u53E3\u4E5F\u4F1A\u7EE7\u7EED":d==="loading"?"\u6B63\u5728\u8FDE\u63A5\u2026":"\u8FDE\u63A5\u4E0D\u53EF\u7528"),n("span",{style:x.spacer}),c?n("button",{type:"button",onClick:c,"aria-label":"\u6253\u5F00\u4E91\u7535\u8111\u4FA7\u680F",title:"\u6253\u5F00\u6216\u91CD\u65B0\u6253\u5F00\u4E91\u7535\u8111\u4FA7\u680F",style:{...x.ghost,display:"inline-flex",alignItems:"center",gap:6}},n("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,"aria-hidden":!0},n("rect",{x:3,y:4,width:18,height:13,rx:2}),n("path",{d:"M8 21h8M12 17v4"})),"\u4E91\u7535\u8111"):null);return n("section",{"data-personal-assistant-conversation":"true",style:x.page,onClick:async i=>{let y=i.target.closest?.('a[href^="cloud-file:"]');if(y){i.preventDefault();try{let h=await te("personal-assistant.file.download",{sessionId:S,path:decodeURIComponent(y.getAttribute("href").slice(11))}),f=Uint8Array.from(atob(h.data),C=>C.charCodeAt(0)),v=URL.createObjectURL(new Blob([f],{type:"application/octet-stream"})),I=document.createElement("a");I.href=v,I.download=h.name,I.click(),setTimeout(()=>URL.revokeObjectURL(v),1e3)}catch(h){w(h.message||"\u4E91\u7AEF\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25")}}}},Ne,n("style",null,"@keyframes pa-awaiting { 0%, 100% { opacity: 0.35 } 50% { opacity: 1 } }"),A&&$.length>0?n("div",{role:"alert",style:{padding:"8px 16px",background:"#fff0d6"}},A):null,n("div",{ref:b,"data-personal-assistant-messages":"true",style:x.scroller,onScroll:i=>{let y=i.currentTarget;pe.current=y.scrollHeight-y.clientHeight-y.scrollTop<64}},n("div",{style:x.thread},$.length===0?n("div",{style:{...x.status,paddingTop:40,textAlign:"center"}},d==="error"?n("div",{style:{...x.centeredInner,margin:"0 auto"}},n("strong",null,"\u6682\u65F6\u8FDE\u4E0D\u4E0A\u4E2A\u4EBA\u52A9\u7406"),n("span",null,A||"\u8BF7\u7A0D\u540E\u91CD\u8BD5"),n("button",{style:x.ghost,onClick:()=>{Ie()}},"\u91CD\u8BD5")):d==="loading"?"\u6B63\u5728\u8FDE\u63A5\u4E2A\u4EBA\u52A9\u7406\u2026":Ot):null,$.map(i=>{if(i.role==="step")return n("div",{key:i.id,style:x.step},`\xB7 ${i.text}`);let y=i.role==="user";return n("div",{key:i.id,style:y?x.rowUser:x.row},n("span",{style:x.who},y?"\u4F60":"\u52A9\u7406"),n("div",{style:y?x.bubbleUser:x.bubble},y?i.text||"\u2026":lt(n,i.text||"",x)||"\u2026"),i.status==="failed"?n("button",{onClick:()=>{Ee(ue.current.get(i.clientTurnId))},disabled:F},`${i.failure} \xB7 \u91CD\u8BD5\u53D1\u9001`):null)}),j?n("div",{key:"awaiting",style:x.row},n("span",{style:x.who},"\u52A9\u7406"),n("div",{style:{...x.bubble,color:"var(--dsw-alias-label-secondary, #536174)"}},n("span",{style:x.pulse},Qe||"\u6B63\u5728\u5904\u7406\u2026"))):null,oe.map(i=>n("div",{key:`queued-${i.clientTurnId}`,style:x.rowUser},n("span",{style:x.who},"\u4F60 \xB7 \u6392\u961F\u4E2D"),n("div",{style:x.queueBubble},`${i.text}${i.uploads?.length?`\uFF08${i.uploads.length} \u4E2A\u9644\u4EF6\u5F85\u53D1\uFF09`:""}`),n("div",{style:x.queueRow},n("span",{style:x.queueHint},i.attempts?"\u4E91\u7535\u8111\u4ECD\u5728\u5904\u7406\u4E0A\u4E00\u8F6E\uFF0C\u7A0D\u540E\u81EA\u52A8\u91CD\u53D1":"\u5DF2\u6392\u961F\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u53D1\u9001"),n("button",{type:"button","aria-label":`\u64A4\u56DE\u6392\u961F\u6D88\u606F\uFF1A${i.text.slice(0,24)}`,title:"\u64A4\u56DE\u8FD9\u6761\u6392\u961F\u6D88\u606F",style:x.queueCancel,onClick:()=>$e(i.clientTurnId)},dt(n),"\u64A4\u56DE")))))),n("div",{"data-personal-assistant-composer":"true",style:x.composer},ke?n("div",{role:"status",style:x.queueNotice},ke):null,n("div",{style:x.composerInner},z.length>0?n("div",{style:x.attachRow},z.map(i=>n("span",{key:i.id,style:x.attach},i.mimeType.startsWith("image/")?n("img",{src:i.dataUrl,alt:"",style:x.attachThumb}):null,n("span",{style:x.attachName},i.name),n("button",{"aria-label":`\u79FB\u9664 ${i.name}`,style:{...x.iconButton,width:16,height:16,border:"none"},onClick:()=>R(y=>y.filter(h=>h.id!==i.id))},dt(n))))):null,n("textarea",{"aria-label":"\u7ED9\u4E2A\u4EBA\u52A9\u7406\u53D1\u6D88\u606F",value:ae,rows:1,style:x.textarea,placeholder:d!=="ready"?"\u4E91\u7AEF\u6682\u672A\u8FDE\u63A5\uFF0C\u53EF\u5148\u5199\u4E0B\u6D88\u606F":F||j?"\u672C\u8F6E\u8FDB\u884C\u4E2D\uFF1A\u73B0\u5728\u53D1\u9001\u4F1A\u6392\u961F\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u51FA":"\u7ED9\u4E2A\u4EBA\u52A9\u7406\u53D1\u6D88\u606F\uFF0CEnter \u53D1\u9001\uFF0CShift+Enter \u6362\u884C",onChange:i=>X(i.target.value),onKeyDown:i=>{d==="ready"&&i.key==="Enter"&&!i.shiftKey&&!i.nativeEvent?.isComposing&&(i.preventDefault(),Ee())}}),n("div",{style:x.composerBar},n("button",{"aria-label":"\u6DFB\u52A0\u9644\u4EF6",style:x.iconButton,disabled:d!=="ready"||F,title:"\u4E0A\u4F20\u5230\u4E91\u7535\u8111\uFF1A\u6700\u591A 4 \u4E2A\u6587\u4EF6\uFF0C\u6BCF\u4E2A 512 KiB",onClick:()=>L.current?.click()},Ft(n)),n("input",{ref:L,type:"file",multiple:!0,accept:"image/*,.txt,.md,.json,.pdf",style:{display:"none"},onChange:ze}),n("span",{style:x.spacer}),oe.length>0?n("span",{role:"status",style:x.queueBadge},`\u6392\u961F\u4E2D ${oe.length}`):null,n("button",{"aria-label":oe.length>0?`\u53D1\u9001\u6D88\u606F\uFF08\u6392\u961F\u4E2D ${oe.length} \u6761\uFF09`:"\u53D1\u9001\u6D88\u606F",title:F||j?"\u672C\u8F6E\u8FDB\u884C\u4E2D\uFF1A\u53D1\u9001\u540E\u4F1A\u6392\u961F\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u51FA":"\u53D1\u9001\u6D88\u606F",disabled:d!=="ready"||!ae.trim()&&z.length===0,style:d!=="ready"||!ae.trim()&&z.length===0?{...x.send,...x.sendDisabled}:F||j?x.sendQueued:x.send,onClick:()=>{Ee()}},Bt(n))))))}var pt="personal-assistant-computer",Mt="personal-assistant",ft="\u5F53\u524D Studio \u7684\u539F\u751F\u4FA7\u680F\u7EC4\u4EF6\u9700\u8981\u66F4\u65B0\uFF0C\u8BF7\u5B89\u88C5\u672C\u6B21\u968F\u63D2\u4EF6\u63D0\u4F9B\u7684\u5BBF\u4E3B\u7EC4\u4EF6\u5305\u3002",Ut=()=>Object.assign(new Error(ft),{code:"PERSONAL_ASSISTANT_NATIVE_SIDEBAR_REQUIRED"});function zt(t){return t.workbench.render(t)}function gt({sidebarRight:t,slots:g,panelId:l=Mt}={}){let c=typeof t?.registerPanelSurface=="function"&&typeof t?.openPanelTab=="function"&&typeof t?.setPanelExpanded=="function"&&typeof g?.inject=="function"&&typeof g?.register=="function",n=new Set,s,o=!1,r=Object.freeze({binding:void 0}),u=()=>{r=Object.freeze({binding:s});for(let T of[...n])T()},d=()=>{if(!c)throw Ut();if(o)throw new Error("\u4E91\u7535\u8111\u5DE5\u4F5C\u9762\u677F\u5DF2\u5173\u95ED")},E,A,w={available:c,unavailableReason:c?null:ft,subscribe:T=>(n.add(T),()=>n.delete(T)),getSnapshot:()=>r,bind(T,D){if(d(),!T?.agentId||!T?.botId||typeof D!="function")throw new Error("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u8FDE\u63A5");s&&(s.scope.agentId!==T.agentId||s.scope.botId!==T.botId)&&(E(),E=t.registerPanelSurface(l)),s=Object.freeze({scope:Object.freeze({...T}),request:D}),u(),w.open()},open(){d(),s&&t.openPanelTab(l,pt)},collapse(){d(),t.setPanelExpanded(l,!1)},dispose(){o||(o=!0,A?.(),E?.(),n.clear())}};return c&&(E=t.registerPanelSurface(l),A=g.inject("sidebar.right.panel.tab",()=>g.register({name:"sidebar.right.panel.tab",key:pt,inject:()=>({workbench:w})},zt))),w}function ht({React:t,workbench:g,Panel:l,active:c=!0,fullscreen:n=!1}){let{createElement:s,useSyncExternalStore:o}=t,r=o(g.subscribe,g.getSnapshot,g.getSnapshot);if(!c||!r.binding)return null;let{scope:u,request:d}=r.binding;return s(l,{key:`${u.agentId}:${u.botId}:${u.sessionId||""}`,request:d,initialBotId:u.botId,initialSessionId:u.sessionId,agentId:u.agentId,variant:"native-tab",active:c,nativeFullscreen:n})}var $t="__directory__";function He(t){if(!Array.isArray(t)||t.length>128)throw new TypeError("\u52A9\u7406\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");let g=new Set;return t.map(l=>{let c=String(l?.botId||"").trim(),n=String(l?.displayName||c).trim();if(!c||c.length>64||/[\u0000-\u001f]/u.test(c)||c===$t||g.has(c)||!n||n.length>256)throw new TypeError("\u52A9\u7406\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");return g.add(c),{botId:c,displayName:c==="default"&&n==="Personal Assistant"?"\u9ED8\u8BA4\u52A9\u7406":c==="researcher"&&n==="Researcher"?"\u7814\u7A76\u52A9\u7406":n}})}function Ke(t,g=""){let l=He(t),c=String(g||"").trim(),n=c?l.find(s=>s.botId===c):l.find(s=>s.botId==="default")||(l.length===1?l[0]:void 0);if(!n)throw Object.assign(new Error("\u4E91\u7AEF\u52A9\u7406\u7ED1\u5B9A\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"),{code:"PERSONAL_ASSISTANT_BINDING_UNAVAILABLE"});return n.botId}var Ve=class extends Error{constructor(){super("Personal Assistant gateway is not connected"),this.name="PersonalAssistantGatewayUnavailableError",this.code="PERSONAL_ASSISTANT_GATEWAY_UNAVAILABLE"}};var xt=Object.freeze(["slots","connection","sidebarRight"]),Ye="personal-assistant",on=Object.freeze({enabled:!1,autoConnect:!1}),Ue="personal-assistant-computer",De="2026-10-27T09:11:09.327Z",yt=12e3,me;function wt(t){me=t}var de={background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #17202c)",border:"1px solid var(--dsw-alias-border-default, #d8dee8)"},bt=t=>t?.code==="PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE"&&Number(t?.status)===409?"\u5F53\u524D\u4E91\u7AEF\u7248\u672C\u5C1A\u4E0D\u652F\u6301\u52A9\u7406\u5217\u8868\uFF0C\u8BF7\u66F4\u65B0\u4E91\u7AEF\u52A9\u7406\u540E\u91CD\u8BD5":"\u8FDE\u63A5\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",jt=t=>Number(t?.status)===409&&["PERSONAL_ASSISTANT_DIRECTORY_UNSUPPORTED","PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE"].includes(t?.code),Wt={Control:"Control_L",Meta:"Super_L",Alt:"Alt_L",Shift:"Shift_L",Enter:"Return",Escape:"Escape",Tab:"Tab",Backspace:"BackSpace",Delete:"Delete",ArrowUp:"Up",ArrowDown:"Down",ArrowLeft:"Left",ArrowRight:"Right"," ":"space"};function mt({request:t,initialBotId:g="",openInSidebar:l=null,variant:c="page",nativeFullscreen:n=!1}={}){let s=me||globalThis.React;if(!s)return"\u4E2A\u4EBA\u52A9\u7406\u9875\u9762\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00";let{createElement:o,useEffect:r,useRef:u,useState:d}=s,[E,A]=d(null),[w,T]=d([]),[D,S]=d(""),[U,$]=d(null),[m,ae]=d(!1),[X,z]=d(g),[R,L]=d("loading"),[F,M]=d(""),[j,re]=d(!0),[Qe,Le]=d(0),[oe,Te]=d(0),[ke,se]=d("observe"),[ye,ue]=d(""),O=u(null),ie=u(null),W=u(null),G=u(null),xe=u(null),Ae=u(null),ee=u(null),q=u(n);q.current=n;let b=u({mounted:!0,socket:null,generation:0,frameEpoch:0,session:null,suspended:!1,resuming:!1,pendingInputs:[],display:{width:1280,height:800},readOnly:!0,botId:X,config:null,reconnect:null,firstFrame:null,receivedSeq:-1,pendingFrame:null,decoding:!1,frames:0,lastMove:0,pressed:new Set,buttons:new Set,composition:!1,retries:0,taskId:"",mode:"control",frameMetadata:null,reconnectAllowed:!1});b.current.botId=X;let pe=async(e,a={})=>{if(typeof t!="function")throw new Error("Studio Host \u5C1A\u672A\u8FDE\u63A5");return t(e,a)},J=e=>{let a=b.current;return a.socket?.readyState!==1?!1:(a.socket.send(JSON.stringify(e)),!0)},te=()=>{let e=b.current;for(let a of e.pressed)O.current?.input({type:"key",action:"up",key:a});for(let a of e.buttons)O.current?.input({type:"button",action:"up",button:a});e.pressed.clear(),e.buttons.clear()},we=()=>{for(let e of b.current.buttons)O.current?.input({type:"button",action:"up",button:e});b.current.buttons.clear()};O.current||(O.current=Ze({send:J,changed:e=>{let a=b.current;a.controlPhase=e.phase,a.readOnly=e.readOnly,a.controlEpoch=e.controlEpoch,e.readOnly&&ee.current&&(ee.current.style.visibility="hidden"),e.phase==="observe"&&(a.pressed.clear(),a.buttons.clear()),a.mounted&&(re(e.readOnly),se(e.phase))},failed:e=>{b.current.mounted&&M(e)}})),ie.current||(ie.current=tt({send:J,controlEpoch:()=>O.current?.snapshot?.controlEpoch}));let le=()=>{te(),O.current.release(),b.current.pressed.clear(),b.current.buttons.clear()},Ie=()=>{let e=b.current;e.pointerFrame&&cancelAnimationFrame(e.pointerFrame),e.pointerFrame=null;let a=e.lastPointer;e.lastPointer=null,a&&(!e.readOnly||e.controlPhase==="acquiring")&&(!e.sentPointer||a.x!==e.sentPointer.x||a.y!==e.sentPointer.y)&&(O.current.input({type:"pointermove",...a}),e.sentPointer=a)},ze=()=>{clearTimeout(b.current.reconnect),clearTimeout(b.current.firstFrame),b.current.reconnect=null,b.current.firstFrame=null},ne=(e=!0)=>{let a=b.current;a.reconnectAllowed=!1,ze(),le(),a.generation+=1,ie.current?.rejectAll();try{J({type:"close"}),a.socket?.close(1e3,"panel closed")}catch{}O.current.reset({readOnly:!0}),a.lastDrawnFrame=null,a.socket=null,a.session=null,a.pendingFrame=null,a.frameMetadata=null,a.readOnly=!0,xe.current?.blur(),a.suspended=!1,a.resuming=!1,a.pendingInputs=[],a.frameEpoch++,e&&a.mounted&&(L(a.config?.configured?"idle":"unconfigured"),re(!0))},_e=e=>{ne(!1),re(!0),L("closed"),M(e?.reason==="lease-lost"||Number(e?.status)===409?"\u63A7\u5236\u79DF\u7EA6\u5DF2\u5931\u6548\uFF0C\u684C\u9762\u8FDE\u63A5\u5DF2\u5173\u95ED\uFF1B\u8BF7\u91CD\u65B0\u8FDE\u63A5\u6216\u9009\u62E9\u53EA\u8BFB\u65C1\u89C2":e?.code==="DESKTOP_SESSION_NOT_FOUND"||Number(e?.status)===404?"\u684C\u9762\u4F1A\u8BDD\u5DF2\u7ED3\u675F\uFF08\u53EF\u80FD\u56E0\u7A7A\u95F2\u8D85\u65F6\uFF09\uFF0C\u8BF7\u91CD\u65B0\u8FDE\u63A5":"\u684C\u9762\u8FDE\u63A5\u5DF2\u7ED3\u675F\uFF0C\u53EF\u91CD\u65B0\u8FDE\u63A5\u4E91\u7535\u8111")},Z=e=>{let a=b.current;if(e.type!=="pointermove"&&Ie(),a.suspended||a.resuming){if(e.type==="pointermove")return!1;let _=a.mode==="control";if(_){if(a.pendingInputs.length>=32)return ne(),M("\u6062\u590D\u671F\u95F4\u8F93\u5165\u8FC7\u5FEB\uFF0C\u8BF7\u91CD\u65B0\u8FDE\u63A5"),!1;a.pendingInputs.push(e)}return a.resuming||i(),_}return!a.session||a.socket?.readyState!==1?(M("\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u8F93\u5165\u672A\u53D1\u9001"),!1):O.current.input(e)},Se=e=>{b.current.mounted&&(ue(e),W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{b.current.mounted&&ue("")},4e3))},Ce=e=>{let a=!1;for(let _ of e)a=Z(_)||a;return a},Oe=async()=>{let e=/Mac|iPhone|iPad/u.test(String(globalThis.navigator?.platform||""))?"Meta":"Control";if(!b.current.pressed.has("_copyShortcut")){b.current.pressed.add("_copyShortcut");try{Ce([{type:"key",action:"down",key:e},{type:"key",action:"down",key:"c"},{type:"key",action:"up",key:"c"},{type:"key",action:"up",key:e}]),await new Promise(a=>setTimeout(a,150))}finally{b.current.pressed.delete("_copyShortcut")}}return st({readCloud:()=>ie.current.read(),notify:Se})},$e=()=>ot({readLocal:()=>We(),writeCloud:e=>ie.current.write(e),sendKeys:Ce,notify:Se}),Ee=async()=>{let e=b.current;if(!e.decoding){e.decoding=!0;try{for(;e.pendingFrame;){let a=e.pendingFrame;e.pendingFrame=null;let _;try{if(_=await createImageBitmap(new Blob([a.bytes],{type:"image/jpeg"})),!e.mounted||e.suspended||a.frameEpoch!==e.frameEpoch||a.generation!==e.generation||a.seq<e.receivedSeq||!G.current)continue;e.lastDrawnFrame=a;let p=G.current,V=p.getBoundingClientRect(),ce=Math.max(1,globalThis.devicePixelRatio||1);p.width=Math.max(1,Math.round(V.width*ce)),p.height=Math.max(1,Math.round(V.height*ce));let Q=p.getContext("2d"),K=e.display,be=Math.min(p.width/K.width,p.height/K.height),fe=K.width*be,k=K.height*be;Q.clearRect(0,0,p.width,p.height),Q.drawImage(_,(p.width-fe)/2,(p.height-k)/2,fe,k);let ge=e.firstFrame!==null;e.frames+=1,clearTimeout(e.firstFrame),e.firstFrame=null,e.retries=0,ge&&M(""),L(e.readOnly?"readonly":"ready"),Le(0)}catch{e.mounted&&M("\u684C\u9762\u5E27\u65E0\u6CD5\u89E3\u7801\uFF0C\u8BF7\u91CD\u8BD5")}finally{_?.close()}}}finally{e.decoding=!1}}},Ne=e=>{let a=b.current;clearTimeout(a.firstFrame),a.firstFrame=null,a.suspended=!0,a.resuming=!1,a.readOnly=!0,a.pendingInputs=[],a.frameEpoch++,a.pendingFrame=null,a.frameMetadata=null,a.pressed.clear(),a.buttons.clear(),a.frames=0,Te(0),re(!0),L("dormant"),M(e?.leaseReleased===!1?"\u5DF2\u7A7A\u95F2\uFF0C\u753B\u9762\u5DF2\u6682\u505C\uFF1B\u63A7\u5236\u6743\u4ECD\u7531\u5916\u90E8\u4EFB\u52A1\u7BA1\u7406":"\u5DF2\u7A7A\u95F2\uFF0C\u63A7\u5236\u6743\u5DF2\u91CA\u653E\uFF1B\u64CD\u4F5C\u684C\u9762\u5373\u53EF\u6062\u590D")},i=()=>{let e=b.current;if(e.resuming||!e.suspended)return;if(e.socket?.readyState!==1){y(e.mode,!1,e.pendingInputs);return}e.resuming=!0,L("resuming"),M("\u6B63\u5728\u6062\u590D\u684C\u9762\u5E76\u68C0\u67E5\u63A7\u5236\u6743\uFF0C\u8BF7\u7A0D\u5019\u3002"),J({type:"resume",mode:e.mode,activity:!0});let a=e.generation,_=e.socket;e.firstFrame=setTimeout(()=>{e.mounted&&e.generation===a&&e.firstFrame!==null&&_.close(4e3,"resume frame timeout")},yt)},y=async(e="read",a=!1,_=[])=>{let p=b.current,V=String(p.botId||"").trim();if(!p.config?.configured){L("unconfigured");return}if(!V||!p.bots?.some(Q=>Q.botId===V)){M("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");return}ne(!1),p.pendingInputs=_,p.resuming=_.length>0;let ce=++p.generation;p.reconnectAllowed=!0,a||(p.retries=0),p.mode=e,p.taskId||=`studio-desktop-${globalThis.crypto.randomUUID()}`,p.receivedSeq=-1,p.frameMetadata=null,L(a?"reconnecting":"connecting"),M("\u9996\u6B21\u6216\u4F11\u7720\u540E\u8FDE\u63A5\u53EF\u80FD\u9700\u8981\u6570\u79D2\uFF0C\u8BF7\u7A0D\u5019\u3002");try{let Q=await pe("personal-assistant.desktop.ticket",{agentId:p.config.agentId,botId:V,mode:e==="observe"?"control":e});if(!p.mounted||ce!==p.generation)return;let K=new WebSocket(Q.wsUrl,["agentkit.personal-assistant.desktop.v1",`agentkit.desktop.ticket.${Q.ticket}`]);K.binaryType="arraybuffer",p.socket=K;let be=()=>p.mounted&&p.generation===ce;K.onopen=()=>{if(!be()){K.close();return}J({type:"open",botId:V,taskId:p.taskId,mode:e,...Q.leaseId?{leaseId:Q.leaseId}:{}}),p.firstFrame=setTimeout(()=>{be()&&(M("\u4E91\u7535\u8111\u54CD\u5E94\u8F83\u6162\uFF0C\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5"),K.close(4e3,"first frame timeout"))},yt)},K.onmessage=fe=>{if(!be())return;if(typeof fe.data!="string"){let ge=p.frameMetadata;p.frameMetadata=null;let ve=fe.data;if(!ge||!Number.isSafeInteger(ge.seq)||ge.seq<=p.receivedSeq||!(ve instanceof ArrayBuffer)||ve.byteLength===0||ve.byteLength>307200||p.suspended)return;p.receivedSeq=ge.seq,p.pendingFrame={bytes:ve,seq:ge.seq,generation:ce,frameEpoch:p.frameEpoch},Ee();return}let k;try{k=JSON.parse(fe.data)}catch{return}if(k.type==="ready"){p.suspended=!1,p.resuming=!1,p.receivedSeq=-1,p.session=k.sessionId,p.readOnly=!!k.readOnly,p.display=je(k.display),p.mode=e,O.current.reset(k);let ge=p.pendingInputs;if(p.pendingInputs=[],p.readOnly)p.pressed.clear(),p.buttons.clear();else for(let ve of ge)O.current.input(ve);re(p.readOnly),M("\u4E91\u7535\u8111\u5DF2\u8FDE\u63A5\uFF0C\u6B63\u5728\u51C6\u5907\u684C\u9762\u753B\u9762");return}if(k.type==="control"){O.current.accept(k),M("");return}if(k.type==="idle"){Ne(k);return}if(k.type==="frame"){k.unchanged||(p.frameMetadata=k);return}if(k.type==="clipboard.response"){ie.current?.accept(k);return}if(k.type==="closed"){k.retryable!==!0&&_e(k);return}if(k.type==="error"){if(Number.isSafeInteger(k.controlEpoch)&&k.controlEpoch<p.controlEpoch)return;if(M(k.message||k.code||"\u4E91\u7535\u8111\u8BF7\u6C42\u5931\u8D25"),p.handoffSupported&&k.recoverable===!0){O.current.reject(k);return}if(k.recoverable===!0&&Number(k.status)===409){k.code==="DESKTOP_SESSION_IDLE"?Ne():(p.pendingInputs=[],p.readOnly=!0,p.pressed.clear(),p.buttons.clear(),re(!0),L("readonly"));return}if(Number(k.status)===409&&e==="control"&&!p.session){y(b.current.handoffSupported?"observe":"read");return}[404,409].includes(Number(k.status))||k.code==="DESKTOP_SESSION_NOT_FOUND"?_e(k):p.session||(L("error"),ne(!1))}},K.onerror=()=>{be()&&M("\u684C\u9762\u901A\u9053\u6682\u65F6\u65AD\u5F00\uFF0C\u6B63\u5728\u91CD\u8FDE")},K.onclose=fe=>{if(!be())return;if(p.suspended&&fe.code!==1e3){clearTimeout(p.firstFrame),p.firstFrame=null,p.socket=null,L("dormant");return}if(p.session=null,clearTimeout(p.firstFrame),p.firstFrame=null,!p.reconnectAllowed||fe.code===1e3){_e();return}if(document.hidden){L("hidden");return}let k=++p.retries;if(Le(k),k>5){p.reconnectAllowed=!1,L("error"),M("\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7535\u8111\uFF0C\u8BF7\u68C0\u67E5\u5B9E\u4F8B\u72B6\u6001\u6216\u7F51\u7EDC\u540E\u91CD\u8BD5");return}L("reconnecting"),p.reconnect=setTimeout(()=>{y(e,!0,p.pendingInputs)},Math.min(8e3,1e3*2**(k-1)))}}catch(Q){p.mounted&&ce===p.generation&&(L("error"),M(bt(Q)))}},h=async e=>{ne(!1),L("loading"),M(""),S(""),$(null);try{let a=await pe("personal-assistant.configuration");if(e?.aborted||!b.current.mounted)return;if(b.current.config=a,A(a),!a.configured){b.current.bots=[],T([]),z(""),L("unconfigured");return}let _=await pe("personal-assistant.bots.list");if(e?.aborted||!b.current.mounted)return;if(_.directoryAvailable!==!0)throw Object.assign(new Error("directory unavailable"),{code:"PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE",status:409});let p=He(_.bots);b.current.bots=p,b.current.handoffSupported=_.features?.includes("desktop-handoff/v1")===!0,T(p);let V=p.length?Ke(p,g||a.botId):"";b.current.botId=V,z(V),L(p.length?"idle":"empty"),V&&["computer","native-tab"].includes(c)&&y(b.current.handoffSupported?"observe":"read")}catch(a){if(e?.aborted||!b.current.mounted)return;Number.isInteger(a?.closeCode)&&a.closeCode>=1e3&&a.closeCode<=4999&&$(a.closeCode),b.current.bots=[],T([]),z(""),L("directory-error"),S(jt(a)?"\u4E91\u7AEF\u52A9\u7406\u9700\u8981\u66F4\u65B0\uFF0C\u8BF7\u66F4\u65B0\u540E\u91CD\u65B0\u8FDE\u63A5\u3002":bt(a))}};r(()=>{let e=b.current;e.mounted=!0;let a=new AbortController;h(a.signal);let _=setInterval(()=>{e.mounted&&Te(e.frames),e.frames=0},1e3),p=()=>{document.hidden?(le(),J({type:"pause"})):e.socket?.readyState===1?J({type:"resume"}):e.reconnectAllowed&&e.config?.configured&&e.session===null&&e.socket&&y(e.mode,!0)},V=typeof ResizeObserver=="function"?new ResizeObserver(()=>{e.lastDrawnFrame&&(e.pendingFrame=e.lastDrawnFrame,Ee())}):null;G.current&&V?.observe(G.current);let ce=()=>le(),Q=K=>{Ae.current?.contains(K.target)||le()};return document.addEventListener("visibilitychange",p),window.addEventListener("blur",ce),document.addEventListener("pointerdown",Q,!0),()=>{e.mounted=!1,V?.disconnect(),e.pointerFrame&&cancelAnimationFrame(e.pointerFrame),a.abort(),ne(!1),clearInterval(_),document.removeEventListener("visibilitychange",p),window.removeEventListener("blur",ce),document.removeEventListener("pointerdown",Q,!0)}},[t]);let f=e=>Je({clientX:e.clientX,clientY:e.clientY,rect:G.current.getBoundingClientRect(),display:b.current.display}),v=e=>{e.preventDefault();let a=b.current,_=[1,2,3][e.button]||1;e.type==="pointerdown"?(xe.current?.focus(),G.current?.setPointerCapture(e.pointerId),Z({type:"button",action:"down",button:_,...f(e)})&&a.buttons.add(_)):(Z({type:"button",action:"up",button:_,...f(e)}),a.buttons.delete(_),G.current?.hasPointerCapture(e.pointerId)&&G.current.releasePointerCapture(e.pointerId))},I=e=>{if(b.current.composition||e.isComposing||e.nativeEvent?.isComposing||e.key==="Process"||e.key==="Unidentified")return;if(nt(e)){e.preventDefault(),$e();return}if(rt(e)){e.preventDefault(),e.type==="keydown"&&!e.repeat&&Oe();return}let a=e.ctrlKey||e.metaKey||e.altKey;if(e.key.length===1&&!a||e.key==="Escape"&&q.current)return;e.preventDefault();let _=Wt[e.key]||e.key;/^[A-Za-z0-9_]+$/u.test(_)&&(e.type==="keydown"?!e.repeat&&Z({type:"key",action:"down",key:_})&&b.current.pressed.add(_):(Z({type:"key",action:"up",key:_}),b.current.pressed.delete(_)))},C={loading:"\u6B63\u5728\u68C0\u67E5\u52A9\u7406\u72B6\u6001",idle:"\u51C6\u5907\u8FDE\u63A5",dormant:"\u5DF2\u7A7A\u95F2",resuming:"\u6B63\u5728\u6062\u590D\u684C\u9762",unconfigured:"\u4E2A\u4EBA\u52A9\u7406\u5C1A\u672A\u5F00\u901A",empty:"\u6682\u65F6\u6CA1\u6709\u53EF\u7528\u52A9\u7406","directory-error":"\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u52A9\u7406\u5217\u8868",connecting:"\u6B63\u5728\u542F\u52A8\u4E91\u7535\u8111",readonly:"\u53EA\u8BFB\u65C1\u89C2",ready:"\u6B63\u5728\u63A7\u5236\u4E91\u7535\u8111",reconnecting:"\u6B63\u5728\u6062\u590D\u8FDE\u63A5",hidden:"\u753B\u9762\u5DF2\u6682\u505C",closed:"\u684C\u9762\u8FDE\u63A5\u5DF2\u7ED3\u675F",error:"\u8FDE\u63A5\u6682\u65F6\u4E0D\u53EF\u7528"}[R],P={...de,borderRadius:6,padding:"7px 12px",cursor:"pointer",font:"inherit"},B=["ready","readonly","hidden","reconnecting","dormant","resuming"].includes(R),H=w.length>0,Pe=R==="unconfigured"?"\u5F00\u901A\u540E\uFF0C\u5728\u8FD9\u91CC\u8FDE\u63A5\u4F60\u7684\u4E2A\u4EBA\u52A9\u7406":R==="empty"?"\u52A9\u7406\u6B63\u5728\u51C6\u5907\u4E2D":R==="directory-error"?"\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7AEF\u52A9\u7406":"\u6B63\u5728\u68C0\u67E5\u52A9\u7406\u72B6\u6001",St=R==="unconfigured"?"\u5F00\u901A\u5B8C\u6210\u540E\uFF0C\u5373\u53EF\u5728\u8FD9\u91CC\u8FDE\u63A5\u4E13\u5C5E\u4E91\u7535\u8111\u3002":R==="empty"?"\u4E91\u7AEF\u521D\u59CB\u5316\u5B8C\u6210\u540E\uFF0C\u53EF\u7528\u52A9\u7406\u4F1A\u663E\u793A\u5728\u8FD9\u91CC\u3002":R==="directory-error"?D:"\u8BF7\u7A0D\u5019",Be=c==="computer"||c==="native-tab",Xe=o("div",{ref:Ae,"data-personal-assistant-desktop-card":Be?"true":void 0,style:{position:"relative",background:"var(--dsw-alias-bg-layer-2, #f1f3f6)",...Be?{width:"100%",aspectRatio:`${b.current.display.width} / ${b.current.display.height}`,flex:"none",minWidth:0,borderRadius:14,overflow:"hidden",boxShadow:"0 0 0 1px var(--dsw-alias-border-default, #d8dee8), 0 8px 28px #1018280d"}:{flex:1,minHeight:240}}},["dormant","resuming"].includes(R)?o("div",{role:"status",style:{position:"absolute",inset:0,zIndex:1,pointerEvents:"none",display:"grid",placeItems:"center",padding:16,textAlign:"center",background:"color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 82%, transparent)",color:"var(--dsw-alias-label-primary, #17202c)"}},R==="dormant"?"\u5DF2\u7A7A\u95F2\uFF0C\u64CD\u4F5C\u684C\u9762\u5373\u53EF\u6062\u590D":"\u6B63\u5728\u6062\u590D\u684C\u9762\u2026"):null,o("canvas",{ref:G,"aria-label":"\u4E91\u7535\u8111\u684C\u9762",tabIndex:B?0:-1,onPointerDown:v,onPointerUp:v,onPointerCancel:we,onLostPointerCapture:we,onPointerLeave:()=>{ee.current&&(ee.current.style.visibility="hidden")},onPointerMove:e=>{let a=b.current,_=e.nativeEvent?.getCoalescedEvents?.().at(-1)||e;if(ee.current){let p=G.current.getBoundingClientRect();ee.current.style.transform=`translate(${_.clientX-p.left}px, ${_.clientY-p.top}px)`,ee.current.style.visibility=a.readOnly?"hidden":"visible"}a.lastPointer=f(_),a.pointerFrame||(a.pointerFrame=requestAnimationFrame(()=>{a.mounted&&Ie()}))},onContextMenu:e=>e.preventDefault(),onWheel:e=>{e.preventDefault(),Z({type:"wheel",deltaY:e.deltaY/100,deltaX:e.deltaX/100})},onKeyDown:I,onKeyUp:I,style:{...Be?{position:"absolute",inset:0}:{},width:"100%",height:"100%",display:"block",visibility:B?"visible":"hidden",pointerEvents:B?"auto":"none",touchAction:"none",cursor:j?"default":"none"}}),o("div",{ref:ee,"aria-hidden":!0,style:{position:"absolute",top:0,left:0,pointerEvents:"none",visibility:"hidden",zIndex:2,width:18,height:22}},o("svg",{viewBox:"0 0 18 22",width:18,height:22},o("path",{d:"M1 1v16l4-4 3 7 3-1-3-7h6z",fill:"#fff",stroke:"#162033",strokeWidth:1.2}))),B?null:o("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,padding:16,textAlign:"center"}},o("h2",{style:{margin:0,fontSize:18,fontWeight:500}},H?C:Pe),o("p",{style:{margin:0,maxWidth:380,lineHeight:1.7,color:"var(--dsw-alias-label-secondary, #536174)"}},H?F||"\u8FDE\u63A5\u540E\u5373\u53EF\u4F7F\u7528\u4E91\u7AEF\u684C\u9762\uFF0C\u5173\u95ED\u9762\u677F\u4F1A\u91CA\u653E\u672C\u6B21\u63A7\u5236\u3002":St),!H&&R!=="loading"?o("button",{style:P,onClick:()=>{h()}},"\u68C0\u67E5\u5F00\u901A\u72B6\u6001"):null),o("input",{ref:xe,"aria-label":"\u4E91\u7535\u8111\u6587\u672C\u8F93\u5165",autoComplete:"off",disabled:!B||j&&!O.current.snapshot.available&&!(b.current.mode==="control"&&["dormant","resuming"].includes(R)),tabIndex:-1,style:{position:"absolute",width:1,height:1,opacity:0,left:0,top:0},onKeyDown:I,onKeyUp:I,onCompositionStart:()=>{b.current.composition=!0},onCompositionEnd:e=>{b.current.composition=!1;let a=e.currentTarget.value;e.currentTarget.value="",a&&Z({type:"text",text:a})},onInput:e=>{if(b.current.composition||e.nativeEvent?.isComposing)return;let a=e.currentTarget.value;e.currentTarget.value="",a&&Z({type:"text",text:a})}})),Re="var(--dsw-alias-label-secondary, #536174)",Qt={...P,background:"transparent",color:"inherit",border:de.border},Ge={...P,borderRadius:999,padding:"7px 16px",border:"none",fontWeight:500,background:"var(--dsw-alias-label-primary, #17202c)",color:"var(--dsw-alias-bg-layer-1, #fff)"};return Be?o("section",{"data-personal-assistant-computer":"true",style:{...de,border:"none",height:"100%",minHeight:0,minWidth:0,display:"flex",flexDirection:"column",background:"var(--dsw-alias-bg-base, #fff)",color:"inherit",fontSize:13}},c!=="native-tab"?o("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:de.border}},o("strong",{style:{fontWeight:500}},"\u4E91\u7535\u8111"),o("span",{role:"status","aria-live":"polite",style:{color:Re,fontSize:12}},C),null):null,j&&B&&!O.current.snapshot.available?o("div",{role:"alert",style:{background:"#fff0d6",color:"#763c00",padding:"8px 12px"}},"\u53EA\u8BFB\u65C1\u89C2\uFF1A\u9F20\u6807\u548C\u952E\u76D8\u4E0D\u4F1A\u53D1\u9001\u5230\u4E91\u7535\u8111"):null,o("div",{"data-personal-assistant-desktop-layout":"true",style:{flex:1,minHeight:0,minWidth:0,overflow:"auto",display:"flex",flexDirection:"column",alignItems:"center",gap:12,padding:"20px 16px 12px",boxSizing:"border-box"}},o("div",{"data-personal-assistant-desktop-stack":"true",style:{width:"100%",maxWidth:1280,margin:"auto 0",display:"flex",flexDirection:"column",alignItems:"center",gap:12,flex:"none"}},Xe,B||H?o("div",{"data-personal-assistant-control-capsule":"true",role:"status","aria-live":"polite",style:{display:"flex",flexWrap:"wrap",justifyContent:"center",alignItems:"center",gap:6,width:"fit-content",maxWidth:"100%",boxSizing:"border-box",padding:"7px 12px",borderRadius:999,background:"var(--dsw-alias-bg-layer-1, #fff)",border:de.border,boxShadow:"0 1px 4px #10182808",lineHeight:1.5}},!B&&H?o("button",{style:Ge,disabled:["connecting","resuming"].includes(R),onClick:()=>{y(b.current.handoffSupported?"observe":"read")}},R==="connecting"?"\u6B63\u5728\u542F\u52A8\u2026":"\u91CD\u65B0\u8FDE\u63A5"):null,B&&j?o("span",{style:{color:Re,fontSize:12}},ke==="acquiring"?"\u6B63\u5728\u63A5\u7BA1\u2026":ke==="releasing"?"\u6B63\u5728\u4EA4\u8FD8\u2026":"\u52A9\u7406\u6B63\u5728\u4F7F\u7528 \xB7 \u70B9\u753B\u9762\u5373\u53EF\u63A5\u7BA1"):null,B&&j&&O.current.snapshot.available?o("button",{style:{...Ge,padding:"3px 9px",fontSize:11},onClick:()=>O.current.acquire()},"\u63A5\u7BA1"):null,B&&!j?o("span",{style:{color:Re,fontSize:12}},"\u60A8\u62E5\u6709\u63A7\u5236\u6743 \xB7 \u70B9\u753B\u9762\u5916\u91CA\u653E"):null,B&&F?o("span",{style:{color:Re,fontSize:12}},F):null,B&&ye?o("span",{role:"status","aria-live":"polite",style:{color:Re,fontSize:12}},ye):null):null),o("details",{style:{alignSelf:"flex-end",color:"var(--dsw-alias-label-tertiary, #76808e)",fontSize:11,opacity:.8,maxWidth:"100%",overflowWrap:"anywhere"}},o("summary",{style:{cursor:"pointer"}},"\u8BCA\u65AD"),o("small",{"data-personal-assistant-build":De},`\u6784\u5EFA ${De}`)))):o("section",{"data-personal-assistant-panel":"true",style:{...de,border:"none",height:"100%",minHeight:0,display:"flex",flexDirection:"column",fontSize:13}},o("header",{style:{display:"flex",flexWrap:"wrap",gap:8,alignItems:"center",padding:12,borderBottom:de.border}},o("strong",{style:{fontWeight:500,marginRight:8}},"\u4E2A\u4EBA\u52A9\u7406"),H&&["idle","closed","error"].includes(R)?o("button",{style:P,onClick:()=>{h()}},"\u5237\u65B0\u52A9\u7406\u5217\u8868"):null,typeof l=="function"?o("button",{style:P,onClick:l},"\u653E\u5230\u53F3\u4FA7\u680F"):null,H?o("button",{style:P,disabled:["connecting","resuming"].includes(R),onClick:()=>R==="dormant"?i():void y(b.current.handoffSupported?"observe":"control")},R==="dormant"?"\u6062\u590D\u753B\u9762":j&&R==="readonly"?"\u7533\u8BF7\u63A7\u5236":B?"\u91CD\u65B0\u8FDE\u63A5":"\u8FDE\u63A5\u4E91\u7535\u8111"):null,H?o("button",{style:P,disabled:R==="connecting",onClick:()=>{y("read")}},"\u53EA\u8BFB\u65C1\u89C2"):null,B?o("span",{role:"status","aria-live":"polite",style:{marginLeft:"auto",color:"var(--dsw-alias-label-secondary, #536174)"}},C):null),R==="readonly"?o("div",{role:"alert",style:{background:"#fff0d6",color:"#763c00",padding:"8px 12px"}},"\u5F53\u524D\u4E3A\u53EA\u8BFB\u65C1\u89C2\uFF0C\u9F20\u6807\u548C\u952E\u76D8\u8F93\u5165\u4E0D\u4F1A\u53D1\u9001\uFF1B\u53EF\u7533\u8BF7\u63A7\u5236"):null,B&&F?o("div",{role:"status",style:{padding:"8px 12px"}},F):null,Xe,o("footer",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:12,padding:"7px 12px",color:"var(--dsw-alias-label-secondary, #536174)",borderTop:de.border}},o("details",{open:m,onToggle:e=>ae(e.currentTarget.open)},o("summary",{style:{cursor:"pointer"}},"\u8BCA\u65AD"),U?o("div",{style:{paddingTop:8}},`\u76EE\u5F55\u8FDE\u63A5\u5173\u95ED\u7801\uFF1A${U}`):null,o("div",{style:{paddingTop:8,lineHeight:1.8,overflowWrap:"anywhere"}},o("div",null,`\u4E91\u7AEF\u5B9E\u4F8B\uFF1A${E?.agentId||"\u672A\u5F00\u901A"}`),o("div",null,`\u8FDE\u63A5\u6807\u8BC6\uFF1A${X||"\u672A\u8FDE\u63A5"}`),o("div",null,`\u753B\u9762\u5E27\u7387\uFF1A${oe} fps`),o("div",null,"\u5FEB\u6377\u952E\u4F1A\u8F6C\u53D1\u5230\u4E91\u7535\u8111\uFF1BEsc \u4F18\u5148\u9000\u51FA\u5168\u5C4F"))),o("small",{"data-personal-assistant-build":De,style:{opacity:.75}},`\u6784\u5EFA ${De}`)))}function qt({request:t,nativeWorkbench:g}={}){let l=me||globalThis.React;if(!l)return"\u4E2A\u4EBA\u52A9\u7406\u9875\u9762\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00";let{createElement:c,useEffect:n,useState:s,useCallback:o}=l,[r,u]=s(null),[d,E]=s(""),[A,w]=s(0);n(()=>{let D=!1;return u(null),E(""),(async()=>{try{let S=await t("personal-assistant.configuration");if(!S.configured)throw new Error("\u4E2A\u4EBA\u52A9\u7406\u5C1A\u672A\u5F00\u901A\uFF0C\u8BF7\u5148\u5728\u8BBE\u7F6E\u4E2D\u8FDE\u63A5\u4E91\u7AEF\u5B9E\u4F8B");let U=await t("personal-assistant.bots.list");if(U.directoryAvailable!==!0)throw new Error("\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7AEF\u52A9\u7406\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");let $=Ke(U.bots,S.botId||U.primaryBotId);D||u({agentId:S.agentId,botId:$})}catch(S){D||E(S.message||"\u4E91\u7AEF\u52A9\u7406\u6682\u4E0D\u53EF\u7528")}})(),()=>{D=!0}},[t,A]);let T=o((D,S={})=>{if(!r)throw new Error("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u8FDE\u63A5");if(S.agentId&&S.agentId!==r.agentId)throw new Error("\u4E91\u7AEF\u5B9E\u4F8B\u4E0D\u4E00\u81F4");if(D!=="personal-assistant.bots.list"&&S.botId&&S.botId!==r.botId)throw new Error("\u4E91\u7AEF\u52A9\u7406\u4E0D\u4E00\u81F4");return t(D,{...S,...r})},[t,r?.agentId,r?.botId]);return n(()=>{r&&g?.available?g.bind(r,T):r&&E(g?.unavailableReason||"\u5F53\u524D\u5BBF\u4E3B\u9700\u8981\u66F4\u65B0\u539F\u751F\u4FA7\u680F\u7EC4\u4EF6")},[g,T,r?.agentId,r?.botId]),r?g?.available?c("div",{key:`${r.agentId}:${r.botId}`,"data-personal-assistant-home":"true","data-agent-id":r.agentId,"data-bot-id":r.botId,style:{flex:"1 1 0px",height:"100%",maxHeight:"100%",minHeight:0,minWidth:0,overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column"}},c(ut,{React:l,request:T,scope:r,onOpenComputer:()=>g.open()})):c("div",{role:"alert",style:{padding:24}},"\u5F53\u524D\u5BBF\u4E3B\u5C1A\u672A\u63D0\u4F9B\u539F\u751F\u4E91\u7535\u8111\u4FA7\u680F\uFF0C\u8BF7\u66F4\u65B0 Studio \u540E\u91CD\u65B0\u6253\u5F00\u3002"):c("div",{role:"status",style:{padding:24}},d||"\u6B63\u5728\u8FDE\u63A5\u4E91\u7AEF\u4E2A\u4EBA\u52A9\u7406\u2026",d?c("button",{onClick:()=>w(D=>D+1)},"\u91CD\u65B0\u8FDE\u63A5"):null)}var N={page:{padding:"2px 2px 28px",display:"flex",flexDirection:"column",gap:18,maxWidth:700,fontSize:13,color:"var(--dsw-alias-label-primary, #17202c)"},title:{margin:0,fontSize:18,fontWeight:600,letterSpacing:"-0.01em"},lede:{margin:0,color:"var(--dsw-alias-label-secondary, #536174)",fontSize:13,lineHeight:1.7},card:{border:de.border,borderRadius:12,overflow:"hidden"},row:{display:"flex",gap:16,padding:"12px 14px",borderTop:"1px solid var(--dsw-alias-border-default, #d8dee8)",alignItems:"flex-start"},rowFirst:{display:"flex",gap:16,padding:"12px 14px",alignItems:"flex-start"},label:{width:116,flex:"none",color:"var(--dsw-alias-label-secondary, #536174)",fontSize:13,lineHeight:1.7},value:{flex:1,minWidth:0,fontSize:13,lineHeight:1.7,overflowWrap:"anywhere"},mono:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12},actions:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},button:{...de,borderRadius:8,padding:"6px 11px",cursor:"pointer",font:"inherit",fontSize:13},note:{color:"var(--dsw-alias-label-secondary, #536174)",fontSize:12,lineHeight:1.7},badge:{display:"inline-block",borderRadius:999,padding:"1px 8px",fontSize:12,lineHeight:1.7},badgeOk:{background:"color-mix(in srgb, #067647 12%, transparent)",color:"#067647"},badgeIdle:{background:"color-mix(in srgb, #946200 14%, transparent)",color:"#946200"},badgeError:{background:"color-mix(in srgb, #b42318 12%, transparent)",color:"#b42318"}};function Ht({request:t,openComputer:g=null}={}){let l=me||globalThis.React;if(!l)return"\u8BBE\u7F6E\u9875\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00 Studio";let{createElement:c,useEffect:n,useState:s,useCallback:o}=l,[r,u]=s(null),[d,E]=s(null),[A,w]=s(""),[T,D]=s(!1),[S,U]=s(""),$=o(async()=>{D(!0),w("");let R=Date.now();try{let L=await t("personal-assistant.configuration");if(u(L),L?.configured){let F=await t("personal-assistant.bots.list");E(Array.isArray(F?.bots)?F.bots:[])}else E([]);U(`${new Date().toLocaleTimeString("zh-CN",{hour12:!1})} \xB7 ${Date.now()-R} ms`)}catch(L){w(L?.message||"\u8FDE\u63A5\u68C0\u67E5\u5931\u8D25"),U(`${new Date().toLocaleTimeString("zh-CN",{hour12:!1})} \xB7 \u5931\u8D25`)}finally{D(!1)}},[t]);n(()=>{$()},[$]);let m=r?.configured===!0,ae=r===null?"\u68C0\u67E5\u4E2D":m?"\u5DF2\u5F00\u901A":"\u5C1A\u672A\u5F00\u901A",X={...N.badge,...r===null?N.badgeIdle:m?N.badgeOk:N.badgeIdle},z=(R,L,F=!1)=>c("div",{style:F?N.rowFirst:N.row},c("div",{style:N.label},R),c("div",{style:N.value},L));return c("section",{"data-personal-assistant-settings":"true",style:N.page},c("div",null,c("h1",{style:N.title},"\u4E2A\u4EBA\u52A9\u7406"),c("p",{style:{...N.lede,marginTop:6}},"\u4E91\u7AEF\u6301\u7EED\u8FD0\u884C\u7684\u52A9\u7406\uFF0C\u5E26\u4E00\u53F0\u72EC\u7ACB\u4E91\u7535\u8111\u3002\u5173\u6389\u7A97\u53E3\u5B83\u4E5F\u5728\u5DE5\u4F5C\uFF1B\u5BF9\u8BDD\u4E0E\u4E91\u7535\u8111\u5728\u5DE6\u4FA7\u300C\u4E2A\u4EBA\u52A9\u7406\u300D\u9875\u3002")),A?c("div",{role:"alert",style:{...N.note,color:"#b42318",background:"color-mix(in srgb, #b42318 8%, transparent)",border:"1px solid color-mix(in srgb, #b42318 25%, transparent)",borderRadius:10,padding:"9px 12px"}},A):null,c("div",{style:N.card},z("\u72B6\u6001",c("span",null,c("span",{style:X},ae),S?c("span",{style:N.note},`\u3000\u4E0A\u6B21\u68C0\u67E5 ${S}`):null),!0),z("\u4E91\u7AEF\u5B9E\u4F8B",r?.agentId?c("span",{style:N.mono},r.agentId):c("span",{style:N.note},m?"\u672A\u8FD4\u56DE\u5B9E\u4F8B\u6807\u8BC6":"\u5F00\u901A\u540E\u7531 Studio \u7ED1\u5B9A")),z("\u7F51\u5173",r?.gatewayUrl?c("span",{style:N.mono},r.gatewayUrl):c("span",{style:N.note},"\u7531 Studio Host \u914D\u7F6E")),z("\u52A9\u7406\u8FDE\u63A5",c("span",{style:N.note},d===null?"\u68C0\u67E5\u4E2D":d.length?"\u5DF2\u8FDE\u63A5\u4F60\u7684\u52A9\u7406":"\u52A9\u7406\u5C1A\u672A\u5C31\u7EEA")),z("\u8BB0\u5FC6",c("div",null,c("div",{style:N.mono},"/workspace/assistant-state"),c("div",{style:N.note},"\u8BB0\u5FC6\u3001\u4F1A\u8BDD\u4E0E\u5B9A\u65F6\u4EFB\u52A1\u968F\u4E91\u7535\u8111\u6301\u4E45\u4FDD\u5B58\uFF0C\u6362\u8BBE\u5907\u4E5F\u5728"))),z("\u4E91\u7AEF\u80FD\u529B",c("div",null,c("div",null,"\u9ED8\u8BA4\u5F00\u542F\uFF1A\u4E91\u7AEF\u547D\u4EE4\u6267\u884C\u3001\u4E91\u7AEF\u6D4F\u89C8\u5668"),c("div",{style:N.note},"\u90FD\u8DD1\u5728\u9694\u79BB\u5DE5\u4F5C\u533A\uFF1A\u8BFB\u4E0D\u5230\u672C\u673A\u6587\u4EF6\u4E0E\u51ED\u8BC1\uFF0C\u4E0D\u80FD\u8BBF\u95EE\u5185\u7F51\u4E0E\u672C\u673A\u5730\u5740\uFF1B\u654F\u611F\u64CD\u4F5C\u4F1A\u5148\u8BF7\u4F60\u786E\u8BA4"))),z("\u63D2\u4EF6\u7248\u672C",c("span",{style:N.note},`\u6784\u5EFA ${De}`))),c("div",{style:N.actions},c("button",{style:N.button,disabled:T,onClick:()=>{$()}},T?"\u6B63\u5728\u68C0\u67E5\u2026":"\u68C0\u67E5\u8FDE\u63A5"),c("span",{style:N.note},"\u68C0\u67E5\u4F1A\u8BFB\u53D6\u5F00\u901A\u72B6\u6001\u5E76\u62C9\u53D6\u4E00\u6B21\u52A9\u7406\u5217\u8868\uFF0C\u4E0D\u4F1A\u542F\u52A8\u4E91\u7535\u8111")))}function Kt({size:t}={}){let g=me,l=Number(t)>0?Number(t):16;return g?.createElement?g.createElement("svg",{width:l,height:l,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"block"}},g.createElement("path",{d:"M3.4 3.2h9.2a1.3 1.3 0 0 1 1.3 1.3H7.7l-2.9 2.3v-2.3H3.4a1.3 1.3 0 0 1-1.3-1.3V4.5a1.3 1.3 0 0 1 1.3-1.3z"}),g.createElement("path",{d:"M8.1 5.6l.62 1.46 1.46.62-1.46.62L8.1 9.76l-.62-1.46-1.46-.62 1.46-.62z"})):"\u52A9"}function Yt({size:t}={}){let g=me,l=Number(t)>0?Number(t):16;return g?.createElement?g.createElement("svg",{width:l,height:l,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"block",flex:"0 0 auto"}},g.createElement("rect",{x:2.2,y:3.4,width:11.6,height:7.4,rx:1.4}),g.createElement("path",{d:"M6.6 13.4h2.8"}),g.createElement("path",{d:"M8 10.8v2.6"})):null}function Vt(){let t=me,g=Yt({size:15});return!t?.createElement||!g?"\u4E91\u7535\u8111":t.createElement("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",lineHeight:1}},g,t.createElement("span",null,"\u4E91\u7535\u8111"))}function It(t){if(!t?.slots?.inject||!t.slots.register)throw new TypeError("Personal Assistant client requires the public DSH slots service");let g=async(s,o={})=>{if(!t.connection?.rpc?.call)throw new Ve;let r=await t.connection.rpc.call("/api","personal-assistant",{operation:s,payload:o});if(!r?.ok)throw Object.assign(new Error(r?.error?.message||"Studio Host \u8BF7\u6C42\u5931\u8D25"),{code:r?.error?.code,status:r?.error?.details?.status,closeCode:r?.error?.details?.closeCode});return r.value},l=(s,o)=>{try{let r=()=>s();return typeof t.effect=="function"?t.effect(r,o):r()}catch(r){try{console.warn(`[personal-assistant] ${o} \u6CE8\u518C\u5931\u8D25`,r)}catch{}return}},c=gt({sidebarRight:t.sidebarRight,slots:t.slots});c&&(c.render=s=>ht({...s,React:me||globalThis.React,workbench:c,Panel:mt}),l(()=>()=>c.dispose(),"personal-assistant: native workbench")),l(()=>t.slots.inject("main",()=>t.slots.register({name:"main",key:Ye,inject:()=>({request:g,nativeWorkbench:c})},qt)),"personal-assistant: main panel"),l(()=>t.slots.inject("sidebar.panellist",()=>t.slots.register({name:"sidebar.panellist",id:Ye,order:90,label:"\u4E2A\u4EBA\u52A9\u7406"},Kt)),"personal-assistant: sidebar row"),l(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:`${Ye}-settings`,order:196,label:"\u4E2A\u4EBA\u52A9\u7406",inject:()=>({request:g})},Ht)),"personal-assistant: settings section"),typeof t.inject=="function"&&l(()=>t.inject(["sidebarRightTabs"],s=>{let o=[],r=u=>{typeof u=="function"&&o.push(u)};try{let u=s.sidebarRightTabs;if(u===void 0||typeof u.register!="function")return;r(u.register({id:Ue,kind:Ue,title:()=>"\u4E91\u7535\u8111",guide:[{order:20,title:()=>"\u4E91\u7535\u8111",description:()=>"\u4E2A\u4EBA\u52A9\u7406\u7684\u4E91\u7AEF\u7535\u8111\u753B\u9762\uFF0C\u53EF\u83B7\u53D6\u63A7\u5236\u6743"}]})),r(s.slots.inject("sidebar.right.pane.tab",()=>s.slots.register({name:"sidebar.right.pane.tab",key:Ue,inject:()=>({request:g})},d=>mt({...d,variant:"computer"})))),r(s.slots.inject("sidebar.right.pane.tab.title",()=>s.slots.register({name:"sidebar.right.pane.tab.title",key:Ue},Vt)))}catch(u){try{console.warn("[personal-assistant] \u53F3\u4FA7\u680F\u6CE8\u518C\u5931\u8D25",u)}catch{}}return()=>{for(let u of o.reverse())u()}}),"personal-assistant: right tab")}window.__ModuleLoader__.load({id:"@kingsoftcloud/agentkit-personal-assistant",factory:t=>(wt(t("react")),{name:"agentkit-personal-assistant",inject:xt,apply:It})});})();
3
+ `),r=[],n=0,a=o=>{o.length!==0&&(r.push({type:"paragraph",text:o.join(`
4
+ `)}),o.length=0)},s=[];for(;n<d.length;){let o=d[n],f=Mt.exec(o);if(f){a(s);let R=[];for(n+=1;n<d.length&&!/^```\s*$/u.test(d[n]);)R.push(d[n]),n+=1;n+=1,r.push({type:"code",lang:f[1]||"",text:R.join(`
5
+ `)});continue}if(o.trim()===""){a(s),n+=1;continue}let p=$t.exec(o);if(p){a(s),r.push({type:"heading",level:p[1].length,text:p[2].trim()}),n+=1;continue}if(jt.test(o)){a(s),r.push({type:"rule"}),n+=1;continue}let E=Ge.exec(o);if(E){a(s);let R=[E[1]];for(n+=1;n<d.length&&Ge.test(d[n]);)R.push(Ge.exec(d[n])[1]),n+=1;r.push({type:"quote",text:R.join(`
6
+ `)});continue}let D=pt.exec(o),S=ft.exec(o);if(D||S){a(s);let R={type:S?"ordered":"unordered",items:[],start:S?Number(S[1]):1};for(;n<d.length;){let N=pt.exec(d[n]),T=ft.exec(d[n]);if(!N&&!T)break;R.items.push((N?N[1]:T[2]).trim()),n+=1}r.push(R);continue}s.push(o),n+=1}return a(s),r}function Ht(t){let g=typeof t=="string"?t:"",d=[],r=a=>{a&&d.push({type:"text",text:a})},n=g;for(;n.length>0;){let a=/^`([^`]+)`/u.exec(n);if(a){d.push({type:"code",text:a[1]}),n=n.slice(a[0].length);continue}let s=/^\*\*([^*\n]+)\*\*/u.exec(n)||/^__([^_\n]+)__/u.exec(n);if(s){d.push({type:"strong",text:s[1]}),n=n.slice(s[0].length);continue}let o=/^\*([^*\s][^*\n]*)\*/u.exec(n)||/^_([^_\s][^_\n]*)_/u.exec(n);if(o){d.push({type:"em",text:o[1]}),n=n.slice(o[0].length);continue}let f=/^\[([^\]]+)\]\(([^)\s]+)\)/u.exec(n);if(f){d.push({type:"link",text:f[1],href:f[2]}),n=n.slice(f[0].length);continue}let p=n.slice(1).search(/[`*_[\]\n]/u),E=p<0?n.length:p+1;r(n.slice(0,E)),n=n.slice(E)}return d.reduce((a,s)=>{let o=a[a.length-1];return s.type==="text"&&o&&o.type==="text"?a[a.length-1]={type:"text",text:o.text+s.text}:a.push(s),a},[])}function gt(t,g,d={}){let r=Wt(g);if(r.length===0)return null;let n=(a,s)=>Ht(a).map((o,f)=>{let p=`${s}-i${f}`;return o.type==="code"?t("code",{key:p,style:d.inlineCode},o.text):o.type==="strong"?t("strong",{key:p},o.text):o.type==="em"?t("em",{key:p},o.text):o.type==="link"?/^(https?:|mailto:|cloud-file:)/iu.test(o.href)?t("a",{key:p,href:o.href,target:"_blank",rel:"noreferrer noopener",style:d.link},o.text):t("span",{key:p},o.text):t("span",{key:p},o.text)});return r.map((a,s)=>{let o=`b${s}`;if(a.type==="code")return t("pre",{key:o,style:d.codeBlock},t("code",null,a.text));if(a.type==="heading")return t("div",{key:o,style:{...d.heading,...a.level<=2?d.headingStrong:null}},n(a.text,o));if(a.type==="rule")return t("hr",{key:o,style:d.rule});if(a.type==="quote")return t("blockquote",{key:o,style:d.quote},n(a.text,o));if(a.type==="unordered"||a.type==="ordered"){let f=a.type==="ordered"?"ol":"ul";return t(f,{key:o,style:d.list,start:a.type==="ordered"&&a.start!==1?a.start:void 0},a.items.map((p,E)=>t("li",{key:`${o}-l${E}`},n(p,`${o}-l${E}`))))}return t("p",{key:o,style:d.paragraph},n(a.text,o))})}var qt="\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u4F60\uFF1F",Kt=new Set(["DSH_SESSION_BUSY","DSH_TURN_TIMEOUT"]),bt={RUNTIME_PROCESS_INTERRUPTED:"\u4E91\u7535\u8111\u91CD\u542F\uFF0C\u4EFB\u52A1\u88AB\u4E2D\u65AD",DSH_SESSION_CONTROLLER_UNAVAILABLE:"\u4E91\u7AEF\u8FDE\u63A5\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",DSH_TURN_NOT_ACCEPTED:"\u4E91\u7AEF\u6CA1\u6709\u63A5\u53D7\u8FD9\u4E00\u8F6E\u5BF9\u8BDD\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001",DSH_SESSION_NOT_FOUND:"\u4F1A\u8BDD\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"},Vt=t=>{let g=String(t||"").trim();return g?bt[g]?bt[g]:/^[A-Z][A-Z0-9_]{5,}$/u.test(g)?"\u4E91\u7AEF\u6CA1\u6709\u5B8C\u6210\u8FD9\u4E00\u8F6E\uFF0C\u8BF7\u91CD\u8BD5":g.slice(0,160):"\u8BF7\u68C0\u67E5\u4EFB\u52A1\u72B6\u6001\u540E\u91CD\u8BD5"},Yt=400,Qt=8,yt=1500,I={page:{flex:"1 1 0px",height:"100%",maxHeight:"100%",minHeight:0,minWidth:0,overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column",fontSize:13,color:"var(--dsw-alias-label-primary, #17202c)",background:"var(--dsw-alias-bg-layer-1, #fff)"},header:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:10,padding:"10px 16px",borderBottom:"1px solid var(--dsw-alias-border-default, #d8dee8)",flex:"none"},title:{margin:0,fontSize:14,fontWeight:600},status:{color:"var(--dsw-alias-label-secondary, #536174)",fontSize:12},spacer:{marginLeft:"auto"},ghost:{border:"1px solid var(--dsw-alias-border-default, #d8dee8)",background:"transparent",color:"inherit",borderRadius:8,padding:"5px 10px",cursor:"pointer",font:"inherit",fontSize:12},scroller:{flex:"1 1 0px",minHeight:0,minWidth:0,overflowY:"auto",overflowX:"hidden",overscrollBehavior:"contain",boxSizing:"border-box",padding:"20px 16px 8px"},thread:{maxWidth:720,margin:"0 auto",display:"flex",flexDirection:"column",gap:14},row:{display:"flex",flexDirection:"column",gap:4,alignItems:"flex-start"},rowUser:{display:"flex",flexDirection:"column",gap:4,alignItems:"flex-end"},who:{fontSize:11,color:"var(--dsw-alias-label-secondary, #536174)"},bubble:{maxWidth:"86%",padding:"9px 12px",borderRadius:12,lineHeight:1.7,overflowWrap:"anywhere",display:"flex",flexDirection:"column",gap:8,background:"color-mix(in srgb, currentColor 5%, transparent)"},paragraph:{margin:0,whiteSpace:"pre-wrap"},heading:{fontWeight:600,fontSize:13.5},headingStrong:{fontSize:15},list:{margin:0,paddingLeft:20,display:"flex",flexDirection:"column",gap:4},codeBlock:{margin:0,padding:"10px 12px",borderRadius:8,overflowX:"auto",fontSize:12,lineHeight:1.65,background:"color-mix(in srgb, currentColor 9%, transparent)",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},inlineCode:{padding:"1px 5px",borderRadius:5,fontSize:12,background:"color-mix(in srgb, currentColor 9%, transparent)",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},quote:{margin:0,paddingLeft:10,borderLeft:"3px solid var(--dsw-alias-border-default, #d8dee8)",color:"var(--dsw-alias-label-secondary, #536174)"},rule:{border:"none",borderTop:"1px solid var(--dsw-alias-border-default, #d8dee8)",margin:"2px 0",width:"100%"},link:{color:"#2f6bff",textDecoration:"none"},bubbleUser:{maxWidth:"86%",padding:"9px 12px",borderRadius:12,lineHeight:1.7,whiteSpace:"pre-wrap",overflowWrap:"anywhere",background:"color-mix(in srgb, #2f6bff 12%, transparent)"},pulse:{animation:"pa-awaiting 1.2s ease-in-out infinite"},step:{fontSize:12,color:"var(--dsw-alias-label-secondary, #536174)",lineHeight:1.7,overflowWrap:"anywhere"},centered:{flex:1,display:"grid",placeItems:"center",padding:24,textAlign:"center"},centeredInner:{maxWidth:420,display:"flex",flexDirection:"column",gap:10,alignItems:"center"},composer:{flex:"0 0 auto",minWidth:0,boxSizing:"border-box",padding:"8px 16px 14px"},composerInner:{maxWidth:720,minWidth:0,margin:"0 auto",display:"flex",flexDirection:"column",gap:6,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:16,padding:"10px 10px 8px 12px",background:"var(--dsw-alias-bg-layer-1, #fff)"},textarea:{flex:1,width:"100%",minWidth:0,boxSizing:"border-box",minHeight:24,maxHeight:200,resize:"none",border:"none",outline:"none",background:"transparent",color:"inherit",font:"inherit",fontSize:13,lineHeight:1.7},composerBar:{display:"flex",alignItems:"center",gap:8},iconButton:{flex:"none",width:28,height:28,display:"grid",placeItems:"center",cursor:"pointer",border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:999,background:"transparent",color:"var(--dsw-alias-label-secondary, #536174)",padding:0},send:{flex:"none",width:28,height:28,display:"grid",placeItems:"center",border:"none",borderRadius:999,cursor:"pointer",padding:0,background:"var(--dsw-alias-label-primary, #17202c)",color:"var(--dsw-alias-bg-layer-1, #fff)"},sendDisabled:{background:"var(--dsw-alias-border-default, #d8dee8)",color:"var(--dsw-alias-label-secondary, #536174)",cursor:"default"},sendQueued:{flex:"none",width:28,height:28,display:"grid",placeItems:"center",borderRadius:999,cursor:"pointer",padding:0,border:"1px dashed var(--dsw-alias-label-primary, #17202c)",background:"transparent",color:"var(--dsw-alias-label-primary, #17202c)"},queueBadge:{flex:"none",borderRadius:999,padding:"1px 8px",fontSize:11,lineHeight:"18px",background:"color-mix(in srgb, #946200 14%, transparent)",color:"#946200"},queueBubble:{maxWidth:"86%",padding:"9px 12px",borderRadius:12,lineHeight:1.7,whiteSpace:"pre-wrap",overflowWrap:"anywhere",border:"1px dashed color-mix(in srgb, currentColor 35%, transparent)",background:"color-mix(in srgb, currentColor 4%, transparent)",color:"var(--dsw-alias-label-secondary, #536174)"},queueRow:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},queueHint:{fontSize:11,color:"var(--dsw-alias-label-secondary, #536174)"},queueCancel:{border:"none",background:"transparent",cursor:"pointer",padding:"2px 4px",borderRadius:6,color:"var(--dsw-alias-label-secondary, #536174)",display:"inline-flex",alignItems:"center",gap:3,font:"inherit",fontSize:11},queueNotice:{maxWidth:720,margin:"0 auto 6px",fontSize:12,color:"#946200",lineHeight:1.6},attach:{flex:"none",display:"flex",alignItems:"center",gap:6,padding:"3px 8px 3px 4px",borderRadius:8,background:"var(--dsw-alias-bg-layer-2, #f4f6fa)",fontSize:11,maxWidth:180},attachName:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},attachThumb:{width:20,height:20,borderRadius:4,objectFit:"cover",flex:"none"},attachRow:{display:"flex",flexWrap:"wrap",gap:6}},ae=t=>typeof t=="string"?t:"",Xt=t=>t("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},t("path",{d:"M12 19V5M5 12l7-7 7 7"})),Gt=t=>t("svg",{width:15,height:15,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round","aria-hidden":!0},t("path",{d:"M12 5v14M5 12h14"})),ht=t=>t("svg",{width:10,height:10,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.4,strokeLinecap:"round","aria-hidden":!0},t("path",{d:"M6 6l12 12M18 6L6 18"}));function mt({React:t,request:g,scope:d,onOpenComputer:r=null}={}){if(!t)return"\u4E2A\u4EBA\u52A9\u7406\u5BF9\u8BDD\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00";let{createElement:n,useCallback:a,useEffect:s,useRef:o,useState:f}=t,[p,E]=f("loading"),[D,S]=f(""),[R,N]=f([]),[T,$]=f(""),[ee,v]=f([]),[ge,X]=f(""),[Y,O]=f([]),B=o(null),[W,L]=f(!1),[M,te]=f(!1),[Be,_e]=f(""),[ne,xe]=f([]),[we,q]=f(""),ie=o(0),G=o(new Map),z=o([]),ve=o(!1),K=o(null),Se=o(!1);Se.current=W;let P=o(!1);P.current=M;let de=o("loading");de.current=p;let he=o(0),C=o(!0),Ie=o(null),ue=o(!0),j=o("");j.current=T;let V=a(async(c,h={})=>{if(typeof g!="function")throw new Error("Studio Host \u5C1A\u672A\u8FDE\u63A5");return g(c,h)},[g]),w=a(c=>{!Array.isArray(c)||c.length===0||v(h=>{let i=[...h];for(let u of c)if(!(!u||typeof u!="object")){if(u.type==="message"){let y=ae(u.id)||`local-${i.length}`,x=ae(u.role)||"assistant",k=ae(u.text),fe=i.findIndex(me=>me.id===y),F={id:y,role:x,text:k,done:u.done!==!1,clientTurnId:u.clientTurnId,status:"accepted"};if(fe>=0)i[fe]={...i[fe],...F};else if(x==="user"){let me=i.findIndex(Me=>Me.role==="user"&&u.clientTurnId&&Me.clientTurnId===u.clientTurnId);me>=0?i[me]={...F}:i.push(F)}else i.push(F)}else if(u.type==="delta"){let y=ae(u.id)||`local-${i.length}`,x=i.findIndex(k=>k.id===y);x>=0?i[x]={...i[x],text:i[x].text+ae(u.text)}:i.push({id:y,role:"assistant",text:ae(u.text),done:!1})}else if(u.type==="step"&&ae(u.text)){let y={id:ae(u.id),role:"step",text:ae(u.text),done:!0},x=i.findIndex(k=>k.id===y.id);x>=0?i[x]=y:i.push(y)}}return i})},[]),re=a(async c=>{if(!c)return;let h=j.current;if(h&&h!==c&&z.current.length>0){let u=z.current.length;z.current=[],xe([]),K.current&&(clearTimeout(K.current),K.current=null),q(`\u5DF2\u5207\u6362\u4F1A\u8BDD\uFF0C${u} \u6761\u6392\u961F\u6D88\u606F\u672A\u53D1\u9001\uFF0C\u5DF2\u53D6\u6D88`)}else h&&h!==c&&q("");j.current=c;let i=++he.current;$(c),E("loading"),S(""),ie.current=0,ue.current=!0,v([]);try{let u=await V("personal-assistant.session.snapshot",{sessionId:c});if(!C.current||j.current!==c||i!==he.current)return;ie.current=Number(u?.cursor)||0;let y=Array.isArray(u?.messages)?u.messages:[];v(y.map((x,k)=>({id:ae(x?.id)||`history-${k}`,role:ae(x?.role)||"assistant",text:ae(x?.text),done:!0}))),te(u.turns?.some(x=>["queued","running"].includes(x.status))||!1),E("ready")}catch(u){if(!C.current||i!==he.current)return;E("error"),S(u?.message||"\u65E0\u6CD5\u8BFB\u53D6\u4F1A\u8BDD\u5185\u5BB9")}},[V]),ce=a(async()=>{if(E("loading"),S(""),!!C.current)try{let c=await V("personal-assistant.sessions.list");if(!C.current)return;let h=Array.isArray(c?.sessions)?c.sessions:[];if(N(h),h.length>0){await re(ae(h[0].sessionId));return}let i=await V("personal-assistant.session.create",{});if(!C.current)return;let u=ae(i?.sessionId);N(u?[{sessionId:u,title:ae(i?.title)||"\u65B0\u4F1A\u8BDD"}]:[]),await re(u)}catch(c){if(!C.current)return;E("error"),S(c?.message||"\u4F1A\u8BDD\u901A\u9053\u6682\u65F6\u4E0D\u53EF\u7528")}},[V,re]);s(()=>(C.current=!0,ce(),()=>{C.current=!1,K.current&&(clearTimeout(K.current),K.current=null)}),[ce]),s(()=>{if(p!=="ready"||!T)return;let c=!1,h=null,i=async()=>{try{let u=await V("personal-assistant.session.events",{sessionId:T,cursor:ie.current});if(c)return;if(ie.current=Number(u?.cursor??ie.current)||0,w(u?.events),Array.isArray(u.turns)){te(u.turns.some(F=>["queued","running"].includes(F.status)));let y=u.turns.findLast(F=>["queued","running"].includes(F.status)),x={cloud_computer:"\u64CD\u4F5C\u4E91\u7535\u8111",cloud_workspace:"\u5904\u7406\u4E91\u7AEF\u6587\u4EF6",cloud_bash:"\u6267\u884C\u4E91\u7AEF\u547D\u4EE4",cloud_run_code:"\u8FD0\u884C\u4E91\u7AEF\u4EE3\u7801",assistant_schedule:"\u8BBE\u7F6E\u4E91\u7AEF\u4EFB\u52A1"},k=y?.progress?.tool;_e(k?`${y.progress.state==="running"?"\u6B63\u5728":"\u5DF2\u5B8C\u6210"}${x[k]||(k.startsWith("cloud_browser_")?"\u64CD\u4F5C\u4E91\u7AEF\u6D4F\u89C8\u5668":"\u6267\u884C\u5DE5\u5177")}`:"");let fe=u.turns.filter(F=>["failed","interrupted","cancelled"].includes(F.status)&&!Kt.has(String(F.error||""))).map(F=>({type:"step",id:`turn-status-${F.turnId}`,text:`\u4EFB\u52A1${F.status==="failed"?"\u5931\u8D25":"\u5DF2\u4E2D\u65AD"}\uFF1A${Vt(F.error)}`}));w(fe)}S("")}catch(u){if(!c){if(u.code==="SESSION_CURSOR_STALE"){re(T);return}S(u.message||"\u4E91\u7AEF\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u6B63\u5728\u6062\u590D\uFF1B\u4EFB\u52A1\u4E0D\u4F1A\u6539\u5230\u672C\u673A\u6267\u884C")}}c||(h=setTimeout(i,600))};return h=setTimeout(i,200),()=>{c=!0,clearTimeout(h)}},[p,T,V,w,re]),s(()=>{let c=Ie.current;c&&ue.current&&(c.scrollTop=c.scrollHeight)},[ee,M]);let Fe=async c=>{let h=Array.from(c.target.files||[]);c.target.value="";let i=[];for(let u of h.slice(0,4)){if(!u||u.size>512*1024){S("\u6BCF\u4E2A\u9644\u4EF6\u6700\u591A 512 KiB\uFF0C\u8BF7\u5148\u538B\u7F29\u6216\u62C6\u5206\u6587\u4EF6");continue}let y=await new Promise(x=>{let k=new FileReader;k.onload=()=>x(String(k.result||"")),k.onerror=()=>x(""),k.readAsDataURL(u)});y&&i.push({id:`${Date.now()}-${u.name}`,name:u.name,mimeType:u.type||"application/octet-stream",size:u.size,dataUrl:y})}i.length&&O(u=>[...u,...i].slice(0,4))},be=c=>{z.current=c,xe(c)},Ce=()=>{K.current&&(clearTimeout(K.current),K.current=null)},oe=c=>Number(c?.status)===409||/SESSION_BUSY|active turn|正忙|处理中/u.test(`${c?.code||""} ${c?.message||""}`),Pe=async(c,{restoreDraft:h=!1}={})=>{G.current.set(c.clientTurnId,c),ue.current=!0,L(!0),S(""),te(!0),v(u=>u.some(y=>y.clientTurnId===c.clientTurnId)?u.map(y=>y.clientTurnId===c.clientTurnId?{...y,status:"pending"}:y):[...u,{id:`local-user-${c.clientTurnId}`,clientTurnId:c.clientTurnId,role:"user",text:c.text,done:!1,status:"pending"}]);let i=c;try{let u=Array.isArray(i.attachments)?i.attachments:[];if(u.length===0&&Array.isArray(i.uploads)&&i.uploads.length>0){let x=[];for(let k of i.uploads)x.push(await V("personal-assistant.file.upload",{sessionId:i.sessionId,name:k.name,dataUrl:k.dataUrl}));u=x.map(({path:k,name:fe,mediaType:F,bytes:me})=>({path:k,name:fe,mediaType:F,bytes:me})),i={...i,attachments:u,uploads:[]},G.current.set(i.clientTurnId,i)}let y=await V("personal-assistant.turn.submit",{sessionId:i.sessionId,text:i.text,clientTurnId:i.clientTurnId,attachments:u});return C.current?(G.current.delete(i.clientTurnId),v(x=>x.map(k=>k.clientTurnId===i.clientTurnId?{...k,status:"accepted",turnId:y.turnId}:k)),{ok:!0,item:i}):{ok:!0,item:i}}catch(u){return C.current?(te(oe(u)),h&&!oe(u)&&X(y=>y||i.text),v(y=>y.map(x=>x.clientTurnId===i.clientTurnId?{...x,status:"failed",failure:u.message||"\u53D1\u9001\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u91CD\u8BD5\u5C06\u590D\u7528\u539F\u6807\u8BC6"}:x)),{ok:!1,failure:u,item:i}):{ok:!1,failure:u,item:i}}finally{C.current&&L(!1)}},ye=(c,h)=>{let i=(c.attempts||0)+1;if(G.current.delete(c.clientTurnId),v(y=>y.filter(x=>x.clientTurnId!==c.clientTurnId)),i>Qt){q(`\u6392\u961F\u6D88\u606F\u591A\u6B21\u672A\u53D1\u51FA\uFF08${h?.message||"\u4E91\u7535\u8111\u4ECD\u5FD9"}\uFF09\uFF0C\u5DF2\u653E\u56DE\u8F93\u5165\u6846\uFF0C\u8BF7\u624B\u52A8\u91CD\u8BD5`),X(y=>y||c.text);return}be([{...c,attempts:i},...z.current]);let u=(yt*Math.min(i,3)/1e3).toFixed(1);q(`\u4E91\u7535\u8111\u4ECD\u5728\u5904\u7406\u4E0A\u4E00\u8F6E\uFF0C\u6D88\u606F\u5DF2\u6392\u961F\uFF0C\u7EA6 ${u} \u79D2\u540E\u81EA\u52A8\u91CD\u53D1`),Ce(),K.current=setTimeout(()=>{K.current=null,U(!0)},yt*Math.min(i,3))},U=async c=>{let h=j.current;if(ve.current||!C.current||de.current!=="ready"||!h||Se.current||!c&&P.current)return!1;let i=z.current[0];if(!i)return!1;if(i.sessionId!==h)return be([]),q("\u4F1A\u8BDD\u5DF2\u53D8\u5316\uFF0C\u6392\u961F\u6D88\u606F\u672A\u53D1\u9001"),!1;ve.current=!0,be(z.current.slice(1));try{let u=await Pe(i);return u.ok?!0:(oe(u.failure)?ye(u.item||i,u.failure):q(`\u6392\u961F\u6D88\u606F\u53D1\u9001\u5931\u8D25\uFF1A${u.failure?.message||"\u8BF7\u70B9\u51FB\u91CD\u8BD5"}`),!1)}finally{ve.current=!1}},pe=c=>{G.current.delete(c),be(z.current.filter(h=>h.clientTurnId!==c)),q("\u5DF2\u64A4\u56DE\u6392\u961F\u6D88\u606F")},De=async(c=null)=>{if(p!=="ready"||!T)return;if(c){W||Pe(c,{restoreDraft:!0});return}let h=ge.trim()||(Y.length?"\u8BF7\u67E5\u770B\u9644\u4EF6\u3002":"");if(!h)return;let i=Y.map(({name:y,mimeType:x,size:k,dataUrl:fe})=>({name:y,mimeType:x,size:k,dataUrl:fe}));if(W||M){be([...z.current,{clientTurnId:crypto.randomUUID(),text:h,sessionId:T,uploads:i,attempts:0,queuedAt:Date.now()}]),ue.current=!0,X(""),O([]),S(""),q("");return}X(""),O([]),S(""),q("");let u=await Pe({clientTurnId:crypto.randomUUID(),text:h,sessionId:T,uploads:i,attempts:0},{restoreDraft:!0});!u.ok&&oe(u.failure)&&ye(u.item,u.failure)};s(()=>{if(p!=="ready"||!T||W||M||ne.length===0)return;let c=setTimeout(()=>{U(!1)},Yt);return()=>clearTimeout(c)},[p,T,W,M,ne]),s(()=>{if(ne.length===0||typeof window>"u"||typeof window.addEventListener!="function")return;let c=h=>{h.preventDefault(),h.returnValue=""};return window.addEventListener("beforeunload",c),()=>window.removeEventListener("beforeunload",c)},[ne.length]);let ze=n("header",{style:I.header},n("h1",{style:I.title},"\u4E2A\u4EBA\u52A9\u7406"),n("span",{style:I.status},p==="ready"?"\u4E91\u7AEF\u5E38\u9A7B\uFF0C\u5173\u6389\u7A97\u53E3\u4E5F\u4F1A\u7EE7\u7EED":p==="loading"?"\u6B63\u5728\u8FDE\u63A5\u2026":"\u8FDE\u63A5\u4E0D\u53EF\u7528"),n("span",{style:I.spacer}),r?n("button",{type:"button",onClick:r,"aria-label":"\u6253\u5F00\u4E91\u7535\u8111\u4FA7\u680F",title:"\u6253\u5F00\u6216\u91CD\u65B0\u6253\u5F00\u4E91\u7535\u8111\u4FA7\u680F",style:{...I.ghost,display:"inline-flex",alignItems:"center",gap:6}},n("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,"aria-hidden":!0},n("rect",{x:3,y:4,width:18,height:13,rx:2}),n("path",{d:"M8 21h8M12 17v4"})),"\u4E91\u7535\u8111"):null);return n("section",{"data-personal-assistant-conversation":"true",style:I.page,onClick:async c=>{let h=c.target.closest?.('a[href^="cloud-file:"]');if(h){c.preventDefault();try{let i=await V("personal-assistant.file.download",{sessionId:T,path:decodeURIComponent(h.getAttribute("href").slice(11))}),u=Uint8Array.from(atob(i.data),k=>k.charCodeAt(0)),y=URL.createObjectURL(new Blob([u],{type:"application/octet-stream"})),x=document.createElement("a");x.href=y,x.download=i.name,x.click(),setTimeout(()=>URL.revokeObjectURL(y),1e3)}catch(i){S(i.message||"\u4E91\u7AEF\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25")}}}},ze,n("style",null,"@keyframes pa-awaiting { 0%, 100% { opacity: 0.35 } 50% { opacity: 1 } }"),D&&ee.length>0?n("div",{role:"alert",style:{padding:"8px 16px",background:"#fff0d6"}},D):null,n("div",{ref:Ie,"data-personal-assistant-messages":"true",style:I.scroller,onScroll:c=>{let h=c.currentTarget;ue.current=h.scrollHeight-h.clientHeight-h.scrollTop<64}},n("div",{style:I.thread},ee.length===0?n("div",{style:{...I.status,paddingTop:40,textAlign:"center"}},p==="error"?n("div",{style:{...I.centeredInner,margin:"0 auto"}},n("strong",null,"\u6682\u65F6\u8FDE\u4E0D\u4E0A\u4E2A\u4EBA\u52A9\u7406"),n("span",null,D||"\u8BF7\u7A0D\u540E\u91CD\u8BD5"),n("button",{style:I.ghost,onClick:()=>{ce()}},"\u91CD\u8BD5")):p==="loading"?"\u6B63\u5728\u8FDE\u63A5\u4E2A\u4EBA\u52A9\u7406\u2026":qt):null,ee.map(c=>{if(c.role==="step")return n("div",{key:c.id,style:I.step},`\xB7 ${c.text}`);let h=c.role==="user";return n("div",{key:c.id,style:h?I.rowUser:I.row},n("span",{style:I.who},h?"\u4F60":"\u52A9\u7406"),n("div",{style:h?I.bubbleUser:I.bubble},h?c.text||"\u2026":gt(n,c.text||"",I)||"\u2026"),c.status==="failed"?n("button",{onClick:()=>{De(G.current.get(c.clientTurnId))},disabled:W},`${c.failure} \xB7 \u91CD\u8BD5\u53D1\u9001`):null)}),M?n("div",{key:"awaiting",style:I.row},n("span",{style:I.who},"\u52A9\u7406"),n("div",{style:{...I.bubble,color:"var(--dsw-alias-label-secondary, #536174)"}},n("span",{style:I.pulse},Be||"\u6B63\u5728\u5904\u7406\u2026"))):null,ne.map(c=>n("div",{key:`queued-${c.clientTurnId}`,style:I.rowUser},n("span",{style:I.who},"\u4F60 \xB7 \u6392\u961F\u4E2D"),n("div",{style:I.queueBubble},`${c.text}${c.uploads?.length?`\uFF08${c.uploads.length} \u4E2A\u9644\u4EF6\u5F85\u53D1\uFF09`:""}`),n("div",{style:I.queueRow},n("span",{style:I.queueHint},c.attempts?"\u4E91\u7535\u8111\u4ECD\u5728\u5904\u7406\u4E0A\u4E00\u8F6E\uFF0C\u7A0D\u540E\u81EA\u52A8\u91CD\u53D1":"\u5DF2\u6392\u961F\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u53D1\u9001"),n("button",{type:"button","aria-label":`\u64A4\u56DE\u6392\u961F\u6D88\u606F\uFF1A${c.text.slice(0,24)}`,title:"\u64A4\u56DE\u8FD9\u6761\u6392\u961F\u6D88\u606F",style:I.queueCancel,onClick:()=>pe(c.clientTurnId)},ht(n),"\u64A4\u56DE")))))),n("div",{"data-personal-assistant-composer":"true",style:I.composer},we?n("div",{role:"status",style:I.queueNotice},we):null,n("div",{style:I.composerInner},Y.length>0?n("div",{style:I.attachRow},Y.map(c=>n("span",{key:c.id,style:I.attach},c.mimeType.startsWith("image/")?n("img",{src:c.dataUrl,alt:"",style:I.attachThumb}):null,n("span",{style:I.attachName},c.name),n("button",{"aria-label":`\u79FB\u9664 ${c.name}`,style:{...I.iconButton,width:16,height:16,border:"none"},onClick:()=>O(h=>h.filter(i=>i.id!==c.id))},ht(n))))):null,n("textarea",{"aria-label":"\u7ED9\u4E2A\u4EBA\u52A9\u7406\u53D1\u6D88\u606F",value:ge,rows:1,style:I.textarea,placeholder:p!=="ready"?"\u4E91\u7AEF\u6682\u672A\u8FDE\u63A5\uFF0C\u53EF\u5148\u5199\u4E0B\u6D88\u606F":W||M?"\u672C\u8F6E\u8FDB\u884C\u4E2D\uFF1A\u73B0\u5728\u53D1\u9001\u4F1A\u6392\u961F\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u51FA":"\u7ED9\u4E2A\u4EBA\u52A9\u7406\u53D1\u6D88\u606F\uFF0CEnter \u53D1\u9001\uFF0CShift+Enter \u6362\u884C",onChange:c=>X(c.target.value),onKeyDown:c=>{p==="ready"&&c.key==="Enter"&&!c.shiftKey&&!c.nativeEvent?.isComposing&&(c.preventDefault(),De())}}),n("div",{style:I.composerBar},n("button",{"aria-label":"\u6DFB\u52A0\u9644\u4EF6",style:I.iconButton,disabled:p!=="ready"||W,title:"\u4E0A\u4F20\u5230\u4E91\u7535\u8111\uFF1A\u6700\u591A 4 \u4E2A\u6587\u4EF6\uFF0C\u6BCF\u4E2A 512 KiB",onClick:()=>B.current?.click()},Gt(n)),n("input",{ref:B,type:"file",multiple:!0,accept:"image/*,.txt,.md,.json,.pdf",style:{display:"none"},onChange:Fe}),n("span",{style:I.spacer}),ne.length>0?n("span",{role:"status",style:I.queueBadge},`\u6392\u961F\u4E2D ${ne.length}`):null,n("button",{"aria-label":ne.length>0?`\u53D1\u9001\u6D88\u606F\uFF08\u6392\u961F\u4E2D ${ne.length} \u6761\uFF09`:"\u53D1\u9001\u6D88\u606F",title:W||M?"\u672C\u8F6E\u8FDB\u884C\u4E2D\uFF1A\u53D1\u9001\u540E\u4F1A\u6392\u961F\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u51FA":"\u53D1\u9001\u6D88\u606F",disabled:p!=="ready"||!ge.trim()&&Y.length===0,style:p!=="ready"||!ge.trim()&&Y.length===0?{...I.send,...I.sendDisabled}:W||M?I.sendQueued:I.send,onClick:()=>{De()}},Xt(n))))))}var xt="personal-assistant-computer",Zt="personal-assistant",wt="\u5F53\u524D Studio \u7684\u539F\u751F\u4FA7\u680F\u7EC4\u4EF6\u9700\u8981\u66F4\u65B0\uFF0C\u8BF7\u5B89\u88C5\u672C\u6B21\u968F\u63D2\u4EF6\u63D0\u4F9B\u7684\u5BBF\u4E3B\u7EC4\u4EF6\u5305\u3002",Jt=()=>Object.assign(new Error(wt),{code:"PERSONAL_ASSISTANT_NATIVE_SIDEBAR_REQUIRED"});function en(t){return t.workbench.render(t)}function vt({sidebarRight:t,slots:g,panelId:d=Zt}={}){let r=typeof t?.registerPanelSurface=="function"&&typeof t?.openPanelTab=="function"&&typeof t?.setPanelExpanded=="function"&&typeof g?.inject=="function"&&typeof g?.register=="function",n=new Set,a,s=!1,o=Object.freeze({binding:void 0}),f=()=>{o=Object.freeze({binding:a});for(let R of[...n])R()},p=()=>{if(!r)throw Jt();if(s)throw new Error("\u4E91\u7535\u8111\u5DE5\u4F5C\u9762\u677F\u5DF2\u5173\u95ED")},E,D,S={available:r,unavailableReason:r?null:wt,subscribe:R=>(n.add(R),()=>n.delete(R)),getSnapshot:()=>o,bind(R,N){if(p(),!R?.agentId||!R?.botId||typeof N!="function")throw new Error("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u8FDE\u63A5");a&&(a.scope.agentId!==R.agentId||a.scope.botId!==R.botId)&&(E(),E=t.registerPanelSurface(d)),a=Object.freeze({scope:Object.freeze({...R}),request:N}),f(),S.open()},open(){p(),a&&t.openPanelTab(d,xt)},collapse(){p(),t.setPanelExpanded(d,!1)},dispose(){s||(s=!0,D?.(),E?.(),n.clear())}};return r&&(E=t.registerPanelSurface(d),D=g.inject("sidebar.right.panel.tab",()=>g.register({name:"sidebar.right.panel.tab",key:xt,inject:()=>({workbench:S})},en))),S}function St({React:t,workbench:g,Panel:d,active:r=!0,fullscreen:n=!1}){let{createElement:a,useSyncExternalStore:s}=t,o=s(g.subscribe,g.getSnapshot,g.getSnapshot);if(!r||!o.binding)return null;let{scope:f,request:p}=o.binding;return a(d,{key:`${f.agentId}:${f.botId}:${f.sessionId||""}`,request:p,initialBotId:f.botId,initialSessionId:f.sessionId,agentId:f.agentId,variant:"native-tab",active:r,nativeFullscreen:n})}var tn="__directory__";function Ze(t){if(!Array.isArray(t)||t.length>128)throw new TypeError("\u52A9\u7406\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");let g=new Set;return t.map(d=>{let r=String(d?.botId||"").trim(),n=String(d?.displayName||r).trim();if(!r||r.length>64||/[\u0000-\u001f]/u.test(r)||r===tn||g.has(r)||!n||n.length>256)throw new TypeError("\u52A9\u7406\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");return g.add(r),{botId:r,displayName:r==="default"&&n==="Personal Assistant"?"\u9ED8\u8BA4\u52A9\u7406":r==="researcher"&&n==="Researcher"?"\u7814\u7A76\u52A9\u7406":n}})}function Je(t,g=""){let d=Ze(t),r=String(g||"").trim(),n=r?d.find(a=>a.botId===r):d.find(a=>a.botId==="default")||(d.length===1?d[0]:void 0);if(!n)throw Object.assign(new Error("\u4E91\u7AEF\u52A9\u7406\u7ED1\u5B9A\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"),{code:"PERSONAL_ASSISTANT_BINDING_UNAVAILABLE"});return n.botId}var tt=class extends Error{constructor(){super("Personal Assistant gateway is not connected"),this.name="PersonalAssistantGatewayUnavailableError",this.code="PERSONAL_ASSISTANT_GATEWAY_UNAVAILABLE"}};var At=Object.freeze(["slots","connection","sidebarRight"]),et="personal-assistant",xn=Object.freeze({enabled:!1,autoConnect:!1}),Ve="personal-assistant-computer",je="2026-10-28T07:36:38.478Z",It=12e3,Ne;function Rt(t){Ne=t}var H={background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #17202c)",border:"1px solid var(--dsw-alias-border-default, #d8dee8)"},Et=t=>typeof t?.message=="string"&&t.message&&!/^(fetch failed|Failed to fetch)$/u.test(t.message)?t.message.slice(0,180):"\u4E91\u7535\u8111\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",Tt=t=>t?.code==="PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE"&&Number(t?.status)===409?"\u5F53\u524D\u4E91\u7AEF\u7248\u672C\u5C1A\u4E0D\u652F\u6301\u52A9\u7406\u5217\u8868\uFF0C\u8BF7\u66F4\u65B0\u4E91\u7AEF\u52A9\u7406\u540E\u91CD\u8BD5":"\u8FDE\u63A5\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",nn=t=>Number(t?.status)===409&&["PERSONAL_ASSISTANT_DIRECTORY_UNSUPPORTED","PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE"].includes(t?.code),rn={Control:"Control_L",Meta:"Super_L",Alt:"Alt_L",Shift:"Shift_L",Enter:"Return",Escape:"Escape",Tab:"Tab",Backspace:"BackSpace",Delete:"Delete",ArrowUp:"Up",ArrowDown:"Down",ArrowLeft:"Left",ArrowRight:"Right"," ":"space"};function kt({request:t,initialBotId:g="",openInSidebar:d=null,variant:r="page",nativeFullscreen:n=!1}={}){let a=Ne||globalThis.React;if(!a)return"\u4E2A\u4EBA\u52A9\u7406\u9875\u9762\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00";let{createElement:s,useEffect:o,useRef:f,useState:p}=a,[E,D]=p(null),[S,R]=p([]),[N,T]=p(""),[$,ee]=p(null),[v,ge]=p(!1),[X,Y]=p(g),[O,B]=p("loading"),[W,L]=p(""),[M,te]=p(!0),[Be,_e]=p(0),[ne,xe]=p(0),[we,q]=p("observe"),[ie,G]=p(null),[z,ve]=p(""),[K,Se]=p(""),P=f(null),de=f(null),he=f(null),C=f(null),Ie=f(null),ue=f(null),j=f(null),V=f(n);V.current=n;let w=f({mounted:!0,socket:null,generation:0,frameEpoch:0,session:null,suspended:!1,resuming:!1,pendingInputs:[],display:{width:1280,height:800},readOnly:!0,botId:X,config:null,reconnect:null,firstFrame:null,receivedSeq:-1,pendingFrame:null,decoding:!1,frames:0,lastMove:0,pressed:new Set,buttons:new Set,composition:!1,retries:0,taskId:"",mode:"control",frameMetadata:null,reconnectAllowed:!1});w.current.botId=X;let re=async(e,l={})=>{if(typeof t!="function")throw new Error("Studio Host \u5C1A\u672A\u8FDE\u63A5");return t(e,l)},ce=e=>{let l=w.current;return l.socket?.readyState!==1?!1:(l.socket.send(JSON.stringify(e)),!0)},Fe=()=>{let e=w.current;for(let l of e.pressed)P.current?.input({type:"key",action:"up",key:l});for(let l of e.buttons)P.current?.input({type:"button",action:"up",button:l});e.pressed.clear(),e.buttons.clear()},be=()=>{for(let e of w.current.buttons)P.current?.input({type:"button",action:"up",button:e});w.current.buttons.clear()};P.current||(P.current=st({send:ce,changed:e=>{let l=w.current;l.controlPhase=e.phase,l.readOnly=e.readOnly,l.controlEpoch=e.controlEpoch,e.readOnly&&j.current&&(j.current.style.visibility="hidden"),e.phase==="observe"&&(l.pressed.clear(),l.buttons.clear()),l.mounted&&(te(e.readOnly),q(e.phase))},failed:e=>{w.current.mounted&&L(e)}})),de.current||(de.current=it({send:ce,controlEpoch:()=>P.current?.snapshot?.controlEpoch}));let Ce=()=>{Fe(),P.current.release(),w.current.pressed.clear(),w.current.buttons.clear()},oe=()=>{let e=w.current;e.pointerFrame&&cancelAnimationFrame(e.pointerFrame),e.pointerFrame=null;let l=e.lastPointer;e.lastPointer=null,l&&(!e.readOnly||e.controlPhase==="acquiring")&&(!e.sentPointer||l.x!==e.sentPointer.x||l.y!==e.sentPointer.y)&&(P.current.input({type:"pointermove",...l}),e.sentPointer=l)},Pe=()=>{clearTimeout(w.current.reconnect),clearTimeout(w.current.firstFrame),w.current.reconnect=null,w.current.firstFrame=null},ye=(e=!0)=>{let l=w.current;l.reconnectAllowed=!1,Pe(),Ce(),l.generation+=1,de.current?.rejectAll();try{ce({type:"close"}),l.socket?.close(1e3,"panel closed")}catch{}P.current.reset({readOnly:!0}),l.lastDrawnFrame=null,l.socket=null,l.session=null,l.pendingFrame=null,l.frameMetadata=null,l.readOnly=!0,Ie.current?.blur(),l.suspended=!1,l.resuming=!1,l.pendingInputs=[],l.frameEpoch++,e&&l.mounted&&(B(l.config?.configured?"idle":"unconfigured"),te(!0))},U=e=>{ye(!1),te(!0),B("closed"),L(e?.reason==="lease-lost"||Number(e?.status)===409?"\u63A7\u5236\u79DF\u7EA6\u5DF2\u5931\u6548\uFF0C\u684C\u9762\u8FDE\u63A5\u5DF2\u5173\u95ED\uFF1B\u8BF7\u91CD\u65B0\u8FDE\u63A5\u6216\u9009\u62E9\u53EA\u8BFB\u65C1\u89C2":e?.code==="DESKTOP_SESSION_NOT_FOUND"||Number(e?.status)===404?"\u684C\u9762\u4F1A\u8BDD\u5DF2\u7ED3\u675F\uFF08\u53EF\u80FD\u56E0\u7A7A\u95F2\u8D85\u65F6\uFF09\uFF0C\u8BF7\u91CD\u65B0\u8FDE\u63A5":"\u684C\u9762\u8FDE\u63A5\u5DF2\u7ED3\u675F\uFF0C\u53EF\u91CD\u65B0\u8FDE\u63A5\u4E91\u7535\u8111")},pe=e=>{let l=w.current;if(e.type!=="pointermove"&&oe(),l.suspended||l.resuming){if(e.type==="pointermove")return!1;let A=l.mode==="control";if(A){if(l.pendingInputs.length>=32)return ye(),L("\u6062\u590D\u671F\u95F4\u8F93\u5165\u8FC7\u5FEB\uFF0C\u8BF7\u91CD\u65B0\u8FDE\u63A5"),!1;l.pendingInputs.push(e)}return l.resuming||y(),A}return!l.session||l.socket?.readyState!==1?(L("\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u8F93\u5165\u672A\u53D1\u9001"),!1):P.current.input(e)},De=e=>{w.current.mounted&&(Se(e),he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{w.current.mounted&&Se("")},4e3))},ze=e=>{let l=!1;for(let A of e)l=pe(A)||l;return l},c=async()=>{let e=/Mac|iPhone|iPad/u.test(String(globalThis.navigator?.platform||""))?"Meta":"Control";if(!w.current.pressed.has("_copyShortcut")){w.current.pressed.add("_copyShortcut");try{ze([{type:"key",action:"down",key:e},{type:"key",action:"down",key:"c"},{type:"key",action:"up",key:"c"},{type:"key",action:"up",key:e}]),await new Promise(l=>setTimeout(l,150))}finally{w.current.pressed.delete("_copyShortcut")}}return ut({readCloud:()=>de.current.read(),notify:De})},h=()=>dt({readLocal:()=>Xe(),writeCloud:e=>de.current.write(e),sendKeys:ze,notify:De}),i=async()=>{let e=w.current;if(!e.decoding){e.decoding=!0;try{for(;e.pendingFrame;){let l=e.pendingFrame;e.pendingFrame=null;let A;try{if(A=await createImageBitmap(new Blob([l.bytes],{type:"image/jpeg"})),!e.mounted||e.suspended||l.frameEpoch!==e.frameEpoch||l.generation!==e.generation||l.seq<e.receivedSeq||!C.current)continue;e.lastDrawnFrame=l;let b=C.current,J=b.getBoundingClientRect(),le=Math.max(1,globalThis.devicePixelRatio||1);b.width=Math.max(1,Math.round(J.width*le)),b.height=Math.max(1,Math.round(J.height*le));let Q=b.getContext("2d"),se=e.display,Le=Math.min(b.width/se.width,b.height/se.height),ke=se.width*Le,_=se.height*Le;Q.clearRect(0,0,b.width,b.height),Q.drawImage(A,(b.width-ke)/2,(b.height-_)/2,ke,_);let Ae=e.firstFrame!==null;e.frames+=1,clearTimeout(e.firstFrame),e.firstFrame=null,e.retries=0,Ae&&L(""),B(e.readOnly?"readonly":"ready"),_e(0)}catch{e.mounted&&L("\u684C\u9762\u5E27\u65E0\u6CD5\u89E3\u7801\uFF0C\u8BF7\u91CD\u8BD5")}finally{A?.close()}}}finally{e.decoding=!1}}},u=e=>{let l=w.current;clearTimeout(l.firstFrame),l.firstFrame=null,l.suspended=!0,l.resuming=!1,l.readOnly=!0,l.pendingInputs=[],l.frameEpoch++,l.pendingFrame=null,l.frameMetadata=null,l.pressed.clear(),l.buttons.clear(),l.frames=0,xe(0),te(!0),B("dormant"),L(e?.leaseReleased===!1?"\u5DF2\u7A7A\u95F2\uFF0C\u753B\u9762\u5DF2\u6682\u505C\uFF1B\u63A7\u5236\u6743\u4ECD\u7531\u5916\u90E8\u4EFB\u52A1\u7BA1\u7406":"\u5DF2\u7A7A\u95F2\uFF0C\u63A7\u5236\u6743\u5DF2\u91CA\u653E\uFF1B\u64CD\u4F5C\u684C\u9762\u5373\u53EF\u6062\u590D")},y=()=>{let e=w.current;if(e.resuming||!e.suspended)return;if(e.socket?.readyState!==1){x(e.mode,!1,e.pendingInputs);return}e.resuming=!0,B("resuming"),L("\u6B63\u5728\u6062\u590D\u684C\u9762\u5E76\u68C0\u67E5\u63A7\u5236\u6743\uFF0C\u8BF7\u7A0D\u5019\u3002"),ce({type:"resume",mode:e.mode,activity:!0});let l=e.generation,A=e.socket;e.firstFrame=setTimeout(()=>{e.mounted&&e.generation===l&&e.firstFrame!==null&&A.close(4e3,"resume frame timeout")},It)},x=async(e="read",l=!1,A=[])=>{let b=w.current,J=String(b.botId||"").trim();if(!b.config?.configured){B("unconfigured");return}if(!J||!b.bots?.some(Q=>Q.botId===J)){L("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");return}ye(!1),b.pendingInputs=A,b.resuming=A.length>0;let le=++b.generation;b.reconnectAllowed=!0,l||(b.retries=0),b.mode=e,b.taskId||=`studio-desktop-${globalThis.crypto.randomUUID()}`,b.receivedSeq=-1,b.frameMetadata=null,B(l?"reconnecting":"connecting"),L("\u9996\u6B21\u6216\u4F11\u7720\u540E\u8FDE\u63A5\u53EF\u80FD\u9700\u8981\u6570\u79D2\uFF0C\u8BF7\u7A0D\u5019\u3002");try{let Q=await re("personal-assistant.desktop.ticket",{agentId:b.config.agentId,botId:J,mode:e==="observe"?"control":e});if(!b.mounted||le!==b.generation)return;let se=new WebSocket(Q.wsUrl,["agentkit.personal-assistant.desktop.v1",`agentkit.desktop.ticket.${Q.ticket}`]);se.binaryType="arraybuffer",b.socket=se;let Le=()=>b.mounted&&b.generation===le;se.onopen=()=>{if(!Le()){se.close();return}ce({type:"open",botId:J,taskId:b.taskId,mode:e,...Q.leaseId?{leaseId:Q.leaseId}:{}}),b.firstFrame=setTimeout(()=>{Le()&&(L("\u4E91\u7535\u8111\u54CD\u5E94\u8F83\u6162\uFF0C\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5"),se.close(4e3,"first frame timeout"))},It)},se.onmessage=ke=>{if(!Le())return;if(typeof ke.data!="string"){let Ae=b.frameMetadata;b.frameMetadata=null;let Ue=ke.data;if(!Ae||!Number.isSafeInteger(Ae.seq)||Ae.seq<=b.receivedSeq||!(Ue instanceof ArrayBuffer)||Ue.byteLength===0||Ue.byteLength>307200||b.suspended)return;b.receivedSeq=Ae.seq,b.pendingFrame={bytes:Ue,seq:Ae.seq,generation:le,frameEpoch:b.frameEpoch},i();return}let _;try{_=JSON.parse(ke.data)}catch{return}if(_.type==="ready"){b.suspended=!1,b.resuming=!1,b.receivedSeq=-1,b.session=_.sessionId,b.readOnly=!!_.readOnly,b.display=Qe(_.display),b.mode=e,P.current.reset(_);let Ae=b.pendingInputs;if(b.pendingInputs=[],b.readOnly)b.pressed.clear(),b.buttons.clear();else for(let Ue of Ae)P.current.input(Ue);te(b.readOnly),L("\u4E91\u7535\u8111\u5DF2\u8FDE\u63A5\uFF0C\u6B63\u5728\u51C6\u5907\u684C\u9762\u753B\u9762");return}if(_.type==="control"){P.current.accept(_),L("");return}if(_.type==="idle"){u(_);return}if(_.type==="frame"){_.unchanged||(b.frameMetadata=_);return}if(_.type==="clipboard.response"){de.current?.accept(_);return}if(_.type==="closed"){_.retryable!==!0&&U(_);return}if(_.type==="error"){if(Number.isSafeInteger(_.controlEpoch)&&_.controlEpoch<b.controlEpoch)return;if(L(_.message||_.code||"\u4E91\u7535\u8111\u8BF7\u6C42\u5931\u8D25"),b.handoffSupported&&_.recoverable===!0){P.current.reject(_);return}if(_.recoverable===!0&&Number(_.status)===409){_.code==="DESKTOP_SESSION_IDLE"?u():(b.pendingInputs=[],b.readOnly=!0,b.pressed.clear(),b.buttons.clear(),te(!0),B("readonly"));return}if(Number(_.status)===409&&e==="control"&&!b.session){x(w.current.handoffSupported?"observe":"read");return}[404,409].includes(Number(_.status))||_.code==="DESKTOP_SESSION_NOT_FOUND"?U(_):b.session||(B("error"),ye(!1))}},se.onerror=()=>{Le()&&L("\u684C\u9762\u901A\u9053\u6682\u65F6\u65AD\u5F00\uFF0C\u6B63\u5728\u91CD\u8FDE")},se.onclose=ke=>{if(!Le())return;if(b.suspended&&ke.code!==1e3){clearTimeout(b.firstFrame),b.firstFrame=null,b.socket=null,B("dormant");return}if(b.session=null,clearTimeout(b.firstFrame),b.firstFrame=null,!b.reconnectAllowed||ke.code===1e3){U();return}if(document.hidden){B("hidden");return}let _=++b.retries;if(_e(_),_>5){b.reconnectAllowed=!1,B("error"),L("\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7535\u8111\uFF0C\u8BF7\u68C0\u67E5\u5B9E\u4F8B\u72B6\u6001\u6216\u7F51\u7EDC\u540E\u91CD\u8BD5");return}B("reconnecting"),b.reconnect=setTimeout(()=>{x(e,!0,b.pendingInputs)},Math.min(8e3,1e3*2**(_-1)))}}catch(Q){b.mounted&&le===b.generation&&(B("error"),L(Tt(Q)))}},k=async e=>{if(e?.aborted)return null;try{let l=await re("personal-assistant.desktop.status");return l&&typeof l=="object"?l:null}catch(l){return l?.code==="PERSONAL_ASSISTANT_OPERATION_UNAVAILABLE"||l?.status===404?null:{configured:!1,reason:"unavailable",detail:Et(l),candidates:[]}}},fe=async e=>{if(!z){ve(e),L(e==="create"?"\u6B63\u5728\u521B\u5EFA\u4E2A\u4EBA\u52A9\u7406\uFF0C\u53EF\u80FD\u9700\u8981\u51E0\u5206\u949F\u2026":"\u6B63\u5728\u83B7\u53D6\u4E91\u7AEF\u8FDE\u63A5\u51ED\u8BC1\u2026");try{await re(`personal-assistant.desktop.${e}`),L(""),await F()}catch(l){L(Et(l)),G(await k().catch(()=>null))}finally{ve("")}}},F=async(e,l=!1)=>{ye(!1),B("loading"),L(""),T(""),ee(null);try{let A=await re("personal-assistant.configuration");if(e?.aborted||!w.current.mounted)return;if(w.current.config=A,D(A),!A.configured){let Q=await k(e);if(e?.aborted||!w.current.mounted)return;if(w.current.bots=[],R([]),Y(""),G(Q),B("unconfigured"),Q?.configured&&!l){await F(e,!0);return}return}G(null);let b=await re("personal-assistant.bots.list");if(e?.aborted||!w.current.mounted)return;if(b.directoryAvailable!==!0)throw Object.assign(new Error("directory unavailable"),{code:"PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE",status:409});let J=Ze(b.bots);w.current.bots=J,w.current.handoffSupported=b.features?.includes("desktop-handoff/v1")===!0,R(J);let le=J.length?Je(J,g||A.botId):"";w.current.botId=le,Y(le),B(J.length?"idle":"empty"),le&&["computer","native-tab"].includes(r)&&x(w.current.handoffSupported?"observe":"read")}catch(A){if(e?.aborted||!w.current.mounted)return;Number.isInteger(A?.closeCode)&&A.closeCode>=1e3&&A.closeCode<=4999&&ee(A.closeCode),w.current.bots=[],R([]),Y(""),B("directory-error"),T(nn(A)?"\u4E91\u7AEF\u52A9\u7406\u9700\u8981\u66F4\u65B0\uFF0C\u8BF7\u66F4\u65B0\u540E\u91CD\u65B0\u8FDE\u63A5\u3002":Tt(A))}};o(()=>{let e=w.current;e.mounted=!0;let l=new AbortController;F(l.signal);let A=setInterval(()=>{e.mounted&&xe(e.frames),e.frames=0},1e3),b=()=>{document.hidden?(Ce(),ce({type:"pause"})):e.socket?.readyState===1?ce({type:"resume"}):e.reconnectAllowed&&e.config?.configured&&e.session===null&&e.socket&&x(e.mode,!0)},J=typeof ResizeObserver=="function"?new ResizeObserver(()=>{e.lastDrawnFrame&&(e.pendingFrame=e.lastDrawnFrame,i())}):null;C.current&&J?.observe(C.current);let le=()=>Ce(),Q=se=>{ue.current?.contains(se.target)||Ce()};return document.addEventListener("visibilitychange",b),window.addEventListener("blur",le),document.addEventListener("pointerdown",Q,!0),()=>{e.mounted=!1,J?.disconnect(),e.pointerFrame&&cancelAnimationFrame(e.pointerFrame),l.abort(),ye(!1),clearInterval(A),document.removeEventListener("visibilitychange",b),window.removeEventListener("blur",le),document.removeEventListener("pointerdown",Q,!0)}},[t]);let me=e=>ot({clientX:e.clientX,clientY:e.clientY,rect:C.current.getBoundingClientRect(),display:w.current.display}),Me=e=>{e.preventDefault();let l=w.current,A=[1,2,3][e.button]||1;e.type==="pointerdown"?(Ie.current?.focus(),C.current?.setPointerCapture(e.pointerId),pe({type:"button",action:"down",button:A,...me(e)})&&l.buttons.add(A)):(pe({type:"button",action:"up",button:A,...me(e)}),l.buttons.delete(A),C.current?.hasPointerCapture(e.pointerId)&&C.current.releasePointerCapture(e.pointerId))},We=e=>{if(w.current.composition||e.isComposing||e.nativeEvent?.isComposing||e.key==="Process"||e.key==="Unidentified")return;if(lt(e)){e.preventDefault(),h();return}if(ct(e)){e.preventDefault(),e.type==="keydown"&&!e.repeat&&c();return}let l=e.ctrlKey||e.metaKey||e.altKey;if(e.key.length===1&&!l||e.key==="Escape"&&V.current)return;e.preventDefault();let A=rn[e.key]||e.key;/^[A-Za-z0-9_]+$/u.test(A)&&(e.type==="keydown"?!e.repeat&&pe({type:"key",action:"down",key:A})&&w.current.pressed.add(A):(pe({type:"key",action:"up",key:A}),w.current.pressed.delete(A)))},Ye={loading:"\u6B63\u5728\u68C0\u67E5\u52A9\u7406\u72B6\u6001",idle:"\u51C6\u5907\u8FDE\u63A5",dormant:"\u5DF2\u7A7A\u95F2",resuming:"\u6B63\u5728\u6062\u590D\u684C\u9762",unconfigured:"\u4E2A\u4EBA\u52A9\u7406\u5C1A\u672A\u5F00\u901A",empty:"\u6682\u65F6\u6CA1\u6709\u53EF\u7528\u52A9\u7406","directory-error":"\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u52A9\u7406\u5217\u8868",connecting:"\u6B63\u5728\u542F\u52A8\u4E91\u7535\u8111",readonly:"\u53EA\u8BFB\u65C1\u89C2",ready:"\u6B63\u5728\u63A7\u5236\u4E91\u7535\u8111",reconnecting:"\u6B63\u5728\u6062\u590D\u8FDE\u63A5",hidden:"\u753B\u9762\u5DF2\u6682\u505C",closed:"\u684C\u9762\u8FDE\u63A5\u5DF2\u7ED3\u675F",error:"\u8FDE\u63A5\u6682\u65F6\u4E0D\u53EF\u7528"}[O],Ee={...H,borderRadius:6,padding:"7px 12px",cursor:"pointer",font:"inherit"},Z=["ready","readonly","hidden","reconnecting","dormant","resuming"].includes(O),Oe=S.length>0,Te=ie?.reason||"",Ct=Array.isArray(ie?.candidates)?ie.candidates.length:0,Dt=Te==="needs-create"?"\u8FD8\u6CA1\u6709\u521B\u5EFA\u4E2A\u4EBA\u52A9\u7406":Te==="credential-unavailable"?"\u6B63\u5728\u6062\u590D\u4E2A\u4EBA\u52A9\u7406\u7684\u8FDE\u63A5\u51ED\u8BC1":Te==="unavailable"?"\u6682\u65F6\u65E0\u6CD5\u81EA\u52A8\u8FDE\u63A5\u4E2A\u4EBA\u52A9\u7406":"\u4E2A\u4EBA\u52A9\u7406\u5C1A\u672A\u5F00\u901A",Ot=Te==="needs-create"?"\u4E91\u8D26\u53F7\u4E0B\u8FD8\u6CA1\u6709\u4E2A\u4EBA\u52A9\u7406\u5B9E\u4F8B\uFF0C\u521B\u5EFA\u540E\u5373\u53EF\u5728\u8FD9\u91CC\u8FDE\u63A5\u4E13\u5C5E\u4E91\u7535\u8111\u3002":Te==="credential-unavailable"?"\u4E91\u7AEF\u6682\u65F6\u6CA1\u6709\u8FD4\u56DE\u8FDE\u63A5\u51ED\u8BC1\uFF0C\u53EF\u4EE5\u91CD\u65B0\u83B7\u53D6\u3002":Te==="unavailable"?ie?.detail||"\u8BF7\u68C0\u67E5\u4E91\u7AEF\u767B\u5F55\u72B6\u6001\u540E\u91CD\u8BD5\u3002":"\u5F00\u901A\u5B8C\u6210\u540E\uFF0C\u5373\u53EF\u5728\u8FD9\u91CC\u8FDE\u63A5\u4E13\u5C5E\u4E91\u7535\u8111\u3002",Lt=O==="unconfigured"?Dt:O==="empty"?"\u52A9\u7406\u6B63\u5728\u51C6\u5907\u4E2D":O==="directory-error"?"\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7AEF\u52A9\u7406":"\u6B63\u5728\u68C0\u67E5\u52A9\u7406\u72B6\u6001",Nt=O==="unconfigured"?Ot:O==="empty"?"\u4E91\u7AEF\u521D\u59CB\u5316\u5B8C\u6210\u540E\uFF0C\u53EF\u7528\u52A9\u7406\u4F1A\u663E\u793A\u5728\u8FD9\u91CC\u3002":O==="directory-error"?N:"\u8BF7\u7A0D\u5019",He=r==="computer"||r==="native-tab",nt=s("div",{ref:ue,"data-personal-assistant-desktop-card":He?"true":void 0,style:{position:"relative",background:"var(--dsw-alias-bg-layer-2, #f1f3f6)",...He?{width:"100%",aspectRatio:`${w.current.display.width} / ${w.current.display.height}`,flex:"none",minWidth:0,borderRadius:14,overflow:"hidden",boxShadow:"0 0 0 1px var(--dsw-alias-border-default, #d8dee8), 0 8px 28px #1018280d"}:{flex:1,minHeight:240}}},["dormant","resuming"].includes(O)?s("div",{role:"status",style:{position:"absolute",inset:0,zIndex:1,pointerEvents:"none",display:"grid",placeItems:"center",padding:16,textAlign:"center",background:"color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 82%, transparent)",color:"var(--dsw-alias-label-primary, #17202c)"}},O==="dormant"?"\u5DF2\u7A7A\u95F2\uFF0C\u64CD\u4F5C\u684C\u9762\u5373\u53EF\u6062\u590D":"\u6B63\u5728\u6062\u590D\u684C\u9762\u2026"):null,s("canvas",{ref:C,"aria-label":"\u4E91\u7535\u8111\u684C\u9762",tabIndex:Z?0:-1,onPointerDown:Me,onPointerUp:Me,onPointerCancel:be,onLostPointerCapture:be,onPointerLeave:()=>{j.current&&(j.current.style.visibility="hidden")},onPointerMove:e=>{let l=w.current,A=e.nativeEvent?.getCoalescedEvents?.().at(-1)||e;if(j.current){let b=C.current.getBoundingClientRect();j.current.style.transform=`translate(${A.clientX-b.left}px, ${A.clientY-b.top}px)`,j.current.style.visibility=l.readOnly?"hidden":"visible"}l.lastPointer=me(A),l.pointerFrame||(l.pointerFrame=requestAnimationFrame(()=>{l.mounted&&oe()}))},onContextMenu:e=>e.preventDefault(),onWheel:e=>{e.preventDefault(),pe({type:"wheel",deltaY:e.deltaY/100,deltaX:e.deltaX/100})},onKeyDown:We,onKeyUp:We,style:{...He?{position:"absolute",inset:0}:{},width:"100%",height:"100%",display:"block",visibility:Z?"visible":"hidden",pointerEvents:Z?"auto":"none",touchAction:"none",cursor:M?"default":"none"}}),s("div",{ref:j,"aria-hidden":!0,style:{position:"absolute",top:0,left:0,pointerEvents:"none",visibility:"hidden",zIndex:2,width:18,height:22}},s("svg",{viewBox:"0 0 18 22",width:18,height:22},s("path",{d:"M1 1v16l4-4 3 7 3-1-3-7h6z",fill:"#fff",stroke:"#162033",strokeWidth:1.2}))),Z?null:s("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,padding:16,textAlign:"center"}},s("h2",{style:{margin:0,fontSize:18,fontWeight:500}},Oe?Ye:Lt),s("p",{style:{margin:0,maxWidth:380,lineHeight:1.7,color:"var(--dsw-alias-label-secondary, #536174)"}},Oe?W||"\u8FDE\u63A5\u540E\u5373\u53EF\u4F7F\u7528\u4E91\u7AEF\u684C\u9762\uFF0C\u5173\u95ED\u9762\u677F\u4F1A\u91CA\u653E\u672C\u6B21\u63A7\u5236\u3002":Nt),!Oe&&O!=="loading"?s("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",alignItems:"center"}},O==="unconfigured"&&Te==="needs-create"?s("button",{style:Ee,disabled:!!z,onClick:()=>{fe("create")}},z==="create"?"\u6B63\u5728\u521B\u5EFA\u2026":"\u521B\u5EFA\u4E2A\u4EBA\u52A9\u7406"):null,O==="unconfigured"&&(Te==="credential-unavailable"||Ct>0)?s("button",{style:Ee,disabled:!!z,onClick:()=>{fe("connect")}},z==="connect"?"\u6B63\u5728\u83B7\u53D6\u2026":Te==="credential-unavailable"?"\u91CD\u65B0\u83B7\u53D6\u8FDE\u63A5\u51ED\u8BC1":"\u8FDE\u63A5\u5DF2\u53D1\u73B0\u7684\u4E2A\u4EBA\u52A9\u7406"):null,s("button",{style:{...Ee,background:"transparent"},disabled:!!z,onClick:()=>{F()}},"\u68C0\u67E5\u5F00\u901A\u72B6\u6001"),z?s("span",{role:"status",style:{color:"var(--dsw-alias-label-secondary, #536174)",fontSize:12}},"\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019\u2026"):null):null),s("input",{ref:Ie,"aria-label":"\u4E91\u7535\u8111\u6587\u672C\u8F93\u5165",autoComplete:"off",disabled:!Z||M&&!P.current.snapshot.available&&!(w.current.mode==="control"&&["dormant","resuming"].includes(O)),tabIndex:-1,style:{position:"absolute",width:1,height:1,opacity:0,left:0,top:0},onKeyDown:We,onKeyUp:We,onCompositionStart:()=>{w.current.composition=!0},onCompositionEnd:e=>{w.current.composition=!1;let l=e.currentTarget.value;e.currentTarget.value="",l&&pe({type:"text",text:l})},onInput:e=>{if(w.current.composition||e.nativeEvent?.isComposing)return;let l=e.currentTarget.value;e.currentTarget.value="",l&&pe({type:"text",text:l})}})),$e="var(--dsw-alias-label-secondary, #536174)",dn={...Ee,background:"transparent",color:"inherit",border:H.border},rt={...Ee,borderRadius:999,padding:"7px 16px",border:"none",fontWeight:500,background:"var(--dsw-alias-label-primary, #17202c)",color:"var(--dsw-alias-bg-layer-1, #fff)"};return He?s("section",{"data-personal-assistant-computer":"true",style:{...H,border:"none",height:"100%",minHeight:0,minWidth:0,display:"flex",flexDirection:"column",background:"var(--dsw-alias-bg-base, #fff)",color:"inherit",fontSize:13}},r!=="native-tab"?s("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:H.border}},s("strong",{style:{fontWeight:500}},"\u4E91\u7535\u8111"),s("span",{role:"status","aria-live":"polite",style:{color:$e,fontSize:12}},Ye),null):null,M&&Z&&!P.current.snapshot.available?s("div",{role:"alert",style:{background:"#fff0d6",color:"#763c00",padding:"8px 12px"}},"\u53EA\u8BFB\u65C1\u89C2\uFF1A\u9F20\u6807\u548C\u952E\u76D8\u4E0D\u4F1A\u53D1\u9001\u5230\u4E91\u7535\u8111"):null,s("div",{"data-personal-assistant-desktop-layout":"true",style:{flex:1,minHeight:0,minWidth:0,overflow:"auto",display:"flex",flexDirection:"column",alignItems:"center",gap:12,padding:"20px 16px 12px",boxSizing:"border-box"}},s("div",{"data-personal-assistant-desktop-stack":"true",style:{width:"100%",maxWidth:1280,margin:"auto 0",display:"flex",flexDirection:"column",alignItems:"center",gap:12,flex:"none"}},nt,Z||Oe?s("div",{"data-personal-assistant-control-capsule":"true",role:"status","aria-live":"polite",style:{display:"flex",flexWrap:"wrap",justifyContent:"center",alignItems:"center",gap:6,width:"fit-content",maxWidth:"100%",boxSizing:"border-box",padding:"7px 12px",borderRadius:999,background:"var(--dsw-alias-bg-layer-1, #fff)",border:H.border,boxShadow:"0 1px 4px #10182808",lineHeight:1.5}},!Z&&Oe?s("button",{style:rt,disabled:["connecting","resuming"].includes(O),onClick:()=>{x(w.current.handoffSupported?"observe":"read")}},O==="connecting"?"\u6B63\u5728\u542F\u52A8\u2026":"\u91CD\u65B0\u8FDE\u63A5"):null,Z&&M?s("span",{style:{color:$e,fontSize:12}},we==="acquiring"?"\u6B63\u5728\u63A5\u7BA1\u2026":we==="releasing"?"\u6B63\u5728\u4EA4\u8FD8\u2026":"\u52A9\u7406\u6B63\u5728\u4F7F\u7528 \xB7 \u70B9\u753B\u9762\u5373\u53EF\u63A5\u7BA1"):null,Z&&M&&P.current.snapshot.available?s("button",{style:{...rt,padding:"3px 9px",fontSize:11},onClick:()=>P.current.acquire()},"\u63A5\u7BA1"):null,Z&&!M?s("span",{style:{color:$e,fontSize:12}},"\u60A8\u62E5\u6709\u63A7\u5236\u6743 \xB7 \u70B9\u753B\u9762\u5916\u91CA\u653E"):null,Z&&W?s("span",{style:{color:$e,fontSize:12}},W):null,Z&&K?s("span",{role:"status","aria-live":"polite",style:{color:$e,fontSize:12}},K):null):null),s("details",{style:{alignSelf:"flex-end",color:"var(--dsw-alias-label-tertiary, #76808e)",fontSize:11,opacity:.8,maxWidth:"100%",overflowWrap:"anywhere"}},s("summary",{style:{cursor:"pointer"}},"\u8BCA\u65AD"),s("small",{"data-personal-assistant-build":je},`\u6784\u5EFA ${je}`)))):s("section",{"data-personal-assistant-panel":"true",style:{...H,border:"none",height:"100%",minHeight:0,display:"flex",flexDirection:"column",fontSize:13}},s("header",{style:{display:"flex",flexWrap:"wrap",gap:8,alignItems:"center",padding:12,borderBottom:H.border}},s("strong",{style:{fontWeight:500,marginRight:8}},"\u4E2A\u4EBA\u52A9\u7406"),Oe&&["idle","closed","error"].includes(O)?s("button",{style:Ee,onClick:()=>{F()}},"\u5237\u65B0\u52A9\u7406\u5217\u8868"):null,typeof d=="function"?s("button",{style:Ee,onClick:d},"\u653E\u5230\u53F3\u4FA7\u680F"):null,Oe?s("button",{style:Ee,disabled:["connecting","resuming"].includes(O),onClick:()=>O==="dormant"?y():void x(w.current.handoffSupported?"observe":"control")},O==="dormant"?"\u6062\u590D\u753B\u9762":M&&O==="readonly"?"\u7533\u8BF7\u63A7\u5236":Z?"\u91CD\u65B0\u8FDE\u63A5":"\u8FDE\u63A5\u4E91\u7535\u8111"):null,Oe?s("button",{style:Ee,disabled:O==="connecting",onClick:()=>{x("read")}},"\u53EA\u8BFB\u65C1\u89C2"):null,Z?s("span",{role:"status","aria-live":"polite",style:{marginLeft:"auto",color:"var(--dsw-alias-label-secondary, #536174)"}},Ye):null),O==="readonly"?s("div",{role:"alert",style:{background:"#fff0d6",color:"#763c00",padding:"8px 12px"}},"\u5F53\u524D\u4E3A\u53EA\u8BFB\u65C1\u89C2\uFF0C\u9F20\u6807\u548C\u952E\u76D8\u8F93\u5165\u4E0D\u4F1A\u53D1\u9001\uFF1B\u53EF\u7533\u8BF7\u63A7\u5236"):null,Z&&W?s("div",{role:"status",style:{padding:"8px 12px"}},W):null,nt,s("footer",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:12,padding:"7px 12px",color:"var(--dsw-alias-label-secondary, #536174)",borderTop:H.border}},s("details",{open:v,onToggle:e=>ge(e.currentTarget.open)},s("summary",{style:{cursor:"pointer"}},"\u8BCA\u65AD"),$?s("div",{style:{paddingTop:8}},`\u76EE\u5F55\u8FDE\u63A5\u5173\u95ED\u7801\uFF1A${$}`):null,s("div",{style:{paddingTop:8,lineHeight:1.8,overflowWrap:"anywhere"}},s("div",null,`\u4E91\u7AEF\u5B9E\u4F8B\uFF1A${E?.agentId||"\u672A\u5F00\u901A"}`),s("div",null,`\u8FDE\u63A5\u6807\u8BC6\uFF1A${X||"\u672A\u8FDE\u63A5"}`),s("div",null,`\u753B\u9762\u5E27\u7387\uFF1A${ne} fps`),s("div",null,"\u5FEB\u6377\u952E\u4F1A\u8F6C\u53D1\u5230\u4E91\u7535\u8111\uFF1BEsc \u4F18\u5148\u9000\u51FA\u5168\u5C4F"))),s("small",{"data-personal-assistant-build":je,style:{opacity:.75}},`\u6784\u5EFA ${je}`)))}function on({request:t,nativeWorkbench:g}={}){let d=Ne||globalThis.React;if(!d)return"\u4E2A\u4EBA\u52A9\u7406\u9875\u9762\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00";let{createElement:r,useEffect:n,useState:a,useCallback:s}=d,[o,f]=a(null),[p,E]=a(""),[D,S]=a(0);n(()=>{let N=!1;return f(null),E(""),(async()=>{try{let T=await t("personal-assistant.configuration");if(!T.configured)throw new Error("\u4E2A\u4EBA\u52A9\u7406\u5C1A\u672A\u5F00\u901A\uFF0C\u8BF7\u5148\u5728\u8BBE\u7F6E\u4E2D\u8FDE\u63A5\u4E91\u7AEF\u5B9E\u4F8B");let $=await t("personal-assistant.bots.list");if($.directoryAvailable!==!0)throw new Error("\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7AEF\u52A9\u7406\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");let ee=Je($.bots,T.botId||$.primaryBotId);N||f({agentId:T.agentId,botId:ee})}catch(T){N||E(T.message||"\u4E91\u7AEF\u52A9\u7406\u6682\u4E0D\u53EF\u7528")}})(),()=>{N=!0}},[t,D]);let R=s((N,T={})=>{if(!o)throw new Error("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u8FDE\u63A5");if(T.agentId&&T.agentId!==o.agentId)throw new Error("\u4E91\u7AEF\u5B9E\u4F8B\u4E0D\u4E00\u81F4");if(N!=="personal-assistant.bots.list"&&T.botId&&T.botId!==o.botId)throw new Error("\u4E91\u7AEF\u52A9\u7406\u4E0D\u4E00\u81F4");return t(N,{...T,...o})},[t,o?.agentId,o?.botId]);return n(()=>{o&&g?.available?g.bind(o,R):o&&E(g?.unavailableReason||"\u5F53\u524D\u5BBF\u4E3B\u9700\u8981\u66F4\u65B0\u539F\u751F\u4FA7\u680F\u7EC4\u4EF6")},[g,R,o?.agentId,o?.botId]),o?g?.available?r("div",{key:`${o.agentId}:${o.botId}`,"data-personal-assistant-home":"true","data-agent-id":o.agentId,"data-bot-id":o.botId,style:{flex:"1 1 0px",height:"100%",maxHeight:"100%",minHeight:0,minWidth:0,overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column"}},r(mt,{React:d,request:R,scope:o,onOpenComputer:()=>g.open()})):r("div",{role:"alert",style:{padding:24}},"\u5F53\u524D\u5BBF\u4E3B\u5C1A\u672A\u63D0\u4F9B\u539F\u751F\u4E91\u7535\u8111\u4FA7\u680F\uFF0C\u8BF7\u66F4\u65B0 Studio \u540E\u91CD\u65B0\u6253\u5F00\u3002"):r("div",{role:"status",style:{padding:24}},p||"\u6B63\u5728\u8FDE\u63A5\u4E91\u7AEF\u4E2A\u4EBA\u52A9\u7406\u2026",p?r("button",{onClick:()=>S(N=>N+1)},"\u91CD\u65B0\u8FDE\u63A5"):null)}var m={page:{padding:"2px 2px 28px",display:"flex",flexDirection:"column",gap:18,maxWidth:700,fontSize:13,color:"var(--dsw-alias-label-primary, #17202c)"},title:{margin:0,fontSize:18,fontWeight:600,letterSpacing:"-0.01em"},lede:{margin:0,color:"var(--dsw-alias-label-secondary, #536174)",fontSize:13,lineHeight:1.7},card:{border:H.border,borderRadius:12,overflow:"hidden"},row:{display:"flex",gap:16,padding:"12px 14px",borderTop:"1px solid var(--dsw-alias-border-default, #d8dee8)",alignItems:"flex-start"},rowFirst:{display:"flex",gap:16,padding:"12px 14px",alignItems:"flex-start"},label:{width:116,flex:"none",color:"var(--dsw-alias-label-secondary, #536174)",fontSize:13,lineHeight:1.7},value:{flex:1,minWidth:0,fontSize:13,lineHeight:1.7,overflowWrap:"anywhere"},mono:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12},actions:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},button:{...H,borderRadius:8,padding:"6px 11px",cursor:"pointer",font:"inherit",fontSize:13},note:{color:"var(--dsw-alias-label-secondary, #536174)",fontSize:12,lineHeight:1.7},badge:{display:"inline-block",borderRadius:999,padding:"1px 8px",fontSize:12,lineHeight:1.7},badgeOk:{background:"color-mix(in srgb, #067647 12%, transparent)",color:"#067647"},badgeIdle:{background:"color-mix(in srgb, #946200 14%, transparent)",color:"#946200"},badgeError:{background:"color-mix(in srgb, #b42318 12%, transparent)",color:"#b42318"},dangerButton:{...H,borderRadius:8,padding:"6px 11px",cursor:"pointer",font:"inherit",fontSize:13,color:"#b42318",border:"1px solid color-mix(in srgb, #b42318 35%, transparent)",background:"transparent"},confirmBox:{border:"1px solid color-mix(in srgb, #b42318 30%, transparent)",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",gap:10,background:"color-mix(in srgb, #b42318 4%, transparent)"},dangerInput:{...H,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:8,padding:"6px 9px",font:"inherit",fontSize:12,width:"100%",maxWidth:360,boxSizing:"border-box"},danger:{...H,borderRadius:8,padding:"6px 11px",cursor:"pointer",font:"inherit",fontSize:13,color:"#fff",border:"1px solid #b42318",background:"#b42318"},dangerDisabled:{...H,borderRadius:8,padding:"6px 11px",cursor:"not-allowed",font:"inherit",fontSize:13,color:"#fff",border:"1px solid color-mix(in srgb, #b42318 35%, transparent)",background:"color-mix(in srgb, #b42318 35%, transparent)"},success:{color:"#067647",fontSize:12,lineHeight:1.7},input:{...H,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:8,padding:"6px 9px",font:"inherit",fontSize:12,width:"100%",maxWidth:360,boxSizing:"border-box"},textarea:{...H,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:8,padding:"6px 9px",font:"inherit",fontSize:12,width:"100%",minHeight:76,resize:"vertical",boxSizing:"border-box"},envRow:{display:"flex",gap:6,alignItems:"center",marginBottom:6,flexWrap:"wrap"},envKey:{...H,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:8,padding:"5px 8px",font:"inherit",fontSize:12,width:190,boxSizing:"border-box"},envValue:{...H,border:"1px solid var(--dsw-alias-border-default, #d8dee8)",borderRadius:8,padding:"5px 8px",font:"inherit",fontSize:12,width:220,boxSizing:"border-box"},tinyButton:{...H,borderRadius:8,padding:"4px 8px",cursor:"pointer",font:"inherit",fontSize:12}};function sn({request:t,openComputer:g=null}={}){let d=Ne||globalThis.React;if(!d)return"\u8BBE\u7F6E\u9875\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00 Studio";let{createElement:r,useEffect:n,useState:a,useCallback:s}=d,[o,f]=a(null),[p,E]=a(null),[D,S]=a(""),[R,N]=a(!1),[T,$]=a(""),[ee,v]=a(!1),[ge,X]=a(""),[Y,O]=a(!1),[B,W]=a(""),[L,M]=a(null),[te,Be]=a(null),[_e,ne]=a(""),[xe,we]=a(""),[q,ie]=a(""),[G,z]=a([]),[ve,K]=a([]),[Se,P]=a(""),[de,he]=a(""),[C,Ie]=a(!1),ue=s(async()=>{N(!0),S("");let h=Date.now();try{let i=await t("personal-assistant.configuration");if(f(i),i?.configured){let u=await t("personal-assistant.bots.list");E(Array.isArray(u?.bots)?u.bots:[]);try{let y=await t("personal-assistant.settings.inspect");M(y),ne(y?.model||""),we(y?.prompt||""),ie(y?.runtime?.version||""),z((y?.environmentVariables||[]).map(k=>({...k,saved:!0,dirty:!1}))),K([]),P("");let x=await t("personal-assistant.settings.versions",{currentVersion:y?.runtime?.version||""}).catch(k=>(P(k?.message||"\u6682\u65F6\u8BFB\u4E0D\u5230\u53EF\u5347\u7EA7\u7684\u7248\u672C"),null));Be(x)}catch(y){M(null),Be(null),P(y?.message||"\u8BFB\u53D6\u4E91\u7AEF\u914D\u7F6E\u5931\u8D25")}}else E([]),M(null),Be(null);$(`${new Date().toLocaleTimeString("zh-CN",{hour12:!1})} \xB7 ${Date.now()-h} ms`)}catch(i){S(i?.message||"\u8FDE\u63A5\u68C0\u67E5\u5931\u8D25"),$(`${new Date().toLocaleTimeString("zh-CN",{hour12:!1})} \xB7 \u5931\u8D25`)}finally{N(!1)}},[t]),j=o?.agentId||"",V=!!j&&ge.trim()===j,w=s(async()=>{if(V){O(!0),S("");try{await t("personal-assistant.desktop.destroy",{confirmAgentId:j}),v(!1),X(""),W("\u4E2A\u4EBA\u52A9\u7406\u5DF2\u5173\u95ED\uFF1A\u4E91\u7AEF\u5B9E\u4F8B\u5DF2\u5220\u9664\uFF0C\u5173\u8054\u7684\u4E91\u8D44\u6E90\u8BA2\u5355\u6B63\u5728\u91CA\u653E\uFF0C\u672C\u673A\u7ED1\u5B9A\u5DF2\u6E05\u9664\u3002"),f({configured:!1}),E([]),$("")}catch(h){let i=String(h?.message||"");S(/更新 Studio|云连接服务/iu.test(i)?"\u5F53\u524D Studio \u7248\u672C\u8FD8\u4E0D\u652F\u6301\u5173\u95ED\u4E2A\u4EBA\u52A9\u7406\uFF0C\u8BF7\u66F4\u65B0 Studio \u540E\u91CD\u8BD5\u3002":i||"\u5173\u95ED\u4E2A\u4EBA\u52A9\u7406\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5")}finally{O(!1)}}},[j,V,t]),re=(h,i)=>z(u=>u.map((y,x)=>x===h?{...y,...i,dirty:!0}:y)),ce=()=>z(h=>[...h,{key:"",value:"",sensitive:!1,saved:!1,dirty:!0}]),Fe=h=>{let i=G[h];i&&(z(u=>u.filter((y,x)=>x!==h)),i.saved&&i.key&&K(u=>u.includes(i.key)?u:[...u,i.key]))},be=L?.recordSource==="studio",Ce=s(async()=>{if(!(!be||C)){Ie(!0),P(""),he("");try{let h=G.filter(i=>i.dirty===!0||i.saved!==!0).map(i=>({key:String(i.key||"").trim(),value:String(i.value||""),sensitive:i.sensitive===!0}));await t("personal-assistant.settings.update",{model:_e.trim(),prompt:xe,runtimeVersion:q,environmentVariables:h,deleteKeys:ve}),he(`\u5DF2\u63D0\u4EA4\u4E91\u7AEF\u66F4\u65B0\uFF08\u7248\u672C ${q}\uFF09\uFF0C\u4E2A\u4EBA\u52A9\u7406\u6B63\u5728\u5E94\u7528\u65B0\u914D\u7F6E\uFF0C\u901A\u5E38 1\u20132 \u5206\u949F\u5B8C\u6210\uFF0C\u671F\u95F4\u4E91\u7535\u8111\u4F1A\u77ED\u6682\u91CD\u8FDE\u3002`),K([]);try{let i=await t("personal-assistant.settings.inspect");M(i),ne(i?.model||""),we(i?.prompt||""),ie(i?.runtime?.version||q),z((i?.environmentVariables||[]).map(u=>({...u,saved:!0,dirty:!1})))}catch{}}catch(h){P(h?.message||"\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5")}finally{Ie(!1)}}},[be,ve,G,_e,xe,t,C,q]);n(()=>{ue()},[ue]);let oe=o?.configured===!0,Pe=o===null?"\u68C0\u67E5\u4E2D":oe?"\u5DF2\u5F00\u901A":"\u5C1A\u672A\u5F00\u901A",ye={...m.badge,...o===null?m.badgeIdle:oe?m.badgeOk:m.badgeIdle},U=(h,i,u=!1)=>r("div",{style:u?m.rowFirst:m.row},r("div",{style:m.label},h),r("div",{style:m.value},i)),pe={...m.note,display:"inline-flex",gap:4,alignItems:"center"},De={...m.actions,marginTop:6},ze={display:"flex",flexDirection:"column",gap:8},c=()=>{if(!L)return r("div",{style:m.card},U("\u4E91\u7AEF\u914D\u7F6E",r("div",{style:m.note},C?"\u8BFB\u53D6\u4E2D\u2026":Se||"\u6682\u65F6\u8BFB\u4E0D\u5230\u4E91\u7AEF\u914D\u7F6E\uFF1B\u8BF7\u70B9\u4E0B\u65B9\u201C\u68C0\u67E5\u8FDE\u63A5\u201D\u91CD\u8BD5"),!0));if(L.recordSource!=="studio")return r("div",{style:m.card},U("\u4E91\u7AEF\u914D\u7F6E",r("div",{style:m.note},"\u8FD9\u4E2A\u4E2A\u4EBA\u52A9\u7406\u662F\u7528\u65E7\u7248 Studio \u521B\u5EFA\u7684\uFF0C\u672C\u673A\u6CA1\u6709\u8BB0\u5F55\u5B83\u7684\u914D\u7F6E\u6E05\u5355\uFF0C\u6682\u65F6\u4E0D\u80FD\u5728\u7EBF\u4FEE\u6539\u3002\u53EF\u4EE5\u5173\u95ED\u540E\u91CD\u65B0\u521B\u5EFA\uFF1B\u7B49\u4E91\u7AEF\u5E73\u53F0\u63D0\u4F9B\u8BFB\u53D6\u63A5\u53E3\u540E\u5373\u53EF\u76F4\u63A5\u7F16\u8F91\u3002"),!0));let h=te&&te.catalogAvailable?r("select",{style:m.input,value:q,disabled:C,"aria-label":"\u8FD0\u884C\u65F6\u7248\u672C",onChange:y=>ie(String(y?.target?.value??""))},te.versions.map(y=>r("option",{key:y.version,value:y.version},y.version===L.runtime?.version?`${y.version}\uFF08\u5F53\u524D\uFF09`:y.version))):r("div",{style:m.note},`${L.runtime?.version||q||"\u672A\u77E5\u7248\u672C"} \xB7 \u4E91\u7AEF\u8FD8\u6CA1\u6709\u53D1\u5E03\u53EF\u5347\u7EA7\u7248\u672C`),i=r("div",null,G.length?G.map((y,x)=>r("div",{key:`env-${x}`,style:m.envRow},r("input",{style:m.envKey,value:y.key,placeholder:"KEY","aria-label":"\u73AF\u5883\u53D8\u91CF\u540D",disabled:C||y.saved===!0,onChange:k=>re(x,{key:String(k?.target?.value??"")})}),r("input",{style:m.envValue,value:y.value,"aria-label":"\u73AF\u5883\u53D8\u91CF\u503C",type:y.sensitive===!0?"password":"text",disabled:C,placeholder:y.saved===!0&&y.sensitive===!0?"\u5DF2\u4FDD\u5B58\uFF08\u7559\u7A7A\u4E0D\u4FEE\u6539\uFF09":"VALUE",onChange:k=>re(x,{value:String(k?.target?.value??"")})}),r("label",{style:pe},r("input",{type:"checkbox",checked:y.sensitive===!0,disabled:C,onChange:k=>re(x,{sensitive:k?.target?.checked===!0})}),"\u654F\u611F"),r("button",{style:m.tinyButton,disabled:C,onClick:()=>Fe(x)},"\u5220\u9664"))):r("div",{style:m.note},"\u8FD8\u6CA1\u6709\u914D\u7F6E\u73AF\u5883\u53D8\u91CF"),r("div",{style:De},r("button",{style:m.tinyButton,disabled:C,onClick:ce},"\u6DFB\u52A0\u53D8\u91CF"),r("span",{style:m.note},"\u5DF2\u4FDD\u5B58\u7684\u654F\u611F\u503C\u4E0D\u4F1A\u56DE\u663E\uFF0C\u7559\u7A7A\u8868\u793A\u4E0D\u4FEE\u6539\uFF1B\u5220\u9664\u540E\u4FDD\u5B58\u751F\u6548"))),u=r("div",{style:ze},de?r("div",{style:m.success},de):null,Se?r("div",{style:{...m.note,color:"#b42318"}},Se):null,r("div",{style:m.actions},r("button",{style:m.button,disabled:C,onClick:()=>{Ce()}},C?"\u6B63\u5728\u4FDD\u5B58\u2026":"\u4FDD\u5B58\u914D\u7F6E"),r("span",{style:m.note},"\u4FDD\u5B58\u4F1A\u63D0\u4EA4\u4E00\u6B21\u4E91\u7AEF\u66F4\u65B0\uFF0C\u7531\u4E91\u7AEF\u6EDA\u52A8\u5E94\u7528")));return r("div",{style:m.card},U("\u4E91\u7AEF\u914D\u7F6E",r("div",{style:m.note},"\u6A21\u578B\u3001\u7CFB\u7EDF\u63D0\u793A\u8BCD\u3001\u8FD0\u884C\u65F6\u7248\u672C\u548C\u73AF\u5883\u53D8\u91CF\u4FDD\u5B58\u5728\u4E91\u7AEF\u5B9E\u4F8B\u3002\u4FDD\u5B58\u65F6\u63D0\u4EA4\u4E00\u6B21\u4E91\u7AEF\u66F4\u65B0\uFF0C\u7531\u4E91\u7AEF\u6EDA\u52A8\u5E94\u7528\u5230\u5B9E\u4F8B\uFF0C\u4E0D\u9700\u8981\u672C\u673A\u91CD\u542F\u3002"),!0),U("\u6A21\u578B",r("input",{style:m.input,value:_e,disabled:C,placeholder:"\u4F8B\u5982 deepseek-v4.1-flash-1017","aria-label":"\u6A21\u578B\u540D\u79F0",onChange:y=>ne(String(y?.target?.value??""))})),U("\u7CFB\u7EDF\u63D0\u793A\u8BCD",r("textarea",{style:m.textarea,value:xe,disabled:C,"aria-label":"\u7CFB\u7EDF\u63D0\u793A\u8BCD",onChange:y=>we(String(y?.target?.value??""))})),U("\u8FD0\u884C\u65F6\u7248\u672C",h),U("\u73AF\u5883\u53D8\u91CF",i),U("\u4FDD\u5B58",u))};return r("section",{"data-personal-assistant-settings":"true",style:m.page},r("div",null,r("h1",{style:m.title},"\u4E2A\u4EBA\u52A9\u7406"),r("p",{style:{...m.lede,marginTop:6}},"\u4E91\u7AEF\u6301\u7EED\u8FD0\u884C\u7684\u52A9\u7406\uFF0C\u5E26\u4E00\u53F0\u72EC\u7ACB\u4E91\u7535\u8111\u3002\u5173\u6389\u7A97\u53E3\u5B83\u4E5F\u5728\u5DE5\u4F5C\uFF1B\u5BF9\u8BDD\u4E0E\u4E91\u7535\u8111\u5728\u5DE6\u4FA7\u300C\u4E2A\u4EBA\u52A9\u7406\u300D\u9875\u3002")),D?r("div",{role:"alert",style:{...m.note,color:"#b42318",background:"color-mix(in srgb, #b42318 8%, transparent)",border:"1px solid color-mix(in srgb, #b42318 25%, transparent)",borderRadius:10,padding:"9px 12px"}},D):null,r("div",{style:m.card},U("\u72B6\u6001",r("span",null,r("span",{style:ye},Pe),T?r("span",{style:m.note},`\u3000\u4E0A\u6B21\u68C0\u67E5 ${T}`):null),!0),U("\u4E91\u7AEF\u5B9E\u4F8B",o?.agentId?r("span",{style:m.mono},o.agentId):r("span",{style:m.note},oe?"\u672A\u8FD4\u56DE\u5B9E\u4F8B\u6807\u8BC6":"\u5F00\u901A\u540E\u7531 Studio \u7ED1\u5B9A")),U("\u7F51\u5173",o?.gatewayUrl?r("span",{style:m.mono},o.gatewayUrl):r("span",{style:m.note},"\u7531 Studio Host \u914D\u7F6E")),U("\u52A9\u7406\u8FDE\u63A5",r("span",{style:m.note},p===null?"\u68C0\u67E5\u4E2D":p.length?"\u5DF2\u8FDE\u63A5\u4F60\u7684\u52A9\u7406":"\u52A9\u7406\u5C1A\u672A\u5C31\u7EEA")),U("\u8BB0\u5FC6",r("div",null,r("div",{style:m.mono},"/workspace/assistant-state"),r("div",{style:m.note},"\u8BB0\u5FC6\u3001\u4F1A\u8BDD\u4E0E\u5B9A\u65F6\u4EFB\u52A1\u968F\u4E91\u7535\u8111\u6301\u4E45\u4FDD\u5B58\uFF0C\u6362\u8BBE\u5907\u4E5F\u5728"))),U("\u4E91\u7AEF\u80FD\u529B",r("div",null,r("div",null,"\u9ED8\u8BA4\u5F00\u542F\uFF1A\u4E91\u7AEF\u547D\u4EE4\u6267\u884C\u3001\u4E91\u7AEF\u6D4F\u89C8\u5668"),r("div",{style:m.note},"\u90FD\u8DD1\u5728\u9694\u79BB\u5DE5\u4F5C\u533A\uFF1A\u8BFB\u4E0D\u5230\u672C\u673A\u6587\u4EF6\u4E0E\u51ED\u8BC1\uFF0C\u4E0D\u80FD\u8BBF\u95EE\u5185\u7F51\u4E0E\u672C\u673A\u5730\u5740\uFF1B\u654F\u611F\u64CD\u4F5C\u4F1A\u5148\u8BF7\u4F60\u786E\u8BA4"))),U("\u63D2\u4EF6\u7248\u672C",r("span",{style:m.note},`\u6784\u5EFA ${je}`))),oe?c():null,oe||B?r("div",{style:m.card},U("\u5173\u95ED\u4E2A\u4EBA\u52A9\u7406",r("div",{style:{display:"flex",flexDirection:"column",gap:8}},r("div",{style:m.note},"\u5173\u95ED\u4F1A\u5220\u9664\u4E91\u7AEF\u5B9E\u4F8B\uFF08\u4E91\u7535\u8111 Pod\uFF09\u548C\u4E91\u7AEF\u52A9\u7406\u6570\u636E\uFF0C\u5E76\u91CA\u653E\u5173\u8054\u7684\u4E91\u8D44\u6E90\u8BA2\u5355\uFF1B\u672C\u673A\u7ED1\u5B9A\u4E5F\u4F1A\u4E00\u5E76\u6E05\u9664\uFF0C\u4E4B\u540E\u53EF\u91CD\u65B0\u521B\u5EFA\u3002"),B?r("div",{style:m.success},B):null,ee?r("div",{style:m.confirmBox},r("div",{style:{...m.note,color:"#b42318"}},"\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002\u8BF7\u8F93\u5165\u4E0A\u65B9\u300C\u4E91\u7AEF\u5B9E\u4F8B\u300D\u7684\u6807\u8BC6\u4EE5\u786E\u8BA4\u5173\u95ED\uFF1A"),r("input",{style:m.dangerInput,value:ge,placeholder:j||"ar-\u2026","aria-label":"\u8F93\u5165\u4E91\u7AEF\u5B9E\u4F8B\u6807\u8BC6\u4EE5\u786E\u8BA4\u5173\u95ED",disabled:Y,onChange:h=>X(String(h?.target?.value??""))}),r("div",{style:m.actions},r("button",{style:V&&!Y?m.danger:m.dangerDisabled,disabled:!V||Y,onClick:()=>{w()}},Y?"\u6B63\u5728\u5173\u95ED\u2026":"\u786E\u8BA4\u5173\u95ED\u4E2A\u4EBA\u52A9\u7406"),r("button",{style:m.button,disabled:Y,onClick:()=>{v(!1),X("")}},"\u53D6\u6D88"))):r("div",{style:m.actions},r("button",{style:m.dangerButton,disabled:!oe||Y,onClick:()=>{v(!0),X(""),W("")}},"\u5173\u95ED\u4E2A\u4EBA\u52A9\u7406"),r("span",{style:m.note},oe?"\u9700\u8981\u8F93\u5165\u5B9E\u4F8B\u6807\u8BC6\u4E8C\u6B21\u786E\u8BA4":"\u5F53\u524D\u6CA1\u6709\u5DF2\u5F00\u901A\u7684\u4E2A\u4EBA\u52A9\u7406"))),!0)):null,r("div",{style:m.actions},r("button",{style:m.button,disabled:R,onClick:()=>{ue()}},R?"\u6B63\u5728\u68C0\u67E5\u2026":"\u68C0\u67E5\u8FDE\u63A5"),r("span",{style:m.note},"\u68C0\u67E5\u4F1A\u8BFB\u53D6\u5F00\u901A\u72B6\u6001\u5E76\u62C9\u53D6\u4E00\u6B21\u52A9\u7406\u5217\u8868\uFF0C\u4E0D\u4F1A\u542F\u52A8\u4E91\u7535\u8111")))}function an({size:t}={}){let g=Ne,d=Number(t)>0?Number(t):16;return g?.createElement?g.createElement("svg",{width:d,height:d,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"block"}},g.createElement("path",{d:"M3.4 3.2h9.2a1.3 1.3 0 0 1 1.3 1.3H7.7l-2.9 2.3v-2.3H3.4a1.3 1.3 0 0 1-1.3-1.3V4.5a1.3 1.3 0 0 1 1.3-1.3z"}),g.createElement("path",{d:"M8.1 5.6l.62 1.46 1.46.62-1.46.62L8.1 9.76l-.62-1.46-1.46-.62 1.46-.62z"})):"\u52A9"}function ln({size:t}={}){let g=Ne,d=Number(t)>0?Number(t):16;return g?.createElement?g.createElement("svg",{width:d,height:d,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"block",flex:"0 0 auto"}},g.createElement("rect",{x:2.2,y:3.4,width:11.6,height:7.4,rx:1.4}),g.createElement("path",{d:"M6.6 13.4h2.8"}),g.createElement("path",{d:"M8 10.8v2.6"})):null}function cn(){let t=Ne,g=ln({size:15});return!t?.createElement||!g?"\u4E91\u7535\u8111":t.createElement("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",lineHeight:1}},g,t.createElement("span",null,"\u4E91\u7535\u8111"))}function _t(t){if(!t?.slots?.inject||!t.slots.register)throw new TypeError("Personal Assistant client requires the public DSH slots service");let g=async(a,s={})=>{if(!t.connection?.rpc?.call)throw new tt;let o=await t.connection.rpc.call("/api","personal-assistant",{operation:a,payload:s});if(!o?.ok)throw Object.assign(new Error(o?.error?.message||"Studio Host \u8BF7\u6C42\u5931\u8D25"),{code:o?.error?.code,status:o?.error?.details?.status,closeCode:o?.error?.details?.closeCode});return o.value},d=(a,s)=>{try{let o=()=>a();return typeof t.effect=="function"?t.effect(o,s):o()}catch(o){try{console.warn(`[personal-assistant] ${s} \u6CE8\u518C\u5931\u8D25`,o)}catch{}return}},r=vt({sidebarRight:t.sidebarRight,slots:t.slots});r&&(r.render=a=>St({...a,React:Ne||globalThis.React,workbench:r,Panel:kt}),d(()=>()=>r.dispose(),"personal-assistant: native workbench")),d(()=>t.slots.inject("main",()=>t.slots.register({name:"main",key:et,inject:()=>({request:g,nativeWorkbench:r})},on)),"personal-assistant: main panel"),d(()=>t.slots.inject("sidebar.panellist",()=>t.slots.register({name:"sidebar.panellist",id:et,order:90,label:"\u4E2A\u4EBA\u52A9\u7406"},an)),"personal-assistant: sidebar row"),d(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:`${et}-settings`,order:196,label:"\u4E2A\u4EBA\u52A9\u7406",inject:()=>({request:g})},sn)),"personal-assistant: settings section"),typeof t.inject=="function"&&d(()=>t.inject(["sidebarRightTabs"],a=>{let s=[],o=f=>{typeof f=="function"&&s.push(f)};try{let f=a.sidebarRightTabs;if(f===void 0||typeof f.register!="function")return;o(f.register({id:Ve,kind:Ve,title:()=>"\u4E91\u7535\u8111",guide:[{order:20,title:()=>"\u4E91\u7535\u8111",description:()=>"\u4E2A\u4EBA\u52A9\u7406\u7684\u4E91\u7AEF\u7535\u8111\u753B\u9762\uFF0C\u53EF\u83B7\u53D6\u63A7\u5236\u6743"}]})),o(a.slots.inject("sidebar.right.pane.tab",()=>a.slots.register({name:"sidebar.right.pane.tab",key:Ve,inject:()=>({request:g})},p=>kt({...p,variant:"computer"})))),o(a.slots.inject("sidebar.right.pane.tab.title",()=>a.slots.register({name:"sidebar.right.pane.tab.title",key:Ve},cn)))}catch(f){try{console.warn("[personal-assistant] \u53F3\u4FA7\u680F\u6CE8\u518C\u5931\u8D25",f)}catch{}}return()=>{for(let f of s.reverse())f()}}),"personal-assistant: right tab")}window.__ModuleLoader__.load({id:"@kingsoftcloud/agentkit-personal-assistant",factory:t=>(Rt(t("react")),{name:"agentkit-personal-assistant",inject:At,apply:_t})});})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-personal-assistant",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Standalone personal assistant DSH plugin with multi-Bot profiles and an explicit Cloud Computer Broker boundary.",
5
5
  "homepage": "https://github.com/kingsoftcloud/agentkit-personal-assistant",
6
6
  "repository": {
@@ -81,5 +81,11 @@
81
81
  "publishConfig": {
82
82
  "access": "public",
83
83
  "registry": "https://registry.npmjs.org/"
84
- }
84
+ },
85
+ "keywords": [
86
+ "dsh-plugin",
87
+ "agentkit",
88
+ "personal-assistant",
89
+ "cloud-computer"
90
+ ]
85
91
  }
@@ -198,6 +198,65 @@ const turnWrite = async (body, sessionId) => {
198
198
  submissionLocks.set(key, current);
199
199
  try { return await current; } finally { if (submissionLocks.get(key) === current) submissionLocks.delete(key); }
200
200
  };
201
+ // 一轮对话的观察上限:DSH 侧的工具/长命令可能跑很久,5 分钟会把正常任务误判成超时,
202
+ // 进而在会话里留下永久的 failed turn(面板一直显示“任务失败:DSH_TURN_TIMEOUT”)。
203
+ const TURN_OBSERVE_TIMEOUT_MS = 30 * 60_000;
204
+ // 同一会话的轮次串行执行:上一轮真正结束(含 DSH turn/end)后才提交下一轮,
205
+ // 而不是把“上一轮还在跑”的用户消息记成 DSH_SESSION_BUSY 的失败任务。
206
+ const sessionTurnChains = new Map();
207
+ const sessionChainKey = (botId, sessionId) => `${botId}\u0000${sessionId}`;
208
+
209
+ const trackTurnWork = promise => {
210
+ pendingTurns.add(promise);
211
+ void promise.catch(() => {}).finally(() => pendingTurns.delete(promise));
212
+ };
213
+
214
+ const buildTurnContent = async (body, botId, sessionId) => {
215
+ const content = [{ type: 'text', text: body.input }];
216
+ for (const attachment of body.attachments || []) {
217
+ const data = await cloudFiles.attachment({ botId, sessionId, path: attachment.path });
218
+ // 只有明确的图像附件进入模型图片通道;其他文件由工作区工具读取处理。
219
+ if (['image/png', 'image/jpeg', 'image/webp', 'image/gif'].includes(attachment.mediaType)) {
220
+ const store = runtime?.ctx?.get?.('attachments');
221
+ if (!store?.saveImage) throw Object.assign(new Error('云端图片附件服务不可用'), { status: 503 });
222
+ const ref = await store.saveImage({ data, mediaType: attachment.mediaType, name: attachment.name });
223
+ content.push({ type: 'image', attachment: ref });
224
+ }
225
+ }
226
+ return content;
227
+ };
228
+
229
+ // bridge 的 busy 标记在 waitForTurn 的 finally 里释放,链式排队后理论上不会撞上;
230
+ // 仍保留短重试兜底(例如云端 DSH 内部还有未归位的旧 turn)。
231
+ const submitWithBusyRetry = async args => {
232
+ for (let attempt = 0; ; attempt += 1) {
233
+ try { return await turnBridge.submitTurn(args); }
234
+ catch (error) {
235
+ if (error?.code !== 'DSH_SESSION_BUSY' || attempt >= 20) throw error;
236
+ await new Promise(resolve => setTimeout(resolve, 1000));
237
+ }
238
+ }
239
+ };
240
+
241
+ const observeTurn = async ({ botId, sessionId, turn, clientTurnId, receipt }) => {
242
+ const result = await turnBridge.waitForTurn({ botId, sessionId, requestId: receipt.requestId, timeoutMs: TURN_OBSERVE_TIMEOUT_MS, onProgress: progress => updateTurn(turn.turnId, { progress }) });
243
+ for (const content of result.messages) await stateStore.appendMessage({ botId, sessionId, role: 'assistant', content, metadata: { turnId: turn.turnId, ...(clientTurnId ? { clientTurnId } : {}), execution: receipt.execution } });
244
+ await updateTurn(turn.turnId, { status: result.status, result: result.messages.join('\n'), error: result.error || null });
245
+ console.info(JSON.stringify({ event: 'personal-assistant.turn.finished', botId, sessionId, turnId: turn.turnId, status: result.status }));
246
+ };
247
+
248
+ const executeTurn = async ({ botId, sessionId, body, turn, clientTurnId }) => {
249
+ try {
250
+ const content = await buildTurnContent(body, botId, sessionId);
251
+ const receipt = await submitWithBusyRetry({ botId, sessionId, input: body.input, parts: content, requestId: turn.turnId });
252
+ await updateTurn(turn.turnId, { status: 'running', execution: receipt.execution, requestId: receipt.requestId });
253
+ await observeTurn({ botId, sessionId, turn, clientTurnId, receipt });
254
+ } catch (error) {
255
+ await updateTurn(turn.turnId, { status: 'failed', error: error.code || error.message });
256
+ throw error;
257
+ }
258
+ };
259
+
201
260
  const submitCloudTurn = async (body, sessionId) => {
202
261
  const botId = stateBotId(body.botId);
203
262
  await requireSession(botId, sessionId);
@@ -212,32 +271,29 @@ const submitCloudTurn = async (body, sessionId) => {
212
271
  }
213
272
  const turn = await stateStore.createTurn({ botId, sessionId, input: body.input, metadata: body.metadata });
214
273
  const message = await stateStore.appendMessage({ botId, sessionId, role: 'user', content: body.input, metadata: { turnId: turn.turnId, ...(clientTurnId ? { clientTurnId } : {}) } });
215
- try {
216
- const content = [{ type: 'text', text: body.input }];
217
- for (const attachment of body.attachments || []) {
218
- const data = await cloudFiles.attachment({ botId, sessionId, path: attachment.path });
219
- // 只有明确的图像附件进入模型图片通道;其他文件由工作区工具读取处理。
220
- if (['image/png', 'image/jpeg', 'image/webp', 'image/gif'].includes(attachment.mediaType)) {
221
- const store = runtime?.ctx?.get?.('attachments');
222
- if (!store?.saveImage) throw Object.assign(new Error('云端图片附件服务不可用'), { status: 503 });
223
- const ref = await store.saveImage({ data, mediaType: attachment.mediaType, name: attachment.name });
224
- content.push({ type: 'image', attachment: ref });
225
- }
226
- }
227
- const receipt = await turnBridge.submitTurn({ botId, sessionId, input: body.input, parts: content, requestId: turn.turnId });
228
- await updateTurn(turn.turnId, { status: 'running', execution: receipt.execution, requestId: receipt.requestId });
229
- const pending = turnBridge.waitForTurn({ botId, sessionId, requestId: receipt.requestId, onProgress: progress => updateTurn(turn.turnId, { progress }) }).then(async result => {
230
- for (const content of result.messages) await stateStore.appendMessage({ botId, sessionId, role: 'assistant', content, metadata: { turnId: turn.turnId, ...(clientTurnId ? { clientTurnId } : {}), execution: receipt.execution } });
231
- await updateTurn(turn.turnId, { status: result.status, result: result.messages.join('\n'), error: result.error || null });
232
- console.info(JSON.stringify({ event: 'personal-assistant.turn.finished', botId, sessionId, turnId: turn.turnId, status: result.status }));
233
- }).catch(error => updateTurn(turn.turnId, { status: 'failed', error: error.code || error.message }));
234
- pendingTurns.add(pending);
235
- void pending.finally(() => pendingTurns.delete(pending));
236
- return { ...turn, status: 'running', messageId: message.messageId, ...receipt };
237
- } catch (error) {
274
+ const key = sessionChainKey(botId, sessionId);
275
+ const previous = sessionTurnChains.get(key);
276
+ if (previous) {
277
+ // 上一轮还没结束:保留 queued 状态,等它完成后再提交,不产生失败任务。
278
+ const queued = previous.catch(() => {}).then(() => executeTurn({ botId, sessionId, body, turn, clientTurnId }));
279
+ sessionTurnChains.set(key, queued);
280
+ void queued.catch(() => {}).finally(() => { if (sessionTurnChains.get(key) === queued) sessionTurnChains.delete(key); });
281
+ trackTurnWork(queued);
282
+ return { ...turn, status: 'queued', messageId: message.messageId };
283
+ }
284
+ // 会话空闲:立即提交,保持原有“提交即返回 running + requestId”的接口语义。
285
+ let receipt;
286
+ try { receipt = await submitWithBusyRetry({ botId, sessionId, input: body.input, parts: await buildTurnContent(body, botId, sessionId), requestId: turn.turnId }); }
287
+ catch (error) {
238
288
  await updateTurn(turn.turnId, { status: 'failed', error: error.code || error.message });
239
289
  throw error;
240
290
  }
291
+ await updateTurn(turn.turnId, { status: 'running', execution: receipt.execution, requestId: receipt.requestId });
292
+ const observed = observeTurn({ botId, sessionId, turn, clientTurnId, receipt }).catch(error => updateTurn(turn.turnId, { status: 'failed', error: error.code || error.message }));
293
+ sessionTurnChains.set(key, observed);
294
+ void observed.finally(() => { if (sessionTurnChains.get(key) === observed) sessionTurnChains.delete(key); });
295
+ trackTurnWork(observed);
296
+ return { ...turn, status: 'running', messageId: message.messageId, ...receipt };
241
297
  };
242
298
 
243
299
  // 尚未开始的任务可恢复;中断时不自动重放未知结果,避免重复执行操作。
@@ -435,8 +435,11 @@ export function createCloudBrowser({
435
435
  }
436
436
 
437
437
  async function launch() {
438
- // 异常重建只恢复已通过 URL 策略的最后页面;不静默切回 about:blank。
439
- const restoreUrl = desktopMode && lastUrl && lastUrl !== 'about:blank' ? desktopPolicy(lastUrl).href : desktopRestoreUrl;
438
+ // 桌面模式的首屏永远是欢迎页:进程/窗口重建时不能把上一次的浏览地址
439
+ // (尤其是 127.0.0.1:8081 的云端 DSH 网页)当成浏览器首页,否则用户点
440
+ // “浏览器”只会看到原生网页,再也回不到欢迎页。普通模式仍恢复最后页面。
441
+ const restoreUrl = desktopMode && desktopStartUrl ? desktopRestoreUrl
442
+ : lastUrl && lastUrl !== 'about:blank' ? desktopPolicy(lastUrl).href : desktopRestoreUrl;
440
443
  let started;
441
444
  try {
442
445
  started = await transportFactory({
@@ -520,10 +523,13 @@ export function createCloudBrowser({
520
523
  // 把应用窗口换成普通浏览器窗口:进程参数不同(去掉 --app),只能重启自有实例;
521
524
  // 页面地址沿用 lastUrl / 欢迎页,用户感知是“欢迎页变成了能上网的浏览器”。
522
525
  async function switchDesktopWindowToBrowsing() {
523
- if (!desktopMode || !desktopAppWindow) return;
526
+ if (!desktopMode) return;
527
+ // 用户要的是“浏览器首页就是欢迎页”:每次从欢迎页/dock 点“浏览器”都固定回
528
+ // 欢迎页,不沿用上次浏览的页面。窗口已经是普通窗口时也要复位 lastUrl,
529
+ // 否则下一次进程重建会把 8081 这类页面当成首页。
530
+ if (desktopStartUrl) lastUrl = desktopRestoreUrl;
531
+ if (!desktopAppWindow) return;
524
532
  desktopAppWindow = false;
525
- // 用户要的是“浏览器首页就是欢迎页”:切窗口时固定回欢迎页,不沿用上次浏览的页面。
526
- lastUrl = desktopRestoreUrl;
527
533
  const previous = transport;
528
534
  if (transport === previous) { transport = null; targetId = null; pageSession = null; }
529
535
  if (previous) { forgetInput(previous); await previous.dispose(); }
@@ -564,7 +570,9 @@ export function createCloudBrowser({
564
570
  }
565
571
  if (!missing && desktopMode && !(await hasBrowserWindow(inspectedTarget))) missing = true;
566
572
  if (!missing) return;
567
- const restoreUrl = lastUrl && lastUrl !== 'about:blank' ? desktopPolicy(lastUrl).href : desktopRestoreUrl;
573
+ // 有欢迎页的桌面模式重建窗口时从欢迎页开始:8081 不能变成“首页”。
574
+ const restoreUrl = desktopMode && desktopStartUrl ? desktopRestoreUrl
575
+ : lastUrl && lastUrl !== 'about:blank' ? desktopPolicy(lastUrl).href : desktopRestoreUrl;
568
576
  // 只替换已关闭/正在关闭的 page,不重启 Chromium;不等待旧 close ACK。
569
577
  let opened = await createDesktopWindowTarget(restoreUrl);
570
578
  // 无窗口的浏览器上新建窗口也可能不落地(线上残留过这种状态):确认失败
@@ -77,6 +77,9 @@ const ensureDesktopBrowser = async (options = {}) => {
77
77
  const openDshWeb = async ({ signal } = {}) => {
78
78
  if (closing || signal?.aborted) throw Object.assign(new Error('桌面入口已停止'), { code: 'DESKTOP_LAUNCH_CLOSED' });
79
79
  if (!dshWebUrl) throw Object.assign(new Error('云端助理网页还没准备好'), { code: 'DSH_WEB_UNAVAILABLE' });
80
+ // 欢迎页地址由桌面桥提供:先确保桌面(含 welcome 桥)就绪,再创建 Chromium,
81
+ // 否则 browserEnv 快照不到 AGENTKIT_WELCOME_URL,这个进程就永远没有首屏。
82
+ if (typeof desktop?.ensureDisplay === 'function') await desktop.ensureDisplay();
80
83
  const target = dshWebUrl;
81
84
  const view = await ensureDesktopBrowser({ browsing: true });
82
85
  if (closing || signal?.aborted) throw Object.assign(new Error('桌面入口已停止'), { code: 'DESKTOP_LAUNCH_CLOSED' });
@@ -90,6 +93,7 @@ desktop = desktopFactory({ applications: env.AGENTKIT_DESKTOP_MODE === '1', work
90
93
  dshWebUrl: () => dshWebUrl, onLaunchDshWeb: openDshWeb,
91
94
  onLaunchBrowser: async ({ signal } = {}) => {
92
95
  if (closing || signal?.aborted) throw Object.assign(new Error('桌面入口已停止'), { code: 'DESKTOP_LAUNCH_CLOSED' });
96
+ if (typeof desktop?.ensureDisplay === 'function') await desktop.ensureDisplay();
93
97
  // 用户主动点“浏览器”:欢迎页应用窗口切换成带地址栏的普通浏览器窗口。
94
98
  const result = await ensureDesktopBrowser({ browsing: true });
95
99
  if (closing || signal?.aborted) throw Object.assign(new Error('桌面入口已停止'), { code: 'DESKTOP_LAUNCH_CLOSED' });
@@ -27,6 +27,23 @@
27
27
  import { renderMarkdown } from './markdown.mjs';
28
28
 
29
29
  const EMPTY_HINT = '有什么可以帮你?';
30
+ /** 这两类失败是“消息根本没开始跑”的瞬时状态:云端现在会按会话排队重试,
31
+ * 历史会话里残留的记录不再渲染成任务失败,避免对话结束后一直显示红色失败。 */
32
+ const TRANSIENT_TURN_ERRORS = new Set(['DSH_SESSION_BUSY', 'DSH_TURN_TIMEOUT']);
33
+ const TURN_ERROR_TEXT = {
34
+ RUNTIME_PROCESS_INTERRUPTED: '云电脑重启,任务被中断',
35
+ DSH_SESSION_CONTROLLER_UNAVAILABLE: '云端连接暂时不可用,请稍后重试',
36
+ DSH_TURN_NOT_ACCEPTED: '云端没有接受这一轮对话,请重新发送',
37
+ DSH_SESSION_NOT_FOUND: '会话不存在或已被删除',
38
+ };
39
+ const turnErrorText = error => {
40
+ const value = String(error || '').trim();
41
+ if (!value) return '请检查任务状态后重试';
42
+ if (TURN_ERROR_TEXT[value]) return TURN_ERROR_TEXT[value];
43
+ // 纯大写错误码对用户没有意义;短句/中文错误保持原文。
44
+ return /^[A-Z][A-Z0-9_]{5,}$/u.test(value) ? '云端没有完成这一轮,请重试' : value.slice(0, 160);
45
+ };
46
+
30
47
  /** 判定回合结束后稍等再发队首:云端把 turn 标记为 running 有延迟,抢跑会撞 409。 */
31
48
  const QUEUE_FLUSH_DELAY_MS = 400;
32
49
  /** 云电脑仍忙时的退避重试上限:超过后交还给用户手动重试(消息内容仍在列表里)。 */
@@ -311,7 +328,10 @@ export function PersonalAssistantConversation({ React: R, request, scope, onOpen
311
328
  const labels = { cloud_computer: '操作云电脑', cloud_workspace: '处理云端文件', cloud_bash: '执行云端命令', cloud_run_code: '运行云端代码', assistant_schedule: '设置云端任务' };
312
329
  const tool = active?.progress?.tool;
313
330
  setProgressText(tool ? `${active.progress.state === 'running' ? '正在' : '已完成'}${labels[tool] || (tool.startsWith('cloud_browser_') ? '操作云端浏览器' : '执行工具')}` : '');
314
- mergeEvents(page.turns.filter(turn => ['failed', 'interrupted', 'cancelled'].includes(turn.status)).map(turn => ({ type: 'step', id: `turn-status-${turn.turnId}`, text: `任务${turn.status === 'failed' ? '失败' : '已中断'}:${turn.error || '请检查任务状态后重试'}` })));
331
+ const visibleFailures = page.turns
332
+ .filter(turn => ['failed', 'interrupted', 'cancelled'].includes(turn.status) && !TRANSIENT_TURN_ERRORS.has(String(turn.error || '')))
333
+ .map(turn => ({ type: 'step', id: `turn-status-${turn.turnId}`, text: `任务${turn.status === 'failed' ? '失败' : '已中断'}:${turnErrorText(turn.error)}` }));
334
+ mergeEvents(visibleFailures);
315
335
  }
316
336
  setError('');
317
337
  } catch (failure) {
@@ -81,6 +81,7 @@ const ui = {
81
81
  background: 'var(--dsw-alias-bg-layer-1, #fff)', color: 'var(--dsw-alias-label-primary, #17202c)',
82
82
  border: '1px solid var(--dsw-alias-border-default, #d8dee8)',
83
83
  };
84
+ const bindingFailure = error => typeof error?.message === 'string' && error.message && !/^(fetch failed|Failed to fetch)$/u.test(error.message) ? error.message.slice(0, 180) : '云电脑连接失败,请稍后重试';
84
85
  const failure = error => error?.code === 'PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE' && Number(error?.status) === 409 ? '当前云端版本尚不支持助理列表,请更新云端助理后重试' : '连接暂时不可用,请稍后重试';
85
86
  const directoryUnsupported = error => Number(error?.status) === 409 && ['PERSONAL_ASSISTANT_DIRECTORY_UNSUPPORTED', 'PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE'].includes(error?.code);
86
87
  const keyNames = { Control: 'Control_L', Meta: 'Super_L', Alt: 'Alt_L', Shift: 'Shift_L', Enter: 'Return', Escape: 'Escape', Tab: 'Tab', Backspace: 'BackSpace', Delete: 'Delete', ArrowUp: 'Up', ArrowDown: 'Down', ArrowLeft: 'Left', ArrowRight: 'Right', ' ': 'space' };
@@ -101,6 +102,8 @@ export function PersonalAssistantPanel({ request, initialBotId = '', openInSideb
101
102
  const [attempt, setAttempt] = useState(0);
102
103
  const [fps, setFps] = useState(0);
103
104
  const [controlPhase, setControlPhase] = useState('observe');
105
+ const [binding, setBinding] = useState(null);
106
+ const [busy, setBusy] = useState('');
104
107
  const [clipboardNotice, setClipboardNotice] = useState('');
105
108
  const controlRef = useRef(null);
106
109
  const clipboardRef = useRef(null), clipboardTimerRef = useRef(null);
@@ -343,13 +346,37 @@ export function PersonalAssistantPanel({ request, initialBotId = '', openInSideb
343
346
  };
344
347
  } catch (error) { if (current.mounted && generation === current.generation) { setPhase('error'); setNotice(failure(error)); } }
345
348
  };
346
- const refreshConnection = async signal => {
349
+ // Studio 负责发现实例、恢复/生成凭证;页面只读取公开状态,绝不接触凭据。
350
+ const bindingSnapshot = async signal => {
351
+ if (signal?.aborted) return null;
352
+ try { const value = await rpc('personal-assistant.desktop.status'); return value && typeof value === 'object' ? value : null; }
353
+ catch (error) {
354
+ if (error?.code === 'PERSONAL_ASSISTANT_OPERATION_UNAVAILABLE' || error?.status === 404) return null;
355
+ return { configured: false, reason: 'unavailable', detail: bindingFailure(error), candidates: [] };
356
+ }
357
+ };
358
+ const bindAssistant = async action => {
359
+ if (busy) return;
360
+ setBusy(action);
361
+ setNotice(action === 'create' ? '正在创建个人助理,可能需要几分钟…' : '正在获取云端连接凭证…');
362
+ try { await rpc(`personal-assistant.desktop.${action}`); setNotice(''); await refreshConnection(); }
363
+ catch (error) { setNotice(bindingFailure(error)); setBinding(await bindingSnapshot().catch(() => null)); }
364
+ finally { setBusy(''); }
365
+ };
366
+ const refreshConnection = async (signal, retried = false) => {
347
367
  close(false); setPhase('loading'); setNotice(''); setDirectoryError(''); setDirectoryCloseCode(null);
348
368
  try {
349
369
  const value = await rpc('personal-assistant.configuration');
350
370
  if (signal?.aborted || !state.current.mounted) return;
351
371
  state.current.config = value; setConfig(value);
352
- if (!value.configured) { state.current.bots = []; setBots([]); setBotId(''); setPhase('unconfigured'); return; }
372
+ if (!value.configured) {
373
+ const snapshot = await bindingSnapshot(signal);
374
+ if (signal?.aborted || !state.current.mounted) return;
375
+ state.current.bots = []; setBots([]); setBotId(''); setBinding(snapshot); setPhase('unconfigured');
376
+ if (snapshot?.configured && !retried) { await refreshConnection(signal, true); return; }
377
+ return;
378
+ }
379
+ setBinding(null);
353
380
  const result = await rpc('personal-assistant.bots.list');
354
381
  if (signal?.aborted || !state.current.mounted) return;
355
382
  if (result.directoryAvailable !== true) throw Object.assign(new Error('directory unavailable'), { code: 'PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE', status: 409 });
@@ -412,8 +439,17 @@ export function PersonalAssistantPanel({ request, initialBotId = '', openInSideb
412
439
  const buttonStyle = { ...ui, borderRadius: 6, padding: '7px 12px', cursor: 'pointer', font: 'inherit' };
413
440
  const active = ['ready', 'readonly', 'hidden', 'reconnecting', 'dormant', 'resuming'].includes(phase);
414
441
  const selectable = bots.length > 0;
415
- const emptyTitle = phase === 'unconfigured' ? '开通后,在这里连接你的个人助理' : phase === 'empty' ? '助理正在准备中' : phase === 'directory-error' ? '暂时无法连接云端助理' : '正在检查助理状态';
416
- const emptyDetail = phase === 'unconfigured' ? '开通完成后,即可在这里连接专属云电脑。' : phase === 'empty' ? '云端初始化完成后,可用助理会显示在这里。' : phase === 'directory-error' ? directoryError : '请稍候';
442
+ const bindingReason = binding?.reason || '';
443
+ const candidateCount = Array.isArray(binding?.candidates) ? binding.candidates.length : 0;
444
+ const bindingTitle = bindingReason === 'needs-create' ? '还没有创建个人助理'
445
+ : bindingReason === 'credential-unavailable' ? '正在恢复个人助理的连接凭证'
446
+ : bindingReason === 'unavailable' ? '暂时无法自动连接个人助理' : '个人助理尚未开通';
447
+ const bindingDetail = bindingReason === 'needs-create' ? '云账号下还没有个人助理实例,创建后即可在这里连接专属云电脑。'
448
+ : bindingReason === 'credential-unavailable' ? '云端暂时没有返回连接凭证,可以重新获取。'
449
+ : bindingReason === 'unavailable' ? (binding?.detail || '请检查云端登录状态后重试。')
450
+ : '开通完成后,即可在这里连接专属云电脑。';
451
+ const emptyTitle = phase === 'unconfigured' ? bindingTitle : phase === 'empty' ? '助理正在准备中' : phase === 'directory-error' ? '暂时无法连接云端助理' : '正在检查助理状态';
452
+ const emptyDetail = phase === 'unconfigured' ? bindingDetail : phase === 'empty' ? '云端初始化完成后,可用助理会显示在这里。' : phase === 'directory-error' ? directoryError : '请稍候';
417
453
  const computerVariant = variant === 'computer' || variant === 'native-tab';
418
454
  const stage = h('div', { ref: viewRef, 'data-personal-assistant-desktop-card': computerVariant ? 'true' : undefined, style: {
419
455
  position: 'relative', background: 'var(--dsw-alias-bg-layer-2, #f1f3f6)',
@@ -430,7 +466,11 @@ export function PersonalAssistantPanel({ request, initialBotId = '', openInSideb
430
466
  !active ? h('div', { style: { position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 10, padding: 16, textAlign: 'center' } },
431
467
  h('h2', { style: { margin: 0, fontSize: 18, fontWeight: 500 } }, selectable ? stateText : emptyTitle),
432
468
  h('p', { style: { margin: 0, maxWidth: 380, lineHeight: 1.7, color: 'var(--dsw-alias-label-secondary, #536174)' } }, selectable ? notice || '连接后即可使用云端桌面,关闭面板会释放本次控制。' : emptyDetail),
433
- !selectable && phase !== 'loading' ? h('button', { style: buttonStyle, onClick: () => void refreshConnection() }, '检查开通状态') : null) : null,
469
+ !selectable && phase !== 'loading' ? h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'center', alignItems: 'center' } },
470
+ phase === 'unconfigured' && bindingReason === 'needs-create' ? h('button', { style: buttonStyle, disabled: Boolean(busy), onClick: () => void bindAssistant('create') }, busy === 'create' ? '正在创建…' : '创建个人助理') : null,
471
+ phase === 'unconfigured' && (bindingReason === 'credential-unavailable' || candidateCount > 0) ? h('button', { style: buttonStyle, disabled: Boolean(busy), onClick: () => void bindAssistant('connect') }, busy === 'connect' ? '正在获取…' : bindingReason === 'credential-unavailable' ? '重新获取连接凭证' : '连接已发现的个人助理') : null,
472
+ h('button', { style: { ...buttonStyle, background: 'transparent' }, disabled: Boolean(busy), onClick: () => void refreshConnection() }, '检查开通状态'),
473
+ busy ? h('span', { role: 'status', style: { color: 'var(--dsw-alias-label-secondary, #536174)', fontSize: 12 } }, '处理中,请稍候…') : null) : null) : null,
434
474
  h('input', { ref: inputRef, 'aria-label': '云电脑文本输入', autoComplete: 'off', disabled: !active || (readOnly && !controlRef.current.snapshot.available && !(state.current.mode === 'control' && ['dormant', 'resuming'].includes(phase))), tabIndex: -1, style: { position: 'absolute', width: 1, height: 1, opacity: 0, left: 0, top: 0 }, onKeyDown: key, onKeyUp: key, onCompositionStart: () => { state.current.composition = true; }, onCompositionEnd: event => { state.current.composition = false; const text = event.currentTarget.value; event.currentTarget.value = ''; if (text) input({ type: 'text', text }); }, onInput: event => { if (state.current.composition || event.nativeEvent?.isComposing) return; const text = event.currentTarget.value; event.currentTarget.value = ''; if (text) input({ type: 'text', text }); } }));
435
475
  const secondaryInk = 'var(--dsw-alias-label-secondary, #536174)';
436
476
  const ghostStyle = { ...buttonStyle, background: 'transparent', color: 'inherit', border: ui.border };
@@ -531,6 +571,27 @@ const settingsStyle = {
531
571
  badgeOk: { background: 'color-mix(in srgb, #067647 12%, transparent)', color: '#067647' },
532
572
  badgeIdle: { background: 'color-mix(in srgb, #946200 14%, transparent)', color: '#946200' },
533
573
  badgeError: { background: 'color-mix(in srgb, #b42318 12%, transparent)', color: '#b42318' },
574
+ dangerButton: { ...ui, borderRadius: 8, padding: '6px 11px', cursor: 'pointer', font: 'inherit', fontSize: 13,
575
+ color: '#b42318', border: '1px solid color-mix(in srgb, #b42318 35%, transparent)', background: 'transparent' },
576
+ confirmBox: { border: '1px solid color-mix(in srgb, #b42318 30%, transparent)', borderRadius: 12, padding: '12px 14px',
577
+ display: 'flex', flexDirection: 'column', gap: 10, background: 'color-mix(in srgb, #b42318 4%, transparent)' },
578
+ dangerInput: { ...ui, border: '1px solid var(--dsw-alias-border-default, #d8dee8)', borderRadius: 8, padding: '6px 9px',
579
+ font: 'inherit', fontSize: 12, width: '100%', maxWidth: 360, boxSizing: 'border-box' },
580
+ danger: { ...ui, borderRadius: 8, padding: '6px 11px', cursor: 'pointer', font: 'inherit', fontSize: 13,
581
+ color: '#fff', border: '1px solid #b42318', background: '#b42318' },
582
+ dangerDisabled: { ...ui, borderRadius: 8, padding: '6px 11px', cursor: 'not-allowed', font: 'inherit', fontSize: 13,
583
+ color: '#fff', border: '1px solid color-mix(in srgb, #b42318 35%, transparent)', background: 'color-mix(in srgb, #b42318 35%, transparent)' },
584
+ success: { color: '#067647', fontSize: 12, lineHeight: 1.7 },
585
+ input: { ...ui, border: '1px solid var(--dsw-alias-border-default, #d8dee8)', borderRadius: 8, padding: '6px 9px',
586
+ font: 'inherit', fontSize: 12, width: '100%', maxWidth: 360, boxSizing: 'border-box' },
587
+ textarea: { ...ui, border: '1px solid var(--dsw-alias-border-default, #d8dee8)', borderRadius: 8, padding: '6px 9px',
588
+ font: 'inherit', fontSize: 12, width: '100%', minHeight: 76, resize: 'vertical', boxSizing: 'border-box' },
589
+ envRow: { display: 'flex', gap: 6, alignItems: 'center', marginBottom: 6, flexWrap: 'wrap' },
590
+ envKey: { ...ui, border: '1px solid var(--dsw-alias-border-default, #d8dee8)', borderRadius: 8, padding: '5px 8px',
591
+ font: 'inherit', fontSize: 12, width: 190, boxSizing: 'border-box' },
592
+ envValue: { ...ui, border: '1px solid var(--dsw-alias-border-default, #d8dee8)', borderRadius: 8, padding: '5px 8px',
593
+ font: 'inherit', fontSize: 12, width: 220, boxSizing: 'border-box' },
594
+ tinyButton: { ...ui, borderRadius: 8, padding: '4px 8px', cursor: 'pointer', font: 'inherit', fontSize: 12 },
534
595
  };
535
596
 
536
597
  /** 设置页里的「个人助理」一节:状态、连接自检、能力与记忆位置。 */
@@ -543,6 +604,20 @@ export function PersonalAssistantSettings({ request, openComputer = null } = {})
543
604
  const [error, setError] = useState('');
544
605
  const [checking, setChecking] = useState(false);
545
606
  const [checkedAt, setCheckedAt] = useState('');
607
+ const [confirming, setConfirming] = useState(false);
608
+ const [confirmText, setConfirmText] = useState('');
609
+ const [closing, setClosing] = useState(false);
610
+ const [closedNotice, setClosedNotice] = useState('');
611
+ const [settings, setSettings] = useState(null);
612
+ const [versions, setVersions] = useState(null);
613
+ const [model, setModel] = useState('');
614
+ const [prompt, setPrompt] = useState('');
615
+ const [version, setVersion] = useState('');
616
+ const [envRows, setEnvRows] = useState([]);
617
+ const [envDeletes, setEnvDeletes] = useState([]);
618
+ const [settingsError, setSettingsError] = useState('');
619
+ const [settingsNotice, setSettingsNotice] = useState('');
620
+ const [settingsBusy, setSettingsBusy] = useState(false);
546
621
 
547
622
  const check = useCallback(async () => {
548
623
  setChecking(true); setError('');
@@ -553,7 +628,25 @@ export function PersonalAssistantSettings({ request, openComputer = null } = {})
553
628
  if (current?.configured) {
554
629
  const directory = await request('personal-assistant.bots.list');
555
630
  setBots(Array.isArray(directory?.bots) ? directory.bots : []);
556
- } else { setBots([]); }
631
+ try {
632
+ const snapshot = await request('personal-assistant.settings.inspect');
633
+ setSettings(snapshot);
634
+ setModel(snapshot?.model || '');
635
+ setPrompt(snapshot?.prompt || '');
636
+ setVersion(snapshot?.runtime?.version || '');
637
+ setEnvRows((snapshot?.environmentVariables || []).map(row => ({ ...row, saved: true, dirty: false })));
638
+ setEnvDeletes([]);
639
+ setSettingsError('');
640
+ const catalog = await request('personal-assistant.settings.versions',
641
+ { currentVersion: snapshot?.runtime?.version || '' }).catch(reason => {
642
+ setSettingsError(reason?.message || '暂时读不到可升级的版本'); return null;
643
+ });
644
+ setVersions(catalog);
645
+ } catch (reason) {
646
+ setSettings(null); setVersions(null);
647
+ setSettingsError(reason?.message || '读取云端配置失败');
648
+ }
649
+ } else { setBots([]); setSettings(null); setVersions(null); }
557
650
  setCheckedAt(`${new Date().toLocaleTimeString('zh-CN', { hour12: false })} · ${Date.now() - started} ms`);
558
651
  } catch (reason) {
559
652
  setError(reason?.message || '连接检查失败');
@@ -561,6 +654,57 @@ export function PersonalAssistantSettings({ request, openComputer = null } = {})
561
654
  } finally { setChecking(false); }
562
655
  }, [request]);
563
656
 
657
+ const agentId = config?.agentId || '';
658
+ const canConfirm = Boolean(agentId) && confirmText.trim() === agentId;
659
+ const closeAssistant = useCallback(async () => {
660
+ if (!canConfirm) return;
661
+ setClosing(true); setError('');
662
+ try {
663
+ await request('personal-assistant.desktop.destroy', { confirmAgentId: agentId });
664
+ setConfirming(false); setConfirmText('');
665
+ setClosedNotice('个人助理已关闭:云端实例已删除,关联的云资源订单正在释放,本机绑定已清除。');
666
+ setConfig({ configured: false }); setBots([]);
667
+ setCheckedAt('');
668
+ } catch (reason) {
669
+ const message = String(reason?.message || '');
670
+ setError(/更新 Studio|云连接服务/iu.test(message) ? '当前 Studio 版本还不支持关闭个人助理,请更新 Studio 后重试。' : (message || '关闭个人助理失败,请稍后重试'));
671
+ } finally { setClosing(false); }
672
+ }, [agentId, canConfirm, request]);
673
+
674
+ const updateEnvRow = (index, patch) => setEnvRows(rows => rows.map((row, at) => at === index ? { ...row, ...patch, dirty: true } : row));
675
+ const addEnvRow = () => setEnvRows(rows => [...rows, { key: '', value: '', sensitive: false, saved: false, dirty: true }]);
676
+ const removeEnvRow = index => {
677
+ const row = envRows[index];
678
+ if (!row) return;
679
+ setEnvRows(rows => rows.filter((_, at) => at !== index));
680
+ if (row.saved && row.key) setEnvDeletes(keys => keys.includes(row.key) ? keys : [...keys, row.key]);
681
+ };
682
+ const editable = settings?.recordSource === 'studio';
683
+ const saveSettings = useCallback(async () => {
684
+ if (!editable || settingsBusy) return;
685
+ setSettingsBusy(true); setSettingsError(''); setSettingsNotice('');
686
+ try {
687
+ const environmentVariables = envRows.filter(row => row.dirty === true || row.saved !== true)
688
+ .map(row => ({ key: String(row.key || '').trim(), value: String(row.value || ''), sensitive: row.sensitive === true }));
689
+ await request('personal-assistant.settings.update', {
690
+ model: model.trim(), prompt, runtimeVersion: version,
691
+ environmentVariables, deleteKeys: envDeletes,
692
+ });
693
+ setSettingsNotice(`已提交云端更新(版本 ${version}),个人助理正在应用新配置,通常 1–2 分钟完成,期间云电脑会短暂重连。`);
694
+ setEnvDeletes([]);
695
+ try {
696
+ const snapshot = await request('personal-assistant.settings.inspect');
697
+ setSettings(snapshot);
698
+ setModel(snapshot?.model || '');
699
+ setPrompt(snapshot?.prompt || '');
700
+ setVersion(snapshot?.runtime?.version || version);
701
+ setEnvRows((snapshot?.environmentVariables || []).map(row => ({ ...row, saved: true, dirty: false })));
702
+ } catch { /* the submit already succeeded; the next check refreshes */ }
703
+ } catch (reason) {
704
+ setSettingsError(reason?.message || '保存配置失败,请稍后重试');
705
+ } finally { setSettingsBusy(false); }
706
+ }, [editable, envDeletes, envRows, model, prompt, request, settingsBusy, version]);
707
+
564
708
  useEffect(() => { void check(); }, [check]);
565
709
 
566
710
  const configured = config?.configured === true;
@@ -569,6 +713,65 @@ export function PersonalAssistantSettings({ request, openComputer = null } = {})
569
713
  const line = (label, value, first = false) => h('div', { style: first ? settingsStyle.rowFirst : settingsStyle.row },
570
714
  h('div', { style: settingsStyle.label }, label), h('div', { style: settingsStyle.value }, value));
571
715
 
716
+ const envSensitiveStyle = { ...settingsStyle.note, display: 'inline-flex', gap: 4, alignItems: 'center' };
717
+ const envActionsStyle = { ...settingsStyle.actions, marginTop: 6 };
718
+ const saveAreaStyle = { display: 'flex', flexDirection: 'column', gap: 8 };
719
+ const renderSettings = () => {
720
+ if (!settings) {
721
+ return h('div', { style: settingsStyle.card },
722
+ line('云端配置', h('div', { style: settingsStyle.note },
723
+ settingsBusy ? '读取中…' : (settingsError || '暂时读不到云端配置;请点下方“检查连接”重试')), true));
724
+ }
725
+ if (settings.recordSource !== 'studio') {
726
+ return h('div', { style: settingsStyle.card },
727
+ line('云端配置', h('div', { style: settingsStyle.note },
728
+ '这个个人助理是用旧版 Studio 创建的,本机没有记录它的配置清单,暂时不能在线修改。可以关闭后重新创建;等云端平台提供读取接口后即可直接编辑。'), true));
729
+ }
730
+ const versionControl = versions && versions.catalogAvailable
731
+ ? h('select', { style: settingsStyle.input, value: version, disabled: settingsBusy, 'aria-label': '运行时版本',
732
+ onChange: event => setVersion(String(event?.target?.value ?? '')) },
733
+ versions.versions.map(item => h('option', { key: item.version, value: item.version },
734
+ item.version === settings.runtime?.version ? `${item.version}(当前)` : item.version)))
735
+ : h('div', { style: settingsStyle.note },
736
+ `${settings.runtime?.version || version || '未知版本'} · 云端还没有发布可升级版本`);
737
+ const envEditor = h('div', null,
738
+ envRows.length
739
+ ? envRows.map((row, index) => h('div', { key: `env-${index}`, style: settingsStyle.envRow },
740
+ h('input', { style: settingsStyle.envKey, value: row.key, placeholder: 'KEY', 'aria-label': '环境变量名',
741
+ disabled: settingsBusy || row.saved === true,
742
+ onChange: event => updateEnvRow(index, { key: String(event?.target?.value ?? '') }) }),
743
+ h('input', { style: settingsStyle.envValue, value: row.value, 'aria-label': '环境变量值',
744
+ type: row.sensitive === true ? 'password' : 'text', disabled: settingsBusy,
745
+ placeholder: row.saved === true && row.sensitive === true ? '已保存(留空不修改)' : 'VALUE',
746
+ onChange: event => updateEnvRow(index, { value: String(event?.target?.value ?? '') }) }),
747
+ h('label', { style: envSensitiveStyle },
748
+ h('input', { type: 'checkbox', checked: row.sensitive === true, disabled: settingsBusy,
749
+ onChange: event => updateEnvRow(index, { sensitive: event?.target?.checked === true }) }), '敏感'),
750
+ h('button', { style: settingsStyle.tinyButton, disabled: settingsBusy, onClick: () => removeEnvRow(index) }, '删除')))
751
+ : h('div', { style: settingsStyle.note }, '还没有配置环境变量'),
752
+ h('div', { style: envActionsStyle },
753
+ h('button', { style: settingsStyle.tinyButton, disabled: settingsBusy, onClick: addEnvRow }, '添加变量'),
754
+ h('span', { style: settingsStyle.note }, '已保存的敏感值不会回显,留空表示不修改;删除后保存生效')));
755
+ const saveArea = h('div', { style: saveAreaStyle },
756
+ settingsNotice ? h('div', { style: settingsStyle.success }, settingsNotice) : null,
757
+ settingsError ? h('div', { style: { ...settingsStyle.note, color: '#b42318' } }, settingsError) : null,
758
+ h('div', { style: settingsStyle.actions },
759
+ h('button', { style: settingsStyle.button, disabled: settingsBusy, onClick: () => void saveSettings() },
760
+ settingsBusy ? '正在保存…' : '保存配置'),
761
+ h('span', { style: settingsStyle.note }, '保存会提交一次云端更新,由云端滚动应用')));
762
+ return h('div', { style: settingsStyle.card },
763
+ line('云端配置', h('div', { style: settingsStyle.note },
764
+ '模型、系统提示词、运行时版本和环境变量保存在云端实例。保存时提交一次云端更新,由云端滚动应用到实例,不需要本机重启。'), true),
765
+ line('模型', h('input', { style: settingsStyle.input, value: model, disabled: settingsBusy,
766
+ placeholder: '例如 deepseek-v4.1-flash-1017', 'aria-label': '模型名称',
767
+ onChange: event => setModel(String(event?.target?.value ?? '')) })),
768
+ line('系统提示词', h('textarea', { style: settingsStyle.textarea, value: prompt, disabled: settingsBusy,
769
+ 'aria-label': '系统提示词', onChange: event => setPrompt(String(event?.target?.value ?? '')) })),
770
+ line('运行时版本', versionControl),
771
+ line('环境变量', envEditor),
772
+ line('保存', saveArea));
773
+ };
774
+
572
775
  return h('section', { 'data-personal-assistant-settings': 'true', style: settingsStyle.page },
573
776
  h('div', null,
574
777
  h('h1', { style: settingsStyle.title }, '个人助理'),
@@ -585,6 +788,26 @@ export function PersonalAssistantSettings({ request, openComputer = null } = {})
585
788
  h('div', null, '默认开启:云端命令执行、云端浏览器'),
586
789
  h('div', { style: settingsStyle.note }, '都跑在隔离工作区:读不到本机文件与凭证,不能访问内网与本机地址;敏感操作会先请你确认'))),
587
790
  line('插件版本', h('span', { style: settingsStyle.note }, `构建 ${PERSONAL_ASSISTANT_CLIENT_BUILD}`))),
791
+ configured ? renderSettings() : null,
792
+ configured || closedNotice ? h('div', { style: settingsStyle.card },
793
+ line('关闭个人助理', h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
794
+ h('div', { style: settingsStyle.note }, '关闭会删除云端实例(云电脑 Pod)和云端助理数据,并释放关联的云资源订单;本机绑定也会一并清除,之后可重新创建。'),
795
+ closedNotice ? h('div', { style: settingsStyle.success }, closedNotice) : null,
796
+ confirming
797
+ ? h('div', { style: settingsStyle.confirmBox },
798
+ h('div', { style: { ...settingsStyle.note, color: '#b42318' } }, '此操作不可撤销。请输入上方「云端实例」的标识以确认关闭:'),
799
+ h('input', {
800
+ style: settingsStyle.dangerInput, value: confirmText, placeholder: agentId || 'ar-…',
801
+ 'aria-label': '输入云端实例标识以确认关闭', disabled: closing,
802
+ onChange: event => setConfirmText(String(event?.target?.value ?? '')),
803
+ }),
804
+ h('div', { style: settingsStyle.actions },
805
+ h('button', { style: canConfirm && !closing ? settingsStyle.danger : settingsStyle.dangerDisabled, disabled: !canConfirm || closing, onClick: () => void closeAssistant() },
806
+ closing ? '正在关闭…' : '确认关闭个人助理'),
807
+ h('button', { style: settingsStyle.button, disabled: closing, onClick: () => { setConfirming(false); setConfirmText(''); } }, '取消')))
808
+ : h('div', { style: settingsStyle.actions },
809
+ h('button', { style: settingsStyle.dangerButton, disabled: !configured || closing, onClick: () => { setConfirming(true); setConfirmText(''); setClosedNotice(''); } }, '关闭个人助理'),
810
+ h('span', { style: settingsStyle.note }, configured ? '需要输入实例标识二次确认' : '当前没有已开通的个人助理'))), true)) : null,
588
811
  h('div', { style: settingsStyle.actions },
589
812
  h('button', { style: settingsStyle.button, disabled: checking, onClick: () => void check() }, checking ? '正在检查…' : '检查连接'),
590
813
  h('span', { style: settingsStyle.note }, '检查会读取开通状态并拉取一次助理列表,不会启动云电脑')));
@@ -32,7 +32,33 @@ const SESSION_OPERATIONS = Object.freeze([
32
32
  'personal-assistant.file.upload',
33
33
  'personal-assistant.file.download',
34
34
  ]);
35
- const OPERATIONS = new Set(['personal-assistant.configuration', 'personal-assistant.bots.list', 'personal-assistant.desktop.ticket', ...SESSION_OPERATIONS]);
35
+ const BINDING_OPERATIONS = Object.freeze([
36
+ // Studio owns the cloud account, the instance selection and the credential.
37
+ // These operations never accept a credential from the page: they only drive
38
+ // discovery, credential recovery and creation inside the Studio Host.
39
+ 'personal-assistant.desktop.status',
40
+ 'personal-assistant.desktop.connect',
41
+ 'personal-assistant.desktop.create',
42
+ 'personal-assistant.desktop.disconnect',
43
+ 'personal-assistant.desktop.destroy',
44
+ // The Assistant's own reachable settings. The page never talks to the cloud
45
+ // control plane; Studio validates and submits every change.
46
+ 'personal-assistant.settings.inspect',
47
+ 'personal-assistant.settings.update',
48
+ 'personal-assistant.settings.versions',
49
+ ]);
50
+ const BINDING_METHODS = Object.freeze({
51
+ 'personal-assistant.desktop.status': 'status',
52
+ 'personal-assistant.desktop.connect': 'connect',
53
+ 'personal-assistant.desktop.create': 'create',
54
+ 'personal-assistant.desktop.disconnect': 'disconnect',
55
+ 'personal-assistant.desktop.destroy': 'destroy',
56
+ 'personal-assistant.settings.inspect': 'settings',
57
+ 'personal-assistant.settings.update': 'settingsUpdate',
58
+ 'personal-assistant.settings.versions': 'settingsVersions',
59
+ });
60
+ const AGENT_ID = /^ar-[A-Za-z0-9-]{4,120}$/u;
61
+ const OPERATIONS = new Set(['personal-assistant.configuration', 'personal-assistant.bots.list', 'personal-assistant.desktop.ticket', ...BINDING_OPERATIONS, ...SESSION_OPERATIONS]);
36
62
  const fail = (code, message, status = 400) => Object.assign(new Error(message), { code, status });
37
63
  const plain = value => value && typeof value === 'object' && !Array.isArray(value);
38
64
  const safeCloseCode = value => Number.isInteger(value) && value >= 1000 && value <= 4999 ? value : undefined;
@@ -107,10 +133,104 @@ export function createPersonalAssistantHostGateway(config = {}, { env = process.
107
133
  issueTicket: (scope, signal) => request('personal-assistant.desktop.ticket', scope, signal),
108
134
  WebSocketImpl, ca: trustedCAs(),
109
135
  });
136
+ function publicBindingStatus(value) {
137
+ if (!plain(value) || typeof value.configured !== 'boolean') throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 返回的绑定状态无效', 502);
138
+ const reason = typeof value.reason === 'string' ? value.reason.slice(0, 80) : '';
139
+ const candidates = Array.isArray(value.candidates) ? value.candidates.filter(row => plain(row) && typeof row.agentId === 'string' && AGENT_ID.test(row.agentId))
140
+ .slice(0, 20).map(row => ({ agentId: row.agentId, name: typeof row.name === 'string' ? row.name.slice(0, 80) : '',
141
+ status: typeof row.status === 'string' ? row.status.slice(0, 32) : '', createdAt: typeof row.createdAt === 'string' ? row.createdAt.slice(0, 40) : '' })) : [];
142
+ // The credential never reaches the page; only the public binding shape does.
143
+ return { configured: value.configured, agentId: value.configured && typeof value.agentId === 'string' ? value.agentId : undefined,
144
+ mode: 'studio', reason, candidates };
145
+ }
146
+ function publicBinding(value) {
147
+ if (!plain(value) || typeof value.configured !== 'boolean' || (value.configured && (typeof value.agentId !== 'string' || !AGENT_ID.test(value.agentId))))
148
+ throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 返回的绑定结果无效', 502);
149
+ return { configured: value.configured, agentId: value.configured ? value.agentId : undefined, mode: 'studio' };
150
+ }
151
+ const settingsText = (value, max) => typeof value === 'string' ? value.slice(0, max) : '';
152
+ /** Settings are whitelisted field by field for the same reason tickets are:
153
+ * the page must never receive anything the Host did not mean to publish. */
154
+ function publicSettings(value) {
155
+ if (!plain(value) || typeof value.configured !== 'boolean' || !plain(value.runtime)) throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 返回的配置格式无效', 502);
156
+ const environmentVariables = Array.isArray(value.environmentVariables) ? value.environmentVariables.filter(plain)
157
+ .filter(row => typeof row.key === 'string' && /^[A-Za-z_][A-Za-z0-9_]{0,63}$/u.test(row.key))
158
+ .slice(0, 64).map(row => ({ key: row.key, sensitive: row.sensitive === true,
159
+ value: row.sensitive === true ? '' : settingsText(row.value, 4096) })) : [];
160
+ return {
161
+ configured: value.configured,
162
+ agentId: value.configured && typeof value.agentId === 'string' && AGENT_ID.test(value.agentId) ? value.agentId : undefined,
163
+ name: settingsText(value.name, 120), description: settingsText(value.description, 300),
164
+ status: settingsText(value.status, 32), deploymentType: settingsText(value.deploymentType, 40),
165
+ runtime: { name: settingsText(value.runtime.name, 60), version: settingsText(value.runtime.version, 40),
166
+ imageDigest: settingsText(value.runtime.imageDigest, 200), updatedAt: settingsText(value.runtime.updatedAt, 40) },
167
+ model: settingsText(value.model, 120),
168
+ prompt: typeof value.prompt === 'string' ? value.prompt.slice(0, 8_000) : '',
169
+ environmentVariables,
170
+ recordSource: value.recordSource === 'studio' ? 'studio' : 'missing',
171
+ };
172
+ }
173
+ function publicSettingsVersions(value) {
174
+ if (!plain(value) || !Array.isArray(value.versions)) throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 返回的版本列表无效', 502);
175
+ const versions = value.versions.filter(plain)
176
+ .filter(row => typeof row.version === 'string' && /^\d+\.\d+\.\d+$/u.test(row.version))
177
+ .slice(0, 200).map(row => ({ version: row.version, image: settingsText(row.image, 200),
178
+ capabilities: Array.isArray(row.capabilities) ? row.capabilities.filter(cap => typeof cap === 'string').slice(0, 20) : [] }));
179
+ return { currentVersion: settingsText(value.currentVersion, 40), versions, catalogAvailable: versions.length > 0 };
180
+ }
181
+ function publicSettingsUpdate(value) {
182
+ if (!plain(value) || value.saved !== true) throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 没有确认配置已提交,请稍后重试', 502);
183
+ return { configured: true, saved: true, agentId: typeof value.agentId === 'string' && AGENT_ID.test(value.agentId) ? value.agentId : undefined,
184
+ version: settingsText(value.version, 40), status: settingsText(value.status, 32) || 'updating' };
185
+ }
186
+
110
187
  async function request(operation, payload = {}, signal) {
111
188
  if (!plain(payload)) throw fail('PERSONAL_ASSISTANT_REQUEST_INVALID', '请求参数格式错误');
112
189
  if (!OPERATIONS.has(operation)) throw fail('PERSONAL_ASSISTANT_OPERATION_UNAVAILABLE', '当前面板不支持此操作', 404);
113
190
  const current = await binding(signal);
191
+ const bindingMethod = BINDING_METHODS[operation];
192
+ if (bindingMethod) {
193
+ if (payload.agentId !== undefined && operation !== 'personal-assistant.desktop.create') {
194
+ if (typeof payload.agentId !== 'string' || !AGENT_ID.test(payload.agentId)) throw fail('PERSONAL_ASSISTANT_AGENT_INVALID', '云端实例标识无效');
195
+ }
196
+ const studio = current.studio;
197
+ if (!studio) throw fail('PERSONAL_ASSISTANT_STANDALONE', '独立安装不支持自动发现;请在 Host 配置中连接云端实例', 409);
198
+ if (typeof studio[bindingMethod] !== 'function') throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', '请更新 Studio 云连接服务', 503);
199
+ const created = operation === 'personal-assistant.desktop.create';
200
+ const closing = operation === 'personal-assistant.desktop.destroy';
201
+ if (closing) {
202
+ const confirm = payload.confirmAgentId;
203
+ // Closing frees a paid cloud resource: never accept an implicit target.
204
+ if (typeof confirm !== 'string' || !AGENT_ID.test(confirm)) throw fail('PERSONAL_ASSISTANT_AGENT_INVALID', '关闭个人助理需要再次确认实例标识');
205
+ }
206
+ const settingsWrite = operation === 'personal-assistant.settings.update';
207
+ const settingsRead = operation === 'personal-assistant.settings.inspect' || operation === 'personal-assistant.settings.versions';
208
+ const scoped = created ? AbortSignal.timeout(360_000) : closing ? AbortSignal.timeout(120_000)
209
+ : settingsWrite ? AbortSignal.timeout(120_000) : settingsRead ? AbortSignal.timeout(30_000) : AbortSignal.timeout(15_000);
210
+ const deadline = signal ? AbortSignal.any([signal, scoped]) : scoped;
211
+ const input = closing
212
+ ? { agentId: current.agentId, confirmAgentId: String(payload.confirmAgentId) }
213
+ : settingsWrite
214
+ ? { model: payload.model, prompt: payload.prompt, runtimeVersion: payload.runtimeVersion,
215
+ environmentVariables: payload.environmentVariables, deleteKeys: payload.deleteKeys }
216
+ : operation === 'personal-assistant.settings.versions'
217
+ ? { currentVersion: payload.currentVersion }
218
+ : settingsRead ? {}
219
+ : !created && operation !== 'personal-assistant.desktop.status' && operation !== 'personal-assistant.desktop.disconnect' && payload.agentId
220
+ ? { agentId: String(payload.agentId) } : {};
221
+ let value;
222
+ try { value = await studio[bindingMethod](input, deadline); }
223
+ catch (error) {
224
+ const status = Number.isInteger(error?.status) && error.status >= 400 && error.status <= 599 ? error.status : 503;
225
+ throw fail(error?.code || 'PERSONAL_ASSISTANT_BINDING_FAILED', String(error?.message || '个人助理连接失败').slice(0, 240), status);
226
+ }
227
+ if (bindingMethod === 'status') return publicBindingStatus(value);
228
+ if (bindingMethod === 'destroy') return { configured: false, mode: 'studio', ...(value?.closed === true ? { closed: true } : {}) };
229
+ if (bindingMethod === 'settings') return publicSettings(value);
230
+ if (bindingMethod === 'settingsVersions') return publicSettingsVersions(value);
231
+ if (bindingMethod === 'settingsUpdate') return publicSettingsUpdate(value);
232
+ return publicBinding(value);
233
+ }
114
234
  if (operation === 'personal-assistant.configuration') return {
115
235
  configured: current.configured, ...(current.configured ? { agentId: current.agentId } : {}),
116
236
  ...(base ? { gatewayUrl: base.origin } : {}),