@wirecat/cli-core 0.270.0 → 0.272.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/dist/cli/bot/admins.d.ts.map +1 -1
- package/dist/cli/bot/admins.js +5 -5
- package/dist/cli/bot/admins.js.map +1 -1
- package/dist/cli/bot/api.d.ts.map +1 -1
- package/dist/cli/bot/api.js +5 -1
- package/dist/cli/bot/api.js.map +1 -1
- package/dist/cli/bot/command.d.ts.map +1 -1
- package/dist/cli/bot/command.js +15 -18
- package/dist/cli/bot/command.js.map +1 -1
- package/dist/cli/bot/mcp.d.ts.map +1 -1
- package/dist/cli/bot/mcp.js +4 -2
- package/dist/cli/bot/mcp.js.map +1 -1
- package/dist/cli/bot/messages.d.ts.map +1 -1
- package/dist/cli/bot/messages.js +7 -6
- package/dist/cli/bot/messages.js.map +1 -1
- package/dist/cli/bot/moderation.d.ts.map +1 -1
- package/dist/cli/bot/moderation.js +5 -5
- package/dist/cli/bot/moderation.js.map +1 -1
- package/dist/cli/bot/people.d.ts.map +1 -1
- package/dist/cli/bot/people.js +6 -4
- package/dist/cli/bot/people.js.map +1 -1
- package/dist/cli/bot/port.d.ts +1 -1
- package/dist/cli/bot/port.d.ts.map +1 -1
- package/dist/cli/bot/setup.d.ts.map +1 -1
- package/dist/cli/bot/setup.js +8 -9
- package/dist/cli/bot/setup.js.map +1 -1
- package/dist/cli/bot/store.d.ts.map +1 -1
- package/dist/cli/bot/store.js +3 -2
- package/dist/cli/bot/store.js.map +1 -1
- package/dist/cli/bot/watch.d.ts.map +1 -1
- package/dist/cli/bot/watch.js +3 -1
- package/dist/cli/bot/watch.js.map +1 -1
- package/dist/cli/command-contract.d.ts +2 -2
- package/dist/cli/command-contract.d.ts.map +1 -1
- package/dist/cli/command-contract.js +2 -4
- package/dist/cli/command-contract.js.map +1 -1
- package/dist/cli/commands-command.d.ts +1 -1
- package/dist/cli/commands-command.d.ts.map +1 -1
- package/dist/cli/commands-command.js +8 -7
- package/dist/cli/commands-command.js.map +1 -1
- package/dist/cli/config-command.d.ts.map +1 -1
- package/dist/cli/config-command.js +4 -4
- package/dist/cli/config-command.js.map +1 -1
- package/dist/cli/effects.d.ts +20 -0
- package/dist/cli/effects.d.ts.map +1 -0
- package/dist/cli/effects.js +28 -0
- package/dist/cli/effects.js.map +1 -0
- package/dist/cli/envelope.d.ts +68 -23
- package/dist/cli/envelope.d.ts.map +1 -1
- package/dist/cli/envelope.js +36 -10
- package/dist/cli/envelope.js.map +1 -1
- package/dist/cli/index.d.ts +7 -4
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +6 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/messenger/account-command.d.ts.map +1 -1
- package/dist/cli/messenger/account-command.js +4 -3
- package/dist/cli/messenger/account-command.js.map +1 -1
- package/dist/cli/messenger/account-sessions-command.d.ts.map +1 -1
- package/dist/cli/messenger/account-sessions-command.js +4 -3
- package/dist/cli/messenger/account-sessions-command.js.map +1 -1
- package/dist/cli/messenger/admin-commands.d.ts.map +1 -1
- package/dist/cli/messenger/admin-commands.js +15 -15
- package/dist/cli/messenger/admin-commands.js.map +1 -1
- package/dist/cli/messenger/admin-contacts-command.d.ts.map +1 -1
- package/dist/cli/messenger/admin-contacts-command.js +4 -3
- package/dist/cli/messenger/admin-contacts-command.js.map +1 -1
- package/dist/cli/messenger/admin-folders-command.d.ts.map +1 -1
- package/dist/cli/messenger/admin-folders-command.js +8 -7
- package/dist/cli/messenger/admin-folders-command.js.map +1 -1
- package/dist/cli/messenger/admin-moderation-command.d.ts.map +1 -1
- package/dist/cli/messenger/admin-moderation-command.js +5 -5
- package/dist/cli/messenger/admin-moderation-command.js.map +1 -1
- package/dist/cli/messenger/admin-statistics-command.d.ts.map +1 -1
- package/dist/cli/messenger/admin-statistics-command.js +5 -1
- package/dist/cli/messenger/admin-statistics-command.js.map +1 -1
- package/dist/cli/messenger/archive-commands.d.ts.map +1 -1
- package/dist/cli/messenger/archive-commands.js +5 -3
- package/dist/cli/messenger/archive-commands.js.map +1 -1
- package/dist/cli/messenger/attachments-command.d.ts.map +1 -1
- package/dist/cli/messenger/attachments-command.js +6 -5
- package/dist/cli/messenger/attachments-command.js.map +1 -1
- package/dist/cli/messenger/backfill-command.d.ts.map +1 -1
- package/dist/cli/messenger/backfill-command.js +7 -9
- package/dist/cli/messenger/backfill-command.js.map +1 -1
- package/dist/cli/messenger/chats-bots-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-bots-command.js +3 -2
- package/dist/cli/messenger/chats-bots-command.js.map +1 -1
- package/dist/cli/messenger/chats-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-command.js +6 -7
- package/dist/cli/messenger/chats-command.js.map +1 -1
- package/dist/cli/messenger/chats-documents-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-documents-command.js +3 -1
- package/dist/cli/messenger/chats-documents-command.js.map +1 -1
- package/dist/cli/messenger/chats-members-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-members-command.js +7 -6
- package/dist/cli/messenger/chats-members-command.js.map +1 -1
- package/dist/cli/messenger/chats-read-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-read-command.js +2 -1
- package/dist/cli/messenger/chats-read-command.js.map +1 -1
- package/dist/cli/messenger/chats-stats-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-stats-command.js +2 -1
- package/dist/cli/messenger/chats-stats-command.js.map +1 -1
- package/dist/cli/messenger/chats-tracking-command.d.ts.map +1 -1
- package/dist/cli/messenger/chats-tracking-command.js +5 -6
- package/dist/cli/messenger/chats-tracking-command.js.map +1 -1
- package/dist/cli/messenger/complete-command.d.ts.map +1 -1
- package/dist/cli/messenger/complete-command.js +3 -2
- package/dist/cli/messenger/complete-command.js.map +1 -1
- package/dist/cli/messenger/contacts-command.d.ts.map +1 -1
- package/dist/cli/messenger/contacts-command.js +12 -18
- package/dist/cli/messenger/contacts-command.js.map +1 -1
- package/dist/cli/messenger/context.d.ts +1 -1
- package/dist/cli/messenger/context.d.ts.map +1 -1
- package/dist/cli/messenger/context.js.map +1 -1
- package/dist/cli/messenger/conversations-command.d.ts.map +1 -1
- package/dist/cli/messenger/conversations-command.js +19 -29
- package/dist/cli/messenger/conversations-command.js.map +1 -1
- package/dist/cli/messenger/counters-command.d.ts.map +1 -1
- package/dist/cli/messenger/counters-command.js +3 -2
- package/dist/cli/messenger/counters-command.js.map +1 -1
- package/dist/cli/messenger/doctor-command.d.ts.map +1 -1
- package/dist/cli/messenger/doctor-command.js +7 -4
- package/dist/cli/messenger/doctor-command.js.map +1 -1
- package/dist/cli/messenger/download-command.d.ts.map +1 -1
- package/dist/cli/messenger/download-command.js +3 -2
- package/dist/cli/messenger/download-command.js.map +1 -1
- package/dist/cli/messenger/flood-command.d.ts.map +1 -1
- package/dist/cli/messenger/flood-command.js +3 -1
- package/dist/cli/messenger/flood-command.js.map +1 -1
- package/dist/cli/messenger/flooded.d.ts +1 -1
- package/dist/cli/messenger/flooded.d.ts.map +1 -1
- package/dist/cli/messenger/flooded.js +1 -1
- package/dist/cli/messenger/flooded.js.map +1 -1
- package/dist/cli/messenger/gaps-command.d.ts.map +1 -1
- package/dist/cli/messenger/gaps-command.js +4 -4
- package/dist/cli/messenger/gaps-command.js.map +1 -1
- package/dist/cli/messenger/guard-commands.d.ts.map +1 -1
- package/dist/cli/messenger/guard-commands.js +6 -6
- package/dist/cli/messenger/guard-commands.js.map +1 -1
- package/dist/cli/messenger/images-command.d.ts.map +1 -1
- package/dist/cli/messenger/images-command.js +3 -2
- package/dist/cli/messenger/images-command.js.map +1 -1
- package/dist/cli/messenger/inbox.d.ts.map +1 -1
- package/dist/cli/messenger/inbox.js +6 -1
- package/dist/cli/messenger/inbox.js.map +1 -1
- package/dist/cli/messenger/mcp-command.d.ts.map +1 -1
- package/dist/cli/messenger/mcp-command.js +5 -4
- package/dist/cli/messenger/mcp-command.js.map +1 -1
- package/dist/cli/messenger/mentions-command.d.ts.map +1 -1
- package/dist/cli/messenger/mentions-command.js +23 -12
- package/dist/cli/messenger/mentions-command.js.map +1 -1
- package/dist/cli/messenger/message-items.d.ts +1 -1
- package/dist/cli/messenger/message-items.d.ts.map +1 -1
- package/dist/cli/messenger/message-writes.d.ts +5 -6
- package/dist/cli/messenger/message-writes.d.ts.map +1 -1
- package/dist/cli/messenger/message-writes.js +7 -8
- package/dist/cli/messenger/message-writes.js.map +1 -1
- package/dist/cli/messenger/messages-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-command.js +5 -5
- package/dist/cli/messenger/messages-command.js.map +1 -1
- package/dist/cli/messenger/messages-comments-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-comments-command.js +3 -1
- package/dist/cli/messenger/messages-comments-command.js.map +1 -1
- package/dist/cli/messenger/messages-delete-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-delete-command.js +2 -1
- package/dist/cli/messenger/messages-delete-command.js.map +1 -1
- package/dist/cli/messenger/messages-edit-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-edit-command.js +2 -1
- package/dist/cli/messenger/messages-edit-command.js.map +1 -1
- package/dist/cli/messenger/messages-evidence-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-evidence-command.js +3 -1
- package/dist/cli/messenger/messages-evidence-command.js.map +1 -1
- package/dist/cli/messenger/messages-forward-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-forward-command.js +4 -3
- package/dist/cli/messenger/messages-forward-command.js.map +1 -1
- package/dist/cli/messenger/messages-link-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-link-command.js +2 -1
- package/dist/cli/messenger/messages-link-command.js.map +1 -1
- package/dist/cli/messenger/messages-pin-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-pin-command.js +3 -2
- package/dist/cli/messenger/messages-pin-command.js.map +1 -1
- package/dist/cli/messenger/messages-press-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-press-command.js +2 -1
- package/dist/cli/messenger/messages-press-command.js.map +1 -1
- package/dist/cli/messenger/messages-scheduled-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-scheduled-command.js +3 -2
- package/dist/cli/messenger/messages-scheduled-command.js.map +1 -1
- package/dist/cli/messenger/messages-search-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-search-command.js +3 -0
- package/dist/cli/messenger/messages-search-command.js.map +1 -1
- package/dist/cli/messenger/messages-send-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-send-command.js +4 -3
- package/dist/cli/messenger/messages-send-command.js.map +1 -1
- package/dist/cli/messenger/messages-stats-command.d.ts.map +1 -1
- package/dist/cli/messenger/messages-stats-command.js +2 -1
- package/dist/cli/messenger/messages-stats-command.js.map +1 -1
- package/dist/cli/messenger/metadata-command.d.ts.map +1 -1
- package/dist/cli/messenger/metadata-command.js +3 -3
- package/dist/cli/messenger/metadata-command.js.map +1 -1
- package/dist/cli/messenger/models-command.d.ts.map +1 -1
- package/dist/cli/messenger/models-command.js +9 -9
- package/dist/cli/messenger/models-command.js.map +1 -1
- package/dist/cli/messenger/observed.d.ts +1 -1
- package/dist/cli/messenger/observed.d.ts.map +1 -1
- package/dist/cli/messenger/observed.js +1 -1
- package/dist/cli/messenger/observed.js.map +1 -1
- package/dist/cli/messenger/official-stats-command.d.ts.map +1 -1
- package/dist/cli/messenger/official-stats-command.js +3 -2
- package/dist/cli/messenger/official-stats-command.js.map +1 -1
- package/dist/cli/messenger/polls-command.d.ts.map +1 -1
- package/dist/cli/messenger/polls-command.js +9 -9
- package/dist/cli/messenger/polls-command.js.map +1 -1
- package/dist/cli/messenger/private-people-command.d.ts.map +1 -1
- package/dist/cli/messenger/private-people-command.js +10 -6
- package/dist/cli/messenger/private-people-command.js.map +1 -1
- package/dist/cli/messenger/rankings-command.d.ts.map +1 -1
- package/dist/cli/messenger/rankings-command.js +3 -2
- package/dist/cli/messenger/rankings-command.js.map +1 -1
- package/dist/cli/messenger/reactions-command.d.ts.map +1 -1
- package/dist/cli/messenger/reactions-command.js +3 -2
- package/dist/cli/messenger/reactions-command.js.map +1 -1
- package/dist/cli/messenger/records-command.d.ts.map +1 -1
- package/dist/cli/messenger/records-command.js +12 -13
- package/dist/cli/messenger/records-command.js.map +1 -1
- package/dist/cli/messenger/replies-command.d.ts.map +1 -1
- package/dist/cli/messenger/replies-command.js +8 -7
- package/dist/cli/messenger/replies-command.js.map +1 -1
- package/dist/cli/messenger/replies-consents-command.d.ts.map +1 -1
- package/dist/cli/messenger/replies-consents-command.js +4 -4
- package/dist/cli/messenger/replies-consents-command.js.map +1 -1
- package/dist/cli/messenger/replies-edit-command.d.ts.map +1 -1
- package/dist/cli/messenger/replies-edit-command.js +5 -4
- package/dist/cli/messenger/replies-edit-command.js.map +1 -1
- package/dist/cli/messenger/retention-command.d.ts.map +1 -1
- package/dist/cli/messenger/retention-command.js +2 -1
- package/dist/cli/messenger/retention-command.js.map +1 -1
- package/dist/cli/messenger/review.d.ts.map +1 -1
- package/dist/cli/messenger/review.js +6 -1
- package/dist/cli/messenger/review.js.map +1 -1
- package/dist/cli/messenger/schedule-command.d.ts.map +1 -1
- package/dist/cli/messenger/schedule-command.js +8 -12
- package/dist/cli/messenger/schedule-command.js.map +1 -1
- package/dist/cli/messenger/search-answers.d.ts +1 -1
- package/dist/cli/messenger/search-answers.d.ts.map +1 -1
- package/dist/cli/messenger/search-answers.js +5 -3
- package/dist/cli/messenger/search-answers.js.map +1 -1
- package/dist/cli/messenger/search-command.d.ts.map +1 -1
- package/dist/cli/messenger/search-command.js +3 -2
- package/dist/cli/messenger/search-command.js.map +1 -1
- package/dist/cli/messenger/searches-command.d.ts.map +1 -1
- package/dist/cli/messenger/searches-command.js +9 -7
- package/dist/cli/messenger/searches-command.js.map +1 -1
- package/dist/cli/messenger/serve-command.d.ts.map +1 -1
- package/dist/cli/messenger/serve-command.js +3 -1
- package/dist/cli/messenger/serve-command.js.map +1 -1
- package/dist/cli/messenger/serve-notice.js +5 -5
- package/dist/cli/messenger/serve-notice.js.map +1 -1
- package/dist/cli/messenger/server-command.d.ts.map +1 -1
- package/dist/cli/messenger/server-command.js +9 -14
- package/dist/cli/messenger/server-command.js.map +1 -1
- package/dist/cli/messenger/stats-answers.d.ts.map +1 -1
- package/dist/cli/messenger/stats-answers.js +1 -0
- package/dist/cli/messenger/stats-answers.js.map +1 -1
- package/dist/cli/messenger/stats-command.d.ts.map +1 -1
- package/dist/cli/messenger/stats-command.js +2 -1
- package/dist/cli/messenger/stats-command.js.map +1 -1
- package/dist/cli/messenger/store-maintenance-command.d.ts.map +1 -1
- package/dist/cli/messenger/store-maintenance-command.js +12 -10
- package/dist/cli/messenger/store-maintenance-command.js.map +1 -1
- package/dist/cli/messenger/stored.d.ts +1 -1
- package/dist/cli/messenger/stored.d.ts.map +1 -1
- package/dist/cli/messenger/stored.js +1 -1
- package/dist/cli/messenger/stored.js.map +1 -1
- package/dist/cli/messenger/tags-command.d.ts.map +1 -1
- package/dist/cli/messenger/tags-command.js +5 -6
- package/dist/cli/messenger/tags-command.js.map +1 -1
- package/dist/cli/messenger/tasks-command.d.ts.map +1 -1
- package/dist/cli/messenger/tasks-command.js +9 -15
- package/dist/cli/messenger/tasks-command.js.map +1 -1
- package/dist/cli/messenger/topics-command.d.ts.map +1 -1
- package/dist/cli/messenger/topics-command.js +12 -12
- package/dist/cli/messenger/topics-command.js.map +1 -1
- package/dist/cli/messenger/transcribe-command.d.ts.map +1 -1
- package/dist/cli/messenger/transcribe-command.js +3 -2
- package/dist/cli/messenger/transcribe-command.js.map +1 -1
- package/dist/cli/messenger/watch-command.d.ts +1 -1
- package/dist/cli/messenger/watch-command.d.ts.map +1 -1
- package/dist/cli/messenger/watch-command.js +3 -1
- package/dist/cli/messenger/watch-command.js.map +1 -1
- package/dist/cli/preview.d.ts.map +1 -1
- package/dist/cli/preview.js +3 -1
- package/dist/cli/preview.js.map +1 -1
- package/dist/cli/program.d.ts.map +1 -1
- package/dist/cli/program.js +10 -2
- package/dist/cli/program.js.map +1 -1
- package/dist/cli/reasons.d.ts +1 -1
- package/dist/cli/reasons.d.ts.map +1 -1
- package/dist/cli/reasons.js +2 -1
- package/dist/cli/reasons.js.map +1 -1
- package/dist/cli/runs/command.d.ts.map +1 -1
- package/dist/cli/runs/command.js +7 -9
- package/dist/cli/runs/command.js.map +1 -1
- package/dist/cli/runs/log-events.d.ts +10 -0
- package/dist/cli/runs/log-events.d.ts.map +1 -0
- package/dist/cli/runs/log-events.js +31 -0
- package/dist/cli/runs/log-events.js.map +1 -0
- package/dist/cli/runs/recording.d.ts +1 -1
- package/dist/cli/runs/recording.d.ts.map +1 -1
- package/dist/cli/runs/recording.js +6 -4
- package/dist/cli/runs/recording.js.map +1 -1
- package/dist/cli/runs/scope.d.ts +5 -0
- package/dist/cli/runs/scope.d.ts.map +1 -1
- package/dist/cli/runs/scope.js +7 -0
- package/dist/cli/runs/scope.js.map +1 -1
- package/dist/cli/skill-command.d.ts.map +1 -1
- package/dist/cli/skill-command.js +12 -4
- package/dist/cli/skill-command.js.map +1 -1
- package/dist/cli/steps.d.ts +21 -4
- package/dist/cli/steps.d.ts.map +1 -1
- package/dist/cli/steps.js +20 -4
- package/dist/cli/steps.js.map +1 -1
- package/dist/cli/upgrade-command.d.ts.map +1 -1
- package/dist/cli/upgrade-command.js +3 -1
- package/dist/cli/upgrade-command.js.map +1 -1
- package/dist/domain/calendar.d.ts +2 -0
- package/dist/domain/calendar.d.ts.map +1 -0
- package/dist/domain/calendar.js +14 -0
- package/dist/domain/calendar.js.map +1 -0
- package/dist/domain/mentions.d.ts +1 -1
- package/dist/domain/mentions.d.ts.map +1 -1
- package/dist/domain/mentions.js +8 -2
- package/dist/domain/mentions.js.map +1 -1
- package/dist/domain/person-names.d.ts +30 -0
- package/dist/domain/person-names.d.ts.map +1 -0
- package/dist/domain/person-names.js +120 -0
- package/dist/domain/person-names.js.map +1 -0
- package/dist/embeddings/models.d.ts +2 -0
- package/dist/embeddings/models.d.ts.map +1 -1
- package/dist/embeddings/models.js +2 -0
- package/dist/embeddings/models.js.map +1 -1
- package/dist/entities/index.d.ts +9 -3
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/kit/contract.d.ts +1 -1
- package/dist/kit/contract.d.ts.map +1 -1
- package/dist/kit/contract.js +1 -1
- package/dist/kit/contract.js.map +1 -1
- package/dist/kit/fake.d.ts +1 -1
- package/dist/kit/fake.d.ts.map +1 -1
- package/dist/kit/fake.js +3 -2
- package/dist/kit/fake.js.map +1 -1
- package/dist/mcp/instructions.js +1 -1
- package/dist/mcp/instructions.js.map +1 -1
- package/dist/mcp/resources.js +1 -1
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +3 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +1 -1
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/tool.d.ts +10 -3
- package/dist/mcp/tool.d.ts.map +1 -1
- package/dist/mcp/tool.js +24 -10
- package/dist/mcp/tool.js.map +1 -1
- package/dist/mcp/tools/account.js +1 -1
- package/dist/mcp/tools/account.js.map +1 -1
- package/dist/mcp/tools/admin.js.map +1 -1
- package/dist/mcp/tools/attachments.d.ts.map +1 -1
- package/dist/mcp/tools/attachments.js +2 -0
- package/dist/mcp/tools/attachments.js.map +1 -1
- package/dist/mcp/tools/contacts.d.ts.map +1 -1
- package/dist/mcp/tools/contacts.js +3 -2
- package/dist/mcp/tools/contacts.js.map +1 -1
- package/dist/mcp/tools/folders.js.map +1 -1
- package/dist/mcp/tools/messages-actions.js +3 -3
- package/dist/mcp/tools/messages-actions.js.map +1 -1
- package/dist/mcp/tools/messages-photo.js +1 -1
- package/dist/mcp/tools/messages-photo.js.map +1 -1
- package/dist/mcp/tools/messages-send.js +3 -3
- package/dist/mcp/tools/messages-send.js.map +1 -1
- package/dist/mcp/tools/messages.d.ts.map +1 -1
- package/dist/mcp/tools/messages.js +3 -1
- package/dist/mcp/tools/messages.js.map +1 -1
- package/dist/mcp/tools/polls.js +4 -4
- package/dist/mcp/tools/polls.js.map +1 -1
- package/dist/mcp/tools/rankings.js +1 -1
- package/dist/mcp/tools/rankings.js.map +1 -1
- package/dist/mcp/tools/search-tools.js +5 -5
- package/dist/mcp/tools/search-tools.js.map +1 -1
- package/dist/mcp/tools/search.d.ts.map +1 -1
- package/dist/mcp/tools/search.js +1 -1
- package/dist/mcp/tools/search.js.map +1 -1
- package/dist/mcp/tools/store.d.ts.map +1 -1
- package/dist/mcp/tools/store.js +2 -0
- package/dist/mcp/tools/store.js.map +1 -1
- package/dist/mcp/tools/topics.js +4 -4
- package/dist/mcp/tools/topics.js.map +1 -1
- package/dist/meetings/answers.d.ts +7 -2
- package/dist/meetings/answers.d.ts.map +1 -1
- package/dist/meetings/answers.js +7 -2
- package/dist/meetings/answers.js.map +1 -1
- package/dist/meetings/cli/passage.js +1 -1
- package/dist/meetings/cli/passage.js.map +1 -1
- package/dist/meetings/cli/project-evidence.js +1 -1
- package/dist/meetings/cli/project-evidence.js.map +1 -1
- package/dist/meetings/cli/search.d.ts.map +1 -1
- package/dist/meetings/cli/search.js +6 -2
- package/dist/meetings/cli/search.js.map +1 -1
- package/dist/meetings/index.d.ts +2 -0
- package/dist/meetings/index.d.ts.map +1 -1
- package/dist/meetings/index.js +1 -0
- package/dist/meetings/index.js.map +1 -1
- package/dist/meetings/mcp/index.d.ts +13 -2
- package/dist/meetings/mcp/index.d.ts.map +1 -1
- package/dist/meetings/mcp/index.js +1 -1
- package/dist/meetings/mcp/index.js.map +1 -1
- package/dist/meetings/mcp/passage.d.ts +13 -2
- package/dist/meetings/mcp/passage.d.ts.map +1 -1
- package/dist/meetings/mcp/passage.js +1 -1
- package/dist/meetings/mcp/passage.js.map +1 -1
- package/dist/meetings/mcp/project-evidence.d.ts +13 -2
- package/dist/meetings/mcp/project-evidence.d.ts.map +1 -1
- package/dist/meetings/mcp/project-evidence.js +1 -1
- package/dist/meetings/mcp/project-evidence.js.map +1 -1
- package/dist/meetings/mcp/search.d.ts +13 -2
- package/dist/meetings/mcp/search.d.ts.map +1 -1
- package/dist/meetings/mcp/search.js +1 -1
- package/dist/meetings/mcp/search.js.map +1 -1
- package/dist/meetings/project-evidence-answer.d.ts +9 -3
- package/dist/meetings/project-evidence-answer.d.ts.map +1 -1
- package/dist/meetings/project-evidence-answer.js +6 -1
- package/dist/meetings/project-evidence-answer.js.map +1 -1
- package/dist/meetings/reads.d.ts +11 -3
- package/dist/meetings/reads.d.ts.map +1 -1
- package/dist/meetings/reads.js +2 -2
- package/dist/meetings/reads.js.map +1 -1
- package/dist/meetings/upcoming-types.d.ts +55 -0
- package/dist/meetings/upcoming-types.d.ts.map +1 -0
- package/dist/meetings/upcoming-types.js +2 -0
- package/dist/meetings/upcoming-types.js.map +1 -0
- package/dist/meetings/upcoming-validation.d.ts +5 -0
- package/dist/meetings/upcoming-validation.d.ts.map +1 -0
- package/dist/meetings/upcoming-validation.js +78 -0
- package/dist/meetings/upcoming-validation.js.map +1 -0
- package/dist/meetings/upcoming.d.ts +7 -0
- package/dist/meetings/upcoming.d.ts.map +1 -0
- package/dist/meetings/upcoming.js +72 -0
- package/dist/meetings/upcoming.js.map +1 -0
- package/dist/moderation/check.d.ts +1 -1
- package/dist/moderation/check.d.ts.map +1 -1
- package/dist/parity/deep.js +1 -1
- package/dist/parity/manifest.js +1 -1
- package/dist/parity/manifest.js.map +1 -1
- package/dist/{cli/messenger/port.d.ts → ports/messenger.d.ts} +7 -7
- package/dist/ports/messenger.d.ts.map +1 -0
- package/dist/{cli/messenger/port.js → ports/messenger.js} +1 -1
- package/dist/ports/messenger.js.map +1 -0
- package/dist/search/account-list.d.ts +3 -0
- package/dist/search/account-list.d.ts.map +1 -1
- package/dist/search/account-list.js +3 -1
- package/dist/search/account-list.js.map +1 -1
- package/dist/search/lucene/registry.d.ts.map +1 -1
- package/dist/search/lucene/registry.js +15 -0
- package/dist/search/lucene/registry.js.map +1 -1
- package/dist/sends/buttons.d.ts +1 -1
- package/dist/sends/buttons.d.ts.map +1 -1
- package/dist/sends/buttons.js +1 -1
- package/dist/sends/buttons.js.map +1 -1
- package/dist/sends/guard.js +2 -2
- package/dist/sends/guard.js.map +1 -1
- package/dist/sends/guarded.d.ts.map +1 -1
- package/dist/sends/guarded.js +5 -2
- package/dist/sends/guarded.js.map +1 -1
- package/dist/sends/index.d.ts +1 -1
- package/dist/sends/index.d.ts.map +1 -1
- package/dist/sends/index.js +1 -1
- package/dist/sends/index.js.map +1 -1
- package/dist/sends/journal.d.ts.map +1 -1
- package/dist/sends/journal.js +7 -3
- package/dist/sends/journal.js.map +1 -1
- package/dist/sends/permissions.d.ts.map +1 -1
- package/dist/sends/permissions.js +3 -0
- package/dist/sends/permissions.js.map +1 -1
- package/dist/sends/polls.d.ts +1 -1
- package/dist/sends/polls.d.ts.map +1 -1
- package/dist/sends/polls.js +1 -1
- package/dist/sends/polls.js.map +1 -1
- package/dist/sends/send-as.d.ts +1 -1
- package/dist/sends/send-as.d.ts.map +1 -1
- package/dist/sends/send-as.js +1 -1
- package/dist/sends/send-as.js.map +1 -1
- package/dist/sends/upload.d.ts +18 -2
- package/dist/sends/upload.d.ts.map +1 -1
- package/dist/sends/upload.js +32 -10
- package/dist/sends/upload.js.map +1 -1
- package/dist/services/account.d.ts +1 -1
- package/dist/services/account.d.ts.map +1 -1
- package/dist/services/account.js +1 -1
- package/dist/services/account.js.map +1 -1
- package/dist/services/admin-statistics.js +1 -1
- package/dist/services/admin-statistics.js.map +1 -1
- package/dist/services/admin.d.ts.map +1 -1
- package/dist/services/admin.js +1 -1
- package/dist/services/admin.js.map +1 -1
- package/dist/services/archive-gaps.js +1 -1
- package/dist/services/archive-gaps.js.map +1 -1
- package/dist/services/archive.d.ts.map +1 -1
- package/dist/services/archive.js +2 -2
- package/dist/services/archive.js.map +1 -1
- package/dist/services/attachments.js +1 -1
- package/dist/services/attachments.js.map +1 -1
- package/dist/services/chat-documents.js +1 -1
- package/dist/services/chat-documents.js.map +1 -1
- package/dist/services/chat-stats.d.ts.map +1 -1
- package/dist/services/chat-stats.js +2 -2
- package/dist/services/chat-stats.js.map +1 -1
- package/dist/services/chats.d.ts.map +1 -1
- package/dist/services/chats.js +2 -2
- package/dist/services/chats.js.map +1 -1
- package/dist/services/conversations.js +1 -1
- package/dist/services/conversations.js.map +1 -1
- package/dist/services/deps.d.ts +1 -1
- package/dist/services/deps.d.ts.map +1 -1
- package/dist/services/embeddings-maintenance.d.ts +51 -0
- package/dist/services/embeddings-maintenance.d.ts.map +1 -0
- package/dist/services/embeddings-maintenance.js +309 -0
- package/dist/services/embeddings-maintenance.js.map +1 -0
- package/dist/services/embeddings-search.d.ts +4 -0
- package/dist/services/embeddings-search.d.ts.map +1 -0
- package/dist/services/embeddings-search.js +329 -0
- package/dist/services/embeddings-search.js.map +1 -0
- package/dist/services/embeddings.d.ts +5 -12
- package/dist/services/embeddings.d.ts.map +1 -1
- package/dist/services/embeddings.js +7 -630
- package/dist/services/embeddings.js.map +1 -1
- package/dist/services/evidence-read.js +1 -1
- package/dist/services/evidence-read.js.map +1 -1
- package/dist/services/file-download.d.ts +1 -1
- package/dist/services/file-download.d.ts.map +1 -1
- package/dist/services/folders.d.ts.map +1 -1
- package/dist/services/folders.js +1 -1
- package/dist/services/folders.js.map +1 -1
- package/dist/services/inbox.d.ts +1 -2
- package/dist/services/inbox.d.ts.map +1 -1
- package/dist/services/inbox.js +2 -3
- package/dist/services/inbox.js.map +1 -1
- package/dist/services/index.d.ts +7 -3
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +5 -2
- package/dist/services/index.js.map +1 -1
- package/dist/services/meeting-model.d.ts +1 -1
- package/dist/services/meeting-model.d.ts.map +1 -1
- package/dist/services/meeting-model.js +1 -2
- package/dist/services/meeting-model.js.map +1 -1
- package/dist/services/mentions.d.ts +4 -0
- package/dist/services/mentions.d.ts.map +1 -1
- package/dist/services/mentions.js +2 -2
- package/dist/services/mentions.js.map +1 -1
- package/dist/services/message-query-validation.d.ts +3 -0
- package/dist/services/message-query-validation.d.ts.map +1 -0
- package/dist/services/message-query-validation.js +14 -0
- package/dist/services/message-query-validation.js.map +1 -0
- package/dist/services/message-resolution.d.ts +36 -0
- package/dist/services/message-resolution.d.ts.map +1 -0
- package/dist/services/message-resolution.js +171 -0
- package/dist/services/message-resolution.js.map +1 -0
- package/dist/services/messages-archive-search.d.ts +24 -0
- package/dist/services/messages-archive-search.d.ts.map +1 -0
- package/dist/services/messages-archive-search.js +123 -0
- package/dist/services/messages-archive-search.js.map +1 -0
- package/dist/services/messages-search.d.ts +1 -2
- package/dist/services/messages-search.d.ts.map +1 -1
- package/dist/services/messages-search.js +2 -14
- package/dist/services/messages-search.js.map +1 -1
- package/dist/services/messages.d.ts +6 -51
- package/dist/services/messages.d.ts.map +1 -1
- package/dist/services/messages.js +10 -303
- package/dist/services/messages.js.map +1 -1
- package/dist/services/metadata.js +2 -2
- package/dist/services/metadata.js.map +1 -1
- package/dist/services/moderation.d.ts.map +1 -1
- package/dist/services/moderation.js +1 -1
- package/dist/services/moderation.js.map +1 -1
- package/dist/services/notes-search.d.ts.map +1 -1
- package/dist/services/notes-search.js +1 -2
- package/dist/services/notes-search.js.map +1 -1
- package/dist/services/people.d.ts.map +1 -1
- package/dist/services/people.js +3 -3
- package/dist/services/people.js.map +1 -1
- package/dist/services/pictures.d.ts +1 -1
- package/dist/services/pictures.d.ts.map +1 -1
- package/dist/services/pictures.js +2 -2
- package/dist/services/pictures.js.map +1 -1
- package/dist/services/rankings.d.ts.map +1 -1
- package/dist/services/rankings.js +1 -1
- package/dist/services/rankings.js.map +1 -1
- package/dist/services/retention.d.ts +26 -26
- package/dist/services/retention.d.ts.map +1 -1
- package/dist/services/retention.js +1 -1
- package/dist/services/retention.js.map +1 -1
- package/dist/services/search-all-meetings.d.ts.map +1 -1
- package/dist/services/search-all-meetings.js +18 -5
- package/dist/services/search-all-meetings.js.map +1 -1
- package/dist/services/search-all.d.ts +6 -4
- package/dist/services/search-all.d.ts.map +1 -1
- package/dist/services/search-all.js +2 -2
- package/dist/services/search-all.js.map +1 -1
- package/dist/services/search-catchup.d.ts +1 -1
- package/dist/services/search-catchup.d.ts.map +1 -1
- package/dist/services/search-catchup.js +2 -2
- package/dist/services/search-catchup.js.map +1 -1
- package/dist/services/search-record.d.ts +29 -0
- package/dist/services/search-record.d.ts.map +1 -0
- package/dist/services/search-record.js +20 -0
- package/dist/services/search-record.js.map +1 -0
- package/dist/services/search-refresh.d.ts +1 -1
- package/dist/services/search-refresh.d.ts.map +1 -1
- package/dist/services/search-refresh.js +2 -1
- package/dist/services/search-refresh.js.map +1 -1
- package/dist/services/searches.d.ts +2 -27
- package/dist/services/searches.d.ts.map +1 -1
- package/dist/services/searches.js +3 -19
- package/dist/services/searches.js.map +1 -1
- package/dist/services/server-search.d.ts.map +1 -1
- package/dist/services/server-search.js +1 -1
- package/dist/services/server-search.js.map +1 -1
- package/dist/services/tags.js +1 -1
- package/dist/services/tags.js.map +1 -1
- package/dist/services/tasks.js +1 -1
- package/dist/services/tasks.js.map +1 -1
- package/dist/services/topics.d.ts +0 -1
- package/dist/services/topics.d.ts.map +1 -1
- package/dist/services/topics.js +2 -2
- package/dist/services/topics.js.map +1 -1
- package/dist/speech/hearing.d.ts +1 -1
- package/dist/speech/hearing.d.ts.map +1 -1
- package/dist/speech/transcribe.d.ts +1 -1
- package/dist/speech/transcribe.d.ts.map +1 -1
- package/dist/speech/transcribe.js +1 -1
- package/dist/speech/transcribe.js.map +1 -1
- package/dist/store/sqlite/lucene.d.ts.map +1 -1
- package/dist/store/sqlite/lucene.js +29 -0
- package/dist/store/sqlite/lucene.js.map +1 -1
- package/dist/store/sqlite/meeting-hit-index.js +1 -1
- package/dist/store/sqlite/meeting-hit-index.js.map +1 -1
- package/dist/store/sqlite/meeting-hit-search.js +1 -1
- package/dist/store/sqlite/meeting-hit-search.js.map +1 -1
- package/dist/store/sqlite/meeting-index-values.d.ts +19 -0
- package/dist/store/sqlite/meeting-index-values.d.ts.map +1 -0
- package/dist/store/sqlite/meeting-index-values.js +37 -0
- package/dist/store/sqlite/meeting-index-values.js.map +1 -0
- package/dist/store/sqlite/meetings.d.ts +0 -12
- package/dist/store/sqlite/meetings.d.ts.map +1 -1
- package/dist/store/sqlite/meetings.js +1 -35
- package/dist/store/sqlite/meetings.js.map +1 -1
- package/dist/store/sqlite/mentions.d.ts +3 -0
- package/dist/store/sqlite/mentions.d.ts.map +1 -1
- package/dist/store/sqlite/mentions.js +99 -22
- package/dist/store/sqlite/mentions.js.map +1 -1
- package/dist/store/sqlite/retention.d.ts.map +1 -1
- package/dist/store/sqlite/retention.js +1 -1
- package/dist/store/sqlite/retention.js.map +1 -1
- package/dist/store/store.d.ts +1 -0
- package/dist/store/store.d.ts.map +1 -1
- package/package.json +3 -3
- package/parity.json +8 -8
- package/dist/cli/messenger/port.d.ts.map +0 -1
- package/dist/cli/messenger/port.js.map +0 -1
|
@@ -1,631 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { CONTEXT_MESSAGES, CONTEXT_MINUTES } from "../images/context/index.js";
|
|
9
|
-
import { registeredImageProviders } from "../images/registry.js";
|
|
10
|
-
import { QUERY_LIMITS, searchError } from "../search/lucene/types.js";
|
|
11
|
-
import { threadConversation, } from "../store/store.js";
|
|
12
|
-
import { conversationsService } from "./conversations.js";
|
|
13
|
-
import { storedChatId } from "./messages.js";
|
|
14
|
-
import { prepareLucene } from "./messages-search.js";
|
|
15
|
-
import { MAIL } from "./search-kind.js";
|
|
16
|
-
import { refreshSearch } from "./search-refresh.js";
|
|
17
|
-
/** How much one run without `--chat` does at most, by default. */
|
|
18
|
-
export const REFRESH_BOUNDS = { maxChats: 20, maxChunks: 2_000 };
|
|
19
|
-
/** A vector's model: the provider, the model and its size — vectors of two of them never mix. */
|
|
20
|
-
export const vectorModelKey = (model) => `local:${model.id}:${model.dims}`;
|
|
21
|
-
/** Chunks per batch for one local session; one short transaction writes each batch. */
|
|
22
|
-
const PER_SESSION = 8;
|
|
23
|
-
/** Texts per remote request; `concurrency` of them run at once. */
|
|
24
|
-
const PER_REQUEST = 256;
|
|
25
|
-
/** How deep each list is read before the two are merged. */
|
|
26
|
-
const CANDIDATES = 50;
|
|
27
|
-
/** Messages the word search reads: one long thread can hold many of them. */
|
|
28
|
-
const WORD_HITS = 200;
|
|
29
|
-
/** Reciprocal rank fusion's usual constant (phase 5 E9). */
|
|
30
|
-
const RRF_K = 60;
|
|
31
|
-
/** e5's tokenizer reads ~3.7 characters a token in Russian; 3 keeps the bound above the real count. */
|
|
32
|
-
const CHARS_PER_TOKEN_AT_LEAST = 3;
|
|
33
|
-
export const embeddingsService = (deps) => {
|
|
34
|
-
const command = deps.messenger.app.command;
|
|
35
|
-
const notDownloaded = (id) => new CliError("not_found", `${id} is not downloaded — \`${command} models text download ${id}\``, {
|
|
36
|
-
reason: "model.not-downloaded",
|
|
37
|
-
model: id,
|
|
38
|
-
});
|
|
39
|
-
const notBuiltError = (chatId) => new CliError("not_found", `chat ${chatId} has no conversations yet — \`${command} conversations build --chat ${chatId}\``);
|
|
40
|
-
const resolve = (choice = DEFAULT_TEXT_MODEL) => {
|
|
41
|
-
if (typeof choice !== "string") {
|
|
42
|
-
const { remote, apiKey, concurrency = 4 } = choice;
|
|
43
|
-
return {
|
|
44
|
-
id: `${remote.provider}:${remote.model}`,
|
|
45
|
-
key: remoteKey(remote),
|
|
46
|
-
dims: remote.dims,
|
|
47
|
-
speed: null,
|
|
48
|
-
price: remote.price,
|
|
49
|
-
installed: true,
|
|
50
|
-
perBatch: (_workers) => PER_REQUEST * concurrency,
|
|
51
|
-
open: async () => (await import("../embeddings/remote.js")).openRemote(remote, apiKey, { concurrency }),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
const model = textModel(choice);
|
|
55
|
-
const directory = textModelsDirectory(deps.env);
|
|
56
|
-
return {
|
|
57
|
-
id: model.id,
|
|
58
|
-
key: vectorModelKey(model),
|
|
59
|
-
dims: model.dims,
|
|
60
|
-
speed: model.chunksPerSecond,
|
|
61
|
-
price: undefined,
|
|
62
|
-
installed: isTextModelInstalled(model, directory),
|
|
63
|
-
perBatch: (workers) => PER_SESSION * Math.max(1, workers),
|
|
64
|
-
open: async ({ workers = 1, threads, apart = false, } = {}) => {
|
|
65
|
-
if (!isTextModelInstalled(model, directory))
|
|
66
|
-
throw notDownloaded(model.id);
|
|
67
|
-
if (apart) {
|
|
68
|
-
const { openProcess } = await import("../embeddings/process.js");
|
|
69
|
-
return openProcess(model, directory, { threads: threads ?? defaultThreads() });
|
|
70
|
-
}
|
|
71
|
-
const { openPool } = await import("../embeddings/pool.js");
|
|
72
|
-
return openPool(model, directory, { workers, ...(threads ? { threads } : {}) });
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* The conversations holding messages that share a word with the query, best message first. Every word
|
|
78
|
-
* is one side of an OR, so a sentence ranks what shares any of it, and nothing in it is read as a filter.
|
|
79
|
-
* Only whole words and their beginnings count: a corrected spelling or a piece of a word would pass a
|
|
80
|
-
* near-miss off as a match, which is what the meaning half is for.
|
|
81
|
-
*/
|
|
82
|
-
const byWords = async (query, prepared, conversations, since) => {
|
|
83
|
-
const words = [...new Set(query.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [])];
|
|
84
|
-
const outside = new Map();
|
|
85
|
-
if (!words.length || !prepared.scopeAccounts.length)
|
|
86
|
-
return { hits: [], outside, sources: new Map() };
|
|
87
|
-
const store = await deps.store();
|
|
88
|
-
const lexical = await prepareLucene(store, await deps.account(), {
|
|
89
|
-
text: words.map((word) => (word.length >= 3 ? `${word}*` : `"${word}"`)).join(" OR "),
|
|
90
|
-
accounts: prepared.scopeAccounts,
|
|
91
|
-
limit: WORD_HITS,
|
|
92
|
-
}, deps.messenger);
|
|
93
|
-
if (!store.matchQuery)
|
|
94
|
-
throw new CliError("validation_error", "the store does not support strict search");
|
|
95
|
-
const { items } = await store.matchQuery({
|
|
96
|
-
...lexical.execution,
|
|
97
|
-
...(prepared.selectedChat ? { chat: prepared.selectedChat } : {}),
|
|
98
|
-
...(conversations === undefined ? {} : { conversationIds: conversations }),
|
|
99
|
-
...(since === undefined ? {} : { conversationSince: Date.parse(since) }),
|
|
100
|
-
});
|
|
101
|
-
const summaries = new Map();
|
|
102
|
-
const sources = new Map();
|
|
103
|
-
for (const account of prepared.scopeAccounts) {
|
|
104
|
-
const refs = items.flatMap((hit, index) => {
|
|
105
|
-
const at = parseLocator(hit.locator);
|
|
106
|
-
return at.provider === account.provider && at.account === account.account ? [{ hit, index }] : [];
|
|
107
|
-
});
|
|
108
|
-
const found = await store.conversationsOfMessages(account, refs.map(({ hit }) => ({ chatId: hit.chatId, messageId: hit.id })));
|
|
109
|
-
const chats = new Set();
|
|
110
|
-
refs.forEach(({ hit, index }, at) => {
|
|
111
|
-
const summary = found[at];
|
|
112
|
-
if (summary) {
|
|
113
|
-
summaries.set(index, summary);
|
|
114
|
-
sources.set(summary.id, account);
|
|
115
|
-
}
|
|
116
|
-
else
|
|
117
|
-
chats.add(hit.chatId);
|
|
118
|
-
});
|
|
119
|
-
outside.set(JSON.stringify(account), { account, chats });
|
|
120
|
-
}
|
|
121
|
-
const ranked = items.flatMap(({ id, score }, index) => {
|
|
122
|
-
const summary = summaries.get(index);
|
|
123
|
-
return summary ? [{ summary, chunk: { firstMessageId: id, lastMessageId: id }, score }] : [];
|
|
124
|
-
});
|
|
125
|
-
// Mail in its own tables has no conversations: each email answers as its thread, ranked with the messages.
|
|
126
|
-
const mailAccounts = prepared.scopeAccounts.filter(({ provider }) => provider === MAIL);
|
|
127
|
-
if (mailAccounts.length && conversations === undefined) {
|
|
128
|
-
const mail = await store
|
|
129
|
-
.matchQuery({
|
|
130
|
-
...lexical.execution,
|
|
131
|
-
accounts: mailAccounts,
|
|
132
|
-
corpus: "mail",
|
|
133
|
-
...(prepared.selectedChat ? { chat: prepared.selectedChat } : {}),
|
|
134
|
-
})
|
|
135
|
-
.catch((error) => {
|
|
136
|
-
if (error instanceof CliError && error.code === "validation_error")
|
|
137
|
-
return { items: [] };
|
|
138
|
-
throw error;
|
|
139
|
-
});
|
|
140
|
-
for (const account of mailAccounts) {
|
|
141
|
-
const found = mail.items.filter((hit) => {
|
|
142
|
-
const at = parseLocator(hit.locator);
|
|
143
|
-
return at.account === account.account && (since === undefined || hit.timestamp >= since);
|
|
144
|
-
});
|
|
145
|
-
if (!found.length)
|
|
146
|
-
continue;
|
|
147
|
-
const { id } = await store.storedAccount(account);
|
|
148
|
-
const places = new Map((await store.mail.inThreads(id, found.map((hit) => hit.id))).map((place) => [place.externalId, place]));
|
|
149
|
-
for (const hit of found) {
|
|
150
|
-
const place = places.get(hit.id);
|
|
151
|
-
if (!place)
|
|
152
|
-
continue;
|
|
153
|
-
const summary = threadConversation(place, Date.now());
|
|
154
|
-
sources.set(summary.id, account);
|
|
155
|
-
ranked.push({ summary, chunk: { firstMessageId: hit.id, lastMessageId: hit.id }, score: hit.score });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
ranked.sort((a, b) => (b.score ?? Number.NEGATIVE_INFINITY) - (a.score ?? Number.NEGATIVE_INFINITY));
|
|
159
|
-
}
|
|
160
|
-
const seen = new Set();
|
|
161
|
-
const hits = ranked.flatMap(({ summary, chunk }) => {
|
|
162
|
-
if (seen.has(summary.id))
|
|
163
|
-
return [];
|
|
164
|
-
seen.add(summary.id);
|
|
165
|
-
return [{ summary, chunk }];
|
|
166
|
-
});
|
|
167
|
-
return { hits, outside, sources };
|
|
168
|
-
};
|
|
169
|
-
const readinessOf = async (chatId, key) => {
|
|
170
|
-
const store = await deps.store();
|
|
171
|
-
const account = await deps.account();
|
|
172
|
-
return (await store.readiness(account, { ...(chatId === undefined ? {} : { chatId }), model: key })).map(shaped);
|
|
173
|
-
};
|
|
174
|
-
const found = async (chat) => {
|
|
175
|
-
const store = await deps.store();
|
|
176
|
-
const account = await deps.account();
|
|
177
|
-
const chatId = await storedChatId(deps.messenger, chat, store, account);
|
|
178
|
-
if (!(await store.conversationState(account, chatId))?.builtAt)
|
|
179
|
-
throw notBuiltError(chatId);
|
|
180
|
-
return { store, account, chatId };
|
|
181
|
-
};
|
|
182
|
-
/** The server's warm model when there is one, kept open after; otherwise opened here and closed. */
|
|
183
|
-
const withEmbedder = async (target, choice, { workers = 1, threads }, work) => {
|
|
184
|
-
const warm = typeof choice !== "object" ? deps.embedders : undefined;
|
|
185
|
-
const embedder = warm
|
|
186
|
-
? await warm.get(target.key, () => target.open({ apart: true }))
|
|
187
|
-
: await target.open({ workers, ...(threads ? { threads } : {}) });
|
|
188
|
-
try {
|
|
189
|
-
return await work(embedder);
|
|
190
|
-
}
|
|
191
|
-
finally {
|
|
192
|
-
if (!warm)
|
|
193
|
-
await embedder.close();
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const embedInto = async (chatId, target, embedder, { workers = 1, maxChunks = Number.POSITIVE_INFINITY, progress, check, }) => {
|
|
197
|
-
const store = await deps.store();
|
|
198
|
-
const account = await deps.account();
|
|
199
|
-
let embedded = 0;
|
|
200
|
-
let skipped = 0;
|
|
201
|
-
let left = (await store.vectorStatus(account, chatId, target.key)).chunks;
|
|
202
|
-
let after;
|
|
203
|
-
while (embedded + skipped < maxChunks) {
|
|
204
|
-
check?.();
|
|
205
|
-
const batch = await store.chunksToEmbed(account, chatId, target.key, {
|
|
206
|
-
limit: Math.min(target.perBatch(workers), maxChunks - embedded - skipped),
|
|
207
|
-
...(after ? { after } : {}),
|
|
208
|
-
});
|
|
209
|
-
if (batch.length === 0)
|
|
210
|
-
break;
|
|
211
|
-
after = batch.at(-1)?.hash;
|
|
212
|
-
const ready = batch.flatMap(({ hash, lines }) => {
|
|
213
|
-
const text = chunkTextOf(lines);
|
|
214
|
-
return chunkHash(text) === hash ? [{ hash, text }] : [];
|
|
215
|
-
});
|
|
216
|
-
skipped += batch.length - ready.length;
|
|
217
|
-
const vectors = await embedder.embed(ready.map(({ text }) => text), "passage");
|
|
218
|
-
check?.();
|
|
219
|
-
await store.saveVectors(target.key, target.dims, ready.map(({ hash }, index) => ({ hash, vector: vectors[index] })));
|
|
220
|
-
embedded += ready.length;
|
|
221
|
-
left = Math.max(0, left - batch.length);
|
|
222
|
-
progress?.(embedded, left);
|
|
223
|
-
}
|
|
224
|
-
embedded += await embedImages(chatId, target, embedder, check);
|
|
225
|
-
return { chat: chatId, model: target.id, embedded, skipped };
|
|
226
|
-
};
|
|
227
|
-
/**
|
|
228
|
-
* One chunk per image of the chat: the text its first image provider gives it, embedded like a message. The
|
|
229
|
-
* chunk's hash names the provider and its version, so a newer provider describes every image again.
|
|
230
|
-
*/
|
|
231
|
-
const embedImages = async (chatId, target, embedder, check) => {
|
|
232
|
-
const providers = registeredImageProviders();
|
|
233
|
-
if (providers.length === 0)
|
|
234
|
-
return 0;
|
|
235
|
-
const store = await deps.store();
|
|
236
|
-
const account = await deps.account();
|
|
237
|
-
const images = await store.imagesToDescribe(account, chatId, {
|
|
238
|
-
messages: CONTEXT_MESSAGES,
|
|
239
|
-
withinMs: CONTEXT_MINUTES * 60_000,
|
|
240
|
-
});
|
|
241
|
-
const described = [];
|
|
242
|
-
for (const image of images) {
|
|
243
|
-
check?.();
|
|
244
|
-
for (const provider of providers) {
|
|
245
|
-
const { text } = await provider.describe({ kind: image.kind, name: image.name, mime: image.mime, localPath: image.localPath }, {
|
|
246
|
-
chatTitle: image.chatTitle,
|
|
247
|
-
sender: image.sender,
|
|
248
|
-
caption: image.caption,
|
|
249
|
-
sentAt: image.sentAt,
|
|
250
|
-
before: image.before,
|
|
251
|
-
after: image.after,
|
|
252
|
-
});
|
|
253
|
-
if (text?.trim()) {
|
|
254
|
-
described.push({
|
|
255
|
-
attachmentPk: image.attachmentPk,
|
|
256
|
-
hash: chunkHash(`${provider.id}:${provider.version}\n${text}`),
|
|
257
|
-
text,
|
|
258
|
-
occurredAt: image.sentAt,
|
|
259
|
-
});
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
const have = await store.embeddedHashes(target.key, described.map(({ hash }) => hash));
|
|
265
|
-
const missing = [...new Map(described.filter(({ hash }) => !have.has(hash)).map((one) => [one.hash, one])).values()];
|
|
266
|
-
for (let at = 0; at < missing.length; at += PER_REQUEST) {
|
|
267
|
-
const batch = missing.slice(at, at + PER_REQUEST);
|
|
268
|
-
const vectors = await embedder.embed(batch.map(({ text }) => text), "passage");
|
|
269
|
-
check?.();
|
|
270
|
-
await store.saveVectors(target.key, target.dims, batch.map(({ hash }, index) => ({ hash, vector: vectors[index] })));
|
|
271
|
-
}
|
|
272
|
-
await store.saveImageChunks(account, chatId, described.map(({ attachmentPk, hash, text, occurredAt }) => ({
|
|
273
|
-
attachmentPk,
|
|
274
|
-
hash,
|
|
275
|
-
length: text.length,
|
|
276
|
-
occurredAt,
|
|
277
|
-
})), described.map(({ attachmentPk }) => attachmentPk));
|
|
278
|
-
return missing.length;
|
|
279
|
-
};
|
|
280
|
-
return {
|
|
281
|
-
status: async (chat, choice) => {
|
|
282
|
-
const { store, account, chatId } = await found(chat);
|
|
283
|
-
const target = resolve(choice);
|
|
284
|
-
const { chunks, embedded } = await store.vectorStatus(account, chatId, target.key);
|
|
285
|
-
const left = chunks - embedded;
|
|
286
|
-
const tokensAtMost = Math.ceil((left * CHUNK_CHARS) / CHARS_PER_TOKEN_AT_LEAST);
|
|
287
|
-
return {
|
|
288
|
-
chat: chatId,
|
|
289
|
-
model: target.id,
|
|
290
|
-
chunks,
|
|
291
|
-
embedded,
|
|
292
|
-
left,
|
|
293
|
-
estimateSeconds: target.speed === null ? null : Math.ceil(left / target.speed),
|
|
294
|
-
tokensAtMost,
|
|
295
|
-
...(target.price
|
|
296
|
-
? { priceAtMost: { usd: (tokensAtMost / 1e6) * target.price.perMillion, read: target.price.read } }
|
|
297
|
-
: {}),
|
|
298
|
-
};
|
|
299
|
-
},
|
|
300
|
-
embed: async (chat, { model: choice, workers = 1, threads, maxChunks, progress }) => {
|
|
301
|
-
const { chatId } = await found(chat);
|
|
302
|
-
const target = resolve(choice);
|
|
303
|
-
return withEmbedder(target, choice, { workers, threads }, (embedder) => embedInto(chatId, target, embedder, { workers, maxChunks, progress }));
|
|
304
|
-
},
|
|
305
|
-
search: async (query, { chat, model: choice, since, limit, filter, source, timezone, syncFirst, signal, refresh }) => {
|
|
306
|
-
if (!query.trim())
|
|
307
|
-
searchError("query.invalid-syntax", { start: 0, end: query.length }, "give words to search for");
|
|
308
|
-
if (new TextEncoder().encode(query).length > QUERY_LIMITS.bytes)
|
|
309
|
-
searchError("query.too-large", { start: 0, end: query.length }, "query is longer than 8 KiB");
|
|
310
|
-
const refreshed = await refreshSearch(deps, {
|
|
311
|
-
chat,
|
|
312
|
-
limit,
|
|
313
|
-
syncFirst,
|
|
314
|
-
signal,
|
|
315
|
-
language: "lucene",
|
|
316
|
-
text: filter,
|
|
317
|
-
source,
|
|
318
|
-
timezone,
|
|
319
|
-
});
|
|
320
|
-
const locallyRefreshed = refresh ? await embeddingsService(deps).refresh(refresh) : undefined;
|
|
321
|
-
const store = await deps.store();
|
|
322
|
-
const account = await deps.account();
|
|
323
|
-
const target = resolve(choice);
|
|
324
|
-
const stop = Date.now() + 200;
|
|
325
|
-
await store.fillSearchIndex({ until: () => Date.now() >= stop });
|
|
326
|
-
await store.fillStems({ until: () => Date.now() >= stop });
|
|
327
|
-
const prepared = await prepareLucene(store, account, {
|
|
328
|
-
...(filter === undefined ? {} : { text: filter }),
|
|
329
|
-
...(source === undefined ? {} : { source }),
|
|
330
|
-
...(chat === undefined ? {} : { chat }),
|
|
331
|
-
...(timezone === undefined ? {} : { timezone }),
|
|
332
|
-
limit,
|
|
333
|
-
}, deps.messenger);
|
|
334
|
-
if (filter !== undefined && !store.conversationEligibility)
|
|
335
|
-
throw new CliError("validation_error", "the store does not support conversation filters — upgrade cli-core");
|
|
336
|
-
const eligibility = filter === undefined ? undefined : await store.conversationEligibility?.(prepared.execution);
|
|
337
|
-
const selected = prepared.selectedChat;
|
|
338
|
-
const scopeOf = (one) => selected
|
|
339
|
-
? selected.account.provider === one.provider && selected.account.account === one.account
|
|
340
|
-
? { chatId: selected.chatId }
|
|
341
|
-
: null
|
|
342
|
-
: {};
|
|
343
|
-
const words = await byWords(query, prepared, eligibility?.conversations, since);
|
|
344
|
-
const meaning = [];
|
|
345
|
-
const sources = words.sources;
|
|
346
|
-
if (target.installed && prepared.scopeAccounts.length && eligibility?.conversations.length !== 0) {
|
|
347
|
-
await withEmbedder(target, choice, {}, async (embedder) => {
|
|
348
|
-
const [vector] = await embedder.embed([query], "query");
|
|
349
|
-
for (const one of prepared.scopeAccounts) {
|
|
350
|
-
const scope = scopeOf(one);
|
|
351
|
-
if (scope === null)
|
|
352
|
-
continue;
|
|
353
|
-
const hits = await store.nearestConversations(one, {
|
|
354
|
-
...scope,
|
|
355
|
-
...(since === undefined ? {} : { since }),
|
|
356
|
-
model: target.key,
|
|
357
|
-
limit: Math.max(limit, CANDIDATES),
|
|
358
|
-
query: vector,
|
|
359
|
-
...(eligibility ? { conversations: eligibility.conversations } : {}),
|
|
360
|
-
});
|
|
361
|
-
for (const hit of hits)
|
|
362
|
-
sources.set(hit.summary.id, one);
|
|
363
|
-
meaning.push(...hits);
|
|
364
|
-
const images = await store.nearestImages(one, {
|
|
365
|
-
...scope,
|
|
366
|
-
...(since === undefined ? {} : { since }),
|
|
367
|
-
model: target.key,
|
|
368
|
-
limit: Math.max(limit, CANDIDATES),
|
|
369
|
-
query: vector,
|
|
370
|
-
});
|
|
371
|
-
for (const hit of images) {
|
|
372
|
-
if (eligibility && !eligibility.conversations.includes(hit.summary.id))
|
|
373
|
-
continue;
|
|
374
|
-
sources.set(hit.summary.id, one);
|
|
375
|
-
meaning.push(hit);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
meaning.sort((a, b) => b.score - a.score);
|
|
381
|
-
const scoped = [];
|
|
382
|
-
const elsewhere = [];
|
|
383
|
-
for (const one of prepared.scopeAccounts) {
|
|
384
|
-
const scope = scopeOf(one);
|
|
385
|
-
if (scope === null)
|
|
386
|
-
continue;
|
|
387
|
-
const eligibleChats = eligibility?.chats
|
|
388
|
-
.filter(({ account }) => account.provider === one.provider && account.account === one.account)
|
|
389
|
-
.map(({ chat }) => chat);
|
|
390
|
-
const rows = eligibleChats === undefined
|
|
391
|
-
? await store.readiness(one, { ...scope, model: target.key })
|
|
392
|
-
: (await Promise.all(eligibleChats.map((chatId) => store.readiness(one, { chatId, model: target.key })))).flat();
|
|
393
|
-
const readiness = searchReadiness(rows.map(shaped), target.installed, words.outside.get(JSON.stringify(one))?.chats ?? new Set());
|
|
394
|
-
scoped.push({ source: one, readiness });
|
|
395
|
-
const other = await store.embeddedOnlyElsewhere(one, { ...scope, model: target.key });
|
|
396
|
-
elsewhere.push(...other
|
|
397
|
-
.filter((id) => eligibleChats === undefined || eligibleChats.includes(id))
|
|
398
|
-
.map((id) => prepared.scopeAccounts.length > 1
|
|
399
|
-
? [one.provider, one.account, id].map(encodeURIComponent).join("/")
|
|
400
|
-
: id));
|
|
401
|
-
}
|
|
402
|
-
const readiness = { searchedByMeaning: [], wordsOnly: [], partial: [], stale: [], notBuilt: [] };
|
|
403
|
-
for (const key of ["searchedByMeaning", "wordsOnly", "partial", "stale", "notBuilt"])
|
|
404
|
-
readiness[key] = [
|
|
405
|
-
...new Set(scoped.flatMap(({ source, readiness }) => readiness[key].map((id) => scoped.length > 1 ? [source.provider, source.account, id].map(encodeURIComponent).join("/") : id))),
|
|
406
|
-
].sort();
|
|
407
|
-
if (scoped.length > 1)
|
|
408
|
-
readiness.scopes = scoped;
|
|
409
|
-
return {
|
|
410
|
-
accounts: prepared.scopeAccounts,
|
|
411
|
-
model: target.id,
|
|
412
|
-
meaning: target.installed ? "searched" : "unavailable",
|
|
413
|
-
hits: fused(meaning, words.hits, meaningFloor(target.key))
|
|
414
|
-
.slice(0, limit)
|
|
415
|
-
.map((hit) => {
|
|
416
|
-
const source = sources.get(hit.summary.id);
|
|
417
|
-
return {
|
|
418
|
-
...hit,
|
|
419
|
-
source,
|
|
420
|
-
locator: formatLocator({ ...source, chat: hit.summary.chatId, message: hit.chunk.firstMessageId }),
|
|
421
|
-
};
|
|
422
|
-
}),
|
|
423
|
-
readiness,
|
|
424
|
-
...(locallyRefreshed ? { prepared: locallyRefreshed } : {}),
|
|
425
|
-
...(refreshed
|
|
426
|
-
? { refreshed, coverage: { state: refreshed.complete ? "partial" : "stale" } }
|
|
427
|
-
: {}),
|
|
428
|
-
embeddedOnlyElsewhere: elsewhere,
|
|
429
|
-
};
|
|
430
|
-
},
|
|
431
|
-
related: async (chat, message, { model: choice, limit }) => {
|
|
432
|
-
const store = await deps.store();
|
|
433
|
-
const account = await deps.account();
|
|
434
|
-
const target = resolve(choice);
|
|
435
|
-
const chatId = await storedChatId(deps.messenger, chat, store, account);
|
|
436
|
-
const [source] = await store.conversationsOfMessages(account, [{ chatId, messageId: message }]);
|
|
437
|
-
if (!source) {
|
|
438
|
-
if (!(await store.conversationState(account, chatId))?.builtAt)
|
|
439
|
-
throw notBuiltError(chatId);
|
|
440
|
-
throw new CliError("not_found", `message ${message} is in no conversation of chat ${chatId}`);
|
|
441
|
-
}
|
|
442
|
-
const { vectors } = await store.conversationVectors(account, source.id, target.key);
|
|
443
|
-
if (vectors.length === 0) {
|
|
444
|
-
const [own] = await readinessOf(chatId, target.key);
|
|
445
|
-
const step = own && isStale(own) ? "build" : "embed";
|
|
446
|
-
throw new CliError("not_found", `conversation ${source.id} has no vector of ${target.id} that matches its messages now — ` +
|
|
447
|
-
`\`${command} conversations ${step} --chat ${chatId}\``);
|
|
448
|
-
}
|
|
449
|
-
const hits = await store.nearestConversations(account, {
|
|
450
|
-
model: target.key,
|
|
451
|
-
limit: Math.max(limit, CANDIDATES),
|
|
452
|
-
query: meanOf(vectors),
|
|
453
|
-
exclude: source.id,
|
|
454
|
-
});
|
|
455
|
-
return {
|
|
456
|
-
model: target.id,
|
|
457
|
-
source,
|
|
458
|
-
hits: hits
|
|
459
|
-
.slice(0, limit)
|
|
460
|
-
.map(({ summary, chunk, score, stale }) => ({ summary, chunk, score, by: ["meaning"], stale })),
|
|
461
|
-
readiness: searchReadiness(await readinessOf(undefined, target.key), true, new Set()),
|
|
462
|
-
};
|
|
463
|
-
},
|
|
464
|
-
readiness: async ({ chat, model: choice }) => {
|
|
465
|
-
const store = await deps.store();
|
|
466
|
-
const account = await deps.account();
|
|
467
|
-
const target = resolve(choice);
|
|
468
|
-
const chatId = chat === undefined ? undefined : await storedChatId(deps.messenger, chat, store, account);
|
|
469
|
-
const chats = await readinessOf(chatId, target.key);
|
|
470
|
-
if (chatId !== undefined)
|
|
471
|
-
return { model: target.id, chats };
|
|
472
|
-
return { model: target.id, chats, unbuiltGroups: (await store.unbuiltGroups(account)).length };
|
|
473
|
-
},
|
|
474
|
-
refresh: async ({ chat, model: choice = DEFAULT_TEXT_MODEL, build = true, embed = true, maxChats = REFRESH_BOUNDS.maxChats, maxChunks = REFRESH_BOUNDS.maxChunks, workers, threads, progress, maxMessages, check, }) => {
|
|
475
|
-
check?.();
|
|
476
|
-
const store = await deps.store();
|
|
477
|
-
const account = await deps.account();
|
|
478
|
-
const target = resolve(choice);
|
|
479
|
-
if (embed && !build && !target.installed)
|
|
480
|
-
throw notDownloaded(target.id);
|
|
481
|
-
const chatId = chat === undefined ? undefined : await storedChatId(deps.messenger, chat, store, account);
|
|
482
|
-
const scan = async () => ({
|
|
483
|
-
chats: (await readinessOf(chatId, target.key)).sort(byOldestBuild),
|
|
484
|
-
unbuilt: chatId === undefined ? await store.unbuiltGroups(account) : [],
|
|
485
|
-
});
|
|
486
|
-
const built = [];
|
|
487
|
-
if (build) {
|
|
488
|
-
const { chats, unbuilt } = await scan();
|
|
489
|
-
const queue = [...chats.filter(needsBuild).map(({ chat }) => chat), ...unbuilt].slice(0, maxChats);
|
|
490
|
-
const conversations = conversationsService(deps);
|
|
491
|
-
for (const id of queue) {
|
|
492
|
-
try {
|
|
493
|
-
check?.();
|
|
494
|
-
const one = await conversations.build(id, { maxMessages, check });
|
|
495
|
-
built.push(one);
|
|
496
|
-
progress?.(`chat ${id}: ${one.messages} messages → ${one.conversations} conversations`);
|
|
497
|
-
}
|
|
498
|
-
catch (error) {
|
|
499
|
-
// Every message of a once-built chat deleted: nothing to build, and it stays in `left`.
|
|
500
|
-
if (!(error instanceof CliError && error.code === "not_found"))
|
|
501
|
-
throw error;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const embedded = [];
|
|
506
|
-
if (embed && target.installed) {
|
|
507
|
-
const fresh = new Set(built.map(({ chat }) => chat));
|
|
508
|
-
const queue = (await scan()).chats
|
|
509
|
-
.filter(needsEmbed)
|
|
510
|
-
.sort((a, b) => Number(fresh.has(b.chat)) - Number(fresh.has(a.chat)))
|
|
511
|
-
.slice(0, maxChats);
|
|
512
|
-
if (queue.length > 0) {
|
|
513
|
-
await withEmbedder(target, choice, { workers, threads }, async (embedder) => {
|
|
514
|
-
let budget = maxChunks;
|
|
515
|
-
for (const { chat } of queue) {
|
|
516
|
-
if (budget <= 0)
|
|
517
|
-
break;
|
|
518
|
-
check?.();
|
|
519
|
-
const done = await embedInto(chat, target, embedder, { workers, maxChunks: budget, check });
|
|
520
|
-
budget -= done.embedded + done.skipped;
|
|
521
|
-
embedded.push(done);
|
|
522
|
-
progress?.(`chat ${chat}: ${done.embedded} chunks embedded with ${target.id}`);
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
const after = await scan();
|
|
528
|
-
const rebuild = build ? [...after.chats.filter(needsBuild).map(({ chat }) => chat), ...after.unbuilt] : [];
|
|
529
|
-
const pending = new Set(rebuild);
|
|
530
|
-
return {
|
|
531
|
-
model: target.id,
|
|
532
|
-
modelAvailable: target.installed,
|
|
533
|
-
built,
|
|
534
|
-
embedded,
|
|
535
|
-
left: [
|
|
536
|
-
...rebuild.map((chat) => ({ chat, needs: "build" })),
|
|
537
|
-
...(embed
|
|
538
|
-
? after.chats
|
|
539
|
-
.filter((one) => needsEmbed(one) && !pending.has(one.chat))
|
|
540
|
-
.map(({ chat }) => ({ chat, needs: "embed" }))
|
|
541
|
-
: []),
|
|
542
|
-
],
|
|
543
|
-
};
|
|
544
|
-
},
|
|
545
|
-
clear: async (chat, choice) => {
|
|
546
|
-
const store = await deps.store();
|
|
547
|
-
const account = await deps.account();
|
|
548
|
-
const chatId = await storedChatId(deps.messenger, chat, store, account);
|
|
549
|
-
const cleared = await store.clearVectors(account, chatId, choice === undefined ? undefined : resolve(choice).key);
|
|
550
|
-
return { chat: chatId, cleared };
|
|
551
|
-
},
|
|
552
|
-
};
|
|
553
|
-
};
|
|
554
|
-
/** Reciprocal rank fusion of the two lists: each conversation scores 1 / (k + rank) in every list it is in. */
|
|
555
|
-
const fused = (meaning, words, minimumCosine) => {
|
|
556
|
-
const merged = new Map();
|
|
557
|
-
meaning
|
|
558
|
-
.filter(({ score }) => score > minimumCosine)
|
|
559
|
-
.forEach(({ summary, chunk, score, stale, matchedIn }, index) => {
|
|
560
|
-
merged.set(matchedIn ? `${summary.id}#${chunk.firstMessageId}` : summary.id, {
|
|
561
|
-
summary,
|
|
562
|
-
chunk,
|
|
563
|
-
score,
|
|
564
|
-
by: ["meaning"],
|
|
565
|
-
stale,
|
|
566
|
-
...(matchedIn ? { matchedIn } : {}),
|
|
567
|
-
fused: 1 / (RRF_K + index + 1),
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
words.forEach(({ summary, chunk }, index) => {
|
|
571
|
-
const share = 1 / (RRF_K + index + 1);
|
|
572
|
-
const held = merged.get(summary.id);
|
|
573
|
-
if (held) {
|
|
574
|
-
held.fused += share;
|
|
575
|
-
held.by.push("words");
|
|
576
|
-
}
|
|
577
|
-
else
|
|
578
|
-
merged.set(summary.id, { summary, chunk, score: null, by: ["words"], stale: false, fused: share });
|
|
579
|
-
});
|
|
580
|
-
return [...merged.values()]
|
|
581
|
-
.sort((a, b) => b.fused - a.fused || (b.score ?? -2) - (a.score ?? -2))
|
|
582
|
-
.map(({ fused: _, ...hit }) => hit);
|
|
583
|
-
};
|
|
584
|
-
const needsBuild = (one) => one.graph === null || isStale(one);
|
|
585
|
-
const needsEmbed = (one) => one.graph !== null && one.vectors.missing > 0;
|
|
586
|
-
/** Never finished first, then the oldest build: the longest-waiting change goes first. */
|
|
587
|
-
const byOldestBuild = (a, b) => (a.graph?.builtAt ?? "").localeCompare(b.graph?.builtAt ?? "");
|
|
588
|
-
/** The chats in readiness by how a meaning search with these vectors could see them, and the word matches outside any. */
|
|
589
|
-
const searchReadiness = (chats, meaning, outside) => {
|
|
590
|
-
const built = new Set(chats.filter(({ state }) => state !== "not-built").map(({ chat }) => chat));
|
|
591
|
-
const ids = (keep) => chats.filter(keep).map(({ chat }) => chat);
|
|
592
|
-
const byMeaning = (one) => meaning && built.has(one.chat) && one.state !== "words-only" && one.vectors.chunks > 0;
|
|
593
|
-
return {
|
|
594
|
-
searchedByMeaning: ids(byMeaning),
|
|
595
|
-
wordsOnly: ids((one) => built.has(one.chat) && !byMeaning(one)),
|
|
596
|
-
partial: ids((one) => byMeaning(one) && one.vectors.missing > 0),
|
|
597
|
-
stale: ids((one) => built.has(one.chat) && isStale(one)),
|
|
598
|
-
notBuilt: [
|
|
599
|
-
...new Set([...ids((one) => one.state === "not-built"), ...[...outside].filter((id) => !built.has(id))]),
|
|
600
|
-
].sort(),
|
|
601
|
-
};
|
|
602
|
-
};
|
|
603
|
-
/** Unit vectors' mean, made unit length again so the dot product stays a cosine. */
|
|
604
|
-
const meanOf = (vectors) => {
|
|
605
|
-
const mean = new Float32Array(vectors[0]?.length ?? 0);
|
|
606
|
-
for (const vector of vectors) {
|
|
607
|
-
for (let index = 0; index < mean.length; index++)
|
|
608
|
-
mean[index] = mean[index] + vector[index];
|
|
609
|
-
}
|
|
610
|
-
const length = Math.hypot(...mean) || 1;
|
|
611
|
-
return mean.map((value) => value / length);
|
|
612
|
-
};
|
|
613
|
-
const isStale = ({ graph, pending, vectors }) => Boolean(graph?.outdatedRules) || pending.new + pending.edited + pending.deleted > 0 || vectors.stale > 0;
|
|
614
|
-
const shaped = ({ chatId, builtAt, algorithmVersion, pending, vectors }) => {
|
|
615
|
-
const { embedded, ...counts } = vectors;
|
|
616
|
-
const graph = builtAt === null
|
|
617
|
-
? null
|
|
618
|
-
: { builtAt, rulesVersion: algorithmVersion, outdatedRules: algorithmVersion !== RULES_VERSION };
|
|
619
|
-
const one = { chat: chatId, state: "ready", graph, pending, vectors: counts };
|
|
620
|
-
const state = graph === null
|
|
621
|
-
? "not-built"
|
|
622
|
-
: counts.chunks > 0 && embedded === 0
|
|
623
|
-
? "words-only"
|
|
624
|
-
: isStale(one)
|
|
625
|
-
? "stale"
|
|
626
|
-
: counts.missing > 0
|
|
627
|
-
? "partial"
|
|
628
|
-
: "ready";
|
|
629
|
-
return { ...one, state };
|
|
630
|
-
};
|
|
1
|
+
import { embeddingsMaintenance } from "./embeddings-maintenance.js";
|
|
2
|
+
import { embeddingsSearch } from "./embeddings-search.js";
|
|
3
|
+
export { REFRESH_BOUNDS } from "./embeddings-maintenance.js";
|
|
4
|
+
export const embeddingsService = (deps) => ({
|
|
5
|
+
...embeddingsMaintenance(deps),
|
|
6
|
+
...embeddingsSearch(deps),
|
|
7
|
+
});
|
|
631
8
|
//# sourceMappingURL=embeddings.js.map
|