@claw-fact-bus/openclaw-plugin 1.0.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/dist/index.js ADDED
@@ -0,0 +1,3767 @@
1
+ import { __export } from './chunk-PR4QN5HX.js';
2
+ import { definePluginEntry } from 'openclaw/plugin-sdk/plugin-entry';
3
+
4
+ // src/api.ts
5
+ var FactBusClient = class {
6
+ baseUrl;
7
+ clawId = null;
8
+ token = null;
9
+ constructor(baseUrl) {
10
+ this.baseUrl = baseUrl.replace(/\/$/, "");
11
+ }
12
+ // ============ Connection Management ============
13
+ async connect(request) {
14
+ const response = await this.fetchJson("/claws/connect", {
15
+ method: "POST",
16
+ body: JSON.stringify({
17
+ name: request.name,
18
+ description: request.description || "",
19
+ capability_offer: request.capability_offer || [],
20
+ domain_interests: request.domain_interests || [],
21
+ fact_type_patterns: request.fact_type_patterns || [],
22
+ priority_range: request.priority_range || [0, 7],
23
+ modes: request.modes || ["exclusive", "broadcast"],
24
+ max_concurrent_claims: request.max_concurrent_claims || 1
25
+ })
26
+ });
27
+ if (response.success && response.data) {
28
+ this.clawId = response.data.claw_id;
29
+ this.token = response.data.token || null;
30
+ } else {
31
+ throw new Error(response.error || "Failed to connect to Fact Bus");
32
+ }
33
+ return response.data;
34
+ }
35
+ async heartbeat() {
36
+ if (!this.clawId) {
37
+ return { success: false, error: "Not connected" };
38
+ }
39
+ return this.fetchJson(`/claws/${this.clawId}/heartbeat`, {
40
+ method: "POST"
41
+ });
42
+ }
43
+ disconnect() {
44
+ this.clawId = null;
45
+ this.token = null;
46
+ }
47
+ get isConnected() {
48
+ return this.clawId !== null;
49
+ }
50
+ get currentClawId() {
51
+ return this.clawId;
52
+ }
53
+ get currentToken() {
54
+ return this.token;
55
+ }
56
+ // ============ Fact Operations ============
57
+ async publishFact(request) {
58
+ if (!this.clawId || !this.token) {
59
+ return { success: false, error: "Not connected to Fact Bus" };
60
+ }
61
+ const body = {
62
+ fact_type: request.fact_type,
63
+ semantic_kind: request.semantic_kind || "observation",
64
+ payload: request.payload || {},
65
+ domain_tags: request.domain_tags || [],
66
+ need_capabilities: request.need_capabilities || [],
67
+ priority: request.priority ?? 3,
68
+ mode: request.mode || "exclusive",
69
+ source_claw_id: this.clawId,
70
+ token: this.token,
71
+ ttl_seconds: request.ttl_seconds || 300,
72
+ schema_version: request.schema_version || "1.0.0",
73
+ confidence: request.confidence ?? 1,
74
+ causation_chain: request.causation_chain || [],
75
+ causation_depth: request.causation_depth || 0,
76
+ subject_key: request.subject_key || "",
77
+ supersedes: request.supersedes || ""
78
+ };
79
+ return this.fetchJson("/facts", {
80
+ method: "POST",
81
+ body: JSON.stringify(body)
82
+ });
83
+ }
84
+ async queryFacts(params = {}) {
85
+ const searchParams = new URLSearchParams();
86
+ if (params.fact_type) searchParams.set("fact_type", params.fact_type);
87
+ if (params.state) searchParams.set("state", params.state);
88
+ if (params.source_claw_id) searchParams.set("source_claw_id", params.source_claw_id);
89
+ if (params.limit) searchParams.set("limit", String(params.limit));
90
+ const query = searchParams.toString();
91
+ const path = query ? `/facts?${query}` : "/facts";
92
+ return this.fetchJson(path, {
93
+ method: "GET"
94
+ });
95
+ }
96
+ async getFact(factId) {
97
+ return this.fetchJson(`/facts/${factId}`, {
98
+ method: "GET"
99
+ });
100
+ }
101
+ async claimFact(factId) {
102
+ if (!this.clawId || !this.token) {
103
+ return { success: false, error: "Not connected to Fact Bus" };
104
+ }
105
+ const body = {
106
+ claw_id: this.clawId,
107
+ token: this.token
108
+ };
109
+ return this.fetchJson(`/facts/${factId}/claim`, {
110
+ method: "POST",
111
+ body: JSON.stringify(body)
112
+ });
113
+ }
114
+ async releaseFact(factId) {
115
+ if (!this.clawId || !this.token) {
116
+ return { success: false, error: "Not connected to Fact Bus" };
117
+ }
118
+ const body = {
119
+ claw_id: this.clawId,
120
+ token: this.token
121
+ };
122
+ return this.fetchJson(`/facts/${factId}/release`, {
123
+ method: "POST",
124
+ body: JSON.stringify(body)
125
+ });
126
+ }
127
+ async resolveFact(factId, resultFacts) {
128
+ if (!this.clawId || !this.token) {
129
+ return { success: false, error: "Not connected to Fact Bus" };
130
+ }
131
+ const body = {
132
+ claw_id: this.clawId,
133
+ token: this.token,
134
+ result_facts: resultFacts || []
135
+ };
136
+ return this.fetchJson(`/facts/${factId}/resolve`, {
137
+ method: "POST",
138
+ body: JSON.stringify(body)
139
+ });
140
+ }
141
+ async corroborateFact(factId) {
142
+ if (!this.clawId) {
143
+ return { success: false, error: "Not connected to Fact Bus" };
144
+ }
145
+ const body = {
146
+ claw_id: this.clawId
147
+ };
148
+ return this.fetchJson(`/facts/${factId}/corroborate`, {
149
+ method: "POST",
150
+ body: JSON.stringify(body)
151
+ });
152
+ }
153
+ async contradictFact(factId) {
154
+ if (!this.clawId) {
155
+ return { success: false, error: "Not connected to Fact Bus" };
156
+ }
157
+ const body = {
158
+ claw_id: this.clawId
159
+ };
160
+ return this.fetchJson(`/facts/${factId}/contradict`, {
161
+ method: "POST",
162
+ body: JSON.stringify(body)
163
+ });
164
+ }
165
+ // ============ Utility Methods ============
166
+ async listClaws() {
167
+ return this.fetchJson("/claws", {
168
+ method: "GET"
169
+ });
170
+ }
171
+ async getClawActivity(clawId, limit = 50) {
172
+ return this.fetchJson(`/claws/${clawId}/activity?limit=${limit}`, {
173
+ method: "GET"
174
+ });
175
+ }
176
+ async getStats() {
177
+ return this.fetchJson("/stats", {
178
+ method: "GET"
179
+ });
180
+ }
181
+ async healthCheck() {
182
+ try {
183
+ const response = await fetch(`${this.baseUrl}/health`);
184
+ return response.ok;
185
+ } catch {
186
+ return false;
187
+ }
188
+ }
189
+ getWebSocketUrl() {
190
+ const url = new URL(this.baseUrl);
191
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
192
+ const urlStr = url.toString();
193
+ return urlStr.endsWith("/") ? urlStr.slice(0, -1) : urlStr;
194
+ }
195
+ // ============ Schema Registry Methods ============
196
+ async listSchemas() {
197
+ return this.fetchJson("/schemas", {
198
+ method: "GET"
199
+ });
200
+ }
201
+ async getSchema(factType, version) {
202
+ const query = version ? `?version=${version}` : "";
203
+ return this.fetchJson(`/schemas/${factType}${query}`, {
204
+ method: "GET"
205
+ });
206
+ }
207
+ async validateSchema(factType, payload, version) {
208
+ const query = version ? `?version=${version}` : "";
209
+ return this.fetchJson(`/schemas/${factType}/validate${query}`, {
210
+ method: "POST",
211
+ body: JSON.stringify({ payload })
212
+ });
213
+ }
214
+ // ============ Private Helpers ============
215
+ async fetchJson(path, options = {}) {
216
+ try {
217
+ const response = await fetch(`${this.baseUrl}${path}`, {
218
+ ...options,
219
+ headers: {
220
+ "Content-Type": "application/json",
221
+ ...options.headers
222
+ }
223
+ });
224
+ if (!response.ok) {
225
+ const errorData = await response.json().catch(() => ({}));
226
+ return {
227
+ success: false,
228
+ error: errorData.error || `HTTP ${response.status}`
229
+ };
230
+ }
231
+ const data = await response.json();
232
+ return { success: true, data };
233
+ } catch (error) {
234
+ return {
235
+ success: false,
236
+ error: error instanceof Error ? error.message : "Unknown error"
237
+ };
238
+ }
239
+ }
240
+ };
241
+
242
+ // node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
243
+ var value_exports = {};
244
+ __export(value_exports, {
245
+ HasPropertyKey: () => HasPropertyKey,
246
+ IsArray: () => IsArray,
247
+ IsAsyncIterator: () => IsAsyncIterator,
248
+ IsBigInt: () => IsBigInt,
249
+ IsBoolean: () => IsBoolean,
250
+ IsDate: () => IsDate,
251
+ IsFunction: () => IsFunction,
252
+ IsIterator: () => IsIterator,
253
+ IsNull: () => IsNull,
254
+ IsNumber: () => IsNumber,
255
+ IsObject: () => IsObject,
256
+ IsRegExp: () => IsRegExp,
257
+ IsString: () => IsString,
258
+ IsSymbol: () => IsSymbol,
259
+ IsUint8Array: () => IsUint8Array,
260
+ IsUndefined: () => IsUndefined
261
+ });
262
+ function HasPropertyKey(value, key) {
263
+ return key in value;
264
+ }
265
+ function IsAsyncIterator(value) {
266
+ return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
267
+ }
268
+ function IsArray(value) {
269
+ return Array.isArray(value);
270
+ }
271
+ function IsBigInt(value) {
272
+ return typeof value === "bigint";
273
+ }
274
+ function IsBoolean(value) {
275
+ return typeof value === "boolean";
276
+ }
277
+ function IsDate(value) {
278
+ return value instanceof globalThis.Date;
279
+ }
280
+ function IsFunction(value) {
281
+ return typeof value === "function";
282
+ }
283
+ function IsIterator(value) {
284
+ return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.iterator in value;
285
+ }
286
+ function IsNull(value) {
287
+ return value === null;
288
+ }
289
+ function IsNumber(value) {
290
+ return typeof value === "number";
291
+ }
292
+ function IsObject(value) {
293
+ return typeof value === "object" && value !== null;
294
+ }
295
+ function IsRegExp(value) {
296
+ return value instanceof globalThis.RegExp;
297
+ }
298
+ function IsString(value) {
299
+ return typeof value === "string";
300
+ }
301
+ function IsSymbol(value) {
302
+ return typeof value === "symbol";
303
+ }
304
+ function IsUint8Array(value) {
305
+ return value instanceof globalThis.Uint8Array;
306
+ }
307
+ function IsUndefined(value) {
308
+ return value === void 0;
309
+ }
310
+
311
+ // node_modules/@sinclair/typebox/build/esm/type/clone/value.mjs
312
+ function ArrayType(value) {
313
+ return value.map((value2) => Visit(value2));
314
+ }
315
+ function DateType(value) {
316
+ return new Date(value.getTime());
317
+ }
318
+ function Uint8ArrayType(value) {
319
+ return new Uint8Array(value);
320
+ }
321
+ function RegExpType(value) {
322
+ return new RegExp(value.source, value.flags);
323
+ }
324
+ function ObjectType(value) {
325
+ const result = {};
326
+ for (const key of Object.getOwnPropertyNames(value)) {
327
+ result[key] = Visit(value[key]);
328
+ }
329
+ for (const key of Object.getOwnPropertySymbols(value)) {
330
+ result[key] = Visit(value[key]);
331
+ }
332
+ return result;
333
+ }
334
+ function Visit(value) {
335
+ return IsArray(value) ? ArrayType(value) : IsDate(value) ? DateType(value) : IsUint8Array(value) ? Uint8ArrayType(value) : IsRegExp(value) ? RegExpType(value) : IsObject(value) ? ObjectType(value) : value;
336
+ }
337
+ function Clone(value) {
338
+ return Visit(value);
339
+ }
340
+
341
+ // node_modules/@sinclair/typebox/build/esm/type/clone/type.mjs
342
+ function CloneType(schema, options) {
343
+ return Clone(schema) ;
344
+ }
345
+
346
+ // node_modules/@sinclair/typebox/build/esm/value/guard/guard.mjs
347
+ function IsObject2(value) {
348
+ return value !== null && typeof value === "object";
349
+ }
350
+ function IsArray2(value) {
351
+ return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value);
352
+ }
353
+ function IsUndefined2(value) {
354
+ return value === void 0;
355
+ }
356
+ function IsNumber2(value) {
357
+ return typeof value === "number";
358
+ }
359
+
360
+ // node_modules/@sinclair/typebox/build/esm/system/policy.mjs
361
+ var TypeSystemPolicy;
362
+ (function(TypeSystemPolicy2) {
363
+ TypeSystemPolicy2.InstanceMode = "default";
364
+ TypeSystemPolicy2.ExactOptionalPropertyTypes = false;
365
+ TypeSystemPolicy2.AllowArrayObject = false;
366
+ TypeSystemPolicy2.AllowNaN = false;
367
+ TypeSystemPolicy2.AllowNullVoid = false;
368
+ function IsExactOptionalProperty(value, key) {
369
+ return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== void 0;
370
+ }
371
+ TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty;
372
+ function IsObjectLike(value) {
373
+ const isObject = IsObject2(value);
374
+ return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !IsArray2(value);
375
+ }
376
+ TypeSystemPolicy2.IsObjectLike = IsObjectLike;
377
+ function IsRecordLike(value) {
378
+ return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
379
+ }
380
+ TypeSystemPolicy2.IsRecordLike = IsRecordLike;
381
+ function IsNumberLike(value) {
382
+ return TypeSystemPolicy2.AllowNaN ? IsNumber2(value) : Number.isFinite(value);
383
+ }
384
+ TypeSystemPolicy2.IsNumberLike = IsNumberLike;
385
+ function IsVoidLike(value) {
386
+ const isUndefined = IsUndefined2(value);
387
+ return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined;
388
+ }
389
+ TypeSystemPolicy2.IsVoidLike = IsVoidLike;
390
+ })(TypeSystemPolicy || (TypeSystemPolicy = {}));
391
+
392
+ // node_modules/@sinclair/typebox/build/esm/type/create/immutable.mjs
393
+ function ImmutableArray(value) {
394
+ return globalThis.Object.freeze(value).map((value2) => Immutable(value2));
395
+ }
396
+ function ImmutableDate(value) {
397
+ return value;
398
+ }
399
+ function ImmutableUint8Array(value) {
400
+ return value;
401
+ }
402
+ function ImmutableRegExp(value) {
403
+ return value;
404
+ }
405
+ function ImmutableObject(value) {
406
+ const result = {};
407
+ for (const key of Object.getOwnPropertyNames(value)) {
408
+ result[key] = Immutable(value[key]);
409
+ }
410
+ for (const key of Object.getOwnPropertySymbols(value)) {
411
+ result[key] = Immutable(value[key]);
412
+ }
413
+ return globalThis.Object.freeze(result);
414
+ }
415
+ function Immutable(value) {
416
+ return IsArray(value) ? ImmutableArray(value) : IsDate(value) ? ImmutableDate(value) : IsUint8Array(value) ? ImmutableUint8Array(value) : IsRegExp(value) ? ImmutableRegExp(value) : IsObject(value) ? ImmutableObject(value) : value;
417
+ }
418
+
419
+ // node_modules/@sinclair/typebox/build/esm/type/create/type.mjs
420
+ function CreateType(schema, options) {
421
+ const result = options !== void 0 ? { ...options, ...schema } : schema;
422
+ switch (TypeSystemPolicy.InstanceMode) {
423
+ case "freeze":
424
+ return Immutable(result);
425
+ case "clone":
426
+ return Clone(result);
427
+ default:
428
+ return result;
429
+ }
430
+ }
431
+
432
+ // node_modules/@sinclair/typebox/build/esm/type/error/error.mjs
433
+ var TypeBoxError = class extends Error {
434
+ constructor(message) {
435
+ super(message);
436
+ }
437
+ };
438
+
439
+ // node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
440
+ var TransformKind = /* @__PURE__ */ Symbol.for("TypeBox.Transform");
441
+ var ReadonlyKind = /* @__PURE__ */ Symbol.for("TypeBox.Readonly");
442
+ var OptionalKind = /* @__PURE__ */ Symbol.for("TypeBox.Optional");
443
+ var Hint = /* @__PURE__ */ Symbol.for("TypeBox.Hint");
444
+ var Kind = /* @__PURE__ */ Symbol.for("TypeBox.Kind");
445
+
446
+ // node_modules/@sinclair/typebox/build/esm/type/guard/kind.mjs
447
+ function IsReadonly(value) {
448
+ return IsObject(value) && value[ReadonlyKind] === "Readonly";
449
+ }
450
+ function IsOptional(value) {
451
+ return IsObject(value) && value[OptionalKind] === "Optional";
452
+ }
453
+ function IsAny(value) {
454
+ return IsKindOf(value, "Any");
455
+ }
456
+ function IsArgument(value) {
457
+ return IsKindOf(value, "Argument");
458
+ }
459
+ function IsArray3(value) {
460
+ return IsKindOf(value, "Array");
461
+ }
462
+ function IsAsyncIterator2(value) {
463
+ return IsKindOf(value, "AsyncIterator");
464
+ }
465
+ function IsBigInt2(value) {
466
+ return IsKindOf(value, "BigInt");
467
+ }
468
+ function IsBoolean2(value) {
469
+ return IsKindOf(value, "Boolean");
470
+ }
471
+ function IsComputed(value) {
472
+ return IsKindOf(value, "Computed");
473
+ }
474
+ function IsConstructor(value) {
475
+ return IsKindOf(value, "Constructor");
476
+ }
477
+ function IsDate2(value) {
478
+ return IsKindOf(value, "Date");
479
+ }
480
+ function IsFunction2(value) {
481
+ return IsKindOf(value, "Function");
482
+ }
483
+ function IsInteger(value) {
484
+ return IsKindOf(value, "Integer");
485
+ }
486
+ function IsIntersect(value) {
487
+ return IsKindOf(value, "Intersect");
488
+ }
489
+ function IsIterator2(value) {
490
+ return IsKindOf(value, "Iterator");
491
+ }
492
+ function IsKindOf(value, kind) {
493
+ return IsObject(value) && Kind in value && value[Kind] === kind;
494
+ }
495
+ function IsLiteralValue(value) {
496
+ return IsBoolean(value) || IsNumber(value) || IsString(value);
497
+ }
498
+ function IsLiteral(value) {
499
+ return IsKindOf(value, "Literal");
500
+ }
501
+ function IsMappedKey(value) {
502
+ return IsKindOf(value, "MappedKey");
503
+ }
504
+ function IsMappedResult(value) {
505
+ return IsKindOf(value, "MappedResult");
506
+ }
507
+ function IsNever(value) {
508
+ return IsKindOf(value, "Never");
509
+ }
510
+ function IsNot(value) {
511
+ return IsKindOf(value, "Not");
512
+ }
513
+ function IsNull2(value) {
514
+ return IsKindOf(value, "Null");
515
+ }
516
+ function IsNumber3(value) {
517
+ return IsKindOf(value, "Number");
518
+ }
519
+ function IsObject3(value) {
520
+ return IsKindOf(value, "Object");
521
+ }
522
+ function IsPromise(value) {
523
+ return IsKindOf(value, "Promise");
524
+ }
525
+ function IsRecord(value) {
526
+ return IsKindOf(value, "Record");
527
+ }
528
+ function IsRef(value) {
529
+ return IsKindOf(value, "Ref");
530
+ }
531
+ function IsRegExp2(value) {
532
+ return IsKindOf(value, "RegExp");
533
+ }
534
+ function IsString2(value) {
535
+ return IsKindOf(value, "String");
536
+ }
537
+ function IsSymbol2(value) {
538
+ return IsKindOf(value, "Symbol");
539
+ }
540
+ function IsTemplateLiteral(value) {
541
+ return IsKindOf(value, "TemplateLiteral");
542
+ }
543
+ function IsThis(value) {
544
+ return IsKindOf(value, "This");
545
+ }
546
+ function IsTransform(value) {
547
+ return IsObject(value) && TransformKind in value;
548
+ }
549
+ function IsTuple(value) {
550
+ return IsKindOf(value, "Tuple");
551
+ }
552
+ function IsUndefined3(value) {
553
+ return IsKindOf(value, "Undefined");
554
+ }
555
+ function IsUnion(value) {
556
+ return IsKindOf(value, "Union");
557
+ }
558
+ function IsUint8Array2(value) {
559
+ return IsKindOf(value, "Uint8Array");
560
+ }
561
+ function IsUnknown(value) {
562
+ return IsKindOf(value, "Unknown");
563
+ }
564
+ function IsUnsafe(value) {
565
+ return IsKindOf(value, "Unsafe");
566
+ }
567
+ function IsVoid(value) {
568
+ return IsKindOf(value, "Void");
569
+ }
570
+ function IsKind(value) {
571
+ return IsObject(value) && Kind in value && IsString(value[Kind]);
572
+ }
573
+ function IsSchema(value) {
574
+ return IsAny(value) || IsArgument(value) || IsArray3(value) || IsBoolean2(value) || IsBigInt2(value) || IsAsyncIterator2(value) || IsComputed(value) || IsConstructor(value) || IsDate2(value) || IsFunction2(value) || IsInteger(value) || IsIntersect(value) || IsIterator2(value) || IsLiteral(value) || IsMappedKey(value) || IsMappedResult(value) || IsNever(value) || IsNot(value) || IsNull2(value) || IsNumber3(value) || IsObject3(value) || IsPromise(value) || IsRecord(value) || IsRef(value) || IsRegExp2(value) || IsString2(value) || IsSymbol2(value) || IsTemplateLiteral(value) || IsThis(value) || IsTuple(value) || IsUndefined3(value) || IsUnion(value) || IsUint8Array2(value) || IsUnknown(value) || IsUnsafe(value) || IsVoid(value) || IsKind(value);
575
+ }
576
+
577
+ // node_modules/@sinclair/typebox/build/esm/type/guard/type.mjs
578
+ var type_exports = {};
579
+ __export(type_exports, {
580
+ IsAny: () => IsAny2,
581
+ IsArgument: () => IsArgument2,
582
+ IsArray: () => IsArray4,
583
+ IsAsyncIterator: () => IsAsyncIterator3,
584
+ IsBigInt: () => IsBigInt3,
585
+ IsBoolean: () => IsBoolean3,
586
+ IsComputed: () => IsComputed2,
587
+ IsConstructor: () => IsConstructor2,
588
+ IsDate: () => IsDate3,
589
+ IsFunction: () => IsFunction3,
590
+ IsImport: () => IsImport,
591
+ IsInteger: () => IsInteger2,
592
+ IsIntersect: () => IsIntersect2,
593
+ IsIterator: () => IsIterator3,
594
+ IsKind: () => IsKind2,
595
+ IsKindOf: () => IsKindOf2,
596
+ IsLiteral: () => IsLiteral2,
597
+ IsLiteralBoolean: () => IsLiteralBoolean,
598
+ IsLiteralNumber: () => IsLiteralNumber,
599
+ IsLiteralString: () => IsLiteralString,
600
+ IsLiteralValue: () => IsLiteralValue2,
601
+ IsMappedKey: () => IsMappedKey2,
602
+ IsMappedResult: () => IsMappedResult2,
603
+ IsNever: () => IsNever2,
604
+ IsNot: () => IsNot2,
605
+ IsNull: () => IsNull3,
606
+ IsNumber: () => IsNumber4,
607
+ IsObject: () => IsObject4,
608
+ IsOptional: () => IsOptional2,
609
+ IsPromise: () => IsPromise2,
610
+ IsProperties: () => IsProperties,
611
+ IsReadonly: () => IsReadonly2,
612
+ IsRecord: () => IsRecord2,
613
+ IsRecursive: () => IsRecursive,
614
+ IsRef: () => IsRef2,
615
+ IsRegExp: () => IsRegExp3,
616
+ IsSchema: () => IsSchema2,
617
+ IsString: () => IsString3,
618
+ IsSymbol: () => IsSymbol3,
619
+ IsTemplateLiteral: () => IsTemplateLiteral2,
620
+ IsThis: () => IsThis2,
621
+ IsTransform: () => IsTransform2,
622
+ IsTuple: () => IsTuple2,
623
+ IsUint8Array: () => IsUint8Array3,
624
+ IsUndefined: () => IsUndefined4,
625
+ IsUnion: () => IsUnion2,
626
+ IsUnionLiteral: () => IsUnionLiteral,
627
+ IsUnknown: () => IsUnknown2,
628
+ IsUnsafe: () => IsUnsafe2,
629
+ IsVoid: () => IsVoid2,
630
+ TypeGuardUnknownTypeError: () => TypeGuardUnknownTypeError
631
+ });
632
+ var TypeGuardUnknownTypeError = class extends TypeBoxError {
633
+ };
634
+ var KnownTypes = [
635
+ "Argument",
636
+ "Any",
637
+ "Array",
638
+ "AsyncIterator",
639
+ "BigInt",
640
+ "Boolean",
641
+ "Computed",
642
+ "Constructor",
643
+ "Date",
644
+ "Enum",
645
+ "Function",
646
+ "Integer",
647
+ "Intersect",
648
+ "Iterator",
649
+ "Literal",
650
+ "MappedKey",
651
+ "MappedResult",
652
+ "Not",
653
+ "Null",
654
+ "Number",
655
+ "Object",
656
+ "Promise",
657
+ "Record",
658
+ "Ref",
659
+ "RegExp",
660
+ "String",
661
+ "Symbol",
662
+ "TemplateLiteral",
663
+ "This",
664
+ "Tuple",
665
+ "Undefined",
666
+ "Union",
667
+ "Uint8Array",
668
+ "Unknown",
669
+ "Void"
670
+ ];
671
+ function IsPattern(value) {
672
+ try {
673
+ new RegExp(value);
674
+ return true;
675
+ } catch {
676
+ return false;
677
+ }
678
+ }
679
+ function IsControlCharacterFree(value) {
680
+ if (!IsString(value))
681
+ return false;
682
+ for (let i = 0; i < value.length; i++) {
683
+ const code = value.charCodeAt(i);
684
+ if (code >= 7 && code <= 13 || code === 27 || code === 127) {
685
+ return false;
686
+ }
687
+ }
688
+ return true;
689
+ }
690
+ function IsAdditionalProperties(value) {
691
+ return IsOptionalBoolean(value) || IsSchema2(value);
692
+ }
693
+ function IsOptionalBigInt(value) {
694
+ return IsUndefined(value) || IsBigInt(value);
695
+ }
696
+ function IsOptionalNumber(value) {
697
+ return IsUndefined(value) || IsNumber(value);
698
+ }
699
+ function IsOptionalBoolean(value) {
700
+ return IsUndefined(value) || IsBoolean(value);
701
+ }
702
+ function IsOptionalString(value) {
703
+ return IsUndefined(value) || IsString(value);
704
+ }
705
+ function IsOptionalPattern(value) {
706
+ return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
707
+ }
708
+ function IsOptionalFormat(value) {
709
+ return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value);
710
+ }
711
+ function IsOptionalSchema(value) {
712
+ return IsUndefined(value) || IsSchema2(value);
713
+ }
714
+ function IsReadonly2(value) {
715
+ return IsObject(value) && value[ReadonlyKind] === "Readonly";
716
+ }
717
+ function IsOptional2(value) {
718
+ return IsObject(value) && value[OptionalKind] === "Optional";
719
+ }
720
+ function IsAny2(value) {
721
+ return IsKindOf2(value, "Any") && IsOptionalString(value.$id);
722
+ }
723
+ function IsArgument2(value) {
724
+ return IsKindOf2(value, "Argument") && IsNumber(value.index);
725
+ }
726
+ function IsArray4(value) {
727
+ return IsKindOf2(value, "Array") && value.type === "array" && IsOptionalString(value.$id) && IsSchema2(value.items) && IsOptionalNumber(value.minItems) && IsOptionalNumber(value.maxItems) && IsOptionalBoolean(value.uniqueItems) && IsOptionalSchema(value.contains) && IsOptionalNumber(value.minContains) && IsOptionalNumber(value.maxContains);
728
+ }
729
+ function IsAsyncIterator3(value) {
730
+ return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
731
+ }
732
+ function IsBigInt3(value) {
733
+ return IsKindOf2(value, "BigInt") && value.type === "bigint" && IsOptionalString(value.$id) && IsOptionalBigInt(value.exclusiveMaximum) && IsOptionalBigInt(value.exclusiveMinimum) && IsOptionalBigInt(value.maximum) && IsOptionalBigInt(value.minimum) && IsOptionalBigInt(value.multipleOf);
734
+ }
735
+ function IsBoolean3(value) {
736
+ return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id);
737
+ }
738
+ function IsComputed2(value) {
739
+ return IsKindOf2(value, "Computed") && IsString(value.target) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema));
740
+ }
741
+ function IsConstructor2(value) {
742
+ return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
743
+ }
744
+ function IsDate3(value) {
745
+ return IsKindOf2(value, "Date") && value.type === "Date" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximumTimestamp) && IsOptionalNumber(value.exclusiveMinimumTimestamp) && IsOptionalNumber(value.maximumTimestamp) && IsOptionalNumber(value.minimumTimestamp) && IsOptionalNumber(value.multipleOfTimestamp);
746
+ }
747
+ function IsFunction3(value) {
748
+ return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
749
+ }
750
+ function IsImport(value) {
751
+ return IsKindOf2(value, "Import") && HasPropertyKey(value, "$defs") && IsObject(value.$defs) && IsProperties(value.$defs) && HasPropertyKey(value, "$ref") && IsString(value.$ref) && value.$ref in value.$defs;
752
+ }
753
+ function IsInteger2(value) {
754
+ return IsKindOf2(value, "Integer") && value.type === "integer" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
755
+ }
756
+ function IsProperties(value) {
757
+ return IsObject(value) && Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema2(schema));
758
+ }
759
+ function IsIntersect2(value) {
760
+ return IsKindOf2(value, "Intersect") && (IsString(value.type) && value.type !== "object" ? false : true) && IsArray(value.allOf) && value.allOf.every((schema) => IsSchema2(schema) && !IsTransform2(schema)) && IsOptionalString(value.type) && (IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) && IsOptionalString(value.$id);
761
+ }
762
+ function IsIterator3(value) {
763
+ return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
764
+ }
765
+ function IsKindOf2(value, kind) {
766
+ return IsObject(value) && Kind in value && value[Kind] === kind;
767
+ }
768
+ function IsLiteralString(value) {
769
+ return IsLiteral2(value) && IsString(value.const);
770
+ }
771
+ function IsLiteralNumber(value) {
772
+ return IsLiteral2(value) && IsNumber(value.const);
773
+ }
774
+ function IsLiteralBoolean(value) {
775
+ return IsLiteral2(value) && IsBoolean(value.const);
776
+ }
777
+ function IsLiteral2(value) {
778
+ return IsKindOf2(value, "Literal") && IsOptionalString(value.$id) && IsLiteralValue2(value.const);
779
+ }
780
+ function IsLiteralValue2(value) {
781
+ return IsBoolean(value) || IsNumber(value) || IsString(value);
782
+ }
783
+ function IsMappedKey2(value) {
784
+ return IsKindOf2(value, "MappedKey") && IsArray(value.keys) && value.keys.every((key) => IsNumber(key) || IsString(key));
785
+ }
786
+ function IsMappedResult2(value) {
787
+ return IsKindOf2(value, "MappedResult") && IsProperties(value.properties);
788
+ }
789
+ function IsNever2(value) {
790
+ return IsKindOf2(value, "Never") && IsObject(value.not) && Object.getOwnPropertyNames(value.not).length === 0;
791
+ }
792
+ function IsNot2(value) {
793
+ return IsKindOf2(value, "Not") && IsSchema2(value.not);
794
+ }
795
+ function IsNull3(value) {
796
+ return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id);
797
+ }
798
+ function IsNumber4(value) {
799
+ return IsKindOf2(value, "Number") && value.type === "number" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
800
+ }
801
+ function IsObject4(value) {
802
+ return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties);
803
+ }
804
+ function IsPromise2(value) {
805
+ return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item);
806
+ }
807
+ function IsRecord2(value) {
808
+ return IsKindOf2(value, "Record") && value.type === "object" && IsOptionalString(value.$id) && IsAdditionalProperties(value.additionalProperties) && IsObject(value.patternProperties) && ((schema) => {
809
+ const keys = Object.getOwnPropertyNames(schema.patternProperties);
810
+ return keys.length === 1 && IsPattern(keys[0]) && IsObject(schema.patternProperties) && IsSchema2(schema.patternProperties[keys[0]]);
811
+ })(value);
812
+ }
813
+ function IsRecursive(value) {
814
+ return IsObject(value) && Hint in value && value[Hint] === "Recursive";
815
+ }
816
+ function IsRef2(value) {
817
+ return IsKindOf2(value, "Ref") && IsOptionalString(value.$id) && IsString(value.$ref);
818
+ }
819
+ function IsRegExp3(value) {
820
+ return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength);
821
+ }
822
+ function IsString3(value) {
823
+ return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format);
824
+ }
825
+ function IsSymbol3(value) {
826
+ return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id);
827
+ }
828
+ function IsTemplateLiteral2(value) {
829
+ return IsKindOf2(value, "TemplateLiteral") && value.type === "string" && IsString(value.pattern) && value.pattern[0] === "^" && value.pattern[value.pattern.length - 1] === "$";
830
+ }
831
+ function IsThis2(value) {
832
+ return IsKindOf2(value, "This") && IsOptionalString(value.$id) && IsString(value.$ref);
833
+ }
834
+ function IsTransform2(value) {
835
+ return IsObject(value) && TransformKind in value;
836
+ }
837
+ function IsTuple2(value) {
838
+ return IsKindOf2(value, "Tuple") && value.type === "array" && IsOptionalString(value.$id) && IsNumber(value.minItems) && IsNumber(value.maxItems) && value.minItems === value.maxItems && // empty
839
+ (IsUndefined(value.items) && IsUndefined(value.additionalItems) && value.minItems === 0 || IsArray(value.items) && value.items.every((schema) => IsSchema2(schema)));
840
+ }
841
+ function IsUndefined4(value) {
842
+ return IsKindOf2(value, "Undefined") && value.type === "undefined" && IsOptionalString(value.$id);
843
+ }
844
+ function IsUnionLiteral(value) {
845
+ return IsUnion2(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema));
846
+ }
847
+ function IsUnion2(value) {
848
+ return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema));
849
+ }
850
+ function IsUint8Array3(value) {
851
+ return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength);
852
+ }
853
+ function IsUnknown2(value) {
854
+ return IsKindOf2(value, "Unknown") && IsOptionalString(value.$id);
855
+ }
856
+ function IsUnsafe2(value) {
857
+ return IsKindOf2(value, "Unsafe");
858
+ }
859
+ function IsVoid2(value) {
860
+ return IsKindOf2(value, "Void") && value.type === "void" && IsOptionalString(value.$id);
861
+ }
862
+ function IsKind2(value) {
863
+ return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
864
+ }
865
+ function IsSchema2(value) {
866
+ return IsObject(value) && (IsAny2(value) || IsArgument2(value) || IsArray4(value) || IsBoolean3(value) || IsBigInt3(value) || IsAsyncIterator3(value) || IsComputed2(value) || IsConstructor2(value) || IsDate3(value) || IsFunction3(value) || IsInteger2(value) || IsIntersect2(value) || IsIterator3(value) || IsLiteral2(value) || IsMappedKey2(value) || IsMappedResult2(value) || IsNever2(value) || IsNot2(value) || IsNull3(value) || IsNumber4(value) || IsObject4(value) || IsPromise2(value) || IsRecord2(value) || IsRef2(value) || IsRegExp3(value) || IsString3(value) || IsSymbol3(value) || IsTemplateLiteral2(value) || IsThis2(value) || IsTuple2(value) || IsUndefined4(value) || IsUnion2(value) || IsUint8Array3(value) || IsUnknown2(value) || IsUnsafe2(value) || IsVoid2(value) || IsKind2(value));
867
+ }
868
+
869
+ // node_modules/@sinclair/typebox/build/esm/type/patterns/patterns.mjs
870
+ var PatternBoolean = "(true|false)";
871
+ var PatternNumber = "(0|[1-9][0-9]*)";
872
+ var PatternString = "(.*)";
873
+ var PatternNever = "(?!.*)";
874
+ var PatternNumberExact = `^${PatternNumber}$`;
875
+ var PatternStringExact = `^${PatternString}$`;
876
+ var PatternNeverExact = `^${PatternNever}$`;
877
+
878
+ // node_modules/@sinclair/typebox/build/esm/type/sets/set.mjs
879
+ function SetIncludes(T, S) {
880
+ return T.includes(S);
881
+ }
882
+ function SetDistinct(T) {
883
+ return [...new Set(T)];
884
+ }
885
+ function SetIntersect(T, S) {
886
+ return T.filter((L) => S.includes(L));
887
+ }
888
+ function SetIntersectManyResolve(T, Init) {
889
+ return T.reduce((Acc, L) => {
890
+ return SetIntersect(Acc, L);
891
+ }, Init);
892
+ }
893
+ function SetIntersectMany(T) {
894
+ return T.length === 1 ? T[0] : T.length > 1 ? SetIntersectManyResolve(T.slice(1), T[0]) : [];
895
+ }
896
+ function SetUnionMany(T) {
897
+ const Acc = [];
898
+ for (const L of T)
899
+ Acc.push(...L);
900
+ return Acc;
901
+ }
902
+
903
+ // node_modules/@sinclair/typebox/build/esm/type/any/any.mjs
904
+ function Any(options) {
905
+ return CreateType({ [Kind]: "Any" }, options);
906
+ }
907
+
908
+ // node_modules/@sinclair/typebox/build/esm/type/array/array.mjs
909
+ function Array2(items, options) {
910
+ return CreateType({ [Kind]: "Array", type: "array", items }, options);
911
+ }
912
+
913
+ // node_modules/@sinclair/typebox/build/esm/type/argument/argument.mjs
914
+ function Argument(index) {
915
+ return CreateType({ [Kind]: "Argument", index });
916
+ }
917
+
918
+ // node_modules/@sinclair/typebox/build/esm/type/async-iterator/async-iterator.mjs
919
+ function AsyncIterator(items, options) {
920
+ return CreateType({ [Kind]: "AsyncIterator", type: "AsyncIterator", items }, options);
921
+ }
922
+
923
+ // node_modules/@sinclair/typebox/build/esm/type/computed/computed.mjs
924
+ function Computed(target, parameters, options) {
925
+ return CreateType({ [Kind]: "Computed", target, parameters }, options);
926
+ }
927
+
928
+ // node_modules/@sinclair/typebox/build/esm/type/discard/discard.mjs
929
+ function DiscardKey(value, key) {
930
+ const { [key]: _, ...rest } = value;
931
+ return rest;
932
+ }
933
+ function Discard(value, keys) {
934
+ return keys.reduce((acc, key) => DiscardKey(acc, key), value);
935
+ }
936
+
937
+ // node_modules/@sinclair/typebox/build/esm/type/never/never.mjs
938
+ function Never(options) {
939
+ return CreateType({ [Kind]: "Never", not: {} }, options);
940
+ }
941
+
942
+ // node_modules/@sinclair/typebox/build/esm/type/mapped/mapped-result.mjs
943
+ function MappedResult(properties) {
944
+ return CreateType({
945
+ [Kind]: "MappedResult",
946
+ properties
947
+ });
948
+ }
949
+
950
+ // node_modules/@sinclair/typebox/build/esm/type/constructor/constructor.mjs
951
+ function Constructor(parameters, returns, options) {
952
+ return CreateType({ [Kind]: "Constructor", type: "Constructor", parameters, returns }, options);
953
+ }
954
+
955
+ // node_modules/@sinclair/typebox/build/esm/type/function/function.mjs
956
+ function Function(parameters, returns, options) {
957
+ return CreateType({ [Kind]: "Function", type: "Function", parameters, returns }, options);
958
+ }
959
+
960
+ // node_modules/@sinclair/typebox/build/esm/type/union/union-create.mjs
961
+ function UnionCreate(T, options) {
962
+ return CreateType({ [Kind]: "Union", anyOf: T }, options);
963
+ }
964
+
965
+ // node_modules/@sinclair/typebox/build/esm/type/union/union-evaluated.mjs
966
+ function IsUnionOptional(types) {
967
+ return types.some((type) => IsOptional(type));
968
+ }
969
+ function RemoveOptionalFromRest(types) {
970
+ return types.map((left) => IsOptional(left) ? RemoveOptionalFromType(left) : left);
971
+ }
972
+ function RemoveOptionalFromType(T) {
973
+ return Discard(T, [OptionalKind]);
974
+ }
975
+ function ResolveUnion(types, options) {
976
+ const isOptional = IsUnionOptional(types);
977
+ return isOptional ? Optional(UnionCreate(RemoveOptionalFromRest(types), options)) : UnionCreate(RemoveOptionalFromRest(types), options);
978
+ }
979
+ function UnionEvaluated(T, options) {
980
+ return T.length === 1 ? CreateType(T[0], options) : T.length === 0 ? Never(options) : ResolveUnion(T, options);
981
+ }
982
+
983
+ // node_modules/@sinclair/typebox/build/esm/type/union/union.mjs
984
+ function Union(types, options) {
985
+ return types.length === 0 ? Never(options) : types.length === 1 ? CreateType(types[0], options) : UnionCreate(types, options);
986
+ }
987
+
988
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/parse.mjs
989
+ var TemplateLiteralParserError = class extends TypeBoxError {
990
+ };
991
+ function Unescape(pattern) {
992
+ return pattern.replace(/\\\$/g, "$").replace(/\\\*/g, "*").replace(/\\\^/g, "^").replace(/\\\|/g, "|").replace(/\\\(/g, "(").replace(/\\\)/g, ")");
993
+ }
994
+ function IsNonEscaped(pattern, index, char) {
995
+ return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
996
+ }
997
+ function IsOpenParen(pattern, index) {
998
+ return IsNonEscaped(pattern, index, "(");
999
+ }
1000
+ function IsCloseParen(pattern, index) {
1001
+ return IsNonEscaped(pattern, index, ")");
1002
+ }
1003
+ function IsSeparator(pattern, index) {
1004
+ return IsNonEscaped(pattern, index, "|");
1005
+ }
1006
+ function IsGroup(pattern) {
1007
+ if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
1008
+ return false;
1009
+ let count = 0;
1010
+ for (let index = 0; index < pattern.length; index++) {
1011
+ if (IsOpenParen(pattern, index))
1012
+ count += 1;
1013
+ if (IsCloseParen(pattern, index))
1014
+ count -= 1;
1015
+ if (count === 0 && index !== pattern.length - 1)
1016
+ return false;
1017
+ }
1018
+ return true;
1019
+ }
1020
+ function InGroup(pattern) {
1021
+ return pattern.slice(1, pattern.length - 1);
1022
+ }
1023
+ function IsPrecedenceOr(pattern) {
1024
+ let count = 0;
1025
+ for (let index = 0; index < pattern.length; index++) {
1026
+ if (IsOpenParen(pattern, index))
1027
+ count += 1;
1028
+ if (IsCloseParen(pattern, index))
1029
+ count -= 1;
1030
+ if (IsSeparator(pattern, index) && count === 0)
1031
+ return true;
1032
+ }
1033
+ return false;
1034
+ }
1035
+ function IsPrecedenceAnd(pattern) {
1036
+ for (let index = 0; index < pattern.length; index++) {
1037
+ if (IsOpenParen(pattern, index))
1038
+ return true;
1039
+ }
1040
+ return false;
1041
+ }
1042
+ function Or(pattern) {
1043
+ let [count, start] = [0, 0];
1044
+ const expressions = [];
1045
+ for (let index = 0; index < pattern.length; index++) {
1046
+ if (IsOpenParen(pattern, index))
1047
+ count += 1;
1048
+ if (IsCloseParen(pattern, index))
1049
+ count -= 1;
1050
+ if (IsSeparator(pattern, index) && count === 0) {
1051
+ const range2 = pattern.slice(start, index);
1052
+ if (range2.length > 0)
1053
+ expressions.push(TemplateLiteralParse(range2));
1054
+ start = index + 1;
1055
+ }
1056
+ }
1057
+ const range = pattern.slice(start);
1058
+ if (range.length > 0)
1059
+ expressions.push(TemplateLiteralParse(range));
1060
+ if (expressions.length === 0)
1061
+ return { type: "const", const: "" };
1062
+ if (expressions.length === 1)
1063
+ return expressions[0];
1064
+ return { type: "or", expr: expressions };
1065
+ }
1066
+ function And(pattern) {
1067
+ function Group(value, index) {
1068
+ if (!IsOpenParen(value, index))
1069
+ throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
1070
+ let count = 0;
1071
+ for (let scan = index; scan < value.length; scan++) {
1072
+ if (IsOpenParen(value, scan))
1073
+ count += 1;
1074
+ if (IsCloseParen(value, scan))
1075
+ count -= 1;
1076
+ if (count === 0)
1077
+ return [index, scan];
1078
+ }
1079
+ throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
1080
+ }
1081
+ function Range(pattern2, index) {
1082
+ for (let scan = index; scan < pattern2.length; scan++) {
1083
+ if (IsOpenParen(pattern2, scan))
1084
+ return [index, scan];
1085
+ }
1086
+ return [index, pattern2.length];
1087
+ }
1088
+ const expressions = [];
1089
+ for (let index = 0; index < pattern.length; index++) {
1090
+ if (IsOpenParen(pattern, index)) {
1091
+ const [start, end] = Group(pattern, index);
1092
+ const range = pattern.slice(start, end + 1);
1093
+ expressions.push(TemplateLiteralParse(range));
1094
+ index = end;
1095
+ } else {
1096
+ const [start, end] = Range(pattern, index);
1097
+ const range = pattern.slice(start, end);
1098
+ if (range.length > 0)
1099
+ expressions.push(TemplateLiteralParse(range));
1100
+ index = end - 1;
1101
+ }
1102
+ }
1103
+ return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
1104
+ }
1105
+ function TemplateLiteralParse(pattern) {
1106
+ return IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: Unescape(pattern) };
1107
+ }
1108
+ function TemplateLiteralParseExact(pattern) {
1109
+ return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
1110
+ }
1111
+
1112
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/finite.mjs
1113
+ var TemplateLiteralFiniteError = class extends TypeBoxError {
1114
+ };
1115
+ function IsNumberExpression(expression) {
1116
+ return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "0" && expression.expr[1].type === "const" && expression.expr[1].const === "[1-9][0-9]*";
1117
+ }
1118
+ function IsBooleanExpression(expression) {
1119
+ return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "true" && expression.expr[1].type === "const" && expression.expr[1].const === "false";
1120
+ }
1121
+ function IsStringExpression(expression) {
1122
+ return expression.type === "const" && expression.const === ".*";
1123
+ }
1124
+ function IsTemplateLiteralExpressionFinite(expression) {
1125
+ return IsNumberExpression(expression) || IsStringExpression(expression) ? false : IsBooleanExpression(expression) ? true : expression.type === "and" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "or" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "const" ? true : (() => {
1126
+ throw new TemplateLiteralFiniteError(`Unknown expression type`);
1127
+ })();
1128
+ }
1129
+ function IsTemplateLiteralFinite(schema) {
1130
+ const expression = TemplateLiteralParseExact(schema.pattern);
1131
+ return IsTemplateLiteralExpressionFinite(expression);
1132
+ }
1133
+
1134
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/generate.mjs
1135
+ var TemplateLiteralGenerateError = class extends TypeBoxError {
1136
+ };
1137
+ function* GenerateReduce(buffer) {
1138
+ if (buffer.length === 1)
1139
+ return yield* buffer[0];
1140
+ for (const left of buffer[0]) {
1141
+ for (const right of GenerateReduce(buffer.slice(1))) {
1142
+ yield `${left}${right}`;
1143
+ }
1144
+ }
1145
+ }
1146
+ function* GenerateAnd(expression) {
1147
+ return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
1148
+ }
1149
+ function* GenerateOr(expression) {
1150
+ for (const expr of expression.expr)
1151
+ yield* TemplateLiteralExpressionGenerate(expr);
1152
+ }
1153
+ function* GenerateConst(expression) {
1154
+ return yield expression.const;
1155
+ }
1156
+ function* TemplateLiteralExpressionGenerate(expression) {
1157
+ return expression.type === "and" ? yield* GenerateAnd(expression) : expression.type === "or" ? yield* GenerateOr(expression) : expression.type === "const" ? yield* GenerateConst(expression) : (() => {
1158
+ throw new TemplateLiteralGenerateError("Unknown expression");
1159
+ })();
1160
+ }
1161
+ function TemplateLiteralGenerate(schema) {
1162
+ const expression = TemplateLiteralParseExact(schema.pattern);
1163
+ return IsTemplateLiteralExpressionFinite(expression) ? [...TemplateLiteralExpressionGenerate(expression)] : [];
1164
+ }
1165
+
1166
+ // node_modules/@sinclair/typebox/build/esm/type/literal/literal.mjs
1167
+ function Literal(value, options) {
1168
+ return CreateType({
1169
+ [Kind]: "Literal",
1170
+ const: value,
1171
+ type: typeof value
1172
+ }, options);
1173
+ }
1174
+
1175
+ // node_modules/@sinclair/typebox/build/esm/type/boolean/boolean.mjs
1176
+ function Boolean(options) {
1177
+ return CreateType({ [Kind]: "Boolean", type: "boolean" }, options);
1178
+ }
1179
+
1180
+ // node_modules/@sinclair/typebox/build/esm/type/bigint/bigint.mjs
1181
+ function BigInt(options) {
1182
+ return CreateType({ [Kind]: "BigInt", type: "bigint" }, options);
1183
+ }
1184
+
1185
+ // node_modules/@sinclair/typebox/build/esm/type/number/number.mjs
1186
+ function Number2(options) {
1187
+ return CreateType({ [Kind]: "Number", type: "number" }, options);
1188
+ }
1189
+
1190
+ // node_modules/@sinclair/typebox/build/esm/type/string/string.mjs
1191
+ function String2(options) {
1192
+ return CreateType({ [Kind]: "String", type: "string" }, options);
1193
+ }
1194
+
1195
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/syntax.mjs
1196
+ function* FromUnion(syntax) {
1197
+ const trim = syntax.trim().replace(/"|'/g, "");
1198
+ return trim === "boolean" ? yield Boolean() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt() : trim === "string" ? yield String2() : yield (() => {
1199
+ const literals = trim.split("|").map((literal) => Literal(literal.trim()));
1200
+ return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
1201
+ })();
1202
+ }
1203
+ function* FromTerminal(syntax) {
1204
+ if (syntax[1] !== "{") {
1205
+ const L = Literal("$");
1206
+ const R = FromSyntax(syntax.slice(1));
1207
+ return yield* [L, ...R];
1208
+ }
1209
+ for (let i = 2; i < syntax.length; i++) {
1210
+ if (syntax[i] === "}") {
1211
+ const L = FromUnion(syntax.slice(2, i));
1212
+ const R = FromSyntax(syntax.slice(i + 1));
1213
+ return yield* [...L, ...R];
1214
+ }
1215
+ }
1216
+ yield Literal(syntax);
1217
+ }
1218
+ function* FromSyntax(syntax) {
1219
+ for (let i = 0; i < syntax.length; i++) {
1220
+ if (syntax[i] === "$") {
1221
+ const L = Literal(syntax.slice(0, i));
1222
+ const R = FromTerminal(syntax.slice(i));
1223
+ return yield* [L, ...R];
1224
+ }
1225
+ }
1226
+ yield Literal(syntax);
1227
+ }
1228
+ function TemplateLiteralSyntax(syntax) {
1229
+ return [...FromSyntax(syntax)];
1230
+ }
1231
+
1232
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/pattern.mjs
1233
+ var TemplateLiteralPatternError = class extends TypeBoxError {
1234
+ };
1235
+ function Escape(value) {
1236
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1237
+ }
1238
+ function Visit2(schema, acc) {
1239
+ return IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : IsUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit2(schema2, acc)).join("|")})` : IsNumber3(schema) ? `${acc}${PatternNumber}` : IsInteger(schema) ? `${acc}${PatternNumber}` : IsBigInt2(schema) ? `${acc}${PatternNumber}` : IsString2(schema) ? `${acc}${PatternString}` : IsLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : IsBoolean2(schema) ? `${acc}${PatternBoolean}` : (() => {
1240
+ throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`);
1241
+ })();
1242
+ }
1243
+ function TemplateLiteralPattern(kinds) {
1244
+ return `^${kinds.map((schema) => Visit2(schema, "")).join("")}$`;
1245
+ }
1246
+
1247
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/union.mjs
1248
+ function TemplateLiteralToUnion(schema) {
1249
+ const R = TemplateLiteralGenerate(schema);
1250
+ const L = R.map((S) => Literal(S));
1251
+ return UnionEvaluated(L);
1252
+ }
1253
+
1254
+ // node_modules/@sinclair/typebox/build/esm/type/template-literal/template-literal.mjs
1255
+ function TemplateLiteral(unresolved, options) {
1256
+ const pattern = IsString(unresolved) ? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved)) : TemplateLiteralPattern(unresolved);
1257
+ return CreateType({ [Kind]: "TemplateLiteral", type: "string", pattern }, options);
1258
+ }
1259
+
1260
+ // node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-property-keys.mjs
1261
+ function FromTemplateLiteral(templateLiteral) {
1262
+ const keys = TemplateLiteralGenerate(templateLiteral);
1263
+ return keys.map((key) => key.toString());
1264
+ }
1265
+ function FromUnion2(types) {
1266
+ const result = [];
1267
+ for (const type of types)
1268
+ result.push(...IndexPropertyKeys(type));
1269
+ return result;
1270
+ }
1271
+ function FromLiteral(literalValue) {
1272
+ return [literalValue.toString()];
1273
+ }
1274
+ function IndexPropertyKeys(type) {
1275
+ return [...new Set(IsTemplateLiteral(type) ? FromTemplateLiteral(type) : IsUnion(type) ? FromUnion2(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : IsNumber3(type) ? ["[number]"] : IsInteger(type) ? ["[number]"] : [])];
1276
+ }
1277
+
1278
+ // node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-result.mjs
1279
+ function FromProperties(type, properties, options) {
1280
+ const result = {};
1281
+ for (const K2 of Object.getOwnPropertyNames(properties)) {
1282
+ result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options);
1283
+ }
1284
+ return result;
1285
+ }
1286
+ function FromMappedResult(type, mappedResult, options) {
1287
+ return FromProperties(type, mappedResult.properties, options);
1288
+ }
1289
+ function IndexFromMappedResult(type, mappedResult, options) {
1290
+ const properties = FromMappedResult(type, mappedResult, options);
1291
+ return MappedResult(properties);
1292
+ }
1293
+
1294
+ // node_modules/@sinclair/typebox/build/esm/type/indexed/indexed.mjs
1295
+ function FromRest(types, key) {
1296
+ return types.map((type) => IndexFromPropertyKey(type, key));
1297
+ }
1298
+ function FromIntersectRest(types) {
1299
+ return types.filter((type) => !IsNever(type));
1300
+ }
1301
+ function FromIntersect(types, key) {
1302
+ return IntersectEvaluated(FromIntersectRest(FromRest(types, key)));
1303
+ }
1304
+ function FromUnionRest(types) {
1305
+ return types.some((L) => IsNever(L)) ? [] : types;
1306
+ }
1307
+ function FromUnion3(types, key) {
1308
+ return UnionEvaluated(FromUnionRest(FromRest(types, key)));
1309
+ }
1310
+ function FromTuple(types, key) {
1311
+ return key in types ? types[key] : key === "[number]" ? UnionEvaluated(types) : Never();
1312
+ }
1313
+ function FromArray(type, key) {
1314
+ return key === "[number]" ? type : Never();
1315
+ }
1316
+ function FromProperty(properties, propertyKey) {
1317
+ return propertyKey in properties ? properties[propertyKey] : Never();
1318
+ }
1319
+ function IndexFromPropertyKey(type, propertyKey) {
1320
+ return IsIntersect(type) ? FromIntersect(type.allOf, propertyKey) : IsUnion(type) ? FromUnion3(type.anyOf, propertyKey) : IsTuple(type) ? FromTuple(type.items ?? [], propertyKey) : IsArray3(type) ? FromArray(type.items, propertyKey) : IsObject3(type) ? FromProperty(type.properties, propertyKey) : Never();
1321
+ }
1322
+ function IndexFromPropertyKeys(type, propertyKeys) {
1323
+ return propertyKeys.map((propertyKey) => IndexFromPropertyKey(type, propertyKey));
1324
+ }
1325
+ function FromSchema(type, propertyKeys) {
1326
+ return UnionEvaluated(IndexFromPropertyKeys(type, propertyKeys));
1327
+ }
1328
+ function Index(type, key, options) {
1329
+ if (IsRef(type) || IsRef(key)) {
1330
+ const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
1331
+ if (!IsSchema(type) || !IsSchema(key))
1332
+ throw new TypeBoxError(error);
1333
+ return Computed("Index", [type, key]);
1334
+ }
1335
+ if (IsMappedResult(key))
1336
+ return IndexFromMappedResult(type, key, options);
1337
+ if (IsMappedKey(key))
1338
+ return IndexFromMappedKey(type, key, options);
1339
+ return CreateType(IsSchema(key) ? FromSchema(type, IndexPropertyKeys(key)) : FromSchema(type, key), options);
1340
+ }
1341
+
1342
+ // node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-key.mjs
1343
+ function MappedIndexPropertyKey(type, key, options) {
1344
+ return { [key]: Index(type, [key], Clone(options)) };
1345
+ }
1346
+ function MappedIndexPropertyKeys(type, propertyKeys, options) {
1347
+ return propertyKeys.reduce((result, left) => {
1348
+ return { ...result, ...MappedIndexPropertyKey(type, left, options) };
1349
+ }, {});
1350
+ }
1351
+ function MappedIndexProperties(type, mappedKey, options) {
1352
+ return MappedIndexPropertyKeys(type, mappedKey.keys, options);
1353
+ }
1354
+ function IndexFromMappedKey(type, mappedKey, options) {
1355
+ const properties = MappedIndexProperties(type, mappedKey, options);
1356
+ return MappedResult(properties);
1357
+ }
1358
+
1359
+ // node_modules/@sinclair/typebox/build/esm/type/iterator/iterator.mjs
1360
+ function Iterator(items, options) {
1361
+ return CreateType({ [Kind]: "Iterator", type: "Iterator", items }, options);
1362
+ }
1363
+
1364
+ // node_modules/@sinclair/typebox/build/esm/type/object/object.mjs
1365
+ function RequiredArray(properties) {
1366
+ return globalThis.Object.keys(properties).filter((key) => !IsOptional(properties[key]));
1367
+ }
1368
+ function _Object(properties, options) {
1369
+ const required = RequiredArray(properties);
1370
+ const schema = required.length > 0 ? { [Kind]: "Object", type: "object", required, properties } : { [Kind]: "Object", type: "object", properties };
1371
+ return CreateType(schema, options);
1372
+ }
1373
+ var Object2 = _Object;
1374
+
1375
+ // node_modules/@sinclair/typebox/build/esm/type/promise/promise.mjs
1376
+ function Promise2(item, options) {
1377
+ return CreateType({ [Kind]: "Promise", type: "Promise", item }, options);
1378
+ }
1379
+
1380
+ // node_modules/@sinclair/typebox/build/esm/type/readonly/readonly.mjs
1381
+ function RemoveReadonly(schema) {
1382
+ return CreateType(Discard(schema, [ReadonlyKind]));
1383
+ }
1384
+ function AddReadonly(schema) {
1385
+ return CreateType({ ...schema, [ReadonlyKind]: "Readonly" });
1386
+ }
1387
+ function ReadonlyWithFlag(schema, F) {
1388
+ return F === false ? RemoveReadonly(schema) : AddReadonly(schema);
1389
+ }
1390
+ function Readonly(schema, enable) {
1391
+ const F = enable ?? true;
1392
+ return IsMappedResult(schema) ? ReadonlyFromMappedResult(schema, F) : ReadonlyWithFlag(schema, F);
1393
+ }
1394
+
1395
+ // node_modules/@sinclair/typebox/build/esm/type/readonly/readonly-from-mapped-result.mjs
1396
+ function FromProperties2(K, F) {
1397
+ const Acc = {};
1398
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
1399
+ Acc[K2] = Readonly(K[K2], F);
1400
+ return Acc;
1401
+ }
1402
+ function FromMappedResult2(R, F) {
1403
+ return FromProperties2(R.properties, F);
1404
+ }
1405
+ function ReadonlyFromMappedResult(R, F) {
1406
+ const P = FromMappedResult2(R, F);
1407
+ return MappedResult(P);
1408
+ }
1409
+
1410
+ // node_modules/@sinclair/typebox/build/esm/type/tuple/tuple.mjs
1411
+ function Tuple(types, options) {
1412
+ return CreateType(types.length > 0 ? { [Kind]: "Tuple", type: "array", items: types, additionalItems: false, minItems: types.length, maxItems: types.length } : { [Kind]: "Tuple", type: "array", minItems: types.length, maxItems: types.length }, options);
1413
+ }
1414
+
1415
+ // node_modules/@sinclair/typebox/build/esm/type/mapped/mapped.mjs
1416
+ function FromMappedResult3(K, P) {
1417
+ return K in P ? FromSchemaType(K, P[K]) : MappedResult(P);
1418
+ }
1419
+ function MappedKeyToKnownMappedResultProperties(K) {
1420
+ return { [K]: Literal(K) };
1421
+ }
1422
+ function MappedKeyToUnknownMappedResultProperties(P) {
1423
+ const Acc = {};
1424
+ for (const L of P)
1425
+ Acc[L] = Literal(L);
1426
+ return Acc;
1427
+ }
1428
+ function MappedKeyToMappedResultProperties(K, P) {
1429
+ return SetIncludes(P, K) ? MappedKeyToKnownMappedResultProperties(K) : MappedKeyToUnknownMappedResultProperties(P);
1430
+ }
1431
+ function FromMappedKey(K, P) {
1432
+ const R = MappedKeyToMappedResultProperties(K, P);
1433
+ return FromMappedResult3(K, R);
1434
+ }
1435
+ function FromRest2(K, T) {
1436
+ return T.map((L) => FromSchemaType(K, L));
1437
+ }
1438
+ function FromProperties3(K, T) {
1439
+ const Acc = {};
1440
+ for (const K2 of globalThis.Object.getOwnPropertyNames(T))
1441
+ Acc[K2] = FromSchemaType(K, T[K2]);
1442
+ return Acc;
1443
+ }
1444
+ function FromSchemaType(K, T) {
1445
+ const options = { ...T };
1446
+ return (
1447
+ // unevaluated modifier types
1448
+ IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) : IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) : (
1449
+ // unevaluated mapped types
1450
+ IsMappedResult(T) ? FromMappedResult3(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : (
1451
+ // unevaluated types
1452
+ IsConstructor(T) ? Constructor(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsFunction2(T) ? Function(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsAsyncIterator2(T) ? AsyncIterator(FromSchemaType(K, T.items), options) : IsIterator2(T) ? Iterator(FromSchemaType(K, T.items), options) : IsIntersect(T) ? Intersect(FromRest2(K, T.allOf), options) : IsUnion(T) ? Union(FromRest2(K, T.anyOf), options) : IsTuple(T) ? Tuple(FromRest2(K, T.items ?? []), options) : IsObject3(T) ? Object2(FromProperties3(K, T.properties), options) : IsArray3(T) ? Array2(FromSchemaType(K, T.items), options) : IsPromise(T) ? Promise2(FromSchemaType(K, T.item), options) : T
1453
+ )
1454
+ )
1455
+ );
1456
+ }
1457
+ function MappedFunctionReturnType(K, T) {
1458
+ const Acc = {};
1459
+ for (const L of K)
1460
+ Acc[L] = FromSchemaType(L, T);
1461
+ return Acc;
1462
+ }
1463
+ function Mapped(key, map, options) {
1464
+ const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
1465
+ const RT = map({ [Kind]: "MappedKey", keys: K });
1466
+ const R = MappedFunctionReturnType(K, RT);
1467
+ return Object2(R, options);
1468
+ }
1469
+
1470
+ // node_modules/@sinclair/typebox/build/esm/type/optional/optional.mjs
1471
+ function RemoveOptional(schema) {
1472
+ return CreateType(Discard(schema, [OptionalKind]));
1473
+ }
1474
+ function AddOptional(schema) {
1475
+ return CreateType({ ...schema, [OptionalKind]: "Optional" });
1476
+ }
1477
+ function OptionalWithFlag(schema, F) {
1478
+ return F === false ? RemoveOptional(schema) : AddOptional(schema);
1479
+ }
1480
+ function Optional(schema, enable) {
1481
+ const F = enable ?? true;
1482
+ return IsMappedResult(schema) ? OptionalFromMappedResult(schema, F) : OptionalWithFlag(schema, F);
1483
+ }
1484
+
1485
+ // node_modules/@sinclair/typebox/build/esm/type/optional/optional-from-mapped-result.mjs
1486
+ function FromProperties4(P, F) {
1487
+ const Acc = {};
1488
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
1489
+ Acc[K2] = Optional(P[K2], F);
1490
+ return Acc;
1491
+ }
1492
+ function FromMappedResult4(R, F) {
1493
+ return FromProperties4(R.properties, F);
1494
+ }
1495
+ function OptionalFromMappedResult(R, F) {
1496
+ const P = FromMappedResult4(R, F);
1497
+ return MappedResult(P);
1498
+ }
1499
+
1500
+ // node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-create.mjs
1501
+ function IntersectCreate(T, options = {}) {
1502
+ const allObjects = T.every((schema) => IsObject3(schema));
1503
+ const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties) ? { unevaluatedProperties: options.unevaluatedProperties } : {};
1504
+ return CreateType(options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects ? { ...clonedUnevaluatedProperties, [Kind]: "Intersect", type: "object", allOf: T } : { ...clonedUnevaluatedProperties, [Kind]: "Intersect", allOf: T }, options);
1505
+ }
1506
+
1507
+ // node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-evaluated.mjs
1508
+ function IsIntersectOptional(types) {
1509
+ return types.every((left) => IsOptional(left));
1510
+ }
1511
+ function RemoveOptionalFromType2(type) {
1512
+ return Discard(type, [OptionalKind]);
1513
+ }
1514
+ function RemoveOptionalFromRest2(types) {
1515
+ return types.map((left) => IsOptional(left) ? RemoveOptionalFromType2(left) : left);
1516
+ }
1517
+ function ResolveIntersect(types, options) {
1518
+ return IsIntersectOptional(types) ? Optional(IntersectCreate(RemoveOptionalFromRest2(types), options)) : IntersectCreate(RemoveOptionalFromRest2(types), options);
1519
+ }
1520
+ function IntersectEvaluated(types, options = {}) {
1521
+ if (types.length === 1)
1522
+ return CreateType(types[0], options);
1523
+ if (types.length === 0)
1524
+ return Never(options);
1525
+ if (types.some((schema) => IsTransform(schema)))
1526
+ throw new Error("Cannot intersect transform types");
1527
+ return ResolveIntersect(types, options);
1528
+ }
1529
+
1530
+ // node_modules/@sinclair/typebox/build/esm/type/intersect/intersect.mjs
1531
+ function Intersect(types, options) {
1532
+ if (types.length === 1)
1533
+ return CreateType(types[0], options);
1534
+ if (types.length === 0)
1535
+ return Never(options);
1536
+ if (types.some((schema) => IsTransform(schema)))
1537
+ throw new Error("Cannot intersect transform types");
1538
+ return IntersectCreate(types, options);
1539
+ }
1540
+
1541
+ // node_modules/@sinclair/typebox/build/esm/type/ref/ref.mjs
1542
+ function Ref(...args) {
1543
+ const [$ref, options] = typeof args[0] === "string" ? [args[0], args[1]] : [args[0].$id, args[1]];
1544
+ if (typeof $ref !== "string")
1545
+ throw new TypeBoxError("Ref: $ref must be a string");
1546
+ return CreateType({ [Kind]: "Ref", $ref }, options);
1547
+ }
1548
+
1549
+ // node_modules/@sinclair/typebox/build/esm/type/awaited/awaited.mjs
1550
+ function FromComputed(target, parameters) {
1551
+ return Computed("Awaited", [Computed(target, parameters)]);
1552
+ }
1553
+ function FromRef($ref) {
1554
+ return Computed("Awaited", [Ref($ref)]);
1555
+ }
1556
+ function FromIntersect2(types) {
1557
+ return Intersect(FromRest3(types));
1558
+ }
1559
+ function FromUnion4(types) {
1560
+ return Union(FromRest3(types));
1561
+ }
1562
+ function FromPromise(type) {
1563
+ return Awaited(type);
1564
+ }
1565
+ function FromRest3(types) {
1566
+ return types.map((type) => Awaited(type));
1567
+ }
1568
+ function Awaited(type, options) {
1569
+ return CreateType(IsComputed(type) ? FromComputed(type.target, type.parameters) : IsIntersect(type) ? FromIntersect2(type.allOf) : IsUnion(type) ? FromUnion4(type.anyOf) : IsPromise(type) ? FromPromise(type.item) : IsRef(type) ? FromRef(type.$ref) : type, options);
1570
+ }
1571
+
1572
+ // node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-property-keys.mjs
1573
+ function FromRest4(types) {
1574
+ const result = [];
1575
+ for (const L of types)
1576
+ result.push(KeyOfPropertyKeys(L));
1577
+ return result;
1578
+ }
1579
+ function FromIntersect3(types) {
1580
+ const propertyKeysArray = FromRest4(types);
1581
+ const propertyKeys = SetUnionMany(propertyKeysArray);
1582
+ return propertyKeys;
1583
+ }
1584
+ function FromUnion5(types) {
1585
+ const propertyKeysArray = FromRest4(types);
1586
+ const propertyKeys = SetIntersectMany(propertyKeysArray);
1587
+ return propertyKeys;
1588
+ }
1589
+ function FromTuple2(types) {
1590
+ return types.map((_, indexer) => indexer.toString());
1591
+ }
1592
+ function FromArray2(_) {
1593
+ return ["[number]"];
1594
+ }
1595
+ function FromProperties5(T) {
1596
+ return globalThis.Object.getOwnPropertyNames(T);
1597
+ }
1598
+ function FromPatternProperties(patternProperties) {
1599
+ return [];
1600
+ }
1601
+ function KeyOfPropertyKeys(type) {
1602
+ return IsIntersect(type) ? FromIntersect3(type.allOf) : IsUnion(type) ? FromUnion5(type.anyOf) : IsTuple(type) ? FromTuple2(type.items ?? []) : IsArray3(type) ? FromArray2(type.items) : IsObject3(type) ? FromProperties5(type.properties) : IsRecord(type) ? FromPatternProperties(type.patternProperties) : [];
1603
+ }
1604
+
1605
+ // node_modules/@sinclair/typebox/build/esm/type/keyof/keyof.mjs
1606
+ function FromComputed2(target, parameters) {
1607
+ return Computed("KeyOf", [Computed(target, parameters)]);
1608
+ }
1609
+ function FromRef2($ref) {
1610
+ return Computed("KeyOf", [Ref($ref)]);
1611
+ }
1612
+ function KeyOfFromType(type, options) {
1613
+ const propertyKeys = KeyOfPropertyKeys(type);
1614
+ const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
1615
+ const result = UnionEvaluated(propertyKeyTypes);
1616
+ return CreateType(result, options);
1617
+ }
1618
+ function KeyOfPropertyKeysToRest(propertyKeys) {
1619
+ return propertyKeys.map((L) => L === "[number]" ? Number2() : Literal(L));
1620
+ }
1621
+ function KeyOf(type, options) {
1622
+ return IsComputed(type) ? FromComputed2(type.target, type.parameters) : IsRef(type) ? FromRef2(type.$ref) : IsMappedResult(type) ? KeyOfFromMappedResult(type, options) : KeyOfFromType(type, options);
1623
+ }
1624
+
1625
+ // node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-from-mapped-result.mjs
1626
+ function FromProperties6(properties, options) {
1627
+ const result = {};
1628
+ for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
1629
+ result[K2] = KeyOf(properties[K2], Clone(options));
1630
+ return result;
1631
+ }
1632
+ function FromMappedResult5(mappedResult, options) {
1633
+ return FromProperties6(mappedResult.properties, options);
1634
+ }
1635
+ function KeyOfFromMappedResult(mappedResult, options) {
1636
+ const properties = FromMappedResult5(mappedResult, options);
1637
+ return MappedResult(properties);
1638
+ }
1639
+
1640
+ // node_modules/@sinclair/typebox/build/esm/type/composite/composite.mjs
1641
+ function CompositeKeys(T) {
1642
+ const Acc = [];
1643
+ for (const L of T)
1644
+ Acc.push(...KeyOfPropertyKeys(L));
1645
+ return SetDistinct(Acc);
1646
+ }
1647
+ function FilterNever(T) {
1648
+ return T.filter((L) => !IsNever(L));
1649
+ }
1650
+ function CompositeProperty(T, K) {
1651
+ const Acc = [];
1652
+ for (const L of T)
1653
+ Acc.push(...IndexFromPropertyKeys(L, [K]));
1654
+ return FilterNever(Acc);
1655
+ }
1656
+ function CompositeProperties(T, K) {
1657
+ const Acc = {};
1658
+ for (const L of K) {
1659
+ Acc[L] = IntersectEvaluated(CompositeProperty(T, L));
1660
+ }
1661
+ return Acc;
1662
+ }
1663
+ function Composite(T, options) {
1664
+ const K = CompositeKeys(T);
1665
+ const P = CompositeProperties(T, K);
1666
+ const R = Object2(P, options);
1667
+ return R;
1668
+ }
1669
+
1670
+ // node_modules/@sinclair/typebox/build/esm/type/date/date.mjs
1671
+ function Date2(options) {
1672
+ return CreateType({ [Kind]: "Date", type: "Date" }, options);
1673
+ }
1674
+
1675
+ // node_modules/@sinclair/typebox/build/esm/type/null/null.mjs
1676
+ function Null(options) {
1677
+ return CreateType({ [Kind]: "Null", type: "null" }, options);
1678
+ }
1679
+
1680
+ // node_modules/@sinclair/typebox/build/esm/type/symbol/symbol.mjs
1681
+ function Symbol2(options) {
1682
+ return CreateType({ [Kind]: "Symbol", type: "symbol" }, options);
1683
+ }
1684
+
1685
+ // node_modules/@sinclair/typebox/build/esm/type/undefined/undefined.mjs
1686
+ function Undefined(options) {
1687
+ return CreateType({ [Kind]: "Undefined", type: "undefined" }, options);
1688
+ }
1689
+
1690
+ // node_modules/@sinclair/typebox/build/esm/type/uint8array/uint8array.mjs
1691
+ function Uint8Array2(options) {
1692
+ return CreateType({ [Kind]: "Uint8Array", type: "Uint8Array" }, options);
1693
+ }
1694
+
1695
+ // node_modules/@sinclair/typebox/build/esm/type/unknown/unknown.mjs
1696
+ function Unknown(options) {
1697
+ return CreateType({ [Kind]: "Unknown" }, options);
1698
+ }
1699
+
1700
+ // node_modules/@sinclair/typebox/build/esm/type/const/const.mjs
1701
+ function FromArray3(T) {
1702
+ return T.map((L) => FromValue(L, false));
1703
+ }
1704
+ function FromProperties7(value) {
1705
+ const Acc = {};
1706
+ for (const K of globalThis.Object.getOwnPropertyNames(value))
1707
+ Acc[K] = Readonly(FromValue(value[K], false));
1708
+ return Acc;
1709
+ }
1710
+ function ConditionalReadonly(T, root) {
1711
+ return root === true ? T : Readonly(T);
1712
+ }
1713
+ function FromValue(value, root) {
1714
+ return IsAsyncIterator(value) ? ConditionalReadonly(Any(), root) : IsIterator(value) ? ConditionalReadonly(Any(), root) : IsArray(value) ? Readonly(Tuple(FromArray3(value))) : IsUint8Array(value) ? Uint8Array2() : IsDate(value) ? Date2() : IsObject(value) ? ConditionalReadonly(Object2(FromProperties7(value)), root) : IsFunction(value) ? ConditionalReadonly(Function([], Unknown()), root) : IsUndefined(value) ? Undefined() : IsNull(value) ? Null() : IsSymbol(value) ? Symbol2() : IsBigInt(value) ? BigInt() : IsNumber(value) ? Literal(value) : IsBoolean(value) ? Literal(value) : IsString(value) ? Literal(value) : Object2({});
1715
+ }
1716
+ function Const(T, options) {
1717
+ return CreateType(FromValue(T, true), options);
1718
+ }
1719
+
1720
+ // node_modules/@sinclair/typebox/build/esm/type/constructor-parameters/constructor-parameters.mjs
1721
+ function ConstructorParameters(schema, options) {
1722
+ return IsConstructor(schema) ? Tuple(schema.parameters, options) : Never(options);
1723
+ }
1724
+
1725
+ // node_modules/@sinclair/typebox/build/esm/type/enum/enum.mjs
1726
+ function Enum(item, options) {
1727
+ if (IsUndefined(item))
1728
+ throw new Error("Enum undefined or empty");
1729
+ const values1 = globalThis.Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
1730
+ const values2 = [...new Set(values1)];
1731
+ const anyOf = values2.map((value) => Literal(value));
1732
+ return Union(anyOf, { ...options, [Hint]: "Enum" });
1733
+ }
1734
+
1735
+ // node_modules/@sinclair/typebox/build/esm/type/extends/extends-check.mjs
1736
+ var ExtendsResolverError = class extends TypeBoxError {
1737
+ };
1738
+ var ExtendsResult;
1739
+ (function(ExtendsResult2) {
1740
+ ExtendsResult2[ExtendsResult2["Union"] = 0] = "Union";
1741
+ ExtendsResult2[ExtendsResult2["True"] = 1] = "True";
1742
+ ExtendsResult2[ExtendsResult2["False"] = 2] = "False";
1743
+ })(ExtendsResult || (ExtendsResult = {}));
1744
+ function IntoBooleanResult(result) {
1745
+ return result === ExtendsResult.False ? result : ExtendsResult.True;
1746
+ }
1747
+ function Throw(message) {
1748
+ throw new ExtendsResolverError(message);
1749
+ }
1750
+ function IsStructuralRight(right) {
1751
+ return type_exports.IsNever(right) || type_exports.IsIntersect(right) || type_exports.IsUnion(right) || type_exports.IsUnknown(right) || type_exports.IsAny(right);
1752
+ }
1753
+ function StructuralRight(left, right) {
1754
+ return type_exports.IsNever(right) ? FromNeverRight() : type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsUnknown(right) ? FromUnknownRight() : type_exports.IsAny(right) ? FromAnyRight() : Throw("StructuralRight");
1755
+ }
1756
+ function FromAnyRight(left, right) {
1757
+ return ExtendsResult.True;
1758
+ }
1759
+ function FromAny(left, right) {
1760
+ return type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) && right.anyOf.some((schema) => type_exports.IsAny(schema) || type_exports.IsUnknown(schema)) ? ExtendsResult.True : type_exports.IsUnion(right) ? ExtendsResult.Union : type_exports.IsUnknown(right) ? ExtendsResult.True : type_exports.IsAny(right) ? ExtendsResult.True : ExtendsResult.Union;
1761
+ }
1762
+ function FromArrayRight(left, right) {
1763
+ return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) ? ExtendsResult.True : ExtendsResult.False;
1764
+ }
1765
+ function FromArray4(left, right) {
1766
+ return type_exports.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsArray(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
1767
+ }
1768
+ function FromAsyncIterator(left, right) {
1769
+ return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsAsyncIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
1770
+ }
1771
+ function FromBigInt(left, right) {
1772
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsBigInt(right) ? ExtendsResult.True : ExtendsResult.False;
1773
+ }
1774
+ function FromBooleanRight(left, right) {
1775
+ return type_exports.IsLiteralBoolean(left) ? ExtendsResult.True : type_exports.IsBoolean(left) ? ExtendsResult.True : ExtendsResult.False;
1776
+ }
1777
+ function FromBoolean(left, right) {
1778
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsBoolean(right) ? ExtendsResult.True : ExtendsResult.False;
1779
+ }
1780
+ function FromConstructor(left, right) {
1781
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsConstructor(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit3(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
1782
+ }
1783
+ function FromDate(left, right) {
1784
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsDate(right) ? ExtendsResult.True : ExtendsResult.False;
1785
+ }
1786
+ function FromFunction(left, right) {
1787
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsFunction(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit3(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
1788
+ }
1789
+ function FromIntegerRight(left, right) {
1790
+ return type_exports.IsLiteral(left) && value_exports.IsNumber(left.const) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
1791
+ }
1792
+ function FromInteger(left, right) {
1793
+ return type_exports.IsInteger(right) || type_exports.IsNumber(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : ExtendsResult.False;
1794
+ }
1795
+ function FromIntersectRight(left, right) {
1796
+ return right.allOf.every((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
1797
+ }
1798
+ function FromIntersect4(left, right) {
1799
+ return left.allOf.some((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
1800
+ }
1801
+ function FromIterator(left, right) {
1802
+ return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
1803
+ }
1804
+ function FromLiteral2(left, right) {
1805
+ return type_exports.IsLiteral(right) && right.const === left.const ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsString(right) ? FromStringRight(left) : type_exports.IsNumber(right) ? FromNumberRight(left) : type_exports.IsInteger(right) ? FromIntegerRight(left) : type_exports.IsBoolean(right) ? FromBooleanRight(left) : ExtendsResult.False;
1806
+ }
1807
+ function FromNeverRight(left, right) {
1808
+ return ExtendsResult.False;
1809
+ }
1810
+ function FromNever(left, right) {
1811
+ return ExtendsResult.True;
1812
+ }
1813
+ function UnwrapTNot(schema) {
1814
+ let [current, depth] = [schema, 0];
1815
+ while (true) {
1816
+ if (!type_exports.IsNot(current))
1817
+ break;
1818
+ current = current.not;
1819
+ depth += 1;
1820
+ }
1821
+ return depth % 2 === 0 ? current : Unknown();
1822
+ }
1823
+ function FromNot(left, right) {
1824
+ return type_exports.IsNot(left) ? Visit3(UnwrapTNot(left), right) : type_exports.IsNot(right) ? Visit3(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
1825
+ }
1826
+ function FromNull(left, right) {
1827
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsNull(right) ? ExtendsResult.True : ExtendsResult.False;
1828
+ }
1829
+ function FromNumberRight(left, right) {
1830
+ return type_exports.IsLiteralNumber(left) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
1831
+ }
1832
+ function FromNumber(left, right) {
1833
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsInteger(right) || type_exports.IsNumber(right) ? ExtendsResult.True : ExtendsResult.False;
1834
+ }
1835
+ function IsObjectPropertyCount(schema, count) {
1836
+ return Object.getOwnPropertyNames(schema.properties).length === count;
1837
+ }
1838
+ function IsObjectStringLike(schema) {
1839
+ return IsObjectArrayLike(schema);
1840
+ }
1841
+ function IsObjectSymbolLike(schema) {
1842
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "description" in schema.properties && type_exports.IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && (type_exports.IsString(schema.properties.description.anyOf[0]) && type_exports.IsUndefined(schema.properties.description.anyOf[1]) || type_exports.IsString(schema.properties.description.anyOf[1]) && type_exports.IsUndefined(schema.properties.description.anyOf[0]));
1843
+ }
1844
+ function IsObjectNumberLike(schema) {
1845
+ return IsObjectPropertyCount(schema, 0);
1846
+ }
1847
+ function IsObjectBooleanLike(schema) {
1848
+ return IsObjectPropertyCount(schema, 0);
1849
+ }
1850
+ function IsObjectBigIntLike(schema) {
1851
+ return IsObjectPropertyCount(schema, 0);
1852
+ }
1853
+ function IsObjectDateLike(schema) {
1854
+ return IsObjectPropertyCount(schema, 0);
1855
+ }
1856
+ function IsObjectUint8ArrayLike(schema) {
1857
+ return IsObjectArrayLike(schema);
1858
+ }
1859
+ function IsObjectFunctionLike(schema) {
1860
+ const length = Number2();
1861
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
1862
+ }
1863
+ function IsObjectConstructorLike(schema) {
1864
+ return IsObjectPropertyCount(schema, 0);
1865
+ }
1866
+ function IsObjectArrayLike(schema) {
1867
+ const length = Number2();
1868
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
1869
+ }
1870
+ function IsObjectPromiseLike(schema) {
1871
+ const then = Function([Any()], Any());
1872
+ return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit3(schema.properties["then"], then)) === ExtendsResult.True;
1873
+ }
1874
+ function Property(left, right) {
1875
+ return Visit3(left, right) === ExtendsResult.False ? ExtendsResult.False : type_exports.IsOptional(left) && !type_exports.IsOptional(right) ? ExtendsResult.False : ExtendsResult.True;
1876
+ }
1877
+ function FromObjectRight(left, right) {
1878
+ return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) || type_exports.IsLiteralString(left) && IsObjectStringLike(right) || type_exports.IsLiteralNumber(left) && IsObjectNumberLike(right) || type_exports.IsLiteralBoolean(left) && IsObjectBooleanLike(right) || type_exports.IsSymbol(left) && IsObjectSymbolLike(right) || type_exports.IsBigInt(left) && IsObjectBigIntLike(right) || type_exports.IsString(left) && IsObjectStringLike(right) || type_exports.IsSymbol(left) && IsObjectSymbolLike(right) || type_exports.IsNumber(left) && IsObjectNumberLike(right) || type_exports.IsInteger(left) && IsObjectNumberLike(right) || type_exports.IsBoolean(left) && IsObjectBooleanLike(right) || type_exports.IsUint8Array(left) && IsObjectUint8ArrayLike(right) || type_exports.IsDate(left) && IsObjectDateLike(right) || type_exports.IsConstructor(left) && IsObjectConstructorLike(right) || type_exports.IsFunction(left) && IsObjectFunctionLike(right) ? ExtendsResult.True : type_exports.IsRecord(left) && type_exports.IsString(RecordKey(left)) ? (() => {
1879
+ return right[Hint] === "Record" ? ExtendsResult.True : ExtendsResult.False;
1880
+ })() : type_exports.IsRecord(left) && type_exports.IsNumber(RecordKey(left)) ? (() => {
1881
+ return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
1882
+ })() : ExtendsResult.False;
1883
+ }
1884
+ function FromObject(left, right) {
1885
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : !type_exports.IsObject(right) ? ExtendsResult.False : (() => {
1886
+ for (const key of Object.getOwnPropertyNames(right.properties)) {
1887
+ if (!(key in left.properties) && !type_exports.IsOptional(right.properties[key])) {
1888
+ return ExtendsResult.False;
1889
+ }
1890
+ if (type_exports.IsOptional(right.properties[key])) {
1891
+ return ExtendsResult.True;
1892
+ }
1893
+ if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
1894
+ return ExtendsResult.False;
1895
+ }
1896
+ }
1897
+ return ExtendsResult.True;
1898
+ })();
1899
+ }
1900
+ function FromPromise2(left, right) {
1901
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True : !type_exports.IsPromise(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.item, right.item));
1902
+ }
1903
+ function RecordKey(schema) {
1904
+ return PatternNumberExact in schema.patternProperties ? Number2() : PatternStringExact in schema.patternProperties ? String2() : Throw("Unknown record key pattern");
1905
+ }
1906
+ function RecordValue(schema) {
1907
+ return PatternNumberExact in schema.patternProperties ? schema.patternProperties[PatternNumberExact] : PatternStringExact in schema.patternProperties ? schema.patternProperties[PatternStringExact] : Throw("Unable to get record value schema");
1908
+ }
1909
+ function FromRecordRight(left, right) {
1910
+ const [Key, Value] = [RecordKey(right), RecordValue(right)];
1911
+ return type_exports.IsLiteralString(left) && type_exports.IsNumber(Key) && IntoBooleanResult(Visit3(left, Value)) === ExtendsResult.True ? ExtendsResult.True : type_exports.IsUint8Array(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsString(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsArray(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsObject(left) ? (() => {
1912
+ for (const key of Object.getOwnPropertyNames(left.properties)) {
1913
+ if (Property(Value, left.properties[key]) === ExtendsResult.False) {
1914
+ return ExtendsResult.False;
1915
+ }
1916
+ }
1917
+ return ExtendsResult.True;
1918
+ })() : ExtendsResult.False;
1919
+ }
1920
+ function FromRecord(left, right) {
1921
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsRecord(right) ? ExtendsResult.False : Visit3(RecordValue(left), RecordValue(right));
1922
+ }
1923
+ function FromRegExp(left, right) {
1924
+ const L = type_exports.IsRegExp(left) ? String2() : left;
1925
+ const R = type_exports.IsRegExp(right) ? String2() : right;
1926
+ return Visit3(L, R);
1927
+ }
1928
+ function FromStringRight(left, right) {
1929
+ return type_exports.IsLiteral(left) && value_exports.IsString(left.const) ? ExtendsResult.True : type_exports.IsString(left) ? ExtendsResult.True : ExtendsResult.False;
1930
+ }
1931
+ function FromString(left, right) {
1932
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsString(right) ? ExtendsResult.True : ExtendsResult.False;
1933
+ }
1934
+ function FromSymbol(left, right) {
1935
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsSymbol(right) ? ExtendsResult.True : ExtendsResult.False;
1936
+ }
1937
+ function FromTemplateLiteral2(left, right) {
1938
+ return type_exports.IsTemplateLiteral(left) ? Visit3(TemplateLiteralToUnion(left), right) : type_exports.IsTemplateLiteral(right) ? Visit3(left, TemplateLiteralToUnion(right)) : Throw("Invalid fallthrough for TemplateLiteral");
1939
+ }
1940
+ function IsArrayOfTuple(left, right) {
1941
+ return type_exports.IsArray(right) && left.items !== void 0 && left.items.every((schema) => Visit3(schema, right.items) === ExtendsResult.True);
1942
+ }
1943
+ function FromTupleRight(left, right) {
1944
+ return type_exports.IsNever(left) ? ExtendsResult.True : type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : ExtendsResult.False;
1945
+ }
1946
+ function FromTuple3(left, right) {
1947
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : type_exports.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True : !type_exports.IsTuple(right) ? ExtendsResult.False : value_exports.IsUndefined(left.items) && !value_exports.IsUndefined(right.items) || !value_exports.IsUndefined(left.items) && value_exports.IsUndefined(right.items) ? ExtendsResult.False : value_exports.IsUndefined(left.items) && !value_exports.IsUndefined(right.items) ? ExtendsResult.True : left.items.every((schema, index) => Visit3(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
1948
+ }
1949
+ function FromUint8Array(left, right) {
1950
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsUint8Array(right) ? ExtendsResult.True : ExtendsResult.False;
1951
+ }
1952
+ function FromUndefined(left, right) {
1953
+ return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsVoid(right) ? FromVoidRight(left) : type_exports.IsUndefined(right) ? ExtendsResult.True : ExtendsResult.False;
1954
+ }
1955
+ function FromUnionRight(left, right) {
1956
+ return right.anyOf.some((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
1957
+ }
1958
+ function FromUnion6(left, right) {
1959
+ return left.anyOf.every((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
1960
+ }
1961
+ function FromUnknownRight(left, right) {
1962
+ return ExtendsResult.True;
1963
+ }
1964
+ function FromUnknown(left, right) {
1965
+ return type_exports.IsNever(right) ? FromNeverRight() : type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsAny(right) ? FromAnyRight() : type_exports.IsString(right) ? FromStringRight(left) : type_exports.IsNumber(right) ? FromNumberRight(left) : type_exports.IsInteger(right) ? FromIntegerRight(left) : type_exports.IsBoolean(right) ? FromBooleanRight(left) : type_exports.IsArray(right) ? FromArrayRight(left) : type_exports.IsTuple(right) ? FromTupleRight(left) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsUnknown(right) ? ExtendsResult.True : ExtendsResult.False;
1966
+ }
1967
+ function FromVoidRight(left, right) {
1968
+ return type_exports.IsUndefined(left) ? ExtendsResult.True : type_exports.IsUndefined(left) ? ExtendsResult.True : ExtendsResult.False;
1969
+ }
1970
+ function FromVoid(left, right) {
1971
+ return type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsUnknown(right) ? FromUnknownRight() : type_exports.IsAny(right) ? FromAnyRight() : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsVoid(right) ? ExtendsResult.True : ExtendsResult.False;
1972
+ }
1973
+ function Visit3(left, right) {
1974
+ return (
1975
+ // resolvable
1976
+ type_exports.IsTemplateLiteral(left) || type_exports.IsTemplateLiteral(right) ? FromTemplateLiteral2(left, right) : type_exports.IsRegExp(left) || type_exports.IsRegExp(right) ? FromRegExp(left, right) : type_exports.IsNot(left) || type_exports.IsNot(right) ? FromNot(left, right) : (
1977
+ // standard
1978
+ type_exports.IsAny(left) ? FromAny(left, right) : type_exports.IsArray(left) ? FromArray4(left, right) : type_exports.IsBigInt(left) ? FromBigInt(left, right) : type_exports.IsBoolean(left) ? FromBoolean(left, right) : type_exports.IsAsyncIterator(left) ? FromAsyncIterator(left, right) : type_exports.IsConstructor(left) ? FromConstructor(left, right) : type_exports.IsDate(left) ? FromDate(left, right) : type_exports.IsFunction(left) ? FromFunction(left, right) : type_exports.IsInteger(left) ? FromInteger(left, right) : type_exports.IsIntersect(left) ? FromIntersect4(left, right) : type_exports.IsIterator(left) ? FromIterator(left, right) : type_exports.IsLiteral(left) ? FromLiteral2(left, right) : type_exports.IsNever(left) ? FromNever() : type_exports.IsNull(left) ? FromNull(left, right) : type_exports.IsNumber(left) ? FromNumber(left, right) : type_exports.IsObject(left) ? FromObject(left, right) : type_exports.IsRecord(left) ? FromRecord(left, right) : type_exports.IsString(left) ? FromString(left, right) : type_exports.IsSymbol(left) ? FromSymbol(left, right) : type_exports.IsTuple(left) ? FromTuple3(left, right) : type_exports.IsPromise(left) ? FromPromise2(left, right) : type_exports.IsUint8Array(left) ? FromUint8Array(left, right) : type_exports.IsUndefined(left) ? FromUndefined(left, right) : type_exports.IsUnion(left) ? FromUnion6(left, right) : type_exports.IsUnknown(left) ? FromUnknown(left, right) : type_exports.IsVoid(left) ? FromVoid(left, right) : Throw(`Unknown left type operand '${left[Kind]}'`)
1979
+ )
1980
+ );
1981
+ }
1982
+ function ExtendsCheck(left, right) {
1983
+ return Visit3(left, right);
1984
+ }
1985
+
1986
+ // node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-result.mjs
1987
+ function FromProperties8(P, Right, True, False, options) {
1988
+ const Acc = {};
1989
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
1990
+ Acc[K2] = Extends(P[K2], Right, True, False, Clone(options));
1991
+ return Acc;
1992
+ }
1993
+ function FromMappedResult6(Left, Right, True, False, options) {
1994
+ return FromProperties8(Left.properties, Right, True, False, options);
1995
+ }
1996
+ function ExtendsFromMappedResult(Left, Right, True, False, options) {
1997
+ const P = FromMappedResult6(Left, Right, True, False, options);
1998
+ return MappedResult(P);
1999
+ }
2000
+
2001
+ // node_modules/@sinclair/typebox/build/esm/type/extends/extends.mjs
2002
+ function ExtendsResolve(left, right, trueType, falseType) {
2003
+ const R = ExtendsCheck(left, right);
2004
+ return R === ExtendsResult.Union ? Union([trueType, falseType]) : R === ExtendsResult.True ? trueType : falseType;
2005
+ }
2006
+ function Extends(L, R, T, F, options) {
2007
+ return IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) : IsMappedKey(L) ? CreateType(ExtendsFromMappedKey(L, R, T, F, options)) : CreateType(ExtendsResolve(L, R, T, F), options);
2008
+ }
2009
+
2010
+ // node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-key.mjs
2011
+ function FromPropertyKey(K, U, L, R, options) {
2012
+ return {
2013
+ [K]: Extends(Literal(K), U, L, R, Clone(options))
2014
+ };
2015
+ }
2016
+ function FromPropertyKeys(K, U, L, R, options) {
2017
+ return K.reduce((Acc, LK) => {
2018
+ return { ...Acc, ...FromPropertyKey(LK, U, L, R, options) };
2019
+ }, {});
2020
+ }
2021
+ function FromMappedKey2(K, U, L, R, options) {
2022
+ return FromPropertyKeys(K.keys, U, L, R, options);
2023
+ }
2024
+ function ExtendsFromMappedKey(T, U, L, R, options) {
2025
+ const P = FromMappedKey2(T, U, L, R, options);
2026
+ return MappedResult(P);
2027
+ }
2028
+
2029
+ // node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-template-literal.mjs
2030
+ function ExcludeFromTemplateLiteral(L, R) {
2031
+ return Exclude(TemplateLiteralToUnion(L), R);
2032
+ }
2033
+
2034
+ // node_modules/@sinclair/typebox/build/esm/type/exclude/exclude.mjs
2035
+ function ExcludeRest(L, R) {
2036
+ const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False);
2037
+ return excluded.length === 1 ? excluded[0] : Union(excluded);
2038
+ }
2039
+ function Exclude(L, R, options = {}) {
2040
+ if (IsTemplateLiteral(L))
2041
+ return CreateType(ExcludeFromTemplateLiteral(L, R), options);
2042
+ if (IsMappedResult(L))
2043
+ return CreateType(ExcludeFromMappedResult(L, R), options);
2044
+ return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
2045
+ }
2046
+
2047
+ // node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-mapped-result.mjs
2048
+ function FromProperties9(P, U) {
2049
+ const Acc = {};
2050
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2051
+ Acc[K2] = Exclude(P[K2], U);
2052
+ return Acc;
2053
+ }
2054
+ function FromMappedResult7(R, T) {
2055
+ return FromProperties9(R.properties, T);
2056
+ }
2057
+ function ExcludeFromMappedResult(R, T) {
2058
+ const P = FromMappedResult7(R, T);
2059
+ return MappedResult(P);
2060
+ }
2061
+
2062
+ // node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-template-literal.mjs
2063
+ function ExtractFromTemplateLiteral(L, R) {
2064
+ return Extract(TemplateLiteralToUnion(L), R);
2065
+ }
2066
+
2067
+ // node_modules/@sinclair/typebox/build/esm/type/extract/extract.mjs
2068
+ function ExtractRest(L, R) {
2069
+ const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False);
2070
+ return extracted.length === 1 ? extracted[0] : Union(extracted);
2071
+ }
2072
+ function Extract(L, R, options) {
2073
+ if (IsTemplateLiteral(L))
2074
+ return CreateType(ExtractFromTemplateLiteral(L, R), options);
2075
+ if (IsMappedResult(L))
2076
+ return CreateType(ExtractFromMappedResult(L, R), options);
2077
+ return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
2078
+ }
2079
+
2080
+ // node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-mapped-result.mjs
2081
+ function FromProperties10(P, T) {
2082
+ const Acc = {};
2083
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2084
+ Acc[K2] = Extract(P[K2], T);
2085
+ return Acc;
2086
+ }
2087
+ function FromMappedResult8(R, T) {
2088
+ return FromProperties10(R.properties, T);
2089
+ }
2090
+ function ExtractFromMappedResult(R, T) {
2091
+ const P = FromMappedResult8(R, T);
2092
+ return MappedResult(P);
2093
+ }
2094
+
2095
+ // node_modules/@sinclair/typebox/build/esm/type/instance-type/instance-type.mjs
2096
+ function InstanceType(schema, options) {
2097
+ return IsConstructor(schema) ? CreateType(schema.returns, options) : Never(options);
2098
+ }
2099
+
2100
+ // node_modules/@sinclair/typebox/build/esm/type/readonly-optional/readonly-optional.mjs
2101
+ function ReadonlyOptional(schema) {
2102
+ return Readonly(Optional(schema));
2103
+ }
2104
+
2105
+ // node_modules/@sinclair/typebox/build/esm/type/record/record.mjs
2106
+ function RecordCreateFromPattern(pattern, T, options) {
2107
+ return CreateType({ [Kind]: "Record", type: "object", patternProperties: { [pattern]: T } }, options);
2108
+ }
2109
+ function RecordCreateFromKeys(K, T, options) {
2110
+ const result = {};
2111
+ for (const K2 of K)
2112
+ result[K2] = T;
2113
+ return Object2(result, { ...options, [Hint]: "Record" });
2114
+ }
2115
+ function FromTemplateLiteralKey(K, T, options) {
2116
+ return IsTemplateLiteralFinite(K) ? RecordCreateFromKeys(IndexPropertyKeys(K), T, options) : RecordCreateFromPattern(K.pattern, T, options);
2117
+ }
2118
+ function FromUnionKey(key, type, options) {
2119
+ return RecordCreateFromKeys(IndexPropertyKeys(Union(key)), type, options);
2120
+ }
2121
+ function FromLiteralKey(key, type, options) {
2122
+ return RecordCreateFromKeys([key.toString()], type, options);
2123
+ }
2124
+ function FromRegExpKey(key, type, options) {
2125
+ return RecordCreateFromPattern(key.source, type, options);
2126
+ }
2127
+ function FromStringKey(key, type, options) {
2128
+ const pattern = IsUndefined(key.pattern) ? PatternStringExact : key.pattern;
2129
+ return RecordCreateFromPattern(pattern, type, options);
2130
+ }
2131
+ function FromAnyKey(_, type, options) {
2132
+ return RecordCreateFromPattern(PatternStringExact, type, options);
2133
+ }
2134
+ function FromNeverKey(_key, type, options) {
2135
+ return RecordCreateFromPattern(PatternNeverExact, type, options);
2136
+ }
2137
+ function FromBooleanKey(_key, type, options) {
2138
+ return Object2({ true: type, false: type }, options);
2139
+ }
2140
+ function FromIntegerKey(_key, type, options) {
2141
+ return RecordCreateFromPattern(PatternNumberExact, type, options);
2142
+ }
2143
+ function FromNumberKey(_, type, options) {
2144
+ return RecordCreateFromPattern(PatternNumberExact, type, options);
2145
+ }
2146
+ function Record(key, type, options = {}) {
2147
+ return IsUnion(key) ? FromUnionKey(key.anyOf, type, options) : IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) : IsLiteral(key) ? FromLiteralKey(key.const, type, options) : IsBoolean2(key) ? FromBooleanKey(key, type, options) : IsInteger(key) ? FromIntegerKey(key, type, options) : IsNumber3(key) ? FromNumberKey(key, type, options) : IsRegExp2(key) ? FromRegExpKey(key, type, options) : IsString2(key) ? FromStringKey(key, type, options) : IsAny(key) ? FromAnyKey(key, type, options) : IsNever(key) ? FromNeverKey(key, type, options) : Never(options);
2148
+ }
2149
+ function RecordPattern(record) {
2150
+ return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
2151
+ }
2152
+ function RecordKey2(type) {
2153
+ const pattern = RecordPattern(type);
2154
+ return pattern === PatternStringExact ? String2() : pattern === PatternNumberExact ? Number2() : String2({ pattern });
2155
+ }
2156
+ function RecordValue2(type) {
2157
+ return type.patternProperties[RecordPattern(type)];
2158
+ }
2159
+
2160
+ // node_modules/@sinclair/typebox/build/esm/type/instantiate/instantiate.mjs
2161
+ function FromConstructor2(args, type) {
2162
+ type.parameters = FromTypes(args, type.parameters);
2163
+ type.returns = FromType(args, type.returns);
2164
+ return type;
2165
+ }
2166
+ function FromFunction2(args, type) {
2167
+ type.parameters = FromTypes(args, type.parameters);
2168
+ type.returns = FromType(args, type.returns);
2169
+ return type;
2170
+ }
2171
+ function FromIntersect5(args, type) {
2172
+ type.allOf = FromTypes(args, type.allOf);
2173
+ return type;
2174
+ }
2175
+ function FromUnion7(args, type) {
2176
+ type.anyOf = FromTypes(args, type.anyOf);
2177
+ return type;
2178
+ }
2179
+ function FromTuple4(args, type) {
2180
+ if (IsUndefined(type.items))
2181
+ return type;
2182
+ type.items = FromTypes(args, type.items);
2183
+ return type;
2184
+ }
2185
+ function FromArray5(args, type) {
2186
+ type.items = FromType(args, type.items);
2187
+ return type;
2188
+ }
2189
+ function FromAsyncIterator2(args, type) {
2190
+ type.items = FromType(args, type.items);
2191
+ return type;
2192
+ }
2193
+ function FromIterator2(args, type) {
2194
+ type.items = FromType(args, type.items);
2195
+ return type;
2196
+ }
2197
+ function FromPromise3(args, type) {
2198
+ type.item = FromType(args, type.item);
2199
+ return type;
2200
+ }
2201
+ function FromObject2(args, type) {
2202
+ const mappedProperties = FromProperties11(args, type.properties);
2203
+ return { ...type, ...Object2(mappedProperties) };
2204
+ }
2205
+ function FromRecord2(args, type) {
2206
+ const mappedKey = FromType(args, RecordKey2(type));
2207
+ const mappedValue = FromType(args, RecordValue2(type));
2208
+ const result = Record(mappedKey, mappedValue);
2209
+ return { ...type, ...result };
2210
+ }
2211
+ function FromArgument(args, argument) {
2212
+ return argument.index in args ? args[argument.index] : Unknown();
2213
+ }
2214
+ function FromProperty2(args, type) {
2215
+ const isReadonly = IsReadonly(type);
2216
+ const isOptional = IsOptional(type);
2217
+ const mapped = FromType(args, type);
2218
+ return isReadonly && isOptional ? ReadonlyOptional(mapped) : isReadonly && !isOptional ? Readonly(mapped) : !isReadonly && isOptional ? Optional(mapped) : mapped;
2219
+ }
2220
+ function FromProperties11(args, properties) {
2221
+ return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
2222
+ return { ...result, [key]: FromProperty2(args, properties[key]) };
2223
+ }, {});
2224
+ }
2225
+ function FromTypes(args, types) {
2226
+ return types.map((type) => FromType(args, type));
2227
+ }
2228
+ function FromType(args, type) {
2229
+ return IsConstructor(type) ? FromConstructor2(args, type) : IsFunction2(type) ? FromFunction2(args, type) : IsIntersect(type) ? FromIntersect5(args, type) : IsUnion(type) ? FromUnion7(args, type) : IsTuple(type) ? FromTuple4(args, type) : IsArray3(type) ? FromArray5(args, type) : IsAsyncIterator2(type) ? FromAsyncIterator2(args, type) : IsIterator2(type) ? FromIterator2(args, type) : IsPromise(type) ? FromPromise3(args, type) : IsObject3(type) ? FromObject2(args, type) : IsRecord(type) ? FromRecord2(args, type) : IsArgument(type) ? FromArgument(args, type) : type;
2230
+ }
2231
+ function Instantiate(type, args) {
2232
+ return FromType(args, CloneType(type));
2233
+ }
2234
+
2235
+ // node_modules/@sinclair/typebox/build/esm/type/integer/integer.mjs
2236
+ function Integer(options) {
2237
+ return CreateType({ [Kind]: "Integer", type: "integer" }, options);
2238
+ }
2239
+
2240
+ // node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs
2241
+ function MappedIntrinsicPropertyKey(K, M, options) {
2242
+ return {
2243
+ [K]: Intrinsic(Literal(K), M, Clone(options))
2244
+ };
2245
+ }
2246
+ function MappedIntrinsicPropertyKeys(K, M, options) {
2247
+ const result = K.reduce((Acc, L) => {
2248
+ return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
2249
+ }, {});
2250
+ return result;
2251
+ }
2252
+ function MappedIntrinsicProperties(T, M, options) {
2253
+ return MappedIntrinsicPropertyKeys(T["keys"], M, options);
2254
+ }
2255
+ function IntrinsicFromMappedKey(T, M, options) {
2256
+ const P = MappedIntrinsicProperties(T, M, options);
2257
+ return MappedResult(P);
2258
+ }
2259
+
2260
+ // node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic.mjs
2261
+ function ApplyUncapitalize(value) {
2262
+ const [first, rest] = [value.slice(0, 1), value.slice(1)];
2263
+ return [first.toLowerCase(), rest].join("");
2264
+ }
2265
+ function ApplyCapitalize(value) {
2266
+ const [first, rest] = [value.slice(0, 1), value.slice(1)];
2267
+ return [first.toUpperCase(), rest].join("");
2268
+ }
2269
+ function ApplyUppercase(value) {
2270
+ return value.toUpperCase();
2271
+ }
2272
+ function ApplyLowercase(value) {
2273
+ return value.toLowerCase();
2274
+ }
2275
+ function FromTemplateLiteral3(schema, mode, options) {
2276
+ const expression = TemplateLiteralParseExact(schema.pattern);
2277
+ const finite = IsTemplateLiteralExpressionFinite(expression);
2278
+ if (!finite)
2279
+ return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
2280
+ const strings = [...TemplateLiteralExpressionGenerate(expression)];
2281
+ const literals = strings.map((value) => Literal(value));
2282
+ const mapped = FromRest5(literals, mode);
2283
+ const union = Union(mapped);
2284
+ return TemplateLiteral([union], options);
2285
+ }
2286
+ function FromLiteralValue(value, mode) {
2287
+ return typeof value === "string" ? mode === "Uncapitalize" ? ApplyUncapitalize(value) : mode === "Capitalize" ? ApplyCapitalize(value) : mode === "Uppercase" ? ApplyUppercase(value) : mode === "Lowercase" ? ApplyLowercase(value) : value : value.toString();
2288
+ }
2289
+ function FromRest5(T, M) {
2290
+ return T.map((L) => Intrinsic(L, M));
2291
+ }
2292
+ function Intrinsic(schema, mode, options = {}) {
2293
+ return (
2294
+ // Intrinsic-Mapped-Inference
2295
+ IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) : (
2296
+ // Standard-Inference
2297
+ IsTemplateLiteral(schema) ? FromTemplateLiteral3(schema, mode, options) : IsUnion(schema) ? Union(FromRest5(schema.anyOf, mode), options) : IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) : (
2298
+ // Default Type
2299
+ CreateType(schema, options)
2300
+ )
2301
+ )
2302
+ );
2303
+ }
2304
+
2305
+ // node_modules/@sinclair/typebox/build/esm/type/intrinsic/capitalize.mjs
2306
+ function Capitalize(T, options = {}) {
2307
+ return Intrinsic(T, "Capitalize", options);
2308
+ }
2309
+
2310
+ // node_modules/@sinclair/typebox/build/esm/type/intrinsic/lowercase.mjs
2311
+ function Lowercase(T, options = {}) {
2312
+ return Intrinsic(T, "Lowercase", options);
2313
+ }
2314
+
2315
+ // node_modules/@sinclair/typebox/build/esm/type/intrinsic/uncapitalize.mjs
2316
+ function Uncapitalize(T, options = {}) {
2317
+ return Intrinsic(T, "Uncapitalize", options);
2318
+ }
2319
+
2320
+ // node_modules/@sinclair/typebox/build/esm/type/intrinsic/uppercase.mjs
2321
+ function Uppercase(T, options = {}) {
2322
+ return Intrinsic(T, "Uppercase", options);
2323
+ }
2324
+
2325
+ // node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-result.mjs
2326
+ function FromProperties12(properties, propertyKeys, options) {
2327
+ const result = {};
2328
+ for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
2329
+ result[K2] = Omit(properties[K2], propertyKeys, Clone(options));
2330
+ return result;
2331
+ }
2332
+ function FromMappedResult9(mappedResult, propertyKeys, options) {
2333
+ return FromProperties12(mappedResult.properties, propertyKeys, options);
2334
+ }
2335
+ function OmitFromMappedResult(mappedResult, propertyKeys, options) {
2336
+ const properties = FromMappedResult9(mappedResult, propertyKeys, options);
2337
+ return MappedResult(properties);
2338
+ }
2339
+
2340
+ // node_modules/@sinclair/typebox/build/esm/type/omit/omit.mjs
2341
+ function FromIntersect6(types, propertyKeys) {
2342
+ return types.map((type) => OmitResolve(type, propertyKeys));
2343
+ }
2344
+ function FromUnion8(types, propertyKeys) {
2345
+ return types.map((type) => OmitResolve(type, propertyKeys));
2346
+ }
2347
+ function FromProperty3(properties, key) {
2348
+ const { [key]: _, ...R } = properties;
2349
+ return R;
2350
+ }
2351
+ function FromProperties13(properties, propertyKeys) {
2352
+ return propertyKeys.reduce((T, K2) => FromProperty3(T, K2), properties);
2353
+ }
2354
+ function FromObject3(type, propertyKeys, properties) {
2355
+ const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2356
+ const mappedProperties = FromProperties13(properties, propertyKeys);
2357
+ return Object2(mappedProperties, options);
2358
+ }
2359
+ function UnionFromPropertyKeys(propertyKeys) {
2360
+ const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
2361
+ return Union(result);
2362
+ }
2363
+ function OmitResolve(type, propertyKeys) {
2364
+ return IsIntersect(type) ? Intersect(FromIntersect6(type.allOf, propertyKeys)) : IsUnion(type) ? Union(FromUnion8(type.anyOf, propertyKeys)) : IsObject3(type) ? FromObject3(type, propertyKeys, type.properties) : Object2({});
2365
+ }
2366
+ function Omit(type, key, options) {
2367
+ const typeKey = IsArray(key) ? UnionFromPropertyKeys(key) : key;
2368
+ const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
2369
+ const isTypeRef = IsRef(type);
2370
+ const isKeyRef = IsRef(key);
2371
+ return IsMappedResult(type) ? OmitFromMappedResult(type, propertyKeys, options) : IsMappedKey(key) ? OmitFromMappedKey(type, key, options) : isTypeRef && isKeyRef ? Computed("Omit", [type, typeKey], options) : !isTypeRef && isKeyRef ? Computed("Omit", [type, typeKey], options) : isTypeRef && !isKeyRef ? Computed("Omit", [type, typeKey], options) : CreateType({ ...OmitResolve(type, propertyKeys), ...options });
2372
+ }
2373
+
2374
+ // node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-key.mjs
2375
+ function FromPropertyKey2(type, key, options) {
2376
+ return { [key]: Omit(type, [key], Clone(options)) };
2377
+ }
2378
+ function FromPropertyKeys2(type, propertyKeys, options) {
2379
+ return propertyKeys.reduce((Acc, LK) => {
2380
+ return { ...Acc, ...FromPropertyKey2(type, LK, options) };
2381
+ }, {});
2382
+ }
2383
+ function FromMappedKey3(type, mappedKey, options) {
2384
+ return FromPropertyKeys2(type, mappedKey.keys, options);
2385
+ }
2386
+ function OmitFromMappedKey(type, mappedKey, options) {
2387
+ const properties = FromMappedKey3(type, mappedKey, options);
2388
+ return MappedResult(properties);
2389
+ }
2390
+
2391
+ // node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-result.mjs
2392
+ function FromProperties14(properties, propertyKeys, options) {
2393
+ const result = {};
2394
+ for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
2395
+ result[K2] = Pick(properties[K2], propertyKeys, Clone(options));
2396
+ return result;
2397
+ }
2398
+ function FromMappedResult10(mappedResult, propertyKeys, options) {
2399
+ return FromProperties14(mappedResult.properties, propertyKeys, options);
2400
+ }
2401
+ function PickFromMappedResult(mappedResult, propertyKeys, options) {
2402
+ const properties = FromMappedResult10(mappedResult, propertyKeys, options);
2403
+ return MappedResult(properties);
2404
+ }
2405
+
2406
+ // node_modules/@sinclair/typebox/build/esm/type/pick/pick.mjs
2407
+ function FromIntersect7(types, propertyKeys) {
2408
+ return types.map((type) => PickResolve(type, propertyKeys));
2409
+ }
2410
+ function FromUnion9(types, propertyKeys) {
2411
+ return types.map((type) => PickResolve(type, propertyKeys));
2412
+ }
2413
+ function FromProperties15(properties, propertyKeys) {
2414
+ const result = {};
2415
+ for (const K2 of propertyKeys)
2416
+ if (K2 in properties)
2417
+ result[K2] = properties[K2];
2418
+ return result;
2419
+ }
2420
+ function FromObject4(Type2, keys, properties) {
2421
+ const options = Discard(Type2, [TransformKind, "$id", "required", "properties"]);
2422
+ const mappedProperties = FromProperties15(properties, keys);
2423
+ return Object2(mappedProperties, options);
2424
+ }
2425
+ function UnionFromPropertyKeys2(propertyKeys) {
2426
+ const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
2427
+ return Union(result);
2428
+ }
2429
+ function PickResolve(type, propertyKeys) {
2430
+ return IsIntersect(type) ? Intersect(FromIntersect7(type.allOf, propertyKeys)) : IsUnion(type) ? Union(FromUnion9(type.anyOf, propertyKeys)) : IsObject3(type) ? FromObject4(type, propertyKeys, type.properties) : Object2({});
2431
+ }
2432
+ function Pick(type, key, options) {
2433
+ const typeKey = IsArray(key) ? UnionFromPropertyKeys2(key) : key;
2434
+ const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
2435
+ const isTypeRef = IsRef(type);
2436
+ const isKeyRef = IsRef(key);
2437
+ return IsMappedResult(type) ? PickFromMappedResult(type, propertyKeys, options) : IsMappedKey(key) ? PickFromMappedKey(type, key, options) : isTypeRef && isKeyRef ? Computed("Pick", [type, typeKey], options) : !isTypeRef && isKeyRef ? Computed("Pick", [type, typeKey], options) : isTypeRef && !isKeyRef ? Computed("Pick", [type, typeKey], options) : CreateType({ ...PickResolve(type, propertyKeys), ...options });
2438
+ }
2439
+
2440
+ // node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-key.mjs
2441
+ function FromPropertyKey3(type, key, options) {
2442
+ return {
2443
+ [key]: Pick(type, [key], Clone(options))
2444
+ };
2445
+ }
2446
+ function FromPropertyKeys3(type, propertyKeys, options) {
2447
+ return propertyKeys.reduce((result, leftKey) => {
2448
+ return { ...result, ...FromPropertyKey3(type, leftKey, options) };
2449
+ }, {});
2450
+ }
2451
+ function FromMappedKey4(type, mappedKey, options) {
2452
+ return FromPropertyKeys3(type, mappedKey.keys, options);
2453
+ }
2454
+ function PickFromMappedKey(type, mappedKey, options) {
2455
+ const properties = FromMappedKey4(type, mappedKey, options);
2456
+ return MappedResult(properties);
2457
+ }
2458
+
2459
+ // node_modules/@sinclair/typebox/build/esm/type/partial/partial.mjs
2460
+ function FromComputed3(target, parameters) {
2461
+ return Computed("Partial", [Computed(target, parameters)]);
2462
+ }
2463
+ function FromRef3($ref) {
2464
+ return Computed("Partial", [Ref($ref)]);
2465
+ }
2466
+ function FromProperties16(properties) {
2467
+ const partialProperties = {};
2468
+ for (const K of globalThis.Object.getOwnPropertyNames(properties))
2469
+ partialProperties[K] = Optional(properties[K]);
2470
+ return partialProperties;
2471
+ }
2472
+ function FromObject5(type, properties) {
2473
+ const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2474
+ const mappedProperties = FromProperties16(properties);
2475
+ return Object2(mappedProperties, options);
2476
+ }
2477
+ function FromRest6(types) {
2478
+ return types.map((type) => PartialResolve(type));
2479
+ }
2480
+ function PartialResolve(type) {
2481
+ return (
2482
+ // Mappable
2483
+ IsComputed(type) ? FromComputed3(type.target, type.parameters) : IsRef(type) ? FromRef3(type.$ref) : IsIntersect(type) ? Intersect(FromRest6(type.allOf)) : IsUnion(type) ? Union(FromRest6(type.anyOf)) : IsObject3(type) ? FromObject5(type, type.properties) : (
2484
+ // Intrinsic
2485
+ IsBigInt2(type) ? type : IsBoolean2(type) ? type : IsInteger(type) ? type : IsLiteral(type) ? type : IsNull2(type) ? type : IsNumber3(type) ? type : IsString2(type) ? type : IsSymbol2(type) ? type : IsUndefined3(type) ? type : (
2486
+ // Passthrough
2487
+ Object2({})
2488
+ )
2489
+ )
2490
+ );
2491
+ }
2492
+ function Partial(type, options) {
2493
+ if (IsMappedResult(type)) {
2494
+ return PartialFromMappedResult(type, options);
2495
+ } else {
2496
+ return CreateType({ ...PartialResolve(type), ...options });
2497
+ }
2498
+ }
2499
+
2500
+ // node_modules/@sinclair/typebox/build/esm/type/partial/partial-from-mapped-result.mjs
2501
+ function FromProperties17(K, options) {
2502
+ const Acc = {};
2503
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
2504
+ Acc[K2] = Partial(K[K2], Clone(options));
2505
+ return Acc;
2506
+ }
2507
+ function FromMappedResult11(R, options) {
2508
+ return FromProperties17(R.properties, options);
2509
+ }
2510
+ function PartialFromMappedResult(R, options) {
2511
+ const P = FromMappedResult11(R, options);
2512
+ return MappedResult(P);
2513
+ }
2514
+
2515
+ // node_modules/@sinclair/typebox/build/esm/type/required/required.mjs
2516
+ function FromComputed4(target, parameters) {
2517
+ return Computed("Required", [Computed(target, parameters)]);
2518
+ }
2519
+ function FromRef4($ref) {
2520
+ return Computed("Required", [Ref($ref)]);
2521
+ }
2522
+ function FromProperties18(properties) {
2523
+ const requiredProperties = {};
2524
+ for (const K of globalThis.Object.getOwnPropertyNames(properties))
2525
+ requiredProperties[K] = Discard(properties[K], [OptionalKind]);
2526
+ return requiredProperties;
2527
+ }
2528
+ function FromObject6(type, properties) {
2529
+ const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2530
+ const mappedProperties = FromProperties18(properties);
2531
+ return Object2(mappedProperties, options);
2532
+ }
2533
+ function FromRest7(types) {
2534
+ return types.map((type) => RequiredResolve(type));
2535
+ }
2536
+ function RequiredResolve(type) {
2537
+ return (
2538
+ // Mappable
2539
+ IsComputed(type) ? FromComputed4(type.target, type.parameters) : IsRef(type) ? FromRef4(type.$ref) : IsIntersect(type) ? Intersect(FromRest7(type.allOf)) : IsUnion(type) ? Union(FromRest7(type.anyOf)) : IsObject3(type) ? FromObject6(type, type.properties) : (
2540
+ // Intrinsic
2541
+ IsBigInt2(type) ? type : IsBoolean2(type) ? type : IsInteger(type) ? type : IsLiteral(type) ? type : IsNull2(type) ? type : IsNumber3(type) ? type : IsString2(type) ? type : IsSymbol2(type) ? type : IsUndefined3(type) ? type : (
2542
+ // Passthrough
2543
+ Object2({})
2544
+ )
2545
+ )
2546
+ );
2547
+ }
2548
+ function Required(type, options) {
2549
+ if (IsMappedResult(type)) {
2550
+ return RequiredFromMappedResult(type, options);
2551
+ } else {
2552
+ return CreateType({ ...RequiredResolve(type), ...options });
2553
+ }
2554
+ }
2555
+
2556
+ // node_modules/@sinclair/typebox/build/esm/type/required/required-from-mapped-result.mjs
2557
+ function FromProperties19(P, options) {
2558
+ const Acc = {};
2559
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2560
+ Acc[K2] = Required(P[K2], options);
2561
+ return Acc;
2562
+ }
2563
+ function FromMappedResult12(R, options) {
2564
+ return FromProperties19(R.properties, options);
2565
+ }
2566
+ function RequiredFromMappedResult(R, options) {
2567
+ const P = FromMappedResult12(R, options);
2568
+ return MappedResult(P);
2569
+ }
2570
+
2571
+ // node_modules/@sinclair/typebox/build/esm/type/module/compute.mjs
2572
+ function DereferenceParameters(moduleProperties, types) {
2573
+ return types.map((type) => {
2574
+ return IsRef(type) ? Dereference(moduleProperties, type.$ref) : FromType2(moduleProperties, type);
2575
+ });
2576
+ }
2577
+ function Dereference(moduleProperties, ref) {
2578
+ return ref in moduleProperties ? IsRef(moduleProperties[ref]) ? Dereference(moduleProperties, moduleProperties[ref].$ref) : FromType2(moduleProperties, moduleProperties[ref]) : Never();
2579
+ }
2580
+ function FromAwaited(parameters) {
2581
+ return Awaited(parameters[0]);
2582
+ }
2583
+ function FromIndex(parameters) {
2584
+ return Index(parameters[0], parameters[1]);
2585
+ }
2586
+ function FromKeyOf(parameters) {
2587
+ return KeyOf(parameters[0]);
2588
+ }
2589
+ function FromPartial(parameters) {
2590
+ return Partial(parameters[0]);
2591
+ }
2592
+ function FromOmit(parameters) {
2593
+ return Omit(parameters[0], parameters[1]);
2594
+ }
2595
+ function FromPick(parameters) {
2596
+ return Pick(parameters[0], parameters[1]);
2597
+ }
2598
+ function FromRequired(parameters) {
2599
+ return Required(parameters[0]);
2600
+ }
2601
+ function FromComputed5(moduleProperties, target, parameters) {
2602
+ const dereferenced = DereferenceParameters(moduleProperties, parameters);
2603
+ return target === "Awaited" ? FromAwaited(dereferenced) : target === "Index" ? FromIndex(dereferenced) : target === "KeyOf" ? FromKeyOf(dereferenced) : target === "Partial" ? FromPartial(dereferenced) : target === "Omit" ? FromOmit(dereferenced) : target === "Pick" ? FromPick(dereferenced) : target === "Required" ? FromRequired(dereferenced) : Never();
2604
+ }
2605
+ function FromArray6(moduleProperties, type) {
2606
+ return Array2(FromType2(moduleProperties, type));
2607
+ }
2608
+ function FromAsyncIterator3(moduleProperties, type) {
2609
+ return AsyncIterator(FromType2(moduleProperties, type));
2610
+ }
2611
+ function FromConstructor3(moduleProperties, parameters, instanceType) {
2612
+ return Constructor(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, instanceType));
2613
+ }
2614
+ function FromFunction3(moduleProperties, parameters, returnType) {
2615
+ return Function(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, returnType));
2616
+ }
2617
+ function FromIntersect8(moduleProperties, types) {
2618
+ return Intersect(FromTypes2(moduleProperties, types));
2619
+ }
2620
+ function FromIterator3(moduleProperties, type) {
2621
+ return Iterator(FromType2(moduleProperties, type));
2622
+ }
2623
+ function FromObject7(moduleProperties, properties) {
2624
+ return Object2(globalThis.Object.keys(properties).reduce((result, key) => {
2625
+ return { ...result, [key]: FromType2(moduleProperties, properties[key]) };
2626
+ }, {}));
2627
+ }
2628
+ function FromRecord3(moduleProperties, type) {
2629
+ const [value, pattern] = [FromType2(moduleProperties, RecordValue2(type)), RecordPattern(type)];
2630
+ const result = CloneType(type);
2631
+ result.patternProperties[pattern] = value;
2632
+ return result;
2633
+ }
2634
+ function FromTransform(moduleProperties, transform) {
2635
+ return IsRef(transform) ? { ...Dereference(moduleProperties, transform.$ref), [TransformKind]: transform[TransformKind] } : transform;
2636
+ }
2637
+ function FromTuple5(moduleProperties, types) {
2638
+ return Tuple(FromTypes2(moduleProperties, types));
2639
+ }
2640
+ function FromUnion10(moduleProperties, types) {
2641
+ return Union(FromTypes2(moduleProperties, types));
2642
+ }
2643
+ function FromTypes2(moduleProperties, types) {
2644
+ return types.map((type) => FromType2(moduleProperties, type));
2645
+ }
2646
+ function FromType2(moduleProperties, type) {
2647
+ return (
2648
+ // Modifiers
2649
+ IsOptional(type) ? CreateType(FromType2(moduleProperties, Discard(type, [OptionalKind])), type) : IsReadonly(type) ? CreateType(FromType2(moduleProperties, Discard(type, [ReadonlyKind])), type) : (
2650
+ // Transform
2651
+ IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) : (
2652
+ // Types
2653
+ IsArray3(type) ? CreateType(FromArray6(moduleProperties, type.items), type) : IsAsyncIterator2(type) ? CreateType(FromAsyncIterator3(moduleProperties, type.items), type) : IsComputed(type) ? CreateType(FromComputed5(moduleProperties, type.target, type.parameters)) : IsConstructor(type) ? CreateType(FromConstructor3(moduleProperties, type.parameters, type.returns), type) : IsFunction2(type) ? CreateType(FromFunction3(moduleProperties, type.parameters, type.returns), type) : IsIntersect(type) ? CreateType(FromIntersect8(moduleProperties, type.allOf), type) : IsIterator2(type) ? CreateType(FromIterator3(moduleProperties, type.items), type) : IsObject3(type) ? CreateType(FromObject7(moduleProperties, type.properties), type) : IsRecord(type) ? CreateType(FromRecord3(moduleProperties, type)) : IsTuple(type) ? CreateType(FromTuple5(moduleProperties, type.items || []), type) : IsUnion(type) ? CreateType(FromUnion10(moduleProperties, type.anyOf), type) : type
2654
+ )
2655
+ )
2656
+ );
2657
+ }
2658
+ function ComputeType(moduleProperties, key) {
2659
+ return key in moduleProperties ? FromType2(moduleProperties, moduleProperties[key]) : Never();
2660
+ }
2661
+ function ComputeModuleProperties(moduleProperties) {
2662
+ return globalThis.Object.getOwnPropertyNames(moduleProperties).reduce((result, key) => {
2663
+ return { ...result, [key]: ComputeType(moduleProperties, key) };
2664
+ }, {});
2665
+ }
2666
+
2667
+ // node_modules/@sinclair/typebox/build/esm/type/module/module.mjs
2668
+ var TModule = class {
2669
+ constructor($defs) {
2670
+ const computed = ComputeModuleProperties($defs);
2671
+ const identified = this.WithIdentifiers(computed);
2672
+ this.$defs = identified;
2673
+ }
2674
+ /** `[Json]` Imports a Type by Key. */
2675
+ Import(key, options) {
2676
+ const $defs = { ...this.$defs, [key]: CreateType(this.$defs[key], options) };
2677
+ return CreateType({ [Kind]: "Import", $defs, $ref: key });
2678
+ }
2679
+ // prettier-ignore
2680
+ WithIdentifiers($defs) {
2681
+ return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
2682
+ return { ...result, [key]: { ...$defs[key], $id: key } };
2683
+ }, {});
2684
+ }
2685
+ };
2686
+ function Module(properties) {
2687
+ return new TModule(properties);
2688
+ }
2689
+
2690
+ // node_modules/@sinclair/typebox/build/esm/type/not/not.mjs
2691
+ function Not(type, options) {
2692
+ return CreateType({ [Kind]: "Not", not: type }, options);
2693
+ }
2694
+
2695
+ // node_modules/@sinclair/typebox/build/esm/type/parameters/parameters.mjs
2696
+ function Parameters(schema, options) {
2697
+ return IsFunction2(schema) ? Tuple(schema.parameters, options) : Never();
2698
+ }
2699
+
2700
+ // node_modules/@sinclair/typebox/build/esm/type/recursive/recursive.mjs
2701
+ var Ordinal = 0;
2702
+ function Recursive(callback, options = {}) {
2703
+ if (IsUndefined(options.$id))
2704
+ options.$id = `T${Ordinal++}`;
2705
+ const thisType = CloneType(callback({ [Kind]: "This", $ref: `${options.$id}` }));
2706
+ thisType.$id = options.$id;
2707
+ return CreateType({ [Hint]: "Recursive", ...thisType }, options);
2708
+ }
2709
+
2710
+ // node_modules/@sinclair/typebox/build/esm/type/regexp/regexp.mjs
2711
+ function RegExp2(unresolved, options) {
2712
+ const expr = IsString(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
2713
+ return CreateType({ [Kind]: "RegExp", type: "RegExp", source: expr.source, flags: expr.flags }, options);
2714
+ }
2715
+
2716
+ // node_modules/@sinclair/typebox/build/esm/type/rest/rest.mjs
2717
+ function RestResolve(T) {
2718
+ return IsIntersect(T) ? T.allOf : IsUnion(T) ? T.anyOf : IsTuple(T) ? T.items ?? [] : [];
2719
+ }
2720
+ function Rest(T) {
2721
+ return RestResolve(T);
2722
+ }
2723
+
2724
+ // node_modules/@sinclair/typebox/build/esm/type/return-type/return-type.mjs
2725
+ function ReturnType(schema, options) {
2726
+ return IsFunction2(schema) ? CreateType(schema.returns, options) : Never(options);
2727
+ }
2728
+
2729
+ // node_modules/@sinclair/typebox/build/esm/type/transform/transform.mjs
2730
+ var TransformDecodeBuilder = class {
2731
+ constructor(schema) {
2732
+ this.schema = schema;
2733
+ }
2734
+ Decode(decode) {
2735
+ return new TransformEncodeBuilder(this.schema, decode);
2736
+ }
2737
+ };
2738
+ var TransformEncodeBuilder = class {
2739
+ constructor(schema, decode) {
2740
+ this.schema = schema;
2741
+ this.decode = decode;
2742
+ }
2743
+ EncodeTransform(encode, schema) {
2744
+ const Encode = (value) => schema[TransformKind].Encode(encode(value));
2745
+ const Decode = (value) => this.decode(schema[TransformKind].Decode(value));
2746
+ const Codec = { Encode, Decode };
2747
+ return { ...schema, [TransformKind]: Codec };
2748
+ }
2749
+ EncodeSchema(encode, schema) {
2750
+ const Codec = { Decode: this.decode, Encode: encode };
2751
+ return { ...schema, [TransformKind]: Codec };
2752
+ }
2753
+ Encode(encode) {
2754
+ return IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema);
2755
+ }
2756
+ };
2757
+ function Transform(schema) {
2758
+ return new TransformDecodeBuilder(schema);
2759
+ }
2760
+
2761
+ // node_modules/@sinclair/typebox/build/esm/type/unsafe/unsafe.mjs
2762
+ function Unsafe(options = {}) {
2763
+ return CreateType({ [Kind]: options[Kind] ?? "Unsafe" }, options);
2764
+ }
2765
+
2766
+ // node_modules/@sinclair/typebox/build/esm/type/void/void.mjs
2767
+ function Void(options) {
2768
+ return CreateType({ [Kind]: "Void", type: "void" }, options);
2769
+ }
2770
+
2771
+ // node_modules/@sinclair/typebox/build/esm/type/type/type.mjs
2772
+ var type_exports2 = {};
2773
+ __export(type_exports2, {
2774
+ Any: () => Any,
2775
+ Argument: () => Argument,
2776
+ Array: () => Array2,
2777
+ AsyncIterator: () => AsyncIterator,
2778
+ Awaited: () => Awaited,
2779
+ BigInt: () => BigInt,
2780
+ Boolean: () => Boolean,
2781
+ Capitalize: () => Capitalize,
2782
+ Composite: () => Composite,
2783
+ Const: () => Const,
2784
+ Constructor: () => Constructor,
2785
+ ConstructorParameters: () => ConstructorParameters,
2786
+ Date: () => Date2,
2787
+ Enum: () => Enum,
2788
+ Exclude: () => Exclude,
2789
+ Extends: () => Extends,
2790
+ Extract: () => Extract,
2791
+ Function: () => Function,
2792
+ Index: () => Index,
2793
+ InstanceType: () => InstanceType,
2794
+ Instantiate: () => Instantiate,
2795
+ Integer: () => Integer,
2796
+ Intersect: () => Intersect,
2797
+ Iterator: () => Iterator,
2798
+ KeyOf: () => KeyOf,
2799
+ Literal: () => Literal,
2800
+ Lowercase: () => Lowercase,
2801
+ Mapped: () => Mapped,
2802
+ Module: () => Module,
2803
+ Never: () => Never,
2804
+ Not: () => Not,
2805
+ Null: () => Null,
2806
+ Number: () => Number2,
2807
+ Object: () => Object2,
2808
+ Omit: () => Omit,
2809
+ Optional: () => Optional,
2810
+ Parameters: () => Parameters,
2811
+ Partial: () => Partial,
2812
+ Pick: () => Pick,
2813
+ Promise: () => Promise2,
2814
+ Readonly: () => Readonly,
2815
+ ReadonlyOptional: () => ReadonlyOptional,
2816
+ Record: () => Record,
2817
+ Recursive: () => Recursive,
2818
+ Ref: () => Ref,
2819
+ RegExp: () => RegExp2,
2820
+ Required: () => Required,
2821
+ Rest: () => Rest,
2822
+ ReturnType: () => ReturnType,
2823
+ String: () => String2,
2824
+ Symbol: () => Symbol2,
2825
+ TemplateLiteral: () => TemplateLiteral,
2826
+ Transform: () => Transform,
2827
+ Tuple: () => Tuple,
2828
+ Uint8Array: () => Uint8Array2,
2829
+ Uncapitalize: () => Uncapitalize,
2830
+ Undefined: () => Undefined,
2831
+ Union: () => Union,
2832
+ Unknown: () => Unknown,
2833
+ Unsafe: () => Unsafe,
2834
+ Uppercase: () => Uppercase,
2835
+ Void: () => Void
2836
+ });
2837
+
2838
+ // node_modules/@sinclair/typebox/build/esm/type/type/index.mjs
2839
+ var Type = type_exports2;
2840
+
2841
+ // src/tools.ts
2842
+ var publishFactTool = {
2843
+ name: "fact_bus_publish",
2844
+ description: "Publish a new fact to the Claw Fact Bus. Facts are immutable records that flow through the bus and can be sensed by other claws.",
2845
+ parameters: Type.Object({
2846
+ fact_type: Type.String({
2847
+ description: "Dot-notation fact type (e.g., 'code.review.needed', 'incident.latency.high')"
2848
+ }),
2849
+ payload: Type.Record(Type.String(), Type.Unknown(), {
2850
+ description: "Business data payload for this fact"
2851
+ }),
2852
+ semantic_kind: Type.Optional(
2853
+ Type.Union(
2854
+ [
2855
+ Type.Literal("observation"),
2856
+ Type.Literal("assertion"),
2857
+ Type.Literal("request"),
2858
+ Type.Literal("resolution"),
2859
+ Type.Literal("correction"),
2860
+ Type.Literal("signal")
2861
+ ],
2862
+ { description: "Semantic kind of this fact (default: observation)" }
2863
+ )
2864
+ ),
2865
+ priority: Type.Optional(
2866
+ Type.Number({
2867
+ minimum: 0,
2868
+ maximum: 7,
2869
+ description: "Priority 0-7 (lower = higher priority, default: 3)"
2870
+ })
2871
+ ),
2872
+ mode: Type.Optional(
2873
+ Type.Union(
2874
+ [Type.Literal("broadcast"), Type.Literal("exclusive")],
2875
+ {
2876
+ description: "broadcast = anyone can process; exclusive = must be claimed first (default: exclusive)"
2877
+ }
2878
+ )
2879
+ ),
2880
+ subject_key: Type.Optional(
2881
+ Type.String({
2882
+ description: "Groups facts about the same subject for knowledge evolution"
2883
+ })
2884
+ ),
2885
+ confidence: Type.Optional(
2886
+ Type.Number({
2887
+ minimum: 0,
2888
+ maximum: 1,
2889
+ description: "Publisher's confidence in this fact 0-1 (default: 1.0)"
2890
+ })
2891
+ ),
2892
+ ttl_seconds: Type.Optional(
2893
+ Type.Number({ description: "Time to live in seconds (default: 300, min: 10)" })
2894
+ ),
2895
+ domain_tags: Type.Optional(
2896
+ Type.Array(Type.String(), { description: "Domain labels for categorization" })
2897
+ ),
2898
+ need_capabilities: Type.Optional(
2899
+ Type.Array(Type.String(), {
2900
+ description: "Required capabilities to process this fact"
2901
+ })
2902
+ )
2903
+ }),
2904
+ async execute(_id, params, context) {
2905
+ const { client: client2, logger } = context;
2906
+ if (!client2.isConnected) {
2907
+ return {
2908
+ content: [
2909
+ {
2910
+ type: "text",
2911
+ text: "Error: Not connected to Fact Bus. Please check configuration."
2912
+ }
2913
+ ]
2914
+ };
2915
+ }
2916
+ logger.info("Publishing fact:", params.fact_type);
2917
+ const result = await client2.publishFact({
2918
+ fact_type: params.fact_type,
2919
+ payload: params.payload,
2920
+ semantic_kind: params.semantic_kind,
2921
+ priority: params.priority,
2922
+ mode: params.mode,
2923
+ subject_key: params.subject_key,
2924
+ confidence: params.confidence,
2925
+ ttl_seconds: params.ttl_seconds,
2926
+ domain_tags: params.domain_tags,
2927
+ need_capabilities: params.need_capabilities,
2928
+ source_claw_id: client2.currentClawId || ""
2929
+ });
2930
+ if (!result.success) {
2931
+ logger.error("Failed to publish fact:", result.error);
2932
+ return {
2933
+ content: [{ type: "text", text: `Failed to publish fact: ${result.error}` }]
2934
+ };
2935
+ }
2936
+ const fact = result.data;
2937
+ logger.info("Fact published:", fact.fact_id);
2938
+ return {
2939
+ content: [
2940
+ {
2941
+ type: "text",
2942
+ text: JSON.stringify(
2943
+ {
2944
+ success: true,
2945
+ fact_id: fact.fact_id,
2946
+ fact_type: fact.fact_type,
2947
+ state: fact.state,
2948
+ created_at: new Date(fact.created_at).toISOString()
2949
+ },
2950
+ null,
2951
+ 2
2952
+ )
2953
+ }
2954
+ ]
2955
+ };
2956
+ }
2957
+ };
2958
+ var queryFactsTool = {
2959
+ name: "fact_bus_query",
2960
+ description: "Query facts from the Claw Fact Bus. Can filter by type, state, and source.",
2961
+ parameters: Type.Object({
2962
+ fact_type: Type.Optional(
2963
+ Type.String({ description: "Filter by fact type" })
2964
+ ),
2965
+ state: Type.Optional(
2966
+ Type.Union(
2967
+ [
2968
+ Type.Literal("created"),
2969
+ Type.Literal("published"),
2970
+ Type.Literal("matched"),
2971
+ Type.Literal("claimed"),
2972
+ Type.Literal("processing"),
2973
+ Type.Literal("resolved"),
2974
+ Type.Literal("dead")
2975
+ ],
2976
+ { description: "Filter by workflow state" }
2977
+ )
2978
+ ),
2979
+ source_claw_id: Type.Optional(
2980
+ Type.String({ description: "Filter by source claw ID" })
2981
+ ),
2982
+ limit: Type.Optional(
2983
+ Type.Number({
2984
+ minimum: 1,
2985
+ maximum: 1e3,
2986
+ description: "Maximum number of facts to return (default: 100)"
2987
+ })
2988
+ )
2989
+ }),
2990
+ async execute(_id, params, context) {
2991
+ const { client: client2, logger } = context;
2992
+ logger.debug("Querying facts:", params);
2993
+ const result = await client2.queryFacts({
2994
+ fact_type: params.fact_type,
2995
+ state: params.state,
2996
+ source_claw_id: params.source_claw_id,
2997
+ limit: params.limit ?? 100
2998
+ });
2999
+ if (!result.success) {
3000
+ logger.error("Failed to query facts:", result.error);
3001
+ return {
3002
+ content: [{ type: "text", text: `Failed to query facts: ${result.error}` }]
3003
+ };
3004
+ }
3005
+ const facts = result.data;
3006
+ logger.info(`Found ${facts.length} facts`);
3007
+ const summary = facts.map((f) => ({
3008
+ fact_id: f.fact_id,
3009
+ fact_type: f.fact_type,
3010
+ state: f.state,
3011
+ confidence: f.confidence,
3012
+ created_at: new Date(f.created_at).toISOString(),
3013
+ subject_key: f.subject_key
3014
+ }));
3015
+ return {
3016
+ content: [
3017
+ {
3018
+ type: "text",
3019
+ text: JSON.stringify({ count: facts.length, facts: summary }, null, 2)
3020
+ }
3021
+ ]
3022
+ };
3023
+ }
3024
+ };
3025
+ var claimFactTool = {
3026
+ name: "fact_bus_claim",
3027
+ description: "Claim an exclusive fact for processing. Only one claw can claim a fact at a time.",
3028
+ parameters: Type.Object({
3029
+ fact_id: Type.String({ description: "The ID of the fact to claim" })
3030
+ }),
3031
+ async execute(_id, params, context) {
3032
+ const { client: client2, logger } = context;
3033
+ if (!client2.isConnected) {
3034
+ return {
3035
+ content: [
3036
+ { type: "text", text: "Error: Not connected to Fact Bus." }
3037
+ ]
3038
+ };
3039
+ }
3040
+ logger.info("Claiming fact:", params.fact_id);
3041
+ const result = await client2.claimFact(params.fact_id);
3042
+ if (!result.success) {
3043
+ logger.error("Failed to claim fact:", result.error);
3044
+ return {
3045
+ content: [{ type: "text", text: `Failed to claim fact: ${result.error}` }]
3046
+ };
3047
+ }
3048
+ logger.info("Fact claimed:", params.fact_id);
3049
+ return {
3050
+ content: [
3051
+ {
3052
+ type: "text",
3053
+ text: JSON.stringify(
3054
+ {
3055
+ success: true,
3056
+ fact_id: result.data.fact_id,
3057
+ claimed_by: result.data.claimed_by
3058
+ },
3059
+ null,
3060
+ 2
3061
+ )
3062
+ }
3063
+ ]
3064
+ };
3065
+ }
3066
+ };
3067
+ var releaseFactTool = {
3068
+ name: "fact_bus_release",
3069
+ description: "Release a claimed fact back to the pool. Use this if you cannot complete processing and want to let other claws claim it.",
3070
+ parameters: Type.Object({
3071
+ fact_id: Type.String({ description: "The ID of the fact to release" })
3072
+ }),
3073
+ async execute(_id, params, context) {
3074
+ const { client: client2, logger } = context;
3075
+ if (!client2.isConnected) {
3076
+ return {
3077
+ content: [
3078
+ { type: "text", text: "Error: Not connected to Fact Bus." }
3079
+ ]
3080
+ };
3081
+ }
3082
+ logger.info("Releasing fact:", params.fact_id);
3083
+ const result = await client2.releaseFact(params.fact_id);
3084
+ if (!result.success) {
3085
+ logger.error("Failed to release fact:", result.error);
3086
+ return {
3087
+ content: [{ type: "text", text: `Failed to release fact: ${result.error}` }]
3088
+ };
3089
+ }
3090
+ logger.info("Fact released:", params.fact_id);
3091
+ return {
3092
+ content: [
3093
+ {
3094
+ type: "text",
3095
+ text: JSON.stringify(
3096
+ {
3097
+ success: true,
3098
+ fact_id: result.data.fact_id
3099
+ },
3100
+ null,
3101
+ 2
3102
+ )
3103
+ }
3104
+ ]
3105
+ };
3106
+ }
3107
+ };
3108
+ var resolveFactTool = {
3109
+ name: "fact_bus_resolve",
3110
+ description: "Mark a claimed fact as resolved. Optionally emit child facts as results.",
3111
+ parameters: Type.Object({
3112
+ fact_id: Type.String({ description: "The ID of the fact to resolve" }),
3113
+ result_facts: Type.Optional(
3114
+ Type.Array(
3115
+ Type.Object({
3116
+ fact_type: Type.String(),
3117
+ payload: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
3118
+ domain_tags: Type.Optional(Type.Array(Type.String())),
3119
+ need_capabilities: Type.Optional(Type.Array(Type.String())),
3120
+ priority: Type.Optional(Type.Number()),
3121
+ mode: Type.Optional(Type.String())
3122
+ }),
3123
+ { description: "Optional child facts to emit as results" }
3124
+ )
3125
+ )
3126
+ }),
3127
+ async execute(_id, params, context) {
3128
+ const { client: client2, logger } = context;
3129
+ if (!client2.isConnected) {
3130
+ return {
3131
+ content: [{ type: "text", text: "Error: Not connected to Fact Bus." }]
3132
+ };
3133
+ }
3134
+ logger.info("Resolving fact:", params.fact_id);
3135
+ const result = await client2.resolveFact(params.fact_id, params.result_facts);
3136
+ if (!result.success) {
3137
+ logger.error("Failed to resolve fact:", result.error);
3138
+ return {
3139
+ content: [{ type: "text", text: `Failed to resolve fact: ${result.error}` }]
3140
+ };
3141
+ }
3142
+ logger.info("Fact resolved:", params.fact_id);
3143
+ return {
3144
+ content: [
3145
+ {
3146
+ type: "text",
3147
+ text: JSON.stringify(
3148
+ {
3149
+ success: true,
3150
+ fact_id: result.data.fact_id
3151
+ },
3152
+ null,
3153
+ 2
3154
+ )
3155
+ }
3156
+ ]
3157
+ };
3158
+ }
3159
+ };
3160
+ var validateFactTool = {
3161
+ name: "fact_bus_validate",
3162
+ description: "Corroborate or contradict a fact. Used for social validation and consensus building.",
3163
+ parameters: Type.Object({
3164
+ fact_id: Type.String({ description: "The ID of the fact to validate" }),
3165
+ action: Type.Union(
3166
+ [Type.Literal("corroborate"), Type.Literal("contradict")],
3167
+ { description: "corroborate = confirm; contradict = dispute" }
3168
+ )
3169
+ }),
3170
+ async execute(_id, params, context) {
3171
+ const { client: client2, logger } = context;
3172
+ if (!client2.isConnected) {
3173
+ return {
3174
+ content: [{ type: "text", text: "Error: Not connected to Fact Bus." }]
3175
+ };
3176
+ }
3177
+ logger.info(`${params.action} fact:`, params.fact_id);
3178
+ const result = params.action === "corroborate" ? await client2.corroborateFact(params.fact_id) : await client2.contradictFact(params.fact_id);
3179
+ if (!result.success) {
3180
+ logger.error(`Failed to ${params.action} fact:`, result.error);
3181
+ return {
3182
+ content: [
3183
+ { type: "text", text: `Failed to ${params.action} fact: ${result.error}` }
3184
+ ]
3185
+ };
3186
+ }
3187
+ logger.info(`Fact ${params.action}d:`, params.fact_id);
3188
+ return {
3189
+ content: [
3190
+ {
3191
+ type: "text",
3192
+ text: JSON.stringify(
3193
+ {
3194
+ success: true,
3195
+ fact_id: result.data.fact_id,
3196
+ action: params.action,
3197
+ epistemic_state: result.data.epistemic_state
3198
+ },
3199
+ null,
3200
+ 2
3201
+ )
3202
+ }
3203
+ ]
3204
+ };
3205
+ }
3206
+ };
3207
+ var factBusTools = [
3208
+ publishFactTool,
3209
+ queryFactsTool,
3210
+ claimFactTool,
3211
+ releaseFactTool,
3212
+ resolveFactTool,
3213
+ validateFactTool
3214
+ ];
3215
+
3216
+ // src/websocket.ts
3217
+ var WS_CONNECTING = 0;
3218
+ var WS_OPEN = 1;
3219
+ var WS_CLOSING = 2;
3220
+ var WS_CLOSED = 3;
3221
+ var FactBusWebSocketService = class {
3222
+ ws = null;
3223
+ client;
3224
+ config;
3225
+ logger;
3226
+ onEvent;
3227
+ reconnectTimer = null;
3228
+ heartbeatTimer = null;
3229
+ isConnecting = false;
3230
+ shouldReconnect = true;
3231
+ // Event handlers map for typed event handling
3232
+ eventHandlers = /* @__PURE__ */ new Map();
3233
+ // Connection state
3234
+ connectionAttempts = 0;
3235
+ maxConnectionAttempts = 10;
3236
+ lastConnectedAt = null;
3237
+ constructor(options) {
3238
+ this.client = options.client;
3239
+ this.config = options.config;
3240
+ this.logger = options.logger;
3241
+ this.onEvent = options.onEvent;
3242
+ }
3243
+ // ============ Event Subscription API ============
3244
+ /**
3245
+ * Subscribe to a specific event type
3246
+ */
3247
+ on(eventType, handler) {
3248
+ if (!this.eventHandlers.has(eventType)) {
3249
+ this.eventHandlers.set(eventType, /* @__PURE__ */ new Set());
3250
+ }
3251
+ const handlers = this.eventHandlers.get(eventType);
3252
+ handlers.add(handler);
3253
+ return () => {
3254
+ handlers.delete(handler);
3255
+ if (handlers.size === 0) {
3256
+ this.eventHandlers.delete(eventType);
3257
+ }
3258
+ };
3259
+ }
3260
+ /**
3261
+ * Subscribe to all events
3262
+ */
3263
+ onAll(handler) {
3264
+ return this.on("*", handler);
3265
+ }
3266
+ /**
3267
+ * Remove all handlers for an event type
3268
+ */
3269
+ off(eventType) {
3270
+ this.eventHandlers.delete(eventType);
3271
+ }
3272
+ // ============ Lifecycle ============
3273
+ async start() {
3274
+ if (!this.client.isConnected) {
3275
+ this.logger.warn("Cannot start WebSocket: client not connected");
3276
+ return;
3277
+ }
3278
+ this.shouldReconnect = this.config.autoReconnect ?? true;
3279
+ this.connectionAttempts = 0;
3280
+ await this.connect();
3281
+ }
3282
+ stop() {
3283
+ this.shouldReconnect = false;
3284
+ this.disconnect();
3285
+ this.eventHandlers.clear();
3286
+ }
3287
+ // ============ Connection Management ============
3288
+ async connect() {
3289
+ if (this.isConnecting || this.ws?.readyState === WS_OPEN) {
3290
+ return;
3291
+ }
3292
+ this.isConnecting = true;
3293
+ this.connectionAttempts++;
3294
+ try {
3295
+ const wsUrl = this.client.getWebSocketUrl();
3296
+ const clawId = this.client.currentClawId;
3297
+ if (!clawId) {
3298
+ this.logger.error("No claw ID available for WebSocket connection");
3299
+ this.isConnecting = false;
3300
+ return;
3301
+ }
3302
+ const wsEndpoint = `${wsUrl}/ws/${clawId}`;
3303
+ this.logger.info(`Connecting to WebSocket: ${wsEndpoint} (attempt ${this.connectionAttempts})`);
3304
+ const WebSocketImpl = await this.getWebSocketImpl();
3305
+ this.ws = new WebSocketImpl(wsEndpoint);
3306
+ this.setupEventHandlers();
3307
+ } catch (error) {
3308
+ this.logger.error("Failed to connect WebSocket:", error);
3309
+ this.isConnecting = false;
3310
+ this.scheduleReconnect();
3311
+ }
3312
+ }
3313
+ async getWebSocketImpl() {
3314
+ if (typeof WebSocket !== "undefined") {
3315
+ return WebSocket;
3316
+ }
3317
+ try {
3318
+ const wsModule = await import('./wrapper-MVER34YC.js');
3319
+ return wsModule.default || wsModule.WebSocket;
3320
+ } catch {
3321
+ throw new Error(
3322
+ "WebSocket is not available. Please install 'ws' package: npm install ws"
3323
+ );
3324
+ }
3325
+ }
3326
+ setupEventHandlers() {
3327
+ if (!this.ws) return;
3328
+ this.ws.onopen = () => {
3329
+ this.logger.info("WebSocket connected");
3330
+ this.isConnecting = false;
3331
+ this.connectionAttempts = 0;
3332
+ this.lastConnectedAt = Date.now();
3333
+ this.subscribe();
3334
+ this.startHeartbeat();
3335
+ };
3336
+ this.ws.onmessage = (event) => {
3337
+ this.handleMessage(event.data);
3338
+ };
3339
+ this.ws.onerror = (_error) => {
3340
+ this.logger.error("WebSocket error occurred");
3341
+ };
3342
+ this.ws.onclose = (event) => {
3343
+ this.logger.info(`WebSocket disconnected: code=${event.code}, reason=${event.reason}`);
3344
+ this.isConnecting = false;
3345
+ this.stopHeartbeat();
3346
+ this.ws = null;
3347
+ this.scheduleReconnect();
3348
+ };
3349
+ }
3350
+ handleMessage(data) {
3351
+ try {
3352
+ const message = JSON.parse(data);
3353
+ if (message.status === "subscribed") {
3354
+ this.logger.info("WebSocket subscribed:", message.claw_id);
3355
+ return;
3356
+ }
3357
+ if (message.type === "pong") {
3358
+ this.logger.debug("WebSocket pong received");
3359
+ return;
3360
+ }
3361
+ if (message.status === "filter_updated") {
3362
+ this.logger.debug("WebSocket filter updated");
3363
+ return;
3364
+ }
3365
+ if (message.error) {
3366
+ this.logger.error("WebSocket error from server:", message.error);
3367
+ return;
3368
+ }
3369
+ const busEvent = message;
3370
+ this.logger.debug(`WebSocket event: ${busEvent.event_type}`);
3371
+ this.dispatchEvent(busEvent);
3372
+ } catch (error) {
3373
+ this.logger.error("Failed to parse WebSocket message:", error);
3374
+ }
3375
+ }
3376
+ dispatchEvent(event) {
3377
+ this.onEvent?.(event);
3378
+ const handlers = this.eventHandlers.get(event.event_type);
3379
+ if (handlers) {
3380
+ for (const handler of handlers) {
3381
+ try {
3382
+ const result = handler(event);
3383
+ if (result instanceof Promise) {
3384
+ result.catch((err) => {
3385
+ this.logger.error(`Error in event handler for ${event.event_type}:`, err);
3386
+ });
3387
+ }
3388
+ } catch (err) {
3389
+ this.logger.error(`Error in event handler for ${event.event_type}:`, err);
3390
+ }
3391
+ }
3392
+ }
3393
+ const wildcardHandlers = this.eventHandlers.get("*");
3394
+ if (wildcardHandlers) {
3395
+ for (const handler of wildcardHandlers) {
3396
+ try {
3397
+ const result = handler(event);
3398
+ if (result instanceof Promise) {
3399
+ result.catch((err) => {
3400
+ this.logger.error("Error in wildcard event handler:", err);
3401
+ });
3402
+ }
3403
+ } catch (err) {
3404
+ this.logger.error("Error in wildcard event handler:", err);
3405
+ }
3406
+ }
3407
+ }
3408
+ }
3409
+ // ============ Subscription ============
3410
+ subscribe() {
3411
+ if (!this.ws || this.ws.readyState !== WS_OPEN) {
3412
+ return;
3413
+ }
3414
+ const subscribeRequest = {
3415
+ action: "subscribe",
3416
+ name: this.config.clawName,
3417
+ filter: {
3418
+ capability_offer: this.config.capabilityOffer || [],
3419
+ domain_interests: this.config.domainInterests || [],
3420
+ fact_type_patterns: this.config.factTypePatterns || [],
3421
+ priority_range: this.config.priorityRange || [0, 7],
3422
+ modes: this.config.modes?.map((m) => m) || ["exclusive", "broadcast"],
3423
+ exclude_superseded: true
3424
+ }
3425
+ };
3426
+ this.logger.debug("Subscribing with filter:", subscribeRequest.filter);
3427
+ this.ws.send(JSON.stringify(subscribeRequest));
3428
+ }
3429
+ // ============ Heartbeat ============
3430
+ startHeartbeat() {
3431
+ this.stopHeartbeat();
3432
+ this.heartbeatTimer = setInterval(() => {
3433
+ this.sendHeartbeat();
3434
+ }, 3e4);
3435
+ }
3436
+ stopHeartbeat() {
3437
+ if (this.heartbeatTimer) {
3438
+ clearInterval(this.heartbeatTimer);
3439
+ this.heartbeatTimer = null;
3440
+ }
3441
+ }
3442
+ sendHeartbeat() {
3443
+ if (!this.ws || this.ws.readyState !== WS_OPEN) {
3444
+ return;
3445
+ }
3446
+ this.ws.send(JSON.stringify({ action: "heartbeat" }));
3447
+ }
3448
+ // ============ Filter Management ============
3449
+ updateFilter(filter) {
3450
+ if (!this.ws || this.ws.readyState !== WS_OPEN) {
3451
+ return;
3452
+ }
3453
+ this.ws.send(JSON.stringify({ action: "update_filter", filter }));
3454
+ }
3455
+ // ============ Reconnection ============
3456
+ scheduleReconnect() {
3457
+ if (!this.shouldReconnect) {
3458
+ return;
3459
+ }
3460
+ if (this.connectionAttempts >= this.maxConnectionAttempts) {
3461
+ this.logger.error(
3462
+ `Max reconnection attempts (${this.maxConnectionAttempts}) reached. Stopping reconnection.`
3463
+ );
3464
+ return;
3465
+ }
3466
+ if (this.reconnectTimer) {
3467
+ clearTimeout(this.reconnectTimer);
3468
+ }
3469
+ const baseInterval = this.config.reconnectInterval ?? 5e3;
3470
+ const backoff = Math.min(baseInterval * Math.pow(2, this.connectionAttempts - 1), 6e4);
3471
+ const jitter = Math.random() * 1e3;
3472
+ const delay = backoff + jitter;
3473
+ this.logger.info(`Reconnecting in ${Math.round(delay)}ms...`);
3474
+ this.reconnectTimer = setTimeout(() => {
3475
+ this.connect();
3476
+ }, delay);
3477
+ }
3478
+ disconnect() {
3479
+ this.stopHeartbeat();
3480
+ if (this.reconnectTimer) {
3481
+ clearTimeout(this.reconnectTimer);
3482
+ this.reconnectTimer = null;
3483
+ }
3484
+ if (this.ws) {
3485
+ if (this.ws.readyState === WS_OPEN || this.ws.readyState === WS_CONNECTING) {
3486
+ this.ws.close(1e3, "Client disconnecting");
3487
+ }
3488
+ this.ws = null;
3489
+ }
3490
+ }
3491
+ // ============ Public API ============
3492
+ get isConnected() {
3493
+ return this.ws?.readyState === WS_OPEN;
3494
+ }
3495
+ get connectionState() {
3496
+ if (!this.ws) return "disconnected";
3497
+ switch (this.ws.readyState) {
3498
+ case WS_CONNECTING:
3499
+ return "connecting";
3500
+ case WS_OPEN:
3501
+ return "connected";
3502
+ case WS_CLOSING:
3503
+ return "disconnecting";
3504
+ case WS_CLOSED:
3505
+ default:
3506
+ return "disconnected";
3507
+ }
3508
+ }
3509
+ get stats() {
3510
+ return {
3511
+ connectionAttempts: this.connectionAttempts,
3512
+ lastConnectedAt: this.lastConnectedAt,
3513
+ isConnected: this.isConnected
3514
+ };
3515
+ }
3516
+ };
3517
+
3518
+ // index.ts
3519
+ var client = null;
3520
+ var wsService = null;
3521
+ var configSchema = {
3522
+ safeParse(value) {
3523
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
3524
+ return { success: false, error: { issues: [{ path: [], message: "config must be an object" }] } };
3525
+ }
3526
+ const cfg = value;
3527
+ if (typeof cfg.busUrl !== "string" || !cfg.busUrl) {
3528
+ return { success: false, error: { issues: [{ path: ["busUrl"], message: "busUrl is required" }] } };
3529
+ }
3530
+ const validConfig = {
3531
+ busUrl: cfg.busUrl,
3532
+ clawName: cfg.clawName,
3533
+ clawDescription: cfg.clawDescription,
3534
+ capabilityOffer: cfg.capabilityOffer,
3535
+ domainInterests: cfg.domainInterests,
3536
+ factTypePatterns: cfg.factTypePatterns,
3537
+ priorityRange: cfg.priorityRange,
3538
+ modes: cfg.modes,
3539
+ autoReconnect: cfg.autoReconnect,
3540
+ reconnectInterval: cfg.reconnectInterval
3541
+ };
3542
+ return { success: true, data: validConfig };
3543
+ },
3544
+ parse(value) {
3545
+ const result = this.safeParse(value);
3546
+ if (!result.success) {
3547
+ throw new Error(result.error.issues.map((i) => i.message).join(", "));
3548
+ }
3549
+ return result.data;
3550
+ },
3551
+ uiHints: {
3552
+ busUrl: {
3553
+ label: "Fact Bus URL",
3554
+ placeholder: "http://localhost:8080",
3555
+ help: "The URL of the Claw Fact Bus server"
3556
+ },
3557
+ clawName: {
3558
+ label: "Claw Name",
3559
+ help: "Unique identifier for this Claw agent"
3560
+ },
3561
+ clawDescription: {
3562
+ label: "Claw Description",
3563
+ help: "Description of this Claw's purpose"
3564
+ },
3565
+ capabilityOffer: {
3566
+ label: "Capabilities Offered",
3567
+ help: "List of capabilities this Claw can provide"
3568
+ },
3569
+ domainInterests: {
3570
+ label: "Domain Interests",
3571
+ help: "List of domains this Claw is interested in"
3572
+ },
3573
+ factTypePatterns: {
3574
+ label: "Fact Type Patterns",
3575
+ help: "Glob patterns for fact types to subscribe to"
3576
+ },
3577
+ autoReconnect: {
3578
+ label: "Auto Reconnect",
3579
+ help: "Automatically reconnect WebSocket on disconnect"
3580
+ },
3581
+ reconnectInterval: {
3582
+ label: "Reconnect Interval (ms)",
3583
+ help: "Interval between reconnection attempts",
3584
+ advanced: true
3585
+ }
3586
+ }
3587
+ };
3588
+ var index_default = definePluginEntry({
3589
+ id: "fact-bus",
3590
+ name: "Claw Fact Bus Plugin",
3591
+ description: "Integrates OpenClaw with Claw Fact Bus for fact-driven autonomous agent coordination",
3592
+ configSchema,
3593
+ register(api) {
3594
+ const config = configSchema.parse(api.pluginConfig);
3595
+ const logger = api.logger;
3596
+ client = new FactBusClient(config.busUrl);
3597
+ const toolContext = {
3598
+ client,
3599
+ logger: {
3600
+ debug: (...args) => {
3601
+ logger.debug?.(args.map(String).join(" "));
3602
+ },
3603
+ info: (...args) => {
3604
+ logger.info?.(args.map(String).join(" "));
3605
+ },
3606
+ warn: (...args) => {
3607
+ logger.warn?.(args.map(String).join(" "));
3608
+ },
3609
+ error: (...args) => {
3610
+ logger.error?.(args.map(String).join(" "));
3611
+ }
3612
+ }
3613
+ };
3614
+ for (const tool of factBusTools) {
3615
+ api.registerTool({
3616
+ name: tool.name,
3617
+ description: tool.description,
3618
+ label: tool.name,
3619
+ parameters: tool.parameters,
3620
+ execute: async (_id, params) => {
3621
+ if (!client?.isConnected) {
3622
+ await connectToBus(config, toolContext.logger);
3623
+ }
3624
+ const result = await tool.execute(_id, params, toolContext);
3625
+ return {
3626
+ content: result.content,
3627
+ details: {}
3628
+ };
3629
+ }
3630
+ });
3631
+ }
3632
+ api.on("gateway_start", async () => {
3633
+ toolContext.logger.info("Gateway starting, connecting to Fact Bus...");
3634
+ await connectToBus(config, toolContext.logger);
3635
+ startWebSocketService(config, toolContext.logger);
3636
+ });
3637
+ api.on("gateway_stop", () => {
3638
+ toolContext.logger.info("Gateway stopping, disconnecting from Fact Bus...");
3639
+ stopWebSocketService();
3640
+ client?.disconnect();
3641
+ });
3642
+ api.registerService({
3643
+ id: "fact-bus-websocket",
3644
+ start: async () => {
3645
+ },
3646
+ stop: async () => {
3647
+ stopWebSocketService();
3648
+ }
3649
+ });
3650
+ api.registerHttpRoute({
3651
+ path: "/plugins/fact-bus/health",
3652
+ auth: "plugin",
3653
+ handler: async (_req, res) => {
3654
+ const response = res;
3655
+ const health = {
3656
+ plugin: "fact-bus",
3657
+ connected: client?.isConnected ?? false,
3658
+ websocket: wsService?.isConnected ?? false,
3659
+ clawId: client?.currentClawId
3660
+ };
3661
+ response.json(health);
3662
+ }
3663
+ });
3664
+ }
3665
+ });
3666
+ async function connectToBus(config, logger) {
3667
+ if (!client) {
3668
+ logger.error("Client not initialized");
3669
+ return;
3670
+ }
3671
+ if (client.isConnected) {
3672
+ logger.debug("Already connected to Fact Bus");
3673
+ return;
3674
+ }
3675
+ try {
3676
+ logger.info(`Connecting to Fact Bus at ${config.busUrl}...`);
3677
+ const response = await client.connect({
3678
+ name: config.clawName ?? "openclaw-agent",
3679
+ description: config.clawDescription ?? "OpenClaw Agent via Fact Bus Plugin",
3680
+ capability_offer: config.capabilityOffer ?? [],
3681
+ domain_interests: config.domainInterests ?? [],
3682
+ fact_type_patterns: config.factTypePatterns ?? []
3683
+ });
3684
+ logger.info(`Connected to Fact Bus as claw: ${response.claw_id}`);
3685
+ } catch (error) {
3686
+ logger.error("Failed to connect to Fact Bus:", error);
3687
+ throw error;
3688
+ }
3689
+ }
3690
+ function startWebSocketService(config, logger) {
3691
+ if (!client || !client.isConnected) {
3692
+ logger.warn("Cannot start WebSocket: client not connected");
3693
+ return;
3694
+ }
3695
+ wsService = new FactBusWebSocketService({
3696
+ client,
3697
+ config,
3698
+ logger,
3699
+ onEvent: (event) => {
3700
+ handleWebSocketEvent(event, logger);
3701
+ }
3702
+ });
3703
+ setupWebSocketEventHandlers(wsService, logger);
3704
+ wsService.start();
3705
+ logger.info("WebSocket service started");
3706
+ }
3707
+ function setupWebSocketEventHandlers(service, logger) {
3708
+ service.on("fact_available", ((event) => {
3709
+ logger.info(`New fact available: ${event.fact?.fact_type} (id: ${event.fact?.fact_id})`);
3710
+ }));
3711
+ service.on("fact_claimed", ((event) => {
3712
+ logger.debug(`Fact claimed: ${event.fact?.fact_id} by ${event.fact?.claimed_by}`);
3713
+ }));
3714
+ service.on("fact_resolved", ((event) => {
3715
+ logger.info(`Fact resolved: ${event.fact?.fact_id}`);
3716
+ }));
3717
+ service.on("fact_superseded", ((event) => {
3718
+ logger.info(`Fact superseded: ${event.fact?.fact_id} -> ${event.fact?.superseded_by}`);
3719
+ }));
3720
+ service.on("fact_trust_changed", ((event) => {
3721
+ logger.debug(`Fact trust changed: ${event.fact?.fact_id}`, event.detail);
3722
+ }));
3723
+ service.on("claw_state_changed", ((event) => {
3724
+ logger.info(`Claw state changed: ${event.claw_id}`, event.detail);
3725
+ }));
3726
+ service.on("fact_expired", ((event) => {
3727
+ logger.debug(`Fact expired: ${event.fact?.fact_id}`);
3728
+ }));
3729
+ service.on("fact_dead", ((event) => {
3730
+ logger.debug(`Fact dead: ${event.fact?.fact_id}`);
3731
+ }));
3732
+ }
3733
+ function stopWebSocketService() {
3734
+ if (wsService) {
3735
+ wsService.stop();
3736
+ wsService = null;
3737
+ }
3738
+ }
3739
+ function handleWebSocketEvent(event, logger) {
3740
+ const ev = event;
3741
+ switch (ev.event_type) {
3742
+ case "fact_available":
3743
+ logger.info(`Fact available: ${ev.fact?.fact_type}`);
3744
+ break;
3745
+ case "fact_claimed":
3746
+ logger.debug(`Fact claimed: ${ev.fact?.fact_id}`);
3747
+ break;
3748
+ case "fact_resolved":
3749
+ logger.info(`Fact resolved: ${ev.fact?.fact_id}`);
3750
+ break;
3751
+ case "fact_superseded":
3752
+ logger.info(`Fact superseded: ${ev.fact?.fact_id}`);
3753
+ break;
3754
+ case "fact_trust_changed":
3755
+ logger.debug(`Fact trust changed: ${ev.fact?.fact_id}`, ev.detail);
3756
+ break;
3757
+ case "claw_state_changed":
3758
+ logger.debug(`Claw state changed`, ev.detail);
3759
+ break;
3760
+ default:
3761
+ logger.debug(`WebSocket event: ${ev.event_type}`);
3762
+ }
3763
+ }
3764
+
3765
+ export { index_default as default };
3766
+ //# sourceMappingURL=index.js.map
3767
+ //# sourceMappingURL=index.js.map