@boxxy/pepys 0.0.1 → 0.1.3

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 (51) hide show
  1. package/README.md +42 -5
  2. package/dist/boxxy-source.d.ts +636 -0
  3. package/dist/boxxy-work-plugin.d.ts +1 -0
  4. package/dist/build-boxxy-plugin.d.ts +181 -0
  5. package/dist/consumers/apply-scope.d.ts +5 -0
  6. package/dist/create-pepys-fact-sink.d.ts +9 -0
  7. package/dist/create-pepys-reader.d.ts +9 -0
  8. package/dist/generated/boxxy-work-boundary.d.ts +566 -0
  9. package/dist/index.d.ts +5 -0
  10. package/dist/queries/build-cost-to-land-query.d.ts +156 -0
  11. package/dist/queries/build-cost-to-land.d.ts +12 -0
  12. package/dist/queries/build-stage-time-query.d.ts +29 -0
  13. package/dist/queries/build-stage-time.d.ts +10 -0
  14. package/dist/queries/constants.d.ts +6 -0
  15. package/dist/queries/find-item-entity-id.d.ts +2 -0
  16. package/dist/queries/types.d.ts +109 -0
  17. package/dist/sink/is-outgoing-fact.d.ts +3 -0
  18. package/dist/sink/pick-sink-answer.d.ts +7 -0
  19. package/dist/sink/to-wire-fact.d.ts +5 -0
  20. package/dist/types.d.ts +6 -0
  21. package/dist/wire-fact-schemas.d.ts +319 -0
  22. package/dist/work/boxxy-work-consumer.d.ts +125 -0
  23. package/dist/work/constants.d.ts +3 -0
  24. package/dist/work/fold-work-facts.d.ts +2 -0
  25. package/dist/work/types.d.ts +147 -0
  26. package/package.json +45 -4
  27. package/src/boxxy-source.ts +25 -0
  28. package/src/boxxy-work-plugin.ts +11 -0
  29. package/src/build-boxxy-plugin.ts +18 -0
  30. package/src/consumers/apply-scope.ts +125 -0
  31. package/src/create-pepys-fact-sink.ts +64 -0
  32. package/src/create-pepys-reader.ts +79 -0
  33. package/src/generated/boxxy-work-boundary.ts +2923 -0
  34. package/src/generated/boxxy-work.sql +71 -0
  35. package/src/index.ts +17 -0
  36. package/src/queries/build-cost-to-land-query.ts +127 -0
  37. package/src/queries/build-cost-to-land.ts +226 -0
  38. package/src/queries/build-stage-time-query.ts +59 -0
  39. package/src/queries/build-stage-time.ts +188 -0
  40. package/src/queries/constants.ts +10 -0
  41. package/src/queries/find-item-entity-id.ts +16 -0
  42. package/src/queries/types.ts +168 -0
  43. package/src/sink/is-outgoing-fact.ts +19 -0
  44. package/src/sink/pick-sink-answer.ts +29 -0
  45. package/src/sink/to-wire-fact.ts +31 -0
  46. package/src/types.ts +14 -0
  47. package/src/wire-fact-schemas.ts +41 -0
  48. package/src/work/boxxy-work-consumer.ts +95 -0
  49. package/src/work/constants.ts +25 -0
  50. package/src/work/fold-work-facts.ts +490 -0
  51. package/src/work/types.ts +177 -0
@@ -0,0 +1,2923 @@
1
+ // Generated by `pepys build`. Do not edit.
2
+
3
+ declare const idTag: unique symbol;
4
+ declare const kindTag: unique symbol;
5
+
6
+ export type EntityID = string & { readonly [idTag]: 'EntityID' };
7
+
8
+ type KindedID<Kind extends string> = EntityID & { readonly [kindTag]: Kind };
9
+
10
+ export type BoxxyAttemptID = KindedID<'boxxy:attempt'>;
11
+
12
+ export function toBoxxyAttemptID(id: string): BoxxyAttemptID {
13
+ const text = 'boxxy:attempt:' + id;
14
+
15
+ if (!isBoxxyAttemptID(text)) {
16
+ throw new Error('an ID of the kind boxxy:attempt is never empty');
17
+ }
18
+
19
+ return text;
20
+ }
21
+
22
+ export function parseBoxxyAttemptID(text: string): BoxxyAttemptID | undefined {
23
+ return isBoxxyAttemptID(text) ? text : undefined;
24
+ }
25
+
26
+ function isBoxxyAttemptID(text: string): text is BoxxyAttemptID {
27
+ return text.length > 'boxxy:attempt:'.length && text.startsWith('boxxy:attempt:');
28
+ }
29
+
30
+ export type BoxxyItemID = KindedID<'boxxy:item'>;
31
+
32
+ export function toBoxxyItemID(id: string): BoxxyItemID {
33
+ const text = 'boxxy:item:' + id;
34
+
35
+ if (!isBoxxyItemID(text)) {
36
+ throw new Error('an ID of the kind boxxy:item is never empty');
37
+ }
38
+
39
+ return text;
40
+ }
41
+
42
+ export function parseBoxxyItemID(text: string): BoxxyItemID | undefined {
43
+ return isBoxxyItemID(text) ? text : undefined;
44
+ }
45
+
46
+ function isBoxxyItemID(text: string): text is BoxxyItemID {
47
+ return text.length > 'boxxy:item:'.length && text.startsWith('boxxy:item:');
48
+ }
49
+
50
+ export type GithubPullRequestID = KindedID<'github:pull_request'>;
51
+
52
+ export function toGithubPullRequestID(id: string): GithubPullRequestID {
53
+ const text = 'github:pull_request:' + id;
54
+
55
+ if (!isGithubPullRequestID(text)) {
56
+ throw new Error('an ID of the kind github:pull_request is never empty');
57
+ }
58
+
59
+ return text;
60
+ }
61
+
62
+ export function parseGithubPullRequestID(text: string): GithubPullRequestID | undefined {
63
+ return isGithubPullRequestID(text) ? text : undefined;
64
+ }
65
+
66
+ function isGithubPullRequestID(text: string): text is GithubPullRequestID {
67
+ return text.length > 'github:pull_request:'.length && text.startsWith('github:pull_request:');
68
+ }
69
+
70
+ export type TelemetrySessionID = KindedID<'telemetry:session'>;
71
+
72
+ export function toTelemetrySessionID(id: string): TelemetrySessionID {
73
+ const text = 'telemetry:session:' + id;
74
+
75
+ if (!isTelemetrySessionID(text)) {
76
+ throw new Error('an ID of the kind telemetry:session is never empty');
77
+ }
78
+
79
+ return text;
80
+ }
81
+
82
+ export function parseTelemetrySessionID(text: string): TelemetrySessionID | undefined {
83
+ return isTelemetrySessionID(text) ? text : undefined;
84
+ }
85
+
86
+ function isTelemetrySessionID(text: string): text is TelemetrySessionID {
87
+ return text.length > 'telemetry:session:'.length && text.startsWith('telemetry:session:');
88
+ }
89
+
90
+ export interface BoxxyWorkModel {
91
+ input: string;
92
+ }
93
+
94
+ export type BoxxyWorkMessage = { kind: 'apply'; input: string } | { kind: 'reset' };
95
+
96
+ export function initBoxxyWorkModel(): BoxxyWorkModel {
97
+ return { input: '' };
98
+ }
99
+
100
+ export function updateBoxxyWorkModel(model: BoxxyWorkModel, message: BoxxyWorkMessage): BoxxyWorkModel {
101
+ return message.kind === 'reset' ? initBoxxyWorkModel() : { ...model, input: message.input };
102
+ }
103
+
104
+ export interface BoxxyItemFiledPayload {
105
+ id: string;
106
+ kind: string;
107
+ repo: string;
108
+ title: string;
109
+ outcome: string;
110
+ acceptance: BoxxyItemFiledPayloadAcceptanceItem[];
111
+ fields: BoxxyItemFiledPayloadFields;
112
+ labels: string[];
113
+ foundInAttempt: string | null;
114
+ filedBy: unknown;
115
+ filedAt: number;
116
+ closedAt: number | null;
117
+ closeReason: string | null;
118
+ storeVersion: number;
119
+ }
120
+
121
+ export interface BoxxyItemFiledPayloadAcceptanceItem {
122
+ id: string;
123
+ text: string;
124
+ evidence: string[];
125
+ }
126
+
127
+ export interface BoxxyItemFiledPayloadFields {
128
+ designMode: unknown;
129
+ }
130
+
131
+ export interface BoxxyItemNotedPayload {
132
+ seq: number;
133
+ text: string;
134
+ storeVersion: number;
135
+ }
136
+
137
+ export interface BoxxyItemEditedPayload {
138
+ title: unknown;
139
+ outcome: unknown;
140
+ acceptance: unknown;
141
+ kind: unknown;
142
+ fields: unknown;
143
+ labels: unknown;
144
+ byAttempt: string | null;
145
+ storeVersion: number;
146
+ }
147
+
148
+ export interface BoxxyItemClosedPayload {
149
+ reason: string;
150
+ byAttempt: string | null;
151
+ ended: BoxxyItemClosedPayloadEndedItem[];
152
+ storeVersion: number;
153
+ }
154
+
155
+ export interface BoxxyItemClosedPayloadEndedItem {
156
+ attempt: string;
157
+ how: 'settled' | 'closing';
158
+ }
159
+
160
+ export interface BoxxyRelationAddedPayload {
161
+ source: string;
162
+ target: string;
163
+ type: string;
164
+ storeVersion: number;
165
+ }
166
+
167
+ export interface BoxxyRelationRemovedPayload {
168
+ source: string;
169
+ target: string;
170
+ type: string;
171
+ storeVersion: number;
172
+ }
173
+
174
+ export interface BoxxyLeverRecordedPayload {
175
+ seq: number;
176
+ kind: unknown;
177
+ item: string;
178
+ until: number | null;
179
+ expiresAt: number | null;
180
+ reason: string | null;
181
+ phase: string | null;
182
+ actor: unknown;
183
+ at: number;
184
+ storeVersion: number;
185
+ }
186
+
187
+ export interface BoxxyAttemptClaimedPayload {
188
+ attempt: string;
189
+ phase: string;
190
+ number: number;
191
+ round: number;
192
+ mode: 'agent' | 'attended';
193
+ pool: string;
194
+ fields: unknown;
195
+ seats: BoxxyAttemptClaimedPayloadSeatsItem[];
196
+ recipeHash: string;
197
+ skillsRef: string | null;
198
+ rulesVersion: string;
199
+ storeVersion: number;
200
+ }
201
+
202
+ export interface BoxxyAttemptClaimedPayloadSeatsItem {
203
+ limit: string;
204
+ }
205
+
206
+ export interface BoxxyDecisionRecordedPayload {
207
+ id: string;
208
+ attempt: string;
209
+ item: string;
210
+ kind: 'start' | 'wake';
211
+ pool: string;
212
+ rulesVersion: string;
213
+ snapshotHash: string;
214
+ storeVersion: number;
215
+ pepysOffsets: unknown;
216
+ faults: BoxxyDecisionRecordedPayloadFaultsItem[];
217
+ limits: BoxxyDecisionRecordedPayloadLimitsItem[];
218
+ at: number;
219
+ }
220
+
221
+ export interface BoxxyDecisionRecordedPayloadFaultsItem {
222
+ plugin: string;
223
+ kind: 'signal' | 'gate' | 'waiver' | 'admission' | 'propagation' | 'filter-field';
224
+ item: string | null;
225
+ error: string;
226
+ }
227
+
228
+ export interface BoxxyDecisionRecordedPayloadLimitsItem {
229
+ limit: string;
230
+ held: number;
231
+ max: number;
232
+ }
233
+
234
+ export interface BoxxyAttemptStartedPayload {
235
+ attempt: string;
236
+ atcSession: string;
237
+ resumeFallback: boolean;
238
+ caller: BoxxyAttemptStartedPayloadCaller | null;
239
+ storeVersion: number;
240
+ }
241
+
242
+ export interface BoxxyAttemptStartedPayloadCaller {
243
+ issuer: string;
244
+ subject: string;
245
+ }
246
+
247
+ export interface BoxxyAttemptSpawnUnansweredPayload {
248
+ attempt: string;
249
+ reason: string;
250
+ storeVersion: number;
251
+ }
252
+
253
+ export interface BoxxyAttemptReconciledPayload {
254
+ attempt: string;
255
+ atcSession: string;
256
+ caller: BoxxyAttemptReconciledPayloadCaller | null;
257
+ storeVersion: number;
258
+ }
259
+
260
+ export interface BoxxyAttemptReconciledPayloadCaller {
261
+ issuer: string;
262
+ subject: string;
263
+ }
264
+
265
+ export interface BoxxyAttemptSessionBoundPayload {
266
+ attempt: string;
267
+ atcSession: string;
268
+ agentSession: string;
269
+ product: 'claude_code' | 'codex';
270
+ source: 'worker' | 'hook';
271
+ seenAt: number;
272
+ storeVersion: number;
273
+ }
274
+
275
+ export interface BoxxyAttemptSleptPayload {
276
+ attempt: string;
277
+ idleSince: number;
278
+ asked: boolean;
279
+ storeVersion: number;
280
+ }
281
+
282
+ export interface BoxxyAttemptWakeRequestedPayload {
283
+ attempt: string;
284
+ by: 'command' | 'session-ran' | 'host-slept-unasked';
285
+ storeVersion: number;
286
+ }
287
+
288
+ export interface BoxxyAttemptWokenPayload {
289
+ attempt: string;
290
+ holdGen: number;
291
+ seats: BoxxyAttemptWokenPayloadSeatsItem[];
292
+ overCap: boolean;
293
+ storeVersion: number;
294
+ }
295
+
296
+ export interface BoxxyAttemptWokenPayloadSeatsItem {
297
+ limit: string;
298
+ }
299
+
300
+ export interface BoxxyAttemptResumedPayload {
301
+ attempt: string;
302
+ atcSession: string;
303
+ caller: BoxxyAttemptResumedPayloadCaller | null;
304
+ storeVersion: number;
305
+ }
306
+
307
+ export interface BoxxyAttemptResumedPayloadCaller {
308
+ issuer: string;
309
+ subject: string;
310
+ }
311
+
312
+ export interface BoxxyAttemptClosedOutPayload {
313
+ attempt: string;
314
+ phase: string;
315
+ closeOut: unknown;
316
+ hash: string;
317
+ storeVersion: number;
318
+ }
319
+
320
+ export interface BoxxyAttemptTimedOutPayload {
321
+ attempt: string;
322
+ phase: string;
323
+ afterMinutes: number;
324
+ storeVersion: number;
325
+ }
326
+
327
+ export interface BoxxyAttemptTurnEndedPayload {
328
+ attempt: string;
329
+ phase: string;
330
+ storeVersion: number;
331
+ }
332
+
333
+ export interface BoxxyAttemptSettledPayload {
334
+ attempt: string;
335
+ phase: string;
336
+ round: number;
337
+ state: 'succeeded' | 'failed';
338
+ failure: string | null;
339
+ outcome: string;
340
+ returnedOutcome: string | null;
341
+ closing: 'closed-out' | 'timed-out' | 'item-closed' | 'stalled' | 'skill-missing' | 'turn-ended' | 'usage-limit' | null;
342
+ asleep: boolean;
343
+ sessionStopped: boolean;
344
+ endedAt: number;
345
+ criteria: BoxxyAttemptSettledPayloadCriteriaItem[];
346
+ matched: string[];
347
+ frictionDropped: number;
348
+ skippedEffects: BoxxyAttemptSettledPayloadSkippedEffectsItem[];
349
+ storeVersion: number;
350
+ }
351
+
352
+ export interface BoxxyAttemptSettledPayloadCriteriaItem {
353
+ criterion: string;
354
+ evidence: string[];
355
+ }
356
+
357
+ export interface BoxxyAttemptSettledPayloadSkippedEffectsItem {
358
+ effect: 'file-item' | 'close-item' | 'add-relation' | 'set-kind' | 'set-field' | 'set-acceptance' | 'record-proposal';
359
+ reason: string;
360
+ }
361
+
362
+ export interface BoxxyProposalRecordedPayload {
363
+ target: BoxxyProposalRecordedPayloadTarget;
364
+ change: string;
365
+ attempt: string;
366
+ storeVersion: number;
367
+ }
368
+
369
+ export interface BoxxyProposalRecordedPayloadTarget {
370
+ kind: 'skill' | 'rule' | 'lint' | 'agents-md' | 'tool';
371
+ name: string;
372
+ }
373
+
374
+ export interface BoxxyEvidenceRecordedPayload {
375
+ attempt: string;
376
+ kind: 'pull_request' | 'commit' | 'test' | 'ci-run' | 'live-check';
377
+ ref: string;
378
+ observed: string | null;
379
+ storeVersion: number;
380
+ }
381
+
382
+ export interface BoxxyPullRequestLinkedPayload {
383
+ attempt: string;
384
+ repo: string;
385
+ number: number;
386
+ url: string;
387
+ pullRequestId: string;
388
+ source: 'hook' | 'watch';
389
+ storeVersion: number;
390
+ }
391
+
392
+ export interface BoxxyCommitLinkedPayload {
393
+ attempt: string;
394
+ repo: string;
395
+ sha: string;
396
+ pullRequestNumber: number;
397
+ storeVersion: number;
398
+ }
399
+
400
+ export interface BoxxyPullRequestMergedPayload {
401
+ attempt: string;
402
+ repo: string;
403
+ number: number;
404
+ pullRequestId: string;
405
+ mergedAt: number;
406
+ mergeCommit: string;
407
+ storeVersion: number;
408
+ }
409
+
410
+ export interface BoxxyPullRequestClosedPayload {
411
+ attempt: string;
412
+ repo: string;
413
+ number: number;
414
+ pullRequestId: string;
415
+ storeVersion: number;
416
+ }
417
+
418
+ export type BoxxyWorkFact =
419
+ | { id: string; type: 'boxxy.item.filed'; entity: string; at: string; payload: BoxxyItemFiledPayload }
420
+ | { id: string; type: 'boxxy.item.noted'; entity: string; at: string; payload: BoxxyItemNotedPayload }
421
+ | { id: string; type: 'boxxy.item.edited'; entity: string; at: string; payload: BoxxyItemEditedPayload }
422
+ | { id: string; type: 'boxxy.item.closed'; entity: string; at: string; payload: BoxxyItemClosedPayload }
423
+ | { id: string; type: 'boxxy.relation.added'; entity: string; at: string; payload: BoxxyRelationAddedPayload }
424
+ | { id: string; type: 'boxxy.relation.removed'; entity: string; at: string; payload: BoxxyRelationRemovedPayload }
425
+ | { id: string; type: 'boxxy.lever.recorded'; entity: string; at: string; payload: BoxxyLeverRecordedPayload }
426
+ | { id: string; type: 'boxxy.attempt.claimed'; entity: string; at: string; payload: BoxxyAttemptClaimedPayload }
427
+ | { id: string; type: 'boxxy.decision.recorded'; entity: string; at: string; payload: BoxxyDecisionRecordedPayload }
428
+ | { id: string; type: 'boxxy.attempt.started'; entity: string; at: string; payload: BoxxyAttemptStartedPayload }
429
+ | { id: string; type: 'boxxy.attempt.spawn_unanswered'; entity: string; at: string; payload: BoxxyAttemptSpawnUnansweredPayload }
430
+ | { id: string; type: 'boxxy.attempt.reconciled'; entity: string; at: string; payload: BoxxyAttemptReconciledPayload }
431
+ | { id: string; type: 'boxxy.attempt.session_bound'; entity: string; at: string; payload: BoxxyAttemptSessionBoundPayload }
432
+ | { id: string; type: 'boxxy.attempt.slept'; entity: string; at: string; payload: BoxxyAttemptSleptPayload }
433
+ | { id: string; type: 'boxxy.attempt.wake_requested'; entity: string; at: string; payload: BoxxyAttemptWakeRequestedPayload }
434
+ | { id: string; type: 'boxxy.attempt.woken'; entity: string; at: string; payload: BoxxyAttemptWokenPayload }
435
+ | { id: string; type: 'boxxy.attempt.resumed'; entity: string; at: string; payload: BoxxyAttemptResumedPayload }
436
+ | { id: string; type: 'boxxy.attempt.closed_out'; entity: string; at: string; payload: BoxxyAttemptClosedOutPayload }
437
+ | { id: string; type: 'boxxy.attempt.timed_out'; entity: string; at: string; payload: BoxxyAttemptTimedOutPayload }
438
+ | { id: string; type: 'boxxy.attempt.turn_ended'; entity: string; at: string; payload: BoxxyAttemptTurnEndedPayload }
439
+ | { id: string; type: 'boxxy.attempt.settled'; entity: string; at: string; payload: BoxxyAttemptSettledPayload }
440
+ | { id: string; type: 'boxxy.proposal.recorded'; entity: string; at: string; payload: BoxxyProposalRecordedPayload }
441
+ | { id: string; type: 'boxxy.evidence.recorded'; entity: string; at: string; payload: BoxxyEvidenceRecordedPayload }
442
+ | { id: string; type: 'boxxy.pull_request.linked'; entity: string; at: string; payload: BoxxyPullRequestLinkedPayload }
443
+ | { id: string; type: 'boxxy.commit.linked'; entity: string; at: string; payload: BoxxyCommitLinkedPayload }
444
+ | { id: string; type: 'boxxy.pull_request.merged'; entity: string; at: string; payload: BoxxyPullRequestMergedPayload }
445
+ | { id: string; type: 'boxxy.pull_request.closed'; entity: string; at: string; payload: BoxxyPullRequestClosedPayload };
446
+
447
+ declare function readScopeFactsLength(scope: string): number;
448
+ declare function readScopeFactsInto(scope: string, facts: Uint8Array): void;
449
+
450
+ // every fact of the scope on the consumer's streams, one per fact ID, in the host's order
451
+ export function readScopeFacts(scope: BoxxyItemID): BoxxyWorkFact[] {
452
+ const buffer = new Uint8Array(readScopeFactsLength(scope));
453
+
454
+ readScopeFactsInto(scope, buffer);
455
+
456
+ const parsed: unknown = JSON.parse(new TextDecoder().decode(buffer));
457
+ const facts: BoxxyWorkFact[] = [];
458
+
459
+ if (!Array.isArray(parsed)) {
460
+ return facts;
461
+ }
462
+
463
+ for (let index = 0; index < parsed.length; index += 1) {
464
+ const decoded = decodeBoxxyWorkFact(parsed[index]);
465
+
466
+ if (decoded !== undefined) {
467
+ facts.push(decoded);
468
+ }
469
+ }
470
+
471
+ return facts;
472
+ }
473
+
474
+ function decodeBoxxyWorkFact(value: unknown): BoxxyWorkFact | undefined {
475
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
476
+ return undefined;
477
+ }
478
+
479
+ const id = 'id' in value ? value.id : undefined;
480
+ const type = 'type' in value ? value.type : undefined;
481
+ const entity = 'entity' in value ? value.entity : undefined;
482
+ const at = 'at' in value ? value.at : undefined;
483
+ const payload = 'payload' in value ? value.payload : undefined;
484
+
485
+ if (typeof id !== 'string' || typeof entity !== 'string' || typeof at !== 'string') {
486
+ return undefined;
487
+ }
488
+
489
+ if (type === 'boxxy.item.filed') {
490
+ const decoded = decodeBoxxyItemFiledPayload(payload);
491
+
492
+ if (decoded === undefined) {
493
+ return undefined;
494
+ }
495
+
496
+ return { id, type, entity, at, payload: decoded };
497
+ }
498
+
499
+ if (type === 'boxxy.item.noted') {
500
+ const decoded = decodeBoxxyItemNotedPayload(payload);
501
+
502
+ if (decoded === undefined) {
503
+ return undefined;
504
+ }
505
+
506
+ return { id, type, entity, at, payload: decoded };
507
+ }
508
+
509
+ if (type === 'boxxy.item.edited') {
510
+ const decoded = decodeBoxxyItemEditedPayload(payload);
511
+
512
+ if (decoded === undefined) {
513
+ return undefined;
514
+ }
515
+
516
+ return { id, type, entity, at, payload: decoded };
517
+ }
518
+
519
+ if (type === 'boxxy.item.closed') {
520
+ const decoded = decodeBoxxyItemClosedPayload(payload);
521
+
522
+ if (decoded === undefined) {
523
+ return undefined;
524
+ }
525
+
526
+ return { id, type, entity, at, payload: decoded };
527
+ }
528
+
529
+ if (type === 'boxxy.relation.added') {
530
+ const decoded = decodeBoxxyRelationAddedPayload(payload);
531
+
532
+ if (decoded === undefined) {
533
+ return undefined;
534
+ }
535
+
536
+ return { id, type, entity, at, payload: decoded };
537
+ }
538
+
539
+ if (type === 'boxxy.relation.removed') {
540
+ const decoded = decodeBoxxyRelationRemovedPayload(payload);
541
+
542
+ if (decoded === undefined) {
543
+ return undefined;
544
+ }
545
+
546
+ return { id, type, entity, at, payload: decoded };
547
+ }
548
+
549
+ if (type === 'boxxy.lever.recorded') {
550
+ const decoded = decodeBoxxyLeverRecordedPayload(payload);
551
+
552
+ if (decoded === undefined) {
553
+ return undefined;
554
+ }
555
+
556
+ return { id, type, entity, at, payload: decoded };
557
+ }
558
+
559
+ if (type === 'boxxy.attempt.claimed') {
560
+ const decoded = decodeBoxxyAttemptClaimedPayload(payload);
561
+
562
+ if (decoded === undefined) {
563
+ return undefined;
564
+ }
565
+
566
+ return { id, type, entity, at, payload: decoded };
567
+ }
568
+
569
+ if (type === 'boxxy.decision.recorded') {
570
+ const decoded = decodeBoxxyDecisionRecordedPayload(payload);
571
+
572
+ if (decoded === undefined) {
573
+ return undefined;
574
+ }
575
+
576
+ return { id, type, entity, at, payload: decoded };
577
+ }
578
+
579
+ if (type === 'boxxy.attempt.started') {
580
+ const decoded = decodeBoxxyAttemptStartedPayload(payload);
581
+
582
+ if (decoded === undefined) {
583
+ return undefined;
584
+ }
585
+
586
+ return { id, type, entity, at, payload: decoded };
587
+ }
588
+
589
+ if (type === 'boxxy.attempt.spawn_unanswered') {
590
+ const decoded = decodeBoxxyAttemptSpawnUnansweredPayload(payload);
591
+
592
+ if (decoded === undefined) {
593
+ return undefined;
594
+ }
595
+
596
+ return { id, type, entity, at, payload: decoded };
597
+ }
598
+
599
+ if (type === 'boxxy.attempt.reconciled') {
600
+ const decoded = decodeBoxxyAttemptReconciledPayload(payload);
601
+
602
+ if (decoded === undefined) {
603
+ return undefined;
604
+ }
605
+
606
+ return { id, type, entity, at, payload: decoded };
607
+ }
608
+
609
+ if (type === 'boxxy.attempt.session_bound') {
610
+ const decoded = decodeBoxxyAttemptSessionBoundPayload(payload);
611
+
612
+ if (decoded === undefined) {
613
+ return undefined;
614
+ }
615
+
616
+ return { id, type, entity, at, payload: decoded };
617
+ }
618
+
619
+ if (type === 'boxxy.attempt.slept') {
620
+ const decoded = decodeBoxxyAttemptSleptPayload(payload);
621
+
622
+ if (decoded === undefined) {
623
+ return undefined;
624
+ }
625
+
626
+ return { id, type, entity, at, payload: decoded };
627
+ }
628
+
629
+ if (type === 'boxxy.attempt.wake_requested') {
630
+ const decoded = decodeBoxxyAttemptWakeRequestedPayload(payload);
631
+
632
+ if (decoded === undefined) {
633
+ return undefined;
634
+ }
635
+
636
+ return { id, type, entity, at, payload: decoded };
637
+ }
638
+
639
+ if (type === 'boxxy.attempt.woken') {
640
+ const decoded = decodeBoxxyAttemptWokenPayload(payload);
641
+
642
+ if (decoded === undefined) {
643
+ return undefined;
644
+ }
645
+
646
+ return { id, type, entity, at, payload: decoded };
647
+ }
648
+
649
+ if (type === 'boxxy.attempt.resumed') {
650
+ const decoded = decodeBoxxyAttemptResumedPayload(payload);
651
+
652
+ if (decoded === undefined) {
653
+ return undefined;
654
+ }
655
+
656
+ return { id, type, entity, at, payload: decoded };
657
+ }
658
+
659
+ if (type === 'boxxy.attempt.closed_out') {
660
+ const decoded = decodeBoxxyAttemptClosedOutPayload(payload);
661
+
662
+ if (decoded === undefined) {
663
+ return undefined;
664
+ }
665
+
666
+ return { id, type, entity, at, payload: decoded };
667
+ }
668
+
669
+ if (type === 'boxxy.attempt.timed_out') {
670
+ const decoded = decodeBoxxyAttemptTimedOutPayload(payload);
671
+
672
+ if (decoded === undefined) {
673
+ return undefined;
674
+ }
675
+
676
+ return { id, type, entity, at, payload: decoded };
677
+ }
678
+
679
+ if (type === 'boxxy.attempt.turn_ended') {
680
+ const decoded = decodeBoxxyAttemptTurnEndedPayload(payload);
681
+
682
+ if (decoded === undefined) {
683
+ return undefined;
684
+ }
685
+
686
+ return { id, type, entity, at, payload: decoded };
687
+ }
688
+
689
+ if (type === 'boxxy.attempt.settled') {
690
+ const decoded = decodeBoxxyAttemptSettledPayload(payload);
691
+
692
+ if (decoded === undefined) {
693
+ return undefined;
694
+ }
695
+
696
+ return { id, type, entity, at, payload: decoded };
697
+ }
698
+
699
+ if (type === 'boxxy.proposal.recorded') {
700
+ const decoded = decodeBoxxyProposalRecordedPayload(payload);
701
+
702
+ if (decoded === undefined) {
703
+ return undefined;
704
+ }
705
+
706
+ return { id, type, entity, at, payload: decoded };
707
+ }
708
+
709
+ if (type === 'boxxy.evidence.recorded') {
710
+ const decoded = decodeBoxxyEvidenceRecordedPayload(payload);
711
+
712
+ if (decoded === undefined) {
713
+ return undefined;
714
+ }
715
+
716
+ return { id, type, entity, at, payload: decoded };
717
+ }
718
+
719
+ if (type === 'boxxy.pull_request.linked') {
720
+ const decoded = decodeBoxxyPullRequestLinkedPayload(payload);
721
+
722
+ if (decoded === undefined) {
723
+ return undefined;
724
+ }
725
+
726
+ return { id, type, entity, at, payload: decoded };
727
+ }
728
+
729
+ if (type === 'boxxy.commit.linked') {
730
+ const decoded = decodeBoxxyCommitLinkedPayload(payload);
731
+
732
+ if (decoded === undefined) {
733
+ return undefined;
734
+ }
735
+
736
+ return { id, type, entity, at, payload: decoded };
737
+ }
738
+
739
+ if (type === 'boxxy.pull_request.merged') {
740
+ const decoded = decodeBoxxyPullRequestMergedPayload(payload);
741
+
742
+ if (decoded === undefined) {
743
+ return undefined;
744
+ }
745
+
746
+ return { id, type, entity, at, payload: decoded };
747
+ }
748
+
749
+ if (type === 'boxxy.pull_request.closed') {
750
+ const decoded = decodeBoxxyPullRequestClosedPayload(payload);
751
+
752
+ if (decoded === undefined) {
753
+ return undefined;
754
+ }
755
+
756
+ return { id, type, entity, at, payload: decoded };
757
+ }
758
+
759
+ return undefined;
760
+ }
761
+
762
+ function decodeBoxxyItemFiledPayload(value: unknown): BoxxyItemFiledPayload | undefined {
763
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
764
+ return undefined;
765
+ }
766
+
767
+ const raw0 = 'id' in value ? value.id : undefined;
768
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
769
+
770
+ if (field0 === undefined) {
771
+ return undefined;
772
+ }
773
+
774
+ const raw1 = 'kind' in value ? value.kind : undefined;
775
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
776
+
777
+ if (field1 === undefined) {
778
+ return undefined;
779
+ }
780
+
781
+ const raw2 = 'repo' in value ? value.repo : undefined;
782
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
783
+
784
+ if (field2 === undefined) {
785
+ return undefined;
786
+ }
787
+
788
+ const raw3 = 'title' in value ? value.title : undefined;
789
+ const field3 = typeof raw3 === 'string' ? raw3 : undefined;
790
+
791
+ if (field3 === undefined) {
792
+ return undefined;
793
+ }
794
+
795
+ const raw4 = 'outcome' in value ? value.outcome : undefined;
796
+ const field4 = typeof raw4 === 'string' ? raw4 : undefined;
797
+
798
+ if (field4 === undefined) {
799
+ return undefined;
800
+ }
801
+
802
+ const raw5 = 'acceptance' in value ? value.acceptance : undefined;
803
+ const field5 = decodeBoxxyItemFiledPayloadAcceptance(raw5);
804
+
805
+ if (field5 === undefined) {
806
+ return undefined;
807
+ }
808
+
809
+ const raw6 = 'fields' in value ? value.fields : undefined;
810
+ const field6 = decodeBoxxyItemFiledPayloadFields(raw6);
811
+
812
+ if (field6 === undefined) {
813
+ return undefined;
814
+ }
815
+
816
+ const raw7 = 'labels' in value ? value.labels : undefined;
817
+ const field7 = decodeBoxxyItemFiledPayloadLabels(raw7);
818
+
819
+ if (field7 === undefined) {
820
+ return undefined;
821
+ }
822
+
823
+ const raw8 = 'foundInAttempt' in value ? value.foundInAttempt : undefined;
824
+ const field8 = raw8 === null ? null : typeof raw8 === 'string' ? raw8 : undefined;
825
+
826
+ if (field8 === undefined) {
827
+ return undefined;
828
+ }
829
+
830
+ const field9 = 'filedBy' in value ? value.filedBy : undefined;
831
+
832
+ const raw10 = 'filedAt' in value ? value.filedAt : undefined;
833
+ const field10 = typeof raw10 === 'number' ? raw10 : undefined;
834
+
835
+ if (field10 === undefined) {
836
+ return undefined;
837
+ }
838
+
839
+ const raw11 = 'closedAt' in value ? value.closedAt : undefined;
840
+ const field11 = raw11 === null ? null : typeof raw11 === 'number' ? raw11 : undefined;
841
+
842
+ if (field11 === undefined) {
843
+ return undefined;
844
+ }
845
+
846
+ const raw12 = 'closeReason' in value ? value.closeReason : undefined;
847
+ const field12 = raw12 === null ? null : typeof raw12 === 'string' ? raw12 : undefined;
848
+
849
+ if (field12 === undefined) {
850
+ return undefined;
851
+ }
852
+
853
+ const raw13 = 'storeVersion' in value ? value.storeVersion : undefined;
854
+ const field13 = typeof raw13 === 'number' ? raw13 : undefined;
855
+
856
+ if (field13 === undefined) {
857
+ return undefined;
858
+ }
859
+
860
+ return {
861
+ id: field0,
862
+ kind: field1,
863
+ repo: field2,
864
+ title: field3,
865
+ outcome: field4,
866
+ acceptance: field5,
867
+ fields: field6,
868
+ labels: field7,
869
+ foundInAttempt: field8,
870
+ filedBy: field9,
871
+ filedAt: field10,
872
+ closedAt: field11,
873
+ closeReason: field12,
874
+ storeVersion: field13,
875
+ };
876
+ }
877
+
878
+ function decodeBoxxyItemFiledPayloadAcceptance(value: unknown): BoxxyItemFiledPayloadAcceptanceItem[] | undefined {
879
+ if (!Array.isArray(value)) {
880
+ return undefined;
881
+ }
882
+
883
+ const items: BoxxyItemFiledPayloadAcceptanceItem[] = [];
884
+
885
+ for (let index = 0; index < value.length; index += 1) {
886
+ const element: unknown = value[index];
887
+ const item = decodeBoxxyItemFiledPayloadAcceptanceItem(element);
888
+
889
+ if (item === undefined) {
890
+ return undefined;
891
+ }
892
+
893
+ items.push(item);
894
+ }
895
+
896
+ return items;
897
+ }
898
+
899
+ function decodeBoxxyItemFiledPayloadAcceptanceItem(value: unknown): BoxxyItemFiledPayloadAcceptanceItem | undefined {
900
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
901
+ return undefined;
902
+ }
903
+
904
+ const raw0 = 'id' in value ? value.id : undefined;
905
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
906
+
907
+ if (field0 === undefined) {
908
+ return undefined;
909
+ }
910
+
911
+ const raw1 = 'text' in value ? value.text : undefined;
912
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
913
+
914
+ if (field1 === undefined) {
915
+ return undefined;
916
+ }
917
+
918
+ const raw2 = 'evidence' in value ? value.evidence : undefined;
919
+ const field2 = decodeBoxxyItemFiledPayloadAcceptanceItemEvidence(raw2);
920
+
921
+ if (field2 === undefined) {
922
+ return undefined;
923
+ }
924
+
925
+ return {
926
+ id: field0,
927
+ text: field1,
928
+ evidence: field2,
929
+ };
930
+ }
931
+
932
+ function decodeBoxxyItemFiledPayloadAcceptanceItemEvidence(value: unknown): string[] | undefined {
933
+ if (!Array.isArray(value)) {
934
+ return undefined;
935
+ }
936
+
937
+ const items: string[] = [];
938
+
939
+ for (let index = 0; index < value.length; index += 1) {
940
+ const element: unknown = value[index];
941
+ const item = typeof element === 'string' ? element : undefined;
942
+
943
+ if (item === undefined) {
944
+ return undefined;
945
+ }
946
+
947
+ items.push(item);
948
+ }
949
+
950
+ return items;
951
+ }
952
+
953
+ function decodeBoxxyItemFiledPayloadFields(value: unknown): BoxxyItemFiledPayloadFields | undefined {
954
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
955
+ return undefined;
956
+ }
957
+
958
+ const field0 = 'designMode' in value ? value.designMode : undefined;
959
+
960
+ return {
961
+ designMode: field0,
962
+ };
963
+ }
964
+
965
+ function decodeBoxxyItemFiledPayloadLabels(value: unknown): string[] | undefined {
966
+ if (!Array.isArray(value)) {
967
+ return undefined;
968
+ }
969
+
970
+ const items: string[] = [];
971
+
972
+ for (let index = 0; index < value.length; index += 1) {
973
+ const element: unknown = value[index];
974
+ const item = typeof element === 'string' ? element : undefined;
975
+
976
+ if (item === undefined) {
977
+ return undefined;
978
+ }
979
+
980
+ items.push(item);
981
+ }
982
+
983
+ return items;
984
+ }
985
+
986
+ function decodeBoxxyItemNotedPayload(value: unknown): BoxxyItemNotedPayload | undefined {
987
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
988
+ return undefined;
989
+ }
990
+
991
+ const raw0 = 'seq' in value ? value.seq : undefined;
992
+ const field0 = typeof raw0 === 'number' ? raw0 : undefined;
993
+
994
+ if (field0 === undefined) {
995
+ return undefined;
996
+ }
997
+
998
+ const raw1 = 'text' in value ? value.text : undefined;
999
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1000
+
1001
+ if (field1 === undefined) {
1002
+ return undefined;
1003
+ }
1004
+
1005
+ const raw2 = 'storeVersion' in value ? value.storeVersion : undefined;
1006
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
1007
+
1008
+ if (field2 === undefined) {
1009
+ return undefined;
1010
+ }
1011
+
1012
+ return {
1013
+ seq: field0,
1014
+ text: field1,
1015
+ storeVersion: field2,
1016
+ };
1017
+ }
1018
+
1019
+ function decodeBoxxyItemEditedPayload(value: unknown): BoxxyItemEditedPayload | undefined {
1020
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1021
+ return undefined;
1022
+ }
1023
+
1024
+ const field0 = 'title' in value ? value.title : undefined;
1025
+
1026
+ const field1 = 'outcome' in value ? value.outcome : undefined;
1027
+
1028
+ const field2 = 'acceptance' in value ? value.acceptance : undefined;
1029
+
1030
+ const field3 = 'kind' in value ? value.kind : undefined;
1031
+
1032
+ const field4 = 'fields' in value ? value.fields : undefined;
1033
+
1034
+ const field5 = 'labels' in value ? value.labels : undefined;
1035
+
1036
+ const raw6 = 'byAttempt' in value ? value.byAttempt : undefined;
1037
+ const field6 = raw6 === null ? null : typeof raw6 === 'string' ? raw6 : undefined;
1038
+
1039
+ if (field6 === undefined) {
1040
+ return undefined;
1041
+ }
1042
+
1043
+ const raw7 = 'storeVersion' in value ? value.storeVersion : undefined;
1044
+ const field7 = typeof raw7 === 'number' ? raw7 : undefined;
1045
+
1046
+ if (field7 === undefined) {
1047
+ return undefined;
1048
+ }
1049
+
1050
+ return {
1051
+ title: field0,
1052
+ outcome: field1,
1053
+ acceptance: field2,
1054
+ kind: field3,
1055
+ fields: field4,
1056
+ labels: field5,
1057
+ byAttempt: field6,
1058
+ storeVersion: field7,
1059
+ };
1060
+ }
1061
+
1062
+ function decodeBoxxyItemClosedPayload(value: unknown): BoxxyItemClosedPayload | undefined {
1063
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1064
+ return undefined;
1065
+ }
1066
+
1067
+ const raw0 = 'reason' in value ? value.reason : undefined;
1068
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1069
+
1070
+ if (field0 === undefined) {
1071
+ return undefined;
1072
+ }
1073
+
1074
+ const raw1 = 'byAttempt' in value ? value.byAttempt : undefined;
1075
+ const field1 = raw1 === null ? null : typeof raw1 === 'string' ? raw1 : undefined;
1076
+
1077
+ if (field1 === undefined) {
1078
+ return undefined;
1079
+ }
1080
+
1081
+ const raw2 = 'ended' in value ? value.ended : undefined;
1082
+ const field2 = decodeBoxxyItemClosedPayloadEnded(raw2);
1083
+
1084
+ if (field2 === undefined) {
1085
+ return undefined;
1086
+ }
1087
+
1088
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
1089
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
1090
+
1091
+ if (field3 === undefined) {
1092
+ return undefined;
1093
+ }
1094
+
1095
+ return {
1096
+ reason: field0,
1097
+ byAttempt: field1,
1098
+ ended: field2,
1099
+ storeVersion: field3,
1100
+ };
1101
+ }
1102
+
1103
+ function decodeBoxxyItemClosedPayloadEnded(value: unknown): BoxxyItemClosedPayloadEndedItem[] | undefined {
1104
+ if (!Array.isArray(value)) {
1105
+ return undefined;
1106
+ }
1107
+
1108
+ const items: BoxxyItemClosedPayloadEndedItem[] = [];
1109
+
1110
+ for (let index = 0; index < value.length; index += 1) {
1111
+ const element: unknown = value[index];
1112
+ const item = decodeBoxxyItemClosedPayloadEndedItem(element);
1113
+
1114
+ if (item === undefined) {
1115
+ return undefined;
1116
+ }
1117
+
1118
+ items.push(item);
1119
+ }
1120
+
1121
+ return items;
1122
+ }
1123
+
1124
+ function decodeBoxxyItemClosedPayloadEndedItem(value: unknown): BoxxyItemClosedPayloadEndedItem | undefined {
1125
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1126
+ return undefined;
1127
+ }
1128
+
1129
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1130
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1131
+
1132
+ if (field0 === undefined) {
1133
+ return undefined;
1134
+ }
1135
+
1136
+ const raw1 = 'how' in value ? value.how : undefined;
1137
+ const field1 = raw1 === 'settled' || raw1 === 'closing' ? raw1 : undefined;
1138
+
1139
+ if (field1 === undefined) {
1140
+ return undefined;
1141
+ }
1142
+
1143
+ return {
1144
+ attempt: field0,
1145
+ how: field1,
1146
+ };
1147
+ }
1148
+
1149
+ function decodeBoxxyRelationAddedPayload(value: unknown): BoxxyRelationAddedPayload | undefined {
1150
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1151
+ return undefined;
1152
+ }
1153
+
1154
+ const raw0 = 'source' in value ? value.source : undefined;
1155
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1156
+
1157
+ if (field0 === undefined) {
1158
+ return undefined;
1159
+ }
1160
+
1161
+ const raw1 = 'target' in value ? value.target : undefined;
1162
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1163
+
1164
+ if (field1 === undefined) {
1165
+ return undefined;
1166
+ }
1167
+
1168
+ const raw2 = 'type' in value ? value.type : undefined;
1169
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
1170
+
1171
+ if (field2 === undefined) {
1172
+ return undefined;
1173
+ }
1174
+
1175
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
1176
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
1177
+
1178
+ if (field3 === undefined) {
1179
+ return undefined;
1180
+ }
1181
+
1182
+ return {
1183
+ source: field0,
1184
+ target: field1,
1185
+ type: field2,
1186
+ storeVersion: field3,
1187
+ };
1188
+ }
1189
+
1190
+ function decodeBoxxyRelationRemovedPayload(value: unknown): BoxxyRelationRemovedPayload | undefined {
1191
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1192
+ return undefined;
1193
+ }
1194
+
1195
+ const raw0 = 'source' in value ? value.source : undefined;
1196
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1197
+
1198
+ if (field0 === undefined) {
1199
+ return undefined;
1200
+ }
1201
+
1202
+ const raw1 = 'target' in value ? value.target : undefined;
1203
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1204
+
1205
+ if (field1 === undefined) {
1206
+ return undefined;
1207
+ }
1208
+
1209
+ const raw2 = 'type' in value ? value.type : undefined;
1210
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
1211
+
1212
+ if (field2 === undefined) {
1213
+ return undefined;
1214
+ }
1215
+
1216
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
1217
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
1218
+
1219
+ if (field3 === undefined) {
1220
+ return undefined;
1221
+ }
1222
+
1223
+ return {
1224
+ source: field0,
1225
+ target: field1,
1226
+ type: field2,
1227
+ storeVersion: field3,
1228
+ };
1229
+ }
1230
+
1231
+ function decodeBoxxyLeverRecordedPayload(value: unknown): BoxxyLeverRecordedPayload | undefined {
1232
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1233
+ return undefined;
1234
+ }
1235
+
1236
+ const raw0 = 'seq' in value ? value.seq : undefined;
1237
+ const field0 = typeof raw0 === 'number' ? raw0 : undefined;
1238
+
1239
+ if (field0 === undefined) {
1240
+ return undefined;
1241
+ }
1242
+
1243
+ const field1 = 'kind' in value ? value.kind : undefined;
1244
+
1245
+ const raw2 = 'item' in value ? value.item : undefined;
1246
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
1247
+
1248
+ if (field2 === undefined) {
1249
+ return undefined;
1250
+ }
1251
+
1252
+ const raw3 = 'until' in value ? value.until : undefined;
1253
+ const field3 = raw3 === null ? null : typeof raw3 === 'number' ? raw3 : undefined;
1254
+
1255
+ if (field3 === undefined) {
1256
+ return undefined;
1257
+ }
1258
+
1259
+ const raw4 = 'expiresAt' in value ? value.expiresAt : undefined;
1260
+ const field4 = raw4 === null ? null : typeof raw4 === 'number' ? raw4 : undefined;
1261
+
1262
+ if (field4 === undefined) {
1263
+ return undefined;
1264
+ }
1265
+
1266
+ const raw5 = 'reason' in value ? value.reason : undefined;
1267
+ const field5 = raw5 === null ? null : typeof raw5 === 'string' ? raw5 : undefined;
1268
+
1269
+ if (field5 === undefined) {
1270
+ return undefined;
1271
+ }
1272
+
1273
+ const raw6 = 'phase' in value ? value.phase : undefined;
1274
+ const field6 = raw6 === null ? null : typeof raw6 === 'string' ? raw6 : undefined;
1275
+
1276
+ if (field6 === undefined) {
1277
+ return undefined;
1278
+ }
1279
+
1280
+ const field7 = 'actor' in value ? value.actor : undefined;
1281
+
1282
+ const raw8 = 'at' in value ? value.at : undefined;
1283
+ const field8 = typeof raw8 === 'number' ? raw8 : undefined;
1284
+
1285
+ if (field8 === undefined) {
1286
+ return undefined;
1287
+ }
1288
+
1289
+ const raw9 = 'storeVersion' in value ? value.storeVersion : undefined;
1290
+ const field9 = typeof raw9 === 'number' ? raw9 : undefined;
1291
+
1292
+ if (field9 === undefined) {
1293
+ return undefined;
1294
+ }
1295
+
1296
+ return {
1297
+ seq: field0,
1298
+ kind: field1,
1299
+ item: field2,
1300
+ until: field3,
1301
+ expiresAt: field4,
1302
+ reason: field5,
1303
+ phase: field6,
1304
+ actor: field7,
1305
+ at: field8,
1306
+ storeVersion: field9,
1307
+ };
1308
+ }
1309
+
1310
+ function decodeBoxxyAttemptClaimedPayload(value: unknown): BoxxyAttemptClaimedPayload | undefined {
1311
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1312
+ return undefined;
1313
+ }
1314
+
1315
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1316
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1317
+
1318
+ if (field0 === undefined) {
1319
+ return undefined;
1320
+ }
1321
+
1322
+ const raw1 = 'phase' in value ? value.phase : undefined;
1323
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1324
+
1325
+ if (field1 === undefined) {
1326
+ return undefined;
1327
+ }
1328
+
1329
+ const raw2 = 'number' in value ? value.number : undefined;
1330
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
1331
+
1332
+ if (field2 === undefined) {
1333
+ return undefined;
1334
+ }
1335
+
1336
+ const raw3 = 'round' in value ? value.round : undefined;
1337
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
1338
+
1339
+ if (field3 === undefined) {
1340
+ return undefined;
1341
+ }
1342
+
1343
+ const raw4 = 'mode' in value ? value.mode : undefined;
1344
+ const field4 = raw4 === 'agent' || raw4 === 'attended' ? raw4 : undefined;
1345
+
1346
+ if (field4 === undefined) {
1347
+ return undefined;
1348
+ }
1349
+
1350
+ const raw5 = 'pool' in value ? value.pool : undefined;
1351
+ const field5 = typeof raw5 === 'string' ? raw5 : undefined;
1352
+
1353
+ if (field5 === undefined) {
1354
+ return undefined;
1355
+ }
1356
+
1357
+ const field6 = 'fields' in value ? value.fields : undefined;
1358
+
1359
+ const raw7 = 'seats' in value ? value.seats : undefined;
1360
+ const field7 = decodeBoxxyAttemptClaimedPayloadSeats(raw7);
1361
+
1362
+ if (field7 === undefined) {
1363
+ return undefined;
1364
+ }
1365
+
1366
+ const raw8 = 'recipeHash' in value ? value.recipeHash : undefined;
1367
+ const field8 = typeof raw8 === 'string' ? raw8 : undefined;
1368
+
1369
+ if (field8 === undefined) {
1370
+ return undefined;
1371
+ }
1372
+
1373
+ const raw9 = 'skillsRef' in value ? value.skillsRef : undefined;
1374
+ const field9 = raw9 === null ? null : typeof raw9 === 'string' ? raw9 : undefined;
1375
+
1376
+ if (field9 === undefined) {
1377
+ return undefined;
1378
+ }
1379
+
1380
+ const raw10 = 'rulesVersion' in value ? value.rulesVersion : undefined;
1381
+ const field10 = typeof raw10 === 'string' ? raw10 : undefined;
1382
+
1383
+ if (field10 === undefined) {
1384
+ return undefined;
1385
+ }
1386
+
1387
+ const raw11 = 'storeVersion' in value ? value.storeVersion : undefined;
1388
+ const field11 = typeof raw11 === 'number' ? raw11 : undefined;
1389
+
1390
+ if (field11 === undefined) {
1391
+ return undefined;
1392
+ }
1393
+
1394
+ return {
1395
+ attempt: field0,
1396
+ phase: field1,
1397
+ number: field2,
1398
+ round: field3,
1399
+ mode: field4,
1400
+ pool: field5,
1401
+ fields: field6,
1402
+ seats: field7,
1403
+ recipeHash: field8,
1404
+ skillsRef: field9,
1405
+ rulesVersion: field10,
1406
+ storeVersion: field11,
1407
+ };
1408
+ }
1409
+
1410
+ function decodeBoxxyAttemptClaimedPayloadSeats(value: unknown): BoxxyAttemptClaimedPayloadSeatsItem[] | undefined {
1411
+ if (!Array.isArray(value)) {
1412
+ return undefined;
1413
+ }
1414
+
1415
+ const items: BoxxyAttemptClaimedPayloadSeatsItem[] = [];
1416
+
1417
+ for (let index = 0; index < value.length; index += 1) {
1418
+ const element: unknown = value[index];
1419
+ const item = decodeBoxxyAttemptClaimedPayloadSeatsItem(element);
1420
+
1421
+ if (item === undefined) {
1422
+ return undefined;
1423
+ }
1424
+
1425
+ items.push(item);
1426
+ }
1427
+
1428
+ return items;
1429
+ }
1430
+
1431
+ function decodeBoxxyAttemptClaimedPayloadSeatsItem(value: unknown): BoxxyAttemptClaimedPayloadSeatsItem | undefined {
1432
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1433
+ return undefined;
1434
+ }
1435
+
1436
+ const raw0 = 'limit' in value ? value.limit : undefined;
1437
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1438
+
1439
+ if (field0 === undefined) {
1440
+ return undefined;
1441
+ }
1442
+
1443
+ return {
1444
+ limit: field0,
1445
+ };
1446
+ }
1447
+
1448
+ function decodeBoxxyDecisionRecordedPayload(value: unknown): BoxxyDecisionRecordedPayload | undefined {
1449
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1450
+ return undefined;
1451
+ }
1452
+
1453
+ const raw0 = 'id' in value ? value.id : undefined;
1454
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1455
+
1456
+ if (field0 === undefined) {
1457
+ return undefined;
1458
+ }
1459
+
1460
+ const raw1 = 'attempt' in value ? value.attempt : undefined;
1461
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1462
+
1463
+ if (field1 === undefined) {
1464
+ return undefined;
1465
+ }
1466
+
1467
+ const raw2 = 'item' in value ? value.item : undefined;
1468
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
1469
+
1470
+ if (field2 === undefined) {
1471
+ return undefined;
1472
+ }
1473
+
1474
+ const raw3 = 'kind' in value ? value.kind : undefined;
1475
+ const field3 = raw3 === 'start' || raw3 === 'wake' ? raw3 : undefined;
1476
+
1477
+ if (field3 === undefined) {
1478
+ return undefined;
1479
+ }
1480
+
1481
+ const raw4 = 'pool' in value ? value.pool : undefined;
1482
+ const field4 = typeof raw4 === 'string' ? raw4 : undefined;
1483
+
1484
+ if (field4 === undefined) {
1485
+ return undefined;
1486
+ }
1487
+
1488
+ const raw5 = 'rulesVersion' in value ? value.rulesVersion : undefined;
1489
+ const field5 = typeof raw5 === 'string' ? raw5 : undefined;
1490
+
1491
+ if (field5 === undefined) {
1492
+ return undefined;
1493
+ }
1494
+
1495
+ const raw6 = 'snapshotHash' in value ? value.snapshotHash : undefined;
1496
+ const field6 = typeof raw6 === 'string' ? raw6 : undefined;
1497
+
1498
+ if (field6 === undefined) {
1499
+ return undefined;
1500
+ }
1501
+
1502
+ const raw7 = 'storeVersion' in value ? value.storeVersion : undefined;
1503
+ const field7 = typeof raw7 === 'number' ? raw7 : undefined;
1504
+
1505
+ if (field7 === undefined) {
1506
+ return undefined;
1507
+ }
1508
+
1509
+ const field8 = 'pepysOffsets' in value ? value.pepysOffsets : undefined;
1510
+
1511
+ const raw9 = 'faults' in value ? value.faults : undefined;
1512
+ const field9 = decodeBoxxyDecisionRecordedPayloadFaults(raw9);
1513
+
1514
+ if (field9 === undefined) {
1515
+ return undefined;
1516
+ }
1517
+
1518
+ const raw10 = 'limits' in value ? value.limits : undefined;
1519
+ const field10 = decodeBoxxyDecisionRecordedPayloadLimits(raw10);
1520
+
1521
+ if (field10 === undefined) {
1522
+ return undefined;
1523
+ }
1524
+
1525
+ const raw11 = 'at' in value ? value.at : undefined;
1526
+ const field11 = typeof raw11 === 'number' ? raw11 : undefined;
1527
+
1528
+ if (field11 === undefined) {
1529
+ return undefined;
1530
+ }
1531
+
1532
+ return {
1533
+ id: field0,
1534
+ attempt: field1,
1535
+ item: field2,
1536
+ kind: field3,
1537
+ pool: field4,
1538
+ rulesVersion: field5,
1539
+ snapshotHash: field6,
1540
+ storeVersion: field7,
1541
+ pepysOffsets: field8,
1542
+ faults: field9,
1543
+ limits: field10,
1544
+ at: field11,
1545
+ };
1546
+ }
1547
+
1548
+ function decodeBoxxyDecisionRecordedPayloadFaults(value: unknown): BoxxyDecisionRecordedPayloadFaultsItem[] | undefined {
1549
+ if (!Array.isArray(value)) {
1550
+ return undefined;
1551
+ }
1552
+
1553
+ const items: BoxxyDecisionRecordedPayloadFaultsItem[] = [];
1554
+
1555
+ for (let index = 0; index < value.length; index += 1) {
1556
+ const element: unknown = value[index];
1557
+ const item = decodeBoxxyDecisionRecordedPayloadFaultsItem(element);
1558
+
1559
+ if (item === undefined) {
1560
+ return undefined;
1561
+ }
1562
+
1563
+ items.push(item);
1564
+ }
1565
+
1566
+ return items;
1567
+ }
1568
+
1569
+ function decodeBoxxyDecisionRecordedPayloadFaultsItem(value: unknown): BoxxyDecisionRecordedPayloadFaultsItem | undefined {
1570
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1571
+ return undefined;
1572
+ }
1573
+
1574
+ const raw0 = 'plugin' in value ? value.plugin : undefined;
1575
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1576
+
1577
+ if (field0 === undefined) {
1578
+ return undefined;
1579
+ }
1580
+
1581
+ const raw1 = 'kind' in value ? value.kind : undefined;
1582
+ const field1 = raw1 === 'signal' || raw1 === 'gate' || raw1 === 'waiver' || raw1 === 'admission' || raw1 === 'propagation' || raw1 === 'filter-field' ? raw1 : undefined;
1583
+
1584
+ if (field1 === undefined) {
1585
+ return undefined;
1586
+ }
1587
+
1588
+ const raw2 = 'item' in value ? value.item : undefined;
1589
+ const field2 = raw2 === null ? null : typeof raw2 === 'string' ? raw2 : undefined;
1590
+
1591
+ if (field2 === undefined) {
1592
+ return undefined;
1593
+ }
1594
+
1595
+ const raw3 = 'error' in value ? value.error : undefined;
1596
+ const field3 = typeof raw3 === 'string' ? raw3 : undefined;
1597
+
1598
+ if (field3 === undefined) {
1599
+ return undefined;
1600
+ }
1601
+
1602
+ return {
1603
+ plugin: field0,
1604
+ kind: field1,
1605
+ item: field2,
1606
+ error: field3,
1607
+ };
1608
+ }
1609
+
1610
+ function decodeBoxxyDecisionRecordedPayloadLimits(value: unknown): BoxxyDecisionRecordedPayloadLimitsItem[] | undefined {
1611
+ if (!Array.isArray(value)) {
1612
+ return undefined;
1613
+ }
1614
+
1615
+ const items: BoxxyDecisionRecordedPayloadLimitsItem[] = [];
1616
+
1617
+ for (let index = 0; index < value.length; index += 1) {
1618
+ const element: unknown = value[index];
1619
+ const item = decodeBoxxyDecisionRecordedPayloadLimitsItem(element);
1620
+
1621
+ if (item === undefined) {
1622
+ return undefined;
1623
+ }
1624
+
1625
+ items.push(item);
1626
+ }
1627
+
1628
+ return items;
1629
+ }
1630
+
1631
+ function decodeBoxxyDecisionRecordedPayloadLimitsItem(value: unknown): BoxxyDecisionRecordedPayloadLimitsItem | undefined {
1632
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1633
+ return undefined;
1634
+ }
1635
+
1636
+ const raw0 = 'limit' in value ? value.limit : undefined;
1637
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1638
+
1639
+ if (field0 === undefined) {
1640
+ return undefined;
1641
+ }
1642
+
1643
+ const raw1 = 'held' in value ? value.held : undefined;
1644
+ const field1 = typeof raw1 === 'number' ? raw1 : undefined;
1645
+
1646
+ if (field1 === undefined) {
1647
+ return undefined;
1648
+ }
1649
+
1650
+ const raw2 = 'max' in value ? value.max : undefined;
1651
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
1652
+
1653
+ if (field2 === undefined) {
1654
+ return undefined;
1655
+ }
1656
+
1657
+ return {
1658
+ limit: field0,
1659
+ held: field1,
1660
+ max: field2,
1661
+ };
1662
+ }
1663
+
1664
+ function decodeBoxxyAttemptStartedPayload(value: unknown): BoxxyAttemptStartedPayload | undefined {
1665
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1666
+ return undefined;
1667
+ }
1668
+
1669
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1670
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1671
+
1672
+ if (field0 === undefined) {
1673
+ return undefined;
1674
+ }
1675
+
1676
+ const raw1 = 'atcSession' in value ? value.atcSession : undefined;
1677
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1678
+
1679
+ if (field1 === undefined) {
1680
+ return undefined;
1681
+ }
1682
+
1683
+ const raw2 = 'resumeFallback' in value ? value.resumeFallback : undefined;
1684
+ const field2 = typeof raw2 === 'boolean' ? raw2 : undefined;
1685
+
1686
+ if (field2 === undefined) {
1687
+ return undefined;
1688
+ }
1689
+
1690
+ const raw3 = 'caller' in value ? value.caller : undefined;
1691
+ const field3 = raw3 === null ? null : decodeBoxxyAttemptStartedPayloadCaller(raw3);
1692
+
1693
+ if (field3 === undefined) {
1694
+ return undefined;
1695
+ }
1696
+
1697
+ const raw4 = 'storeVersion' in value ? value.storeVersion : undefined;
1698
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
1699
+
1700
+ if (field4 === undefined) {
1701
+ return undefined;
1702
+ }
1703
+
1704
+ return {
1705
+ attempt: field0,
1706
+ atcSession: field1,
1707
+ resumeFallback: field2,
1708
+ caller: field3,
1709
+ storeVersion: field4,
1710
+ };
1711
+ }
1712
+
1713
+ function decodeBoxxyAttemptStartedPayloadCaller(value: unknown): BoxxyAttemptStartedPayloadCaller | undefined {
1714
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1715
+ return undefined;
1716
+ }
1717
+
1718
+ const raw0 = 'issuer' in value ? value.issuer : undefined;
1719
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1720
+
1721
+ if (field0 === undefined) {
1722
+ return undefined;
1723
+ }
1724
+
1725
+ const raw1 = 'subject' in value ? value.subject : undefined;
1726
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1727
+
1728
+ if (field1 === undefined) {
1729
+ return undefined;
1730
+ }
1731
+
1732
+ return {
1733
+ issuer: field0,
1734
+ subject: field1,
1735
+ };
1736
+ }
1737
+
1738
+ function decodeBoxxyAttemptSpawnUnansweredPayload(value: unknown): BoxxyAttemptSpawnUnansweredPayload | undefined {
1739
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1740
+ return undefined;
1741
+ }
1742
+
1743
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1744
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1745
+
1746
+ if (field0 === undefined) {
1747
+ return undefined;
1748
+ }
1749
+
1750
+ const raw1 = 'reason' in value ? value.reason : undefined;
1751
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1752
+
1753
+ if (field1 === undefined) {
1754
+ return undefined;
1755
+ }
1756
+
1757
+ const raw2 = 'storeVersion' in value ? value.storeVersion : undefined;
1758
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
1759
+
1760
+ if (field2 === undefined) {
1761
+ return undefined;
1762
+ }
1763
+
1764
+ return {
1765
+ attempt: field0,
1766
+ reason: field1,
1767
+ storeVersion: field2,
1768
+ };
1769
+ }
1770
+
1771
+ function decodeBoxxyAttemptReconciledPayload(value: unknown): BoxxyAttemptReconciledPayload | undefined {
1772
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1773
+ return undefined;
1774
+ }
1775
+
1776
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1777
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1778
+
1779
+ if (field0 === undefined) {
1780
+ return undefined;
1781
+ }
1782
+
1783
+ const raw1 = 'atcSession' in value ? value.atcSession : undefined;
1784
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1785
+
1786
+ if (field1 === undefined) {
1787
+ return undefined;
1788
+ }
1789
+
1790
+ const raw2 = 'caller' in value ? value.caller : undefined;
1791
+ const field2 = raw2 === null ? null : decodeBoxxyAttemptReconciledPayloadCaller(raw2);
1792
+
1793
+ if (field2 === undefined) {
1794
+ return undefined;
1795
+ }
1796
+
1797
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
1798
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
1799
+
1800
+ if (field3 === undefined) {
1801
+ return undefined;
1802
+ }
1803
+
1804
+ return {
1805
+ attempt: field0,
1806
+ atcSession: field1,
1807
+ caller: field2,
1808
+ storeVersion: field3,
1809
+ };
1810
+ }
1811
+
1812
+ function decodeBoxxyAttemptReconciledPayloadCaller(value: unknown): BoxxyAttemptReconciledPayloadCaller | undefined {
1813
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1814
+ return undefined;
1815
+ }
1816
+
1817
+ const raw0 = 'issuer' in value ? value.issuer : undefined;
1818
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1819
+
1820
+ if (field0 === undefined) {
1821
+ return undefined;
1822
+ }
1823
+
1824
+ const raw1 = 'subject' in value ? value.subject : undefined;
1825
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1826
+
1827
+ if (field1 === undefined) {
1828
+ return undefined;
1829
+ }
1830
+
1831
+ return {
1832
+ issuer: field0,
1833
+ subject: field1,
1834
+ };
1835
+ }
1836
+
1837
+ function decodeBoxxyAttemptSessionBoundPayload(value: unknown): BoxxyAttemptSessionBoundPayload | undefined {
1838
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1839
+ return undefined;
1840
+ }
1841
+
1842
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1843
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1844
+
1845
+ if (field0 === undefined) {
1846
+ return undefined;
1847
+ }
1848
+
1849
+ const raw1 = 'atcSession' in value ? value.atcSession : undefined;
1850
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
1851
+
1852
+ if (field1 === undefined) {
1853
+ return undefined;
1854
+ }
1855
+
1856
+ const raw2 = 'agentSession' in value ? value.agentSession : undefined;
1857
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
1858
+
1859
+ if (field2 === undefined) {
1860
+ return undefined;
1861
+ }
1862
+
1863
+ const raw3 = 'product' in value ? value.product : undefined;
1864
+ const field3 = raw3 === 'claude_code' || raw3 === 'codex' ? raw3 : undefined;
1865
+
1866
+ if (field3 === undefined) {
1867
+ return undefined;
1868
+ }
1869
+
1870
+ const raw4 = 'source' in value ? value.source : undefined;
1871
+ const field4 = raw4 === 'worker' || raw4 === 'hook' ? raw4 : undefined;
1872
+
1873
+ if (field4 === undefined) {
1874
+ return undefined;
1875
+ }
1876
+
1877
+ const raw5 = 'seenAt' in value ? value.seenAt : undefined;
1878
+ const field5 = typeof raw5 === 'number' ? raw5 : undefined;
1879
+
1880
+ if (field5 === undefined) {
1881
+ return undefined;
1882
+ }
1883
+
1884
+ const raw6 = 'storeVersion' in value ? value.storeVersion : undefined;
1885
+ const field6 = typeof raw6 === 'number' ? raw6 : undefined;
1886
+
1887
+ if (field6 === undefined) {
1888
+ return undefined;
1889
+ }
1890
+
1891
+ return {
1892
+ attempt: field0,
1893
+ atcSession: field1,
1894
+ agentSession: field2,
1895
+ product: field3,
1896
+ source: field4,
1897
+ seenAt: field5,
1898
+ storeVersion: field6,
1899
+ };
1900
+ }
1901
+
1902
+ function decodeBoxxyAttemptSleptPayload(value: unknown): BoxxyAttemptSleptPayload | undefined {
1903
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1904
+ return undefined;
1905
+ }
1906
+
1907
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1908
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1909
+
1910
+ if (field0 === undefined) {
1911
+ return undefined;
1912
+ }
1913
+
1914
+ const raw1 = 'idleSince' in value ? value.idleSince : undefined;
1915
+ const field1 = typeof raw1 === 'number' ? raw1 : undefined;
1916
+
1917
+ if (field1 === undefined) {
1918
+ return undefined;
1919
+ }
1920
+
1921
+ const raw2 = 'asked' in value ? value.asked : undefined;
1922
+ const field2 = typeof raw2 === 'boolean' ? raw2 : undefined;
1923
+
1924
+ if (field2 === undefined) {
1925
+ return undefined;
1926
+ }
1927
+
1928
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
1929
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
1930
+
1931
+ if (field3 === undefined) {
1932
+ return undefined;
1933
+ }
1934
+
1935
+ return {
1936
+ attempt: field0,
1937
+ idleSince: field1,
1938
+ asked: field2,
1939
+ storeVersion: field3,
1940
+ };
1941
+ }
1942
+
1943
+ function decodeBoxxyAttemptWakeRequestedPayload(value: unknown): BoxxyAttemptWakeRequestedPayload | undefined {
1944
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1945
+ return undefined;
1946
+ }
1947
+
1948
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1949
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1950
+
1951
+ if (field0 === undefined) {
1952
+ return undefined;
1953
+ }
1954
+
1955
+ const raw1 = 'by' in value ? value.by : undefined;
1956
+ const field1 = raw1 === 'command' || raw1 === 'session-ran' || raw1 === 'host-slept-unasked' ? raw1 : undefined;
1957
+
1958
+ if (field1 === undefined) {
1959
+ return undefined;
1960
+ }
1961
+
1962
+ const raw2 = 'storeVersion' in value ? value.storeVersion : undefined;
1963
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
1964
+
1965
+ if (field2 === undefined) {
1966
+ return undefined;
1967
+ }
1968
+
1969
+ return {
1970
+ attempt: field0,
1971
+ by: field1,
1972
+ storeVersion: field2,
1973
+ };
1974
+ }
1975
+
1976
+ function decodeBoxxyAttemptWokenPayload(value: unknown): BoxxyAttemptWokenPayload | undefined {
1977
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
1978
+ return undefined;
1979
+ }
1980
+
1981
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
1982
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
1983
+
1984
+ if (field0 === undefined) {
1985
+ return undefined;
1986
+ }
1987
+
1988
+ const raw1 = 'holdGen' in value ? value.holdGen : undefined;
1989
+ const field1 = typeof raw1 === 'number' ? raw1 : undefined;
1990
+
1991
+ if (field1 === undefined) {
1992
+ return undefined;
1993
+ }
1994
+
1995
+ const raw2 = 'seats' in value ? value.seats : undefined;
1996
+ const field2 = decodeBoxxyAttemptWokenPayloadSeats(raw2);
1997
+
1998
+ if (field2 === undefined) {
1999
+ return undefined;
2000
+ }
2001
+
2002
+ const raw3 = 'overCap' in value ? value.overCap : undefined;
2003
+ const field3 = typeof raw3 === 'boolean' ? raw3 : undefined;
2004
+
2005
+ if (field3 === undefined) {
2006
+ return undefined;
2007
+ }
2008
+
2009
+ const raw4 = 'storeVersion' in value ? value.storeVersion : undefined;
2010
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
2011
+
2012
+ if (field4 === undefined) {
2013
+ return undefined;
2014
+ }
2015
+
2016
+ return {
2017
+ attempt: field0,
2018
+ holdGen: field1,
2019
+ seats: field2,
2020
+ overCap: field3,
2021
+ storeVersion: field4,
2022
+ };
2023
+ }
2024
+
2025
+ function decodeBoxxyAttemptWokenPayloadSeats(value: unknown): BoxxyAttemptWokenPayloadSeatsItem[] | undefined {
2026
+ if (!Array.isArray(value)) {
2027
+ return undefined;
2028
+ }
2029
+
2030
+ const items: BoxxyAttemptWokenPayloadSeatsItem[] = [];
2031
+
2032
+ for (let index = 0; index < value.length; index += 1) {
2033
+ const element: unknown = value[index];
2034
+ const item = decodeBoxxyAttemptWokenPayloadSeatsItem(element);
2035
+
2036
+ if (item === undefined) {
2037
+ return undefined;
2038
+ }
2039
+
2040
+ items.push(item);
2041
+ }
2042
+
2043
+ return items;
2044
+ }
2045
+
2046
+ function decodeBoxxyAttemptWokenPayloadSeatsItem(value: unknown): BoxxyAttemptWokenPayloadSeatsItem | undefined {
2047
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2048
+ return undefined;
2049
+ }
2050
+
2051
+ const raw0 = 'limit' in value ? value.limit : undefined;
2052
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2053
+
2054
+ if (field0 === undefined) {
2055
+ return undefined;
2056
+ }
2057
+
2058
+ return {
2059
+ limit: field0,
2060
+ };
2061
+ }
2062
+
2063
+ function decodeBoxxyAttemptResumedPayload(value: unknown): BoxxyAttemptResumedPayload | undefined {
2064
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2065
+ return undefined;
2066
+ }
2067
+
2068
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2069
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2070
+
2071
+ if (field0 === undefined) {
2072
+ return undefined;
2073
+ }
2074
+
2075
+ const raw1 = 'atcSession' in value ? value.atcSession : undefined;
2076
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2077
+
2078
+ if (field1 === undefined) {
2079
+ return undefined;
2080
+ }
2081
+
2082
+ const raw2 = 'caller' in value ? value.caller : undefined;
2083
+ const field2 = raw2 === null ? null : decodeBoxxyAttemptResumedPayloadCaller(raw2);
2084
+
2085
+ if (field2 === undefined) {
2086
+ return undefined;
2087
+ }
2088
+
2089
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
2090
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
2091
+
2092
+ if (field3 === undefined) {
2093
+ return undefined;
2094
+ }
2095
+
2096
+ return {
2097
+ attempt: field0,
2098
+ atcSession: field1,
2099
+ caller: field2,
2100
+ storeVersion: field3,
2101
+ };
2102
+ }
2103
+
2104
+ function decodeBoxxyAttemptResumedPayloadCaller(value: unknown): BoxxyAttemptResumedPayloadCaller | undefined {
2105
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2106
+ return undefined;
2107
+ }
2108
+
2109
+ const raw0 = 'issuer' in value ? value.issuer : undefined;
2110
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2111
+
2112
+ if (field0 === undefined) {
2113
+ return undefined;
2114
+ }
2115
+
2116
+ const raw1 = 'subject' in value ? value.subject : undefined;
2117
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2118
+
2119
+ if (field1 === undefined) {
2120
+ return undefined;
2121
+ }
2122
+
2123
+ return {
2124
+ issuer: field0,
2125
+ subject: field1,
2126
+ };
2127
+ }
2128
+
2129
+ function decodeBoxxyAttemptClosedOutPayload(value: unknown): BoxxyAttemptClosedOutPayload | undefined {
2130
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2131
+ return undefined;
2132
+ }
2133
+
2134
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2135
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2136
+
2137
+ if (field0 === undefined) {
2138
+ return undefined;
2139
+ }
2140
+
2141
+ const raw1 = 'phase' in value ? value.phase : undefined;
2142
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2143
+
2144
+ if (field1 === undefined) {
2145
+ return undefined;
2146
+ }
2147
+
2148
+ const field2 = 'closeOut' in value ? value.closeOut : undefined;
2149
+
2150
+ const raw3 = 'hash' in value ? value.hash : undefined;
2151
+ const field3 = typeof raw3 === 'string' ? raw3 : undefined;
2152
+
2153
+ if (field3 === undefined) {
2154
+ return undefined;
2155
+ }
2156
+
2157
+ const raw4 = 'storeVersion' in value ? value.storeVersion : undefined;
2158
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
2159
+
2160
+ if (field4 === undefined) {
2161
+ return undefined;
2162
+ }
2163
+
2164
+ return {
2165
+ attempt: field0,
2166
+ phase: field1,
2167
+ closeOut: field2,
2168
+ hash: field3,
2169
+ storeVersion: field4,
2170
+ };
2171
+ }
2172
+
2173
+ function decodeBoxxyAttemptTimedOutPayload(value: unknown): BoxxyAttemptTimedOutPayload | undefined {
2174
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2175
+ return undefined;
2176
+ }
2177
+
2178
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2179
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2180
+
2181
+ if (field0 === undefined) {
2182
+ return undefined;
2183
+ }
2184
+
2185
+ const raw1 = 'phase' in value ? value.phase : undefined;
2186
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2187
+
2188
+ if (field1 === undefined) {
2189
+ return undefined;
2190
+ }
2191
+
2192
+ const raw2 = 'afterMinutes' in value ? value.afterMinutes : undefined;
2193
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
2194
+
2195
+ if (field2 === undefined) {
2196
+ return undefined;
2197
+ }
2198
+
2199
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
2200
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
2201
+
2202
+ if (field3 === undefined) {
2203
+ return undefined;
2204
+ }
2205
+
2206
+ return {
2207
+ attempt: field0,
2208
+ phase: field1,
2209
+ afterMinutes: field2,
2210
+ storeVersion: field3,
2211
+ };
2212
+ }
2213
+
2214
+ function decodeBoxxyAttemptTurnEndedPayload(value: unknown): BoxxyAttemptTurnEndedPayload | undefined {
2215
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2216
+ return undefined;
2217
+ }
2218
+
2219
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2220
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2221
+
2222
+ if (field0 === undefined) {
2223
+ return undefined;
2224
+ }
2225
+
2226
+ const raw1 = 'phase' in value ? value.phase : undefined;
2227
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2228
+
2229
+ if (field1 === undefined) {
2230
+ return undefined;
2231
+ }
2232
+
2233
+ const raw2 = 'storeVersion' in value ? value.storeVersion : undefined;
2234
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
2235
+
2236
+ if (field2 === undefined) {
2237
+ return undefined;
2238
+ }
2239
+
2240
+ return {
2241
+ attempt: field0,
2242
+ phase: field1,
2243
+ storeVersion: field2,
2244
+ };
2245
+ }
2246
+
2247
+ function decodeBoxxyAttemptSettledPayload(value: unknown): BoxxyAttemptSettledPayload | undefined {
2248
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2249
+ return undefined;
2250
+ }
2251
+
2252
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2253
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2254
+
2255
+ if (field0 === undefined) {
2256
+ return undefined;
2257
+ }
2258
+
2259
+ const raw1 = 'phase' in value ? value.phase : undefined;
2260
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2261
+
2262
+ if (field1 === undefined) {
2263
+ return undefined;
2264
+ }
2265
+
2266
+ const raw2 = 'round' in value ? value.round : undefined;
2267
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
2268
+
2269
+ if (field2 === undefined) {
2270
+ return undefined;
2271
+ }
2272
+
2273
+ const raw3 = 'state' in value ? value.state : undefined;
2274
+ const field3 = raw3 === 'succeeded' || raw3 === 'failed' ? raw3 : undefined;
2275
+
2276
+ if (field3 === undefined) {
2277
+ return undefined;
2278
+ }
2279
+
2280
+ const raw4 = 'failure' in value ? value.failure : undefined;
2281
+ const field4 = raw4 === null ? null : typeof raw4 === 'string' ? raw4 : undefined;
2282
+
2283
+ if (field4 === undefined) {
2284
+ return undefined;
2285
+ }
2286
+
2287
+ const raw5 = 'outcome' in value ? value.outcome : undefined;
2288
+ const field5 = typeof raw5 === 'string' ? raw5 : undefined;
2289
+
2290
+ if (field5 === undefined) {
2291
+ return undefined;
2292
+ }
2293
+
2294
+ const raw6 = 'returnedOutcome' in value ? value.returnedOutcome : undefined;
2295
+ const field6 = raw6 === null ? null : typeof raw6 === 'string' ? raw6 : undefined;
2296
+
2297
+ if (field6 === undefined) {
2298
+ return undefined;
2299
+ }
2300
+
2301
+ const raw7 = 'closing' in value ? value.closing : undefined;
2302
+ const field7 = raw7 === null ? null : raw7 === 'closed-out' || raw7 === 'timed-out' || raw7 === 'item-closed' || raw7 === 'stalled' || raw7 === 'skill-missing' || raw7 === 'turn-ended' || raw7 === 'usage-limit' ? raw7 : undefined;
2303
+
2304
+ if (field7 === undefined) {
2305
+ return undefined;
2306
+ }
2307
+
2308
+ const raw8 = 'asleep' in value ? value.asleep : undefined;
2309
+ const field8 = typeof raw8 === 'boolean' ? raw8 : undefined;
2310
+
2311
+ if (field8 === undefined) {
2312
+ return undefined;
2313
+ }
2314
+
2315
+ const raw9 = 'sessionStopped' in value ? value.sessionStopped : undefined;
2316
+ const field9 = typeof raw9 === 'boolean' ? raw9 : undefined;
2317
+
2318
+ if (field9 === undefined) {
2319
+ return undefined;
2320
+ }
2321
+
2322
+ const raw10 = 'endedAt' in value ? value.endedAt : undefined;
2323
+ const field10 = typeof raw10 === 'number' ? raw10 : undefined;
2324
+
2325
+ if (field10 === undefined) {
2326
+ return undefined;
2327
+ }
2328
+
2329
+ const raw11 = 'criteria' in value ? value.criteria : undefined;
2330
+ const field11 = decodeBoxxyAttemptSettledPayloadCriteria(raw11);
2331
+
2332
+ if (field11 === undefined) {
2333
+ return undefined;
2334
+ }
2335
+
2336
+ const raw12 = 'matched' in value ? value.matched : undefined;
2337
+ const field12 = decodeBoxxyAttemptSettledPayloadMatched(raw12);
2338
+
2339
+ if (field12 === undefined) {
2340
+ return undefined;
2341
+ }
2342
+
2343
+ const raw13 = 'frictionDropped' in value ? value.frictionDropped : undefined;
2344
+ const field13 = typeof raw13 === 'number' ? raw13 : undefined;
2345
+
2346
+ if (field13 === undefined) {
2347
+ return undefined;
2348
+ }
2349
+
2350
+ const raw14 = 'skippedEffects' in value ? value.skippedEffects : undefined;
2351
+ const field14 = decodeBoxxyAttemptSettledPayloadSkippedEffects(raw14);
2352
+
2353
+ if (field14 === undefined) {
2354
+ return undefined;
2355
+ }
2356
+
2357
+ const raw15 = 'storeVersion' in value ? value.storeVersion : undefined;
2358
+ const field15 = typeof raw15 === 'number' ? raw15 : undefined;
2359
+
2360
+ if (field15 === undefined) {
2361
+ return undefined;
2362
+ }
2363
+
2364
+ return {
2365
+ attempt: field0,
2366
+ phase: field1,
2367
+ round: field2,
2368
+ state: field3,
2369
+ failure: field4,
2370
+ outcome: field5,
2371
+ returnedOutcome: field6,
2372
+ closing: field7,
2373
+ asleep: field8,
2374
+ sessionStopped: field9,
2375
+ endedAt: field10,
2376
+ criteria: field11,
2377
+ matched: field12,
2378
+ frictionDropped: field13,
2379
+ skippedEffects: field14,
2380
+ storeVersion: field15,
2381
+ };
2382
+ }
2383
+
2384
+ function decodeBoxxyAttemptSettledPayloadCriteria(value: unknown): BoxxyAttemptSettledPayloadCriteriaItem[] | undefined {
2385
+ if (!Array.isArray(value)) {
2386
+ return undefined;
2387
+ }
2388
+
2389
+ const items: BoxxyAttemptSettledPayloadCriteriaItem[] = [];
2390
+
2391
+ for (let index = 0; index < value.length; index += 1) {
2392
+ const element: unknown = value[index];
2393
+ const item = decodeBoxxyAttemptSettledPayloadCriteriaItem(element);
2394
+
2395
+ if (item === undefined) {
2396
+ return undefined;
2397
+ }
2398
+
2399
+ items.push(item);
2400
+ }
2401
+
2402
+ return items;
2403
+ }
2404
+
2405
+ function decodeBoxxyAttemptSettledPayloadCriteriaItem(value: unknown): BoxxyAttemptSettledPayloadCriteriaItem | undefined {
2406
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2407
+ return undefined;
2408
+ }
2409
+
2410
+ const raw0 = 'criterion' in value ? value.criterion : undefined;
2411
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2412
+
2413
+ if (field0 === undefined) {
2414
+ return undefined;
2415
+ }
2416
+
2417
+ const raw1 = 'evidence' in value ? value.evidence : undefined;
2418
+ const field1 = decodeBoxxyAttemptSettledPayloadCriteriaItemEvidence(raw1);
2419
+
2420
+ if (field1 === undefined) {
2421
+ return undefined;
2422
+ }
2423
+
2424
+ return {
2425
+ criterion: field0,
2426
+ evidence: field1,
2427
+ };
2428
+ }
2429
+
2430
+ function decodeBoxxyAttemptSettledPayloadCriteriaItemEvidence(value: unknown): string[] | undefined {
2431
+ if (!Array.isArray(value)) {
2432
+ return undefined;
2433
+ }
2434
+
2435
+ const items: string[] = [];
2436
+
2437
+ for (let index = 0; index < value.length; index += 1) {
2438
+ const element: unknown = value[index];
2439
+ const item = typeof element === 'string' ? element : undefined;
2440
+
2441
+ if (item === undefined) {
2442
+ return undefined;
2443
+ }
2444
+
2445
+ items.push(item);
2446
+ }
2447
+
2448
+ return items;
2449
+ }
2450
+
2451
+ function decodeBoxxyAttemptSettledPayloadMatched(value: unknown): string[] | undefined {
2452
+ if (!Array.isArray(value)) {
2453
+ return undefined;
2454
+ }
2455
+
2456
+ const items: string[] = [];
2457
+
2458
+ for (let index = 0; index < value.length; index += 1) {
2459
+ const element: unknown = value[index];
2460
+ const item = typeof element === 'string' ? element : undefined;
2461
+
2462
+ if (item === undefined) {
2463
+ return undefined;
2464
+ }
2465
+
2466
+ items.push(item);
2467
+ }
2468
+
2469
+ return items;
2470
+ }
2471
+
2472
+ function decodeBoxxyAttemptSettledPayloadSkippedEffects(value: unknown): BoxxyAttemptSettledPayloadSkippedEffectsItem[] | undefined {
2473
+ if (!Array.isArray(value)) {
2474
+ return undefined;
2475
+ }
2476
+
2477
+ const items: BoxxyAttemptSettledPayloadSkippedEffectsItem[] = [];
2478
+
2479
+ for (let index = 0; index < value.length; index += 1) {
2480
+ const element: unknown = value[index];
2481
+ const item = decodeBoxxyAttemptSettledPayloadSkippedEffectsItem(element);
2482
+
2483
+ if (item === undefined) {
2484
+ return undefined;
2485
+ }
2486
+
2487
+ items.push(item);
2488
+ }
2489
+
2490
+ return items;
2491
+ }
2492
+
2493
+ function decodeBoxxyAttemptSettledPayloadSkippedEffectsItem(value: unknown): BoxxyAttemptSettledPayloadSkippedEffectsItem | undefined {
2494
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2495
+ return undefined;
2496
+ }
2497
+
2498
+ const raw0 = 'effect' in value ? value.effect : undefined;
2499
+ const field0 = raw0 === 'file-item' || raw0 === 'close-item' || raw0 === 'add-relation' || raw0 === 'set-kind' || raw0 === 'set-field' || raw0 === 'set-acceptance' || raw0 === 'record-proposal' ? raw0 : undefined;
2500
+
2501
+ if (field0 === undefined) {
2502
+ return undefined;
2503
+ }
2504
+
2505
+ const raw1 = 'reason' in value ? value.reason : undefined;
2506
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2507
+
2508
+ if (field1 === undefined) {
2509
+ return undefined;
2510
+ }
2511
+
2512
+ return {
2513
+ effect: field0,
2514
+ reason: field1,
2515
+ };
2516
+ }
2517
+
2518
+ function decodeBoxxyProposalRecordedPayload(value: unknown): BoxxyProposalRecordedPayload | undefined {
2519
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2520
+ return undefined;
2521
+ }
2522
+
2523
+ const raw0 = 'target' in value ? value.target : undefined;
2524
+ const field0 = decodeBoxxyProposalRecordedPayloadTarget(raw0);
2525
+
2526
+ if (field0 === undefined) {
2527
+ return undefined;
2528
+ }
2529
+
2530
+ const raw1 = 'change' in value ? value.change : undefined;
2531
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2532
+
2533
+ if (field1 === undefined) {
2534
+ return undefined;
2535
+ }
2536
+
2537
+ const raw2 = 'attempt' in value ? value.attempt : undefined;
2538
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
2539
+
2540
+ if (field2 === undefined) {
2541
+ return undefined;
2542
+ }
2543
+
2544
+ const raw3 = 'storeVersion' in value ? value.storeVersion : undefined;
2545
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
2546
+
2547
+ if (field3 === undefined) {
2548
+ return undefined;
2549
+ }
2550
+
2551
+ return {
2552
+ target: field0,
2553
+ change: field1,
2554
+ attempt: field2,
2555
+ storeVersion: field3,
2556
+ };
2557
+ }
2558
+
2559
+ function decodeBoxxyProposalRecordedPayloadTarget(value: unknown): BoxxyProposalRecordedPayloadTarget | undefined {
2560
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2561
+ return undefined;
2562
+ }
2563
+
2564
+ const raw0 = 'kind' in value ? value.kind : undefined;
2565
+ const field0 = raw0 === 'skill' || raw0 === 'rule' || raw0 === 'lint' || raw0 === 'agents-md' || raw0 === 'tool' ? raw0 : undefined;
2566
+
2567
+ if (field0 === undefined) {
2568
+ return undefined;
2569
+ }
2570
+
2571
+ const raw1 = 'name' in value ? value.name : undefined;
2572
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2573
+
2574
+ if (field1 === undefined) {
2575
+ return undefined;
2576
+ }
2577
+
2578
+ return {
2579
+ kind: field0,
2580
+ name: field1,
2581
+ };
2582
+ }
2583
+
2584
+ function decodeBoxxyEvidenceRecordedPayload(value: unknown): BoxxyEvidenceRecordedPayload | undefined {
2585
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2586
+ return undefined;
2587
+ }
2588
+
2589
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2590
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2591
+
2592
+ if (field0 === undefined) {
2593
+ return undefined;
2594
+ }
2595
+
2596
+ const raw1 = 'kind' in value ? value.kind : undefined;
2597
+ const field1 = raw1 === 'pull_request' || raw1 === 'commit' || raw1 === 'test' || raw1 === 'ci-run' || raw1 === 'live-check' ? raw1 : undefined;
2598
+
2599
+ if (field1 === undefined) {
2600
+ return undefined;
2601
+ }
2602
+
2603
+ const raw2 = 'ref' in value ? value.ref : undefined;
2604
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
2605
+
2606
+ if (field2 === undefined) {
2607
+ return undefined;
2608
+ }
2609
+
2610
+ const raw3 = 'observed' in value ? value.observed : undefined;
2611
+ const field3 = raw3 === null ? null : typeof raw3 === 'string' ? raw3 : undefined;
2612
+
2613
+ if (field3 === undefined) {
2614
+ return undefined;
2615
+ }
2616
+
2617
+ const raw4 = 'storeVersion' in value ? value.storeVersion : undefined;
2618
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
2619
+
2620
+ if (field4 === undefined) {
2621
+ return undefined;
2622
+ }
2623
+
2624
+ return {
2625
+ attempt: field0,
2626
+ kind: field1,
2627
+ ref: field2,
2628
+ observed: field3,
2629
+ storeVersion: field4,
2630
+ };
2631
+ }
2632
+
2633
+ function decodeBoxxyPullRequestLinkedPayload(value: unknown): BoxxyPullRequestLinkedPayload | undefined {
2634
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2635
+ return undefined;
2636
+ }
2637
+
2638
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2639
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2640
+
2641
+ if (field0 === undefined) {
2642
+ return undefined;
2643
+ }
2644
+
2645
+ const raw1 = 'repo' in value ? value.repo : undefined;
2646
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2647
+
2648
+ if (field1 === undefined) {
2649
+ return undefined;
2650
+ }
2651
+
2652
+ const raw2 = 'number' in value ? value.number : undefined;
2653
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
2654
+
2655
+ if (field2 === undefined) {
2656
+ return undefined;
2657
+ }
2658
+
2659
+ const raw3 = 'url' in value ? value.url : undefined;
2660
+ const field3 = typeof raw3 === 'string' ? raw3 : undefined;
2661
+
2662
+ if (field3 === undefined) {
2663
+ return undefined;
2664
+ }
2665
+
2666
+ const raw4 = 'pullRequestId' in value ? value.pullRequestId : undefined;
2667
+ const field4 = typeof raw4 === 'string' ? raw4 : undefined;
2668
+
2669
+ if (field4 === undefined) {
2670
+ return undefined;
2671
+ }
2672
+
2673
+ const raw5 = 'source' in value ? value.source : undefined;
2674
+ const field5 = raw5 === 'hook' || raw5 === 'watch' ? raw5 : undefined;
2675
+
2676
+ if (field5 === undefined) {
2677
+ return undefined;
2678
+ }
2679
+
2680
+ const raw6 = 'storeVersion' in value ? value.storeVersion : undefined;
2681
+ const field6 = typeof raw6 === 'number' ? raw6 : undefined;
2682
+
2683
+ if (field6 === undefined) {
2684
+ return undefined;
2685
+ }
2686
+
2687
+ return {
2688
+ attempt: field0,
2689
+ repo: field1,
2690
+ number: field2,
2691
+ url: field3,
2692
+ pullRequestId: field4,
2693
+ source: field5,
2694
+ storeVersion: field6,
2695
+ };
2696
+ }
2697
+
2698
+ function decodeBoxxyCommitLinkedPayload(value: unknown): BoxxyCommitLinkedPayload | undefined {
2699
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2700
+ return undefined;
2701
+ }
2702
+
2703
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2704
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2705
+
2706
+ if (field0 === undefined) {
2707
+ return undefined;
2708
+ }
2709
+
2710
+ const raw1 = 'repo' in value ? value.repo : undefined;
2711
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2712
+
2713
+ if (field1 === undefined) {
2714
+ return undefined;
2715
+ }
2716
+
2717
+ const raw2 = 'sha' in value ? value.sha : undefined;
2718
+ const field2 = typeof raw2 === 'string' ? raw2 : undefined;
2719
+
2720
+ if (field2 === undefined) {
2721
+ return undefined;
2722
+ }
2723
+
2724
+ const raw3 = 'pullRequestNumber' in value ? value.pullRequestNumber : undefined;
2725
+ const field3 = typeof raw3 === 'number' ? raw3 : undefined;
2726
+
2727
+ if (field3 === undefined) {
2728
+ return undefined;
2729
+ }
2730
+
2731
+ const raw4 = 'storeVersion' in value ? value.storeVersion : undefined;
2732
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
2733
+
2734
+ if (field4 === undefined) {
2735
+ return undefined;
2736
+ }
2737
+
2738
+ return {
2739
+ attempt: field0,
2740
+ repo: field1,
2741
+ sha: field2,
2742
+ pullRequestNumber: field3,
2743
+ storeVersion: field4,
2744
+ };
2745
+ }
2746
+
2747
+ function decodeBoxxyPullRequestMergedPayload(value: unknown): BoxxyPullRequestMergedPayload | undefined {
2748
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2749
+ return undefined;
2750
+ }
2751
+
2752
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2753
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2754
+
2755
+ if (field0 === undefined) {
2756
+ return undefined;
2757
+ }
2758
+
2759
+ const raw1 = 'repo' in value ? value.repo : undefined;
2760
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2761
+
2762
+ if (field1 === undefined) {
2763
+ return undefined;
2764
+ }
2765
+
2766
+ const raw2 = 'number' in value ? value.number : undefined;
2767
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
2768
+
2769
+ if (field2 === undefined) {
2770
+ return undefined;
2771
+ }
2772
+
2773
+ const raw3 = 'pullRequestId' in value ? value.pullRequestId : undefined;
2774
+ const field3 = typeof raw3 === 'string' ? raw3 : undefined;
2775
+
2776
+ if (field3 === undefined) {
2777
+ return undefined;
2778
+ }
2779
+
2780
+ const raw4 = 'mergedAt' in value ? value.mergedAt : undefined;
2781
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
2782
+
2783
+ if (field4 === undefined) {
2784
+ return undefined;
2785
+ }
2786
+
2787
+ const raw5 = 'mergeCommit' in value ? value.mergeCommit : undefined;
2788
+ const field5 = typeof raw5 === 'string' ? raw5 : undefined;
2789
+
2790
+ if (field5 === undefined) {
2791
+ return undefined;
2792
+ }
2793
+
2794
+ const raw6 = 'storeVersion' in value ? value.storeVersion : undefined;
2795
+ const field6 = typeof raw6 === 'number' ? raw6 : undefined;
2796
+
2797
+ if (field6 === undefined) {
2798
+ return undefined;
2799
+ }
2800
+
2801
+ return {
2802
+ attempt: field0,
2803
+ repo: field1,
2804
+ number: field2,
2805
+ pullRequestId: field3,
2806
+ mergedAt: field4,
2807
+ mergeCommit: field5,
2808
+ storeVersion: field6,
2809
+ };
2810
+ }
2811
+
2812
+ function decodeBoxxyPullRequestClosedPayload(value: unknown): BoxxyPullRequestClosedPayload | undefined {
2813
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
2814
+ return undefined;
2815
+ }
2816
+
2817
+ const raw0 = 'attempt' in value ? value.attempt : undefined;
2818
+ const field0 = typeof raw0 === 'string' ? raw0 : undefined;
2819
+
2820
+ if (field0 === undefined) {
2821
+ return undefined;
2822
+ }
2823
+
2824
+ const raw1 = 'repo' in value ? value.repo : undefined;
2825
+ const field1 = typeof raw1 === 'string' ? raw1 : undefined;
2826
+
2827
+ if (field1 === undefined) {
2828
+ return undefined;
2829
+ }
2830
+
2831
+ const raw2 = 'number' in value ? value.number : undefined;
2832
+ const field2 = typeof raw2 === 'number' ? raw2 : undefined;
2833
+
2834
+ if (field2 === undefined) {
2835
+ return undefined;
2836
+ }
2837
+
2838
+ const raw3 = 'pullRequestId' in value ? value.pullRequestId : undefined;
2839
+ const field3 = typeof raw3 === 'string' ? raw3 : undefined;
2840
+
2841
+ if (field3 === undefined) {
2842
+ return undefined;
2843
+ }
2844
+
2845
+ const raw4 = 'storeVersion' in value ? value.storeVersion : undefined;
2846
+ const field4 = typeof raw4 === 'number' ? raw4 : undefined;
2847
+
2848
+ if (field4 === undefined) {
2849
+ return undefined;
2850
+ }
2851
+
2852
+ return {
2853
+ attempt: field0,
2854
+ repo: field1,
2855
+ number: field2,
2856
+ pullRequestId: field3,
2857
+ storeVersion: field4,
2858
+ };
2859
+ }
2860
+
2861
+ export interface BoxxyItemRow {
2862
+ id: BoxxyItemID;
2863
+ kind: string;
2864
+ repo: string;
2865
+ title: string;
2866
+ design_mode: string | null;
2867
+ filed_at: string;
2868
+ closed_at: string | null;
2869
+ close_reason: string | null;
2870
+ updated_at: string;
2871
+ }
2872
+
2873
+ export interface BoxxyAttemptRow {
2874
+ id: BoxxyAttemptID;
2875
+ item_id: EntityID;
2876
+ phase: string;
2877
+ number: number;
2878
+ round: number;
2879
+ mode: string;
2880
+ pool: string;
2881
+ recipe_hash: string;
2882
+ rules_version: string;
2883
+ atc_session: string | null;
2884
+ state: string;
2885
+ outcome: string | null;
2886
+ failure: string | null;
2887
+ claimed_at: string;
2888
+ started_at: string | null;
2889
+ closed_out_at: string | null;
2890
+ ended_at: string | null;
2891
+ sleeps: unknown;
2892
+ updated_at: string;
2893
+ }
2894
+
2895
+ export interface BoxxyAttemptSessionRow {
2896
+ attempt_id: EntityID;
2897
+ session_id: EntityID;
2898
+ key: string;
2899
+ product: string | null;
2900
+ caller_issuer: string | null;
2901
+ caller_subject: string | null;
2902
+ bound_at: string;
2903
+ }
2904
+
2905
+ export type BoxxyWorkOperation =
2906
+ | { upsert: { boxxy_item: BoxxyItemRow } }
2907
+ | { upsert: { boxxy_attempt: BoxxyAttemptRow } }
2908
+ | { upsert: { boxxy_attempt_session: BoxxyAttemptSessionRow } }
2909
+ | { link: { type: 'ran_in'; from: BoxxyAttemptID; to: TelemetrySessionID; confidence: number; evidence: string } }
2910
+ | { link: { type: 'produced'; from: BoxxyAttemptID; to: GithubPullRequestID; confidence: number; evidence: string } }
2911
+ | { link: { type: 'attempt_of'; from: BoxxyAttemptID; to: BoxxyItemID; confidence: number; evidence: string } };
2912
+
2913
+ export function linkRanIn(link: { from: BoxxyAttemptID; to: TelemetrySessionID; confidence: number; evidence: string }): BoxxyWorkOperation {
2914
+ return { link: { type: 'ran_in', from: link.from, to: link.to, confidence: link.confidence, evidence: link.evidence } };
2915
+ }
2916
+
2917
+ export function linkProduced(link: { from: BoxxyAttemptID; to: GithubPullRequestID; confidence: number; evidence: string }): BoxxyWorkOperation {
2918
+ return { link: { type: 'produced', from: link.from, to: link.to, confidence: link.confidence, evidence: link.evidence } };
2919
+ }
2920
+
2921
+ export function linkAttemptOf(link: { from: BoxxyAttemptID; to: BoxxyItemID; confidence: number; evidence: string }): BoxxyWorkOperation {
2922
+ return { link: { type: 'attempt_of', from: link.from, to: link.to, confidence: link.confidence, evidence: link.evidence } };
2923
+ }