dsh-plugin-om 0.0.51 → 0.0.52
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 +9 -3
- package/dist/client/OmCompactionCard.d.ts +4 -1
- package/dist/client/OmCompactionCard.d.ts.map +1 -1
- package/dist/client/OmRecompressMenu.d.ts +13 -0
- package/dist/client/OmRecompressMenu.d.ts.map +1 -0
- package/dist/client/definition.d.ts +2 -0
- package/dist/client/definition.d.ts.map +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/locales.d.ts +11 -0
- package/dist/client/locales.d.ts.map +1 -1
- package/dist/client/recompress-inject.d.ts +9 -0
- package/dist/client/recompress-inject.d.ts.map +1 -0
- package/dist/client/recompress-run.d.ts +73 -0
- package/dist/client/recompress-run.d.ts.map +1 -0
- package/dist/client.js +396 -43
- package/dist/client.js.map +1 -1
- package/dist/compaction-log.d.ts +28 -4
- package/dist/compaction-log.d.ts.map +1 -1
- package/dist/compress-loop.d.ts +6 -0
- package/dist/compress-loop.d.ts.map +1 -1
- package/dist/compress.d.ts +7 -3
- package/dist/compress.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/format.d.ts +6 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +290 -57
- package/dist/recall.d.ts.map +1 -1
- package/dist/recompress.d.ts +66 -0
- package/dist/recompress.d.ts.map +1 -0
- package/dist/system-reminder.d.ts +4 -13
- package/dist/system-reminder.d.ts.map +1 -1
- package/dist/types.d.ts +1 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +4 -1
- package/dist/client/format.d.ts +0 -6
- package/dist/client/format.d.ts.map +0 -1
package/dist/client.js
CHANGED
|
@@ -6,6 +6,7 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
7
|
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
8
8
|
let react = require("react");
|
|
9
|
+
let react_dom = require("react-dom");
|
|
9
10
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
11
|
/**
|
|
11
12
|
* 解码一条会话事件为 om 私有事件:仅识别 feedback/record 中带 om 信封前缀的
|
|
@@ -91,7 +92,7 @@ window.__ModuleLoader__.load({
|
|
|
91
92
|
return null;
|
|
92
93
|
}
|
|
93
94
|
/** 从 compaction/summary 载荷提取摘要文本与遮蔽统计(载荷非法时各字段回落 null)。 */
|
|
94
|
-
function compactSummaryData(summaryMatch, endMatch) {
|
|
95
|
+
function compactSummaryData(compactionId, summaryMatch, endMatch) {
|
|
95
96
|
let summary = null;
|
|
96
97
|
let shadowedItemCount = null;
|
|
97
98
|
let shadowedTokenCount = null;
|
|
@@ -107,6 +108,7 @@ window.__ModuleLoader__.load({
|
|
|
107
108
|
shadowedCharCount = data.shadowedCharCount !== void 0 && Number.isSafeInteger(data.shadowedCharCount) && data.shadowedCharCount >= 0 ? data.shadowedCharCount : null;
|
|
108
109
|
}
|
|
109
110
|
return {
|
|
111
|
+
compactionId,
|
|
110
112
|
running: false,
|
|
111
113
|
phase: null,
|
|
112
114
|
error: null,
|
|
@@ -126,8 +128,9 @@ window.__ModuleLoader__.load({
|
|
|
126
128
|
return data?.phase === "observe" || data?.phase === "reflect" ? data.phase : null;
|
|
127
129
|
}
|
|
128
130
|
/** 压缩进行中提示行的载荷(统计未就绪,全部为 null)。 */
|
|
129
|
-
function runningData(start) {
|
|
131
|
+
function runningData(compactionId, start) {
|
|
130
132
|
return {
|
|
133
|
+
compactionId,
|
|
131
134
|
running: true,
|
|
132
135
|
phase: startPhase(start),
|
|
133
136
|
error: null,
|
|
@@ -146,9 +149,10 @@ window.__ModuleLoader__.load({
|
|
|
146
149
|
* error 取 compaction/end 载荷中的实际报错文案(非字符串或为空时回落 null);
|
|
147
150
|
* 摘要与统计字段全部为 null。
|
|
148
151
|
*/
|
|
149
|
-
function failureData(start, end) {
|
|
152
|
+
function failureData(compactionId, start, end) {
|
|
150
153
|
const data = end.event.data;
|
|
151
154
|
return {
|
|
155
|
+
compactionId,
|
|
152
156
|
running: false,
|
|
153
157
|
phase: startPhase(start),
|
|
154
158
|
error: typeof data?.error === "string" && data.error !== "" ? data.error : null,
|
|
@@ -231,16 +235,16 @@ window.__ModuleLoader__.load({
|
|
|
231
235
|
buildViewNode: (context) => {
|
|
232
236
|
const state = context.state ?? fallbackState(context);
|
|
233
237
|
if (state.checkpoint !== void 0) {
|
|
234
|
-
const data = compactSummaryData(state.summary, state.end);
|
|
238
|
+
const data = compactSummaryData(context.id, state.summary, state.end);
|
|
235
239
|
return chatNode(context, COMPACTION_CARD_KIND, state.checkpoint.event.seq, data);
|
|
236
240
|
}
|
|
237
241
|
if (state.end !== void 0) {
|
|
238
242
|
const anchorSeq = context.start?.event.seq ?? state.end.event.seq;
|
|
239
243
|
const endData = state.end.event.data;
|
|
240
|
-
if (typeof endData?.error === "string" && endData.error !== "" && !endData.error.startsWith("压缩已中止(signal aborted)")) return chatNode(context, COMPACTION_CARD_KIND, anchorSeq, failureData(context.start, state.end));
|
|
241
|
-
return chatNode(context, COMPACTION_CARD_KIND, anchorSeq, runningData(context.start), "hidden");
|
|
244
|
+
if (typeof endData?.error === "string" && endData.error !== "" && !endData.error.startsWith("压缩已中止(signal aborted)")) return chatNode(context, COMPACTION_CARD_KIND, anchorSeq, failureData(context.id, context.start, state.end));
|
|
245
|
+
return chatNode(context, COMPACTION_CARD_KIND, anchorSeq, runningData(context.id, context.start), "hidden");
|
|
242
246
|
}
|
|
243
|
-
if (context.start !== void 0) return chatNode(context, COMPACTION_CARD_KIND, context.start.event.seq, runningData(context.start));
|
|
247
|
+
if (context.start !== void 0) return chatNode(context, COMPACTION_CARD_KIND, context.start.event.seq, runningData(context.id, context.start));
|
|
244
248
|
return null;
|
|
245
249
|
}
|
|
246
250
|
};
|
|
@@ -298,6 +302,17 @@ window.__ModuleLoader__.load({
|
|
|
298
302
|
"compaction.failed.reflect": "上下文压缩失败(反思)",
|
|
299
303
|
"card.inspect": "诊断日志",
|
|
300
304
|
"card.trajectory": "轨迹",
|
|
305
|
+
"recompress.action": "尝试其他模型",
|
|
306
|
+
"recompress.running": "重压缩中…",
|
|
307
|
+
"recompress.started": "压缩开始,完成后会添加至“子智能体”",
|
|
308
|
+
"recompress.search": "搜索模型",
|
|
309
|
+
"recompress.loading": "正在加载模型…",
|
|
310
|
+
"recompress.empty": "没有可用模型",
|
|
311
|
+
"recompress.loadFailed": "模型列表加载失败",
|
|
312
|
+
"recompress.retry": "重试",
|
|
313
|
+
"recompress.effort.default": "模型默认",
|
|
314
|
+
"recompress.done": "重压缩完成,会话记录已写入日志",
|
|
315
|
+
"recompress.failed": "重压缩失败:{error}",
|
|
301
316
|
warning: "上下文压缩功能降级",
|
|
302
317
|
"config.description": "配置上下文压缩与原文召回。",
|
|
303
318
|
"config.loading": "正在加载配置…",
|
|
@@ -355,6 +370,17 @@ window.__ModuleLoader__.load({
|
|
|
355
370
|
"compaction.failed.reflect": "Context compaction failed (reflection)",
|
|
356
371
|
"card.inspect": "Diagnostic log",
|
|
357
372
|
"card.trajectory": "Trajectory",
|
|
373
|
+
"recompress.action": "Try another model",
|
|
374
|
+
"recompress.running": "Recompressing…",
|
|
375
|
+
"recompress.started": "Compression started; it will be added to “Subagents” when done",
|
|
376
|
+
"recompress.search": "Search models",
|
|
377
|
+
"recompress.loading": "Loading models…",
|
|
378
|
+
"recompress.empty": "No models available",
|
|
379
|
+
"recompress.loadFailed": "Failed to load models",
|
|
380
|
+
"recompress.retry": "Retry",
|
|
381
|
+
"recompress.effort.default": "Model default",
|
|
382
|
+
"recompress.done": "Recompression finished; the session record is in the log",
|
|
383
|
+
"recompress.failed": "Recompression failed: {error}",
|
|
358
384
|
warning: "Context compaction degraded",
|
|
359
385
|
"config.description": "Configure context compaction and original-text recall.",
|
|
360
386
|
"config.loading": "Loading configuration…",
|
|
@@ -398,9 +424,9 @@ window.__ModuleLoader__.load({
|
|
|
398
424
|
"config.debug.hint": "Log processing steps; the default follows NODE_ENV."
|
|
399
425
|
};
|
|
400
426
|
//#endregion
|
|
401
|
-
//#region src/
|
|
427
|
+
//#region src/format.ts
|
|
402
428
|
/**
|
|
403
|
-
*
|
|
429
|
+
* 紧凑数字格式化(压缩卡片、重压缩记录与压缩日志共用)。零依赖,服务端与浏览器均可引用。导出 formatCompactCount。
|
|
404
430
|
* <1k 原样;≥1k 用 k;≥1w(万)用 w;≥1M 用 M;保留 1 位小数并去掉末尾 .0。
|
|
405
431
|
*/
|
|
406
432
|
function formatCompactCount(value) {
|
|
@@ -414,6 +440,237 @@ window.__ModuleLoader__.load({
|
|
|
414
440
|
return String(value);
|
|
415
441
|
}
|
|
416
442
|
//#endregion
|
|
443
|
+
//#region src/client/OmRecompressMenu.tsx
|
|
444
|
+
/**
|
|
445
|
+
* 换模型重压缩的模型选择菜单:触发按钮 + 浮层。
|
|
446
|
+
* 数据来自宿主会话共享的模型目录(与 /model 弹窗同一份:按供应商分组、模型的思考等级
|
|
447
|
+
* 元数据),搜索排序复用宿主 rankByName,浮层材质复用 MenuSurface / MenuGroup。
|
|
448
|
+
* 选中模型后若该模型带思考等级则进入等级列表(含「模型默认」),再提交;
|
|
449
|
+
* 选择只触发 onPick,不改变会话自身所选模型。
|
|
450
|
+
* 导出 OmRecompressMenu。
|
|
451
|
+
*/
|
|
452
|
+
/** 超过该模型数才显示搜索框。 */
|
|
453
|
+
const SEARCH_MIN_MODELS = 5;
|
|
454
|
+
const css$1 = {
|
|
455
|
+
button: "om-recompress-button",
|
|
456
|
+
panel: "om-recompress-panel",
|
|
457
|
+
search: "om-recompress-search",
|
|
458
|
+
list: "om-recompress-list",
|
|
459
|
+
row: "om-recompress-row",
|
|
460
|
+
note: "om-recompress-note"
|
|
461
|
+
};
|
|
462
|
+
const menuCss = `
|
|
463
|
+
.${css$1.button}{border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:16px;cursor:pointer;white-space:nowrap;border-radius:999px;flex:none;align-items:center;gap:4px;margin:0;padding:2px 8px;display:inline-flex}
|
|
464
|
+
.${css$1.button}:is(:hover,:focus-visible):not(:disabled){background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}
|
|
465
|
+
.${css$1.button}:disabled{cursor:default;opacity:.6}
|
|
466
|
+
.${css$1.panel}{position:fixed;z-index:1000;box-sizing:border-box;width:260px;max-height:320px;display:flex;flex-direction:column;overflow:hidden}
|
|
467
|
+
.${css$1.search}{box-sizing:border-box;width:100%;margin:0;padding:8px 12px;font:inherit;font-size:13px;color:inherit;background:none;border:none;border-bottom:1px solid var(--dsw-alias-label-caption);outline:none}
|
|
468
|
+
.${css$1.list}{min-height:0;overflow-y:auto;padding:4px}
|
|
469
|
+
.${css$1.row}{box-sizing:border-box;width:100%;display:block;text-align:left;font:inherit;font-size:13px;line-height:20px;color:inherit;background:none;border:none;border-radius:6px;padding:4px 8px;cursor:pointer}
|
|
470
|
+
.${css$1.row}:hover,.${css$1.row}:focus-visible{background:var(--dsw-alias-bg-hover,transparent);outline:none}
|
|
471
|
+
.${css$1.note}{padding:8px 12px;font-size:13px;color:var(--dsw-alias-label-tertiary)}
|
|
472
|
+
`;
|
|
473
|
+
/** 注册菜单样式(无 document 的环境如 node 测试直接跳过)。 */
|
|
474
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-dsh-plugin-om-recompress]") === null) {
|
|
475
|
+
const tag = document.createElement("style");
|
|
476
|
+
tag.dataset.dshPluginOmRecompress = "true";
|
|
477
|
+
tag.textContent = menuCss;
|
|
478
|
+
document.head.appendChild(tag);
|
|
479
|
+
}
|
|
480
|
+
/** 触发按钮与模型选择浮层。 */
|
|
481
|
+
function OmRecompressMenu({ source, t, disabled, onPick }) {
|
|
482
|
+
const state = (0, react.useSyncExternalStore)((listener) => source.directory.subscribe(listener), () => source.directory.getSnapshot());
|
|
483
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
484
|
+
const [query, setQuery] = (0, react.useState)("");
|
|
485
|
+
const [picked, setPicked] = (0, react.useState)(null);
|
|
486
|
+
const [position, setPosition] = (0, react.useState)(null);
|
|
487
|
+
const triggerRef = (0, react.useRef)(null);
|
|
488
|
+
const panelRef = (0, react.useRef)(null);
|
|
489
|
+
const showSearch = state.groups.reduce((sum, group) => sum + group.models.length, 0) >= SEARCH_MIN_MODELS;
|
|
490
|
+
const groups = (0, react.useMemo)(() => {
|
|
491
|
+
const text = showSearch ? query.trim() : "";
|
|
492
|
+
return state.groups.map((group) => ({
|
|
493
|
+
...group,
|
|
494
|
+
models: (0, _deepseek_ai_dsh_client_ui_primitives.rankByName)(group.models, text)
|
|
495
|
+
})).filter((group) => group.models.length > 0);
|
|
496
|
+
}, [
|
|
497
|
+
state.groups,
|
|
498
|
+
query,
|
|
499
|
+
showSearch
|
|
500
|
+
]);
|
|
501
|
+
const close = (0, react.useCallback)(() => {
|
|
502
|
+
setOpen(false);
|
|
503
|
+
setPicked(null);
|
|
504
|
+
setQuery("");
|
|
505
|
+
}, []);
|
|
506
|
+
(0, react.useEffect)(() => {
|
|
507
|
+
if (!open) return;
|
|
508
|
+
const outside = (event) => {
|
|
509
|
+
const target = event.target;
|
|
510
|
+
if (triggerRef.current?.contains(target) === true) return;
|
|
511
|
+
if (panelRef.current?.contains(target) === true) return;
|
|
512
|
+
close();
|
|
513
|
+
};
|
|
514
|
+
const onKey = (event) => {
|
|
515
|
+
if (event.key === "Escape") close();
|
|
516
|
+
};
|
|
517
|
+
document.addEventListener("mousedown", outside);
|
|
518
|
+
document.addEventListener("keydown", onKey);
|
|
519
|
+
return () => {
|
|
520
|
+
document.removeEventListener("mousedown", outside);
|
|
521
|
+
document.removeEventListener("keydown", onKey);
|
|
522
|
+
};
|
|
523
|
+
}, [open, close]);
|
|
524
|
+
(0, react.useLayoutEffect)(() => {
|
|
525
|
+
if (!open) {
|
|
526
|
+
setPosition(null);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const place = () => {
|
|
530
|
+
const rect = triggerRef.current?.getBoundingClientRect();
|
|
531
|
+
if (rect === void 0) return;
|
|
532
|
+
const margin = 12;
|
|
533
|
+
const width = panelRef.current?.offsetWidth ?? 260;
|
|
534
|
+
const height = panelRef.current?.offsetHeight ?? 0;
|
|
535
|
+
const left = Math.min(Math.max(rect.right - width, margin), window.innerWidth - width - margin);
|
|
536
|
+
const below = rect.bottom + 4;
|
|
537
|
+
const top = below + height <= window.innerHeight - margin ? below : Math.max(margin, rect.top - 4 - height);
|
|
538
|
+
setPosition({
|
|
539
|
+
left,
|
|
540
|
+
top
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
place();
|
|
544
|
+
window.addEventListener("scroll", place, true);
|
|
545
|
+
window.addEventListener("resize", place);
|
|
546
|
+
return () => {
|
|
547
|
+
window.removeEventListener("scroll", place, true);
|
|
548
|
+
window.removeEventListener("resize", place);
|
|
549
|
+
};
|
|
550
|
+
}, [
|
|
551
|
+
open,
|
|
552
|
+
state,
|
|
553
|
+
query,
|
|
554
|
+
picked
|
|
555
|
+
]);
|
|
556
|
+
const choose = (provider, model) => {
|
|
557
|
+
if (model.reasoning === void 0 || model.reasoning.efforts.length === 0) {
|
|
558
|
+
close();
|
|
559
|
+
onPick({
|
|
560
|
+
provider,
|
|
561
|
+
model: model.id
|
|
562
|
+
});
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
setPicked({
|
|
566
|
+
provider,
|
|
567
|
+
model
|
|
568
|
+
});
|
|
569
|
+
};
|
|
570
|
+
const finish = (effort) => {
|
|
571
|
+
if (picked === null) return;
|
|
572
|
+
const choice = {
|
|
573
|
+
provider: picked.provider,
|
|
574
|
+
model: picked.model.id,
|
|
575
|
+
...effort === void 0 ? {} : { reasoningEffort: effort }
|
|
576
|
+
};
|
|
577
|
+
close();
|
|
578
|
+
onPick(choice);
|
|
579
|
+
};
|
|
580
|
+
let body;
|
|
581
|
+
if (picked !== null) body = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
582
|
+
className: css$1.list,
|
|
583
|
+
children: [
|
|
584
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
585
|
+
type: "button",
|
|
586
|
+
className: css$1.row,
|
|
587
|
+
"data-om-recompress-back": true,
|
|
588
|
+
onClick: () => setPicked(null),
|
|
589
|
+
children: ["← ", picked.model.name]
|
|
590
|
+
}),
|
|
591
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
592
|
+
type: "button",
|
|
593
|
+
className: css$1.row,
|
|
594
|
+
"data-om-recompress-effort": "",
|
|
595
|
+
onClick: () => finish(void 0),
|
|
596
|
+
children: t("recompress.effort.default")
|
|
597
|
+
}),
|
|
598
|
+
picked.model.reasoning?.efforts.map((effort) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
599
|
+
type: "button",
|
|
600
|
+
className: css$1.row,
|
|
601
|
+
"data-om-recompress-effort": effort.id,
|
|
602
|
+
onClick: () => finish(effort.id),
|
|
603
|
+
children: effort.name
|
|
604
|
+
}, effort.id))
|
|
605
|
+
]
|
|
606
|
+
});
|
|
607
|
+
else if (state.status === "error" && state.groups.length === 0) body = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
608
|
+
className: css$1.note,
|
|
609
|
+
children: [
|
|
610
|
+
state.error ?? t("recompress.loadFailed"),
|
|
611
|
+
" ",
|
|
612
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
613
|
+
type: "button",
|
|
614
|
+
className: css$1.row,
|
|
615
|
+
"data-om-recompress-retry": true,
|
|
616
|
+
onClick: () => source.load(),
|
|
617
|
+
children: t("recompress.retry")
|
|
618
|
+
})
|
|
619
|
+
]
|
|
620
|
+
});
|
|
621
|
+
else if (state.groups.length === 0) body = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
622
|
+
className: css$1.note,
|
|
623
|
+
children: state.status === "ready" ? t("recompress.empty") : t("recompress.loading")
|
|
624
|
+
});
|
|
625
|
+
else body = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [showSearch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
626
|
+
className: css$1.search,
|
|
627
|
+
"data-om-recompress-search": true,
|
|
628
|
+
value: query,
|
|
629
|
+
placeholder: t("recompress.search"),
|
|
630
|
+
onChange: (event) => setQuery(event.target.value),
|
|
631
|
+
autoFocus: true
|
|
632
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
633
|
+
className: css$1.list,
|
|
634
|
+
children: groups.map((group) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MenuGroup, {
|
|
635
|
+
label: group.name,
|
|
636
|
+
children: group.models.map((model) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
637
|
+
type: "button",
|
|
638
|
+
className: css$1.row,
|
|
639
|
+
"data-om-recompress-model": `${group.id}/${model.id}`,
|
|
640
|
+
onClick: () => choose(group.id, model),
|
|
641
|
+
children: model.name
|
|
642
|
+
}, model.id))
|
|
643
|
+
}, group.id))
|
|
644
|
+
})] });
|
|
645
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
646
|
+
ref: triggerRef,
|
|
647
|
+
type: "button",
|
|
648
|
+
className: css$1.button,
|
|
649
|
+
"data-om-recompress": true,
|
|
650
|
+
disabled,
|
|
651
|
+
onClick: (event) => {
|
|
652
|
+
event.stopPropagation();
|
|
653
|
+
if (open) {
|
|
654
|
+
close();
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
source.load();
|
|
658
|
+
setOpen(true);
|
|
659
|
+
},
|
|
660
|
+
children: disabled ? t("recompress.running") : t("recompress.action")
|
|
661
|
+
}), open && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MenuSurface, {
|
|
662
|
+
ref: panelRef,
|
|
663
|
+
className: css$1.panel,
|
|
664
|
+
role: "menu",
|
|
665
|
+
style: position ?? {
|
|
666
|
+
visibility: "hidden",
|
|
667
|
+
left: 0,
|
|
668
|
+
top: 0
|
|
669
|
+
},
|
|
670
|
+
children: body
|
|
671
|
+
}), document.body)] });
|
|
672
|
+
}
|
|
673
|
+
//#endregion
|
|
417
674
|
//#region src/client/OmCompactionCard.tsx
|
|
418
675
|
/** 卡片样式类名(与宿主 ContextInjectionRow.module.css 同款规则,增加水平滚动支持)。 */
|
|
419
676
|
const css = {
|
|
@@ -425,6 +682,7 @@ window.__ModuleLoader__.load({
|
|
|
425
682
|
body: "om-compaction-body",
|
|
426
683
|
actions: "om-compaction-actions",
|
|
427
684
|
inspect: "om-compaction-inspect",
|
|
685
|
+
result: "om-compaction-recompress-result",
|
|
428
686
|
trajectory: "om-compaction-trajectory"
|
|
429
687
|
};
|
|
430
688
|
/** 卡片样式规则:保留宿主外观,对折叠摘要与展开体增加水平滚动适配。 */
|
|
@@ -440,6 +698,7 @@ window.__ModuleLoader__.load({
|
|
|
440
698
|
.${css.inspect}{border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:16px;cursor:pointer;white-space:nowrap;border-radius:999px;flex:none;align-items:center;gap:4px;margin:0;padding:2px 8px;display:inline-flex}
|
|
441
699
|
.${css.inspect}:is(:hover,:focus-visible){background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}
|
|
442
700
|
.${css.trajectory}{display:none}
|
|
701
|
+
.${css.result}{padding:2px 0 0 22px;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary);max-height:60px;overflow-y:auto;overflow-wrap:anywhere;overscroll-behavior:contain;scrollbar-width:thin}
|
|
443
702
|
.${css.body}{box-sizing:border-box;background:var(--dsw-alias-markdown-code-block);width:calc(100% - 22px);max-height:141px;color:var(--dsw-alias-label-tertiary);font:400 11px/16px var(--ds-font-family-code);border:none;border-radius:8px;margin:4px 0 0 22px;padding:10px 16px 12px 12px;overflow-x:auto;overflow-y:auto;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;scrollbar-width:thin}
|
|
444
703
|
`;
|
|
445
704
|
/** 注册卡片样式(无 document 的环境如 node 测试直接跳过)。 */
|
|
@@ -450,8 +709,10 @@ window.__ModuleLoader__.load({
|
|
|
450
709
|
document.head.appendChild(tag);
|
|
451
710
|
}
|
|
452
711
|
/** 折叠式压缩卡片(统计标题行 + 代码块样式 summary 展开)。 */
|
|
453
|
-
const OmCompactionCard = (0, react.memo)(function OmCompactionCard({ node, t, sessionId, openSession, inspectCall }) {
|
|
712
|
+
const OmCompactionCard = (0, react.memo)(function OmCompactionCard({ node, t, sessionId, openSession, recompress, inspectCall }) {
|
|
454
713
|
const [expanded, setExpanded] = (0, react.useState)(false);
|
|
714
|
+
const [recompressState, setRecompressState] = (0, react.useState)({ status: "idle" });
|
|
715
|
+
const [startedToast, setStartedToast] = (0, react.useState)(0);
|
|
455
716
|
const { data } = node;
|
|
456
717
|
const diagnosticSessionId = data.diagnosticSessionId;
|
|
457
718
|
const inspect = diagnosticSessionId !== null && sessionId !== void 0 && openSession !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
@@ -468,6 +729,31 @@ window.__ModuleLoader__.load({
|
|
|
468
729
|
},
|
|
469
730
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconInspectOutlineRegular, { size: 12 }), t("card.inspect")]
|
|
470
731
|
}) : null;
|
|
732
|
+
const pickRecompress = (choice) => {
|
|
733
|
+
if (recompress === void 0) return;
|
|
734
|
+
setRecompressState({ status: "running" });
|
|
735
|
+
setStartedToast((seq) => seq + 1);
|
|
736
|
+
recompress.run(data.compactionId, choice).then((outcome) => {
|
|
737
|
+
setRecompressState(outcome.ok ? {
|
|
738
|
+
status: "done",
|
|
739
|
+
text: outcome.text || t("recompress.done")
|
|
740
|
+
} : {
|
|
741
|
+
status: "failed",
|
|
742
|
+
text: t("recompress.failed", { error: outcome.text })
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
const recompressButton = recompress === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OmRecompressMenu, {
|
|
747
|
+
source: recompress,
|
|
748
|
+
t,
|
|
749
|
+
disabled: recompressState.status === "running",
|
|
750
|
+
onPick: pickRecompress
|
|
751
|
+
});
|
|
752
|
+
const recompressResult = recompressState.status === "done" || recompressState.status === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
753
|
+
className: css.result,
|
|
754
|
+
"data-om-recompress-result": true,
|
|
755
|
+
children: recompressState.text
|
|
756
|
+
}) : null;
|
|
471
757
|
const trajectory = inspectCall === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
472
758
|
type: "button",
|
|
473
759
|
className: `${css.inspect} ${css.trajectory}`,
|
|
@@ -478,11 +764,17 @@ window.__ModuleLoader__.load({
|
|
|
478
764
|
},
|
|
479
765
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconInspectOutlineRegular, { size: 12 }), t("card.trajectory")]
|
|
480
766
|
});
|
|
481
|
-
const
|
|
767
|
+
const actionBar = (extra) => inspect === null && extra === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
482
768
|
className: css.actions,
|
|
483
769
|
"data-om-compaction-actions": true,
|
|
484
|
-
children: [
|
|
770
|
+
children: [
|
|
771
|
+
trajectory,
|
|
772
|
+
inspect,
|
|
773
|
+
extra
|
|
774
|
+
]
|
|
485
775
|
});
|
|
776
|
+
const failureActions = actionBar(null);
|
|
777
|
+
const actions = actionBar(recompressButton);
|
|
486
778
|
if (data.running) {
|
|
487
779
|
const runningLabel = data.phase === "observe" ? t("compaction.running.observe") : data.phase === "reflect" ? t("compaction.running.reflect") : t("compaction.running");
|
|
488
780
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -525,7 +817,7 @@ window.__ModuleLoader__.load({
|
|
|
525
817
|
className: css.body,
|
|
526
818
|
style: styles$1.body,
|
|
527
819
|
children: data.error
|
|
528
|
-
}),
|
|
820
|
+
}), failureActions]
|
|
529
821
|
})
|
|
530
822
|
});
|
|
531
823
|
}
|
|
@@ -541,34 +833,45 @@ window.__ModuleLoader__.load({
|
|
|
541
833
|
items: formatCompactCount(data.shadowedItemCount),
|
|
542
834
|
tokens: formatCompactCount(data.shadowedTokenCount)
|
|
543
835
|
}) : data.summary !== null ? t("compaction.expand") : t("compaction.unavailable");
|
|
544
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
836
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
545
837
|
style: styles$1.row,
|
|
546
|
-
children:
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
838
|
+
children: [
|
|
839
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.DisclosureRow, {
|
|
840
|
+
className: css.root,
|
|
841
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconBrowseOutlineRegular, { size: 14 }),
|
|
842
|
+
chevronClassName: css.chevron,
|
|
843
|
+
title: t("compaction"),
|
|
844
|
+
collapsedContent: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
845
|
+
className: css.sep,
|
|
846
|
+
"aria-hidden": true
|
|
847
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
848
|
+
className: `${css.summary} ${css.scrollable}`,
|
|
849
|
+
"data-om-compaction-summary": true,
|
|
850
|
+
children: stats
|
|
851
|
+
})] }),
|
|
852
|
+
keepContentWhenOpen: true,
|
|
853
|
+
expandable,
|
|
854
|
+
expandOnRowClick: true,
|
|
855
|
+
open,
|
|
856
|
+
onToggle: () => {
|
|
857
|
+
setExpanded((value) => !value);
|
|
858
|
+
},
|
|
859
|
+
children: [data.summary !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
860
|
+
className: css.body,
|
|
861
|
+
style: styles$1.body,
|
|
862
|
+
children: data.summary
|
|
863
|
+
}), actions]
|
|
864
|
+
}),
|
|
865
|
+
recompressResult,
|
|
866
|
+
startedToast > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
|
|
867
|
+
tone: "success",
|
|
868
|
+
text: t("recompress.started"),
|
|
869
|
+
holdMs: 4e3,
|
|
870
|
+
onDone: () => {
|
|
871
|
+
setStartedToast(0);
|
|
872
|
+
}
|
|
873
|
+
}, startedToast)
|
|
874
|
+
]
|
|
572
875
|
});
|
|
573
876
|
});
|
|
574
877
|
const styles$1 = {
|
|
@@ -891,6 +1194,50 @@ window.__ModuleLoader__.load({
|
|
|
891
1194
|
});
|
|
892
1195
|
const bodyStyle = { whiteSpace: "pre-wrap" };
|
|
893
1196
|
//#endregion
|
|
1197
|
+
//#region src/client/recompress-run.ts
|
|
1198
|
+
/** 拼出命令行:/om-recompress <compactionId> <provider> <model> [effort]。 */
|
|
1199
|
+
function recompressLine(compactionId, choice) {
|
|
1200
|
+
const effort = choice.reasoningEffort === void 0 ? "" : ` ${choice.reasoningEffort}`;
|
|
1201
|
+
return `/om-recompress ${compactionId} ${choice.provider} ${choice.model}${effort}`;
|
|
1202
|
+
}
|
|
1203
|
+
/** 经命令通道提交一次重压缩;远程拒绝或抛错都归一为失败结果。 */
|
|
1204
|
+
async function submitRecompress(execute, sessionId, compactionId, choice) {
|
|
1205
|
+
try {
|
|
1206
|
+
const result = await execute(sessionId, recompressLine(compactionId, choice));
|
|
1207
|
+
if (!result.ok) return {
|
|
1208
|
+
ok: false,
|
|
1209
|
+
text: result.error.message
|
|
1210
|
+
};
|
|
1211
|
+
const { kind, text } = result.value.result;
|
|
1212
|
+
return {
|
|
1213
|
+
ok: kind === "success",
|
|
1214
|
+
text: text ?? ""
|
|
1215
|
+
};
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
return {
|
|
1218
|
+
ok: false,
|
|
1219
|
+
text: error instanceof Error ? error.message : String(error)
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
//#endregion
|
|
1224
|
+
//#region src/client/recompress-inject.ts
|
|
1225
|
+
/** 构造某会话的重压缩能力:目录与 /model 弹窗共用,提交走 command.execute。 */
|
|
1226
|
+
function recompressFor(ctx, directories, sessionId) {
|
|
1227
|
+
const directory = directories.directoryFor(sessionId);
|
|
1228
|
+
return {
|
|
1229
|
+
directory: directory.store,
|
|
1230
|
+
load: () => {
|
|
1231
|
+
directory.load();
|
|
1232
|
+
},
|
|
1233
|
+
run: (compactionId, choice) => submitRecompress(async (id, line) => {
|
|
1234
|
+
const commands = ctx.get("remote.commands");
|
|
1235
|
+
if (commands === void 0) throw new Error("remote.commands unavailable");
|
|
1236
|
+
return commands.execute(id, line, []);
|
|
1237
|
+
}, sessionId, compactionId, choice)
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
//#endregion
|
|
894
1241
|
//#region src/client/index.ts
|
|
895
1242
|
/** 必需服务:聊天节点槽、会话定义、双语 locale、宿主配置表单与会话跳转。 */
|
|
896
1243
|
const inject = [
|
|
@@ -912,9 +1259,15 @@ window.__ModuleLoader__.load({
|
|
|
912
1259
|
name: "conversation.chat.node",
|
|
913
1260
|
key: "om-compaction",
|
|
914
1261
|
locale: NS,
|
|
915
|
-
inject: () =>
|
|
916
|
-
ctx.
|
|
917
|
-
|
|
1262
|
+
inject: (sessionId) => {
|
|
1263
|
+
const directories = ctx.get("modelDirectories");
|
|
1264
|
+
return {
|
|
1265
|
+
openSession: (target) => {
|
|
1266
|
+
ctx.uiWorkspace.openSession(target);
|
|
1267
|
+
},
|
|
1268
|
+
...directories === void 0 ? {} : { recompress: recompressFor(ctx, directories, sessionId) }
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
918
1271
|
}, OmCompactionCard));
|
|
919
1272
|
ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
|
|
920
1273
|
name: "conversation.chat.node",
|