@osolmaz/pi-workflows 0.16.0 → 0.16.2
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.
- package/README.md +18 -2
- package/dist/channels/adapter-entry.d.ts +3 -0
- package/dist/channels/adapter-entry.js +203 -0
- package/dist/channels/adapter-entry.js.map +1 -0
- package/dist/channels/config.d.ts +43 -0
- package/dist/channels/config.js +234 -0
- package/dist/channels/config.js.map +1 -0
- package/dist/channels/protocol.d.ts +94 -0
- package/dist/channels/protocol.js +219 -0
- package/dist/channels/protocol.js.map +1 -0
- package/dist/channels/telegram.d.ts +46 -0
- package/dist/channels/telegram.js +285 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +5 -1
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/protocol.d.ts +1 -1
- package/dist/client/protocol.js +11 -5
- package/dist/client/protocol.js.map +1 -1
- package/dist/client/view.d.ts +48 -16
- package/dist/client/view.js +1 -0
- package/dist/client/view.js.map +1 -1
- package/dist/controllers/index.d.ts +1 -1
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/sqlite.d.ts +20 -165
- package/dist/controllers/sqlite.js +178 -436
- package/dist/controllers/sqlite.js.map +1 -1
- package/dist/extension/index.d.ts +23 -2
- package/dist/extension/index.js +637 -534
- package/dist/extension/index.js.map +1 -1
- package/dist/extension/recorder.d.ts +95 -0
- package/dist/extension/recorder.js +530 -0
- package/dist/extension/recorder.js.map +1 -0
- package/dist/extension/remote-recorder-store.d.ts +25 -0
- package/dist/extension/remote-recorder-store.js +81 -0
- package/dist/extension/remote-recorder-store.js.map +1 -0
- package/dist/extension/session-events.d.ts +134 -0
- package/dist/extension/session-events.js +60 -0
- package/dist/extension/session-events.js.map +1 -0
- package/dist/extension/session-view.d.ts +2 -0
- package/dist/extension/session-view.js +60 -2
- package/dist/extension/session-view.js.map +1 -1
- package/dist/extension/step-message.d.ts +6 -4
- package/dist/extension/step-message.js +12 -6
- package/dist/extension/step-message.js.map +1 -1
- package/dist/extension/widget.d.ts +2 -2
- package/dist/extension/widget.js +28 -18
- package/dist/extension/widget.js.map +1 -1
- package/dist/extension/workflow-message-coordinator.d.ts +28 -0
- package/dist/extension/workflow-message-coordinator.js +346 -0
- package/dist/extension/workflow-message-coordinator.js.map +1 -0
- package/dist/host/channel-effects.d.ts +72 -0
- package/dist/host/channel-effects.js +271 -0
- package/dist/host/channel-effects.js.map +1 -0
- package/dist/host/channel-supervisor.d.ts +21 -0
- package/dist/host/channel-supervisor.js +54 -0
- package/dist/host/channel-supervisor.js.map +1 -0
- package/dist/host/runner.d.ts +50 -8
- package/dist/host/runner.js +1632 -341
- package/dist/host/runner.js.map +1 -1
- package/dist/host/state.d.ts +19 -16
- package/dist/host/state.js +251 -63
- package/dist/host/state.js.map +1 -1
- package/dist/host/view.d.ts +19 -9
- package/dist/host/view.js +227 -119
- package/dist/host/view.js.map +1 -1
- package/dist/host/worker-entry.d.ts +4 -1
- package/dist/host/worker-entry.js +23 -24
- package/dist/host/worker-entry.js.map +1 -1
- package/dist/host/worker-protocol.d.ts +15 -0
- package/dist/host/worker-protocol.js.map +1 -1
- package/dist/state/prune.js +3 -25
- package/dist/state/prune.js.map +1 -1
- package/dist/state/schema.js +76 -97
- package/dist/state/schema.js.map +1 -1
- package/dist/state/workflow-messages.d.ts +98 -0
- package/dist/state/workflow-messages.js +366 -0
- package/dist/state/workflow-messages.js.map +1 -0
- package/dist/viewer/render.js +1 -1
- package/dist/viewer/render.js.map +1 -1
- package/dist/viewer/tui.d.ts +1 -1
- package/dist/viewer/tui.js +65 -8
- package/dist/viewer/tui.js.map +1 -1
- package/dist/workflows/composition.js +0 -4
- package/dist/workflows/composition.js.map +1 -1
- package/dist/workflows/definition.js +0 -8
- package/dist/workflows/definition.js.map +1 -1
- package/dist/workflows/engine.js +4 -5
- package/dist/workflows/engine.js.map +1 -1
- package/dist/workflows/human-decision.d.ts +2 -0
- package/dist/workflows/human-decision.js +8 -2
- package/dist/workflows/human-decision.js.map +1 -1
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/schema.js +0 -4
- package/dist/workflows/schema.js.map +1 -1
- package/dist/workflows/settings.d.ts +1 -8
- package/dist/workflows/settings.js.map +1 -1
- package/dist/workflows/store.d.ts +20 -19
- package/dist/workflows/store.js +163 -354
- package/dist/workflows/store.js.map +1 -1
- package/dist/workflows/tool-input.d.ts +21 -0
- package/dist/workflows/tool-input.js +23 -1
- package/dist/workflows/tool-input.js.map +1 -1
- package/dist/workflows/types.d.ts +6 -8
- package/dist/workflows/workflow-message-content.d.ts +38 -0
- package/dist/workflows/workflow-message-content.js +157 -0
- package/dist/workflows/workflow-message-content.js.map +1 -0
- package/docs/2026-08-18-herdr-piw-plan.md +2 -1
- package/docs/2026-08-20-durable-workflow-launch-plan.md +1 -1
- package/docs/2026-08-25-workflow-follow-ups.md +26 -50
- package/docs/2026-08-30-out-of-process-workflow-host-plan.md +3 -3
- package/docs/2026-09-01-restore-session-delivery-controls-plan.md +4 -0
- package/docs/2026-09-01-unified-workflow-client-plan.md +5 -1
- package/docs/2026-09-02-installed-live-e2e-plan.md +15 -1
- package/docs/2026-09-02-unify-workflow-messages-plan.md +562 -0
- package/docs/2026-09-04-workflow-run-state-plan.md +363 -0
- package/docs/DEFERRED_TURNS.md +66 -294
- package/docs/HUMAN_DECISIONS.md +29 -30
- package/docs/HUMAN_DECISION_PRESENTATIONS.md +4 -11
- package/docs/SQLITE_STATE.md +25 -17
- package/docs/WORKFLOW_HOST.md +105 -31
- package/docs/WORKFLOW_STEP_MESSAGES.md +166 -75
- package/docs/live-replay-protocol.md +8 -4
- package/docs/tui-viewer.md +3 -1
- package/docs/workflows.md +44 -28
- package/herdr-plugin.toml +1 -1
- package/package.json +1 -1
- package/plugins/herdr/viewer.mjs +14 -5
- package/src/channels/adapter-entry.ts +220 -0
- package/src/channels/config.ts +296 -0
- package/src/channels/protocol.ts +333 -0
- package/src/channels/telegram.ts +335 -0
- package/src/client/client.ts +6 -2
- package/src/client/index.ts +2 -1
- package/src/client/protocol.ts +11 -5
- package/src/client/view.ts +51 -18
- package/src/controllers/index.ts +0 -1
- package/src/controllers/sqlite.ts +247 -845
- package/src/extension/index.ts +712 -647
- package/src/extension/recorder.ts +687 -0
- package/src/extension/remote-recorder-store.ts +126 -0
- package/src/extension/session-events.ts +119 -0
- package/src/extension/session-view.ts +86 -3
- package/src/extension/step-message.ts +19 -9
- package/src/extension/widget.ts +37 -17
- package/src/extension/workflow-message-coordinator.ts +398 -0
- package/src/host/channel-effects.ts +465 -0
- package/src/host/channel-supervisor.ts +73 -0
- package/src/host/runner.ts +2163 -525
- package/src/host/state.ts +333 -94
- package/src/host/view.ts +254 -122
- package/src/host/worker-entry.ts +38 -30
- package/src/host/worker-protocol.ts +11 -0
- package/src/state/prune.ts +3 -31
- package/src/state/schema.ts +76 -97
- package/src/state/workflow-messages.ts +599 -0
- package/src/viewer/render.ts +1 -5
- package/src/viewer/tui.ts +71 -6
- package/src/workflows/composition.ts +0 -5
- package/src/workflows/definition.ts +0 -8
- package/src/workflows/engine.ts +4 -6
- package/src/workflows/human-decision.ts +18 -2
- package/src/workflows/index.ts +0 -1
- package/src/workflows/schema.ts +0 -6
- package/src/workflows/settings.ts +1 -20
- package/src/workflows/store.ts +237 -489
- package/src/workflows/tool-input.ts +36 -1
- package/src/workflows/types.ts +6 -8
- package/src/workflows/workflow-message-content.ts +197 -0
- package/dist/extension/decision-channels.d.ts +0 -134
- package/dist/extension/decision-channels.js +0 -1307
- package/dist/extension/decision-channels.js.map +0 -1
- package/src/extension/decision-channels.ts +0 -1826
package/src/state/prune.ts
CHANGED
|
@@ -215,13 +215,7 @@ function treeHasBlocker(database: Database.Database, runIds: string[]): boolean
|
|
|
215
215
|
hasRow(
|
|
216
216
|
database,
|
|
217
217
|
`SELECT 1 FROM workflow_follow_ups
|
|
218
|
-
WHERE run_id IN (${values}) AND status
|
|
219
|
-
runIds,
|
|
220
|
-
) ||
|
|
221
|
-
hasRow(
|
|
222
|
-
database,
|
|
223
|
-
`SELECT 1 FROM workflow_follow_up_queues
|
|
224
|
-
WHERE run_id IN (${values}) AND presentation_state = 'pending'`,
|
|
218
|
+
WHERE run_id IN (${values}) AND status = 'queued'`,
|
|
225
219
|
runIds,
|
|
226
220
|
) ||
|
|
227
221
|
hasRow(
|
|
@@ -294,15 +288,8 @@ function deleteRunAggregates(database: Database.Database, runIds: string[]): voi
|
|
|
294
288
|
const effectIds = effectRows.map((row) => row.effectId);
|
|
295
289
|
if (effectIds.length !== 0) {
|
|
296
290
|
const effectValues = placeholders(effectIds);
|
|
297
|
-
database
|
|
298
|
-
.prepare(`DELETE FROM notifications WHERE effect_id IN (${effectValues})`)
|
|
299
|
-
.run(...effectIds);
|
|
300
|
-
database
|
|
301
|
-
.prepare(`DELETE FROM turn_intents WHERE effect_id IN (${effectValues})`)
|
|
302
|
-
.run(...effectIds);
|
|
303
291
|
database.prepare(`DELETE FROM effects WHERE effect_id IN (${effectValues})`).run(...effectIds);
|
|
304
292
|
}
|
|
305
|
-
database.prepare(`DELETE FROM turn_intents WHERE run_id IN (${values})`).run(...runIds);
|
|
306
293
|
database
|
|
307
294
|
.prepare(
|
|
308
295
|
`DELETE FROM continuations
|
|
@@ -331,13 +318,11 @@ function relatedResourceIds(database: Database.Database, runIds: string[]): stri
|
|
|
331
318
|
`SELECT resource_id AS resourceId FROM runs WHERE run_id IN (${values})
|
|
332
319
|
UNION SELECT resource_id FROM session_segments WHERE run_id IN (${values})
|
|
333
320
|
UNION SELECT resource_id FROM human_decisions WHERE run_id IN (${values})
|
|
334
|
-
UNION SELECT resource_id FROM turn_intents WHERE run_id IN (${values})
|
|
335
321
|
UNION SELECT resource_id FROM workflow_settings
|
|
336
322
|
WHERE origin_run_id IN (${values}) OR active_run_id IN (${values})
|
|
337
|
-
UNION SELECT resource_id FROM workflow_follow_up_queues WHERE run_id IN (${values})
|
|
338
323
|
UNION SELECT resource_id FROM workflow_follow_ups WHERE run_id IN (${values})`,
|
|
339
324
|
)
|
|
340
|
-
.all(...runIds, ...runIds, ...runIds, ...runIds, ...runIds, ...runIds
|
|
325
|
+
.all(...runIds, ...runIds, ...runIds, ...runIds, ...runIds, ...runIds)
|
|
341
326
|
.filter(isResourceRow);
|
|
342
327
|
const resources = rows.map((row) => row.resourceId);
|
|
343
328
|
if (resources.length === 0) return [];
|
|
@@ -349,20 +334,7 @@ function relatedResourceIds(database: Database.Database, runIds: string[]): stri
|
|
|
349
334
|
.all(...resources)
|
|
350
335
|
.filter(isResourceRow)
|
|
351
336
|
.map((row) => row.resourceId);
|
|
352
|
-
|
|
353
|
-
.prepare(
|
|
354
|
-
`SELECT resource.resource_id AS resourceId
|
|
355
|
-
FROM notifications notification
|
|
356
|
-
JOIN effects effect ON effect.effect_id = notification.effect_id
|
|
357
|
-
JOIN resources resource
|
|
358
|
-
ON resource.resource_type = 'notification'
|
|
359
|
-
AND resource.aggregate_key = notification.notification_id
|
|
360
|
-
WHERE effect.source_resource_id IN (${placeholders(resources)})`,
|
|
361
|
-
)
|
|
362
|
-
.all(...resources)
|
|
363
|
-
.filter(isResourceRow)
|
|
364
|
-
.map((row) => row.resourceId);
|
|
365
|
-
return [...new Set([...resources, ...effectResources, ...notificationResources])];
|
|
337
|
+
return [...new Set([...resources, ...effectResources])];
|
|
366
338
|
}
|
|
367
339
|
|
|
368
340
|
function selectionSignature(database: Database.Database, runIds: string[]): string {
|
package/src/state/schema.ts
CHANGED
|
@@ -56,8 +56,7 @@ CREATE TABLE blobs (
|
|
|
56
56
|
CREATE TABLE resources (
|
|
57
57
|
resource_id TEXT PRIMARY KEY,
|
|
58
58
|
resource_type TEXT NOT NULL CHECK (resource_type IN (
|
|
59
|
-
'run', 'session', 'decision', 'controller', 'effect', 'channel', '
|
|
60
|
-
'settings', 'follow_up_queue', 'follow_up'
|
|
59
|
+
'run', 'session', 'decision', 'controller', 'effect', 'channel', 'settings', 'follow_up'
|
|
61
60
|
)),
|
|
62
61
|
aggregate_key TEXT NOT NULL,
|
|
63
62
|
revision INTEGER NOT NULL DEFAULT 0 CHECK (revision >= 0),
|
|
@@ -115,6 +114,12 @@ CREATE TABLE runs (
|
|
|
115
114
|
resource_id TEXT NOT NULL UNIQUE REFERENCES resources(resource_id) ON DELETE CASCADE,
|
|
116
115
|
project_id TEXT REFERENCES projects(project_id),
|
|
117
116
|
parent_run_id TEXT REFERENCES runs(run_id),
|
|
117
|
+
root_run_id TEXT NOT NULL REFERENCES runs(run_id),
|
|
118
|
+
lineage_kind TEXT CHECK (lineage_kind IS NULL OR lineage_kind IN ('continuation', 'restart')),
|
|
119
|
+
restart_number INTEGER NOT NULL DEFAULT 0 CHECK (restart_number >= 0),
|
|
120
|
+
parent_terminal_fingerprint BLOB CHECK (
|
|
121
|
+
parent_terminal_fingerprint IS NULL OR length(parent_terminal_fingerprint) = 32
|
|
122
|
+
),
|
|
118
123
|
definition_digest BLOB NOT NULL REFERENCES workflow_definitions(definition_digest),
|
|
119
124
|
workflow_ref TEXT NOT NULL,
|
|
120
125
|
launch_options_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
@@ -127,15 +132,24 @@ CREATE TABLE runs (
|
|
|
127
132
|
input_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
128
133
|
final_output_hash BLOB REFERENCES blobs(blob_hash),
|
|
129
134
|
error_hash BLOB REFERENCES blobs(blob_hash),
|
|
135
|
+
presentation_prompt_hash BLOB REFERENCES blobs(blob_hash),
|
|
130
136
|
created_at INTEGER NOT NULL,
|
|
131
137
|
updated_at INTEGER NOT NULL,
|
|
132
138
|
finished_at INTEGER,
|
|
133
|
-
CHECK ((status IN ('waiting', 'completed', 'failed', 'timed_out', 'cancelled')) = (finished_at IS NOT NULL))
|
|
139
|
+
CHECK ((status IN ('waiting', 'completed', 'failed', 'timed_out', 'cancelled')) = (finished_at IS NOT NULL)),
|
|
140
|
+
CHECK ((parent_run_id IS NULL) = (lineage_kind IS NULL)),
|
|
141
|
+
CHECK (
|
|
142
|
+
(lineage_kind = 'restart' AND parent_terminal_fingerprint IS NOT NULL) OR
|
|
143
|
+
(lineage_kind IS NOT 'restart' AND parent_terminal_fingerprint IS NULL)
|
|
144
|
+
),
|
|
145
|
+
CHECK (parent_run_id IS NOT NULL OR restart_number = 0)
|
|
134
146
|
) STRICT;
|
|
135
147
|
|
|
136
148
|
CREATE INDEX runs_project_idx ON runs(project_id, created_at DESC);
|
|
137
149
|
CREATE INDEX runs_status_idx ON runs(status, updated_at DESC);
|
|
138
150
|
CREATE INDEX runs_parent_idx ON runs(parent_run_id);
|
|
151
|
+
CREATE UNIQUE INDEX runs_restart_parent_idx ON runs(parent_run_id)
|
|
152
|
+
WHERE lineage_kind = 'restart';
|
|
139
153
|
|
|
140
154
|
CREATE TABLE run_view_content (
|
|
141
155
|
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
@@ -233,33 +247,10 @@ CREATE TABLE workflow_setting_changes (
|
|
|
233
247
|
UNIQUE (scope_id, change_number)
|
|
234
248
|
) STRICT;
|
|
235
249
|
|
|
236
|
-
CREATE TABLE workflow_follow_up_queues (
|
|
237
|
-
run_id TEXT PRIMARY KEY REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
238
|
-
resource_id TEXT NOT NULL UNIQUE REFERENCES resources(resource_id) ON DELETE CASCADE,
|
|
239
|
-
origin_session_id TEXT,
|
|
240
|
-
presentation_state TEXT NOT NULL DEFAULT 'none' CHECK (presentation_state IN (
|
|
241
|
-
'none', 'not-needed', 'pending', 'settled', 'unavailable'
|
|
242
|
-
)),
|
|
243
|
-
presentation_entry_id TEXT,
|
|
244
|
-
presentation_assistant_entry_id TEXT,
|
|
245
|
-
presentation_reason_hash BLOB REFERENCES blobs(blob_hash),
|
|
246
|
-
presentation_updated_at INTEGER,
|
|
247
|
-
created_at INTEGER NOT NULL,
|
|
248
|
-
updated_at INTEGER NOT NULL,
|
|
249
|
-
CHECK (
|
|
250
|
-
(presentation_state IN ('none', 'not-needed', 'pending') AND presentation_assistant_entry_id IS NULL AND presentation_reason_hash IS NULL)
|
|
251
|
-
OR
|
|
252
|
-
(presentation_state = 'unavailable' AND presentation_assistant_entry_id IS NULL AND presentation_reason_hash IS NOT NULL)
|
|
253
|
-
OR
|
|
254
|
-
(presentation_state = 'settled' AND presentation_entry_id IS NOT NULL AND presentation_assistant_entry_id IS NOT NULL AND presentation_reason_hash IS NULL)
|
|
255
|
-
)
|
|
256
|
-
) STRICT;
|
|
257
|
-
|
|
258
250
|
CREATE TABLE workflow_follow_ups (
|
|
259
251
|
follow_up_id TEXT PRIMARY KEY,
|
|
260
252
|
resource_id TEXT NOT NULL UNIQUE REFERENCES resources(resource_id) ON DELETE CASCADE,
|
|
261
|
-
|
|
262
|
-
run_id TEXT NOT NULL REFERENCES workflow_follow_up_queues(run_id) ON DELETE CASCADE,
|
|
253
|
+
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
263
254
|
request_id TEXT NOT NULL,
|
|
264
255
|
order_number INTEGER NOT NULL CHECK (order_number > 0),
|
|
265
256
|
target_session_id TEXT NOT NULL,
|
|
@@ -269,21 +260,17 @@ CREATE TABLE workflow_follow_ups (
|
|
|
269
260
|
actor_id TEXT,
|
|
270
261
|
source_type TEXT NOT NULL,
|
|
271
262
|
prompt_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
272
|
-
status TEXT NOT NULL CHECK (status IN (
|
|
273
|
-
'queued', 'pending_presentation', 'ready', 'sent', 'removed', 'cancelled'
|
|
274
|
-
)),
|
|
275
|
-
session_entry_id TEXT,
|
|
263
|
+
status TEXT NOT NULL CHECK (status IN ('queued', 'removed', 'cancelled')),
|
|
276
264
|
reason_hash BLOB REFERENCES blobs(blob_hash),
|
|
277
265
|
created_at INTEGER NOT NULL,
|
|
278
266
|
updated_at INTEGER NOT NULL,
|
|
279
|
-
sent_at INTEGER,
|
|
280
267
|
UNIQUE (run_id, request_id),
|
|
281
268
|
UNIQUE (run_id, order_number),
|
|
282
|
-
CHECK ((status = 'sent') = (session_entry_id IS NOT NULL AND sent_at IS NOT NULL)),
|
|
283
269
|
CHECK ((status IN ('removed', 'cancelled')) = (reason_hash IS NOT NULL))
|
|
284
270
|
) STRICT;
|
|
285
271
|
|
|
286
|
-
CREATE INDEX
|
|
272
|
+
CREATE INDEX workflow_follow_ups_order_idx
|
|
273
|
+
ON workflow_follow_ups(target_session_id, run_id, order_number);
|
|
287
274
|
|
|
288
275
|
CREATE TABLE run_queue (
|
|
289
276
|
run_id TEXT PRIMARY KEY REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
@@ -312,7 +299,9 @@ CREATE TABLE host_commands (
|
|
|
312
299
|
operation TEXT NOT NULL CHECK (operation IN (
|
|
313
300
|
'run.start', 'run.pause', 'run.resume', 'run.cancel', 'run.status', 'run.list',
|
|
314
301
|
'checkpoint.answer', 'decision.answer', 'interaction.submit', 'interaction.update',
|
|
315
|
-
'
|
|
302
|
+
'workflowMessage.reportBranch', 'workflowTurn.report', 'sessionView.clearTerminal',
|
|
303
|
+
'run.restart', 'run.changeSettings', 'followUp.queue', 'followUp.remove', 'session.record',
|
|
304
|
+
'channel.reload', 'channel.recover',
|
|
316
305
|
'controller.list', 'controller.get', 'controller.apply', 'controller.reconcile', 'controller.delete',
|
|
317
306
|
'host.status', 'host.stop', 'state.backup', 'state.prune'
|
|
318
307
|
)),
|
|
@@ -518,24 +507,70 @@ CREATE TABLE interactive_requests (
|
|
|
518
507
|
kind TEXT NOT NULL CHECK (kind IN ('agent', 'assistant', 'decision')),
|
|
519
508
|
contract_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
520
509
|
revision INTEGER NOT NULL DEFAULT 1 CHECK (revision > 0),
|
|
521
|
-
status TEXT NOT NULL CHECK (status IN ('pending', '
|
|
522
|
-
|
|
523
|
-
presentation_claim_expires_at INTEGER,
|
|
524
|
-
presentation_session_entry_id TEXT,
|
|
510
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'settled', 'cancelled')),
|
|
511
|
+
unproductive_turn_ends INTEGER NOT NULL DEFAULT 0 CHECK (unproductive_turn_ends >= 0),
|
|
525
512
|
accepted_submission_id TEXT,
|
|
526
513
|
created_at INTEGER NOT NULL,
|
|
527
514
|
updated_at INTEGER NOT NULL,
|
|
528
515
|
settled_at INTEGER,
|
|
529
516
|
consumed_at INTEGER,
|
|
530
517
|
CHECK ((status = 'settled') = (accepted_submission_id IS NOT NULL AND settled_at IS NOT NULL)),
|
|
531
|
-
CHECK ((presenter_id IS NULL) = (presentation_claim_expires_at IS NULL)),
|
|
532
|
-
CHECK (presenter_id IS NULL OR status = 'presenting'),
|
|
533
518
|
CHECK (consumed_at IS NULL OR status = 'settled')
|
|
534
519
|
) STRICT;
|
|
535
520
|
|
|
536
521
|
CREATE INDEX interactive_requests_session_idx
|
|
537
522
|
ON interactive_requests(target_session_id, status, created_at);
|
|
538
523
|
|
|
524
|
+
CREATE TABLE workflow_messages (
|
|
525
|
+
workflow_message_id TEXT PRIMARY KEY,
|
|
526
|
+
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
527
|
+
target_session_id TEXT NOT NULL,
|
|
528
|
+
kind TEXT NOT NULL CHECK (kind IN ('step', 'decision', 'notification', 'terminal', 'followUp')),
|
|
529
|
+
source_id TEXT NOT NULL,
|
|
530
|
+
content_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
531
|
+
order_number INTEGER NOT NULL CHECK (order_number > 0),
|
|
532
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'sent', 'cancelled')),
|
|
533
|
+
pi_session_entry_id TEXT,
|
|
534
|
+
created_at INTEGER NOT NULL,
|
|
535
|
+
updated_at INTEGER NOT NULL,
|
|
536
|
+
UNIQUE (target_session_id, order_number),
|
|
537
|
+
CHECK ((status = 'sent') = (pi_session_entry_id IS NOT NULL))
|
|
538
|
+
) STRICT;
|
|
539
|
+
|
|
540
|
+
CREATE INDEX workflow_messages_session_idx
|
|
541
|
+
ON workflow_messages(target_session_id, status, order_number);
|
|
542
|
+
CREATE INDEX workflow_messages_run_idx ON workflow_messages(run_id, order_number);
|
|
543
|
+
CREATE INDEX workflow_messages_source_idx ON workflow_messages(kind, source_id, order_number);
|
|
544
|
+
CREATE UNIQUE INDEX workflow_messages_pending_step_source_idx
|
|
545
|
+
ON workflow_messages(source_id) WHERE kind = 'step' AND status = 'pending';
|
|
546
|
+
|
|
547
|
+
CREATE TABLE workflow_turns (
|
|
548
|
+
workflow_turn_id TEXT PRIMARY KEY,
|
|
549
|
+
workflow_message_id TEXT NOT NULL REFERENCES workflow_messages(workflow_message_id) ON DELETE CASCADE,
|
|
550
|
+
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
551
|
+
target_session_id TEXT NOT NULL,
|
|
552
|
+
state TEXT NOT NULL CHECK (state IN ('started', 'ended')),
|
|
553
|
+
stop_reason TEXT CHECK (stop_reason IS NULL OR stop_reason IN ('completed', 'aborted', 'error', 'lost')),
|
|
554
|
+
response_session_entry_id TEXT,
|
|
555
|
+
started_at INTEGER NOT NULL,
|
|
556
|
+
ended_at INTEGER,
|
|
557
|
+
CHECK (
|
|
558
|
+
(state = 'started' AND stop_reason IS NULL AND ended_at IS NULL)
|
|
559
|
+
OR
|
|
560
|
+
(state = 'ended' AND stop_reason IS NOT NULL AND ended_at IS NOT NULL)
|
|
561
|
+
)
|
|
562
|
+
) STRICT;
|
|
563
|
+
|
|
564
|
+
CREATE UNIQUE INDEX workflow_turns_open_message_idx
|
|
565
|
+
ON workflow_turns(workflow_message_id) WHERE state = 'started';
|
|
566
|
+
CREATE INDEX workflow_turns_session_idx ON workflow_turns(target_session_id, state, started_at);
|
|
567
|
+
|
|
568
|
+
CREATE TABLE session_terminal_views (
|
|
569
|
+
target_session_id TEXT PRIMARY KEY,
|
|
570
|
+
cleared_run_id TEXT REFERENCES runs(run_id) ON DELETE SET NULL,
|
|
571
|
+
cleared_at INTEGER NOT NULL
|
|
572
|
+
) STRICT;
|
|
573
|
+
|
|
539
574
|
CREATE TABLE interactive_submissions (
|
|
540
575
|
submission_id TEXT PRIMARY KEY,
|
|
541
576
|
request_id TEXT NOT NULL REFERENCES interactive_requests(request_id) ON DELETE CASCADE,
|
|
@@ -681,39 +716,6 @@ CREATE TABLE effect_attempts (
|
|
|
681
716
|
PRIMARY KEY (effect_id, attempt_number)
|
|
682
717
|
) STRICT;
|
|
683
718
|
|
|
684
|
-
CREATE TABLE notifications (
|
|
685
|
-
notification_id TEXT PRIMARY KEY,
|
|
686
|
-
effect_id TEXT NOT NULL UNIQUE REFERENCES effects(effect_id),
|
|
687
|
-
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
688
|
-
attempt_id TEXT NOT NULL REFERENCES node_attempts(attempt_id),
|
|
689
|
-
notification_index INTEGER NOT NULL CHECK (notification_index >= 0),
|
|
690
|
-
target_session_id TEXT NOT NULL,
|
|
691
|
-
notification_type TEXT NOT NULL CHECK (notification_type IN ('progress', 'final')),
|
|
692
|
-
content_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
693
|
-
created_at INTEGER NOT NULL,
|
|
694
|
-
UNIQUE (run_id, attempt_id, notification_index)
|
|
695
|
-
) STRICT;
|
|
696
|
-
|
|
697
|
-
CREATE TABLE turn_intents (
|
|
698
|
-
turn_intent_id TEXT PRIMARY KEY,
|
|
699
|
-
resource_id TEXT NOT NULL UNIQUE REFERENCES resources(resource_id),
|
|
700
|
-
effect_id TEXT NOT NULL UNIQUE REFERENCES effects(effect_id),
|
|
701
|
-
source_event_id TEXT NOT NULL UNIQUE,
|
|
702
|
-
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
703
|
-
workflow_ref TEXT NOT NULL,
|
|
704
|
-
target_session_id TEXT NOT NULL,
|
|
705
|
-
cause TEXT NOT NULL,
|
|
706
|
-
node_id TEXT,
|
|
707
|
-
attempt_id TEXT,
|
|
708
|
-
resolution_type TEXT,
|
|
709
|
-
resolution_message_id TEXT,
|
|
710
|
-
facts_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
711
|
-
requested_at INTEGER NOT NULL,
|
|
712
|
-
eligible_at INTEGER,
|
|
713
|
-
resolved_at INTEGER,
|
|
714
|
-
created_at INTEGER NOT NULL
|
|
715
|
-
) STRICT;
|
|
716
|
-
|
|
717
719
|
CREATE TABLE channels (
|
|
718
720
|
channel_id TEXT PRIMARY KEY,
|
|
719
721
|
resource_id TEXT NOT NULL UNIQUE REFERENCES resources(resource_id),
|
|
@@ -731,41 +733,18 @@ CREATE TABLE channel_cursors (
|
|
|
731
733
|
PRIMARY KEY (channel_id, cursor_key)
|
|
732
734
|
) STRICT;
|
|
733
735
|
|
|
734
|
-
CREATE TABLE channel_inbox (
|
|
735
|
-
channel_id TEXT NOT NULL REFERENCES channels(channel_id) ON DELETE CASCADE,
|
|
736
|
-
external_event_id TEXT NOT NULL,
|
|
737
|
-
event_type TEXT NOT NULL CHECK (event_type IN ('callback', 'reply')),
|
|
738
|
-
payload_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
739
|
-
received_at INTEGER NOT NULL,
|
|
740
|
-
processed_at INTEGER,
|
|
741
|
-
result_hash BLOB REFERENCES blobs(blob_hash),
|
|
742
|
-
PRIMARY KEY (channel_id, external_event_id)
|
|
743
|
-
) STRICT;
|
|
744
|
-
|
|
745
736
|
CREATE TABLE channel_messages (
|
|
746
737
|
message_id TEXT PRIMARY KEY,
|
|
747
738
|
channel_id TEXT NOT NULL REFERENCES channels(channel_id) ON DELETE CASCADE,
|
|
748
739
|
decision_id TEXT REFERENCES human_decisions(decision_id),
|
|
749
740
|
purpose TEXT NOT NULL CHECK (purpose IN ('delivery', 'settlement')),
|
|
750
741
|
content_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
751
|
-
external_conversation_ref TEXT,
|
|
752
|
-
external_message_ref TEXT,
|
|
753
742
|
status TEXT NOT NULL CHECK (status IN ('pending', 'confirmed', 'failed', 'ambiguous')),
|
|
754
743
|
created_at INTEGER NOT NULL,
|
|
755
744
|
updated_at INTEGER NOT NULL
|
|
756
745
|
) STRICT;
|
|
757
746
|
|
|
758
747
|
CREATE INDEX channel_messages_decision_idx ON channel_messages(decision_id, purpose, created_at);
|
|
759
|
-
|
|
760
|
-
CREATE TABLE channel_message_parts (
|
|
761
|
-
message_id TEXT NOT NULL REFERENCES channel_messages(message_id) ON DELETE CASCADE,
|
|
762
|
-
recipient_index INTEGER NOT NULL CHECK (recipient_index >= 0),
|
|
763
|
-
part_index INTEGER NOT NULL CHECK (part_index >= 0),
|
|
764
|
-
content_hash BLOB NOT NULL REFERENCES blobs(blob_hash),
|
|
765
|
-
external_conversation_ref TEXT NOT NULL,
|
|
766
|
-
external_message_ref TEXT NOT NULL,
|
|
767
|
-
PRIMARY KEY (message_id, recipient_index, part_index)
|
|
768
|
-
) STRICT;
|
|
769
748
|
`;
|
|
770
749
|
|
|
771
750
|
export const STATE_SCHEMA_DIGEST = createHash("sha256").update(STATE_SCHEMA_SQL).digest();
|