@qvac/core 0.4.1 → 0.6.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/CHANGELOG.md +262 -1
- package/README.md +1 -1
- package/dist-lib/lib/api/agents.js +3 -2
- package/dist-lib/lib/api/app-config.d.ts +1 -1
- package/dist-lib/lib/api/app-config.js +54 -15
- package/dist-lib/lib/api/attachments.d.ts +6 -5
- package/dist-lib/lib/api/attachments.js +4 -2
- package/dist-lib/lib/api/chat.d.ts +7 -3
- package/dist-lib/lib/api/chat.js +4 -4
- package/dist-lib/lib/api/chunks.js +3 -3
- package/dist-lib/lib/api/config.js +2 -2
- package/dist-lib/lib/api/current-mesh.d.ts +3 -4
- package/dist-lib/lib/api/current-mesh.js +9 -4
- package/dist-lib/lib/api/custom-models.d.ts +8 -1
- package/dist-lib/lib/api/custom-models.js +53 -16
- package/dist-lib/lib/api/devices.d.ts +14 -5
- package/dist-lib/lib/api/devices.js +14 -9
- package/dist-lib/lib/api/diagnostics.d.ts +1 -0
- package/dist-lib/lib/api/diagnostics.js +1 -1
- package/dist-lib/lib/api/effective-ctx-size.d.ts +6 -1
- package/dist-lib/lib/api/effective-ctx-size.js +5 -3
- package/dist-lib/lib/api/execution.js +9 -2
- package/dist-lib/lib/api/files.js +2 -1
- package/dist-lib/lib/api/index.d.ts +7 -1
- package/dist-lib/lib/api/index.js +101 -101
- package/dist-lib/lib/api/instrument.js +29 -20
- package/dist-lib/lib/api/knowledge.d.ts +6 -5
- package/dist-lib/lib/api/knowledge.js +8 -6
- package/dist-lib/lib/api/local-files.js +1 -1
- package/dist-lib/lib/api/logs.js +6 -3
- package/dist-lib/lib/api/members.js +22 -13
- package/dist-lib/lib/api/mesh.d.ts +7 -2
- package/dist-lib/lib/api/mesh.js +10 -5
- package/dist-lib/lib/api/model-download.js +1 -1
- package/dist-lib/lib/api/network.d.ts +1 -0
- package/dist-lib/lib/api/network.js +1 -1
- package/dist-lib/lib/api/notifications.js +23 -13
- package/dist-lib/lib/api/rag.d.ts +6 -1
- package/dist-lib/lib/api/rag.js +20 -11
- package/dist-lib/lib/api/range.d.ts +2 -2
- package/dist-lib/lib/api/sync.js +1 -1
- package/dist-lib/lib/api/tool-activity.js +7 -3
- package/dist-lib/lib/api/tool-configs.js +2 -4
- package/dist-lib/lib/api/upload-frames.d.ts +7 -8
- package/dist-lib/lib/api/upload-frames.js +2 -1
- package/dist-lib/lib/api/watchable.d.ts +6 -1
- package/dist-lib/lib/api/watchable.js +23 -14
- package/dist-lib/lib/assistant/fetch-body.js +4 -2
- package/dist-lib/lib/assistant/harness.d.ts +72 -24
- package/dist-lib/lib/assistant/harness.js +53 -15
- package/dist-lib/lib/assistant/history.d.ts +9 -7
- package/dist-lib/lib/assistant/history.js +77 -42
- package/dist-lib/lib/assistant/message.d.ts +5 -3
- package/dist-lib/lib/assistant/message.js +4 -2
- package/dist-lib/lib/assistant/skill-encode.d.ts +3 -1
- package/dist-lib/lib/assistant/skill-encode.js +52 -62
- package/dist-lib/lib/assistant-client.js +7 -4
- package/dist-lib/lib/assistant-tree.js +36 -11
- package/dist-lib/lib/assistant.d.ts +37 -12
- package/dist-lib/lib/assistant.js +977 -373
- package/dist-lib/lib/audio-format.d.ts +1 -1
- package/dist-lib/lib/audio-format.js +1 -1
- package/dist-lib/lib/chat-title.js +9 -4
- package/dist-lib/lib/client.js +3 -2
- package/dist-lib/lib/collabora/convert.d.ts +2 -2
- package/dist-lib/lib/collabora/convert.js +6 -3
- package/dist-lib/lib/collabora/entry.js +9 -5
- package/dist-lib/lib/collabora/protocol.d.ts +2 -2
- package/dist-lib/lib/collabora/protocol.js +14 -7
- package/dist-lib/lib/collabora/worker.js +14 -7
- package/dist-lib/lib/compaction.d.ts +5 -6
- package/dist-lib/lib/compaction.js +14 -7
- package/dist-lib/lib/constants.d.ts +2 -0
- package/dist-lib/lib/constants.js +4 -0
- package/dist-lib/lib/core/account-recovery.d.ts +4 -3
- package/dist-lib/lib/core/account-recovery.js +7 -4
- package/dist-lib/lib/core/agent.d.ts +0 -1
- package/dist-lib/lib/core/agent.js +18 -16
- package/dist-lib/lib/core/approval-rules.d.ts +7 -6
- package/dist-lib/lib/core/approval-rules.js +12 -6
- package/dist-lib/lib/core/archived-mesh.d.ts +7 -5
- package/dist-lib/lib/core/archived-mesh.js +25 -22
- package/dist-lib/lib/core/async-iterable.js +10 -5
- package/dist-lib/lib/core/attachment-link.d.ts +2 -2
- package/dist-lib/lib/core/audio-attachment.js +1 -1
- package/dist-lib/lib/core/blind-peers.d.ts +2 -2
- package/dist-lib/lib/core/chat-activity.d.ts +2 -2
- package/dist-lib/lib/core/chat-activity.js +42 -21
- package/dist-lib/lib/core/chat-group.d.ts +8 -6
- package/dist-lib/lib/core/chat-group.js +17 -10
- package/dist-lib/lib/core/chat-order.d.ts +11 -9
- package/dist-lib/lib/core/chat-order.js +1 -3
- package/dist-lib/lib/core/chat-search.d.ts +4 -4
- package/dist-lib/lib/core/chat-search.js +38 -24
- package/dist-lib/lib/core/chat.d.ts +20 -14
- package/dist-lib/lib/core/chat.js +42 -28
- package/dist-lib/lib/core/chunk.d.ts +20 -24
- package/dist-lib/lib/core/chunk.js +34 -22
- package/dist-lib/lib/core/collections.d.ts +69 -0
- package/dist-lib/lib/core/collections.js +69 -0
- package/dist-lib/lib/core/contract/activity.d.ts +8 -2
- package/dist-lib/lib/core/contract/activity.js +39 -11
- package/dist-lib/lib/core/contract/agents.js +3 -2
- package/dist-lib/lib/core/contract/approval-rules.js +1 -1
- package/dist-lib/lib/core/contract/attestations.js +1 -1
- package/dist-lib/lib/core/contract/chat-group.js +1 -1
- package/dist-lib/lib/core/contract/chat.js +1 -1
- package/dist-lib/lib/core/contract/chunks.js +16 -9
- package/dist-lib/lib/core/contract/compute.js +2 -1
- package/dist-lib/lib/core/contract/devices.js +10 -6
- package/dist-lib/lib/core/contract/grant-order.d.ts +5 -0
- package/dist-lib/lib/core/contract/grant-order.js +20 -0
- package/dist-lib/lib/core/contract/index.d.ts +1 -1
- package/dist-lib/lib/core/contract/index.js +27 -2
- package/dist-lib/lib/core/contract/indexing.js +3 -3
- package/dist-lib/lib/core/contract/invites.d.ts +16 -0
- package/dist-lib/lib/core/contract/invites.js +256 -0
- package/dist-lib/lib/core/contract/joined-meshes.js +22 -22
- package/dist-lib/lib/core/contract/knowledge.js +5 -5
- package/dist-lib/lib/core/contract/members.d.ts +15 -0
- package/dist-lib/lib/core/contract/members.js +116 -31
- package/dist-lib/lib/core/contract/mesh-kind.d.ts +6 -0
- package/dist-lib/lib/core/contract/mesh-kind.js +49 -0
- package/dist-lib/lib/core/contract/seal.js +1 -1
- package/dist-lib/lib/core/contract/seed-defaults.js +1 -3
- package/dist-lib/lib/core/contract/tool-activity.js +5 -5
- package/dist-lib/lib/core/contract/tool-configs.js +1 -2
- package/dist-lib/lib/core/contract/writers.d.ts +13 -0
- package/dist-lib/lib/core/contract/writers.js +181 -24
- package/dist-lib/lib/core/departures.js +16 -8
- package/dist-lib/lib/core/device-attestation.d.ts +5 -0
- package/dist-lib/lib/core/device-attestation.js +24 -0
- package/dist-lib/lib/core/device-invites.d.ts +2 -0
- package/dist-lib/lib/core/device-invites.js +29 -7
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +52 -2
- package/dist-lib/lib/core/document-attachment.d.ts +20 -11
- package/dist-lib/lib/core/document-attachment.js +10 -5
- package/dist-lib/lib/core/files/attachments.d.ts +2 -5
- package/dist-lib/lib/core/files/attachments.js +6 -3
- package/dist-lib/lib/core/files/index.d.ts +44 -52
- package/dist-lib/lib/core/files/index.js +142 -93
- package/dist-lib/lib/core/files/knowledge.d.ts +2 -5
- package/dist-lib/lib/core/files/local-index.js +9 -5
- package/dist-lib/lib/core/files/preview/image.d.ts +0 -1
- package/dist-lib/lib/core/files/preview/image.js +9 -6
- package/dist-lib/lib/core/files/preview/index.d.ts +8 -11
- package/dist-lib/lib/core/files/preview/index.js +20 -15
- package/dist-lib/lib/core/files/processing/claims.d.ts +6 -5
- package/dist-lib/lib/core/files/processing/claims.js +16 -8
- package/dist-lib/lib/core/files/processing/document.d.ts +21 -50
- package/dist-lib/lib/core/files/processing/index.d.ts +18 -13
- package/dist-lib/lib/core/files/processing/index.js +65 -37
- package/dist-lib/lib/core/files/processing/ownership.d.ts +8 -1
- package/dist-lib/lib/core/files/processing/ownership.js +1 -1
- package/dist-lib/lib/core/files/processing/protocol.d.ts +19 -19
- package/dist-lib/lib/core/files/processing/protocol.js +5 -5
- package/dist-lib/lib/core/files/processing/settle.d.ts +10 -7
- package/dist-lib/lib/core/files/processing/settle.js +22 -11
- package/dist-lib/lib/core/files/processing/source.js +14 -8
- package/dist-lib/lib/core/files/processing/state.d.ts +13 -11
- package/dist-lib/lib/core/files/processing/state.js +19 -12
- package/dist-lib/lib/core/files/rag/build.d.ts +2 -2
- package/dist-lib/lib/core/files/rag/build.js +2 -1
- package/dist-lib/lib/core/files/rag/document-types.d.ts +4 -6
- package/dist-lib/lib/core/files/rag/index.d.ts +10 -13
- package/dist-lib/lib/core/files/rag/index.js +3 -2
- package/dist-lib/lib/core/files/rag/load.d.ts +10 -9
- package/dist-lib/lib/core/files/rag/load.js +26 -13
- package/dist-lib/lib/core/files/rag/policy.js +2 -1
- package/dist-lib/lib/core/files/rag/produce.js +33 -19
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +5 -3
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +30 -10
- package/dist-lib/lib/core/files/records/chunks.js +4 -2
- package/dist-lib/lib/core/files/records/knowledge.d.ts +10 -11
- package/dist-lib/lib/core/files/records/knowledge.js +9 -8
- package/dist-lib/lib/core/files/records/linkage.js +6 -3
- package/dist-lib/lib/core/files/records/output.d.ts +5 -4
- package/dist-lib/lib/core/files/records/output.js +8 -4
- package/dist-lib/lib/core/files/records/reclaim.js +41 -25
- package/dist-lib/lib/core/files/records/routing.d.ts +4 -6
- package/dist-lib/lib/core/files/records/routing.js +15 -8
- package/dist-lib/lib/core/files/records/source.d.ts +5 -4
- package/dist-lib/lib/core/files/records/source.js +20 -14
- package/dist-lib/lib/core/files/records/sweep.js +1 -3
- package/dist-lib/lib/core/files/store/blob.d.ts +10 -10
- package/dist-lib/lib/core/files/store/blob.js +25 -19
- package/dist-lib/lib/core/files/store/index.d.ts +1 -6
- package/dist-lib/lib/core/files/store/index.js +4 -4
- package/dist-lib/lib/core/files/store/inline.d.ts +2 -2
- package/dist-lib/lib/core/files/store/inline.js +6 -3
- package/dist-lib/lib/core/files/store/reference.d.ts +6 -9
- package/dist-lib/lib/core/files/store/reference.js +25 -17
- package/dist-lib/lib/core/files/store/server.d.ts +7 -6
- package/dist-lib/lib/core/files/store/server.js +22 -11
- package/dist-lib/lib/core/files/store/sweep.js +13 -7
- package/dist-lib/lib/core/files/upload-input.d.ts +4 -12
- package/dist-lib/lib/core/files/upload-input.js +10 -5
- package/dist-lib/lib/core/files/upload.d.ts +27 -24
- package/dist-lib/lib/core/files/upload.js +74 -51
- package/dist-lib/lib/core/fs-drives.js +4 -2
- package/dist-lib/lib/core/grant-expiry.d.ts +11 -0
- package/dist-lib/lib/core/grant-expiry.js +66 -0
- package/dist-lib/lib/core/handoff-channel.d.ts +2 -1
- package/dist-lib/lib/core/handoff-channel.js +36 -15
- package/dist-lib/lib/core/harness-loan.js +35 -17
- package/dist-lib/lib/core/helpers/index.d.ts +2 -1
- package/dist-lib/lib/core/helpers/index.js +11 -6
- package/dist-lib/lib/core/hosted-agents.js +19 -12
- package/dist-lib/lib/core/id.js +1 -1
- package/dist-lib/lib/core/identity.d.ts +1 -0
- package/dist-lib/lib/core/identity.js +11 -3
- package/dist-lib/lib/core/image/cache-sweep.d.ts +12 -10
- package/dist-lib/lib/core/image/cache-sweep.js +11 -6
- package/dist-lib/lib/core/image/normalize.d.ts +6 -0
- package/dist-lib/lib/core/image/normalize.js +12 -2
- package/dist-lib/lib/core/image/sniff.js +42 -21
- package/dist-lib/lib/core/inference-calls-receiver.js +7 -4
- package/dist-lib/lib/core/invite-grants.d.ts +20 -0
- package/dist-lib/lib/core/invite-grants.js +46 -0
- package/dist-lib/lib/core/invite.d.ts +3 -0
- package/dist-lib/lib/core/invite.js +6 -3
- package/dist-lib/lib/core/local/files.js +20 -19
- package/dist-lib/lib/core/local/index.d.ts +70 -45
- package/dist-lib/lib/core/local/index.js +157 -126
- package/dist-lib/lib/core/membership.d.ts +15 -2
- package/dist-lib/lib/core/membership.js +95 -20
- package/dist-lib/lib/core/mesh-seed-handoff.d.ts +12 -4
- package/dist-lib/lib/core/mesh-seed-handoff.js +23 -5
- package/dist-lib/lib/core/mesh.d.ts +57 -30
- package/dist-lib/lib/core/mesh.js +232 -78
- package/dist-lib/lib/core/migrations/agent-catalog.js +3 -2
- package/dist-lib/lib/core/migrations/agent-indexes.js +3 -3
- package/dist-lib/lib/core/migrations/device-indexes.d.ts +2 -0
- package/dist-lib/lib/core/migrations/device-indexes.js +7 -0
- package/dist-lib/lib/core/migrations/file-index.js +7 -4
- package/dist-lib/lib/core/migrations/index.d.ts +4 -3
- package/dist-lib/lib/core/migrations/index.js +3 -1
- package/dist-lib/lib/core/migrations/membership.js +9 -4
- package/dist-lib/lib/core/migrations/seal.js +3 -2
- package/dist-lib/lib/core/min-version.js +4 -2
- package/dist-lib/lib/core/next-frame.d.ts +5 -4
- package/dist-lib/lib/core/next-frame.js +6 -3
- package/dist-lib/lib/core/notification.d.ts +5 -1
- package/dist-lib/lib/core/notification.js +89 -77
- package/dist-lib/lib/core/ota-config.js +2 -1
- package/dist-lib/lib/core/pdf/rasterize.d.ts +18 -0
- package/dist-lib/lib/core/pdf/rasterize.js +57 -0
- package/dist-lib/lib/core/prompt-history.js +4 -2
- package/dist-lib/lib/core/range.d.ts +4 -4
- package/dist-lib/lib/core/range.js +12 -6
- package/dist-lib/lib/core/rank.d.ts +5 -4
- package/dist-lib/lib/core/rank.js +2 -1
- package/dist-lib/lib/core/send.d.ts +8 -5
- package/dist-lib/lib/core/send.js +9 -3
- package/dist-lib/lib/core/skill-overlay-receiver.js +7 -4
- package/dist-lib/lib/core/skill-secrets.js +16 -9
- package/dist-lib/lib/core/sync/chunks.js +2 -1
- package/dist-lib/lib/core/sync/devices.js +3 -1
- package/dist-lib/lib/core/sync/files.d.ts +2 -4
- package/dist-lib/lib/core/sync/files.js +28 -20
- package/dist-lib/lib/core/sync/index.d.ts +2 -5
- package/dist-lib/lib/core/sync/index.js +33 -17
- package/dist-lib/lib/core/sync-status.js +10 -7
- package/dist-lib/lib/core/system-info.js +4 -2
- package/dist-lib/lib/core/tool-activity.d.ts +4 -3
- package/dist-lib/lib/core/tool-activity.js +1 -1
- package/dist-lib/lib/core/tool-configs.js +12 -7
- package/dist-lib/lib/core.d.ts +107 -45
- package/dist-lib/lib/core.js +1765 -595
- package/dist-lib/lib/credential-pusher.d.ts +12 -17
- package/dist-lib/lib/credential-pusher.js +61 -42
- package/dist-lib/lib/custom-model-pusher.d.ts +7 -3
- package/dist-lib/lib/custom-model-pusher.js +15 -7
- package/dist-lib/lib/custom-model-task.d.ts +1 -0
- package/dist-lib/lib/custom-model-task.js +12 -0
- package/dist-lib/lib/deadline.js +4 -2
- package/dist-lib/lib/diagnostics.d.ts +1 -5
- package/dist-lib/lib/frame-readable.d.ts +3 -0
- package/dist-lib/lib/frame-readable.js +3 -0
- package/dist-lib/lib/fs-drive-bridge.js +24 -14
- package/dist-lib/lib/fs-grants.js +13 -8
- package/dist-lib/lib/guards.d.ts +3 -0
- package/dist-lib/lib/guards.js +9 -0
- package/dist-lib/lib/inference-calls.d.ts +28 -23
- package/dist-lib/lib/inference-calls.js +25 -13
- package/dist-lib/lib/integrations/mcp-providers.d.ts +2 -2
- package/dist-lib/lib/integrations/setup-routes.d.ts +2 -2
- package/dist-lib/lib/knowledge-search.d.ts +6 -5
- package/dist-lib/lib/knowledge-search.js +26 -18
- package/dist-lib/lib/kv-cache-reclaim.js +4 -2
- package/dist-lib/lib/kv-cache.js +8 -4
- package/dist-lib/lib/legacy-core-domain.d.ts +42 -42
- package/dist-lib/lib/log-buffer.js +2 -1
- package/dist-lib/lib/log.js +25 -15
- package/dist-lib/lib/mesh-scoped-engine.js +14 -4
- package/dist-lib/lib/model-catalog-revision.js +6 -3
- package/dist-lib/lib/model-clamp.js +6 -3
- package/dist-lib/lib/model-context.d.ts +8 -3
- package/dist-lib/lib/model-context.js +13 -5
- package/dist-lib/lib/model-download-status.js +4 -2
- package/dist-lib/lib/model-download.d.ts +12 -4
- package/dist-lib/lib/model-download.js +200 -103
- package/dist-lib/lib/model-idle-pusher.d.ts +10 -0
- package/dist-lib/lib/model-idle-pusher.js +41 -0
- package/dist-lib/lib/oauth/browser-connect.d.ts +10 -8
- package/dist-lib/lib/oauth/browser-connect.js +33 -20
- package/dist-lib/lib/oauth/client.d.ts +2 -2
- package/dist-lib/lib/oauth/flow-core.js +23 -9
- package/dist-lib/lib/oauth/flow.d.ts +1 -3
- package/dist-lib/lib/oauth/flow.js +9 -5
- package/dist-lib/lib/oauth/keys.d.ts +4 -4
- package/dist-lib/lib/oauth/keys.js +18 -12
- package/dist-lib/lib/oauth/loopback.d.ts +2 -2
- package/dist-lib/lib/oauth/loopback.js +147 -107
- package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
- package/dist-lib/lib/oauth/loopback.stub.js +1 -1
- package/dist-lib/lib/oauth/pkce.d.ts +4 -2
- package/dist-lib/lib/oauth/pkce.js +10 -0
- package/dist-lib/lib/oauth/providers.js +5 -5
- package/dist-lib/lib/oauth/redirect-types.d.ts +12 -7
- package/dist-lib/lib/oauth/register.js +3 -2
- package/dist-lib/lib/oauth/registry.d.ts +2 -2
- package/dist-lib/lib/oauth/registry.js +2 -1
- package/dist-lib/lib/oauth/resolve.d.ts +30 -10
- package/dist-lib/lib/oauth/resolve.js +12 -6
- package/dist-lib/lib/oauth/token-exchange-core.d.ts +12 -4
- package/dist-lib/lib/oauth/token-exchange-core.js +1 -1
- package/dist-lib/lib/oauth/types.d.ts +12 -12
- package/dist-lib/lib/oauth.d.ts +4 -5
- package/dist-lib/lib/oauth.js +2 -3
- package/dist-lib/lib/reconnecting-watch.d.ts +1 -1
- package/dist-lib/lib/reconnecting-watch.js +6 -6
- package/dist-lib/lib/retry-budget.js +6 -3
- package/dist-lib/lib/run-notices.d.ts +2 -0
- package/dist-lib/lib/run-notices.js +7 -3
- package/dist-lib/lib/run-transcript.d.ts +2 -4
- package/dist-lib/lib/run-transcript.js +4 -2
- package/dist-lib/lib/skill-readiness.d.ts +1 -0
- package/dist-lib/lib/skill-readiness.js +17 -2
- package/dist-lib/lib/skill-types.d.ts +16 -16
- package/dist-lib/lib/suspend-lifecycle.d.ts +4 -4
- package/dist-lib/lib/suspend-lifecycle.js +10 -5
- package/dist-lib/lib/task.d.ts +5 -1
- package/dist-lib/lib/task.js +29 -12
- package/dist-lib/lib/unref.d.ts +3 -2
- package/dist-lib/lib/unref.js +2 -1
- package/dist-lib/lib/wav-duration.js +10 -5
- package/dist-lib/lib/write-queue.d.ts +5 -4
- package/dist-lib/lib/write-queue.js +2 -1
- package/dist-lib/schema/build.js +16 -8
- package/dist-lib/schema/config.d.ts +3 -4
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/content.d.ts +18 -2
- package/dist-lib/schema/content.js +4 -1
- package/dist-lib/schema/engine.d.ts +3 -2
- package/dist-lib/schema/engine.js +192 -12
- package/dist-lib/schema/field-order.js +22 -11
- package/dist-lib/schema/indexes.d.ts +22 -0
- package/dist-lib/schema/{helpers.js → indexes.js} +19 -57
- package/dist-lib/schema/local.d.ts +3 -2
- package/dist-lib/schema/local.js +9 -3
- package/dist-lib/schema/media-kind.d.ts +8 -0
- package/dist-lib/schema/media-kind.js +52 -0
- package/dist-lib/schema/qvac.d.ts +12 -9
- package/dist-lib/schema/qvac.js +132 -7
- package/dist-lib/spec/bind.js +21 -0
- package/dist-lib/spec/calls.js +7 -0
- package/dist-lib/spec/capabilities.d.ts +18 -4
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/dist-lib/spec/hrpc/hrpc.json +93 -2
- package/dist-lib/spec/hrpc/index.js +89 -5
- package/dist-lib/spec/hrpc/messages.js +1568 -941
- package/dist-lib/spec/hyperschema/index.js +1568 -941
- package/dist-lib/spec/hyperschema/schema.json +531 -1
- package/dist-lib/spec/hyperschema/types.d.ts +145 -1
- package/dist-lib/spec/local/hyperdb/index.js +1 -1
- package/dist-lib/spec/local/hyperdb/messages.js +92 -20
- package/dist-lib/spec/local/hyperschema/index.js +47 -11
- package/dist-lib/spec/local/hyperschema/schema.json +32 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +7 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +131 -3
- package/dist-lib/spec/mesh/hyperdb/index.js +548 -5
- package/dist-lib/spec/mesh/hyperdb/messages.js +2444 -893
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +37 -1
- package/dist-lib/spec/mesh/hyperdispatch/index.js +104 -2
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +1035 -11
- package/dist-lib/spec/mesh/hyperschema/index.js +1035 -11
- package/dist-lib/spec/mesh/hyperschema/schema.json +553 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +143 -1
- package/package.json +11 -5
- package/tui/app.mjs +2624 -986
- package/tui/boot.mjs +17 -46
- package/tui/index.mjs +10 -5
- package/tui/lib/boot-timing.mjs +8 -8
- package/tui/lib/busy-words.mjs +21 -22
- package/tui/lib/export.mjs +100 -32
- package/tui/lib/knowledge-command.mjs +64 -19
- package/tui/lib/knowledge-import.mjs +52 -18
- package/tui/lib/render.mjs +65 -33
- package/tui/lib/save-file.mjs +30 -13
- package/tui/lib/select.mjs +23 -5
- package/tui/lib/selection.mjs +6 -4
- package/tui/lib/setup.mjs +11 -19
- package/tui/lib/sidebar.mjs +23 -13
- package/tui/lib/splash.mjs +6 -7
- package/tui/lib/upload-frames.mjs +1 -2
- package/tui/lib/usage.mjs +13 -9
- package/tui/lib/wrap.mjs +35 -6
- package/tui/main.mjs +54 -78
- package/worker/assistant-sidecar.mjs +5 -10
- package/worker/stow-entry.mjs +7 -4
- package/dist-lib/lib/custom-model-source.d.ts +0 -15
- package/dist-lib/lib/custom-model-source.js +0 -46
- package/dist-lib/lib/oauth/common.d.ts +0 -38
- package/dist-lib/lib/oauth/common.js +0 -34
- package/dist-lib/schema/helpers.d.ts +0 -32
|
@@ -7,6 +7,8 @@ import { runnableModelName } from './model-clamp.js';
|
|
|
7
7
|
import { ModelDownloadStatus } from './model-download-status.js';
|
|
8
8
|
import { RetryBudget } from './retry-budget.js';
|
|
9
9
|
import { unref } from './unref.js';
|
|
10
|
+
import b4a from 'b4a';
|
|
11
|
+
import { errorMessage } from './guards.js';
|
|
10
12
|
const WATCH_RETRY_MS = 30_000;
|
|
11
13
|
const LOCAL_PROGRESS_INTERVAL_MS = 750;
|
|
12
14
|
const LOCAL_PROGRESS_PERCENTAGE_STEP = 1;
|
|
@@ -32,6 +34,7 @@ export class ModelDownloadReconciler {
|
|
|
32
34
|
_observedProgress = new Map();
|
|
33
35
|
_observedSpeed = new Map();
|
|
34
36
|
_requestedModels = new Set();
|
|
37
|
+
_releasing = new Set();
|
|
35
38
|
_targetTotals = new Map();
|
|
36
39
|
_config = null;
|
|
37
40
|
_active = null;
|
|
@@ -85,7 +88,7 @@ export class ModelDownloadReconciler {
|
|
|
85
88
|
const first = await it.next();
|
|
86
89
|
await it.return?.();
|
|
87
90
|
for (const row of first.value?.downloads ?? []) {
|
|
88
|
-
await this._engine.clearModelDownload({ name: row.name }).catch(
|
|
91
|
+
await this._engine.clearModelDownload({ name: row.name }).catch(noop);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
catch (err) {
|
|
@@ -109,8 +112,9 @@ export class ModelDownloadReconciler {
|
|
|
109
112
|
return;
|
|
110
113
|
const agents = this._agentsStream;
|
|
111
114
|
this._agentsStream = null;
|
|
112
|
-
if (agents?.return)
|
|
113
|
-
void agents.return().catch(
|
|
115
|
+
if (agents?.return) {
|
|
116
|
+
void agents.return().catch(noop);
|
|
117
|
+
}
|
|
114
118
|
this._watchAgents();
|
|
115
119
|
this._swapToolConfigsWatch(this._toolConfigsAgentId);
|
|
116
120
|
this._kick();
|
|
@@ -119,8 +123,9 @@ export class ModelDownloadReconciler {
|
|
|
119
123
|
if (this._closed)
|
|
120
124
|
return;
|
|
121
125
|
const next = new Set(models);
|
|
122
|
-
if (next.size === this._runModels.size && [...next].every((m) => this._runModels.has(m)))
|
|
126
|
+
if (next.size === this._runModels.size && [...next].every((m) => this._runModels.has(m))) {
|
|
123
127
|
return;
|
|
128
|
+
}
|
|
124
129
|
this._runModels = next;
|
|
125
130
|
this._kick();
|
|
126
131
|
}
|
|
@@ -175,13 +180,15 @@ export class ModelDownloadReconciler {
|
|
|
175
180
|
return;
|
|
176
181
|
}
|
|
177
182
|
const rows = await this._harness.list({}).catch(noop);
|
|
178
|
-
if (this._closed || this._handled.has(model) || signal.aborted)
|
|
183
|
+
if (this._closed || this._handled.has(model) || signal.aborted) {
|
|
179
184
|
return;
|
|
185
|
+
}
|
|
180
186
|
let addon = 'llm';
|
|
181
187
|
if (rows) {
|
|
182
188
|
const row = rows.find((entry) => entry.name === model);
|
|
183
|
-
if (!row || row.isCached)
|
|
189
|
+
if (!row || row.isCached) {
|
|
184
190
|
return;
|
|
191
|
+
}
|
|
185
192
|
addon = row.type;
|
|
186
193
|
}
|
|
187
194
|
await new Promise((resolve, reject) => {
|
|
@@ -207,30 +214,57 @@ export class ModelDownloadReconciler {
|
|
|
207
214
|
this._requestedModels.add(name);
|
|
208
215
|
this._attemptGenerations.set(name, this._attemptGeneration(name) + 1);
|
|
209
216
|
const demand = this._demands.get(name);
|
|
210
|
-
if (demand)
|
|
217
|
+
if (demand) {
|
|
211
218
|
demand.failures = 0;
|
|
219
|
+
}
|
|
212
220
|
this._retry.reset(name);
|
|
213
221
|
this._scheduler.clear();
|
|
214
|
-
if (this._active?.model === name)
|
|
222
|
+
if (this._active?.model === name) {
|
|
215
223
|
await this._stopActive(false);
|
|
224
|
+
}
|
|
216
225
|
this._kick();
|
|
217
226
|
}
|
|
227
|
+
async release(name, removeFiles) {
|
|
228
|
+
if (this._closed)
|
|
229
|
+
throw new Error('model download reconciler is closed');
|
|
230
|
+
this._releasing.add(name);
|
|
231
|
+
this._requestedModels.delete(name);
|
|
232
|
+
this._handled.delete(name);
|
|
233
|
+
try {
|
|
234
|
+
if (this._active?.model === name) {
|
|
235
|
+
await this._stopActive(true);
|
|
236
|
+
}
|
|
237
|
+
const result = await removeFiles();
|
|
238
|
+
this._config = await this._engine.setModelReleased({ name, released: true });
|
|
239
|
+
await this._running;
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
this._releasing.delete(name);
|
|
244
|
+
this._kick();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
218
247
|
async close() {
|
|
219
248
|
this._closed = true;
|
|
220
249
|
this._scheduler.clear();
|
|
221
|
-
for (const timer of this._timers)
|
|
250
|
+
for (const timer of this._timers) {
|
|
222
251
|
clearTimeout(timer);
|
|
252
|
+
}
|
|
223
253
|
this._timers.clear();
|
|
224
|
-
if (this._configStream?.return)
|
|
254
|
+
if (this._configStream?.return) {
|
|
225
255
|
await this._configStream.return();
|
|
226
|
-
|
|
256
|
+
}
|
|
257
|
+
if (this._agentsStream?.return) {
|
|
227
258
|
await this._agentsStream.return();
|
|
228
|
-
|
|
259
|
+
}
|
|
260
|
+
if (this._toolConfigsStream?.return) {
|
|
229
261
|
await this._toolConfigsStream.return();
|
|
262
|
+
}
|
|
230
263
|
await this._stopActive(false);
|
|
231
264
|
await this._running;
|
|
232
|
-
for (const name of [...this._demands.keys()])
|
|
265
|
+
for (const name of [...this._demands.keys()]) {
|
|
233
266
|
this._resolveDemand(name);
|
|
267
|
+
}
|
|
234
268
|
}
|
|
235
269
|
_watchConfig() {
|
|
236
270
|
if (this._closed)
|
|
@@ -240,8 +274,9 @@ export class ModelDownloadReconciler {
|
|
|
240
274
|
this._configStream = stream[Symbol.asyncIterator]();
|
|
241
275
|
while (true) {
|
|
242
276
|
const { value, done } = await this._configStream.next();
|
|
243
|
-
if (done || this._closed)
|
|
277
|
+
if (done || this._closed) {
|
|
244
278
|
return;
|
|
279
|
+
}
|
|
245
280
|
this._config = value;
|
|
246
281
|
this._syncToolConfigsWatch();
|
|
247
282
|
this._kick();
|
|
@@ -251,25 +286,29 @@ export class ModelDownloadReconciler {
|
|
|
251
286
|
}
|
|
252
287
|
_syncToolConfigsWatch() {
|
|
253
288
|
const agentId = this._config?.activeAgentId ?? null;
|
|
254
|
-
if (agentId === this._toolConfigsAgentId)
|
|
289
|
+
if (agentId === this._toolConfigsAgentId) {
|
|
255
290
|
return;
|
|
291
|
+
}
|
|
256
292
|
this._swapToolConfigsWatch(agentId);
|
|
257
293
|
}
|
|
258
294
|
_swapToolConfigsWatch(agentId) {
|
|
259
295
|
const previous = this._toolConfigsStream;
|
|
260
296
|
this._toolConfigsStream = null;
|
|
261
297
|
this._toolConfigsAgentId = agentId;
|
|
262
|
-
if (previous?.return)
|
|
263
|
-
void previous.return().catch(
|
|
264
|
-
|
|
298
|
+
if (previous?.return) {
|
|
299
|
+
void previous.return().catch(noop);
|
|
300
|
+
}
|
|
301
|
+
if (agentId) {
|
|
265
302
|
this._watchToolConfigs(agentId);
|
|
303
|
+
}
|
|
266
304
|
}
|
|
267
305
|
_watchToolConfigs(agentId) {
|
|
268
306
|
if (this._closed)
|
|
269
307
|
return;
|
|
270
308
|
const meshId = this._meshId();
|
|
271
|
-
if (!meshId)
|
|
309
|
+
if (!meshId) {
|
|
272
310
|
return;
|
|
311
|
+
}
|
|
273
312
|
let active = null;
|
|
274
313
|
const run = async () => {
|
|
275
314
|
const stream = this._engine.toolConfigsWatch({ agentId, meshId });
|
|
@@ -278,8 +317,9 @@ export class ModelDownloadReconciler {
|
|
|
278
317
|
this._toolConfigsStream = iterator;
|
|
279
318
|
while (true) {
|
|
280
319
|
const { done } = await iterator.next();
|
|
281
|
-
if (done || this._closed || this._toolConfigsStream !== iterator)
|
|
320
|
+
if (done || this._closed || this._toolConfigsStream !== iterator) {
|
|
282
321
|
return;
|
|
322
|
+
}
|
|
283
323
|
this._kick();
|
|
284
324
|
}
|
|
285
325
|
};
|
|
@@ -287,8 +327,9 @@ export class ModelDownloadReconciler {
|
|
|
287
327
|
if (active && this._toolConfigsStream !== active)
|
|
288
328
|
return;
|
|
289
329
|
this._restartWatch('toolConfigs', err, () => {
|
|
290
|
-
if (this._toolConfigsAgentId === agentId)
|
|
330
|
+
if (this._toolConfigsAgentId === agentId) {
|
|
291
331
|
this._watchToolConfigs(agentId);
|
|
332
|
+
}
|
|
292
333
|
});
|
|
293
334
|
});
|
|
294
335
|
}
|
|
@@ -296,15 +337,17 @@ export class ModelDownloadReconciler {
|
|
|
296
337
|
if (this._closed)
|
|
297
338
|
return;
|
|
298
339
|
const meshId = this._meshId();
|
|
299
|
-
if (!meshId)
|
|
340
|
+
if (!meshId) {
|
|
300
341
|
return;
|
|
342
|
+
}
|
|
301
343
|
const run = async () => {
|
|
302
344
|
const stream = this._engine.agentsWatch({ meshId });
|
|
303
345
|
this._agentsStream = stream[Symbol.asyncIterator]();
|
|
304
346
|
while (true) {
|
|
305
347
|
const { done } = await this._agentsStream.next();
|
|
306
|
-
if (done || this._closed)
|
|
348
|
+
if (done || this._closed) {
|
|
307
349
|
return;
|
|
350
|
+
}
|
|
308
351
|
this._kick();
|
|
309
352
|
}
|
|
310
353
|
};
|
|
@@ -319,8 +362,9 @@ export class ModelDownloadReconciler {
|
|
|
319
362
|
_scheduleRestart(restart) {
|
|
320
363
|
const timer = setTimeout(() => {
|
|
321
364
|
this._timers.delete(timer);
|
|
322
|
-
if (this._closed)
|
|
365
|
+
if (this._closed) {
|
|
323
366
|
return;
|
|
367
|
+
}
|
|
324
368
|
restart();
|
|
325
369
|
}, this._watchRetryMs);
|
|
326
370
|
unref(timer);
|
|
@@ -330,12 +374,14 @@ export class ModelDownloadReconciler {
|
|
|
330
374
|
if (this._closed || this._paused)
|
|
331
375
|
return;
|
|
332
376
|
this._dirty = true;
|
|
333
|
-
if (this._running)
|
|
377
|
+
if (this._running) {
|
|
334
378
|
return;
|
|
379
|
+
}
|
|
335
380
|
this._running = this._drain().finally(() => {
|
|
336
381
|
this._running = null;
|
|
337
|
-
if (this._dirty)
|
|
382
|
+
if (this._dirty) {
|
|
338
383
|
this._kick();
|
|
384
|
+
}
|
|
339
385
|
});
|
|
340
386
|
}
|
|
341
387
|
async _drain() {
|
|
@@ -362,8 +408,9 @@ export class ModelDownloadReconciler {
|
|
|
362
408
|
}
|
|
363
409
|
await this._flushObservedProgress();
|
|
364
410
|
const targets = await this._desired();
|
|
365
|
-
if (this._closed || this._paused)
|
|
411
|
+
if (this._closed || this._paused) {
|
|
366
412
|
return;
|
|
413
|
+
}
|
|
367
414
|
const downloadable = new Map(targets.filter((t) => !t.paused).map((t) => [t.name, t]));
|
|
368
415
|
if (this._active && !downloadable.has(this._active.model)) {
|
|
369
416
|
const stillWanted = targets.some((t) => t.name === this._active?.model);
|
|
@@ -375,13 +422,15 @@ export class ModelDownloadReconciler {
|
|
|
375
422
|
if (this._runModels.size === 0) {
|
|
376
423
|
const preemptLlm = this._preemptLlm;
|
|
377
424
|
this._preemptLlm = null;
|
|
378
|
-
if (this._shouldPreempt(preferred, preemptLlm))
|
|
425
|
+
if (this._shouldPreempt(preferred, preemptLlm)) {
|
|
379
426
|
await this._stopActive(false);
|
|
427
|
+
}
|
|
380
428
|
}
|
|
381
429
|
const next = this._active ? null : preferred;
|
|
382
430
|
await this._writeWaiting(targets, next?.name, now);
|
|
383
|
-
if (next && !this._closed && !this._paused)
|
|
431
|
+
if (next && !this._closed && !this._paused) {
|
|
384
432
|
this._begin(next);
|
|
433
|
+
}
|
|
385
434
|
}
|
|
386
435
|
async _writeWaiting(targets, nextName, now) {
|
|
387
436
|
for (const target of targets) {
|
|
@@ -403,8 +452,9 @@ export class ModelDownloadReconciler {
|
|
|
403
452
|
if (progress.phase === 'complete') {
|
|
404
453
|
await this._completeTransfer(model);
|
|
405
454
|
this._observedTransfers.delete(model);
|
|
406
|
-
if (this._observedProgress.get(model) === progress)
|
|
455
|
+
if (this._observedProgress.get(model) === progress) {
|
|
407
456
|
this._observedProgress.delete(model);
|
|
457
|
+
}
|
|
408
458
|
this._handled.add(model);
|
|
409
459
|
this._retry.reset(model);
|
|
410
460
|
this._observedSpeed.delete(model);
|
|
@@ -414,8 +464,9 @@ export class ModelDownloadReconciler {
|
|
|
414
464
|
continue;
|
|
415
465
|
}
|
|
416
466
|
await this._engine.beginModelTransfer({ name: model, transferred: true });
|
|
417
|
-
if (this._observedProgress.get(model) === progress)
|
|
467
|
+
if (this._observedProgress.get(model) === progress) {
|
|
418
468
|
this._observedProgress.delete(model);
|
|
469
|
+
}
|
|
419
470
|
const total = progress.total > 0 ? progress.total : expectedTotal;
|
|
420
471
|
const downloaded = total > 0 ? Math.min(progress.downloaded, total) : progress.downloaded;
|
|
421
472
|
let speed = this._observedSpeed.get(model);
|
|
@@ -463,8 +514,9 @@ export class ModelDownloadReconciler {
|
|
|
463
514
|
_scheduleNextRetry(downloadable, now) {
|
|
464
515
|
this._scheduler.clear();
|
|
465
516
|
const deadline = this._retry.nextDeadline(new Set(downloadable.keys()), now);
|
|
466
|
-
if (deadline !== null)
|
|
517
|
+
if (deadline !== null) {
|
|
467
518
|
this._scheduler.schedule(deadline);
|
|
519
|
+
}
|
|
468
520
|
}
|
|
469
521
|
async _desired() {
|
|
470
522
|
if (this._demands.size === 0 &&
|
|
@@ -477,9 +529,12 @@ export class ModelDownloadReconciler {
|
|
|
477
529
|
return [];
|
|
478
530
|
}
|
|
479
531
|
const availability = await this._modelAvailability();
|
|
480
|
-
for (const name of availability.cached)
|
|
532
|
+
for (const name of availability.cached) {
|
|
481
533
|
this._handled.delete(name);
|
|
534
|
+
}
|
|
482
535
|
const paused = new Set(this._config?.pausedModels ?? []);
|
|
536
|
+
await this._reclaimCached(new Set([...availability.cached, ...this._handled]));
|
|
537
|
+
const released = new Set([...(this._config?.releasedModels ?? []), ...this._releasing]);
|
|
483
538
|
const wanted = new Map();
|
|
484
539
|
for (const [name, demand] of this._demands) {
|
|
485
540
|
wanted.set(name, { name, addon: demand.addon, paused: paused.has(name) });
|
|
@@ -493,11 +548,11 @@ export class ModelDownloadReconciler {
|
|
|
493
548
|
this._preemptLlm = localLlm;
|
|
494
549
|
}
|
|
495
550
|
this._pausedLocalLlm = localLlm !== null && paused.has(localLlm) ? localLlm : null;
|
|
496
|
-
if (localLlm && !wanted.has(localLlm)) {
|
|
551
|
+
if (localLlm && !wanted.has(localLlm) && !released.has(localLlm)) {
|
|
497
552
|
wanted.set(localLlm, { name: localLlm, addon: 'llm', paused: paused.has(localLlm) });
|
|
498
553
|
}
|
|
499
554
|
for (const model of [...this._localSkillModels, ...infra]) {
|
|
500
|
-
if (!wanted.has(model.name)) {
|
|
555
|
+
if (!wanted.has(model.name) && !released.has(model.name)) {
|
|
501
556
|
wanted.set(model.name, { ...model, paused: paused.has(model.name) });
|
|
502
557
|
}
|
|
503
558
|
}
|
|
@@ -506,14 +561,16 @@ export class ModelDownloadReconciler {
|
|
|
506
561
|
if (wanted.has(name))
|
|
507
562
|
continue;
|
|
508
563
|
const addon = availability.addons.get(name);
|
|
509
|
-
if (addon === undefined)
|
|
564
|
+
if (addon === undefined) {
|
|
510
565
|
continue;
|
|
566
|
+
}
|
|
511
567
|
wanted.set(name, { name, addon, paused: paused.has(name) });
|
|
512
568
|
}
|
|
513
569
|
const wantedNames = new Set(wanted.keys());
|
|
514
570
|
for (const name of this._attemptGenerations.keys()) {
|
|
515
|
-
if (!wantedNames.has(name))
|
|
571
|
+
if (!wantedNames.has(name)) {
|
|
516
572
|
this._attemptGenerations.delete(name);
|
|
573
|
+
}
|
|
517
574
|
}
|
|
518
575
|
this._retry.retain(wantedNames);
|
|
519
576
|
await this._status.clearUnwanted(wantedNames);
|
|
@@ -531,8 +588,9 @@ export class ModelDownloadReconciler {
|
|
|
531
588
|
});
|
|
532
589
|
}
|
|
533
590
|
const pendingNames = new Set(pending.map((target) => target.name));
|
|
534
|
-
for (const target of pending)
|
|
591
|
+
for (const target of pending) {
|
|
535
592
|
this._targetTotals.set(target.name, target.total);
|
|
593
|
+
}
|
|
536
594
|
for (const name of this._targetTotals.keys()) {
|
|
537
595
|
if (pendingNames.has(name))
|
|
538
596
|
continue;
|
|
@@ -542,6 +600,13 @@ export class ModelDownloadReconciler {
|
|
|
542
600
|
}
|
|
543
601
|
return pending;
|
|
544
602
|
}
|
|
603
|
+
async _reclaimCached(cached) {
|
|
604
|
+
for (const name of this._config?.releasedModels ?? []) {
|
|
605
|
+
if (!cached.has(name) || this._releasing.has(name))
|
|
606
|
+
continue;
|
|
607
|
+
this._config = await this._engine.setModelReleased({ name, released: false });
|
|
608
|
+
}
|
|
609
|
+
}
|
|
545
610
|
async _modelAvailability() {
|
|
546
611
|
const rows = (await this._harness.list?.({}).catch(() => [])) ?? [];
|
|
547
612
|
const cached = new Set(rows.filter((row) => row.isCached).map((row) => row.name));
|
|
@@ -558,12 +623,14 @@ export class ModelDownloadReconciler {
|
|
|
558
623
|
if (this._profile)
|
|
559
624
|
return this._profile;
|
|
560
625
|
const meshId = this._meshId();
|
|
561
|
-
if (!meshId)
|
|
626
|
+
if (!meshId) {
|
|
562
627
|
return this._profile ?? 'mid';
|
|
628
|
+
}
|
|
563
629
|
const { devices } = await this._engine.listDevices({ meshId }).catch(() => ({ devices: [] }));
|
|
564
|
-
const self = (devices ?? []).find((device) => device.id
|
|
565
|
-
if (self)
|
|
630
|
+
const self = (devices ?? []).find((device) => b4a.equals(device.id, this._deviceId));
|
|
631
|
+
if (self) {
|
|
566
632
|
this._profile = self.capabilityProfile;
|
|
633
|
+
}
|
|
567
634
|
return this._profile ?? 'mid';
|
|
568
635
|
}
|
|
569
636
|
async _hostCapability() {
|
|
@@ -571,8 +638,9 @@ export class ModelDownloadReconciler {
|
|
|
571
638
|
return this._capability;
|
|
572
639
|
try {
|
|
573
640
|
const probed = await this._harness.capability?.();
|
|
574
|
-
if (!probed?.recommendedModelName)
|
|
641
|
+
if (!probed?.recommendedModelName) {
|
|
575
642
|
return null;
|
|
643
|
+
}
|
|
576
644
|
this._capability = probed;
|
|
577
645
|
return probed;
|
|
578
646
|
}
|
|
@@ -584,72 +652,82 @@ export class ModelDownloadReconciler {
|
|
|
584
652
|
async _refreshLocalAgentModels() {
|
|
585
653
|
const activeAgentId = this._config?.activeAgentId;
|
|
586
654
|
const meshId = this._meshId();
|
|
587
|
-
if (!activeAgentId || !meshId)
|
|
655
|
+
if (!activeAgentId || !meshId) {
|
|
588
656
|
return;
|
|
657
|
+
}
|
|
589
658
|
const agent = await this._engine.getAgent({ agentId: activeAgentId, meshId }).catch(noop);
|
|
590
|
-
if (!agent?.modelName)
|
|
659
|
+
if (!agent?.modelName) {
|
|
591
660
|
return;
|
|
592
|
-
|
|
661
|
+
}
|
|
662
|
+
if (!agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, this._deviceId)) {
|
|
593
663
|
return;
|
|
664
|
+
}
|
|
594
665
|
const model = runnableModelName(agent.modelName, await this._hostCapability(), this._mobileClass);
|
|
595
666
|
const music = await this._musicModelChoice(activeAgentId);
|
|
596
|
-
if (this._config?.activeAgentId !== activeAgentId)
|
|
667
|
+
if (this._config?.activeAgentId !== activeAgentId) {
|
|
597
668
|
return;
|
|
669
|
+
}
|
|
598
670
|
if (model !== agent.modelName) {
|
|
599
671
|
this._log?.warn('model-download', 'model clamped to what this device can run', {
|
|
600
672
|
requested: agent.modelName,
|
|
601
673
|
model
|
|
602
674
|
});
|
|
603
675
|
}
|
|
604
|
-
if (model !== this._localLlm)
|
|
676
|
+
if (model !== this._localLlm) {
|
|
605
677
|
this._preemptLlm = model;
|
|
678
|
+
}
|
|
606
679
|
this._localLlm = model;
|
|
607
|
-
if (music.ok)
|
|
680
|
+
if (music.ok) {
|
|
608
681
|
this._musicChoice = music.choice;
|
|
682
|
+
}
|
|
609
683
|
this._localSkillModels = skillModelsForAgent({ ...agent, musicModelChoice: this._musicChoice });
|
|
610
684
|
}
|
|
611
685
|
async _musicModelChoice(agentId) {
|
|
612
686
|
const meshId = this._meshId();
|
|
613
|
-
if (!meshId)
|
|
687
|
+
if (!meshId) {
|
|
614
688
|
return { ok: false };
|
|
689
|
+
}
|
|
615
690
|
const configs = await this._engine
|
|
616
691
|
.listToolConfigs({ agentId, meshId })
|
|
617
692
|
.then((result) => result.configs ?? [])
|
|
618
693
|
.catch(noop);
|
|
619
|
-
if (!configs)
|
|
694
|
+
if (!configs) {
|
|
620
695
|
return { ok: false };
|
|
696
|
+
}
|
|
621
697
|
const row = configs.find((entry) => entry?.toolName === GENERATE_MUSIC_TOOL);
|
|
622
698
|
const settings = row?.settings;
|
|
623
|
-
if (!settings || typeof settings !== 'object')
|
|
699
|
+
if (!settings || typeof settings !== 'object') {
|
|
624
700
|
return { ok: true, choice: undefined };
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
choice: typeof choice === 'string' &&
|
|
629
|
-
MUSIC_MODEL_CHOICES.includes(choice)
|
|
630
|
-
? choice
|
|
631
|
-
: undefined
|
|
632
|
-
};
|
|
701
|
+
}
|
|
702
|
+
const choice = 'modelChoice' in settings ? settings.modelChoice : undefined;
|
|
703
|
+
return { ok: true, choice: isMusicModelChoice(choice) ? choice : undefined };
|
|
633
704
|
}
|
|
634
705
|
_begin({ name, addon, total }) {
|
|
635
706
|
const controller = new AbortController();
|
|
636
|
-
const done = this._download(name,
|
|
707
|
+
const done = this._download(name, controller, {
|
|
708
|
+
addon,
|
|
709
|
+
expectedTotal: total,
|
|
710
|
+
attemptGeneration: this._attemptGeneration(name)
|
|
711
|
+
});
|
|
637
712
|
this._active = { model: name, addon, total, controller, done };
|
|
638
713
|
}
|
|
639
714
|
_removeDemandWaiter(model, waiter) {
|
|
640
715
|
const demand = this._demands.get(model);
|
|
641
|
-
if (!demand)
|
|
716
|
+
if (!demand) {
|
|
642
717
|
return;
|
|
718
|
+
}
|
|
643
719
|
demand.waiters.delete(waiter);
|
|
644
720
|
waiter.signal.removeEventListener('abort', waiter.abort);
|
|
645
|
-
if (demand.waiters.size === 0)
|
|
721
|
+
if (demand.waiters.size === 0) {
|
|
646
722
|
this._demands.delete(model);
|
|
723
|
+
}
|
|
647
724
|
this._kick();
|
|
648
725
|
}
|
|
649
726
|
_resolveDemand(model) {
|
|
650
727
|
const demand = this._demands.get(model);
|
|
651
|
-
if (!demand)
|
|
728
|
+
if (!demand) {
|
|
652
729
|
return;
|
|
730
|
+
}
|
|
653
731
|
this._demands.delete(model);
|
|
654
732
|
for (const waiter of demand.waiters) {
|
|
655
733
|
waiter.signal.removeEventListener('abort', waiter.abort);
|
|
@@ -658,11 +736,13 @@ export class ModelDownloadReconciler {
|
|
|
658
736
|
}
|
|
659
737
|
_failDemand(model, message) {
|
|
660
738
|
const demand = this._demands.get(model);
|
|
661
|
-
if (!demand)
|
|
739
|
+
if (!demand) {
|
|
662
740
|
return;
|
|
741
|
+
}
|
|
663
742
|
demand.failures += 1;
|
|
664
|
-
if (demand.failures < MAX_DEMAND_FAILURES)
|
|
743
|
+
if (demand.failures < MAX_DEMAND_FAILURES) {
|
|
665
744
|
return;
|
|
745
|
+
}
|
|
666
746
|
this._demands.delete(model);
|
|
667
747
|
for (const waiter of demand.waiters) {
|
|
668
748
|
waiter.signal.removeEventListener('abort', waiter.abort);
|
|
@@ -674,15 +754,17 @@ export class ModelDownloadReconciler {
|
|
|
674
754
|
}
|
|
675
755
|
async _stopActive(clear) {
|
|
676
756
|
const active = this._active;
|
|
677
|
-
if (!active)
|
|
757
|
+
if (!active) {
|
|
678
758
|
return;
|
|
759
|
+
}
|
|
679
760
|
this._active = null;
|
|
680
761
|
active.controller.abort('model-download superseded');
|
|
681
762
|
await active.done;
|
|
682
|
-
if (clear)
|
|
763
|
+
if (clear) {
|
|
683
764
|
await this._status.clear(active.model);
|
|
765
|
+
}
|
|
684
766
|
}
|
|
685
|
-
async _download(model, addon, expectedTotal,
|
|
767
|
+
async _download(model, controller, { addon, expectedTotal, attemptGeneration }) {
|
|
686
768
|
const current = () => this._active?.controller === controller;
|
|
687
769
|
const speed = new DownloadSpeedSampler();
|
|
688
770
|
let localFlush = null;
|
|
@@ -691,12 +773,41 @@ export class ModelDownloadReconciler {
|
|
|
691
773
|
let retry = false;
|
|
692
774
|
let completed = false;
|
|
693
775
|
let failureMessage = 'model download failed';
|
|
776
|
+
const recordProgress = async (event) => {
|
|
777
|
+
const at = this._now();
|
|
778
|
+
const transfer = transferProgress(event);
|
|
779
|
+
if (!recordedTransfer &&
|
|
780
|
+
(event.transferred === true ||
|
|
781
|
+
(event.transferred === undefined && transfer && transfer.percentage < 100))) {
|
|
782
|
+
await this._engine.beginModelTransfer({ name: model, transferred: true });
|
|
783
|
+
recordedTransfer = true;
|
|
784
|
+
}
|
|
785
|
+
if (hasTransfer && isEmptyTick(transfer)) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
const bytes = transfer ?? progressBytes(event);
|
|
789
|
+
const percentage = transfer?.percentage ?? 0;
|
|
790
|
+
if (shouldFlush(localFlush, { at, percentage })) {
|
|
791
|
+
const written = await this._status.write(model, 'downloading', {
|
|
792
|
+
percentage,
|
|
793
|
+
downloaded: bytes.downloaded,
|
|
794
|
+
total: bytes.total,
|
|
795
|
+
bytesPerSecond: speed.sample(bytes, at, event.downloadKey)
|
|
796
|
+
});
|
|
797
|
+
if (written) {
|
|
798
|
+
localFlush = { at, percentage };
|
|
799
|
+
hasTransfer ||= !isEmptyTick(transfer);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
};
|
|
694
803
|
try {
|
|
695
|
-
if (this._completedTransfers.delete(model))
|
|
804
|
+
if (this._completedTransfers.delete(model)) {
|
|
696
805
|
this._transfers.delete(model);
|
|
806
|
+
}
|
|
697
807
|
await this._transfer(model);
|
|
698
|
-
if (controller.signal.aborted || !current())
|
|
808
|
+
if (controller.signal.aborted || !current()) {
|
|
699
809
|
return;
|
|
810
|
+
}
|
|
700
811
|
const initialPercentage = 0;
|
|
701
812
|
const initialAt = this._now();
|
|
702
813
|
if (await this._status.write(model, 'downloading', {
|
|
@@ -707,6 +818,9 @@ export class ModelDownloadReconciler {
|
|
|
707
818
|
})) {
|
|
708
819
|
localFlush = { at: initialAt, percentage: initialPercentage };
|
|
709
820
|
}
|
|
821
|
+
if (!this._harness.download) {
|
|
822
|
+
throw new Error('the harness cannot download models');
|
|
823
|
+
}
|
|
710
824
|
for await (const event of this._harness.download({
|
|
711
825
|
model,
|
|
712
826
|
addon,
|
|
@@ -714,35 +828,12 @@ export class ModelDownloadReconciler {
|
|
|
714
828
|
})) {
|
|
715
829
|
if (this._closed || !current())
|
|
716
830
|
return;
|
|
831
|
+
if (event.type === 'complete' && controller.signal.aborted)
|
|
832
|
+
return;
|
|
717
833
|
if (event.type === 'progress') {
|
|
718
|
-
|
|
719
|
-
const transfer = transferProgress(event);
|
|
720
|
-
if (!recordedTransfer &&
|
|
721
|
-
(event.transferred === true ||
|
|
722
|
-
(event.transferred === undefined && transfer && transfer.percentage < 100))) {
|
|
723
|
-
await this._engine.beginModelTransfer({ name: model, transferred: true });
|
|
724
|
-
recordedTransfer = true;
|
|
725
|
-
}
|
|
726
|
-
if (hasTransfer && isEmptyTick(transfer))
|
|
727
|
-
continue;
|
|
728
|
-
const bytes = transfer ?? progressBytes(event);
|
|
729
|
-
const percentage = transfer?.percentage ?? 0;
|
|
730
|
-
if (shouldFlush(localFlush, percentage, at, LOCAL_PROGRESS_INTERVAL_MS, LOCAL_PROGRESS_PERCENTAGE_STEP)) {
|
|
731
|
-
const written = await this._status.write(model, 'downloading', {
|
|
732
|
-
percentage,
|
|
733
|
-
downloaded: bytes.downloaded,
|
|
734
|
-
total: bytes.total,
|
|
735
|
-
bytesPerSecond: speed.sample(bytes, at, event.downloadKey)
|
|
736
|
-
});
|
|
737
|
-
if (written) {
|
|
738
|
-
localFlush = { at, percentage };
|
|
739
|
-
hasTransfer ||= !isEmptyTick(transfer);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
834
|
+
await recordProgress(event);
|
|
742
835
|
}
|
|
743
836
|
else if (event.type === 'complete') {
|
|
744
|
-
if (controller.signal.aborted)
|
|
745
|
-
return;
|
|
746
837
|
await this._completeTransfer(model, { downloaded: event.downloaded !== false });
|
|
747
838
|
completed = true;
|
|
748
839
|
retry = false;
|
|
@@ -769,13 +860,14 @@ export class ModelDownloadReconciler {
|
|
|
769
860
|
});
|
|
770
861
|
}
|
|
771
862
|
}
|
|
772
|
-
if (current() && !controller.signal.aborted && !completed && !retry)
|
|
863
|
+
if (current() && !controller.signal.aborted && !completed && !retry) {
|
|
773
864
|
retry = true;
|
|
865
|
+
}
|
|
774
866
|
}
|
|
775
867
|
catch (err) {
|
|
776
868
|
if (!this._closed && current()) {
|
|
777
869
|
retry = true;
|
|
778
|
-
failureMessage =
|
|
870
|
+
failureMessage = errorMessage(err);
|
|
779
871
|
await this._status.write(model, 'error', {
|
|
780
872
|
error: failureMessage,
|
|
781
873
|
bytesPerSecond: 0
|
|
@@ -784,8 +876,9 @@ export class ModelDownloadReconciler {
|
|
|
784
876
|
}
|
|
785
877
|
finally {
|
|
786
878
|
const wasCurrent = current();
|
|
787
|
-
if (wasCurrent)
|
|
879
|
+
if (wasCurrent) {
|
|
788
880
|
this._active = null;
|
|
881
|
+
}
|
|
789
882
|
if (retry &&
|
|
790
883
|
!this._closed &&
|
|
791
884
|
!this._paused &&
|
|
@@ -793,8 +886,9 @@ export class ModelDownloadReconciler {
|
|
|
793
886
|
this._failDemand(model, failureMessage);
|
|
794
887
|
this._scheduler.schedule(this._retry.fail(model, this._now()));
|
|
795
888
|
}
|
|
796
|
-
if (!this._closed && !this._paused && wasCurrent)
|
|
889
|
+
if (!this._closed && !this._paused && wasCurrent) {
|
|
797
890
|
this._kick();
|
|
891
|
+
}
|
|
798
892
|
}
|
|
799
893
|
}
|
|
800
894
|
}
|
|
@@ -802,9 +896,12 @@ function isEmptyTick(transfer) {
|
|
|
802
896
|
return (transfer === null ||
|
|
803
897
|
(transfer.percentage === 0 && transfer.downloaded === 0 && transfer.total === 0));
|
|
804
898
|
}
|
|
805
|
-
function shouldFlush(previous,
|
|
899
|
+
function shouldFlush(previous, { at, percentage }) {
|
|
806
900
|
return (previous === null ||
|
|
807
|
-
at - previous.at >=
|
|
808
|
-
percentage - previous.percentage >=
|
|
901
|
+
at - previous.at >= LOCAL_PROGRESS_INTERVAL_MS ||
|
|
902
|
+
percentage - previous.percentage >= LOCAL_PROGRESS_PERCENTAGE_STEP);
|
|
903
|
+
}
|
|
904
|
+
function isMusicModelChoice(value) {
|
|
905
|
+
return MUSIC_MODEL_CHOICES.some((choice) => choice === value);
|
|
809
906
|
}
|
|
810
907
|
function noop() { }
|