@relayfx/sdk 0.2.15 → 0.2.16

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 (109) hide show
  1. package/dist/ai.js +2 -2
  2. package/dist/{index-z9xk02sv.js → index-5x686v8w.js} +1782 -1542
  3. package/dist/{index-gxskhyra.js → index-6dv1dqq1.js} +8 -8
  4. package/dist/{index-xbbfagnb.js → index-a6vwwhcp.js} +116 -105
  5. package/dist/{index-d8q4kfjy.js → index-per7tyzq.js} +12 -8
  6. package/dist/index.js +5 -5
  7. package/dist/mysql.js +24 -9
  8. package/dist/postgres.js +18 -13
  9. package/dist/sqlite.js +26 -29
  10. package/dist/types/ai/embedding-model/embedding-model-registration.d.ts +2 -2
  11. package/dist/types/relay/adapter-outbox.d.ts +1 -1
  12. package/dist/types/relay/client.d.ts +28 -28
  13. package/dist/types/relay/command.d.ts +10 -4
  14. package/dist/types/relay/database.d.ts +4 -4
  15. package/dist/types/relay/migration-errors.d.ts +8 -2
  16. package/dist/types/relay/mysql.d.ts +2 -2
  17. package/dist/types/relay/operation.d.ts +126 -126
  18. package/dist/types/relay/postgres.d.ts +2 -2
  19. package/dist/types/relay/runtime-capability-policy.d.ts +11 -5
  20. package/dist/types/relay/runtime-database.d.ts +1 -1
  21. package/dist/types/relay/runtime.d.ts +4 -4
  22. package/dist/types/relay/sqlite-migrations.d.ts +1 -1
  23. package/dist/types/relay/sqlite-runtime.d.ts +10 -5
  24. package/dist/types/relay/tool-worker.d.ts +6 -5
  25. package/dist/types/runtime/address/address-book-service.d.ts +3 -3
  26. package/dist/types/runtime/address/address-resolution-service.d.ts +41 -41
  27. package/dist/types/runtime/agent/agent-loop-service.d.ts +14 -5
  28. package/dist/types/runtime/agent/agent-registry-service.d.ts +2 -2
  29. package/dist/types/runtime/agent/prompt-assembler-service.d.ts +1 -1
  30. package/dist/types/runtime/agent/relay-tool-output.d.ts +4 -1
  31. package/dist/types/runtime/child/child-fan-out-admission-service.d.ts +1 -1
  32. package/dist/types/runtime/child/child-fan-out-runtime.d.ts +12 -8
  33. package/dist/types/runtime/child/child-fan-out-transition-service.d.ts +1 -1
  34. package/dist/types/runtime/child/child-run-service.d.ts +7 -4
  35. package/dist/types/runtime/child/parent-notifier-service.d.ts +4 -2
  36. package/dist/types/runtime/child/spawn-child-run-tool.d.ts +5 -4
  37. package/dist/types/runtime/cluster/execution-entity.d.ts +2 -2
  38. package/dist/types/runtime/content/artifact-store-service.d.ts +2 -2
  39. package/dist/types/runtime/content/blob-store-service.d.ts +1 -1
  40. package/dist/types/runtime/entity/entity-instance-service.d.ts +14 -5
  41. package/dist/types/runtime/entity/entity-registry-service.d.ts +2 -2
  42. package/dist/types/runtime/envelope/envelope-service.d.ts +2 -2
  43. package/dist/types/runtime/execution/active-execution-registry.d.ts +1 -1
  44. package/dist/types/runtime/execution/event-log-service.d.ts +5 -2
  45. package/dist/types/runtime/execution/execution-service.d.ts +1 -1
  46. package/dist/types/runtime/execution/execution-watch-service.d.ts +1 -1
  47. package/dist/types/runtime/execution/session-stream-service.d.ts +1 -1
  48. package/dist/types/runtime/inbox/inbox-service.d.ts +1 -1
  49. package/dist/types/runtime/memory/memory-service.d.ts +1 -1
  50. package/dist/types/runtime/model/embedding-model-service.d.ts +23 -10
  51. package/dist/types/runtime/model/language-model-service.d.ts +19 -6
  52. package/dist/types/runtime/model/model-call-policy.d.ts +1 -1
  53. package/dist/types/runtime/observability/runtime-metrics.d.ts +12 -3
  54. package/dist/types/runtime/presence/presence-service.d.ts +1 -1
  55. package/dist/types/runtime/presence/presence-tool.d.ts +1 -1
  56. package/dist/types/runtime/runner/runner-runtime-service.d.ts +19 -19
  57. package/dist/types/runtime/schedule/scheduler-service.d.ts +3 -3
  58. package/dist/types/runtime/schema-registry/schema-registry-service.d.ts +2 -2
  59. package/dist/types/runtime/session/session-store-service.d.ts +13 -4
  60. package/dist/types/runtime/skill/skill-registry-service.d.ts +2 -2
  61. package/dist/types/runtime/state/execution-state-service.d.ts +5 -2
  62. package/dist/types/runtime/tool/tool-runtime-service.d.ts +42 -19
  63. package/dist/types/runtime/tool/tool-transition-coordinator.d.ts +2 -2
  64. package/dist/types/runtime/topic/topic-service.d.ts +1 -1
  65. package/dist/types/runtime/wait/wait-service.d.ts +1 -1
  66. package/dist/types/runtime/wait/wait-signal.d.ts +12 -3
  67. package/dist/types/runtime/workflow/activity-version-registry.d.ts +7 -3
  68. package/dist/types/runtime/workflow/definition-runtime.d.ts +37 -22
  69. package/dist/types/runtime/workflow/execution-workflow.d.ts +105 -110
  70. package/dist/types/runtime/workspace/workspace-planner-service.d.ts +6 -6
  71. package/dist/types/runtime/workspace/workspace-provider-service.d.ts +11 -7
  72. package/dist/types/runtime/workspace/workspace-runtime-service.d.ts +1 -1
  73. package/dist/types/schema/agent-schema.d.ts +246 -246
  74. package/dist/types/schema/child-orchestration-schema.d.ts +64 -64
  75. package/dist/types/schema/execution-schema.d.ts +57 -57
  76. package/dist/types/schema/workflow-schema.d.ts +243 -243
  77. package/dist/types/schema/workspace-schema.d.ts +1 -1
  78. package/dist/types/store-sql/address/address-book-repository.d.ts +5 -5
  79. package/dist/types/store-sql/agent/agent-definition-repository.d.ts +7 -7
  80. package/dist/types/store-sql/chat/agent-chat-repository.d.ts +2 -2
  81. package/dist/types/store-sql/child/child-execution-repository.d.ts +4 -4
  82. package/dist/types/store-sql/child/child-fan-out-repository.d.ts +2 -2
  83. package/dist/types/store-sql/cluster/cluster-registry-repository.d.ts +5 -5
  84. package/dist/types/store-sql/compaction/compaction-repository.d.ts +3 -3
  85. package/dist/types/store-sql/database/database-service.d.ts +3 -3
  86. package/dist/types/store-sql/database/notification-bus.d.ts +1 -1
  87. package/dist/types/store-sql/database/sql-dialect.d.ts +4 -1
  88. package/dist/types/store-sql/entity/entity-repository.d.ts +2 -2
  89. package/dist/types/store-sql/envelope/envelope-repository.d.ts +13 -13
  90. package/dist/types/store-sql/execution/execution-event-repository.d.ts +4 -4
  91. package/dist/types/store-sql/execution/execution-repository.d.ts +8 -8
  92. package/dist/types/store-sql/idempotency/idempotency-repository.d.ts +5 -5
  93. package/dist/types/store-sql/inbox/inbox-repository.d.ts +1 -1
  94. package/dist/types/store-sql/memory/memory-repository.d.ts +3 -3
  95. package/dist/types/store-sql/permission/permission-rule-repository.d.ts +2 -2
  96. package/dist/types/store-sql/presence/presence-repository.d.ts +2 -2
  97. package/dist/types/store-sql/schedule/schedule-repository.d.ts +9 -9
  98. package/dist/types/store-sql/schema/relay-schema.d.ts +257 -257
  99. package/dist/types/store-sql/session/context-epoch-repository.d.ts +2 -2
  100. package/dist/types/store-sql/session/session-repository.d.ts +5 -5
  101. package/dist/types/store-sql/skill/skill-definition-repository.d.ts +9 -9
  102. package/dist/types/store-sql/state/execution-state-repository.d.ts +2 -2
  103. package/dist/types/store-sql/steering/steering-repository.d.ts +5 -5
  104. package/dist/types/store-sql/tenant/tenant-id.d.ts +2 -2
  105. package/dist/types/store-sql/tool/tool-call-repository.d.ts +19 -16
  106. package/dist/types/store-sql/topic/topic-repository.d.ts +1 -1
  107. package/dist/types/store-sql/workflow/workflow-definition-repository.d.ts +16 -14
  108. package/dist/types/store-sql/workspace/workspace-lease-repository.d.ts +11 -11
  109. package/package.json +3 -3
@@ -52,7 +52,7 @@ import {
52
52
  exports_wait_service,
53
53
  exports_wait_signal,
54
54
  exports_workflow_definition_repository
55
- } from "./index-z9xk02sv.js";
55
+ } from "./index-5x686v8w.js";
56
56
 
57
57
  // src/operation.ts
58
58
  var exports_operation = {};
@@ -702,8 +702,8 @@ __export(exports_command, {
702
702
  CommandTimedOut: () => CommandTimedOut,
703
703
  CommandReplyInvalid: () => CommandReplyInvalid
704
704
  });
705
- import { Schema as Schema2 } from "effect";
706
- var make = (name, options) => ({ name, ...options });
705
+ import { Function, Schema as Schema2 } from "effect";
706
+ var make = Function.dual(2, (name, options) => ({ name, ...options }));
707
707
  var inputSchemaRef = (name) => `relay/command/${name}/input`;
708
708
  var outputSchemaRef = (name) => `relay/command/${name}/output`;
709
709
 
@@ -805,10 +805,10 @@ __export(exports_client, {
805
805
  EntityNamespaceReserved: () => EntityNamespaceReserved,
806
806
  ClientError: () => ClientError
807
807
  });
808
- import { Clock, Context as Context2, Effect as Effect2, Layer as Layer2, Option, Schema as Schema4, SchemaGetter, SchemaIssue, Stream } from "effect";
808
+ import { Clock, Context as Context2, Effect as Effect2, Layer as Layer2, Option, Random, Schema as Schema4, SchemaGetter, SchemaIssue, Stream } from "effect";
809
809
  import { EntityId, ShardId, Sharding, ShardingConfig } from "effect/unstable/cluster";
810
810
  // src/runtime-capability-policy.ts
811
- import { Context, Effect, Layer, Schema as Schema3 } from "effect";
811
+ import { Context, Effect, Function as Function2, Layer, Schema as Schema3 } from "effect";
812
812
 
813
813
  class RuntimeCapabilityUnavailable extends Schema3.TaggedErrorClass()("RuntimeCapabilityUnavailable", {
814
814
  capability: Schema3.Literals(["fan-out", "workflow-definition"]),
@@ -817,18 +817,18 @@ class RuntimeCapabilityUnavailable extends Schema3.TaggedErrorClass()("RuntimeCa
817
817
  }) {
818
818
  }
819
819
 
820
- class Service extends Context.Service()("@relayfx/sdk/RuntimeCapabilityPolicy") {
820
+ class Service extends Context.Service()("@relayfx/sdk/runtime-capability-policy/Service") {
821
821
  }
822
- var layer = (role, capabilities) => Layer.succeed(Service, {
822
+ var layer = Function2.dual(2, (role, capabilities) => Layer.succeed(Service, {
823
823
  admit: (capability) => {
824
824
  const enabled = capability === "fan-out" ? capabilities.fanOut : capabilities.workflowDefinition;
825
- return enabled ? Effect.void : Effect.fail(new RuntimeCapabilityUnavailable({
825
+ return enabled ? Effect.void : Effect.fail(RuntimeCapabilityUnavailable.make({
826
826
  capability,
827
827
  role,
828
828
  nextAction: role === "embedded" ? "enable-embedded-capability" : "use-embedded-runtime"
829
829
  }));
830
830
  }
831
- });
831
+ }));
832
832
 
833
833
  // src/client.ts
834
834
  class ClientError extends Schema4.TaggedErrorClass()("ClientError", {
@@ -852,7 +852,7 @@ class WaitKindMismatch extends Schema4.TaggedErrorClass()("WaitKindMismatch", {
852
852
  }) {
853
853
  }
854
854
 
855
- class Service2 extends Context2.Service()("@relayfx/sdk/Client") {
855
+ class Service2 extends Context2.Service()("@relayfx/sdk/client/Service") {
856
856
  }
857
857
  var followTerminalStatus = (type) => type === "execution.completed" ? "completed" : type === "execution.failed" ? "failed" : type === "execution.cancelled" ? "cancelled" : undefined;
858
858
  var followReconnectDelayMillis = (attempt) => Math.min(100 * 2 ** (attempt - 1), 5000);
@@ -864,7 +864,7 @@ var followStopped = (reason, cursor) => ({
864
864
  var followExecutionFrom = (dependencies) => (input) => {
865
865
  const maxReconnects = input.max_reconnects ?? 10;
866
866
  const stopModes = input.stop_on_wait_modes;
867
- const inspect = Effect2.suspend(() => dependencies.inspectExecution(input.execution_id)).pipe(Effect2.catchTag("ExecutionNotFound", (error) => new ClientError({ message: `execution ${error.execution_id} not found` })));
867
+ const inspect = Effect2.suspend(() => dependencies.inspectExecution(input.execution_id)).pipe(Effect2.catchTag("ExecutionNotFound", (error) => ClientError.make({ message: `execution ${error.execution_id} not found` })));
868
868
  const reconcile = (state, message) => Stream.unwrap(Effect2.gen(function* () {
869
869
  const inspection = yield* inspect;
870
870
  const terminal = followTerminalStatus(`execution.${inspection.status}`);
@@ -876,7 +876,7 @@ var followExecutionFrom = (dependencies) => (input) => {
876
876
  return Stream.make(followStopped({ _tag: "actionable_wait", wait: actionable }, state.cursor));
877
877
  }
878
878
  if (state.attempts >= maxReconnects) {
879
- return Stream.fail(new ClientError({
879
+ return Stream.fail(ClientError.make({
880
880
  message: `follow of ${input.execution_id} exhausted ${maxReconnects} reconnects: ${message}`
881
881
  }));
882
882
  }
@@ -900,7 +900,7 @@ var followExecutionFrom = (dependencies) => (input) => {
900
900
  if (stopModes !== undefined && event.type === "wait.created") {
901
901
  const mode = event.data?.mode;
902
902
  if (typeof mode === "string" && stopModes.includes(mode)) {
903
- const inspection = yield* dependencies.inspectExecution(input.execution_id).pipe(Effect2.catchTag("ExecutionNotFound", () => Effect2.succeed(undefined)));
903
+ const inspection = yield* dependencies.inspectExecution(input.execution_id).pipe(Effect2.catchTag("ExecutionNotFound", () => Effect2.void));
904
904
  const actionable = inspection?.waiting_on.find((wait) => wait.state === "open" && wait.wait_id === event.data?.wait_id);
905
905
  if (actionable !== undefined) {
906
906
  items.push(followStopped({ _tag: "actionable_wait", wait: actionable }, state.cursor));
@@ -916,7 +916,7 @@ var followExecutionFrom = (dependencies) => (input) => {
916
916
  return Stream.unwrap(Effect2.gen(function* () {
917
917
  const existing = yield* dependencies.getExecution(input.execution_id);
918
918
  if (existing === undefined) {
919
- return Stream.fail(new ClientError({ message: `execution ${input.execution_id} not found` }));
919
+ return Stream.fail(ClientError.make({ message: `execution ${input.execution_id} not found` }));
920
920
  }
921
921
  const state = {
922
922
  cursor: input.after_cursor,
@@ -938,8 +938,8 @@ var errorMessage = (error) => {
938
938
  }
939
939
  return String(error);
940
940
  };
941
- var toClientError = (error) => new ClientError({ message: errorMessage(error) });
942
- var rejectReserved = (id, prefix) => id.startsWith(prefix) ? Effect2.fail(new EntityNamespaceReserved({ id, message: "start entities via Client.getOrCreateEntity" })) : Effect2.void;
941
+ var toClientError = (error) => ClientError.make({ message: errorMessage(error) });
942
+ var rejectReserved = (id, prefix) => id.startsWith(prefix) ? Effect2.fail(EntityNamespaceReserved.make({ id, message: "start entities via Client.getOrCreateEntity" })) : Effect2.void;
943
943
  var replyValueFrom = (content) => {
944
944
  if (content === undefined || content.length === 0)
945
945
  return Option.none();
@@ -1087,9 +1087,9 @@ var modelSelectionFromBatonAgent = (selection) => ({
1087
1087
  model: selection.model,
1088
1088
  ...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
1089
1089
  });
1090
- var decodeBatonAgentName = (name) => Schema4.decodeUnknownEffect(exports_shared_schema.NonEmptyString)(name).pipe(Effect2.mapError(() => new ClientError({ message: "Baton agent name must not be blank" })));
1091
- var decodeBatonAgentMetadata = (metadata) => metadata === undefined ? Effect2.succeed(undefined) : Schema4.decodeUnknownEffect(exports_shared_schema.Metadata)(metadata).pipe(Effect2.mapError(() => new ClientError({ message: "Baton agent metadata must be JSON metadata" })));
1092
- var decodeBatonMemorySubject = (subject) => Schema4.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect2.mapError(() => new ClientError({ message: "Baton agent memory subject must be a MemorySubjectId" })));
1090
+ var decodeBatonAgentName = (name) => Schema4.decodeUnknownEffect(exports_shared_schema.NonEmptyString)(name).pipe(Effect2.mapError(() => ClientError.make({ message: "Baton agent name must not be blank" })));
1091
+ 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" })));
1092
+ var decodeBatonMemorySubject = (subject) => Schema4.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect2.mapError(() => ClientError.make({ message: "Baton agent memory subject must be a MemorySubjectId" })));
1093
1093
  var metadataFromBatonAgent = Effect2.fn("Client.metadataFromBatonAgent")(function* (input) {
1094
1094
  const agentMetadata = yield* decodeBatonAgentMetadata(input.agent.metadata);
1095
1095
  const memorySubject = input.agent.memory === undefined ? undefined : yield* decodeBatonMemorySubject(input.agent.memory.subject);
@@ -1105,32 +1105,32 @@ var modelSelectionFromRegisterInput = (input) => {
1105
1105
  return Effect2.succeed(input.model);
1106
1106
  if (input.agent.model !== undefined)
1107
1107
  return Effect2.succeed(modelSelectionFromBatonAgent(input.agent.model));
1108
- return Effect2.fail(new ClientError({ message: "Client.registerAgent requires model or agent.model" }));
1108
+ return Effect2.fail(ClientError.make({ message: "Client.registerAgent requires model or agent.model" }));
1109
1109
  };
1110
- var batonTurnPolicyInvalid = (detail) => new ClientError({ message: `Baton agent turn policy is not durably portable: ${detail}` });
1110
+ var batonTurnPolicyInvalid = (detail) => ClientError.make({ message: `Baton agent turn policy is not durably portable: ${detail}` });
1111
1111
  var turnPolicySnapshotFromBaton = Effect2.fn("Client.turnPolicySnapshotFromBaton")(function* (snapshot) {
1112
1112
  let nodes = 0;
1113
1113
  const visit = (current, depth) => Effect2.gen(function* () {
1114
1114
  if (typeof current !== "object" || current === null || Array.isArray(current)) {
1115
- return yield* Effect2.fail(batonTurnPolicyInvalid("snapshot nodes must be objects"));
1115
+ return yield* batonTurnPolicyInvalid("snapshot nodes must be objects");
1116
1116
  }
1117
1117
  const node = current;
1118
1118
  nodes += 1;
1119
1119
  if (depth > exports_agent_schema.maxTurnPolicySnapshotDepth) {
1120
- return yield* Effect2.fail(batonTurnPolicyInvalid(`depth exceeds ${exports_agent_schema.maxTurnPolicySnapshotDepth}`));
1120
+ return yield* batonTurnPolicyInvalid(`depth exceeds ${exports_agent_schema.maxTurnPolicySnapshotDepth}`);
1121
1121
  }
1122
1122
  if (nodes > exports_agent_schema.maxTurnPolicySnapshotNodes) {
1123
- return yield* Effect2.fail(batonTurnPolicyInvalid(`node count exceeds ${exports_agent_schema.maxTurnPolicySnapshotNodes}`));
1123
+ return yield* batonTurnPolicyInvalid(`node count exceeds ${exports_agent_schema.maxTurnPolicySnapshotNodes}`);
1124
1124
  }
1125
1125
  switch (node._tag) {
1126
1126
  case "Recurs":
1127
1127
  if (typeof node.count !== "number" || !Number.isInteger(node.count) || node.count < 0) {
1128
- return yield* Effect2.fail(batonTurnPolicyInvalid("recurs count must be a non-negative integer"));
1128
+ return yield* batonTurnPolicyInvalid("recurs count must be a non-negative integer");
1129
1129
  }
1130
1130
  return { kind: "recurs", count: node.count };
1131
1131
  case "UntilToolCall":
1132
1132
  if (typeof node.name !== "string" || node.name.trim().length === 0) {
1133
- return yield* Effect2.fail(batonTurnPolicyInvalid("until-tool-call name must not be blank"));
1133
+ return yield* batonTurnPolicyInvalid("until-tool-call name must not be blank");
1134
1134
  }
1135
1135
  return { kind: "until-tool-call", name: node.name };
1136
1136
  case "Both":
@@ -1140,7 +1140,7 @@ var turnPolicySnapshotFromBaton = Effect2.fn("Client.turnPolicySnapshotFromBaton
1140
1140
  second: yield* visit(node.second, depth + 1)
1141
1141
  };
1142
1142
  default:
1143
- return yield* Effect2.fail(batonTurnPolicyInvalid("snapshot tag is not recognized"));
1143
+ return yield* batonTurnPolicyInvalid("snapshot tag is not recognized");
1144
1144
  }
1145
1145
  });
1146
1146
  return yield* visit(snapshot, 1);
@@ -1150,7 +1150,7 @@ var turnPolicyFieldsFromRegisterInput = Effect2.fn("Client.turnPolicyFieldsFromR
1150
1150
  return { max_tool_turns: input.max_tool_turns };
1151
1151
  const snapshot = input.agent.policy.snapshot;
1152
1152
  if (snapshot === undefined) {
1153
- return yield* Effect2.fail(batonTurnPolicyInvalid("opaque policies require an explicit max_tool_turns replacement"));
1153
+ return yield* batonTurnPolicyInvalid("opaque policies require an explicit max_tool_turns replacement");
1154
1154
  }
1155
1155
  const durable = yield* turnPolicySnapshotFromBaton(snapshot);
1156
1156
  if (durable.kind === "recurs" && durable.count === 8)
@@ -1243,19 +1243,19 @@ var resolveToolOutcomeWait = Effect2.fn("Client.resolveToolOutcomeWait")(functio
1243
1243
  const waitId = call.waitId ?? toolWaitId(call.call.id);
1244
1244
  const wait = yield* waits.get(waitId).pipe(Effect2.mapError(toClientError));
1245
1245
  if (wait === undefined)
1246
- return yield* new ClientError({ message: `Tool wait not found: ${waitId}` });
1246
+ return yield* ClientError.make({ message: `Tool wait not found: ${waitId}` });
1247
1247
  if (wait.executionId !== call.executionId) {
1248
- return yield* new ClientError({ message: `Tool wait does not match call: ${call.call.id}` });
1248
+ return yield* ClientError.make({ message: `Tool wait does not match call: ${call.call.id}` });
1249
1249
  }
1250
1250
  if (wait.state === "resolved") {
1251
1251
  const accepted = yield* acceptedWaitOutcome(wait);
1252
1252
  if (exports_shared_schema.canonicalString(accepted) !== exports_shared_schema.canonicalString(outcome)) {
1253
- return yield* new ClientError({ message: `Tool outcome conflicts with accepted wait: ${call.call.id}` });
1253
+ return yield* ClientError.make({ message: `Tool outcome conflicts with accepted wait: ${call.call.id}` });
1254
1254
  }
1255
1255
  return wait;
1256
1256
  }
1257
1257
  if (wait.state !== "open") {
1258
- return yield* new ClientError({ message: `Tool wait is ${wait.state}: ${call.call.id}` });
1258
+ return yield* ClientError.make({ message: `Tool wait is ${wait.state}: ${call.call.id}` });
1259
1259
  }
1260
1260
  const eventSequence = yield* nextEventSequence(eventLog, call.executionId);
1261
1261
  const resolved = yield* waits.wake({
@@ -1267,19 +1267,19 @@ var resolveToolOutcomeWait = Effect2.fn("Client.resolveToolOutcomeWait")(functio
1267
1267
  if (!resolved.transitioned) {
1268
1268
  const accepted = yield* acceptedWaitOutcome(resolved.wait);
1269
1269
  if (exports_shared_schema.canonicalString(accepted) !== exports_shared_schema.canonicalString(outcome)) {
1270
- return yield* new ClientError({ message: `Tool outcome conflicts with accepted wait: ${call.call.id}` });
1270
+ return yield* ClientError.make({ message: `Tool outcome conflicts with accepted wait: ${call.call.id}` });
1271
1271
  }
1272
1272
  }
1273
1273
  return resolved.wait;
1274
1274
  });
1275
1275
  var signalToolOutcome = Effect2.fn("Client.signalToolOutcome")(function* (executionRepository, makeExecutionClient, wait, signaledAt) {
1276
- yield* exports_wait_signal.signalWorkflowWait({
1277
- makeExecutionClient,
1276
+ yield* Effect2.mapError(Effect2.orDie(exports_wait_signal.signalWorkflowWait({
1277
+ makeExecutionClient: typedWaitSignalClient(makeExecutionClient),
1278
1278
  executionId: wait.executionId,
1279
1279
  waitId: wait.id,
1280
1280
  state: "resolved",
1281
1281
  signaledAt
1282
- }).pipe(Effect2.provideService(exports_execution_repository.Service, executionRepository), Effect2.mapError(toClientError));
1282
+ }).pipe(Effect2.provideService(exports_execution_repository.Service, executionRepository))), toClientError);
1283
1283
  });
1284
1284
  var toReady = (record) => ({
1285
1285
  id: record.id,
@@ -1294,6 +1294,12 @@ var toLease = (record) => ({
1294
1294
  worker_id: record.claimOwner ?? "unclaimed",
1295
1295
  claim_expires_at: record.claimExpiresAt ?? record.updatedAt
1296
1296
  });
1297
+ var typedWaitSignalClient = (makeExecutionClient) => (executionId) => {
1298
+ const client = makeExecutionClient(executionId);
1299
+ return {
1300
+ signalWait: (input) => client.signalWait(input).pipe(Effect2.mapError((error) => exports_wait_signal.WaitSignalError.make({ message: String(error) })))
1301
+ };
1302
+ };
1297
1303
  var nextEventSequence = Effect2.fn("Client.nextEventSequence")(function* (eventLog, executionId) {
1298
1304
  const max = yield* eventLog.maxSequence(executionId).pipe(Effect2.mapError(toClientError));
1299
1305
  return max === undefined ? 0 : max + 1;
@@ -1306,10 +1312,10 @@ var terminalChildStatus = (metadata) => {
1306
1312
  var wakeRuntime = Effect2.fn("Client.wakeRuntime")(function* (waits, eventLog, executionRepository, makeExecutionClient, input, accepts) {
1307
1313
  const wait = yield* waits.get(input.wait_id).pipe(Effect2.mapError(toClientError));
1308
1314
  if (wait === undefined)
1309
- return yield* new ClientError({ message: `Wait not found: ${input.wait_id}` });
1315
+ return yield* ClientError.make({ message: `Wait not found: ${input.wait_id}` });
1310
1316
  const kind = waitSemanticKind(wait);
1311
1317
  if (accepts !== undefined && kind !== accepts) {
1312
- return yield* new WaitKindMismatch({
1318
+ return yield* WaitKindMismatch.make({
1313
1319
  wait_id: input.wait_id,
1314
1320
  expected: accepts,
1315
1321
  actual: kind,
@@ -1317,7 +1323,7 @@ var wakeRuntime = Effect2.fn("Client.wakeRuntime")(function* (waits, eventLog, e
1317
1323
  });
1318
1324
  }
1319
1325
  if (accepts === undefined && kind === "child" && !terminalChildStatus(input.metadata)) {
1320
- return yield* new WaitKindMismatch({
1326
+ return yield* WaitKindMismatch.make({
1321
1327
  wait_id: input.wait_id,
1322
1328
  expected: 'child wake with terminal metadata.child_status ("completed" | "failed" | "cancelled")',
1323
1329
  actual: kind,
@@ -1325,7 +1331,7 @@ var wakeRuntime = Effect2.fn("Client.wakeRuntime")(function* (waits, eventLog, e
1325
1331
  });
1326
1332
  }
1327
1333
  if (input.state === "cancelled" && wait.metadata.kind === "tool-placement") {
1328
- return yield* new ClientError({ message: "Tool placement waits must be cancelled through cancelExecution" });
1334
+ return yield* ClientError.make({ message: "Tool placement waits must be cancelled through cancelExecution" });
1329
1335
  }
1330
1336
  const eventSequence = yield* nextEventSequence(eventLog, wait.executionId);
1331
1337
  const result = input.state === "resolved" ? yield* waits.wake({
@@ -1345,13 +1351,13 @@ var wakeRuntime = Effect2.fn("Client.wakeRuntime")(function* (waits, eventLog, e
1345
1351
  metadata: wakeMetadata(input)
1346
1352
  }).pipe(Effect2.mapError(toClientError));
1347
1353
  if (result.transitioned) {
1348
- yield* exports_wait_signal.signalWorkflowWait({
1349
- makeExecutionClient,
1354
+ yield* Effect2.mapError(Effect2.orDie(exports_wait_signal.signalWorkflowWait({
1355
+ makeExecutionClient: typedWaitSignalClient(makeExecutionClient),
1350
1356
  executionId: result.wait.executionId,
1351
1357
  waitId: result.wait.id,
1352
1358
  state: input.state,
1353
1359
  signaledAt: input.signaled_at
1354
- }).pipe(Effect2.provideService(exports_execution_repository.Service, executionRepository), Effect2.mapError(toClientError));
1360
+ }).pipe(Effect2.provideService(exports_execution_repository.Service, executionRepository))), toClientError);
1355
1361
  }
1356
1362
  return {
1357
1363
  wait_id: result.wait.id,
@@ -1420,20 +1426,20 @@ var reconcileExistingChildSpawn = Effect2.fn("Client.reconcileExistingChildSpawn
1420
1426
  if (existing === undefined)
1421
1427
  return;
1422
1428
  if (existing.executionId !== input.execution_id || existing.addressId !== input.address_id || childSpawnFingerprint(existing) !== exports_shared_schema.canonicalString(input)) {
1423
- return yield* new ClientError({ message: `Child execution conflicts: ${childExecutionId}` });
1429
+ return yield* ClientError.make({ message: `Child execution conflicts: ${childExecutionId}` });
1424
1430
  }
1425
1431
  const spawned = yield* eventLog.findByCursor({
1426
1432
  executionId: input.execution_id,
1427
1433
  cursor: `${input.execution_id}:child:${childExecutionId}:spawned`
1428
1434
  }).pipe(Effect2.mapError(toClientError));
1429
1435
  if (Option.isNone(spawned)) {
1430
- return yield* new ClientError({ message: `Child spawn event missing: ${childExecutionId}` });
1436
+ return yield* ClientError.make({ message: `Child spawn event missing: ${childExecutionId}` });
1431
1437
  }
1432
1438
  const parentWaitId = input.wait === true ? childJoinWaitId(childExecutionId) : undefined;
1433
1439
  if (parentWaitId !== undefined) {
1434
1440
  const wait = yield* waits.get(parentWaitId).pipe(Effect2.mapError(toClientError));
1435
1441
  if (wait === undefined) {
1436
- return yield* new ClientError({ message: `Child join wait missing: ${childExecutionId}` });
1442
+ return yield* ClientError.make({ message: `Child join wait missing: ${childExecutionId}` });
1437
1443
  }
1438
1444
  }
1439
1445
  return {
@@ -1445,10 +1451,10 @@ var reconcileExistingChildSpawn = Effect2.fn("Client.reconcileExistingChildSpawn
1445
1451
  var parentDefinitionPin = Effect2.fn("Client.parentDefinitionPin")(function* (executionRepository, executionId) {
1446
1452
  const record = yield* executionRepository.get(executionId).pipe(Effect2.mapError(toClientError));
1447
1453
  if (record === undefined) {
1448
- return yield* new ClientError({ message: `Execution not found: ${executionId}` });
1454
+ return yield* ClientError.make({ message: `Execution not found: ${executionId}` });
1449
1455
  }
1450
1456
  if (record.agentId === undefined || record.agentRevision === undefined || record.agentSnapshot === undefined) {
1451
- return yield* new ClientError({ message: `Parent execution is not pinned to an agent: ${executionId}` });
1457
+ return yield* ClientError.make({ message: `Parent execution is not pinned to an agent: ${executionId}` });
1452
1458
  }
1453
1459
  return {
1454
1460
  agentId: record.agentId,
@@ -1515,12 +1521,12 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1515
1521
  if (Option.isSome(childFanOutRuntime)) {
1516
1522
  const fanOut = yield* childFanOutRuntime.value.cancel(input.fan_out_id, input.cancelled_at, input.reason ?? "child fan-out cancelled").pipe(Effect2.mapError(toClientError));
1517
1523
  if (fanOut === undefined)
1518
- return yield* new ClientError({ message: `Child fan-out not found: ${input.fan_out_id}` });
1524
+ return yield* ClientError.make({ message: `Child fan-out not found: ${input.fan_out_id}` });
1519
1525
  return { fan_out: fanOut };
1520
1526
  }
1521
1527
  const result = yield* childFanOuts.cancel(input.fan_out_id, input.cancelled_at).pipe(Effect2.mapError(toClientError));
1522
1528
  if (result === undefined)
1523
- return yield* new ClientError({ message: `Child fan-out not found: ${input.fan_out_id}` });
1529
+ return yield* ClientError.make({ message: `Child fan-out not found: ${input.fan_out_id}` });
1524
1530
  yield* Effect2.forEach(result.activeChildExecutionIds, (childId) => makeExecutionClient(exports_ids_schema.ExecutionId.make(childId)).cancel({
1525
1531
  execution_id: exports_ids_schema.ExecutionId.make(childId),
1526
1532
  cancelled_at: input.cancelled_at,
@@ -1566,14 +1572,14 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1566
1572
  const awaitWaitOperation = Effect2.fn("Client.runtime.awaitWait")(function* (input) {
1567
1573
  const current = yield* envelopeReady.getWait(input.wait_id).pipe(Effect2.mapError(toClientError));
1568
1574
  if (current === undefined) {
1569
- return yield* new ClientError({ message: `wait ${input.wait_id} not found` });
1575
+ return yield* ClientError.make({ message: `wait ${input.wait_id} not found` });
1570
1576
  }
1571
1577
  if (current.state !== "open")
1572
1578
  return yield* waitOutcomeFrom(current);
1573
1579
  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));
1574
1580
  const terminal = yield* envelopeReady.getWait(input.wait_id).pipe(Effect2.mapError(toClientError));
1575
1581
  if (terminal === undefined || terminal.state === "open") {
1576
- return yield* new ClientError({ message: `wait ${input.wait_id} did not reach a terminal state` });
1582
+ return yield* ClientError.make({ message: `wait ${input.wait_id} did not reach a terminal state` });
1577
1583
  }
1578
1584
  return yield* waitOutcomeFrom(terminal);
1579
1585
  });
@@ -1589,7 +1595,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1589
1595
  const inspectExecutionOperation = Effect2.fn("Client.runtime.inspectExecution")(function* (executionId) {
1590
1596
  const execution = yield* executionRepository.get(executionId).pipe(Effect2.mapError(toClientError));
1591
1597
  if (execution === undefined)
1592
- return yield* new ExecutionNotFound({ execution_id: executionId });
1598
+ return yield* ExecutionNotFound.make({ execution_id: executionId });
1593
1599
  const openWaits = yield* envelopeReady.listAllWaits({ executionId, state: "open" }).pipe(Effect2.mapError(toClientError));
1594
1600
  const calls = yield* toolCalls.listCalls(executionId).pipe(Effect2.mapError(toClientError));
1595
1601
  const pendingChunks = yield* Effect2.forEach(calls, (call) => toolCalls.getResult(call.call.id).pipe(Effect2.mapError(toClientError), Effect2.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
@@ -1676,8 +1682,8 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1676
1682
  getAgentDefinition: Effect2.fn("Client.runtime.getAgentDefinition")(function* (id) {
1677
1683
  return yield* agentRegistry.get(id).pipe(Effect2.mapError(toClientError));
1678
1684
  }),
1679
- listAgentDefinitions: Effect2.fn("Client.runtime.listAgentDefinitions")(function* () {
1680
- return yield* agentRegistry.list().pipe(Effect2.mapError(toClientError));
1685
+ listAgentDefinitions: Effect2.fn("Client.runtime.listAgentDefinitions")(function* (_) {
1686
+ return yield* agentRegistry.list.pipe(Effect2.mapError(toClientError));
1681
1687
  }),
1682
1688
  listAgentDefinitionRevisions: Effect2.fn("Client.runtime.listAgentDefinitionRevisions")(function* (id) {
1683
1689
  return yield* agentRegistry.listRevisions(id).pipe(Effect2.mapError(toClientError));
@@ -1685,8 +1691,8 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1685
1691
  getSkillDefinition: Effect2.fn("Client.runtime.getSkillDefinition")(function* (id) {
1686
1692
  return yield* skillRegistry.get(id).pipe(Effect2.mapError(toClientError));
1687
1693
  }),
1688
- listSkillDefinitions: Effect2.fn("Client.runtime.listSkillDefinitions")(function* () {
1689
- return yield* skillRegistry.list().pipe(Effect2.mapError(toClientError));
1694
+ listSkillDefinitions: Effect2.fn("Client.runtime.listSkillDefinitions")(function* (_) {
1695
+ return yield* skillRegistry.list.pipe(Effect2.mapError(toClientError));
1690
1696
  }),
1691
1697
  listSkillDefinitionRevisions: Effect2.fn("Client.runtime.listSkillDefinitionRevisions")(function* (id) {
1692
1698
  return yield* skillRegistry.listRevisions(id).pipe(Effect2.mapError(toClientError));
@@ -1698,8 +1704,8 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1698
1704
  getAddressBookRoute: Effect2.fn("Client.runtime.getAddressBookRoute")(function* (id) {
1699
1705
  return yield* addressBook.get(id).pipe(Effect2.mapError(toClientError));
1700
1706
  }),
1701
- listAddressBookRoutes: Effect2.fn("Client.runtime.listAddressBookRoutes")(function* () {
1702
- return yield* addressBook.list().pipe(Effect2.mapError(toClientError));
1707
+ listAddressBookRoutes: Effect2.fn("Client.runtime.listAddressBookRoutes")(function* (_) {
1708
+ return yield* addressBook.list.pipe(Effect2.mapError(toClientError));
1703
1709
  }),
1704
1710
  startExecution: Effect2.fn("Client.runtime.startExecution")(function* (input) {
1705
1711
  yield* rejectReserved(input.execution_id, "execution:entity:");
@@ -1726,7 +1732,9 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1726
1732
  yield* rejectReserved(input.session_id, "session:entity:");
1727
1733
  const definition = yield* agentRegistry.getRevision({ id: input.agent_id, revision: input.agent_revision }).pipe(Effect2.mapError(toClientError));
1728
1734
  if (definition === undefined) {
1729
- return yield* Effect2.fail(new ClientError({ message: `Agent revision not found: ${input.agent_id}@${input.agent_revision}` }));
1735
+ return yield* ClientError.make({
1736
+ message: `Agent revision not found: ${input.agent_id}@${input.agent_revision}`
1737
+ });
1730
1738
  }
1731
1739
  const payload = startExecutionByAgentDefinitionPayload(input, definition);
1732
1740
  const client = makeExecutionClient(payload.execution_id);
@@ -1749,10 +1757,10 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1749
1757
  steer: Effect2.fn("Client.runtime.steer")(function* (input) {
1750
1758
  const execution = yield* executionRepository.get(input.execution_id).pipe(Effect2.mapError(toClientError));
1751
1759
  if (execution === undefined) {
1752
- return yield* new ClientError({ message: `Execution not found: ${input.execution_id}` });
1760
+ return yield* ClientError.make({ message: `Execution not found: ${input.execution_id}` });
1753
1761
  }
1754
1762
  if (execution.status !== "running") {
1755
- return yield* new ClientError({ message: `Execution is not running: ${input.execution_id}` });
1763
+ return yield* ClientError.make({ message: `Execution is not running: ${input.execution_id}` });
1756
1764
  }
1757
1765
  const record = yield* steering.appendForRunning({
1758
1766
  executionId: input.execution_id,
@@ -1778,19 +1786,19 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1778
1786
  return records.map(toWaitView);
1779
1787
  }),
1780
1788
  listExecutions: Effect2.fn("Client.runtime.listExecutions")(function* (input) {
1781
- const cursor = input.cursor === undefined ? undefined : yield* Schema4.decodeEffect(ExecutionCursorFromString)(input.cursor).pipe(Effect2.mapError(toClientError));
1789
+ const cursor = input.cursor === undefined ? undefined : yield* Schema4.decodeEffect(ExecutionCursorFromString)(input.cursor);
1782
1790
  const result = yield* executionRepository.list({
1783
1791
  ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
1784
1792
  ...input.status === undefined ? {} : { status: input.status },
1785
1793
  ...input.limit === undefined ? {} : { limit: input.limit },
1786
1794
  ...cursor === undefined ? {} : { cursor }
1787
- }).pipe(Effect2.mapError(toClientError));
1788
- const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema4.encodeEffect(ExecutionCursorFromString)(result.nextCursor).pipe(Effect2.mapError(toClientError));
1795
+ });
1796
+ const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema4.encodeEffect(ExecutionCursorFromString)(result.nextCursor);
1789
1797
  return {
1790
1798
  records: result.records.map(toConversationSummary),
1791
1799
  ...nextCursor === undefined ? {} : { next_cursor: nextCursor }
1792
1800
  };
1793
- }),
1801
+ }, Effect2.mapError(toClientError)),
1794
1802
  subscribeTopic: Effect2.fn("Client.runtime.subscribeTopic")(function* (input) {
1795
1803
  return yield* topicService.subscribe({
1796
1804
  topicAddressId: input.topic_address_id,
@@ -1828,22 +1836,22 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1828
1836
  }).pipe(Effect2.mapError(toClientError));
1829
1837
  }),
1830
1838
  listSessions: Effect2.fn("Client.runtime.listSessions")(function* (input) {
1831
- const cursor = input.cursor === undefined ? undefined : yield* Schema4.decodeEffect(SessionCursorFromString)(input.cursor).pipe(Effect2.mapError(toClientError));
1839
+ const cursor = input.cursor === undefined ? undefined : yield* Schema4.decodeEffect(SessionCursorFromString)(input.cursor);
1832
1840
  const result = yield* sessionRepository.list({
1833
1841
  ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
1834
1842
  ...input.limit === undefined ? {} : { limit: input.limit },
1835
1843
  ...cursor === undefined ? {} : { cursor }
1836
- }).pipe(Effect2.mapError(toClientError));
1837
- const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema4.encodeEffect(SessionCursorFromString)(result.nextCursor).pipe(Effect2.mapError(toClientError));
1844
+ });
1845
+ const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema4.encodeEffect(SessionCursorFromString)(result.nextCursor);
1838
1846
  return {
1839
1847
  records: result.records.map(toSessionSummary),
1840
1848
  ...nextCursor === undefined ? {} : { next_cursor: nextCursor }
1841
1849
  };
1842
- }),
1850
+ }, Effect2.mapError(toClientError)),
1843
1851
  getSession: Effect2.fn("Client.runtime.getSession")(function* (input) {
1844
1852
  const session = yield* sessionRepository.get(input.session_id).pipe(Effect2.mapError(toClientError));
1845
1853
  if (session === undefined)
1846
- return yield* new ClientError({ message: `Session not found: ${input.session_id}` });
1854
+ return yield* ClientError.make({ message: `Session not found: ${input.session_id}` });
1847
1855
  const cursor = input.cursor === undefined ? undefined : yield* Schema4.decodeEffect(ExecutionCursorFromString)(input.cursor).pipe(Effect2.mapError(toClientError));
1848
1856
  const result = yield* executionRepository.list({
1849
1857
  sessionId: input.session_id,
@@ -1865,7 +1873,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1865
1873
  }).pipe(Effect2.mapError(toClientError));
1866
1874
  return { events };
1867
1875
  }),
1868
- listRunners: Effect2.fn("Client.runtime.listRunners")(function* () {
1876
+ listRunners: Effect2.fn("Client.runtime.listRunners")(function* (_) {
1869
1877
  const runners = yield* clusterRegistry.listRunners().pipe(Effect2.mapError(toClientError));
1870
1878
  return {
1871
1879
  runners: runners.map((runner) => ({
@@ -1893,7 +1901,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1893
1901
  askEntity: Effect2.fn("Client.runtime.askEntity")(function* (input) {
1894
1902
  const instance = yield* entities.get({ kind: input.kind, key: input.key }).pipe(Effect2.mapError(toClientError));
1895
1903
  if (instance === undefined || instance.status === "destroyed") {
1896
- return yield* new EntityNotFound({ kind: input.kind, key: input.key });
1904
+ return yield* EntityNotFound.make({ kind: input.kind, key: input.key });
1897
1905
  }
1898
1906
  const encoded = yield* Schema4.encodeUnknownEffect(input.command.input)(input.input).pipe(Effect2.mapError(toClientError));
1899
1907
  const inputRef = inputSchemaRef(input.command.name);
@@ -1902,7 +1910,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1902
1910
  yield* schemaRegistry.value.register({ ref: inputRef, schema: input.command.input });
1903
1911
  yield* schemaRegistry.value.register({ ref: outputRef, schema: input.command.output });
1904
1912
  }
1905
- const correlation = `command:${input.command.name}:${globalThis.crypto.randomUUID()}`;
1913
+ const correlation = `command:${input.command.name}:${yield* Random.nextInt}`;
1906
1914
  const accepted = yield* sendEnvelope({
1907
1915
  from: input.from,
1908
1916
  to: instance.address_id,
@@ -1921,28 +1929,28 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1921
1929
  }
1922
1930
  });
1923
1931
  if (accepted.wait_id === undefined) {
1924
- return yield* new ClientError({ message: "askEntity send did not create a reply wait" });
1932
+ return yield* ClientError.make({ message: "askEntity send did not create a reply wait" });
1925
1933
  }
1926
1934
  const outcome = yield* awaitWaitOperation({ wait_id: accepted.wait_id, execution_id: accepted.execution_id });
1927
1935
  if (outcome.state === "timed_out") {
1928
- return yield* new CommandTimedOut({
1936
+ return yield* CommandTimedOut.make({
1929
1937
  command: input.command.name,
1930
1938
  wait_id: outcome.wait_id,
1931
1939
  timeout: input.timeout ?? "unspecified"
1932
1940
  });
1933
1941
  }
1934
1942
  if (outcome.state === "cancelled") {
1935
- return yield* new ClientError({ message: `reply wait ${outcome.wait_id} was cancelled` });
1943
+ return yield* ClientError.make({ message: `reply wait ${outcome.wait_id} was cancelled` });
1936
1944
  }
1937
1945
  const replyValue = replyValueFrom(outcome.content);
1938
1946
  if (replyValue._tag === "None") {
1939
- return yield* new CommandReplyInvalid({
1947
+ return yield* CommandReplyInvalid.make({
1940
1948
  command: input.command.name,
1941
1949
  wait_id: outcome.wait_id,
1942
1950
  message: "reply carried no decodable content"
1943
1951
  });
1944
1952
  }
1945
- return yield* Schema4.decodeUnknownEffect(input.command.output)(replyValue.value).pipe(Effect2.mapError((issue) => new CommandReplyInvalid({
1953
+ return yield* Schema4.decodeUnknownEffect(input.command.output)(replyValue.value).pipe(Effect2.mapError((issue) => CommandReplyInvalid.make({
1946
1954
  command: input.command.name,
1947
1955
  wait_id: outcome.wait_id,
1948
1956
  message: errorMessage(issue)
@@ -1983,14 +1991,14 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
1983
1991
  ...input.expected_version === undefined ? {} : { expectedVersion: input.expected_version },
1984
1992
  ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
1985
1993
  updatedAt: input.updated_at
1986
- }).pipe(Effect2.mapError((error) => error instanceof exports_execution_state_service.StateVersionConflict ? error : toClientError(error)))),
1994
+ }).pipe(Effect2.mapError((error) => Schema4.is(exports_execution_state_service.StateVersionConflict)(error) ? error : toClientError(error)))),
1987
1995
  deleteEntityState: Effect2.fn("Client.runtime.deleteEntityState")((input) => executionState.remove({
1988
1996
  executionId: input.execution_id,
1989
1997
  key: input.key,
1990
1998
  ...input.expected_version === undefined ? {} : { expectedVersion: input.expected_version },
1991
1999
  ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
1992
2000
  removedAt: input.removed_at
1993
- }).pipe(Effect2.mapError((error) => error instanceof exports_execution_state_service.StateVersionConflict ? error : toClientError(error)))),
2001
+ }).pipe(Effect2.mapError((error) => Schema4.is(exports_execution_state_service.StateVersionConflict)(error) ? error : toClientError(error)))),
1994
2002
  listEntityState: Effect2.fn("Client.runtime.listEntityState")((input) => executionState.list({
1995
2003
  executionId: input.execution_id,
1996
2004
  ...input.prefix === undefined ? {} : { prefix: input.prefix },
@@ -2041,7 +2049,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
2041
2049
  const coordinated = yield* coordinateToolTransition(Effect2.gen(function* () {
2042
2050
  const call = yield* toolCalls.getCall(input.tool_call_id).pipe(Effect2.mapError(toClientError));
2043
2051
  if (call === undefined || call.executionId !== input.execution_id || call.placement.kind !== "client") {
2044
- return yield* new ClientError({ message: `Client tool call not found: ${input.tool_call_id}` });
2052
+ return yield* ClientError.make({ message: `Client tool call not found: ${input.tool_call_id}` });
2045
2053
  }
2046
2054
  const wait = yield* resolveToolOutcomeWait(waits, eventLog, call, input.outcome, input.fulfilled_at);
2047
2055
  const accepted = yield* toolCalls.acceptClientOutcome({
@@ -2070,7 +2078,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
2070
2078
  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;
2071
2079
  const acceptedRetry = call !== undefined && call.placement.kind === "remote" && call.state === "submitted" && call.activeAttemptId === input.attempt_id && call.externalOutcome !== undefined;
2072
2080
  if (call === undefined || !active && !acceptedRetry) {
2073
- return yield* new ClientError({ message: `Remote tool claim is not active: ${input.tool_call_id}` });
2081
+ return yield* ClientError.make({ message: `Remote tool claim is not active: ${input.tool_call_id}` });
2074
2082
  }
2075
2083
  const wait = yield* resolveToolOutcomeWait(waits, eventLog, call, input.outcome, input.completed_at);
2076
2084
  const accepted = yield* toolCalls.acceptRemoteOutcome({
@@ -2113,8 +2121,8 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
2113
2121
  const pin = yield* parentDefinitionPin(executionRepository, input.execution_id);
2114
2122
  const createdAt = yield* Clock.currentTimeMillis;
2115
2123
  const internal = internalSpawnChildRunInput(input, pin, createdAt);
2116
- const context = yield* exports_child_run_service.resolveForDispatch(internal).pipe(Effect2.mapError((error) => new ClientError({ message: error._tag })));
2117
- const definition = yield* exports_child_run_service.childDefinition(pin.agentSnapshot, context).pipe(Effect2.mapError((error) => new ClientError({ message: error._tag })));
2124
+ const context = yield* exports_child_run_service.resolveForDispatch(internal).pipe(Effect2.mapError((error) => ClientError.make({ message: error._tag })));
2125
+ const definition = yield* exports_child_run_service.childDefinition(pin.agentSnapshot, context).pipe(Effect2.mapError((error) => ClientError.make({ message: error._tag })));
2118
2126
  const coordinated = yield* coordinateChildSpawn(Effect2.gen(function* () {
2119
2127
  const existing = yield* reconcileExistingChildSpawn(childExecutions, waits, eventLog, input);
2120
2128
  if (existing !== undefined)
@@ -2122,7 +2130,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
2122
2130
  const accepted = yield* executions.spawnChildRun(internal).pipe(Effect2.mapError(toClientError));
2123
2131
  const parentWaitId = input.wait === true ? yield* createChildJoinWait(waits, eventLog, internal, accepted, createdAt) : undefined;
2124
2132
  return { accepted, createdAt, parentWaitId };
2125
- })).pipe(Effect2.catch((error) => error.message === "DuplicateChildExecution" ? coordinateChildSpawn(reconcileExistingChildSpawn(childExecutions, waits, eventLog, input).pipe(Effect2.flatMap((existing) => existing === undefined ? Effect2.fail(new ClientError({ message: `Child execution retry missing: ${input.execution_id}` })) : Effect2.succeed(existing)))) : Effect2.fail(error)));
2133
+ })).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)));
2126
2134
  const startPayload = childStartInput(internal, coordinated.accepted, pin, definition, coordinated.createdAt, coordinated.parentWaitId);
2127
2135
  const client = makeExecutionClient(startPayload.execution_id);
2128
2136
  yield* client.dispatch(startPayload).pipe(Effect2.mapError(toClientError));
@@ -2132,7 +2140,7 @@ var layerFromRuntime = Layer2.effect(Service2, Effect2.gen(function* () {
2132
2140
  if (Option.isSome(runtimeCapabilityPolicy))
2133
2141
  yield* runtimeCapabilityPolicy.value.admit("fan-out");
2134
2142
  if (Option.isNone(childFanOutRuntime)) {
2135
- return yield* new ClientError({
2143
+ return yield* ClientError.make({
2136
2144
  message: "Child fan-out runtime unavailable; provide ChildFanOutRuntime.Service to Client.layerFromRuntime"
2137
2145
  });
2138
2146
  }
@@ -2218,9 +2226,9 @@ var testLayer = (implementation) => Layer2.succeed(Service2, Service2.of({
2218
2226
  streamExecution: implementation.streamExecution
2219
2227
  }),
2220
2228
  registerEntityKind: implementation.registerEntityKind ?? ((input) => Effect2.succeed(input)),
2221
- getOrCreateEntity: implementation.getOrCreateEntity ?? (() => Effect2.fail(new ClientError({ message: "Entity service unavailable" }))),
2222
- getEntity: implementation.getEntity ?? (() => Effect2.succeed(undefined)),
2223
- destroyEntity: implementation.destroyEntity ?? (() => Effect2.fail(new ClientError({ message: "Entity service unavailable" }))),
2229
+ getOrCreateEntity: implementation.getOrCreateEntity ?? (() => Effect2.fail(ClientError.make({ message: "Entity service unavailable" }))),
2230
+ getEntity: implementation.getEntity ?? (() => Effect2.void.pipe(Effect2.as(undefined))),
2231
+ destroyEntity: implementation.destroyEntity ?? (() => Effect2.fail(ClientError.make({ message: "Entity service unavailable" }))),
2224
2232
  listEntities: implementation.listEntities ?? (() => Effect2.succeed([])),
2225
2233
  streamSession: implementation.streamSession ?? (() => Stream.empty),
2226
2234
  watchExecutions: implementation.watchExecutions ?? (() => Stream.empty),
@@ -2525,12 +2533,13 @@ __export(exports_runtime_database, {
2525
2533
  });
2526
2534
  import { Context as Context3 } from "effect";
2527
2535
 
2528
- class Service3 extends Context3.Service()("@relayfx/sdk/RuntimeDatabase") {
2536
+ class Service3 extends Context3.Service()("@relayfx/sdk/runtime-database/Service") {
2529
2537
  }
2530
2538
 
2531
2539
  // src/runtime.ts
2532
2540
  var DatabaseIdentity = Schema5.NonEmptyString.pipe(Schema5.brand("@relayfx/sdk/DatabaseIdentity"));
2533
- var makeDatabaseIdentity = Schema5.decodeUnknownSync(DatabaseIdentity);
2541
+ var decodeDatabaseIdentity = Schema5.decodeUnknownSync(DatabaseIdentity);
2542
+ var makeDatabaseIdentity = (input) => decodeDatabaseIdentity(input);
2534
2543
  var Dialect = Schema5.Literals(["pg", "mysql", "sqlite"]);
2535
2544
  var DatabaseDialect = Symbol("@relayfx/sdk/DatabaseDialect");
2536
2545
 
@@ -2649,29 +2658,30 @@ class RuntimeReadinessError extends Schema5.TaggedErrorClass()("RuntimeReadiness
2649
2658
  }) {
2650
2659
  }
2651
2660
 
2652
- class Service4 extends Context4.Service()("@relayfx/sdk/Runtime") {
2661
+ class Service4 extends Context4.Service()("@relayfx/sdk/runtime/Service") {
2653
2662
  }
2663
+ var embeddedOutput = (layer2) => layer2;
2654
2664
  var isAcquisitionError = (error) => typeof error === "object" && error !== null && ("_tag" in error) && (error._tag === "RuntimeConfigurationError" || error._tag === "RuntimeTopologyError" || error._tag === "RuntimeMigrationError");
2655
2665
  var normalizeHost = (layer2, role, dialect) => {
2656
2666
  const normalize = (error) => {
2657
2667
  if (isAcquisitionError(error))
2658
2668
  return error;
2659
2669
  if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "ClusterConfigMismatch") {
2660
- const clusterFailure = new ClusterFailure({ reason: "cluster configuration is incompatible" });
2670
+ const clusterFailure = ClusterFailure.make({ reason: "cluster configuration is incompatible" });
2661
2671
  Object.defineProperty(clusterFailure, "originalCause", { value: error, enumerable: false });
2662
- return new RuntimeTopologyError({
2672
+ return RuntimeTopologyError.make({
2663
2673
  dialect,
2664
2674
  role,
2665
2675
  nextAction: role === "embedded" ? "use-embedded" : "use-different-database",
2666
2676
  cause: clusterFailure
2667
2677
  });
2668
2678
  }
2669
- const hostFailure = new HostLayerError({
2679
+ const hostFailure = HostLayerError.make({
2670
2680
  service: "Runtime host graph",
2671
2681
  reason: "host layer acquisition failed"
2672
2682
  });
2673
2683
  Object.defineProperty(hostFailure, "originalCause", { value: error, enumerable: false });
2674
- return new RuntimeConfigurationError({
2684
+ return RuntimeConfigurationError.make({
2675
2685
  setting: "host layers",
2676
2686
  nextAction: "provide-host-layer",
2677
2687
  cause: hostFailure
@@ -2698,11 +2708,11 @@ var validatedDatabase = (databaseLayer, role) => {
2698
2708
  const sql = yield* SqlClient;
2699
2709
  const actual = actualDialect(sql);
2700
2710
  if (actual !== database.dialect) {
2701
- return yield* new RuntimeTopologyError({
2711
+ return yield* RuntimeTopologyError.make({
2702
2712
  dialect: database.dialect,
2703
2713
  role,
2704
2714
  nextAction: role === "embedded" ? "use-different-database" : "use-postgres-or-mysql",
2705
- cause: new DatabaseDialectMismatch({ expected: database.dialect, actual })
2715
+ cause: DatabaseDialectMismatch.make({ expected: database.dialect, actual })
2706
2716
  });
2707
2717
  }
2708
2718
  if (database.dialect === "sqlite") {
@@ -2719,10 +2729,10 @@ var runtimeServiceLayer = (role, capabilities) => Layer3.effect(Service4, Effect
2719
2729
  const database = yield* Service3;
2720
2730
  const runner = yield* exports_runner_runtime_service.Service;
2721
2731
  return Service4.of({
2722
- readiness: runner.check().pipe(Effect3.mapError((error) => {
2723
- const cause = new SqlFailure({ category: "unknown", operation: "readiness", retryable: false });
2732
+ readiness: runner.check.pipe(Effect3.mapError((error) => {
2733
+ const cause = SqlFailure.make({ category: "unknown", operation: "readiness", retryable: false });
2724
2734
  Object.defineProperty(cause, "originalCause", { value: error, enumerable: false });
2725
- return new RuntimeReadinessError({ phase: "database", cause });
2735
+ return RuntimeReadinessError.make({ phase: "database", cause });
2726
2736
  }), Effect3.as({
2727
2737
  ready: true,
2728
2738
  role,
@@ -2756,7 +2766,7 @@ var withHosts = (runner, options) => {
2756
2766
  const workflowHost = options.workflowDefinitionHandlersLayer === undefined ? Layer3.empty : exports_definition_runtime.layerFromRuntime.pipe(Layer3.provide(options.workflowDefinitionHandlersLayer), Layer3.provideMerge(childHost), Layer3.provide(runner));
2757
2767
  return Layer3.mergeAll(runner, childHost, workflowHost);
2758
2768
  };
2759
- var layerEmbedded = (options) => {
2769
+ function layerEmbedded(options) {
2760
2770
  const runner = exports_runner_runtime_service.layerWithServices({
2761
2771
  databaseLayer: ambientDatabaseLayer,
2762
2772
  languageModelLayer: options.languageModelLayer,
@@ -2767,11 +2777,12 @@ var layerEmbedded = (options) => {
2767
2777
  promptAssemblerLayer: options.promptAssemblerLayer,
2768
2778
  schemaRegistryLayer: options.schemaRegistryLayer
2769
2779
  });
2770
- return normalizeHost(publicGraph(withHosts(runner, options), options.databaseLayer, "embedded", {
2780
+ const host = normalizeHost(publicGraph(withHosts(runner, options), options.databaseLayer, "embedded", {
2771
2781
  fanOut: options.childFanOutHandlersLayer !== undefined,
2772
2782
  workflowDefinition: options.workflowDefinitionHandlersLayer !== undefined
2773
2783
  }), "embedded", options.databaseLayer[DatabaseDialect]);
2774
- };
2784
+ return embeddedOutput(host);
2785
+ }
2775
2786
  var layerRunner = (options) => {
2776
2787
  const runner = exports_runner_runtime_service.layerWithServicesMultiNode({
2777
2788
  databaseLayer: ambientDatabaseLayer,