@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +61 -0
- package/README.md +60 -2
- package/apk/dsh-remote.apk +0 -0
- package/approval-summary.mjs +115 -0
- package/client.js +197 -0
- package/cordis.patch.yml +5 -0
- package/doctor-skill.mjs +99 -0
- package/doctor-target.mjs +24 -0
- package/file-delivery.mjs +84 -0
- package/gateway-stats.cjs +501 -0
- package/gateway.cjs +8451 -0
- package/index.mjs +1784 -0
- package/insights.mjs +111 -0
- package/market.mjs +86 -0
- package/package.json +71 -4
- package/peak-reminders.mjs +50 -0
- package/plugin-center.mjs +777 -0
- package/plugin-transaction.mjs +300 -0
- package/public/activity.js +188 -0
- package/public/admin.html +820 -0
- package/public/admin.js +1167 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +464 -0
- package/public/app.js +8826 -0
- package/public/approval-records.js +301 -0
- package/public/approval-summary.js +78 -0
- package/public/build.json +5 -0
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/chat-files.js +87 -0
- package/public/desktop/desktop.css +816 -0
- package/public/desktop/desktop.html +871 -0
- package/public/desktop/desktop.js +4548 -0
- package/public/desktop/i18n.js +85 -0
- package/public/diagnostics.js +203 -0
- package/public/doctor-entry.js +94 -0
- package/public/doctor.css +205 -0
- package/public/doctor.js +769 -0
- package/public/donate.png +0 -0
- package/public/e2ee-transport.js +219 -0
- package/public/extensions.css +109 -0
- package/public/extensions.js +215 -0
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/genui.css +8 -0
- package/public/genui.js +254 -0
- package/public/history.js +304 -0
- package/public/i18n.js +57 -0
- package/public/icon.svg +12 -0
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +290 -0
- package/public/index.html +1548 -0
- package/public/insights.css +28 -0
- package/public/insights.js +290 -0
- package/public/jsqr.min.js +10104 -0
- package/public/lan-discovery.js +94 -0
- package/public/link-check.js +109 -0
- package/public/manifest.webmanifest +16 -0
- package/public/md.js +333 -0
- package/public/morphicons-init.js +41 -0
- package/public/motion.js +557 -0
- package/public/network.js +100 -0
- package/public/onboarding.css +36 -0
- package/public/onboarding.js +253 -0
- package/public/operations.js +141 -0
- package/public/permission-presets.js +159 -0
- package/public/plugin-center.css +120 -0
- package/public/plugin-center.js +666 -0
- package/public/plugin-icon.svg +5 -0
- package/public/plugin.html +68 -0
- package/public/plugin.js +211 -0
- package/public/qrcode.min.js +2297 -0
- package/public/relay-autopair.js +251 -0
- package/public/relay-devices.js +80 -0
- package/public/relay-settings.css +24 -0
- package/public/relay-settings.js +194 -0
- package/public/remote-state.js +27 -0
- package/public/remote-ui.css +148 -0
- package/public/remote-ui.js +243 -0
- package/public/session-deck.css +79 -0
- package/public/session-deck.js +180 -0
- package/public/session-presets.js +47 -0
- package/public/setup.css +18 -0
- package/public/setup.js +213 -0
- package/public/sha256.js +119 -0
- package/public/skills.css +81 -0
- package/public/skills.js +202 -0
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/face.png +0 -0
- package/public/skins/blue-fish/icon-blush.png +0 -0
- package/public/skins/blue-fish/icon-sleep.png +0 -0
- package/public/skins/blue-fish/icon-smile.png +0 -0
- package/public/skins/blue-fish/icon-star.png +0 -0
- package/public/skins/blue-fish/icon-wink.png +0 -0
- package/public/skins/blue-fish/icon.png +0 -0
- package/public/skins/blue-fish/mascot.png +0 -0
- package/public/skins/blue-fish/pattern.png +0 -0
- package/public/skins/blue-fish/preview.html +12 -0
- package/public/skins/blue-fish/skin.css +122 -0
- package/public/skins/blue-fish/sparkles.svg +18 -0
- package/public/skins/bocchi/DESIGN.md +99 -0
- package/public/skins/bocchi/face.png +0 -0
- package/public/skins/bocchi/grain.png +0 -0
- package/public/skins/bocchi/icon-blush.png +0 -0
- package/public/skins/bocchi/icon-sleep.png +0 -0
- package/public/skins/bocchi/icon-smile.png +0 -0
- package/public/skins/bocchi/icon-star.png +0 -0
- package/public/skins/bocchi/icon-wink.png +0 -0
- package/public/skins/bocchi/icon.png +0 -0
- package/public/skins/bocchi/pattern-soft.png +0 -0
- package/public/skins/bocchi/pattern.png +0 -0
- package/public/skins/bocchi/preview.html +55 -0
- package/public/skins/bocchi/skin.css +233 -0
- package/public/skins/bocchi/stage-bg.png +0 -0
- package/public/skins/bocchi/stage-soft.png +0 -0
- package/public/skins/bocchi/stand.png +0 -0
- package/public/skins/bocchi/sticker-guitar.png +0 -0
- package/public/skins/kessoku/DESIGN.md +38 -0
- package/public/skins/kessoku/grain.png +0 -0
- package/public/skins/kessoku/skin.css +212 -0
- package/public/skins/kita/SOURCES.json +51 -0
- package/public/skins/kita/face.png +0 -0
- package/public/skins/kita/icon-live.png +0 -0
- package/public/skins/kita/icon-reddress.png +0 -0
- package/public/skins/kita/icon-seifuku.png +0 -0
- package/public/skins/kita/pattern.png +0 -0
- package/public/skins/kita/preview.html +56 -0
- package/public/skins/kita/skin.css +26 -0
- package/public/skins/kita/stand.png +0 -0
- package/public/skins/kita/sticker-live.png +0 -0
- package/public/skins/nijika/SOURCES.json +51 -0
- package/public/skins/nijika/face.png +0 -0
- package/public/skins/nijika/icon-live.png +0 -0
- package/public/skins/nijika/icon-reddress.png +0 -0
- package/public/skins/nijika/icon-seifuku.png +0 -0
- package/public/skins/nijika/pattern.png +0 -0
- package/public/skins/nijika/preview.html +56 -0
- package/public/skins/nijika/skin.css +25 -0
- package/public/skins/nijika/stand.png +0 -0
- package/public/skins/nijika/sticker-live.png +0 -0
- package/public/skins/penguin/DESIGN.md +33 -0
- package/public/skins/penguin/SOURCES.json +22 -0
- package/public/skins/penguin/aic-blueprint.svg +24 -0
- package/public/skins/penguin/endfield-triangles.svg +4 -0
- package/public/skins/penguin/face.png +0 -0
- package/public/skins/penguin/icon-blush.png +0 -0
- package/public/skins/penguin/icon-dizzy.png +0 -0
- package/public/skins/penguin/icon-laugh.png +0 -0
- package/public/skins/penguin/icon-sleep.png +0 -0
- package/public/skins/penguin/icon-smile.png +0 -0
- package/public/skins/penguin/icon-star.png +0 -0
- package/public/skins/penguin/icon-wink.png +0 -0
- package/public/skins/penguin/icon.png +0 -0
- package/public/skins/penguin/mascot.png +0 -0
- package/public/skins/penguin/pattern-night.png +0 -0
- package/public/skins/penguin/pattern.png +0 -0
- package/public/skins/penguin/preview.html +12 -0
- package/public/skins/penguin/skin.css +212 -0
- package/public/skins/ryo/SOURCES.json +51 -0
- package/public/skins/ryo/face.png +0 -0
- package/public/skins/ryo/icon-live.png +0 -0
- package/public/skins/ryo/icon-reddress.png +0 -0
- package/public/skins/ryo/icon-seifuku.png +0 -0
- package/public/skins/ryo/pattern.png +0 -0
- package/public/skins/ryo/preview.html +56 -0
- package/public/skins/ryo/skin.css +25 -0
- package/public/skins/ryo/stand.png +0 -0
- package/public/skins/ryo/sticker-live.png +0 -0
- package/public/sponsor-entry.js +21 -0
- package/public/styles.css +1494 -0
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/task-board.js +109 -0
- package/public/teams.js +98 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +1044 -0
- package/public/theme.js +166 -0
- package/public/transcribe-core.js +74 -0
- package/public/turn-results.js +121 -0
- package/public/update.json +49 -0
- package/public/vendor/gsap/NOTICE.md +10 -0
- package/public/vendor/gsap/gsap.min.js +11 -0
- package/public/vendor/morphicons/LICENSE +21 -0
- package/public/vendor/morphicons/README.md +10 -0
- package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
- package/public/vendor/morphicons/dom.js +206 -0
- package/public/vendor/morphicons/element.js +261 -0
- package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
- package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
- package/public/version.json +3 -0
- package/public/voice-input.js +739 -0
- package/public/workflow.css +365 -0
- package/public/workflow.js +409 -0
- package/session-file.mjs +39 -0
- package/skills/dsh-remote-doctor/SKILL.md +186 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/skills.mjs +53 -0
- package/task-board.mjs +57 -0
- package/teams.mjs +58 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* In-context task cards: no backdrop, forced navigation, or moving coach marks. */
|
|
2
|
+
.onboarding-entry { width:100%; border:1px solid var(--dsr-accent-line); border-radius:14px; background:var(--dsr-accent-soft); color:var(--dsr-text); text-align:left; cursor:pointer; font:inherit; }
|
|
3
|
+
.onboarding-entry { display:flex; flex-direction:column; gap:5px; padding:14px 16px; margin:0 0 16px; }
|
|
4
|
+
.onboarding-entry strong { font-size:15px; color:var(--dsr-accent-strong); }
|
|
5
|
+
.onboarding-entry span { color:var(--dsr-muted); font-size:12px; }
|
|
6
|
+
.onboarding-restart { margin:0; cursor:pointer; }
|
|
7
|
+
.onboarding-restart-copy { display:grid; gap:0; min-width:0; }
|
|
8
|
+
.onboarding-restart .setting-name,.onboarding-restart .setting-desc { display:block; overflow-wrap:anywhere; }
|
|
9
|
+
.onboarding-restart-icon::before { content:'?'; font-size:18px; font-weight:600; line-height:1; }
|
|
10
|
+
.onboarding-coach { flex:none; min-width:0; margin:0 0 12px; padding:12px; border:1px solid var(--dsr-accent-line); border-radius:14px; background:var(--dsr-bg-2); color:var(--dsr-text); font-size:13px; line-height:1.55; overflow-wrap:anywhere; }
|
|
11
|
+
.onboarding-coach[hidden],.onboarding-entry[hidden] { display:none!important; }
|
|
12
|
+
.onboarding-head,.onboarding-actions,.onboarding-navigation { display:flex; align-items:center; flex-wrap:wrap; gap:6px; }
|
|
13
|
+
.onboarding-head { justify-content:space-between; position:sticky; top:-12px; z-index:1; background:var(--dsr-bg-2); }
|
|
14
|
+
.onboarding-head-actions { display:flex; align-items:center; gap:2px; }
|
|
15
|
+
.onboarding-head-actions .onboarding-button { padding-left:7px; padding-right:7px; font-size:12px; }
|
|
16
|
+
.onboarding-coach.is-folded > :not(.onboarding-head) { display:none; }
|
|
17
|
+
.onboarding-eyebrow { color:var(--dsr-accent-strong); font-weight:700; font-size:12px; }
|
|
18
|
+
.onboarding-coach h2 { margin:4px 0 6px; font-size:17px; line-height:1.4; }
|
|
19
|
+
.onboarding-body { margin:0 0 6px; }
|
|
20
|
+
.onboarding-status { margin:6px 0; color:var(--dsr-muted); font-size:12px; }
|
|
21
|
+
.onboarding-details { margin:6px 0 10px; }
|
|
22
|
+
.onboarding-details summary { min-height:44px; padding:10px 0; cursor:pointer; color:var(--dsr-accent-strong); }
|
|
23
|
+
.onboarding-details ol { padding-left:22px; margin:4px 0 12px; }
|
|
24
|
+
.onboarding-details li { padding:3px 0; }
|
|
25
|
+
.onboarding-button { min-height:44px; padding:9px 12px; border:1px solid var(--dsr-line); border-radius:10px; color:var(--dsr-text); background:var(--dsr-panel); cursor:pointer; font:inherit; line-height:1.4; }
|
|
26
|
+
.onboarding-primary { border-color:var(--dsr-accent-line); color:var(--dsr-accent-strong); background:var(--dsr-accent-soft); }
|
|
27
|
+
.onboarding-button:disabled { opacity:.5; cursor:default; }
|
|
28
|
+
.onboarding-subtle { color:var(--dsr-muted); background:transparent; border-color:transparent; }
|
|
29
|
+
.onboarding-navigation { margin-top:6px; justify-content:flex-end; border-top:1px solid var(--dsr-line); padding-top:6px; }
|
|
30
|
+
.onboarding-target { outline:2px solid var(--dsr-accent-strong)!important; outline-offset:3px; }
|
|
31
|
+
.onboarding-button:focus-visible,.onboarding-entry:focus-visible,.onboarding-restart:focus-visible { outline:2px solid var(--dsr-accent-strong); outline-offset:2px; }
|
|
32
|
+
.workflow-settings-list .onboarding-restart:focus-visible { outline-offset:-3px; }
|
|
33
|
+
body.in-session .onboarding-coach { max-height:min(38dvh,280px); overflow-y:auto; overscroll-behavior:contain; }
|
|
34
|
+
.modal-card .onboarding-coach { padding:10px; font-size:12px; }
|
|
35
|
+
.modal-card .onboarding-coach h2 { font-size:15px; }
|
|
36
|
+
@media(max-height:520px) { body.in-session .onboarding-coach { max-height:30dvh; } }
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/* Guided practice for the mobile WebUI and Android WebView. No network ownership. */
|
|
2
|
+
;(function(root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
const KEY = 'dshRemoteOnboardingV1'
|
|
5
|
+
const $ = id => document.getElementById(id)
|
|
6
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
7
|
+
const steps = [
|
|
8
|
+
{ id: 'connect', title: ['先连接你的电脑', 'Connect your computer'],
|
|
9
|
+
body: ['手机是遥控器,DSH 和模型运行在电脑上。电脑需要开机,DSH 与 Remote 网关需要保持运行。', 'Your phone controls DSH and its model on your computer. Keep the computer, DSH and Remote gateway running.'],
|
|
10
|
+
tips: [
|
|
11
|
+
['在电脑的 DSH 中安装 Remote 插件,打开插件里的连接向导。手机选择“扫码连接”,扫描连接码;下载 APK 的二维码用于安装,不能拿来配对。', 'Install Remote in DSH on the computer and open its connection wizard. Scan the connection QR on the phone; the APK download QR installs the app and does not pair it.'],
|
|
12
|
+
['同一 Wi-Fi 下可用局域网地址。离开家后需要可达的中转或组网地址;手机里的 localhost 指向手机自己。', 'Use the LAN address on the same Wi-Fi. Away from home, use a reachable relay or private-network address. On a phone, localhost means the phone itself.'],
|
|
13
|
+
['连接码含访问凭证,请不要公开截图。“主机与连接”可以重新扫码或修改地址。', 'Connection QR codes contain credentials. Keep them private. Hosts and connections lets you scan again or edit addresses.']
|
|
14
|
+
], action: ['打开主机与连接', 'Open hosts and connections'], target: '#workflow-connection' },
|
|
15
|
+
{ id: 'session', title: ['选择工作区,打开一段对话', 'Choose a workspace and open a conversation'],
|
|
16
|
+
body: ['工作区是电脑上的项目目录;会话是在这个目录里进行的一段对话。可以打开已有会话,也可以新建。', 'A workspace is a project folder on the computer. A conversation works in that folder. Open an existing conversation or create one.'],
|
|
17
|
+
tips: [
|
|
18
|
+
['新建时先确认工作区名称和完整路径,再选主机提供的对话类型。不确定时保留默认类型。', 'When creating a conversation, check the workspace name and full path, then choose an agent type supplied by the host. Keep the default if unsure.'],
|
|
19
|
+
['没有工作区时,按新建面板里的“浏览主机目录”选择目录,再使用当前目录或新建工作区。这里选择的是电脑目录,不是手机目录。', 'With no workspace, use Browse host folders in the creation panel. Choose a folder, then use it or create a workspace. These folders are on the computer, not the phone.'],
|
|
20
|
+
['切换主机会切换对应的工作区和历史;请先确认页面显示的主机。', 'Changing hosts changes the workspaces and history you see. Check the selected host first.']
|
|
21
|
+
], action: ['选择或新建会话', 'Choose or create a conversation'], target: '#btn-new-session' },
|
|
22
|
+
{ id: 'message', title: ['亲手发出第一条消息', 'Send your first message'],
|
|
23
|
+
body: ['在下方输入需求,点击“发送”。消息会发给当前电脑的 DSH,使用你已配置的模型和额度。', 'Type a request below and tap Send. It goes to DSH on the selected computer and uses your configured model and quota.'],
|
|
24
|
+
tips: [
|
|
25
|
+
['可以自己写一句问候,也可以把示例放入空白输入框。示例只填草稿,需要你再点击发送。', 'Write a greeting or place the example in an empty composer. The example only fills a draft; you still tap Send.'],
|
|
26
|
+
['输入区的“模型”按钮可选择模型与思考深度;“指令”提供常用命令和权限预设。不确定时保留主机默认设置。', 'Model near the composer selects the model and reasoning depth. Commands includes common commands and permission presets. Keep the host defaults if unsure.'],
|
|
27
|
+
['如果暂时不想调用模型,选择“先跳过这步”。引导不会替你发送。', 'Choose Skip this step if you do not want to call the model yet. The guide never sends for you.'],
|
|
28
|
+
['运行中普通点击是排队,等待当前轮完成;“插队发送”会调整当前任务方向,先读清按钮再操作。', 'While a turn is running, a normal click queues your message. Steer changes the direction of the current task. Read the button before using it.']
|
|
29
|
+
], action: ['定位输入框', 'Find the composer'], target: '#composer-input' },
|
|
30
|
+
{ id: 'results', title: ['看懂回复、审批和发送结果', 'Understand replies, approvals and send results'],
|
|
31
|
+
body: ['“已发送”表示主机已接受,不代表模型已经回复。运行状态、对话记录和待处理事项会告诉你下一步。', 'Sent means the host accepted the request, not that the model has replied. Check the running status, history and items needing attention.'],
|
|
32
|
+
tips: [
|
|
33
|
+
['出现审批或问题时,先看具体内容,再允许、拒绝或回答。“停止本轮”用于请求停止当前任务。', 'When an approval or question appears, read it before allowing, denying or answering. Stop turn requests cancellation of the current task.'],
|
|
34
|
+
['网络断开或“结果未确认”时,先核对历史和操作回执;重复发送可能执行两次。回执里的“查询结果”用于核对原请求。', 'After a disconnect or an unconfirmed result, check history and receipts before sending again. Repeating a request may run it twice. Check result looks up the original request.'],
|
|
35
|
+
['模型或权限报错会保留在对话里。重试前先看错误原因,必要时打开 AI 排查或写反馈。', 'Model and permission errors remain in the conversation. Read the error before retrying; use AI diagnosis or feedback if needed.']
|
|
36
|
+
], action: ['查看审批与操作回执', 'Open approvals and receipts'], target: '#history' },
|
|
37
|
+
{ id: 'files', title: ['分清图片附件和文件传输', 'Use images and file transfer'],
|
|
38
|
+
body: ['对话里的图片按钮用来附上截图或照片;底部“文件”页用来浏览、上传和下载电脑文件。', 'The image button in a conversation attaches a screenshot or photo. Files in the bottom navigation browses, uploads and downloads computer files.'],
|
|
39
|
+
tips: [
|
|
40
|
+
['选择图片后先看附件预览,再随消息发送。能否理解图片还取决于主机模型或图片理解插件。', 'Review the image attachment before sending it with your message. Image understanding depends on the host model or vision plugin.'],
|
|
41
|
+
['文件上传到当前电脑、当前目录;上传前确认路径,上传后核对列表与进度。传到电脑不等于已作为对话附件发送。', 'Files upload to the selected computer and folder. Check the path first, then the file list and progress. Uploading does not automatically attach a file to a conversation.'],
|
|
42
|
+
['本步只带你查看入口,不会自动选择或上传任何文件。', 'This step only opens the controls. It does not select or upload files.']
|
|
43
|
+
], action: ['打开文件页', 'Open Files'], target: '#fs-upload-btn' },
|
|
44
|
+
{ id: 'branch', title: ['从一条回复继续尝试另一条思路', 'Try another direction with a branch'],
|
|
45
|
+
body: ['一轮回复结束后,结果下方可出现“从此处分支”。分支会创建另一段会话,从选定位置继续。', 'After a completed turn, Branch from here may appear below the result. It creates another conversation continuing from that point.'],
|
|
46
|
+
tips: [
|
|
47
|
+
['适合比较另一种方案,同时保留原会话。分支不会撤销已经修改的文件。', 'Use it to compare another approach while keeping the original conversation. A branch does not undo file changes.'],
|
|
48
|
+
['看不到按钮时,可能还没有完整回复,或当前主机、会话不支持分支;可以跳过,不需要为了学习额外运行任务。', 'If the button is missing, the turn may be incomplete or branching unsupported for this host or conversation. You can skip without running an extra task.'],
|
|
49
|
+
['引导只定位分支按钮,不会替你创建分支。', 'The guide only locates the branch control. It does not create a branch.']
|
|
50
|
+
], action: ['回到会话查看分支入口', 'Find branching in the conversation'], target: '[data-turn-action="fork"]' },
|
|
51
|
+
{ id: 'doctor', title: ['遇到异常,先让 AI 帮你排查', 'Use AI diagnosis when something goes wrong'],
|
|
52
|
+
body: ['首页的“AI 排查问题”会打开说明面板。确认排查范围后,再由你点击“开始”。', 'AI diagnosis on the home page opens an explanation panel. Review the scope, then choose Start yourself.'],
|
|
53
|
+
tips: [
|
|
54
|
+
['排查使用你的 DSH 和模型,会消耗模型额度。正常开始后会进入诊断会话,在对话里查看结果。', 'Diagnosis uses your DSH and model quota. A successful start opens a diagnosis conversation where you can read the result.'],
|
|
55
|
+
['诊断按只读范围排查;需要改动时先确认建议。如果面板关闭却没有会话或回复,这也是可以反馈的问题。', 'Diagnosis investigates within its read-only scope. Review any suggested changes. A panel closing without a conversation or reply is itself worth reporting.'],
|
|
56
|
+
['这一步只打开说明,不会自动开始诊断。你也可以直接写反馈。', 'This step only opens the explanation. It does not start diagnosis. You can also go directly to feedback.']
|
|
57
|
+
], action: ['查看 AI 排查说明', 'View AI diagnosis'], target: '#home-doctor' },
|
|
58
|
+
{ id: 'feedback', title: ['写一条能复现问题的反馈', 'Write feedback that can be reproduced'],
|
|
59
|
+
body: ['不需要 GitHub 账号。可以在 App 内填写反馈;以后从“更多 → 关于与维护 → 提交反馈”重新进入。', 'No GitHub account is needed for in-app feedback. Find it again under More → About and maintenance → Send feedback.'],
|
|
60
|
+
tips: [
|
|
61
|
+
['按顺序写:在哪个页面 → 点了什么 → 预期发生什么 → 实际发生什么。补充是否每次出现,以及 App/浏览器和电脑系统。', 'Describe the page → what you clicked → what you expected → what happened. Include how often it happens, the app/browser and the computer OS.'],
|
|
62
|
+
['诊断日志和崩溃摘要都由你选择是否附带,可以先查看摘要。不要在描述或截图中公开令牌、二维码或密钥。', 'You choose whether to include diagnostic or crash summaries and can preview them. Keep tokens, QR credentials and keys out of descriptions and screenshots.'],
|
|
63
|
+
['只有服务器确认后才会显示“反馈发送成功”。现在只是学习入口,不必为了完成引导提交测试反馈。', 'Feedback sent appears only after server confirmation. You do not need to submit test feedback to finish this guide.']
|
|
64
|
+
], action: ['打开反馈表单', 'Open feedback form'], target: '#fb-msg' }
|
|
65
|
+
]
|
|
66
|
+
let config, progress, active = false, folded = false, card, entry, restart, signature = '', highlighted, sessionStamp = '', sent = false
|
|
67
|
+
const read = () => {
|
|
68
|
+
try {
|
|
69
|
+
const value = JSON.parse(root.localStorage.getItem(KEY))
|
|
70
|
+
if (value?.schema === 1 && Number.isInteger(value.step) && value.step >= 0 && value.step < steps.length
|
|
71
|
+
&& ['new', 'paused', 'complete', 'skipped'].includes(value.status)) return { schema: 1, step: value.step, status: value.status }
|
|
72
|
+
} catch {}
|
|
73
|
+
return { schema: 1, step: 0, status: 'new' }
|
|
74
|
+
}
|
|
75
|
+
function save() {
|
|
76
|
+
// A reload after an accepted message must not invite a second practice send.
|
|
77
|
+
const stored = { ...progress, step: progress.step === 2 && sent ? 3 : progress.step }
|
|
78
|
+
try { root.localStorage.setItem(KEY, JSON.stringify(stored)) } catch {}
|
|
79
|
+
}
|
|
80
|
+
function el(tag, cls, content) {
|
|
81
|
+
const node = document.createElement(tag)
|
|
82
|
+
if (cls) node.className = cls
|
|
83
|
+
if (content) node.textContent = content
|
|
84
|
+
return node
|
|
85
|
+
}
|
|
86
|
+
function button(content, action, kind = '') {
|
|
87
|
+
const node = el('button', 'onboarding-button ' + kind, content); node.type = 'button'
|
|
88
|
+
node.addEventListener('click', action); return node
|
|
89
|
+
}
|
|
90
|
+
function clearHighlight() { highlighted?.classList.remove('onboarding-target'); highlighted = null }
|
|
91
|
+
function snapshot() { return config.snapshot() || {} }
|
|
92
|
+
function ready(live) {
|
|
93
|
+
if (progress.step === 0) return !!live.connected
|
|
94
|
+
if (progress.step === 1) return !!live.connected && !!live.session && !!live.sessionReady
|
|
95
|
+
if (progress.step === 2) return !!live.connected && !!live.session && sent && sessionStamp === JSON.stringify([live.connection, live.session])
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
function start(reset = false) {
|
|
99
|
+
if (reset || progress.status === 'complete' || progress.status === 'skipped') progress = { schema: 1, step: 0, status: 'paused' }
|
|
100
|
+
active = true; folded = false; progress.status = 'paused'; save(); signature = ''
|
|
101
|
+
update(); card.scrollIntoView?.({ block: 'nearest', behavior: 'auto' }); card.focus?.({ preventScroll: true })
|
|
102
|
+
}
|
|
103
|
+
function pause() {
|
|
104
|
+
if (progress.step === 2 && sent) progress.step = 3
|
|
105
|
+
active = false; progress.status = 'paused'; save(); clearHighlight(); signature = ''; update()
|
|
106
|
+
}
|
|
107
|
+
function skipAll() {
|
|
108
|
+
if (!active) return
|
|
109
|
+
active = false; progress.status = 'skipped'
|
|
110
|
+
clearHighlight(); config.closePractice?.(); save(); signature = ''; update()
|
|
111
|
+
}
|
|
112
|
+
function advance(skip = false) {
|
|
113
|
+
if (!active || (!skip && !ready(snapshot()))) return
|
|
114
|
+
clearHighlight()
|
|
115
|
+
config.closePractice?.()
|
|
116
|
+
folded = false
|
|
117
|
+
if (progress.step === steps.length - 1) {
|
|
118
|
+
active = false; progress.status = 'complete'
|
|
119
|
+
} else progress.step++
|
|
120
|
+
save(); signature = ''; update()
|
|
121
|
+
if (active) card.scrollIntoView?.({ block: 'nearest', behavior: 'auto' })
|
|
122
|
+
}
|
|
123
|
+
function placement() {
|
|
124
|
+
// Unrelated notices, approvals and native dialogs keep precedence.
|
|
125
|
+
const modal = document.querySelector('.modal:not(.hidden), dialog[open], .doctor-overlay:not(.hidden)')
|
|
126
|
+
if (modal) {
|
|
127
|
+
if ((modal.id === 'modal-new-session' && progress.step === 1) || (modal.id === 'modal-feedback' && progress.step === 7)) {
|
|
128
|
+
return modal.querySelector('.modal-body') || modal.querySelector('.modal-card')
|
|
129
|
+
}
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
return document.querySelector('#main > .view:not(.hidden)')
|
|
133
|
+
}
|
|
134
|
+
function waiting(live) {
|
|
135
|
+
if (progress.step < 3 && !live.connected) return text('尚未确认电脑连接。先打开主机与连接,确认地址和电脑上的 DSH 正在运行。', 'Computer connection is not confirmed. Check the host address and that DSH is running.')
|
|
136
|
+
if (progress.step === 1) return text('等你打开会话并加载历史后,这一步才会完成。', 'This step completes after you open a conversation and its history loads.')
|
|
137
|
+
if (progress.step === 2 && !live.session) return text('当前没有打开会话,先打开或新建一段会话。', 'Open or create a conversation first.')
|
|
138
|
+
if (progress.step === 2) return text('等待主机确认接受你发出的普通消息;点击发送或“结果未确认”都不算完成。', 'Waiting for the host to accept a normal message. A click or unconfirmed result does not count.')
|
|
139
|
+
return text('先看说明,需要时再打开入口练习;不必真的执行操作。', 'Read the explanation and open the controls if useful. You do not have to perform the action.')
|
|
140
|
+
}
|
|
141
|
+
function render(live) {
|
|
142
|
+
const step = steps[progress.step], complete = ready(live)
|
|
143
|
+
card.replaceChildren()
|
|
144
|
+
const header = el('div', 'onboarding-head'), caption = el('span', 'onboarding-eyebrow', text('新手引导', 'Getting started') + ' · ' + (progress.step + 1) + '/' + steps.length)
|
|
145
|
+
const headerActions = el('div', 'onboarding-head-actions')
|
|
146
|
+
const fold = button(folded ? text('展开', 'Expand') : text('收起', 'Collapse'), () => {
|
|
147
|
+
folded = !folded; card.classList.toggle('is-folded', folded)
|
|
148
|
+
fold.textContent = folded ? text('展开', 'Expand') : text('收起', 'Collapse')
|
|
149
|
+
fold.setAttribute('aria-expanded', String(!folded))
|
|
150
|
+
}, 'onboarding-subtle')
|
|
151
|
+
fold.setAttribute('aria-expanded', String(!folded))
|
|
152
|
+
headerActions.append(fold, button(text('稍后继续', 'Pause'), pause, 'onboarding-subtle'))
|
|
153
|
+
header.append(caption, headerActions)
|
|
154
|
+
const title = el('h2', '', text(...step.title)); title.id = 'onboarding-title'
|
|
155
|
+
const status = el('p', 'onboarding-status', progress.step < 3 && complete
|
|
156
|
+
? text('✓ 已确认这一步,可以继续。', '✓ This step is confirmed. You can continue.') : waiting(live))
|
|
157
|
+
status.setAttribute('role', 'status')
|
|
158
|
+
const details = el('details', 'onboarding-details'), summary = el('summary', '', text('操作说明与遇到问题怎么办', 'How to do it and recover from problems'))
|
|
159
|
+
const list = el('ol')
|
|
160
|
+
for (const tip of step.tips) list.append(el('li', '', text(...tip)))
|
|
161
|
+
details.append(summary, list)
|
|
162
|
+
const actions = el('div', 'onboarding-actions'), locate = button(text(...step.action), () => void practice(), 'onboarding-primary')
|
|
163
|
+
locate.dataset.onboardingAction = 'practice'
|
|
164
|
+
actions.append(locate)
|
|
165
|
+
if (progress.step === 2) actions.append(button(text('把示例放入空白输入框', 'Put example in empty composer'), () => {
|
|
166
|
+
if (!snapshot().session || !snapshot().connected) return
|
|
167
|
+
const placed = config.example?.(text('请用一句话介绍你能帮我做什么。', 'In one sentence, what can you help me with?'))
|
|
168
|
+
status.textContent = placed ? text('已填入草稿。需要你自己点击发送。', 'Draft filled. Tap Send yourself.') : text('已保留你的草稿,请继续输入或自己发送。', 'Your draft is preserved. Continue typing or send it yourself.')
|
|
169
|
+
}))
|
|
170
|
+
const next = button(progress.step === steps.length - 1 ? text('完成引导', 'Finish guide') : text('下一步', 'Next'), () => advance())
|
|
171
|
+
next.disabled = !complete; next.dataset.onboardingAction = 'next'
|
|
172
|
+
const navigation = el('div', 'onboarding-navigation')
|
|
173
|
+
if (progress.step > 0) navigation.append(button(text('上一步', 'Back'), () => {
|
|
174
|
+
config.closePractice?.(); folded = false; progress.step--; save(); signature = ''; update()
|
|
175
|
+
}, 'onboarding-subtle'))
|
|
176
|
+
navigation.append(button(text('先跳过这步', 'Skip this step'), () => advance(true), 'onboarding-subtle'), next)
|
|
177
|
+
const dismiss = button(text('跳过整个引导,以后在“更多”中查看', 'Skip the guide; find it later in More'), skipAll, 'onboarding-subtle')
|
|
178
|
+
card.append(header, title, el('p', 'onboarding-body', text(...step.body)), status, details, actions, navigation, dismiss)
|
|
179
|
+
card.classList.toggle('is-folded', folded)
|
|
180
|
+
card.scrollTop = 0
|
|
181
|
+
}
|
|
182
|
+
async function practice() {
|
|
183
|
+
if (!active) return
|
|
184
|
+
const step = steps[progress.step], at = progress.step
|
|
185
|
+
try {
|
|
186
|
+
await config.actions[step.id]?.()
|
|
187
|
+
if (!active || progress.step !== at) return
|
|
188
|
+
update()
|
|
189
|
+
clearHighlight()
|
|
190
|
+
const target = document.querySelector(step.target)
|
|
191
|
+
if (target && target.getClientRects().length && !card.hidden) {
|
|
192
|
+
highlighted = target; target.classList.add('onboarding-target')
|
|
193
|
+
target.scrollIntoView?.({ block: 'nearest', behavior: 'auto' })
|
|
194
|
+
if (step.id === 'message') target.focus?.({ preventScroll: true })
|
|
195
|
+
} else if (step.id === 'branch' && !card.hidden) {
|
|
196
|
+
card.querySelector('.onboarding-status').textContent = text('当前没有可用的分支按钮。完整回复结束且主机支持后才会出现,可先继续。', 'No branch control is available yet. It needs a completed turn and host support. You can continue.')
|
|
197
|
+
}
|
|
198
|
+
} catch {
|
|
199
|
+
if (active && progress.step === at) card.querySelector('.onboarding-status').textContent = text('入口暂时无法打开。可以稍后再试,或先跳过这一步。', 'Unable to open this right now. Try later or skip this step.')
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function update() {
|
|
203
|
+
if (!config) return
|
|
204
|
+
const live = snapshot(), stamp = JSON.stringify([live.connection, live.session])
|
|
205
|
+
if (stamp !== sessionStamp) { sessionStamp = stamp; sent = false; clearHighlight() }
|
|
206
|
+
if (!active) {
|
|
207
|
+
card.hidden = true
|
|
208
|
+
const done = progress.status === 'complete' || progress.status === 'skipped'
|
|
209
|
+
const title = progress.status === 'paused'
|
|
210
|
+
? text('继续新手引导', 'Continue the guide') + ' · ' + (progress.step + 1) + '/' + steps.length : text('第一次用?一步一步带你上手', 'First time? Let us guide you')
|
|
211
|
+
entry.querySelector('strong').textContent = title
|
|
212
|
+
entry.querySelector('span').textContent = text('每次只做一件事,随时暂停或跳过。', 'One task at a time. Pause or skip whenever you like.')
|
|
213
|
+
restart.querySelector('.setting-name').textContent = text('新手引导', 'Getting started')
|
|
214
|
+
restart.querySelector('.setting-desc').textContent = done
|
|
215
|
+
? text('重新查看连接、对话与常见操作', 'Revisit connection, chat and common actions')
|
|
216
|
+
: text('按步骤熟悉连接、对话与常见操作', 'Learn connection, chat and common actions step by step')
|
|
217
|
+
entry.hidden = done
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
entry.hidden = true
|
|
221
|
+
const destination = placement()
|
|
222
|
+
card.hidden = !destination
|
|
223
|
+
if (!destination) { clearHighlight(); return }
|
|
224
|
+
if (card.parentElement !== destination) destination.prepend(card)
|
|
225
|
+
const nextSignature = JSON.stringify([progress.step, root.I18N?.lang, !!live.connected, !!live.session, !!live.sessionReady, sent])
|
|
226
|
+
if (nextSignature !== signature) { signature = nextSignature; render(live) }
|
|
227
|
+
}
|
|
228
|
+
function record(type, context) {
|
|
229
|
+
const live = snapshot()
|
|
230
|
+
if (!active || progress.step !== 2 || type !== 'message-accepted' || !live.connected || !context?.session
|
|
231
|
+
|| context.session !== live.session || context.connection !== live.connection) return
|
|
232
|
+
const stamp = JSON.stringify([live.connection, live.session])
|
|
233
|
+
if (stamp !== sessionStamp) { sessionStamp = stamp; sent = false }
|
|
234
|
+
sent = true; save(); update()
|
|
235
|
+
}
|
|
236
|
+
function mount(options) {
|
|
237
|
+
if (config || !$('view-home')) return
|
|
238
|
+
config = options; progress = read()
|
|
239
|
+
card = el('section', 'onboarding-coach'); card.id = 'onboarding-coach'; card.tabIndex = -1
|
|
240
|
+
card.setAttribute('aria-labelledby', 'onboarding-title'); card.hidden = true
|
|
241
|
+
entry = button('', () => start(), 'onboarding-entry'); entry.id = 'onboarding-entry'
|
|
242
|
+
entry.append(el('strong'), el('span')); $('view-home').prepend(entry)
|
|
243
|
+
restart = button('', () => start(true), 'workflow-setting-link onboarding-restart'); restart.id = 'onboarding-restart'
|
|
244
|
+
const mark = el('span', 'workflow-setting-icon onboarding-restart-icon'); mark.setAttribute('aria-hidden', 'true')
|
|
245
|
+
const copy = el('span', 'onboarding-restart-copy'); copy.append(el('span', 'setting-name'), el('span', 'setting-desc'))
|
|
246
|
+
restart.append(mark, copy)
|
|
247
|
+
const settings = $('workflow-more-preferences') || $('settings-home'); settings?.append(restart)
|
|
248
|
+
document.body.append(card)
|
|
249
|
+
document.addEventListener('click', () => queueMicrotask(update))
|
|
250
|
+
update()
|
|
251
|
+
}
|
|
252
|
+
root.DshOnboarding = { mount, update, record, start, pause }
|
|
253
|
+
})(window)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* Durable write receipts. POST once, recover using GET only; zero dependencies. */
|
|
2
|
+
;(function(root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
const methods = new Set(['session.fork','session.create','session.prompt','session.updateQueue','session.selectModel',
|
|
5
|
+
'session.rename','session.cancel','workspace.create','workspace.archiveSession',
|
|
6
|
+
'goal.edit','goal.pause','goal.resume','goal.complete','goal.clear'])
|
|
7
|
+
const pending = new Map()
|
|
8
|
+
const storageKey = 'dshRemoteOperationReceiptsV1'
|
|
9
|
+
// Scope of the connection the UI is currently showing. Receipts from another
|
|
10
|
+
// connection stay visible as "unconfirmed" so a pending write is never lost
|
|
11
|
+
// from the user's view merely because the address/token changed.
|
|
12
|
+
let currentScope = ''
|
|
13
|
+
function saved() { try { return JSON.parse(root.localStorage?.getItem(storageKey) || '[]').filter(row => Date.now()-row.createdAt<86400000).slice(-100) } catch { return [] } }
|
|
14
|
+
function originOf(config) {
|
|
15
|
+
try {
|
|
16
|
+
const base = String(config?.server || config?.url?.('/') || '')
|
|
17
|
+
return base ? new URL(base, root.location?.href || 'http://localhost').origin : ''
|
|
18
|
+
} catch { return '' }
|
|
19
|
+
}
|
|
20
|
+
function persist() {
|
|
21
|
+
const rows=new Map(saved().map(row=>[row.id,row]))
|
|
22
|
+
for(const row of pending.values())rows.set(row.id,{id:row.id,scope:row.scope,intent:row.intent,method:row.method,sessionId:row.sessionId,origin:row.origin,createdAt:row.createdAt})
|
|
23
|
+
try { root.localStorage?.setItem(storageKey,JSON.stringify([...rows.values()].slice(-100))) } catch {}
|
|
24
|
+
root.dispatchEvent?.(new Event('dsh-operation-change'))
|
|
25
|
+
}
|
|
26
|
+
function forget(id) {
|
|
27
|
+
pending.delete(id)
|
|
28
|
+
try { root.localStorage?.setItem(storageKey,JSON.stringify(saved().filter(row=>row.id!==id))) } catch {}
|
|
29
|
+
root.dispatchEvent?.(new Event('dsh-operation-change'))
|
|
30
|
+
}
|
|
31
|
+
async function digest(value) {
|
|
32
|
+
const input=new TextEncoder().encode(value)
|
|
33
|
+
if(root.crypto?.subtle) {
|
|
34
|
+
const bytes=await root.crypto.subtle.digest('SHA-256',input)
|
|
35
|
+
return [...new Uint8Array(bytes)].map(n=>n.toString(16).padStart(2,'0')).join('')
|
|
36
|
+
}
|
|
37
|
+
// LAN HTTP does not expose SubtleCrypto. Reuse the existing upload hasher.
|
|
38
|
+
if(typeof root.SHA256==='function')return new root.SHA256().update(input).hex()
|
|
39
|
+
throw new Error('SHA-256 unavailable')
|
|
40
|
+
}
|
|
41
|
+
function newId() {
|
|
42
|
+
if(root.crypto.randomUUID)return root.crypto.randomUUID()
|
|
43
|
+
return [...root.crypto.getRandomValues(new Uint8Array(16))].map(n=>n.toString(16).padStart(2,'0')).join('')
|
|
44
|
+
}
|
|
45
|
+
async function restore(config) {
|
|
46
|
+
const scope=await digest(config.url('/api/operations')+'\0'+config.headers.authorization)
|
|
47
|
+
currentScope=scope
|
|
48
|
+
if(!config.valid())return scope
|
|
49
|
+
const origin=originOf(config)
|
|
50
|
+
for(const row of saved())if(row.scope===scope&&!pending.has(row.id))pending.set(row.id,{...row,origin:row.origin||origin,phase:'unknown',config})
|
|
51
|
+
for(const row of pending.values())if(row.scope===scope){row.config=config;if(!row.origin)row.origin=origin}
|
|
52
|
+
return scope
|
|
53
|
+
}
|
|
54
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
55
|
+
function unknown(id) {
|
|
56
|
+
const error = new Error((root.I18N?.lang === 'en' ? 'Result unconfirmed. The operation may already have been applied. Check before trying again. Operation: ' : '结果未确认,操作可能已生效。请先核对会话,再决定是否重试。操作编号:') + id)
|
|
57
|
+
error.operationId = id; error.operationPending = true
|
|
58
|
+
return error
|
|
59
|
+
}
|
|
60
|
+
async function execute(config) {
|
|
61
|
+
const scope=await restore(config),intent=await digest(JSON.stringify([config.method,config.payload]))
|
|
62
|
+
if(!config.valid())throw unknown('connection-changed')
|
|
63
|
+
const existing=[...pending.values()].find(row=>row.scope===scope&&row.intent===intent)
|
|
64
|
+
const id = existing?.id || newId(), createdAt = Date.now()
|
|
65
|
+
const entry = existing || { id, scope, intent, method: config.method, sessionId: config.payload.sessionId || '', origin: originOf(config), createdAt, phase: 'running', config }
|
|
66
|
+
if (!entry.origin) entry.origin = originOf(config)
|
|
67
|
+
pending.set(id, entry)
|
|
68
|
+
persist()
|
|
69
|
+
const statusUrl = config.url('/api/operations?id=' + encodeURIComponent(id))
|
|
70
|
+
const request = async (method, body) => {
|
|
71
|
+
const response = await root.fetch(statusUrl, { method, headers: config.headers,
|
|
72
|
+
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(15000) })
|
|
73
|
+
if (!config.valid()) throw unknown(id)
|
|
74
|
+
if (response.status === 401) throw Error('AUTH')
|
|
75
|
+
const value = await response.json()
|
|
76
|
+
if (!config.valid()) throw unknown(id)
|
|
77
|
+
if (response.status >= 400) {
|
|
78
|
+
if (response.status >= 500) throw unknown(id)
|
|
79
|
+
if (method === 'GET' && response.status === 404) throw unknown(id)
|
|
80
|
+
const error = new Error(value.error || ('HTTP ' + response.status)); error.rpcRejected = true; throw error
|
|
81
|
+
}
|
|
82
|
+
return value
|
|
83
|
+
}
|
|
84
|
+
let status
|
|
85
|
+
try {
|
|
86
|
+
try { status = existing ? await request('GET') : await request('POST', { method: config.method, payload: config.payload }) }
|
|
87
|
+
catch (error) { if (error.message === 'AUTH' || error.rpcRejected || !config.valid()) throw error }
|
|
88
|
+
for (let attempt = 0; config.valid() && Date.now() - createdAt < 90000; attempt++) {
|
|
89
|
+
if (status?.phase === 'complete' || status?.phase === 'rejected') {
|
|
90
|
+
entry.phase = status.phase; forget(id)
|
|
91
|
+
return status.result
|
|
92
|
+
}
|
|
93
|
+
if (status?.phase === 'unknown') { entry.phase = 'unknown'; throw unknown(id) }
|
|
94
|
+
await sleep(Math.min(3000, 400 + attempt * 250))
|
|
95
|
+
try { status = await request('GET') }
|
|
96
|
+
catch (error) { if (error.message === 'AUTH' || error.rpcRejected) throw error }
|
|
97
|
+
}
|
|
98
|
+
throw unknown(id)
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error.rpcRejected || error.message === 'AUTH') forget(id)
|
|
101
|
+
else entry.phase = 'unknown'
|
|
102
|
+
persist()
|
|
103
|
+
throw error
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function check(id) {
|
|
107
|
+
const entry = pending.get(id)
|
|
108
|
+
if (!entry || !entry.config || !entry.config.valid()) return null
|
|
109
|
+
const response = await root.fetch(entry.config.url('/api/operations?id=' + encodeURIComponent(id)), {
|
|
110
|
+
headers: entry.config.headers, signal: AbortSignal.timeout(15000) })
|
|
111
|
+
if (!entry.config.valid()) return null
|
|
112
|
+
const value = await response.json()
|
|
113
|
+
if (!entry.config.valid()) return null
|
|
114
|
+
if (response.ok) { entry.phase = value.phase; if (['complete','rejected'].includes(value.phase)) forget(id) }
|
|
115
|
+
return response.ok ? value : null
|
|
116
|
+
}
|
|
117
|
+
function pendingRows() {
|
|
118
|
+
const rows = new Map()
|
|
119
|
+
for (const row of pending.values()) rows.set(row.id, { id: row.id, method: row.method, sessionId: row.sessionId,
|
|
120
|
+
createdAt: row.createdAt, phase: row.phase, origin: row.origin || '', current: !!(row.config && row.config.valid()) })
|
|
121
|
+
// Receipts persisted for another address/token are still shown, as unknown.
|
|
122
|
+
// They cannot be queried until the user switches back to that connection,
|
|
123
|
+
// but hiding them would let an ambiguous write disappear from the UI.
|
|
124
|
+
for (const row of saved()) {
|
|
125
|
+
if (rows.has(row.id) || (currentScope && row.scope === currentScope)) continue
|
|
126
|
+
rows.set(row.id, { id: row.id, method: row.method, sessionId: row.sessionId, createdAt: row.createdAt,
|
|
127
|
+
phase: 'unknown', origin: row.origin || '', current: false })
|
|
128
|
+
}
|
|
129
|
+
return [...rows.values()].filter(row => row.current || row.phase === 'unknown')
|
|
130
|
+
}
|
|
131
|
+
const api = { supports: method => methods.has(method), execute, check, restore,
|
|
132
|
+
dismiss: id => {
|
|
133
|
+
const row = pending.get(id) || saved().find(value => value.id === id)
|
|
134
|
+
if (!row || (row.phase && row.phase !== 'unknown')) return false
|
|
135
|
+
forget(id)
|
|
136
|
+
return true
|
|
137
|
+
},
|
|
138
|
+
pending: pendingRows }
|
|
139
|
+
root.DshOperations = api
|
|
140
|
+
if (typeof module !== 'undefined') module.exports = api
|
|
141
|
+
})(typeof window === 'undefined' ? globalThis : window)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* Host-provided permission presets (sandbox mode + approval policy). No guessed list. */
|
|
2
|
+
'use strict'
|
|
3
|
+
;(function (root) {
|
|
4
|
+
const CACHE_MS = 15000
|
|
5
|
+
const MAX_OPTIONS = 20
|
|
6
|
+
const VALUE = /^[a-z][a-z0-9-]{0,63}$/
|
|
7
|
+
// Used only when the host cannot answer, so pre-0.2.1 servers keep the three
|
|
8
|
+
// sandbox modes this client switched between before presets were configurable.
|
|
9
|
+
const FALLBACK = Object.freeze(['read-only', 'workspace-write', 'danger-full-access'])
|
|
10
|
+
// Presets that run without a sandbox need an explicit risk acknowledgement.
|
|
11
|
+
const GATED = new Set(['auto', 'danger-full-access'])
|
|
12
|
+
// `custom` is derived host state: it may be shown as current, never switched to.
|
|
13
|
+
const UNSELECTABLE = new Set(['custom'])
|
|
14
|
+
let cached = null
|
|
15
|
+
|
|
16
|
+
const text = (tag, className, value) => {
|
|
17
|
+
const node = document.createElement(tag)
|
|
18
|
+
if (className) node.className = className
|
|
19
|
+
if (value != null) node.textContent = value
|
|
20
|
+
return node
|
|
21
|
+
}
|
|
22
|
+
const button = (className, value) => {
|
|
23
|
+
const node = document.createElement('button')
|
|
24
|
+
node.type = 'button'
|
|
25
|
+
node.className = className
|
|
26
|
+
if (value != null) node.textContent = value
|
|
27
|
+
return node
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function rowsOf(payload) {
|
|
31
|
+
if (!Array.isArray(payload?.options)) return null
|
|
32
|
+
const rows = [], seen = new Set()
|
|
33
|
+
for (const item of payload.options) {
|
|
34
|
+
const value = typeof item?.value === 'string' ? item.value.trim() : ''
|
|
35
|
+
if (!value || !VALUE.test(value) || UNSELECTABLE.has(value) || seen.has(value)) continue
|
|
36
|
+
seen.add(value)
|
|
37
|
+
const name = typeof item.name === 'string' && item.name.trim() ? item.name.trim().slice(0, 80) : value
|
|
38
|
+
const description = typeof item.description === 'string' ? item.description.trim().slice(0, 400) : ''
|
|
39
|
+
rows.push({ value, name, description })
|
|
40
|
+
if (rows.length >= MAX_OPTIONS) break
|
|
41
|
+
}
|
|
42
|
+
return rows
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const fallbackRows = () => FALLBACK.map(value => ({ value, name: value, description: '' }))
|
|
46
|
+
const identity = connection => String(connection?.server || '') + '\u0000' + String(connection?.token || '')
|
|
47
|
+
|
|
48
|
+
async function load({ rpc, connection }) {
|
|
49
|
+
const key = identity(connection)
|
|
50
|
+
if (cached && cached.key === key && Date.now() - cached.at < CACHE_MS) return cached.value
|
|
51
|
+
let rows = null
|
|
52
|
+
try { rows = rowsOf(await rpc('permissionPresets.catalog', {}, 10000)) } catch { rows = null }
|
|
53
|
+
const value = rows && rows.length ? { known: true, rows } : { known: false, rows: fallbackRows() }
|
|
54
|
+
if (connection?.valid?.() !== false) cached = { key, at: Date.now(), value }
|
|
55
|
+
return value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function invalidate() { cached = null }
|
|
59
|
+
|
|
60
|
+
function labelOf(row, t) {
|
|
61
|
+
// The host reports the Auto contribution by its machine name; the shipped
|
|
62
|
+
// client owns that option's label, badge and description.
|
|
63
|
+
return row.value === 'auto' ? t('perm.autoLabel') : row.name
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function detailOf(row, t) {
|
|
67
|
+
return row.value === 'auto' ? t('perm.autoDesc') : row.description
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function chip(row, isCurrent, options) {
|
|
71
|
+
const { t } = options
|
|
72
|
+
const node = button('menu-chip perm-opt' + (isCurrent ? ' current' : '') + (GATED.has(row.value) ? ' danger' : ''))
|
|
73
|
+
node.dataset.perm = row.value
|
|
74
|
+
node.setAttribute('aria-pressed', isCurrent ? 'true' : 'false')
|
|
75
|
+
node.append(document.createTextNode(labelOf(row, t)))
|
|
76
|
+
if (row.value === 'auto') node.append(text('span', 'perm-badge', t('perm.autoBadge')))
|
|
77
|
+
const detail = detailOf(row, t)
|
|
78
|
+
if (detail) node.title = detail
|
|
79
|
+
node.addEventListener('click', () => {
|
|
80
|
+
if (!valid(options)) return
|
|
81
|
+
if (isCurrent) { options.close?.(); return }
|
|
82
|
+
if (GATED.has(row.value)) confirm(row, options)
|
|
83
|
+
else void apply(row.value, options)
|
|
84
|
+
})
|
|
85
|
+
return node
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function currentOnly(value, options) {
|
|
89
|
+
const node = button('menu-chip perm-opt current', value + ' · ' + options.t('perm.current'))
|
|
90
|
+
node.disabled = true
|
|
91
|
+
return node
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function confirm(row, options) {
|
|
95
|
+
const { container, t } = options
|
|
96
|
+
const auto = row.value === 'auto'
|
|
97
|
+
const card = text('div', 'perm-confirm')
|
|
98
|
+
const acknowledge = document.createElement('input')
|
|
99
|
+
acknowledge.type = 'checkbox'
|
|
100
|
+
acknowledge.className = 'perm-confirm-box'
|
|
101
|
+
const ackLabel = text('label', 'perm-confirm-ack')
|
|
102
|
+
ackLabel.append(acknowledge, text('span', null, t(auto ? 'perm.autoConfirmAck' : 'perm.confirmAck')))
|
|
103
|
+
const actions = text('div', 'perm-confirm-actions')
|
|
104
|
+
const cancel = button('menu-chip perm-confirm-cancel', t('perm.confirmCancel'))
|
|
105
|
+
const enable = button('menu-chip danger perm-confirm-enable', t(auto ? 'perm.autoConfirmEnable' : 'perm.confirmEnable'))
|
|
106
|
+
enable.disabled = true
|
|
107
|
+
acknowledge.addEventListener('change', () => { enable.disabled = !acknowledge.checked })
|
|
108
|
+
cancel.addEventListener('click', () => { container.__dshPerm = (container.__dshPerm || 0) + 1; void open(options) })
|
|
109
|
+
enable.addEventListener('click', () => { if (acknowledge.checked) void apply(row.value, options) })
|
|
110
|
+
actions.append(cancel, enable)
|
|
111
|
+
card.append(
|
|
112
|
+
text('div', 'perm-confirm-title', t(auto ? 'perm.autoConfirmTitle' : 'perm.confirmTitle')),
|
|
113
|
+
text('p', 'perm-confirm-desc', t(auto ? 'perm.autoConfirmDesc' : 'perm.confirmDesc')),
|
|
114
|
+
ackLabel,
|
|
115
|
+
actions,
|
|
116
|
+
)
|
|
117
|
+
container.replaceChildren(card)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function apply(value, options) {
|
|
121
|
+
const { container, t } = options
|
|
122
|
+
if (!valid(options) || container.dataset.pending) return
|
|
123
|
+
const operation = {}; container.__dshPermPending = operation
|
|
124
|
+
container.dataset.pending = value
|
|
125
|
+
let ok = false
|
|
126
|
+
try { ok = await options.request(value) } catch { ok = false }
|
|
127
|
+
if (container.__dshPermPending === operation) delete container.dataset.pending
|
|
128
|
+
if (!valid(options)) return
|
|
129
|
+
if (!ok) { options.toast?.(t('perm.changeFailed'), 'err'); return }
|
|
130
|
+
options.close?.()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function open(options) {
|
|
134
|
+
const { container, t } = options
|
|
135
|
+
if (!container) return
|
|
136
|
+
const serial = container.__dshPerm = (container.__dshPerm || 0) + 1
|
|
137
|
+
delete container.dataset.pending
|
|
138
|
+
container.__dshPermPending = null
|
|
139
|
+
options = { ...options, serial }
|
|
140
|
+
container.replaceChildren(text('div', 'perm-hint', t('perm.loading')))
|
|
141
|
+
const result = await load(options)
|
|
142
|
+
if (!valid(options)) return
|
|
143
|
+
container.replaceChildren()
|
|
144
|
+
const current = typeof options.current === 'string' ? options.current : ''
|
|
145
|
+
for (const row of result.rows) container.append(chip(row, row.value === current, options))
|
|
146
|
+
if (current && !result.rows.some(row => row.value === current)) container.append(currentOnly(current, options))
|
|
147
|
+
if (!result.known) container.append(text('div', 'perm-hint', t('perm.hostUnavailable')))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function valid(options) {
|
|
151
|
+
return options.container.__dshPerm === options.serial && options.connection?.valid?.() !== false && options.currentValid?.() !== false
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
root.DshPermissionPresets = {
|
|
155
|
+
open, invalidate, rowsOf, fallbackRows,
|
|
156
|
+
gated: value => GATED.has(value),
|
|
157
|
+
fallback: FALLBACK.slice(),
|
|
158
|
+
}
|
|
159
|
+
})(window)
|