dsh-plugin-om 0.0.50 → 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 +14 -6
- package/dist/client/OmCompactionCard.d.ts +12 -5
- 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 +13 -1
- 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 +426 -60
- 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-tools.d.ts +2 -2
- package/dist/compress-tools.d.ts.map +1 -1
- package/dist/compress-view.d.ts +6 -8
- package/dist/compress-view.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 +3 -5
- 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 +354 -152
- package/dist/log-index.d.ts +2 -2
- package/dist/log-index.d.ts.map +1 -1
- package/dist/recall-xml.d.ts +0 -1
- package/dist/recall-xml.d.ts.map +1 -1
- 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 +5 -14
- package/dist/system-reminder.d.ts.map +1 -1
- package/dist/types.d.ts +7 -12
- 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
|
};
|
|
@@ -296,7 +300,19 @@ window.__ModuleLoader__.load({
|
|
|
296
300
|
"compaction.failed": "上下文压缩失败",
|
|
297
301
|
"compaction.failed.observe": "上下文压缩失败(观察)",
|
|
298
302
|
"compaction.failed.reflect": "上下文压缩失败(反思)",
|
|
299
|
-
"card.inspect": "
|
|
303
|
+
"card.inspect": "诊断日志",
|
|
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}",
|
|
300
316
|
warning: "上下文压缩功能降级",
|
|
301
317
|
"config.description": "配置上下文压缩与原文召回。",
|
|
302
318
|
"config.loading": "正在加载配置…",
|
|
@@ -352,7 +368,19 @@ window.__ModuleLoader__.load({
|
|
|
352
368
|
"compaction.failed": "Context compaction failed",
|
|
353
369
|
"compaction.failed.observe": "Context compaction failed (observation)",
|
|
354
370
|
"compaction.failed.reflect": "Context compaction failed (reflection)",
|
|
355
|
-
"card.inspect": "
|
|
371
|
+
"card.inspect": "Diagnostic log",
|
|
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}",
|
|
356
384
|
warning: "Context compaction degraded",
|
|
357
385
|
"config.description": "Configure context compaction and original-text recall.",
|
|
358
386
|
"config.loading": "Loading configuration…",
|
|
@@ -396,9 +424,9 @@ window.__ModuleLoader__.load({
|
|
|
396
424
|
"config.debug.hint": "Log processing steps; the default follows NODE_ENV."
|
|
397
425
|
};
|
|
398
426
|
//#endregion
|
|
399
|
-
//#region src/
|
|
427
|
+
//#region src/format.ts
|
|
400
428
|
/**
|
|
401
|
-
*
|
|
429
|
+
* 紧凑数字格式化(压缩卡片、重压缩记录与压缩日志共用)。零依赖,服务端与浏览器均可引用。导出 formatCompactCount。
|
|
402
430
|
* <1k 原样;≥1k 用 k;≥1w(万)用 w;≥1M 用 M;保留 1 位小数并去掉末尾 .0。
|
|
403
431
|
*/
|
|
404
432
|
function formatCompactCount(value) {
|
|
@@ -412,6 +440,237 @@ window.__ModuleLoader__.load({
|
|
|
412
440
|
return String(value);
|
|
413
441
|
}
|
|
414
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
|
|
415
674
|
//#region src/client/OmCompactionCard.tsx
|
|
416
675
|
/** 卡片样式类名(与宿主 ContextInjectionRow.module.css 同款规则,增加水平滚动支持)。 */
|
|
417
676
|
const css = {
|
|
@@ -421,7 +680,10 @@ window.__ModuleLoader__.load({
|
|
|
421
680
|
summary: "om-compaction-summary",
|
|
422
681
|
scrollable: "om-compaction-scrollable",
|
|
423
682
|
body: "om-compaction-body",
|
|
424
|
-
|
|
683
|
+
actions: "om-compaction-actions",
|
|
684
|
+
inspect: "om-compaction-inspect",
|
|
685
|
+
result: "om-compaction-recompress-result",
|
|
686
|
+
trajectory: "om-compaction-trajectory"
|
|
425
687
|
};
|
|
426
688
|
/** 卡片样式规则:保留宿主外观,对折叠摘要与展开体增加水平滚动适配。 */
|
|
427
689
|
const cardCss = `
|
|
@@ -432,8 +694,11 @@ window.__ModuleLoader__.load({
|
|
|
432
694
|
.${css.summary}{min-width:0;color:var(--dsw-alias-label-tertiary);text-overflow:ellipsis;white-space:nowrap;flex:auto;font-size:14px;line-height:24px;overflow:hidden}
|
|
433
695
|
.${css.summary}.${css.scrollable}{overflow-x:auto;overflow-y:hidden;text-overflow:clip;scrollbar-width:none;-webkit-overflow-scrolling:touch}
|
|
434
696
|
.${css.summary}.${css.scrollable}::-webkit-scrollbar{display:none}
|
|
435
|
-
.${css.
|
|
436
|
-
.${css.inspect}
|
|
697
|
+
.${css.actions}{flex-wrap:wrap;align-items:center;gap:8px;margin:4px 0 2px 22px;display:flex}
|
|
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}
|
|
699
|
+
.${css.inspect}:is(:hover,:focus-visible){background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}
|
|
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}
|
|
437
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}
|
|
438
703
|
`;
|
|
439
704
|
/** 注册卡片样式(无 document 的环境如 node 测试直接跳过)。 */
|
|
@@ -444,8 +709,10 @@ window.__ModuleLoader__.load({
|
|
|
444
709
|
document.head.appendChild(tag);
|
|
445
710
|
}
|
|
446
711
|
/** 折叠式压缩卡片(统计标题行 + 代码块样式 summary 展开)。 */
|
|
447
|
-
const OmCompactionCard = (0, react.memo)(function OmCompactionCard({ node, t, sessionId, openSession }) {
|
|
712
|
+
const OmCompactionCard = (0, react.memo)(function OmCompactionCard({ node, t, sessionId, openSession, recompress, inspectCall }) {
|
|
448
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);
|
|
449
716
|
const { data } = node;
|
|
450
717
|
const diagnosticSessionId = data.diagnosticSessionId;
|
|
451
718
|
const inspect = diagnosticSessionId !== null && sessionId !== void 0 && openSession !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
@@ -462,6 +729,52 @@ window.__ModuleLoader__.load({
|
|
|
462
729
|
},
|
|
463
730
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconInspectOutlineRegular, { size: 12 }), t("card.inspect")]
|
|
464
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;
|
|
757
|
+
const trajectory = inspectCall === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
758
|
+
type: "button",
|
|
759
|
+
className: `${css.inspect} ${css.trajectory}`,
|
|
760
|
+
"data-om-compaction-trajectory": true,
|
|
761
|
+
onClick: (event) => {
|
|
762
|
+
event.stopPropagation();
|
|
763
|
+
inspectCall(node.key);
|
|
764
|
+
},
|
|
765
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconInspectOutlineRegular, { size: 12 }), t("card.trajectory")]
|
|
766
|
+
});
|
|
767
|
+
const actionBar = (extra) => inspect === null && extra === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
768
|
+
className: css.actions,
|
|
769
|
+
"data-om-compaction-actions": true,
|
|
770
|
+
children: [
|
|
771
|
+
trajectory,
|
|
772
|
+
inspect,
|
|
773
|
+
extra
|
|
774
|
+
]
|
|
775
|
+
});
|
|
776
|
+
const failureActions = actionBar(null);
|
|
777
|
+
const actions = actionBar(recompressButton);
|
|
465
778
|
if (data.running) {
|
|
466
779
|
const runningLabel = data.phase === "observe" ? t("compaction.running.observe") : data.phase === "reflect" ? t("compaction.running.reflect") : t("compaction.running");
|
|
467
780
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -481,22 +794,18 @@ window.__ModuleLoader__.load({
|
|
|
481
794
|
const errorSummary = data.error.length > 80 ? `${data.error.slice(0, 80)}…` : data.error;
|
|
482
795
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
483
796
|
style: styles$1.row,
|
|
484
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.
|
|
797
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.DisclosureRow, {
|
|
485
798
|
className: css.root,
|
|
486
799
|
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconBrowseOutlineRegular, { size: 14 }),
|
|
487
800
|
chevronClassName: css.chevron,
|
|
488
801
|
title: failedLabel,
|
|
489
|
-
collapsedContent: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
children: errorSummary
|
|
497
|
-
}),
|
|
498
|
-
inspect
|
|
499
|
-
] }),
|
|
802
|
+
collapsedContent: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
803
|
+
className: css.sep,
|
|
804
|
+
"aria-hidden": true
|
|
805
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
806
|
+
className: `${css.summary} ${css.scrollable}`,
|
|
807
|
+
children: errorSummary
|
|
808
|
+
})] }),
|
|
500
809
|
keepContentWhenOpen: true,
|
|
501
810
|
expandable: true,
|
|
502
811
|
expandOnRowClick: true,
|
|
@@ -504,15 +813,15 @@ window.__ModuleLoader__.load({
|
|
|
504
813
|
onToggle: () => {
|
|
505
814
|
setExpanded((value) => !value);
|
|
506
815
|
},
|
|
507
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
816
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
508
817
|
className: css.body,
|
|
509
818
|
style: styles$1.body,
|
|
510
819
|
children: data.error
|
|
511
|
-
})
|
|
820
|
+
}), failureActions]
|
|
512
821
|
})
|
|
513
822
|
});
|
|
514
823
|
}
|
|
515
|
-
const expandable = data.summary !== null;
|
|
824
|
+
const expandable = data.summary !== null || actions !== null;
|
|
516
825
|
const open = expandable && expanded;
|
|
517
826
|
const stats = data.shadowedItemCount !== null && data.shadowedCharCount !== null && data.shadowedTokenCount !== null && data.summaryCharCount !== null && data.summaryTokenCount !== null ? t("compaction.stats", {
|
|
518
827
|
items: formatCompactCount(data.shadowedItemCount),
|
|
@@ -523,39 +832,46 @@ window.__ModuleLoader__.load({
|
|
|
523
832
|
}) : data.shadowedItemCount !== null && data.shadowedTokenCount !== null ? t("compaction.completed", {
|
|
524
833
|
items: formatCompactCount(data.shadowedItemCount),
|
|
525
834
|
tokens: formatCompactCount(data.shadowedTokenCount)
|
|
526
|
-
}) :
|
|
527
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
835
|
+
}) : data.summary !== null ? t("compaction.expand") : t("compaction.unavailable");
|
|
836
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
528
837
|
style: styles$1.row,
|
|
529
|
-
children:
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
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", {
|
|
536
845
|
className: css.sep,
|
|
537
846
|
"aria-hidden": true
|
|
538
|
-
}),
|
|
539
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
847
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
540
848
|
className: `${css.summary} ${css.scrollable}`,
|
|
541
849
|
"data-om-compaction-summary": true,
|
|
542
850
|
children: stats
|
|
543
|
-
}),
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
+
]
|
|
559
875
|
});
|
|
560
876
|
});
|
|
561
877
|
const styles$1 = {
|
|
@@ -878,6 +1194,50 @@ window.__ModuleLoader__.load({
|
|
|
878
1194
|
});
|
|
879
1195
|
const bodyStyle = { whiteSpace: "pre-wrap" };
|
|
880
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
|
|
881
1241
|
//#region src/client/index.ts
|
|
882
1242
|
/** 必需服务:聊天节点槽、会话定义、双语 locale、宿主配置表单与会话跳转。 */
|
|
883
1243
|
const inject = [
|
|
@@ -899,9 +1259,15 @@ window.__ModuleLoader__.load({
|
|
|
899
1259
|
name: "conversation.chat.node",
|
|
900
1260
|
key: "om-compaction",
|
|
901
1261
|
locale: NS,
|
|
902
|
-
inject: () =>
|
|
903
|
-
ctx.
|
|
904
|
-
|
|
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
|
+
}
|
|
905
1271
|
}, OmCompactionCard));
|
|
906
1272
|
ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
|
|
907
1273
|
name: "conversation.chat.node",
|