@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,787 @@
|
|
|
1
|
+
import { AbortController } from 'bare-abort-controller';
|
|
2
|
+
import { skillModelsForAgent } from '@qvac/harness/lib/models/model-catalog.ts';
|
|
3
|
+
import { GENERATE_MUSIC_TOOL, MUSIC_MODEL_CHOICES } from '@qvac/harness/music-catalog';
|
|
4
|
+
import { DeadlineScheduler } from "./deadline.js";
|
|
5
|
+
import { DownloadSpeedSampler, progressBytes, transferProgress } from '@qvac/harness/model-progress';
|
|
6
|
+
import { isMeshTransition } from "./api/current-mesh.js";
|
|
7
|
+
import { runnableModelName } from "./model-clamp.js";
|
|
8
|
+
import { ModelDownloadStatus } from "./model-download-status.js";
|
|
9
|
+
import { RetryBudget } from "./retry-budget.js";
|
|
10
|
+
import { unref } from "./unref.js";
|
|
11
|
+
const WATCH_RETRY_MS = 30_000;
|
|
12
|
+
const LOCAL_PROGRESS_INTERVAL_MS = 750;
|
|
13
|
+
const LOCAL_PROGRESS_PERCENTAGE_STEP = 1;
|
|
14
|
+
const MAX_DEMAND_FAILURES = 3;
|
|
15
|
+
export class ModelDownloadReconciler {
|
|
16
|
+
_engine;
|
|
17
|
+
_harness;
|
|
18
|
+
_deviceId;
|
|
19
|
+
_onCacheChanged;
|
|
20
|
+
_log;
|
|
21
|
+
_status;
|
|
22
|
+
_retry;
|
|
23
|
+
_now;
|
|
24
|
+
_watchRetryMs;
|
|
25
|
+
_mobileClass;
|
|
26
|
+
_scheduler;
|
|
27
|
+
_attemptGenerations = new Map();
|
|
28
|
+
_transfers = new Map();
|
|
29
|
+
_completedTransfers = new Set();
|
|
30
|
+
_pendingCompletions = new Map();
|
|
31
|
+
_observedTransfers = new Set();
|
|
32
|
+
_observedProgress = new Map();
|
|
33
|
+
_observedSpeed = new Map();
|
|
34
|
+
_requestedModels = new Set();
|
|
35
|
+
_targetTotals = new Map();
|
|
36
|
+
_config = null;
|
|
37
|
+
_active = null;
|
|
38
|
+
_localLlm = null;
|
|
39
|
+
_localSkillModels = [];
|
|
40
|
+
_musicChoice = undefined;
|
|
41
|
+
_preemptLlm = null;
|
|
42
|
+
_pausedLocalLlm = null;
|
|
43
|
+
_profile = null;
|
|
44
|
+
_capability = null;
|
|
45
|
+
_handled = new Set();
|
|
46
|
+
_demands = new Map();
|
|
47
|
+
_dirty = false;
|
|
48
|
+
_running = null;
|
|
49
|
+
_paused = false;
|
|
50
|
+
_runModels = new Set();
|
|
51
|
+
_closed = false;
|
|
52
|
+
_configStream = null;
|
|
53
|
+
_agentsStream = null;
|
|
54
|
+
_toolConfigsStream = null;
|
|
55
|
+
_toolConfigsAgentId = null;
|
|
56
|
+
_timers = new Set();
|
|
57
|
+
constructor({ engine, harness, deviceId, onCacheChanged, retryMs, now = Date.now, createScheduler = (onFire) => new DeadlineScheduler(onFire), logger = null, mobileClass = false }) {
|
|
58
|
+
this._engine = engine;
|
|
59
|
+
this._harness = harness;
|
|
60
|
+
this._deviceId = deviceId;
|
|
61
|
+
this._onCacheChanged = onCacheChanged;
|
|
62
|
+
this._log = logger;
|
|
63
|
+
this._status = new ModelDownloadStatus(engine, logger);
|
|
64
|
+
this._retry = new RetryBudget(retryMs === undefined ? {} : { retryMs });
|
|
65
|
+
this._now = now;
|
|
66
|
+
this._scheduler = createScheduler(() => this._kick());
|
|
67
|
+
this._watchRetryMs = retryMs ?? WATCH_RETRY_MS;
|
|
68
|
+
this._mobileClass = mobileClass;
|
|
69
|
+
}
|
|
70
|
+
start() {
|
|
71
|
+
if (!this._harness.download)
|
|
72
|
+
return;
|
|
73
|
+
this._reset().finally(() => {
|
|
74
|
+
if (this._closed)
|
|
75
|
+
return;
|
|
76
|
+
this._watchConfig();
|
|
77
|
+
this._watchAgents();
|
|
78
|
+
this._kick();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async _reset() {
|
|
82
|
+
try {
|
|
83
|
+
const it = this._engine.modelDownloadsWatch({})[Symbol.asyncIterator]();
|
|
84
|
+
const first = await it.next();
|
|
85
|
+
await it.return?.();
|
|
86
|
+
for (const row of first.value?.downloads ?? []) {
|
|
87
|
+
await this._engine.clearModelDownload({ name: row.name }).catch(() => { });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
this._log?.warn('model-download', 'stale local status reset failed', err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async suspend() {
|
|
95
|
+
this._paused = true;
|
|
96
|
+
this._scheduler.clear();
|
|
97
|
+
await this._stopActive(false);
|
|
98
|
+
await this._running;
|
|
99
|
+
}
|
|
100
|
+
resume() {
|
|
101
|
+
if (this._closed)
|
|
102
|
+
return;
|
|
103
|
+
this._paused = false;
|
|
104
|
+
this._kick();
|
|
105
|
+
}
|
|
106
|
+
yieldToRuns(models) {
|
|
107
|
+
if (this._closed)
|
|
108
|
+
return;
|
|
109
|
+
const next = new Set(models);
|
|
110
|
+
if (next.size === this._runModels.size && [...next].every((m) => this._runModels.has(m)))
|
|
111
|
+
return;
|
|
112
|
+
this._runModels = next;
|
|
113
|
+
this._kick();
|
|
114
|
+
}
|
|
115
|
+
observeImageProgress(observation) {
|
|
116
|
+
if (this._closed)
|
|
117
|
+
return;
|
|
118
|
+
if (observation.phase === 'downloading') {
|
|
119
|
+
this._observedTransfers.add(observation.model);
|
|
120
|
+
if (this._completedTransfers.delete(observation.model)) {
|
|
121
|
+
this._transfers.delete(observation.model);
|
|
122
|
+
}
|
|
123
|
+
void this._transfer(observation.model).catch((error) => {
|
|
124
|
+
this._log?.warn('model-download', 'recording observed transfer failed', error);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else if (!this._transfers.has(observation.model) &&
|
|
128
|
+
!this._observedTransfers.has(observation.model)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this._observedProgress.set(observation.model, {
|
|
132
|
+
...observation,
|
|
133
|
+
at: this._now(),
|
|
134
|
+
percentage: Math.max(0, Math.min(100, Math.floor(observation.percentage))),
|
|
135
|
+
downloaded: Math.max(0, Math.floor(observation.downloaded)),
|
|
136
|
+
total: Math.max(0, Math.floor(observation.total))
|
|
137
|
+
});
|
|
138
|
+
this._kick();
|
|
139
|
+
}
|
|
140
|
+
_transfer(name) {
|
|
141
|
+
let transfer = this._transfers.get(name);
|
|
142
|
+
if (!transfer) {
|
|
143
|
+
transfer = this._engine.beginModelTransfer({ name }).catch((error) => {
|
|
144
|
+
this._transfers.delete(name);
|
|
145
|
+
throw error;
|
|
146
|
+
});
|
|
147
|
+
this._transfers.set(name, transfer);
|
|
148
|
+
}
|
|
149
|
+
return transfer;
|
|
150
|
+
}
|
|
151
|
+
async _completeTransfer(name, { downloaded = true } = {}) {
|
|
152
|
+
this._pendingCompletions.set(name, downloaded);
|
|
153
|
+
await this._engine.completeModelTransfer({ ...(await this._transfer(name)), downloaded });
|
|
154
|
+
this._pendingCompletions.delete(name);
|
|
155
|
+
this._completedTransfers.add(name);
|
|
156
|
+
}
|
|
157
|
+
async waitUntilCached(model, signal) {
|
|
158
|
+
if (this._closed ||
|
|
159
|
+
!this._harness.list ||
|
|
160
|
+
!this._harness.download ||
|
|
161
|
+
this._handled.has(model) ||
|
|
162
|
+
signal.aborted) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const rows = await this._harness.list({}).catch(() => null);
|
|
166
|
+
if (this._closed || this._handled.has(model) || signal.aborted)
|
|
167
|
+
return;
|
|
168
|
+
let addon = 'llm';
|
|
169
|
+
if (rows !== null) {
|
|
170
|
+
const row = rows.find((entry) => entry.name === model);
|
|
171
|
+
if (!row || row.isCached)
|
|
172
|
+
return;
|
|
173
|
+
addon = row.type;
|
|
174
|
+
}
|
|
175
|
+
await new Promise((resolve, reject) => {
|
|
176
|
+
const abort = () => {
|
|
177
|
+
this._removeDemandWaiter(model, waiter);
|
|
178
|
+
resolve();
|
|
179
|
+
};
|
|
180
|
+
const waiter = { signal, abort, reject, resolve };
|
|
181
|
+
const demand = this._demands.get(model) ?? {
|
|
182
|
+
addon,
|
|
183
|
+
failures: 0,
|
|
184
|
+
waiters: new Set()
|
|
185
|
+
};
|
|
186
|
+
demand.waiters.add(waiter);
|
|
187
|
+
this._demands.set(model, demand);
|
|
188
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
189
|
+
this._kick();
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async retry(name) {
|
|
193
|
+
if (this._closed)
|
|
194
|
+
throw new Error('model download reconciler is closed');
|
|
195
|
+
this._requestedModels.add(name);
|
|
196
|
+
this._attemptGenerations.set(name, this._attemptGeneration(name) + 1);
|
|
197
|
+
const demand = this._demands.get(name);
|
|
198
|
+
if (demand)
|
|
199
|
+
demand.failures = 0;
|
|
200
|
+
this._retry.reset(name);
|
|
201
|
+
this._scheduler.clear();
|
|
202
|
+
if (this._active?.model === name)
|
|
203
|
+
await this._stopActive(false);
|
|
204
|
+
this._kick();
|
|
205
|
+
}
|
|
206
|
+
async close() {
|
|
207
|
+
this._closed = true;
|
|
208
|
+
this._scheduler.clear();
|
|
209
|
+
for (const timer of this._timers)
|
|
210
|
+
clearTimeout(timer);
|
|
211
|
+
this._timers.clear();
|
|
212
|
+
if (this._configStream?.return)
|
|
213
|
+
await this._configStream.return();
|
|
214
|
+
if (this._agentsStream?.return)
|
|
215
|
+
await this._agentsStream.return();
|
|
216
|
+
if (this._toolConfigsStream?.return)
|
|
217
|
+
await this._toolConfigsStream.return();
|
|
218
|
+
await this._stopActive(false);
|
|
219
|
+
await this._running;
|
|
220
|
+
for (const name of [...this._demands.keys()])
|
|
221
|
+
this._resolveDemand(name);
|
|
222
|
+
}
|
|
223
|
+
_watchConfig() {
|
|
224
|
+
if (this._closed)
|
|
225
|
+
return;
|
|
226
|
+
const run = async () => {
|
|
227
|
+
const stream = this._engine.configWatchTyped({});
|
|
228
|
+
this._configStream = stream[Symbol.asyncIterator]();
|
|
229
|
+
while (true) {
|
|
230
|
+
const { value, done } = await this._configStream.next();
|
|
231
|
+
if (done || this._closed)
|
|
232
|
+
return;
|
|
233
|
+
this._config = value;
|
|
234
|
+
this._syncToolConfigsWatch();
|
|
235
|
+
this._kick();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
run().catch((err) => this._restartWatch('config', err, () => this._watchConfig()));
|
|
239
|
+
}
|
|
240
|
+
_syncToolConfigsWatch() {
|
|
241
|
+
const agentId = this._config?.activeAgentId ?? null;
|
|
242
|
+
if (agentId === this._toolConfigsAgentId)
|
|
243
|
+
return;
|
|
244
|
+
const previous = this._toolConfigsStream;
|
|
245
|
+
this._toolConfigsStream = null;
|
|
246
|
+
this._toolConfigsAgentId = null;
|
|
247
|
+
if (previous?.return)
|
|
248
|
+
void previous.return().catch(() => { });
|
|
249
|
+
if (agentId)
|
|
250
|
+
this._watchToolConfigs(agentId);
|
|
251
|
+
}
|
|
252
|
+
_watchToolConfigs(agentId) {
|
|
253
|
+
if (this._closed)
|
|
254
|
+
return;
|
|
255
|
+
this._toolConfigsAgentId = agentId;
|
|
256
|
+
let active = null;
|
|
257
|
+
const run = async () => {
|
|
258
|
+
const stream = this._engine.toolConfigsWatch({ agentId });
|
|
259
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
260
|
+
active = iterator;
|
|
261
|
+
this._toolConfigsStream = iterator;
|
|
262
|
+
while (true) {
|
|
263
|
+
const { done } = await iterator.next();
|
|
264
|
+
if (done || this._closed || this._toolConfigsStream !== iterator)
|
|
265
|
+
return;
|
|
266
|
+
this._kick();
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
run().catch((err) => {
|
|
270
|
+
if (active && this._toolConfigsStream !== active)
|
|
271
|
+
return;
|
|
272
|
+
this._restartWatch('toolConfigs', err, () => {
|
|
273
|
+
if (this._toolConfigsAgentId === agentId)
|
|
274
|
+
this._watchToolConfigs(agentId);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
_watchAgents() {
|
|
279
|
+
if (this._closed)
|
|
280
|
+
return;
|
|
281
|
+
const run = async () => {
|
|
282
|
+
const stream = this._engine.agentsWatch({});
|
|
283
|
+
this._agentsStream = stream[Symbol.asyncIterator]();
|
|
284
|
+
while (true) {
|
|
285
|
+
const { done } = await this._agentsStream.next();
|
|
286
|
+
if (done || this._closed)
|
|
287
|
+
return;
|
|
288
|
+
this._kick();
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
run().catch((err) => this._restartWatch('agents', err, () => this._watchAgents()));
|
|
292
|
+
}
|
|
293
|
+
_restartWatch(name, err, restart) {
|
|
294
|
+
if (this._closed)
|
|
295
|
+
return;
|
|
296
|
+
if (isMeshTransition(err)) {
|
|
297
|
+
this._log?.debug('model-download', `${name} watch reopens on the next mesh`);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
this._log?.error('model-download', `${name} watch failed — restarting`, err);
|
|
301
|
+
}
|
|
302
|
+
this._scheduleRestart(restart);
|
|
303
|
+
}
|
|
304
|
+
_scheduleRestart(restart) {
|
|
305
|
+
const timer = setTimeout(() => {
|
|
306
|
+
this._timers.delete(timer);
|
|
307
|
+
if (this._closed)
|
|
308
|
+
return;
|
|
309
|
+
restart();
|
|
310
|
+
}, this._watchRetryMs);
|
|
311
|
+
unref(timer);
|
|
312
|
+
this._timers.add(timer);
|
|
313
|
+
}
|
|
314
|
+
_kick() {
|
|
315
|
+
if (this._closed || this._paused)
|
|
316
|
+
return;
|
|
317
|
+
this._dirty = true;
|
|
318
|
+
if (this._running)
|
|
319
|
+
return;
|
|
320
|
+
this._running = this._drain().finally(() => {
|
|
321
|
+
this._running = null;
|
|
322
|
+
if (this._dirty)
|
|
323
|
+
this._kick();
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
async _drain() {
|
|
327
|
+
while (this._dirty && !this._closed && !this._paused) {
|
|
328
|
+
this._dirty = false;
|
|
329
|
+
try {
|
|
330
|
+
await this._step();
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
this._log?.warn('model-download', 'reconcile step failed', err);
|
|
334
|
+
if (this._pendingCompletions.size > 0 || this._observedProgress.size > 0) {
|
|
335
|
+
this._scheduler.schedule(this._now() + this._watchRetryMs);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async _step() {
|
|
341
|
+
for (const [name, downloaded] of this._pendingCompletions) {
|
|
342
|
+
await this._completeTransfer(name, { downloaded });
|
|
343
|
+
this._handled.add(name);
|
|
344
|
+
await this._status.clear(name);
|
|
345
|
+
this._resolveDemand(name);
|
|
346
|
+
this._onCacheChanged();
|
|
347
|
+
}
|
|
348
|
+
await this._flushObservedProgress();
|
|
349
|
+
const targets = await this._desired();
|
|
350
|
+
if (this._closed || this._paused)
|
|
351
|
+
return;
|
|
352
|
+
const downloadable = new Map(targets.filter((t) => !t.paused).map((t) => [t.name, t]));
|
|
353
|
+
if (this._active && !downloadable.has(this._active.model)) {
|
|
354
|
+
const stillWanted = targets.some((t) => t.name === this._active?.model);
|
|
355
|
+
await this._stopActive(!stillWanted);
|
|
356
|
+
}
|
|
357
|
+
const now = this._now();
|
|
358
|
+
this._scheduleNextRetry(downloadable, now);
|
|
359
|
+
const preferred = this._nextTarget(downloadable, now);
|
|
360
|
+
if (this._runModels.size === 0) {
|
|
361
|
+
const preemptLlm = this._preemptLlm;
|
|
362
|
+
this._preemptLlm = null;
|
|
363
|
+
if (this._shouldPreempt(preferred, preemptLlm))
|
|
364
|
+
await this._stopActive(false);
|
|
365
|
+
}
|
|
366
|
+
const next = this._active ? null : preferred;
|
|
367
|
+
await this._writeWaiting(targets, next?.name, now);
|
|
368
|
+
if (next && !this._closed && !this._paused)
|
|
369
|
+
this._begin(next);
|
|
370
|
+
}
|
|
371
|
+
async _writeWaiting(targets, nextName, now) {
|
|
372
|
+
for (const target of targets) {
|
|
373
|
+
if (target.paused) {
|
|
374
|
+
await this._status.write(target.name, 'paused', { bytesPerSecond: 0 });
|
|
375
|
+
}
|
|
376
|
+
else if (this._waiting(target.name, nextName, now)) {
|
|
377
|
+
await this._status.write(target.name, 'queued', {
|
|
378
|
+
total: target.total,
|
|
379
|
+
bytesPerSecond: 0
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async _flushObservedProgress() {
|
|
385
|
+
for (const [model, progress] of this._observedProgress) {
|
|
386
|
+
await this._transfer(model);
|
|
387
|
+
const expectedTotal = this._targetTotals.get(model) ?? progress.total;
|
|
388
|
+
if (progress.phase === 'complete') {
|
|
389
|
+
await this._completeTransfer(model);
|
|
390
|
+
this._observedTransfers.delete(model);
|
|
391
|
+
if (this._observedProgress.get(model) === progress)
|
|
392
|
+
this._observedProgress.delete(model);
|
|
393
|
+
this._handled.add(model);
|
|
394
|
+
this._retry.reset(model);
|
|
395
|
+
this._observedSpeed.delete(model);
|
|
396
|
+
await this._status.clear(model);
|
|
397
|
+
this._resolveDemand(model);
|
|
398
|
+
this._onCacheChanged();
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
await this._engine.beginModelTransfer({ name: model, transferred: true });
|
|
402
|
+
if (this._observedProgress.get(model) === progress)
|
|
403
|
+
this._observedProgress.delete(model);
|
|
404
|
+
const total = progress.total > 0 ? progress.total : expectedTotal;
|
|
405
|
+
const downloaded = total > 0 ? Math.min(progress.downloaded, total) : progress.downloaded;
|
|
406
|
+
let speed = this._observedSpeed.get(model);
|
|
407
|
+
if (!speed) {
|
|
408
|
+
speed = new DownloadSpeedSampler();
|
|
409
|
+
this._observedSpeed.set(model, speed);
|
|
410
|
+
}
|
|
411
|
+
await this._status.write(model, 'downloading', {
|
|
412
|
+
percentage: progress.percentage,
|
|
413
|
+
downloaded,
|
|
414
|
+
total,
|
|
415
|
+
bytesPerSecond: speed.sample({ downloaded, total, aggregate: true }, progress.at, model)
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
_shouldPreempt(preferred, preemptLlm) {
|
|
420
|
+
if (preferred !== null &&
|
|
421
|
+
this._demands.has(preferred.name) &&
|
|
422
|
+
this._active !== null &&
|
|
423
|
+
this._active.model !== preferred.name) {
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
return (preemptLlm !== null &&
|
|
427
|
+
this._active !== null &&
|
|
428
|
+
this._active.addon !== 'llm' &&
|
|
429
|
+
preferred?.addon === 'llm' &&
|
|
430
|
+
preferred.name === preemptLlm);
|
|
431
|
+
}
|
|
432
|
+
_waiting(name, nextName, now) {
|
|
433
|
+
return (this._active?.model !== name &&
|
|
434
|
+
nextName !== name &&
|
|
435
|
+
!this._handled.has(name) &&
|
|
436
|
+
this._retry.ready(name, now));
|
|
437
|
+
}
|
|
438
|
+
_nextTarget(downloadable, now) {
|
|
439
|
+
for (const target of downloadable.values()) {
|
|
440
|
+
if (this._handled.has(target.name))
|
|
441
|
+
continue;
|
|
442
|
+
if (!this._retry.ready(target.name, now))
|
|
443
|
+
continue;
|
|
444
|
+
return target;
|
|
445
|
+
}
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
_scheduleNextRetry(downloadable, now) {
|
|
449
|
+
this._scheduler.clear();
|
|
450
|
+
const deadline = this._retry.nextDeadline(new Set(downloadable.keys()), now);
|
|
451
|
+
if (deadline !== null)
|
|
452
|
+
this._scheduler.schedule(deadline);
|
|
453
|
+
}
|
|
454
|
+
async _desired() {
|
|
455
|
+
if (this._demands.size === 0 &&
|
|
456
|
+
this._handled.size === 0 &&
|
|
457
|
+
!this._config?.onboardingCompleted) {
|
|
458
|
+
await this._status.clearUnwanted(new Set());
|
|
459
|
+
this._targetTotals.clear();
|
|
460
|
+
this._observedProgress.clear();
|
|
461
|
+
this._observedSpeed.clear();
|
|
462
|
+
return [];
|
|
463
|
+
}
|
|
464
|
+
const availability = await this._modelAvailability();
|
|
465
|
+
for (const name of availability.cached)
|
|
466
|
+
this._handled.delete(name);
|
|
467
|
+
const paused = new Set(this._config?.pausedModels ?? []);
|
|
468
|
+
const wanted = new Map();
|
|
469
|
+
for (const [name, demand] of this._demands) {
|
|
470
|
+
wanted.set(name, { name, addon: demand.addon, paused: paused.has(name) });
|
|
471
|
+
}
|
|
472
|
+
if (this._config?.onboardingCompleted) {
|
|
473
|
+
await this._refreshLocalAgentModels();
|
|
474
|
+
const profile = await this._deviceProfile();
|
|
475
|
+
const infra = (await this._harness.infraModels?.(profile)) ?? [];
|
|
476
|
+
const localLlm = this._localLlm;
|
|
477
|
+
if (localLlm !== null && this._pausedLocalLlm === localLlm && !paused.has(localLlm)) {
|
|
478
|
+
this._preemptLlm = localLlm;
|
|
479
|
+
}
|
|
480
|
+
this._pausedLocalLlm = localLlm !== null && paused.has(localLlm) ? localLlm : null;
|
|
481
|
+
if (localLlm && !wanted.has(localLlm)) {
|
|
482
|
+
wanted.set(localLlm, { name: localLlm, addon: 'llm', paused: paused.has(localLlm) });
|
|
483
|
+
}
|
|
484
|
+
for (const model of [...this._localSkillModels, ...infra]) {
|
|
485
|
+
if (!wanted.has(model.name)) {
|
|
486
|
+
wanted.set(model.name, { ...model, paused: paused.has(model.name) });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
for (const name of this._requestedModels) {
|
|
491
|
+
if (wanted.has(name))
|
|
492
|
+
continue;
|
|
493
|
+
const addon = availability.addons.get(name);
|
|
494
|
+
if (addon === undefined)
|
|
495
|
+
continue;
|
|
496
|
+
wanted.set(name, { name, addon, paused: paused.has(name) });
|
|
497
|
+
}
|
|
498
|
+
const wantedNames = new Set(wanted.keys());
|
|
499
|
+
for (const name of this._attemptGenerations.keys()) {
|
|
500
|
+
if (!wantedNames.has(name))
|
|
501
|
+
this._attemptGenerations.delete(name);
|
|
502
|
+
}
|
|
503
|
+
this._retry.retain(wantedNames);
|
|
504
|
+
await this._status.clearUnwanted(wantedNames);
|
|
505
|
+
const pending = [];
|
|
506
|
+
for (const model of wanted.values()) {
|
|
507
|
+
if (availability.cached.has(model.name)) {
|
|
508
|
+
this._requestedModels.delete(model.name);
|
|
509
|
+
this._resolveDemand(model.name);
|
|
510
|
+
await this._status.clear(model.name);
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
pending.push({
|
|
514
|
+
...model,
|
|
515
|
+
total: availability.totals.get(model.name) ?? 0
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
const pendingNames = new Set(pending.map((target) => target.name));
|
|
519
|
+
for (const target of pending)
|
|
520
|
+
this._targetTotals.set(target.name, target.total);
|
|
521
|
+
for (const name of this._targetTotals.keys()) {
|
|
522
|
+
if (pendingNames.has(name))
|
|
523
|
+
continue;
|
|
524
|
+
this._targetTotals.delete(name);
|
|
525
|
+
this._observedProgress.delete(name);
|
|
526
|
+
this._observedSpeed.delete(name);
|
|
527
|
+
}
|
|
528
|
+
return pending;
|
|
529
|
+
}
|
|
530
|
+
async _modelAvailability() {
|
|
531
|
+
const rows = (await this._harness.list?.({}).catch(() => [])) ?? [];
|
|
532
|
+
const cached = new Set(rows.filter((row) => row.isCached).map((row) => row.name));
|
|
533
|
+
const addons = new Map(rows.map((row) => [row.name, row.type]));
|
|
534
|
+
const totals = new Map(rows.map((row) => [
|
|
535
|
+
row.name,
|
|
536
|
+
typeof row.expectedSize === 'number' && row.expectedSize > 0
|
|
537
|
+
? Math.floor(row.expectedSize)
|
|
538
|
+
: 0
|
|
539
|
+
]));
|
|
540
|
+
return { cached, totals, addons };
|
|
541
|
+
}
|
|
542
|
+
async _deviceProfile() {
|
|
543
|
+
if (this._profile)
|
|
544
|
+
return this._profile;
|
|
545
|
+
const { devices } = await this._engine.listDevices({}).catch(() => ({ devices: [] }));
|
|
546
|
+
const self = (devices ?? []).find((device) => device.id.equals(this._deviceId));
|
|
547
|
+
if (self)
|
|
548
|
+
this._profile = self.capabilityProfile;
|
|
549
|
+
return this._profile ?? 'mid';
|
|
550
|
+
}
|
|
551
|
+
async _hostCapability() {
|
|
552
|
+
if (this._capability)
|
|
553
|
+
return this._capability;
|
|
554
|
+
try {
|
|
555
|
+
const probed = await this._harness.capability?.();
|
|
556
|
+
if (!probed?.recommendedModelName)
|
|
557
|
+
return null;
|
|
558
|
+
this._capability = probed;
|
|
559
|
+
return probed;
|
|
560
|
+
}
|
|
561
|
+
catch (err) {
|
|
562
|
+
this._log?.warn('model-download', 'capability probe failed', err);
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
async _refreshLocalAgentModels() {
|
|
567
|
+
const activeAgentId = this._config?.activeAgentId;
|
|
568
|
+
if (!activeAgentId)
|
|
569
|
+
return;
|
|
570
|
+
const agent = await this._engine.getAgent({ id: activeAgentId }).catch(() => null);
|
|
571
|
+
if (!agent?.modelName)
|
|
572
|
+
return;
|
|
573
|
+
if (!agent.providerDeviceId?.equals(this._deviceId))
|
|
574
|
+
return;
|
|
575
|
+
const model = runnableModelName(agent.modelName, await this._hostCapability(), this._mobileClass);
|
|
576
|
+
const music = await this._musicModelChoice(activeAgentId);
|
|
577
|
+
if (this._config?.activeAgentId !== activeAgentId)
|
|
578
|
+
return;
|
|
579
|
+
if (model !== agent.modelName) {
|
|
580
|
+
this._log?.warn('model-download', 'model clamped to what this device can run', {
|
|
581
|
+
requested: agent.modelName,
|
|
582
|
+
model
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
if (model !== this._localLlm)
|
|
586
|
+
this._preemptLlm = model;
|
|
587
|
+
this._localLlm = model;
|
|
588
|
+
if (music.ok)
|
|
589
|
+
this._musicChoice = music.choice;
|
|
590
|
+
this._localSkillModels = skillModelsForAgent({ ...agent, musicModelChoice: this._musicChoice });
|
|
591
|
+
}
|
|
592
|
+
async _musicModelChoice(agentId) {
|
|
593
|
+
const configs = await this._engine
|
|
594
|
+
.listToolConfigs({ agentId })
|
|
595
|
+
.then((result) => result.configs ?? [])
|
|
596
|
+
.catch(() => null);
|
|
597
|
+
if (configs === null)
|
|
598
|
+
return { ok: false };
|
|
599
|
+
const row = configs.find((entry) => entry?.toolName === GENERATE_MUSIC_TOOL);
|
|
600
|
+
const settings = row?.settings;
|
|
601
|
+
if (!settings || typeof settings !== 'object')
|
|
602
|
+
return { ok: true, choice: undefined };
|
|
603
|
+
const choice = settings.modelChoice;
|
|
604
|
+
return {
|
|
605
|
+
ok: true,
|
|
606
|
+
choice: typeof choice === 'string' &&
|
|
607
|
+
MUSIC_MODEL_CHOICES.includes(choice)
|
|
608
|
+
? choice
|
|
609
|
+
: undefined
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
_begin({ name, addon, total }) {
|
|
613
|
+
const controller = new AbortController();
|
|
614
|
+
const done = this._download(name, addon, total, controller, this._attemptGeneration(name));
|
|
615
|
+
this._active = { model: name, addon, total, controller, done };
|
|
616
|
+
}
|
|
617
|
+
_removeDemandWaiter(model, waiter) {
|
|
618
|
+
const demand = this._demands.get(model);
|
|
619
|
+
if (!demand)
|
|
620
|
+
return;
|
|
621
|
+
demand.waiters.delete(waiter);
|
|
622
|
+
waiter.signal.removeEventListener('abort', waiter.abort);
|
|
623
|
+
if (demand.waiters.size === 0)
|
|
624
|
+
this._demands.delete(model);
|
|
625
|
+
this._kick();
|
|
626
|
+
}
|
|
627
|
+
_resolveDemand(model) {
|
|
628
|
+
const demand = this._demands.get(model);
|
|
629
|
+
if (!demand)
|
|
630
|
+
return;
|
|
631
|
+
this._demands.delete(model);
|
|
632
|
+
for (const waiter of demand.waiters) {
|
|
633
|
+
waiter.signal.removeEventListener('abort', waiter.abort);
|
|
634
|
+
waiter.resolve();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
_failDemand(model, message) {
|
|
638
|
+
const demand = this._demands.get(model);
|
|
639
|
+
if (!demand)
|
|
640
|
+
return;
|
|
641
|
+
demand.failures += 1;
|
|
642
|
+
if (demand.failures < MAX_DEMAND_FAILURES)
|
|
643
|
+
return;
|
|
644
|
+
this._demands.delete(model);
|
|
645
|
+
for (const waiter of demand.waiters) {
|
|
646
|
+
waiter.signal.removeEventListener('abort', waiter.abort);
|
|
647
|
+
waiter.reject(new Error(message));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
_attemptGeneration(name) {
|
|
651
|
+
return this._attemptGenerations.get(name) ?? 0;
|
|
652
|
+
}
|
|
653
|
+
async _stopActive(clear) {
|
|
654
|
+
const active = this._active;
|
|
655
|
+
if (!active)
|
|
656
|
+
return;
|
|
657
|
+
this._active = null;
|
|
658
|
+
active.controller.abort('model-download superseded');
|
|
659
|
+
await active.done;
|
|
660
|
+
if (clear)
|
|
661
|
+
await this._status.clear(active.model);
|
|
662
|
+
}
|
|
663
|
+
async _download(model, addon, expectedTotal, controller, attemptGeneration) {
|
|
664
|
+
const current = () => this._active?.controller === controller;
|
|
665
|
+
const speed = new DownloadSpeedSampler();
|
|
666
|
+
let localFlush = null;
|
|
667
|
+
let hasTransfer = false;
|
|
668
|
+
let recordedTransfer = false;
|
|
669
|
+
let retry = false;
|
|
670
|
+
let completed = false;
|
|
671
|
+
let failureMessage = 'model download failed';
|
|
672
|
+
try {
|
|
673
|
+
if (this._completedTransfers.delete(model))
|
|
674
|
+
this._transfers.delete(model);
|
|
675
|
+
await this._transfer(model);
|
|
676
|
+
if (controller.signal.aborted || !current())
|
|
677
|
+
return;
|
|
678
|
+
const initialPercentage = 0;
|
|
679
|
+
const initialAt = this._now();
|
|
680
|
+
if (await this._status.write(model, 'downloading', {
|
|
681
|
+
percentage: 0,
|
|
682
|
+
downloaded: 0,
|
|
683
|
+
total: expectedTotal,
|
|
684
|
+
bytesPerSecond: 0
|
|
685
|
+
})) {
|
|
686
|
+
localFlush = { at: initialAt, percentage: initialPercentage };
|
|
687
|
+
}
|
|
688
|
+
for await (const event of this._harness.download({
|
|
689
|
+
model,
|
|
690
|
+
addon,
|
|
691
|
+
signal: controller.signal
|
|
692
|
+
})) {
|
|
693
|
+
if (this._closed || !current())
|
|
694
|
+
return;
|
|
695
|
+
if (event.type === 'progress') {
|
|
696
|
+
const at = this._now();
|
|
697
|
+
const transfer = transferProgress(event);
|
|
698
|
+
if (!recordedTransfer &&
|
|
699
|
+
(event.transferred === true ||
|
|
700
|
+
(event.transferred === undefined && transfer && transfer.percentage < 100))) {
|
|
701
|
+
await this._engine.beginModelTransfer({ name: model, transferred: true });
|
|
702
|
+
recordedTransfer = true;
|
|
703
|
+
}
|
|
704
|
+
if (hasTransfer && isEmptyTick(transfer))
|
|
705
|
+
continue;
|
|
706
|
+
const bytes = transfer ?? progressBytes(event);
|
|
707
|
+
const percentage = transfer?.percentage ?? 0;
|
|
708
|
+
if (shouldFlush(localFlush, percentage, at, LOCAL_PROGRESS_INTERVAL_MS, LOCAL_PROGRESS_PERCENTAGE_STEP)) {
|
|
709
|
+
const written = await this._status.write(model, 'downloading', {
|
|
710
|
+
percentage,
|
|
711
|
+
downloaded: bytes.downloaded,
|
|
712
|
+
total: bytes.total,
|
|
713
|
+
bytesPerSecond: speed.sample(bytes, at, event.downloadKey)
|
|
714
|
+
});
|
|
715
|
+
if (written) {
|
|
716
|
+
localFlush = { at, percentage };
|
|
717
|
+
hasTransfer ||= !isEmptyTick(transfer);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
else if (event.type === 'complete') {
|
|
722
|
+
if (controller.signal.aborted)
|
|
723
|
+
return;
|
|
724
|
+
await this._completeTransfer(model, { downloaded: event.downloaded !== false });
|
|
725
|
+
completed = true;
|
|
726
|
+
retry = false;
|
|
727
|
+
this._handled.add(model);
|
|
728
|
+
this._retry.reset(model);
|
|
729
|
+
await this._status.clear(model);
|
|
730
|
+
this._resolveDemand(model);
|
|
731
|
+
this._onCacheChanged();
|
|
732
|
+
}
|
|
733
|
+
else if (event.type === 'error' && current()) {
|
|
734
|
+
retry = true;
|
|
735
|
+
failureMessage = typeof event.message === 'string' ? event.message : 'download failed';
|
|
736
|
+
await this._status.write(model, 'error', {
|
|
737
|
+
error: failureMessage,
|
|
738
|
+
bytesPerSecond: 0
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
else if (event.type === 'aborted' && current() && !controller.signal.aborted) {
|
|
742
|
+
retry = true;
|
|
743
|
+
failureMessage = 'download interrupted';
|
|
744
|
+
await this._status.write(model, 'error', {
|
|
745
|
+
error: failureMessage,
|
|
746
|
+
bytesPerSecond: 0
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (current() && !controller.signal.aborted && !completed && !retry)
|
|
751
|
+
retry = true;
|
|
752
|
+
}
|
|
753
|
+
catch (err) {
|
|
754
|
+
if (!this._closed && current()) {
|
|
755
|
+
retry = true;
|
|
756
|
+
failureMessage = err instanceof Error ? err.message : String(err);
|
|
757
|
+
await this._status.write(model, 'error', {
|
|
758
|
+
error: failureMessage,
|
|
759
|
+
bytesPerSecond: 0
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
finally {
|
|
764
|
+
const wasCurrent = current();
|
|
765
|
+
if (wasCurrent)
|
|
766
|
+
this._active = null;
|
|
767
|
+
if (retry &&
|
|
768
|
+
!this._closed &&
|
|
769
|
+
!this._paused &&
|
|
770
|
+
attemptGeneration === this._attemptGeneration(model)) {
|
|
771
|
+
this._failDemand(model, failureMessage);
|
|
772
|
+
this._scheduler.schedule(this._retry.fail(model, this._now()));
|
|
773
|
+
}
|
|
774
|
+
if (!this._closed && !this._paused && wasCurrent)
|
|
775
|
+
this._kick();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function isEmptyTick(transfer) {
|
|
780
|
+
return (transfer === null ||
|
|
781
|
+
(transfer.percentage === 0 && transfer.downloaded === 0 && transfer.total === 0));
|
|
782
|
+
}
|
|
783
|
+
function shouldFlush(previous, percentage, at, intervalMs, percentageStep) {
|
|
784
|
+
return (previous === null ||
|
|
785
|
+
at - previous.at >= intervalMs ||
|
|
786
|
+
percentage - previous.percentage >= percentageStep);
|
|
787
|
+
}
|