dsh-boost 0.1.4 → 0.2.1
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.en.md +60 -18
- package/README.md +53 -17
- package/dist/http/fence.js +119 -0
- package/dist/http/fence.js.map +1 -0
- package/dist/http/mount.js +71 -0
- package/dist/http/mount.js.map +1 -0
- package/dist/http/state.js +216 -0
- package/dist/http/state.js.map +1 -0
- package/dist/index.js +36 -4
- package/dist/index.js.map +1 -1
- package/dist/scope/doc.js +8 -0
- package/dist/scope/doc.js.map +1 -1
- package/dist/scope/store.js +5 -4
- package/dist/scope/store.js.map +1 -1
- package/dist/shared/api-prefix.js +9 -0
- package/dist/shared/api-prefix.js.map +1 -0
- package/dist/shared/api-types.js +10 -0
- package/dist/shared/api-types.js.map +1 -0
- package/dist/tools/boost.js +11 -3
- package/dist/tools/boost.js.map +1 -1
- package/lib/client.js +929 -0
- package/locale/en.json +96 -2
- package/locale/zh.json +96 -2
- package/package.json +21 -7
package/lib/client.js
ADDED
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-boost",
|
|
3
|
+
factory: (require2) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const jsxRuntime = require2("react/jsx-runtime");
|
|
9
|
+
const react = require2("react");
|
|
10
|
+
const ACTION_REREAD$1 = "重新读取";
|
|
11
|
+
const ACTION_SAVE$1 = "保存";
|
|
12
|
+
const CONFIG_READONLY$1 = "这一栏是只读的。它显示的是启动时 resolveConfig 算出来的值(含 clamp 与回落),改它要编辑 profile 的 cordis.patch.yml 并重启宿主。";
|
|
13
|
+
const CONFIG_UNAVAILABLE$1 = "读不到生效配置:路由返回的 config 不是对象。页面不会把它显示成一张空表。";
|
|
14
|
+
const DEGRADED_FALLBACK$1 = "未收录的码:查 docs/RELEASE.md 的稳定码表。";
|
|
15
|
+
const EMPTY_GLOBAL$1 = "所有工作区都会生效,下面这份名单只作为记录保留。";
|
|
16
|
+
const EMPTY_SELECTED$1 = "当前只对选中的工作区生效,但一个都没选——此时插件完全不介入。";
|
|
17
|
+
const ESTIMATE_HOST$1 = "宿主计量";
|
|
18
|
+
const HINT_DIRTY$1 = "改动还没有写下去。";
|
|
19
|
+
const HINT_NO_WORKSPACES_TO_PICK$1 = "宿主的注册表里没有工作区,没得选。";
|
|
20
|
+
const HINT_OVERHEAD$1 = "每次请求的常驻成本:协议段 + 工具 schema。它不随会话变化,也不被任何节省抵消。";
|
|
21
|
+
const HINT_PROJECTION_GROSS_REPLAY$1 = "每条回执的节省乘以它自己的 (1 + horizon) 再求和。这个数才是净额的被减数。";
|
|
22
|
+
const HINT_PROJECTION_NET$1 = "净额 = 重放毛额 − 取回内容成本 − 取回调用成本。回放用每条回执自己的 horizon,不是当前值;所以上面两个毛额不是同一个数,净额只与重放那个对齐。";
|
|
23
|
+
const HINT_PROJECTION_ON_ROLLBACK$1 = '回滚:把「投影」改回 `shadow` 并保存;或调 `boost` 工具,`cmd: "scope-set"`、`body: {"projection": "shadow"}`。改动对后续请求立即生效,不需要重启宿主。';
|
|
24
|
+
const HINT_PROJECTION_ON_SPILL$1 = "宿主有 spill 后端。没有的话投影会被跳过——`boost status` 的降级项会写 `ERR_HOST_NO_SPILL`,页面上也会显示这一条。";
|
|
25
|
+
const HINT_SAVED_LOWER$1 = "下界是被跳过那次请求自己的总用量:它不含「后续还会回放多少次」,所以真实节省高于这个数。";
|
|
26
|
+
const HINT_SAVED_UPPER$1 = "上界是「下一次请求的输入」:它把被替换调用的结果也算进了节省,所以真实节省低于这个数。";
|
|
27
|
+
const HINT_SHADOW_MEANS$1 = "影子模式:插件照常决策并记账,但不真的改动发给模型的内容。";
|
|
28
|
+
const HINT_SUBSTITUTE_ON_ROLLBACK$1 = "回滚:把「影子模式」勾回去并保存,替换立即停止;投影的设置不受影响。";
|
|
29
|
+
const HINT_SUBSTITUTE_ON_THINKING$1 = "第一次真替换之后盯一次含 `content[].thinking` 的 400。合成回合没有 `replayState`,宿主侧的转换会丢掉 thinking 块;当前路由是不是 Anthropic 兼容的 thinking 模式,在这台机器上查不出来,只能在真替换时观察。";
|
|
30
|
+
const INTRO$1 = "投影裁剪工具回执、确定性替换可推导的调用。下面的数字全部来自收据,不是估算的替代品:区间给出下界与上界,两者都不是精确值。";
|
|
31
|
+
const LABEL_CONFIG_KEY$1 = "键";
|
|
32
|
+
const LABEL_CONFIG_VALUE$1 = "生效值";
|
|
33
|
+
const LABEL_DEGRADED$1 = "降级项";
|
|
34
|
+
const LABEL_DIRTY$1 = "未保存";
|
|
35
|
+
const LABEL_ESTIMATE$1 = "口径";
|
|
36
|
+
const LABEL_MODE$1 = "模式";
|
|
37
|
+
const LABEL_MODE_GLOBAL$1 = "全部工作区";
|
|
38
|
+
const LABEL_MODE_SELECTED$1 = "仅选中的工作区";
|
|
39
|
+
const LABEL_OVERHEAD$1 = "常驻开销";
|
|
40
|
+
const LABEL_PROJECTION$1 = "投影";
|
|
41
|
+
const LABEL_PROJECTION_GROSS$1 = "投影毛额(一次性)";
|
|
42
|
+
const LABEL_PROJECTION_GROSS_REPLAY$1 = "投影毛额(按各自 horizon 重放)";
|
|
43
|
+
const LABEL_PROJECTION_NET$1 = "投影净额";
|
|
44
|
+
const LABEL_PROJECTION_ON_PRECONDITIONS$1 = "开启投影前确认两件事";
|
|
45
|
+
const LABEL_RETRIEVALS$1 = "取回次数";
|
|
46
|
+
const LABEL_SAVED_LOWER$1 = "替换节省(下界)";
|
|
47
|
+
const LABEL_SAVED_UPPER$1 = "替换节省(上界)";
|
|
48
|
+
const LABEL_SAVE_FAILED$1 = "保存没有生效:";
|
|
49
|
+
const LABEL_SHADOW$1 = "影子模式";
|
|
50
|
+
const LABEL_STALE_IDS$1 = "已保存但注册表里没有";
|
|
51
|
+
const LABEL_SUBSTITUTE_ON_PRECONDITIONS$1 = "关掉影子模式前确认一件事";
|
|
52
|
+
const LABEL_UNMATCHED_IDS$1 = "已勾选但注册表里没有";
|
|
53
|
+
const LABEL_WORKSPACES$1 = "工作区";
|
|
54
|
+
const LOADING$1 = "读取中…";
|
|
55
|
+
const NO_DEGRADED$1 = "没有降级项:宿主提供了这个插件需要的全部服务。";
|
|
56
|
+
const NO_RECEIPTS$1 = "还没有任何收据:插件在这个宿主上还没有产生过一次决策。";
|
|
57
|
+
const PROJECTION_OFF$1 = "关闭(不投影)";
|
|
58
|
+
const PROJECTION_ON$1 = "开启(真替换)";
|
|
59
|
+
const PROJECTION_SHADOW$1 = "影子(只记账)";
|
|
60
|
+
const RETRY$1 = "重试";
|
|
61
|
+
const SAVED$1 = "与磁盘上的文档一致。";
|
|
62
|
+
const SECTION_CONFIG$1 = "生效配置";
|
|
63
|
+
const SECTION_COUNTS$1 = "收据计数";
|
|
64
|
+
const SECTION_SCOPE$1 = "作用域";
|
|
65
|
+
const SECTION_STATUS$1 = "运行状态";
|
|
66
|
+
const TITLE$1 = "Token 效率";
|
|
67
|
+
const UNAVAILABLE_REGISTRY$1 = "读不到作用域文档,这一块暂时只读。";
|
|
68
|
+
const UNKNOWN$1 = "未测量";
|
|
69
|
+
const meta$1 = { "description": "通过工具回执投影与确定性只读替换降低 DeepSeek Harness 的 token 消耗。", "title": "dsh-boost" };
|
|
70
|
+
const zh = {
|
|
71
|
+
ACTION_REREAD: ACTION_REREAD$1,
|
|
72
|
+
ACTION_SAVE: ACTION_SAVE$1,
|
|
73
|
+
"ADVICE_FOR_CODE.ERR_BOOST_INTERNAL": "插件内部出错,磁盘上的文档没有被改动。看宿主日志。",
|
|
74
|
+
"ADVICE_FOR_CODE.ERR_BOOST_INVALID_ARGS": "请求参数不完整。",
|
|
75
|
+
"ADVICE_FOR_CODE.ERR_BOOST_INVALID_BODY": "有字段的取值不合法,所以整次写入被拒绝——磁盘上的文档没有被改动。",
|
|
76
|
+
"ADVICE_FOR_CODE.ERR_CLIENT_NETWORK": "页面没能连上插件的路由。它可能没有挂上——看宿主日志里有没有 webServer。",
|
|
77
|
+
"ADVICE_FOR_CODE.ERR_CLIENT_SHAPE": "插件返回的数据形状和这个页面预期的不一样,多半是版本不匹配。",
|
|
78
|
+
"ADVICE_FOR_CODE.ERR_HTTP_BODY": "请求体不是合法的 JSON,或超过了 64 KiB。",
|
|
79
|
+
"ADVICE_FOR_CODE.ERR_HTTP_FORBIDDEN": "请求被同源栅栏拒绝:Host 不在受信列表里,或 Origin 与 Host 不一致。",
|
|
80
|
+
"ADVICE_FOR_CODE.ERR_HTTP_INTERNAL": "服务端读状态时抛了:通常是宿主服务在自己内部出错。看宿主日志。",
|
|
81
|
+
"ADVICE_FOR_CODE.ERR_HTTP_METHOD": "这个方法用错了:/state 只接受读,/scope 只接受 POST。页面自己不会发错,多半是别的调用方。",
|
|
82
|
+
"ADVICE_FOR_CODE.ERR_HTTP_NOT_FOUND": "插件没有这个子路径:页面与服务端的版本可能不一致。",
|
|
83
|
+
"ADVICE_FOR_CODE.ERR_HTTP_WORKSPACES_UNAVAILABLE": "读不到工作区列表,所以保存被禁用。这不是「没有工作区」——是宿主没有提供注册表,或它读的时候抛错了。",
|
|
84
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_ABORTED": "请求被取消了,磁盘上的文档没有被改动。",
|
|
85
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_FUTURE_VERSION": "磁盘上的文档是更高版本的插件写的,这个版本不敢改它。升级插件。",
|
|
86
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_LOCKED": "另一个进程正拿着写锁。稍后再存一次。",
|
|
87
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_PARSE_FAILED": "磁盘上的文档不是合法的 JSON,这个版本不敢改它。手工检查 boost 目录里的 scope.json。",
|
|
88
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_READ_FAILED": "读不到磁盘上的作用域文档,所以不知道基线是什么。检查 boost 目录的权限。",
|
|
89
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_REVISION_CONFLICT": "磁盘上的文档在别处被改过,这次保存被拒绝。点「重新读取」按新文档重来——你现在的改动会丢,所以由你决定。",
|
|
90
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_UNKNOWN_VERSION": "磁盘上的文档版本无法识别,这个版本不敢改它。手工检查 boost 目录里的 scope.json。",
|
|
91
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_WRITE_FAILED": "写盘失败,磁盘上的文档没有被改动。检查 boost 目录的权限与剩余空间。",
|
|
92
|
+
CONFIG_READONLY: CONFIG_READONLY$1,
|
|
93
|
+
CONFIG_UNAVAILABLE: CONFIG_UNAVAILABLE$1,
|
|
94
|
+
"DEGRADED_ADVICE.ERR_BOOST_PARTIAL_MOUNT": "有钩子没挂上:插件是部分装配的。看宿主日志里的缺失项。",
|
|
95
|
+
"DEGRADED_ADVICE.ERR_BOOST_SECTION_REGISTER_FAILED": "提示段注册失败:协议段没有注入。",
|
|
96
|
+
"DEGRADED_ADVICE.ERR_HOST_COMPLETE_SECTION": "提示段被宿主吞掉了:协议段可能没有到达模型。",
|
|
97
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_ESTIMATOR": "宿主没有估算器:常驻开销只能是未知,别把它当 0。",
|
|
98
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_SPILL": "没有 spill 后端:投影不会发生。装上 dsh-spill 或等价的 spill 服务。",
|
|
99
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_SPILL_NOTICE": "spill 后端在,但页脚产不出来:投影被跳过。检查 spill 通知模块是否被裁剪掉。",
|
|
100
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_TOKENMETER": "没有 token 计量服务:替换被拒绝,投影仍可用但数字标为未测量。",
|
|
101
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_WORKSPACE_REGISTRY": "宿主没有工作区注册表:任何会话都解析不到工作区,插件全程惰性。",
|
|
102
|
+
"DEGRADED_ADVICE.ERR_HOST_PLATFORM_UNSUPPORTED": "这个平台上不启用替换:投影仍然可用。",
|
|
103
|
+
"DEGRADED_ADVICE.ERR_HOST_SELECTOR_UNAVAILABLE": "选择器调不到模型:多候选只能回落到大模型决策。",
|
|
104
|
+
"DEGRADED_ADVICE.ERR_HOST_SPILL_FAILING": "spill 后端在,但每次写都失败:投影被跳过。查后端日志,不是重装。",
|
|
105
|
+
"DEGRADED_ADVICE.ERR_HOST_SPILL_UNUSABLE": "spill 后端存在但不可用(没有 saveText):投影被跳过。",
|
|
106
|
+
"DEGRADED_ADVICE.ERR_HOST_VERSION_MISMATCH": "宿主版本与 engines.dsh 的区间不符:本包没有在这个版本上验证过。",
|
|
107
|
+
"DEGRADED_ADVICE.ERR_HOST_WORKSPACE_REGISTRY_BROKEN": "工作区注册表在,但 list() 抛错:工作区列表读不到。",
|
|
108
|
+
"DEGRADED_ADVICE.ERR_RECEIPTS_TRUNCATED": "收据流超过分片上限,旧分片被丢弃:`boost status` 的合计只覆盖还在的分片。",
|
|
109
|
+
"DEGRADED_ADVICE.ERR_RECEIPTS_UNREADABLE": "有收据分片读不出来:那一部分的账没有算进去,合计偏低。",
|
|
110
|
+
DEGRADED_FALLBACK: DEGRADED_FALLBACK$1,
|
|
111
|
+
EMPTY_GLOBAL: EMPTY_GLOBAL$1,
|
|
112
|
+
EMPTY_SELECTED: EMPTY_SELECTED$1,
|
|
113
|
+
ESTIMATE_HOST: ESTIMATE_HOST$1,
|
|
114
|
+
HINT_DIRTY: HINT_DIRTY$1,
|
|
115
|
+
HINT_NO_WORKSPACES_TO_PICK: HINT_NO_WORKSPACES_TO_PICK$1,
|
|
116
|
+
HINT_OVERHEAD: HINT_OVERHEAD$1,
|
|
117
|
+
HINT_PROJECTION_GROSS_REPLAY: HINT_PROJECTION_GROSS_REPLAY$1,
|
|
118
|
+
HINT_PROJECTION_NET: HINT_PROJECTION_NET$1,
|
|
119
|
+
HINT_PROJECTION_ON_ROLLBACK: HINT_PROJECTION_ON_ROLLBACK$1,
|
|
120
|
+
HINT_PROJECTION_ON_SPILL: HINT_PROJECTION_ON_SPILL$1,
|
|
121
|
+
HINT_SAVED_LOWER: HINT_SAVED_LOWER$1,
|
|
122
|
+
HINT_SAVED_UPPER: HINT_SAVED_UPPER$1,
|
|
123
|
+
HINT_SHADOW_MEANS: HINT_SHADOW_MEANS$1,
|
|
124
|
+
HINT_SUBSTITUTE_ON_ROLLBACK: HINT_SUBSTITUTE_ON_ROLLBACK$1,
|
|
125
|
+
HINT_SUBSTITUTE_ON_THINKING: HINT_SUBSTITUTE_ON_THINKING$1,
|
|
126
|
+
INTRO: INTRO$1,
|
|
127
|
+
LABEL_CONFIG_KEY: LABEL_CONFIG_KEY$1,
|
|
128
|
+
LABEL_CONFIG_VALUE: LABEL_CONFIG_VALUE$1,
|
|
129
|
+
LABEL_DEGRADED: LABEL_DEGRADED$1,
|
|
130
|
+
LABEL_DIRTY: LABEL_DIRTY$1,
|
|
131
|
+
LABEL_ESTIMATE: LABEL_ESTIMATE$1,
|
|
132
|
+
LABEL_MODE: LABEL_MODE$1,
|
|
133
|
+
LABEL_MODE_GLOBAL: LABEL_MODE_GLOBAL$1,
|
|
134
|
+
LABEL_MODE_SELECTED: LABEL_MODE_SELECTED$1,
|
|
135
|
+
LABEL_OVERHEAD: LABEL_OVERHEAD$1,
|
|
136
|
+
LABEL_PROJECTION: LABEL_PROJECTION$1,
|
|
137
|
+
LABEL_PROJECTION_GROSS: LABEL_PROJECTION_GROSS$1,
|
|
138
|
+
LABEL_PROJECTION_GROSS_REPLAY: LABEL_PROJECTION_GROSS_REPLAY$1,
|
|
139
|
+
LABEL_PROJECTION_NET: LABEL_PROJECTION_NET$1,
|
|
140
|
+
LABEL_PROJECTION_ON_PRECONDITIONS: LABEL_PROJECTION_ON_PRECONDITIONS$1,
|
|
141
|
+
LABEL_RETRIEVALS: LABEL_RETRIEVALS$1,
|
|
142
|
+
LABEL_SAVED_LOWER: LABEL_SAVED_LOWER$1,
|
|
143
|
+
LABEL_SAVED_UPPER: LABEL_SAVED_UPPER$1,
|
|
144
|
+
LABEL_SAVE_FAILED: LABEL_SAVE_FAILED$1,
|
|
145
|
+
LABEL_SHADOW: LABEL_SHADOW$1,
|
|
146
|
+
LABEL_STALE_IDS: LABEL_STALE_IDS$1,
|
|
147
|
+
LABEL_SUBSTITUTE_ON_PRECONDITIONS: LABEL_SUBSTITUTE_ON_PRECONDITIONS$1,
|
|
148
|
+
LABEL_UNMATCHED_IDS: LABEL_UNMATCHED_IDS$1,
|
|
149
|
+
LABEL_WORKSPACES: LABEL_WORKSPACES$1,
|
|
150
|
+
LOADING: LOADING$1,
|
|
151
|
+
NO_DEGRADED: NO_DEGRADED$1,
|
|
152
|
+
NO_RECEIPTS: NO_RECEIPTS$1,
|
|
153
|
+
PROJECTION_OFF: PROJECTION_OFF$1,
|
|
154
|
+
PROJECTION_ON: PROJECTION_ON$1,
|
|
155
|
+
PROJECTION_SHADOW: PROJECTION_SHADOW$1,
|
|
156
|
+
RETRY: RETRY$1,
|
|
157
|
+
SAVED: SAVED$1,
|
|
158
|
+
SECTION_CONFIG: SECTION_CONFIG$1,
|
|
159
|
+
SECTION_COUNTS: SECTION_COUNTS$1,
|
|
160
|
+
SECTION_SCOPE: SECTION_SCOPE$1,
|
|
161
|
+
SECTION_STATUS: SECTION_STATUS$1,
|
|
162
|
+
TITLE: TITLE$1,
|
|
163
|
+
UNAVAILABLE_REGISTRY: UNAVAILABLE_REGISTRY$1,
|
|
164
|
+
UNKNOWN: UNKNOWN$1,
|
|
165
|
+
meta: meta$1
|
|
166
|
+
};
|
|
167
|
+
function copyOf(t) {
|
|
168
|
+
const resolved = {};
|
|
169
|
+
for (const key of Object.keys(zh)) {
|
|
170
|
+
if (key === "meta") continue;
|
|
171
|
+
resolved[key] = t(key);
|
|
172
|
+
}
|
|
173
|
+
return resolved;
|
|
174
|
+
}
|
|
175
|
+
function adviceFor(t, code) {
|
|
176
|
+
const direct = t(`ADVICE_FOR_CODE.${code}`);
|
|
177
|
+
if (direct !== `ADVICE_FOR_CODE.${code}`) return direct;
|
|
178
|
+
const degraded = t(`DEGRADED_ADVICE.${code}`);
|
|
179
|
+
if (degraded !== `DEGRADED_ADVICE.${code}`) return degraded;
|
|
180
|
+
return t("DEGRADED_FALLBACK");
|
|
181
|
+
}
|
|
182
|
+
const MODE_VALUE_SELECTED = "selected";
|
|
183
|
+
const MODE_VALUE_GLOBAL = "global";
|
|
184
|
+
const PROJECTION_LABEL = {
|
|
185
|
+
off: "PROJECTION_OFF",
|
|
186
|
+
shadow: "PROJECTION_SHADOW",
|
|
187
|
+
on: "PROJECTION_ON"
|
|
188
|
+
};
|
|
189
|
+
const PROJECTIONS = ["off", "shadow", "on"];
|
|
190
|
+
const isMode = (value) => value === "selected" || value === "global";
|
|
191
|
+
const isProjection = (value) => value === "off" || value === "shadow" || value === "on";
|
|
192
|
+
function seedOf(scope) {
|
|
193
|
+
if (scope === null || typeof scope !== "object") return void 0;
|
|
194
|
+
const envelope = scope;
|
|
195
|
+
if (envelope.ok !== true || envelope.data === null || typeof envelope.data !== "object") return void 0;
|
|
196
|
+
const doc = envelope.data;
|
|
197
|
+
const revision = doc.revision;
|
|
198
|
+
const version2 = doc.version;
|
|
199
|
+
const shadow = doc.shadow;
|
|
200
|
+
const workspaceIds = doc.workspaceIds;
|
|
201
|
+
if (typeof revision !== "number" || !Number.isFinite(revision)) return void 0;
|
|
202
|
+
if (typeof version2 !== "number" || !Number.isFinite(version2)) return void 0;
|
|
203
|
+
if (typeof shadow !== "boolean") return void 0;
|
|
204
|
+
if (!Array.isArray(workspaceIds) || !workspaceIds.every((id) => typeof id === "string")) return void 0;
|
|
205
|
+
if (!isMode(doc.mode) || !isProjection(doc.projection)) return void 0;
|
|
206
|
+
return {
|
|
207
|
+
version: version2,
|
|
208
|
+
revision,
|
|
209
|
+
mode: doc.mode,
|
|
210
|
+
workspaceIds: [...workspaceIds],
|
|
211
|
+
shadow,
|
|
212
|
+
projection: doc.projection
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function draftOf(seed) {
|
|
216
|
+
return patchOf(seed);
|
|
217
|
+
}
|
|
218
|
+
function isDirty(draft, seed) {
|
|
219
|
+
if (draft.mode !== seed.mode) return true;
|
|
220
|
+
if (draft.shadow !== seed.shadow) return true;
|
|
221
|
+
if (draft.projection !== seed.projection) return true;
|
|
222
|
+
if (draft.workspaceIds.length !== seed.workspaceIds.length) return true;
|
|
223
|
+
return draft.workspaceIds.some((id) => !seed.workspaceIds.includes(id));
|
|
224
|
+
}
|
|
225
|
+
const VERSION_CODES = /* @__PURE__ */ new Set([
|
|
226
|
+
"ERR_SCOPE_UNKNOWN_VERSION",
|
|
227
|
+
"ERR_SCOPE_FUTURE_VERSION",
|
|
228
|
+
"ERR_SCOPE_PARSE_FAILED"
|
|
229
|
+
]);
|
|
230
|
+
function disableReasons(scope, workspaces) {
|
|
231
|
+
const reasons = [];
|
|
232
|
+
const envelope = scope ?? {};
|
|
233
|
+
const code = typeof envelope.code === "string" ? envelope.code : "";
|
|
234
|
+
const unreadable = envelope.ok !== true;
|
|
235
|
+
if (unreadable && VERSION_CODES.has(code)) {
|
|
236
|
+
reasons.push({ id: "version-unsupported", code });
|
|
237
|
+
} else if (unreadable) {
|
|
238
|
+
reasons.push({ id: "not-writable", code: code === "" ? "ERR_SCOPE_READ_FAILED" : code });
|
|
239
|
+
}
|
|
240
|
+
if (workspaces !== void 0 && workspaces.available === false) {
|
|
241
|
+
reasons.push({ id: "workspaces-unavailable", code: workspaces.code });
|
|
242
|
+
}
|
|
243
|
+
return reasons;
|
|
244
|
+
}
|
|
245
|
+
function staleWorkspaceIds(seed, workspaces) {
|
|
246
|
+
if (seed === void 0 || workspaces === void 0 || workspaces.available !== true) return [];
|
|
247
|
+
const known = new Set(workspaces.entries.map((entry) => entry.id));
|
|
248
|
+
return seed.workspaceIds.filter((id) => !known.has(id));
|
|
249
|
+
}
|
|
250
|
+
function unmatchedDraftIds(draft, workspaces) {
|
|
251
|
+
if (workspaces === void 0 || workspaces.available !== true) return [];
|
|
252
|
+
const known = new Set(workspaces.entries.map((entry) => entry.id));
|
|
253
|
+
return draft.workspaceIds.filter((id) => !known.has(id));
|
|
254
|
+
}
|
|
255
|
+
function patchOf(draft) {
|
|
256
|
+
return {
|
|
257
|
+
mode: draft.mode,
|
|
258
|
+
workspaceIds: [...draft.workspaceIds],
|
|
259
|
+
shadow: draft.shadow,
|
|
260
|
+
projection: draft.projection
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function isTicked(draft, entry) {
|
|
264
|
+
return draft.workspaceIds.includes(entry.id);
|
|
265
|
+
}
|
|
266
|
+
function toggleTicked(draft, entry) {
|
|
267
|
+
const has = draft.workspaceIds.includes(entry.id);
|
|
268
|
+
return {
|
|
269
|
+
...draft,
|
|
270
|
+
workspaceIds: has ? draft.workspaceIds.filter((id) => id !== entry.id) : [...draft.workspaceIds, entry.id]
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function payloadOf(value) {
|
|
274
|
+
if (value === null || typeof value !== "object") return value;
|
|
275
|
+
const envelope = value;
|
|
276
|
+
return envelope.ok === true ? envelope.data : value;
|
|
277
|
+
}
|
|
278
|
+
const ACTION_REREAD = "Re-read";
|
|
279
|
+
const ACTION_SAVE = "Save";
|
|
280
|
+
const CONFIG_READONLY = "This section is read-only. It shows what resolveConfig decided at load (clamps and fallbacks included); to change it, edit the profile's cordis.patch.yml and restart the host.";
|
|
281
|
+
const CONFIG_UNAVAILABLE = "The effective config could not be read: the route's config was not an object. The page will not render it as an empty table.";
|
|
282
|
+
const DEGRADED_FALLBACK = "Code not in the table: see the stable-code list in docs/RELEASE.md.";
|
|
283
|
+
const EMPTY_GLOBAL = "Every workspace is in scope; the list below is kept only as a record.";
|
|
284
|
+
const EMPTY_SELECTED = "Only selected workspaces are in scope, and none is selected — the plugin does nothing at all.";
|
|
285
|
+
const ESTIMATE_HOST = "Measured by the host";
|
|
286
|
+
const HINT_DIRTY = "Changes are not written yet.";
|
|
287
|
+
const HINT_NO_WORKSPACES_TO_PICK = "The host's registry has no workspaces, so there is nothing to pick.";
|
|
288
|
+
const HINT_OVERHEAD = "Fixed cost per request: the protocol section plus tool schemas. It does not vary by session and no saving offsets it.";
|
|
289
|
+
const HINT_PROJECTION_GROSS_REPLAY = "Each receipt's saving multiplied by its own (1 + horizon), summed. This is the figure the net is derived from.";
|
|
290
|
+
const HINT_PROJECTION_NET = "Net = replay gross − retrieval content cost − retrieval call cost. Replay uses each receipt's own horizon, not the current one; so the two gross figures above are not the same number, and only the replay one lines up with the net.";
|
|
291
|
+
const HINT_PROJECTION_ON_ROLLBACK = 'To roll back, set projection back to `shadow` and save; or call the `boost` tool with `cmd: "scope-set"` and `body: {"projection": "shadow"}`. The change applies to subsequent requests with no host restart.';
|
|
292
|
+
const HINT_PROJECTION_ON_SPILL = "The host has a spill backend. Without one, projection is skipped: `boost status` lists `ERR_HOST_NO_SPILL` among the degraded codes and this page shows the same line.";
|
|
293
|
+
const HINT_SAVED_LOWER = "The lower bound is the skipped request's own total usage: it excludes how many more times it would have been replayed, so the true saving is higher.";
|
|
294
|
+
const HINT_SAVED_UPPER = "The upper bound is the next request's input: it counts the replaced call's result as saved, so the true saving is lower.";
|
|
295
|
+
const HINT_SHADOW_MEANS = "Shadow mode: the plugin still decides and records receipts, but never changes what reaches the model.";
|
|
296
|
+
const HINT_SUBSTITUTE_ON_ROLLBACK = "To roll back, tick shadow mode again and save: substitution stops at once and the projection setting is untouched.";
|
|
297
|
+
const HINT_SUBSTITUTE_ON_THINKING = "Watch for one 400 mentioning `content[].thinking` after the first real substitution. Synthesized turns carry no `replayState`, so the host-side conversion drops the thinking block; whether this route is an Anthropic-compatible thinking mode cannot be determined on this machine and only shows up on a real substitution.";
|
|
298
|
+
const INTRO = "Projection trims tool receipts; deterministic substitution replaces derivable calls. Every number below comes from receipts, not from an estimate: the range gives a lower and an upper bound, and neither is exact.";
|
|
299
|
+
const LABEL_CONFIG_KEY = "Key";
|
|
300
|
+
const LABEL_CONFIG_VALUE = "Effective value";
|
|
301
|
+
const LABEL_DEGRADED = "Degraded";
|
|
302
|
+
const LABEL_DIRTY = "unsaved";
|
|
303
|
+
const LABEL_ESTIMATE = "Measured by";
|
|
304
|
+
const LABEL_MODE = "Mode";
|
|
305
|
+
const LABEL_MODE_GLOBAL = "All workspaces";
|
|
306
|
+
const LABEL_MODE_SELECTED = "Selected workspaces only";
|
|
307
|
+
const LABEL_OVERHEAD = "Fixed overhead";
|
|
308
|
+
const LABEL_PROJECTION = "Projection";
|
|
309
|
+
const LABEL_PROJECTION_GROSS = "Projection gross (one-time)";
|
|
310
|
+
const LABEL_PROJECTION_GROSS_REPLAY = "Projection gross (replayed per horizon)";
|
|
311
|
+
const LABEL_PROJECTION_NET = "Projection net";
|
|
312
|
+
const LABEL_PROJECTION_ON_PRECONDITIONS = "Two things to check before switching projection on";
|
|
313
|
+
const LABEL_RETRIEVALS = "Retrievals";
|
|
314
|
+
const LABEL_SAVED_LOWER = "Substitution saving (lower)";
|
|
315
|
+
const LABEL_SAVED_UPPER = "Substitution saving (upper)";
|
|
316
|
+
const LABEL_SAVE_FAILED = "The save did not take effect:";
|
|
317
|
+
const LABEL_SHADOW = "Shadow mode";
|
|
318
|
+
const LABEL_STALE_IDS = "Saved, but not in the registry";
|
|
319
|
+
const LABEL_SUBSTITUTE_ON_PRECONDITIONS = "One thing to check before switching shadow mode off";
|
|
320
|
+
const LABEL_UNMATCHED_IDS = "Ticked, but not in the registry";
|
|
321
|
+
const LABEL_WORKSPACES = "Workspaces";
|
|
322
|
+
const LOADING = "Loading…";
|
|
323
|
+
const NO_DEGRADED = "Nothing degraded: the host provides every service this plugin needs.";
|
|
324
|
+
const NO_RECEIPTS = "No receipts yet: the plugin has not made a single decision on this host.";
|
|
325
|
+
const PROJECTION_OFF = "Off (no projection)";
|
|
326
|
+
const PROJECTION_ON = "On (real substitution)";
|
|
327
|
+
const PROJECTION_SHADOW = "Shadow (record only)";
|
|
328
|
+
const RETRY = "Retry";
|
|
329
|
+
const SAVED = "Matches the document on disk.";
|
|
330
|
+
const SECTION_CONFIG = "Effective config";
|
|
331
|
+
const SECTION_COUNTS = "Receipt counts";
|
|
332
|
+
const SECTION_SCOPE = "Scope";
|
|
333
|
+
const SECTION_STATUS = "Status";
|
|
334
|
+
const TITLE = "Token efficiency";
|
|
335
|
+
const UNAVAILABLE_REGISTRY = "The scope document could not be read, so this section is read-only for now.";
|
|
336
|
+
const UNKNOWN = "unmeasured";
|
|
337
|
+
const meta = { "description": "Cut DeepSeek Harness token usage by projecting tool receipts and substituting deterministic read-only calls.", "title": "dsh-boost" };
|
|
338
|
+
const en = {
|
|
339
|
+
ACTION_REREAD,
|
|
340
|
+
ACTION_SAVE,
|
|
341
|
+
"ADVICE_FOR_CODE.ERR_BOOST_INTERNAL": "The plugin failed internally. Nothing on disk changed. Check the host log.",
|
|
342
|
+
"ADVICE_FOR_CODE.ERR_BOOST_INVALID_ARGS": "The request is missing a required field.",
|
|
343
|
+
"ADVICE_FOR_CODE.ERR_BOOST_INVALID_BODY": "A field value is invalid, so the whole write was rejected — nothing on disk changed.",
|
|
344
|
+
"ADVICE_FOR_CODE.ERR_CLIENT_NETWORK": "The page could not reach the plugin's route. It may not be mounted — look for webServer in the host log.",
|
|
345
|
+
"ADVICE_FOR_CODE.ERR_CLIENT_SHAPE": "The plugin returned a shape this page does not recognise; most likely a version mismatch.",
|
|
346
|
+
"ADVICE_FOR_CODE.ERR_HTTP_BODY": "The request body is not valid JSON, or exceeds 64 KiB.",
|
|
347
|
+
"ADVICE_FOR_CODE.ERR_HTTP_FORBIDDEN": "The same-origin fence rejected the request: Host is not trusted, or Origin does not match Host.",
|
|
348
|
+
"ADVICE_FOR_CODE.ERR_HTTP_INTERNAL": "The server threw while reading state — usually a host service failing internally. Check the host log.",
|
|
349
|
+
"ADVICE_FOR_CODE.ERR_HTTP_METHOD": "Wrong method: /state only reads, /scope only accepts POST. The page does not send this; another caller does.",
|
|
350
|
+
"ADVICE_FOR_CODE.ERR_HTTP_NOT_FOUND": "The plugin has no such sub-path: page and server versions may disagree.",
|
|
351
|
+
"ADVICE_FOR_CODE.ERR_HTTP_WORKSPACES_UNAVAILABLE": "The workspace list could not be read, so saving is disabled. This is not 'no workspaces' — the host offered no registry, or reading it threw.",
|
|
352
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_ABORTED": "The request was cancelled. Nothing on disk changed.",
|
|
353
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_FUTURE_VERSION": "The document on disk was written by a newer plugin. This version will not touch it. Upgrade the plugin.",
|
|
354
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_LOCKED": "Another process holds the write lock. Save again shortly.",
|
|
355
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_PARSE_FAILED": "The document on disk is not valid JSON. This version will not touch it. Inspect scope.json in the boost directory by hand.",
|
|
356
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_READ_FAILED": "The scope document on disk could not be read, so the baseline is unknown. Check permissions on the boost directory.",
|
|
357
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_REVISION_CONFLICT": "The document on disk changed elsewhere, so this save was rejected. Use 'Re-read' to start from the new document — your unsaved changes are lost, so that call is yours.",
|
|
358
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_UNKNOWN_VERSION": "The document version on disk is unrecognised. This version will not touch it. Inspect scope.json in the boost directory by hand.",
|
|
359
|
+
"ADVICE_FOR_CODE.ERR_SCOPE_WRITE_FAILED": "Writing to disk failed. Nothing on disk changed. Check permissions and free space on the boost directory.",
|
|
360
|
+
CONFIG_READONLY,
|
|
361
|
+
CONFIG_UNAVAILABLE,
|
|
362
|
+
"DEGRADED_ADVICE.ERR_BOOST_PARTIAL_MOUNT": "A hook did not mount: the plugin is only partly wired. Check the host log for the missing item.",
|
|
363
|
+
"DEGRADED_ADVICE.ERR_BOOST_SECTION_REGISTER_FAILED": "Registering the prompt section failed: the protocol section is not injected.",
|
|
364
|
+
"DEGRADED_ADVICE.ERR_HOST_COMPLETE_SECTION": "The host swallowed the prompt section: the protocol text may never reach the model.",
|
|
365
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_ESTIMATOR": "The host has no estimator: fixed overhead can only be unknown. Do not read it as zero.",
|
|
366
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_SPILL": "No spill backend: projection does not happen. Install dsh-spill or an equivalent spill service.",
|
|
367
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_SPILL_NOTICE": "The spill backend is present but the footer cannot be produced, so projection was skipped. Check whether the spill notice module was pruned.",
|
|
368
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_TOKENMETER": "No token meter: substitution is refused; projection still works but its numbers are marked unmeasured.",
|
|
369
|
+
"DEGRADED_ADVICE.ERR_HOST_NO_WORKSPACE_REGISTRY": "The host offers no workspace registry, so no session resolves to a workspace and the plugin stays inert.",
|
|
370
|
+
"DEGRADED_ADVICE.ERR_HOST_PLATFORM_UNSUPPORTED": "Substitution is off on this platform; projection still works.",
|
|
371
|
+
"DEGRADED_ADVICE.ERR_HOST_SELECTOR_UNAVAILABLE": "The selector cannot reach a model: multiple candidates fall back to the main model.",
|
|
372
|
+
"DEGRADED_ADVICE.ERR_HOST_SPILL_FAILING": "The spill backend is present but every write fails, so projection was skipped. Check the backend's log; do not reinstall.",
|
|
373
|
+
"DEGRADED_ADVICE.ERR_HOST_SPILL_UNUSABLE": "The spill backend exists but is unusable (no saveText): projection was skipped.",
|
|
374
|
+
"DEGRADED_ADVICE.ERR_HOST_VERSION_MISMATCH": "The host version is outside engines.dsh: this package was not verified against it.",
|
|
375
|
+
"DEGRADED_ADVICE.ERR_HOST_WORKSPACE_REGISTRY_BROKEN": "The workspace registry exists but list() throws: the workspace list cannot be read.",
|
|
376
|
+
"DEGRADED_ADVICE.ERR_RECEIPTS_TRUNCATED": "The receipt stream passed the shard cap and old shards were dropped: the status totals cover only the shards still present.",
|
|
377
|
+
"DEGRADED_ADVICE.ERR_RECEIPTS_UNREADABLE": "A receipt shard could not be read: its share is missing from the totals, which read low.",
|
|
378
|
+
DEGRADED_FALLBACK,
|
|
379
|
+
EMPTY_GLOBAL,
|
|
380
|
+
EMPTY_SELECTED,
|
|
381
|
+
ESTIMATE_HOST,
|
|
382
|
+
HINT_DIRTY,
|
|
383
|
+
HINT_NO_WORKSPACES_TO_PICK,
|
|
384
|
+
HINT_OVERHEAD,
|
|
385
|
+
HINT_PROJECTION_GROSS_REPLAY,
|
|
386
|
+
HINT_PROJECTION_NET,
|
|
387
|
+
HINT_PROJECTION_ON_ROLLBACK,
|
|
388
|
+
HINT_PROJECTION_ON_SPILL,
|
|
389
|
+
HINT_SAVED_LOWER,
|
|
390
|
+
HINT_SAVED_UPPER,
|
|
391
|
+
HINT_SHADOW_MEANS,
|
|
392
|
+
HINT_SUBSTITUTE_ON_ROLLBACK,
|
|
393
|
+
HINT_SUBSTITUTE_ON_THINKING,
|
|
394
|
+
INTRO,
|
|
395
|
+
LABEL_CONFIG_KEY,
|
|
396
|
+
LABEL_CONFIG_VALUE,
|
|
397
|
+
LABEL_DEGRADED,
|
|
398
|
+
LABEL_DIRTY,
|
|
399
|
+
LABEL_ESTIMATE,
|
|
400
|
+
LABEL_MODE,
|
|
401
|
+
LABEL_MODE_GLOBAL,
|
|
402
|
+
LABEL_MODE_SELECTED,
|
|
403
|
+
LABEL_OVERHEAD,
|
|
404
|
+
LABEL_PROJECTION,
|
|
405
|
+
LABEL_PROJECTION_GROSS,
|
|
406
|
+
LABEL_PROJECTION_GROSS_REPLAY,
|
|
407
|
+
LABEL_PROJECTION_NET,
|
|
408
|
+
LABEL_PROJECTION_ON_PRECONDITIONS,
|
|
409
|
+
LABEL_RETRIEVALS,
|
|
410
|
+
LABEL_SAVED_LOWER,
|
|
411
|
+
LABEL_SAVED_UPPER,
|
|
412
|
+
LABEL_SAVE_FAILED,
|
|
413
|
+
LABEL_SHADOW,
|
|
414
|
+
LABEL_STALE_IDS,
|
|
415
|
+
LABEL_SUBSTITUTE_ON_PRECONDITIONS,
|
|
416
|
+
LABEL_UNMATCHED_IDS,
|
|
417
|
+
LABEL_WORKSPACES,
|
|
418
|
+
LOADING,
|
|
419
|
+
NO_DEGRADED,
|
|
420
|
+
NO_RECEIPTS,
|
|
421
|
+
PROJECTION_OFF,
|
|
422
|
+
PROJECTION_ON,
|
|
423
|
+
PROJECTION_SHADOW,
|
|
424
|
+
RETRY,
|
|
425
|
+
SAVED,
|
|
426
|
+
SECTION_CONFIG,
|
|
427
|
+
SECTION_COUNTS,
|
|
428
|
+
SECTION_SCOPE,
|
|
429
|
+
SECTION_STATUS,
|
|
430
|
+
TITLE,
|
|
431
|
+
UNAVAILABLE_REGISTRY,
|
|
432
|
+
UNKNOWN,
|
|
433
|
+
meta
|
|
434
|
+
};
|
|
435
|
+
const LOCALE_NAMESPACE = "dsh-boost";
|
|
436
|
+
function stringsOf(source) {
|
|
437
|
+
const strings = {};
|
|
438
|
+
for (const [key, value] of Object.entries(source)) {
|
|
439
|
+
if (key !== "meta" && typeof value === "string") strings[key] = value;
|
|
440
|
+
}
|
|
441
|
+
return strings;
|
|
442
|
+
}
|
|
443
|
+
const DICTIONARIES = {
|
|
444
|
+
zh: stringsOf(zh),
|
|
445
|
+
en: stringsOf(en)
|
|
446
|
+
};
|
|
447
|
+
const FALLBACK_LANGUAGE = "zh";
|
|
448
|
+
Object.keys(zh).filter((key) => key !== "meta");
|
|
449
|
+
const fallbackT = (key) => DICTIONARIES[FALLBACK_LANGUAGE]?.[key] ?? key;
|
|
450
|
+
let current = fallbackT;
|
|
451
|
+
let version = 0;
|
|
452
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
453
|
+
function setTranslator(next) {
|
|
454
|
+
current = next;
|
|
455
|
+
version += 1;
|
|
456
|
+
for (const listener of [...listeners]) {
|
|
457
|
+
try {
|
|
458
|
+
listener();
|
|
459
|
+
} catch {
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function subscribe(listener) {
|
|
464
|
+
listeners.add(listener);
|
|
465
|
+
return () => {
|
|
466
|
+
listeners.delete(listener);
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function useT() {
|
|
470
|
+
react.useSyncExternalStore(subscribe, () => version, () => version);
|
|
471
|
+
return current;
|
|
472
|
+
}
|
|
473
|
+
const HTTP_API_PREFIX = "/dsh-boost/api";
|
|
474
|
+
const ERR_CLIENT_NETWORK = "ERR_CLIENT_NETWORK";
|
|
475
|
+
const ERR_CLIENT_SHAPE = "ERR_CLIENT_SHAPE";
|
|
476
|
+
function isWorkspaceListing(value) {
|
|
477
|
+
if (value === null || typeof value !== "object") return false;
|
|
478
|
+
const listing = value;
|
|
479
|
+
if (listing.available === false) return typeof value.code === "string";
|
|
480
|
+
return listing.available === true && Array.isArray(value.entries);
|
|
481
|
+
}
|
|
482
|
+
async function fetchState(signal) {
|
|
483
|
+
let response;
|
|
484
|
+
try {
|
|
485
|
+
response = await fetch(`${HTTP_API_PREFIX}/state`, {
|
|
486
|
+
credentials: "same-origin",
|
|
487
|
+
headers: { accept: "application/json" },
|
|
488
|
+
...signal === void 0 ? {} : { signal }
|
|
489
|
+
});
|
|
490
|
+
} catch (error) {
|
|
491
|
+
if (error instanceof DOMException && error.name === "AbortError") throw error;
|
|
492
|
+
return { ok: false, code: ERR_CLIENT_NETWORK };
|
|
493
|
+
}
|
|
494
|
+
let body;
|
|
495
|
+
try {
|
|
496
|
+
body = await response.json();
|
|
497
|
+
} catch {
|
|
498
|
+
return { ok: false, code: ERR_CLIENT_NETWORK };
|
|
499
|
+
}
|
|
500
|
+
if (!response.ok) {
|
|
501
|
+
const code = body?.error;
|
|
502
|
+
return { ok: false, code: typeof code === "string" ? code : ERR_CLIENT_NETWORK };
|
|
503
|
+
}
|
|
504
|
+
const payload = body;
|
|
505
|
+
if (payload === null || typeof payload !== "object" || !isWorkspaceListing(payload.workspaces)) {
|
|
506
|
+
return { ok: false, code: ERR_CLIENT_SHAPE };
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
ok: true,
|
|
510
|
+
data: {
|
|
511
|
+
status: payload.status,
|
|
512
|
+
scope: payload.scope,
|
|
513
|
+
workspaces: payload.workspaces,
|
|
514
|
+
config: payload.config
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
async function saveScope(patch, baseRevision) {
|
|
519
|
+
let response;
|
|
520
|
+
try {
|
|
521
|
+
response = await fetch(`${HTTP_API_PREFIX}/scope`, {
|
|
522
|
+
method: "POST",
|
|
523
|
+
credentials: "same-origin",
|
|
524
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
525
|
+
body: JSON.stringify({ body: patch, baseRevision })
|
|
526
|
+
});
|
|
527
|
+
} catch {
|
|
528
|
+
return { ok: false, code: ERR_CLIENT_NETWORK };
|
|
529
|
+
}
|
|
530
|
+
let body;
|
|
531
|
+
try {
|
|
532
|
+
body = await response.json();
|
|
533
|
+
} catch {
|
|
534
|
+
return { ok: false, code: ERR_CLIENT_NETWORK };
|
|
535
|
+
}
|
|
536
|
+
if (!response.ok) {
|
|
537
|
+
const code = body?.error;
|
|
538
|
+
return { ok: false, code: typeof code === "string" ? code : ERR_CLIENT_NETWORK };
|
|
539
|
+
}
|
|
540
|
+
return { ok: true, data: body?.data };
|
|
541
|
+
}
|
|
542
|
+
const REREAD_CODES = /* @__PURE__ */ new Set([
|
|
543
|
+
"ERR_SCOPE_REVISION_CONFLICT",
|
|
544
|
+
"ERR_SCOPE_LOCKED",
|
|
545
|
+
"ERR_SCOPE_READ_FAILED",
|
|
546
|
+
"ERR_SCOPE_UNKNOWN_VERSION",
|
|
547
|
+
"ERR_SCOPE_FUTURE_VERSION",
|
|
548
|
+
"ERR_SCOPE_PARSE_FAILED"
|
|
549
|
+
]);
|
|
550
|
+
function BlockedBy({ reasons }) {
|
|
551
|
+
const t = useT();
|
|
552
|
+
if (reasons.length === 0) return null;
|
|
553
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "boost-settings__blockers", children: reasons.map((reason) => /* @__PURE__ */ jsxRuntime.jsxs("li", { "data-reason": reason.id, children: [
|
|
554
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: reason.code }),
|
|
555
|
+
" ",
|
|
556
|
+
adviceFor(t, reason.code)
|
|
557
|
+
] }, reason.id)) });
|
|
558
|
+
}
|
|
559
|
+
function ScopeForm({ payload, scopeCode, onReload }) {
|
|
560
|
+
const t = useT();
|
|
561
|
+
const c = copyOf(t);
|
|
562
|
+
const workspaces = payload.workspaces;
|
|
563
|
+
const [seed, setSeed] = react.useState(() => seedOf(payload.scope));
|
|
564
|
+
const [draft, setDraft] = react.useState(() => {
|
|
565
|
+
const initial = seedOf(payload.scope);
|
|
566
|
+
return initial === void 0 ? void 0 : draftOf(initial);
|
|
567
|
+
});
|
|
568
|
+
const [saving, setSaving] = react.useState(false);
|
|
569
|
+
const [failure, setFailure] = react.useState(void 0);
|
|
570
|
+
react.useEffect(() => {
|
|
571
|
+
const next = seedOf(payload.scope);
|
|
572
|
+
setSeed(next);
|
|
573
|
+
setDraft(next === void 0 ? void 0 : draftOf(next));
|
|
574
|
+
setFailure(void 0);
|
|
575
|
+
}, [payload]);
|
|
576
|
+
const reasons = react.useMemo(() => disableReasons(payload.scope, workspaces), [payload.scope, workspaces]);
|
|
577
|
+
const dirty = draft !== void 0 && seed !== void 0 && isDirty(draft, seed);
|
|
578
|
+
const stale = staleWorkspaceIds(seed, workspaces);
|
|
579
|
+
const unmatched = draft === void 0 ? [] : unmatchedDraftIds(draft, workspaces);
|
|
580
|
+
const entries = workspaces?.available === true ? workspaces.entries : [];
|
|
581
|
+
const update = react.useCallback((patch) => {
|
|
582
|
+
setDraft((current2) => current2 === void 0 ? current2 : { ...current2, ...patch });
|
|
583
|
+
}, []);
|
|
584
|
+
const toggleWorkspace = react.useCallback((entry) => {
|
|
585
|
+
setDraft((current2) => current2 === void 0 ? current2 : toggleTicked(current2, entry));
|
|
586
|
+
}, []);
|
|
587
|
+
const save = react.useCallback(async () => {
|
|
588
|
+
if (draft === void 0 || seed === void 0) return;
|
|
589
|
+
setSaving(true);
|
|
590
|
+
setFailure(void 0);
|
|
591
|
+
const result = await saveScope(patchOf(draft), seed.revision);
|
|
592
|
+
setSaving(false);
|
|
593
|
+
if (result.ok) {
|
|
594
|
+
onReload();
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
setFailure(result.code);
|
|
598
|
+
}, [draft, seed, onReload]);
|
|
599
|
+
if (draft === void 0 || seed === void 0) {
|
|
600
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "boost-settings__section", children: [
|
|
601
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { children: c.SECTION_SCOPE }),
|
|
602
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", "data-code": scopeCode ?? "", children: scopeCode === void 0 ? c.UNAVAILABLE_REGISTRY : adviceFor(t, scopeCode) }),
|
|
603
|
+
/* @__PURE__ */ jsxRuntime.jsx(BlockedBy, { reasons })
|
|
604
|
+
] });
|
|
605
|
+
}
|
|
606
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "boost-settings__section", children: [
|
|
607
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { children: c.SECTION_SCOPE }),
|
|
608
|
+
/* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "boost-settings__field", children: [
|
|
609
|
+
/* @__PURE__ */ jsxRuntime.jsx("legend", { children: c.LABEL_MODE }),
|
|
610
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
611
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
612
|
+
"input",
|
|
613
|
+
{
|
|
614
|
+
type: "radio",
|
|
615
|
+
name: "boost-mode",
|
|
616
|
+
checked: draft.mode === MODE_VALUE_SELECTED,
|
|
617
|
+
onChange: () => update({ mode: MODE_VALUE_SELECTED })
|
|
618
|
+
}
|
|
619
|
+
),
|
|
620
|
+
c.LABEL_MODE_SELECTED
|
|
621
|
+
] }),
|
|
622
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
623
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
624
|
+
"input",
|
|
625
|
+
{
|
|
626
|
+
type: "radio",
|
|
627
|
+
name: "boost-mode",
|
|
628
|
+
checked: draft.mode === MODE_VALUE_GLOBAL,
|
|
629
|
+
onChange: () => update({ mode: MODE_VALUE_GLOBAL })
|
|
630
|
+
}
|
|
631
|
+
),
|
|
632
|
+
c.LABEL_MODE_GLOBAL
|
|
633
|
+
] }),
|
|
634
|
+
draft.mode === MODE_VALUE_GLOBAL ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.EMPTY_GLOBAL }) : draft.workspaceIds.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.EMPTY_SELECTED }) : null
|
|
635
|
+
] }),
|
|
636
|
+
/* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "boost-settings__field", disabled: draft.mode === MODE_VALUE_GLOBAL, children: [
|
|
637
|
+
/* @__PURE__ */ jsxRuntime.jsx("legend", { children: c.LABEL_WORKSPACES }),
|
|
638
|
+
workspaces?.available === false ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", "data-code": workspaces.code, children: adviceFor(t, workspaces.code) }) : entries.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.HINT_NO_WORKSPACES_TO_PICK }) : entries.map((entry) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "boost-settings__workspace", children: [
|
|
639
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
640
|
+
"input",
|
|
641
|
+
{
|
|
642
|
+
type: "checkbox",
|
|
643
|
+
checked: isTicked(draft, entry),
|
|
644
|
+
onChange: () => toggleWorkspace(entry)
|
|
645
|
+
}
|
|
646
|
+
),
|
|
647
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: entry.path })
|
|
648
|
+
] }, entry.id))
|
|
649
|
+
] }),
|
|
650
|
+
/* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "boost-settings__field", children: [
|
|
651
|
+
/* @__PURE__ */ jsxRuntime.jsx("legend", { children: c.LABEL_SHADOW }),
|
|
652
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
654
|
+
"input",
|
|
655
|
+
{
|
|
656
|
+
type: "checkbox",
|
|
657
|
+
checked: draft.shadow,
|
|
658
|
+
onChange: () => update({ shadow: !draft.shadow })
|
|
659
|
+
}
|
|
660
|
+
),
|
|
661
|
+
c.LABEL_SHADOW
|
|
662
|
+
] })
|
|
663
|
+
] }),
|
|
664
|
+
/* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "boost-settings__field", children: [
|
|
665
|
+
/* @__PURE__ */ jsxRuntime.jsx("legend", { children: c.LABEL_PROJECTION }),
|
|
666
|
+
PROJECTIONS.map((option) => /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
667
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
668
|
+
"input",
|
|
669
|
+
{
|
|
670
|
+
type: "radio",
|
|
671
|
+
name: "boost-projection",
|
|
672
|
+
checked: draft.projection === option,
|
|
673
|
+
onChange: () => update({ projection: option })
|
|
674
|
+
}
|
|
675
|
+
),
|
|
676
|
+
c[PROJECTION_LABEL[option] ?? "PROJECTION_OFF"]
|
|
677
|
+
] }, option))
|
|
678
|
+
] }),
|
|
679
|
+
draft.projection === "on" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__notice", role: "note", "data-notice": "projection-on", children: [
|
|
680
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: c.LABEL_PROJECTION_ON_PRECONDITIONS }),
|
|
681
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { children: /* @__PURE__ */ jsxRuntime.jsx("li", { children: c.HINT_PROJECTION_ON_SPILL }) }),
|
|
682
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: c.HINT_PROJECTION_ON_ROLLBACK })
|
|
683
|
+
] }) : null,
|
|
684
|
+
draft.shadow ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.HINT_SHADOW_MEANS }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__notice", role: "note", "data-notice": "substitute-on", children: [
|
|
685
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: c.LABEL_SUBSTITUTE_ON_PRECONDITIONS }),
|
|
686
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { children: /* @__PURE__ */ jsxRuntime.jsx("li", { children: c.HINT_SUBSTITUTE_ON_THINKING }) }),
|
|
687
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: c.HINT_SUBSTITUTE_ON_ROLLBACK })
|
|
688
|
+
] }),
|
|
689
|
+
stale.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__diagnostic", "data-diagnostic": "stale", children: [
|
|
690
|
+
/* @__PURE__ */ jsxRuntime.jsx("h4", { children: c.LABEL_STALE_IDS }),
|
|
691
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { children: stale.map((id) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: id }, id)) })
|
|
692
|
+
] }) : null,
|
|
693
|
+
unmatched.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__diagnostic", "data-diagnostic": "unmatched", children: [
|
|
694
|
+
/* @__PURE__ */ jsxRuntime.jsx("h4", { children: c.LABEL_UNMATCHED_IDS }),
|
|
695
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { children: unmatched.map((id) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: id }, id)) })
|
|
696
|
+
] }) : null,
|
|
697
|
+
/* @__PURE__ */ jsxRuntime.jsx(BlockedBy, { reasons }),
|
|
698
|
+
failure !== void 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__failure", role: "alert", "data-code": failure, children: [
|
|
699
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
700
|
+
c.LABEL_SAVE_FAILED,
|
|
701
|
+
" ",
|
|
702
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: failure })
|
|
703
|
+
] }),
|
|
704
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: adviceFor(t, failure) }),
|
|
705
|
+
REREAD_CODES.has(failure) ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => onReload(), children: c.ACTION_REREAD }) : null
|
|
706
|
+
] }) : null,
|
|
707
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__actions", children: [
|
|
708
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
709
|
+
"button",
|
|
710
|
+
{
|
|
711
|
+
type: "button",
|
|
712
|
+
disabled: reasons.length > 0 || !dirty || saving,
|
|
713
|
+
onClick: () => void save(),
|
|
714
|
+
children: c.ACTION_SAVE
|
|
715
|
+
}
|
|
716
|
+
),
|
|
717
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "boost-settings__muted", "data-dirty": dirty ? "true" : "false", children: dirty ? c.HINT_DIRTY : c.SAVED }),
|
|
718
|
+
dirty ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "boost-settings__badge", children: c.LABEL_DIRTY }) : null
|
|
719
|
+
] })
|
|
720
|
+
] });
|
|
721
|
+
}
|
|
722
|
+
function tokens(c, value) {
|
|
723
|
+
if (value === "unknown" || value === void 0 || value === null) return c.UNKNOWN;
|
|
724
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return c.UNKNOWN;
|
|
725
|
+
return value.toLocaleString();
|
|
726
|
+
}
|
|
727
|
+
function pick(source, ...path) {
|
|
728
|
+
let cursor = source;
|
|
729
|
+
for (const key of path) {
|
|
730
|
+
if (cursor === null || typeof cursor !== "object") return void 0;
|
|
731
|
+
cursor = cursor[key];
|
|
732
|
+
}
|
|
733
|
+
return cursor;
|
|
734
|
+
}
|
|
735
|
+
function flatten(source, prefix = "") {
|
|
736
|
+
if (source === null || typeof source !== "object") {
|
|
737
|
+
return prefix === "" ? [] : [[prefix, typeof source === "string" ? source : JSON.stringify(source) ?? ""]];
|
|
738
|
+
}
|
|
739
|
+
if (Array.isArray(source)) return [[prefix, source.join(", ")]];
|
|
740
|
+
const rows = [];
|
|
741
|
+
for (const [key, value] of Object.entries(source)) {
|
|
742
|
+
rows.push(...flatten(value, prefix === "" ? key : `${prefix}.${key}`));
|
|
743
|
+
}
|
|
744
|
+
return rows;
|
|
745
|
+
}
|
|
746
|
+
function Row({ label, value, hint }) {
|
|
747
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__row", children: [
|
|
748
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { children: label }),
|
|
749
|
+
/* @__PURE__ */ jsxRuntime.jsxs("dd", { children: [
|
|
750
|
+
value,
|
|
751
|
+
hint === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "boost-settings__hint", children: hint })
|
|
752
|
+
] })
|
|
753
|
+
] });
|
|
754
|
+
}
|
|
755
|
+
function Section({ title, children, rows = true }) {
|
|
756
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "boost-settings__section", children: [
|
|
757
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { children: title }),
|
|
758
|
+
rows ? /* @__PURE__ */ jsxRuntime.jsx("dl", { children }) : children
|
|
759
|
+
] });
|
|
760
|
+
}
|
|
761
|
+
function Degraded({ codes }) {
|
|
762
|
+
const t = useT();
|
|
763
|
+
const c = copyOf(t);
|
|
764
|
+
if (codes.length === 0) {
|
|
765
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__ok", children: c.NO_DEGRADED });
|
|
766
|
+
}
|
|
767
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "boost-settings__codes", children: codes.map((code) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
768
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: code }),
|
|
769
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: adviceFor(t, code) })
|
|
770
|
+
] }, code)) });
|
|
771
|
+
}
|
|
772
|
+
function App() {
|
|
773
|
+
const [result, setResult] = react.useState(void 0);
|
|
774
|
+
const [pending, setPending] = react.useState(true);
|
|
775
|
+
const t = useT();
|
|
776
|
+
const c = copyOf(t);
|
|
777
|
+
const load = react.useCallback(() => {
|
|
778
|
+
const controller = new AbortController();
|
|
779
|
+
setPending(true);
|
|
780
|
+
void fetchState(controller.signal).then((next) => {
|
|
781
|
+
setResult(next);
|
|
782
|
+
setPending(false);
|
|
783
|
+
}).catch(() => {
|
|
784
|
+
setPending(false);
|
|
785
|
+
});
|
|
786
|
+
return () => controller.abort();
|
|
787
|
+
}, []);
|
|
788
|
+
react.useEffect(load, [load]);
|
|
789
|
+
const status = payloadOf(result?.ok === true ? result.data.status : void 0);
|
|
790
|
+
const scope = result?.ok === true ? result.data.scope : void 0;
|
|
791
|
+
const config = payloadOf(result?.ok === true ? result.data.config : void 0);
|
|
792
|
+
const saved = pick(status, "saved");
|
|
793
|
+
const degraded = pick(status, "degraded");
|
|
794
|
+
const codes = Array.isArray(degraded) ? degraded.filter((code) => typeof code === "string") : [];
|
|
795
|
+
const counts = pick(status, "counts");
|
|
796
|
+
const countRows = counts === null || typeof counts !== "object" ? [] : Object.entries(counts).filter((entry) => typeof entry[1] === "number" && Number.isFinite(entry[1])).sort((left, right) => right[1] - left[1]);
|
|
797
|
+
const configRows = flatten(config);
|
|
798
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings", children: [
|
|
799
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { children: c.TITLE }),
|
|
800
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__intro", children: c.INTRO }),
|
|
801
|
+
pending && result === void 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.LOADING }) : null,
|
|
802
|
+
result !== void 0 && !result.ok ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "boost-settings__error", role: "alert", children: [
|
|
803
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: result.code }),
|
|
804
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: adviceFor(t, result.code) }),
|
|
805
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => load(), children: c.RETRY })
|
|
806
|
+
] }) : null,
|
|
807
|
+
result !== void 0 && result.ok ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
808
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Section, { title: c.SECTION_STATUS, children: [
|
|
809
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: c.LABEL_SAVED_LOWER, value: tokens(c, pick(saved, "substitution_avoided")), hint: c.HINT_SAVED_LOWER }),
|
|
810
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: c.LABEL_SAVED_UPPER, value: tokens(c, pick(saved, "substitution")), hint: c.HINT_SAVED_UPPER }),
|
|
811
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: c.LABEL_PROJECTION_GROSS, value: tokens(c, pick(status, "projection_gross_tokens")) }),
|
|
812
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
813
|
+
Row,
|
|
814
|
+
{
|
|
815
|
+
label: c.LABEL_PROJECTION_GROSS_REPLAY,
|
|
816
|
+
value: tokens(c, pick(saved, "projectionGross")),
|
|
817
|
+
hint: c.HINT_PROJECTION_GROSS_REPLAY
|
|
818
|
+
}
|
|
819
|
+
),
|
|
820
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: c.LABEL_PROJECTION_NET, value: tokens(c, pick(saved, "projectionNet")), hint: c.HINT_PROJECTION_NET }),
|
|
821
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: c.LABEL_RETRIEVALS, value: tokens(c, pick(saved, "retrievals")) }),
|
|
822
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: c.LABEL_OVERHEAD, value: tokens(c, pick(status, "fixedOverheadTokens")), hint: c.HINT_OVERHEAD }),
|
|
823
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
824
|
+
Row,
|
|
825
|
+
{
|
|
826
|
+
label: c.LABEL_ESTIMATE,
|
|
827
|
+
value: pick(status, "estimate_kind") === "host" ? c.ESTIMATE_HOST : c.UNKNOWN
|
|
828
|
+
}
|
|
829
|
+
)
|
|
830
|
+
] }),
|
|
831
|
+
result.ok === true ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
832
|
+
ScopeForm,
|
|
833
|
+
{
|
|
834
|
+
payload: result.data,
|
|
835
|
+
scopeCode: pick(scope, "code"),
|
|
836
|
+
onReload: () => load()
|
|
837
|
+
}
|
|
838
|
+
) : null,
|
|
839
|
+
/* @__PURE__ */ jsxRuntime.jsx(Section, { title: c.LABEL_DEGRADED, rows: false, children: /* @__PURE__ */ jsxRuntime.jsx(Degraded, { codes }) }),
|
|
840
|
+
/* @__PURE__ */ jsxRuntime.jsx(Section, { title: c.SECTION_COUNTS, rows: false, children: countRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.NO_RECEIPTS }) : /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "boost-settings__codes", children: countRows.map(([code, count]) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
|
|
841
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: code }),
|
|
842
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: count.toLocaleString() })
|
|
843
|
+
] }, code)) }) }),
|
|
844
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Section, { title: c.SECTION_CONFIG, rows: false, children: [
|
|
845
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__hint", children: c.CONFIG_READONLY }),
|
|
846
|
+
configRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "boost-settings__muted", children: c.CONFIG_UNAVAILABLE }) : /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "boost-settings__config", children: [
|
|
847
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
848
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: c.LABEL_CONFIG_KEY }),
|
|
849
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: c.LABEL_CONFIG_VALUE })
|
|
850
|
+
] }) }),
|
|
851
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: configRows.map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
852
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: key }) }),
|
|
853
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: value })
|
|
854
|
+
] }, key)) })
|
|
855
|
+
] })
|
|
856
|
+
] })
|
|
857
|
+
] }) : null
|
|
858
|
+
] });
|
|
859
|
+
}
|
|
860
|
+
const styles = "/**\n * The settings page's own styles.\n *\n * SCOPED DELIBERATELY. This stylesheet is injected into the HOST page's\n * document head, not a sandboxed frame, so a bare `button {}` rule restyles\n * every button in the host UI — a plugin must not do that. Every top-level\n * selector in this file is therefore rooted at a plugin-owned class in the\n * `boost-` namespace.\n */\n.boost-settings {\n display: flex;\n flex-direction: column;\n gap: 20px;\n padding: 16px;\n color: inherit;\n font-size: 13px;\n line-height: 1.6;\n}\n\n.boost-settings h2 {\n margin: 0;\n font-size: 16px;\n}\n\n.boost-settings__intro {\n margin: 0 0 1rem;\n color: var(--dsh-text-secondary, #5a5a5f);\n line-height: 1.6;\n}\n\n.boost-settings__section {\n margin: 0 0 1.25rem;\n}\n\n.boost-settings__section h3 {\n margin: 0 0 0.5rem;\n font-size: 0.95rem;\n font-weight: 600;\n}\n\n.boost-settings__row {\n display: grid;\n grid-template-columns: minmax(8rem, 14rem) 1fr;\n gap: 0.5rem 1rem;\n padding: 0.25rem 0;\n border-bottom: 1px solid var(--dsh-border, #e6e6e8);\n}\n\n.boost-settings__row dt {\n color: var(--dsh-text-secondary, #5a5a5f);\n}\n\n.boost-settings__row dd {\n margin: 0;\n font-variant-numeric: tabular-nums;\n}\n\n.boost-settings__hint {\n display: block;\n margin-top: 0.25rem;\n font-size: 0.85rem;\n color: var(--dsh-text-secondary, #5a5a5f);\n font-variant-numeric: normal;\n}\n\n.boost-settings__ok,\n.boost-settings__muted {\n color: var(--dsh-text-secondary, #5a5a5f);\n}\n\n.boost-settings__codes {\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.boost-settings__codes li {\n display: flex;\n flex-direction: column;\n gap: 0.15rem;\n padding: 0.4rem 0;\n border-bottom: 1px solid var(--dsh-border, #e6e6e8);\n}\n\n.boost-settings__error {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 0.5rem;\n padding: 0.6rem 0.75rem;\n border: 1px solid var(--dsh-danger, #c0392b);\n border-radius: 6px;\n}\n\n.boost-settings__workspaces {\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.boost-settings__workspaces li {\n display: flex;\n gap: 0.75rem;\n padding: 0.3rem 0;\n}\n\n.boost-settings__workspaces li.is-selected {\n font-weight: 600;\n}\n\n.boost-settings__config {\n width: 100%;\n border-collapse: collapse;\n}\n\n.boost-settings__config th,\n.boost-settings__config td {\n text-align: left;\n padding: 0.25rem 0.5rem 0.25rem 0;\n border-bottom: 1px solid var(--dsh-border, #e6e6e8);\n font-variant-numeric: tabular-nums;\n}\n";
|
|
861
|
+
const SETTINGS_SLOT = "settings.section";
|
|
862
|
+
const WARN_PREFIX = "dsh-boost";
|
|
863
|
+
const SETTINGS_ID = "boost";
|
|
864
|
+
const inject = ["slots"];
|
|
865
|
+
function installStyles() {
|
|
866
|
+
const node = document.createElement("style");
|
|
867
|
+
node.setAttribute("data-boost-styles", "");
|
|
868
|
+
node.textContent = styles;
|
|
869
|
+
document.head.append(node);
|
|
870
|
+
return () => node.remove();
|
|
871
|
+
}
|
|
872
|
+
function installTranslator(ctx) {
|
|
873
|
+
const locale = ctx.get?.("locale");
|
|
874
|
+
if (locale === void 0) {
|
|
875
|
+
console.warn(`[${WARN_PREFIX}] host has no locale service; the page stays readable but will not follow the host language`);
|
|
876
|
+
}
|
|
877
|
+
if (locale !== void 0) {
|
|
878
|
+
try {
|
|
879
|
+
ctx.effect?.(() => locale.register(LOCALE_NAMESPACE, DICTIONARIES), `${WARN_PREFIX}: dictionaries`);
|
|
880
|
+
const bound = locale.bind(LOCALE_NAMESPACE);
|
|
881
|
+
setTranslator(bound);
|
|
882
|
+
ctx.effect?.(
|
|
883
|
+
() => locale.subscribe?.(() => setTranslator(locale.bind(LOCALE_NAMESPACE))) ?? (() => {
|
|
884
|
+
}),
|
|
885
|
+
`${WARN_PREFIX}: locale subscription`
|
|
886
|
+
);
|
|
887
|
+
return bound;
|
|
888
|
+
} catch (error) {
|
|
889
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
890
|
+
console.warn(
|
|
891
|
+
`[${WARN_PREFIX}] host locale service rejected the dictionaries (${message}); registering the section without a locale namespace and using the built-in translator`
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
setTranslator(fallbackT);
|
|
896
|
+
return fallbackT;
|
|
897
|
+
}
|
|
898
|
+
function apply(ctx) {
|
|
899
|
+
ctx.effect?.(() => installStyles(), `${WARN_PREFIX}: settings styles`);
|
|
900
|
+
const t = installTranslator(ctx);
|
|
901
|
+
if (ctx.slots === void 0) {
|
|
902
|
+
console.warn(`[${WARN_PREFIX}] client slots service unavailable; settings page not registered`);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const slots = ctx.slots;
|
|
906
|
+
slots.inject(
|
|
907
|
+
SETTINGS_SLOT,
|
|
908
|
+
() => slots.register(
|
|
909
|
+
{
|
|
910
|
+
name: SETTINGS_SLOT,
|
|
911
|
+
id: SETTINGS_ID,
|
|
912
|
+
order: 50,
|
|
913
|
+
// A thunk, not a string: the shell re-reads it when the locale changes,
|
|
914
|
+
// so the nav item follows the language without this plugin subscribing.
|
|
915
|
+
label: () => t("TITLE"),
|
|
916
|
+
inject: () => ({})
|
|
917
|
+
},
|
|
918
|
+
App
|
|
919
|
+
)
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
exports.SETTINGS_ID = SETTINGS_ID;
|
|
923
|
+
exports.SETTINGS_SLOT = SETTINGS_SLOT;
|
|
924
|
+
exports.WARN_PREFIX = WARN_PREFIX;
|
|
925
|
+
exports.apply = apply;
|
|
926
|
+
exports.inject = inject;
|
|
927
|
+
return module.exports;
|
|
928
|
+
}
|
|
929
|
+
});
|