dsh-hello 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +508 -2
  3. package/cordis.patch.yml +3 -0
  4. package/lib/catalogs.d.ts +100 -0
  5. package/lib/catalogs.d.ts.map +1 -0
  6. package/lib/catalogs.js +205 -0
  7. package/lib/catalogs.js.map +1 -0
  8. package/lib/client.js +544 -0
  9. package/lib/config.d.ts +96 -0
  10. package/lib/config.d.ts.map +1 -0
  11. package/lib/config.js +110 -0
  12. package/lib/config.js.map +1 -0
  13. package/lib/devices.d.ts +71 -0
  14. package/lib/devices.d.ts.map +1 -0
  15. package/lib/devices.js +219 -0
  16. package/lib/devices.js.map +1 -0
  17. package/lib/files.d.ts +43 -0
  18. package/lib/files.d.ts.map +1 -0
  19. package/lib/files.js +187 -0
  20. package/lib/files.js.map +1 -0
  21. package/lib/host.d.ts +324 -0
  22. package/lib/host.d.ts.map +1 -0
  23. package/lib/host.js +10 -0
  24. package/lib/host.js.map +1 -0
  25. package/lib/http.d.ts +77 -0
  26. package/lib/http.d.ts.map +1 -0
  27. package/lib/http.js +340 -0
  28. package/lib/http.js.map +1 -0
  29. package/lib/index.d.ts +20 -0
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/index.js +8227 -0
  32. package/lib/index.js.map +7 -0
  33. package/lib/interactions.d.ts +99 -0
  34. package/lib/interactions.d.ts.map +1 -0
  35. package/lib/interactions.js +568 -0
  36. package/lib/interactions.js.map +1 -0
  37. package/lib/pairing.d.ts +56 -0
  38. package/lib/pairing.d.ts.map +1 -0
  39. package/lib/pairing.js +128 -0
  40. package/lib/pairing.js.map +1 -0
  41. package/lib/protocol.d.ts +336 -0
  42. package/lib/protocol.d.ts.map +1 -0
  43. package/lib/protocol.js +7 -0
  44. package/lib/protocol.js.map +1 -0
  45. package/lib/push.d.ts +47 -0
  46. package/lib/push.d.ts.map +1 -0
  47. package/lib/push.js +339 -0
  48. package/lib/push.js.map +1 -0
  49. package/lib/read-state.d.ts +32 -0
  50. package/lib/read-state.d.ts.map +1 -0
  51. package/lib/read-state.js +39 -0
  52. package/lib/read-state.js.map +1 -0
  53. package/lib/routes.d.ts +33 -0
  54. package/lib/routes.d.ts.map +1 -0
  55. package/lib/routes.js +1293 -0
  56. package/lib/routes.js.map +1 -0
  57. package/lib/schedules.d.ts +31 -0
  58. package/lib/schedules.d.ts.map +1 -0
  59. package/lib/schedules.js +122 -0
  60. package/lib/schedules.js.map +1 -0
  61. package/lib/sessions.d.ts +60 -0
  62. package/lib/sessions.d.ts.map +1 -0
  63. package/lib/sessions.js +287 -0
  64. package/lib/sessions.js.map +1 -0
  65. package/lib/speech.d.ts +20 -0
  66. package/lib/speech.d.ts.map +1 -0
  67. package/lib/speech.js +47 -0
  68. package/lib/speech.js.map +1 -0
  69. package/lib/streams.d.ts +30 -0
  70. package/lib/streams.d.ts.map +1 -0
  71. package/lib/streams.js +106 -0
  72. package/lib/streams.js.map +1 -0
  73. package/lib/terminal.d.ts +55 -0
  74. package/lib/terminal.d.ts.map +1 -0
  75. package/lib/terminal.js +231 -0
  76. package/lib/terminal.js.map +1 -0
  77. package/lib/util.d.ts +18 -0
  78. package/lib/util.d.ts.map +1 -0
  79. package/lib/util.js +52 -0
  80. package/lib/util.js.map +1 -0
  81. package/lib/version.d.ts +15 -0
  82. package/lib/version.d.ts.map +1 -0
  83. package/lib/version.js +98 -0
  84. package/lib/version.js.map +1 -0
  85. package/package.json +80 -4
package/lib/client.js ADDED
@@ -0,0 +1,544 @@
1
+ /**
2
+ * Browser half of dsh-door.
3
+ *
4
+ * Ships one surface: a top-level Settings section, ordered just after General
5
+ * (order 5) so it is not the first menu item. There is no standalone page; the
6
+ * React panel reads the Host's `/admin/data` and `/admin/pair-code` endpoints.
7
+ *
8
+ * This file is hand-written in the lazy-CJS factory format the dsh client
9
+ * module system expects. build.mjs copies it to lib/client.js.
10
+ */
11
+ window.__ModuleLoader__.load({
12
+ id: 'dsh-door',
13
+ factory(require) {
14
+ const React = require('react')
15
+ const { Button, Input } = require('@deepseek-ai/dsh-client-ui-primitives')
16
+ const h = React.createElement
17
+
18
+ const NS = 'dshDoorAdmin'
19
+ const injected = globalThis.__DSH_DOOR__
20
+ const BASE = typeof injected?.basePath === 'string' && injected.basePath.length > 0
21
+ ? injected.basePath.replace(/\/$/, '')
22
+ : '/dsh-door'
23
+
24
+ const styles = `
25
+ .dd-page{display:flex;flex-direction:column;width:100%;gap:0}
26
+ .dd-head{padding:0 0 18px}
27
+ .dd-title{font-size:18px;font-weight:600;margin:0 0 4px;color:var(--dsw-alias-label-primary)}
28
+ .dd-desc{margin:0;font-size:13px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
29
+ .dd-row{display:flex;gap:24px;align-items:center;justify-content:space-between;padding:16px 0;border-bottom:0.5px solid var(--dsw-alias-border-l3,rgba(127,127,127,.22))}
30
+ .dd-row:last-child{border-bottom:none}
31
+ .dd-rowText{display:flex;flex-direction:column;gap:4px;min-width:0}
32
+ .dd-label{font-size:14px;color:var(--dsw-alias-label-primary)}
33
+ .dd-control{display:flex;gap:8px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
34
+ .dd-block{display:flex;flex-direction:column;gap:8px;padding:16px 0;border-bottom:0.5px solid var(--dsw-alias-border-l3,rgba(127,127,127,.22))}
35
+ .dd-code{font:600 20px ui-monospace,monospace;letter-spacing:3px;color:var(--dsw-alias-brand-primary,#3d7bfd)}
36
+ .dd-segment{display:inline-flex;gap:2px;padding:2px;border-radius:9px;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
37
+ .dd-segmentButton{height:28px;padding:0 12px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-tertiary,#888);font:inherit;font-size:13px;cursor:pointer}
38
+ .dd-segmentButton.is-active{background:var(--dsw-alias-surface-primary,#fff);color:var(--dsw-alias-label-primary,#111);box-shadow:0 1px 2px rgba(0,0,0,.12)}
39
+ .dd-countdown{font-size:12px;color:var(--dsw-alias-label-tertiary,#888);white-space:nowrap}
40
+ .dd-modalBackdrop{position:fixed;inset:0;z-index:100;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.35)}
41
+ .dd-modal{display:flex;flex-direction:column;gap:12px;width:min(380px,90vw);padding:18px;border-radius:12px;background:var(--dsw-alias-surface-primary,#fff);box-shadow:0 12px 40px rgba(0,0,0,.28)}
42
+ .dd-modalTitle{margin:0;font-size:16px;font-weight:600;color:var(--dsw-alias-label-primary,#111)}
43
+ .dd-modalActions{display:flex;justify-content:flex-end;gap:8px}
44
+ .dd-modalInput{box-sizing:border-box;width:100%;max-width:100%;min-width:0}
45
+ .dd-qr{font-size:10px;line-height:1;overflow:auto;margin:0;color:var(--dsw-alias-label-secondary);max-height:220px}
46
+ .dd-qr-img{display:flex;justify-content:flex-start;align-self:flex-start;background:#fff;border-radius:8px;padding:8px}
47
+ .dd-qr-img svg{width:220px;height:220px;display:block}
48
+ .dd-table{width:100%;border-collapse:collapse;font-size:13px}
49
+ .dd-table th,.dd-table td{text-align:left;padding:8px 0;border-bottom:0.5px solid var(--dsw-alias-border-l3,rgba(127,127,127,.18));color:var(--dsw-alias-label-secondary)}
50
+ .dd-table th{font-weight:500;color:var(--dsw-alias-label-tertiary)}
51
+ .dd-devices{display:flex;flex-direction:column;margin-top:2px}
52
+ .dd-device{display:flex;gap:20px;align-items:flex-start;justify-content:space-between;padding:14px 0;border-bottom:0.5px solid var(--dsw-alias-border-l3,rgba(127,127,127,.18))}
53
+ .dd-device:last-child{border-bottom:0}
54
+ .dd-deviceInfo{display:flex;flex-direction:column;gap:3px;min-width:0;flex:1}
55
+ .dd-deviceNameRow{display:flex;align-items:center;gap:8px;min-width:0}
56
+ .dd-deviceName{font-size:14px;color:var(--dsw-alias-label-primary,#111)}
57
+ .dd-rename{padding:0;border:0;background:transparent;color:var(--dsw-alias-link,var(--dsw-alias-brand-primary,#3d7bfd));font:inherit;font-size:12px;cursor:pointer}
58
+ .dd-rename:disabled{opacity:.45;cursor:default}
59
+ .dd-deviceMeta{font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary,#888);word-break:break-all}
60
+ .dd-deviceSide{display:flex;align-items:center;gap:20px;flex:none}
61
+ .dd-deviceTimes{display:flex;flex-direction:column;gap:3px;text-align:right}
62
+ .dd-deviceTime{font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary,#888);white-space:nowrap}
63
+ .dd-deviceAction{flex:none}
64
+ .dd-deviceAction button{white-space:nowrap;color:var(--dsw-alias-state-error-primary,#e5484d)!important}
65
+ .dd-deviceAction button:hover{background:var(--dsw-alias-state-error-primary,#e5484d)!important;color:#fff!important}
66
+ @media (max-width:640px){
67
+ .dd-device{flex-wrap:wrap}
68
+ .dd-deviceSide{width:100%;justify-content:space-between}
69
+ }
70
+ .dd-error{color:var(--dsw-alias-state-error-primary,#f87171);font-size:13px;margin:0}
71
+ .dd-link{color:var(--dsw-alias-link,var(--dsw-alias-brand-primary,#3d7bfd))}
72
+ .dd-input{width:180px}
73
+ `
74
+
75
+ const zh = {
76
+ nav: 'DSH Door',
77
+ title: 'DSH Door',
78
+ pairingCode: '配对码',
79
+ oneTimeMode: '一次性',
80
+ fixedMode: '永久性',
81
+ oneTimeHint: '一次性码过期后自动换新码',
82
+ fixedHint: '永久码不会过期;建议只在可信网络使用',
83
+ remaining: '剩余 {time}',
84
+ reset: '重置',
85
+ modify: '修改',
86
+ setPermanentTitle: '设置永久配对码',
87
+ setPermanentDesc: '输入 4 位数字,将作为永久配对码。',
88
+ modifyTitle: '修改永久配对码',
89
+ modifyDesc: '输入新的 4 位数字,旧永久码会立即失效。',
90
+ passwordPlaceholder: '4 位数字',
91
+ passwordInvalid: '请输入 4 位数字',
92
+ confirm: '确定',
93
+ cancel: '取消',
94
+ resetTitle: '恢复为一次性配对码?',
95
+ resetDesc: '当前永久码会立即失效,并生成新的一次性码。',
96
+ qrTitle: '扫码/输入',
97
+ qrLoading: '二维码加载中…',
98
+ qrHint: '请用手机打开 DSH Door,连接 → 添加服务器 → 使用插件配对 → 扫描二维码。',
99
+ devices: '已配对设备',
100
+ device: '设备',
101
+ pairedAt: '配对时间',
102
+ lastSeen: '最近连接',
103
+ actions: '操作',
104
+ revoke: '移除',
105
+ rename: '改名',
106
+ renameTitle: '重命名设备',
107
+ renameDesc: '只修改显示名称,不影响已配对连接。',
108
+ renameEmpty: '设备名称不能为空',
109
+ revokeConfirm: '移除设备「{name}」?它需要重新配对才能连接。',
110
+ via: '地址',
111
+ noDevices: '还没有设备',
112
+ codeLost: '登录已失效,请刷新 dsh Web UI',
113
+ operationFailed: '操作失败',
114
+ }
115
+
116
+ const en = {
117
+ nav: 'DSH Door',
118
+ title: 'DSH Door',
119
+ pairingCode: 'Pairing code',
120
+ oneTimeMode: 'One-time',
121
+ fixedMode: 'Permanent',
122
+ oneTimeHint: 'A new code is generated when this one expires',
123
+ fixedHint: 'The permanent code never expires; use it only on a trusted network',
124
+ remaining: '{time} left',
125
+ reset: 'Reset',
126
+ modify: 'Change',
127
+ setPermanentTitle: 'Set a permanent pairing code',
128
+ setPermanentDesc: 'Enter four digits to use as the permanent pairing code.',
129
+ modifyTitle: 'Change the permanent pairing code',
130
+ modifyDesc: 'Enter four new digits; the old permanent code stops working immediately.',
131
+ passwordPlaceholder: 'Four digits',
132
+ passwordInvalid: 'Enter four digits',
133
+ confirm: 'Confirm',
134
+ cancel: 'Cancel',
135
+ resetTitle: 'Restore one-time pairing?',
136
+ resetDesc: 'The permanent code stops working immediately and a fresh one-time code is generated.',
137
+ qrTitle: 'Scan or type',
138
+ qrLoading: 'Loading QR…',
139
+ qrHint: 'Open DSH Door on your phone, then Connection → Add server → Plugin pairing → Scan QR code.',
140
+ devices: 'Paired devices',
141
+ device: 'Device',
142
+ pairedAt: 'Paired',
143
+ lastSeen: 'Last seen',
144
+ actions: 'Actions',
145
+ revoke: 'Remove',
146
+ rename: 'Rename',
147
+ renameTitle: 'Rename device',
148
+ renameDesc: 'Only the display name changes; the pairing stays connected.',
149
+ renameEmpty: 'The device name cannot be empty',
150
+ revokeConfirm: 'Remove “{name}”? It must pair again to reconnect.',
151
+ via: 'Via',
152
+ noDevices: 'No devices yet',
153
+ codeLost: 'Session expired. Reload the dsh Web UI.',
154
+ operationFailed: 'Operation failed',
155
+ }
156
+
157
+ function installStyles() {
158
+ const style = document.createElement('style')
159
+ style.dataset.plugin = 'dsh-door'
160
+ style.textContent = styles
161
+ document.head.append(style)
162
+ return () => style.remove()
163
+ }
164
+
165
+ return {
166
+ inject: ['slots', 'locale'],
167
+ apply(ctx) {
168
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-door: admin copy')
169
+ ctx.effect(installStyles, 'dsh-door: admin styles')
170
+
171
+ const t = ctx.locale.bind(NS)
172
+
173
+ /** Browser-local date/time for the device table; follows the page language. */
174
+ let deviceTimeFormat
175
+ function formatDeviceTime(value) {
176
+ const date = new Date(value)
177
+ if (Number.isNaN(date.getTime())) return '—'
178
+ try {
179
+ deviceTimeFormat ??= new Intl.DateTimeFormat(
180
+ document.documentElement.lang || navigator.language || undefined,
181
+ { dateStyle: 'medium', timeStyle: 'short' },
182
+ )
183
+ return deviceTimeFormat.format(date)
184
+ } catch {
185
+ return date.toLocaleString()
186
+ }
187
+ }
188
+
189
+ function AdminSection() {
190
+ const [data, setData] = React.useState(null)
191
+ const [error, setError] = React.useState(null)
192
+ const [busy, setBusy] = React.useState(false)
193
+ const [now, setNow] = React.useState(Date.now())
194
+ const [dialog, setDialog] = React.useState(null)
195
+ const [password, setPassword] = React.useState('')
196
+ const [dialogError, setDialogError] = React.useState(null)
197
+ const [busyDevice, setBusyDevice] = React.useState(null)
198
+ const [renameTarget, setRenameTarget] = React.useState(null)
199
+ const [renameValue, setRenameValue] = React.useState('')
200
+ const [renameError, setRenameError] = React.useState(null)
201
+
202
+ React.useEffect(() => {
203
+ let alive = true
204
+ async function load() {
205
+ try {
206
+ const response = await fetch(BASE + '/admin/data', { credentials: 'same-origin', cache: 'no-store' })
207
+ if (!response.ok) throw new Error(t('codeLost'))
208
+ const next = await response.json()
209
+ if (alive) {
210
+ setData(next)
211
+ setError(null)
212
+ }
213
+ } catch (failure) {
214
+ if (alive) setError(failure instanceof Error ? failure.message : String(failure))
215
+ }
216
+ }
217
+ void load()
218
+ const timer = setInterval(load, 5000)
219
+ return () => {
220
+ alive = false
221
+ clearInterval(timer)
222
+ }
223
+ }, [t])
224
+
225
+ React.useEffect(() => {
226
+ const timer = setInterval(() => setNow(Date.now()), 1000)
227
+ return () => clearInterval(timer)
228
+ }, [])
229
+
230
+ async function perform(payload) {
231
+ setBusy(true)
232
+ try {
233
+ const response = await fetch(BASE + '/admin/pair-code', {
234
+ method: 'POST',
235
+ credentials: 'same-origin',
236
+ headers: { 'content-type': 'application/json' },
237
+ body: JSON.stringify(payload),
238
+ })
239
+ if (!response.ok) {
240
+ const body = await response.json().catch(() => null)
241
+ throw new Error(body?.error?.message || t('operationFailed'))
242
+ }
243
+ setData(await response.json())
244
+ return null
245
+ } catch (failure) {
246
+ return failure instanceof Error ? failure.message : String(failure)
247
+ } finally {
248
+ setBusy(false)
249
+ }
250
+ }
251
+
252
+ const fixed = data?.fixed === true
253
+ const remaining = !fixed && data ? Math.max(0, data.expiresAt - now) : null
254
+ const left = remaining === null
255
+ ? ''
256
+ : `${Math.floor(remaining / 60000)}:${String(Math.floor((remaining % 60000) / 1000)).padStart(2, '0')}`
257
+
258
+ const openPermanent = () => {
259
+ setPassword('')
260
+ setDialogError(null)
261
+ setDialog('permanent')
262
+ }
263
+ const openReset = () => {
264
+ setDialogError(null)
265
+ setDialog('reset')
266
+ }
267
+ const confirmPermanent = async () => {
268
+ const code = password.trim()
269
+ if (!/^\d{4}$/.test(code)) {
270
+ setDialogError(t('passwordInvalid'))
271
+ return
272
+ }
273
+ const failure = await perform({ action: 'fixed', code })
274
+ if (failure !== null) {
275
+ setDialogError(failure)
276
+ return
277
+ }
278
+ setDialog(null)
279
+ setPassword('')
280
+ }
281
+ const confirmReset = async () => {
282
+ const failure = await perform({ action: 'auto' })
283
+ if (failure !== null) {
284
+ setDialogError(failure)
285
+ return
286
+ }
287
+ setDialog(null)
288
+ }
289
+
290
+ const revokeDevice = async (device) => {
291
+ const name = device.deviceName || String(device.deviceId || '').slice(0, 12)
292
+ if (!window.confirm(t('revokeConfirm', { name }))) return
293
+ setBusyDevice(device.deviceId)
294
+ setError(null)
295
+ try {
296
+ const response = await fetch(BASE + '/admin/devices/' + encodeURIComponent(device.deviceId), {
297
+ method: 'DELETE',
298
+ credentials: 'same-origin',
299
+ })
300
+ if (!response.ok) {
301
+ const body = await response.json().catch(() => null)
302
+ throw new Error(body?.error?.message || t('operationFailed'))
303
+ }
304
+ setData(await response.json())
305
+ } catch (failure) {
306
+ setError(failure instanceof Error ? failure.message : String(failure))
307
+ } finally {
308
+ setBusyDevice(null)
309
+ }
310
+ }
311
+
312
+ const openRename = (device) => {
313
+ setRenameValue(device.deviceName || '')
314
+ setRenameError(null)
315
+ setRenameTarget(device)
316
+ }
317
+
318
+ const confirmRename = async () => {
319
+ if (renameTarget === null) return
320
+ const name = renameValue.trim()
321
+ if (name.length === 0) {
322
+ setRenameError(t('renameEmpty'))
323
+ return
324
+ }
325
+ setBusyDevice(renameTarget.deviceId)
326
+ setRenameError(null)
327
+ setError(null)
328
+ try {
329
+ const response = await fetch(BASE + '/admin/devices/' + encodeURIComponent(renameTarget.deviceId), {
330
+ method: 'PUT',
331
+ credentials: 'same-origin',
332
+ headers: { 'content-type': 'application/json' },
333
+ body: JSON.stringify({ name }),
334
+ })
335
+ if (!response.ok) {
336
+ const body = await response.json().catch(() => null)
337
+ throw new Error(body?.error?.message || t('operationFailed'))
338
+ }
339
+ setData(await response.json())
340
+ setRenameTarget(null)
341
+ } catch (failure) {
342
+ setRenameError(failure instanceof Error ? failure.message : String(failure))
343
+ } finally {
344
+ setBusyDevice(null)
345
+ }
346
+ }
347
+
348
+ const devices = Array.isArray(data?.devices) ? data.devices : []
349
+
350
+ return h('section', { className: 'dd-page' },
351
+ h('header', { className: 'dd-head' },
352
+ h('h2', { className: 'dd-title' }, t('title'))),
353
+ error === null ? null : h('p', { className: 'dd-error' }, error),
354
+
355
+ h('div', { className: 'dd-row' },
356
+ h('div', { className: 'dd-rowText' },
357
+ h('span', { className: 'dd-label' }, t('pairingCode')),
358
+ h('span', { className: 'dd-desc' }, fixed ? t('fixedHint') : t('oneTimeHint')),
359
+ ),
360
+ h('div', { className: 'dd-control' },
361
+ h('div', { className: 'dd-segment' },
362
+ h('button', {
363
+ type: 'button',
364
+ className: 'dd-segmentButton' + (fixed ? '' : ' is-active'),
365
+ disabled: busy || data === null,
366
+ onClick: () => { if (fixed) openReset() },
367
+ }, t('oneTimeMode')),
368
+ h('button', {
369
+ type: 'button',
370
+ className: 'dd-segmentButton' + (fixed ? ' is-active' : ''),
371
+ disabled: busy || data === null,
372
+ onClick: () => { if (!fixed) openPermanent() },
373
+ }, t('fixedMode')),
374
+ ),
375
+ h('span', { className: 'dd-code' }, data?.formatted ?? '…'),
376
+ fixed
377
+ ? h(Button, {
378
+ variant: 'outline',
379
+ size: 'sm',
380
+ disabled: busy,
381
+ onClick: openPermanent,
382
+ }, t('modify'))
383
+ : h('span', { className: 'dd-countdown' }, left.length > 0 ? t('remaining', { time: left }) : ''),
384
+ ),
385
+ ),
386
+
387
+ h('div', { className: 'dd-block' },
388
+ h('span', { className: 'dd-label' }, t('qrTitle')),
389
+ data?.qrSvg
390
+ ? h('div', { className: 'dd-qr-img', dangerouslySetInnerHTML: { __html: data.qrSvg } })
391
+ : h('span', { className: 'dd-desc' }, t('qrFailed')),
392
+ h('span', { className: 'dd-desc' }, t('qrHint')),
393
+ ),
394
+
395
+ h('div', { className: 'dd-block' },
396
+ h('span', { className: 'dd-label' }, t('devices')),
397
+ h('div', { className: 'dd-devices' },
398
+ devices.length === 0
399
+ ? h('div', { className: 'dd-desc' }, t('noDevices'))
400
+ : devices.map(device => h('div', { className: 'dd-device', key: String(device.deviceId) },
401
+ h('div', { className: 'dd-deviceInfo' },
402
+ h('div', { className: 'dd-deviceNameRow' },
403
+ h('span', { className: 'dd-deviceName' }, device.deviceName || '—'),
404
+ h('button', {
405
+ type: 'button',
406
+ className: 'dd-rename',
407
+ disabled: busyDevice === device.deviceId,
408
+ onClick: () => { openRename(device) },
409
+ }, t('rename')),
410
+ ),
411
+ h('span', { className: 'dd-deviceMeta' },
412
+ `${device.platform || 'unknown'} · ${device.appVersion || '—'}`),
413
+ ),
414
+ h('div', { className: 'dd-deviceSide' },
415
+ h('div', { className: 'dd-deviceTimes' },
416
+ h('span', { className: 'dd-deviceTime' }, `${t('lastSeen')} ${formatDeviceTime(device.lastSeenAt)}`),
417
+ h('span', { className: 'dd-deviceTime' }, `${t('pairedAt')} ${formatDeviceTime(device.pairedAt)}`),
418
+ ),
419
+ h('div', { className: 'dd-deviceAction' },
420
+ h(Button, {
421
+ variant: 'ghost',
422
+ size: 'sm',
423
+ disabled: busyDevice === device.deviceId,
424
+ onClick: () => { void revokeDevice(device) },
425
+ }, t('revoke'))),
426
+ ),
427
+ )),
428
+ ),
429
+ ),
430
+
431
+ dialog === null ? null : h('div', {
432
+ className: 'dd-modalBackdrop',
433
+ onMouseDown: (event) => {
434
+ if (event.target === event.currentTarget) setDialog(null)
435
+ },
436
+ },
437
+ h('div', { className: 'dd-modal', role: 'dialog', 'aria-modal': 'true' },
438
+ h('h3', { className: 'dd-modalTitle' },
439
+ dialog === 'permanent'
440
+ ? (fixed ? t('modifyTitle') : t('setPermanentTitle'))
441
+ : t('resetTitle')),
442
+ h('p', { className: 'dd-desc' },
443
+ dialog === 'permanent'
444
+ ? (fixed ? t('modifyDesc') : t('setPermanentDesc'))
445
+ : t('resetDesc')),
446
+ dialog === 'permanent'
447
+ ? h(Input, {
448
+ className: 'dd-modalInput',
449
+ value: password,
450
+ placeholder: t('passwordPlaceholder'),
451
+ autoFocus: true,
452
+ autoComplete: 'off',
453
+ onChange: event => setPassword(event.target.value.replace(/\D/g, '').slice(0, 4)),
454
+ })
455
+ : null,
456
+ dialogError === null ? null : h('p', { className: 'dd-error' }, dialogError),
457
+ h('div', { className: 'dd-modalActions' },
458
+ h(Button, {
459
+ variant: 'ghost',
460
+ size: 'sm',
461
+ disabled: busy,
462
+ onClick: () => setDialog(null),
463
+ }, t('cancel')),
464
+ h(Button, {
465
+ variant: 'primary',
466
+ size: 'sm',
467
+ disabled: busy,
468
+ onClick: () => { void (dialog === 'permanent' ? confirmPermanent() : confirmReset()) },
469
+ }, t('confirm')),
470
+ ),
471
+ )),
472
+ renameTarget === null ? null : h('div', {
473
+ className: 'dd-modalBackdrop',
474
+ onMouseDown: (event) => {
475
+ if (event.target === event.currentTarget) setRenameTarget(null)
476
+ },
477
+ },
478
+ h('div', { className: 'dd-modal', role: 'dialog', 'aria-modal': 'true' },
479
+ h('h3', { className: 'dd-modalTitle' }, t('renameTitle')),
480
+ h('p', { className: 'dd-desc' }, t('renameDesc')),
481
+ h(Input, {
482
+ className: 'dd-modalInput',
483
+ value: renameValue,
484
+ placeholder: t('renameTitle'),
485
+ autoFocus: true,
486
+ autoComplete: 'off',
487
+ onChange: event => setRenameValue(event.target.value.slice(0, 120)),
488
+ onKeyDown: (event) => {
489
+ if (event.key !== 'Enter') return
490
+ event.preventDefault()
491
+ void confirmRename()
492
+ },
493
+ }),
494
+ renameError === null ? null : h('p', { className: 'dd-error' }, renameError),
495
+ h('div', { className: 'dd-modalActions' },
496
+ h(Button, {
497
+ variant: 'ghost',
498
+ size: 'sm',
499
+ disabled: busyDevice === renameTarget.deviceId,
500
+ onClick: () => setRenameTarget(null),
501
+ }, t('cancel')),
502
+ h(Button, {
503
+ variant: 'primary',
504
+ size: 'sm',
505
+ disabled: busyDevice === renameTarget.deviceId,
506
+ onClick: () => { void confirmRename() },
507
+ }, t('confirm')),
508
+ ),
509
+ )),
510
+ )
511
+ }
512
+
513
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
514
+ name: 'settings.section',
515
+ id: 'dsh-door',
516
+ order: 5,
517
+ label: () => t('nav'),
518
+ }, AdminSection))
519
+
520
+ ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
521
+ name: 'settings.section.icon',
522
+ id: 'dsh-door',
523
+ }, ({ size = 16, active }) => h('svg', {
524
+ width: size,
525
+ height: size,
526
+ viewBox: '0 0 16 16',
527
+ 'aria-hidden': true,
528
+ },
529
+ h('path', {
530
+ d: 'M3 2.5h7v11H3z',
531
+ fill: active ? 'currentColor' : 'none',
532
+ stroke: 'currentColor',
533
+ strokeWidth: 1.2,
534
+ }),
535
+ h('path', {
536
+ d: 'M10 3.5l3 1v9l-3-1z',
537
+ fill: 'none',
538
+ stroke: 'currentColor',
539
+ strokeWidth: 1.2,
540
+ }))))
541
+ },
542
+ }
543
+ },
544
+ })
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Plugin configuration. Every tunable value is a configuration field so a
3
+ * deployment can change it from `cordis.yml` without editing code.
4
+ */
5
+ import Schema from '@deepseek-ai/schemastery';
6
+ export interface PushConfig {
7
+ /** Push transport. `none` disables outbound notifications entirely. */
8
+ provider: 'none' | 'fcm' | 'apns' | 'relay';
9
+ /** Relay base URL, e.g. https://push.example.com. */
10
+ relayUrl?: string;
11
+ /** Host token issued by the relay's /v1/hosts enrollment. */
12
+ relayHostToken?: string;
13
+ /** FCM v1 service-account JSON (the whole JSON document as a string). */
14
+ fcmServiceAccountJson?: string;
15
+ /** FCM project id; read from the service account when omitted. */
16
+ fcmProjectId?: string;
17
+ /** APNs `.p8` private key contents (the whole PEM as a string). */
18
+ apnsKey?: string;
19
+ /** APNs key id from the Apple developer portal. */
20
+ apnsKeyId?: string;
21
+ /** APNs team id from the Apple developer portal. */
22
+ apnsTeamId?: string;
23
+ /** APNs bundle topic, normally the iOS bundle id. */
24
+ apnsTopic?: string;
25
+ /** APNs environment. */
26
+ apnsEnvironment: 'sandbox' | 'production';
27
+ /** Whether a turn-end notification is sent. */
28
+ notifyTurnEnd: boolean;
29
+ /** Whether approval requests are pushed. */
30
+ notifyApproval: boolean;
31
+ /** Whether user questions are pushed. */
32
+ notifyQuestion: boolean;
33
+ }
34
+ export interface Config {
35
+ /** Base path for every route this plugin registers. No trailing slash. */
36
+ basePath: string;
37
+ /**
38
+ * Extra authorities admitted by the Host-header check, as `host` or
39
+ * `host:port`. Pairing always records the authority a device paired through;
40
+ * loopback and the listener's own bind address are always admitted.
41
+ */
42
+ allowedHosts: string[];
43
+ /**
44
+ * Refuse plain-HTTP device traffic from non-loopback peers. TLS is normally
45
+ * terminated by a reverse proxy; set this only when the Host itself serves
46
+ * TLS and you want the plugin to enforce it.
47
+ */
48
+ requireSecure: boolean;
49
+ /**
50
+ * Bind authenticated requests to a known Host authority. The default is
51
+ * false: a valid device token is the boundary, so changing IP, port, or
52
+ * tunnel keeps the pairing. Set true for an extra pre-routing fence.
53
+ */
54
+ strictHostCheck: boolean;
55
+ /** One-time pairing code lifetime in milliseconds. */
56
+ pairingTtlMs: number;
57
+ /** Number of digits in a generated pairing code (4 by default). */
58
+ pairingCodeLength: number;
59
+ /** Failed pairing attempts allowed per client address inside the TTL. */
60
+ pairingMaxAttempts: number;
61
+ /** Fixed pairing code for local testing. Omit in normal deployments. */
62
+ pairingCode?: string;
63
+ /** Print the current pairing code and QR at activation. */
64
+ logPairingCode: boolean;
65
+ /** How long an approval request is held for the app before delegation. */
66
+ approvalWaitTimeoutMs: number;
67
+ /** How long a user question is held for the app before delegation. */
68
+ questionWaitTimeoutMs: number;
69
+ /**
70
+ * Allow an app to answer `always` for one tool in one session. dsh itself
71
+ * only has one-shot grants, so this is a process-local convenience grant and
72
+ * disappears when the Host restarts.
73
+ */
74
+ allowSessionWideGrants: boolean;
75
+ /**
76
+ * Expose authenticated debug routes that create synthetic approvals and
77
+ * questions. Disabled by default; use it to exercise the phone UI without a
78
+ * model/tool call, then turn it off.
79
+ */
80
+ enableDebugRoutes: boolean;
81
+ /** Maximum JSON request body in bytes. */
82
+ maxBodyBytes: number;
83
+ /** Rate-limit window in milliseconds. */
84
+ rateLimitWindowMs: number;
85
+ /** Maximum requests per client address inside one rate-limit window. */
86
+ rateLimitMax: number;
87
+ /** SemVer range of dsh runtimes this plugin supports. */
88
+ dshVersionRange: string;
89
+ /** Push configuration. */
90
+ push: PushConfig;
91
+ }
92
+ export declare const Config: Schema<Config>;
93
+ /** Structural type check for the configuration Cordis passes to apply(). */
94
+ export declare function normalizeConfig(input: Partial<Config> | undefined): Config;
95
+ export declare const defaultPushConfig: PushConfig;
96
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAE7C,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;IAC3C,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,yEAAyE;IACzE,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wBAAwB;IACxB,eAAe,EAAE,SAAS,GAAG,YAAY,CAAA;IACzC,+CAA+C;IAC/C,aAAa,EAAE,OAAO,CAAA;IACtB,4CAA4C;IAC5C,cAAc,EAAE,OAAO,CAAA;IACvB,yCAAyC;IACzC,cAAc,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,MAAM;IACrB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB;;;;OAIG;IACH,aAAa,EAAE,OAAO,CAAA;IACtB;;;;OAIG;IACH,eAAe,EAAE,OAAO,CAAA;IACxB,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAA;IACpB,mEAAmE;IACnE,iBAAiB,EAAE,MAAM,CAAA;IACzB,yEAAyE;IACzE,kBAAkB,EAAE,MAAM,CAAA;IAC1B,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2DAA2D;IAC3D,cAAc,EAAE,OAAO,CAAA;IACvB,0EAA0E;IAC1E,qBAAqB,EAAE,MAAM,CAAA;IAC7B,sEAAsE;IACtE,qBAAqB,EAAE,MAAM,CAAA;IAC7B;;;;OAIG;IACH,sBAAsB,EAAE,OAAO,CAAA;IAC/B;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAA;IAC1B,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,iBAAiB,EAAE,MAAM,CAAA;IACzB,wEAAwE;IACxE,YAAY,EAAE,MAAM,CAAA;IACpB,yDAAyD;IACzD,eAAe,EAAE,MAAM,CAAA;IACvB,0BAA0B;IAC1B,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,CAqChC,CAAA;AAEF,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,CA+C1E;AAUD,eAAO,MAAM,iBAAiB,EAAE,UAM/B,CAAA"}