@authinex/dsh-plugin 0.1.2 → 0.1.4

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 CHANGED
@@ -55,6 +55,8 @@ dsh plugin --profile <你的 profile> add @authinex/dsh-plugin
55
55
 
56
56
  > 刚发布完可能提示「未找到相关插件」——这是 npm 元数据还没扩散,等几分钟再试。
57
57
 
58
+ > 刚发布不到 24 小时的版本会被 pnpm 的供应链策略(`minimumReleaseAge`)暂缓,直接装会拿到上一个版本。要新版本就装精确版本号 `@authinex/dsh-plugin@x.y.z`;插件页会先卸掉当前版本再装。
59
+
58
60
  ## 绑定
59
61
 
60
62
  左侧「插件」→ 点这一行右侧的「Configure」,页面上有两个输入框:
@@ -67,6 +69,7 @@ dsh plugin --profile <你的 profile> add @authinex/dsh-plugin
67
69
  - 密钥一次性,兑换成功即作废。
68
70
  - 测试密钥只能连测试环境,前缀和服务对不上只显示「密钥无效」。
69
71
  - 绑定成功后地址和私钥一起存进本机凭据,重启自动登录,不用重填。
72
+ - 已经连上时再贴一把新密钥,也会拿去兑换。运营台要重新打开「DS 插件密钥」,状态才会从「待绑定」变成「已绑定」。
70
73
  - 换地址要先「解除绑定」再重填。
71
74
  - 验证通过后才会出现使用者、功能列表和账号;没通过之前这些都不显示。
72
75
 
@@ -81,7 +84,7 @@ dsh plugin --profile <你的 profile> add @authinex/dsh-plugin
81
84
 
82
85
  ## 更新
83
86
 
84
- 点「检查更新」取清单,有新版本时卡片会给出新版本号、版本说明和校验值。
87
+ 点「检查更新」先取服务端清单;服务端没配更新源(清单 404)时,退回 npm 的 `latest` 标签比较版本,这时只能发现版本号,安装仍让 DeepSeek 的安装器按 `@authinex/dsh-plugin@x.y.z` 去 npm 取。
85
88
 
86
89
  点「更新到 x.y.z」并确认,插件会调用 DeepSeek 自己的安装器装新版本。装完重启智能问答生效,绑定和账号都不动。
87
90
 
package/lib/client.js CHANGED
@@ -328,6 +328,9 @@ async function api(path, init) {
328
328
  return {};
329
329
  }
330
330
  }
331
+ function dwell(ms = 450) {
332
+ return new Promise((resolve) => setTimeout(resolve, ms));
333
+ }
331
334
  function tagTone(state) {
332
335
  if (state === "ready") return "success";
333
336
  if (state === "read_only") return "info";
@@ -352,6 +355,7 @@ function AuthinexPanel() {
352
355
  const [confirmUnbind, setConfirmUnbind] = (0, import_react.useState)(false);
353
356
  const [confirmUpdate, setConfirmUpdate] = (0, import_react.useState)(false);
354
357
  const [restart, setRestart] = (0, import_react.useState)(false);
358
+ const [feedback, setFeedback] = (0, import_react.useState)("");
355
359
  const model = (0, import_react.useMemo)(() => viewModel(state || void 0), [state]);
356
360
  const applyState = (0, import_react.useCallback)((next) => {
357
361
  setState(next);
@@ -359,8 +363,10 @@ function AuthinexPanel() {
359
363
  const read = (0, import_react.useCallback)(async () => {
360
364
  try {
361
365
  applyState(await api("/authinex-ds/state"));
366
+ return true;
362
367
  } catch {
363
368
  setState({ phase: "unreachable" });
369
+ return false;
364
370
  } finally {
365
371
  setLoaded(true);
366
372
  }
@@ -375,10 +381,14 @@ function AuthinexPanel() {
375
381
  setBusy(label);
376
382
  setNotice("");
377
383
  setLocalError("");
384
+ setFeedback("");
378
385
  try {
379
386
  await work();
380
387
  } catch {
381
388
  setState({ phase: "unreachable" });
389
+ if (label === "refresh") setNotice("没有刷新到");
390
+ if (label === "update") setNotice("没有查到更新");
391
+ if (label === "refresh" || label === "update") setFeedback("error");
382
392
  } finally {
383
393
  setBusy("");
384
394
  }
@@ -402,6 +412,26 @@ function AuthinexPanel() {
402
412
  setNotice(String(body.message || ""));
403
413
  });
404
414
  };
415
+ const onRebind = () => {
416
+ const url = (model.endpoint || endpoint).trim();
417
+ const problem = checkEndpoint(url);
418
+ if (problem) {
419
+ setLocalError(problem);
420
+ return;
421
+ }
422
+ if (!parseKey(key)) {
423
+ setLocalError("密钥格式不对,管理员发的密钥形如 auds-t-XXXX-XXXX-XXX");
424
+ return;
425
+ }
426
+ void run("bind", async () => {
427
+ const body = await api("/authinex-ds/bind", { method: "POST", body: { endpoint: url, key } });
428
+ applyState(body);
429
+ setKey("");
430
+ const failed = body.phase === "invalid" || body.phase === "unreachable" || body.phase === "revoked" || body.phase === "locked";
431
+ setNotice(String(body.message || (failed ? "没有绑定" : "已绑定")));
432
+ setFeedback(failed ? "error" : "ok");
433
+ });
434
+ };
405
435
  const onUnbind = () => {
406
436
  setConfirmUnbind(false);
407
437
  void run("unbind", async () => {
@@ -464,11 +494,28 @@ function AuthinexPanel() {
464
494
  }
465
495
  });
466
496
  };
497
+ const onRefresh = () => {
498
+ void run("refresh", async () => {
499
+ const [ok] = await Promise.all([read(), dwell()]);
500
+ if (!ok) {
501
+ setFeedback("error");
502
+ setNotice("没有刷新到");
503
+ return;
504
+ }
505
+ setFeedback("ok");
506
+ setNotice("已刷新");
507
+ });
508
+ };
467
509
  const onCheckUpdate = () => {
468
510
  void run("update", async () => {
469
- const body = await api("/authinex-ds/update/check", { method: "POST" });
511
+ const [body] = await Promise.all([
512
+ api("/authinex-ds/update/check", { method: "POST" }),
513
+ dwell()
514
+ ]);
470
515
  applyState(body);
471
- setNotice(String(body.updateMessage || "没有查到更新"));
516
+ const text = String(body.updateMessage || "没有查到更新");
517
+ setNotice(text);
518
+ setFeedback(text.includes("没有") ? "warn" : "ok");
472
519
  });
473
520
  };
474
521
  const onApplyUpdate = () => {
@@ -476,6 +523,7 @@ function AuthinexPanel() {
476
523
  void run("update-apply", async () => {
477
524
  const body = await api("/authinex-ds/update/apply", { method: "POST" });
478
525
  setNotice(String(body.message || (body.ok ? "已更新" : "没有更新")));
526
+ setFeedback(body.ok ? "ok" : "error");
479
527
  if (body.ok) setRestart(true);
480
528
  });
481
529
  };
@@ -483,6 +531,8 @@ function AuthinexPanel() {
483
531
  const message = localError || notice || model.message;
484
532
  const messageError = localError !== "" || model.phase === "invalid" || model.phase === "revoked" || model.phase === "unreachable";
485
533
  const disabled = busy !== "";
534
+ const pending = busy === "refresh" ? "正在刷新…" : busy === "update" ? "正在检查更新…" : "";
535
+ const messageClass = feedback === "ok" ? "axds-ok" : feedback === "warn" ? "axds-notice" : messageError || feedback === "error" ? "axds-error" : "axds-muted";
486
536
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "axds", "aria-label": "AuthineX 助手", children: [
487
537
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", { className: "axds-head", children: [
488
538
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.StateDot, { state: model.tone }),
@@ -490,9 +540,7 @@ function AuthinexPanel() {
490
540
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "axds-title", children: "AuthineX 助手" }),
491
541
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "axds-sub", children: loaded ? model.headline : "正在读取状态…" })
492
542
  ] }),
493
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "axds-head-actions", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", disabled, onClick: () => {
494
- void read();
495
- }, children: "刷新" }) })
543
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "axds-head-actions", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", disabled, onClick: onRefresh, children: busy === "refresh" ? "刷新中" : "刷新" }) })
496
544
  ] }),
497
545
  model.retryAfterSec > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "axds-notice", children: [
498
546
  "请等待 ",
@@ -506,7 +554,10 @@ function AuthinexPanel() {
506
554
  model.minVersion,
507
555
  "。请先更新插件。"
508
556
  ] }) : null,
509
- message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: messageError ? "axds-error" : "axds-muted", children: message }) : null,
557
+ pending ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "axds-pending", role: "status", children: [
558
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "axds-spin", "aria-hidden": "true" }),
559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: pending })
560
+ ] }, "pending") : message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: messageClass, role: "status", children: message }, message) : null,
510
561
  showForm ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "axds-card", onSubmit: onBind, children: [
511
562
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "axds-field", children: [
512
563
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "访问地址" }),
@@ -671,8 +722,31 @@ function AuthinexPanel() {
671
722
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", variant: "primary", disabled, onClick: onApplyUpdate, children: "确认更新" })
672
723
  ] }) : null,
673
724
  restart ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "axds-notice", children: "已装好,重启智能问答后新版本才生效。" }) : null,
725
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "axds-card", children: [
726
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "axds-field", children: [
727
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "新密钥" }),
728
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
729
+ import_dsh_client_ui_primitives.Input,
730
+ {
731
+ className: "axds-input",
732
+ value: key,
733
+ placeholder: "auds-p-XXXX-XXXX-XXX",
734
+ autoComplete: "off",
735
+ spellCheck: false,
736
+ onChange: (event) => {
737
+ setKey(event.target.value);
738
+ setLocalError("");
739
+ }
740
+ }
741
+ )
742
+ ] }),
743
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "axds-actions", children: [
744
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "axds-muted", children: "贴一把新密钥会重新兑换,运营台才会变成已绑定" }),
745
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", variant: "primary", disabled: disabled || key.trim() === "", onClick: onRebind, children: "绑定这把密钥" })
746
+ ] })
747
+ ] }),
674
748
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "axds-row", children: [
675
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", disabled, onClick: onCheckUpdate, children: "检查更新" }),
749
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", disabled, onClick: onCheckUpdate, children: busy === "update" ? "检查中" : "检查更新" }),
676
750
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", variant: "outline", disabled, onClick: () => {
677
751
  setConfirmUnbind(true);
678
752
  }, children: "解除绑定" }),
@@ -714,6 +788,13 @@ var CSS = `
714
788
  .axds-notice{color:var(--dsw-alias-state-warn-label);font-size:12px}
715
789
  .axds-error{color:var(--dsw-alias-state-error-primary);font-size:12px}
716
790
  .axds-ok{color:var(--dsw-alias-state-success-primary);font-size:12px}
791
+ /* 状态行换了内容时淡入一下,否则点「刷新」像什么都没发生。 */
792
+ .axds-pending,.axds-ok,.axds-notice,.axds-error{animation:axds-fade .18s ease-out both}
793
+ @keyframes axds-fade{from{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}
794
+ @media (prefers-reduced-motion:reduce){.axds-pending,.axds-ok,.axds-notice,.axds-error{animation:none}}
795
+ .axds-pending{display:flex;align-items:center;gap:8px;color:var(--dsw-alias-label-secondary);font-size:12px}
796
+ .axds-spin{width:14px;height:14px;border-radius:50%;border:2px solid var(--dsw-alias-border-l1);border-top-color:var(--dsw-alias-label-primary);animation:axds-spin .7s linear infinite;flex:none}
797
+ @keyframes axds-spin{to{transform:rotate(360deg)}}
717
798
  .axds-bind{display:flex;gap:8px;align-items:center}
718
799
  /* Input 原子自带边框、圆角与 focus-within;这里只让它占满一行,别再叠一层。 */
719
800
  .axds-input{display:flex;width:100%;box-sizing:border-box;height:36px}
package/lib/index.js CHANGED
@@ -215,8 +215,9 @@ var ROW_ID = "authinex-ds-plugin";
215
215
  var ROW_KEY = `${PACKAGE_NAME}#${ROW_ID}`;
216
216
 
217
217
  // src/controller.ts
218
- var VERSION = true ? "0.1.2" : "0.1.0";
218
+ var VERSION = true ? "0.1.4" : "0.1.0";
219
219
  var CREDENTIAL_REF = "AUTHINEX_DS_DEVICE";
220
+ var NPM_LATEST_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
220
221
  var ALLOWED_DETAILS = /* @__PURE__ */ new Set([
221
222
  "密钥无效",
222
223
  "尝试次数过多,请稍后再试",
@@ -499,17 +500,8 @@ function createController(options) {
499
500
  if (!parsed) {
500
501
  return { ok: false, message: PHRASES.invalid, state: fail("invalid") };
501
502
  }
502
- if (memory.token && memory.phase === "bound" && memory.endpoint === endpoint) {
503
- return { ok: true, state: snapshot() };
504
- }
505
503
  memory.endpoint = endpoint;
506
504
  const existing = await readSecret();
507
- const samePlace = Boolean(existing?.endpoint) && existing?.endpoint === endpoint;
508
- if (samePlace && existing?.privateJwk && existing.deviceId) {
509
- const restored = await restore();
510
- if (memory.token) return { ok: true, state: restored };
511
- memory.endpoint = endpoint;
512
- }
513
505
  memory.phase = "binding";
514
506
  memory.detail = "";
515
507
  const installId = existing?.installId || randomUUID();
@@ -762,11 +754,34 @@ ${description}`;
762
754
  return null;
763
755
  }
764
756
  }
757
+ async function fetchNpmLatest() {
758
+ try {
759
+ const response = await fetchImpl(NPM_LATEST_URL, {
760
+ method: "GET",
761
+ headers: { accept: "application/json" },
762
+ timeout: 1e4
763
+ });
764
+ if (!response.ok) return null;
765
+ const data = JSON.parse(await response.text());
766
+ const found = String(data.version || "").trim();
767
+ if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(found)) return null;
768
+ return {
769
+ version: found,
770
+ sha: "",
771
+ notes: "服务端没有更新清单,按 npm 上的最新版本比较",
772
+ artifact: "",
773
+ size: 0,
774
+ available: versionBelow(version, found)
775
+ };
776
+ } catch {
777
+ return null;
778
+ }
779
+ }
765
780
  async function checkUpdate() {
766
781
  if (memory.busy) return { ok: false, message: BUSY, state: snapshot() };
767
782
  const base = normalizeEndpoint(memory.endpoint);
768
- if (!base) return { ok: false, message: PHRASES.unreachable, state: snapshot() };
769
- const found = await fetchManifest();
783
+ if (!base || !memory.token) return { ok: false, message: PHRASES.unreachable, state: snapshot() };
784
+ const found = await fetchManifest() || await fetchNpmLatest();
770
785
  if (!found) {
771
786
  memory.update = null;
772
787
  return { ok: false, message: "没有查到更新", state: snapshot() };
@@ -774,9 +789,13 @@ ${description}`;
774
789
  memory.update = found;
775
790
  return { ok: true, message: found.available ? `发现新版本 ${found.version}` : "已经是最新版本", state: snapshot() };
776
791
  }
792
+ async function discoverUpdate() {
793
+ if (memory.update?.available) return memory.update;
794
+ return await fetchManifest() || await fetchNpmLatest();
795
+ }
777
796
  async function applyUpdate() {
778
797
  if (memory.busy) return { ok: false, message: BUSY };
779
- const found = memory.update?.available ? memory.update : await fetchManifest();
798
+ const found = await discoverUpdate();
780
799
  if (!found) return { ok: false, message: "没有查到更新" };
781
800
  memory.update = found;
782
801
  if (!found.available) return { ok: false, message: "已经是最新版本" };
@@ -797,10 +816,13 @@ ${description}`;
797
816
  if (memory.busy) return { ok: false, message: BUSY };
798
817
  const base = normalizeEndpoint(memory.endpoint);
799
818
  if (!base || !memory.token) return { ok: false, message: PHRASES.unreachable };
800
- const found = memory.update?.available ? memory.update : await fetchManifest();
819
+ const found = await discoverUpdate();
801
820
  if (!found) return { ok: false, message: "没有查到更新" };
802
821
  memory.update = found;
803
822
  if (!found.available) return { ok: false, message: "已经是最新版本" };
823
+ if (!found.artifact) {
824
+ return { ok: false, message: "这次只查到 npm 上的版本号,没有可下载的更新包,请到插件页更新" };
825
+ }
804
826
  if (!/^authinex-dsh-plugin-[0-9A-Za-z.+-]+\.(tgz|tar\.gz)$/.test(found.artifact)) {
805
827
  return { ok: false, message: "更新包名不合法,已放弃这次更新" };
806
828
  }
@@ -946,7 +968,15 @@ function apply(ctx) {
946
968
  install: async (spec) => {
947
969
  const service = manager();
948
970
  if (!service) throw new Error("没有可用的插件管理器");
949
- const result = await service.installBundle(spec, { enabled: true });
971
+ let result;
972
+ try {
973
+ result = await service.installBundle(spec, { enabled: true });
974
+ } catch (error) {
975
+ if (/already-installed/.test(String(error?.message || error))) {
976
+ throw new Error("这台机器上已经装了这个插件;请在插件页卸载,再安装新版本");
977
+ }
978
+ throw error;
979
+ }
950
980
  if (result?.application === "failed") {
951
981
  throw new Error(result.error?.code || result.packageResult?.kind || "安装失败");
952
982
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authinex/dsh-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "DeepSeek 里的 AuthineX 插件:问知识库、查工单、检索源码、只读定位,并用本人账号建单",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -34,6 +34,7 @@
34
34
  "typecheck": "tsc --noEmit",
35
35
  "test": "tsc --noEmit && node scripts/build.mjs && node --test test/*.test.mjs",
36
36
  "prepublishOnly": "npm test",
37
+ "release": "node scripts/publish.mjs",
37
38
  "preview": "node scripts/preview.mjs"
38
39
  },
39
40
  "publishConfig": {