@smithers-orchestrator/db 0.16.0
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/LICENSE +21 -0
- package/package.json +43 -0
- package/src/JsonBounds.ts +6 -0
- package/src/SchemaRegistryEntry.ts +6 -0
- package/src/SqlMessageStorage.js +818 -0
- package/src/SqlMessageStorageEventHistoryQuery.ts +7 -0
- package/src/SqliteWriteRetryOptions.ts +7 -0
- package/src/adapter/AlertRow.ts +29 -0
- package/src/adapter/AlertSeverity.ts +2 -0
- package/src/adapter/AlertStatus.ts +2 -0
- package/src/adapter/ApprovalRow.ts +13 -0
- package/src/adapter/AttemptRow.ts +17 -0
- package/src/adapter/CacheRow.ts +12 -0
- package/src/adapter/DB_ALERT_ALLOWED_SEVERITIES.js +5 -0
- package/src/adapter/DB_ALERT_ALLOWED_STATUSES.js +6 -0
- package/src/adapter/DB_ALERT_ID_MAX_LENGTH.js +1 -0
- package/src/adapter/DB_ALERT_MESSAGE_MAX_LENGTH.js +1 -0
- package/src/adapter/DB_ALERT_POLICY_NAME_MAX_LENGTH.js +1 -0
- package/src/adapter/DB_RUN_ALLOWED_STATUSES.js +10 -0
- package/src/adapter/DB_RUN_ID_MAX_LENGTH.js +1 -0
- package/src/adapter/DB_RUN_WORKFLOW_NAME_MAX_LENGTH.js +1 -0
- package/src/adapter/EventHistoryQuery.ts +7 -0
- package/src/adapter/HumanRequestRow.ts +19 -0
- package/src/adapter/NodeDiffCacheRow.ts +9 -0
- package/src/adapter/NodeRow.ts +10 -0
- package/src/adapter/PendingHumanRequestRow.ts +7 -0
- package/src/adapter/RunAncestryRow.ts +5 -0
- package/src/adapter/RunRow.ts +21 -0
- package/src/adapter/SignalQuery.ts +6 -0
- package/src/adapter/SignalRow.ts +9 -0
- package/src/adapter/SmithersDb.js +2236 -0
- package/src/adapter/StaleRunRecord.ts +7 -0
- package/src/adapter/index.js +27 -0
- package/src/adapter.js +2359 -0
- package/src/assertJsonPayloadWithinBounds.js +94 -0
- package/src/assertMaxBytes.js +23 -0
- package/src/assertMaxJsonDepth.js +40 -0
- package/src/assertMaxStringLength.js +16 -0
- package/src/assertOptionalArrayMaxLength.js +16 -0
- package/src/assertOptionalStringMaxLength.js +11 -0
- package/src/assertPositiveFiniteInteger.js +14 -0
- package/src/assertPositiveFiniteNumber.js +12 -0
- package/src/buildHumanRequestId.js +9 -0
- package/src/cache/nodeDiffCache.js +124 -0
- package/src/ensure.js +18 -0
- package/src/ensureSqlMessageStorage.js +11 -0
- package/src/ensureSqlMessageStorageEffect.js +12 -0
- package/src/frame-codec/FRAME_KEYFRAME_INTERVAL.js +1 -0
- package/src/frame-codec/FrameDelta.ts +6 -0
- package/src/frame-codec/FrameDeltaOp.ts +20 -0
- package/src/frame-codec/FrameEncoding.ts +1 -0
- package/src/frame-codec/JsonPath.ts +3 -0
- package/src/frame-codec/JsonPathSegment.ts +1 -0
- package/src/frame-codec/applyFrameDelta.js +143 -0
- package/src/frame-codec/applyFrameDeltaJson.js +10 -0
- package/src/frame-codec/encodeFrameDelta.js +247 -0
- package/src/frame-codec/index.js +15 -0
- package/src/frame-codec/normalizeFrameEncoding.js +13 -0
- package/src/frame-codec/parseFrameDelta.js +27 -0
- package/src/frame-codec/serializeFrameDelta.js +9 -0
- package/src/frame-codec.js +409 -0
- package/src/getSqlMessageStorage.js +11 -0
- package/src/index.d.ts +5203 -0
- package/src/index.js +20 -0
- package/src/input-bounds.js +12 -0
- package/src/input.js +17 -0
- package/src/internal-schema/index.js +19 -0
- package/src/internal-schema/smithersAlerts.js +27 -0
- package/src/internal-schema/smithersApprovals.js +18 -0
- package/src/internal-schema/smithersAttempts.js +20 -0
- package/src/internal-schema/smithersCache.js +13 -0
- package/src/internal-schema/smithersCron.js +11 -0
- package/src/internal-schema/smithersEvents.js +10 -0
- package/src/internal-schema/smithersFrames.js +14 -0
- package/src/internal-schema/smithersHumanRequests.js +17 -0
- package/src/internal-schema/smithersNodeDiffs.js +12 -0
- package/src/internal-schema/smithersNodes.js +13 -0
- package/src/internal-schema/smithersRalph.js +10 -0
- package/src/internal-schema/smithersRuns.js +22 -0
- package/src/internal-schema/smithersSandboxes.js +16 -0
- package/src/internal-schema/smithersSignals.js +12 -0
- package/src/internal-schema/smithersTimeTravelAudit.js +12 -0
- package/src/internal-schema/smithersToolCalls.js +19 -0
- package/src/internal-schema/smithersVectors.js +12 -0
- package/src/internal-schema.js +245 -0
- package/src/isRetryableSqliteWriteError.js +53 -0
- package/src/loadInputEffect.js +28 -0
- package/src/loadOutputsEffect.js +87 -0
- package/src/output/OutputKey.ts +1 -0
- package/src/output/buildKeyWhere.js +17 -0
- package/src/output/buildOutputRow.js +34 -0
- package/src/output/describeSchemaShape.js +70 -0
- package/src/output/getAgentOutputSchema.js +13 -0
- package/src/output/getKeyColumns.js +19 -0
- package/src/output/index.js +14 -0
- package/src/output/selectOutputRowEffect.js +30 -0
- package/src/output/stripAutoColumns.js +10 -0
- package/src/output/upsertOutputRowEffect.js +38 -0
- package/src/output/validateExistingOutput.js +17 -0
- package/src/output/validateOutput.js +17 -0
- package/src/output-schema-descriptor.js +163 -0
- package/src/output.js +240 -0
- package/src/react-output.js +10 -0
- package/src/runState/ComputeRunStateOptions.ts +4 -0
- package/src/runState/DeriveRunStateInput.ts +10 -0
- package/src/runState/RUN_STATE_HEARTBEAT_STALE_MS.js +1 -0
- package/src/runState/ReasonBlocked.ts +10 -0
- package/src/runState/ReasonUnhealthy.ts +6 -0
- package/src/runState/RunState.ts +12 -0
- package/src/runState/RunStateView.ts +11 -0
- package/src/runState/computeRunState.js +22 -0
- package/src/runState/computeRunStateFromRow.js +102 -0
- package/src/runState/deriveRunState.js +109 -0
- package/src/runState/parseEventMeta.js +18 -0
- package/src/runState/parseTimerMeta.js +16 -0
- package/src/runState-types.ts +23 -0
- package/src/runState.js +7 -0
- package/src/schema-signature.js +22 -0
- package/src/snapshot.js +125 -0
- package/src/sql-message-storage.js +839 -0
- package/src/storage/InMemoryStorage.js +484 -0
- package/src/storage/StorageService.js +7 -0
- package/src/storage/StorageServiceShape.ts +122 -0
- package/src/storage/StorageServiceTypes.ts +150 -0
- package/src/unwrapZodType.js +17 -0
- package/src/utils/camelToSnake.js +6 -0
- package/src/withSqliteWriteRetryEffect.js +110 -0
- package/src/write-retry.js +49 -0
- package/src/zodToCreateTableSQL.js +41 -0
- package/src/zodToTable.js +60 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @smithers-type-exports-begin
|
|
2
|
+
/** @typedef {import("./SchemaRegistryEntry.ts").SchemaRegistryEntry} SchemaRegistryEntry */
|
|
3
|
+
// @smithers-type-exports-end
|
|
4
|
+
|
|
5
|
+
export * from "./adapter.js";
|
|
6
|
+
export * from "./ensure.js";
|
|
7
|
+
export * from "./input-bounds.js";
|
|
8
|
+
export * from "./frame-codec.js";
|
|
9
|
+
export * from "./input.js";
|
|
10
|
+
export * from "./internal-schema.js";
|
|
11
|
+
export * from "./output.js";
|
|
12
|
+
export * from "./schema-signature.js";
|
|
13
|
+
export * from "./snapshot.js";
|
|
14
|
+
export * from "./sql-message-storage.js";
|
|
15
|
+
export * from "./cache/nodeDiffCache.js";
|
|
16
|
+
export * from "./unwrapZodType.js";
|
|
17
|
+
export * from "./write-retry.js";
|
|
18
|
+
export * from "./zodToCreateTableSQL.js";
|
|
19
|
+
export * from "./zodToTable.js";
|
|
20
|
+
export * from "./utils/camelToSnake.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @smithers-type-exports-begin
|
|
2
|
+
/** @typedef {import("./JsonBounds.ts").JsonBounds} JsonBounds */
|
|
3
|
+
// @smithers-type-exports-end
|
|
4
|
+
|
|
5
|
+
export { assertMaxStringLength } from "./assertMaxStringLength.js";
|
|
6
|
+
export { assertOptionalStringMaxLength } from "./assertOptionalStringMaxLength.js";
|
|
7
|
+
export { assertOptionalArrayMaxLength } from "./assertOptionalArrayMaxLength.js";
|
|
8
|
+
export { assertPositiveFiniteNumber } from "./assertPositiveFiniteNumber.js";
|
|
9
|
+
export { assertPositiveFiniteInteger } from "./assertPositiveFiniteInteger.js";
|
|
10
|
+
export { assertMaxBytes } from "./assertMaxBytes.js";
|
|
11
|
+
export { assertMaxJsonDepth } from "./assertMaxJsonDepth.js";
|
|
12
|
+
export { assertJsonPayloadWithinBounds } from "./assertJsonPayloadWithinBounds.js";
|
package/src/input.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createInsertSchema } from "drizzle-zod";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** @typedef {import("drizzle-orm").Table} _Table */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {_Table} table
|
|
7
|
+
* @param {unknown} payload
|
|
8
|
+
* @returns {{ ok: boolean; data?: any; error?: z.ZodError; }}
|
|
9
|
+
*/
|
|
10
|
+
export function validateInput(table, payload) {
|
|
11
|
+
const schema = createInsertSchema(table);
|
|
12
|
+
const result = schema.safeParse(payload);
|
|
13
|
+
if (result.success) {
|
|
14
|
+
return { ok: true, data: result.data };
|
|
15
|
+
}
|
|
16
|
+
return { ok: false, error: result.error };
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { smithersRuns } from "./smithersRuns.js";
|
|
2
|
+
export { smithersNodes } from "./smithersNodes.js";
|
|
3
|
+
export { smithersAttempts } from "./smithersAttempts.js";
|
|
4
|
+
export { smithersFrames } from "./smithersFrames.js";
|
|
5
|
+
export { smithersApprovals } from "./smithersApprovals.js";
|
|
6
|
+
export { smithersHumanRequests } from "./smithersHumanRequests.js";
|
|
7
|
+
export { smithersAlerts } from "./smithersAlerts.js";
|
|
8
|
+
export { smithersSignals } from "./smithersSignals.js";
|
|
9
|
+
export { smithersCache } from "./smithersCache.js";
|
|
10
|
+
export { smithersNodeDiffs } from "./smithersNodeDiffs.js";
|
|
11
|
+
export { smithersTimeTravelAudit } from "./smithersTimeTravelAudit.js";
|
|
12
|
+
export { smithersSandboxes } from "./smithersSandboxes.js";
|
|
13
|
+
export { smithersToolCalls } from "./smithersToolCalls.js";
|
|
14
|
+
export { smithersEvents } from "./smithersEvents.js";
|
|
15
|
+
export { smithersRalph } from "./smithersRalph.js";
|
|
16
|
+
export { smithersScorers } from "@smithers-orchestrator/scorers/schema";
|
|
17
|
+
export { smithersMemoryFacts, smithersMemoryThreads, smithersMemoryMessages, } from "@smithers-orchestrator/memory/schema";
|
|
18
|
+
export { smithersVectors } from "./smithersVectors.js";
|
|
19
|
+
export { smithersCron } from "./smithersCron.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersAlerts = sqliteTable("_smithers_alerts", {
|
|
3
|
+
alertId: text("alert_id").primaryKey(),
|
|
4
|
+
runId: text("run_id"),
|
|
5
|
+
policyName: text("policy_name").notNull(),
|
|
6
|
+
severity: text("severity").notNull(),
|
|
7
|
+
status: text("status").notNull(),
|
|
8
|
+
firedAtMs: integer("fired_at_ms").notNull(),
|
|
9
|
+
resolvedAtMs: integer("resolved_at_ms"),
|
|
10
|
+
acknowledgedAtMs: integer("acknowledged_at_ms"),
|
|
11
|
+
message: text("message").notNull(),
|
|
12
|
+
detailsJson: text("details_json"),
|
|
13
|
+
fingerprint: text("fingerprint"),
|
|
14
|
+
nodeId: text("node_id"),
|
|
15
|
+
iteration: integer("iteration"),
|
|
16
|
+
owner: text("owner"),
|
|
17
|
+
runbook: text("runbook"),
|
|
18
|
+
labelsJson: text("labels_json"),
|
|
19
|
+
reactionJson: text("reaction_json"),
|
|
20
|
+
sourceEventType: text("source_event_type"),
|
|
21
|
+
firstFiredAtMs: integer("first_fired_at_ms"),
|
|
22
|
+
lastFiredAtMs: integer("last_fired_at_ms"),
|
|
23
|
+
occurrenceCount: integer("occurrence_count").default(1),
|
|
24
|
+
silencedUntilMs: integer("silenced_until_ms"),
|
|
25
|
+
acknowledgedBy: text("acknowledged_by"),
|
|
26
|
+
resolvedBy: text("resolved_by"),
|
|
27
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersApprovals = sqliteTable("_smithers_approvals", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
nodeId: text("node_id").notNull(),
|
|
5
|
+
iteration: integer("iteration").notNull().default(0),
|
|
6
|
+
status: text("status").notNull(),
|
|
7
|
+
requestedAtMs: integer("requested_at_ms"),
|
|
8
|
+
decidedAtMs: integer("decided_at_ms"),
|
|
9
|
+
note: text("note"),
|
|
10
|
+
decidedBy: text("decided_by"),
|
|
11
|
+
requestJson: text("request_json"),
|
|
12
|
+
decisionJson: text("decision_json"),
|
|
13
|
+
autoApproved: integer("auto_approved", { mode: "boolean" })
|
|
14
|
+
.notNull()
|
|
15
|
+
.default(false),
|
|
16
|
+
}, (t) => ({
|
|
17
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration] }),
|
|
18
|
+
}));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersAttempts = sqliteTable("_smithers_attempts", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
nodeId: text("node_id").notNull(),
|
|
5
|
+
iteration: integer("iteration").notNull().default(0),
|
|
6
|
+
attempt: integer("attempt").notNull(),
|
|
7
|
+
state: text("state").notNull(),
|
|
8
|
+
startedAtMs: integer("started_at_ms").notNull(),
|
|
9
|
+
finishedAtMs: integer("finished_at_ms"),
|
|
10
|
+
heartbeatAtMs: integer("heartbeat_at_ms"),
|
|
11
|
+
heartbeatDataJson: text("heartbeat_data_json"),
|
|
12
|
+
errorJson: text("error_json"),
|
|
13
|
+
jjPointer: text("jj_pointer"),
|
|
14
|
+
cached: integer("cached", { mode: "boolean" }).default(false),
|
|
15
|
+
metaJson: text("meta_json"),
|
|
16
|
+
responseText: text("response_text"),
|
|
17
|
+
jjCwd: text("jj_cwd"),
|
|
18
|
+
}, (t) => ({
|
|
19
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration, t.attempt] }),
|
|
20
|
+
}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersCache = sqliteTable("_smithers_cache", {
|
|
3
|
+
cacheKey: text("cache_key").primaryKey(),
|
|
4
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
5
|
+
workflowName: text("workflow_name").notNull(),
|
|
6
|
+
nodeId: text("node_id").notNull(),
|
|
7
|
+
outputTable: text("output_table").notNull(),
|
|
8
|
+
schemaSig: text("schema_sig").notNull(),
|
|
9
|
+
agentSig: text("agent_sig"),
|
|
10
|
+
toolsSig: text("tools_sig"),
|
|
11
|
+
jjPointer: text("jj_pointer"),
|
|
12
|
+
payloadJson: text("payload_json").notNull(),
|
|
13
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersCron = sqliteTable("_smithers_cron", {
|
|
3
|
+
cronId: text("cron_id").primaryKey(),
|
|
4
|
+
pattern: text("pattern").notNull(),
|
|
5
|
+
workflowPath: text("workflow_path").notNull(),
|
|
6
|
+
enabled: integer("enabled", { mode: "boolean" }).default(true),
|
|
7
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
8
|
+
lastRunAtMs: integer("last_run_at_ms"),
|
|
9
|
+
nextRunAtMs: integer("next_run_at_ms"),
|
|
10
|
+
errorJson: text("error_json"),
|
|
11
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersEvents = sqliteTable("_smithers_events", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
seq: integer("seq").notNull(),
|
|
5
|
+
timestampMs: integer("timestamp_ms").notNull(),
|
|
6
|
+
type: text("type").notNull(),
|
|
7
|
+
payloadJson: text("payload_json").notNull(),
|
|
8
|
+
}, (t) => ({
|
|
9
|
+
pk: primaryKey({ columns: [t.runId, t.seq] }),
|
|
10
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersFrames = sqliteTable("_smithers_frames", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
frameNo: integer("frame_no").notNull(),
|
|
5
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
6
|
+
xmlJson: text("xml_json").notNull(),
|
|
7
|
+
xmlHash: text("xml_hash").notNull(),
|
|
8
|
+
encoding: text("encoding").notNull().default("full"),
|
|
9
|
+
mountedTaskIdsJson: text("mounted_task_ids_json"),
|
|
10
|
+
taskIndexJson: text("task_index_json"),
|
|
11
|
+
note: text("note"),
|
|
12
|
+
}, (t) => ({
|
|
13
|
+
pk: primaryKey({ columns: [t.runId, t.frameNo] }),
|
|
14
|
+
}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersHumanRequests = sqliteTable("_smithers_human_requests", {
|
|
3
|
+
requestId: text("request_id").primaryKey(),
|
|
4
|
+
runId: text("run_id").notNull(),
|
|
5
|
+
nodeId: text("node_id").notNull(),
|
|
6
|
+
iteration: integer("iteration").notNull().default(0),
|
|
7
|
+
kind: text("kind").notNull(),
|
|
8
|
+
status: text("status").notNull(),
|
|
9
|
+
prompt: text("prompt").notNull(),
|
|
10
|
+
schemaJson: text("schema_json"),
|
|
11
|
+
optionsJson: text("options_json"),
|
|
12
|
+
responseJson: text("response_json"),
|
|
13
|
+
requestedAtMs: integer("requested_at_ms").notNull(),
|
|
14
|
+
answeredAtMs: integer("answered_at_ms"),
|
|
15
|
+
answeredBy: text("answered_by"),
|
|
16
|
+
timeoutAtMs: integer("timeout_at_ms"),
|
|
17
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersNodeDiffs = sqliteTable("_smithers_node_diffs", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
nodeId: text("node_id").notNull(),
|
|
5
|
+
iteration: integer("iteration").notNull(),
|
|
6
|
+
baseRef: text("base_ref").notNull(),
|
|
7
|
+
diffJson: text("diff_json").notNull(),
|
|
8
|
+
computedAtMs: integer("computed_at_ms").notNull(),
|
|
9
|
+
sizeBytes: integer("size_bytes").notNull(),
|
|
10
|
+
}, (t) => ({
|
|
11
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration, t.baseRef] }),
|
|
12
|
+
}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersNodes = sqliteTable("_smithers_nodes", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
nodeId: text("node_id").notNull(),
|
|
5
|
+
iteration: integer("iteration").notNull().default(0),
|
|
6
|
+
state: text("state").notNull(),
|
|
7
|
+
lastAttempt: integer("last_attempt"),
|
|
8
|
+
updatedAtMs: integer("updated_at_ms").notNull(),
|
|
9
|
+
outputTable: text("output_table").notNull(),
|
|
10
|
+
label: text("label"),
|
|
11
|
+
}, (t) => ({
|
|
12
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration] }),
|
|
13
|
+
}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersRalph = sqliteTable("_smithers_ralph", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
ralphId: text("ralph_id").notNull(),
|
|
5
|
+
iteration: integer("iteration").notNull().default(0),
|
|
6
|
+
done: integer("done", { mode: "boolean" }).notNull().default(false),
|
|
7
|
+
updatedAtMs: integer("updated_at_ms").notNull(),
|
|
8
|
+
}, (t) => ({
|
|
9
|
+
pk: primaryKey({ columns: [t.runId, t.ralphId] }),
|
|
10
|
+
}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersRuns = sqliteTable("_smithers_runs", {
|
|
3
|
+
runId: text("run_id").primaryKey(),
|
|
4
|
+
parentRunId: text("parent_run_id"),
|
|
5
|
+
workflowName: text("workflow_name").notNull(),
|
|
6
|
+
workflowPath: text("workflow_path"),
|
|
7
|
+
workflowHash: text("workflow_hash"),
|
|
8
|
+
status: text("status").notNull(),
|
|
9
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
10
|
+
startedAtMs: integer("started_at_ms"),
|
|
11
|
+
finishedAtMs: integer("finished_at_ms"),
|
|
12
|
+
heartbeatAtMs: integer("heartbeat_at_ms"),
|
|
13
|
+
runtimeOwnerId: text("runtime_owner_id"),
|
|
14
|
+
cancelRequestedAtMs: integer("cancel_requested_at_ms"),
|
|
15
|
+
hijackRequestedAtMs: integer("hijack_requested_at_ms"),
|
|
16
|
+
hijackTarget: text("hijack_target"),
|
|
17
|
+
vcsType: text("vcs_type"),
|
|
18
|
+
vcsRoot: text("vcs_root"),
|
|
19
|
+
vcsRevision: text("vcs_revision"),
|
|
20
|
+
errorJson: text("error_json"),
|
|
21
|
+
configJson: text("config_json"),
|
|
22
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersSandboxes = sqliteTable("_smithers_sandboxes", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
sandboxId: text("sandbox_id").notNull(),
|
|
5
|
+
runtime: text("runtime").notNull().default("bubblewrap"),
|
|
6
|
+
remoteRunId: text("remote_run_id"),
|
|
7
|
+
workspaceId: text("workspace_id"),
|
|
8
|
+
containerId: text("container_id"),
|
|
9
|
+
configJson: text("config_json").notNull(),
|
|
10
|
+
status: text("status").notNull().default("pending"),
|
|
11
|
+
shippedAtMs: integer("shipped_at_ms"),
|
|
12
|
+
completedAtMs: integer("completed_at_ms"),
|
|
13
|
+
bundlePath: text("bundle_path"),
|
|
14
|
+
}, (t) => ({
|
|
15
|
+
pk: primaryKey({ columns: [t.runId, t.sandboxId] }),
|
|
16
|
+
}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersSignals = sqliteTable("_smithers_signals", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
seq: integer("seq").notNull(),
|
|
5
|
+
signalName: text("signal_name").notNull(),
|
|
6
|
+
correlationId: text("correlation_id"),
|
|
7
|
+
payloadJson: text("payload_json").notNull(),
|
|
8
|
+
receivedAtMs: integer("received_at_ms").notNull(),
|
|
9
|
+
receivedBy: text("received_by"),
|
|
10
|
+
}, (t) => ({
|
|
11
|
+
pk: primaryKey({ columns: [t.runId, t.seq] }),
|
|
12
|
+
}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
|
|
3
|
+
export const smithersTimeTravelAudit = sqliteTable("_smithers_time_travel_audit", {
|
|
4
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
5
|
+
runId: text("run_id").notNull(),
|
|
6
|
+
fromFrameNo: integer("from_frame_no").notNull(),
|
|
7
|
+
toFrameNo: integer("to_frame_no").notNull(),
|
|
8
|
+
caller: text("caller").notNull(),
|
|
9
|
+
timestampMs: integer("timestamp_ms").notNull(),
|
|
10
|
+
result: text("result").notNull(),
|
|
11
|
+
durationMs: integer("duration_ms"),
|
|
12
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersToolCalls = sqliteTable("_smithers_tool_calls", {
|
|
3
|
+
runId: text("run_id").notNull(),
|
|
4
|
+
nodeId: text("node_id").notNull(),
|
|
5
|
+
iteration: integer("iteration").notNull().default(0),
|
|
6
|
+
attempt: integer("attempt").notNull(),
|
|
7
|
+
seq: integer("seq").notNull(),
|
|
8
|
+
toolName: text("tool_name").notNull(),
|
|
9
|
+
inputJson: text("input_json"),
|
|
10
|
+
outputJson: text("output_json"),
|
|
11
|
+
startedAtMs: integer("started_at_ms").notNull(),
|
|
12
|
+
finishedAtMs: integer("finished_at_ms"),
|
|
13
|
+
status: text("status").notNull(),
|
|
14
|
+
errorJson: text("error_json"),
|
|
15
|
+
}, (t) => ({
|
|
16
|
+
pk: primaryKey({
|
|
17
|
+
columns: [t.runId, t.nodeId, t.iteration, t.attempt, t.seq],
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { blob, integer, sqliteTable, text, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersVectors = sqliteTable("_smithers_vectors", {
|
|
3
|
+
id: text("id").primaryKey(),
|
|
4
|
+
namespace: text("namespace").notNull(),
|
|
5
|
+
content: text("content").notNull(),
|
|
6
|
+
embedding: blob("embedding").notNull(),
|
|
7
|
+
dimensions: integer("dimensions").notNull(),
|
|
8
|
+
metadataJson: text("metadata_json"),
|
|
9
|
+
documentId: text("document_id"),
|
|
10
|
+
chunkIndex: integer("chunk_index"),
|
|
11
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
12
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { blob, integer, sqliteTable, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const smithersRuns = sqliteTable("_smithers_runs", {
|
|
3
|
+
runId: text("run_id").primaryKey(),
|
|
4
|
+
parentRunId: text("parent_run_id"),
|
|
5
|
+
workflowName: text("workflow_name").notNull(),
|
|
6
|
+
workflowPath: text("workflow_path"),
|
|
7
|
+
workflowHash: text("workflow_hash"),
|
|
8
|
+
status: text("status").notNull(),
|
|
9
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
10
|
+
startedAtMs: integer("started_at_ms"),
|
|
11
|
+
finishedAtMs: integer("finished_at_ms"),
|
|
12
|
+
heartbeatAtMs: integer("heartbeat_at_ms"),
|
|
13
|
+
runtimeOwnerId: text("runtime_owner_id"),
|
|
14
|
+
cancelRequestedAtMs: integer("cancel_requested_at_ms"),
|
|
15
|
+
hijackRequestedAtMs: integer("hijack_requested_at_ms"),
|
|
16
|
+
hijackTarget: text("hijack_target"),
|
|
17
|
+
vcsType: text("vcs_type"),
|
|
18
|
+
vcsRoot: text("vcs_root"),
|
|
19
|
+
vcsRevision: text("vcs_revision"),
|
|
20
|
+
errorJson: text("error_json"),
|
|
21
|
+
configJson: text("config_json"),
|
|
22
|
+
});
|
|
23
|
+
export const smithersNodes = sqliteTable("_smithers_nodes", {
|
|
24
|
+
runId: text("run_id").notNull(),
|
|
25
|
+
nodeId: text("node_id").notNull(),
|
|
26
|
+
iteration: integer("iteration").notNull().default(0),
|
|
27
|
+
state: text("state").notNull(),
|
|
28
|
+
lastAttempt: integer("last_attempt"),
|
|
29
|
+
updatedAtMs: integer("updated_at_ms").notNull(),
|
|
30
|
+
outputTable: text("output_table").notNull(),
|
|
31
|
+
label: text("label"),
|
|
32
|
+
}, (t) => ({
|
|
33
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration] }),
|
|
34
|
+
}));
|
|
35
|
+
export const smithersAttempts = sqliteTable("_smithers_attempts", {
|
|
36
|
+
runId: text("run_id").notNull(),
|
|
37
|
+
nodeId: text("node_id").notNull(),
|
|
38
|
+
iteration: integer("iteration").notNull().default(0),
|
|
39
|
+
attempt: integer("attempt").notNull(),
|
|
40
|
+
state: text("state").notNull(),
|
|
41
|
+
startedAtMs: integer("started_at_ms").notNull(),
|
|
42
|
+
finishedAtMs: integer("finished_at_ms"),
|
|
43
|
+
heartbeatAtMs: integer("heartbeat_at_ms"),
|
|
44
|
+
heartbeatDataJson: text("heartbeat_data_json"),
|
|
45
|
+
errorJson: text("error_json"),
|
|
46
|
+
jjPointer: text("jj_pointer"),
|
|
47
|
+
cached: integer("cached", { mode: "boolean" }).default(false),
|
|
48
|
+
metaJson: text("meta_json"),
|
|
49
|
+
responseText: text("response_text"),
|
|
50
|
+
jjCwd: text("jj_cwd"),
|
|
51
|
+
}, (t) => ({
|
|
52
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration, t.attempt] }),
|
|
53
|
+
}));
|
|
54
|
+
export const smithersFrames = sqliteTable("_smithers_frames", {
|
|
55
|
+
runId: text("run_id").notNull(),
|
|
56
|
+
frameNo: integer("frame_no").notNull(),
|
|
57
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
58
|
+
xmlJson: text("xml_json").notNull(),
|
|
59
|
+
xmlHash: text("xml_hash").notNull(),
|
|
60
|
+
encoding: text("encoding").notNull().default("full"),
|
|
61
|
+
mountedTaskIdsJson: text("mounted_task_ids_json"),
|
|
62
|
+
taskIndexJson: text("task_index_json"),
|
|
63
|
+
note: text("note"),
|
|
64
|
+
}, (t) => ({
|
|
65
|
+
pk: primaryKey({ columns: [t.runId, t.frameNo] }),
|
|
66
|
+
}));
|
|
67
|
+
export const smithersApprovals = sqliteTable("_smithers_approvals", {
|
|
68
|
+
runId: text("run_id").notNull(),
|
|
69
|
+
nodeId: text("node_id").notNull(),
|
|
70
|
+
iteration: integer("iteration").notNull().default(0),
|
|
71
|
+
status: text("status").notNull(),
|
|
72
|
+
requestedAtMs: integer("requested_at_ms"),
|
|
73
|
+
decidedAtMs: integer("decided_at_ms"),
|
|
74
|
+
note: text("note"),
|
|
75
|
+
decidedBy: text("decided_by"),
|
|
76
|
+
requestJson: text("request_json"),
|
|
77
|
+
decisionJson: text("decision_json"),
|
|
78
|
+
autoApproved: integer("auto_approved", { mode: "boolean" })
|
|
79
|
+
.notNull()
|
|
80
|
+
.default(false),
|
|
81
|
+
}, (t) => ({
|
|
82
|
+
pk: primaryKey({ columns: [t.runId, t.nodeId, t.iteration] }),
|
|
83
|
+
}));
|
|
84
|
+
export const smithersHumanRequests = sqliteTable("_smithers_human_requests", {
|
|
85
|
+
requestId: text("request_id").primaryKey(),
|
|
86
|
+
runId: text("run_id").notNull(),
|
|
87
|
+
nodeId: text("node_id").notNull(),
|
|
88
|
+
iteration: integer("iteration").notNull().default(0),
|
|
89
|
+
kind: text("kind").notNull(),
|
|
90
|
+
status: text("status").notNull(),
|
|
91
|
+
prompt: text("prompt").notNull(),
|
|
92
|
+
schemaJson: text("schema_json"),
|
|
93
|
+
optionsJson: text("options_json"),
|
|
94
|
+
responseJson: text("response_json"),
|
|
95
|
+
requestedAtMs: integer("requested_at_ms").notNull(),
|
|
96
|
+
answeredAtMs: integer("answered_at_ms"),
|
|
97
|
+
answeredBy: text("answered_by"),
|
|
98
|
+
timeoutAtMs: integer("timeout_at_ms"),
|
|
99
|
+
});
|
|
100
|
+
export const smithersAlerts = sqliteTable("_smithers_alerts", {
|
|
101
|
+
alertId: text("alert_id").primaryKey(),
|
|
102
|
+
runId: text("run_id"),
|
|
103
|
+
policyName: text("policy_name").notNull(),
|
|
104
|
+
severity: text("severity").notNull(),
|
|
105
|
+
status: text("status").notNull(),
|
|
106
|
+
firedAtMs: integer("fired_at_ms").notNull(),
|
|
107
|
+
resolvedAtMs: integer("resolved_at_ms"),
|
|
108
|
+
acknowledgedAtMs: integer("acknowledged_at_ms"),
|
|
109
|
+
message: text("message").notNull(),
|
|
110
|
+
detailsJson: text("details_json"),
|
|
111
|
+
fingerprint: text("fingerprint"),
|
|
112
|
+
nodeId: text("node_id"),
|
|
113
|
+
iteration: integer("iteration"),
|
|
114
|
+
owner: text("owner"),
|
|
115
|
+
runbook: text("runbook"),
|
|
116
|
+
labelsJson: text("labels_json"),
|
|
117
|
+
reactionJson: text("reaction_json"),
|
|
118
|
+
sourceEventType: text("source_event_type"),
|
|
119
|
+
firstFiredAtMs: integer("first_fired_at_ms"),
|
|
120
|
+
lastFiredAtMs: integer("last_fired_at_ms"),
|
|
121
|
+
occurrenceCount: integer("occurrence_count").default(1),
|
|
122
|
+
silencedUntilMs: integer("silenced_until_ms"),
|
|
123
|
+
acknowledgedBy: text("acknowledged_by"),
|
|
124
|
+
resolvedBy: text("resolved_by"),
|
|
125
|
+
});
|
|
126
|
+
export const smithersSignals = sqliteTable("_smithers_signals", {
|
|
127
|
+
runId: text("run_id").notNull(),
|
|
128
|
+
seq: integer("seq").notNull(),
|
|
129
|
+
signalName: text("signal_name").notNull(),
|
|
130
|
+
correlationId: text("correlation_id"),
|
|
131
|
+
payloadJson: text("payload_json").notNull(),
|
|
132
|
+
receivedAtMs: integer("received_at_ms").notNull(),
|
|
133
|
+
receivedBy: text("received_by"),
|
|
134
|
+
}, (t) => ({
|
|
135
|
+
pk: primaryKey({ columns: [t.runId, t.seq] }),
|
|
136
|
+
}));
|
|
137
|
+
export const smithersCache = sqliteTable("_smithers_cache", {
|
|
138
|
+
cacheKey: text("cache_key").primaryKey(),
|
|
139
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
140
|
+
workflowName: text("workflow_name").notNull(),
|
|
141
|
+
nodeId: text("node_id").notNull(),
|
|
142
|
+
outputTable: text("output_table").notNull(),
|
|
143
|
+
schemaSig: text("schema_sig").notNull(),
|
|
144
|
+
agentSig: text("agent_sig"),
|
|
145
|
+
toolsSig: text("tools_sig"),
|
|
146
|
+
jjPointer: text("jj_pointer"),
|
|
147
|
+
payloadJson: text("payload_json").notNull(),
|
|
148
|
+
});
|
|
149
|
+
export const smithersNodeDiffs = sqliteTable("_smithers_node_diffs", {
|
|
150
|
+
runId: text("run_id").notNull(),
|
|
151
|
+
nodeId: text("node_id").notNull(),
|
|
152
|
+
iteration: integer("iteration").notNull(),
|
|
153
|
+
baseRef: text("base_ref").notNull(),
|
|
154
|
+
diffJson: text("diff_json").notNull(),
|
|
155
|
+
computedAtMs: integer("computed_at_ms").notNull(),
|
|
156
|
+
sizeBytes: integer("size_bytes").notNull(),
|
|
157
|
+
}, (t) => ({
|
|
158
|
+
pk: primaryKey({
|
|
159
|
+
columns: [t.runId, t.nodeId, t.iteration, t.baseRef],
|
|
160
|
+
}),
|
|
161
|
+
}));
|
|
162
|
+
export const smithersTimeTravelAudit = sqliteTable("_smithers_time_travel_audit", {
|
|
163
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
164
|
+
runId: text("run_id").notNull(),
|
|
165
|
+
fromFrameNo: integer("from_frame_no").notNull(),
|
|
166
|
+
toFrameNo: integer("to_frame_no").notNull(),
|
|
167
|
+
caller: text("caller").notNull(),
|
|
168
|
+
timestampMs: integer("timestamp_ms").notNull(),
|
|
169
|
+
result: text("result").notNull(),
|
|
170
|
+
durationMs: integer("duration_ms"),
|
|
171
|
+
});
|
|
172
|
+
export const smithersSandboxes = sqliteTable("_smithers_sandboxes", {
|
|
173
|
+
runId: text("run_id").notNull(),
|
|
174
|
+
sandboxId: text("sandbox_id").notNull(),
|
|
175
|
+
runtime: text("runtime").notNull().default("bubblewrap"),
|
|
176
|
+
remoteRunId: text("remote_run_id"),
|
|
177
|
+
workspaceId: text("workspace_id"),
|
|
178
|
+
containerId: text("container_id"),
|
|
179
|
+
configJson: text("config_json").notNull(),
|
|
180
|
+
status: text("status").notNull().default("pending"),
|
|
181
|
+
shippedAtMs: integer("shipped_at_ms"),
|
|
182
|
+
completedAtMs: integer("completed_at_ms"),
|
|
183
|
+
bundlePath: text("bundle_path"),
|
|
184
|
+
}, (t) => ({
|
|
185
|
+
pk: primaryKey({ columns: [t.runId, t.sandboxId] }),
|
|
186
|
+
}));
|
|
187
|
+
export const smithersToolCalls = sqliteTable("_smithers_tool_calls", {
|
|
188
|
+
runId: text("run_id").notNull(),
|
|
189
|
+
nodeId: text("node_id").notNull(),
|
|
190
|
+
iteration: integer("iteration").notNull().default(0),
|
|
191
|
+
attempt: integer("attempt").notNull(),
|
|
192
|
+
seq: integer("seq").notNull(),
|
|
193
|
+
toolName: text("tool_name").notNull(),
|
|
194
|
+
inputJson: text("input_json"),
|
|
195
|
+
outputJson: text("output_json"),
|
|
196
|
+
startedAtMs: integer("started_at_ms").notNull(),
|
|
197
|
+
finishedAtMs: integer("finished_at_ms"),
|
|
198
|
+
status: text("status").notNull(),
|
|
199
|
+
errorJson: text("error_json"),
|
|
200
|
+
}, (t) => ({
|
|
201
|
+
pk: primaryKey({
|
|
202
|
+
columns: [t.runId, t.nodeId, t.iteration, t.attempt, t.seq],
|
|
203
|
+
}),
|
|
204
|
+
}));
|
|
205
|
+
export const smithersEvents = sqliteTable("_smithers_events", {
|
|
206
|
+
runId: text("run_id").notNull(),
|
|
207
|
+
seq: integer("seq").notNull(),
|
|
208
|
+
timestampMs: integer("timestamp_ms").notNull(),
|
|
209
|
+
type: text("type").notNull(),
|
|
210
|
+
payloadJson: text("payload_json").notNull(),
|
|
211
|
+
}, (t) => ({
|
|
212
|
+
pk: primaryKey({ columns: [t.runId, t.seq] }),
|
|
213
|
+
}));
|
|
214
|
+
export const smithersRalph = sqliteTable("_smithers_ralph", {
|
|
215
|
+
runId: text("run_id").notNull(),
|
|
216
|
+
ralphId: text("ralph_id").notNull(),
|
|
217
|
+
iteration: integer("iteration").notNull().default(0),
|
|
218
|
+
done: integer("done", { mode: "boolean" }).notNull().default(false),
|
|
219
|
+
updatedAtMs: integer("updated_at_ms").notNull(),
|
|
220
|
+
}, (t) => ({
|
|
221
|
+
pk: primaryKey({ columns: [t.runId, t.ralphId] }),
|
|
222
|
+
}));
|
|
223
|
+
export { smithersScorers } from "@smithers-orchestrator/scorers/schema";
|
|
224
|
+
export { smithersMemoryFacts, smithersMemoryThreads, smithersMemoryMessages, } from "@smithers-orchestrator/memory/schema";
|
|
225
|
+
export const smithersVectors = sqliteTable("_smithers_vectors", {
|
|
226
|
+
id: text("id").primaryKey(),
|
|
227
|
+
namespace: text("namespace").notNull(),
|
|
228
|
+
content: text("content").notNull(),
|
|
229
|
+
embedding: blob("embedding").notNull(),
|
|
230
|
+
dimensions: integer("dimensions").notNull(),
|
|
231
|
+
metadataJson: text("metadata_json"),
|
|
232
|
+
documentId: text("document_id"),
|
|
233
|
+
chunkIndex: integer("chunk_index"),
|
|
234
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
235
|
+
});
|
|
236
|
+
export const smithersCron = sqliteTable("_smithers_cron", {
|
|
237
|
+
cronId: text("cron_id").primaryKey(),
|
|
238
|
+
pattern: text("pattern").notNull(),
|
|
239
|
+
workflowPath: text("workflow_path").notNull(),
|
|
240
|
+
enabled: integer("enabled", { mode: "boolean" }).default(true),
|
|
241
|
+
createdAtMs: integer("created_at_ms").notNull(),
|
|
242
|
+
lastRunAtMs: integer("last_run_at_ms"),
|
|
243
|
+
nextRunAtMs: integer("next_run_at_ms"),
|
|
244
|
+
errorJson: text("error_json"),
|
|
245
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {unknown} error
|
|
3
|
+
* @returns {SqliteErrorMetadata | null}
|
|
4
|
+
*/
|
|
5
|
+
function readSqliteErrorMetadata(error) {
|
|
6
|
+
if (!error || (typeof error !== "object" && !(error instanceof Error))) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const code = typeof error?.code === "string" ? error.code : "";
|
|
10
|
+
const message = String(error?.message ?? "");
|
|
11
|
+
return { code, message };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @param {unknown} error
|
|
15
|
+
* @returns {SqliteErrorMetadata | null}
|
|
16
|
+
*/
|
|
17
|
+
function findSqliteErrorMetadata(error) {
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
let current = error;
|
|
20
|
+
while (current && !seen.has(current)) {
|
|
21
|
+
seen.add(current);
|
|
22
|
+
const metadata = readSqliteErrorMetadata(current);
|
|
23
|
+
if (metadata) {
|
|
24
|
+
const message = metadata.message.toLowerCase();
|
|
25
|
+
if (metadata.code.startsWith("SQLITE_BUSY") ||
|
|
26
|
+
metadata.code.startsWith("SQLITE_IOERR") ||
|
|
27
|
+
message.includes("database is locked") ||
|
|
28
|
+
message.includes("database is busy") ||
|
|
29
|
+
message.includes("disk i/o error")) {
|
|
30
|
+
return metadata;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
current = current?.cause;
|
|
34
|
+
}
|
|
35
|
+
return readSqliteErrorMetadata(error);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @param {unknown} error
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
export function isRetryableSqliteWriteError(error) {
|
|
42
|
+
const metadata = findSqliteErrorMetadata(error);
|
|
43
|
+
if (!metadata)
|
|
44
|
+
return false;
|
|
45
|
+
const { code } = metadata;
|
|
46
|
+
if (code.startsWith("SQLITE_BUSY") || code.startsWith("SQLITE_IOERR")) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const message = metadata.message.toLowerCase();
|
|
50
|
+
return (message.includes("database is locked") ||
|
|
51
|
+
message.includes("database is busy") ||
|
|
52
|
+
message.includes("disk i/o error"));
|
|
53
|
+
}
|