@sixb/sqlite 0.1.0 → 0.1.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 -13
- package/dist/action-run-storage.d.ts +5 -2
- package/dist/action-run-storage.d.ts.map +1 -1
- package/dist/agents/agent-storage.d.ts +4 -2
- package/dist/agents/agent-storage.d.ts.map +1 -1
- package/dist/agents/rows.d.ts +3 -10
- package/dist/agents/rows.d.ts.map +1 -1
- package/dist/agents/runs.d.ts +3 -2
- package/dist/agents/runs.d.ts.map +1 -1
- package/dist/ai-usage-storage.d.ts +22 -0
- package/dist/ai-usage-storage.d.ts.map +1 -0
- package/dist/auth-storage/service-accounts.d.ts.map +1 -1
- package/dist/auth-storage/shared.d.ts +1 -10
- package/dist/auth-storage/shared.d.ts.map +1 -1
- package/dist/connector-connection-storage.d.ts +9 -0
- package/dist/connector-connection-storage.d.ts.map +1 -0
- package/dist/execution-storage.d.ts +14 -0
- package/dist/execution-storage.d.ts.map +1 -0
- package/dist/index.d.ts +13 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4114 -1149
- package/dist/index.js.map +30 -27
- package/dist/latest-run-query.d.ts.map +1 -1
- package/dist/migrations.d.ts +0 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-session.d.ts +50 -8
- package/dist/ontology-storage/materialization-session.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-state.d.ts +4 -5
- package/dist/ontology-storage/materialization-state.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-writer.d.ts.map +1 -1
- package/dist/ontology-storage/materializations.d.ts +0 -2
- package/dist/ontology-storage/materializations.d.ts.map +1 -1
- package/dist/ontology-storage/outbox.d.ts.map +1 -1
- package/dist/ontology-storage/shared.d.ts +3 -3
- package/dist/ontology-storage/shared.d.ts.map +1 -1
- package/dist/ontology-storage/sources.d.ts.map +1 -1
- package/dist/pipeline-run-storage.d.ts +7 -2
- package/dist/pipeline-run-storage.d.ts.map +1 -1
- package/dist/projection-run-storage.d.ts +9 -2
- package/dist/projection-run-storage.d.ts.map +1 -1
- package/dist/run-list-query.d.ts +1 -1
- package/dist/run-list-query.d.ts.map +1 -1
- package/dist/sync-run-storage.d.ts +7 -2
- package/dist/sync-run-storage.d.ts.map +1 -1
- package/dist/testing.d.ts +6 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/transactions.d.ts +3 -0
- package/dist/transactions.d.ts.map +1 -1
- package/dist/webhook-run-storage.d.ts +9 -2
- package/dist/webhook-run-storage.d.ts.map +1 -1
- package/dist/workflow-run-storage.d.ts +7 -3
- package/dist/workflow-run-storage.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/action-run-storage.ts +51 -74
- package/src/agents/agent-storage.ts +5 -3
- package/src/agents/rows.ts +8 -40
- package/src/agents/runs.ts +27 -21
- package/src/ai-usage-storage.ts +324 -0
- package/src/auth-storage/service-accounts.ts +14 -21
- package/src/auth-storage/shared.ts +0 -22
- package/src/connector-connection-storage.ts +784 -0
- package/src/execution-storage.ts +158 -0
- package/src/index.ts +63 -22
- package/src/latest-run-query.ts +7 -1
- package/src/migrations/002-workflow-run-output.sql +27 -0
- package/src/migrations/003-merge-sync-runs.sql +71 -0
- package/src/migrations/004-executions.sql +142 -0
- package/src/migrations/005-workflow-executions.sql +7 -0
- package/src/migrations/006-narrow-ontology-source-root-index.sql +4 -0
- package/src/migrations/007-split-overrides.sql +154 -0
- package/src/migrations/008-action-executions.sql +4 -0
- package/src/migrations/009-agent-executions.sql +115 -0
- package/src/migrations/010-ai-usage-accounting-foundation.sql +74 -0
- package/src/migrations/011-sync-failure-record.sql +22 -0
- package/src/migrations/012-pipeline-failure-record.sql +45 -0
- package/src/migrations/013-workflow-failure-record.sql +45 -0
- package/src/migrations/014-agent-failure-record.sql +59 -0
- package/src/migrations/015-projection-failure-record.sql +20 -0
- package/src/migrations/016-webhook-run-failure-record.sql +19 -0
- package/src/migrations/017-action-failure-record.sql +65 -0
- package/src/migrations/018-ontology-outbox-failure-record.sql +80 -0
- package/src/migrations/019-webhook-delivery-failure-record.sql +62 -0
- package/src/migrations/020-drop-run-usage-projections.sql +7 -0
- package/src/migrations/021-sync-pipeline-executions.sql +101 -0
- package/src/migrations/022-projection-executions.sql +244 -0
- package/src/migrations/023-webhook-executions.sql +51 -0
- package/src/migrations/024-ontology-commit-executions.sql +58 -0
- package/src/migrations/025-connector-connections.sql +257 -0
- package/src/migrations.ts +126 -5
- package/src/ontology-storage/materialization-session.ts +317 -143
- package/src/ontology-storage/materialization-state.ts +398 -150
- package/src/ontology-storage/materialization-writer.ts +142 -67
- package/src/ontology-storage/materializations.ts +67 -141
- package/src/ontology-storage/outbox.ts +10 -3
- package/src/ontology-storage/shared.ts +10 -4
- package/src/ontology-storage/sources.ts +4 -1
- package/src/pipeline-run-storage.ts +128 -43
- package/src/projection-run-storage.ts +209 -97
- package/src/run-list-query.ts +9 -4
- package/src/sync-run-storage.ts +120 -34
- package/src/testing.ts +20 -0
- package/src/transactions.ts +10 -3
- package/src/webhook-run-storage.ts +118 -74
- package/src/workflow-run-storage.ts +124 -133
- package/dist/validation.d.ts +0 -5
- package/dist/validation.d.ts.map +0 -1
- package/dist/webhook-delivery-storage.d.ts +0 -27
- package/dist/webhook-delivery-storage.d.ts.map +0 -1
- package/src/validation.ts +0 -30
- package/src/webhook-delivery-storage.ts +0 -272
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite"
|
|
2
|
-
import
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
`[SixbSqlite] Workflow run '${input.id}'
|
|
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
|
-
|
|
178
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
})()
|
|
@@ -290,15 +253,20 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
|
|
|
290
253
|
SET
|
|
291
254
|
status = ?,
|
|
292
255
|
finished_at = ?,
|
|
293
|
-
|
|
294
|
-
|
|
256
|
+
output = ?,
|
|
257
|
+
error = ?,
|
|
258
|
+
execution_token = NULL,
|
|
259
|
+
execution_queue_lease_expires_at = NULL
|
|
295
260
|
WHERE project_id = ? AND id = ?
|
|
296
261
|
`
|
|
297
262
|
)
|
|
298
263
|
.run(
|
|
299
264
|
input.status,
|
|
300
265
|
(input.finishedAt ?? new Date()).toISOString(),
|
|
301
|
-
input.status === "succeeded" ?
|
|
266
|
+
input.status === "succeeded" ? serializeRecord(input.output) : null,
|
|
267
|
+
input.status === "succeeded" || input.error === undefined
|
|
268
|
+
? null
|
|
269
|
+
: serializeSixbFailure(input.error, WORKFLOW_RUN_FAILURE_CODES),
|
|
302
270
|
input.projectId,
|
|
303
271
|
input.id
|
|
304
272
|
)
|
|
@@ -493,19 +461,51 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
|
|
|
493
461
|
}
|
|
494
462
|
|
|
495
463
|
export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunStorage {
|
|
496
|
-
constructor(
|
|
464
|
+
constructor(
|
|
465
|
+
private readonly db: Database,
|
|
466
|
+
private readonly executions: ExecutionStorage
|
|
467
|
+
) {}
|
|
497
468
|
|
|
498
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
|
+
|
|
499
498
|
try {
|
|
500
499
|
this.db
|
|
501
500
|
.query(`
|
|
502
501
|
INSERT INTO workflow_agent_node_runs (
|
|
503
|
-
project_id, node_run_id, agent_id, status, prompt, attempt, created_at
|
|
504
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
502
|
+
project_id, node_run_id, execution_id, agent_id, status, prompt, attempt, created_at
|
|
503
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
505
504
|
`)
|
|
506
505
|
.run(
|
|
507
506
|
input.projectId,
|
|
508
507
|
input.nodeRunId,
|
|
508
|
+
input.executionId,
|
|
509
509
|
input.agentId,
|
|
510
510
|
"queued",
|
|
511
511
|
input.prompt,
|
|
@@ -529,14 +529,12 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
|
|
|
529
529
|
this.db
|
|
530
530
|
.query(`
|
|
531
531
|
UPDATE workflow_agent_node_runs SET
|
|
532
|
-
status = ?,
|
|
533
|
-
|
|
532
|
+
status = ?, model_id = ?, attempt = 1, execution_token = ?,
|
|
533
|
+
execution_queue_lease_expires_at = ?, started_at = ?
|
|
534
534
|
WHERE project_id = ? AND node_run_id = ?
|
|
535
535
|
`)
|
|
536
536
|
.run(
|
|
537
537
|
"running",
|
|
538
|
-
input.executionPrincipal?.type ?? null,
|
|
539
|
-
input.executionPrincipal?.id ?? null,
|
|
540
538
|
input.modelId ?? null,
|
|
541
539
|
input.execution.token,
|
|
542
540
|
input.execution.queueLeaseExpiresAt.toISOString(),
|
|
@@ -598,7 +596,7 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
|
|
|
598
596
|
this.db
|
|
599
597
|
.query(`
|
|
600
598
|
UPDATE workflow_agent_node_runs SET
|
|
601
|
-
status = ?, model_id = COALESCE(?, model_id), finish_reason = ?,
|
|
599
|
+
status = ?, model_id = COALESCE(?, model_id), finish_reason = ?, trace = ?,
|
|
602
600
|
diagnostics = ?, error = ?, execution_token = NULL,
|
|
603
601
|
execution_queue_lease_expires_at = NULL, completed_at = ?
|
|
604
602
|
WHERE project_id = ? AND node_run_id = ?
|
|
@@ -607,10 +605,11 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
|
|
|
607
605
|
input.status,
|
|
608
606
|
input.modelId ?? null,
|
|
609
607
|
input.finishReason ?? null,
|
|
610
|
-
input.usage ? JSON.stringify(input.usage) : null,
|
|
611
608
|
input.trace ? JSON.stringify(input.trace) : null,
|
|
612
609
|
input.diagnostics ? JSON.stringify(input.diagnostics) : null,
|
|
613
|
-
input.status === "succeeded"
|
|
610
|
+
input.status === "succeeded" || input.error === undefined
|
|
611
|
+
? null
|
|
612
|
+
: serializeSixbFailure(input.error, AGENT_RUN_FAILURE_CODES),
|
|
614
613
|
(input.completedAt ?? new Date()).toISOString(),
|
|
615
614
|
input.projectId,
|
|
616
615
|
input.nodeRunId
|
|
@@ -635,7 +634,9 @@ export class SqliteWorkflowAgentNodeRunStorage implements WorkflowAgentNodeRunSt
|
|
|
635
634
|
)
|
|
636
635
|
.run(
|
|
637
636
|
"cancelled",
|
|
638
|
-
input.error
|
|
637
|
+
input.error === undefined
|
|
638
|
+
? null
|
|
639
|
+
: serializeSixbFailure(input.error, AGENT_RUN_FAILURE_CODES),
|
|
639
640
|
(input.completedAt ?? new Date()).toISOString(),
|
|
640
641
|
input.projectId,
|
|
641
642
|
input.nodeRunId
|
|
@@ -832,7 +833,9 @@ export class SqliteWorkflowNodeRunStorage implements WorkflowNodeRunStorage {
|
|
|
832
833
|
input.status,
|
|
833
834
|
(input.finishedAt ?? new Date()).toISOString(),
|
|
834
835
|
input.status === "succeeded" && input.output ? serializeRecord(input.output) : null,
|
|
835
|
-
input.status === "succeeded"
|
|
836
|
+
input.status === "succeeded" || input.error === undefined
|
|
837
|
+
? null
|
|
838
|
+
: serializeSixbFailure(input.error, WORKFLOW_RUN_FAILURE_CODES),
|
|
836
839
|
input.projectId,
|
|
837
840
|
input.id
|
|
838
841
|
)
|
|
@@ -971,18 +974,16 @@ function rowToWorkflowRunRecord(row: WorkflowRunDatabaseRow): WorkflowRunRecord
|
|
|
971
974
|
return {
|
|
972
975
|
id: row.id,
|
|
973
976
|
projectId: row.project_id,
|
|
977
|
+
executionId: row.execution_id,
|
|
974
978
|
workflowId: row.workflow_id,
|
|
975
979
|
status: row.status,
|
|
976
980
|
input: parseRecord(row.input),
|
|
981
|
+
output: row.output ? parseRecord(row.output) : undefined,
|
|
977
982
|
queuedAt: row.queued_at ? new Date(row.queued_at) : undefined,
|
|
978
983
|
startedAt: new Date(row.started_at),
|
|
979
984
|
finishedAt: row.finished_at ? new Date(row.finished_at) : undefined,
|
|
980
|
-
error: row.error
|
|
981
|
-
|
|
982
|
-
requestedByPrincipal: {
|
|
983
|
-
type: row.requested_by_principal_type,
|
|
984
|
-
id: row.requested_by_principal_id,
|
|
985
|
-
},
|
|
985
|
+
error: row.error === null ? undefined : parseSixbFailure(row.error, WORKFLOW_RUN_FAILURE_CODES),
|
|
986
|
+
requesterGroupIds: JSON.parse(row.requester_group_ids) as string[],
|
|
986
987
|
attempt: row.attempt,
|
|
987
988
|
...(row.execution_token && row.execution_queue_lease_expires_at
|
|
988
989
|
? {
|
|
@@ -1010,7 +1011,7 @@ function rowToWorkflowNodeRunRecord(row: WorkflowNodeRunDatabaseRow): WorkflowNo
|
|
|
1010
1011
|
startedAt: new Date(row.started_at),
|
|
1011
1012
|
finishedAt: row.finished_at ? new Date(row.finished_at) : undefined,
|
|
1012
1013
|
output: row.output ? parseRecord(row.output) : undefined,
|
|
1013
|
-
error: row.error
|
|
1014
|
+
error: row.error === null ? undefined : parseSixbFailure(row.error, WORKFLOW_RUN_FAILURE_CODES),
|
|
1014
1015
|
}
|
|
1015
1016
|
}
|
|
1016
1017
|
|
|
@@ -1036,16 +1037,16 @@ function canFinishWorkflowRun(
|
|
|
1036
1037
|
interface WorkflowRunDatabaseRow {
|
|
1037
1038
|
project_id: string
|
|
1038
1039
|
id: string
|
|
1040
|
+
execution_id: string
|
|
1039
1041
|
workflow_id: string
|
|
1040
1042
|
status: WorkflowRunRecord["status"]
|
|
1041
1043
|
input: string
|
|
1044
|
+
output: string | null
|
|
1042
1045
|
queued_at: string | null
|
|
1043
1046
|
started_at: string
|
|
1044
1047
|
finished_at: string | null
|
|
1045
1048
|
error: string | null
|
|
1046
|
-
|
|
1047
|
-
requested_by_principal_type: Principal["type"]
|
|
1048
|
-
requested_by_principal_id: string
|
|
1049
|
+
requester_group_ids: string
|
|
1049
1050
|
attempt: number
|
|
1050
1051
|
execution_token: string | null
|
|
1051
1052
|
execution_queue_lease_expires_at: string | null
|
|
@@ -1071,14 +1072,12 @@ interface WorkflowNodeRunDatabaseRow {
|
|
|
1071
1072
|
interface WorkflowAgentNodeRunDatabaseRow {
|
|
1072
1073
|
project_id: string
|
|
1073
1074
|
node_run_id: string
|
|
1075
|
+
execution_id: string
|
|
1074
1076
|
agent_id: string
|
|
1075
1077
|
status: WorkflowAgentNodeRunRecord["status"]
|
|
1076
1078
|
prompt: string
|
|
1077
|
-
execution_principal_type: "serviceAccount" | null
|
|
1078
|
-
execution_principal_id: string | null
|
|
1079
1079
|
model_id: string | null
|
|
1080
1080
|
finish_reason: WorkflowAgentNodeRunRecord["finishReason"] | null
|
|
1081
|
-
usage: string | null
|
|
1082
1081
|
trace: string | null
|
|
1083
1082
|
diagnostics: string | null
|
|
1084
1083
|
error: string | null
|
|
@@ -1107,23 +1106,15 @@ function rowToWorkflowAgentNodeRunRecord(
|
|
|
1107
1106
|
return {
|
|
1108
1107
|
projectId: row.project_id,
|
|
1109
1108
|
nodeRunId: row.node_run_id,
|
|
1109
|
+
executionId: row.execution_id,
|
|
1110
1110
|
agentId: row.agent_id,
|
|
1111
1111
|
status: row.status,
|
|
1112
1112
|
prompt: row.prompt,
|
|
1113
|
-
...(row.execution_principal_type && row.execution_principal_id
|
|
1114
|
-
? {
|
|
1115
|
-
executionPrincipal: {
|
|
1116
|
-
type: row.execution_principal_type,
|
|
1117
|
-
id: row.execution_principal_id,
|
|
1118
|
-
},
|
|
1119
|
-
}
|
|
1120
|
-
: {}),
|
|
1121
1113
|
...(row.model_id ? { modelId: row.model_id } : {}),
|
|
1122
1114
|
...(row.finish_reason ? { finishReason: row.finish_reason } : {}),
|
|
1123
|
-
...(row.usage ? { usage: JSON.parse(row.usage) } : {}),
|
|
1124
1115
|
...(row.trace ? { trace: JSON.parse(row.trace) } : {}),
|
|
1125
1116
|
...(row.diagnostics ? { diagnostics: JSON.parse(row.diagnostics) } : {}),
|
|
1126
|
-
...(row.error ? { error: row.error } : {}),
|
|
1117
|
+
...(row.error ? { error: parseSixbFailure(row.error, AGENT_RUN_FAILURE_CODES) } : {}),
|
|
1127
1118
|
attempt: row.attempt,
|
|
1128
1119
|
...(row.execution_token && row.execution_queue_lease_expires_at
|
|
1129
1120
|
? {
|
package/dist/validation.d.ts
DELETED
|
@@ -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
|
package/dist/validation.d.ts.map
DELETED
|
@@ -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
|
-
}
|