@relayflows/sdk 2.0.35 → 2.0.36

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 (138) hide show
  1. package/dist/adapters/base.d.ts +16 -0
  2. package/dist/adapters/base.d.ts.map +1 -1
  3. package/dist/adapters/claude.d.ts.map +1 -1
  4. package/dist/adapters/claude.js +15 -0
  5. package/dist/adapters/claude.js.map +1 -1
  6. package/dist/adapters/codex.d.ts.map +1 -1
  7. package/dist/adapters/codex.js +4 -0
  8. package/dist/adapters/codex.js.map +1 -1
  9. package/dist/adapters/usage-limit.d.ts +2 -0
  10. package/dist/adapters/usage-limit.d.ts.map +1 -0
  11. package/dist/adapters/usage-limit.js +17 -0
  12. package/dist/adapters/usage-limit.js.map +1 -0
  13. package/dist/authored-activity.d.ts +17 -0
  14. package/dist/authored-activity.d.ts.map +1 -0
  15. package/dist/authored-activity.js +218 -0
  16. package/dist/authored-activity.js.map +1 -0
  17. package/dist/authored-child-run.d.ts +34 -0
  18. package/dist/authored-child-run.d.ts.map +1 -0
  19. package/dist/authored-child-run.js +128 -0
  20. package/dist/authored-child-run.js.map +1 -0
  21. package/dist/authored-flow-error.d.ts +32 -3
  22. package/dist/authored-flow-error.d.ts.map +1 -1
  23. package/dist/authored-flow-error.js +3 -1
  24. package/dist/authored-flow-error.js.map +1 -1
  25. package/dist/authored-flow-executor.d.ts +9 -1
  26. package/dist/authored-flow-executor.d.ts.map +1 -1
  27. package/dist/authored-flow-executor.js +30 -0
  28. package/dist/authored-flow-executor.js.map +1 -1
  29. package/dist/authored-mcp.js +2 -2
  30. package/dist/authored-mcp.js.map +1 -1
  31. package/dist/authored-node-entry.js +3 -1
  32. package/dist/authored-node-entry.js.map +1 -1
  33. package/dist/authored-node-runner.d.ts.map +1 -1
  34. package/dist/authored-node-runner.js +40 -8
  35. package/dist/authored-node-runner.js.map +1 -1
  36. package/dist/authored-plugin-effect.js +2 -2
  37. package/dist/authored-plugin-effect.js.map +1 -1
  38. package/dist/authored-root.d.ts +10 -7
  39. package/dist/authored-root.d.ts.map +1 -1
  40. package/dist/authored-root.js +19 -0
  41. package/dist/authored-root.js.map +1 -1
  42. package/dist/authored-step-output.d.ts +24 -8
  43. package/dist/authored-step-output.d.ts.map +1 -1
  44. package/dist/authored-step-output.js +81 -15
  45. package/dist/authored-step-output.js.map +1 -1
  46. package/dist/authored-subscription-park.d.ts +5 -0
  47. package/dist/authored-subscription-park.d.ts.map +1 -0
  48. package/dist/authored-subscription-park.js +47 -0
  49. package/dist/authored-subscription-park.js.map +1 -0
  50. package/dist/authored-worker-step.d.ts.map +1 -1
  51. package/dist/authored-worker-step.js +7 -2
  52. package/dist/authored-worker-step.js.map +1 -1
  53. package/dist/cli/check-activities.d.ts +8 -0
  54. package/dist/cli/check-activities.d.ts.map +1 -0
  55. package/dist/cli/check-activities.js +155 -0
  56. package/dist/cli/check-activities.js.map +1 -0
  57. package/dist/cli/cli-probe.d.ts.map +1 -1
  58. package/dist/cli/cli-probe.js +14 -2
  59. package/dist/cli/cli-probe.js.map +1 -1
  60. package/dist/cli/direct-run.d.ts.map +1 -1
  61. package/dist/cli/direct-run.js +10 -2
  62. package/dist/cli/direct-run.js.map +1 -1
  63. package/dist/cli/run.d.ts +18 -5
  64. package/dist/cli/run.d.ts.map +1 -1
  65. package/dist/cli/run.js +24 -5
  66. package/dist/cli/run.js.map +1 -1
  67. package/dist/cli/subscription-report.d.ts +5 -0
  68. package/dist/cli/subscription-report.d.ts.map +1 -0
  69. package/dist/cli/subscription-report.js +48 -0
  70. package/dist/cli/subscription-report.js.map +1 -0
  71. package/dist/cli-adapter.d.ts +4 -2
  72. package/dist/cli-adapter.d.ts.map +1 -1
  73. package/dist/cli-adapter.js +4 -0
  74. package/dist/cli-adapter.js.map +1 -1
  75. package/dist/cli.d.ts +1 -1
  76. package/dist/cli.d.ts.map +1 -1
  77. package/dist/cli.js +13 -5
  78. package/dist/cli.js.map +1 -1
  79. package/dist/failure-kinds.d.ts +2 -2
  80. package/dist/failure-kinds.d.ts.map +1 -1
  81. package/dist/failure-kinds.js +2 -0
  82. package/dist/failure-kinds.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/journal-client.d.ts +17 -2
  87. package/dist/journal-client.d.ts.map +1 -1
  88. package/dist/journal-client.js +33 -2
  89. package/dist/journal-client.js.map +1 -1
  90. package/dist/journal-reader.d.ts.map +1 -1
  91. package/dist/journal-reader.js +2 -0
  92. package/dist/journal-reader.js.map +1 -1
  93. package/dist/local-agent.d.ts +4 -1
  94. package/dist/local-agent.d.ts.map +1 -1
  95. package/dist/local-agent.js +14 -4
  96. package/dist/local-agent.js.map +1 -1
  97. package/dist/preflight.d.ts +6 -0
  98. package/dist/preflight.d.ts.map +1 -1
  99. package/dist/preflight.js +36 -10
  100. package/dist/preflight.js.map +1 -1
  101. package/dist/protocol.d.ts +166 -1
  102. package/dist/protocol.d.ts.map +1 -1
  103. package/dist/step-settling.d.ts +11 -0
  104. package/dist/step-settling.d.ts.map +1 -0
  105. package/dist/step-settling.js +22 -0
  106. package/dist/step-settling.js.map +1 -0
  107. package/package.json +2 -2
  108. package/src/adapters/base.ts +19 -0
  109. package/src/adapters/claude.ts +15 -0
  110. package/src/adapters/codex.ts +6 -0
  111. package/src/adapters/usage-limit.ts +17 -0
  112. package/src/authored-activity.ts +251 -0
  113. package/src/authored-child-run.ts +138 -0
  114. package/src/authored-flow-error.ts +33 -0
  115. package/src/authored-flow-executor.ts +40 -0
  116. package/src/authored-mcp.ts +2 -2
  117. package/src/authored-node-entry.ts +3 -1
  118. package/src/authored-node-runner.ts +41 -8
  119. package/src/authored-plugin-effect.ts +2 -2
  120. package/src/authored-root.ts +27 -4
  121. package/src/authored-step-output.ts +88 -15
  122. package/src/authored-subscription-park.ts +46 -0
  123. package/src/authored-worker-step.ts +7 -2
  124. package/src/cli/check-activities.ts +144 -0
  125. package/src/cli/cli-probe.ts +15 -3
  126. package/src/cli/direct-run.ts +9 -0
  127. package/src/cli/run.ts +46 -9
  128. package/src/cli/subscription-report.ts +51 -0
  129. package/src/cli-adapter.ts +8 -2
  130. package/src/cli.ts +13 -6
  131. package/src/failure-kinds.ts +2 -0
  132. package/src/index.ts +6 -0
  133. package/src/journal-client.ts +47 -3
  134. package/src/journal-reader.ts +2 -0
  135. package/src/local-agent.ts +17 -3
  136. package/src/preflight.ts +46 -10
  137. package/src/protocol.ts +129 -0
  138. package/src/step-settling.ts +19 -0
package/src/protocol.ts CHANGED
@@ -53,8 +53,16 @@ export type Verb =
53
53
  | 'effect.confirm'
54
54
  | 'step.complete'
55
55
  | 'step.wait'
56
+ | 'subscription.park'
56
57
  | 'event.emit'
57
58
  | 'event.submit'
59
+ | 'subscription.open'
60
+ | 'subscription.activate'
61
+ | 'subscription.deliver'
62
+ | 'subscription.inspect'
63
+ | 'subscription.fence_overflow'
64
+ | 'subscription.next'
65
+ | 'subscription.close'
58
66
  | 'channel.append'
59
67
  | 'channel.receive'
60
68
  | 'channel.ack'
@@ -362,6 +370,10 @@ export interface EventEmitParams {
362
370
  run_id: string;
363
371
  event_key: string;
364
372
  payload: unknown;
373
+ /** Provider delivery id for body activities. Required by Cloud; optional for legacy exact waits. */
374
+ delivery_id?: string;
375
+ /** Provider actor identity, used by the local router adapter for self filtering. */
376
+ actor?: string;
365
377
  }
366
378
  export interface EventEmitResult {
367
379
  matched: number;
@@ -388,6 +400,111 @@ export interface EventSubmitResult {
388
400
  run?: unknown;
389
401
  }
390
402
 
403
+ /** Body-level activity open; the server acknowledges only after its fenced binding is durable. */
404
+ export interface SubscriptionOpenParams {
405
+ run_id: string;
406
+ subscription_id: string;
407
+ event_types: string[];
408
+ pattern?: Record<string, unknown>;
409
+ settle_ms: number;
410
+ idle_ms: number;
411
+ deadline_ms: number;
412
+ include_self: boolean;
413
+ }
414
+ export type SubscriptionOpenResult =
415
+ | {
416
+ /** Immutable snapshot from the durable `subscription.prepared` entry. */
417
+ state: 'prepared';
418
+ subscription_id: string;
419
+ event_types: string[];
420
+ pattern?: Record<string, unknown>;
421
+ stream: string;
422
+ settle_ms: number;
423
+ idle_ms: number;
424
+ deadline_at_ms: number;
425
+ include_self: boolean;
426
+ }
427
+ | {
428
+ state: 'active';
429
+ subscription_id: string;
430
+ stream: string;
431
+ deadline_at_ms: number;
432
+ };
433
+
434
+ /** Cloud supplies this receipt only after it has durably fenced its binding. */
435
+ export interface SubscriptionActivateParams {
436
+ run_id: string;
437
+ subscription_id: string;
438
+ ingress_offset: number;
439
+ router_binding: Record<string, unknown>;
440
+ }
441
+ export interface SubscriptionActivateResult {
442
+ state: 'active';
443
+ subscription_id: string;
444
+ stream: string;
445
+ deadline_at_ms: number;
446
+ }
447
+
448
+ /** Targeted Cloud ingress; receipt must equal the journaled activation receipt. */
449
+ export interface SubscriptionDeliverParams {
450
+ run_id: string;
451
+ subscription_id: string;
452
+ router_binding: Record<string, unknown>;
453
+ delivery_id: string;
454
+ frame: unknown;
455
+ }
456
+ export interface SubscriptionDeliverResult {
457
+ /** False for an idempotent duplicate or a frame that closes on overflow. */
458
+ appended: boolean;
459
+ reason?: 'duplicate' | 'overflow';
460
+ }
461
+
462
+ /** Read-only projection of the kernel's durable subscription records. */
463
+ export interface SubscriptionSnapshot {
464
+ subscriptionId: string;
465
+ state: 'prepared' | 'active' | 'closed';
466
+ completionReason?: 'closed' | 'run_completed' | 'canceled' | 'deadline' | 'overflow';
467
+ routerBinding?: Record<string, unknown>;
468
+ ingressOffset?: number;
469
+ unreadFrames: number;
470
+ unreadBytes: number;
471
+ settleMs: number;
472
+ idleAtMs?: number;
473
+ deadlineAtMs: number;
474
+ }
475
+ export interface SubscriptionInspectParams { run_id: string }
476
+ export interface SubscriptionInspectResult { subscriptions: SubscriptionSnapshot[] }
477
+ export interface SubscriptionFenceOverflowParams {
478
+ run_id: string;
479
+ subscription_id: string;
480
+ router_binding: Record<string, unknown>;
481
+ }
482
+ export interface SubscriptionFenceOverflowResult { fenced: true }
483
+
484
+ export interface SubscriptionNextParams {
485
+ run_id: string;
486
+ subscription_id: string;
487
+ /** Internal durable receipt for the prior normal wake, supplied with the next pull. */
488
+ acknowledge_wait_id?: string;
489
+ /** Body call ordinal: replay this pull's durable wake across process restarts. */
490
+ sequence?: number;
491
+ }
492
+ export type SubscriptionNextResult =
493
+ | { kind: 'suspended'; subscription_id: string; stream: string; deadline_at_ms: number }
494
+ | { kind: 'events'; events: unknown[]; offset: number; acknowledge_wait_id?: string }
495
+ | { kind: 'idle'; acknowledge_wait_id?: string }
496
+ | { kind: 'deadline'; pending: { from: number; to: number } | null }
497
+ | { kind: 'overflow'; retained: number; bytes: number; from: number };
498
+
499
+ export interface SubscriptionCloseParams {
500
+ run_id: string;
501
+ subscription_id: string;
502
+ completion_reason: 'closed' | 'run_completed' | 'canceled';
503
+ }
504
+ export interface SubscriptionCloseResult {
505
+ closed: string;
506
+ }
507
+
391
508
  export interface StreamAppendParams {
392
509
  run_id: string;
393
510
  stream: string;
@@ -441,8 +558,20 @@ export interface VerbContract {
441
558
  'effect.confirm': { params: EffectConfirmParams; result: EffectConfirmResult };
442
559
  'step.complete': { params: StepCompleteParams; result: StepCompleteResult };
443
560
  'step.wait': { params: StepWaitParams; result: StepWaitResult };
561
+ 'subscription.park': {
562
+ params: { run_id: string; step_id: string; attempt: number; idempotency_key: string;
563
+ subscription_id: string; phase: 'activation' | 'event_wait' };
564
+ result: RunOutcome;
565
+ };
444
566
  'event.emit': { params: EventEmitParams; result: EventEmitResult };
445
567
  'event.submit': { params: EventSubmitParams; result: EventSubmitResult };
568
+ 'subscription.open': { params: SubscriptionOpenParams; result: SubscriptionOpenResult };
569
+ 'subscription.activate': { params: SubscriptionActivateParams; result: SubscriptionActivateResult };
570
+ 'subscription.deliver': { params: SubscriptionDeliverParams; result: SubscriptionDeliverResult };
571
+ 'subscription.inspect': { params: SubscriptionInspectParams; result: SubscriptionInspectResult };
572
+ 'subscription.fence_overflow': { params: SubscriptionFenceOverflowParams; result: SubscriptionFenceOverflowResult };
573
+ 'subscription.next': { params: SubscriptionNextParams; result: SubscriptionNextResult };
574
+ 'subscription.close': { params: SubscriptionCloseParams; result: SubscriptionCloseResult };
446
575
  'stream.append': { params: StreamAppendParams; result: StreamAppendResult };
447
576
  'stream.read': { params: StreamReadParams; result: StreamReadResult };
448
577
  'journal.read': { params: JournalReadParams; result: JournalReadResult };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A step's LAST settling `step.completed`: the verdict the kernel settled the
3
+ * step on. `retry` and `park` completions record an attempt the kernel did
4
+ * NOT settle it on (relayflowd-core `Disposition`) — crash recovery's
5
+ * `crashed`, a `worker_error` with iterations left — and precede the attempt
6
+ * that did, so neither the first completion nor a completion count is the
7
+ * step's verdict. Shared by the authored reader and the Bun result verifier,
8
+ * which must agree on which completion a claim is judged against.
9
+ */
10
+ export function settlingCompletion<T>(entries: readonly T[], stepId: string): T | undefined {
11
+ return entries.filter(entry => {
12
+ if (typeof entry !== 'object' || entry === null) return false;
13
+ const { entry_type: type, step_id: step, payload } = entry as Record<string, unknown>;
14
+ if (type !== 'step.completed' || step !== stepId) return false;
15
+ const disposition = typeof payload === 'object' && payload !== null
16
+ ? (payload as Record<string, unknown>)['disposition'] : undefined;
17
+ return disposition !== 'retry' && disposition !== 'park';
18
+ }).at(-1);
19
+ }