@bokutake/dsh-connect-qoder 0.0.0-stage → 1.28.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.
@@ -0,0 +1,171 @@
1
+ import { I as QODER_REGION_TRANSFER_DOMAIN, _ as qoderAccountId } from "./host-heartbeat-Daj8rZV0.js";
2
+ //#region src/transfer.ts
3
+ /**
4
+ * Account transfer: the export / import file format shared with sibling
5
+ * credential managers for the same upstream.
6
+ *
7
+ * 参考:dsh-connect-workbuddy(MIT,Copyright (c) 2026 LaoDing)的
8
+ * `src/transfer.ts` —— 传输文件格式(JSON 数组、snake_case 字段、去重、
9
+ * 预览不回明文、解析不依赖文件系统、区域门放在纯函数里以便无 UI 单测)
10
+ * 的形态整体沿用;工作清单上又是家族内各 DSH 插件的既有互操作约定。
11
+ * 改动(按 Qoder 上游的实际能力):
12
+ * 1. 凭据是 PAT,不是桌面端登录文件——记录只承载 `access_token`(即
13
+ * PAT)、`uid`(PAT 派生的账号 id)、`nickname`、`email`、`domain`,
14
+ * 没有 refresh_token / expiresAt 一族字段(PAT 一般无过期);
15
+ * 2. domain 只取两个上游区域值——`qoder.com.cn`(cn)/ `qoder.sh`
16
+ * (global)——区域门用白名单正匹配:值不属于目标区域的记录一律跳过,
17
+ * 不做「当作哪个区域都行」的默认,避免跨区导入交叉计费或收进伪装域;
18
+ * 3. 账号 id 由 PAT 单向散列派生(`credentials.ts` 的 `qoderAccountId`),
19
+ * 合并按 id 去重、以同 id 覆盖;import 落库由 Host 侧的
20
+ * `QoderAccountStore.add(pat, accountName)` 完成,`nickname` → accountName。
21
+ *
22
+ * @module dsh-connect-qoder/transfer
23
+ */
24
+ /**
25
+ * Parse transfer-file text: a JSON array, every element an object.
26
+ *
27
+ * The error strings carry the position (1-based item number) because a file
28
+ * from another tool can be big, and "第 N 项" is what lets the user find the
29
+ * broken record in their editor.
30
+ */
31
+ function parseTransferFile(text) {
32
+ if (text.trim() === "") throw new Error("transfer file is empty");
33
+ let parsed;
34
+ try {
35
+ parsed = JSON.parse(text);
36
+ } catch (error) {
37
+ throw new Error("transfer file is not valid JSON: " + (error instanceof Error ? error.message : String(error)));
38
+ }
39
+ if (!Array.isArray(parsed)) throw new Error("transfer file must be a JSON array of account records");
40
+ for (const [index, item] of parsed.entries()) if (typeof item !== "object" || item === null || Array.isArray(item)) throw new Error("transfer file item " + (index + 1) + " is not an account object");
41
+ return parsed;
42
+ }
43
+ /** One string field of a record, tolerating the sibling format's odd shapes. */
44
+ function displayString(value) {
45
+ if (typeof value === "string") return value;
46
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
47
+ return "";
48
+ }
49
+ /** Whether a record carries a usable token, envelope-shaped or plain. */
50
+ function hasToken(record) {
51
+ const token = record["access_token"];
52
+ return typeof token === "string" && token !== "";
53
+ }
54
+ /**
55
+ * The transfer file's desensitized preview: display fields only.
56
+ *
57
+ * Fields come from EXTERNAL files, so a display field may hold an object or an
58
+ * array (a sibling tool can store the desktop app's encrypted-wrapper nickname
59
+ * verbatim); every preview field is normalized to a string or emptied rather
60
+ * than letting a non-renderable value reach the card.
61
+ */
62
+ function previewTransferFile(text) {
63
+ const records = parseTransferFile(text);
64
+ return {
65
+ accounts: records.map((record, index) => ({
66
+ index,
67
+ uid: displayString(record["uid"]),
68
+ nickname: displayString(record["nickname"]),
69
+ email: displayString(record["email"]),
70
+ hasToken: hasToken(record)
71
+ })),
72
+ total: records.length
73
+ };
74
+ }
75
+ /**
76
+ * Project one stored vault account into the shared transfer record shape.
77
+ *
78
+ * `regionDomain` is the target region's login domain (`qoder.com.cn` for cn,
79
+ * `qoder.sh` for global); the export caller passes it so the imported file
80
+ * self-describes which region each record belongs to. `uid` is the PAT-derived
81
+ * account id so a re-import converges on the SAME vault key. `nickname` is
82
+ * dropped — never set to empty/undefined — when the account has no name, and
83
+ * `access_token` carries the PAT itself.
84
+ */
85
+ function transferRecordOf(account, regionDomain) {
86
+ return {
87
+ access_token: account.pat,
88
+ uid: account.id,
89
+ ...account.accountName !== "" ? { nickname: account.accountName } : {},
90
+ domain: regionDomain
91
+ };
92
+ }
93
+ /**
94
+ * Project a region's whole vault into the exported transfer document.
95
+ *
96
+ * This is the ONE place the export path turns vault accounts into records;
97
+ * the `exportAccounts` dep (`index.ts`) MUST go through it. It used to be
98
+ * written inline in `exportAccounts` as a raw `{pat, accountName, id}` map,
99
+ * which is what produced files that could never be re-imported: the region
100
+ * gate (`mergeTransferRecords`) reads `domain`, and the raw vault shape has
101
+ * none. Keeping the projection here — rather than in the Host wiring — is what
102
+ * lets a test export through it and immediately import the result.
103
+ */
104
+ function transferRecordsFor(region, accounts) {
105
+ const domain = QODER_REGION_TRANSFER_DOMAIN[region];
106
+ return accounts.map((account) => transferRecordOf(account, domain));
107
+ }
108
+ /**
109
+ * Positive-match a record's login domain to a region.
110
+ *
111
+ * Distinct from any upstream-side registry: `domain` is whatever the FILE'S
112
+ * author wrote, so only an exactly-known Qoder domain counts. `qoder.com.cn`
113
+ * and `qoder.sh` are the plugin's two per-region domains; an empty, misspelled,
114
+ * spoofed, or registrable-domain-lookalike value classifies as undecidable and
115
+ * is refused rather than being filed under either region.
116
+ */
117
+ function knownRegionOfDomain(domain) {
118
+ if (domain === "qoder.com.cn") return "cn";
119
+ if (domain === "qoder.sh") return "global";
120
+ }
121
+ /**
122
+ * Pure merge: fold the selected records of a transfer file into a CHANGES map.
123
+ *
124
+ * Mirrors the sibling merger's contract: a record with the same account id
125
+ * OVERWRITES the stored entry (the imported PAT replaces what is stored —
126
+ * re-importing a rotated PAT must refresh it; the write layer stores the record
127
+ * atomically, so "overwrite" needs no knowledge of the incumbent), and a
128
+ * record without a token is skipped. The region gate lives HERE rather than in
129
+ * the route so it is testable without a Host: a record whose login domain maps
130
+ * to the other region's tab is skipped, because the two regions' providers are
131
+ * parallel stacks and a cross-region import would cross-bill.
132
+ *
133
+ * The caller persists each map entry via `QoderAccountStore.add`; an importing
134
+ * selection that is already stored rewrites those entries with identical
135
+ * content — idempotent, and the steady state of importing the same file twice.
136
+ */
137
+ function mergeTransferRecords(region, text, indexes) {
138
+ const records = parseTransferFile(text);
139
+ const changes = /* @__PURE__ */ new Map();
140
+ let imported = 0;
141
+ let skipped = 0;
142
+ for (const index of indexes) {
143
+ const record = records[index];
144
+ if (record === void 0) {
145
+ skipped += 1;
146
+ continue;
147
+ }
148
+ const accessToken = record["access_token"];
149
+ if (typeof accessToken !== "string" || accessToken === "") {
150
+ skipped += 1;
151
+ continue;
152
+ }
153
+ if (knownRegionOfDomain(record["domain"]) !== region) {
154
+ skipped += 1;
155
+ continue;
156
+ }
157
+ const id = qoderAccountId(accessToken);
158
+ changes.set(id, {
159
+ pat: accessToken,
160
+ accountName: displayString(record["nickname"])
161
+ });
162
+ imported += 1;
163
+ }
164
+ return {
165
+ changes,
166
+ imported,
167
+ skipped
168
+ };
169
+ }
170
+ //#endregion
171
+ export { mergeTransferRecords, previewTransferFile, transferRecordsFor };
package/package.json CHANGED
@@ -1,6 +1,153 @@
1
1
  {
2
2
  "name": "@bokutake/dsh-connect-qoder",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "displayName": "DSH Connect Qoder",
4
+ "description": "把 Qoder(通义灵码国内版 / 国际版)接入 DeepSeek Harness:PAT 多账号池、每日签到、积分读数与模型管理。(dingminhua/dsh-connect-qoder 的独立维护分叉)",
5
+ "version": "1.28.0",
6
+ "author": "bokutake <i@html.moe>",
7
+ "contributors": [
8
+ "dingminhua (upstream author, https://github.com/dingminhua/dsh-connect-qoder)"
9
+ ],
10
+ "copyright": "Copyright (c) 2026 LaoDing (upstream); modifications Copyright (c) 2026 bokutake",
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "dsh-plugin",
14
+ "deepseek-harness",
15
+ "qoder",
16
+ "lingma",
17
+ "model-provider",
18
+ "credits",
19
+ "account-pool",
20
+ "check-in"
21
+ ],
22
+ "type": "module",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "engines": {
27
+ "node": "^22.19.0 || >=24.0.0"
28
+ },
29
+ "main": "lib/index.js",
30
+ "types": "lib/index.d.ts",
31
+ "bin": {
32
+ "dsh-connect-qoder": "lib/bin.js"
33
+ },
34
+ "icon": "icons/dsh-connect-qoder-128.png",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./lib/index.d.ts",
38
+ "default": "./lib/index.js"
39
+ },
40
+ "./client": "./lib/client.js",
41
+ "./cordis.patch.yml": "./cordis.patch.yml",
42
+ "./package.json": "./package.json"
43
+ },
44
+ "dependencies": {
45
+ "@deepseek-ai/schemastery": "3.18.4"
46
+ },
47
+ "files": [
48
+ "lib",
49
+ "icons",
50
+ "docs/assets",
51
+ "docs/PAT.md",
52
+ "docs/PRIVACY.md",
53
+ "docs/DESIGN.md",
54
+ "docs/PROMO_BADGE.md",
55
+ "screenshots.json",
56
+ "cordis.patch.yml",
57
+ "README.md",
58
+ "README.en.md",
59
+ "CHANGELOG.md",
60
+ "THIRD_PARTY_NOTICES.md",
61
+ "LICENSE",
62
+ "LICENSE-MODIFICATIONS.md",
63
+ "docs/DSH-0.2.1-RC1-FOLLOWUP.md",
64
+ "docs/DSH-0.2.2-RC1-FOLLOWUP.md",
65
+ "docs/DSH-0.2.2-RC2-FOLLOWUP.md",
66
+ "docs/DSH-0.2.2-RC3-FOLLOWUP.md",
67
+ "docs/DSH-0.2.2-RC5-FOLLOWUP.md",
68
+ "docs/issues/magpie-330-billing-count.md"
69
+ ],
70
+ "scripts": {
71
+ "prepack": "npm run build",
72
+ "build": "tsdown",
73
+ "test": "vitest run",
74
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.client.json",
75
+ "check": "pnpm run typecheck && pnpm run test && pnpm run build",
76
+ "probe:cosy": "node scripts/probe-cosy.mjs",
77
+ "probe:vault": "node scripts/dump-vault.mjs",
78
+ "probe:cache": "node scripts/probe-cache-usage.mjs",
79
+ "fixture:host-classifier": "node scripts/extract-host-classifier.mjs",
80
+ "fixture:pi-ai-modern": "npm install --prefix tests/fixtures/pi-ai-modern --no-audit --no-fund",
81
+ "preview:client": "vitest run --config scripts/vitest.preview.config.ts"
82
+ },
83
+ "dsh": {
84
+ "bundle": {
85
+ "patch": "./cordis.patch.yml"
86
+ },
87
+ "client": {
88
+ "inject": [
89
+ "@deepseek-ai/dsh-client-ui-settings",
90
+ "@deepseek-ai/dsh-client-ui-slots",
91
+ "@deepseek-ai/dsh-client-ui-settings-plugins",
92
+ "@deepseek-ai/dsh-client-locale"
93
+ ],
94
+ "platform": "web"
95
+ }
96
+ },
97
+ "repository": {
98
+ "type": "git",
99
+ "url": "git+https://github.com/bokutake/dsh-connect-qoder.git"
100
+ },
101
+ "homepage": "https://github.com/bokutake/dsh-connect-qoder#readme",
102
+ "bugs": {
103
+ "url": "https://github.com/bokutake/dsh-connect-qoder/issues"
104
+ },
105
+ "peerDependencies": {
106
+ "@deepseek-ai/cordis": ">=4.0.1-rc.1 <5.0.0 || >=4.0.2 <5.0.0",
107
+ "@deepseek-ai/dsh-atomic-write": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
108
+ "@deepseek-ai/dsh-attachment": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
109
+ "@deepseek-ai/dsh-client-locale": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
110
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
111
+ "@deepseek-ai/dsh-client-ui-renderer": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
112
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
113
+ "@deepseek-ai/dsh-client-ui-settings-plugins": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
114
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
115
+ "@deepseek-ai/dsh-home-paths": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
116
+ "@deepseek-ai/dsh-host-webserver": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
117
+ "@deepseek-ai/dsh-llm": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
118
+ "@deepseek-ai/dsh-llm-pi-ai": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
119
+ "@deepseek-ai/dsh-settings": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
120
+ "@deepseek-ai/schemastery": ">=3.18.1-rc.1 <4.0.0 || >=3.18.2 <4.0.0",
121
+ "@earendil-works/pi-ai": ">=0.85.0 <0.88.0 || >=1.0.0 <2.0.0",
122
+ "react": "^18.2.0"
123
+ },
124
+ "devDependencies": {
125
+ "@deepseek-ai/cordis": ">=4.0.1 <5.0.0 || >=4.0.2 <5.0.0",
126
+ "@deepseek-ai/dsh-atomic-write": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
127
+ "@deepseek-ai/dsh-attachment": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
128
+ "@deepseek-ai/dsh-client-locale": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
129
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
130
+ "@deepseek-ai/dsh-client-ui-renderer": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
131
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
132
+ "@deepseek-ai/dsh-client-ui-settings-plugins": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
133
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
134
+ "@deepseek-ai/dsh-home-paths": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
135
+ "@deepseek-ai/dsh-host-webserver": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
136
+ "@deepseek-ai/dsh-llm": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
137
+ "@deepseek-ai/dsh-llm-pi-ai": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
138
+ "@deepseek-ai/dsh-settings": ">=0.1.7-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-rc.1 <0.3.0-0 || >=0.2.2-rc.1 <0.3.0-0",
139
+ "@deepseek-ai/schemastery": ">=3.18.1 <4.0.0 || >=3.18.2 <4.0.0",
140
+ "@earendil-works/pi-ai": ">=0.85.0 <0.88.0 || >=1.0.0 <2.0.0",
141
+ "@types/node": "^22.20.0",
142
+ "@types/react": "~18.3.31",
143
+ "@types/react-dom": "18.3.7",
144
+ "@types/semver": "^7.8.0",
145
+ "jsdom": "^29.1.1",
146
+ "react": "^18.3.1",
147
+ "react-dom": "18.3.1",
148
+ "semver": "^7.8.5",
149
+ "tsdown": "^0.22.2",
150
+ "typescript": "^5.9.3",
151
+ "vitest": "^4.1.8"
152
+ }
153
+ }
@@ -0,0 +1,8 @@
1
+ [
2
+ "docs/assets/dsh-connect-qoder-settings-page.png",
3
+ "docs/assets/dsh-connect-qoder-usage-card.png",
4
+ "docs/assets/dsh-connect-qoder-model-management.png",
5
+ "docs/assets/dsh-connect-qoder-promo-badge.png",
6
+ "docs/assets/dsh-connect-qoder-composer-credits.png",
7
+ "docs/assets/dsh-connect-qoder-model-picker.png"
8
+ ]