@wirecat/cli-core 0.306.0 → 0.307.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/analysis/consents.js +4 -4
- package/dist/analysis/consents.js.map +1 -1
- package/dist/attachments/directory.js +1 -1
- package/dist/attachments/directory.js.map +1 -1
- package/dist/botcheck/service.js +3 -3
- package/dist/botcheck/service.js.map +1 -1
- package/dist/cli/bot/context.d.ts +2 -2
- package/dist/cli/bot/copy.js +4 -4
- package/dist/cli/bot/copy.js.map +1 -1
- package/dist/cli/bot/messages.d.ts.map +1 -1
- package/dist/cli/bot/messages.js +2 -2
- package/dist/cli/bot/messages.js.map +1 -1
- package/dist/cli/bot/moderation.js +1 -1
- package/dist/cli/bot/moderation.js.map +1 -1
- package/dist/cli/bot/people.js +4 -4
- package/dist/cli/bot/people.js.map +1 -1
- package/dist/cli/bot/store.js +2 -2
- package/dist/cli/bot/store.js.map +1 -1
- package/dist/cli/config-keys.d.ts.map +1 -1
- package/dist/cli/config-keys.js +2 -1
- package/dist/cli/config-keys.js.map +1 -1
- package/dist/cli/messenger/account-command.js +1 -1
- package/dist/cli/messenger/account-command.js.map +1 -1
- package/dist/cli/messenger/complete-command.js +2 -2
- package/dist/cli/messenger/complete-command.js.map +1 -1
- package/dist/cli/messenger/context.js +1 -1
- package/dist/cli/messenger/context.js.map +1 -1
- package/dist/cli/messenger/serve-members.js +1 -1
- package/dist/cli/messenger/serve-members.js.map +1 -1
- package/dist/cli/messenger/serve-stems.js +3 -3
- package/dist/cli/messenger/serve-stems.js.map +1 -1
- package/dist/cli/messenger/stored.d.ts.map +1 -1
- package/dist/cli/messenger/stored.js +21 -21
- package/dist/cli/messenger/stored.js.map +1 -1
- package/dist/cli/store-settings.js +3 -3
- package/dist/cli/store-settings.js.map +1 -1
- package/dist/errors/reasons.d.ts.map +1 -1
- package/dist/errors/reasons.js +1 -0
- package/dist/errors/reasons.js.map +1 -1
- package/dist/files/atomic-write.d.ts +15 -0
- package/dist/files/atomic-write.d.ts.map +1 -0
- package/dist/files/atomic-write.js +35 -0
- package/dist/files/atomic-write.js.map +1 -0
- package/dist/files/index.d.ts +2 -0
- package/dist/files/index.d.ts.map +1 -1
- package/dist/files/index.js +2 -0
- package/dist/files/index.js.map +1 -1
- package/dist/files/lock.d.ts +14 -0
- package/dist/files/lock.d.ts.map +1 -0
- package/dist/files/lock.js +22 -0
- package/dist/files/lock.js.map +1 -0
- package/dist/files/native-lease-release.d.ts +3 -1
- package/dist/files/native-lease-release.d.ts.map +1 -1
- package/dist/files/native-lease-release.js +7 -3
- package/dist/files/native-lease-release.js.map +1 -1
- package/dist/kit/search-recipes.d.ts.map +1 -1
- package/dist/kit/search-recipes.js +5 -5
- package/dist/kit/search-recipes.js.map +1 -1
- package/dist/mcp/resources.js +1 -1
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/tools/chats.js +1 -1
- package/dist/mcp/tools/chats.js.map +1 -1
- package/dist/replies/dry-run.d.ts.map +1 -1
- package/dist/replies/dry-run.js +5 -5
- package/dist/replies/dry-run.js.map +1 -1
- package/dist/services/admin-statistics.js +6 -6
- package/dist/services/admin-statistics.js.map +1 -1
- package/dist/services/agenda.js +1 -1
- package/dist/services/agenda.js.map +1 -1
- package/dist/services/archive-gaps.js +4 -4
- package/dist/services/archive-gaps.js.map +1 -1
- package/dist/services/archive.d.ts.map +1 -1
- package/dist/services/archive.js +23 -23
- package/dist/services/archive.js.map +1 -1
- package/dist/services/attachments.d.ts.map +1 -1
- package/dist/services/attachments.js +21 -10
- package/dist/services/attachments.js.map +1 -1
- package/dist/services/chat-documents.js +2 -2
- package/dist/services/chat-documents.js.map +1 -1
- package/dist/services/chats.d.ts.map +1 -1
- package/dist/services/chats.js +24 -19
- package/dist/services/chats.js.map +1 -1
- package/dist/services/conversations.js +15 -15
- package/dist/services/conversations.js.map +1 -1
- package/dist/services/counters.d.ts.map +1 -1
- package/dist/services/counters.js +4 -4
- package/dist/services/counters.js.map +1 -1
- package/dist/services/embeddings-maintenance.d.ts.map +1 -1
- package/dist/services/embeddings-maintenance.js +13 -13
- package/dist/services/embeddings-maintenance.js.map +1 -1
- package/dist/services/embeddings-search.d.ts.map +1 -1
- package/dist/services/embeddings-search.js +16 -16
- package/dist/services/embeddings-search.js.map +1 -1
- package/dist/services/evidence-read.js +1 -1
- package/dist/services/evidence-read.js.map +1 -1
- package/dist/services/folders.js +1 -1
- package/dist/services/folders.js.map +1 -1
- package/dist/services/inbox.js +4 -4
- package/dist/services/inbox.js.map +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/mail-search.d.ts.map +1 -1
- package/dist/services/mail-search.js +15 -13
- package/dist/services/mail-search.js.map +1 -1
- package/dist/services/meeting-context.d.ts +4 -2
- package/dist/services/meeting-context.d.ts.map +1 -1
- package/dist/services/meeting-context.js +1 -1
- package/dist/services/meeting-context.js.map +1 -1
- package/dist/services/meeting-tasks.d.ts +4 -2
- package/dist/services/meeting-tasks.d.ts.map +1 -1
- package/dist/services/meeting-tasks.js +1 -1
- package/dist/services/meeting-tasks.js.map +1 -1
- package/dist/services/mentions.d.ts.map +1 -1
- package/dist/services/mentions.js +8 -8
- package/dist/services/mentions.js.map +1 -1
- package/dist/services/message-resolution.d.ts.map +1 -1
- package/dist/services/message-resolution.js +6 -6
- package/dist/services/message-resolution.js.map +1 -1
- package/dist/services/messages-archive-search.js +4 -4
- package/dist/services/messages-archive-search.js.map +1 -1
- package/dist/services/messages-combined.js +3 -3
- package/dist/services/messages-combined.js.map +1 -1
- package/dist/services/messages-discovery.js +2 -2
- package/dist/services/messages-discovery.js.map +1 -1
- package/dist/services/messages-search.d.ts.map +1 -1
- package/dist/services/messages-search.js +13 -13
- package/dist/services/messages-search.js.map +1 -1
- package/dist/services/messages.js +6 -6
- package/dist/services/messages.js.map +1 -1
- package/dist/services/metadata.js +9 -9
- package/dist/services/metadata.js.map +1 -1
- package/dist/services/notes-search.js +4 -4
- package/dist/services/notes-search.js.map +1 -1
- package/dist/services/people.d.ts.map +1 -1
- package/dist/services/people.js +18 -17
- package/dist/services/people.js.map +1 -1
- package/dist/services/person-context.js +16 -16
- package/dist/services/person-context.js.map +1 -1
- package/dist/services/person-meeting-context.d.ts +3 -2
- package/dist/services/person-meeting-context.d.ts.map +1 -1
- package/dist/services/person-meeting-context.js +3 -3
- package/dist/services/person-meeting-context.js.map +1 -1
- package/dist/services/person-profile.js +5 -5
- package/dist/services/person-profile.js.map +1 -1
- package/dist/services/person-timeline.js +2 -2
- package/dist/services/person-timeline.js.map +1 -1
- package/dist/services/pictures.d.ts.map +1 -1
- package/dist/services/pictures.js +9 -6
- package/dist/services/pictures.js.map +1 -1
- package/dist/services/private-people.d.ts.map +1 -1
- package/dist/services/private-people.js +7 -7
- package/dist/services/private-people.js.map +1 -1
- package/dist/services/rankings-selection.js +1 -1
- package/dist/services/rankings-selection.js.map +1 -1
- package/dist/services/rankings.js +7 -7
- package/dist/services/rankings.js.map +1 -1
- package/dist/services/retention.d.ts +3 -3
- package/dist/services/retention.js +2 -2
- package/dist/services/retention.js.map +1 -1
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all-meetings.js.map +1 -1
- package/dist/services/search-all.d.ts.map +1 -1
- package/dist/services/search-all.js +3 -1
- package/dist/services/search-all.js.map +1 -1
- package/dist/services/search-catchup.js +1 -1
- package/dist/services/search-catchup.js.map +1 -1
- package/dist/services/search-kind.js +4 -4
- package/dist/services/search-kind.js.map +1 -1
- package/dist/services/search-refresh.d.ts.map +1 -1
- package/dist/services/search-refresh.js +2 -2
- package/dist/services/search-refresh.js.map +1 -1
- package/dist/services/searches.js +7 -7
- package/dist/services/searches.js.map +1 -1
- package/dist/services/server-search.js +4 -4
- package/dist/services/server-search.js.map +1 -1
- package/dist/services/tags.d.ts.map +1 -1
- package/dist/services/tags.js +7 -4
- package/dist/services/tags.js.map +1 -1
- package/dist/services/task-rules.js +6 -6
- package/dist/services/task-rules.js.map +1 -1
- package/dist/services/tasks.js +2 -2
- package/dist/services/tasks.js.map +1 -1
- package/dist/services/thread-context.d.ts.map +1 -1
- package/dist/services/thread-context.js +5 -5
- package/dist/services/thread-context.js.map +1 -1
- package/dist/speech/hearing.d.ts.map +1 -1
- package/dist/speech/hearing.js +2 -2
- package/dist/speech/hearing.js.map +1 -1
- package/dist/store/account-store.d.ts +64 -17
- package/dist/store/account-store.d.ts.map +1 -1
- package/dist/store/account-store.js +75 -121
- package/dist/store/account-store.js.map +1 -1
- package/dist/store/accounts.d.ts +35 -0
- package/dist/store/accounts.d.ts.map +1 -0
- package/dist/store/accounts.js +47 -0
- package/dist/store/accounts.js.map +1 -0
- package/dist/store/attachments.d.ts +40 -0
- package/dist/store/attachments.d.ts.map +1 -0
- package/dist/store/attachments.js +50 -0
- package/dist/store/attachments.js.map +1 -0
- package/dist/store/chats.d.ts +47 -0
- package/dist/store/chats.d.ts.map +1 -0
- package/dist/store/chats.js +80 -0
- package/dist/store/chats.js.map +1 -0
- package/dist/store/conversations.d.ts +73 -0
- package/dist/store/conversations.d.ts.map +1 -0
- package/dist/store/conversations.js +118 -0
- package/dist/store/conversations.js.map +1 -0
- package/dist/store/counters.d.ts +25 -0
- package/dist/store/counters.d.ts.map +1 -0
- package/dist/store/counters.js +26 -0
- package/dist/store/counters.js.map +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js.map +1 -1
- package/dist/store/keys.d.ts +16 -0
- package/dist/store/keys.d.ts.map +1 -0
- package/dist/store/keys.js +25 -0
- package/dist/store/keys.js.map +1 -0
- package/dist/store/mentions.d.ts +41 -0
- package/dist/store/mentions.d.ts.map +1 -0
- package/dist/store/mentions.js +39 -0
- package/dist/store/mentions.js.map +1 -0
- package/dist/store/messages.d.ts +116 -0
- package/dist/store/messages.d.ts.map +1 -0
- package/dist/store/messages.js +102 -0
- package/dist/store/messages.js.map +1 -0
- package/dist/store/people.d.ts +53 -0
- package/dist/store/people.d.ts.map +1 -0
- package/dist/store/people.js +65 -0
- package/dist/store/people.js.map +1 -0
- package/dist/store/queries.d.ts +22 -0
- package/dist/store/queries.d.ts.map +1 -0
- package/dist/store/queries.js +22 -0
- package/dist/store/queries.js.map +1 -0
- package/dist/store/roster.d.ts +38 -0
- package/dist/store/roster.d.ts.map +1 -0
- package/dist/store/roster.js +54 -0
- package/dist/store/roster.js.map +1 -0
- package/dist/store/search-index.d.ts +40 -0
- package/dist/store/search-index.d.ts.map +1 -0
- package/dist/store/search-index.js +19 -0
- package/dist/store/search-index.js.map +1 -0
- package/dist/store/searches.d.ts +22 -0
- package/dist/store/searches.d.ts.map +1 -0
- package/dist/store/searches.js +25 -0
- package/dist/store/searches.js.map +1 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/admin-statistics.d.ts +1 -1
- package/dist/store/sqlite/batches.d.ts +1 -1
- package/dist/store/sqlite/bot-updates.d.ts +1 -1
- package/dist/store/sqlite/chats.d.ts +1 -1
- package/dist/store/sqlite/conversation-eligibility.d.ts +1 -1
- package/dist/store/sqlite/conversations.d.ts +1 -1
- package/dist/store/sqlite/emails.d.ts +1 -1
- package/dist/store/sqlite/emails.d.ts.map +1 -1
- package/dist/store/sqlite/emails.js +5 -2
- package/dist/store/sqlite/emails.js.map +1 -1
- package/dist/store/sqlite/identities.d.ts +1 -1
- package/dist/store/sqlite/knowledge.d.ts +1 -1
- package/dist/store/sqlite/lucene-fields.d.ts +66 -0
- package/dist/store/sqlite/lucene-fields.d.ts.map +1 -0
- package/dist/store/sqlite/lucene-fields.js +360 -0
- package/dist/store/sqlite/lucene-fields.js.map +1 -0
- package/dist/store/sqlite/lucene.d.ts +2 -13
- package/dist/store/sqlite/lucene.d.ts.map +1 -1
- package/dist/store/sqlite/lucene.js +27 -329
- package/dist/store/sqlite/lucene.js.map +1 -1
- package/dist/store/sqlite/meeting-projects.d.ts +1 -1
- package/dist/store/sqlite/messages.d.ts +1 -1
- package/dist/store/sqlite/person-links.d.ts +1 -1
- package/dist/store/sqlite/private-people.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/ranges.d.ts +1 -1
- package/dist/store/sqlite/ranking-evidence.d.ts +1 -1
- package/dist/store/sqlite/reads.d.ts +1 -1
- package/dist/store/sqlite/search.d.ts +1 -1
- package/dist/store/sqlite/tags.d.ts +1 -1
- package/dist/store/sqlite/task-rule-stops.d.ts +1 -1
- package/dist/store/sqlite/words.d.ts +1 -1
- package/dist/store/store.d.ts +62 -828
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +105 -836
- package/dist/store/store.js.map +1 -1
- package/dist/store/sync.d.ts +36 -0
- package/dist/store/sync.d.ts.map +1 -0
- package/dist/store/sync.js +59 -0
- package/dist/store/sync.js.map +1 -0
- package/dist/store/tags.d.ts +13 -0
- package/dist/store/tags.d.ts.map +1 -0
- package/dist/store/tags.js +23 -0
- package/dist/store/tags.js.map +1 -0
- package/dist/store/types.d.ts +247 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/types.js +2 -0
- package/dist/store/types.js.map +1 -0
- package/dist/store/vectors.d.ts +109 -0
- package/dist/store/vectors.d.ts.map +1 -0
- package/dist/store/vectors.js +221 -0
- package/dist/store/vectors.js.map +1 -0
- package/dist/update/index.d.ts +52 -0
- package/dist/update/index.d.ts.map +1 -0
- package/dist/update/index.js +68 -0
- package/dist/update/index.js.map +1 -0
- package/package.json +5 -1
package/dist/store/store.js
CHANGED
|
@@ -1,71 +1,48 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import { CliError } from "@wirecat/cli-base";
|
|
4
|
-
import { ACCOUNT_GROUPS } from "../search/account-list.js";
|
|
5
3
|
import { bindAccount } from "./account-store.js";
|
|
4
|
+
import { accountAccountsOver, accountsStoreOver } from "./accounts.js";
|
|
5
|
+
import { accountAttachmentsOver, attachmentsStoreOver, } from "./attachments.js";
|
|
6
|
+
import { chatsStoreOver } from "./chats.js";
|
|
7
|
+
import { conversationsStoreOver } from "./conversations.js";
|
|
8
|
+
import { accountCountersOver, countersStoreOver } from "./counters.js";
|
|
9
|
+
import { accountMentionsOver, mentionsStoreOver } from "./mentions.js";
|
|
10
|
+
import { accountMessagesOver, messagesStoreOver } from "./messages.js";
|
|
6
11
|
import { migrate } from "./migrations.js";
|
|
7
12
|
import { storeCapable } from "./open.js";
|
|
8
13
|
import { storePath } from "./path.js";
|
|
14
|
+
import { accountPeopleOver, peopleStoreOver } from "./people.js";
|
|
15
|
+
import { queriesStoreOver } from "./queries.js";
|
|
16
|
+
import { rosterStoreOver } from "./roster.js";
|
|
17
|
+
import { searchIndexStoreOver } from "./search-index.js";
|
|
18
|
+
import { searchesStoreOver } from "./searches.js";
|
|
9
19
|
import { sharedConfigPath } from "./shared-config.js";
|
|
10
|
-
import { accountGroupsOf, profilesOf, saveProfile } from "./sqlite/account-groups.js";
|
|
11
20
|
import * as accounts from "./sqlite/accounts.js";
|
|
12
|
-
import { adminStatisticsQuery } from "./sqlite/admin-statistics.js";
|
|
13
21
|
import { agentActionsStoreOver } from "./sqlite/agent-actions.js";
|
|
14
22
|
import * as attachmentTexts from "./sqlite/attachment-texts.js";
|
|
15
|
-
import * as attachmentRows from "./sqlite/attachments.js";
|
|
16
23
|
import { backfillNormalized, pendingNormalization } from "./sqlite/backfill.js";
|
|
17
|
-
import * as batches from "./sqlite/batches.js";
|
|
18
24
|
import { botUpdateStoreOver } from "./sqlite/bot-updates.js";
|
|
19
25
|
import { catalogStoreOver } from "./sqlite/catalog.js";
|
|
20
|
-
import
|
|
21
|
-
import * as chatQueries from "./sqlite/chats.js";
|
|
22
|
-
import * as completeness from "./sqlite/completeness.js";
|
|
23
|
-
import { conversationEligibility } from "./sqlite/conversation-eligibility.js";
|
|
24
|
-
import * as conversationQueries from "./sqlite/conversations.js";
|
|
25
|
-
import { applyCounterObservations, counterStates, counterTargets } from "./sqlite/counters.js";
|
|
26
|
-
import { documentLinkMessages } from "./sqlite/document-links.js";
|
|
27
|
-
import { drainEmailIndex } from "./sqlite/email-index.js";
|
|
28
|
-
import { mailStoreOver, threadConversation } from "./sqlite/emails.js";
|
|
26
|
+
import { mailStoreOver } from "./sqlite/emails.js";
|
|
29
27
|
import { factsStoreOver } from "./sqlite/facts.js";
|
|
30
28
|
import { fillFolded } from "./sqlite/folded.js";
|
|
31
|
-
import * as identities from "./sqlite/identities.js";
|
|
32
|
-
import * as imageChunks from "./sqlite/image-chunks.js";
|
|
33
29
|
import { involvementStoreOver } from "./sqlite/involvements.js";
|
|
34
30
|
import { knowledgeStoreOver } from "./sqlite/knowledge.js";
|
|
35
31
|
import { logPruner } from "./sqlite/log-pruning.js";
|
|
36
|
-
import * as lucene from "./sqlite/lucene.js";
|
|
37
32
|
import { meetingVectorsOver } from "./sqlite/meeting-vectors.js";
|
|
38
33
|
import { meetingStoreOver } from "./sqlite/meetings.js";
|
|
39
34
|
import { memoriesStoreOver } from "./sqlite/memories.js";
|
|
40
35
|
import { sourceMentionStoreOver } from "./sqlite/mention-sources.js";
|
|
41
|
-
import { confirmMention, listMentions, mentionOfAccount, mentionOwner, mentionsState, rebuildMentions, rejectMention, showMention, } from "./sqlite/mentions.js";
|
|
42
|
-
import * as messageWrites from "./sqlite/messages.js";
|
|
43
36
|
import { noteSearchOver } from "./sqlite/note-search.js";
|
|
44
37
|
import { notesStoreOver } from "./sqlite/notes.js";
|
|
45
38
|
import { openSqlite } from "./sqlite/open.js";
|
|
46
|
-
import * as personLinks from "./sqlite/person-links.js";
|
|
47
|
-
import { personSeenInAccounts } from "./sqlite/person-scope.js";
|
|
48
|
-
import * as privatePeople from "./sqlite/private-people.js";
|
|
49
39
|
import { proposedActionsStoreOver } from "./sqlite/proposed-actions.js";
|
|
50
|
-
import * as ranges from "./sqlite/ranges.js";
|
|
51
|
-
import { rankingEvidence } from "./sqlite/ranking-evidence.js";
|
|
52
|
-
import { rankQuery } from "./sqlite/rankings.js";
|
|
53
|
-
import * as reads from "./sqlite/reads.js";
|
|
54
|
-
import { retentionQuery } from "./sqlite/retention.js";
|
|
55
|
-
import * as roster from "./sqlite/roster.js";
|
|
56
|
-
import * as search from "./sqlite/search.js";
|
|
57
|
-
import * as searchIndex from "./sqlite/search-index.js";
|
|
58
|
-
import * as searchRecords from "./sqlite/searches.js";
|
|
59
40
|
import * as stems from "./sqlite/stems.js";
|
|
60
41
|
import { fillStems, followDefaultStemmers } from "./sqlite/stems-fill.js";
|
|
61
|
-
import
|
|
62
|
-
import
|
|
63
|
-
import {
|
|
64
|
-
import {
|
|
65
|
-
import { read, write } from "./sqlite/transaction.js";
|
|
66
|
-
import * as transcripts from "./sqlite/transcripts.js";
|
|
67
|
-
import * as vectors from "./sqlite/vectors.js";
|
|
68
|
-
import * as words from "./sqlite/words.js";
|
|
42
|
+
import { taskStoreOver } from "./sqlite/tasks.js";
|
|
43
|
+
import { syncStoreOver } from "./sync.js";
|
|
44
|
+
import { tagsStoreOver } from "./tags.js";
|
|
45
|
+
import { accountVectorsOver, vectorsStoreOver } from "./vectors.js";
|
|
69
46
|
/** About 40 ms of the first open (129k rows/s measured at 1M, 2026-09-30); Tab opens the store too. */
|
|
70
47
|
export const BACKFILL_ON_OPEN = 5_000;
|
|
71
48
|
export const openStore = async ({ path, env, now = Date.now, command } = {}) => {
|
|
@@ -96,850 +73,142 @@ export const openStore = async ({ path, env, now = Date.now, command } = {}) =>
|
|
|
96
73
|
}
|
|
97
74
|
return storeOver({ database, orm, now, sharedConfig: sharedConfigPath(file, env ?? process.env) });
|
|
98
75
|
};
|
|
76
|
+
/** Built on first use, once, so a spy on an area sees every call. */
|
|
77
|
+
const once = (build) => {
|
|
78
|
+
let built;
|
|
79
|
+
return () => {
|
|
80
|
+
built ??= build();
|
|
81
|
+
return built;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const areaOf = (keyed, whole) => once(() => {
|
|
85
|
+
const part = keyed();
|
|
86
|
+
return { keyed: part, whole: whole(part) };
|
|
87
|
+
});
|
|
99
88
|
const storeOver = (context) => {
|
|
100
89
|
const { database } = context;
|
|
101
90
|
const stemmerFor = stems.stemmerCache();
|
|
102
91
|
const pruneLogsWhenDue = logPruner(database, context.now);
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const writeState = (accountKey, name, value) => sync.writeState(context, accountKey, name, value);
|
|
120
|
-
let botUpdates;
|
|
121
|
-
let involvements;
|
|
122
|
-
let tasks;
|
|
123
|
-
let sourceMentions;
|
|
124
|
-
let knowledge;
|
|
125
|
-
let notes;
|
|
126
|
-
let catalog;
|
|
127
|
-
let facts;
|
|
128
|
-
let memories;
|
|
129
|
-
let proposedActions;
|
|
130
|
-
let agentActions;
|
|
131
|
-
let meetings;
|
|
132
|
-
let mail;
|
|
133
|
-
const mailOf = () => {
|
|
134
|
-
mail ??= mailStoreOver(context, stemmerFor);
|
|
135
|
-
return mail;
|
|
92
|
+
const own = (keyed) => ({ ...keyed });
|
|
93
|
+
// Built on first use: an area that prepares its statements must not stop the store opening for the rest.
|
|
94
|
+
const mail = once(() => mailStoreOver(context, stemmerFor));
|
|
95
|
+
const areas = {
|
|
96
|
+
accounts: areaOf(() => accountAccountsOver(context), (keyed) => accountsStoreOver(context, keyed)),
|
|
97
|
+
chats: areaOf(() => chatsStoreOver(context), own),
|
|
98
|
+
sync: areaOf(() => syncStoreOver(context), own),
|
|
99
|
+
messages: areaOf(() => accountMessagesOver(context), (keyed) => messagesStoreOver(context, keyed)),
|
|
100
|
+
attachments: areaOf(() => accountAttachmentsOver(context), (keyed) => attachmentsStoreOver(context, keyed)),
|
|
101
|
+
roster: areaOf(() => rosterStoreOver(context), own),
|
|
102
|
+
people: areaOf(() => accountPeopleOver(context), (keyed) => peopleStoreOver(context, keyed)),
|
|
103
|
+
conversations: areaOf(() => conversationsStoreOver(context), own),
|
|
104
|
+
vectors: areaOf(() => accountVectorsOver(context, mail), (keyed) => vectorsStoreOver(context, keyed)),
|
|
105
|
+
counters: areaOf(() => accountCountersOver(context), (keyed) => countersStoreOver(context, keyed)),
|
|
106
|
+
tags: areaOf(() => tagsStoreOver(context), own),
|
|
107
|
+
mentions: areaOf(() => accountMentionsOver(context), (keyed) => mentionsStoreOver(context, keyed)),
|
|
136
108
|
};
|
|
109
|
+
const searches = once(() => searchesStoreOver(context));
|
|
110
|
+
const queries = once(() => queriesStoreOver(context, stemmerFor));
|
|
111
|
+
const searchIndex = once(() => searchIndexStoreOver(context));
|
|
112
|
+
const botUpdates = once(() => botUpdateStoreOver(context, pruneLogsWhenDue));
|
|
113
|
+
const involvements = once(() => involvementStoreOver(context));
|
|
114
|
+
const tasks = once(() => taskStoreOver(context));
|
|
115
|
+
const sourceMentions = once(() => sourceMentionStoreOver(context));
|
|
116
|
+
const knowledge = once(() => knowledgeStoreOver(context));
|
|
117
|
+
const notes = once(() => ({ ...notesStoreOver(context), ...noteSearchOver(context) }));
|
|
118
|
+
const catalog = once(() => catalogStoreOver(context));
|
|
119
|
+
const facts = once(() => factsStoreOver(context));
|
|
120
|
+
const memories = once(() => memoriesStoreOver(context));
|
|
121
|
+
const proposedActions = once(() => proposedActionsStoreOver(context));
|
|
122
|
+
const agentActions = once(() => agentActionsStoreOver(context, pruneLogsWhenDue));
|
|
123
|
+
const meetings = once(() => meetingStoreOver(context));
|
|
137
124
|
const store = {
|
|
138
125
|
meetingVectors: meetingVectorsOver(context),
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
linkInbox(database, `${key.provider}:${key.account}`, pk);
|
|
142
|
-
return pk;
|
|
143
|
-
},
|
|
144
|
-
saveChats: async (key, list) => write(database, () => {
|
|
145
|
-
const accountKey = accountPk(key);
|
|
146
|
-
for (const chat of list)
|
|
147
|
-
chatQueries.upsertChat(context, accountKey, chat);
|
|
148
|
-
}),
|
|
149
|
-
saveMessages: async (key, chatId, messages, { via, seenAt }) => write(database, () => {
|
|
150
|
-
const accountKey = accountPk(key);
|
|
151
|
-
const chatKey = chatPkFor(accountKey, chatId);
|
|
152
|
-
for (const message of messages) {
|
|
153
|
-
if (message.scheduledFor === undefined)
|
|
154
|
-
upsertMessage(key, accountKey, chatKey, message, via, seenAt);
|
|
155
|
-
}
|
|
156
|
-
}),
|
|
157
|
-
saveMembers: async (key, chatId, memberIds) => write(database, () => writeMembers(key, accountPk(key), chatId, memberIds)),
|
|
158
|
-
saveRoster: async (key, chatId, read) => {
|
|
159
|
-
let change = { joined: [], gone: [], changed: [] };
|
|
160
|
-
write(database, () => {
|
|
161
|
-
const accountKey = accountPk(key);
|
|
162
|
-
change = roster.saveRoster(context, accountKey, key.provider, chatPkFor(accountKey, chatId), read);
|
|
163
|
-
});
|
|
164
|
-
return change;
|
|
165
|
-
},
|
|
166
|
-
memberStays: async (key, chatId, { since } = {}) => {
|
|
167
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
168
|
-
return chatKey === undefined
|
|
169
|
-
? []
|
|
170
|
-
: roster.memberStaysOf(context, chatKey, since === undefined ? undefined : Date.parse(since));
|
|
171
|
-
},
|
|
172
|
-
memberCounts: async (key, chatId, { since } = {}) => {
|
|
173
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
174
|
-
return chatKey === undefined ? [] : roster.memberCountsOf(context, chatKey, since);
|
|
175
|
-
},
|
|
176
|
-
profileRevisions: async (key, chatId, { since } = {}) => {
|
|
177
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
178
|
-
return chatKey === undefined
|
|
179
|
-
? []
|
|
180
|
-
: roster.profileRevisionsOf(context, chatKey, since === undefined ? undefined : Date.parse(since));
|
|
181
|
-
},
|
|
182
|
-
trackMembers: async (key, chatId, tracked) => write(database, () => roster.setTracked(context, chatPkFor(accountPk(key), chatId), tracked)),
|
|
183
|
-
trackedChats: async (key) => {
|
|
184
|
-
const accountKey = findAccountPk(key);
|
|
185
|
-
return accountKey === undefined ? [] : roster.trackedChats(context, accountKey);
|
|
186
|
-
},
|
|
187
|
-
members: async (key, chatId) => {
|
|
188
|
-
const accountKey = findAccountPk(key);
|
|
189
|
-
const chatKey = accountKey === undefined ? undefined : findChatPk(accountKey, chatId);
|
|
190
|
-
return chatKey === undefined ? [] : chatQueries.members(context, chatKey);
|
|
191
|
-
},
|
|
192
|
-
personOf: async (identity) => personLinks.personOf(context, identity),
|
|
193
|
-
personSeenInAccounts: async (uid, accountIds) => personSeenInAccounts(context, uid, accountIds),
|
|
194
|
-
personByUid: async (uid) => personLinks.personByUid(context, uid),
|
|
195
|
-
linkIdentities: async (person, other, options) => {
|
|
196
|
-
return write(database, () => personLinks.linkIdentities(context, person, other, options));
|
|
197
|
-
},
|
|
198
|
-
unlinkIdentity: async (identity, options) => {
|
|
199
|
-
return write(database, () => personLinks.unlinkIdentity(context, identity, options));
|
|
200
|
-
},
|
|
201
|
-
mentioning: async (key, person, limit) => {
|
|
202
|
-
const accountKey = findAccountPk(key);
|
|
203
|
-
return accountKey === undefined
|
|
204
|
-
? { items: [], hasMore: false }
|
|
205
|
-
: personLinks.mentioning(context, accountKey, person, limit);
|
|
206
|
-
},
|
|
207
|
-
chatsWith: async (key, memberId) => {
|
|
208
|
-
const accountKey = findAccountPk(key);
|
|
209
|
-
return accountKey === undefined ? [] : chatQueries.chatsWith(context, accountKey, key, memberId);
|
|
210
|
-
},
|
|
211
|
-
syncState: async (key, name) => {
|
|
212
|
-
const accountKey = findAccountPk(key);
|
|
213
|
-
return accountKey === undefined ? undefined : sync.syncStateOf(context, accountKey, name);
|
|
214
|
-
},
|
|
215
|
-
setSyncState: async (key, name, value) => write(database, () => writeState(accountPk(key), name, value)),
|
|
216
|
-
applyDelta: async (key, { chats = [], people = [], members = new Map(), state = {} }) => write(database, () => {
|
|
217
|
-
const accountKey = accountPk(key);
|
|
218
|
-
for (const chat of chats)
|
|
219
|
-
chatQueries.upsertChat(context, accountKey, chat);
|
|
220
|
-
for (const person of people)
|
|
221
|
-
identityPk(accountKey, key.provider, person.id, person.name, person);
|
|
222
|
-
for (const [chatId, ids] of members)
|
|
223
|
-
writeMembers(key, accountKey, chatId, ids);
|
|
224
|
-
for (const [name, value] of Object.entries(state))
|
|
225
|
-
writeState(accountKey, name, value);
|
|
226
|
-
}),
|
|
227
|
-
clearSyncState: async (key, name) => {
|
|
228
|
-
const accountKey = findAccountPk(key);
|
|
229
|
-
if (accountKey !== undefined)
|
|
230
|
-
sync.clearState(context, accountKey, name);
|
|
231
|
-
},
|
|
232
|
-
claim: async (key, chatId, anchor, holder, forMs) => {
|
|
233
|
-
let taken = false;
|
|
234
|
-
write(database, () => {
|
|
235
|
-
taken = sync.claim(context, chatPkFor(accountPk(key), chatId), anchor, holder, forMs);
|
|
236
|
-
});
|
|
237
|
-
return taken;
|
|
238
|
-
},
|
|
239
|
-
release: async (key, chatId, anchor, holder) => {
|
|
240
|
-
const accountKey = findAccountPk(key);
|
|
241
|
-
const chatKey = accountKey === undefined ? undefined : findChatPk(accountKey, chatId);
|
|
242
|
-
if (chatKey !== undefined)
|
|
243
|
-
sync.release(context, chatKey, anchor, holder);
|
|
244
|
-
},
|
|
245
|
-
transcript: async (key, chatId, messageId) => {
|
|
246
|
-
const accountKey = findAccountPk(key);
|
|
247
|
-
const chatKey = accountKey === undefined ? undefined : findChatPk(accountKey, chatId);
|
|
248
|
-
return chatKey === undefined ? undefined : transcripts.transcript(context, chatKey, messageId);
|
|
249
|
-
},
|
|
250
|
-
keepTranscript: async (key, chatId, messageId, text, source) => {
|
|
251
|
-
if (text.trim() === "")
|
|
252
|
-
return;
|
|
253
|
-
write(database, () => transcripts.keepTranscript(context, chatPkFor(accountPk(key), chatId), messageId, text, source));
|
|
254
|
-
},
|
|
255
|
-
fileAttachments: async (key, { chatId, ...page }) => {
|
|
256
|
-
const accountKey = findAccountPk(key);
|
|
257
|
-
if (accountKey === undefined)
|
|
258
|
-
return [];
|
|
259
|
-
if (chatId === undefined)
|
|
260
|
-
return attachmentTexts.fileAttachments(context, accountKey, page);
|
|
261
|
-
const chatKey = findChatPk(accountKey, chatId);
|
|
262
|
-
return chatKey === undefined ? [] : attachmentTexts.fileAttachments(context, accountKey, { ...page, chatKey });
|
|
263
|
-
},
|
|
264
|
-
attachments: async (key, { chatId, ...filter }) => {
|
|
265
|
-
const accountKey = findAccountPk(key);
|
|
266
|
-
if (accountKey === undefined)
|
|
267
|
-
return [];
|
|
268
|
-
if (chatId === undefined)
|
|
269
|
-
return attachmentTexts.attachmentViews(context, accountKey, filter);
|
|
270
|
-
const chatKey = findChatPk(accountKey, chatId);
|
|
271
|
-
return chatKey === undefined ? [] : attachmentTexts.attachmentViews(context, accountKey, { ...filter, chatKey });
|
|
272
|
-
},
|
|
273
|
-
localPathOf: async (attachmentPk) => attachmentTexts.localPathOf(context, attachmentPk),
|
|
274
|
-
keepAttachmentText: async (attachmentPk, entry) => {
|
|
275
|
-
let kept = false;
|
|
276
|
-
write(database, () => {
|
|
277
|
-
kept = attachmentTexts.keepText(context, attachmentPk, entry);
|
|
278
|
-
});
|
|
279
|
-
return kept;
|
|
280
|
-
},
|
|
281
|
-
keepDownloads: async (key, chatId, messageId, files) => {
|
|
282
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
283
|
-
if (chatKey === undefined || files.length === 0)
|
|
284
|
-
return 0;
|
|
285
|
-
let kept = 0;
|
|
286
|
-
write(database, () => {
|
|
287
|
-
kept = attachmentRows.keepDownloads(context, chatKey, messageId, files);
|
|
288
|
-
});
|
|
289
|
-
return kept;
|
|
290
|
-
},
|
|
291
|
-
linkInputs: async (key, chatId, page) => {
|
|
292
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
293
|
-
return chatKey === undefined ? { items: [], next: null } : conversationQueries.linkInputs(context, chatKey, page);
|
|
294
|
-
},
|
|
295
|
-
senderHandles: async (key, chatId) => {
|
|
296
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
297
|
-
return chatKey === undefined ? new Map() : conversationQueries.senderHandles(context, chatKey);
|
|
298
|
-
},
|
|
299
|
-
replaceConversations: async (key, chatId, build) => {
|
|
300
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
301
|
-
if (chatKey === undefined)
|
|
302
|
-
throw new CliError("not_found", `chat ${chatId} is not in the local copy`);
|
|
303
|
-
await conversationQueries.replaceConversations(context, chatKey, build);
|
|
304
|
-
},
|
|
305
|
-
conversations: async (key, chatId, window) => {
|
|
306
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
307
|
-
return chatKey === undefined
|
|
308
|
-
? { items: [], hasMore: false }
|
|
309
|
-
: conversationQueries.conversationPage(context, chatKey, window);
|
|
310
|
-
},
|
|
311
|
-
conversation: async (key, id) => {
|
|
312
|
-
const accountKey = findAccountPk(key);
|
|
313
|
-
const pk = Number(id);
|
|
314
|
-
return accountKey === undefined || !Number.isSafeInteger(pk)
|
|
315
|
-
? undefined
|
|
316
|
-
: conversationQueries.conversation(context, accountKey, pk);
|
|
317
|
-
},
|
|
318
|
-
conversationOf: async (key, chatId, messageId) => {
|
|
319
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
320
|
-
return chatKey === undefined ? undefined : conversationQueries.conversationOf(context, chatKey, messageId);
|
|
321
|
-
},
|
|
322
|
-
conversationsOfMessages: async (key, refs) => {
|
|
323
|
-
const accountPk = findAccountPk(key);
|
|
324
|
-
if (accountPk === undefined)
|
|
325
|
-
return refs.map(() => undefined);
|
|
326
|
-
const pks = refs.map(({ chatId, messageId }) => {
|
|
327
|
-
const chatKey = findChatPk(accountPk, chatId);
|
|
328
|
-
const id = chatKey === undefined ? undefined : conversationQueries.conversationOf(context, chatKey, messageId);
|
|
329
|
-
return id === undefined ? undefined : Number(id);
|
|
330
|
-
});
|
|
331
|
-
const found = conversationQueries.summariesOf(context, accountPk, pks.filter((pk) => pk !== undefined));
|
|
332
|
-
return pks.map((pk) => (pk === undefined ? undefined : found.get(pk)));
|
|
333
|
-
},
|
|
334
|
-
links: async (key, chatId, messageId, options) => {
|
|
335
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
336
|
-
return chatKey === undefined ? [] : conversationQueries.linksOf(context, chatKey, messageId, options?.limit);
|
|
337
|
-
},
|
|
338
|
-
replies: async (key, chatId, messageId, limit) => {
|
|
339
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
340
|
-
return chatKey === undefined
|
|
341
|
-
? { items: [], hasMore: false }
|
|
342
|
-
: conversationQueries.repliesTo(context, chatKey, messageId, limit);
|
|
343
|
-
},
|
|
344
|
-
agentAnswers: async (key, chatId) => {
|
|
345
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
346
|
-
return chatKey === undefined ? new Map() : conversationQueries.agentAnswers(context, chatKey);
|
|
347
|
-
},
|
|
348
|
-
saveAnswers: async (key, batch, answer) => {
|
|
349
|
-
const chatKey = batches.chatOfBatch(batch);
|
|
350
|
-
const accountKey = findAccountPk(key);
|
|
351
|
-
const chat = chatKey === undefined || accountKey === undefined ? undefined : chatQueries.chatOf(context, accountKey, chatKey);
|
|
352
|
-
if (chatKey === undefined || chat === undefined) {
|
|
353
|
-
throw new CliError("validation_error", `the answer was not stored: ${batch} is not a batch of this account`);
|
|
354
|
-
}
|
|
355
|
-
let stored = 0;
|
|
356
|
-
write(database, () => {
|
|
357
|
-
stored = batches.saveAnswers(context, batch, answer);
|
|
358
|
-
});
|
|
359
|
-
return { chat, stored };
|
|
360
|
-
},
|
|
361
|
-
clearAnswers: async (key, chatId, model) => {
|
|
362
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
363
|
-
if (chatKey === undefined)
|
|
364
|
-
return 0;
|
|
365
|
-
let cleared = 0;
|
|
366
|
-
write(database, () => {
|
|
367
|
-
cleared = batches.clearAnswers(context, chatKey, model);
|
|
368
|
-
});
|
|
369
|
-
return cleared;
|
|
370
|
-
},
|
|
371
|
-
batchStatus: async (key, chatId) => {
|
|
372
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
373
|
-
return chatKey === undefined ? { messages: 0, characters: 0 } : batches.batchStatus(context, chatKey);
|
|
374
|
-
},
|
|
375
|
-
nextBatch: async (key, chatId, { size }) => {
|
|
376
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
377
|
-
if (chatKey === undefined)
|
|
378
|
-
return undefined;
|
|
379
|
-
const found = batches.nextBatch(context, chatKey, chatId, size);
|
|
380
|
-
if (!found)
|
|
381
|
-
return undefined;
|
|
382
|
-
const answered = found.messages.filter(({ answer }) => answer);
|
|
383
|
-
const left = batches.batchStatus(context, chatKey);
|
|
384
|
-
return {
|
|
385
|
-
...found,
|
|
386
|
-
remaining: {
|
|
387
|
-
messages: left.messages - answered.length,
|
|
388
|
-
characters: left.characters - answered.reduce((sum, { text }) => sum + [...text].length, 0),
|
|
389
|
-
},
|
|
390
|
-
};
|
|
391
|
-
},
|
|
392
|
-
chunksToEmbed: async (key, chatId, model, options) => {
|
|
393
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
394
|
-
return chatKey === undefined ? [] : vectors.chunksToEmbed(context, chatKey, model, options);
|
|
395
|
-
},
|
|
396
|
-
saveVectors: async (model, dims, rows) => {
|
|
397
|
-
write(database, () => vectors.saveVectors(context, model, dims, rows));
|
|
398
|
-
},
|
|
399
|
-
imagesToDescribe: async (key, chatId, window) => {
|
|
400
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
401
|
-
return chatKey === undefined ? [] : imageChunks.imagesOfChat(context, chatKey, window);
|
|
402
|
-
},
|
|
403
|
-
saveImageChunks: async (key, chatId, chunks, keep) => {
|
|
404
|
-
const accountPk = findAccountPk(key);
|
|
405
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
406
|
-
if (accountPk === undefined || chatKey === undefined)
|
|
407
|
-
return;
|
|
408
|
-
write(database, () => imageChunks.saveImageChunks(context, accountPk, chatKey, chunks, keep));
|
|
409
|
-
},
|
|
410
|
-
embeddedHashes: async (model, hashes) => imageChunks.embeddedHashes(context, model, hashes),
|
|
411
|
-
nearestImages: async (key, { chatId, model, since, limit, query }) => {
|
|
412
|
-
const accountPk = findAccountPk(key);
|
|
413
|
-
if (accountPk === undefined)
|
|
414
|
-
return [];
|
|
415
|
-
const chatKey = chatId === undefined ? undefined : chatKeyOf(key, chatId);
|
|
416
|
-
if (chatId !== undefined && chatKey === undefined)
|
|
417
|
-
return [];
|
|
418
|
-
const nearest = imageChunks.nearestImages(context, accountPk, {
|
|
419
|
-
...(chatKey === undefined ? {} : { chatKey }),
|
|
420
|
-
...(since === undefined ? {} : { since: Date.parse(since) }),
|
|
421
|
-
model,
|
|
422
|
-
limit,
|
|
423
|
-
query,
|
|
424
|
-
});
|
|
425
|
-
const hits = [];
|
|
426
|
-
for (const { chatId: chat, messageId, score } of nearest) {
|
|
427
|
-
const chatPk = findChatPk(accountPk, chat);
|
|
428
|
-
const conversation = chatPk === undefined ? undefined : conversationQueries.conversationOf(context, chatPk, messageId);
|
|
429
|
-
const summary = conversation === undefined
|
|
430
|
-
? undefined
|
|
431
|
-
: conversationQueries.summariesOf(context, accountPk, [Number(conversation)]).get(Number(conversation));
|
|
432
|
-
if (summary)
|
|
433
|
-
hits.push({
|
|
434
|
-
summary,
|
|
435
|
-
chunk: { firstMessageId: messageId, lastMessageId: messageId },
|
|
436
|
-
score,
|
|
437
|
-
stale: false,
|
|
438
|
-
matchedIn: "context",
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
return hits;
|
|
442
|
-
},
|
|
443
|
-
picturesToEmbed: async (key, { chatId, after, limit }) => {
|
|
444
|
-
const accountPk = findAccountPk(key);
|
|
445
|
-
if (accountPk === undefined)
|
|
446
|
-
return [];
|
|
447
|
-
const chatKey = chatId === undefined ? undefined : chatKeyOf(key, chatId);
|
|
448
|
-
if (chatId !== undefined && chatKey === undefined)
|
|
449
|
-
return [];
|
|
450
|
-
return imageChunks.picturesToEmbed(context, accountPk, {
|
|
451
|
-
...(chatKey === undefined ? {} : { chatKey }),
|
|
452
|
-
...(after === undefined ? {} : { after }),
|
|
453
|
-
limit,
|
|
454
|
-
});
|
|
455
|
-
},
|
|
456
|
-
savePictures: async (key, model, dims, pictures) => {
|
|
457
|
-
const accountPk = findAccountPk(key);
|
|
458
|
-
if (accountPk === undefined)
|
|
459
|
-
return;
|
|
460
|
-
write(database, () => {
|
|
461
|
-
vectors.saveVectors(context, model, dims, pictures.map(({ hash, vector }) => ({ hash, vector })));
|
|
462
|
-
imageChunks.savePictureChunks(context, accountPk, pictures);
|
|
463
|
-
});
|
|
464
|
-
},
|
|
465
|
-
nearestPictures: async (key, { chatId, model, since, limit, query }) => {
|
|
466
|
-
const accountPk = findAccountPk(key);
|
|
467
|
-
if (accountPk === undefined)
|
|
468
|
-
return [];
|
|
469
|
-
const chatKey = chatId === undefined ? undefined : chatKeyOf(key, chatId);
|
|
470
|
-
if (chatId !== undefined && chatKey === undefined)
|
|
471
|
-
return [];
|
|
472
|
-
return imageChunks.nearestImages(context, accountPk, {
|
|
473
|
-
...(chatKey === undefined ? {} : { chatKey }),
|
|
474
|
-
...(since === undefined ? {} : { since: Date.parse(since) }),
|
|
475
|
-
model,
|
|
476
|
-
limit,
|
|
477
|
-
query,
|
|
478
|
-
position: imageChunks.PICTURE_POSITION,
|
|
479
|
-
});
|
|
480
|
-
},
|
|
481
|
-
vectorStatus: async (key, chatId, model) => {
|
|
482
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
483
|
-
return chatKey === undefined ? { chunks: 0, embedded: 0 } : vectors.vectorStatus(context, chatKey, model);
|
|
484
|
-
},
|
|
485
|
-
clearVectors: async (key, chatId, model) => {
|
|
486
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
487
|
-
if (chatKey === undefined)
|
|
488
|
-
return 0;
|
|
489
|
-
let cleared = 0;
|
|
490
|
-
write(database, () => {
|
|
491
|
-
cleared = vectors.clearVectors(context, chatKey, model);
|
|
492
|
-
});
|
|
493
|
-
return cleared;
|
|
494
|
-
},
|
|
495
|
-
nearestConversations: async (key, { chatId, model, since, limit, query, exclude, conversations, scope, projectId, personId, before }) => {
|
|
496
|
-
const accountPk = findAccountPk(key);
|
|
497
|
-
if (accountPk === undefined)
|
|
498
|
-
return [];
|
|
499
|
-
const chatKey = chatId === undefined ? undefined : chatKeyOf(key, chatId);
|
|
500
|
-
const mailToo = key.provider === "email" &&
|
|
501
|
-
conversations === undefined &&
|
|
502
|
-
scope === undefined &&
|
|
503
|
-
projectId === undefined &&
|
|
504
|
-
personId === undefined &&
|
|
505
|
-
before === undefined;
|
|
506
|
-
const mailHits = async () => mailToo
|
|
507
|
-
? (await mailOf().nearest(model, query, {
|
|
508
|
-
accountId: accountPk,
|
|
509
|
-
limit,
|
|
510
|
-
...(chatId === undefined ? {} : { threadExternalId: chatId }),
|
|
511
|
-
...(since === undefined ? {} : { since: Date.parse(since) }),
|
|
512
|
-
})).map((hit) => ({
|
|
513
|
-
summary: threadConversation(hit, context.now()),
|
|
514
|
-
chunk: { firstMessageId: hit.externalId, lastMessageId: hit.externalId },
|
|
515
|
-
score: hit.score,
|
|
516
|
-
stale: false,
|
|
517
|
-
}))
|
|
518
|
-
: [];
|
|
519
|
-
if (chatId !== undefined && chatKey === undefined)
|
|
520
|
-
return mailHits();
|
|
521
|
-
const nearest = vectors.nearestChunks(context, accountPk, {
|
|
522
|
-
...(chatKey === undefined ? {} : { chatKey }),
|
|
523
|
-
...(since === undefined ? {} : { since: Date.parse(since) }),
|
|
524
|
-
...(exclude === undefined ? {} : { exclude: Number(exclude) }),
|
|
525
|
-
model,
|
|
526
|
-
limit,
|
|
527
|
-
query,
|
|
528
|
-
...(conversations === undefined ? {} : { conversations }),
|
|
529
|
-
...(scope === undefined ? {} : { scope }),
|
|
530
|
-
...(projectId === undefined ? {} : { projectId: Number(projectId) }),
|
|
531
|
-
...(personId === undefined ? {} : { personId: Number(personId) }),
|
|
532
|
-
...(before === undefined ? {} : { before: Date.parse(before) }),
|
|
533
|
-
});
|
|
534
|
-
const found = conversationQueries.summariesOf(context, accountPk, nearest.map(({ conversationPk }) => conversationPk));
|
|
535
|
-
const ids = vectors.messageIds(context, nearest.flatMap(({ firstMessagePk, lastMessagePk }) => [firstMessagePk, lastMessagePk]));
|
|
536
|
-
const messageHits = nearest.flatMap((chunk) => {
|
|
537
|
-
const summary = found.get(chunk.conversationPk);
|
|
538
|
-
const first = ids.get(chunk.firstMessagePk);
|
|
539
|
-
const last = ids.get(chunk.lastMessagePk);
|
|
540
|
-
const freshness = vectors.chunkFreshness(context, chunk);
|
|
541
|
-
return summary && first && last && freshness !== "deleted"
|
|
542
|
-
? [
|
|
543
|
-
{
|
|
544
|
-
summary,
|
|
545
|
-
chunk: { firstMessageId: first, lastMessageId: last },
|
|
546
|
-
score: chunk.score,
|
|
547
|
-
stale: freshness === "stale",
|
|
548
|
-
},
|
|
549
|
-
]
|
|
550
|
-
: [];
|
|
551
|
-
});
|
|
552
|
-
if (!mailToo)
|
|
553
|
-
return messageHits;
|
|
554
|
-
return [...messageHits, ...(await mailHits())].sort((a, b) => b.score - a.score).slice(0, limit);
|
|
555
|
-
},
|
|
556
|
-
conversationVectors: async (key, id, model) => {
|
|
557
|
-
const accountPk = findAccountPk(key);
|
|
558
|
-
const pk = Number(id);
|
|
559
|
-
if (accountPk === undefined || !conversationQueries.summariesOf(context, accountPk, [pk]).has(pk)) {
|
|
560
|
-
return { chunks: 0, vectors: [] };
|
|
561
|
-
}
|
|
562
|
-
return vectors.conversationVectors(context, pk, model);
|
|
563
|
-
},
|
|
564
|
-
readiness: async (key, { chatId, model }) => {
|
|
565
|
-
const accountPk = findAccountPk(key);
|
|
566
|
-
if (accountPk === undefined)
|
|
567
|
-
return [];
|
|
568
|
-
const chats = chatId === undefined
|
|
569
|
-
? vectors.builtChats(context, accountPk)
|
|
570
|
-
: [{ chatKey: chatKeyOf(key, chatId), id: chatId }].flatMap(({ chatKey, id }) => chatKey === undefined ? [] : [{ chatKey, id }]);
|
|
571
|
-
return chats.map(({ chatKey, id }) => {
|
|
572
|
-
const found = vectors.readiness(context, chatKey, model);
|
|
573
|
-
return found
|
|
574
|
-
? { chatId: id, ...found, builtAt: new Date(found.builtAt).toISOString() }
|
|
575
|
-
: {
|
|
576
|
-
chatId: id,
|
|
577
|
-
builtAt: null,
|
|
578
|
-
algorithmVersion: null,
|
|
579
|
-
pending: { new: 0, edited: 0, deleted: 0 },
|
|
580
|
-
vectors: { chunks: 0, embedded: 0, current: 0, stale: 0, missing: 0 },
|
|
581
|
-
};
|
|
582
|
-
});
|
|
583
|
-
},
|
|
584
|
-
unbuiltGroups: async (key) => {
|
|
585
|
-
const accountPk = findAccountPk(key);
|
|
586
|
-
return accountPk === undefined ? [] : vectors.unbuiltGroups(context, accountPk);
|
|
587
|
-
},
|
|
588
|
-
embeddedOnlyElsewhere: async (key, { chatId, model }) => {
|
|
589
|
-
const accountPk = findAccountPk(key);
|
|
590
|
-
if (accountPk === undefined)
|
|
591
|
-
return [];
|
|
592
|
-
const chatKey = chatId === undefined ? undefined : chatKeyOf(key, chatId);
|
|
593
|
-
if (chatId !== undefined && chatKey === undefined)
|
|
594
|
-
return [];
|
|
595
|
-
return vectors.embeddedOnlyElsewhere(context, accountPk, { ...(chatKey === undefined ? {} : { chatKey }), model });
|
|
596
|
-
},
|
|
597
|
-
conversationState: async (key, chatId) => {
|
|
598
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
599
|
-
return chatKey === undefined ? undefined : conversationQueries.stateOf(context, chatKey);
|
|
600
|
-
},
|
|
601
|
-
chats: async (key, window) => {
|
|
602
|
-
const accountKey = findAccountPk(key);
|
|
603
|
-
return accountKey === undefined
|
|
604
|
-
? { items: [], hasMore: false }
|
|
605
|
-
: chatQueries.listChats(context, accountKey, window);
|
|
606
|
-
},
|
|
607
|
-
countChats: async (key, filter = {}) => {
|
|
608
|
-
const accountKey = findAccountPk(key);
|
|
609
|
-
return accountKey === undefined ? 0 : chatQueries.countChats(context, accountKey, filter);
|
|
610
|
-
},
|
|
611
|
-
countMessages: async (key, chatId, { since } = {}) => {
|
|
612
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
613
|
-
return chatKey === undefined ? 0 : reads.countMessages(context, chatKey, since);
|
|
614
|
-
},
|
|
615
|
-
documentLinkMessages: async (key, chatId) => {
|
|
616
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
617
|
-
return chatKey === undefined ? [] : documentLinkMessages(context, chatKey);
|
|
618
|
-
},
|
|
619
|
-
mentions: async (key, query, window) => {
|
|
620
|
-
const accountKey = findAccountPk(key);
|
|
621
|
-
return accountKey === undefined
|
|
622
|
-
? { items: [], hasMore: false }
|
|
623
|
-
: listMentions(database, accountKey, query, window);
|
|
624
|
-
},
|
|
625
|
-
mention: async (key, id) => {
|
|
626
|
-
const accountKey = findAccountPk(key);
|
|
627
|
-
return accountKey === undefined ? undefined : showMention(database, accountKey, id);
|
|
628
|
-
},
|
|
629
|
-
confirmMention: async (key, id, ownerRef, by) => {
|
|
630
|
-
const accountKey = findAccountPk(key);
|
|
631
|
-
if (accountKey === undefined)
|
|
632
|
-
throw new CliError("not_found", `no mention ${id} in this account`);
|
|
633
|
-
const mention = mentionOfAccount(database, accountKey, id);
|
|
634
|
-
return write(database, () => confirmMention(context, mention, mentionOwner(context, ownerRef), by));
|
|
635
|
-
},
|
|
636
|
-
rejectMention: async (key, id, by) => {
|
|
637
|
-
const accountKey = findAccountPk(key);
|
|
638
|
-
if (accountKey === undefined)
|
|
639
|
-
throw new CliError("not_found", `no mention ${id} in this account`);
|
|
640
|
-
return write(database, () => rejectMention(context, mentionOfAccount(database, accountKey, id), by));
|
|
641
|
-
},
|
|
642
|
-
rebuildMentions: async (options = {}) => rebuildMentions(database, { now: context.now(), ...options }),
|
|
643
|
-
mentionsState: async () => mentionsState(database),
|
|
644
|
-
taskRulesStop: async (key) => taskRulesStop(database, key),
|
|
645
|
-
setTaskRulesStop: async (key, until) => setTaskRulesStop(database, key, until, context.now()),
|
|
646
|
-
changes: async (key, chatId, at) => {
|
|
647
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
648
|
-
return chatKey === undefined
|
|
649
|
-
? { messages: [], deleted: [] }
|
|
650
|
-
: reads.changesSince(context, chatKey, Date.parse(at));
|
|
651
|
-
},
|
|
652
|
-
messagesWindow: async (key, chatId, window) => {
|
|
653
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
654
|
-
return chatKey === undefined ? [] : reads.messagesWindow(context, chatKey, window);
|
|
655
|
-
},
|
|
656
|
-
messages: async (key, chatId, window) => {
|
|
657
|
-
const chatKey = chatKeyOf(key, chatId);
|
|
658
|
-
return chatKey === undefined ? { items: [], hasMore: false } : reads.messagePage(context, chatKey, window);
|
|
659
|
-
},
|
|
660
|
-
around: async (key, chatId, messageId, window) => reads.around(context, chatKeyOf(key, chatId), messageId, window),
|
|
661
|
-
message: async (key, messageId, { chatId } = {}) => {
|
|
662
|
-
const accountKey = findAccountPk(key);
|
|
663
|
-
return accountKey === undefined ? undefined : reads.message(context, accountKey, messageId, chatId);
|
|
664
|
-
},
|
|
665
|
-
markDeleted: async (key, messageIds, { chatId, among } = {}) => {
|
|
666
|
-
const accountKey = findAccountPk(key);
|
|
667
|
-
if (accountKey === undefined || messageIds.length === 0)
|
|
668
|
-
return 0;
|
|
669
|
-
let changed = 0;
|
|
670
|
-
write(database, () => {
|
|
671
|
-
changed = messageWrites.markDeleted(context, accountKey, messageIds, chatId, among);
|
|
672
|
-
});
|
|
673
|
-
return changed;
|
|
674
|
-
},
|
|
675
|
-
purge: async (key) => {
|
|
676
|
-
const accountKey = findAccountPk(key);
|
|
677
|
-
if (accountKey === undefined)
|
|
678
|
-
return;
|
|
679
|
-
write(database, () => accounts.purgeAccount(context, accountKey));
|
|
680
|
-
},
|
|
681
|
-
markChatsLeft: async (key, present) => {
|
|
682
|
-
const accountKey = findAccountPk(key);
|
|
683
|
-
if (accountKey === undefined)
|
|
684
|
-
return 0;
|
|
685
|
-
let marked = 0;
|
|
686
|
-
write(database, () => {
|
|
687
|
-
marked = chatQueries.markLeft(context, accountKey, present);
|
|
688
|
-
writeState(accountKey, completeness.CHAT_LIST_KEY, String(present.length));
|
|
689
|
-
});
|
|
690
|
-
return marked;
|
|
691
|
-
},
|
|
692
|
-
leftChats: async (key, { clear = false } = {}) => {
|
|
693
|
-
const accountKey = findAccountPk(key);
|
|
694
|
-
if (accountKey === undefined)
|
|
695
|
-
return { chats: 0, messages: 0 };
|
|
696
|
-
let found = { pks: [], messages: 0 };
|
|
697
|
-
write(database, () => {
|
|
698
|
-
found = chatQueries.leftChats(context, accountKey);
|
|
699
|
-
if (clear)
|
|
700
|
-
chatQueries.purgeChats(context, found.pks);
|
|
701
|
-
});
|
|
702
|
-
return { chats: found.pks.length, messages: found.messages };
|
|
703
|
-
},
|
|
704
|
-
search: async (query, { limit, account }) => search.find(context, { text: query, limit, ...(account ? { account } : {}) }),
|
|
705
|
-
find: async (filter) => search.find(context, filter),
|
|
706
|
-
rankingDiscussionChats: async (account, chatId) => {
|
|
707
|
-
const rows = database
|
|
708
|
-
.prepare("SELECT DISTINCT json_extract(CASE WHEN json_valid(m.metadata) THEN m.metadata ELSE '{}' END,'$.graph.discussionChatId') AS id FROM messages m JOIN chats c ON c.id=m.chat_id JOIN accounts ac ON ac.id=m.account_id WHERE ac.provider=? AND ac.external_id=? AND c.external_id=? AND c.kind='channel' AND m.deleted_at IS NULL AND json_extract(CASE WHEN json_valid(m.metadata) THEN m.metadata ELSE '{}' END,'$.graph.version')=1 AND json_type(CASE WHEN json_valid(m.metadata) THEN m.metadata ELSE '{}' END,'$.graph.discussionChatId')='text' LIMIT 101")
|
|
709
|
-
.all(account.provider, account.account, chatId);
|
|
710
|
-
if (rows.length > 100)
|
|
711
|
-
throw new CliError("validation_error", "too many linked discussion groups — narrow the channel scope");
|
|
712
|
-
return rows.map(({ id }) => String(id));
|
|
713
|
-
},
|
|
714
|
-
rankingEvidence: async (execution, request) => rankingEvidence(context, execution, request),
|
|
715
|
-
retention: async (key, chatId, options, evidence) => {
|
|
716
|
-
const accountKey = findAccountPk(key);
|
|
717
|
-
const chatKey = accountKey === undefined ? undefined : findChatPk(accountKey, chatId);
|
|
718
|
-
if (accountKey === undefined || chatKey === undefined)
|
|
719
|
-
throw new CliError("validation_error", "retention needs a stored chat and membership observations");
|
|
720
|
-
return read(database, () => retentionQuery(context, accountKey, chatKey, chatId, options, evidence));
|
|
721
|
-
},
|
|
722
|
-
adminStatisticsQuery: async (execution, request) => adminStatisticsQuery(context, execution, request),
|
|
723
|
-
rankQuery: async (execution, request) => rankQuery(context, execution, request),
|
|
724
|
-
directReplies: async (parents, limit) => search.directReplies(context, parents, limit),
|
|
725
|
-
matchQuery: async (execution) => lucene.matchQuery(context, mailIndexed(execution)),
|
|
726
|
-
conversationEligibility: async (execution) => conversationEligibility(context, execution),
|
|
727
|
-
countQuery: async (execution, by) => lucene.countQuery(context, mailIndexed(execution), by),
|
|
728
|
-
accounts: async () => accounts.heldAccounts(context),
|
|
729
|
-
storedAccounts: async () => accounts.storedAccounts(context),
|
|
730
|
-
storedAccount: async (key) => accounts.storedAccount(context, key),
|
|
731
|
-
accountName: async (key) => accounts.accountName(context, key),
|
|
732
|
-
chatCompleteness: async (key, chatIds) => {
|
|
733
|
-
const accountKey = accounts.findAccountPk(context, key);
|
|
734
|
-
return accountKey === undefined ? [] : completeness.chatCompleteness(context, accountKey, chatIds);
|
|
735
|
-
},
|
|
736
|
-
knownTerms: async (terms) => words.knownTerms(context, terms),
|
|
737
|
-
termCandidates: async (trigrams, lengths) => words.termCandidates(context, trigrams, lengths),
|
|
738
|
-
searchIndexState: async () => searchIndex.searchIndexState(database),
|
|
739
|
-
fillSearchIndex: async ({ until } = {}) => searchIndex.fillSearchIndex(database, { now: context.now, ...(until ? { until } : {}) }),
|
|
740
|
-
stemsState: async () => stems.stemsState(database),
|
|
741
|
-
fillStems: async ({ until } = {}) => fillStems(database, { now: context.now, ...(until ? { until } : {}) }),
|
|
742
|
-
stemmers: async () => stems.savedStemmers(database),
|
|
743
|
-
saveStemmers: async (stemmers) => write(database, () => stems.saveStoreStemmers(database, stemmers, context.now())),
|
|
744
|
-
accountGroups: async () => accountGroupsOf(database),
|
|
745
|
-
profiles: async () => profilesOf(database),
|
|
746
|
-
saveProfile: async (app, profile, key) => write(database, () => saveProfile(database, app, profile, key, context.now())),
|
|
747
|
-
saveAccountGroup: async (name, members) => write(database, () => {
|
|
748
|
-
const groups = accountGroupsOf(database);
|
|
749
|
-
if (members === undefined)
|
|
750
|
-
delete groups[name];
|
|
751
|
-
else
|
|
752
|
-
groups[name] = members;
|
|
753
|
-
database
|
|
754
|
-
.prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
|
|
755
|
-
.run(ACCOUNT_GROUPS, JSON.stringify(groups), context.now());
|
|
756
|
-
}),
|
|
757
|
-
contacts: async (key, options) => {
|
|
758
|
-
const accountKey = findAccountPk(key);
|
|
759
|
-
if (accountKey === undefined)
|
|
760
|
-
return { items: [], hasMore: false };
|
|
761
|
-
return identities.contacts(context, accountKey, key, options);
|
|
762
|
-
},
|
|
763
|
-
countContacts: async (key, filter = {}) => {
|
|
764
|
-
const accountKey = findAccountPk(key);
|
|
765
|
-
return accountKey === undefined ? 0 : identities.countContacts(context, accountKey, key, filter);
|
|
766
|
-
},
|
|
767
|
-
refreshRecency: async (key) => {
|
|
768
|
-
const accountKey = findAccountPk(key);
|
|
769
|
-
if (accountKey !== undefined)
|
|
770
|
-
identities.refreshRecency(context, accountKey);
|
|
771
|
-
},
|
|
772
|
-
savePeople: async (key, people) => write(database, () => {
|
|
773
|
-
const accountKey = accountPk(key);
|
|
774
|
-
for (const person of people)
|
|
775
|
-
identityPk(accountKey, key.provider, person.id, person.name, person);
|
|
776
|
-
}),
|
|
777
|
-
people: async (provider, options = {}) => identities.people(context, provider, options),
|
|
778
|
-
counterTargets: async (execution, options) => counterTargets(context, execution, options),
|
|
779
|
-
counterStates: async (key, chatId, messageId, options) => {
|
|
780
|
-
const row = database
|
|
781
|
-
.prepare("SELECT m.id AS pk FROM messages m JOIN chats c ON c.id=m.chat_id JOIN accounts ac ON ac.id=m.account_id WHERE ac.provider=? AND ac.external_id=? AND c.external_id=? AND m.external_id=? AND m.deleted_at IS NULL")
|
|
782
|
-
.get(key.provider, key.account, chatId, messageId);
|
|
783
|
-
return row ? counterStates(context, Number(row.pk), options.now, options.maxAge) : [];
|
|
784
|
-
},
|
|
785
|
-
updateCounterObservations: async (key, chatId, messageId, observations) => {
|
|
786
|
-
let updated = 0;
|
|
787
|
-
write(database, () => {
|
|
788
|
-
const row = database
|
|
789
|
-
.prepare("SELECT m.id AS pk FROM messages m JOIN chats c ON c.id=m.chat_id JOIN accounts ac ON ac.id=m.account_id WHERE ac.provider=? AND ac.external_id=? AND c.external_id=? AND m.external_id=? AND m.deleted_at IS NULL")
|
|
790
|
-
.get(key.provider, key.account, chatId, messageId);
|
|
791
|
-
if (row)
|
|
792
|
-
updated = applyCounterObservations(context, Number(row.pk), observations);
|
|
793
|
-
});
|
|
794
|
-
return updated;
|
|
795
|
-
},
|
|
796
|
-
saveReactions: async (key, chatId, messageId, reactions, options = {}) => {
|
|
797
|
-
const accountKey = findAccountPk(key);
|
|
798
|
-
const chatKey = accountKey === undefined ? undefined : findChatPk(accountKey, chatId);
|
|
799
|
-
if (chatKey === undefined)
|
|
800
|
-
return false;
|
|
801
|
-
let saved = false;
|
|
802
|
-
write(database, () => {
|
|
803
|
-
saved = messageWrites.saveReactions(context, chatKey, messageId, reactions);
|
|
804
|
-
const row = database
|
|
805
|
-
.prepare("SELECT id AS pk FROM messages WHERE chat_id=? AND external_id=? AND deleted_at IS NULL")
|
|
806
|
-
.get(chatKey, messageId);
|
|
807
|
-
if (row && options.observation)
|
|
808
|
-
applyCounterObservations(context, Number(row.pk), { reactions: options.observation });
|
|
809
|
-
});
|
|
810
|
-
return saved;
|
|
126
|
+
get accounts() {
|
|
127
|
+
return areas.accounts().whole;
|
|
811
128
|
},
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
write(database, () => {
|
|
815
|
-
merged = ranges.markRange(context, chatPkFor(accountPk(key), chatId), from, to);
|
|
816
|
-
});
|
|
817
|
-
return merged;
|
|
129
|
+
get chats() {
|
|
130
|
+
return areas.chats().whole;
|
|
818
131
|
},
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
return accountKey === undefined ? [] : reads.senderStats(context, accountKey, key.provider, senderId);
|
|
132
|
+
get sync() {
|
|
133
|
+
return areas.sync().whole;
|
|
822
134
|
},
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
return accountKey === undefined ? [] : identities.namesOf(context, accountKey, key.provider, personId);
|
|
135
|
+
get messages() {
|
|
136
|
+
return areas.messages().whole;
|
|
826
137
|
},
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
return accountKey === undefined ? [] : reads.chatStats(context, accountKey, chatId);
|
|
138
|
+
get attachments() {
|
|
139
|
+
return areas.attachments().whole;
|
|
830
140
|
},
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
return accountKey === undefined
|
|
834
|
-
? { chats: [], storedAt: null }
|
|
835
|
-
: reads.chatActivity(context, accountKey, since, where);
|
|
141
|
+
get roster() {
|
|
142
|
+
return areas.roster().whole;
|
|
836
143
|
},
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
const chatKey = accountKey === undefined ? undefined : findChatPk(accountKey, chatId);
|
|
840
|
-
return chatKey === undefined ? [] : ranges.ranges(context, chatKey);
|
|
144
|
+
get people() {
|
|
145
|
+
return areas.people().whole;
|
|
841
146
|
},
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
replaceAutoTags: async (key, chatId, algorithm, matches) => write(database, () => metadataQueries.replaceAutoTags(context, key, chatId, algorithm, matches)),
|
|
845
|
-
privateContact: async (key, person) => privatePeople.privateContact(context, key, person),
|
|
846
|
-
setContactAlias: async (key, person, alias) => {
|
|
847
|
-
return write(database, () => privatePeople.setAlias(context, key, person, alias));
|
|
147
|
+
get conversations() {
|
|
148
|
+
return areas.conversations().whole;
|
|
848
149
|
},
|
|
849
|
-
|
|
850
|
-
return
|
|
150
|
+
get vectors() {
|
|
151
|
+
return areas.vectors().whole;
|
|
851
152
|
},
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
return write(database, () => privatePeople.editNote(context, key, person, id, text, revision));
|
|
153
|
+
get counters() {
|
|
154
|
+
return areas.counters().whole;
|
|
855
155
|
},
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
let added = [];
|
|
859
|
-
write(database, () => {
|
|
860
|
-
added = tagQueries.addTags(context, tagQueries.targetThing(context, key, target), list);
|
|
861
|
-
});
|
|
862
|
-
return added;
|
|
156
|
+
get tags() {
|
|
157
|
+
return areas.tags().whole;
|
|
863
158
|
},
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
write(database, () => {
|
|
867
|
-
removed = tagQueries.removeTags(context, tagQueries.targetThing(context, key, target), list, source);
|
|
868
|
-
});
|
|
869
|
-
return removed;
|
|
159
|
+
get mentions() {
|
|
160
|
+
return areas.mentions().whole;
|
|
870
161
|
},
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
saveSearch: async (name, search, { replace = false } = {}) => {
|
|
874
|
-
return write(database, () => searchRecords.saveSearch(context, name, search, replace));
|
|
162
|
+
get searches() {
|
|
163
|
+
return searches();
|
|
875
164
|
},
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
searchHistory: async (limit, offset) => searchRecords.searchHistory(context, limit, offset),
|
|
879
|
-
deleteSearch: async (reference) => {
|
|
880
|
-
return write(database, () => searchRecords.deleteSearch(context, reference));
|
|
165
|
+
get queries() {
|
|
166
|
+
return queries();
|
|
881
167
|
},
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
write(database, () => {
|
|
885
|
-
cleared = searchRecords.clearHistory(context);
|
|
886
|
-
});
|
|
887
|
-
return cleared;
|
|
168
|
+
get searchIndex() {
|
|
169
|
+
return searchIndex();
|
|
888
170
|
},
|
|
889
|
-
// Built on first use: an area that prepares its statements must not stop the store opening for the rest.
|
|
890
171
|
get botUpdates() {
|
|
891
|
-
botUpdates
|
|
892
|
-
return botUpdates;
|
|
172
|
+
return botUpdates();
|
|
893
173
|
},
|
|
894
174
|
get involvements() {
|
|
895
|
-
involvements
|
|
896
|
-
return involvements;
|
|
175
|
+
return involvements();
|
|
897
176
|
},
|
|
898
177
|
get tasks() {
|
|
899
|
-
tasks
|
|
900
|
-
return tasks;
|
|
178
|
+
return tasks();
|
|
901
179
|
},
|
|
902
180
|
get sourceMentions() {
|
|
903
|
-
sourceMentions
|
|
904
|
-
return sourceMentions;
|
|
181
|
+
return sourceMentions();
|
|
905
182
|
},
|
|
906
183
|
get knowledge() {
|
|
907
|
-
knowledge
|
|
908
|
-
return knowledge;
|
|
184
|
+
return knowledge();
|
|
909
185
|
},
|
|
910
186
|
get notes() {
|
|
911
|
-
notes
|
|
912
|
-
return notes;
|
|
187
|
+
return notes();
|
|
913
188
|
},
|
|
914
189
|
get catalog() {
|
|
915
|
-
catalog
|
|
916
|
-
return catalog;
|
|
190
|
+
return catalog();
|
|
917
191
|
},
|
|
918
192
|
get facts() {
|
|
919
|
-
facts
|
|
920
|
-
return facts;
|
|
193
|
+
return facts();
|
|
921
194
|
},
|
|
922
195
|
get memories() {
|
|
923
|
-
memories
|
|
924
|
-
return memories;
|
|
196
|
+
return memories();
|
|
925
197
|
},
|
|
926
198
|
get proposedActions() {
|
|
927
|
-
proposedActions
|
|
928
|
-
return proposedActions;
|
|
199
|
+
return proposedActions();
|
|
929
200
|
},
|
|
930
201
|
get agentActions() {
|
|
931
|
-
agentActions
|
|
932
|
-
return agentActions;
|
|
202
|
+
return agentActions();
|
|
933
203
|
},
|
|
934
204
|
get meetings() {
|
|
935
|
-
meetings
|
|
936
|
-
return meetings;
|
|
205
|
+
return meetings();
|
|
937
206
|
},
|
|
938
207
|
get mail() {
|
|
939
|
-
return
|
|
208
|
+
return mail();
|
|
940
209
|
},
|
|
941
|
-
forAccount: (key) => bindAccount(store, key, {
|
|
942
|
-
accountPk: () => findAccountPk(key),
|
|
210
|
+
forAccount: (key) => bindAccount(store, key, areas, {
|
|
211
|
+
accountPk: () => accounts.findAccountPk(context, key),
|
|
943
212
|
attachmentAccount: (attachmentPk) => attachmentTexts.accountOf(context, attachmentPk),
|
|
944
213
|
}),
|
|
945
214
|
close: async () => database.close(),
|