@lin0306/dsh-mind 0.1.0 → 0.1.2

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/index.js CHANGED
@@ -5380,7 +5380,8 @@ function savePersonaState(raw, source, now, opts, extra) {
5380
5380
  */
5381
5381
  function stateDir(raw) {
5382
5382
  const trimmed = raw.trim();
5383
- return path.normalize(trimmed !== "" ? trimmed : path.join(dshHome(), "dsh-mind"));
5383
+ const base = trimmed !== "" ? trimmed : path.join(dshHome(), "dsh-mind");
5384
+ return path.normalize(base).replace(/\\/g, "/");
5384
5385
  }
5385
5386
  /** 人设内核文件路径(用户可编辑)。 */
5386
5387
  function personaFile(raw) {
@@ -5903,7 +5904,7 @@ function makeView(state, t) {
5903
5904
  * `init` 就是新会话的起点:从跨会话档案里**接管**人设与长期记忆,
5904
5905
  * 但情感/思想/进度从零开始(它们永远是"这一段对话内"的)。
5905
5906
  */
5906
- function registerProjection(projections, deps) {
5907
+ async function registerProjection(projections, deps) {
5907
5908
  const definition = {
5908
5909
  key: PROJECTION_KEY,
5909
5910
  stateVersion: 3,
@@ -5953,12 +5954,30 @@ function registerProjection(projections, deps) {
5953
5954
  }
5954
5955
  }
5955
5956
  };
5956
- return projections.register(definition);
5957
+ try {
5958
+ return await projections.register(definition);
5959
+ } catch (error) {
5960
+ logger.warn("[dsh-mind] 注册投影失败:面板与注入会没有数据", error);
5961
+ return;
5962
+ }
5957
5963
  }
5958
- /** 从会话上取状态;拿不到就返回 undefined(绝不用空状态掩盖问题)。 */
5959
- function stateOf(projections, session) {
5964
+ /**
5965
+ * 从会话上取状态;拿不到就返回 `undefined`(绝不用空状态掩盖问题)。
5966
+ *
5967
+ * 优先用注册时拿到的**句柄**(DSH 0.2.x 的推荐路径,自己折叠、不打弃用警告);
5968
+ * 句柄不可用(老宿主 / 假宿主)才回落注册表级读取——那条从 0.2.1-rc.2 起已弃用。
5969
+ */
5970
+ function stateOfVia(registration, projections, session) {
5960
5971
  try {
5961
- const value = projections.stateOf(session, PROJECTION_KEY);
5972
+ const handle = registration;
5973
+ if (handle !== void 0 && typeof handle.stateOf === "function") {
5974
+ const value = handle.stateOf(session);
5975
+ if (value === null || value === void 0 || typeof value !== "object") return void 0;
5976
+ return value;
5977
+ }
5978
+ const fallback = projections.stateOf;
5979
+ if (typeof fallback !== "function") return void 0;
5980
+ const value = fallback.call(projections, session, PROJECTION_KEY);
5962
5981
  if (value === null || value === void 0 || typeof value !== "object") return void 0;
5963
5982
  return value;
5964
5983
  } catch (error) {
@@ -5966,6 +5985,14 @@ function stateOf(projections, session) {
5966
5985
  return;
5967
5986
  }
5968
5987
  }
5988
+ /**
5989
+ * 老入口:直接按注册表读。
5990
+ *
5991
+ * @deprecated 用 `stateOfVia(句柄, …)`。这里只为向后兼容而保留。
5992
+ */
5993
+ function stateOf(projections, session) {
5994
+ return stateOfVia(void 0, projections, session);
5995
+ }
5969
5996
  // src/settings-bridge.ts
5970
5997
  /**
5971
5998
  * 设置页的宿主半边:把"心念"的配置接到 DSH 的设置服务上,再开一条受围栏的路由给客户端读写。
@@ -7209,7 +7236,7 @@ function globalOnly(memory) {
7209
7236
  * @param ctx 插件作用域(root)。每-agent 的东西一律在 `agent/created` 里用 `agent.ctx` 注册。
7210
7237
  * @param config patch 里给的配置(可能是 `{}`、可能缺键,按默认补齐)
7211
7238
  */
7212
- function apply(ctx, config) {
7239
+ async function apply(ctx, config) {
7213
7240
  const now0 = Date.now();
7214
7241
  const enabled = flag(config, "enabled");
7215
7242
  const tunables = toTunables(config);
@@ -7331,7 +7358,7 @@ function apply(ctx, config) {
7331
7358
  return state;
7332
7359
  }
7333
7360
  };
7334
- registerProjection(projections, {
7361
+ const registration = await registerProjection(projections, {
7335
7362
  tunables: () => tunables,
7336
7363
  adoptPersist,
7337
7364
  note: (message) => logger.info(message),
@@ -7362,7 +7389,7 @@ function apply(ctx, config) {
7362
7389
  };
7363
7390
  }
7364
7391
  });
7365
- const stateOfSession = (session) => stateOf(projections, session);
7392
+ const stateOfSession = (session) => stateOfVia(registration, projections, session);
7366
7393
  const systemPrompt = service(ctx, "systemPrompt");
7367
7394
  if (systemPrompt !== void 0 && enabled) {
7368
7395
  if (flag(config, "injectRealtime")) registerRealtimeContext(systemPrompt, {