@relayfx/sdk 0.1.0 → 0.2.1

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 (47) hide show
  1. package/dist/ai.js +2 -2
  2. package/dist/{index-vbf5hcw8.js → index-9tx9fh58.js} +320 -33
  3. package/dist/{index-sms8x6cq.js → index-bke4jyr6.js} +1 -1
  4. package/dist/{index-q0z11q9m.js → index-jy6rpstp.js} +5711 -3835
  5. package/dist/index.js +92 -3
  6. package/dist/migrations/20260712180000_child_fan_out/migration.sql +27 -0
  7. package/dist/migrations/20260712190000_workflow_definitions/migration.sql +3 -0
  8. package/dist/migrations/20260712200000_workflow_runtime/migration.sql +2 -0
  9. package/dist/migrations/mysql/0008_child_fan_out.sql +26 -0
  10. package/dist/migrations/mysql/0009_workflow_definitions.sql +3 -0
  11. package/dist/migrations/mysql/0010_workflow_runtime.sql +3 -0
  12. package/dist/migrations/pg/20260712180000_child_fan_out/migration.sql +27 -0
  13. package/dist/migrations/pg/20260712190000_workflow_definitions/migration.sql +3 -0
  14. package/dist/migrations/pg/20260712200000_workflow_runtime/migration.sql +2 -0
  15. package/dist/migrations/sqlite/0008_child_fan_out.sql +27 -0
  16. package/dist/migrations/sqlite/0009_workflow_definitions.sql +3 -0
  17. package/dist/migrations/sqlite/0010_workflow_runtime.sql +3 -0
  18. package/dist/sqlite.js +60 -11
  19. package/dist/types/relay/adapter-outbox.d.ts +3 -3
  20. package/dist/types/relay/client.d.ts +147 -17
  21. package/dist/types/relay/index.d.ts +2 -2
  22. package/dist/types/relay/operation.d.ts +559 -2
  23. package/dist/types/relay/sqlite-migrations.d.ts +16 -1
  24. package/dist/types/relay/sqlite-runtime.d.ts +8 -3
  25. package/dist/types/relay/sqlite.d.ts +3 -1
  26. package/dist/types/runtime/child/child-fan-out-admission-service.d.ts +30 -0
  27. package/dist/types/runtime/child/child-fan-out-runtime.d.ts +34 -0
  28. package/dist/types/runtime/child/child-fan-out-transition-service.d.ts +25 -0
  29. package/dist/types/runtime/cluster/execution-entity.d.ts +4 -2
  30. package/dist/types/runtime/execution/active-execution-registry.d.ts +12 -0
  31. package/dist/types/runtime/execution/execution-service.d.ts +1 -0
  32. package/dist/types/runtime/index.d.ts +5 -0
  33. package/dist/types/runtime/runner/runner-runtime-service.d.ts +14 -14
  34. package/dist/types/runtime/workflow/definition-runtime.d.ts +78 -0
  35. package/dist/types/runtime/workflow/execution-workflow.d.ts +5 -5
  36. package/dist/types/schema/child-orchestration-schema.d.ts +393 -0
  37. package/dist/types/schema/execution-schema.d.ts +2 -2
  38. package/dist/types/schema/ids-schema.d.ts +12 -0
  39. package/dist/types/schema/index.d.ts +3 -0
  40. package/dist/types/schema/wait-schema.d.ts +98 -0
  41. package/dist/types/schema/workflow-schema.d.ts +2062 -0
  42. package/dist/types/store-sql/child/child-fan-out-repository.d.ts +53 -0
  43. package/dist/types/store-sql/index.d.ts +2 -0
  44. package/dist/types/store-sql/portable.d.ts +2 -0
  45. package/dist/types/store-sql/schema/relay-schema.d.ts +1266 -1
  46. package/dist/types/store-sql/workflow/workflow-definition-repository.d.ts +29 -0
  47. package/package.json +1 -1
package/dist/ai.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import"./index-sms8x6cq.js";
2
+ import"./index-bke4jyr6.js";
3
3
  import {
4
4
  AiError,
5
5
  Chat,
@@ -34,7 +34,7 @@ import {
34
34
  exports_tool_executor,
35
35
  exports_tool_output,
36
36
  exports_turn_policy
37
- } from "./index-q0z11q9m.js";
37
+ } from "./index-jy6rpstp.js";
38
38
 
39
39
  // src/ai.ts
40
40
  var relayAiPackage = "@relayfx/sdk/ai";
@@ -6,9 +6,13 @@ import {
6
6
  exports_agent_registry_service,
7
7
  exports_agent_schema,
8
8
  exports_child_execution_repository,
9
+ exports_child_fan_out_repository,
10
+ exports_child_fan_out_runtime,
11
+ exports_child_orchestration_schema,
9
12
  exports_child_run_service,
10
13
  exports_cluster_registry_repository,
11
14
  exports_content_schema,
15
+ exports_definition_runtime,
12
16
  exports_entity_instance_service,
13
17
  exports_entity_registry_service,
14
18
  exports_entity_schema,
@@ -40,9 +44,11 @@ import {
40
44
  exports_tool_schema,
41
45
  exports_tool_transition_coordinator,
42
46
  exports_topic_service,
47
+ exports_wait_schema,
43
48
  exports_wait_service,
44
- exports_wait_signal
45
- } from "./index-q0z11q9m.js";
49
+ exports_wait_signal,
50
+ exports_workflow_definition_repository
51
+ } from "./index-jy6rpstp.js";
46
52
 
47
53
  // src/operation.ts
48
54
  var exports_operation = {};
@@ -106,12 +112,17 @@ __export(exports_operation, {
106
112
  ListExecutionsInput: () => ListExecutionsInput,
107
113
  ListEntityStateInput: () => ListEntityStateInput,
108
114
  ListEntitiesInput: () => ListEntitiesInput,
115
+ InspectChildFanOutResult: () => InspectChildFanOutResult,
116
+ InspectChildFanOutInput: () => InspectChildFanOutInput,
109
117
  GetSessionResult: () => GetSessionResult,
110
118
  GetSessionInput: () => GetSessionInput,
111
119
  GetOrCreateEntityInput: () => GetOrCreateEntityInput,
112
120
  GetEntityStateInput: () => GetEntityStateInput,
113
121
  GetEntityInput: () => GetEntityInput,
114
122
  FulfillToolCallInput: () => FulfillToolCallInput,
123
+ FollowStopReason: () => FollowStopReason,
124
+ FollowExecutionItem: () => FollowExecutionItem,
125
+ FollowExecutionInput: () => FollowExecutionInput,
115
126
  ExecutionListChange: () => ExecutionListChange,
116
127
  ExecutionInspection: () => ExecutionInspection,
117
128
  ExecutionCursor: () => ExecutionCursor,
@@ -124,6 +135,7 @@ __export(exports_operation, {
124
135
  DeleteEntityStateInput: () => DeleteEntityStateInput,
125
136
  CreateScheduleResult: () => CreateScheduleResult,
126
137
  CreateScheduleInput: () => CreateScheduleInput,
138
+ CreateChildFanOutInput: () => CreateChildFanOutInput,
127
139
  ConversationSummary: () => ConversationSummary,
128
140
  ConversationKind: () => ConversationKind,
129
141
  CompleteToolWorkInput: () => CompleteToolWorkInput,
@@ -134,6 +146,8 @@ __export(exports_operation, {
134
146
  CancelScheduleInput: () => CancelScheduleInput,
135
147
  CancelExecutionInput: () => CancelExecutionInput,
136
148
  CancelExecutionAccepted: () => CancelExecutionAccepted,
149
+ CancelChildFanOutResult: () => CancelChildFanOutResult,
150
+ CancelChildFanOutInput: () => CancelChildFanOutInput,
137
151
  AwaitWaitInput: () => AwaitWaitInput,
138
152
  AckEnvelopeReadyInput: () => AckEnvelopeReadyInput
139
153
  });
@@ -272,6 +286,7 @@ var WaitView = Schema.Struct({
272
286
  wait_id: exports_ids_schema.WaitId,
273
287
  execution_id: exports_ids_schema.ExecutionId,
274
288
  envelope_id: Schema.optionalKey(exports_ids_schema.EnvelopeId),
289
+ kind: Schema.optionalKey(exports_wait_schema.WaitKind),
275
290
  mode: exports_envelope_schema.WaitMode,
276
291
  correlation_key: Schema.optionalKey(Schema.String),
277
292
  state: WaitState,
@@ -279,6 +294,25 @@ var WaitView = Schema.Struct({
279
294
  created_at: exports_shared_schema.TimestampMillis,
280
295
  resolved_at: Schema.optionalKey(exports_shared_schema.TimestampMillis)
281
296
  }).annotate({ identifier: "Relay.Operation.WaitView" });
297
+ var FollowStopReason = Schema.Union([
298
+ Schema.Struct({ _tag: Schema.tag("terminal"), status: exports_execution_schema.ExecutionStatus }),
299
+ Schema.Struct({ _tag: Schema.tag("actionable_wait"), wait: WaitView })
300
+ ]).annotate({ identifier: "Relay.Operation.FollowStopReason" });
301
+ var FollowExecutionItem = Schema.Union([
302
+ Schema.Struct({ _tag: Schema.tag("event"), event: exports_execution_schema.ExecutionEvent }),
303
+ Schema.Struct({ _tag: Schema.tag("reconnecting"), message: Schema.String, attempt: Schema.Int }),
304
+ Schema.Struct({
305
+ _tag: Schema.tag("stopped"),
306
+ reason: FollowStopReason,
307
+ cursor: Schema.NullOr(exports_shared_schema.NonEmptyString)
308
+ })
309
+ ]).annotate({ identifier: "Relay.Operation.FollowExecutionItem" });
310
+ var FollowExecutionInput = Schema.Struct({
311
+ execution_id: exports_ids_schema.ExecutionId,
312
+ after_cursor: Schema.optionalKey(exports_shared_schema.NonEmptyString),
313
+ stop_on_wait_modes: Schema.optionalKey(Schema.Array(exports_envelope_schema.WaitMode)),
314
+ max_reconnects: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
315
+ }).annotate({ identifier: "Relay.Operation.FollowExecutionInput" });
282
316
  var PendingToolApproval = Schema.Struct({
283
317
  wait_id: exports_ids_schema.WaitId,
284
318
  execution_id: exports_ids_schema.ExecutionId,
@@ -390,6 +424,23 @@ var SpawnChildRunInput = Schema.Struct({
390
424
  input: Schema.optionalKey(Schema.Array(exports_content_schema.Part)),
391
425
  wait: Schema.optionalKey(Schema.Boolean)
392
426
  }).annotate({ identifier: "Relay.Operation.SpawnChildRunInput" });
427
+ var CreateChildFanOutInput = exports_child_orchestration_schema.FanOutDefinition.annotate({
428
+ identifier: "Relay.Operation.CreateChildFanOutInput"
429
+ });
430
+ var CancelChildFanOutInput = Schema.Struct({
431
+ fan_out_id: exports_ids_schema.ChildFanOutId,
432
+ cancelled_at: exports_shared_schema.TimestampMillis,
433
+ reason: Schema.optionalKey(Schema.String)
434
+ }).annotate({ identifier: "Relay.Operation.CancelChildFanOutInput" });
435
+ var CancelChildFanOutResult = Schema.Struct({
436
+ fan_out: exports_child_orchestration_schema.FanOutState
437
+ }).annotate({ identifier: "Relay.Operation.CancelChildFanOutResult" });
438
+ var InspectChildFanOutInput = Schema.Struct({
439
+ fan_out_id: exports_ids_schema.ChildFanOutId
440
+ }).annotate({ identifier: "Relay.Operation.InspectChildFanOutInput" });
441
+ var InspectChildFanOutResult = Schema.Struct({
442
+ fan_out: Schema.NullOr(exports_child_orchestration_schema.FanOutState)
443
+ }).annotate({ identifier: "Relay.Operation.InspectChildFanOutResult" });
393
444
  var ResolveToolApprovalInput = Schema.Struct({
394
445
  wait_id: exports_ids_schema.WaitId,
395
446
  approved: Schema.Boolean,
@@ -718,6 +769,7 @@ __export(exports_client, {
718
769
  listAddressBookRoutes: () => listAddressBookRoutes,
719
770
  layerFromRuntime: () => layerFromRuntime,
720
771
  inspectExecution: () => inspectExecution,
772
+ inspectChildFanOut: () => inspectChildFanOut,
721
773
  getSkillDefinition: () => getSkillDefinition,
722
774
  getSession: () => getSession,
723
775
  getPresence: () => getPresence,
@@ -727,16 +779,21 @@ __export(exports_client, {
727
779
  getAgentDefinition: () => getAgentDefinition,
728
780
  getAddressBookRoute: () => getAddressBookRoute,
729
781
  fulfillToolCall: () => fulfillToolCall,
782
+ followExecutionFrom: () => followExecutionFrom,
783
+ followExecution: () => followExecution,
730
784
  destroyEntity: () => destroyEntity,
731
785
  createSchedule: () => createSchedule,
786
+ createChildFanOut: () => createChildFanOut,
732
787
  completeToolWork: () => completeToolWork,
733
788
  claimToolWork: () => claimToolWork,
734
789
  claimEnvelopeReady: () => claimEnvelopeReady,
735
790
  cancelSchedule: () => cancelSchedule,
736
791
  cancelExecution: () => cancelExecution,
792
+ cancelChildFanOut: () => cancelChildFanOut,
737
793
  awaitWait: () => awaitWait,
738
794
  askEntity: () => askEntity,
739
795
  ackEnvelopeReady: () => ackEnvelopeReady,
796
+ WaitKindMismatch: () => WaitKindMismatch,
740
797
  Service: () => Service,
741
798
  ExecutionNotFound: () => ExecutionNotFound,
742
799
  EventLogCursorNotFound: () => EventLogCursorNotFound,
@@ -758,8 +815,89 @@ class ExecutionNotFound extends Schema3.TaggedErrorClass()("ExecutionNotFound",
758
815
  class EntityNamespaceReserved extends Schema3.TaggedErrorClass()("EntityNamespaceReserved", { id: Schema3.String, message: Schema3.String }) {
759
816
  }
760
817
 
818
+ class WaitKindMismatch extends Schema3.TaggedErrorClass()("WaitKindMismatch", {
819
+ wait_id: exports_ids_schema.WaitId,
820
+ expected: Schema3.String,
821
+ actual: Schema3.String,
822
+ message: Schema3.String
823
+ }) {
824
+ }
825
+
761
826
  class Service extends Context.Service()("@relayfx/sdk/Client") {
762
827
  }
828
+ var followTerminalStatus = (type) => type === "execution.completed" ? "completed" : type === "execution.failed" ? "failed" : type === "execution.cancelled" ? "cancelled" : undefined;
829
+ var followReconnectDelayMillis = (attempt) => Math.min(100 * 2 ** (attempt - 1), 5000);
830
+ var followStopped = (reason, cursor) => ({
831
+ _tag: "stopped",
832
+ reason,
833
+ cursor: cursor ?? null
834
+ });
835
+ var followExecutionFrom = (dependencies) => (input) => {
836
+ const maxReconnects = input.max_reconnects ?? 10;
837
+ const stopModes = input.stop_on_wait_modes;
838
+ const inspect = Effect.suspend(() => dependencies.inspectExecution(input.execution_id)).pipe(Effect.catchTag("ExecutionNotFound", (error) => new ClientError({ message: `execution ${error.execution_id} not found` })));
839
+ const reconcile = (state, message) => Stream.unwrap(Effect.gen(function* () {
840
+ const inspection = yield* inspect;
841
+ const terminal = followTerminalStatus(`execution.${inspection.status}`);
842
+ if (terminal !== undefined) {
843
+ return Stream.make(followStopped({ _tag: "terminal", status: terminal }, state.cursor));
844
+ }
845
+ const actionable = stopModes === undefined ? undefined : inspection.waiting_on.find((wait) => wait.state === "open" && stopModes.includes(wait.mode));
846
+ if (actionable !== undefined) {
847
+ return Stream.make(followStopped({ _tag: "actionable_wait", wait: actionable }, state.cursor));
848
+ }
849
+ if (state.attempts >= maxReconnects) {
850
+ return Stream.fail(new ClientError({
851
+ message: `follow of ${input.execution_id} exhausted ${maxReconnects} reconnects: ${message}`
852
+ }));
853
+ }
854
+ state.attempts += 1;
855
+ const reconnecting = { _tag: "reconnecting", message, attempt: state.attempts };
856
+ return Stream.make(reconnecting).pipe(Stream.concat(Stream.fromEffect(Effect.sleep(followReconnectDelayMillis(state.attempts))).pipe(Stream.drain)), Stream.concat(Stream.suspend(() => connect(state))));
857
+ }));
858
+ const itemsFor = (state, event) => Effect.gen(function* () {
859
+ if (event.sequence <= state.sequence)
860
+ return [];
861
+ state.sequence = event.sequence;
862
+ state.cursor = event.cursor;
863
+ state.emitted = true;
864
+ state.attempts = 0;
865
+ const items = [{ _tag: "event", event }];
866
+ const terminal = followTerminalStatus(event.type);
867
+ if (terminal !== undefined) {
868
+ items.push(followStopped({ _tag: "terminal", status: terminal }, state.cursor));
869
+ return items;
870
+ }
871
+ if (stopModes !== undefined && event.type === "wait.created") {
872
+ const mode = event.data?.mode;
873
+ if (typeof mode === "string" && stopModes.includes(mode)) {
874
+ const inspection = yield* dependencies.inspectExecution(input.execution_id).pipe(Effect.catchTag("ExecutionNotFound", () => Effect.succeed(undefined)));
875
+ const actionable = inspection?.waiting_on.find((wait) => wait.state === "open" && wait.wait_id === event.data?.wait_id);
876
+ if (actionable !== undefined) {
877
+ items.push(followStopped({ _tag: "actionable_wait", wait: actionable }, state.cursor));
878
+ }
879
+ }
880
+ }
881
+ return items;
882
+ });
883
+ const connect = (state) => dependencies.streamExecution({
884
+ execution_id: input.execution_id,
885
+ ...state.cursor === undefined ? {} : { after_cursor: state.cursor }
886
+ }).pipe(Stream.flatMap((event) => Stream.fromEffect(itemsFor(state, event)).pipe(Stream.flatMap((items) => Stream.fromIterable(items)))), Stream.catchTag("EventLogCursorNotFound", (error) => !state.emitted && input.after_cursor !== undefined ? Stream.fail(error) : reconcile(state, `cursor ${error.cursor} was not found`)), Stream.catchTag("ClientError", (error) => reconcile(state, `stream failed: ${error.message}`)), Stream.concat(Stream.suspend(() => reconcile(state, "stream ended before a terminal event"))));
887
+ return Stream.unwrap(Effect.gen(function* () {
888
+ const existing = yield* dependencies.getExecution(input.execution_id);
889
+ if (existing === undefined) {
890
+ return Stream.fail(new ClientError({ message: `execution ${input.execution_id} not found` }));
891
+ }
892
+ const state = {
893
+ cursor: input.after_cursor,
894
+ sequence: -1,
895
+ attempts: 0,
896
+ emitted: false
897
+ };
898
+ return connect(state);
899
+ })).pipe(Stream.takeUntil((item) => item._tag === "stopped"));
900
+ };
763
901
  var errorMessage = (error) => {
764
902
  if (error instanceof Error)
765
903
  return error.message;
@@ -844,6 +982,12 @@ var toWaitView = (record) => ({
844
982
  wait_id: record.id,
845
983
  execution_id: record.executionId,
846
984
  ...record.envelopeId === undefined ? {} : { envelope_id: record.envelopeId },
985
+ kind: exports_wait_schema.classify({
986
+ wait_id: record.id,
987
+ mode: record.mode,
988
+ ...record.envelopeId === undefined ? {} : { envelope_id: record.envelopeId },
989
+ ...record.correlationKey === undefined ? {} : { correlation_key: record.correlationKey }
990
+ }).kind,
847
991
  mode: record.mode,
848
992
  ...record.correlationKey === undefined ? {} : { correlation_key: record.correlationKey },
849
993
  state: record.state,
@@ -1125,10 +1269,32 @@ var nextEventSequence = Effect.fn("Client.nextEventSequence")(function* (eventLo
1125
1269
  const max = yield* eventLog.maxSequence(executionId).pipe(Effect.mapError(toClientError));
1126
1270
  return max === undefined ? 0 : max + 1;
1127
1271
  });
1128
- var wakeRuntime = Effect.fn("Client.wakeRuntime")(function* (waits, eventLog, executionRepository, makeExecutionClient, input) {
1272
+ var waitSemanticKind = (wait) => wait.mode === "child" ? "child" : typeof wait.metadata.kind === "string" && wait.metadata.kind.length > 0 ? wait.metadata.kind : "general";
1273
+ var terminalChildStatus = (metadata) => {
1274
+ const status = metadata?.child_status;
1275
+ return status === "completed" || status === "failed" || status === "cancelled";
1276
+ };
1277
+ var wakeRuntime = Effect.fn("Client.wakeRuntime")(function* (waits, eventLog, executionRepository, makeExecutionClient, input, accepts) {
1129
1278
  const wait = yield* waits.get(input.wait_id).pipe(Effect.mapError(toClientError));
1130
1279
  if (wait === undefined)
1131
1280
  return yield* new ClientError({ message: `Wait not found: ${input.wait_id}` });
1281
+ const kind = waitSemanticKind(wait);
1282
+ if (accepts !== undefined && kind !== accepts) {
1283
+ return yield* new WaitKindMismatch({
1284
+ wait_id: input.wait_id,
1285
+ expected: accepts,
1286
+ actual: kind,
1287
+ message: `Wait ${input.wait_id} is a ${kind} wait; this resolver mutates only ${accepts} waits`
1288
+ });
1289
+ }
1290
+ if (accepts === undefined && kind === "child" && !terminalChildStatus(input.metadata)) {
1291
+ return yield* new WaitKindMismatch({
1292
+ wait_id: input.wait_id,
1293
+ expected: 'child wake with terminal metadata.child_status ("completed" | "failed" | "cancelled")',
1294
+ actual: kind,
1295
+ message: `Wait ${input.wait_id} joins a child run; wake it with terminal metadata.child_status or let the child runtime complete it`
1296
+ });
1297
+ }
1132
1298
  if (input.state === "cancelled" && wait.metadata.kind === "tool-placement") {
1133
1299
  return yield* new ClientError({ message: "Tool placement waits must be cancelled through cancelExecution" });
1134
1300
  }
@@ -1293,6 +1459,7 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1293
1459
  const topicService = yield* exports_topic_service.Service;
1294
1460
  const toolCalls = yield* exports_tool_call_repository.Service;
1295
1461
  const childExecutions = yield* exports_child_execution_repository.Service;
1462
+ const childFanOuts = yield* exports_child_fan_out_repository.Service;
1296
1463
  const sessionRepository = yield* exports_session_repository.Service;
1297
1464
  const steering = yield* exports_steering_repository.Service;
1298
1465
  const agentRegistry = yield* exports_agent_registry_service.Service;
@@ -1305,9 +1472,41 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1305
1472
  const schedules = yield* exports_schedule_repository.Service;
1306
1473
  const skillRegistry = yield* exports_skill_registry_service.Service;
1307
1474
  const toolTransitions = yield* exports_tool_transition_coordinator.Service;
1475
+ const workflows = yield* exports_workflow_definition_repository.Service;
1476
+ const workflowRuntime = yield* Effect.serviceOption(exports_definition_runtime.Service);
1477
+ const childFanOutRuntime = yield* Effect.serviceOption(exports_child_fan_out_runtime.Service);
1308
1478
  const schemaRegistry = yield* Effect.serviceOption(exports_schema_registry_service.Service);
1309
1479
  const coordinateToolTransition = (effect) => toolTransitions.coordinate(effect).pipe(Effect.mapError(toClientError));
1310
1480
  const coordinateChildSpawn = (effect) => toolTransitions.coordinate(effect).pipe(Effect.mapError(toClientError));
1481
+ const cancelFanOut = Effect.fn("Client.runtime.cancelFanOut")(function* (input) {
1482
+ if (Option.isSome(childFanOutRuntime)) {
1483
+ const fanOut = yield* childFanOutRuntime.value.cancel(input.fan_out_id, input.cancelled_at, input.reason ?? "child fan-out cancelled").pipe(Effect.mapError(toClientError));
1484
+ if (fanOut === undefined)
1485
+ return yield* new ClientError({ message: `Child fan-out not found: ${input.fan_out_id}` });
1486
+ return { fan_out: fanOut };
1487
+ }
1488
+ const result = yield* childFanOuts.cancel(input.fan_out_id, input.cancelled_at).pipe(Effect.mapError(toClientError));
1489
+ if (result === undefined)
1490
+ return yield* new ClientError({ message: `Child fan-out not found: ${input.fan_out_id}` });
1491
+ yield* Effect.forEach(result.activeChildExecutionIds, (childId) => makeExecutionClient(exports_ids_schema.ExecutionId.make(childId)).cancel({
1492
+ execution_id: exports_ids_schema.ExecutionId.make(childId),
1493
+ cancelled_at: input.cancelled_at,
1494
+ reason: input.reason ?? "child fan-out cancelled"
1495
+ }).pipe(Effect.mapError(toClientError)), { discard: true });
1496
+ if (result.transitioned) {
1497
+ const max = yield* eventLog.maxSequence(result.fanOut.parent_execution_id).pipe(Effect.mapError(toClientError));
1498
+ yield* exports_event_log_service.appendIdempotentTo(eventLog, {
1499
+ id: exports_ids_schema.EventId.make(`event:${result.fanOut.parent_execution_id}:fan-out:${input.fan_out_id}:terminal`),
1500
+ execution_id: result.fanOut.parent_execution_id,
1501
+ type: "child_fan_out.terminal",
1502
+ sequence: exports_execution_schema.ExecutionEventSequence.make(max === undefined ? 0 : max + 1),
1503
+ cursor: `${result.fanOut.parent_execution_id}:fan-out:${input.fan_out_id}:terminal`,
1504
+ data: { fan_out_id: input.fan_out_id, state: "cancelled" },
1505
+ created_at: input.cancelled_at
1506
+ }).pipe(Effect.mapError(toClientError));
1507
+ }
1508
+ return { fan_out: result.fanOut };
1509
+ });
1311
1510
  const sendEnvelope = Effect.fn("Client.runtime.send")(function* (input) {
1312
1511
  const identity = input.idempotency_key ?? input.correlation_key ?? `${input.from}:${input.to}`;
1313
1512
  const executionId = exports_ids_schema.ExecutionId.make(input.correlation_key ?? `execution:send:${identity}`);
@@ -1345,6 +1544,34 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1345
1544
  }
1346
1545
  return yield* waitOutcomeFrom(terminal);
1347
1546
  });
1547
+ const getExecutionOperation = Effect.fn("Client.runtime.getExecution")(function* (id) {
1548
+ const record = yield* executionRepository.get(id).pipe(Effect.mapError(toClientError));
1549
+ return record === undefined ? undefined : toExecutionView(record);
1550
+ });
1551
+ const streamExecutionOperation = (input) => executions.stream({
1552
+ executionId: input.execution_id,
1553
+ ...input.after_cursor === undefined ? {} : { afterCursor: input.after_cursor },
1554
+ ...input.limit === undefined ? {} : { limit: input.limit }
1555
+ }).pipe(Stream.mapError(toStreamError));
1556
+ const inspectExecutionOperation = Effect.fn("Client.runtime.inspectExecution")(function* (executionId) {
1557
+ const execution = yield* executionRepository.get(executionId).pipe(Effect.mapError(toClientError));
1558
+ if (execution === undefined)
1559
+ return yield* new ExecutionNotFound({ execution_id: executionId });
1560
+ const openWaits = yield* envelopeReady.listAllWaits({ executionId, state: "open" }).pipe(Effect.mapError(toClientError));
1561
+ const calls = yield* toolCalls.listCalls(executionId).pipe(Effect.mapError(toClientError));
1562
+ const pendingChunks = yield* Effect.forEach(calls, (call) => toolCalls.getResult(call.call.id).pipe(Effect.mapError(toClientError), Effect.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
1563
+ const children = yield* childExecutions.listByExecution(executionId).pipe(Effect.mapError(toClientError));
1564
+ const maxSequence = yield* eventLog.maxSequence(executionId).pipe(Effect.mapError(toClientError));
1565
+ const lastEvent = maxSequence === undefined ? undefined : yield* eventLog.findBySequence({ executionId, sequence: maxSequence }).pipe(Effect.mapError(toClientError), Effect.map(Option.getOrUndefined));
1566
+ return {
1567
+ execution_id: execution.id,
1568
+ status: execution.status,
1569
+ waiting_on: openWaits.map(toWaitView),
1570
+ pending_tool_calls: pendingChunks.flat(),
1571
+ child_runs: children.map(toChildRunSummary),
1572
+ ...lastEvent === undefined ? {} : { last_event_cursor: lastEvent.cursor }
1573
+ };
1574
+ });
1348
1575
  return Service.of({
1349
1576
  registerEntityKind: (input) => entityRegistry.registerKind(input).pipe(Effect.mapError(toClientError)),
1350
1577
  getOrCreateEntity: (input) => entities.getOrCreate({
@@ -1367,6 +1594,39 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1367
1594
  ...input.after_key === undefined ? {} : { afterKey: input.after_key },
1368
1595
  ...input.limit === undefined ? {} : { limit: input.limit }
1369
1596
  }).pipe(Effect.mapError(toClientError)),
1597
+ registerWorkflowDefinition: Effect.fn("Client.runtime.registerWorkflowDefinition")(function* (input) {
1598
+ return { record: yield* workflows.register(input).pipe(Effect.mapError(toClientError)) };
1599
+ }),
1600
+ getWorkflowDefinitionRevision: Effect.fn("Client.runtime.getWorkflowDefinitionRevision")(function* (id, revision) {
1601
+ return yield* workflows.get(id, revision).pipe(Effect.mapError(toClientError));
1602
+ }),
1603
+ listWorkflowDefinitionRevisions: Effect.fn("Client.runtime.listWorkflowDefinitionRevisions")(function* (id) {
1604
+ return { records: yield* workflows.list(id).pipe(Effect.mapError(toClientError)) };
1605
+ }),
1606
+ startWorkflowRun: Effect.fn("Client.runtime.startWorkflowRun")(function* (input) {
1607
+ return yield* Option.match(workflowRuntime, {
1608
+ onNone: () => workflows.start(input),
1609
+ onSome: (runtime) => runtime.start(input)
1610
+ }).pipe(Effect.mapError(toClientError));
1611
+ }),
1612
+ inspectWorkflowRun: Effect.fn("Client.runtime.inspectWorkflowRun")(function* (id) {
1613
+ return yield* Option.match(workflowRuntime, {
1614
+ onNone: () => workflows.inspect(id),
1615
+ onSome: (runtime) => runtime.inspect(id)
1616
+ }).pipe(Effect.mapError(toClientError));
1617
+ }),
1618
+ replayWorkflowRun: Effect.fn("Client.runtime.replayWorkflowRun")(function* (id) {
1619
+ return yield* Option.match(workflowRuntime, {
1620
+ onNone: () => workflows.listLifecycle(id),
1621
+ onSome: (runtime) => runtime.replay(id)
1622
+ }).pipe(Effect.mapError(toClientError));
1623
+ }),
1624
+ cancelWorkflowRun: Effect.fn("Client.runtime.cancelWorkflowRun")(function* (id) {
1625
+ return yield* Option.match(workflowRuntime, {
1626
+ onNone: () => workflows.cancel(id),
1627
+ onSome: (runtime) => runtime.cancel(id)
1628
+ }).pipe(Effect.mapError(toClientError));
1629
+ }),
1370
1630
  registerAgent: Effect.fn("Client.runtime.registerAgent")(function* (input) {
1371
1631
  const payload = yield* registerAgentPayload(input);
1372
1632
  const registered = yield* agentRegistry.register(payload).pipe(Effect.mapError(toClientError));
@@ -1437,6 +1697,12 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1437
1697
  return yield* client.start(payload).pipe(Effect.mapError(toClientError));
1438
1698
  }),
1439
1699
  cancelExecution: Effect.fn("Client.runtime.cancelExecution")(function* (input) {
1700
+ const fanOuts = yield* childFanOuts.listNonTerminal(input.execution_id).pipe(Effect.mapError(toClientError));
1701
+ yield* Effect.forEach(fanOuts, (fanOut) => cancelFanOut({
1702
+ fan_out_id: fanOut.fan_out_id,
1703
+ cancelled_at: input.cancelled_at,
1704
+ ...input.reason === undefined ? {} : { reason: input.reason }
1705
+ }), { discard: true });
1440
1706
  const client = makeExecutionClient(input.execution_id);
1441
1707
  return yield* client.cancel({
1442
1708
  execution_id: input.execution_id,
@@ -1460,28 +1726,12 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1460
1726
  }).pipe(Effect.mapError(toClientError));
1461
1727
  return { execution_id: record.executionId, kind: record.kind, sequence: record.sequence };
1462
1728
  }),
1463
- getExecution: Effect.fn("Client.runtime.getExecution")(function* (id) {
1464
- const record = yield* executionRepository.get(id).pipe(Effect.mapError(toClientError));
1465
- return record === undefined ? undefined : toExecutionView(record);
1466
- }),
1467
- inspectExecution: Effect.fn("Client.runtime.inspectExecution")(function* (executionId) {
1468
- const execution = yield* executionRepository.get(executionId).pipe(Effect.mapError(toClientError));
1469
- if (execution === undefined)
1470
- return yield* new ExecutionNotFound({ execution_id: executionId });
1471
- const openWaits = yield* envelopeReady.listAllWaits({ executionId, state: "open" }).pipe(Effect.mapError(toClientError));
1472
- const calls = yield* toolCalls.listCalls(executionId).pipe(Effect.mapError(toClientError));
1473
- const pendingChunks = yield* Effect.forEach(calls, (call) => toolCalls.getResult(call.call.id).pipe(Effect.mapError(toClientError), Effect.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
1474
- const children = yield* childExecutions.listByExecution(executionId).pipe(Effect.mapError(toClientError));
1475
- const maxSequence = yield* eventLog.maxSequence(executionId).pipe(Effect.mapError(toClientError));
1476
- const lastEvent = maxSequence === undefined ? undefined : yield* eventLog.findBySequence({ executionId, sequence: maxSequence }).pipe(Effect.mapError(toClientError), Effect.map(Option.getOrUndefined));
1477
- return {
1478
- execution_id: execution.id,
1479
- status: execution.status,
1480
- waiting_on: openWaits.map(toWaitView),
1481
- pending_tool_calls: pendingChunks.flat(),
1482
- child_runs: children.map(toChildRunSummary),
1483
- ...lastEvent === undefined ? {} : { last_event_cursor: lastEvent.cursor }
1484
- };
1729
+ getExecution: getExecutionOperation,
1730
+ inspectExecution: inspectExecutionOperation,
1731
+ followExecution: followExecutionFrom({
1732
+ getExecution: getExecutionOperation,
1733
+ inspectExecution: inspectExecutionOperation,
1734
+ streamExecution: streamExecutionOperation
1485
1735
  }),
1486
1736
  listWaits: Effect.fn("Client.runtime.listWaits")(function* (input) {
1487
1737
  const records = yield* envelopeReady.listWaits({
@@ -1663,11 +1913,7 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1663
1913
  })));
1664
1914
  }),
1665
1915
  awaitWait: awaitWaitOperation,
1666
- streamExecution: (input) => executions.stream({
1667
- executionId: input.execution_id,
1668
- ...input.after_cursor === undefined ? {} : { afterCursor: input.after_cursor },
1669
- ...input.limit === undefined ? {} : { limit: input.limit }
1670
- }).pipe(Stream.mapError(toStreamError)),
1916
+ streamExecution: streamExecutionOperation,
1671
1917
  streamSession: (input) => sessionStream.stream({
1672
1918
  sessionId: input.session_id,
1673
1919
  ...input.resume === undefined ? {} : {
@@ -1733,7 +1979,7 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1733
1979
  approved: input.approved,
1734
1980
  ...input.comment === undefined ? {} : { comment: input.comment }
1735
1981
  }
1736
- });
1982
+ }, "tool-approval");
1737
1983
  }),
1738
1984
  resolvePermission: Effect.fn("Client.runtime.resolvePermission")(function* (input) {
1739
1985
  return yield* wakeRuntime(waits, eventLog, executionRepository, makeExecutionClient, {
@@ -1744,7 +1990,7 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1744
1990
  answer: input.answer,
1745
1991
  ...input.reason === undefined ? {} : { reason: input.reason }
1746
1992
  }
1747
- });
1993
+ }, "tool-permission");
1748
1994
  }),
1749
1995
  listPendingToolCalls: Effect.fn("Client.runtime.listPendingToolCalls")(function* (input) {
1750
1996
  const openWaits = yield* envelopeReady.listAllWaits({
@@ -1846,6 +2092,22 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1846
2092
  yield* client.dispatch(startPayload).pipe(Effect.mapError(toClientError));
1847
2093
  return coordinated.accepted;
1848
2094
  }),
2095
+ createChildFanOut: Effect.fn("Client.runtime.createChildFanOut")(function* (input) {
2096
+ return yield* Option.match(childFanOutRuntime, {
2097
+ onNone: () => childFanOuts.create(input),
2098
+ onSome: (runtime) => runtime.create(input)
2099
+ }).pipe(Effect.mapError(toClientError));
2100
+ }),
2101
+ cancelChildFanOut: Effect.fn("Client.runtime.cancelChildFanOut")(function* (input) {
2102
+ return yield* cancelFanOut(input);
2103
+ }),
2104
+ inspectChildFanOut: Effect.fn("Client.runtime.inspectChildFanOut")(function* (input) {
2105
+ const fanOut = yield* Option.match(childFanOutRuntime, {
2106
+ onNone: () => childFanOuts.get(input.fan_out_id),
2107
+ onSome: (runtime) => runtime.inspect(input.fan_out_id)
2108
+ }).pipe(Effect.mapError(toClientError));
2109
+ return { fan_out: fanOut ?? null };
2110
+ }),
1849
2111
  claimEnvelopeReady: Effect.fn("Client.runtime.claimEnvelopeReady")(function* (input) {
1850
2112
  return yield* envelopeReady.claimReady({
1851
2113
  routeType: input.route_type,
@@ -1910,6 +2172,11 @@ var layerFromRuntime = Layer.effect(Service, Effect.gen(function* () {
1910
2172
  }));
1911
2173
  var testLayer = (implementation) => Layer.succeed(Service, Service.of({
1912
2174
  ...implementation,
2175
+ followExecution: implementation.followExecution ?? followExecutionFrom({
2176
+ getExecution: implementation.getExecution,
2177
+ inspectExecution: implementation.inspectExecution,
2178
+ streamExecution: implementation.streamExecution
2179
+ }),
1913
2180
  registerEntityKind: implementation.registerEntityKind ?? ((input) => Effect.succeed(input)),
1914
2181
  getOrCreateEntity: implementation.getOrCreateEntity ?? (() => Effect.fail(new ClientError({ message: "Entity service unavailable" }))),
1915
2182
  getEntity: implementation.getEntity ?? (() => Effect.succeed(undefined)),
@@ -1918,7 +2185,14 @@ var testLayer = (implementation) => Layer.succeed(Service, Service.of({
1918
2185
  streamSession: implementation.streamSession ?? (() => Stream.empty),
1919
2186
  watchExecutions: implementation.watchExecutions ?? (() => Stream.empty),
1920
2187
  getPresence: implementation.getPresence ?? ((scope) => Effect.succeed({ scope, entries: [], observed_at: 0 })),
1921
- watchPresence: implementation.watchPresence ?? (() => Stream.empty)
2188
+ watchPresence: implementation.watchPresence ?? (() => Stream.empty),
2189
+ registerWorkflowDefinition: implementation.registerWorkflowDefinition ?? (() => Effect.die("registerWorkflowDefinition not implemented")),
2190
+ getWorkflowDefinitionRevision: implementation.getWorkflowDefinitionRevision ?? (() => Effect.die("getWorkflowDefinitionRevision not implemented")),
2191
+ listWorkflowDefinitionRevisions: implementation.listWorkflowDefinitionRevisions ?? (() => Effect.die("listWorkflowDefinitionRevisions not implemented")),
2192
+ startWorkflowRun: implementation.startWorkflowRun ?? (() => Effect.die("startWorkflowRun not implemented")),
2193
+ inspectWorkflowRun: implementation.inspectWorkflowRun ?? (() => Effect.die("inspectWorkflowRun not implemented")),
2194
+ replayWorkflowRun: implementation.replayWorkflowRun ?? (() => Effect.die("replayWorkflowRun not implemented")),
2195
+ cancelWorkflowRun: implementation.cancelWorkflowRun ?? (() => Effect.die("cancelWorkflowRun not implemented"))
1922
2196
  }));
1923
2197
  var registerAgentDefinition = Effect.fn("Client.registerAgentDefinition.call")(function* (input) {
1924
2198
  const service = yield* Service;
@@ -2065,6 +2339,7 @@ var send = Effect.fn("Client.send.call")(function* (input) {
2065
2339
  return yield* service.send(input);
2066
2340
  });
2067
2341
  var streamExecution = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.streamExecution(input))));
2342
+ var followExecution = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.followExecution(input))));
2068
2343
  var streamSession = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.streamSession(input))));
2069
2344
  var watchExecutions = (input) => Stream.unwrap(Service.pipe(Effect.map((service) => service.watchExecutions(input))));
2070
2345
  var getPresence = Effect.fn("Client.getPresence.call")(function* (scope) {
@@ -2120,6 +2395,18 @@ var spawnChildRun = Effect.fn("Client.spawnChildRun.call")(function* (input) {
2120
2395
  const service = yield* Service;
2121
2396
  return yield* service.spawnChildRun(input);
2122
2397
  });
2398
+ var createChildFanOut = Effect.fn("Client.createChildFanOut.call")(function* (input) {
2399
+ const service = yield* Service;
2400
+ return yield* service.createChildFanOut(input);
2401
+ });
2402
+ var cancelChildFanOut = Effect.fn("Client.cancelChildFanOut.call")(function* (input) {
2403
+ const service = yield* Service;
2404
+ return yield* service.cancelChildFanOut(input);
2405
+ });
2406
+ var inspectChildFanOut = Effect.fn("Client.inspectChildFanOut.call")(function* (input) {
2407
+ const service = yield* Service;
2408
+ return yield* service.inspectChildFanOut(input);
2409
+ });
2123
2410
  var claimEnvelopeReady = Effect.fn("Client.claimEnvelopeReady.call")(function* (input) {
2124
2411
  const service = yield* Service;
2125
2412
  return yield* service.claimEnvelopeReady(input);
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  __export,
4
4
  exports_model_registry
5
- } from "./index-q0z11q9m.js";
5
+ } from "./index-jy6rpstp.js";
6
6
 
7
7
  // ../ai/src/language-model/language-model-registration.ts
8
8
  var exports_language_model_registration = {};