@relayfx/sdk 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/ai.js +1 -1
  2. package/dist/{index-h1cf8za4.js → index-0jx86sx3.js} +1 -1
  3. package/dist/{index-8asvg7x0.js → index-96b7htye.js} +878 -706
  4. package/dist/{index-x32kbvxv.js → index-c6jave5p.js} +989 -958
  5. package/dist/index.js +252 -117
  6. package/dist/migrations/20260721170000_session_writer_ownership/migration.sql +5 -0
  7. package/dist/migrations/mysql/0014_session_writer_ownership.sql +5 -0
  8. package/dist/migrations/pg/20260721170000_session_writer_ownership/migration.sql +5 -0
  9. package/dist/migrations/sqlite/0014_session_writer_ownership.sql +5 -0
  10. package/dist/mysql.js +13 -4
  11. package/dist/postgres.js +7 -4
  12. package/dist/sqlite.js +13 -4
  13. package/dist/types/ai/language-model/language-model-registration.d.ts +23 -11
  14. package/dist/types/relay/language-model-registration.d.ts +25 -11
  15. package/dist/types/relay/mysql-migrations.d.ts +1 -1
  16. package/dist/types/relay/sqlite-migrations.d.ts +6 -1
  17. package/dist/types/runtime/agent/agent-loop-error.d.ts +1 -1
  18. package/dist/types/runtime/agent/relay-permissions.d.ts +2 -2
  19. package/dist/types/runtime/execution/active-execution-registry.d.ts +1 -0
  20. package/dist/types/runtime/model/model-hub.d.ts +5 -5
  21. package/dist/types/runtime/runner/runner-runtime-service.d.ts +4 -4
  22. package/dist/types/runtime/session/session-store-service.d.ts +1 -0
  23. package/dist/types/store-sql/schema/session-schema.d.ts +45 -0
  24. package/dist/types/store-sql/session/session-records.d.ts +5 -47
  25. package/dist/types/store-sql/session/session-repository.d.ts +35 -1
  26. package/dist/types/store-sql/session/session-row.d.ts +60 -0
  27. package/package.json +3 -3
@@ -16,7 +16,7 @@ import {
16
16
  exports_tool_executor,
17
17
  exports_tool_output,
18
18
  exports_turn_policy
19
- } from "./index-x32kbvxv.js";
19
+ } from "./index-c6jave5p.js";
20
20
  import {
21
21
  ClientError,
22
22
  EventLogCursorNotFound,
@@ -550,12 +550,12 @@ var notRegistered = (selection) => LanguageModelNotRegistered.make({
550
550
 
551
551
  class Service8 extends Context6.Service()("@relayfx/runtime/model/language-model-service/Service") {
552
552
  }
553
- var registrationFromLayer2 = exports_model_registry.registrationFromLayer;
553
+ var registrationFromLayer2 = exports_model_registry.registration;
554
554
  var fromModelRegistry = (registry) => Service8.of({
555
555
  register: (input) => registry.register(input),
556
556
  registrations: registry.registrations,
557
- provide: (selection, effect) => registry.provide(toSelection(selection), effect),
558
- provideForAgent: (agent, effect) => registry.provide(toSelection(agent.model), effect)
557
+ provide: (selection, effect) => registry.operate(toSelection(selection), effect),
558
+ provideForAgent: (agent, effect) => registry.operate(toSelection(agent.model), effect)
559
559
  });
560
560
  var testLayer5 = (implementation) => Layer6.succeed(Service8, Service8.of(implementation));
561
561
  var register3 = Effect6.fn("LanguageModelService.register.call")(function* (input) {
@@ -616,9 +616,9 @@ var validate = (registrations3) => Effect7.gen(function* () {
616
616
  return registrations3;
617
617
  });
618
618
  var fromRegistrations = (registrations3, options) => {
619
- const registryLayer = exports_model_registry.layer(registrations3, options);
619
+ const registryLayer = exports_model_registry.layer(registrations3.map((registration) => Effect7.succeed(registration)), options);
620
620
  const hubLayer = Layer7.effect(Service9, Effect7.gen(function* () {
621
- const modelRegistry = yield* exports_model_registry.Service;
621
+ const modelRegistry = yield* exports_model_registry.ModelRegistry;
622
622
  return Service9.of({
623
623
  modelRegistry,
624
624
  languageModelService: fromModelRegistry(modelRegistry)
@@ -633,7 +633,7 @@ var layer4 = Function4.dual((args) => Array.isArray(args[0]), (registrations3, o
633
633
  var layerFromRegistrationEffects2 = Function4.dual((args) => Array.isArray(args[0]), (declarations, options) => Layer7.unwrap(Effect7.all(declarations).pipe(Effect7.flatMap(validate), Effect7.map((items) => fromRegistrations(items, options)))));
634
634
  var testLayer6 = (modelRegistry) => {
635
635
  const languageModelService = fromModelRegistry(modelRegistry);
636
- return Layer7.mergeAll(Layer7.succeed(Service9, Service9.of({ modelRegistry, languageModelService })), Layer7.succeed(exports_model_registry.Service, modelRegistry), Layer7.succeed(Service8, languageModelService));
636
+ return Layer7.mergeAll(Layer7.succeed(Service9, Service9.of({ modelRegistry, languageModelService })), Layer7.succeed(exports_model_registry.ModelRegistry, modelRegistry), Layer7.succeed(Service8, languageModelService));
637
637
  };
638
638
 
639
639
  // ../runtime/src/schema-registry/schema-registry-service.ts
@@ -6206,7 +6206,7 @@ __export(exports_session_repository, {
6206
6206
  Service: () => Service35,
6207
6207
  DuplicateSession: () => DuplicateSession
6208
6208
  });
6209
- import { Context as Context33, Effect as Effect41, Layer as Layer35, Schema as Schema39 } from "effect";
6209
+ import { Context as Context33, Effect as Effect41, Layer as Layer35, Schema as Schema40 } from "effect";
6210
6210
 
6211
6211
  // ../store-sql/src/session/session-entry-records.ts
6212
6212
  import { Effect as Effect39, Schema as Schema37 } from "effect";
@@ -6489,16 +6489,23 @@ var makeSessionEntryRecords = (errors) => {
6489
6489
  };
6490
6490
 
6491
6491
  // ../store-sql/src/session/session-records.ts
6492
- import { Effect as Effect40, Schema as Schema38 } from "effect";
6492
+ import { Effect as Effect40, Schema as Schema39 } from "effect";
6493
6493
  import { SqlClient as SqlClient23 } from "effect/unstable/sql/SqlClient";
6494
+
6495
+ // ../store-sql/src/session/session-row.ts
6496
+ import { Schema as Schema38 } from "effect";
6494
6497
  var sessionRow = Schema38.Struct({
6495
6498
  id: Schema38.String,
6496
6499
  root_address_id: Schema38.String,
6497
6500
  leaf_entry_id: Schema38.Union([Schema38.String, Schema38.Null, Schema38.Undefined]),
6501
+ owner_execution_id: Schema38.Union([Schema38.String, Schema38.Null, Schema38.Undefined]),
6502
+ owner_epoch: Schema38.Union([Schema38.Finite, Schema38.String, Schema38.BigInt]),
6503
+ owner_released: Schema38.Union([Schema38.Boolean, Schema38.Finite, Schema38.String, Schema38.BigInt]),
6498
6504
  metadata_json: Schema38.Unknown,
6499
6505
  created_at: Schema38.Union([Schema38.Date, Schema38.String, Schema38.Finite]),
6500
6506
  updated_at: Schema38.Union([Schema38.Date, Schema38.String, Schema38.Finite])
6501
6507
  }).annotate({ identifier: "Relay.Session.Row" });
6508
+ var releasedFlag = (value) => value === true || value === 1 || value === "1" || value === 1n || value === "true";
6502
6509
  var CountRow = Schema38.Struct({
6503
6510
  value: Schema38.Union([Schema38.Finite, Schema38.String, Schema38.BigInt])
6504
6511
  }).annotate({ identifier: "Relay.SessionEntry.CountRow" });
@@ -6507,6 +6514,13 @@ var toSessionRecord = (row) => ({
6507
6514
  id: exports_ids_schema.SessionId.make(row.id),
6508
6515
  rootAddressId: exports_ids_schema.AddressId.make(row.root_address_id),
6509
6516
  ...row.leaf_entry_id === null || row.leaf_entry_id === undefined ? {} : { leafEntryId: exports_ids_schema.SessionEntryId.make(row.leaf_entry_id) },
6517
+ ...row.owner_execution_id === null || row.owner_execution_id === undefined ? {} : {
6518
+ writer: {
6519
+ executionId: exports_ids_schema.ExecutionId.make(row.owner_execution_id),
6520
+ epoch: Number(row.owner_epoch),
6521
+ released: releasedFlag(row.owner_released)
6522
+ }
6523
+ },
6510
6524
  metadata: decodeJson(row.metadata_json),
6511
6525
  createdAt: fromDbTimestamp(row.created_at),
6512
6526
  updatedAt: fromDbTimestamp(row.updated_at)
@@ -6527,9 +6541,29 @@ var makeSessionRecordSupport = (errors) => {
6527
6541
  missingSession: (id) => SessionRepositoryError.make({ message: `Session ${id} does not exist` }),
6528
6542
  rootMismatch: (id) => SessionRepositoryError.make({ message: `Session ${id} already exists for a different root address` }),
6529
6543
  cloneSession: (record2) => structuredClone(record2),
6530
- currentLeaf: (session) => session.leafEntryId ?? null
6544
+ currentLeaf: (session) => session.leafEntryId ?? null,
6545
+ writerFenceViolation: (session, expected) => {
6546
+ if (expected === undefined)
6547
+ return;
6548
+ const writer = session.writer;
6549
+ if (writer === undefined)
6550
+ return `Session ${session.id} has no writer claim`;
6551
+ if (writer.released)
6552
+ return `Session ${session.id} writer claim was released`;
6553
+ if (writer.executionId !== expected.executionId || writer.epoch !== expected.epoch)
6554
+ return `Session ${session.id} is owned by ${writer.executionId} at epoch ${writer.epoch}`;
6555
+ return;
6556
+ },
6557
+ nextWriterClaim: (current2, executionId) => {
6558
+ if (current2 === undefined || current2.released)
6559
+ return { _tag: "Claimed", writer: { executionId, epoch: (current2?.epoch ?? 0) + 1, released: false } };
6560
+ if (current2.executionId === executionId)
6561
+ return { _tag: "Claimed", writer: { executionId, epoch: current2.epoch, released: false } };
6562
+ return { _tag: "Busy", writer: current2 };
6563
+ }
6531
6564
  };
6532
6565
  };
6566
+ // ../store-sql/src/session/session-records.ts
6533
6567
  var makeSessionRepository = (errors) => Effect40.gen(function* () {
6534
6568
  const { SessionRepositoryError, DuplicateSession } = errors;
6535
6569
  const {
@@ -6542,7 +6576,7 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6542
6576
  toEntryRecord,
6543
6577
  validateCompaction
6544
6578
  } = makeSessionEntryRecords(errors);
6545
- const { currentLeaf, missingSession, rootMismatch } = makeSessionRecordSupport(errors);
6579
+ const { currentLeaf, missingSession, nextWriterClaim, rootMismatch, writerFenceViolation } = makeSessionRecordSupport(errors);
6546
6580
  const sql = yield* SqlClient23;
6547
6581
  const toRepositoryError12 = (error5) => SessionRepositoryError.make({ message: String(error5) });
6548
6582
  function mapRepositoryError(effect) {
@@ -6552,14 +6586,23 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6552
6586
  return toRepositoryError12(error5);
6553
6587
  }));
6554
6588
  }
6555
- const decodeSessionRow = (row) => Schema38.decodeUnknownEffect(sessionRow)(row).pipe(Effect40.mapError(toRepositoryError12));
6556
- const decodeEntryRow = (row) => Schema38.decodeUnknownEffect(sessionEntryRow)(row).pipe(Effect40.mapError(toRepositoryError12));
6557
- const decodeCountRow = (row) => Schema38.decodeUnknownEffect(CountRow)(row).pipe(Effect40.mapError(toRepositoryError12));
6589
+ const decodeSessionRow = (row) => Schema39.decodeUnknownEffect(sessionRow)(row).pipe(Effect40.mapError(toRepositoryError12));
6590
+ const decodeEntryRow = (row) => Schema39.decodeUnknownEffect(sessionEntryRow)(row).pipe(Effect40.mapError(toRepositoryError12));
6591
+ const decodeCountRow = (row) => Schema39.decodeUnknownEffect(CountRow)(row).pipe(Effect40.mapError(toRepositoryError12));
6558
6592
  const selectSessionByKey = (tenantId, id) => sql`
6559
- SELECT id, root_address_id, leaf_entry_id, metadata_json, created_at, updated_at
6593
+ SELECT id, root_address_id, leaf_entry_id, owner_execution_id, owner_epoch, owner_released, metadata_json, created_at, updated_at
6560
6594
  FROM relay_sessions
6561
6595
  WHERE tenant_id = ${tenantId} AND id = ${id}
6562
6596
  `;
6597
+ const releasedParam = sql.onDialectOrElse({
6598
+ pg: () => (released) => released,
6599
+ orElse: () => (released) => released ? 1 : 0
6600
+ });
6601
+ const updateWriter = (tenantId, input) => sql`
6602
+ UPDATE relay_sessions
6603
+ SET owner_execution_id = ${input.writer.executionId}, owner_epoch = ${input.writer.epoch}, owner_released = ${releasedParam(input.writer.released)}, updated_at = ${timestampParam(sql, input.updatedAt)}
6604
+ WHERE tenant_id = ${tenantId} AND id = ${input.sessionId}
6605
+ `;
6563
6606
  const lockSession = sql.onDialectOrElse({
6564
6607
  pg: () => (tenantId, id) => sql`SELECT id FROM relay_sessions WHERE tenant_id = ${tenantId} AND id = ${id} FOR UPDATE`,
6565
6608
  mysql: () => (tenantId, id) => sql`SELECT id FROM relay_sessions WHERE tenant_id = ${tenantId} AND id = ${id} FOR UPDATE`,
@@ -6689,14 +6732,14 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6689
6732
  ]));
6690
6733
  }
6691
6734
  const rows = yield* mapRepositoryError(sql`
6692
- SELECT id, root_address_id, leaf_entry_id, metadata_json, created_at, updated_at
6735
+ SELECT id, root_address_id, leaf_entry_id, owner_execution_id, owner_epoch, owner_released, metadata_json, created_at, updated_at
6693
6736
  FROM relay_sessions
6694
6737
  WHERE ${sql.and(conditions)}
6695
6738
  ORDER BY updated_at DESC, id DESC
6696
6739
  LIMIT ${sql.literal(String(limit + 1))}
6697
6740
  `);
6698
6741
  const records = yield* Effect40.forEach(rows.slice(0, limit), (row) => decodeSessionRow(row).pipe(Effect40.map(toSessionRecord)));
6699
- const nextCursor = nextCursorOf2(records, rows.length, limit);
6742
+ const nextCursor = sessionRecordPaging.nextCursorOf(records, rows.length, limit);
6700
6743
  return nextCursor === undefined ? { records } : { records, nextCursor };
6701
6744
  });
6702
6745
  const touch = Effect40.fn("SessionRepository.touch")(function* (input) {
@@ -6727,6 +6770,9 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6727
6770
  return yield* mapRepositoryError(sql.withTransaction(Effect40.gen(function* () {
6728
6771
  yield* lockSession(tenantId, input.sessionId);
6729
6772
  const session = yield* requireSession(tenantId, input.sessionId);
6773
+ const fence = writerFenceViolation(session, input.expectedWriter);
6774
+ if (fence !== undefined)
6775
+ return yield* conflict4("fenced", fence);
6730
6776
  if (input.expectedLeafId !== undefined && input.expectedLeafId !== currentLeaf(session)) {
6731
6777
  return yield* conflict4("stale-leaf", `Expected Session leaf ${String(input.expectedLeafId)} but found ${String(currentLeaf(session))}`);
6732
6778
  }
@@ -6764,6 +6810,9 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6764
6810
  return yield* mapRepositoryError(sql.withTransaction(Effect40.gen(function* () {
6765
6811
  yield* lockSession(tenantId, input.sessionId);
6766
6812
  const session = yield* requireSession(tenantId, input.sessionId);
6813
+ const checkpointFence = writerFenceViolation(session, input.expectedWriter);
6814
+ if (checkpointFence !== undefined)
6815
+ return yield* conflict4("fenced", checkpointFence);
6767
6816
  const existing = yield* entryById(tenantId, input.sessionId, input.id);
6768
6817
  const appendInput = {
6769
6818
  id: input.id,
@@ -6816,9 +6865,40 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6816
6865
  const counted = yield* decodeCountRow(rows[0]);
6817
6866
  return Number(counted.value);
6818
6867
  });
6868
+ const claimWriter = Effect40.fn("SessionRepository.claimWriter")(function* (input) {
6869
+ const tenantId = yield* current();
6870
+ return yield* mapRepositoryError(sql.withTransaction(Effect40.gen(function* () {
6871
+ yield* lockSession(tenantId, input.sessionId);
6872
+ const session = yield* requireSession(tenantId, input.sessionId);
6873
+ const claim = nextWriterClaim(session.writer, input.executionId);
6874
+ if (claim._tag === "Busy")
6875
+ return claim;
6876
+ yield* updateWriter(tenantId, { sessionId: input.sessionId, writer: claim.writer, updatedAt: input.now });
6877
+ return claim;
6878
+ })));
6879
+ });
6880
+ const releaseWriter = Effect40.fn("SessionRepository.releaseWriter")(function* (input) {
6881
+ const tenantId = yield* current();
6882
+ yield* mapRepositoryError(sql.withTransaction(Effect40.gen(function* () {
6883
+ yield* lockSession(tenantId, input.sessionId);
6884
+ const session = yield* getForTenant(tenantId, input.sessionId);
6885
+ const writer = session?.writer;
6886
+ if (session === undefined || writer === undefined || writer.executionId !== input.executionId)
6887
+ return;
6888
+ if (writer.released)
6889
+ return;
6890
+ yield* updateWriter(tenantId, {
6891
+ sessionId: input.sessionId,
6892
+ writer: { ...writer, released: true },
6893
+ updatedAt: input.now
6894
+ });
6895
+ })));
6896
+ });
6819
6897
  return {
6820
6898
  create: create5,
6821
6899
  ensure,
6900
+ claimWriter,
6901
+ releaseWriter,
6822
6902
  get: get9,
6823
6903
  list: list10,
6824
6904
  touch,
@@ -6832,19 +6912,19 @@ var makeSessionRepository = (errors) => Effect40.gen(function* () {
6832
6912
  });
6833
6913
 
6834
6914
  // ../store-sql/src/session/session-repository.ts
6835
- class SessionRepositoryError extends Schema39.TaggedErrorClass()("SessionRepositoryError", {
6836
- message: Schema39.String
6915
+ class SessionRepositoryError extends Schema40.TaggedErrorClass()("SessionRepositoryError", {
6916
+ message: Schema40.String
6837
6917
  }) {
6838
6918
  }
6839
6919
 
6840
- class DuplicateSession extends Schema39.TaggedErrorClass()("DuplicateSession", {
6920
+ class DuplicateSession extends Schema40.TaggedErrorClass()("DuplicateSession", {
6841
6921
  id: exports_ids_schema.SessionId
6842
6922
  }) {
6843
6923
  }
6844
6924
 
6845
- class SessionConflict extends Schema39.TaggedErrorClass()("SessionConflict", {
6846
- reason: Schema39.Literals(["stale-leaf", "checkpoint-id-reused", "checkpoint-not-on-active-path"]),
6847
- message: Schema39.String
6925
+ class SessionConflict extends Schema40.TaggedErrorClass()("SessionConflict", {
6926
+ reason: Schema40.Literals(["stale-leaf", "checkpoint-id-reused", "checkpoint-not-on-active-path", "fenced"]),
6927
+ message: Schema40.String
6848
6928
  }) {
6849
6929
  }
6850
6930
 
@@ -6863,7 +6943,7 @@ var {
6863
6943
  sameEntry,
6864
6944
  validateCompaction
6865
6945
  } = makeSessionEntryRecords(repositoryErrors);
6866
- var { cloneSession, currentLeaf, missingSession, rootMismatch } = makeSessionRecordSupport(repositoryErrors);
6946
+ var { cloneSession, currentLeaf, missingSession, nextWriterClaim, rootMismatch, writerFenceViolation } = makeSessionRecordSupport(repositoryErrors);
6867
6947
  var { afterCursor: afterCursor3, compareDesc: compareDesc3, nextCursorOf: nextCursorOf3 } = sessionRecordPaging;
6868
6948
  var layer28 = Layer35.effect(Service35, makeSessionRepository(repositoryErrors).pipe(Effect41.map(Service35.of)));
6869
6949
  var layerFromTenant = layer28;
@@ -6931,6 +7011,25 @@ var memoryLayer26 = Layer35.sync(Service35, () => {
6931
7011
  sessions.set(input.id, record2);
6932
7012
  return cloneSession(record2);
6933
7013
  }),
7014
+ claimWriter: Effect41.fn("SessionRepository.memory.claimWriter")(function* (input) {
7015
+ const session = sessions.get(input.sessionId);
7016
+ if (session === undefined)
7017
+ return yield* missingSession(input.sessionId);
7018
+ const claim = nextWriterClaim(session.writer, input.executionId);
7019
+ if (claim._tag === "Busy")
7020
+ return claim;
7021
+ sessions.set(input.sessionId, { ...session, writer: claim.writer, updatedAt: input.now });
7022
+ return claim;
7023
+ }),
7024
+ releaseWriter: Effect41.fn("SessionRepository.memory.releaseWriter")((input) => Effect41.sync(() => {
7025
+ const session = sessions.get(input.sessionId);
7026
+ const writer = session?.writer;
7027
+ if (session === undefined || writer === undefined || writer.executionId !== input.executionId)
7028
+ return;
7029
+ if (writer.released)
7030
+ return;
7031
+ sessions.set(input.sessionId, { ...session, writer: { ...writer, released: true }, updatedAt: input.now });
7032
+ })),
6934
7033
  get: Effect41.fn("SessionRepository.memory.get")((id) => Effect41.sync(() => {
6935
7034
  const record2 = sessions.get(id);
6936
7035
  return record2 === undefined ? undefined : cloneSession(record2);
@@ -6954,6 +7053,9 @@ var memoryLayer26 = Layer35.sync(Service35, () => {
6954
7053
  const session = sessions.get(input.sessionId);
6955
7054
  if (session === undefined)
6956
7055
  return yield* missingSession(input.sessionId);
7056
+ const fence = writerFenceViolation(session, input.expectedWriter);
7057
+ if (fence !== undefined)
7058
+ return yield* conflict4("fenced", fence);
6957
7059
  if (input.expectedLeafId !== undefined && input.expectedLeafId !== currentLeaf(session)) {
6958
7060
  return yield* conflict4("stale-leaf", `Expected Session leaf ${String(input.expectedLeafId)} but found ${String(currentLeaf(session))}`);
6959
7061
  }
@@ -6978,6 +7080,9 @@ var memoryLayer26 = Layer35.sync(Service35, () => {
6978
7080
  const session = sessions.get(input.sessionId);
6979
7081
  if (session === undefined)
6980
7082
  return yield* missingSession(input.sessionId);
7083
+ const fence = writerFenceViolation(session, input.expectedWriter);
7084
+ if (fence !== undefined)
7085
+ return yield* conflict4("fenced", fence);
6981
7086
  const appendInput = {
6982
7087
  id: input.id,
6983
7088
  sessionId: input.sessionId,
@@ -7101,36 +7206,36 @@ __export(exports_skill_definition_repository, {
7101
7206
  Service: () => Service36,
7102
7207
  ExecutionSkillPinRow: () => ExecutionSkillPinRow
7103
7208
  });
7104
- import { Context as Context34, Effect as Effect42, HashSet, Layer as Layer36, Schema as Schema40, Semaphore as Semaphore4 } from "effect";
7209
+ import { Context as Context34, Effect as Effect42, HashSet, Layer as Layer36, Schema as Schema41, Semaphore as Semaphore4 } from "effect";
7105
7210
  import { SqlClient as SqlClient24 } from "effect/unstable/sql/SqlClient";
7106
- class SkillDefinitionRepositoryError extends Schema40.TaggedErrorClass()("SkillDefinitionRepositoryError", {
7107
- message: Schema40.String
7211
+ class SkillDefinitionRepositoryError extends Schema41.TaggedErrorClass()("SkillDefinitionRepositoryError", {
7212
+ message: Schema41.String
7108
7213
  }) {
7109
7214
  }
7110
7215
 
7111
7216
  class Service36 extends Context34.Service()("@relayfx/store-sql/skill/skill-definition-repository/Service") {
7112
7217
  }
7113
- var SkillDefinitionRow = Schema40.Struct({
7114
- id: Schema40.String,
7115
- current_revision: Schema40.Finite,
7116
- definition_json: Schema40.Unknown,
7117
- created_at: Schema40.Union([Schema40.Date, Schema40.String, Schema40.Finite]),
7118
- updated_at: Schema40.Union([Schema40.Date, Schema40.String, Schema40.Finite])
7218
+ var SkillDefinitionRow = Schema41.Struct({
7219
+ id: Schema41.String,
7220
+ current_revision: Schema41.Finite,
7221
+ definition_json: Schema41.Unknown,
7222
+ created_at: Schema41.Union([Schema41.Date, Schema41.String, Schema41.Finite]),
7223
+ updated_at: Schema41.Union([Schema41.Date, Schema41.String, Schema41.Finite])
7119
7224
  }).annotate({ identifier: "Relay.SkillDefinition.Row" });
7120
- var SkillDefinitionRevisionRow = Schema40.Struct({
7121
- skill_definition_id: Schema40.String,
7122
- revision: Schema40.Finite,
7123
- definition_json: Schema40.Unknown,
7124
- created_at: Schema40.Union([Schema40.Date, Schema40.String, Schema40.Finite])
7225
+ var SkillDefinitionRevisionRow = Schema41.Struct({
7226
+ skill_definition_id: Schema41.String,
7227
+ revision: Schema41.Finite,
7228
+ definition_json: Schema41.Unknown,
7229
+ created_at: Schema41.Union([Schema41.Date, Schema41.String, Schema41.Finite])
7125
7230
  }).annotate({ identifier: "Relay.SkillDefinitionRevision.Row" });
7126
- var ExecutionSkillPinRow = Schema40.Struct({
7127
- execution_id: Schema40.String,
7128
- skill_definition_id: Schema40.String,
7129
- skill_definition_revision: Schema40.Finite,
7130
- skill_definition_snapshot_json: Schema40.Unknown,
7131
- created_at: Schema40.Union([Schema40.Date, Schema40.String, Schema40.Finite])
7231
+ var ExecutionSkillPinRow = Schema41.Struct({
7232
+ execution_id: Schema41.String,
7233
+ skill_definition_id: Schema41.String,
7234
+ skill_definition_revision: Schema41.Finite,
7235
+ skill_definition_snapshot_json: Schema41.Unknown,
7236
+ created_at: Schema41.Union([Schema41.Date, Schema41.String, Schema41.Finite])
7132
7237
  }).annotate({ identifier: "Relay.ExecutionSkillPin.Row" });
7133
- var cloneDefinition3 = (definition) => Schema40.decodeUnknownSync(exports_skill_schema.Definition)(globalThis.structuredClone(definition));
7238
+ var cloneDefinition3 = (definition) => Schema41.decodeUnknownSync(exports_skill_schema.Definition)(globalThis.structuredClone(definition));
7134
7239
  var toRecord10 = (row) => ({
7135
7240
  id: exports_ids_schema.SkillDefinitionId.make(row.id),
7136
7241
  currentRevision: row.current_revision,
@@ -7186,11 +7291,11 @@ var missingSkillMessage = (requested, records) => {
7186
7291
  return `Skill definition not found: ${requested.find((id) => !HashSet.has(found, id)) ?? requested[0]}`;
7187
7292
  };
7188
7293
  var toRepositoryError12 = (error5) => SkillDefinitionRepositoryError.make({ message: String(error5) });
7189
- var mapPutError2 = (error5) => Schema40.is(SkillDefinitionRepositoryError)(error5) ? error5 : toRepositoryError12(error5);
7190
- var isUniqueViolation = (error5) => !Schema40.is(SkillDefinitionRepositoryError)(error5) && /unique|duplicate/i.test(String(error5));
7191
- var decodeRow12 = (row) => Schema40.decodeUnknownEffect(SkillDefinitionRow)(row).pipe(Effect42.mapError(toRepositoryError12));
7192
- var decodeRevisionRow2 = (row) => Schema40.decodeUnknownEffect(SkillDefinitionRevisionRow)(row).pipe(Effect42.mapError(toRepositoryError12));
7193
- var decodePinRow = (row) => Schema40.decodeUnknownEffect(ExecutionSkillPinRow)(row).pipe(Effect42.mapError(toRepositoryError12));
7294
+ var mapPutError2 = (error5) => Schema41.is(SkillDefinitionRepositoryError)(error5) ? error5 : toRepositoryError12(error5);
7295
+ var isUniqueViolation = (error5) => !Schema41.is(SkillDefinitionRepositoryError)(error5) && /unique|duplicate/i.test(String(error5));
7296
+ var decodeRow12 = (row) => Schema41.decodeUnknownEffect(SkillDefinitionRow)(row).pipe(Effect42.mapError(toRepositoryError12));
7297
+ var decodeRevisionRow2 = (row) => Schema41.decodeUnknownEffect(SkillDefinitionRevisionRow)(row).pipe(Effect42.mapError(toRepositoryError12));
7298
+ var decodePinRow = (row) => Schema41.decodeUnknownEffect(ExecutionSkillPinRow)(row).pipe(Effect42.mapError(toRepositoryError12));
7194
7299
  var layer29 = Layer36.effect(Service36, Effect42.gen(function* () {
7195
7300
  const sql = yield* SqlClient24;
7196
7301
  const columns3 = sql.literal(["id", "current_revision", "definition_json", "created_at", "updated_at"].join(", "));
@@ -7527,37 +7632,37 @@ __export(exports_steering_repository, {
7527
7632
  SteeringDrainRow: () => SteeringDrainRow,
7528
7633
  Service: () => Service37
7529
7634
  });
7530
- import { Context as Context35, Effect as Effect43, Layer as Layer37, Ref as Ref9, Schema as Schema41 } from "effect";
7635
+ import { Context as Context35, Effect as Effect43, Layer as Layer37, Ref as Ref9, Schema as Schema42 } from "effect";
7531
7636
  import { SqlClient as SqlClient25 } from "effect/unstable/sql/SqlClient";
7532
- class SteeringRepositoryError extends Schema41.TaggedErrorClass()("SteeringRepositoryError", {
7533
- message: Schema41.String
7637
+ class SteeringRepositoryError extends Schema42.TaggedErrorClass()("SteeringRepositoryError", {
7638
+ message: Schema42.String
7534
7639
  }) {
7535
7640
  }
7536
7641
 
7537
7642
  class Service37 extends Context35.Service()("@relayfx/store-sql/steering/steering-repository/Service") {
7538
7643
  }
7539
- var SteeringKindSchema = Schema41.Literals(["steering", "follow_up"]);
7540
- var DbTimestamp4 = Schema41.Union([Schema41.Date, Schema41.String, Schema41.Finite]);
7541
- var SteeringMessageRow = Schema41.Struct({
7542
- execution_id: Schema41.String,
7644
+ var SteeringKindSchema = Schema42.Literals(["steering", "follow_up"]);
7645
+ var DbTimestamp4 = Schema42.Union([Schema42.Date, Schema42.String, Schema42.Finite]);
7646
+ var SteeringMessageRow = Schema42.Struct({
7647
+ execution_id: Schema42.String,
7543
7648
  kind: SteeringKindSchema,
7544
- sequence: Schema41.Union([Schema41.Finite, Schema41.String]),
7545
- content_json: Schema41.Unknown,
7546
- drain_id: Schema41.NullishOr(Schema41.String),
7547
- consumed_at: Schema41.NullishOr(DbTimestamp4),
7649
+ sequence: Schema42.Union([Schema42.Finite, Schema42.String]),
7650
+ content_json: Schema42.Unknown,
7651
+ drain_id: Schema42.NullishOr(Schema42.String),
7652
+ consumed_at: Schema42.NullishOr(DbTimestamp4),
7548
7653
  created_at: DbTimestamp4
7549
7654
  }).annotate({ identifier: "Relay.SteeringMessage.Row" });
7550
- var SteeringDrainRow = Schema41.Struct({
7551
- execution_id: Schema41.String,
7655
+ var SteeringDrainRow = Schema42.Struct({
7656
+ execution_id: Schema42.String,
7552
7657
  kind: SteeringKindSchema,
7553
- drain_id: Schema41.String,
7554
- message_sequences_json: Schema41.Unknown,
7658
+ drain_id: Schema42.String,
7659
+ message_sequences_json: Schema42.Unknown,
7555
7660
  created_at: DbTimestamp4
7556
7661
  }).annotate({ identifier: "Relay.SteeringDrain.Row" });
7557
7662
  var toRepositoryError13 = (error5) => SteeringRepositoryError.make({ message: String(error5) });
7558
- var mapTransactionError = (effect) => effect.pipe(Effect43.mapError((error5) => Schema41.is(SteeringRepositoryError)(error5) ? error5 : toRepositoryError13(error5)));
7559
- var decodeMessageRow = (row) => Schema41.decodeUnknownEffect(SteeringMessageRow)(row).pipe(Effect43.mapError(toRepositoryError13));
7560
- var decodeDrainRow = (row) => Schema41.decodeUnknownEffect(SteeringDrainRow)(row).pipe(Effect43.mapError(toRepositoryError13));
7663
+ var mapTransactionError = (effect) => effect.pipe(Effect43.mapError((error5) => Schema42.is(SteeringRepositoryError)(error5) ? error5 : toRepositoryError13(error5)));
7664
+ var decodeMessageRow = (row) => Schema42.decodeUnknownEffect(SteeringMessageRow)(row).pipe(Effect43.mapError(toRepositoryError13));
7665
+ var decodeDrainRow = (row) => Schema42.decodeUnknownEffect(SteeringDrainRow)(row).pipe(Effect43.mapError(toRepositoryError13));
7561
7666
  var toMessageRecord = (row) => {
7562
7667
  const consumedAt = fromNullableDbTimestamp(row.consumed_at);
7563
7668
  return {
@@ -7866,29 +7971,29 @@ __export(exports_tool_call_repository, {
7866
7971
  DuplicateToolResult: () => DuplicateToolResult,
7867
7972
  DuplicateToolCall: () => DuplicateToolCall
7868
7973
  });
7869
- import { Context as Context36, Effect as Effect47, Layer as Layer38, Schema as Schema45 } from "effect";
7974
+ import { Context as Context36, Effect as Effect47, Layer as Layer38, Schema as Schema46 } from "effect";
7870
7975
  import { dual } from "effect/Function";
7871
7976
 
7872
7977
  // ../store-sql/src/tool/tool-call-records.ts
7873
- import { Effect as Effect46, Schema as Schema44 } from "effect";
7978
+ import { Effect as Effect46, Schema as Schema45 } from "effect";
7874
7979
  import { SqlClient as SqlClient26 } from "effect/unstable/sql/SqlClient";
7875
7980
  import { isSqlError as isSqlError2 } from "effect/unstable/sql/SqlError";
7876
7981
 
7877
7982
  // ../store-sql/src/tool/tool-attempt-records.ts
7878
- import { Effect as Effect44, Schema as Schema42 } from "effect";
7879
- var toolAttemptRow = Schema42.Struct({
7880
- id: Schema42.String,
7881
- tool_call_id: Schema42.String,
7882
- attempt_number: Schema42.Union([Schema42.Finite, Schema42.String, Schema42.BigInt]),
7883
- state: Schema42.String,
7884
- worker_id: Schema42.NullishOr(Schema42.String),
7885
- claim_expires_at: Schema42.NullishOr(Schema42.Union([Schema42.Date, Schema42.String, Schema42.Finite])),
7886
- error: Schema42.NullishOr(Schema42.String),
7887
- created_at: Schema42.Union([Schema42.Date, Schema42.String, Schema42.Finite]),
7888
- completed_at: Schema42.NullishOr(Schema42.Union([Schema42.Date, Schema42.String, Schema42.Finite]))
7983
+ import { Effect as Effect44, Schema as Schema43 } from "effect";
7984
+ var toolAttemptRow = Schema43.Struct({
7985
+ id: Schema43.String,
7986
+ tool_call_id: Schema43.String,
7987
+ attempt_number: Schema43.Union([Schema43.Finite, Schema43.String, Schema43.BigInt]),
7988
+ state: Schema43.String,
7989
+ worker_id: Schema43.NullishOr(Schema43.String),
7990
+ claim_expires_at: Schema43.NullishOr(Schema43.Union([Schema43.Date, Schema43.String, Schema43.Finite])),
7991
+ error: Schema43.NullishOr(Schema43.String),
7992
+ created_at: Schema43.Union([Schema43.Date, Schema43.String, Schema43.Finite]),
7993
+ completed_at: Schema43.NullishOr(Schema43.Union([Schema43.Date, Schema43.String, Schema43.Finite]))
7889
7994
  }).annotate({ identifier: "Relay.ToolAttempt.Row" });
7890
- var MaxAttemptRow = Schema42.Struct({
7891
- max_attempt: Schema42.NullishOr(Schema42.Union([Schema42.Finite, Schema42.String, Schema42.BigInt]))
7995
+ var MaxAttemptRow = Schema43.Struct({
7996
+ max_attempt: Schema43.NullishOr(Schema43.Union([Schema43.Finite, Schema43.String, Schema43.BigInt]))
7892
7997
  });
7893
7998
  var toolAttemptId = (attemptNumber) => exports_ids_schema.ToolAttemptId.make(`tool-attempt:${attemptNumber}`);
7894
7999
  var makeToolAttemptRecordOperations = ({
@@ -7912,15 +8017,15 @@ var makeToolAttemptRecordOperations = ({
7912
8017
  id: exports_ids_schema.ToolAttemptId.make(row.id),
7913
8018
  callId: exports_ids_schema.ToolCallId.make(row.tool_call_id),
7914
8019
  attemptNumber: Number(row.attempt_number),
7915
- state: Schema42.decodeUnknownSync(exports_tool_schema.AttemptState)(row.state),
8020
+ state: Schema43.decodeUnknownSync(exports_tool_schema.AttemptState)(row.state),
7916
8021
  ...row.worker_id === null || row.worker_id === undefined ? {} : { workerId: row.worker_id },
7917
8022
  ...row.claim_expires_at === null || row.claim_expires_at === undefined ? {} : { claimExpiresAt: fromDbTimestamp(row.claim_expires_at) },
7918
8023
  ...row.error === null || row.error === undefined ? {} : { error: row.error },
7919
8024
  createdAt: fromDbTimestamp(row.created_at),
7920
8025
  ...row.completed_at === null || row.completed_at === undefined ? {} : { completedAt: fromDbTimestamp(row.completed_at) }
7921
8026
  });
7922
- const decodeAttemptRow = (row) => Schema42.decodeUnknownEffect(toolAttemptRow)(row).pipe(Effect44.mapError(toRepositoryError14));
7923
- const decodeMaxAttemptRow = (row) => Schema42.decodeUnknownEffect(Schema42.UndefinedOr(MaxAttemptRow))(row).pipe(Effect44.mapError(toRepositoryError14));
8027
+ const decodeAttemptRow = (row) => Schema43.decodeUnknownEffect(toolAttemptRow)(row).pipe(Effect44.mapError(toRepositoryError14));
8028
+ const decodeMaxAttemptRow = (row) => Schema43.decodeUnknownEffect(Schema43.UndefinedOr(MaxAttemptRow))(row).pipe(Effect44.mapError(toRepositoryError14));
7924
8029
  const selectAttempts = (tenantId, executionId, callId) => sql`
7925
8030
  SELECT ${attemptColumns}
7926
8031
  FROM relay_tool_attempts
@@ -8003,13 +8108,13 @@ var makeToolAttemptRecordOperations = ({
8003
8108
  };
8004
8109
 
8005
8110
  // ../store-sql/src/tool/tool-work-operations.ts
8006
- import { Effect as Effect45, Schema as Schema43 } from "effect";
8007
- var ExpiredCallRow = Schema43.Struct({
8008
- id: Schema43.String,
8009
- execution_id: Schema43.String,
8010
- active_attempt_id: Schema43.NullishOr(Schema43.String)
8111
+ import { Effect as Effect45, Schema as Schema44 } from "effect";
8112
+ var ExpiredCallRow = Schema44.Struct({
8113
+ id: Schema44.String,
8114
+ execution_id: Schema44.String,
8115
+ active_attempt_id: Schema44.NullishOr(Schema44.String)
8011
8116
  });
8012
- var IdRow = Schema43.Struct({ id: Schema43.String, execution_id: Schema43.String });
8117
+ var IdRow = Schema44.Struct({ id: Schema44.String, execution_id: Schema44.String });
8013
8118
  var makeToolWorkOperations = ({
8014
8119
  records,
8015
8120
  attempts,
@@ -8172,7 +8277,7 @@ var makeToolWorkOperations = ({
8172
8277
  WHERE tenant_id = ${tenantId} AND placement_kind = 'remote' AND placement_key = ${input.queue}
8173
8278
  AND state = 'running' AND claim_expires_at IS NOT NULL AND claim_expires_at <= ${ts(input.now)}
8174
8279
  `.pipe(Effect45.mapError(toRepositoryError14));
8175
- const expired = yield* Schema43.decodeUnknownEffect(Schema43.Array(ExpiredCallRow))(expiredRows).pipe(Effect45.mapError(toRepositoryError14));
8280
+ const expired = yield* Schema44.decodeUnknownEffect(Schema44.Array(ExpiredCallRow))(expiredRows).pipe(Effect45.mapError(toRepositoryError14));
8176
8281
  for (const row of expired) {
8177
8282
  const executionId2 = exports_ids_schema.ExecutionId.make(row.execution_id);
8178
8283
  if (row.active_attempt_id !== null && row.active_attempt_id !== undefined) {
@@ -8186,7 +8291,7 @@ var makeToolWorkOperations = ({
8186
8291
  `.pipe(Effect45.mapError(toRepositoryError14));
8187
8292
  }
8188
8293
  const candidateRows = yield* selectClaimCandidate(tenantId, input).pipe(Effect45.mapError(toRepositoryError14));
8189
- const candidates = yield* Schema43.decodeUnknownEffect(Schema43.Array(IdRow))(candidateRows).pipe(Effect45.mapError(toRepositoryError14));
8294
+ const candidates = yield* Schema44.decodeUnknownEffect(Schema44.Array(IdRow))(candidateRows).pipe(Effect45.mapError(toRepositoryError14));
8190
8295
  const candidate = candidates[0];
8191
8296
  if (candidate === undefined)
8192
8297
  return;
@@ -8361,54 +8466,54 @@ var makeToolWorkOperations = ({
8361
8466
  };
8362
8467
 
8363
8468
  // ../store-sql/src/tool/tool-call-records.ts
8364
- var toolCallRow = Schema44.Struct({
8365
- id: Schema44.String,
8366
- execution_id: Schema44.String,
8367
- name: Schema44.String,
8368
- input_json: Schema44.Unknown,
8369
- definition_json: Schema44.NullishOr(Schema44.Unknown),
8370
- placement_kind: Schema44.String,
8371
- placement_key: Schema44.NullishOr(Schema44.String),
8372
- state: Schema44.String,
8373
- wait_id: Schema44.NullishOr(Schema44.String),
8374
- idempotency_key: Schema44.String,
8375
- available_at: Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite]),
8376
- active_attempt_id: Schema44.NullishOr(Schema44.String),
8377
- claim_owner: Schema44.NullishOr(Schema44.String),
8378
- claimed_at: Schema44.NullishOr(Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite])),
8379
- claim_expires_at: Schema44.NullishOr(Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite])),
8380
- external_outcome_json: Schema44.NullishOr(Schema44.Unknown),
8381
- external_outcome_at: Schema44.NullishOr(Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite])),
8382
- metadata_json: Schema44.Unknown,
8383
- created_at: Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite]),
8384
- updated_at: Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite])
8469
+ var toolCallRow = Schema45.Struct({
8470
+ id: Schema45.String,
8471
+ execution_id: Schema45.String,
8472
+ name: Schema45.String,
8473
+ input_json: Schema45.Unknown,
8474
+ definition_json: Schema45.NullishOr(Schema45.Unknown),
8475
+ placement_kind: Schema45.String,
8476
+ placement_key: Schema45.NullishOr(Schema45.String),
8477
+ state: Schema45.String,
8478
+ wait_id: Schema45.NullishOr(Schema45.String),
8479
+ idempotency_key: Schema45.String,
8480
+ available_at: Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite]),
8481
+ active_attempt_id: Schema45.NullishOr(Schema45.String),
8482
+ claim_owner: Schema45.NullishOr(Schema45.String),
8483
+ claimed_at: Schema45.NullishOr(Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite])),
8484
+ claim_expires_at: Schema45.NullishOr(Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite])),
8485
+ external_outcome_json: Schema45.NullishOr(Schema45.Unknown),
8486
+ external_outcome_at: Schema45.NullishOr(Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite])),
8487
+ metadata_json: Schema45.Unknown,
8488
+ created_at: Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite]),
8489
+ updated_at: Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite])
8385
8490
  }).annotate({ identifier: "Relay.ToolCall.Row" });
8386
- var toolResultRow = Schema44.Struct({
8387
- tool_call_id: Schema44.String,
8388
- output_json: Schema44.Unknown,
8389
- error: Schema44.NullishOr(Schema44.String),
8390
- metadata_json: Schema44.Unknown,
8391
- created_at: Schema44.Union([Schema44.Date, Schema44.String, Schema44.Finite])
8491
+ var toolResultRow = Schema45.Struct({
8492
+ tool_call_id: Schema45.String,
8493
+ output_json: Schema45.Unknown,
8494
+ error: Schema45.NullishOr(Schema45.String),
8495
+ metadata_json: Schema45.Unknown,
8496
+ created_at: Schema45.Union([Schema45.Date, Schema45.String, Schema45.Finite])
8392
8497
  }).annotate({ identifier: "Relay.ToolResult.Row" });
8393
8498
  var metadata8 = (input) => input ?? {};
8394
8499
  var normalizeCall = (call) => ({ ...call, metadata: metadata8(call.metadata) });
8395
8500
  var sameCallIdentity = (left, right) => exports_shared_schema.canonicalEquals(normalizeCall(left), normalizeCall(right));
8396
8501
  var toolCallRecordIdentity = { sameCallIdentity };
8397
- var placementFromRow = (row) => Schema44.decodeUnknownSync(exports_tool_schema.Placement)(row.placement_kind === "remote" ? { kind: "remote", queue: row.placement_key } : row.placement_kind === "mcp" ? { kind: "mcp", server_id: row.placement_key } : { kind: row.placement_kind });
8502
+ var placementFromRow = (row) => Schema45.decodeUnknownSync(exports_tool_schema.Placement)(row.placement_kind === "remote" ? { kind: "remote", queue: row.placement_key } : row.placement_kind === "mcp" ? { kind: "mcp", server_id: row.placement_key } : { kind: row.placement_kind });
8398
8503
  var toCallRecord = (row) => {
8399
- const definition = row.definition_json === null || row.definition_json === undefined ? undefined : Schema44.decodeUnknownSync(exports_tool_schema.Definition)(decodeJson(row.definition_json));
8400
- const outcome = row.external_outcome_json === null || row.external_outcome_json === undefined ? undefined : Schema44.decodeUnknownSync(exports_tool_schema.ExternalOutcome)(decodeJson(row.external_outcome_json));
8504
+ const definition = row.definition_json === null || row.definition_json === undefined ? undefined : Schema45.decodeUnknownSync(exports_tool_schema.Definition)(decodeJson(row.definition_json));
8505
+ const outcome = row.external_outcome_json === null || row.external_outcome_json === undefined ? undefined : Schema45.decodeUnknownSync(exports_tool_schema.ExternalOutcome)(decodeJson(row.external_outcome_json));
8401
8506
  return {
8402
8507
  executionId: exports_ids_schema.ExecutionId.make(row.execution_id),
8403
8508
  call: normalizeCall({
8404
8509
  id: exports_ids_schema.ToolCallId.make(row.id),
8405
8510
  name: row.name,
8406
- input: Schema44.decodeUnknownSync(exports_shared_schema.JsonValue)(decodeJson(row.input_json)),
8407
- metadata: Schema44.decodeUnknownSync(exports_shared_schema.Metadata)(decodeJson(row.metadata_json))
8511
+ input: Schema45.decodeUnknownSync(exports_shared_schema.JsonValue)(decodeJson(row.input_json)),
8512
+ metadata: Schema45.decodeUnknownSync(exports_shared_schema.Metadata)(decodeJson(row.metadata_json))
8408
8513
  }),
8409
8514
  ...definition === undefined ? {} : { definition },
8410
8515
  placement: placementFromRow(row),
8411
- state: Schema44.decodeUnknownSync(exports_tool_schema.CallState)(row.state),
8516
+ state: Schema45.decodeUnknownSync(exports_tool_schema.CallState)(row.state),
8412
8517
  ...row.wait_id === null || row.wait_id === undefined ? {} : { waitId: exports_ids_schema.WaitId.make(row.wait_id) },
8413
8518
  idempotencyKey: row.idempotency_key,
8414
8519
  availableAt: fromDbTimestamp(row.available_at),
@@ -8425,9 +8530,9 @@ var toCallRecord = (row) => {
8425
8530
  var toResultRecord = (row) => ({
8426
8531
  result: {
8427
8532
  call_id: exports_ids_schema.ToolCallId.make(row.tool_call_id),
8428
- output: Schema44.decodeUnknownSync(exports_shared_schema.JsonValue)(decodeJson(row.output_json)),
8533
+ output: Schema45.decodeUnknownSync(exports_shared_schema.JsonValue)(decodeJson(row.output_json)),
8429
8534
  ...row.error === null || row.error === undefined ? {} : { error: row.error },
8430
- metadata: Schema44.decodeUnknownSync(exports_shared_schema.Metadata)(decodeJson(row.metadata_json))
8535
+ metadata: Schema45.decodeUnknownSync(exports_shared_schema.Metadata)(decodeJson(row.metadata_json))
8431
8536
  },
8432
8537
  createdAt: fromDbTimestamp(row.created_at)
8433
8538
  });
@@ -8544,8 +8649,8 @@ var makeToolCallRecordSupport = ({ sql, errors, toolCallIdempotencyKey }) => {
8544
8649
  `,
8545
8650
  orElse: () => selectCallByKey
8546
8651
  });
8547
- const decodeCallRow = (row) => Schema44.decodeUnknownEffect(toolCallRow)(row).pipe(Effect46.mapError(toRepositoryError14));
8548
- const decodeResultRow = (row) => Schema44.decodeUnknownEffect(toolResultRow)(row).pipe(Effect46.mapError(toRepositoryError14));
8652
+ const decodeCallRow = (row) => Schema45.decodeUnknownEffect(toolCallRow)(row).pipe(Effect46.mapError(toRepositoryError14));
8653
+ const decodeResultRow = (row) => Schema45.decodeUnknownEffect(toolResultRow)(row).pipe(Effect46.mapError(toRepositoryError14));
8549
8654
  const decodeCall = Effect46.fn("ToolCallRepository.decodeCall")(function* (row) {
8550
8655
  const decoded = yield* decodeCallRow(row);
8551
8656
  return yield* Effect46.try({ try: () => toCallRecord(decoded), catch: toRepositoryError14 });
@@ -8677,44 +8782,44 @@ var makeToolCallRepository = ({
8677
8782
  });
8678
8783
 
8679
8784
  // ../store-sql/src/tool/tool-call-repository.ts
8680
- class ToolCallRepositoryError extends Schema45.TaggedErrorClass()("ToolCallRepositoryError", {
8681
- message: Schema45.String
8785
+ class ToolCallRepositoryError extends Schema46.TaggedErrorClass()("ToolCallRepositoryError", {
8786
+ message: Schema46.String
8682
8787
  }) {
8683
8788
  }
8684
8789
 
8685
- class ToolCallNotFound extends Schema45.TaggedErrorClass()("ToolCallNotFound", {
8790
+ class ToolCallNotFound extends Schema46.TaggedErrorClass()("ToolCallNotFound", {
8686
8791
  id: exports_ids_schema.ToolCallId
8687
8792
  }) {
8688
8793
  }
8689
8794
 
8690
- class DuplicateToolCall extends Schema45.TaggedErrorClass()("DuplicateToolCall", {
8795
+ class DuplicateToolCall extends Schema46.TaggedErrorClass()("DuplicateToolCall", {
8691
8796
  id: exports_ids_schema.ToolCallId
8692
8797
  }) {
8693
8798
  }
8694
8799
 
8695
- class DuplicateToolResult extends Schema45.TaggedErrorClass()("DuplicateToolResult", {
8800
+ class DuplicateToolResult extends Schema46.TaggedErrorClass()("DuplicateToolResult", {
8696
8801
  call_id: exports_ids_schema.ToolCallId
8697
8802
  }) {
8698
8803
  }
8699
8804
 
8700
- class ToolCallConflict extends Schema45.TaggedErrorClass()("ToolCallConflict", {
8805
+ class ToolCallConflict extends Schema46.TaggedErrorClass()("ToolCallConflict", {
8701
8806
  id: exports_ids_schema.ToolCallId
8702
8807
  }) {
8703
8808
  }
8704
8809
 
8705
- class ToolCallTransitionRejected extends Schema45.TaggedErrorClass()("ToolCallTransitionRejected", {
8810
+ class ToolCallTransitionRejected extends Schema46.TaggedErrorClass()("ToolCallTransitionRejected", {
8706
8811
  id: exports_ids_schema.ToolCallId,
8707
- message: Schema45.String
8812
+ message: Schema46.String
8708
8813
  }) {
8709
8814
  }
8710
8815
 
8711
- class ToolOutcomeConflict extends Schema45.TaggedErrorClass()("ToolOutcomeConflict", {
8816
+ class ToolOutcomeConflict extends Schema46.TaggedErrorClass()("ToolOutcomeConflict", {
8712
8817
  id: exports_ids_schema.ToolCallId
8713
8818
  }) {
8714
8819
  }
8715
8820
 
8716
- class ToolClaimRejected extends Schema45.TaggedErrorClass()("ToolClaimRejected", {
8717
- message: Schema45.String
8821
+ class ToolClaimRejected extends Schema46.TaggedErrorClass()("ToolClaimRejected", {
8822
+ message: Schema46.String
8718
8823
  }) {
8719
8824
  }
8720
8825
  var lengthPrefixed = (value) => `${[...value].length}:${value}`;
@@ -9181,57 +9286,57 @@ __export(exports_workspace_lease_repository, {
9181
9286
  Service: () => Service39,
9182
9287
  DuplicateWorkspaceLease: () => DuplicateWorkspaceLease
9183
9288
  });
9184
- import { Context as Context37, Effect as Effect48, Layer as Layer39, Schema as Schema46 } from "effect";
9289
+ import { Context as Context37, Effect as Effect48, Layer as Layer39, Schema as Schema47 } from "effect";
9185
9290
  import { SqlClient as SqlClient27 } from "effect/unstable/sql/SqlClient";
9186
- class WorkspaceLeaseRepositoryError extends Schema46.TaggedErrorClass()("WorkspaceLeaseRepositoryError", {
9187
- message: Schema46.String
9291
+ class WorkspaceLeaseRepositoryError extends Schema47.TaggedErrorClass()("WorkspaceLeaseRepositoryError", {
9292
+ message: Schema47.String
9188
9293
  }) {
9189
9294
  }
9190
9295
 
9191
- class DuplicateWorkspaceLease extends Schema46.TaggedErrorClass()("DuplicateWorkspaceLease", {
9296
+ class DuplicateWorkspaceLease extends Schema47.TaggedErrorClass()("DuplicateWorkspaceLease", {
9192
9297
  execution_id: exports_ids_schema.ExecutionId
9193
9298
  }) {
9194
9299
  }
9195
9300
 
9196
- class WorkspaceLeaseNotFound extends Schema46.TaggedErrorClass()("WorkspaceLeaseNotFound", {
9301
+ class WorkspaceLeaseNotFound extends Schema47.TaggedErrorClass()("WorkspaceLeaseNotFound", {
9197
9302
  execution_id: exports_ids_schema.ExecutionId
9198
9303
  }) {
9199
9304
  }
9200
9305
 
9201
9306
  class Service39 extends Context37.Service()("@relayfx/store-sql/workspace/workspace-lease-repository/Service") {
9202
9307
  }
9203
- var WorkspaceLeaseRow = Schema46.Struct({
9204
- id: Schema46.String,
9205
- execution_id: Schema46.String,
9206
- provider_key: Schema46.String,
9207
- sandbox_ref: Schema46.NullishOr(Schema46.String),
9208
- latest_snapshot_ref: Schema46.NullishOr(Schema46.String),
9209
- status: Schema46.String,
9210
- resume_strategy: Schema46.String,
9211
- region: Schema46.NullishOr(Schema46.String),
9212
- request_json: Schema46.NullishOr(Schema46.Unknown),
9213
- metadata_json: Schema46.Unknown,
9214
- created_at: Schema46.Union([Schema46.Date, Schema46.String, Schema46.Finite]),
9215
- updated_at: Schema46.Union([Schema46.Date, Schema46.String, Schema46.Finite])
9308
+ var WorkspaceLeaseRow = Schema47.Struct({
9309
+ id: Schema47.String,
9310
+ execution_id: Schema47.String,
9311
+ provider_key: Schema47.String,
9312
+ sandbox_ref: Schema47.NullishOr(Schema47.String),
9313
+ latest_snapshot_ref: Schema47.NullishOr(Schema47.String),
9314
+ status: Schema47.String,
9315
+ resume_strategy: Schema47.String,
9316
+ region: Schema47.NullishOr(Schema47.String),
9317
+ request_json: Schema47.NullishOr(Schema47.Unknown),
9318
+ metadata_json: Schema47.Unknown,
9319
+ created_at: Schema47.Union([Schema47.Date, Schema47.String, Schema47.Finite]),
9320
+ updated_at: Schema47.Union([Schema47.Date, Schema47.String, Schema47.Finite])
9216
9321
  }).annotate({ identifier: "Relay.WorkspaceLease.Row" });
9217
- var WorkspaceSnapshotRow = Schema46.Struct({
9218
- id: Schema46.String,
9219
- lease_id: Schema46.String,
9220
- execution_id: Schema46.String,
9221
- reason: Schema46.String,
9222
- snapshot_ref: Schema46.String,
9223
- metadata_json: Schema46.Unknown,
9224
- created_at: Schema46.Union([Schema46.Date, Schema46.String, Schema46.Finite])
9322
+ var WorkspaceSnapshotRow = Schema47.Struct({
9323
+ id: Schema47.String,
9324
+ lease_id: Schema47.String,
9325
+ execution_id: Schema47.String,
9326
+ reason: Schema47.String,
9327
+ snapshot_ref: Schema47.String,
9328
+ metadata_json: Schema47.Unknown,
9329
+ created_at: Schema47.Union([Schema47.Date, Schema47.String, Schema47.Finite])
9225
9330
  }).annotate({ identifier: "Relay.WorkspaceSnapshot.Row" });
9226
9331
  var metadata9 = (input) => input ?? {};
9227
9332
  var terminalStatuses = new Set(["released", "failed"]);
9228
9333
  var isActive = (record2) => !terminalStatuses.has(record2.status);
9229
- var cloneLease = (record2) => Schema46.decodeUnknownSync(exports_workspace_schema.WorkspaceLeaseRecord)(globalThis.structuredClone(record2));
9230
- var cloneSnapshot = (record2) => Schema46.decodeUnknownSync(exports_workspace_schema.WorkspaceSnapshotRecord)(globalThis.structuredClone(record2));
9334
+ var cloneLease = (record2) => Schema47.decodeUnknownSync(exports_workspace_schema.WorkspaceLeaseRecord)(globalThis.structuredClone(record2));
9335
+ var cloneSnapshot = (record2) => Schema47.decodeUnknownSync(exports_workspace_schema.WorkspaceSnapshotRecord)(globalThis.structuredClone(record2));
9231
9336
  var toRepositoryError14 = (error5) => WorkspaceLeaseRepositoryError.make({ message: String(error5) });
9232
- var decodeLeaseRow = (row) => Schema46.decodeUnknownEffect(WorkspaceLeaseRow)(row).pipe(Effect48.mapError(toRepositoryError14));
9233
- var decodeSnapshotRow = (row) => Schema46.decodeUnknownEffect(WorkspaceSnapshotRow)(row).pipe(Effect48.mapError(toRepositoryError14));
9234
- var decodeRequest = (value) => Schema46.decodeUnknownSync(exports_workspace_schema.WorkspaceRequest)(decodeJson(value));
9337
+ var decodeLeaseRow = (row) => Schema47.decodeUnknownEffect(WorkspaceLeaseRow)(row).pipe(Effect48.mapError(toRepositoryError14));
9338
+ var decodeSnapshotRow = (row) => Schema47.decodeUnknownEffect(WorkspaceSnapshotRow)(row).pipe(Effect48.mapError(toRepositoryError14));
9339
+ var decodeRequest = (value) => Schema47.decodeUnknownSync(exports_workspace_schema.WorkspaceRequest)(decodeJson(value));
9235
9340
  var toLeaseRecord = (row) => ({
9236
9341
  id: exports_ids_schema.WorkspaceLeaseId.make(row.id),
9237
9342
  execution_id: exports_ids_schema.ExecutionId.make(row.execution_id),
@@ -9584,10 +9689,10 @@ __export(exports_workflow_definition_repository, {
9584
9689
  Service: () => Service40,
9585
9690
  RepositoryError: () => RepositoryError
9586
9691
  });
9587
- import { Clock as Clock4, Context as Context38, Effect as Effect49, Layer as Layer40, Schema as Schema47 } from "effect";
9692
+ import { Clock as Clock4, Context as Context38, Effect as Effect49, Layer as Layer40, Schema as Schema48 } from "effect";
9588
9693
  import { SqlClient as SqlClient28 } from "effect/unstable/sql/SqlClient";
9589
- class RepositoryError extends Schema47.TaggedErrorClass()("WorkflowDefinitionRepositoryError", {
9590
- message: Schema47.String
9694
+ class RepositoryError extends Schema48.TaggedErrorClass()("WorkflowDefinitionRepositoryError", {
9695
+ message: Schema48.String
9591
9696
  }) {
9592
9697
  }
9593
9698
 
@@ -9841,8 +9946,8 @@ var transition2 = (sql, tenant, id, status, now, data) => sql.withTransaction(Ef
9841
9946
  var decodeDefinition = (row) => ({
9842
9947
  id: exports_ids_schema.WorkflowDefinitionId.make(row.workflow_definition_id),
9843
9948
  revision: Number(row.revision),
9844
- digest: Schema47.decodeUnknownSync(exports_workflow_schema.DefinitionDigest)(row.digest),
9845
- definition: Schema47.decodeUnknownSync(exports_workflow_schema.Definition)(decodeJson(row.definition_json)),
9949
+ digest: Schema48.decodeUnknownSync(exports_workflow_schema.DefinitionDigest)(row.digest),
9950
+ definition: Schema48.decodeUnknownSync(exports_workflow_schema.Definition)(decodeJson(row.definition_json)),
9846
9951
  created_at: fromDbTimestamp(row.created_at)
9847
9952
  });
9848
9953
  var decodeRun = (row) => ({
@@ -9850,19 +9955,19 @@ var decodeRun = (row) => ({
9850
9955
  pin: {
9851
9956
  workflow_definition_id: exports_ids_schema.WorkflowDefinitionId.make(row.workflow_definition_id),
9852
9957
  workflow_definition_revision: Number(row.workflow_definition_revision),
9853
- workflow_definition_digest: Schema47.decodeUnknownSync(exports_workflow_schema.DefinitionDigest)(row.workflow_definition_digest)
9958
+ workflow_definition_digest: Schema48.decodeUnknownSync(exports_workflow_schema.DefinitionDigest)(row.workflow_definition_digest)
9854
9959
  },
9855
- status: Schema47.decodeUnknownSync(exports_workflow_schema.RunStatus)(row.status),
9960
+ status: Schema48.decodeUnknownSync(exports_workflow_schema.RunStatus)(row.status),
9856
9961
  created_at: fromDbTimestamp(row.created_at),
9857
9962
  updated_at: fromDbTimestamp(row.updated_at)
9858
9963
  });
9859
9964
  var decodeOperation = (row) => ({
9860
9965
  execution_id: exports_ids_schema.ExecutionId.make(row.execution_id),
9861
9966
  operation_id: exports_ids_schema.WorkflowOperationId.make(row.operation_id),
9862
- status: Schema47.decodeUnknownSync(exports_workflow_schema.OperationStatus)(row.status),
9967
+ status: Schema48.decodeUnknownSync(exports_workflow_schema.OperationStatus)(row.status),
9863
9968
  ...row.fan_out_id === null || row.fan_out_id === undefined ? {} : { fan_out_id: exports_ids_schema.ChildFanOutId.make(row.fan_out_id) },
9864
9969
  ...row.decision === null || row.decision === undefined ? {} : { decision: Boolean(row.decision) },
9865
- ...row.output_json === null || row.output_json === undefined ? {} : { output: Schema47.decodeUnknownSync(exports_workflow_schema.OperationState.fields.output)(decodeJson(row.output_json)) },
9970
+ ...row.output_json === null || row.output_json === undefined ? {} : { output: Schema48.decodeUnknownSync(exports_workflow_schema.OperationState.fields.output)(decodeJson(row.output_json)) },
9866
9971
  ...row.attempt === null || row.attempt === undefined ? {} : { attempt: Number(row.attempt) },
9867
9972
  ...row.backoff_until === null || row.backoff_until === undefined ? {} : { backoff_until: fromDbTimestamp(row.backoff_until) },
9868
9973
  ...row.compensation_operation_id === null || row.compensation_operation_id === undefined ? {} : { compensation_operation_id: exports_ids_schema.WorkflowOperationId.make(row.compensation_operation_id) },
@@ -9873,17 +9978,17 @@ var decodeOperation = (row) => ({
9873
9978
  var decodeLifecycle = (row) => ({
9874
9979
  execution_id: exports_ids_schema.ExecutionId.make(row.execution_id),
9875
9980
  sequence: Number(row.sequence),
9876
- type: Schema47.decodeUnknownSync(exports_workflow_schema.LifecycleEventType)(row.event_type),
9981
+ type: Schema48.decodeUnknownSync(exports_workflow_schema.LifecycleEventType)(row.event_type),
9877
9982
  ...row.operation_id === null || row.operation_id === undefined ? {} : { operation_id: exports_ids_schema.WorkflowOperationId.make(row.operation_id) },
9878
- ...row.data_json === null || row.data_json === undefined ? {} : { data: Schema47.decodeUnknownSync(exports_workflow_schema.LifecycleEvent.fields.data)(decodeJson(row.data_json)) },
9983
+ ...row.data_json === null || row.data_json === undefined ? {} : { data: Schema48.decodeUnknownSync(exports_workflow_schema.LifecycleEvent.fields.data)(decodeJson(row.data_json)) },
9879
9984
  created_at: fromDbTimestamp(row.created_at)
9880
9985
  });
9881
9986
  // ../runtime/src/tool/tool-runtime-service.ts
9882
9987
  import { Tool as AiTool } from "effect/unstable/ai";
9883
- import { Chunk, Context as Context41, Effect as Effect55, Function as Function8, HashSet as HashSet3, Layer as Layer45, Option as Option12, Ref as Ref12, Schema as Schema50, Sink, Stream as Stream10 } from "effect";
9988
+ import { Chunk, Context as Context41, Effect as Effect55, Function as Function8, HashSet as HashSet3, Layer as Layer45, Option as Option12, Ref as Ref12, Schema as Schema51, Sink, Stream as Stream10 } from "effect";
9884
9989
 
9885
9990
  // ../runtime/src/execution/event-log-service.ts
9886
- import { Context as Context39, Effect as Effect53, Function as Function7, Layer as Layer43, Option as Option10, Schema as Schema48, Stream as Stream9 } from "effect";
9991
+ import { Context as Context39, Effect as Effect53, Function as Function7, Layer as Layer43, Option as Option10, Schema as Schema49, Stream as Stream9 } from "effect";
9887
9992
 
9888
9993
  // ../runtime/src/execution/event-log-memory.ts
9889
9994
  import { Effect as Effect51, HashMap as HashMap2, HashSet as HashSet2, Layer as Layer41, Option as Option8, PubSub as PubSub5, Ref as Ref10, Stream as Stream7 } from "effect";
@@ -10236,14 +10341,14 @@ var makeRepositoryLayer = (eventLog) => {
10236
10341
  };
10237
10342
 
10238
10343
  // ../runtime/src/execution/event-log-service.ts
10239
- class EventLogCursorNotFound2 extends Schema48.TaggedErrorClass()("EventLogCursorNotFound", {
10344
+ class EventLogCursorNotFound2 extends Schema49.TaggedErrorClass()("EventLogCursorNotFound", {
10240
10345
  execution_id: exports_ids_schema.ExecutionId,
10241
10346
  cursor: exports_shared_schema.NonEmptyString
10242
10347
  }) {
10243
10348
  }
10244
10349
 
10245
- class EventLogError extends Schema48.TaggedErrorClass()("EventLogError", {
10246
- message: Schema48.String
10350
+ class EventLogError extends Schema49.TaggedErrorClass()("EventLogError", {
10351
+ message: Schema49.String
10247
10352
  }) {
10248
10353
  }
10249
10354
 
@@ -10312,19 +10417,19 @@ var sumUsage2 = Effect53.fn("EventLog.sumUsage.call")(function* (executionId) {
10312
10417
  });
10313
10418
 
10314
10419
  // ../runtime/src/wait/wait-service.ts
10315
- import { Context as Context40, Duration as Duration2, Effect as Effect54, Layer as Layer44, Option as Option11, Schema as Schema49 } from "effect";
10316
- class WaitNotFound2 extends Schema49.TaggedErrorClass()("WaitNotFound", {
10420
+ import { Context as Context40, Duration as Duration2, Effect as Effect54, Layer as Layer44, Option as Option11, Schema as Schema50 } from "effect";
10421
+ class WaitNotFound2 extends Schema50.TaggedErrorClass()("WaitNotFound", {
10317
10422
  wait_id: exports_ids_schema.WaitId
10318
10423
  }) {
10319
10424
  }
10320
10425
 
10321
- class WaitDefinitionMissing extends Schema49.TaggedErrorClass()("WaitDefinitionMissing", {
10426
+ class WaitDefinitionMissing extends Schema50.TaggedErrorClass()("WaitDefinitionMissing", {
10322
10427
  envelope_id: exports_ids_schema.EnvelopeId
10323
10428
  }) {
10324
10429
  }
10325
10430
 
10326
- class WaitServiceError extends Schema49.TaggedErrorClass()("WaitServiceError", {
10327
- message: Schema49.String
10431
+ class WaitServiceError extends Schema50.TaggedErrorClass()("WaitServiceError", {
10432
+ message: Schema50.String
10328
10433
  }) {
10329
10434
  }
10330
10435
 
@@ -10604,20 +10709,20 @@ var upsertTool = (registry, tool) => {
10604
10709
  return Chunk.map(registry, (registered) => registered.definition.name === tool.definition.name ? tool : registered);
10605
10710
  };
10606
10711
  var registerTool = (tools, tool) => Ref12.update(tools, (registry) => upsertTool(registry, tool));
10607
- var jsonValue2 = (value) => Schema50.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
10608
- var fallbackParametersSchema = Schema50.Struct({});
10712
+ var jsonValue2 = (value) => Schema51.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
10713
+ var fallbackParametersSchema = Schema51.Struct({});
10609
10714
  var parametersForInputSchema = (inputSchema) => {
10610
10715
  const schema = exports_tool_schema.parametersSchema(inputSchema);
10611
10716
  return schema.ast._tag === "Unknown" || schema.ast._tag === "Declaration" ? { parameters: fallbackParametersSchema, jsonSchema: inputSchema } : { parameters: schema };
10612
10717
  };
10613
10718
  var attachJsonSchema = (tool, jsonSchema) => jsonSchema === undefined ? tool : Object.assign(tool, { jsonSchema });
10614
- var isStructFieldMap = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((field) => Schema50.isSchema(field));
10719
+ var isStructFieldMap = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((field) => Schema51.isSchema(field));
10615
10720
  var jsonSchemaFromEffectToolParameters = (tool) => {
10616
10721
  const parameters = tool.parametersSchema;
10617
- if (Schema50.isSchema(parameters))
10722
+ if (Schema51.isSchema(parameters))
10618
10723
  return AiTool.getJsonSchema(tool);
10619
10724
  if (isStructFieldMap(parameters))
10620
- return AiTool.getJsonSchemaFromSchema(Schema50.Struct(parameters));
10725
+ return AiTool.getJsonSchemaFromSchema(Schema51.Struct(parameters));
10621
10726
  return AiTool.getJsonSchema(tool);
10622
10727
  };
10623
10728
  var runHandledToolkitTool = (toolkit, name, input, services) => {
@@ -10631,7 +10736,7 @@ var runHandledToolkitTool = (toolkit, name, input, services) => {
10631
10736
  message: "Tool handler did not produce a final result"
10632
10737
  })),
10633
10738
  onSome: (result) => result.isFailure ? Effect55.fail(ToolExecutionFailed.make({ tool_name: String(name), message: String(result.result) })) : Effect55.succeed(jsonValue2(result.encodedResult))
10634
- })), Effect55.provide(services), Effect55.mapError((error5) => Schema50.is(ToolExecutionFailed)(error5) ? error5 : ToolExecutionFailed.make({ tool_name: String(name), message: String(error5) })));
10739
+ })), Effect55.provide(services), Effect55.mapError((error5) => Schema51.is(ToolExecutionFailed)(error5) ? error5 : ToolExecutionFailed.make({ tool_name: String(name), message: String(error5) })));
10635
10740
  };
10636
10741
  var finalToolResult = (tool, input, idempotencyKey) => Effect55.gen(function* () {
10637
10742
  if (tool.run === undefined) {
@@ -10728,7 +10833,7 @@ var recordRequested = (repository, eventLog, input, tool) => repository.ensureCa
10728
10833
  var repairResultEvent = (eventLog, input, record2) => ensureToolEvent(eventLog, resultEvent({ ...input, createdAt: record2.createdAt - 1 }, record2.result, input.eventSequence + 1));
10729
10834
  var persistReceived = (repository, input, result) => repository.recordResult({ executionId: input.executionId, result, createdAt: input.createdAt + 1 }).pipe(Effect55.catchTag("DuplicateToolResult", () => repository.getResult(input.executionId, result.call_id).pipe(Effect55.mapError(mapRepositoryError2), Effect55.flatMap((existing) => existing === undefined ? Effect55.fail(ToolRuntimeError.make({ message: "DuplicateToolResult" })) : Effect55.succeed(existing)))), Effect55.mapError(preserveRecordResultError));
10730
10835
  var recordReceived = (eventLog, input, record2) => ensureToolEvent(eventLog, resultEvent({ ...input, createdAt: record2.createdAt - 1 }, record2.result, input.eventSequence + 1)).pipe(Effect55.as(record2.result));
10731
- var nonEmptyName = (name) => Schema50.decodeUnknownSync(exports_shared_schema.NonEmptyString)(name);
10836
+ var nonEmptyName = (name) => Schema51.decodeUnknownSync(exports_shared_schema.NonEmptyString)(name);
10732
10837
  var needsApprovalFromEffectTool = (tool) => tool.needsApproval === undefined ? undefined : typeof tool.needsApproval === "boolean" ? tool.needsApproval : true;
10733
10838
  var definitionFromEffectTool = (modelTool, options) => ({
10734
10839
  name: modelTool.name,
@@ -10769,8 +10874,8 @@ var tool = Function8.dual(2, (name, options) => {
10769
10874
  tool: effectTool,
10770
10875
  ...options.placement === undefined ? {} : { placement: options.placement },
10771
10876
  ...options.requiredPermissions === undefined ? {} : { requiredPermissions: options.requiredPermissions },
10772
- validateInput: (input) => Schema50.decodeUnknownEffect(inputSchema)(input).pipe(Effect55.mapError((error5) => ToolInputInvalid.make({ tool_name: name, message: error5.message })), Effect55.asVoid),
10773
- run: (input, context) => Schema50.decodeUnknownEffect(inputSchema)(input).pipe(Effect55.mapError((error5) => ToolExecutionFailed.make({ tool_name: name, message: error5.message })), Effect55.flatMap((decoded) => options.run(decoded, context)), Effect55.provideService(ToolCallInfo, context), Effect55.flatMap((output) => Schema50.encodeUnknownEffect(outputSchema)(output).pipe(Effect55.mapError((error5) => ToolExecutionFailed.make({ tool_name: name, message: error5.message })))), Effect55.map(jsonValue2))
10877
+ validateInput: (input) => Schema51.decodeUnknownEffect(inputSchema)(input).pipe(Effect55.mapError((error5) => ToolInputInvalid.make({ tool_name: name, message: error5.message })), Effect55.asVoid),
10878
+ run: (input, context) => Schema51.decodeUnknownEffect(inputSchema)(input).pipe(Effect55.mapError((error5) => ToolExecutionFailed.make({ tool_name: name, message: error5.message })), Effect55.flatMap((decoded) => options.run(decoded, context)), Effect55.provideService(ToolCallInfo, context), Effect55.flatMap((output) => Schema51.encodeUnknownEffect(outputSchema)(output).pipe(Effect55.mapError((error5) => ToolExecutionFailed.make({ tool_name: name, message: error5.message })))), Effect55.map(jsonValue2))
10774
10879
  };
10775
10880
  });
10776
10881
  var dynamicTool = Function8.dual(2, (name, options) => {
@@ -10778,7 +10883,7 @@ var dynamicTool = Function8.dual(2, (name, options) => {
10778
10883
  const modelTool = attachJsonSchema(AiTool.dynamic(name, {
10779
10884
  description: options.description,
10780
10885
  parameters: parameters.parameters,
10781
- success: Schema50.Unknown,
10886
+ success: Schema51.Unknown,
10782
10887
  needsApproval: options.needsApproval
10783
10888
  }), parameters.jsonSchema);
10784
10889
  return {
@@ -10823,7 +10928,7 @@ var externalOutcomeResult = (call, input) => {
10823
10928
  return Effect55.succeed(placementFailureResult(input, call.externalOutcome.message));
10824
10929
  }
10825
10930
  const placement = call.placement.kind;
10826
- return Schema50.decodeUnknownEffect(exports_tool_schema.resultSchema(call.definition.output_schema))(call.externalOutcome.output).pipe(Effect55.map((output) => ({ call_id: input.call.id, output: jsonValue2(output) })), Effect55.catch((error5) => Effect55.succeed(placementFailureResult(input, `invalid ${placement} result: ${error5.message}`))));
10931
+ return Schema51.decodeUnknownEffect(exports_tool_schema.resultSchema(call.definition.output_schema))(call.externalOutcome.output).pipe(Effect55.map((output) => ({ call_id: input.call.id, output: jsonValue2(output) })), Effect55.catch((error5) => Effect55.succeed(placementFailureResult(input, `invalid ${placement} result: ${error5.message}`))));
10827
10932
  };
10828
10933
  var runExternalTool = (repository, waits, call, input) => Effect55.gen(function* () {
10829
10934
  const waitId2 = placementWaitId(input);
@@ -10857,7 +10962,7 @@ var runExternalTool = (repository, waits, call, input) => Effect55.gen(function*
10857
10962
  return placementFailureResult(input, "Tool execution timed out");
10858
10963
  if (wait.state === "cancelled")
10859
10964
  return placementFailureResult(input, "Tool execution cancelled");
10860
- const repairedCall = waitingCall.externalOutcome === undefined && waitingCall.placement.kind === "client" ? yield* Schema50.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect55.mapError((error5) => ToolRuntimeError.make({ message: error5.message })), Effect55.flatMap((outcome) => repository.acceptClientOutcome({
10965
+ const repairedCall = waitingCall.externalOutcome === undefined && waitingCall.placement.kind === "client" ? yield* Schema51.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect55.mapError((error5) => ToolRuntimeError.make({ message: error5.message })), Effect55.flatMap((outcome) => repository.acceptClientOutcome({
10861
10966
  executionId: input.executionId,
10862
10967
  callId: input.call.id,
10863
10968
  outcome,
@@ -11022,11 +11127,11 @@ __export(exports_runtime, {
11022
11127
  });
11023
11128
 
11024
11129
  // ../runtime/src/child/child-fan-out-runtime.ts
11025
- import { Clock as Clock5, Context as Context44, Effect as Effect58, FiberMap, Layer as Layer48, Schema as Schema53 } from "effect";
11130
+ import { Clock as Clock5, Context as Context44, Effect as Effect58, FiberMap, Layer as Layer48, Schema as Schema54 } from "effect";
11026
11131
 
11027
11132
  // ../runtime/src/child/child-fan-out-transition-service.ts
11028
- import { Context as Context43, Effect as Effect57, Layer as Layer47, Option as Option13, Schema as Schema52 } from "effect";
11029
- class ChildFanOutTransitionError extends Schema52.TaggedErrorClass()("ChildFanOutTransitionError", { message: Schema52.String }) {
11133
+ import { Context as Context43, Effect as Effect57, Layer as Layer47, Option as Option13, Schema as Schema53 } from "effect";
11134
+ class ChildFanOutTransitionError extends Schema53.TaggedErrorClass()("ChildFanOutTransitionError", { message: Schema53.String }) {
11030
11135
  }
11031
11136
 
11032
11137
  class Service43 extends Context43.Service()("@relayfx/runtime/child/child-fan-out-transition-service/Service") {
@@ -11093,7 +11198,7 @@ var terminal2 = Effect57.fn("ChildFanOutTransitionService.terminal.call")(functi
11093
11198
  class HandlerService extends Context44.Service()("@relayfx/runtime/child/child-fan-out-runtime/HandlerService") {
11094
11199
  }
11095
11200
 
11096
- class ChildFanOutRuntimeError extends Schema53.TaggedErrorClass()("ChildFanOutRuntimeError", { message: Schema53.String }) {
11201
+ class ChildFanOutRuntimeError extends Schema54.TaggedErrorClass()("ChildFanOutRuntimeError", { message: Schema54.String }) {
11097
11202
  }
11098
11203
 
11099
11204
  class Service44 extends Context44.Service()("@relayfx/runtime/child/child-fan-out-runtime/Service") {
@@ -11160,17 +11265,17 @@ var layerFromRuntime = Layer48.effect(Service44, Effect58.gen(function* () {
11160
11265
  }).pipe(Effect58.mapError(runtimeError)));
11161
11266
 
11162
11267
  // ../runtime/src/state/execution-state-service.ts
11163
- import { Config as Config2, Context as Context45, Effect as Effect59, Function as Function10, Layer as Layer49, Schema as Schema54 } from "effect";
11268
+ import { Config as Config2, Context as Context45, Effect as Effect59, Function as Function10, Layer as Layer49, Schema as Schema55 } from "effect";
11164
11269
  var StateVersionConflict3 = exports_execution_state_repository.StateVersionConflict;
11165
11270
 
11166
- class StateValueInvalid extends Schema54.TaggedErrorClass()("StateValueInvalid", {
11167
- key: Schema54.String,
11168
- message: Schema54.String
11271
+ class StateValueInvalid extends Schema55.TaggedErrorClass()("StateValueInvalid", {
11272
+ key: Schema55.String,
11273
+ message: Schema55.String
11169
11274
  }) {
11170
11275
  }
11171
11276
 
11172
- class ExecutionStateError extends Schema54.TaggedErrorClass()("ExecutionStateError", {
11173
- message: Schema54.String
11277
+ class ExecutionStateError extends Schema55.TaggedErrorClass()("ExecutionStateError", {
11278
+ message: Schema55.String
11174
11279
  }) {
11175
11280
  }
11176
11281
  var key3 = Function10.dual(2, (name, schema) => ({
@@ -11190,7 +11295,7 @@ var layer38 = Layer49.effect(Service45, Effect59.gen(function* () {
11190
11295
  const row = yield* repository.get(executionId, stateKey.name).pipe(Effect59.mapError(stateError));
11191
11296
  if (row === undefined)
11192
11297
  return;
11193
- return yield* Schema54.decodeUnknownEffect(stateKey.schema)(row.value).pipe(Effect59.mapError((cause) => invalid(stateKey.name, cause)));
11298
+ return yield* Schema55.decodeUnknownEffect(stateKey.schema)(row.value).pipe(Effect59.mapError((cause) => invalid(stateKey.name, cause)));
11194
11299
  });
11195
11300
  const getRecord = Effect59.fn("ExecutionStateService.getRecord")((executionId, stateKey) => repository.get(executionId, stateKey).pipe(Effect59.mapError(stateError)));
11196
11301
  const put4 = Effect59.fn("ExecutionStateService.put")(function* (input) {
@@ -11199,8 +11304,8 @@ var layer38 = Layer49.effect(Service45, Effect59.gen(function* () {
11199
11304
  if (replay2 !== undefined && replay2.key === input.key.name && replay2.op === "put" && replay2.record !== undefined)
11200
11305
  return replay2.record;
11201
11306
  }
11202
- const value = yield* Schema54.encodeUnknownEffect(input.key.schema)(input.value).pipe(Effect59.mapError((cause) => invalid(input.key.name, cause)));
11203
- const encoded = yield* Schema54.encodeEffect(Schema54.UnknownFromJsonString)(value).pipe(Effect59.mapError((cause) => invalid(input.key.name, cause)));
11307
+ const value = yield* Schema55.encodeUnknownEffect(input.key.schema)(input.value).pipe(Effect59.mapError((cause) => invalid(input.key.name, cause)));
11308
+ const encoded = yield* Schema55.encodeEffect(Schema55.UnknownFromJsonString)(value).pipe(Effect59.mapError((cause) => invalid(input.key.name, cause)));
11204
11309
  const bytes = new TextEncoder().encode(encoded);
11205
11310
  let eventValue = { value };
11206
11311
  if (bytes.byteLength > eventInlineMaxBytes) {
@@ -11215,9 +11320,9 @@ var layer38 = Layer49.effect(Service45, Effect59.gen(function* () {
11215
11320
  ...input.expectedVersion === undefined ? {} : { expectedVersion: input.expectedVersion },
11216
11321
  ...input.idempotencyKey === undefined ? {} : { idempotencyKey: input.idempotencyKey },
11217
11322
  updatedAt: input.updatedAt
11218
- }).pipe(Effect59.mapError((cause) => Schema54.is(exports_execution_state_repository.StateVersionConflict)(cause) ? cause : stateError(cause)));
11323
+ }).pipe(Effect59.mapError((cause) => Schema55.is(exports_execution_state_repository.StateVersionConflict)(cause) ? cause : stateError(cause)));
11219
11324
  });
11220
- const remove3 = Effect59.fn("ExecutionStateService.remove")((input) => repository.remove(input).pipe(Effect59.mapError((cause) => Schema54.is(exports_execution_state_repository.StateVersionConflict)(cause) ? cause : stateError(cause))));
11325
+ const remove3 = Effect59.fn("ExecutionStateService.remove")((input) => repository.remove(input).pipe(Effect59.mapError((cause) => Schema55.is(exports_execution_state_repository.StateVersionConflict)(cause) ? cause : stateError(cause))));
11221
11326
  const list12 = Effect59.fn("ExecutionStateService.list")((input) => repository.list(input).pipe(Effect59.mapError(stateError)));
11222
11327
  return Service45.of({ getRecord, get: get12, put: put4, remove: remove3, list: list12 });
11223
11328
  }));
@@ -11225,7 +11330,7 @@ var memoryRepositoryDependencies = Layer49.mergeAll(exports_execution_repository
11225
11330
  var memoryLayer36 = layer38.pipe(Layer49.provide(exports_execution_state_repository.memoryLayer.pipe(Layer49.provide(memoryRepositoryDependencies))));
11226
11331
 
11227
11332
  // ../runtime/src/runner/runner-runtime-service.ts
11228
- import { Config as Config8, Context as Context70, Crypto as Crypto4, Duration as Duration7, Effect as Effect99, Layer as Layer81, Option as Option26, Schema as Schema90, Stream as Stream16 } from "effect";
11333
+ import { Config as Config8, Context as Context70, Crypto as Crypto4, Duration as Duration7, Effect as Effect99, Layer as Layer81, Option as Option26, Schema as Schema91, Stream as Stream16 } from "effect";
11229
11334
  import {
11230
11335
  ClusterWorkflowEngine,
11231
11336
  HttpRunner,
@@ -11246,7 +11351,7 @@ import { WorkflowEngine as WorkflowEngine2 } from "effect/unstable/workflow";
11246
11351
  import { LanguageModel as LanguageModel2 } from "effect/unstable/ai";
11247
11352
 
11248
11353
  // ../runtime/src/agent/agent-registry-service.ts
11249
- import { Clock as Clock6, Context as Context46, Crypto as Crypto2, Effect as Effect61, HashSet as HashSet4, Layer as Layer50, Option as Option14, Schema as Schema55 } from "effect";
11354
+ import { Clock as Clock6, Context as Context46, Crypto as Crypto2, Effect as Effect61, HashSet as HashSet4, Layer as Layer50, Option as Option14, Schema as Schema56 } from "effect";
11250
11355
 
11251
11356
  // ../runtime/src/tool/tool-input-schema-digest.ts
11252
11357
  import { Crypto, Effect as Effect60, Encoding } from "effect";
@@ -11268,13 +11373,13 @@ var digestDefinitions = Effect60.fn("ToolInputSchemaDigest.digestDefinitions")(f
11268
11373
  });
11269
11374
 
11270
11375
  // ../runtime/src/agent/agent-registry-service.ts
11271
- class AgentDefinitionInvalid extends Schema55.TaggedErrorClass()("AgentDefinitionInvalid", {
11272
- message: Schema55.String
11376
+ class AgentDefinitionInvalid extends Schema56.TaggedErrorClass()("AgentDefinitionInvalid", {
11377
+ message: Schema56.String
11273
11378
  }) {
11274
11379
  }
11275
11380
 
11276
- class AgentRegistryError extends Schema55.TaggedErrorClass()("AgentRegistryError", {
11277
- message: Schema55.String
11381
+ class AgentRegistryError extends Schema56.TaggedErrorClass()("AgentRegistryError", {
11382
+ message: Schema56.String
11278
11383
  }) {
11279
11384
  }
11280
11385
 
@@ -11316,7 +11421,7 @@ var transferToolName = (name) => `transfer_to_${name.trim().toLowerCase().replac
11316
11421
  var validateTurnPolicySnapshot = Effect61.fn("AgentRegistry.validateTurnPolicySnapshot")(function* (snapshot) {
11317
11422
  if (snapshot === undefined)
11318
11423
  return;
11319
- const decoded = yield* Schema55.decodeUnknownEffect(exports_agent_schema.TurnPolicySnapshot)(snapshot).pipe(Effect61.mapError(() => AgentDefinitionInvalid.make({ message: "definition.turn_policy must be a valid turn policy snapshot" })));
11424
+ const decoded = yield* Schema56.decodeUnknownEffect(exports_agent_schema.TurnPolicySnapshot)(snapshot).pipe(Effect61.mapError(() => AgentDefinitionInvalid.make({ message: "definition.turn_policy must be a valid turn policy snapshot" })));
11320
11425
  let nodes = 0;
11321
11426
  const pending = [
11322
11427
  { snapshot: decoded, depth: 1 }
@@ -11460,35 +11565,35 @@ var listRevisions3 = Effect61.fn("AgentRegistry.listRevisions.call")(function* (
11460
11565
  });
11461
11566
 
11462
11567
  // ../runtime/src/agent/agent-loop-service.ts
11463
- import { Cause as Cause2, Config as Config4, Context as Context64, Crypto as Crypto3, Effect as Effect93, HashSet as HashSet7, Layer as Layer75, Option as Option24, Ref as Ref19, Schema as Schema83, Stream as Stream13 } from "effect";
11568
+ import { Cause as Cause2, Config as Config4, Context as Context64, Crypto as Crypto3, Effect as Effect93, HashSet as HashSet7, Layer as Layer75, Option as Option24, Ref as Ref19, Schema as Schema84, Stream as Stream13 } from "effect";
11464
11569
  import { AiError as AiError3, Chat, LanguageModel, Prompt as Prompt6, Tokenizer, Tool as AiTool2, Toolkit as Toolkit2 } from "effect/unstable/ai";
11465
11570
 
11466
11571
  // ../runtime/src/child/child-run-service.ts
11467
- import { Context as Context48, Effect as Effect63, Function as Function12, HashSet as HashSet5, Layer as Layer52, Option as Option15, Result as Result2, Schema as Schema57 } from "effect";
11572
+ import { Context as Context48, Effect as Effect63, Function as Function12, HashSet as HashSet5, Layer as Layer52, Option as Option15, Result as Result2, Schema as Schema58 } from "effect";
11468
11573
 
11469
11574
  // ../runtime/src/workspace/workspace-provider-service.ts
11470
- import { Context as Context47, Effect as Effect62, Function as Function11, Layer as Layer51, Ref as Ref13, Schema as Schema56 } from "effect";
11575
+ import { Context as Context47, Effect as Effect62, Function as Function11, Layer as Layer51, Ref as Ref13, Schema as Schema57 } from "effect";
11471
11576
 
11472
- class WorkspaceNotFound extends Schema56.TaggedErrorClass()("WorkspaceNotFound", {
11577
+ class WorkspaceNotFound extends Schema57.TaggedErrorClass()("WorkspaceNotFound", {
11473
11578
  sandbox_ref: exports_ids_schema.WorkspaceRef
11474
11579
  }) {
11475
11580
  }
11476
11581
 
11477
- class WorkspaceUnavailable extends Schema56.TaggedErrorClass()("WorkspaceUnavailable", {
11582
+ class WorkspaceUnavailable extends Schema57.TaggedErrorClass()("WorkspaceUnavailable", {
11478
11583
  sandbox_ref: exports_ids_schema.WorkspaceRef,
11479
- message: Schema56.String
11584
+ message: Schema57.String
11480
11585
  }) {
11481
11586
  }
11482
11587
 
11483
- class WorkspaceCapabilityUnsupported extends Schema56.TaggedErrorClass()("WorkspaceCapabilityUnsupported", {
11484
- capability: Schema56.Literals(["suspend", "snapshot", "fork"]),
11588
+ class WorkspaceCapabilityUnsupported extends Schema57.TaggedErrorClass()("WorkspaceCapabilityUnsupported", {
11589
+ capability: Schema57.Literals(["suspend", "snapshot", "fork"]),
11485
11590
  provider_key: exports_workspace_schema.WorkspaceProviderKey
11486
11591
  }) {
11487
11592
  }
11488
11593
 
11489
- class WorkspaceProviderError extends Schema56.TaggedErrorClass()("WorkspaceProviderError", {
11594
+ class WorkspaceProviderError extends Schema57.TaggedErrorClass()("WorkspaceProviderError", {
11490
11595
  provider_key: exports_workspace_schema.WorkspaceProviderKey,
11491
- message: Schema56.String
11596
+ message: Schema57.String
11492
11597
  }) {
11493
11598
  }
11494
11599
 
@@ -11541,28 +11646,28 @@ var destroy = Effect62.fn("WorkspaceProvider.destroy.call")(function* (ref) {
11541
11646
  });
11542
11647
 
11543
11648
  // ../runtime/src/child/child-run-service.ts
11544
- class StaticChildRunPresetNotFound extends Schema57.TaggedErrorClass()("StaticChildRunPresetNotFound", {
11649
+ class StaticChildRunPresetNotFound extends Schema58.TaggedErrorClass()("StaticChildRunPresetNotFound", {
11545
11650
  preset_name: exports_shared_schema.NonEmptyString
11546
11651
  }) {
11547
11652
  }
11548
11653
 
11549
- class ChildRunScopeBroadened extends Schema57.TaggedErrorClass()("ChildRunScopeBroadened", {
11550
- field: Schema57.Literals(["tool_names", "permissions"]),
11654
+ class ChildRunScopeBroadened extends Schema58.TaggedErrorClass()("ChildRunScopeBroadened", {
11655
+ field: Schema58.Literals(["tool_names", "permissions"]),
11551
11656
  value: exports_shared_schema.NonEmptyString
11552
11657
  }) {
11553
11658
  }
11554
11659
 
11555
- class ChildRunServiceError extends Schema57.TaggedErrorClass()("ChildRunServiceError", {
11556
- message: Schema57.String
11660
+ class ChildRunServiceError extends Schema58.TaggedErrorClass()("ChildRunServiceError", {
11661
+ message: Schema58.String
11557
11662
  }) {
11558
11663
  }
11559
11664
 
11560
- class ChildRunWorkspaceUnavailable extends Schema57.TaggedErrorClass()("ChildRunWorkspaceUnavailable", {
11561
- reason: Schema57.String
11665
+ class ChildRunWorkspaceUnavailable extends Schema58.TaggedErrorClass()("ChildRunWorkspaceUnavailable", {
11666
+ reason: Schema58.String
11562
11667
  }) {
11563
11668
  }
11564
11669
 
11565
- class ChildRunModelMissing extends Schema57.TaggedErrorClass()("ChildRunModelMissing", {}) {
11670
+ class ChildRunModelMissing extends Schema58.TaggedErrorClass()("ChildRunModelMissing", {}) {
11566
11671
  }
11567
11672
 
11568
11673
  class Service48 extends Context48.Service()("@relayfx/runtime/child/child-run-service/Service") {
@@ -11798,53 +11903,53 @@ var spawnDynamic = Effect63.fn("ChildRunService.spawnDynamic.call")(function* (i
11798
11903
  });
11799
11904
 
11800
11905
  // ../runtime/src/child/spawn-child-run-tool.ts
11801
- import { Effect as Effect64, Schema as Schema58 } from "effect";
11906
+ import { Effect as Effect64, Schema as Schema59 } from "effect";
11802
11907
  var toolName = "spawn_child_run";
11803
11908
  var permissionName = "relay.child_run.spawn";
11804
- var Input = Schema58.Struct({
11805
- preset_name: Schema58.optionalKey(exports_shared_schema.NonEmptyString),
11806
- instructions: Schema58.optionalKey(Schema58.String),
11807
- model: Schema58.optionalKey(exports_agent_schema.ModelSelection),
11808
- compaction_policy: Schema58.optionalKey(exports_agent_schema.CompactionPolicy),
11809
- tool_names: Schema58.optionalKey(Schema58.Array(Schema58.String)),
11810
- permissions: Schema58.optionalKey(Schema58.Array(Schema58.String)),
11811
- output_schema_ref: Schema58.optionalKey(Schema58.String),
11812
- metadata: Schema58.optionalKey(exports_shared_schema.Metadata),
11813
- input: Schema58.optionalKey(Schema58.Array(exports_content_schema.Part))
11909
+ var Input = Schema59.Struct({
11910
+ preset_name: Schema59.optionalKey(exports_shared_schema.NonEmptyString),
11911
+ instructions: Schema59.optionalKey(Schema59.String),
11912
+ model: Schema59.optionalKey(exports_agent_schema.ModelSelection),
11913
+ compaction_policy: Schema59.optionalKey(exports_agent_schema.CompactionPolicy),
11914
+ tool_names: Schema59.optionalKey(Schema59.Array(Schema59.String)),
11915
+ permissions: Schema59.optionalKey(Schema59.Array(Schema59.String)),
11916
+ output_schema_ref: Schema59.optionalKey(Schema59.String),
11917
+ metadata: Schema59.optionalKey(exports_shared_schema.Metadata),
11918
+ input: Schema59.optionalKey(Schema59.Array(exports_content_schema.Part))
11814
11919
  }).annotate({ identifier: "Relay.SpawnChildRunTool.Input" });
11815
- var Output = Schema58.Struct({
11920
+ var Output = Schema59.Struct({
11816
11921
  child_execution_id: exports_ids_schema.ChildExecutionId,
11817
- status: Schema58.Literals(["completed", "failed", "cancelled"]),
11818
- output: Schema58.Array(exports_content_schema.Part)
11922
+ status: Schema59.Literals(["completed", "failed", "cancelled"]),
11923
+ output: Schema59.Array(exports_content_schema.Part)
11819
11924
  }).annotate({ identifier: "Relay.SpawnChildRunTool.Output" });
11820
- var TransferInput = Schema58.Struct({
11821
- input: Schema58.optionalKey(Schema58.Array(exports_content_schema.Part))
11925
+ var TransferInput = Schema59.Struct({
11926
+ input: Schema59.optionalKey(Schema59.Array(exports_content_schema.Part))
11822
11927
  }).annotate({ identifier: "Relay.SpawnChildRunTool.TransferInput" });
11823
- var ModelInput = Schema58.Struct({
11824
- preset_name: Schema58.optionalKey(Schema58.NullOr(Schema58.String)),
11825
- instructions: Schema58.optionalKey(Schema58.String),
11826
- model: Schema58.optionalKey(Schema58.NullOr(Schema58.Struct({
11827
- provider: Schema58.String,
11828
- model: Schema58.String,
11829
- registration_key: Schema58.optionalKey(Schema58.String)
11928
+ var ModelInput = Schema59.Struct({
11929
+ preset_name: Schema59.optionalKey(Schema59.NullOr(Schema59.String)),
11930
+ instructions: Schema59.optionalKey(Schema59.String),
11931
+ model: Schema59.optionalKey(Schema59.NullOr(Schema59.Struct({
11932
+ provider: Schema59.String,
11933
+ model: Schema59.String,
11934
+ registration_key: Schema59.optionalKey(Schema59.String)
11830
11935
  }))),
11831
- compaction_policy: Schema58.optionalKey(Schema58.Struct({
11832
- context_window: Schema58.Finite,
11833
- reserve_tokens: Schema58.Finite,
11834
- keep_recent_tokens: Schema58.Finite,
11835
- summary_model: Schema58.optionalKey(Schema58.Struct({
11836
- provider: Schema58.String,
11837
- model: Schema58.String,
11838
- registration_key: Schema58.optionalKey(Schema58.String)
11936
+ compaction_policy: Schema59.optionalKey(Schema59.Struct({
11937
+ context_window: Schema59.Finite,
11938
+ reserve_tokens: Schema59.Finite,
11939
+ keep_recent_tokens: Schema59.Finite,
11940
+ summary_model: Schema59.optionalKey(Schema59.Struct({
11941
+ provider: Schema59.String,
11942
+ model: Schema59.String,
11943
+ registration_key: Schema59.optionalKey(Schema59.String)
11839
11944
  }))
11840
11945
  })),
11841
- tool_names: Schema58.optionalKey(Schema58.Array(Schema58.String)),
11842
- permissions: Schema58.optionalKey(Schema58.Array(Schema58.String)),
11843
- output_schema_ref: Schema58.optionalKey(Schema58.NullOr(Schema58.String)),
11844
- input: Schema58.optionalKey(Schema58.Array(Schema58.Struct({ type: Schema58.Literal("text"), text: Schema58.String })))
11946
+ tool_names: Schema59.optionalKey(Schema59.Array(Schema59.String)),
11947
+ permissions: Schema59.optionalKey(Schema59.Array(Schema59.String)),
11948
+ output_schema_ref: Schema59.optionalKey(Schema59.NullOr(Schema59.String)),
11949
+ input: Schema59.optionalKey(Schema59.Array(Schema59.Struct({ type: Schema59.Literal("text"), text: Schema59.String })))
11845
11950
  });
11846
- var ModelTransferInput = Schema58.Struct({
11847
- input: Schema58.optionalKey(Schema58.Array(Schema58.Struct({ type: Schema58.Literal("text"), text: Schema58.String })))
11951
+ var ModelTransferInput = Schema59.Struct({
11952
+ input: Schema59.optionalKey(Schema59.Array(Schema59.Struct({ type: Schema59.Literal("text"), text: Schema59.String })))
11848
11953
  });
11849
11954
  var normalizeModelInput = (input) => {
11850
11955
  const { preset_name: presetName, model, output_schema_ref: outputSchemaRef2, ...rest } = input;
@@ -12029,7 +12134,7 @@ var registeredTool = (config) => tool(toolName, {
12029
12134
  permissions: [{ name: permissionName, value: true }],
12030
12135
  requiredPermissions: [permissionName],
12031
12136
  metadata: { relay_core_tool: true },
12032
- run: (input, context) => Schema58.decodeUnknownEffect(Input)(normalizeModelInput(input)).pipe(Effect64.mapError((error5) => ToolExecutionFailed.make({ tool_name: toolName, message: error5.message })), Effect64.flatMap((decoded) => run3(config, toolName, decoded, context, true)))
12137
+ run: (input, context) => Schema59.decodeUnknownEffect(Input)(normalizeModelInput(input)).pipe(Effect64.mapError((error5) => ToolExecutionFailed.make({ tool_name: toolName, message: error5.message })), Effect64.flatMap((decoded) => run3(config, toolName, decoded, context, true)))
12033
12138
  });
12034
12139
  var transferToolName2 = (name) => `transfer_to_${name.trim().toLowerCase().replaceAll(/[^a-z0-9]+/g, "_").replaceAll(/^_+|_+$/g, "")}`;
12035
12140
  var transferTools = (config) => (config.agent.handoff_targets ?? []).map((target) => {
@@ -12041,12 +12146,12 @@ var transferTools = (config) => (config.agent.handoff_targets ?? []).map((target
12041
12146
  permissions: [{ name: permissionName, value: true }],
12042
12147
  requiredPermissions: [permissionName],
12043
12148
  metadata: { relay_core_tool: true, handoff_target: target.name, preset_name: target.preset_name },
12044
- run: (input, context) => Schema58.decodeUnknownEffect(TransferInput)(input).pipe(Effect64.mapError((error5) => ToolExecutionFailed.make({ tool_name: name, message: error5.message })), Effect64.flatMap((decoded) => run3(config, name, { preset_name: target.preset_name, input: decoded.input ?? [] }, context, false)))
12149
+ run: (input, context) => Schema59.decodeUnknownEffect(TransferInput)(input).pipe(Effect64.mapError((error5) => ToolExecutionFailed.make({ tool_name: name, message: error5.message })), Effect64.flatMap((decoded) => run3(config, name, { preset_name: target.preset_name, input: decoded.input ?? [] }, context, false)))
12045
12150
  });
12046
12151
  });
12047
12152
 
12048
12153
  // ../runtime/src/memory/memory-service.ts
12049
- import { Clock as Clock7, Context as Context49, Effect as Effect65, Layer as Layer53, Schema as Schema59 } from "effect";
12154
+ import { Clock as Clock7, Context as Context49, Effect as Effect65, Layer as Layer53, Schema as Schema60 } from "effect";
12050
12155
  import { EmbeddingModel as EmbeddingModel2, Prompt as Prompt4 } from "effect/unstable/ai";
12051
12156
  class Service49 extends Context49.Service()("@relayfx/runtime/memory/memory-service/Service") {
12052
12157
  }
@@ -12054,7 +12159,7 @@ var defaultTopK = 5;
12054
12159
  var memoryError = (error5) => exports_memory.MemoryError.make({
12055
12160
  message: error5 instanceof Error ? `${error5.name}: ${error5.message}` : String(error5)
12056
12161
  });
12057
- var decodeSubject = (subject) => Schema59.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect65.mapError(memoryError));
12162
+ var decodeSubject = (subject) => Schema60.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect65.mapError(memoryError));
12058
12163
  var textPart = (text) => Prompt4.makePart("text", { text });
12059
12164
  var textFromParts = (parts) => parts.filter((part) => part.type === "text").map((part) => part.text).join(`
12060
12165
  `).trim();
@@ -12217,8 +12322,8 @@ var layer42 = (input) => Layer54.succeed(Service50, Service50.of(make4(input)));
12217
12322
  var noRetryLayer = layer42({ retrySchedule: Schedule3.recurs(0) });
12218
12323
 
12219
12324
  // ../runtime/src/presence/presence-service.ts
12220
- import { Clock as Clock8, Config as Config3, Effect as Effect66, Layer as Layer55, Random, Schedule as Schedule4, Schema as Schema60, Stream as Stream11 } from "effect";
12221
- var isPresenceError = Schema60.is(PresenceError);
12325
+ import { Clock as Clock8, Config as Config3, Effect as Effect66, Layer as Layer55, Random, Schedule as Schedule4, Schema as Schema61, Stream as Stream11 } from "effect";
12326
+ var isPresenceError = Schema61.is(PresenceError);
12222
12327
  var readError = (cause) => isPresenceError(cause) ? cause : PresenceError.make({ message: String(cause) });
12223
12328
  var warn = (operation) => (cause) => Effect66.logWarning(`Presence ${operation} failed`).pipe(Effect66.annotateLogs({ cause: String(cause) }));
12224
12329
  var layerFromRepository2 = Layer55.effect(Service2, Effect66.gen(function* () {
@@ -12273,11 +12378,11 @@ var list13 = Effect66.fn("Presence.list.call")(function* (scope) {
12273
12378
  });
12274
12379
 
12275
12380
  // ../runtime/src/presence/presence-tool.ts
12276
- import { Effect as Effect67, Schema as Schema61 } from "effect";
12381
+ import { Effect as Effect67, Schema as Schema62 } from "effect";
12277
12382
  var toolName2 = "relay_presence";
12278
12383
  var permissionName2 = "relay.presence.read";
12279
- var Input2 = Schema61.Struct({ scope: Schema61.optionalKey(exports_presence_schema.Scope) });
12280
- var Output2 = Schema61.Struct({ watcher_count: Schema61.Finite, entries: Schema61.Array(exports_presence_schema.Entry) });
12384
+ var Input2 = Schema62.Struct({ scope: Schema62.optionalKey(exports_presence_schema.Scope) });
12385
+ var Output2 = Schema62.Struct({ watcher_count: Schema62.Finite, entries: Schema62.Array(exports_presence_schema.Entry) });
12281
12386
  var registeredTool2 = (presence) => tool(toolName2, {
12282
12387
  description: "List observers currently watching an execution or session.",
12283
12388
  input: Input2,
@@ -12293,24 +12398,24 @@ var registeredTool2 = (presence) => tool(toolName2, {
12293
12398
  });
12294
12399
 
12295
12400
  // ../runtime/src/state/state-tools.ts
12296
- import { Effect as Effect68, Schema as Schema62 } from "effect";
12297
- var GetInput = Schema62.Struct({ key: exports_shared_schema.NonEmptyString });
12298
- var GetOutput = Schema62.Struct({
12299
- value: Schema62.optionalKey(exports_shared_schema.JsonValue),
12300
- version: Schema62.optionalKey(Schema62.Int)
12401
+ import { Effect as Effect68, Schema as Schema63 } from "effect";
12402
+ var GetInput = Schema63.Struct({ key: exports_shared_schema.NonEmptyString });
12403
+ var GetOutput = Schema63.Struct({
12404
+ value: Schema63.optionalKey(exports_shared_schema.JsonValue),
12405
+ version: Schema63.optionalKey(Schema63.Int)
12301
12406
  });
12302
- var PutInput = Schema62.Struct({
12407
+ var PutInput = Schema63.Struct({
12303
12408
  key: exports_shared_schema.NonEmptyString,
12304
12409
  value: exports_shared_schema.JsonValue,
12305
- expected_version: Schema62.optionalKey(Schema62.Int.check(Schema62.isGreaterThanOrEqualTo(0)))
12410
+ expected_version: Schema63.optionalKey(Schema63.Int.check(Schema63.isGreaterThanOrEqualTo(0)))
12306
12411
  });
12307
- var DeleteInput = Schema62.Struct({ key: exports_shared_schema.NonEmptyString, expected_version: Schema62.optionalKey(Schema62.Int) });
12308
- var ListInput = Schema62.Struct({
12309
- prefix: Schema62.optionalKey(Schema62.String),
12310
- after_key: Schema62.optionalKey(Schema62.String),
12311
- limit: Schema62.optionalKey(Schema62.Int)
12412
+ var DeleteInput = Schema63.Struct({ key: exports_shared_schema.NonEmptyString, expected_version: Schema63.optionalKey(Schema63.Int) });
12413
+ var ListInput = Schema63.Struct({
12414
+ prefix: Schema63.optionalKey(Schema63.String),
12415
+ after_key: Schema63.optionalKey(Schema63.String),
12416
+ limit: Schema63.optionalKey(Schema63.Int)
12312
12417
  });
12313
- var RecordOutput = Schema62.Struct({
12418
+ var RecordOutput = Schema63.Struct({
12314
12419
  execution_id: exports_state_schema.StateRecordView.fields.execution_id,
12315
12420
  key: exports_state_schema.StateRecordView.fields.key,
12316
12421
  value: exports_state_schema.StateRecordView.fields.value,
@@ -12318,8 +12423,8 @@ var RecordOutput = Schema62.Struct({
12318
12423
  created_at: exports_state_schema.StateRecordView.fields.created_at,
12319
12424
  updated_at: exports_state_schema.StateRecordView.fields.updated_at
12320
12425
  });
12321
- var PutOutput = Schema62.Struct({ key: exports_state_schema.StateKey, version: exports_state_schema.StateVersion });
12322
- var DeleteOutput = Schema62.Struct({ deleted: Schema62.Boolean, version: Schema62.optionalKey(Schema62.Int) });
12426
+ var PutOutput = Schema63.Struct({ key: exports_state_schema.StateKey, version: exports_state_schema.StateVersion });
12427
+ var DeleteOutput = Schema63.Struct({ deleted: Schema63.Boolean, version: Schema63.optionalKey(Schema63.Int) });
12323
12428
  var enabled2 = (agent) => agent.metadata?.state_enabled === true;
12324
12429
  var mapStateError = (toolName3) => (error5) => ToolExecutionFailed.make({ tool_name: toolName3, message: error5._tag });
12325
12430
  var registeredTools2 = (state) => [
@@ -12360,7 +12465,7 @@ var registeredTools2 = (state) => [
12360
12465
  tool("state_list", {
12361
12466
  description: "List durable execution state",
12362
12467
  input: ListInput,
12363
- output: Schema62.Array(RecordOutput),
12468
+ output: Schema63.Array(RecordOutput),
12364
12469
  metadata: { relay_core_tool: true },
12365
12470
  run: (input, context) => state.list({
12366
12471
  executionId: context.executionId,
@@ -12537,7 +12642,8 @@ var make5 = Effect69.fn("RelaySessionStore.make")(function* (sessionId, entrySco
12537
12642
  parentId: current2.leaf,
12538
12643
  input: toAppendInput(input),
12539
12644
  createdAt: now,
12540
- ...expectedLeafId === undefined ? {} : { expectedLeafId: expectedLeafId === null ? null : entryId(expectedLeafId) }
12645
+ ...expectedLeafId === undefined ? {} : { expectedLeafId: expectedLeafId === null ? null : entryId(expectedLeafId) },
12646
+ ...makeOptions?.writer === undefined ? {} : { expectedWriter: makeOptions.writer }
12541
12647
  }).pipe(Effect69.mapError(mapWriteError));
12542
12648
  yield* Ref14.set(state, { leaf: entry.id, next: current2.next + 1 });
12543
12649
  return entry;
@@ -12571,7 +12677,8 @@ var make5 = Effect69.fn("RelaySessionStore.make")(function* (sessionId, entrySco
12571
12677
  parentId: checkpoint.parentId === null ? null : entryId(checkpoint.parentId),
12572
12678
  projectedHistory: checkpoint.projectedHistory,
12573
12679
  ...checkpoint.summary === undefined ? {} : { summary: checkpoint.summary },
12574
- createdAt: now
12680
+ createdAt: now,
12681
+ ...makeOptions?.writer === undefined ? {} : { expectedWriter: makeOptions.writer }
12575
12682
  }).pipe(Effect69.mapError(mapWriteError));
12576
12683
  const current2 = yield* Ref14.get(state);
12577
12684
  if (current2 === undefined) {
@@ -12619,43 +12726,43 @@ var layer43 = Function13.dual((args) => typeof args[0] === "string" && String(ar
12619
12726
  var memoryLayer39 = Function13.dual((args) => typeof args[0] === "string" && String(args[0]).startsWith("session:"), (sessionId, entryScope = "default") => layer43(sessionId, entryScope).pipe(Layer56.provide(exports_session_repository.memoryLayer)));
12620
12727
 
12621
12728
  // ../runtime/src/inbox/inbox-service.ts
12622
- import { Clock as Clock12, Context as Context61, Effect as Effect81, Layer as Layer67, Schema as Schema74 } from "effect";
12729
+ import { Clock as Clock12, Context as Context61, Effect as Effect81, Layer as Layer67, Schema as Schema75 } from "effect";
12623
12730
 
12624
12731
  // ../runtime/src/wait/wait-signal.ts
12625
- import { Effect as Effect80, Schema as Schema73 } from "effect";
12732
+ import { Effect as Effect80, Schema as Schema74 } from "effect";
12626
12733
 
12627
12734
  // ../runtime/src/workflow/execution-workflow.ts
12628
12735
  import { Activity, DurableDeferred, Workflow as Workflow2, WorkflowEngine } from "effect/unstable/workflow";
12629
- import { Cause, Effect as Effect79, Exit, Function as Function14, Layer as Layer66, Option as Option20, Schema as Schema72 } from "effect";
12736
+ import { Cause, Effect as Effect79, Exit, Function as Function14, Layer as Layer66, Option as Option20, Schema as Schema73 } from "effect";
12630
12737
 
12631
12738
  // ../runtime/src/address/address-resolution-service.ts
12632
- import { Context as Context53, Effect as Effect71, Layer as Layer58, Schema as Schema64 } from "effect";
12739
+ import { Context as Context53, Effect as Effect71, Layer as Layer58, Schema as Schema65 } from "effect";
12633
12740
 
12634
12741
  // ../runtime/src/address/address-book-service.ts
12635
- import { Context as Context52, Effect as Effect70, Layer as Layer57, Ref as Ref15, Schema as Schema63 } from "effect";
12742
+ import { Context as Context52, Effect as Effect70, Layer as Layer57, Ref as Ref15, Schema as Schema64 } from "effect";
12636
12743
  var RouteKind2 = exports_address_schema.RouteKind;
12637
12744
  var Route = exports_address_schema.Route;
12638
12745
  var RouteRecord = exports_address_schema.RouteRecord;
12639
12746
 
12640
- class AddressNotFound2 extends Schema63.TaggedErrorClass()("AddressNotFound", {
12747
+ class AddressNotFound2 extends Schema64.TaggedErrorClass()("AddressNotFound", {
12641
12748
  address_id: exports_ids_schema.AddressId
12642
12749
  }) {
12643
12750
  }
12644
12751
 
12645
- class AddressUnavailable extends Schema63.TaggedErrorClass()("AddressUnavailable", {
12752
+ class AddressUnavailable extends Schema64.TaggedErrorClass()("AddressUnavailable", {
12646
12753
  address_id: exports_ids_schema.AddressId,
12647
- route_key: Schema63.String
12754
+ route_key: Schema64.String
12648
12755
  }) {
12649
12756
  }
12650
12757
 
12651
- class AddressDeferred extends Schema63.TaggedErrorClass()("AddressDeferred", {
12758
+ class AddressDeferred extends Schema64.TaggedErrorClass()("AddressDeferred", {
12652
12759
  address_id: exports_ids_schema.AddressId,
12653
- route_key: Schema63.String
12760
+ route_key: Schema64.String
12654
12761
  }) {
12655
12762
  }
12656
12763
 
12657
- class AddressBookServiceError extends Schema63.TaggedErrorClass()("AddressBookServiceError", {
12658
- message: Schema63.String
12764
+ class AddressBookServiceError extends Schema64.TaggedErrorClass()("AddressBookServiceError", {
12765
+ message: Schema64.String
12659
12766
  }) {
12660
12767
  }
12661
12768
 
@@ -12683,7 +12790,7 @@ var recordFromEntry = (entry) => ({
12683
12790
  updated_at: entry.updatedAt
12684
12791
  });
12685
12792
  var entryIdFor = (addressId) => exports_ids_schema.AddressBookEntryId.make(`address-book:${addressId}`);
12686
- var validateRoute = (route) => Schema63.decodeUnknownEffect(Route)(route).pipe(Effect70.mapError((error5) => AddressBookServiceError.make({ message: String(error5) })));
12793
+ var validateRoute = (route) => Schema64.decodeUnknownEffect(Route)(route).pipe(Effect70.mapError((error5) => AddressBookServiceError.make({ message: String(error5) })));
12687
12794
  var mapRepositoryError5 = (error5) => {
12688
12795
  if (error5._tag === "AddressNotFound") {
12689
12796
  return AddressNotFound2.make({ address_id: error5.address_id });
@@ -12748,41 +12855,41 @@ var list14 = Effect70.fn("AddressBook.list.call")(function* () {
12748
12855
  });
12749
12856
 
12750
12857
  // ../runtime/src/address/address-resolution-service.ts
12751
- class AddressRouteNotFound extends Schema64.TaggedErrorClass()("AddressRouteNotFound", {
12858
+ class AddressRouteNotFound extends Schema65.TaggedErrorClass()("AddressRouteNotFound", {
12752
12859
  address_id: exports_ids_schema.AddressId
12753
12860
  }) {
12754
12861
  }
12755
12862
 
12756
- class AddressRouteKindMismatch extends Schema64.TaggedErrorClass()("AddressRouteKindMismatch", {
12863
+ class AddressRouteKindMismatch extends Schema65.TaggedErrorClass()("AddressRouteKindMismatch", {
12757
12864
  address_id: exports_ids_schema.AddressId,
12758
- expected: Schema64.Literal("local-agent"),
12865
+ expected: Schema65.Literal("local-agent"),
12759
12866
  actual: exports_address_schema.RouteKind,
12760
- route_key: Schema64.String
12867
+ route_key: Schema65.String
12761
12868
  }) {
12762
12869
  }
12763
12870
 
12764
- class AddressAgentDefinitionNotFound extends Schema64.TaggedErrorClass()("AddressAgentDefinitionNotFound", {
12871
+ class AddressAgentDefinitionNotFound extends Schema65.TaggedErrorClass()("AddressAgentDefinitionNotFound", {
12765
12872
  address_id: exports_ids_schema.AddressId,
12766
12873
  agent_id: exports_ids_schema.AgentId
12767
12874
  }) {
12768
12875
  }
12769
12876
 
12770
- class AddressResolutionError extends Schema64.TaggedErrorClass()("AddressResolutionError", {
12771
- message: Schema64.String
12877
+ class AddressResolutionError extends Schema65.TaggedErrorClass()("AddressResolutionError", {
12878
+ message: Schema65.String
12772
12879
  }) {
12773
12880
  }
12774
- var LocalAgentRoute = Schema64.Struct({
12775
- kind: Schema64.Literal("local-agent"),
12881
+ var LocalAgentRoute = Schema65.Struct({
12882
+ kind: Schema65.Literal("local-agent"),
12776
12883
  route_key: exports_shared_schema.NonEmptyString,
12777
- metadata: Schema64.optionalKey(exports_shared_schema.Metadata)
12884
+ metadata: Schema65.optionalKey(exports_shared_schema.Metadata)
12778
12885
  }).annotate({ identifier: "Relay.AddressResolution.LocalAgentRoute" });
12779
- var LocalAgentTarget = Schema64.Struct({
12886
+ var LocalAgentTarget = Schema65.Struct({
12780
12887
  address_id: exports_ids_schema.AddressId,
12781
12888
  route: LocalAgentRoute,
12782
12889
  agent_id: exports_ids_schema.AgentId,
12783
12890
  agent_revision: exports_agent_schema.DefinitionRevision,
12784
12891
  agent_snapshot: exports_agent_schema.Definition,
12785
- tool_input_schema_digests: Schema64.optionalKey(exports_agent_schema.ToolInputSchemaDigests)
12892
+ tool_input_schema_digests: Schema65.optionalKey(exports_agent_schema.ToolInputSchemaDigests)
12786
12893
  }).annotate({ identifier: "Relay.AddressResolution.LocalAgentTarget" });
12787
12894
 
12788
12895
  class Service53 extends Context53.Service()("@relayfx/runtime/address/address-resolution-service/Service") {
@@ -12815,7 +12922,7 @@ var layer44 = Layer58.effect(Service53, Effect71.gen(function* () {
12815
12922
  return yield* AddressRouteNotFound.make({ address_id: addressId });
12816
12923
  }
12817
12924
  const route = yield* routeToLocalAgent(addressId, record2.route);
12818
- const agentId = yield* Schema64.decodeUnknownEffect(exports_ids_schema.AgentId)(route.route_key).pipe(Effect71.mapError((error5) => AddressResolutionError.make({ message: String(error5) })));
12925
+ const agentId = yield* Schema65.decodeUnknownEffect(exports_ids_schema.AgentId)(route.route_key).pipe(Effect71.mapError((error5) => AddressResolutionError.make({ message: String(error5) })));
12819
12926
  const definition = yield* agentRegistry.get(agentId).pipe(Effect71.mapError(mapAgentRegistryError));
12820
12927
  if (definition === undefined) {
12821
12928
  return yield* AddressAgentDefinitionNotFound.make({
@@ -12844,13 +12951,13 @@ var resolveLocalAgent = Effect71.fn("AddressResolution.resolveLocalAgent.call")(
12844
12951
  });
12845
12952
 
12846
12953
  // ../runtime/src/agent/agent-loop-error.ts
12847
- import { Schema as Schema65 } from "effect";
12954
+ import { Schema as Schema66 } from "effect";
12848
12955
  import { AiError as AiError2 } from "effect/unstable/ai";
12849
12956
 
12850
- class AgentLoopError extends Schema65.TaggedErrorClass()("AgentLoopError", {
12851
- message: Schema65.String,
12852
- failure_classification: Schema65.optionalKey(Schema65.Literal("context-overflow")),
12853
- baton_failure: Schema65.optionalKey(Schema65.Union([
12957
+ class AgentLoopError extends Schema66.TaggedErrorClass()("AgentLoopError", {
12958
+ message: Schema66.String,
12959
+ failure_classification: Schema66.optionalKey(Schema66.Literal("context-overflow")),
12960
+ baton_failure: Schema66.optionalKey(Schema66.Union([
12854
12961
  exports_agent_event.AgentError,
12855
12962
  exports_agent_event.ResumeMismatch,
12856
12963
  exports_turn_policy.TurnPolicyError,
@@ -12858,31 +12965,31 @@ class AgentLoopError extends Schema65.TaggedErrorClass()("AgentLoopError", {
12858
12965
  exports_agent_event.TurnLimitExceeded,
12859
12966
  exports_agent_event.MiddlewareViolation,
12860
12967
  exports_agent_event.DuplicateToolCallId,
12861
- exports_agent_event.ProgressOverflowError,
12968
+ exports_agent_event.ProgressOverflow,
12862
12969
  exports_agent_event.ToolNameCollision,
12863
12970
  AiError2.AiError,
12864
12971
  exports_model_registry.LanguageModelNotRegistered,
12865
12972
  exports_tool_executor.FrameworkFailure
12866
12973
  ])),
12867
- next_event_sequence: Schema65.optionalKey(exports_execution_schema.ExecutionEventSequence)
12974
+ next_event_sequence: Schema66.optionalKey(exports_execution_schema.ExecutionEventSequence)
12868
12975
  }) {
12869
12976
  }
12870
12977
 
12871
- class AgentLoopBudgetExceeded extends Schema65.TaggedErrorClass()("AgentLoopBudgetExceeded", {
12872
- tokens_used: Schema65.Int,
12873
- token_budget: Schema65.Int,
12978
+ class AgentLoopBudgetExceeded extends Schema66.TaggedErrorClass()("AgentLoopBudgetExceeded", {
12979
+ tokens_used: Schema66.Int,
12980
+ token_budget: Schema66.Int,
12874
12981
  next_event_sequence: exports_execution_schema.ExecutionEventSequence
12875
12982
  }) {
12876
12983
  }
12877
- var AgentTerminalFailure = Schema65.Union([AgentLoopError, AgentLoopBudgetExceeded]);
12984
+ var AgentTerminalFailure = Schema66.Union([AgentLoopError, AgentLoopBudgetExceeded]);
12878
12985
 
12879
12986
  // ../runtime/src/child/parent-notifier-service.ts
12880
- import { Context as Context54, Effect as Effect72, Layer as Layer59, Option as Option16, Ref as Ref16, Schema as Schema66 } from "effect";
12881
- class ParentNotifyError extends Schema66.TaggedErrorClass()("ParentNotifyError", {
12882
- message: Schema66.String
12987
+ import { Context as Context54, Effect as Effect72, Layer as Layer59, Option as Option16, Ref as Ref16, Schema as Schema67 } from "effect";
12988
+ class ParentNotifyError extends Schema67.TaggedErrorClass()("ParentNotifyError", {
12989
+ message: Schema67.String
12883
12990
  }) {
12884
12991
  }
12885
- var ChildTerminalStatus = Schema66.Literals(["completed", "failed", "cancelled"]).annotate({
12992
+ var ChildTerminalStatus = Schema67.Literals(["completed", "failed", "cancelled"]).annotate({
12886
12993
  identifier: "Relay.ParentNotifier.ChildTerminalStatus"
12887
12994
  });
12888
12995
 
@@ -12963,15 +13070,15 @@ var notify = Effect72.fn("ParentNotifier.notify.call")(function* (input) {
12963
13070
  });
12964
13071
 
12965
13072
  // ../runtime/src/skill/skill-registry-service.ts
12966
- import { Clock as Clock10, Context as Context55, Effect as Effect73, Layer as Layer60, Schema as Schema67 } from "effect";
13073
+ import { Clock as Clock10, Context as Context55, Effect as Effect73, Layer as Layer60, Schema as Schema68 } from "effect";
12967
13074
 
12968
- class SkillDefinitionInvalid extends Schema67.TaggedErrorClass()("SkillDefinitionInvalid", {
12969
- message: Schema67.String
13075
+ class SkillDefinitionInvalid extends Schema68.TaggedErrorClass()("SkillDefinitionInvalid", {
13076
+ message: Schema68.String
12970
13077
  }) {
12971
13078
  }
12972
13079
 
12973
- class SkillRegistryError extends Schema67.TaggedErrorClass()("SkillRegistryError", {
12974
- message: Schema67.String
13080
+ class SkillRegistryError extends Schema68.TaggedErrorClass()("SkillRegistryError", {
13081
+ message: Schema68.String
12975
13082
  }) {
12976
13083
  }
12977
13084
 
@@ -13124,16 +13231,16 @@ var sourceForExecution = Effect73.fn("SkillRegistry.sourceForExecution.call")(fu
13124
13231
  });
13125
13232
 
13126
13233
  // ../runtime/src/execution/execution-service.ts
13127
- import { Clock as Clock11, Context as Context56, Effect as Effect74, Layer as Layer61, Option as Option17, Schema as Schema68, Stream as Stream12 } from "effect";
13234
+ import { Clock as Clock11, Context as Context56, Effect as Effect74, Layer as Layer61, Option as Option17, Schema as Schema69, Stream as Stream12 } from "effect";
13128
13235
  import { ShardingConfig } from "effect/unstable/cluster";
13129
13236
  var ExecutionServiceErrorDetails = exports_shared_schema.JsonValue.annotate({
13130
13237
  identifier: "Relay.ExecutionServiceErrorDetails"
13131
13238
  });
13132
13239
 
13133
- class ExecutionServiceError extends Schema68.TaggedErrorClass()("ExecutionServiceError", {
13134
- message: Schema68.String,
13135
- details: Schema68.optionalKey(ExecutionServiceErrorDetails),
13136
- next_event_sequence: Schema68.optionalKey(exports_execution_schema.ExecutionEventSequence)
13240
+ class ExecutionServiceError extends Schema69.TaggedErrorClass()("ExecutionServiceError", {
13241
+ message: Schema69.String,
13242
+ details: Schema69.optionalKey(ExecutionServiceErrorDetails),
13243
+ next_event_sequence: Schema69.optionalKey(exports_execution_schema.ExecutionEventSequence)
13137
13244
  }) {
13138
13245
  }
13139
13246
 
@@ -13268,6 +13375,37 @@ var failedEvent = (input, error5) => ({
13268
13375
  created_at: input.completedAt
13269
13376
  });
13270
13377
  var terminalEvent2 = (events) => events.find((event) => event.type === "execution.completed" || event.type === "execution.failed");
13378
+ var terminalStatuses2 = new Set(["completed", "failed", "cancelled"]);
13379
+ var claimSessionWriter = Effect74.fn("ExecutionService.claimSessionWriter")(function* (sessions, repository, input) {
13380
+ if (input.sessionId === undefined)
13381
+ return;
13382
+ const sessionId = input.sessionId;
13383
+ const mapSessionError = (error5) => ExecutionServiceError.make({ message: error5.message });
13384
+ const claim = yield* sessions.claimWriter({ sessionId, executionId: input.executionId, now: input.createdAt }).pipe(Effect74.mapError(mapSessionError));
13385
+ if (claim._tag === "Claimed")
13386
+ return;
13387
+ const owner = yield* repository.get(claim.writer.executionId).pipe(Effect74.mapError(mapRepositoryError7));
13388
+ if (owner !== undefined && !terminalStatuses2.has(owner.status)) {
13389
+ return yield* ExecutionServiceError.make({
13390
+ message: `Session ${sessionId} is owned by execution ${claim.writer.executionId} at epoch ${claim.writer.epoch}`
13391
+ });
13392
+ }
13393
+ yield* sessions.releaseWriter({ sessionId, executionId: claim.writer.executionId, now: input.createdAt }).pipe(Effect74.mapError(mapSessionError));
13394
+ const seized = yield* sessions.claimWriter({ sessionId, executionId: input.executionId, now: input.createdAt }).pipe(Effect74.mapError(mapSessionError));
13395
+ if (seized._tag === "Busy") {
13396
+ return yield* ExecutionServiceError.make({
13397
+ message: `Session ${sessionId} is owned by execution ${seized.writer.executionId} at epoch ${seized.writer.epoch}`
13398
+ });
13399
+ }
13400
+ });
13401
+ var releaseSessionWriter = Effect74.fn("ExecutionService.releaseSessionWriter")(function* (sessions, execution, now) {
13402
+ if (Option17.isNone(sessions))
13403
+ return;
13404
+ const sessionId = execution.session_id;
13405
+ if (sessionId === undefined)
13406
+ return;
13407
+ yield* sessions.value.releaseWriter({ sessionId, executionId: execution.id, now }).pipe(Effect74.ignore);
13408
+ });
13271
13409
  var existingTerminalExecution = Effect74.fn("ExecutionService.existingTerminalExecution")(function* (repository, eventLog, input) {
13272
13410
  const events = yield* eventLog.replay({ executionId: input.executionId }).pipe(Effect74.mapError(mapEventLogError4));
13273
13411
  const event = terminalEvent2(events);
@@ -13283,7 +13421,7 @@ var existingTerminalExecution = Effect74.fn("ExecutionService.existingTerminalEx
13283
13421
  execution: undefined,
13284
13422
  failure: ExecutionServiceError.make({
13285
13423
  message: typeof metadata11.message === "string" ? metadata11.message : "Execution failed",
13286
- ...Schema68.is(ExecutionServiceErrorDetails)(metadata11.details) ? { details: metadata11.details } : {},
13424
+ ...Schema69.is(ExecutionServiceErrorDetails)(metadata11.details) ? { details: metadata11.details } : {},
13287
13425
  next_event_sequence: event.sequence
13288
13426
  })
13289
13427
  };
@@ -13326,6 +13464,7 @@ var layer46 = Layer61.effect(Service56, Effect74.gen(function* () {
13326
13464
  rootAddressId: input.rootAddressId,
13327
13465
  now: input.createdAt
13328
13466
  }).pipe(Effect74.mapError((error5) => ExecutionServiceError.make({ message: error5.message })));
13467
+ yield* claimSessionWriter(sessions.value, repository, input);
13329
13468
  }
13330
13469
  const record2 = yield* repository.create({
13331
13470
  id: input.executionId,
@@ -13361,6 +13500,7 @@ var layer46 = Layer61.effect(Service56, Effect74.gen(function* () {
13361
13500
  if (failedExecution.status !== "failed")
13362
13501
  return failedExecution;
13363
13502
  yield* appendIdempotentTo(eventLog, failedEvent(input, error5)).pipe(Effect74.mapError(mapEventLogError4));
13503
+ yield* releaseSessionWriter(sessions, failedExecution, input.completedAt);
13364
13504
  yield* recordExecutionFinished("failed");
13365
13505
  yield* recordExecutionDuration("failed", failedExecution.updated_at - failedExecution.created_at);
13366
13506
  return yield* error5;
@@ -13376,6 +13516,7 @@ var layer46 = Layer61.effect(Service56, Effect74.gen(function* () {
13376
13516
  if (execution.status !== "completed")
13377
13517
  return execution;
13378
13518
  yield* appendIdempotentTo(eventLog, completedEvent(input, resultMetadata, completedSequence)).pipe(Effect74.mapError(mapEventLogError4));
13519
+ yield* releaseSessionWriter(sessions, execution, input.completedAt);
13379
13520
  yield* recordExecutionFinished("completed");
13380
13521
  yield* recordExecutionDuration("completed", execution.updated_at - execution.created_at);
13381
13522
  return execution;
@@ -13392,6 +13533,7 @@ var layer46 = Layer61.effect(Service56, Effect74.gen(function* () {
13392
13533
  if (execution.status !== "cancelled")
13393
13534
  return execution;
13394
13535
  yield* appendIdempotentTo(eventLog, cancelledEvent(input)).pipe(Effect74.mapError(mapEventLogError4));
13536
+ yield* releaseSessionWriter(sessions, execution, input.cancelledAt);
13395
13537
  yield* recordExecutionFinished("cancelled");
13396
13538
  yield* recordExecutionDuration("cancelled", execution.updated_at - execution.created_at);
13397
13539
  return execution;
@@ -13473,18 +13615,25 @@ var layer47 = Layer62.effect(Service57, Effect75.gen(function* () {
13473
13615
  return Service57.of({
13474
13616
  run: (executionId, effect) => Effect75.gen(function* () {
13475
13617
  const signal = yield* Deferred2.make();
13476
- yield* Ref17.update(active, (entries) => new Map(entries).set(executionId, signal));
13618
+ const done = yield* Deferred2.make();
13619
+ const entry = { signal, done };
13620
+ yield* Ref17.update(active, (entries) => new Map(entries).set(executionId, entry));
13477
13621
  const interrupted = Deferred2.await(signal).pipe(Effect75.andThen(() => Effect75.interrupt));
13478
13622
  return yield* Effect75.raceFirst(effect, interrupted).pipe(Effect75.ensuring(Ref17.update(active, (entries) => {
13479
13623
  const next = new Map(entries);
13480
- if (next.get(executionId) === signal)
13624
+ if (next.get(executionId) === entry)
13481
13625
  next.delete(executionId);
13482
13626
  return next;
13483
- })));
13627
+ }).pipe(Effect75.andThen(Deferred2.succeed(done, undefined)))));
13484
13628
  }),
13485
13629
  interrupt: Effect75.fn("ActiveExecutionRegistry.interrupt")(function* (executionId) {
13486
- const signal = yield* Ref17.get(active).pipe(Effect75.map((entries) => entries.get(executionId)));
13487
- return signal === undefined ? false : yield* Deferred2.succeed(signal, undefined);
13630
+ const entry = yield* Ref17.get(active).pipe(Effect75.map((entries) => entries.get(executionId)));
13631
+ return entry === undefined ? false : yield* Deferred2.succeed(entry.signal, undefined);
13632
+ }),
13633
+ awaitQuiescent: Effect75.fn("ActiveExecutionRegistry.awaitQuiescent")(function* (executionId) {
13634
+ const entry = yield* Ref17.get(active).pipe(Effect75.map((entries) => entries.get(executionId)));
13635
+ if (entry !== undefined)
13636
+ yield* Deferred2.await(entry.done);
13488
13637
  })
13489
13638
  });
13490
13639
  }));
@@ -13515,13 +13664,13 @@ var coordinate = Effect76.fn("ToolTransitionCoordinator.coordinate")(function* (
13515
13664
  });
13516
13665
 
13517
13666
  // ../runtime/src/workspace/workspace-planner-service.ts
13518
- import { Context as Context60, Effect as Effect78, HashSet as HashSet6, Layer as Layer65, Option as Option18, Schema as Schema70 } from "effect";
13667
+ import { Context as Context60, Effect as Effect78, HashSet as HashSet6, Layer as Layer65, Option as Option18, Schema as Schema71 } from "effect";
13519
13668
 
13520
13669
  // ../runtime/src/workspace/workspace-runtime-service.ts
13521
- import { Context as Context59, Effect as Effect77, Layer as Layer64, Schema as Schema69 } from "effect";
13670
+ import { Context as Context59, Effect as Effect77, Layer as Layer64, Schema as Schema70 } from "effect";
13522
13671
 
13523
- class WorkspaceRuntimeError extends Schema69.TaggedErrorClass()("WorkspaceRuntimeError", {
13524
- message: Schema69.String
13672
+ class WorkspaceRuntimeError extends Schema70.TaggedErrorClass()("WorkspaceRuntimeError", {
13673
+ message: Schema70.String
13525
13674
  }) {
13526
13675
  }
13527
13676
 
@@ -13549,18 +13698,18 @@ var exec = Effect77.fn("WorkspaceRuntime.exec.call")(function* (input) {
13549
13698
  });
13550
13699
 
13551
13700
  // ../runtime/src/workspace/workspace-planner-service.ts
13552
- class WorkspaceRuntimeMissing extends Schema70.TaggedErrorClass()("WorkspaceRuntimeMissing", {
13701
+ class WorkspaceRuntimeMissing extends Schema71.TaggedErrorClass()("WorkspaceRuntimeMissing", {
13553
13702
  execution_id: exports_ids_schema.ExecutionId
13554
13703
  }) {
13555
13704
  }
13556
13705
 
13557
- class WorkspaceLeaseMissingRef extends Schema70.TaggedErrorClass()("WorkspaceLeaseMissingRef", {
13706
+ class WorkspaceLeaseMissingRef extends Schema71.TaggedErrorClass()("WorkspaceLeaseMissingRef", {
13558
13707
  execution_id: exports_ids_schema.ExecutionId
13559
13708
  }) {
13560
13709
  }
13561
13710
 
13562
- class WorkspacePlannerError extends Schema70.TaggedErrorClass()("WorkspacePlannerError", {
13563
- message: Schema70.String
13711
+ class WorkspacePlannerError extends Schema71.TaggedErrorClass()("WorkspacePlannerError", {
13712
+ message: Schema71.String
13564
13713
  }) {
13565
13714
  }
13566
13715
 
@@ -13746,7 +13895,7 @@ var fail = Effect78.fn("WorkspacePlanner.fail.call")(function* (input) {
13746
13895
  });
13747
13896
 
13748
13897
  // ../runtime/src/workflow/execution-workflow-state.ts
13749
- import { Option as Option19, Schema as Schema71 } from "effect";
13898
+ import { Option as Option19, Schema as Schema72 } from "effect";
13750
13899
  var toWaitSnapshot = (record2) => ({
13751
13900
  id: record2.id,
13752
13901
  execution_id: record2.executionId,
@@ -13814,7 +13963,7 @@ var waitIdFromExecution = (execution) => {
13814
13963
  };
13815
13964
  var pendingSuspensionFromExecution = (execution) => {
13816
13965
  const pending = execution.metadata?.pending_agent_suspension;
13817
- return Schema71.decodeUnknownOption(exports_agent_event.AgentSuspended)(pending).pipe(Option19.getOrUndefined);
13966
+ return Schema72.decodeUnknownOption(exports_agent_event.AgentSuspended)(pending).pipe(Option19.getOrUndefined);
13818
13967
  };
13819
13968
  var ExecutionWorkflowState = {
13820
13969
  agentDefinitionPinCount,
@@ -13855,74 +14004,74 @@ var {
13855
14004
  workflowGenerationFromRecord: workflowGenerationFromRecord2
13856
14005
  } = ExecutionWorkflowState;
13857
14006
 
13858
- class ExecutionWorkflowFailed extends Schema72.TaggedErrorClass()("ExecutionWorkflowFailed", {
13859
- message: Schema72.String,
13860
- terminal_failure: Schema72.optionalKey(AgentTerminalFailure)
14007
+ class ExecutionWorkflowFailed extends Schema73.TaggedErrorClass()("ExecutionWorkflowFailed", {
14008
+ message: Schema73.String,
14009
+ terminal_failure: Schema73.optionalKey(AgentTerminalFailure)
13861
14010
  }) {
13862
14011
  }
13863
14012
 
13864
- class AgentCheckpointCompatibilityError extends Schema72.TaggedErrorClass()("AgentCheckpointCompatibilityError", {
13865
- message: Schema72.String
14013
+ class AgentCheckpointCompatibilityError extends Schema73.TaggedErrorClass()("AgentCheckpointCompatibilityError", {
14014
+ message: Schema73.String
13866
14015
  }) {
13867
14016
  }
13868
- var ExecutionWorkflowError = Schema72.Union([ExecutionWorkflowFailed, AgentCheckpointCompatibilityError]);
13869
- var StartInput = Schema72.Struct({
14017
+ var ExecutionWorkflowError = Schema73.Union([ExecutionWorkflowFailed, AgentCheckpointCompatibilityError]);
14018
+ var StartInput = Schema73.Struct({
13870
14019
  execution_id: exports_ids_schema.ExecutionId,
13871
14020
  root_address_id: exports_ids_schema.AddressId,
13872
- session_id: Schema72.optionalKey(exports_ids_schema.SessionId),
13873
- input: Schema72.optionalKey(Schema72.Array(exports_content_schema.Part)),
14021
+ session_id: Schema73.optionalKey(exports_ids_schema.SessionId),
14022
+ input: Schema73.optionalKey(Schema73.Array(exports_content_schema.Part)),
13874
14023
  event_sequence: exports_execution_schema.ExecutionEventSequence,
13875
14024
  started_at: exports_shared_schema.TimestampMillis,
13876
14025
  completed_at: exports_shared_schema.TimestampMillis,
13877
- agent_id: Schema72.optionalKey(exports_ids_schema.AgentId),
13878
- agent_revision: Schema72.optionalKey(exports_agent_schema.DefinitionRevision),
13879
- agent_snapshot: Schema72.optionalKey(exports_agent_schema.Definition),
13880
- agent_tool_input_schema_digests: Schema72.optionalKey(exports_agent_schema.ToolInputSchemaDigests),
13881
- wait_id: Schema72.optionalKey(exports_ids_schema.WaitId),
13882
- resume_suspension: Schema72.optionalKey(exports_agent_event.AgentSuspended),
13883
- workflow_generation: Schema72.optionalKey(Schema72.Int.check(Schema72.isGreaterThanOrEqualTo(0))),
13884
- metadata: Schema72.optionalKey(exports_shared_schema.Metadata)
14026
+ agent_id: Schema73.optionalKey(exports_ids_schema.AgentId),
14027
+ agent_revision: Schema73.optionalKey(exports_agent_schema.DefinitionRevision),
14028
+ agent_snapshot: Schema73.optionalKey(exports_agent_schema.Definition),
14029
+ agent_tool_input_schema_digests: Schema73.optionalKey(exports_agent_schema.ToolInputSchemaDigests),
14030
+ wait_id: Schema73.optionalKey(exports_ids_schema.WaitId),
14031
+ resume_suspension: Schema73.optionalKey(exports_agent_event.AgentSuspended),
14032
+ workflow_generation: Schema73.optionalKey(Schema73.Int.check(Schema73.isGreaterThanOrEqualTo(0))),
14033
+ metadata: Schema73.optionalKey(exports_shared_schema.Metadata)
13885
14034
  }).annotate({ identifier: "Relay.ExecutionWorkflow.StartInput" });
13886
- var WaitSignalState = Schema72.Literals(["resolved", "timed_out", "cancelled"]).annotate({
14035
+ var WaitSignalState = Schema73.Literals(["resolved", "timed_out", "cancelled"]).annotate({
13887
14036
  identifier: "Relay.ExecutionWorkflow.WaitSignalState"
13888
14037
  });
13889
- var WaitSignal = Schema72.Struct({
14038
+ var WaitSignal = Schema73.Struct({
13890
14039
  wait_id: exports_ids_schema.WaitId,
13891
14040
  state: WaitSignalState,
13892
14041
  signaled_at: exports_shared_schema.TimestampMillis
13893
14042
  }).annotate({ identifier: "Relay.ExecutionWorkflow.WaitSignal" });
13894
- var SignalWaitInput = Schema72.Struct({
13895
- workflow_execution_id: Schema72.String,
14043
+ var SignalWaitInput = Schema73.Struct({
14044
+ workflow_execution_id: Schema73.String,
13896
14045
  wait_id: exports_ids_schema.WaitId,
13897
14046
  state: WaitSignalState,
13898
14047
  signaled_at: exports_shared_schema.TimestampMillis
13899
14048
  }).annotate({ identifier: "Relay.ExecutionWorkflow.SignalWaitInput" });
13900
- var CancelExecutionInput = Schema72.Struct({
14049
+ var CancelExecutionInput = Schema73.Struct({
13901
14050
  execution_id: exports_ids_schema.ExecutionId,
13902
14051
  cancelled_at: exports_shared_schema.TimestampMillis,
13903
- reason: Schema72.optionalKey(Schema72.String)
14052
+ reason: Schema73.optionalKey(Schema73.String)
13904
14053
  }).annotate({ identifier: "Relay.ExecutionWorkflow.CancelExecutionInput" });
13905
- var CancelExecutionResult = Schema72.Struct({
14054
+ var CancelExecutionResult = Schema73.Struct({
13906
14055
  execution_id: exports_ids_schema.ExecutionId,
13907
14056
  status: exports_execution_schema.ExecutionStatus
13908
14057
  }).annotate({ identifier: "Relay.ExecutionWorkflow.CancelExecutionResult" });
13909
- var WaitSnapshot = Schema72.Struct({
14058
+ var WaitSnapshot = Schema73.Struct({
13910
14059
  id: exports_ids_schema.WaitId,
13911
14060
  execution_id: exports_ids_schema.ExecutionId,
13912
- envelope_id: Schema72.optionalKey(exports_ids_schema.EnvelopeId),
14061
+ envelope_id: Schema73.optionalKey(exports_ids_schema.EnvelopeId),
13913
14062
  mode: exports_envelope_schema.WaitMode,
13914
- correlation_key: Schema72.optionalKey(Schema72.String),
13915
- state: Schema72.Literals(["open", "resolved", "timed_out", "cancelled"]),
14063
+ correlation_key: Schema73.optionalKey(Schema73.String),
14064
+ state: Schema73.Literals(["open", "resolved", "timed_out", "cancelled"]),
13916
14065
  metadata: exports_shared_schema.Metadata,
13917
14066
  created_at: exports_shared_schema.TimestampMillis,
13918
- resolved_at: Schema72.optionalKey(exports_shared_schema.TimestampMillis)
14067
+ resolved_at: Schema73.optionalKey(exports_shared_schema.TimestampMillis)
13919
14068
  }).annotate({ identifier: "Relay.ExecutionWorkflow.WaitSnapshot" });
13920
- var StartResult = Schema72.Struct({
14069
+ var StartResult = Schema73.Struct({
13921
14070
  execution_id: exports_ids_schema.ExecutionId,
13922
14071
  status: exports_execution_schema.ExecutionStatus,
13923
- wait_id: Schema72.optionalKey(exports_ids_schema.WaitId),
13924
- wait_state: Schema72.optionalKey(Schema72.Literals(["resolved", "timed_out", "cancelled"])),
13925
- metadata: Schema72.optionalKey(exports_shared_schema.Metadata)
14072
+ wait_id: Schema73.optionalKey(exports_ids_schema.WaitId),
14073
+ wait_state: Schema73.optionalKey(Schema73.Literals(["resolved", "timed_out", "cancelled"])),
14074
+ metadata: Schema73.optionalKey(exports_shared_schema.Metadata)
13926
14075
  }).annotate({ identifier: "Relay.ExecutionWorkflow.StartResult" });
13927
14076
  var StartExecutionWorkflowName = "Relay/Execution/Start";
13928
14077
  var ActivityNames = {
@@ -13970,12 +14119,12 @@ var StartExecutionWorkflow = Workflow2.make(StartExecutionWorkflowName, {
13970
14119
  var mapExecutionError = (error5) => {
13971
14120
  if (error5.details === undefined)
13972
14121
  return ExecutionWorkflowFailed.make({ message: error5.message });
13973
- const terminalFailure = Schema72.decodeUnknownOption(AgentTerminalFailure)(error5.details).pipe(Option20.getOrUndefined);
14122
+ const terminalFailure = Schema73.decodeUnknownOption(AgentTerminalFailure)(error5.details).pipe(Option20.getOrUndefined);
13974
14123
  return terminalFailure === undefined ? ExecutionWorkflowFailed.make({ message: "Malformed durable agent failure details" }) : ExecutionWorkflowFailed.make({ message: error5.message, terminal_failure: terminalFailure });
13975
14124
  };
13976
14125
  var mapAgentLoopError = (error5) => ExecutionServiceError.make({
13977
14126
  message: error5._tag === "AgentLoopBudgetExceeded" ? `AgentLoopBudgetExceeded: used ${error5.tokens_used} of ${error5.token_budget} tokens` : error5.message,
13978
- details: error5.pipe(Schema72.encodeSync(AgentTerminalFailure), Schema72.decodeUnknownSync(exports_shared_schema.JsonValue)),
14127
+ details: error5.pipe(Schema73.encodeSync(AgentTerminalFailure), Schema73.decodeUnknownSync(exports_shared_schema.JsonValue)),
13979
14128
  ...error5.next_event_sequence === undefined ? {} : { next_event_sequence: error5.next_event_sequence }
13980
14129
  });
13981
14130
  var mapWaitError2 = (error5) => ExecutionWorkflowFailed.make({
@@ -14124,7 +14273,7 @@ var prepareCancellation = Effect79.fn("ExecutionWorkflow.prepareCancellation")(f
14124
14273
  signals,
14125
14274
  terminalNoop: false
14126
14275
  };
14127
- })).pipe(Effect79.mapError((error5) => Schema72.is(ExecutionWorkflowFailed)(error5) ? error5 : ExecutionWorkflowFailed.make({ message: "Tool cancellation transaction failed" })));
14276
+ })).pipe(Effect79.mapError((error5) => Schema73.is(ExecutionWorkflowFailed)(error5) ? error5 : ExecutionWorkflowFailed.make({ message: "Tool cancellation transaction failed" })));
14128
14277
  });
14129
14278
  var signalPreparedCancellation = Effect79.fn("ExecutionWorkflow.signalPreparedCancellation")(function* (prepared, signaledAt) {
14130
14279
  for (const pending of prepared.signals) {
@@ -14149,23 +14298,39 @@ var cancelChildExecution = Effect79.fn("ExecutionWorkflow.cancelChildExecution")
14149
14298
  reason: childCancelReason
14150
14299
  });
14151
14300
  yield* signalPreparedCancellation(prepared, cancelledAt);
14301
+ const activeExecutions = yield* Effect79.serviceOption(Service57);
14302
+ if (Option20.isSome(activeExecutions)) {
14303
+ yield* activeExecutions.value.interrupt(executionId);
14304
+ yield* activeExecutions.value.awaitQuiescent(executionId);
14305
+ }
14152
14306
  });
14153
14307
  var cancelOpenChildren = Effect79.fn("ExecutionWorkflow.cancelOpenChildren")(function* (executionId, cancelledAt) {
14154
- const children = yield* exports_child_execution_repository.listByExecution(executionId).pipe(Effect79.mapError(mapChildExecutionRepositoryError));
14155
- yield* Effect79.forEach(children.filter((child) => openChildStatuses.has(child.status)), (child) => Effect79.gen(function* () {
14156
- yield* exports_child_execution_repository.updateStatus({
14157
- id: child.id,
14158
- status: "cancelled",
14159
- updatedAt: cancelledAt,
14160
- metadata: {
14161
- ...child.metadata,
14162
- cancellation_requested: true,
14163
- cancellation_reason: childCancelReason,
14164
- cancellation_requested_at: cancelledAt
14165
- }
14166
- }).pipe(Effect79.mapError(mapChildExecutionRepositoryError));
14167
- yield* cancelChildExecution(exports_ids_schema.ExecutionId.make(child.id), cancelledAt);
14168
- }), { discard: true });
14308
+ const pending = [executionId];
14309
+ const seen = new Set([executionId]);
14310
+ while (pending.length > 0) {
14311
+ const current2 = pending.shift();
14312
+ const children = yield* exports_child_execution_repository.listByExecution(current2).pipe(Effect79.mapError(mapChildExecutionRepositoryError));
14313
+ yield* Effect79.forEach(children.filter((child) => openChildStatuses.has(child.status)), (child) => Effect79.gen(function* () {
14314
+ yield* exports_child_execution_repository.updateStatus({
14315
+ id: child.id,
14316
+ status: "cancelled",
14317
+ updatedAt: cancelledAt,
14318
+ metadata: {
14319
+ ...child.metadata,
14320
+ cancellation_requested: true,
14321
+ cancellation_reason: childCancelReason,
14322
+ cancellation_requested_at: cancelledAt
14323
+ }
14324
+ }).pipe(Effect79.mapError(mapChildExecutionRepositoryError));
14325
+ yield* cancelChildExecution(exports_ids_schema.ExecutionId.make(child.id), cancelledAt);
14326
+ }), { discard: true });
14327
+ for (const child of children) {
14328
+ if (seen.has(child.id))
14329
+ continue;
14330
+ seen.add(child.id);
14331
+ pending.push(exports_ids_schema.ExecutionId.make(child.id));
14332
+ }
14333
+ }
14169
14334
  });
14170
14335
  var cancelExecution = (input, turn, reason) => Activity.make({
14171
14336
  name: ActivityNames.cancel(turn),
@@ -14185,7 +14350,7 @@ var cancelExecution = (input, turn, reason) => Activity.make({
14185
14350
  });
14186
14351
  var loadCancellationRequested = (input, turn) => Activity.make({
14187
14352
  name: ActivityNames.checkCancel(turn),
14188
- success: Schema72.Boolean,
14353
+ success: Schema73.Boolean,
14189
14354
  error: ExecutionWorkflowFailed,
14190
14355
  execute: Effect79.gen(function* () {
14191
14356
  const repository = yield* exports_execution_repository.Service;
@@ -14195,7 +14360,7 @@ var loadCancellationRequested = (input, turn) => Activity.make({
14195
14360
  });
14196
14361
  var loadWait = (name, waitId2) => Activity.make({
14197
14362
  name,
14198
- success: Schema72.UndefinedOr(WaitSnapshot),
14363
+ success: Schema73.UndefinedOr(WaitSnapshot),
14199
14364
  error: ExecutionWorkflowFailed,
14200
14365
  execute: get11(waitId2).pipe(Effect79.map((record2) => record2 === undefined ? undefined : toWaitSnapshot2(record2)), Effect79.mapError(mapWaitError2))
14201
14366
  });
@@ -14238,7 +14403,7 @@ var decodeOptionalNumberSetting = (value, key4, valid) => {
14238
14403
  var optionalNumberForStart = (input, key4, valid) => decodeOptionalNumberSetting(metadataSetting2(input, key4), key4, valid).pipe(Effect79.map((value) => value === null ? undefined : value));
14239
14404
  var continueAsNewAfterTurnsForStart = (input) => optionalNumberForStart(input, continueAsNewAfterTurnsMetadataKey2, (value) => Number.isInteger(value) && value > 0);
14240
14405
  var toolOutputMaxBytesForStart = (input) => decodeOptionalNumberSetting(metadataSetting2(input, toolOutputMaxBytesMetadataKey2), toolOutputMaxBytesMetadataKey2, (value) => value >= 0);
14241
- var decodeMemorySubject = (value) => typeof value === "string" ? Schema72.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(value).pipe(Effect79.mapError(() => ExecutionWorkflowFailed.make({ message: `Invalid memory_subject_id metadata value: ${value}` }))) : Effect79.fail(ExecutionWorkflowFailed.make({ message: "memory_subject_id metadata value must be a string" }));
14406
+ var decodeMemorySubject = (value) => typeof value === "string" ? Schema73.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(value).pipe(Effect79.mapError(() => ExecutionWorkflowFailed.make({ message: `Invalid memory_subject_id metadata value: ${value}` }))) : Effect79.fail(ExecutionWorkflowFailed.make({ message: "memory_subject_id metadata value must be a string" }));
14242
14407
  var memorySubjectForStart = Effect79.fn("ExecutionWorkflow.memorySubjectForStart")(function* (input) {
14243
14408
  const executionSubject = memorySubjectFromMetadata2(input.metadata);
14244
14409
  if (executionSubject !== undefined)
@@ -14249,7 +14414,7 @@ var memorySubjectForStart = Effect79.fn("ExecutionWorkflow.memorySubjectForStart
14249
14414
  var nextEventSequence4 = (eventLog, executionId) => eventLog.maxSequence(executionId).pipe(Effect79.map((max) => max === undefined ? 0 : max + 1), Effect79.mapError(mapEventLogError6));
14250
14415
  var ensureWorkspace = (input) => Activity.make({
14251
14416
  name: ActivityNames.ensureWorkspace,
14252
- success: Schema72.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14417
+ success: Schema73.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14253
14418
  error: ExecutionWorkflowFailed,
14254
14419
  execute: Effect79.gen(function* () {
14255
14420
  if (input.agent_snapshot === undefined)
@@ -14266,19 +14431,19 @@ var ensureWorkspace = (input) => Activity.make({
14266
14431
  });
14267
14432
  var suspendWorkspace = (input, key4) => Activity.make({
14268
14433
  name: ActivityNames.suspendWorkspace(key4),
14269
- success: Schema72.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14434
+ success: Schema73.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14270
14435
  error: ExecutionWorkflowFailed,
14271
14436
  execute: suspend2({ executionId: input.execution_id, now: input.started_at }).pipe(Effect79.mapError(mapWorkspaceError))
14272
14437
  });
14273
14438
  var resumeWorkspace = (input, key4) => Activity.make({
14274
14439
  name: ActivityNames.resumeWorkspace(key4),
14275
- success: Schema72.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14440
+ success: Schema73.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14276
14441
  error: ExecutionWorkflowFailed,
14277
14442
  execute: resume2({ executionId: input.execution_id, now: input.started_at }).pipe(Effect79.map((plan2) => plan2?.lease), Effect79.mapError(mapWorkspaceError))
14278
14443
  });
14279
14444
  var releaseWorkspace = (input) => Activity.make({
14280
14445
  name: ActivityNames.releaseWorkspace,
14281
- success: Schema72.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14446
+ success: Schema73.UndefinedOr(exports_workspace_schema.WorkspaceLeaseRecord),
14282
14447
  error: ExecutionWorkflowFailed,
14283
14448
  execute: release2({ executionId: input.execution_id, now: input.completed_at }).pipe(Effect79.mapError(mapWorkspaceError))
14284
14449
  });
@@ -14354,7 +14519,7 @@ var completeExecution = (input, waitId2, waitState, workspaceRuntimeLayer, turn,
14354
14519
  ...input.metadata,
14355
14520
  wait_id: wait.wait_id,
14356
14521
  wait_state: "open",
14357
- pending_agent_suspension: wait.suspension.pipe(Schema72.encodeSync(exports_agent_event.AgentSuspended), Schema72.decodeUnknownSync(exports_shared_schema.JsonValue)),
14522
+ pending_agent_suspension: wait.suspension.pipe(Schema73.encodeSync(exports_agent_event.AgentSuspended), Schema73.decodeUnknownSync(exports_shared_schema.JsonValue)),
14358
14523
  ...generationMetadata2(workflowGenerationForStart2(input))
14359
14524
  },
14360
14525
  nextEventSequence: wait.next_event_sequence
@@ -14370,12 +14535,12 @@ var completeExecution = (input, waitId2, waitState, workspaceRuntimeLayer, turn,
14370
14535
  });
14371
14536
  var failIncompatibleCheckpoint = (input, error5) => Activity.make({
14372
14537
  name: ActivityNames.failIncompatibleCheckpoint,
14373
- success: Schema72.Void,
14538
+ success: Schema73.Void,
14374
14539
  error: ExecutionWorkflowFailed,
14375
14540
  execute: Effect79.gen(function* () {
14376
14541
  const eventLog = yield* Service41;
14377
14542
  const eventSequence = yield* nextEventSequence4(eventLog, input.execution_id);
14378
- const details = yield* error5.pipe(Schema72.encodeEffect(AgentCheckpointCompatibilityError), Effect79.flatMap(Schema72.decodeUnknownEffect(exports_shared_schema.JsonValue)), Effect79.mapError(() => ExecutionWorkflowFailed.make({ message: "Invalid checkpoint failure details" })));
14543
+ const details = yield* error5.pipe(Schema73.encodeEffect(AgentCheckpointCompatibilityError), Effect79.flatMap(Schema73.decodeUnknownEffect(exports_shared_schema.JsonValue)), Effect79.mapError(() => ExecutionWorkflowFailed.make({ message: "Invalid checkpoint failure details" })));
14379
14544
  yield* run4({
14380
14545
  executionId: input.execution_id,
14381
14546
  eventSequence,
@@ -14390,7 +14555,7 @@ var failIncompatibleCheckpoint = (input, error5) => Activity.make({
14390
14555
  });
14391
14556
  var loadChildCancellationRequested = (input) => Activity.make({
14392
14557
  name: ActivityNames.checkQueuedChildCancellation,
14393
- success: Schema72.Boolean,
14558
+ success: Schema73.Boolean,
14394
14559
  error: ExecutionWorkflowFailed,
14395
14560
  execute: Effect79.gen(function* () {
14396
14561
  const context = childDispatchContext2(input);
@@ -14402,7 +14567,7 @@ var loadChildCancellationRequested = (input) => Activity.make({
14402
14567
  });
14403
14568
  var notifyParentActivity = (input, context, status, output) => Activity.make({
14404
14569
  name: ActivityNames.notifyParent(status),
14405
- success: Schema72.Void,
14570
+ success: Schema73.Void,
14406
14571
  error: ExecutionWorkflowFailed,
14407
14572
  execute: Effect79.gen(function* () {
14408
14573
  const notifier = yield* Effect79.serviceOption(Service54);
@@ -14632,6 +14797,10 @@ var cancelRequest = Effect79.fn("ExecutionWorkflow.cancelRequest")(function* (in
14632
14797
  return { execution_id: prepared.record.id, status: prepared.status };
14633
14798
  }
14634
14799
  yield* signalPreparedCancellation(prepared, input.cancelled_at);
14800
+ if (Option20.isSome(activeExecutions)) {
14801
+ yield* activeExecutions.value.interrupt(prepared.record.id);
14802
+ yield* activeExecutions.value.awaitQuiescent(prepared.record.id);
14803
+ }
14635
14804
  yield* cancelOpenChildren(prepared.record.id, input.cancelled_at);
14636
14805
  const eventLog = yield* Service41;
14637
14806
  const eventSequence = yield* nextEventSequence4(eventLog, prepared.record.id);
@@ -14642,8 +14811,6 @@ var cancelRequest = Effect79.fn("ExecutionWorkflow.cancelRequest")(function* (in
14642
14811
  ...input.reason === undefined ? {} : { reason: input.reason },
14643
14812
  metadata: prepared.record.metadata
14644
14813
  }).pipe(Effect79.mapError(mapExecutionError));
14645
- if (Option20.isSome(activeExecutions))
14646
- yield* activeExecutions.value.interrupt(prepared.record.id);
14647
14814
  return { execution_id: prepared.record.id, status: cancelled.status };
14648
14815
  });
14649
14816
  var workflowIdPlaceholderAddressId = exports_ids_schema.AddressId.make("address:workflow-id-placeholder");
@@ -14678,8 +14845,8 @@ var signalWait = Effect79.fn("ExecutionWorkflow.signalWait")(function* (input) {
14678
14845
  });
14679
14846
 
14680
14847
  // ../runtime/src/wait/wait-signal.ts
14681
- class WaitSignalError extends Schema73.TaggedErrorClass()("WaitSignalError", {
14682
- message: Schema73.String
14848
+ class WaitSignalError extends Schema74.TaggedErrorClass()("WaitSignalError", {
14849
+ message: Schema74.String
14683
14850
  }) {
14684
14851
  }
14685
14852
  var signalWorkflowWait = Effect80.fn("WaitSignal.signalWorkflowWait")(function* (input) {
@@ -14698,19 +14865,19 @@ var signalWorkflowWait = Effect80.fn("WaitSignal.signalWorkflowWait")(function*
14698
14865
  });
14699
14866
 
14700
14867
  // ../runtime/src/inbox/inbox-service.ts
14701
- class InboxDeliveryError extends Schema74.TaggedErrorClass()("InboxDeliveryError", {
14868
+ class InboxDeliveryError extends Schema75.TaggedErrorClass()("InboxDeliveryError", {
14702
14869
  execution_id: exports_ids_schema.ExecutionId,
14703
- message: Schema74.String
14870
+ message: Schema75.String
14704
14871
  }) {
14705
14872
  }
14706
14873
 
14707
- class InboxReplyTokenInvalid extends Schema74.TaggedErrorClass()("InboxReplyTokenInvalid", {
14708
- reply_token: Schema74.String
14874
+ class InboxReplyTokenInvalid extends Schema75.TaggedErrorClass()("InboxReplyTokenInvalid", {
14875
+ reply_token: Schema75.String
14709
14876
  }) {
14710
14877
  }
14711
14878
 
14712
- class InboxServiceError extends Schema74.TaggedErrorClass()("InboxServiceError", {
14713
- message: Schema74.String
14879
+ class InboxServiceError extends Schema75.TaggedErrorClass()("InboxServiceError", {
14880
+ message: Schema75.String
14714
14881
  }) {
14715
14882
  }
14716
14883
 
@@ -14818,9 +14985,9 @@ var layerWithSignal = (dependencies) => makeLayer2(dependencies);
14818
14985
  var memoryLayer42 = layer50.pipe(Layer67.provide(exports_inbox_repository.memoryLayer), Layer67.provide(exports_envelope_repository.memoryLayer));
14819
14986
 
14820
14987
  // ../runtime/src/topic/topic-service.ts
14821
- import { Clock as Clock13, Context as Context62, Effect as Effect82, Layer as Layer68, Random as Random2, Schema as Schema75 } from "effect";
14822
- class TopicServiceError extends Schema75.TaggedErrorClass()("TopicServiceError", {
14823
- message: Schema75.String
14988
+ import { Clock as Clock13, Context as Context62, Effect as Effect82, Layer as Layer68, Random as Random2, Schema as Schema76 } from "effect";
14989
+ class TopicServiceError extends Schema76.TaggedErrorClass()("TopicServiceError", {
14990
+ message: Schema76.String
14824
14991
  }) {
14825
14992
  }
14826
14993
 
@@ -14896,17 +15063,17 @@ var layer51 = Layer68.effect(Service63, Effect82.gen(function* () {
14896
15063
  var memoryLayer43 = layer51.pipe(Layer68.provide(exports_topic_repository.memoryLayer));
14897
15064
 
14898
15065
  // ../runtime/src/topic/publish-to-topic-tool.ts
14899
- import { Effect as Effect83, Schema as Schema76 } from "effect";
15066
+ import { Effect as Effect83, Schema as Schema77 } from "effect";
14900
15067
  var toolName3 = "publish_to_topic";
14901
15068
  var permissionName3 = "relay.topic.publish";
14902
- var ContentInput = Schema76.Union([Schema76.String, Schema76.Array(exports_content_schema.TextPart)]);
14903
- var Input3 = Schema76.Struct({
14904
- topic: Schema76.String,
15069
+ var ContentInput = Schema77.Union([Schema77.String, Schema77.Array(exports_content_schema.TextPart)]);
15070
+ var Input3 = Schema77.Struct({
15071
+ topic: Schema77.String,
14905
15072
  content: ContentInput
14906
15073
  }).annotate({ identifier: "Relay.PublishToTopicTool.Input" });
14907
- var Output3 = Schema76.Struct({
14908
- envelope_id: Schema76.String,
14909
- subscriber_count: Schema76.Int
15074
+ var Output3 = Schema77.Struct({
15075
+ envelope_id: Schema77.String,
15076
+ subscriber_count: Schema77.Int
14910
15077
  }).annotate({ identifier: "Relay.PublishToTopicTool.Output" });
14911
15078
  var registeredTool3 = (config) => tool(toolName3, {
14912
15079
  description: "Publish a durable message to every subscriber of a topic.",
@@ -14928,23 +15095,23 @@ var registeredTool3 = (config) => tool(toolName3, {
14928
15095
  });
14929
15096
 
14930
15097
  // ../runtime/src/inbox/wait-for-messages-tool.ts
14931
- import { Effect as Effect84, Schema as Schema77 } from "effect";
15098
+ import { Effect as Effect84, Schema as Schema78 } from "effect";
14932
15099
  var toolName4 = "wait_for_messages";
14933
15100
  var permissionName4 = "relay.inbox.wait";
14934
- var Input4 = Schema77.Struct({ timeout: Schema77.optionalKey(Schema77.String) }).annotate({
15101
+ var Input4 = Schema78.Struct({ timeout: Schema78.optionalKey(Schema78.String) }).annotate({
14935
15102
  identifier: "Relay.WaitForMessagesTool.Input"
14936
15103
  });
14937
- var MessageView = Schema77.Struct({
14938
- sequence: Schema77.Int,
14939
- from: Schema77.String,
14940
- content: Schema77.Array(exports_content_schema.TextPart),
14941
- reply_token: Schema77.optionalKey(Schema77.String),
14942
- correlation_key: Schema77.optionalKey(Schema77.String),
14943
- metadata: Schema77.optionalKey(exports_shared_schema.Metadata)
15104
+ var MessageView = Schema78.Struct({
15105
+ sequence: Schema78.Int,
15106
+ from: Schema78.String,
15107
+ content: Schema78.Array(exports_content_schema.TextPart),
15108
+ reply_token: Schema78.optionalKey(Schema78.String),
15109
+ correlation_key: Schema78.optionalKey(Schema78.String),
15110
+ metadata: Schema78.optionalKey(exports_shared_schema.Metadata)
14944
15111
  }).annotate({ identifier: "Relay.WaitForMessagesTool.MessageView" });
14945
- var Output4 = Schema77.Struct({
14946
- status: Schema77.Literals(["messages", "timed_out"]),
14947
- messages: Schema77.Array(MessageView)
15112
+ var Output4 = Schema78.Struct({
15113
+ status: Schema78.Literals(["messages", "timed_out"]),
15114
+ messages: Schema78.Array(MessageView)
14948
15115
  }).annotate({ identifier: "Relay.WaitForMessagesTool.Output" });
14949
15116
  var project = (message) => ({
14950
15117
  sequence: message.sequence,
@@ -15001,18 +15168,18 @@ var registeredTool4 = (config) => tool(toolName4, {
15001
15168
  });
15002
15169
 
15003
15170
  // ../runtime/src/inbox/send-message-tool.ts
15004
- import { Effect as Effect85, Schema as Schema78 } from "effect";
15171
+ import { Effect as Effect85, Schema as Schema79 } from "effect";
15005
15172
  var toolName5 = "send_message";
15006
15173
  var permissionName5 = "relay.inbox.send";
15007
- var ContentInput2 = Schema78.Union([Schema78.String, Schema78.Array(exports_content_schema.TextPart)]);
15008
- var Input5 = Schema78.Struct({
15009
- to: Schema78.String,
15174
+ var ContentInput2 = Schema79.Union([Schema79.String, Schema79.Array(exports_content_schema.TextPart)]);
15175
+ var Input5 = Schema79.Struct({
15176
+ to: Schema79.String,
15010
15177
  content: ContentInput2,
15011
- reply_token: Schema78.optionalKey(Schema78.String)
15178
+ reply_token: Schema79.optionalKey(Schema79.String)
15012
15179
  }).annotate({ identifier: "Relay.SendMessageTool.Input" });
15013
- var Output5 = Schema78.Struct({
15014
- envelope_id: Schema78.String,
15015
- delivered: Schema78.Literals(["inbox", "outbox", "reply"])
15180
+ var Output5 = Schema79.Struct({
15181
+ envelope_id: Schema79.String,
15182
+ delivered: Schema79.Literals(["inbox", "outbox", "reply"])
15016
15183
  }).annotate({ identifier: "Relay.SendMessageTool.Output" });
15017
15184
  var registeredTool5 = (config) => tool(toolName5, {
15018
15185
  description: "Send a durable message to an address or reply to an inbox message.",
@@ -15050,26 +15217,26 @@ var registeredTool5 = (config) => tool(toolName5, {
15050
15217
  });
15051
15218
 
15052
15219
  // ../runtime/src/envelope/envelope-service.ts
15053
- import { Context as Context63, Effect as Effect86, Layer as Layer69, Schema as Schema79 } from "effect";
15054
- class EnvelopeAddressNotFound extends Schema79.TaggedErrorClass()("EnvelopeAddressNotFound", {
15220
+ import { Context as Context63, Effect as Effect86, Layer as Layer69, Schema as Schema80 } from "effect";
15221
+ class EnvelopeAddressNotFound extends Schema80.TaggedErrorClass()("EnvelopeAddressNotFound", {
15055
15222
  address_id: exports_ids_schema.AddressId
15056
15223
  }) {
15057
15224
  }
15058
15225
 
15059
- class EnvelopeRouteUnavailable extends Schema79.TaggedErrorClass()("EnvelopeRouteUnavailable", {
15226
+ class EnvelopeRouteUnavailable extends Schema80.TaggedErrorClass()("EnvelopeRouteUnavailable", {
15060
15227
  address_id: exports_ids_schema.AddressId,
15061
- route_key: Schema79.String
15228
+ route_key: Schema80.String
15062
15229
  }) {
15063
15230
  }
15064
15231
 
15065
- class EnvelopeRouteDeferred extends Schema79.TaggedErrorClass()("EnvelopeRouteDeferred", {
15232
+ class EnvelopeRouteDeferred extends Schema80.TaggedErrorClass()("EnvelopeRouteDeferred", {
15066
15233
  address_id: exports_ids_schema.AddressId,
15067
- route_key: Schema79.String
15234
+ route_key: Schema80.String
15068
15235
  }) {
15069
15236
  }
15070
15237
 
15071
- class EnvelopeServiceError extends Schema79.TaggedErrorClass()("EnvelopeServiceError", {
15072
- message: Schema79.String
15238
+ class EnvelopeServiceError extends Schema80.TaggedErrorClass()("EnvelopeServiceError", {
15239
+ message: Schema80.String
15073
15240
  }) {
15074
15241
  }
15075
15242
 
@@ -15250,7 +15417,7 @@ var send2 = Effect86.fn("EnvelopeService.send.call")(function* (input) {
15250
15417
  });
15251
15418
 
15252
15419
  // ../runtime/src/agent/relay-approvals.ts
15253
- var layer53 = exports_approvals.autoApprove;
15420
+ var layer53 = exports_approvals.layerAutoApprove;
15254
15421
 
15255
15422
  // ../runtime/src/agent/relay-compaction.ts
15256
15423
  import { Clock as Clock14, Effect as Effect87, Layer as Layer70 } from "effect";
@@ -15301,11 +15468,11 @@ var make8 = (config) => exports_compaction.make(strategy(config), defaultOptions
15301
15468
  var layerFromEpoch = (epoch) => exports_instructions.layer(epoch.baseline.length === 0 ? [] : [exports_instructions.staticSource("relay:context-epoch", epoch.baseline)]);
15302
15469
 
15303
15470
  // ../runtime/src/agent/relay-permissions.ts
15304
- import { Clock as Clock15, Effect as Effect88, Layer as Layer71, Option as Option21, Schema as Schema80 } from "effect";
15305
- var jsonValue3 = (value) => Schema80.decodeUnknownSync(exports_shared_schema.JsonValue)(value === undefined ? null : value);
15471
+ import { Clock as Clock15, Effect as Effect88, Layer as Layer71, Option as Option21, Schema as Schema81 } from "effect";
15472
+ var permissionTokenPrefix = "wait:permission:";
15473
+ var jsonValue3 = (value) => Schema81.decodeUnknownSync(exports_shared_schema.JsonValue)(value === undefined ? null : value);
15306
15474
  var waitIdForToolCall = (executionId, toolCallId) => Identifiers.waitId("permission", executionId, toolCallId);
15307
- var fallbackToolCallId = (request) => `${request.agentName}:${request.turn}:${request.tool}`;
15308
- var tokenFor = (executionId, request) => waitIdForToolCall(executionId, request.toolCallId ?? fallbackToolCallId(request));
15475
+ var tokenFor = (executionId, request) => waitIdForToolCall(executionId, request.call.id);
15309
15476
  var matchingRule = (rules, tool3, params) => {
15310
15477
  let matched;
15311
15478
  for (const rule of rules) {
@@ -15315,7 +15482,7 @@ var matchingRule = (rules, tool3, params) => {
15315
15482
  return matched;
15316
15483
  };
15317
15484
  var staticDecision = (executionId, ruleset, request) => {
15318
- const rule = matchingRule(ruleset.rules, request.tool, request.params);
15485
+ const rule = matchingRule(ruleset.rules, request.call.name, request.call.params);
15319
15486
  const level = rule?.level ?? ruleset.fallback ?? "ask";
15320
15487
  switch (level) {
15321
15488
  case "allow":
@@ -15329,25 +15496,8 @@ var staticDecision = (executionId, ruleset, request) => {
15329
15496
  return { _tag: "Ask", token: tokenFor(executionId, request) };
15330
15497
  }
15331
15498
  };
15332
- var evaluateDecision = Effect88.fn("RelayPermissions.evaluateDecision")(function* (config, request) {
15333
- const remembered = yield* config.repository.list({ agent: config.agentName, scope: config.scope }).pipe(Effect88.mapError((error5) => permissionError(error5.message)));
15334
- const rule = matchingRule(remembered.map((record2) => record2.rule), request.tool, request.params);
15335
- if (rule !== undefined) {
15336
- switch (rule.level) {
15337
- case "allow":
15338
- return { _tag: "Allow" };
15339
- case "deny":
15340
- return {
15341
- _tag: "Deny",
15342
- ...rule.reason === undefined ? {} : { reason: rule.reason }
15343
- };
15344
- case "ask":
15345
- return { _tag: "Ask", token: tokenFor(config.executionId, request) };
15346
- }
15347
- }
15348
- return staticDecision(config.executionId, config.ruleset, request);
15349
- });
15350
15499
  var permissionError = (message) => exports_permissions.PermissionError.make({ message });
15500
+ var rememberedRules = (config) => config.repository.list({ agent: config.agentName, scope: config.scope }).pipe(Effect88.mapError((error5) => permissionError(error5.message)), Effect88.map((records) => records.map((record2) => record2.rule)));
15351
15501
  var createdAtForSequence = (config, sequence) => config.startedAt + sequence - config.eventSequence;
15352
15502
  var nextLoggedSequence = (eventLog, executionId, fallback) => eventLog.maxSequence(executionId).pipe(Effect88.mapError((error5) => permissionError(error5.message)), Effect88.map((max) => max === undefined ? fallback : Math.max(max + 1, fallback)));
15353
15503
  var allocateEventSequence = Effect88.fn("RelayPermissions.allocateEventSequence")(function* (config) {
@@ -15357,19 +15507,19 @@ var allocateEventSequence = Effect88.fn("RelayPermissions.allocateEventSequence"
15357
15507
  return sequence;
15358
15508
  });
15359
15509
  var resetAllocatorToLog = (config) => config.allocator.current.pipe(Effect88.flatMap((current2) => nextLoggedSequence(config.eventLog, config.executionId, current2)), Effect88.flatMap(config.allocator.resetTo));
15360
- var permissionRequestedCursor = (config, pending, waitId2) => `${config.executionId}:permission:${pending.toolCallId ?? waitId2}:requested`;
15361
- var permissionResolvedCursor = (config, pending, wait) => `${config.executionId}:permission:${pending.toolCallId ?? wait.id}:resolved`;
15510
+ var permissionRequestedCursor = (config, pending) => `${config.executionId}:permission:${pending.call.id}:requested`;
15511
+ var permissionResolvedCursor = (config, pending) => `${config.executionId}:permission:${pending.call.id}:resolved`;
15362
15512
  var permissionRequestedEvent = (config, pending, waitId2, sequence) => ({
15363
- id: Identifiers.eventId(config.executionId, pending.toolCallId ?? waitId2, "permission-requested"),
15513
+ id: Identifiers.eventId(config.executionId, pending.call.id, "permission-requested"),
15364
15514
  execution_id: config.executionId,
15365
15515
  type: "permission.ask.requested",
15366
15516
  sequence,
15367
- cursor: permissionRequestedCursor(config, pending, waitId2),
15517
+ cursor: permissionRequestedCursor(config, pending),
15368
15518
  data: {
15369
- tool_call_id: pending.toolCallId ?? pending.token,
15370
- tool_name: pending.tool,
15519
+ tool_call_id: pending.call.id,
15520
+ tool_name: pending.call.name,
15371
15521
  wait_id: waitId2,
15372
- input: jsonValue3(pending.params),
15522
+ input: jsonValue3(pending.call.params),
15373
15523
  agent_name: pending.agentName,
15374
15524
  scope: config.scope
15375
15525
  },
@@ -15394,15 +15544,28 @@ var answerForWait = (wait) => {
15394
15544
  return { _tag: "Denied", reason: "Permission ask cancelled" };
15395
15545
  return { _tag: "Denied", reason: "Permission denied" };
15396
15546
  };
15547
+ var resolutionForAnswer = (pending, answer) => {
15548
+ switch (answer._tag) {
15549
+ case "Approved":
15550
+ return { _tag: "Approved" };
15551
+ case "Always":
15552
+ return { _tag: "Approved", remember: { pattern: pending.call.name, level: "allow" } };
15553
+ case "Denied":
15554
+ return {
15555
+ _tag: "Denied",
15556
+ ...answer.reason === undefined ? {} : { reason: answer.reason }
15557
+ };
15558
+ }
15559
+ };
15397
15560
  var permissionResolvedEvent = (config, pending, wait, answer, sequence) => ({
15398
- id: Identifiers.eventId(config.executionId, pending.toolCallId ?? wait.id, "permission-resolved"),
15561
+ id: Identifiers.eventId(config.executionId, pending.call.id, "permission-resolved"),
15399
15562
  execution_id: config.executionId,
15400
15563
  type: "permission.ask.resolved",
15401
15564
  sequence,
15402
- cursor: permissionResolvedCursor(config, pending, wait),
15565
+ cursor: permissionResolvedCursor(config, pending),
15403
15566
  data: {
15404
- tool_call_id: pending.toolCallId ?? "",
15405
- tool_name: pending.tool,
15567
+ tool_call_id: pending.call.id,
15568
+ tool_name: pending.call.name,
15406
15569
  wait_id: wait.id,
15407
15570
  answer: answer._tag,
15408
15571
  state: wait.state
@@ -15416,7 +15579,7 @@ var appendPermissionEvent = (config, event) => appendIdempotentTo(config.eventLo
15416
15579
  onSome: (prior) => samePermissionEvent(prior, event) ? Effect88.succeed(prior) : Effect88.fail(permissionError(error5.message))
15417
15580
  })))), Effect88.mapError((error5) => permissionError(error5.message)), Effect88.tap(() => resetAllocatorToLog(config)));
15418
15581
  var ensurePermissionRequestedEvent = Effect88.fn("RelayPermissions.ensurePermissionRequestedEvent")(function* (config, pending, waitId2) {
15419
- const cursor = permissionRequestedCursor(config, pending, waitId2);
15582
+ const cursor = permissionRequestedCursor(config, pending);
15420
15583
  const existing = yield* findEventByCursor(config, cursor);
15421
15584
  if (Option21.isSome(existing))
15422
15585
  return;
@@ -15430,12 +15593,12 @@ var createAsk = Effect88.fn("RelayPermissions.createAsk")(function* (config, pen
15430
15593
  waitId: waitId2,
15431
15594
  executionId: config.executionId,
15432
15595
  mode: "event",
15433
- correlationKey: pending.toolCallId ?? pending.token,
15596
+ correlationKey: pending.call.id,
15434
15597
  metadata: {
15435
15598
  kind: "tool-permission",
15436
- tool_call_id: pending.toolCallId ?? pending.token,
15437
- tool_name: pending.tool,
15438
- input: jsonValue3(pending.params),
15599
+ tool_call_id: pending.call.id,
15600
+ tool_name: pending.call.name,
15601
+ input: jsonValue3(pending.call.params),
15439
15602
  agent_name: pending.agentName,
15440
15603
  scope: config.scope
15441
15604
  },
@@ -15449,26 +15612,27 @@ var awaitAnswer = Effect88.fn("RelayPermissions.awaitAnswer")(function* (config,
15449
15612
  const existing = yield* config.waits.get(waitId2).pipe(Effect88.mapError((error5) => permissionError(error5.message)));
15450
15613
  if (existing === undefined) {
15451
15614
  yield* createAsk(config, pending);
15452
- return Option21.none();
15615
+ return pending;
15453
15616
  }
15454
15617
  if (existing.state === "open") {
15455
15618
  yield* ensurePermissionRequestedEvent(config, pending, waitId2);
15456
- return Option21.none();
15619
+ return pending;
15457
15620
  }
15458
15621
  const answer = answerForWait(existing);
15459
- const resolvedCursor = permissionResolvedCursor(config, pending, existing);
15622
+ const resolvedCursor = permissionResolvedCursor(config, pending);
15460
15623
  const resolved = yield* findEventByCursor(config, resolvedCursor);
15461
15624
  if (Option21.isSome(resolved)) {
15462
15625
  yield* resetAllocatorToLog(config);
15463
- return Option21.some(answer);
15626
+ return resolutionForAnswer(pending, answer);
15464
15627
  }
15465
15628
  const resolvedSequence = yield* allocateEventSequence(config);
15466
15629
  yield* appendPermissionEvent(config, permissionResolvedEvent(config, pending, existing, answer, resolvedSequence));
15467
- return Option21.some(answer);
15630
+ return resolutionForAnswer(pending, answer);
15468
15631
  });
15632
+ var resolve8 = (config, pending) => pending.token.startsWith(permissionTokenPrefix) ? awaitAnswer(config, pending).pipe(Effect88.orDie) : Effect88.succeed({ _tag: "Approved" });
15469
15633
  var rememberRule = Effect88.fn("RelayPermissions.rememberRule")(function* (config, rule) {
15470
15634
  const createdAt = yield* Clock15.currentTimeMillis;
15471
- const decodedRule = yield* Schema80.decodeUnknownEffect(exports_agent_schema.PermissionRule)(rule).pipe(Effect88.mapError((error5) => permissionError(error5.message)));
15635
+ const decodedRule = yield* Schema81.decodeUnknownEffect(exports_agent_schema.PermissionRule)(rule).pipe(Effect88.mapError((error5) => permissionError(error5.message)));
15472
15636
  yield* config.repository.remember({
15473
15637
  agent: config.agentName,
15474
15638
  scope: config.scope,
@@ -15477,16 +15641,18 @@ var rememberRule = Effect88.fn("RelayPermissions.rememberRule")(function* (confi
15477
15641
  }).pipe(Effect88.mapError((error5) => permissionError(error5.message)));
15478
15642
  });
15479
15643
  var layer54 = (config) => Layer71.mergeAll(Layer71.succeed(exports_permissions.Permissions, exports_permissions.Permissions.of({
15480
- evaluate: (request) => evaluateDecision(config, request),
15481
- await: (pending) => awaitAnswer(config, pending)
15644
+ evaluate: (request) => Effect88.succeed(staticDecision(config.executionId, config.ruleset, request))
15482
15645
  })), Layer71.succeed(exports_permissions.RuleStore, exports_permissions.RuleStore.of({
15483
- remember: (rule) => rememberRule(config, rule)
15646
+ remember: (rule) => rememberRule(config, rule),
15647
+ rules: rememberedRules(config)
15648
+ })), Layer71.succeed(exports_approvals.Approvals, exports_approvals.Approvals.of({
15649
+ resolve: (pending) => resolve8(config, pending)
15484
15650
  })));
15485
15651
 
15486
15652
  // ../runtime/src/agent/relay-steering.ts
15487
- import { Clock as Clock16, Effect as Effect89, Layer as Layer72, Schema as Schema81 } from "effect";
15653
+ import { Clock as Clock16, Effect as Effect89, Layer as Layer72, Schema as Schema82 } from "effect";
15488
15654
  import { Prompt as Prompt5 } from "effect/unstable/ai";
15489
- var jsonValue4 = (value) => Schema81.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
15655
+ var jsonValue4 = (value) => Schema82.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
15490
15656
  var stringifyJson2 = (value) => JSON.stringify(jsonValue4(value));
15491
15657
  var createdAtForSequence2 = (config, sequence) => config.startedAt + sequence - config.eventSequence;
15492
15658
  var drainId = (config, kind, sequence) => `drain:${config.executionId}:steering:${kind}:sequence:${sequence}`;
@@ -15519,7 +15685,7 @@ var contentFromMessage = (message) => {
15519
15685
  const textParts = promptTextParts(prompt);
15520
15686
  if (textParts.length > 0)
15521
15687
  return textParts;
15522
- return [exports_content_schema.text(prompt.pipe(Schema81.encodeSync(Prompt5.Prompt), stringifyJson2))];
15688
+ return [exports_content_schema.text(prompt.pipe(Schema82.encodeSync(Prompt5.Prompt), stringifyJson2))];
15523
15689
  };
15524
15690
  var steeringDeliveredEvent = (config, kind, drain2, messages, sequence) => ({
15525
15691
  id: exports_ids_schema.EventId.make(`event:${drain2.drainId}:delivered`),
@@ -15564,8 +15730,8 @@ var layer55 = (config) => Layer72.succeed(exports_steering.Steering, exports_ste
15564
15730
  }));
15565
15731
 
15566
15732
  // ../runtime/src/agent/relay-tool-executor.ts
15567
- import { Deferred as Deferred3, Effect as Effect90, Layer as Layer73, Option as Option22, Schema as Schema82 } from "effect";
15568
- var jsonValue5 = (value) => Schema82.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
15733
+ import { Deferred as Deferred3, Effect as Effect90, Layer as Layer73, Option as Option22, Schema as Schema83 } from "effect";
15734
+ var jsonValue5 = (value) => Schema83.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
15569
15735
  var errorDetail = (error5) => {
15570
15736
  switch (error5._tag) {
15571
15737
  case "ToolNotRegistered":
@@ -15881,7 +16047,7 @@ var {
15881
16047
  usageReportedEvent: usageReportedEvent2
15882
16048
  } = AgentLoopEvents;
15883
16049
 
15884
- class AgentLoopWaitRequested extends Schema83.TaggedErrorClass()("AgentLoopWaitRequested", {
16050
+ class AgentLoopWaitRequested extends Schema84.TaggedErrorClass()("AgentLoopWaitRequested", {
15885
16051
  wait_id: exports_ids_schema.WaitId,
15886
16052
  tool_call: exports_tool_schema.Call,
15887
16053
  suspension: exports_agent_event.AgentSuspended,
@@ -15891,7 +16057,7 @@ class AgentLoopWaitRequested extends Schema83.TaggedErrorClass()("AgentLoopWaitR
15891
16057
 
15892
16058
  class Service61 extends Context64.Service()("@relayfx/runtime/agent/agent-loop-service/Service") {
15893
16059
  }
15894
- var jsonValue6 = (value) => Schema83.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
16060
+ var jsonValue6 = (value) => Schema84.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
15895
16061
  var toolNames = (agent) => HashSet7.fromIterable(agent.tool_names);
15896
16062
  var turnPolicyFromSnapshot = (snapshot2) => {
15897
16063
  switch (snapshot2.kind) {
@@ -15983,7 +16149,7 @@ var runStructuredTurn = Effect93.fn("AgentLoop.runStructuredTurn")(function* (la
15983
16149
  prompt: STRUCTURED_TURN_PROMPT,
15984
16150
  schema: registration.schema,
15985
16151
  objectName: "output"
15986
- })).pipe(Effect93.mapError((error5) => Schema83.is(AgentLoopError)(error5) ? error5 : loopError(error5, sequence)));
16152
+ })).pipe(Effect93.mapError((error5) => Schema84.is(AgentLoopError)(error5) ? error5 : loopError(error5, sequence)));
15987
16153
  return jsonValue6(response.value);
15988
16154
  });
15989
16155
  var loopError = (error5, nextEventSequence5) => AgentLoopError.make({
@@ -16017,8 +16183,8 @@ var appendCompactionCommittedEvent = Effect93.fn("AgentLoop.appendCompactionComm
16017
16183
  });
16018
16184
  var toolFromDefinition = (definition) => AiTool2.dynamic(definition.name, {
16019
16185
  description: definition.description,
16020
- parameters: Schema83.make(exports_tool_schema.parametersSchema(definition.input_schema).ast),
16021
- success: Schema83.Unknown,
16186
+ parameters: Schema84.make(exports_tool_schema.parametersSchema(definition.input_schema).ast),
16187
+ success: Schema84.Unknown,
16022
16188
  ...definition.needs_approval === undefined ? {} : { needsApproval: definition.needs_approval }
16023
16189
  });
16024
16190
  var toolkitFromRegistered = (registered) => Toolkit2.make(...registered.map((tool3) => toolFromDefinition(tool3.definition)));
@@ -16048,7 +16214,7 @@ var restoreHistory = Effect93.fn("AgentLoop.restoreHistory")(function* (chats, i
16048
16214
  }
16049
16215
  return history;
16050
16216
  });
16051
- var promptEquivalence = Schema83.toEquivalence(Prompt6.Prompt);
16217
+ var promptEquivalence = Schema84.toEquivalence(Prompt6.Prompt);
16052
16218
  var reconcileCompactionCheckpoint = Effect93.fn("AgentLoop.reconcileCompactionCheckpoint")(function* (sessions, chats, input, restoredHistory, onCheckpointCommitted, failOnMismatch = false) {
16053
16219
  if (input.sessionId === undefined)
16054
16220
  return restoredHistory;
@@ -16140,7 +16306,7 @@ var restoreContextEpoch = Effect93.fn("AgentLoop.restoreContextEpoch")(function*
16140
16306
  return { baseline: epoch.baseline, dynamicSourceIds: epoch.dynamicSourceIds };
16141
16307
  });
16142
16308
  var mapBatonRunError = (error5, current2) => {
16143
- if (Schema83.is(exports_agent_event.AgentSuspended)(error5)) {
16309
+ if (Schema84.is(exports_agent_event.AgentSuspended)(error5)) {
16144
16310
  return AgentLoopWaitRequested.make({
16145
16311
  wait_id: exports_ids_schema.WaitId.make(error5.token),
16146
16312
  tool_call: {
@@ -16153,29 +16319,29 @@ var mapBatonRunError = (error5, current2) => {
16153
16319
  });
16154
16320
  }
16155
16321
  let message;
16156
- if (Schema83.is(exports_agent_event.AgentError)(error5))
16322
+ if (Schema84.is(exports_agent_event.AgentError)(error5))
16157
16323
  message = error5.message;
16158
- else if (Schema83.is(exports_agent_event.ResumeMismatch)(error5))
16324
+ else if (Schema84.is(exports_agent_event.ResumeMismatch)(error5))
16159
16325
  message = `Resume mismatch: ${error5.reason}`;
16160
- else if (Schema83.is(exports_turn_policy.TurnPolicyError)(error5))
16326
+ else if (Schema84.is(exports_turn_policy.TurnPolicyError)(error5))
16161
16327
  message = error5.message;
16162
- else if (Schema83.is(exports_agent_event.TurnPolicyStopped)(error5))
16328
+ else if (Schema84.is(exports_agent_event.TurnPolicyStopped)(error5))
16163
16329
  message = `Turn policy stopped at turn ${error5.turn}`;
16164
- else if (Schema83.is(exports_agent_event.TurnLimitExceeded)(error5))
16330
+ else if (Schema84.is(exports_agent_event.TurnLimitExceeded)(error5))
16165
16331
  message = "Tool call turn limit exceeded";
16166
- else if (Schema83.is(exports_agent_event.MiddlewareViolation)(error5))
16332
+ else if (Schema84.is(exports_agent_event.MiddlewareViolation)(error5))
16167
16333
  message = `ModelMiddleware violation at turn ${error5.turn}: ${error5.detail}`;
16168
- else if (Schema83.is(exports_agent_event.DuplicateToolCallId)(error5))
16334
+ else if (Schema84.is(exports_agent_event.DuplicateToolCallId)(error5))
16169
16335
  message = `Duplicate tool call id: ${error5.id}`;
16170
- else if (Schema83.is(exports_agent_event.ProgressOverflowError)(error5))
16336
+ else if (Schema84.is(exports_agent_event.ProgressOverflow)(error5))
16171
16337
  message = `Tool progress overflow: ${error5.toolCallId}`;
16172
- else if (Schema83.is(exports_agent_event.ToolNameCollision)(error5))
16338
+ else if (Schema84.is(exports_agent_event.ToolNameCollision)(error5))
16173
16339
  message = `Tool name collision: ${error5.name}`;
16174
- else if (Schema83.is(AiError3.AiError)(error5))
16340
+ else if (Schema84.is(AiError3.AiError)(error5))
16175
16341
  message = error5.message;
16176
- else if (Schema83.is(exports_model_registry.LanguageModelNotRegistered)(error5))
16342
+ else if (Schema84.is(exports_model_registry.LanguageModelNotRegistered)(error5))
16177
16343
  message = `Language model not registered: ${error5.provider}/${error5.model}`;
16178
- else if (Schema83.is(exports_tool_executor.FrameworkFailure)(error5))
16344
+ else if (Schema84.is(exports_tool_executor.FrameworkFailure)(error5))
16179
16345
  message = error5.message;
16180
16346
  else {
16181
16347
  const exhaustive = error5;
@@ -16183,14 +16349,14 @@ var mapBatonRunError = (error5, current2) => {
16183
16349
  }
16184
16350
  return AgentLoopError.make({ message, baton_failure: error5, next_event_sequence: current2 });
16185
16351
  };
16186
- var isBatonRunError = (error5) => Schema83.is(exports_agent_event.AgentSuspended)(error5) || Schema83.is(exports_agent_event.ResumeMismatch)(error5) || Schema83.is(exports_turn_policy.TurnPolicyError)(error5) || Schema83.is(exports_agent_event.TurnPolicyStopped)(error5) || Schema83.is(exports_agent_event.TurnLimitExceeded)(error5) || Schema83.is(exports_agent_event.MiddlewareViolation)(error5) || Schema83.is(exports_agent_event.DuplicateToolCallId)(error5) || Schema83.is(exports_agent_event.ProgressOverflowError)(error5) || Schema83.is(exports_agent_event.ToolNameCollision)(error5) || Schema83.is(exports_agent_event.AgentError)(error5) || Schema83.is(AiError3.AiError)(error5) || Schema83.is(exports_model_registry.LanguageModelNotRegistered)(error5) || Schema83.is(exports_tool_executor.FrameworkFailure)(error5);
16352
+ var isBatonRunError = (error5) => Schema84.is(exports_agent_event.AgentSuspended)(error5) || Schema84.is(exports_agent_event.ResumeMismatch)(error5) || Schema84.is(exports_turn_policy.TurnPolicyError)(error5) || Schema84.is(exports_agent_event.TurnPolicyStopped)(error5) || Schema84.is(exports_agent_event.TurnLimitExceeded)(error5) || Schema84.is(exports_agent_event.MiddlewareViolation)(error5) || Schema84.is(exports_agent_event.DuplicateToolCallId)(error5) || Schema84.is(exports_agent_event.ProgressOverflow)(error5) || Schema84.is(exports_agent_event.ToolNameCollision)(error5) || Schema84.is(exports_agent_event.AgentError)(error5) || Schema84.is(AiError3.AiError)(error5) || Schema84.is(exports_model_registry.LanguageModelNotRegistered)(error5) || Schema84.is(exports_tool_executor.FrameworkFailure)(error5);
16187
16353
  var mapBoundaryError = (errorOrCurrent, current2, failureClassification) => {
16188
16354
  if (current2 === undefined) {
16189
16355
  const sequence = errorOrCurrent;
16190
16356
  return (error6) => mapBoundaryError(error6, sequence);
16191
16357
  }
16192
16358
  const error5 = errorOrCurrent;
16193
- if (Schema83.is(AgentLoopError)(error5) || Schema83.is(AgentLoopWaitRequested)(error5) || Schema83.is(AgentLoopBudgetExceeded)(error5))
16359
+ if (Schema84.is(AgentLoopError)(error5) || Schema84.is(AgentLoopWaitRequested)(error5) || Schema84.is(AgentLoopBudgetExceeded)(error5))
16194
16360
  return error5;
16195
16361
  const mapped = isBatonRunError(error5) ? mapBatonRunError(error5, current2) : loopError(error5, current2);
16196
16362
  return mapped._tag === "AgentLoopError" && failureClassification === "context-overflow" ? AgentLoopError.make({
@@ -16336,6 +16502,7 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
16336
16502
  startedAt: input.startedAt,
16337
16503
  eventSequence: input.eventSequence
16338
16504
  });
16505
+ const approvalsLayer = input.agent.permission_rules === undefined ? layer53 : Layer75.empty;
16339
16506
  const steeringLayer = input.steeringEnabled !== true ? Layer75.empty : Option24.isNone(steeringRepository) ? yield* AgentLoopError.make({
16340
16507
  message: "Execution steering requires SteeringRepository in context",
16341
16508
  next_event_sequence: input.eventSequence + 1
@@ -16351,6 +16518,8 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
16351
16518
  const memory = input.memorySubjectId === undefined ? undefined : { key: { agent: input.agent.name, subject: input.memorySubjectId } };
16352
16519
  const restoredEpoch = durableHistory !== undefined && Option24.isSome(contextEpochs) ? yield* restoreContextEpoch(contextEpochs.value, input) : undefined;
16353
16520
  const freshSessionHistory = durableHistory !== undefined || input.sessionId === undefined || Option24.isNone(sessionRepository) ? undefined : yield* sessionRepository.value.path({ sessionId: input.sessionId }).pipe(Effect93.mapError((error5) => loopError(error5, input.eventSequence + 1)), Effect93.map((path2) => path2.length === 0 ? undefined : exports_session.buildContext(path2)));
16521
+ const sessionWriter = input.sessionId === undefined || Option24.isNone(sessionRepository) ? undefined : yield* sessionRepository.value.get(input.sessionId).pipe(Effect93.mapError((error5) => loopError(error5, input.eventSequence + 1)), Effect93.map((record2) => record2?.writer === undefined ? undefined : { executionId: input.executionId, epoch: record2.writer.epoch }));
16522
+ const sessionOwnerToken = sessionWriter === undefined ? undefined : `${sessionWriter.executionId}#${sessionWriter.epoch}`;
16354
16523
  const { options, instructionsLayer } = durableHistory === undefined ? yield* assembler.assemble({ agent: input.agent, tools: definitions2, input: input.input }).pipe(Effect93.mapError((error5) => loopError(error5, input.eventSequence + 1)), Effect93.flatMap((assembled) => Effect93.gen(function* () {
16355
16524
  const epoch = { baseline: assembled.system, dynamicSourceIds: [] };
16356
16525
  if (Option24.isSome(contextEpochs))
@@ -16360,6 +16529,7 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
16360
16529
  prompt: assembled.prompt,
16361
16530
  ...freshSessionHistory === undefined ? {} : { history: freshSessionHistory },
16362
16531
  sessionId: input.sessionId ?? input.executionId,
16532
+ ...sessionOwnerToken === undefined ? {} : { sessionOwnerToken },
16363
16533
  ...memory === undefined ? {} : { memory }
16364
16534
  },
16365
16535
  instructionsLayer: freshSessionHistory === undefined ? layerFromEpoch(epoch) : Layer75.empty
@@ -16370,7 +16540,8 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
16370
16540
  prompt: [],
16371
16541
  ...memory === undefined ? {} : { memory },
16372
16542
  ...resumeSuspension === undefined ? {} : { resume: { suspension: resumeSuspension } },
16373
- sessionId: input.sessionId ?? input.executionId
16543
+ sessionId: input.sessionId ?? input.executionId,
16544
+ ...sessionOwnerToken === undefined ? {} : { sessionOwnerToken }
16374
16545
  },
16375
16546
  instructionsLayer: restoredEpoch === undefined ? Layer75.empty : layerFromEpoch(restoredEpoch)
16376
16547
  };
@@ -16516,9 +16687,10 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
16516
16687
  const runFold = Effect93.scoped(Effect93.gen(function* () {
16517
16688
  const base = withToolCallDecodeResilience(yield* LanguageModel.LanguageModel, definitions2.map((definition) => definition.name), toolCallDecodeMaxRetries, (classification) => Ref19.set(lastModelFailureClassification, classification));
16518
16689
  const sessionStore = input.sessionId !== undefined && Option24.isSome(sessionRepository) ? yield* make5(input.sessionId, input.sessionEntryScope ?? input.executionId, {
16519
- onCheckpointCommitted: (result) => onCheckpointCommitted(result).pipe(Effect93.orDie)
16690
+ onCheckpointCommitted: (result) => onCheckpointCommitted(result).pipe(Effect93.orDie),
16691
+ ...sessionWriter === undefined ? {} : { writer: sessionWriter }
16520
16692
  }).pipe(Effect93.provideService(exports_session_repository.Service, sessionRepository.value)) : undefined;
16521
- const foldContext = yield* Layer75.build(Layer75.mergeAll(executorLayer, handlerLayer, layer53, exports_model_middleware.identityLayer, instructionsLayer, permissionsLayer, steeringLayer));
16693
+ const foldContext = yield* Layer75.build(Layer75.mergeAll(executorLayer, handlerLayer, approvalsLayer, exports_model_middleware.layerIdentity, instructionsLayer, permissionsLayer, steeringLayer));
16522
16694
  const folded = exports_agent.stream(agent, batonOptions).pipe(Stream13.runFoldEffect(() => ({
16523
16695
  text: "",
16524
16696
  transcript: undefined,
@@ -16570,7 +16742,7 @@ var run5 = Effect93.fn("AgentLoop.run.call")(function* (input) {
16570
16742
  // ../runtime/src/cluster/execution-entity.ts
16571
16743
  import { ClusterSchema, Entity } from "effect/unstable/cluster";
16572
16744
  import { Rpc } from "effect/unstable/rpc";
16573
- import { Schema as Schema84 } from "effect";
16745
+ import { Schema as Schema85 } from "effect";
16574
16746
  var Start = Rpc.make("start", {
16575
16747
  payload: StartInput,
16576
16748
  success: StartResult,
@@ -16578,12 +16750,12 @@ var Start = Rpc.make("start", {
16578
16750
  }).annotate(ClusterSchema.Persisted, true).annotate(ClusterSchema.Uninterruptible, "server");
16579
16751
  var SignalWait = Rpc.make("signalWait", {
16580
16752
  payload: SignalWaitInput,
16581
- success: Schema84.Void,
16753
+ success: Schema85.Void,
16582
16754
  error: ExecutionWorkflowFailed
16583
16755
  }).annotate(ClusterSchema.Persisted, true).annotate(ClusterSchema.Uninterruptible, "server");
16584
16756
  var Dispatch = Rpc.make("dispatch", {
16585
16757
  payload: StartInput,
16586
- success: Schema84.Void,
16758
+ success: Schema85.Void,
16587
16759
  error: ExecutionWorkflowError
16588
16760
  }).annotate(ClusterSchema.Persisted, true).annotate(ClusterSchema.Uninterruptible, "server");
16589
16761
  var Cancel = Rpc.make("cancel", {
@@ -16606,10 +16778,10 @@ var layer59 = entity.toLayer(entity.of({
16606
16778
  var client = entity.client;
16607
16779
 
16608
16780
  // ../runtime/src/execution/execution-watch-service.ts
16609
- import { Config as Config5, Context as Context65, Duration as Duration4, Effect as Effect94, Layer as Layer76, Ref as Ref20, Schema as Schema85, Stream as Stream14 } from "effect";
16781
+ import { Config as Config5, Context as Context65, Duration as Duration4, Effect as Effect94, Layer as Layer76, Ref as Ref20, Schema as Schema86, Stream as Stream14 } from "effect";
16610
16782
 
16611
- class ExecutionWatchError extends Schema85.TaggedErrorClass()("ExecutionWatchError", {
16612
- message: Schema85.String
16783
+ class ExecutionWatchError extends Schema86.TaggedErrorClass()("ExecutionWatchError", {
16784
+ message: Schema86.String
16613
16785
  }) {
16614
16786
  }
16615
16787
 
@@ -16657,20 +16829,20 @@ var layerFromServices = Layer76.effect(Service65, Effect94.gen(function* () {
16657
16829
  }));
16658
16830
 
16659
16831
  // ../runtime/src/resident/resident-registry-service.ts
16660
- import { Context as Context66, Effect as Effect95, Layer as Layer77, Schema as Schema86 } from "effect";
16661
- class ResidentKindNotFound extends Schema86.TaggedErrorClass()("ResidentKindNotFound", {
16832
+ import { Context as Context66, Effect as Effect95, Layer as Layer77, Schema as Schema87 } from "effect";
16833
+ class ResidentKindNotFound extends Schema87.TaggedErrorClass()("ResidentKindNotFound", {
16662
16834
  kind: exports_ids_schema.ResidentKindName
16663
16835
  }) {
16664
16836
  }
16665
16837
 
16666
- class ResidentKindInvalid extends Schema86.TaggedErrorClass()("ResidentKindInvalid", {
16838
+ class ResidentKindInvalid extends Schema87.TaggedErrorClass()("ResidentKindInvalid", {
16667
16839
  kind: exports_ids_schema.ResidentKindName,
16668
- message: Schema86.String
16840
+ message: Schema87.String
16669
16841
  }) {
16670
16842
  }
16671
16843
 
16672
- class ResidentRegistryError extends Schema86.TaggedErrorClass()("ResidentRegistryError", {
16673
- message: Schema86.String
16844
+ class ResidentRegistryError extends Schema87.TaggedErrorClass()("ResidentRegistryError", {
16845
+ message: Schema87.String
16674
16846
  }) {
16675
16847
  }
16676
16848
 
@@ -16702,21 +16874,21 @@ var layer60 = Layer77.effect(Service66, Effect95.gen(function* () {
16702
16874
  }));
16703
16875
 
16704
16876
  // ../runtime/src/resident/resident-instance-service.ts
16705
- import { Context as Context67, Effect as Effect96, Function as Function16, Layer as Layer78, Schema as Schema87 } from "effect";
16706
- class ResidentDestroyed extends Schema87.TaggedErrorClass()("ResidentDestroyed", {
16877
+ import { Context as Context67, Effect as Effect96, Function as Function16, Layer as Layer78, Schema as Schema88 } from "effect";
16878
+ class ResidentDestroyed extends Schema88.TaggedErrorClass()("ResidentDestroyed", {
16707
16879
  kind: exports_ids_schema.ResidentKindName,
16708
16880
  key: exports_ids_schema.ResidentKey
16709
16881
  }) {
16710
16882
  }
16711
16883
 
16712
- class ResidentNotFound2 extends Schema87.TaggedErrorClass()("ResidentNotFound", {
16884
+ class ResidentNotFound2 extends Schema88.TaggedErrorClass()("ResidentNotFound", {
16713
16885
  kind: exports_ids_schema.ResidentKindName,
16714
16886
  key: exports_ids_schema.ResidentKey
16715
16887
  }) {
16716
16888
  }
16717
16889
 
16718
- class ResidentServiceError extends Schema87.TaggedErrorClass()("ResidentServiceError", {
16719
- message: Schema87.String
16890
+ class ResidentServiceError extends Schema88.TaggedErrorClass()("ResidentServiceError", {
16891
+ message: Schema88.String
16720
16892
  }) {
16721
16893
  }
16722
16894
 
@@ -16819,9 +16991,9 @@ var layer61 = Layer78.effect(Service67, Effect96.gen(function* () {
16819
16991
  }));
16820
16992
 
16821
16993
  // ../runtime/src/execution/session-stream-service.ts
16822
- import { Config as Config6, Context as Context68, Duration as Duration5, Effect as Effect97, HashSet as HashSet8, Layer as Layer79, Ref as Ref21, Schema as Schema88, Stream as Stream15 } from "effect";
16823
- class SessionStreamError extends Schema88.TaggedErrorClass()("SessionStreamError", {
16824
- message: Schema88.String
16994
+ import { Config as Config6, Context as Context68, Duration as Duration5, Effect as Effect97, HashSet as HashSet8, Layer as Layer79, Ref as Ref21, Schema as Schema89, Stream as Stream15 } from "effect";
16995
+ class SessionStreamError extends Schema89.TaggedErrorClass()("SessionStreamError", {
16996
+ message: Schema89.String
16825
16997
  }) {
16826
16998
  }
16827
16999
 
@@ -16854,15 +17026,15 @@ var layerFromServices2 = Layer79.effect(Service68, Effect97.gen(function* () {
16854
17026
  }));
16855
17027
 
16856
17028
  // ../runtime/src/schedule/scheduler-service.ts
16857
- import { Clock as Clock17, Config as Config7, Context as Context69, Cron, DateTime as DateTime2, Duration as Duration6, Effect as Effect98, Layer as Layer80, Option as Option25, Random as Random3, Result as Result3, Schema as Schema89 } from "effect";
16858
- class SchedulerError extends Schema89.TaggedErrorClass()("SchedulerError", {
16859
- message: Schema89.String
17029
+ import { Clock as Clock17, Config as Config7, Context as Context69, Cron, DateTime as DateTime2, Duration as Duration6, Effect as Effect98, Layer as Layer80, Option as Option25, Random as Random3, Result as Result3, Schema as Schema90 } from "effect";
17030
+ class SchedulerError extends Schema90.TaggedErrorClass()("SchedulerError", {
17031
+ message: Schema90.String
16860
17032
  }) {
16861
17033
  }
16862
17034
 
16863
- class ScheduleCronInvalid extends Schema89.TaggedErrorClass()("ScheduleCronInvalid", {
16864
- cron_expr: Schema89.String,
16865
- message: Schema89.String
17035
+ class ScheduleCronInvalid extends Schema90.TaggedErrorClass()("ScheduleCronInvalid", {
17036
+ cron_expr: Schema90.String,
17037
+ message: Schema90.String
16866
17038
  }) {
16867
17039
  }
16868
17040
 
@@ -17017,25 +17189,25 @@ var runOnce2 = Effect98.fn("SchedulerService.runOnce.call")(function* () {
17017
17189
  });
17018
17190
 
17019
17191
  // ../runtime/src/runner/runner-runtime-service.ts
17020
- var DatabaseMode = Schema90.Literals(["sql", "pg", "mysql", "sqlite", "memory"]).annotate({
17192
+ var DatabaseMode = Schema91.Literals(["sql", "pg", "mysql", "sqlite", "memory"]).annotate({
17021
17193
  identifier: "Relay.RunnerRuntime.DatabaseMode"
17022
17194
  });
17023
- var ReadinessStatus = Schema90.Struct({
17195
+ var ReadinessStatus = Schema91.Struct({
17024
17196
  database: DatabaseMode,
17025
- cluster: Schema90.Literal("ready"),
17026
- workflow: Schema90.Literals(["ready", "client"]),
17027
- executionEntity: Schema90.Literals(["registered", "client"])
17197
+ cluster: Schema91.Literal("ready"),
17198
+ workflow: Schema91.Literals(["ready", "client"]),
17199
+ executionEntity: Schema91.Literals(["registered", "client"])
17028
17200
  }).annotate({ identifier: "Relay.RunnerRuntime.ReadinessStatus" });
17029
17201
 
17030
- class RunnerRuntimeError extends Schema90.TaggedErrorClass()("RunnerRuntimeError", {
17031
- message: Schema90.String
17202
+ class RunnerRuntimeError extends Schema91.TaggedErrorClass()("RunnerRuntimeError", {
17203
+ message: Schema91.String
17032
17204
  }) {
17033
17205
  }
17034
17206
 
17035
- class ClusterConfigMismatch extends Schema90.TaggedErrorClass()("ClusterConfigMismatch", {
17036
- field: Schema90.String,
17037
- expected: Schema90.String,
17038
- actual: Schema90.String
17207
+ class ClusterConfigMismatch extends Schema91.TaggedErrorClass()("ClusterConfigMismatch", {
17208
+ field: Schema91.String,
17209
+ expected: Schema91.String,
17210
+ actual: Schema91.String
17039
17211
  }) {
17040
17212
  }
17041
17213
 
@@ -17049,7 +17221,7 @@ var memoryClusterLayer = Sharding.layer.pipe(Layer81.provideMerge(Runners.layerN
17049
17221
  var clusterHost = Config8.string("RELAY_CLUSTER_HOST").pipe(Config8.withDefault("localhost"));
17050
17222
  var clusterPort = Config8.int("RELAY_CLUSTER_PORT").pipe(Config8.withDefault(34431));
17051
17223
  var clusterShardsPerGroup = Config8.int("RELAY_CLUSTER_SHARDS_PER_GROUP").pipe(Config8.withDefault(300));
17052
- var clusterShardGroups = Config8.schema(Config8.Array(Schema90.String), "RELAY_CLUSTER_SHARD_GROUPS").pipe(Config8.withDefault(["default", "execution"]));
17224
+ var clusterShardGroups = Config8.schema(Config8.Array(Schema91.String), "RELAY_CLUSTER_SHARD_GROUPS").pipe(Config8.withDefault(["default", "execution"]));
17053
17225
  var runnerAddressKey = (address) => `${address.host}:${address.port}`;
17054
17226
  var runnerAddressEquals = (left, right) => left.host === right.host && left.port === right.port;
17055
17227
  var shardingConfigFromEnv = Layer81.effect(ShardingConfig2.ShardingConfig, Effect99.gen(function* () {
@@ -17380,24 +17552,24 @@ var check = Effect99.fn("RunnerRuntime.check.call")(function* () {
17380
17552
  });
17381
17553
 
17382
17554
  // ../runtime/src/workflow/definition-runtime.ts
17383
- import { Cause as Cause3, Clock as Clock18, Context as Context71, Effect as Effect100, Exit as Exit2, FiberMap as FiberMap2, Layer as Layer82, Option as Option27, Schema as Schema91 } from "effect";
17555
+ import { Cause as Cause3, Clock as Clock18, Context as Context71, Effect as Effect100, Exit as Exit2, FiberMap as FiberMap2, Layer as Layer82, Option as Option27, Schema as Schema92 } from "effect";
17384
17556
  import { dual as dual2 } from "effect/Function";
17385
17557
 
17386
- class UnsupportedOperation extends Schema91.TaggedErrorClass()("UnsupportedWorkflowOperation", { operation_id: exports_ids_schema.WorkflowOperationId, kind: Schema91.String }) {
17558
+ class UnsupportedOperation extends Schema92.TaggedErrorClass()("UnsupportedWorkflowOperation", { operation_id: exports_ids_schema.WorkflowOperationId, kind: Schema92.String }) {
17387
17559
  }
17388
17560
 
17389
- class PinnedDefinitionNotFound extends Schema91.TaggedErrorClass()("PinnedWorkflowDefinitionNotFound", { execution_id: exports_ids_schema.ExecutionId }) {
17561
+ class PinnedDefinitionNotFound extends Schema92.TaggedErrorClass()("PinnedWorkflowDefinitionNotFound", { execution_id: exports_ids_schema.ExecutionId }) {
17390
17562
  }
17391
17563
 
17392
- class PinnedDefinitionMismatch extends Schema91.TaggedErrorClass()("PinnedWorkflowDefinitionMismatch", { execution_id: exports_ids_schema.ExecutionId }) {
17564
+ class PinnedDefinitionMismatch extends Schema92.TaggedErrorClass()("PinnedWorkflowDefinitionMismatch", { execution_id: exports_ids_schema.ExecutionId }) {
17393
17565
  }
17394
17566
 
17395
- class WorkflowRuntimeError extends Schema91.TaggedErrorClass()("WorkflowRuntimeError", {
17396
- message: Schema91.String
17567
+ class WorkflowRuntimeError extends Schema92.TaggedErrorClass()("WorkflowRuntimeError", {
17568
+ message: Schema92.String
17397
17569
  }) {
17398
17570
  }
17399
17571
 
17400
- class WorkflowJoinPolicyNotSatisfied extends Schema91.TaggedErrorClass()("WorkflowJoinPolicyNotSatisfied", { policy: Schema91.String }) {
17572
+ class WorkflowJoinPolicyNotSatisfied extends Schema92.TaggedErrorClass()("WorkflowJoinPolicyNotSatisfied", { policy: Schema92.String }) {
17401
17573
  }
17402
17574
  var runtimeError2 = (error5) => WorkflowRuntimeError.make({ message: String(error5) });
17403
17575
  var mapRuntimeError2 = Effect100.mapError(runtimeError2);
@@ -17410,13 +17582,13 @@ class Service71 extends Context71.Service()("@relayfx/runtime/workflow/definitio
17410
17582
  var fanOutIdFor = dual2(2, (executionId, fanOutKey) => exports_ids_schema.ChildFanOutId.make(`workflow:${executionId}:fan-out:${fanOutKey}`));
17411
17583
  var childExecutionIdFor = (fanOutId, operationId2) => exports_ids_schema.ChildExecutionId.make(`${fanOutId}:member:${operationId2}`);
17412
17584
 
17413
- class WorkflowCancelled extends Schema91.TaggedErrorClass()("WorkflowCancelled", {}) {
17585
+ class WorkflowCancelled extends Schema92.TaggedErrorClass()("WorkflowCancelled", {}) {
17414
17586
  }
17415
17587
 
17416
- class WorkflowBudgetExceeded extends Schema91.TaggedErrorClass()("WorkflowBudgetExceeded", { operation_id: exports_ids_schema.WorkflowOperationId }) {
17588
+ class WorkflowBudgetExceeded extends Schema92.TaggedErrorClass()("WorkflowBudgetExceeded", { operation_id: exports_ids_schema.WorkflowOperationId }) {
17417
17589
  }
17418
17590
 
17419
- class WorkflowJoining extends Schema91.TaggedErrorClass()("WorkflowJoining", {
17591
+ class WorkflowJoining extends Schema92.TaggedErrorClass()("WorkflowJoining", {
17420
17592
  fan_out_id: exports_ids_schema.ChildFanOutId
17421
17593
  }) {
17422
17594
  }
@@ -17671,7 +17843,7 @@ var run6 = Effect100.fn("WorkflowDefinitionRuntime.run")(function* (executionId)
17671
17843
  break;
17672
17844
  }
17673
17845
  case "cancellation":
17674
- output2 = yield* execute(operation.operation).pipe(Effect100.catchIf(Schema91.is(WorkflowCancelled), () => operation.on_cancel === undefined ? Effect100.fail(WorkflowCancelled.make()) : execute(operation.on_cancel)));
17846
+ output2 = yield* execute(operation.operation).pipe(Effect100.catchIf(Schema92.is(WorkflowCancelled), () => operation.on_cancel === undefined ? Effect100.fail(WorkflowCancelled.make()) : execute(operation.on_cancel)));
17675
17847
  break;
17676
17848
  case "compensation":
17677
17849
  output2 = yield* execute(operation.operation);
@@ -17718,7 +17890,7 @@ var run6 = Effect100.fn("WorkflowDefinitionRuntime.run")(function* (executionId)
17718
17890
  const result = yield* Effect100.exit(execute(revision.definition.entry_operation_id));
17719
17891
  if (Exit2.isFailure(result)) {
17720
17892
  const failure2 = Cause3.findErrorOption(result.cause);
17721
- if (Option27.isSome(failure2) && Schema91.is(WorkflowJoining)(failure2.value))
17893
+ if (Option27.isSome(failure2) && Schema92.is(WorkflowJoining)(failure2.value))
17722
17894
  return yield* result;
17723
17895
  const currentRun = yield* repository.inspect(executionId);
17724
17896
  if (currentRun?.status === "cancelled") {
@@ -17789,12 +17961,12 @@ var layerFromRuntime2 = Layer82.effect(Service71, Effect100.gen(function* () {
17789
17961
  }));
17790
17962
 
17791
17963
  // src/runtime.ts
17792
- import { Cause as Cause5, Context as Context74, Effect as Effect112, Layer as Layer86, Option as Option31, Schema as Schema99 } from "effect";
17964
+ import { Cause as Cause5, Context as Context74, Effect as Effect112, Layer as Layer86, Option as Option31, Schema as Schema100 } from "effect";
17793
17965
  import { SqlClient as SqlClient31 } from "effect/unstable/sql/SqlClient";
17794
17966
 
17795
17967
  // src/runtime-acquisition-error.ts
17796
- import { Cause as Cause4, Function as Function17, Schema as Schema92 } from "effect";
17797
- var RuntimeConfigurationCategory = Schema92.Literals([
17968
+ import { Cause as Cause4, Function as Function17, Schema as Schema93 } from "effect";
17969
+ var RuntimeConfigurationCategory = Schema93.Literals([
17798
17970
  "missing-http-client",
17799
17971
  "provider-config",
17800
17972
  "model-registration",
@@ -17802,31 +17974,31 @@ var RuntimeConfigurationCategory = Schema92.Literals([
17802
17974
  "database-config",
17803
17975
  "unknown-host-layer"
17804
17976
  ]);
17805
- var RuntimeConfigurationScope = Schema92.Literals(["host-layer", "database-client"]);
17977
+ var RuntimeConfigurationScope = Schema93.Literals(["host-layer", "database-client"]);
17806
17978
 
17807
- class RuntimeHostLayerFailure extends Schema92.TaggedErrorClass()("RuntimeHostLayerFailure", { category: RuntimeConfigurationCategory }) {
17979
+ class RuntimeHostLayerFailure extends Schema93.TaggedErrorClass()("RuntimeHostLayerFailure", { category: RuntimeConfigurationCategory }) {
17808
17980
  }
17809
- var SafeCauseReason = Schema92.TaggedUnion({
17981
+ var SafeCauseReason = Schema93.TaggedUnion({
17810
17982
  Fail: {
17811
17983
  category: RuntimeConfigurationCategory,
17812
- errorTag: Schema92.Literals(["RuntimeHostLayerFailure", "UnknownTypedFailure"])
17984
+ errorTag: Schema93.Literals(["RuntimeHostLayerFailure", "UnknownTypedFailure"])
17813
17985
  },
17814
- Die: { defectTag: Schema92.Literal("UnknownDefect") },
17986
+ Die: { defectTag: Schema93.Literal("UnknownDefect") },
17815
17987
  Interrupt: {}
17816
17988
  });
17817
- var SafeCause = Schema92.Struct({
17818
- reasons: Schema92.Array(SafeCauseReason).check(Schema92.isMaxLength(16)),
17819
- truncated: Schema92.Boolean
17989
+ var SafeCause = Schema93.Struct({
17990
+ reasons: Schema93.Array(SafeCauseReason).check(Schema93.isMaxLength(16)),
17991
+ truncated: Schema93.Boolean
17820
17992
  });
17821
17993
 
17822
- class RuntimeConfigurationError extends Schema92.TaggedErrorClass()("RuntimeConfigurationError", {
17994
+ class RuntimeConfigurationError extends Schema93.TaggedErrorClass()("RuntimeConfigurationError", {
17823
17995
  category: RuntimeConfigurationCategory,
17824
17996
  scope: RuntimeConfigurationScope,
17825
17997
  cause: SafeCause
17826
17998
  }) {
17827
17999
  }
17828
18000
  var typedFailure = (error5) => {
17829
- if (Schema92.is(RuntimeHostLayerFailure)(error5)) {
18001
+ if (Schema93.is(RuntimeHostLayerFailure)(error5)) {
17830
18002
  return { _tag: "Fail", category: error5.category, errorTag: "RuntimeHostLayerFailure" };
17831
18003
  }
17832
18004
  return { _tag: "Fail", category: "unknown-host-layer", errorTag: "UnknownTypedFailure" };
@@ -17845,11 +18017,11 @@ var safeCause = (cause) => {
17845
18017
  var normalizeAcquisitionCauseImpl = (cause, scope, preserve) => {
17846
18018
  const summary = safeCause(cause);
17847
18019
  return Cause4.map(cause, (error5) => {
17848
- if (Schema92.is(RuntimeConfigurationError)(error5) || preserve !== undefined && preserve(error5))
18020
+ if (Schema93.is(RuntimeConfigurationError)(error5) || preserve !== undefined && preserve(error5))
17849
18021
  return error5;
17850
18022
  const reason = typedFailure(error5);
17851
18023
  return RuntimeConfigurationError.make({
17852
- category: Schema92.is(RuntimeHostLayerFailure)(error5) ? reason.category : scope === "database-client" ? "database-config" : "unknown-host-layer",
18024
+ category: Schema93.is(RuntimeHostLayerFailure)(error5) ? reason.category : scope === "database-client" ? "database-config" : "unknown-host-layer",
17853
18025
  scope,
17854
18026
  cause: summary
17855
18027
  });
@@ -17871,16 +18043,16 @@ var renderConfigurationError = (error5) => {
17871
18043
  return `Runtime configuration error [${error5.category}/${error5.scope}]: ${remediation}; causes=${reasons}${error5.cause.truncated ? ",truncated" : ""}`;
17872
18044
  };
17873
18045
  // src/internal-client.ts
17874
- import { Clock as Clock19, Effect as Effect109, Layer as Layer84, Option as Option30, Random as Random4, Schema as Schema98, Stream as Stream17 } from "effect";
18046
+ import { Clock as Clock19, Effect as Effect109, Layer as Layer84, Option as Option30, Random as Random4, Schema as Schema99, Stream as Stream17 } from "effect";
17875
18047
  import { EntityId, ShardId, Sharding as Sharding2, ShardingConfig as ShardingConfig3 } from "effect/unstable/cluster";
17876
18048
 
17877
18049
  // src/runtime-capability-policy.ts
17878
- import { Context as Context72, Effect as Effect101, Function as Function18, Layer as Layer83, Schema as Schema93 } from "effect";
18050
+ import { Context as Context72, Effect as Effect101, Function as Function18, Layer as Layer83, Schema as Schema94 } from "effect";
17879
18051
 
17880
- class RuntimeCapabilityUnavailable extends Schema93.TaggedErrorClass()("RuntimeCapabilityUnavailable", {
17881
- capability: Schema93.Literals(["fan-out", "workflow-definition"]),
17882
- role: Schema93.Literals(["embedded", "runner", "client"]),
17883
- nextAction: Schema93.Literals(["enable-embedded-capability", "use-embedded-runtime"])
18052
+ class RuntimeCapabilityUnavailable extends Schema94.TaggedErrorClass()("RuntimeCapabilityUnavailable", {
18053
+ capability: Schema94.Literals(["fan-out", "workflow-definition"]),
18054
+ role: Schema94.Literals(["embedded", "runner", "client"]),
18055
+ nextAction: Schema94.Literals(["enable-embedded-capability", "use-embedded-runtime"])
17884
18056
  }) {
17885
18057
  }
17886
18058
 
@@ -17898,7 +18070,7 @@ var layer64 = Function18.dual(2, (role, capabilities) => Layer83.succeed(Service
17898
18070
  }));
17899
18071
 
17900
18072
  // src/client-baton-agent.ts
17901
- import { Effect as Effect102, Schema as Schema94 } from "effect";
18073
+ import { Effect as Effect102, Schema as Schema95 } from "effect";
17902
18074
  var isRegisterBatonAgentInput = (input) => ("agent" in input);
17903
18075
  var toolRefsFromBatonAgent = (agent) => Object.values(agent.toolkit.tools).map((tool3) => ({ name: tool3.name }));
17904
18076
  var modelSelectionFromBatonAgent = (selection) => ({
@@ -17906,9 +18078,9 @@ var modelSelectionFromBatonAgent = (selection) => ({
17906
18078
  model: selection.model,
17907
18079
  ...selection.registrationKey === undefined ? {} : { registration_key: selection.registrationKey }
17908
18080
  });
17909
- var decodeBatonAgentName = (name) => Schema94.decodeUnknownEffect(exports_shared_schema.NonEmptyString)(name).pipe(Effect102.mapError(() => ClientError.make({ message: "Baton agent name must not be blank" })));
17910
- var decodeBatonAgentMetadata = (metadata11) => metadata11 === undefined ? Effect102.void : Schema94.decodeUnknownEffect(exports_shared_schema.Metadata)(metadata11).pipe(Effect102.mapError(() => ClientError.make({ message: "Baton agent metadata must be JSON metadata" })));
17911
- var decodeBatonMemorySubject = (subject) => Schema94.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect102.mapError(() => ClientError.make({ message: "Baton agent memory subject must be a MemorySubjectId" })));
18081
+ var decodeBatonAgentName = (name) => Schema95.decodeUnknownEffect(exports_shared_schema.NonEmptyString)(name).pipe(Effect102.mapError(() => ClientError.make({ message: "Baton agent name must not be blank" })));
18082
+ var decodeBatonAgentMetadata = (metadata11) => metadata11 === undefined ? Effect102.void : Schema95.decodeUnknownEffect(exports_shared_schema.Metadata)(metadata11).pipe(Effect102.mapError(() => ClientError.make({ message: "Baton agent metadata must be JSON metadata" })));
18083
+ var decodeBatonMemorySubject = (subject) => Schema95.decodeUnknownEffect(exports_ids_schema.MemorySubjectId)(subject).pipe(Effect102.mapError(() => ClientError.make({ message: "Baton agent memory subject must be a MemorySubjectId" })));
17912
18084
  var metadataFromBatonAgent = Effect102.fn("Client.metadataFromBatonAgent")(function* (input) {
17913
18085
  const agentMetadata = yield* decodeBatonAgentMetadata(input.agent.metadata);
17914
18086
  const memorySubject = input.agent.memory === undefined ? undefined : yield* decodeBatonMemorySubject(input.agent.memory.subject);
@@ -18017,10 +18189,10 @@ import { Effect as Effect104, Option as Option29 } from "effect";
18017
18189
  import { Effect as Effect103 } from "effect";
18018
18190
 
18019
18191
  // src/client-error-mapping.ts
18020
- import { Option as Option28, Schema as Schema95 } from "effect";
18192
+ import { Option as Option28, Schema as Schema96 } from "effect";
18021
18193
  var errorMessage2 = (error5) => error5 instanceof Error ? error5.message : String(error5);
18022
18194
  var toClientError = (error5) => ClientError.make({ message: errorMessage2(error5) });
18023
- var toStreamError = (error5) => Option28.match(Schema95.decodeUnknownOption(EventLogCursorNotFound)(error5), {
18195
+ var toStreamError = (error5) => Option28.match(Schema96.decodeUnknownOption(EventLogCursorNotFound)(error5), {
18024
18196
  onNone: () => toClientError(error5),
18025
18197
  onSome: (cursorError) => cursorError
18026
18198
  });
@@ -18151,8 +18323,8 @@ var childStartInput = (input, accepted2, pin, definition, createdAt, parentWaitI
18151
18323
  var childRunInternals = { childStartInput, internalSpawnChildRunInput };
18152
18324
 
18153
18325
  // src/client-execution-payloads.ts
18154
- import { Effect as Effect105, Schema as Schema96 } from "effect";
18155
- var encodeExecutionCursor = (cursor) => Schema96.encodeEffect(exports_pagination_schema.ExecutionCursorCodec)({ id: cursor.id, at: cursor.updatedAt }).pipe(Effect105.mapError(toClientError));
18326
+ import { Effect as Effect105, Schema as Schema97 } from "effect";
18327
+ var encodeExecutionCursor = (cursor) => Schema97.encodeEffect(exports_pagination_schema.ExecutionCursorCodec)({ id: cursor.id, at: cursor.updatedAt }).pipe(Effect105.mapError(toClientError));
18156
18328
  var executionIdFromIdempotencyKey = (idempotencyKey) => exports_ids_schema.ExecutionId.make(`execution:${idempotencyKey}`);
18157
18329
  var metadataWithIdempotencyKey = (metadata11, idempotencyKey) => ({
18158
18330
  ...metadata11,
@@ -18269,9 +18441,9 @@ var wakeRuntime = Effect107.fn("Client.waits.wakeRuntime")(function* (waits, eve
18269
18441
  var runtimeWakeInternals = { wakeRuntime };
18270
18442
 
18271
18443
  // src/client-tool-outcome.ts
18272
- import { Effect as Effect108, Schema as Schema97 } from "effect";
18444
+ import { Effect as Effect108, Schema as Schema98 } from "effect";
18273
18445
  var toolWaitId = (executionId, callId) => Identifiers.waitId("tool", executionId, callId);
18274
- var acceptedWaitOutcome = (wait) => Schema97.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect108.mapError(toClientError));
18446
+ var acceptedWaitOutcome = (wait) => Schema98.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect108.mapError(toClientError));
18275
18447
  var resolveToolOutcomeWait = Effect108.fn("Client.resolveToolOutcomeWait")(function* (waits, eventLog, call, outcome, completedAt) {
18276
18448
  const waitId2 = call.waitId ?? toolWaitId(call.executionId, call.call.id);
18277
18449
  const wait = yield* waits.get(waitId2).pipe(Effect108.mapError(toClientError));
@@ -18552,7 +18724,7 @@ var replyValueFrom = (content) => {
18552
18724
  const text = content.filter((part) => part.type === "text").map((part) => part.text).join("");
18553
18725
  if (text.length === 0)
18554
18726
  return Option30.none();
18555
- return Schema98.decodeUnknownOption(Schema98.UnknownFromJsonString)(text);
18727
+ return Schema99.decodeUnknownOption(Schema99.UnknownFromJsonString)(text);
18556
18728
  };
18557
18729
  var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
18558
18730
  const makeExecutionClient = yield* client;
@@ -18632,7 +18804,7 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
18632
18804
  status: "queued",
18633
18805
  metadata: { operation: "envelope-send" },
18634
18806
  createdAt
18635
- }).pipe(Effect109.catchIf(Schema98.is(exports_execution_repository.DuplicateExecution), () => Effect109.void), Effect109.mapError(toClientError));
18807
+ }).pipe(Effect109.catchIf(Schema99.is(exports_execution_repository.DuplicateExecution), () => Effect109.void), Effect109.mapError(toClientError));
18636
18808
  }
18637
18809
  const maxSequence3 = yield* eventLog.maxSequence(executionId).pipe(Effect109.mapError(toClientError));
18638
18810
  return yield* envelopes.send({
@@ -18878,7 +19050,7 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
18878
19050
  return records.map(toWaitView);
18879
19051
  }),
18880
19052
  listExecutions: Effect109.fn("Client.runtime.listExecutions")(function* (input) {
18881
- const cursor = input.cursor === undefined ? undefined : yield* Schema98.decodeEffect(exports_pagination_schema.ExecutionCursorCodec)(input.cursor).pipe(Effect109.map(({ id, at }) => ({ id, updatedAt: at })));
19053
+ const cursor = input.cursor === undefined ? undefined : yield* Schema99.decodeEffect(exports_pagination_schema.ExecutionCursorCodec)(input.cursor).pipe(Effect109.map(({ id, at }) => ({ id, updatedAt: at })));
18882
19054
  const result = yield* executionRepository.list({
18883
19055
  ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
18884
19056
  ...input.status === undefined ? {} : { status: input.status },
@@ -18928,13 +19100,13 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
18928
19100
  }).pipe(Effect109.mapError(toClientError));
18929
19101
  }),
18930
19102
  listSessions: Effect109.fn("Client.runtime.listSessions")(function* (input) {
18931
- const cursor = input.cursor === undefined ? undefined : yield* Schema98.decodeEffect(exports_pagination_schema.SessionCursorCodec)(input.cursor).pipe(Effect109.map(({ id, at }) => ({ id, updatedAt: at })));
19103
+ const cursor = input.cursor === undefined ? undefined : yield* Schema99.decodeEffect(exports_pagination_schema.SessionCursorCodec)(input.cursor).pipe(Effect109.map(({ id, at }) => ({ id, updatedAt: at })));
18932
19104
  const result = yield* sessionRepository.list({
18933
19105
  ...input.root_address_id === undefined ? {} : { rootAddressId: input.root_address_id },
18934
19106
  ...input.limit === undefined ? {} : { limit: input.limit },
18935
19107
  ...cursor === undefined ? {} : { cursor }
18936
19108
  });
18937
- const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema98.encodeEffect(exports_pagination_schema.SessionCursorCodec)({
19109
+ const nextCursor = result.nextCursor === undefined ? undefined : yield* Schema99.encodeEffect(exports_pagination_schema.SessionCursorCodec)({
18938
19110
  id: result.nextCursor.id,
18939
19111
  at: result.nextCursor.updatedAt
18940
19112
  });
@@ -18947,7 +19119,7 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
18947
19119
  const session = yield* sessionRepository.get(input.session_id).pipe(Effect109.mapError(toClientError));
18948
19120
  if (session === undefined)
18949
19121
  return yield* ClientError.make({ message: `Session not found: ${input.session_id}` });
18950
- const cursor = input.cursor === undefined ? undefined : yield* Schema98.decodeEffect(exports_pagination_schema.ExecutionCursorCodec)(input.cursor).pipe(Effect109.map(({ id, at }) => ({ id, updatedAt: at })), Effect109.mapError(toClientError));
19122
+ const cursor = input.cursor === undefined ? undefined : yield* Schema99.decodeEffect(exports_pagination_schema.ExecutionCursorCodec)(input.cursor).pipe(Effect109.map(({ id, at }) => ({ id, updatedAt: at })), Effect109.mapError(toClientError));
18951
19123
  const result = yield* executionRepository.list({
18952
19124
  sessionId: input.session_id,
18953
19125
  ...input.limit === undefined ? {} : { limit: input.limit },
@@ -19018,7 +19190,7 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
19018
19190
  if (instance === undefined || instance.status === "destroyed") {
19019
19191
  return yield* ResidentNotFound.make({ kind: input.kind, key: input.key });
19020
19192
  }
19021
- const encoded = yield* Schema98.encodeUnknownEffect(input.command.input)(input.input).pipe(Effect109.mapError(toClientError));
19193
+ const encoded = yield* Schema99.encodeUnknownEffect(input.command.input)(input.input).pipe(Effect109.mapError(toClientError));
19022
19194
  const inputRef = inputSchemaRef(input.command.name);
19023
19195
  const outputRef = outputSchemaRef(input.command.name);
19024
19196
  if (Option30.isSome(schemaRegistry)) {
@@ -19065,7 +19237,7 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
19065
19237
  message: "reply carried no decodable content"
19066
19238
  });
19067
19239
  }
19068
- return yield* Schema98.decodeUnknownEffect(input.command.output)(replyValue.value).pipe(Effect109.mapError((issue) => CommandReplyInvalid.make({
19240
+ return yield* Schema99.decodeUnknownEffect(input.command.output)(replyValue.value).pipe(Effect109.mapError((issue) => CommandReplyInvalid.make({
19069
19241
  command: input.command.name,
19070
19242
  wait_id: outcome.wait_id,
19071
19243
  message: errorMessage2(issue)
@@ -19106,14 +19278,14 @@ var layerFromRuntime3 = Layer84.effect(Service, Effect109.gen(function* () {
19106
19278
  ...input.expected_version === undefined ? {} : { expectedVersion: input.expected_version },
19107
19279
  ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
19108
19280
  updatedAt: input.updated_at
19109
- }).pipe(Effect109.mapError((error5) => Schema98.is(StateVersionConflict3)(error5) ? StateVersionConflict.make(error5) : toClientError(error5)))),
19281
+ }).pipe(Effect109.mapError((error5) => Schema99.is(StateVersionConflict3)(error5) ? StateVersionConflict.make(error5) : toClientError(error5)))),
19110
19282
  deleteResidentState: Effect109.fn("Client.runtime.deleteResidentState")((input) => executionState.remove({
19111
19283
  executionId: input.execution_id,
19112
19284
  key: input.key,
19113
19285
  ...input.expected_version === undefined ? {} : { expectedVersion: input.expected_version },
19114
19286
  ...input.idempotency_key === undefined ? {} : { idempotencyKey: input.idempotency_key },
19115
19287
  removedAt: input.removed_at
19116
- }).pipe(Effect109.mapError((error5) => Schema98.is(StateVersionConflict3)(error5) ? StateVersionConflict.make(error5) : toClientError(error5)))),
19288
+ }).pipe(Effect109.mapError((error5) => Schema99.is(StateVersionConflict3)(error5) ? StateVersionConflict.make(error5) : toClientError(error5)))),
19117
19289
  listResidentState: Effect109.fn("Client.runtime.listResidentState")((input) => executionState.list({
19118
19290
  executionId: input.execution_id,
19119
19291
  ...input.prefix === undefined ? {} : { prefix: input.prefix },
@@ -19372,77 +19544,77 @@ import { Effect as Effect111 } from "effect";
19372
19544
  var recoverPersistedFanOut = (recover) => recover().pipe(Effect111.mapError((error5) => WorkflowRuntimeError.make({ message: error5._tag })), Effect111.asVoid);
19373
19545
 
19374
19546
  // src/runtime.ts
19375
- var Dialect2 = Schema99.Literals(["pg", "mysql", "sqlite"]);
19547
+ var Dialect2 = Schema100.Literals(["pg", "mysql", "sqlite"]);
19376
19548
 
19377
- class NotificationFailure extends Schema99.TaggedErrorClass()("NotificationFailure", {
19378
- reason: Schema99.String
19549
+ class NotificationFailure extends Schema100.TaggedErrorClass()("NotificationFailure", {
19550
+ reason: Schema100.String
19379
19551
  }) {
19380
19552
  }
19381
19553
 
19382
- class ClusterFailure extends Schema99.TaggedErrorClass()("ClusterFailure", {
19383
- reason: Schema99.String
19554
+ class ClusterFailure extends Schema100.TaggedErrorClass()("ClusterFailure", {
19555
+ reason: Schema100.String
19384
19556
  }) {
19385
19557
  }
19386
19558
 
19387
- class SqlFailure extends Schema99.TaggedErrorClass()("SqlFailure", {
19388
- category: Schema99.Literals(["connection", "statement", "unknown"]),
19389
- operation: Schema99.Literals(["acquire", "migrate", "verify", "notify", "readiness"]),
19390
- retryable: Schema99.Boolean
19559
+ class SqlFailure extends Schema100.TaggedErrorClass()("SqlFailure", {
19560
+ category: Schema100.Literals(["connection", "statement", "unknown"]),
19561
+ operation: Schema100.Literals(["acquire", "migrate", "verify", "notify", "readiness"]),
19562
+ retryable: Schema100.Boolean
19391
19563
  }) {
19392
19564
  }
19393
- var SqlDialect = Schema99.Literals(["sqlite", "pg", "mysql", "mssql", "clickhouse"]);
19565
+ var SqlDialect = Schema100.Literals(["sqlite", "pg", "mysql", "mssql", "clickhouse"]);
19394
19566
 
19395
- class DatabaseDialectMismatch extends Schema99.TaggedErrorClass()("DatabaseDialectMismatch", { expected: Dialect2, actual: SqlDialect }) {
19567
+ class DatabaseDialectMismatch extends Schema100.TaggedErrorClass()("DatabaseDialectMismatch", { expected: Dialect2, actual: SqlDialect }) {
19396
19568
  }
19397
19569
 
19398
- class DatabaseAlreadyOwned extends Schema99.TaggedErrorClass()("DatabaseAlreadyOwned", {
19570
+ class DatabaseAlreadyOwned extends Schema100.TaggedErrorClass()("DatabaseAlreadyOwned", {
19399
19571
  databaseIdentity: DatabaseIdentity
19400
19572
  }) {
19401
19573
  }
19402
19574
 
19403
- class UnsupportedTopology extends Schema99.TaggedErrorClass()("UnsupportedTopology", {
19404
- reason: Schema99.String
19575
+ class UnsupportedTopology extends Schema100.TaggedErrorClass()("UnsupportedTopology", {
19576
+ reason: Schema100.String
19405
19577
  }) {
19406
19578
  }
19407
19579
 
19408
- class MigratorError extends Schema99.TaggedErrorClass()("MigratorError", {
19409
- reason: Schema99.String
19580
+ class MigratorError extends Schema100.TaggedErrorClass()("MigratorError", {
19581
+ reason: Schema100.String
19410
19582
  }) {
19411
19583
  }
19412
19584
 
19413
- class SchemaHeadMismatch extends Schema99.TaggedErrorClass()("SchemaHeadMismatch", {
19414
- expected: Schema99.String,
19415
- actual: Schema99.String
19585
+ class SchemaHeadMismatch extends Schema100.TaggedErrorClass()("SchemaHeadMismatch", {
19586
+ expected: Schema100.String,
19587
+ actual: Schema100.String
19416
19588
  }) {
19417
19589
  }
19418
19590
 
19419
- class HostUnavailable extends Schema99.TaggedErrorClass()("HostUnavailable", {
19420
- host: Schema99.String,
19421
- reason: Schema99.String
19591
+ class HostUnavailable extends Schema100.TaggedErrorClass()("HostUnavailable", {
19592
+ host: Schema100.String,
19593
+ reason: Schema100.String
19422
19594
  }) {
19423
19595
  }
19424
- var RuntimeTopologyCause = Schema99.Union([
19596
+ var RuntimeTopologyCause = Schema100.Union([
19425
19597
  ClusterFailure,
19426
19598
  DatabaseDialectMismatch,
19427
19599
  DatabaseAlreadyOwned,
19428
19600
  UnsupportedTopology
19429
19601
  ]);
19430
- var RuntimeMigrationCause = Schema99.Union([
19602
+ var RuntimeMigrationCause = Schema100.Union([
19431
19603
  SqlFailure,
19432
19604
  MigratorError,
19433
19605
  SchemaHeadMismatch
19434
19606
  ]);
19435
- var RuntimeReadinessCause = Schema99.Union([
19607
+ var RuntimeReadinessCause = Schema100.Union([
19436
19608
  SqlFailure,
19437
19609
  NotificationFailure,
19438
19610
  ClusterFailure,
19439
19611
  HostUnavailable
19440
19612
  ]);
19441
19613
 
19442
- class RuntimeTopologyError extends Schema99.TaggedErrorClass()("RuntimeTopologyError", {
19614
+ class RuntimeTopologyError extends Schema100.TaggedErrorClass()("RuntimeTopologyError", {
19443
19615
  dialect: Dialect2,
19444
- role: Schema99.Literals(["embedded", "runner", "client"]),
19445
- nextAction: Schema99.Literals([
19616
+ role: Schema100.Literals(["embedded", "runner", "client"]),
19617
+ nextAction: Schema100.Literals([
19446
19618
  "use-embedded",
19447
19619
  "use-postgres-or-mysql",
19448
19620
  "use-client-constructor",
@@ -19453,39 +19625,39 @@ class RuntimeTopologyError extends Schema99.TaggedErrorClass()("RuntimeTopologyE
19453
19625
  }) {
19454
19626
  }
19455
19627
 
19456
- class RuntimeMigrationError extends Schema99.TaggedErrorClass()("RuntimeMigrationError", {
19628
+ class RuntimeMigrationError extends Schema100.TaggedErrorClass()("RuntimeMigrationError", {
19457
19629
  dialect: Dialect2,
19458
- phase: Schema99.Literals(["apply", "verify"]),
19459
- nextAction: Schema99.Literals(["retry", "inspect-schema", "run-compatible-release"]),
19630
+ phase: Schema100.Literals(["apply", "verify"]),
19631
+ nextAction: Schema100.Literals(["retry", "inspect-schema", "run-compatible-release"]),
19460
19632
  cause: RuntimeMigrationCause
19461
19633
  }) {
19462
19634
  }
19463
19635
 
19464
- class RuntimeReadinessError extends Schema99.TaggedErrorClass()("RuntimeReadinessError", {
19465
- phase: Schema99.Literals(["database", "notification", "cluster", "hosts"]),
19636
+ class RuntimeReadinessError extends Schema100.TaggedErrorClass()("RuntimeReadinessError", {
19637
+ phase: Schema100.Literals(["database", "notification", "cluster", "hosts"]),
19466
19638
  cause: RuntimeReadinessCause
19467
19639
  }) {
19468
19640
  }
19469
- var RuntimeCapabilityStatus = Schema99.Union([
19470
- Schema99.Struct({
19471
- enabled: Schema99.Literal(false),
19472
- source: Schema99.Literals(["local-host", "role-unavailable"]),
19473
- health: Schema99.Literal("not-applicable")
19641
+ var RuntimeCapabilityStatus = Schema100.Union([
19642
+ Schema100.Struct({
19643
+ enabled: Schema100.Literal(false),
19644
+ source: Schema100.Literals(["local-host", "role-unavailable"]),
19645
+ health: Schema100.Literal("not-applicable")
19474
19646
  }),
19475
- Schema99.Struct({
19476
- enabled: Schema99.Literal(true),
19477
- source: Schema99.Literal("local-host"),
19478
- health: Schema99.Literals(["healthy", "unhealthy"])
19647
+ Schema100.Struct({
19648
+ enabled: Schema100.Literal(true),
19649
+ source: Schema100.Literal("local-host"),
19650
+ health: Schema100.Literals(["healthy", "unhealthy"])
19479
19651
  })
19480
19652
  ]);
19481
- var ReadinessStatus2 = Schema99.Struct({
19482
- ready: Schema99.Literal(true),
19483
- role: Schema99.Literals(["embedded", "runner", "client"]),
19653
+ var ReadinessStatus2 = Schema100.Struct({
19654
+ ready: Schema100.Literal(true),
19655
+ role: Schema100.Literals(["embedded", "runner", "client"]),
19484
19656
  dialect: Dialect2,
19485
19657
  databaseIdentity: DatabaseIdentity,
19486
- schemaHead: Schema99.String,
19487
- notification: Schema99.Literals(["pg-listen-notify", "polling", "in-process"]),
19488
- capabilities: Schema99.Struct({
19658
+ schemaHead: Schema100.String,
19659
+ notification: Schema100.Literals(["pg-listen-notify", "polling", "in-process"]),
19660
+ capabilities: Schema100.Struct({
19489
19661
  fanOut: RuntimeCapabilityStatus,
19490
19662
  workflowDefinition: RuntimeCapabilityStatus
19491
19663
  })
@@ -19499,7 +19671,7 @@ var normalizeHost = (layer65, _role, _dialect) => layer65.pipe(Layer86.catchCaus
19499
19671
  role: _role,
19500
19672
  nextAction: _role === "embedded" ? "use-embedded" : "use-different-database",
19501
19673
  cause: ClusterFailure.make({ reason: "cluster configuration is incompatible" })
19502
- }) : error5), "host-layer", (error5) => Schema99.is(RuntimeConfigurationError)(error5) || Schema99.is(RuntimeTopologyError)(error5) || Schema99.is(RuntimeMigrationError)(error5))))));
19674
+ }) : error5), "host-layer", (error5) => Schema100.is(RuntimeConfigurationError)(error5) || Schema100.is(RuntimeTopologyError)(error5) || Schema100.is(RuntimeMigrationError)(error5))))));
19503
19675
  var actualDialect = (sql) => sql.onDialectOrElse({
19504
19676
  sqlite: () => "sqlite",
19505
19677
  pg: () => "pg",