@agent_memory/dsh 0.5.0 → 0.5.1

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/client/client.js CHANGED
@@ -588,6 +588,8 @@ function MemoryPage() {
588
588
  const [tagDraft, setTagDraft] = React2.useState("");
589
589
  const [relationTarget, setRelationTarget] = React2.useState("");
590
590
  const [relationType, setRelationType] = React2.useState("relates_to");
591
+ const [updateInfo, setUpdateInfo] = React2.useState(null);
592
+ const [updateBusy, setUpdateBusy] = React2.useState(false);
591
593
  React2.useEffect(() => {
592
594
  persistTheme(theme);
593
595
  }, [theme]);
@@ -705,6 +707,29 @@ function MemoryPage() {
705
707
  fetch("/api/agent-memory/rules", { headers: { accept: "application/json" } }).then((response) => response.json()).then((data2) => setRulesText(data2.text || "")).catch(() => setNotice("读取规则失败"));
706
708
  fetch("/api/agent-memory/soul-path", { headers: { accept: "application/json" } }).then((response) => response.json()).then((data2) => setSoulPath(data2)).catch(() => setSoulPath(null));
707
709
  };
710
+ const checkUpdate = () => {
711
+ setUpdateBusy(true);
712
+ setUpdateInfo({ checking: true });
713
+ fetch("/api/agent-memory/update/check", { headers: { accept: "application/json" } }).then(async (response) => {
714
+ const data2 = await response.json();
715
+ if (!response.ok) throw new Error(data2.error || `HTTP ${response.status}`);
716
+ return data2;
717
+ }).then((data2) => setUpdateInfo(data2)).catch((error) => setUpdateInfo({ error: String(error) })).finally(() => setUpdateBusy(false));
718
+ };
719
+ const applyUpdate = () => {
720
+ if (updateInfo === null || typeof updateInfo.latest !== "string") return;
721
+ setUpdateBusy(true);
722
+ setUpdateInfo((previous) => ({ ...previous || {}, applying: true }));
723
+ fetch("/api/agent-memory/update/apply", {
724
+ method: "POST",
725
+ headers: { accept: "application/json", "content-type": "application/json" },
726
+ body: JSON.stringify({ version: updateInfo.latest })
727
+ }).then(async (response) => {
728
+ const data2 = await response.json();
729
+ if (!response.ok || data2.ok === false) throw new Error(data2.error || `HTTP ${response.status}`);
730
+ return data2;
731
+ }).then((data2) => setUpdateInfo((previous) => ({ ...previous || {}, applied: data2 }))).catch((error) => setUpdateInfo((previous) => ({ ...previous || {}, applyError: String(error) }))).finally(() => setUpdateBusy(false));
732
+ };
708
733
  const openCreate = (kind) => {
709
734
  setPanel("create");
710
735
  setCreateKind(kind);
@@ -1640,6 +1665,22 @@ ${lines.join("\n")}`);
1640
1665
  ),
1641
1666
  React2.createElement("p", { style: styles.small }, soulPath.hint)
1642
1667
  ),
1668
+ React2.createElement("h2", { style: styles.groupTitle }, "插件更新"),
1669
+ React2.createElement(
1670
+ "div",
1671
+ { style: styles.actions },
1672
+ React2.createElement(
1673
+ AmButton,
1674
+ { variant: "ghost", disabled: updateBusy, onClick: checkUpdate },
1675
+ "检查更新"
1676
+ ),
1677
+ updateInfo !== null && updateInfo.update_available === true ? React2.createElement(
1678
+ AmButton,
1679
+ { variant: "primary", disabled: updateBusy, onClick: applyUpdate },
1680
+ `升级到 ${updateInfo.latest}`
1681
+ ) : null
1682
+ ),
1683
+ updateInfo === null ? React2.createElement("p", { style: styles.small }, "不会自动联网;点一下才会检查。") : updateInfo.checking === true ? React2.createElement("p", { style: styles.small }, "正在检查…") : updateInfo.error !== void 0 ? React2.createElement("p", { style: styles.small }, `检查失败:${updateInfo.error}`) : updateInfo.applied !== void 0 ? React2.createElement("p", { style: styles.small }, "新版本已安装,请完整重启 DSH 后生效。") : updateInfo.applyError !== void 0 ? React2.createElement("p", { style: styles.small }, `升级失败:${updateInfo.applyError}`) : updateInfo.applying === true ? React2.createElement("p", { style: styles.small }, "正在安装…") : updateInfo.update_available === true ? React2.createElement("p", { style: styles.small }, `当前 ${updateInfo.current},最新 ${updateInfo.latest}。`) : React2.createElement("p", { style: styles.small }, `已是最新版本(${updateInfo.current})。`),
1643
1684
  React2.createElement("button", { style: { ...styles.button, marginTop: "12px" }, onClick: () => setPanel(null) }, "返回列表")
1644
1685
  ) : null,
1645
1686
  panel !== null ? null : React2.createElement(
package/dist/plugin.mjs CHANGED
@@ -6524,6 +6524,31 @@ function guiRoutes(deps) {
6524
6524
  }
6525
6525
  }
6526
6526
  };
6527
+ const updateCheck = {
6528
+ path: "/api/agent-memory/update/check",
6529
+ methods: ["GET"],
6530
+ requestBody: "buffered",
6531
+ fetch: async () => {
6532
+ if (deps.update === void 0) return errorResponse("update service unavailable", 503);
6533
+ try {
6534
+ return json(await deps.update.check());
6535
+ } catch (error) {
6536
+ return errorResponse(error instanceof Error ? error.message : String(error), 502);
6537
+ }
6538
+ }
6539
+ };
6540
+ const updateApply = {
6541
+ path: "/api/agent-memory/update/apply",
6542
+ methods: ["POST"],
6543
+ requestBody: "buffered",
6544
+ fetch: async (request) => {
6545
+ if (deps.update === void 0) return errorResponse("update service unavailable", 503);
6546
+ const body = await readJson(request);
6547
+ const version = typeof body.version === "string" ? body.version : "";
6548
+ const result = await deps.update.apply(version);
6549
+ return json(result, result.ok ? 200 : 409);
6550
+ }
6551
+ };
6527
6552
  return [
6528
6553
  status,
6529
6554
  list,
@@ -6544,7 +6569,9 @@ function guiRoutes(deps) {
6544
6569
  soulPathRoute,
6545
6570
  sealRoute,
6546
6571
  profileRoute,
6547
- rulesRoute
6572
+ rulesRoute,
6573
+ updateCheck,
6574
+ updateApply
6548
6575
  ];
6549
6576
  }
6550
6577
  function registerGuiRoutes(connection, deps, effect) {
@@ -6556,6 +6583,80 @@ function registerGuiRoutes(connection, deps, effect) {
6556
6583
  else install();
6557
6584
  }
6558
6585
 
6586
+ // packages/dsh/src/update.ts
6587
+ var PLUGIN_VERSION = "0.5.1";
6588
+ var PACKAGE_NAME = "@agent_memory/dsh";
6589
+ var REGISTRY_LATEST = [
6590
+ "https://registry.npmjs.org/@agent_memory%2Fdsh/latest",
6591
+ "https://registry.npmmirror.com/@agent_memory%2Fdsh/latest"
6592
+ ];
6593
+ function compareVersions(left, right) {
6594
+ const parse = (value) => {
6595
+ const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(value);
6596
+ return match === null ? [0, 0, 0] : [Number(match[1]), Number(match[2]), Number(match[3])];
6597
+ };
6598
+ const a = parse(left);
6599
+ const b = parse(right);
6600
+ for (let index = 0; index < 3; index += 1) {
6601
+ if (a[index] !== b[index]) return a[index] > b[index] ? 1 : -1;
6602
+ }
6603
+ return 0;
6604
+ }
6605
+ function createUpdateService(manager, fetcher = fetch) {
6606
+ return {
6607
+ async check() {
6608
+ let lastError;
6609
+ for (const endpoint of REGISTRY_LATEST) {
6610
+ try {
6611
+ const response = await fetcher(endpoint, {
6612
+ headers: { accept: "application/json" },
6613
+ signal: AbortSignal.timeout(8e3)
6614
+ });
6615
+ if (!response.ok) throw new Error(`registry returned HTTP ${response.status}`);
6616
+ const body = await response.json();
6617
+ if (typeof body.version !== "string" || !/^\d+\.\d+\.\d+/.test(body.version)) {
6618
+ throw new Error("registry response has no valid version");
6619
+ }
6620
+ return {
6621
+ current: PLUGIN_VERSION,
6622
+ latest: body.version,
6623
+ update_available: compareVersions(body.version, PLUGIN_VERSION) > 0,
6624
+ ...typeof body.dist?.tarball === "string" ? { tarball: body.dist.tarball } : {}
6625
+ };
6626
+ } catch (error) {
6627
+ lastError = error;
6628
+ }
6629
+ }
6630
+ throw lastError instanceof Error ? lastError : new Error(String(lastError));
6631
+ },
6632
+ async apply(version) {
6633
+ if (!/^\d+\.\d+\.\d+$/.test(version) || compareVersions(version, PLUGIN_VERSION) <= 0) {
6634
+ return { ok: false, version, restart_required: false, error: "invalid upgrade version" };
6635
+ }
6636
+ if (manager === void 0) {
6637
+ return {
6638
+ ok: false,
6639
+ version,
6640
+ restart_required: false,
6641
+ manual: true,
6642
+ error: "\u5BBF\u4E3B\u672A\u63D0\u4F9B\u63D2\u4EF6\u7BA1\u7406\u670D\u52A1\uFF0C\u8BF7\u5728 \u8BBE\u7F6E \u2192 \u63D2\u4EF6 \u4E2D\u66F4\u65B0"
6643
+ };
6644
+ }
6645
+ try {
6646
+ const result = await manager.installBundle(`${PACKAGE_NAME}@${version}`, { enabled: true });
6647
+ return { ok: true, version, restart_required: true, result };
6648
+ } catch (error) {
6649
+ return {
6650
+ ok: false,
6651
+ version,
6652
+ restart_required: false,
6653
+ error: error instanceof Error ? error.message : String(error)
6654
+ };
6655
+ }
6656
+ }
6657
+ };
6658
+ }
6659
+
6559
6660
  // packages/dsh/src/service.ts
6560
6661
  function speakerOf(type) {
6561
6662
  if (type.startsWith("assistant")) return "assistant";
@@ -6874,9 +6975,12 @@ function apply(ctx) {
6874
6975
  const effectful = ctx;
6875
6976
  const effect = (install, label) => typeof effectful.effect === "function" ? effectful.effect(install, label) : install();
6876
6977
  const installRoutes = (connection) => {
6978
+ const update = createUpdateService(
6979
+ service(ctx, "pluginManager")
6980
+ );
6877
6981
  registerGuiRoutes(
6878
6982
  connection,
6879
- { store: host.store, home, mode: host.mode, modules: moduleHealth, config: host.runtime.config },
6983
+ { store: host.store, home, mode: host.mode, modules: moduleHealth, config: host.runtime.config, update },
6880
6984
  effect
6881
6985
  );
6882
6986
  try {