dsh-duet 0.3.0 → 0.3.2

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 (44) hide show
  1. package/assets/avatar/desktop/companion.mjs +3 -4
  2. package/assets/avatar/desktop/manifest.json +1 -1
  3. package/desktop/bin/darwin-arm64/duet-avatar.app/Contents/MacOS/duet-avatar +0 -0
  4. package/desktop/bin/darwin-arm64/manifest.json +3 -3
  5. package/desktop/bin/win32-x64/duet-avatar.exe +0 -0
  6. package/desktop/bin/win32-x64/manifest.json +3 -3
  7. package/node_modules/dsh-duet-superagent/lib/duet.d.ts +19 -3
  8. package/node_modules/dsh-duet-superagent/lib/duet.js +156 -10
  9. package/node_modules/dsh-duet-superagent/lib/{feishu-rAGM9U9b.js → feishu-CwKBb-B_.js} +1 -1
  10. package/node_modules/dsh-duet-superagent/lib/feishu-watch.d.ts +1 -1
  11. package/node_modules/dsh-duet-superagent/lib/feishu-watch.js +1 -1
  12. package/node_modules/dsh-duet-superagent/lib/{github-pull-gSbjzypm.js → github-pull-DyfAy0yE.js} +1 -1
  13. package/node_modules/dsh-duet-superagent/lib/github-watch.d.ts +1 -1
  14. package/node_modules/dsh-duet-superagent/lib/github-watch.js +2 -2
  15. package/node_modules/dsh-duet-superagent/lib/index.js +2 -2
  16. package/node_modules/dsh-duet-superagent/lib/{poll-Dh7J1cdM.js → poll-BBkmV_GM.js} +4 -1
  17. package/node_modules/dsh-duet-superagent/lib/{registry-BTgyFZ8S.d.ts → registry-Ehgir8LC.d.ts} +70 -61
  18. package/node_modules/dsh-duet-superagent/lib/{runtime-CbDPyQoo.js → runtime-Ow0S-7ZZ.js} +45 -5
  19. package/package.json +6 -2
  20. package/src/avatar/surface.mjs +6 -1
  21. package/src/client/agent-entry.mjs +27 -0
  22. package/src/client/agent-tasks.mjs +42 -10
  23. package/src/client/agent-tool-views.mjs +190 -0
  24. package/src/client/audio.mjs +1 -1
  25. package/src/client/avatar-surfaces.mjs +3 -3
  26. package/src/client/browser.mjs +35 -27
  27. package/src/client/composer-bridge.mjs +1 -1
  28. package/src/client/connection-hint.mjs +20 -5
  29. package/src/client/entry.js +10 -3
  30. package/src/client/feedback.mjs +1 -1
  31. package/src/client/identity.mjs +1 -1
  32. package/src/client/settings.html +84 -80
  33. package/src/client/tutorial-adapter.mjs +5 -5
  34. package/src/client/tutorial.mjs +1 -1
  35. package/src/client/work-mode.mjs +46 -9
  36. package/src/host/agent-connection.mjs +6 -1
  37. package/src/host/assets.mjs +2 -0
  38. package/src/host/plugin.mjs +4 -2
  39. package/src/shared/avatar-menu-ui.mjs +30 -12
  40. package/src/shared/avatar-menu.mjs +4 -1
  41. package/src/shared/avatar-surface.mjs +1 -0
  42. package/src/shared/avatar-ui.mjs +2 -0
  43. package/src/shared/state.mjs +1 -1
  44. package/src/shared/work-mode.mjs +64 -4
@@ -0,0 +1,190 @@
1
+ import {focusedSession,openLocalSession} from './composer.mjs'
2
+ import {TASK_STATES,taskCardState} from '../shared/work-mode.mjs'
3
+
4
+ const ticketId=value=>typeof value==='string'&&/^[a-f0-9]{32}$/.test(value)?value:null
5
+ const object=value=>{
6
+ if(typeof value!=='string')return value&&typeof value==='object'&&!Array.isArray(value)?value:null
7
+ if(value.length>512000)return null
8
+ try{return object(JSON.parse(value))}catch{return null}
9
+ }
10
+ const output=block=>(Array.isArray(block?.content)?block.content:[]).filter(p=>p?.type==='text'&&typeof p.text==='string').map(p=>p.text).join('\n')
11
+
12
+ // Ticket stages (working, working/queued, person/answer) differ from UI states.
13
+ // The successful routing receipt,
14
+ // not that lifecycle or the proposed arguments, identifies this historical event.
15
+ const routeEventState=item=>{
16
+ const kind=item.decision??item.kind
17
+ if(kind==='accept')return 'running'
18
+ if(kind==='attach')return 'progress'
19
+ if(kind==='stop')return 'stopped'
20
+ const stages={'working':'running','working/queued':'queued','person/answer':'waiting_user','person/review':'waiting_user','person/delivery':'ready','person/blocked':'blocked','person/failed':'failed','idle':'waiting'}
21
+ const state=item.ticket?.state
22
+ return typeof state==='string'?(Object.hasOwn(stages,state)?stages[state]:state):null
23
+ }
24
+
25
+ /** Only successful, explicit ticket references become links; never route by title. */
26
+ export function agentToolCard(toolName,block){
27
+ const settled=block?.kind==='tool-result',args=object(block?.call?.argsRaw??block?.argsRaw)||{}
28
+ const raw=output(block),result=object(raw),failed=!!block?.isError
29
+ const links=[],messages=[]
30
+ if(toolName==='orchestrator_route'&&settled&&!failed){
31
+ for(const item of (Array.isArray(result?.results)?result.results:[]).slice(0,100)){
32
+ if(item?.refused){messages.push(String(item.refused));continue}
33
+ const id=ticketId(item?.ticket?.ticket_id)
34
+ if(id&&!links.some(link=>link.ticket===id))links.push({ticket:id,name:typeof item.ticket.title==='string'?item.ticket.title:'',state:routeEventState(item),label:'打开会话',result:false})
35
+ }
36
+ }
37
+ if(toolName==='orchestrator_reply'&&settled&&!failed&&ticketId(args.ticket_id)&&['sent','pending'].includes(result?.status)){
38
+ links.push({ticket:args.ticket_id,name:'',state:args.purpose==='result'?'ready':args.purpose==='attention'?'waiting_user':null,label:args.purpose==='result'?'跳转到结果':'打开会话',result:args.purpose==='result',at:block.callTime??block.time})
39
+ }
40
+ const title=toolName==='orchestrator_route'?'任务安排':toolName==='orchestrator_report'?'任务报告':args.purpose==='attention'?'需要你确认':args.purpose==='result'?'任务结果':'任务回复'
41
+ return {title,links,messages,settled,failed,args,raw,text:typeof args.text==='string'?args.text:toolName==='orchestrator_report'&&typeof args.summary==='string'?args.summary:'',
42
+ reportTime:toolName==='orchestrator_report'&&settled&&!failed&&args.state==='ready'?block.time:null}
43
+ }
44
+
45
+ export function taskLinkPresentation(link,session){
46
+ const name=[link.name,session?.title].find(value=>typeof value==='string'&&value.trim())?.trim().slice(0,512)||'任务会话'
47
+ const state=typeof link.state==='string'&&Object.hasOwn(TASK_STATES,link.state)?link.state:null
48
+ const labels={running:'开始执行',progress:'继续执行',waiting_user:'向你提问'}
49
+ return {name,label:state?(labels[state]||TASK_STATES[state]):'已关联任务',tone:state?taskCardState({state}):'neutral'}
50
+ }
51
+
52
+ /** Turn-local links remain available when DSH folds the tool execution process. */
53
+ export function agentTurnLinks(snapshot,turn){
54
+ const links=new Map()
55
+ const visit=block=>{
56
+ if(!block)return
57
+ const name=block.call?.name??block.name
58
+ if(['orchestrator_route','orchestrator_reply'].includes(name)){
59
+ for(const link of agentToolCard(name,block).links){
60
+ const previous=links.get(link.ticket)
61
+ if(!previous||link.result)links.set(link.ticket,{...link,name:link.name||previous?.name||''})
62
+ }
63
+ }
64
+ for(const child of block.subCalls||[])visit(child)
65
+ }
66
+ for(const key of snapshot.locations.getTurn(turn)){
67
+ const node=snapshot.nodes.get(key)
68
+ if(node?.kind==='tool-call')visit(node.data.root)
69
+ }
70
+ return [...links.values()]
71
+ }
72
+
73
+ /** Land on the matching report's final chat node, not a newer run of the same ticket. */
74
+ export async function navigateAgentTool(ctx,link,signal){
75
+ const id=ticketId(link.ticket)
76
+ if(!id)throw Error('无法确定这个任务的会话。')
77
+ const target='worker-'+id
78
+ await ctx.sessions.refresh();signal.throwIfAborted()
79
+ if(!ctx.sessions.list.getSnapshot().byId?.[target])throw Error('这个任务会话暂时不可用,可能已被移除。')
80
+ await openLocalSession(ctx,target,signal)
81
+ if(!link.result)return ''
82
+ if(!Number.isFinite(link.at))return '已打开任务会话,暂时无法定位这次结果。'
83
+ for(let n=0;n<12;n++){
84
+ signal.throwIfAborted()
85
+ if(focusedSession(ctx)!==target)return ''
86
+ const reports=[...document.querySelectorAll('[data-duet-report-time]')].filter(node=>Number(node.dataset.duetReportTime)<=link.at)
87
+ .sort((a,b)=>Number(b.dataset.duetReportTime)-Number(a.dataset.duetReportTime))
88
+ const report=reports[0]
89
+ if(report){
90
+ const row=report.closest('[data-chat-turn]')
91
+ // DSH gives every node in a turn the same durable turn identity.
92
+ const peers=row?[...row.parentElement.querySelectorAll('[data-chat-turn]')].filter(node=>node.dataset.chatTurn===row.dataset.chatTurn&&node.getClientRects().length):[]
93
+ const end=peers.filter(node=>(node.dataset.chatFlowKind==='assistant'||node.dataset.turnProcessAnswer==='true')
94
+ && (report.compareDocumentPosition(node)&Node.DOCUMENT_POSITION_FOLLOWING)).at(-1)
95
+ if(end){end.scrollIntoView({block:'center',behavior:'auto'});return ''}
96
+ }
97
+ await new Promise(resolve=>setTimeout(resolve,100))
98
+ }
99
+ return '已打开任务会话;这次结果所在的历史内容尚未加载。'
100
+ }
101
+
102
+ /** Official keyed tool views: only duet's three tools are customized. */
103
+ export function mountAgentToolViews(ctx,React){
104
+ if(!ctx.slots?.inject||!React?.createElement)return ()=>{}
105
+ const {createElement:h,useState,useEffect,useRef}=React,cleanup=[]
106
+ let navigation=null,disposed=false
107
+ let noticeTimer
108
+ const notice=document.createElement('div')
109
+ notice.setAttribute('role','status');notice.hidden=true
110
+ notice.style.cssText='position:fixed;bottom:24px;left:50%;transform:translateX(-50%);z-index:100021;max-width:calc(100vw - 48px);padding:12px 18px;border-radius:12px;background:Canvas;color:CanvasText;box-shadow:0 4px 24px #0003;font:14px/1.6 system-ui;white-space:pre-wrap'
111
+ document.body.append(notice)
112
+ const showNotice=text=>{if(!text||disposed)return;clearTimeout(noticeTimer);notice.textContent=text;notice.hidden=false;noticeTimer=setTimeout(()=>{notice.hidden=true},6000)}
113
+ const css=document.createElement('style')
114
+ css.textContent='.duet-tool-card{font:inherit;color:inherit;margin:6px 0;padding:8px 0}.duet-tool-card header{display:flex;align-items:center;gap:8px;font-weight:600}.duet-tool-card p{white-space:pre-wrap;overflow-wrap:anywhere;margin:8px 0}.duet-tool-card .links{display:grid;gap:8px;margin:8px 0}.duet-tool-card .link-row{display:flex;align-items:center;flex-wrap:wrap;gap:8px}.duet-tool-card button{font:inherit;color:inherit;border:1px solid color-mix(in srgb,currentColor 20%,transparent);border-radius:8px;padding:4px 10px;background:transparent;cursor:pointer}.duet-tool-card button:hover{background:color-mix(in srgb,currentColor 8%,transparent)}.duet-tool-card button:focus-visible{outline:2px solid Highlight;outline-offset:2px}.duet-tool-card button:disabled{opacity:.5;cursor:default}.duet-tool-card summary{cursor:pointer;opacity:.65;font-size:12px}.duet-tool-card pre{white-space:pre-wrap;overflow-wrap:anywhere;max-height:280px;overflow:auto;font-size:12px}.duet-tool-card [role=status]{font-size:12px;opacity:.8}'
115
+ document.head.append(css)
116
+ css.textContent+=`
117
+ .duet-tool-card .links{gap:10px;margin:4px 0}
118
+ .duet-tool-card button.duet-task-link{display:flex;align-items:center;gap:12px;width:100%;max-width:660px;min-width:0;box-sizing:border-box;padding:14px 16px;text-align:start;border:1px solid color-mix(in srgb,CanvasText 10%,Canvas);border-radius:16px;background:color-mix(in srgb,Canvas 94%,transparent);box-shadow:0 2px 8px -4px #0002;transition:background .16s,border-color .16s,box-shadow .16s,transform .16s}
119
+ .duet-tool-card button.duet-task-link:hover:not(:disabled){background:color-mix(in srgb,Highlight 5%,Canvas);border-color:color-mix(in srgb,Highlight 30%,Canvas);box-shadow:0 6px 18px -8px #0003;transform:translateY(-1px)}
120
+ .duet-task-link .task-icon{display:grid;place-items:center;width:36px;height:36px;flex-shrink:0;border-radius:12px;background:light-dark(#edf3f9,#273848);color:light-dark(#527fa3,#9bc2e3)}
121
+ .duet-task-link[data-duet-task-tone=completed] .task-icon{background:light-dark(#e5f3ec,#203c30);color:light-dark(#328363,#8ecbaa)}
122
+ .duet-task-link[data-duet-task-tone=waiting] .task-icon{background:light-dark(#fcf1de,#423722);color:light-dark(#a67932,#e4bd78)}
123
+ .duet-task-link[data-duet-task-tone=failed] .task-icon{background:light-dark(#fae9e7,#442b2c);color:light-dark(#b65e57,#e7a49b)}
124
+ .duet-task-link svg{display:block;width:18px;height:18px;flex-shrink:0}
125
+ .duet-task-link .task-icon svg{width:22px;height:22px}
126
+ .duet-task-link .task-copy{display:grid;gap:4px;flex:1;min-width:0}
127
+ .duet-task-link .task-name{font-size:14px;font-weight:600;line-height:1.5;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
128
+ .duet-task-link .task-status{font-size:11px;font-weight:400;line-height:1.5;color:color-mix(in srgb,CanvasText 60%,Canvas)}
129
+ .duet-task-link .task-destination{display:flex;align-items:center;justify-content:flex-end;gap:5px;flex-shrink:0;font-size:12px;font-weight:450;color:color-mix(in srgb,CanvasText 65%,Canvas)}
130
+ .duet-task-link .task-destination svg{width:14px;height:14px}
131
+ @media(max-width:420px){.duet-tool-card button.duet-task-link{padding:12px;gap:9px}.duet-task-link .task-icon{width:28px;height:28px;border-radius:9px}.duet-task-link .task-destination{font-size:11px;gap:1px}.duet-task-link .task-name{font-size:13px}}
132
+ @media(prefers-reduced-motion:reduce){.duet-tool-card button.duet-task-link{transition:none;transform:none!important}}
133
+ `
134
+ // Heroicons v2.2.0, 24/outline (MIT), matching the sidebar controls.
135
+ const taskIcons={
136
+ running:['rocket-launch','M15.59 14.37a6 6 0 0 1-5.84 7.38v-4.8m5.84-2.58a14.98 14.98 0 0 0 6.16-12.12A14.98 14.98 0 0 0 9.631 8.41m5.96 5.96a14.926 14.926 0 0 1-5.841 2.58m-.119-8.54a6 6 0 0 0-7.381 5.84h4.8m2.581-5.84a14.927 14.927 0 0 0-2.58 5.84m2.699 2.7c-.103.021-.207.041-.311.06a15.09 15.09 0 0 1-2.448-2.448 14.9 14.9 0 0 1 .06-.312m-2.24 2.39a4.493 4.493 0 0 0-1.757 4.306 4.493 4.493 0 0 0 4.306-1.758M16.5 9a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z'],
137
+ completed:['check-circle','M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z'],
138
+ waiting:['question-mark-circle','M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 5.25h.008v.008H12v-.008Z'],
139
+ failed:['exclamation-circle','M12 9v3.75m9-.75a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 3.75h.008v.008H12v-.008Z'],
140
+ stopped:['stop-circle','M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z','M9 9.563C9 9.252 9.252 9 9.563 9h4.874c.311 0 .563.252.563.563v4.874c0 .311-.252.563-.563.563H9.564A.562.562 0 0 1 9 14.437V9.564Z'],
141
+ neutral:['clipboard-document-list','M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 0 0 2.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 0 0-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75 2.25 2.25 0 0 0-.1-.664m-5.8 0A2.251 2.251 0 0 1 13.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125H8.25ZM6.75 12h.008v.008H6.75V12Zm0 3h.008v.008H6.75V15Zm0 3h.008v.008H6.75V18Z'],
142
+ }
143
+ const icon=tone=>{
144
+ const [name,...paths]=taskIcons[tone]||taskIcons.neutral
145
+ return h('svg',{viewBox:'0 0 24 24',fill:'none',stroke:'currentColor',strokeWidth:1.5,'aria-hidden':true,'data-heroicon':name},
146
+ ...paths.map((d,key)=>h('path',{key,d,strokeLinecap:'round',strokeLinejoin:'round'})))
147
+ }
148
+ function Links({links}){
149
+ const [busy,setBusy]=useState(false),alive=useRef(true)
150
+ const descriptionPrefix=useRef(crypto.randomUUID()).current
151
+ const [,refresh]=useState(0)
152
+ useEffect(()=>ctx.sessions.list.subscribe?.(()=>refresh(n=>n+1)),[])
153
+ useEffect(()=>{alive.current=true;return ()=>{alive.current=false}},[])
154
+ const open=async link=>{
155
+ navigation?.abort();const controller=navigation=new AbortController()
156
+ setBusy(true);notice.hidden=true
157
+ try{const text=await navigateAgentTool(ctx,link,controller.signal);if(!controller.signal.aborted)showNotice(text)}
158
+ catch(error){if(!controller.signal.aborted)showNotice(error.message||'暂时无法打开任务会话。')}
159
+ finally{if(!disposed&&alive.current)setBusy(false)}
160
+ }
161
+ return h('div',{className:'links'},...links.map(link=>{
162
+ const item=taskLinkPresentation(link,ctx.sessions.list.getSnapshot().byId?.['worker-'+link.ticket])
163
+ return h('button',{className:'duet-task-link',key:link.ticket,type:'button',disabled:busy,'data-duet-task-tone':item.tone,'aria-label':link.label,'aria-describedby':descriptionPrefix+link.ticket,title:item.name+' · '+item.label,onClick:()=>void open(link)},
164
+ h('span',{className:'task-icon','aria-hidden':true},icon(item.tone)),
165
+ h('span',{className:'task-copy',id:descriptionPrefix+link.ticket},h('span',{className:'task-name'},item.name),h('span',{className:'task-status',title:'此轮任务回执'},item.label)),
166
+ h('span',{className:'task-destination','aria-hidden':true},link.label,h('svg',{viewBox:'0 0 20 20',fill:'none',stroke:'currentColor',strokeWidth:1.5,strokeLinecap:'round',strokeLinejoin:'round'},h('path',{d:'m8 5 5 5-5 5'}))))
167
+ }))
168
+ }
169
+ function Card({toolName,block,inspect}){
170
+ const card=agentToolCard(toolName,block)
171
+ return h('section',{className:'duet-tool-card','data-duet-report-time':card.reportTime??undefined},
172
+ h('header',null,card.title,h('small',null,card.failed?'执行失败':card.settled?'':'处理中…')),
173
+ card.text&&h('p',null,card.text),
174
+ h(Links,{links:card.links}),
175
+ ...card.messages.map((text,i)=>h('p',{key:i,role:'status'},text)),
176
+ h('details',null,h('summary',null,'调用详情'),h('pre',null,JSON.stringify(card.args,null,2).slice(0,30000)),h('pre',null,card.raw.slice(0,30000)),inspect&&h('button',{type:'button',onClick:inspect},'查看调用记录')))
177
+ }
178
+ function TurnLinks({turn,useChat}){
179
+ const serialized=useChat(snapshot=>JSON.stringify(agentTurnLinks(snapshot,turn.turn)))
180
+ const links=JSON.parse(serialized)
181
+ return links.length?h('nav',{className:'duet-tool-card','aria-label':'任务快捷操作','data-duet-turn-links':''},h(Links,{links})):null
182
+ }
183
+ const tail=ctx.slots.inject('conversation.chat.turnTail',()=>ctx.slots.register({name:'conversation.chat.turnTail',id:'dsh-duet-task-links'},TurnLinks))
184
+ if(typeof tail==='function')cleanup.push(tail)
185
+ for(const key of ['orchestrator_route','orchestrator_reply','orchestrator_report']){
186
+ const off=ctx.slots.inject('tool.call.toolview',()=>ctx.slots.register({name:'tool.call.toolview',key},Card))
187
+ if(typeof off==='function')cleanup.push(off)
188
+ }
189
+ return ()=>{disposed=true;navigation?.abort();clearTimeout(noticeTimer);notice.remove();for(const off of cleanup)off();css.remove()}
190
+ }
@@ -1,4 +1,4 @@
1
- import { microphoneConstraints } from './microphone.mjs?v=0.3.0'
1
+ import { microphoneConstraints } from './microphone.mjs?v=0.3.2'
2
2
  import { captionCue, captionAt, AudioCaptionTimeline } from '../shared/avatar.mjs'
3
3
 
4
4
  export const AUDIO_STOP_PROTOCOL = 'audio_stop_candidates_v1'
@@ -19,8 +19,8 @@ export function mountAvatarSurfaces({avatar,canActivate=()=>false}) {
19
19
  let action=actionIds.get(node);if(!action){action=`a${++actionSerial}`;actionIds.set(node,action)}
20
20
  const gesture=node.hasAttribute('data-duet-user-gesture')&&!canActivate()
21
21
  actions.set(action,node)
22
- const text=node.matches('summary')?[...node.children].map(n=>n.textContent).join('\n'):node.textContent
23
- nodes.push({kind:node.matches('input')?'checkbox':'button',text:node.matches('input')?'':text.slice(0,4000),action,disabled:node.disabled===true,checked:node.checked===true,gesture,label:node.getAttribute('aria-label')||node.closest('label')?.textContent.slice(0,100)||'',...(node.dataset.taskState?{taskState:node.dataset.taskState}:{})})
22
+ const text=node.matches('summary')?[...node.children].map(n=>n.textContent).join('\n'):(node.querySelector('[data-task-copy]')||node).textContent
23
+ nodes.push({kind:node.matches('input')?'checkbox':'button',text:node.matches('input')?'':text.slice(0,4000),action,disabled:node.disabled===true,checked:node.checked===true,gesture,label:node.getAttribute('aria-label')||node.closest('label')?.textContent.slice(0,100)||'',...(node.dataset.taskState?{taskState:node.dataset.taskState}:{}),...(node.hasAttribute('data-task-countdown')?{countdown:Number(node.dataset.taskCountdown)}:{})})
24
24
  return
25
25
  }
26
26
  if(/^H[1-6]$/.test(node.tagName)){nodes.push({kind:'heading',text:node.textContent.slice(0,4000)});return}
@@ -46,7 +46,7 @@ export function mountAvatarSurfaces({avatar,canActivate=()=>false}) {
46
46
  const key=JSON.stringify({id,nodes,target,layout}),changed=key!==last
47
47
  // Cosmetic countdown text does not invalidate an in-flight click. All other
48
48
  // content and action state still fence stale confirmations.
49
- const actionKey=JSON.stringify({id,target,nodes:nodes.map(n=>n.action&&actions.get(n.action)?.hasAttribute('data-duet-live-text')?{...n,text:''}:n)})
49
+ const actionKey=JSON.stringify({id,target,nodes:nodes.map(({countdown,...n})=>n.action&&actions.get(n.action)?.hasAttribute('data-duet-live-text')?{...n,text:''}:n)})
50
50
  if(changed)current={id,revision:(current?.revision||0)+(actionKey!==semantic?1:0),nodes,target,...(layout?{layout}:{})}
51
51
  semantic=actionKey
52
52
  // A real click must happen in the playback document. Keep that counterpart visible.
@@ -1,28 +1,29 @@
1
- import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.3.0'
2
- import { DuetAudio, AUDIO_STOP_PROTOCOL } from './audio.mjs?v=0.3.0'
3
- import { HarnessRPCExecutor, rpcNavigationSession } from './rpc.mjs?v=0.3.0'
4
- import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.3.0'
5
- import { startComposerBridge } from './composer-bridge.mjs?v=0.3.0'
6
- import { mountTutorial } from './tutorial.mjs?v=0.3.0'
1
+ import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.3.2'
2
+ import { DuetAudio, AUDIO_STOP_PROTOCOL } from './audio.mjs?v=0.3.2'
3
+ import { HarnessRPCExecutor, rpcNavigationSession } from './rpc.mjs?v=0.3.2'
4
+ import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.3.2'
5
+ import { startComposerBridge } from './composer-bridge.mjs?v=0.3.2'
6
+ import { mountTutorial } from './tutorial.mjs?v=0.3.2'
7
7
  import { mountAvatarTasks } from './avatar-tasks.mjs'
8
- import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.3.0'
9
- import { mountRating } from './feedback.mjs?v=0.3.0'
10
- import { createAudioUploadConsent } from './consent.mjs?v=0.3.0'
11
- import { bindDuetShortcuts } from './shortcuts.mjs?v=0.3.0'
12
- import { nativeInteractions } from './interactions.mjs?v=0.3.0'
13
- import { mountConnectionHint } from './connection-hint.mjs?v=0.3.0'
14
- import { mountControlsLayout } from './controls-layout.mjs?v=0.3.0'
15
- import { mountNotice } from './notice.mjs?v=0.3.0'
16
- import { browserSessionCatalog, sessionCreationPayload } from './workspaces.mjs?v=0.3.0'
8
+ import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.3.2'
9
+ import { mountRating } from './feedback.mjs?v=0.3.2'
10
+ import { createAudioUploadConsent } from './consent.mjs?v=0.3.2'
11
+ import { bindDuetShortcuts } from './shortcuts.mjs?v=0.3.2'
12
+ import { nativeInteractions } from './interactions.mjs?v=0.3.2'
13
+ import { mountConnectionHint } from './connection-hint.mjs?v=0.3.2'
14
+ import { mountControlsLayout } from './controls-layout.mjs?v=0.3.2'
15
+ import { mountNotice } from './notice.mjs?v=0.3.2'
16
+ import { browserSessionCatalog, sessionCreationPayload } from './workspaces.mjs?v=0.3.2'
17
17
  import { workModeOnboarding } from './work-mode.mjs'
18
+ import { agentEntryNavigation } from './agent-entry.mjs'
18
19
  import { workModeIssue, noteTaskVisit } from '../shared/work-mode.mjs'
19
- import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.3.0'
20
- import { identityFetch, identityVoiceProtocols } from './identity.mjs?v=0.3.0'
21
- import { sessionLabel } from '../shared/catalog.mjs?v=0.3.0'
22
- import { resultNotification } from '../shared/result-notification.mjs?v=0.3.0'
23
- import { HarnessSync } from './harness-sync.mjs?v=0.3.0'
24
- import { LocalSync } from './local-sync.mjs?v=0.3.0'
25
- import { diagnosticPayload } from '../shared/diagnostics.mjs?v=0.3.0'
20
+ import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.3.2'
21
+ import { identityFetch, identityVoiceProtocols } from './identity.mjs?v=0.3.2'
22
+ import { sessionLabel } from '../shared/catalog.mjs?v=0.3.2'
23
+ import { resultNotification } from '../shared/result-notification.mjs?v=0.3.2'
24
+ import { HarnessSync } from './harness-sync.mjs?v=0.3.2'
25
+ import { LocalSync } from './local-sync.mjs?v=0.3.2'
26
+ import { diagnosticPayload } from '../shared/diagnostics.mjs?v=0.3.2'
26
27
  import { mountAvatar } from './avatar.mjs'
27
28
  import { mountAvatarSurfaces } from './avatar-surfaces.mjs'
28
29
  import { audioUnlockPanel } from '../shared/avatar-ui.mjs'
@@ -41,7 +42,7 @@ export function mountDuet(ctx) {
41
42
  const resultResume = {}
42
43
  let localSync,avatarTasks,closeMenuSettings
43
44
  let clientTraceId = null, diagnosticCount = 0
44
- let connectionGuidance = null, reportHintShown = null
45
+ let connectionGuidance = null, reportHintShown = null, connectionWorkMode = null
45
46
  let tutorial, teaching, ratingPanel, connectionHint, stopControlsLayout, stopSettings, avatar
46
47
  const modeActions=new Map()
47
48
  let unlockPanel
@@ -86,12 +87,13 @@ export function mountDuet(ctx) {
86
87
  const mark = controls.querySelector('[data-duet-mark]')
87
88
  mark.style.color = state.ready ? '#7fd6a6' : '#ed9b35'
88
89
  mark.title = state.ready ? '语音已连接' : '语音未连接'
89
- connectionHint?.update({ mode: state.mode, ready: state.ready, teaching: Boolean(tutorial?.active), guidance:connectionGuidance })
90
+ connectionHint?.update({ mode: state.mode, ready: state.ready, teaching: Boolean(tutorial?.active), guidance:connectionGuidance,
91
+ workMode:connectionWorkMode,connectionId:clientTraceId })
90
92
  }
91
93
  const connect = (mode, receive) => {
92
94
  if (!audioConsent.granted()) throw Error('data_upload_consent_required')
93
95
  clientTraceId = crypto.randomUUID(); diagnosticCount = 0
94
- connectionGuidance = null; reportHintShown = null
96
+ connectionGuidance = null; reportHintShown = null; connectionWorkMode = null
95
97
  const connectionTraceId = clientTraceId
96
98
  const started = performance.now()
97
99
  let firstInput = false
@@ -106,6 +108,8 @@ export function mountDuet(ctx) {
106
108
  }
107
109
  let ws, closed = false, release, ready = false, stopComposer, stopBridge, agentMode = false
108
110
  const opening = new AbortController()
111
+ let autoSwitchSession=true
112
+ const agentEntry=agentEntryNavigation(ctx,opening.signal,()=>autoSwitchSession)
109
113
  const startupTimer = setTimeout(() => {
110
114
  if (!closed) receive({ type: 'error', code: 'voice_start_timeout' })
111
115
  }, 45000)
@@ -191,7 +195,9 @@ export function mountDuet(ctx) {
191
195
  const issue = workModeIssue(configuration)
192
196
  if(issue){void workMode.show();throw Error(issue)}
193
197
  agentMode = configuration.work_mode === 'agent'
198
+ autoSwitchSession = configuration.agent_options?.auto_switch_session !== false
194
199
  if(closed)return
200
+ connectionWorkMode=agentMode?'agent':'direct'
195
201
  if (mode === 'online' && !agentMode) stopBridge = startComposerBridge(ctx, connectionTraceId, fetch, localSync,
196
202
  (text,id)=>avatar?.inputWritten(text,id))
197
203
  ws = new WebSocket(voiceSocketUrl({ mode, plugin_version: PLUGIN_VERSION, client_trace_id: connectionTraceId, page_id: pageId }), identityVoiceProtocols())
@@ -206,11 +212,12 @@ export function mountDuet(ctx) {
206
212
  try {
207
213
  message = JSON.parse(event.data)
208
214
  if(message.type==='duet.local.tasks'){
215
+ if(agentMode&&mode==='online')agentEntry.frame(message)
209
216
  if(agentMode)try{
210
217
  const {agentTaskPanel}=await import('./agent-tasks.mjs')
211
218
  if(closed||disposed)return
212
219
  agentTasks??=agentTaskPanel(ctx,()=>controls,text=>notice(text),()=>avatar?.presentation())
213
- agentTasks.update(message,mode==='online'||message.focus_reason==='result')
220
+ agentTasks.update(message,autoSwitchSession&&(mode==='online'||message.focus_reason==='result'))
214
221
  }catch{/* A missing presentation module must not stop the voice connection. */}
215
222
  return
216
223
  }
@@ -267,6 +274,7 @@ export function mountDuet(ctx) {
267
274
  if (!closed) {
268
275
  clearTimeout(startupTimer)
269
276
  receive({ type: 'ready' })
277
+ if(agentMode&&mode==='online')agentEntry.connected()
270
278
  try { audio.connectedChime() } catch { /* A notification must not break voice. */ }
271
279
  }
272
280
  }
@@ -399,7 +407,7 @@ export function mountDuet(ctx) {
399
407
  stopControlsLayout?.()
400
408
  stopControlsLayout = mountControlsLayout(controls)
401
409
  connectionHint?.dispose()
402
- connectionHint = mountConnectionHint(controls,{onShown:hint=>reportHintShown?.(hint)})
410
+ connectionHint = mountConnectionHint(controls,{onShown:hint=>reportHintShown?.(hint),onSettings:()=>settings.click()})
403
411
  draw(state)
404
412
  avatar?.syncToggle()
405
413
  }
@@ -1,5 +1,5 @@
1
1
  /** Composer requests belong to one explicit voice/tutorial connection, never all tabs. */
2
- import { focusedSession as currentSession } from './composer.mjs?v=0.3.0'
2
+ import { focusedSession as currentSession } from './composer.mjs?v=0.3.2'
3
3
 
4
4
  export function startComposerBridge(ctx, clientId, fetchImpl = fetch, feed = null, onWrite = () => {}) {
5
5
  const focusedSession = () => currentSession(ctx)
@@ -1,15 +1,26 @@
1
1
  /** A brief, non-modal invitation after the microphone is actually ready. */
2
- import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.3.0'
3
- export function mountConnectionHint(controls, { duration = 8000, onShown = ()=>{} } = {}) {
2
+ import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.3.2'
3
+ import {AGENT_WORKSPACE_NOTICE,agentEntryReminder} from '../shared/work-mode.mjs'
4
+ export function mountConnectionHint(controls, { duration = 8000, onShown = ()=>{}, onSettings = ()=>{} } = {}) {
4
5
  const hint = document.createElement('div')
5
6
  hint.dataset.duetConnectionHint = ''
6
7
  hint.dataset.duetAvatarSurface = '30'
7
8
  hint.setAttribute('role', 'status')
8
9
  hint.setAttribute('aria-live', 'polite')
9
10
  hint.hidden = true
10
- hint.style.cssText = 'position:fixed;z-index:100020;box-sizing:border-box;width:268px;max-width:calc(100vw - 32px);padding:12px 15px;border:1px solid #a5d8f4;border-radius:12px;background:#eff9ff;color:#163c56;font:13px/1.65 system-ui,sans-serif;box-shadow:0 8px 28px #153e6524;pointer-events:none'
11
+ hint.style.cssText = 'position:fixed;z-index:100020;box-sizing:border-box;width:268px;max-width:calc(100vw - 32px);padding:12px 15px;border:1px solid #a5d8f4;border-radius:12px;background:#eff9ff;color:#163c56;font:13px/1.65 system-ui,sans-serif;box-shadow:0 8px 28px #153e6524;pointer-events:auto;-webkit-user-select:text;user-select:text'
11
12
  const text=document.createTextNode(normalizeGuidance(null).text)
12
13
  hint.append(text)
14
+ const reminder=document.createElement('div');reminder.hidden=true;reminder.style.marginTop='8px'
15
+ reminder.dataset.duetAgentReminder=''
16
+ const emphasis=document.createElement('strong');emphasis.textContent='只能'
17
+ const [before,after]=AGENT_WORKSPACE_NOTICE.split('只能');reminder.append(before,emphasis,after)
18
+ const actions=document.createElement('div');actions.style.cssText='display:flex;flex-wrap:wrap;gap:8px;margin-top:8px'
19
+ const settings=document.createElement('button');settings.type='button';settings.textContent='打开设置'
20
+ const acknowledge=document.createElement('button');acknowledge.type='button';acknowledge.textContent='我知道了'
21
+ for(const button of [settings,acknowledge])button.style.cssText='padding:4px 12px;border:1px solid #a5d8f4;border-radius:8px;background:white;color:#185a89;cursor:pointer;font:inherit;pointer-events:auto;-webkit-user-select:none;user-select:none'
22
+ settings.onclick=()=>{hide();onSettings()};acknowledge.onclick=()=>hide()
23
+ actions.append(settings,acknowledge);hint.append(reminder,actions)
13
24
  const arrow = document.createElement('span')
14
25
  arrow.setAttribute('aria-hidden', 'true')
15
26
  arrow.style.cssText = 'position:absolute;bottom:-6px;width:10px;height:10px;transform:rotate(45deg);background:#eff9ff;border-right:1px solid #a5d8f4;border-bottom:1px solid #a5d8f4'
@@ -42,17 +53,21 @@ export function mountConnectionHint(controls, { duration = 8000, onShown = ()=>{
42
53
  observer.observe(controls)
43
54
  return {
44
55
  dismiss: hide,
45
- update({ mode, ready, teaching = false, guidance }) {
56
+ update({ mode, ready, teaching = false, guidance, workMode, connectionId }) {
46
57
  if (disposed) return
47
58
  const active = mode === 'online' && ready
48
59
  if (!active || teaching) hide()
49
60
  if (active && !wasReady && !teaching) {
50
61
  const actual=normalizeGuidance(guidance)
51
62
  text.textContent=actual.text
63
+ reminder.hidden=workMode!=='agent'||!agentEntryReminder(connectionId)
64
+ settings.hidden=reminder.hidden
65
+ actions.hidden=workMode!=='agent'
66
+ actions.style.display=actions.hidden?'none':'flex'
52
67
  hint.hidden = false
53
68
  position()
54
69
  clearTimeout(timer)
55
- timer = setTimeout(hide, duration)
70
+ timer = setTimeout(hide, reminder.hidden ? duration : Math.max(duration,20000))
56
71
  try{onShown(actual)}catch{ /* Diagnostics must never break the tooltip. */ }
57
72
  }
58
73
  wasReady = active
@@ -1,19 +1,26 @@
1
1
  window.__ModuleLoader__.load({
2
2
  id: "dsh-duet",
3
- factory: () => {
3
+ factory: (require) => {
4
4
  const module = { exports: {} }
5
5
  const exports = module.exports
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
7
7
 
8
- const inject = ["sessions", "conversation", "uiSession", "workspaces"]
8
+ const inject = ["sessions", "conversation", "uiSession", "workspaces", "slots", "uiWorkspace"]
9
9
 
10
10
  function apply(ctx) {
11
+ ctx.effect(() => {
12
+ let active=true,dispose
13
+ import('/duet/assets/client/agent-tool-views.mjs?v=0.3.2').then(module=>{
14
+ if(active&&ctx.slots&&typeof require==='function')dispose=module.mountAgentToolViews(ctx,require('react'))
15
+ }).catch(error=>console.warn('duet task cards could not load:',error))
16
+ return ()=>{active=false;dispose?.()}
17
+ }, 'duet-client: task navigation cards')
11
18
  let loadFailure = false
12
19
  let showLoadFailure = () => {}
13
20
  ctx.effect(() => {
14
21
  let active = true
15
22
  let dispose
16
- import('/duet/assets/client/browser.mjs?v=0.3.0').then(module => {
23
+ import('/duet/assets/client/browser.mjs?v=0.3.2').then(module => {
17
24
  if (active) dispose = module.mountDuet(ctx)
18
25
  }).catch(error => {
19
26
  console.warn('duet controls could not load:', error)
@@ -1,5 +1,5 @@
1
1
  /** Optional, explicit rating; never opens voice or submits without a user click. */
2
- import { identityFetch } from './identity.mjs?v=0.3.0'
2
+ import { identityFetch } from './identity.mjs?v=0.3.2'
3
3
 
4
4
  export function mountRating(anchor, sessionTicket, {origin='page'} = {}) {
5
5
  if(!sessionTicket)return null
@@ -1,5 +1,5 @@
1
1
  import { IDENTITY_HEADER, IDENTITY_TRANSPORT_HEADER, IDENTITY_TRANSPORT, IDENTITY_STORAGE,
2
- VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX, validIdentityToken } from '../shared/identity.mjs?v=0.3.0'
2
+ VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX, validIdentityToken } from '../shared/identity.mjs?v=0.3.2'
3
3
 
4
4
  /** Desktop strips plugin cookies. Keep the Host-signed value in its origin storage. */
5
5
  export function createIdentityClient(globals = globalThis) {