@relayfx/sdk 0.3.1 → 0.3.3

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