@relayfx/sdk 0.0.50 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +5 -0
  2. package/dist/ai.js +42 -17222
  3. package/dist/index-2xztzkfr.js +20596 -0
  4. package/dist/index-bcbbm5wt.js +137 -0
  5. package/dist/index-qgt9z94q.js +2443 -0
  6. package/dist/index.js +830 -18839
  7. package/dist/migrations/20260712120000_durable_inbox/migration.sql +9 -0
  8. package/dist/migrations/20260712140000_execution_state/migration.sql +5 -0
  9. package/dist/migrations/20260712150000_durable_entities/migration.sql +15 -0
  10. package/dist/migrations/20260712160000_ephemeral_presence/migration.sql +13 -0
  11. package/dist/migrations/20260712170000_topic_subscriptions/migration.sql +3 -0
  12. package/dist/migrations/20260712180000_child_fan_out/migration.sql +27 -0
  13. package/dist/migrations/20260712190000_workflow_definitions/migration.sql +3 -0
  14. package/dist/migrations/20260712200000_workflow_runtime/migration.sql +2 -0
  15. package/dist/migrations/mysql/0003_durable_inbox.sql +3 -0
  16. package/dist/migrations/mysql/0004_execution_state.sql +3 -0
  17. package/dist/migrations/mysql/0005_durable_entities.sql +13 -0
  18. package/dist/migrations/mysql/0006_ephemeral_presence.sql +12 -0
  19. package/dist/migrations/mysql/0007_topic_subscriptions.sql +1 -0
  20. package/dist/migrations/mysql/0008_child_fan_out.sql +26 -0
  21. package/dist/migrations/mysql/0009_workflow_definitions.sql +3 -0
  22. package/dist/migrations/mysql/0010_workflow_runtime.sql +3 -0
  23. package/dist/migrations/pg/20260712120000_durable_inbox/migration.sql +9 -0
  24. package/dist/migrations/pg/20260712140000_execution_state/migration.sql +5 -0
  25. package/dist/migrations/pg/20260712150000_durable_entities/migration.sql +15 -0
  26. package/dist/migrations/pg/20260712160000_ephemeral_presence/migration.sql +13 -0
  27. package/dist/migrations/pg/20260712170000_topic_subscriptions/migration.sql +3 -0
  28. package/dist/migrations/pg/20260712180000_child_fan_out/migration.sql +27 -0
  29. package/dist/migrations/pg/20260712190000_workflow_definitions/migration.sql +3 -0
  30. package/dist/migrations/pg/20260712200000_workflow_runtime/migration.sql +2 -0
  31. package/dist/migrations/sqlite/0003_durable_inbox.sql +9 -0
  32. package/dist/migrations/sqlite/0004_execution_state.sql +3 -0
  33. package/dist/migrations/sqlite/0005_durable_entities.sql +15 -0
  34. package/dist/migrations/sqlite/0006_ephemeral_presence.sql +12 -0
  35. package/dist/migrations/sqlite/0007_topic_subscriptions.sql +3 -0
  36. package/dist/migrations/sqlite/0008_child_fan_out.sql +27 -0
  37. package/dist/migrations/sqlite/0009_workflow_definitions.sql +3 -0
  38. package/dist/migrations/sqlite/0010_workflow_runtime.sql +3 -0
  39. package/dist/sqlite.js +737 -0
  40. package/dist/types/relay/adapter-outbox.d.ts +3 -3
  41. package/dist/types/relay/client.d.ts +335 -25
  42. package/dist/types/relay/command.d.ts +41 -0
  43. package/dist/types/relay/database.d.ts +1 -0
  44. package/dist/types/relay/index.d.ts +3 -2
  45. package/dist/types/relay/operation.d.ts +1082 -7
  46. package/dist/types/relay/sqlite-migrations.d.ts +54 -0
  47. package/dist/types/relay/sqlite-runtime.d.ts +10 -0
  48. package/dist/types/relay/sqlite.d.ts +29 -0
  49. package/dist/types/runtime/address/address-book-service.d.ts +4 -4
  50. package/dist/types/runtime/address/address-resolution-service.d.ts +1 -1
  51. package/dist/types/runtime/agent/agent-loop-service.d.ts +2 -2
  52. package/dist/types/runtime/agent/agent-registry-service.d.ts +1 -1
  53. package/dist/types/runtime/agent/relay-compaction.d.ts +1 -1
  54. package/dist/types/runtime/agent/relay-permissions.d.ts +1 -1
  55. package/dist/types/runtime/agent/relay-steering.d.ts +1 -1
  56. package/dist/types/runtime/child/child-fan-out-admission-service.d.ts +30 -0
  57. package/dist/types/runtime/child/child-fan-out-runtime.d.ts +34 -0
  58. package/dist/types/runtime/child/child-fan-out-transition-service.d.ts +25 -0
  59. package/dist/types/runtime/child/child-run-service.d.ts +1 -1
  60. package/dist/types/runtime/child/parent-notifier-service.d.ts +1 -1
  61. package/dist/types/runtime/cluster/execution-entity.d.ts +5 -3
  62. package/dist/types/runtime/entity/entity-instance-service.d.ts +67 -0
  63. package/dist/types/runtime/entity/entity-registry-service.d.ts +35 -0
  64. package/dist/types/runtime/envelope/envelope-service.d.ts +7 -3
  65. package/dist/types/runtime/execution/active-execution-registry.d.ts +12 -0
  66. package/dist/types/runtime/execution/event-log-service.d.ts +1 -1
  67. package/dist/types/runtime/execution/execution-service.d.ts +2 -1
  68. package/dist/types/runtime/execution/execution-watch-service.d.ts +32 -0
  69. package/dist/types/runtime/execution/session-stream-service.d.ts +33 -0
  70. package/dist/types/runtime/inbox/inbox-service.d.ts +76 -0
  71. package/dist/types/runtime/inbox/send-message-tool.d.ts +27 -0
  72. package/dist/types/runtime/inbox/wait-for-messages-tool.d.ts +34 -0
  73. package/dist/types/runtime/index.d.ts +18 -0
  74. package/dist/types/runtime/memory/memory-service.d.ts +1 -1
  75. package/dist/types/runtime/presence/presence-service.d.ts +30 -0
  76. package/dist/types/runtime/presence/presence-tool.d.ts +20 -0
  77. package/dist/types/runtime/runner/runner-runtime-service.d.ts +18 -18
  78. package/dist/types/runtime/schedule/scheduler-service.d.ts +1 -1
  79. package/dist/types/runtime/session/session-store-service.d.ts +1 -1
  80. package/dist/types/runtime/skill/skill-registry-service.d.ts +1 -1
  81. package/dist/types/runtime/state/execution-state-service.d.ts +57 -0
  82. package/dist/types/runtime/state/state-tools.d.ts +5 -0
  83. package/dist/types/runtime/tool/tool-runtime-service.d.ts +1 -1
  84. package/dist/types/runtime/topic/publish-to-topic-tool.d.ts +24 -0
  85. package/dist/types/runtime/topic/topic-service.d.ts +50 -0
  86. package/dist/types/runtime/wait/wait-service.d.ts +2 -1
  87. package/dist/types/runtime/wait/wait-signal.d.ts +1 -1
  88. package/dist/types/runtime/workflow/definition-runtime.d.ts +78 -0
  89. package/dist/types/runtime/workflow/execution-workflow.d.ts +7 -7
  90. package/dist/types/runtime/workspace/workspace-planner-service.d.ts +1 -1
  91. package/dist/types/schema/address-schema.d.ts +6 -6
  92. package/dist/types/schema/child-orchestration-schema.d.ts +393 -0
  93. package/dist/types/schema/entity-schema.d.ts +40 -0
  94. package/dist/types/schema/envelope-schema.d.ts +1 -0
  95. package/dist/types/schema/execution-schema.d.ts +2 -2
  96. package/dist/types/schema/ids-schema.d.ts +20 -0
  97. package/dist/types/schema/inbox-schema.d.ts +81 -0
  98. package/dist/types/schema/index.d.ts +7 -0
  99. package/dist/types/schema/presence-schema.d.ts +28 -0
  100. package/dist/types/schema/state-schema.d.ts +35 -0
  101. package/dist/types/schema/wait-schema.d.ts +98 -0
  102. package/dist/types/schema/workflow-schema.d.ts +2062 -0
  103. package/dist/types/store-sql/address/address-book-repository.d.ts +1 -1
  104. package/dist/types/store-sql/child/child-fan-out-repository.d.ts +53 -0
  105. package/dist/types/store-sql/database/database-service.d.ts +4 -18
  106. package/dist/types/store-sql/database/notification-bus.d.ts +2 -0
  107. package/dist/types/store-sql/database/sql-dialect.d.ts +13 -0
  108. package/dist/types/store-sql/entity/entity-repository.d.ts +36 -0
  109. package/dist/types/store-sql/envelope/envelope-repository.d.ts +1 -0
  110. package/dist/types/store-sql/execution/execution-event-repository.d.ts +2 -1
  111. package/dist/types/store-sql/execution/execution-repository.d.ts +12 -2
  112. package/dist/types/store-sql/inbox/inbox-repository.d.ts +56 -0
  113. package/dist/types/store-sql/index.d.ts +8 -0
  114. package/dist/types/store-sql/portable.d.ts +29 -0
  115. package/dist/types/store-sql/presence/presence-repository.d.ts +51 -0
  116. package/dist/types/store-sql/schema/relay-schema.d.ts +3064 -587
  117. package/dist/types/store-sql/state/execution-state-repository.d.ts +80 -0
  118. package/dist/types/store-sql/tenant/tenant-id.d.ts +0 -2
  119. package/dist/types/store-sql/topic/topic-repository.d.ts +44 -0
  120. package/dist/types/store-sql/workflow/workflow-definition-repository.d.ts +29 -0
  121. package/package.json +26 -4
  122. package/dist/migrations/20260701002839_sour_cerebro/snapshot.json +0 -1971
  123. package/dist/migrations/20260701041134_acoustic_hulk/snapshot.json +0 -2372
  124. package/dist/migrations/20260701160543_condemned_stryfe/snapshot.json +0 -2442
  125. package/dist/migrations/20260701220315_heavy_gorgon/snapshot.json +0 -2495
  126. package/dist/migrations/20260701225444_polite_lord_hawal/snapshot.json +0 -2821
  127. package/dist/migrations/20260702030128_flaky_misty_knight/snapshot.json +0 -2821
  128. package/dist/migrations/20260705003847_nervous_banshee/snapshot.json +0 -2954
  129. package/dist/migrations/20260705012626_common_stryfe/snapshot.json +0 -3378
  130. package/dist/migrations/20260705015420_sweet_captain_marvel/snapshot.json +0 -3485
  131. package/dist/migrations/20260705023041_chunky_scalphunter/snapshot.json +0 -3753
  132. package/dist/migrations/20260705030344_short_patriot/snapshot.json +0 -3873
  133. package/dist/migrations/20260705045546_heavy_ben_grimm/snapshot.json +0 -4193
  134. package/dist/migrations/20260706185931_regular_shadow_king/snapshot.json +0 -4844
  135. package/dist/migrations/20260706233300_equal_cyclops/snapshot.json +0 -4883
  136. package/dist/migrations/20260709030349_agent_id_rename/snapshot.json +0 -4883
  137. package/dist/migrations/20260709214238_faithful_black_widow/snapshot.json +0 -5426
  138. package/dist/migrations/20260709220016_fearless_aaron_stack/snapshot.json +0 -5426
  139. package/dist/migrations/pg/20260701002839_sour_cerebro/snapshot.json +0 -1971
  140. package/dist/migrations/pg/20260701041134_acoustic_hulk/snapshot.json +0 -2372
  141. package/dist/migrations/pg/20260701160543_condemned_stryfe/snapshot.json +0 -2442
  142. package/dist/migrations/pg/20260701220315_heavy_gorgon/snapshot.json +0 -2495
  143. package/dist/migrations/pg/20260701225444_polite_lord_hawal/snapshot.json +0 -2821
  144. package/dist/migrations/pg/20260702030128_flaky_misty_knight/snapshot.json +0 -2821
  145. package/dist/migrations/pg/20260705003847_nervous_banshee/snapshot.json +0 -2954
  146. package/dist/migrations/pg/20260705012626_common_stryfe/snapshot.json +0 -3378
  147. package/dist/migrations/pg/20260705015420_sweet_captain_marvel/snapshot.json +0 -3485
  148. package/dist/migrations/pg/20260705023041_chunky_scalphunter/snapshot.json +0 -3753
  149. package/dist/migrations/pg/20260705030344_short_patriot/snapshot.json +0 -3873
  150. package/dist/migrations/pg/20260705045546_heavy_ben_grimm/snapshot.json +0 -4193
  151. package/dist/migrations/pg/20260706185931_regular_shadow_king/snapshot.json +0 -4844
  152. package/dist/migrations/pg/20260706233300_equal_cyclops/snapshot.json +0 -4883
  153. package/dist/migrations/pg/20260709030349_agent_id_rename/snapshot.json +0 -4883
  154. package/dist/migrations/pg/20260709214238_faithful_black_widow/snapshot.json +0 -5426
  155. package/dist/migrations/pg/20260709220016_fearless_aaron_stack/snapshot.json +0 -5426
@@ -0,0 +1,2443 @@
1
+ // @bun
2
+ import {
3
+ __export,
4
+ exports_address_book_service,
5
+ exports_address_schema,
6
+ exports_agent_registry_service,
7
+ exports_agent_schema,
8
+ exports_child_execution_repository,
9
+ exports_child_fan_out_repository,
10
+ exports_child_fan_out_runtime,
11
+ exports_child_orchestration_schema,
12
+ exports_child_run_service,
13
+ exports_cluster_registry_repository,
14
+ exports_content_schema,
15
+ exports_definition_runtime,
16
+ exports_entity_instance_service,
17
+ exports_entity_registry_service,
18
+ exports_entity_schema,
19
+ exports_envelope_repository,
20
+ exports_envelope_schema,
21
+ exports_envelope_service,
22
+ exports_event_log_service,
23
+ exports_execution_entity,
24
+ exports_execution_repository,
25
+ exports_execution_schema,
26
+ exports_execution_service,
27
+ exports_execution_state_service,
28
+ exports_execution_watch_service,
29
+ exports_ids_schema,
30
+ exports_inbox_repository,
31
+ exports_inbox_schema,
32
+ exports_presence_service,
33
+ exports_schedule_repository,
34
+ exports_schedule_schema,
35
+ exports_scheduler_service,
36
+ exports_schema_registry_service,
37
+ exports_session_repository,
38
+ exports_session_stream_service,
39
+ exports_shared_schema,
40
+ exports_skill_registry_service,
41
+ exports_state_schema,
42
+ exports_steering_repository,
43
+ exports_tool_call_repository,
44
+ exports_tool_schema,
45
+ exports_tool_transition_coordinator,
46
+ exports_topic_service,
47
+ exports_wait_schema,
48
+ exports_wait_service,
49
+ exports_wait_signal,
50
+ exports_workflow_definition_repository
51
+ } from "./index-2xztzkfr.js";
52
+
53
+ // src/operation.ts
54
+ var exports_operation = {};
55
+ __export(exports_operation, {
56
+ WatchExecutionsInput: () => WatchExecutionsInput,
57
+ WakeInput: () => WakeInput,
58
+ WakeAccepted: () => WakeAccepted,
59
+ WaitView: () => WaitView,
60
+ WaitTerminalState: () => WaitTerminalState,
61
+ WaitState: () => WaitState,
62
+ WaitOutcome: () => WaitOutcome,
63
+ UnsubscribeTopicInput: () => UnsubscribeTopicInput,
64
+ TopicSubscription: () => TopicSubscription,
65
+ TopicPublishAccepted: () => TopicPublishAccepted,
66
+ ToolWorkReleased: () => ToolWorkReleased,
67
+ ToolWorkLease: () => ToolWorkLease,
68
+ ToolOutcomeAccepted: () => ToolOutcomeAccepted,
69
+ ToolCallSummary: () => ToolCallSummary,
70
+ ToolAttemptList: () => ToolAttemptList,
71
+ ToolAttempt: () => ToolAttempt,
72
+ SubscribeTopicInput: () => SubscribeTopicInput,
73
+ SubmitInboundEnvelopeInput: () => SubmitInboundEnvelopeInput,
74
+ SubmitInboundEnvelopeAccepted: () => SubmitInboundEnvelopeAccepted,
75
+ StreamSessionInput: () => StreamSessionInput,
76
+ StreamExecutionInput: () => StreamExecutionInput,
77
+ SteeringKind: () => SteeringKind,
78
+ SteerInput: () => SteerInput,
79
+ SteerAccepted: () => SteerAccepted,
80
+ StartExecutionResult: () => StartExecutionResult,
81
+ StartExecutionInput: () => StartExecutionInput,
82
+ SpawnChildRunInput: () => SpawnChildRunInput,
83
+ SessionSummary: () => SessionSummary,
84
+ SessionStreamItem: () => SessionStreamItem,
85
+ RunnerSummary: () => RunnerSummary,
86
+ RouteExecutionResult: () => RouteExecutionResult,
87
+ ResolveToolApprovalInput: () => ResolveToolApprovalInput,
88
+ ResolvePermissionInput: () => ResolvePermissionInput,
89
+ ReplayExecutionResult: () => ReplayExecutionResult,
90
+ ReplayExecutionInput: () => ReplayExecutionInput,
91
+ ReleaseToolWorkInput: () => ReleaseToolWorkInput,
92
+ ReleaseEnvelopeReadyInput: () => ReleaseEnvelopeReadyInput,
93
+ PutEntityStateInput: () => PutEntityStateInput,
94
+ PublishTopicInput: () => PublishTopicInput,
95
+ PermissionAnswer: () => PermissionAnswer,
96
+ PendingToolCallList: () => PendingToolCallList,
97
+ PendingToolCall: () => PendingToolCall,
98
+ PendingToolApprovalList: () => PendingToolApprovalList,
99
+ PendingToolApproval: () => PendingToolApproval,
100
+ ListWaitsInput: () => ListWaitsInput,
101
+ ListTopicSubscriptionsInput: () => ListTopicSubscriptionsInput,
102
+ ListToolAttemptsInput: () => ListToolAttemptsInput,
103
+ ListSessionsResult: () => ListSessionsResult,
104
+ ListSessionsInput: () => ListSessionsInput,
105
+ ListSchedulesResult: () => ListSchedulesResult,
106
+ ListSchedulesInput: () => ListSchedulesInput,
107
+ ListRunnersResult: () => ListRunnersResult,
108
+ ListPendingToolCallsInput: () => ListPendingToolCallsInput,
109
+ ListPendingApprovalsInput: () => ListPendingApprovalsInput,
110
+ ListInboxMessagesInput: () => ListInboxMessagesInput,
111
+ ListExecutionsResult: () => ListExecutionsResult,
112
+ ListExecutionsInput: () => ListExecutionsInput,
113
+ ListEntityStateInput: () => ListEntityStateInput,
114
+ ListEntitiesInput: () => ListEntitiesInput,
115
+ InspectChildFanOutResult: () => InspectChildFanOutResult,
116
+ InspectChildFanOutInput: () => InspectChildFanOutInput,
117
+ GetSessionResult: () => GetSessionResult,
118
+ GetSessionInput: () => GetSessionInput,
119
+ GetOrCreateEntityInput: () => GetOrCreateEntityInput,
120
+ GetEntityStateInput: () => GetEntityStateInput,
121
+ GetEntityInput: () => GetEntityInput,
122
+ FulfillToolCallInput: () => FulfillToolCallInput,
123
+ FollowStopReason: () => FollowStopReason,
124
+ FollowExecutionItem: () => FollowExecutionItem,
125
+ FollowExecutionInput: () => FollowExecutionInput,
126
+ ExecutionListChange: () => ExecutionListChange,
127
+ ExecutionInspection: () => ExecutionInspection,
128
+ ExecutionCursor: () => ExecutionCursor,
129
+ EventLogCursorNotFound: () => EventLogCursorNotFound,
130
+ EnvelopeReadyReleased: () => EnvelopeReadyReleased,
131
+ EnvelopeReadyLease: () => EnvelopeReadyLease,
132
+ EnvelopeReadyAcked: () => EnvelopeReadyAcked,
133
+ EntityInstance: () => EntityInstance,
134
+ DestroyEntityInput: () => DestroyEntityInput,
135
+ DeleteEntityStateInput: () => DeleteEntityStateInput,
136
+ CreateScheduleResult: () => CreateScheduleResult,
137
+ CreateScheduleInput: () => CreateScheduleInput,
138
+ CreateChildFanOutInput: () => CreateChildFanOutInput,
139
+ ConversationSummary: () => ConversationSummary,
140
+ ConversationKind: () => ConversationKind,
141
+ CompleteToolWorkInput: () => CompleteToolWorkInput,
142
+ ClaimToolWorkInput: () => ClaimToolWorkInput,
143
+ ClaimEnvelopeReadyInput: () => ClaimEnvelopeReadyInput,
144
+ ChildRunSummary: () => ChildRunSummary,
145
+ CancelScheduleResult: () => CancelScheduleResult,
146
+ CancelScheduleInput: () => CancelScheduleInput,
147
+ CancelExecutionInput: () => CancelExecutionInput,
148
+ CancelExecutionAccepted: () => CancelExecutionAccepted,
149
+ CancelChildFanOutResult: () => CancelChildFanOutResult,
150
+ CancelChildFanOutInput: () => CancelChildFanOutInput,
151
+ AwaitWaitInput: () => AwaitWaitInput,
152
+ AckEnvelopeReadyInput: () => AckEnvelopeReadyInput
153
+ });
154
+ import { Schema } from "effect";
155
+ var StartExecutionInput = Schema.Struct({
156
+ execution_id: exports_ids_schema.ExecutionId,
157
+ root_address_id: exports_ids_schema.AddressId,
158
+ session_id: Schema.optionalKey(exports_ids_schema.SessionId),
159
+ input: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
160
+ event_sequence: exports_execution_schema.ExecutionEventSequence,
161
+ started_at: exports_shared_schema.TimestampMillis,
162
+ completed_at: exports_shared_schema.TimestampMillis,
163
+ agent_id: Schema.optionalKey(exports_ids_schema.AgentId),
164
+ agent_revision: Schema.optionalKey(exports_agent_schema.DefinitionRevision),
165
+ agent_snapshot: Schema.optionalKey(exports_agent_schema.Definition),
166
+ agent_tool_input_schema_digests: Schema.optionalKey(exports_agent_schema.ToolInputSchemaDigests),
167
+ wait_id: Schema.optionalKey(exports_ids_schema.WaitId),
168
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata)
169
+ }).annotate({ identifier: "Relay.Operation.StartExecutionInput" });
170
+ var StartExecutionResult = Schema.Struct({
171
+ execution_id: exports_ids_schema.ExecutionId,
172
+ status: exports_execution_schema.ExecutionStatus,
173
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata)
174
+ }).annotate({ identifier: "Relay.Operation.StartExecutionResult" });
175
+ var GetOrCreateEntityInput = Schema.Struct({
176
+ kind: exports_ids_schema.EntityKindName,
177
+ key: exports_ids_schema.EntityKey,
178
+ input: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
179
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata),
180
+ created_at: exports_shared_schema.TimestampMillis
181
+ }).annotate({ identifier: "Relay.Operation.GetOrCreateEntityInput" });
182
+ var GetEntityInput = Schema.Struct({ kind: exports_ids_schema.EntityKindName, key: exports_ids_schema.EntityKey }).annotate({
183
+ identifier: "Relay.Operation.GetEntityInput"
184
+ });
185
+ var DestroyEntityInput = Schema.Struct({
186
+ kind: exports_ids_schema.EntityKindName,
187
+ key: exports_ids_schema.EntityKey,
188
+ reason: Schema.optionalKey(Schema.String),
189
+ destroyed_at: exports_shared_schema.TimestampMillis
190
+ }).annotate({ identifier: "Relay.Operation.DestroyEntityInput" });
191
+ var ListEntitiesInput = Schema.Struct({
192
+ kind: Schema.optionalKey(exports_ids_schema.EntityKindName),
193
+ after_kind: Schema.optionalKey(exports_ids_schema.EntityKindName),
194
+ after_key: Schema.optionalKey(Schema.String),
195
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
196
+ }).annotate({ identifier: "Relay.Operation.ListEntitiesInput" });
197
+ var EntityInstance = exports_entity_schema.Instance;
198
+ var StreamExecutionInput = Schema.Struct({
199
+ execution_id: exports_execution_schema.Execution.fields.id,
200
+ after_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString),
201
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
202
+ }).annotate({ identifier: "Relay.Operation.StreamExecutionInput" });
203
+ var GetEntityStateInput = Schema.Struct({ execution_id: exports_ids_schema.ExecutionId, key: exports_state_schema.StateKey }).annotate({
204
+ identifier: "Relay.Operation.GetEntityStateInput"
205
+ });
206
+ var PutEntityStateInput = Schema.Struct({
207
+ execution_id: exports_ids_schema.ExecutionId,
208
+ key: exports_state_schema.StateKey,
209
+ value: exports_shared_schema.JsonValue,
210
+ expected_version: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
211
+ idempotency_key: Schema.optionalKey(exports_state_schema.StateIdempotencyKey.check(Schema.makeFilter((value) => !value.startsWith("relay:internal:")))),
212
+ updated_at: exports_shared_schema.TimestampMillis
213
+ }).annotate({ identifier: "Relay.Operation.PutEntityStateInput" });
214
+ var DeleteEntityStateInput = Schema.Struct({
215
+ execution_id: exports_ids_schema.ExecutionId,
216
+ key: exports_state_schema.StateKey,
217
+ expected_version: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
218
+ idempotency_key: Schema.optionalKey(exports_state_schema.StateIdempotencyKey.check(Schema.makeFilter((value) => !value.startsWith("relay:internal:")))),
219
+ removed_at: exports_shared_schema.TimestampMillis
220
+ }).annotate({ identifier: "Relay.Operation.DeleteEntityStateInput" });
221
+ var ListEntityStateInput = Schema.Struct({
222
+ execution_id: exports_ids_schema.ExecutionId,
223
+ prefix: Schema.optionalKey(Schema.String),
224
+ after_key: Schema.optionalKey(Schema.String),
225
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
226
+ }).annotate({ identifier: "Relay.Operation.ListEntityStateInput" });
227
+ var WaitTerminalState = Schema.Literals(["resolved", "timed_out", "cancelled"]).annotate({
228
+ identifier: "Relay.Operation.WaitTerminalState"
229
+ });
230
+ var AwaitWaitInput = Schema.Struct({
231
+ wait_id: exports_ids_schema.WaitId,
232
+ execution_id: exports_ids_schema.ExecutionId
233
+ }).annotate({ identifier: "Relay.Operation.AwaitWaitInput" });
234
+ var WaitOutcome = Schema.Struct({
235
+ wait_id: exports_ids_schema.WaitId,
236
+ state: WaitTerminalState,
237
+ content: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
238
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata)
239
+ }).annotate({ identifier: "Relay.Operation.WaitOutcome" });
240
+ var CancelExecutionInput = Schema.Struct({
241
+ execution_id: exports_ids_schema.ExecutionId,
242
+ cancelled_at: exports_shared_schema.TimestampMillis,
243
+ reason: Schema.optionalKey(Schema.String)
244
+ }).annotate({ identifier: "Relay.Operation.CancelExecutionInput" });
245
+ var CancelExecutionAccepted = Schema.Struct({
246
+ execution_id: exports_ids_schema.ExecutionId,
247
+ status: exports_execution_schema.ExecutionStatus
248
+ }).annotate({ identifier: "Relay.Operation.CancelExecutionAccepted" });
249
+ var SteeringKind = Schema.Literals(["steering", "follow_up"]).annotate({
250
+ identifier: "Relay.Operation.SteeringKind"
251
+ });
252
+ var SteerInput = Schema.Struct({
253
+ execution_id: exports_ids_schema.ExecutionId,
254
+ kind: SteeringKind,
255
+ content: Schema.Array(exports_content_schema.Part),
256
+ created_at: exports_shared_schema.TimestampMillis
257
+ }).annotate({ identifier: "Relay.Operation.SteerInput" });
258
+ var SteerAccepted = Schema.Struct({
259
+ execution_id: exports_ids_schema.ExecutionId,
260
+ kind: SteeringKind,
261
+ sequence: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
262
+ }).annotate({ identifier: "Relay.Operation.SteerAccepted" });
263
+ var WakeInput = Schema.Struct({
264
+ wait_id: exports_ids_schema.WaitId,
265
+ state: WaitTerminalState,
266
+ signaled_at: exports_shared_schema.TimestampMillis,
267
+ from: Schema.optionalKey(exports_ids_schema.AddressId),
268
+ content: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
269
+ correlation_key: Schema.optionalKey(Schema.String),
270
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata)
271
+ }).annotate({ identifier: "Relay.Operation.WakeInput" });
272
+ var WakeAccepted = Schema.Struct({
273
+ wait_id: exports_ids_schema.WaitId,
274
+ state: WaitTerminalState,
275
+ signaled_at: exports_shared_schema.TimestampMillis
276
+ }).annotate({ identifier: "Relay.Operation.WakeAccepted" });
277
+ var WaitState = Schema.Literals(["open", "resolved", "timed_out", "cancelled"]).annotate({
278
+ identifier: "Relay.Operation.WaitState"
279
+ });
280
+ var ListWaitsInput = Schema.Struct({
281
+ state: Schema.optionalKey(WaitState),
282
+ execution_id: Schema.optionalKey(exports_ids_schema.ExecutionId),
283
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
284
+ }).annotate({ identifier: "Relay.Operation.ListWaitsInput" });
285
+ var WaitView = Schema.Struct({
286
+ wait_id: exports_ids_schema.WaitId,
287
+ execution_id: exports_ids_schema.ExecutionId,
288
+ envelope_id: Schema.optionalKey(exports_ids_schema.EnvelopeId),
289
+ kind: Schema.optionalKey(exports_wait_schema.WaitKind),
290
+ mode: exports_envelope_schema.WaitMode,
291
+ correlation_key: Schema.optionalKey(Schema.String),
292
+ state: WaitState,
293
+ metadata: exports_shared_schema.Metadata,
294
+ created_at: exports_shared_schema.TimestampMillis,
295
+ resolved_at: Schema.optionalKey(exports_shared_schema.TimestampMillis)
296
+ }).annotate({ identifier: "Relay.Operation.WaitView" });
297
+ var FollowStopReason = Schema.Union([
298
+ Schema.Struct({ _tag: Schema.tag("terminal"), status: exports_execution_schema.ExecutionStatus }),
299
+ Schema.Struct({ _tag: Schema.tag("actionable_wait"), wait: WaitView })
300
+ ]).annotate({ identifier: "Relay.Operation.FollowStopReason" });
301
+ var FollowExecutionItem = Schema.Union([
302
+ Schema.Struct({ _tag: Schema.tag("event"), event: exports_execution_schema.ExecutionEvent }),
303
+ Schema.Struct({ _tag: Schema.tag("reconnecting"), message: Schema.String, attempt: Schema.Int }),
304
+ Schema.Struct({
305
+ _tag: Schema.tag("stopped"),
306
+ reason: FollowStopReason,
307
+ cursor: Schema.NullOr(exports_shared_schema.NonEmptyString)
308
+ })
309
+ ]).annotate({ identifier: "Relay.Operation.FollowExecutionItem" });
310
+ var FollowExecutionInput = Schema.Struct({
311
+ execution_id: exports_ids_schema.ExecutionId,
312
+ after_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString),
313
+ stop_on_wait_modes: Schema.optionalKey(Schema.Array(exports_envelope_schema.WaitMode)),
314
+ max_reconnects: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
315
+ }).annotate({ identifier: "Relay.Operation.FollowExecutionInput" });
316
+ var PendingToolApproval = Schema.Struct({
317
+ wait_id: exports_ids_schema.WaitId,
318
+ execution_id: exports_ids_schema.ExecutionId,
319
+ tool_call_id: exports_ids_schema.ToolCallId,
320
+ tool_name: exports_shared_schema.NonEmptyString,
321
+ input: exports_shared_schema.JsonValue,
322
+ requested_at: exports_shared_schema.TimestampMillis
323
+ }).annotate({ identifier: "Relay.Operation.PendingToolApproval" });
324
+ var ListPendingApprovalsInput = Schema.Struct({
325
+ execution_id: exports_ids_schema.ExecutionId
326
+ }).annotate({ identifier: "Relay.Operation.ListPendingApprovalsInput" });
327
+ var PendingToolApprovalList = Schema.Struct({
328
+ approvals: Schema.Array(PendingToolApproval)
329
+ }).annotate({ identifier: "Relay.Operation.PendingToolApprovalList" });
330
+ var PendingToolCall = Schema.Struct({
331
+ execution_id: exports_ids_schema.ExecutionId,
332
+ call: exports_tool_schema.Call,
333
+ definition: exports_tool_schema.Definition,
334
+ placement: exports_tool_schema.Placement,
335
+ state: exports_tool_schema.CallState,
336
+ wait_id: exports_ids_schema.WaitId,
337
+ idempotency_key: Schema.String,
338
+ requested_at: exports_shared_schema.TimestampMillis
339
+ }).annotate({ identifier: "Relay.Operation.PendingToolCall" });
340
+ var ListPendingToolCallsInput = Schema.Struct({
341
+ execution_id: Schema.optionalKey(exports_ids_schema.ExecutionId),
342
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
343
+ }).annotate({ identifier: "Relay.Operation.ListPendingToolCallsInput" });
344
+ var PendingToolCallList = Schema.Struct({
345
+ tool_calls: Schema.Array(PendingToolCall)
346
+ }).annotate({ identifier: "Relay.Operation.PendingToolCallList" });
347
+ var FulfillToolCallInput = Schema.Struct({
348
+ execution_id: exports_ids_schema.ExecutionId,
349
+ tool_call_id: exports_ids_schema.ToolCallId,
350
+ outcome: exports_tool_schema.ExternalOutcome,
351
+ fulfilled_at: exports_shared_schema.TimestampMillis
352
+ }).annotate({ identifier: "Relay.Operation.FulfillToolCallInput" });
353
+ var ClaimToolWorkInput = Schema.Struct({
354
+ queue: exports_tool_schema.PlacementKey,
355
+ worker_id: exports_tool_schema.WorkerId,
356
+ now: exports_shared_schema.TimestampMillis,
357
+ claim_expires_at: exports_shared_schema.TimestampMillis
358
+ }).annotate({ identifier: "Relay.Operation.ClaimToolWorkInput" });
359
+ var CompleteToolWorkInput = Schema.Struct({
360
+ tool_call_id: exports_ids_schema.ToolCallId,
361
+ attempt_id: exports_ids_schema.ToolAttemptId,
362
+ worker_id: exports_tool_schema.WorkerId,
363
+ outcome: exports_tool_schema.ExternalOutcome,
364
+ completed_at: exports_shared_schema.TimestampMillis
365
+ }).annotate({ identifier: "Relay.Operation.CompleteToolWorkInput" });
366
+ var ReleaseToolWorkInput = Schema.Struct({
367
+ tool_call_id: exports_ids_schema.ToolCallId,
368
+ attempt_id: exports_ids_schema.ToolAttemptId,
369
+ worker_id: exports_tool_schema.WorkerId,
370
+ released_at: exports_shared_schema.TimestampMillis,
371
+ next_available_at: exports_shared_schema.TimestampMillis,
372
+ error: Schema.optionalKey(Schema.String)
373
+ }).annotate({ identifier: "Relay.Operation.ReleaseToolWorkInput" });
374
+ var ListToolAttemptsInput = Schema.Struct({
375
+ tool_call_id: exports_ids_schema.ToolCallId
376
+ }).annotate({ identifier: "Relay.Operation.ListToolAttemptsInput" });
377
+ var ToolAttempt = Schema.Struct({
378
+ attempt_id: exports_ids_schema.ToolAttemptId,
379
+ tool_call_id: exports_ids_schema.ToolCallId,
380
+ attempt_number: Schema.Int.check(Schema.isGreaterThan(0)),
381
+ state: exports_tool_schema.AttemptState,
382
+ worker_id: Schema.optionalKey(Schema.String),
383
+ claim_expires_at: Schema.optionalKey(exports_shared_schema.TimestampMillis),
384
+ error: Schema.optionalKey(Schema.String),
385
+ created_at: exports_shared_schema.TimestampMillis,
386
+ completed_at: Schema.optionalKey(exports_shared_schema.TimestampMillis)
387
+ }).annotate({ identifier: "Relay.Operation.ToolAttempt" });
388
+ var ToolAttemptList = Schema.Struct({
389
+ attempts: Schema.Array(ToolAttempt)
390
+ }).annotate({ identifier: "Relay.Operation.ToolAttemptList" });
391
+ var ToolOutcomeAccepted = Schema.Struct({
392
+ tool_call_id: exports_ids_schema.ToolCallId,
393
+ attempt: ToolAttempt,
394
+ duplicate: Schema.Boolean
395
+ }).annotate({ identifier: "Relay.Operation.ToolOutcomeAccepted" });
396
+ var ToolWorkLease = Schema.Struct({
397
+ execution_id: exports_ids_schema.ExecutionId,
398
+ call: exports_tool_schema.Call,
399
+ definition: exports_tool_schema.Definition,
400
+ placement: exports_tool_schema.Placement,
401
+ attempt: ToolAttempt,
402
+ queue: exports_tool_schema.PlacementKey,
403
+ worker_id: exports_tool_schema.WorkerId,
404
+ claim_expires_at: exports_shared_schema.TimestampMillis,
405
+ idempotency_key: Schema.String
406
+ }).annotate({ identifier: "Relay.Operation.ToolWorkLease" });
407
+ var ToolWorkReleased = Schema.Struct({
408
+ tool_call_id: exports_ids_schema.ToolCallId,
409
+ state: Schema.Literal("waiting"),
410
+ next_available_at: exports_shared_schema.TimestampMillis
411
+ }).annotate({ identifier: "Relay.Operation.ToolWorkReleased" });
412
+ var SpawnChildRunInput = Schema.Struct({
413
+ execution_id: exports_ids_schema.ExecutionId,
414
+ child_execution_id: Schema.optionalKey(exports_ids_schema.ChildExecutionId),
415
+ address_id: exports_ids_schema.AddressId,
416
+ preset_name: Schema.optionalKey(exports_shared_schema.NonEmptyString),
417
+ instructions: Schema.optionalKey(Schema.String),
418
+ model: Schema.optionalKey(exports_agent_schema.ModelSelection),
419
+ tool_names: Schema.optionalKey(Schema.Array(Schema.String)),
420
+ permissions: Schema.optionalKey(Schema.Array(Schema.String)),
421
+ workspace_policy: Schema.optionalKey(exports_agent_schema.ChildRunWorkspacePolicy),
422
+ output_schema_ref: Schema.optionalKey(Schema.String),
423
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata),
424
+ input: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
425
+ wait: Schema.optionalKey(Schema.Boolean)
426
+ }).annotate({ identifier: "Relay.Operation.SpawnChildRunInput" });
427
+ var CreateChildFanOutInput = exports_child_orchestration_schema.FanOutDefinition.annotate({
428
+ identifier: "Relay.Operation.CreateChildFanOutInput"
429
+ });
430
+ var CancelChildFanOutInput = Schema.Struct({
431
+ fan_out_id: exports_ids_schema.ChildFanOutId,
432
+ cancelled_at: exports_shared_schema.TimestampMillis,
433
+ reason: Schema.optionalKey(Schema.String)
434
+ }).annotate({ identifier: "Relay.Operation.CancelChildFanOutInput" });
435
+ var CancelChildFanOutResult = Schema.Struct({
436
+ fan_out: exports_child_orchestration_schema.FanOutState
437
+ }).annotate({ identifier: "Relay.Operation.CancelChildFanOutResult" });
438
+ var InspectChildFanOutInput = Schema.Struct({
439
+ fan_out_id: exports_ids_schema.ChildFanOutId
440
+ }).annotate({ identifier: "Relay.Operation.InspectChildFanOutInput" });
441
+ var InspectChildFanOutResult = Schema.Struct({
442
+ fan_out: Schema.NullOr(exports_child_orchestration_schema.FanOutState)
443
+ }).annotate({ identifier: "Relay.Operation.InspectChildFanOutResult" });
444
+ var ResolveToolApprovalInput = Schema.Struct({
445
+ wait_id: exports_ids_schema.WaitId,
446
+ approved: Schema.Boolean,
447
+ comment: Schema.optionalKey(Schema.String),
448
+ resolved_at: exports_shared_schema.TimestampMillis
449
+ }).annotate({ identifier: "Relay.Operation.ResolveToolApprovalInput" });
450
+ var PermissionAnswer = Schema.Literals(["Approved", "Denied", "Always"]).annotate({
451
+ identifier: "Relay.Operation.PermissionAnswer"
452
+ });
453
+ var ResolvePermissionInput = Schema.Struct({
454
+ wait_id: exports_ids_schema.WaitId,
455
+ answer: PermissionAnswer,
456
+ reason: Schema.optionalKey(Schema.String),
457
+ resolved_at: exports_shared_schema.TimestampMillis
458
+ }).annotate({ identifier: "Relay.Operation.ResolvePermissionInput" });
459
+ var SubmitInboundEnvelopeInput = Schema.Struct({
460
+ envelope: exports_envelope_schema.SendInput,
461
+ wake: WakeInput
462
+ }).annotate({ identifier: "Relay.Operation.SubmitInboundEnvelopeInput" });
463
+ var SubmitInboundEnvelopeAccepted = Schema.Struct({
464
+ envelope: exports_envelope_schema.EnvelopeAccepted,
465
+ wake: WakeAccepted
466
+ }).annotate({ identifier: "Relay.Operation.SubmitInboundEnvelopeAccepted" });
467
+ var ClaimEnvelopeReadyInput = Schema.Struct({
468
+ route_type: exports_address_schema.RouteKind,
469
+ route_key: Schema.optionalKey(Schema.String),
470
+ worker_id: exports_shared_schema.NonEmptyString,
471
+ now: exports_shared_schema.TimestampMillis,
472
+ claim_expires_at: exports_shared_schema.TimestampMillis
473
+ }).annotate({ identifier: "Relay.Operation.ClaimEnvelopeReadyInput" });
474
+ var EnvelopeReadyLease = Schema.Struct({
475
+ ready: exports_envelope_schema.EnvelopeReady,
476
+ worker_id: exports_shared_schema.NonEmptyString,
477
+ claim_expires_at: exports_shared_schema.TimestampMillis
478
+ }).annotate({ identifier: "Relay.Operation.EnvelopeReadyLease" });
479
+ var AckEnvelopeReadyInput = Schema.Struct({
480
+ envelope_ready_id: exports_ids_schema.EnvelopeReadyId,
481
+ worker_id: exports_shared_schema.NonEmptyString,
482
+ acknowledged_at: exports_shared_schema.TimestampMillis
483
+ }).annotate({ identifier: "Relay.Operation.AckEnvelopeReadyInput" });
484
+ var EnvelopeReadyAcked = Schema.Struct({
485
+ envelope_ready_id: exports_ids_schema.EnvelopeReadyId,
486
+ state: Schema.Literal("acknowledged"),
487
+ acknowledged_at: exports_shared_schema.TimestampMillis
488
+ }).annotate({ identifier: "Relay.Operation.EnvelopeReadyAcked" });
489
+ var ReleaseEnvelopeReadyInput = Schema.Struct({
490
+ envelope_ready_id: exports_ids_schema.EnvelopeReadyId,
491
+ worker_id: exports_shared_schema.NonEmptyString,
492
+ next_available_at: exports_shared_schema.TimestampMillis,
493
+ error: Schema.optionalKey(Schema.String)
494
+ }).annotate({ identifier: "Relay.Operation.ReleaseEnvelopeReadyInput" });
495
+ var EnvelopeReadyReleased = Schema.Struct({
496
+ envelope_ready_id: exports_ids_schema.EnvelopeReadyId,
497
+ state: Schema.Literal("ready"),
498
+ next_available_at: exports_shared_schema.TimestampMillis
499
+ }).annotate({ identifier: "Relay.Operation.EnvelopeReadyReleased" });
500
+ var CreateScheduleInput = Schema.Struct({
501
+ schedule_id: exports_ids_schema.ScheduleId,
502
+ kind: exports_schedule_schema.ScheduleKind,
503
+ target_kind: exports_schedule_schema.ScheduleTargetKind,
504
+ address_id: Schema.optionalKey(exports_ids_schema.AddressId),
505
+ wait_id: Schema.optionalKey(exports_ids_schema.WaitId),
506
+ cron_expr: Schema.optionalKey(exports_shared_schema.NonEmptyString),
507
+ input: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
508
+ next_run_at: exports_shared_schema.TimestampMillis,
509
+ idempotency_key: Schema.optionalKey(exports_shared_schema.NonEmptyString),
510
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata)
511
+ }).annotate({ identifier: "Relay.Operation.CreateScheduleInput" });
512
+ var CreateScheduleResult = Schema.Struct({
513
+ schedule: exports_schedule_schema.ScheduleRecord
514
+ }).annotate({ identifier: "Relay.Operation.CreateScheduleResult" });
515
+ var CancelScheduleInput = Schema.Struct({
516
+ schedule_id: exports_ids_schema.ScheduleId,
517
+ cancelled_at: exports_shared_schema.TimestampMillis
518
+ }).annotate({ identifier: "Relay.Operation.CancelScheduleInput" });
519
+ var CancelScheduleResult = Schema.Struct({
520
+ schedule: exports_schedule_schema.ScheduleRecord
521
+ }).annotate({ identifier: "Relay.Operation.CancelScheduleResult" });
522
+ var ListSchedulesInput = Schema.Struct({
523
+ state: Schema.optionalKey(exports_schedule_schema.ScheduleState)
524
+ }).annotate({ identifier: "Relay.Operation.ListSchedulesInput" });
525
+ var ListSchedulesResult = Schema.Struct({
526
+ schedules: Schema.Array(exports_schedule_schema.ScheduleRecord)
527
+ }).annotate({ identifier: "Relay.Operation.ListSchedulesResult" });
528
+ var ListExecutionsInput = Schema.Struct({
529
+ root_address_id: Schema.optionalKey(exports_ids_schema.AddressId),
530
+ status: Schema.optionalKey(exports_execution_schema.ExecutionStatus),
531
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
532
+ cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
533
+ }).annotate({ identifier: "Relay.Operation.ListExecutionsInput" });
534
+ var SubscribeTopicInput = Schema.Struct({
535
+ topic_address_id: exports_ids_schema.AddressId,
536
+ subscriber_execution_id: exports_ids_schema.ExecutionId,
537
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata)
538
+ }).annotate({ identifier: "Relay.Operation.SubscribeTopicInput" });
539
+ var TopicSubscription = Schema.Struct({
540
+ topic_address_id: exports_ids_schema.AddressId,
541
+ subscriber_execution_id: exports_ids_schema.ExecutionId,
542
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata),
543
+ created_at: exports_shared_schema.TimestampMillis
544
+ }).annotate({ identifier: "Relay.Operation.TopicSubscription" });
545
+ var PublishTopicInput = Schema.Struct({
546
+ topic_address_id: exports_ids_schema.AddressId,
547
+ from: exports_ids_schema.AddressId,
548
+ content: Schema.Array(exports_content_schema.Part),
549
+ metadata: Schema.optionalKey(exports_shared_schema.Metadata),
550
+ idempotency_key: Schema.optionalKey(exports_shared_schema.NonEmptyString)
551
+ }).annotate({ identifier: "Relay.Operation.PublishTopicInput" });
552
+ var TopicPublishAccepted = Schema.Struct({
553
+ envelope_id: exports_ids_schema.EnvelopeId,
554
+ subscriber_count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
555
+ }).annotate({ identifier: "Relay.Operation.TopicPublishAccepted" });
556
+ var UnsubscribeTopicInput = Schema.Struct({
557
+ topic_address_id: exports_ids_schema.AddressId,
558
+ subscriber_execution_id: exports_ids_schema.ExecutionId
559
+ }).annotate({ identifier: "Relay.Operation.UnsubscribeTopicInput" });
560
+ var ListTopicSubscriptionsInput = Schema.Struct({
561
+ topic_address_id: Schema.optionalKey(exports_ids_schema.AddressId),
562
+ subscriber_execution_id: Schema.optionalKey(exports_ids_schema.ExecutionId)
563
+ }).annotate({ identifier: "Relay.Operation.ListTopicSubscriptionsInput" });
564
+ var ListInboxMessagesInput = Schema.Struct({
565
+ execution_id: exports_ids_schema.ExecutionId,
566
+ include_consumed: Schema.optionalKey(Schema.Boolean),
567
+ after_sequence: Schema.optionalKey(exports_inbox_schema.MessageSequence),
568
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
569
+ }).annotate({ identifier: "Relay.Operation.ListInboxMessagesInput" });
570
+ var ConversationKind = Schema.Literals(["user-agent", "agent-agent"]).annotate({
571
+ identifier: "Relay.Operation.ConversationKind"
572
+ });
573
+ var ConversationSummary = Schema.Struct({
574
+ execution_id: exports_ids_schema.ExecutionId,
575
+ root_address_id: exports_ids_schema.AddressId,
576
+ session_id: Schema.optionalKey(exports_ids_schema.SessionId),
577
+ status: exports_execution_schema.ExecutionStatus,
578
+ kind: ConversationKind,
579
+ agent_id: Schema.optionalKey(exports_ids_schema.AgentId),
580
+ metadata: exports_shared_schema.Metadata,
581
+ created_at: exports_shared_schema.TimestampMillis,
582
+ updated_at: exports_shared_schema.TimestampMillis
583
+ }).annotate({ identifier: "Relay.Operation.ConversationSummary" });
584
+ var ExecutionCursor = Schema.Struct({
585
+ execution_id: exports_ids_schema.ExecutionId,
586
+ after_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
587
+ }).annotate({ identifier: "Relay.Operation.ExecutionCursor" });
588
+
589
+ class EventLogCursorNotFound extends Schema.TaggedErrorClass()("EventLogCursorNotFound", { execution_id: exports_ids_schema.ExecutionId, cursor: exports_shared_schema.NonEmptyString }) {
590
+ }
591
+ var StreamSessionInput = Schema.Struct({
592
+ session_id: exports_ids_schema.SessionId,
593
+ resume: Schema.optionalKey(Schema.Array(ExecutionCursor))
594
+ }).annotate({ identifier: "Relay.Operation.StreamSessionInput" });
595
+ var SessionStreamItem = Schema.Union([
596
+ Schema.TaggedStruct("execution_joined", { execution: ConversationSummary }),
597
+ Schema.TaggedStruct("execution_event", { event: exports_execution_schema.ExecutionEvent })
598
+ ]).annotate({ identifier: "Relay.Operation.SessionStreamItem" });
599
+ var WatchExecutionsInput = Schema.Struct({
600
+ root_address_id: Schema.optionalKey(exports_ids_schema.AddressId),
601
+ session_id: Schema.optionalKey(exports_ids_schema.SessionId),
602
+ status: Schema.optionalKey(exports_execution_schema.ExecutionStatus),
603
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
604
+ }).annotate({ identifier: "Relay.Operation.WatchExecutionsInput" });
605
+ var ExecutionListChange = Schema.Union([
606
+ Schema.TaggedStruct("snapshot", {
607
+ records: Schema.Array(ConversationSummary),
608
+ next_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
609
+ }),
610
+ Schema.TaggedStruct("upsert", { record: ConversationSummary })
611
+ ]).annotate({ identifier: "Relay.Operation.ExecutionListChange" });
612
+ var ToolCallSummary = Schema.Struct({
613
+ tool_call_id: exports_ids_schema.ToolCallId,
614
+ tool_name: exports_shared_schema.NonEmptyString,
615
+ input: exports_shared_schema.JsonValue,
616
+ metadata: exports_shared_schema.Metadata,
617
+ requested_at: exports_shared_schema.TimestampMillis
618
+ }).annotate({ identifier: "Relay.Operation.ToolCallSummary" });
619
+ var ChildRunSummary = Schema.Struct({
620
+ child_execution_id: exports_ids_schema.ChildExecutionId,
621
+ address_id: exports_ids_schema.AddressId,
622
+ status: exports_execution_schema.ExecutionStatus,
623
+ metadata: exports_shared_schema.Metadata,
624
+ created_at: exports_shared_schema.TimestampMillis,
625
+ updated_at: exports_shared_schema.TimestampMillis
626
+ }).annotate({ identifier: "Relay.Operation.ChildRunSummary" });
627
+ var ExecutionInspection = Schema.Struct({
628
+ execution_id: exports_ids_schema.ExecutionId,
629
+ status: exports_execution_schema.ExecutionStatus,
630
+ waiting_on: Schema.Array(WaitView),
631
+ pending_tool_calls: Schema.Array(ToolCallSummary),
632
+ child_runs: Schema.Array(ChildRunSummary),
633
+ last_event_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
634
+ }).annotate({ identifier: "Relay.Operation.ExecutionInspection" });
635
+ var ListExecutionsResult = Schema.Struct({
636
+ records: Schema.Array(ConversationSummary),
637
+ next_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
638
+ }).annotate({ identifier: "Relay.Operation.ListExecutionsResult" });
639
+ var ListSessionsInput = Schema.Struct({
640
+ root_address_id: Schema.optionalKey(exports_ids_schema.AddressId),
641
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
642
+ cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
643
+ }).annotate({ identifier: "Relay.Operation.ListSessionsInput" });
644
+ var SessionSummary = Schema.Struct({
645
+ session_id: exports_ids_schema.SessionId,
646
+ root_address_id: exports_ids_schema.AddressId,
647
+ metadata: exports_shared_schema.Metadata,
648
+ created_at: exports_shared_schema.TimestampMillis,
649
+ updated_at: exports_shared_schema.TimestampMillis
650
+ }).annotate({ identifier: "Relay.Operation.SessionSummary" });
651
+ var ListSessionsResult = Schema.Struct({
652
+ records: Schema.Array(SessionSummary),
653
+ next_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
654
+ }).annotate({ identifier: "Relay.Operation.ListSessionsResult" });
655
+ var GetSessionInput = Schema.Struct({
656
+ session_id: exports_ids_schema.SessionId,
657
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
658
+ cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
659
+ }).annotate({ identifier: "Relay.Operation.GetSessionInput" });
660
+ var GetSessionResult = Schema.Struct({
661
+ session: SessionSummary,
662
+ executions: Schema.Array(ConversationSummary),
663
+ next_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString)
664
+ }).annotate({ identifier: "Relay.Operation.GetSessionResult" });
665
+ var ReplayExecutionInput = Schema.Struct({
666
+ execution_id: exports_ids_schema.ExecutionId,
667
+ after_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString),
668
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
669
+ }).annotate({ identifier: "Relay.Operation.ReplayExecutionInput" });
670
+ var ReplayExecutionResult = Schema.Struct({
671
+ events: Schema.Array(exports_execution_schema.ExecutionEvent)
672
+ }).annotate({ identifier: "Relay.Operation.ReplayExecutionResult" });
673
+ var RunnerSummary = Schema.Struct({
674
+ address: Schema.String,
675
+ healthy: Schema.Boolean,
676
+ last_heartbeat: exports_shared_schema.TimestampMillis,
677
+ owned_shards: Schema.Int
678
+ }).annotate({ identifier: "Relay.Operation.RunnerSummary" });
679
+ var ListRunnersResult = Schema.Struct({
680
+ runners: Schema.Array(RunnerSummary),
681
+ total_shards: Schema.Int
682
+ }).annotate({ identifier: "Relay.Operation.ListRunnersResult" });
683
+ var RouteExecutionResult = Schema.Struct({
684
+ execution_id: exports_ids_schema.ExecutionId,
685
+ shard: Schema.String,
686
+ runner_address: Schema.NullOr(Schema.String),
687
+ owned: Schema.Boolean
688
+ }).annotate({ identifier: "Relay.Operation.RouteExecutionResult" });
689
+
690
+ // src/command.ts
691
+ var exports_command = {};
692
+ __export(exports_command, {
693
+ outputSchemaRef: () => outputSchemaRef,
694
+ make: () => make,
695
+ inputSchemaRef: () => inputSchemaRef,
696
+ EntityNotFound: () => EntityNotFound,
697
+ CommandTimedOut: () => CommandTimedOut,
698
+ CommandReplyInvalid: () => CommandReplyInvalid
699
+ });
700
+ import { Schema as Schema2 } from "effect";
701
+ var make = (name, options) => ({ name, ...options });
702
+ var inputSchemaRef = (name) => `relay/command/${name}/input`;
703
+ var outputSchemaRef = (name) => `relay/command/${name}/output`;
704
+
705
+ class CommandTimedOut extends Schema2.TaggedErrorClass()("CommandTimedOut", {
706
+ command: exports_shared_schema.NonEmptyString,
707
+ wait_id: exports_ids_schema.WaitId,
708
+ timeout: Schema2.String
709
+ }) {
710
+ }
711
+
712
+ class CommandReplyInvalid extends Schema2.TaggedErrorClass()("CommandReplyInvalid", {
713
+ command: exports_shared_schema.NonEmptyString,
714
+ wait_id: exports_ids_schema.WaitId,
715
+ message: Schema2.String
716
+ }) {
717
+ }
718
+
719
+ class EntityNotFound extends Schema2.TaggedErrorClass()("EntityNotFound", {
720
+ kind: exports_ids_schema.EntityKindName,
721
+ key: exports_ids_schema.EntityKey
722
+ }) {
723
+ }
724
+
725
+ // src/client.ts
726
+ var exports_client = {};
727
+ __export(exports_client, {
728
+ watchPresence: () => watchPresence,
729
+ watchExecutions: () => watchExecutions,
730
+ wake: () => wake,
731
+ unsubscribeTopic: () => unsubscribeTopic,
732
+ testLayer: () => testLayer,
733
+ subscribeTopic: () => subscribeTopic,
734
+ submitInboundEnvelope: () => submitInboundEnvelope,
735
+ streamSession: () => streamSession,
736
+ streamExecution: () => streamExecution,
737
+ steer: () => steer,
738
+ startExecutionByAgentDefinition: () => startExecutionByAgentDefinition,
739
+ startExecutionByAddress: () => startExecutionByAddress,
740
+ startExecution: () => startExecution,
741
+ spawnChildRun: () => spawnChildRun,
742
+ send: () => send,
743
+ routeExecution: () => routeExecution,
744
+ resolveToolApproval: () => resolveToolApproval,
745
+ resolvePermission: () => resolvePermission,
746
+ replayExecution: () => replayExecution,
747
+ releaseToolWork: () => releaseToolWork,
748
+ releaseEnvelopeReady: () => releaseEnvelopeReady,
749
+ registerEntityKind: () => registerEntityKind,
750
+ registerAgentDefinition: () => registerAgentDefinition,
751
+ registerAgent: () => registerAgent,
752
+ registerAddressBookRoute: () => registerAddressBookRoute,
753
+ publishTopic: () => publishTopic,
754
+ listWaits: () => listWaits,
755
+ listTopicSubscriptions: () => listTopicSubscriptions,
756
+ listToolAttempts: () => listToolAttempts,
757
+ listSkillDefinitions: () => listSkillDefinitions,
758
+ listSkillDefinitionRevisions: () => listSkillDefinitionRevisions,
759
+ listSessions: () => listSessions,
760
+ listSchedules: () => listSchedules,
761
+ listRunners: () => listRunners,
762
+ listPendingToolCalls: () => listPendingToolCalls,
763
+ listPendingApprovals: () => listPendingApprovals,
764
+ listInboxMessages: () => listInboxMessages,
765
+ listExecutions: () => listExecutions,
766
+ listEntities: () => listEntities,
767
+ listAgentDefinitions: () => listAgentDefinitions,
768
+ listAgentDefinitionRevisions: () => listAgentDefinitionRevisions,
769
+ listAddressBookRoutes: () => listAddressBookRoutes,
770
+ layerFromRuntime: () => layerFromRuntime,
771
+ inspectExecution: () => inspectExecution,
772
+ inspectChildFanOut: () => inspectChildFanOut,
773
+ getSkillDefinition: () => getSkillDefinition,
774
+ getSession: () => getSession,
775
+ getPresence: () => getPresence,
776
+ getOrCreateEntity: () => getOrCreateEntity,
777
+ getExecution: () => getExecution,
778
+ getEntity: () => getEntity,
779
+ getAgentDefinition: () => getAgentDefinition,
780
+ getAddressBookRoute: () => getAddressBookRoute,
781
+ fulfillToolCall: () => fulfillToolCall,
782
+ followExecutionFrom: () => followExecutionFrom,
783
+ followExecution: () => followExecution,
784
+ destroyEntity: () => destroyEntity,
785
+ createSchedule: () => createSchedule,
786
+ createChildFanOut: () => createChildFanOut,
787
+ completeToolWork: () => completeToolWork,
788
+ claimToolWork: () => claimToolWork,
789
+ claimEnvelopeReady: () => claimEnvelopeReady,
790
+ cancelSchedule: () => cancelSchedule,
791
+ cancelExecution: () => cancelExecution,
792
+ cancelChildFanOut: () => cancelChildFanOut,
793
+ awaitWait: () => awaitWait,
794
+ askEntity: () => askEntity,
795
+ ackEnvelopeReady: () => ackEnvelopeReady,
796
+ WaitKindMismatch: () => WaitKindMismatch,
797
+ Service: () => Service,
798
+ ExecutionNotFound: () => ExecutionNotFound,
799
+ EventLogCursorNotFound: () => EventLogCursorNotFound,
800
+ EntityNamespaceReserved: () => EntityNamespaceReserved,
801
+ ClientError: () => ClientError
802
+ });
803
+ import { Clock, Context, Effect, Layer, Option, Schema as Schema3, SchemaGetter, SchemaIssue, Stream } from "effect";
804
+ import { EntityId, ShardId, Sharding, ShardingConfig } from "effect/unstable/cluster";
805
+ class ClientError extends Schema3.TaggedErrorClass()("ClientError", {
806
+ message: Schema3.String
807
+ }) {
808
+ }
809
+
810
+ class ExecutionNotFound extends Schema3.TaggedErrorClass()("ExecutionNotFound", {
811
+ execution_id: exports_ids_schema.ExecutionId
812
+ }) {
813
+ }
814
+
815
+ class EntityNamespaceReserved extends Schema3.TaggedErrorClass()("EntityNamespaceReserved", { id: Schema3.String, message: Schema3.String }) {
816
+ }
817
+
818
+ class WaitKindMismatch extends Schema3.TaggedErrorClass()("WaitKindMismatch", {
819
+ wait_id: exports_ids_schema.WaitId,
820
+ expected: Schema3.String,
821
+ actual: Schema3.String,
822
+ message: Schema3.String
823
+ }) {
824
+ }
825
+
826
+ class Service extends Context.Service()("@relayfx/sdk/Client") {
827
+ }
828
+ var followTerminalStatus = (type) => type === "execution.completed" ? "completed" : type === "execution.failed" ? "failed" : type === "execution.cancelled" ? "cancelled" : undefined;
829
+ var followReconnectDelayMillis = (attempt) => Math.min(100 * 2 ** (attempt - 1), 5000);
830
+ var followStopped = (reason, cursor) => ({
831
+ _tag: "stopped",
832
+ reason,
833
+ cursor: cursor ?? null
834
+ });
835
+ var followExecutionFrom = (dependencies) => (input) => {
836
+ const maxReconnects = input.max_reconnects ?? 10;
837
+ const stopModes = input.stop_on_wait_modes;
838
+ const inspect = Effect.suspend(() => dependencies.inspectExecution(input.execution_id)).pipe(Effect.catchTag("ExecutionNotFound", (error) => new ClientError({ message: `execution ${error.execution_id} not found` })));
839
+ const reconcile = (state, message) => Stream.unwrap(Effect.gen(function* () {
840
+ const inspection = yield* inspect;
841
+ const terminal = followTerminalStatus(`execution.${inspection.status}`);
842
+ if (terminal !== undefined) {
843
+ return Stream.make(followStopped({ _tag: "terminal", status: terminal }, state.cursor));
844
+ }
845
+ const actionable = stopModes === undefined ? undefined : inspection.waiting_on.find((wait) => wait.state === "open" && stopModes.includes(wait.mode));
846
+ if (actionable !== undefined) {
847
+ return Stream.make(followStopped({ _tag: "actionable_wait", wait: actionable }, state.cursor));
848
+ }
849
+ if (state.attempts >= maxReconnects) {
850
+ return Stream.fail(new ClientError({
851
+ message: `follow of ${input.execution_id} exhausted ${maxReconnects} reconnects: ${message}`
852
+ }));
853
+ }
854
+ state.attempts += 1;
855
+ const reconnecting = { _tag: "reconnecting", message, attempt: state.attempts };
856
+ return Stream.make(reconnecting).pipe(Stream.concat(Stream.fromEffect(Effect.sleep(followReconnectDelayMillis(state.attempts))).pipe(Stream.drain)), Stream.concat(Stream.suspend(() => connect(state))));
857
+ }));
858
+ const itemsFor = (state, event) => Effect.gen(function* () {
859
+ if (event.sequence <= state.sequence)
860
+ return [];
861
+ state.sequence = event.sequence;
862
+ state.cursor = event.cursor;
863
+ state.emitted = true;
864
+ state.attempts = 0;
865
+ const items = [{ _tag: "event", event }];
866
+ const terminal = followTerminalStatus(event.type);
867
+ if (terminal !== undefined) {
868
+ items.push(followStopped({ _tag: "terminal", status: terminal }, state.cursor));
869
+ return items;
870
+ }
871
+ if (stopModes !== undefined && event.type === "wait.created") {
872
+ const mode = event.data?.mode;
873
+ if (typeof mode === "string" && stopModes.includes(mode)) {
874
+ const inspection = yield* dependencies.inspectExecution(input.execution_id).pipe(Effect.catchTag("ExecutionNotFound", () => Effect.succeed(undefined)));
875
+ const actionable = inspection?.waiting_on.find((wait) => wait.state === "open" && wait.wait_id === event.data?.wait_id);
876
+ if (actionable !== undefined) {
877
+ items.push(followStopped({ _tag: "actionable_wait", wait: actionable }, state.cursor));
878
+ }
879
+ }
880
+ }
881
+ return items;
882
+ });
883
+ const connect = (state) => dependencies.streamExecution({
884
+ execution_id: input.execution_id,
885
+ ...state.cursor === undefined ? {} : { after_cursor: state.cursor }
886
+ }).pipe(Stream.flatMap((event) => Stream.fromEffect(itemsFor(state, event)).pipe(Stream.flatMap((items) => Stream.fromIterable(items)))), Stream.catchTag("EventLogCursorNotFound", (error) => !state.emitted && input.after_cursor !== undefined ? Stream.fail(error) : reconcile(state, `cursor ${error.cursor} was not found`)), Stream.catchTag("ClientError", (error) => reconcile(state, `stream failed: ${error.message}`)), Stream.concat(Stream.suspend(() => reconcile(state, "stream ended before a terminal event"))));
887
+ return Stream.unwrap(Effect.gen(function* () {
888
+ const existing = yield* dependencies.getExecution(input.execution_id);
889
+ if (existing === undefined) {
890
+ return Stream.fail(new ClientError({ message: `execution ${input.execution_id} not found` }));
891
+ }
892
+ const state = {
893
+ cursor: input.after_cursor,
894
+ sequence: -1,
895
+ attempts: 0,
896
+ emitted: false
897
+ };
898
+ return connect(state);
899
+ })).pipe(Stream.takeUntil((item) => item._tag === "stopped"));
900
+ };
901
+ var errorMessage = (error) => {
902
+ if (error instanceof Error)
903
+ return error.message;
904
+ if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
905
+ return error.message;
906
+ }
907
+ if (typeof error === "object" && error !== null && "_tag" in error && typeof error._tag === "string") {
908
+ return error._tag;
909
+ }
910
+ return String(error);
911
+ };
912
+ var toClientError = (error) => new ClientError({ message: errorMessage(error) });
913
+ var rejectReserved = (id, prefix) => id.startsWith(prefix) ? Effect.fail(new EntityNamespaceReserved({ id, message: "start entities via Client.getOrCreateEntity" })) : Effect.void;
914
+ var replyValueFrom = (content) => {
915
+ if (content === undefined || content.length === 0)
916
+ return Option.none();
917
+ const structured = content.find((part) => part.type === "structured");
918
+ if (structured !== undefined)
919
+ return Option.some(structured.value);
920
+ const text = content.filter((part) => part.type === "text").map((part) => part.text).join("");
921
+ if (text.length === 0)
922
+ return Option.none();
923
+ try {
924
+ return Option.some(JSON.parse(text));
925
+ } catch {
926
+ return Option.none();
927
+ }
928
+ };
929
+ var toStreamError = (error) => Option.match(Schema3.decodeUnknownOption(EventLogCursorNotFound)(error), {
930
+ onNone: () => toClientError(error),
931
+ onSome: (cursorError) => cursorError
932
+ });
933
+ var malformedCursor = (wire) => new SchemaIssue.InvalidValue(Option.some(wire), { message: "Malformed pagination cursor" });
934
+ var decodeCursorFields = (wire) => Effect.gen(function* () {
935
+ const decoded = yield* Effect.try({
936
+ try: () => globalThis.atob(wire),
937
+ catch: () => malformedCursor(wire)
938
+ });
939
+ const separator = decoded.indexOf(":");
940
+ if (separator === -1)
941
+ return yield* Effect.fail(malformedCursor(wire));
942
+ const updatedAt = Number(decoded.slice(0, separator));
943
+ if (!Number.isFinite(updatedAt))
944
+ return yield* Effect.fail(malformedCursor(wire));
945
+ return { updatedAt, id: decoded.slice(separator + 1) };
946
+ });
947
+ var ExecutionCursorFromString = exports_shared_schema.NonEmptyString.pipe(Schema3.decodeTo(Schema3.Struct({ updatedAt: Schema3.Int, id: exports_ids_schema.ExecutionId }), {
948
+ decode: SchemaGetter.transformOrFail((wire) => decodeCursorFields(wire)),
949
+ encode: SchemaGetter.transform((cursor) => globalThis.btoa(`${cursor.updatedAt}:${cursor.id}`))
950
+ })).annotate({ identifier: "Relay.Client.ExecutionCursor" });
951
+ var encodeExecutionCursor = (cursor) => Schema3.encodeEffect(ExecutionCursorFromString)(cursor).pipe(Effect.mapError(toClientError));
952
+ var SessionCursorFromString = exports_shared_schema.NonEmptyString.pipe(Schema3.decodeTo(Schema3.Struct({ updatedAt: Schema3.Int, id: exports_ids_schema.SessionId }), {
953
+ decode: SchemaGetter.transformOrFail((wire) => decodeCursorFields(wire)),
954
+ encode: SchemaGetter.transform((cursor) => globalThis.btoa(`${cursor.updatedAt}:${cursor.id}`))
955
+ })).annotate({ identifier: "Relay.Client.SessionCursor" });
956
+ var conversationKind = (metadata) => metadata.kind === "agent-agent" ? "agent-agent" : "user-agent";
957
+ var toConversationSummary = (record) => ({
958
+ execution_id: record.id,
959
+ root_address_id: record.rootAddressId,
960
+ ...record.sessionId === undefined ? {} : { session_id: record.sessionId },
961
+ status: record.status,
962
+ kind: conversationKind(record.metadata),
963
+ ...record.agentId === undefined ? {} : { agent_id: record.agentId },
964
+ metadata: record.metadata,
965
+ created_at: record.createdAt,
966
+ updated_at: record.updatedAt
967
+ });
968
+ var toExecutionView = (record) => ({
969
+ id: record.id,
970
+ root_address_id: record.rootAddressId,
971
+ ...record.sessionId === undefined ? {} : { session_id: record.sessionId },
972
+ status: record.status,
973
+ ...record.agentId === undefined ? {} : { agent_id: record.agentId },
974
+ ...record.agentRevision === undefined ? {} : { agent_revision: record.agentRevision },
975
+ ...record.agentSnapshot === undefined ? {} : { agent_snapshot: record.agentSnapshot },
976
+ ...record.agentToolInputSchemaDigests === undefined ? {} : { agent_tool_input_schema_digests: record.agentToolInputSchemaDigests },
977
+ metadata: record.metadata,
978
+ created_at: record.createdAt,
979
+ updated_at: record.updatedAt
980
+ });
981
+ var toWaitView = (record) => ({
982
+ wait_id: record.id,
983
+ execution_id: record.executionId,
984
+ ...record.envelopeId === undefined ? {} : { envelope_id: record.envelopeId },
985
+ kind: exports_wait_schema.classify({
986
+ wait_id: record.id,
987
+ mode: record.mode,
988
+ ...record.envelopeId === undefined ? {} : { envelope_id: record.envelopeId },
989
+ ...record.correlationKey === undefined ? {} : { correlation_key: record.correlationKey }
990
+ }).kind,
991
+ mode: record.mode,
992
+ ...record.correlationKey === undefined ? {} : { correlation_key: record.correlationKey },
993
+ state: record.state,
994
+ metadata: record.metadata,
995
+ created_at: record.createdAt,
996
+ ...record.resolvedAt === undefined ? {} : { resolved_at: record.resolvedAt }
997
+ });
998
+ var toSessionSummary = (record) => ({
999
+ session_id: record.id,
1000
+ root_address_id: record.rootAddressId,
1001
+ metadata: record.metadata,
1002
+ created_at: record.createdAt,
1003
+ updated_at: record.updatedAt
1004
+ });
1005
+ var toToolCallSummary = (record) => ({
1006
+ tool_call_id: record.call.id,
1007
+ tool_name: record.call.name,
1008
+ input: record.call.input,
1009
+ metadata: record.call.metadata ?? {},
1010
+ requested_at: record.createdAt
1011
+ });
1012
+ var toChildRunSummary = (record) => ({
1013
+ child_execution_id: record.id,
1014
+ address_id: record.addressId,
1015
+ status: record.status,
1016
+ metadata: record.metadata,
1017
+ created_at: record.createdAt,
1018
+ updated_at: record.updatedAt
1019
+ });
1020
+ var executionIdFromIdempotencyKey = (idempotencyKey) => exports_ids_schema.ExecutionId.make(`execution:${idempotencyKey}`);
1021
+ var metadataWithIdempotencyKey = (metadata, idempotencyKey) => ({
1022
+ ...metadata,
1023
+ idempotency_key: idempotencyKey
1024
+ });
1025
+ var startExecutionByAddressPayload = (input) => ({
1026
+ execution_id: input.execution_id ?? executionIdFromIdempotencyKey(input.idempotency_key),
1027
+ root_address_id: input.address_id,
1028
+ ...input.session_id === undefined ? {} : { session_id: input.session_id },
1029
+ ...input.input === undefined ? {} : { input: [...input.input] },
1030
+ event_sequence: input.event_sequence ?? 0,
1031
+ started_at: input.started_at,
1032
+ completed_at: input.completed_at,
1033
+ ...input.wait_id === undefined ? {} : { wait_id: input.wait_id },
1034
+ metadata: metadataWithIdempotencyKey(input.metadata, input.idempotency_key)
1035
+ });
1036
+ var startExecutionByAgentDefinitionPayload = (input, definition) => ({
1037
+ execution_id: input.execution_id ?? executionIdFromIdempotencyKey(input.idempotency_key),
1038
+ root_address_id: input.root_address_id,
1039
+ ...input.session_id === undefined ? {} : { session_id: input.session_id },
1040
+ ...input.input === undefined ? {} : { input: [...input.input] },
1041
+ event_sequence: input.event_sequence ?? 0,
1042
+ started_at: input.started_at,
1043
+ completed_at: input.completed_at,
1044
+ agent_id: input.agent_id,
1045
+ agent_revision: definition.current_revision,
1046
+ agent_snapshot: definition.definition,
1047
+ ...definition.tool_input_schema_digests === undefined ? {} : { agent_tool_input_schema_digests: definition.tool_input_schema_digests },
1048
+ ...input.wait_id === undefined ? {} : { wait_id: input.wait_id },
1049
+ metadata: metadataWithIdempotencyKey(input.metadata, input.idempotency_key)
1050
+ });
1051
+ var isRegisterBatonAgentInput = (input) => ("agent" in input);
1052
+ var toolRefsFromBatonAgent = (agent) => {
1053
+ const tools = agent.toolkit.tools;
1054
+ return Object.values(tools).map((tool) => ({ name: tool.name }));
1055
+ };
1056
+ var modelSelectionFromBatonAgent = (selection) => ({
1057
+ provider: selection.provider,
1058
+ model: selection.model,
1059
+ ...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
1060
+ });
1061
+ var decodeBatonAgentName = (name) => Schema3.decodeUnknownEffect(exports_shared_schema.NonEmptyString)(name).pipe(Effect.mapError(() => new ClientError({ message: "Baton agent name must not be blank" })));
1062
+ var decodeBatonAgentMetadata = (metadata) => metadata === undefined ? Effect.succeed(undefined) : Schema3.decodeUnknownEffect(exports_shared_schema.Metadata)(metadata).pipe(Effect.mapError(() => new ClientError({ message: "Baton agent metadata must be JSON metadata" })));
1063
+ var decodeBatonMemorySubject = (subject) => Schema3.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect.mapError(() => new ClientError({ message: "Baton agent memory subject must be a MemorySubjectId" })));
1064
+ var metadataFromBatonAgent = Effect.fn("Client.metadataFromBatonAgent")(function* (input) {
1065
+ const agentMetadata = yield* decodeBatonAgentMetadata(input.agent.metadata);
1066
+ const memorySubject = input.agent.memory === undefined ? undefined : yield* decodeBatonMemorySubject(input.agent.memory.subject);
1067
+ const metadata = {
1068
+ ...agentMetadata,
1069
+ ...memorySubject === undefined ? {} : { memory_subject_id: memorySubject },
1070
+ ...input.metadata
1071
+ };
1072
+ return Object.keys(metadata).length === 0 ? undefined : metadata;
1073
+ });
1074
+ var modelSelectionFromRegisterInput = (input) => {
1075
+ if (input.model !== undefined)
1076
+ return Effect.succeed(input.model);
1077
+ if (input.agent.model !== undefined)
1078
+ return Effect.succeed(modelSelectionFromBatonAgent(input.agent.model));
1079
+ return Effect.fail(new ClientError({ message: "Client.registerAgent requires model or agent.model" }));
1080
+ };
1081
+ var batonTurnPolicyInvalid = (detail) => new ClientError({ message: `Baton agent turn policy is not durably portable: ${detail}` });
1082
+ var turnPolicySnapshotFromBaton = Effect.fn("Client.turnPolicySnapshotFromBaton")(function* (snapshot) {
1083
+ let nodes = 0;
1084
+ const visit = (current, depth) => Effect.gen(function* () {
1085
+ if (typeof current !== "object" || current === null || Array.isArray(current)) {
1086
+ return yield* Effect.fail(batonTurnPolicyInvalid("snapshot nodes must be objects"));
1087
+ }
1088
+ const node = current;
1089
+ nodes += 1;
1090
+ if (depth > exports_agent_schema.maxTurnPolicySnapshotDepth) {
1091
+ return yield* Effect.fail(batonTurnPolicyInvalid(`depth exceeds ${exports_agent_schema.maxTurnPolicySnapshotDepth}`));
1092
+ }
1093
+ if (nodes > exports_agent_schema.maxTurnPolicySnapshotNodes) {
1094
+ return yield* Effect.fail(batonTurnPolicyInvalid(`node count exceeds ${exports_agent_schema.maxTurnPolicySnapshotNodes}`));
1095
+ }
1096
+ switch (node._tag) {
1097
+ case "Recurs":
1098
+ if (typeof node.count !== "number" || !Number.isInteger(node.count) || node.count < 0) {
1099
+ return yield* Effect.fail(batonTurnPolicyInvalid("recurs count must be a non-negative integer"));
1100
+ }
1101
+ return { kind: "recurs", count: node.count };
1102
+ case "UntilToolCall":
1103
+ if (typeof node.name !== "string" || node.name.trim().length === 0) {
1104
+ return yield* Effect.fail(batonTurnPolicyInvalid("until-tool-call name must not be blank"));
1105
+ }
1106
+ return { kind: "until-tool-call", name: node.name };
1107
+ case "Both":
1108
+ return {
1109
+ kind: "both",
1110
+ first: yield* visit(node.first, depth + 1),
1111
+ second: yield* visit(node.second, depth + 1)
1112
+ };
1113
+ default:
1114
+ return yield* Effect.fail(batonTurnPolicyInvalid("snapshot tag is not recognized"));
1115
+ }
1116
+ });
1117
+ return yield* visit(snapshot, 1);
1118
+ });
1119
+ var turnPolicyFieldsFromRegisterInput = Effect.fn("Client.turnPolicyFieldsFromRegisterInput")(function* (input) {
1120
+ if (input.max_tool_turns !== undefined)
1121
+ return { max_tool_turns: input.max_tool_turns };
1122
+ const snapshot = input.agent.policy.snapshot;
1123
+ if (snapshot === undefined) {
1124
+ return yield* Effect.fail(batonTurnPolicyInvalid("opaque policies require an explicit max_tool_turns replacement"));
1125
+ }
1126
+ const durable = yield* turnPolicySnapshotFromBaton(snapshot);
1127
+ if (durable.kind === "recurs" && durable.count === exports_agent_schema.defaultMaxToolTurns)
1128
+ return {};
1129
+ if (durable.kind === "recurs" && durable.count > 0)
1130
+ return { max_tool_turns: durable.count };
1131
+ return { turn_policy: durable };
1132
+ });
1133
+ var registerAgentPayload = Effect.fn("Client.registerAgentPayload")(function* (input) {
1134
+ if (!isRegisterBatonAgentInput(input))
1135
+ return exports_agent_schema.define(input);
1136
+ const name = yield* decodeBatonAgentName(input.agent.name);
1137
+ const model = yield* modelSelectionFromRegisterInput(input);
1138
+ const metadata = yield* metadataFromBatonAgent(input);
1139
+ const turnPolicy = yield* turnPolicyFieldsFromRegisterInput(input);
1140
+ return exports_agent_schema.define({
1141
+ id: input.id,
1142
+ name,
1143
+ ...input.agent.instructions === undefined ? {} : { instructions: input.agent.instructions },
1144
+ model,
1145
+ tools: toolRefsFromBatonAgent(input.agent),
1146
+ permissions: input.permissions ?? [],
1147
+ ...input.skill_definition_ids === undefined ? {} : { skill_definition_ids: input.skill_definition_ids },
1148
+ ...input.permission_rules === undefined ? {} : { permission_rules: input.permission_rules },
1149
+ ...turnPolicy,
1150
+ ...input.max_wait_turns === undefined ? {} : { max_wait_turns: input.max_wait_turns },
1151
+ ...input.token_budget === undefined ? {} : { token_budget: input.token_budget },
1152
+ ...input.child_run_presets === undefined ? {} : { child_run_presets: input.child_run_presets },
1153
+ ...input.handoff_targets === undefined ? {} : { handoff_targets: input.handoff_targets },
1154
+ ...input.output_schema_ref === undefined ? {} : { output_schema_ref: input.output_schema_ref },
1155
+ ...metadata === undefined ? {} : { metadata }
1156
+ });
1157
+ });
1158
+ var agentDefinitionNotFound = (id) => new ClientError({ message: `Agent not found: ${id}` });
1159
+ var wakeMetadata = (input) => ({
1160
+ ...input.metadata,
1161
+ ...input.from === undefined ? {} : { from: input.from },
1162
+ ...input.content === undefined ? {} : { content: input.content },
1163
+ ...input.correlation_key === undefined ? {} : { correlation_key: input.correlation_key }
1164
+ });
1165
+ var toPendingToolApproval = (record) => ({
1166
+ wait_id: record.id,
1167
+ execution_id: record.executionId,
1168
+ tool_call_id: exports_ids_schema.ToolCallId.make(String(record.metadata.tool_call_id ?? "")),
1169
+ tool_name: String(record.metadata.tool_name ?? ""),
1170
+ input: record.metadata.input ?? null,
1171
+ requested_at: record.createdAt
1172
+ });
1173
+ var isToolApprovalWait = (record) => record.metadata.kind === "tool-approval";
1174
+ var toToolAttempt = (record) => ({
1175
+ attempt_id: record.id,
1176
+ tool_call_id: record.callId,
1177
+ attempt_number: record.attemptNumber,
1178
+ state: record.state,
1179
+ ...record.workerId === undefined ? {} : { worker_id: record.workerId },
1180
+ ...record.claimExpiresAt === undefined ? {} : { claim_expires_at: record.claimExpiresAt },
1181
+ ...record.error === undefined ? {} : { error: record.error },
1182
+ created_at: record.createdAt,
1183
+ ...record.completedAt === undefined ? {} : { completed_at: record.completedAt }
1184
+ });
1185
+ var toPendingToolCall = (record) => record.definition === undefined || record.waitId === undefined ? undefined : {
1186
+ execution_id: record.executionId,
1187
+ call: record.call,
1188
+ definition: record.definition,
1189
+ placement: record.placement,
1190
+ state: record.state,
1191
+ wait_id: record.waitId,
1192
+ idempotency_key: record.idempotencyKey,
1193
+ requested_at: record.createdAt
1194
+ };
1195
+ var toToolOutcomeAccepted = (accepted) => ({
1196
+ tool_call_id: accepted.call.call.id,
1197
+ attempt: toToolAttempt(accepted.attempt),
1198
+ duplicate: accepted.duplicate
1199
+ });
1200
+ var toToolWorkLease = (lease) => ({
1201
+ execution_id: lease.call.executionId,
1202
+ call: lease.call.call,
1203
+ definition: lease.call.definition,
1204
+ placement: lease.call.placement,
1205
+ attempt: toToolAttempt(lease.attempt),
1206
+ queue: lease.queue,
1207
+ worker_id: lease.workerId,
1208
+ claim_expires_at: lease.claimExpiresAt,
1209
+ idempotency_key: lease.idempotencyKey
1210
+ });
1211
+ var toolWaitId = (callId) => exports_ids_schema.WaitId.make(`wait:tool:${callId}`);
1212
+ var acceptedWaitOutcome = (wait) => Schema3.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect.mapError(toClientError));
1213
+ var resolveToolOutcomeWait = Effect.fn("Client.resolveToolOutcomeWait")(function* (waits, eventLog, call, outcome, completedAt) {
1214
+ const waitId = call.waitId ?? toolWaitId(call.call.id);
1215
+ const wait = yield* waits.get(waitId).pipe(Effect.mapError(toClientError));
1216
+ if (wait === undefined)
1217
+ return yield* new ClientError({ message: `Tool wait not found: ${waitId}` });
1218
+ if (wait.executionId !== call.executionId) {
1219
+ return yield* new ClientError({ message: `Tool wait does not match call: ${call.call.id}` });
1220
+ }
1221
+ if (wait.state === "resolved") {
1222
+ const accepted = yield* acceptedWaitOutcome(wait);
1223
+ if (exports_shared_schema.canonicalString(accepted) !== exports_shared_schema.canonicalString(outcome)) {
1224
+ return yield* new ClientError({ message: `Tool outcome conflicts with accepted wait: ${call.call.id}` });
1225
+ }
1226
+ return wait;
1227
+ }
1228
+ if (wait.state !== "open") {
1229
+ return yield* new ClientError({ message: `Tool wait is ${wait.state}: ${call.call.id}` });
1230
+ }
1231
+ const eventSequence = yield* nextEventSequence(eventLog, call.executionId);
1232
+ const resolved = yield* waits.wake({
1233
+ waitId,
1234
+ resolvedAt: completedAt,
1235
+ eventSequence,
1236
+ metadata: { kind: "tool-placement", external_outcome: outcome }
1237
+ }).pipe(Effect.mapError(toClientError));
1238
+ if (!resolved.transitioned) {
1239
+ const accepted = yield* acceptedWaitOutcome(resolved.wait);
1240
+ if (exports_shared_schema.canonicalString(accepted) !== exports_shared_schema.canonicalString(outcome)) {
1241
+ return yield* new ClientError({ message: `Tool outcome conflicts with accepted wait: ${call.call.id}` });
1242
+ }
1243
+ }
1244
+ return resolved.wait;
1245
+ });
1246
+ var signalToolOutcome = Effect.fn("Client.signalToolOutcome")(function* (executionRepository, makeExecutionClient, wait, signaledAt) {
1247
+ yield* exports_wait_signal.signalWorkflowWait({
1248
+ makeExecutionClient,
1249
+ executionId: wait.executionId,
1250
+ waitId: wait.id,
1251
+ state: "resolved",
1252
+ signaledAt
1253
+ }).pipe(Effect.provideService(exports_execution_repository.Service, executionRepository), Effect.mapError(toClientError));
1254
+ });
1255
+ var toReady = (record) => ({
1256
+ id: record.id,
1257
+ envelope_id: record.envelopeId,
1258
+ route_key: record.routeKey,
1259
+ available_at: record.availableAt,
1260
+ attempt: record.attempt,
1261
+ metadata: record.metadata
1262
+ });
1263
+ var toLease = (record) => ({
1264
+ ready: toReady(record),
1265
+ worker_id: record.claimOwner ?? "unclaimed",
1266
+ claim_expires_at: record.claimExpiresAt ?? record.updatedAt
1267
+ });
1268
+ var nextEventSequence = Effect.fn("Client.nextEventSequence")(function* (eventLog, executionId) {
1269
+ const max = yield* eventLog.maxSequence(executionId).pipe(Effect.mapError(toClientError));
1270
+ return max === undefined ? 0 : max + 1;
1271
+ });
1272
+ var waitSemanticKind = (wait) => wait.mode === "child" ? "child" : typeof wait.metadata.kind === "string" && wait.metadata.kind.length > 0 ? wait.metadata.kind : "general";
1273
+ var terminalChildStatus = (metadata) => {
1274
+ const status = metadata?.child_status;
1275
+ return status === "completed" || status === "failed" || status === "cancelled";
1276
+ };
1277
+ var wakeRuntime = Effect.fn("Client.wakeRuntime")(function* (waits, eventLog, executionRepository, makeExecutionClient, input, accepts) {
1278
+ const wait = yield* waits.get(input.wait_id).pipe(Effect.mapError(toClientError));
1279
+ if (wait === undefined)
1280
+ return yield* new ClientError({ message: `Wait not found: ${input.wait_id}` });
1281
+ const kind = waitSemanticKind(wait);
1282
+ if (accepts !== undefined && kind !== accepts) {
1283
+ return yield* new WaitKindMismatch({
1284
+ wait_id: input.wait_id,
1285
+ expected: accepts,
1286
+ actual: kind,
1287
+ message: `Wait ${input.wait_id} is a ${kind} wait; this resolver mutates only ${accepts} waits`
1288
+ });
1289
+ }
1290
+ if (accepts === undefined && kind === "child" && !terminalChildStatus(input.metadata)) {
1291
+ return yield* new WaitKindMismatch({
1292
+ wait_id: input.wait_id,
1293
+ expected: 'child wake with terminal metadata.child_status ("completed" | "failed" | "cancelled")',
1294
+ actual: kind,
1295
+ message: `Wait ${input.wait_id} joins a child run; wake it with terminal metadata.child_status or let the child runtime complete it`
1296
+ });
1297
+ }
1298
+ if (input.state === "cancelled" && wait.metadata.kind === "tool-placement") {
1299
+ return yield* new ClientError({ message: "Tool placement waits must be cancelled through cancelExecution" });
1300
+ }
1301
+ const eventSequence = yield* nextEventSequence(eventLog, wait.executionId);
1302
+ const result = input.state === "resolved" ? yield* waits.wake({
1303
+ waitId: input.wait_id,
1304
+ resolvedAt: input.signaled_at,
1305
+ eventSequence,
1306
+ metadata: wakeMetadata(input)
1307
+ }).pipe(Effect.mapError(toClientError)) : input.state === "timed_out" ? yield* waits.timeout({
1308
+ waitId: input.wait_id,
1309
+ timedOutAt: input.signaled_at,
1310
+ eventSequence,
1311
+ metadata: wakeMetadata(input)
1312
+ }).pipe(Effect.mapError(toClientError)) : yield* waits.cancel({
1313
+ waitId: input.wait_id,
1314
+ cancelledAt: input.signaled_at,
1315
+ eventSequence,
1316
+ metadata: wakeMetadata(input)
1317
+ }).pipe(Effect.mapError(toClientError));
1318
+ if (result.transitioned) {
1319
+ yield* exports_wait_signal.signalWorkflowWait({
1320
+ makeExecutionClient,
1321
+ executionId: result.wait.executionId,
1322
+ waitId: result.wait.id,
1323
+ state: input.state,
1324
+ signaledAt: input.signaled_at
1325
+ }).pipe(Effect.provideService(exports_execution_repository.Service, executionRepository), Effect.mapError(toClientError));
1326
+ }
1327
+ return {
1328
+ wait_id: result.wait.id,
1329
+ state: input.state,
1330
+ signaled_at: input.signaled_at
1331
+ };
1332
+ });
1333
+ var childJoinWaitId = (childExecutionId) => exports_ids_schema.WaitId.make(`wait:child:${childExecutionId}`);
1334
+ var childSpawnFingerprintKey = "relay_child_spawn_fingerprint";
1335
+ var childExecutionIdForSpawn = (input) => input.child_execution_id ?? exports_ids_schema.ChildExecutionId.make(`${input.execution_id}:child:${input.address_id}`);
1336
+ var parentContextFromDefinition = (definition, fingerprint) => ({
1337
+ ...definition.instructions === undefined ? {} : { instructions: definition.instructions },
1338
+ model: definition.model,
1339
+ tool_names: definition.tool_names,
1340
+ permissions: definition.permissions.map((permission) => permission.name),
1341
+ ...definition.output_schema_ref === undefined ? {} : { output_schema_ref: definition.output_schema_ref },
1342
+ metadata: { ...definition.metadata, [childSpawnFingerprintKey]: fingerprint }
1343
+ });
1344
+ var internalSpawnChildRunInput = (input, pin, createdAt) => ({
1345
+ execution_id: input.execution_id,
1346
+ child_execution_id: childExecutionIdForSpawn(input),
1347
+ address_id: input.address_id,
1348
+ parent_context: parentContextFromDefinition(pin.agentSnapshot, exports_shared_schema.canonicalString(input)),
1349
+ ...pin.agentSnapshot.child_run_presets === undefined ? {} : { presets: pin.agentSnapshot.child_run_presets },
1350
+ ...input.preset_name === undefined ? {} : { preset_name: input.preset_name },
1351
+ ...input.instructions === undefined ? {} : { instructions: input.instructions },
1352
+ ...input.model === undefined ? {} : { model: input.model },
1353
+ ...input.tool_names === undefined ? {} : { tool_names: input.tool_names },
1354
+ ...input.permissions === undefined ? {} : { permissions: input.permissions },
1355
+ ...input.workspace_policy === undefined ? {} : { workspace_policy: input.workspace_policy },
1356
+ ...input.output_schema_ref === undefined ? {} : { output_schema_ref: input.output_schema_ref },
1357
+ ...input.metadata === undefined ? {} : { metadata: input.metadata },
1358
+ ...input.input === undefined ? {} : { input: input.input },
1359
+ ...input.wait === undefined ? {} : { wait: input.wait },
1360
+ created_at: createdAt
1361
+ });
1362
+ var childSpawnFingerprint = (record) => {
1363
+ const parentMetadata = record.metadata.parent_metadata;
1364
+ if (parentMetadata === null || typeof parentMetadata !== "object" || Array.isArray(parentMetadata))
1365
+ return;
1366
+ const fingerprint = parentMetadata[childSpawnFingerprintKey];
1367
+ return typeof fingerprint === "string" ? fingerprint : undefined;
1368
+ };
1369
+ var createChildJoinWait = Effect.fn("Client.createChildJoinWait")(function* (waits, eventLog, input, accepted, createdAt) {
1370
+ const waitId = childJoinWaitId(accepted.child_execution_id);
1371
+ const eventSequence = yield* nextEventSequence(eventLog, input.execution_id);
1372
+ yield* waits.createDetached({
1373
+ waitId,
1374
+ executionId: input.execution_id,
1375
+ mode: "child",
1376
+ correlationKey: accepted.child_execution_id,
1377
+ metadata: {
1378
+ parent_execution_id: input.execution_id,
1379
+ child_execution_id: accepted.child_execution_id
1380
+ },
1381
+ eventSequence,
1382
+ createdAt
1383
+ }).pipe(Effect.mapError(toClientError));
1384
+ return waitId;
1385
+ });
1386
+ var reconcileExistingChildSpawn = Effect.fn("Client.reconcileExistingChildSpawn")(function* (childExecutions, waits, eventLog, input) {
1387
+ const childExecutionId = childExecutionIdForSpawn(input);
1388
+ const existing = yield* childExecutions.get(childExecutionId).pipe(Effect.mapError(toClientError));
1389
+ if (existing === undefined)
1390
+ return;
1391
+ if (existing.executionId !== input.execution_id || existing.addressId !== input.address_id || childSpawnFingerprint(existing) !== exports_shared_schema.canonicalString(input)) {
1392
+ return yield* new ClientError({ message: `Child execution conflicts: ${childExecutionId}` });
1393
+ }
1394
+ const spawned = yield* eventLog.findByCursor({
1395
+ executionId: input.execution_id,
1396
+ cursor: `${input.execution_id}:child:${childExecutionId}:spawned`
1397
+ }).pipe(Effect.mapError(toClientError));
1398
+ if (Option.isNone(spawned)) {
1399
+ return yield* new ClientError({ message: `Child spawn event missing: ${childExecutionId}` });
1400
+ }
1401
+ const parentWaitId = input.wait === true ? childJoinWaitId(childExecutionId) : undefined;
1402
+ if (parentWaitId !== undefined) {
1403
+ const wait = yield* waits.get(parentWaitId).pipe(Effect.mapError(toClientError));
1404
+ if (wait === undefined) {
1405
+ return yield* new ClientError({ message: `Child join wait missing: ${childExecutionId}` });
1406
+ }
1407
+ }
1408
+ return {
1409
+ accepted: { child_execution_id: childExecutionId, execution_id: input.execution_id },
1410
+ createdAt: existing.createdAt,
1411
+ parentWaitId
1412
+ };
1413
+ });
1414
+ var parentDefinitionPin = Effect.fn("Client.parentDefinitionPin")(function* (executionRepository, executionId) {
1415
+ const record = yield* executionRepository.get(executionId).pipe(Effect.mapError(toClientError));
1416
+ if (record === undefined) {
1417
+ return yield* new ClientError({ message: `Execution not found: ${executionId}` });
1418
+ }
1419
+ if (record.agentId === undefined || record.agentRevision === undefined || record.agentSnapshot === undefined) {
1420
+ return yield* new ClientError({ message: `Parent execution is not pinned to an agent: ${executionId}` });
1421
+ }
1422
+ return {
1423
+ agentId: record.agentId,
1424
+ agentRevision: record.agentRevision,
1425
+ agentSnapshot: record.agentSnapshot,
1426
+ ...record.agentToolInputSchemaDigests === undefined ? {} : { agentToolInputSchemaDigests: record.agentToolInputSchemaDigests }
1427
+ };
1428
+ });
1429
+ var childStartInput = (input, accepted, pin, definition, createdAt, parentWaitId) => ({
1430
+ execution_id: exports_ids_schema.ExecutionId.make(accepted.child_execution_id),
1431
+ root_address_id: input.address_id,
1432
+ input: input.input === undefined ? [] : [...input.input],
1433
+ event_sequence: 0,
1434
+ started_at: createdAt,
1435
+ completed_at: createdAt,
1436
+ agent_id: pin.agentId,
1437
+ agent_revision: pin.agentRevision,
1438
+ agent_snapshot: definition,
1439
+ ...pin.agentToolInputSchemaDigests === undefined ? {} : { agent_tool_input_schema_digests: pin.agentToolInputSchemaDigests },
1440
+ metadata: {
1441
+ parent_execution_id: input.execution_id,
1442
+ child_execution_id: accepted.child_execution_id,
1443
+ ...parentWaitId === undefined ? {} : { parent_wait_id: parentWaitId }
1444
+ }
1445
+ });
1446
+ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1447
+ const makeExecutionClient = yield* exports_execution_entity.client;
1448
+ const executions = yield* exports_execution_service.Service;
1449
+ const envelopes = yield* exports_envelope_service.Service;
1450
+ const waits = yield* exports_wait_service.Service;
1451
+ const eventLog = yield* exports_event_log_service.Service;
1452
+ const sessionStream = yield* exports_session_stream_service.Service;
1453
+ const executionWatch = yield* exports_execution_watch_service.Service;
1454
+ const executionState = yield* exports_execution_state_service.Service;
1455
+ const presence = yield* exports_presence_service.Service;
1456
+ const envelopeReady = yield* exports_envelope_repository.Service;
1457
+ const executionRepository = yield* exports_execution_repository.Service;
1458
+ const inboxRepository = yield* exports_inbox_repository.Service;
1459
+ const topicService = yield* exports_topic_service.Service;
1460
+ const toolCalls = yield* exports_tool_call_repository.Service;
1461
+ const childExecutions = yield* exports_child_execution_repository.Service;
1462
+ const childFanOuts = yield* exports_child_fan_out_repository.Service;
1463
+ const sessionRepository = yield* exports_session_repository.Service;
1464
+ const steering = yield* exports_steering_repository.Service;
1465
+ const agentRegistry = yield* exports_agent_registry_service.Service;
1466
+ const entityRegistry = yield* exports_entity_registry_service.Service;
1467
+ const entities = yield* exports_entity_instance_service.Service;
1468
+ const addressBook = yield* exports_address_book_service.Service;
1469
+ const sharding = yield* Sharding.Sharding;
1470
+ const shardingConfig = yield* ShardingConfig.ShardingConfig;
1471
+ const clusterRegistry = yield* exports_cluster_registry_repository.Service;
1472
+ const schedules = yield* exports_schedule_repository.Service;
1473
+ const skillRegistry = yield* exports_skill_registry_service.Service;
1474
+ const toolTransitions = yield* exports_tool_transition_coordinator.Service;
1475
+ const workflows = yield* exports_workflow_definition_repository.Service;
1476
+ const workflowRuntime = yield* Effect.serviceOption(exports_definition_runtime.Service);
1477
+ const childFanOutRuntime = yield* Effect.serviceOption(exports_child_fan_out_runtime.Service);
1478
+ const schemaRegistry = yield* Effect.serviceOption(exports_schema_registry_service.Service);
1479
+ const coordinateToolTransition = (effect) => toolTransitions.coordinate(effect).pipe(Effect.mapError(toClientError));
1480
+ const coordinateChildSpawn = (effect) => toolTransitions.coordinate(effect).pipe(Effect.mapError(toClientError));
1481
+ const cancelFanOut = Effect.fn("Client.runtime.cancelFanOut")(function* (input) {
1482
+ if (Option.isSome(childFanOutRuntime)) {
1483
+ const fanOut = yield* childFanOutRuntime.value.cancel(input.fan_out_id, input.cancelled_at, input.reason ?? "child fan-out cancelled").pipe(Effect.mapError(toClientError));
1484
+ if (fanOut === undefined)
1485
+ return yield* new ClientError({ message: `Child fan-out not found: ${input.fan_out_id}` });
1486
+ return { fan_out: fanOut };
1487
+ }
1488
+ const result = yield* childFanOuts.cancel(input.fan_out_id, input.cancelled_at).pipe(Effect.mapError(toClientError));
1489
+ if (result === undefined)
1490
+ return yield* new ClientError({ message: `Child fan-out not found: ${input.fan_out_id}` });
1491
+ yield* Effect.forEach(result.activeChildExecutionIds, (childId) => makeExecutionClient(exports_ids_schema.ExecutionId.make(childId)).cancel({
1492
+ execution_id: exports_ids_schema.ExecutionId.make(childId),
1493
+ cancelled_at: input.cancelled_at,
1494
+ reason: input.reason ?? "child fan-out cancelled"
1495
+ }).pipe(Effect.mapError(toClientError)), { discard: true });
1496
+ if (result.transitioned) {
1497
+ const max = yield* eventLog.maxSequence(result.fanOut.parent_execution_id).pipe(Effect.mapError(toClientError));
1498
+ yield* exports_event_log_service.appendIdempotentTo(eventLog, {
1499
+ id: exports_ids_schema.EventId.make(`event:${result.fanOut.parent_execution_id}:fan-out:${input.fan_out_id}:terminal`),
1500
+ execution_id: result.fanOut.parent_execution_id,
1501
+ type: "child_fan_out.terminal",
1502
+ sequence: exports_execution_schema.ExecutionEventSequence.make(max === undefined ? 0 : max + 1),
1503
+ cursor: `${result.fanOut.parent_execution_id}:fan-out:${input.fan_out_id}:terminal`,
1504
+ data: { fan_out_id: input.fan_out_id, state: "cancelled" },
1505
+ created_at: input.cancelled_at
1506
+ }).pipe(Effect.mapError(toClientError));
1507
+ }
1508
+ return { fan_out: result.fanOut };
1509
+ });
1510
+ const sendEnvelope = Effect.fn("Client.runtime.send")(function* (input) {
1511
+ const identity = input.idempotency_key ?? input.correlation_key ?? `${input.from}:${input.to}`;
1512
+ const executionId = exports_ids_schema.ExecutionId.make(input.correlation_key ?? `execution:send:${identity}`);
1513
+ const envelopeId = exports_ids_schema.EnvelopeId.make(`${executionId}:envelope:${identity}`);
1514
+ const createdAt = yield* Clock.currentTimeMillis;
1515
+ const maxSequence = yield* eventLog.maxSequence(executionId).pipe(Effect.mapError(toClientError));
1516
+ return yield* envelopes.send({
1517
+ envelopeId,
1518
+ executionId,
1519
+ input,
1520
+ eventSequence: maxSequence === undefined ? 0 : maxSequence + 1,
1521
+ createdAt
1522
+ }).pipe(Effect.mapError(toClientError));
1523
+ });
1524
+ const waitOutcomeFrom = Effect.fn("Client.runtime.waitOutcome")(function* (wait) {
1525
+ const reply = wait.state === "resolved" ? yield* envelopeReady.getEnvelope(exports_ids_schema.EnvelopeId.make(`envelope:reply:${wait.id}`)).pipe(Effect.mapError(toClientError)) : undefined;
1526
+ return {
1527
+ wait_id: wait.id,
1528
+ state: wait.state,
1529
+ ...reply === undefined ? {} : { content: reply.content },
1530
+ ...Object.keys(wait.metadata).length === 0 ? {} : { metadata: wait.metadata }
1531
+ };
1532
+ });
1533
+ const awaitWaitOperation = Effect.fn("Client.runtime.awaitWait")(function* (input) {
1534
+ const current = yield* envelopeReady.getWait(input.wait_id).pipe(Effect.mapError(toClientError));
1535
+ if (current === undefined) {
1536
+ return yield* new ClientError({ message: `wait ${input.wait_id} not found` });
1537
+ }
1538
+ if (current.state !== "open")
1539
+ return yield* waitOutcomeFrom(current);
1540
+ yield* eventLog.stream({ executionId: input.execution_id }).pipe(Stream.filter((event) => (event.type === "wait.woken" || event.type === "wait.timed_out" || event.type === "wait.cancelled") && event.data?.wait_id === input.wait_id), Stream.take(1), Stream.runDrain, Effect.mapError(toClientError));
1541
+ const terminal = yield* envelopeReady.getWait(input.wait_id).pipe(Effect.mapError(toClientError));
1542
+ if (terminal === undefined || terminal.state === "open") {
1543
+ return yield* new ClientError({ message: `wait ${input.wait_id} did not reach a terminal state` });
1544
+ }
1545
+ return yield* waitOutcomeFrom(terminal);
1546
+ });
1547
+ const getExecutionOperation = Effect.fn("Client.runtime.getExecution")(function* (id) {
1548
+ const record = yield* executionRepository.get(id).pipe(Effect.mapError(toClientError));
1549
+ return record === undefined ? undefined : toExecutionView(record);
1550
+ });
1551
+ const streamExecutionOperation = (input) => executions.stream({
1552
+ executionId: input.execution_id,
1553
+ ...input.after_cursor === undefined ? {} : { afterCursor: input.after_cursor },
1554
+ ...input.limit === undefined ? {} : { limit: input.limit }
1555
+ }).pipe(Stream.mapError(toStreamError));
1556
+ const inspectExecutionOperation = Effect.fn("Client.runtime.inspectExecution")(function* (executionId) {
1557
+ const execution = yield* executionRepository.get(executionId).pipe(Effect.mapError(toClientError));
1558
+ if (execution === undefined)
1559
+ return yield* new ExecutionNotFound({ execution_id: executionId });
1560
+ const openWaits = yield* envelopeReady.listAllWaits({ executionId, state: "open" }).pipe(Effect.mapError(toClientError));
1561
+ const calls = yield* toolCalls.listCalls(executionId).pipe(Effect.mapError(toClientError));
1562
+ const pendingChunks = yield* Effect.forEach(calls, (call) => toolCalls.getResult(call.call.id).pipe(Effect.mapError(toClientError), Effect.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
1563
+ const children = yield* childExecutions.listByExecution(executionId).pipe(Effect.mapError(toClientError));
1564
+ const maxSequence = yield* eventLog.maxSequence(executionId).pipe(Effect.mapError(toClientError));
1565
+ const lastEvent = maxSequence === undefined ? undefined : yield* eventLog.findBySequence({ executionId, sequence: maxSequence }).pipe(Effect.mapError(toClientError), Effect.map(Option.getOrUndefined));
1566
+ return {
1567
+ execution_id: execution.id,
1568
+ status: execution.status,
1569
+ waiting_on: openWaits.map(toWaitView),
1570
+ pending_tool_calls: pendingChunks.flat(),
1571
+ child_runs: children.map(toChildRunSummary),
1572
+ ...lastEvent === undefined ? {} : { last_event_cursor: lastEvent.cursor }
1573
+ };
1574
+ });
1575
+ return Service.of({
1576
+ registerEntityKind: (input) => entityRegistry.registerKind(input).pipe(Effect.mapError(toClientError)),
1577
+ getOrCreateEntity: (input) => entities.getOrCreate({
1578
+ kind: input.kind,
1579
+ key: input.key,
1580
+ createdAt: input.created_at,
1581
+ ...input.input === undefined ? {} : { input: input.input },
1582
+ ...input.metadata === undefined ? {} : { metadata: input.metadata }
1583
+ }).pipe(Effect.mapError(toClientError)),
1584
+ getEntity: (input) => entities.get(input).pipe(Effect.mapError(toClientError)),
1585
+ destroyEntity: (input) => entities.destroy({
1586
+ kind: input.kind,
1587
+ key: input.key,
1588
+ destroyedAt: input.destroyed_at,
1589
+ ...input.reason === undefined ? {} : { reason: input.reason }
1590
+ }).pipe(Effect.mapError(toClientError)),
1591
+ listEntities: (input) => entities.list({
1592
+ ...input.kind === undefined ? {} : { kind: input.kind },
1593
+ ...input.after_kind === undefined ? {} : { afterKind: input.after_kind },
1594
+ ...input.after_key === undefined ? {} : { afterKey: input.after_key },
1595
+ ...input.limit === undefined ? {} : { limit: input.limit }
1596
+ }).pipe(Effect.mapError(toClientError)),
1597
+ registerWorkflowDefinition: Effect.fn("Client.runtime.registerWorkflowDefinition")(function* (input) {
1598
+ return { record: yield* workflows.register(input).pipe(Effect.mapError(toClientError)) };
1599
+ }),
1600
+ getWorkflowDefinitionRevision: Effect.fn("Client.runtime.getWorkflowDefinitionRevision")(function* (id, revision) {
1601
+ return yield* workflows.get(id, revision).pipe(Effect.mapError(toClientError));
1602
+ }),
1603
+ listWorkflowDefinitionRevisions: Effect.fn("Client.runtime.listWorkflowDefinitionRevisions")(function* (id) {
1604
+ return { records: yield* workflows.list(id).pipe(Effect.mapError(toClientError)) };
1605
+ }),
1606
+ startWorkflowRun: Effect.fn("Client.runtime.startWorkflowRun")(function* (input) {
1607
+ return yield* Option.match(workflowRuntime, {
1608
+ onNone: () => workflows.start(input),
1609
+ onSome: (runtime) => runtime.start(input)
1610
+ }).pipe(Effect.mapError(toClientError));
1611
+ }),
1612
+ inspectWorkflowRun: Effect.fn("Client.runtime.inspectWorkflowRun")(function* (id) {
1613
+ return yield* Option.match(workflowRuntime, {
1614
+ onNone: () => workflows.inspect(id),
1615
+ onSome: (runtime) => runtime.inspect(id)
1616
+ }).pipe(Effect.mapError(toClientError));
1617
+ }),
1618
+ replayWorkflowRun: Effect.fn("Client.runtime.replayWorkflowRun")(function* (id) {
1619
+ return yield* Option.match(workflowRuntime, {
1620
+ onNone: () => workflows.listLifecycle(id),
1621
+ onSome: (runtime) => runtime.replay(id)
1622
+ }).pipe(Effect.mapError(toClientError));
1623
+ }),
1624
+ cancelWorkflowRun: Effect.fn("Client.runtime.cancelWorkflowRun")(function* (id) {
1625
+ return yield* Option.match(workflowRuntime, {
1626
+ onNone: () => workflows.cancel(id),
1627
+ onSome: (runtime) => runtime.cancel(id)
1628
+ }).pipe(Effect.mapError(toClientError));
1629
+ }),
1630
+ registerAgent: Effect.fn("Client.runtime.registerAgent")(function* (input) {
1631
+ const payload = yield* registerAgentPayload(input);
1632
+ const registered = yield* agentRegistry.register(payload).pipe(Effect.mapError(toClientError));
1633
+ if (input.address !== undefined) {
1634
+ yield* addressBook.register(input.address, { kind: "local-agent", route_key: payload.id }).pipe(Effect.mapError(toClientError));
1635
+ }
1636
+ return registered;
1637
+ }),
1638
+ registerAgentDefinition: Effect.fn("Client.runtime.registerAgentDefinition")(function* (input) {
1639
+ return yield* agentRegistry.register(input).pipe(Effect.mapError(toClientError));
1640
+ }),
1641
+ getAgentDefinition: Effect.fn("Client.runtime.getAgentDefinition")(function* (id) {
1642
+ return yield* agentRegistry.get(id).pipe(Effect.mapError(toClientError));
1643
+ }),
1644
+ listAgentDefinitions: Effect.fn("Client.runtime.listAgentDefinitions")(function* () {
1645
+ return yield* agentRegistry.list().pipe(Effect.mapError(toClientError));
1646
+ }),
1647
+ listAgentDefinitionRevisions: Effect.fn("Client.runtime.listAgentDefinitionRevisions")(function* (id) {
1648
+ return yield* agentRegistry.listRevisions(id).pipe(Effect.mapError(toClientError));
1649
+ }),
1650
+ getSkillDefinition: Effect.fn("Client.runtime.getSkillDefinition")(function* (id) {
1651
+ return yield* skillRegistry.get(id).pipe(Effect.mapError(toClientError));
1652
+ }),
1653
+ listSkillDefinitions: Effect.fn("Client.runtime.listSkillDefinitions")(function* () {
1654
+ return yield* skillRegistry.list().pipe(Effect.mapError(toClientError));
1655
+ }),
1656
+ listSkillDefinitionRevisions: Effect.fn("Client.runtime.listSkillDefinitionRevisions")(function* (id) {
1657
+ return yield* skillRegistry.listRevisions(id).pipe(Effect.mapError(toClientError));
1658
+ }),
1659
+ registerAddressBookRoute: Effect.fn("Client.runtime.registerAddressBookRoute")(function* (input) {
1660
+ yield* rejectReserved(input.address_id, "address:entity:");
1661
+ return yield* addressBook.register(input.address_id, input.route).pipe(Effect.mapError(toClientError));
1662
+ }),
1663
+ getAddressBookRoute: Effect.fn("Client.runtime.getAddressBookRoute")(function* (id) {
1664
+ return yield* addressBook.get(id).pipe(Effect.mapError(toClientError));
1665
+ }),
1666
+ listAddressBookRoutes: Effect.fn("Client.runtime.listAddressBookRoutes")(function* () {
1667
+ return yield* addressBook.list().pipe(Effect.mapError(toClientError));
1668
+ }),
1669
+ startExecution: Effect.fn("Client.runtime.startExecution")(function* (input) {
1670
+ yield* rejectReserved(input.execution_id, "execution:entity:");
1671
+ if (input.session_id !== undefined)
1672
+ yield* rejectReserved(input.session_id, "session:entity:");
1673
+ const client = makeExecutionClient(input.execution_id);
1674
+ return yield* client.start(input).pipe(Effect.mapError(toClientError));
1675
+ }),
1676
+ startExecutionByAddress: Effect.fn("Client.runtime.startExecutionByAddress")(function* (input) {
1677
+ yield* rejectReserved(input.idempotency_key, "entity:");
1678
+ if (input.execution_id !== undefined)
1679
+ yield* rejectReserved(input.execution_id, "execution:entity:");
1680
+ if (input.session_id !== undefined)
1681
+ yield* rejectReserved(input.session_id, "session:entity:");
1682
+ const payload = startExecutionByAddressPayload(input);
1683
+ const client = makeExecutionClient(payload.execution_id);
1684
+ return yield* client.start(payload).pipe(Effect.mapError(toClientError));
1685
+ }),
1686
+ startExecutionByAgentDefinition: Effect.fn("Client.runtime.startExecutionByAgentDefinition")(function* (input) {
1687
+ yield* rejectReserved(input.idempotency_key, "entity:");
1688
+ if (input.execution_id !== undefined)
1689
+ yield* rejectReserved(input.execution_id, "execution:entity:");
1690
+ if (input.session_id !== undefined)
1691
+ yield* rejectReserved(input.session_id, "session:entity:");
1692
+ const definition = yield* agentRegistry.get(input.agent_id).pipe(Effect.mapError(toClientError));
1693
+ if (definition === undefined)
1694
+ return yield* Effect.fail(agentDefinitionNotFound(input.agent_id));
1695
+ const payload = startExecutionByAgentDefinitionPayload(input, definition);
1696
+ const client = makeExecutionClient(payload.execution_id);
1697
+ return yield* client.start(payload).pipe(Effect.mapError(toClientError));
1698
+ }),
1699
+ cancelExecution: Effect.fn("Client.runtime.cancelExecution")(function* (input) {
1700
+ const fanOuts = yield* childFanOuts.listNonTerminal(input.execution_id).pipe(Effect.mapError(toClientError));
1701
+ yield* Effect.forEach(fanOuts, (fanOut) => cancelFanOut({
1702
+ fan_out_id: fanOut.fan_out_id,
1703
+ cancelled_at: input.cancelled_at,
1704
+ ...input.reason === undefined ? {} : { reason: input.reason }
1705
+ }), { discard: true });
1706
+ const client = makeExecutionClient(input.execution_id);
1707
+ return yield* client.cancel({
1708
+ execution_id: input.execution_id,
1709
+ cancelled_at: input.cancelled_at,
1710
+ ...input.reason === undefined ? {} : { reason: input.reason }
1711
+ }).pipe(Effect.mapError(toClientError));
1712
+ }),
1713
+ steer: Effect.fn("Client.runtime.steer")(function* (input) {
1714
+ const execution = yield* executionRepository.get(input.execution_id).pipe(Effect.mapError(toClientError));
1715
+ if (execution === undefined) {
1716
+ return yield* new ClientError({ message: `Execution not found: ${input.execution_id}` });
1717
+ }
1718
+ if (execution.status !== "running") {
1719
+ return yield* new ClientError({ message: `Execution is not running: ${input.execution_id}` });
1720
+ }
1721
+ const record = yield* steering.appendForRunning({
1722
+ executionId: input.execution_id,
1723
+ kind: input.kind,
1724
+ content: input.content,
1725
+ createdAt: input.created_at
1726
+ }).pipe(Effect.mapError(toClientError));
1727
+ return { execution_id: record.executionId, kind: record.kind, sequence: record.sequence };
1728
+ }),
1729
+ getExecution: getExecutionOperation,
1730
+ inspectExecution: inspectExecutionOperation,
1731
+ followExecution: followExecutionFrom({
1732
+ getExecution: getExecutionOperation,
1733
+ inspectExecution: inspectExecutionOperation,
1734
+ streamExecution: streamExecutionOperation
1735
+ }),
1736
+ listWaits: Effect.fn("Client.runtime.listWaits")(function* (input) {
1737
+ const records = yield* envelopeReady.listWaits({
1738
+ ...input.state === undefined ? {} : { state: input.state },
1739
+ ...input.execution_id === undefined ? {} : { executionId: input.execution_id },
1740
+ ...input.limit === undefined ? {} : { limit: input.limit }
1741
+ }).pipe(Effect.mapError(toClientError));
1742
+ return records.map(toWaitView);
1743
+ }),
1744
+ listExecutions: Effect.fn("Client.runtime.listExecutions")(function* (input) {
1745
+ const cursor = input.cursor === undefined ? undefined : yield* Schema3.decodeEffect(ExecutionCursorFromString)(input.cursor).pipe(Effect.mapError(toClientError));
1746
+ const result = yield* executionRepository.list({
1747
+ ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
1748
+ ...input.status === undefined ? {} : { status: input.status },
1749
+ ...input.limit === undefined ? {} : { limit: input.limit },
1750
+ ...cursor === undefined ? {} : { cursor }
1751
+ }).pipe(Effect.mapError(toClientError));
1752
+ const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema3.encodeEffect(ExecutionCursorFromString)(result.nextCursor).pipe(Effect.mapError(toClientError));
1753
+ return {
1754
+ records: result.records.map(toConversationSummary),
1755
+ ...nextCursor === undefined ? {} : { next_cursor: nextCursor }
1756
+ };
1757
+ }),
1758
+ subscribeTopic: Effect.fn("Client.runtime.subscribeTopic")(function* (input) {
1759
+ return yield* topicService.subscribe({
1760
+ topicAddressId: input.topic_address_id,
1761
+ subscriberExecutionId: input.subscriber_execution_id,
1762
+ ...input.metadata === undefined ? {} : { metadata: input.metadata }
1763
+ }).pipe(Effect.mapError(toClientError));
1764
+ }),
1765
+ unsubscribeTopic: Effect.fn("Client.runtime.unsubscribeTopic")(function* (input) {
1766
+ return yield* topicService.unsubscribe({
1767
+ topicAddressId: input.topic_address_id,
1768
+ subscriberExecutionId: input.subscriber_execution_id
1769
+ }).pipe(Effect.mapError(toClientError));
1770
+ }),
1771
+ publishTopic: Effect.fn("Client.runtime.publishTopic")(function* (input) {
1772
+ return yield* topicService.publish({
1773
+ topicAddressId: input.topic_address_id,
1774
+ from: input.from,
1775
+ content: input.content,
1776
+ ...input.metadata === undefined ? {} : { metadata: input.metadata },
1777
+ ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key }
1778
+ }).pipe(Effect.mapError(toClientError));
1779
+ }),
1780
+ listTopicSubscriptions: Effect.fn("Client.runtime.listTopicSubscriptions")(function* (input) {
1781
+ return yield* topicService.list({
1782
+ ...input.topic_address_id === undefined ? {} : { topicAddressId: input.topic_address_id },
1783
+ ...input.subscriber_execution_id === undefined ? {} : { subscriberExecutionId: input.subscriber_execution_id }
1784
+ }).pipe(Effect.mapError(toClientError));
1785
+ }),
1786
+ listInboxMessages: Effect.fn("Client.runtime.listInboxMessages")(function* (input) {
1787
+ return yield* inboxRepository.list({
1788
+ executionId: input.execution_id,
1789
+ ...input.include_consumed === undefined ? {} : { includeConsumed: input.include_consumed },
1790
+ ...input.after_sequence === undefined ? {} : { afterSequence: input.after_sequence },
1791
+ ...input.limit === undefined ? {} : { limit: input.limit }
1792
+ }).pipe(Effect.mapError(toClientError));
1793
+ }),
1794
+ listSessions: Effect.fn("Client.runtime.listSessions")(function* (input) {
1795
+ const cursor = input.cursor === undefined ? undefined : yield* Schema3.decodeEffect(SessionCursorFromString)(input.cursor).pipe(Effect.mapError(toClientError));
1796
+ const result = yield* sessionRepository.list({
1797
+ ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
1798
+ ...input.limit === undefined ? {} : { limit: input.limit },
1799
+ ...cursor === undefined ? {} : { cursor }
1800
+ }).pipe(Effect.mapError(toClientError));
1801
+ const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema3.encodeEffect(SessionCursorFromString)(result.nextCursor).pipe(Effect.mapError(toClientError));
1802
+ return {
1803
+ records: result.records.map(toSessionSummary),
1804
+ ...nextCursor === undefined ? {} : { next_cursor: nextCursor }
1805
+ };
1806
+ }),
1807
+ getSession: Effect.fn("Client.runtime.getSession")(function* (input) {
1808
+ const session = yield* sessionRepository.get(input.session_id).pipe(Effect.mapError(toClientError));
1809
+ if (session === undefined)
1810
+ return yield* new ClientError({ message: `Session not found: ${input.session_id}` });
1811
+ const cursor = input.cursor === undefined ? undefined : yield* Schema3.decodeEffect(ExecutionCursorFromString)(input.cursor).pipe(Effect.mapError(toClientError));
1812
+ const result = yield* executionRepository.list({
1813
+ sessionId: input.session_id,
1814
+ ...input.limit === undefined ? {} : { limit: input.limit },
1815
+ ...cursor === undefined ? {} : { cursor }
1816
+ }).pipe(Effect.mapError(toClientError));
1817
+ const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema3.encodeEffect(ExecutionCursorFromString)(result.nextCursor).pipe(Effect.mapError(toClientError));
1818
+ return {
1819
+ session: toSessionSummary(session),
1820
+ executions: result.records.map(toConversationSummary),
1821
+ ...nextCursor === undefined ? {} : { next_cursor: nextCursor }
1822
+ };
1823
+ }),
1824
+ replayExecution: Effect.fn("Client.runtime.replayExecution")(function* (input) {
1825
+ const events = yield* eventLog.replay({
1826
+ executionId: input.execution_id,
1827
+ ...input.after_cursor === undefined ? {} : { afterCursor: input.after_cursor },
1828
+ ...input.limit === undefined ? {} : { limit: input.limit }
1829
+ }).pipe(Effect.mapError(toClientError));
1830
+ return { events };
1831
+ }),
1832
+ listRunners: Effect.fn("Client.runtime.listRunners")(function* () {
1833
+ const runners = yield* clusterRegistry.listRunners().pipe(Effect.mapError(toClientError));
1834
+ return {
1835
+ runners: runners.map((runner) => ({
1836
+ address: runner.address,
1837
+ healthy: runner.healthy,
1838
+ last_heartbeat: runner.lastHeartbeat,
1839
+ owned_shards: runner.ownedShards
1840
+ })),
1841
+ total_shards: shardingConfig.shardsPerGroup * shardingConfig.availableShardGroups.length
1842
+ };
1843
+ }),
1844
+ routeExecution: Effect.fn("Client.runtime.routeExecution")(function* (executionId) {
1845
+ const shard = ShardId.toString(sharding.getShardId(EntityId.make(executionId), "execution"));
1846
+ const owner = yield* clusterRegistry.lockOwner(shard).pipe(Effect.mapError(toClientError));
1847
+ const runnerAddress = owner ?? null;
1848
+ const self = Option.map(shardingConfig.runnerAddress, (address) => `${address.host}:${address.port}`);
1849
+ return {
1850
+ execution_id: executionId,
1851
+ shard,
1852
+ runner_address: runnerAddress,
1853
+ owned: runnerAddress !== null && Option.getOrNull(self) === runnerAddress
1854
+ };
1855
+ }),
1856
+ send: sendEnvelope,
1857
+ askEntity: Effect.fn("Client.runtime.askEntity")(function* (input) {
1858
+ const instance = yield* entities.get({ kind: input.kind, key: input.key }).pipe(Effect.mapError(toClientError));
1859
+ if (instance === undefined || instance.status === "destroyed") {
1860
+ return yield* new EntityNotFound({ kind: input.kind, key: input.key });
1861
+ }
1862
+ const encoded = yield* Schema3.encodeUnknownEffect(input.command.input)(input.input).pipe(Effect.mapError(toClientError));
1863
+ const inputRef = inputSchemaRef(input.command.name);
1864
+ const outputRef = outputSchemaRef(input.command.name);
1865
+ if (Option.isSome(schemaRegistry)) {
1866
+ yield* schemaRegistry.value.register({ ref: inputRef, schema: input.command.input });
1867
+ yield* schemaRegistry.value.register({ ref: outputRef, schema: input.command.output });
1868
+ }
1869
+ const correlation = `command:${input.command.name}:${globalThis.crypto.randomUUID()}`;
1870
+ const accepted = yield* sendEnvelope({
1871
+ from: input.from,
1872
+ to: instance.address_id,
1873
+ content: [{ type: "structured", value: encoded, schema_ref: inputRef }],
1874
+ idempotency_key: correlation,
1875
+ wait: {
1876
+ mode: "reply",
1877
+ correlation_key: correlation,
1878
+ ...input.timeout === undefined ? {} : { timeout: input.timeout }
1879
+ },
1880
+ metadata: {
1881
+ ...input.metadata,
1882
+ command: input.command.name,
1883
+ command_input_schema_ref: inputRef,
1884
+ command_output_schema_ref: outputRef
1885
+ }
1886
+ });
1887
+ if (accepted.wait_id === undefined) {
1888
+ return yield* new ClientError({ message: "askEntity send did not create a reply wait" });
1889
+ }
1890
+ const outcome = yield* awaitWaitOperation({ wait_id: accepted.wait_id, execution_id: accepted.execution_id });
1891
+ if (outcome.state === "timed_out") {
1892
+ return yield* new CommandTimedOut({
1893
+ command: input.command.name,
1894
+ wait_id: outcome.wait_id,
1895
+ timeout: input.timeout ?? "unspecified"
1896
+ });
1897
+ }
1898
+ if (outcome.state === "cancelled") {
1899
+ return yield* new ClientError({ message: `reply wait ${outcome.wait_id} was cancelled` });
1900
+ }
1901
+ const replyValue = replyValueFrom(outcome.content);
1902
+ if (replyValue._tag === "None") {
1903
+ return yield* new CommandReplyInvalid({
1904
+ command: input.command.name,
1905
+ wait_id: outcome.wait_id,
1906
+ message: "reply carried no decodable content"
1907
+ });
1908
+ }
1909
+ return yield* Schema3.decodeUnknownEffect(input.command.output)(replyValue.value).pipe(Effect.mapError((issue) => new CommandReplyInvalid({
1910
+ command: input.command.name,
1911
+ wait_id: outcome.wait_id,
1912
+ message: errorMessage(issue)
1913
+ })));
1914
+ }),
1915
+ awaitWait: awaitWaitOperation,
1916
+ streamExecution: streamExecutionOperation,
1917
+ streamSession: (input) => sessionStream.stream({
1918
+ sessionId: input.session_id,
1919
+ ...input.resume === undefined ? {} : {
1920
+ resume: input.resume.map((item) => ({
1921
+ executionId: item.execution_id,
1922
+ ...item.after_cursor === undefined ? {} : { afterCursor: item.after_cursor }
1923
+ }))
1924
+ }
1925
+ }).pipe(Stream.map((item) => item._tag === "execution_joined" ? { _tag: "execution_joined", execution: toConversationSummary(item.record) } : item), Stream.mapError(toStreamError)),
1926
+ watchExecutions: (input) => executionWatch.watch({
1927
+ ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
1928
+ ...input.session_id === undefined ? {} : { sessionId: input.session_id },
1929
+ ...input.status === undefined ? {} : { status: input.status },
1930
+ ...input.limit === undefined ? {} : { limit: input.limit }
1931
+ }).pipe(Stream.mapEffect((change) => change._tag === "snapshot" ? change.nextCursor === undefined ? Effect.succeed({
1932
+ _tag: "snapshot",
1933
+ records: change.records.map(toConversationSummary)
1934
+ }) : encodeExecutionCursor(change.nextCursor).pipe(Effect.map((next_cursor) => ({
1935
+ _tag: "snapshot",
1936
+ records: change.records.map(toConversationSummary),
1937
+ next_cursor
1938
+ }))) : Effect.succeed({
1939
+ _tag: "upsert",
1940
+ record: toConversationSummary(change.record)
1941
+ })), Stream.mapError(toClientError)),
1942
+ getEntityState: Effect.fn("Client.runtime.getEntityState")((input) => executionState.getRecord(input.execution_id, input.key).pipe(Effect.mapError(toClientError))),
1943
+ putEntityState: Effect.fn("Client.runtime.putEntityState")((input) => executionState.put({
1944
+ executionId: input.execution_id,
1945
+ key: exports_execution_state_service.key(input.key, exports_shared_schema.JsonValue),
1946
+ value: input.value,
1947
+ ...input.expected_version === undefined ? {} : { expectedVersion: input.expected_version },
1948
+ ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
1949
+ updatedAt: input.updated_at
1950
+ }).pipe(Effect.mapError((error) => error instanceof exports_execution_state_service.StateVersionConflict ? error : toClientError(error)))),
1951
+ deleteEntityState: Effect.fn("Client.runtime.deleteEntityState")((input) => executionState.remove({
1952
+ executionId: input.execution_id,
1953
+ key: input.key,
1954
+ ...input.expected_version === undefined ? {} : { expectedVersion: input.expected_version },
1955
+ ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
1956
+ removedAt: input.removed_at
1957
+ }).pipe(Effect.mapError((error) => error instanceof exports_execution_state_service.StateVersionConflict ? error : toClientError(error)))),
1958
+ listEntityState: Effect.fn("Client.runtime.listEntityState")((input) => executionState.list({
1959
+ executionId: input.execution_id,
1960
+ ...input.prefix === undefined ? {} : { prefix: input.prefix },
1961
+ ...input.after_key === undefined ? {} : { afterKey: input.after_key },
1962
+ ...input.limit === undefined ? {} : { limit: input.limit }
1963
+ }).pipe(Effect.mapError(toClientError))),
1964
+ getPresence: (scope) => presence.list(scope).pipe(Effect.mapError(toClientError)),
1965
+ watchPresence: (scope) => presence.watch(scope).pipe(Stream.mapError(toClientError)),
1966
+ wake: Effect.fn("Client.runtime.wake")(function* (input) {
1967
+ return yield* wakeRuntime(waits, eventLog, executionRepository, makeExecutionClient, input);
1968
+ }),
1969
+ listPendingApprovals: Effect.fn("Client.runtime.listPendingApprovals")(function* (input) {
1970
+ const records = yield* envelopeReady.listWaits({ executionId: input.execution_id, state: "open" }).pipe(Effect.mapError(toClientError));
1971
+ return { approvals: records.filter(isToolApprovalWait).map(toPendingToolApproval) };
1972
+ }),
1973
+ resolveToolApproval: Effect.fn("Client.runtime.resolveToolApproval")(function* (input) {
1974
+ return yield* wakeRuntime(waits, eventLog, executionRepository, makeExecutionClient, {
1975
+ wait_id: input.wait_id,
1976
+ state: "resolved",
1977
+ signaled_at: input.resolved_at,
1978
+ metadata: {
1979
+ approved: input.approved,
1980
+ ...input.comment === undefined ? {} : { comment: input.comment }
1981
+ }
1982
+ }, "tool-approval");
1983
+ }),
1984
+ resolvePermission: Effect.fn("Client.runtime.resolvePermission")(function* (input) {
1985
+ return yield* wakeRuntime(waits, eventLog, executionRepository, makeExecutionClient, {
1986
+ wait_id: input.wait_id,
1987
+ state: "resolved",
1988
+ signaled_at: input.resolved_at,
1989
+ metadata: {
1990
+ answer: input.answer,
1991
+ ...input.reason === undefined ? {} : { reason: input.reason }
1992
+ }
1993
+ }, "tool-permission");
1994
+ }),
1995
+ listPendingToolCalls: Effect.fn("Client.runtime.listPendingToolCalls")(function* (input) {
1996
+ const openWaits = yield* envelopeReady.listAllWaits({
1997
+ state: "open",
1998
+ ...input.execution_id === undefined ? {} : { executionId: input.execution_id }
1999
+ }).pipe(Effect.mapError(toClientError));
2000
+ const records = yield* Effect.forEach(openWaits.filter((wait) => wait.metadata.kind === "tool-placement"), (wait) => toolCalls.getCall(exports_ids_schema.ToolCallId.make(String(wait.metadata.tool_call_id ?? ""))).pipe(Effect.mapError(toClientError), Effect.map((call) => call?.placement.kind === "client" && call.state === "waiting" ? toPendingToolCall(call) : undefined)));
2001
+ const sorted = records.filter((record) => record !== undefined).toSorted((left, right) => left.requested_at - right.requested_at || left.call.id.localeCompare(right.call.id));
2002
+ return { tool_calls: input.limit === undefined ? sorted : sorted.slice(0, input.limit) };
2003
+ }),
2004
+ fulfillToolCall: Effect.fn("Client.runtime.fulfillToolCall")(function* (input) {
2005
+ const coordinated = yield* coordinateToolTransition(Effect.gen(function* () {
2006
+ const call = yield* toolCalls.getCall(input.tool_call_id).pipe(Effect.mapError(toClientError));
2007
+ if (call === undefined || call.executionId !== input.execution_id || call.placement.kind !== "client") {
2008
+ return yield* new ClientError({ message: `Client tool call not found: ${input.tool_call_id}` });
2009
+ }
2010
+ const wait = yield* resolveToolOutcomeWait(waits, eventLog, call, input.outcome, input.fulfilled_at);
2011
+ const accepted = yield* toolCalls.acceptClientOutcome({
2012
+ executionId: input.execution_id,
2013
+ callId: input.tool_call_id,
2014
+ outcome: input.outcome,
2015
+ submittedAt: input.fulfilled_at
2016
+ }).pipe(Effect.mapError(toClientError));
2017
+ return { wait, accepted };
2018
+ }));
2019
+ yield* signalToolOutcome(executionRepository, makeExecutionClient, coordinated.wait, input.fulfilled_at);
2020
+ return toToolOutcomeAccepted(coordinated.accepted);
2021
+ }),
2022
+ claimToolWork: Effect.fn("Client.runtime.claimToolWork")(function* (input) {
2023
+ const lease = yield* coordinateToolTransition(toolCalls.claimRemote({
2024
+ queue: input.queue,
2025
+ workerId: input.worker_id,
2026
+ now: input.now,
2027
+ claimExpiresAt: input.claim_expires_at
2028
+ }).pipe(Effect.mapError(toClientError)));
2029
+ return lease === undefined ? null : toToolWorkLease(lease);
2030
+ }),
2031
+ completeToolWork: Effect.fn("Client.runtime.completeToolWork")(function* (input) {
2032
+ const coordinated = yield* coordinateToolTransition(Effect.gen(function* () {
2033
+ const call = yield* toolCalls.getCall(input.tool_call_id).pipe(Effect.mapError(toClientError));
2034
+ const active = call !== undefined && call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attempt_id && call.claimOwner === input.worker_id && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.completed_at;
2035
+ const acceptedRetry = call !== undefined && call.placement.kind === "remote" && call.state === "submitted" && call.activeAttemptId === input.attempt_id && call.externalOutcome !== undefined;
2036
+ if (call === undefined || !active && !acceptedRetry) {
2037
+ return yield* new ClientError({ message: `Remote tool claim is not active: ${input.tool_call_id}` });
2038
+ }
2039
+ const wait = yield* resolveToolOutcomeWait(waits, eventLog, call, input.outcome, input.completed_at);
2040
+ const accepted = yield* toolCalls.acceptRemoteOutcome({
2041
+ callId: input.tool_call_id,
2042
+ attemptId: input.attempt_id,
2043
+ workerId: input.worker_id,
2044
+ outcome: input.outcome,
2045
+ submittedAt: input.completed_at
2046
+ }).pipe(Effect.mapError(toClientError));
2047
+ return { wait, accepted };
2048
+ }));
2049
+ yield* signalToolOutcome(executionRepository, makeExecutionClient, coordinated.wait, input.completed_at);
2050
+ return toToolOutcomeAccepted(coordinated.accepted);
2051
+ }),
2052
+ releaseToolWork: Effect.fn("Client.runtime.releaseToolWork")(function* (input) {
2053
+ const call = yield* coordinateToolTransition(toolCalls.releaseRemote({
2054
+ callId: input.tool_call_id,
2055
+ attemptId: input.attempt_id,
2056
+ workerId: input.worker_id,
2057
+ releasedAt: input.released_at,
2058
+ nextAvailableAt: input.next_available_at,
2059
+ ...input.error === undefined ? {} : { error: input.error }
2060
+ }).pipe(Effect.mapError(toClientError)));
2061
+ return {
2062
+ tool_call_id: call.call.id,
2063
+ state: "waiting",
2064
+ next_available_at: call.availableAt
2065
+ };
2066
+ }),
2067
+ listToolAttempts: Effect.fn("Client.runtime.listToolAttempts")(function* (input) {
2068
+ const attempts = yield* toolCalls.listAttempts(input.tool_call_id).pipe(Effect.mapError(toClientError));
2069
+ return { attempts: attempts.map(toToolAttempt) };
2070
+ }),
2071
+ submitInboundEnvelope: Effect.fn("Client.runtime.submitInboundEnvelope")(function* (input) {
2072
+ const envelope = yield* executions.send(input.envelope).pipe(Effect.mapError(toClientError));
2073
+ const wakeResult = yield* wakeRuntime(waits, eventLog, executionRepository, makeExecutionClient, input.wake);
2074
+ return { envelope, wake: wakeResult };
2075
+ }),
2076
+ spawnChildRun: Effect.fn("Client.runtime.spawnChildRun")(function* (input) {
2077
+ const pin = yield* parentDefinitionPin(executionRepository, input.execution_id);
2078
+ const createdAt = yield* Clock.currentTimeMillis;
2079
+ const internal = internalSpawnChildRunInput(input, pin, createdAt);
2080
+ const context = yield* exports_child_run_service.resolveForDispatch(internal).pipe(Effect.mapError((error) => new ClientError({ message: error._tag })));
2081
+ const definition = yield* exports_child_run_service.childDefinition(pin.agentSnapshot, context).pipe(Effect.mapError((error) => new ClientError({ message: error._tag })));
2082
+ const coordinated = yield* coordinateChildSpawn(Effect.gen(function* () {
2083
+ const existing = yield* reconcileExistingChildSpawn(childExecutions, waits, eventLog, input);
2084
+ if (existing !== undefined)
2085
+ return existing;
2086
+ const accepted = yield* executions.spawnChildRun(internal).pipe(Effect.mapError(toClientError));
2087
+ const parentWaitId = input.wait === true ? yield* createChildJoinWait(waits, eventLog, internal, accepted, createdAt) : undefined;
2088
+ return { accepted, createdAt, parentWaitId };
2089
+ })).pipe(Effect.catch((error) => error.message === "DuplicateChildExecution" ? coordinateChildSpawn(reconcileExistingChildSpawn(childExecutions, waits, eventLog, input).pipe(Effect.flatMap((existing) => existing === undefined ? Effect.fail(new ClientError({ message: `Child execution retry missing: ${input.execution_id}` })) : Effect.succeed(existing)))) : Effect.fail(error)));
2090
+ const startPayload = childStartInput(internal, coordinated.accepted, pin, definition, coordinated.createdAt, coordinated.parentWaitId);
2091
+ const client = makeExecutionClient(startPayload.execution_id);
2092
+ yield* client.dispatch(startPayload).pipe(Effect.mapError(toClientError));
2093
+ return coordinated.accepted;
2094
+ }),
2095
+ createChildFanOut: Effect.fn("Client.runtime.createChildFanOut")(function* (input) {
2096
+ return yield* Option.match(childFanOutRuntime, {
2097
+ onNone: () => childFanOuts.create(input),
2098
+ onSome: (runtime) => runtime.create(input)
2099
+ }).pipe(Effect.mapError(toClientError));
2100
+ }),
2101
+ cancelChildFanOut: Effect.fn("Client.runtime.cancelChildFanOut")(function* (input) {
2102
+ return yield* cancelFanOut(input);
2103
+ }),
2104
+ inspectChildFanOut: Effect.fn("Client.runtime.inspectChildFanOut")(function* (input) {
2105
+ const fanOut = yield* Option.match(childFanOutRuntime, {
2106
+ onNone: () => childFanOuts.get(input.fan_out_id),
2107
+ onSome: (runtime) => runtime.inspect(input.fan_out_id)
2108
+ }).pipe(Effect.mapError(toClientError));
2109
+ return { fan_out: fanOut ?? null };
2110
+ }),
2111
+ claimEnvelopeReady: Effect.fn("Client.runtime.claimEnvelopeReady")(function* (input) {
2112
+ return yield* envelopeReady.claimReady({
2113
+ routeType: input.route_type,
2114
+ ...input.route_key === undefined ? {} : { routeKey: input.route_key },
2115
+ workerId: input.worker_id,
2116
+ now: input.now,
2117
+ claimExpiresAt: input.claim_expires_at
2118
+ }).pipe(Effect.map((record) => record === undefined ? null : toLease(record)), Effect.mapError(toClientError));
2119
+ }),
2120
+ ackEnvelopeReady: Effect.fn("Client.runtime.ackEnvelopeReady")(function* (input) {
2121
+ return yield* envelopeReady.ackReady({
2122
+ id: input.envelope_ready_id,
2123
+ workerId: input.worker_id,
2124
+ now: input.acknowledged_at
2125
+ }).pipe(Effect.map((record) => ({
2126
+ envelope_ready_id: record.id,
2127
+ state: "acknowledged",
2128
+ acknowledged_at: record.acknowledgedAt ?? input.acknowledged_at
2129
+ })), Effect.mapError(toClientError));
2130
+ }),
2131
+ releaseEnvelopeReady: Effect.fn("Client.runtime.releaseEnvelopeReady")(function* (input) {
2132
+ return yield* envelopeReady.releaseReady({
2133
+ id: input.envelope_ready_id,
2134
+ workerId: input.worker_id,
2135
+ nextAvailableAt: input.next_available_at,
2136
+ ...input.error === undefined ? {} : { error: input.error }
2137
+ }).pipe(Effect.map((record) => ({
2138
+ envelope_ready_id: record.id,
2139
+ state: "ready",
2140
+ next_available_at: record.availableAt
2141
+ })), Effect.mapError(toClientError));
2142
+ }),
2143
+ createSchedule: Effect.fn("Client.runtime.createSchedule")(function* (input) {
2144
+ if (input.cron_expr !== undefined) {
2145
+ yield* exports_scheduler_service.parseCron(input.cron_expr).pipe(Effect.mapError(toClientError));
2146
+ }
2147
+ const createdAt = yield* Clock.currentTimeMillis;
2148
+ const schedule = yield* schedules.create({
2149
+ id: input.schedule_id,
2150
+ kind: input.kind,
2151
+ targetKind: input.target_kind,
2152
+ nextRunAt: input.next_run_at,
2153
+ createdAt,
2154
+ ...input.address_id === undefined ? {} : { addressId: input.address_id },
2155
+ ...input.wait_id === undefined ? {} : { waitId: input.wait_id },
2156
+ ...input.cron_expr === undefined ? {} : { cronExpr: input.cron_expr },
2157
+ ...input.input === undefined ? {} : { input: input.input },
2158
+ ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
2159
+ ...input.metadata === undefined ? {} : { metadata: input.metadata }
2160
+ }).pipe(Effect.mapError(toClientError));
2161
+ return { schedule };
2162
+ }),
2163
+ cancelSchedule: Effect.fn("Client.runtime.cancelSchedule")(function* (input) {
2164
+ const schedule = yield* schedules.cancel({ id: input.schedule_id, cancelledAt: input.cancelled_at }).pipe(Effect.mapError(toClientError));
2165
+ return { schedule };
2166
+ }),
2167
+ listSchedules: Effect.fn("Client.runtime.listSchedules")(function* (input) {
2168
+ const records = yield* schedules.list(input.state === undefined ? {} : { state: input.state }).pipe(Effect.mapError(toClientError));
2169
+ return { schedules: records };
2170
+ })
2171
+ });
2172
+ }));
2173
+ var testLayer = (implementation) => Layer.succeed(Service, Service.of({
2174
+ ...implementation,
2175
+ followExecution: implementation.followExecution ?? followExecutionFrom({
2176
+ getExecution: implementation.getExecution,
2177
+ inspectExecution: implementation.inspectExecution,
2178
+ streamExecution: implementation.streamExecution
2179
+ }),
2180
+ registerEntityKind: implementation.registerEntityKind ?? ((input) => Effect.succeed(input)),
2181
+ getOrCreateEntity: implementation.getOrCreateEntity ?? (() => Effect.fail(new ClientError({ message: "Entity service unavailable" }))),
2182
+ getEntity: implementation.getEntity ?? (() => Effect.succeed(undefined)),
2183
+ destroyEntity: implementation.destroyEntity ?? (() => Effect.fail(new ClientError({ message: "Entity service unavailable" }))),
2184
+ listEntities: implementation.listEntities ?? (() => Effect.succeed([])),
2185
+ streamSession: implementation.streamSession ?? (() => Stream.empty),
2186
+ watchExecutions: implementation.watchExecutions ?? (() => Stream.empty),
2187
+ getPresence: implementation.getPresence ?? ((scope) => Effect.succeed({ scope, entries: [], observed_at: 0 })),
2188
+ watchPresence: implementation.watchPresence ?? (() => Stream.empty),
2189
+ registerWorkflowDefinition: implementation.registerWorkflowDefinition ?? (() => Effect.die("registerWorkflowDefinition not implemented")),
2190
+ getWorkflowDefinitionRevision: implementation.getWorkflowDefinitionRevision ?? (() => Effect.die("getWorkflowDefinitionRevision not implemented")),
2191
+ listWorkflowDefinitionRevisions: implementation.listWorkflowDefinitionRevisions ?? (() => Effect.die("listWorkflowDefinitionRevisions not implemented")),
2192
+ startWorkflowRun: implementation.startWorkflowRun ?? (() => Effect.die("startWorkflowRun not implemented")),
2193
+ inspectWorkflowRun: implementation.inspectWorkflowRun ?? (() => Effect.die("inspectWorkflowRun not implemented")),
2194
+ replayWorkflowRun: implementation.replayWorkflowRun ?? (() => Effect.die("replayWorkflowRun not implemented")),
2195
+ cancelWorkflowRun: implementation.cancelWorkflowRun ?? (() => Effect.die("cancelWorkflowRun not implemented"))
2196
+ }));
2197
+ var registerAgentDefinition = Effect.fn("Client.registerAgentDefinition.call")(function* (input) {
2198
+ const service = yield* Service;
2199
+ return yield* service.registerAgentDefinition(input);
2200
+ });
2201
+ var registerEntityKind = Effect.fn("Client.registerEntityKind.call")(function* (input) {
2202
+ const service = yield* Service;
2203
+ return yield* service.registerEntityKind(input);
2204
+ });
2205
+ var getOrCreateEntity = Effect.fn("Client.getOrCreateEntity.call")(function* (input) {
2206
+ const service = yield* Service;
2207
+ return yield* service.getOrCreateEntity(input);
2208
+ });
2209
+ var getEntity = Effect.fn("Client.getEntity.call")(function* (input) {
2210
+ const service = yield* Service;
2211
+ return yield* service.getEntity(input);
2212
+ });
2213
+ var destroyEntity = Effect.fn("Client.destroyEntity.call")(function* (input) {
2214
+ const service = yield* Service;
2215
+ return yield* service.destroyEntity(input);
2216
+ });
2217
+ var listEntities = Effect.fn("Client.listEntities.call")(function* (input) {
2218
+ const service = yield* Service;
2219
+ return yield* service.listEntities(input);
2220
+ });
2221
+ var registerAgent = Effect.fn("Client.registerAgent.call")(function* (input) {
2222
+ const service = yield* Service;
2223
+ return yield* service.registerAgent(input);
2224
+ });
2225
+ var getAgentDefinition = Effect.fn("Client.getAgentDefinition.call")(function* (id) {
2226
+ const service = yield* Service;
2227
+ return yield* service.getAgentDefinition(id);
2228
+ });
2229
+ var listAgentDefinitions = Effect.fn("Client.listAgentDefinitions.call")(function* () {
2230
+ const service = yield* Service;
2231
+ return yield* service.listAgentDefinitions();
2232
+ });
2233
+ var listAgentDefinitionRevisions = Effect.fn("Client.listAgentDefinitionRevisions.call")(function* (id) {
2234
+ const service = yield* Service;
2235
+ return yield* service.listAgentDefinitionRevisions(id);
2236
+ });
2237
+ var getSkillDefinition = Effect.fn("Client.getSkillDefinition.call")(function* (id) {
2238
+ const service = yield* Service;
2239
+ return yield* service.getSkillDefinition(id);
2240
+ });
2241
+ var listSkillDefinitions = Effect.fn("Client.listSkillDefinitions.call")(function* () {
2242
+ const service = yield* Service;
2243
+ return yield* service.listSkillDefinitions();
2244
+ });
2245
+ var listSkillDefinitionRevisions = Effect.fn("Client.listSkillDefinitionRevisions.call")(function* (id) {
2246
+ const service = yield* Service;
2247
+ return yield* service.listSkillDefinitionRevisions(id);
2248
+ });
2249
+ var registerAddressBookRoute = Effect.fn("Client.registerAddressBookRoute.call")(function* (input) {
2250
+ const service = yield* Service;
2251
+ return yield* service.registerAddressBookRoute(input);
2252
+ });
2253
+ var getAddressBookRoute = Effect.fn("Client.getAddressBookRoute.call")(function* (id) {
2254
+ const service = yield* Service;
2255
+ return yield* service.getAddressBookRoute(id);
2256
+ });
2257
+ var listAddressBookRoutes = Effect.fn("Client.listAddressBookRoutes.call")(function* () {
2258
+ const service = yield* Service;
2259
+ return yield* service.listAddressBookRoutes();
2260
+ });
2261
+ var startExecution = Effect.fn("Client.startExecution.call")(function* (input) {
2262
+ const service = yield* Service;
2263
+ return yield* service.startExecution(input);
2264
+ });
2265
+ var startExecutionByAddress = Effect.fn("Client.startExecutionByAddress.call")(function* (input) {
2266
+ const service = yield* Service;
2267
+ return yield* service.startExecutionByAddress(input);
2268
+ });
2269
+ var startExecutionByAgentDefinition = Effect.fn("Client.startExecutionByAgentDefinition.call")(function* (input) {
2270
+ const service = yield* Service;
2271
+ return yield* service.startExecutionByAgentDefinition(input);
2272
+ });
2273
+ var cancelExecution = Effect.fn("Client.cancelExecution.call")(function* (input) {
2274
+ const service = yield* Service;
2275
+ return yield* service.cancelExecution(input);
2276
+ });
2277
+ var steer = Effect.fn("Client.steer.call")(function* (input) {
2278
+ const service = yield* Service;
2279
+ return yield* service.steer(input);
2280
+ });
2281
+ var getExecution = Effect.fn("Client.getExecution.call")(function* (id) {
2282
+ const service = yield* Service;
2283
+ return yield* service.getExecution(id);
2284
+ });
2285
+ var listExecutions = Effect.fn("Client.listExecutions.call")(function* (input) {
2286
+ const service = yield* Service;
2287
+ return yield* service.listExecutions(input);
2288
+ });
2289
+ var listSessions = Effect.fn("Client.listSessions.call")(function* (input) {
2290
+ const service = yield* Service;
2291
+ return yield* service.listSessions(input);
2292
+ });
2293
+ var getSession = Effect.fn("Client.getSession.call")(function* (input) {
2294
+ const service = yield* Service;
2295
+ return yield* service.getSession(input);
2296
+ });
2297
+ var listWaits = Effect.fn("Client.listWaits.call")(function* (input) {
2298
+ const service = yield* Service;
2299
+ return yield* service.listWaits(input);
2300
+ });
2301
+ var replayExecution = Effect.fn("Client.replayExecution.call")(function* (input) {
2302
+ const service = yield* Service;
2303
+ return yield* service.replayExecution(input);
2304
+ });
2305
+ var listRunners = Effect.fn("Client.listRunners.call")(function* () {
2306
+ const service = yield* Service;
2307
+ return yield* service.listRunners();
2308
+ });
2309
+ var routeExecution = Effect.fn("Client.routeExecution.call")(function* (executionId) {
2310
+ const service = yield* Service;
2311
+ return yield* service.routeExecution(executionId);
2312
+ });
2313
+ var subscribeTopic = Effect.fn("Client.subscribeTopic.call")(function* (input) {
2314
+ const service = yield* Service;
2315
+ return yield* service.subscribeTopic(input);
2316
+ });
2317
+ var unsubscribeTopic = Effect.fn("Client.unsubscribeTopic.call")(function* (input) {
2318
+ const service = yield* Service;
2319
+ return yield* service.unsubscribeTopic(input);
2320
+ });
2321
+ var publishTopic = Effect.fn("Client.publishTopic.call")(function* (input) {
2322
+ const service = yield* Service;
2323
+ return yield* service.publishTopic(input);
2324
+ });
2325
+ var listTopicSubscriptions = Effect.fn("Client.listTopicSubscriptions.call")(function* (input) {
2326
+ const service = yield* Service;
2327
+ return yield* service.listTopicSubscriptions(input);
2328
+ });
2329
+ var listInboxMessages = Effect.fn("Client.listInboxMessages.call")(function* (input) {
2330
+ const service = yield* Service;
2331
+ return yield* service.listInboxMessages(input);
2332
+ });
2333
+ var inspectExecution = Effect.fn("Client.inspectExecution.call")(function* (executionId) {
2334
+ const service = yield* Service;
2335
+ return yield* service.inspectExecution(executionId);
2336
+ });
2337
+ var send = Effect.fn("Client.send.call")(function* (input) {
2338
+ const service = yield* Service;
2339
+ return yield* service.send(input);
2340
+ });
2341
+ var streamExecution = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.streamExecution(input))));
2342
+ var followExecution = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.followExecution(input))));
2343
+ var streamSession = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.streamSession(input))));
2344
+ var watchExecutions = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.watchExecutions(input))));
2345
+ var getPresence = Effect.fn("Client.getPresence.call")(function* (scope) {
2346
+ const service = yield* Service;
2347
+ return yield* service.getPresence(scope);
2348
+ });
2349
+ var watchPresence = (scope) => Stream.unwrap(Service.pipe(Effect.map((service) => service.watchPresence(scope))));
2350
+ var wake = Effect.fn("Client.wake.call")(function* (input) {
2351
+ const service = yield* Service;
2352
+ return yield* service.wake(input);
2353
+ });
2354
+ var listPendingApprovals = Effect.fn("Client.listPendingApprovals.call")(function* (input) {
2355
+ const service = yield* Service;
2356
+ return yield* service.listPendingApprovals(input);
2357
+ });
2358
+ var resolveToolApproval = Effect.fn("Client.resolveToolApproval.call")(function* (input) {
2359
+ const service = yield* Service;
2360
+ return yield* service.resolveToolApproval(input);
2361
+ });
2362
+ var resolvePermission = Effect.fn("Client.resolvePermission.call")(function* (input) {
2363
+ const service = yield* Service;
2364
+ return yield* service.resolvePermission(input);
2365
+ });
2366
+ var listPendingToolCalls = Effect.fn("Client.listPendingToolCalls.call")(function* (input) {
2367
+ const service = yield* Service;
2368
+ return yield* service.listPendingToolCalls(input);
2369
+ });
2370
+ var fulfillToolCall = Effect.fn("Client.fulfillToolCall.call")(function* (input) {
2371
+ const service = yield* Service;
2372
+ return yield* service.fulfillToolCall(input);
2373
+ });
2374
+ var claimToolWork = Effect.fn("Client.claimToolWork.call")(function* (input) {
2375
+ const service = yield* Service;
2376
+ return yield* service.claimToolWork(input);
2377
+ });
2378
+ var completeToolWork = Effect.fn("Client.completeToolWork.call")(function* (input) {
2379
+ const service = yield* Service;
2380
+ return yield* service.completeToolWork(input);
2381
+ });
2382
+ var releaseToolWork = Effect.fn("Client.releaseToolWork.call")(function* (input) {
2383
+ const service = yield* Service;
2384
+ return yield* service.releaseToolWork(input);
2385
+ });
2386
+ var listToolAttempts = Effect.fn("Client.listToolAttempts.call")(function* (input) {
2387
+ const service = yield* Service;
2388
+ return yield* service.listToolAttempts(input);
2389
+ });
2390
+ var submitInboundEnvelope = Effect.fn("Client.submitInboundEnvelope.call")(function* (input) {
2391
+ const service = yield* Service;
2392
+ return yield* service.submitInboundEnvelope(input);
2393
+ });
2394
+ var spawnChildRun = Effect.fn("Client.spawnChildRun.call")(function* (input) {
2395
+ const service = yield* Service;
2396
+ return yield* service.spawnChildRun(input);
2397
+ });
2398
+ var createChildFanOut = Effect.fn("Client.createChildFanOut.call")(function* (input) {
2399
+ const service = yield* Service;
2400
+ return yield* service.createChildFanOut(input);
2401
+ });
2402
+ var cancelChildFanOut = Effect.fn("Client.cancelChildFanOut.call")(function* (input) {
2403
+ const service = yield* Service;
2404
+ return yield* service.cancelChildFanOut(input);
2405
+ });
2406
+ var inspectChildFanOut = Effect.fn("Client.inspectChildFanOut.call")(function* (input) {
2407
+ const service = yield* Service;
2408
+ return yield* service.inspectChildFanOut(input);
2409
+ });
2410
+ var claimEnvelopeReady = Effect.fn("Client.claimEnvelopeReady.call")(function* (input) {
2411
+ const service = yield* Service;
2412
+ return yield* service.claimEnvelopeReady(input);
2413
+ });
2414
+ var ackEnvelopeReady = Effect.fn("Client.ackEnvelopeReady.call")(function* (input) {
2415
+ const service = yield* Service;
2416
+ return yield* service.ackEnvelopeReady(input);
2417
+ });
2418
+ var releaseEnvelopeReady = Effect.fn("Client.releaseEnvelopeReady.call")(function* (input) {
2419
+ const service = yield* Service;
2420
+ return yield* service.releaseEnvelopeReady(input);
2421
+ });
2422
+ var createSchedule = Effect.fn("Client.createSchedule.call")(function* (input) {
2423
+ const service = yield* Service;
2424
+ return yield* service.createSchedule(input);
2425
+ });
2426
+ var cancelSchedule = Effect.fn("Client.cancelSchedule.call")(function* (input) {
2427
+ const service = yield* Service;
2428
+ return yield* service.cancelSchedule(input);
2429
+ });
2430
+ var listSchedules = Effect.fn("Client.listSchedules.call")(function* (input) {
2431
+ const service = yield* Service;
2432
+ return yield* service.listSchedules(input);
2433
+ });
2434
+ var askEntity = Effect.fn("Client.askEntity.call")(function* (input) {
2435
+ const service = yield* Service;
2436
+ return yield* service.askEntity(input);
2437
+ });
2438
+ var awaitWait = Effect.fn("Client.awaitWait.call")(function* (input) {
2439
+ const service = yield* Service;
2440
+ return yield* service.awaitWait(input);
2441
+ });
2442
+
2443
+ export { exports_operation, exports_command, Service, exports_client };