@zhin.js/runtime 1.1.2 → 1.1.4

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.
@@ -1,6 +1,570 @@
1
1
  import type { RuntimeConfigDocument } from '@zhin.js/plugin-runtime';
2
2
  import type { PluginId } from '@zhin.js/plugin-runtime';
3
3
  import type { ProjectGraph } from './project-graph.js';
4
+ export declare const HOST_CONFIG_SCHEMA: {
5
+ $schema: string;
6
+ type: string;
7
+ additionalProperties: boolean;
8
+ properties: {
9
+ http: {
10
+ type: string;
11
+ additionalProperties: boolean;
12
+ description: string;
13
+ "x-descriptionZh": string;
14
+ properties: {
15
+ readiness: {
16
+ type: string;
17
+ additionalProperties: boolean;
18
+ description: string;
19
+ "x-descriptionZh": string;
20
+ properties: {
21
+ database: {
22
+ type: string;
23
+ default: boolean;
24
+ description: string;
25
+ "x-descriptionZh": string;
26
+ };
27
+ endpoints: {
28
+ type: string;
29
+ uniqueItems: boolean;
30
+ description: string;
31
+ "x-descriptionZh": string;
32
+ items: {
33
+ type: string;
34
+ additionalProperties: boolean;
35
+ required: string[];
36
+ properties: {
37
+ owner: {
38
+ type: string;
39
+ pattern: string;
40
+ };
41
+ name: {
42
+ type: string;
43
+ minLength: number;
44
+ pattern: string;
45
+ };
46
+ };
47
+ };
48
+ };
49
+ agents: {
50
+ type: string;
51
+ uniqueItems: boolean;
52
+ items: {
53
+ type: string;
54
+ minLength: number;
55
+ };
56
+ description: string;
57
+ "x-descriptionZh": string;
58
+ };
59
+ };
60
+ };
61
+ };
62
+ };
63
+ database: {
64
+ type: string;
65
+ additionalProperties: boolean;
66
+ description: string;
67
+ "x-descriptionZh": string;
68
+ };
69
+ ai: {
70
+ type: string;
71
+ additionalProperties: boolean;
72
+ description: string;
73
+ "x-descriptionZh": string;
74
+ properties: {
75
+ workroom: {
76
+ type: string;
77
+ additionalProperties: boolean;
78
+ description: string;
79
+ "x-descriptionZh": string;
80
+ properties: {
81
+ trustedPackPublishers: {
82
+ type: string;
83
+ items: {
84
+ type: string;
85
+ minLength: number;
86
+ };
87
+ uniqueItems: boolean;
88
+ description: string;
89
+ "x-descriptionZh": string;
90
+ };
91
+ disclosure: {
92
+ type: string;
93
+ additionalProperties: boolean;
94
+ description: string;
95
+ "x-descriptionZh": string;
96
+ properties: {
97
+ tenantId: {
98
+ type: string;
99
+ minLength: number;
100
+ };
101
+ modelProviders: {
102
+ type: string;
103
+ additionalProperties: {
104
+ type: string;
105
+ additionalProperties: boolean;
106
+ required: string[];
107
+ properties: {
108
+ endpoint: {
109
+ type: string;
110
+ minLength: number;
111
+ };
112
+ owner: {
113
+ type: string;
114
+ minLength: number;
115
+ };
116
+ trustDomain: {
117
+ type: string;
118
+ minLength: number;
119
+ };
120
+ processingRegions: {
121
+ type: string;
122
+ minItems: number;
123
+ uniqueItems: boolean;
124
+ items: {
125
+ type: string;
126
+ minLength: number;
127
+ };
128
+ };
129
+ maxConfidentiality: {
130
+ type: string;
131
+ enum: string[];
132
+ };
133
+ external: {
134
+ type: string;
135
+ };
136
+ noTraining: {
137
+ type: string;
138
+ };
139
+ loggingMode: {
140
+ type: string;
141
+ enum: string[];
142
+ };
143
+ maximumRetentionSeconds: {
144
+ type: string;
145
+ minimum: number;
146
+ };
147
+ allowsRedisclosure: {
148
+ type: string;
149
+ };
150
+ supportsDeletion: {
151
+ type: string;
152
+ };
153
+ };
154
+ };
155
+ };
156
+ };
157
+ };
158
+ };
159
+ };
160
+ agent: {
161
+ type: string;
162
+ additionalProperties: boolean;
163
+ description: string;
164
+ "x-descriptionZh": string;
165
+ properties: {
166
+ inboundQueue: {
167
+ type: string;
168
+ additionalProperties: boolean;
169
+ description: string;
170
+ "x-descriptionZh": string;
171
+ properties: {
172
+ groupMode: {
173
+ type: string;
174
+ enum: string[];
175
+ description: string;
176
+ "x-descriptionZh": string;
177
+ };
178
+ };
179
+ };
180
+ execSecurity: {
181
+ type: string;
182
+ enum: string[];
183
+ description: string;
184
+ "x-descriptionZh": string;
185
+ };
186
+ execPreset: {
187
+ type: string;
188
+ enum: string[];
189
+ description: string;
190
+ "x-descriptionZh": string;
191
+ };
192
+ execApprovalMode: {
193
+ type: string;
194
+ enum: string[];
195
+ description: string;
196
+ "x-descriptionZh": string;
197
+ };
198
+ subagentExecApprovalMode: {
199
+ type: string;
200
+ enum: string[];
201
+ description: string;
202
+ "x-descriptionZh": string;
203
+ };
204
+ workerExecApprovalMode: {
205
+ type: string;
206
+ enum: string[];
207
+ description: string;
208
+ "x-descriptionZh": string;
209
+ };
210
+ taskExecApprovalMode: {
211
+ type: string;
212
+ enum: string[];
213
+ description: string;
214
+ "x-descriptionZh": string;
215
+ };
216
+ toolExecution: {
217
+ type: string;
218
+ enum: string[];
219
+ description: string;
220
+ "x-descriptionZh": string;
221
+ };
222
+ modelSizeHint: {
223
+ type: string;
224
+ enum: string[];
225
+ description: string;
226
+ "x-descriptionZh": string;
227
+ };
228
+ promptCacheRetention: {
229
+ type: string;
230
+ enum: string[];
231
+ description: string;
232
+ "x-descriptionZh": string;
233
+ };
234
+ steeringMode: {
235
+ type: string;
236
+ enum: string[];
237
+ description: string;
238
+ "x-descriptionZh": string;
239
+ };
240
+ followUpMode: {
241
+ type: string;
242
+ enum: string[];
243
+ description: string;
244
+ "x-descriptionZh": string;
245
+ };
246
+ outputSchema: {
247
+ anyOf: ({
248
+ type: string;
249
+ enum?: undefined;
250
+ } | {
251
+ type: string;
252
+ enum: string[];
253
+ })[];
254
+ description: string;
255
+ "x-descriptionZh": string;
256
+ };
257
+ schedule: {
258
+ type: string;
259
+ additionalProperties: boolean;
260
+ description: string;
261
+ "x-descriptionZh": string;
262
+ properties: {
263
+ security: {
264
+ type: string;
265
+ additionalProperties: boolean;
266
+ description: string;
267
+ "x-descriptionZh": string;
268
+ properties: {
269
+ execPreset: {
270
+ type: string;
271
+ enum: string[];
272
+ description: string;
273
+ "x-descriptionZh": string;
274
+ };
275
+ };
276
+ };
277
+ };
278
+ };
279
+ };
280
+ };
281
+ };
282
+ };
283
+ mcp: {
284
+ type: string;
285
+ additionalProperties: boolean;
286
+ description: string;
287
+ "x-descriptionZh": string;
288
+ };
289
+ a2a: {
290
+ type: string;
291
+ additionalProperties: boolean;
292
+ description: string;
293
+ "x-descriptionZh": string;
294
+ };
295
+ speech: {
296
+ type: string;
297
+ additionalProperties: boolean;
298
+ description: string;
299
+ "x-descriptionZh": string;
300
+ };
301
+ htmlRenderer: {
302
+ type: string;
303
+ additionalProperties: boolean;
304
+ description: string;
305
+ "x-descriptionZh": string;
306
+ properties: {
307
+ width: {
308
+ type: string;
309
+ minimum: number;
310
+ maximum: number;
311
+ description: string;
312
+ "x-descriptionZh": string;
313
+ };
314
+ defaultWidth: {
315
+ type: string;
316
+ minimum: number;
317
+ maximum: number;
318
+ description: string;
319
+ "x-descriptionZh": string;
320
+ };
321
+ viewport: {
322
+ type: string;
323
+ additionalProperties: boolean;
324
+ description: string;
325
+ "x-descriptionZh": string;
326
+ properties: {
327
+ width: {
328
+ type: string;
329
+ minimum: number;
330
+ maximum: number;
331
+ description: string;
332
+ "x-descriptionZh": string;
333
+ };
334
+ height: {
335
+ type: string;
336
+ minimum: number;
337
+ maximum: number;
338
+ description: string;
339
+ "x-descriptionZh": string;
340
+ };
341
+ };
342
+ };
343
+ backgroundColor: {
344
+ type: string;
345
+ description: string;
346
+ "x-descriptionZh": string;
347
+ };
348
+ defaultBackgroundColor: {
349
+ type: string;
350
+ description: string;
351
+ "x-descriptionZh": string;
352
+ };
353
+ scale: {
354
+ type: string;
355
+ minimum: number;
356
+ maximum: number;
357
+ description: string;
358
+ "x-descriptionZh": string;
359
+ };
360
+ type: {
361
+ type: string;
362
+ enum: string[];
363
+ description: string;
364
+ "x-descriptionZh": string;
365
+ };
366
+ quality: {
367
+ type: string;
368
+ minimum: number;
369
+ maximum: number;
370
+ description: string;
371
+ "x-descriptionZh": string;
372
+ };
373
+ timeout: {
374
+ type: string;
375
+ minimum: number;
376
+ maximum: number;
377
+ description: string;
378
+ "x-descriptionZh": string;
379
+ };
380
+ waitUntil: {
381
+ type: string;
382
+ enum: string[];
383
+ description: string;
384
+ "x-descriptionZh": string;
385
+ };
386
+ fontFamily: {
387
+ type: string;
388
+ description: string;
389
+ "x-descriptionZh": string;
390
+ };
391
+ maxImageHeight: {
392
+ type: string;
393
+ minimum: number;
394
+ maximum: number;
395
+ description: string;
396
+ "x-descriptionZh": string;
397
+ };
398
+ sliceCompression: {
399
+ type: string;
400
+ minimum: number;
401
+ maximum: number;
402
+ description: string;
403
+ "x-descriptionZh": string;
404
+ };
405
+ allowFileAccess: {
406
+ type: string;
407
+ description: string;
408
+ "x-descriptionZh": string;
409
+ };
410
+ takeOverHtmlSegments: {
411
+ type: string;
412
+ description: string;
413
+ "x-descriptionZh": string;
414
+ };
415
+ cacheDir: {
416
+ type: string;
417
+ description: string;
418
+ "x-descriptionZh": string;
419
+ };
420
+ cacheMaxBytes: {
421
+ type: string;
422
+ minimum: number;
423
+ description: string;
424
+ "x-descriptionZh": string;
425
+ };
426
+ userAgent: {
427
+ type: string;
428
+ description: string;
429
+ "x-descriptionZh": string;
430
+ };
431
+ idleTimeoutMs: {
432
+ type: string;
433
+ minimum: number;
434
+ maximum: number;
435
+ description: string;
436
+ "x-descriptionZh": string;
437
+ };
438
+ logStats: {
439
+ type: string;
440
+ description: string;
441
+ "x-descriptionZh": string;
442
+ };
443
+ mode: {
444
+ type: string;
445
+ enum: string[];
446
+ description: string;
447
+ "x-descriptionZh": string;
448
+ };
449
+ aiTextAsImage: {
450
+ anyOf: ({
451
+ type: string;
452
+ additionalProperties?: undefined;
453
+ description?: undefined;
454
+ "x-descriptionZh"?: undefined;
455
+ properties?: undefined;
456
+ } | {
457
+ type: string;
458
+ additionalProperties: boolean;
459
+ description: string;
460
+ "x-descriptionZh": string;
461
+ properties: {
462
+ enabled: {
463
+ type: string;
464
+ description: string;
465
+ "x-descriptionZh": string;
466
+ };
467
+ onlyAdapters: {
468
+ type: string;
469
+ items: {
470
+ type: string;
471
+ minLength: number;
472
+ };
473
+ uniqueItems: boolean;
474
+ description: string;
475
+ "x-descriptionZh": string;
476
+ };
477
+ minLength: {
478
+ type: string;
479
+ minimum: number;
480
+ description: string;
481
+ "x-descriptionZh": string;
482
+ };
483
+ maxLength: {
484
+ type: string;
485
+ minimum: number;
486
+ description: string;
487
+ "x-descriptionZh": string;
488
+ };
489
+ skipIfRich: {
490
+ type: string;
491
+ description: string;
492
+ "x-descriptionZh": string;
493
+ };
494
+ width: {
495
+ type: string;
496
+ minimum: number;
497
+ maximum: number;
498
+ description: string;
499
+ "x-descriptionZh": string;
500
+ };
501
+ height: {
502
+ type: string;
503
+ minimum: number;
504
+ maximum: number;
505
+ description: string;
506
+ "x-descriptionZh": string;
507
+ };
508
+ backgroundColor: {
509
+ type: string;
510
+ description: string;
511
+ "x-descriptionZh": string;
512
+ };
513
+ fontSize: {
514
+ type: string;
515
+ minimum: number;
516
+ description: string;
517
+ "x-descriptionZh": string;
518
+ };
519
+ color: {
520
+ type: string;
521
+ description: string;
522
+ "x-descriptionZh": string;
523
+ };
524
+ padding: {
525
+ type: string;
526
+ minimum: number;
527
+ description: string;
528
+ "x-descriptionZh": string;
529
+ };
530
+ scale: {
531
+ type: string;
532
+ minimum: number;
533
+ maximum: number;
534
+ description: string;
535
+ "x-descriptionZh": string;
536
+ };
537
+ fileName: {
538
+ type: string;
539
+ minLength: number;
540
+ description: string;
541
+ "x-descriptionZh": string;
542
+ };
543
+ };
544
+ })[];
545
+ description: string;
546
+ "x-descriptionZh": string;
547
+ };
548
+ };
549
+ };
550
+ assistant: {
551
+ type: string;
552
+ additionalProperties: boolean;
553
+ description: string;
554
+ "x-descriptionZh": string;
555
+ };
556
+ log_level: {
557
+ type: string[];
558
+ description: string;
559
+ "x-descriptionZh": string;
560
+ };
561
+ plugin: {
562
+ type: string;
563
+ description: string;
564
+ "x-descriptionZh": string;
565
+ };
566
+ };
567
+ };
4
568
  /** Host configuration keys consumed by Runtime composition and Host installers. */
5
569
  export declare const HOST_CONFIG_KEYS: readonly string[];
6
570
  export type JsonSchema = Readonly<Record<string, unknown>>;
@@ -10,7 +10,7 @@ function deepFreeze(value) {
10
10
  }
11
11
  return value;
12
12
  }
13
- const HOST_CONFIG_SCHEMA = deepFreeze(hostConfigSchema);
13
+ export const HOST_CONFIG_SCHEMA = deepFreeze(hostConfigSchema);
14
14
  /** Host configuration keys consumed by Runtime composition and Host installers. */
15
15
  export const HOST_CONFIG_KEYS = Object.freeze(Object.keys(HOST_CONFIG_SCHEMA.properties));
16
16
  export class ConfigSchemaCollisionError extends Error {
@@ -1,3 +1,4 @@
1
+ import { normalizeSourcePath } from './source-path.js';
1
2
  import { InvalidationPlanner, } from './invalidation-planner.js';
2
3
  export class HmrCoordinator {
3
4
  options;
@@ -21,7 +22,7 @@ export class HmrCoordinator {
21
22
  if (!this.options.modules.watch) {
22
23
  throw new Error('ModuleRuntime does not provide a file watcher');
23
24
  }
24
- this.#syncWatchRoots();
25
+ this.#syncModuleState();
25
26
  this.#unwatch = this.options.modules.watch((source) => {
26
27
  void this.enqueue(source).catch(() => undefined);
27
28
  });
@@ -31,11 +32,28 @@ export class HmrCoordinator {
31
32
  if (this.#stopResult)
32
33
  return this.#stopResult;
33
34
  this.#closing = true;
34
- this.#unwatch?.();
35
+ const unwatch = this.#unwatch;
35
36
  this.#unwatch = undefined;
36
- this.#stopResult = (async () => {
37
- await this.#draining;
38
- })();
37
+ this.#stopResult = Promise.resolve().then(async () => {
38
+ const errors = [];
39
+ try {
40
+ await unwatch?.();
41
+ }
42
+ catch (error) {
43
+ errors.push(error);
44
+ }
45
+ // Watcher disposal failure must not bypass already admitted reloads.
46
+ try {
47
+ await this.#draining;
48
+ }
49
+ catch (error) {
50
+ errors.push(error);
51
+ }
52
+ if (errors.length === 1)
53
+ throw errors[0];
54
+ if (errors.length > 1)
55
+ throw new AggregateError(errors, 'HMR stop failed');
56
+ });
39
57
  return this.#stopResult;
40
58
  }
41
59
  enqueue(source) {
@@ -45,7 +63,7 @@ export class HmrCoordinator {
45
63
  if (this.#restartRequired) {
46
64
  return Promise.reject(new Error('HMR coordinator requires a process restart'));
47
65
  }
48
- this.#pending.add(source);
66
+ this.#pending.add(normalizeSourcePath(source));
49
67
  const completed = new Promise((resolve, reject) => {
50
68
  this.#waiters.push({ resolve, reject });
51
69
  });
@@ -99,21 +117,23 @@ export class HmrCoordinator {
99
117
  if (plan.kind === 'none')
100
118
  continue;
101
119
  const startedAt = performance.now();
102
- for (const source of plan.changed) {
103
- await this.options.modules.invalidate?.(source);
104
- }
105
- const restart = await this.options.runtime.reload(plan);
106
- if (restart) {
107
- this.#restartRequired = true;
108
- this.#pending.clear();
109
- this.#notifyRestart(restart);
110
- break;
111
- }
112
- else {
120
+ try {
121
+ this.options.modules.beginGeneration?.();
122
+ for (const source of plan.changed) {
123
+ await this.options.modules.invalidate?.(source);
124
+ }
125
+ const restart = await this.options.runtime.reload(plan);
126
+ if (restart) {
127
+ this.options.modules.rollbackGeneration?.();
128
+ this.#restartRequired = true;
129
+ this.#pending.clear();
130
+ this.#notifyRestart(restart);
131
+ break;
132
+ }
113
133
  // reload resolves only after RootController has committed the new
114
- // generation. Read ownership now so failed transactions never make
115
- // newly discovered workspace packages observable to the watcher.
116
- this.#syncWatchRoots();
134
+ // generation. Commit module metadata and ownership together so a
135
+ // failed transaction keeps the previous dependency graph intact.
136
+ this.#syncModuleState();
117
137
  const durationMs = Number((performance.now() - startedAt).toFixed(1));
118
138
  try {
119
139
  await this.options.onReload?.(plan, durationMs);
@@ -128,6 +148,10 @@ export class HmrCoordinator {
128
148
  }
129
149
  }
130
150
  }
151
+ catch (error) {
152
+ this.options.modules.rollbackGeneration?.();
153
+ throw error;
154
+ }
131
155
  }
132
156
  this.#resolveWaiters();
133
157
  }
@@ -158,8 +182,10 @@ export class HmrCoordinator {
158
182
  for (const waiter of this.#waiters.splice(0))
159
183
  waiter.reject(error);
160
184
  }
161
- #syncWatchRoots() {
162
- this.options.modules.updateWatchRoots?.(this.options.ownership().watchRoots());
185
+ #syncModuleState() {
186
+ const ownership = this.options.ownership();
187
+ this.options.modules.updateWatchRoots?.(ownership.watchRoots());
188
+ this.options.modules.commitGeneration?.(ownership.moduleSources());
163
189
  }
164
190
  #notifyRestart(plan) {
165
191
  // Restart is a committed control outcome. Invoke the observer without