@qvac/core 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +198 -0
- package/NOTICE.md +13 -0
- package/README.md +694 -0
- package/SECURITY.md +6 -0
- package/dist/assistant.bundle +47257 -0
- package/dist/assistant.cjs +18 -0
- package/dist/assistant.d.ts +8 -0
- package/dist/prebuilds-manifest.json +380 -0
- package/dist-lib/client.d.ts +2 -0
- package/dist-lib/client.js +1 -0
- package/dist-lib/index.d.ts +13 -0
- package/dist-lib/index.js +10 -0
- package/dist-lib/lib/agent-icons.d.ts +3 -0
- package/dist-lib/lib/agent-icons.js +1 -0
- package/dist-lib/lib/api/agents.d.ts +5 -0
- package/dist-lib/lib/api/agents.js +38 -0
- package/dist-lib/lib/api/app-config.d.ts +5 -0
- package/dist-lib/lib/api/app-config.js +108 -0
- package/dist-lib/lib/api/approval-rules.d.ts +3 -0
- package/dist-lib/lib/api/approval-rules.js +9 -0
- package/dist-lib/lib/api/attachments.d.ts +8 -0
- package/dist-lib/lib/api/attachments.js +15 -0
- package/dist-lib/lib/api/chat-groups.d.ts +5 -0
- package/dist-lib/lib/api/chat-groups.js +12 -0
- package/dist-lib/lib/api/chat.d.ts +5 -0
- package/dist-lib/lib/api/chat.js +38 -0
- package/dist-lib/lib/api/chunks.d.ts +5 -0
- package/dist-lib/lib/api/chunks.js +61 -0
- package/dist-lib/lib/api/config.d.ts +5 -0
- package/dist-lib/lib/api/config.js +15 -0
- package/dist-lib/lib/api/current-mesh.d.ts +5 -0
- package/dist-lib/lib/api/current-mesh.js +12 -0
- package/dist-lib/lib/api/custom-models.d.ts +5 -0
- package/dist-lib/lib/api/custom-models.js +45 -0
- package/dist-lib/lib/api/devices.d.ts +8 -0
- package/dist-lib/lib/api/devices.js +125 -0
- package/dist-lib/lib/api/diagnostics.d.ts +7 -0
- package/dist-lib/lib/api/diagnostics.js +7 -0
- package/dist-lib/lib/api/effective-ctx-size.d.ts +2 -0
- package/dist-lib/lib/api/effective-ctx-size.js +10 -0
- package/dist-lib/lib/api/execution.d.ts +3 -0
- package/dist-lib/lib/api/execution.js +45 -0
- package/dist-lib/lib/api/files.d.ts +3 -0
- package/dist-lib/lib/api/files.js +48 -0
- package/dist-lib/lib/api/index.d.ts +62 -0
- package/dist-lib/lib/api/index.js +172 -0
- package/dist-lib/lib/api/instrument.d.ts +2 -0
- package/dist-lib/lib/api/instrument.js +86 -0
- package/dist-lib/lib/api/knowledge.d.ts +8 -0
- package/dist-lib/lib/api/knowledge.js +26 -0
- package/dist-lib/lib/api/logs.d.ts +14 -0
- package/dist-lib/lib/api/logs.js +116 -0
- package/dist-lib/lib/api/mesh.d.ts +13 -0
- package/dist-lib/lib/api/mesh.js +25 -0
- package/dist-lib/lib/api/model-download.d.ts +5 -0
- package/dist-lib/lib/api/model-download.js +47 -0
- package/dist-lib/lib/api/network.d.ts +8 -0
- package/dist-lib/lib/api/network.js +6 -0
- package/dist-lib/lib/api/notifications.d.ts +21 -0
- package/dist-lib/lib/api/notifications.js +108 -0
- package/dist-lib/lib/api/rag.d.ts +7 -0
- package/dist-lib/lib/api/rag.js +216 -0
- package/dist-lib/lib/api/sync.d.ts +3 -0
- package/dist-lib/lib/api/sync.js +6 -0
- package/dist-lib/lib/api/tool-activity.d.ts +5 -0
- package/dist-lib/lib/api/tool-activity.js +53 -0
- package/dist-lib/lib/api/tool-configs.d.ts +6 -0
- package/dist-lib/lib/api/tool-configs.js +27 -0
- package/dist-lib/lib/api/watchable.d.ts +12 -0
- package/dist-lib/lib/api/watchable.js +121 -0
- package/dist-lib/lib/assistant-client.d.ts +21 -0
- package/dist-lib/lib/assistant-client.js +52 -0
- package/dist-lib/lib/assistant-tree.d.ts +50 -0
- package/dist-lib/lib/assistant-tree.js +184 -0
- package/dist-lib/lib/assistant.d.ts +425 -0
- package/dist-lib/lib/assistant.js +2706 -0
- package/dist-lib/lib/audio-format.d.ts +4 -0
- package/dist-lib/lib/audio-format.js +4 -0
- package/dist-lib/lib/chat-title.d.ts +5 -0
- package/dist-lib/lib/chat-title.js +58 -0
- package/dist-lib/lib/client.d.ts +25 -0
- package/dist-lib/lib/client.js +53 -0
- package/dist-lib/lib/collabora/convert.d.ts +9 -0
- package/dist-lib/lib/collabora/convert.js +62 -0
- package/dist-lib/lib/collabora/entry.d.ts +1 -0
- package/dist-lib/lib/collabora/entry.js +44 -0
- package/dist-lib/lib/collabora/protocol.d.ts +15 -0
- package/dist-lib/lib/collabora/protocol.js +24 -0
- package/dist-lib/lib/collabora/worker.d.ts +5 -0
- package/dist-lib/lib/collabora/worker.js +111 -0
- package/dist-lib/lib/compaction.d.ts +30 -0
- package/dist-lib/lib/compaction.js +95 -0
- package/dist-lib/lib/constants.d.ts +4 -0
- package/dist-lib/lib/constants.js +4 -0
- package/dist-lib/lib/core/agent.d.ts +15 -0
- package/dist-lib/lib/core/agent.js +149 -0
- package/dist-lib/lib/core/app-build.d.ts +7 -0
- package/dist-lib/lib/core/app-build.js +1 -0
- package/dist-lib/lib/core/approval-rules.d.ts +15 -0
- package/dist-lib/lib/core/approval-rules.js +41 -0
- package/dist-lib/lib/core/async-iterable.d.ts +13 -0
- package/dist-lib/lib/core/async-iterable.js +65 -0
- package/dist-lib/lib/core/attachment-link.d.ts +7 -0
- package/dist-lib/lib/core/attachment-link.js +6 -0
- package/dist-lib/lib/core/audio-attachment.d.ts +1 -0
- package/dist-lib/lib/core/audio-attachment.js +4 -0
- package/dist-lib/lib/core/blind-peers.d.ts +6 -0
- package/dist-lib/lib/core/blind-peers.js +13 -0
- package/dist-lib/lib/core/chat-activity.d.ts +7 -0
- package/dist-lib/lib/core/chat-activity.js +244 -0
- package/dist-lib/lib/core/chat-group.d.ts +14 -0
- package/dist-lib/lib/core/chat-group.js +79 -0
- package/dist-lib/lib/core/chat-search.d.ts +17 -0
- package/dist-lib/lib/core/chat-search.js +199 -0
- package/dist-lib/lib/core/chat.d.ts +37 -0
- package/dist-lib/lib/core/chat.js +196 -0
- package/dist-lib/lib/core/chunk.d.ts +61 -0
- package/dist-lib/lib/core/chunk.js +212 -0
- package/dist-lib/lib/core/contract/activity.d.ts +11 -0
- package/dist-lib/lib/core/contract/activity.js +45 -0
- package/dist-lib/lib/core/contract/agents.d.ts +2 -0
- package/dist-lib/lib/core/contract/agents.js +29 -0
- package/dist-lib/lib/core/contract/approval-rules.d.ts +2 -0
- package/dist-lib/lib/core/contract/approval-rules.js +14 -0
- package/dist-lib/lib/core/contract/attestations.d.ts +2 -0
- package/dist-lib/lib/core/contract/attestations.js +14 -0
- package/dist-lib/lib/core/contract/chat-group.d.ts +2 -0
- package/dist-lib/lib/core/contract/chat-group.js +20 -0
- package/dist-lib/lib/core/contract/chat.d.ts +2 -0
- package/dist-lib/lib/core/contract/chat.js +18 -0
- package/dist-lib/lib/core/contract/chunks.d.ts +2 -0
- package/dist-lib/lib/core/contract/chunks.js +156 -0
- package/dist-lib/lib/core/contract/devices.d.ts +2 -0
- package/dist-lib/lib/core/contract/devices.js +110 -0
- package/dist-lib/lib/core/contract/index.d.ts +2 -0
- package/dist-lib/lib/core/contract/index.js +30 -0
- package/dist-lib/lib/core/contract/indexing.d.ts +4 -0
- package/dist-lib/lib/core/contract/indexing.js +82 -0
- package/dist-lib/lib/core/contract/knowledge.d.ts +2 -0
- package/dist-lib/lib/core/contract/knowledge.js +55 -0
- package/dist-lib/lib/core/contract/members.d.ts +2 -0
- package/dist-lib/lib/core/contract/members.js +96 -0
- package/dist-lib/lib/core/contract/seed-defaults.d.ts +2 -0
- package/dist-lib/lib/core/contract/seed-defaults.js +29 -0
- package/dist-lib/lib/core/contract/tool-activity.d.ts +2 -0
- package/dist-lib/lib/core/contract/tool-activity.js +25 -0
- package/dist-lib/lib/core/contract/tool-configs.d.ts +2 -0
- package/dist-lib/lib/core/contract/tool-configs.js +50 -0
- package/dist-lib/lib/core/contract/types.d.ts +11 -0
- package/dist-lib/lib/core/contract/types.js +1 -0
- package/dist-lib/lib/core/contract/writers.d.ts +2 -0
- package/dist-lib/lib/core/contract/writers.js +112 -0
- package/dist-lib/lib/core/cpu-info-node.d.ts +3 -0
- package/dist-lib/lib/core/cpu-info-node.js +2 -0
- package/dist-lib/lib/core/departures.d.ts +41 -0
- package/dist-lib/lib/core/departures.js +145 -0
- package/dist-lib/lib/core/device-attestation.d.ts +6 -0
- package/dist-lib/lib/core/device-attestation.js +12 -0
- package/dist-lib/lib/core/devices.d.ts +14 -0
- package/dist-lib/lib/core/devices.js +11 -0
- package/dist-lib/lib/core/document-attachment.d.ts +22 -0
- package/dist-lib/lib/core/document-attachment.js +35 -0
- package/dist-lib/lib/core/files/attachments.d.ts +8 -0
- package/dist-lib/lib/core/files/attachments.js +50 -0
- package/dist-lib/lib/core/files/index.d.ts +133 -0
- package/dist-lib/lib/core/files/index.js +585 -0
- package/dist-lib/lib/core/files/knowledge.d.ts +9 -0
- package/dist-lib/lib/core/files/knowledge.js +31 -0
- package/dist-lib/lib/core/files/preview/image.d.ts +4 -0
- package/dist-lib/lib/core/files/preview/image.js +42 -0
- package/dist-lib/lib/core/files/preview/index.d.ts +33 -0
- package/dist-lib/lib/core/files/preview/index.js +161 -0
- package/dist-lib/lib/core/files/processing/claims.d.ts +26 -0
- package/dist-lib/lib/core/files/processing/claims.js +89 -0
- package/dist-lib/lib/core/files/processing/document.d.ts +100 -0
- package/dist-lib/lib/core/files/processing/document.js +101 -0
- package/dist-lib/lib/core/files/processing/index.d.ts +75 -0
- package/dist-lib/lib/core/files/processing/index.js +295 -0
- package/dist-lib/lib/core/files/processing/ownership.d.ts +11 -0
- package/dist-lib/lib/core/files/processing/ownership.js +41 -0
- package/dist-lib/lib/core/files/processing/protocol.d.ts +29 -0
- package/dist-lib/lib/core/files/processing/protocol.js +70 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +10 -0
- package/dist-lib/lib/core/files/processing/settle.js +75 -0
- package/dist-lib/lib/core/files/processing/source.d.ts +36 -0
- package/dist-lib/lib/core/files/processing/source.js +96 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +64 -0
- package/dist-lib/lib/core/files/processing/state.js +118 -0
- package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/artifact/codec.js +172 -0
- package/dist-lib/lib/core/files/rag/artifact/id.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/artifact/id.js +39 -0
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +24 -0
- package/dist-lib/lib/core/files/rag/artifact/types.js +41 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +25 -0
- package/dist-lib/lib/core/files/rag/build.js +60 -0
- package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +12 -0
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +117 -0
- package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +30 -0
- package/dist-lib/lib/core/files/rag/chunk/metadata.js +89 -0
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +7 -0
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +18 -0
- package/dist-lib/lib/core/files/rag/document-types.d.ts +11 -0
- package/dist-lib/lib/core/files/rag/document-types.js +94 -0
- package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/csv-text.js +117 -0
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +22 -0
- package/dist-lib/lib/core/files/rag/extract/document-types.js +152 -0
- package/dist-lib/lib/core/files/rag/extract/extract.d.ts +17 -0
- package/dist-lib/lib/core/files/rag/extract/extract.js +81 -0
- package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/html-table-text.js +125 -0
- package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/html-text.js +132 -0
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +8 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +17 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +141 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +12 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +43 -0
- package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/rtf-text.js +15 -0
- package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +91 -0
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +36 -0
- package/dist-lib/lib/core/files/rag/extract/types.js +12 -0
- package/dist-lib/lib/core/files/rag/extract/utf.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/extract/utf.js +18 -0
- package/dist-lib/lib/core/files/rag/index.d.ts +54 -0
- package/dist-lib/lib/core/files/rag/index.js +79 -0
- package/dist-lib/lib/core/files/rag/limits.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/limits.js +2 -0
- package/dist-lib/lib/core/files/rag/load.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/load.js +250 -0
- package/dist-lib/lib/core/files/rag/models.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/models.js +1 -0
- package/dist-lib/lib/core/files/rag/policy.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/policy.js +23 -0
- package/dist-lib/lib/core/files/rag/produce.d.ts +21 -0
- package/dist-lib/lib/core/files/rag/produce.js +214 -0
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +16 -0
- package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +4 -0
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +48 -0
- package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +37 -0
- package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +5 -0
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +21 -0
- package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/retrieval/format.js +21 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +22 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +137 -0
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +53 -0
- package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +16 -0
- package/dist-lib/lib/core/files/rag/retrieval/notices.js +27 -0
- package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +82 -0
- package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/retrieval/search.js +46 -0
- package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +63 -0
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +79 -0
- package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +13 -0
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +20 -0
- package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +13 -0
- package/dist-lib/lib/core/files/rag/retrieval/target.js +89 -0
- package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +70 -0
- package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/retrieval/types.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +41 -0
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +96 -0
- package/dist-lib/lib/core/files/rag/vector/memory.d.ts +15 -0
- package/dist-lib/lib/core/files/rag/vector/memory.js +135 -0
- package/dist-lib/lib/core/files/rag/vector/types.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/vector/types.js +1 -0
- package/dist-lib/lib/core/files/records/chunks.d.ts +3 -0
- package/dist-lib/lib/core/files/records/chunks.js +12 -0
- package/dist-lib/lib/core/files/records/index.d.ts +10 -0
- package/dist-lib/lib/core/files/records/index.js +8 -0
- package/dist-lib/lib/core/files/records/knowledge.d.ts +22 -0
- package/dist-lib/lib/core/files/records/knowledge.js +105 -0
- package/dist-lib/lib/core/files/records/linkage.d.ts +11 -0
- package/dist-lib/lib/core/files/records/linkage.js +27 -0
- package/dist-lib/lib/core/files/records/output.d.ts +8 -0
- package/dist-lib/lib/core/files/records/output.js +38 -0
- package/dist-lib/lib/core/files/records/reclaim.d.ts +5 -0
- package/dist-lib/lib/core/files/records/reclaim.js +73 -0
- package/dist-lib/lib/core/files/records/routing.d.ts +23 -0
- package/dist-lib/lib/core/files/records/routing.js +62 -0
- package/dist-lib/lib/core/files/records/source.d.ts +16 -0
- package/dist-lib/lib/core/files/records/source.js +70 -0
- package/dist-lib/lib/core/files/records/sweep.d.ts +2 -0
- package/dist-lib/lib/core/files/records/sweep.js +30 -0
- package/dist-lib/lib/core/files/store/blob.d.ts +29 -0
- package/dist-lib/lib/core/files/store/blob.js +98 -0
- package/dist-lib/lib/core/files/store/index.d.ts +36 -0
- package/dist-lib/lib/core/files/store/index.js +89 -0
- package/dist-lib/lib/core/files/store/inline.d.ts +8 -0
- package/dist-lib/lib/core/files/store/inline.js +38 -0
- package/dist-lib/lib/core/files/store/reference.d.ts +27 -0
- package/dist-lib/lib/core/files/store/reference.js +168 -0
- package/dist-lib/lib/core/files/store/server.d.ts +27 -0
- package/dist-lib/lib/core/files/store/server.js +114 -0
- package/dist-lib/lib/core/files/store/sweep.d.ts +2 -0
- package/dist-lib/lib/core/files/store/sweep.js +45 -0
- package/dist-lib/lib/core/files/upload-input.d.ts +27 -0
- package/dist-lib/lib/core/files/upload-input.js +52 -0
- package/dist-lib/lib/core/files/upload.d.ts +32 -0
- package/dist-lib/lib/core/files/upload.js +201 -0
- package/dist-lib/lib/core/fs-drives.d.ts +18 -0
- package/dist-lib/lib/core/fs-drives.js +58 -0
- package/dist-lib/lib/core/gpu-info-node.d.ts +3 -0
- package/dist-lib/lib/core/gpu-info-node.js +2 -0
- package/dist-lib/lib/core/handoff-channel.d.ts +46 -0
- package/dist-lib/lib/core/handoff-channel.js +102 -0
- package/dist-lib/lib/core/health-assistant.d.ts +7 -0
- package/dist-lib/lib/core/health-assistant.js +24 -0
- package/dist-lib/lib/core/helpers/index.d.ts +5 -0
- package/dist-lib/lib/core/helpers/index.js +74 -0
- package/dist-lib/lib/core/hosted-agents.d.ts +36 -0
- package/dist-lib/lib/core/hosted-agents.js +127 -0
- package/dist-lib/lib/core/id.d.ts +1 -0
- package/dist-lib/lib/core/id.js +5 -0
- package/dist-lib/lib/core/identity.d.ts +14 -0
- package/dist-lib/lib/core/identity.js +45 -0
- package/dist-lib/lib/core/image/cache-sweep.d.ts +12 -0
- package/dist-lib/lib/core/image/cache-sweep.js +67 -0
- package/dist-lib/lib/core/image/normalize.d.ts +3 -0
- package/dist-lib/lib/core/image/normalize.js +49 -0
- package/dist-lib/lib/core/image/sniff.d.ts +3 -0
- package/dist-lib/lib/core/image/sniff.js +149 -0
- package/dist-lib/lib/core/invite.d.ts +14 -0
- package/dist-lib/lib/core/invite.js +36 -0
- package/dist-lib/lib/core/local/index.d.ts +71 -0
- package/dist-lib/lib/core/local/index.js +391 -0
- package/dist-lib/lib/core/membership.d.ts +15 -0
- package/dist-lib/lib/core/membership.js +40 -0
- package/dist-lib/lib/core/mesh.d.ts +153 -0
- package/dist-lib/lib/core/mesh.js +509 -0
- package/dist-lib/lib/core/migrations/agent-catalog.d.ts +6 -0
- package/dist-lib/lib/core/migrations/agent-catalog.js +17 -0
- package/dist-lib/lib/core/migrations/index.d.ts +5 -0
- package/dist-lib/lib/core/migrations/index.js +7 -0
- package/dist-lib/lib/core/migrations/membership.d.ts +11 -0
- package/dist-lib/lib/core/migrations/membership.js +26 -0
- package/dist-lib/lib/core/min-version.d.ts +6 -0
- package/dist-lib/lib/core/min-version.js +31 -0
- package/dist-lib/lib/core/next-frame.d.ts +6 -0
- package/dist-lib/lib/core/next-frame.js +27 -0
- package/dist-lib/lib/core/notification.d.ts +6 -0
- package/dist-lib/lib/core/notification.js +162 -0
- package/dist-lib/lib/core/ota-config.d.ts +19 -0
- package/dist-lib/lib/core/ota-config.js +44 -0
- package/dist-lib/lib/core/prompt-history.d.ts +12 -0
- package/dist-lib/lib/core/prompt-history.js +40 -0
- package/dist-lib/lib/core/search-fold.d.ts +1 -0
- package/dist-lib/lib/core/search-fold.js +4 -0
- package/dist-lib/lib/core/secret-handoff.d.ts +17 -0
- package/dist-lib/lib/core/secret-handoff.js +29 -0
- package/dist-lib/lib/core/send.d.ts +18 -0
- package/dist-lib/lib/core/send.js +46 -0
- package/dist-lib/lib/core/skill-overlay-handoff.d.ts +25 -0
- package/dist-lib/lib/core/skill-overlay-handoff.js +50 -0
- package/dist-lib/lib/core/skill-overlay-receiver.d.ts +8 -0
- package/dist-lib/lib/core/skill-overlay-receiver.js +20 -0
- package/dist-lib/lib/core/skill-secrets.d.ts +25 -0
- package/dist-lib/lib/core/skill-secrets.js +79 -0
- package/dist-lib/lib/core/sync/chats.d.ts +3 -0
- package/dist-lib/lib/core/sync/chats.js +5 -0
- package/dist-lib/lib/core/sync/chunks.d.ts +9 -0
- package/dist-lib/lib/core/sync/chunks.js +16 -0
- package/dist-lib/lib/core/sync/devices.d.ts +4 -0
- package/dist-lib/lib/core/sync/devices.js +12 -0
- package/dist-lib/lib/core/sync/files.d.ts +16 -0
- package/dist-lib/lib/core/sync/files.js +109 -0
- package/dist-lib/lib/core/sync/index.d.ts +5 -0
- package/dist-lib/lib/core/sync/index.js +63 -0
- package/dist-lib/lib/core/sync-status.d.ts +17 -0
- package/dist-lib/lib/core/sync-status.js +129 -0
- package/dist-lib/lib/core/system-info.d.ts +24 -0
- package/dist-lib/lib/core/system-info.js +66 -0
- package/dist-lib/lib/core/tool-activity.d.ts +22 -0
- package/dist-lib/lib/core/tool-activity.js +39 -0
- package/dist-lib/lib/core/tool-configs.d.ts +13 -0
- package/dist-lib/lib/core/tool-configs.js +141 -0
- package/dist-lib/lib/core.d.ts +291 -0
- package/dist-lib/lib/core.js +2126 -0
- package/dist-lib/lib/credential-pusher.d.ts +67 -0
- package/dist-lib/lib/credential-pusher.js +290 -0
- package/dist-lib/lib/custom-model-pusher.d.ts +9 -0
- package/dist-lib/lib/custom-model-pusher.js +42 -0
- package/dist-lib/lib/custom-model-source.d.ts +15 -0
- package/dist-lib/lib/custom-model-source.js +46 -0
- package/dist-lib/lib/deadline.d.ts +9 -0
- package/dist-lib/lib/deadline.js +31 -0
- package/dist-lib/lib/diagnostics.d.ts +35 -0
- package/dist-lib/lib/diagnostics.js +14 -0
- package/dist-lib/lib/fetch-node.d.ts +1 -0
- package/dist-lib/lib/fetch-node.js +1 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +12 -0
- package/dist-lib/lib/fs-drive-bridge.js +186 -0
- package/dist-lib/lib/fs-grant-keys.d.ts +2 -0
- package/dist-lib/lib/fs-grant-keys.js +6 -0
- package/dist-lib/lib/fs-grants.d.ts +10 -0
- package/dist-lib/lib/fs-grants.js +44 -0
- package/dist-lib/lib/image-cache-dir.d.ts +1 -0
- package/dist-lib/lib/image-cache-dir.js +5 -0
- package/dist-lib/lib/integrations/index.d.ts +4 -0
- package/dist-lib/lib/integrations/index.js +3 -0
- package/dist-lib/lib/integrations/mcp-providers.d.ts +12 -0
- package/dist-lib/lib/integrations/mcp-providers.js +22 -0
- package/dist-lib/lib/integrations/oauth-providers.d.ts +14 -0
- package/dist-lib/lib/integrations/oauth-providers.js +116 -0
- package/dist-lib/lib/integrations/setup-routes.d.ts +12 -0
- package/dist-lib/lib/integrations/setup-routes.js +114 -0
- package/dist-lib/lib/knowledge-search.d.ts +7 -0
- package/dist-lib/lib/knowledge-search.js +53 -0
- package/dist-lib/lib/kv-cache-reclaim.d.ts +5 -0
- package/dist-lib/lib/kv-cache-reclaim.js +29 -0
- package/dist-lib/lib/kv-cache.d.ts +18 -0
- package/dist-lib/lib/kv-cache.js +33 -0
- package/dist-lib/lib/legacy-core-domain.d.ts +258 -0
- package/dist-lib/lib/legacy-core-domain.js +1 -0
- package/dist-lib/lib/llm-model-names.d.ts +1 -0
- package/dist-lib/lib/llm-model-names.js +1 -0
- package/dist-lib/lib/log-buffer.d.ts +7 -0
- package/dist-lib/lib/log-buffer.js +16 -0
- package/dist-lib/lib/log-levels.d.ts +7 -0
- package/dist-lib/lib/log-levels.js +1 -0
- package/dist-lib/lib/log.d.ts +60 -0
- package/dist-lib/lib/log.js +149 -0
- package/dist-lib/lib/logger-type.d.ts +13 -0
- package/dist-lib/lib/logger-type.js +1 -0
- package/dist-lib/lib/logger.d.ts +5 -0
- package/dist-lib/lib/logger.js +18 -0
- package/dist-lib/lib/model-catalog-revision.d.ts +9 -0
- package/dist-lib/lib/model-catalog-revision.js +65 -0
- package/dist-lib/lib/model-clamp.d.ts +6 -0
- package/dist-lib/lib/model-clamp.js +20 -0
- package/dist-lib/lib/model-context.d.ts +13 -0
- package/dist-lib/lib/model-context.js +71 -0
- package/dist-lib/lib/model-download-status.d.ts +29 -0
- package/dist-lib/lib/model-download-status.js +56 -0
- package/dist-lib/lib/model-download.d.ts +191 -0
- package/dist-lib/lib/model-download.js +787 -0
- package/dist-lib/lib/oauth/asana.d.ts +35 -0
- package/dist-lib/lib/oauth/asana.js +71 -0
- package/dist-lib/lib/oauth/browser-connect.d.ts +22 -0
- package/dist-lib/lib/oauth/browser-connect.js +83 -0
- package/dist-lib/lib/oauth/client.d.ts +9 -0
- package/dist-lib/lib/oauth/client.js +9 -0
- package/dist-lib/lib/oauth/common.d.ts +38 -0
- package/dist-lib/lib/oauth/common.js +36 -0
- package/dist-lib/lib/oauth/crypto.d.ts +3 -0
- package/dist-lib/lib/oauth/crypto.js +25 -0
- package/dist-lib/lib/oauth/fetch-platform.d.ts +1 -0
- package/dist-lib/lib/oauth/fetch-platform.js +1 -0
- package/dist-lib/lib/oauth/flow-core.d.ts +6 -0
- package/dist-lib/lib/oauth/flow-core.js +37 -0
- package/dist-lib/lib/oauth/flow.d.ts +3 -0
- package/dist-lib/lib/oauth/flow.js +24 -0
- package/dist-lib/lib/oauth/google.d.ts +37 -0
- package/dist-lib/lib/oauth/google.js +77 -0
- package/dist-lib/lib/oauth/host.d.ts +5 -0
- package/dist-lib/lib/oauth/host.js +3 -0
- package/dist-lib/lib/oauth/keys.d.ts +25 -0
- package/dist-lib/lib/oauth/keys.js +93 -0
- package/dist-lib/lib/oauth/loopback.d.ts +3 -0
- package/dist-lib/lib/oauth/loopback.js +119 -0
- package/dist-lib/lib/oauth/loopback.stub.d.ts +3 -0
- package/dist-lib/lib/oauth/loopback.stub.js +6 -0
- package/dist-lib/lib/oauth/notion.d.ts +34 -0
- package/dist-lib/lib/oauth/notion.js +82 -0
- package/dist-lib/lib/oauth/pkce-runtime.d.ts +3 -0
- package/dist-lib/lib/oauth/pkce-runtime.js +5 -0
- package/dist-lib/lib/oauth/pkce.d.ts +8 -0
- package/dist-lib/lib/oauth/pkce.js +6 -0
- package/dist-lib/lib/oauth/providers.d.ts +5 -0
- package/dist-lib/lib/oauth/providers.js +73 -0
- package/dist-lib/lib/oauth/redirect-types.d.ts +19 -0
- package/dist-lib/lib/oauth/redirect-types.js +1 -0
- package/dist-lib/lib/oauth/register.d.ts +3 -0
- package/dist-lib/lib/oauth/register.js +34 -0
- package/dist-lib/lib/oauth/resolve.d.ts +17 -0
- package/dist-lib/lib/oauth/resolve.js +57 -0
- package/dist-lib/lib/oauth/spotify.d.ts +32 -0
- package/dist-lib/lib/oauth/spotify.js +73 -0
- package/dist-lib/lib/oauth/token-exchange-core.d.ts +6 -0
- package/dist-lib/lib/oauth/token-exchange-core.js +97 -0
- package/dist-lib/lib/oauth/token-exchange.d.ts +5 -0
- package/dist-lib/lib/oauth/token-exchange.js +9 -0
- package/dist-lib/lib/oauth/types.d.ts +54 -0
- package/dist-lib/lib/oauth/types.js +1 -0
- package/dist-lib/lib/oauth.client.d.ts +5 -0
- package/dist-lib/lib/oauth.client.js +2 -0
- package/dist-lib/lib/oauth.d.ts +14 -0
- package/dist-lib/lib/oauth.js +12 -0
- package/dist-lib/lib/obsidian-key.d.ts +1 -0
- package/dist-lib/lib/obsidian-key.js +1 -0
- package/dist-lib/lib/race-resource.d.ts +5 -0
- package/dist-lib/lib/race-resource.js +25 -0
- package/dist-lib/lib/reconnecting-watch.d.ts +2 -0
- package/dist-lib/lib/reconnecting-watch.js +78 -0
- package/dist-lib/lib/retry-budget.d.ts +14 -0
- package/dist-lib/lib/retry-budget.js +39 -0
- package/dist-lib/lib/run-notices.d.ts +23 -0
- package/dist-lib/lib/run-notices.js +33 -0
- package/dist-lib/lib/run-transcript.d.ts +35 -0
- package/dist-lib/lib/run-transcript.js +106 -0
- package/dist-lib/lib/skill-readiness.d.ts +2 -0
- package/dist-lib/lib/skill-readiness.js +21 -0
- package/dist-lib/lib/skill-types.d.ts +70 -0
- package/dist-lib/lib/skill-types.js +1 -0
- package/dist-lib/lib/spec-loader.d.ts +14 -0
- package/dist-lib/lib/spec-loader.js +9 -0
- package/dist-lib/lib/suspend-lifecycle.d.ts +17 -0
- package/dist-lib/lib/suspend-lifecycle.js +33 -0
- package/dist-lib/lib/task.d.ts +26 -0
- package/dist-lib/lib/task.js +69 -0
- package/dist-lib/lib/unref.d.ts +3 -0
- package/dist-lib/lib/unref.js +4 -0
- package/dist-lib/lib/wav-duration.d.ts +1 -0
- package/dist-lib/lib/wav-duration.js +53 -0
- package/dist-lib/lib/write-queue.d.ts +22 -0
- package/dist-lib/lib/write-queue.js +39 -0
- package/dist-lib/schema/build.d.ts +1 -0
- package/dist-lib/schema/build.js +120 -0
- package/dist-lib/schema/config.d.ts +4 -0
- package/dist-lib/schema/config.js +7 -0
- package/dist-lib/schema/content.d.ts +20 -0
- package/dist-lib/schema/content.js +122 -0
- package/dist-lib/schema/engine.d.ts +2 -0
- package/dist-lib/schema/engine.js +2013 -0
- package/dist-lib/schema/field-order.d.ts +1 -0
- package/dist-lib/schema/field-order.js +95 -0
- package/dist-lib/schema/helpers.d.ts +28 -0
- package/dist-lib/schema/helpers.js +176 -0
- package/dist-lib/schema/local.d.ts +2 -0
- package/dist-lib/schema/local.js +133 -0
- package/dist-lib/schema/qvac.d.ts +22 -0
- package/dist-lib/schema/qvac.js +722 -0
- package/dist-lib/schema/vendor.d.ts +5 -0
- package/dist-lib/spec/bind.d.ts +2 -0
- package/dist-lib/spec/bind.js +520 -0
- package/dist-lib/spec/calls.d.ts +3 -0
- package/dist-lib/spec/calls.js +129 -0
- package/dist-lib/spec/capabilities.d.ts +263 -0
- package/dist-lib/spec/config/hyperconf/index.d.ts +15 -0
- package/dist-lib/spec/config/hyperconf/index.js +24 -0
- package/dist-lib/spec/config/hyperconf/package.json +3 -0
- package/dist-lib/spec/config/hyperschema/index.js +81 -0
- package/dist-lib/spec/config/hyperschema/schema.json +19 -0
- package/dist-lib/spec/hrpc/hrpc.json +1500 -0
- package/dist-lib/spec/hrpc/index.d.ts +3 -0
- package/dist-lib/spec/hrpc/index.js +1545 -0
- package/dist-lib/spec/hrpc/messages.d.ts +4 -0
- package/dist-lib/spec/hrpc/messages.js +8373 -0
- package/dist-lib/spec/hyperschema/index.d.ts +20 -0
- package/dist-lib/spec/hyperschema/index.js +8373 -0
- package/dist-lib/spec/hyperschema/schema.json +6202 -0
- package/dist-lib/spec/hyperschema/types.d.ts +1545 -0
- package/dist-lib/spec/index.d.ts +36 -0
- package/dist-lib/spec/index.js +6 -0
- package/dist-lib/spec/local/hyperdb/db.json +186 -0
- package/dist-lib/spec/local/hyperdb/index.d.ts +9 -0
- package/dist-lib/spec/local/hyperdb/index.js +855 -0
- package/dist-lib/spec/local/hyperdb/messages.js +2189 -0
- package/dist-lib/spec/local/hyperschema/index.js +1208 -0
- package/dist-lib/spec/local/hyperschema/schema.json +639 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +159 -0
- package/dist-lib/spec/mesh/hyperdb/db.json +702 -0
- package/dist-lib/spec/mesh/hyperdb/index.d.ts +9 -0
- package/dist-lib/spec/mesh/hyperdb/index.js +2260 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +7453 -0
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +174 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.d.ts +13 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +566 -0
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +5713 -0
- package/dist-lib/spec/mesh/hyperschema/index.d.ts +14 -0
- package/dist-lib/spec/mesh/hyperschema/index.js +5713 -0
- package/dist-lib/spec/mesh/hyperschema/schema.json +3142 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +754 -0
- package/ducks.png +0 -0
- package/package.json +336 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { encodeRagArtifact } from "./artifact/codec.js";
|
|
2
|
+
import { contentHash, documentIndexArtifactId, pipelineVersionFor } from "./artifact/id.js";
|
|
3
|
+
import { classifyRagDocument, RAG_DOCUMENT_KIND } from "./extract/document-types.js";
|
|
4
|
+
import { buildArtifactPayload, EmbedderFailure } from "./build.js";
|
|
5
|
+
import { isClaimLive } from "../processing/index.js";
|
|
6
|
+
import { AbortedError } from '@qvac/harness/race-abort';
|
|
7
|
+
const UNSUPPORTED = 'unsupported';
|
|
8
|
+
const ERROR_LIMIT = 300;
|
|
9
|
+
export const EMBED_RETRY_LIMIT = 5;
|
|
10
|
+
export class IndexingPass {
|
|
11
|
+
_embedder;
|
|
12
|
+
_extractors;
|
|
13
|
+
constructor(embedder, extractors = {}) {
|
|
14
|
+
this._embedder = embedder;
|
|
15
|
+
this._extractors = extractors;
|
|
16
|
+
}
|
|
17
|
+
async run(document, signal) {
|
|
18
|
+
const knowledge = document.record;
|
|
19
|
+
const pipelineVersion = pipelineVersionFor(this._embedder.model);
|
|
20
|
+
const artifacts = await document.artifacts();
|
|
21
|
+
const published = artifacts.find((row) => row.embedderVersion === pipelineVersion);
|
|
22
|
+
if (published) {
|
|
23
|
+
await document.ownership.reclaimSuperseded(published.id, published.artifactBlobId);
|
|
24
|
+
await document.claims.settle(published.id);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const local = document.state;
|
|
28
|
+
const memo = local.artifactIdMemo;
|
|
29
|
+
if (memo === UNSUPPORTED)
|
|
30
|
+
return;
|
|
31
|
+
if (memo && (await document.claims.blockedByStatus(memo)))
|
|
32
|
+
return;
|
|
33
|
+
if (!memo) {
|
|
34
|
+
const statuses = await document.statuses();
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
for (const row of statuses) {
|
|
37
|
+
if (isClaimLive(row, now)) {
|
|
38
|
+
document.schedule(row.expiresAt);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (document.claims.isFailed(row.id))
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const retryAt = document.source.blockedUntil();
|
|
46
|
+
if (retryAt !== null) {
|
|
47
|
+
document.schedule(retryAt);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (document.paused() || document.closed())
|
|
51
|
+
return;
|
|
52
|
+
const read = await document.source.read(signal);
|
|
53
|
+
if (read.kind === 'malformed') {
|
|
54
|
+
local.artifactIdMemo = UNSUPPORTED;
|
|
55
|
+
document.work({ state: 'failed', reason: 'invalid source reference' });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (read.kind === 'missing') {
|
|
59
|
+
const { retryAt } = read;
|
|
60
|
+
document.schedule(retryAt);
|
|
61
|
+
document.work({
|
|
62
|
+
state: 'pending',
|
|
63
|
+
reason: 'source unavailable',
|
|
64
|
+
retryAt
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const bytes = read.bytes;
|
|
69
|
+
const kind = classifyRagDocument({
|
|
70
|
+
fileName: knowledge.fileName,
|
|
71
|
+
mimeType: knowledge.mimeType,
|
|
72
|
+
bytes
|
|
73
|
+
});
|
|
74
|
+
if (kind === RAG_DOCUMENT_KIND.unsupported) {
|
|
75
|
+
local.artifactIdMemo = UNSUPPORTED;
|
|
76
|
+
document.work({
|
|
77
|
+
state: 'not-applicable',
|
|
78
|
+
reason: 'unsupported file type'
|
|
79
|
+
});
|
|
80
|
+
document.report({
|
|
81
|
+
stage: 'failed',
|
|
82
|
+
processedChunks: 0,
|
|
83
|
+
totalChunks: 0,
|
|
84
|
+
error: `${knowledge.fileName} is not a supported Knowledge file.`
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (kind === RAG_DOCUMENT_KIND.office && !this._extractors.office) {
|
|
89
|
+
local.artifactIdMemo = UNSUPPORTED;
|
|
90
|
+
document.work({
|
|
91
|
+
state: 'pending',
|
|
92
|
+
reason: 'extractor unavailable on this device'
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const sourceHash = contentHash(bytes);
|
|
97
|
+
const artifactId = documentIndexArtifactId({
|
|
98
|
+
attachmentId: knowledge.id,
|
|
99
|
+
sourceBlobId: knowledge.blobId,
|
|
100
|
+
sourceHash,
|
|
101
|
+
embeddingModel: this._embedder.model
|
|
102
|
+
});
|
|
103
|
+
local.artifactIdMemo = artifactId;
|
|
104
|
+
if (await document.claims.blockedByStatus(artifactId))
|
|
105
|
+
return;
|
|
106
|
+
if (document.paused() || document.closed())
|
|
107
|
+
return;
|
|
108
|
+
const claim = await document.claims.claim(artifactId);
|
|
109
|
+
if (!claim)
|
|
110
|
+
return;
|
|
111
|
+
document.work({ state: 'running' });
|
|
112
|
+
let blobRef = null;
|
|
113
|
+
let lastTotal = 0;
|
|
114
|
+
try {
|
|
115
|
+
if (signal.aborted || document.paused() || document.closed()) {
|
|
116
|
+
throw new Error('interrupted: suspend');
|
|
117
|
+
}
|
|
118
|
+
const payload = await buildArtifactPayload({
|
|
119
|
+
embedder: this._embedder,
|
|
120
|
+
extractors: this._extractors,
|
|
121
|
+
knowledge,
|
|
122
|
+
artifactId,
|
|
123
|
+
bytes,
|
|
124
|
+
signal,
|
|
125
|
+
onProgress: (processedChunks, totalChunks) => {
|
|
126
|
+
lastTotal = totalChunks;
|
|
127
|
+
document.report({
|
|
128
|
+
stage: 'embedding',
|
|
129
|
+
processedChunks,
|
|
130
|
+
totalChunks
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if (signal.aborted)
|
|
135
|
+
throw new AbortedError();
|
|
136
|
+
const built = await document.write(encodeRagArtifact(payload));
|
|
137
|
+
blobRef = built.blobRef;
|
|
138
|
+
const current = await document.current();
|
|
139
|
+
if (!current || current.deletedAt || signal.aborted) {
|
|
140
|
+
throw new Error('interrupted: file no longer available');
|
|
141
|
+
}
|
|
142
|
+
const landed = await document.publish({
|
|
143
|
+
id: artifactId,
|
|
144
|
+
sourceHash,
|
|
145
|
+
embedderVersion: pipelineVersion,
|
|
146
|
+
dimensions: payload.dimensions,
|
|
147
|
+
artifactBlobId: built.artifactBlobId
|
|
148
|
+
});
|
|
149
|
+
await document.ownership.onPublished(artifactId, built.blobRef, built.artifactBlobId, landed.artifactBlobId);
|
|
150
|
+
const { applied } = await document.resolve({
|
|
151
|
+
artifactId,
|
|
152
|
+
claimId: claim.claimId,
|
|
153
|
+
status: 'ready'
|
|
154
|
+
});
|
|
155
|
+
document.source.clear();
|
|
156
|
+
local.embedFailures = undefined;
|
|
157
|
+
document.report({
|
|
158
|
+
stage: 'ready',
|
|
159
|
+
processedChunks: payload.chunks.length,
|
|
160
|
+
totalChunks: payload.chunks.length
|
|
161
|
+
});
|
|
162
|
+
logger.info('rag', applied ? 'indexed' : 'indexed, claim superseded', {
|
|
163
|
+
id: artifactId,
|
|
164
|
+
chunks: payload.chunks.length
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
if (document.closed())
|
|
169
|
+
return;
|
|
170
|
+
const interrupted = document.paused() || signal.aborted;
|
|
171
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
172
|
+
const message = interrupted
|
|
173
|
+
? 'interrupted: suspend'
|
|
174
|
+
: raw.length > ERROR_LIMIT
|
|
175
|
+
? `${raw.slice(0, ERROR_LIMIT)}...`
|
|
176
|
+
: raw;
|
|
177
|
+
const failures = !interrupted && err instanceof EmbedderFailure
|
|
178
|
+
? (local.embedFailures = (local.embedFailures ?? 0) + 1)
|
|
179
|
+
: 0;
|
|
180
|
+
const retrying = failures > 0 && failures <= EMBED_RETRY_LIMIT;
|
|
181
|
+
const retryAt = retrying ? document.source.miss() : undefined;
|
|
182
|
+
document.work({
|
|
183
|
+
state: interrupted ? 'pending' : 'failed',
|
|
184
|
+
reason: message,
|
|
185
|
+
retryAt
|
|
186
|
+
});
|
|
187
|
+
if (retryAt)
|
|
188
|
+
document.schedule(retryAt);
|
|
189
|
+
else if (!interrupted)
|
|
190
|
+
document.claims.markFailed(artifactId);
|
|
191
|
+
if (blobRef)
|
|
192
|
+
await document.ownership.clearUnreferenced(artifactId, blobRef);
|
|
193
|
+
try {
|
|
194
|
+
await document.resolve({
|
|
195
|
+
artifactId,
|
|
196
|
+
claimId: claim.claimId,
|
|
197
|
+
status: 'failed',
|
|
198
|
+
error: message
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
}
|
|
203
|
+
if (!interrupted) {
|
|
204
|
+
document.report({
|
|
205
|
+
stage: 'failed',
|
|
206
|
+
processedChunks: 0,
|
|
207
|
+
totalChunks: lastTotal,
|
|
208
|
+
error: message
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
logger.warn('rag', 'indexing failed', { id: artifactId, error: message });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { similarity } from 'asenion';
|
|
2
|
+
const MIN_PHRASE_TOKENS = 4;
|
|
3
|
+
export function citedByPhraseOverlap(answer, records) {
|
|
4
|
+
const cited = [];
|
|
5
|
+
const seen = new Set();
|
|
6
|
+
for (const record of records) {
|
|
7
|
+
const key = record.title.toLowerCase();
|
|
8
|
+
if (seen.has(key))
|
|
9
|
+
continue;
|
|
10
|
+
if (similarity(answer, record.excerpt, { phrase: MIN_PHRASE_TOKENS }) === 0)
|
|
11
|
+
continue;
|
|
12
|
+
seen.add(key);
|
|
13
|
+
cited.push(record.title);
|
|
14
|
+
}
|
|
15
|
+
return cited;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { parseRagMetadata } from "../chunk/metadata.js";
|
|
2
|
+
import { estimateRagTokens } from "../chunk/tokenizer.js";
|
|
3
|
+
const DEFAULT_COVERAGE_BUDGET_TOKENS = 3072;
|
|
4
|
+
export function selectCoverage(hits, { budgetTokens = DEFAULT_COVERAGE_BUDGET_TOKENS } = {}) {
|
|
5
|
+
const documents = groupByDocument(hits);
|
|
6
|
+
if (documents.length === 0)
|
|
7
|
+
return [];
|
|
8
|
+
const perDocument = Math.max(1, Math.floor(budgetTokens / documents.length));
|
|
9
|
+
const selected = [];
|
|
10
|
+
for (const document of documents)
|
|
11
|
+
selected.push(...stride(document, perDocument));
|
|
12
|
+
return selected;
|
|
13
|
+
}
|
|
14
|
+
function stride(document, budgetTokens) {
|
|
15
|
+
const costs = document.chunks.map((chunk) => estimateRagTokens(chunk.hit.content));
|
|
16
|
+
const total = costs.reduce((sum, cost) => sum + cost, 0);
|
|
17
|
+
if (total <= budgetTokens)
|
|
18
|
+
return document.chunks.map((chunk) => chunk.hit);
|
|
19
|
+
const last = document.chunks.length - 1;
|
|
20
|
+
const average = Math.max(1, Math.round(total / document.chunks.length));
|
|
21
|
+
const seats = Math.min(document.chunks.length, Math.max(1, Math.floor(budgetTokens / average)));
|
|
22
|
+
const step = seats > 1 ? last / (seats - 1) : 0;
|
|
23
|
+
const taken = [];
|
|
24
|
+
let used = 0;
|
|
25
|
+
for (let seat = 0; seat < seats; seat++) {
|
|
26
|
+
const at = Math.round(seat * step);
|
|
27
|
+
const cost = costs[at] ?? 0;
|
|
28
|
+
if (used + cost > budgetTokens && taken.length > 0)
|
|
29
|
+
continue;
|
|
30
|
+
taken.push(document.chunks[at].hit);
|
|
31
|
+
used += cost;
|
|
32
|
+
}
|
|
33
|
+
return taken;
|
|
34
|
+
}
|
|
35
|
+
function groupByDocument(hits) {
|
|
36
|
+
const byDocument = new Map();
|
|
37
|
+
for (const hit of hits) {
|
|
38
|
+
const metadata = parseRagMetadata(hit.metadataJson);
|
|
39
|
+
const documentId = metadata?.documentId ?? hit.id;
|
|
40
|
+
const chunks = byDocument.get(documentId) ?? [];
|
|
41
|
+
chunks.push({ index: metadata?.chunkIndex ?? 0, hit });
|
|
42
|
+
byDocument.set(documentId, chunks);
|
|
43
|
+
}
|
|
44
|
+
return [...byDocument].map(([documentId, chunks]) => ({
|
|
45
|
+
documentId,
|
|
46
|
+
chunks: chunks.sort((left, right) => left.index - right.index)
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VectorCandidate, VectorHit } from '../vector/types.ts';
|
|
2
|
+
export type RagScopeFilters = {
|
|
3
|
+
readonly chatId?: string;
|
|
4
|
+
readonly documentIds?: ReadonlyArray<string>;
|
|
5
|
+
readonly attachmentIds?: ReadonlyArray<string>;
|
|
6
|
+
readonly liveSourceIds?: ReadonlyArray<string>;
|
|
7
|
+
};
|
|
8
|
+
export declare function scopeFilterFor(filters: RagScopeFilters): ((candidate: VectorCandidate) => boolean) | undefined;
|
|
9
|
+
export declare function filterHits(hits: ReadonlyArray<VectorHit>, filters: RagScopeFilters): ReadonlyArray<VectorHit>;
|
|
10
|
+
export declare function applyPerSourceCap(hits: ReadonlyArray<VectorHit>, limit: number): ReadonlyArray<VectorHit>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { hitMatchesFilters, parseRagMetadata } from "../chunk/metadata.js";
|
|
2
|
+
export function scopeFilterFor(filters) {
|
|
3
|
+
const liveSourceIds = filters.liveSourceIds ? new Set(filters.liveSourceIds) : undefined;
|
|
4
|
+
if (!filters.chatId &&
|
|
5
|
+
!filters.documentIds?.length &&
|
|
6
|
+
!filters.attachmentIds?.length &&
|
|
7
|
+
!liveSourceIds) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return (candidate) => hitMatchesFilters(candidate, filters, liveSourceIds);
|
|
11
|
+
}
|
|
12
|
+
export function filterHits(hits, filters) {
|
|
13
|
+
const filter = scopeFilterFor(filters);
|
|
14
|
+
return filter ? hits.filter(filter) : hits;
|
|
15
|
+
}
|
|
16
|
+
export function applyPerSourceCap(hits, limit) {
|
|
17
|
+
if (hits.length <= limit)
|
|
18
|
+
return hits;
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const firstPass = [];
|
|
21
|
+
const leftovers = [];
|
|
22
|
+
for (const hit of hits) {
|
|
23
|
+
const key = sourceKey(hit);
|
|
24
|
+
if (seen.has(key)) {
|
|
25
|
+
leftovers.push(hit);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
seen.add(key);
|
|
29
|
+
firstPass.push(hit);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [...firstPass, ...leftovers].slice(0, limit);
|
|
33
|
+
}
|
|
34
|
+
function sourceKey(hit) {
|
|
35
|
+
const metadata = parseRagMetadata(hit.metadataJson);
|
|
36
|
+
return metadata?.documentId ?? `__chunk:${hit.id}`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import '../../../../logger.ts';
|
|
2
|
+
import type { VectorHit } from '../vector/types.ts';
|
|
3
|
+
export declare const RAG_MIN_SIMILARITY = 0.4;
|
|
4
|
+
export declare function applySimilarityFloor(hits: ReadonlyArray<VectorHit>, targetDocumentId: string | null): ReadonlyArray<VectorHit>;
|
|
5
|
+
export declare function logSimilarityScores(candidates: ReadonlyArray<VectorHit>, kept: ReadonlyArray<VectorHit>): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../../../../logger.js";
|
|
2
|
+
import { parseRagMetadata } from "../chunk/metadata.js";
|
|
3
|
+
export const RAG_MIN_SIMILARITY = 0.4;
|
|
4
|
+
export function applySimilarityFloor(hits, targetDocumentId) {
|
|
5
|
+
if (targetDocumentId)
|
|
6
|
+
return hits;
|
|
7
|
+
return hits.filter((hit) => hit.score >= RAG_MIN_SIMILARITY);
|
|
8
|
+
}
|
|
9
|
+
export function logSimilarityScores(candidates, kept) {
|
|
10
|
+
if (candidates.length === 0) {
|
|
11
|
+
logger.debug('rag', 'semantic search returned 0 hits');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const keptIds = new Set(kept.map((hit) => hit.id));
|
|
15
|
+
for (const [index, hit] of candidates.entries()) {
|
|
16
|
+
const source = parseRagMetadata(hit.metadataJson)?.title ?? hit.id;
|
|
17
|
+
const percent = (hit.score * 100).toFixed(1);
|
|
18
|
+
const status = keptIds.has(hit.id) ? 'kept' : 'dropped';
|
|
19
|
+
logger.debug('rag', `similarity #${index + 1} ${percent}% (${status}) - ${source}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parseRagMetadata } from "../chunk/metadata.js";
|
|
2
|
+
export function formatRagContext(hits, availableFiles = []) {
|
|
3
|
+
const manifest = availableFiles.length > 0 ? [`Available files in this chat: ${availableFiles.join(', ')}`] : [];
|
|
4
|
+
return [
|
|
5
|
+
'The following knowledge excerpts are the primary source for answering the user.',
|
|
6
|
+
'Each excerpt is tagged with its source file name and chunk index in a [Source N: filename, ...] label.',
|
|
7
|
+
'The app renders source attribution separately. Do not echo the [Source N: ...] labels. When attribution helps, name only the files you used naturally in prose.',
|
|
8
|
+
...manifest,
|
|
9
|
+
'If the user references a specific file or document by name, prioritise excerpts whose source matches that file.',
|
|
10
|
+
'If the user references a file that has no excerpts below, tell the user that file is not in the retrieved knowledge - do not invent an answer from other files.',
|
|
11
|
+
'If the excerpts collectively do not contain the answer, say the knowledge base did not contain it.',
|
|
12
|
+
...hits.flatMap((hit, index) => ['', formatHitLabel(hit, index), hit.content])
|
|
13
|
+
].join('\n');
|
|
14
|
+
}
|
|
15
|
+
function formatHitLabel(hit, index) {
|
|
16
|
+
const metadata = hit.metadataJson ? parseRagMetadata(hit.metadataJson) : null;
|
|
17
|
+
const title = metadata?.title ?? 'document';
|
|
18
|
+
const chunk = metadata ? `chunk ${metadata.chunkIndex}` : `chunk ${index}`;
|
|
19
|
+
const attachment = metadata?.attachmentId ? `, attachmentId=${metadata.attachmentId}` : '';
|
|
20
|
+
return `[Source ${index + 1}: ${title}, ${chunk}${attachment}]`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { QvacKnowledge } from '../../../../../spec/mesh/hyperschema/types.d.ts';
|
|
2
|
+
import type { Mesh } from '../../../mesh.ts';
|
|
3
|
+
import type { VectorHit } from '../vector/types.ts';
|
|
4
|
+
export declare function fullTextBudgetChars(ctxSize: number): number;
|
|
5
|
+
export declare function isFullTextHit(hit: {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
}): boolean;
|
|
8
|
+
export type FullTextCoverage = {
|
|
9
|
+
readonly unit: 'pages';
|
|
10
|
+
readonly included: number;
|
|
11
|
+
readonly total: number;
|
|
12
|
+
} | {
|
|
13
|
+
readonly unit: 'chars';
|
|
14
|
+
readonly included: number;
|
|
15
|
+
readonly total: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function isTruncatedFullTextHit(hit: VectorHit): boolean;
|
|
18
|
+
export declare function formatFullDocumentContext(hits: ReadonlyArray<VectorHit>): string;
|
|
19
|
+
export interface FullTextOptions {
|
|
20
|
+
readonly head?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function fullTextHits(mesh: Mesh, rows: ReadonlyArray<QvacKnowledge>, budgetChars: number, { head }?: FullTextOptions): Promise<VectorHit[] | null>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { parseRagMetadata } from "../chunk/metadata.js";
|
|
2
|
+
import { classifyRagDocument, RAG_DOCUMENT_KIND } from "../extract/document-types.js";
|
|
3
|
+
import { extractRagDocumentFromBytes } from "../extract/extract.js";
|
|
4
|
+
import { extractPdfHead } from "../extract/pdf-text.js";
|
|
5
|
+
const DEFAULT_FULL_TEXT_BUDGET_TOKENS = 4096;
|
|
6
|
+
const CHARS_PER_TOKEN = 4;
|
|
7
|
+
const FULL_TEXT_MAX_BYTES = 20 * 1024 * 1024;
|
|
8
|
+
const FULL_TEXT_KINDS = new Set([
|
|
9
|
+
RAG_DOCUMENT_KIND.pdf,
|
|
10
|
+
RAG_DOCUMENT_KIND.rtf,
|
|
11
|
+
RAG_DOCUMENT_KIND.html,
|
|
12
|
+
RAG_DOCUMENT_KIND.csv,
|
|
13
|
+
RAG_DOCUMENT_KIND.tsv,
|
|
14
|
+
RAG_DOCUMENT_KIND.text
|
|
15
|
+
]);
|
|
16
|
+
export function fullTextBudgetChars(ctxSize) {
|
|
17
|
+
const tokens = ctxSize > 0 ? Math.floor(ctxSize / 2) : DEFAULT_FULL_TEXT_BUDGET_TOKENS;
|
|
18
|
+
return tokens * CHARS_PER_TOKEN;
|
|
19
|
+
}
|
|
20
|
+
const FULL_TEXT_HIT_PREFIX = 'full-text-';
|
|
21
|
+
export function isFullTextHit(hit) {
|
|
22
|
+
return hit.id.startsWith(FULL_TEXT_HIT_PREFIX);
|
|
23
|
+
}
|
|
24
|
+
function fullTextExtras(hit) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(hit.metadataJson);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function isTruncatedFullTextHit(hit) {
|
|
33
|
+
return isFullTextHit(hit) && fullTextExtras(hit).truncated === true;
|
|
34
|
+
}
|
|
35
|
+
export function formatFullDocumentContext(hits) {
|
|
36
|
+
const truncated = hits.find(isTruncatedFullTextHit);
|
|
37
|
+
const parts = [
|
|
38
|
+
truncated
|
|
39
|
+
? truncatedFraming(titleOf(truncated), fullTextExtras(truncated).coverage, hits.length > 1)
|
|
40
|
+
: 'The full text of the attached document(s) follows. Answer the user from it directly.'
|
|
41
|
+
];
|
|
42
|
+
for (const hit of hits) {
|
|
43
|
+
const extras = fullTextExtras(hit);
|
|
44
|
+
const scope = extras.truncated && extras.coverage ? ` (${describeCoverage(extras.coverage)})` : '';
|
|
45
|
+
parts.push('', `--- ${titleOf(hit)}${scope} ---`, hit.content);
|
|
46
|
+
}
|
|
47
|
+
return parts.join('\n');
|
|
48
|
+
}
|
|
49
|
+
function titleOf(hit) {
|
|
50
|
+
return parseRagMetadata(hit.metadataJson)?.title ?? 'document';
|
|
51
|
+
}
|
|
52
|
+
function truncatedFraming(title, coverage, others) {
|
|
53
|
+
const read = coverage ? `Only the ${describeCoverage(coverage)}` : 'Only the opening';
|
|
54
|
+
const rest = others ? ' The other attached documents follow in full.' : '';
|
|
55
|
+
return `${read} of "${title}" could be read: it is too long for the model's context window. Do not try to read it again or fetch the rest with a tool, it would not fit either. Answer from what is here and say that your answer covers only the beginning of "${title}".${rest}`;
|
|
56
|
+
}
|
|
57
|
+
function describeCoverage(coverage) {
|
|
58
|
+
return coverage.unit === 'pages'
|
|
59
|
+
? `first ${coverage.included} of ${coverage.total} pages`
|
|
60
|
+
: `first ${formatChars(coverage.included)} of about ${formatChars(coverage.total)} characters`;
|
|
61
|
+
}
|
|
62
|
+
function formatChars(count) {
|
|
63
|
+
return count >= 1000 ? `${Math.round(count / 1000)}k` : String(count);
|
|
64
|
+
}
|
|
65
|
+
export async function fullTextHits(mesh, rows, budgetChars, { head = false } = {}) {
|
|
66
|
+
if (rows.length === 0)
|
|
67
|
+
return null;
|
|
68
|
+
const kinds = rows.map((row) => classifyRagDocument({ fileName: row.fileName, mimeType: row.mimeType }));
|
|
69
|
+
if (!kinds.every((kind) => FULL_TEXT_KINDS.has(kind)))
|
|
70
|
+
return null;
|
|
71
|
+
const hits = [];
|
|
72
|
+
let used = 0;
|
|
73
|
+
for (const [index, row] of rows.entries()) {
|
|
74
|
+
if (row.byteLength > FULL_TEXT_MAX_BYTES)
|
|
75
|
+
return null;
|
|
76
|
+
const remaining = budgetChars - used;
|
|
77
|
+
if (!head && kinds[index] !== RAG_DOCUMENT_KIND.pdf && row.byteLength > remaining)
|
|
78
|
+
return null;
|
|
79
|
+
let read;
|
|
80
|
+
try {
|
|
81
|
+
const bytes = await mesh.files.readBytes(row.blobId);
|
|
82
|
+
read = await extractFullText(kinds[index], bytes, row, remaining);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
logger.warn('rag', 'full-text extraction failed; falling back to retrieval', { err });
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (!read.text)
|
|
89
|
+
return null;
|
|
90
|
+
const fits = read.complete && read.text.length <= remaining;
|
|
91
|
+
if (!fits && !head)
|
|
92
|
+
return null;
|
|
93
|
+
const text = fits ? read.text : read.text.slice(0, remaining);
|
|
94
|
+
used += text.length;
|
|
95
|
+
hits.push({
|
|
96
|
+
id: `${FULL_TEXT_HIT_PREFIX}${row.id}`,
|
|
97
|
+
content: text,
|
|
98
|
+
metadataJson: JSON.stringify({
|
|
99
|
+
documentId: `${FULL_TEXT_HIT_PREFIX}${row.id}`,
|
|
100
|
+
title: row.fileName,
|
|
101
|
+
mimeType: row.mimeType,
|
|
102
|
+
attachmentId: row.id,
|
|
103
|
+
chatId: row.chatId,
|
|
104
|
+
chunkIndex: 0,
|
|
105
|
+
tokenCount: Math.ceil(text.length / 4),
|
|
106
|
+
indexedAt: new Date().toISOString(),
|
|
107
|
+
...(fits ? {} : { truncated: true, coverage: coverageOf(read, text.length) })
|
|
108
|
+
}),
|
|
109
|
+
score: 1
|
|
110
|
+
});
|
|
111
|
+
if (!fits)
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return hits;
|
|
115
|
+
}
|
|
116
|
+
function coverageOf(read, included) {
|
|
117
|
+
if (read.pages && read.pages.read < read.pages.total) {
|
|
118
|
+
return { unit: 'pages', included: read.pages.read, total: read.pages.total };
|
|
119
|
+
}
|
|
120
|
+
return { unit: 'chars', included, total: read.totalChars ?? read.text.length };
|
|
121
|
+
}
|
|
122
|
+
async function extractFullText(kind, bytes, row, remainingChars) {
|
|
123
|
+
if (kind === RAG_DOCUMENT_KIND.pdf) {
|
|
124
|
+
const pdf = await extractPdfHead(bytes, { maxChars: remainingChars });
|
|
125
|
+
return {
|
|
126
|
+
text: pdf.text,
|
|
127
|
+
complete: pdf.pagesRead === pdf.totalPages,
|
|
128
|
+
pages: { read: pdf.pagesRead, total: pdf.totalPages }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const document = await extractRagDocumentFromBytes({
|
|
132
|
+
fileName: row.fileName,
|
|
133
|
+
mimeType: row.mimeType,
|
|
134
|
+
bytes
|
|
135
|
+
});
|
|
136
|
+
return { text: document.content, complete: true, totalChars: document.content.length };
|
|
137
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { applySimilarityFloor, logSimilarityScores } from "./floor.js";
|
|
2
|
+
import { searchRagChunks } from "./search.js";
|
|
3
|
+
import { DEFAULT_CHUNK_BUDGET_TOKENS, MAX_SELECTED_CHUNKS } from "./selection.js";
|
|
4
|
+
import { resolveTargetDocument } from "./target.js";
|
|
5
|
+
import { isWholeDocumentQuery } from "./whole-document-query.js";
|
|
6
|
+
export async function retrieveRagKnowledge(query, deps) {
|
|
7
|
+
if (query.scopeDocumentIds?.length) {
|
|
8
|
+
const hits = await searchRagChunks({
|
|
9
|
+
query: query.query,
|
|
10
|
+
chatId: query.chatId,
|
|
11
|
+
liveSourceIds: query.liveSourceIds,
|
|
12
|
+
...scopedShape(query.query, query.scopeDocumentIds)
|
|
13
|
+
}, deps);
|
|
14
|
+
logSimilarityScores(hits, hits);
|
|
15
|
+
return { hits, targetDocumentId: null, searchedCount: hits.length };
|
|
16
|
+
}
|
|
17
|
+
const targetDocumentId = resolveTargetDocument(query.query, query.documents);
|
|
18
|
+
if (!targetDocumentId && isWholeDocumentQuery(query.query)) {
|
|
19
|
+
const hits = await searchRagChunks({
|
|
20
|
+
query: query.query,
|
|
21
|
+
chatId: query.chatId,
|
|
22
|
+
liveSourceIds: query.liveSourceIds,
|
|
23
|
+
documentIds: query.documents.map((document) => document.documentId),
|
|
24
|
+
coverage: true,
|
|
25
|
+
chunkBudgetTokens: DEFAULT_CHUNK_BUDGET_TOKENS
|
|
26
|
+
}, deps);
|
|
27
|
+
return { hits, targetDocumentId, searchedCount: hits.length };
|
|
28
|
+
}
|
|
29
|
+
const { hits: searched, scoped } = await searchKnowledge(query, deps, targetDocumentId);
|
|
30
|
+
const hits = applySimilarityFloor(searched, scoped ? targetDocumentId : null);
|
|
31
|
+
logSimilarityScores(searched, hits);
|
|
32
|
+
return { hits, targetDocumentId, searchedCount: searched.length };
|
|
33
|
+
}
|
|
34
|
+
async function searchKnowledge(query, deps, targetDocumentId) {
|
|
35
|
+
const base = { query: query.query, chatId: query.chatId, liveSourceIds: query.liveSourceIds };
|
|
36
|
+
if (!targetDocumentId) {
|
|
37
|
+
const hits = await searchRagChunks({ ...base, documentFirst: true, chunkBudgetTokens: DEFAULT_CHUNK_BUDGET_TOKENS }, deps);
|
|
38
|
+
return { hits, scoped: false };
|
|
39
|
+
}
|
|
40
|
+
const scopedHits = await searchRagChunks({ ...base, ...scopedShape(query.query, [targetDocumentId]) }, deps);
|
|
41
|
+
if (scopedHits.length > 0)
|
|
42
|
+
return { hits: scopedHits, scoped: true };
|
|
43
|
+
const hits = await searchRagChunks({ ...base, documentFirst: true, chunkBudgetTokens: DEFAULT_CHUNK_BUDGET_TOKENS }, deps);
|
|
44
|
+
return { hits, scoped: false };
|
|
45
|
+
}
|
|
46
|
+
function scopedShape(query, documentIds) {
|
|
47
|
+
return {
|
|
48
|
+
documentIds,
|
|
49
|
+
chunkBudgetTokens: DEFAULT_CHUNK_BUDGET_TOKENS,
|
|
50
|
+
...(documentIds.length === 1 ? { perDocChunkCap: MAX_SELECTED_CHUNKS } : {}),
|
|
51
|
+
...(isWholeDocumentQuery(query) ? { coverage: true } : { documentFirst: true })
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const RAG_FAILED_NOTICE = "Knowledge search failed and was not used.";
|
|
2
|
+
export declare const RAG_EMPTY_NOTICE = "Knowledge is enabled, but no relevant excerpts were found.";
|
|
3
|
+
export declare const RAG_UNAVAILABLE_NOTICE = "Knowledge is still being indexed and was not used yet.";
|
|
4
|
+
export declare const RAG_KNOWLEDGE_OFF_NOTICE = "Knowledge is off for this agent, so the attached document was not used. Enable Knowledge to let the agent read it.";
|
|
5
|
+
export declare const RAG_TRUNCATED_NOTICE = "Only the beginning of the attached document was used. Enable Knowledge to let the agent search all of it.";
|
|
6
|
+
export declare function ragUnreadableNotice(files: ReadonlyArray<string>): string;
|
|
7
|
+
export declare function chooseRagNotice(input: {
|
|
8
|
+
readonly errorMessage?: string | null;
|
|
9
|
+
readonly hitCount: number;
|
|
10
|
+
readonly searchedCount: number;
|
|
11
|
+
readonly indexEmpty: boolean;
|
|
12
|
+
readonly hasKnowledge: boolean;
|
|
13
|
+
readonly pendingReferenced?: boolean;
|
|
14
|
+
readonly failedFiles?: ReadonlyArray<string>;
|
|
15
|
+
readonly pendingFiles?: ReadonlyArray<string>;
|
|
16
|
+
}): string | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const RAG_FAILED_NOTICE = 'Knowledge search failed and was not used.';
|
|
2
|
+
export const RAG_EMPTY_NOTICE = 'Knowledge is enabled, but no relevant excerpts were found.';
|
|
3
|
+
export const RAG_UNAVAILABLE_NOTICE = 'Knowledge is still being indexed and was not used yet.';
|
|
4
|
+
export const RAG_KNOWLEDGE_OFF_NOTICE = 'Knowledge is off for this agent, so the attached document was not used. Enable Knowledge to let the agent read it.';
|
|
5
|
+
export const RAG_TRUNCATED_NOTICE = 'Only the beginning of the attached document was used. Enable Knowledge to let the agent search all of it.';
|
|
6
|
+
export function ragUnreadableNotice(files) {
|
|
7
|
+
const plural = files.length > 1;
|
|
8
|
+
return `Attached file${plural ? 's' : ''} could not be read and ${plural ? 'were' : 'was'} not used: ${files.join(', ')}.`;
|
|
9
|
+
}
|
|
10
|
+
export function chooseRagNotice(input) {
|
|
11
|
+
if (input.errorMessage)
|
|
12
|
+
return RAG_FAILED_NOTICE;
|
|
13
|
+
if (input.pendingReferenced)
|
|
14
|
+
return RAG_UNAVAILABLE_NOTICE;
|
|
15
|
+
if (input.failedFiles?.length)
|
|
16
|
+
return ragUnreadableNotice(input.failedFiles);
|
|
17
|
+
if (input.pendingFiles?.length) {
|
|
18
|
+
return `Files not yet available: ${input.pendingFiles.join(', ')}.`;
|
|
19
|
+
}
|
|
20
|
+
if (input.hitCount > 0)
|
|
21
|
+
return null;
|
|
22
|
+
if (input.searchedCount > 0)
|
|
23
|
+
return RAG_EMPTY_NOTICE;
|
|
24
|
+
if (input.indexEmpty && input.hasKnowledge)
|
|
25
|
+
return RAG_UNAVAILABLE_NOTICE;
|
|
26
|
+
return RAG_EMPTY_NOTICE;
|
|
27
|
+
}
|