dsh-codearts 0.3.0 → 0.4.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.
package/lib/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { S as codeartsAccountsPath, _ as FALLBACK_CODEARTS_MODELS, b as CodeArtsAccountStore, l as fetchCallerIdentity, n as codeartsUsagePath, r as discoverModels, t as CodeArtsUsageTracker, y as isBenefitModel } from "./usage-Cn1Bzmxj.mjs";
2
+ import { C as codeartsAccountsPath, b as isBenefitModel, n as codeartsUsagePath, r as discoverModels, t as CodeArtsUsageTracker, u as fetchCallerIdentity, v as FALLBACK_CODEARTS_MODELS, x as CodeArtsAccountStore } from "./usage-3W88T_H1.mjs";
3
3
  import { existsSync, statSync } from "node:fs";
4
4
  //#region src/version.ts
5
5
  const CODEARTS_VERSION = "0.3.0";
@@ -67,6 +67,10 @@ interface CodeArtsSettingsKey {
67
67
  creditsUnavailable: string;
68
68
  creditsDock: string;
69
69
  creditsDockTitle: string;
70
+ claimButton: string;
71
+ claiming: string;
72
+ claimSuccess: string;
73
+ claimFailed: string;
70
74
  [key: string]: string;
71
75
  }
72
76
  //#endregion
@@ -18,32 +18,32 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
18
18
  document.head.appendChild(tag);
19
19
  }
20
20
  var CodeArtsPluginCard_module_css_default = {
21
- "fieldLabel": "DZPfya_fieldLabel",
22
- "danger": "DZPfya_danger",
23
- "card": "DZPfya_card",
24
- "hint": "DZPfya_hint",
25
- "header": "DZPfya_header",
26
- "link": "DZPfya_link",
27
- "body": "DZPfya_body",
28
- "headText": "DZPfya_headText",
29
- "name": "DZPfya_name",
30
- "meta": "DZPfya_meta",
31
- "section": "DZPfya_section",
32
- "sectionLabel": "DZPfya_sectionLabel",
33
- "error": "DZPfya_error",
34
21
  "choices": "DZPfya_choices",
35
- "desc": "DZPfya_desc",
36
- "sectionHead": "DZPfya_sectionHead",
22
+ "actions": "DZPfya_actions",
37
23
  "choiceRow": "DZPfya_choiceRow",
38
- "check": "DZPfya_check",
39
- "manual": "DZPfya_manual",
24
+ "header": "DZPfya_header",
40
25
  "manualSummary": "DZPfya_manualSummary",
41
- "statusLine": "DZPfya_statusLine",
42
26
  "field": "DZPfya_field",
43
- "actions": "DZPfya_actions",
27
+ "meta": "DZPfya_meta",
28
+ "link": "DZPfya_link",
44
29
  "area": "DZPfya_area",
45
30
  "headActions": "DZPfya_headActions",
46
- "count": "DZPfya_count"
31
+ "hint": "DZPfya_hint",
32
+ "statusLine": "DZPfya_statusLine",
33
+ "check": "DZPfya_check",
34
+ "manual": "DZPfya_manual",
35
+ "desc": "DZPfya_desc",
36
+ "fieldLabel": "DZPfya_fieldLabel",
37
+ "body": "DZPfya_body",
38
+ "section": "DZPfya_section",
39
+ "card": "DZPfya_card",
40
+ "name": "DZPfya_name",
41
+ "sectionHead": "DZPfya_sectionHead",
42
+ "sectionLabel": "DZPfya_sectionLabel",
43
+ "count": "DZPfya_count",
44
+ "headText": "DZPfya_headText",
45
+ "error": "DZPfya_error",
46
+ "danger": "DZPfya_danger"
47
47
  };
48
48
  //#endregion
49
49
  //#region src/client/CodeArtsPluginCard.tsx
@@ -90,8 +90,41 @@ function formatCredits(value) {
90
90
  * 所以这里能直接显示账号总额度 —— 与下面的「本机用量」互补:一个是账号级、一个是
91
91
  * 本机级。拉不到时显示原因(creditsError),不静默吞掉。
92
92
  */
93
- function CreditsSection({ credits, error, t }) {
93
+ function CreditsSection({ credits, error, t, onClaimed }) {
94
+ const [claimState, setClaimState] = (0, react.useState)(() => {
95
+ try {
96
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
97
+ if (typeof localStorage !== "undefined" && localStorage.getItem("codearts-claim-date") === today) return "success";
98
+ } catch {}
99
+ return "idle";
100
+ });
101
+ const [claimMessage, setClaimMessage] = (0, react.useState)("");
94
102
  if (credits === void 0 && error === void 0) return null;
103
+ const handleClaim = async () => {
104
+ setClaimState("loading");
105
+ try {
106
+ const res = await fetch("/api/codearts/claim", {
107
+ method: "POST",
108
+ headers: { Accept: "application/json" },
109
+ credentials: "same-origin"
110
+ });
111
+ const data = await res.json().catch(() => void 0);
112
+ if (res.ok && data?.ok === true) {
113
+ setClaimState("success");
114
+ try {
115
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
116
+ if (typeof localStorage !== "undefined") localStorage.setItem("codearts-claim-date", today);
117
+ } catch {}
118
+ onClaimed?.();
119
+ } else {
120
+ setClaimState("error");
121
+ setClaimMessage(data?.message ?? `HTTP ${res.status}`);
122
+ }
123
+ } catch (err) {
124
+ setClaimState("error");
125
+ setClaimMessage(err instanceof Error ? err.message : String(err));
126
+ }
127
+ };
95
128
  const c = credits?.credits;
96
129
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
97
130
  className: CodeArtsPluginCard_module_css_default.section,
@@ -101,18 +134,31 @@ function CreditsSection({ credits, error, t }) {
101
134
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
102
135
  className: CodeArtsPluginCard_module_css_default.sectionLabel,
103
136
  children: t("creditsTitle")
104
- }), c !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
105
- className: CodeArtsPluginCard_module_css_default.count,
106
- children: t("creditsRemaining", {
107
- remain: formatCredits(c.total.remain),
108
- total: formatCredits(c.total.total)
109
- })
137
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
138
+ className: CodeArtsPluginCard_module_css_default.headActions,
139
+ children: [c !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
140
+ className: CodeArtsPluginCard_module_css_default.count,
141
+ children: t("creditsRemaining", {
142
+ remain: formatCredits(c.total.remain),
143
+ total: formatCredits(c.total.total)
144
+ })
145
+ }), onClaimed !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
146
+ variant: "outline",
147
+ size: "sm",
148
+ disabled: claimState === "loading" || claimState === "success",
149
+ onClick: () => void handleClaim(),
150
+ children: claimState === "loading" ? t("claiming") : claimState === "success" ? t("claimSuccess") : t("claimButton")
151
+ })]
110
152
  })]
111
153
  }),
112
154
  error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
113
155
  className: CodeArtsPluginCard_module_css_default.hint,
114
156
  children: t("creditsUnavailable", { message: error })
115
157
  }),
158
+ claimState === "error" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
159
+ className: CodeArtsPluginCard_module_css_default.hint,
160
+ children: t("claimFailed", { message: claimMessage })
161
+ }),
116
162
  c !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
117
163
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
118
164
  className: CodeArtsPluginCard_module_css_default.choiceRow,
@@ -734,7 +780,8 @@ function CodeArtsPluginCard({ t }) {
734
780
  signedIn && (status?.credits !== void 0 || status?.creditsError !== void 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CreditsSection, {
735
781
  credits: status?.credits,
736
782
  error: status?.creditsError,
737
- t
783
+ t,
784
+ onClaimed: () => void refresh()
738
785
  }),
739
786
  status?.usage !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageSection, {
740
787
  usage: status.usage,
@@ -900,7 +947,11 @@ const zh = {
900
947
  creditsTokensBalance: "余额 {balance}",
901
948
  creditsUnavailable: "积分不可用:{message}",
902
949
  creditsDock: "积分 {remain}",
903
- creditsDockTitle: "CodeArts 剩余积分 {remain} / {total}"
950
+ creditsDockTitle: "CodeArts 剩余积分 {remain} / {total}",
951
+ claimButton: "领取积分",
952
+ claiming: "领取中…",
953
+ claimSuccess: "已领取",
954
+ claimFailed: "领取失败:{message}"
904
955
  };
905
956
  const en = {
906
957
  tabLabel: "CodeArts",
@@ -968,7 +1019,11 @@ const en = {
968
1019
  creditsTokensBalance: "{balance} left",
969
1020
  creditsUnavailable: "Credits unavailable: {message}",
970
1021
  creditsDock: "Credits {remain}",
971
- creditsDockTitle: "CodeArts credits left {remain} / {total}"
1022
+ creditsDockTitle: "CodeArts credits left {remain} / {total}",
1023
+ claimButton: "Claim credits",
1024
+ claiming: "Claiming…",
1025
+ claimSuccess: "Claimed",
1026
+ claimFailed: "Claim failed: {message}"
972
1027
  };
973
1028
  //#endregion
974
1029
  //#region src/client/index.tsx
package/lib/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as codeartsAuthPath, S as codeartsAccountsPath, _ as FALLBACK_CODEARTS_MODELS, a as SNAP_HOST, b as CodeArtsAccountStore, c as degradeTokenCeiling, d as isConcurrencyCap, f as isParamInvalidFrame, g as CodeArtsCatalog, h as signedGet, i as refreshCatalog, l as fetchCallerIdentity, m as prepareChatBody, n as codeartsUsagePath, o as canonicalModel, p as maxTokensCeilingFor, r as discoverModels, s as chatStream, t as CodeArtsUsageTracker, u as fetchModels, v as filterEnabledModels, w as startLogin, x as CodeArtsCredentialStore, y as isBenefitModel } from "./usage-Cn1Bzmxj.mjs";
1
+ import { C as codeartsAccountsPath, S as CodeArtsCredentialStore, T as startLogin, _ as CodeArtsCatalog, a as SNAP_HOST, b as isBenefitModel, c as claimBenefit, d as fetchModels, f as isConcurrencyCap, g as signedGet, h as prepareChatBody, i as refreshCatalog, l as degradeTokenCeiling, m as maxTokensCeilingFor, n as codeartsUsagePath, o as canonicalModel, p as isParamInvalidFrame, r as discoverModels, s as chatStream, t as CodeArtsUsageTracker, u as fetchCallerIdentity, v as FALLBACK_CODEARTS_MODELS, w as codeartsAuthPath, x as CodeArtsAccountStore, y as filterEnabledModels } from "./usage-3W88T_H1.mjs";
2
2
  import z from "@deepseek-ai/schemastery";
3
3
  import { randomBytes, timingSafeEqual } from "node:crypto";
4
4
  import { createServer } from "node:http";
@@ -999,6 +999,8 @@ const CODEARTS_LOGIN_PATH = "/api/codearts/login";
999
999
  const CODEARTS_LOGIN_STATUS_PATH = "/api/codearts/login/status";
1000
1000
  /** 删除某个账号:DELETE /api/codearts/accounts?id=<accountId> */
1001
1001
  const CODEARTS_ACCOUNTS_PATH = "/api/codearts/accounts";
1002
+ /** POST /api/codearts/claim — 手动领取限时福利(签到领积分,幂等)。 */
1003
+ const CODEARTS_CLAIM_PATH = "/api/codearts/claim";
1002
1004
  /**
1003
1005
  * 由完整目录 + 已存 enabled 计算 selection。
1004
1006
  * - enabled 为空/未存 => 全部勾选(restricted=false)
@@ -1331,6 +1333,36 @@ function accountsHandler(deps) {
1331
1333
  }
1332
1334
  };
1333
1335
  }
1336
+ /** POST /api/codearts/claim — 手动领取限时福利(签到领积分,幂等)。 */
1337
+ function claimHandler(deps) {
1338
+ return async (req, res) => {
1339
+ if (req.method !== "POST") {
1340
+ json(res, 405, { error: "method not allowed" });
1341
+ return;
1342
+ }
1343
+ if (deps.claim === void 0) {
1344
+ json(res, 404, { error: "claim not available" });
1345
+ return;
1346
+ }
1347
+ if (!loopbackRequest(req)) {
1348
+ json(res, 403, { error: "request-not-trusted" });
1349
+ return;
1350
+ }
1351
+ try {
1352
+ const result = await deps.claim();
1353
+ if (result.ok) json(res, 200, { ok: true });
1354
+ else json(res, 500, {
1355
+ ok: false,
1356
+ message: result.message
1357
+ });
1358
+ } catch (error) {
1359
+ json(res, 500, {
1360
+ ok: false,
1361
+ message: safeMessage(error)
1362
+ });
1363
+ }
1364
+ };
1365
+ }
1334
1366
  /** Mount the status / models / token routes. */
1335
1367
  function registerCodeArtsStatusRoute(ctx, deps) {
1336
1368
  ctx.effect(() => {
@@ -1372,6 +1404,11 @@ function registerCodeArtsStatusRoute(ctx, deps) {
1372
1404
  path: CODEARTS_ACCOUNTS_PATH,
1373
1405
  handler: accountsHandler(deps)
1374
1406
  });
1407
+ const disposeClaim = ctx.webServer.register({
1408
+ kind: "exact",
1409
+ path: CODEARTS_CLAIM_PATH,
1410
+ handler: claimHandler(deps)
1411
+ });
1375
1412
  return () => {
1376
1413
  disposeStatus();
1377
1414
  disposeModels();
@@ -1380,6 +1417,7 @@ function registerCodeArtsStatusRoute(ctx, deps) {
1380
1417
  disposeLoginStart();
1381
1418
  disposeLoginStatus();
1382
1419
  disposeAccounts();
1420
+ disposeClaim();
1383
1421
  for (const s of activeLogins.values()) s.close();
1384
1422
  activeLogins.clear();
1385
1423
  };
@@ -1607,7 +1645,30 @@ function apply(ctx, rawConfig) {
1607
1645
  setEnabledModels,
1608
1646
  pool: () => pool.list(),
1609
1647
  usage: () => usage.snapshot(),
1610
- credits: (signal) => loadCredits(signal)
1648
+ credits: (signal) => loadCredits(signal),
1649
+ claim: async () => {
1650
+ try {
1651
+ const ids = await store.ids();
1652
+ for (const id of ids) {
1653
+ const stored = await store.credential(id);
1654
+ if (stored === void 0 || stored.stale === true) continue;
1655
+ const resolved = await store.resolve(id);
1656
+ if (resolved === void 0) continue;
1657
+ await claimBenefit(resolved, AbortSignal.timeout(1e4));
1658
+ credits.invalidate();
1659
+ return { ok: true };
1660
+ }
1661
+ return {
1662
+ ok: false,
1663
+ message: "no usable credential"
1664
+ };
1665
+ } catch (error) {
1666
+ return {
1667
+ ok: false,
1668
+ message: error instanceof Error ? error.message : String(error)
1669
+ };
1670
+ }
1671
+ }
1611
1672
  }));
1612
1673
  installSettingsSectionCompat(ctx, CODEARTS_SETTINGS_NS, Config, config, {
1613
1674
  setSource(source) {
@@ -2220,4 +2220,4 @@ function sumOf(store) {
2220
2220
  return out;
2221
2221
  }
2222
2222
  //#endregion
2223
- export { codeartsAuthPath as C, codeartsAccountsPath as S, FALLBACK_CODEARTS_MODELS as _, SNAP_HOST as a, CodeArtsAccountStore as b, degradeTokenCeiling as c, isConcurrencyCap as d, isParamInvalidFrame as f, CodeArtsCatalog as g, signedGet as h, refreshCatalog as i, fetchCallerIdentity as l, prepareChatBody as m, codeartsUsagePath as n, canonicalModel as o, maxTokensCeilingFor as p, discoverModels as r, chatStream as s, CodeArtsUsageTracker as t, fetchModels as u, filterEnabledModels as v, startLogin as w, CodeArtsCredentialStore as x, isBenefitModel as y };
2223
+ export { codeartsAccountsPath as C, CodeArtsCredentialStore as S, startLogin as T, CodeArtsCatalog as _, SNAP_HOST as a, isBenefitModel as b, claimBenefit as c, fetchModels as d, isConcurrencyCap as f, signedGet as g, prepareChatBody as h, refreshCatalog as i, degradeTokenCeiling as l, maxTokensCeilingFor as m, codeartsUsagePath as n, canonicalModel as o, isParamInvalidFrame as p, discoverModels as r, chatStream as s, CodeArtsUsageTracker as t, fetchCallerIdentity as u, FALLBACK_CODEARTS_MODELS as v, codeartsAuthPath as w, CodeArtsAccountStore as x, filterEnabledModels as y };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-codearts",
3
3
  "displayName": "DSH CodeArts Connect",
4
4
  "description": "把华为云 CodeArts 接入 DeepSeek Harness —— 内置 OAuth2 登录(PKCE + DPoP),登录后即可在 DSH 对话窗口使用 CodeArts 的模型。",
5
- "version": "0.3.0",
5
+ "version": "0.4.0",
6
6
  "author": "elegant01",
7
7
  "keywords": [
8
8
  "dsh-plugin",