@qvac/core 0.0.0 → 0.1.1
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 +47257 -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/helpers.d.ts +28 -0
- package/dist-lib/schema/helpers.js +176 -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/schema/vendor.d.ts +5 -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 +336 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { AbortController } from 'bare-abort-controller';
|
|
2
|
+
import {} from "../rag/index.js";
|
|
3
|
+
import { DeadlineScheduler } from "../../../deadline.js";
|
|
4
|
+
import { IndexingSource } from "./source.js";
|
|
5
|
+
import { fileIds, fileRecord } from "../records/index.js";
|
|
6
|
+
import { FileDocument } from "./document.js";
|
|
7
|
+
export class FileProcessing {
|
|
8
|
+
_mesh;
|
|
9
|
+
_processor;
|
|
10
|
+
_deviceId;
|
|
11
|
+
_source;
|
|
12
|
+
_output;
|
|
13
|
+
_progress;
|
|
14
|
+
_lanes = [];
|
|
15
|
+
_deadlines = new Map();
|
|
16
|
+
_scheduler = new DeadlineScheduler(() => this._retry());
|
|
17
|
+
_scanning = null;
|
|
18
|
+
_dirty = false;
|
|
19
|
+
_paused = false;
|
|
20
|
+
_closed = false;
|
|
21
|
+
_close = null;
|
|
22
|
+
_indexCleared = true;
|
|
23
|
+
_onDirty = (ids) => {
|
|
24
|
+
if (ids)
|
|
25
|
+
void this.enqueue(ids);
|
|
26
|
+
else
|
|
27
|
+
this._kick();
|
|
28
|
+
};
|
|
29
|
+
_onAll = () => this._kick();
|
|
30
|
+
constructor(mesh, options) {
|
|
31
|
+
this._mesh = mesh;
|
|
32
|
+
this._processor = options.processor;
|
|
33
|
+
this._deviceId = options.deviceId;
|
|
34
|
+
this._progress = options.progress;
|
|
35
|
+
const readBytes = mesh.files.readBytes.bind(mesh.files);
|
|
36
|
+
const fetch = mesh.files.download.bind(mesh.files);
|
|
37
|
+
this._source = new IndexingSource(readBytes, {
|
|
38
|
+
retryMs: options.retryMs,
|
|
39
|
+
retries: mesh.files.processorState(options.processor.id).sourceRetries,
|
|
40
|
+
download: { fetch, ready: (id) => this._schedule(id, Date.now()) }
|
|
41
|
+
});
|
|
42
|
+
this._output = new IndexingSource(readBytes, {
|
|
43
|
+
retryMs: options.retryMs,
|
|
44
|
+
retries: mesh.files.processorState(options.processor.id).outputRetries,
|
|
45
|
+
download: {
|
|
46
|
+
fetch,
|
|
47
|
+
ready: (id) => this._schedule(mesh.files.processorState(options.processor.id).artifact(id).knowledgeId ?? id, Date.now())
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
this._lanes.push({ stage: 'produce', queue: new Map(), running: null, abort: null });
|
|
51
|
+
if (options.processor.load) {
|
|
52
|
+
this._lanes.push({ stage: 'load', queue: new Map(), running: null, abort: null });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
start() {
|
|
56
|
+
this._mesh.on('indexing-dirty', this._onDirty);
|
|
57
|
+
this._mesh.autobee.on('move-to', this._onAll);
|
|
58
|
+
this._mesh.autobee.on('writable', this._onAll);
|
|
59
|
+
this._kick();
|
|
60
|
+
}
|
|
61
|
+
async suspend() {
|
|
62
|
+
this._paused = true;
|
|
63
|
+
await this._stop();
|
|
64
|
+
}
|
|
65
|
+
resume() {
|
|
66
|
+
if (this._closed)
|
|
67
|
+
return;
|
|
68
|
+
this._paused = false;
|
|
69
|
+
this._kick();
|
|
70
|
+
}
|
|
71
|
+
reconnect() {
|
|
72
|
+
this._source.reconnect((id, deadline) => this._schedule(id, deadline));
|
|
73
|
+
this._output.reconnect((id, deadline) => this._schedule(this._mesh.files.processorState(this._processor.id).artifact(id).knowledgeId ?? id, deadline));
|
|
74
|
+
}
|
|
75
|
+
close() {
|
|
76
|
+
this._close ??= this._shutdown();
|
|
77
|
+
return this._close;
|
|
78
|
+
}
|
|
79
|
+
get indexCleared() {
|
|
80
|
+
return this._indexCleared;
|
|
81
|
+
}
|
|
82
|
+
async settle() {
|
|
83
|
+
if (this._closed || this._paused)
|
|
84
|
+
return;
|
|
85
|
+
const ids = await this._documents();
|
|
86
|
+
for (const lane of this._lanes)
|
|
87
|
+
await this._enqueue(ids, [lane], { wait: true });
|
|
88
|
+
}
|
|
89
|
+
enqueue(ids, options = {}) {
|
|
90
|
+
return this._enqueue(ids, this._lanes, options);
|
|
91
|
+
}
|
|
92
|
+
async _enqueue(ids, lanes, { wait = false } = {}) {
|
|
93
|
+
if (this._closed || this._paused)
|
|
94
|
+
return;
|
|
95
|
+
const pending = [];
|
|
96
|
+
for (const id of ids) {
|
|
97
|
+
for (const lane of lanes) {
|
|
98
|
+
let wakes = lane.queue.get(id);
|
|
99
|
+
if (!wakes)
|
|
100
|
+
lane.queue.set(id, (wakes = []));
|
|
101
|
+
if (wait)
|
|
102
|
+
pending.push(new Promise((resolve) => wakes.push(resolve)));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const lane of lanes)
|
|
106
|
+
this._pump(lane);
|
|
107
|
+
await Promise.all(pending);
|
|
108
|
+
}
|
|
109
|
+
get active() {
|
|
110
|
+
return !this._paused && !this._closed && !this._mesh.closing;
|
|
111
|
+
}
|
|
112
|
+
pending(id) {
|
|
113
|
+
return (!this._paused &&
|
|
114
|
+
!this._closed &&
|
|
115
|
+
(this._lanes.some((lane) => lane.current === id || lane.queue.has(id)) ||
|
|
116
|
+
this._source.pending((key) => key === id) ||
|
|
117
|
+
this._output.pending((key) => this._mesh.files.processorState(this._processor.id).artifact(key).knowledgeId === id)));
|
|
118
|
+
}
|
|
119
|
+
prioritize(ids) {
|
|
120
|
+
for (const lane of this._lanes) {
|
|
121
|
+
const queued = new Map(lane.queue);
|
|
122
|
+
lane.queue.clear();
|
|
123
|
+
for (const id of ids)
|
|
124
|
+
lane.queue.set(id, queued.get(id) ?? []);
|
|
125
|
+
for (const [id, wakes] of queued)
|
|
126
|
+
if (!lane.queue.has(id))
|
|
127
|
+
lane.queue.set(id, wakes);
|
|
128
|
+
this._pump(lane);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async _shutdown() {
|
|
132
|
+
this._closed = true;
|
|
133
|
+
this._mesh.off('indexing-dirty', this._onDirty);
|
|
134
|
+
this._mesh.autobee.off('move-to', this._onAll);
|
|
135
|
+
this._mesh.autobee.off('writable', this._onAll);
|
|
136
|
+
await this._stop();
|
|
137
|
+
if (this._processor.load)
|
|
138
|
+
this._mesh.files.clearLoaded(this._processor.id);
|
|
139
|
+
this._indexCleared = await this._processor.close();
|
|
140
|
+
}
|
|
141
|
+
async _stop() {
|
|
142
|
+
this._scheduler.clear();
|
|
143
|
+
this._deadlines.clear();
|
|
144
|
+
this._mesh.files.emit('update');
|
|
145
|
+
for (const lane of this._lanes) {
|
|
146
|
+
lane.abort?.abort({
|
|
147
|
+
type: this._closed ? 'file-processing-closed' : 'file-processing-suspended'
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
await Promise.all([this._scanning, ...this._lanes.map((lane) => lane.running)]);
|
|
151
|
+
await Promise.all([this._source.cancel(), this._output.cancel()]);
|
|
152
|
+
for (const lane of this._lanes) {
|
|
153
|
+
for (const wakes of lane.queue.values())
|
|
154
|
+
for (const wake of wakes)
|
|
155
|
+
wake();
|
|
156
|
+
lane.queue.clear();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
_kick() {
|
|
160
|
+
if (this._closed || this._paused)
|
|
161
|
+
return;
|
|
162
|
+
this._dirty = true;
|
|
163
|
+
if (this._scanning)
|
|
164
|
+
return;
|
|
165
|
+
this._scanning = this._scan().finally(() => {
|
|
166
|
+
this._scanning = null;
|
|
167
|
+
if (this._dirty)
|
|
168
|
+
this._kick();
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async _scan() {
|
|
172
|
+
while (this._dirty && !this._closed && !this._paused) {
|
|
173
|
+
this._dirty = false;
|
|
174
|
+
try {
|
|
175
|
+
await this.enqueue(await this._documents());
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
logger.warn('rag', 'file processing scan failed', { err });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async _documents() {
|
|
183
|
+
if (this._mesh.closing)
|
|
184
|
+
return [];
|
|
185
|
+
const snap = this._mesh.view.snapshot();
|
|
186
|
+
try {
|
|
187
|
+
return await fileIds(snap, this._processor.input, this._processor.mediaKind);
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
await snap.close();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
_pump(lane) {
|
|
194
|
+
if (lane.running || !lane.queue.size || this._closed || this._paused || this._mesh.closing) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
lane.running = this._drain(lane).finally(() => {
|
|
198
|
+
lane.running = null;
|
|
199
|
+
this._pump(lane);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async _drain(lane) {
|
|
203
|
+
while (lane.queue.size && !this._closed && !this._paused && !this._mesh.closing) {
|
|
204
|
+
const [id, wakes] = lane.queue.entries().next().value;
|
|
205
|
+
lane.queue.delete(id);
|
|
206
|
+
lane.current = id;
|
|
207
|
+
lane.abort = new AbortController();
|
|
208
|
+
let produced = false;
|
|
209
|
+
try {
|
|
210
|
+
const record = await fileRecord(this._mesh.view, id, this._processor.input);
|
|
211
|
+
if (!record || record.deletedAt) {
|
|
212
|
+
await this._source.cancel((key) => key === id);
|
|
213
|
+
await this._output.cancel((key) => this._mesh.files.processorState(this._processor.id).artifact(key).knowledgeId === id);
|
|
214
|
+
}
|
|
215
|
+
if (!record || !this._processor.applies(record) || lane.abort.signal.aborted)
|
|
216
|
+
continue;
|
|
217
|
+
if (lane.stage === 'produce' &&
|
|
218
|
+
(!this._mesh.writable ||
|
|
219
|
+
!(await this._processor.canProduce(record, {
|
|
220
|
+
mesh: this._mesh,
|
|
221
|
+
deviceId: this._deviceId
|
|
222
|
+
})))) {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const document = new FileDocument(this._mesh, {
|
|
226
|
+
record,
|
|
227
|
+
processor: this._processor,
|
|
228
|
+
source: this._source,
|
|
229
|
+
output: this._output,
|
|
230
|
+
schedule: (deadline) => this._schedule(id, deadline),
|
|
231
|
+
closed: () => this._closed,
|
|
232
|
+
paused: () => this._paused,
|
|
233
|
+
progress: this._progress
|
|
234
|
+
});
|
|
235
|
+
if (lane.abort.signal.aborted)
|
|
236
|
+
continue;
|
|
237
|
+
await this._processor[lane.stage]?.(document, lane.abort.signal);
|
|
238
|
+
produced = lane.stage === 'produce';
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
if (!lane.abort.signal.aborted) {
|
|
242
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
243
|
+
if (lane.stage === 'load') {
|
|
244
|
+
this._mesh.files.load(id, { state: 'failed', reason }, {
|
|
245
|
+
processorId: this._processor.id,
|
|
246
|
+
artifactId: this._mesh.files.hydratedArtifact(id) ?? undefined
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this._mesh.files.work(id, { state: 'failed', reason }, this._processor.id);
|
|
251
|
+
}
|
|
252
|
+
logger.warn('rag', 'file processing failed', { id, stage: lane.stage, err });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
lane.abort = null;
|
|
257
|
+
lane.current = undefined;
|
|
258
|
+
if (produced && this.active) {
|
|
259
|
+
const loader = this._lanes.find((entry) => entry.stage === 'load');
|
|
260
|
+
if (loader) {
|
|
261
|
+
if (!loader.queue.has(id))
|
|
262
|
+
loader.queue.set(id, []);
|
|
263
|
+
this._pump(loader);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (const wake of wakes)
|
|
267
|
+
wake();
|
|
268
|
+
this._mesh.files.emit('update');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
_schedule(id, deadline) {
|
|
273
|
+
if (this._closed || this._paused)
|
|
274
|
+
return;
|
|
275
|
+
const previous = this._deadlines.get(id);
|
|
276
|
+
if (previous === undefined || deadline < previous)
|
|
277
|
+
this._deadlines.set(id, deadline);
|
|
278
|
+
this._scheduler.schedule(deadline);
|
|
279
|
+
}
|
|
280
|
+
_retry() {
|
|
281
|
+
const ids = [];
|
|
282
|
+
for (const [id, deadline] of this._deadlines) {
|
|
283
|
+
if (deadline <= Date.now()) {
|
|
284
|
+
this._deadlines.delete(id);
|
|
285
|
+
ids.push(id);
|
|
286
|
+
}
|
|
287
|
+
else
|
|
288
|
+
this._scheduler.schedule(deadline);
|
|
289
|
+
}
|
|
290
|
+
void this.enqueue(ids);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
export { isClaimLive, listIndexingByChat } from "./protocol.js";
|
|
294
|
+
export { FileState } from "./state.js";
|
|
295
|
+
export { settleFiles } from "./settle.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BlobId } from 'hyperblobs';
|
|
2
|
+
import type { Mesh } from '../../mesh.ts';
|
|
3
|
+
import type { FileState } from './state.ts';
|
|
4
|
+
export declare class ArtifactOwnership {
|
|
5
|
+
private readonly _mesh;
|
|
6
|
+
private readonly _state;
|
|
7
|
+
constructor(mesh: Mesh, state?: FileState);
|
|
8
|
+
onPublished(artifactId: string, blobRef: BlobId, artifactBlobId: string, landedBlobId: string): Promise<void>;
|
|
9
|
+
reclaimSuperseded(artifactId: string, winnerBlobId: string): Promise<void>;
|
|
10
|
+
clearUnreferenced(artifactId: string, blobRef: BlobId): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { compareBlobReferences } from "../store/index.js";
|
|
2
|
+
export class ArtifactOwnership {
|
|
3
|
+
_mesh;
|
|
4
|
+
_state;
|
|
5
|
+
constructor(mesh, state = mesh.files.state) {
|
|
6
|
+
this._mesh = mesh;
|
|
7
|
+
this._state = state;
|
|
8
|
+
}
|
|
9
|
+
async onPublished(artifactId, blobRef, artifactBlobId, landedBlobId) {
|
|
10
|
+
if (compareBlobReferences(landedBlobId, artifactBlobId, this._mesh.blobs.core.key.toString('hex')) === false) {
|
|
11
|
+
await this._mesh.files.clear(this._mesh.files.reference(blobRef), artifactId).catch(noop);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
this._state.artifact(artifactId).published = { artifactBlobId };
|
|
15
|
+
}
|
|
16
|
+
async reclaimSuperseded(artifactId, winnerBlobId) {
|
|
17
|
+
const local = this._state.artifact(artifactId);
|
|
18
|
+
const mine = local.published;
|
|
19
|
+
if (!mine ||
|
|
20
|
+
compareBlobReferences(mine.artifactBlobId, winnerBlobId, this._mesh.blobs.core.key.toString('hex')) !== false) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
local.published = undefined;
|
|
24
|
+
await this._mesh.files.clear(mine.artifactBlobId, artifactId).catch(noop);
|
|
25
|
+
}
|
|
26
|
+
async clearUnreferenced(artifactId, blobRef) {
|
|
27
|
+
try {
|
|
28
|
+
const row = await this._mesh.files.artifact(artifactId);
|
|
29
|
+
const mine = this._mesh.files.reference(blobRef);
|
|
30
|
+
if (row &&
|
|
31
|
+
compareBlobReferences(row.artifactBlobId, mine, this._mesh.blobs.core.key.toString('hex')) !== false) {
|
|
32
|
+
this._state.artifact(artifactId).published = { artifactBlobId: mine };
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await this._mesh.files.clear(this._mesh.files.reference(blobRef), artifactId).catch(noop);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const noop = () => { };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { QvacIndexingResolution, QvacIndexingStatus } from '../../../../spec/mesh/hyperschema/types.d.ts';
|
|
2
|
+
import type { Mesh } from '../../mesh.ts';
|
|
3
|
+
export { INDEXING_CLAIM_TTL_MS, INDEXING_MAX_CLOCK_SKEW_MS } from '../../contract/indexing.ts';
|
|
4
|
+
export declare function isClaimLive(row: QvacIndexingStatus, at: number): boolean;
|
|
5
|
+
export interface ClaimIndexingInput {
|
|
6
|
+
artifactId: string;
|
|
7
|
+
knowledgeId: string;
|
|
8
|
+
at: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function getIndexingStatus(store: Mesh, artifactId: string): Promise<QvacIndexingStatus | null>;
|
|
11
|
+
export declare function listIndexingByKnowledge(store: Mesh, { knowledgeId }: {
|
|
12
|
+
knowledgeId: string;
|
|
13
|
+
}): Promise<QvacIndexingStatus[]>;
|
|
14
|
+
export declare function listIndexingByChat(store: Mesh, { chatId }: {
|
|
15
|
+
chatId: string;
|
|
16
|
+
}): Promise<QvacIndexingStatus[]>;
|
|
17
|
+
export declare function claimIndexing(store: Mesh, { artifactId, knowledgeId, at }: ClaimIndexingInput): Promise<{
|
|
18
|
+
row: QvacIndexingStatus;
|
|
19
|
+
won: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function resolveIndexing(store: Mesh, { artifactId, claimId, status, error }: {
|
|
22
|
+
artifactId: string;
|
|
23
|
+
claimId: string;
|
|
24
|
+
status: QvacIndexingResolution;
|
|
25
|
+
error?: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
row: QvacIndexingStatus;
|
|
28
|
+
applied: boolean;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { INDEXING_MAX_CLOCK_SKEW_MS } from "../../contract/indexing.js";
|
|
2
|
+
import { randomId } from "../../id.js";
|
|
3
|
+
export { INDEXING_CLAIM_TTL_MS, INDEXING_MAX_CLOCK_SKEW_MS } from "../../contract/indexing.js";
|
|
4
|
+
export function isClaimLive(row, at) {
|
|
5
|
+
return (row.status === 'indexing' && row.expiresAt > at && row.at <= at + INDEXING_MAX_CLOCK_SKEW_MS);
|
|
6
|
+
}
|
|
7
|
+
const INDEXING_STATUS = '@qvac/indexing-status';
|
|
8
|
+
const INDEXING_STATUS_BY_KNOWLEDGE = '@qvac/indexing-status-by-knowledge';
|
|
9
|
+
const INDEXING_STATUS_BY_CHAT = '@qvac/indexing-status-by-chat';
|
|
10
|
+
export async function getIndexingStatus(store, artifactId) {
|
|
11
|
+
const snap = store.view.snapshot();
|
|
12
|
+
try {
|
|
13
|
+
const status = await snap.get(INDEXING_STATUS, { id: artifactId });
|
|
14
|
+
return status;
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
await snap.close();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function mustGetIndexingStatus(store, artifactId) {
|
|
21
|
+
const row = await getIndexingStatus(store, artifactId);
|
|
22
|
+
if (!row)
|
|
23
|
+
throw new Error(`indexing status not found: ${artifactId}`);
|
|
24
|
+
return row;
|
|
25
|
+
}
|
|
26
|
+
export async function listIndexingByKnowledge(store, { knowledgeId }) {
|
|
27
|
+
const snap = store.view.snapshot();
|
|
28
|
+
try {
|
|
29
|
+
const rows = await snap
|
|
30
|
+
.find(INDEXING_STATUS_BY_KNOWLEDGE, {
|
|
31
|
+
gte: { knowledgeId },
|
|
32
|
+
lte: { knowledgeId }
|
|
33
|
+
})
|
|
34
|
+
.toArray();
|
|
35
|
+
return rows;
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await snap.close();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function listIndexingByChat(store, { chatId }) {
|
|
42
|
+
const snap = store.view.snapshot();
|
|
43
|
+
try {
|
|
44
|
+
const rows = await snap
|
|
45
|
+
.find(INDEXING_STATUS_BY_CHAT, {
|
|
46
|
+
gte: { chatId },
|
|
47
|
+
lte: { chatId }
|
|
48
|
+
})
|
|
49
|
+
.toArray();
|
|
50
|
+
return rows;
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
await snap.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export async function claimIndexing(store, { artifactId, knowledgeId, at }) {
|
|
57
|
+
if (!at || at < 0)
|
|
58
|
+
throw new Error(`claim-indexing needs a positive timestamp, got ${at}`);
|
|
59
|
+
const claimId = randomId();
|
|
60
|
+
await store.dispatch('claim-indexing', { id: artifactId, knowledgeId, claimId, at });
|
|
61
|
+
const row = await mustGetIndexingStatus(store, artifactId);
|
|
62
|
+
const won = row.status === 'indexing' && row.claimId === claimId;
|
|
63
|
+
return { row, won };
|
|
64
|
+
}
|
|
65
|
+
export async function resolveIndexing(store, { artifactId, claimId, status, error }) {
|
|
66
|
+
await store.dispatch('resolve-indexing', { id: artifactId, claimId, status, error });
|
|
67
|
+
const row = await mustGetIndexingStatus(store, artifactId);
|
|
68
|
+
const applied = row.status === status && row.claimId === claimId;
|
|
69
|
+
return { row, applied };
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import type { Files } from '../index.ts';
|
|
3
|
+
import type { FileProcessing } from './index.ts';
|
|
4
|
+
export declare function settleFiles(files: Files, options: {
|
|
5
|
+
ids: string[];
|
|
6
|
+
processing: FileProcessing;
|
|
7
|
+
chatIds: () => Promise<string[]>;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AbortedError } from '@qvac/harness/race-abort';
|
|
2
|
+
export function settleFiles(files, options) {
|
|
3
|
+
const { ids, processing, signal, timeoutMs = 5_000 } = options;
|
|
4
|
+
if (signal?.aborted)
|
|
5
|
+
return Promise.reject(new AbortedError());
|
|
6
|
+
if (!ids.length || timeoutMs <= 0 || files.closed)
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
const deadline = Date.now() + timeoutMs;
|
|
9
|
+
const wanted = new Set(ids);
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
let done = false;
|
|
12
|
+
let checking = false;
|
|
13
|
+
let dirty = false;
|
|
14
|
+
const timer = setTimeout(() => finish(), timeoutMs);
|
|
15
|
+
const finish = (error) => {
|
|
16
|
+
if (done)
|
|
17
|
+
return;
|
|
18
|
+
done = true;
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
files.unwatch(check);
|
|
21
|
+
files.off('close', onClose);
|
|
22
|
+
signal?.removeEventListener('abort', onAbort);
|
|
23
|
+
if (error)
|
|
24
|
+
reject(error);
|
|
25
|
+
else
|
|
26
|
+
resolve();
|
|
27
|
+
};
|
|
28
|
+
const onClose = () => finish();
|
|
29
|
+
const onAbort = () => finish(new AbortedError());
|
|
30
|
+
const chats = options.chatIds();
|
|
31
|
+
const check = () => {
|
|
32
|
+
dirty = true;
|
|
33
|
+
if (checking || done)
|
|
34
|
+
return;
|
|
35
|
+
checking = true;
|
|
36
|
+
void (async () => {
|
|
37
|
+
while (dirty && !done) {
|
|
38
|
+
dirty = false;
|
|
39
|
+
const snapshots = await Promise.all((await chats).map((chatId) => files.status(chatId)));
|
|
40
|
+
if (done)
|
|
41
|
+
return;
|
|
42
|
+
if (!processing.active)
|
|
43
|
+
return finish();
|
|
44
|
+
const waiting = snapshots
|
|
45
|
+
.flatMap((snapshot) => snapshot.files)
|
|
46
|
+
.some((file) => {
|
|
47
|
+
if (!wanted.has(file.fileId) || file.readyForChat)
|
|
48
|
+
return false;
|
|
49
|
+
const rag = file.processors.find((entry) => entry.processorId === 'rag');
|
|
50
|
+
if (!rag || rag.state === 'not-applicable')
|
|
51
|
+
return false;
|
|
52
|
+
if (rag.state === 'failed' && (!rag.retryAt || rag.retryAt > deadline))
|
|
53
|
+
return false;
|
|
54
|
+
return (processing.pending(file.fileId) ||
|
|
55
|
+
rag.state === 'running' ||
|
|
56
|
+
(rag.retryAt !== undefined && rag.retryAt <= deadline));
|
|
57
|
+
});
|
|
58
|
+
if (!waiting)
|
|
59
|
+
finish();
|
|
60
|
+
}
|
|
61
|
+
})()
|
|
62
|
+
.catch(finish)
|
|
63
|
+
.finally(() => {
|
|
64
|
+
checking = false;
|
|
65
|
+
if (dirty && !done)
|
|
66
|
+
check();
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
files.watch(check);
|
|
70
|
+
files.on('close', onClose);
|
|
71
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
72
|
+
processing.prioritize(ids);
|
|
73
|
+
check();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type BlobStore } from '../store/index.ts';
|
|
2
|
+
import { type AbortSignal } from 'bare-abort-controller';
|
|
3
|
+
import type { FileRetries } from './state.ts';
|
|
4
|
+
export type SourceRead = {
|
|
5
|
+
kind: 'bytes';
|
|
6
|
+
bytes: Buffer;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'missing';
|
|
9
|
+
retryAt: number;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'malformed';
|
|
12
|
+
};
|
|
13
|
+
export interface IndexingSourceOptions {
|
|
14
|
+
readonly retryMs?: number;
|
|
15
|
+
readonly retries: FileRetries;
|
|
16
|
+
readonly download?: {
|
|
17
|
+
fetch: BlobStore['download'];
|
|
18
|
+
ready: (id: string) => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class IndexingSource {
|
|
22
|
+
private readonly _readBytes;
|
|
23
|
+
private readonly _retryMs;
|
|
24
|
+
private readonly _download;
|
|
25
|
+
private readonly _downloads;
|
|
26
|
+
readonly retry: FileRetries;
|
|
27
|
+
constructor(readBytes: BlobStore['readBytes'], opts: IndexingSourceOptions);
|
|
28
|
+
retryBlockedUntil(id: string, now: number): number | null;
|
|
29
|
+
retryMiss(id: string, now: number): number;
|
|
30
|
+
retryClear(id: string): void;
|
|
31
|
+
reconnect(onRetry?: (id: string, deadline: number) => void): number | null;
|
|
32
|
+
read(id: string, blobRef: string, signal?: AbortSignal): Promise<SourceRead>;
|
|
33
|
+
cancel(matches?: (id: string) => boolean): Promise<void>;
|
|
34
|
+
pending(matches: (id: string) => boolean): boolean;
|
|
35
|
+
private _fetch;
|
|
36
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isInvalidBlobReferenceError, compareBlobReferences } from "../store/index.js";
|
|
2
|
+
import { AbortController } from 'bare-abort-controller';
|
|
3
|
+
import { AbortedError } from '@qvac/harness/race-abort';
|
|
4
|
+
const BLOB_RETRY_MS = 30_000;
|
|
5
|
+
export class IndexingSource {
|
|
6
|
+
_readBytes;
|
|
7
|
+
_retryMs;
|
|
8
|
+
_download;
|
|
9
|
+
_downloads = new Map();
|
|
10
|
+
retry;
|
|
11
|
+
constructor(readBytes, opts) {
|
|
12
|
+
this._readBytes = readBytes;
|
|
13
|
+
this._retryMs = opts.retryMs ?? BLOB_RETRY_MS;
|
|
14
|
+
this.retry = opts.retries;
|
|
15
|
+
this._download = opts.download;
|
|
16
|
+
}
|
|
17
|
+
retryBlockedUntil(id, now) {
|
|
18
|
+
return this.retry.blockedUntil(id, now);
|
|
19
|
+
}
|
|
20
|
+
retryMiss(id, now) {
|
|
21
|
+
return this.retry.miss(id, now, this._retryMs);
|
|
22
|
+
}
|
|
23
|
+
retryClear(id) {
|
|
24
|
+
this.retry.clear(id);
|
|
25
|
+
}
|
|
26
|
+
reconnect(onRetry) {
|
|
27
|
+
return this.retry.reconnect(onRetry);
|
|
28
|
+
}
|
|
29
|
+
async read(id, blobRef, signal) {
|
|
30
|
+
try {
|
|
31
|
+
const bytes = await this._readBytes(blobRef, { signal, wait: !this._download });
|
|
32
|
+
this.retry.missing(id, false);
|
|
33
|
+
return { kind: 'bytes', bytes };
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (signal?.aborted || err instanceof AbortedError)
|
|
37
|
+
throw new AbortedError();
|
|
38
|
+
if (isInvalidBlobReferenceError(err)) {
|
|
39
|
+
logger.warn('rag', 'blob ref is malformed, never readable', { id });
|
|
40
|
+
return { kind: 'malformed' };
|
|
41
|
+
}
|
|
42
|
+
logger.debug('rag', 'blob bytes unavailable', { id, err });
|
|
43
|
+
this.retry.missing(id, true);
|
|
44
|
+
const retryAt = this.retryMiss(id, Date.now());
|
|
45
|
+
this._fetch(id, blobRef);
|
|
46
|
+
return { kind: 'missing', retryAt };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async cancel(matches = () => true) {
|
|
50
|
+
const pending = [];
|
|
51
|
+
for (const [id, transfer] of this._downloads) {
|
|
52
|
+
if (!matches(id))
|
|
53
|
+
continue;
|
|
54
|
+
transfer.abort.abort(new AbortedError());
|
|
55
|
+
this.retryClear(id);
|
|
56
|
+
pending.push(transfer.done);
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(pending);
|
|
59
|
+
}
|
|
60
|
+
pending(matches) {
|
|
61
|
+
for (const id of this._downloads.keys())
|
|
62
|
+
if (matches(id))
|
|
63
|
+
return true;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
_fetch(id, reference) {
|
|
67
|
+
const download = this._download;
|
|
68
|
+
if (!download)
|
|
69
|
+
return;
|
|
70
|
+
const current = this._downloads.get(id);
|
|
71
|
+
if (current && compareBlobReferences(current.reference, reference))
|
|
72
|
+
return;
|
|
73
|
+
current?.abort.abort(new AbortedError());
|
|
74
|
+
const abort = new AbortController();
|
|
75
|
+
const transfer = {
|
|
76
|
+
reference,
|
|
77
|
+
abort,
|
|
78
|
+
done: download
|
|
79
|
+
.fetch(reference, { signal: abort.signal })
|
|
80
|
+
.then(() => {
|
|
81
|
+
if (abort.signal.aborted)
|
|
82
|
+
return;
|
|
83
|
+
this.retryClear(id);
|
|
84
|
+
download.ready(id);
|
|
85
|
+
}, (err) => {
|
|
86
|
+
if (!abort.signal.aborted)
|
|
87
|
+
logger.debug('rag', 'blob download interrupted', { id, err });
|
|
88
|
+
})
|
|
89
|
+
.finally(() => {
|
|
90
|
+
if (this._downloads.get(id) === transfer)
|
|
91
|
+
this._downloads.delete(id);
|
|
92
|
+
})
|
|
93
|
+
};
|
|
94
|
+
this._downloads.set(id, transfer);
|
|
95
|
+
}
|
|
96
|
+
}
|