@wirecat/cli-core 0.649.0 → 0.651.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 +117 -0
- package/dist/analysis/anthropic.js +2 -1
- package/dist/cli/account-remove.d.ts +2 -0
- package/dist/cli/account-remove.js +54 -13
- package/dist/cli/compact.d.ts +5 -0
- package/dist/cli/compact.js +7 -3
- package/dist/cli/doctor-reports-command.d.ts +11 -0
- package/dist/cli/doctor-reports-command.js +57 -5
- package/dist/cli/help/first-screen.js +5 -0
- 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/program.js +3 -1
- package/dist/cli/schedule/schedule-command.js +9 -3
- package/dist/cli/steps.js +9 -0
- package/dist/cli/unknown-profile.d.ts +4 -3
- package/dist/cli/unknown-profile.js +14 -6
- package/dist/constants/index.d.ts +7 -0
- package/dist/constants/index.js +16 -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/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 +9 -5
- package/dist/index.d.ts +1 -1
- package/dist/kit/own-catalogue.d.ts +1 -1
- package/dist/kit/own-catalogue.js +3 -3
- 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 +21 -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 +12 -1
- package/dist/models/ai.js +2 -2
- package/dist/models/endpoint.d.ts +7 -0
- package/dist/models/endpoint.js +44 -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/meeting-model.js +2 -1
- 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/speech/openai.js +5 -2
- package/dist/store/path.d.ts +2 -0
- package/dist/store/path.js +1 -1
- 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/meeting-projects.js +3 -3
- package/dist/store/sqlite/meetings.js +16 -2
- package/dist/store/sqlite/person-match-scan.d.ts +5 -0
- package/dist/store/sqlite/person-match-scan.js +60 -15
- package/dist/update/index.d.ts +1 -1
- package/dist/update/index.js +4 -2
- package/package.json +2 -2
package/dist/meetings/pull.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { linkEvent } from "./events.js";
|
|
2
2
|
import { speakerPosition, timestamp, transcriptInput } from "./ingest.js";
|
|
3
3
|
const participantInput = (p, provider, occurrenceId, position, accountId) => {
|
|
4
|
-
const { identityExternalId, ...fields } = p;
|
|
4
|
+
const { identityExternalId, phone, ...fields } = p;
|
|
5
5
|
const externalId = identityExternalId ??
|
|
6
6
|
(p.email ? `email:${p.email.toLowerCase()}` : p.externalId) ??
|
|
7
7
|
`name:${p.displayName ?? "unknown"}@${accountId}/${occurrenceId}:${position}`;
|
|
@@ -11,6 +11,7 @@ const participantInput = (p, provider, occurrenceId, position, accountId) => {
|
|
|
11
11
|
provider,
|
|
12
12
|
externalId,
|
|
13
13
|
name: p.displayName,
|
|
14
|
+
...(phone?.trim() ? { phone } : {}),
|
|
14
15
|
metadata: p.metadata,
|
|
15
16
|
associatePerson: Boolean(identityExternalId?.trim() || p.email?.trim() || p.externalId?.trim()),
|
|
16
17
|
},
|
|
@@ -37,6 +38,20 @@ export const pull = async (source, store, options) => {
|
|
|
37
38
|
let failed = false;
|
|
38
39
|
/** The start of the first meeting that failed: the cursor of a stopped pull goes no further. */
|
|
39
40
|
let firstFailed;
|
|
41
|
+
const callers = new Set();
|
|
42
|
+
const linkCallers = async () => {
|
|
43
|
+
if (callers.size === 0 || !store.linkCallers)
|
|
44
|
+
return;
|
|
45
|
+
try {
|
|
46
|
+
await store.linkCallers(source.provider, [...callers]);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
report.warnings.push({
|
|
50
|
+
externalId: source.provider,
|
|
51
|
+
message: `callers not linked to people: ${error instanceof Error ? error.message : "failed"}`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
40
55
|
const from = timestamp(since) - lookbackMs;
|
|
41
56
|
// Oldest first, so a stopped pull leaves everything before its cursor done.
|
|
42
57
|
const meetings = (await source.meetings(lookbackMs === 0 ? since : new Date(from).toISOString())).toSorted((a, b) => startOf(a) - startOf(b));
|
|
@@ -48,6 +63,7 @@ export const pull = async (source, store, options) => {
|
|
|
48
63
|
const reached = Math.min(startOf(m), firstFailed ?? Number.POSITIVE_INFINITY);
|
|
49
64
|
if (Number.isFinite(reached) && reached > timestamp(since))
|
|
50
65
|
await store.setCursor(options.accountId, new Date(reached).toISOString(), now);
|
|
66
|
+
await linkCallers();
|
|
51
67
|
return report;
|
|
52
68
|
}
|
|
53
69
|
const id = m.occurrence.id;
|
|
@@ -158,6 +174,9 @@ export const pull = async (source, store, options) => {
|
|
|
158
174
|
now,
|
|
159
175
|
});
|
|
160
176
|
await linkEvent(store, details, now);
|
|
177
|
+
for (const p of participants)
|
|
178
|
+
if (p.identity.phone)
|
|
179
|
+
callers.add(p.identity.externalId);
|
|
161
180
|
report.meetings++;
|
|
162
181
|
report.participants += participants.length;
|
|
163
182
|
report.transcriptRows += lines?.length ?? 0;
|
|
@@ -168,6 +187,7 @@ export const pull = async (source, store, options) => {
|
|
|
168
187
|
report.warnings.push({ externalId: id, message: error instanceof Error ? error.message : "Meeting pull failed" });
|
|
169
188
|
}
|
|
170
189
|
}
|
|
190
|
+
await linkCallers();
|
|
171
191
|
// A failed occurrence must remain inside the next pull's retry window.
|
|
172
192
|
if (!failed)
|
|
173
193
|
await store.setCursor(options.accountId, new Date(now).toISOString(), now);
|
|
@@ -124,6 +124,10 @@ export declare const meetingParticipants: v.StrictObjectSchema<{
|
|
|
124
124
|
readonly identity_id: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
125
125
|
readonly display_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
126
126
|
readonly email: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
127
|
+
readonly person: v.NullableSchema<v.StrictObjectSchema<{
|
|
128
|
+
readonly ref: v.StringSchema<undefined>;
|
|
129
|
+
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
130
|
+
}, undefined>, undefined>;
|
|
127
131
|
}, undefined>, undefined>;
|
|
128
132
|
/** Several identities on one page are observations, never speaker attribution or person links. */
|
|
129
133
|
readonly ambiguity: v.StrictObjectSchema<{
|
|
@@ -164,6 +164,7 @@ export const meetingParticipants = v.strictObject({
|
|
|
164
164
|
identity_id: id,
|
|
165
165
|
display_name: v.nullable(text),
|
|
166
166
|
email: v.nullable(text),
|
|
167
|
+
person: v.nullable(v.strictObject({ ref: text, name: v.nullable(text) })),
|
|
167
168
|
})),
|
|
168
169
|
/** Several identities on one page are observations, never speaker attribution or person links. */
|
|
169
170
|
ambiguity: v.strictObject({ scope: v.literal("page"), multiple_identities: v.boolean(), identity_ids: v.array(id) }),
|
|
@@ -3,6 +3,11 @@ import type { MeetingSave } from "./store.js";
|
|
|
3
3
|
export interface SourceParticipant {
|
|
4
4
|
identityExternalId: string | null;
|
|
5
5
|
email: string | null;
|
|
6
|
+
/**
|
|
7
|
+
* The number the participant called from or was called on, as the phone network gave it: what links a call's
|
|
8
|
+
* client to the CRM contact with that number. E.164, or written with `+`; anything else is left out.
|
|
9
|
+
*/
|
|
10
|
+
phone?: string | null;
|
|
6
11
|
displayName: string | null;
|
|
7
12
|
externalId: string | null;
|
|
8
13
|
role: string | null;
|
package/dist/meetings/store.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface IdentityInput {
|
|
|
9
9
|
provider: string;
|
|
10
10
|
externalId: string;
|
|
11
11
|
name: string | null;
|
|
12
|
+
/** As the source gave it; the store keeps it only when it reads as E.164. */
|
|
13
|
+
phone?: string | null;
|
|
12
14
|
metadata: Metadata;
|
|
13
15
|
}
|
|
14
16
|
export interface ParticipantInput extends Omit<NewRecord<Participant>, "meetingId" | "identityId"> {
|
|
@@ -44,10 +46,17 @@ export interface MeetingSave {
|
|
|
44
46
|
*/
|
|
45
47
|
fromFile?: boolean;
|
|
46
48
|
}
|
|
49
|
+
/** A participant with the person their identity is linked to, when the store knows people. */
|
|
50
|
+
export interface MeetingParticipant extends Participant {
|
|
51
|
+
person?: {
|
|
52
|
+
uid: string;
|
|
53
|
+
name: string | null;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
47
56
|
export interface MeetingDetails {
|
|
48
57
|
meeting: Meeting;
|
|
49
58
|
series: MeetingSeries | null;
|
|
50
|
-
participants:
|
|
59
|
+
participants: MeetingParticipant[];
|
|
51
60
|
transcripts: {
|
|
52
61
|
transcript: Transcript;
|
|
53
62
|
rows: TranscriptRow[];
|
|
@@ -136,6 +145,8 @@ export interface MeetingStore {
|
|
|
136
145
|
reviewMeetingLink?(meetingId: number, eventIds: number[], now: number): Promise<void>;
|
|
137
146
|
cursor(accountId: number): Promise<string | null>;
|
|
138
147
|
setCursor(accountId: number, value: string, now: number): Promise<void>;
|
|
148
|
+
/** Links the callers a sync saved, by `provider` and identity external id, to the people with their number. */
|
|
149
|
+
linkCallers?(provider: string, externalIds: readonly string[]): Promise<void>;
|
|
139
150
|
/** Detects the language of the account's transcripts that have none; stores it only with `apply`. */
|
|
140
151
|
fillTranscriptLanguages?(input: {
|
|
141
152
|
accountId: number;
|
package/dist/models/ai.js
CHANGED
|
@@ -54,10 +54,10 @@ export const aiSettingOf = (given) => {
|
|
|
54
54
|
? `the provider is one of ${AI_PROVIDERS.join(", ")}`
|
|
55
55
|
: field === "base_url"
|
|
56
56
|
? "this address is not allowed: use https, or http only on this computer"
|
|
57
|
-
: "name the model, 1 to 200 characters", { reason: field === "base_url" ? "
|
|
57
|
+
: "name the model, 1 to 200 characters", { reason: field === "base_url" ? "model.address-refused" : "ai.setting-invalid" });
|
|
58
58
|
}
|
|
59
59
|
if (checked.output.provider === "ollama" && !onThisComputer(aiBaseUrl(checked.output)))
|
|
60
|
-
throw new CliError("validation_error", "Ollama is read only on this computer", { reason: "
|
|
60
|
+
throw new CliError("validation_error", "Ollama is read only on this computer", { reason: "model.address-refused" });
|
|
61
61
|
return given.allowImages
|
|
62
62
|
? {
|
|
63
63
|
...checked.output,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { type FetchLike } from "@wirecat/cli-base/http";
|
|
1
2
|
export declare const endpoint: (value: string) => boolean;
|
|
2
3
|
/** An address on this computer: localhost, 127.x.x.x or [::1]. */
|
|
3
4
|
export declare const onThisComputer: (value: string) => boolean;
|
|
4
5
|
/** https anywhere; plain http only to this computer, so neither the text nor the key crosses a network unencrypted. */
|
|
5
6
|
export declare const modelAddressAllowed: (value: string) => boolean;
|
|
6
7
|
export declare const PLAIN_HTTP_REFUSED = "this address is not allowed: use https, or http only on this computer";
|
|
8
|
+
/**
|
|
9
|
+
* `fetch` that reaches only the host of this model address, through `hostFetch`. The address was checked when it was
|
|
10
|
+
* saved; its host is the one the person configured. `[::1]` cannot leave this computer, so it goes through the plain
|
|
11
|
+
* `fetch`; any other IPv6 literal through `literalFetch`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const endpointFetch: (address: string, timeoutMs: number) => FetchLike;
|
package/dist/models/endpoint.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
|
+
import { hostFetch } from "@wirecat/cli-base/http";
|
|
1
3
|
export const endpoint = (value) => {
|
|
2
4
|
try {
|
|
3
5
|
const url = new URL(value);
|
|
@@ -20,3 +22,45 @@ export const onThisComputer = (value) => {
|
|
|
20
22
|
/** https anywhere; plain http only to this computer, so neither the text nor the key crosses a network unencrypted. */
|
|
21
23
|
export const modelAddressAllowed = (value) => endpoint(value) && (new URL(value).protocol === "https:" || onThisComputer(value));
|
|
22
24
|
export const PLAIN_HTTP_REFUSED = "this address is not allowed: use https, or http only on this computer";
|
|
25
|
+
/**
|
|
26
|
+
* `hostFetch`'s rules for an IPv6 literal, which it does not take as a host: only this host, a deadline, and no
|
|
27
|
+
* redirect followed, since a model API has none to give.
|
|
28
|
+
*/
|
|
29
|
+
const literalFetch = (hostname, timeoutMs) => async (input, init = {}) => {
|
|
30
|
+
const url = new URL(input instanceof Request ? input.url : String(input));
|
|
31
|
+
if (url.hostname !== hostname)
|
|
32
|
+
throw new CliError("configuration_error", `${url.hostname} is not the model address's host, ${hostname}`, {
|
|
33
|
+
reason: "network.host-undeclared",
|
|
34
|
+
sent: false,
|
|
35
|
+
});
|
|
36
|
+
const deadline = AbortSignal.timeout(timeoutMs);
|
|
37
|
+
const signal = init.signal ? AbortSignal.any([init.signal, deadline]) : deadline;
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(input, { ...init, signal, redirect: "manual" });
|
|
40
|
+
if (response.status >= 300 && response.status < 400) {
|
|
41
|
+
void response.body?.cancel().catch(() => { });
|
|
42
|
+
throw new CliError("invalid_response", `${hostname} answered with a redirect, which is not followed`);
|
|
43
|
+
}
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (isCliError(error))
|
|
48
|
+
throw error;
|
|
49
|
+
if (init.signal?.aborted)
|
|
50
|
+
throw new CliError("cancelled", "request cancelled");
|
|
51
|
+
if (deadline.aborted)
|
|
52
|
+
throw new CliError("timeout", `${hostname} did not answer within ${timeoutMs} ms`, { retryable: true });
|
|
53
|
+
throw new CliError("network_error", `${hostname} could not be reached`, { retryable: true });
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* `fetch` that reaches only the host of this model address, through `hostFetch`. The address was checked when it was
|
|
58
|
+
* saved; its host is the one the person configured. `[::1]` cannot leave this computer, so it goes through the plain
|
|
59
|
+
* `fetch`; any other IPv6 literal through `literalFetch`.
|
|
60
|
+
*/
|
|
61
|
+
export const endpointFetch = (address, timeoutMs) => {
|
|
62
|
+
const { hostname } = new URL(address);
|
|
63
|
+
if (hostname === "[::1]")
|
|
64
|
+
return fetch;
|
|
65
|
+
return hostname.startsWith("[") ? literalFetch(hostname, timeoutMs) : hostFetch({ hosts: [hostname], timeoutMs });
|
|
66
|
+
};
|
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
|
};
|
|
@@ -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);
|
|
@@ -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
|
+
};
|
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;
|
package/dist/store/path.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export declare const storePath: (env?: NodeJS.ProcessEnv) => string;
|
|
|
9
9
|
export declare const accountHome: () => string | undefined;
|
|
10
10
|
/** Whether `file` is in the owner's real WireCat folder, whatever HOME or MESSAGING_STORE this process was given. */
|
|
11
11
|
export declare const inOwnerFolder: (file: string, home?: string | undefined) => boolean;
|
|
12
|
+
/** The path with every link in its existing part followed, so a link into the owner's folder is seen as one. */
|
|
13
|
+
export declare const settled: (path: string) => string;
|
|
12
14
|
/** Throws when a test is about to open a file in the owner's real WireCat folder. */
|
|
13
15
|
export declare const refuseOwnerStoreInTests: (file: string, env?: NodeJS.ProcessEnv, home?: string | undefined) => void;
|
package/dist/store/path.js
CHANGED
|
@@ -32,7 +32,7 @@ export const inOwnerFolder = (file, home = accountHome()) => {
|
|
|
32
32
|
return within(resolve(file), owner) || within(settled(resolve(file)), settled(owner));
|
|
33
33
|
};
|
|
34
34
|
/** The path with every link in its existing part followed, so a link into the owner's folder is seen as one. */
|
|
35
|
-
const settled = (path) => {
|
|
35
|
+
export const settled = (path) => {
|
|
36
36
|
try {
|
|
37
37
|
return realpathSync(path);
|
|
38
38
|
}
|
|
@@ -50,15 +50,19 @@ export declare const crmStageMoves: (database: CacheDatabase, key: AccountKey, a
|
|
|
50
50
|
through: number;
|
|
51
51
|
};
|
|
52
52
|
export interface CrmStageMove {
|
|
53
|
-
/** The stage change's own id
|
|
53
|
+
/** The stage change's own id. */
|
|
54
54
|
id: number;
|
|
55
55
|
kind: DealKind;
|
|
56
56
|
ref: string;
|
|
57
|
+
/** What its task is opened from: one task per entry into a stage, never two. */
|
|
58
|
+
source: string;
|
|
57
59
|
/** The CRM's id of the stage entered. */
|
|
58
60
|
stage: string;
|
|
59
61
|
stageName: string;
|
|
60
62
|
pipelineName: string;
|
|
61
63
|
}
|
|
64
|
+
/** When stage tasks were last opened, or the rules first set: where the CRM's stage history is first read from. */
|
|
65
|
+
export declare const crmStageTasksSince: (database: CacheDatabase, key: AccountKey) => number | null;
|
|
62
66
|
export declare const saveStageMovesMark: (database: CacheDatabase, key: AccountKey, through: number, now: number) => void;
|
|
63
67
|
export declare const parseCrmSettingValue: (name: CrmSettingName, value: string) => unknown;
|
|
64
68
|
export declare const saveCrmSetting: (database: CacheDatabase, setting: string, value: unknown, now: number) => void;
|
|
@@ -148,12 +148,20 @@ export const crmStageMoves = (database, key, accountId) => {
|
|
|
148
148
|
id: Number(row.id),
|
|
149
149
|
kind: row.item_type,
|
|
150
150
|
ref: `${String(row.item_type)}:${String(row.item_id)}`,
|
|
151
|
+
source: `${String(row.item_type)}:${String(row.item_id)}/move/${String(row.id)}`,
|
|
151
152
|
stage: String(row.stage),
|
|
152
153
|
stageName: String(row.stage_name),
|
|
153
154
|
pipelineName: String(row.pipeline_name),
|
|
154
155
|
}));
|
|
155
156
|
return { moves, through };
|
|
156
157
|
};
|
|
158
|
+
/** When stage tasks were last opened, or the rules first set: where the CRM's stage history is first read from. */
|
|
159
|
+
export const crmStageTasksSince = (database, key) => {
|
|
160
|
+
const row = database
|
|
161
|
+
.prepare("SELECT at FROM store_settings WHERE key = ?")
|
|
162
|
+
.get(stageTasksMark(crmSettingKey(key, "stage-tasks")));
|
|
163
|
+
return row ? Number(row.at) : null;
|
|
164
|
+
};
|
|
157
165
|
export const saveStageMovesMark = (database, key, through, now) => {
|
|
158
166
|
database
|
|
159
167
|
.prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CrmStageEntry } from "../../domain/crm.js";
|
|
2
|
+
import type { AccountKey } from "../types.js";
|
|
3
|
+
import type { CrmStageMove } from "./crm-settings.js";
|
|
4
|
+
import type { StoreContext } from "./open.js";
|
|
5
|
+
export declare const STAGE_ENTRY_RECORD = "crm.stage-entry";
|
|
6
|
+
/**
|
|
7
|
+
* The CRM's own record of each stage a deal or lead entered, kept until its stage task is handled: a run stopped
|
|
8
|
+
* between reading the history and opening the tasks opens them next time. A handled entry stays, marked deleted, so
|
|
9
|
+
* reading the same history again opens nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare const crmStageEntriesOver: (context: StoreContext) => {
|
|
12
|
+
save: (key: AccountKey, entries: readonly CrmStageEntry[]) => number;
|
|
13
|
+
pending: (key: AccountKey) => CrmStageMove[];
|
|
14
|
+
handled: (ids: readonly number[]) => void;
|
|
15
|
+
};
|