dsh-plugin-om 0.0.42 → 0.0.44

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/dist/client.js CHANGED
@@ -7,21 +7,13 @@ window.__ModuleLoader__.load({
7
7
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
8
8
  let react = require("react");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
- /** 校验载荷字段与类别匹配(运行时守卫,保证返回类型的诚实性)。 */
11
- function isValidPayload(kind, data) {
12
- switch (kind) {
13
- case "om/warning": return typeof data.problem === "string" && typeof data.message === "string";
14
- case "om/observe-pending": return typeof data.triggerMessageIndex === "number" && Number.isSafeInteger(data.triggerMessageIndex);
15
- case "om/observe-invalidate": return typeof data.pendingSeq === "number" && Number.isSafeInteger(data.pendingSeq);
16
- }
17
- }
18
10
  /**
19
11
  * 解码一条会话事件为 om 私有事件:仅识别 feedback/record 中带 om 信封前缀的
20
12
  * text;前缀缺失、JSON 非法、kind 未知或载荷字段缺失时返回 undefined。
21
13
  */
22
14
  function readOmEvent(event) {
23
15
  if (event === void 0 || event === null || event.type !== "feedback/record") return void 0;
24
- const text = event.data?.text;
16
+ const text = event.data.text;
25
17
  if (typeof text !== "string" || !text.startsWith("om:1:")) return void 0;
26
18
  let envelope;
27
19
  try {
@@ -31,19 +23,39 @@ window.__ModuleLoader__.load({
31
23
  }
32
24
  if (envelope === null || typeof envelope !== "object" || Array.isArray(envelope)) return void 0;
33
25
  const { kind, ...rest } = envelope;
34
- if (typeof kind !== "string") return void 0;
35
- if (![
36
- "om/warning",
37
- "om/observe-pending",
38
- "om/observe-invalidate"
39
- ].includes(kind)) return void 0;
40
- const omKind = kind;
41
- if (!isValidPayload(omKind, rest)) return void 0;
42
- return {
43
- kind: omKind,
44
- data: rest,
45
- seq: event.seq
46
- };
26
+ switch (kind) {
27
+ case "om/warning": {
28
+ const { problem, message } = rest;
29
+ if (typeof problem !== "string" || typeof message !== "string") return void 0;
30
+ return {
31
+ kind,
32
+ data: {
33
+ problem,
34
+ message
35
+ },
36
+ seq: event.seq
37
+ };
38
+ }
39
+ case "om/observe-pending": {
40
+ const { triggerMessageIndex } = rest;
41
+ if (typeof triggerMessageIndex !== "number" || !Number.isSafeInteger(triggerMessageIndex)) return void 0;
42
+ return {
43
+ kind,
44
+ data: { triggerMessageIndex },
45
+ seq: event.seq
46
+ };
47
+ }
48
+ case "om/observe-invalidate": {
49
+ const { pendingSeq } = rest;
50
+ if (typeof pendingSeq !== "number" || !Number.isSafeInteger(pendingSeq)) return void 0;
51
+ return {
52
+ kind,
53
+ data: { pendingSeq },
54
+ seq: event.seq
55
+ };
56
+ }
57
+ default: return;
58
+ }
47
59
  }
48
60
  //#endregion
49
61
  //#region src/client/definition.ts
@@ -61,14 +73,14 @@ window.__ModuleLoader__.load({
61
73
  return typeof surfaceOp === "object" && surfaceOp !== null && surfaceOp.op === "replace";
62
74
  }
63
75
  /**
64
- * 从压缩替换检查点(user/message + replace surface + source.plugin 为本插件)读取
76
+ * 从压缩替换检查点(user/message + replace surface + source 为插件自产)读取
65
77
  * 关联 compactionId;其余事件返回 undefined。
66
78
  */
67
79
  function checkpointCompactionId(event) {
68
80
  if (event.type !== "user/message" || !isReplacementSurface(event)) return void 0;
69
81
  const source = event.data.source;
70
- if (source === void 0 || source.kind !== "plugin" || source.plugin !== "dsh-plugin-om" || typeof source.compactionId !== "string") return;
71
- return source.compactionId;
82
+ if (source?.kind !== "plugin:dsh-plugin-om") return void 0;
83
+ return typeof source.compactionId === "string" ? source.compactionId : void 0;
72
84
  }
73
85
  /** 从 compaction/summary 载荷提取摘要文本与遮蔽统计(载荷非法时各字段回落 null)。 */
74
86
  function compactSummaryData(summaryMatch) {
@@ -255,7 +267,7 @@ window.__ModuleLoader__.load({
255
267
  //#endregion
256
268
  //#region src/client/locales.ts
257
269
  /**
258
- * `om-compaction` namespace 字典:插件压缩卡片的界面文案(zh/en)。
270
+ * `om-compaction` namespace 字典:压缩卡片、降级警告与插件行配置页的中英文文案。
259
271
  * 导出 NS / zh / en;zh 为键集事实源,en 键集与 zh 一致。
260
272
  */
261
273
  /** Dictionary namespace owned by this plugin. */
@@ -273,7 +285,48 @@ window.__ModuleLoader__.load({
273
285
  "compaction.failed": "上下文压缩失败",
274
286
  "compaction.failed.observe": "上下文压缩失败(观察)",
275
287
  "compaction.failed.reflect": "上下文压缩失败(反思)",
276
- warning: "上下文压缩功能降级"
288
+ warning: "上下文压缩功能降级",
289
+ "config.description": "配置上下文压缩与原文召回。",
290
+ "config.loading": "正在加载配置…",
291
+ "config.unavailable": "插件当前不可用,无法配置。",
292
+ "config.readOnly": "本部署的配置只读。",
293
+ "config.saveFailed": "保存失败,修改已保留,请检查配置或重试。",
294
+ "config.versionConflict": "配置已被其他页面修改,请重新加载后再保存。",
295
+ "config.save": "保存修改",
296
+ "config.discard": "撤销修改",
297
+ "config.saving": "保存中…",
298
+ "config.overridden": "已覆盖",
299
+ "config.inherited": "继承默认",
300
+ "config.reset": "恢复默认",
301
+ "config.invalidInteger": "请输入整数;留空使用默认值。",
302
+ "config.observeThresholdTokens": "观察阈值",
303
+ "config.observeThresholdTokens.hint": "上下文压力达到此 token 数时触发观察压缩。",
304
+ "config.reflectThresholdTokens": "摘要合并阈值",
305
+ "config.reflectThresholdTokens.hint": "摘要累计达到此 token 数时触发反思合并。",
306
+ "config.tailMessageCount": "保留消息数",
307
+ "config.tailMessageCount.hint": "触发观察后保留的完整消息条数。",
308
+ "config.compressMaxTokens": "单次生成上限",
309
+ "config.compressMaxTokens.hint": "压缩请求的最大生成 token 数;留空使用模型默认值。",
310
+ "config.compressProvider": "压缩 Provider",
311
+ "config.compressProvider.hint": "与压缩模型同时设置;留空使用会话路由。",
312
+ "config.compressModel": "压缩模型",
313
+ "config.compressModel.hint": "与压缩 Provider 同时设置;留空使用会话路由。",
314
+ "config.compressReasoningEffort": "思考等级",
315
+ "config.compressReasoningEffort.hint": "压缩请求的思考等级;留空使用模型默认值。",
316
+ "config.compressSkipReasoning": "忽略思考内容",
317
+ "config.compressSkipReasoning.hint": "压缩时不将历史 reasoning 纳入参考。",
318
+ "config.rateLimitWaitMs": "限流等待毫秒数",
319
+ "config.rateLimitWaitMs.hint": "429 限流后的冷却时间;0 表示不等待。",
320
+ "config.modelDir": "嵌入模型目录",
321
+ "config.modelDir.hint": "本地语义召回使用的嵌入模型目录。",
322
+ "config.omEnabled": "自动压缩",
323
+ "config.omEnabled.hint": "启用观察压缩和摘要反思合并。",
324
+ "config.recallEnabled": "原文召回",
325
+ "config.recallEnabled.hint": "注册按消息序号召回原文的工具。",
326
+ "config.semanticRecallEnabled": "语义召回",
327
+ "config.semanticRecallEnabled.hint": "注册本地语义检索工具。",
328
+ "config.debug": "步骤日志",
329
+ "config.debug.hint": "启用步骤级日志;缺省值由 NODE_ENV 决定。"
277
330
  };
278
331
  /** English dictionary(键集与 zh 一致)。 */
279
332
  const en = {
@@ -288,7 +341,48 @@ window.__ModuleLoader__.load({
288
341
  "compaction.failed": "Context compaction failed",
289
342
  "compaction.failed.observe": "Context compaction failed (observation)",
290
343
  "compaction.failed.reflect": "Context compaction failed (reflection)",
291
- warning: "Context compaction degraded"
344
+ warning: "Context compaction degraded",
345
+ "config.description": "Configure context compaction and original-text recall.",
346
+ "config.loading": "Loading configuration…",
347
+ "config.unavailable": "This plugin is unavailable and cannot be configured.",
348
+ "config.readOnly": "This deployment stores configuration read-only.",
349
+ "config.saveFailed": "Save failed. Your changes are retained; check the values or retry.",
350
+ "config.versionConflict": "Configuration changed elsewhere. Reload before saving again.",
351
+ "config.save": "Save changes",
352
+ "config.discard": "Discard changes",
353
+ "config.saving": "Saving…",
354
+ "config.overridden": "Overridden",
355
+ "config.inherited": "Inherited default",
356
+ "config.reset": "Reset to default",
357
+ "config.invalidInteger": "Enter an integer; leave blank to use the default.",
358
+ "config.observeThresholdTokens": "Observation threshold",
359
+ "config.observeThresholdTokens.hint": "Context pressure in tokens that triggers observation.",
360
+ "config.reflectThresholdTokens": "Reflection threshold",
361
+ "config.reflectThresholdTokens.hint": "Total summary tokens that trigger reflection.",
362
+ "config.tailMessageCount": "Retained message count",
363
+ "config.tailMessageCount.hint": "Full messages retained after observation is triggered.",
364
+ "config.compressMaxTokens": "Generation limit",
365
+ "config.compressMaxTokens.hint": "Maximum generated tokens per compression request; blank uses the model default.",
366
+ "config.compressProvider": "Compression provider",
367
+ "config.compressProvider.hint": "Set with the compression model; blank uses session routing.",
368
+ "config.compressModel": "Compression model",
369
+ "config.compressModel.hint": "Set with the compression provider; blank uses session routing.",
370
+ "config.compressReasoningEffort": "Reasoning effort",
371
+ "config.compressReasoningEffort.hint": "Reasoning effort for compression; blank uses the model default.",
372
+ "config.compressSkipReasoning": "Skip reasoning",
373
+ "config.compressSkipReasoning.hint": "Exclude historical reasoning from compression references.",
374
+ "config.rateLimitWaitMs": "Rate-limit wait in milliseconds",
375
+ "config.rateLimitWaitMs.hint": "Cooldown after a 429 response; zero skips the wait.",
376
+ "config.modelDir": "Embedding model directory",
377
+ "config.modelDir.hint": "Directory containing the local semantic-recall embedding model.",
378
+ "config.omEnabled": "Automatic compaction",
379
+ "config.omEnabled.hint": "Enable observation and reflection of summaries.",
380
+ "config.recallEnabled": "Original-text recall",
381
+ "config.recallEnabled.hint": "Register the message-index recall tool.",
382
+ "config.semanticRecallEnabled": "Semantic recall",
383
+ "config.semanticRecallEnabled.hint": "Register the local semantic-search tool.",
384
+ "config.debug": "Step logs",
385
+ "config.debug.hint": "Log processing steps; the default follows NODE_ENV."
292
386
  };
293
387
  //#endregion
294
388
  //#region src/client/format.ts
@@ -430,6 +524,210 @@ window.__ModuleLoader__.load({
430
524
  body: { whiteSpace: "pre-wrap" }
431
525
  };
432
526
  //#endregion
527
+ //#region src/client/om-config-controller.ts
528
+ /** 由宿主提供的插件条目配置命名空间。 */
529
+ const CONFIG_NS = "dsh-plugin-om";
530
+ /** 完整表单字段及控件类别。 */
531
+ const OM_CONFIG_FIELDS = [
532
+ {
533
+ name: "observeThresholdTokens",
534
+ kind: "integer"
535
+ },
536
+ {
537
+ name: "reflectThresholdTokens",
538
+ kind: "integer"
539
+ },
540
+ {
541
+ name: "tailMessageCount",
542
+ kind: "integer"
543
+ },
544
+ {
545
+ name: "compressMaxTokens",
546
+ kind: "integer"
547
+ },
548
+ {
549
+ name: "compressProvider",
550
+ kind: "text"
551
+ },
552
+ {
553
+ name: "compressModel",
554
+ kind: "text"
555
+ },
556
+ {
557
+ name: "compressReasoningEffort",
558
+ kind: "text"
559
+ },
560
+ {
561
+ name: "compressSkipReasoning",
562
+ kind: "boolean"
563
+ },
564
+ {
565
+ name: "rateLimitWaitMs",
566
+ kind: "integer"
567
+ },
568
+ {
569
+ name: "modelDir",
570
+ kind: "text"
571
+ },
572
+ {
573
+ name: "omEnabled",
574
+ kind: "boolean"
575
+ },
576
+ {
577
+ name: "recallEnabled",
578
+ kind: "boolean"
579
+ },
580
+ {
581
+ name: "semanticRecallEnabled",
582
+ kind: "boolean"
583
+ },
584
+ {
585
+ name: "debug",
586
+ kind: "boolean"
587
+ }
588
+ ];
589
+ /** 数字草稿只接受十进制整数,空白表示清除覆盖。 */
590
+ function integerField(field) {
591
+ return {
592
+ field,
593
+ format: (value) => typeof value === "number" ? String(value) : "",
594
+ parse: (text) => {
595
+ const trimmed = text.trim();
596
+ if (trimmed === "") return { kind: "clear" };
597
+ if (!/^[+-]?\d+$/.test(trimmed)) return void 0;
598
+ const value = Number(trimmed);
599
+ return Number.isInteger(value) ? {
600
+ kind: "set",
601
+ value
602
+ } : void 0;
603
+ }
604
+ };
605
+ }
606
+ /** 布尔草稿只允许 true 和 false,缺省值始终来自宿主快照。 */
607
+ function booleanField(field) {
608
+ return {
609
+ field,
610
+ format: (value) => typeof value === "boolean" ? String(value) : "",
611
+ parse: (text) => text === "true" || text === "false" ? {
612
+ kind: "set",
613
+ value: text === "true"
614
+ } : void 0
615
+ };
616
+ }
617
+ /** 将声明的控件类别映射为表单解析规格。 */
618
+ const specs = OM_CONFIG_FIELDS.map(({ name, kind }) => kind === "integer" ? integerField(name) : kind === "boolean" ? booleanField(name) : (0, _deepseek_ai_dsh_client_ui_primitives.settingsTextField)(name));
619
+ /** 在插件客户端生命周期内托管表单订阅。 */
620
+ var OmConfigController = class {
621
+ scope;
622
+ form;
623
+ store;
624
+ conflict = false;
625
+ constructor(scope) {
626
+ this.scope = scope;
627
+ const guarded = {
628
+ getSnapshot: () => scope.getSnapshot(),
629
+ subscribe: (listener) => scope.subscribe(listener),
630
+ mutate: async (ops, revision) => {
631
+ this.conflict = false;
632
+ const accepted = await scope.mutate(ops, revision);
633
+ this.conflict = !accepted && revision !== void 0 && scope.getSnapshot().revision !== revision;
634
+ return accepted;
635
+ }
636
+ };
637
+ this.form = new _deepseek_ai_dsh_client_ui_primitives.SettingsFormModel(guarded, specs);
638
+ this.store = this.form.bind(() => this.projection());
639
+ }
640
+ /** 从模型投影唯一一份字段及加载状态。 */
641
+ projection() {
642
+ return {
643
+ ...this.form.shell(),
644
+ status: this.scope.getSnapshot().status,
645
+ conflict: this.form.shell().failed && this.conflict,
646
+ fields: Object.fromEntries(OM_CONFIG_FIELDS.map(({ name }) => [name, this.form.field(name)]))
647
+ };
648
+ }
649
+ /** 供行槽注册器向 React 注入表单操作。 */
650
+ inject() {
651
+ return {
652
+ hooks: { omConfigCard: this.store },
653
+ ...this.form.actions()
654
+ };
655
+ }
656
+ /** 释放宿主快照订阅。 */
657
+ dispose() {
658
+ this.form.dispose();
659
+ }
660
+ };
661
+ //#endregion
662
+ //#region src/client/OmConfigCard.tsx
663
+ /** 配置行内容:说明、草稿值及继承/覆盖标记。 */
664
+ function OmConfigCard(props) {
665
+ const { t } = props;
666
+ const state = props.useOmConfigCard((snapshot) => snapshot);
667
+ if (props.view === "summary") return t("config.description");
668
+ if (state.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
669
+ role: "status",
670
+ children: t("config.loading")
671
+ });
672
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.SettingsForm, {
673
+ labels: {
674
+ unavailable: t("config.unavailable"),
675
+ readOnly: t("config.readOnly"),
676
+ saveFailed: state.conflict ? t("config.versionConflict") : t("config.saveFailed"),
677
+ save: t("config.save"),
678
+ saving: t("config.saving")
679
+ },
680
+ state: state.writable ? state : {
681
+ ...state,
682
+ dirty: false
683
+ },
684
+ onSave: props.save,
685
+ onDiscard: props.discard,
686
+ children: [state.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
687
+ type: "button",
688
+ disabled: !state.writable || state.saving,
689
+ onClick: props.discard,
690
+ children: t("config.discard")
691
+ }) : null, OM_CONFIG_FIELDS.map(({ name, kind }) => {
692
+ const field = state.fields[name];
693
+ const label = t(`config.${name}`);
694
+ const hint = t(`config.${name}.hint`);
695
+ const disabled = !state.writable || state.saving;
696
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
697
+ "data-om-field": name,
698
+ children: kind === "boolean" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
699
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
700
+ label,
701
+ checked: field.text === "true",
702
+ disabled,
703
+ onChange: (value) => props.edit(name, String(value))
704
+ }),
705
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: hint }),
706
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: field.overridden ? t("config.overridden") : t("config.inherited") }),
707
+ field.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
708
+ type: "button",
709
+ disabled,
710
+ onClick: () => props.resetField(name),
711
+ children: t("config.reset")
712
+ }) : null
713
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsValueField, {
714
+ id: `plugin-config-om-${name}`,
715
+ label,
716
+ hint,
717
+ overriddenLabel: t("config.overridden"),
718
+ resetLabel: t("config.reset"),
719
+ invalidLabel: t("config.invalidInteger"),
720
+ numeric: kind === "integer",
721
+ disabled,
722
+ ...field,
723
+ onEdit: (text) => props.edit(name, text),
724
+ onReset: () => props.resetField(name)
725
+ }), !field.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("config.inherited") }) : null] })
726
+ }, name);
727
+ })]
728
+ });
729
+ }
730
+ //#endregion
433
731
  //#region src/client/OmWarningCard.tsx
434
732
  /** 折叠式功能降级警告行(降级说明摘要行 + 完整说明展开)。 */
435
733
  const OmWarningCard = (0, react.memo)(function OmWarningCard({ node, t }) {
@@ -467,13 +765,14 @@ window.__ModuleLoader__.load({
467
765
  const bodyStyle = { whiteSpace: "pre-wrap" };
468
766
  //#endregion
469
767
  //#region src/client/index.ts
470
- /** Required services: 聊天节点槽、uiConversation 会话定义注册表与 locale 服务。 */
768
+ /** 必需服务:聊天节点槽、会话定义、双语 locale 与宿主配置表单。 */
471
769
  const inject = [
472
770
  "slots",
473
771
  "uiConversation",
474
- "locale"
772
+ "locale",
773
+ "configForms"
475
774
  ];
476
- /** Client plugin body: 注册压缩卡片的业务定义与 keyed 渲染器(随插件卸载移除)。 */
775
+ /** 挂载压缩卡片、警告行和可配置的插件行。 */
477
776
  function apply(ctx) {
478
777
  ctx.effect(() => ctx.locale.register(NS, {
479
778
  zh,
@@ -491,6 +790,14 @@ window.__ModuleLoader__.load({
491
790
  key: "om-warning",
492
791
  locale: NS
493
792
  }, OmWarningCard));
793
+ const card = new OmConfigController(ctx.configForms.get(CONFIG_NS));
794
+ ctx.effect(() => () => card.dispose(), "dsh-plugin-om: config form subscription");
795
+ ctx.effect(() => ctx.configForms.whileServed([CONFIG_NS], () => ctx.slots.inject("plugins.row.config", () => ctx.slots.register({
796
+ name: "plugins.row.config",
797
+ key: "dsh-plugin-om#dsh-plugin-om",
798
+ locale: NS,
799
+ inject: () => card.inject()
800
+ }, OmConfigCard))), "dsh-plugin-om: row configuration");
494
801
  }
495
802
  //#endregion
496
803
  exports.apply = apply;