@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.9

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 (211) hide show
  1. package/README.en.md +61 -0
  2. package/README.md +60 -2
  3. package/apk/dsh-remote.apk +0 -0
  4. package/approval-summary.mjs +115 -0
  5. package/client.js +197 -0
  6. package/cordis.patch.yml +5 -0
  7. package/doctor-skill.mjs +99 -0
  8. package/doctor-target.mjs +24 -0
  9. package/file-delivery.mjs +84 -0
  10. package/gateway-stats.cjs +501 -0
  11. package/gateway.cjs +8451 -0
  12. package/index.mjs +1788 -0
  13. package/insights.mjs +111 -0
  14. package/market.mjs +86 -0
  15. package/package.json +73 -4
  16. package/peak-reminders.mjs +50 -0
  17. package/plugin-center.mjs +777 -0
  18. package/plugin-transaction.mjs +300 -0
  19. package/public/activity.js +188 -0
  20. package/public/admin.html +820 -0
  21. package/public/admin.js +1167 -0
  22. package/public/announcement-forms.js +89 -0
  23. package/public/announcements.json +464 -0
  24. package/public/app.js +8826 -0
  25. package/public/approval-records.js +301 -0
  26. package/public/approval-summary.js +78 -0
  27. package/public/build.json +5 -0
  28. package/public/cache-upgrade.js +51 -0
  29. package/public/chat-copy.js +59 -0
  30. package/public/chat-files.js +87 -0
  31. package/public/desktop/desktop.css +816 -0
  32. package/public/desktop/desktop.html +871 -0
  33. package/public/desktop/desktop.js +4548 -0
  34. package/public/desktop/i18n.js +85 -0
  35. package/public/diagnostics.js +203 -0
  36. package/public/doctor-entry.js +94 -0
  37. package/public/doctor.css +205 -0
  38. package/public/doctor.js +769 -0
  39. package/public/donate.png +0 -0
  40. package/public/e2ee-transport.js +219 -0
  41. package/public/extensions.css +109 -0
  42. package/public/extensions.js +215 -0
  43. package/public/file-inbox.css +66 -0
  44. package/public/file-inbox.js +289 -0
  45. package/public/genui.css +8 -0
  46. package/public/genui.js +254 -0
  47. package/public/history.js +304 -0
  48. package/public/i18n.js +57 -0
  49. package/public/icon.svg +12 -0
  50. package/public/image-cache.js +141 -0
  51. package/public/image-preview.js +290 -0
  52. package/public/index.html +1568 -0
  53. package/public/insights.css +28 -0
  54. package/public/insights.js +290 -0
  55. package/public/jsqr.min.js +10104 -0
  56. package/public/lan-discovery.js +94 -0
  57. package/public/link-check.js +109 -0
  58. package/public/manifest.webmanifest +16 -0
  59. package/public/md.js +333 -0
  60. package/public/morphicons-init.js +41 -0
  61. package/public/motion.js +557 -0
  62. package/public/network.js +100 -0
  63. package/public/onboarding.css +36 -0
  64. package/public/onboarding.js +253 -0
  65. package/public/operations.js +141 -0
  66. package/public/permission-presets.js +159 -0
  67. package/public/plugin-center.css +120 -0
  68. package/public/plugin-center.js +666 -0
  69. package/public/plugin-icon.svg +5 -0
  70. package/public/plugin.html +68 -0
  71. package/public/plugin.js +211 -0
  72. package/public/qrcode.min.js +2297 -0
  73. package/public/relay-autopair.js +251 -0
  74. package/public/relay-devices.js +80 -0
  75. package/public/relay-settings.css +24 -0
  76. package/public/relay-settings.js +194 -0
  77. package/public/remote-state.js +27 -0
  78. package/public/remote-ui.css +148 -0
  79. package/public/remote-ui.js +243 -0
  80. package/public/session-deck.css +79 -0
  81. package/public/session-deck.js +180 -0
  82. package/public/session-presets.js +47 -0
  83. package/public/setup.css +18 -0
  84. package/public/setup.js +213 -0
  85. package/public/sha256.js +119 -0
  86. package/public/skills.css +81 -0
  87. package/public/skills.js +202 -0
  88. package/public/skins/blue-fish/DESIGN.md +24 -0
  89. package/public/skins/blue-fish/face.png +0 -0
  90. package/public/skins/blue-fish/icon-blush.png +0 -0
  91. package/public/skins/blue-fish/icon-sleep.png +0 -0
  92. package/public/skins/blue-fish/icon-smile.png +0 -0
  93. package/public/skins/blue-fish/icon-star.png +0 -0
  94. package/public/skins/blue-fish/icon-wink.png +0 -0
  95. package/public/skins/blue-fish/icon.png +0 -0
  96. package/public/skins/blue-fish/mascot.png +0 -0
  97. package/public/skins/blue-fish/pattern.png +0 -0
  98. package/public/skins/blue-fish/preview.html +12 -0
  99. package/public/skins/blue-fish/skin.css +122 -0
  100. package/public/skins/blue-fish/sparkles.svg +18 -0
  101. package/public/skins/bocchi/DESIGN.md +99 -0
  102. package/public/skins/bocchi/face.png +0 -0
  103. package/public/skins/bocchi/grain.png +0 -0
  104. package/public/skins/bocchi/icon-blush.png +0 -0
  105. package/public/skins/bocchi/icon-sleep.png +0 -0
  106. package/public/skins/bocchi/icon-smile.png +0 -0
  107. package/public/skins/bocchi/icon-star.png +0 -0
  108. package/public/skins/bocchi/icon-wink.png +0 -0
  109. package/public/skins/bocchi/icon.png +0 -0
  110. package/public/skins/bocchi/pattern-soft.png +0 -0
  111. package/public/skins/bocchi/pattern.png +0 -0
  112. package/public/skins/bocchi/preview.html +55 -0
  113. package/public/skins/bocchi/skin.css +233 -0
  114. package/public/skins/bocchi/stage-bg.png +0 -0
  115. package/public/skins/bocchi/stage-soft.png +0 -0
  116. package/public/skins/bocchi/stand.png +0 -0
  117. package/public/skins/bocchi/sticker-guitar.png +0 -0
  118. package/public/skins/kessoku/DESIGN.md +38 -0
  119. package/public/skins/kessoku/grain.png +0 -0
  120. package/public/skins/kessoku/skin.css +212 -0
  121. package/public/skins/kita/SOURCES.json +51 -0
  122. package/public/skins/kita/face.png +0 -0
  123. package/public/skins/kita/icon-live.png +0 -0
  124. package/public/skins/kita/icon-reddress.png +0 -0
  125. package/public/skins/kita/icon-seifuku.png +0 -0
  126. package/public/skins/kita/pattern.png +0 -0
  127. package/public/skins/kita/preview.html +56 -0
  128. package/public/skins/kita/skin.css +26 -0
  129. package/public/skins/kita/stand.png +0 -0
  130. package/public/skins/kita/sticker-live.png +0 -0
  131. package/public/skins/nijika/SOURCES.json +51 -0
  132. package/public/skins/nijika/face.png +0 -0
  133. package/public/skins/nijika/icon-live.png +0 -0
  134. package/public/skins/nijika/icon-reddress.png +0 -0
  135. package/public/skins/nijika/icon-seifuku.png +0 -0
  136. package/public/skins/nijika/pattern.png +0 -0
  137. package/public/skins/nijika/preview.html +56 -0
  138. package/public/skins/nijika/skin.css +25 -0
  139. package/public/skins/nijika/stand.png +0 -0
  140. package/public/skins/nijika/sticker-live.png +0 -0
  141. package/public/skins/penguin/DESIGN.md +33 -0
  142. package/public/skins/penguin/SOURCES.json +22 -0
  143. package/public/skins/penguin/aic-blueprint.svg +24 -0
  144. package/public/skins/penguin/endfield-triangles.svg +4 -0
  145. package/public/skins/penguin/face.png +0 -0
  146. package/public/skins/penguin/icon-blush.png +0 -0
  147. package/public/skins/penguin/icon-dizzy.png +0 -0
  148. package/public/skins/penguin/icon-laugh.png +0 -0
  149. package/public/skins/penguin/icon-sleep.png +0 -0
  150. package/public/skins/penguin/icon-smile.png +0 -0
  151. package/public/skins/penguin/icon-star.png +0 -0
  152. package/public/skins/penguin/icon-wink.png +0 -0
  153. package/public/skins/penguin/icon.png +0 -0
  154. package/public/skins/penguin/mascot.png +0 -0
  155. package/public/skins/penguin/pattern-night.png +0 -0
  156. package/public/skins/penguin/pattern.png +0 -0
  157. package/public/skins/penguin/preview.html +12 -0
  158. package/public/skins/penguin/skin.css +212 -0
  159. package/public/skins/ryo/SOURCES.json +51 -0
  160. package/public/skins/ryo/face.png +0 -0
  161. package/public/skins/ryo/icon-live.png +0 -0
  162. package/public/skins/ryo/icon-reddress.png +0 -0
  163. package/public/skins/ryo/icon-seifuku.png +0 -0
  164. package/public/skins/ryo/pattern.png +0 -0
  165. package/public/skins/ryo/preview.html +56 -0
  166. package/public/skins/ryo/skin.css +25 -0
  167. package/public/skins/ryo/stand.png +0 -0
  168. package/public/skins/ryo/sticker-live.png +0 -0
  169. package/public/sponsor-entry.js +21 -0
  170. package/public/styles.css +1526 -0
  171. package/public/subagents.css +61 -0
  172. package/public/subagents.js +275 -0
  173. package/public/task-board.js +109 -0
  174. package/public/teams.js +98 -0
  175. package/public/theme-picker.css +58 -0
  176. package/public/theme-vars.css +1044 -0
  177. package/public/theme.js +166 -0
  178. package/public/transcribe-core.js +74 -0
  179. package/public/turn-results.js +121 -0
  180. package/public/update.json +49 -0
  181. package/public/vendor/gsap/NOTICE.md +10 -0
  182. package/public/vendor/gsap/gsap.min.js +11 -0
  183. package/public/vendor/morphicons/LICENSE +21 -0
  184. package/public/vendor/morphicons/README.md +10 -0
  185. package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
  186. package/public/vendor/morphicons/dom.js +206 -0
  187. package/public/vendor/morphicons/element.js +261 -0
  188. package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
  189. package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
  190. package/public/version.json +3 -0
  191. package/public/voice-input.js +1151 -0
  192. package/public/workflow.css +365 -0
  193. package/public/workflow.js +419 -0
  194. package/session-file.mjs +39 -0
  195. package/skills/dsh-remote-doctor/SKILL.md +186 -0
  196. package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
  197. package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
  198. package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
  199. package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
  200. package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
  201. package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
  202. package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
  203. package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
  204. package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
  205. package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
  206. package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
  207. package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
  208. package/skills.mjs +53 -0
  209. package/speech-whisper.mjs +705 -0
  210. package/task-board.mjs +57 -0
  211. package/teams.mjs +58 -0
package/insights.mjs ADDED
@@ -0,0 +1,111 @@
1
+ // Read-only, bounded adapter for dsh-cost-meter 1.8.x/1.9.x. Never forward its config.
2
+ const states = new WeakMap()
3
+ const record = value => value && typeof value === 'object' && !Array.isArray(value) ? value : {}
4
+ const number = value => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null
5
+ const text = (value, max = 80) => typeof value === 'string' ? value.slice(0, max) : ''
6
+ const status = value => ['ok', 'off', 'error', 'stale', 'loading', 'partial'].includes(value) ? value : 'unknown'
7
+ const visible = value => value?.enabled === true && value.display !== 'off'
8
+ const unit = value => ['USD', 'CNY', 'EUR', 'CREDITS'].includes(value) ? value : ''
9
+ function customBalances(raw, config) {
10
+ const multiple = Array.isArray(config.customBalances)
11
+ const definitions = multiple ? config.customBalances : [config.customBalance]
12
+ const snapshots = multiple ? (Array.isArray(raw.customBalances) ? raw.customBalances : []) : [raw.customBalance]
13
+ return snapshots.slice(0, 40).flatMap(value => {
14
+ const row = record(value), index = multiple ? row.index : 0
15
+ if (!Number.isInteger(index) || index < 0 || !visible(definitions[index])) return []
16
+ return [{ name: text(row.label || definitions[index].label), status: status(row.status), fetchedAt: number(row.fetchedAt),
17
+ currency: unit(row.unit), remaining: typeof row.remaining === 'number' && Number.isFinite(row.remaining) ? row.remaining : null,
18
+ maxBudget: number(row.maxBudget), spend: number(row.spend) }]
19
+ })
20
+ }
21
+ function gatewayQuotas(raw, config) {
22
+ const definitions = Array.isArray(config.gatewayQuotas?.sources) ? config.gatewayQuotas.sources : []
23
+ return (Array.isArray(raw.gatewayQuotas) ? raw.gatewayQuotas : []).slice(0, 20).flatMap(value => {
24
+ const row = record(value)
25
+ if (!visible(definitions.find(source => source?.id === row.id))) return []
26
+ return [{ name: text(row.label), status: status(row.status), fetchedAt: number(row.fetchedAt),
27
+ accounts: (Array.isArray(row.accounts) ? row.accounts : []).slice(0, 16).map(value => {
28
+ const account = record(value)
29
+ return { name: text(account.label), provider: text(account.provider), status: status(account.status),
30
+ windows: (Array.isArray(account.windows) ? account.windows : []).slice(0, 8).map(value => {
31
+ const w = record(value), percent = number(w.percent)
32
+ return { name: text(w.label || w.id), percent: percent !== null && percent <= 100 ? percent : null, resetsAt: text(w.resetsAt) }
33
+ }) }
34
+ }) }]
35
+ })
36
+ }
37
+ function amount(value) {
38
+ const row = record(value)
39
+ const tokens = Object.fromEntries(['input', 'cacheRead', 'cacheWrite', 'output'].map(key => [key, number(row[key])]))
40
+ const cost = number(row.cost), apiCost = number(row.apiCost)
41
+ return { cost, apiCost, planEquivalent: cost !== null && apiCost !== null && cost >= apiCost ? cost - apiCost : null, calls: number(row.calls), tokens,
42
+ totalTokens: Object.values(tokens).every(value => value !== null) ? Object.values(tokens).reduce((sum, value) => sum + value, 0) : null }
43
+ }
44
+ function windows(value, statistics) {
45
+ return Object.entries(record(value)).slice(0, 8).map(([key, raw]) => {
46
+ const row = record(raw), percent = number(row.percent)
47
+ const stat = record(record(statistics)[key] || record(statistics)[{ rolling: 'fiveHour', five_hour: 'fiveHour', seven_day: 'weekly' }[key]])
48
+ return { name: text(key), percent: percent !== null && percent <= 100 ? percent : null,
49
+ resetsAt: text(row.resetsAt), unlimited: row.unlimited === true, localTokens: number(stat.localTokens) }
50
+ })
51
+ }
52
+ export function summarizeCost(state, session, sessionId) {
53
+ const raw = record(state), config = record(raw.config), balance = record(raw.balance)
54
+ const plans = Object.entries(record(raw.codingPlans)).slice(0, 20)
55
+ .filter(([, row]) => record(row).enabled === true && record(row).display !== 'off')
56
+ .map(([name, value]) => {
57
+ const row = record(value)
58
+ return { name: text(name), status: status(row.status), fetchedAt: number(row.fetchedAt), windows: windows(row.windows, record(record(raw.planStats).providers)[name]?.windows) }
59
+ })
60
+ const go = record(raw.goQuota)
61
+ if (record(config.goQuota).enabled === true && record(config.goQuota).display !== 'off') {
62
+ plans.unshift({ name: 'OpenCode Go', status: status(go.status), fetchedAt: number(go.fetchedAt),
63
+ windows: windows({ rolling: go.rolling, weekly: go.weekly, monthly: go.monthly }, record(record(raw.planStats).providers).go?.windows).filter(row => row.percent !== null) })
64
+ }
65
+ const s = record(session)
66
+ return { schema: 1, available: true, source: 'dsh-cost-meter', generatedAt: Date.now(), currency: 'USD',
67
+ day: text(record(raw.meta).dayKey || record(raw.runtime).dayKey || record(raw.today).date, 10),
68
+ today: config.hideTodayCost === true ? null : amount(raw.today),
69
+ history: config.hideTodayCost === true ? [] : (Array.isArray(raw.history) ? raw.history : []).slice(0, 90).filter(row => /^\d{4}-\d{2}-\d{2}$/.test(row?.date)).sort((a, b) => a.date.localeCompare(b.date)).slice(-7).map(row => ({ date: row.date, ...amount(row) })),
70
+ session: sessionId ? { found: s.found === true, own: s.found === true ? amount(s.own) : null,
71
+ subagents: s.found === true ? amount(s.subagents) : null, subagentCount: number(s.subagentCount) } : null,
72
+ balance: config.hideOfficialBalance === true || record(config.balance).display === 'off' ? null : {
73
+ status: status(balance.status), fetchedAt: number(balance.fetchedAt),
74
+ currency: /^[A-Z]{3}$/.test(balance.currency) ? balance.currency : '', total: number(balance.totalBalance) }, plans,
75
+ customBalances: customBalances(raw, config), gatewayQuotas: gatewayQuotas(raw, config) }
76
+ }
77
+ function bounded(task, ms = 20000) {
78
+ let timer
79
+ return Promise.race([task, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error('timeout')), ms) })])
80
+ .finally(() => clearTimeout(timer))
81
+ }
82
+ export async function readCostInsights(ctx, sessionId = '') {
83
+ if (typeof sessionId !== 'string' || sessionId.length > 200 || /[\s\x00-\x1f\x7f]/.test(sessionId)) {
84
+ return { status: 400, body: { ok: false, code: 'invalid-session' } }
85
+ }
86
+ let service
87
+ try { service = ctx.get?.('costMeter') } catch {}
88
+ if (!service) return { status: 200, body: { ok: true, schema: 1, available: false, code: 'not-installed' } }
89
+ if (typeof service.getState !== 'function') return { status: 200, body: { ok: true, schema: 1, available: false, code: 'unsupported' } }
90
+ try {
91
+ // A short shared cache coalesces device reads; no credentials or settings are sent.
92
+ let cache = states.get(ctx)
93
+ const identity = service[Symbol.for('cordis.original')] ?? service
94
+ if (!cache || cache.service !== identity) { cache = { service: identity, at: 0 }; states.set(ctx, cache) }
95
+ if (!cache.task && (!cache.value || Date.now() - cache.at > 15000)) {
96
+ cache.task = bounded(Promise.resolve().then(() => service.getState())).then(value => {
97
+ if (!value || typeof value !== 'object' || !value.today) throw new Error('unsupported')
98
+ cache.value = value; cache.at = Date.now(); return value
99
+ }).finally(() => { cache.task = null })
100
+ }
101
+ // Independent reads share one wait window; serial 20s waits can exceed both
102
+ // the gateway's 30s and the insights client's 25s request budgets.
103
+ const [raw, session] = await Promise.all([cache.task || cache.value,
104
+ sessionId && typeof service.getSessionCost === 'function'
105
+ ? bounded(Promise.resolve().then(() => service.getSessionCost(sessionId))) : null])
106
+ return { status: 200, body: { ok: true, ...summarizeCost(raw, session, sessionId) } }
107
+ } catch {
108
+ // Plugin failures may mention credentials, URLs or paths. Return a fixed code.
109
+ return { status: 502, body: { ok: false, code: 'cost-unavailable' } }
110
+ }
111
+ }
package/market.mjs ADDED
@@ -0,0 +1,86 @@
1
+ /* Read-only facade over DSH's official market. No index fetcher or ranking here. */
2
+ const packageName = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/
3
+ const versionName = /^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?$/
4
+ const text = (value, max = 300) => typeof value === 'string' ? value.slice(0, max) : ''
5
+ function localized(value) {
6
+ if (typeof value === 'string') return text(value)
7
+ return Object.fromEntries(Object.entries(value || {}).filter(([key, val]) => /^[a-z]{2}(?:-[A-Za-z]{2,4})?$/.test(key) && typeof val === 'string').slice(0, 8).map(([key, val]) => [key, text(val)]))
8
+ }
9
+ function safeUrl(value) {
10
+ try { const url = new URL(value); return /^https?:$/.test(url.protocol) && !url.username && !url.password && value.length <= 2048 ? url.href : '' } catch { return '' }
11
+ }
12
+ async function bounded(task, ms) {
13
+ let timer
14
+ try { return await Promise.race([task, new Promise((_, reject) => { timer = setTimeout(() => reject(Error('timeout')), ms) })]) } finally { clearTimeout(timer) }
15
+ }
16
+ function validQuery(query) {
17
+ if (!query || typeof query !== 'object' || Array.isArray(query) || Object.keys(query).some(key => !['text','category','labels','sort','offset','limit','fetchedAt','refresh'].includes(key))) return false
18
+ if (query.text != null && (typeof query.text !== 'string' || query.text.length > 80)) return false
19
+ if (query.category != null && (typeof query.category !== 'string' || query.category.length > 100)) return false
20
+ if (query.labels != null && (!Array.isArray(query.labels) || query.labels.length > 20 || query.labels.some(v => typeof v !== 'string' || v.length > 100))) return false
21
+ if (!Number.isSafeInteger(query.offset) || query.offset < 0 || !Number.isInteger(query.limit) || query.limit < 1 || query.limit > 100) return false
22
+ if (query.fetchedAt != null && (!Number.isSafeInteger(query.fetchedAt) || query.fetchedAt < 0) || query.refresh != null && typeof query.refresh !== 'boolean') return false
23
+ const sort = query.sort
24
+ if (!sort || typeof sort !== 'object' || Array.isArray(sort)) return false
25
+ if (['index','relevance'].includes(sort.kind)) return Object.keys(sort).length === 1
26
+ if (!['published','key'].includes(sort.kind) || !['asc','desc'].includes(sort.direction)) return false
27
+ return sort.kind === 'published' ? Object.keys(sort).length === 2 : Object.keys(sort).length === 3 && typeof sort.id === 'string' && !!sort.id && sort.id.length <= 100
28
+ }
29
+ export function createMarketAdapter(ctx, { timeoutMs = 20000 } = {}) {
30
+ function service() { try { return ctx.get?.('pluginMarket') } catch {} }
31
+ async function indexes() {
32
+ const host = service()
33
+ const base = { ok: true, source: 'official', indexes: [] }
34
+ if (!host) return { ...base, available: false, code: 'not-installed' }
35
+ if (typeof host.listIndexes !== 'function' || typeof host.search !== 'function') return { ...base, available: false, code: 'unsupported' }
36
+ try {
37
+ const rows = await bounded(Promise.resolve().then(() => host.listIndexes()), timeoutMs)
38
+ if (!Array.isArray(rows) || rows.length > 100) throw Error('unsupported')
39
+ return { ...base, available: true, indexes: rows.map(row => ({ url: safeUrl(row.url), title: localized(row.title), description: localized(row.description), ...(row.error || !safeUrl(row.url) ? { code: 'index-unavailable' } : {}) })) }
40
+ } catch { return { ...base, available: false, code: 'market-unavailable' } }
41
+ }
42
+ async function search(url, query) {
43
+ const empty = { ok: true, available: false, source: 'official', items: [], total: 0, nextOffset: null }
44
+ if (!validQuery(query)) return { ...empty, ok: false, code: 'invalid-query' }
45
+ const deadline = Date.now() + timeoutMs
46
+ const state = await indexes()
47
+ if (!state.available) return { ...empty, code: state.code }
48
+ const index = url ? state.indexes.find(row => row.url === url) : state.indexes.find(row => !row.code)
49
+ if (!index) return { ...empty, code: state.indexes.length ? 'unknown-index' : 'no-indexes' }
50
+ if (index.code) return { ...empty, code: 'index-unavailable' }
51
+ try {
52
+ const remaining = deadline - Date.now()
53
+ if (remaining <= 0) return { ...empty, code: 'market-unavailable' }
54
+ const result = await bounded(Promise.resolve().then(() => service().search(index.url, query)), remaining)
55
+ if (!Array.isArray(result.entries)) throw Error('invalid response')
56
+ const categories = Object.entries(result.metadata?.categories || {}).slice(0, 100).map(([id, row]) => ({ id: text(id, 100), title: localized(row.title) }))
57
+ const items = result.entries.slice(0, query.limit).filter(row => packageName.test(row.name)).map(row => {
58
+ const versions = Array.isArray(row.versions) ? row.versions : [], selected = versions.find(v => v.version === row.defaultVersion) || versions[0] || {}
59
+ return { name: row.name, version: text(selected.version, 100), title: localized(row.title), description: localized(row.description), author: text(row.author), homepage: safeUrl(row.homepage), repository: { url: safeUrl(row.repository?.url), directory: text(row.repository?.directory) }, category: text(row.metadata?.category, 100), versionCount: versions.length,
60
+ installSupported: selected.source?.type === 'npm' && (!selected.source.registry || safeUrl(selected.source.registry).replace(/\/$/, '') === 'https://registry.npmjs.org'),
61
+ installation: { status: ['not-installed','installed','update-available','different-version','provided'].includes(row.installation?.status) ? row.installation.status : 'unknown', installedVersion: text(row.installation?.installedVersion, 100) },
62
+ compatibility: typeof selected.compatibility?.compatible === 'boolean' ? { compatible: selected.compatibility.compatible, runtimeVersion: text(selected.compatibility.runtimeVersion, 100), requirements: { 'engines.dsh': text(selected.compatibility.requirements?.['engines.dsh'], 100) } } : null }
63
+ })
64
+ return { ok: true, available: true, source: 'official', index: { ...index, title: localized(result.title), description: localized(result.description) }, categories, items, total: Number.isSafeInteger(result.total) && result.total >= 0 ? result.total : items.length, nextOffset: Number.isSafeInteger(result.nextOffset) && result.nextOffset > query.offset ? result.nextOffset : null, fetchedAt: Number.isSafeInteger(result.fetchedAt) ? result.fetchedAt : null }
65
+ } catch { return { ...empty, code: 'market-unavailable' } }
66
+ }
67
+ return { indexes, search }
68
+ }
69
+
70
+ export function createReadmeReader(registry) {
71
+ const cache = new Map()
72
+ return async (name, version = '') => {
73
+ if (!packageName.test(name) || version && !versionName.test(version)) return { ok: false, code: 'invalid-name' }
74
+ try {
75
+ let record = cache.get(name)
76
+ if (!record || record.until < Date.now()) {
77
+ const data = await registry('/' + encodeURIComponent(name))
78
+ if (data.name !== name) throw Error('invalid package')
79
+ const content = typeof data.readme === 'string' ? data.readme : ''
80
+ record = { until: Date.now() + 600000, value: content.trim() ? { ok: true, available: true, source: 'npm', content: content.slice(0, 100000), truncated: content.length > 100000, version: versionName.test(data['dist-tags']?.latest || '') ? data['dist-tags'].latest : '', versionBasis: 'dist-tag:latest' } : { ok: true, available: false, code: 'no-readme' } }
81
+ cache.set(name, record); if (cache.size > 30) cache.delete(cache.keys().next().value)
82
+ }
83
+ return { ...record.value }
84
+ } catch { return { ok: false, code: 'readme-unavailable' } }
85
+ }
86
+ }
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@hyprnos/dsh-remote-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.8.9",
4
+ "description": "DSH Remote(个人分支)bundle 插件:手机连接入口、首次连接提示与浏览器管理控制台;内置网关自动启停,支持手机远程会话、审批、文件互传、语音输入和设备管理。",
5
+ "displayName": "DSH Remote",
6
+ "type": "module",
7
+ "main": "./index.mjs",
8
+ "exports": {
9
+ ".": "./index.mjs",
10
+ "./client": "./client.js",
11
+ "./cordis.patch.yml": "./cordis.patch.yml",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "index.mjs",
16
+ "client.js",
17
+ "gateway.cjs",
18
+ "gateway-stats.cjs",
19
+ "public",
20
+ "apk",
21
+ "cordis.patch.yml",
22
+ "*.md",
23
+ "plugin-center.mjs",
24
+ "plugin-transaction.mjs",
25
+ "market.mjs",
26
+ "insights.mjs",
27
+ "approval-summary.mjs",
28
+ "teams.mjs",
29
+ "task-board.mjs",
30
+ "peak-reminders.mjs",
31
+ "skills.mjs",
32
+ "doctor-skill.mjs",
33
+ "doctor-target.mjs",
34
+ "file-delivery.mjs",
35
+ "skills",
36
+ "session-file.mjs",
37
+ "speech-whisper.mjs"
38
+ ],
39
+ "keywords": [
40
+ "dsh-plugin",
41
+ "deepseek-harness",
42
+ "dsh",
43
+ "bundle",
44
+ "remote-control",
45
+ "mobile"
46
+ ],
47
+ "license": "MIT",
48
+ "homepage": "https://github.com/hyprnos/dsh-Remote",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/hyprnos/dsh-Remote.git",
52
+ "directory": "packages/plugin"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/hyprnos/dsh-Remote/issues"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "engines": {
61
+ "node": ">=18"
62
+ },
63
+ "dsh": {
64
+ "bundle": {
65
+ "patch": "./cordis.patch.yml"
66
+ },
67
+ "client": {
68
+ "inject": [
69
+ "@deepseek-ai/dsh-client-runtime",
70
+ "@deepseek-ai/dsh-client-ui-slots"
71
+ ],
72
+ "platform": "web"
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,50 @@
1
+ // Only public peak-pricing settings are projected; account configuration stays on the host.
2
+ export function peakReminderSchedule(config, now = Date.now()) {
3
+ const base = { ok: true, schema: 1, source: 'dsh-cost-meter', generatedAt: now, validUntil: now + 7 * 86400000 }
4
+ if (config?.peakEnabled === false || config?.peakAlertEnabled === false) return { ...base, available: true, enabled: false, events: [] }
5
+ const windows = config?.peakWindows, holidays = config?.peakHolidays
6
+ const effectiveAt = Date.parse(config?.peakEffectiveAt || '')
7
+ const validDate = d => typeof d === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(d) && Number.isFinite(Date.parse(d + 'T00:00:00Z')) && new Date(d + 'T00:00:00Z').toISOString().slice(0,10) === d
8
+ const ahead = config?.peakAlertAhead ?? 2, target = config?.peakAlertTarget ?? 'both'
9
+ if (config?.peakEnabled !== true || !Array.isArray(windows) || windows.length > 24 || !Array.isArray(holidays) || holidays.length > 366
10
+ || !Number.isFinite(effectiveAt) || !Number.isInteger(ahead) || ahead < 1 || ahead > 30 || !['peak','offpeak','both'].includes(target)
11
+ || windows.some(w => !Number.isInteger(w?.start) || w.start < 0 || w.start > 23 || !Number.isInteger(w?.end) || w.end < 0 || w.end > 24)
12
+ || holidays.some(d => !validDate(d))) {
13
+ return { ...base, available: false, code: 'unsupported-policy', events: [] }
14
+ }
15
+ const excluded = new Set(holidays)
16
+ const isPeak = at => {
17
+ if (at < effectiveAt) return false
18
+ const beijing = new Date(at + 8 * 3600000), day = beijing.getUTCDay()
19
+ if (day === 0 || day === 6 || excluded.has(beijing.toISOString().slice(0,10))) return false
20
+ const hour = new Date(at).getUTCHours()
21
+ return windows.some(w => w.start < w.end ? hour >= w.start && hour < w.end : hour >= w.start || hour < w.end)
22
+ }
23
+ const candidates = new Set([effectiveAt]), midnight = Math.floor(now / 86400000) * 86400000
24
+ for (let day = -1; day <= 8; day++) {
25
+ const start = midnight + day * 86400000
26
+ candidates.add(start + 16 * 3600000)
27
+ for (const w of windows) { candidates.add(start + w.start * 3600000); candidates.add(start + w.end * 3600000) }
28
+ }
29
+ const transitions = [...candidates].sort((a,b) => a-b).flatMap(at => {
30
+ const intoPeak = isPeak(at)
31
+ if (at < now - 30 * 60000 || at > base.validUntil || isPeak(at - 1) === intoPeak) return []
32
+ return [{ id: at + ':' + (intoPeak ? 'peak' : 'offpeak'), at, notifyAt: at - ahead * 60000, intoPeak }]
33
+ })
34
+ const events = transitions.filter(e => target === 'both' || (target === 'peak') === e.intoPeak).slice(0,64)
35
+ // Status needs every boundary even when alerts target only peak or offpeak.
36
+ const phase = { intoPeak: isPeak(now), transitions: transitions.filter(e => e.at > now).map(({ at, intoPeak }) => ({ at, intoPeak })) }
37
+ return { ...base, available: true, enabled: true, aheadMinutes: ahead, target, timezone: 'Asia/Shanghai', phase, events }
38
+ }
39
+
40
+ export async function readPeakReminders(ctx) {
41
+ let service
42
+ try { service = ctx.get?.('costMeter') } catch {}
43
+ if (!service || typeof service.getState !== 'function') return { status: 200, body: { ok: true, schema: 1, available: false, code: 'not-installed' } }
44
+ let timer
45
+ try {
46
+ const state = await Promise.race([Promise.resolve().then(() => service.getState()), new Promise((_, reject) => { timer = setTimeout(() => reject(Error('timeout')), 20000) })])
47
+ return { status: 200, body: peakReminderSchedule(state?.config) }
48
+ } catch { return { status: 502, body: { ok: false, code: 'peak-policy-unavailable' } } }
49
+ finally { clearTimeout(timer) }
50
+ }