@wirecat/cli-core 0.649.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 +65 -0
- package/dist/analysis/anthropic.js +2 -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/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/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/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/update/index.d.ts +1 -1
- package/dist/update/index.js +4 -2
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { accountPk, findAccountPk } from "./accounts.js";
|
|
2
|
+
import { SOURCE, TABLES } from "./crm-rows.js";
|
|
3
|
+
import { write } from "./transaction.js";
|
|
4
|
+
export const STAGE_ENTRY_RECORD = "crm.stage-entry";
|
|
5
|
+
/**
|
|
6
|
+
* The CRM's own record of each stage a deal or lead entered, kept until its stage task is handled: a run stopped
|
|
7
|
+
* between reading the history and opening the tasks opens them next time. A handled entry stays, marked deleted, so
|
|
8
|
+
* reading the same history again opens nothing.
|
|
9
|
+
*/
|
|
10
|
+
export const crmStageEntriesOver = (context) => {
|
|
11
|
+
const { database, now } = context;
|
|
12
|
+
/** Answers how many were new; an entry on a deal or lead the copy does not hold, or into an unknown stage, is not. */
|
|
13
|
+
const save = (key, entries) => write(database, () => {
|
|
14
|
+
const accountId = accountPk(context, key);
|
|
15
|
+
const at = now();
|
|
16
|
+
let saved = 0;
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const item = database
|
|
19
|
+
.prepare(`SELECT id FROM ${TABLES[entry.kind]} WHERE account_id = ? AND external_id = ? AND deleted_at IS NULL`)
|
|
20
|
+
.get(accountId, entry.item);
|
|
21
|
+
const stage = database
|
|
22
|
+
.prepare("SELECT s.id FROM pipeline_stages s JOIN pipelines p ON p.id = s.pipeline_id " +
|
|
23
|
+
"WHERE p.account_id = ? AND p.kind = ? AND p.external_id = ? AND s.external_id = ?")
|
|
24
|
+
.get(accountId, entry.kind, entry.pipeline, entry.stage);
|
|
25
|
+
if (!item || !stage)
|
|
26
|
+
continue;
|
|
27
|
+
const externalId = `${entry.kind}/${entry.externalId}`;
|
|
28
|
+
const inserted = database
|
|
29
|
+
.prepare("INSERT INTO records (account_id, type, external_id, fields, fingerprint, batch_id, created_at, updated_at) " +
|
|
30
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT DO NOTHING RETURNING id")
|
|
31
|
+
.get(accountId, STAGE_ENTRY_RECORD, externalId, JSON.stringify({ kind: entry.kind, item_id: Number(item.id), stage_id: Number(stage.id), at: entry.at }), externalId, SOURCE, at, at);
|
|
32
|
+
if (!inserted)
|
|
33
|
+
continue;
|
|
34
|
+
database
|
|
35
|
+
.prepare("INSERT INTO record_relations (record_id, role, target_type, target_external_id, created_at) " +
|
|
36
|
+
"VALUES (?, 'on', ?, ?, ?)")
|
|
37
|
+
.run(Number(inserted.id), entry.kind, entry.item, at);
|
|
38
|
+
saved += 1;
|
|
39
|
+
}
|
|
40
|
+
return saved;
|
|
41
|
+
});
|
|
42
|
+
/** The entries not handled yet, oldest first, as stage moves whose task source names the CRM's history row. */
|
|
43
|
+
const pending = (key) => {
|
|
44
|
+
const accountId = findAccountPk(context, key);
|
|
45
|
+
if (accountId === undefined)
|
|
46
|
+
return [];
|
|
47
|
+
return database
|
|
48
|
+
.prepare("SELECT r.id, r.external_id, json_extract(r.fields, '$.kind') AS kind, " +
|
|
49
|
+
"json_extract(r.fields, '$.item_id') AS item_id, s.external_id AS stage, s.name AS stage_name, " +
|
|
50
|
+
"p.name AS pipeline_name FROM records r " +
|
|
51
|
+
"JOIN pipeline_stages s ON s.id = json_extract(r.fields, '$.stage_id') JOIN pipelines p ON p.id = s.pipeline_id " +
|
|
52
|
+
"WHERE r.account_id = ? AND r.type = ? AND r.deleted_at IS NULL " +
|
|
53
|
+
"ORDER BY json_extract(r.fields, '$.at'), r.id")
|
|
54
|
+
.all(accountId, STAGE_ENTRY_RECORD)
|
|
55
|
+
.map((row) => {
|
|
56
|
+
const ref = `${String(row.kind)}:${String(row.item_id)}`;
|
|
57
|
+
return {
|
|
58
|
+
id: Number(row.id),
|
|
59
|
+
kind: row.kind,
|
|
60
|
+
ref,
|
|
61
|
+
source: `${ref}/history/${String(row.external_id).split("/").at(-1)}`,
|
|
62
|
+
stage: String(row.stage),
|
|
63
|
+
stageName: String(row.stage_name),
|
|
64
|
+
pipelineName: String(row.pipeline_name),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const handled = (ids) => write(database, () => {
|
|
69
|
+
const at = now();
|
|
70
|
+
for (const id of ids)
|
|
71
|
+
database.prepare("UPDATE records SET deleted_at = ? WHERE id = ?").run(at, id);
|
|
72
|
+
});
|
|
73
|
+
return { save, pending, handled };
|
|
74
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CrmActivity, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmScopeSetting, type CrmUser } from "../../domain/crm.js";
|
|
1
|
+
import { type CrmActivity, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmScopeSetting, type CrmStageEntry, type CrmUser } from "../../domain/crm.js";
|
|
2
2
|
import { type DealKind } from "../../domain/deals.js";
|
|
3
3
|
import type { AccountPeople } from "../people.js";
|
|
4
4
|
import type { AccountKey } from "../types.js";
|
|
@@ -95,6 +95,13 @@ export interface CrmCopies {
|
|
|
95
95
|
through: number;
|
|
96
96
|
}>;
|
|
97
97
|
markStageMoves(key: AccountKey, through: number): Promise<void>;
|
|
98
|
+
/** When stage tasks were last opened, or the rules first set; null without rules. */
|
|
99
|
+
stageTasksSince(key: AccountKey): Promise<number | null>;
|
|
100
|
+
/** Entries from the CRM's stage history on kept deals and leads; answers how many were new. */
|
|
101
|
+
saveStageEntries(key: AccountKey, entries: readonly CrmStageEntry[]): Promise<number>;
|
|
102
|
+
/** The stored history entries whose stage task is not handled yet, oldest first. */
|
|
103
|
+
stageEntries(key: AccountKey): Promise<CrmStageMove[]>;
|
|
104
|
+
handleStageEntries(ids: readonly number[]): Promise<void>;
|
|
98
105
|
/** Whether the owner turned on reading activities and tasks (`activities` setting). */
|
|
99
106
|
activitiesOn(key: AccountKey): Promise<boolean>;
|
|
100
107
|
/** Activities and tasks, each on the kept deals and leads it names; one on none of them is not stored. */
|
package/dist/store/sqlite/crm.js
CHANGED
|
@@ -7,7 +7,8 @@ import { suggestBaseStages } from "./base-suggest.js";
|
|
|
7
7
|
import { crmActivitiesOver } from "./crm-activities.js";
|
|
8
8
|
import { removeCrmContacts } from "./crm-contacts.js";
|
|
9
9
|
import { crmAccountPrefix, crmIdentityId, crmRowsOver, SOURCE, TABLES, textOf } from "./crm-rows.js";
|
|
10
|
-
import { crmActivitiesOn, crmCompanyTypes, crmOwnUser, crmScope, crmScopeUsers, crmSettingKey, crmStageMoves, crmStageTasks, saveCrmSetting, saveStageMovesMark, } from "./crm-settings.js";
|
|
10
|
+
import { crmActivitiesOn, crmCompanyTypes, crmOwnUser, crmScope, crmScopeUsers, crmSettingKey, crmStageMoves, crmStageTasks, crmStageTasksSince, saveCrmSetting, saveStageMovesMark, } from "./crm-settings.js";
|
|
11
|
+
import { crmStageEntriesOver } from "./crm-stage-entries.js";
|
|
11
12
|
import { syncReportedIn } from "./reported-relations.js";
|
|
12
13
|
import { clearState, syncStateOf, writeState } from "./sync.js";
|
|
13
14
|
import { write } from "./transaction.js";
|
|
@@ -30,6 +31,7 @@ export const crmCopiesOver = (context, people) => {
|
|
|
30
31
|
const { savePipeline, saveItemRow } = crmRowsOver(context);
|
|
31
32
|
const account = (key) => accountPk(context, key);
|
|
32
33
|
const activityStore = crmActivitiesOver(context);
|
|
34
|
+
const stageEntryStore = crmStageEntriesOver(context);
|
|
33
35
|
/**
|
|
34
36
|
* One kind's whole list: a pipeline it lacks is marked deleted, one listed again comes back. An empty list marks
|
|
35
37
|
* nothing: a sign-in that lost its CRM rights lists no pipeline at all.
|
|
@@ -593,6 +595,10 @@ export const crmCopiesOver = (context, people) => {
|
|
|
593
595
|
stageTasks: async (key) => crmStageTasks(database, key),
|
|
594
596
|
stageMoves: async (key) => crmStageMoves(database, key, findAccountPk(context, key)),
|
|
595
597
|
markStageMoves: async (key, through) => saveStageMovesMark(database, key, through, now()),
|
|
598
|
+
stageTasksSince: async (key) => crmStageTasksSince(database, key),
|
|
599
|
+
saveStageEntries: async (key, entries) => stageEntryStore.save(key, entries),
|
|
600
|
+
stageEntries: async (key) => stageEntryStore.pending(key),
|
|
601
|
+
handleStageEntries: async (ids) => stageEntryStore.handled(ids),
|
|
596
602
|
activitiesOn: async (key) => crmActivitiesOn(database, key),
|
|
597
603
|
saveActivities: async (key, activities) => activityStore.save(key, activities),
|
|
598
604
|
activitiesOf: async (key, kind, externalId, limit) => activityStore.of(key, kind, externalId, limit),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { e164Of } from "../../domain/phones.js";
|
|
2
3
|
import { fold } from "../normalize.js";
|
|
3
4
|
import { and, asc, desc, eq, inArray, isNotNull, isNull, ne, sql } from "./drizzle/core.js";
|
|
4
5
|
import { folded } from "./folded.js";
|
|
@@ -358,7 +359,8 @@ export const meetingIdentityPk = (context, accountId, identity) => {
|
|
|
358
359
|
if (!identity.provider || !identity.externalId)
|
|
359
360
|
throw new CliError("validation_error", "Invalid identity key");
|
|
360
361
|
const associatePerson = identity.associatePerson === true;
|
|
361
|
-
const
|
|
362
|
+
const phone = identity.phone ? e164Of(identity.phone, undefined) : undefined;
|
|
363
|
+
const saved = saveIdentity(context, identity.provider, identity.externalId, identity.name, { metadata: identity.metadata, ...(phone ? { phone } : {}) }, false, associatePerson);
|
|
362
364
|
if (associatePerson)
|
|
363
365
|
statementsOf(context.orm).seen.run({ accountId, identityId: saved.pk, createdAt: context.now() });
|
|
364
366
|
return saved.pk;
|
|
@@ -32,6 +32,8 @@ export interface InvolvementStore {
|
|
|
32
32
|
*/
|
|
33
33
|
forPerson(personId: number, options?: {
|
|
34
34
|
scopes?: readonly string[];
|
|
35
|
+
/** Only rows of these subjects, such as `["meeting"]`; left out, every subject. */
|
|
36
|
+
subjectTypes?: readonly string[];
|
|
35
37
|
since?: number;
|
|
36
38
|
until?: number;
|
|
37
39
|
only?: {
|
|
@@ -21,13 +21,16 @@ export const involvementStoreOver = ({ database, now }) => ({
|
|
|
21
21
|
return { recomputed, pending: pendingInvolvements(database) };
|
|
22
22
|
},
|
|
23
23
|
pending: () => pendingInvolvements(database),
|
|
24
|
-
forPerson: (personId, { scopes, since, until, only, before, limit = 100 } = {}) => {
|
|
24
|
+
forPerson: (personId, { scopes, subjectTypes, since, until, only, before, limit = 100 } = {}) => {
|
|
25
25
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1000)
|
|
26
26
|
throw new CliError("validation_error", "involvement limit takes 1–1000");
|
|
27
27
|
const filters = [
|
|
28
28
|
...(scopes === undefined
|
|
29
29
|
? []
|
|
30
30
|
: [["AND i.scope IN (SELECT value FROM json_each(?))", JSON.stringify(scopes)]]),
|
|
31
|
+
...(subjectTypes === undefined
|
|
32
|
+
? []
|
|
33
|
+
: [["AND i.subject_type IN (SELECT value FROM json_each(?))", JSON.stringify(subjectTypes)]]),
|
|
31
34
|
...(since === undefined ? [] : [["AND i.occurred_at>=?", since]]),
|
|
32
35
|
...(until === undefined ? [] : [["AND i.occurred_at<=?", until]]),
|
|
33
36
|
];
|
|
@@ -42,12 +42,16 @@ export const meetingParticipantSearchOver = (context) => ({
|
|
|
42
42
|
.get(limits.accountId)?.id);
|
|
43
43
|
const rows = database
|
|
44
44
|
.prepare(`SELECT p.id,
|
|
45
|
-
coalesce(length(CAST(p.display_name AS BLOB)), 0) + coalesce(length(CAST(p.email AS BLOB)), 0)
|
|
45
|
+
coalesce(length(CAST(p.display_name AS BLOB)), 0) + coalesce(length(CAST(p.email AS BLOB)), 0) +
|
|
46
|
+
coalesce(length(CAST(n.name AS BLOB)), 0) AS bytes
|
|
46
47
|
FROM meeting_participants p JOIN meetings m ON m.id = p.meeting_id
|
|
48
|
+
LEFT JOIN identity_links l ON l.identity_id = p.identity_id LEFT JOIN persons n ON n.id = l.person_id
|
|
47
49
|
WHERE m.account_id = ? AND m.deleted_at IS NULL AND p.id > ? AND p.id <= ?
|
|
48
50
|
ORDER BY p.id LIMIT ?`)
|
|
49
51
|
.all(limits.accountId, previous?.after ?? 0, until, limits.scanLimit + 1);
|
|
50
|
-
const read = database.prepare("SELECT id, meeting_id, identity_id, display_name, email
|
|
52
|
+
const read = database.prepare("SELECT p.id, p.meeting_id, p.identity_id, p.display_name, p.email, l.person_id, n.name AS person_name " +
|
|
53
|
+
"FROM meeting_participants p LEFT JOIN identity_links l ON l.identity_id = p.identity_id " +
|
|
54
|
+
"LEFT JOIN persons n ON n.id = l.person_id WHERE p.id = ?");
|
|
51
55
|
const result = {
|
|
52
56
|
schema_version: 1,
|
|
53
57
|
kind: "meeting_participants",
|
|
@@ -78,10 +82,11 @@ export const meetingParticipantSearchOver = (context) => ({
|
|
|
78
82
|
throw new CliError("invalid_response", "participant observation disappeared within its snapshot");
|
|
79
83
|
const name = found.display_name === null ? null : String(found.display_name);
|
|
80
84
|
const email = found.email === null ? null : String(found.email);
|
|
85
|
+
const personName = found.person_name == null ? null : String(found.person_name);
|
|
81
86
|
after = Number(row.id);
|
|
82
87
|
result.coverage.scanned++;
|
|
83
88
|
result.coverage.read_bytes += Number(row.bytes);
|
|
84
|
-
if (!normalizeMeetingParticipantQuery(`${name ?? ""} ${email ?? ""}`).includes(limits.query))
|
|
89
|
+
if (!normalizeMeetingParticipantQuery(`${name ?? ""} ${email ?? ""} ${personName ?? ""}`).includes(limits.query))
|
|
85
90
|
continue;
|
|
86
91
|
result.items.push({
|
|
87
92
|
participant_id: after,
|
|
@@ -89,6 +94,7 @@ export const meetingParticipantSearchOver = (context) => ({
|
|
|
89
94
|
identity_id: Number(found.identity_id),
|
|
90
95
|
display_name: name,
|
|
91
96
|
email,
|
|
97
|
+
person: found.person_id == null ? null : { ref: `person:${found.person_id}`, name: personName },
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
100
|
result.hasMore = result.coverage.truncated_by !== null;
|
|
@@ -111,9 +111,14 @@ const details = (database, id) => {
|
|
|
111
111
|
meeting,
|
|
112
112
|
series,
|
|
113
113
|
participants: database
|
|
114
|
-
.prepare("SELECT
|
|
114
|
+
.prepare("SELECT mp.*, l.person_id AS person_uid, p.name AS person_name FROM meeting_participants mp " +
|
|
115
|
+
"LEFT JOIN identity_links l ON l.identity_id = mp.identity_id LEFT JOIN persons p ON p.id = l.person_id " +
|
|
116
|
+
"WHERE mp.meeting_id = ? ORDER BY mp.id")
|
|
115
117
|
.all(id)
|
|
116
|
-
.map(
|
|
118
|
+
.map((row) => ({
|
|
119
|
+
...participantOf(row),
|
|
120
|
+
...(row.person_uid == null ? {} : { person: { uid: String(row.person_uid), name: str(row.person_name) } }),
|
|
121
|
+
})),
|
|
117
122
|
transcripts: database
|
|
118
123
|
.prepare("SELECT * FROM meeting_transcripts WHERE meeting_id = ? ORDER BY id")
|
|
119
124
|
.all(id)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isEmailAddress, isNoReplyAddress, isPersonLikeRoleAddress, isRoleAddress } from "../../domain/addresses.js";
|
|
2
2
|
import { displayName, isReadable } from "../../domain/display-names.js";
|
|
3
3
|
import { variantKey } from "../../domain/name-variants.js";
|
|
4
|
-
import { BARE_INTERNATIONAL_PROVIDERS, storedPhone } from "../../domain/phones.js";
|
|
4
|
+
import { BARE_INTERNATIONAL_PROVIDERS, isMobilePhone, nationalPhone, storedPhone } from "../../domain/phones.js";
|
|
5
5
|
import { linkIndex, settleLinks } from "./identity-link-rows.js";
|
|
6
6
|
import { openIdentityLink } from "./identity-proposals.js";
|
|
7
7
|
import { peopleByNameKey, sharedTraces } from "./name-traces.js";
|
|
@@ -9,6 +9,7 @@ import { isOwner, mergePerson } from "./person-links.js";
|
|
|
9
9
|
import { personsByIdentifiers } from "./person-matcher.js";
|
|
10
10
|
import { resolvePersonLinks } from "./person-resolution.js";
|
|
11
11
|
import { separated } from "./person-separation.js";
|
|
12
|
+
import { storePhoneCountries } from "./phone-countries.js";
|
|
12
13
|
import { referenceOfThing } from "./things.js";
|
|
13
14
|
import { write } from "./transaction.js";
|
|
14
15
|
/** Who an automatic link is recorded as: never the owner, whose moves count as separations. */
|
|
@@ -18,7 +19,7 @@ export const RULE = { bot: "rule", kind: "rule" };
|
|
|
18
19
|
const MOST_SHARING = 6;
|
|
19
20
|
const CURSOR = "people.scan";
|
|
20
21
|
/** Raised when a rule changes what a pass finds in values nobody touched: the next pass then reads everything once. */
|
|
21
|
-
const RULES =
|
|
22
|
+
const RULES = 5;
|
|
22
23
|
/**
|
|
23
24
|
* NEED-2526: a shared mailbox says little alone, so its proposal is scored by what else the two people have in common.
|
|
24
25
|
* The owner's word (2026-11-11): `hr@` is often one person's, so it starts below `info@`.
|
|
@@ -43,8 +44,11 @@ export const PROPOSAL_SCORE = {
|
|
|
43
44
|
/**
|
|
44
45
|
* NEED-2445, safe option until the owner rules: a number two people share joins them only when a messenger, which
|
|
45
46
|
* keeps its user's own number, holds it; a CRM's or a card's number is someone's word and waits as a proposal.
|
|
47
|
+
* NEED-2600: a call's other side, kept as `phone:<number>`, is that number as the phone network gave it, as strong
|
|
48
|
+
* as a messenger's; it joins only on a mobile number, since an office's landline is everyone's who works there.
|
|
46
49
|
*/
|
|
47
|
-
const phonePairJoins = (holders) => holders.some(({ provider }) => BARE_INTERNATIONAL_PROVIDERS.includes(provider))
|
|
50
|
+
const phonePairJoins = (phone, holders) => holders.some(({ provider }) => BARE_INTERNATIONAL_PROVIDERS.includes(provider)) ||
|
|
51
|
+
(holders.some(({ externalId }) => externalId === `phone:${phone}`) && isMobilePhone(phone));
|
|
48
52
|
/** NEED-2446, safe option until the owner rules: an address more than two people have is shared, so it proposes. */
|
|
49
53
|
const addressGroupJoins = (people) => people <= 2;
|
|
50
54
|
/** A bot or a service account shares its number or address with whoever runs it; it is nobody's person. */
|
|
@@ -99,6 +103,7 @@ const holderOf = (row) => {
|
|
|
99
103
|
return {
|
|
100
104
|
identity: Number(row.id),
|
|
101
105
|
provider,
|
|
106
|
+
externalId: String(row.external_id),
|
|
102
107
|
list: `${provider}:${String(row.external_id).replace(/[^/]*$/u, "")}`,
|
|
103
108
|
company: row.company === 1,
|
|
104
109
|
};
|
|
@@ -111,17 +116,36 @@ const add = (found, key, holder) => {
|
|
|
111
116
|
held.push(holder);
|
|
112
117
|
found.set(key, held);
|
|
113
118
|
};
|
|
119
|
+
/**
|
|
120
|
+
* NEED-2600: a CRM keeps a number as someone typed it, `8 (912) 345-67-89`; without a `+` it is read in the store's
|
|
121
|
+
* `phone_countries` (Russian by default), so a call from that number finds the contact. A messenger's bare digits stay
|
|
122
|
+
* international (`storedPhone`).
|
|
123
|
+
*/
|
|
124
|
+
const phoneKey = (raw, provider, countries) => storedPhone(raw, provider) ??
|
|
125
|
+
(/^\s*(\+|00)/.test(raw) || BARE_INTERNATIONAL_PROVIDERS.includes(provider)
|
|
126
|
+
? undefined
|
|
127
|
+
: nationalPhone(raw.replace(/\(0\)/, "").replace(/\D/g, ""), countries, { anyType: true })?.value);
|
|
128
|
+
/** The numbers an identity holds: its phone column, and the other numbers a CRM keeps in its metadata's `phones`. */
|
|
129
|
+
const phonesOf = (row) => {
|
|
130
|
+
const raws = [row.provider === "phone" ? row.external_id : row.phone];
|
|
131
|
+
try {
|
|
132
|
+
const more = row.metadata == null ? undefined : JSON.parse(String(row.metadata)).phones;
|
|
133
|
+
if (Array.isArray(more))
|
|
134
|
+
raws.push(...more);
|
|
135
|
+
}
|
|
136
|
+
catch { }
|
|
137
|
+
return raws.filter((raw) => typeof raw === "string" && raw.trim() !== "");
|
|
138
|
+
};
|
|
114
139
|
const phoneHolders = (database) => {
|
|
115
140
|
const found = new Map();
|
|
141
|
+
const countries = storePhoneCountries(database);
|
|
116
142
|
for (const row of database
|
|
117
|
-
.prepare(`SELECT i.id, i.provider, i.external_id, i.phone, ${COMPANY} FROM identities i ` +
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
.all())
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
add(found, storedPhone(raw, provider), holderOf(row));
|
|
124
|
-
}
|
|
143
|
+
.prepare(`SELECT i.id, i.provider, i.external_id, i.phone, i.metadata, ${COMPANY} FROM identities i ` +
|
|
144
|
+
"JOIN identity_links l ON l.identity_id = i.id WHERE (i.provider = 'phone' OR i.phone IS NOT NULL OR " +
|
|
145
|
+
`(json_valid(i.metadata) AND json_extract(i.metadata, '$.phones') IS NOT NULL)) AND ${NOT_A_BOT} ORDER BY i.id`)
|
|
146
|
+
.all())
|
|
147
|
+
for (const raw of phonesOf(row))
|
|
148
|
+
add(found, phoneKey(raw, String(row.provider), countries), holderOf(row));
|
|
125
149
|
return found;
|
|
126
150
|
};
|
|
127
151
|
const addressOf = (value) => {
|
|
@@ -243,14 +267,14 @@ const skipShared = (pass, people, signal) => pass.result.skipped.push({ persons:
|
|
|
243
267
|
* A number two people have joins them (NEED-2445); one that more share, or that once proposed, proposes. A company's
|
|
244
268
|
* line does neither.
|
|
245
269
|
*/
|
|
246
|
-
const samePhone = (pass, holders) => {
|
|
270
|
+
const samePhone = (pass, phone, holders) => {
|
|
247
271
|
const people = peopleOf(pass.context, holders);
|
|
248
272
|
if (people.size < 2 || tooMany(pass, people, "identity.shared-phone", "phone"))
|
|
249
273
|
return;
|
|
250
274
|
if (sharedLine(pass.context, holders))
|
|
251
275
|
return skipShared(pass, people, "phone");
|
|
252
276
|
const [into, from] = [...people.keys()].sort((a, b) => a - b);
|
|
253
|
-
if (people.size === 2 && phonePairJoins(holders) && !pass.index.known(from, into))
|
|
277
|
+
if (people.size === 2 && phonePairJoins(phone, holders) && !pass.index.known(from, into))
|
|
254
278
|
join(pass, { from, into, identity: people.get(from), with: people.get(into) }, "phone");
|
|
255
279
|
else
|
|
256
280
|
proposeEachPair(pass, people, "phone");
|
|
@@ -527,9 +551,9 @@ export const scanMatches = (context, { full = false } = {}) => {
|
|
|
527
551
|
for (const [address, holders] of emailHolders(database))
|
|
528
552
|
if (holders.length > 1 && touched(holders))
|
|
529
553
|
write(database, () => sameEmail(pass, address, holders));
|
|
530
|
-
for (const holders of phoneHolders(database)
|
|
554
|
+
for (const [phone, holders] of phoneHolders(database))
|
|
531
555
|
if (holders.length > 1 && touched(holders))
|
|
532
|
-
write(database, () => samePhone(pass, holders));
|
|
556
|
+
write(database, () => samePhone(pass, phone, holders));
|
|
533
557
|
for (const group of pass.shared)
|
|
534
558
|
write(database, () => proposeShared(pass, group));
|
|
535
559
|
for (const row of guestRows(database))
|
package/dist/update/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FetchLike } from "@wirecat/cli-base/http";
|
|
2
2
|
import { type Installer } from "@wirecat/cli-base/update";
|
|
3
3
|
/** npm, the clock, the terminal and the package manager as `<app> upgrade` sees them — faked in a test. */
|
|
4
4
|
export interface UpdateEnvironment {
|
package/dist/update/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { hostFetch } from "@wirecat/cli-base/http";
|
|
3
4
|
import { installerOf, latestVersion, runUpdate as runPackageManager, updateNotice as sharedNotice, } from "@wirecat/cli-base/update";
|
|
5
|
+
const npmRegistry = () => hostFetch({ hosts: ["registry.npmjs.org"] });
|
|
4
6
|
/** Words after which a line on stderr would land in a machine's answer, or would only repeat the command. */
|
|
5
7
|
export const QUIET_WORDS = [
|
|
6
8
|
"--help",
|
|
@@ -27,7 +29,7 @@ export const appUpdate = (app) => {
|
|
|
27
29
|
};
|
|
28
30
|
return {
|
|
29
31
|
installer,
|
|
30
|
-
latest: (environment = {}) => latestVersion(app.packageName, environment.fetch ??
|
|
32
|
+
latest: (environment = {}) => latestVersion(app.packageName, environment.fetch ?? npmRegistry(), { timeoutMs: 3000 }),
|
|
31
33
|
/** The package manager's output goes to stderr, so stdout stays one result. */
|
|
32
34
|
runUpdate: (argv, environment = {}) => environment.spawn ? environment.spawn(argv) : runPackageManager(argv),
|
|
33
35
|
/**
|
|
@@ -48,7 +50,7 @@ export const appUpdate = (app) => {
|
|
|
48
50
|
command: app.command,
|
|
49
51
|
version: app.version,
|
|
50
52
|
statePath: app.statePath(env),
|
|
51
|
-
fetch: environment.fetch ??
|
|
53
|
+
fetch: environment.fetch ?? npmRegistry(),
|
|
52
54
|
...(environment.now ? { now: environment.now } : {}),
|
|
53
55
|
format: pretty ? "pretty" : "json",
|
|
54
56
|
stderrIsTTY: environment.stderrIsTTY ?? process.stderr.isTTY === true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.650.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|