dsh-codearts-dock 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/DISCLAIMER.md +47 -0
  2. package/LICENSE +21 -0
  3. package/README.md +172 -2
  4. package/SECURITY.md +47 -0
  5. package/THIRD_PARTY_NOTICES.md +64 -0
  6. package/client.js +3519 -0
  7. package/cordis.patch.yml +10 -0
  8. package/docs/DETAIL.md +25 -0
  9. package/docs/DETAIL.zh.md +25 -0
  10. package/docs/PUBLISHING.md +43 -0
  11. package/docs/preview.svg +78 -0
  12. package/icons/dsh-connect-codearts-128.png +0 -0
  13. package/icons/dsh-connect-codearts-256.png +0 -0
  14. package/locale/en.json +7 -0
  15. package/locale/zh.json +7 -0
  16. package/package.json +88 -4
  17. package/scripts/build-market-index.mjs +24 -0
  18. package/scripts/check-legal.sh +33 -0
  19. package/scripts/check-release.mjs +29 -0
  20. package/scripts/test.mjs +11 -0
  21. package/src/account.js +217 -0
  22. package/src/accounts.js +481 -0
  23. package/src/adapter.js +742 -0
  24. package/src/backup.js +89 -0
  25. package/src/catalog.js +269 -0
  26. package/src/checkin.js +271 -0
  27. package/src/credentials.js +435 -0
  28. package/src/features.js +79 -0
  29. package/src/gateway.js +521 -0
  30. package/src/health.js +18 -0
  31. package/src/index.js +1108 -0
  32. package/src/models.js +147 -0
  33. package/src/paths.js +36 -0
  34. package/src/preferences.js +90 -0
  35. package/src/protocol/crypto.js +160 -0
  36. package/src/protocol/sign.js +176 -0
  37. package/src/protocol/sm4.js +264 -0
  38. package/src/protocol/sse.js +134 -0
  39. package/src/sts.js +118 -0
  40. package/src/usage.js +55 -0
  41. package/test/accounts.test.mjs +322 -0
  42. package/test/adapter.test.mjs +234 -0
  43. package/test/assembler.test.mjs +86 -0
  44. package/test/features.test.mjs +257 -0
  45. package/test/live-probe.mjs +55 -0
  46. package/test/protocol.test.mjs +167 -0
  47. package/test/registration.test.mjs +301 -0
  48. package/test/sm4.test.mjs +64 -0
  49. package/test/ui.test.mjs +370 -0
  50. package/test/visual.test.mjs +438 -0
@@ -0,0 +1,10 @@
1
+ # Register the 码道 provider as a bundle row. The provider route itself is
2
+ # registered by the plugin at activation, so no profile-level model list is
3
+ # written here: the catalog is whatever the gateway advertised at the last
4
+ # refresh, and a model selection therefore never needs a restart.
5
+ - insert:
6
+ - id: dsh-connect-codearts
7
+ name: dsh-codearts-dock
8
+ config:
9
+ enabled: true
10
+ composerChip: true
package/docs/DETAIL.md ADDED
@@ -0,0 +1,25 @@
1
+ # CodeArts Dock
2
+
3
+ Connect Huawei Cloud CodeArts models to DeepSeek Harness and manage accounts, credits and model preferences.
4
+
5
+ An unofficial third-party plugin, unaffiliated with Huawei and DeepSeek / Harness operators. You need your own authorized account. Model requests may consume credits or incur charges.
6
+
7
+ ## Features
8
+
9
+ - Native adapter for streaming text, reasoning, tool calls and model-supported image input.
10
+ - Multiple accounts, import/export, manual switching and actionable health checks.
11
+ - Composer credit chip, configurable low-balance alerts and backup account overview.
12
+ - Model search, capability filters, multiplier sorting, drafts and configuration presets.
13
+ - Up to 200 local request metadata records, with recording and clear controls.
14
+ - Configuration migration with mandatory password encryption when credentials are included, and a restore preview.
15
+ - Optional daily check-in, disabled by default and attempted only while the plugin is running.
16
+
17
+ ## Get started
18
+
19
+ Install and enable the bundle, open Settings → CodeArts → Accounts, add your AK/SK, select and save the models you need, then choose a CodeArts model in a conversation.
20
+
21
+ ## Data and costs
22
+
23
+ Requests and authentication information are sent to the configured services. Local credentials and ordinary account exports are plaintext; prefer encrypted backups for migration. Balances, multipliers and local usage records are not official billing records.
24
+
25
+ [Documentation](https://github.com/Jensen0925/dsh-codearts-dock#readme) · [Disclaimer](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/DISCLAIMER.md) · [Security](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/SECURITY.md)
@@ -0,0 +1,25 @@
1
+ # CodeArts Dock · 码道驿站
2
+
3
+ 在 DeepSeek Harness 中接入华为云码道模型,管理多账号、积分和模型配置。
4
+
5
+ 这是第三方非官方插件,与华为及 DeepSeek / Harness 运营方无官方关系。需要自己的有效账号和服务权限;调用可能消耗积分或产生费用。
6
+
7
+ ## 功能
8
+
9
+ - 原生模型适配:流式文本、推理、工具调用,以及模型支持的图片输入。
10
+ - 多账号管理、导入导出、手动切换和健康检查。
11
+ - 输入框积分胶囊、自定义低余额提醒及备用账号概览。
12
+ - 模型搜索、能力筛选、倍率排序、配置草稿和预设。
13
+ - 本机最近 200 条请求元数据,可关闭记录并清空。
14
+ - 配置迁移;包含账号凭证时必须密码加密,恢复前预览。
15
+ - 可选每日自动签到,默认关闭,仅在插件运行时尝试。
16
+
17
+ ## 开始使用
18
+
19
+ 安装启用后,打开「设置 → 码道 → 账号」添加 AK/SK,在模型页启用需要的模型并保存,再从对话模型选择器选择对应模型。
20
+
21
+ ## 数据与费用
22
+
23
+ 请求内容及认证信息会发送给配置的服务;本机凭证以明文保存。普通账号导出包含密钥,换机优先使用加密备份。余额、倍率和本机用量不是官方账单,实际计费以上游为准。
24
+
25
+ [完整文档](https://github.com/Jensen0925/dsh-codearts-dock#readme) · [免责声明](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/DISCLAIMER.md) · [安全说明](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/SECURITY.md)
@@ -0,0 +1,43 @@
1
+ # 发布与插件索引
2
+
3
+ 包名:`dsh-codearts-dock`。仓库:[Jensen0925/dsh-codearts-dock](https://github.com/Jensen0925/dsh-codearts-dock)。
4
+
5
+ ## 给使用者
6
+
7
+ ### GitHub
8
+
9
+ 在 Harness 插件管理页使用 Git 仓库地址安装:
10
+
11
+ ```text
12
+ https://github.com/Jensen0925/dsh-codearts-dock.git
13
+ ```
14
+
15
+ ### npm
16
+
17
+ npm 发行包名为 `dsh-codearts-dock`。包是否已发布、可用版本和发布时间,以 [npm 页面](https://www.npmjs.com/package/dsh-codearts-dock) 的实际记录为准。
18
+
19
+ ### 自定义插件索引
20
+
21
+ 支持格式 1 自定义索引的 Harness 版本,可启用「自定义插件索引」,在「插件 → 发现」的索引源中添加:
22
+
23
+ ```text
24
+ https://raw.githubusercontent.com/Jensen0925/dsh-codearts-dock/main/market-index.json
25
+ ```
26
+
27
+ 该索引由本项目维护,提供固定 Git 提交的安装目标,即使 npm 尚未发布也可使用 Git 来源。索引发布不等于被官方或其他社区市场收录,不代表官方审核、安全认证或推荐。
28
+
29
+ ### 社区市场
30
+
31
+ 社区目录 [awesome-deepseek-harness-plugins](https://github.com/imsai-sh/awesome-deepseek-harness-plugins) / [DSH 1024 Store](https://deepseek1024.com/) 有独立的收录流程。可按其 [贡献说明](https://github.com/imsai-sh/awesome-deepseek-harness-plugins/blob/main/CONTRIBUTING.md) 提交 `catalog/plugins/*.json` 条目,并给仓库添加 `dsh-plugin` topic。提交、审核合并和网站同步是不同阶段,以对应 PR 及市场页面为准。
32
+
33
+ ## 给维护者
34
+
35
+ 1. 更新版本、README、免责声明、安全说明和多语言元数据。
36
+ 2. 执行 `npm test` 与 `npm run check:release`。
37
+ 3. 执行 `npm pack --dry-run`,检查包内文件,再生成并检查实际 tarball。不得包含账号、令牌、本机笔记、导出或备份。
38
+ 4. 将验证后的源码提交、推送到 GitHub,为发行提交创建版本标签。
39
+ 5. 确认 npm 登录身份后执行 `npm publish --access public --registry=https://registry.npmjs.org/`。如要求 2FA,由维护者在官方流程中完成认证;不要把令牌提交到仓库。
40
+ 6. 使用 `node scripts/build-market-index.mjs <40位发行提交SHA>` 更新固定提交索引,再推送索引。
41
+ 7. 核实 npm 的具体版本和索引安装目标,并按需提交社区目录收录申请。
42
+
43
+ 本仓库保留 `dsh-connect-codearts` 本机配置目录和内部设置标识,模型 provider 仍为 `codearts`,以兼容已有配置。请勿同时启用新旧两个包。
@@ -0,0 +1,78 @@
1
+ <svg width="640" height="300" viewBox="0 0 640 300" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <defs>
3
+ <linearGradient id="dsh_codearts_preview_hero" x1="40" y1="40" x2="300" y2="260" gradientUnits="userSpaceOnUse">
4
+ <stop stop-color="#EDF3FF"/>
5
+ <stop offset="1" stop-color="#E4E9FF"/>
6
+ </linearGradient>
7
+ <linearGradient id="dsh_codearts_preview_accent" x1="60" y1="60" x2="260" y2="240" gradientUnits="userSpaceOnUse">
8
+ <stop stop-color="#4C8DFF"/>
9
+ <stop offset="1" stop-color="#2C3EDB"/>
10
+ </linearGradient>
11
+ </defs>
12
+
13
+ <!-- Settings page surface -->
14
+ <rect x="32" y="28" width="288" height="244" rx="14" fill="url(#dsh_codearts_preview_hero)"/>
15
+
16
+ <!-- Page header -->
17
+ <rect x="52" y="48" width="96" height="10" rx="5" fill="#2C3EDB" fill-opacity="0.75"/>
18
+ <rect x="52" y="66" width="180" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.22"/>
19
+
20
+ <!-- Tab strip -->
21
+ <rect x="52" y="86" width="42" height="6" rx="3" fill="url(#dsh_codearts_preview_accent)"/>
22
+ <rect x="104" y="86" width="34" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.2"/>
23
+ <rect x="148" y="86" width="34" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.2"/>
24
+ <rect x="52" y="98" width="164" height="1.5" rx="0.75" fill="#2C3EDB" fill-opacity="0.15"/>
25
+
26
+ <!-- Credential card: two fields -->
27
+ <rect x="52" y="112" width="248" height="56" rx="9" fill="#FFFFFF" fill-opacity="0.85"/>
28
+ <rect x="64" y="124" width="52" height="5" rx="2.5" fill="#2C3EDB" fill-opacity="0.3"/>
29
+ <rect x="64" y="134" width="100" height="20" rx="5" fill="#FFFFFF" stroke="#2C3EDB" stroke-opacity="0.2"/>
30
+ <rect x="170" y="124" width="60" height="5" rx="2.5" fill="#2C3EDB" fill-opacity="0.3"/>
31
+ <rect x="170" y="134" width="118" height="20" rx="5" fill="#FFFFFF" stroke="#2C3EDB" stroke-opacity="0.2"/>
32
+ <rect x="72" y="142" width="30" height="4" rx="2" fill="#2C3EDB" fill-opacity="0.35"/>
33
+ <rect x="178" y="142" width="42" height="4" rx="2" fill="#2C3EDB" fill-opacity="0.35"/>
34
+
35
+ <!-- Save / test buttons -->
36
+ <rect x="64" y="160" width="44" height="16" rx="5" fill="url(#dsh_codearts_preview_accent)"/>
37
+ <rect x="116" y="160" width="44" height="16" rx="5" fill="#FFFFFF" stroke="#2C3EDB" stroke-opacity="0.25"/>
38
+ <rect x="168" y="160" width="52" height="16" rx="5" fill="#FFFFFF" stroke="#2C3EDB" stroke-opacity="0.25"/>
39
+
40
+ <!-- Model catalog rows with multipliers -->
41
+ <rect x="52" y="186" width="248" height="70" rx="9" fill="#FFFFFF" fill-opacity="0.85"/>
42
+ <rect x="64" y="196" width="60" height="5" rx="2.5" fill="#2C3EDB" fill-opacity="0.55"/>
43
+
44
+ <rect x="64" y="208" width="72" height="5" rx="2.5" fill="#2C3EDB" fill-opacity="0.28"/>
45
+ <rect x="238" y="206" width="46" height="10" rx="5" fill="#4C8DFF" fill-opacity="0.22"/>
46
+ <rect x="248" y="209" width="26" height="4" rx="2" fill="#2C3EDB" fill-opacity="0.55"/>
47
+
48
+ <rect x="64" y="224" width="88" height="5" rx="2.5" fill="#2C3EDB" fill-opacity="0.28"/>
49
+ <rect x="238" y="222" width="46" height="10" rx="5" fill="#2C3EDB" fill-opacity="0.12"/>
50
+ <rect x="248" y="225" width="26" height="4" rx="2" fill="#2C3EDB" fill-opacity="0.45"/>
51
+
52
+ <rect x="64" y="240" width="64" height="5" rx="2.5" fill="#2C3EDB" fill-opacity="0.28"/>
53
+ <rect x="238" y="238" width="46" height="10" rx="5" fill="#2C3EDB" fill-opacity="0.12"/>
54
+ <rect x="248" y="241" width="26" height="4" rx="2" fill="#2C3EDB" fill-opacity="0.45"/>
55
+
56
+ <!-- Arrow: the same connector, now reachable from the composer -->
57
+ <path d="M336 150h34" stroke="#2C3EDB" stroke-opacity="0.35" stroke-width="2" stroke-linecap="round"/>
58
+ <path d="M362 142l10 8-10 8" stroke="#2C3EDB" stroke-opacity="0.45" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
59
+
60
+ <!-- Composer surface with the credit pill -->
61
+ <rect x="384" y="96" width="224" height="120" rx="14" fill="url(#dsh_codearts_preview_hero)"/>
62
+ <rect x="402" y="116" width="150" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.25"/>
63
+ <rect x="402" y="132" width="188" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.15"/>
64
+
65
+ <!-- The credit pill itself -->
66
+ <rect x="402" y="176" width="92" height="24" rx="12" fill="#FFFFFF" stroke="#2C3EDB" stroke-opacity="0.3"/>
67
+ <circle cx="417" cy="188" r="4" fill="url(#dsh_codearts_preview_accent)"/>
68
+ <rect x="427" y="185" width="26" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.55"/>
69
+ <rect x="459" y="185" width="22" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.3"/>
70
+
71
+ <!-- Send affordance -->
72
+ <circle cx="576" cy="188" r="14" fill="url(#dsh_codearts_preview_accent)"/>
73
+ <path d="M571 188h10M577 184l4 4-4 4" stroke="#FFFFFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
74
+
75
+ <!-- Caption: the provider route -->
76
+ <rect x="384" y="240" width="120" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.22"/>
77
+ <rect x="384" y="254" width="86" height="6" rx="3" fill="#2C3EDB" fill-opacity="0.14"/>
78
+ </svg>
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "CodeArts Dock",
4
+ "description": "Unofficial Huawei Cloud CodeArts model connector for DeepSeek Harness. Multi-account management, credit alerts, health checks, model presets, local usage metadata and encrypted configuration backups. Requires your own authorized account; upstream charges may apply.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "CodeArts Dock · 码道驿站",
4
+ "description": "为 DeepSeek Harness 接入华为云码道模型的第三方非官方插件。支持多账号、积分与余额提醒、账号健康检查、模型搜索与配置预设、本机用量记录及加密配置备份。需要自己的有效账号与权限,调用可能产生费用。",
5
+ "detail": "docs/DETAIL.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,90 @@
1
1
  {
2
2
  "name": "dsh-codearts-dock",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "displayName": "CodeArts Dock · 码道驿站",
5
+ "description": "为 DeepSeek Harness 接入华为云码道模型的非官方插件,提供多账号、积分提醒、模型预设、本机用量与加密配置备份。",
6
+ "type": "module",
7
+ "main": "src/index.js",
8
+ "icon": "icons/dsh-connect-codearts-128.png",
9
+ "exports": {
10
+ ".": "./src/index.js",
11
+ "./client": "./client.js",
12
+ "./cordis.patch.yml": "./cordis.patch.yml",
13
+ "./locale/*.json": "./locale/*.json",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "client.js",
19
+ "cordis.patch.yml",
20
+ "locale",
21
+ "docs",
22
+ "icons",
23
+ "test",
24
+ "README.md",
25
+ "LICENSE",
26
+ "THIRD_PARTY_NOTICES.md",
27
+ "DISCLAIMER.md",
28
+ "SECURITY.md",
29
+ "scripts"
30
+ ],
31
+ "dsh": {
32
+ "bundle": {
33
+ "patch": "./cordis.patch.yml"
34
+ },
35
+ "client": {
36
+ "platform": "web",
37
+ "immediately": true,
38
+ "inject": [
39
+ "@deepseek-ai/dsh-client-ui-settings",
40
+ "@deepseek-ai/dsh-client-ui-slots",
41
+ "@deepseek-ai/dsh-client-locale",
42
+ "@deepseek-ai/dsh-client-ui-conversation"
43
+ ]
44
+ }
45
+ },
46
+ "dependencies": {
47
+ "@deepseek-ai/schemastery": "3.18.5"
48
+ },
49
+ "peerDependencies": {
50
+ "@deepseek-ai/dsh-llm": ">=0.1.7-rc.1 <0.3.0-0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "@deepseek-ai/dsh-llm": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "keywords": [
58
+ "dsh-plugin",
59
+ "deepseek-harness",
60
+ "codearts",
61
+ "huawei-cloud",
62
+ "madao",
63
+ "model-provider",
64
+ "llm-adapter",
65
+ "sm4-gcm",
66
+ "huawei-signature",
67
+ "ai-coding-agent"
68
+ ],
69
+ "license": "MIT",
70
+ "scripts": {
71
+ "test": "npm run check:legal && node scripts/test.mjs",
72
+ "test:live": "node --no-warnings test/live-probe.mjs",
73
+ "check:legal": "bash scripts/check-legal.sh",
74
+ "check:release": "node scripts/check-release.mjs",
75
+ "prepublishOnly": "npm test && npm run check:release"
76
+ },
77
+ "author": "Jensen0925",
78
+ "repository": {
79
+ "type": "git",
80
+ "url": "git+https://github.com/Jensen0925/dsh-codearts-dock.git"
81
+ },
82
+ "homepage": "https://github.com/Jensen0925/dsh-codearts-dock#readme",
83
+ "bugs": {
84
+ "url": "https://github.com/Jensen0925/dsh-codearts-dock/issues"
85
+ },
86
+ "publishConfig": {
87
+ "access": "public",
88
+ "registry": "https://registry.npmjs.org/"
89
+ }
90
+ }
@@ -0,0 +1,24 @@
1
+ /** Pin marketplace installation to a reviewed commit, independently of npm authentication. */
2
+ import { readFileSync, writeFileSync } from 'node:fs'
3
+ const commit = process.argv[2]
4
+ if (!/^[a-f\d]{40}$/.test(commit ?? '')) throw new Error('Supply the full 40-character release commit SHA')
5
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
6
+ const root = 'https://github.com/Jensen0925/dsh-codearts-dock'
7
+ const index = {
8
+ format: 1,
9
+ title: { zh: 'CodeArts Dock 插件索引', en: 'CodeArts Dock plugin index' },
10
+ description: { zh: '项目维护的第三方插件索引;非官方审核或推荐。', en: 'Project-maintained third-party index; not an official review or endorsement.' },
11
+ metadata: { categories: { models: { title: { zh: '模型接入', en: 'Model providers' } } } },
12
+ plugins: [{
13
+ name: pkg.name,
14
+ title: { zh: pkg.displayName, en: 'CodeArts Dock' },
15
+ description: { zh: pkg.description, en: 'Unofficial CodeArts model connector with accounts, credits, presets and encrypted backups.' },
16
+ author: 'Jensen0925', homepage: root,
17
+ repository: { url: root },
18
+ icon: `https://raw.githubusercontent.com/Jensen0925/dsh-codearts-dock/${commit}/icons/dsh-connect-codearts-128.png`,
19
+ metadata: { category: 'models', keywords: pkg.keywords },
20
+ versions: [{ version: pkg.version, publishTimestamp: Math.floor(Date.now() / 1000), source: { type: 'git', url: root, commit } }],
21
+ }],
22
+ }
23
+ writeFileSync(new URL('../market-index.json', import.meta.url), JSON.stringify(index, null, 2) + '\n')
24
+ console.log(`market index: ${pkg.name}@${pkg.version} pinned to ${commit}`)
@@ -0,0 +1,33 @@
1
+ #!/bin/bash
2
+ # 发布文档一致性检查,不构成法律审查
3
+ cd "$(dirname "$0")/.." 2>/dev/null || cd .
4
+ fail=0
5
+ chk(){ if eval "$2" >/dev/null 2>&1; then echo "✓ $1"; else echo "✗ $1"; fail=1; fi; }
6
+
7
+ echo '=== 发布文档与安全说明检查 ==='
8
+ chk 'LICENSE 存在且为 MIT' 'head -2 LICENSE | grep -q MIT'
9
+ chk 'DISCLAIMER.md 存在' 'test -f DISCLAIMER.md'
10
+ chk 'DISCLAIMER 声明无关联' 'grep -q "没有任何关联" DISCLAIMER.md'
11
+ chk 'DISCLAIMER 声明商标描述性使用' 'grep -q "描述性使用" DISCLAIMER.md'
12
+ chk 'DISCLAIMER 声明无担保' 'grep -qi "按原样" DISCLAIMER.md'
13
+ chk 'SECURITY.md 存在' 'test -f SECURITY.md'
14
+ chk 'README 顶部有非官方声明' 'head -12 README.md | grep -q "非官方"'
15
+ chk 'README 声明与华为无关联' 'head -12 README.md | grep -q "无任何关联"'
16
+ chk 'README 链到免责声明' 'grep -q "DISCLAIMER.md" README.md'
17
+ chk 'README 链到安全说明' 'grep -q "SECURITY.md" README.md'
18
+ chk 'THIRD_PARTY_NOTICES 存在' 'test -f THIRD_PARTY_NOTICES.md'
19
+ chk 'README 无逆向措辞' '! grep -qiE "看内核源码|逆向工程|反编译" README.md'
20
+ chk 'README 声明不绕过计费' 'grep -q "不绕过计费" README.md'
21
+ chk '凭据借用声明仅本机本人' 'grep -q "本机" README.md && grep -q "本人" README.md'
22
+ chk '凭证文件权限 0600' 'grep -q "0o600" src/accounts.js'
23
+ chk '无第三方遥测域名' '! grep -rqE "google-analytics\\.com|sentry\\.io|api\\.segment\\.io|mixpanel\\.com|posthog|amplitude" src/ client.js'
24
+ chk 'package.json 有 license 字段' 'grep -q "\"license\": \"MIT\"" package.json'
25
+ chk 'package.json 无死链接' '! grep -qE "\"(repository|bugs|homepage)\"[^}]*github\\.com/Jensen0925/dsh-connect-codearts" package.json'
26
+ chk 'README 使用公开发行名称' 'head -10 README.md | grep -q "CodeArts Dock"'
27
+ chk '无旧版仅限自用的发行声明' '! grep -qE "仓库已删除|未公开发布|不通过 npm" README.md DISCLAIMER.md'
28
+ chk '新文档已列入 files' 'grep -q "DISCLAIMER.md" package.json && grep -q "SECURITY.md" package.json'
29
+ chk '.gitignore 排除凭证文件' 'grep -q "credentials.json" .gitignore'
30
+
31
+ echo
32
+ if [ $fail -eq 0 ]; then echo '全部通过。'; else echo '有未通过项,见上。'; fi
33
+ exit $fail
@@ -0,0 +1,29 @@
1
+ /** Check the public package metadata and file references before an npm release. */
2
+ import assert from 'node:assert/strict'
3
+ import { existsSync, readFileSync } from 'node:fs'
4
+ import { dirname, resolve } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ const root = fileURLToPath(new URL('../', import.meta.url))
7
+ const read = (name) => readFileSync(resolve(root, name), 'utf8')
8
+ const pkg = JSON.parse(read('package.json'))
9
+ assert.equal(pkg.name, 'dsh-codearts-dock')
10
+ assert.notEqual(pkg.private, true)
11
+ assert.equal(pkg.license, 'MIT')
12
+ assert.equal(pkg.repository.url, 'git+https://github.com/Jensen0925/dsh-codearts-dock.git')
13
+ assert.equal(pkg.publishConfig.registry, 'https://registry.npmjs.org/')
14
+ assert.ok(existsSync(resolve(root, pkg.dsh.bundle.patch)))
15
+ for (const name of ['README.md', 'DISCLAIMER.md', 'SECURITY.md', 'LICENSE', 'THIRD_PARTY_NOTICES.md', 'client.js', pkg.main]) assert.ok(existsSync(resolve(root, name)), `Missing ${name}`)
16
+ for (const name of ['README.md', 'DISCLAIMER.md', 'SECURITY.md', 'docs/PUBLISHING.md', 'docs/DETAIL.md', 'docs/DETAIL.zh.md']) {
17
+ const content = read(name)
18
+ for (const match of content.matchAll(/\]\(([^\s)]+)(?:\s+"[^"]*")?\)/g)) {
19
+ const path = match[1].split('#')[0]
20
+ if (!path || /^[a-z][a-z\d+.-]*:/i.test(path)) continue
21
+ assert.ok(existsSync(resolve(root, dirname(name), path)), `${name}: missing linked file ${path}`)
22
+ }
23
+ }
24
+ for (const lang of ['en', 'zh']) {
25
+ const locale = JSON.parse(read(`locale/${lang}.json`))
26
+ assert.ok(locale.meta.title.includes('CodeArts Dock'))
27
+ assert.ok(existsSync(resolve(root, locale.meta.detail)))
28
+ }
29
+ console.log('release: package metadata, bundle, locale and documentation links passed')
@@ -0,0 +1,11 @@
1
+ /** Run each offline suite in its own process so test environment overrides stay isolated. */
2
+ import { readdirSync } from 'node:fs'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { spawnSync } from 'node:child_process'
5
+ const root = fileURLToPath(new URL('../', import.meta.url))
6
+ const files = readdirSync(new URL('../test/', import.meta.url)).filter((name) => name.endsWith('.test.mjs')).sort()
7
+ for (const file of files) {
8
+ const result = spawnSync(process.execPath, ['--no-warnings', `test/${file}`], { cwd: root, stdio: 'inherit' })
9
+ if (result.error) throw result.error
10
+ if (result.status !== 0) process.exit(result.status ?? 1)
11
+ }
package/src/account.js ADDED
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Read-only account facts: credit balance, identity, and the daily check-in.
3
+ *
4
+ * Everything here is a plain (unsealed) gateway read. None of it changes
5
+ * account state except `claimBenefit`, which spends one real entitlement and
6
+ * therefore runs only when a user clicks it.
7
+ */
8
+
9
+ import { BENEFITS_PATH, BENEFIT_CLAIM_PATH, CREDIT_STATISTICS_PATH, ROLES_PATH } from './gateway.js'
10
+
11
+ /**
12
+ * @typedef {object} CreditInfo
13
+ * @property {number} total granted credits.
14
+ * @property {number} used consumed credits.
15
+ * @property {number} remain available credits.
16
+ * @property {{amount: number, used: number, remain: number}} [basic] the base package.
17
+ * @property {{amount: number, used: number, remain: number}} [bonus] the promotional package.
18
+ * @property {{amount: number, used: number, remain: number}} [onDemand] pay-as-you-go.
19
+ * @property {number} [totalTokens] lifetime chat tokens.
20
+ */
21
+
22
+ /**
23
+ * Read the credit balance.
24
+ *
25
+ * The gateway reports it as a flat list of named metrics, so the numbers have
26
+ * to be selected by name rather than by position. The metric key is `name` —
27
+ * reading `metric_name` yields a list of `undefined` and silently reports no
28
+ * balance at all.
29
+ *
30
+ * @param {import('./gateway.js').MadaoClient} client an authenticated client.
31
+ * @returns {Promise<CreditInfo|null>} the balance, or null when unreadable.
32
+ */
33
+ export async function readCredit(client, { strict = false } = {}) {
34
+ try {
35
+ const reply = await client.getJson(CREDIT_STATISTICS_PATH)
36
+ const metrics = reply?.metrics ?? reply?.data?.metrics ?? []
37
+ if (!Array.isArray(metrics)) return null
38
+
39
+ const pick = (name) => metrics.find((metric) => metric?.name === name)
40
+ const totals = pick('usageTotalPackageCredit')
41
+ if (!totals) return null
42
+
43
+ const packageOf = (metric) =>
44
+ metric
45
+ ? {
46
+ amount: Number(metric.package_credit_amount ?? 0),
47
+ used: Number(metric.package_credit_used ?? 0),
48
+ remain: Number(metric.package_credit_remain ?? 0),
49
+ }
50
+ : undefined
51
+
52
+ const tokens = pick('usageTokenChatMessages')
53
+ const plan = reply?.package
54
+ return {
55
+ total: Number(totals.package_credit_amount ?? 0),
56
+ used: Number(totals.package_credit_used ?? 0),
57
+ remain: Number(totals.package_credit_remain ?? 0),
58
+ basic: packageOf(pick('usageBasicPackageCredit')),
59
+ bonus: packageOf(pick('usageBonusPackageCredit')),
60
+ onDemand: packageOf(pick('usageOnDemandPackageCredit')),
61
+ totalTokens: tokens ? Number(tokens.usage_token_num ?? 0) : undefined,
62
+ // Summed across packages: the headline number the card reports.
63
+ expiringTotal:
64
+ Number(totals.package_credit_expiring_amount ?? 0) ||
65
+ ['usageBasicPackageCredit', 'usageBonusPackageCredit', 'usageOnDemandPackageCredit'].reduce(
66
+ (sum, name) => sum + Number(pick(name)?.package_credit_expiring_amount ?? 0),
67
+ 0,
68
+ ),
69
+ ...(plan?.package_name_cn || plan?.package_name_en
70
+ ? { plan: plan.package_name_cn ?? plan.package_name_en }
71
+ : {}),
72
+ }
73
+ } catch (error) {
74
+ if (strict) throw error
75
+ return null
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Read enterprise role names, when the account belongs to an enterprise.
81
+ * @param {import('./gateway.js').MadaoClient} client an authenticated client.
82
+ * @returns {Promise<string[]>} role names; empty for a personal account.
83
+ */
84
+ export async function readRoles(client) {
85
+ try {
86
+ const reply = await client.getJson(ROLES_PATH)
87
+ const roles = reply?.enterprise_roles ?? reply?.data?.enterprise_roles ?? []
88
+ return Array.isArray(roles) ? roles.filter((role) => typeof role === 'string') : []
89
+ } catch {
90
+ return []
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Decode the identity a security token carries.
96
+ *
97
+ * The token is a Base64 JSON document followed by a binary signature. A naive
98
+ * "find the last `}`" slices the signature back into the JSON, because the
99
+ * trailing bytes can contain that character, so this pairs braces instead.
100
+ *
101
+ * @param {string|undefined} securityToken the token from the credential.
102
+ * @returns {{accountName?: string, domainId?: string, userId?: string, userType?: number}} identity facts.
103
+ */
104
+ export function parseIdentity(securityToken) {
105
+ if (!securityToken) return {}
106
+ try {
107
+ const raw = Buffer.from(securityToken, 'base64').toString('utf8')
108
+ const start = raw.indexOf('{')
109
+ if (start < 0) return {}
110
+ const end = findJsonEnd(raw, start)
111
+ if (end < 0) return {}
112
+ const parsed = JSON.parse(raw.slice(start, end + 1))
113
+ const user = parsed?.user ?? {}
114
+ const domain = user.domain ?? {}
115
+ return {
116
+ accountName: domain.name ?? user.name,
117
+ domainId: domain.id,
118
+ userId: user.id,
119
+ userType: typeof user.user_type === 'number' ? user.user_type : undefined,
120
+ }
121
+ } catch {
122
+ return {}
123
+ }
124
+ }
125
+
126
+ /** Find the index of the brace that closes the object opened at `start`. */
127
+ function findJsonEnd(raw, start) {
128
+ let depth = 0
129
+ let inString = false
130
+ let escaped = false
131
+ for (let i = start; i < raw.length; i++) {
132
+ const ch = raw[i]
133
+ if (inString) {
134
+ if (escaped) escaped = false
135
+ else if (ch === '\\') escaped = true
136
+ else if (ch === '"') inString = false
137
+ continue
138
+ }
139
+ if (ch === '"') inString = true
140
+ else if (ch === '{') depth += 1
141
+ else if (ch === '}') {
142
+ depth -= 1
143
+ if (depth === 0) return i
144
+ }
145
+ }
146
+ return -1
147
+ }
148
+
149
+ /**
150
+ * @typedef {object} BenefitItem
151
+ * @property {number} campaignId campaign identifier.
152
+ * @property {string} title campaign title.
153
+ * @property {string|null} status upstream status text.
154
+ * @property {boolean} claimable whether it can be claimed right now.
155
+ * @property {number} pendingAmount credits on offer.
156
+ * @property {string} unit benefit unit.
157
+ * @property {string|null} expireAt ISO expiry, when one is declared.
158
+ */
159
+
160
+ /**
161
+ * List the campaigns this account can see, annotating which are claimable.
162
+ *
163
+ * This is a read: no claim is attempted. Displaying what *can* be claimed is
164
+ * the whole point of the list.
165
+ * @param {import('./gateway.js').MadaoClient} client an authenticated client.
166
+ * @returns {Promise<BenefitItem[]>} the campaigns.
167
+ */
168
+ export async function listBenefits(client) {
169
+ const reply = await client.getJson(BENEFITS_PATH)
170
+ const items = reply?.data?.items ?? reply?.items ?? []
171
+ if (!Array.isArray(items)) return []
172
+ return items.map((item) => ({
173
+ campaignId: Number(item.campaignId ?? 0),
174
+ title: String(item.title ?? ''),
175
+ status: item.status ?? null,
176
+ claimable: item.claimable === true,
177
+ pendingAmount: Number(item.pendingTotalAmount ?? 0),
178
+ unit: String(item.benefitUnit ?? 'CREDIT'),
179
+ expireAt: item.expireAt ?? null,
180
+ }))
181
+ }
182
+
183
+ /**
184
+ * Claim one campaign.
185
+ *
186
+ * One campaign per call, by design: a single click spends one real,
187
+ * irreversible entitlement, so there is no "claim all" path.
188
+ * @param {import('./gateway.js').MadaoClient} client an authenticated client.
189
+ * @param {number} campaignId the campaign to claim.
190
+ * @returns {Promise<{ok: true, reply: unknown} | {ok: false, reason: string}>} the outcome.
191
+ */
192
+ export async function claimBenefit(client, campaignId) {
193
+ if (!Number.isInteger(campaignId) || campaignId <= 0) {
194
+ return { ok: false, reason: '缺少有效的 campaignId' }
195
+ }
196
+ try {
197
+ // Re-read immediately before claiming: an already-claimed or expired
198
+ // campaign must not be sent to the write endpoint.
199
+ const items = await listBenefits(client)
200
+ const target = items.find((item) => item.campaignId === campaignId)
201
+ if (!target) return { ok: false, reason: `上游列表里没有 campaignId=${campaignId}` }
202
+ if (!target.claimable) {
203
+ return { ok: false, reason: `「${target.title}」当前不可领取(status=${target.status ?? '未知'})` }
204
+ }
205
+
206
+ const reply = await client.postJson(BENEFIT_CLAIM_PATH, {
207
+ campaignId,
208
+ // A deterministic key makes a retried request idempotent rather than
209
+ // a second claim.
210
+ idempotentKey: `codearts-claim-${campaignId}-${new Date().toISOString().slice(0, 10)}`,
211
+ channel: 'IDE',
212
+ })
213
+ return { ok: true, reply }
214
+ } catch (error) {
215
+ return { ok: false, reason: error?.message ?? String(error) }
216
+ }
217
+ }