dsh-remote-plugin 0.7.6 → 0.8.0-rc.3

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.
@@ -0,0 +1,366 @@
1
+ /* 0.8 task navigation. Existing controllers retain all protocol ownership. */
2
+ ;(function(root) {
3
+ 'use strict'
4
+ let config, sheet, connectionButton, attention, operationList
5
+ let receiptIdentity=''
6
+ const $ = id => document.getElementById(id)
7
+ const label = (zh,en) => root.I18N?.lang === 'en' ? en : zh
8
+ function element(tag,cls,text) { const el=document.createElement(tag);if(cls)el.className=cls;if(text)el.textContent=text;return el }
9
+ function icon(name) {
10
+ const paths={host:'M3 4h18v12H3zM8 21h8m-4-5v5',plugins:'M9 3h6v6h6v6h-6v6H9v-6H3V9h6z',
11
+ receipts:'M6 3h12v18l-3-2-3 2-3-2-3 2zM9 8h6m-6 4h6',general:'M12 3v3m0 12v3M3 12h3m12 0h3M6 6l2 2m8 8 2 2M6 18l2-2M16 8l2-2M16 12a4 4 0 1 1-8 0 4 4 0 0 1 8 0',
12
+ model:'m12 3 9 5-9 5-9-5zM3 12l9 5 9-5M3 16l9 5 9-5',notify:'M6 9a6 6 0 0 1 12 0c0 7 3 7 3 8H3c0-1 3-1 3-8m4 12h4',about:'M12 11v6m0-10v.1M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0'}
13
+ const svg=document.createElementNS('http://www.w3.org/2000/svg','svg')
14
+ for(const [key,value] of Object.entries({viewBox:'0 0 24 24',fill:'none',stroke:'currentColor','stroke-width':'1.7','stroke-linecap':'round','stroke-linejoin':'round','aria-hidden':'true'}))svg.setAttribute(key,value)
15
+ const path=document.createElementNS(svg.namespaceURI,'path');path.setAttribute('d',paths[name]||paths.host);svg.append(path);return svg
16
+ }
17
+ function button(zh,en,action,cls='workflow-button') {
18
+ const el=element('button',cls),caption=element('span');el.type='button';caption.dataset.flowZh=zh;caption.dataset.flowEn=en;el.append(caption)
19
+ el.addEventListener('click',action);return el
20
+ }
21
+ function rename(target,zh,en) {
22
+ if(!target)return
23
+ target.removeAttribute('data-i18n');target.dataset.flowZh=zh;target.dataset.flowEn=en
24
+ }
25
+ function restoreAttention() {
26
+ const list=$(config?.desktop?'ds-overview-attention-list':'overview-attention-list')
27
+ if(list&&attention&&!attention.contains(list))attention.append(list)
28
+ }
29
+ function openSheet(title,content) {
30
+ restoreAttention()
31
+ operationList=null
32
+ sheet.querySelector('h2').textContent=title
33
+ const body=sheet.querySelector('.workflow-sheet-body')
34
+ for(const child of [...body.children])if(child.id==='workflow-model-content'){child.hidden=true;document.body.append(child)}
35
+ if(content.id==='workflow-model-content')content.hidden=false
36
+ body.replaceChildren(content)
37
+ if(!sheet.open)sheet.showModal()
38
+ }
39
+ function close() { restoreAttention();operationList=null;sheet?.close() }
40
+ function openModels() {
41
+ const content=$('workflow-model-content')
42
+ if(content)openSheet(label('模型与思考深度','Model and reasoning'),content)
43
+ config.models?.()
44
+ }
45
+ async function showOperations() {
46
+ const content=element('div'),pending=element('section'),receipts=element('section')
47
+ pending.append(element('h3','',label('待审批与待回答','Approvals and questions')))
48
+ receipts.append(element('h3','',label('操作回执','Operation receipts')),
49
+ element('p','workflow-muted',label('回执用于查询网络中断后尚未确认的操作结果。','Receipts track operation results after a connection interruption.')))
50
+ const rows=element('div');receipts.append(rows);content.append(pending,receipts)
51
+ openSheet(label('审批与操作回执','Approvals and receipts'),content);operationList=rows
52
+ const list=$(config.desktop?'ds-overview-attention-list':'overview-attention-list')
53
+ if(list)pending.append(list)
54
+ // Question dialogs use the existing modal controller, above the page.
55
+ pending.addEventListener('click',event=>{if(event.target.closest('[data-overview-question],[data-ds-overview-question]'))close()},true)
56
+ void refreshOperations()
57
+ try { if(config.operations)await root.DshOperations?.restore(config.operations()) }
58
+ catch { if(operationList===rows)rows.append(element('p','workflow-muted',label('暂时无法读取回执,可稍后重新打开。','Unable to read receipts. Try again shortly.')));return }
59
+ if(operationList===rows)void refreshOperations()
60
+ }
61
+ async function refreshOperations() {
62
+ if(!operationList||!sheet.open)return
63
+ const target=operationList;target.replaceChildren()
64
+ const rows=root.DshOperations?.pending()||[]
65
+ if(!rows.length)target.append(element('p','workflow-muted',label('没有待确认操作。','No unconfirmed operations.')))
66
+ for(const row of rows){
67
+ const item=element('div','workflow-receipt')
68
+ item.append(element('strong','',row.method),element('code','',row.id),element('span','workflow-muted',label('结果待确认,不会自动重复提交','Unconfirmed; never automatically submitted again')))
69
+ const check=button('查询结果','Check result',async()=>{
70
+ check.disabled=true
71
+ try {
72
+ const value=await root.DshOperations.check(row.id)
73
+ if(!sheet.open||target!==operationList)return
74
+ item.append(element('p','',value?label('当前状态:','Status: ')+value.phase:label('暂时无法确认,请核对会话。','Unable to confirm. Check the conversation.')))
75
+ if(value?.phase==='complete'){config.refresh();config.recover?.(row,value);check.remove()}
76
+ }catch{item.append(element('p','',label('网络不可达,可稍后查询。','Network unavailable. Check later.')))}
77
+ finally{check.disabled=false}
78
+ });item.append(check)
79
+ if(row.phase==='unknown')item.append(button('核对后结束跟踪','Finish tracking after checking',()=>{
80
+ if(!root.confirm(label('请先核对主机会话记录。结束跟踪后,相同操作将作为新请求提交;如果原操作已执行,再次提交会重复。确定结束跟踪?','Check the conversation on the host first. After tracking ends, the same action will create a new request and may duplicate a completed action. Finish tracking?')))return
81
+ if(root.DshOperations.dismiss(row.id))void refreshOperations()
82
+ }))
83
+ target.append(item)
84
+ }
85
+ translate()
86
+ }
87
+ async function preview(connection,path,name) {
88
+ if(!connection.valid())return
89
+ const content=element('div'),status=element('p','workflow-muted',label('正在读取…','Loading…'));content.append(status)
90
+ openSheet(name,content)
91
+ try{
92
+ const url=new URL(connection.server+'/fs/preview',location.href);url.searchParams.set('path',path)
93
+ const response=await root.fetch(url,{headers:connection.headers,signal:AbortSignal.timeout(root.DshNetwork?.profile().readTimeout||45000)})
94
+ const value=await response.json()
95
+ if(!connection.valid()||!sheet.open||!sheet.contains(content))return
96
+ if(!response.ok)throw Error(value.error||('HTTP '+response.status))
97
+ content.replaceChildren(element('code','workflow-muted',value.path||path))
98
+ const source=element('pre','workflow-file-source',value.content||'');content.append(source)
99
+ if(/\.md$|\.markdown$/i.test(name)&&root.mdToHtml){
100
+ const rendered=element('div','workflow-file-markdown');rendered.innerHTML=root.mdToHtml(value.content||'');content.append(rendered);source.hidden=true
101
+ const toggle=button('源码 / 预览','Source / preview',()=>{source.hidden=!source.hidden;rendered.hidden=!rendered.hidden})
102
+ content.prepend(toggle);translate()
103
+ }
104
+ }catch(error){if(connection.valid()&&sheet.open&&sheet.contains(content))status.textContent=label('无法预览:','Unable to preview: ')+error.message}
105
+ }
106
+ function connectionDetails() {
107
+ const content=element('div','workflow-connection-content'),snapshot=config.snapshot()
108
+ content.append(element('p','',snapshot.host||label('当前页面主机','Current host')))
109
+ content.append(element('p','workflow-muted',label('连接主机后,工作区与会话始终归属这台主机。','Workspaces and conversations belong to the selected host.')))
110
+ const links=$(config.desktop?'view-overview':'view-activity')
111
+ if(links){
112
+ const details=element('details','workflow-technical'),summary=element('summary','',label('连接与运行详情','Connection details'))
113
+ details.append(summary);const clone=element('div','workflow-link-status')
114
+ for(const [key,name] of [['gateway','网关 / Gateway'],['dsh','DSH'],['mux','实时 / mux'],['hostEvents','主机事件 / host']]){
115
+ clone.append(element('p','',name+' · '+(snapshot[key]?label('在线','Online'):label('未就绪','Not ready'))))
116
+ }
117
+ details.append(clone);content.append(details)
118
+ }
119
+ content.append(button('重新检查','Check connection',()=>{config.retry();close()}),button('主机与连接','Hosts and connections',()=>{close();config.settings('servers')}))
120
+ if(snapshot.gateway)content.append(button('打开管理控制台','Open management console',()=>config.admin()))
121
+ openSheet(label('当前主机','Current host'),content);translate()
122
+ }
123
+ function setupMore() {
124
+ const home=$('settings-home');if(!home)return
125
+ const intro=element('div','workflow-page-head');const heading=element('h1');rename(heading,'更多','More');intro.append(heading);home.prepend(intro)
126
+ const plugins=button('主机插件','Host plugins',()=>config.plugins(),'workflow-setting-link')
127
+ const receipts=button('审批与操作回执','Approvals and receipts',showOperations,'workflow-setting-link')
128
+ const main=home.querySelector('.settings-group,.ds-settings');main?.prepend(plugins);main?.append(receipts)
129
+ const names={servers:['主机与连接','Hosts and connections'],general:['外观与输入','Appearance and input'],model:['模型与提供方','Models and providers'],notify:['通知与后台','Notifications and background'],about:['关于与维护','About and maintenance']}
130
+ const descriptions={servers:['连接地址、访问令牌与公网中转','Addresses, access tokens and cloud relay'],general:['主题、语言、输入与常用提示词','Theme, language, input and reusable prompts'],model:['提供方、访问凭据与模型目录','Providers, credentials and model catalog'],notify:['消息提醒与后台接收','Event notifications and background delivery'],about:['版本、公告、反馈与本地数据','Version, announcements, feedback and local data']}
131
+ for(const [key,nameset] of Object.entries(names)){
132
+ const row=home.querySelector(`[data-settings-group="${key}"]`)
133
+ rename(row?.querySelector('.setting-name,.ds-setting-name'),...nameset)
134
+ rename(row?.querySelector('.setting-desc,.ds-setting-desc'),...descriptions[key])
135
+ const page=$('settings-page-'+key)
136
+ rename(page?.querySelector('[data-settings-back] .setting-name,[data-settings-back] .ds-setting-name'),...nameset)
137
+ if(row){const mark=element('span','workflow-setting-icon');mark.append(icon(key==='servers'?'host':key));row.prepend(mark)}
138
+ }
139
+ for(const [target,name] of [[plugins,'plugins'],[receipts,'receipts']]){const mark=element('span','workflow-setting-icon');mark.append(icon(name));target.prepend(mark)}
140
+ const work=element('section','workflow-more-group'),preferences=element('section','workflow-more-group')
141
+ const workTitle=element('h2'),preferenceTitle=element('h2');rename(workTitle,'连接与工作','Connections and work');rename(preferenceTitle,'偏好与维护','Preferences and maintenance')
142
+ const workList=element('div','workflow-settings-list'),preferenceList=element('div','workflow-settings-list')
143
+ const host=home.querySelector('[data-settings-group="servers"]');if(host)workList.append(host)
144
+ workList.append(plugins,receipts);work.append(workTitle,workList)
145
+ for(const name of ['general','model','notify','about']){const row=home.querySelector(`[data-settings-group="${name}"]`);if(row)preferenceList.append(row)}
146
+ preferences.append(preferenceTitle,preferenceList);home.append(work,preferences)
147
+ home.querySelector('[data-settings-group="tests"]')?.remove()
148
+ home.querySelector('[data-settings-group="theme"]')?.remove()
149
+ const general=$('settings-page-general'),theme=$('settings-page-theme')
150
+ if(general&&theme){
151
+ const groups=config.desktop?[...theme.querySelectorAll(':scope > .ds-setting-row')].slice(1):[...theme.querySelectorAll('.settings-group')].slice(1)
152
+ for(const group of groups)general.append(group)
153
+ }
154
+ const defaultMode=$('busy-send-mode')?.closest('.setting-row');if(defaultMode)defaultMode.hidden=true
155
+ const gesture=$('opt-steer-send')?.closest('.setting-row')
156
+ rename(gesture?.querySelector('.setting-name'),'长按快捷插队','Hold to steer')
157
+ rename(gesture?.querySelector('.setting-desc'),'运行时长按发送可插队;普通点击仍排队。','Hold to steer while running; clicking still queues.')
158
+ for(const id of ['btn-change-token','token-desc','desktop-token-input']){
159
+ const row=$(id)?.closest('.setting-row,.ds-setting-row,.desktop-connect-form')
160
+ if(row&&home.contains(row))$('settings-page-servers')?.append(row)
161
+ }
162
+ const language=$('btn-lang')?.closest('.setting-row,.ds-setting-row')
163
+ if(language&&home.contains(language))general?.append(language)
164
+ const about=$('settings-page-about'),servers=$('settings-page-servers')
165
+ if(about&&config.feedback)about.append(button('提交反馈','Send feedback',config.feedback))
166
+ for(const id of ['btn-dsh-start','btn-host-describe']){const row=$(id)?.closest('.setting-row,.ds-setting-row');if(row&&about?.contains(row))servers?.append(row)}
167
+ const support=home.querySelector('.feedback-card');if(support)about?.append(support)
168
+ home.querySelector('p.about')?.remove()
169
+ const data=element('section','workflow-data-settings');data.append(element('h3','',label('本地数据','Local data')))
170
+ data.append(button('清除历史缓存','Clear history cache',()=>config.clear('history')),button('移除当前连接','Remove current connection',()=>config.clear('connection')),button('清除全部本地配置','Clear all local settings',()=>config.clear('all'),'workflow-button workflow-danger'))
171
+ about?.append(data)
172
+ const reset=$('btn-reset')?.closest('.setting-row,.ds-setting-row');if(reset)reset.hidden=true
173
+ for(const group of home.querySelectorAll('.settings-group,.ds-settings')){
174
+ if(!group.children.length)group.remove()
175
+ else if([...group.children].every(child=>child.hidden||child.classList.contains('hidden')))group.hidden=true
176
+ }
177
+ const wb=$(config.desktop?'workbench-box':'workbench-bar')
178
+ if(wb&&servers){const details=element('details','workflow-technical'),summary=element('summary','',label('高级目录组织(原工作台)','Advanced folder organization'))
179
+ details.append(summary,wb,button('发现并登记子目录','Discover subfolders',()=>config.discover()));servers.append(details)}
180
+ if(servers)servers.append(button('打开管理控制台','Open management console',()=>config.admin()))
181
+ const workspace=$('modal-workspace')?.querySelector('.modal-body,.ds-modal-body')
182
+ if(workspace&&config.register)workspace.append(button('使用当前目录,不新建文件夹','Use current folder',()=>config.register()))
183
+ const noWorkspaces=$('new-session-empty')
184
+ if(noWorkspaces)noWorkspaces.after(button('浏览主机目录','Browse host folders',()=>{config.browse?.()}))
185
+ const notify=$('settings-page-notify')
186
+ if(notify){
187
+ const more=element('details','workflow-technical');more.append(element('summary','',label('后台间隔与通知排障','Background interval and diagnostics')))
188
+ for(const id of ['bg-interval','btn-test-notify']){const row=$(id)?.closest('.setting-row');if(row)more.append(row)}
189
+ notify.append(more)
190
+ }
191
+ }
192
+ function setupComposer() {
193
+ if(!config.desktop){
194
+ const content=element('div');content.id='workflow-model-content'
195
+ for(const id of ['menu-models','menu-effort-group']){const row=$(id);if(row)content.append(id==='menu-models'?row.closest('.menu-group'):row)}
196
+ content.hidden=true;document.body.append(content)
197
+ const controls=element('div','workflow-composer-config')
198
+ const models=button('模型','Model',()=>{content.hidden=false;openModels()});models.id='workflow-models';models.prepend(icon('model'));controls.append(models)
199
+ $('composer-wrap')?.querySelector('.composer')?.append(controls)
200
+ rename($('btn-plus'),'指令','Commands')
201
+ }
202
+ const send=$('btn-send');if(!send)return
203
+ const alternate=button('插队发送','Steer',()=>config.send('steer'),'workflow-button workflow-steer')
204
+ alternate.id='workflow-steer';send.after(alternate)
205
+ const actions=$('session-actions')
206
+ if(actions){
207
+ actions.append(button('查看工作区文件','Workspace files',()=>{actions.close();config.files()}),
208
+ button('导出会话','Export conversation',()=>{actions.close();void config.command('/export')}),
209
+ button('压缩上下文','Compact context',()=>{actions.close();void config.command('/compact')}))
210
+ }
211
+ for(const el of document.querySelectorAll('[data-cmd="/compact"],[data-cmd="/export"],[data-ds-cmd="/compact"],[data-ds-cmd="/export"]'))el.remove()
212
+ }
213
+ function setupSecondaryPages() {
214
+ const definitions={
215
+ general:{title:['外观与输入','Appearance and input'],intro:['按你的习惯调整显示、输入与常用提示词。','Adjust display, input and reusable prompts to suit your workflow.'],icon:'general',groups:[['input','对话与输入','Conversation and input'],['appearance','外观与语言','Appearance and language'],['presets','预设提示词','Reusable prompts']]},
216
+ servers:{title:['主机与连接','Hosts and connections'],intro:['管理连接地址、访问令牌与公网中转。','Manage host addresses, access tokens and relay connections.'],icon:'host',groups:[['local','连接地址','Host addresses'],['access','访问令牌','Access token'],['relay','云服务器中转','Cloud relay'],['host','主机管理','Host management'],['advanced','高级选项','Advanced options']]},
217
+ model:{title:['模型与提供方','Models and providers'],intro:['配置当前主机的模型提供方与访问凭据。','Configure model providers and credentials on the current host.'],icon:'model',groups:[['main','提供方配置','Provider configuration']]},
218
+ notify:{title:['通知与后台','Notifications and background'],intro:['选择需要提醒的事项,并管理后台接收方式。','Choose which events to hear about and how to receive them in the background.'],icon:'notify',groups:[['main','消息与提醒','Messages and reminders'],['advanced','后台与排障','Background and diagnostics']]},
219
+ about:{title:['关于与维护','About and maintenance'],intro:['查看版本与公告,获取帮助或管理本地数据。','Find version information, announcements, help and local data controls.'],icon:'about',groups:[['main','版本与项目','Version and project'],['announcements','公告','Announcements'],['support','反馈与支持','Feedback and support'],['data','本地数据','Local data']]},
220
+ theme:{title:['外观','Appearance'],intro:['选择你喜欢的配色。','Choose your preferred color palette.'],icon:'general',groups:[['main','配色','Color palette']]},
221
+ tests:{title:['功能测试','Diagnostics'],intro:['检查当前设备与主机的可用能力。','Check the capabilities of this device and host.'],icon:'host',groups:[['main','功能检查','Capability checks']]},
222
+ }
223
+ const includes=(node,selector)=>node.matches(selector)||!!node.querySelector(selector)
224
+ for(const [key,definition] of Object.entries(definitions)){
225
+ const page=$('settings-page-'+key);if(!page||page.classList.contains('workflow-subpage'))continue
226
+ const oldBack=page.querySelector('[data-settings-back]'),oldGroup=oldBack?.parentElement
227
+ oldBack?.remove()
228
+ if(oldGroup!==page&&oldGroup?.classList.contains('settings-group')&&!oldGroup.children.length)oldGroup.remove()
229
+ const parts=[]
230
+ for(const node of [...page.children]){
231
+ if(node.matches('.settings-group:not(.model-settings-shell):not(.feedback-card)')){parts.push(...node.children);node.remove()}
232
+ else parts.push(node)
233
+ }
234
+ const header=element('header','workflow-subpage-head'),back=element('button','workflow-back'),backLabel=element('span')
235
+ back.type='button';rename(backLabel,'返回更多','Back to More');back.dataset.settingsBack=''
236
+ back.append(element('span','workflow-back-arrow','‹'),backLabel)
237
+ const title=element('h1');rename(title,...definition.title);title.id='workflow-title-'+key
238
+ const intro=element('p','workflow-subpage-intro');rename(intro,...definition.intro)
239
+ const mark=element('span','workflow-setting-icon');mark.append(icon(definition.icon))
240
+ const identity=element('div','workflow-subpage-identity'),copy=element('div');copy.append(title,intro);identity.append(mark,copy)
241
+ header.append(back,identity)
242
+ const body=element('div','workflow-subpage-body'),cards=new Map()
243
+ for(const [id,zh,en] of definition.groups){
244
+ const section=element('section','workflow-settings-section'),heading=element('h2'),card=element('div','workflow-settings-card')
245
+ rename(heading,zh,en);heading.id='workflow-group-'+key+'-'+id;section.setAttribute('aria-labelledby',heading.id);card.dataset.workflowSettingsSlot=id
246
+ section.append(heading,card);cards.set(id,{section,card});body.append(section)
247
+ }
248
+ for(const node of parts){
249
+ let group=definition.groups[0][0]
250
+ if(key==='general'){
251
+ if(includes(node,'#btn-theme,#btn-lang'))group='appearance'
252
+ else if(includes(node,'#btn-preset-add,#btn-manage-presets,#preset-list'))group='presets'
253
+ }else if(key==='servers'){
254
+ if(node.id==='relay-settings')group='relay'
255
+ else if(includes(node,'#token-desc,#desktop-token-input'))group='access'
256
+ else if(node.matches('.workflow-technical'))group='advanced'
257
+ else if(includes(node,'#btn-host-describe,#btn-dsh-start')||node.matches('.workflow-button'))group='host'
258
+ }else if(key==='notify'&&node.matches('.workflow-technical'))group='advanced'
259
+ else if(key==='about'){
260
+ if(node.matches('.workflow-data-settings'))group='data'
261
+ else if(node.id==='overview-announcement-board')group='announcements'
262
+ else if(node.matches('.feedback-card,.workflow-button')||includes(node,'[data-donate-open],#btn-donate-about'))group='support'
263
+ }
264
+ cards.get(group).card.append(node)
265
+ }
266
+ // Move existing controls rather than rebuilding them: listeners, form state
267
+ // and asynchronously updated regions keep their original DOM identities.
268
+ for(const {section,card} of cards.values())if(!card.children.length||[...card.children].every(node=>node.hidden||node.classList.contains('hidden')))section.hidden=true
269
+ page.classList.add('workflow-subpage');page.setAttribute('aria-labelledby',title.id)
270
+ page.replaceChildren(header,body)
271
+ }
272
+ }
273
+ function setupStart() {
274
+ const desktop=config.desktop,home=$(desktop?'view-sessions':'view-home');if(!home)return
275
+ const head=element('section','workflow-start')
276
+ const title=element('div','workflow-page-head'),heading=element('h1');rename(heading,desktop?'会话':'工作空间',desktop?'Conversations':'Workspace');title.append(heading)
277
+ connectionButton=button('检查连接…','Checking connection…',connectionDetails,'workflow-connection');connectionButton.id='workflow-connection'
278
+ connectionButton.removeAttribute('data-flow-zh');connectionButton.removeAttribute('data-flow-en')
279
+ title.append(connectionButton);head.append(title)
280
+ if(!desktop){
281
+ const workspace=$('workspace-nav'),create=$('btn-new-session')
282
+ if(workspace)head.append(workspace)
283
+ if(create){create.classList.add('workflow-new-session');head.append(create)}
284
+ rename(home.querySelector('.section-head > span:first-child'),'最近会话','Recent conversations')
285
+ }
286
+ attention=element('section','workflow-attention');attention.id='workflow-attention'
287
+ const attentionTitle=element('h2');rename(attentionTitle,'待处理','Needs attention');attention.append(attentionTitle)
288
+ const pending=$(desktop?'ds-overview-attention-list':'overview-attention-list');if(pending)attention.append(pending)
289
+ head.append(attention)
290
+ const notice=element('div','workflow-notice');notice.id='workflow-unconfirmed';notice.hidden=true
291
+ notice.append(element('span','',label('有操作结果待确认','Some operation results are unconfirmed')),button('查看回执','Check receipts',showOperations));head.append(notice)
292
+ home.prepend(head)
293
+ const announcements=$('overview-announcement-board')
294
+ if(announcements)$('settings-page-about')?.append(announcements)
295
+ const stat=$('stat-strip');if(stat)stat.hidden=true
296
+ }
297
+ function translate() {
298
+ const english=root.I18N?.lang==='en'
299
+ for(const el of document.querySelectorAll('[data-flow-zh]'))el.textContent=english?el.dataset.flowEn:el.dataset.flowZh
300
+ if(!config.desktop&&$('btn-plus')){
301
+ $('btn-plus').setAttribute('aria-label',label('指令与权限','Commands and permissions'))
302
+ $('btn-plus').title=label('指令与权限','Commands and permissions')
303
+ }
304
+ $('workflow-models')?.setAttribute('aria-label',label('模型与思考深度','Model and reasoning'))
305
+ }
306
+ function update() {
307
+ if(!config)return
308
+ const snapshot=config.snapshot(),english=root.I18N?.lang==='en'
309
+ if(snapshot.token&&config.operations&&root.DshOperations){
310
+ const context=config.operations(),identity=JSON.stringify([context.url('/api/operations'),context.headers.authorization])
311
+ if(identity!==receiptIdentity){receiptIdentity=identity;void root.DshOperations.restore(context).then(()=>{if(identity===receiptIdentity)update()}).catch(()=>{})}
312
+ }
313
+ if(connectionButton){
314
+ const status=!snapshot.token?label('连接主机','Connect host'):snapshot.gateway&&snapshot.dsh?label('已连接','Connected'):label('正在恢复连接','Reconnecting')
315
+ connectionButton.textContent=status+' · '+(snapshot.host||label('当前主机','Current host'))
316
+ connectionButton.classList.toggle('is-online',!!snapshot.gateway&&!!snapshot.dsh)
317
+ }
318
+ if(attention)attention.hidden=!snapshot.pending
319
+ const alternate=$('workflow-steer');if(alternate){alternate.hidden=!snapshot.busy;alternate.disabled=!!snapshot.sending}
320
+ const send=$('btn-send');if(send&&!snapshot.sending){send.textContent=snapshot.busy?label('排队发送','Queue'):label('发送','Send');send.setAttribute('aria-label',send.textContent)}
321
+ const unconfirmed=$('workflow-unconfirmed');if(unconfirmed)unconfirmed.hidden=!(root.DshOperations?.pending().some(row=>row.phase==='unknown'))
322
+ document.documentElement.dataset.workflowLang=english?'en':'zh'
323
+ translate()
324
+ }
325
+ function mount(options) {
326
+ if(config)return;config=options;document.body.classList.add('workflow-v8')
327
+ sheet=element('dialog','workflow-sheet');sheet.id='workflow-sheet'
328
+ const header=element('header','workflow-sheet-head');header.append(element('h2'),button('关闭','Close',close));sheet.append(header,element('div','workflow-sheet-body'));document.body.append(sheet)
329
+ sheet.addEventListener('click',event=>{if(event.target===sheet)close()})
330
+ sheet.addEventListener('close',()=>{if(!sheet.open){restoreAttention();operationList=null}})
331
+ setupMore();setupStart();setupComposer();config.start?.()
332
+ const relaySettings=$('relay-settings')
333
+ if(relaySettings){$('settings-page-servers')?.append(relaySettings);root.DshRelaySettings?.mount(relaySettings,{connection:config.relay||config.operations})}
334
+ setupSecondaryPages()
335
+ const overview=$('view-activity');if(overview)overview.dataset.workflowLegacy='overview'
336
+ if(!config.desktop){
337
+ const badge=$('nav-pending')
338
+ if(badge)badge.remove()
339
+ for(const el of document.querySelectorAll('.bottom-nav [data-view="view-activity"],.bottom-nav [data-view="view-plugins"],nav [data-view="view-activity"],nav [data-view="view-plugins"]'))el.remove()
340
+ rename(document.querySelector('nav [data-view="view-settings"] [data-i18n]'),'更多','More')
341
+ if(badge)document.querySelector('nav [data-view="view-home"]')?.append(badge)
342
+ for(const id of ['btn-donate','btn-feedback']){const el=$(id);if(el)el.hidden=true}
343
+ }else{
344
+ const sessions=document.querySelector('.ds-nav-item[data-view="view-overview"]')
345
+ if(sessions){sessions.dataset.view='view-sessions';rename(sessions.querySelector('[data-i18n]'),'会话','Conversations')}
346
+ for(const el of document.querySelectorAll('.ds-nav-item[data-view="view-plugins"]'))el.hidden=true
347
+ rename(document.querySelector('[data-view="view-settings"] [data-i18n]'),'更多','More')
348
+ const feedback=$('btn-feedback');if(feedback)feedback.hidden=true
349
+ }
350
+ new MutationObserver(update).observe(document.documentElement,{attributes:true,attributeFilter:['lang']})
351
+ root.addEventListener('dsh-operation-change',update)
352
+ update()
353
+ }
354
+ function clearStorage() {
355
+ const keys=new Set(['activeServer','busySendMode','dsShowArchivedV1','dshAdminDoctorCollapsed','dshAdminToken',
356
+ 'dshLang','dshNetworkModeV1','dshWeakStreamOff','dshTheme','fsWorkspaceIdV1','lastNewSessionWorkspaceV1','mobileEnterAction',
357
+ 'notify','peakRemind','server','servers','servers-v1','servers-v2','sessionSort','showArchivedV1','showTools',
358
+ 'steerSendingEnabled','token','workspaceFilterV1','dshRemoteClientIdV2','dshPromptPresets','seenNotesVersion',
359
+ 'dshCollapsedGoalsV1','workbenchOrderV1','seenAnnouncementsV1','announcementHistoryV1','announcementVotesV1',
360
+ 'dshAdminEnabledHostIPsV1','dshAdminManualHostIPsV1','dshRemoteOperationReceiptsV1'])
361
+ for(const key of Object.keys(localStorage))if(keys.has(key)||/^(?:sessions|history)Cache/.test(key))localStorage.removeItem(key)
362
+ sessionStorage.removeItem('dshRemoteOperationReceiptsV1')
363
+ sessionStorage.removeItem('dshRemoteLayout')
364
+ }
365
+ root.DshWorkflow={mount,update,close,connectionDetails,showOperations,clearStorage,preview,isMounted:()=>!!config}
366
+ })(window)