@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
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,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyprnos/dsh-remote-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.8",
|
|
4
|
+
"description": "DSH Remote(个人分支)bundle 插件:手机连接入口、首次连接提示与浏览器管理控制台;内置网关自动启停,支持手机远程会话、审批、文件互传、语音输入和设备管理。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.mjs",
|
|
9
|
+
"./client": "./client.js",
|
|
10
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.mjs",
|
|
15
|
+
"client.js",
|
|
16
|
+
"gateway.cjs",
|
|
17
|
+
"gateway-stats.cjs",
|
|
18
|
+
"public",
|
|
19
|
+
"apk",
|
|
20
|
+
"cordis.patch.yml",
|
|
21
|
+
"*.md",
|
|
22
|
+
"plugin-center.mjs",
|
|
23
|
+
"plugin-transaction.mjs",
|
|
24
|
+
"market.mjs",
|
|
25
|
+
"insights.mjs",
|
|
26
|
+
"approval-summary.mjs",
|
|
27
|
+
"teams.mjs",
|
|
28
|
+
"task-board.mjs",
|
|
29
|
+
"peak-reminders.mjs",
|
|
30
|
+
"skills.mjs",
|
|
31
|
+
"doctor-skill.mjs",
|
|
32
|
+
"doctor-target.mjs",
|
|
33
|
+
"file-delivery.mjs",
|
|
34
|
+
"skills",
|
|
35
|
+
"session-file.mjs"
|
|
36
|
+
],
|
|
37
|
+
"keywords": [
|
|
38
|
+
"dsh-plugin",
|
|
39
|
+
"deepseek-harness",
|
|
40
|
+
"dsh",
|
|
41
|
+
"bundle",
|
|
42
|
+
"remote-control",
|
|
43
|
+
"mobile"
|
|
44
|
+
],
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"homepage": "https://github.com/hyprnos/dsh-Remote",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/hyprnos/dsh-Remote.git",
|
|
50
|
+
"directory": "packages/plugin"
|
|
51
|
+
},
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/hyprnos/dsh-Remote/issues"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18"
|
|
60
|
+
},
|
|
61
|
+
"dsh": {
|
|
62
|
+
"bundle": {
|
|
63
|
+
"patch": "./cordis.patch.yml"
|
|
64
|
+
},
|
|
65
|
+
"client": {
|
|
66
|
+
"inject": [
|
|
67
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
69
|
+
],
|
|
70
|
+
"platform": "web"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -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
|
+
}
|