@qvac/core 0.0.0 → 0.1.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.md +198 -0
- package/NOTICE.md +13 -0
- package/README.md +694 -0
- package/SECURITY.md +6 -0
- package/dist/assistant.bundle +47256 -0
- package/dist/assistant.cjs +18 -0
- package/dist/assistant.d.ts +8 -0
- package/dist/prebuilds-manifest.json +380 -0
- package/dist-lib/client.d.ts +2 -0
- package/dist-lib/client.js +1 -0
- package/dist-lib/index.d.ts +13 -0
- package/dist-lib/index.js +10 -0
- package/dist-lib/lib/agent-icons.d.ts +3 -0
- package/dist-lib/lib/agent-icons.js +1 -0
- package/dist-lib/lib/api/agents.d.ts +5 -0
- package/dist-lib/lib/api/agents.js +38 -0
- package/dist-lib/lib/api/app-config.d.ts +5 -0
- package/dist-lib/lib/api/app-config.js +108 -0
- package/dist-lib/lib/api/approval-rules.d.ts +3 -0
- package/dist-lib/lib/api/approval-rules.js +9 -0
- package/dist-lib/lib/api/attachments.d.ts +8 -0
- package/dist-lib/lib/api/attachments.js +15 -0
- package/dist-lib/lib/api/chat-groups.d.ts +5 -0
- package/dist-lib/lib/api/chat-groups.js +12 -0
- package/dist-lib/lib/api/chat.d.ts +5 -0
- package/dist-lib/lib/api/chat.js +38 -0
- package/dist-lib/lib/api/chunks.d.ts +5 -0
- package/dist-lib/lib/api/chunks.js +61 -0
- package/dist-lib/lib/api/config.d.ts +5 -0
- package/dist-lib/lib/api/config.js +15 -0
- package/dist-lib/lib/api/current-mesh.d.ts +5 -0
- package/dist-lib/lib/api/current-mesh.js +12 -0
- package/dist-lib/lib/api/custom-models.d.ts +5 -0
- package/dist-lib/lib/api/custom-models.js +45 -0
- package/dist-lib/lib/api/devices.d.ts +8 -0
- package/dist-lib/lib/api/devices.js +125 -0
- package/dist-lib/lib/api/diagnostics.d.ts +7 -0
- package/dist-lib/lib/api/diagnostics.js +7 -0
- package/dist-lib/lib/api/effective-ctx-size.d.ts +2 -0
- package/dist-lib/lib/api/effective-ctx-size.js +10 -0
- package/dist-lib/lib/api/execution.d.ts +3 -0
- package/dist-lib/lib/api/execution.js +45 -0
- package/dist-lib/lib/api/files.d.ts +3 -0
- package/dist-lib/lib/api/files.js +48 -0
- package/dist-lib/lib/api/index.d.ts +62 -0
- package/dist-lib/lib/api/index.js +172 -0
- package/dist-lib/lib/api/instrument.d.ts +2 -0
- package/dist-lib/lib/api/instrument.js +86 -0
- package/dist-lib/lib/api/knowledge.d.ts +8 -0
- package/dist-lib/lib/api/knowledge.js +26 -0
- package/dist-lib/lib/api/logs.d.ts +14 -0
- package/dist-lib/lib/api/logs.js +116 -0
- package/dist-lib/lib/api/mesh.d.ts +13 -0
- package/dist-lib/lib/api/mesh.js +25 -0
- package/dist-lib/lib/api/model-download.d.ts +5 -0
- package/dist-lib/lib/api/model-download.js +47 -0
- package/dist-lib/lib/api/network.d.ts +8 -0
- package/dist-lib/lib/api/network.js +6 -0
- package/dist-lib/lib/api/notifications.d.ts +21 -0
- package/dist-lib/lib/api/notifications.js +108 -0
- package/dist-lib/lib/api/rag.d.ts +7 -0
- package/dist-lib/lib/api/rag.js +216 -0
- package/dist-lib/lib/api/sync.d.ts +3 -0
- package/dist-lib/lib/api/sync.js +6 -0
- package/dist-lib/lib/api/tool-activity.d.ts +5 -0
- package/dist-lib/lib/api/tool-activity.js +53 -0
- package/dist-lib/lib/api/tool-configs.d.ts +6 -0
- package/dist-lib/lib/api/tool-configs.js +27 -0
- package/dist-lib/lib/api/watchable.d.ts +12 -0
- package/dist-lib/lib/api/watchable.js +121 -0
- package/dist-lib/lib/assistant-client.d.ts +21 -0
- package/dist-lib/lib/assistant-client.js +52 -0
- package/dist-lib/lib/assistant-tree.d.ts +50 -0
- package/dist-lib/lib/assistant-tree.js +184 -0
- package/dist-lib/lib/assistant.d.ts +425 -0
- package/dist-lib/lib/assistant.js +2706 -0
- package/dist-lib/lib/audio-format.d.ts +4 -0
- package/dist-lib/lib/audio-format.js +4 -0
- package/dist-lib/lib/chat-title.d.ts +5 -0
- package/dist-lib/lib/chat-title.js +58 -0
- package/dist-lib/lib/client.d.ts +25 -0
- package/dist-lib/lib/client.js +53 -0
- package/dist-lib/lib/collabora/convert.d.ts +9 -0
- package/dist-lib/lib/collabora/convert.js +62 -0
- package/dist-lib/lib/collabora/entry.d.ts +1 -0
- package/dist-lib/lib/collabora/entry.js +44 -0
- package/dist-lib/lib/collabora/protocol.d.ts +15 -0
- package/dist-lib/lib/collabora/protocol.js +24 -0
- package/dist-lib/lib/collabora/worker.d.ts +5 -0
- package/dist-lib/lib/collabora/worker.js +111 -0
- package/dist-lib/lib/compaction.d.ts +30 -0
- package/dist-lib/lib/compaction.js +95 -0
- package/dist-lib/lib/constants.d.ts +4 -0
- package/dist-lib/lib/constants.js +4 -0
- package/dist-lib/lib/core/agent.d.ts +15 -0
- package/dist-lib/lib/core/agent.js +149 -0
- package/dist-lib/lib/core/app-build.d.ts +7 -0
- package/dist-lib/lib/core/app-build.js +1 -0
- package/dist-lib/lib/core/approval-rules.d.ts +15 -0
- package/dist-lib/lib/core/approval-rules.js +41 -0
- package/dist-lib/lib/core/async-iterable.d.ts +13 -0
- package/dist-lib/lib/core/async-iterable.js +65 -0
- package/dist-lib/lib/core/attachment-link.d.ts +7 -0
- package/dist-lib/lib/core/attachment-link.js +6 -0
- package/dist-lib/lib/core/audio-attachment.d.ts +1 -0
- package/dist-lib/lib/core/audio-attachment.js +4 -0
- package/dist-lib/lib/core/blind-peers.d.ts +6 -0
- package/dist-lib/lib/core/blind-peers.js +13 -0
- package/dist-lib/lib/core/chat-activity.d.ts +7 -0
- package/dist-lib/lib/core/chat-activity.js +244 -0
- package/dist-lib/lib/core/chat-group.d.ts +14 -0
- package/dist-lib/lib/core/chat-group.js +79 -0
- package/dist-lib/lib/core/chat-search.d.ts +17 -0
- package/dist-lib/lib/core/chat-search.js +199 -0
- package/dist-lib/lib/core/chat.d.ts +37 -0
- package/dist-lib/lib/core/chat.js +196 -0
- package/dist-lib/lib/core/chunk.d.ts +61 -0
- package/dist-lib/lib/core/chunk.js +212 -0
- package/dist-lib/lib/core/contract/activity.d.ts +11 -0
- package/dist-lib/lib/core/contract/activity.js +45 -0
- package/dist-lib/lib/core/contract/agents.d.ts +2 -0
- package/dist-lib/lib/core/contract/agents.js +29 -0
- package/dist-lib/lib/core/contract/approval-rules.d.ts +2 -0
- package/dist-lib/lib/core/contract/approval-rules.js +14 -0
- package/dist-lib/lib/core/contract/attestations.d.ts +2 -0
- package/dist-lib/lib/core/contract/attestations.js +14 -0
- package/dist-lib/lib/core/contract/chat-group.d.ts +2 -0
- package/dist-lib/lib/core/contract/chat-group.js +20 -0
- package/dist-lib/lib/core/contract/chat.d.ts +2 -0
- package/dist-lib/lib/core/contract/chat.js +18 -0
- package/dist-lib/lib/core/contract/chunks.d.ts +2 -0
- package/dist-lib/lib/core/contract/chunks.js +156 -0
- package/dist-lib/lib/core/contract/devices.d.ts +2 -0
- package/dist-lib/lib/core/contract/devices.js +110 -0
- package/dist-lib/lib/core/contract/index.d.ts +2 -0
- package/dist-lib/lib/core/contract/index.js +30 -0
- package/dist-lib/lib/core/contract/indexing.d.ts +4 -0
- package/dist-lib/lib/core/contract/indexing.js +82 -0
- package/dist-lib/lib/core/contract/knowledge.d.ts +2 -0
- package/dist-lib/lib/core/contract/knowledge.js +55 -0
- package/dist-lib/lib/core/contract/members.d.ts +2 -0
- package/dist-lib/lib/core/contract/members.js +96 -0
- package/dist-lib/lib/core/contract/seed-defaults.d.ts +2 -0
- package/dist-lib/lib/core/contract/seed-defaults.js +29 -0
- package/dist-lib/lib/core/contract/tool-activity.d.ts +2 -0
- package/dist-lib/lib/core/contract/tool-activity.js +25 -0
- package/dist-lib/lib/core/contract/tool-configs.d.ts +2 -0
- package/dist-lib/lib/core/contract/tool-configs.js +50 -0
- package/dist-lib/lib/core/contract/types.d.ts +11 -0
- package/dist-lib/lib/core/contract/types.js +1 -0
- package/dist-lib/lib/core/contract/writers.d.ts +2 -0
- package/dist-lib/lib/core/contract/writers.js +112 -0
- package/dist-lib/lib/core/cpu-info-node.d.ts +3 -0
- package/dist-lib/lib/core/cpu-info-node.js +2 -0
- package/dist-lib/lib/core/departures.d.ts +41 -0
- package/dist-lib/lib/core/departures.js +145 -0
- package/dist-lib/lib/core/device-attestation.d.ts +6 -0
- package/dist-lib/lib/core/device-attestation.js +12 -0
- package/dist-lib/lib/core/devices.d.ts +14 -0
- package/dist-lib/lib/core/devices.js +11 -0
- package/dist-lib/lib/core/document-attachment.d.ts +22 -0
- package/dist-lib/lib/core/document-attachment.js +35 -0
- package/dist-lib/lib/core/files/attachments.d.ts +8 -0
- package/dist-lib/lib/core/files/attachments.js +50 -0
- package/dist-lib/lib/core/files/index.d.ts +133 -0
- package/dist-lib/lib/core/files/index.js +585 -0
- package/dist-lib/lib/core/files/knowledge.d.ts +9 -0
- package/dist-lib/lib/core/files/knowledge.js +31 -0
- package/dist-lib/lib/core/files/preview/image.d.ts +4 -0
- package/dist-lib/lib/core/files/preview/image.js +42 -0
- package/dist-lib/lib/core/files/preview/index.d.ts +33 -0
- package/dist-lib/lib/core/files/preview/index.js +161 -0
- package/dist-lib/lib/core/files/processing/claims.d.ts +26 -0
- package/dist-lib/lib/core/files/processing/claims.js +89 -0
- package/dist-lib/lib/core/files/processing/document.d.ts +100 -0
- package/dist-lib/lib/core/files/processing/document.js +101 -0
- package/dist-lib/lib/core/files/processing/index.d.ts +75 -0
- package/dist-lib/lib/core/files/processing/index.js +295 -0
- package/dist-lib/lib/core/files/processing/ownership.d.ts +11 -0
- package/dist-lib/lib/core/files/processing/ownership.js +41 -0
- package/dist-lib/lib/core/files/processing/protocol.d.ts +29 -0
- package/dist-lib/lib/core/files/processing/protocol.js +70 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +10 -0
- package/dist-lib/lib/core/files/processing/settle.js +75 -0
- package/dist-lib/lib/core/files/processing/source.d.ts +36 -0
- package/dist-lib/lib/core/files/processing/source.js +96 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +64 -0
- package/dist-lib/lib/core/files/processing/state.js +118 -0
- package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/artifact/codec.js +172 -0
- package/dist-lib/lib/core/files/rag/artifact/id.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/artifact/id.js +39 -0
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +24 -0
- package/dist-lib/lib/core/files/rag/artifact/types.js +41 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +25 -0
- package/dist-lib/lib/core/files/rag/build.js +60 -0
- package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +12 -0
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +117 -0
- package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +30 -0
- package/dist-lib/lib/core/files/rag/chunk/metadata.js +89 -0
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +7 -0
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +18 -0
- package/dist-lib/lib/core/files/rag/document-types.d.ts +11 -0
- package/dist-lib/lib/core/files/rag/document-types.js +94 -0
- package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/csv-text.js +117 -0
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +22 -0
- package/dist-lib/lib/core/files/rag/extract/document-types.js +152 -0
- package/dist-lib/lib/core/files/rag/extract/extract.d.ts +17 -0
- package/dist-lib/lib/core/files/rag/extract/extract.js +81 -0
- package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/html-table-text.js +125 -0
- package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/html-text.js +132 -0
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +8 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +17 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +141 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +12 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +43 -0
- package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/rtf-text.js +15 -0
- package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +91 -0
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +36 -0
- package/dist-lib/lib/core/files/rag/extract/types.js +12 -0
- package/dist-lib/lib/core/files/rag/extract/utf.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/extract/utf.js +18 -0
- package/dist-lib/lib/core/files/rag/index.d.ts +54 -0
- package/dist-lib/lib/core/files/rag/index.js +79 -0
- package/dist-lib/lib/core/files/rag/limits.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/limits.js +2 -0
- package/dist-lib/lib/core/files/rag/load.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/load.js +250 -0
- package/dist-lib/lib/core/files/rag/models.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/models.js +1 -0
- package/dist-lib/lib/core/files/rag/policy.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/policy.js +23 -0
- package/dist-lib/lib/core/files/rag/produce.d.ts +21 -0
- package/dist-lib/lib/core/files/rag/produce.js +214 -0
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +16 -0
- package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +4 -0
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +48 -0
- package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +37 -0
- package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +5 -0
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +21 -0
- package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/retrieval/format.js +21 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +22 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +137 -0
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +53 -0
- package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +16 -0
- package/dist-lib/lib/core/files/rag/retrieval/notices.js +27 -0
- package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +82 -0
- package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/retrieval/search.js +46 -0
- package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +63 -0
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +79 -0
- package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +13 -0
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +20 -0
- package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +13 -0
- package/dist-lib/lib/core/files/rag/retrieval/target.js +89 -0
- package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +70 -0
- package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/retrieval/types.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +41 -0
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +96 -0
- package/dist-lib/lib/core/files/rag/vector/memory.d.ts +15 -0
- package/dist-lib/lib/core/files/rag/vector/memory.js +135 -0
- package/dist-lib/lib/core/files/rag/vector/types.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/vector/types.js +1 -0
- package/dist-lib/lib/core/files/records/chunks.d.ts +3 -0
- package/dist-lib/lib/core/files/records/chunks.js +12 -0
- package/dist-lib/lib/core/files/records/index.d.ts +10 -0
- package/dist-lib/lib/core/files/records/index.js +8 -0
- package/dist-lib/lib/core/files/records/knowledge.d.ts +22 -0
- package/dist-lib/lib/core/files/records/knowledge.js +105 -0
- package/dist-lib/lib/core/files/records/linkage.d.ts +11 -0
- package/dist-lib/lib/core/files/records/linkage.js +27 -0
- package/dist-lib/lib/core/files/records/output.d.ts +8 -0
- package/dist-lib/lib/core/files/records/output.js +38 -0
- package/dist-lib/lib/core/files/records/reclaim.d.ts +5 -0
- package/dist-lib/lib/core/files/records/reclaim.js +73 -0
- package/dist-lib/lib/core/files/records/routing.d.ts +23 -0
- package/dist-lib/lib/core/files/records/routing.js +62 -0
- package/dist-lib/lib/core/files/records/source.d.ts +16 -0
- package/dist-lib/lib/core/files/records/source.js +70 -0
- package/dist-lib/lib/core/files/records/sweep.d.ts +2 -0
- package/dist-lib/lib/core/files/records/sweep.js +30 -0
- package/dist-lib/lib/core/files/store/blob.d.ts +29 -0
- package/dist-lib/lib/core/files/store/blob.js +98 -0
- package/dist-lib/lib/core/files/store/index.d.ts +36 -0
- package/dist-lib/lib/core/files/store/index.js +89 -0
- package/dist-lib/lib/core/files/store/inline.d.ts +8 -0
- package/dist-lib/lib/core/files/store/inline.js +38 -0
- package/dist-lib/lib/core/files/store/reference.d.ts +27 -0
- package/dist-lib/lib/core/files/store/reference.js +168 -0
- package/dist-lib/lib/core/files/store/server.d.ts +27 -0
- package/dist-lib/lib/core/files/store/server.js +114 -0
- package/dist-lib/lib/core/files/store/sweep.d.ts +2 -0
- package/dist-lib/lib/core/files/store/sweep.js +45 -0
- package/dist-lib/lib/core/files/upload-input.d.ts +27 -0
- package/dist-lib/lib/core/files/upload-input.js +52 -0
- package/dist-lib/lib/core/files/upload.d.ts +32 -0
- package/dist-lib/lib/core/files/upload.js +201 -0
- package/dist-lib/lib/core/fs-drives.d.ts +18 -0
- package/dist-lib/lib/core/fs-drives.js +58 -0
- package/dist-lib/lib/core/gpu-info-node.d.ts +3 -0
- package/dist-lib/lib/core/gpu-info-node.js +2 -0
- package/dist-lib/lib/core/handoff-channel.d.ts +46 -0
- package/dist-lib/lib/core/handoff-channel.js +102 -0
- package/dist-lib/lib/core/health-assistant.d.ts +7 -0
- package/dist-lib/lib/core/health-assistant.js +24 -0
- package/dist-lib/lib/core/helpers/index.d.ts +5 -0
- package/dist-lib/lib/core/helpers/index.js +74 -0
- package/dist-lib/lib/core/hosted-agents.d.ts +36 -0
- package/dist-lib/lib/core/hosted-agents.js +127 -0
- package/dist-lib/lib/core/id.d.ts +1 -0
- package/dist-lib/lib/core/id.js +5 -0
- package/dist-lib/lib/core/identity.d.ts +14 -0
- package/dist-lib/lib/core/identity.js +45 -0
- package/dist-lib/lib/core/image/cache-sweep.d.ts +12 -0
- package/dist-lib/lib/core/image/cache-sweep.js +67 -0
- package/dist-lib/lib/core/image/normalize.d.ts +3 -0
- package/dist-lib/lib/core/image/normalize.js +49 -0
- package/dist-lib/lib/core/image/sniff.d.ts +3 -0
- package/dist-lib/lib/core/image/sniff.js +149 -0
- package/dist-lib/lib/core/invite.d.ts +14 -0
- package/dist-lib/lib/core/invite.js +36 -0
- package/dist-lib/lib/core/local/index.d.ts +71 -0
- package/dist-lib/lib/core/local/index.js +391 -0
- package/dist-lib/lib/core/membership.d.ts +15 -0
- package/dist-lib/lib/core/membership.js +40 -0
- package/dist-lib/lib/core/mesh.d.ts +153 -0
- package/dist-lib/lib/core/mesh.js +509 -0
- package/dist-lib/lib/core/migrations/agent-catalog.d.ts +6 -0
- package/dist-lib/lib/core/migrations/agent-catalog.js +17 -0
- package/dist-lib/lib/core/migrations/index.d.ts +5 -0
- package/dist-lib/lib/core/migrations/index.js +7 -0
- package/dist-lib/lib/core/migrations/membership.d.ts +11 -0
- package/dist-lib/lib/core/migrations/membership.js +26 -0
- package/dist-lib/lib/core/min-version.d.ts +6 -0
- package/dist-lib/lib/core/min-version.js +31 -0
- package/dist-lib/lib/core/next-frame.d.ts +6 -0
- package/dist-lib/lib/core/next-frame.js +27 -0
- package/dist-lib/lib/core/notification.d.ts +6 -0
- package/dist-lib/lib/core/notification.js +162 -0
- package/dist-lib/lib/core/ota-config.d.ts +19 -0
- package/dist-lib/lib/core/ota-config.js +44 -0
- package/dist-lib/lib/core/prompt-history.d.ts +12 -0
- package/dist-lib/lib/core/prompt-history.js +40 -0
- package/dist-lib/lib/core/search-fold.d.ts +1 -0
- package/dist-lib/lib/core/search-fold.js +4 -0
- package/dist-lib/lib/core/secret-handoff.d.ts +17 -0
- package/dist-lib/lib/core/secret-handoff.js +29 -0
- package/dist-lib/lib/core/send.d.ts +18 -0
- package/dist-lib/lib/core/send.js +46 -0
- package/dist-lib/lib/core/skill-overlay-handoff.d.ts +25 -0
- package/dist-lib/lib/core/skill-overlay-handoff.js +50 -0
- package/dist-lib/lib/core/skill-overlay-receiver.d.ts +8 -0
- package/dist-lib/lib/core/skill-overlay-receiver.js +20 -0
- package/dist-lib/lib/core/skill-secrets.d.ts +25 -0
- package/dist-lib/lib/core/skill-secrets.js +79 -0
- package/dist-lib/lib/core/sync/chats.d.ts +3 -0
- package/dist-lib/lib/core/sync/chats.js +5 -0
- package/dist-lib/lib/core/sync/chunks.d.ts +9 -0
- package/dist-lib/lib/core/sync/chunks.js +16 -0
- package/dist-lib/lib/core/sync/devices.d.ts +4 -0
- package/dist-lib/lib/core/sync/devices.js +12 -0
- package/dist-lib/lib/core/sync/files.d.ts +16 -0
- package/dist-lib/lib/core/sync/files.js +109 -0
- package/dist-lib/lib/core/sync/index.d.ts +5 -0
- package/dist-lib/lib/core/sync/index.js +63 -0
- package/dist-lib/lib/core/sync-status.d.ts +17 -0
- package/dist-lib/lib/core/sync-status.js +129 -0
- package/dist-lib/lib/core/system-info.d.ts +24 -0
- package/dist-lib/lib/core/system-info.js +66 -0
- package/dist-lib/lib/core/tool-activity.d.ts +22 -0
- package/dist-lib/lib/core/tool-activity.js +39 -0
- package/dist-lib/lib/core/tool-configs.d.ts +13 -0
- package/dist-lib/lib/core/tool-configs.js +141 -0
- package/dist-lib/lib/core.d.ts +291 -0
- package/dist-lib/lib/core.js +2126 -0
- package/dist-lib/lib/credential-pusher.d.ts +67 -0
- package/dist-lib/lib/credential-pusher.js +290 -0
- package/dist-lib/lib/custom-model-pusher.d.ts +9 -0
- package/dist-lib/lib/custom-model-pusher.js +42 -0
- package/dist-lib/lib/custom-model-source.d.ts +15 -0
- package/dist-lib/lib/custom-model-source.js +46 -0
- package/dist-lib/lib/deadline.d.ts +9 -0
- package/dist-lib/lib/deadline.js +31 -0
- package/dist-lib/lib/diagnostics.d.ts +35 -0
- package/dist-lib/lib/diagnostics.js +14 -0
- package/dist-lib/lib/fetch-node.d.ts +1 -0
- package/dist-lib/lib/fetch-node.js +1 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +12 -0
- package/dist-lib/lib/fs-drive-bridge.js +186 -0
- package/dist-lib/lib/fs-grant-keys.d.ts +2 -0
- package/dist-lib/lib/fs-grant-keys.js +6 -0
- package/dist-lib/lib/fs-grants.d.ts +10 -0
- package/dist-lib/lib/fs-grants.js +44 -0
- package/dist-lib/lib/image-cache-dir.d.ts +1 -0
- package/dist-lib/lib/image-cache-dir.js +5 -0
- package/dist-lib/lib/integrations/index.d.ts +4 -0
- package/dist-lib/lib/integrations/index.js +3 -0
- package/dist-lib/lib/integrations/mcp-providers.d.ts +12 -0
- package/dist-lib/lib/integrations/mcp-providers.js +22 -0
- package/dist-lib/lib/integrations/oauth-providers.d.ts +14 -0
- package/dist-lib/lib/integrations/oauth-providers.js +116 -0
- package/dist-lib/lib/integrations/setup-routes.d.ts +12 -0
- package/dist-lib/lib/integrations/setup-routes.js +114 -0
- package/dist-lib/lib/knowledge-search.d.ts +7 -0
- package/dist-lib/lib/knowledge-search.js +53 -0
- package/dist-lib/lib/kv-cache-reclaim.d.ts +5 -0
- package/dist-lib/lib/kv-cache-reclaim.js +29 -0
- package/dist-lib/lib/kv-cache.d.ts +18 -0
- package/dist-lib/lib/kv-cache.js +33 -0
- package/dist-lib/lib/legacy-core-domain.d.ts +258 -0
- package/dist-lib/lib/legacy-core-domain.js +1 -0
- package/dist-lib/lib/llm-model-names.d.ts +1 -0
- package/dist-lib/lib/llm-model-names.js +1 -0
- package/dist-lib/lib/log-buffer.d.ts +7 -0
- package/dist-lib/lib/log-buffer.js +16 -0
- package/dist-lib/lib/log-levels.d.ts +7 -0
- package/dist-lib/lib/log-levels.js +1 -0
- package/dist-lib/lib/log.d.ts +60 -0
- package/dist-lib/lib/log.js +149 -0
- package/dist-lib/lib/logger-type.d.ts +13 -0
- package/dist-lib/lib/logger-type.js +1 -0
- package/dist-lib/lib/logger.d.ts +5 -0
- package/dist-lib/lib/logger.js +18 -0
- package/dist-lib/lib/model-catalog-revision.d.ts +9 -0
- package/dist-lib/lib/model-catalog-revision.js +65 -0
- package/dist-lib/lib/model-clamp.d.ts +6 -0
- package/dist-lib/lib/model-clamp.js +20 -0
- package/dist-lib/lib/model-context.d.ts +13 -0
- package/dist-lib/lib/model-context.js +71 -0
- package/dist-lib/lib/model-download-status.d.ts +29 -0
- package/dist-lib/lib/model-download-status.js +56 -0
- package/dist-lib/lib/model-download.d.ts +191 -0
- package/dist-lib/lib/model-download.js +787 -0
- package/dist-lib/lib/oauth/asana.d.ts +35 -0
- package/dist-lib/lib/oauth/asana.js +71 -0
- package/dist-lib/lib/oauth/browser-connect.d.ts +22 -0
- package/dist-lib/lib/oauth/browser-connect.js +83 -0
- package/dist-lib/lib/oauth/client.d.ts +9 -0
- package/dist-lib/lib/oauth/client.js +9 -0
- package/dist-lib/lib/oauth/common.d.ts +38 -0
- package/dist-lib/lib/oauth/common.js +36 -0
- package/dist-lib/lib/oauth/crypto.d.ts +3 -0
- package/dist-lib/lib/oauth/crypto.js +25 -0
- package/dist-lib/lib/oauth/fetch-platform.d.ts +1 -0
- package/dist-lib/lib/oauth/fetch-platform.js +1 -0
- package/dist-lib/lib/oauth/flow-core.d.ts +6 -0
- package/dist-lib/lib/oauth/flow-core.js +37 -0
- package/dist-lib/lib/oauth/flow.d.ts +3 -0
- package/dist-lib/lib/oauth/flow.js +24 -0
- package/dist-lib/lib/oauth/google.d.ts +37 -0
- package/dist-lib/lib/oauth/google.js +77 -0
- package/dist-lib/lib/oauth/host.d.ts +5 -0
- package/dist-lib/lib/oauth/host.js +3 -0
- package/dist-lib/lib/oauth/keys.d.ts +25 -0
- package/dist-lib/lib/oauth/keys.js +93 -0
- package/dist-lib/lib/oauth/loopback.d.ts +3 -0
- package/dist-lib/lib/oauth/loopback.js +119 -0
- package/dist-lib/lib/oauth/loopback.stub.d.ts +3 -0
- package/dist-lib/lib/oauth/loopback.stub.js +6 -0
- package/dist-lib/lib/oauth/notion.d.ts +34 -0
- package/dist-lib/lib/oauth/notion.js +82 -0
- package/dist-lib/lib/oauth/pkce-runtime.d.ts +3 -0
- package/dist-lib/lib/oauth/pkce-runtime.js +5 -0
- package/dist-lib/lib/oauth/pkce.d.ts +8 -0
- package/dist-lib/lib/oauth/pkce.js +6 -0
- package/dist-lib/lib/oauth/providers.d.ts +5 -0
- package/dist-lib/lib/oauth/providers.js +73 -0
- package/dist-lib/lib/oauth/redirect-types.d.ts +19 -0
- package/dist-lib/lib/oauth/redirect-types.js +1 -0
- package/dist-lib/lib/oauth/register.d.ts +3 -0
- package/dist-lib/lib/oauth/register.js +34 -0
- package/dist-lib/lib/oauth/resolve.d.ts +17 -0
- package/dist-lib/lib/oauth/resolve.js +57 -0
- package/dist-lib/lib/oauth/spotify.d.ts +32 -0
- package/dist-lib/lib/oauth/spotify.js +73 -0
- package/dist-lib/lib/oauth/token-exchange-core.d.ts +6 -0
- package/dist-lib/lib/oauth/token-exchange-core.js +97 -0
- package/dist-lib/lib/oauth/token-exchange.d.ts +5 -0
- package/dist-lib/lib/oauth/token-exchange.js +9 -0
- package/dist-lib/lib/oauth/types.d.ts +54 -0
- package/dist-lib/lib/oauth/types.js +1 -0
- package/dist-lib/lib/oauth.client.d.ts +5 -0
- package/dist-lib/lib/oauth.client.js +2 -0
- package/dist-lib/lib/oauth.d.ts +14 -0
- package/dist-lib/lib/oauth.js +12 -0
- package/dist-lib/lib/obsidian-key.d.ts +1 -0
- package/dist-lib/lib/obsidian-key.js +1 -0
- package/dist-lib/lib/race-resource.d.ts +5 -0
- package/dist-lib/lib/race-resource.js +25 -0
- package/dist-lib/lib/reconnecting-watch.d.ts +2 -0
- package/dist-lib/lib/reconnecting-watch.js +78 -0
- package/dist-lib/lib/retry-budget.d.ts +14 -0
- package/dist-lib/lib/retry-budget.js +39 -0
- package/dist-lib/lib/run-notices.d.ts +23 -0
- package/dist-lib/lib/run-notices.js +33 -0
- package/dist-lib/lib/run-transcript.d.ts +35 -0
- package/dist-lib/lib/run-transcript.js +106 -0
- package/dist-lib/lib/skill-readiness.d.ts +2 -0
- package/dist-lib/lib/skill-readiness.js +21 -0
- package/dist-lib/lib/skill-types.d.ts +70 -0
- package/dist-lib/lib/skill-types.js +1 -0
- package/dist-lib/lib/spec-loader.d.ts +14 -0
- package/dist-lib/lib/spec-loader.js +9 -0
- package/dist-lib/lib/suspend-lifecycle.d.ts +17 -0
- package/dist-lib/lib/suspend-lifecycle.js +33 -0
- package/dist-lib/lib/task.d.ts +26 -0
- package/dist-lib/lib/task.js +69 -0
- package/dist-lib/lib/unref.d.ts +3 -0
- package/dist-lib/lib/unref.js +4 -0
- package/dist-lib/lib/wav-duration.d.ts +1 -0
- package/dist-lib/lib/wav-duration.js +53 -0
- package/dist-lib/lib/write-queue.d.ts +22 -0
- package/dist-lib/lib/write-queue.js +39 -0
- package/dist-lib/schema/build.d.ts +1 -0
- package/dist-lib/schema/build.js +120 -0
- package/dist-lib/schema/config.d.ts +4 -0
- package/dist-lib/schema/config.js +7 -0
- package/dist-lib/schema/content.d.ts +20 -0
- package/dist-lib/schema/content.js +122 -0
- package/dist-lib/schema/engine.d.ts +2 -0
- package/dist-lib/schema/engine.js +2013 -0
- package/dist-lib/schema/field-order.d.ts +1 -0
- package/dist-lib/schema/field-order.js +95 -0
- package/dist-lib/schema/local.d.ts +2 -0
- package/dist-lib/schema/local.js +133 -0
- package/dist-lib/schema/qvac.d.ts +22 -0
- package/dist-lib/schema/qvac.js +722 -0
- package/dist-lib/spec/bind.d.ts +2 -0
- package/dist-lib/spec/bind.js +520 -0
- package/dist-lib/spec/calls.d.ts +3 -0
- package/dist-lib/spec/calls.js +129 -0
- package/dist-lib/spec/capabilities.d.ts +263 -0
- package/dist-lib/spec/config/hyperconf/index.d.ts +15 -0
- package/dist-lib/spec/config/hyperconf/index.js +24 -0
- package/dist-lib/spec/config/hyperconf/package.json +3 -0
- package/dist-lib/spec/config/hyperschema/index.js +81 -0
- package/dist-lib/spec/config/hyperschema/schema.json +19 -0
- package/dist-lib/spec/hrpc/hrpc.json +1500 -0
- package/dist-lib/spec/hrpc/index.d.ts +3 -0
- package/dist-lib/spec/hrpc/index.js +1545 -0
- package/dist-lib/spec/hrpc/messages.d.ts +4 -0
- package/dist-lib/spec/hrpc/messages.js +8373 -0
- package/dist-lib/spec/hyperschema/index.d.ts +20 -0
- package/dist-lib/spec/hyperschema/index.js +8373 -0
- package/dist-lib/spec/hyperschema/schema.json +6202 -0
- package/dist-lib/spec/hyperschema/types.d.ts +1545 -0
- package/dist-lib/spec/index.d.ts +36 -0
- package/dist-lib/spec/index.js +6 -0
- package/dist-lib/spec/local/hyperdb/db.json +186 -0
- package/dist-lib/spec/local/hyperdb/index.d.ts +9 -0
- package/dist-lib/spec/local/hyperdb/index.js +855 -0
- package/dist-lib/spec/local/hyperdb/messages.js +2189 -0
- package/dist-lib/spec/local/hyperschema/index.js +1208 -0
- package/dist-lib/spec/local/hyperschema/schema.json +639 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +159 -0
- package/dist-lib/spec/mesh/hyperdb/db.json +702 -0
- package/dist-lib/spec/mesh/hyperdb/index.d.ts +9 -0
- package/dist-lib/spec/mesh/hyperdb/index.js +2260 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +7453 -0
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +174 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.d.ts +13 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +566 -0
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +5713 -0
- package/dist-lib/spec/mesh/hyperschema/index.d.ts +14 -0
- package/dist-lib/spec/mesh/hyperschema/index.js +5713 -0
- package/dist-lib/spec/mesh/hyperschema/schema.json +3142 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +754 -0
- package/ducks.png +0 -0
- package/package.json +332 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { attestDeviceProof } from "./identity.js";
|
|
2
|
+
export async function membershipView(mesh, deviceId) {
|
|
3
|
+
const snap = mesh.view.snapshot();
|
|
4
|
+
try {
|
|
5
|
+
let members = 0;
|
|
6
|
+
let own = null;
|
|
7
|
+
const unattested = [];
|
|
8
|
+
for await (const _member of snap.find('@qvac/members'))
|
|
9
|
+
members++;
|
|
10
|
+
for await (const device of snap.find('@qvac/devices')) {
|
|
11
|
+
if (device.id.equals(deviceId))
|
|
12
|
+
own = device;
|
|
13
|
+
else if (!device.revoked && !device.memberId)
|
|
14
|
+
unattested.push(device.id);
|
|
15
|
+
}
|
|
16
|
+
return { members, own, unattested };
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
await snap.close();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function attestUnattestedDevices(mesh, { deviceKeyPair, log }) {
|
|
23
|
+
const { own, unattested } = await membershipView(mesh, deviceKeyPair.publicKey);
|
|
24
|
+
if (!own?.memberId || !own.memberProof || unattested.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
const batch = mesh.batch();
|
|
28
|
+
for (const id of unattested) {
|
|
29
|
+
batch.dispatch('attest-member-device', {
|
|
30
|
+
deviceId: id,
|
|
31
|
+
memberId: own.memberId,
|
|
32
|
+
proof: await attestDeviceProof(id, deviceKeyPair, own.memberProof),
|
|
33
|
+
attestedAt: now
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
await batch.flush();
|
|
37
|
+
log?.info(['p2p', 'mesh'], 'every device we hold is attested to our member', {
|
|
38
|
+
attested: unattested.length
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import Autobee, { type AutobeeChanges, type AutobeeHost, type AutobeeNode, type AutobeeOplogRef } from 'autobee';
|
|
2
|
+
import Corestore from 'corestore';
|
|
3
|
+
import HyperDB from 'hyperdb';
|
|
4
|
+
import Hyperblobs from 'hyperblobs';
|
|
5
|
+
import type Wakeup from 'protomux-wakeup';
|
|
6
|
+
import ReadyResource from 'ready-resource';
|
|
7
|
+
import { Files } from './files/index.ts';
|
|
8
|
+
import type { Logger } from '../../index.ts';
|
|
9
|
+
import { Router } from '../../spec/mesh/hyperdispatch/index.js';
|
|
10
|
+
import type { QvacCapabilityProfile, QvacMember } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
11
|
+
import type { BlindPeeringOpts } from './blind-peers.ts';
|
|
12
|
+
import type { AttachmentUrl } from './attachment-link.ts';
|
|
13
|
+
import { type DeviceAttestation } from './device-attestation.ts';
|
|
14
|
+
import { type SyncActivity } from './sync-status.ts';
|
|
15
|
+
export interface MeshView {
|
|
16
|
+
readonly db: HyperDB;
|
|
17
|
+
}
|
|
18
|
+
export interface DeviceMetadata {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly capabilityProfile: QvacCapabilityProfile;
|
|
21
|
+
readonly recommendedModelName: string;
|
|
22
|
+
readonly platform?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface OrphanedBlobSweepStatus {
|
|
25
|
+
readonly state: 'pending' | 'running' | 'succeeded' | 'failed';
|
|
26
|
+
readonly error?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface MeshOptions {
|
|
29
|
+
seed?: Buffer;
|
|
30
|
+
key?: Buffer | null;
|
|
31
|
+
writerSeed?: string;
|
|
32
|
+
deviceId?: Buffer;
|
|
33
|
+
logger?: Logger | null;
|
|
34
|
+
blindPeerKeys?: ReadonlyArray<Buffer>;
|
|
35
|
+
blindPeeringOpts?: BlindPeeringOpts;
|
|
36
|
+
bootFrom?: AutobeeOplogRef | null;
|
|
37
|
+
wakeup?: Wakeup;
|
|
38
|
+
attachmentUrl?: AttachmentUrl | null;
|
|
39
|
+
}
|
|
40
|
+
export declare function isOurTrustedWriter(snap: HyperDB, writerKey: Buffer, ourMemberId: Buffer | null): Promise<boolean>;
|
|
41
|
+
export type BirthRow = {
|
|
42
|
+
readonly id: Buffer;
|
|
43
|
+
readonly joinedAt: number;
|
|
44
|
+
} & DeviceMetadata;
|
|
45
|
+
export interface BirthMember {
|
|
46
|
+
readonly member: QvacMember;
|
|
47
|
+
readonly proof: Buffer;
|
|
48
|
+
}
|
|
49
|
+
export interface MembershipStats {
|
|
50
|
+
readonly members: number;
|
|
51
|
+
readonly attested: number;
|
|
52
|
+
readonly unattested: number;
|
|
53
|
+
readonly revoked: number;
|
|
54
|
+
}
|
|
55
|
+
export declare function claimableDevice(row: BirthRow): {
|
|
56
|
+
id: Buffer<ArrayBufferLike>;
|
|
57
|
+
joinedAt: number;
|
|
58
|
+
name: string;
|
|
59
|
+
capabilityProfile: QvacCapabilityProfile;
|
|
60
|
+
recommendedModelName: string;
|
|
61
|
+
};
|
|
62
|
+
export declare class Mesh extends ReadyResource {
|
|
63
|
+
private _files;
|
|
64
|
+
get files(): Files;
|
|
65
|
+
private readonly _store;
|
|
66
|
+
private readonly _seed;
|
|
67
|
+
private readonly _key;
|
|
68
|
+
private readonly _writerSeed;
|
|
69
|
+
private readonly _log;
|
|
70
|
+
private readonly _blindPeerKeys;
|
|
71
|
+
private readonly _blindPeeringOpts;
|
|
72
|
+
private readonly _bootFrom;
|
|
73
|
+
private readonly _wakeup;
|
|
74
|
+
readonly attachmentUrl: AttachmentUrl | null;
|
|
75
|
+
private readonly _scope;
|
|
76
|
+
readonly router: Router;
|
|
77
|
+
private readonly _keyPair;
|
|
78
|
+
private readonly _deviceKeyPair;
|
|
79
|
+
private readonly _encryptionKey;
|
|
80
|
+
private _blindPeering;
|
|
81
|
+
private _orphanedBlobSweepStatus;
|
|
82
|
+
private _bootInterrupted;
|
|
83
|
+
private _localWriterUploadedLength;
|
|
84
|
+
private _ourMemberId;
|
|
85
|
+
private _membership;
|
|
86
|
+
private readonly _deviceId;
|
|
87
|
+
autobee: Autobee<MeshView>;
|
|
88
|
+
blobs: Hyperblobs;
|
|
89
|
+
readonly discoveryKey: Buffer;
|
|
90
|
+
syncActivity: SyncActivity;
|
|
91
|
+
get publicKey(): Buffer;
|
|
92
|
+
get devicePublicKey(): Buffer;
|
|
93
|
+
get key(): Buffer;
|
|
94
|
+
get encryptionKey(): Buffer;
|
|
95
|
+
get blindPeerKeys(): ReadonlyArray<Buffer>;
|
|
96
|
+
get orphanedBlobSweepStatus(): OrphanedBlobSweepStatus;
|
|
97
|
+
blindPeerStats(): Array<{
|
|
98
|
+
key: string;
|
|
99
|
+
connected: boolean;
|
|
100
|
+
connects: number;
|
|
101
|
+
uploaded: number;
|
|
102
|
+
}>;
|
|
103
|
+
get ourMemberId(): Buffer | null;
|
|
104
|
+
get membership(): MembershipStats;
|
|
105
|
+
refreshMembership(): Promise<void>;
|
|
106
|
+
refreshOurMember(): Promise<void>;
|
|
107
|
+
sign(message: Buffer): Buffer;
|
|
108
|
+
attestDevice(deviceId: Buffer): DeviceAttestation;
|
|
109
|
+
constructor(store: Corestore, opts?: MeshOptions);
|
|
110
|
+
_open(): Promise<void>;
|
|
111
|
+
startBlindPeering(dht: unknown): void;
|
|
112
|
+
openBlobs(coreKey: Buffer): Promise<Hyperblobs>;
|
|
113
|
+
interruptBoot(): void;
|
|
114
|
+
_close(): Promise<void>;
|
|
115
|
+
private _sweepOrphanedBlobs;
|
|
116
|
+
get view(): HyperDB;
|
|
117
|
+
get localWriterKey(): Buffer<ArrayBufferLike>;
|
|
118
|
+
get writable(): boolean;
|
|
119
|
+
get localLength(): number;
|
|
120
|
+
dispatch(name: string, payload: unknown, opts?: {
|
|
121
|
+
optimistic?: boolean;
|
|
122
|
+
}): Promise<void>;
|
|
123
|
+
batch(): MeshBatch;
|
|
124
|
+
appendBirthOp(deviceId: Buffer, device?: DeviceMetadata, member?: BirthMember): Promise<void>;
|
|
125
|
+
get interrupted(): unknown;
|
|
126
|
+
throwIfInterrupted(): void;
|
|
127
|
+
waitForWritable(): Promise<void>;
|
|
128
|
+
pendingUploads(): number;
|
|
129
|
+
suspend(): Promise<void>;
|
|
130
|
+
resume(): Promise<void>;
|
|
131
|
+
watch(listener: () => void): void;
|
|
132
|
+
unwatch(listener: () => void): void;
|
|
133
|
+
_autobeeIsTrusted(key: Buffer, reference: MeshView): Promise<boolean>;
|
|
134
|
+
_autobeeMostRecentTrusted(target: MeshView, reference: MeshView | null): Promise<AutobeeOplogRef | null>;
|
|
135
|
+
_autobeeOpen(bee: unknown): MeshView;
|
|
136
|
+
_autobeeApply(nodes: ReadonlyArray<AutobeeNode>, view: MeshView, host: AutobeeHost): Promise<void>;
|
|
137
|
+
private _halt;
|
|
138
|
+
_autobeeUpdate(view: MeshView, changes: AutobeeChanges): Promise<void>;
|
|
139
|
+
checkResumedRevocation(): Promise<'kicked' | 'left' | null>;
|
|
140
|
+
}
|
|
141
|
+
export interface MeshDispatcher {
|
|
142
|
+
dispatch(name: string, payload: unknown): void | Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
export declare class MeshBatch {
|
|
145
|
+
private readonly _autobee;
|
|
146
|
+
private _ops;
|
|
147
|
+
constructor(autobee: Autobee<MeshView>);
|
|
148
|
+
get size(): number;
|
|
149
|
+
dispatch(name: string, payload: unknown): void;
|
|
150
|
+
flush(opts?: {
|
|
151
|
+
optimistic?: boolean;
|
|
152
|
+
}): Promise<void>;
|
|
153
|
+
}
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import Autobee, {} from 'autobee';
|
|
2
|
+
import BlindPeering from 'blind-peering';
|
|
3
|
+
import Corestore from 'corestore';
|
|
4
|
+
import HyperDB from 'hyperdb';
|
|
5
|
+
import { ERRORS } from 'hyperdispatch/runtime';
|
|
6
|
+
import Hyperblobs from 'hyperblobs';
|
|
7
|
+
import crypto from 'hypercore-crypto';
|
|
8
|
+
import ReadyResource from 'ready-resource';
|
|
9
|
+
import { Files } from "./files/index.js";
|
|
10
|
+
import MeshDefinition from '../../spec/mesh/hyperdb/index.js';
|
|
11
|
+
import { Router, encode } from '../../spec/mesh/hyperdispatch/index.js';
|
|
12
|
+
import { syncChanges } from "./sync/index.js";
|
|
13
|
+
import { buildDefaultSeed, isOwnKickedRow, isOwnRevokedRow } from "./helpers/index.js";
|
|
14
|
+
import { raceResource } from "../race-resource.js";
|
|
15
|
+
import { signDeviceAttestation } from "./device-attestation.js";
|
|
16
|
+
import { liveDeviceForWriter } from "./contract/activity.js";
|
|
17
|
+
import { registerRoutes } from "./contract/index.js";
|
|
18
|
+
import { createSyncActivity } from "./sync-status.js";
|
|
19
|
+
import { buildHealthAssistant } from "./health-assistant.js";
|
|
20
|
+
const [MESH_KEYPAIR, MESH_ENCRYPTION, MESH_DEVICE] = crypto.namespace('@qvac/core/mesh', 3);
|
|
21
|
+
const LIVE_WRITERS_BY_MOST_RECENT = '@qvac/live-writers-by-most-recent';
|
|
22
|
+
export async function isOurTrustedWriter(snap, writerKey, ourMemberId) {
|
|
23
|
+
const device = await liveDeviceForWriter(snap, writerKey);
|
|
24
|
+
if (!device)
|
|
25
|
+
return false;
|
|
26
|
+
if (!ourMemberId)
|
|
27
|
+
return true;
|
|
28
|
+
return device.memberId?.equals(ourMemberId) === true;
|
|
29
|
+
}
|
|
30
|
+
export function claimableDevice(row) {
|
|
31
|
+
return {
|
|
32
|
+
id: row.id,
|
|
33
|
+
joinedAt: row.joinedAt,
|
|
34
|
+
name: row.name,
|
|
35
|
+
capabilityProfile: row.capabilityProfile,
|
|
36
|
+
recommendedModelName: row.recommendedModelName
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export class Mesh extends ReadyResource {
|
|
40
|
+
_files = null;
|
|
41
|
+
get files() {
|
|
42
|
+
this._files ??= new Files(this);
|
|
43
|
+
return this._files;
|
|
44
|
+
}
|
|
45
|
+
_store;
|
|
46
|
+
_seed;
|
|
47
|
+
_key;
|
|
48
|
+
_writerSeed;
|
|
49
|
+
_log;
|
|
50
|
+
_blindPeerKeys;
|
|
51
|
+
_blindPeeringOpts;
|
|
52
|
+
_bootFrom;
|
|
53
|
+
_wakeup;
|
|
54
|
+
attachmentUrl;
|
|
55
|
+
_scope;
|
|
56
|
+
router;
|
|
57
|
+
_keyPair;
|
|
58
|
+
_deviceKeyPair;
|
|
59
|
+
_encryptionKey;
|
|
60
|
+
_blindPeering = null;
|
|
61
|
+
_orphanedBlobSweepStatus = { state: 'pending' };
|
|
62
|
+
_bootInterrupted = false;
|
|
63
|
+
_localWriterUploadedLength = 0;
|
|
64
|
+
_ourMemberId = null;
|
|
65
|
+
_membership = {
|
|
66
|
+
members: 0,
|
|
67
|
+
attested: 0,
|
|
68
|
+
unattested: 0,
|
|
69
|
+
revoked: 0
|
|
70
|
+
};
|
|
71
|
+
_deviceId;
|
|
72
|
+
autobee;
|
|
73
|
+
blobs;
|
|
74
|
+
discoveryKey;
|
|
75
|
+
syncActivity;
|
|
76
|
+
get publicKey() {
|
|
77
|
+
return this._keyPair.publicKey;
|
|
78
|
+
}
|
|
79
|
+
get devicePublicKey() {
|
|
80
|
+
return this._deviceKeyPair.publicKey;
|
|
81
|
+
}
|
|
82
|
+
get key() {
|
|
83
|
+
return this.autobee.key;
|
|
84
|
+
}
|
|
85
|
+
get encryptionKey() {
|
|
86
|
+
return this._encryptionKey;
|
|
87
|
+
}
|
|
88
|
+
get blindPeerKeys() {
|
|
89
|
+
return this._blindPeerKeys;
|
|
90
|
+
}
|
|
91
|
+
get orphanedBlobSweepStatus() {
|
|
92
|
+
return this._orphanedBlobSweepStatus;
|
|
93
|
+
}
|
|
94
|
+
blindPeerStats() {
|
|
95
|
+
const peering = this._blindPeering;
|
|
96
|
+
if (!peering?.blindPeers)
|
|
97
|
+
return [];
|
|
98
|
+
return [...peering.blindPeers.values()].map((bp) => ({
|
|
99
|
+
key: bp.remotePublicKey.toString('hex').slice(0, 16),
|
|
100
|
+
connected: bp.connected,
|
|
101
|
+
connects: bp.connects,
|
|
102
|
+
uploaded: bp.uploaded
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
get ourMemberId() {
|
|
106
|
+
return this._ourMemberId;
|
|
107
|
+
}
|
|
108
|
+
get membership() {
|
|
109
|
+
return this._membership;
|
|
110
|
+
}
|
|
111
|
+
async refreshMembership() {
|
|
112
|
+
const snap = this.view.snapshot();
|
|
113
|
+
try {
|
|
114
|
+
let members = 0;
|
|
115
|
+
let attested = 0;
|
|
116
|
+
let unattested = 0;
|
|
117
|
+
let revoked = 0;
|
|
118
|
+
for await (const _member of snap.find('@qvac/members'))
|
|
119
|
+
members++;
|
|
120
|
+
for await (const device of snap.find('@qvac/devices')) {
|
|
121
|
+
if (device.revoked)
|
|
122
|
+
revoked++;
|
|
123
|
+
else if (device.memberId)
|
|
124
|
+
attested++;
|
|
125
|
+
else
|
|
126
|
+
unattested++;
|
|
127
|
+
}
|
|
128
|
+
this._membership = {
|
|
129
|
+
members,
|
|
130
|
+
attested,
|
|
131
|
+
unattested,
|
|
132
|
+
revoked
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await snap.close();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async refreshOurMember() {
|
|
140
|
+
if (!this._deviceId)
|
|
141
|
+
return;
|
|
142
|
+
const own = await this.view.get('@qvac/devices', { id: this._deviceId });
|
|
143
|
+
this._ourMemberId = own?.memberId ?? null;
|
|
144
|
+
if (own?.memberId && own.memberProof)
|
|
145
|
+
this.emit('membership', own);
|
|
146
|
+
}
|
|
147
|
+
sign(message) {
|
|
148
|
+
return crypto.sign(message, this._keyPair.secretKey);
|
|
149
|
+
}
|
|
150
|
+
attestDevice(deviceId) {
|
|
151
|
+
return signDeviceAttestation(this._deviceKeyPair.secretKey, deviceId);
|
|
152
|
+
}
|
|
153
|
+
constructor(store, opts = {}) {
|
|
154
|
+
super();
|
|
155
|
+
this._store = store;
|
|
156
|
+
this._seed = opts.seed ?? crypto.randomBytes(32);
|
|
157
|
+
this._key = opts.key ?? null;
|
|
158
|
+
this._writerSeed = opts.writerSeed;
|
|
159
|
+
this._log = opts.logger ?? null;
|
|
160
|
+
this._blindPeerKeys = opts.blindPeerKeys ?? [];
|
|
161
|
+
this._blindPeeringOpts = opts.blindPeeringOpts;
|
|
162
|
+
this._bootFrom = opts.bootFrom;
|
|
163
|
+
this._deviceId = opts.deviceId ?? null;
|
|
164
|
+
this._wakeup = opts.wakeup;
|
|
165
|
+
this.attachmentUrl = opts.attachmentUrl ?? null;
|
|
166
|
+
this.router = new Router();
|
|
167
|
+
this._keyPair = crypto.keyPair(crypto.hash([MESH_KEYPAIR, this._seed]));
|
|
168
|
+
this._deviceKeyPair = crypto.keyPair(crypto.hash([MESH_DEVICE, this._seed]));
|
|
169
|
+
this._encryptionKey = crypto.hash([MESH_ENCRYPTION, this._seed]);
|
|
170
|
+
this.discoveryKey = crypto.discoveryKey(this._keyPair.publicKey);
|
|
171
|
+
this._scope = ['p2p', 'mesh', this._keyPair.publicKey.toString('hex').slice(0, 8)];
|
|
172
|
+
registerRoutes(this.router);
|
|
173
|
+
}
|
|
174
|
+
async _open() {
|
|
175
|
+
this._log?.info(this._scope, 'opening');
|
|
176
|
+
const namespace = this._store.namespace(this.discoveryKey);
|
|
177
|
+
const blobCore = namespace.get({ name: 'qvac-blobs', encryptionKey: this._encryptionKey });
|
|
178
|
+
this.blobs = new Hyperblobs(blobCore);
|
|
179
|
+
try {
|
|
180
|
+
await raceResource(this.blobs.core, this.blobs.ready(), 'blobs');
|
|
181
|
+
this._log?.info(this._scope, 'blob store opened');
|
|
182
|
+
const writerKeyPair = await namespace.createKeyPair(this._writerSeed ?? 'local');
|
|
183
|
+
this.autobee = new Autobee(namespace, this._key, {
|
|
184
|
+
open: this._autobeeOpen.bind(this),
|
|
185
|
+
apply: this._autobeeApply.bind(this),
|
|
186
|
+
update: this._autobeeUpdate.bind(this),
|
|
187
|
+
isTrusted: this._autobeeIsTrusted.bind(this),
|
|
188
|
+
mostRecentTrusted: this._autobeeMostRecentTrusted.bind(this),
|
|
189
|
+
keyPair: writerKeyPair,
|
|
190
|
+
encrypted: true,
|
|
191
|
+
encryptionKey: this._encryptionKey,
|
|
192
|
+
wakeupCapability: { key: this._keyPair.publicKey, discoveryKey: this.discoveryKey },
|
|
193
|
+
wakeup: this._wakeup,
|
|
194
|
+
fastForward: { boot: this._bootFrom ? { head: this._bootFrom } : null }
|
|
195
|
+
});
|
|
196
|
+
this.autobee.on('error', (err) => this._log?.warn(this._scope, 'autobee error', err));
|
|
197
|
+
this.autobee.on('move-to', (to, from) => this._log?.info(this._scope, 'fast-forwarded onto a head', {
|
|
198
|
+
from: from?.length ?? 0,
|
|
199
|
+
to: to?.length ?? 0,
|
|
200
|
+
fastForwards: this.autobee.stats.fastForwards
|
|
201
|
+
}));
|
|
202
|
+
this.autobee.on('interrupt', (err) => this._log?.warn(this._scope, 'autobee interrupt', err));
|
|
203
|
+
if (this._bootInterrupted)
|
|
204
|
+
void this.autobee.close().catch(noop);
|
|
205
|
+
await raceResource(this.autobee, this.autobee.ready(), 'autobee');
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
await this.autobee?.close().catch(noop);
|
|
209
|
+
await this.blobs.close().catch(noop);
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
212
|
+
this.autobee.local.on('upload', (index) => {
|
|
213
|
+
this._localWriterUploadedLength = Math.max(this._localWriterUploadedLength, index + 1);
|
|
214
|
+
});
|
|
215
|
+
this.syncActivity = createSyncActivity(this);
|
|
216
|
+
void this.refreshOurMember().catch((err) => this._log?.warn(this._scope, 'reading our member failed', err));
|
|
217
|
+
this._log?.info(this._scope, 'autobee opened', {
|
|
218
|
+
writable: this.autobee.writable,
|
|
219
|
+
creator: this._key === null
|
|
220
|
+
});
|
|
221
|
+
void this._sweepOrphanedBlobs(this.blobs.core.length);
|
|
222
|
+
this.files.start({ deviceId: this._deviceId });
|
|
223
|
+
}
|
|
224
|
+
startBlindPeering(dht) {
|
|
225
|
+
if (this.closing || !this.autobee || !this.blobs)
|
|
226
|
+
return;
|
|
227
|
+
this._blindPeering = new BlindPeering(dht, this._store, {
|
|
228
|
+
pick: 2,
|
|
229
|
+
wakeup: this._wakeup,
|
|
230
|
+
...this._blindPeeringOpts
|
|
231
|
+
});
|
|
232
|
+
this._blindPeering.addAutobaseBackground(this.autobee, {
|
|
233
|
+
target: this._keyPair.publicKey,
|
|
234
|
+
keys: this._blindPeerKeys
|
|
235
|
+
});
|
|
236
|
+
this._blindPeering.addCoreBackground(this.blobs.core, {
|
|
237
|
+
target: this._keyPair.publicKey,
|
|
238
|
+
keys: this._blindPeerKeys
|
|
239
|
+
});
|
|
240
|
+
this._log?.info(this._scope, 'blind peering started');
|
|
241
|
+
}
|
|
242
|
+
async openBlobs(coreKey) {
|
|
243
|
+
const core = this._store.get({ key: coreKey, encryptionKey: this._encryptionKey });
|
|
244
|
+
const blobs = new Hyperblobs(core);
|
|
245
|
+
await blobs.ready();
|
|
246
|
+
return blobs;
|
|
247
|
+
}
|
|
248
|
+
interruptBoot() {
|
|
249
|
+
this._bootInterrupted = true;
|
|
250
|
+
if (this.autobee)
|
|
251
|
+
void this.autobee.close().catch(noop);
|
|
252
|
+
}
|
|
253
|
+
async _close() {
|
|
254
|
+
this._log?.info(this._scope, 'closing');
|
|
255
|
+
await this._files?.close();
|
|
256
|
+
await Promise.all([this.autobee.close(), this.blobs.close(), this._blindPeering?.close()]);
|
|
257
|
+
this._blindPeering = null;
|
|
258
|
+
}
|
|
259
|
+
async _sweepOrphanedBlobs(blobLength) {
|
|
260
|
+
this._orphanedBlobSweepStatus = { state: 'running' };
|
|
261
|
+
try {
|
|
262
|
+
await this.autobee.update();
|
|
263
|
+
await this.files.sweepOrphans(blobLength);
|
|
264
|
+
this._orphanedBlobSweepStatus = { state: 'succeeded' };
|
|
265
|
+
this._log?.info(this._scope, 'orphaned blob sweep finished');
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
if (this.closing)
|
|
269
|
+
return;
|
|
270
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
271
|
+
this._orphanedBlobSweepStatus = { state: 'failed', error };
|
|
272
|
+
this._log?.warn(this._scope, 'orphaned blob sweep failed', err);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
get view() {
|
|
276
|
+
return this.autobee.view.db;
|
|
277
|
+
}
|
|
278
|
+
get localWriterKey() {
|
|
279
|
+
return this.autobee.local.key;
|
|
280
|
+
}
|
|
281
|
+
get writable() {
|
|
282
|
+
return this.autobee.writable;
|
|
283
|
+
}
|
|
284
|
+
get localLength() {
|
|
285
|
+
return this.autobee.local.length;
|
|
286
|
+
}
|
|
287
|
+
async dispatch(name, payload, opts) {
|
|
288
|
+
await this.autobee.append(encode(`@qvac/${name}`, payload), opts);
|
|
289
|
+
}
|
|
290
|
+
batch() {
|
|
291
|
+
return new MeshBatch(this.autobee);
|
|
292
|
+
}
|
|
293
|
+
async appendBirthOp(deviceId, device, member) {
|
|
294
|
+
if (this.autobee.local.length > 0)
|
|
295
|
+
return;
|
|
296
|
+
const localKey = this.autobee.local.key;
|
|
297
|
+
const row = device
|
|
298
|
+
? { id: deviceId, joinedAt: Date.now(), ...device }
|
|
299
|
+
: undefined;
|
|
300
|
+
if (this._key === null) {
|
|
301
|
+
const birth = this.batch();
|
|
302
|
+
birth.dispatch('add-writer', { writerKey: localKey, device: row });
|
|
303
|
+
if (row) {
|
|
304
|
+
birth.dispatch('attest-device', this.attestDevice(deviceId));
|
|
305
|
+
if (member)
|
|
306
|
+
birth.dispatch('mint-member', member);
|
|
307
|
+
birth.dispatch('seed-defaults', buildDefaultSeed(row, this._blindPeerKeys));
|
|
308
|
+
birth.dispatch('put-agent', { agent: buildHealthAssistant(row) });
|
|
309
|
+
}
|
|
310
|
+
await birth.flush();
|
|
311
|
+
}
|
|
312
|
+
else if (!this.autobee.writable) {
|
|
313
|
+
const signature = this.sign(localKey);
|
|
314
|
+
const device = row ? claimableDevice(row) : undefined;
|
|
315
|
+
const claim = this.batch();
|
|
316
|
+
claim.dispatch('join', { signature, deviceId, device });
|
|
317
|
+
if (row)
|
|
318
|
+
claim.dispatch('attest-device', this.attestDevice(deviceId));
|
|
319
|
+
await claim.flush({ optimistic: true });
|
|
320
|
+
}
|
|
321
|
+
await this.autobee.update();
|
|
322
|
+
this.throwIfInterrupted();
|
|
323
|
+
}
|
|
324
|
+
get interrupted() {
|
|
325
|
+
return this.autobee.interrupted;
|
|
326
|
+
}
|
|
327
|
+
throwIfInterrupted() {
|
|
328
|
+
if (this.interrupted)
|
|
329
|
+
throw this.interrupted;
|
|
330
|
+
}
|
|
331
|
+
async waitForWritable() {
|
|
332
|
+
if (this.closing || this.autobee.writable)
|
|
333
|
+
return;
|
|
334
|
+
await new Promise((resolve) => {
|
|
335
|
+
const done = () => {
|
|
336
|
+
this.autobee.off('writable', done);
|
|
337
|
+
this.off('close', done);
|
|
338
|
+
resolve();
|
|
339
|
+
};
|
|
340
|
+
this.autobee.on('writable', done);
|
|
341
|
+
this.on('close', done);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
pendingUploads() {
|
|
345
|
+
const peers = this.autobee.local.peers;
|
|
346
|
+
if (this.closing || peers.length === 0)
|
|
347
|
+
return 0;
|
|
348
|
+
const taken = Math.max(this._localWriterUploadedLength, ...peers.map((peer) => peer.remoteLength));
|
|
349
|
+
return Math.max(0, this.autobee.local.length - taken);
|
|
350
|
+
}
|
|
351
|
+
async suspend() {
|
|
352
|
+
await this._files?.suspend();
|
|
353
|
+
if (this._blindPeering)
|
|
354
|
+
await this._blindPeering.suspend();
|
|
355
|
+
}
|
|
356
|
+
async resume() {
|
|
357
|
+
if (this._blindPeering)
|
|
358
|
+
await this._blindPeering.resume();
|
|
359
|
+
this._files?.resume();
|
|
360
|
+
}
|
|
361
|
+
watch(listener) {
|
|
362
|
+
this.view.watch(listener);
|
|
363
|
+
}
|
|
364
|
+
unwatch(listener) {
|
|
365
|
+
this.view.unwatch(listener);
|
|
366
|
+
}
|
|
367
|
+
async _autobeeIsTrusted(key, reference) {
|
|
368
|
+
if (this.closing)
|
|
369
|
+
return false;
|
|
370
|
+
const snap = reference.db.snapshot();
|
|
371
|
+
try {
|
|
372
|
+
const trusted = await isOurTrustedWriter(snap, key, this._ourMemberId);
|
|
373
|
+
if (!trusted) {
|
|
374
|
+
this._log?.debug(this._scope, 'writer is no device of ours', {
|
|
375
|
+
writerKey: key.toString('hex').slice(0, 16)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return trusted;
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
await snap.close();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async _autobeeMostRecentTrusted(target, reference) {
|
|
385
|
+
if (this.closing)
|
|
386
|
+
return null;
|
|
387
|
+
const snap = (reference ?? target).db.snapshot();
|
|
388
|
+
try {
|
|
389
|
+
for await (const writer of target.db.find(LIVE_WRITERS_BY_MOST_RECENT, {
|
|
390
|
+
reverse: true
|
|
391
|
+
})) {
|
|
392
|
+
if (await isOurTrustedWriter(snap, writer.writerKey, this._ourMemberId)) {
|
|
393
|
+
this._log?.debug(this._scope, 'vouching for a head', {
|
|
394
|
+
writerKey: writer.writerKey.toString('hex').slice(0, 16),
|
|
395
|
+
length: writer.length
|
|
396
|
+
});
|
|
397
|
+
return { key: writer.writerKey, length: writer.length };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
this._log?.debug(this._scope, 'vouching for no head: no writer of ours has been active');
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
await snap.close();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
_autobeeOpen(bee) {
|
|
408
|
+
const db = HyperDB.bee2(bee, MeshDefinition, { autoUpdate: true });
|
|
409
|
+
return { db };
|
|
410
|
+
}
|
|
411
|
+
async _autobeeApply(nodes, view, host) {
|
|
412
|
+
const tx = view.db.transaction();
|
|
413
|
+
try {
|
|
414
|
+
for (const node of nodes) {
|
|
415
|
+
if (!node.value)
|
|
416
|
+
continue;
|
|
417
|
+
try {
|
|
418
|
+
await this.router.dispatch(node.value, {
|
|
419
|
+
tx,
|
|
420
|
+
host,
|
|
421
|
+
node,
|
|
422
|
+
meshPublicKey: this.publicKey,
|
|
423
|
+
meshDevicePublicKey: this.devicePublicKey,
|
|
424
|
+
log: this._log
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
if (!isFromANewerBuild(err))
|
|
429
|
+
throw err;
|
|
430
|
+
this._halt(err, host);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
await tx.flush();
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
await tx.close();
|
|
437
|
+
if (isInterrupt(err))
|
|
438
|
+
throw err;
|
|
439
|
+
if (isFromANewerBuild(err))
|
|
440
|
+
this._halt(err, host);
|
|
441
|
+
this._log?.error(this._scope, 'autobee apply', err);
|
|
442
|
+
throw err;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
_halt(err, host) {
|
|
446
|
+
this._log?.warn(this._scope, 'halting apply: the mesh moved past this build', err);
|
|
447
|
+
return host.interrupt(err);
|
|
448
|
+
}
|
|
449
|
+
async _autobeeUpdate(view, changes) {
|
|
450
|
+
if (this.closing)
|
|
451
|
+
return;
|
|
452
|
+
const change = changes.get('view');
|
|
453
|
+
if (!change)
|
|
454
|
+
return;
|
|
455
|
+
const shared = change.shared;
|
|
456
|
+
const from = shared?.key ? { key: shared.key, length: shared.length } : change.from;
|
|
457
|
+
try {
|
|
458
|
+
await syncChanges(this, view, from);
|
|
459
|
+
}
|
|
460
|
+
catch (err) {
|
|
461
|
+
this._log?.warn(this._scope, 'change sync failed', err);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
async checkResumedRevocation() {
|
|
465
|
+
const snap = this.view.snapshot();
|
|
466
|
+
try {
|
|
467
|
+
for await (const device of snap.find('@qvac/devices')) {
|
|
468
|
+
if (!isOwnRevokedRow(this, device))
|
|
469
|
+
continue;
|
|
470
|
+
return isOwnKickedRow(this, device) ? 'kicked' : 'left';
|
|
471
|
+
}
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
finally {
|
|
475
|
+
await snap.close();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
export class MeshBatch {
|
|
480
|
+
_autobee;
|
|
481
|
+
_ops = [];
|
|
482
|
+
constructor(autobee) {
|
|
483
|
+
this._autobee = autobee;
|
|
484
|
+
}
|
|
485
|
+
get size() {
|
|
486
|
+
return this._ops.length;
|
|
487
|
+
}
|
|
488
|
+
dispatch(name, payload) {
|
|
489
|
+
this._ops.push(encode(`@qvac/${name}`, payload));
|
|
490
|
+
}
|
|
491
|
+
async flush(opts) {
|
|
492
|
+
if (this._ops.length === 0)
|
|
493
|
+
return;
|
|
494
|
+
const ops = this._ops;
|
|
495
|
+
this._ops = [];
|
|
496
|
+
await this._autobee.append(ops, opts);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function noop() { }
|
|
500
|
+
const NEWER_BUILD_MESSAGES = new Set(['Unsupported version', 'Unknown enum', 'Out of bounds']);
|
|
501
|
+
function isInterrupt(err) {
|
|
502
|
+
return err instanceof Error && err.message === 'Apply interrupted';
|
|
503
|
+
}
|
|
504
|
+
function isFromANewerBuild(err) {
|
|
505
|
+
if (typeof err === 'object' && err !== null && 'code' in err) {
|
|
506
|
+
return err.code === ERRORS.HANDLER_NOT_FOUND_BY_ID;
|
|
507
|
+
}
|
|
508
|
+
return err instanceof Error && NEWER_BUILD_MESSAGES.has(err.message);
|
|
509
|
+
}
|