@sixb/sqlite 0.1.1 → 0.1.3

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 (123) hide show
  1. package/README.md +18 -13
  2. package/dist/action-run-storage.d.ts +5 -2
  3. package/dist/action-run-storage.d.ts.map +1 -1
  4. package/dist/agents/agent-storage.d.ts +9 -5
  5. package/dist/agents/agent-storage.d.ts.map +1 -1
  6. package/dist/agents/checkpoints.d.ts +14 -0
  7. package/dist/agents/checkpoints.d.ts.map +1 -0
  8. package/dist/agents/index.d.ts +1 -0
  9. package/dist/agents/index.d.ts.map +1 -1
  10. package/dist/agents/messages.d.ts +2 -1
  11. package/dist/agents/messages.d.ts.map +1 -1
  12. package/dist/agents/rows.d.ts +21 -11
  13. package/dist/agents/rows.d.ts.map +1 -1
  14. package/dist/agents/runs.d.ts +3 -2
  15. package/dist/agents/runs.d.ts.map +1 -1
  16. package/dist/ai-cost-storage.d.ts +15 -0
  17. package/dist/ai-cost-storage.d.ts.map +1 -0
  18. package/dist/ai-usage-storage.d.ts +22 -0
  19. package/dist/ai-usage-storage.d.ts.map +1 -0
  20. package/dist/auth-storage/service-accounts.d.ts.map +1 -1
  21. package/dist/auth-storage/shared.d.ts +1 -10
  22. package/dist/auth-storage/shared.d.ts.map +1 -1
  23. package/dist/connector-connection-storage.d.ts +9 -0
  24. package/dist/connector-connection-storage.d.ts.map +1 -0
  25. package/dist/execution-storage.d.ts +14 -0
  26. package/dist/execution-storage.d.ts.map +1 -0
  27. package/dist/index.d.ts +14 -9
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4633 -1066
  30. package/dist/index.js.map +33 -28
  31. package/dist/latest-run-query.d.ts.map +1 -1
  32. package/dist/migrations.d.ts +0 -1
  33. package/dist/migrations.d.ts.map +1 -1
  34. package/dist/ontology-storage/materialization-session.d.ts +50 -8
  35. package/dist/ontology-storage/materialization-session.d.ts.map +1 -1
  36. package/dist/ontology-storage/materialization-state.d.ts +4 -5
  37. package/dist/ontology-storage/materialization-state.d.ts.map +1 -1
  38. package/dist/ontology-storage/materialization-writer.d.ts.map +1 -1
  39. package/dist/ontology-storage/materializations.d.ts +0 -2
  40. package/dist/ontology-storage/materializations.d.ts.map +1 -1
  41. package/dist/ontology-storage/outbox.d.ts.map +1 -1
  42. package/dist/ontology-storage/shared.d.ts +3 -3
  43. package/dist/ontology-storage/shared.d.ts.map +1 -1
  44. package/dist/ontology-storage/sources.d.ts.map +1 -1
  45. package/dist/pipeline-run-storage.d.ts +7 -2
  46. package/dist/pipeline-run-storage.d.ts.map +1 -1
  47. package/dist/projection-run-storage.d.ts +9 -2
  48. package/dist/projection-run-storage.d.ts.map +1 -1
  49. package/dist/run-list-query.d.ts +1 -1
  50. package/dist/run-list-query.d.ts.map +1 -1
  51. package/dist/sync-run-storage.d.ts +7 -2
  52. package/dist/sync-run-storage.d.ts.map +1 -1
  53. package/dist/testing.d.ts +6 -0
  54. package/dist/testing.d.ts.map +1 -0
  55. package/dist/transactions.d.ts +3 -0
  56. package/dist/transactions.d.ts.map +1 -1
  57. package/dist/webhook-run-storage.d.ts +9 -2
  58. package/dist/webhook-run-storage.d.ts.map +1 -1
  59. package/dist/workflow-run-storage.d.ts +7 -3
  60. package/dist/workflow-run-storage.d.ts.map +1 -1
  61. package/package.json +3 -3
  62. package/src/action-run-storage.ts +51 -74
  63. package/src/agents/agent-storage.ts +11 -6
  64. package/src/agents/checkpoints.ts +175 -0
  65. package/src/agents/index.ts +1 -0
  66. package/src/agents/messages.ts +59 -0
  67. package/src/agents/rows.ts +52 -40
  68. package/src/agents/runs.ts +27 -21
  69. package/src/ai-cost-storage.ts +744 -0
  70. package/src/ai-usage-storage.ts +324 -0
  71. package/src/auth-storage/service-accounts.ts +14 -21
  72. package/src/auth-storage/shared.ts +0 -22
  73. package/src/connector-connection-storage.ts +784 -0
  74. package/src/execution-storage.ts +158 -0
  75. package/src/index.ts +69 -22
  76. package/src/latest-run-query.ts +7 -1
  77. package/src/migrations/004-executions.sql +142 -0
  78. package/src/migrations/005-workflow-executions.sql +7 -0
  79. package/src/migrations/006-narrow-ontology-source-root-index.sql +4 -0
  80. package/src/migrations/007-split-overrides.sql +154 -0
  81. package/src/migrations/008-action-executions.sql +4 -0
  82. package/src/migrations/009-agent-executions.sql +115 -0
  83. package/src/migrations/010-ai-usage-accounting-foundation.sql +74 -0
  84. package/src/migrations/011-sync-failure-record.sql +22 -0
  85. package/src/migrations/012-pipeline-failure-record.sql +45 -0
  86. package/src/migrations/013-workflow-failure-record.sql +45 -0
  87. package/src/migrations/014-agent-failure-record.sql +59 -0
  88. package/src/migrations/015-projection-failure-record.sql +20 -0
  89. package/src/migrations/016-webhook-run-failure-record.sql +19 -0
  90. package/src/migrations/017-action-failure-record.sql +65 -0
  91. package/src/migrations/018-ontology-outbox-failure-record.sql +80 -0
  92. package/src/migrations/019-webhook-delivery-failure-record.sql +62 -0
  93. package/src/migrations/020-drop-run-usage-projections.sql +7 -0
  94. package/src/migrations/021-sync-pipeline-executions.sql +101 -0
  95. package/src/migrations/022-projection-executions.sql +244 -0
  96. package/src/migrations/023-webhook-executions.sql +51 -0
  97. package/src/migrations/024-ontology-commit-executions.sql +58 -0
  98. package/src/migrations/025-connector-connections.sql +257 -0
  99. package/src/migrations/026-ai-cost-accounting.sql +57 -0
  100. package/src/migrations/027-agent-context-checkpoints.sql +28 -0
  101. package/src/migrations/028-object-override-edit-times.sql +3 -0
  102. package/src/migrations.ts +129 -4
  103. package/src/ontology-storage/materialization-session.ts +317 -143
  104. package/src/ontology-storage/materialization-state.ts +323 -112
  105. package/src/ontology-storage/materialization-writer.ts +145 -67
  106. package/src/ontology-storage/materializations.ts +67 -141
  107. package/src/ontology-storage/outbox.ts +10 -3
  108. package/src/ontology-storage/shared.ts +10 -4
  109. package/src/ontology-storage/sources.ts +4 -1
  110. package/src/pipeline-run-storage.ts +128 -43
  111. package/src/projection-run-storage.ts +209 -97
  112. package/src/run-list-query.ts +9 -4
  113. package/src/sync-run-storage.ts +118 -32
  114. package/src/testing.ts +20 -0
  115. package/src/transactions.ts +10 -3
  116. package/src/webhook-run-storage.ts +118 -74
  117. package/src/workflow-run-storage.ts +117 -131
  118. package/dist/validation.d.ts +0 -5
  119. package/dist/validation.d.ts.map +0 -1
  120. package/dist/webhook-delivery-storage.d.ts +0 -27
  121. package/dist/webhook-delivery-storage.d.ts.map +0 -1
  122. package/src/validation.ts +0 -30
  123. package/src/webhook-delivery-storage.ts +0 -272
@@ -1,11 +1,17 @@
1
1
  import type { Database } from "bun:sqlite"
2
- import type { Principal, WorkflowRunSource } from "@sixb/core"
2
+ import { normalizeRequesterGroupIds } from "@sixb/core/internal/auth"
3
+ import { parseSixbFailure, serializeSixbFailure } from "@sixb/core/internal/errors"
4
+ import {
5
+ assertWorkflowAgentNodeRunExecution,
6
+ assertWorkflowRunExecution,
7
+ } from "@sixb/core/internal/workflow-run-storage-provider"
3
8
  import type { WorkflowIOSnapshot } from "@sixb/core/internal/workflows"
4
9
  import type {
5
10
  CancelWorkflowAgentNodeRunInput,
6
11
  ConfirmWorkflowAgentNodeRunExecutionOwnershipInput,
7
12
  ConfirmWorkflowRunExecutionOwnershipInput,
8
13
  CreateWorkflowAgentNodeRunInput,
14
+ ExecutionStorage,
9
15
  FinishWorkflowAgentNodeRunInput,
10
16
  FinishWorkflowNodeRunInput,
11
17
  FinishWorkflowRunInput,
@@ -33,7 +39,11 @@ import type {
33
39
  WorkflowRunRecord,
34
40
  WorkflowRunStorage,
35
41
  } from "@sixb/core/storage"
36
- import { WorkflowRunError } from "@sixb/core/storage"
42
+ import {
43
+ AGENT_RUN_FAILURE_CODES,
44
+ WORKFLOW_RUN_FAILURE_CODES,
45
+ WorkflowRunError,
46
+ } from "@sixb/core/storage"
37
47
  import { queryLatestRunsByOwnerId } from "./latest-run-query"
38
48
  import { installFreshSqliteSchema } from "./migrations"
39
49
  import {
@@ -50,6 +60,8 @@ import {
50
60
  } from "./transactions"
51
61
 
52
62
  export interface SqliteWorkflowRunStorageOptions {
63
+ /** Execution lookup sharing the same provider transaction. */
64
+ executions: ExecutionStorage
53
65
  /** Path to SQLite database file. Defaults to ':memory:' for in-memory database. */
54
66
  path?: string
55
67
  /** Internal shared connection used by bundled SqliteStorage. */
@@ -62,21 +74,30 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
62
74
 
63
75
  private readonly connection: SqliteStoreConnection
64
76
  private readonly db: Database
77
+ private readonly executions: ExecutionStorage
65
78
 
66
- constructor(options: SqliteWorkflowRunStorageOptions = {}) {
79
+ constructor(options: SqliteWorkflowRunStorageOptions) {
67
80
  this.connection = openSqliteStoreConnection(options)
68
81
  this.db = this.connection.db
82
+ this.executions = options.executions
69
83
 
70
84
  if (this.connection.installFreshSchema) {
71
85
  installFreshSqliteSchema(this.db)
72
86
  }
73
87
 
74
88
  this.nodes = new SqliteWorkflowNodeRunStorage(this.db)
75
- this.agentNodes = new SqliteWorkflowAgentNodeRunStorage(this.db)
89
+ this.agentNodes = new SqliteWorkflowAgentNodeRunStorage(this.db, this.executions)
76
90
  }
77
91
 
78
92
  async queue(input: QueueWorkflowRunInput): Promise<WorkflowRunRecord> {
79
93
  const queuedAt = input.queuedAt ?? new Date()
94
+ await assertWorkflowRunExecution({
95
+ executions: this.executions,
96
+ projectId: input.projectId,
97
+ executionId: input.executionId,
98
+ runId: input.id,
99
+ workflowId: input.workflowId,
100
+ })
80
101
 
81
102
  try {
82
103
  this.db
@@ -85,35 +106,33 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
85
106
  INSERT INTO workflow_runs (
86
107
  project_id,
87
108
  id,
109
+ execution_id,
88
110
  workflow_id,
89
111
  status,
90
112
  input,
91
113
  queued_at,
92
114
  started_at,
93
- source,
94
- requested_by_principal_type,
95
- requested_by_principal_id,
115
+ requester_group_ids,
96
116
  attempt
97
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
117
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
98
118
  `
99
119
  )
100
120
  .run(
101
121
  input.projectId,
102
122
  input.id,
123
+ input.executionId,
103
124
  input.workflowId,
104
125
  "queued",
105
126
  serializeRecord(input.input),
106
127
  queuedAt.toISOString(),
107
128
  queuedAt.toISOString(),
108
- input.source ? JSON.stringify(input.source) : null,
109
- input.requestedByPrincipal?.type ?? "system",
110
- input.requestedByPrincipal?.id ?? "system",
129
+ JSON.stringify(normalizeRequesterGroupIds(input.requesterGroupIds)),
111
130
  0
112
131
  )
113
132
  } catch (error) {
114
133
  if (isUniqueConstraintError(error)) {
115
134
  throw new WorkflowRunError(
116
- `[SixbSqlite] Workflow run '${input.id}' already exists for project '${input.projectId}'.`
135
+ `[SixbSqlite] Workflow run '${input.id}' or execution '${input.executionId}' is already linked for project '${input.projectId}'.`
117
136
  )
118
137
  }
119
138
 
@@ -131,92 +150,36 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
131
150
  .query("SELECT * FROM workflow_runs WHERE project_id = ? AND id = ?")
132
151
  .get(input.projectId, input.id) as WorkflowRunDatabaseRow | null
133
152
 
134
- if (existing) {
135
- if (existing.status !== "queued") {
136
- throw new WorkflowRunError(
137
- `[SixbSqlite] Workflow run '${input.id}' already exists for project '${input.projectId}'.`
138
- )
139
- }
140
-
141
- if (existing.workflow_id !== input.workflowId) {
142
- throw new WorkflowRunError(
143
- `[SixbSqlite] Workflow run '${input.id}' workflow '${input.workflowId}' does not match existing workflow '${existing.workflow_id}'.`
144
- )
145
- }
146
-
147
- this.db
148
- .query(
149
- `
150
- UPDATE workflow_runs
151
- SET
152
- status = ?,
153
- input = ?,
154
- started_at = ?,
155
- finished_at = NULL,
156
- error = NULL,
157
- source = COALESCE(source, ?)
158
- , attempt = attempt + 1,
159
- execution_token = ?, execution_queue_lease_expires_at = ?
160
- WHERE project_id = ? AND id = ?
161
- `
162
- )
163
- .run(
164
- "running",
165
- serializeRecord(input.input),
166
- startedAt.toISOString(),
167
- input.source ? JSON.stringify(input.source) : null,
168
- input.execution?.token ?? null,
169
- input.execution?.queueLeaseExpiresAt.toISOString() ?? null,
170
- input.projectId,
171
- input.id
172
- )
173
-
174
- return this.requireWorkflowRun(input.projectId, input.id)
153
+ if (!existing || existing.status !== "queued") {
154
+ throw new WorkflowRunError(
155
+ existing
156
+ ? `[SixbSqlite] Workflow run '${input.id}' cannot start from status '${existing.status}'.`
157
+ : `[SixbSqlite] Workflow run '${input.id}' not found for project '${input.projectId}'.`
158
+ )
175
159
  }
176
160
 
177
- try {
178
- this.db
179
- .query(
180
- `
181
- INSERT INTO workflow_runs (
182
- project_id,
183
- id,
184
- workflow_id,
185
- status,
186
- input,
187
- started_at,
188
- source,
189
- requested_by_principal_type,
190
- requested_by_principal_id,
191
- attempt,
192
- execution_token,
193
- execution_queue_lease_expires_at
194
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
161
+ this.db
162
+ .query(
195
163
  `
196
- )
197
- .run(
198
- input.projectId,
199
- input.id,
200
- input.workflowId,
201
- "running",
202
- serializeRecord(input.input),
203
- startedAt.toISOString(),
204
- input.source ? JSON.stringify(input.source) : null,
205
- input.requestedByPrincipal?.type ?? "system",
206
- input.requestedByPrincipal?.id ?? "system",
207
- 1,
208
- input.execution?.token ?? null,
209
- input.execution?.queueLeaseExpiresAt.toISOString() ?? null
210
- )
211
- } catch (error) {
212
- if (isUniqueConstraintError(error)) {
213
- throw new WorkflowRunError(
214
- `[SixbSqlite] Workflow run '${input.id}' already exists for project '${input.projectId}'.`
215
- )
216
- }
217
-
218
- throw error
219
- }
164
+ UPDATE workflow_runs
165
+ SET
166
+ status = ?,
167
+ started_at = ?,
168
+ finished_at = NULL,
169
+ error = NULL,
170
+ attempt = attempt + 1,
171
+ execution_token = ?, execution_queue_lease_expires_at = ?
172
+ WHERE project_id = ? AND id = ?
173
+ `
174
+ )
175
+ .run(
176
+ "running",
177
+ startedAt.toISOString(),
178
+ input.execution?.token ?? null,
179
+ input.execution?.queueLeaseExpiresAt.toISOString() ?? null,
180
+ input.projectId,
181
+ input.id
182
+ )
220
183
 
221
184
  return this.requireWorkflowRun(input.projectId, input.id)
222
185
  })()
@@ -301,7 +264,9 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
301
264
  input.status,
302
265
  (input.finishedAt ?? new Date()).toISOString(),
303
266
  input.status === "succeeded" ? serializeRecord(input.output) : null,
304
- input.status === "succeeded" ? null : (input.error ?? null),
267
+ input.status === "succeeded" || input.error === undefined
268
+ ? null
269
+ : serializeSixbFailure(input.error, WORKFLOW_RUN_FAILURE_CODES),
305
270
  input.projectId,
306
271
  input.id
307
272
  )
@@ -496,19 +461,51 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
496
461
  }
497
462
 
498
463
  export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunStorage {
499
- constructor(private readonly db: Database) {}
464
+ constructor(
465
+ private readonly db: Database,
466
+ private readonly executions: ExecutionStorage
467
+ ) {}
500
468
 
501
469
  async create(input: CreateWorkflowAgentNodeRunInput): Promise<WorkflowAgentNodeRunRecord> {
470
+ const parent = this.db
471
+ .query(
472
+ `
473
+ SELECT workflow_runs.execution_id
474
+ FROM workflow_node_runs
475
+ JOIN workflow_runs
476
+ ON workflow_runs.project_id = workflow_node_runs.project_id
477
+ AND workflow_runs.id = workflow_node_runs.workflow_run_id
478
+ WHERE workflow_node_runs.project_id = ?
479
+ AND workflow_node_runs.id = ?
480
+ AND workflow_node_runs.node_type = 'agent'
481
+ `
482
+ )
483
+ .get(input.projectId, input.nodeRunId) as { execution_id: string } | null
484
+ if (!parent) {
485
+ throw new WorkflowRunError(
486
+ `[SixbSqlite] Agent workflow node run '${input.nodeRunId}' was not found.`
487
+ )
488
+ }
489
+ await assertWorkflowAgentNodeRunExecution({
490
+ executions: this.executions,
491
+ projectId: input.projectId,
492
+ executionId: input.executionId,
493
+ nodeRunId: input.nodeRunId,
494
+ agentId: input.agentId,
495
+ workflowExecutionId: parent.execution_id,
496
+ })
497
+
502
498
  try {
503
499
  this.db
504
500
  .query(`
505
501
  INSERT INTO workflow_agent_node_runs (
506
- project_id, node_run_id, agent_id, status, prompt, attempt, created_at
507
- ) VALUES (?, ?, ?, ?, ?, ?, ?)
502
+ project_id, node_run_id, execution_id, agent_id, status, prompt, attempt, created_at
503
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
508
504
  `)
509
505
  .run(
510
506
  input.projectId,
511
507
  input.nodeRunId,
508
+ input.executionId,
512
509
  input.agentId,
513
510
  "queued",
514
511
  input.prompt,
@@ -532,14 +529,12 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
532
529
  this.db
533
530
  .query(`
534
531
  UPDATE workflow_agent_node_runs SET
535
- status = ?, execution_principal_type = ?, execution_principal_id = ?, model_id = ?,
536
- attempt = 1, execution_token = ?, execution_queue_lease_expires_at = ?, started_at = ?
532
+ status = ?, model_id = ?, attempt = 1, execution_token = ?,
533
+ execution_queue_lease_expires_at = ?, started_at = ?
537
534
  WHERE project_id = ? AND node_run_id = ?
538
535
  `)
539
536
  .run(
540
537
  "running",
541
- input.executionPrincipal?.type ?? null,
542
- input.executionPrincipal?.id ?? null,
543
538
  input.modelId ?? null,
544
539
  input.execution.token,
545
540
  input.execution.queueLeaseExpiresAt.toISOString(),
@@ -601,7 +596,7 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
601
596
  this.db
602
597
  .query(`
603
598
  UPDATE workflow_agent_node_runs SET
604
- status = ?, model_id = COALESCE(?, model_id), finish_reason = ?, usage = ?, trace = ?,
599
+ status = ?, model_id = COALESCE(?, model_id), finish_reason = ?, trace = ?,
605
600
  diagnostics = ?, error = ?, execution_token = NULL,
606
601
  execution_queue_lease_expires_at = NULL, completed_at = ?
607
602
  WHERE project_id = ? AND node_run_id = ?
@@ -610,10 +605,11 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
610
605
  input.status,
611
606
  input.modelId ?? null,
612
607
  input.finishReason ?? null,
613
- input.usage ? JSON.stringify(input.usage) : null,
614
608
  input.trace ? JSON.stringify(input.trace) : null,
615
609
  input.diagnostics ? JSON.stringify(input.diagnostics) : null,
616
- input.status === "succeeded" ? null : (input.error ?? null),
610
+ input.status === "succeeded" || input.error === undefined
611
+ ? null
612
+ : serializeSixbFailure(input.error, AGENT_RUN_FAILURE_CODES),
617
613
  (input.completedAt ?? new Date()).toISOString(),
618
614
  input.projectId,
619
615
  input.nodeRunId
@@ -638,7 +634,9 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
638
634
  )
639
635
  .run(
640
636
  "cancelled",
641
- input.error ?? null,
637
+ input.error === undefined
638
+ ? null
639
+ : serializeSixbFailure(input.error, AGENT_RUN_FAILURE_CODES),
642
640
  (input.completedAt ?? new Date()).toISOString(),
643
641
  input.projectId,
644
642
  input.nodeRunId
@@ -835,7 +833,9 @@ export class SqliteWorkflowNodeRunStorage implements WorkflowNodeRunStorage {
835
833
  input.status,
836
834
  (input.finishedAt ?? new Date()).toISOString(),
837
835
  input.status === "succeeded" && input.output ? serializeRecord(input.output) : null,
838
- input.status === "succeeded" ? null : (input.error ?? null),
836
+ input.status === "succeeded" || input.error === undefined
837
+ ? null
838
+ : serializeSixbFailure(input.error, WORKFLOW_RUN_FAILURE_CODES),
839
839
  input.projectId,
840
840
  input.id
841
841
  )
@@ -974,6 +974,7 @@ function rowToWorkflowRunRecord(row: WorkflowRunDatabaseRow): WorkflowRunRecord
974
974
  return {
975
975
  id: row.id,
976
976
  projectId: row.project_id,
977
+ executionId: row.execution_id,
977
978
  workflowId: row.workflow_id,
978
979
  status: row.status,
979
980
  input: parseRecord(row.input),
@@ -981,12 +982,8 @@ function rowToWorkflowRunRecord(row: WorkflowRunDatabaseRow): WorkflowRunRecord
981
982
  queuedAt: row.queued_at ? new Date(row.queued_at) : undefined,
982
983
  startedAt: new Date(row.started_at),
983
984
  finishedAt: row.finished_at ? new Date(row.finished_at) : undefined,
984
- error: row.error ?? undefined,
985
- source: row.source ? (JSON.parse(row.source) as WorkflowRunSource) : undefined,
986
- requestedByPrincipal: {
987
- type: row.requested_by_principal_type,
988
- id: row.requested_by_principal_id,
989
- },
985
+ error: row.error === null ? undefined : parseSixbFailure(row.error, WORKFLOW_RUN_FAILURE_CODES),
986
+ requesterGroupIds: JSON.parse(row.requester_group_ids) as string[],
990
987
  attempt: row.attempt,
991
988
  ...(row.execution_token && row.execution_queue_lease_expires_at
992
989
  ? {
@@ -1014,7 +1011,7 @@ function rowToWorkflowNodeRunRecord(row: WorkflowNodeRunDatabaseRow): WorkflowNo
1014
1011
  startedAt: new Date(row.started_at),
1015
1012
  finishedAt: row.finished_at ? new Date(row.finished_at) : undefined,
1016
1013
  output: row.output ? parseRecord(row.output) : undefined,
1017
- error: row.error ?? undefined,
1014
+ error: row.error === null ? undefined : parseSixbFailure(row.error, WORKFLOW_RUN_FAILURE_CODES),
1018
1015
  }
1019
1016
  }
1020
1017
 
@@ -1040,6 +1037,7 @@ function canFinishWorkflowRun(
1040
1037
  interface WorkflowRunDatabaseRow {
1041
1038
  project_id: string
1042
1039
  id: string
1040
+ execution_id: string
1043
1041
  workflow_id: string
1044
1042
  status: WorkflowRunRecord["status"]
1045
1043
  input: string
@@ -1048,9 +1046,7 @@ interface WorkflowRunDatabaseRow {
1048
1046
  started_at: string
1049
1047
  finished_at: string | null
1050
1048
  error: string | null
1051
- source: string | null
1052
- requested_by_principal_type: Principal["type"]
1053
- requested_by_principal_id: string
1049
+ requester_group_ids: string
1054
1050
  attempt: number
1055
1051
  execution_token: string | null
1056
1052
  execution_queue_lease_expires_at: string | null
@@ -1076,14 +1072,12 @@ interface WorkflowNodeRunDatabaseRow {
1076
1072
  interface WorkflowAgentNodeRunDatabaseRow {
1077
1073
  project_id: string
1078
1074
  node_run_id: string
1075
+ execution_id: string
1079
1076
  agent_id: string
1080
1077
  status: WorkflowAgentNodeRunRecord["status"]
1081
1078
  prompt: string
1082
- execution_principal_type: "serviceAccount" | null
1083
- execution_principal_id: string | null
1084
1079
  model_id: string | null
1085
1080
  finish_reason: WorkflowAgentNodeRunRecord["finishReason"] | null
1086
- usage: string | null
1087
1081
  trace: string | null
1088
1082
  diagnostics: string | null
1089
1083
  error: string | null
@@ -1112,23 +1106,15 @@ function rowToWorkflowAgentNodeRunRecord(
1112
1106
  return {
1113
1107
  projectId: row.project_id,
1114
1108
  nodeRunId: row.node_run_id,
1109
+ executionId: row.execution_id,
1115
1110
  agentId: row.agent_id,
1116
1111
  status: row.status,
1117
1112
  prompt: row.prompt,
1118
- ...(row.execution_principal_type && row.execution_principal_id
1119
- ? {
1120
- executionPrincipal: {
1121
- type: row.execution_principal_type,
1122
- id: row.execution_principal_id,
1123
- },
1124
- }
1125
- : {}),
1126
1113
  ...(row.model_id ? { modelId: row.model_id } : {}),
1127
1114
  ...(row.finish_reason ? { finishReason: row.finish_reason } : {}),
1128
- ...(row.usage ? { usage: JSON.parse(row.usage) } : {}),
1129
1115
  ...(row.trace ? { trace: JSON.parse(row.trace) } : {}),
1130
1116
  ...(row.diagnostics ? { diagnostics: JSON.parse(row.diagnostics) } : {}),
1131
- ...(row.error ? { error: row.error } : {}),
1117
+ ...(row.error ? { error: parseSixbFailure(row.error, AGENT_RUN_FAILURE_CODES) } : {}),
1132
1118
  attempt: row.attempt,
1133
1119
  ...(row.execution_token && row.execution_queue_lease_expires_at
1134
1120
  ? {
@@ -1,5 +0,0 @@
1
- export declare function assertProjectionRunFieldNonEmpty(value: string, fieldName: string): void;
2
- export declare function assertProjectionRunCounter(value: number, fieldName: string): void;
3
- export declare function assertOptionalProjectionRunCounter(value: number | undefined, fieldName: string): void;
4
- export declare function assertProjectionRunListWindowValue(value: number, fieldName: string): void;
5
- //# sourceMappingURL=validation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAEA,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAIvF;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAMjF;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,MAAM,GAChB,IAAI,CAIN;AAED,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAIzF"}
@@ -1,27 +0,0 @@
1
- import type { WebhookDeliveryClaimRecord, WebhookDeliveryKey, WebhookDeliveryRecord, WebhookDeliveryStorage } from "@sixb/core/storage";
2
- import { type SqliteStoreConnection } from "./transactions";
3
- export interface SqliteWebhookDeliveryStorageOptions {
4
- /** Path to SQLite database file. Defaults to ':memory:' for in-memory database. */
5
- path?: string;
6
- /** Internal shared connection used by bundled SqliteStorage. */
7
- connection?: SqliteStoreConnection;
8
- }
9
- export declare class SqliteWebhookDeliveryStorage implements WebhookDeliveryStorage {
10
- private readonly connection;
11
- private readonly db;
12
- constructor(options?: SqliteWebhookDeliveryStorageOptions);
13
- claim(input: WebhookDeliveryKey & {
14
- receivedAt: string;
15
- }): Promise<WebhookDeliveryClaimRecord>;
16
- complete(input: WebhookDeliveryKey & {
17
- completedAt: string;
18
- }): Promise<WebhookDeliveryRecord>;
19
- fail(input: WebhookDeliveryKey & {
20
- failedAt: string;
21
- error: string;
22
- }): Promise<WebhookDeliveryRecord>;
23
- close(): void;
24
- private getDeliveryRecord;
25
- private requireDeliveryRecord;
26
- }
27
- //# sourceMappingURL=webhook-delivery-storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook-delivery-storage.d.ts","sourceRoot":"","sources":["../src/webhook-delivery-storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAE1B,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,mCAAmC;IAClD,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gEAAgE;IAChE,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC;AAED,qBAAa,4BAA6B,YAAW,sBAAsB;IACzE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAU;gBAEjB,OAAO,GAAE,mCAAwC;IASvD,KAAK,CACT,KAAK,EAAE,kBAAkB,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GACjD,OAAO,CAAC,0BAA0B,CAAC;IAyFhC,QAAQ,CACZ,KAAK,EAAE,kBAAkB,GAAG;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAClD,OAAO,CAAC,qBAAqB,CAAC;IA0B3B,IAAI,CACR,KAAK,EAAE,kBAAkB,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAC9D,OAAO,CAAC,qBAAqB,CAAC;IA0BjC,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,iBAAiB;IA+BzB,OAAO,CAAC,qBAAqB;CAc9B"}
package/src/validation.ts DELETED
@@ -1,30 +0,0 @@
1
- import { ProjectionRunError } from "@sixb/core/storage"
2
-
3
- export function assertProjectionRunFieldNonEmpty(value: string, fieldName: string): void {
4
- if (value.trim().length === 0) {
5
- throw new ProjectionRunError(`[SixbSqlite] Projection run ${fieldName} must not be empty.`)
6
- }
7
- }
8
-
9
- export function assertProjectionRunCounter(value: number, fieldName: string): void {
10
- if (!Number.isInteger(value) || value < 0) {
11
- throw new ProjectionRunError(
12
- `[SixbSqlite] Projection run ${fieldName} must be a non-negative integer.`
13
- )
14
- }
15
- }
16
-
17
- export function assertOptionalProjectionRunCounter(
18
- value: number | undefined,
19
- fieldName: string
20
- ): void {
21
- if (value !== undefined) {
22
- assertProjectionRunCounter(value, fieldName)
23
- }
24
- }
25
-
26
- export function assertProjectionRunListWindowValue(value: number, fieldName: string): void {
27
- if (!Number.isInteger(value) || value < 0) {
28
- throw new ProjectionRunError(`[SixbSqlite] Projection run list ${fieldName} must be >= 0.`)
29
- }
30
- }