@qvac/core 1.0.0-rc.1 → 1.0.0-rc.11
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/CHANGELOG.md +1205 -1
- package/README.md +56 -45
- package/dist-lib/index.d.ts +3 -2
- package/dist-lib/index.js +1 -1
- package/dist-lib/lib/api/agent-folders.d.ts +22 -0
- package/dist-lib/lib/api/agent-folders.js +115 -0
- package/dist-lib/lib/api/agents.d.ts +20 -2
- package/dist-lib/lib/api/agents.js +128 -24
- package/dist-lib/lib/api/app-config.d.ts +7 -1
- package/dist-lib/lib/api/app-config.js +37 -6
- package/dist-lib/lib/api/approval-rules.d.ts +1 -1
- package/dist-lib/lib/api/approval-rules.js +12 -5
- package/dist-lib/lib/api/attachments.d.ts +1 -1
- package/dist-lib/lib/api/attachments.js +14 -2
- package/dist-lib/lib/api/chat-move.d.ts +4 -0
- package/dist-lib/lib/api/chat-move.js +7 -0
- package/dist-lib/lib/api/chat.d.ts +12 -2
- package/dist-lib/lib/api/chat.js +100 -9
- package/dist-lib/lib/api/chunk-delta.d.ts +12 -0
- package/dist-lib/lib/api/chunk-delta.js +115 -0
- package/dist-lib/lib/api/chunks.d.ts +19 -2
- package/dist-lib/lib/api/chunks.js +73 -13
- package/dist-lib/lib/api/config.d.ts +11 -3
- package/dist-lib/lib/api/config.js +51 -5
- package/dist-lib/lib/api/current-mesh.d.ts +13 -5
- package/dist-lib/lib/api/current-mesh.js +15 -11
- package/dist-lib/lib/api/custom-models.d.ts +7 -1
- package/dist-lib/lib/api/custom-models.js +12 -12
- package/dist-lib/lib/api/device-routes.d.ts +14 -0
- package/dist-lib/lib/api/device-routes.js +144 -0
- package/dist-lib/lib/api/devices.d.ts +3 -2
- package/dist-lib/lib/api/devices.js +28 -28
- package/dist-lib/lib/api/diagnostics.d.ts +2 -1
- package/dist-lib/lib/api/diagnostics.js +2 -2
- package/dist-lib/lib/api/execution.d.ts +16 -1
- package/dist-lib/lib/api/execution.js +72 -16
- package/dist-lib/lib/api/files.d.ts +1 -1
- package/dist-lib/lib/api/files.js +65 -8
- package/dist-lib/lib/api/host-run-log.d.ts +2 -41
- package/dist-lib/lib/api/host-run-log.js +35 -83
- package/dist-lib/lib/api/index.d.ts +39 -7
- package/dist-lib/lib/api/index.js +116 -36
- package/dist-lib/lib/api/instrument.d.ts +2 -2
- package/dist-lib/lib/api/instrument.js +24 -48
- package/dist-lib/lib/api/knowledge.d.ts +4 -1
- package/dist-lib/lib/api/knowledge.js +25 -7
- package/dist-lib/lib/api/local-files.d.ts +5 -1
- package/dist-lib/lib/api/local-files.js +9 -5
- package/dist-lib/lib/api/logs.js +3 -3
- package/dist-lib/lib/api/members.d.ts +10 -1
- package/dist-lib/lib/api/members.js +69 -44
- package/dist-lib/lib/api/mesh.d.ts +15 -6
- package/dist-lib/lib/api/mesh.js +13 -9
- package/dist-lib/lib/api/model-download.d.ts +2 -1
- package/dist-lib/lib/api/model-download.js +2 -2
- package/dist-lib/lib/api/network.d.ts +10 -2
- package/dist-lib/lib/api/network.js +8 -2
- package/dist-lib/lib/api/notifications.d.ts +3 -1
- package/dist-lib/lib/api/notifications.js +14 -9
- package/dist-lib/lib/api/projects.d.ts +20 -0
- package/dist-lib/lib/api/projects.js +172 -0
- package/dist-lib/lib/api/rag-plugin.d.ts +17 -0
- package/dist-lib/lib/api/rag-plugin.js +44 -0
- package/dist-lib/lib/api/rag.d.ts +0 -1
- package/dist-lib/lib/api/rag.js +106 -33
- package/dist-lib/lib/api/served.d.ts +17 -0
- package/dist-lib/lib/api/served.js +65 -0
- package/dist-lib/lib/api/sync.d.ts +2 -1
- package/dist-lib/lib/api/sync.js +13 -3
- package/dist-lib/lib/api/tool-activity.d.ts +2 -1
- package/dist-lib/lib/api/tool-activity.js +4 -3
- package/dist-lib/lib/api/tool-configs.d.ts +2 -1
- package/dist-lib/lib/api/tool-configs.js +6 -9
- package/dist-lib/lib/api/upload-frames.d.ts +0 -1
- package/dist-lib/lib/api/upload-frames.js +0 -1
- package/dist-lib/lib/api/watchable.d.ts +3 -2
- package/dist-lib/lib/api/watchable.js +2 -3
- package/dist-lib/lib/api/workspace.d.ts +12 -0
- package/dist-lib/lib/api/workspace.js +61 -0
- package/dist-lib/lib/assistant/fake-models.d.ts +20 -0
- package/dist-lib/lib/assistant/fake-models.js +112 -0
- package/dist-lib/lib/assistant/harness.d.ts +48 -31
- package/dist-lib/lib/assistant/harness.js +51 -10
- package/dist-lib/lib/assistant/history.d.ts +37 -17
- package/dist-lib/lib/assistant/history.js +212 -87
- package/dist-lib/lib/assistant/host-run-log.d.ts +6 -1
- package/dist-lib/lib/assistant/host-run-log.js +24 -36
- package/dist-lib/lib/assistant/media-round.d.ts +61 -0
- package/dist-lib/lib/assistant/media-round.js +111 -0
- package/dist-lib/lib/assistant/message.d.ts +28 -1
- package/dist-lib/lib/assistant/message.js +65 -2
- package/dist-lib/lib/assistant/model-round.d.ts +118 -0
- package/dist-lib/lib/assistant/model-round.js +706 -0
- package/dist-lib/lib/assistant/pdf-budget.d.ts +11 -0
- package/dist-lib/lib/assistant/pdf-budget.js +12 -0
- package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
- package/dist-lib/lib/assistant/pdf-pages.js +75 -0
- package/dist-lib/lib/assistant/round-host.d.ts +65 -0
- package/dist-lib/lib/assistant/round-host.js +332 -0
- package/dist-lib/lib/assistant/skill-encode.d.ts +2 -1
- package/dist-lib/lib/assistant/skill-encode.js +2 -1
- package/dist-lib/lib/assistant/upload.d.ts +12 -0
- package/dist-lib/lib/assistant/upload.js +36 -0
- package/dist-lib/lib/assistant/video-budget.d.ts +13 -0
- package/dist-lib/lib/assistant/video-budget.js +29 -0
- package/dist-lib/lib/assistant-client.d.ts +5 -1
- package/dist-lib/lib/assistant-client.js +54 -14
- package/dist-lib/lib/assistant-tree.d.ts +14 -3
- package/dist-lib/lib/assistant-tree.js +113 -21
- package/dist-lib/lib/assistant.d.ts +115 -25
- package/dist-lib/lib/assistant.js +2409 -1245
- package/dist-lib/lib/audio-format.js +1 -1
- package/dist-lib/lib/chat-suggestion.d.ts +3 -0
- package/dist-lib/lib/chat-suggestion.js +47 -0
- package/dist-lib/lib/client.d.ts +3 -2
- package/dist-lib/lib/client.js +18 -3
- package/dist-lib/lib/compaction.d.ts +3 -1
- package/dist-lib/lib/compaction.js +20 -6
- package/dist-lib/lib/constants.d.ts +10 -0
- package/dist-lib/lib/constants.js +10 -0
- package/dist-lib/lib/core/agent-copies.d.ts +9 -0
- package/dist-lib/lib/core/agent-copies.js +47 -0
- package/dist-lib/lib/core/agent-hosting.d.ts +25 -0
- package/dist-lib/lib/core/agent-hosting.js +76 -0
- package/dist-lib/lib/core/agent.d.ts +9 -1
- package/dist-lib/lib/core/agent.js +58 -63
- package/dist-lib/lib/core/approval-rules.d.ts +5 -1
- package/dist-lib/lib/core/approval-rules.js +17 -9
- package/dist-lib/lib/core/archived-mesh.d.ts +14 -7
- package/dist-lib/lib/core/archived-mesh.js +75 -59
- package/dist-lib/lib/core/async-iterable.js +1 -1
- package/dist-lib/lib/core/blind-peers.d.ts +1 -0
- package/dist-lib/lib/core/blind-peers.js +1 -0
- package/dist-lib/lib/core/chat-activity.d.ts +1 -1
- package/dist-lib/lib/core/chat-activity.js +45 -34
- package/dist-lib/lib/core/chat-copy.d.ts +42 -0
- package/dist-lib/lib/core/chat-copy.js +404 -0
- package/dist-lib/lib/core/chat-fork.d.ts +16 -0
- package/dist-lib/lib/core/chat-fork.js +246 -0
- package/dist-lib/lib/core/chat-group.js +10 -22
- package/dist-lib/lib/core/chat-move.d.ts +77 -0
- package/dist-lib/lib/core/chat-move.js +601 -0
- package/dist-lib/lib/core/chat-order.d.ts +2 -1
- package/dist-lib/lib/core/chat-order.js +28 -19
- package/dist-lib/lib/core/chat-read.d.ts +4 -0
- package/dist-lib/lib/core/chat-read.js +49 -0
- package/dist-lib/lib/core/chat-search.js +14 -12
- package/dist-lib/lib/core/chat.d.ts +32 -4
- package/dist-lib/lib/core/chat.js +135 -61
- package/dist-lib/lib/core/chunk.d.ts +35 -7
- package/dist-lib/lib/core/chunk.js +271 -72
- package/dist-lib/lib/core/collections.d.ts +41 -1
- package/dist-lib/lib/core/collections.js +41 -1
- package/dist-lib/lib/core/config-value.d.ts +7 -0
- package/dist-lib/lib/core/config-value.js +15 -0
- package/dist-lib/lib/core/contract/activity.d.ts +7 -2
- package/dist-lib/lib/core/contract/activity.js +71 -23
- package/dist-lib/lib/core/contract/agent-join.d.ts +10 -0
- package/dist-lib/lib/core/contract/agent-join.js +104 -0
- package/dist-lib/lib/core/contract/agents.d.ts +5 -0
- package/dist-lib/lib/core/contract/agents.js +142 -3
- package/dist-lib/lib/core/contract/chat.d.ts +4 -0
- package/dist-lib/lib/core/contract/chat.js +53 -3
- package/dist-lib/lib/core/contract/chunks.d.ts +7 -0
- package/dist-lib/lib/core/contract/chunks.js +125 -38
- package/dist-lib/lib/core/contract/devices.js +6 -4
- package/dist-lib/lib/core/contract/index.d.ts +2 -3
- package/dist-lib/lib/core/contract/index.js +38 -11
- package/dist-lib/lib/core/contract/indexing.d.ts +1 -0
- package/dist-lib/lib/core/contract/indexing.js +51 -7
- package/dist-lib/lib/core/contract/invites.d.ts +3 -14
- package/dist-lib/lib/core/contract/invites.js +26 -36
- package/dist-lib/lib/core/contract/joined-meshes.js +4 -1
- package/dist-lib/lib/core/contract/knowledge.d.ts +1 -0
- package/dist-lib/lib/core/contract/knowledge.js +57 -6
- package/dist-lib/lib/core/contract/members.d.ts +3 -1
- package/dist-lib/lib/core/contract/members.js +48 -12
- package/dist-lib/lib/core/contract/mesh-kind.d.ts +3 -3
- package/dist-lib/lib/core/contract/mesh-kind.js +20 -16
- package/dist-lib/lib/core/contract/mesh-name.d.ts +3 -0
- package/dist-lib/lib/core/contract/mesh-name.js +31 -0
- package/dist-lib/lib/core/contract/mesh-rules.d.ts +8 -0
- package/dist-lib/lib/core/contract/mesh-rules.js +35 -0
- package/dist-lib/lib/core/contract/mesh-seeds.d.ts +2 -0
- package/dist-lib/lib/core/contract/mesh-seeds.js +26 -0
- package/dist-lib/lib/core/contract/model-requests.d.ts +26 -0
- package/dist-lib/lib/core/contract/model-requests.js +280 -0
- package/dist-lib/lib/core/contract/oldest-version.d.ts +9 -0
- package/dist-lib/lib/core/contract/oldest-version.js +20 -0
- package/dist-lib/lib/core/contract/open-join.d.ts +2 -0
- package/dist-lib/lib/core/contract/open-join.js +77 -0
- package/dist-lib/lib/core/contract/project-device-keys.d.ts +9 -0
- package/dist-lib/lib/core/contract/project-device-keys.js +38 -0
- package/dist-lib/lib/core/contract/project-host-keys.d.ts +9 -0
- package/dist-lib/lib/core/contract/project-host-keys.js +52 -0
- package/dist-lib/lib/core/contract/project-order.d.ts +2 -0
- package/dist-lib/lib/core/contract/project-order.js +25 -0
- package/dist-lib/lib/core/contract/projects.d.ts +23 -0
- package/dist-lib/lib/core/contract/projects.js +339 -0
- package/dist-lib/lib/core/contract/public-mesh.d.ts +3 -0
- package/dist-lib/lib/core/contract/public-mesh.js +31 -0
- package/dist-lib/lib/core/contract/public-seeds.d.ts +9 -0
- package/dist-lib/lib/core/contract/public-seeds.js +43 -0
- package/dist-lib/lib/core/contract/roles.d.ts +10 -0
- package/dist-lib/lib/core/contract/roles.js +123 -0
- package/dist-lib/lib/core/contract/run-requests.d.ts +11 -0
- package/dist-lib/lib/core/contract/run-requests.js +114 -0
- package/dist-lib/lib/core/contract/seed-defaults.d.ts +3 -1
- package/dist-lib/lib/core/contract/seed-defaults.js +17 -4
- package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
- package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
- package/dist-lib/lib/core/contract/skill-secrets.d.ts +3 -0
- package/dist-lib/lib/core/contract/skill-secrets.js +32 -0
- package/dist-lib/lib/core/contract/tool-activity.js +12 -1
- package/dist-lib/lib/core/contract/tool-configs.js +2 -1
- package/dist-lib/lib/core/contract/types.d.ts +2 -2
- package/dist-lib/lib/core/contract/workspace.d.ts +31 -0
- package/dist-lib/lib/core/contract/workspace.js +311 -0
- package/dist-lib/lib/core/contract/writers.js +100 -16
- package/dist-lib/lib/core/deleted-agent-runs.d.ts +8 -0
- package/dist-lib/lib/core/deleted-agent-runs.js +57 -0
- package/dist-lib/lib/core/departures.d.ts +18 -5
- package/dist-lib/lib/core/departures.js +82 -6
- package/dist-lib/lib/core/device-control.d.ts +21 -0
- package/dist-lib/lib/core/device-control.js +91 -0
- package/dist-lib/lib/core/device-seal.d.ts +4 -0
- package/dist-lib/lib/core/device-seal.js +22 -0
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +6 -11
- package/dist-lib/lib/core/document-attachment.d.ts +10 -0
- package/dist-lib/lib/core/document-attachment.js +14 -0
- package/dist-lib/lib/core/files/attachments.d.ts +2 -0
- package/dist-lib/lib/core/files/attachments.js +23 -7
- package/dist-lib/lib/core/files/index.d.ts +28 -15
- package/dist-lib/lib/core/files/index.js +222 -43
- package/dist-lib/lib/core/files/knowledge.d.ts +10 -1
- package/dist-lib/lib/core/files/knowledge.js +77 -5
- package/dist-lib/lib/core/files/preview/index.js +6 -2
- package/dist-lib/lib/core/files/processing/claims.d.ts +7 -0
- package/dist-lib/lib/core/files/processing/claims.js +33 -7
- package/dist-lib/lib/core/files/processing/document.d.ts +8 -0
- package/dist-lib/lib/core/files/processing/document.js +26 -2
- package/dist-lib/lib/core/files/processing/index.d.ts +12 -3
- package/dist-lib/lib/core/files/processing/index.js +122 -73
- package/dist-lib/lib/core/files/processing/protocol.d.ts +7 -1
- package/dist-lib/lib/core/files/processing/protocol.js +27 -37
- package/dist-lib/lib/core/files/processing/source.d.ts +4 -0
- package/dist-lib/lib/core/files/processing/source.js +12 -4
- package/dist-lib/lib/core/files/processing/state.d.ts +5 -1
- package/dist-lib/lib/core/files/processing/state.js +9 -1
- package/dist-lib/lib/core/files/rag/build.d.ts +15 -2
- package/dist-lib/lib/core/files/rag/build.js +119 -21
- package/dist-lib/lib/core/files/rag/failure.d.ts +20 -0
- package/dist-lib/lib/core/files/rag/failure.js +58 -0
- package/dist-lib/lib/core/files/rag/index.d.ts +21 -5
- package/dist-lib/lib/core/files/rag/index.js +38 -9
- package/dist-lib/lib/core/files/rag/joined-index.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/joined-index.js +35 -0
- package/dist-lib/lib/core/files/rag/limits.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/limits.js +1 -0
- package/dist-lib/lib/core/files/rag/load.d.ts +3 -3
- package/dist-lib/lib/core/files/rag/load.js +6 -3
- package/dist-lib/lib/core/files/rag/plugin-index.d.ts +32 -0
- package/dist-lib/lib/core/files/rag/plugin-index.js +120 -0
- package/dist-lib/lib/core/files/rag/policy.d.ts +10 -1
- package/dist-lib/lib/core/files/rag/policy.js +23 -2
- package/dist-lib/lib/core/files/rag/produce.d.ts +3 -4
- package/dist-lib/lib/core/files/rag/produce.js +31 -18
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +8 -2
- package/dist-lib/lib/core/files/rag/similarity.d.ts +2 -2
- package/dist-lib/lib/core/files/rag/similarity.js +2 -3
- package/dist-lib/lib/core/files/records/chunks.js +22 -1
- package/dist-lib/lib/core/files/records/index.d.ts +1 -1
- package/dist-lib/lib/core/files/records/index.js +1 -1
- package/dist-lib/lib/core/files/records/knowledge.d.ts +12 -4
- package/dist-lib/lib/core/files/records/knowledge.js +34 -30
- package/dist-lib/lib/core/files/records/purge.js +13 -8
- package/dist-lib/lib/core/files/records/reclaim.js +21 -55
- package/dist-lib/lib/core/files/records/routing.d.ts +1 -1
- package/dist-lib/lib/core/files/records/routing.js +6 -2
- package/dist-lib/lib/core/files/records/source.js +3 -5
- package/dist-lib/lib/core/files/records/sweep.d.ts +3 -0
- package/dist-lib/lib/core/files/records/sweep.js +9 -3
- package/dist-lib/lib/core/files/store/blob.d.ts +2 -0
- package/dist-lib/lib/core/files/store/blob.js +2 -2
- package/dist-lib/lib/core/files/store/index.d.ts +3 -1
- package/dist-lib/lib/core/files/store/index.js +4 -1
- package/dist-lib/lib/core/files/store/reference.d.ts +3 -0
- package/dist-lib/lib/core/files/store/reference.js +12 -2
- package/dist-lib/lib/core/files/store/sweep.js +3 -1
- package/dist-lib/lib/core/files/upload.d.ts +5 -1
- package/dist-lib/lib/core/files/upload.js +117 -51
- package/dist-lib/lib/core/first-event.d.ts +6 -0
- package/dist-lib/lib/core/first-event.js +13 -0
- package/dist-lib/lib/core/fs-drives.d.ts +6 -3
- package/dist-lib/lib/core/fs-drives.js +35 -35
- package/dist-lib/lib/core/helpers/index.d.ts +1 -1
- package/dist-lib/lib/core/helpers/index.js +2 -2
- package/dist-lib/lib/core/id.d.ts +1 -0
- package/dist-lib/lib/core/id.js +3 -0
- package/dist-lib/lib/core/identity.d.ts +3 -1
- package/dist-lib/lib/core/identity.js +25 -4
- package/dist-lib/lib/core/invite.d.ts +6 -2
- package/dist-lib/lib/core/invite.js +22 -8
- package/dist-lib/lib/core/local/files.d.ts +2 -1
- package/dist-lib/lib/core/local/files.js +5 -7
- package/dist-lib/lib/core/local/index.d.ts +93 -8
- package/dist-lib/lib/core/local/index.js +327 -28
- package/dist-lib/lib/core/local/run-logs.d.ts +38 -0
- package/dist-lib/lib/core/local/run-logs.js +132 -0
- package/dist-lib/lib/core/member-key.d.ts +7 -0
- package/dist-lib/lib/core/member-key.js +24 -0
- package/dist-lib/lib/core/membership.d.ts +3 -14
- package/dist-lib/lib/core/membership.js +3 -96
- package/dist-lib/lib/core/mesh.d.ts +132 -29
- package/dist-lib/lib/core/mesh.js +775 -215
- package/dist-lib/lib/core/migrations/agent-catalog.js +2 -8
- package/dist-lib/lib/core/migrations/agent-tools-scope.d.ts +2 -0
- package/dist-lib/lib/core/migrations/agent-tools-scope.js +18 -0
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
- package/dist-lib/lib/core/migrations/file-index.js +8 -6
- package/dist-lib/lib/core/migrations/index.d.ts +2 -1
- package/dist-lib/lib/core/migrations/index.js +69 -8
- package/dist-lib/lib/core/migrations/writer-links.d.ts +3 -0
- package/dist-lib/lib/core/migrations/writer-links.js +30 -0
- package/dist-lib/lib/core/model-requests.d.ts +13 -0
- package/dist-lib/lib/core/model-requests.js +65 -0
- package/dist-lib/lib/core/next-frame.js +2 -1
- package/dist-lib/lib/core/notification.js +100 -25
- package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
- package/dist-lib/lib/core/pdf/figure.js +64 -0
- package/dist-lib/lib/core/pdf/rasterize.d.ts +12 -3
- package/dist-lib/lib/core/pdf/rasterize.js +77 -28
- package/dist-lib/lib/core/peer-duplex.d.ts +34 -0
- package/dist-lib/lib/core/{harness-loan.js → peer-duplex.js} +104 -45
- package/dist-lib/lib/core/project-keys.d.ts +16 -0
- package/dist-lib/lib/core/project-keys.js +65 -0
- package/dist-lib/lib/core/prompt-history.js +4 -4
- package/dist-lib/lib/core/protocol-pairing.d.ts +11 -0
- package/dist-lib/lib/core/protocol-pairing.js +22 -0
- package/dist-lib/lib/core/public-mesh.d.ts +25 -0
- package/dist-lib/lib/core/public-mesh.js +81 -0
- package/dist-lib/lib/core/purge.d.ts +3 -0
- package/dist-lib/lib/core/purge.js +7 -0
- package/dist-lib/lib/core/run-driver.d.ts +17 -0
- package/dist-lib/lib/core/run-driver.js +20 -0
- package/dist-lib/lib/core/run-requests.d.ts +14 -0
- package/dist-lib/lib/core/run-requests.js +78 -0
- package/dist-lib/lib/core/send.d.ts +2 -0
- package/dist-lib/lib/core/send.js +17 -4
- package/dist-lib/lib/core/senders.d.ts +19 -0
- package/dist-lib/lib/core/senders.js +45 -0
- package/dist-lib/lib/core/shared-agents.d.ts +40 -0
- package/dist-lib/lib/core/shared-agents.js +283 -0
- package/dist-lib/lib/core/skill-availability.d.ts +33 -0
- package/dist-lib/lib/core/skill-availability.js +67 -0
- package/dist-lib/lib/core/skill-secrets.d.ts +13 -18
- package/dist-lib/lib/core/skill-secrets.js +93 -72
- package/dist-lib/lib/core/sync/background.d.ts +34 -0
- package/dist-lib/lib/core/sync/background.js +86 -0
- package/dist-lib/lib/core/sync/changed.d.ts +20 -0
- package/dist-lib/lib/core/sync/changed.js +7 -0
- package/dist-lib/lib/core/sync/devices.js +6 -3
- package/dist-lib/lib/core/sync/files.d.ts +1 -0
- package/dist-lib/lib/core/sync/files.js +50 -72
- package/dist-lib/lib/core/sync/index.d.ts +1 -1
- package/dist-lib/lib/core/sync/index.js +193 -81
- package/dist-lib/lib/core/sync/view-updates.d.ts +39 -0
- package/dist-lib/lib/core/sync/view-updates.js +124 -0
- package/dist-lib/lib/core/sync-status.js +99 -43
- package/dist-lib/lib/core/system-info.d.ts +2 -2
- package/dist-lib/lib/core/system-info.js +10 -11
- package/dist-lib/lib/core/tool-activity.js +6 -12
- package/dist-lib/lib/core/tool-configs.d.ts +5 -3
- package/dist-lib/lib/core/tool-configs.js +27 -39
- package/dist-lib/lib/core/transcript-visibility.d.ts +5 -5
- package/dist-lib/lib/core/transcript-visibility.js +27 -31
- package/dist-lib/lib/core/upgrade-agents.d.ts +11 -0
- package/dist-lib/lib/core/upgrade-agents.js +78 -0
- package/dist-lib/lib/core/upgrade-summary.d.ts +19 -0
- package/dist-lib/lib/core/upgrade-summary.js +67 -0
- package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
- package/dist-lib/lib/core/vault-managed-skills.js +105 -0
- package/dist-lib/lib/core/video/attachment.d.ts +1 -0
- package/dist-lib/lib/core/video/attachment.js +7 -0
- package/dist-lib/lib/core/video/digest.d.ts +16 -0
- package/dist-lib/lib/core/video/digest.js +57 -0
- package/dist-lib/lib/core/video/frames.d.ts +32 -0
- package/dist-lib/lib/core/video/frames.js +224 -0
- package/dist-lib/lib/core/view-read.d.ts +4 -0
- package/dist-lib/lib/core/view-read.js +23 -0
- package/dist-lib/lib/core/workspace-upgrade.d.ts +23 -0
- package/dist-lib/lib/core/workspace-upgrade.js +51 -0
- package/dist-lib/lib/core.d.ts +345 -88
- package/dist-lib/lib/core.js +4275 -1513
- package/dist-lib/lib/credential-pusher.d.ts +17 -7
- package/dist-lib/lib/credential-pusher.js +111 -62
- package/dist-lib/lib/custom-model-pusher.d.ts +2 -4
- package/dist-lib/lib/custom-model-task.d.ts +2 -1
- package/dist-lib/lib/custom-model-task.js +2 -2
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/lib/diagnostics.d.ts +7 -0
- package/dist-lib/lib/diagnostics.js +22 -0
- package/dist-lib/lib/doctor/checks.d.ts +15 -0
- package/dist-lib/lib/doctor/checks.js +272 -0
- package/dist-lib/lib/doctor/redact.d.ts +4 -0
- package/dist-lib/lib/doctor/redact.js +31 -0
- package/dist-lib/lib/doctor/render.d.ts +8 -0
- package/dist-lib/lib/doctor/render.js +83 -0
- package/dist-lib/lib/doctor/tree.d.ts +5 -0
- package/dist-lib/lib/doctor/tree.js +167 -0
- package/dist-lib/lib/downloads-allowed-pusher.d.ts +8 -0
- package/dist-lib/lib/downloads-allowed-pusher.js +37 -0
- package/dist-lib/lib/errors.d.ts +814 -0
- package/dist-lib/lib/errors.js +748 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +8 -1
- package/dist-lib/lib/fs-drive-bridge.js +312 -31
- package/dist-lib/lib/guards.d.ts +1 -0
- package/dist-lib/lib/guards.js +4 -0
- package/dist-lib/lib/inference-calls.d.ts +1 -2
- package/dist-lib/lib/inference-calls.js +2 -10
- package/dist-lib/lib/integrations/setup-routes.js +7 -5
- package/dist-lib/lib/knowledge-search.d.ts +1 -1
- package/dist-lib/lib/knowledge-search.js +5 -51
- package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
- package/dist-lib/lib/kv-cache-ledger.js +72 -0
- package/dist-lib/lib/kv-cache-reclaim.d.ts +2 -1
- package/dist-lib/lib/kv-cache-reclaim.js +30 -0
- package/dist-lib/lib/kv-cache-retention.d.ts +36 -0
- package/dist-lib/lib/kv-cache-retention.js +101 -0
- package/dist-lib/lib/latest-frame.d.ts +10 -0
- package/dist-lib/lib/latest-frame.js +48 -0
- package/dist-lib/lib/llm-model-names.d.ts +1 -1
- package/dist-lib/lib/llm-model-names.js +1 -1
- package/dist-lib/lib/log.d.ts +7 -6
- package/dist-lib/lib/log.js +14 -7
- package/dist-lib/lib/logger-type.d.ts +2 -5
- package/dist-lib/lib/mesh-scoped-engine.js +47 -2
- package/dist-lib/lib/model-context.js +1 -2
- package/dist-lib/lib/model-download-status.d.ts +3 -3
- package/dist-lib/lib/model-download.d.ts +22 -13
- package/dist-lib/lib/model-download.js +106 -37
- package/dist-lib/lib/model-idle-pusher.d.ts +2 -4
- package/dist-lib/lib/model-memory-cap.d.ts +30 -0
- package/dist-lib/lib/model-memory-cap.js +78 -0
- package/dist-lib/lib/models-watch.d.ts +1 -1
- package/dist-lib/lib/models-watch.js +4 -4
- package/dist-lib/lib/oauth/browser-connect.js +3 -2
- package/dist-lib/lib/oauth/flow-core.js +5 -3
- package/dist-lib/lib/oauth/flow.js +1 -1
- package/dist-lib/lib/oauth/loopback.d.ts +1 -0
- package/dist-lib/lib/oauth/loopback.js +57 -12
- package/dist-lib/lib/oauth/providers.js +4 -2
- package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
- package/dist-lib/lib/oauth/register.js +35 -19
- package/dist-lib/lib/oauth/request.d.ts +10 -0
- package/dist-lib/lib/oauth/request.js +22 -0
- package/dist-lib/lib/oauth/resolve.js +42 -13
- package/dist-lib/lib/oauth/token-exchange-core.js +40 -31
- package/dist-lib/lib/oauth/types.d.ts +3 -0
- package/dist-lib/lib/oauth.d.ts +2 -1
- package/dist-lib/lib/oauth.js +1 -0
- package/dist-lib/lib/persistent-dir.d.ts +1 -0
- package/dist-lib/lib/persistent-dir.js +9 -0
- package/dist-lib/lib/probe-rounds.d.ts +8 -0
- package/dist-lib/lib/probe-rounds.js +10 -0
- package/dist-lib/lib/reconnecting-watch.js +19 -11
- package/dist-lib/lib/run-input.d.ts +14 -0
- package/dist-lib/lib/run-input.js +33 -0
- package/dist-lib/lib/run-notices.d.ts +5 -0
- package/dist-lib/lib/run-notices.js +13 -2
- package/dist-lib/lib/run-replay.d.ts +45 -0
- package/dist-lib/lib/run-replay.js +169 -0
- package/dist-lib/lib/run-transcript.d.ts +13 -12
- package/dist-lib/lib/run-transcript.js +20 -19
- package/dist-lib/lib/suspend-lifecycle.js +15 -5
- package/dist-lib/lib/task.js +6 -4
- package/dist-lib/lib/test-env.d.ts +1 -0
- package/dist-lib/lib/test-env.js +4 -0
- package/dist-lib/schema/build.js +66 -55
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/content.d.ts +5 -1
- package/dist-lib/schema/content.js +60 -12
- package/dist-lib/schema/engine.d.ts +1 -0
- package/dist-lib/schema/engine.js +941 -152
- package/dist-lib/schema/field-order.js +8 -1
- package/dist-lib/schema/indexes.d.ts +10 -0
- package/dist-lib/schema/indexes.js +53 -3
- package/dist-lib/schema/local.js +83 -5
- package/dist-lib/schema/qvac.d.ts +4 -1
- package/dist-lib/schema/qvac.js +558 -16
- package/dist-lib/spec/bind.js +261 -48
- package/dist-lib/spec/calls.js +56 -5
- package/dist-lib/spec/capabilities.d.ts +129 -20
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/dist-lib/spec/hrpc/hrpc.json +870 -207
- package/dist-lib/spec/hrpc/index.js +969 -347
- package/dist-lib/spec/hrpc/messages.js +7590 -4896
- package/dist-lib/spec/hyperschema/index.js +7590 -4896
- package/dist-lib/spec/hyperschema/schema.json +5316 -3224
- package/dist-lib/spec/hyperschema/types.d.ts +576 -62
- package/dist-lib/spec/local/hyperdb/db.json +95 -1
- package/dist-lib/spec/local/hyperdb/index.js +459 -2
- package/dist-lib/spec/local/hyperdb/messages.js +1588 -488
- package/dist-lib/spec/local/hyperschema/index.js +584 -16
- package/dist-lib/spec/local/hyperschema/schema.json +369 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +88 -2
- package/dist-lib/spec/mesh/hyperdb/db.json +711 -9
- package/dist-lib/spec/mesh/hyperdb/index.js +2769 -7
- package/dist-lib/spec/mesh/hyperdb/messages.js +7140 -1298
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +205 -1
- package/dist-lib/spec/mesh/hyperdispatch/index.js +579 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +4017 -267
- package/dist-lib/spec/mesh/hyperschema/index.js +4017 -267
- package/dist-lib/spec/mesh/hyperschema/schema.json +2193 -19
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +550 -6
- package/package.json +136 -90
- package/tui/README.md +119 -20
- package/tui/app.mjs +2000 -621
- package/tui/boot.mjs +76 -9
- package/tui/cli.mjs +93 -0
- package/tui/index.mjs +2 -51
- package/tui/lib/connect-sheet.mjs +350 -0
- package/tui/lib/device-target.mjs +64 -0
- package/tui/lib/folders-command.mjs +84 -0
- package/tui/lib/fork-command.mjs +43 -0
- package/tui/lib/knowledge-import.mjs +3 -21
- package/tui/lib/local-path.mjs +21 -0
- package/tui/lib/move-command.mjs +17 -0
- package/tui/lib/render.mjs +30 -1
- package/tui/lib/setup.mjs +59 -25
- package/tui/lib/skill-connect.mjs +145 -0
- package/tui/lib/updater.mjs +86 -0
- package/tui/main.mjs +44 -18
- package/tui/plugins.mjs +158 -0
- package/worker/assistant-sidecar.mjs +28 -4
- package/worker/stow-entry.mjs +3 -50
- package/dist-lib/lib/core/contract/compute.d.ts +0 -11
- package/dist-lib/lib/core/contract/compute.js +0 -48
- package/dist-lib/lib/core/device-invites.d.ts +0 -11
- package/dist-lib/lib/core/device-invites.js +0 -63
- package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
- package/dist-lib/lib/core/files/processing/settle.js +0 -86
- package/dist-lib/lib/core/grant-expiry.d.ts +0 -11
- package/dist-lib/lib/core/grant-expiry.js +0 -66
- package/dist-lib/lib/core/handoff-channel.d.ts +0 -47
- package/dist-lib/lib/core/handoff-channel.js +0 -123
- package/dist-lib/lib/core/harness-loan.d.ts +0 -29
- package/dist-lib/lib/core/host-run-log-store.d.ts +0 -114
- package/dist-lib/lib/core/host-run-log-store.js +0 -976
- package/dist-lib/lib/core/hosted-agents.d.ts +0 -38
- package/dist-lib/lib/core/hosted-agents.js +0 -140
- package/dist-lib/lib/core/inference-calls-handoff.d.ts +0 -20
- package/dist-lib/lib/core/inference-calls-handoff.js +0 -37
- package/dist-lib/lib/core/inference-calls-receiver.d.ts +0 -14
- package/dist-lib/lib/core/inference-calls-receiver.js +0 -42
- package/dist-lib/lib/core/mesh-seed-handoff.d.ts +0 -25
- package/dist-lib/lib/core/mesh-seed-handoff.js +0 -52
- package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
- package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
- package/dist-lib/lib/core/secret-handoff.d.ts +0 -17
- package/dist-lib/lib/core/secret-handoff.js +0 -29
- package/dist-lib/lib/core/skill-overlay-handoff.d.ts +0 -25
- package/dist-lib/lib/core/skill-overlay-handoff.js +0 -50
- package/dist-lib/lib/core/skill-overlay-receiver.d.ts +0 -8
- package/dist-lib/lib/core/skill-overlay-receiver.js +0 -23
- package/dist-lib/lib/image-cache-dir.d.ts +0 -1
- package/dist-lib/lib/image-cache-dir.js +0 -5
- package/dist-lib/lib/log-levels.d.ts +0 -7
- package/dist-lib/lib/log-levels.js +0 -1
- package/dist-lib/lib/logger.d.ts +0 -5
- package/dist-lib/lib/logger.js +0 -18
- package/dist-lib/lib/oauth/loopback.stub.d.ts +0 -3
- package/dist-lib/lib/oauth/loopback.stub.js +0 -6
|
@@ -1,976 +0,0 @@
|
|
|
1
|
-
import { createCipheriv, createDecipheriv, createHmac, randomBytes, randomUUID } from 'crypto';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
import Corestore from 'corestore';
|
|
4
|
-
import Hyperbee from 'hyperbee2';
|
|
5
|
-
import { applyEngineStep, createEngineBoot, validateEngineBoot } from '@qvac/harness/run-log';
|
|
6
|
-
import ScopeLock from 'scope-lock';
|
|
7
|
-
import { isRecord } from '../guards.js';
|
|
8
|
-
const STORE_NAMESPACE = 'qvac-host-run-log-v1';
|
|
9
|
-
const INDEX_NAME = 'index-v1';
|
|
10
|
-
const CURSOR_KEY = b4a.from('cursor');
|
|
11
|
-
const RECORD_PREFIX = 'record:';
|
|
12
|
-
const STEP_PREFIX = 'step:';
|
|
13
|
-
const INDEX_VALUE_VERSION = 1;
|
|
14
|
-
const DEFAULT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
15
|
-
const DEFAULT_SNAPSHOT_TIMEOUT_MS = 30_000;
|
|
16
|
-
const MAX_TIMER_TIMEOUT_MS = 2_147_483_647;
|
|
17
|
-
const HOST_RUN_LOG_OWNERS = new WeakMap();
|
|
18
|
-
export class HostRunLogStore {
|
|
19
|
-
_ownerRoot;
|
|
20
|
-
_ownerNamespace;
|
|
21
|
-
_cores;
|
|
22
|
-
_retentionMs;
|
|
23
|
-
_now;
|
|
24
|
-
_locks = new Map();
|
|
25
|
-
_indexLock = new ScopeLock();
|
|
26
|
-
_sessions = new Map();
|
|
27
|
-
_indexBee = null;
|
|
28
|
-
_ready = null;
|
|
29
|
-
_closePromise = null;
|
|
30
|
-
_closed = false;
|
|
31
|
-
opened = false;
|
|
32
|
-
constructor(store, options = {}) {
|
|
33
|
-
const owner = ownerIdentity(store);
|
|
34
|
-
let namespaces = HOST_RUN_LOG_OWNERS.get(owner.root);
|
|
35
|
-
if (namespaces?.has(owner.namespace)) {
|
|
36
|
-
throw new Error('Host run-log store is already open for this Corestore');
|
|
37
|
-
}
|
|
38
|
-
this._ownerRoot = owner.root;
|
|
39
|
-
this._ownerNamespace = owner.namespace;
|
|
40
|
-
this._cores = store.namespace(STORE_NAMESPACE);
|
|
41
|
-
this._retentionMs = options.retentionMs ?? DEFAULT_RETENTION_MS;
|
|
42
|
-
this._now = options.now ?? Date.now;
|
|
43
|
-
if (!namespaces) {
|
|
44
|
-
HOST_RUN_LOG_OWNERS.set(owner.root, (namespaces = new Map()));
|
|
45
|
-
}
|
|
46
|
-
namespaces.set(owner.namespace, this);
|
|
47
|
-
}
|
|
48
|
-
ready() {
|
|
49
|
-
if (this._ready)
|
|
50
|
-
return this._ready;
|
|
51
|
-
this._ready = this._open();
|
|
52
|
-
return this._ready;
|
|
53
|
-
}
|
|
54
|
-
async _open() {
|
|
55
|
-
if (this._closed)
|
|
56
|
-
throw new Error('Host run-log store is closed');
|
|
57
|
-
await this._cores.ready();
|
|
58
|
-
const indexStore = storeSession(this._cores);
|
|
59
|
-
try {
|
|
60
|
-
const core = getCore(indexStore, { name: INDEX_NAME });
|
|
61
|
-
await core.ready();
|
|
62
|
-
const index = openBee(indexStore, { core });
|
|
63
|
-
await index.ready();
|
|
64
|
-
this._indexBee = index;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
await indexStore.close().catch(noop);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
for (const { id, entry } of await this._entries()) {
|
|
71
|
-
if (entry.expired)
|
|
72
|
-
continue;
|
|
73
|
-
const session = await this._openRun(entry.meshId, entry.runId, { restoreBoot: false });
|
|
74
|
-
try {
|
|
75
|
-
await this._fenceLease(id, entry, session);
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
await this._closeRun(session);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
await this._expireOldRuns();
|
|
82
|
-
this.opened = true;
|
|
83
|
-
}
|
|
84
|
-
async _fenceLease(id, entry, session) {
|
|
85
|
-
if (!session.cursor.active)
|
|
86
|
-
return;
|
|
87
|
-
const cursor = {
|
|
88
|
-
...session.cursor,
|
|
89
|
-
generation: randomUUID(),
|
|
90
|
-
active: false,
|
|
91
|
-
commitKind: 'lease'
|
|
92
|
-
};
|
|
93
|
-
await this._writeCursor(session, cursor);
|
|
94
|
-
session.cursor = cursor;
|
|
95
|
-
await this._putIndex(id, this._summaryEntry(session, entry.createdAt));
|
|
96
|
-
}
|
|
97
|
-
async begin({ meshId, runId }) {
|
|
98
|
-
if (!this.opened)
|
|
99
|
-
await this.ready();
|
|
100
|
-
this._assertOpen();
|
|
101
|
-
const id = scopeId(meshId, runId);
|
|
102
|
-
const lock = this._lock(id);
|
|
103
|
-
await lock.lock();
|
|
104
|
-
try {
|
|
105
|
-
this._assertOpen();
|
|
106
|
-
const indexed = await this._getIndex(id);
|
|
107
|
-
if (indexed?.expired) {
|
|
108
|
-
throw new Error(`Run ${runId} has expired and cannot be reused`);
|
|
109
|
-
}
|
|
110
|
-
const previous = this._sessions.get(id);
|
|
111
|
-
const session = previous ?? (await this._openRun(meshId, runId));
|
|
112
|
-
const generation = randomUUID();
|
|
113
|
-
const cursor = {
|
|
114
|
-
...session.cursor,
|
|
115
|
-
generation,
|
|
116
|
-
active: true,
|
|
117
|
-
updatedAt: this._now(),
|
|
118
|
-
commitKind: 'lease'
|
|
119
|
-
};
|
|
120
|
-
try {
|
|
121
|
-
await this._writeCursor(session, cursor);
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
if (!previous) {
|
|
125
|
-
await this._closeRun(session);
|
|
126
|
-
}
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
session.cursor = cursor;
|
|
130
|
-
this._sessions.set(id, session);
|
|
131
|
-
const existing = await this._getIndex(id);
|
|
132
|
-
const createdAt = existing?.createdAt ?? session.cursor.createdAt;
|
|
133
|
-
await this._putIndex(id, this._summaryEntry(session, createdAt));
|
|
134
|
-
return {
|
|
135
|
-
generation,
|
|
136
|
-
boot: session.boot.metadata ? clone(session.boot) : undefined,
|
|
137
|
-
digestKey: b4a.from(session.digestKey)
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
finally {
|
|
141
|
-
lock.unlock();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async append(args) {
|
|
145
|
-
const { meshId, runId, generation } = args;
|
|
146
|
-
const step = clone(args.step);
|
|
147
|
-
if (!this.opened) {
|
|
148
|
-
await this.ready();
|
|
149
|
-
}
|
|
150
|
-
this._assertOpen();
|
|
151
|
-
const id = scopeId(meshId, runId);
|
|
152
|
-
const lock = this._lock(id);
|
|
153
|
-
await lock.lock();
|
|
154
|
-
try {
|
|
155
|
-
this._assertOpen();
|
|
156
|
-
const session = await this._session(meshId, runId);
|
|
157
|
-
this._assertLease(session.cursor, generation);
|
|
158
|
-
if (step.records.some((record) => record.type === 'fork')) {
|
|
159
|
-
throw new Error('Forked run-log records are not supported by the host run-log store');
|
|
160
|
-
}
|
|
161
|
-
const next = applyEngineStep(session.boot, step);
|
|
162
|
-
if (next.metadata && next.metadata.runId !== runId) {
|
|
163
|
-
throw new Error('Run-log step metadata belongs to a different run');
|
|
164
|
-
}
|
|
165
|
-
const batch = session.bee.write();
|
|
166
|
-
if (step.seq > 0) {
|
|
167
|
-
const previousHeader = await getJson(session.bee, stepKey(step.seq - 1));
|
|
168
|
-
const previousLength = session.lastStepPhysicalLength;
|
|
169
|
-
if (!previousHeader || previousLength === undefined) {
|
|
170
|
-
throw new Error(`Run-log step ${step.seq - 1} is missing its physical commit boundary`);
|
|
171
|
-
}
|
|
172
|
-
if (previousHeader.physicalLength !== undefined &&
|
|
173
|
-
previousHeader.physicalLength !== previousLength) {
|
|
174
|
-
throw new Error(`Run-log step ${step.seq - 1} physical boundary changed`);
|
|
175
|
-
}
|
|
176
|
-
batch.tryPut(stepKey(step.seq - 1), jsonBytes({ ...previousHeader, physicalLength: previousLength }));
|
|
177
|
-
}
|
|
178
|
-
for (let i = 0; i < step.records.length; i++) {
|
|
179
|
-
const recordIndex = session.cursor.length + i;
|
|
180
|
-
batch.tryPut(recordKey(recordIndex), jsonBytes(step.records[i]));
|
|
181
|
-
}
|
|
182
|
-
const header = {
|
|
183
|
-
seq: step.seq,
|
|
184
|
-
expectedLength: step.expectedLength,
|
|
185
|
-
recordCount: step.records.length,
|
|
186
|
-
nextLength: next.length
|
|
187
|
-
};
|
|
188
|
-
batch.tryPut(stepKey(step.seq), jsonBytes(header));
|
|
189
|
-
const cursor = {
|
|
190
|
-
...session.cursor,
|
|
191
|
-
length: next.length,
|
|
192
|
-
nextSeq: next.nextSeq,
|
|
193
|
-
updatedAt: this._now(),
|
|
194
|
-
commitKind: 'step'
|
|
195
|
-
};
|
|
196
|
-
batch.tryPut(CURSOR_KEY, jsonBytes(cursor));
|
|
197
|
-
await batch.flush();
|
|
198
|
-
session.cursor = cursor;
|
|
199
|
-
session.lastStepPhysicalLength = session.bee.core.length;
|
|
200
|
-
session.boot = next;
|
|
201
|
-
}
|
|
202
|
-
finally {
|
|
203
|
-
lock.unlock();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
async release({ meshId, runId, generation }) {
|
|
207
|
-
if (!this.opened)
|
|
208
|
-
await this.ready();
|
|
209
|
-
this._assertOpen();
|
|
210
|
-
const id = scopeId(meshId, runId);
|
|
211
|
-
const lock = this._lock(id);
|
|
212
|
-
await lock.lock();
|
|
213
|
-
try {
|
|
214
|
-
this._assertOpen();
|
|
215
|
-
const session = await this._session(meshId, runId);
|
|
216
|
-
if (session.cursor.generation !== generation) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (session.cursor.active) {
|
|
220
|
-
const cursor = {
|
|
221
|
-
...session.cursor,
|
|
222
|
-
active: false,
|
|
223
|
-
updatedAt: this._now(),
|
|
224
|
-
commitKind: 'lease'
|
|
225
|
-
};
|
|
226
|
-
await this._writeCursor(session, cursor);
|
|
227
|
-
session.cursor = cursor;
|
|
228
|
-
}
|
|
229
|
-
const existing = await this._getIndex(id);
|
|
230
|
-
await this._putIndex(id, this._summaryEntry(session, existing?.createdAt ?? session.cursor.createdAt));
|
|
231
|
-
this._sessions.delete(id);
|
|
232
|
-
await this._closeRun(session);
|
|
233
|
-
}
|
|
234
|
-
finally {
|
|
235
|
-
lock.unlock();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
async exportRun({ meshId, runId }) {
|
|
239
|
-
if (!this.opened)
|
|
240
|
-
await this.ready();
|
|
241
|
-
this._assertOpen();
|
|
242
|
-
const id = scopeId(meshId, runId);
|
|
243
|
-
const lock = this._lock(id);
|
|
244
|
-
await lock.lock();
|
|
245
|
-
try {
|
|
246
|
-
this._assertOpen();
|
|
247
|
-
const session = await this._session(meshId, runId);
|
|
248
|
-
const head = session.bee.head();
|
|
249
|
-
const physicalLength = head?.length ?? 0;
|
|
250
|
-
if (physicalLength !== session.bee.core.length) {
|
|
251
|
-
throw new Error('Run-log Hyperbee head is not at the physical core length');
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
meshId,
|
|
255
|
-
runId,
|
|
256
|
-
publicKey: b4a.from(session.bee.core.key),
|
|
257
|
-
discoveryKey: b4a.from(session.bee.core.discoveryKey),
|
|
258
|
-
encryptionKey: b4a.from(session.encryptionKey),
|
|
259
|
-
physicalLength,
|
|
260
|
-
logicalLength: session.cursor.length,
|
|
261
|
-
nextSeq: session.cursor.nextSeq
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
finally {
|
|
265
|
-
lock.unlock();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async exportIndex() {
|
|
269
|
-
if (!this.opened)
|
|
270
|
-
await this.ready();
|
|
271
|
-
this._assertOpen();
|
|
272
|
-
await this._indexLock.lock();
|
|
273
|
-
try {
|
|
274
|
-
this._assertOpen();
|
|
275
|
-
const index = this._index();
|
|
276
|
-
const physicalLength = index.head()?.length ?? 0;
|
|
277
|
-
if (physicalLength !== index.core.length) {
|
|
278
|
-
throw new Error('Run-log index Hyperbee head is not at the physical core length');
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
publicKey: b4a.from(index.core.key),
|
|
282
|
-
discoveryKey: b4a.from(index.core.discoveryKey),
|
|
283
|
-
physicalLength
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
finally {
|
|
287
|
-
this._indexLock.unlock();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
async list({ meshId, includeExpired = false } = {}) {
|
|
291
|
-
if (!this.opened)
|
|
292
|
-
await this.ready();
|
|
293
|
-
this._assertOpen();
|
|
294
|
-
await this._indexLock.lock();
|
|
295
|
-
try {
|
|
296
|
-
this._assertOpen();
|
|
297
|
-
const rows = [];
|
|
298
|
-
for (const { id, entry } of await this._entries()) {
|
|
299
|
-
if (meshId !== undefined && entry.meshId !== meshId)
|
|
300
|
-
continue;
|
|
301
|
-
if (entry.expired && !includeExpired)
|
|
302
|
-
continue;
|
|
303
|
-
const session = this._sessions.get(id);
|
|
304
|
-
const summary = session ? this._summaryEntry(session, entry.createdAt) : entry;
|
|
305
|
-
rows.push({ ...summary, expired: entry.expired });
|
|
306
|
-
}
|
|
307
|
-
return rows.sort((a, b) => a.createdAt - b.createdAt || a.runId.localeCompare(b.runId));
|
|
308
|
-
}
|
|
309
|
-
finally {
|
|
310
|
-
this._indexLock.unlock();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
async expired({ meshId, runId }) {
|
|
314
|
-
if (!this.opened)
|
|
315
|
-
await this.ready();
|
|
316
|
-
this._assertOpen();
|
|
317
|
-
await this._indexLock.lock();
|
|
318
|
-
try {
|
|
319
|
-
this._assertOpen();
|
|
320
|
-
return (await this._getIndex(scopeId(meshId, runId)))?.expired === true;
|
|
321
|
-
}
|
|
322
|
-
finally {
|
|
323
|
-
this._indexLock.unlock();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
close() {
|
|
327
|
-
if (this._closePromise)
|
|
328
|
-
return this._closePromise;
|
|
329
|
-
this._closed = true;
|
|
330
|
-
this._closePromise = this._close();
|
|
331
|
-
return this._closePromise;
|
|
332
|
-
}
|
|
333
|
-
async _close() {
|
|
334
|
-
try {
|
|
335
|
-
await this._ready?.catch(noop);
|
|
336
|
-
const acquired = [];
|
|
337
|
-
try {
|
|
338
|
-
for (const lock of this._locks.values()) {
|
|
339
|
-
await lock.lock();
|
|
340
|
-
acquired.push(lock);
|
|
341
|
-
}
|
|
342
|
-
await this._indexLock.lock();
|
|
343
|
-
acquired.push(this._indexLock);
|
|
344
|
-
for (const session of this._sessions.values()) {
|
|
345
|
-
await this._closeRun(session);
|
|
346
|
-
}
|
|
347
|
-
this._sessions.clear();
|
|
348
|
-
}
|
|
349
|
-
finally {
|
|
350
|
-
for (const lock of acquired.reverse()) {
|
|
351
|
-
lock.unlock();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
await Promise.resolve(this._indexBee?.close()).catch(noop);
|
|
355
|
-
this._indexBee = null;
|
|
356
|
-
await this._cores.close();
|
|
357
|
-
}
|
|
358
|
-
finally {
|
|
359
|
-
const namespaces = HOST_RUN_LOG_OWNERS.get(this._ownerRoot);
|
|
360
|
-
if (namespaces?.get(this._ownerNamespace) === this) {
|
|
361
|
-
namespaces.delete(this._ownerNamespace);
|
|
362
|
-
if (namespaces.size === 0) {
|
|
363
|
-
HOST_RUN_LOG_OWNERS.delete(this._ownerRoot);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
async _expireOldRuns() {
|
|
369
|
-
if (this._retentionMs > 0) {
|
|
370
|
-
const cutoff = this._now() - this._retentionMs;
|
|
371
|
-
for (const { id, entry } of await this._entries()) {
|
|
372
|
-
if (entry.expired)
|
|
373
|
-
continue;
|
|
374
|
-
const session = await this._openRun(entry.meshId, entry.runId, { restoreBoot: false });
|
|
375
|
-
try {
|
|
376
|
-
await this._expireRun({ id, entry }, session, cutoff);
|
|
377
|
-
}
|
|
378
|
-
finally {
|
|
379
|
-
await this._closeRun(session);
|
|
380
|
-
this._sessions.delete(id);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
for (const { id, entry } of await this._entries()) {
|
|
385
|
-
if (!entry.expired || !entry.cleanupPending)
|
|
386
|
-
continue;
|
|
387
|
-
const { runKey } = await this._keysById(id);
|
|
388
|
-
const runStore = storeSession(this._cores);
|
|
389
|
-
const core = getCore(runStore, {
|
|
390
|
-
key: b4a.from(entry.publicKey, 'hex'),
|
|
391
|
-
encryption: { key: runKey }
|
|
392
|
-
});
|
|
393
|
-
try {
|
|
394
|
-
await core.ready();
|
|
395
|
-
if (core.length > 0) {
|
|
396
|
-
await core.clear(0, core.length);
|
|
397
|
-
}
|
|
398
|
-
await this._putIndex(id, { ...entry, cleanupPending: false });
|
|
399
|
-
}
|
|
400
|
-
finally {
|
|
401
|
-
await core.close().catch(noop);
|
|
402
|
-
await runStore.close().catch(noop);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
async _expireRun({ id, entry }, session, cutoff) {
|
|
407
|
-
if (session.cursor.active || session.cursor.updatedAt >= cutoff)
|
|
408
|
-
return;
|
|
409
|
-
const tombstone = {
|
|
410
|
-
...entry,
|
|
411
|
-
active: false,
|
|
412
|
-
expired: true,
|
|
413
|
-
cleanupPending: true
|
|
414
|
-
};
|
|
415
|
-
await this._putIndex(id, tombstone);
|
|
416
|
-
const end = session.bee.core.length;
|
|
417
|
-
if (end > 0) {
|
|
418
|
-
await session.bee.core.clear(0, end);
|
|
419
|
-
}
|
|
420
|
-
await this._putIndex(id, { ...tombstone, cleanupPending: false });
|
|
421
|
-
}
|
|
422
|
-
async _session(meshId, runId) {
|
|
423
|
-
const id = scopeId(meshId, runId);
|
|
424
|
-
const cached = this._sessions.get(id);
|
|
425
|
-
if (cached) {
|
|
426
|
-
return cached;
|
|
427
|
-
}
|
|
428
|
-
const indexed = await this._getIndex(id);
|
|
429
|
-
if (!indexed) {
|
|
430
|
-
throw new Error(`Run ${runId} does not exist`);
|
|
431
|
-
}
|
|
432
|
-
if (indexed?.expired) {
|
|
433
|
-
throw new Error(`Run ${runId} has expired`);
|
|
434
|
-
}
|
|
435
|
-
const session = await this._openRun(meshId, runId);
|
|
436
|
-
this._sessions.set(id, session);
|
|
437
|
-
return session;
|
|
438
|
-
}
|
|
439
|
-
async _openRun(meshId, runId, { restoreBoot = true } = {}) {
|
|
440
|
-
validateScope(meshId, runId);
|
|
441
|
-
const id = scopeId(meshId, runId);
|
|
442
|
-
const name = `run-${id}`;
|
|
443
|
-
const keyPair = await this._cores.createKeyPair(name);
|
|
444
|
-
const encryptionKey = deriveKey(keyPair.secretKey, 'qvac-run-log/block-encryption/v1');
|
|
445
|
-
const digestKey = deriveKey(keyPair.secretKey, 'qvac-run-log/request-digest/v1');
|
|
446
|
-
const runStore = storeSession(this._cores);
|
|
447
|
-
let bee = null;
|
|
448
|
-
try {
|
|
449
|
-
const core = getCore(runStore, { name, encryption: { key: encryptionKey } });
|
|
450
|
-
await core.ready();
|
|
451
|
-
bee = openBee(runStore, { core });
|
|
452
|
-
await bee.ready();
|
|
453
|
-
const storedCursor = await getJson(bee, CURSOR_KEY);
|
|
454
|
-
let cursor;
|
|
455
|
-
let boot = createEngineBoot();
|
|
456
|
-
if (storedCursor) {
|
|
457
|
-
cursor = validateCursor(storedCursor, meshId, runId);
|
|
458
|
-
if (restoreBoot) {
|
|
459
|
-
boot = await foldStoredSteps(bee, cursor, { physicalLength: bee.core.length });
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
cursor = {
|
|
464
|
-
version: 1,
|
|
465
|
-
meshId,
|
|
466
|
-
runId,
|
|
467
|
-
generation: randomUUID(),
|
|
468
|
-
active: false,
|
|
469
|
-
commitKind: 'init',
|
|
470
|
-
length: 0,
|
|
471
|
-
nextSeq: 0,
|
|
472
|
-
createdAt: this._now(),
|
|
473
|
-
updatedAt: this._now()
|
|
474
|
-
};
|
|
475
|
-
const batch = bee.write();
|
|
476
|
-
batch.tryPut(CURSOR_KEY, jsonBytes(cursor));
|
|
477
|
-
await batch.flush();
|
|
478
|
-
}
|
|
479
|
-
const lastStepPhysicalLength = await recoverLastStepPhysicalLength(bee, cursor, {
|
|
480
|
-
physicalLength: bee.core.length
|
|
481
|
-
});
|
|
482
|
-
return {
|
|
483
|
-
id,
|
|
484
|
-
meshId,
|
|
485
|
-
runId,
|
|
486
|
-
name,
|
|
487
|
-
bee,
|
|
488
|
-
encryptionKey,
|
|
489
|
-
digestKey,
|
|
490
|
-
cursor,
|
|
491
|
-
boot,
|
|
492
|
-
lastStepPhysicalLength
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
catch (error) {
|
|
496
|
-
if (bee) {
|
|
497
|
-
await Promise.resolve(bee.close()).catch(noop);
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
await runStore.close().catch(noop);
|
|
501
|
-
}
|
|
502
|
-
throw error;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
async _writeCursor(session, cursor = session.cursor) {
|
|
506
|
-
const batch = session.bee.write();
|
|
507
|
-
if (cursor.nextSeq > 0) {
|
|
508
|
-
const physicalLength = session.lastStepPhysicalLength;
|
|
509
|
-
if (physicalLength === undefined) {
|
|
510
|
-
throw new Error('Run-log is missing the latest EngineStep physical commit boundary');
|
|
511
|
-
}
|
|
512
|
-
const key = stepKey(cursor.nextSeq - 1);
|
|
513
|
-
const header = await getJson(session.bee, key);
|
|
514
|
-
if (!header) {
|
|
515
|
-
throw new Error(`Run-log step ${cursor.nextSeq - 1} is missing before lease update`);
|
|
516
|
-
}
|
|
517
|
-
if (header.physicalLength !== undefined && header.physicalLength !== physicalLength) {
|
|
518
|
-
throw new Error(`Run-log step ${cursor.nextSeq - 1} physical boundary changed`);
|
|
519
|
-
}
|
|
520
|
-
batch.tryPut(key, jsonBytes({ ...header, physicalLength }));
|
|
521
|
-
}
|
|
522
|
-
batch.tryPut(CURSOR_KEY, jsonBytes(cursor));
|
|
523
|
-
await batch.flush();
|
|
524
|
-
}
|
|
525
|
-
_index() {
|
|
526
|
-
if (!this._indexBee)
|
|
527
|
-
throw new Error('Host run-log index is not ready');
|
|
528
|
-
return this._indexBee;
|
|
529
|
-
}
|
|
530
|
-
async _getIndex(id) {
|
|
531
|
-
const row = await this._index().get(b4a.from(id));
|
|
532
|
-
if (!row) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
const { indexKey } = await this._keysById(id);
|
|
536
|
-
const entry = openJson(row.value, indexKey);
|
|
537
|
-
if (scopeId(entry.meshId, entry.runId) !== id) {
|
|
538
|
-
throw new Error('Run-log index entry identity does not match its key');
|
|
539
|
-
}
|
|
540
|
-
return entry;
|
|
541
|
-
}
|
|
542
|
-
async _putIndex(id, entry) {
|
|
543
|
-
await this._indexLock.lock();
|
|
544
|
-
try {
|
|
545
|
-
const { indexKey } = await this._keys(entry.meshId, entry.runId);
|
|
546
|
-
const batch = this._index().write();
|
|
547
|
-
batch.tryPut(b4a.from(id), sealJson(entry, indexKey));
|
|
548
|
-
await batch.flush();
|
|
549
|
-
}
|
|
550
|
-
finally {
|
|
551
|
-
this._indexLock.unlock();
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
async _entries() {
|
|
555
|
-
const result = [];
|
|
556
|
-
for await (const row of this._index().createReadStream()) {
|
|
557
|
-
const id = b4a.toString(row.key);
|
|
558
|
-
if (!/^[a-f0-9]{64}$/.test(id)) {
|
|
559
|
-
throw new Error('Host run-log index contains an invalid scope key');
|
|
560
|
-
}
|
|
561
|
-
const { indexKey } = await this._keysById(id);
|
|
562
|
-
const entry = openJson(row.value, indexKey);
|
|
563
|
-
if (scopeId(entry.meshId, entry.runId) !== id) {
|
|
564
|
-
throw new Error('Run-log index entry identity does not match its key');
|
|
565
|
-
}
|
|
566
|
-
result.push({ id, entry });
|
|
567
|
-
}
|
|
568
|
-
return result;
|
|
569
|
-
}
|
|
570
|
-
_keys(meshId, runId) {
|
|
571
|
-
return this._keysById(scopeId(meshId, runId));
|
|
572
|
-
}
|
|
573
|
-
async _keysById(id) {
|
|
574
|
-
if (!/^[a-f0-9]{64}$/.test(id)) {
|
|
575
|
-
throw new Error('Host run-log index contains an invalid scope key');
|
|
576
|
-
}
|
|
577
|
-
const name = `run-${id}`;
|
|
578
|
-
const pair = await this._cores.createKeyPair(name);
|
|
579
|
-
return {
|
|
580
|
-
runKey: deriveKey(pair.secretKey, 'qvac-run-log/block-encryption/v1'),
|
|
581
|
-
indexKey: deriveKey(pair.secretKey, 'qvac-run-log/index-value-encryption/v1')
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
_summaryEntry(session, createdAt) {
|
|
585
|
-
return {
|
|
586
|
-
meshId: session.meshId,
|
|
587
|
-
runId: session.runId,
|
|
588
|
-
publicKey: b4a.toHex(session.bee.core.key),
|
|
589
|
-
discoveryKey: b4a.toHex(session.bee.core.discoveryKey),
|
|
590
|
-
createdAt,
|
|
591
|
-
updatedAt: session.cursor.updatedAt,
|
|
592
|
-
logicalLength: session.cursor.length,
|
|
593
|
-
nextSeq: session.cursor.nextSeq,
|
|
594
|
-
active: session.cursor.active
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
_lock(id) {
|
|
598
|
-
let lock = this._locks.get(id);
|
|
599
|
-
if (!lock) {
|
|
600
|
-
this._locks.set(id, (lock = new ScopeLock()));
|
|
601
|
-
}
|
|
602
|
-
return lock;
|
|
603
|
-
}
|
|
604
|
-
_assertOpen() {
|
|
605
|
-
if (this._closed)
|
|
606
|
-
throw new Error('Host run-log store is closed');
|
|
607
|
-
}
|
|
608
|
-
_assertLease(cursor, generation) {
|
|
609
|
-
if (!cursor.active || cursor.generation !== generation) {
|
|
610
|
-
throw new Error('Run-log lease is stale or has been released');
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
async _closeRun(session) {
|
|
614
|
-
await Promise.resolve(session.bee.close()).catch(noop);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
export async function openRunLogSnapshot(store, descriptor) {
|
|
618
|
-
validateScope(descriptor.meshId, descriptor.runId);
|
|
619
|
-
if (!Number.isSafeInteger(descriptor.physicalLength) || descriptor.physicalLength < 0) {
|
|
620
|
-
throw new TypeError('Run-log physical length must be a nonnegative safe integer');
|
|
621
|
-
}
|
|
622
|
-
if (descriptor.encryptionKey.byteLength !== 32) {
|
|
623
|
-
throw new TypeError('Run-log read key must contain 32 bytes');
|
|
624
|
-
}
|
|
625
|
-
const timeoutMs = descriptor.timeoutMs ?? DEFAULT_SNAPSHOT_TIMEOUT_MS;
|
|
626
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_TIMEOUT_MS) {
|
|
627
|
-
throw new TypeError(`Run-log snapshot timeout must be an integer from 1 to ${MAX_TIMER_TIMEOUT_MS}`);
|
|
628
|
-
}
|
|
629
|
-
const deadline = Date.now() + timeoutMs;
|
|
630
|
-
const snapshotStore = storeSession(store);
|
|
631
|
-
const core = getCore(snapshotStore, {
|
|
632
|
-
key: descriptor.publicKey,
|
|
633
|
-
encryption: { key: descriptor.encryptionKey },
|
|
634
|
-
timeout: timeoutMs
|
|
635
|
-
});
|
|
636
|
-
let bee = null;
|
|
637
|
-
let view = null;
|
|
638
|
-
try {
|
|
639
|
-
await withReadDeadline(() => core.ready(), deadline, timeoutMs);
|
|
640
|
-
if (descriptor.physicalLength > 0 && core.length < descriptor.physicalLength) {
|
|
641
|
-
await withReadDeadline(() => core.get(descriptor.physicalLength - 1, {
|
|
642
|
-
wait: true,
|
|
643
|
-
timeout: remainingReadMs(deadline, timeoutMs)
|
|
644
|
-
}), deadline, timeoutMs);
|
|
645
|
-
}
|
|
646
|
-
const opened = openBee(snapshotStore, {
|
|
647
|
-
core,
|
|
648
|
-
timeout: remainingReadMs(deadline, timeoutMs),
|
|
649
|
-
wait: true,
|
|
650
|
-
writable: false
|
|
651
|
-
});
|
|
652
|
-
bee = opened;
|
|
653
|
-
await withReadDeadline(() => opened.ready(), deadline, timeoutMs);
|
|
654
|
-
if (descriptor.physicalLength <= 0 || descriptor.physicalLength > bee.core.length) {
|
|
655
|
-
throw new Error('Requested run-log physical length is outside the available core prefix');
|
|
656
|
-
}
|
|
657
|
-
view = bee.checkout({
|
|
658
|
-
length: descriptor.physicalLength,
|
|
659
|
-
writable: false,
|
|
660
|
-
wait: true,
|
|
661
|
-
timeout: remainingReadMs(deadline, timeoutMs)
|
|
662
|
-
});
|
|
663
|
-
if (view.head()?.length !== descriptor.physicalLength) {
|
|
664
|
-
throw new Error('Requested run-log physical length is not a Hyperbee commit boundary');
|
|
665
|
-
}
|
|
666
|
-
const openRead = (target, key) => readSnapshotJson(target, key, { deadline, timeoutMs });
|
|
667
|
-
const cursor = await openRead(view, CURSOR_KEY);
|
|
668
|
-
if (!cursor) {
|
|
669
|
-
throw new Error('Requested run-log prefix has no committed cursor');
|
|
670
|
-
}
|
|
671
|
-
validateCursor(cursor, descriptor.meshId, descriptor.runId);
|
|
672
|
-
const lastStepPhysicalLength = await recoverLastStepPhysicalLength(view, cursor, {
|
|
673
|
-
physicalLength: descriptor.physicalLength,
|
|
674
|
-
read: openRead
|
|
675
|
-
});
|
|
676
|
-
const boot = await foldStoredSteps(view, cursor, {
|
|
677
|
-
physicalLength: descriptor.physicalLength,
|
|
678
|
-
read: openRead
|
|
679
|
-
});
|
|
680
|
-
if (boot.length !== cursor.length || boot.nextSeq !== cursor.nextSeq) {
|
|
681
|
-
throw new Error('Requested run-log prefix is not a complete committed step boundary');
|
|
682
|
-
}
|
|
683
|
-
const snapshotView = view;
|
|
684
|
-
let closePromise = null;
|
|
685
|
-
const closeSnapshot = () => {
|
|
686
|
-
if (!closePromise) {
|
|
687
|
-
closePromise = (async () => {
|
|
688
|
-
await Promise.resolve(snapshotView.close()).catch(noop);
|
|
689
|
-
await Promise.resolve(bee?.close()).catch(noop);
|
|
690
|
-
})();
|
|
691
|
-
}
|
|
692
|
-
return closePromise;
|
|
693
|
-
};
|
|
694
|
-
return {
|
|
695
|
-
meshId: descriptor.meshId,
|
|
696
|
-
runId: descriptor.runId,
|
|
697
|
-
physicalLength: descriptor.physicalLength,
|
|
698
|
-
logicalLength: cursor.length,
|
|
699
|
-
nextSeq: cursor.nextSeq,
|
|
700
|
-
boot,
|
|
701
|
-
async *records() {
|
|
702
|
-
const recordsDeadline = Date.now() + timeoutMs;
|
|
703
|
-
const readRecord = (target, key) => readSnapshotJson(target, key, { deadline: recordsDeadline, timeoutMs });
|
|
704
|
-
try {
|
|
705
|
-
let recordIndex = 0;
|
|
706
|
-
for (let seq = 0; seq < cursor.nextSeq; seq++) {
|
|
707
|
-
const header = await readRecord(snapshotView, stepKey(seq));
|
|
708
|
-
if (!header) {
|
|
709
|
-
throw new Error(`Run-log step ${seq} is missing from its committed prefix`);
|
|
710
|
-
}
|
|
711
|
-
const stepPhysicalLength = header.physicalLength ?? lastStepPhysicalLength;
|
|
712
|
-
if (stepPhysicalLength === undefined) {
|
|
713
|
-
throw new Error(`Run-log step ${seq} has no physical boundary`);
|
|
714
|
-
}
|
|
715
|
-
for (let i = 0; i < header.recordCount; i++) {
|
|
716
|
-
const record = await readCommittedRecord(readRecord, snapshotView, recordIndex);
|
|
717
|
-
yield { recordIndex, stepSeq: seq, physicalLength: stepPhysicalLength, record };
|
|
718
|
-
recordIndex++;
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
catch (error) {
|
|
723
|
-
await closeSnapshot();
|
|
724
|
-
throw error;
|
|
725
|
-
}
|
|
726
|
-
},
|
|
727
|
-
close: closeSnapshot
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
catch (error) {
|
|
731
|
-
await Promise.resolve(view?.close()).catch(noop);
|
|
732
|
-
await Promise.resolve(bee?.close()).catch(noop);
|
|
733
|
-
if (!bee) {
|
|
734
|
-
await core.close().catch(noop);
|
|
735
|
-
await snapshotStore.close().catch(noop);
|
|
736
|
-
}
|
|
737
|
-
throw error;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
async function readCommittedRecord(read, bee, recordIndex) {
|
|
741
|
-
const record = await read(bee, recordKey(recordIndex));
|
|
742
|
-
if (!record) {
|
|
743
|
-
throw new Error(`Run-log record ${recordIndex} is missing from its committed prefix`);
|
|
744
|
-
}
|
|
745
|
-
return record;
|
|
746
|
-
}
|
|
747
|
-
async function foldStoredSteps(bee, cursor, { physicalLength, read = getJson } = {}) {
|
|
748
|
-
let boot = createEngineBoot();
|
|
749
|
-
let expectedLength = 0;
|
|
750
|
-
let previousPhysicalLength = 0;
|
|
751
|
-
for (let seq = 0; seq < cursor.nextSeq; seq++) {
|
|
752
|
-
const header = await read(bee, stepKey(seq));
|
|
753
|
-
if (!header ||
|
|
754
|
-
header.seq !== seq ||
|
|
755
|
-
header.expectedLength !== expectedLength ||
|
|
756
|
-
!Number.isSafeInteger(header.recordCount) ||
|
|
757
|
-
header.recordCount < 1 ||
|
|
758
|
-
header.nextLength !== expectedLength + header.recordCount) {
|
|
759
|
-
throw new Error(`Run-log step ${seq} is missing or malformed`);
|
|
760
|
-
}
|
|
761
|
-
if (header.physicalLength === undefined && seq < cursor.nextSeq - 1) {
|
|
762
|
-
throw new Error(`Run-log step ${seq} is missing its durable physical commit boundary`);
|
|
763
|
-
}
|
|
764
|
-
if (header.physicalLength !== undefined) {
|
|
765
|
-
if (!Number.isSafeInteger(header.physicalLength) ||
|
|
766
|
-
header.physicalLength <= previousPhysicalLength ||
|
|
767
|
-
(physicalLength !== undefined && header.physicalLength > physicalLength)) {
|
|
768
|
-
throw new Error(`Run-log step ${seq} has an invalid physical commit length`);
|
|
769
|
-
}
|
|
770
|
-
previousPhysicalLength = header.physicalLength;
|
|
771
|
-
}
|
|
772
|
-
const records = [];
|
|
773
|
-
for (let i = 0; i < header.recordCount; i++) {
|
|
774
|
-
const record = await read(bee, recordKey(expectedLength + i));
|
|
775
|
-
if (!record) {
|
|
776
|
-
throw new Error(`Run-log step ${seq} is incomplete`);
|
|
777
|
-
}
|
|
778
|
-
records.push(record);
|
|
779
|
-
}
|
|
780
|
-
boot = applyEngineStep(boot, { seq, expectedLength, records });
|
|
781
|
-
expectedLength = header.nextLength;
|
|
782
|
-
if (boot.length !== expectedLength) {
|
|
783
|
-
throw new Error(`Run-log step ${seq} has a bad resulting length`);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
if (expectedLength !== cursor.length || boot.nextSeq !== cursor.nextSeq) {
|
|
787
|
-
throw new Error('Run-log cursor does not match its complete step history');
|
|
788
|
-
}
|
|
789
|
-
validateEngineBoot(boot);
|
|
790
|
-
if (boot.metadata && boot.metadata.runId !== cursor.runId) {
|
|
791
|
-
throw new Error('Run-log metadata belongs to another run');
|
|
792
|
-
}
|
|
793
|
-
return boot;
|
|
794
|
-
}
|
|
795
|
-
async function recoverLastStepPhysicalLength(bee, cursor, { physicalLength, read = getJson }) {
|
|
796
|
-
if (cursor.nextSeq === 0)
|
|
797
|
-
return undefined;
|
|
798
|
-
if (cursor.commitKind === 'step')
|
|
799
|
-
return physicalLength;
|
|
800
|
-
const latest = await read(bee, stepKey(cursor.nextSeq - 1));
|
|
801
|
-
if (latest?.physicalLength !== undefined &&
|
|
802
|
-
Number.isSafeInteger(latest.physicalLength) &&
|
|
803
|
-
latest.physicalLength > 0 &&
|
|
804
|
-
latest.physicalLength <= physicalLength) {
|
|
805
|
-
return latest.physicalLength;
|
|
806
|
-
}
|
|
807
|
-
throw new Error(`Run-log latest step ${cursor.nextSeq - 1} has no physical commit boundary`);
|
|
808
|
-
}
|
|
809
|
-
function validateCursor(cursor, meshId, runId) {
|
|
810
|
-
if (!cursor ||
|
|
811
|
-
cursor.version !== 1 ||
|
|
812
|
-
cursor.meshId !== meshId ||
|
|
813
|
-
cursor.runId !== runId ||
|
|
814
|
-
typeof cursor.generation !== 'string' ||
|
|
815
|
-
!cursor.generation ||
|
|
816
|
-
typeof cursor.active !== 'boolean' ||
|
|
817
|
-
!['init', 'lease', 'step'].includes(cursor.commitKind) ||
|
|
818
|
-
!Number.isSafeInteger(cursor.length) ||
|
|
819
|
-
cursor.length < 0 ||
|
|
820
|
-
!Number.isSafeInteger(cursor.nextSeq) ||
|
|
821
|
-
cursor.nextSeq < 0 ||
|
|
822
|
-
cursor.nextSeq > cursor.length ||
|
|
823
|
-
(cursor.commitKind === 'init' && (cursor.length !== 0 || cursor.nextSeq !== 0)) ||
|
|
824
|
-
(cursor.commitKind === 'step' && (cursor.length === 0 || cursor.nextSeq === 0)) ||
|
|
825
|
-
!Number.isSafeInteger(cursor.createdAt) ||
|
|
826
|
-
!Number.isSafeInteger(cursor.updatedAt)) {
|
|
827
|
-
throw new Error('Run-log cursor is malformed or belongs to a different scope');
|
|
828
|
-
}
|
|
829
|
-
return cursor;
|
|
830
|
-
}
|
|
831
|
-
function validateScope(meshId, runId) {
|
|
832
|
-
if (!meshId || !runId || meshId.includes('\0') || runId.includes('\0')) {
|
|
833
|
-
throw new TypeError('Host run-log meshId and runId must be nonempty and contain no NUL');
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
function scopeId(meshId, runId) {
|
|
837
|
-
validateScope(meshId, runId);
|
|
838
|
-
return b4a.toHex(createHmac('sha256', b4a.from('qvac-host-run-log-scope-v1'))
|
|
839
|
-
.update(`${meshId}\0${runId}`)
|
|
840
|
-
.digest());
|
|
841
|
-
}
|
|
842
|
-
function recordKey(index) {
|
|
843
|
-
return b4a.from(`${RECORD_PREFIX}${String(index).padStart(16, '0')}`);
|
|
844
|
-
}
|
|
845
|
-
function stepKey(seq) {
|
|
846
|
-
return b4a.from(`${STEP_PREFIX}${String(seq).padStart(16, '0')}`);
|
|
847
|
-
}
|
|
848
|
-
function jsonBytes(value) {
|
|
849
|
-
return b4a.from(JSON.stringify(value));
|
|
850
|
-
}
|
|
851
|
-
function isBee(value) {
|
|
852
|
-
return isRecord(value);
|
|
853
|
-
}
|
|
854
|
-
function openBee(store, options) {
|
|
855
|
-
const bee = new Hyperbee(store, options);
|
|
856
|
-
if (!isBee(bee)) {
|
|
857
|
-
throw new TypeError('Hyperbee did not open a bee');
|
|
858
|
-
}
|
|
859
|
-
return bee;
|
|
860
|
-
}
|
|
861
|
-
function canOpenCores(store) {
|
|
862
|
-
return isRecord(store) && typeof store.get === 'function';
|
|
863
|
-
}
|
|
864
|
-
function getCore(store, options) {
|
|
865
|
-
if (!canOpenCores(store)) {
|
|
866
|
-
throw new TypeError('Corestore cannot open cores by name or key');
|
|
867
|
-
}
|
|
868
|
-
return store.get(options);
|
|
869
|
-
}
|
|
870
|
-
function hasOwnerFields(store) {
|
|
871
|
-
return isRecord(store) && 'root' in store && store.ns instanceof Uint8Array;
|
|
872
|
-
}
|
|
873
|
-
function ownerIdentity(store) {
|
|
874
|
-
if (!hasOwnerFields(store)) {
|
|
875
|
-
throw new TypeError('Corestore does not expose its root and namespace');
|
|
876
|
-
}
|
|
877
|
-
return {
|
|
878
|
-
root: store.root ?? store,
|
|
879
|
-
namespace: b4a.toHex(store.ns)
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
function canSession(store) {
|
|
883
|
-
return isRecord(store) && typeof store.session === 'function';
|
|
884
|
-
}
|
|
885
|
-
function storeSession(store) {
|
|
886
|
-
if (!canSession(store)) {
|
|
887
|
-
throw new TypeError('Corestore cannot open sessions');
|
|
888
|
-
}
|
|
889
|
-
return store.session();
|
|
890
|
-
}
|
|
891
|
-
async function getJson(bee, key, options) {
|
|
892
|
-
const row = await bee.get(key, options);
|
|
893
|
-
if (!row) {
|
|
894
|
-
return null;
|
|
895
|
-
}
|
|
896
|
-
return JSON.parse(b4a.toString(row.value));
|
|
897
|
-
}
|
|
898
|
-
function readSnapshotJson(bee, key, { deadline, timeoutMs }) {
|
|
899
|
-
const timeout = remainingReadMs(deadline, timeoutMs);
|
|
900
|
-
return withReadDeadline(() => getJson(bee, key, { wait: true, timeout }), deadline, timeoutMs);
|
|
901
|
-
}
|
|
902
|
-
function remainingReadMs(deadline, timeoutMs) {
|
|
903
|
-
const remaining = deadline - Date.now();
|
|
904
|
-
if (remaining <= 0) {
|
|
905
|
-
throw snapshotTimeoutError(timeoutMs);
|
|
906
|
-
}
|
|
907
|
-
return Math.max(1, Math.ceil(remaining));
|
|
908
|
-
}
|
|
909
|
-
async function withReadDeadline(operation, deadline, timeoutMs) {
|
|
910
|
-
const remaining = remainingReadMs(deadline, timeoutMs);
|
|
911
|
-
let timer;
|
|
912
|
-
let timedOut = false;
|
|
913
|
-
const timeout = new Promise((_, reject) => {
|
|
914
|
-
timer = setTimeout(() => {
|
|
915
|
-
timedOut = true;
|
|
916
|
-
reject(snapshotTimeoutError(timeoutMs));
|
|
917
|
-
}, remaining);
|
|
918
|
-
});
|
|
919
|
-
try {
|
|
920
|
-
return await Promise.race([operation(), timeout]);
|
|
921
|
-
}
|
|
922
|
-
catch (error) {
|
|
923
|
-
if (timedOut || Date.now() >= deadline || hasCoreTimeoutCode(error)) {
|
|
924
|
-
throw snapshotTimeoutError(timeoutMs, error);
|
|
925
|
-
}
|
|
926
|
-
throw error;
|
|
927
|
-
}
|
|
928
|
-
finally {
|
|
929
|
-
if (timer !== undefined) {
|
|
930
|
-
clearTimeout(timer);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
function snapshotTimeoutError(timeoutMs, cause) {
|
|
935
|
-
const message = `Run-log snapshot read timed out after ${timeoutMs}ms`;
|
|
936
|
-
return new Error(message, cause === undefined ? undefined : { cause });
|
|
937
|
-
}
|
|
938
|
-
function hasCoreTimeoutCode(error) {
|
|
939
|
-
return !!error && typeof error === 'object' && 'code' in error && error.code === 'ERR_TIMEOUT';
|
|
940
|
-
}
|
|
941
|
-
function deriveKey(secret, label) {
|
|
942
|
-
return createHmac('sha256', secret).update(label).digest();
|
|
943
|
-
}
|
|
944
|
-
function sealJson(value, key) {
|
|
945
|
-
const nonce = cryptoBytes(12);
|
|
946
|
-
const cipher = createCipheriv('aes-256-gcm', key, nonce);
|
|
947
|
-
const plaintext = jsonBytes(value);
|
|
948
|
-
const ciphertext = b4a.concat([cipher.update(plaintext), cipher.final()]);
|
|
949
|
-
const envelope = {
|
|
950
|
-
version: INDEX_VALUE_VERSION,
|
|
951
|
-
nonce: b4a.toHex(nonce),
|
|
952
|
-
tag: b4a.toHex(cipher.getAuthTag()),
|
|
953
|
-
ciphertext: b4a.toHex(ciphertext)
|
|
954
|
-
};
|
|
955
|
-
return jsonBytes(envelope);
|
|
956
|
-
}
|
|
957
|
-
function openJson(value, key) {
|
|
958
|
-
const envelope = JSON.parse(b4a.toString(value));
|
|
959
|
-
if (envelope.version !== INDEX_VALUE_VERSION) {
|
|
960
|
-
throw new Error('Unsupported run-log index value version');
|
|
961
|
-
}
|
|
962
|
-
const decipher = createDecipheriv('aes-256-gcm', key, b4a.from(envelope.nonce, 'hex'));
|
|
963
|
-
decipher.setAuthTag(b4a.from(envelope.tag, 'hex'));
|
|
964
|
-
const plaintext = b4a.concat([
|
|
965
|
-
decipher.update(b4a.from(envelope.ciphertext, 'hex')),
|
|
966
|
-
decipher.final()
|
|
967
|
-
]);
|
|
968
|
-
return JSON.parse(b4a.toString(plaintext));
|
|
969
|
-
}
|
|
970
|
-
function cryptoBytes(length) {
|
|
971
|
-
return randomBytes(length);
|
|
972
|
-
}
|
|
973
|
-
function clone(value) {
|
|
974
|
-
return JSON.parse(JSON.stringify(value));
|
|
975
|
-
}
|
|
976
|
-
function noop() { }
|