dsh-jev-tools-continued 0.0.0-stage → 0.2.0
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.en.md +449 -0
- package/CHANGELOG.i18n.yaml +13 -0
- package/CHANGELOG.md +357 -0
- package/LICENSE +21 -0
- package/README.en.md +210 -0
- package/README.i18n.yaml +13 -0
- package/README.md +209 -2
- package/client/client.js +755 -0
- package/cordis.patch.yml +30 -0
- package/docs/banner.png +0 -0
- package/docs/dev-workflow.md +414 -0
- package/docs/s0-trigger-rate.md +168 -0
- package/icon.svg +16 -0
- package/lib/backends/jev.d.ts +69 -0
- package/lib/backends/jev.d.ts.map +1 -0
- package/lib/backends/jev.js +151 -0
- package/lib/backends/jev.js.map +1 -0
- package/lib/backends/types.d.ts +104 -0
- package/lib/backends/types.d.ts.map +1 -0
- package/lib/backends/types.js +12 -0
- package/lib/backends/types.js.map +1 -0
- package/lib/budget.d.ts +60 -0
- package/lib/budget.d.ts.map +1 -0
- package/lib/budget.js +70 -0
- package/lib/budget.js.map +1 -0
- package/lib/calibrate.d.ts +162 -0
- package/lib/calibrate.d.ts.map +1 -0
- package/lib/calibrate.js +269 -0
- package/lib/calibrate.js.map +1 -0
- package/lib/config.d.ts +261 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +194 -0
- package/lib/config.js.map +1 -0
- package/lib/context-cache.d.ts +59 -0
- package/lib/context-cache.d.ts.map +1 -0
- package/lib/context-cache.js +116 -0
- package/lib/context-cache.js.map +1 -0
- package/lib/credentials.d.ts +32 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +44 -0
- package/lib/credentials.js.map +1 -0
- package/lib/degrade.d.ts +36 -0
- package/lib/degrade.d.ts.map +1 -0
- package/lib/degrade.js +41 -0
- package/lib/degrade.js.map +1 -0
- package/lib/features/prune.d.ts +116 -0
- package/lib/features/prune.d.ts.map +1 -0
- package/lib/features/prune.js +574 -0
- package/lib/features/prune.js.map +1 -0
- package/lib/features/screen.d.ts +112 -0
- package/lib/features/screen.d.ts.map +1 -0
- package/lib/features/screen.js +130 -0
- package/lib/features/screen.js.map +1 -0
- package/lib/features/skill-suggest.d.ts +68 -0
- package/lib/features/skill-suggest.d.ts.map +1 -0
- package/lib/features/skill-suggest.js +283 -0
- package/lib/features/skill-suggest.js.map +1 -0
- package/lib/host.d.ts +280 -0
- package/lib/host.d.ts.map +1 -0
- package/lib/host.js +15 -0
- package/lib/host.js.map +1 -0
- package/lib/http.d.ts +71 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +162 -0
- package/lib/http.js.map +1 -0
- package/lib/i18n.d.ts +372 -0
- package/lib/i18n.d.ts.map +1 -0
- package/lib/i18n.js +254 -0
- package/lib/i18n.js.map +1 -0
- package/lib/index.d.ts +44 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +268 -0
- package/lib/index.js.map +1 -0
- package/lib/keys.d.ts +90 -0
- package/lib/keys.d.ts.map +1 -0
- package/lib/keys.js +131 -0
- package/lib/keys.js.map +1 -0
- package/lib/ledger-domain.d.ts +169 -0
- package/lib/ledger-domain.d.ts.map +1 -0
- package/lib/ledger-domain.js +338 -0
- package/lib/ledger-domain.js.map +1 -0
- package/lib/ledger.d.ts +243 -0
- package/lib/ledger.d.ts.map +1 -0
- package/lib/ledger.js +239 -0
- package/lib/ledger.js.map +1 -0
- package/lib/memo.d.ts +32 -0
- package/lib/memo.d.ts.map +1 -0
- package/lib/memo.js +62 -0
- package/lib/memo.js.map +1 -0
- package/lib/notify.d.ts +78 -0
- package/lib/notify.d.ts.map +1 -0
- package/lib/notify.js +122 -0
- package/lib/notify.js.map +1 -0
- package/lib/proxy.d.ts +40 -0
- package/lib/proxy.d.ts.map +1 -0
- package/lib/proxy.js +136 -0
- package/lib/proxy.js.map +1 -0
- package/lib/request.d.ts +99 -0
- package/lib/request.d.ts.map +1 -0
- package/lib/request.js +168 -0
- package/lib/request.js.map +1 -0
- package/lib/source.d.ts +46 -0
- package/lib/source.d.ts.map +1 -0
- package/lib/source.js +35 -0
- package/lib/source.js.map +1 -0
- package/lib/status.d.ts +42 -0
- package/lib/status.d.ts.map +1 -0
- package/lib/status.js +214 -0
- package/lib/status.js.map +1 -0
- package/lib/tokens.d.ts +26 -0
- package/lib/tokens.d.ts.map +1 -0
- package/lib/tokens.js +57 -0
- package/lib/tokens.js.map +1 -0
- package/lib/tools/jev-ask.d.ts +44 -0
- package/lib/tools/jev-ask.d.ts.map +1 -0
- package/lib/tools/jev-ask.js +208 -0
- package/lib/tools/jev-ask.js.map +1 -0
- package/lib/tools/jev-gate.d.ts +79 -0
- package/lib/tools/jev-gate.d.ts.map +1 -0
- package/lib/tools/jev-gate.js +412 -0
- package/lib/tools/jev-gate.js.map +1 -0
- package/package.json +169 -4
package/lib/config.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin settings schema.
|
|
3
|
+
*
|
|
4
|
+
* Every default here is a *measured* decision, not a guess — see
|
|
5
|
+
* `docs/s0-trigger-rate.md` for the numbers behind `minTokens`, `perTurnLimit`
|
|
6
|
+
* and `minCatalogSize`.
|
|
7
|
+
*
|
|
8
|
+
* The settings *namespace* is not declared here: DSH derives it from the mount
|
|
9
|
+
* row id (`cordis.patch.yml`), which therefore has to equal this package's name —
|
|
10
|
+
* that is the address the bundle's own card reads and writes.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-jev-tools/config
|
|
13
|
+
*/
|
|
14
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
15
|
+
import { isVolatile } from '@deepseek-ai/cosmokit';
|
|
16
|
+
/**
|
|
17
|
+
* Read a resolved config value out of its volatile marker.
|
|
18
|
+
*
|
|
19
|
+
* `.volatile()` marks a field as editable from the settings page, and resolving a
|
|
20
|
+
* marked schema wraps that field's value in a marker object — which is how the
|
|
21
|
+
* writer knows which keys it may persist to the profile patch. This plugin only
|
|
22
|
+
* ever wants the *value*, so the marker is unwrapped recursively. It is the same
|
|
23
|
+
* projection the settings provider performs before drawing a form
|
|
24
|
+
* (`plainConfig` in `@deepseek-ai/dsh-settings`), and the reason a first-party
|
|
25
|
+
* plugin can read `config.baseURL` as a string while its schema marks that field
|
|
26
|
+
* volatile.
|
|
27
|
+
*
|
|
28
|
+
* @param value - a resolved config value, possibly marked.
|
|
29
|
+
* @returns the same value with every marker replaced by what it carries.
|
|
30
|
+
*/
|
|
31
|
+
function plainConfig(value) {
|
|
32
|
+
if (isVolatile(value))
|
|
33
|
+
return plainConfig(value.get());
|
|
34
|
+
if (Array.isArray(value))
|
|
35
|
+
return value.map(item => plainConfig(item));
|
|
36
|
+
if (value !== null && typeof value === 'object') {
|
|
37
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, plainConfig(child)]));
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/** Where a user creates a TypeSafe API key. Shown as a link in the settings card. */
|
|
42
|
+
export const TYPESAFE_KEYS_URL = 'https://console.typesafe.ai/keys';
|
|
43
|
+
/**
|
|
44
|
+
* Default System One API root, as a bare host.
|
|
45
|
+
*
|
|
46
|
+
* The path (`/v1/systemone`) is appended by the backend, so this must not carry
|
|
47
|
+
* one. It is a *default*, not the only endpoint: `backends/jev.ts` has always
|
|
48
|
+
* accepted an override, so a self-hosted Jev-compatible server — or a deployment
|
|
49
|
+
* that puts a gateway in front — needs the endpoint to be a setting rather than a
|
|
50
|
+
* constant. Declaring the default once, here, is also what lets the settings
|
|
51
|
+
* schema use exactly the value the backend falls back to.
|
|
52
|
+
*/
|
|
53
|
+
export const DEFAULT_BASE_URL = 'https://api.typesafe.ai';
|
|
54
|
+
/**
|
|
55
|
+
* Default credential reference.
|
|
56
|
+
*
|
|
57
|
+
* Deliberately the same environment variable the official TypeSafe SDK reads,
|
|
58
|
+
* so anyone already using Jev with the official tooling works with no setup.
|
|
59
|
+
*/
|
|
60
|
+
export const DEFAULT_API_KEY_ENV = 'TYPESAFE_API_KEY';
|
|
61
|
+
/**
|
|
62
|
+
* Tools whose bulk output is worth judging for relevance.
|
|
63
|
+
*
|
|
64
|
+
* Measured: at `minTokens` 2000 these covered 76% of oversized results.
|
|
65
|
+
* `pwsh` is deliberately absent — terminal output carries build logs, error
|
|
66
|
+
* traces and file listings whose "irrelevant" parts are often exactly what a
|
|
67
|
+
* debugging step needs, so a cheap judgment must not trim them.
|
|
68
|
+
*/
|
|
69
|
+
export const DEFAULT_TOOL_ALLOWLIST = ['read', 'grep', 'glob', 'web_fetch', 'web_search'];
|
|
70
|
+
/**
|
|
71
|
+
* Tools whose output is **not** the user's own material.
|
|
72
|
+
*
|
|
73
|
+
* Screening exists because fetched content is untrusted input: a page can carry
|
|
74
|
+
* text aimed at the agent reading it. Local files are deliberately excluded by
|
|
75
|
+
* default — they are the user's own material, they are read far more often, and
|
|
76
|
+
* screening them would spend the per-turn budget that pruning needs. A user who
|
|
77
|
+
* clones untrusted repositories can add `read` themselves.
|
|
78
|
+
*/
|
|
79
|
+
export const DEFAULT_SCREEN_ALLOWLIST = ['web_fetch', 'web_search'];
|
|
80
|
+
/**
|
|
81
|
+
* Composition-entry schema.
|
|
82
|
+
*
|
|
83
|
+
* Also the declaration a configuration surface dispatches on — and **only fields
|
|
84
|
+
* marked `.volatile()` reach that surface**. `SettingsForms.describe()` derives
|
|
85
|
+
* the form through `volatileForm()`, which returns nothing when a schema has no
|
|
86
|
+
* volatile field, and a write to a non-volatile path is refused. A schema without
|
|
87
|
+
* a single `.volatile()` therefore publishes **no namespace at all**: the bundle's
|
|
88
|
+
* card reads nothing, every toggle stays disabled and both endpoint fields stay
|
|
89
|
+
* blank, with no error printed anywhere.
|
|
90
|
+
*
|
|
91
|
+
* So the fields this bundle's own card draws are volatile: the master switch, the
|
|
92
|
+
* key reference, the endpoint, the model, and the two capability toggles.
|
|
93
|
+
* `test/bundle-contract.test.ts` keeps that set honest. Everything else stays an
|
|
94
|
+
* ordinary composition setting, editable by hand in the profile patch.
|
|
95
|
+
*/
|
|
96
|
+
export const Config = Schema.object({
|
|
97
|
+
enabled: Schema.boolean()
|
|
98
|
+
.default(true)
|
|
99
|
+
.volatile()
|
|
100
|
+
.description('总开关。关闭后两项自动能力完全失效——与"未配置 key"行为一致,不发任何网络请求。'),
|
|
101
|
+
apiKeyEnv: Schema.string()
|
|
102
|
+
.default(DEFAULT_API_KEY_ENV)
|
|
103
|
+
.volatile()
|
|
104
|
+
.description(`读取 API key 的环境变量名。默认 ${DEFAULT_API_KEY_ENV}(与 TypeSafe 官方 SDK 相同,已在使用官方工具链的人无需配置)。填多个时用逗号分隔(例如 ${DEFAULT_API_KEY_ENV},TYPESAFE_API_KEY_2):同一会话固定用同一个 key,只有它返回 401 或 429(额度用尽)才换下一个。密钥本身永远不会出现在任何响应里。`),
|
|
105
|
+
proxy: Schema.string()
|
|
106
|
+
.default('')
|
|
107
|
+
.volatile()
|
|
108
|
+
.description('网络出口。留空直连(默认);填 system 用操作系统的代理设置(Windows 读系统代理,其它平台读 HTTPS_PROXY);也可以直接填代理地址,例如 http://127.0.0.1:7897。Jev 按 IP 判定可用地区,境外端点在受限地区只会返回 403,走代理是唯一能让它返回结果的开关。'),
|
|
109
|
+
baseUrl: Schema.string()
|
|
110
|
+
.default(DEFAULT_BASE_URL)
|
|
111
|
+
.volatile()
|
|
112
|
+
.description(`System One 判定端点,填裸主机名(例如 https://jev.example.com)。默认 ${DEFAULT_BASE_URL};自建的 Jev 兼容服务、或在前面挡了一层网关的部署都要改这里——端点写死会让这些部署的请求发去默认主机,而本插件是 fail-open 的,失败看起来就像什么都没发生。路径 /v1/systemone 由插件追加,不要写进这里。`),
|
|
113
|
+
model: Schema.string()
|
|
114
|
+
.default('jev-latest')
|
|
115
|
+
.volatile()
|
|
116
|
+
.description('使用的 Jev 模型。别名会随版本移动——每次判定都会记录响应里回报的实际作答版本。'),
|
|
117
|
+
sessionCallLimit: Schema.number()
|
|
118
|
+
.default(200)
|
|
119
|
+
.description('单个会话的最大判定次数(所有能力合计)。超出后原样放行并给出说明,不会静默。'),
|
|
120
|
+
prune: Schema.object({
|
|
121
|
+
enabled: Schema.boolean().default(true).volatile()
|
|
122
|
+
.description('自动剪掉工具结果中与当前任务无关的部分。'),
|
|
123
|
+
minTokens: Schema.number().default(2000)
|
|
124
|
+
.description('只判定超过这个估算 token 数的工具结果。实测:2000 可省下约 32% 的工具结果 token,同时避开"省得少却照样花 300ms"的边际区间。'),
|
|
125
|
+
perTurnLimit: Schema.number().default(3)
|
|
126
|
+
.description('单个 turn 内的剪枝次数上限。实测:不设上限时最坏一个 turn 会触发 27 次(约 8.1 秒);限 3 次后最坏 0.9 秒。'),
|
|
127
|
+
toolAllowlist: Schema.array(Schema.string()).default([...DEFAULT_TOOL_ALLOWLIST])
|
|
128
|
+
.description('参与剪枝的工具白名单。刻意不含 pwsh——终端输出里的"无关"内容往往是排查所需。'),
|
|
129
|
+
headLines: Schema.number().default(40)
|
|
130
|
+
.description('确定性保底:结果开头的行数永远保留。'),
|
|
131
|
+
tailLines: Schema.number().default(40)
|
|
132
|
+
.description('确定性保底:结果结尾的行数永远保留。'),
|
|
133
|
+
keepHigh: Schema.number().default(0.5)
|
|
134
|
+
.description('相关概率达到此值的片段无条件保留。'),
|
|
135
|
+
minKeepRatio: Schema.number().default(0.2)
|
|
136
|
+
.description('削减下限:任何结果都不会被压到这个比例以下,防止削成空壳。'),
|
|
137
|
+
minSaving: Schema.number().default(0.15)
|
|
138
|
+
.description('若可达削减比例低于此值则放弃剪枝、原样返回——不值得为这点收益引入失真。'),
|
|
139
|
+
minTaskChars: Schema.number().default(12)
|
|
140
|
+
.description('当前任务文本短于此长度时放弃剪枝。实测发现:拿「继续吧」这类极短消息去判相关性,结果基本是噪声——与其用无信息量的任务乱裁,不如不动。'),
|
|
141
|
+
shadow: Schema.boolean().default(false)
|
|
142
|
+
.description('试运行:照常判定与记账,但不真的改动内容,只告诉你"本来会削掉多少、留下什么"。用来在信任剪枝之前先看清它的取舍——判定成本照付,上下文一个字不改。'),
|
|
143
|
+
}).description('工具结果语义剪枝'),
|
|
144
|
+
suggest: Schema.object({
|
|
145
|
+
enabled: Schema.boolean().default(true).volatile()
|
|
146
|
+
.description('当技能目录较大时,每轮至多推荐一个 skill(仅建议,不会替你决定)。'),
|
|
147
|
+
minCatalogSize: Schema.number().default(15)
|
|
148
|
+
.description('技能数量达到此值才启用推荐。实测典型目录有 29 个 skill,此阈值对真实用户必触发、对极简配置保持沉默。'),
|
|
149
|
+
minConfidence: Schema.number().default(0.3)
|
|
150
|
+
.description('最高概率低于此值时不注入任何建议——宁可沉默,不要噪音。'),
|
|
151
|
+
}).description('技能推荐'),
|
|
152
|
+
screen: Schema.object({
|
|
153
|
+
enabled: Schema.boolean().default(true)
|
|
154
|
+
.description('检查抓取到的外部内容里是否有针对 AI 的注入指令(提示注入)。只做提醒,绝不阻断、绝不改写内容。'),
|
|
155
|
+
minTokens: Schema.number().default(300)
|
|
156
|
+
.description('低于此估算 token 数不做注入筛查——太短的文本承载不了注入指令。'),
|
|
157
|
+
threshold: Schema.number().default(0.75)
|
|
158
|
+
.description('注入概率达到此值时附加一条提醒。判定是建议性的:插件不会替你拦截任何内容。'),
|
|
159
|
+
toolAllowlist: Schema.array(Schema.string()).default([...DEFAULT_SCREEN_ALLOWLIST])
|
|
160
|
+
.description('参与注入筛查的工具。默认只查外部抓取(web_fetch / web_search)——本地文件是你自己的材料,且读取频繁。克隆不受信仓库的人可以自己加上 read。'),
|
|
161
|
+
}).description('注入筛查(仅提醒)'),
|
|
162
|
+
ledger: Schema.object({
|
|
163
|
+
enabled: Schema.boolean().default(true)
|
|
164
|
+
.description('把每次判定记入本地台账。台账是校准阈值、核算成本与验证削减效果的唯一依据,建议保持开启。关闭后台账不再记录,/jev-status 会显示"已关闭"。'),
|
|
165
|
+
}).description('判定台账'),
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* Resolve a raw composition entry against the schema.
|
|
169
|
+
*
|
|
170
|
+
* `apply` receives whatever the patch declared, which may be `undefined` when
|
|
171
|
+
* the row carries no `config:`.
|
|
172
|
+
*
|
|
173
|
+
* The **standard-schema** path is used on purpose: it is the one the Loader
|
|
174
|
+
* itself takes (`resolveConfig` in cordis is exactly
|
|
175
|
+
* `Config['~standard'].validate(value)` → `result.value`). Either path hands back
|
|
176
|
+
* a `.volatile()` field as a marker object rather than the value it denotes, so
|
|
177
|
+
* {@link plainConfig} unwraps it on the way in **and** on the way out — which
|
|
178
|
+
* makes this function idempotent, because the Loader hands `apply` the config it
|
|
179
|
+
* already resolved (markers included).
|
|
180
|
+
*
|
|
181
|
+
* @param entry - the composition entry, raw or already resolved by the Loader.
|
|
182
|
+
* @returns the fully resolved settings.
|
|
183
|
+
*/
|
|
184
|
+
export function resolveSettings(entry) {
|
|
185
|
+
const result = Config['~standard'].validate(plainConfig(entry ?? {}));
|
|
186
|
+
if (result instanceof Promise)
|
|
187
|
+
throw new TypeError('config validation must be synchronous');
|
|
188
|
+
if (result.issues !== undefined) {
|
|
189
|
+
const detail = result.issues.map(issue => issue.message).join('; ');
|
|
190
|
+
throw new TypeError(`invalid dsh-jev-tools config: ${detail}`);
|
|
191
|
+
}
|
|
192
|
+
return plainConfig(result.value);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElD;;;;;;;;;;;;;;GAcG;AACH,SAAS,WAAW,CAAK,KAAQ;IAC/B,IAAI,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,EAAO,CAAC,CAAA;IAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO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relevance is undecidable without knowing what the session is trying to do,
|
|
5
|
+
* and neither `tools/post-execute` (which carries only the call's name,
|
|
6
|
+
* arguments and agent) nor `AssembleContext` (scope and signal) exposes the
|
|
7
|
+
* conversation. So the request is captured from the two places that do carry
|
|
8
|
+
* it, whichever arrives first, and looked up by agent id.
|
|
9
|
+
*
|
|
10
|
+
* This is a cache of *recent user text*, not a transcript: it keeps one string
|
|
11
|
+
* per agent, bounded in length, and drops an agent's entry when it goes away.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-jev-tools/context-cache
|
|
14
|
+
*/
|
|
15
|
+
/** Owners of the current request, keyed by agent id. */
|
|
16
|
+
export interface ContextCache {
|
|
17
|
+
/** Record the request text for one agent. Empty text is ignored. */
|
|
18
|
+
remember(agentId: string, text: string): void;
|
|
19
|
+
/** Read the request text for one agent, or `undefined` when unknown. */
|
|
20
|
+
task(agentId: string): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Read only the most recent request message for one agent.
|
|
23
|
+
*
|
|
24
|
+
* `task` answers "what is this session working on" — pruning's question. Skill
|
|
25
|
+
* suggestion needs "what is being asked right now", so it reads the latest
|
|
26
|
+
* message whenever that message is substantive enough to stand alone.
|
|
27
|
+
*/
|
|
28
|
+
latest(agentId: string): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Record the turn an agent is on.
|
|
31
|
+
*
|
|
32
|
+
* `ToolExecution` carries no turn number, but `agent/pre-step` and
|
|
33
|
+
* `agent/inbox/claimed` both do, so the per-turn quota reads it from here.
|
|
34
|
+
*/
|
|
35
|
+
rememberTurn(agentId: string, turn: number): void;
|
|
36
|
+
/** The current turn for one agent, or `undefined` when unknown. */
|
|
37
|
+
turn(agentId: string): number | undefined;
|
|
38
|
+
/** Forget one agent. */
|
|
39
|
+
forget(agentId: string): void;
|
|
40
|
+
/** Number of agents currently remembered (diagnostics and bounds). */
|
|
41
|
+
readonly size: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a bounded per-agent request cache.
|
|
45
|
+
*
|
|
46
|
+
* @param maxAgents - ceiling on remembered agents; the oldest insertion is
|
|
47
|
+
* evicted. A long-lived host sees many short-lived agents, so an unbounded
|
|
48
|
+
* map here would be a slow leak.
|
|
49
|
+
* @returns the cache.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createContextCache(maxAgents?: number): ContextCache;
|
|
52
|
+
/**
|
|
53
|
+
* Extract the plain text of a message-like value.
|
|
54
|
+
*
|
|
55
|
+
* @param content - a `ContentBlock[]`-shaped value.
|
|
56
|
+
* @returns the concatenated text blocks.
|
|
57
|
+
*/
|
|
58
|
+
export declare function textOfContent(content: unknown): string;
|
|
59
|
+
//# sourceMappingURL=context-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-cache.d.ts","sourceRoot":"","sources":["../src/context-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,oEAAoE;IACpE,QAAQ,CAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9C,wEAAwE;IACxE,IAAI,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1C;;;;;;OAMG;IACH,MAAM,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC5C;;;;;OAKG;IACH,YAAY,CAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAClD,mEAAmE;IACnE,IAAI,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1C,wBAAwB;IACxB,MAAM,CAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAE,SAAS,SAAK,GAAG,YAAY,CA8DhE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAUvD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-agent memory of the current request.
|
|
3
|
+
*
|
|
4
|
+
* Relevance is undecidable without knowing what the session is trying to do,
|
|
5
|
+
* and neither `tools/post-execute` (which carries only the call's name,
|
|
6
|
+
* arguments and agent) nor `AssembleContext` (scope and signal) exposes the
|
|
7
|
+
* conversation. So the request is captured from the two places that do carry
|
|
8
|
+
* it, whichever arrives first, and looked up by agent id.
|
|
9
|
+
*
|
|
10
|
+
* This is a cache of *recent user text*, not a transcript: it keeps one string
|
|
11
|
+
* per agent, bounded in length, and drops an agent's entry when it goes away.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-jev-tools/context-cache
|
|
14
|
+
*/
|
|
15
|
+
/** Longest request text retained per agent, in characters. */
|
|
16
|
+
const MAX_LENGTH = 4_000;
|
|
17
|
+
/** How many recent user messages make up the current task description. */
|
|
18
|
+
const MAX_MESSAGES = 3;
|
|
19
|
+
/**
|
|
20
|
+
* Create a bounded per-agent request cache.
|
|
21
|
+
*
|
|
22
|
+
* @param maxAgents - ceiling on remembered agents; the oldest insertion is
|
|
23
|
+
* evicted. A long-lived host sees many short-lived agents, so an unbounded
|
|
24
|
+
* map here would be a slow leak.
|
|
25
|
+
* @returns the cache.
|
|
26
|
+
*/
|
|
27
|
+
export function createContextCache(maxAgents = 64) {
|
|
28
|
+
// A *list* per agent, not a single string: one terse message ("继续吧",
|
|
29
|
+
// "ok", "go on") carries no usable signal, so relevance judged against it is
|
|
30
|
+
// noise. Keeping the last few messages gives the task enough context to be
|
|
31
|
+
// worth judging against.
|
|
32
|
+
const byAgent = new Map();
|
|
33
|
+
const turns = new Map();
|
|
34
|
+
return {
|
|
35
|
+
remember(agentId, text) {
|
|
36
|
+
const trimmed = text.trim();
|
|
37
|
+
if (trimmed === '')
|
|
38
|
+
return;
|
|
39
|
+
const history = byAgent.get(agentId) ?? [];
|
|
40
|
+
// Ignore a repeat of the immediately preceding message.
|
|
41
|
+
if (history[history.length - 1] === trimmed)
|
|
42
|
+
return;
|
|
43
|
+
history.push(trimmed);
|
|
44
|
+
while (history.length > MAX_MESSAGES)
|
|
45
|
+
history.shift();
|
|
46
|
+
// Re-insert so the eviction order is least-recently-used.
|
|
47
|
+
byAgent.delete(agentId);
|
|
48
|
+
byAgent.set(agentId, history);
|
|
49
|
+
while (byAgent.size > maxAgents) {
|
|
50
|
+
const oldest = byAgent.keys().next();
|
|
51
|
+
if (oldest.done === true)
|
|
52
|
+
break;
|
|
53
|
+
byAgent.delete(oldest.value);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
task(agentId) {
|
|
57
|
+
const history = byAgent.get(agentId);
|
|
58
|
+
if (history === undefined || history.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
// Oldest first, so the request that framed the work precedes the
|
|
61
|
+
// follow-ups that refine it. Truncated from the front when long.
|
|
62
|
+
const joined = history.join('\n');
|
|
63
|
+
return joined.length > MAX_LENGTH ? joined.slice(joined.length - MAX_LENGTH) : joined;
|
|
64
|
+
},
|
|
65
|
+
latest(agentId) {
|
|
66
|
+
const history = byAgent.get(agentId);
|
|
67
|
+
const last = history?.[history.length - 1];
|
|
68
|
+
if (last === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
// Same cap as `task`, for the same reason: one pasted document is not a
|
|
71
|
+
// request, and a judgment request has its own size ceiling.
|
|
72
|
+
return last.length > MAX_LENGTH ? last.slice(last.length - MAX_LENGTH) : last;
|
|
73
|
+
},
|
|
74
|
+
rememberTurn(agentId, turn) {
|
|
75
|
+
if (!Number.isFinite(turn))
|
|
76
|
+
return;
|
|
77
|
+
turns.set(agentId, turn);
|
|
78
|
+
while (turns.size > maxAgents) {
|
|
79
|
+
const oldest = turns.keys().next();
|
|
80
|
+
if (oldest.done === true)
|
|
81
|
+
break;
|
|
82
|
+
turns.delete(oldest.value);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
turn(agentId) {
|
|
86
|
+
return turns.get(agentId);
|
|
87
|
+
},
|
|
88
|
+
forget(agentId) {
|
|
89
|
+
byAgent.delete(agentId);
|
|
90
|
+
turns.delete(agentId);
|
|
91
|
+
},
|
|
92
|
+
get size() {
|
|
93
|
+
return byAgent.size;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extract the plain text of a message-like value.
|
|
99
|
+
*
|
|
100
|
+
* @param content - a `ContentBlock[]`-shaped value.
|
|
101
|
+
* @returns the concatenated text blocks.
|
|
102
|
+
*/
|
|
103
|
+
export function textOfContent(content) {
|
|
104
|
+
if (!Array.isArray(content))
|
|
105
|
+
return '';
|
|
106
|
+
let text = '';
|
|
107
|
+
for (const block of content) {
|
|
108
|
+
if (block !== null && typeof block === 'object') {
|
|
109
|
+
const typed = block;
|
|
110
|
+
if (typed.type === 'text' && typeof typed.text === 'string')
|
|
111
|
+
text += `${typed.text}\n`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return text;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=context-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-cache.js","sourceRoot":"","sources":["../src/context-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,8DAA8D;AAC9D,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,0EAA0E;AAC1E,MAAM,YAAY,GAAG,CAAC,CAAA;AA+BtB;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAE,SAAS,GAAG,EAAE;IAChD,qEAAqE;IACrE,6EAA6E;IAC7E,2EAA2E;IAC3E,yBAAyB;IACzB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAA;IAC3C,MAAM,KAAK,GAAG,IAAI,GA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AC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAE,OAAgB;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAA;IACtC,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,KAAK,GAAG,KAA2C,CAAA;YACzD,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAAE,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,CAAA;QACxF,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential access for the TypeSafe API key.
|
|
3
|
+
*
|
|
4
|
+
* The plugin never stores, caches or logs the key. It resolves the reference
|
|
5
|
+
* on **every operation** — the credentials seam requires that, and it is what
|
|
6
|
+
* lets a user fix a wrong key and have the next judgment pick it up without a
|
|
7
|
+
* restart.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-jev-tools/credentials
|
|
10
|
+
*/
|
|
11
|
+
import type { CredentialsService } from './host.js';
|
|
12
|
+
/** Why a key could not be used. Drives the user-facing diagnostic. */
|
|
13
|
+
export type KeyProblem = 'invalid-name' | 'unconfigured';
|
|
14
|
+
/** The outcome of one credential lookup. */
|
|
15
|
+
export type KeyLookup = {
|
|
16
|
+
readonly ok: true;
|
|
17
|
+
readonly value: string;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly ok: false;
|
|
21
|
+
readonly problem: KeyProblem;
|
|
22
|
+
readonly ref: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the API key for one operation.
|
|
26
|
+
*
|
|
27
|
+
* @param credentials - the credentials service, or `undefined` when the profile lacks it.
|
|
28
|
+
* @param ref - the environment-variable name to resolve.
|
|
29
|
+
* @returns the resolved key, or the reason it is unusable.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveApiKey(credentials: CredentialsService | undefined, ref: string): Promise<KeyLookup>;
|
|
32
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAsB,MAAM,WAAW,CAAA;AAUvE,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,cAAc,CAAA;AAExD,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9E;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,kBAAkB,GAAG,SAAS,EAC3C,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,SAAS,CAAC,CAepB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential access for the TypeSafe API key.
|
|
3
|
+
*
|
|
4
|
+
* The plugin never stores, caches or logs the key. It resolves the reference
|
|
5
|
+
* on **every operation** — the credentials seam requires that, and it is what
|
|
6
|
+
* lets a user fix a wrong key and have the next judgment pick it up without a
|
|
7
|
+
* restart.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-jev-tools/credentials
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Environment-variable grammar a `CredentialRef` must satisfy.
|
|
13
|
+
*
|
|
14
|
+
* Mirrors the seam's own guard so a bad `apiKeyEnv` is rejected here with a
|
|
15
|
+
* clear message instead of surfacing as an opaque resolution failure.
|
|
16
|
+
*/
|
|
17
|
+
const REF_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the API key for one operation.
|
|
20
|
+
*
|
|
21
|
+
* @param credentials - the credentials service, or `undefined` when the profile lacks it.
|
|
22
|
+
* @param ref - the environment-variable name to resolve.
|
|
23
|
+
* @returns the resolved key, or the reason it is unusable.
|
|
24
|
+
*/
|
|
25
|
+
export async function resolveApiKey(credentials, ref) {
|
|
26
|
+
if (!REF_NAME.test(ref))
|
|
27
|
+
return { ok: false, problem: 'invalid-name', ref };
|
|
28
|
+
if (credentials === undefined)
|
|
29
|
+
return { ok: false, problem: 'unconfigured', ref };
|
|
30
|
+
let resolved;
|
|
31
|
+
try {
|
|
32
|
+
resolved = await credentials.resolve(ref);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { ok: false, problem: 'unconfigured', ref };
|
|
36
|
+
}
|
|
37
|
+
// An empty stored value is absent everywhere by the seam's own rule: a blank
|
|
38
|
+
// must never masquerade as a configured secret.
|
|
39
|
+
if (resolved === undefined || resolved.value === '') {
|
|
40
|
+
return { ok: false, problem: 'unconfigured', ref };
|
|
41
|
+
}
|
|
42
|
+
return { ok: true, value: resolved.value, source: resolved.source };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;;GAKG;AACH,MAAM,QAAQ,GAAG,0BAA0B,CAAA;AAU3C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,WAA2C,EAC3C,GAAW;IAEX,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,CAAA;IAC3E,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,CAAA;IACjF,IAAI,QAAwC,CAAA;IAC5C,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,CAAA;IACpD,CAAC;IACD,6EAA6E;IAC7E,gDAAgD;IAChD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,KAAK,EAAE,EAAE,CAAC;QACpD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,CAAA;IACpD,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAA;AACrE,CAAC"}
|
package/lib/degrade.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One vocabulary for "why nothing happened".
|
|
3
|
+
*
|
|
4
|
+
* Every capability can decline for a dozen reasons, and the difference matters
|
|
5
|
+
* to whoever is looking at a session where the plugin appears to do nothing.
|
|
6
|
+
* A missing key, an exhausted quota and a deliberately skipped small result all
|
|
7
|
+
* look identical from the outside unless the reason is carried as a value.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-jev-tools/degrade
|
|
10
|
+
*/
|
|
11
|
+
import { type Lang } from './i18n.js';
|
|
12
|
+
/** Why a capability did not act. */
|
|
13
|
+
export type SkipReason = 'disabled' | 'no-key' | 'budget-turn' | 'budget-session' | 'too-small' | 'tool-not-allowed' | 'is-error' | 'cached' | 'no-task' | 'task-too-vague' | 'no-saving' | 'no-skills' | 'catalog-unavailable' | 'catalog-too-small' | 'shadow' | 'empty' | 'aborted' | 'invalid-request' | 'unauthorized' | 'bad-request' | 'rate-limited' | 'overloaded' | 'server' | 'network' | 'malformed-response' | 'unknown';
|
|
14
|
+
/**
|
|
15
|
+
* Human-readable phrasing for a skip reason.
|
|
16
|
+
*
|
|
17
|
+
* The text lives in the shared catalog (`i18n.ts`) rather than here, because
|
|
18
|
+
* these phrases are read by a *user* in `/jev-status`, not just by the plugin:
|
|
19
|
+
* they must follow the conversation's language like every other message.
|
|
20
|
+
*
|
|
21
|
+
* @param reason - the classification.
|
|
22
|
+
* @param lang - the language to render in.
|
|
23
|
+
* @returns a short phrase suitable for a session notice.
|
|
24
|
+
*/
|
|
25
|
+
export declare function skipMessage(reason: SkipReason, lang: Lang): string;
|
|
26
|
+
/**
|
|
27
|
+
* Map a thrown judgment failure onto a skip reason.
|
|
28
|
+
*
|
|
29
|
+
* Keeps the caller from having to know the backend's error taxonomy: anything
|
|
30
|
+
* it cannot place becomes `unknown` rather than escaping.
|
|
31
|
+
*
|
|
32
|
+
* @param problem - the failure's own classification, if it had one.
|
|
33
|
+
* @returns the skip reason to report.
|
|
34
|
+
*/
|
|
35
|
+
export declare function reasonFromFailure(problem: string | undefined): SkipReason;
|
|
36
|
+
//# sourceMappingURL=degrade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degrade.d.ts","sourceRoot":"","sources":["../src/degrade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAmB,KAAK,IAAI,EAAmB,MAAM,WAAW,CAAA;AAEvE,oCAAoC;AACpC,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,QAAQ,GACR,aAAa,GACb,gBAAgB,GAChB,WAAW,GACX,kBAAkB,GAClB,UAAU,GACV,QAAQ,GACR,SAAS,GACT,gBAAgB,GAChB,WAAW,GACX,WAAW,GACX,qBAAqB,GACrB,mBAAmB,GACnB,QAAQ,GACR,OAAO,GACP,SAAS,GACT,iBAAiB,GACjB,cAAc,GACd,aAAa,GACb,cAAc,GACd,YAAY,GACZ,QAAQ,GACR,SAAS,GACT,oBAAoB,GACpB,SAAS,CAAA;AAEb;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAI1E"}
|
package/lib/degrade.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One vocabulary for "why nothing happened".
|
|
3
|
+
*
|
|
4
|
+
* Every capability can decline for a dozen reasons, and the difference matters
|
|
5
|
+
* to whoever is looking at a session where the plugin appears to do nothing.
|
|
6
|
+
* A missing key, an exhausted quota and a deliberately skipped small result all
|
|
7
|
+
* look identical from the outside unless the reason is carried as a value.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-jev-tools/degrade
|
|
10
|
+
*/
|
|
11
|
+
import { MESSAGE_KEYS, t } from './i18n.js';
|
|
12
|
+
/**
|
|
13
|
+
* Human-readable phrasing for a skip reason.
|
|
14
|
+
*
|
|
15
|
+
* The text lives in the shared catalog (`i18n.ts`) rather than here, because
|
|
16
|
+
* these phrases are read by a *user* in `/jev-status`, not just by the plugin:
|
|
17
|
+
* they must follow the conversation's language like every other message.
|
|
18
|
+
*
|
|
19
|
+
* @param reason - the classification.
|
|
20
|
+
* @param lang - the language to render in.
|
|
21
|
+
* @returns a short phrase suitable for a session notice.
|
|
22
|
+
*/
|
|
23
|
+
export function skipMessage(reason, lang) {
|
|
24
|
+
return t(lang, `skip.${reason}`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Map a thrown judgment failure onto a skip reason.
|
|
28
|
+
*
|
|
29
|
+
* Keeps the caller from having to know the backend's error taxonomy: anything
|
|
30
|
+
* it cannot place becomes `unknown` rather than escaping.
|
|
31
|
+
*
|
|
32
|
+
* @param problem - the failure's own classification, if it had one.
|
|
33
|
+
* @returns the skip reason to report.
|
|
34
|
+
*/
|
|
35
|
+
export function reasonFromFailure(problem) {
|
|
36
|
+
if (problem === undefined)
|
|
37
|
+
return 'unknown';
|
|
38
|
+
const candidate = `skip.${problem}`;
|
|
39
|
+
return MESSAGE_KEYS.includes(candidate) ? problem : 'unknown';
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=degrade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degrade.js","sourceRoot":"","sources":["../src/degrade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,CAAC,EAA8B,MAAM,WAAW,CAAA;AA+BvE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAE,MAAkB,EAAE,IAAU;IACzD,OAAO,CAAC,CAAC,IAAI,EAAE,QAAQ,MAAM,EAAgB,CAAC,CAAA;AAChD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAE,OAA2B;IAC5D,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC3C,MAAM,SAAS,GAAG,QAAQ,OAAO,EAAgB,CAAA;IACjD,OAAO,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAE,OAAsB,CAAC,CAAC,CAAC,SAAS,CAAA;AAC/E,CAAC"}
|