@relayfx/sdk 0.7.12 → 0.7.13

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.
@@ -8,7 +8,7 @@ import {
8
8
  SqlFailure,
9
9
  make,
10
10
  normalizeAcquisitionCause
11
- } from "./index-chbsjf5d.js";
11
+ } from "./index-0fta2cfp.js";
12
12
 
13
13
  // src/migration-errors.ts
14
14
  import { Cause, Effect, Function } from "effect";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  exports_tool_runtime,
15
15
  exports_workflow_definition_host,
16
16
  makeDatabaseIdentity
17
- } from "./index-chbsjf5d.js";
17
+ } from "./index-0fta2cfp.js";
18
18
  import {
19
19
  exports_context_overflow,
20
20
  exports_model_registry
@@ -148,6 +148,16 @@ var run = Effect2.fn("ToolWorker.run")(function* (options) {
148
148
  return yield* runOnce(options).pipe(Effect2.catch((error) => Effect2.logWarning("relay tool worker poll failed", { message: error.message }).pipe(Effect2.as(false))), Effect2.flatMap((worked) => worked ? Effect2.void : Effect2.sleep(pollInterval)), Effect2.forever);
149
149
  });
150
150
 
151
+ // src/event-history.ts
152
+ var exports_event_history = {};
153
+ __export(exports_event_history, {
154
+ fileSystem: () => fileSystem
155
+ });
156
+ var fileSystem = (options) => ({
157
+ _tag: "FileSystem",
158
+ directory: options.directory
159
+ });
160
+
151
161
  // src/language-model-registration.ts
152
162
  var exports_language_model_registration = {};
153
163
  __export(exports_language_model_registration, {
@@ -1044,6 +1054,7 @@ var Command = exports_command;
1044
1054
  var Operation = exports_operation;
1045
1055
  var ToolWorker = exports_tool_worker;
1046
1056
  var Runtime = exports_runtime;
1057
+ var EventHistory = exports_event_history;
1047
1058
  var WorkflowDefinitionHost = exports_workflow_definition_host;
1048
1059
  var ArtifactStore = exports_artifact_store_service;
1049
1060
  var BlobStore = exports_blob_store_service;
@@ -1079,6 +1090,7 @@ export {
1079
1090
  exports_inbox_schema as Inbox,
1080
1091
  exports_ids_schema as Ids,
1081
1092
  exports_execution_schema as Execution,
1093
+ EventHistory,
1082
1094
  exports_envelope_schema as Envelope,
1083
1095
  EmbeddingModelService,
1084
1096
  DatabaseIdentity,
@@ -0,0 +1,8 @@
1
+ CREATE TABLE "relay_event_history_bindings" (
2
+ "binding_key" integer PRIMARY KEY NOT NULL,
3
+ "store_identity" text NOT NULL,
4
+ "state" text NOT NULL,
5
+ CONSTRAINT "ck_relay_event_history_bindings_singleton" CHECK ("binding_key" = 1),
6
+ CONSTRAINT "ck_relay_event_history_bindings_identity" CHECK (length("store_identity") = 64),
7
+ CONSTRAINT "ck_relay_event_history_bindings_state" CHECK ("state" IN ('allocating', 'publishing', 'ready'))
8
+ );
@@ -0,0 +1,9 @@
1
+ CREATE TABLE `relay_event_history_bindings` (
2
+ `binding_key` integer NOT NULL,
3
+ `store_identity` varchar(64) NOT NULL,
4
+ `state` varchar(16) NOT NULL,
5
+ CONSTRAINT `pk_relay_event_history_bindings` PRIMARY KEY (`binding_key`),
6
+ CONSTRAINT `ck_relay_event_history_bindings_singleton` CHECK (`binding_key` = 1),
7
+ CONSTRAINT `ck_relay_event_history_bindings_identity` CHECK (char_length(`store_identity`) = 64),
8
+ CONSTRAINT `ck_relay_event_history_bindings_state` CHECK (`state` IN ('allocating', 'publishing', 'ready'))
9
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@@ -0,0 +1,8 @@
1
+ CREATE TABLE "relay_event_history_bindings" (
2
+ "binding_key" integer PRIMARY KEY NOT NULL,
3
+ "store_identity" text NOT NULL,
4
+ "state" text NOT NULL,
5
+ CONSTRAINT "ck_relay_event_history_bindings_singleton" CHECK ("binding_key" = 1),
6
+ CONSTRAINT "ck_relay_event_history_bindings_identity" CHECK (length("store_identity") = 64),
7
+ CONSTRAINT "ck_relay_event_history_bindings_state" CHECK ("state" IN ('allocating', 'publishing', 'ready'))
8
+ );
@@ -0,0 +1,8 @@
1
+ CREATE TABLE "relay_event_history_bindings" (
2
+ "binding_key" integer PRIMARY KEY NOT NULL,
3
+ "store_identity" text NOT NULL,
4
+ "state" text NOT NULL,
5
+ CONSTRAINT "ck_relay_event_history_bindings_singleton" CHECK ("binding_key" = 1),
6
+ CONSTRAINT "ck_relay_event_history_bindings_identity" CHECK (length("store_identity") = 64),
7
+ CONSTRAINT "ck_relay_event_history_bindings_state" CHECK ("state" IN ('allocating', 'publishing', 'ready'))
8
+ );
package/dist/mysql.js CHANGED
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-agr4t5nk.js";
5
+ } from "./index-fn3rdmbr.js";
6
6
  import {
7
7
  MigratorError,
8
8
  RuntimeMigrationError,
9
9
  SqlFailure
10
- } from "./index-chbsjf5d.js";
10
+ } from "./index-0fta2cfp.js";
11
11
  import"./index-d5563j6w.js";
12
12
  import"./index-j8k41y47.js";
13
13
  import"./index-nb39b5ae.js";
@@ -109,6 +109,9 @@ var _0017_execution_event_identity_directory_default = "CREATE TABLE IF NOT EXIS
109
109
  // ../../migrations/mysql/0018_idempotent_steering.sql
110
110
  var _0018_idempotent_steering_default = "ALTER TABLE `relay_steering_messages` ADD COLUMN `idempotency_key` varchar(191) COLLATE utf8mb4_bin;\n--> statement-breakpoint\nUPDATE `relay_steering_messages` SET `idempotency_key` = CONCAT('relay:legacy:', `kind`, ':', `sequence`);\n--> statement-breakpoint\nALTER TABLE `relay_steering_messages` MODIFY COLUMN `idempotency_key` varchar(191) COLLATE utf8mb4_bin NOT NULL;\n--> statement-breakpoint\nCREATE UNIQUE INDEX `uq_relay_steering_messages_idempotency` ON `relay_steering_messages` (`tenant_id`, `execution_id`, `idempotency_key`);\n";
111
111
 
112
+ // ../../migrations/mysql/0019_event_history_binding.sql
113
+ var _0019_event_history_binding_default = "CREATE TABLE `relay_event_history_bindings` (\n `binding_key` integer NOT NULL,\n `store_identity` varchar(64) NOT NULL,\n `state` varchar(16) NOT NULL,\n CONSTRAINT `pk_relay_event_history_bindings` PRIMARY KEY (`binding_key`),\n CONSTRAINT `ck_relay_event_history_bindings_singleton` CHECK (`binding_key` = 1),\n CONSTRAINT `ck_relay_event_history_bindings_identity` CHECK (char_length(`store_identity`) = 64),\n CONSTRAINT `ck_relay_event_history_bindings_state` CHECK (`state` IN ('allocating', 'publishing', 'ready'))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n";
114
+
112
115
  // src/mysql-migrations.ts
113
116
  var migrations = [
114
117
  [1, "baseline", _0001_baseline_default],
@@ -128,10 +131,85 @@ var migrations = [
128
131
  [15, "transactional_event_head", _0015_transactional_event_head_default],
129
132
  [16, "execution_event_archive_manifests", _0016_execution_event_archive_manifests_default],
130
133
  [17, "execution_event_identity_directory", _0017_execution_event_identity_directory_default],
131
- [18, "idempotent_steering", _0018_idempotent_steering_default]
134
+ [18, "idempotent_steering", _0018_idempotent_steering_default],
135
+ [19, "event_history_binding", _0019_event_history_binding_default]
132
136
  ];
133
137
 
134
138
  // src/mysql.ts
139
+ var migration19Failure = () => RuntimeMigrationError.make({
140
+ dialect: "mysql",
141
+ phase: "apply",
142
+ nextAction: "inspect-schema",
143
+ cause: MigratorError.make({ reason: "migration 19 table exists with an unexpected catalog shape" })
144
+ });
145
+ var normalizeCheckClause = (value) => (value.match(/'(?:''|[^'])*'|[^']+/g) ?? []).map((part) => part.startsWith("'") ? part : part.toLowerCase().replace(/_[a-z0-9]+$/g, "").replace(/[`()\s]/g, "")).join("");
146
+ var rowsEqual = (left, right) => left.length === right.length && left.every((row, index) => row.every((value, column) => value === right[index]?.[column]));
147
+ var reconcileMigration19 = Effect.fn("MySQL.reconcileMigration19")(function* (connection) {
148
+ const tables = yield* connection.execute(`SELECT t.engine AS engine, t.table_collation AS table_collation
149
+ FROM information_schema.tables t
150
+ WHERE t.table_schema = DATABASE() AND t.table_name = 'relay_event_history_bindings'`, [], undefined);
151
+ if (tables.length === 0)
152
+ return false;
153
+ if (tables.length !== 1)
154
+ return yield* migration19Failure();
155
+ const table = tables[0];
156
+ if (table.engine?.toLowerCase() !== "innodb" || table.table_collation !== "utf8mb4_unicode_ci") {
157
+ return yield* migration19Failure();
158
+ }
159
+ const columns = yield* connection.execute(`SELECT ordinal_position, column_name, data_type, column_type, is_nullable,
160
+ character_maximum_length, collation_name, column_default, extra
161
+ FROM information_schema.columns
162
+ WHERE table_schema = DATABASE() AND table_name = 'relay_event_history_bindings'
163
+ ORDER BY ordinal_position`, [], undefined);
164
+ const expectedColumns = [
165
+ [1, "binding_key", "int", "int", "NO", null, null, null, ""],
166
+ [2, "store_identity", "varchar", "varchar(64)", "NO", 64, "utf8mb4_unicode_ci", null, ""],
167
+ [3, "state", "varchar", "varchar(16)", "NO", 16, "utf8mb4_unicode_ci", null, ""]
168
+ ];
169
+ const actualColumns = columns.map((column) => [
170
+ Number(column.ordinal_position),
171
+ column.column_name,
172
+ column.data_type,
173
+ column.column_type,
174
+ column.is_nullable,
175
+ column.character_maximum_length === null ? null : Number(column.character_maximum_length),
176
+ column.collation_name,
177
+ column.column_default,
178
+ column.extra
179
+ ]);
180
+ if (!rowsEqual(actualColumns, expectedColumns))
181
+ return yield* migration19Failure();
182
+ const constraints = yield* connection.execute(`SELECT tc.constraint_name, tc.constraint_type, tc.enforced, cc.check_clause
183
+ FROM information_schema.table_constraints tc
184
+ LEFT JOIN information_schema.check_constraints cc
185
+ ON tc.constraint_type = 'CHECK'
186
+ AND cc.constraint_schema = tc.constraint_schema AND cc.constraint_name = tc.constraint_name
187
+ WHERE tc.constraint_schema = DATABASE() AND tc.table_name = 'relay_event_history_bindings'
188
+ ORDER BY tc.constraint_name`, [], undefined);
189
+ const actualConstraints = constraints.map((constraint) => [
190
+ constraint.constraint_name,
191
+ constraint.constraint_type,
192
+ constraint.constraint_type === "CHECK" ? constraint.enforced : null,
193
+ typeof constraint.check_clause === "string" ? normalizeCheckClause(constraint.check_clause) : null
194
+ ]).toSorted((left, right) => String(left[0]).localeCompare(String(right[0]), "en"));
195
+ const expectedConstraints = [
196
+ ["PRIMARY", "PRIMARY KEY", null, null],
197
+ ["ck_relay_event_history_bindings_identity", "CHECK", "YES", "char_lengthstore_identity=64"],
198
+ ["ck_relay_event_history_bindings_singleton", "CHECK", "YES", "binding_key=1"],
199
+ ["ck_relay_event_history_bindings_state", "CHECK", "YES", "statein'allocating','publishing','ready'"]
200
+ ].toSorted((left, right) => String(left[0]).localeCompare(String(right[0]), "en"));
201
+ if (!rowsEqual(actualConstraints, expectedConstraints))
202
+ return yield* migration19Failure();
203
+ const primaryKey = yield* connection.execute(`SELECT column_name, ordinal_position
204
+ FROM information_schema.key_column_usage
205
+ WHERE constraint_schema = DATABASE() AND table_name = 'relay_event_history_bindings'
206
+ AND constraint_name = 'PRIMARY'
207
+ ORDER BY ordinal_position`, [], undefined);
208
+ if (primaryKey.length !== 1 || primaryKey[0].column_name !== "binding_key" || Number(primaryKey[0].ordinal_position) !== 1) {
209
+ return yield* migration19Failure();
210
+ }
211
+ return true;
212
+ });
135
213
  var verifySchema = Effect.gen(function* () {
136
214
  const sql = yield* SqlClient;
137
215
  const rows = yield* sql`SELECT migration_id, name FROM relay_migrations ORDER BY migration_id`;
@@ -167,6 +245,8 @@ var runMigrations = Effect.gen(function* () {
167
245
  return yield* Effect.gen(function* () {
168
246
  const migration = yield* Effect.exit(Effect.gen(function* () {
169
247
  for (const statement of statements) {
248
+ if (id === 19 && (yield* reconcileMigration19(connection)))
249
+ continue;
170
250
  if (id === 16) {
171
251
  const catalogQuery = statement.includes("ADD COLUMN") ? [
172
252
  "SELECT COUNT(*) AS count FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'relay_execution_event_heads' AND column_name = ?",
package/dist/postgres.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-agr4t5nk.js";
5
+ } from "./index-fn3rdmbr.js";
6
6
  import {
7
7
  Dialect,
8
8
  RuntimeMigrationError,
@@ -14,7 +14,7 @@ import {
14
14
  fromDbTimestamp,
15
15
  fromNullableDbTimestamp,
16
16
  timestampParam
17
- } from "./index-chbsjf5d.js";
17
+ } from "./index-0fta2cfp.js";
18
18
  import"./index-d5563j6w.js";
19
19
  import {
20
20
  exports_ids_schema
@@ -422,6 +422,16 @@ var relayExecutionEventHeads = pgTable5("relay_execution_event_heads", {
422
422
  primaryKey5({ columns: [table.tenantId, table.executionId], name: "pk_relay_execution_event_heads" }),
423
423
  check2("ck_relay_execution_event_heads_archive_pointer", sql2`(${table.archivedThrough} IS NULL) = (${table.archiveGeneration} IS NULL)`)
424
424
  ]);
425
+ var relayEventHistoryBindings = pgTable5("relay_event_history_bindings", {
426
+ bindingKey: integer4("binding_key").notNull(),
427
+ storeIdentity: text6("store_identity").notNull(),
428
+ state: text6("state").$type().notNull()
429
+ }, (table) => [
430
+ primaryKey5({ columns: [table.bindingKey], name: "pk_relay_event_history_bindings" }),
431
+ check2("ck_relay_event_history_bindings_singleton", sql2`${table.bindingKey} = 1`),
432
+ check2("ck_relay_event_history_bindings_identity", sql2`length(${table.storeIdentity}) = 64`),
433
+ check2("ck_relay_event_history_bindings_state", sql2`${table.state} IN ('allocating', 'publishing', 'ready')`)
434
+ ]);
425
435
  var relayExecutionEventArchiveManifests = pgTable5("relay_execution_event_archive_manifests", {
426
436
  tenantId: tenantId(),
427
437
  executionId: text6("execution_id").$type().notNull(),
@@ -865,8 +875,8 @@ var relayIdempotencyKeys = pgTable13("relay_idempotency_keys", {
865
875
  uniqueIndex9("uq_relay_idempotency_scope_operation_key").on(table.tenantId, table.scope, table.operation, table.key)
866
876
  ]);
867
877
  // src/postgres.ts
868
- var priorSchemaHead = "20260724120000_execution_event_identity_directory";
869
- var schemaHead = "20260724230000_idempotent_steering";
878
+ var priorSchemaHead = "20260724230000_idempotent_steering";
879
+ var schemaHead = "20260725010000_event_history_binding";
870
880
  var migrationNames = [
871
881
  "20260701002839_sour_cerebro",
872
882
  "20260701041134_acoustic_hulk",
@@ -899,6 +909,7 @@ var migrationNames = [
899
909
  "20260721170000_session_writer_ownership",
900
910
  "20260723190000_transactional_event_head",
901
911
  "20260724010000_execution_event_archive_manifests",
912
+ "20260724120000_execution_event_identity_directory",
902
913
  priorSchemaHead,
903
914
  schemaHead
904
915
  ];
package/dist/sqlite.js CHANGED
@@ -2,17 +2,21 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-agr4t5nk.js";
5
+ } from "./index-fn3rdmbr.js";
6
6
  import {
7
7
  DatabaseAlreadyOwned,
8
+ HostUnavailable,
8
9
  RuntimeConfigurationError,
9
10
  RuntimeMigrationError,
11
+ RuntimeReadinessError,
10
12
  RuntimeTopologyError,
11
13
  SchemaHeadMismatch,
14
+ UnsupportedTopology,
15
+ exports_runtime_event_history,
12
16
  make,
13
17
  makeDatabaseIdentity,
14
18
  runtimeLayer
15
- } from "./index-chbsjf5d.js";
19
+ } from "./index-0fta2cfp.js";
16
20
  import"./index-d5563j6w.js";
17
21
  import"./index-j8k41y47.js";
18
22
  import"./index-nb39b5ae.js";
@@ -21,8 +25,9 @@ import"./index-nb39b5ae.js";
21
25
  import { layer as sqliteClientLayer } from "@effect/sql-sqlite-bun/SqliteClient";
22
26
  import { run as runSqliteMigrator } from "@effect/sql-sqlite-bun/SqliteMigrator";
23
27
  import { layer as bunServicesLayer } from "@effect/platform-bun/BunServices";
24
- import { Effect as Effect2, FileSystem, Layer, Path } from "effect";
28
+ import { Cause, Effect as Effect2, FileSystem, Layer, Path, Semaphore } from "effect";
25
29
  import { SqlClient as SqlClient2 } from "effect/unstable/sql/SqlClient";
30
+ import { resolve } from "path";
26
31
 
27
32
  // ../../migrations/sqlite/0001_baseline.sql
28
33
  var _0001_baseline_default = `CREATE TABLE "relay_address_book_entries" (
@@ -779,6 +784,17 @@ UPDATE "relay_steering_messages" SET "idempotency_key" = 'relay:legacy:' || "kin
779
784
  CREATE UNIQUE INDEX "uq_relay_steering_messages_idempotency" ON "relay_steering_messages" ("tenant_id", "execution_id", "idempotency_key");
780
785
  `;
781
786
 
787
+ // ../../migrations/sqlite/0019_event_history_binding.sql
788
+ var _0019_event_history_binding_default = `CREATE TABLE "relay_event_history_bindings" (
789
+ "binding_key" integer PRIMARY KEY NOT NULL,
790
+ "store_identity" text NOT NULL,
791
+ "state" text NOT NULL,
792
+ CONSTRAINT "ck_relay_event_history_bindings_singleton" CHECK ("binding_key" = 1),
793
+ CONSTRAINT "ck_relay_event_history_bindings_identity" CHECK (length("store_identity") = 64),
794
+ CONSTRAINT "ck_relay_event_history_bindings_state" CHECK ("state" IN ('allocating', 'publishing', 'ready'))
795
+ );
796
+ `;
797
+
782
798
  // src/sqlite-migrations.ts
783
799
  import { Effect } from "effect";
784
800
  import { SqlClient } from "effect/unstable/sql/SqlClient";
@@ -817,7 +833,8 @@ var migrations = [
817
833
  file: "0017_execution_event_identity_directory.sql",
818
834
  source: _0017_execution_event_identity_directory_default
819
835
  },
820
- { id: 18, name: "idempotent_steering", file: "0018_idempotent_steering.sql", source: _0018_idempotent_steering_default }
836
+ { id: 18, name: "idempotent_steering", file: "0018_idempotent_steering.sql", source: _0018_idempotent_steering_default },
837
+ { id: 19, name: "event_history_binding", file: "0019_event_history_binding.sql", source: _0019_event_history_binding_default }
821
838
  ];
822
839
  var loader = Effect.succeed(migrations.map(({ id, name, source }) => [id, name, Effect.succeed(execute(source))]));
823
840
 
@@ -831,15 +848,41 @@ var canonicalFilename = Effect2.fn("SQLite.canonicalFilename")(function* (filena
831
848
  const absolute = path.resolve(filename);
832
849
  return yield* fs.realPath(absolute).pipe(Effect2.catch(() => fs.realPath(path.dirname(absolute)).pipe(Effect2.map((parent) => path.resolve(parent, path.basename(absolute))), Effect2.orElseSucceed(() => absolute))));
833
850
  });
851
+ var databaseConfigurationFailure = () => RuntimeConfigurationError.make({
852
+ category: "database-config",
853
+ scope: "database-client",
854
+ cause: {
855
+ reasons: [
856
+ { _tag: "Fail", category: "database-config", errorTag: "RuntimeHostLayerFailure" }
857
+ ],
858
+ truncated: false
859
+ }
860
+ });
861
+ var eventHistoryOptions = (rootDirectory) => {
862
+ const operationGate = Semaphore.makeUnsafe(1);
863
+ return {
864
+ executionEventRepositoryLayer: exports_runtime_event_history.fileSystemRepositoryLayer({
865
+ rootDirectory,
866
+ operationGate
867
+ }).pipe(Layer.provide(bunServicesLayer), Layer.catchCause((cause) => Layer.unwrap(Effect2.failCause(Cause.map(cause, databaseConfigurationFailure))))),
868
+ eventHistoryCheck: exports_runtime_event_history.fileSystemHealth({
869
+ rootDirectory,
870
+ operationGate
871
+ }).pipe(Effect2.provide(bunServicesLayer), Effect2.mapError(() => RuntimeReadinessError.make({
872
+ phase: "event-history",
873
+ cause: HostUnavailable.make({ host: "event-history", reason: "health check failed" })
874
+ })))
875
+ };
876
+ };
834
877
  var database2 = (options) => {
835
- if (options.filename.length === 0) {
836
- const failure = RuntimeConfigurationError.make({
837
- category: "database-config",
838
- scope: "database-client",
839
- cause: {
840
- reasons: [{ _tag: "Fail", category: "database-config", errorTag: "RuntimeHostLayerFailure" }],
841
- truncated: false
842
- }
878
+ if (options.eventHistory !== undefined && options.filename === ":memory:") {
879
+ const failure = RuntimeTopologyError.make({
880
+ dialect: "sqlite",
881
+ role: "embedded",
882
+ nextAction: "use-different-database",
883
+ cause: UnsupportedTopology.make({
884
+ reason: "Filesystem event history requires persistent SQLite and a directory"
885
+ })
843
886
  });
844
887
  return make({
845
888
  dialect: "sqlite",
@@ -848,14 +891,25 @@ var database2 = (options) => {
848
891
  runtimeLayer: Layer.unwrap(Effect2.fail(failure))
849
892
  });
850
893
  }
894
+ if (options.filename.length === 0 || options.eventHistory !== undefined && (options.eventHistory._tag !== "FileSystem" || options.eventHistory.directory.length === 0)) {
895
+ const failure = databaseConfigurationFailure();
896
+ return make({
897
+ dialect: "sqlite",
898
+ migrate: Effect2.fail(failure),
899
+ verify: Effect2.fail(failure),
900
+ runtimeLayer: Layer.unwrap(Effect2.fail(failure))
901
+ });
902
+ }
851
903
  const memoryOwnerIdentity = options.filename === ":memory:" ? `sqlite:memory:${memoryIdentity++}` : undefined;
904
+ const historyRoot = options.eventHistory === undefined ? undefined : resolve(options.eventHistory.directory);
852
905
  const resolvedFilename = options.filename === ":memory:" ? Effect2.succeed(options.filename) : Effect2.scoped(Layer.build(bunServicesLayer).pipe(Effect2.flatMap((context) => Effect2.provide(canonicalFilename(options.filename), context))));
853
906
  const resolveDatabase = resolvedFilename.pipe(Effect2.map((filename) => makeSqliteDatabase(options, filename, memoryOwnerIdentity)));
854
907
  return make({
855
908
  dialect: "sqlite",
856
909
  runtimeLayer: Layer.unwrap(resolveDatabase.pipe(Effect2.map(runtimeLayer))),
857
910
  migrate: resolveDatabase.pipe(Effect2.flatMap((value) => value.migrate)),
858
- verify: resolveDatabase.pipe(Effect2.flatMap((value) => value.verify))
911
+ verify: resolveDatabase.pipe(Effect2.flatMap((value) => value.verify)),
912
+ ...historyRoot === undefined ? {} : eventHistoryOptions(historyRoot)
859
913
  });
860
914
  };
861
915
  var makeSqliteDatabase = (options, filename, memoryOwnerIdentity) => {
@@ -876,9 +930,10 @@ var makeSqliteDatabase = (options, filename, memoryOwnerIdentity) => {
876
930
  });
877
931
  }
878
932
  });
933
+ const { eventHistory: _eventHistory, ...clientOptions } = options;
879
934
  const adapterDatabase = database({
880
935
  dialect: "sqlite",
881
- clientLayer: clientLayer({ ...options, filename }),
936
+ clientLayer: clientLayer({ ...clientOptions, filename }),
882
937
  databaseIdentity,
883
938
  ownership: "runtime-exclusive",
884
939
  schemaHead: String(migrations.at(-1)?.id ?? 0),
@@ -0,0 +1,8 @@
1
+ export interface FileSystemConfig {
2
+ readonly _tag: "FileSystem";
3
+ readonly directory: string;
4
+ }
5
+ export type Config = FileSystemConfig;
6
+ export declare const fileSystem: (options: {
7
+ readonly directory: string;
8
+ }) => FileSystemConfig;
@@ -4,6 +4,7 @@ import * as CommandModule from "./command";
4
4
  import * as OperationModule from "./operation";
5
5
  import * as ToolWorkerModule from "./tool-worker";
6
6
  import * as RuntimeModule from "./runtime";
7
+ import * as EventHistoryModule from "./event-history";
7
8
  import * as WorkflowDefinitionHostModule from "./workflow-definition-host";
8
9
  import { DatabaseIdentity, makeDatabaseIdentity } from "./database-identity";
9
10
  import { Address, Agent, ChildOrchestration, Content, Resident, Envelope, Execution, Ids, Inbox, Pagination, Presence, Schedule, Shared, Skill, State, Tool, Waits, Workflow } from "../schema/index";
@@ -23,6 +24,7 @@ export import Command = CommandModule;
23
24
  export import Operation = OperationModule;
24
25
  export import ToolWorker = ToolWorkerModule;
25
26
  export import Runtime = RuntimeModule;
27
+ export import EventHistory = EventHistoryModule;
26
28
  export import WorkflowDefinitionHost = WorkflowDefinitionHostModule;
27
29
  export import ArtifactStore = ArtifactStoreModule;
28
30
  export import BlobStore = BlobStoreModule;
@@ -1 +1 @@
1
- export declare const migrations: readonly [readonly [1, "baseline", string], readonly [2, "durable_tool_placement", string], readonly [3, "durable_inbox", string], readonly [4, "execution_state", string], readonly [5, "durable_entities", string], readonly [6, "ephemeral_presence", string], readonly [7, "topic_subscriptions", string], readonly [8, "child_fan_out", string], readonly [9, "workflow_definitions", string], readonly [10, "workflow_runtime", string], readonly [11, "execution_scoped_tool_calls", string], readonly [12, "rename_entity_to_resident", string], readonly [13, "steering_delivered", string], readonly [14, "session_writer_ownership", string], readonly [15, "transactional_event_head", string], readonly [16, "execution_event_archive_manifests", string], readonly [17, "execution_event_identity_directory", string], readonly [18, "idempotent_steering", string]];
1
+ export declare const migrations: readonly [readonly [1, "baseline", string], readonly [2, "durable_tool_placement", string], readonly [3, "durable_inbox", string], readonly [4, "execution_state", string], readonly [5, "durable_entities", string], readonly [6, "ephemeral_presence", string], readonly [7, "topic_subscriptions", string], readonly [8, "child_fan_out", string], readonly [9, "workflow_definitions", string], readonly [10, "workflow_runtime", string], readonly [11, "execution_scoped_tool_calls", string], readonly [12, "rename_entity_to_resident", string], readonly [13, "steering_delivered", string], readonly [14, "session_writer_ownership", string], readonly [15, "transactional_event_head", string], readonly [16, "execution_event_archive_manifests", string], readonly [17, "execution_event_identity_directory", string], readonly [18, "idempotent_steering", string], readonly [19, "event_history_binding", string]];
@@ -1,13 +1,19 @@
1
1
  import { Effect, Layer } from "effect";
2
- import type { SqlClient } from "effect/unstable/sql/SqlClient";
2
+ import { type SqlClient } from "effect/unstable/sql/SqlClient";
3
3
  import type { Service as RuntimeDatabaseService } from "./runtime-database";
4
4
  import type { Dialect } from "./runtime";
5
5
  import type { Database } from "./runtime-database-public";
6
+ import type { ExecutionEventRepository, NotificationBus } from "../store-sql/portable";
7
+ import type { RuntimeReadinessError } from "./runtime";
6
8
  import { RuntimeConfigurationError } from "./runtime-acquisition-error";
7
9
  export declare const make: <D extends Dialect, E, R>(value: {
8
10
  readonly dialect: D;
9
11
  readonly migrate: Effect.Effect<void, E, R>;
10
12
  readonly verify: Effect.Effect<void, E, R>;
11
13
  readonly runtimeLayer: Layer.Layer<RuntimeDatabaseService | SqlClient, E, R>;
14
+ readonly executionEventRepositoryLayer?: Layer.Layer<ExecutionEventRepository.Service, RuntimeConfigurationError, NotificationBus.Service | SqlClient>;
15
+ readonly eventHistoryCheck?: Effect.Effect<void, RuntimeReadinessError, SqlClient>;
12
16
  }) => Database<D, E, R>;
17
+ export declare const executionEventRepositoryLayer: <D extends Dialect, E, R>(database: Database<D, E, R>) => Layer.Layer<ExecutionEventRepository.Service, RuntimeConfigurationError, NotificationBus.Service | SqlClient> | undefined;
18
+ export declare const eventHistoryCheck: <D extends Dialect, E, R>(database: Database<D, E, R>) => Effect.Effect<void, RuntimeReadinessError, SqlClient> | undefined;
13
19
  export declare const runtimeLayer: <D extends Dialect, E, R>(database: Database<D, E, R>) => Layer.Layer<RuntimeDatabaseService | SqlClient, E | RuntimeConfigurationError, R>;
@@ -99,7 +99,7 @@ declare const RuntimeMigrationError_base: Schema.Class<RuntimeMigrationError, Sc
99
99
  export declare class RuntimeMigrationError extends RuntimeMigrationError_base {
100
100
  }
101
101
  declare const RuntimeReadinessError_base: Schema.Class<RuntimeReadinessError, Schema.TaggedStruct<"RuntimeReadinessError", {
102
- readonly phase: Schema.Literals<readonly ["database", "notification", "cluster", "hosts"]>;
102
+ readonly phase: Schema.Literals<readonly ["database", "notification", "cluster", "hosts", "event-history"]>;
103
103
  readonly cause: Schema.Schema<RuntimeReadinessCause>;
104
104
  }>, Cause.YieldableError>;
105
105
  export declare class RuntimeReadinessError extends RuntimeReadinessError_base {
@@ -122,6 +122,10 @@ export declare const ReadinessStatus: Schema.Struct<{
122
122
  readonly databaseIdentity: Schema.brand<Schema.NonEmptyString, "@relayfx/sdk/DatabaseIdentity">;
123
123
  readonly schemaHead: Schema.String;
124
124
  readonly notification: Schema.Literals<readonly ["pg-listen-notify", "polling", "in-process"]>;
125
+ readonly eventHistory: Schema.Struct<{
126
+ readonly mode: Schema.Literals<readonly ["sql-only", "archive-aware"]>;
127
+ readonly health: Schema.Literal<"healthy">;
128
+ }>;
125
129
  readonly capabilities: Schema.Struct<{
126
130
  readonly fanOut: Schema.Union<readonly [Schema.Struct<{
127
131
  readonly enabled: Schema.Literal<false>;
@@ -90,5 +90,10 @@ export declare const migrations: readonly [{
90
90
  readonly name: "idempotent_steering";
91
91
  readonly file: "0018_idempotent_steering.sql";
92
92
  readonly source: string;
93
+ }, {
94
+ readonly id: 19;
95
+ readonly name: "event_history_binding";
96
+ readonly file: "0019_event_history_binding.sql";
97
+ readonly source: string;
93
98
  }];
94
- export declare const loader: Effect.Effect<(readonly [1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18, "baseline" | "child_fan_out" | "durable_entities" | "durable_inbox" | "durable_tool_placement" | "ephemeral_presence" | "execution_event_archive_manifests" | "execution_event_identity_directory" | "execution_scoped_tool_calls" | "execution_state" | "idempotent_steering" | "rename_entity_to_resident" | "session_writer_ownership" | "steering_delivered" | "topic_subscriptions" | "transactional_event_head" | "workflow_definitions" | "workflow_runtime", Effect.Effect<Effect.Effect<void, import("effect/unstable/sql/SqlError").SqlError, SqlClient>, never, never>])[], never, never>;
99
+ export declare const loader: Effect.Effect<(readonly [1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19, "baseline" | "child_fan_out" | "durable_entities" | "durable_inbox" | "durable_tool_placement" | "ephemeral_presence" | "event_history_binding" | "execution_event_archive_manifests" | "execution_event_identity_directory" | "execution_scoped_tool_calls" | "execution_state" | "idempotent_steering" | "rename_entity_to_resident" | "session_writer_ownership" | "steering_delivered" | "topic_subscriptions" | "transactional_event_head" | "workflow_definitions" | "workflow_runtime", Effect.Effect<Effect.Effect<void, import("effect/unstable/sql/SqlError").SqlError, SqlClient>, never, never>])[], never, never>;
@@ -2,6 +2,7 @@ import type { Database } from "./runtime-database-public";
2
2
  import { RuntimeConfigurationError, RuntimeMigrationError, RuntimeTopologyError } from "./runtime";
3
3
  interface SQLiteRuntimeDatabaseOptions {
4
4
  readonly filename: string;
5
+ readonly eventHistory?: import("./event-history").Config;
5
6
  readonly disableWAL?: boolean;
6
7
  readonly spanAttributes?: Record<string, unknown>;
7
8
  readonly transformResultNames?: (name: string) => string;
@@ -1,8 +1,15 @@
1
1
  export * from "../runtime/tool/tool-runtime-contract";
2
- import type { DynamicToolOptions, Interface, PlacedToolOptions, RegisteredTool, RunError, RunInput, Service, ToolkitRegistrationOptions, ToolOptions } from "../runtime/tool/tool-runtime-contract";
2
+ import type { DynamicToolOptions, Interface, PlacedToolOptions, RegisteredTool, RunError, RunInput, Service, ToolkitRegistrationOptions, ToolExecutionContext, ToolExecutionFailed, ToolOptions } from "../runtime/tool/tool-runtime-contract";
3
3
  import { Context, Effect, Layer, Schema } from "effect";
4
4
  import type { Tool as AiTool, Toolkit } from "effect/unstable/ai";
5
5
  import type { Tool } from "../schema/index";
6
+ export interface ToolkitInvocationContext<Services, Requirements> {
7
+ readonly make: (context: ToolExecutionContext) => Effect.Effect<Context.Context<Services>, ToolExecutionFailed, Requirements>;
8
+ }
9
+ export interface HandledToolkitRegistrationOptions<Services = never, Requirements = never> {
10
+ readonly tools?: ToolkitRegistrationOptions;
11
+ readonly invocation?: ToolkitInvocationContext<Services, Requirements>;
12
+ }
6
13
  export declare const tool: {
7
14
  <const Name extends string, Input extends Schema.ConstraintCodec<unknown, unknown, never, never>, Output extends Schema.ConstraintCodec<unknown, unknown, never, never>>(name: Name, options: ToolOptions<Input, Output>): RegisteredTool;
8
15
  <Input extends Schema.ConstraintCodec<unknown, unknown, never, never>, Output extends Schema.ConstraintCodec<unknown, unknown, never, never>>(options: ToolOptions<Input, Output>): <const Name extends string>(name: Name) => RegisteredTool;
@@ -40,5 +47,11 @@ export declare const layerFromToolkit: {
40
47
  <Tools extends Record<string, AiTool.Any>>(toolkit: Toolkit.Toolkit<Tools>, options?: ToolkitRegistrationOptions): Layer.Layer<HostService, never, AiTool.HandlersFor<Tools>>;
41
48
  (options?: ToolkitRegistrationOptions): <Tools extends Record<string, AiTool.Any>>(toolkit: Toolkit.Toolkit<Tools>) => Layer.Layer<HostService, never, AiTool.HandlersFor<Tools>>;
42
49
  };
50
+ export declare const layerFromHandledToolkit: {
51
+ <Tools extends Record<string, AiTool.Any>, E, R>(toolkit: Effect.Effect<Toolkit.WithHandler<Tools>, E, R>): Layer.Layer<HostService, E, R>;
52
+ <Tools extends Record<string, AiTool.Any>, E, R, InvocationRequirements>(toolkit: Effect.Effect<Toolkit.WithHandler<Tools>, E, R>, options: HandledToolkitRegistrationOptions<AiTool.HandlerServices<Tools[keyof Tools]>, InvocationRequirements>): Layer.Layer<HostService, E, R | InvocationRequirements>;
53
+ (): <Tools extends Record<string, AiTool.Any>, E, R>(toolkit: Effect.Effect<Toolkit.WithHandler<Tools>, E, R>) => Layer.Layer<HostService, E, R>;
54
+ <Services, InvocationRequirements>(options: HandledToolkitRegistrationOptions<Services, InvocationRequirements>): <Tools extends Record<string, AiTool.Any>, E, R>(toolkit: Effect.Effect<Toolkit.WithHandler<Tools>, E, R>) => Layer.Layer<HostService, E, R | InvocationRequirements>;
55
+ };
43
56
  export declare const testLayer: (implementation: Interface) => Layer.Layer<Service>;
44
57
  export declare const run: (input: RunInput) => Effect.Effect<Tool.Result, RunError, Service>;