@kingsoftcloud/agentkit-personal-assistant 0.1.6 → 0.1.7
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 +4 -4
- package/package.json +1 -1
- package/src/client/index.mjs +45 -5
- package/src/host-gateway.mjs +54 -1
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var We=Object.freeze({width:1280,height:800});function Ve(t={}){let g=Number(t.width)||We.width,l=Number(t.height)||We.height;return!Number.isFinite(g)||!Number.isFinite(l)||g<=0||l<=0?We:Object.freeze({width:Math.round(g),height:Math.round(l)})}function ot({clientX:t,clientY:g,rect:l,display:c=We}){let n=Ve(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),v=r+(s-n.width*d)/2,_=u+(o-n.height*d)/2,I=Math.max(0,Math.min(n.width-1,Math.round((Number(t)-v)/d))),k=Math.max(0,Math.min(n.height-1,Math.round((Number(g)-_)/d)));return{x:I,y:k}}function st({send:t,changed:g=()=>{},failed:l=()=>{},setTimer:c=setTimeout,clearTimer:n=clearTimeout}={}){let s=!1,o=0,r="observe",u=!1,d=[],v="",_,I=()=>g({phase:r,readOnly:r!=="controlling",controlEpoch:o,available:s}),k=()=>{n(_),_=void 0;let b=v;v="",b&&r==="controlling"&&t({type:"input",controlEpoch:o,event:{type:"text",text:b}})},D=b=>{b.type==="text"?(v.length+b.text.length>16384&&k(),v+=b.text,_||(_=c(k,30))):(k(),t({type:"input",controlEpoch:o,event:b}))},S=()=>{r="acquiring",I(),t({type:"control.acquire",controlEpoch:o})},M=b=>{if(b.type==="pointermove"&&d.at(-1)?.type==="pointermove")d[d.length-1]=b;else if(d.length<32)d.push(b);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(b={}){n(_),_=void 0,v="",d=[],s=b.controlAvailable===!0,o=Number.isSafeInteger(b.controlEpoch)?b.controlEpoch:0,r=b.readOnly===!1?"controlling":"observe",u=r==="controlling",I()},input(b){return r==="controlling"?(D(b),!0):(!u||r==="observe")&&(b.type==="pointermove"||["button","key"].includes(b.type)&&b.action==="up")||b.type==="pointermove"&&r==="observe"?!1:s?(u=!0,M(b)?(r==="observe"&&S(),!0):!1):(b.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"&&(k(),r="releasing",I(),t({type:"control.release",controlEpoch:o}))},accept(b){if(!Number.isSafeInteger(b.controlEpoch)||b.controlEpoch<o)return;if(b.controlEpoch!==o&&(n(_),_=void 0,v=""),o=b.controlEpoch,s=b.controlAvailable===!0,b.readOnly){r!=="releasing"&&(u=!1,d=[]),r="observe",I(),u&&s&&S();return}if(!u){d=[],r="releasing",I(),t({type:"control.release",controlEpoch:o});return}r="controlling",I();let ae=d;d=[];for(let J of ae)D(J)},reject(b){Number.isSafeInteger(b.controlEpoch)&&b.controlEpoch<o||(u=!1,d=[],n(_),_=void 0,v="",Number.isSafeInteger(b.controlEpoch)&&b.controlEpoch>=o&&(o=b.controlEpoch),r=b.readOnly===!1?"controlling":"observe",I(),l(b.message||"\u63A7\u5236\u6743\u6682\u4E0D\u53EF\u7528\uFF0C\u4ECD\u53EF\u7EE7\u7EED\u65C1\u89C2"))},dispose(){$.release(),n(_),_=void 0,v="",d=[]}};return $}var me=(t,g,l)=>Object.assign(new Error(g),{code:t,cause:l}),Nt=t=>{try{return new TextEncoder().encode(t).length}catch{return t.length}},at=t=>typeof t=="string"?t:String(t?.text??"");async function Qe({clipboard:t}={}){let g=t||globalThis.navigator?.clipboard;if(!g||typeof g.readText!="function")throw me("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 me("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 Pt(t,{clipboard:g}={}){let l=g||globalThis.navigator?.clipboard;if(!l||typeof l.writeText!="function")throw me("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 me("CLIPBOARD_WRITE_DENIED","\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u5199\u5165\u526A\u8D34\u677F\uFF0C\u8BF7\u91CD\u8BD5",c)}}function Bt(){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 qe(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 Ft=0,Mt=()=>{let t=globalThis.crypto?.randomUUID?.();return t?`clip-${t}`:`clip-${Date.now().toString(36)}-${Ft+=1}`};function it({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((v,_)=>{let I=Mt(),k=c(()=>{let M=s.get(I);M&&o(M,()=>_(me("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(I,{id:I,timer:k,resolve:v,reject:M=>_(M)});let D=!1,S;try{S=typeof l=="function"?l():void 0}catch{S=void 0}try{D=t({type:u,requestId:I,...Number.isSafeInteger(S)?{controlEpoch:S}:{},...d})!==!1}catch(M){o(s.get(I),()=>_(me("CLIPBOARD_UNAVAILABLE","\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u526A\u8D34\u677F\u6682\u4E0D\u53EF\u7528",M)));return}D||o(s.get(I),()=>_(me("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:at(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(me(u.error?.code||"CLIPBOARD_FAILED",u.error?.message||"",u.error))}),!0):!1},rejectAll(u=me("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 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:l,notify:c=()=>{}}={}){let n=t||(()=>Qe()),s="";try{s=await n()}catch(o){return c(qe(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(Nt(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(qe(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(Bt())!==!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 ut({readCloud:t,writeLocal:g,notify:l=()=>{}}={}){let c=g||(o=>Pt(o)),n;try{n=await t()}catch(o){return l(qe(o)||"\u8BFB\u53D6\u4E91\u7535\u8111\u526A\u8D34\u677F\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"),{ok:!1,code:"CLIPBOARD_READ_FAILED"}}let s=at(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(qe(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 Ut=/^```\s*([\w+#.-]*)\s*$/u,zt=/^(#{1,6})\s+(.*)$/u,pt=/^\s*[-*+]\s+(.*)$/u,ft=/^\s*(\d{1,3})[.)]\s+(.*)$/u,Xe=/^\s*>\s?(.*)$/u,$t=/^\s*([-*_])\s*(?:\1\s*){2,}$/u;function jt(t){let l=(typeof t=="string"?t.replace(/\r\n?/gu,`
|
|
2
2
|
`):"").split(`
|
|
3
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=
|
|
5
|
-
`)});continue}if(r.trim()===""){s(o),n+=1;continue}let d=
|
|
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})});})();
|
|
4
|
+
`)}),r.length=0)},o=[];for(;n<l.length;){let r=l[n],u=Ut.exec(r);if(u){s(o);let k=[];for(n+=1;n<l.length&&!/^```\s*$/u.test(l[n]);)k.push(l[n]),n+=1;n+=1,c.push({type:"code",lang:u[1]||"",text:k.join(`
|
|
5
|
+
`)});continue}if(r.trim()===""){s(o),n+=1;continue}let d=zt.exec(r);if(d){s(o),c.push({type:"heading",level:d[1].length,text:d[2].trim()}),n+=1;continue}if($t.test(r)){s(o),c.push({type:"rule"}),n+=1;continue}let v=Xe.exec(r);if(v){s(o);let k=[v[1]];for(n+=1;n<l.length&&Xe.test(l[n]);)k.push(Xe.exec(l[n])[1]),n+=1;c.push({type:"quote",text:k.join(`
|
|
6
|
+
`)});continue}let _=pt.exec(r),I=ft.exec(r);if(_||I){s(o);let k={type:I?"ordered":"unordered",items:[],start:I?Number(I[1]):1};for(;n<l.length;){let D=pt.exec(l[n]),S=ft.exec(l[n]);if(!D&&!S)break;k.items.push((D?D[1]:S[2]).trim()),n+=1}c.push(k);continue}o.push(r),n+=1}return s(o),c}function Wt(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),v=d<0?n.length:d+1;c(n.slice(0,v)),n=n.slice(v)}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 gt(t,g,l={}){let c=jt(g);if(c.length===0)return null;let n=(s,o)=>Wt(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,v)=>t("li",{key:`${r}-l${v}`},n(d,`${r}-l${v}`))))}return t("p",{key:r,style:l.paragraph},n(s.text,r))})}var qt="\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u4F60\uFF1F",Ht=400,Kt=8,yt=1500,w={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}},V=t=>typeof t=="string"?t:"",Yt=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"})),Vt=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 bt({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,v]=u("loading"),[_,I]=u(""),[k,D]=u([]),[S,M]=u(""),[$,b]=u([]),[ae,J]=u(""),[z,C]=u([]),L=r(null),[B,N]=u(!1),[j,te]=u(!1),[tt,Ue]=u(""),[ne,Le]=u([]),[Oe,re]=u(""),ie=r(0),le=r(new Map),W=r([]),ke=r(!1),Q=r(null),Ne=r(!1);Ne.current=B;let F=r(!1);F.current=j;let pe=r("loading");pe.current=d;let ve=r(0),P=r(!0),Ae=r(null),xe=r(!0),X=r("");X.current=S;let Z=s(async(i,m={})=>{if(typeof g!="function")throw new Error("Studio Host \u5C1A\u672A\u8FDE\u63A5");return g(i,m)},[g]),h=s(i=>{!Array.isArray(i)||i.length===0||b(m=>{let y=[...m];for(let p of i)if(!(!p||typeof p!="object")){if(p.type==="message"){let T=V(p.id)||`local-${y.length}`,x=V(p.role)||"assistant",R=V(p.text),U=y.findIndex(de=>de.id===T),ee={id:T,role:x,text:R,done:p.done!==!1,clientTurnId:p.clientTurnId,status:"accepted"};if(U>=0)y[U]={...y[U],...ee};else if(x==="user"){let de=y.findIndex(Be=>Be.role==="user"&&p.clientTurnId&&Be.clientTurnId===p.clientTurnId);de>=0?y[de]={...ee}:y.push(ee)}else y.push(ee)}else if(p.type==="delta"){let T=V(p.id)||`local-${y.length}`,x=y.findIndex(R=>R.id===T);x>=0?y[x]={...y[x],text:y[x].text+V(p.text)}:y.push({id:T,role:"assistant",text:V(p.text),done:!1})}else if(p.type==="step"&&V(p.text)){let T={id:V(p.id),role:"step",text:V(p.text),done:!0},x=y.findIndex(R=>R.id===T.id);x>=0?y[x]=T:y.push(T)}}return y})},[]),oe=s(async i=>{if(!i)return;let m=X.current;if(m&&m!==i&&W.current.length>0){let p=W.current.length;W.current=[],Le([]),Q.current&&(clearTimeout(Q.current),Q.current=null),re(`\u5DF2\u5207\u6362\u4F1A\u8BDD\uFF0C${p} \u6761\u6392\u961F\u6D88\u606F\u672A\u53D1\u9001\uFF0C\u5DF2\u53D6\u6D88`)}else m&&m!==i&&re("");X.current=i;let y=++ve.current;M(i),v("loading"),I(""),ie.current=0,xe.current=!0,b([]);try{let p=await Z("personal-assistant.session.snapshot",{sessionId:i});if(!P.current||X.current!==i||y!==ve.current)return;ie.current=Number(p?.cursor)||0;let T=Array.isArray(p?.messages)?p.messages:[];b(T.map((x,R)=>({id:V(x?.id)||`history-${R}`,role:V(x?.role)||"assistant",text:V(x?.text),done:!0}))),te(p.turns?.some(x=>["queued","running"].includes(x.status))||!1),v("ready")}catch(p){if(!P.current||y!==ve.current)return;v("error"),I(p?.message||"\u65E0\u6CD5\u8BFB\u53D6\u4F1A\u8BDD\u5185\u5BB9")}},[Z]),se=s(async()=>{if(v("loading"),I(""),!!P.current)try{let i=await Z("personal-assistant.sessions.list");if(!P.current)return;let m=Array.isArray(i?.sessions)?i.sessions:[];if(D(m),m.length>0){await oe(V(m[0].sessionId));return}let y=await Z("personal-assistant.session.create",{});if(!P.current)return;let p=V(y?.sessionId);D(p?[{sessionId:p,title:V(y?.title)||"\u65B0\u4F1A\u8BDD"}]:[]),await oe(p)}catch(i){if(!P.current)return;v("error"),I(i?.message||"\u4F1A\u8BDD\u901A\u9053\u6682\u65F6\u4E0D\u53EF\u7528")}},[Z,oe]);o(()=>(P.current=!0,se(),()=>{P.current=!1,Q.current&&(clearTimeout(Q.current),Q.current=null)}),[se]),o(()=>{if(d!=="ready"||!S)return;let i=!1,m=null,y=async()=>{try{let p=await Z("personal-assistant.session.events",{sessionId:S,cursor:ie.current});if(i)return;if(ie.current=Number(p?.cursor??ie.current)||0,h(p?.events),Array.isArray(p.turns)){te(p.turns.some(U=>["queued","running"].includes(U.status)));let T=p.turns.findLast(U=>["queued","running"].includes(U.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"},R=T?.progress?.tool;Ue(R?`${T.progress.state==="running"?"\u6B63\u5728":"\u5DF2\u5B8C\u6210"}${x[R]||(R.startsWith("cloud_browser_")?"\u64CD\u4F5C\u4E91\u7AEF\u6D4F\u89C8\u5668":"\u6267\u884C\u5DE5\u5177")}`:""),h(p.turns.filter(U=>["failed","interrupted","cancelled"].includes(U.status)).map(U=>({type:"step",id:`turn-status-${U.turnId}`,text:`\u4EFB\u52A1${U.status==="failed"?"\u5931\u8D25":"\u5DF2\u4E2D\u65AD"}\uFF1A${U.error||"\u8BF7\u68C0\u67E5\u4EFB\u52A1\u72B6\u6001\u540E\u91CD\u8BD5"}`})))}I("")}catch(p){if(!i){if(p.code==="SESSION_CURSOR_STALE"){oe(S);return}I(p.message||"\u4E91\u7AEF\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u6B63\u5728\u6062\u590D\uFF1B\u4EFB\u52A1\u4E0D\u4F1A\u6539\u5230\u672C\u673A\u6267\u884C")}}i||(m=setTimeout(y,600))};return m=setTimeout(y,200),()=>{i=!0,clearTimeout(m)}},[d,S,Z,h,oe]),o(()=>{let i=Ae.current;i&&xe.current&&(i.scrollTop=i.scrollHeight)},[$,j]);let Ke=async i=>{let m=Array.from(i.target.files||[]);i.target.value="";let y=[];for(let p of m.slice(0,4)){if(!p||p.size>512*1024){I("\u6BCF\u4E2A\u9644\u4EF6\u6700\u591A 512 KiB\uFF0C\u8BF7\u5148\u538B\u7F29\u6216\u62C6\u5206\u6587\u4EF6");continue}let T=await new Promise(x=>{let R=new FileReader;R.onload=()=>x(String(R.result||"")),R.onerror=()=>x(""),R.readAsDataURL(p)});T&&y.push({id:`${Date.now()}-${p.name}`,name:p.name,mimeType:p.type||"application/octet-stream",size:p.size,dataUrl:T})}y.length&&C(p=>[...p,...y].slice(0,4))},we=i=>{W.current=i,Le(i)},_e=()=>{Q.current&&(clearTimeout(Q.current),Q.current=null)},Te=i=>Number(i?.status)===409||/SESSION_BUSY|active turn|正忙|处理中/u.test(`${i?.code||""} ${i?.message||""}`),Pe=async(i,{restoreDraft:m=!1}={})=>{le.current.set(i.clientTurnId,i),xe.current=!0,N(!0),I(""),te(!0),b(p=>p.some(T=>T.clientTurnId===i.clientTurnId)?p.map(T=>T.clientTurnId===i.clientTurnId?{...T,status:"pending"}:T):[...p,{id:`local-user-${i.clientTurnId}`,clientTurnId:i.clientTurnId,role:"user",text:i.text,done:!1,status:"pending"}]);let y=i;try{let p=Array.isArray(y.attachments)?y.attachments:[];if(p.length===0&&Array.isArray(y.uploads)&&y.uploads.length>0){let x=[];for(let R of y.uploads)x.push(await Z("personal-assistant.file.upload",{sessionId:y.sessionId,name:R.name,dataUrl:R.dataUrl}));p=x.map(({path:R,name:U,mediaType:ee,bytes:de})=>({path:R,name:U,mediaType:ee,bytes:de})),y={...y,attachments:p,uploads:[]},le.current.set(y.clientTurnId,y)}let T=await Z("personal-assistant.turn.submit",{sessionId:y.sessionId,text:y.text,clientTurnId:y.clientTurnId,attachments:p});return P.current?(le.current.delete(y.clientTurnId),b(x=>x.map(R=>R.clientTurnId===y.clientTurnId?{...R,status:"accepted",turnId:T.turnId}:R)),{ok:!0,item:y}):{ok:!0,item:y}}catch(p){return P.current?(te(Te(p)),m&&!Te(p)&&J(T=>T||y.text),b(T=>T.map(x=>x.clientTurnId===y.clientTurnId?{...x,status:"failed",failure:p.message||"\u53D1\u9001\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u91CD\u8BD5\u5C06\u590D\u7528\u539F\u6807\u8BC6"}:x)),{ok:!1,failure:p,item:y}):{ok:!1,failure:p,item:y}}finally{P.current&&N(!1)}},fe=(i,m)=>{let y=(i.attempts||0)+1;if(le.current.delete(i.clientTurnId),b(T=>T.filter(x=>x.clientTurnId!==i.clientTurnId)),y>Kt){re(`\u6392\u961F\u6D88\u606F\u591A\u6B21\u672A\u53D1\u51FA\uFF08${m?.message||"\u4E91\u7535\u8111\u4ECD\u5FD9"}\uFF09\uFF0C\u5DF2\u653E\u56DE\u8F93\u5165\u6846\uFF0C\u8BF7\u624B\u52A8\u91CD\u8BD5`),J(T=>T||i.text);return}we([{...i,attempts:y},...W.current]);let p=(yt*Math.min(y,3)/1e3).toFixed(1);re(`\u4E91\u7535\u8111\u4ECD\u5728\u5904\u7406\u4E0A\u4E00\u8F6E\uFF0C\u6D88\u606F\u5DF2\u6392\u961F\uFF0C\u7EA6 ${p} \u79D2\u540E\u81EA\u52A8\u91CD\u53D1`),_e(),Q.current=setTimeout(()=>{Q.current=null,Ce(!0)},yt*Math.min(y,3))},Ce=async i=>{let m=X.current;if(ke.current||!P.current||pe.current!=="ready"||!m||Ne.current||!i&&F.current)return!1;let y=W.current[0];if(!y)return!1;if(y.sessionId!==m)return we([]),re("\u4F1A\u8BDD\u5DF2\u53D8\u5316\uFF0C\u6392\u961F\u6D88\u606F\u672A\u53D1\u9001"),!1;ke.current=!0,we(W.current.slice(1));try{let p=await Pe(y);return p.ok?!0:(Te(p.failure)?fe(p.item||y,p.failure):re(`\u6392\u961F\u6D88\u606F\u53D1\u9001\u5931\u8D25\uFF1A${p.failure?.message||"\u8BF7\u70B9\u51FB\u91CD\u8BD5"}`),!1)}finally{ke.current=!1}},ce=i=>{le.current.delete(i),we(W.current.filter(m=>m.clientTurnId!==i)),re("\u5DF2\u64A4\u56DE\u6392\u961F\u6D88\u606F")},Re=async(i=null)=>{if(d!=="ready"||!S)return;if(i){B||Pe(i,{restoreDraft:!0});return}let m=ae.trim()||(z.length?"\u8BF7\u67E5\u770B\u9644\u4EF6\u3002":"");if(!m)return;let y=z.map(({name:T,mimeType:x,size:R,dataUrl:U})=>({name:T,mimeType:x,size:R,dataUrl:U}));if(B||j){we([...W.current,{clientTurnId:crypto.randomUUID(),text:m,sessionId:S,uploads:y,attempts:0,queuedAt:Date.now()}]),xe.current=!0,J(""),C([]),I(""),re("");return}J(""),C([]),I(""),re("");let p=await Pe({clientTurnId:crypto.randomUUID(),text:m,sessionId:S,uploads:y,attempts:0},{restoreDraft:!0});!p.ok&&Te(p.failure)&&fe(p.item,p.failure)};o(()=>{if(d!=="ready"||!S||B||j||ne.length===0)return;let i=setTimeout(()=>{Ce(!1)},Ht);return()=>clearTimeout(i)},[d,S,B,j,ne]),o(()=>{if(ne.length===0||typeof window>"u"||typeof window.addEventListener!="function")return;let i=m=>{m.preventDefault(),m.returnValue=""};return window.addEventListener("beforeunload",i),()=>window.removeEventListener("beforeunload",i)},[ne.length]);let ze=n("header",{style:w.header},n("h1",{style:w.title},"\u4E2A\u4EBA\u52A9\u7406"),n("span",{style:w.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:w.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:{...w.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:w.page,onClick:async i=>{let m=i.target.closest?.('a[href^="cloud-file:"]');if(m){i.preventDefault();try{let y=await Z("personal-assistant.file.download",{sessionId:S,path:decodeURIComponent(m.getAttribute("href").slice(11))}),p=Uint8Array.from(atob(y.data),R=>R.charCodeAt(0)),T=URL.createObjectURL(new Blob([p],{type:"application/octet-stream"})),x=document.createElement("a");x.href=T,x.download=y.name,x.click(),setTimeout(()=>URL.revokeObjectURL(T),1e3)}catch(y){I(y.message||"\u4E91\u7AEF\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25")}}}},ze,n("style",null,"@keyframes pa-awaiting { 0%, 100% { opacity: 0.35 } 50% { opacity: 1 } }"),_&&$.length>0?n("div",{role:"alert",style:{padding:"8px 16px",background:"#fff0d6"}},_):null,n("div",{ref:Ae,"data-personal-assistant-messages":"true",style:w.scroller,onScroll:i=>{let m=i.currentTarget;xe.current=m.scrollHeight-m.clientHeight-m.scrollTop<64}},n("div",{style:w.thread},$.length===0?n("div",{style:{...w.status,paddingTop:40,textAlign:"center"}},d==="error"?n("div",{style:{...w.centeredInner,margin:"0 auto"}},n("strong",null,"\u6682\u65F6\u8FDE\u4E0D\u4E0A\u4E2A\u4EBA\u52A9\u7406"),n("span",null,_||"\u8BF7\u7A0D\u540E\u91CD\u8BD5"),n("button",{style:w.ghost,onClick:()=>{se()}},"\u91CD\u8BD5")):d==="loading"?"\u6B63\u5728\u8FDE\u63A5\u4E2A\u4EBA\u52A9\u7406\u2026":qt):null,$.map(i=>{if(i.role==="step")return n("div",{key:i.id,style:w.step},`\xB7 ${i.text}`);let m=i.role==="user";return n("div",{key:i.id,style:m?w.rowUser:w.row},n("span",{style:w.who},m?"\u4F60":"\u52A9\u7406"),n("div",{style:m?w.bubbleUser:w.bubble},m?i.text||"\u2026":gt(n,i.text||"",w)||"\u2026"),i.status==="failed"?n("button",{onClick:()=>{Re(le.current.get(i.clientTurnId))},disabled:B},`${i.failure} \xB7 \u91CD\u8BD5\u53D1\u9001`):null)}),j?n("div",{key:"awaiting",style:w.row},n("span",{style:w.who},"\u52A9\u7406"),n("div",{style:{...w.bubble,color:"var(--dsw-alias-label-secondary, #536174)"}},n("span",{style:w.pulse},tt||"\u6B63\u5728\u5904\u7406\u2026"))):null,ne.map(i=>n("div",{key:`queued-${i.clientTurnId}`,style:w.rowUser},n("span",{style:w.who},"\u4F60 \xB7 \u6392\u961F\u4E2D"),n("div",{style:w.queueBubble},`${i.text}${i.uploads?.length?`\uFF08${i.uploads.length} \u4E2A\u9644\u4EF6\u5F85\u53D1\uFF09`:""}`),n("div",{style:w.queueRow},n("span",{style:w.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:w.queueCancel,onClick:()=>ce(i.clientTurnId)},ht(n),"\u64A4\u56DE")))))),n("div",{"data-personal-assistant-composer":"true",style:w.composer},Oe?n("div",{role:"status",style:w.queueNotice},Oe):null,n("div",{style:w.composerInner},z.length>0?n("div",{style:w.attachRow},z.map(i=>n("span",{key:i.id,style:w.attach},i.mimeType.startsWith("image/")?n("img",{src:i.dataUrl,alt:"",style:w.attachThumb}):null,n("span",{style:w.attachName},i.name),n("button",{"aria-label":`\u79FB\u9664 ${i.name}`,style:{...w.iconButton,width:16,height:16,border:"none"},onClick:()=>C(m=>m.filter(y=>y.id!==i.id))},ht(n))))):null,n("textarea",{"aria-label":"\u7ED9\u4E2A\u4EBA\u52A9\u7406\u53D1\u6D88\u606F",value:ae,rows:1,style:w.textarea,placeholder:d!=="ready"?"\u4E91\u7AEF\u6682\u672A\u8FDE\u63A5\uFF0C\u53EF\u5148\u5199\u4E0B\u6D88\u606F":B||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=>J(i.target.value),onKeyDown:i=>{d==="ready"&&i.key==="Enter"&&!i.shiftKey&&!i.nativeEvent?.isComposing&&(i.preventDefault(),Re())}}),n("div",{style:w.composerBar},n("button",{"aria-label":"\u6DFB\u52A0\u9644\u4EF6",style:w.iconButton,disabled:d!=="ready"||B,title:"\u4E0A\u4F20\u5230\u4E91\u7535\u8111\uFF1A\u6700\u591A 4 \u4E2A\u6587\u4EF6\uFF0C\u6BCF\u4E2A 512 KiB",onClick:()=>L.current?.click()},Vt(n)),n("input",{ref:L,type:"file",multiple:!0,accept:"image/*,.txt,.md,.json,.pdf",style:{display:"none"},onChange:Ke}),n("span",{style:w.spacer}),ne.length>0?n("span",{role:"status",style:w.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:B||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?{...w.send,...w.sendDisabled}:B||j?w.sendQueued:w.send,onClick:()=>{Re()}},Yt(n))))))}var mt="personal-assistant-computer",Qt="personal-assistant",xt="\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",Xt=()=>Object.assign(new Error(xt),{code:"PERSONAL_ASSISTANT_NATIVE_SIDEBAR_REQUIRED"});function Gt(t){return t.workbench.render(t)}function wt({sidebarRight:t,slots:g,panelId:l=Qt}={}){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 k of[...n])k()},d=()=>{if(!c)throw Xt();if(o)throw new Error("\u4E91\u7535\u8111\u5DE5\u4F5C\u9762\u677F\u5DF2\u5173\u95ED")},v,_,I={available:c,unavailableReason:c?null:xt,subscribe:k=>(n.add(k),()=>n.delete(k)),getSnapshot:()=>r,bind(k,D){if(d(),!k?.agentId||!k?.botId||typeof D!="function")throw new Error("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u8FDE\u63A5");s&&(s.scope.agentId!==k.agentId||s.scope.botId!==k.botId)&&(v(),v=t.registerPanelSurface(l)),s=Object.freeze({scope:Object.freeze({...k}),request:D}),u(),I.open()},open(){d(),s&&t.openPanelTab(l,mt)},collapse(){d(),t.setPanelExpanded(l,!1)},dispose(){o||(o=!0,_?.(),v?.(),n.clear())}};return c&&(v=t.registerPanelSurface(l),_=g.inject("sidebar.right.panel.tab",()=>g.register({name:"sidebar.right.panel.tab",key:mt,inject:()=>({workbench:I})},Gt))),I}function It({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 Jt="__directory__";function Ge(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===Jt||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 Je(t,g=""){let l=Ge(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 et=class extends Error{constructor(){super("Personal Assistant gateway is not connected"),this.name="PersonalAssistantGatewayUnavailableError",this.code="PERSONAL_ASSISTANT_GATEWAY_UNAVAILABLE"}};var kt=Object.freeze(["slots","connection","sidebarRight"]),Ze="personal-assistant",hn=Object.freeze({enabled:!1,autoConnect:!1}),He="personal-assistant-computer",Me="2026-10-28T03:37:57.547Z",St=12e3,Ee;function At(t){Ee=t}var ue={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",vt=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",Zt=t=>Number(t?.status)===409&&["PERSONAL_ASSISTANT_DIRECTORY_UNSUPPORTED","PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE"].includes(t?.code),en={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 Tt({request:t,initialBotId:g="",openInSidebar:l=null,variant:c="page",nativeFullscreen:n=!1}={}){let s=Ee||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,[v,_]=d(null),[I,k]=d([]),[D,S]=d(""),[M,$]=d(null),[b,ae]=d(!1),[J,z]=d(g),[C,L]=d("loading"),[B,N]=d(""),[j,te]=d(!0),[tt,Ue]=d(0),[ne,Le]=d(0),[Oe,re]=d("observe"),[ie,le]=d(null),[W,ke]=d(""),[Q,Ne]=d(""),F=u(null),pe=u(null),ve=u(null),P=u(null),Ae=u(null),xe=u(null),X=u(null),Z=u(n);Z.current=n;let h=u({mounted:!0,socket:null,generation:0,frameEpoch:0,session:null,suspended:!1,resuming:!1,pendingInputs:[],display:{width:1280,height:800},readOnly:!0,botId:J,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});h.current.botId=J;let oe=async(e,a={})=>{if(typeof t!="function")throw new Error("Studio Host \u5C1A\u672A\u8FDE\u63A5");return t(e,a)},se=e=>{let a=h.current;return a.socket?.readyState!==1?!1:(a.socket.send(JSON.stringify(e)),!0)},Ke=()=>{let e=h.current;for(let a of e.pressed)F.current?.input({type:"key",action:"up",key:a});for(let a of e.buttons)F.current?.input({type:"button",action:"up",button:a});e.pressed.clear(),e.buttons.clear()},we=()=>{for(let e of h.current.buttons)F.current?.input({type:"button",action:"up",button:e});h.current.buttons.clear()};F.current||(F.current=st({send:se,changed:e=>{let a=h.current;a.controlPhase=e.phase,a.readOnly=e.readOnly,a.controlEpoch=e.controlEpoch,e.readOnly&&X.current&&(X.current.style.visibility="hidden"),e.phase==="observe"&&(a.pressed.clear(),a.buttons.clear()),a.mounted&&(te(e.readOnly),re(e.phase))},failed:e=>{h.current.mounted&&N(e)}})),pe.current||(pe.current=it({send:se,controlEpoch:()=>F.current?.snapshot?.controlEpoch}));let _e=()=>{Ke(),F.current.release(),h.current.pressed.clear(),h.current.buttons.clear()},Te=()=>{let e=h.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)&&(F.current.input({type:"pointermove",...a}),e.sentPointer=a)},Pe=()=>{clearTimeout(h.current.reconnect),clearTimeout(h.current.firstFrame),h.current.reconnect=null,h.current.firstFrame=null},fe=(e=!0)=>{let a=h.current;a.reconnectAllowed=!1,Pe(),_e(),a.generation+=1,pe.current?.rejectAll();try{se({type:"close"}),a.socket?.close(1e3,"panel closed")}catch{}F.current.reset({readOnly:!0}),a.lastDrawnFrame=null,a.socket=null,a.session=null,a.pendingFrame=null,a.frameMetadata=null,a.readOnly=!0,Ae.current?.blur(),a.suspended=!1,a.resuming=!1,a.pendingInputs=[],a.frameEpoch++,e&&a.mounted&&(L(a.config?.configured?"idle":"unconfigured"),te(!0))},Ce=e=>{fe(!1),te(!0),L("closed"),N(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")},ce=e=>{let a=h.current;if(e.type!=="pointermove"&&Te(),a.suspended||a.resuming){if(e.type==="pointermove")return!1;let E=a.mode==="control";if(E){if(a.pendingInputs.length>=32)return fe(),N("\u6062\u590D\u671F\u95F4\u8F93\u5165\u8FC7\u5FEB\uFF0C\u8BF7\u91CD\u65B0\u8FDE\u63A5"),!1;a.pendingInputs.push(e)}return a.resuming||T(),E}return!a.session||a.socket?.readyState!==1?(N("\u4E91\u7535\u8111\u5C1A\u672A\u8FDE\u63A5\uFF0C\u8F93\u5165\u672A\u53D1\u9001"),!1):F.current.input(e)},Re=e=>{h.current.mounted&&(Ne(e),ve.current&&clearTimeout(ve.current),ve.current=setTimeout(()=>{h.current.mounted&&Ne("")},4e3))},ze=e=>{let a=!1;for(let E of e)a=ce(E)||a;return a},i=async()=>{let e=/Mac|iPhone|iPad/u.test(String(globalThis.navigator?.platform||""))?"Meta":"Control";if(!h.current.pressed.has("_copyShortcut")){h.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(a=>setTimeout(a,150))}finally{h.current.pressed.delete("_copyShortcut")}}return ut({readCloud:()=>pe.current.read(),notify:Re})},m=()=>dt({readLocal:()=>Qe(),writeCloud:e=>pe.current.write(e),sendKeys:ze,notify:Re}),y=async()=>{let e=h.current;if(!e.decoding){e.decoding=!0;try{for(;e.pendingFrame;){let a=e.pendingFrame;e.pendingFrame=null;let E;try{if(E=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||!P.current)continue;e.lastDrawnFrame=a;let f=P.current,K=f.getBoundingClientRect(),G=Math.max(1,globalThis.devicePixelRatio||1);f.width=Math.max(1,Math.round(K.width*G)),f.height=Math.max(1,Math.round(K.height*G));let q=f.getContext("2d"),Y=e.display,Se=Math.min(f.width/Y.width,f.height/Y.height),he=Y.width*Se,A=Y.height*Se;q.clearRect(0,0,f.width,f.height),q.drawImage(E,(f.width-he)/2,(f.height-A)/2,he,A);let be=e.firstFrame!==null;e.frames+=1,clearTimeout(e.firstFrame),e.firstFrame=null,e.retries=0,be&&N(""),L(e.readOnly?"readonly":"ready"),Ue(0)}catch{e.mounted&&N("\u684C\u9762\u5E27\u65E0\u6CD5\u89E3\u7801\uFF0C\u8BF7\u91CD\u8BD5")}finally{E?.close()}}}finally{e.decoding=!1}}},p=e=>{let a=h.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,Le(0),te(!0),L("dormant"),N(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")},T=()=>{let e=h.current;if(e.resuming||!e.suspended)return;if(e.socket?.readyState!==1){x(e.mode,!1,e.pendingInputs);return}e.resuming=!0,L("resuming"),N("\u6B63\u5728\u6062\u590D\u684C\u9762\u5E76\u68C0\u67E5\u63A7\u5236\u6743\uFF0C\u8BF7\u7A0D\u5019\u3002"),se({type:"resume",mode:e.mode,activity:!0});let a=e.generation,E=e.socket;e.firstFrame=setTimeout(()=>{e.mounted&&e.generation===a&&e.firstFrame!==null&&E.close(4e3,"resume frame timeout")},St)},x=async(e="read",a=!1,E=[])=>{let f=h.current,K=String(f.botId||"").trim();if(!f.config?.configured){L("unconfigured");return}if(!K||!f.bots?.some(q=>q.botId===K)){N("\u4E91\u7AEF\u52A9\u7406\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");return}fe(!1),f.pendingInputs=E,f.resuming=E.length>0;let G=++f.generation;f.reconnectAllowed=!0,a||(f.retries=0),f.mode=e,f.taskId||=`studio-desktop-${globalThis.crypto.randomUUID()}`,f.receivedSeq=-1,f.frameMetadata=null,L(a?"reconnecting":"connecting"),N("\u9996\u6B21\u6216\u4F11\u7720\u540E\u8FDE\u63A5\u53EF\u80FD\u9700\u8981\u6570\u79D2\uFF0C\u8BF7\u7A0D\u5019\u3002");try{let q=await oe("personal-assistant.desktop.ticket",{agentId:f.config.agentId,botId:K,mode:e==="observe"?"control":e});if(!f.mounted||G!==f.generation)return;let Y=new WebSocket(q.wsUrl,["agentkit.personal-assistant.desktop.v1",`agentkit.desktop.ticket.${q.ticket}`]);Y.binaryType="arraybuffer",f.socket=Y;let Se=()=>f.mounted&&f.generation===G;Y.onopen=()=>{if(!Se()){Y.close();return}se({type:"open",botId:K,taskId:f.taskId,mode:e,...q.leaseId?{leaseId:q.leaseId}:{}}),f.firstFrame=setTimeout(()=>{Se()&&(N("\u4E91\u7535\u8111\u54CD\u5E94\u8F83\u6162\uFF0C\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5"),Y.close(4e3,"first frame timeout"))},St)},Y.onmessage=he=>{if(!Se())return;if(typeof he.data!="string"){let be=f.frameMetadata;f.frameMetadata=null;let De=he.data;if(!be||!Number.isSafeInteger(be.seq)||be.seq<=f.receivedSeq||!(De instanceof ArrayBuffer)||De.byteLength===0||De.byteLength>307200||f.suspended)return;f.receivedSeq=be.seq,f.pendingFrame={bytes:De,seq:be.seq,generation:G,frameEpoch:f.frameEpoch},y();return}let A;try{A=JSON.parse(he.data)}catch{return}if(A.type==="ready"){f.suspended=!1,f.resuming=!1,f.receivedSeq=-1,f.session=A.sessionId,f.readOnly=!!A.readOnly,f.display=Ve(A.display),f.mode=e,F.current.reset(A);let be=f.pendingInputs;if(f.pendingInputs=[],f.readOnly)f.pressed.clear(),f.buttons.clear();else for(let De of be)F.current.input(De);te(f.readOnly),N("\u4E91\u7535\u8111\u5DF2\u8FDE\u63A5\uFF0C\u6B63\u5728\u51C6\u5907\u684C\u9762\u753B\u9762");return}if(A.type==="control"){F.current.accept(A),N("");return}if(A.type==="idle"){p(A);return}if(A.type==="frame"){A.unchanged||(f.frameMetadata=A);return}if(A.type==="clipboard.response"){pe.current?.accept(A);return}if(A.type==="closed"){A.retryable!==!0&&Ce(A);return}if(A.type==="error"){if(Number.isSafeInteger(A.controlEpoch)&&A.controlEpoch<f.controlEpoch)return;if(N(A.message||A.code||"\u4E91\u7535\u8111\u8BF7\u6C42\u5931\u8D25"),f.handoffSupported&&A.recoverable===!0){F.current.reject(A);return}if(A.recoverable===!0&&Number(A.status)===409){A.code==="DESKTOP_SESSION_IDLE"?p():(f.pendingInputs=[],f.readOnly=!0,f.pressed.clear(),f.buttons.clear(),te(!0),L("readonly"));return}if(Number(A.status)===409&&e==="control"&&!f.session){x(h.current.handoffSupported?"observe":"read");return}[404,409].includes(Number(A.status))||A.code==="DESKTOP_SESSION_NOT_FOUND"?Ce(A):f.session||(L("error"),fe(!1))}},Y.onerror=()=>{Se()&&N("\u684C\u9762\u901A\u9053\u6682\u65F6\u65AD\u5F00\uFF0C\u6B63\u5728\u91CD\u8FDE")},Y.onclose=he=>{if(!Se())return;if(f.suspended&&he.code!==1e3){clearTimeout(f.firstFrame),f.firstFrame=null,f.socket=null,L("dormant");return}if(f.session=null,clearTimeout(f.firstFrame),f.firstFrame=null,!f.reconnectAllowed||he.code===1e3){Ce();return}if(document.hidden){L("hidden");return}let A=++f.retries;if(Ue(A),A>5){f.reconnectAllowed=!1,L("error"),N("\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7535\u8111\uFF0C\u8BF7\u68C0\u67E5\u5B9E\u4F8B\u72B6\u6001\u6216\u7F51\u7EDC\u540E\u91CD\u8BD5");return}L("reconnecting"),f.reconnect=setTimeout(()=>{x(e,!0,f.pendingInputs)},Math.min(8e3,1e3*2**(A-1)))}}catch(q){f.mounted&&G===f.generation&&(L("error"),N(vt(q)))}},R=async e=>{if(e?.aborted)return null;try{let a=await oe("personal-assistant.desktop.status");return a&&typeof a=="object"?a:null}catch(a){return a?.code==="PERSONAL_ASSISTANT_OPERATION_UNAVAILABLE"||a?.status===404?null:{configured:!1,reason:"unavailable",detail:Et(a),candidates:[]}}},U=async e=>{if(!W){ke(e),N(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 oe(`personal-assistant.desktop.${e}`),N(""),await ee()}catch(a){N(Et(a)),le(await R().catch(()=>null))}finally{ke("")}}},ee=async(e,a=!1)=>{fe(!1),L("loading"),N(""),S(""),$(null);try{let E=await oe("personal-assistant.configuration");if(e?.aborted||!h.current.mounted)return;if(h.current.config=E,_(E),!E.configured){let q=await R(e);if(e?.aborted||!h.current.mounted)return;if(h.current.bots=[],k([]),z(""),le(q),L("unconfigured"),q?.configured&&!a){await ee(e,!0);return}return}le(null);let f=await oe("personal-assistant.bots.list");if(e?.aborted||!h.current.mounted)return;if(f.directoryAvailable!==!0)throw Object.assign(new Error("directory unavailable"),{code:"PERSONAL_ASSISTANT_DIRECTORY_UNAVAILABLE",status:409});let K=Ge(f.bots);h.current.bots=K,h.current.handoffSupported=f.features?.includes("desktop-handoff/v1")===!0,k(K);let G=K.length?Je(K,g||E.botId):"";h.current.botId=G,z(G),L(K.length?"idle":"empty"),G&&["computer","native-tab"].includes(c)&&x(h.current.handoffSupported?"observe":"read")}catch(E){if(e?.aborted||!h.current.mounted)return;Number.isInteger(E?.closeCode)&&E.closeCode>=1e3&&E.closeCode<=4999&&$(E.closeCode),h.current.bots=[],k([]),z(""),L("directory-error"),S(Zt(E)?"\u4E91\u7AEF\u52A9\u7406\u9700\u8981\u66F4\u65B0\uFF0C\u8BF7\u66F4\u65B0\u540E\u91CD\u65B0\u8FDE\u63A5\u3002":vt(E))}};r(()=>{let e=h.current;e.mounted=!0;let a=new AbortController;ee(a.signal);let E=setInterval(()=>{e.mounted&&Le(e.frames),e.frames=0},1e3),f=()=>{document.hidden?(_e(),se({type:"pause"})):e.socket?.readyState===1?se({type:"resume"}):e.reconnectAllowed&&e.config?.configured&&e.session===null&&e.socket&&x(e.mode,!0)},K=typeof ResizeObserver=="function"?new ResizeObserver(()=>{e.lastDrawnFrame&&(e.pendingFrame=e.lastDrawnFrame,y())}):null;P.current&&K?.observe(P.current);let G=()=>_e(),q=Y=>{xe.current?.contains(Y.target)||_e()};return document.addEventListener("visibilitychange",f),window.addEventListener("blur",G),document.addEventListener("pointerdown",q,!0),()=>{e.mounted=!1,K?.disconnect(),e.pointerFrame&&cancelAnimationFrame(e.pointerFrame),a.abort(),fe(!1),clearInterval(E),document.removeEventListener("visibilitychange",f),window.removeEventListener("blur",G),document.removeEventListener("pointerdown",q,!0)}},[t]);let de=e=>ot({clientX:e.clientX,clientY:e.clientY,rect:P.current.getBoundingClientRect(),display:h.current.display}),Be=e=>{e.preventDefault();let a=h.current,E=[1,2,3][e.button]||1;e.type==="pointerdown"?(Ae.current?.focus(),P.current?.setPointerCapture(e.pointerId),ce({type:"button",action:"down",button:E,...de(e)})&&a.buttons.add(E)):(ce({type:"button",action:"up",button:E,...de(e)}),a.buttons.delete(E),P.current?.hasPointerCapture(e.pointerId)&&P.current.releasePointerCapture(e.pointerId))},$e=e=>{if(h.current.composition||e.isComposing||e.nativeEvent?.isComposing||e.key==="Process"||e.key==="Unidentified")return;if(lt(e)){e.preventDefault(),m();return}if(ct(e)){e.preventDefault(),e.type==="keydown"&&!e.repeat&&i();return}let a=e.ctrlKey||e.metaKey||e.altKey;if(e.key.length===1&&!a||e.key==="Escape"&&Z.current)return;e.preventDefault();let E=en[e.key]||e.key;/^[A-Za-z0-9_]+$/u.test(E)&&(e.type==="keydown"?!e.repeat&&ce({type:"key",action:"down",key:E})&&h.current.pressed.add(E):(ce({type:"key",action:"up",key:E}),h.current.pressed.delete(E)))},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"}[C],ge={...ue,borderRadius:6,padding:"7px 12px",cursor:"pointer",font:"inherit"},H=["ready","readonly","hidden","reconnecting","dormant","resuming"].includes(C),Ie=I.length>0,ye=ie?.reason||"",Ct=Array.isArray(ie?.candidates)?ie.candidates.length:0,Rt=ye==="needs-create"?"\u8FD8\u6CA1\u6709\u521B\u5EFA\u4E2A\u4EBA\u52A9\u7406":ye==="credential-unavailable"?"\u6B63\u5728\u6062\u590D\u4E2A\u4EBA\u52A9\u7406\u7684\u8FDE\u63A5\u51ED\u8BC1":ye==="unavailable"?"\u6682\u65F6\u65E0\u6CD5\u81EA\u52A8\u8FDE\u63A5\u4E2A\u4EBA\u52A9\u7406":"\u4E2A\u4EBA\u52A9\u7406\u5C1A\u672A\u5F00\u901A",Dt=ye==="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":ye==="credential-unavailable"?"\u4E91\u7AEF\u6682\u65F6\u6CA1\u6709\u8FD4\u56DE\u8FDE\u63A5\u51ED\u8BC1\uFF0C\u53EF\u4EE5\u91CD\u65B0\u83B7\u53D6\u3002":ye==="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=C==="unconfigured"?Rt:C==="empty"?"\u52A9\u7406\u6B63\u5728\u51C6\u5907\u4E2D":C==="directory-error"?"\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7AEF\u52A9\u7406":"\u6B63\u5728\u68C0\u67E5\u52A9\u7406\u72B6\u6001",Ot=C==="unconfigured"?Dt:C==="empty"?"\u4E91\u7AEF\u521D\u59CB\u5316\u5B8C\u6210\u540E\uFF0C\u53EF\u7528\u52A9\u7406\u4F1A\u663E\u793A\u5728\u8FD9\u91CC\u3002":C==="directory-error"?D:"\u8BF7\u7A0D\u5019",je=c==="computer"||c==="native-tab",nt=o("div",{ref:xe,"data-personal-assistant-desktop-card":je?"true":void 0,style:{position:"relative",background:"var(--dsw-alias-bg-layer-2, #f1f3f6)",...je?{width:"100%",aspectRatio:`${h.current.display.width} / ${h.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(C)?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)"}},C==="dormant"?"\u5DF2\u7A7A\u95F2\uFF0C\u64CD\u4F5C\u684C\u9762\u5373\u53EF\u6062\u590D":"\u6B63\u5728\u6062\u590D\u684C\u9762\u2026"):null,o("canvas",{ref:P,"aria-label":"\u4E91\u7535\u8111\u684C\u9762",tabIndex:H?0:-1,onPointerDown:Be,onPointerUp:Be,onPointerCancel:we,onLostPointerCapture:we,onPointerLeave:()=>{X.current&&(X.current.style.visibility="hidden")},onPointerMove:e=>{let a=h.current,E=e.nativeEvent?.getCoalescedEvents?.().at(-1)||e;if(X.current){let f=P.current.getBoundingClientRect();X.current.style.transform=`translate(${E.clientX-f.left}px, ${E.clientY-f.top}px)`,X.current.style.visibility=a.readOnly?"hidden":"visible"}a.lastPointer=de(E),a.pointerFrame||(a.pointerFrame=requestAnimationFrame(()=>{a.mounted&&Te()}))},onContextMenu:e=>e.preventDefault(),onWheel:e=>{e.preventDefault(),ce({type:"wheel",deltaY:e.deltaY/100,deltaX:e.deltaX/100})},onKeyDown:$e,onKeyUp:$e,style:{...je?{position:"absolute",inset:0}:{},width:"100%",height:"100%",display:"block",visibility:H?"visible":"hidden",pointerEvents:H?"auto":"none",touchAction:"none",cursor:j?"default":"none"}}),o("div",{ref:X,"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}))),H?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}},Ie?Ye:Lt),o("p",{style:{margin:0,maxWidth:380,lineHeight:1.7,color:"var(--dsw-alias-label-secondary, #536174)"}},Ie?B||"\u8FDE\u63A5\u540E\u5373\u53EF\u4F7F\u7528\u4E91\u7AEF\u684C\u9762\uFF0C\u5173\u95ED\u9762\u677F\u4F1A\u91CA\u653E\u672C\u6B21\u63A7\u5236\u3002":Ot),!Ie&&C!=="loading"?o("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",alignItems:"center"}},C==="unconfigured"&&ye==="needs-create"?o("button",{style:ge,disabled:!!W,onClick:()=>{U("create")}},W==="create"?"\u6B63\u5728\u521B\u5EFA\u2026":"\u521B\u5EFA\u4E2A\u4EBA\u52A9\u7406"):null,C==="unconfigured"&&(ye==="credential-unavailable"||Ct>0)?o("button",{style:ge,disabled:!!W,onClick:()=>{U("connect")}},W==="connect"?"\u6B63\u5728\u83B7\u53D6\u2026":ye==="credential-unavailable"?"\u91CD\u65B0\u83B7\u53D6\u8FDE\u63A5\u51ED\u8BC1":"\u8FDE\u63A5\u5DF2\u53D1\u73B0\u7684\u4E2A\u4EBA\u52A9\u7406"):null,o("button",{style:{...ge,background:"transparent"},disabled:!!W,onClick:()=>{ee()}},"\u68C0\u67E5\u5F00\u901A\u72B6\u6001"),W?o("span",{role:"status",style:{color:"var(--dsw-alias-label-secondary, #536174)",fontSize:12}},"\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019\u2026"):null):null),o("input",{ref:Ae,"aria-label":"\u4E91\u7535\u8111\u6587\u672C\u8F93\u5165",autoComplete:"off",disabled:!H||j&&!F.current.snapshot.available&&!(h.current.mode==="control"&&["dormant","resuming"].includes(C)),tabIndex:-1,style:{position:"absolute",width:1,height:1,opacity:0,left:0,top:0},onKeyDown:$e,onKeyUp:$e,onCompositionStart:()=>{h.current.composition=!0},onCompositionEnd:e=>{h.current.composition=!1;let a=e.currentTarget.value;e.currentTarget.value="",a&&ce({type:"text",text:a})},onInput:e=>{if(h.current.composition||e.nativeEvent?.isComposing)return;let a=e.currentTarget.value;e.currentTarget.value="",a&&ce({type:"text",text:a})}})),Fe="var(--dsw-alias-label-secondary, #536174)",an={...ge,background:"transparent",color:"inherit",border:ue.border},rt={...ge,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 je?o("section",{"data-personal-assistant-computer":"true",style:{...ue,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:ue.border}},o("strong",{style:{fontWeight:500}},"\u4E91\u7535\u8111"),o("span",{role:"status","aria-live":"polite",style:{color:Fe,fontSize:12}},Ye),null):null,j&&H&&!F.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"}},nt,H||Ie?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:ue.border,boxShadow:"0 1px 4px #10182808",lineHeight:1.5}},!H&&Ie?o("button",{style:rt,disabled:["connecting","resuming"].includes(C),onClick:()=>{x(h.current.handoffSupported?"observe":"read")}},C==="connecting"?"\u6B63\u5728\u542F\u52A8\u2026":"\u91CD\u65B0\u8FDE\u63A5"):null,H&&j?o("span",{style:{color:Fe,fontSize:12}},Oe==="acquiring"?"\u6B63\u5728\u63A5\u7BA1\u2026":Oe==="releasing"?"\u6B63\u5728\u4EA4\u8FD8\u2026":"\u52A9\u7406\u6B63\u5728\u4F7F\u7528 \xB7 \u70B9\u753B\u9762\u5373\u53EF\u63A5\u7BA1"):null,H&&j&&F.current.snapshot.available?o("button",{style:{...rt,padding:"3px 9px",fontSize:11},onClick:()=>F.current.acquire()},"\u63A5\u7BA1"):null,H&&!j?o("span",{style:{color:Fe,fontSize:12}},"\u60A8\u62E5\u6709\u63A7\u5236\u6743 \xB7 \u70B9\u753B\u9762\u5916\u91CA\u653E"):null,H&&B?o("span",{style:{color:Fe,fontSize:12}},B):null,H&&Q?o("span",{role:"status","aria-live":"polite",style:{color:Fe,fontSize:12}},Q):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":Me},`\u6784\u5EFA ${Me}`)))):o("section",{"data-personal-assistant-panel":"true",style:{...ue,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:ue.border}},o("strong",{style:{fontWeight:500,marginRight:8}},"\u4E2A\u4EBA\u52A9\u7406"),Ie&&["idle","closed","error"].includes(C)?o("button",{style:ge,onClick:()=>{ee()}},"\u5237\u65B0\u52A9\u7406\u5217\u8868"):null,typeof l=="function"?o("button",{style:ge,onClick:l},"\u653E\u5230\u53F3\u4FA7\u680F"):null,Ie?o("button",{style:ge,disabled:["connecting","resuming"].includes(C),onClick:()=>C==="dormant"?T():void x(h.current.handoffSupported?"observe":"control")},C==="dormant"?"\u6062\u590D\u753B\u9762":j&&C==="readonly"?"\u7533\u8BF7\u63A7\u5236":H?"\u91CD\u65B0\u8FDE\u63A5":"\u8FDE\u63A5\u4E91\u7535\u8111"):null,Ie?o("button",{style:ge,disabled:C==="connecting",onClick:()=>{x("read")}},"\u53EA\u8BFB\u65C1\u89C2"):null,H?o("span",{role:"status","aria-live":"polite",style:{marginLeft:"auto",color:"var(--dsw-alias-label-secondary, #536174)"}},Ye):null),C==="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,H&&B?o("div",{role:"status",style:{padding:"8px 12px"}},B):null,nt,o("footer",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:12,padding:"7px 12px",color:"var(--dsw-alias-label-secondary, #536174)",borderTop:ue.border}},o("details",{open:b,onToggle:e=>ae(e.currentTarget.open)},o("summary",{style:{cursor:"pointer"}},"\u8BCA\u65AD"),M?o("div",{style:{paddingTop:8}},`\u76EE\u5F55\u8FDE\u63A5\u5173\u95ED\u7801\uFF1A${M}`):null,o("div",{style:{paddingTop:8,lineHeight:1.8,overflowWrap:"anywhere"}},o("div",null,`\u4E91\u7AEF\u5B9E\u4F8B\uFF1A${v?.agentId||"\u672A\u5F00\u901A"}`),o("div",null,`\u8FDE\u63A5\u6807\u8BC6\uFF1A${J||"\u672A\u8FDE\u63A5"}`),o("div",null,`\u753B\u9762\u5E27\u7387\uFF1A${ne} 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":Me,style:{opacity:.75}},`\u6784\u5EFA ${Me}`)))}function tn({request:t,nativeWorkbench:g}={}){let l=Ee||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,v]=s(""),[_,I]=s(0);n(()=>{let D=!1;return u(null),v(""),(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 M=await t("personal-assistant.bots.list");if(M.directoryAvailable!==!0)throw new Error("\u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u4E91\u7AEF\u52A9\u7406\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");let $=Je(M.bots,S.botId||M.primaryBotId);D||u({agentId:S.agentId,botId:$})}catch(S){D||v(S.message||"\u4E91\u7AEF\u52A9\u7406\u6682\u4E0D\u53EF\u7528")}})(),()=>{D=!0}},[t,_]);let k=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,k):r&&v(g?.unavailableReason||"\u5F53\u524D\u5BBF\u4E3B\u9700\u8981\u66F4\u65B0\u539F\u751F\u4FA7\u680F\u7EC4\u4EF6")},[g,k,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(bt,{React:l,request:k,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:()=>I(D=>D+1)},"\u91CD\u65B0\u8FDE\u63A5"):null)}var O={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:ue.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:{...ue,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 nn({request:t,openComputer:g=null}={}){let l=Ee||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,v]=s(null),[_,I]=s(""),[k,D]=s(!1),[S,M]=s(""),$=o(async()=>{D(!0),I("");let C=Date.now();try{let L=await t("personal-assistant.configuration");if(u(L),L?.configured){let B=await t("personal-assistant.bots.list");v(Array.isArray(B?.bots)?B.bots:[])}else v([]);M(`${new Date().toLocaleTimeString("zh-CN",{hour12:!1})} \xB7 ${Date.now()-C} ms`)}catch(L){I(L?.message||"\u8FDE\u63A5\u68C0\u67E5\u5931\u8D25"),M(`${new Date().toLocaleTimeString("zh-CN",{hour12:!1})} \xB7 \u5931\u8D25`)}finally{D(!1)}},[t]);n(()=>{$()},[$]);let b=r?.configured===!0,ae=r===null?"\u68C0\u67E5\u4E2D":b?"\u5DF2\u5F00\u901A":"\u5C1A\u672A\u5F00\u901A",J={...O.badge,...r===null?O.badgeIdle:b?O.badgeOk:O.badgeIdle},z=(C,L,B=!1)=>c("div",{style:B?O.rowFirst:O.row},c("div",{style:O.label},C),c("div",{style:O.value},L));return c("section",{"data-personal-assistant-settings":"true",style:O.page},c("div",null,c("h1",{style:O.title},"\u4E2A\u4EBA\u52A9\u7406"),c("p",{style:{...O.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")),_?c("div",{role:"alert",style:{...O.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"}},_):null,c("div",{style:O.card},z("\u72B6\u6001",c("span",null,c("span",{style:J},ae),S?c("span",{style:O.note},`\u3000\u4E0A\u6B21\u68C0\u67E5 ${S}`):null),!0),z("\u4E91\u7AEF\u5B9E\u4F8B",r?.agentId?c("span",{style:O.mono},r.agentId):c("span",{style:O.note},b?"\u672A\u8FD4\u56DE\u5B9E\u4F8B\u6807\u8BC6":"\u5F00\u901A\u540E\u7531 Studio \u7ED1\u5B9A")),z("\u7F51\u5173",r?.gatewayUrl?c("span",{style:O.mono},r.gatewayUrl):c("span",{style:O.note},"\u7531 Studio Host \u914D\u7F6E")),z("\u52A9\u7406\u8FDE\u63A5",c("span",{style:O.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:O.mono},"/workspace/assistant-state"),c("div",{style:O.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:O.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:O.note},`\u6784\u5EFA ${Me}`))),c("div",{style:O.actions},c("button",{style:O.button,disabled:k,onClick:()=>{$()}},k?"\u6B63\u5728\u68C0\u67E5\u2026":"\u68C0\u67E5\u8FDE\u63A5"),c("span",{style:O.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 rn({size:t}={}){let g=Ee,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 on({size:t}={}){let g=Ee,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 sn(){let t=Ee,g=on({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(s,o={})=>{if(!t.connection?.rpc?.call)throw new et;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=wt({sidebarRight:t.sidebarRight,slots:t.slots});c&&(c.render=s=>It({...s,React:Ee||globalThis.React,workbench:c,Panel:Tt}),l(()=>()=>c.dispose(),"personal-assistant: native workbench")),l(()=>t.slots.inject("main",()=>t.slots.register({name:"main",key:Ze,inject:()=>({request:g,nativeWorkbench:c})},tn)),"personal-assistant: main panel"),l(()=>t.slots.inject("sidebar.panellist",()=>t.slots.register({name:"sidebar.panellist",id:Ze,order:90,label:"\u4E2A\u4EBA\u52A9\u7406"},rn)),"personal-assistant: sidebar row"),l(()=>t.slots.inject("settings.section",()=>t.slots.register({name:"settings.section",id:`${Ze}-settings`,order:196,label:"\u4E2A\u4EBA\u52A9\u7406",inject:()=>({request:g})},nn)),"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:He,kind:He,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:He,inject:()=>({request:g})},d=>Tt({...d,variant:"computer"})))),r(s.slots.inject("sidebar.right.pane.tab.title",()=>s.slots.register({name:"sidebar.right.pane.tab.title",key:He},sn)))}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=>(At(t("react")),{name:"agentkit-personal-assistant",inject:kt,apply:_t})});})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-personal-assistant",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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": {
|
package/src/client/index.mjs
CHANGED
|
@@ -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
|
-
|
|
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) {
|
|
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
|
|
416
|
-
const
|
|
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('
|
|
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 };
|
package/src/host-gateway.mjs
CHANGED
|
@@ -32,7 +32,23 @@ const SESSION_OPERATIONS = Object.freeze([
|
|
|
32
32
|
'personal-assistant.file.upload',
|
|
33
33
|
'personal-assistant.file.download',
|
|
34
34
|
]);
|
|
35
|
-
const
|
|
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
|
+
]);
|
|
44
|
+
const BINDING_METHODS = Object.freeze({
|
|
45
|
+
'personal-assistant.desktop.status': 'status',
|
|
46
|
+
'personal-assistant.desktop.connect': 'connect',
|
|
47
|
+
'personal-assistant.desktop.create': 'create',
|
|
48
|
+
'personal-assistant.desktop.disconnect': 'disconnect',
|
|
49
|
+
});
|
|
50
|
+
const AGENT_ID = /^ar-[A-Za-z0-9-]{4,120}$/u;
|
|
51
|
+
const OPERATIONS = new Set(['personal-assistant.configuration', 'personal-assistant.bots.list', 'personal-assistant.desktop.ticket', ...BINDING_OPERATIONS, ...SESSION_OPERATIONS]);
|
|
36
52
|
const fail = (code, message, status = 400) => Object.assign(new Error(message), { code, status });
|
|
37
53
|
const plain = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
38
54
|
const safeCloseCode = value => Number.isInteger(value) && value >= 1000 && value <= 4999 ? value : undefined;
|
|
@@ -107,10 +123,47 @@ export function createPersonalAssistantHostGateway(config = {}, { env = process.
|
|
|
107
123
|
issueTicket: (scope, signal) => request('personal-assistant.desktop.ticket', scope, signal),
|
|
108
124
|
WebSocketImpl, ca: trustedCAs(),
|
|
109
125
|
});
|
|
126
|
+
function publicBindingStatus(value) {
|
|
127
|
+
if (!plain(value) || typeof value.configured !== 'boolean') throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 返回的绑定状态无效', 502);
|
|
128
|
+
const reason = typeof value.reason === 'string' ? value.reason.slice(0, 80) : '';
|
|
129
|
+
const candidates = Array.isArray(value.candidates) ? value.candidates.filter(row => plain(row) && typeof row.agentId === 'string' && AGENT_ID.test(row.agentId))
|
|
130
|
+
.slice(0, 20).map(row => ({ agentId: row.agentId, name: typeof row.name === 'string' ? row.name.slice(0, 80) : '',
|
|
131
|
+
status: typeof row.status === 'string' ? row.status.slice(0, 32) : '', createdAt: typeof row.createdAt === 'string' ? row.createdAt.slice(0, 40) : '' })) : [];
|
|
132
|
+
// The credential never reaches the page; only the public binding shape does.
|
|
133
|
+
return { configured: value.configured, agentId: value.configured && typeof value.agentId === 'string' ? value.agentId : undefined,
|
|
134
|
+
mode: 'studio', reason, candidates };
|
|
135
|
+
}
|
|
136
|
+
function publicBinding(value) {
|
|
137
|
+
if (!plain(value) || typeof value.configured !== 'boolean' || (value.configured && (typeof value.agentId !== 'string' || !AGENT_ID.test(value.agentId))))
|
|
138
|
+
throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', 'Studio 返回的绑定结果无效', 502);
|
|
139
|
+
return { configured: value.configured, agentId: value.configured ? value.agentId : undefined, mode: 'studio' };
|
|
140
|
+
}
|
|
110
141
|
async function request(operation, payload = {}, signal) {
|
|
111
142
|
if (!plain(payload)) throw fail('PERSONAL_ASSISTANT_REQUEST_INVALID', '请求参数格式错误');
|
|
112
143
|
if (!OPERATIONS.has(operation)) throw fail('PERSONAL_ASSISTANT_OPERATION_UNAVAILABLE', '当前面板不支持此操作', 404);
|
|
113
144
|
const current = await binding(signal);
|
|
145
|
+
const bindingMethod = BINDING_METHODS[operation];
|
|
146
|
+
if (bindingMethod) {
|
|
147
|
+
if (payload.agentId !== undefined && operation !== 'personal-assistant.desktop.create') {
|
|
148
|
+
if (typeof payload.agentId !== 'string' || !AGENT_ID.test(payload.agentId)) throw fail('PERSONAL_ASSISTANT_AGENT_INVALID', '云端实例标识无效');
|
|
149
|
+
}
|
|
150
|
+
const studio = current.studio;
|
|
151
|
+
if (!studio) throw fail('PERSONAL_ASSISTANT_STANDALONE', '独立安装不支持自动发现;请在 Host 配置中连接云端实例', 409);
|
|
152
|
+
if (typeof studio[bindingMethod] !== 'function') throw fail('PERSONAL_ASSISTANT_STUDIO_UNAVAILABLE', '请更新 Studio 云连接服务', 503);
|
|
153
|
+
const created = operation === 'personal-assistant.desktop.create';
|
|
154
|
+
const scoped = created ? AbortSignal.timeout(360_000) : AbortSignal.timeout(15_000);
|
|
155
|
+
const deadline = signal ? AbortSignal.any([signal, scoped]) : scoped;
|
|
156
|
+
const input = !created && operation !== 'personal-assistant.desktop.status' && operation !== 'personal-assistant.desktop.disconnect' && payload.agentId
|
|
157
|
+
? { agentId: String(payload.agentId) } : {};
|
|
158
|
+
let value;
|
|
159
|
+
try { value = await studio[bindingMethod](input, deadline); }
|
|
160
|
+
catch (error) {
|
|
161
|
+
const status = Number.isInteger(error?.status) && error.status >= 400 && error.status <= 599 ? error.status : 503;
|
|
162
|
+
throw fail(error?.code || 'PERSONAL_ASSISTANT_BINDING_FAILED', String(error?.message || '个人助理连接失败').slice(0, 240), status);
|
|
163
|
+
}
|
|
164
|
+
if (bindingMethod === 'status') return publicBindingStatus(value);
|
|
165
|
+
return publicBinding(value);
|
|
166
|
+
}
|
|
114
167
|
if (operation === 'personal-assistant.configuration') return {
|
|
115
168
|
configured: current.configured, ...(current.configured ? { agentId: current.agentId } : {}),
|
|
116
169
|
...(base ? { gatewayUrl: base.origin } : {}),
|