dshmarket 1.73.23 → 1.73.24
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.md +1 -1
- package/README.zh.md +1 -1
- package/client/client.js +49 -4
- package/lib/routes.js +40 -0
- package/lib/telemetry.js +110 -0
- package/lib/types/net.d.ts +2 -1
- package/lib/types/telemetry.d.ts +44 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ Installs prefer repo-verified npm packages, then author-supplied prebuilt GitHub
|
|
|
118
118
|
- Installs are restricted to sources listed in the curated [awesome-dsh-plugin](https://awesome-dsh-plugin.com) registry — anything else is rejected
|
|
119
119
|
- Build scripts stay blocked by default (pnpm ≥10); allowing one is your explicit per-package choice
|
|
120
120
|
- Terminal/CLI-surface plugins are flagged before you install them into the web profile
|
|
121
|
-
- The install endpoint accepts same-origin POST only;
|
|
121
|
+
- The install endpoint accepts same-origin POST only; one anonymous count a day, no personal information, can be turned off in Settings (details in SECURITY.md)
|
|
122
122
|
- Backups can contain credentials from your profile config — the UI warns before export and upload; WebDAV sync is https-only, refuses private-network targets, and never stores your password in the browser
|
|
123
123
|
- Authenticated Gist requests always go directly to `api.github.com`; bearer tokens are never sent to a public GitHub acceleration service. GitHub source archives also stay on canonical codeload URLs so pnpm's integrity policy remains in force
|
|
124
124
|
- The restart endpoint additionally requires a direct loopback client (forwarded requests are rejected) and relaunches the exact DSH entry, arguments, environment, and working directory
|
package/README.zh.md
CHANGED
|
@@ -108,7 +108,7 @@ profile,因此不会出现在桌面端。请通过应用内的 **设置 →
|
|
|
108
108
|
- 只允许安装 [awesome-dsh-plugin](https://awesome-dsh-plugin.com) 精选列表内的来源,其它一律拒绝
|
|
109
109
|
- 构建脚本默认禁止执行(pnpm ≥10),放行与否由你按包显式决定
|
|
110
110
|
- 终端/命令行类插件装进网页版前会被明确提醒
|
|
111
|
-
- 安装接口只接受同源 POST
|
|
111
|
+
- 安装接口只接受同源 POST;每天一次匿名计数,不含任何个人信息,可在设置里关闭(详见 SECURITY.md)
|
|
112
112
|
- 备份可能包含 profile 配置里的密钥——导出与上传前 UI 会明确提醒;WebDAV 同步仅限 https、拒绝内网地址,且密码永不落盘浏览器
|
|
113
113
|
- 带鉴权的 Gist 请求始终直连 `api.github.com`,Bearer token 不会交给公共 GitHub 加速服务;GitHub 源码归档也保持 canonical codeload URL,以保留 pnpm 的完整性校验边界
|
|
114
114
|
- 重启接口还要求客户端直接来自环回地址(拒绝代理转发请求),并使用原入口、参数、环境和工作目录重新启动 DSH
|
package/client/client.js
CHANGED
|
@@ -224,6 +224,7 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
224
224
|
setSelfUpdateWaiting: "新版等待中",
|
|
225
225
|
setSelfUpdateHint: "更新会下载新版本,重启后生效。",
|
|
226
226
|
setSelfUpToDateHint: "",
|
|
227
|
+
setSelfChangedHint: "上次检查后有插件被安装或移除。请打开「插件市场 → 已安装 → 更新检查」,点「立即检查」刷新结果。",
|
|
227
228
|
setSelfHostManagedHint: "这份市场由桌面端安装,新版本请在桌面端更新。",
|
|
228
229
|
setSelfUpdate: "更新",
|
|
229
230
|
setSelfUpdatedHint: "已下载完成。重启 DeepSeek Harness 后新版本才会生效——页面会先显示新版本号。",
|
|
@@ -255,6 +256,10 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
255
256
|
setRegionGlobalHint: "从 npm 和 GitHub 官方源下载。",
|
|
256
257
|
setRegionChinaHint: "中国大陆访问更快。仅改变下载线路,插件来源不变。",
|
|
257
258
|
setRegionAuto: "已根据网络状况自动选择,可随时切换。",
|
|
259
|
+
setCount: "匿名使用统计",
|
|
260
|
+
setCountHint: "每天一次匿名计数,不含任何个人信息,可随时关闭。只发送:随机安装编号、市场版本、DSH 版本、桌面端或网页端、下载区域。",
|
|
261
|
+
setCountOn: "开启",
|
|
262
|
+
setCountOff: "关闭",
|
|
258
263
|
setGithubProxy: "GitHub 加速",
|
|
259
264
|
setGithubProxyAutoHint: "自动选择可用线路,失败时才切换。",
|
|
260
265
|
setGithubProxyCustom: "自定义",
|
|
@@ -1108,6 +1113,7 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
1108
1113
|
setSelfUpdateWaiting: "New version pending",
|
|
1109
1114
|
setSelfUpdateHint: "Updating downloads the new version; it takes effect after a restart.",
|
|
1110
1115
|
setSelfUpToDateHint: "",
|
|
1116
|
+
setSelfChangedHint: "A plugin was installed or removed after the last check. Open Plugin Market → Installed → Update checks and select Check now to refresh the results.",
|
|
1111
1117
|
setSelfHostManagedHint: "This copy was installed by the desktop app; update it from there.",
|
|
1112
1118
|
setSelfUpdate: "Update",
|
|
1113
1119
|
setSelfUpdatedHint: "Downloaded. Restart DeepSeek Harness for it to take effect — the page will already show the new version.",
|
|
@@ -1139,6 +1145,10 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
1139
1145
|
setRegionGlobalHint: "Downloads directly from npm and GitHub.",
|
|
1140
1146
|
setRegionChinaHint: "Faster in mainland China. Changes the download route, not the source.",
|
|
1141
1147
|
setRegionAuto: "Selected from a network check. Change it anytime.",
|
|
1148
|
+
setCount: "Anonymous usage count",
|
|
1149
|
+
setCountHint: "One anonymous count a day, no personal information, can be turned off anytime. It sends only: a random install ID, market version, DSH version, desktop or web, and download region.",
|
|
1150
|
+
setCountOn: "On",
|
|
1151
|
+
setCountOff: "Off",
|
|
1142
1152
|
setGithubProxy: "GitHub acceleration",
|
|
1143
1153
|
setGithubProxyAutoHint: "Chooses a working route automatically and switches only after a failure.",
|
|
1144
1154
|
setGithubProxyCustom: "Custom",
|
|
@@ -1991,6 +2001,7 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
1991
2001
|
setSelfUpdateWaiting: "新バージョン(更新待ち)",
|
|
1992
2002
|
setSelfUpdateHint: "更新すると新しいバージョンをダウンロードし、再起動後に有効になります。",
|
|
1993
2003
|
setSelfUpToDateHint: "",
|
|
2004
|
+
setSelfChangedHint: "前回の確認後にプラグインが追加または削除されました。「プラグインマーケット → インストール済み → 更新の確認」で「今すぐ確認」を選択してください。",
|
|
1994
2005
|
setSelfHostManagedHint: "このマーケットはデスクトップアプリがインストールしたものです。新しいバージョンへの更新はデスクトップアプリで行ってください。",
|
|
1995
2006
|
setSelfUpdate: "更新",
|
|
1996
2007
|
setSelfUpdatedHint: "ダウンロードが完了しました。新しいバージョンは DeepSeek Harness を再起動すると有効になります。ページには先に新しいバージョン番号が表示されます。",
|
|
@@ -2022,6 +2033,10 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
2022
2033
|
setRegionGlobalHint: "npm と GitHub の公式ソースからダウンロードします。",
|
|
2023
2034
|
setRegionChinaHint: "中国本土ではより高速です。ダウンロード経路が変わるだけで、プラグインの入手元は変わりません。",
|
|
2024
2035
|
setRegionAuto: "ネットワーク状況から自動で選択済みです。いつでも切り替えできます。",
|
|
2036
|
+
setCount: "匿名の利用カウント",
|
|
2037
|
+
setCountHint: "1日1回の匿名カウントです。個人情報は含まれず、いつでもオフにできます。送るのは、ランダムなインストール ID、マーケットのバージョン、DSH のバージョン、デスクトップかウェブか、ダウンロード地域だけです。",
|
|
2038
|
+
setCountOn: "オン",
|
|
2039
|
+
setCountOff: "オフ",
|
|
2025
2040
|
setGithubProxy: "GitHub 高速化",
|
|
2026
2041
|
setGithubProxyAutoHint: "使える経路を自動で選び、失敗したときだけ切り替えます。",
|
|
2027
2042
|
setGithubProxyCustom: "カスタム",
|
|
@@ -21647,7 +21662,8 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
21647
21662
|
githubProxyManaged: body.githubProxyManaged === true,
|
|
21648
21663
|
selfManaged: body.selfManaged !== false,
|
|
21649
21664
|
selfUninstallReachable: body.selfUninstallReachable !== false,
|
|
21650
|
-
buildEnv: body.buildEnv ?? {}
|
|
21665
|
+
buildEnv: body.buildEnv ?? {},
|
|
21666
|
+
anonymousCount: typeof body.anonymousCount === "boolean" ? body.anonymousCount : null
|
|
21651
21667
|
};
|
|
21652
21668
|
}
|
|
21653
21669
|
/** Render the effective build environment as one `KEY=value` line each. */
|
|
@@ -21776,7 +21792,8 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
21776
21792
|
githubProxyManaged: false,
|
|
21777
21793
|
selfManaged: true,
|
|
21778
21794
|
selfUninstallReachable: true,
|
|
21779
|
-
buildEnv: {}
|
|
21795
|
+
buildEnv: {},
|
|
21796
|
+
anonymousCount: null
|
|
21780
21797
|
});
|
|
21781
21798
|
}
|
|
21782
21799
|
try {
|
|
@@ -21929,6 +21946,25 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
21929
21946
|
}
|
|
21930
21947
|
})();
|
|
21931
21948
|
}, [post, t]);
|
|
21949
|
+
/** Turn the anonymous daily count on or off; shows what the server saved. */
|
|
21950
|
+
const onCount = (0, react.useCallback)((next) => {
|
|
21951
|
+
setError(null);
|
|
21952
|
+
(async () => {
|
|
21953
|
+
try {
|
|
21954
|
+
const body = await post(api("/dsh-market/telemetry"), { enabled: next });
|
|
21955
|
+
if (body.ok !== true) {
|
|
21956
|
+
setError(body.error ?? t("setSelfFailed"));
|
|
21957
|
+
return;
|
|
21958
|
+
}
|
|
21959
|
+
setStatus((current) => current === null ? current : {
|
|
21960
|
+
...current,
|
|
21961
|
+
anonymousCount: body.enabled ?? next
|
|
21962
|
+
});
|
|
21963
|
+
} catch (cause) {
|
|
21964
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
21965
|
+
}
|
|
21966
|
+
})();
|
|
21967
|
+
}, [post, t]);
|
|
21932
21968
|
/** Save or clear the single user-facing GitHub escape route. */
|
|
21933
21969
|
const onGithubProxy = (0, react.useCallback)((proxy) => {
|
|
21934
21970
|
setError(null);
|
|
@@ -22072,7 +22108,7 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
22072
22108
|
const offeredVersion = update?.eligibleVersion ?? update?.latest ?? null;
|
|
22073
22109
|
const held = update?.heldUpdate;
|
|
22074
22110
|
const heldVersionText = held != null && typeof held.latest === "string" && held.latest !== "" && (update?.updateAvailable !== true || held.latest !== offeredVersion) ? marketHeldVersionText(held, activeLocale, t) : null;
|
|
22075
|
-
const body = phase === "removed" ? row(t("setSelfRemoved"), t("setSelfRemovedHint"), null) : (0, react.createElement)(react.Fragment, null, advanced, row(t("setIndexSource"), t("setIndexSourceHint"), null), status?.selfManaged === true ? row((update?.updateAvailable === true || update?.hostManaged === true) && offeredVersion !== null ? `${t("setSelfUpdateReady")} ${offeredVersion}` : update?.channelSwitch != null ? `${t("setChannelSwitch")} ${update.channelSwitch}` : checkFailed ? t("updateChecksFailed") : pluginListChanged ? t("updateChecksChanged") : update?.profileBlocked != null || heldVersionText !== null ? t("setSelfUpdateWaiting") : update === null ? t("updateChecksPending") : t("setSelfUpToDate"), phase === "updated" ? t("setSelfUpdatedHint") : update?.channelSwitch != null ? t("setChannelSwitchHint") : update?.updateAvailable === true ? [t("setSelfUpdateHint"), heldVersionText].filter(Boolean).join(" · ") : update?.hostManaged === true && update.latest !== null ? t("setSelfHostManagedHint") : checkFailed ? t("updateChecksFailedHint") : pluginListChanged ? t("
|
|
22111
|
+
const body = phase === "removed" ? row(t("setSelfRemoved"), t("setSelfRemovedHint"), null) : (0, react.createElement)(react.Fragment, null, advanced, row(t("setIndexSource"), t("setIndexSourceHint"), null), status?.selfManaged === true ? row((update?.updateAvailable === true || update?.hostManaged === true) && offeredVersion !== null ? `${t("setSelfUpdateReady")} ${offeredVersion}` : update?.channelSwitch != null ? `${t("setChannelSwitch")} ${update.channelSwitch}` : checkFailed ? t("updateChecksFailed") : pluginListChanged ? t("updateChecksChanged") : update?.profileBlocked != null || heldVersionText !== null ? t("setSelfUpdateWaiting") : update === null ? t("updateChecksPending") : t("setSelfUpToDate"), phase === "updated" ? t("setSelfUpdatedHint") : update?.channelSwitch != null ? t("setChannelSwitchHint") : update?.updateAvailable === true ? [t("setSelfUpdateHint"), heldVersionText].filter(Boolean).join(" · ") : update?.hostManaged === true && update.latest !== null ? t("setSelfHostManagedHint") : checkFailed ? t("updateChecksFailedHint") : pluginListChanged ? t("setSelfChangedHint") : update?.profileBlocked != null ? profileBlockedText(update.profileBlocked, t) : heldVersionText ?? t("setSelfUpToDateHint"), phase === "updated" ? null : update?.updateAvailable === true ? (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
22076
22112
|
variant: "primary",
|
|
22077
22113
|
size: "sm",
|
|
22078
22114
|
disabled: busy,
|
|
@@ -22112,7 +22148,16 @@ window.__ModuleLoader__.load({ id: "dshmarket", factory: (require) => {
|
|
|
22112
22148
|
onClick: () => {
|
|
22113
22149
|
onRegion(id);
|
|
22114
22150
|
}
|
|
22115
|
-
}, t(REGION_LABEL[id]))))),
|
|
22151
|
+
}, t(REGION_LABEL[id]))))), status?.anonymousCount !== null && status?.anonymousCount !== void 0 ? row(t("setCount"), t("setCountHint"), (0, react.createElement)("div", { className: Market_module_css_default.setSeg }, [true, false].map((value) => (0, react.createElement)("button", {
|
|
22152
|
+
key: String(value),
|
|
22153
|
+
type: "button",
|
|
22154
|
+
className: status.anonymousCount === value ? `${Market_module_css_default.setSegBtn} ${Market_module_css_default.setSegOn}` : Market_module_css_default.setSegBtn,
|
|
22155
|
+
disabled: busy,
|
|
22156
|
+
"aria-pressed": status.anonymousCount === value,
|
|
22157
|
+
onClick: () => {
|
|
22158
|
+
if (status.anonymousCount !== value) onCount(value);
|
|
22159
|
+
}
|
|
22160
|
+
}, t(value ? "setCountOn" : "setCountOff"))))) : null, row(t("setGithubProxy"), status?.githubProxyManaged === true ? t("setGithubProxyManagedHint") : status?.githubProxyCustom !== null && status?.githubProxyCustom !== void 0 ? t("setGithubProxyCustomHint") : t("setGithubProxyAutoHint"), status?.githubProxyManaged === true ? null : status?.githubProxyCustom !== null && status?.githubProxyCustom !== void 0 ? (0, react.createElement)("div", { className: Market_module_css_default.setInlineActions }, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
22116
22161
|
variant: "outline",
|
|
22117
22162
|
size: "sm",
|
|
22118
22163
|
disabled: proxySaving,
|
package/lib/routes.js
CHANGED
|
@@ -58,6 +58,7 @@ import { DEFAULT_UPDATE_CHECK_INTERVAL_HOURS, isUpdateCheckIntervalHours } from
|
|
|
58
58
|
import { createThemeManager } from './themes.js';
|
|
59
59
|
import { readJsonBody, refuseUnadmitted, sameOrigin, sendJson } from './http.js';
|
|
60
60
|
import { resolveDshHome } from './home-paths.js';
|
|
61
|
+
import { readTelemetryState, setTelemetryEnabled, startHeartbeat } from './telemetry.js';
|
|
61
62
|
import { clearWebdavSecret, readWebdavSecret, webdavSecretFor, writeWebdavSecret } from './webdav-secret.js';
|
|
62
63
|
import { detectedDebugger, detectedSupervisor, restartAllowed, scheduleRestart, servingPort, trustedRestartRequest, trustedDownloadRequest, trustedSelfUninstallRequest, selfUninstallReachableFrom, restartReachableFrom } from './restart.js';
|
|
63
64
|
import { activationAfterReplace, brokenClientBundles, bundlePatchIsEmpty, checkClientBundle, defaultHostRuntimeFacts, findUnservedConfigNamespaces, hasHostHalf, hostPeerGate, isDeclaredLibraryDsh, newlyBrokenBundles, peerGateRemedy, verifyActivation } from './verify.js';
|
|
@@ -3128,6 +3129,37 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
|
|
|
3128
3129
|
});
|
|
3129
3130
|
};
|
|
3130
3131
|
const disposers = [
|
|
3132
|
+
registerRoute({
|
|
3133
|
+
kind: 'exact',
|
|
3134
|
+
path: '/dsh-market/telemetry',
|
|
3135
|
+
handler: async (request, response) => {
|
|
3136
|
+
if (request.method === 'GET') {
|
|
3137
|
+
sendJson(response, 200, { enabled: readTelemetryState().enabled });
|
|
3138
|
+
return;
|
|
3139
|
+
}
|
|
3140
|
+
if (request.method !== 'POST') {
|
|
3141
|
+
response.writeHead(405, { allow: 'GET, POST' });
|
|
3142
|
+
response.end();
|
|
3143
|
+
return;
|
|
3144
|
+
}
|
|
3145
|
+
if (!sameOrigin(request)) {
|
|
3146
|
+
sendJson(response, 403, { error: 'untrusted origin' });
|
|
3147
|
+
return;
|
|
3148
|
+
}
|
|
3149
|
+
try {
|
|
3150
|
+
const body = await readJsonBody(request);
|
|
3151
|
+
if (body === null || typeof body !== 'object' || typeof body.enabled !== 'boolean') {
|
|
3152
|
+
sendJson(response, 400, { error: 'enabled must be a boolean' });
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
setTelemetryEnabled(body.enabled);
|
|
3156
|
+
sendJson(response, 200, { ok: true, enabled: body.enabled });
|
|
3157
|
+
}
|
|
3158
|
+
catch {
|
|
3159
|
+
sendJson(response, 400, { error: '没能保存这个设置,请再试一次。 / Could not save this setting. Try again.' });
|
|
3160
|
+
}
|
|
3161
|
+
},
|
|
3162
|
+
}),
|
|
3131
3163
|
registerRoute({
|
|
3132
3164
|
kind: 'exact',
|
|
3133
3165
|
path: '/dsh-market/update-notifications',
|
|
@@ -5174,6 +5206,7 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
|
|
|
5174
5206
|
channels: CHANNELS,
|
|
5175
5207
|
region,
|
|
5176
5208
|
regions: REGIONS,
|
|
5209
|
+
anonymousCount: readTelemetryState().enabled,
|
|
5177
5210
|
// The padded/PATH- and CI-safe build environment currently pinned
|
|
5178
5211
|
// (issue #336): composition plus any card-saved override. The card
|
|
5179
5212
|
// edits exactly what this reports, so the form never shows a stale
|
|
@@ -9012,8 +9045,15 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
|
|
|
9012
9045
|
})),
|
|
9013
9046
|
];
|
|
9014
9047
|
startCheckoutRepair();
|
|
9048
|
+
const stopHeartbeat = startHeartbeat({
|
|
9049
|
+
version: marketVersion(),
|
|
9050
|
+
hostVersion: () => dshHostInfo()?.version ?? null,
|
|
9051
|
+
kind: () => (config.desktopHost === true ? 'desktop' : 'web'),
|
|
9052
|
+
region: () => region,
|
|
9053
|
+
});
|
|
9015
9054
|
return async () => {
|
|
9016
9055
|
disposed = true;
|
|
9056
|
+
stopHeartbeat();
|
|
9017
9057
|
checkoutRepairRound = undefined;
|
|
9018
9058
|
if (checkoutRepairTimer !== undefined)
|
|
9019
9059
|
clearTimeout(checkoutRepairTimer);
|
package/lib/telemetry.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { resolveDshHome } from './home-paths.js';
|
|
5
|
+
import { logEvent } from './log.js';
|
|
6
|
+
import { marketFetch } from './net.js';
|
|
7
|
+
/**
|
|
8
|
+
* The anonymous daily count.
|
|
9
|
+
*
|
|
10
|
+
* One POST per install per UTC day, from the Node side only, carrying exactly
|
|
11
|
+
* five fields (see `Ping`). It is on by default and off with one switch in
|
|
12
|
+
* the settings card or with an environment variable. Everything about it is
|
|
13
|
+
* best effort: a failure changes nothing for the user and is never an error.
|
|
14
|
+
*/
|
|
15
|
+
export const TELEMETRY_URL = 'https://t.dshmarket.com/v1/ping';
|
|
16
|
+
const TIMEOUT_MS = 10_000;
|
|
17
|
+
const START_DELAY_MS = 30_000;
|
|
18
|
+
const RECHECK_MS = 6 * 60 * 60 * 1000;
|
|
19
|
+
export function telemetryFile(home = resolveDshHome()) {
|
|
20
|
+
return join(home, 'dsh-market', 'telemetry.json');
|
|
21
|
+
}
|
|
22
|
+
export function readTelemetryState(file = telemetryFile()) {
|
|
23
|
+
try {
|
|
24
|
+
const value = JSON.parse(readFileSync(file, 'utf8'));
|
|
25
|
+
return {
|
|
26
|
+
...(typeof value.id === 'string' && /^[0-9a-f]{32}$/.test(value.id) ? { id: value.id } : {}),
|
|
27
|
+
...(typeof value.lastDay === 'string' ? { lastDay: value.lastDay } : {}),
|
|
28
|
+
enabled: value.enabled !== false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { enabled: true };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function writeState(state, file) {
|
|
36
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
37
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
38
|
+
writeFileSync(temp, JSON.stringify(state));
|
|
39
|
+
renameSync(temp, file);
|
|
40
|
+
}
|
|
41
|
+
/** Turn the count on or off. Keeps the rest of the file; deletes nothing else. */
|
|
42
|
+
export function setTelemetryEnabled(enabled, file = telemetryFile()) {
|
|
43
|
+
writeState({ ...readTelemetryState(file), enabled }, file);
|
|
44
|
+
}
|
|
45
|
+
const utcDay = (now) => new Date(now).toISOString().slice(0, 10);
|
|
46
|
+
/** Why nothing may be sent right now, or null. Explicit opt-outs always win. */
|
|
47
|
+
export function suppressedBy(env) {
|
|
48
|
+
if (env.DSH_MARKET_TELEMETRY === '0')
|
|
49
|
+
return 'DSH_MARKET_TELEMETRY=0';
|
|
50
|
+
if (env.DO_NOT_TRACK === '1')
|
|
51
|
+
return 'DO_NOT_TRACK=1';
|
|
52
|
+
// Tests and CI never count, unless a test points the URL at its own server.
|
|
53
|
+
const overridden = (env.DSH_MARKET_TELEMETRY_URL ?? '') !== '';
|
|
54
|
+
if (!overridden && env.CI !== undefined && env.CI !== '' && env.CI !== '0' && env.CI !== 'false')
|
|
55
|
+
return 'CI';
|
|
56
|
+
if (!overridden && (env.VITEST !== undefined || env.NODE_ENV === 'test'))
|
|
57
|
+
return 'test run';
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/** Send today's count if it is due. Never throws. */
|
|
61
|
+
export async function sendHeartbeat(options) {
|
|
62
|
+
try {
|
|
63
|
+
const env = options.env ?? process.env;
|
|
64
|
+
const file = options.file ?? telemetryFile();
|
|
65
|
+
if (suppressedBy(env) !== null)
|
|
66
|
+
return 'skipped';
|
|
67
|
+
const state = readTelemetryState(file);
|
|
68
|
+
if (!state.enabled)
|
|
69
|
+
return 'skipped';
|
|
70
|
+
const day = utcDay((options.now ?? Date.now)());
|
|
71
|
+
if (state.lastDay === day)
|
|
72
|
+
return 'skipped';
|
|
73
|
+
const id = state.id ?? randomBytes(16).toString('hex');
|
|
74
|
+
const ping = { id, v: options.version, hv: options.hostVersion(), kind: options.kind(), region: options.region() };
|
|
75
|
+
const response = await (options.fetch ?? marketFetch)(env.DSH_MARKET_TELEMETRY_URL || TELEMETRY_URL, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
headers: { 'content-type': 'application/json' },
|
|
78
|
+
body: JSON.stringify(ping),
|
|
79
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
80
|
+
});
|
|
81
|
+
if (response.status < 200 || response.status > 299)
|
|
82
|
+
return 'failed';
|
|
83
|
+
// Re-read: the user may have turned it off while the request was in flight.
|
|
84
|
+
writeState({ ...readTelemetryState(file), id, lastDay: day }, file);
|
|
85
|
+
return 'sent';
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
logEvent('info', 'telemetry', `not sent: ${error instanceof Error ? error.message : 'unknown'}`);
|
|
89
|
+
return 'failed';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Start the schedule: first check after a short delay, then every ~6 hours. */
|
|
93
|
+
export function startHeartbeat(options, delayMs = START_DELAY_MS, everyMs = RECHECK_MS) {
|
|
94
|
+
let stopped = false;
|
|
95
|
+
let timer;
|
|
96
|
+
const tick = () => {
|
|
97
|
+
if (stopped)
|
|
98
|
+
return;
|
|
99
|
+
void sendHeartbeat(options).finally(() => {
|
|
100
|
+
if (stopped)
|
|
101
|
+
return;
|
|
102
|
+
timer = setTimeout(tick, everyMs);
|
|
103
|
+
timer.unref?.();
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
timer = setTimeout(tick, delayMs);
|
|
107
|
+
timer.unref?.();
|
|
108
|
+
return () => { stopped = true; if (timer !== undefined)
|
|
109
|
+
clearTimeout(timer); };
|
|
110
|
+
}
|
package/lib/types/net.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export declare function configuredProxy(): string | null;
|
|
|
89
89
|
export declare function marketFetch(url: string, init?: {
|
|
90
90
|
signal?: AbortSignal;
|
|
91
91
|
headers?: Record<string, string>;
|
|
92
|
-
method?: 'GET' | 'HEAD';
|
|
92
|
+
method?: 'GET' | 'HEAD' | 'POST';
|
|
93
|
+
body?: string;
|
|
93
94
|
redirect?: 'follow' | 'manual';
|
|
94
95
|
}): Promise<Response>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { marketFetch } from './net.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The anonymous daily count.
|
|
4
|
+
*
|
|
5
|
+
* One POST per install per UTC day, from the Node side only, carrying exactly
|
|
6
|
+
* five fields (see `Ping`). It is on by default and off with one switch in
|
|
7
|
+
* the settings card or with an environment variable. Everything about it is
|
|
8
|
+
* best effort: a failure changes nothing for the user and is never an error.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TELEMETRY_URL = "https://t.dshmarket.com/v1/ping";
|
|
11
|
+
/** The whole payload. Adding a field here is a privacy change: update SECURITY.md. */
|
|
12
|
+
export interface Ping {
|
|
13
|
+
id: string;
|
|
14
|
+
v: string;
|
|
15
|
+
hv: string | null;
|
|
16
|
+
kind: 'desktop' | 'web';
|
|
17
|
+
region: string;
|
|
18
|
+
}
|
|
19
|
+
interface TelemetryState {
|
|
20
|
+
id?: string;
|
|
21
|
+
lastDay?: string;
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function telemetryFile(home?: string): string;
|
|
25
|
+
export declare function readTelemetryState(file?: string): TelemetryState;
|
|
26
|
+
/** Turn the count on or off. Keeps the rest of the file; deletes nothing else. */
|
|
27
|
+
export declare function setTelemetryEnabled(enabled: boolean, file?: string): void;
|
|
28
|
+
/** Why nothing may be sent right now, or null. Explicit opt-outs always win. */
|
|
29
|
+
export declare function suppressedBy(env: Record<string, string | undefined>): string | null;
|
|
30
|
+
export interface HeartbeatOptions {
|
|
31
|
+
version: string;
|
|
32
|
+
hostVersion: () => string | null;
|
|
33
|
+
kind: () => 'desktop' | 'web';
|
|
34
|
+
region: () => string;
|
|
35
|
+
file?: string;
|
|
36
|
+
env?: Record<string, string | undefined>;
|
|
37
|
+
now?: () => number;
|
|
38
|
+
fetch?: typeof marketFetch;
|
|
39
|
+
}
|
|
40
|
+
/** Send today's count if it is due. Never throws. */
|
|
41
|
+
export declare function sendHeartbeat(options: HeartbeatOptions): Promise<'sent' | 'skipped' | 'failed'>;
|
|
42
|
+
/** Start the schedule: first check after a short delay, then every ~6 hours. */
|
|
43
|
+
export declare function startHeartbeat(options: HeartbeatOptions, delayMs?: number, everyMs?: number): () => void;
|
|
44
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dshmarket",
|
|
3
3
|
"description": "Visual plugin market inside DeepSeek Harness — browse, search, and one-click install community plugins. · DSH 可视化插件市场:逛一逛,点一下,装好。",
|
|
4
|
-
"version": "1.73.
|
|
4
|
+
"version": "1.73.24",
|
|
5
5
|
"icon": "assets/logo.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|