@itphx/synth-shared 0.13.4 → 0.13.10
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/dist/config/defaults.js +102 -3
- package/dist/config/env-overrides.d.ts +39 -4
- package/dist/config/env-overrides.js +174 -4
- package/dist/config/execution-runtime.d.ts +89 -0
- package/dist/config/execution-runtime.js +506 -0
- package/dist/config/execution.d.ts +202 -1
- package/dist/config/execution.js +459 -3
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +3 -0
- package/dist/config/loader.d.ts +8 -0
- package/dist/config/loader.js +6 -1
- package/dist/config/redact.d.ts +22 -0
- package/dist/config/redact.js +53 -0
- package/dist/config/security.d.ts +77 -0
- package/dist/config/security.js +116 -0
- package/dist/config/tls.d.ts +7 -4
- package/dist/config/tls.js +10 -23
- package/dist/config/types.d.ts +568 -38
- package/dist/config/types.js +390 -33
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +325 -13
- package/dist/index.d.ts +7 -6
- package/dist/index.js +17 -4
- package/dist/model-metadata.d.ts +10 -0
- package/dist/model-metadata.js +10 -0
- package/dist/schemas/index.d.ts +444 -30
- package/dist/schemas/index.js +354 -17
- package/dist/skills/frontmatter.js +1 -1
- package/dist/types/agent.d.ts +29 -1
- package/dist/types/authority.d.ts +10 -0
- package/dist/types/authority.js +8 -0
- package/dist/types/bus-events.d.ts +88 -2
- package/dist/types/catalog.d.ts +1 -1
- package/dist/types/catalog.js +1 -1
- package/dist/types/command-audit.d.ts +91 -0
- package/dist/types/command-audit.js +44 -0
- package/dist/types/commands.d.ts +29 -11
- package/dist/types/commands.js +2 -2
- package/dist/types/egress.d.ts +18 -3
- package/dist/types/egress.js +18 -3
- package/dist/types/events.d.ts +23 -2
- package/dist/types/execution.d.ts +424 -0
- package/dist/types/execution.js +355 -0
- package/dist/types/file-kind.d.ts +3 -2
- package/dist/types/file-kind.js +11 -2
- package/dist/types/git.d.ts +131 -0
- package/dist/types/git.js +101 -1
- package/dist/types/host-pattern.d.ts +41 -0
- package/dist/types/host-pattern.js +143 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +25 -3
- package/dist/types/maintenance.d.ts +1 -1
- package/dist/types/mcp.d.ts +90 -0
- package/dist/types/mcp.js +11 -0
- package/dist/types/mentions.d.ts +96 -0
- package/dist/types/mentions.js +9 -0
- package/dist/types/message-stream.d.ts +41 -0
- package/dist/types/message.d.ts +24 -1
- package/dist/types/message.js +13 -0
- package/dist/types/pack.d.ts +21 -21
- package/dist/types/pack.js +4 -4
- package/dist/types/permission.d.ts +20 -3
- package/dist/types/pipeline.d.ts +2 -2
- package/dist/types/plugin-protocol.d.ts +203 -4
- package/dist/types/plugin-protocol.js +77 -4
- package/dist/types/project-access.d.ts +94 -0
- package/dist/types/project-access.js +140 -0
- package/dist/types/project.d.ts +89 -2
- package/dist/types/project.js +36 -0
- package/dist/types/prompt.d.ts +4 -2
- package/dist/types/schedules.d.ts +49 -3
- package/dist/types/schedules.js +50 -1
- package/dist/types/scripts.d.ts +98 -0
- package/dist/types/scripts.js +14 -0
- package/dist/types/service-keys.d.ts +16 -3
- package/dist/types/service-keys.js +19 -1
- package/dist/types/session.d.ts +68 -3
- package/dist/types/skills.d.ts +21 -11
- package/dist/types/skills.js +6 -6
- package/dist/types/timers.d.ts +402 -0
- package/dist/types/timers.js +166 -0
- package/dist/types/tools.d.ts +160 -1
- package/dist/types/tools.js +70 -0
- package/dist/types/user.d.ts +24 -0
- package/dist/types/worktree.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-135: runtime-каталог профилей исполнения — слияние, применение и
|
|
3
|
+
* отпечаток для `restartRequired`.
|
|
4
|
+
*
|
|
5
|
+
* ## Где живёт каталог
|
|
6
|
+
*
|
|
7
|
+
* Каталог профилей и дефолты исполнения — **runtime-настройка инстанца**
|
|
8
|
+
* (`settings.json`/PG, секция `execution`), которой управляет администратор
|
|
9
|
+
* через `GET/PUT/DELETE /api/v2/settings/execution`.
|
|
10
|
+
*
|
|
11
|
+
* ## Приоритет
|
|
12
|
+
*
|
|
13
|
+
* **env/CLI > runtime > config.yaml** (ADR-023). Env/CLI разрешаются внутри
|
|
14
|
+
* `resolveExecutionConfig` — поэтому runtime-override применяется **поверх
|
|
15
|
+
* config-уровня, но под env**: поле, заданное переменной окружения, runtime
|
|
16
|
+
* не перекрывает.
|
|
17
|
+
*
|
|
18
|
+
* ## Каталог профилей — merge, а не замена
|
|
19
|
+
*
|
|
20
|
+
* Эффективный каталог = **config-профили + runtime-профили − отключённые**
|
|
21
|
+
* (аддендум §11):
|
|
22
|
+
*
|
|
23
|
+
* - runtime-запись **переопределяет** одноимённую config-запись целиком
|
|
24
|
+
* (не дополняет её);
|
|
25
|
+
* - config-записи, которых нет в runtime, **сохраняются** — поэтому
|
|
26
|
+
* администратор может отредактировать один профиль, не переписывая каталог;
|
|
27
|
+
* - профили из `config.yaml` **не удаляются** — их можно **отключить**
|
|
28
|
+
* (`disabledProfiles`); профиль, созданный в runtime, удаляется удалением
|
|
29
|
+
* из `profiles`.
|
|
30
|
+
*
|
|
31
|
+
* ## Когда применяется
|
|
32
|
+
*
|
|
33
|
+
* `execution` — **параметр запуска** (инвариант 24): порты пулов и роутер
|
|
34
|
+
* создаются на старте процесса. Поэтому изменение каталога требует рестарта —
|
|
35
|
+
* API честно отдаёт `restartRequired`.
|
|
36
|
+
*/
|
|
37
|
+
import { executionRuntimeSettingsSchema } from '../types/execution.js';
|
|
38
|
+
import { EXECUTION_ENV } from './execution.js';
|
|
39
|
+
import { effectiveProfileClass } from './execution.js';
|
|
40
|
+
/**
|
|
41
|
+
* Разобрать сохранённую runtime-секцию исполнения.
|
|
42
|
+
*
|
|
43
|
+
* Валидация — Zod (`:strict()`): неизвестное поле → невалидная секция.
|
|
44
|
+
* Невалидная секция **игнорируется** (fail-soft): испорченный `settings.json`
|
|
45
|
+
* не должен ронять инстанс — применяется config-уровень (как при деградации
|
|
46
|
+
* хранилища).
|
|
47
|
+
*/
|
|
48
|
+
export function parseExecutionRuntimeSettings(raw) {
|
|
49
|
+
if (raw === undefined || raw === null)
|
|
50
|
+
return undefined;
|
|
51
|
+
const parsed = executionRuntimeSettingsSchema.safeParse(raw);
|
|
52
|
+
return parsed.success ? parsed.data : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** Env-значение задано явно (непустая строка) — runtime его не перекрывает. */
|
|
55
|
+
function envSet(env, name) {
|
|
56
|
+
const raw = env[name];
|
|
57
|
+
return raw !== undefined && raw.trim() !== '';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Материализовать runtime-профиль в форму эффективного профиля.
|
|
61
|
+
*
|
|
62
|
+
* Незаданные поля наследуют общие параметры секции (`url`/`timeoutMs`/
|
|
63
|
+
* `concurrency`/`failMode`) — ровно как профили config.yaml.
|
|
64
|
+
*/
|
|
65
|
+
function materializeRuntimeProfile(profile, common) {
|
|
66
|
+
const urls = (profile.url ?? []).map((u) => u.trim()).filter((u) => u.length > 0);
|
|
67
|
+
const resolved = {
|
|
68
|
+
url: urls.length > 0 ? urls : [...common.url],
|
|
69
|
+
timeoutMs: common.timeoutMs,
|
|
70
|
+
concurrency: common.concurrency,
|
|
71
|
+
failMode: common.failMode,
|
|
72
|
+
};
|
|
73
|
+
const description = profile.description?.trim();
|
|
74
|
+
if (description !== undefined && description !== '')
|
|
75
|
+
resolved.description = description;
|
|
76
|
+
const image = profile.image?.trim();
|
|
77
|
+
if (image !== undefined && image !== '')
|
|
78
|
+
resolved.image = image;
|
|
79
|
+
if (profile.network !== undefined)
|
|
80
|
+
resolved.network = profile.network;
|
|
81
|
+
const resources = normalizeRuntimeResources(profile.resources);
|
|
82
|
+
if (resources !== undefined)
|
|
83
|
+
resolved.resources = resources;
|
|
84
|
+
// Placement профиля (аннотации/метки/отбор нод) — уходит в pod spec пула.
|
|
85
|
+
const annotations = normalizeStringMap(profile.annotations);
|
|
86
|
+
if (annotations !== undefined)
|
|
87
|
+
resolved.annotations = annotations;
|
|
88
|
+
const labels = normalizeStringMap(profile.labels);
|
|
89
|
+
if (labels !== undefined)
|
|
90
|
+
resolved.labels = labels;
|
|
91
|
+
const nodeSelector = normalizeStringMap(profile.nodeSelector);
|
|
92
|
+
if (nodeSelector !== undefined)
|
|
93
|
+
resolved.nodeSelector = nodeSelector;
|
|
94
|
+
if (profile.tolerations !== undefined && profile.tolerations.length > 0) {
|
|
95
|
+
resolved.tolerations = profile.tolerations.map((toleration) => ({ ...toleration }));
|
|
96
|
+
}
|
|
97
|
+
if (profile.affinity !== undefined && Object.keys(profile.affinity).length > 0) {
|
|
98
|
+
resolved.affinity = { ...profile.affinity };
|
|
99
|
+
}
|
|
100
|
+
const runtimeClass = profile.runtimeClass?.trim();
|
|
101
|
+
if (runtimeClass !== undefined && runtimeClass !== '')
|
|
102
|
+
resolved.runtimeClass = runtimeClass;
|
|
103
|
+
if (profile.readOnlyRootFilesystem !== undefined) {
|
|
104
|
+
resolved.readOnlyRootFilesystem = profile.readOnlyRootFilesystem;
|
|
105
|
+
}
|
|
106
|
+
if (profile.env !== undefined && Object.keys(profile.env).length > 0) {
|
|
107
|
+
resolved.env = { ...profile.env };
|
|
108
|
+
}
|
|
109
|
+
// Объявленный класс профиля (ADR-135, аддендум §11).
|
|
110
|
+
if (profile.class !== undefined)
|
|
111
|
+
resolved.class = profile.class;
|
|
112
|
+
// MCP-серверы runtime-каталога — полное описание (имя + команда): команда
|
|
113
|
+
// нужна provisioner'у, чтобы запустить сервер в поде. Строковая форма
|
|
114
|
+
// (legacy-запись) нормализуется в `{ name }`.
|
|
115
|
+
const mcpServers = normalizeMcpServers(profile.mcpServers);
|
|
116
|
+
if (mcpServers.length > 0)
|
|
117
|
+
resolved.mcpServers = mcpServers;
|
|
118
|
+
return resolved;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Нормализация MCP-серверов профиля: строки (legacy) → `{ name }`, объекты —
|
|
122
|
+
* как есть (имя/команда/аргументы/env). Пустые имена отбрасываются.
|
|
123
|
+
*/
|
|
124
|
+
function normalizeMcpServers(raw) {
|
|
125
|
+
if (!Array.isArray(raw))
|
|
126
|
+
return [];
|
|
127
|
+
const out = [];
|
|
128
|
+
for (const entry of raw) {
|
|
129
|
+
if (typeof entry === 'string') {
|
|
130
|
+
const name = entry.trim();
|
|
131
|
+
if (name !== '')
|
|
132
|
+
out.push({ name });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!entry || typeof entry !== 'object')
|
|
136
|
+
continue;
|
|
137
|
+
const server = entry;
|
|
138
|
+
const name = typeof server.name === 'string' ? server.name.trim() : '';
|
|
139
|
+
if (name === '')
|
|
140
|
+
continue;
|
|
141
|
+
const command = typeof server.command === 'string' ? server.command.trim() : '';
|
|
142
|
+
const args = Array.isArray(server.args)
|
|
143
|
+
? server.args.filter((item) => typeof item === 'string')
|
|
144
|
+
: [];
|
|
145
|
+
const env = {};
|
|
146
|
+
if (server.env !== null && typeof server.env === 'object') {
|
|
147
|
+
for (const [key, value] of Object.entries(server.env)) {
|
|
148
|
+
if (typeof value === 'string')
|
|
149
|
+
env[key] = value;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
out.push({
|
|
153
|
+
name,
|
|
154
|
+
...(command !== '' ? { command } : {}),
|
|
155
|
+
...(args.length > 0 ? { args } : {}),
|
|
156
|
+
...(Object.keys(env).length > 0 ? { env } : {}),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
/** Ресурсы профиля: копируются только заданные непустые строки. */
|
|
162
|
+
function normalizeRuntimeResources(resources) {
|
|
163
|
+
if (resources === undefined)
|
|
164
|
+
return undefined;
|
|
165
|
+
const requests = normalizeResourceList(resources.requests);
|
|
166
|
+
const limits = normalizeResourceList(resources.limits);
|
|
167
|
+
if (requests === undefined && limits === undefined)
|
|
168
|
+
return undefined;
|
|
169
|
+
return {
|
|
170
|
+
...(requests !== undefined ? { requests } : {}),
|
|
171
|
+
...(limits !== undefined ? { limits } : {}),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function normalizeResourceList(list) {
|
|
175
|
+
if (list === undefined)
|
|
176
|
+
return undefined;
|
|
177
|
+
// Список ресурсов **произвольный** (`nvidia.com/gpu` и пр.) — копируются
|
|
178
|
+
// все ключи, а не только cpu/memory/ephemeralStorage.
|
|
179
|
+
const out = {};
|
|
180
|
+
for (const [key, value] of Object.entries(list)) {
|
|
181
|
+
const trimmed = typeof value === 'string' ? value.trim() : '';
|
|
182
|
+
if (trimmed !== '')
|
|
183
|
+
out[key] = trimmed;
|
|
184
|
+
}
|
|
185
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Карта строковых значений профиля (аннотации/метки/селектор): копия без
|
|
189
|
+
* пустых ключей и значений; пустая карта — `undefined` (поле не задано).
|
|
190
|
+
*/
|
|
191
|
+
function normalizeStringMap(map) {
|
|
192
|
+
if (map === undefined)
|
|
193
|
+
return undefined;
|
|
194
|
+
const out = {};
|
|
195
|
+
for (const [key, value] of Object.entries(map)) {
|
|
196
|
+
const trimmedKey = key.trim();
|
|
197
|
+
const trimmedValue = typeof value === 'string' ? value.trim() : '';
|
|
198
|
+
if (trimmedKey === '' || trimmedValue === '')
|
|
199
|
+
continue;
|
|
200
|
+
out[trimmedKey] = trimmedValue;
|
|
201
|
+
}
|
|
202
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Ресурсы профиля → форма runtime-профиля: только **заданные** значения
|
|
206
|
+
* (без `undefined`), список ключей произвольный (`nvidia.com/gpu`).
|
|
207
|
+
*/
|
|
208
|
+
function toRuntimeResources(resources) {
|
|
209
|
+
const out = {};
|
|
210
|
+
const requests = toRuntimeResourceList(resources.requests);
|
|
211
|
+
const limits = toRuntimeResourceList(resources.limits);
|
|
212
|
+
if (requests !== undefined)
|
|
213
|
+
out.requests = requests;
|
|
214
|
+
if (limits !== undefined)
|
|
215
|
+
out.limits = limits;
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
/** Список ресурсов без пустых значений (`undefined` — блок пуст). */
|
|
219
|
+
function toRuntimeResourceList(list) {
|
|
220
|
+
if (list === undefined)
|
|
221
|
+
return undefined;
|
|
222
|
+
const out = {};
|
|
223
|
+
for (const [key, value] of Object.entries(list)) {
|
|
224
|
+
if (typeof value !== 'string')
|
|
225
|
+
continue;
|
|
226
|
+
const trimmed = value.trim();
|
|
227
|
+
if (trimmed !== '')
|
|
228
|
+
out[key] = trimmed;
|
|
229
|
+
}
|
|
230
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Собрать эффективный каталог профилей (ADR-135, аддендум §11).
|
|
234
|
+
*
|
|
235
|
+
* Порядок: env > runtime > config.yaml (ADR-023). Runtime-запись профиля
|
|
236
|
+
* **переопределяет** одноимённую config-запись целиком; config-записи без
|
|
237
|
+
* runtime-пары сохраняются; `disabledProfiles` (только имена из config-базы)
|
|
238
|
+
* убирают профиль из каталога.
|
|
239
|
+
*/
|
|
240
|
+
export function effectiveExecutionCatalog(base, runtime, env = process.env) {
|
|
241
|
+
const remote = base.remote;
|
|
242
|
+
const defaultProfile = envSet(env, EXECUTION_ENV.defaultProfile)
|
|
243
|
+
? remote.defaultProfile
|
|
244
|
+
: (runtime?.defaultProfile ?? remote.defaultProfile);
|
|
245
|
+
const browserProfile = envSet(env, EXECUTION_ENV.browserProfile)
|
|
246
|
+
? remote.browserProfile
|
|
247
|
+
: (runtime?.browserProfile ?? remote.browserProfile);
|
|
248
|
+
const browserProfiles = envSet(env, EXECUTION_ENV.browserProfiles)
|
|
249
|
+
? remote.browserProfiles
|
|
250
|
+
: (runtime?.browserProfiles ?? remote.browserProfiles);
|
|
251
|
+
const common = {
|
|
252
|
+
url: remote.url,
|
|
253
|
+
timeoutMs: remote.timeoutMs,
|
|
254
|
+
concurrency: remote.concurrency,
|
|
255
|
+
failMode: remote.failMode,
|
|
256
|
+
};
|
|
257
|
+
const profiles = {};
|
|
258
|
+
const origins = {};
|
|
259
|
+
for (const [name, profile] of Object.entries(remote.profiles ?? {})) {
|
|
260
|
+
profiles[name] = { ...profile };
|
|
261
|
+
origins[name] = 'config';
|
|
262
|
+
}
|
|
263
|
+
for (const [name, profile] of Object.entries(runtime?.profiles ?? {})) {
|
|
264
|
+
profiles[name] = materializeRuntimeProfile(profile, common);
|
|
265
|
+
if (origins[name] === undefined)
|
|
266
|
+
origins[name] = 'runtime';
|
|
267
|
+
}
|
|
268
|
+
// Отключение — только профили **config-базы** (профиль, созданный в
|
|
269
|
+
// runtime, удаляется удалением из `profiles`).
|
|
270
|
+
const disabledProfiles = [];
|
|
271
|
+
for (const name of runtime?.disabledProfiles ?? []) {
|
|
272
|
+
const trimmed = name.trim();
|
|
273
|
+
if (trimmed === '' || origins[trimmed] !== 'config')
|
|
274
|
+
continue;
|
|
275
|
+
delete profiles[trimmed];
|
|
276
|
+
delete origins[trimmed];
|
|
277
|
+
disabledProfiles.push(trimmed);
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
profiles,
|
|
281
|
+
origins,
|
|
282
|
+
defaultProfile,
|
|
283
|
+
browserProfile,
|
|
284
|
+
browserProfiles: [...browserProfiles],
|
|
285
|
+
disabledProfiles,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Применить runtime-каталог к эффективной секции `execution`.
|
|
290
|
+
*
|
|
291
|
+
* Вход — **уже разрешённая** секция (config.yaml + env, ADR-023); выход —
|
|
292
|
+
* секция, с которой работает процесс (config.yaml + env + runtime).
|
|
293
|
+
*
|
|
294
|
+
* Env/CLI выше runtime: поле, явно заданное переменной окружения, не
|
|
295
|
+
* перекрывается (иначе оператор не смог бы зафиксировать значение из
|
|
296
|
+
* `SYNTH_EXECUTION_*`).
|
|
297
|
+
*
|
|
298
|
+
* Каталог `profiles` runtime-секции **сливается** с каталогом config.yaml
|
|
299
|
+
* (runtime-запись переопределяет одноимённую config-запись целиком), а
|
|
300
|
+
* `disabledProfiles` убирают профили config-базы из эффективного каталога.
|
|
301
|
+
*/
|
|
302
|
+
export function applyExecutionRuntimeSettings(resolved, runtime, env = process.env) {
|
|
303
|
+
if (!runtime)
|
|
304
|
+
return resolved;
|
|
305
|
+
const remote = resolved.remote;
|
|
306
|
+
const catalog = effectiveExecutionCatalog(resolved, runtime, env);
|
|
307
|
+
const pooling = envSet(env, EXECUTION_ENV.pooling)
|
|
308
|
+
? remote.pooling
|
|
309
|
+
: (runtime.pooling ?? remote.pooling);
|
|
310
|
+
const fallback = envSet(env, EXECUTION_ENV.fallback)
|
|
311
|
+
? remote.fallback
|
|
312
|
+
: (runtime.fallback ?? remote.fallback);
|
|
313
|
+
return {
|
|
314
|
+
...resolved,
|
|
315
|
+
remote: {
|
|
316
|
+
...remote,
|
|
317
|
+
defaultProfile: catalog.defaultProfile,
|
|
318
|
+
browserProfile: catalog.browserProfile,
|
|
319
|
+
browserProfiles: [...catalog.browserProfiles],
|
|
320
|
+
pooling,
|
|
321
|
+
fallback,
|
|
322
|
+
profiles: catalog.profiles,
|
|
323
|
+
...(catalog.disabledProfiles.length > 0
|
|
324
|
+
? { disabledProfiles: [...catalog.disabledProfiles] }
|
|
325
|
+
: {}),
|
|
326
|
+
profileOrigins: { ...catalog.origins },
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Снимок эффективной секции `execution` в форме runtime-секции.
|
|
332
|
+
*
|
|
333
|
+
* Нужен админ-API: «что сейчас работает» (`running`) и «что сохранено»
|
|
334
|
+
* (`saved`) сравниваются одним отпечатком. Профили приводятся к runtime-форме
|
|
335
|
+
* (только поля runtime-модели; `url` — фактический адрес профиля, включая
|
|
336
|
+
* унаследованный; `class` — **эффективный** класс профиля; `mcpServers` —
|
|
337
|
+
* имя + команда, если она известна).
|
|
338
|
+
*/
|
|
339
|
+
export function executionRuntimeSettingsFromResolved(resolved) {
|
|
340
|
+
if (!resolved)
|
|
341
|
+
return null;
|
|
342
|
+
const remote = resolved.remote;
|
|
343
|
+
const profiles = {};
|
|
344
|
+
for (const [name, profile] of Object.entries(remote.profiles ?? {})) {
|
|
345
|
+
const entry = {};
|
|
346
|
+
if (profile.description !== undefined && profile.description !== '') {
|
|
347
|
+
entry.description = profile.description;
|
|
348
|
+
}
|
|
349
|
+
if (profile.image !== undefined && profile.image !== '')
|
|
350
|
+
entry.image = profile.image;
|
|
351
|
+
if (profile.url.length > 0)
|
|
352
|
+
entry.url = [...profile.url];
|
|
353
|
+
if (profile.network !== undefined)
|
|
354
|
+
entry.network = profile.network;
|
|
355
|
+
if (profile.resources !== undefined)
|
|
356
|
+
entry.resources = toRuntimeResources(profile.resources);
|
|
357
|
+
if (profile.annotations !== undefined && Object.keys(profile.annotations).length > 0) {
|
|
358
|
+
entry.annotations = { ...profile.annotations };
|
|
359
|
+
}
|
|
360
|
+
if (profile.labels !== undefined && Object.keys(profile.labels).length > 0) {
|
|
361
|
+
entry.labels = { ...profile.labels };
|
|
362
|
+
}
|
|
363
|
+
if (profile.nodeSelector !== undefined && Object.keys(profile.nodeSelector).length > 0) {
|
|
364
|
+
entry.nodeSelector = { ...profile.nodeSelector };
|
|
365
|
+
}
|
|
366
|
+
if (profile.tolerations !== undefined && profile.tolerations.length > 0) {
|
|
367
|
+
entry.tolerations = profile.tolerations.map((toleration) => ({ ...toleration }));
|
|
368
|
+
}
|
|
369
|
+
if (profile.affinity !== undefined && Object.keys(profile.affinity).length > 0) {
|
|
370
|
+
entry.affinity = { ...profile.affinity };
|
|
371
|
+
}
|
|
372
|
+
if (profile.runtimeClass !== undefined && profile.runtimeClass !== '') {
|
|
373
|
+
entry.runtimeClass = profile.runtimeClass;
|
|
374
|
+
}
|
|
375
|
+
if (profile.readOnlyRootFilesystem !== undefined) {
|
|
376
|
+
entry.readOnlyRootFilesystem = profile.readOnlyRootFilesystem;
|
|
377
|
+
}
|
|
378
|
+
if (profile.env !== undefined && Object.keys(profile.env).length > 0) {
|
|
379
|
+
entry.env = { ...profile.env };
|
|
380
|
+
}
|
|
381
|
+
// Эффективный класс профиля (ADR-135, аддендум §11): объявленный класс,
|
|
382
|
+
// иначе — выведенный из legacy-списка браузерных имён/`browserProfile`.
|
|
383
|
+
entry.class = effectiveProfileClass(profile, name, remote.browserProfiles, remote.browserProfile);
|
|
384
|
+
if (profile.mcpServers !== undefined && profile.mcpServers.length > 0) {
|
|
385
|
+
entry.mcpServers = profile.mcpServers.map((server) => ({
|
|
386
|
+
name: server.name,
|
|
387
|
+
...(server.command !== undefined && server.command !== ''
|
|
388
|
+
? { command: server.command }
|
|
389
|
+
: {}),
|
|
390
|
+
...(server.args !== undefined && server.args.length > 0
|
|
391
|
+
? { args: [...server.args] }
|
|
392
|
+
: {}),
|
|
393
|
+
...(server.env !== undefined && Object.keys(server.env).length > 0
|
|
394
|
+
? { env: { ...server.env } }
|
|
395
|
+
: {}),
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
profiles[name] = entry;
|
|
399
|
+
}
|
|
400
|
+
const snapshot = {
|
|
401
|
+
defaultProfile: remote.defaultProfile,
|
|
402
|
+
browserProfile: remote.browserProfile,
|
|
403
|
+
// Legacy-подсказка класса (не эффективный каталог): эффективный класс
|
|
404
|
+
// каждого профиля уже записан в `profiles[name].class`.
|
|
405
|
+
browserProfiles: [...remote.browserProfiles],
|
|
406
|
+
pooling: remote.pooling,
|
|
407
|
+
fallback: remote.fallback,
|
|
408
|
+
profiles,
|
|
409
|
+
};
|
|
410
|
+
if (remote.disabledProfiles !== undefined && remote.disabledProfiles.length > 0) {
|
|
411
|
+
snapshot.disabledProfiles = [...remote.disabledProfiles];
|
|
412
|
+
}
|
|
413
|
+
return snapshot;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Слить config-уровень и runtime-секцию (runtime > config).
|
|
417
|
+
*
|
|
418
|
+
* `profiles` runtime-секции **сливается** с каталогом base: одноимённая
|
|
419
|
+
* запись runtime переопределяет base целиком, остальные base-записи
|
|
420
|
+
* сохраняются (ADR-135, аддендум §11).
|
|
421
|
+
*/
|
|
422
|
+
export function mergeExecutionRuntimeSettings(base, runtime) {
|
|
423
|
+
const merged = {
|
|
424
|
+
...(base ?? {}),
|
|
425
|
+
...(runtime ?? {}),
|
|
426
|
+
};
|
|
427
|
+
merged.profiles = { ...(base?.profiles ?? {}), ...(runtime?.profiles ?? {}) };
|
|
428
|
+
const disabled = [
|
|
429
|
+
...(base?.disabledProfiles ?? []),
|
|
430
|
+
...(runtime?.disabledProfiles ?? []),
|
|
431
|
+
].filter((name, index, list) => list.indexOf(name) === index);
|
|
432
|
+
if (disabled.length > 0)
|
|
433
|
+
merged.disabledProfiles = disabled;
|
|
434
|
+
else
|
|
435
|
+
delete merged.disabledProfiles;
|
|
436
|
+
return merged;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Имена профилей **эффективного** каталога (после применения runtime-секции).
|
|
440
|
+
*
|
|
441
|
+
* Каталог = config-профили + runtime-профили (override) − отключённые.
|
|
442
|
+
*/
|
|
443
|
+
export function effectiveExecutionProfileNames(base, runtime) {
|
|
444
|
+
const merged = { ...(base?.profiles ?? {}), ...(runtime?.profiles ?? {}) };
|
|
445
|
+
const disabled = new Set([
|
|
446
|
+
...(base?.disabledProfiles ?? []),
|
|
447
|
+
...(runtime?.disabledProfiles ?? []),
|
|
448
|
+
]);
|
|
449
|
+
return Object.keys(merged).filter((name) => !disabled.has(name));
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Отпечаток runtime-секции — для сравнения «сохранено» vs «работает»
|
|
453
|
+
* (`restartRequired`).
|
|
454
|
+
*
|
|
455
|
+
* Нормализация: имена профилей — по алфавиту, ключи профиля — по алфавиту,
|
|
456
|
+
* списки (`url`, `mcpServers`, `disabledProfiles`) — по алфавиту (порядок
|
|
457
|
+
* элементов и ключей не влияет на отпечаток). Пустая секция и `null` — один
|
|
458
|
+
* отпечаток («ничего не задано»).
|
|
459
|
+
*/
|
|
460
|
+
export function executionRuntimeFingerprint(settings) {
|
|
461
|
+
if (!settings)
|
|
462
|
+
return 'none';
|
|
463
|
+
const profiles = Object.keys(settings.profiles ?? {})
|
|
464
|
+
.sort((a, b) => a.localeCompare(b))
|
|
465
|
+
.map((name) => {
|
|
466
|
+
const profile = settings.profiles?.[name];
|
|
467
|
+
const entry = {};
|
|
468
|
+
for (const key of Object.keys(profile ?? {}).sort()) {
|
|
469
|
+
const value = profile[key];
|
|
470
|
+
if (value === undefined)
|
|
471
|
+
continue;
|
|
472
|
+
entry[key] = normalizeFingerprintValue(value);
|
|
473
|
+
}
|
|
474
|
+
return { name, profile: entry };
|
|
475
|
+
});
|
|
476
|
+
return JSON.stringify({
|
|
477
|
+
defaultProfile: settings.defaultProfile ?? null,
|
|
478
|
+
browserProfile: settings.browserProfile ?? null,
|
|
479
|
+
browserProfiles: [...(settings.browserProfiles ?? [])].sort(),
|
|
480
|
+
disabledProfiles: [...(settings.disabledProfiles ?? [])].sort(),
|
|
481
|
+
pooling: settings.pooling ?? null,
|
|
482
|
+
fallback: settings.fallback ?? null,
|
|
483
|
+
profiles,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Нормализация значения для отпечатка: объекты — по алфавиту ключей, списки —
|
|
488
|
+
* по алфавиту (строковое представление). Порядок не влияет на сравнение
|
|
489
|
+
* «сохранено» vs «работает».
|
|
490
|
+
*/
|
|
491
|
+
function normalizeFingerprintValue(value) {
|
|
492
|
+
if (Array.isArray(value)) {
|
|
493
|
+
return value
|
|
494
|
+
.map((item) => normalizeFingerprintValue(item))
|
|
495
|
+
.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
496
|
+
}
|
|
497
|
+
if (value !== null && typeof value === 'object') {
|
|
498
|
+
return Object.keys(value)
|
|
499
|
+
.sort()
|
|
500
|
+
.reduce((acc, key) => {
|
|
501
|
+
acc[key] = normalizeFingerprintValue(value[key]);
|
|
502
|
+
return acc;
|
|
503
|
+
}, {});
|
|
504
|
+
}
|
|
505
|
+
return value;
|
|
506
|
+
}
|