@tenetkit/pg 0.32.0 → 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
- export const SCHEMA_VERSION = 8;
2
- export const V7_SCHEMA_CHECKSUM = "4d86018b3453e9757e05694ce981fc486a15a00ebb36874b49821f6289e6d495";
3
- export const SCHEMA_META_TABLE = "baton_schema_meta";
4
- export const MIGRATIONS_TABLE = "baton_sql_migrations";
5
- export const NOTIFY_CHANNEL = "baton_run_events";
6
- export const V7_SCHEMA_STATEMENTS = [
7
- `CREATE TABLE IF NOT EXISTS baton_schema_meta (
1
+ export const SCHEMA_VERSION = 1;
2
+ export const MIGRATION_NAME = "tenetkit_runtime";
3
+ export const SCHEMA_META_TABLE = "tenetkit_schema_meta";
4
+ export const MIGRATIONS_TABLE = "tenetkit_sql_migrations";
5
+ export const NOTIFY_CHANNEL = "tenetkit_run_events";
6
+ export const SCHEMA_STATEMENTS = [
7
+ `CREATE TABLE IF NOT EXISTS tenetkit_schema_meta (
8
8
  id INTEGER PRIMARY KEY CHECK (id = 1),
9
9
  version INTEGER NOT NULL,
10
10
  checksum TEXT NOT NULL,
11
11
  dirty BOOLEAN NOT NULL DEFAULT FALSE,
12
12
  applied_at TIMESTAMPTZ NOT NULL
13
13
  )`,
14
- `CREATE TABLE IF NOT EXISTS baton_lanes (
14
+ `CREATE TABLE IF NOT EXISTS tenetkit_lanes (
15
15
  address TEXT NOT NULL,
16
16
  session_id TEXT NOT NULL,
17
17
  accepted_sequence BIGINT NOT NULL,
@@ -19,7 +19,7 @@ export const V7_SCHEMA_STATEMENTS = [
19
19
  head_run_id TEXT,
20
20
  PRIMARY KEY (address, session_id)
21
21
  )`,
22
- `CREATE TABLE IF NOT EXISTS baton_runs (
22
+ `CREATE TABLE IF NOT EXISTS tenetkit_runs (
23
23
  run_id TEXT PRIMARY KEY,
24
24
  status TEXT NOT NULL,
25
25
  address TEXT NOT NULL,
@@ -55,15 +55,15 @@ export const V7_SCHEMA_STATEMENTS = [
55
55
  updated_at TIMESTAMPTZ NOT NULL,
56
56
  UNIQUE (address, session_id, idempotency_key)
57
57
  )`,
58
- `CREATE TABLE IF NOT EXISTS baton_run_events (
59
- run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
58
+ `CREATE TABLE IF NOT EXISTS tenetkit_run_events (
59
+ run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
60
60
  sequence INTEGER NOT NULL,
61
61
  event_id TEXT NOT NULL UNIQUE,
62
62
  event_json TEXT NOT NULL,
63
63
  PRIMARY KEY (run_id, sequence)
64
64
  )`,
65
- `CREATE TABLE IF NOT EXISTS baton_run_operations (
66
- run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
65
+ `CREATE TABLE IF NOT EXISTS tenetkit_run_operations (
66
+ run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
67
67
  operation_id TEXT NOT NULL,
68
68
  operation_key TEXT NOT NULL,
69
69
  kind TEXT NOT NULL,
@@ -83,8 +83,8 @@ export const V7_SCHEMA_STATEMENTS = [
83
83
  PRIMARY KEY (run_id, operation_id),
84
84
  UNIQUE (run_id, operation_key)
85
85
  )`,
86
- `CREATE TABLE IF NOT EXISTS baton_run_waits (
87
- run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
86
+ `CREATE TABLE IF NOT EXISTS tenetkit_run_waits (
87
+ run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
88
88
  wait_id TEXT NOT NULL,
89
89
  reason TEXT NOT NULL,
90
90
  status TEXT NOT NULL,
@@ -96,9 +96,9 @@ export const V7_SCHEMA_STATEMENTS = [
96
96
  closed_at TIMESTAMPTZ,
97
97
  PRIMARY KEY (run_id, wait_id)
98
98
  )`,
99
- `CREATE TABLE IF NOT EXISTS baton_run_links (
100
- parent_run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
101
- child_run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
99
+ `CREATE TABLE IF NOT EXISTS tenetkit_run_links (
100
+ parent_run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
101
+ child_run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
102
102
  invocation_id TEXT NOT NULL,
103
103
  readiness TEXT NOT NULL,
104
104
  terminal_event_id TEXT,
@@ -107,10 +107,10 @@ export const V7_SCHEMA_STATEMENTS = [
107
107
  PRIMARY KEY (parent_run_id, child_run_id),
108
108
  UNIQUE (child_run_id)
109
109
  )`,
110
- `CREATE INDEX IF NOT EXISTS baton_run_links_readiness_idx ON baton_run_links(parent_run_id, readiness, created_at, child_run_id)`,
111
- `CREATE TABLE IF NOT EXISTS baton_run_steering (
110
+ `CREATE INDEX IF NOT EXISTS tenetkit_run_links_readiness_idx ON tenetkit_run_links(parent_run_id, readiness, created_at, child_run_id)`,
111
+ `CREATE TABLE IF NOT EXISTS tenetkit_run_steering (
112
112
  entry_id TEXT PRIMARY KEY,
113
- run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
113
+ run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
114
114
  sequence BIGINT NOT NULL,
115
115
  idempotency_key TEXT NOT NULL,
116
116
  digest TEXT NOT NULL,
@@ -120,16 +120,16 @@ export const V7_SCHEMA_STATEMENTS = [
120
120
  UNIQUE (run_id, sequence),
121
121
  UNIQUE (run_id, idempotency_key)
122
122
  )`,
123
- `CREATE INDEX IF NOT EXISTS baton_run_steering_pending_idx
124
- ON baton_run_steering(run_id, sequence) WHERE consumed_operation_id IS NULL AND discarded_reason IS NULL`,
125
- `CREATE TABLE IF NOT EXISTS baton_agent_names (
123
+ `CREATE INDEX IF NOT EXISTS tenetkit_run_steering_pending_idx
124
+ ON tenetkit_run_steering(run_id, sequence) WHERE consumed_operation_id IS NULL AND discarded_reason IS NULL`,
125
+ `CREATE TABLE IF NOT EXISTS tenetkit_agent_names (
126
126
  scope TEXT NOT NULL,
127
127
  name TEXT NOT NULL,
128
- run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
128
+ run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
129
129
  PRIMARY KEY (scope, name)
130
130
  )`,
131
- `CREATE INDEX IF NOT EXISTS baton_agent_names_run_idx ON baton_agent_names(run_id)`,
132
- `CREATE TABLE IF NOT EXISTS baton_messages (
131
+ `CREATE INDEX IF NOT EXISTS tenetkit_agent_names_run_idx ON tenetkit_agent_names(run_id)`,
132
+ `CREATE TABLE IF NOT EXISTS tenetkit_messages (
133
133
  entry_id TEXT PRIMARY KEY,
134
134
  target_session_id TEXT NOT NULL,
135
135
  sequence BIGINT NOT NULL,
@@ -151,17 +151,17 @@ export const V7_SCHEMA_STATEMENTS = [
151
151
  UNIQUE (target_session_id, message_id, idempotency_key),
152
152
  UNIQUE (target_session_id, sequence)
153
153
  )`,
154
- `CREATE INDEX IF NOT EXISTS baton_messages_pending_idx
155
- ON baton_messages(target_session_id, sequence) WHERE delivered_run_id IS NULL`,
156
- `CREATE INDEX IF NOT EXISTS baton_runs_claim_idx
157
- ON baton_runs(status, lease_expires_at)
154
+ `CREATE INDEX IF NOT EXISTS tenetkit_messages_pending_idx
155
+ ON tenetkit_messages(target_session_id, sequence) WHERE delivered_run_id IS NULL`,
156
+ `CREATE INDEX IF NOT EXISTS tenetkit_runs_claim_idx
157
+ ON tenetkit_runs(status, lease_expires_at)
158
158
  WHERE status IN ('queued', 'running', 'waiting', 'needs-resolution', 'cancelling')`,
159
- `CREATE INDEX IF NOT EXISTS baton_lanes_head_idx ON baton_lanes(head_run_id)`,
160
- `CREATE INDEX IF NOT EXISTS baton_run_operations_status_idx ON baton_run_operations(status)`,
161
- `CREATE INDEX IF NOT EXISTS baton_run_waits_due_idx ON baton_run_waits(status, due_at)`,
162
- `CREATE TABLE IF NOT EXISTS baton_fan_outs (
159
+ `CREATE INDEX IF NOT EXISTS tenetkit_lanes_head_idx ON tenetkit_lanes(head_run_id)`,
160
+ `CREATE INDEX IF NOT EXISTS tenetkit_run_operations_status_idx ON tenetkit_run_operations(status)`,
161
+ `CREATE INDEX IF NOT EXISTS tenetkit_run_waits_due_idx ON tenetkit_run_waits(status, due_at)`,
162
+ `CREATE TABLE IF NOT EXISTS tenetkit_fan_outs (
163
163
  fan_out_id TEXT PRIMARY KEY,
164
- parent_run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
164
+ parent_run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
165
165
  idempotency_key TEXT NOT NULL,
166
166
  input_digest TEXT NOT NULL,
167
167
  join_json TEXT NOT NULL,
@@ -172,15 +172,15 @@ export const V7_SCHEMA_STATEMENTS = [
172
172
  updated_at TIMESTAMPTZ NOT NULL,
173
173
  UNIQUE (parent_run_id, idempotency_key)
174
174
  )`,
175
- `CREATE TABLE IF NOT EXISTS baton_fan_out_members (
176
- fan_out_id TEXT NOT NULL REFERENCES baton_fan_outs(fan_out_id),
175
+ `CREATE TABLE IF NOT EXISTS tenetkit_fan_out_members (
176
+ fan_out_id TEXT NOT NULL REFERENCES tenetkit_fan_outs(fan_out_id),
177
177
  ordinal INTEGER NOT NULL,
178
178
  member_key TEXT NOT NULL,
179
179
  selection TEXT NOT NULL,
180
180
  display_label TEXT,
181
181
  prompt_json TEXT NOT NULL,
182
182
  origin_json TEXT,
183
- child_run_id TEXT NOT NULL UNIQUE REFERENCES baton_runs(run_id),
183
+ child_run_id TEXT NOT NULL UNIQUE REFERENCES tenetkit_runs(run_id),
184
184
  depth INTEGER NOT NULL,
185
185
  status TEXT NOT NULL,
186
186
  terminal_event_id TEXT,
@@ -188,24 +188,24 @@ export const V7_SCHEMA_STATEMENTS = [
188
188
  PRIMARY KEY (fan_out_id, ordinal),
189
189
  UNIQUE (fan_out_id, member_key)
190
190
  )`,
191
- `CREATE INDEX IF NOT EXISTS baton_fan_out_members_status_idx ON baton_fan_out_members(fan_out_id, status, ordinal)`,
192
- `CREATE TABLE IF NOT EXISTS baton_tree_roots (
193
- root_run_id TEXT PRIMARY KEY REFERENCES baton_runs(run_id),
191
+ `CREATE INDEX IF NOT EXISTS tenetkit_fan_out_members_status_idx ON tenetkit_fan_out_members(fan_out_id, status, ordinal)`,
192
+ `CREATE TABLE IF NOT EXISTS tenetkit_tree_roots (
193
+ root_run_id TEXT PRIMARY KEY REFERENCES tenetkit_runs(run_id),
194
194
  earliest_position BIGINT NOT NULL DEFAULT 0,
195
195
  last_position BIGINT NOT NULL DEFAULT -1
196
196
  )`,
197
- `CREATE TABLE IF NOT EXISTS baton_tree_event_index (
198
- root_run_id TEXT NOT NULL REFERENCES baton_tree_roots(root_run_id),
197
+ `CREATE TABLE IF NOT EXISTS tenetkit_tree_event_index (
198
+ root_run_id TEXT NOT NULL REFERENCES tenetkit_tree_roots(root_run_id),
199
199
  position BIGINT NOT NULL,
200
200
  run_id TEXT NOT NULL,
201
201
  run_sequence INTEGER NOT NULL,
202
- event_id TEXT NOT NULL UNIQUE REFERENCES baton_run_events(event_id),
202
+ event_id TEXT NOT NULL UNIQUE REFERENCES tenetkit_run_events(event_id),
203
203
  PRIMARY KEY (root_run_id, position),
204
204
  UNIQUE (run_id, run_sequence),
205
- FOREIGN KEY (run_id, run_sequence) REFERENCES baton_run_events(run_id, sequence)
205
+ FOREIGN KEY (run_id, run_sequence) REFERENCES tenetkit_run_events(run_id, sequence)
206
206
  )`,
207
- `CREATE TABLE IF NOT EXISTS baton_program_runs (
208
- run_id TEXT PRIMARY KEY REFERENCES baton_runs(run_id),
207
+ `CREATE TABLE IF NOT EXISTS tenetkit_program_runs (
208
+ run_id TEXT PRIMARY KEY REFERENCES tenetkit_runs(run_id),
209
209
  program_pin TEXT NOT NULL,
210
210
  budget_json TEXT NOT NULL,
211
211
  deadline_millis BIGINT NOT NULL,
@@ -215,8 +215,8 @@ export const V7_SCHEMA_STATEMENTS = [
215
215
  log_bytes BIGINT NOT NULL DEFAULT 0,
216
216
  active_slots BIGINT NOT NULL DEFAULT 0
217
217
  )`,
218
- `CREATE TABLE IF NOT EXISTS baton_program_operations (
219
- run_id TEXT NOT NULL REFERENCES baton_program_runs(run_id),
218
+ `CREATE TABLE IF NOT EXISTS tenetkit_program_operations (
219
+ run_id TEXT NOT NULL REFERENCES tenetkit_program_runs(run_id),
220
220
  operation_name TEXT NOT NULL,
221
221
  kind TEXT NOT NULL,
222
222
  capability TEXT NOT NULL,
@@ -233,27 +233,27 @@ export const V7_SCHEMA_STATEMENTS = [
233
233
  resolution_json TEXT,
234
234
  PRIMARY KEY (run_id, operation_name)
235
235
  )`,
236
- `CREATE TABLE IF NOT EXISTS baton_executable_registrations (
236
+ `CREATE TABLE IF NOT EXISTS tenetkit_executable_registrations (
237
237
  pin TEXT PRIMARY KEY,
238
238
  codec TEXT NOT NULL,
239
239
  version TEXT NOT NULL,
240
240
  payload_json TEXT NOT NULL,
241
241
  registration_digest TEXT NOT NULL
242
242
  )`,
243
- `CREATE TABLE IF NOT EXISTS baton_run_registrations (
244
- run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
245
- pin TEXT NOT NULL REFERENCES baton_executable_registrations(pin),
243
+ `CREATE TABLE IF NOT EXISTS tenetkit_run_registrations (
244
+ run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
245
+ pin TEXT NOT NULL REFERENCES tenetkit_executable_registrations(pin),
246
246
  PRIMARY KEY (run_id, pin)
247
247
  )`,
248
- `CREATE INDEX IF NOT EXISTS baton_run_registrations_pin_idx ON baton_run_registrations(pin)`,
249
- `CREATE TABLE IF NOT EXISTS baton_sessions (
248
+ `CREATE INDEX IF NOT EXISTS tenetkit_run_registrations_pin_idx ON tenetkit_run_registrations(pin)`,
249
+ `CREATE TABLE IF NOT EXISTS tenetkit_sessions (
250
250
  session_id TEXT PRIMARY KEY,
251
251
  leaf_id TEXT,
252
252
  next_seq BIGINT NOT NULL DEFAULT 0,
253
253
  owner_token TEXT,
254
254
  updated_at TIMESTAMPTZ NOT NULL
255
255
  )`,
256
- `CREATE TABLE IF NOT EXISTS baton_session_entries (
256
+ `CREATE TABLE IF NOT EXISTS tenetkit_session_entries (
257
257
  session_id TEXT NOT NULL,
258
258
  entry_id TEXT NOT NULL,
259
259
  parent_id TEXT,
@@ -263,13 +263,11 @@ export const V7_SCHEMA_STATEMENTS = [
263
263
  created_at TIMESTAMPTZ NOT NULL,
264
264
  PRIMARY KEY (session_id, entry_id)
265
265
  )`,
266
- `CREATE UNIQUE INDEX IF NOT EXISTS baton_session_entries_seq_idx ON baton_session_entries(session_id, seq)`,
267
- `CREATE INDEX IF NOT EXISTS baton_session_entries_parent_idx ON baton_session_entries(session_id, parent_id)`,
268
- ];
269
- export const EXTERNAL_CHILD_STATEMENTS = [
270
- `CREATE TABLE IF NOT EXISTS baton_external_child_placements (
266
+ `CREATE UNIQUE INDEX IF NOT EXISTS tenetkit_session_entries_seq_idx ON tenetkit_session_entries(session_id, seq)`,
267
+ `CREATE INDEX IF NOT EXISTS tenetkit_session_entries_parent_idx ON tenetkit_session_entries(session_id, parent_id)`,
268
+ `CREATE TABLE IF NOT EXISTS tenetkit_external_child_placements (
271
269
  placement_id TEXT PRIMARY KEY,
272
- parent_run_id TEXT NOT NULL REFERENCES baton_runs(run_id),
270
+ parent_run_id TEXT NOT NULL REFERENCES tenetkit_runs(run_id),
273
271
  partition TEXT NOT NULL,
274
272
  external_run_id TEXT NOT NULL,
275
273
  invocation_id TEXT NOT NULL,
@@ -289,10 +287,10 @@ export const EXTERNAL_CHILD_STATEMENTS = [
289
287
  CHECK ((settlement_id IS NULL AND outcome_json IS NULL AND outcome_event_id IS NULL AND settled_at IS NULL)
290
288
  OR (settlement_id IS NOT NULL AND outcome_json IS NOT NULL AND outcome_event_id IS NOT NULL AND settled_at IS NOT NULL))
291
289
  )`,
292
- `CREATE INDEX IF NOT EXISTS baton_external_child_placements_parent_idx
293
- ON baton_external_child_placements(parent_run_id, settlement_id, created_at)`,
290
+ `CREATE INDEX IF NOT EXISTS tenetkit_external_child_placements_parent_idx
291
+ ON tenetkit_external_child_placements(parent_run_id, settlement_id, created_at)`,
294
292
  ];
295
- export const SCHEMA_STATEMENTS = [...V7_SCHEMA_STATEMENTS, ...EXTERNAL_CHILD_STATEMENTS];
293
+ export const SCHEMA_TABLES = SCHEMA_STATEMENTS.flatMap((statement) => statement.match(/^CREATE TABLE IF NOT EXISTS (\w+)/)?.slice(1, 2) ?? []);
296
294
  export const schemaChecksum = () => {
297
295
  const hasher = new Bun.CryptoHasher("sha256");
298
296
  hasher.update(SCHEMA_STATEMENTS.join("\n"));
@@ -6,12 +6,12 @@ const { encodePayload, entryPayloadEquivalence, pathFromRows, requireActive, sto
6
6
  const lockSession = (sessionId) => Effect.gen(function* () {
7
7
  const sql = yield* SqlClient.SqlClient;
8
8
  yield* sql `
9
- INSERT INTO baton_sessions (session_id, leaf_id, next_seq, owner_token, updated_at)
9
+ INSERT INTO tenetkit_sessions (session_id, leaf_id, next_seq, owner_token, updated_at)
10
10
  VALUES (${sessionId}, NULL, 0, NULL, NOW())
11
11
  ON CONFLICT (session_id) DO NOTHING
12
12
  `;
13
13
  const rows = yield* sql `
14
- SELECT leaf_id, next_seq, owner_token FROM baton_sessions
14
+ SELECT leaf_id, next_seq, owner_token FROM tenetkit_sessions
15
15
  WHERE session_id = ${sessionId}
16
16
  FOR UPDATE
17
17
  `;
@@ -21,14 +21,14 @@ const lockSession = (sessionId) => Effect.gen(function* () {
21
21
  const loadEntries = (sessionId) => Effect.gen(function* () {
22
22
  const sql = yield* SqlClient.SqlClient;
23
23
  return yield* sql `
24
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
24
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
25
25
  WHERE session_id = ${sessionId} ORDER BY seq
26
26
  `;
27
27
  });
28
28
  const insertEntry = (input) => Effect.gen(function* () {
29
29
  const sql = yield* SqlClient.SqlClient;
30
30
  yield* sql `
31
- INSERT INTO baton_session_entries (session_id, entry_id, parent_id, seq, tag, payload_json, created_at)
31
+ INSERT INTO tenetkit_session_entries (session_id, entry_id, parent_id, seq, tag, payload_json, created_at)
32
32
  VALUES (${input.sessionId}, ${input.id}, ${input.parentId}, ${input.seq}, ${input.tag},
33
33
  ${encodePayload(input.payload)}, NOW())
34
34
  `;
@@ -37,13 +37,13 @@ const advanceSession = (input) => Effect.gen(function* () {
37
37
  const sql = yield* SqlClient.SqlClient;
38
38
  if (input.ownerToken === undefined) {
39
39
  yield* sql `
40
- UPDATE baton_sessions SET leaf_id = ${input.leafId}, next_seq = ${input.nextSeq}, updated_at = NOW()
40
+ UPDATE tenetkit_sessions SET leaf_id = ${input.leafId}, next_seq = ${input.nextSeq}, updated_at = NOW()
41
41
  WHERE session_id = ${input.sessionId}
42
42
  `;
43
43
  }
44
44
  else {
45
45
  yield* sql `
46
- UPDATE baton_sessions SET leaf_id = ${input.leafId}, next_seq = ${input.nextSeq},
46
+ UPDATE tenetkit_sessions SET leaf_id = ${input.leafId}, next_seq = ${input.nextSeq},
47
47
  owner_token = ${input.ownerToken}, updated_at = NOW()
48
48
  WHERE session_id = ${input.sessionId}
49
49
  `;
@@ -21,7 +21,7 @@ export const appendCompletedSessionEntry = (input) => Effect.gen(function* () {
21
21
  const sql = yield* SqlClient.SqlClient;
22
22
  const session = yield* lockSession(input.sessionId);
23
23
  const rows = yield* sql `
24
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
24
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
25
25
  WHERE session_id = ${input.sessionId} AND entry_id = ${input.entryId}
26
26
  `;
27
27
  const existing = rows[0];
@@ -65,7 +65,7 @@ export const verifyCompletedSessionEntry = (input) => Effect.gen(function* () {
65
65
  const sql = yield* SqlClient.SqlClient;
66
66
  const session = yield* lockSession(input.sessionId);
67
67
  const rows = yield* sql `
68
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
68
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
69
69
  WHERE session_id = ${input.sessionId} AND entry_id = ${input.entryId}
70
70
  `;
71
71
  const existing = rows[0];
@@ -86,7 +86,7 @@ export const appendInterruptedSessionEntry = (input) => Effect.gen(function* ()
86
86
  const sql = yield* SqlClient.SqlClient;
87
87
  const session = yield* lockSession(input.sessionId);
88
88
  const rows = yield* sql `
89
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
89
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
90
90
  WHERE session_id = ${input.sessionId} AND entry_id = ${input.entryId}
91
91
  `;
92
92
  const existing = rows[0];
@@ -129,7 +129,7 @@ export const verifyInterruptedSessionEntry = (input) => Effect.gen(function* ()
129
129
  const sql = yield* SqlClient.SqlClient;
130
130
  const session = yield* lockSession(input.sessionId);
131
131
  const rows = yield* sql `
132
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
132
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
133
133
  WHERE session_id = ${input.sessionId} AND entry_id = ${input.entryId}
134
134
  `;
135
135
  const existing = rows[0];
@@ -150,7 +150,7 @@ export const appendHandoffSessionEntry = (input) => Effect.gen(function* () {
150
150
  const sql = yield* SqlClient.SqlClient;
151
151
  const session = yield* lockSession(input.sessionId);
152
152
  const rows = yield* sql `
153
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
153
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
154
154
  WHERE session_id = ${input.sessionId} AND entry_id = ${input.entryId}
155
155
  `;
156
156
  const existing = rows[0];
@@ -193,7 +193,7 @@ export const verifyHandoffSessionEntry = (input) => Effect.gen(function* () {
193
193
  const sql = yield* SqlClient.SqlClient;
194
194
  const session = yield* lockSession(input.sessionId);
195
195
  const rows = yield* sql `
196
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
196
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
197
197
  WHERE session_id = ${input.sessionId} AND entry_id = ${input.entryId}
198
198
  `;
199
199
  const existing = rows[0];
@@ -221,7 +221,7 @@ export const makePostgresSessionStore = (options) => {
221
221
  const session = yield* lockSession(sessionId);
222
222
  if (appendOptions?.id !== undefined) {
223
223
  const rows = yield* sql `
224
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
224
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
225
225
  WHERE session_id = ${sessionId} AND entry_id = ${appendOptions.id}
226
226
  `;
227
227
  const existing = rows[0];
@@ -249,7 +249,7 @@ export const makePostgresSessionStore = (options) => {
249
249
  if (appendOptions?.id === undefined) {
250
250
  while (true) {
251
251
  const collision = yield* sql `
252
- SELECT entry_id FROM baton_session_entries
252
+ SELECT entry_id FROM tenetkit_session_entries
253
253
  WHERE session_id = ${sessionId} AND entry_id = ${String(generatedSequence)}
254
254
  `;
255
255
  if (collision[0] === undefined)
@@ -278,7 +278,7 @@ export const makePostgresSessionStore = (options) => {
278
278
  const sql = yield* SqlClient.SqlClient;
279
279
  const session = yield* lockSession(sessionId);
280
280
  const rows = yield* sql `
281
- SELECT entry_id, parent_id, seq, tag, payload_json FROM baton_session_entries
281
+ SELECT entry_id, parent_id, seq, tag, payload_json FROM tenetkit_session_entries
282
282
  WHERE session_id = ${sessionId} AND entry_id = ${prepared.id}
283
283
  `;
284
284
  const existing = rows[0];
@@ -343,7 +343,7 @@ export const makePostgresSessionStore = (options) => {
343
343
  let sequence = Number(session.next_seq);
344
344
  while (true) {
345
345
  const collision = yield* sql `
346
- SELECT entry_id FROM baton_session_entries
346
+ SELECT entry_id FROM tenetkit_session_entries
347
347
  WHERE session_id = ${sessionId} AND entry_id = ${String(sequence)}
348
348
  `;
349
349
  if (collision[0] === undefined)
@@ -358,7 +358,7 @@ export const makePostgresSessionStore = (options) => {
358
358
  path: (leaf) => runNoTxn(Effect.gen(function* () {
359
359
  const sql = yield* SqlClient.SqlClient;
360
360
  const sessions = yield* sql `
361
- SELECT leaf_id, next_seq, owner_token FROM baton_sessions WHERE session_id = ${sessionId}
361
+ SELECT leaf_id, next_seq, owner_token FROM tenetkit_sessions WHERE session_id = ${sessionId}
362
362
  `;
363
363
  return { target: leaf ?? sessions[0]?.leaf_id ?? null, rows: yield* loadEntries(sessionId) };
364
364
  }).pipe(Effect.flatMap(({ rows, target }) => {
@@ -370,17 +370,17 @@ export const makePostgresSessionStore = (options) => {
370
370
  yield* lockSession(sessionId);
371
371
  if (id !== null) {
372
372
  const rows = yield* sql `
373
- SELECT entry_id FROM baton_session_entries WHERE session_id = ${sessionId} AND entry_id = ${id}
373
+ SELECT entry_id FROM tenetkit_session_entries WHERE session_id = ${sessionId} AND entry_id = ${id}
374
374
  `;
375
375
  if (rows[0] === undefined)
376
376
  return yield* storeError(`Session entry ${id} does not exist`);
377
377
  }
378
- yield* sql `UPDATE baton_sessions SET leaf_id = ${id}, updated_at = NOW() WHERE session_id = ${sessionId}`;
378
+ yield* sql `UPDATE tenetkit_sessions SET leaf_id = ${id}, updated_at = NOW() WHERE session_id = ${sessionId}`;
379
379
  })).pipe(mapReadError),
380
380
  leaf: Effect.orDie(runNoTxn(Effect.gen(function* () {
381
381
  const sql = yield* SqlClient.SqlClient;
382
382
  const rows = yield* sql `
383
- SELECT leaf_id, next_seq, owner_token FROM baton_sessions WHERE session_id = ${sessionId}
383
+ SELECT leaf_id, next_seq, owner_token FROM tenetkit_sessions WHERE session_id = ${sessionId}
384
384
  `;
385
385
  return rows[0]?.leaf_id ?? null;
386
386
  }))),
@@ -28,7 +28,7 @@ export const admitSend = Function.dual(4, (hub, addressBindings, nextId, input)
28
28
  const treePolicy = yield* normalizeTreePolicy(input.treePolicy);
29
29
  const digest = rootDigest(input.message, treePolicy);
30
30
  const existing = yield* sql `
31
- SELECT * FROM baton_runs
31
+ SELECT * FROM tenetkit_runs
32
32
  WHERE address = ${input.message.to}
33
33
  AND session_id = ${input.message.sessionId}
34
34
  AND idempotency_key = ${input.message.idempotencyKey}
@@ -55,7 +55,7 @@ export const admitSend = Function.dual(4, (hub, addressBindings, nextId, input)
55
55
  };
56
56
  }
57
57
  if (input.runId !== undefined) {
58
- const byId = yield* sql `SELECT * FROM baton_runs WHERE run_id = ${input.runId}`;
58
+ const byId = yield* sql `SELECT * FROM tenetkit_runs WHERE run_id = ${input.runId}`;
59
59
  if (byId[0] !== undefined)
60
60
  return yield* RunIdConflict.make({ runId: input.runId, existingRunId: byId[0].run_id });
61
61
  }
@@ -7,11 +7,11 @@ import { cancelOwnedFanOuts } from "./store-fan-out.js";
7
7
  import { reconcileProgramCancellation } from "tenetkit/runtime/driver/sql/store-program";
8
8
  export const deferCancelledFanOutParent = Function.dual(2, (sql, runId) => Effect.gen(function* () {
9
9
  const running = yield* sql `
10
- SELECT fan_out_id FROM baton_fan_outs WHERE parent_run_id = ${runId} AND status = 'running' LIMIT 1
10
+ SELECT fan_out_id FROM tenetkit_fan_outs WHERE parent_run_id = ${runId} AND status = 'running' LIMIT 1
11
11
  `;
12
12
  if (running.length === 0 && !(yield* hasUnsettledChild(runId)))
13
13
  return false;
14
- yield* sql `UPDATE baton_runs SET owner_worker_id = NULL, lease_expires_at = NULL WHERE run_id = ${runId}`;
14
+ yield* sql `UPDATE tenetkit_runs SET owner_worker_id = NULL, lease_expires_at = NULL WHERE run_id = ${runId}`;
15
15
  return true;
16
16
  }));
17
17
  export const makeCancelRun = (input) => {
@@ -27,12 +27,12 @@ export const makeCancelRun = (input) => {
27
27
  if (!terminal)
28
28
  yield* reconcileProgramCancellation(runId, reason ?? current.cancelReason);
29
29
  yield* input.sql `
30
- UPDATE baton_run_waits SET status = 'cancelled', closed_at = NOW()
30
+ UPDATE tenetkit_run_waits SET status = 'cancelled', closed_at = NOW()
31
31
  WHERE run_id = ${runId} AND status = 'open'
32
32
  `;
33
33
  const linked = yield* input.sql `
34
- SELECT l.child_run_id FROM baton_run_links l
35
- LEFT JOIN baton_fan_out_members m ON m.child_run_id = l.child_run_id
34
+ SELECT l.child_run_id FROM tenetkit_run_links l
35
+ LEFT JOIN tenetkit_fan_out_members m ON m.child_run_id = l.child_run_id
36
36
  WHERE l.parent_run_id = ${runId} AND m.child_run_id IS NULL
37
37
  ORDER BY l.child_run_id ASC
38
38
  `;
@@ -58,7 +58,7 @@ export const makeCancelRun = (input) => {
58
58
  if (isTerminal(current.status))
59
59
  return;
60
60
  const running = yield* input.sql `
61
- SELECT fan_out_id FROM baton_fan_outs WHERE parent_run_id = ${runId} AND status = 'running' LIMIT 1
61
+ SELECT fan_out_id FROM tenetkit_fan_outs WHERE parent_run_id = ${runId} AND status = 'running' LIMIT 1
62
62
  `;
63
63
  if (running.length > 0)
64
64
  return;
@@ -3,14 +3,14 @@ import { admitFanOut, inspectFanOut } from "tenetkit/runtime/driver/sql/store-fa
3
3
  import { NOTIFY_CHANNEL } from "./schema.js";
4
4
  export const fanOutStoreMethods = (input) => ({
5
5
  admitFanOut: (fanOut) => input
6
- .run(input.sql `SELECT run_id FROM baton_runs WHERE run_id = ${fanOut.parentRunId} FOR UPDATE`.pipe(Effect.andThen(input.sql `SELECT pg_advisory_xact_lock(hashtext(${`fanout:${fanOut.parentRunId}:${fanOut.idempotencyKey}`}))`), Effect.andThen(admitFanOut(input.hub, fanOut))))
6
+ .run(input.sql `SELECT run_id FROM tenetkit_runs WHERE run_id = ${fanOut.parentRunId} FOR UPDATE`.pipe(Effect.andThen(input.sql `SELECT pg_advisory_xact_lock(hashtext(${`fanout:${fanOut.parentRunId}:${fanOut.idempotencyKey}`}))`), Effect.andThen(admitFanOut(input.hub, fanOut))))
7
7
  .pipe(Effect.tap((receipt) => input.runNoTxn(Effect.forEach([receipt.parentRunId, ...receipt.childRunIds], (runId) => input.pg.notify(NOTIFY_CHANNEL, runId), { discard: true })))),
8
8
  inspectFanOut: (fanOutId) => input.runNoTxn(inspectFanOut(fanOutId)),
9
9
  });
10
10
  export const cancelOwnedFanOuts = Function.dual(2, (sql, parentRunId) => Effect.gen(function* () {
11
11
  const owned = yield* sql `
12
- SELECT m.child_run_id FROM baton_fan_outs f
13
- JOIN baton_fan_out_members m ON m.fan_out_id = f.fan_out_id
12
+ SELECT m.child_run_id FROM tenetkit_fan_outs f
13
+ JOIN tenetkit_fan_out_members m ON m.fan_out_id = f.fan_out_id
14
14
  WHERE f.parent_run_id = ${parentRunId} AND f.status = 'running' ORDER BY m.ordinal ASC
15
15
  `;
16
16
  return owned.map((row) => row.child_run_id);
@@ -11,12 +11,12 @@ import { sameInterruptedModelOutcome, sameInterruptedModelResponse, validateInte
11
11
  import { appendCompletedSessionEntry, appendInterruptedSessionEntry, verifyCompletedSessionEntry, verifyInterruptedSessionEntry, } from "./session-store.js";
12
12
  export const postgresModelResponseOperations = (input) => {
13
13
  const { sql, hub, run, requireRun, requireClaim } = input;
14
- const fenced = (claim, effect) => run(sql `SELECT run_id FROM baton_runs WHERE run_id = ${claim.runId} FOR UPDATE`.pipe(Effect.andThen(requireClaim(claim)), Effect.andThen(effect)));
14
+ const fenced = (claim, effect) => run(sql `SELECT run_id FROM tenetkit_runs WHERE run_id = ${claim.runId} FOR UPDATE`.pipe(Effect.andThen(requireClaim(claim)), Effect.andThen(effect)));
15
15
  return {
16
16
  commitInterruptedModelResponse: (op) => fenced(op, Effect.gen(function* () {
17
17
  const loaded = yield* requireRun(op.runId);
18
18
  const rows = yield* sql `
19
- SELECT * FROM baton_run_operations
19
+ SELECT * FROM tenetkit_run_operations
20
20
  WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
21
21
  FOR UPDATE
22
22
  `;
@@ -58,20 +58,20 @@ export const postgresModelResponseOperations = (input) => {
58
58
  }
59
59
  yield* appendInterruptedSessionEntry(sessionEntry).pipe(Effect.mapError((error) => RuntimeUnavailable.make({ message: error.message })));
60
60
  yield* sql `
61
- UPDATE baton_run_operations
61
+ UPDATE tenetkit_run_operations
62
62
  SET status = 'failed', error_json = ${encodeJsonValue(op.outcome.error)}, finished_at = NOW()
63
63
  WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'running'
64
64
  `;
65
65
  yield* appendEvent(hub, yield* requireRun(op.runId), validated.event);
66
66
  const completed = yield* sql `
67
- SELECT * FROM baton_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
67
+ SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
68
68
  `;
69
69
  return toOperationRecord(completed[0]);
70
70
  })),
71
71
  commitModelResponse: (op) => fenced(op, Effect.gen(function* () {
72
72
  const loaded = yield* requireRun(op.runId);
73
73
  const existing = yield* sql `
74
- SELECT * FROM baton_run_operations
74
+ SELECT * FROM tenetkit_run_operations
75
75
  WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
76
76
  FOR UPDATE
77
77
  `;
@@ -116,7 +116,7 @@ export const postgresModelResponseOperations = (input) => {
116
116
  }
117
117
  for (const entryId of new Set(op.steeringEntryIds ?? [])) {
118
118
  const rows = yield* sql `
119
- SELECT consumed_operation_id FROM baton_run_steering
119
+ SELECT consumed_operation_id FROM tenetkit_run_steering
120
120
  WHERE run_id = ${op.runId} AND entry_id = ${entryId}
121
121
  `;
122
122
  if (rows[0]?.consumed_operation_id !== op.operationId) {
@@ -131,13 +131,13 @@ export const postgresModelResponseOperations = (input) => {
131
131
  });
132
132
  yield* appendCompletedSessionEntry(sessionEntry).pipe(Effect.mapError((error) => RuntimeUnavailable.make({ message: error.message })));
133
133
  yield* sql `
134
- UPDATE baton_run_operations
134
+ UPDATE tenetkit_run_operations
135
135
  SET status = 'succeeded', result_json = ${encodeJsonValue(validated.reference)}, finished_at = NOW()
136
136
  WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
137
137
  AND status IN ('requested', 'running')
138
138
  `;
139
139
  yield* sql `
140
- UPDATE baton_runs SET
140
+ UPDATE tenetkit_runs SET
141
141
  driver_checkpoint_json = COALESCE(${op.checkpoint === undefined ? null : encodeJson(ExecutionCheckpoint, op.checkpoint)}, driver_checkpoint_json),
142
142
  executable_ref_json = ${encodeExecutableRef(executableRef)},
143
143
  continuation_json = CASE WHEN ${op.continuation === undefined ? 0 : 1} = 1
@@ -148,7 +148,7 @@ export const postgresModelResponseOperations = (input) => {
148
148
  `;
149
149
  yield* appendEvent(hub, yield* requireRun(op.runId), validated.event);
150
150
  const rows = yield* sql `
151
- SELECT * FROM baton_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
151
+ SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
152
152
  `;
153
153
  return toOperationRecord(rows[0]);
154
154
  })),