| 1 | import { ArchiveObjectHash, ThreadId } from "@t3tools/contracts"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | |
| 4 | export const payloadTables = ["messages", "turn_items", "subagents"] as const; |
| 5 | export const Table = Schema.Literals(payloadTables); |
| 6 | const Cell = Schema.Union([Schema.String, Schema.Number, Schema.Null]); |
| 7 | export const Row = Schema.Record(Schema.String, Cell); |
| 8 | export const Segment = Schema.Struct({ table: Table, rows: Schema.Array(Row) }); |
| 9 | export const Metadata = Schema.Array(Segment); |
| 10 | export const canonicalTables = [ |
| 11 | "threads", |
| 12 | "runs", |
| 13 | "run_attempts", |
| 14 | "nodes", |
| 15 | "subagents", |
| 16 | "provider_sessions", |
| 17 | "provider_session_bindings", |
| 18 | "provider_threads", |
| 19 | "provider_turns", |
| 20 | "runtime_requests", |
| 21 | "messages", |
| 22 | "plans", |
| 23 | "turn_items", |
| 24 | "checkpoint_scopes", |
| 25 | "checkpoints", |
| 26 | "context_handoffs", |
| 27 | "context_transfers", |
| 28 | ] as const; |
| 29 | export const CanonicalTable = Schema.Literals( |
| 30 | canonicalTables.map((name) => `orchestration_v2_projection_${name}`), |
| 31 | ); |
| 32 | export const Bundle = Schema.Struct({ |
| 33 | version: Schema.Literal(1), |
| 34 | threadId: ThreadId, |
| 35 | throughSequence: Schema.Number, |
| 36 | segments: Schema.Array(Schema.Struct({ table: Table, hash: ArchiveObjectHash })), |
| 37 | events: ArchiveObjectHash, |
| 38 | context: Schema.Array(Schema.Struct({ table: CanonicalTable, hash: ArchiveObjectHash })), |
| 39 | assets: Schema.Array(Schema.Struct({ path: Schema.String, hash: ArchiveObjectHash })), |
| 40 | }); |