@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.
Files changed (130) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +43 -0
  3. package/src/JsonBounds.ts +6 -0
  4. package/src/SchemaRegistryEntry.ts +6 -0
  5. package/src/SqlMessageStorage.js +818 -0
  6. package/src/SqlMessageStorageEventHistoryQuery.ts +7 -0
  7. package/src/SqliteWriteRetryOptions.ts +7 -0
  8. package/src/adapter/AlertRow.ts +29 -0
  9. package/src/adapter/AlertSeverity.ts +2 -0
  10. package/src/adapter/AlertStatus.ts +2 -0
  11. package/src/adapter/ApprovalRow.ts +13 -0
  12. package/src/adapter/AttemptRow.ts +17 -0
  13. package/src/adapter/CacheRow.ts +12 -0
  14. package/src/adapter/DB_ALERT_ALLOWED_SEVERITIES.js +5 -0
  15. package/src/adapter/DB_ALERT_ALLOWED_STATUSES.js +6 -0
  16. package/src/adapter/DB_ALERT_ID_MAX_LENGTH.js +1 -0
  17. package/src/adapter/DB_ALERT_MESSAGE_MAX_LENGTH.js +1 -0
  18. package/src/adapter/DB_ALERT_POLICY_NAME_MAX_LENGTH.js +1 -0
  19. package/src/adapter/DB_RUN_ALLOWED_STATUSES.js +10 -0
  20. package/src/adapter/DB_RUN_ID_MAX_LENGTH.js +1 -0
  21. package/src/adapter/DB_RUN_WORKFLOW_NAME_MAX_LENGTH.js +1 -0
  22. package/src/adapter/EventHistoryQuery.ts +7 -0
  23. package/src/adapter/HumanRequestRow.ts +19 -0
  24. package/src/adapter/NodeDiffCacheRow.ts +9 -0
  25. package/src/adapter/NodeRow.ts +10 -0
  26. package/src/adapter/PendingHumanRequestRow.ts +7 -0
  27. package/src/adapter/RunAncestryRow.ts +5 -0
  28. package/src/adapter/RunRow.ts +21 -0
  29. package/src/adapter/SignalQuery.ts +6 -0
  30. package/src/adapter/SignalRow.ts +9 -0
  31. package/src/adapter/SmithersDb.js +2236 -0
  32. package/src/adapter/StaleRunRecord.ts +7 -0
  33. package/src/adapter/index.js +27 -0
  34. package/src/adapter.js +2359 -0
  35. package/src/assertJsonPayloadWithinBounds.js +94 -0
  36. package/src/assertMaxBytes.js +23 -0
  37. package/src/assertMaxJsonDepth.js +40 -0
  38. package/src/assertMaxStringLength.js +16 -0
  39. package/src/assertOptionalArrayMaxLength.js +16 -0
  40. package/src/assertOptionalStringMaxLength.js +11 -0
  41. package/src/assertPositiveFiniteInteger.js +14 -0
  42. package/src/assertPositiveFiniteNumber.js +12 -0
  43. package/src/buildHumanRequestId.js +9 -0
  44. package/src/cache/nodeDiffCache.js +124 -0
  45. package/src/ensure.js +18 -0
  46. package/src/ensureSqlMessageStorage.js +11 -0
  47. package/src/ensureSqlMessageStorageEffect.js +12 -0
  48. package/src/frame-codec/FRAME_KEYFRAME_INTERVAL.js +1 -0
  49. package/src/frame-codec/FrameDelta.ts +6 -0
  50. package/src/frame-codec/FrameDeltaOp.ts +20 -0
  51. package/src/frame-codec/FrameEncoding.ts +1 -0
  52. package/src/frame-codec/JsonPath.ts +3 -0
  53. package/src/frame-codec/JsonPathSegment.ts +1 -0
  54. package/src/frame-codec/applyFrameDelta.js +143 -0
  55. package/src/frame-codec/applyFrameDeltaJson.js +10 -0
  56. package/src/frame-codec/encodeFrameDelta.js +247 -0
  57. package/src/frame-codec/index.js +15 -0
  58. package/src/frame-codec/normalizeFrameEncoding.js +13 -0
  59. package/src/frame-codec/parseFrameDelta.js +27 -0
  60. package/src/frame-codec/serializeFrameDelta.js +9 -0
  61. package/src/frame-codec.js +409 -0
  62. package/src/getSqlMessageStorage.js +11 -0
  63. package/src/index.d.ts +5203 -0
  64. package/src/index.js +20 -0
  65. package/src/input-bounds.js +12 -0
  66. package/src/input.js +17 -0
  67. package/src/internal-schema/index.js +19 -0
  68. package/src/internal-schema/smithersAlerts.js +27 -0
  69. package/src/internal-schema/smithersApprovals.js +18 -0
  70. package/src/internal-schema/smithersAttempts.js +20 -0
  71. package/src/internal-schema/smithersCache.js +13 -0
  72. package/src/internal-schema/smithersCron.js +11 -0
  73. package/src/internal-schema/smithersEvents.js +10 -0
  74. package/src/internal-schema/smithersFrames.js +14 -0
  75. package/src/internal-schema/smithersHumanRequests.js +17 -0
  76. package/src/internal-schema/smithersNodeDiffs.js +12 -0
  77. package/src/internal-schema/smithersNodes.js +13 -0
  78. package/src/internal-schema/smithersRalph.js +10 -0
  79. package/src/internal-schema/smithersRuns.js +22 -0
  80. package/src/internal-schema/smithersSandboxes.js +16 -0
  81. package/src/internal-schema/smithersSignals.js +12 -0
  82. package/src/internal-schema/smithersTimeTravelAudit.js +12 -0
  83. package/src/internal-schema/smithersToolCalls.js +19 -0
  84. package/src/internal-schema/smithersVectors.js +12 -0
  85. package/src/internal-schema.js +245 -0
  86. package/src/isRetryableSqliteWriteError.js +53 -0
  87. package/src/loadInputEffect.js +28 -0
  88. package/src/loadOutputsEffect.js +87 -0
  89. package/src/output/OutputKey.ts +1 -0
  90. package/src/output/buildKeyWhere.js +17 -0
  91. package/src/output/buildOutputRow.js +34 -0
  92. package/src/output/describeSchemaShape.js +70 -0
  93. package/src/output/getAgentOutputSchema.js +13 -0
  94. package/src/output/getKeyColumns.js +19 -0
  95. package/src/output/index.js +14 -0
  96. package/src/output/selectOutputRowEffect.js +30 -0
  97. package/src/output/stripAutoColumns.js +10 -0
  98. package/src/output/upsertOutputRowEffect.js +38 -0
  99. package/src/output/validateExistingOutput.js +17 -0
  100. package/src/output/validateOutput.js +17 -0
  101. package/src/output-schema-descriptor.js +163 -0
  102. package/src/output.js +240 -0
  103. package/src/react-output.js +10 -0
  104. package/src/runState/ComputeRunStateOptions.ts +4 -0
  105. package/src/runState/DeriveRunStateInput.ts +10 -0
  106. package/src/runState/RUN_STATE_HEARTBEAT_STALE_MS.js +1 -0
  107. package/src/runState/ReasonBlocked.ts +10 -0
  108. package/src/runState/ReasonUnhealthy.ts +6 -0
  109. package/src/runState/RunState.ts +12 -0
  110. package/src/runState/RunStateView.ts +11 -0
  111. package/src/runState/computeRunState.js +22 -0
  112. package/src/runState/computeRunStateFromRow.js +102 -0
  113. package/src/runState/deriveRunState.js +109 -0
  114. package/src/runState/parseEventMeta.js +18 -0
  115. package/src/runState/parseTimerMeta.js +16 -0
  116. package/src/runState-types.ts +23 -0
  117. package/src/runState.js +7 -0
  118. package/src/schema-signature.js +22 -0
  119. package/src/snapshot.js +125 -0
  120. package/src/sql-message-storage.js +839 -0
  121. package/src/storage/InMemoryStorage.js +484 -0
  122. package/src/storage/StorageService.js +7 -0
  123. package/src/storage/StorageServiceShape.ts +122 -0
  124. package/src/storage/StorageServiceTypes.ts +150 -0
  125. package/src/unwrapZodType.js +17 -0
  126. package/src/utils/camelToSnake.js +6 -0
  127. package/src/withSqliteWriteRetryEffect.js +110 -0
  128. package/src/write-retry.js +49 -0
  129. package/src/zodToCreateTableSQL.js +41 -0
  130. package/src/zodToTable.js +60 -0
@@ -0,0 +1,7 @@
1
+ export type SqlMessageStorageEventHistoryQuery = {
2
+ afterSeq?: number;
3
+ limit?: number;
4
+ nodeId?: string;
5
+ types?: readonly string[];
6
+ sinceTimestampMs?: number;
7
+ };
@@ -0,0 +1,7 @@
1
+ export type SqliteWriteRetryOptions = {
2
+ label?: string;
3
+ maxAttempts?: number;
4
+ baseDelayMs?: number;
5
+ maxDelayMs?: number;
6
+ sleep?: (ms: number) => Promise<void>;
7
+ };
@@ -0,0 +1,29 @@
1
+ import type { AlertSeverity } from "./AlertSeverity";
2
+ import type { AlertStatus } from "./AlertStatus";
3
+
4
+ export type AlertRow = {
5
+ alertId: string;
6
+ runId: string | null;
7
+ policyName: string;
8
+ severity: AlertSeverity;
9
+ status: AlertStatus;
10
+ firedAtMs: number;
11
+ resolvedAtMs: number | null;
12
+ acknowledgedAtMs: number | null;
13
+ message: string;
14
+ detailsJson: string | null;
15
+ fingerprint?: string | null;
16
+ nodeId?: string | null;
17
+ iteration?: number | null;
18
+ owner?: string | null;
19
+ runbook?: string | null;
20
+ labelsJson?: string | null;
21
+ reactionJson?: string | null;
22
+ sourceEventType?: string | null;
23
+ firstFiredAtMs?: number | null;
24
+ lastFiredAtMs?: number | null;
25
+ occurrenceCount?: number;
26
+ silencedUntilMs?: number | null;
27
+ acknowledgedBy?: string | null;
28
+ resolvedBy?: string | null;
29
+ };
@@ -0,0 +1,2 @@
1
+ import { DB_ALERT_ALLOWED_SEVERITIES } from "./DB_ALERT_ALLOWED_SEVERITIES.js";
2
+ export type AlertSeverity = (typeof DB_ALERT_ALLOWED_SEVERITIES)[number];
@@ -0,0 +1,2 @@
1
+ import { DB_ALERT_ALLOWED_STATUSES } from "./DB_ALERT_ALLOWED_STATUSES.js";
2
+ export type AlertStatus = (typeof DB_ALERT_ALLOWED_STATUSES)[number];
@@ -0,0 +1,13 @@
1
+ export type ApprovalRow = {
2
+ runId: string;
3
+ nodeId: string;
4
+ iteration: number;
5
+ status: string;
6
+ requestedAtMs: number | null;
7
+ decidedAtMs: number | null;
8
+ note: string | null;
9
+ decidedBy: string | null;
10
+ requestJson: string | null;
11
+ decisionJson: string | null;
12
+ autoApproved: boolean;
13
+ };
@@ -0,0 +1,17 @@
1
+ export type AttemptRow = {
2
+ runId: string;
3
+ nodeId: string;
4
+ iteration: number;
5
+ attempt: number;
6
+ state: string;
7
+ startedAtMs: number;
8
+ finishedAtMs: number | null;
9
+ heartbeatAtMs: number | null;
10
+ heartbeatDataJson: string | null;
11
+ errorJson: string | null;
12
+ jjPointer: string | null;
13
+ responseText: string | null;
14
+ jjCwd: string | null;
15
+ cached: boolean;
16
+ metaJson: string | null;
17
+ };
@@ -0,0 +1,12 @@
1
+ export type CacheRow = {
2
+ cacheKey: string;
3
+ createdAtMs: number;
4
+ workflowName: string;
5
+ nodeId: string;
6
+ outputTable: string;
7
+ schemaSig: string;
8
+ agentSig: string | null;
9
+ toolsSig: string | null;
10
+ jjPointer: string | null;
11
+ payloadJson: string;
12
+ };
@@ -0,0 +1,5 @@
1
+ export const DB_ALERT_ALLOWED_SEVERITIES = [
2
+ "info",
3
+ "warning",
4
+ "critical",
5
+ ];
@@ -0,0 +1,6 @@
1
+ export const DB_ALERT_ALLOWED_STATUSES = [
2
+ "firing",
3
+ "acknowledged",
4
+ "resolved",
5
+ "silenced",
6
+ ];
@@ -0,0 +1 @@
1
+ export const DB_ALERT_ID_MAX_LENGTH = 256;
@@ -0,0 +1 @@
1
+ export const DB_ALERT_MESSAGE_MAX_LENGTH = 4096;
@@ -0,0 +1 @@
1
+ export const DB_ALERT_POLICY_NAME_MAX_LENGTH = 256;
@@ -0,0 +1,10 @@
1
+ export const DB_RUN_ALLOWED_STATUSES = [
2
+ "running",
3
+ "waiting-approval",
4
+ "waiting-event",
5
+ "waiting-timer",
6
+ "finished",
7
+ "failed",
8
+ "cancelled",
9
+ "continued",
10
+ ];
@@ -0,0 +1 @@
1
+ export const DB_RUN_ID_MAX_LENGTH = 256;
@@ -0,0 +1 @@
1
+ export const DB_RUN_WORKFLOW_NAME_MAX_LENGTH = 256;
@@ -0,0 +1,7 @@
1
+ export type EventHistoryQuery = {
2
+ afterSeq?: number;
3
+ limit?: number;
4
+ nodeId?: string;
5
+ types?: readonly string[];
6
+ sinceTimestampMs?: number;
7
+ };
@@ -0,0 +1,19 @@
1
+ export type HumanRequestKind = "ask" | "confirm" | "select" | "json";
2
+ export type HumanRequestStatus = "pending" | "answered" | "cancelled" | "expired";
3
+
4
+ export type HumanRequestRow = {
5
+ requestId: string;
6
+ runId: string;
7
+ nodeId: string;
8
+ iteration: number;
9
+ kind: HumanRequestKind;
10
+ status: HumanRequestStatus;
11
+ prompt: string;
12
+ schemaJson: string | null;
13
+ optionsJson: string | null;
14
+ responseJson: string | null;
15
+ requestedAtMs: number;
16
+ answeredAtMs: number | null;
17
+ answeredBy: string | null;
18
+ timeoutAtMs: number | null;
19
+ };
@@ -0,0 +1,9 @@
1
+ export type NodeDiffCacheRow = {
2
+ runId: string;
3
+ nodeId: string;
4
+ iteration: number;
5
+ baseRef: string;
6
+ diffJson: string;
7
+ computedAtMs: number;
8
+ sizeBytes: number;
9
+ };
@@ -0,0 +1,10 @@
1
+ export type NodeRow = {
2
+ runId: string;
3
+ nodeId: string;
4
+ iteration: number;
5
+ state: string;
6
+ lastAttempt: number | null;
7
+ updatedAtMs: number;
8
+ outputTable: string;
9
+ label: string | null;
10
+ };
@@ -0,0 +1,7 @@
1
+ import type { HumanRequestRow } from "./HumanRequestRow";
2
+
3
+ export type PendingHumanRequestRow = HumanRequestRow & {
4
+ workflowName: string | null;
5
+ runStatus: string | null;
6
+ nodeLabel: string | null;
7
+ };
@@ -0,0 +1,5 @@
1
+ export type RunAncestryRow = {
2
+ runId: string;
3
+ parentRunId: string | null;
4
+ depth: number;
5
+ };
@@ -0,0 +1,21 @@
1
+ export type RunRow = {
2
+ runId: string;
3
+ parentRunId: string | null;
4
+ workflowName: string;
5
+ workflowPath: string | null;
6
+ workflowHash: string | null;
7
+ status: string;
8
+ createdAtMs: number;
9
+ startedAtMs: number | null;
10
+ finishedAtMs: number | null;
11
+ heartbeatAtMs: number | null;
12
+ runtimeOwnerId: string | null;
13
+ cancelRequestedAtMs: number | null;
14
+ hijackRequestedAtMs: number | null;
15
+ hijackTarget: string | null;
16
+ vcsType: string | null;
17
+ vcsRoot: string | null;
18
+ vcsRevision: string | null;
19
+ errorJson: string | null;
20
+ configJson: string | null;
21
+ };
@@ -0,0 +1,6 @@
1
+ export type SignalQuery = {
2
+ signalName?: string;
3
+ correlationId?: string | null;
4
+ receivedAfterMs?: number;
5
+ limit?: number;
6
+ };
@@ -0,0 +1,9 @@
1
+ export type SignalRow = {
2
+ runId: string;
3
+ seq: number;
4
+ signalName: string;
5
+ correlationId: string | null;
6
+ payloadJson: string;
7
+ receivedAtMs: number;
8
+ receivedBy: string | null;
9
+ };