@qvac/core 0.5.0 → 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 +75 -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 +13 -8
- 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 +2 -1
- package/dist-lib/lib/api/files.js +2 -1
- package/dist-lib/lib/api/index.d.ts +5 -1
- package/dist-lib/lib/api/index.js +101 -102
- 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.js +3 -3
- 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 +48 -27
- package/dist-lib/lib/assistant/harness.js +40 -16
- 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 +27 -11
- package/dist-lib/lib/assistant.d.ts +30 -11
- package/dist-lib/lib/assistant.js +824 -378
- 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/core/account-recovery.d.ts +4 -3
- package/dist-lib/lib/core/account-recovery.js +7 -4
- package/dist-lib/lib/core/agent.js +17 -15
- 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 +19 -23
- package/dist-lib/lib/core/chunk.js +27 -21
- 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 +6 -2
- package/dist-lib/lib/core/contract/activity.js +15 -12
- 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 +10 -9
- package/dist-lib/lib/core/contract/compute.js +2 -1
- package/dist-lib/lib/core/contract/devices.js +6 -5
- package/dist-lib/lib/core/contract/grant-order.js +5 -6
- package/dist-lib/lib/core/contract/index.js +4 -2
- package/dist-lib/lib/core/contract/indexing.js +3 -3
- package/dist-lib/lib/core/contract/invites.d.ts +8 -3
- package/dist-lib/lib/core/contract/invites.js +52 -26
- package/dist-lib/lib/core/contract/joined-meshes.js +3 -3
- package/dist-lib/lib/core/contract/knowledge.js +5 -5
- package/dist-lib/lib/core/contract/members.d.ts +13 -2
- package/dist-lib/lib/core/contract/members.js +46 -25
- package/dist-lib/lib/core/contract/mesh-kind.js +9 -8
- 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 +6 -1
- package/dist-lib/lib/core/contract/writers.js +55 -34
- package/dist-lib/lib/core/departures.js +16 -8
- package/dist-lib/lib/core/device-invites.js +3 -2
- package/dist-lib/lib/core/devices.js +6 -3
- 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.js +12 -7
- package/dist-lib/lib/core/handoff-channel.js +27 -13
- package/dist-lib/lib/core/harness-loan.js +35 -17
- package/dist-lib/lib/core/helpers/index.js +6 -2
- 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.js +6 -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.js +4 -2
- package/dist-lib/lib/core/invite.js +2 -1
- package/dist-lib/lib/core/local/files.js +20 -19
- package/dist-lib/lib/core/local/index.d.ts +69 -46
- package/dist-lib/lib/core/local/index.js +146 -129
- package/dist-lib/lib/core/membership.d.ts +12 -2
- package/dist-lib/lib/core/membership.js +55 -33
- package/dist-lib/lib/core/mesh-seed-handoff.js +7 -1
- package/dist-lib/lib/core/mesh.d.ts +37 -27
- package/dist-lib/lib/core/mesh.js +131 -73
- 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/file-index.js +7 -4
- package/dist-lib/lib/core/migrations/index.d.ts +4 -3
- 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 +4 -4
- package/dist-lib/lib/core/send.js +6 -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 +20 -15
- 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 +38 -26
- package/dist-lib/lib/core.js +987 -539
- 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 +12 -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 +2 -2
- package/dist-lib/lib/model-idle-pusher.js +3 -4
- 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 +1 -0
- package/dist-lib/lib/run-notices.js +5 -2
- 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.js +4 -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.js +22 -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 +10 -6
- package/dist-lib/schema/config.d.ts +2 -3
- package/dist-lib/schema/content.d.ts +17 -2
- package/dist-lib/schema/content.js +2 -1
- package/dist-lib/schema/engine.d.ts +3 -2
- package/dist-lib/schema/engine.js +95 -6
- 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} +14 -57
- package/dist-lib/schema/local.d.ts +3 -2
- package/dist-lib/schema/local.js +7 -2
- 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 +8 -4
- package/dist-lib/spec/bind.js +12 -0
- package/dist-lib/spec/calls.js +4 -0
- package/dist-lib/spec/capabilities.d.ts +12 -4
- package/dist-lib/spec/hrpc/hrpc.json +54 -2
- package/dist-lib/spec/hrpc/index.js +53 -5
- package/dist-lib/spec/hrpc/messages.js +783 -494
- package/dist-lib/spec/hyperschema/index.js +783 -494
- package/dist-lib/spec/hyperschema/schema.json +247 -1
- package/dist-lib/spec/hyperschema/types.d.ts +69 -1
- package/dist-lib/spec/local/hyperdb/index.js +1 -1
- package/dist-lib/spec/local/hyperdb/messages.js +82 -14
- package/dist-lib/spec/local/hyperschema/index.js +42 -8
- package/dist-lib/spec/local/hyperschema/schema.json +27 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +6 -1
- package/dist-lib/spec/mesh/hyperdb/index.js +1 -1
- package/package.json +7 -3
- package/tui/app.mjs +2424 -941
- 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 -33
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { diagramRepairAccepted, diagramRepairLinks, isDiagramRepairPrompt } from '@qvac/harness/lib/diagram-repair.ts';
|
|
2
|
-
import { chunkTypeOrdinal } from '../../schema/
|
|
2
|
+
import { chunkTypeOrdinal } from '../../schema/indexes.js';
|
|
3
3
|
import { enrichAll, lastActivity, liveGroupIds } from './chat.js';
|
|
4
4
|
import { foldSearchText } from './search-fold.js';
|
|
5
|
-
|
|
6
|
-
const CHUNKS_BY_TYPE = '@qvac/chunks-by-type';
|
|
5
|
+
import { ACTIVE_CHATS, CHUNKS_BY_TYPE } from './collections.js';
|
|
7
6
|
const DEFAULT_LIMIT = 100;
|
|
8
7
|
const PER_CHAT_LIMIT = 20;
|
|
9
8
|
const SNIPPET_PAD = 40;
|
|
10
9
|
export async function searchChats(store, input) {
|
|
11
10
|
const needle = foldSearchText(input.query.trim());
|
|
12
|
-
if (!needle)
|
|
11
|
+
if (!needle) {
|
|
13
12
|
return [];
|
|
13
|
+
}
|
|
14
14
|
const limit = input.limit || DEFAULT_LIMIT;
|
|
15
15
|
const snap = store.view.snapshot();
|
|
16
16
|
try {
|
|
@@ -20,23 +20,27 @@ export async function searchChats(store, input) {
|
|
|
20
20
|
const titled = [];
|
|
21
21
|
const untitled = [];
|
|
22
22
|
for (const chat of chats) {
|
|
23
|
-
if (foldSearchText(chat.title).includes(needle))
|
|
23
|
+
if (foldSearchText(chat.title).includes(needle)) {
|
|
24
24
|
titled.push(chat);
|
|
25
|
-
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
26
27
|
untitled.push(chat);
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
const hits = [];
|
|
29
31
|
for (const chat of titled) {
|
|
30
32
|
hits.push(titleHit(chat));
|
|
31
|
-
if (hits.length >= limit)
|
|
33
|
+
if (hits.length >= limit) {
|
|
32
34
|
return hits;
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
for (const chat of [...titled, ...untitled]) {
|
|
35
38
|
if (input.signal?.aborted)
|
|
36
39
|
break;
|
|
37
|
-
hits.push(...(await contentHits(snap, chat, needle, remainingCap(hits.length, limit))));
|
|
38
|
-
if (hits.length >= limit)
|
|
40
|
+
hits.push(...(await contentHits(snap, chat, { needle, cap: remainingCap(hits.length, limit) })));
|
|
41
|
+
if (hits.length >= limit) {
|
|
39
42
|
break;
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
return hits;
|
|
42
46
|
}
|
|
@@ -50,7 +54,7 @@ function remainingCap(used, limit) {
|
|
|
50
54
|
function titleHit(chat) {
|
|
51
55
|
return { chat, match: 'title', snippet: '', chunkId: '', runId: '' };
|
|
52
56
|
}
|
|
53
|
-
async function contentHits(snap, chat, needle, cap) {
|
|
57
|
+
async function contentHits(snap, chat, { needle, cap }) {
|
|
54
58
|
if (cap <= 0)
|
|
55
59
|
return [];
|
|
56
60
|
const [users, content, attachments, requests, statuses] = await Promise.all([
|
|
@@ -76,18 +80,20 @@ async function contentHits(snap, chat, needle, cap) {
|
|
|
76
80
|
for (const repair of repairs) {
|
|
77
81
|
const parentRunId = requests.find((request) => request.id === repair.parentId)?.runId;
|
|
78
82
|
if (completedRunIds.has(repair.runId) && diagramRepairAccepted(repairText(repair.runId))) {
|
|
79
|
-
if (parentRunId)
|
|
83
|
+
if (parentRunId) {
|
|
80
84
|
hiddenRunIds.add(parentRunId);
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
else {
|
|
83
88
|
hiddenRunIds.add(repair.runId);
|
|
84
|
-
if (parentRunId)
|
|
89
|
+
if (parentRunId) {
|
|
85
90
|
redactedRunIds.add(parentRunId);
|
|
91
|
+
}
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
const matches = [
|
|
89
|
-
...matchUserMessages(users, needle, cap, hiddenPromptIds),
|
|
90
|
-
...matchJoinedContent(content, needle, cap,
|
|
95
|
+
...matchUserMessages(users, needle, { cap, hiddenIds: hiddenPromptIds }),
|
|
96
|
+
...matchJoinedContent(content, needle, { cap, hidden: hiddenRunIds, redacted: redactedRunIds }),
|
|
91
97
|
...matchAttachments(attachments, needle, cap)
|
|
92
98
|
];
|
|
93
99
|
return matches
|
|
@@ -110,28 +116,31 @@ async function chunksOfType(snap, chatId, type) {
|
|
|
110
116
|
})
|
|
111
117
|
.toArray();
|
|
112
118
|
}
|
|
113
|
-
function matchUserMessages(chunks, needle, cap, hiddenIds) {
|
|
119
|
+
function matchUserMessages(chunks, needle, { cap, hiddenIds }) {
|
|
114
120
|
const matches = [];
|
|
115
121
|
for (const chunk of chunks) {
|
|
116
122
|
if (matches.length >= cap)
|
|
117
123
|
break;
|
|
118
124
|
const text = chunk.userMessage?.text;
|
|
119
|
-
if (!text || hiddenIds.has(chunk.id))
|
|
125
|
+
if (!text || hiddenIds.has(chunk.id)) {
|
|
120
126
|
continue;
|
|
127
|
+
}
|
|
121
128
|
const found = locate(text, needle);
|
|
122
|
-
if (!found)
|
|
129
|
+
if (!found) {
|
|
123
130
|
continue;
|
|
131
|
+
}
|
|
124
132
|
matches.push({ seq: chunk.seq, snippet: found, chunkId: chunk.id, runId: chunk.runId ?? '' });
|
|
125
133
|
}
|
|
126
134
|
return matches;
|
|
127
135
|
}
|
|
128
|
-
function matchJoinedContent(chunks, needle, cap, runs) {
|
|
136
|
+
function matchJoinedContent(chunks, needle, { cap, ...runs }) {
|
|
129
137
|
const byRun = new Map();
|
|
130
138
|
const order = [];
|
|
131
139
|
for (const chunk of chunks) {
|
|
132
140
|
const runId = chunk.runId;
|
|
133
|
-
if (!runId || runs.hidden.has(runId))
|
|
141
|
+
if (!runId || runs.hidden.has(runId)) {
|
|
134
142
|
continue;
|
|
143
|
+
}
|
|
135
144
|
const group = byRun.get(runId);
|
|
136
145
|
if (group) {
|
|
137
146
|
group.push(chunk);
|
|
@@ -146,13 +155,15 @@ function matchJoinedContent(chunks, needle, cap, runs) {
|
|
|
146
155
|
break;
|
|
147
156
|
const group = byRun.get(runId);
|
|
148
157
|
const first = group?.[0];
|
|
149
|
-
if (!group || !first)
|
|
158
|
+
if (!group || !first) {
|
|
150
159
|
continue;
|
|
160
|
+
}
|
|
151
161
|
const content = group.map((chunk) => chunk.content?.text ?? '').join('');
|
|
152
162
|
const text = runs.redacted.has(runId) ? withoutMermaidDiagrams(content) : content;
|
|
153
163
|
const found = locate(text, needle);
|
|
154
|
-
if (!found)
|
|
164
|
+
if (!found) {
|
|
155
165
|
continue;
|
|
166
|
+
}
|
|
156
167
|
matches.push({ seq: first.seq, snippet: found, chunkId: first.id, runId });
|
|
157
168
|
}
|
|
158
169
|
return matches;
|
|
@@ -166,11 +177,13 @@ function matchAttachments(chunks, needle, cap) {
|
|
|
166
177
|
if (matches.length >= cap)
|
|
167
178
|
break;
|
|
168
179
|
const attachment = chunk.attachment;
|
|
169
|
-
if (!attachment || (attachment.deletedAt ?? 0) > 0)
|
|
180
|
+
if (!attachment || (attachment.deletedAt ?? 0) > 0) {
|
|
170
181
|
continue;
|
|
182
|
+
}
|
|
171
183
|
const found = locate(attachment.fileName, needle);
|
|
172
|
-
if (!found)
|
|
184
|
+
if (!found) {
|
|
173
185
|
continue;
|
|
186
|
+
}
|
|
174
187
|
matches.push({ seq: chunk.seq, snippet: found, chunkId: chunk.id, runId: chunk.runId ?? '' });
|
|
175
188
|
}
|
|
176
189
|
return matches;
|
|
@@ -179,8 +192,9 @@ function locate(text, needle) {
|
|
|
179
192
|
if (!text)
|
|
180
193
|
return null;
|
|
181
194
|
const index = foldSearchText(text).indexOf(needle);
|
|
182
|
-
if (index < 0)
|
|
195
|
+
if (index < 0) {
|
|
183
196
|
return null;
|
|
197
|
+
}
|
|
184
198
|
return snippetAround(text, index, needle.length);
|
|
185
199
|
}
|
|
186
200
|
function snippetAround(text, index, needleLength) {
|
|
@@ -20,23 +20,29 @@ export declare function getChat(store: Mesh, id: string): Promise<QvacChat | nul
|
|
|
20
20
|
export declare function mustGetChat(store: Mesh, id: string): Promise<QvacChat>;
|
|
21
21
|
export declare function mustGetActiveChat(store: Mesh, id: string): Promise<QvacChat>;
|
|
22
22
|
export declare function mustGetActiveChatListing(store: Mesh, id: string): Promise<ChatListing>;
|
|
23
|
-
export
|
|
24
|
-
agentId: string;
|
|
25
|
-
title: string;
|
|
26
|
-
}
|
|
27
|
-
export declare function
|
|
28
|
-
|
|
29
|
-
title: string;
|
|
30
|
-
}): Promise<ChatListing>;
|
|
23
|
+
export interface CreateChatInput {
|
|
24
|
+
readonly agentId: string;
|
|
25
|
+
readonly title: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function buildChat(input: CreateChatInput): QvacChat;
|
|
28
|
+
export declare function createChat(store: Mesh, input: CreateChatInput): Promise<ChatListing>;
|
|
31
29
|
export declare function renameChat(store: Mesh, id: string, title: string): Promise<ChatListing>;
|
|
32
|
-
export
|
|
30
|
+
export interface SetChatRagEnabledOptions {
|
|
31
|
+
readonly ragEnabled: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare function setChatRagEnabled(store: Mesh, id: string, opts: SetChatRagEnabledOptions): Promise<ChatListing>;
|
|
33
34
|
export declare function setChatGroup(store: Mesh, id: string, groupId: string | null | undefined): Promise<ChatListing>;
|
|
34
|
-
export
|
|
35
|
-
groupId?: string | null;
|
|
36
|
-
afterId?: string | null;
|
|
37
|
-
}
|
|
35
|
+
export interface MoveChatOptions {
|
|
36
|
+
readonly groupId?: string | null;
|
|
37
|
+
readonly afterId?: string | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function moveChat(store: Mesh, id: string, { groupId, afterId }: MoveChatOptions): Promise<ChatListing>;
|
|
38
40
|
export declare function setChatWebSearchEnabled(store: Mesh, id: string, webSearchEnabled: boolean): Promise<ChatListing>;
|
|
39
41
|
export declare function removeChatKnowledge(store: Mesh, chatId: string, at: number): Promise<void>;
|
|
40
|
-
export
|
|
42
|
+
export interface RemoveChatAttachmentsOptions {
|
|
43
|
+
readonly deviceId: Buffer;
|
|
44
|
+
readonly at: number;
|
|
45
|
+
}
|
|
46
|
+
export declare function removeChatAttachments(store: Mesh, chatId: string, { deviceId, at }: RemoveChatAttachmentsOptions): Promise<void>;
|
|
41
47
|
export declare function deleteChat(store: Mesh, deviceId: Buffer | null, id: string): Promise<ChatListing>;
|
|
42
48
|
export declare function softDeleteChatsForAgent(store: Mesh, deviceId: Buffer | null, agentId: string): Promise<void>;
|
|
@@ -4,12 +4,8 @@ import { randomId } from './id.js';
|
|
|
4
4
|
import { assertRemovableAt } from './files/index.js';
|
|
5
5
|
import { place } from './rank.js';
|
|
6
6
|
import { chatSortKey } from './chat-order.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const ACTIVE_CHATS = '@qvac/active-chats';
|
|
10
|
-
const ACTIVE_CHATS_BY_AGENT = '@qvac/active-chats-by-agent';
|
|
11
|
-
const ACTIVE_CHAT_GROUPS = '@qvac/active-chat-groups';
|
|
12
|
-
const CHUNK_COUNTERS = '@qvac/chunk-counters';
|
|
7
|
+
import b4a from 'b4a';
|
|
8
|
+
import { ACTIVE_CHATS, ACTIVE_CHATS_BY_AGENT, ACTIVE_CHAT_GROUPS, CHATS, CHAT_GROUPS, CHUNK_COUNTERS } from './collections.js';
|
|
13
9
|
const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
14
10
|
function byChatOrder(a, b) {
|
|
15
11
|
return chatSortKey(a) - chatSortKey(b) || (a.id < b.id ? -1 : 1);
|
|
@@ -22,11 +18,11 @@ export async function lastActivity(snap) {
|
|
|
22
18
|
const counters = await snap.find(CHUNK_COUNTERS).toArray();
|
|
23
19
|
return new Map(counters.map((counter) => [counter.chatId, counter.lastActivityAt ?? 0]));
|
|
24
20
|
}
|
|
25
|
-
function listingOf(chat,
|
|
21
|
+
function listingOf(chat, opts) {
|
|
26
22
|
return {
|
|
27
23
|
...chat,
|
|
28
|
-
groupId: inLiveGroup ? chat.groupId : undefined,
|
|
29
|
-
lastActivityAt: activityAt || chat.createdAt
|
|
24
|
+
groupId: opts.inLiveGroup ? chat.groupId : undefined,
|
|
25
|
+
lastActivityAt: opts.activityAt || chat.createdAt
|
|
30
26
|
};
|
|
31
27
|
}
|
|
32
28
|
export async function enrichChat(store, chat) {
|
|
@@ -45,10 +41,16 @@ export async function enrichIn(snap, chat) {
|
|
|
45
41
|
: Promise.resolve(null),
|
|
46
42
|
snap.get(CHUNK_COUNTERS, { chatId: chat.id })
|
|
47
43
|
]);
|
|
48
|
-
return listingOf(chat,
|
|
44
|
+
return listingOf(chat, {
|
|
45
|
+
inLiveGroup: !!group && !group?.deletedAt,
|
|
46
|
+
activityAt: counter?.lastActivityAt
|
|
47
|
+
});
|
|
49
48
|
}
|
|
50
49
|
export function enrichAll(chats, activity, liveGroups) {
|
|
51
|
-
return chats.map((chat) => listingOf(chat,
|
|
50
|
+
return chats.map((chat) => listingOf(chat, {
|
|
51
|
+
inLiveGroup: Boolean(chat.groupId && liveGroups.has(chat.groupId)),
|
|
52
|
+
activityAt: activity.get(chat.id)
|
|
53
|
+
}));
|
|
52
54
|
}
|
|
53
55
|
export async function listSidebar(store) {
|
|
54
56
|
const snap = store.view.snapshot();
|
|
@@ -80,14 +82,16 @@ export async function getChat(store, id) {
|
|
|
80
82
|
}
|
|
81
83
|
export async function mustGetChat(store, id) {
|
|
82
84
|
const chat = await getChat(store, id);
|
|
83
|
-
if (!chat)
|
|
85
|
+
if (!chat) {
|
|
84
86
|
throw new Error(`chat not found: ${id}`);
|
|
87
|
+
}
|
|
85
88
|
return chat;
|
|
86
89
|
}
|
|
87
90
|
export async function mustGetActiveChat(store, id) {
|
|
88
91
|
const chat = await mustGetChat(store, id);
|
|
89
|
-
if (chat.deletedAt)
|
|
92
|
+
if (chat.deletedAt) {
|
|
90
93
|
throw new Error(`chat not found: ${id}`);
|
|
94
|
+
}
|
|
91
95
|
return chat;
|
|
92
96
|
}
|
|
93
97
|
export async function mustGetActiveChatListing(store, id) {
|
|
@@ -109,7 +113,7 @@ export function buildChat(input) {
|
|
|
109
113
|
export async function createChat(store, input) {
|
|
110
114
|
const chat = buildChat(input);
|
|
111
115
|
await store.dispatch('put-chat', { chat });
|
|
112
|
-
return listingOf(chat, false
|
|
116
|
+
return listingOf(chat, { inLiveGroup: false });
|
|
113
117
|
}
|
|
114
118
|
async function patchChat(store, id, patch) {
|
|
115
119
|
return patchChatRow(store, await mustGetActiveChat(store, id), patch);
|
|
@@ -122,13 +126,14 @@ async function patchChatRow(store, current, patch) {
|
|
|
122
126
|
export function renameChat(store, id, title) {
|
|
123
127
|
return patchChat(store, id, { title });
|
|
124
128
|
}
|
|
125
|
-
export function setChatRagEnabled(store, id,
|
|
126
|
-
return patchChat(store, id, { ragEnabled });
|
|
129
|
+
export function setChatRagEnabled(store, id, opts) {
|
|
130
|
+
return patchChat(store, id, { ragEnabled: opts.ragEnabled });
|
|
127
131
|
}
|
|
128
132
|
export async function setChatGroup(store, id, groupId) {
|
|
129
133
|
const target = groupId || undefined;
|
|
130
|
-
if (target)
|
|
134
|
+
if (target) {
|
|
131
135
|
await mustGetActiveChatGroup(store, target);
|
|
136
|
+
}
|
|
132
137
|
const current = await mustGetActiveChat(store, id);
|
|
133
138
|
const kept = (current.groupId || undefined) === target;
|
|
134
139
|
return patchChatRow(store, current, kept ? { groupId: target } : { groupId: target, rank: undefined, rankedAt: undefined });
|
|
@@ -136,23 +141,26 @@ export async function setChatGroup(store, id, groupId) {
|
|
|
136
141
|
export async function moveChat(store, id, { groupId, afterId }) {
|
|
137
142
|
const target = groupId || undefined;
|
|
138
143
|
const anchor = afterId || undefined;
|
|
139
|
-
if (anchor === id)
|
|
144
|
+
if (anchor === id) {
|
|
140
145
|
throw new Error(`a chat cannot be placed after itself: ${id}`);
|
|
146
|
+
}
|
|
141
147
|
const now = Date.now();
|
|
142
148
|
const snap = store.view.snapshot();
|
|
143
149
|
let moved;
|
|
144
150
|
let placement;
|
|
145
|
-
let
|
|
151
|
+
let respaced;
|
|
146
152
|
try {
|
|
147
153
|
if (target) {
|
|
148
154
|
const group = await snap.get(CHAT_GROUPS, { id: target });
|
|
149
|
-
if (!group || group.deletedAt)
|
|
155
|
+
if (!group || group.deletedAt) {
|
|
150
156
|
throw new Error(`chat group not found: ${target}`);
|
|
157
|
+
}
|
|
151
158
|
}
|
|
152
159
|
const { chats } = await listSidebarIn(snap);
|
|
153
160
|
const me = chats.find((chat) => chat.id === id);
|
|
154
|
-
if (!me)
|
|
161
|
+
if (!me) {
|
|
155
162
|
throw new Error(`chat not found: ${id}`);
|
|
163
|
+
}
|
|
156
164
|
moved = me;
|
|
157
165
|
const siblings = chats
|
|
158
166
|
.filter((sibling) => sibling.id !== id && (sibling.groupId || undefined) === target)
|
|
@@ -165,7 +173,11 @@ export async function moveChat(store, id, { groupId, afterId }) {
|
|
|
165
173
|
}
|
|
166
174
|
}
|
|
167
175
|
placement = place(siblings, chatSortKey, { at, now });
|
|
168
|
-
|
|
176
|
+
respaced = await Promise.all(placement.respaced.map(async ({ row, rank }) => ({
|
|
177
|
+
chat: (await snap.get(CHATS, { id: row.id })) ?? row,
|
|
178
|
+
lastActivityAt: row.lastActivityAt,
|
|
179
|
+
rank
|
|
180
|
+
})));
|
|
169
181
|
}
|
|
170
182
|
finally {
|
|
171
183
|
await snap.close();
|
|
@@ -177,8 +189,8 @@ export async function moveChat(store, id, { groupId, afterId }) {
|
|
|
177
189
|
updatedAt: Math.max(now, chat.updatedAt ?? 0)
|
|
178
190
|
});
|
|
179
191
|
const batch = store.batch();
|
|
180
|
-
for (const {
|
|
181
|
-
batch.dispatch('put-chat', { chat: stamp(
|
|
192
|
+
for (const { chat, lastActivityAt, rank } of respaced) {
|
|
193
|
+
batch.dispatch('put-chat', { chat: stamp(chat, lastActivityAt, rank) });
|
|
182
194
|
}
|
|
183
195
|
const { lastActivityAt, ...chat } = moved;
|
|
184
196
|
batch.dispatch('put-chat', {
|
|
@@ -217,14 +229,16 @@ export async function removeChatKnowledge(store, chatId, at) {
|
|
|
217
229
|
}
|
|
218
230
|
await batch.flush();
|
|
219
231
|
}
|
|
220
|
-
export async function removeChatAttachments(store,
|
|
232
|
+
export async function removeChatAttachments(store, chatId, { deviceId, at }) {
|
|
221
233
|
const batch = store.batch();
|
|
222
234
|
for (const chunk of await listChunks(store, { chatId, type: 'attachment' })) {
|
|
223
235
|
const attachment = chunk.attachment;
|
|
224
|
-
if (!attachment || attachment.deletedAt)
|
|
236
|
+
if (!attachment || attachment.deletedAt) {
|
|
225
237
|
continue;
|
|
226
|
-
|
|
238
|
+
}
|
|
239
|
+
if (!b4a.equals(chunk.originDeviceId, deviceId)) {
|
|
227
240
|
continue;
|
|
241
|
+
}
|
|
228
242
|
const tombstone = { ...attachment, deletedAt: at };
|
|
229
243
|
batch.dispatch('update-chunk', updateOp(chunk, { id: chunk.id, attachment: tombstone }));
|
|
230
244
|
}
|
|
@@ -235,7 +249,7 @@ export async function deleteChat(store, deviceId, id) {
|
|
|
235
249
|
const now = Date.now();
|
|
236
250
|
if (deviceId) {
|
|
237
251
|
await cancelActiveRuns(store, deviceId, id);
|
|
238
|
-
await removeChatAttachments(store,
|
|
252
|
+
await removeChatAttachments(store, id, { deviceId, at: now });
|
|
239
253
|
}
|
|
240
254
|
await removeChatKnowledge(store, id, now);
|
|
241
255
|
const deleted = { ...current, deletedAt: now, updatedAt: now };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
|
-
import type { QvacChunk } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
2
|
+
import type { QvacChunk, QvacUpdateChunkOperation } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
3
3
|
import type { Mesh, MeshDispatcher } from './mesh.ts';
|
|
4
4
|
import { type Bounds } from './range.ts';
|
|
5
5
|
type ChunkPayload = Pick<QvacChunk, 'userMessage' | 'content' | 'thinking' | 'toolCall' | 'toolResult' | 'attachment' | 'approvalRequest' | 'runStatus' | 'runRequest' | 'sources' | 'compaction'>;
|
|
@@ -25,31 +25,27 @@ type ListChunksInput = Bounds & {
|
|
|
25
25
|
type?: QvacChunk['type'];
|
|
26
26
|
types?: ReadonlyArray<QvacChunk['type']>;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export interface FindChunksOfTypeInput extends Bounds {
|
|
29
|
+
readonly chatId: string;
|
|
30
|
+
readonly type: QvacChunk['type'];
|
|
31
|
+
}
|
|
32
|
+
export declare function findChunksOfType(snap: HyperDB, { chatId, type, ...bounds }: FindChunksOfTypeInput): Promise<QvacChunk[]>;
|
|
29
33
|
export declare function listChunks(store: Mesh, { chatId, type, types, ...bounds }: ListChunksInput): Promise<ReadChunk[]>;
|
|
30
34
|
export declare function listAttachmentsByKind(store: Mesh, { kind, origin, ...bounds }: ListAttachmentsByKindInput): Promise<ReadChunk[]>;
|
|
31
35
|
export declare function getChunk(store: Mesh, id: string): Promise<QvacChunk | null>;
|
|
32
|
-
export
|
|
33
|
-
id: string;
|
|
34
|
-
}
|
|
36
|
+
export interface AppendedChunk {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function appendChunk(store: Mesh, { id, chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, ...payload }: AppendChunkInput, into?: MeshDispatcher): Promise<AppendedChunk>;
|
|
35
40
|
export declare function updateChunk(store: Mesh, { id, runStatus, attachment }: UpdateChunkInput): Promise<QvacChunk>;
|
|
36
|
-
export declare function updateOp(chunk: QvacChunk, { id, runStatus, attachment }: UpdateChunkInput):
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
updatedAt: number;
|
|
46
|
-
};
|
|
47
|
-
export declare function resolveApproval(store: Mesh, { id, approved, scope, expiresAt, agentId }: {
|
|
48
|
-
id: string;
|
|
49
|
-
approved: boolean;
|
|
50
|
-
scope?: 'once' | 'always';
|
|
51
|
-
expiresAt?: number;
|
|
52
|
-
agentId?: string;
|
|
53
|
-
}): Promise<QvacChunk>;
|
|
41
|
+
export declare function updateOp(chunk: QvacChunk, { id, runStatus, attachment }: UpdateChunkInput): QvacUpdateChunkOperation;
|
|
42
|
+
export interface ResolveApprovalInput {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly approved: boolean;
|
|
45
|
+
readonly scope?: 'once' | 'always';
|
|
46
|
+
readonly expiresAt?: number;
|
|
47
|
+
readonly agentId?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function resolveApproval(store: Mesh, { id, approved, scope, expiresAt, agentId }: ResolveApprovalInput): Promise<QvacChunk>;
|
|
54
50
|
export declare function listRunRequests(store: Mesh, deviceId: Buffer | null): Promise<QvacChunk[]>;
|
|
55
51
|
export {};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { CHUNK_PAYLOAD_FIELDS, ragSourcesWithinBounds } from '../../schema/qvac.js';
|
|
2
|
-
import { chunkTypeOrdinal
|
|
2
|
+
import { chunkTypeOrdinal } from '../../schema/indexes.js';
|
|
3
|
+
import { mediaKindOrdinal } from '../../schema/media-kind.js';
|
|
3
4
|
import { putApprovalRule } from './approval-rules.js';
|
|
4
5
|
import { linkAttachment } from './attachment-link.js';
|
|
5
6
|
import { randomId } from './id.js';
|
|
6
7
|
import { keyRange } from './range.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const CHUNKS_BY_TYPE = '@qvac/chunks-by-type';
|
|
10
|
-
const HISTORY_CHUNKS = '@qvac/history-chunks';
|
|
11
|
-
const ATTACHMENTS_BY_MEDIA_KIND = '@qvac/attachments-by-media-kind';
|
|
12
|
-
const ATTACHMENTS_BY_MEDIA_KIND_ORIGIN = '@qvac/attachments-by-media-kind-origin';
|
|
8
|
+
import b4a from 'b4a';
|
|
9
|
+
import { AGENTS, ATTACHMENTS_BY_MEDIA_KIND, ATTACHMENTS_BY_MEDIA_KIND_ORIGIN, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, HISTORY_CHUNKS, RUN_REQUESTS } from './collections.js';
|
|
13
10
|
export const HISTORY_CHUNK_TYPES = [
|
|
14
11
|
'user-message',
|
|
15
12
|
'run-request',
|
|
@@ -19,15 +16,16 @@ export const HISTORY_CHUNK_TYPES = [
|
|
|
19
16
|
];
|
|
20
17
|
function linkChunks(store, chunks) {
|
|
21
18
|
const mint = store.attachmentUrl;
|
|
22
|
-
if (!mint)
|
|
19
|
+
if (!mint) {
|
|
23
20
|
return chunks;
|
|
21
|
+
}
|
|
24
22
|
return chunks.map((chunk) => chunk.attachment ? { ...chunk, attachment: linkAttachment(mint, chunk.attachment) } : chunk);
|
|
25
23
|
}
|
|
26
24
|
export async function recordLinks(store, chunks) {
|
|
27
25
|
await store.fileIndex?.record(chunks.filter((chunk) => chunk.attachment?.url));
|
|
28
26
|
return chunks;
|
|
29
27
|
}
|
|
30
|
-
export function findChunksOfType(snap, chatId, type, bounds
|
|
28
|
+
export function findChunksOfType(snap, { chatId, type, ...bounds }) {
|
|
31
29
|
const prefix = { chatId, type: chunkTypeOrdinal(type) };
|
|
32
30
|
return snap
|
|
33
31
|
.find(CHUNKS_BY_TYPE, keyRange(prefix, 'seq', bounds))
|
|
@@ -35,8 +33,9 @@ export function findChunksOfType(snap, chatId, type, bounds = {}) {
|
|
|
35
33
|
}
|
|
36
34
|
export async function listChunks(store, { chatId, type, types, ...bounds }) {
|
|
37
35
|
const selected = selectedChunkTypes(type, types);
|
|
38
|
-
if (selected?.length === 0)
|
|
36
|
+
if (selected?.length === 0) {
|
|
39
37
|
return [];
|
|
38
|
+
}
|
|
40
39
|
if (selected && selected.length > 1 && !isHistorySelection(selected)) {
|
|
41
40
|
throw new Error('multiple chunk types require a mapped index');
|
|
42
41
|
}
|
|
@@ -82,8 +81,9 @@ function selectedChunkTypes(type, types) {
|
|
|
82
81
|
if (!type && types === undefined)
|
|
83
82
|
return null;
|
|
84
83
|
const selected = new Set(types);
|
|
85
|
-
if (type)
|
|
84
|
+
if (type) {
|
|
86
85
|
selected.add(type);
|
|
86
|
+
}
|
|
87
87
|
return [...selected];
|
|
88
88
|
}
|
|
89
89
|
function isHistorySelection(types) {
|
|
@@ -102,8 +102,9 @@ export async function getChunk(store, id) {
|
|
|
102
102
|
}
|
|
103
103
|
async function mustGetChunk(store, id) {
|
|
104
104
|
const chunk = await getChunk(store, id);
|
|
105
|
-
if (!chunk)
|
|
105
|
+
if (!chunk) {
|
|
106
106
|
throw new Error(`chunk not found: ${id}`);
|
|
107
|
+
}
|
|
107
108
|
return chunk;
|
|
108
109
|
}
|
|
109
110
|
function assertPayloadMatchesType(type, payload) {
|
|
@@ -127,8 +128,9 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
|
|
|
127
128
|
if (capability && type !== 'run-request') {
|
|
128
129
|
throw new Error('chunk payload invalid: only a run-request carries a capability');
|
|
129
130
|
}
|
|
130
|
-
if (type === 'user-message' && !store.ourMemberId)
|
|
131
|
+
if (type === 'user-message' && !store.ourMemberId) {
|
|
131
132
|
await store.refreshOurMember();
|
|
133
|
+
}
|
|
132
134
|
if (parentId) {
|
|
133
135
|
const parent = await getChunk(store, parentId);
|
|
134
136
|
if (!parent || parent.chatId !== chatId) {
|
|
@@ -150,14 +152,15 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
|
|
|
150
152
|
capabilityArgs,
|
|
151
153
|
enhance,
|
|
152
154
|
createdAt: Date.now(),
|
|
153
|
-
|
|
154
|
-
?
|
|
155
|
-
: undefined
|
|
155
|
+
senderMemberId: type === 'user-message' && store.ourDeviceId && b4a.equals(store.ourDeviceId, originDeviceId)
|
|
156
|
+
? store.ourMemberId || undefined
|
|
157
|
+
: undefined,
|
|
156
158
|
...payload
|
|
157
159
|
};
|
|
158
160
|
await into.dispatch('append-chunk', op);
|
|
159
|
-
if (type === 'attachment')
|
|
161
|
+
if (type === 'attachment') {
|
|
160
162
|
await store.fileIndex?.record([op]);
|
|
163
|
+
}
|
|
161
164
|
return { id };
|
|
162
165
|
}
|
|
163
166
|
export async function updateChunk(store, { id, runStatus, attachment }) {
|
|
@@ -208,21 +211,24 @@ export async function listRunRequests(store, deviceId) {
|
|
|
208
211
|
return [];
|
|
209
212
|
const snap = store.view.snapshot();
|
|
210
213
|
try {
|
|
211
|
-
const requests = await snap.find(
|
|
214
|
+
const requests = await snap.find(RUN_REQUESTS).toArray();
|
|
212
215
|
const providers = new Map();
|
|
213
216
|
const mine = [];
|
|
214
217
|
for (const request of requests) {
|
|
215
218
|
if (store.closing)
|
|
216
219
|
return mine;
|
|
217
220
|
const agentId = request.runRequest?.agentId;
|
|
218
|
-
if (!agentId)
|
|
221
|
+
if (!agentId) {
|
|
219
222
|
continue;
|
|
223
|
+
}
|
|
220
224
|
if (!providers.has(agentId)) {
|
|
221
|
-
const agent = await snap.get(
|
|
225
|
+
const agent = await snap.get(AGENTS, { id: agentId });
|
|
222
226
|
providers.set(agentId, agent?.providerDeviceId);
|
|
223
227
|
}
|
|
224
|
-
|
|
228
|
+
const provider = providers.get(agentId);
|
|
229
|
+
if (provider && b4a.equals(provider, deviceId)) {
|
|
225
230
|
mine.push(request);
|
|
231
|
+
}
|
|
226
232
|
}
|
|
227
233
|
return mine;
|
|
228
234
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare const CHUNKS = "@qvac/chunks";
|
|
2
|
+
export declare const CHUNK_COUNTERS = "@qvac/chunk-counters";
|
|
3
|
+
export declare const AGENTS = "@qvac/agents";
|
|
4
|
+
export declare const APPROVAL_RULES = "@qvac/approval-rules";
|
|
5
|
+
export declare const CHATS = "@qvac/chats";
|
|
6
|
+
export declare const DEVICES = "@qvac/devices";
|
|
7
|
+
export declare const MESH_BLIND_PEERS = "@qvac/mesh-blind-peers";
|
|
8
|
+
export declare const KNOWLEDGE = "@qvac/knowledge";
|
|
9
|
+
export declare const KNOWLEDGE_ARTIFACTS = "@qvac/knowledge-artifacts";
|
|
10
|
+
export declare const INDEXING_STATUS = "@qvac/indexing-status";
|
|
11
|
+
export declare const CHUNKS_BY_CHAT = "@qvac/chunks-by-chat";
|
|
12
|
+
export declare const CHUNKS_BY_TYPE = "@qvac/chunks-by-type";
|
|
13
|
+
export declare const RUN_REQUESTS = "@qvac/run-requests";
|
|
14
|
+
export declare const ACTIVE_AGENTS = "@qvac/active-agents";
|
|
15
|
+
export declare const ACTIVE_CHATS = "@qvac/active-chats";
|
|
16
|
+
export declare const ACTIVE_CHATS_BY_AGENT = "@qvac/active-chats-by-agent";
|
|
17
|
+
export declare const KNOWLEDGE_BY_CHAT = "@qvac/knowledge-by-chat";
|
|
18
|
+
export declare const KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE = "@qvac/knowledge-artifacts-by-knowledge";
|
|
19
|
+
export declare const INDEXING_STATUS_BY_KNOWLEDGE = "@qvac/indexing-status-by-knowledge";
|
|
20
|
+
export declare const HISTORY_CHUNKS = "@qvac/history-chunks";
|
|
21
|
+
export declare const INDEXING_STATUS_BY_CHAT = "@qvac/indexing-status-by-chat";
|
|
22
|
+
export declare const ACTIVE_KNOWLEDGE_BY_CHAT = "@qvac/active-knowledge-by-chat";
|
|
23
|
+
export declare const TOOL_CONFIGS = "@qvac/tool-configs";
|
|
24
|
+
export declare const TOOL_ACTIVITY = "@qvac/tool-activity";
|
|
25
|
+
export declare const TOOL_ACTIVITY_COUNTER = "@qvac/tool-activity-counter";
|
|
26
|
+
export declare const ACTIVE_TOOL_CONFIGS_BY_AGENT = "@qvac/active-tool-configs-by-agent";
|
|
27
|
+
export declare const ATTACHMENTS_BY_MEDIA_KIND = "@qvac/attachments-by-media-kind";
|
|
28
|
+
export declare const ATTACHMENTS_BY_MEDIA_KIND_ORIGIN = "@qvac/attachments-by-media-kind-origin";
|
|
29
|
+
export declare const TOOL_ACTIVITY_BY_AGENT = "@qvac/tool-activity-by-agent";
|
|
30
|
+
export declare const WRITER_ACTIVITY = "@qvac/writer-activity";
|
|
31
|
+
export declare const DEVICES_BY_WRITER_KEY = "@qvac/devices-by-writer-key";
|
|
32
|
+
export declare const DEVICE_ATTESTATIONS = "@qvac/device-attestations";
|
|
33
|
+
export declare const MEMBERS = "@qvac/members";
|
|
34
|
+
export declare const CHAT_GROUPS = "@qvac/chat-groups";
|
|
35
|
+
export declare const ACTIVE_CHAT_GROUPS = "@qvac/active-chat-groups";
|
|
36
|
+
export declare const LIVE_WRITERS_BY_MOST_RECENT = "@qvac/live-writers-by-most-recent";
|
|
37
|
+
export declare const JOINED_MESHES = "@qvac/joined-meshes";
|
|
38
|
+
export declare const AGENTS_BY_PROVIDER = "@qvac/agents-by-provider";
|
|
39
|
+
export declare const DEFAULT_AGENTS = "@qvac/default-agents";
|
|
40
|
+
export declare const LOCAL_CONFIG = "@local/config";
|
|
41
|
+
export declare const LOCAL_DEVICE = "@local/device";
|
|
42
|
+
export declare const LOCAL_APP_CONFIG = "@local/app-config";
|
|
43
|
+
export declare const LOCAL_MODEL_DOWNLOAD = "@local/model-download";
|
|
44
|
+
export declare const LOCAL_CUSTOM_MODEL = "@local/custom-model";
|
|
45
|
+
export declare const LOCAL_IDENTITY = "@local/identity";
|
|
46
|
+
export declare const LOCAL_CHAT_NOTIFY = "@local/chat-notify";
|
|
47
|
+
export declare const LOCAL_MODEL_NOTIFY = "@local/model-notify";
|
|
48
|
+
export declare const LOCAL_ACTIVE_MESH = "@local/active-mesh";
|
|
49
|
+
export declare const LOCAL_MESH_MEMBERSHIP = "@local/mesh-membership";
|
|
50
|
+
export declare const LOCAL_MESH_DEPARTURE = "@local/mesh-departure";
|
|
51
|
+
export declare const LOCAL_MEMBER_PROOF = "@local/member-proof";
|
|
52
|
+
export declare const LOCAL_ACCOUNT_RECOVERY = "@local/account-recovery";
|
|
53
|
+
export declare const LOCAL_CHAT_ORDER = "@local/chat-order";
|
|
54
|
+
export declare const LOCAL_CHAT_ORDER_BY_KEY = "@local/chat-order-by-key";
|
|
55
|
+
export declare const LOCAL_FILES = "@local/files";
|
|
56
|
+
export declare const LOCAL_FILES_BY_BLOB = "@local/files-by-blob";
|
|
57
|
+
export declare const LOCAL_RECLAIMABLE_FILES_BY_LAST_ACCESSED = "@local/reclaimable-files-by-last-accessed";
|
|
58
|
+
export declare const LOCAL_LIVE_FILES = "@local/live-files";
|
|
59
|
+
export declare const LOCAL_MESH_SESSION = "@local/mesh-session";
|
|
60
|
+
export declare const LOCAL_MESH_HISTORY = "@local/mesh-history";
|
|
61
|
+
export declare const LOCAL_MEMBERSHIP = "@local/membership";
|
|
62
|
+
export declare const INDEX_BACKFILLS = "@qvac/index-backfills";
|
|
63
|
+
export declare const LIVE_DEVICES_BY_WRITER_KEY = "@qvac/live-devices-by-writer-key";
|
|
64
|
+
export declare const MEMBER_REMOVALS = "@qvac/member-removals";
|
|
65
|
+
export declare const INVITE_SEQUENCES = "@qvac/invite-sequences";
|
|
66
|
+
export declare const MESH_INVITE_SPENDS = "@qvac/mesh-invite-spends";
|
|
67
|
+
export declare const MESH_INVITE_GRANTS = "@qvac/mesh-invite-grants";
|
|
68
|
+
export declare const MESH_FOUNDERS = "@qvac/mesh-founders";
|
|
69
|
+
export declare const MESH_KINDS = "@qvac/mesh-kinds";
|