dsh-plugin-model-tuning 3.0.1 → 3.1.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 (3) hide show
  1. package/README.md +1 -1
  2. package/client.js +43 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  > **v3 边界收缩(2026-10,基线 dsh 0.2.1-rc.1)**:v2 合并进来的「标题生成路由」交还官方 `session-title-llm` 行,「模型参数」页交还官方 Models 页。官方已经能做的,本插件不再复制;官方没有的,见下面两节。重叠盘点记录见 [docs/PLUGIN-SCOPE-dsh-0.2.1-rc.1.md](../docs/PLUGIN-SCOPE-dsh-0.2.1-rc.1.md)。
9
9
 
10
- > 兼容性:`engines.dsh` = `>=0.2.0-rc.2 <0.3.0-0`,已在 dsh 0.2.1-rc.3 上实测运行。
10
+ > 兼容性:`engines.dsh` = `>=0.2.0-rc.2 <0.3.0-0`,已在 dsh 0.2.1-rc.3 上实测运行。3.1.0 起模型目录优先读 `models.catalog` 命名空间(dsh 0.2.3-alpha.3 起从 session 迁移),回落 `session.modelCatalog`,新旧运行时通用。
11
11
 
12
12
  ## 1. 兼容与推理(官方 Models 页扩展)
13
13
 
package/client.js CHANGED
@@ -937,11 +937,38 @@ window.__ModuleLoader__.load({
937
937
  };
938
938
  const call = async (method, args) => unwrap(await ctx.connection.rpc.call("/api", `imageGeneration/${method}`, { args }));
939
939
 
940
+ /**
941
+ * The deployment model catalog. DSH 0.2.3-alpha.3 moved it out of the
942
+ * session namespace into `models` (the models-remote upgrade guide);
943
+ * older runtimes answer `session.modelCatalog` instead. `remote.models`
944
+ * is deliberately NOT in `inject`: declaring a namespace that some
945
+ * supported runtimes never register would keep this fiber PENDING
946
+ * forever there, so detect the shape at call time instead — by then the
947
+ * mux connection has long been up and every installed namespace is
948
+ * reachable through `ctx.remote`.
949
+ */
950
+ async function readModelCatalog() {
951
+ let models;
952
+ try {
953
+ models = remote.models;
954
+ } catch {
955
+ models = undefined; /* the namespace is absent on older runtimes */
956
+ }
957
+ if (models !== undefined && models !== null && typeof models.catalog === "function") {
958
+ return unwrap(await models.catalog());
959
+ }
960
+ const session = remote.session;
961
+ if (session !== undefined && session !== null && typeof session.modelCatalog === "function") {
962
+ return unwrap(await session.modelCatalog());
963
+ }
964
+ throw new Error("模型目录服务不可用:当前运行时既没有 remote.models.catalog,也没有 remote.session.modelCatalog");
965
+ }
966
+
940
967
  /** Provider metadata, its settings section and the model catalog, read together. */
941
968
  async function compatSnapshot(providerId) {
942
969
  const [providers, catalog, settings] = await Promise.all([
943
970
  unwrap(await remote.llm.listConfigurableProviders()),
944
- unwrap(await remote.session.modelCatalog()),
971
+ readModelCatalog(),
945
972
  unwrap(await remote.settings.describe()),
946
973
  ]);
947
974
  const entry = providers.find((item) => item && item.provider === providerId);
@@ -1004,7 +1031,6 @@ window.__ModuleLoader__.load({
1004
1031
  async function saveCompat(providerId, modelId, kind, value) {
1005
1032
  const snapshot = await compatSnapshot(providerId);
1006
1033
  const entry = snapshot.entry;
1007
- const nsView = snapshot.nsView;
1008
1034
  if (kind === "imageLink") {
1009
1035
  // The drawing list lives in this plugin's own namespace; re-read it
1010
1036
  // right before writing so the plan and its revision come from one
@@ -1024,24 +1050,35 @@ window.__ModuleLoader__.load({
1024
1050
  if (!response.ok) throw new Error(response.error && response.error.message ? response.error.message : "保存失败");
1025
1051
  return;
1026
1052
  }
1053
+ // Re-read the provider namespace right before writing: the plan and the
1054
+ // revision it is applied against must come from the same document, or a
1055
+ // concurrent write is either refused as stale or silently overwritten
1056
+ // (the same discipline the drawing page's commit() uses).
1057
+ const freshSettings = unwrap(await remote.settings.describe());
1058
+ const freshNamespaces = Array.isArray(freshSettings.namespaces) ? freshSettings.namespaces : [];
1059
+ const freshNs = freshNamespaces.find((item) => item && item.ns === entry.settingsNs);
1060
+ if (!freshNs) throw new Error("该 provider 的设置命名空间未激活,无法保存");
1027
1061
  let write;
1028
1062
  if (kind === "supportsDeveloperRole" || kind === "adaptiveThinking") {
1029
1063
  if (value !== null && typeof value !== "boolean") throw new Error("取值必须是布尔值");
1030
1064
  const compatKey = kind === "supportsDeveloperRole" ? "supportsDeveloperRole" : snapshot.adaptiveKey;
1031
1065
  if (compatKey === null || compatKey === undefined) throw new Error("该路由不是 anthropic-messages,不能设置思考格式");
1032
- write = computeCompatWriteOps(entry, nsView, modelId, compatKey, value);
1066
+ write = computeCompatWriteOps(entry, freshNs, modelId, compatKey, value);
1033
1067
  } else if (kind === "reasoningLevels") {
1034
1068
  const levels = Array.isArray(value) ? value : [];
1035
1069
  for (const level of levels) {
1036
1070
  if (REASONING_LEVELS.indexOf(level) < 0) throw new Error("未知的推理档位:" + level);
1037
1071
  }
1038
- const payload = reasoningEffortsPayload(levels, storedReasoningEfforts(entry, nsView, modelId));
1039
- write = computeWriteOps(entry, nsView, modelId, "reasoningEfforts", payload);
1072
+ const payload = reasoningEffortsPayload(levels, storedReasoningEfforts(entry, freshNs, modelId));
1073
+ write = computeWriteOps(entry, freshNs, modelId, "reasoningEfforts", payload);
1040
1074
  } else {
1041
1075
  throw new Error("未知的修改类型");
1042
1076
  }
1043
1077
  if (!write) throw new Error("该 provider 不接受这个字段");
1044
- const response = await remote.settings.mutate(write.ns, write.ops);
1078
+ // settings/mutate declares three parameters (ns, ops, expectedRevision);
1079
+ // the client bridge refuses a two-argument call outright, and the
1080
+ // revision is what makes a stale editor fail instead of overwriting.
1081
+ const response = await remote.settings.mutate(write.ns, write.ops, freshNs.revision);
1045
1082
  if (!response.ok) throw new Error(response.error && response.error.message ? response.error.message : "保存失败");
1046
1083
  }
1047
1084
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-model-tuning",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "engines": { "dsh": ">=0.2.0-rc.2 <0.3.0-0" },
5
5
  "license": "MIT",
6
6
  "keywords": ["dsh-plugin", "deepseek-harness", "dsh", "model", "settings", "reasoning", "compat", "image-generation"],