agenthooksprotocol 0.0.0-stage → 0.1.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.
Files changed (151) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +28 -2
  3. package/dist/src/client/auth.d.ts +147 -0
  4. package/dist/src/client/auth.d.ts.map +1 -0
  5. package/dist/src/client/auth.js +629 -0
  6. package/dist/src/client/auth.js.map +1 -0
  7. package/dist/src/client/composition.d.ts +42 -0
  8. package/dist/src/client/composition.d.ts.map +1 -0
  9. package/dist/src/client/composition.js +523 -0
  10. package/dist/src/client/composition.js.map +1 -0
  11. package/dist/src/client/content.d.ts +73 -0
  12. package/dist/src/client/content.d.ts.map +1 -0
  13. package/dist/src/client/content.js +404 -0
  14. package/dist/src/client/content.js.map +1 -0
  15. package/dist/src/client/hooks.d.ts +62 -0
  16. package/dist/src/client/hooks.d.ts.map +1 -0
  17. package/dist/src/client/hooks.js +997 -0
  18. package/dist/src/client/hooks.js.map +1 -0
  19. package/dist/src/client/index.d.ts +11 -0
  20. package/dist/src/client/index.d.ts.map +1 -0
  21. package/dist/src/client/index.js +9 -0
  22. package/dist/src/client/index.js.map +1 -0
  23. package/dist/src/client/transport.d.ts +12 -0
  24. package/dist/src/client/transport.d.ts.map +1 -0
  25. package/dist/src/client/transport.js +347 -0
  26. package/dist/src/client/transport.js.map +1 -0
  27. package/dist/src/client/types.d.ts +117 -0
  28. package/dist/src/client/types.d.ts.map +1 -0
  29. package/dist/src/client/types.js +10 -0
  30. package/dist/src/client/types.js.map +1 -0
  31. package/dist/src/client/validation.d.ts +3 -0
  32. package/dist/src/client/validation.d.ts.map +1 -0
  33. package/dist/src/client/validation.js +25 -0
  34. package/dist/src/client/validation.js.map +1 -0
  35. package/dist/src/compaction.d.ts +27 -0
  36. package/dist/src/compaction.d.ts.map +1 -0
  37. package/dist/src/compaction.js +155 -0
  38. package/dist/src/compaction.js.map +1 -0
  39. package/dist/src/content-upload.d.ts +60 -0
  40. package/dist/src/content-upload.d.ts.map +1 -0
  41. package/dist/src/content-upload.js +129 -0
  42. package/dist/src/content-upload.js.map +1 -0
  43. package/dist/src/draft/generated.d.ts +3085 -0
  44. package/dist/src/draft/generated.d.ts.map +1 -0
  45. package/dist/src/draft/generated.js +15372 -0
  46. package/dist/src/draft/generated.js.map +1 -0
  47. package/dist/src/draft/index.d.ts +31 -0
  48. package/dist/src/draft/index.d.ts.map +1 -0
  49. package/dist/src/draft/index.js +129 -0
  50. package/dist/src/draft/index.js.map +1 -0
  51. package/dist/src/draft/schemas.d.ts +8848 -0
  52. package/dist/src/draft/schemas.d.ts.map +1 -0
  53. package/dist/src/draft/schemas.js +9219 -0
  54. package/dist/src/draft/schemas.js.map +1 -0
  55. package/dist/src/draft-atomic.d.ts +18 -0
  56. package/dist/src/draft-atomic.d.ts.map +1 -0
  57. package/dist/src/draft-atomic.js +102 -0
  58. package/dist/src/draft-atomic.js.map +1 -0
  59. package/dist/src/draft-runtime.d.ts +89 -0
  60. package/dist/src/draft-runtime.d.ts.map +1 -0
  61. package/dist/src/draft-runtime.js +242 -0
  62. package/dist/src/draft-runtime.js.map +1 -0
  63. package/dist/src/elicitation.d.ts +18 -0
  64. package/dist/src/elicitation.d.ts.map +1 -0
  65. package/dist/src/elicitation.js +191 -0
  66. package/dist/src/elicitation.js.map +1 -0
  67. package/dist/src/errors.d.ts +7 -0
  68. package/dist/src/errors.d.ts.map +1 -0
  69. package/dist/src/errors.js +15 -0
  70. package/dist/src/errors.js.map +1 -0
  71. package/dist/src/framing.d.ts +7 -0
  72. package/dist/src/framing.d.ts.map +1 -0
  73. package/dist/src/framing.js +39 -0
  74. package/dist/src/framing.js.map +1 -0
  75. package/dist/src/generated.d.ts +304 -0
  76. package/dist/src/generated.d.ts.map +1 -0
  77. package/dist/src/generated.js +1885 -0
  78. package/dist/src/generated.js.map +1 -0
  79. package/dist/src/hook-runner.d.ts +11 -0
  80. package/dist/src/hook-runner.d.ts.map +1 -0
  81. package/dist/src/hook-runner.js +223 -0
  82. package/dist/src/hook-runner.js.map +1 -0
  83. package/dist/src/index.d.ts +8 -0
  84. package/dist/src/index.d.ts.map +1 -0
  85. package/dist/src/index.js +8 -0
  86. package/dist/src/index.js.map +1 -0
  87. package/dist/src/observation.d.ts +26 -0
  88. package/dist/src/observation.d.ts.map +1 -0
  89. package/dist/src/observation.js +28 -0
  90. package/dist/src/observation.js.map +1 -0
  91. package/dist/src/server/attachments.d.ts +29 -0
  92. package/dist/src/server/attachments.d.ts.map +1 -0
  93. package/dist/src/server/attachments.js +112 -0
  94. package/dist/src/server/attachments.js.map +1 -0
  95. package/dist/src/server/hooks.d.ts +20 -0
  96. package/dist/src/server/hooks.d.ts.map +1 -0
  97. package/dist/src/server/hooks.js +129 -0
  98. package/dist/src/server/hooks.js.map +1 -0
  99. package/dist/src/server/index.d.ts +7 -0
  100. package/dist/src/server/index.d.ts.map +1 -0
  101. package/dist/src/server/index.js +4 -0
  102. package/dist/src/server/index.js.map +1 -0
  103. package/dist/src/server/stdio.d.ts +15 -0
  104. package/dist/src/server/stdio.d.ts.map +1 -0
  105. package/dist/src/server/stdio.js +69 -0
  106. package/dist/src/server/stdio.js.map +1 -0
  107. package/dist/src/transport.d.ts +7 -0
  108. package/dist/src/transport.d.ts.map +1 -0
  109. package/dist/src/transport.js +195 -0
  110. package/dist/src/transport.js.map +1 -0
  111. package/dist/src/types.d.ts +116 -0
  112. package/dist/src/types.d.ts.map +1 -0
  113. package/dist/src/types.js +14 -0
  114. package/dist/src/types.js.map +1 -0
  115. package/dist/src/validation.d.ts +7 -0
  116. package/dist/src/validation.d.ts.map +1 -0
  117. package/dist/src/validation.js +209 -0
  118. package/dist/src/validation.js.map +1 -0
  119. package/package.json +62 -4
  120. package/src/client/auth.ts +1076 -0
  121. package/src/client/composition.ts +708 -0
  122. package/src/client/content.ts +510 -0
  123. package/src/client/hooks.ts +1368 -0
  124. package/src/client/index.ts +28 -0
  125. package/src/client/transport.ts +408 -0
  126. package/src/client/types.ts +173 -0
  127. package/src/client/validation.ts +24 -0
  128. package/src/compaction.ts +196 -0
  129. package/src/content-upload.ts +205 -0
  130. package/src/draft/README.md +16 -0
  131. package/src/draft/ahp-codegen.lock.json +123 -0
  132. package/src/draft/generated.ts +19143 -0
  133. package/src/draft/index.ts +246 -0
  134. package/src/draft/schemas.ts +9413 -0
  135. package/src/draft-atomic.ts +119 -0
  136. package/src/draft-runtime.ts +365 -0
  137. package/src/elicitation.ts +254 -0
  138. package/src/errors.ts +30 -0
  139. package/src/framing.ts +56 -0
  140. package/src/generated.ts +2408 -0
  141. package/src/hook-runner.ts +310 -0
  142. package/src/index.ts +8 -0
  143. package/src/observation.ts +65 -0
  144. package/src/server/attachments.ts +128 -0
  145. package/src/server/hooks.ts +205 -0
  146. package/src/server/index.ts +18 -0
  147. package/src/server/node-crypto.d.ts +7 -0
  148. package/src/server/stdio.ts +81 -0
  149. package/src/transport.ts +273 -0
  150. package/src/types.ts +124 -0
  151. package/src/validation.ts +372 -0
@@ -0,0 +1,1885 @@
1
+ // Generated by ahp-codegen. DO NOT EDIT.
2
+ // Generated from AHP schema draft.
3
+ // The source schema is authoritative if this output conflicts with it.
4
+ export const SCHEMA_REVISION = "draft";
5
+ export const PROTOCOL_VERSION = "draft";
6
+ const SCHEMAS = {
7
+ Authentication: {
8
+ additional: {
9
+ kind: "allowed",
10
+ },
11
+ forbidden_property_sets: [["bearerToken"], ["token"], ["value"]],
12
+ kind: "object",
13
+ properties: [
14
+ {
15
+ required: true,
16
+ shape: {
17
+ kind: "string",
18
+ },
19
+ wire_name: "tokenEnv",
20
+ },
21
+ {
22
+ required: true,
23
+ shape: {
24
+ kind: "literal",
25
+ value: "bearer",
26
+ },
27
+ wire_name: "type",
28
+ },
29
+ ],
30
+ },
31
+ Backend: {
32
+ additional: {
33
+ kind: "allowed",
34
+ },
35
+ forbidden_property_sets: [],
36
+ kind: "object",
37
+ properties: [
38
+ {
39
+ required: false,
40
+ shape: {
41
+ kind: "ref",
42
+ name: "Authentication",
43
+ },
44
+ wire_name: "authentication",
45
+ },
46
+ {
47
+ required: true,
48
+ shape: {
49
+ kind: "ref",
50
+ name: "ReverseDnsName",
51
+ },
52
+ wire_name: "id",
53
+ },
54
+ {
55
+ required: true,
56
+ shape: {
57
+ items: {
58
+ discriminator: "mode",
59
+ kind: "union",
60
+ mode: "oneOf",
61
+ variants: [
62
+ {
63
+ kind: "ref",
64
+ name: "InterceptSubscription",
65
+ },
66
+ {
67
+ kind: "ref",
68
+ name: "ObserveSubscription",
69
+ },
70
+ ],
71
+ },
72
+ kind: "array",
73
+ },
74
+ wire_name: "subscriptions",
75
+ },
76
+ {
77
+ required: true,
78
+ shape: {
79
+ discriminator: "type",
80
+ kind: "union",
81
+ mode: "oneOf",
82
+ variants: [
83
+ {
84
+ kind: "ref",
85
+ name: "StdioTransport",
86
+ },
87
+ {
88
+ kind: "ref",
89
+ name: "HttpTransport",
90
+ },
91
+ ],
92
+ },
93
+ wire_name: "transport",
94
+ },
95
+ ],
96
+ },
97
+ Capabilities: {
98
+ additional: {
99
+ kind: "allowed",
100
+ },
101
+ forbidden_property_sets: [],
102
+ kind: "object",
103
+ properties: [
104
+ {
105
+ required: true,
106
+ shape: {
107
+ items: {
108
+ kind: "union",
109
+ mode: "anyOf",
110
+ variants: [
111
+ {
112
+ kind: "literal",
113
+ value: "deny",
114
+ },
115
+ {
116
+ kind: "string",
117
+ },
118
+ ],
119
+ },
120
+ kind: "array",
121
+ },
122
+ wire_name: "effects",
123
+ },
124
+ ],
125
+ },
126
+ DenyEffect: {
127
+ additional: {
128
+ kind: "allowed",
129
+ },
130
+ forbidden_property_sets: [],
131
+ kind: "object",
132
+ properties: [
133
+ {
134
+ required: false,
135
+ shape: {
136
+ kind: "string",
137
+ },
138
+ wire_name: "code",
139
+ },
140
+ {
141
+ required: false,
142
+ shape: {
143
+ kind: "ref",
144
+ name: "Extensions",
145
+ },
146
+ wire_name: "extensions",
147
+ },
148
+ {
149
+ required: true,
150
+ shape: {
151
+ kind: "string",
152
+ },
153
+ wire_name: "reason",
154
+ },
155
+ {
156
+ required: true,
157
+ shape: {
158
+ kind: "literal",
159
+ value: "deny",
160
+ },
161
+ wire_name: "type",
162
+ },
163
+ ],
164
+ },
165
+ Extensions: {
166
+ additional: {
167
+ kind: "allowed",
168
+ },
169
+ forbidden_property_sets: [],
170
+ kind: "object",
171
+ properties: [],
172
+ },
173
+ HttpTransport: {
174
+ additional: {
175
+ kind: "allowed",
176
+ },
177
+ forbidden_property_sets: [],
178
+ kind: "object",
179
+ properties: [
180
+ {
181
+ required: true,
182
+ shape: {
183
+ kind: "literal",
184
+ value: "http",
185
+ },
186
+ wire_name: "type",
187
+ },
188
+ {
189
+ required: true,
190
+ shape: {
191
+ kind: "string",
192
+ },
193
+ wire_name: "url",
194
+ },
195
+ ],
196
+ },
197
+ InterceptDenyResponse: {
198
+ kind: "intersection",
199
+ variants: [
200
+ {
201
+ kind: "ref",
202
+ name: "JsonRpcSuccessResponse",
203
+ },
204
+ {
205
+ additional: {
206
+ kind: "allowed",
207
+ },
208
+ forbidden_property_sets: [],
209
+ kind: "object",
210
+ properties: [
211
+ {
212
+ required: false,
213
+ shape: {
214
+ additional: {
215
+ kind: "allowed",
216
+ },
217
+ forbidden_property_sets: [],
218
+ kind: "object",
219
+ properties: [
220
+ {
221
+ required: true,
222
+ shape: {
223
+ items: {
224
+ kind: "ref",
225
+ name: "DenyEffect",
226
+ },
227
+ kind: "array",
228
+ },
229
+ wire_name: "effects",
230
+ },
231
+ {
232
+ required: false,
233
+ shape: {
234
+ kind: "ref",
235
+ name: "Extensions",
236
+ },
237
+ wire_name: "extensions",
238
+ },
239
+ {
240
+ required: true,
241
+ shape: {
242
+ kind: "ref",
243
+ name: "ProtocolVersion",
244
+ },
245
+ wire_name: "protocolVersion",
246
+ },
247
+ ],
248
+ },
249
+ wire_name: "result",
250
+ },
251
+ ],
252
+ },
253
+ ],
254
+ },
255
+ InterceptNoEffectResponse: {
256
+ kind: "intersection",
257
+ variants: [
258
+ {
259
+ kind: "ref",
260
+ name: "JsonRpcSuccessResponse",
261
+ },
262
+ {
263
+ additional: {
264
+ kind: "allowed",
265
+ },
266
+ forbidden_property_sets: [],
267
+ kind: "object",
268
+ properties: [
269
+ {
270
+ required: false,
271
+ shape: {
272
+ additional: {
273
+ kind: "allowed",
274
+ },
275
+ forbidden_property_sets: [],
276
+ kind: "object",
277
+ properties: [
278
+ {
279
+ required: true,
280
+ shape: {
281
+ items: {
282
+ kind: "any",
283
+ },
284
+ kind: "array",
285
+ },
286
+ wire_name: "effects",
287
+ },
288
+ {
289
+ required: false,
290
+ shape: {
291
+ kind: "ref",
292
+ name: "Extensions",
293
+ },
294
+ wire_name: "extensions",
295
+ },
296
+ {
297
+ required: true,
298
+ shape: {
299
+ kind: "ref",
300
+ name: "ProtocolVersion",
301
+ },
302
+ wire_name: "protocolVersion",
303
+ },
304
+ ],
305
+ },
306
+ wire_name: "result",
307
+ },
308
+ ],
309
+ },
310
+ ],
311
+ },
312
+ InterceptRequest: {
313
+ kind: "intersection",
314
+ variants: [
315
+ {
316
+ kind: "ref",
317
+ name: "JsonRpcRequest",
318
+ },
319
+ {
320
+ additional: {
321
+ kind: "allowed",
322
+ },
323
+ forbidden_property_sets: [],
324
+ kind: "object",
325
+ properties: [
326
+ {
327
+ required: false,
328
+ shape: {
329
+ kind: "literal",
330
+ value: "hooks/intercept",
331
+ },
332
+ wire_name: "method",
333
+ },
334
+ {
335
+ required: false,
336
+ shape: {
337
+ additional: {
338
+ kind: "allowed",
339
+ },
340
+ forbidden_property_sets: [],
341
+ kind: "object",
342
+ properties: [
343
+ {
344
+ required: true,
345
+ shape: {
346
+ kind: "intersection",
347
+ variants: [
348
+ {
349
+ kind: "ref",
350
+ name: "Capabilities",
351
+ },
352
+ {
353
+ additional: {
354
+ kind: "allowed",
355
+ },
356
+ forbidden_property_sets: [],
357
+ kind: "object",
358
+ properties: [
359
+ {
360
+ required: false,
361
+ shape: {
362
+ kind: "any",
363
+ },
364
+ wire_name: "effects",
365
+ },
366
+ ],
367
+ },
368
+ ],
369
+ },
370
+ wire_name: "capabilities",
371
+ },
372
+ {
373
+ required: true,
374
+ shape: {
375
+ kind: "ref",
376
+ name: "ToolBeforeEvent",
377
+ },
378
+ wire_name: "event",
379
+ },
380
+ {
381
+ required: false,
382
+ shape: {
383
+ kind: "ref",
384
+ name: "Extensions",
385
+ },
386
+ wire_name: "extensions",
387
+ },
388
+ {
389
+ required: true,
390
+ shape: {
391
+ kind: "ref",
392
+ name: "ProtocolVersion",
393
+ },
394
+ wire_name: "protocolVersion",
395
+ },
396
+ ],
397
+ },
398
+ wire_name: "params",
399
+ },
400
+ ],
401
+ },
402
+ ],
403
+ },
404
+ InterceptSubscription: {
405
+ additional: {
406
+ kind: "allowed",
407
+ },
408
+ forbidden_property_sets: [],
409
+ kind: "object",
410
+ properties: [
411
+ {
412
+ required: true,
413
+ shape: {
414
+ items: {
415
+ kind: "literal",
416
+ value: "tool.before",
417
+ },
418
+ kind: "array",
419
+ },
420
+ wire_name: "events",
421
+ },
422
+ {
423
+ required: true,
424
+ shape: {
425
+ kind: "enum",
426
+ open_strings: true,
427
+ values: ["fail-open", "fail-closed"],
428
+ },
429
+ wire_name: "failurePolicy",
430
+ },
431
+ {
432
+ required: false,
433
+ shape: {
434
+ kind: "boolean",
435
+ },
436
+ wire_name: "includeNative",
437
+ },
438
+ {
439
+ required: true,
440
+ shape: {
441
+ kind: "literal",
442
+ value: "intercept",
443
+ },
444
+ wire_name: "mode",
445
+ },
446
+ {
447
+ required: true,
448
+ shape: {
449
+ kind: "integer",
450
+ },
451
+ wire_name: "timeoutMs",
452
+ },
453
+ ],
454
+ },
455
+ JsonRpcErrorResponse: {
456
+ additional: {
457
+ kind: "allowed",
458
+ },
459
+ forbidden_property_sets: [["result"]],
460
+ kind: "object",
461
+ properties: [
462
+ {
463
+ required: true,
464
+ shape: {
465
+ additional: {
466
+ kind: "allowed",
467
+ },
468
+ forbidden_property_sets: [],
469
+ kind: "object",
470
+ properties: [
471
+ {
472
+ required: true,
473
+ shape: {
474
+ kind: "integer",
475
+ },
476
+ wire_name: "code",
477
+ },
478
+ {
479
+ required: false,
480
+ shape: {
481
+ kind: "any",
482
+ },
483
+ wire_name: "data",
484
+ },
485
+ {
486
+ required: true,
487
+ shape: {
488
+ kind: "string",
489
+ },
490
+ wire_name: "message",
491
+ },
492
+ ],
493
+ },
494
+ wire_name: "error",
495
+ },
496
+ {
497
+ required: true,
498
+ shape: {
499
+ kind: "ref",
500
+ name: "JsonRpcResponseId",
501
+ },
502
+ wire_name: "id",
503
+ },
504
+ {
505
+ required: true,
506
+ shape: {
507
+ kind: "literal",
508
+ value: "2.0",
509
+ },
510
+ wire_name: "jsonrpc",
511
+ },
512
+ ],
513
+ },
514
+ JsonRpcId: {
515
+ kind: "union",
516
+ mode: "anyOf",
517
+ variants: [
518
+ {
519
+ kind: "string",
520
+ },
521
+ {
522
+ kind: "integer",
523
+ },
524
+ ],
525
+ },
526
+ JsonRpcMessage: {
527
+ kind: "union",
528
+ mode: "oneOf",
529
+ variants: [
530
+ {
531
+ kind: "ref",
532
+ name: "JsonRpcRequest",
533
+ },
534
+ {
535
+ kind: "ref",
536
+ name: "JsonRpcNotification",
537
+ },
538
+ {
539
+ kind: "ref",
540
+ name: "JsonRpcSuccessResponse",
541
+ },
542
+ {
543
+ kind: "ref",
544
+ name: "JsonRpcErrorResponse",
545
+ },
546
+ ],
547
+ },
548
+ JsonRpcNotification: {
549
+ additional: {
550
+ kind: "allowed",
551
+ },
552
+ forbidden_property_sets: [["id"]],
553
+ kind: "object",
554
+ properties: [
555
+ {
556
+ required: true,
557
+ shape: {
558
+ kind: "literal",
559
+ value: "2.0",
560
+ },
561
+ wire_name: "jsonrpc",
562
+ },
563
+ {
564
+ required: true,
565
+ shape: {
566
+ kind: "string",
567
+ },
568
+ wire_name: "method",
569
+ },
570
+ {
571
+ required: true,
572
+ shape: {
573
+ additional: {
574
+ kind: "allowed",
575
+ },
576
+ forbidden_property_sets: [],
577
+ kind: "object",
578
+ properties: [],
579
+ },
580
+ wire_name: "params",
581
+ },
582
+ ],
583
+ },
584
+ JsonRpcRequest: {
585
+ additional: {
586
+ kind: "allowed",
587
+ },
588
+ forbidden_property_sets: [],
589
+ kind: "object",
590
+ properties: [
591
+ {
592
+ required: true,
593
+ shape: {
594
+ kind: "ref",
595
+ name: "JsonRpcId",
596
+ },
597
+ wire_name: "id",
598
+ },
599
+ {
600
+ required: true,
601
+ shape: {
602
+ kind: "literal",
603
+ value: "2.0",
604
+ },
605
+ wire_name: "jsonrpc",
606
+ },
607
+ {
608
+ required: true,
609
+ shape: {
610
+ kind: "string",
611
+ },
612
+ wire_name: "method",
613
+ },
614
+ {
615
+ required: true,
616
+ shape: {
617
+ additional: {
618
+ kind: "allowed",
619
+ },
620
+ forbidden_property_sets: [],
621
+ kind: "object",
622
+ properties: [],
623
+ },
624
+ wire_name: "params",
625
+ },
626
+ ],
627
+ },
628
+ JsonRpcResponseId: {
629
+ kind: "union",
630
+ mode: "anyOf",
631
+ variants: [
632
+ {
633
+ kind: "ref",
634
+ name: "JsonRpcId",
635
+ },
636
+ {
637
+ kind: "null",
638
+ },
639
+ ],
640
+ },
641
+ JsonRpcSuccessResponse: {
642
+ additional: {
643
+ kind: "allowed",
644
+ },
645
+ forbidden_property_sets: [["error"]],
646
+ kind: "object",
647
+ properties: [
648
+ {
649
+ required: true,
650
+ shape: {
651
+ kind: "ref",
652
+ name: "JsonRpcResponseId",
653
+ },
654
+ wire_name: "id",
655
+ },
656
+ {
657
+ required: true,
658
+ shape: {
659
+ kind: "literal",
660
+ value: "2.0",
661
+ },
662
+ wire_name: "jsonrpc",
663
+ },
664
+ {
665
+ required: true,
666
+ shape: {
667
+ additional: {
668
+ kind: "allowed",
669
+ },
670
+ forbidden_property_sets: [],
671
+ kind: "object",
672
+ properties: [],
673
+ },
674
+ wire_name: "result",
675
+ },
676
+ ],
677
+ },
678
+ NativeEvent: {
679
+ additional: {
680
+ kind: "allowed",
681
+ },
682
+ forbidden_property_sets: [],
683
+ kind: "object",
684
+ properties: [
685
+ {
686
+ required: true,
687
+ shape: {
688
+ kind: "string",
689
+ },
690
+ wire_name: "eventName",
691
+ },
692
+ {
693
+ required: true,
694
+ shape: {
695
+ additional: {
696
+ kind: "allowed",
697
+ },
698
+ forbidden_property_sets: [],
699
+ kind: "object",
700
+ properties: [],
701
+ },
702
+ wire_name: "payload",
703
+ },
704
+ {
705
+ required: true,
706
+ shape: {
707
+ kind: "string",
708
+ },
709
+ wire_name: "provider",
710
+ },
711
+ ],
712
+ },
713
+ ObserveNotification: {
714
+ kind: "intersection",
715
+ variants: [
716
+ {
717
+ kind: "ref",
718
+ name: "JsonRpcNotification",
719
+ },
720
+ {
721
+ additional: {
722
+ kind: "allowed",
723
+ },
724
+ forbidden_property_sets: [],
725
+ kind: "object",
726
+ properties: [
727
+ {
728
+ required: false,
729
+ shape: {
730
+ kind: "literal",
731
+ value: "hooks/observe",
732
+ },
733
+ wire_name: "method",
734
+ },
735
+ {
736
+ required: false,
737
+ shape: {
738
+ additional: {
739
+ kind: "allowed",
740
+ },
741
+ forbidden_property_sets: [],
742
+ kind: "object",
743
+ properties: [
744
+ {
745
+ required: true,
746
+ shape: {
747
+ discriminator: "type",
748
+ kind: "union",
749
+ mode: "oneOf",
750
+ variants: [
751
+ {
752
+ kind: "ref",
753
+ name: "ToolBeforeEvent",
754
+ },
755
+ {
756
+ kind: "ref",
757
+ name: "ToolAfterEvent",
758
+ },
759
+ {
760
+ kind: "ref",
761
+ name: "ToolErrorEvent",
762
+ },
763
+ {
764
+ kind: "ref",
765
+ name: "SessionStartEvent",
766
+ },
767
+ {
768
+ kind: "ref",
769
+ name: "SessionEndEvent",
770
+ },
771
+ ],
772
+ },
773
+ wire_name: "event",
774
+ },
775
+ {
776
+ required: true,
777
+ shape: {
778
+ kind: "ref",
779
+ name: "ProtocolVersion",
780
+ },
781
+ wire_name: "protocolVersion",
782
+ },
783
+ ],
784
+ },
785
+ wire_name: "params",
786
+ },
787
+ ],
788
+ },
789
+ ],
790
+ },
791
+ ObserveSubscription: {
792
+ additional: {
793
+ kind: "allowed",
794
+ },
795
+ forbidden_property_sets: [["failurePolicy"], ["timeoutMs"]],
796
+ kind: "object",
797
+ properties: [
798
+ {
799
+ required: true,
800
+ shape: {
801
+ items: {
802
+ kind: "enum",
803
+ open_strings: true,
804
+ values: [
805
+ "tool.before",
806
+ "tool.after",
807
+ "tool.error",
808
+ "session.start",
809
+ "session.end",
810
+ ],
811
+ },
812
+ kind: "array",
813
+ },
814
+ wire_name: "events",
815
+ },
816
+ {
817
+ required: false,
818
+ shape: {
819
+ kind: "boolean",
820
+ },
821
+ wire_name: "includeNative",
822
+ },
823
+ {
824
+ required: true,
825
+ shape: {
826
+ kind: "literal",
827
+ value: "observe",
828
+ },
829
+ wire_name: "mode",
830
+ },
831
+ ],
832
+ },
833
+ ProtocolVersion: {
834
+ kind: "literal",
835
+ value: "draft",
836
+ },
837
+ Registration: {
838
+ additional: {
839
+ kind: "allowed",
840
+ },
841
+ forbidden_property_sets: [],
842
+ kind: "object",
843
+ properties: [
844
+ {
845
+ required: true,
846
+ shape: {
847
+ items: {
848
+ kind: "ref",
849
+ name: "Backend",
850
+ },
851
+ kind: "array",
852
+ },
853
+ wire_name: "hooks",
854
+ },
855
+ {
856
+ required: true,
857
+ shape: {
858
+ kind: "ref",
859
+ name: "ProtocolVersion",
860
+ },
861
+ wire_name: "protocolVersion",
862
+ },
863
+ ],
864
+ },
865
+ ReverseDnsName: {
866
+ kind: "string",
867
+ },
868
+ Session: {
869
+ additional: {
870
+ kind: "allowed",
871
+ },
872
+ forbidden_property_sets: [],
873
+ kind: "object",
874
+ properties: [
875
+ {
876
+ required: false,
877
+ shape: {
878
+ additional: {
879
+ kind: "allowed",
880
+ },
881
+ forbidden_property_sets: [],
882
+ kind: "object",
883
+ properties: [
884
+ {
885
+ required: true,
886
+ shape: {
887
+ kind: "string",
888
+ },
889
+ wire_name: "id",
890
+ },
891
+ {
892
+ required: false,
893
+ shape: {
894
+ kind: "string",
895
+ },
896
+ wire_name: "type",
897
+ },
898
+ ],
899
+ },
900
+ wire_name: "agent",
901
+ },
902
+ {
903
+ required: false,
904
+ shape: {
905
+ kind: "string",
906
+ },
907
+ wire_name: "cwd",
908
+ },
909
+ {
910
+ required: true,
911
+ shape: {
912
+ kind: "string",
913
+ },
914
+ wire_name: "id",
915
+ },
916
+ {
917
+ required: false,
918
+ shape: {
919
+ kind: "string",
920
+ },
921
+ wire_name: "model",
922
+ },
923
+ {
924
+ required: false,
925
+ shape: {
926
+ items: {
927
+ kind: "string",
928
+ },
929
+ kind: "array",
930
+ },
931
+ wire_name: "workspaceRoots",
932
+ },
933
+ ],
934
+ },
935
+ SessionEndEvent: {
936
+ additional: {
937
+ kind: "allowed",
938
+ },
939
+ forbidden_property_sets: [["tool"]],
940
+ kind: "object",
941
+ properties: [
942
+ {
943
+ required: false,
944
+ shape: {
945
+ kind: "ref",
946
+ name: "Extensions",
947
+ },
948
+ wire_name: "extensions",
949
+ },
950
+ {
951
+ required: true,
952
+ shape: {
953
+ kind: "string",
954
+ },
955
+ wire_name: "id",
956
+ },
957
+ {
958
+ required: false,
959
+ shape: {
960
+ kind: "ref",
961
+ name: "NativeEvent",
962
+ },
963
+ wire_name: "native",
964
+ },
965
+ {
966
+ required: false,
967
+ shape: {
968
+ kind: "enum",
969
+ open_strings: true,
970
+ values: ["completed", "cancelled", "error", "unknown"],
971
+ },
972
+ wire_name: "outcome",
973
+ },
974
+ {
975
+ required: true,
976
+ shape: {
977
+ kind: "ref",
978
+ name: "Session",
979
+ },
980
+ wire_name: "session",
981
+ },
982
+ {
983
+ required: true,
984
+ shape: {
985
+ kind: "string",
986
+ },
987
+ wire_name: "source",
988
+ },
989
+ {
990
+ required: true,
991
+ shape: {
992
+ kind: "string",
993
+ },
994
+ wire_name: "time",
995
+ },
996
+ {
997
+ required: true,
998
+ shape: {
999
+ kind: "literal",
1000
+ value: "session.end",
1001
+ },
1002
+ wire_name: "type",
1003
+ },
1004
+ ],
1005
+ },
1006
+ SessionStartEvent: {
1007
+ additional: {
1008
+ kind: "allowed",
1009
+ },
1010
+ forbidden_property_sets: [["outcome"], ["tool"]],
1011
+ kind: "object",
1012
+ properties: [
1013
+ {
1014
+ required: false,
1015
+ shape: {
1016
+ kind: "ref",
1017
+ name: "Extensions",
1018
+ },
1019
+ wire_name: "extensions",
1020
+ },
1021
+ {
1022
+ required: true,
1023
+ shape: {
1024
+ kind: "string",
1025
+ },
1026
+ wire_name: "id",
1027
+ },
1028
+ {
1029
+ required: false,
1030
+ shape: {
1031
+ kind: "ref",
1032
+ name: "NativeEvent",
1033
+ },
1034
+ wire_name: "native",
1035
+ },
1036
+ {
1037
+ required: true,
1038
+ shape: {
1039
+ kind: "ref",
1040
+ name: "Session",
1041
+ },
1042
+ wire_name: "session",
1043
+ },
1044
+ {
1045
+ required: true,
1046
+ shape: {
1047
+ kind: "string",
1048
+ },
1049
+ wire_name: "source",
1050
+ },
1051
+ {
1052
+ required: true,
1053
+ shape: {
1054
+ kind: "string",
1055
+ },
1056
+ wire_name: "time",
1057
+ },
1058
+ {
1059
+ required: true,
1060
+ shape: {
1061
+ kind: "literal",
1062
+ value: "session.start",
1063
+ },
1064
+ wire_name: "type",
1065
+ },
1066
+ ],
1067
+ },
1068
+ StdioTransport: {
1069
+ additional: {
1070
+ kind: "allowed",
1071
+ },
1072
+ forbidden_property_sets: [],
1073
+ kind: "object",
1074
+ properties: [
1075
+ {
1076
+ required: false,
1077
+ shape: {
1078
+ items: {
1079
+ kind: "string",
1080
+ },
1081
+ kind: "array",
1082
+ },
1083
+ wire_name: "args",
1084
+ },
1085
+ {
1086
+ required: true,
1087
+ shape: {
1088
+ kind: "string",
1089
+ },
1090
+ wire_name: "command",
1091
+ },
1092
+ {
1093
+ required: false,
1094
+ shape: {
1095
+ kind: "string",
1096
+ },
1097
+ wire_name: "cwd",
1098
+ },
1099
+ {
1100
+ required: true,
1101
+ shape: {
1102
+ kind: "enum",
1103
+ open_strings: true,
1104
+ values: ["persistent", "per_event"],
1105
+ },
1106
+ wire_name: "lifecycle",
1107
+ },
1108
+ {
1109
+ required: true,
1110
+ shape: {
1111
+ kind: "literal",
1112
+ value: "stdio",
1113
+ },
1114
+ wire_name: "type",
1115
+ },
1116
+ ],
1117
+ },
1118
+ ToolAfterEvent: {
1119
+ additional: {
1120
+ kind: "allowed",
1121
+ },
1122
+ forbidden_property_sets: [],
1123
+ kind: "object",
1124
+ properties: [
1125
+ {
1126
+ required: false,
1127
+ shape: {
1128
+ kind: "ref",
1129
+ name: "Extensions",
1130
+ },
1131
+ wire_name: "extensions",
1132
+ },
1133
+ {
1134
+ required: true,
1135
+ shape: {
1136
+ kind: "string",
1137
+ },
1138
+ wire_name: "id",
1139
+ },
1140
+ {
1141
+ required: false,
1142
+ shape: {
1143
+ kind: "ref",
1144
+ name: "NativeEvent",
1145
+ },
1146
+ wire_name: "native",
1147
+ },
1148
+ {
1149
+ required: true,
1150
+ shape: {
1151
+ kind: "ref",
1152
+ name: "Session",
1153
+ },
1154
+ wire_name: "session",
1155
+ },
1156
+ {
1157
+ required: true,
1158
+ shape: {
1159
+ kind: "string",
1160
+ },
1161
+ wire_name: "source",
1162
+ },
1163
+ {
1164
+ required: true,
1165
+ shape: {
1166
+ kind: "string",
1167
+ },
1168
+ wire_name: "time",
1169
+ },
1170
+ {
1171
+ required: true,
1172
+ shape: {
1173
+ additional: {
1174
+ kind: "allowed",
1175
+ },
1176
+ forbidden_property_sets: [["error"]],
1177
+ kind: "object",
1178
+ properties: [
1179
+ {
1180
+ required: true,
1181
+ shape: {
1182
+ kind: "string",
1183
+ },
1184
+ wire_name: "callId",
1185
+ },
1186
+ {
1187
+ required: true,
1188
+ shape: {
1189
+ additional: {
1190
+ kind: "allowed",
1191
+ },
1192
+ forbidden_property_sets: [],
1193
+ kind: "object",
1194
+ properties: [],
1195
+ },
1196
+ wire_name: "input",
1197
+ },
1198
+ {
1199
+ required: true,
1200
+ shape: {
1201
+ kind: "enum",
1202
+ open_strings: true,
1203
+ values: [
1204
+ "shell",
1205
+ "file_read",
1206
+ "file_write",
1207
+ "file_edit",
1208
+ "search",
1209
+ "fetch",
1210
+ "task",
1211
+ "mcp",
1212
+ "other",
1213
+ ],
1214
+ },
1215
+ wire_name: "kind",
1216
+ },
1217
+ {
1218
+ required: false,
1219
+ shape: {
1220
+ additional: {
1221
+ kind: "allowed",
1222
+ },
1223
+ forbidden_property_sets: [],
1224
+ kind: "object",
1225
+ properties: [],
1226
+ },
1227
+ wire_name: "mcp",
1228
+ },
1229
+ {
1230
+ required: true,
1231
+ shape: {
1232
+ kind: "string",
1233
+ },
1234
+ wire_name: "name",
1235
+ },
1236
+ {
1237
+ required: false,
1238
+ shape: {
1239
+ kind: "any",
1240
+ },
1241
+ wire_name: "output",
1242
+ },
1243
+ ],
1244
+ },
1245
+ wire_name: "tool",
1246
+ },
1247
+ {
1248
+ required: true,
1249
+ shape: {
1250
+ kind: "literal",
1251
+ value: "tool.after",
1252
+ },
1253
+ wire_name: "type",
1254
+ },
1255
+ ],
1256
+ },
1257
+ ToolBeforeEvent: {
1258
+ additional: {
1259
+ kind: "allowed",
1260
+ },
1261
+ forbidden_property_sets: [],
1262
+ kind: "object",
1263
+ properties: [
1264
+ {
1265
+ required: false,
1266
+ shape: {
1267
+ kind: "ref",
1268
+ name: "Extensions",
1269
+ },
1270
+ wire_name: "extensions",
1271
+ },
1272
+ {
1273
+ required: true,
1274
+ shape: {
1275
+ kind: "string",
1276
+ },
1277
+ wire_name: "id",
1278
+ },
1279
+ {
1280
+ required: false,
1281
+ shape: {
1282
+ kind: "ref",
1283
+ name: "NativeEvent",
1284
+ },
1285
+ wire_name: "native",
1286
+ },
1287
+ {
1288
+ required: true,
1289
+ shape: {
1290
+ kind: "ref",
1291
+ name: "Session",
1292
+ },
1293
+ wire_name: "session",
1294
+ },
1295
+ {
1296
+ required: true,
1297
+ shape: {
1298
+ kind: "string",
1299
+ },
1300
+ wire_name: "source",
1301
+ },
1302
+ {
1303
+ required: true,
1304
+ shape: {
1305
+ kind: "string",
1306
+ },
1307
+ wire_name: "time",
1308
+ },
1309
+ {
1310
+ required: true,
1311
+ shape: {
1312
+ additional: {
1313
+ kind: "allowed",
1314
+ },
1315
+ forbidden_property_sets: [["error"], ["output"]],
1316
+ kind: "object",
1317
+ properties: [
1318
+ {
1319
+ required: true,
1320
+ shape: {
1321
+ kind: "string",
1322
+ },
1323
+ wire_name: "callId",
1324
+ },
1325
+ {
1326
+ required: true,
1327
+ shape: {
1328
+ additional: {
1329
+ kind: "allowed",
1330
+ },
1331
+ forbidden_property_sets: [],
1332
+ kind: "object",
1333
+ properties: [],
1334
+ },
1335
+ wire_name: "input",
1336
+ },
1337
+ {
1338
+ required: true,
1339
+ shape: {
1340
+ kind: "enum",
1341
+ open_strings: true,
1342
+ values: [
1343
+ "shell",
1344
+ "file_read",
1345
+ "file_write",
1346
+ "file_edit",
1347
+ "search",
1348
+ "fetch",
1349
+ "task",
1350
+ "mcp",
1351
+ "other",
1352
+ ],
1353
+ },
1354
+ wire_name: "kind",
1355
+ },
1356
+ {
1357
+ required: false,
1358
+ shape: {
1359
+ additional: {
1360
+ kind: "allowed",
1361
+ },
1362
+ forbidden_property_sets: [],
1363
+ kind: "object",
1364
+ properties: [],
1365
+ },
1366
+ wire_name: "mcp",
1367
+ },
1368
+ {
1369
+ required: true,
1370
+ shape: {
1371
+ kind: "string",
1372
+ },
1373
+ wire_name: "name",
1374
+ },
1375
+ ],
1376
+ },
1377
+ wire_name: "tool",
1378
+ },
1379
+ {
1380
+ required: true,
1381
+ shape: {
1382
+ kind: "literal",
1383
+ value: "tool.before",
1384
+ },
1385
+ wire_name: "type",
1386
+ },
1387
+ ],
1388
+ },
1389
+ ToolErrorEvent: {
1390
+ additional: {
1391
+ kind: "allowed",
1392
+ },
1393
+ forbidden_property_sets: [],
1394
+ kind: "object",
1395
+ properties: [
1396
+ {
1397
+ required: false,
1398
+ shape: {
1399
+ kind: "ref",
1400
+ name: "Extensions",
1401
+ },
1402
+ wire_name: "extensions",
1403
+ },
1404
+ {
1405
+ required: true,
1406
+ shape: {
1407
+ kind: "string",
1408
+ },
1409
+ wire_name: "id",
1410
+ },
1411
+ {
1412
+ required: false,
1413
+ shape: {
1414
+ kind: "ref",
1415
+ name: "NativeEvent",
1416
+ },
1417
+ wire_name: "native",
1418
+ },
1419
+ {
1420
+ required: true,
1421
+ shape: {
1422
+ kind: "ref",
1423
+ name: "Session",
1424
+ },
1425
+ wire_name: "session",
1426
+ },
1427
+ {
1428
+ required: true,
1429
+ shape: {
1430
+ kind: "string",
1431
+ },
1432
+ wire_name: "source",
1433
+ },
1434
+ {
1435
+ required: true,
1436
+ shape: {
1437
+ kind: "string",
1438
+ },
1439
+ wire_name: "time",
1440
+ },
1441
+ {
1442
+ required: true,
1443
+ shape: {
1444
+ additional: {
1445
+ kind: "allowed",
1446
+ },
1447
+ forbidden_property_sets: [["output"]],
1448
+ kind: "object",
1449
+ properties: [
1450
+ {
1451
+ required: true,
1452
+ shape: {
1453
+ kind: "string",
1454
+ },
1455
+ wire_name: "callId",
1456
+ },
1457
+ {
1458
+ required: true,
1459
+ shape: {
1460
+ additional: {
1461
+ kind: "allowed",
1462
+ },
1463
+ forbidden_property_sets: [],
1464
+ kind: "object",
1465
+ properties: [
1466
+ {
1467
+ required: false,
1468
+ shape: {
1469
+ kind: "any",
1470
+ },
1471
+ wire_name: "category",
1472
+ },
1473
+ {
1474
+ required: false,
1475
+ shape: {
1476
+ kind: "any",
1477
+ },
1478
+ wire_name: "code",
1479
+ },
1480
+ {
1481
+ required: true,
1482
+ shape: {
1483
+ kind: "any",
1484
+ },
1485
+ wire_name: "message",
1486
+ },
1487
+ ],
1488
+ },
1489
+ wire_name: "error",
1490
+ },
1491
+ {
1492
+ required: true,
1493
+ shape: {
1494
+ additional: {
1495
+ kind: "allowed",
1496
+ },
1497
+ forbidden_property_sets: [],
1498
+ kind: "object",
1499
+ properties: [],
1500
+ },
1501
+ wire_name: "input",
1502
+ },
1503
+ {
1504
+ required: true,
1505
+ shape: {
1506
+ kind: "enum",
1507
+ open_strings: true,
1508
+ values: [
1509
+ "shell",
1510
+ "file_read",
1511
+ "file_write",
1512
+ "file_edit",
1513
+ "search",
1514
+ "fetch",
1515
+ "task",
1516
+ "mcp",
1517
+ "other",
1518
+ ],
1519
+ },
1520
+ wire_name: "kind",
1521
+ },
1522
+ {
1523
+ required: false,
1524
+ shape: {
1525
+ additional: {
1526
+ kind: "allowed",
1527
+ },
1528
+ forbidden_property_sets: [],
1529
+ kind: "object",
1530
+ properties: [],
1531
+ },
1532
+ wire_name: "mcp",
1533
+ },
1534
+ {
1535
+ required: true,
1536
+ shape: {
1537
+ kind: "string",
1538
+ },
1539
+ wire_name: "name",
1540
+ },
1541
+ ],
1542
+ },
1543
+ wire_name: "tool",
1544
+ },
1545
+ {
1546
+ required: true,
1547
+ shape: {
1548
+ kind: "literal",
1549
+ value: "tool.error",
1550
+ },
1551
+ wire_name: "type",
1552
+ },
1553
+ ],
1554
+ },
1555
+ WireMessage: {
1556
+ kind: "union",
1557
+ mode: "oneOf",
1558
+ variants: [
1559
+ {
1560
+ kind: "ref",
1561
+ name: "InterceptRequest",
1562
+ },
1563
+ {
1564
+ kind: "ref",
1565
+ name: "InterceptNoEffectResponse",
1566
+ },
1567
+ {
1568
+ kind: "ref",
1569
+ name: "InterceptDenyResponse",
1570
+ },
1571
+ {
1572
+ kind: "ref",
1573
+ name: "JsonRpcErrorResponse",
1574
+ },
1575
+ {
1576
+ kind: "ref",
1577
+ name: "ObserveNotification",
1578
+ },
1579
+ ],
1580
+ },
1581
+ };
1582
+ function parseRoot(name, input) {
1583
+ let raw;
1584
+ try {
1585
+ raw = toSafeJson(typeof input === "string" ? JSON.parse(input) : input);
1586
+ }
1587
+ catch (error) {
1588
+ return {
1589
+ ok: false,
1590
+ diagnostics: [
1591
+ {
1592
+ path: "",
1593
+ code: "invalid_json",
1594
+ severity: "error",
1595
+ message: error instanceof Error ? error.message : "Invalid JSON",
1596
+ },
1597
+ ],
1598
+ };
1599
+ }
1600
+ const diagnostics = [];
1601
+ checkNode(SCHEMAS[name], raw, "", diagnostics);
1602
+ if (diagnostics.some((diagnostic) => diagnostic.severity === "error"))
1603
+ return { ok: false, raw, diagnostics };
1604
+ return { ok: true, value: raw, raw, diagnostics };
1605
+ }
1606
+ function checkNode(schema, value, path, diagnostics) {
1607
+ switch (schema.kind) {
1608
+ case "any":
1609
+ return;
1610
+ case "never":
1611
+ return error(diagnostics, path, "invalid_type", "Value is forbidden");
1612
+ case "null":
1613
+ if (value !== null)
1614
+ error(diagnostics, path, "invalid_type", "Expected null");
1615
+ return;
1616
+ case "boolean":
1617
+ if (typeof value !== "boolean")
1618
+ error(diagnostics, path, "invalid_type", "Expected boolean");
1619
+ return;
1620
+ case "integer":
1621
+ if (typeof value !== "number" || !Number.isSafeInteger(value))
1622
+ error(diagnostics, path, "invalid_type", "Expected safely representable integer");
1623
+ return;
1624
+ case "number":
1625
+ if (typeof value !== "number" || !Number.isFinite(value))
1626
+ error(diagnostics, path, "invalid_type", "Expected finite number");
1627
+ return;
1628
+ case "string":
1629
+ if (typeof value !== "string")
1630
+ error(diagnostics, path, "invalid_type", "Expected string");
1631
+ return;
1632
+ case "literal":
1633
+ if (!sameJson(value, schema.value))
1634
+ error(diagnostics, path, "literal_mismatch", `Expected ${JSON.stringify(schema.value)}`);
1635
+ return;
1636
+ case "enum": {
1637
+ if (schema.values.some((candidate) => sameJson(candidate, value)))
1638
+ return;
1639
+ if (schema.open_strings && typeof value === "string") {
1640
+ diagnostics.push({
1641
+ path,
1642
+ code: "unknown_enum",
1643
+ severity: "warning",
1644
+ message: `Unknown enum value ${JSON.stringify(value)} was preserved`,
1645
+ });
1646
+ }
1647
+ else
1648
+ error(diagnostics, path, "invalid_type", "Value does not match the enum's scalar type");
1649
+ return;
1650
+ }
1651
+ case "array":
1652
+ if (!Array.isArray(value))
1653
+ return error(diagnostics, path, "invalid_type", "Expected array");
1654
+ value.forEach((item, index) => checkNode(schema.items, item, `${path}/${index}`, diagnostics));
1655
+ return;
1656
+ case "object":
1657
+ if (!isObject(value))
1658
+ return error(diagnostics, path, "invalid_type", "Expected object");
1659
+ for (const forbiddenSet of schema.forbidden_property_sets) {
1660
+ if (forbiddenSet.every((key) => Object.prototype.hasOwnProperty.call(value, key))) {
1661
+ error(diagnostics, path, "invalid_type", `Forbidden property combination: ${forbiddenSet.join(", ")}`);
1662
+ }
1663
+ }
1664
+ for (const property of schema.properties) {
1665
+ if (!Object.prototype.hasOwnProperty.call(value, property.wire_name)) {
1666
+ if (property.required)
1667
+ error(diagnostics, joinPath(path, property.wire_name), "missing_required", "Required property is absent");
1668
+ }
1669
+ else
1670
+ checkNode(property.shape, value[property.wire_name], joinPath(path, property.wire_name), diagnostics);
1671
+ }
1672
+ return;
1673
+ case "intersection":
1674
+ schema.variants.forEach((variant) => checkNode(variant, value, path, diagnostics));
1675
+ return;
1676
+ case "ref":
1677
+ checkNode(SCHEMAS[schema.name], value, path, diagnostics);
1678
+ return;
1679
+ case "union":
1680
+ checkUnion(schema, value, path, diagnostics);
1681
+ return;
1682
+ }
1683
+ }
1684
+ function checkUnion(schema, value, path, diagnostics) {
1685
+ if (schema.discriminator) {
1686
+ if (!isObject(value) || typeof value[schema.discriminator] !== "string")
1687
+ return error(diagnostics, joinPath(path, schema.discriminator), "invalid_type", "Expected string discriminator");
1688
+ const actual = value[schema.discriminator];
1689
+ const branch = schema.variants.find((variant) => discriminatorValue(variant, schema.discriminator) === actual);
1690
+ if (!branch) {
1691
+ diagnostics.push({
1692
+ path,
1693
+ code: "unknown_variant",
1694
+ severity: "warning",
1695
+ message: `Unknown ${schema.discriminator} variant ${JSON.stringify(actual)} was preserved`,
1696
+ });
1697
+ return;
1698
+ }
1699
+ const branchDiagnostics = [];
1700
+ checkNode(branch, value, path, branchDiagnostics);
1701
+ if (branchDiagnostics.some((item) => item.severity === "error")) {
1702
+ diagnostics.push(...branchDiagnostics, {
1703
+ path,
1704
+ code: "invalid_known_variant",
1705
+ severity: "error",
1706
+ message: `Known ${schema.discriminator} variant is malformed`,
1707
+ });
1708
+ }
1709
+ else
1710
+ diagnostics.push(...branchDiagnostics);
1711
+ return;
1712
+ }
1713
+ const attempts = schema.variants.map((variant) => {
1714
+ const result = [];
1715
+ checkNode(variant, value, path, result);
1716
+ return result;
1717
+ });
1718
+ const matches = attempts.filter((attempt) => !attempt.some((item) => item.severity === "error"));
1719
+ if (matches.length === 0)
1720
+ error(diagnostics, path, "no_union_match", "Value matches no union branch");
1721
+ else if (schema.mode === "oneOf" && matches.length > 1)
1722
+ error(diagnostics, path, "ambiguous_union", "Value matches more than one union branch");
1723
+ else
1724
+ diagnostics.push(...matches[0]);
1725
+ }
1726
+ function discriminatorValue(schema, property) {
1727
+ if (schema.kind === "ref")
1728
+ return discriminatorValue(SCHEMAS[schema.name], property);
1729
+ if (schema.kind === "intersection") {
1730
+ for (const variant of schema.variants) {
1731
+ const value = discriminatorValue(variant, property);
1732
+ if (value !== undefined)
1733
+ return value;
1734
+ }
1735
+ }
1736
+ if (schema.kind === "object") {
1737
+ const field = schema.properties.find((candidate) => candidate.wire_name === property);
1738
+ if (field?.shape.kind === "literal" &&
1739
+ typeof field.shape.value === "string")
1740
+ return field.shape.value;
1741
+ }
1742
+ return undefined;
1743
+ }
1744
+ function toSafeJson(value) {
1745
+ if (value === null || typeof value === "string" || typeof value === "boolean")
1746
+ return value;
1747
+ if (typeof value === "number" && Number.isFinite(value))
1748
+ return value;
1749
+ if (Array.isArray(value))
1750
+ return value.map(toSafeJson);
1751
+ if (typeof value === "object") {
1752
+ const result = Object.create(null);
1753
+ for (const [key, child] of Object.entries(value)) {
1754
+ Object.defineProperty(result, key, {
1755
+ value: toSafeJson(child),
1756
+ enumerable: true,
1757
+ configurable: true,
1758
+ writable: true,
1759
+ });
1760
+ }
1761
+ return result;
1762
+ }
1763
+ throw new TypeError("Input is not a JSON value");
1764
+ }
1765
+ function encodeJson(value) {
1766
+ return JSON.stringify(value);
1767
+ }
1768
+ function isObject(value) {
1769
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1770
+ }
1771
+ function sameJson(left, right) {
1772
+ return JSON.stringify(left) === JSON.stringify(right);
1773
+ }
1774
+ function joinPath(path, key) {
1775
+ return `${path}/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`;
1776
+ }
1777
+ function error(diagnostics, path, code, message) {
1778
+ diagnostics.push({ path, code, severity: "error", message });
1779
+ }
1780
+ export function parseCapabilities(input) {
1781
+ return parseRoot("Capabilities", input);
1782
+ }
1783
+ export function encodeCapabilities(value) {
1784
+ return encodeJson(value);
1785
+ }
1786
+ export const capabilitiesSchemaRevision = SCHEMA_REVISION;
1787
+ export function parseDenyEffect(input) {
1788
+ return parseRoot("DenyEffect", input);
1789
+ }
1790
+ export function encodeDenyEffect(value) {
1791
+ return encodeJson(value);
1792
+ }
1793
+ export const denyEffectSchemaRevision = SCHEMA_REVISION;
1794
+ export function parseExtensions(input) {
1795
+ return parseRoot("Extensions", input);
1796
+ }
1797
+ export function encodeExtensions(value) {
1798
+ return encodeJson(value);
1799
+ }
1800
+ export const extensionsSchemaRevision = SCHEMA_REVISION;
1801
+ export function parseInterceptDenyResponse(input) {
1802
+ return parseRoot("InterceptDenyResponse", input);
1803
+ }
1804
+ export function encodeInterceptDenyResponse(value) {
1805
+ return encodeJson(value);
1806
+ }
1807
+ export const interceptDenyResponseSchemaRevision = SCHEMA_REVISION;
1808
+ export function parseInterceptNoEffectResponse(input) {
1809
+ return parseRoot("InterceptNoEffectResponse", input);
1810
+ }
1811
+ export function encodeInterceptNoEffectResponse(value) {
1812
+ return encodeJson(value);
1813
+ }
1814
+ export const interceptNoEffectResponseSchemaRevision = SCHEMA_REVISION;
1815
+ export function parseInterceptRequest(input) {
1816
+ return parseRoot("InterceptRequest", input);
1817
+ }
1818
+ export function encodeInterceptRequest(value) {
1819
+ return encodeJson(value);
1820
+ }
1821
+ export const interceptRequestSchemaRevision = SCHEMA_REVISION;
1822
+ export function parseJsonRpcMessage(input) {
1823
+ return parseRoot("JsonRpcMessage", input);
1824
+ }
1825
+ export function encodeJsonRpcMessage(value) {
1826
+ return encodeJson(value);
1827
+ }
1828
+ export const jsonRpcMessageSchemaRevision = SCHEMA_REVISION;
1829
+ export function parseObserveNotification(input) {
1830
+ return parseRoot("ObserveNotification", input);
1831
+ }
1832
+ export function encodeObserveNotification(value) {
1833
+ return encodeJson(value);
1834
+ }
1835
+ export const observeNotificationSchemaRevision = SCHEMA_REVISION;
1836
+ export function parseRegistration(input) {
1837
+ return parseRoot("Registration", input);
1838
+ }
1839
+ export function encodeRegistration(value) {
1840
+ return encodeJson(value);
1841
+ }
1842
+ export const registrationSchemaRevision = SCHEMA_REVISION;
1843
+ export function parseSessionEndEvent(input) {
1844
+ return parseRoot("SessionEndEvent", input);
1845
+ }
1846
+ export function encodeSessionEndEvent(value) {
1847
+ return encodeJson(value);
1848
+ }
1849
+ export const sessionEndEventSchemaRevision = SCHEMA_REVISION;
1850
+ export function parseSessionStartEvent(input) {
1851
+ return parseRoot("SessionStartEvent", input);
1852
+ }
1853
+ export function encodeSessionStartEvent(value) {
1854
+ return encodeJson(value);
1855
+ }
1856
+ export const sessionStartEventSchemaRevision = SCHEMA_REVISION;
1857
+ export function parseToolAfterEvent(input) {
1858
+ return parseRoot("ToolAfterEvent", input);
1859
+ }
1860
+ export function encodeToolAfterEvent(value) {
1861
+ return encodeJson(value);
1862
+ }
1863
+ export const toolAfterEventSchemaRevision = SCHEMA_REVISION;
1864
+ export function parseToolBeforeEvent(input) {
1865
+ return parseRoot("ToolBeforeEvent", input);
1866
+ }
1867
+ export function encodeToolBeforeEvent(value) {
1868
+ return encodeJson(value);
1869
+ }
1870
+ export const toolBeforeEventSchemaRevision = SCHEMA_REVISION;
1871
+ export function parseToolErrorEvent(input) {
1872
+ return parseRoot("ToolErrorEvent", input);
1873
+ }
1874
+ export function encodeToolErrorEvent(value) {
1875
+ return encodeJson(value);
1876
+ }
1877
+ export const toolErrorEventSchemaRevision = SCHEMA_REVISION;
1878
+ export function parseWireMessage(input) {
1879
+ return parseRoot("WireMessage", input);
1880
+ }
1881
+ export function encodeWireMessage(value) {
1882
+ return encodeJson(value);
1883
+ }
1884
+ export const wireMessageSchemaRevision = SCHEMA_REVISION;
1885
+ //# sourceMappingURL=generated.js.map