dsh-duet 0.1.10 → 0.2.0

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.
Files changed (64) hide show
  1. package/README.md +19 -1
  2. package/assets/avatar/THREE-LICENSE.txt +21 -0
  3. package/assets/avatar/character.glb +0 -0
  4. package/assets/avatar/desktop/character.glb +0 -0
  5. package/assets/avatar/desktop/companion.mjs +18 -0
  6. package/assets/avatar/desktop/index.html +33 -0
  7. package/assets/avatar/desktop/manifest.json +10 -0
  8. package/assets/avatar/desktop/portrait.png +0 -0
  9. package/assets/avatar/desktop/renderer.mjs +4230 -0
  10. package/assets/avatar/portrait.png +0 -0
  11. package/assets/avatar/renderer.mjs +4230 -0
  12. package/desktop/bin/darwin-arm64/duet-avatar.app/Contents/Info.plist +36 -0
  13. package/desktop/bin/darwin-arm64/duet-avatar.app/Contents/MacOS/duet-avatar +0 -0
  14. package/desktop/bin/darwin-arm64/duet-avatar.app/Contents/Resources/duet companion.icns +0 -0
  15. package/desktop/bin/darwin-arm64/duet-avatar.app/Contents/_CodeSignature/CodeResources +128 -0
  16. package/desktop/bin/darwin-arm64/manifest.json +14 -0
  17. package/desktop/bin/win32-x64/duet-avatar.exe +0 -0
  18. package/desktop/bin/win32-x64/manifest.json +11 -0
  19. package/package.json +17 -5
  20. package/src/avatar/companion.html +33 -0
  21. package/src/avatar/companion.mjs +210 -0
  22. package/src/avatar/idle.mjs +9 -0
  23. package/src/avatar/lipsync.mjs +13 -0
  24. package/src/avatar/motion.mjs +93 -0
  25. package/src/avatar/renderer.mjs +90 -0
  26. package/src/avatar/surface.mjs +45 -0
  27. package/src/avatar/toolbar.mjs +49 -0
  28. package/src/client/audio.mjs +68 -3
  29. package/src/client/avatar-surfaces.mjs +83 -0
  30. package/src/client/avatar-tasks.mjs +68 -0
  31. package/src/client/avatar.mjs +218 -0
  32. package/src/client/browser.mjs +80 -33
  33. package/src/client/composer-bridge.mjs +5 -2
  34. package/src/client/connection-hint.mjs +2 -1
  35. package/src/client/consent.mjs +3 -1
  36. package/src/client/controls-layout.mjs +21 -9
  37. package/src/client/entry.js +26 -3
  38. package/src/client/feedback.mjs +19 -4
  39. package/src/client/identity.mjs +2 -2
  40. package/src/client/input-effect.mjs +51 -0
  41. package/src/client/notice.mjs +1 -0
  42. package/src/client/rpc.mjs +2 -1
  43. package/src/client/settings.html +78 -4
  44. package/src/client/transport.mjs +2 -2
  45. package/src/client/tutorial-adapter.mjs +4 -4
  46. package/src/client/tutorial.mjs +5 -3
  47. package/src/host/assets.mjs +12 -0
  48. package/src/host/avatar-activity.mjs +24 -0
  49. package/src/host/avatar-assets.mjs +18 -0
  50. package/src/host/avatar.mjs +130 -0
  51. package/src/host/diagnostics.mjs +111 -7
  52. package/src/host/feedback-files.mjs +5 -1
  53. package/src/host/plugin.mjs +39 -2
  54. package/src/host/proxy.mjs +13 -5
  55. package/src/host/settings-migration.mjs +2 -1
  56. package/src/host/settings.mjs +19 -4
  57. package/src/shared/avatar-activity.mjs +33 -0
  58. package/src/shared/avatar-menu-ui.mjs +85 -0
  59. package/src/shared/avatar-menu.mjs +83 -0
  60. package/src/shared/avatar-surface.mjs +24 -0
  61. package/src/shared/avatar-ui.mjs +91 -0
  62. package/src/shared/avatar.mjs +125 -0
  63. package/src/shared/nickname.mjs +13 -0
  64. package/src/shared/state.mjs +1 -1
package/README.md CHANGED
@@ -11,11 +11,13 @@ duet,意为「二重奏」。这里的 duet 使用全双工语音模型,可
11
11
 
12
12
  当然,你也可以用 duet 帮你只播报结果,让你不用一直盯着屏幕。
13
13
 
14
+ 现在,duet 还可以成为屏幕上的伙伴:听你说话、随声音回应,在任务完成或需要你处理时提醒你。
15
+
14
16
  最重要的是,duet 语音服务目前可以免费使用。
15
17
 
16
18
  ## 安装
17
19
 
18
- 支持 DSH Web 和 Desktop。当前版本已通过 DSH `0.2.0-rc.1` 的 Web 集成测试。
20
+ 支持 DSH Web 和 Desktop。
19
21
 
20
22
  ### Web
21
23
 
@@ -56,6 +58,20 @@ duet 支持两种模式。
56
58
  | 喇叭 | 播报模式 | 任务完成后,进行简短的播报 |
57
59
  | 双向箭头 | 交互模式 | 开口操作 DSH、自由聊天,也可以在回复过程中插话 |
58
60
 
61
+ 首次启用声音时,按提示回到 DSH 页面点击“启用声音”;开始教学时点击“开始教学”。
62
+
63
+ ### 3D 形象(实验)
64
+
65
+ 点击头像按钮,打开或隐藏你的 duet 伙伴。可以让它悬浮在桌面,也可以在设置中选择“仅在网页端显示”,让角色出现在 DSH 侧栏上方。
66
+
67
+ 本版桌面形象支持 macOS Apple Silicon 和 Windows x64,其他平台可使用网页形象。
68
+
69
+ 字幕跟随声音,点头、摇头和嘴型让交流更直观。输入内容时,键盘气泡会显示正在写入的文字;教学、提示和确认也可以在角色旁完成。
70
+
71
+ 右键桌面角色,可以调整大小、切换气泡样式、查看待处理事项或返回 DSH。不打开语音模式时,也可以通过角色查看任务通知。
72
+
73
+ 你还可以在设置中给助手起个昵称,或直接用语音改名。
74
+
59
75
  ### 目前支持的语音操作
60
76
 
61
77
  | 操作 | 你可以这样说 |
@@ -64,12 +80,14 @@ duet 支持两种模式。
64
80
  | 修改内容 | “把这周改成下周” |
65
81
  | 清空输入框 | “清空输入框” |
66
82
  | 发送任务 | “发送”“提交” |
83
+ | 停止任务 | “停止当前任务” |
67
84
  | 新建会话 | “新建一个会话,叫旅行计划” |
68
85
  | 切换会话 | “切换到第二个会话”“切换到旅行计划” |
69
86
  | 重命名会话 | “把当前会话改名为周末安排” |
70
87
  | 分叉会话 | “从当前会话分叉一个新会话” |
71
88
  | 归档会话 | “归档这个会话” |
72
89
  | 回答 DSH 的问题 | “选第二个”“用中文就好” |
90
+ | 给助手改名 | “把你的名字改成沐沐” |
73
91
  | 自由聊天 | “什么是全双工语音交互?” |
74
92
 
75
93
  ## 麦克风与隐私
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright © 2010-2026 three.js authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
Binary file
@@ -0,0 +1,18 @@
1
+ import{mountAvatarRenderer as st}from"./renderer.mjs";var ve=Object.freeze({large:1,medium:.75,small:.5}),j=e=>Object.hasOwn(ve,e)?e:"large";var mt=Object.freeze({enabled:!0,webOnly:!1,size:"large"}),ue=class{constructor(t=15e3,i=Date.now(),l=6e4){this.interval=t,this.timeout=l,this.last=this.tick=i}touch(t=Date.now()){this.last=t}expired(t=Date.now()){return(t-this.tick>this.interval*2||t<this.tick)&&(this.last=t),this.tick=t,t-this.last>this.timeout}},ft=Object.freeze({off:"\u5F53\u524D\u663E\u793A\uFF1A\u5DF2\u5173\u95ED",desktop:"\u5F53\u524D\u663E\u793A\uFF1A\u684C\u9762\u6D6E\u52A8\u7A97\u53E3",connecting:"\u5F53\u524D\u663E\u793A\uFF1A\u6B63\u5728\u542F\u52A8\u684C\u9762\u7A97\u53E3",recovering:"\u5F53\u524D\u663E\u793A\uFF1A\u684C\u9762\u8FDE\u63A5\u6062\u590D\u4E2D",other:"\u5F53\u524D\u663E\u793A\uFF1A\u7531\u53E6\u4E00\u4E2A DSH \u9875\u9762\u7BA1\u7406\u684C\u9762\u7A97\u53E3",web:"\u5F53\u524D\u663E\u793A\uFF1A\u7F51\u9875\u5185",fallback:"\u5F53\u524D\u663E\u793A\uFF1A\u7F51\u9875\u5185\uFF08\u684C\u9762\u7EC4\u4EF6\u6682\u4E0D\u53EF\u7528\uFF09",unavailable:"\u5F53\u524D\u663E\u793A\uFF1A\u5F62\u8C61\u52A0\u8F7D\u5931\u8D25"});function Oe(e){if(!e||!["off","online","tts_only"].includes(e.mode)||!Number.isFinite(e.rms)||e.rms<0||e.rms>1)throw Error("invalid_avatar_frame");return{type:"frame",mode:e.mode,ready:e.ready===!0,rms:e.rms,size:j(e.size),viseme:["A","I","U","E","O"].includes(e.viseme)?e.viseme:"A",text:typeof e.text=="string"?e.text.slice(-240):"",utterance:typeof e.utterance=="string"?e.utterance.slice(0,100):""}}function qe(e){if(e?.type!=="input_effect"||typeof e.text!="string"||!e.text||e.text.length>600)throw Error("invalid_avatar_input_effect");return{type:"input_effect",text:e.text}}var pe=Object.keys(ve),we={large:"\u5927\uFF08100%\uFF09",medium:"\u4E2D\uFF0875%\uFF09",small:"\u5C0F\uFF0850%\uFF09"},se=e=>pe[(pe.indexOf(j(e))+1)%pe.length];function re(e,t,{label:i=!1}={}){let l=j(t),n=`\u5F62\u8C61\u5927\u5C0F\uFF1A${we[l]}\uFF0C\u70B9\u51FB\u5207\u6362\u4E3A${we[se(l)]}`;e.type="button",e.dataset.size=l,e.setAttribute("aria-label",n),e.title=n;let a=pe.filter(d=>d!==l).concat(l).map(d=>{let o={large:18,medium:12,small:6}[d];return`<rect data-size-square="${d}" x="3" y="${21-o}" width="${o}" height="${o}" stroke-width="${d===l?"2.8":"1"}"/>`}).join("");e.innerHTML=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">${a}</svg>${i?`<span>${we[l]}</span>`:""}`}function Ne({onChange:e=()=>{},floating:t=!1,origin:i="page",anchor:l=()=>null,viewport:n=()=>[0,0,innerWidth,innerHeight]}={}){let a=null,d,o,_,v=!1,k=()=>{if(!t||!o)return;let f=l()?.getBoundingClientRect();if(!f)return;let g=o.getBoundingClientRect(),[p,r,h,m]=n(),w=f.top-g.height-16>=r+12?f.top-g.height-16:f.bottom+12;o.style.left=Math.max(p+12,Math.min(f.left+f.width/2-g.width/2,p+h-g.width-12))+"px",o.style.top=Math.max(r+12,Math.min(w,r+m-g.height-12))+"px",o.style.bottom="auto"},S=f=>{if(!a)return;let g=d;a=null,d=null,document.removeEventListener("keydown",T,!0),window.removeEventListener("resize",k),o?.remove(),o=null,_?.isConnected&&_.focus({preventScroll:!0}),e(),g(f)},T=f=>{if(f.key==="Escape")f.preventDefault(),f.stopImmediatePropagation(),S(!1);else if(f.key==="Tab"&&!t){f.preventDefault();let g=[...o.querySelectorAll("button")],p=g.indexOf(document.activeElement);g[(p+(f.shiftKey?-1:1)+g.length)%g.length].focus()}};return{ask(){if(v)return Promise.resolve(!1);if(a)return a;_=document.activeElement,a=new Promise(r=>d=r),o=document.createElement("div"),o.dataset.avatarCloseOverlay="",o.style.cssText="position:fixed;inset:0;z-index:2147483600;display:flex;align-items:center;justify-content:center;padding:12px;box-sizing:border-box;background:#0003;pointer-events:auto",t&&(o.dataset.duetAvatarSurface="110",o.dataset.duetSurfaceOrigin=i,o.style.cssText="position:fixed;left:12px;bottom:100px;width:260px;max-width:calc(100vw - 24px);z-index:2147483600;pointer-events:auto");let f=document.createElement("div");f.dataset.avatarCloseConfirm="",f.setAttribute("role","alertdialog"),f.setAttribute("aria-modal",String(!t)),f.setAttribute("aria-label","\u9690\u85CF\u62DF\u4EBA\u89D2\u8272\uFF1F"),f.style.cssText="box-sizing:border-box;width:260px;max-width:100%;padding:16px;border:1px solid #8dc5ed55;border-radius:16px;background:#142638;color:#e9f4ff;font:13px/1.6 system-ui;box-shadow:0 8px 28px #0005";let g=document.createElement("div");g.textContent="\u9690\u85CF\u62DF\u4EBA\u89D2\u8272\uFF1F",g.style.cssText="font-size:14px;font-weight:600;margin-bottom:14px";let p=document.createElement("div");p.style.cssText="display:flex;justify-content:flex-end;gap:8px";for(let[r,h]of[["\u53D6\u6D88",!1],["\u9690\u85CF\u62DF\u4EBA\u89D2\u8272",!0]]){let m=document.createElement("button");m.type="button",m.textContent=r,m.dataset.avatarCloseChoice=h?"confirm":"cancel",m.style.cssText=`font:13px system-ui;display:block;width:auto;min-width:56px;min-height:32px;padding:6px 10px;border:0;border-radius:8px;cursor:pointer;background:${h?"#dcefff":"#294154"};color:${h?"#185a89":"#e9f4ff"}`,m.onclick=()=>S(h),p.append(m)}return f.append(g,p),o.append(f),document.body.append(o),document.addEventListener("keydown",T,!0),window.addEventListener("resize",k),k(),p.firstChild.focus(),e(),a},cancel(){S(!1)},dispose(){v=!0,S(!1)},get element(){return o}}}function Be(e,t,i,l){let[n,a,d,o]=t;return!d||!o||i<n||l<a||i>=n+d||l>=a+o||e?.length!==3072?!1:e[Math.floor((l-a)/o*64)*48+Math.floor((i-n)/d*48)]===1}function $e({tools:e,avatar:t,hitTest:i=()=>!1,onChange:l=()=>{}}){let n=!1,a=!1,d=!1,o=!1,_={x:-1,y:-1,overAvatar:!1},v,k,S=b=>{let A=b.getBoundingClientRect();return[A.x,A.y,A.width,A.height]},T=([b,A,ne,ye])=>_.x>=b&&_.y>=A&&_.x<b+ne&&_.y<A+ye,f=()=>{let b=t.getBoundingClientRect(),A=e.getBoundingClientRect();return[Math.min(b.left,A.left),b.bottom-2,Math.max(b.right,A.right)-Math.min(b.left,A.left),Math.max(0,A.top-b.bottom)+4]},g=()=>{e.dataset.revealed=String(a),e.dataset.interactive=String(d),e.dataset.confirming=String(o),l()},p=()=>o||e.dataset.keyboard==="true"&&!!e.querySelector(":focus-visible")||_.overAvatar||d&&(T(S(e))||T(f())),r=()=>{n||(p()?(clearTimeout(v),v=null,clearTimeout(k),k=null,(!a||!d)&&(a=!0,d=!0,g())):a&&!v&&(v=setTimeout(()=>{if(v=null,n||p())return r();a=!1,g(),k=setTimeout(()=>{if(k=null,!n){if(p())return r();d=!1,g()}},500)},180)))},h=b=>{n||(_={x:Number.isFinite(b.x)?b.x:-1,y:Number.isFinite(b.y)?b.y:-1,overAvatar:b.overAvatar===!0},t.style.pointerEvents=_.overAvatar?"auto":"none",r())},m=b=>h({x:b.clientX,y:b.clientY,overAvatar:i(b.clientX,b.clientY)}),w=()=>h({x:-1,y:-1,overAvatar:!1}),N=()=>queueMicrotask(r),te=b=>{["Shift","Control","Alt","Meta"].includes(b.key)||(e.dataset.keyboard="true"),N()},B=()=>{e.dataset.keyboard="false",N()},M=()=>{e.dataset.keyboard="false",w()},R=(b,A,ne)=>(b.addEventListener(A,ne),()=>b.removeEventListener(A,ne)),V=[R(document,"pointermove",m),R(document,"pointerleave",w),R(document,"focusin",N),R(document,"focusout",N),R(document,"keydown",te),R(document,"pointerdown",B),R(window,"blur",M)];return e.dataset.keyboard="false",e.dataset.revealed="false",e.dataset.interactive="false",e.dataset.confirming="false",t.style.pointerEvents="none",{pointer:h,refresh(){r()},setConfirmation(b){o=!!b,g(),r()},get interactive(){return d},regions(){return d?[S(e),f()]:[]},dispose(){n=!0,clearTimeout(v),clearTimeout(k),V.forEach(b=>b())}}}function Le(e){if(e?.type!=="surface")throw Error("invalid_surface");if(e.panel===null)return{type:"surface",panel:null};let t=e.panel;if(!t||!/^s\d+$/.test(t.id)||!Number.isSafeInteger(t.revision)||t.revision<1||!Array.isArray(t.nodes)||t.nodes.length>160)throw Error("invalid_surface");let i=0,l=t.nodes.map(n=>{if(!n||!["text","heading","button","checkbox","break"].includes(n.kind)||typeof n.text!="string"||n.text.length>4e3||(i+=n.text.length,i>1e4))throw Error("invalid_surface");let a={kind:n.kind,text:n.text};if(n.kind==="button"||n.kind==="checkbox"){if(!/^a\d+$/.test(n.action))throw Error("invalid_surface");Object.assign(a,{action:n.action,disabled:n.disabled===!0,checked:n.checked===!0,gesture:n.gesture===!0,label:String(n.label||"").slice(0,100)})}return a});return{type:"surface",panel:{id:t.id,revision:t.revision,nodes:l,target:["online","tts_only"].includes(t.target)?t.target:null}}}function De(e,{send:t,changed:i}){let l=null,n="",a=new Map;return{update(d){let o=Le(d).panel,_=JSON.stringify(o);if(_===n)return;let v=e.contains(document.activeElement)?document.activeElement.dataset.surfaceAction:null,k=e.scrollTop,S=l?.id===o?.id;n=_,l=o,e.hidden=!o;let T=[],f=new Map,g=(p,r)=>{let h=S?a.get(p):null,m=h?.tagName.toLowerCase()===r?h:document.createElement(r);return f.set(p,m),T.push(m),m};if(o){if(o.nodes.some(p=>p.gesture)){let p=o.nodes.find(h=>h.gesture&&h.kind==="button"),r=g("gesture","p");r.className="gesture-note",r.textContent=p?.text==="\u5F00\u59CB\u6559\u5B66"?"\u8BF7\u56DE\u5230 DSH\uFF0C\u70B9\u51FB\u201C\u5F00\u59CB\u6559\u5B66\u201D\u3002":"\u8BF7\u56DE\u5230 DSH\uFF0C\u70B9\u51FB\u201C\u542F\u52A8\u97F3\u9891\u64AD\u653E\u201D\u3002"}for(let[p,r]of o.nodes.entries()){let h=r.kind==="break"?"br":r.kind==="heading"?"h3":r.kind==="button"?"button":r.kind==="checkbox"?"input":"span",m=g(r.action||"node"+p,h);if(m.textContent!==r.text&&(m.textContent=r.text),r.kind==="checkbox"&&(m.type="checkbox",m.checked=r.checked),r.kind==="button"||r.kind==="checkbox"){m.dataset.surfaceAction=r.action,r.kind==="button"&&(m.type="button"),m.disabled=r.disabled||r.gesture,r.label?m.setAttribute("aria-label",r.label):m.removeAttribute("aria-label");let w=()=>{l!==o||m.disabled||t({type:"surface_action",id:o.id,revision:o.revision,action:r.action,checked:m.checked===!0})};r.kind==="checkbox"?m.onchange=w:m.onclick=w}}}for(T.forEach((p,r)=>{e.children[r]!==p&&e.insertBefore(p,e.children[r]||null)});e.children.length>T.length;)e.lastElementChild.remove();if(a=f,v){let p=a.get(v);p&&!p.disabled&&document.activeElement!==p&&p.focus({preventScroll:!0})}e.scrollTop=k,i(!!o,o?.target)}}}var He="avatar_local_v1";var nt=["open_dsh","pending","settings","tutorial","hide","notifications","size","bubble","view","dismiss"],_e=["small","medium","large"],it=["completed","failed","stopped","approval","question","plan_review"];var me=(e,t)=>typeof e=="string"?e.slice(0,t):"";function Ue(e){if(e?.type!=="menu_action"||!nt.includes(e.action)||!/^[a-zA-Z0-9-]{1,64}$/.test(e.request_id||""))throw Error("invalid_avatar_menu_action");let t={type:"menu_action",request_id:e.request_id,action:e.action};if(["size","bubble"].includes(e.action)){if(!_e.includes(e.value))throw Error("invalid_avatar_size");t.value=e.value}if(["view","dismiss"].includes(e.action)){if(typeof e.id!="string"||!e.id||e.id.length>512)throw Error("invalid_avatar_notice");t.id=e.id}if(e.action==="notifications"){if(typeof e.value!="boolean")throw Error("invalid_avatar_preference");t.value=e.value}if(e.action==="snooze"){if(![0,30].includes(e.value))throw Error("invalid_avatar_snooze");t.value=e.value}return t}function Pe(e){if(e?.type!=="local_state"||e.protocol!==He||!Number.isSafeInteger(e.revision)||e.revision<0||!Array.isArray(e.items)||e.items.length>32)throw Error("invalid_avatar_local_state");let t=e.items.map(i=>{if(!it.includes(i.status)||!i.id||typeof i.id!="string"||i.id.length>512)throw Error("invalid_avatar_notice");return{id:i.id,session_id:me(i.session_id,256),name:me(i.name,100),status:i.status,summary:me(i.summary,240),pending:i.pending===!0,unread:i.unread===!0}});for(;JSON.stringify(t).length>12e3;)t.pop();return{type:"local_state",protocol:He,revision:e.revision,items:t,size:_e.includes(e.size)?e.size:"large",bubble:_e.includes(e.bubble)?e.bubble:"medium",enabled:e.enabled!==!1,snoozed:e.snoozed===!0,running:Math.max(0,Math.min(1e4,Number(e.running)||0)),available:e.available===!0,toast:t.some(i=>i.id===e.toast)?e.toast:null}}function Ve(e){if(e?.type!=="menu_result"||!/^[a-zA-Z0-9-]{1,64}$/.test(e.request_id||""))throw Error("invalid_avatar_menu_result");return{type:"menu_result",request_id:e.request_id,ok:e.ok===!0,message:me(e.message,180)}}var je={completed:"\u672C\u8F6E\u5DF2\u5B8C\u6210",failed:"\u6267\u884C\u5931\u8D25",stopped:"\u5DF2\u505C\u6B62",approval:"\u7B49\u5F85\u6388\u6743",question:"\u7B49\u5F85\u56DE\u7B54",plan_review:"\u7B49\u5F85\u65B9\u6848\u786E\u8BA4"},Fe={small:"\u7D27\u51D1",medium:"\u6807\u51C6",large:"\u5BBD\u677E"},ke={open:"M14 3h7v7m0-7L10 14M10 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-5",pending:"M8 4h8m-9 0H5v17h14V4h-2M8 3h8v4H8zM8 12h8m-8 4h5",bubble:"M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 3v-3H3V6a2 2 0 0 1 2-2zM7 9h10m-10 4h6",tutorial:"m9 5 10 7-10 7z",settings:"M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8M9 3h6l1 3 3 1 2 5-2 5-3 1-1 3H9l-1-3-3-1-2-5 2-5 3-1z",hide:"m4 4 16 16M9 5a11 11 0 0 1 12 7l-3 4M6 6a13 13 0 0 0-5 6s4 7 11 7l3-1M10 10a3 3 0 0 0 4 4",back:"m14 5-7 7 7 7"},at=e=>{let t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.innerHTML=`<path d="${ke[e]||ke.pending}"/>`,t};function Ye({anchor:e,viewport:t=()=>[0,0,innerWidth,innerHeight],send:i,changed:l=()=>{}}){let n={items:[],running:0,enabled:!0,size:"large",bubble:"medium"},a,d,o,_="main",v,k=!1,S,T,f,g,p=document.createElement("style");p.textContent=`
2
+ .duet-pet-menu{position:fixed;z-index:2147483601;box-sizing:border-box;width:264px;max-width:calc(100vw - 24px);padding:9px;border:1px solid #a7c5dc30;border-radius:18px;background:#142330f7;color:#eaf2f8;font:13px/1.5 Inter,"PingFang SC",sans-serif;box-shadow:0 16px 48px #0004,0 2px 8px #0002;backdrop-filter:blur(20px);pointer-events:auto;overflow:auto}
3
+ .duet-pet-menu button{position:relative;display:flex;align-items:center;justify-content:flex-start;gap:10px;box-sizing:border-box;width:100%;min-height:39px;margin:0;border:0;border-radius:10px;padding:8px 11px;background:transparent;color:inherit;text-align:left;font:inherit;cursor:pointer;height:auto;flex-shrink:0;letter-spacing:normal}
4
+ .duet-pet-menu button>[data-label]{min-width:0;flex:1;overflow-wrap:anywhere}
5
+ .duet-pet-menu button>svg,.duet-pet-menu [data-size-icon]{display:flex;align-items:center;justify-content:center;width:20px;height:20px;flex:0 0 20px}
6
+ [data-duet-notice-badge][hidden]{display:none!important}
7
+ .duet-pet-menu button:hover,.duet-pet-menu button:focus-visible{background:#b3daff16;outline:none}
8
+ .duet-pet-menu svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;flex-shrink:0;color:#a7bdd0}
9
+ .duet-pet-menu [data-wordmark]{font:700 28px/1.1 Inter,"PingFang SC",sans-serif;letter-spacing:-1.1px;padding:11px 12px 15px}
10
+ .duet-pet-menu [data-wordmark] span{color:#ed9b35}.duet-pet-menu hr{border:0;border-top:1px solid #a7c5dc1c;margin:6px 9px}
11
+ .duet-pet-menu [data-value]{margin-left:auto;color:#9eb1c0;font-size:12px}.duet-pet-menu [data-switch]{position:relative;display:block;width:28px;height:16px;border-radius:10px;background:#53616e;flex-shrink:0;transition:background .15s}
12
+ .duet-pet-menu [data-switch]:after{content:'';position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:white;transition:transform .15s}.duet-pet-menu [aria-checked=true] [data-switch]{background:#6eabc9}.duet-pet-menu [aria-checked=true] [data-switch]:after{transform:translateX(12px)}
13
+ .duet-pet-menu [data-bubble-preview]{margin:12px 9px;padding:12px 14px;border-radius:15px 15px 15px 4px;border:1px solid #8dc5ed45;background:#213b4c;white-space:pre-wrap;overflow:auto;line-height:1.7;scrollbar-width:thin}
14
+ .duet-pet-menu p{margin:10px 12px;color:#a7bdd0}.duet-pet-menu [data-notice-title]{padding:8px 11px;font-weight:600}
15
+ `,document.head.append(p);let r=s=>{let[c,E,x,y]=t();s.style.maxHeight=Math.max(40,y-24)+"px",s.style.maxWidth=Math.max(40,x-24)+"px";let C=e().getBoundingClientRect(),L=s.getBoundingClientRect(),I=S?.y??(C.top-L.height-12>=E?C.top-L.height-12:C.bottom+12);s.style.left=Math.max(c+12,Math.min(S?.x??C.left,c+x-L.width-12))+"px",s.style.top=Math.max(E+12,Math.min(I,E+y-L.height-12))+"px"},h=()=>{a?.remove(),a=null,S=null,T?.isConnected&&T.focus({preventScroll:!0}),l()},m=(s,c,E)=>i(Ue({type:"menu_action",request_id:crypto.randomUUID(),action:s,value:c,id:E})),w=(s,c,E=c,x)=>{let y=document.createElement("button");y.type="button",y.setAttribute("role","menuitem"),y.dataset.menuAction=c,ke[E]&&y.append(at(E));let C=document.createElement("span");return C.dataset.label="",C.textContent=s,y.append(C),y.onclick=()=>{if(["pending","bubble_panel","back"].includes(c)){_=c==="back"?"main":c,M();return}h(),m(c,void 0,x)},y},N=()=>{let s=n.items.filter(c=>c.pending||c.unread).length;return"\u5F85\u5904\u7406\u4E8B\u9879\u4E0E\u901A\u77E5"+(s?`\uFF08${s}\uFF09`:"")},te=s=>{let c=document.createElement("span");return c.dataset.value="",s.append(c),c},B=()=>{if(!a)return;let s=a.querySelector("[data-menu-action=size]");if(s){let C=s.querySelector("[data-size-icon]");re(C,n.size),s.querySelector("[data-value]").textContent={large:"\u5927",medium:"\u4E2D",small:"\u5C0F"}[n.size],s.setAttribute("aria-label",C.getAttribute("aria-label"))}a.querySelector("[data-menu-action=notifications]")?.setAttribute("aria-checked",String(n.enabled));let E=a.querySelector("[data-menu-action=bubble]");E&&(E.querySelector("[data-value]").textContent=Fe[n.bubble],E.setAttribute("aria-label",`\u6C14\u6CE1\u5927\u5C0F\uFF1A${Fe[n.bubble]}\uFF0C\u70B9\u51FB\u5207\u6362`));let x=a.querySelector("[data-bubble-preview]");x&&(x.style.maxHeight={small:60,medium:110,large:180}[n.bubble]+"px",x.dataset.size=n.bubble);let y=a.querySelector("[data-menu-action=pending] span");y&&(y.textContent=N()),r(a),l()},M=()=>{if(!a)return;a.replaceChildren();let s=document.createElement("div");s.dataset.wordmark="",s.append("duet");let c=document.createElement("span");c.textContent=".",s.append(c),a.append(s);let E=()=>a.append(document.createElement("hr"));if(_==="main"){a.append(w("\u6253\u5F00 DSH","open_dsh","open"),w(N(),"pending"));let x=w("\u4EFB\u52A1\u901A\u77E5","notifications","pending");x.setAttribute("role","menuitemcheckbox");let y=document.createElement("span");y.dataset.switch="",x.append(y),x.onclick=()=>{n.enabled=!n.enabled,B(),m("notifications",n.enabled)},a.append(x),E();let C=w("\u5F62\u8C61\u5927\u5C0F","size"),L=document.createElement("span");L.dataset.sizeIcon="",C.prepend(L),te(C),C.onclick=()=>{n.size=se(n.size),B(),m("size",n.size)},a.append(C,w("\u6C14\u6CE1\u5927\u5C0F","bubble_panel","bubble")),E(),a.append(w("\u4F7F\u7528\u6559\u5B66","tutorial"),w("duet \u8BBE\u7F6E","settings"),w("\u9690\u85CF\u5F62\u8C61","hide"))}else if(_==="bubble_panel"){let x=w("\u6C14\u6CE1\u5927\u5C0F","bubble","bubble");te(x),x.onclick=()=>{n.bubble={small:"medium",medium:"large",large:"small"}[n.bubble],B(),m("bubble",n.bubble)},a.append(x);let y=document.createElement("div");y.dataset.bubblePreview="",y.setAttribute("aria-label","\u793A\u4F8B\u6C14\u6CE1"),y.textContent=`\u597D\u7684\uFF0C\u6211\u6765\u5E2E\u4F60\u3002
16
+ \u4EFB\u52A1\u5B8C\u6210\u540E\uFF0C\u6211\u4F1A\u5728\u8FD9\u91CC\u544A\u8BC9\u4F60\u7ED3\u679C\u3002
17
+ \u4E5F\u53EF\u4EE5\u968F\u65F6\u6253\u65AD\u6211\uFF0C\u7EE7\u7EED\u804A\u804A\u4F60\u7684\u65B0\u60F3\u6CD5\u3002
18
+ \u8FD9\u662F\u4E00\u6BB5\u8F83\u957F\u7684\u6587\u5B57\uFF0C\u4F60\u53EF\u4EE5\u770B\u770B\u5F53\u524D\u6C14\u6CE1\u80FD\u663E\u793A\u591A\u5C11\u5185\u5BB9\u3002`,a.append(y,w("\u8FD4\u56DE","back"))}else{if(!n.available){let x=document.createElement("p");x.textContent="\u6B63\u5728\u8FDE\u63A5 DSH",a.append(x)}if(!n.items.length){let x=document.createElement("p");x.textContent="\u6682\u65F6\u6CA1\u6709\u5F85\u5904\u7406\u4E8B\u9879\u6216\u65B0\u901A\u77E5",a.append(x)}for(let x of n.items){let y=w(`${x.unread?"\u25CF ":""}${x.name||"\u672A\u547D\u540D\u4F1A\u8BDD"} \xB7 ${je[x.status]}`,"view","pending",x.id);y.title=x.summary,a.append(y)}a.append(w("\u8FD4\u56DE","back"))}B(),a.querySelector("button")?.focus({preventScroll:!0})},R=(s,c="main")=>{k||(s?.preventDefault(),s?.stopPropagation(),h(),T=document.activeElement,_=c,S=s&&Number.isFinite(s.clientX)&&s.clientX>0?{x:s.clientX,y:s.clientY}:null,a=document.createElement("div"),a.className="duet-pet-menu",a.dataset.duetContextMenu="",a.setAttribute("role","menu"),a.setAttribute("aria-label","duet \u5F62\u8C61\u83DC\u5355"),document.body.append(a),M())},V=s=>{a&&!a.contains(s.target)&&(s.preventDefault(),s.stopPropagation(),h())},b=s=>{if(!a)return;if(s.key==="Escape"){s.preventDefault(),s.stopImmediatePropagation(),h();return}let c=[...a.querySelectorAll("button")],E=c.indexOf(document.activeElement);["ArrowDown","ArrowUp","Home","End","Tab"].includes(s.key)&&(s.preventDefault(),c[s.key==="Home"?0:s.key==="End"?c.length-1:(E+(s.key==="ArrowUp"||s.key==="Tab"&&s.shiftKey?-1:1)+c.length)%c.length]?.focus())},A=(s,c)=>{s.className="duet-pet-menu",s.setAttribute("aria-label",c)},ne=s=>{n=Pe(s),o??=document.createElement("button"),o.type="button",o.dataset.duetNoticeBadge="",o.style.cssText="position:fixed;z-index:2147483600;border:0;border-radius:12px;background:#dcefff;color:#185a89;font:12px system-ui;padding:4px 7px;cursor:pointer;pointer-events:auto";let c=n.items.filter(I=>I.pending||I.unread).length;o.textContent=c?String(c):"",o.setAttribute("aria-label",N()),o.hidden=!c||!n.enabled,o.onclick=I=>R(I,"pending"),o.isConnected||document.body.append(o);let E=e().getBoundingClientRect(),[x,y,C,L]=t();if(o.style.left=Math.max(x+12,Math.min((E.right??E.left+E.width)-24,x+C-36))+"px",o.style.top=Math.max(y+12,Math.min(E.top,y+L-30))+"px",f!==n.toast){clearTimeout(v),clearTimeout(g),d?.remove(),d=null,f=n.toast;let I=n.items.find(oe=>oe.id===n.toast);if(I){d=document.createElement("section"),d.dataset.duetLocalNotice="",A(d,"DSH \u4EFB\u52A1\u901A\u77E5");let oe=document.createElement("div");oe.dataset.noticeTitle="",oe.textContent=`${I.name||"\u672A\u547D\u540D\u4F1A\u8BDD"} \xB7 ${je[I.status]}`,d.append(oe,w(I.pending?"\u53BB\u5904\u7406":"\u67E5\u770B","view","open",I.id),w("\u6536\u8D77","dismiss","hide",I.id)),document.body.append(d),r(d),I.pending||(v=setTimeout(()=>{d?.remove(),d=null,l()},8e3))}}B(),l()},ye=s=>{let c=Ve(s);c.message&&(clearTimeout(g),d?.remove(),d=document.createElement("section"),A(d,"\u64CD\u4F5C\u63D0\u793A"),d.textContent=c.message,document.body.append(d),r(d),l(),g=setTimeout(()=>{d?.remove(),d=null,l()},4e3))},Ie=()=>{a&&r(a),d&&r(d)};return document.addEventListener("pointerdown",V,!0),document.addEventListener("keydown",b,!0),window.addEventListener("resize",Ie),window.addEventListener("blur",h),{open:R,close:h,update:ne,result:ye,get active(){return!!a},regions(){return[a,d,o].filter(s=>s?.isConnected&&!s.hidden).map(s=>{let c=s.getBoundingClientRect();return[c.x,c.y,c.width,c.height]})},dispose(){k=!0,h(),p.remove(),clearTimeout(v),clearTimeout(g),d?.remove(),o?.remove(),document.removeEventListener("pointerdown",V,!0),document.removeEventListener("keydown",b,!0),window.removeEventListener("resize",Ie),window.removeEventListener("blur",h)}}}var F=(e,t,i)=>Number.isFinite(e)&&e>=t&&e<=i,Ae=e=>e&&F(e.width,1,1e6)&&F(e.height,1,1e6)?{width:e.width,height:e.height}:null;function We(e){if(!e||!["desktop_physical","viewport_css"].includes(e.space))return null;let t=Ae(e.total_resolution),i=e.avatar_position;if(!t||!i||!F(i.x,-1e6,1e6)||!F(i.y,-1e6,1e6)||!Ae(i))return null;let l={space:e.space,total_resolution:t,avatar_position:{x:i.x,y:i.y,width:i.width,height:i.height}};if(e.space==="desktop_physical"){if(!e.desktop_origin||!F(e.desktop_origin.x,-1e6,1e6)||!F(e.desktop_origin.y,-1e6,1e6)||!F(e.scale,.25,16))return null;l.desktop_origin={x:e.desktop_origin.x,y:e.desktop_origin.y},l.scale=e.scale}else{let n=Ae(e.viewport_resolution);if(!n)return null;l.viewport_resolution=n}return l}var ie=window.__DUET_AVATAR__,U=(e,t)=>window.__TAURI__.core.invoke(e,t);if(!ie||!/^ws:\/\/127\.0\.0\.1:\d+\/?$/.test(ie.url)||!/^[a-f0-9]{64}$/.test(ie.token))throw Error("companion must be started by duet");var u=e=>document.getElementById(e),H=new WebSocket(ie.url,[`duet-avatar-${ie.token}`]),xe=!1,X=!1,$=!1,Y=Date.now(),G,be,W=null,Ee=!1,J=null,fe=null,K=j(ie.size),ce=!1,Se=null,O,Ke="medium",Je,z={mode:"off",ready:!1,rms:0,viseme:"A",text:"",utterance:""},de=null,Ce=[],Ge,Ze,ge=null,ze=!1,Xe="";async function rt(){if(!(!xe||$||ze)){ze=!0;try{let e=await U("avatar_geometry"),t=u("avatar").getBoundingClientRect(),i=e.scale,l=We({space:"desktop_physical",total_resolution:e.total_resolution,desktop_origin:e.desktop_origin,scale:i,avatar_position:{x:e.window_origin.x+t.x*i,y:e.window_origin.y+t.y*i,width:t.width*i,height:t.height*i}}),n=JSON.stringify(l);l&&n!==Xe&&(Xe=n,q({type:"avatar_geometry",position:l}))}catch{}finally{ze=!1}}}var Re=()=>{if(!ge)return[0,0,innerWidth,innerHeight];let[e,t,i,l]=ge,n=Math.max(0,e),a=Math.max(0,t);return[n,a,Math.max(1,Math.min(innerWidth,e+i)-n),Math.max(1,Math.min(innerHeight,t+l)-a)]},Q=$e({tools:u("tools"),avatar:u("avatar"),hitTest:(e,t)=>Be(Ce,le(u("avatar")),e,t),onChange:()=>{ee()}}),Qe={getBoundingClientRect(){let e=u("avatar").getBoundingClientRect(),t=u("tools").getBoundingClientRect();return{left:e.left,width:e.width,top:e.top,bottom:Math.max(e.bottom,t.bottom)}}},Z=Ne({floating:!0,origin:"avatar",anchor:()=>Qe,viewport:Re,onChange:()=>Q.setConfirmation(ce||!!Z.element||O?.active)}),lt=De(u("surface"),{send:e=>q(e),changed:(e,t)=>{ce=e,e||(Se=null),Q.setConfirmation(e||!!Z.element||O?.active);for(let i of document.querySelectorAll("[data-mode]"))i.toggleAttribute("data-teaching",i.dataset.mode===t);ae(),ee()}});O=Ye({anchor:()=>Qe,viewport:Re,send:async e=>{if(e.action==="hide")u("close").click();else{if(["open_dsh","view","settings"].includes(e.action))try{await U("focus_dsh")}catch{O.result({type:"menu_result",request_id:e.request_id,ok:!1,message:"\u672A\u80FD\u5524\u8D77 DSH\uFF0C\u8BF7\u786E\u8BA4\u6240\u5C5E\u7A97\u53E3\u4ECD\u7136\u6253\u5F00\uFF1B\u82E5\u521A\u66F4\u65B0\u63D2\u4EF6\uFF0C\u8BF7\u66F4\u65B0\u684C\u9762\u5F62\u8C61\u3002"});return}q(e)}},changed:()=>{Q.setConfirmation(ce||!!Z.element||O.active),ee()}});var dt=Promise.all([window.__TAURI__.event.listen("avatar-pointer",e=>Q.pointer(e.payload)).then(e=>{$?e():Ge=e}),window.__TAURI__.event.listen("avatar-viewport",e=>{!Array.isArray(e.payload)||e.payload.length!==4||!e.payload.every(Number.isFinite)||ge?.every((t,i)=>t===e.payload[i])||(ge=e.payload,ae(),window.dispatchEvent(new Event("resize")),ee())}).then(e=>{$?e():Ze=e})]).catch(()=>{X=!0,q({type:"failed"}),P()});re(u("size"),K);var q=e=>{H.readyState===1&&H.bufferedAmount<16e3&&H.send(JSON.stringify(e))};function ae(){let e=u("bubble"),t=u("surface"),i=[e,t].filter(M=>!M.hidden);if(!i.length)return;let[l,n,a,d]=Re(),o=u("avatar").getBoundingClientRect(),_=u("tools").getBoundingClientRect(),v=o.width/u("avatar").offsetWidth||1,k=12*v;e.style.width="256px",e.style.right="auto";for(let M of i)M.style.maxHeight=Math.max(1,d-24)/v+"px";let S=e.hidden?0:Math.min({small:90,medium:180,large:260}[Ke]*v,e.getBoundingClientRect().height),T=t.hidden?0:Math.min(256*v,t.getBoundingClientRect().height),f=i.length>1?k:0,g=S+T+f,p=Math.max(0,o.top-k-(n+12)),r=Math.max(0,n+d-12-(_.bottom+k)),h=ce?Se:null;(!h||(h==="above"?p:r)<Math.min(g,80*v))&&(h=p>=g?"above":r>=g?"below":p>=r?"above":"below"),ce&&(Se=h);let m=h==="above"?p:r,w=t.hidden?m:Math.min(S,Math.max(0,(m-f)*.3)),N=Math.min(S,w),te=Math.min(T,Math.max(0,m-N-f));e.hidden||(e.style.maxHeight=Math.max(1,N/v)+"px"),t.hidden||(t.style.maxHeight=Math.max(1,te/v)+"px");let B=h==="above"?o.top-k:_.bottom+k;for(let M of i){let R=M.getBoundingClientRect(),V=M.offsetParent.getBoundingClientRect(),b=Math.max(l+12,Math.min(o.left+o.width/2-R.width/2,l+a-12-R.width)),A=h==="above"?B-R.height:B;M.style.left=(b-V.left)/v+"px",M.style.top=(A-V.top)/v+"px",M.style.bottom="auto",M.style.right="auto",B=h==="above"?A-k:A+R.height+k}e.hidden||(e.scrollTop=e.scrollHeight)}var Te=()=>{let e=de?.text||z.text,t=u("bubble").hidden===!!e||u("text").textContent!==e;u("bubble").hidden=!e,u("bubble").dataset.input=String(!!de),u("keyboard").toggleAttribute("hidden",!de),u("text").textContent!==e&&(u("text").textContent=e),t&&ae()},he=()=>{clearTimeout(be),de=null,Te()},ct=()=>{for(let t of document.querySelectorAll("[data-mode]")){let i=z.mode===t.dataset.mode;t.disabled=!1,t.setAttribute("aria-pressed",String(i)),t.setAttribute("aria-busy",String(i&&!z.ready)),t.querySelector("[data-connecting-ring]").hidden=!(i&&!z.ready),t.setAttribute("aria-label",`${i?"\u5173\u95ED":"\u6253\u5F00"}${t.dataset.mode==="online"?"\u4EA4\u4E92\u6A21\u5F0F":"\u64AD\u62A5\u6A21\u5F0F"}`),t.title=i&&!z.ready?`\u6B63\u5728\u8FDE\u63A5${t.dataset.mode==="online"?"\u4EA4\u4E92\u6A21\u5F0F":"\u64AD\u62A5\u6A21\u5F0F"}`:t.getAttribute("aria-label")}u("dot").style.color=z.ready?"#7fd6a6":"#ed9b35";let e=z.mode==="off"?"\u8BED\u97F3\u672A\u5F00\u542F":z.ready?z.mode==="online"?"\u4EA4\u4E92\u6A21\u5F0F":"\u64AD\u62A5\u6A21\u5F0F":"\u6B63\u5728\u8FDE\u63A5\u2026";u("status").textContent!==e&&(u("status").textContent=e)},P=()=>{$||($=!0,O.dispose(),Z.dispose(),Q.dispose(),Ge?.(),Ze?.(),clearInterval(ut),clearInterval(pt),clearTimeout(be),G?.update({...z,rms:0,text:""}),G?.dispose(),H.close(),U("hide_avatar").catch(()=>{}))},Me=()=>{X?q({type:"failed"}):xe&&q({type:"ready",protocol:2})},et=e=>(K=j(e),J||K===fe?J||Promise.resolve():(J=(async()=>{for(await W;!$&&K!==fe;){let t=K,i=!0,l=await U("set_avatar_size",{size:t,panel:i});if(!l||!Number.isFinite(l.scale)||l.scale<=0||l.scale>1)throw Error("invalid_avatar_layout");u("shell").style.transform=`scale(${l.fit??1})`,u("shell").dataset.panel=String(i),u("stage").dataset.size=t,u("stage").style.setProperty("--scale",l.scale),re(u("size"),t),fe=t,Q.refresh(),ae()}})().catch(()=>{X=!0,q({type:"failed"}),P()}).finally(()=>{J=null}),J));try{G=st(u("avatar"),{modelURL:"./character.glb",onReady(){Promise.all([dt,et(K)]).then(async()=>{if(!($||X)&&(xe=!0,await ee(),!$))return Me(),U("show_avatar")}).catch(()=>{X=!0,q({type:"failed"}),P()})},onError(){X=!0,Me()}})}catch{X=!0}H.onopen=Me;var tt=new ue(1e3);H.onmessage=e=>{tt.touch();try{let t=JSON.parse(e.data);if(t.type==="frame")z=Oe(t),Y=Date.now(),G?.update(z),et(z.size),z.mode==="off"&&he(),Te(),ct();else if(t.type==="input_effect")de=qe(t),Y=Date.now(),clearTimeout(be),Te(),be=setTimeout(he,1600);else if(t.type==="clear_input_effect")he();else if(t.type==="surface")lt.update(t),Y=Date.now();else if(t.type==="local_state")O.update(t),Ke=t.bubble,ae(),Y=Date.now(),t.toast&&t.toast!==Je&&z.mode==="off"&&t.items.find(i=>i.id===t.toast)?.status==="completed"&&G?.update({...z,text:"\u5B8C\u6210\u4E86",utterance:"notice-"+t.toast}),Je=t.toast;else if(t.type==="menu_result")O.result(t),Y=Date.now();else if(t.type==="owner_focus")U("remember_dsh").catch(()=>{}),Y=Date.now();else if(t.type!=="alive")throw Error("invalid_avatar_message")}catch{H.close(1008,"invalid_avatar_message")}};H.onclose=P;H.onerror=P;var ut=setInterval(()=>{if(tt.expired()){P();return}Date.now()-Y>1500&&(G?.update({...z,rms:0,text:""}),z={...z,text:""},he()),q({type:"alive"}),rt()},1e3),le=e=>{let t=e.getBoundingClientRect();return[t.x,t.y,t.width,t.height]};function ee(){if(!(!xe||J||$||document.hidden))return W?(Ee=!0,W):(W=(async()=>{do{if(Ee=!1,$||J||document.hidden)break;let e=Z.element?[le(Z.element)]:O.active?[[0,0,innerWidth,innerHeight]]:[...Q.regions(),...u("bubble").hidden?[]:[le(u("bubble"))],...u("surface").hidden?[]:[le(u("surface"))],...O.regions()];Ce=G.hitMask(),await U("avatar_hit_mask",{mask:Ce,avatar:le(u("avatar")),regions:e})}while(Ee)})().catch(()=>{}).finally(()=>{W=null}),W)}var pt=setInterval(()=>{W||ee()},350);for(let e of document.querySelectorAll("[data-mode]")){let t=document.createElement("span");t.dataset.connectingRing="",t.hidden=!0,t.innerHTML='<svg viewBox="0 0 30 30" preserveAspectRatio="none" aria-hidden="true"><rect x="1" y="1" width="28" height="28" rx="7" pathLength="100"/></svg>',e.append(t),e.onclick=()=>q({type:"mode",mode:e.dataset.mode})}u("close").onclick=async()=>{await Z.ask()&&!$&&(q({type:"hide"}),P())};u("size").onclick=()=>q({type:"size",size:se(fe||K)});var D=null;u("avatar").tabIndex=0;u("avatar").oncontextmenu=e=>{D=null,O.open(e)};u("avatar").onkeydown=e=>{(e.key==="ContextMenu"||e.key==="F10"&&e.shiftKey)&&(D=null,O.open(e))};u("avatar").onpointerdown=e=>{e.button===0&&!e.ctrlKey&&!O.active&&(D={x:e.clientX,y:e.clientY})};u("avatar").onpointermove=e=>{D&&!O.active&&e.buttons===1&&Math.hypot(e.clientX-D.x,e.clientY-D.y)>4&&(D=null,U("drag_avatar").catch(()=>{}))};window.addEventListener("pointerup",()=>{D=null});window.addEventListener("blur",()=>{D=null});window.addEventListener("resize",()=>{ae(),ee()});window.addEventListener("pagehide",P,{once:!0});
@@ -0,0 +1,33 @@
1
+ <!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
2
+ <title>duet</title><style>
3
+ html,body{margin:0;background:transparent;font:13px/1.6 system-ui;overflow:hidden;color:#e9f4ff;user-select:none}
4
+ #stage{--scale:1;position:absolute;left:0;top:0;width:280px;height:calc(210px + 280px * var(--scale));transform-origin:top left}
5
+ #avatar{position:absolute;left:calc((280px - 260px * var(--scale)) / 2);top:140px;height:calc(280px * var(--scale));width:calc(260px * var(--scale));cursor:grab;touch-action:none}
6
+ #bubble{position:absolute;bottom:calc(100% - 134px);left:12px;right:12px;padding:12px 14px;background:#142638ed;border:1px solid #8dc5ed45;border-radius:17px;box-shadow:0 5px 20px #0002;max-height:180px;overflow-y:auto;white-space:pre-wrap;overflow-wrap:anywhere;scrollbar-width:thin}
7
+ #bubble{box-sizing:border-box}#bubble[hidden]{display:none}#bubble[data-input=true]{background:#193b53f5;border-color:#7cb8e599}
8
+ #keyboard{display:inline-block;vertical-align:middle;margin-right:7px}#keyboard[hidden]{display:none}
9
+ #tools{position:absolute;top:calc(142px + 280px * var(--scale));left:16px;right:16px;display:flex;align-items:center;justify-content:center;gap:6px;padding:5px;border:1px solid transparent;border-radius:15px;background:transparent;isolation:isolate}
10
+ #tools{opacity:0;pointer-events:none;transition:opacity .5s ease}
11
+ #stage{pointer-events:none}#bubble{pointer-events:auto}
12
+ #tools[data-revealed=true]{opacity:1}
13
+ #tools[data-interactive=true]{pointer-events:auto}
14
+ #tools::before{content:'';position:absolute;inset:-1px;z-index:-1;pointer-events:none;border:1px solid #8dc5ed30;border-radius:inherit;background:#142638e8}
15
+ #brand{font-family:Inter,"PingFang SC",sans-serif;font-size:21px;font-weight:700;letter-spacing:-1.1px;line-height:1.1;padding:0 4px;text-shadow:0 1px 2px #000b}#dot{color:#ed9b35}
16
+ #tools button:not([aria-pressed=true]) svg{filter:drop-shadow(0 1px 1px #0009)}
17
+ button{position:relative;display:flex;align-items:center;justify-content:center;width:31px;height:30px;flex-shrink:0;border:0;border-radius:8px;background:transparent;color:#d5e6f4;cursor:pointer;padding:5px}
18
+ button:disabled{opacity:.4;cursor:wait}button:focus-visible{outline:2px solid #8dccff;outline-offset:2px}button[aria-pressed=true]:not([aria-busy=true]){background:#dcefff;color:#185a89}
19
+ #tools:not([data-keyboard=true]) button:focus{outline:none}
20
+ button svg{width:20px;height:20px}[data-connecting-ring]{position:absolute;inset:0;pointer-events:none}[data-connecting-ring][hidden]{display:none}[data-connecting-ring] svg{width:100%;height:100%;overflow:visible}[data-connecting-ring] rect{fill:none;stroke:#ed9b35;stroke-width:2;stroke-linecap:round;stroke-dasharray:28 72;animation:connect 1.6s linear infinite}@keyframes connect{to{stroke-dashoffset:-100}}
21
+ #status{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
22
+ #shell{position:absolute;left:0;top:0;transform-origin:top left}#shell[data-panel=true] #stage{left:50px;top:280px}
23
+ #surface{position:absolute;left:12px;top:12px;width:356px;max-height:256px;overflow:auto;box-sizing:border-box;background:#142638f5;color:#e9f4ff;border:1px solid #8dc5ed65;border-radius:18px;padding:18px;box-shadow:0 8px 26px #0003;white-space:pre-wrap;overflow-wrap:anywhere;user-select:text}
24
+ #surface[hidden]{display:none}#surface h3{font-size:17px;margin:0 0 10px}#surface button{display:inline-block;width:auto;height:auto;min-height:32px;margin:8px 5px 0 0;padding:6px 10px;border:1px solid #8dc5ed70;background:#254866}#surface input{accent-color:#80c2ff}#surface .gesture-note{color:#ffd39a;margin:0 0 10px}
25
+ [data-teaching]{outline:2px solid #80c2ff!important;box-shadow:0 0 0 5px #80c2ff40}[data-teaching]::after{content:'↓';position:absolute;top:-30px;left:8px;color:#80c2ff;font-size:24px}
26
+ </style><div id="shell"><section id="surface" hidden role="region" aria-label="duet 提示和教学"></section><div id="stage" data-size="large">
27
+ <div id="bubble" hidden><svg id="keyboard" hidden width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><rect x="2" y="5" width="20" height="14" rx="3"/><path d="M6 9h1m3 0h1m3 0h1m3 0h1M6 12h1m3 0h1m3 0h1m3 0h1M7 15h10"/></svg><span id="text"></span></div>
28
+ <div id="avatar" aria-label="duet 3D 形象"></div>
29
+ <div id="tools"><span id="brand">duet<span id="dot">.</span></span><button id="size" type="button" aria-label="形象大小"></button>
30
+ <button data-mode="online" aria-label="打开交互模式" title="交互模式" disabled><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7.5 3.75 3 8.25m0 0 4.5 4.5M3 8.25h18m-4.5 3L21 15.75m0 0-4.5 4.5M21 15.75H3"/></svg></button>
31
+ <button data-mode="tts_only" aria-label="打开播报模式" title="播报模式" disabled><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 8h4l5-4v16l-5-4H4zM17 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14"/></svg></button>
32
+ <button id="close" aria-label="隐藏拟人角色" title="隐藏拟人角色"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="m6 6 12 12M18 6 6 18"/></svg></button></div>
33
+ <div id="status" role="status">正在连接 DSH</div></div></div><script type="module" src="./companion.mjs"></script></html>
@@ -0,0 +1,10 @@
1
+ {
2
+ "protocol": 2,
3
+ "files": {
4
+ "index.html": "a441808e27bfed10ac554d505a21d794a21ad0520dd2c276b3b20cab72ad1ac4",
5
+ "companion.mjs": "7fcc1e19214886472eb551b8c00bc846952417af7c45778145228840423f50ff",
6
+ "renderer.mjs": "2cbfccca5c10ca2dc720461b3a9a2c5b59a5ef679210206869fa9159316b5650",
7
+ "character.glb": "b2413d92e9417ceaced3227ebb3331c78692b9843a8d545d6e799eb195c9beab",
8
+ "portrait.png": "2271313cea7163f8c7f7acf88a5efa2605be7aea93fd93a55381048fc468ff27"
9
+ }
10
+ }