@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,20 +1,20 @@
|
|
|
1
1
|
import type { Harness } from './assistant.ts';
|
|
2
2
|
import { type ConfigEngine } from './oauth.ts';
|
|
3
3
|
import type { OAuthRouteLike } from './oauth/keys.ts';
|
|
4
|
-
export
|
|
4
|
+
export interface CredentialEntry {
|
|
5
5
|
key: string;
|
|
6
6
|
token?: string | null;
|
|
7
7
|
expiresAt?: number | null;
|
|
8
8
|
agentId?: string | null;
|
|
9
9
|
skill?: string | null;
|
|
10
|
-
}
|
|
11
|
-
export
|
|
10
|
+
}
|
|
11
|
+
export interface SettingEntry {
|
|
12
12
|
skill: string;
|
|
13
13
|
key: string;
|
|
14
14
|
value: string;
|
|
15
15
|
agentId?: string | null;
|
|
16
|
-
}
|
|
17
|
-
export
|
|
16
|
+
}
|
|
17
|
+
export interface PusherSkill {
|
|
18
18
|
name: string;
|
|
19
19
|
credentials?: readonly string[];
|
|
20
20
|
requires?: {
|
|
@@ -28,7 +28,7 @@ export type PusherSkill = {
|
|
|
28
28
|
}>;
|
|
29
29
|
}>;
|
|
30
30
|
};
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
export interface CredentialEngine extends ConfigEngine {
|
|
33
33
|
configWatch(req: {
|
|
34
34
|
key: string;
|
|
@@ -41,26 +41,21 @@ export interface CredentialEngine extends ConfigEngine {
|
|
|
41
41
|
}>;
|
|
42
42
|
}>;
|
|
43
43
|
}
|
|
44
|
-
export
|
|
44
|
+
export interface CredentialTarget {
|
|
45
45
|
setCredentials: NonNullable<Harness['setCredentials']>;
|
|
46
46
|
setSkillSettings?: (entries: ReadonlyArray<SettingEntry>) => void | Promise<void>;
|
|
47
47
|
skills?: (agentId?: string | null, modelName?: string | null, options?: {
|
|
48
48
|
readonly skipCredentialProbe?: boolean;
|
|
49
49
|
}) => Promise<ReadonlyArray<PusherSkill>>;
|
|
50
|
-
}
|
|
51
|
-
export
|
|
50
|
+
}
|
|
51
|
+
export interface CredentialPusherLogger {
|
|
52
52
|
warn(...args: unknown[]): void;
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
54
|
export type CredentialPusherHandle = (() => Promise<void>) & {
|
|
55
55
|
sync(): Promise<void>;
|
|
56
56
|
};
|
|
57
|
-
export declare function nextRefreshDelay(entries: ReadonlyArray<
|
|
58
|
-
expiresAt?: number | null;
|
|
59
|
-
}>, now?: number): number;
|
|
57
|
+
export declare function nextRefreshDelay(entries: ReadonlyArray<Pick<CredentialEntry, 'expiresAt'>>, now?: number): number;
|
|
60
58
|
export declare function credentialOwners(catalog: ReadonlyArray<PusherSkill>): ReadonlyMap<string, readonly string[]>;
|
|
61
|
-
export declare function settingFields(catalog: ReadonlyArray<PusherSkill>): ReadonlyArray<
|
|
62
|
-
skill: string;
|
|
63
|
-
key: string;
|
|
64
|
-
}>;
|
|
59
|
+
export declare function settingFields(catalog: ReadonlyArray<PusherSkill>): ReadonlyArray<Pick<SettingEntry, 'skill' | 'key'>>;
|
|
65
60
|
export declare function settingConfigKey(agentId: string | undefined, skill: string, key: string): string;
|
|
66
61
|
export declare function startCredentialPusher(harness: CredentialTarget, engine: CredentialEngine, logger?: CredentialPusherLogger | null): CredentialPusherHandle;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY } from './obsidian-key.js';
|
|
2
2
|
import { scopedKey } from './oauth.js';
|
|
3
3
|
import { oauthSpecs } from './oauth/registry.js';
|
|
4
|
-
import { resolveOAuthCredential } from './oauth/resolve.js';
|
|
4
|
+
import { REFRESH_SKEW_MS, resolveOAuthCredential } from './oauth/resolve.js';
|
|
5
5
|
import { buildProviderConfig } from './oauth/providers.js';
|
|
6
6
|
import { refreshOAuthTokens } from './oauth/token-exchange.js';
|
|
7
7
|
import ScopeLock from 'scope-lock';
|
|
8
8
|
import { credentialSlots } from '@qvac/harness/lib/tools/skills/credential-slots.ts';
|
|
9
|
-
import {
|
|
9
|
+
import { errorMessage } from './guards.js';
|
|
10
10
|
const PLAIN_KEYS = ['github_access_token', OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY];
|
|
11
11
|
const REFRESH_INTERVAL = 10 * 60 * 1000;
|
|
12
12
|
const MIN_REFRESH_DELAY = 30_000;
|
|
@@ -17,12 +17,14 @@ export function nextRefreshDelay(entries, now = Date.now()) {
|
|
|
17
17
|
let nearest = null;
|
|
18
18
|
for (const entry of entries) {
|
|
19
19
|
if (typeof entry.expiresAt === 'number' && entry.expiresAt > 0) {
|
|
20
|
-
if (nearest === null || entry.expiresAt < nearest)
|
|
20
|
+
if (nearest === null || entry.expiresAt < nearest) {
|
|
21
21
|
nearest = entry.expiresAt;
|
|
22
|
+
}
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
if (nearest === null)
|
|
25
|
+
if (nearest === null) {
|
|
25
26
|
return REFRESH_INTERVAL;
|
|
27
|
+
}
|
|
26
28
|
return Math.min(REFRESH_INTERVAL, Math.max(MIN_REFRESH_DELAY, nearest - now - REFRESH_SKEW_MS));
|
|
27
29
|
}
|
|
28
30
|
async function oauthEntry(engine, spec, agentId) {
|
|
@@ -35,8 +37,9 @@ async function oauthEntry(engine, spec, agentId) {
|
|
|
35
37
|
requireClientSecret: spec.tokenAuth !== 'pkce-only',
|
|
36
38
|
refresh: (args) => refreshOAuthTokens(buildProviderConfig(spec, { clientId: args.clientId, clientSecret: args.clientSecret }), args.refreshToken)
|
|
37
39
|
});
|
|
38
|
-
if (!token)
|
|
40
|
+
if (!token) {
|
|
39
41
|
return null;
|
|
42
|
+
}
|
|
40
43
|
const { value } = await engine.configGet({
|
|
41
44
|
key: scopedKey(agentId, stateKey)
|
|
42
45
|
});
|
|
@@ -49,18 +52,19 @@ async function oauthEntry(engine, spec, agentId) {
|
|
|
49
52
|
return {
|
|
50
53
|
key: credentialKey,
|
|
51
54
|
token,
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
expiresAt,
|
|
56
|
+
agentId
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
async function plainEntry(engine, key, agentId) {
|
|
57
60
|
const { value } = await engine.configGet({ key: scopedKey(agentId, key) });
|
|
58
|
-
if (typeof value !== 'string' || value === '')
|
|
61
|
+
if (typeof value !== 'string' || value === '') {
|
|
59
62
|
return null;
|
|
63
|
+
}
|
|
60
64
|
return {
|
|
61
65
|
key,
|
|
62
66
|
token: value,
|
|
63
|
-
|
|
67
|
+
agentId
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
70
|
export function credentialOwners(catalog) {
|
|
@@ -68,8 +72,9 @@ export function credentialOwners(catalog) {
|
|
|
68
72
|
for (const skill of catalog) {
|
|
69
73
|
for (const key of credentialSlots(skill).flat()) {
|
|
70
74
|
const list = owners.get(key) ?? [];
|
|
71
|
-
if (!list.includes(skill.name))
|
|
75
|
+
if (!list.includes(skill.name)) {
|
|
72
76
|
list.push(skill.name);
|
|
77
|
+
}
|
|
73
78
|
owners.set(key, list);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
@@ -78,14 +83,13 @@ export function credentialOwners(catalog) {
|
|
|
78
83
|
export function settingFields(catalog) {
|
|
79
84
|
const fields = [];
|
|
80
85
|
for (const skill of catalog) {
|
|
81
|
-
for (const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
continue;
|
|
87
|
-
fields.push({ skill: skill.name, key: field.key });
|
|
86
|
+
for (const field of (skill.setup?.routes ?? []).flatMap((route) => route.fields ?? [])) {
|
|
87
|
+
if (field.secret === true)
|
|
88
|
+
continue;
|
|
89
|
+
if (fields.some((f) => f.skill === skill.name && f.key === field.key)) {
|
|
90
|
+
continue;
|
|
88
91
|
}
|
|
92
|
+
fields.push({ skill: skill.name, key: field.key });
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
return fields;
|
|
@@ -97,7 +101,7 @@ function fanOut(entry, owners) {
|
|
|
97
101
|
const skills = owners.get(entry.key) ?? [];
|
|
98
102
|
return skills.length > 0 ? skills.map((skill) => ({ ...entry, skill })) : [entry];
|
|
99
103
|
}
|
|
100
|
-
async function resolveScope(
|
|
104
|
+
async function resolveScope(agentId, { engine, last, owners, specs, logger }) {
|
|
101
105
|
const entries = [];
|
|
102
106
|
for (const spec of specs) {
|
|
103
107
|
const mk = storeKey(spec.credentialKey, agentId);
|
|
@@ -114,8 +118,9 @@ async function resolveScope(engine, agentId, last, owners, specs, logger) {
|
|
|
114
118
|
catch (err) {
|
|
115
119
|
logger?.warn('credential-pusher', `credential resolve failed for ${spec.credentialKey}`, errorMessage(err));
|
|
116
120
|
const kept = last.get(mk);
|
|
117
|
-
if (kept)
|
|
121
|
+
if (kept) {
|
|
118
122
|
entries.push(...fanOut(kept, owners));
|
|
123
|
+
}
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
const specKeys = new Set(specs.map((spec) => spec.credentialKey));
|
|
@@ -136,22 +141,25 @@ async function resolveScope(engine, agentId, last, owners, specs, logger) {
|
|
|
136
141
|
catch (err) {
|
|
137
142
|
logger?.warn('credential-pusher', `credential read failed for ${key}`, errorMessage(err));
|
|
138
143
|
const kept = last.get(mk);
|
|
139
|
-
if (kept)
|
|
144
|
+
if (kept) {
|
|
140
145
|
entries.push(...fanOut(kept, owners));
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
return entries;
|
|
144
150
|
}
|
|
145
|
-
async function resolveSettings(engine, scopes, catalog, logger) {
|
|
151
|
+
async function resolveSettings(engine, scopes, { catalog, logger }) {
|
|
146
152
|
const fields = settingFields(catalog);
|
|
147
|
-
if (fields.length === 0)
|
|
153
|
+
if (fields.length === 0) {
|
|
148
154
|
return [];
|
|
155
|
+
}
|
|
149
156
|
const resolved = await Promise.all(scopes.flatMap((agentId) => fields.map(async ({ skill, key }) => {
|
|
150
157
|
try {
|
|
151
158
|
const { value } = await engine.configGet({ key: settingConfigKey(agentId, skill, key) });
|
|
152
|
-
if (typeof value !== 'string' || value === '')
|
|
159
|
+
if (typeof value !== 'string' || value === '') {
|
|
153
160
|
return null;
|
|
154
|
-
|
|
161
|
+
}
|
|
162
|
+
return { skill, key, value, agentId };
|
|
155
163
|
}
|
|
156
164
|
catch (err) {
|
|
157
165
|
logger?.warn('credential-pusher', `setting read failed for ${skill}.${key}`, errorMessage(err));
|
|
@@ -160,8 +168,9 @@ async function resolveSettings(engine, scopes, catalog, logger) {
|
|
|
160
168
|
})));
|
|
161
169
|
const entries = [];
|
|
162
170
|
for (const entry of resolved) {
|
|
163
|
-
if (entry)
|
|
171
|
+
if (entry) {
|
|
164
172
|
entries.push(entry);
|
|
173
|
+
}
|
|
165
174
|
}
|
|
166
175
|
return entries;
|
|
167
176
|
}
|
|
@@ -175,10 +184,12 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
175
184
|
const stream = engine.configWatch({ key: scopedKey(undefined, key) });
|
|
176
185
|
watches.set(key, stream);
|
|
177
186
|
(async () => {
|
|
178
|
-
for await (const _ of stream)
|
|
187
|
+
for await (const _ of stream) {
|
|
179
188
|
schedule();
|
|
180
|
-
|
|
189
|
+
}
|
|
190
|
+
if (disposed || watches.get(key) !== stream) {
|
|
181
191
|
return;
|
|
192
|
+
}
|
|
182
193
|
logger?.warn('credential-pusher', `credential watch ended for ${key}, change propagation degrades to the interval until restart`);
|
|
183
194
|
})().catch((err) => {
|
|
184
195
|
if (disposed || watches.get(key) !== stream)
|
|
@@ -200,20 +211,23 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
200
211
|
watches.delete(key);
|
|
201
212
|
}
|
|
202
213
|
for (const key of wanted) {
|
|
203
|
-
if (!watches.has(key))
|
|
214
|
+
if (!watches.has(key)) {
|
|
204
215
|
watch(key);
|
|
216
|
+
}
|
|
205
217
|
}
|
|
206
218
|
for (const mk of last.keys()) {
|
|
207
219
|
const key = mk.includes('\0') ? mk.slice(mk.indexOf('\0') + 1) : mk;
|
|
208
|
-
if (!wanted.has(key))
|
|
220
|
+
if (!wanted.has(key)) {
|
|
209
221
|
last.delete(mk);
|
|
222
|
+
}
|
|
210
223
|
}
|
|
211
224
|
};
|
|
212
225
|
const armTimer = (delay) => {
|
|
213
226
|
if (disposed)
|
|
214
227
|
return;
|
|
215
|
-
if (timer)
|
|
228
|
+
if (timer) {
|
|
216
229
|
clearTimeout(timer);
|
|
230
|
+
}
|
|
217
231
|
timer = setTimeout(() => {
|
|
218
232
|
timer = null;
|
|
219
233
|
schedule();
|
|
@@ -234,26 +248,30 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
234
248
|
const entries = [];
|
|
235
249
|
try {
|
|
236
250
|
const skills = await catalog();
|
|
237
|
-
if (skills === null)
|
|
251
|
+
if (skills === null) {
|
|
238
252
|
return;
|
|
253
|
+
}
|
|
239
254
|
const owners = credentialOwners(skills);
|
|
240
255
|
const specs = oauthSpecs(skills);
|
|
241
256
|
syncWatches(specs.map((spec) => spec.credentialKey));
|
|
242
257
|
const ids = (await engine.listAgents({})).agents.map((agent) => agent.id);
|
|
243
258
|
const scopes = [undefined, ...ids];
|
|
259
|
+
const resolution = { engine, last, owners, specs, logger };
|
|
244
260
|
for (const agentId of scopes) {
|
|
245
|
-
entries.push(...(await resolveScope(
|
|
261
|
+
entries.push(...(await resolveScope(agentId, resolution)));
|
|
246
262
|
}
|
|
247
|
-
if (disposed)
|
|
263
|
+
if (disposed) {
|
|
248
264
|
return;
|
|
265
|
+
}
|
|
249
266
|
await harness.setCredentials(entries);
|
|
250
267
|
if (harness.setSkillSettings) {
|
|
251
|
-
await harness.setSkillSettings(await resolveSettings(engine, scopes, skills, logger));
|
|
268
|
+
await harness.setSkillSettings(await resolveSettings(engine, scopes, { catalog: skills, logger }));
|
|
252
269
|
}
|
|
253
270
|
}
|
|
254
271
|
finally {
|
|
255
|
-
if (!disposed)
|
|
272
|
+
if (!disposed) {
|
|
256
273
|
armTimer(nextRefreshDelay(entries));
|
|
274
|
+
}
|
|
257
275
|
}
|
|
258
276
|
};
|
|
259
277
|
const schedule = async () => {
|
|
@@ -262,8 +280,9 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
262
280
|
if (!(await pushLock.lock()))
|
|
263
281
|
return;
|
|
264
282
|
try {
|
|
265
|
-
if (!disposed)
|
|
283
|
+
if (!disposed) {
|
|
266
284
|
await pushAll();
|
|
285
|
+
}
|
|
267
286
|
}
|
|
268
287
|
catch (err) {
|
|
269
288
|
logger?.warn('credential-pusher', 'credential push failed', errorMessage(err));
|
|
@@ -276,15 +295,17 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
276
295
|
if (disposed)
|
|
277
296
|
return;
|
|
278
297
|
await pushLock.flush();
|
|
279
|
-
if (disposed)
|
|
298
|
+
if (disposed) {
|
|
280
299
|
return;
|
|
300
|
+
}
|
|
281
301
|
if (!(await pushLock.lock())) {
|
|
282
302
|
await pushLock.flush();
|
|
283
303
|
return;
|
|
284
304
|
}
|
|
285
305
|
try {
|
|
286
|
-
if (!disposed)
|
|
306
|
+
if (!disposed) {
|
|
287
307
|
await pushAll();
|
|
308
|
+
}
|
|
288
309
|
}
|
|
289
310
|
catch (err) {
|
|
290
311
|
logger?.warn('credential-pusher', 'credential sync failed', errorMessage(err));
|
|
@@ -298,8 +319,9 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
298
319
|
if (disposed)
|
|
299
320
|
return;
|
|
300
321
|
disposed = true;
|
|
301
|
-
if (timer)
|
|
322
|
+
if (timer) {
|
|
302
323
|
clearTimeout(timer);
|
|
324
|
+
}
|
|
303
325
|
timer = null;
|
|
304
326
|
for (const stream of watches.values()) {
|
|
305
327
|
try {
|
|
@@ -313,6 +335,3 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
313
335
|
};
|
|
314
336
|
return Object.assign(stop, { sync });
|
|
315
337
|
}
|
|
316
|
-
function errorMessage(error) {
|
|
317
|
-
return error instanceof Error ? error.message : String(error);
|
|
318
|
-
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Harness } from './assistant.ts';
|
|
2
2
|
import type { openLocalStore } from './core/local/index.ts';
|
|
3
3
|
type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
|
|
4
|
-
|
|
4
|
+
interface Logger {
|
|
5
5
|
warn(...args: unknown[]): void;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
export type CustomModelTarget = Pick<Harness, 'setCustomModels'>;
|
|
8
|
-
export
|
|
8
|
+
export interface CustomModelPusherOptions {
|
|
9
|
+
logger?: Logger | null;
|
|
10
|
+
onPushed?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function startCustomModelPusher(harness: CustomModelTarget, state: LocalStore, opts?: CustomModelPusherOptions): () => Promise<void>;
|
|
9
13
|
export {};
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { errorMessage } from './guards.js';
|
|
2
|
+
export function startCustomModelPusher(harness, state, opts = {}) {
|
|
3
|
+
const { logger, onPushed } = opts;
|
|
2
4
|
let disposed = false;
|
|
3
5
|
let tail = Promise.resolve();
|
|
4
6
|
let queued = false;
|
|
5
7
|
const push = async () => {
|
|
6
8
|
const rows = await state.getCustomModelRows();
|
|
7
|
-
if (disposed)
|
|
9
|
+
if (disposed) {
|
|
8
10
|
return;
|
|
11
|
+
}
|
|
9
12
|
await harness.setCustomModels?.(rows.map((row) => ({
|
|
10
13
|
name: row.name,
|
|
11
14
|
src: row.src,
|
|
12
|
-
projectionSrc: row.mmprojSrc ?? undefined
|
|
15
|
+
projectionSrc: row.mmprojSrc ?? undefined,
|
|
16
|
+
taskType: row.taskType ?? undefined,
|
|
17
|
+
expectedSize: row.expectedSize || undefined,
|
|
18
|
+
label: row.label || undefined,
|
|
19
|
+
contextLength: row.contextLength || undefined
|
|
13
20
|
})));
|
|
21
|
+
if (!disposed) {
|
|
22
|
+
onPushed?.();
|
|
23
|
+
}
|
|
14
24
|
};
|
|
15
25
|
const schedule = () => {
|
|
16
26
|
if (disposed || queued)
|
|
@@ -18,8 +28,9 @@ export function startCustomModelPusher(harness, state, logger) {
|
|
|
18
28
|
queued = true;
|
|
19
29
|
tail = tail.then(async () => {
|
|
20
30
|
queued = false;
|
|
21
|
-
if (disposed)
|
|
31
|
+
if (disposed) {
|
|
22
32
|
return;
|
|
33
|
+
}
|
|
23
34
|
try {
|
|
24
35
|
await push();
|
|
25
36
|
}
|
|
@@ -37,6 +48,3 @@ export function startCustomModelPusher(harness, state, logger) {
|
|
|
37
48
|
await tail;
|
|
38
49
|
};
|
|
39
50
|
}
|
|
40
|
-
function errorMessage(error) {
|
|
41
|
-
return error instanceof Error ? error.message : String(error);
|
|
42
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function customModelTaskRefusal(taskType: string | null | undefined): string | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const TASK_NAMES = {
|
|
2
|
+
embeddings: 'embedding',
|
|
3
|
+
'speech-to-text': 'speech-to-text',
|
|
4
|
+
'text-to-speech': 'text-to-speech',
|
|
5
|
+
'image-generation': 'image-generation'
|
|
6
|
+
};
|
|
7
|
+
export function customModelTaskRefusal(taskType) {
|
|
8
|
+
if (!taskType || taskType === 'llm')
|
|
9
|
+
return null;
|
|
10
|
+
const task = TASK_NAMES[taskType] ?? taskType;
|
|
11
|
+
return `This is ${/^[aeiou]/i.test(task) ? 'an' : 'a'} ${task} model. Custom models run as the assistant's text model only.`;
|
|
12
|
+
}
|
package/dist-lib/lib/deadline.js
CHANGED
|
@@ -11,8 +11,9 @@ export class DeadlineScheduler {
|
|
|
11
11
|
}
|
|
12
12
|
schedule(deadline) {
|
|
13
13
|
const at = deadline + 1;
|
|
14
|
-
if (this._at !== null && this._at <= at)
|
|
14
|
+
if (this._at !== null && this._at <= at) {
|
|
15
15
|
return;
|
|
16
|
+
}
|
|
16
17
|
this.clear();
|
|
17
18
|
this._at = at;
|
|
18
19
|
this._timer = setTimeout(() => {
|
|
@@ -23,8 +24,9 @@ export class DeadlineScheduler {
|
|
|
23
24
|
unref(this._timer);
|
|
24
25
|
}
|
|
25
26
|
clear() {
|
|
26
|
-
if (this._timer)
|
|
27
|
+
if (this._timer) {
|
|
27
28
|
clearTimeout(this._timer);
|
|
29
|
+
}
|
|
28
30
|
this._timer = null;
|
|
29
31
|
this._at = null;
|
|
30
32
|
}
|
|
@@ -28,8 +28,4 @@ export interface DiagnosticsSlice {
|
|
|
28
28
|
mobileClass: boolean;
|
|
29
29
|
memoryBudget: MemoryBudget | null;
|
|
30
30
|
}
|
|
31
|
-
export declare function summarizeRuns(runs: Iterable<
|
|
32
|
-
runId: string;
|
|
33
|
-
chatId: string;
|
|
34
|
-
model: string;
|
|
35
|
-
}>, suspended: boolean): AssistantDiagnostics;
|
|
31
|
+
export declare function summarizeRuns(runs: Iterable<RunSummary>, suspended: boolean): AssistantDiagnostics;
|
|
@@ -5,6 +5,7 @@ import { AbortController } from 'bare-abort-controller';
|
|
|
5
5
|
import { STAGING_DIR as HARNESS_STAGING_DIR } from '@qvac/harness/lib/staging.ts';
|
|
6
6
|
import { userTmpPath } from '@qvac/harness/lib/tmp-path.ts';
|
|
7
7
|
import { MAX_DRIVE_BYTES } from '@qvac/harness/lib/tools/fs/remote.ts';
|
|
8
|
+
import { errorMessage } from './guards.js';
|
|
8
9
|
export const DRIVE_OP_TIMEOUT_MS = 15_000;
|
|
9
10
|
const STAGING_DIR = userTmpPath('qvac-fs-drive-host');
|
|
10
11
|
const STAGING_MAX_AGE_MS = 60 * 60 * 1000;
|
|
@@ -42,11 +43,9 @@ async function stagedPath(prefix) {
|
|
|
42
43
|
return path.join(STAGING_DIR, `${prefix}-${unique}`);
|
|
43
44
|
}
|
|
44
45
|
function stripMetadata(entry) {
|
|
45
|
-
if (!entry)
|
|
46
|
-
return null;
|
|
47
46
|
return { ...entry, value: { ...entry.value, metadata: null } };
|
|
48
47
|
}
|
|
49
|
-
async function pipeCapped(source, target, cap, signal) {
|
|
48
|
+
async function pipeCapped(source, target, { cap, signal }) {
|
|
50
49
|
const sink = fs.createWriteStream(target, { mode: 0o600 });
|
|
51
50
|
let sinkError = null;
|
|
52
51
|
sink.on('error', (err) => {
|
|
@@ -68,15 +67,17 @@ async function pipeCapped(source, target, cap, signal) {
|
|
|
68
67
|
const slice = chunk.byteLength > room ? chunk.subarray(0, room) : chunk;
|
|
69
68
|
sink.write(slice);
|
|
70
69
|
written += slice.byteLength;
|
|
71
|
-
if (slice.byteLength < chunk.byteLength)
|
|
70
|
+
if (slice.byteLength < chunk.byteLength) {
|
|
72
71
|
truncated = true;
|
|
72
|
+
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
finally {
|
|
76
76
|
await new Promise((resolve) => sink.end(resolve));
|
|
77
77
|
}
|
|
78
|
-
if (sinkError)
|
|
78
|
+
if (sinkError) {
|
|
79
79
|
throw sinkError;
|
|
80
|
+
}
|
|
80
81
|
return truncated;
|
|
81
82
|
}
|
|
82
83
|
function folderRange(folder) {
|
|
@@ -88,18 +89,20 @@ async function handleRequest(acquired, request, signal) {
|
|
|
88
89
|
switch (request.op) {
|
|
89
90
|
case 'entry': {
|
|
90
91
|
const entry = await drive.entry(request.key, { timeout: DRIVE_OP_TIMEOUT_MS, wait: true });
|
|
91
|
-
return { entry: stripMetadata(entry) };
|
|
92
|
+
return { entry: entry ? stripMetadata(entry) : null };
|
|
92
93
|
}
|
|
93
94
|
case 'get': {
|
|
94
95
|
const entry = await drive.entry(request.key, { timeout: DRIVE_OP_TIMEOUT_MS, wait: true });
|
|
95
|
-
if (!entry)
|
|
96
|
+
if (!entry) {
|
|
96
97
|
return { path: null };
|
|
98
|
+
}
|
|
97
99
|
if ((entry.value.blob?.byteLength ?? 0) > MAX_DRIVE_BYTES) {
|
|
98
100
|
return { error: `get exceeds ${MAX_DRIVE_BYTES} bytes: ${request.key}` };
|
|
99
101
|
}
|
|
100
102
|
const buffer = await drive.get(request.key, { timeout: DRIVE_OP_TIMEOUT_MS, wait: true });
|
|
101
|
-
if (!buffer)
|
|
103
|
+
if (!buffer) {
|
|
102
104
|
return { path: null };
|
|
105
|
+
}
|
|
103
106
|
const target = await stagedPath('drive-get');
|
|
104
107
|
signal.addEventListener('abort', () => void fs.promises.unlink(target).catch(noop), {
|
|
105
108
|
once: true
|
|
@@ -112,7 +115,10 @@ async function handleRequest(acquired, request, signal) {
|
|
|
112
115
|
signal.addEventListener('abort', () => void fs.promises.unlink(target).catch(noop), {
|
|
113
116
|
once: true
|
|
114
117
|
});
|
|
115
|
-
const truncated = await pipeCapped(drive.createReadStream(request.key), target,
|
|
118
|
+
const truncated = await pipeCapped(drive.createReadStream(request.key), target, {
|
|
119
|
+
cap: MAX_DRIVE_BYTES,
|
|
120
|
+
signal
|
|
121
|
+
});
|
|
116
122
|
return { path: target, truncated };
|
|
117
123
|
}
|
|
118
124
|
case 'list': {
|
|
@@ -132,8 +138,9 @@ async function handleRequest(acquired, request, signal) {
|
|
|
132
138
|
return { entries, cursor };
|
|
133
139
|
}
|
|
134
140
|
case 'write': {
|
|
135
|
-
if (!acquired.writable)
|
|
141
|
+
if (!acquired.writable) {
|
|
136
142
|
return { error: `drive is read-only: cannot write ${request.key}` };
|
|
143
|
+
}
|
|
137
144
|
const resolvedPath = path.resolve(request.path);
|
|
138
145
|
if (path.relative(HARNESS_STAGING_DIR, resolvedPath).startsWith('..')) {
|
|
139
146
|
return { error: `write path is outside the staging directory: ${request.path}` };
|
|
@@ -153,13 +160,14 @@ async function handleRequest(acquired, request, signal) {
|
|
|
153
160
|
export function createDriveOp(drives) {
|
|
154
161
|
return async (request) => {
|
|
155
162
|
const acquired = drives.get(request.driveKey);
|
|
156
|
-
if (!acquired)
|
|
163
|
+
if (!acquired) {
|
|
157
164
|
return { error: `drive not granted for this run: ${request.driveKey}` };
|
|
165
|
+
}
|
|
158
166
|
try {
|
|
159
167
|
return await withDeadline(request.op, DRIVE_OP_TIMEOUT_MS, (signal) => handleRequest(acquired, request, signal));
|
|
160
168
|
}
|
|
161
169
|
catch (err) {
|
|
162
|
-
return { error:
|
|
170
|
+
return { error: errorMessage(err) };
|
|
163
171
|
}
|
|
164
172
|
};
|
|
165
173
|
}
|
|
@@ -168,8 +176,9 @@ export async function resolveFsGrants(grants, driveHost, onDropped) {
|
|
|
168
176
|
.filter((grant) => grant.kind === 'local')
|
|
169
177
|
.map((grant) => grant.path);
|
|
170
178
|
const hyperGrants = grants.filter((grant) => grant.kind === 'hyper');
|
|
171
|
-
if (!driveHost || hyperGrants.length === 0)
|
|
179
|
+
if (!driveHost || hyperGrants.length === 0) {
|
|
172
180
|
return { grantedDirs, grantedDrives: [] };
|
|
181
|
+
}
|
|
173
182
|
const drives = new Map();
|
|
174
183
|
const grantedDrives = [];
|
|
175
184
|
for (const grant of hyperGrants) {
|
|
@@ -182,7 +191,8 @@ export async function resolveFsGrants(grants, driveHost, onDropped) {
|
|
|
182
191
|
onDropped?.(grant.key, err);
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
|
-
if (drives.size === 0)
|
|
194
|
+
if (drives.size === 0) {
|
|
186
195
|
return { grantedDirs, grantedDrives: [] };
|
|
196
|
+
}
|
|
187
197
|
return { grantedDirs, grantedDrives, driveOp: createDriveOp(drives) };
|
|
188
198
|
}
|
|
@@ -14,25 +14,30 @@ function parseHyperKey(value) {
|
|
|
14
14
|
export function fsGrantsFrom(value) {
|
|
15
15
|
if (!Array.isArray(value))
|
|
16
16
|
return [];
|
|
17
|
+
const items = value;
|
|
17
18
|
const grants = [];
|
|
18
|
-
for (const item of
|
|
19
|
+
for (const item of items) {
|
|
19
20
|
if (typeof item === 'string') {
|
|
20
|
-
if (path.isAbsolute(item))
|
|
21
|
+
if (path.isAbsolute(item)) {
|
|
21
22
|
grants.push({ kind: 'local', path: item });
|
|
23
|
+
}
|
|
22
24
|
continue;
|
|
23
25
|
}
|
|
24
|
-
if (!item || typeof item !== 'object')
|
|
26
|
+
if (!item || typeof item !== 'object') {
|
|
25
27
|
continue;
|
|
26
|
-
|
|
28
|
+
}
|
|
29
|
+
const kind = 'kind' in item ? item.kind : undefined;
|
|
27
30
|
if (kind === 'local') {
|
|
28
|
-
const dir = item.path;
|
|
29
|
-
if (typeof dir === 'string' && path.isAbsolute(dir))
|
|
31
|
+
const dir = 'path' in item ? item.path : undefined;
|
|
32
|
+
if (typeof dir === 'string' && path.isAbsolute(dir)) {
|
|
30
33
|
grants.push({ kind: 'local', path: dir });
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
36
|
else if (kind === 'hyper') {
|
|
33
|
-
const key = parseHyperKey(item.key);
|
|
34
|
-
if (key)
|
|
37
|
+
const key = parseHyperKey('key' in item ? item.key : undefined);
|
|
38
|
+
if (key) {
|
|
35
39
|
grants.push({ kind: 'hyper', key });
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
return grants;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function errorMessage(err) {
|
|
5
|
+
return err instanceof Error ? err.message : String(err);
|
|
6
|
+
}
|
|
7
|
+
export function asError(err) {
|
|
8
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
9
|
+
}
|