dsh-compaction-weave 0.0.0-stage → 0.3.3
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/CHANGELOG.md +97 -0
- package/LICENSE +21 -0
- package/README.en.md +136 -0
- package/README.md +139 -2
- package/cordis.patch.yml +19 -0
- package/docs/architecture.md +84 -0
- package/docs/benchmarks/published-0.3.2-rc.1-tests.json +576 -0
- package/docs/benchmarks/rc2-documentation.json +41 -0
- package/docs/benchmarks/rc2-linux-tests.json +590 -0
- package/docs/benchmarks/rc2-live-and-cost.json +746 -0
- package/docs/benchmarks/rc3-host-compatibility.json +2314 -0
- package/docs/benchmarks/rc4-tests.json +617 -0
- package/docs/benchmarks/review35-compression.json +117 -0
- package/docs/benchmarks/v0.3.2-live-four-way.json +3495 -0
- package/docs/benchmarks/v0.3.2-tests.json +590 -0
- package/docs/configuration.md +131 -0
- package/docs/development.md +88 -0
- package/docs/en/architecture.md +75 -0
- package/docs/en/configuration.md +131 -0
- package/docs/en/development.md +86 -0
- package/docs/en/feedback.md +47 -0
- package/docs/en/principles.md +235 -0
- package/docs/en/testing.md +368 -0
- package/docs/en/troubleshooting.md +59 -0
- package/docs/feedback.md +47 -0
- package/docs/images/principles-context.en.svg +77 -0
- package/docs/images/principles-context.zh.svg +77 -0
- package/docs/images/principles-pipeline.en.svg +93 -0
- package/docs/images/principles-pipeline.zh.svg +93 -0
- package/docs/images/principles-recovery.en.svg +46 -0
- package/docs/images/principles-recovery.zh.svg +46 -0
- package/docs/principles.md +235 -0
- package/docs/test-results.json +634 -0
- package/docs/testing.md +358 -0
- package/docs/troubleshooting.md +59 -0
- package/lib/abort.js +13 -0
- package/lib/action-state.js +60 -0
- package/lib/atomic-replace.js +18 -0
- package/lib/attachments.js +76 -0
- package/lib/audit-reject.js +161 -0
- package/lib/audit.js +939 -0
- package/lib/cache-policy.js +71 -0
- package/lib/client.js +696 -0
- package/lib/command-compact.js +38 -0
- package/lib/command-heartbeat.js +61 -0
- package/lib/config.js +596 -0
- package/lib/constraint-scope.js +37 -0
- package/lib/continuation-budget.js +69 -0
- package/lib/continuation-pending.js +57 -0
- package/lib/continuation-progress.js +46 -0
- package/lib/continuation.js +287 -0
- package/lib/engine-entry.js +103 -0
- package/lib/engine.js +2485 -0
- package/lib/failure-diagnostics.js +220 -0
- package/lib/history-source.js +74 -0
- package/lib/history.js +712 -0
- package/lib/idle-compaction.js +64 -0
- package/lib/index.js +611 -0
- package/lib/instruction-source.js +163 -0
- package/lib/journal.js +164 -0
- package/lib/manual-error.js +179 -0
- package/lib/memory-policy.js +383 -0
- package/lib/meter.js +387 -0
- package/lib/observation-mask.js +390 -0
- package/lib/proactive.js +108 -0
- package/lib/progress-facts.js +347 -0
- package/lib/progress-state.js +30 -0
- package/lib/prompt.js +194 -0
- package/lib/reconstruct.js +72 -0
- package/lib/reference-input.js +107 -0
- package/lib/region.js +972 -0
- package/lib/source-provenance.js +58 -0
- package/lib/source-recovery.js +22 -0
- package/lib/source-refs.js +137 -0
- package/lib/state.js +46 -0
- package/lib/storage-path.js +42 -0
- package/lib/summary-budget.js +187 -0
- package/lib/summary-config.js +308 -0
- package/lib/summary-progress.js +56 -0
- package/lib/summary-retry.js +27 -0
- package/lib/summary-timeout.js +68 -0
- package/lib/summary.js +476 -0
- package/lib/tools.js +341 -0
- package/lib/transaction-host.js +252 -0
- package/lib/transaction.js +285 -0
- package/lib/validate.js +503 -0
- package/lib/version.js +3 -0
- package/lib/window.js +120 -0
- package/lib/work-report.js +55 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +71 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client half of dsh-compaction-weave: one Settings page section that lets the
|
|
3
|
+
* user choose the model used to write compaction summaries.
|
|
4
|
+
*
|
|
5
|
+
* Contract notes:
|
|
6
|
+
* - Only `react` is required. Requiring any Harness Client package would make a
|
|
7
|
+
* throwing component blank the whole settings panel.
|
|
8
|
+
* - No document.body writes; all listeners/registrations go through ctx.effect
|
|
9
|
+
* or the slot disposer.
|
|
10
|
+
* - The page is a settings.section contribution, so it appears in the Settings
|
|
11
|
+
* navigation as its own page (id `compaction-weave-summary`).
|
|
12
|
+
*/
|
|
13
|
+
window.__ModuleLoader__.load({
|
|
14
|
+
id: 'dsh-compaction-weave',
|
|
15
|
+
factory(require) {
|
|
16
|
+
const React = require('react');
|
|
17
|
+
const h = React.createElement;
|
|
18
|
+
|
|
19
|
+
const NS = 'weaveSummary';
|
|
20
|
+
const RPC_PATH = '/plugins/dsh-compaction-weave/rpc';
|
|
21
|
+
const PAGE_ID = 'compaction-weave-summary';
|
|
22
|
+
const MAX_IDLE_COMPACTION_MINUTES = 43200; // One month is a fixed 30 days.
|
|
23
|
+
const IDLE_PRESETS = ['0', '5', '10', '30', '60', '720', '1440', '10080', '43200'];
|
|
24
|
+
|
|
25
|
+
const dictionaries = {
|
|
26
|
+
zh: {
|
|
27
|
+
nav: '摘要模型',
|
|
28
|
+
title: '摘要模型',
|
|
29
|
+
intro: '选择压缩历史时负责写摘要的模型。留空表示跟随当前会话模型。',
|
|
30
|
+
provider: 'Provider',
|
|
31
|
+
providerPlaceholder: '例如 deepseek',
|
|
32
|
+
model: 'Model',
|
|
33
|
+
modelPlaceholder: '例如 deepseek-v4.1-flash',
|
|
34
|
+
maxTokens: 'maxTokens(输出上限)',
|
|
35
|
+
maxTokensPlaceholder: '默认 8192',
|
|
36
|
+
save: '保存',
|
|
37
|
+
saving: '保存中…',
|
|
38
|
+
clear: '清除(跟随会话模型)',
|
|
39
|
+
loading: '读取当前配置…',
|
|
40
|
+
saved: '已保存,无需重启 DSH。新设置从后续压缩或请求边界生效。',
|
|
41
|
+
cleared: '已清除摘要模型覆盖,无需重启 DSH。从后续压缩或请求边界跟随会话模型。',
|
|
42
|
+
applyHint: '保存或清除本页设置无需重启 DSH,从后续压缩或请求边界生效。进行中的压缩仍使用开始时的配置。首次安装或升级插件本体仍需按 DSH 提示重载宿主。',
|
|
43
|
+
pair: 'Provider 和 Model 必须同时填写,或同时留空。',
|
|
44
|
+
badMax: 'maxTokens 必须是 1 到 1000000 之间的整数。',
|
|
45
|
+
error: '保存失败:',
|
|
46
|
+
follow: '两项都空时清除覆盖,跟随当前会话模型。',
|
|
47
|
+
followSession: '跟随当前会话模型',
|
|
48
|
+
notInCatalog: '不在当前模型列表中',
|
|
49
|
+
noModels: '该 Provider 没有可选模型',
|
|
50
|
+
defaultMax: '默认(8192)',
|
|
51
|
+
catalogError: '模型列表读取失败',
|
|
52
|
+
reloadModels: '重新读取模型列表',
|
|
53
|
+
trigger: '自动压缩触发线',
|
|
54
|
+
minimumReduction: '最小压缩幅度',
|
|
55
|
+
reductionHint: '自动压缩至少减少压缩前上下文的 {pct}%。达不到时尝试同会话接续;无法保留必要要求时会停止并报错。',
|
|
56
|
+
reductionRange: '最小压缩幅度必须在 5% 到 90% 之间。',
|
|
57
|
+
triggerHint: '触发线 = 窗口的 {pct}%。实际触发线取较小值:min(窗口 × 百分比, 窗口 − 输出预留 − 33000);输出预留越大,实际触发会越早。',
|
|
58
|
+
triggerRange: '触发线必须在 50% 到 95% 之间。',
|
|
59
|
+
idleCompaction: '闲置后先压缩',
|
|
60
|
+
idleOff: '关闭',
|
|
61
|
+
idle5: '5 分钟(Claude 默认 / 旧 GPT 参考)',
|
|
62
|
+
idle10: '10 分钟',
|
|
63
|
+
idle30: '30 分钟(GPT / Gemini 参考)',
|
|
64
|
+
idle60: '60 分钟(Claude 延长缓存参考)',
|
|
65
|
+
idle720: '720 分钟(GPT 12 小时参考)',
|
|
66
|
+
idle1440: '1440 分钟(旧 GPT 最长 24 小时参考,非保证)',
|
|
67
|
+
idle10080: '7 天(10080 分钟)',
|
|
68
|
+
idle43200: '30 天(1 个月,43200 分钟)',
|
|
69
|
+
idleCustom: '自定义',
|
|
70
|
+
idleCustomMinutes: '自定义闲置时间(分钟)',
|
|
71
|
+
idleDurationHint: '自定义可填 1–43200 整数分钟;1 个月固定为 30 天(43200 分钟)。7 天/30 天是闲置策略,不代表服务商缓存有效期;停用请选择“关闭”。',
|
|
72
|
+
idleReferences: '各家缓存时间参考',
|
|
73
|
+
idleClaudeHint: 'Claude 默认缓存至少保留 5 分钟,可选 1 小时;从使用缓存的请求开始计时,生成回复也占用这段时间。',
|
|
74
|
+
idleHint: '默认关闭,与按上下文压力触发的自动压缩开关独立。按本会话最近一次用户、助手或工具的实际活动,到新用户消息入队时的间隔估计闲置时间;时间未知时不触发。',
|
|
75
|
+
idleTriggerHint: '超过所选时间后,仅在新用户回合的第一步、发送前压缩仍可压缩的历史;活跃工具循环中不触发。压缩失败则保留新输入并停止该次请求。',
|
|
76
|
+
idleGptHint: 'GPT-5.6 及以后模型在 Responses API 中默认最低缓存寿命为 30 分钟,可选 12 小时;这涉及缓存读取计费资格,不保证每次命中或降低延迟。旧模型 in_memory 通常闲置 5–10 分钟、最长 1 小时;24h 通常约 30 分钟、最长 24 小时,支持范围和默认值因模型与组织策略而异,最长值并非保证。',
|
|
77
|
+
idleCacheHint: '这些时间是手动触发参考,并非服务商缓存的实际过期时间。12 / 24 小时选项仅适用于上游已启用相应缓存策略,此设置不会启用或修改上游缓存。Gemini 的 30 分钟是本插件的触发参考,并非官方隐式缓存有效期。DeepSeek / GLM 目前无可靠固定有效期,可自定义时间。',
|
|
78
|
+
idleRange: '自定义闲置时间必须为 1–43200 之间的整数分钟;停用请选择“关闭”。',
|
|
79
|
+
compressing: '正在压缩…',
|
|
80
|
+
retryCount: '失败重试次数',
|
|
81
|
+
retryDelay: '重试基础间隔(秒)',
|
|
82
|
+
summaryTimeout: '每次摘要等待上限(秒)',
|
|
83
|
+
retryHint: '每个摘要或未完成页失败后最多再试 {count} 次(合计 {total} 次)。摘要修正也占次数;分页只重试未完成页,接续总预算仍然有效。',
|
|
84
|
+
retryDelayHint: '后续重试间隔逐次加倍,最长 30 秒。取消、凭据错误或存储异常会立即停止。',
|
|
85
|
+
timeoutHint: '单次请求超时后可重试,因此总等待时间可能超过此值。已发出的请求可能计费。',
|
|
86
|
+
retryRange: '重试次数须为 0–4 的整数;基础间隔须为 0–30 秒;每次等待上限须为 5–3600 秒。',
|
|
87
|
+
},
|
|
88
|
+
en: {
|
|
89
|
+
nav: 'Summary model',
|
|
90
|
+
title: 'Summary model',
|
|
91
|
+
intro: 'Choose the model that writes compaction summaries. Leave both fields empty to follow the current session model.',
|
|
92
|
+
provider: 'Provider',
|
|
93
|
+
providerPlaceholder: 'e.g. deepseek',
|
|
94
|
+
model: 'Model',
|
|
95
|
+
modelPlaceholder: 'e.g. deepseek-v4.1-flash',
|
|
96
|
+
maxTokens: 'maxTokens (output cap)',
|
|
97
|
+
maxTokensPlaceholder: 'default 8192',
|
|
98
|
+
save: 'Save',
|
|
99
|
+
saving: 'Saving…',
|
|
100
|
+
clear: 'Clear (follow session model)',
|
|
101
|
+
loading: 'Reading current configuration…',
|
|
102
|
+
saved: 'Saved. No DSH restart needed. Changes apply at subsequent compaction or request boundaries.',
|
|
103
|
+
cleared: 'Summary model override cleared. No DSH restart needed. Follow the session model at subsequent compaction or request boundaries.',
|
|
104
|
+
applyHint: 'Saving or clearing any setting on this page needs no DSH restart. Changes apply at subsequent compaction or request boundaries. A compaction already in progress keeps the configuration it started with. First installation or plugin upgrades still require a host reload as prompted by DSH.',
|
|
105
|
+
pair: 'Provider and Model must be filled together, or both left empty.',
|
|
106
|
+
badMax: 'maxTokens must be an integer between 1 and 1000000.',
|
|
107
|
+
error: 'Save failed: ',
|
|
108
|
+
follow: 'Leave both empty to clear the override and follow the current session model.',
|
|
109
|
+
followSession: 'Follow the current session model',
|
|
110
|
+
notInCatalog: 'not in the current catalog',
|
|
111
|
+
noModels: 'No models for this provider',
|
|
112
|
+
defaultMax: 'Default (8192)',
|
|
113
|
+
catalogError: 'Could not read the model catalog',
|
|
114
|
+
reloadModels: 'Reload models',
|
|
115
|
+
trigger: 'Auto-compaction trigger',
|
|
116
|
+
minimumReduction: 'Minimum compaction reduction',
|
|
117
|
+
reductionHint: 'Reduce total context by at least {pct}% during automatic compaction. Try same-session continuation if needed; stop if required evidence cannot fit.',
|
|
118
|
+
reductionRange: 'Minimum reduction must be between 5% and 90%.',
|
|
119
|
+
triggerHint: 'The trigger line is {pct}% of the window. The effective line is min(window × percent, window − reserved output − 33000); a larger output reservation makes it fire earlier.',
|
|
120
|
+
triggerRange: 'The trigger line must be between 50% and 95%.',
|
|
121
|
+
idleCompaction: 'Compact before resuming',
|
|
122
|
+
idleOff: 'Off',
|
|
123
|
+
idle5: '5 minutes (Claude default / older GPT reference)',
|
|
124
|
+
idle10: '10 minutes',
|
|
125
|
+
idle30: '30 minutes (GPT / Gemini reference)',
|
|
126
|
+
idle60: '60 minutes (Claude extended cache reference)',
|
|
127
|
+
idle720: '720 minutes (GPT 12-hour reference)',
|
|
128
|
+
idle1440: '1440 minutes (older GPT, up to 24 hours; not guaranteed)',
|
|
129
|
+
idle10080: '7 days (10080 minutes)',
|
|
130
|
+
idle43200: '30 days (1 month, 43200 minutes)',
|
|
131
|
+
idleCustom: 'Custom',
|
|
132
|
+
idleCustomMinutes: 'Custom idle time (minutes)',
|
|
133
|
+
idleDurationHint: 'Custom accepts 1–43200 whole minutes; 1 month is fixed at 30 days (43200 minutes). The 7-day and 30-day presets are idle policies, not provider cache lifetimes. Select Off to disable.',
|
|
134
|
+
idleReferences: 'Provider cache time references',
|
|
135
|
+
idleClaudeHint: 'Claude caches last at least 5 minutes by default, with a 1-hour option. Time starts when the request using the cache begins, including response generation.',
|
|
136
|
+
idleHint: 'Off by default and independent of the automatic compaction switch for context pressure. Estimate idle time from this session’s latest actual user, assistant or tool activity to when the new user message is queued. Unknown timestamps do not trigger compaction.',
|
|
137
|
+
idleTriggerHint: 'After the selected interval, compact any history that can still be compacted before sending, only at the first step of a new user turn. Active tool loops do not trigger it. If compaction fails, keep the new input and stop that request.',
|
|
138
|
+
idleGptHint: 'For GPT-5.6 and later in the Responses API, the default minimum cache lifetime is 30 minutes, with 12 hours available. This governs cache-read pricing eligibility, without guaranteeing a cache hit or lower latency. For older models, in_memory typically lasts 5–10 idle minutes, up to 1 hour; 24h typically lasts around 30 minutes, up to 24 hours. Support and defaults vary by model and organization policy; maximum retention is not guaranteed.',
|
|
139
|
+
idleCacheHint: 'These times are manual trigger references, not the provider’s actual cache expiry. The 12 / 24-hour options apply only when the upstream enables the corresponding cache policy; this setting does not enable or modify upstream caching. Gemini’s 30 minutes is this plugin’s trigger reference, not an official cache TTL. DeepSeek / GLM currently have no reliable fixed TTL; choose a custom time.',
|
|
140
|
+
idleRange: 'Custom idle time must be an integer from 1 to 43200 minutes. Select Off to disable.',
|
|
141
|
+
compressing: 'Compacting…',
|
|
142
|
+
retryCount: 'Retries after failure',
|
|
143
|
+
retryDelay: 'Base retry delay (seconds)',
|
|
144
|
+
summaryTimeout: 'Timeout per summary request (seconds)',
|
|
145
|
+
retryHint: 'Retry up to {count} times ({total} total attempts), including corrective requests. Resume only unfinished pages; the continuation budget still applies.',
|
|
146
|
+
retryDelayHint: 'The delay doubles on later retries, capped at 30 seconds. Cancellation, credentials and storage failures stop immediately.',
|
|
147
|
+
timeoutHint: 'A timed-out request can be retried, so total waiting time may exceed this limit. Dispatched requests may be billed.',
|
|
148
|
+
retryRange: 'Retries must be an integer from 0 to 4; base delay 0–30 seconds; timeout 5–3600 seconds.',
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
async function rpc(method, params, signal) {
|
|
153
|
+
const response = await fetch(RPC_PATH, {
|
|
154
|
+
method: 'POST',
|
|
155
|
+
headers: { 'content-type': 'application/json' },
|
|
156
|
+
credentials: 'same-origin',
|
|
157
|
+
body: JSON.stringify(params === undefined ? { method } : { method, params }),
|
|
158
|
+
...(signal === undefined ? {} : { signal }),
|
|
159
|
+
});
|
|
160
|
+
const text = await response.text();
|
|
161
|
+
let payload = null;
|
|
162
|
+
try {
|
|
163
|
+
payload = text === '' ? null : JSON.parse(text);
|
|
164
|
+
} catch {
|
|
165
|
+
throw new Error(`host returned non-JSON (HTTP ${response.status})`);
|
|
166
|
+
}
|
|
167
|
+
if (payload === null || payload.ok !== true) {
|
|
168
|
+
const error = new Error(payload?.error?.message ?? `HTTP ${response.status}`);
|
|
169
|
+
error.code = payload?.error?.code;
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
return payload.value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Composer card that exists only while a compaction is running.
|
|
177
|
+
*
|
|
178
|
+
* The host records `compaction/start` / `compaction/end` around the whole
|
|
179
|
+
* operation (the two log-only events are always written by the engine), so
|
|
180
|
+
* the card polls one tiny RPC method and renders nothing otherwise. It is
|
|
181
|
+
* deliberately a status card, not a progress bar: the engine cannot report
|
|
182
|
+
* chunk progress without a second event vocabulary.
|
|
183
|
+
*/
|
|
184
|
+
function CompactionProgressCard(props) {
|
|
185
|
+
const sessionId = typeof props?.sessionId === 'string' ? props.sessionId : '';
|
|
186
|
+
const [status, setStatus] = React.useState({ active: false, startedAt: null, elapsedMs: 0 });
|
|
187
|
+
React.useEffect(() => {
|
|
188
|
+
if (sessionId === '') return undefined;
|
|
189
|
+
let alive = true;
|
|
190
|
+
let timer = null;
|
|
191
|
+
let inFlight = false;
|
|
192
|
+
const tick = async () => {
|
|
193
|
+
if (inFlight) return;
|
|
194
|
+
inFlight = true;
|
|
195
|
+
try {
|
|
196
|
+
const response = await fetch(RPC_PATH, {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers: { 'content-type': 'application/json' },
|
|
199
|
+
credentials: 'same-origin',
|
|
200
|
+
body: JSON.stringify({ method: 'status', params: { sessionId } }),
|
|
201
|
+
});
|
|
202
|
+
const text = await response.text();
|
|
203
|
+
const payload = text === '' ? null : JSON.parse(text);
|
|
204
|
+
if (!alive) return;
|
|
205
|
+
const value = payload?.ok === true ? payload.value : null;
|
|
206
|
+
const next = value?.active
|
|
207
|
+
? { active: true, startedAt: value.startedAt, elapsedMs: Number(value.elapsedMs) || 0 }
|
|
208
|
+
: { active: false, startedAt: null, elapsedMs: 0 };
|
|
209
|
+
setStatus(previous => {
|
|
210
|
+
if (previous.active !== next.active) return next;
|
|
211
|
+
if (!next.active) return previous;
|
|
212
|
+
return Math.floor(previous.elapsedMs / 1000) === Math.floor(next.elapsedMs / 1000)
|
|
213
|
+
? previous
|
|
214
|
+
: next;
|
|
215
|
+
});
|
|
216
|
+
} catch {
|
|
217
|
+
// Host unreachable: keep the last snapshot instead of flashing.
|
|
218
|
+
} finally {
|
|
219
|
+
inFlight = false;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
void tick();
|
|
223
|
+
timer = setInterval(() => void tick(), 1000);
|
|
224
|
+
return () => {
|
|
225
|
+
alive = false;
|
|
226
|
+
if (timer !== null) clearInterval(timer);
|
|
227
|
+
};
|
|
228
|
+
}, [sessionId]);
|
|
229
|
+
|
|
230
|
+
if (!status.active) return null;
|
|
231
|
+
const t = typeof props?.t === 'function' ? props.t : (key => dictionaries.zh[key] ?? key);
|
|
232
|
+
const seconds = Math.max(0, Math.floor(status.elapsedMs / 1000));
|
|
233
|
+
return h('div', {
|
|
234
|
+
role: 'status',
|
|
235
|
+
'aria-live': 'polite',
|
|
236
|
+
'data-compaction-progress': 'active',
|
|
237
|
+
style: {
|
|
238
|
+
display: 'inline-flex',
|
|
239
|
+
alignItems: 'center',
|
|
240
|
+
gap: 8,
|
|
241
|
+
alignSelf: 'flex-start',
|
|
242
|
+
maxWidth: '100%',
|
|
243
|
+
padding: '6px 10px',
|
|
244
|
+
borderRadius: 8,
|
|
245
|
+
border: '1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.35))',
|
|
246
|
+
background: 'var(--dsw-alias-bg-elevated, transparent)',
|
|
247
|
+
color: 'var(--dsw-alias-text-secondary, inherit)',
|
|
248
|
+
fontSize: 12,
|
|
249
|
+
lineHeight: 1.4,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
h('span', {
|
|
253
|
+
'aria-hidden': 'true',
|
|
254
|
+
style: {
|
|
255
|
+
display: 'inline-block',
|
|
256
|
+
width: 10,
|
|
257
|
+
height: 10,
|
|
258
|
+
borderRadius: '50%',
|
|
259
|
+
border: '2px solid var(--dsw-alias-brand-primary, #2f6fed)',
|
|
260
|
+
borderTopColor: 'transparent',
|
|
261
|
+
},
|
|
262
|
+
}),
|
|
263
|
+
h('span', null, t('compressing')),
|
|
264
|
+
h('span', { style: { fontVariantNumeric: 'tabular-nums', opacity: 0.75 } }, `${seconds}s`),
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const inputStyle = {
|
|
269
|
+
width: '100%',
|
|
270
|
+
boxSizing: 'border-box',
|
|
271
|
+
padding: '8px 10px',
|
|
272
|
+
borderRadius: 8,
|
|
273
|
+
border: '1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.35))',
|
|
274
|
+
background: 'var(--dsw-alias-bg-base, transparent)',
|
|
275
|
+
color: 'var(--dsw-alias-text-primary, inherit)',
|
|
276
|
+
font: 'inherit',
|
|
277
|
+
}; const labelStyle = {
|
|
278
|
+
display: 'block',
|
|
279
|
+
fontSize: 12,
|
|
280
|
+
fontWeight: 600,
|
|
281
|
+
color: 'var(--dsw-alias-text-secondary, inherit)',
|
|
282
|
+
marginBottom: 4,
|
|
283
|
+
};
|
|
284
|
+
const fieldStyle = { display: 'flex', flexDirection: 'column', gap: 4 };
|
|
285
|
+
const buttonStyle = {
|
|
286
|
+
border: '1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.35))',
|
|
287
|
+
borderRadius: 8,
|
|
288
|
+
padding: '8px 14px',
|
|
289
|
+
font: 'inherit',
|
|
290
|
+
cursor: 'pointer',
|
|
291
|
+
background: 'var(--dsw-alias-bg-elevated, transparent)',
|
|
292
|
+
color: 'var(--dsw-alias-text-primary, inherit)',
|
|
293
|
+
};
|
|
294
|
+
const primaryStyle = {
|
|
295
|
+
...buttonStyle,
|
|
296
|
+
background: 'var(--dsw-alias-brand-primary, #2f6fed)',
|
|
297
|
+
borderColor: 'var(--dsw-alias-brand-primary, #2f6fed)',
|
|
298
|
+
color: '#fff',
|
|
299
|
+
};
|
|
300
|
+
const mutedStyle = {
|
|
301
|
+
color: 'var(--dsw-alias-text-secondary, inherit)',
|
|
302
|
+
fontSize: 12,
|
|
303
|
+
lineHeight: 1.5,
|
|
304
|
+
margin: 0,
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
function apply(ctx) {
|
|
308
|
+
const fallback = key => dictionaries.zh[key] ?? key;
|
|
309
|
+
let t = fallback;
|
|
310
|
+
try {
|
|
311
|
+
if (typeof ctx.locale?.register === 'function') {
|
|
312
|
+
ctx.effect?.(() => ctx.locale.register(NS, dictionaries), 'compaction-weave: settings locale');
|
|
313
|
+
}
|
|
314
|
+
if (typeof ctx.locale?.bind === 'function') t = ctx.locale.bind(NS);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.warn('[dsh-compaction-weave] settings locale unavailable:', error?.message ?? error);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function Section() {
|
|
320
|
+
const [loading, setLoading] = React.useState(true);
|
|
321
|
+
const [provider, setProvider] = React.useState('');
|
|
322
|
+
const [model, setModel] = React.useState('');
|
|
323
|
+
const [maxTokens, setMaxTokens] = React.useState('');
|
|
324
|
+
const [thresholdRatio, setThresholdRatio] = React.useState(80);
|
|
325
|
+
const [minimumReductionRatio, setMinimumReductionRatio] = React.useState(20);
|
|
326
|
+
const [retryCount, setRetryCount] = React.useState('2');
|
|
327
|
+
const [retryDelay, setRetryDelay] = React.useState('1');
|
|
328
|
+
const [summaryTimeout, setSummaryTimeout] = React.useState('180');
|
|
329
|
+
const [idlePreset, setIdlePreset] = React.useState('0');
|
|
330
|
+
const [idleCustomMinutes, setIdleCustomMinutes] = React.useState('');
|
|
331
|
+
const [catalog, setCatalog] = React.useState([]);
|
|
332
|
+
const [catalogError, setCatalogError] = React.useState(null);
|
|
333
|
+
const [saving, setSaving] = React.useState(false);
|
|
334
|
+
const [status, setStatus] = React.useState(null);
|
|
335
|
+
|
|
336
|
+
function load() {
|
|
337
|
+
let alive = true;
|
|
338
|
+
setLoading(true);
|
|
339
|
+
setCatalogError(null);
|
|
340
|
+
Promise.allSettled([rpc('get'), rpc('models')])
|
|
341
|
+
.then(([configResult, catalogResult]) => {
|
|
342
|
+
if (!alive) return;
|
|
343
|
+
if (configResult.status === 'fulfilled') {
|
|
344
|
+
const config = configResult.value?.config ?? null;
|
|
345
|
+
const idle = String(config?.idleCompactionMinutes ?? 0);
|
|
346
|
+
setIdlePreset(IDLE_PRESETS.includes(idle) ? idle : 'custom');
|
|
347
|
+
setIdleCustomMinutes(IDLE_PRESETS.includes(idle) ? '' : idle);
|
|
348
|
+
if (config) {
|
|
349
|
+
setRetryCount(String(config.summaryRetryCount ?? 2));
|
|
350
|
+
setRetryDelay(String((config.summaryRetryDelayMs ?? 1000) / 1000));
|
|
351
|
+
setSummaryTimeout(String((config.summaryTimeoutMs ?? 180000) / 1000));
|
|
352
|
+
setProvider(config.provider ?? '');
|
|
353
|
+
setModel(config.model ?? '');
|
|
354
|
+
setMaxTokens(config.maxTokens === null || config.maxTokens === undefined ? '' : String(config.maxTokens));
|
|
355
|
+
setThresholdRatio(typeof config.thresholdRatio === 'number' ? Math.round(config.thresholdRatio * 100) : 80);
|
|
356
|
+
setMinimumReductionRatio(typeof config.minimumReductionRatio === 'number' ? Math.round(config.minimumReductionRatio * 100) : 20);
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
setStatus({ kind: 'error', text: (t('error') ?? 'Save failed: ') + (configResult.reason?.message ?? configResult.reason) });
|
|
360
|
+
}
|
|
361
|
+
if (catalogResult.status === 'fulfilled') {
|
|
362
|
+
const providers = catalogResult.value?.providers;
|
|
363
|
+
setCatalog(Array.isArray(providers) ? providers : []);
|
|
364
|
+
} else {
|
|
365
|
+
setCatalog([]);
|
|
366
|
+
setCatalogError(catalogResult.reason?.message ?? String(catalogResult.reason));
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
.finally(() => {
|
|
370
|
+
if (alive) setLoading(false);
|
|
371
|
+
});
|
|
372
|
+
return () => {
|
|
373
|
+
alive = false;
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
React.useEffect(load, []);
|
|
378
|
+
|
|
379
|
+
const providerOptions = [{ value: '', label: t('followSession') }];
|
|
380
|
+
for (const entry of catalog) {
|
|
381
|
+
const id = String(entry?.provider ?? '');
|
|
382
|
+
if (id === '') continue;
|
|
383
|
+
providerOptions.push({
|
|
384
|
+
value: id,
|
|
385
|
+
label: entry.name && entry.name !== id ? `${entry.name} (${id})` : id,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
if (provider && !providerOptions.some(option => option.value === provider)) {
|
|
389
|
+
providerOptions.push({ value: provider, label: `${provider} (${t('notInCatalog')})` });
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const selectedProvider = catalog.find(entry => entry?.provider === provider);
|
|
393
|
+
const modelOptions = [];
|
|
394
|
+
for (const entry of selectedProvider?.models ?? []) {
|
|
395
|
+
const id = String(entry?.id ?? '');
|
|
396
|
+
if (id === '') continue;
|
|
397
|
+
modelOptions.push({ value: id, label: entry.name && entry.name !== id ? `${entry.name} (${id})` : id });
|
|
398
|
+
}
|
|
399
|
+
if (model && !modelOptions.some(option => option.value === model)) {
|
|
400
|
+
modelOptions.push({ value: model, label: `${model} (${t('notInCatalog')})` });
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const maxTokenValues = ['8192', '16384', '32768', '65536', '131072'];
|
|
404
|
+
const maxOptions = [{ value: '', label: t('defaultMax') }, ...maxTokenValues.map(value => ({ value, label: value }))];
|
|
405
|
+
if (maxTokens && !maxOptions.some(option => option.value === maxTokens)) {
|
|
406
|
+
maxOptions.push({ value: maxTokens, label: maxTokens });
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function onProviderChange(event) {
|
|
410
|
+
const next = event.target.value;
|
|
411
|
+
setProvider(next);
|
|
412
|
+
const entry = catalog.find(item => item?.provider === next);
|
|
413
|
+
setModel(entry?.models?.[0]?.id ?? '');
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function validate(clear = false) {
|
|
417
|
+
const idleText = String(idlePreset === 'custom' ? idleCustomMinutes : idlePreset).trim();
|
|
418
|
+
const idle = Number(idleText);
|
|
419
|
+
if (!/^\d+$/.test(idleText) || !Number.isInteger(idle) || idle < (idlePreset === 'custom' ? 1 : 0) || idle > MAX_IDLE_COMPACTION_MINUTES ||
|
|
420
|
+
(idlePreset !== 'custom' && !IDLE_PRESETS.includes(idlePreset))) return t('idleRange');
|
|
421
|
+
const retries=Number(retryCount),delay=Number(retryDelay)*1000,timeout=Number(summaryTimeout)*1000;
|
|
422
|
+
if (![retryCount,retryDelay,summaryTimeout].every(v=>String(v).trim()!=='') || !Number.isInteger(retries)||retries<0||retries>4||!Number.isInteger(delay)||delay<0||delay>30000||!Number.isInteger(timeout)||timeout<5000||timeout>3600000) return t('retryRange');
|
|
423
|
+
const p = provider.trim();
|
|
424
|
+
const m = model.trim();
|
|
425
|
+
if (!clear && (p === '') !== (m === '')) return t('pair');
|
|
426
|
+
if (!Number.isInteger(thresholdRatio) || thresholdRatio < 50 || thresholdRatio > 95) return t('triggerRange');
|
|
427
|
+
if (!Number.isInteger(minimumReductionRatio) || minimumReductionRatio < 5 || minimumReductionRatio > 90) return t('reductionRange');
|
|
428
|
+
const v = maxTokens.trim();
|
|
429
|
+
if (!clear && v !== '') {
|
|
430
|
+
const number = Number(v);
|
|
431
|
+
if (!Number.isInteger(number) || number < 1 || number > 1_000_000) return t('badMax');
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async function submit(clear) {
|
|
437
|
+
const problem = validate(clear);
|
|
438
|
+
if (problem) {
|
|
439
|
+
setStatus({ kind: 'error', text: problem });
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
setSaving(true);
|
|
443
|
+
setStatus(null);
|
|
444
|
+
try {
|
|
445
|
+
const params = clear
|
|
446
|
+
? { provider: '', model: '', maxTokens: null, thresholdRatio: thresholdRatio / 100, minimumReductionRatio: minimumReductionRatio / 100 }
|
|
447
|
+
: {
|
|
448
|
+
provider: provider.trim(),
|
|
449
|
+
model: model.trim(),
|
|
450
|
+
maxTokens: maxTokens.trim() === '' ? null : Number(maxTokens),
|
|
451
|
+
thresholdRatio: thresholdRatio / 100,
|
|
452
|
+
minimumReductionRatio: minimumReductionRatio / 100,
|
|
453
|
+
};
|
|
454
|
+
Object.assign(params,{summaryRetryCount:Number(retryCount),summaryRetryDelayMs:Number(retryDelay)*1000,summaryTimeoutMs:Number(summaryTimeout)*1000});
|
|
455
|
+
params.idleCompactionMinutes = Number(idlePreset === 'custom' ? idleCustomMinutes : idlePreset);
|
|
456
|
+
await rpc('set', params);
|
|
457
|
+
if (clear) {
|
|
458
|
+
setProvider('');
|
|
459
|
+
setModel('');
|
|
460
|
+
setMaxTokens('');
|
|
461
|
+
setStatus({ kind: 'ok', text: t('cleared') });
|
|
462
|
+
} else {
|
|
463
|
+
setStatus({ kind: 'ok', text: t('saved') });
|
|
464
|
+
}
|
|
465
|
+
} catch (error) {
|
|
466
|
+
setStatus({ kind: 'error', text: (t('error') ?? 'Save failed: ') + (error?.message ?? error) });
|
|
467
|
+
} finally {
|
|
468
|
+
setSaving(false);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (loading) {
|
|
473
|
+
return h('section', { style: { maxWidth: 760, padding: '4px 0' } }, h('p', { style: mutedStyle }, t('loading')));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return h(
|
|
477
|
+
'section',
|
|
478
|
+
{ style: { maxWidth: 760, display: 'flex', flexDirection: 'column', gap: 14, padding: '4px 0' } },
|
|
479
|
+
h('header', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
480
|
+
h('h2', { style: { fontSize: 18, margin: 0 } }, t('title')),
|
|
481
|
+
h('p', { style: mutedStyle }, t('intro')),
|
|
482
|
+
),
|
|
483
|
+
h('div', { style: fieldStyle },
|
|
484
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-provider' }, t('provider')),
|
|
485
|
+
h('select', {
|
|
486
|
+
id: 'weave-summary-provider',
|
|
487
|
+
style: inputStyle,
|
|
488
|
+
value: provider,
|
|
489
|
+
onChange: onProviderChange,
|
|
490
|
+
}, providerOptions.map(option => h('option', { key: option.value, value: option.value }, option.label))),
|
|
491
|
+
),
|
|
492
|
+
h('div', { style: fieldStyle },
|
|
493
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-model' }, t('model')),
|
|
494
|
+
h('select', {
|
|
495
|
+
id: 'weave-summary-model',
|
|
496
|
+
style: inputStyle,
|
|
497
|
+
value: model,
|
|
498
|
+
disabled: provider === '' || modelOptions.length === 0,
|
|
499
|
+
onChange: event => setModel(event.target.value),
|
|
500
|
+
}, modelOptions.length === 0
|
|
501
|
+
? h('option', { value: '' }, provider === '' ? t('followSession') : t('noModels'))
|
|
502
|
+
: modelOptions.map(option => h('option', { key: option.value, value: option.value }, option.label))),
|
|
503
|
+
),
|
|
504
|
+
h('div', { style: fieldStyle },
|
|
505
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-max-tokens' }, t('maxTokens')),
|
|
506
|
+
h('select', {
|
|
507
|
+
id: 'weave-summary-max-tokens',
|
|
508
|
+
style: inputStyle,
|
|
509
|
+
value: maxTokens,
|
|
510
|
+
onChange: event => setMaxTokens(event.target.value),
|
|
511
|
+
}, maxOptions.map(option => h('option', { key: option.value, value: option.value }, option.label))),
|
|
512
|
+
),
|
|
513
|
+
h('div', { style: fieldStyle },
|
|
514
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-retry-count' }, t('retryCount')),
|
|
515
|
+
h('input', {id:'weave-summary-retry-count',type:'number',min:0,max:4,step:1,style:inputStyle,value:retryCount,onChange:event=>setRetryCount(event.target.value)}),
|
|
516
|
+
h('p', {style:mutedStyle}, t('retryHint').replace('{count}',String(retryCount)).replace('{total}',String(Number(retryCount)+1))),
|
|
517
|
+
),
|
|
518
|
+
h('div', { style: fieldStyle },
|
|
519
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-retry-delay' }, t('retryDelay')),
|
|
520
|
+
h('input', {id:'weave-summary-retry-delay',type:'number',min:0,max:30,step:0.001,style:inputStyle,value:retryDelay,onChange:event=>setRetryDelay(event.target.value)}),
|
|
521
|
+
h('p', {style:mutedStyle}, t('retryDelayHint')),
|
|
522
|
+
),
|
|
523
|
+
h('div', { style: fieldStyle },
|
|
524
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-timeout' }, t('summaryTimeout')),
|
|
525
|
+
h('input', {id:'weave-summary-timeout',type:'number',min:5,max:3600,step:1,style:inputStyle,value:summaryTimeout,onChange:event=>setSummaryTimeout(event.target.value)}),
|
|
526
|
+
h('p', {style:mutedStyle}, t('timeoutHint')),
|
|
527
|
+
),
|
|
528
|
+
h('div', { style: fieldStyle },
|
|
529
|
+
h('label', { style: labelStyle, htmlFor: 'weave-summary-threshold' }, t('trigger')),
|
|
530
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 12 } },
|
|
531
|
+
h('input', {
|
|
532
|
+
id: 'weave-summary-threshold',
|
|
533
|
+
type: 'range',
|
|
534
|
+
min: 50,
|
|
535
|
+
max: 95,
|
|
536
|
+
step: 1,
|
|
537
|
+
value: thresholdRatio,
|
|
538
|
+
style: { flex: 1, accentColor: 'var(--dsw-alias-brand-primary, #2f6fed)' },
|
|
539
|
+
'aria-label': t('trigger'),
|
|
540
|
+
onChange: event => setThresholdRatio(Number(event.target.value)),
|
|
541
|
+
}),
|
|
542
|
+
h('span', { style: { minWidth: 48, textAlign: 'right', fontVariantNumeric: 'tabular-nums' } }, `${thresholdRatio}%`),
|
|
543
|
+
),
|
|
544
|
+
h('p', { style: mutedStyle }, t('triggerHint').replace('{pct}', String(thresholdRatio))),
|
|
545
|
+
),
|
|
546
|
+
h('div', { style: fieldStyle },
|
|
547
|
+
h('label', { style: labelStyle, htmlFor: 'weave-idle-compaction' }, t('idleCompaction')),
|
|
548
|
+
h('select', {
|
|
549
|
+
id: 'weave-idle-compaction',
|
|
550
|
+
style: inputStyle,
|
|
551
|
+
value: idlePreset,
|
|
552
|
+
'aria-describedby': 'weave-idle-duration-hint weave-idle-hint weave-idle-trigger-hint',
|
|
553
|
+
onChange: event => setIdlePreset(event.target.value),
|
|
554
|
+
},
|
|
555
|
+
IDLE_PRESETS.map(value => h('option', { key: value, value }, t(value === '0' ? 'idleOff' : `idle${value}`))),
|
|
556
|
+
h('option', { value: 'custom' }, t('idleCustom')),
|
|
557
|
+
),
|
|
558
|
+
idlePreset !== 'custom' ? null : h('div', { style: fieldStyle },
|
|
559
|
+
h('label', { style: labelStyle, htmlFor: 'weave-idle-custom-minutes' }, t('idleCustomMinutes')),
|
|
560
|
+
h('input', {
|
|
561
|
+
id: 'weave-idle-custom-minutes', type: 'number', min: 1, max: MAX_IDLE_COMPACTION_MINUTES, step: 1,
|
|
562
|
+
style: inputStyle, value: idleCustomMinutes,
|
|
563
|
+
'aria-describedby': 'weave-idle-duration-hint weave-idle-hint weave-idle-trigger-hint',
|
|
564
|
+
onChange: event => setIdleCustomMinutes(event.target.value),
|
|
565
|
+
}),
|
|
566
|
+
),
|
|
567
|
+
h('p', { id: 'weave-idle-duration-hint', style: mutedStyle }, t('idleDurationHint')),
|
|
568
|
+
h('p', { id: 'weave-idle-hint', style: mutedStyle }, t('idleHint')),
|
|
569
|
+
h('p', { id: 'weave-idle-trigger-hint', style: mutedStyle }, t('idleTriggerHint')),
|
|
570
|
+
h('details', {style:mutedStyle},
|
|
571
|
+
h('summary', {style:{cursor:'pointer'}}, t('idleReferences')),
|
|
572
|
+
h('p', { id: 'weave-idle-gpt-hint', style: mutedStyle }, t('idleGptHint')),
|
|
573
|
+
h('p', { style: mutedStyle }, t('idleClaudeHint')),
|
|
574
|
+
h('p', { id: 'weave-idle-cache-hint', style: mutedStyle }, t('idleCacheHint')),
|
|
575
|
+
h('p', {style:mutedStyle}, [
|
|
576
|
+
['OpenAI', 'https://developers.openai.com/api/docs/guides/prompt-caching'],
|
|
577
|
+
['Claude', 'https://platform.claude.com/docs/en/build-with-claude/prompt-caching'],
|
|
578
|
+
['Gemini', 'https://ai.google.dev/gemini-api/docs/caching'],
|
|
579
|
+
['DeepSeek', 'https://api-docs.deepseek.com/guides/kv_cache/'],
|
|
580
|
+
['GLM', 'https://docs.bigmodel.cn/cn/guide/capabilities/cache'],
|
|
581
|
+
].map(([label,href]) => h('a', {key:label,href,target:'_blank',rel:'noopener noreferrer',style:{marginRight:12,color:'inherit'}}, label))),
|
|
582
|
+
),
|
|
583
|
+
),
|
|
584
|
+
h('div', { style: fieldStyle },
|
|
585
|
+
h('label', { style: labelStyle, htmlFor: 'weave-minimum-reduction' }, t('minimumReduction')),
|
|
586
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 12 } },
|
|
587
|
+
h('input', {
|
|
588
|
+
id: 'weave-minimum-reduction', type: 'range', min: 5, max: 90, step: 1,
|
|
589
|
+
value: minimumReductionRatio,
|
|
590
|
+
style: { flex: 1, accentColor: 'var(--dsw-alias-brand-primary, #2f6fed)' },
|
|
591
|
+
'aria-label': t('minimumReduction'),
|
|
592
|
+
onChange: event => setMinimumReductionRatio(Number(event.target.value)),
|
|
593
|
+
}),
|
|
594
|
+
h('span', { style: { minWidth: 48, textAlign: 'right', fontVariantNumeric: 'tabular-nums' } }, `${minimumReductionRatio}%`),
|
|
595
|
+
),
|
|
596
|
+
h('p', { style: mutedStyle }, t('reductionHint').replace('{pct}', String(minimumReductionRatio))),
|
|
597
|
+
),
|
|
598
|
+
h('p', { style: mutedStyle }, t('follow')),
|
|
599
|
+
catalogError === null
|
|
600
|
+
? null
|
|
601
|
+
: h('p', { style: { ...mutedStyle, color: 'var(--dsw-alias-text-danger, #c0392b)' } },
|
|
602
|
+
`${t('catalogError')}: ${catalogError}`),
|
|
603
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
604
|
+
h('button', { type: 'button', style: primaryStyle, disabled: saving, onClick: () => void submit(false) },
|
|
605
|
+
saving ? t('saving') : t('save')),
|
|
606
|
+
h('button', { type: 'button', style: buttonStyle, disabled: saving, onClick: () => void submit(true) },
|
|
607
|
+
t('clear')),
|
|
608
|
+
catalogError === null
|
|
609
|
+
? null
|
|
610
|
+
: h('button', { type: 'button', style: buttonStyle, disabled: saving, onClick: () => void load() },
|
|
611
|
+
t('reloadModels')),
|
|
612
|
+
),
|
|
613
|
+
status === null
|
|
614
|
+
? null
|
|
615
|
+
: h('p', {
|
|
616
|
+
role: 'status',
|
|
617
|
+
style: {
|
|
618
|
+
...mutedStyle,
|
|
619
|
+
color: status.kind === 'error'
|
|
620
|
+
? 'var(--dsw-alias-text-danger, #c0392b)'
|
|
621
|
+
: 'var(--dsw-alias-text-success, #1e8449)',
|
|
622
|
+
},
|
|
623
|
+
}, status.text),
|
|
624
|
+
h('p', { style: mutedStyle }, t('applyHint')),
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Fallback for compositions whose main Settings shell is unavailable or
|
|
629
|
+
// does not project late settings.section registrations: the same form is
|
|
630
|
+
// also reachable from Plugins -> dsh-compaction-weave.
|
|
631
|
+
function PluginSection(props) {
|
|
632
|
+
const subject = props?.subject;
|
|
633
|
+
const pkg = subject?.pkg;
|
|
634
|
+
const name = typeof pkg === 'string' ? pkg : pkg?.name;
|
|
635
|
+
if (subject?.kind !== 'bundle' || name !== 'dsh-compaction-weave') return null;
|
|
636
|
+
return h(Section);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
try {
|
|
640
|
+
ctx.slots.inject('settings.section', () =>
|
|
641
|
+
ctx.slots.register(
|
|
642
|
+
{
|
|
643
|
+
name: 'settings.section',
|
|
644
|
+
id: PAGE_ID,
|
|
645
|
+
order: 5,
|
|
646
|
+
label: () => t('nav'),
|
|
647
|
+
locale: NS,
|
|
648
|
+
},
|
|
649
|
+
Section,
|
|
650
|
+
),
|
|
651
|
+
);
|
|
652
|
+
} catch (error) {
|
|
653
|
+
console.warn('[dsh-compaction-weave] settings.section unavailable:', error?.message ?? error);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// The "compacting…" card sits where the session-recap card sits: in the
|
|
657
|
+
// composer dock above the input box. It renders nothing when idle.
|
|
658
|
+
try {
|
|
659
|
+
ctx.slots.inject('conversation.input.dock', () =>
|
|
660
|
+
ctx.slots.register(
|
|
661
|
+
{
|
|
662
|
+
name: 'conversation.input.dock',
|
|
663
|
+
id: 'compaction-weave-progress',
|
|
664
|
+
order: 3,
|
|
665
|
+
locale: NS,
|
|
666
|
+
},
|
|
667
|
+
CompactionProgressCard,
|
|
668
|
+
),
|
|
669
|
+
);
|
|
670
|
+
} catch (error) {
|
|
671
|
+
console.warn('[dsh-compaction-weave] composer progress card unavailable:', error?.message ?? error);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
try {
|
|
675
|
+
ctx.slots.inject('plugins.detail.section', () =>
|
|
676
|
+
ctx.slots.register(
|
|
677
|
+
{
|
|
678
|
+
name: 'plugins.detail.section',
|
|
679
|
+
id: PAGE_ID,
|
|
680
|
+
order: 10,
|
|
681
|
+
locale: NS,
|
|
682
|
+
},
|
|
683
|
+
PluginSection,
|
|
684
|
+
),
|
|
685
|
+
);
|
|
686
|
+
} catch (error) {
|
|
687
|
+
console.warn('[dsh-compaction-weave] plugins.detail.section unavailable:', error?.message ?? error);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const module = { exports: {} };
|
|
692
|
+
module.exports.apply = apply;
|
|
693
|
+
module.exports.inject = ['slots', 'locale'];
|
|
694
|
+
return module.exports;
|
|
695
|
+
},
|
|
696
|
+
});
|