@zhin.js/host-http 1.1.14 → 1.1.15

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.
@@ -0,0 +1,608 @@
1
+ import {
2
+ CONFIG_PATCH_LIMITS,
3
+ ENDPOINT_RPC,
4
+ type ConsoleConfigApplicationStatus,
5
+ } from '@zhin.js/console-protocol';
6
+ import type {
7
+ ConversationAddress,
8
+ RuntimeConsoleRpcContext,
9
+ RuntimeConsoleRpcMessage,
10
+ RuntimeConsoleRpcReply,
11
+ } from './console-rpc.js';
12
+
13
+ /** Canonical Console wire fields → runtime conversation address. */
14
+ export function wireConversation(
15
+ channelType: string,
16
+ channelId: string,
17
+ parent: unknown,
18
+ ): ConversationAddress {
19
+ const kind: ConversationAddress['kind'] =
20
+ channelType === 'group' || channelType === 'channel' ? channelType : 'private';
21
+ const wire = parent && typeof parent === 'object'
22
+ ? parent as { readonly type?: unknown; readonly id?: unknown }
23
+ : undefined;
24
+ const parentKind = wire?.type === 'group' || wire?.type === 'channel' ? wire.type : undefined;
25
+ const parentId = typeof wire?.id === 'string' && wire.id ? wire.id : undefined;
26
+ return {
27
+ kind,
28
+ id: channelId,
29
+ ...(parentKind && parentId ? { parent: { kind: parentKind, id: parentId } } : {}),
30
+ };
31
+ }
32
+
33
+ const FORBIDDEN_PATCH_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype']);
34
+
35
+ /**
36
+ * Structural check for `config:patch-project` operations at the RPC boundary, so no project
37
+ * port implementation receives a malformed request. The store repeats the full validation.
38
+ */
39
+ export function invalidProjectPatchOperations(patches: readonly unknown[]): string | undefined {
40
+ if (patches.length === 0) return 'patches 必须是非空数组';
41
+ if (patches.length > CONFIG_PATCH_LIMITS.maxOperations) return `一次最多 ${CONFIG_PATCH_LIMITS.maxOperations} 个 patch`;
42
+ for (const [index, item] of patches.entries()) {
43
+ if (!item || typeof item !== 'object' || Array.isArray(item)) return `patches[${index}] 必须是对象`;
44
+ const operation = item as Record<string, unknown>;
45
+ const path = operation.path;
46
+ if (!Array.isArray(path) || path.length === 0 || path.length > CONFIG_PATCH_LIMITS.maxPathDepth
47
+ || path.some(segment => typeof segment !== 'string' || !segment
48
+ || segment.length > CONFIG_PATCH_LIMITS.maxSegmentLength || FORBIDDEN_PATCH_SEGMENTS.has(segment))) {
49
+ return `patches[${index}].path 必须是 1–${CONFIG_PATCH_LIMITS.maxPathDepth} 段的有效字符串数组`;
50
+ }
51
+ if (operation.op === 'set') {
52
+ if (!Object.hasOwn(operation, 'value') || operation.value === undefined) return `patches[${index}] 的 set 需要 value`;
53
+ } else if (operation.op !== 'remove') return `patches[${index}].op 只能是 set 或 remove`;
54
+ }
55
+ return undefined;
56
+ }
57
+
58
+ export async function dispatchHostResourceConsoleRpc(
59
+ type: string,
60
+ message: RuntimeConsoleRpcMessage,
61
+ ctx: RuntimeConsoleRpcContext,
62
+ requestId: number | string | undefined,
63
+ payloads: RuntimeConsoleRpcReply[],
64
+ ): Promise<boolean> {
65
+ const emit = (payload: RuntimeConsoleRpcReply) => {
66
+ payloads.push(payload);
67
+ };
68
+
69
+ switch (type) {
70
+ case 'files:tree': {
71
+ try {
72
+ const tree = ctx.listProjectFiles ? await ctx.listProjectFiles() : [];
73
+ emit({ requestId, data: { tree } });
74
+ } catch (error) {
75
+ emit({
76
+ requestId,
77
+ error: `Failed to build file tree: ${error instanceof Error ? error.message : String(error)}`,
78
+ });
79
+ }
80
+ return true;
81
+ }
82
+ case 'files:read': {
83
+ try {
84
+ const filePath = String(message.filePath ?? '');
85
+ if (!filePath) {
86
+ emit({ requestId, error: 'filePath is required' });
87
+ return true;
88
+ }
89
+ if (!ctx.readProjectFile) {
90
+ emit({ requestId, error: 'File read is not configured' });
91
+ return true;
92
+ }
93
+ const file = await ctx.readProjectFile(filePath);
94
+ emit({ requestId, data: file });
95
+ } catch (error) {
96
+ emit({
97
+ requestId,
98
+ error: `Failed to read file: ${error instanceof Error ? error.message : String(error)}`,
99
+ });
100
+ }
101
+ return true;
102
+ }
103
+ case 'files:save': {
104
+ try {
105
+ const filePath = String(message.filePath ?? '');
106
+ const content = message.content;
107
+ if (!filePath) {
108
+ emit({ requestId, error: 'filePath is required' });
109
+ return true;
110
+ }
111
+ if (typeof content !== 'string') {
112
+ emit({ requestId, error: 'content field is required' });
113
+ return true;
114
+ }
115
+ if (!ctx.saveProjectFile) {
116
+ emit({ requestId, error: 'File write is not configured' });
117
+ return true;
118
+ }
119
+ await ctx.saveProjectFile(filePath, content);
120
+ emit({ requestId, data: { success: true, message: `文件已保存: ${filePath}` } });
121
+ } catch (error) {
122
+ emit({
123
+ requestId,
124
+ error: `Failed to save file: ${error instanceof Error ? error.message : String(error)}`,
125
+ });
126
+ }
127
+ return true;
128
+ }
129
+ case 'env:list': {
130
+ try {
131
+ const files = ctx.listEnvFiles ? await ctx.listEnvFiles() : [];
132
+ emit({ requestId, data: { files } });
133
+ } catch (error) {
134
+ emit({
135
+ requestId,
136
+ error: `Failed to list env files: ${error instanceof Error ? error.message : String(error)}`,
137
+ });
138
+ }
139
+ return true;
140
+ }
141
+ case 'env:get': {
142
+ try {
143
+ const filename = String(message.filename ?? '');
144
+ if (!filename) {
145
+ emit({ requestId, error: 'filename is required' });
146
+ return true;
147
+ }
148
+ if (!ctx.readEnvFile) {
149
+ emit({ requestId, error: 'Env read is not configured' });
150
+ return true;
151
+ }
152
+ const content = await ctx.readEnvFile(filename);
153
+ emit({ requestId, data: { content } });
154
+ } catch (error) {
155
+ emit({
156
+ requestId,
157
+ error: `Failed to read env file: ${error instanceof Error ? error.message : String(error)}`,
158
+ });
159
+ }
160
+ return true;
161
+ }
162
+ case 'env:save': {
163
+ try {
164
+ const filename = String(message.filename ?? '');
165
+ const content = message.content;
166
+ if (!filename) {
167
+ emit({ requestId, error: 'filename is required' });
168
+ return true;
169
+ }
170
+ if (typeof content !== 'string') {
171
+ emit({ requestId, error: 'content field is required' });
172
+ return true;
173
+ }
174
+ if (!ctx.writeEnvFile) {
175
+ emit({ requestId, error: 'Env write is not configured' });
176
+ return true;
177
+ }
178
+ await ctx.writeEnvFile(filename, content);
179
+ emit({ requestId, data: { success: true, message: `环境文件已保存: ${filename}` } });
180
+ } catch (error) {
181
+ emit({
182
+ requestId,
183
+ error: `Failed to save env file: ${error instanceof Error ? error.message : String(error)}`,
184
+ });
185
+ }
186
+ return true;
187
+ }
188
+ case 'schema:get': {
189
+ try {
190
+ const pluginName = typeof message.pluginName === 'string'
191
+ ? message.pluginName
192
+ : undefined;
193
+ const schema = ctx.getSchema ? await ctx.getSchema(pluginName) : null;
194
+ emit({ requestId, data: schema });
195
+ } catch (error) {
196
+ emit({
197
+ requestId,
198
+ error: `Failed to get schema: ${error instanceof Error ? error.message : String(error)}`,
199
+ });
200
+ }
201
+ return true;
202
+ }
203
+ case 'schema:get-all': {
204
+ try {
205
+ const schemas = ctx.getAllSchemas ? await ctx.getAllSchemas() : {};
206
+ emit({ requestId, data: schemas });
207
+ } catch (error) {
208
+ emit({
209
+ requestId,
210
+ error: `Failed to get all schemas: ${error instanceof Error ? error.message : String(error)}`,
211
+ });
212
+ }
213
+ return true;
214
+ }
215
+ case 'db:info': {
216
+ if (ctx.database) {
217
+ emit({ requestId, data: ctx.database.info() });
218
+ return true;
219
+ }
220
+ if (ctx.dbInfo) {
221
+ try {
222
+ emit({ requestId, data: await ctx.dbInfo() });
223
+ } catch (error) {
224
+ emit({
225
+ requestId,
226
+ error: error instanceof Error ? error.message : String(error),
227
+ });
228
+ }
229
+ return true;
230
+ }
231
+ emit({
232
+ requestId,
233
+ data: { dialect: null, connected: false, message: 'Database not configured on Plugin Runtime Host' },
234
+ });
235
+ return true;
236
+ }
237
+ case 'db:tables': {
238
+ try {
239
+ if (ctx.database) {
240
+ emit({ requestId, data: { tables: ctx.database.tables() } });
241
+ return true;
242
+ }
243
+ const tables = ctx.dbTables ? await ctx.dbTables() : [];
244
+ emit({ requestId, data: tables });
245
+ } catch (error) {
246
+ emit({
247
+ requestId,
248
+ error: error instanceof Error ? error.message : String(error),
249
+ });
250
+ }
251
+ return true;
252
+ }
253
+ case 'db:select': {
254
+ const table = stringField(message, 'table');
255
+ if (!table) { errorReply(payloads, requestId, 'table is required'); return true; }
256
+ const page = positiveInteger(message.page, 1);
257
+ const pageSize = Math.min(positiveInteger(message.pageSize, 50), 500);
258
+ const where = recordField(message.where);
259
+ if (!ctx.database) {
260
+ emit({ requestId, data: { rows: [], total: 0, page, pageSize } });
261
+ return true;
262
+ }
263
+ try {
264
+ emit({ requestId, data: await ctx.database.select(table, page, pageSize, where) });
265
+ } catch (error) {
266
+ emit({ requestId, error: `Failed to select: ${errorMessage(error)}` });
267
+ }
268
+ return true;
269
+ }
270
+ case 'db:insert': {
271
+ if (!ctx.database) { errorReply(payloads, requestId, 'Database RPC is not available on Plugin Runtime Host'); return true; }
272
+ const table = stringField(message, 'table');
273
+ const row = recordField(message.row);
274
+ if (!table || !row) { errorReply(payloads, requestId, 'table and row are required'); return true; }
275
+ try {
276
+ await ctx.database.insert(table, row);
277
+ emit({ requestId, data: { success: true } });
278
+ } catch (error) {
279
+ emit({ requestId, error: `Failed to insert: ${errorMessage(error)}` });
280
+ }
281
+ return true;
282
+ }
283
+ case 'db:update': {
284
+ if (!ctx.database) { errorReply(payloads, requestId, 'Database RPC is not available on Plugin Runtime Host'); return true; }
285
+ const table = stringField(message, 'table');
286
+ const row = recordField(message.row);
287
+ const where = recordField(message.where);
288
+ if (!table || !row || !where) {
289
+ errorReply(payloads, requestId, 'table, row, and where are required');
290
+ return true;
291
+ }
292
+ try {
293
+ const affected = await ctx.database.update(table, row, where);
294
+ emit({ requestId, data: { success: true, affected } });
295
+ } catch (error) {
296
+ emit({ requestId, error: `Failed to update: ${errorMessage(error)}` });
297
+ }
298
+ return true;
299
+ }
300
+ case 'db:delete': {
301
+ if (!ctx.database) { errorReply(payloads, requestId, 'Database RPC is not available on Plugin Runtime Host'); return true; }
302
+ const table = stringField(message, 'table');
303
+ const where = recordField(message.where);
304
+ if (!table || !where) { errorReply(payloads, requestId, 'table and where are required'); return true; }
305
+ try {
306
+ const deleted = await ctx.database.delete(table, where);
307
+ emit({ requestId, data: { success: true, deleted } });
308
+ } catch (error) {
309
+ emit({ requestId, error: `Failed to delete: ${errorMessage(error)}` });
310
+ }
311
+ return true;
312
+ }
313
+ case 'db:drop-table': {
314
+ if (!ctx.database) { errorReply(payloads, requestId, 'Database RPC is not available on Plugin Runtime Host'); return true; }
315
+ const table = stringField(message, 'table');
316
+ if (!table) { errorReply(payloads, requestId, 'table is required'); return true; }
317
+ try {
318
+ await ctx.database.dropTable(table);
319
+ emit({ requestId, data: { success: true } });
320
+ } catch (error) {
321
+ emit({ requestId, error: `Failed to drop table: ${errorMessage(error)}` });
322
+ }
323
+ return true;
324
+ }
325
+ case 'db:kv:get': {
326
+ const table = stringField(message, 'table');
327
+ const key = stringField(message, 'key');
328
+ if (!table || !key) { errorReply(payloads, requestId, 'table and key are required'); return true; }
329
+ if (!ctx.database) {
330
+ emit({ requestId, data: { key, value: null } });
331
+ return true;
332
+ }
333
+ try {
334
+ emit({ requestId, data: { key, value: await ctx.database.kvGet(table, key) } });
335
+ } catch (error) {
336
+ emit({ requestId, error: `Failed to get kv: ${errorMessage(error)}` });
337
+ }
338
+ return true;
339
+ }
340
+ case 'db:kv:set': {
341
+ if (!ctx.database) { errorReply(payloads, requestId, 'Database RPC is not available on Plugin Runtime Host'); return true; }
342
+ const table = stringField(message, 'table');
343
+ const key = stringField(message, 'key');
344
+ if (!table || !key) { errorReply(payloads, requestId, 'table and key are required'); return true; }
345
+ try {
346
+ const ttl = typeof message.ttl === 'number' && Number.isFinite(message.ttl)
347
+ ? message.ttl
348
+ : undefined;
349
+ await ctx.database.kvSet(table, key, message.value, ttl);
350
+ emit({ requestId, data: { success: true } });
351
+ } catch (error) {
352
+ emit({ requestId, error: `Failed to set kv: ${errorMessage(error)}` });
353
+ }
354
+ return true;
355
+ }
356
+ case 'db:kv:delete': {
357
+ if (!ctx.database) { errorReply(payloads, requestId, 'Database RPC is not available on Plugin Runtime Host'); return true; }
358
+ const table = stringField(message, 'table');
359
+ const key = stringField(message, 'key');
360
+ if (!table || !key) { errorReply(payloads, requestId, 'table and key are required'); return true; }
361
+ try {
362
+ await ctx.database.kvDelete(table, key);
363
+ emit({ requestId, data: { success: true } });
364
+ } catch (error) {
365
+ emit({ requestId, error: `Failed to delete kv: ${errorMessage(error)}` });
366
+ }
367
+ return true;
368
+ }
369
+ case 'db:kv:entries': {
370
+ const table = stringField(message, 'table');
371
+ if (!table) { errorReply(payloads, requestId, 'table is required'); return true; }
372
+ if (!ctx.database) {
373
+ emit({ requestId, data: { entries: [] } });
374
+ return true;
375
+ }
376
+ try {
377
+ emit({ requestId, data: { entries: await ctx.database.kvEntries(table) } });
378
+ } catch (error) {
379
+ emit({ requestId, error: `Failed to get entries: ${errorMessage(error)}` });
380
+ }
381
+ return true;
382
+ }
383
+ case 'endpoint.list': {
384
+ try {
385
+ const endpoints = ctx.listEndpoints ? await ctx.listEndpoints() : [];
386
+ emit({ requestId, data: { endpoints } });
387
+ } catch (error) {
388
+ emit({
389
+ requestId,
390
+ error: error instanceof Error ? error.message : String(error),
391
+ });
392
+ }
393
+ return true;
394
+ }
395
+ case 'endpoint.info': {
396
+ try {
397
+ const data = recordField(message.data) ?? message;
398
+ const adapter = String(data.adapter ?? '');
399
+ const endpointKey = String(data.endpointKey ?? '');
400
+ if (!adapter || !endpointKey) {
401
+ emit({ requestId, error: 'adapter and endpointKey are required' });
402
+ return true;
403
+ }
404
+ if (!ctx.getEndpoint) {
405
+ emit({ requestId, error: 'Endpoint registry is not configured' });
406
+ return true;
407
+ }
408
+ const endpoint = await ctx.getEndpoint(adapter, endpointKey);
409
+ if (!endpoint) {
410
+ emit({ requestId, error: 'endpoint not found' });
411
+ return true;
412
+ }
413
+ emit({ requestId, data: endpoint });
414
+ } catch (error) {
415
+ emit({
416
+ requestId,
417
+ error: error instanceof Error ? error.message : String(error),
418
+ });
419
+ }
420
+ return true;
421
+ }
422
+ case ENDPOINT_RPC.TEST: {
423
+ const data = recordField(message.data) ?? message;
424
+ const adapter = stringField(data, 'adapter');
425
+ const endpointKey = stringField(data, 'endpointKey');
426
+ if (!adapter || !endpointKey) {
427
+ emit({ requestId, error: 'adapter and endpointKey are required' });
428
+ return true;
429
+ }
430
+ if (!ctx.getEndpoint) {
431
+ emit({ requestId, error: 'Endpoint registry is not configured' });
432
+ return true;
433
+ }
434
+ const startedAt = Date.now();
435
+ try {
436
+ const endpoint = await ctx.getEndpoint(adapter, endpointKey);
437
+ if (!endpoint) {
438
+ emit({ requestId, data: {
439
+ reachable: false,
440
+ connected: false,
441
+ phase: 'unconfigured',
442
+ latencyMs: Date.now() - startedAt,
443
+ message: 'Endpoint 未注册到当前 generation',
444
+ } });
445
+ return true;
446
+ }
447
+ emit({ requestId, data: {
448
+ reachable: endpoint.connected && endpoint.status === 'online',
449
+ connected: endpoint.connected,
450
+ status: endpoint.status,
451
+ admitted: endpoint.admitted,
452
+ transportState: endpoint.transportState,
453
+ phase: endpoint.phase ?? (endpoint.connected ? 'online' : 'pending'),
454
+ pendingLogin: endpoint.pendingLogin ?? false,
455
+ latencyMs: Date.now() - startedAt,
456
+ message: endpoint.connected
457
+ ? 'Endpoint 已连接'
458
+ : endpoint.pendingLogin
459
+ ? 'Endpoint 等待登录操作'
460
+ : 'Endpoint 当前离线',
461
+ } });
462
+ } catch (error) {
463
+ emit({ requestId, data: {
464
+ reachable: false,
465
+ connected: false,
466
+ phase: 'failed',
467
+ latencyMs: Date.now() - startedAt,
468
+ message: error instanceof Error ? error.message : String(error),
469
+ } });
470
+ }
471
+ return true;
472
+ }
473
+ case 'endpoint.send_message': {
474
+ try {
475
+ const data = recordField(message.data) ?? message;
476
+ const adapter = String(data.adapter ?? '');
477
+ const endpointKey = String(data.endpointKey ?? '');
478
+ const channelId = String(data.channelId ?? data.id ?? '');
479
+ const channelType = String(data.channelType ?? data.type ?? '');
480
+ const content = data.content;
481
+ if (!adapter || !endpointKey || !channelId || !channelType || content === undefined) {
482
+ emit({
483
+ requestId,
484
+ error: 'adapter, endpointKey, channelId, channelType, and content are required',
485
+ });
486
+ return true;
487
+ }
488
+ if (!ctx.sendEndpointMessage) {
489
+ emit({ requestId, error: 'Endpoint send is not configured' });
490
+ return true;
491
+ }
492
+ const result = await ctx.sendEndpointMessage({
493
+ adapter,
494
+ endpointKey,
495
+ conversation: wireConversation(channelType, channelId, data.parent),
496
+ content,
497
+ });
498
+ emit({ requestId, data: { messageId: result.messageId } });
499
+ } catch (error) {
500
+ emit({
501
+ requestId,
502
+ error: error instanceof Error ? error.message : String(error),
503
+ });
504
+ }
505
+ return true;
506
+ }
507
+ case 'system:restart': {
508
+ try {
509
+ if (!ctx.requestRestart) {
510
+ emit({ requestId, error: 'Process restart is not configured' });
511
+ return true;
512
+ }
513
+ ctx.publishEvent?.('system:restarting', { timestamp: Date.now() });
514
+ emit({ requestId, data: { success: true, message: '正在重启...' } });
515
+ // Delay so the HTTP response can flush (parity with legacy host-api).
516
+ setTimeout(() => {
517
+ void Promise.resolve(ctx.requestRestart?.()).catch(() => {
518
+ /* restart is best-effort */
519
+ });
520
+ }, 500);
521
+ } catch (error) {
522
+ emit({
523
+ requestId,
524
+ error: error instanceof Error ? error.message : String(error),
525
+ });
526
+ }
527
+ return true;
528
+ }
529
+ default:
530
+ return false;
531
+ }
532
+ }
533
+
534
+ export function stringField(message: RuntimeConsoleRpcMessage, key: string): string {
535
+ const value = message[key];
536
+ return typeof value === 'string' ? value.trim() : '';
537
+ }
538
+
539
+ export function recordField(value: unknown): Record<string, unknown> | undefined {
540
+ return value && typeof value === 'object' && !Array.isArray(value)
541
+ ? value as Record<string, unknown>
542
+ : undefined;
543
+ }
544
+
545
+ export function positiveInteger(value: unknown, fallback: number): number {
546
+ const parsed = Number(value ?? fallback);
547
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
548
+ }
549
+
550
+ export function errorMessage(error: unknown): string {
551
+ return error instanceof Error ? error.message : String(error);
552
+ }
553
+
554
+ export function errorReply(
555
+ payloads: RuntimeConsoleRpcReply[],
556
+ requestId: number | string | undefined,
557
+ error: string,
558
+ ): RuntimeConsoleRpcReply[] {
559
+ payloads.push({ requestId, error });
560
+ return payloads;
561
+ }
562
+
563
+ /** HTTP paths under apiBase that demo scope may call (ADR 0016). */
564
+ export function isDemoHttpAllowed(method: string, pathname: string, apiBase: string): boolean {
565
+ const normalizedBase = apiBase.replace(/\/$/u, '') || '/api';
566
+ const m = method.toUpperCase();
567
+ // Each inference handler resolves a static authenticated personal binding before reading or mutating anything.
568
+ if (m === 'GET' && ['', '/owners', '/export', '/mutation', '/sessions', '/session'].some(path => pathname === `${normalizedBase}/agent/inference${path}`)) return true;
569
+ if (m === 'PUT' && pathname === `${normalizedBase}/agent/inference/session`) return true;
570
+ if (m === 'POST' && ['/plan', '/apply', '/key/prepare', '/discover', '/profile-schema'].some(path => pathname === `${normalizedBase}/agent/inference${path}`)) return true;
571
+ if (m === 'GET' && pathname === `${normalizedBase}/events`) return true;
572
+ if (m === 'GET' && pathname === `${normalizedBase}/events/history`) return true;
573
+ if (m === 'GET' && DEMO_INTROSPECTION_PATHS.has(pathname.slice(normalizedBase.length))) return true;
574
+ if (m === 'POST' && pathname === `${normalizedBase}/console/request`) return true;
575
+ // Read-only dashboard / plugin inspection routes (legacy host-api parity).
576
+ if (m === 'GET' && pathname === `${normalizedBase}/system/status`) return true;
577
+ if (m === 'GET' && pathname === `${normalizedBase}/stats`) return true;
578
+ if (m === 'GET' && (pathname === `${normalizedBase}/plugins`
579
+ || pathname.startsWith(`${normalizedBase}/plugins/`))) return true;
580
+ return false;
581
+ }
582
+
583
+ export function configurationSaveMessage(result: { restartRequired: boolean; revision?: string }
584
+ & ConsoleConfigApplicationStatus): string {
585
+ if (result.applicationError === 'superseded') return '配置已保存,但该次生效申请已被替代';
586
+ if (result.applicationError === 'invalid') return '配置已保存,但配置校验失败,未生效';
587
+ if (result.applicationError) return '配置已保存,生效结果未确认';
588
+ if (result.application) {
589
+ if (result.revision && result.application.sourceRevision !== result.revision) return '配置已保存,但已被较新修订替代';
590
+ if (result.application.groups.some(group => group.status === 'unknown')) return '配置已保存,生效结果未确认';
591
+ if (result.application.groups.some(group => group.status === 'superseded')) return '配置已保存,但该次生效申请已被替代';
592
+ if (result.application.groups.some(group => ['failed', 'blocked'].includes(group.status))) return '配置已保存,部分配置未生效';
593
+ if (result.restartRequired) return '配置已保存,部分配置待重启生效';
594
+ return '配置已保存并已生效';
595
+ }
596
+ return result.restartRequired ? '配置已保存,需重启进程才能生效' : '配置已保存';
597
+ }
598
+
599
+ const DEMO_INTROSPECTION_PATHS: ReadonlySet<string> = new Set([
600
+ '/introspection/commands',
601
+ '/introspection/middlewares',
602
+ '/introspection/components',
603
+ '/introspection/endpoints',
604
+ '/introspection/bindings',
605
+ '/introspection/tools',
606
+ '/introspection/prompt-sections',
607
+ '/introspection/mcp',
608
+ ]);