@relayfx/sdk 0.7.10 → 0.7.11

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 (71) hide show
  1. package/dist/http-server.js +1 -1
  2. package/dist/{index-gwgea1te.js → index-d1je4njg.js} +4088 -3764
  3. package/dist/{index-nb078xsy.js → index-j8k41y47.js} +26 -4
  4. package/dist/{index-m7dpw880.js → index-skcp0xvt.js} +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/migrations/20260723190000_transactional_event_head/migration.sql +22 -0
  7. package/dist/migrations/20260724010000_execution_event_archive_manifests/migration.sql +66 -0
  8. package/dist/migrations/20260724120000_execution_event_identity_directory/migration.sql +15 -0
  9. package/dist/migrations/20260724230000_idempotent_steering/migration.sql +7 -0
  10. package/dist/migrations/mysql/0015_transactional_event_head.sql +32 -0
  11. package/dist/migrations/mysql/0016_execution_event_archive_manifests.sql +65 -0
  12. package/dist/migrations/mysql/0017_execution_event_identity_directory.sql +20 -0
  13. package/dist/migrations/mysql/0018_idempotent_steering.sql +7 -0
  14. package/dist/migrations/pg/20260723190000_transactional_event_head/migration.sql +22 -0
  15. package/dist/migrations/pg/20260724010000_execution_event_archive_manifests/migration.sql +66 -0
  16. package/dist/migrations/pg/20260724120000_execution_event_identity_directory/migration.sql +15 -0
  17. package/dist/migrations/pg/20260724230000_idempotent_steering/migration.sql +7 -0
  18. package/dist/migrations/sqlite/0015_transactional_event_head.sql +22 -0
  19. package/dist/migrations/sqlite/0016_execution_event_archive_manifests.sql +45 -0
  20. package/dist/migrations/sqlite/0017_execution_event_identity_directory.sql +13 -0
  21. package/dist/migrations/sqlite/0018_idempotent_steering.sql +5 -0
  22. package/dist/mysql.js +49 -8
  23. package/dist/postgres.js +135 -13
  24. package/dist/sqlite.js +115 -4
  25. package/dist/types/relay/client-public-executions.d.ts +1 -1
  26. package/dist/types/relay/client-public.d.ts +2 -2
  27. package/dist/types/relay/http-server.d.ts +2 -2
  28. package/dist/types/relay/mysql-migrations.d.ts +1 -1
  29. package/dist/types/relay/operation.d.ts +9 -0
  30. package/dist/types/relay/sqlite-migrations.d.ts +21 -1
  31. package/dist/types/runtime/agent/agent-loop-events.d.ts +10 -9
  32. package/dist/types/runtime/agent/agent-loop-service.d.ts +1 -0
  33. package/dist/types/runtime/agent/emission-ordinal-allocator.d.ts +7 -0
  34. package/dist/types/runtime/agent/relay-permissions.d.ts +4 -7
  35. package/dist/types/runtime/agent/relay-steering.d.ts +5 -5
  36. package/dist/types/runtime/agent/relay-tool-executor.d.ts +3 -2
  37. package/dist/types/runtime/envelope/envelope-service.d.ts +2 -1
  38. package/dist/types/runtime/execution/event-log-service.d.ts +5 -4
  39. package/dist/types/runtime/execution/execution-service.d.ts +1 -1
  40. package/dist/types/runtime/inbox/inbox-service.d.ts +6 -6
  41. package/dist/types/runtime/schedule/scheduler-service.d.ts +3 -4
  42. package/dist/types/runtime/state/execution-state-service.d.ts +2 -2
  43. package/dist/types/runtime/tool/tool-runtime-contract.d.ts +2 -0
  44. package/dist/types/runtime/tool/tool-runtime-identifiers.d.ts +6 -0
  45. package/dist/types/runtime/wait/wait-service.d.ts +5 -5
  46. package/dist/types/runtime/workflow/execution-workflow.d.ts +2 -3
  47. package/dist/types/runtime/workspace/workspace-planner-service.d.ts +2 -0
  48. package/dist/types/schema/workflow-schema.d.ts +1 -0
  49. package/dist/types/store-sql/execution/archive-compression.d.ts +11 -0
  50. package/dist/types/store-sql/execution/event-history-file-system.d.ts +7 -0
  51. package/dist/types/store-sql/execution/event-history-store.d.ts +93 -0
  52. package/dist/types/store-sql/execution/execution-event-archive-codec.d.ts +69 -0
  53. package/dist/types/store-sql/execution/execution-event-archive-repository-memory.d.ts +28 -0
  54. package/dist/types/store-sql/execution/execution-event-archive-repository-sql.d.ts +19 -0
  55. package/dist/types/store-sql/execution/execution-event-archive-repository.d.ts +175 -0
  56. package/dist/types/store-sql/execution/execution-event-head-memory.d.ts +13 -0
  57. package/dist/types/store-sql/execution/execution-event-head.d.ts +40 -0
  58. package/dist/types/store-sql/execution/execution-event-identity-directory.d.ts +26 -0
  59. package/dist/types/store-sql/execution/execution-event-repository-archive-aware.d.ts +7 -0
  60. package/dist/types/store-sql/execution/execution-event-repository-memory.d.ts +6 -1
  61. package/dist/types/store-sql/execution/execution-event-repository.d.ts +6 -4
  62. package/dist/types/store-sql/inbox/inbox-repository.d.ts +6 -2
  63. package/dist/types/store-sql/schema/communication-schema.d.ts +15 -0
  64. package/dist/types/store-sql/schema/execution-schema.d.ts +583 -0
  65. package/dist/types/store-sql/schema/relay-schema.d.ts +1 -1
  66. package/dist/types/store-sql/state/execution-state-repository.d.ts +2 -1
  67. package/dist/types/store-sql/steering/steering-model.d.ts +60 -0
  68. package/dist/types/store-sql/steering/steering-repository.d.ts +5 -50
  69. package/package.json +3 -3
  70. package/dist/types/relay/client-event-sequence.d.ts +0 -3
  71. package/dist/types/runtime/agent/sequence-allocator.d.ts +0 -9
package/dist/mysql.js CHANGED
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-m7dpw880.js";
5
+ } from "./index-skcp0xvt.js";
6
6
  import {
7
7
  MigratorError,
8
8
  RuntimeMigrationError,
9
9
  SqlFailure
10
- } from "./index-gwgea1te.js";
10
+ } from "./index-d1je4njg.js";
11
11
  import"./index-d5563j6w.js";
12
- import"./index-nb078xsy.js";
12
+ import"./index-j8k41y47.js";
13
13
  import"./index-nb39b5ae.js";
14
14
 
15
15
  // src/mysql.ts
@@ -97,6 +97,18 @@ ALTER TABLE relay_sessions ADD COLUMN owner_epoch BIGINT NOT NULL DEFAULT 0;
97
97
  ALTER TABLE relay_sessions ADD COLUMN owner_released BOOLEAN NOT NULL DEFAULT TRUE;
98
98
  `;
99
99
 
100
+ // ../../migrations/mysql/0015_transactional_event_head.sql
101
+ var _0015_transactional_event_head_default = "ALTER TABLE `relay_execution_events`\n MODIFY `id` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,\n MODIFY `cursor` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;\n--> statement-breakpoint\nCREATE TABLE IF NOT EXISTS `relay_execution_event_heads` (\n\t`tenant_id` VARCHAR(191) NOT NULL DEFAULT 'system',\n\t`execution_id` VARCHAR(191) NOT NULL,\n\t`next_sequence` INT NOT NULL DEFAULT 0,\n\t`max_sequence` INT NULL,\n\t`event_count` INT NOT NULL DEFAULT 0,\n\t`usage_tokens` BIGINT NOT NULL DEFAULT 0,\n\tCONSTRAINT `pk_relay_execution_event_heads` PRIMARY KEY (`tenant_id`, `execution_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n--> statement-breakpoint\n-- Relay pins this migration to one reserved connection. These WRITE locks\n-- block legacy execution creation and event appends until every head has been\n-- backfilled and migration 15 is recorded. The runner guarantees UNLOCK TABLES\n-- on success or failure.\nLOCK TABLES\n `relay_executions` WRITE,\n `relay_execution_events` WRITE,\n `relay_execution_event_heads` WRITE,\n `relay_migrations` WRITE;\n--> statement-breakpoint\nDELETE FROM `relay_execution_event_heads`;\n--> statement-breakpoint\nINSERT INTO `relay_execution_event_heads` (`tenant_id`, `execution_id`, `next_sequence`, `max_sequence`, `event_count`, `usage_tokens`)\nSELECT `relay_executions`.`tenant_id`, `relay_executions`.`id`, COALESCE(MAX(`relay_execution_events`.`sequence`) + 1, 0), MAX(`relay_execution_events`.`sequence`), COUNT(`relay_execution_events`.`id`), COALESCE(SUM(CASE WHEN `relay_execution_events`.`type` = 'model.usage.reported' THEN COALESCE(CAST(JSON_EXTRACT(`relay_execution_events`.`data_json`, '$.input_tokens') AS SIGNED), 0) + COALESCE(CAST(JSON_EXTRACT(`relay_execution_events`.`data_json`, '$.output_tokens') AS SIGNED), 0) ELSE 0 END), 0)\nFROM `relay_executions`\nLEFT JOIN `relay_execution_events`\n ON `relay_execution_events`.`tenant_id` = `relay_executions`.`tenant_id` AND `relay_execution_events`.`execution_id` = `relay_executions`.`id`\nGROUP BY `relay_executions`.`tenant_id`, `relay_executions`.`id`;\n";
102
+
103
+ // ../../migrations/mysql/0016_execution_event_archive_manifests.sql
104
+ var _0016_execution_event_archive_manifests_default = "ALTER TABLE `relay_execution_event_heads`\n ADD COLUMN `archived_through` INT NULL;\n--> statement-breakpoint\nALTER TABLE `relay_execution_event_heads`\n ADD COLUMN `archive_generation` INT NULL;\n--> statement-breakpoint\nALTER TABLE `relay_execution_event_heads`\n ADD CONSTRAINT `ck_relay_execution_event_heads_archive_pointer`\n CHECK ((`archived_through` IS NULL) = (`archive_generation` IS NULL));\n--> statement-breakpoint\nCREATE TABLE IF NOT EXISTS `relay_execution_event_archive_manifests` (\n\t`tenant_id` VARCHAR(191) NOT NULL DEFAULT 'system',\n\t`execution_id` VARCHAR(191) NOT NULL,\n\t`generation` INT NOT NULL,\n\t`archived_through` INT NOT NULL,\n\t`event_count` INT NOT NULL,\n\t`max_sequence` INT NOT NULL,\n\t`usage_tokens` BIGINT NOT NULL,\n\t`schema_version` INT NOT NULL,\n\tCONSTRAINT `pk_relay_execution_event_archive_manifests` PRIMARY KEY (`tenant_id`, `execution_id`, `generation`),\n\tCONSTRAINT `fk_relay_execution_event_archive_manifests_execution` FOREIGN KEY (`tenant_id`, `execution_id`) REFERENCES `relay_executions` (`tenant_id`, `id`),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_generation` CHECK (`generation` > 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_frontier` CHECK (`archived_through` >= 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_count` CHECK (`event_count` > 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_max` CHECK (`max_sequence` = `archived_through`),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_gaps` CHECK (`event_count` <= `archived_through` + 1),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_usage` CHECK (`usage_tokens` >= 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_manifests_schema` CHECK (`schema_version` = 1)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n--> statement-breakpoint\nCREATE TABLE IF NOT EXISTS `relay_execution_event_archive_blocks` (\n\t`tenant_id` VARCHAR(191) NOT NULL DEFAULT 'system',\n\t`execution_id` VARCHAR(191) NOT NULL,\n\t`generation` INT NOT NULL,\n\t`block_index` INT NOT NULL,\n\t`first_sequence` INT NOT NULL,\n\t`last_sequence` INT NOT NULL,\n\t`event_count` INT NOT NULL,\n\t`object_key` VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,\n\t`object_checksum` CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,\n\t`object_size` INT NOT NULL,\n\t`codec_version` INT NOT NULL,\n\t`encoding` VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,\n\t`compression` VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,\n\t`payload_checksum` CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,\n\t`stored_payload_bytes` INT NOT NULL,\n\t`uncompressed_bytes` INT NOT NULL,\n\tCONSTRAINT `pk_relay_execution_event_archive_blocks` PRIMARY KEY (`tenant_id`, `execution_id`, `generation`, `block_index`),\n\tCONSTRAINT `fk_relay_execution_event_archive_blocks_manifest` FOREIGN KEY (`tenant_id`, `execution_id`, `generation`) REFERENCES `relay_execution_event_archive_manifests` (`tenant_id`, `execution_id`, `generation`),\n\tCONSTRAINT `uq_relay_execution_event_archive_blocks_first` UNIQUE (`tenant_id`, `execution_id`, `generation`, `first_sequence`),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_index` CHECK (`block_index` >= 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_first` CHECK (`first_sequence` >= 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_bounds` CHECK (`last_sequence` >= `first_sequence`),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_count` CHECK (`event_count` > 0),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_count_limit` CHECK (`event_count` <= 4096),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_gaps` CHECK (`event_count` <= `last_sequence` - `first_sequence` + 1),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_object_size` CHECK (`object_size` > 0 AND `object_size` <= 16777216),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_stored_payload_size` CHECK (`stored_payload_bytes` > 0 AND `stored_payload_bytes` <= 15728640),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_uncompressed_size` CHECK (`uncompressed_bytes` > 0 AND `uncompressed_bytes` <= 15728640),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_stored_size` CHECK (`stored_payload_bytes` < `object_size`),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_expansion` CHECK (`stored_payload_bytes` <= `uncompressed_bytes`),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_codec` CHECK (`codec_version` IN (1, 2)),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_encoding` CHECK (`encoding` = 'json'),\n\tCONSTRAINT `ck_relay_execution_event_archive_blocks_compression` CHECK ((`codec_version` = 1 AND `compression` = 'none' AND `stored_payload_bytes` = `uncompressed_bytes`) OR (`codec_version` = 2 AND `compression` = 'gzip'))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n";
105
+
106
+ // ../../migrations/mysql/0017_execution_event_identity_directory.sql
107
+ var _0017_execution_event_identity_directory_default = "CREATE TABLE IF NOT EXISTS `relay_execution_event_identity_directory` (\n `tenant_id` varchar(191) NOT NULL,\n `cursor` varchar(512) COLLATE utf8mb4_bin NOT NULL,\n `event_id` varchar(512) COLLATE utf8mb4_bin NOT NULL,\n `execution_id` varchar(191) NOT NULL,\n `sequence` int NOT NULL,\n CONSTRAINT `pk_relay_execution_event_identity_directory` PRIMARY KEY (`tenant_id`, `cursor`),\n CONSTRAINT `uq_relay_execution_event_identity_directory_event` UNIQUE (`tenant_id`, `event_id`),\n CONSTRAINT `uq_relay_execution_event_identity_directory_sequence` UNIQUE (`tenant_id`, `execution_id`, `sequence`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n--> statement-breakpoint\nLOCK TABLES\n `relay_execution_events` WRITE,\n `relay_execution_event_identity_directory` WRITE,\n `relay_migrations` WRITE;\n--> statement-breakpoint\nDELETE FROM `relay_execution_event_identity_directory`;\n--> statement-breakpoint\nINSERT INTO `relay_execution_event_identity_directory` (`tenant_id`, `cursor`, `event_id`, `execution_id`, `sequence`)\nSELECT `tenant_id`, `cursor`, `id`, `execution_id`, `sequence` FROM `relay_execution_events`;\n";
108
+
109
+ // ../../migrations/mysql/0018_idempotent_steering.sql
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
+
100
112
  // src/mysql-migrations.ts
101
113
  var migrations = [
102
114
  [1, "baseline", _0001_baseline_default],
@@ -112,7 +124,11 @@ var migrations = [
112
124
  [11, "execution_scoped_tool_calls", _0011_execution_scoped_tool_calls_default],
113
125
  [12, "rename_entity_to_resident", _0012_rename_entity_to_resident_default],
114
126
  [13, "steering_delivered", _0013_steering_delivered_default],
115
- [14, "session_writer_ownership", _0014_session_writer_ownership_default]
127
+ [14, "session_writer_ownership", _0014_session_writer_ownership_default],
128
+ [15, "transactional_event_head", _0015_transactional_event_head_default],
129
+ [16, "execution_event_archive_manifests", _0016_execution_event_archive_manifests_default],
130
+ [17, "execution_event_identity_directory", _0017_execution_event_identity_directory_default],
131
+ [18, "idempotent_steering", _0018_idempotent_steering_default]
116
132
  ];
117
133
 
118
134
  // src/mysql.ts
@@ -145,10 +161,35 @@ var runMigrations = Effect.gen(function* () {
145
161
  });
146
162
  }
147
163
  for (const [id, name, source] of migrations.slice(current.length)) {
148
- for (const statement of source.split("--> statement-breakpoint").map((value) => value.trim()).filter(Boolean)) {
149
- yield* sql.unsafe(statement);
150
- }
151
- yield* sql`INSERT INTO relay_migrations (migration_id, name) VALUES (${id}, ${name})`;
164
+ const statements = source.split("--> statement-breakpoint").map((value) => value.trim()).filter(Boolean);
165
+ yield* Effect.scoped(Effect.gen(function* () {
166
+ const connection = yield* sql.reserve;
167
+ return yield* Effect.gen(function* () {
168
+ const migration = yield* Effect.exit(Effect.gen(function* () {
169
+ for (const statement of statements) {
170
+ if (id === 16) {
171
+ const catalogQuery = statement.includes("ADD COLUMN") ? [
172
+ "SELECT COUNT(*) AS count FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'relay_execution_event_heads' AND column_name = ?",
173
+ [statement.includes("`archived_through`") ? "archived_through" : "archive_generation"]
174
+ ] : statement.includes("ADD CONSTRAINT") ? [
175
+ "SELECT COUNT(*) AS count FROM information_schema.table_constraints WHERE constraint_schema = DATABASE() AND table_name = 'relay_execution_event_heads' AND constraint_name = ?",
176
+ ["ck_relay_execution_event_heads_archive_pointer"]
177
+ ] : undefined;
178
+ if (catalogQuery !== undefined) {
179
+ const present = yield* connection.execute(catalogQuery[0], catalogQuery[1], undefined);
180
+ if (Number(present[0]?.count ?? 0) === 1) {
181
+ continue;
182
+ }
183
+ }
184
+ }
185
+ yield* connection.executeUnprepared(statement, [], undefined);
186
+ }
187
+ yield* connection.execute("INSERT INTO relay_migrations (migration_id, name) VALUES (?, ?)", [id, name], undefined);
188
+ }));
189
+ yield* connection.executeUnprepared("UNLOCK TABLES", [], undefined);
190
+ return yield* migration;
191
+ }).pipe(Effect.uninterruptible);
192
+ }));
152
193
  }
153
194
  });
154
195
  var database2 = (options) => database({
package/dist/postgres.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-m7dpw880.js";
5
+ } from "./index-skcp0xvt.js";
6
6
  import {
7
7
  Dialect,
8
8
  RuntimeMigrationError,
@@ -14,11 +14,11 @@ import {
14
14
  fromDbTimestamp,
15
15
  fromNullableDbTimestamp,
16
16
  timestampParam
17
- } from "./index-gwgea1te.js";
17
+ } from "./index-d1je4njg.js";
18
18
  import"./index-d5563j6w.js";
19
19
  import {
20
20
  exports_ids_schema
21
- } from "./index-nb078xsy.js";
21
+ } from "./index-j8k41y47.js";
22
22
  import {
23
23
  __export
24
24
  } from "./index-nb39b5ae.js";
@@ -294,7 +294,21 @@ var relayPermissionRules = pgTable4("relay_permission_rules", {
294
294
  index2("idx_relay_permission_rules_agent_scope").on(table.tenantId, table.agent, table.scope)
295
295
  ]);
296
296
  // ../store-sql/src/schema/execution-schema.ts
297
- import { boolean as boolean2, index as index3, integer as integer4, jsonb as jsonb5, pgTable as pgTable5, primaryKey as primaryKey5, text as text6, timestamp as timestamp5, uniqueIndex as uniqueIndex3 } from "drizzle-orm/pg-core";
297
+ import {
298
+ bigint,
299
+ boolean as boolean2,
300
+ check as check2,
301
+ foreignKey,
302
+ index as index3,
303
+ integer as integer4,
304
+ jsonb as jsonb5,
305
+ pgTable as pgTable5,
306
+ primaryKey as primaryKey5,
307
+ text as text6,
308
+ timestamp as timestamp5,
309
+ uniqueIndex as uniqueIndex3
310
+ } from "drizzle-orm/pg-core";
311
+ import { sql as sql2 } from "drizzle-orm";
298
312
  var relayExecutionState = pgTable5("relay_execution_state", {
299
313
  tenantId: tenantId(),
300
314
  executionId: text6("execution_id").$type().notNull(),
@@ -395,6 +409,96 @@ var relayChildFanOutMembers = pgTable5("relay_child_fan_out_members", {
395
409
  }),
396
410
  uniqueIndex3("uq_relay_child_fan_out_member_ordinal").on(table.tenantId, table.fanOutId, table.ordinal)
397
411
  ]);
412
+ var relayExecutionEventHeads = pgTable5("relay_execution_event_heads", {
413
+ tenantId: tenantId(),
414
+ executionId: text6("execution_id").$type().notNull(),
415
+ nextSequence: integer4("next_sequence").notNull().default(0),
416
+ maxSequence: integer4("max_sequence"),
417
+ eventCount: integer4("event_count").notNull().default(0),
418
+ usageTokens: bigint("usage_tokens", { mode: "number" }).notNull().default(0),
419
+ archivedThrough: integer4("archived_through"),
420
+ archiveGeneration: integer4("archive_generation")
421
+ }, (table) => [
422
+ primaryKey5({ columns: [table.tenantId, table.executionId], name: "pk_relay_execution_event_heads" }),
423
+ check2("ck_relay_execution_event_heads_archive_pointer", sql2`(${table.archivedThrough} IS NULL) = (${table.archiveGeneration} IS NULL)`)
424
+ ]);
425
+ var relayExecutionEventArchiveManifests = pgTable5("relay_execution_event_archive_manifests", {
426
+ tenantId: tenantId(),
427
+ executionId: text6("execution_id").$type().notNull(),
428
+ generation: integer4("generation").notNull(),
429
+ archivedThrough: integer4("archived_through").notNull(),
430
+ eventCount: integer4("event_count").notNull(),
431
+ maxSequence: integer4("max_sequence").notNull(),
432
+ usageTokens: bigint("usage_tokens", { mode: "number" }).notNull(),
433
+ schemaVersion: integer4("schema_version").notNull()
434
+ }, (table) => [
435
+ primaryKey5({
436
+ columns: [table.tenantId, table.executionId, table.generation],
437
+ name: "pk_relay_execution_event_archive_manifests"
438
+ }),
439
+ foreignKey({
440
+ columns: [table.tenantId, table.executionId],
441
+ foreignColumns: [relayExecutions.tenantId, relayExecutions.id],
442
+ name: "fk_relay_execution_event_archive_manifests_execution"
443
+ }),
444
+ check2("ck_relay_execution_event_archive_manifests_generation", sql2`${table.generation} > 0`),
445
+ check2("ck_relay_execution_event_archive_manifests_frontier", sql2`${table.archivedThrough} >= 0`),
446
+ check2("ck_relay_execution_event_archive_manifests_count", sql2`${table.eventCount} > 0`),
447
+ check2("ck_relay_execution_event_archive_manifests_max", sql2`${table.maxSequence} = ${table.archivedThrough}`),
448
+ check2("ck_relay_execution_event_archive_manifests_gaps", sql2`${table.eventCount} <= ${table.archivedThrough} + 1`),
449
+ check2("ck_relay_execution_event_archive_manifests_usage", sql2`${table.usageTokens} >= 0`),
450
+ check2("ck_relay_execution_event_archive_manifests_schema", sql2`${table.schemaVersion} = 1`)
451
+ ]);
452
+ var relayExecutionEventArchiveBlocks = pgTable5("relay_execution_event_archive_blocks", {
453
+ tenantId: tenantId(),
454
+ executionId: text6("execution_id").$type().notNull(),
455
+ generation: integer4("generation").notNull(),
456
+ blockIndex: integer4("block_index").notNull(),
457
+ firstSequence: integer4("first_sequence").notNull(),
458
+ lastSequence: integer4("last_sequence").notNull(),
459
+ eventCount: integer4("event_count").notNull(),
460
+ objectKey: text6("object_key").notNull(),
461
+ objectChecksum: text6("object_checksum").notNull(),
462
+ objectSize: integer4("object_size").notNull(),
463
+ codecVersion: integer4("codec_version").notNull(),
464
+ encoding: text6("encoding").notNull(),
465
+ compression: text6("compression").notNull(),
466
+ payloadChecksum: text6("payload_checksum").notNull(),
467
+ storedPayloadBytes: integer4("stored_payload_bytes").notNull(),
468
+ uncompressedBytes: integer4("uncompressed_bytes").notNull()
469
+ }, (table) => [
470
+ primaryKey5({
471
+ columns: [table.tenantId, table.executionId, table.generation, table.blockIndex],
472
+ name: "pk_relay_execution_event_archive_blocks"
473
+ }),
474
+ foreignKey({
475
+ columns: [table.tenantId, table.executionId, table.generation],
476
+ foreignColumns: [
477
+ relayExecutionEventArchiveManifests.tenantId,
478
+ relayExecutionEventArchiveManifests.executionId,
479
+ relayExecutionEventArchiveManifests.generation
480
+ ],
481
+ name: "fk_relay_execution_event_archive_blocks_manifest"
482
+ }),
483
+ uniqueIndex3("uq_relay_execution_event_archive_blocks_first").on(table.tenantId, table.executionId, table.generation, table.firstSequence),
484
+ check2("ck_relay_execution_event_archive_blocks_index", sql2`${table.blockIndex} >= 0`),
485
+ check2("ck_relay_execution_event_archive_blocks_first", sql2`${table.firstSequence} >= 0`),
486
+ check2("ck_relay_execution_event_archive_blocks_bounds", sql2`${table.lastSequence} >= ${table.firstSequence}`),
487
+ check2("ck_relay_execution_event_archive_blocks_count", sql2`${table.eventCount} > 0`),
488
+ check2("ck_relay_execution_event_archive_blocks_count_limit", sql2`${table.eventCount} <= 4096`),
489
+ check2("ck_relay_execution_event_archive_blocks_gaps", sql2`${table.eventCount} <= ${table.lastSequence} - ${table.firstSequence} + 1`),
490
+ check2("ck_relay_execution_event_archive_blocks_object_size", sql2`${table.objectSize} > 0 AND ${table.objectSize} <= 16777216`),
491
+ check2("ck_relay_execution_event_archive_blocks_stored_payload_size", sql2`${table.storedPayloadBytes} > 0 AND ${table.storedPayloadBytes} <= 15728640`),
492
+ check2("ck_relay_execution_event_archive_blocks_uncompressed_size", sql2`${table.uncompressedBytes} > 0 AND ${table.uncompressedBytes} <= 15728640`),
493
+ check2("ck_relay_execution_event_archive_blocks_stored_size", sql2`${table.storedPayloadBytes} < ${table.objectSize}`),
494
+ check2("ck_relay_execution_event_archive_blocks_expansion", sql2`${table.storedPayloadBytes} <= ${table.uncompressedBytes}`),
495
+ check2("ck_relay_execution_event_archive_blocks_codec", sql2`${table.codecVersion} IN (1, 2)`),
496
+ check2("ck_relay_execution_event_archive_blocks_encoding", sql2`${table.encoding} = 'json'`),
497
+ check2("ck_relay_execution_event_archive_blocks_compression", sql2`(${table.codecVersion} = 1 AND ${table.compression} = 'none' AND ${table.storedPayloadBytes} = ${table.uncompressedBytes}) OR (${table.codecVersion} = 2 AND ${table.compression} = 'gzip')`),
498
+ check2("ck_relay_execution_event_archive_blocks_object_key", sql2`length(${table.objectKey}) <= 80`),
499
+ check2("ck_relay_execution_event_archive_blocks_checksum", sql2`length(${table.objectChecksum}) = 64`),
500
+ check2("ck_relay_execution_event_archive_blocks_payload_checksum", sql2`length(${table.payloadChecksum}) = 64`)
501
+ ]);
398
502
  var relayExecutionEvents = pgTable5("relay_execution_events", {
399
503
  tenantId: tenantId(),
400
504
  id: text6("id").$type().notNull(),
@@ -412,11 +516,23 @@ var relayExecutionEvents = pgTable5("relay_execution_events", {
412
516
  uniqueIndex3("uq_relay_execution_events_sequence").on(table.tenantId, table.executionId, table.sequence),
413
517
  uniqueIndex3("uq_relay_execution_events_cursor").on(table.tenantId, table.cursor)
414
518
  ]);
519
+ var relayExecutionEventIdentityDirectory = pgTable5("relay_execution_event_identity_directory", {
520
+ tenantId: tenantId(),
521
+ cursor: text6("cursor").notNull(),
522
+ eventId: text6("event_id").$type().notNull(),
523
+ executionId: text6("execution_id").$type().notNull(),
524
+ sequence: integer4("sequence").notNull()
525
+ }, (table) => [
526
+ primaryKey5({ columns: [table.tenantId, table.cursor], name: "pk_relay_execution_event_identity_directory" }),
527
+ uniqueIndex3("uq_relay_execution_event_identity_directory_event").on(table.tenantId, table.eventId),
528
+ uniqueIndex3("uq_relay_execution_event_identity_directory_sequence").on(table.tenantId, table.executionId, table.sequence)
529
+ ]);
415
530
  // ../store-sql/src/schema/communication-schema.ts
416
531
  import { index as index4, integer as integer5, jsonb as jsonb6, pgTable as pgTable6, primaryKey as primaryKey6, text as text7, timestamp as timestamp6, uniqueIndex as uniqueIndex4 } from "drizzle-orm/pg-core";
417
532
  var relaySteeringMessages = pgTable6("relay_steering_messages", {
418
533
  tenantId: tenantId(),
419
534
  executionId: text7("execution_id").notNull(),
535
+ idempotencyKey: text7("idempotency_key").notNull(),
420
536
  kind: text7("kind").notNull(),
421
537
  sequence: integer5("sequence").notNull(),
422
538
  contentJson: jsonb6("content_json").$type().notNull(),
@@ -428,6 +544,7 @@ var relaySteeringMessages = pgTable6("relay_steering_messages", {
428
544
  columns: [table.tenantId, table.executionId, table.kind, table.sequence],
429
545
  name: "pk_relay_steering_messages"
430
546
  }),
547
+ uniqueIndex4("uq_relay_steering_messages_idempotency").on(table.tenantId, table.executionId, table.idempotencyKey),
431
548
  index4("idx_relay_steering_messages_unconsumed").on(table.tenantId, table.executionId, table.kind, table.consumedAt, table.sequence),
432
549
  index4("idx_relay_steering_messages_drain").on(table.tenantId, table.executionId, table.kind, table.drainId, table.sequence)
433
550
  ]);
@@ -487,14 +604,14 @@ var relayTopicSubscriptions = pgTable6("relay_topic_subscriptions", {
487
604
  index4("idx_relay_topic_subscriptions_subscriber").on(table.tenantId, table.subscriberExecutionId)
488
605
  ]);
489
606
  // ../store-sql/src/schema/session-schema.ts
490
- import { bigint, boolean as boolean3, index as index5, jsonb as jsonb7, pgTable as pgTable7, primaryKey as primaryKey7, text as text8, timestamp as timestamp7 } from "drizzle-orm/pg-core";
607
+ import { bigint as bigint2, boolean as boolean3, index as index5, jsonb as jsonb7, pgTable as pgTable7, primaryKey as primaryKey7, text as text8, timestamp as timestamp7 } from "drizzle-orm/pg-core";
491
608
  var relaySessions = pgTable7("relay_sessions", {
492
609
  tenantId: tenantId(),
493
610
  id: text8("id").$type().notNull(),
494
611
  rootAddressId: text8("root_address_id").$type().notNull(),
495
612
  leafEntryId: text8("leaf_entry_id").$type(),
496
613
  ownerExecutionId: text8("owner_execution_id").$type(),
497
- ownerEpoch: bigint("owner_epoch", { mode: "number" }).notNull().default(0),
614
+ ownerEpoch: bigint2("owner_epoch", { mode: "number" }).notNull().default(0),
498
615
  ownerReleased: boolean3("owner_released").notNull().default(true),
499
616
  metadataJson: jsonb7("metadata_json").$type().notNull().default({}),
500
617
  createdAt: timestamp7("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -588,7 +705,7 @@ var relayRouteAttempts = pgTable8("relay_route_attempts", {
588
705
  ]);
589
706
  // ../store-sql/src/schema/workspace-schema.ts
590
707
  import { index as index7, jsonb as jsonb9, pgTable as pgTable9, primaryKey as primaryKey9, text as text10, timestamp as timestamp9, uniqueIndex as uniqueIndex6 } from "drizzle-orm/pg-core";
591
- import { sql as sql2 } from "drizzle-orm";
708
+ import { sql as sql3 } from "drizzle-orm";
592
709
  var relayWorkspaceLeases = pgTable9("relay_workspace_leases", {
593
710
  tenantId: tenantId(),
594
711
  id: text10("id").$type().notNull(),
@@ -605,7 +722,7 @@ var relayWorkspaceLeases = pgTable9("relay_workspace_leases", {
605
722
  updatedAt: timestamp9("updated_at", { withTimezone: true }).notNull().defaultNow()
606
723
  }, (table) => [
607
724
  primaryKey9({ columns: [table.tenantId, table.id], name: "pk_relay_workspace_leases" }),
608
- uniqueIndex6("uq_relay_workspace_leases_active_execution").on(table.tenantId, table.executionId).where(sql2`${table.status} not in ('released', 'failed')`),
725
+ uniqueIndex6("uq_relay_workspace_leases_active_execution").on(table.tenantId, table.executionId).where(sql3`${table.status} not in ('released', 'failed')`),
609
726
  index7("idx_relay_workspace_leases_execution").on(table.tenantId, table.executionId),
610
727
  index7("idx_relay_workspace_leases_status_updated").on(table.tenantId, table.status, table.updatedAt)
611
728
  ]);
@@ -748,7 +865,8 @@ var relayIdempotencyKeys = pgTable13("relay_idempotency_keys", {
748
865
  uniqueIndex9("uq_relay_idempotency_scope_operation_key").on(table.tenantId, table.scope, table.operation, table.key)
749
866
  ]);
750
867
  // src/postgres.ts
751
- var schemaHead = "20260721170000_session_writer_ownership";
868
+ var priorSchemaHead = "20260724120000_execution_event_identity_directory";
869
+ var schemaHead = "20260724230000_idempotent_steering";
752
870
  var migrationNames = [
753
871
  "20260701002839_sour_cerebro",
754
872
  "20260701041134_acoustic_hulk",
@@ -778,13 +896,17 @@ var migrationNames = [
778
896
  "20260718140000_execution_scoped_tool_calls",
779
897
  "20260719120000_rename_entity_to_resident",
780
898
  "20260721120000_steering_delivered",
899
+ "20260721170000_session_writer_ownership",
900
+ "20260723190000_transactional_event_head",
901
+ "20260724010000_execution_event_archive_manifests",
902
+ priorSchemaHead,
781
903
  schemaHead
782
904
  ];
783
905
  var migrationsFolderUrl = import.meta.url.endsWith("/src/postgres.ts") ? new URL("../../../migrations/pg", import.meta.url) : new URL("./migrations/pg", import.meta.url);
784
906
  var migrationsFolder = fileURLToPath(migrationsFolderUrl);
785
907
  var verifySchema = Effect2.gen(function* () {
786
- const sql3 = yield* SqlClient;
787
- const rows = yield* sql3`SELECT name FROM drizzle.__drizzle_migrations ORDER BY id`;
908
+ const sql4 = yield* SqlClient;
909
+ const rows = yield* sql4`SELECT name FROM drizzle.__drizzle_migrations ORDER BY id`;
788
910
  const actual = rows.map((row) => row.name).join(",");
789
911
  const expected = migrationNames.join(",");
790
912
  if (actual !== expected) {
@@ -797,8 +919,8 @@ var verifySchema = Effect2.gen(function* () {
797
919
  }
798
920
  }).pipe((effect) => normalizeMigrationCause(effect, "pg", "verify"));
799
921
  var runMigrations = normalizeMigrationCause(Effect2.gen(function* () {
800
- const sql3 = yield* SqlClient;
801
- const pg = sql3;
922
+ const sql4 = yield* SqlClient;
923
+ const pg = sql4;
802
924
  const database2 = yield* makeWithDefaults2().pipe(Effect2.provideService(PgClient2, pg));
803
925
  yield* runDrizzleMigrator(database2, { migrationsFolder });
804
926
  }), "pg", "apply");
package/dist/sqlite.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-m7dpw880.js";
5
+ } from "./index-skcp0xvt.js";
6
6
  import {
7
7
  DatabaseAlreadyOwned,
8
8
  RuntimeConfigurationError,
@@ -12,9 +12,9 @@ import {
12
12
  make,
13
13
  makeDatabaseIdentity,
14
14
  runtimeLayer
15
- } from "./index-gwgea1te.js";
15
+ } from "./index-d1je4njg.js";
16
16
  import"./index-d5563j6w.js";
17
- import"./index-nb078xsy.js";
17
+ import"./index-j8k41y47.js";
18
18
  import"./index-nb39b5ae.js";
19
19
 
20
20
  // src/sqlite-runtime.ts
@@ -682,6 +682,103 @@ ALTER TABLE "relay_sessions" ADD COLUMN "owner_epoch" INTEGER NOT NULL DEFAULT 0
682
682
  ALTER TABLE "relay_sessions" ADD COLUMN "owner_released" INTEGER NOT NULL DEFAULT 1;
683
683
  `;
684
684
 
685
+ // ../../migrations/sqlite/0015_transactional_event_head.sql
686
+ var _0015_transactional_event_head_default = `CREATE TABLE "relay_execution_event_heads" (
687
+ "tenant_id" TEXT NOT NULL DEFAULT 'system',
688
+ "execution_id" TEXT NOT NULL,
689
+ "next_sequence" INTEGER NOT NULL DEFAULT 0,
690
+ "max_sequence" INTEGER,
691
+ "event_count" INTEGER NOT NULL DEFAULT 0,
692
+ "usage_tokens" INTEGER NOT NULL DEFAULT 0,
693
+ CONSTRAINT "pk_relay_execution_event_heads" PRIMARY KEY ("tenant_id", "execution_id")
694
+ );
695
+ --> statement-breakpoint
696
+ INSERT INTO "relay_execution_event_heads" ("tenant_id", "execution_id", "next_sequence", "max_sequence", "event_count", "usage_tokens")
697
+ SELECT execution."tenant_id", execution."id", COALESCE(MAX(event."sequence") + 1, 0), MAX(event."sequence"), COUNT(event."id"),
698
+ COALESCE(SUM(CASE WHEN event."type" = 'model.usage.reported' AND json_valid(event."data_json") THEN
699
+ CASE WHEN json_type(event."data_json", '$.input_tokens') IN ('integer', 'real')
700
+ THEN CAST(json_extract(event."data_json", '$.input_tokens') AS INTEGER) ELSE 0 END +
701
+ CASE WHEN json_type(event."data_json", '$.output_tokens') IN ('integer', 'real')
702
+ THEN CAST(json_extract(event."data_json", '$.output_tokens') AS INTEGER) ELSE 0 END
703
+ ELSE 0 END), 0)
704
+ FROM "relay_executions" execution
705
+ LEFT JOIN "relay_execution_events" event
706
+ ON event."tenant_id" = execution."tenant_id" AND event."execution_id" = execution."id"
707
+ GROUP BY execution."tenant_id", execution."id";
708
+ `;
709
+
710
+ // ../../migrations/sqlite/0016_execution_event_archive_manifests.sql
711
+ var _0016_execution_event_archive_manifests_default = `ALTER TABLE "relay_execution_event_heads" ADD COLUMN "archived_through" INTEGER;
712
+ --> statement-breakpoint
713
+ ALTER TABLE "relay_execution_event_heads" ADD COLUMN "archive_generation" INTEGER;
714
+ --> statement-breakpoint
715
+ CREATE TABLE "relay_execution_event_archive_manifests" (
716
+ "tenant_id" TEXT NOT NULL DEFAULT 'system',
717
+ "execution_id" TEXT NOT NULL,
718
+ "generation" INTEGER NOT NULL CHECK ("generation" > 0),
719
+ "archived_through" INTEGER NOT NULL CHECK ("archived_through" >= 0),
720
+ "event_count" INTEGER NOT NULL CHECK ("event_count" > 0),
721
+ "max_sequence" INTEGER NOT NULL,
722
+ "usage_tokens" INTEGER NOT NULL CHECK ("usage_tokens" >= 0),
723
+ "schema_version" INTEGER NOT NULL CHECK ("schema_version" = 1),
724
+ CONSTRAINT "pk_relay_execution_event_archive_manifests" PRIMARY KEY ("tenant_id", "execution_id", "generation"),
725
+ CONSTRAINT "fk_relay_execution_event_archive_manifests_execution" FOREIGN KEY ("tenant_id", "execution_id") REFERENCES "relay_executions" ("tenant_id", "id"),
726
+ CONSTRAINT "ck_relay_execution_event_archive_manifests_max" CHECK ("max_sequence" = "archived_through"),
727
+ CONSTRAINT "ck_relay_execution_event_archive_manifests_gaps" CHECK ("event_count" <= "archived_through" + 1)
728
+ );
729
+ --> statement-breakpoint
730
+ CREATE TABLE "relay_execution_event_archive_blocks" (
731
+ "tenant_id" TEXT NOT NULL DEFAULT 'system',
732
+ "execution_id" TEXT NOT NULL,
733
+ "generation" INTEGER NOT NULL,
734
+ "block_index" INTEGER NOT NULL CHECK ("block_index" >= 0),
735
+ "first_sequence" INTEGER NOT NULL CHECK ("first_sequence" >= 0),
736
+ "last_sequence" INTEGER NOT NULL,
737
+ "event_count" INTEGER NOT NULL CHECK ("event_count" > 0 AND "event_count" <= 4096),
738
+ "object_key" TEXT NOT NULL CHECK (length("object_key") <= 80),
739
+ "object_checksum" TEXT NOT NULL CHECK (length("object_checksum") = 64),
740
+ "object_size" INTEGER NOT NULL CHECK ("object_size" > 0 AND "object_size" <= 16777216),
741
+ "codec_version" INTEGER NOT NULL CHECK ("codec_version" IN (1, 2)),
742
+ "encoding" TEXT NOT NULL CHECK ("encoding" = 'json'),
743
+ "compression" TEXT NOT NULL,
744
+ "payload_checksum" TEXT NOT NULL CHECK (length("payload_checksum") = 64),
745
+ "stored_payload_bytes" INTEGER NOT NULL CHECK ("stored_payload_bytes" > 0 AND "stored_payload_bytes" <= 15728640),
746
+ "uncompressed_bytes" INTEGER NOT NULL CHECK ("uncompressed_bytes" > 0 AND "uncompressed_bytes" <= 15728640),
747
+ CONSTRAINT "pk_relay_execution_event_archive_blocks" PRIMARY KEY ("tenant_id", "execution_id", "generation", "block_index"),
748
+ CONSTRAINT "fk_relay_execution_event_archive_blocks_manifest" FOREIGN KEY ("tenant_id", "execution_id", "generation") REFERENCES "relay_execution_event_archive_manifests" ("tenant_id", "execution_id", "generation"),
749
+ CONSTRAINT "ck_relay_execution_event_archive_blocks_bounds" CHECK ("last_sequence" >= "first_sequence"),
750
+ CONSTRAINT "ck_relay_execution_event_archive_blocks_gaps" CHECK ("event_count" <= "last_sequence" - "first_sequence" + 1),
751
+ CONSTRAINT "ck_relay_execution_event_archive_blocks_stored_size" CHECK ("stored_payload_bytes" < "object_size"),
752
+ CONSTRAINT "ck_relay_execution_event_archive_blocks_expansion" CHECK ("stored_payload_bytes" <= "uncompressed_bytes"),
753
+ CONSTRAINT "ck_relay_execution_event_archive_blocks_compression" CHECK (("codec_version" = 1 AND "compression" = 'none' AND "stored_payload_bytes" = "uncompressed_bytes") OR ("codec_version" = 2 AND "compression" = 'gzip')),
754
+ CONSTRAINT "uq_relay_execution_event_archive_blocks_first" UNIQUE ("tenant_id", "execution_id", "generation", "first_sequence")
755
+ );
756
+ `;
757
+
758
+ // ../../migrations/sqlite/0017_execution_event_identity_directory.sql
759
+ var _0017_execution_event_identity_directory_default = `CREATE TABLE "relay_execution_event_identity_directory" (
760
+ "tenant_id" text NOT NULL,
761
+ "cursor" text NOT NULL,
762
+ "event_id" text NOT NULL,
763
+ "execution_id" text NOT NULL,
764
+ "sequence" integer NOT NULL,
765
+ CONSTRAINT "pk_relay_execution_event_identity_directory" PRIMARY KEY("tenant_id", "cursor"),
766
+ CONSTRAINT "uq_relay_execution_event_identity_directory_event" UNIQUE("tenant_id", "event_id"),
767
+ CONSTRAINT "uq_relay_execution_event_identity_directory_sequence" UNIQUE("tenant_id", "execution_id", "sequence")
768
+ );
769
+ --> statement-breakpoint
770
+ INSERT INTO "relay_execution_event_identity_directory" ("tenant_id", "cursor", "event_id", "execution_id", "sequence")
771
+ SELECT "tenant_id", "cursor", "id", "execution_id", "sequence" FROM "relay_execution_events";
772
+ `;
773
+
774
+ // ../../migrations/sqlite/0018_idempotent_steering.sql
775
+ var _0018_idempotent_steering_default = `ALTER TABLE "relay_steering_messages" ADD COLUMN "idempotency_key" text NOT NULL DEFAULT '';
776
+ --> statement-breakpoint
777
+ UPDATE "relay_steering_messages" SET "idempotency_key" = 'relay:legacy:' || "kind" || ':' || CAST("sequence" AS text);
778
+ --> statement-breakpoint
779
+ CREATE UNIQUE INDEX "uq_relay_steering_messages_idempotency" ON "relay_steering_messages" ("tenant_id", "execution_id", "idempotency_key");
780
+ `;
781
+
685
782
  // src/sqlite-migrations.ts
686
783
  import { Effect } from "effect";
687
784
  import { SqlClient } from "effect/unstable/sql/SqlClient";
@@ -706,7 +803,21 @@ var migrations = [
706
803
  { id: 11, name: "execution_scoped_tool_calls", file: "0011_execution_scoped_tool_calls.sql", source: _0011_execution_scoped_tool_calls_default },
707
804
  { id: 12, name: "rename_entity_to_resident", file: "0012_rename_entity_to_resident.sql", source: _0012_rename_entity_to_resident_default },
708
805
  { id: 13, name: "steering_delivered", file: "0013_steering_delivered.sql", source: _0013_steering_delivered_default },
709
- { id: 14, name: "session_writer_ownership", file: "0014_session_writer_ownership.sql", source: _0014_session_writer_ownership_default }
806
+ { id: 14, name: "session_writer_ownership", file: "0014_session_writer_ownership.sql", source: _0014_session_writer_ownership_default },
807
+ { id: 15, name: "transactional_event_head", file: "0015_transactional_event_head.sql", source: _0015_transactional_event_head_default },
808
+ {
809
+ id: 16,
810
+ name: "execution_event_archive_manifests",
811
+ file: "0016_execution_event_archive_manifests.sql",
812
+ source: _0016_execution_event_archive_manifests_default
813
+ },
814
+ {
815
+ id: 17,
816
+ name: "execution_event_identity_directory",
817
+ file: "0017_execution_event_identity_directory.sql",
818
+ source: _0017_execution_event_identity_directory_default
819
+ },
820
+ { id: 18, name: "idempotent_steering", file: "0018_idempotent_steering.sql", source: _0018_idempotent_steering_default }
710
821
  ];
711
822
  var loader = Effect.succeed(migrations.map(({ id, name, source }) => [id, name, Effect.succeed(execute(source))]));
712
823
 
@@ -7,7 +7,7 @@ export declare const startExecution: (input: StartExecutionInput) => Effect.Effe
7
7
  export declare const startExecutionByAddress: (input: StartExecutionByAddressInput) => Effect.Effect<import("./operation").StartExecutionResult, ClientError | import("./client-public").ResidentNamespaceReserved, Service>;
8
8
  export declare const startExecutionByAgentDefinition: (input: StartExecutionByAgentDefinitionInput) => Effect.Effect<import("./operation").StartExecutionResult, ClientError | import("./client-public").ResidentNamespaceReserved, Service>;
9
9
  export declare const cancelExecution: (input: CancelExecutionInput) => Effect.Effect<import("./operation").CancelExecutionAccepted, ClientError, Service>;
10
- export declare const steer: (input: SteerInput) => Effect.Effect<import("./operation").SteerAccepted, ClientError, Service>;
10
+ export declare const steer: (input: SteerInput) => Effect.Effect<import("./operation").SteerAccepted, ClientError | import("./operation").SteeringIdempotencyConflict, Service>;
11
11
  export declare const getExecution: (id: Ids.ExecutionId) => Effect.Effect<Execution.Execution | undefined, ClientError, Service>;
12
12
  export declare const listExecutions: (input: ListExecutionsInput) => Effect.Effect<import("./operation").ListExecutionsResult, ClientError, Service>;
13
13
  export declare const listSessions: (input: ListSessionsInput) => Effect.Effect<import("./operation").ListSessionsResult, ClientError, Service>;
@@ -4,7 +4,7 @@ import type { Agent as BatonAgent } from "@batonfx/core";
4
4
  import { Address, Agent, ChildOrchestration, Content, Resident, Envelope, Execution, Ids, Inbox, Presence, Shared, Skill, State, Tool, Workflow } from "../schema/index";
5
5
  import { Context, Effect, Schema, Stream } from "effect";
6
6
  import type { Tool as BatonTool } from "effect/unstable/ai";
7
- import type { AckEnvelopeReadyInput, CancelExecutionAccepted, CancelExecutionInput, CancelScheduleInput, CancelScheduleResult, ClaimEnvelopeReadyInput, CreateScheduleInput, CreateScheduleResult, EnvelopeReadyAcked, EnvelopeReadyLease, EnvelopeReadyReleased, ExecutionInspection, ExecutionListChange, GetSessionInput, GetSessionResult, GetResidentStateInput, PutResidentStateInput, DeleteResidentStateInput, ListResidentStateInput, SpawnResidentInput, GetResidentInput, DestroyResidentInput, ListResidentsInput, ListExecutionsInput, ListExecutionsResult, ListInboxMessagesInput, ListTopicSubscriptionsInput, PublishTopicInput, SubscribeTopicInput, TopicPublishAccepted, TopicSubscription, UnsubscribeTopicInput, ListPendingApprovalsInput, SessionStreamItem, StreamSessionInput, WatchExecutionsInput, ListRunnersResult, ListSchedulesInput, ListSchedulesResult, ListSessionsInput, ListSessionsResult, ListWaitsInput, PendingToolApprovalList, PendingToolCallList, ListPendingToolCallsInput, FulfillToolCallInput, ClaimToolWorkInput, CompleteToolWorkInput, ReleaseToolWorkInput, ListToolAttemptsInput, ToolAttemptList, ToolOutcomeAccepted, ToolWorkLease, ToolWorkReleased, ReleaseEnvelopeReadyInput, PageExecutionEventsInput, PageExecutionEventsResult, ReplayExecutionInput, ReplayExecutionResult, ResolvePermissionInput, ResolveToolApprovalInput, RouteExecutionResult, StartExecutionInput, StartExecutionResult, SpawnChildRunInput, CancelChildFanOutInput, CancelChildFanOutResult, CreateChildFanOutInput, InspectChildFanOutInput, InspectChildFanOutResult, SteerAccepted, SteerInput, StreamExecutionInput, SubmitInboundEnvelopeAccepted, SubmitInboundEnvelopeInput, WaitView, WakeAccepted, WakeInput } from "./operation";
7
+ import type { AckEnvelopeReadyInput, CancelExecutionAccepted, CancelExecutionInput, CancelScheduleInput, CancelScheduleResult, ClaimEnvelopeReadyInput, CreateScheduleInput, CreateScheduleResult, EnvelopeReadyAcked, EnvelopeReadyLease, EnvelopeReadyReleased, ExecutionInspection, ExecutionListChange, GetSessionInput, GetSessionResult, GetResidentStateInput, PutResidentStateInput, DeleteResidentStateInput, ListResidentStateInput, SpawnResidentInput, GetResidentInput, DestroyResidentInput, ListResidentsInput, ListExecutionsInput, ListExecutionsResult, ListInboxMessagesInput, ListTopicSubscriptionsInput, PublishTopicInput, SubscribeTopicInput, TopicPublishAccepted, TopicSubscription, UnsubscribeTopicInput, ListPendingApprovalsInput, SessionStreamItem, StreamSessionInput, WatchExecutionsInput, ListRunnersResult, ListSchedulesInput, ListSchedulesResult, ListSessionsInput, ListSessionsResult, ListWaitsInput, PendingToolApprovalList, PendingToolCallList, ListPendingToolCallsInput, FulfillToolCallInput, ClaimToolWorkInput, CompleteToolWorkInput, ReleaseToolWorkInput, ListToolAttemptsInput, ToolAttemptList, ToolOutcomeAccepted, ToolWorkLease, ToolWorkReleased, ReleaseEnvelopeReadyInput, PageExecutionEventsInput, PageExecutionEventsResult, ReplayExecutionInput, ReplayExecutionResult, ResolvePermissionInput, ResolveToolApprovalInput, RouteExecutionResult, StartExecutionInput, StartExecutionResult, SpawnChildRunInput, CancelChildFanOutInput, CancelChildFanOutResult, CreateChildFanOutInput, InspectChildFanOutInput, InspectChildFanOutResult, SteerAccepted, SteerInput, SteeringIdempotencyConflict, StreamExecutionInput, SubmitInboundEnvelopeAccepted, SubmitInboundEnvelopeInput, WaitView, WakeAccepted, WakeInput } from "./operation";
8
8
  import { EventLogCursorNotFound } from "./operation";
9
9
  export { EventLogCursorNotFound } from "./operation";
10
10
  import { AwaitWaitInput, WaitOutcome } from "./operation";
@@ -130,7 +130,7 @@ export interface FlatInterface {
130
130
  readonly startExecutionByAddress: (input: StartExecutionByAddressInput) => Effect.Effect<StartExecutionResult, ResidentNamespaceReserved | ClientError>;
131
131
  readonly startExecutionByAgentDefinition: (input: StartExecutionByAgentDefinitionInput) => Effect.Effect<StartExecutionResult, ResidentNamespaceReserved | ClientError>;
132
132
  readonly cancelExecution: (input: CancelExecutionInput) => Effect.Effect<CancelExecutionAccepted, ClientError>;
133
- readonly steer: (input: SteerInput) => Effect.Effect<SteerAccepted, ClientError>;
133
+ readonly steer: (input: SteerInput) => Effect.Effect<SteerAccepted, ClientError | SteeringIdempotencyConflict>;
134
134
  readonly getExecution: (id: Ids.ExecutionId) => Effect.Effect<Execution.Execution | undefined, ClientError>;
135
135
  readonly inspectExecution: (executionId: Ids.ExecutionId) => Effect.Effect<ExecutionInspection, ExecutionNotFound | ClientError>;
136
136
  readonly listExecutions: (input: ListExecutionsInput) => Effect.Effect<ListExecutionsResult, ClientError>;
@@ -3,7 +3,7 @@ export { StateVersionConflict } from "./state-version-conflict";
3
3
  import type { StateVersionConflict } from "./state-version-conflict";
4
4
  import { Context } from "effect";
5
5
  import type { Effect, Scope, Stream } from "effect";
6
- import type { CancelExecutionAccepted, CancelExecutionInput, ClaimToolWorkInput, CompleteToolWorkInput, DeleteResidentStateInput, DestroyResidentInput, ExecutionInspection, ExecutionListChange, FulfillToolCallInput, GetResidentInput, GetResidentStateInput, ListResidentsInput, ListExecutionsInput, ListExecutionsResult, ListInboxMessagesInput, ListPendingToolCallsInput, ListResidentStateInput, ListToolAttemptsInput, ListWaitsInput, PendingToolCallList, PutResidentStateInput, ReleaseToolWorkInput, ResolvePermissionInput, SessionStreamItem, SpawnResidentInput, SpawnChildRunInput, StartExecutionResult, SteerAccepted, SteerInput, StreamExecutionInput, StreamSessionInput, ToolAttemptList, ToolOutcomeAccepted, ToolWorkLease, ToolWorkReleased, WaitView, WakeAccepted, WakeInput, WatchExecutionsInput } from "./operation";
6
+ import type { CancelExecutionAccepted, CancelExecutionInput, ClaimToolWorkInput, CompleteToolWorkInput, DeleteResidentStateInput, DestroyResidentInput, ExecutionInspection, ExecutionListChange, FulfillToolCallInput, GetResidentInput, GetResidentStateInput, ListResidentsInput, ListExecutionsInput, ListExecutionsResult, ListInboxMessagesInput, ListPendingToolCallsInput, ListResidentStateInput, ListToolAttemptsInput, ListWaitsInput, PendingToolCallList, PutResidentStateInput, ReleaseToolWorkInput, ResolvePermissionInput, SessionStreamItem, SpawnResidentInput, SpawnChildRunInput, StartExecutionResult, SteerAccepted, SteerInput, SteeringIdempotencyConflict, StreamExecutionInput, StreamSessionInput, ToolAttemptList, ToolOutcomeAccepted, ToolWorkLease, ToolWorkReleased, WaitView, WakeAccepted, WakeInput, WatchExecutionsInput } from "./operation";
7
7
  export interface ClientError {
8
8
  readonly _tag: "ClientError";
9
9
  readonly message: string;
@@ -49,7 +49,7 @@ export interface ClientInterface {
49
49
  readonly executions: {
50
50
  readonly startByAddress: (input: StartExecutionByAddressInput) => Effect.Effect<StartExecutionResult, ResidentNamespaceReserved | ClientError>;
51
51
  readonly cancel: (input: CancelExecutionInput) => Effect.Effect<CancelExecutionAccepted, ClientError>;
52
- readonly steer: (input: SteerInput) => Effect.Effect<SteerAccepted, ClientError>;
52
+ readonly steer: (input: SteerInput) => Effect.Effect<SteerAccepted, ClientError | SteeringIdempotencyConflict>;
53
53
  readonly get: (id: Ids.ExecutionId) => Effect.Effect<Execution.Execution | undefined, ClientError>;
54
54
  readonly inspect: (executionId: Ids.ExecutionId) => Effect.Effect<ExecutionInspection, ExecutionNotFound | ClientError>;
55
55
  readonly list: (input: ListExecutionsInput) => Effect.Effect<ListExecutionsResult, ClientError>;
@@ -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]];
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]];
@@ -454,6 +454,7 @@ export declare const SteerInput: Schema.Struct<{
454
454
  readonly execution_id: Schema.brand<Schema.String, "Relay.ExecutionId"> & {
455
455
  make: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => string & import("effect/Brand").Brand<"Relay.ExecutionId">;
456
456
  };
457
+ readonly idempotency_key: Schema.String;
457
458
  readonly kind: Schema.Literals<readonly ["steering", "follow_up"]>;
458
459
  readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
459
460
  readonly type: Schema.Literal<"text">;
@@ -508,6 +509,14 @@ export declare const SteerInput: Schema.Struct<{
508
509
  }>;
509
510
  export interface SteerInput extends Schema.Schema.Type<typeof SteerInput> {
510
511
  }
512
+ declare const SteeringIdempotencyConflict_base: Schema.Class<SteeringIdempotencyConflict, Schema.TaggedStruct<"SteeringIdempotencyConflict", {
513
+ readonly execution_id: Schema.brand<Schema.String, "Relay.ExecutionId"> & {
514
+ make: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => string & import("effect/Brand").Brand<"Relay.ExecutionId">;
515
+ };
516
+ readonly idempotency_key: Schema.String;
517
+ }>, import("effect/Cause").YieldableError>;
518
+ export declare class SteeringIdempotencyConflict extends SteeringIdempotencyConflict_base {
519
+ }
511
520
  export declare const SteerAccepted: Schema.Struct<{
512
521
  readonly execution_id: Schema.brand<Schema.String, "Relay.ExecutionId"> & {
513
522
  make: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => string & import("effect/Brand").Brand<"Relay.ExecutionId">;
@@ -70,5 +70,25 @@ export declare const migrations: readonly [{
70
70
  readonly name: "session_writer_ownership";
71
71
  readonly file: "0014_session_writer_ownership.sql";
72
72
  readonly source: string;
73
+ }, {
74
+ readonly id: 15;
75
+ readonly name: "transactional_event_head";
76
+ readonly file: "0015_transactional_event_head.sql";
77
+ readonly source: string;
78
+ }, {
79
+ readonly id: 16;
80
+ readonly name: "execution_event_archive_manifests";
81
+ readonly file: "0016_execution_event_archive_manifests.sql";
82
+ readonly source: string;
83
+ }, {
84
+ readonly id: 17;
85
+ readonly name: "execution_event_identity_directory";
86
+ readonly file: "0017_execution_event_identity_directory.sql";
87
+ readonly source: string;
88
+ }, {
89
+ readonly id: 18;
90
+ readonly name: "idempotent_steering";
91
+ readonly file: "0018_idempotent_steering.sql";
92
+ readonly source: string;
73
93
  }];
74
- export declare const loader: Effect.Effect<(readonly [1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14, "baseline" | "child_fan_out" | "durable_entities" | "durable_inbox" | "durable_tool_placement" | "ephemeral_presence" | "execution_scoped_tool_calls" | "execution_state" | "rename_entity_to_resident" | "session_writer_ownership" | "steering_delivered" | "topic_subscriptions" | "workflow_definitions" | "workflow_runtime", Effect.Effect<Effect.Effect<void, import("effect/unstable/sql/SqlError").SqlError, SqlClient>, never, never>])[], never, never>;
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>;