@wirecat/cli-core 0.648.0 → 0.650.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/dist/analysis/anthropic.js +2 -1
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/account-remove.d.ts +2 -0
- package/dist/cli/account-remove.js +46 -10
- package/dist/cli/messenger/messages-search-command.js +6 -1
- package/dist/cli/messenger/search-answers.d.ts +3 -1
- package/dist/cli/messenger/search-answers.js +3 -1
- package/dist/cli/steps.js +9 -0
- package/dist/cli/unknown-profile.js +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +14 -0
- package/dist/crm/cli/index.js +30 -5
- package/dist/crm/source.d.ts +8 -1
- package/dist/crm/stage-tasks.d.ts +3 -1
- package/dist/crm/stage-tasks.js +8 -4
- package/dist/crm/sync.d.ts +1 -1
- package/dist/crm/sync.js +54 -0
- package/dist/domain/crm.d.ts +15 -0
- package/dist/domain/phones.d.ts +2 -0
- package/dist/domain/phones.js +3 -0
- package/dist/domain/providers.d.ts +4 -1
- package/dist/domain/providers.js +9 -2
- package/dist/domain/record-types.d.ts +24 -3
- package/dist/domain/record-types.js +23 -2
- package/dist/domain/records-table.js +4 -3
- package/dist/domain/records.d.ts +1 -1
- package/dist/domain/records.js +3 -2
- package/dist/entities/contact-context.d.ts +6 -0
- package/dist/entities/contact-context.js +3 -0
- package/dist/entities/deal.d.ts +4 -0
- package/dist/entities/deal.js +3 -0
- package/dist/entities/index.d.ts +12 -0
- package/dist/entities/recorded-meeting.d.ts +17 -0
- package/dist/entities/recorded-meeting.js +15 -0
- package/dist/errors/reasons.js +3 -4
- package/dist/index.d.ts +1 -1
- package/dist/meetings/answers.d.ts +5 -0
- package/dist/meetings/answers.js +3 -0
- package/dist/meetings/index.d.ts +1 -1
- package/dist/meetings/participant-search.d.ts +5 -0
- package/dist/meetings/pull.js +2 -1
- package/dist/meetings/read-answers.d.ts +4 -0
- package/dist/meetings/read-answers.js +1 -0
- package/dist/meetings/source.d.ts +5 -0
- package/dist/meetings/store.d.ts +10 -1
- package/dist/models/ai.js +2 -2
- package/dist/models/endpoint.d.ts +7 -0
- package/dist/models/endpoint.js +10 -0
- package/dist/models/index.js +2 -2
- package/dist/oauth/keeper.js +1 -1
- package/dist/sends/guard.js +8 -6
- package/dist/services/communications.d.ts +2 -2
- package/dist/services/communications.js +24 -2
- package/dist/services/document-source.js +9 -1
- package/dist/services/meeting-model.js +2 -1
- package/dist/services/notes-search.d.ts +10 -5
- package/dist/services/notes-search.js +19 -7
- package/dist/services/person-context.d.ts +3 -0
- package/dist/services/person-context.js +9 -1
- package/dist/services/person-meetings.d.ts +36 -0
- package/dist/services/person-meetings.js +57 -0
- package/dist/services/search-all.js +18 -10
- package/dist/speech/openai.js +5 -2
- package/dist/store/sqlite/added-sources.d.ts +38 -0
- package/dist/store/sqlite/added-sources.js +80 -50
- package/dist/store/sqlite/crm-settings.d.ts +5 -1
- package/dist/store/sqlite/crm-settings.js +8 -0
- package/dist/store/sqlite/crm-stage-entries.d.ts +15 -0
- package/dist/store/sqlite/crm-stage-entries.js +74 -0
- package/dist/store/sqlite/crm.d.ts +8 -1
- package/dist/store/sqlite/crm.js +7 -1
- package/dist/store/sqlite/identities.js +3 -1
- package/dist/store/sqlite/involvements.d.ts +2 -0
- package/dist/store/sqlite/involvements.js +4 -1
- package/dist/store/sqlite/meeting-participant-search.js +9 -3
- package/dist/store/sqlite/meetings.js +7 -2
- package/dist/store/sqlite/person-match-scan.js +39 -15
- package/dist/store/sqlite/record-projectors-document.d.ts +12 -0
- package/dist/store/sqlite/record-projectors-document.js +81 -0
- package/dist/store/sqlite/record-projectors.js +2 -0
- package/dist/update/index.d.ts +1 -1
- package/dist/update/index.js +4 -2
- package/package.json +1 -1
- package/schemas/records-envelope.v1.schema.json +57 -2
package/dist/models/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { endpoint, modelAddressAllowed, PLAIN_HTTP_REFUSED } from "./endpoint.js";
|
|
2
|
+
import { endpoint, endpointFetch, modelAddressAllowed, PLAIN_HTTP_REFUSED } from "./endpoint.js";
|
|
3
3
|
import { refuseOffComputer } from "./local-only.js";
|
|
4
4
|
import { openai } from "./openai.js";
|
|
5
5
|
import { EmptyAnswer, validateImages, } from "./types.js";
|
|
@@ -42,7 +42,7 @@ export const modelGateway = (deps) => ({
|
|
|
42
42
|
const apiKey = await deps.key?.(target.provider, target);
|
|
43
43
|
if (deps.signal?.aborted)
|
|
44
44
|
throw new CliError("cancelled", "model request cancelled");
|
|
45
|
-
const fetcher = deps.fetch ??
|
|
45
|
+
const fetcher = deps.fetch ?? endpointFetch(baseUrl, 120_000);
|
|
46
46
|
let limited = false;
|
|
47
47
|
let unreachable = false;
|
|
48
48
|
let refused = false;
|
package/dist/oauth/keeper.js
CHANGED
|
@@ -31,7 +31,7 @@ export const tokenKeeper = (options) => {
|
|
|
31
31
|
});
|
|
32
32
|
const exchange = (params, ctx) => provider.exchange ? provider.exchange(params, ctx) : requestTokens(provider, params, ctx);
|
|
33
33
|
const notSignedIn = () => new CliError("authentication_error", `not signed in to ${provider.name}; run ${options.signInCommand}`, {
|
|
34
|
-
reason: "
|
|
34
|
+
reason: "session.missing",
|
|
35
35
|
});
|
|
36
36
|
const busy = (error) => isCliError(error) && error.details.reason === "file.locked";
|
|
37
37
|
const acquire = async () => {
|
package/dist/sends/guard.js
CHANGED
|
@@ -8,9 +8,9 @@ import { RecipientList, recipientsPathFor } from "./recipients.js";
|
|
|
8
8
|
const HOUR_MS = 60 * 60 * 1000;
|
|
9
9
|
/**
|
|
10
10
|
* Asked of the guard for their permission level, yet they only read from the messenger or work here: reads go on
|
|
11
|
-
* during a hold.
|
|
11
|
+
* during a hold and under the read-only lock, which promises reads and syncs.
|
|
12
12
|
*/
|
|
13
|
-
const
|
|
13
|
+
const READS = new Set([
|
|
14
14
|
"attachments.extract",
|
|
15
15
|
"conversations.embeddings",
|
|
16
16
|
"conversations.links",
|
|
@@ -67,13 +67,15 @@ export const sendGuard = ({ profile, recipients, command = recipients.command, r
|
|
|
67
67
|
const currentPermissions = () => (typeof permissions === "function" ? permissions() : permissions);
|
|
68
68
|
let reservation;
|
|
69
69
|
const answered = new WeakSet();
|
|
70
|
-
const refuseReadOnly = () => {
|
|
70
|
+
const refuseReadOnly = ({ key }) => {
|
|
71
|
+
if (key !== undefined && READS.has(key))
|
|
72
|
+
return;
|
|
71
73
|
if (readOnlyLock)
|
|
72
74
|
throw readOnlyRefusal(readOnlyLock, MESSENGER_CHANGE_REFUSAL);
|
|
73
75
|
};
|
|
74
76
|
// Every write, counted or not: a reaction or a read receipt sent through a ban is what makes the ban stick.
|
|
75
77
|
const refuseHeld = ({ key }) => {
|
|
76
|
-
if (key !== undefined &&
|
|
78
|
+
if (key !== undefined && READS.has(key))
|
|
77
79
|
return;
|
|
78
80
|
const block = flood?.sendBlock();
|
|
79
81
|
if (!block)
|
|
@@ -84,7 +86,7 @@ export const sendGuard = ({ profile, recipients, command = recipients.command, r
|
|
|
84
86
|
};
|
|
85
87
|
const permitted = (request) => {
|
|
86
88
|
const { chatId, kind = "message", action, personIds } = request;
|
|
87
|
-
refuseReadOnly();
|
|
89
|
+
refuseReadOnly(request);
|
|
88
90
|
const levels = currentPermissions();
|
|
89
91
|
if (levels !== undefined) {
|
|
90
92
|
const key = request.key ?? keyForWrite(kind, action);
|
|
@@ -201,7 +203,7 @@ export const sendGuard = ({ profile, recipients, command = recipients.command, r
|
|
|
201
203
|
};
|
|
202
204
|
return {
|
|
203
205
|
ask: async (request) => {
|
|
204
|
-
refuseReadOnly();
|
|
206
|
+
refuseReadOnly(request);
|
|
205
207
|
const levels = currentPermissions();
|
|
206
208
|
if (levels === undefined)
|
|
207
209
|
return;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AccountKey, LinkedIdentity, MessageStore, PersonRecord, StoredAccount } from "../store/store.js";
|
|
2
2
|
import { type Coverage, type Scope } from "./business-context.js";
|
|
3
|
-
/** A one-to-one chat, a mail
|
|
3
|
+
/** A one-to-one chat, a mail, a calendar event or a recorded meeting or call with some of the people asked about. */
|
|
4
4
|
export interface Touch {
|
|
5
5
|
kind: "message" | "mail" | "meeting";
|
|
6
|
-
/** A message's or mail's locator, an `event:<id>`. */
|
|
6
|
+
/** A message's or mail's locator, an `event:<id>`, or a recorded meeting's `meeting:<account>/<id>`. */
|
|
7
7
|
ref: string;
|
|
8
8
|
/** The chat's title, the mail's subject, the event's title. */
|
|
9
9
|
title: string | null;
|
|
@@ -2,9 +2,12 @@ import { formatLocator } from "../domain/locator.js";
|
|
|
2
2
|
import { kindIn } from "../domain/providers.js";
|
|
3
3
|
import { keyOf, newestFirst } from "./business-context.js";
|
|
4
4
|
import { eventsOnce } from "./person-context.js";
|
|
5
|
+
import { personMeetings } from "./person-meetings.js";
|
|
5
6
|
/** Mail read per address when counting: past it the count says `hasMore`. */
|
|
6
7
|
const MAIL_ROWS = 500;
|
|
7
8
|
const EVENT_ROWS = 1000;
|
|
9
|
+
/** Recorded meetings and calls listed: past it the count still counts each, and the read says `hasMore`. */
|
|
10
|
+
const RECORDED_ROWS = 100;
|
|
8
11
|
/** The stored accounts that hold a calendar: what a person's events are read from. */
|
|
9
12
|
export const calendarsOf = async (store, stored) => {
|
|
10
13
|
const held = [];
|
|
@@ -45,6 +48,7 @@ export const communicationsOf = async (store, asked, scope, { since, until, limi
|
|
|
45
48
|
const messages = new Map();
|
|
46
49
|
const mail = new Map();
|
|
47
50
|
const meetings = new Map();
|
|
51
|
+
const recordedTouches = [];
|
|
48
52
|
let messageCount = 0;
|
|
49
53
|
let cut = false;
|
|
50
54
|
const sinceIso = since === undefined ? undefined : new Date(since).toISOString();
|
|
@@ -131,9 +135,27 @@ export const communicationsOf = async (store, asked, scope, { since, until, limi
|
|
|
131
135
|
}
|
|
132
136
|
for (const key of calendars)
|
|
133
137
|
read.add(keyOf(key));
|
|
138
|
+
const recorded = await personMeetings(store, people.map(({ uid }) => uid), stored.filter((one) => scope.has(one)), { limit: RECORDED_ROWS, ...(since === undefined ? {} : { since }), ...(until === undefined ? {} : { until }) });
|
|
139
|
+
cut ||= recorded.hasMore;
|
|
140
|
+
let held = 0;
|
|
141
|
+
for (const meeting of recorded.items) {
|
|
142
|
+
read.add(keyOf(meeting.account));
|
|
143
|
+
const event = meeting.event === null ? undefined : Number(meeting.event.slice("event:".length));
|
|
144
|
+
if (event !== undefined && meetings.has(event)) {
|
|
145
|
+
held++;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
recordedTouches.push({
|
|
149
|
+
kind: "meeting",
|
|
150
|
+
ref: meeting.ref,
|
|
151
|
+
title: meeting.title,
|
|
152
|
+
at: meeting.startedAt,
|
|
153
|
+
people: meeting.people,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
134
156
|
return {
|
|
135
|
-
counts: { messages: messageCount, mail: mail.size, meetings: meetings.size },
|
|
136
|
-
items: [...messages.values(), ...mail.values(), ...meetings.values()].sort(newestFirst),
|
|
157
|
+
counts: { messages: messageCount, mail: mail.size, meetings: meetings.size + recorded.total - held },
|
|
158
|
+
items: [...messages.values(), ...mail.values(), ...meetings.values(), ...recordedTouches].sort(newestFirst),
|
|
137
159
|
hasMore: cut,
|
|
138
160
|
coverage: coverageOf(people, read, calendars.length > 0),
|
|
139
161
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFolderProvider, kindIn } from "../domain/providers.js";
|
|
1
|
+
import { isFolderProvider, isImportedProvider, kindIn } from "../domain/providers.js";
|
|
2
2
|
/**
|
|
3
3
|
* Where a hit came from. The document's preferred file says it: its account's provider and its link.
|
|
4
4
|
* A Drive document under a notes folder (before version 31 moves it) is still known by its front matter.
|
|
@@ -7,6 +7,14 @@ import { isFolderProvider, kindIn } from "../domain/providers.js";
|
|
|
7
7
|
export const documentSource = (note, accounts, profiles, file) => {
|
|
8
8
|
const metadata = note.frontMatter;
|
|
9
9
|
const account = accounts.find(({ id }) => String(id) === note.folderId);
|
|
10
|
+
// An import's document stays in its source's account, beside that source's calls and SMS.
|
|
11
|
+
if (note.source === "file" && account !== undefined && isImportedProvider(account.provider))
|
|
12
|
+
return {
|
|
13
|
+
kind: "document",
|
|
14
|
+
provider: account.provider,
|
|
15
|
+
account: account.account,
|
|
16
|
+
...(file?.url ? { url: file.url } : {}),
|
|
17
|
+
};
|
|
10
18
|
const remote = note.source === "file" &&
|
|
11
19
|
((account !== undefined && kindIn(account.provider) === "documents") || metadata?.source === "google-drive");
|
|
12
20
|
const profile = remote && account
|
|
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { isTextModelInstalled, openEmbedder, textModelsDirectory, } from "../embeddings/embed.js";
|
|
3
3
|
import { textModel, vectorModelKey } from "../embeddings/models.js";
|
|
4
4
|
import { OPENAI_URL, openRemote, remoteKey, remoteModel } from "../embeddings/remote.js";
|
|
5
|
+
import { endpointFetch } from "../models/endpoint.js";
|
|
5
6
|
const integer = (value, name, max) => {
|
|
6
7
|
if (!Number.isSafeInteger(value) || value < 1 || value > max)
|
|
7
8
|
throw new CliError("validation_error", `Invalid ${name}`);
|
|
@@ -128,7 +129,7 @@ export const openMeetingEmbedder = async (choice, options = {}) => {
|
|
|
128
129
|
const key = choice.apiKey ?? (remote.provider === "openai" ? (options.env ?? process.env).OPENAI_API_KEY : undefined);
|
|
129
130
|
if (remote.provider === "openai" && !key)
|
|
130
131
|
throw new CliError("authentication_error", "The explicit remote embedding model requires an API key");
|
|
131
|
-
const post = options.fetch ??
|
|
132
|
+
const post = options.fetch ?? endpointFetch(remote.baseUrl, 120_000);
|
|
132
133
|
const guarded = async (url, init) => {
|
|
133
134
|
try {
|
|
134
135
|
cancelled(signal);
|
|
@@ -9,7 +9,7 @@ import { type ResolvedNode } from "../search/lucene/resolved.js";
|
|
|
9
9
|
import { type Stemmer } from "../search/stem.js";
|
|
10
10
|
import { type SearchTotal } from "../search/total.js";
|
|
11
11
|
import type { Link, NearestNote, Note, NoteHit } from "../store/index.js";
|
|
12
|
-
import type { AccountKey, MessageStore } from "../store/store.js";
|
|
12
|
+
import type { AccountKey, MessageStore, StoredAccount } from "../store/store.js";
|
|
13
13
|
import { type EnrichOptions, type EnrichRun } from "./enrichment.js";
|
|
14
14
|
export interface NotesSearchRequest {
|
|
15
15
|
text: string;
|
|
@@ -203,13 +203,18 @@ export declare const RANK_WITHIN = 2000;
|
|
|
203
203
|
* of `filter` holds for every hit, found by words or by meaning; a query of fields alone is not searched by meaning.
|
|
204
204
|
*/
|
|
205
205
|
export declare const searchNotes: (store: MessageStore, query: string, { limit, offset, tag, filter: expression, folderIds, withInternal, source: given, exact, discover, timezone, env, command, embedders, pictures: withPictures, pictureLimit, pictureEmbedder, }?: NotesQuery) => Promise<NotesFound>;
|
|
206
|
-
/**
|
|
207
|
-
|
|
206
|
+
/**
|
|
207
|
+
* What `notes:internal`, `notes:<folder id>` and an import's own account (`phone:office-pbx`) ask of the store: one
|
|
208
|
+
* query, so a page of it is one page. `stored` gives an import's account its store id.
|
|
209
|
+
*/
|
|
210
|
+
export declare const notesScopeOf: (accounts: readonly AccountKey[], stored?: readonly StoredAccount[]) => Pick<NotesQuery, "folderIds" | "withInternal" | "source">;
|
|
211
|
+
/** The accounts of import-only providers: their documents stay under their own key, `phone:office-pbx`. */
|
|
212
|
+
export declare const importAccounts: (store: MessageStore) => Promise<StoredAccount[]>;
|
|
208
213
|
export interface NotesFoundOf extends NotesFound {
|
|
209
|
-
/** Every notes account read: `internal
|
|
214
|
+
/** Every notes account read: `internal`, each folder's id, and each import's account by its own key. */
|
|
210
215
|
accounts: {
|
|
211
216
|
resource: "notes";
|
|
212
|
-
provider:
|
|
217
|
+
provider: string;
|
|
213
218
|
account: string;
|
|
214
219
|
}[];
|
|
215
220
|
/** A `--source` entry naming nothing `search notes` reads. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { dateRange, parseLucene, timezoneOf } from "@wirecat/cli-base/query";
|
|
3
|
-
import { INTERNAL_NOTES } from "../domain/providers.js";
|
|
3
|
+
import { INTERNAL_NOTES, isImportedProvider } from "../domain/providers.js";
|
|
4
4
|
import { normalizeTag } from "../domain/tags.js";
|
|
5
5
|
import { defaultThreads, isTextModelInstalled, openEmbedder, textModelsDirectory, } from "../embeddings/embed.js";
|
|
6
6
|
import { chosenTextModel, meaningFloor, textModel, vectorModelKey } from "../embeddings/models.js";
|
|
@@ -551,13 +551,22 @@ export const searchNotes = async (store, query, { limit = 20, offset = 0, tag, f
|
|
|
551
551
|
...lane,
|
|
552
552
|
};
|
|
553
553
|
};
|
|
554
|
-
/**
|
|
555
|
-
|
|
556
|
-
|
|
554
|
+
/**
|
|
555
|
+
* What `notes:internal`, `notes:<folder id>` and an import's own account (`phone:office-pbx`) ask of the store: one
|
|
556
|
+
* query, so a page of it is one page. `stored` gives an import's account its store id.
|
|
557
|
+
*/
|
|
558
|
+
export const notesScopeOf = (accounts, stored = []) => {
|
|
559
|
+
const folderIds = accounts
|
|
560
|
+
.filter(({ provider, account }) => provider !== "notes" || account !== INTERNAL_NOTES)
|
|
561
|
+
.map(({ provider, account }) => provider === "notes"
|
|
562
|
+
? account
|
|
563
|
+
: String(stored.find((one) => one.provider === provider && one.account === account)?.id ?? 0));
|
|
557
564
|
if (!folderIds.length)
|
|
558
565
|
return { source: "internal" };
|
|
559
566
|
return { folderIds, ...(accounts.length > folderIds.length ? { withInternal: true } : {}) };
|
|
560
567
|
};
|
|
568
|
+
/** The accounts of import-only providers: their documents stay under their own key, `phone:office-pbx`. */
|
|
569
|
+
export const importAccounts = async (store) => (await store.accounts.storedAccounts()).filter(({ provider }) => isImportedProvider(provider));
|
|
561
570
|
/**
|
|
562
571
|
* `search notes` with `--source`: the notes accounts the list names — `notes:internal`, `notes:<folder id>`, `notes`
|
|
563
572
|
* — and every entry naming none of them in `skipped`. Without a list, every notes account `type` leaves in.
|
|
@@ -571,6 +580,7 @@ export const searchNotesOf = async (store, account, text, { accounts: list, app,
|
|
|
571
580
|
...(await store.notes.folders()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
572
581
|
...(await store.notes.documentsAccounts()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
573
582
|
...[await store.notes.addedAccount()].flatMap((added) => (added ? [{ provider: "notes", account: added.id }] : [])),
|
|
583
|
+
...(await importAccounts(store)).map(({ provider, account }) => ({ provider, account })),
|
|
574
584
|
];
|
|
575
585
|
const lock = groupLockOf(app, env);
|
|
576
586
|
const typedScope = list ?? (lock === undefined ? undefined : `group:${lock}`);
|
|
@@ -582,22 +592,24 @@ export const searchNotesOf = async (store, account, text, { accounts: list, app,
|
|
|
582
592
|
? { accounts: held, skipped: [] }
|
|
583
593
|
: fitting(entriesOfList(notesScope, await listContextOf(store, account, app, undefined, env)), ["notes", "documents"], what);
|
|
584
594
|
const source = query.source ?? noteSourceOfQuery(text).source;
|
|
585
|
-
const
|
|
595
|
+
const internal = ({ provider, account }) => provider === "notes" && account === INTERNAL_NOTES;
|
|
596
|
+
const typed = named.accounts.filter((one) => source === undefined || internal(one) === (source === "internal"));
|
|
586
597
|
if (!typed.length && list !== undefined)
|
|
587
598
|
throw new CliError("validation_error", source === "internal"
|
|
588
599
|
? "the query's source:internal keeps the notes written in memo, and the --source list names none of them: " +
|
|
589
600
|
"add notes:internal to --source, or drop source:internal from the query"
|
|
590
601
|
: "the query's source:file keeps the files from notes folders, and the --source list names none of them: " +
|
|
591
602
|
"add notes:<folder id> to --source, or drop source:file from the query");
|
|
592
|
-
const scope = list === undefined ? {} : notesScopeOf(typed);
|
|
603
|
+
const scope = list === undefined ? {} : notesScopeOf(typed, await store.accounts.storedAccounts());
|
|
593
604
|
const found = await searchNotes(store, text, {
|
|
594
605
|
...query,
|
|
595
606
|
...scope,
|
|
596
607
|
...(source ? { source } : {}),
|
|
608
|
+
...(env === undefined ? {} : { env }),
|
|
597
609
|
});
|
|
598
610
|
return {
|
|
599
611
|
...found,
|
|
600
|
-
accounts: typed.map(({ account }) => ({ resource: "notes", provider
|
|
612
|
+
accounts: typed.map(({ provider, account }) => ({ resource: "notes", provider, account })),
|
|
601
613
|
skipped: named.skipped,
|
|
602
614
|
};
|
|
603
615
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChatKind, Id, Message, Provider } from "../domain/models.js";
|
|
2
2
|
import type { Event, EventFilter } from "../meetings/index.js";
|
|
3
3
|
import type { AccountKey, IdentityRef, LinkedIdentity, MessageStore, PersonRecord, StoredAccount } from "../store/store.js";
|
|
4
|
+
import { type PersonMeeting } from "./person-meetings.js";
|
|
4
5
|
export declare const CONTEXT_MESSAGES = 10;
|
|
5
6
|
export declare const CONTEXT_BYTES: number;
|
|
6
7
|
export interface ContextMessage {
|
|
@@ -65,6 +66,8 @@ export interface PersonContext {
|
|
|
65
66
|
upcoming: ContextEvent[];
|
|
66
67
|
recent: ContextEvent[];
|
|
67
68
|
};
|
|
69
|
+
/** Recorded meetings and calls they took part in, newest first, in the accounts read. */
|
|
70
|
+
meetings: PersonMeeting[];
|
|
68
71
|
limits: {
|
|
69
72
|
messages: number;
|
|
70
73
|
bytes: number;
|
|
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { formatLocator } from "../domain/locator.js";
|
|
3
3
|
import { pickPerson } from "../resolve.js";
|
|
4
4
|
import { messageOfEmail } from "../store/store.js";
|
|
5
|
+
import { personMeetings } from "./person-meetings.js";
|
|
5
6
|
export const CONTEXT_MESSAGES = 10;
|
|
6
7
|
export const CONTEXT_BYTES = 64 * 1024;
|
|
7
8
|
export const toContext = (key, message, chatTitle) => ({
|
|
@@ -212,6 +213,11 @@ export const recordContext = async (store, record, reads, readable, { messages =
|
|
|
212
213
|
? await eventsOnce(store, { personId, accountIds, to: now, newest: true, ...(since === undefined ? {} : { from: since }) }, messages)
|
|
213
214
|
: nothing;
|
|
214
215
|
cut ||= upcoming.cut || past.cut;
|
|
216
|
+
const recorded = await personMeetings(store, [record.uid], readable, {
|
|
217
|
+
limit: messages,
|
|
218
|
+
...(since === undefined ? {} : { since }),
|
|
219
|
+
});
|
|
220
|
+
cut ||= recorded.hasMore;
|
|
215
221
|
direct.sort(newestFirst);
|
|
216
222
|
const each = [...direct, ...beyond].sort(newestFirst);
|
|
217
223
|
theirs.sort(newestFirst);
|
|
@@ -229,7 +235,8 @@ export const recordContext = async (store, record, reads, readable, { messages =
|
|
|
229
235
|
const read = [
|
|
230
236
|
...reads.map(({ key, scope }) => ({ ...key, scope })),
|
|
231
237
|
...calendars.map(({ provider, account, scope }) => ({ provider, account, scope })),
|
|
232
|
-
|
|
238
|
+
...recorded.items.flatMap(({ account }) => readable.filter((one) => nameOf(one) === nameOf(account))),
|
|
239
|
+
].map(({ provider, account, scope }) => ({ provider, account, scope }));
|
|
233
240
|
const accounts = [...new Map(read.map((one) => [nameOf(one), one])).values()].sort((a, b) => nameOf(a).localeCompare(nameOf(b)));
|
|
234
241
|
return {
|
|
235
242
|
accounts,
|
|
@@ -245,6 +252,7 @@ export const recordContext = async (store, record, reads, readable, { messages =
|
|
|
245
252
|
upcoming: upcoming.items.map(contextEvent),
|
|
246
253
|
recent: past.items.filter(({ id }) => !upcomingIds.has(id)).map(contextEvent),
|
|
247
254
|
},
|
|
255
|
+
meetings: recorded.items,
|
|
248
256
|
limits: { messages, bytes },
|
|
249
257
|
hasMore: cut || kept.cut,
|
|
250
258
|
complete: notRead.length === 0,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MessageStore, StoredAccount } from "../store/store.js";
|
|
2
|
+
/** A recorded meeting or call some of the people took part in, as the meeting source stored it. */
|
|
3
|
+
export interface PersonMeeting {
|
|
4
|
+
/** `meeting:<account>/<meeting>`: `meetings show <meeting>` and `meetings transcript <meeting>` of `account` open it. */
|
|
5
|
+
ref: string;
|
|
6
|
+
/** The stored meeting id those commands take. */
|
|
7
|
+
meetingId: number;
|
|
8
|
+
/** The account that holds it: its tool's profile opens it. */
|
|
9
|
+
account: {
|
|
10
|
+
provider: string;
|
|
11
|
+
account: string;
|
|
12
|
+
};
|
|
13
|
+
title: string | null;
|
|
14
|
+
startedAt: string | null;
|
|
15
|
+
durationMs: number | null;
|
|
16
|
+
hasTranscript: boolean;
|
|
17
|
+
/** `event:<id>` of the calendar event it was held for, when the store knows it. */
|
|
18
|
+
event: string | null;
|
|
19
|
+
/** `person:<uid>` of each one asked about who took part. */
|
|
20
|
+
people: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The newest recorded meetings of these people in `accounts`, each once, newest first, and how many there are;
|
|
24
|
+
* `hasMore` when there are more than `limit`, or a person took part in more than `SCAN`. A meeting reaches
|
|
25
|
+
* a person through the identity it was saved under, and through every identity linked to them since, such as a
|
|
26
|
+
* call's number matched to a CRM contact.
|
|
27
|
+
*/
|
|
28
|
+
export declare const personMeetings: (store: Pick<MessageStore, "involvements" | "meetings">, people: readonly string[], accounts: readonly StoredAccount[], { limit, since, until }?: {
|
|
29
|
+
limit?: number;
|
|
30
|
+
since?: number;
|
|
31
|
+
until?: number;
|
|
32
|
+
}) => Promise<{
|
|
33
|
+
items: PersonMeeting[];
|
|
34
|
+
total: number;
|
|
35
|
+
hasMore: boolean;
|
|
36
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { formatMeetingReference } from "../meetings/index.js";
|
|
2
|
+
const SCAN = 1000;
|
|
3
|
+
/**
|
|
4
|
+
* The newest recorded meetings of these people in `accounts`, each once, newest first, and how many there are;
|
|
5
|
+
* `hasMore` when there are more than `limit`, or a person took part in more than `SCAN`. A meeting reaches
|
|
6
|
+
* a person through the identity it was saved under, and through every identity linked to them since, such as a
|
|
7
|
+
* call's number matched to a CRM contact.
|
|
8
|
+
*/
|
|
9
|
+
export const personMeetings = async (store, people, accounts, { limit = 10, since, until } = {}) => {
|
|
10
|
+
const byId = new Map(accounts.map((one) => [one.id, one]));
|
|
11
|
+
let cut = false;
|
|
12
|
+
const found = new Map();
|
|
13
|
+
for (const uid of people) {
|
|
14
|
+
const rows = store.involvements.forPerson(Number(uid), {
|
|
15
|
+
limit: SCAN,
|
|
16
|
+
subjectTypes: ["meeting"],
|
|
17
|
+
...(since === undefined ? {} : { since }),
|
|
18
|
+
...(until === undefined ? {} : { until }),
|
|
19
|
+
});
|
|
20
|
+
cut ||= rows.length === SCAN;
|
|
21
|
+
for (const row of rows) {
|
|
22
|
+
if (row.subjectType !== "meeting" || row.accountId === null || !byId.has(row.accountId))
|
|
23
|
+
continue;
|
|
24
|
+
const key = `${row.accountId}/${row.subjectId}`;
|
|
25
|
+
const held = found.get(key) ?? {
|
|
26
|
+
accountId: row.accountId,
|
|
27
|
+
meetingId: row.subjectId,
|
|
28
|
+
at: row.occurredAt,
|
|
29
|
+
people: [],
|
|
30
|
+
};
|
|
31
|
+
if (!held.people.includes(`person:${uid}`))
|
|
32
|
+
held.people.push(`person:${uid}`);
|
|
33
|
+
found.set(key, held);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const newest = [...found.values()].sort((a, b) => b.at - a.at || b.meetingId - a.meetingId);
|
|
37
|
+
const items = [];
|
|
38
|
+
for (const { accountId, meetingId, people: who } of newest.slice(0, limit)) {
|
|
39
|
+
const meeting = await store.meetings.meetingMetadata({ accountId, meetingId }).catch(() => undefined);
|
|
40
|
+
if (meeting === undefined || meeting.deletedAt !== null)
|
|
41
|
+
continue;
|
|
42
|
+
const transcripts = await store.meetings.transcripts({ accountId, meetingId, limit: 1 });
|
|
43
|
+
const account = byId.get(accountId);
|
|
44
|
+
items.push({
|
|
45
|
+
ref: formatMeetingReference({ type: "meeting", accountId, meetingId }),
|
|
46
|
+
meetingId,
|
|
47
|
+
account: { provider: account.provider, account: account.account },
|
|
48
|
+
title: meeting.title,
|
|
49
|
+
startedAt: meeting.startedAt === null ? null : new Date(meeting.startedAt).toISOString(),
|
|
50
|
+
durationMs: meeting.durationMs,
|
|
51
|
+
hasTranscript: transcripts.items.length > 0,
|
|
52
|
+
event: meeting.eventId === null ? null : `event:${meeting.eventId}`,
|
|
53
|
+
people: who,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return { items, total: newest.length, hasMore: cut || newest.length > limit };
|
|
57
|
+
};
|
|
@@ -15,7 +15,7 @@ import { calendarAccounts, searchEvents } from "./events-search.js";
|
|
|
15
15
|
import { excerpt } from "./excerpt.js";
|
|
16
16
|
import { MAX_SEARCH_OFFSET, searchStore } from "./messages-archive-search.js";
|
|
17
17
|
import { nearEligible } from "./messages-discovery.js";
|
|
18
|
-
import { notesScopeOf, RRF_K, searchNotes } from "./notes-search.js";
|
|
18
|
+
import { importAccounts, notesScopeOf, RRF_K, searchNotes } from "./notes-search.js";
|
|
19
19
|
import { BUSINESS_WORDS_ONLY, searchBusiness } from "./search-all-business.js";
|
|
20
20
|
import { meetingLane } from "./search-all-meetings.js";
|
|
21
21
|
import { HARDER_CANDIDATES, reorderHarder } from "./search-harder.js";
|
|
@@ -85,11 +85,16 @@ const sourceScope = async (store, account, source, asked, messenger) => {
|
|
|
85
85
|
? new Set((await store.business.accounts()).map(accountKeyOf))
|
|
86
86
|
: new Set();
|
|
87
87
|
const holdsBusiness = (one) => imported.has(accountKeyOf(one));
|
|
88
|
-
|
|
88
|
+
// An import's account holds documents under its own key, and the notes lane reads them.
|
|
89
|
+
const holdsDocuments = (one) => asked.includes("notes") && holdsKind(one.provider, "documents");
|
|
90
|
+
const { skipped } = fitting(entries, asked.filter((one) => one !== "business"), "search all", (kind) => `--only leaves ${kind} out`, (one) => holdsBusiness(one) || holdsDocuments(one));
|
|
91
|
+
const holds = (resource, one) => resource === "business"
|
|
92
|
+
? holdsBusiness(one)
|
|
93
|
+
: listedHolds(one, resource) || (resource === "notes" && holdsDocuments(one));
|
|
89
94
|
const named = (resource) => [
|
|
90
95
|
...new Map(entries
|
|
91
96
|
.flatMap(({ accounts }) => accounts)
|
|
92
|
-
.filter((one) => (resource
|
|
97
|
+
.filter((one) => holds(resource, one))
|
|
93
98
|
.map(({ provider, account }) => [`${provider}\u0000${account}`, { provider, account }])).values(),
|
|
94
99
|
];
|
|
95
100
|
const scope = Object.fromEntries(asked.map((resource) => [resource, named(resource)]));
|
|
@@ -243,7 +248,7 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
|
|
|
243
248
|
limit: depth,
|
|
244
249
|
command,
|
|
245
250
|
embedders,
|
|
246
|
-
...(chosen === undefined ? {} : notesScopeOf(chosen)),
|
|
251
|
+
...(chosen === undefined ? {} : notesScopeOf(chosen, await store.accounts.storedAccounts())),
|
|
247
252
|
...(request.exact ? { exact: true } : {}),
|
|
248
253
|
...(discover ? { discover: true } : {}),
|
|
249
254
|
...(request.timezone === undefined ? {} : { timezone: request.timezone }),
|
|
@@ -268,13 +273,16 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
|
|
|
268
273
|
text: hit.excerpt,
|
|
269
274
|
foundBy: hit.found_by,
|
|
270
275
|
})));
|
|
271
|
-
const read = chosen
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
const read = chosen ?? [
|
|
277
|
+
...[
|
|
278
|
+
INTERNAL_NOTES,
|
|
279
|
+
...(await store.notes.folders()).map(({ id }) => id),
|
|
280
|
+
...(await store.notes.documentsAccounts()).map(({ id }) => id),
|
|
281
|
+
...[await store.notes.addedAccount()].flatMap((added) => (added ? [added.id] : [])),
|
|
282
|
+
].map((account) => ({ provider: "notes", account })),
|
|
283
|
+
...(await importAccounts(store)).map(({ provider, account }) => ({ provider, account })),
|
|
276
284
|
];
|
|
277
|
-
accounts.push(...read.map((account) => ({ resource, provider
|
|
285
|
+
accounts.push(...read.map(({ provider, account }) => ({ resource, provider, account })));
|
|
278
286
|
}
|
|
279
287
|
else if (resource === "events") {
|
|
280
288
|
const read = scope?.events ?? (await calendarAccounts(store));
|
package/dist/speech/openai.js
CHANGED
|
@@ -2,6 +2,7 @@ import { setTimeout as wait } from "node:timers/promises";
|
|
|
2
2
|
import { backoffMs, CliError, DEFAULT_RETRY } from "@wirecat/cli-base";
|
|
3
3
|
import { providerWaitMs } from "@wirecat/cli-base/http";
|
|
4
4
|
import { OPENAI_URL } from "../embeddings/remote.js";
|
|
5
|
+
import { endpointFetch } from "../models/endpoint.js";
|
|
5
6
|
import { refuseModelAddress } from "../models/local-only.js";
|
|
6
7
|
import { filesPresent, modelsDirectory, vadPath } from "./install.js";
|
|
7
8
|
import { OPENAI_TRANSCRIBE_MODEL, VAD } from "./models.js";
|
|
@@ -67,13 +68,15 @@ const failureOf = async (response) => {
|
|
|
67
68
|
return {};
|
|
68
69
|
}
|
|
69
70
|
};
|
|
71
|
+
// A piece runs up to ten minutes of audio; the provider may take minutes to answer it.
|
|
72
|
+
const TRANSCRIPTION_TIMEOUT_MS = 600_000;
|
|
70
73
|
/** One file, one request. 429, 408 and server errors are tried again; the provider's `Retry-After` beats our backoff. */
|
|
71
74
|
const send = async (wav, options) => {
|
|
72
|
-
const
|
|
75
|
+
const url = `${(options.baseUrl ?? OPENAI_URL).replace(/\/+$/, "")}/audio/transcriptions`;
|
|
76
|
+
const post = options.fetch ?? endpointFetch(url, TRANSCRIPTION_TIMEOUT_MS);
|
|
73
77
|
const retry = options.retry ?? RETRY;
|
|
74
78
|
const sleep = options.sleep ?? sleeping;
|
|
75
79
|
const random = options.random ?? Math.random;
|
|
76
|
-
const url = `${(options.baseUrl ?? OPENAI_URL).replace(/\/+$/, "")}/audio/transcriptions`;
|
|
77
80
|
for (let attempt = 1;; attempt++) {
|
|
78
81
|
interrupted(options.signal);
|
|
79
82
|
let response;
|
|
@@ -97,6 +97,43 @@ export interface AddedSourceDetails {
|
|
|
97
97
|
/** Where the caller keeps the copy, when one was kept. */
|
|
98
98
|
copy: string | null;
|
|
99
99
|
}
|
|
100
|
+
type Row = Record<string, unknown>;
|
|
101
|
+
/** What a document's text and description write, whichever account holds it. */
|
|
102
|
+
export interface DocumentText {
|
|
103
|
+
kind: string;
|
|
104
|
+
title: string | null;
|
|
105
|
+
fileName: string | null;
|
|
106
|
+
extension: string | null;
|
|
107
|
+
url: string | null;
|
|
108
|
+
mime: string | null;
|
|
109
|
+
size: number | null;
|
|
110
|
+
/** `null` keeps it out of every match by content: an imported document is its source's, never a folder file's. */
|
|
111
|
+
hash: string | null;
|
|
112
|
+
text: string;
|
|
113
|
+
extraction: "text" | "none";
|
|
114
|
+
metadata: string | null;
|
|
115
|
+
language: string | null;
|
|
116
|
+
}
|
|
117
|
+
/** Where a copy of the file is kept, when one is: `text` keeps the text alone. */
|
|
118
|
+
export interface DocumentStorage {
|
|
119
|
+
storage: "text" | "copy";
|
|
120
|
+
localPath: string | null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The writes of a document in a given account: the added sources' (`added:owner`) and a records import's (the
|
|
124
|
+
* envelope's own account) go through the same columns.
|
|
125
|
+
*/
|
|
126
|
+
export declare const documentWritesOver: ({ database }: Pick<StoreContext, "database">) => {
|
|
127
|
+
insert: (accountId: number, externalId: string, document: DocumentText, kept: DocumentStorage, at: number) => number;
|
|
128
|
+
/** Its next revision, the text before kept; `revised: false` changes what describes it and keeps the revision. */
|
|
129
|
+
update: (row: Row, document: DocumentText, at: number, revised?: boolean) => void;
|
|
130
|
+
/** A removed document back, as written now. */
|
|
131
|
+
revive: (id: number, document: DocumentText, kept: DocumentStorage, at: number) => void;
|
|
132
|
+
/** Its `files` row, named as its source names it, not by a hash or a key. */
|
|
133
|
+
place: (id: number, at: number, name: string) => void;
|
|
134
|
+
/** Its text goes, its row stays as deleted: what a folder file's removal does. */
|
|
135
|
+
remove: (id: number, at: number) => void;
|
|
136
|
+
};
|
|
100
137
|
/**
|
|
101
138
|
* The key an added source is stored under: its source key, else `sha256:<hash>` (a file's bytes; pasted text or a page
|
|
102
139
|
* by its normalized text, or its address when it has none), and every hash a folder or Drive document of the same
|
|
@@ -108,3 +145,4 @@ export declare const addedSourceKeyOf: (content: AddedSourceContent) => {
|
|
|
108
145
|
hashes: string[];
|
|
109
146
|
};
|
|
110
147
|
export declare const addedSourcesOver: (context: StoreContext) => AddedSources;
|
|
148
|
+
export {};
|