@wirecat/cli-core 0.603.0 → 0.605.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 +92 -0
- package/dist/calendar/prepare.d.ts +4 -2
- package/dist/calendar/prepare.js +8 -8
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/messenger/contacts-command.js +3 -2
- package/dist/cli/messenger/doctor-command.js +14 -7
- package/dist/cli/messenger/search-answers.js +8 -1
- package/dist/cli/messenger/store-maintenance-command.d.ts +34 -2
- package/dist/cli/messenger/store-maintenance-command.js +31 -4
- package/dist/cli/model-catalogue-command.js +28 -2
- package/dist/cli/program.js +11 -2
- package/dist/cli/steps.js +9 -1
- package/dist/cli/store-recover.d.ts +10 -2
- package/dist/cli/store-recover.js +18 -4
- package/dist/domain/record-types.d.ts +61 -0
- package/dist/domain/record-types.js +26 -0
- package/dist/domain/records.d.ts +3 -5
- package/dist/domain/records.js +10 -13
- package/dist/entities/contact-activity.d.ts +4 -0
- package/dist/entities/contact-activity.js +1 -0
- package/dist/entities/contact-context.d.ts +20 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/index.d.ts +22 -0
- package/dist/errors/failures.d.ts +17 -1
- package/dist/errors/failures.js +57 -1
- package/dist/errors/reasons.js +16 -0
- package/dist/mcp/tool.js +2 -1
- package/dist/runs/recording.js +13 -4
- package/dist/search/lucene/plain.d.ts +2 -1
- package/dist/search/lucene/plain.js +15 -1
- package/dist/services/deps.js +4 -6
- package/dist/services/index.d.ts +1 -1
- package/dist/services/link-scorers/chat-senders.d.ts +3 -2
- package/dist/services/link-scorers/chat-senders.js +7 -4
- package/dist/services/link-scorers/mail-thread.js +1 -0
- package/dist/services/link-scorers/member-chats.js +1 -0
- package/dist/services/link-scorers/member-dialog.d.ts +1 -1
- package/dist/services/link-scorers/member-dialog.js +4 -3
- package/dist/services/link-scorers/scan.d.ts +5 -2
- package/dist/services/link-scorers/scan.js +98 -53
- package/dist/services/link-scorers/shared.d.ts +2 -2
- package/dist/services/link-scorers/shared.js +7 -4
- package/dist/services/link-scorers/types.d.ts +3 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/model-downloads.d.ts +5 -3
- package/dist/services/model-downloads.js +6 -6
- package/dist/services/notes-search.js +4 -2
- package/dist/services/person-context.d.ts +24 -7
- package/dist/services/person-context.js +45 -11
- package/dist/services/person-preparation.js +4 -5
- package/dist/services/search-all.d.ts +6 -0
- package/dist/services/search-all.js +16 -8
- package/dist/speech/install.d.ts +6 -7
- package/dist/speech/install.js +17 -10
- package/dist/store/damage.d.ts +3 -1
- package/dist/store/damage.js +19 -12
- package/dist/store/document-transfer/index.js +7 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/marks.d.ts +57 -0
- package/dist/store/marks.js +121 -0
- package/dist/store/project-transfer/preview.js +12 -7
- package/dist/store/recover.js +16 -1
- package/dist/store/sqlite/finance.d.ts +8 -1
- package/dist/store/sqlite/finance.js +10 -3
- package/dist/store/sqlite/note-dates.d.ts +6 -0
- package/dist/store/sqlite/note-dates.js +23 -0
- package/dist/store/sqlite/notes.d.ts +13 -0
- package/dist/store/sqlite/notes.js +6 -1
- package/dist/store/sqlite/open-store.js +4 -1
- package/dist/store/sqlite/own-identities.d.ts +1 -1
- package/dist/store/sqlite/own-identities.js +7 -5
- package/dist/store/sqlite/person-links.d.ts +5 -2
- package/dist/store/sqlite/person-links.js +24 -18
- package/dist/store/sqlite/person-separation.d.ts +5 -0
- package/dist/store/sqlite/person-separation.js +26 -0
- package/dist/store/sqlite/record-projectors.d.ts +44 -0
- package/dist/store/sqlite/record-projectors.js +72 -0
- package/dist/store/sqlite/records.js +12 -70
- package/dist/store/sqlite/transaction.js +2 -5
- package/dist/store/types.d.ts +5 -0
- package/package.json +3 -3
- package/parity.json +3 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LinkScorer } from "./types.js";
|
|
2
|
-
/** A dialog with a
|
|
2
|
+
/** A dialog with a person member, divided by how many projects that person is a member of, this one counted. */
|
|
3
3
|
export declare const memberDialog: LinkScorer;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { chatRef, identitiesIn, projectsOf } from "./shared.js";
|
|
2
2
|
const WEIGHT = 0.6;
|
|
3
|
-
/** A dialog with a
|
|
3
|
+
/** A dialog with a person member, divided by how many projects that person is a member of, this one counted. */
|
|
4
4
|
export const memberDialog = {
|
|
5
5
|
id: "member-dialog",
|
|
6
|
-
version:
|
|
6
|
+
version: 2,
|
|
7
|
+
spreads: true,
|
|
7
8
|
candidates: async ({ store, project, confirmed, sources, owner, signal }) => {
|
|
8
9
|
if (!project)
|
|
9
10
|
return [];
|
|
@@ -17,7 +18,7 @@ export const memberDialog = {
|
|
|
17
18
|
if (chat.kind !== "dialog")
|
|
18
19
|
continue;
|
|
19
20
|
if (!projects.has(person))
|
|
20
|
-
projects.set(person,
|
|
21
|
+
projects.set(person, await projectsOf(store, person, project.ref));
|
|
21
22
|
const shared = projects.get(person) ?? 1;
|
|
22
23
|
found.push({
|
|
23
24
|
from: chatRef(key, chat.id),
|
|
@@ -14,6 +14,8 @@ export declare const DEFAULT_THRESHOLD = 0.5;
|
|
|
14
14
|
/** A person ↔ person scan keeps the old rule's reach: one weak signal is enough to ask the owner. */
|
|
15
15
|
export declare const PERSON_THRESHOLD = 0.3;
|
|
16
16
|
export declare const DEFAULT_LIMIT = 20;
|
|
17
|
+
/** How many times one scan spreads from what it found; a project's links are rarely more than a few steps apart. */
|
|
18
|
+
export declare const MAX_HOPS = 4;
|
|
17
19
|
export interface ScanInput {
|
|
18
20
|
/** A project's key, name, alias or `project:<id>`; `null` runs the person ↔ person rules. */
|
|
19
21
|
project: string | null;
|
|
@@ -33,8 +35,9 @@ export interface ScanInput {
|
|
|
33
35
|
export declare const combinedScore: (weights: readonly number[]) => number;
|
|
34
36
|
/**
|
|
35
37
|
* Runs the scorers for one project over the sources named, combines their signals per pair, and proposes what scores
|
|
36
|
-
* `threshold` or more, highest first, at most `limit` new ones.
|
|
37
|
-
*
|
|
38
|
+
* `threshold` or more, highest first, at most `limit` new ones. What scores `threshold` or more is spread from as if
|
|
39
|
+
* linked, up to `MAX_HOPS` times, so one run reaches a member's chats in every messenger. A pair a link joins, or that
|
|
40
|
+
* was rejected once, is never proposed; a pending one is updated in place. People are matched by identity only. With `write: false`
|
|
38
41
|
* nothing is written.
|
|
39
42
|
*/
|
|
40
43
|
export declare const scanProjectLinks: (store: MessageStore, input: ScanInput) => Promise<ScanResult>;
|
|
@@ -20,6 +20,8 @@ export const DEFAULT_THRESHOLD = 0.5;
|
|
|
20
20
|
/** A person ↔ person scan keeps the old rule's reach: one weak signal is enough to ask the owner. */
|
|
21
21
|
export const PERSON_THRESHOLD = 0.3;
|
|
22
22
|
export const DEFAULT_LIMIT = 20;
|
|
23
|
+
/** How many times one scan spreads from what it found; a project's links are rarely more than a few steps apart. */
|
|
24
|
+
export const MAX_HOPS = 4;
|
|
23
25
|
const projectOf = async (store, reference) => {
|
|
24
26
|
const ref = await canonicalProjectRef(store, reference);
|
|
25
27
|
const entry = (await store.knowledge.vocabulary({ kind: "project" })).entries.find((one) => one.id === ref.slice(8));
|
|
@@ -57,8 +59,9 @@ const pairKey = ({ from, to, kind }) => `${from}\u0000${to}\u0000${kind}`;
|
|
|
57
59
|
export const combinedScore = (weights) => Math.round((1 - weights.reduce((left, weight) => left * (1 - weight), 1)) * 1000) / 1000;
|
|
58
60
|
/**
|
|
59
61
|
* Runs the scorers for one project over the sources named, combines their signals per pair, and proposes what scores
|
|
60
|
-
* `threshold` or more, highest first, at most `limit` new ones.
|
|
61
|
-
*
|
|
62
|
+
* `threshold` or more, highest first, at most `limit` new ones. What scores `threshold` or more is spread from as if
|
|
63
|
+
* linked, up to `MAX_HOPS` times, so one run reaches a member's chats in every messenger. A pair a link joins, or that
|
|
64
|
+
* was rejected once, is never proposed; a pending one is updated in place. People are matched by identity only. With `write: false`
|
|
62
65
|
* nothing is written.
|
|
63
66
|
*/
|
|
64
67
|
export const scanProjectLinks = async (store, input) => {
|
|
@@ -93,60 +96,28 @@ export const scanProjectLinks = async (store, input) => {
|
|
|
93
96
|
nameOnly: 0,
|
|
94
97
|
unresolved: 0,
|
|
95
98
|
};
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
skipped.unresolved++;
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const weight = Math.min(1, Math.max(0, candidate.weight));
|
|
116
|
-
const held = pairs.get(key) ?? { candidate, signals: new Map() };
|
|
117
|
-
const scorerId = `${scorer.id}@${scorer.version}`;
|
|
118
|
-
const before = held.signals.get(scorerId);
|
|
119
|
-
if (!before || before.weight < weight)
|
|
120
|
-
held.signals.set(scorerId, {
|
|
121
|
-
scorer: scorerId,
|
|
122
|
-
weight,
|
|
123
|
-
why: candidate.why.slice(0, 500),
|
|
124
|
-
...(candidate.purpose && scorerInput.purposes.includes(candidate.purpose)
|
|
125
|
-
? { purpose: candidate.purpose }
|
|
126
|
-
: {}),
|
|
127
|
-
});
|
|
128
|
-
held.candidate = {
|
|
129
|
-
...held.candidate,
|
|
130
|
-
evidence: [...new Set([...held.candidate.evidence, ...candidate.evidence])],
|
|
131
|
-
};
|
|
132
|
-
pairs.set(key, held);
|
|
133
|
-
}
|
|
99
|
+
const fixed = new Map();
|
|
100
|
+
const candidatesOf = async (scorer, seeds) => {
|
|
101
|
+
if (scorer.spreads)
|
|
102
|
+
return scorer.candidates({ ...scorerInput, confirmed: seeds });
|
|
103
|
+
const held = fixed.get(scorer) ?? (await scorer.candidates(scorerInput));
|
|
104
|
+
fixed.set(scorer, held);
|
|
105
|
+
return held;
|
|
106
|
+
};
|
|
107
|
+
let seeds = scorerInput.confirmed;
|
|
108
|
+
let collected = await collect(store, scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
|
|
109
|
+
for (let hop = 0; hop < MAX_HOPS && scorers.some((one) => one.spreads); hop++) {
|
|
110
|
+
const grown = await seedsOf(store, seeds, collected.scored, threshold);
|
|
111
|
+
if (!grown)
|
|
112
|
+
break;
|
|
113
|
+
seeds = grown;
|
|
114
|
+
collected = await collect(store, scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
|
|
134
115
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const list = [...signals.values()].sort((a, b) => b.weight - a.weight || a.scorer.localeCompare(b.scorer));
|
|
138
|
-
const purpose = list.find((one) => one.purpose)?.purpose;
|
|
139
|
-
return {
|
|
140
|
-
candidate,
|
|
141
|
-
purpose,
|
|
142
|
-
signals: list.map(({ scorer, weight, why }) => ({ scorer, weight, why })),
|
|
143
|
-
score: combinedScore(list.map((one) => one.weight)),
|
|
144
|
-
};
|
|
145
|
-
})
|
|
146
|
-
.sort((a, b) => b.score - a.score || a.candidate.from.localeCompare(b.candidate.from));
|
|
116
|
+
skipped.nameOnly = collected.nameOnly;
|
|
117
|
+
skipped.unresolved = collected.unresolved;
|
|
147
118
|
const proposals = [];
|
|
148
119
|
let fresh = 0;
|
|
149
|
-
for (const { candidate, purpose, signals, score } of scored) {
|
|
120
|
+
for (const { candidate, purpose, signals, score } of collected.scored) {
|
|
150
121
|
const state = await store.knowledge.relationState(null, candidate);
|
|
151
122
|
if (!state) {
|
|
152
123
|
skipped.unresolved++;
|
|
@@ -207,6 +178,80 @@ export const scanProjectLinks = async (store, input) => {
|
|
|
207
178
|
}
|
|
208
179
|
return { project: project?.ref ?? null, proposals, skipped };
|
|
209
180
|
};
|
|
181
|
+
/** Every scorer's candidates, combined per pair and scored, highest first. */
|
|
182
|
+
const collect = async (store, input, scorers, candidatesOf) => {
|
|
183
|
+
const pairs = new Map();
|
|
184
|
+
const nameOnly = new Set();
|
|
185
|
+
let unresolved = 0;
|
|
186
|
+
for (const scorer of scorers) {
|
|
187
|
+
input.signal?.throwIfAborted();
|
|
188
|
+
for (const candidate of await candidatesOf(scorer)) {
|
|
189
|
+
const key = pairKey(candidate);
|
|
190
|
+
const verdict = await admissible(store, input, candidate);
|
|
191
|
+
if (verdict === "owner")
|
|
192
|
+
continue;
|
|
193
|
+
if (verdict === "name-only") {
|
|
194
|
+
nameOnly.add(key);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (verdict !== "ok") {
|
|
198
|
+
unresolved++;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const weight = Math.min(1, Math.max(0, candidate.weight));
|
|
202
|
+
const held = pairs.get(key) ?? { candidate, signals: new Map() };
|
|
203
|
+
const scorerId = `${scorer.id}@${scorer.version}`;
|
|
204
|
+
const before = held.signals.get(scorerId);
|
|
205
|
+
if (!before || before.weight < weight)
|
|
206
|
+
held.signals.set(scorerId, {
|
|
207
|
+
scorer: scorerId,
|
|
208
|
+
weight,
|
|
209
|
+
why: candidate.why.slice(0, 500),
|
|
210
|
+
...(candidate.purpose && input.purposes.includes(candidate.purpose) ? { purpose: candidate.purpose } : {}),
|
|
211
|
+
});
|
|
212
|
+
held.candidate = {
|
|
213
|
+
...held.candidate,
|
|
214
|
+
evidence: [...new Set([...held.candidate.evidence, ...candidate.evidence])],
|
|
215
|
+
};
|
|
216
|
+
pairs.set(key, held);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const scored = [...pairs.values()]
|
|
220
|
+
.map(({ candidate, signals }) => {
|
|
221
|
+
const list = [...signals.values()].sort((a, b) => b.weight - a.weight || a.scorer.localeCompare(b.scorer));
|
|
222
|
+
const purpose = list.find((one) => one.purpose)?.purpose;
|
|
223
|
+
return {
|
|
224
|
+
candidate,
|
|
225
|
+
purpose,
|
|
226
|
+
signals: list.map(({ scorer, weight, why }) => ({ scorer, weight, why })),
|
|
227
|
+
score: combinedScore(list.map((one) => one.weight)),
|
|
228
|
+
};
|
|
229
|
+
})
|
|
230
|
+
.sort((a, b) => b.score - a.score || a.candidate.from.localeCompare(b.candidate.from));
|
|
231
|
+
return { scored, nameOnly: nameOnly.size, unresolved };
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* The links to spread from, grown by what scored `threshold` or more and was never rejected; `undefined` when
|
|
235
|
+
* nothing new was found. Spreading in one run reaches what the owner would otherwise confirm round after round.
|
|
236
|
+
*/
|
|
237
|
+
const seedsOf = async (store, seeds, scored, threshold) => {
|
|
238
|
+
const chats = new Set(seeds.chats);
|
|
239
|
+
const people = new Set(seeds.people);
|
|
240
|
+
const size = chats.size + people.size;
|
|
241
|
+
for (const { candidate, score } of scored) {
|
|
242
|
+
if (score < threshold || candidate.kind !== "member-of")
|
|
243
|
+
continue;
|
|
244
|
+
if (chats.has(candidate.from) || people.has(candidate.from))
|
|
245
|
+
continue;
|
|
246
|
+
if ((await store.knowledge.relationState(null, candidate))?.rejected !== false)
|
|
247
|
+
continue;
|
|
248
|
+
if (candidate.from.startsWith("chat:"))
|
|
249
|
+
chats.add(candidate.from);
|
|
250
|
+
else if (candidate.from.startsWith("person:"))
|
|
251
|
+
people.add(candidate.from);
|
|
252
|
+
}
|
|
253
|
+
return chats.size + people.size === size ? undefined : { chats: [...chats].sort(), people: [...people].sort() };
|
|
254
|
+
};
|
|
210
255
|
/** A person candidate stands only on an identity that is that person's; a chat only in a source the scan reads. */
|
|
211
256
|
const admissible = async (store, input, candidate) => {
|
|
212
257
|
if (candidate.from === candidate.to || !Number.isFinite(candidate.weight))
|
|
@@ -16,8 +16,8 @@ export declare const sameAccount: (a: AccountKey, b: {
|
|
|
16
16
|
}) => boolean;
|
|
17
17
|
/** The person an identity is, as `person:<uid>`; `undefined` when the store has no person for it. */
|
|
18
18
|
export declare const personRefOf: (store: MessageStore, provider: string, id: Id) => Promise<string | undefined>;
|
|
19
|
-
/** How many projects a person is a confirmed member of. */
|
|
20
|
-
export declare const projectsOf: (store: MessageStore, person: string) => Promise<number>;
|
|
19
|
+
/** How many projects a person is a confirmed member of, counting `project` whether confirmed or only found. */
|
|
20
|
+
export declare const projectsOf: (store: MessageStore, person: string, project: string) => Promise<number>;
|
|
21
21
|
/** Each confirmed member's identities in one messenger, by member. */
|
|
22
22
|
export declare const identitiesIn: (store: MessageStore, people: readonly string[], provider: string) => Promise<{
|
|
23
23
|
person: string;
|
|
@@ -30,10 +30,13 @@ export const personRefOf = async (store, provider, id) => {
|
|
|
30
30
|
const person = await store.people.personOf({ provider, id });
|
|
31
31
|
return person ? `person:${person.uid}` : undefined;
|
|
32
32
|
};
|
|
33
|
-
/** How many projects a person is a confirmed member of. */
|
|
34
|
-
export const projectsOf = async (store, person) => new Set(
|
|
35
|
-
|
|
36
|
-
.
|
|
33
|
+
/** How many projects a person is a confirmed member of, counting `project` whether confirmed or only found. */
|
|
34
|
+
export const projectsOf = async (store, person, project) => new Set([
|
|
35
|
+
project,
|
|
36
|
+
...(await store.knowledge.relations(null, person))
|
|
37
|
+
.filter((one) => one.confirmed && one.kind === "member-of" && one.from === person && one.to.startsWith("project:"))
|
|
38
|
+
.map((one) => one.to),
|
|
39
|
+
]).size;
|
|
37
40
|
/** Each confirmed member's identities in one messenger, by member. */
|
|
38
41
|
export const identitiesIn = async (store, people, provider) => {
|
|
39
42
|
const found = [];
|
|
@@ -31,6 +31,7 @@ export interface ScorerInput {
|
|
|
31
31
|
store: MessageStore;
|
|
32
32
|
/** `null` for a scan with no project, which only person ↔ person rules answer. */
|
|
33
33
|
project: ScannedProject | null;
|
|
34
|
+
/** The project's confirmed chats and people, and, within one scan, what the scan already found above threshold. */
|
|
34
35
|
confirmed: {
|
|
35
36
|
chats: string[];
|
|
36
37
|
people: string[];
|
|
@@ -48,6 +49,8 @@ export interface ScorerInput {
|
|
|
48
49
|
export interface LinkScorer {
|
|
49
50
|
readonly id: string;
|
|
50
51
|
readonly version: number;
|
|
52
|
+
/** Reads `confirmed`, so a scan runs it again each time the links it spreads from grow. */
|
|
53
|
+
readonly spreads?: boolean;
|
|
51
54
|
candidates(input: ScorerInput): Promise<LinkCandidate[]>;
|
|
52
55
|
}
|
|
53
56
|
export type Signal = NonNullable<ProposalRow["signals"]>[number];
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
+
error?: undefined;
|
|
17
18
|
chatId: string;
|
|
18
19
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
19
20
|
algorithm: string;
|
|
20
21
|
fetchedAt: string | null;
|
|
21
22
|
source: string;
|
|
22
|
-
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
|
@@ -4,6 +4,8 @@ export interface ModelDownloadOptions {
|
|
|
4
4
|
env: NodeJS.ProcessEnv;
|
|
5
5
|
/** One line at a time: the size before the download, its progress, then the check. */
|
|
6
6
|
progress?: (line: string) => void;
|
|
7
|
+
/** The model's bytes in place so far, of its total; not the ONNX Runtime fetched after it. */
|
|
8
|
+
bytes?: (done: number, total: number) => void;
|
|
7
9
|
}
|
|
8
10
|
export interface DownloadedModel<M> {
|
|
9
11
|
model: M;
|
|
@@ -13,10 +15,10 @@ export interface DownloadedModel<M> {
|
|
|
13
15
|
* The text embedding model into the shared models folder, checked against the sha256 this version expects and
|
|
14
16
|
* loaded once on a word. Nothing is downloaded when it is already there; it is still loaded.
|
|
15
17
|
*/
|
|
16
|
-
export declare const downloadTextModel: (id: string, { env, progress, acceptTerms }: ModelDownloadOptions & {
|
|
18
|
+
export declare const downloadTextModel: (id: string, { env, progress, bytes, acceptTerms }: ModelDownloadOptions & {
|
|
17
19
|
acceptTerms?: boolean;
|
|
18
20
|
}) => Promise<DownloadedModel<TextModel>>;
|
|
19
21
|
/** A reranker, the same way as {@link downloadTextModel}, into the same folder. */
|
|
20
|
-
export declare const downloadRerankModel: (id: string, { env, progress }: ModelDownloadOptions) => Promise<DownloadedModel<RerankModel>>;
|
|
22
|
+
export declare const downloadRerankModel: (id: string, { env, progress, bytes }: ModelDownloadOptions) => Promise<DownloadedModel<RerankModel>>;
|
|
21
23
|
/** The picture model, the same way as {@link downloadTextModel}. */
|
|
22
|
-
export declare const downloadImageModel: (id: string, { env, progress }: ModelDownloadOptions) => Promise<DownloadedModel<ImageModel>>;
|
|
24
|
+
export declare const downloadImageModel: (id: string, { env, progress, bytes }: ModelDownloadOptions) => Promise<DownloadedModel<ImageModel>>;
|
|
@@ -21,7 +21,7 @@ const nativeRuntime = async ({ env, progress = () => { } }) => {
|
|
|
21
21
|
* The text embedding model into the shared models folder, checked against the sha256 this version expects and
|
|
22
22
|
* loaded once on a word. Nothing is downloaded when it is already there; it is still loaded.
|
|
23
23
|
*/
|
|
24
|
-
export const downloadTextModel = async (id, { env, progress = () => { }, acceptTerms = false }) => {
|
|
24
|
+
export const downloadTextModel = async (id, { env, progress = () => { }, bytes, acceptTerms = false }) => {
|
|
25
25
|
const model = textModel(id);
|
|
26
26
|
if (model.terms && !acceptTerms) {
|
|
27
27
|
throw new CliError("validation_error", `${model.id} comes under the ${model.licence} (${model.terms}): read them, then run this again with --accept-terms`);
|
|
@@ -29,7 +29,7 @@ export const downloadTextModel = async (id, { env, progress = () => { }, acceptT
|
|
|
29
29
|
const directory = textModelsDirectory(env);
|
|
30
30
|
if (!isTextModelInstalled(model, directory)) {
|
|
31
31
|
progress(`${model.id}: ${megabytes(bytesOf(model))} from Hugging Face`);
|
|
32
|
-
await installFiles(placedText(model, directory), { progress });
|
|
32
|
+
await installFiles(placedText(model, directory), { progress, ...(bytes ? { bytes } : {}) });
|
|
33
33
|
}
|
|
34
34
|
await nativeRuntime({ env, progress });
|
|
35
35
|
progress(`${model.id}: loading it once to check it works`);
|
|
@@ -46,12 +46,12 @@ export const downloadTextModel = async (id, { env, progress = () => { }, acceptT
|
|
|
46
46
|
return { model, directory };
|
|
47
47
|
};
|
|
48
48
|
/** A reranker, the same way as {@link downloadTextModel}, into the same folder. */
|
|
49
|
-
export const downloadRerankModel = async (id, { env, progress = () => { } }) => {
|
|
49
|
+
export const downloadRerankModel = async (id, { env, progress = () => { }, bytes }) => {
|
|
50
50
|
const model = rerankModel(id);
|
|
51
51
|
const directory = textModelsDirectory(env);
|
|
52
52
|
if (!isTextModelInstalled(model, directory)) {
|
|
53
53
|
progress(`${model.id}: ${megabytes(bytesOf(model))} from Hugging Face`);
|
|
54
|
-
await installFiles(placedText(model, directory), { progress });
|
|
54
|
+
await installFiles(placedText(model, directory), { progress, ...(bytes ? { bytes } : {}) });
|
|
55
55
|
}
|
|
56
56
|
await nativeRuntime({ env, progress });
|
|
57
57
|
progress(`${model.id}: loading it once to check it works`);
|
|
@@ -66,12 +66,12 @@ export const downloadRerankModel = async (id, { env, progress = () => { } }) =>
|
|
|
66
66
|
return { model, directory };
|
|
67
67
|
};
|
|
68
68
|
/** The picture model, the same way as {@link downloadTextModel}. */
|
|
69
|
-
export const downloadImageModel = async (id, { env, progress = () => { } }) => {
|
|
69
|
+
export const downloadImageModel = async (id, { env, progress = () => { }, bytes }) => {
|
|
70
70
|
const model = imageModel(id);
|
|
71
71
|
const directory = imageModelsDirectory(env);
|
|
72
72
|
if (!isImageModelInstalled(model, directory)) {
|
|
73
73
|
progress(`${model.id}: ${megabytes(bytesOf(model))} from Hugging Face`);
|
|
74
|
-
await installFiles(placedImage(model, directory), { progress });
|
|
74
|
+
await installFiles(placedImage(model, directory), { progress, ...(bytes ? { bytes } : {}) });
|
|
75
75
|
}
|
|
76
76
|
progress(`${model.id}: loading it once to check it works`);
|
|
77
77
|
const { openPictureEmbedder } = await import("../images/picture/embedder.js");
|
|
@@ -420,11 +420,13 @@ export const searchNotes = async (store, query, { limit = 20, offset = 0, tag, f
|
|
|
420
420
|
const held = ranked.get(ref) ?? { note, at, score: 0, foundBy: [] };
|
|
421
421
|
held.foundBy.push(by);
|
|
422
422
|
ranked.set(ref, held);
|
|
423
|
+
const vote = 1 / (RRF_K + rank + 1);
|
|
423
424
|
// A question's any-word list holds nearly every note meaning finds; a second vote there buried notes found by
|
|
424
425
|
// words alone (recall@10 0.55 against 1.00, cli-testing knowledge-graph-memory, MEMO-36).
|
|
425
426
|
if (by === "meaning" && lookup !== undefined && held.foundBy.includes("words"))
|
|
426
|
-
|
|
427
|
-
|
|
427
|
+
held.score = Math.max(held.score, vote);
|
|
428
|
+
else
|
|
429
|
+
held.score += vote;
|
|
428
430
|
});
|
|
429
431
|
add(matched.items, "words");
|
|
430
432
|
if (meaning !== undefined)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChatKind, Id, Message, Provider } from "../domain/models.js";
|
|
2
|
-
import type { AccountKey, IdentityRef, LinkedIdentity, MessageStore, PersonRecord } from "../store/store.js";
|
|
2
|
+
import type { AccountKey, IdentityRef, LinkedIdentity, MessageStore, PersonRecord, StoredAccount } from "../store/store.js";
|
|
3
3
|
export declare const CONTEXT_MESSAGES = 10;
|
|
4
4
|
export declare const CONTEXT_BYTES: number;
|
|
5
5
|
export interface ContextMessage {
|
|
@@ -37,11 +37,16 @@ export interface ContextEvent {
|
|
|
37
37
|
}
|
|
38
38
|
/** `not_fetched`: nothing of its history was ever read into the store; `partial`: only some of it was. */
|
|
39
39
|
export type NotReadReason = "not_fetched" | "partial";
|
|
40
|
+
export type AccountScope = StoredAccount["scope"];
|
|
40
41
|
export interface PersonContext {
|
|
41
42
|
person: PersonRecord & {
|
|
42
43
|
provider: Provider;
|
|
43
44
|
id: Id;
|
|
44
45
|
};
|
|
46
|
+
/** Every account read, with its scope: only accounts of the scopes the caller may read. */
|
|
47
|
+
accounts: (AccountKey & {
|
|
48
|
+
scope: AccountScope;
|
|
49
|
+
})[];
|
|
45
50
|
shared: SharedChat[];
|
|
46
51
|
/** Each way, the newest in a messenger dialog whatever `limits` says; mail only within them. */
|
|
47
52
|
last: {
|
|
@@ -78,15 +83,23 @@ export interface ContextOptions {
|
|
|
78
83
|
since?: number;
|
|
79
84
|
/** ms: what splits upcoming events from past ones; the clock when absent. */
|
|
80
85
|
now?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The account scopes read; the asked account's own scope when absent. One exact email address joins a personal
|
|
88
|
+
* and a work contact into one person, so a personal account must not read that person's work mail by default.
|
|
89
|
+
*/
|
|
90
|
+
scopes?: readonly AccountScope[];
|
|
81
91
|
}
|
|
82
92
|
export declare const toContext: (key: AccountKey, message: Message, chatTitle: string | null) => ContextMessage;
|
|
93
|
+
/** The stored accounts of `scopes`, or of the asked account's own scope; the asked account must be stored. */
|
|
94
|
+
export declare const readableAccounts: (store: MessageStore, asked: AccountKey, scopes?: readonly AccountScope[]) => Promise<StoredAccount[]>;
|
|
83
95
|
/**
|
|
84
|
-
* The accounts each identity is read in: for the messenger asked, only the account asked
|
|
85
|
-
* second account of the same messenger is somebody else's view; for a linked messenger, every
|
|
86
|
-
* of this store that saw that identity.
|
|
96
|
+
* The accounts each identity is read in, among `readable` only: for the messenger asked, only the account asked
|
|
97
|
+
* about — a second account of the same messenger is somebody else's view; for a linked messenger, every readable
|
|
98
|
+
* account of this store that saw that identity.
|
|
87
99
|
*/
|
|
88
|
-
export declare const readsOf: (record: PersonRecord, asked: AccountKey) => {
|
|
100
|
+
export declare const readsOf: (record: PersonRecord, asked: AccountKey, readable: readonly StoredAccount[]) => {
|
|
89
101
|
key: AccountKey;
|
|
102
|
+
scope: AccountScope;
|
|
90
103
|
identity: LinkedIdentity;
|
|
91
104
|
}[];
|
|
92
105
|
/**
|
|
@@ -94,11 +107,15 @@ export declare const readsOf: (record: PersonRecord, asked: AccountKey) => {
|
|
|
94
107
|
* only: nothing is fetched, nothing marked read. Identity is by id, never by name.
|
|
95
108
|
*/
|
|
96
109
|
export declare const personContext: (store: MessageStore, asked: AccountKey, reference: string, options?: ContextOptions) => Promise<PersonContext>;
|
|
97
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* `personContext` of a person already found, read in the identities and accounts `reads` names; their calendar
|
|
112
|
+
* events in every calendar account of `readable`.
|
|
113
|
+
*/
|
|
98
114
|
export declare const recordContext: (store: MessageStore, record: PersonRecord, reads: {
|
|
99
115
|
key: AccountKey;
|
|
116
|
+
scope: AccountScope;
|
|
100
117
|
identity: LinkedIdentity;
|
|
101
|
-
}[], { messages, bytes, since, now }?: ContextOptions) => Promise<Omit<PersonContext, "person">>;
|
|
118
|
+
}[], readable: readonly StoredAccount[], { messages, bytes, since, now }?: ContextOptions) => Promise<Omit<PersonContext, "person">>;
|
|
102
119
|
/** `max:Ana` names a person in another messenger of this store; a reference with no prefix, this one. */
|
|
103
120
|
export declare const identityIn: (store: MessageStore, asked: AccountKey, reference: string) => Promise<IdentityRef>;
|
|
104
121
|
export declare const CHAT_MESSAGES = 20;
|
|
@@ -80,14 +80,30 @@ const eventsOnce = async (store, filter, limit) => {
|
|
|
80
80
|
}
|
|
81
81
|
return { items, cut: true };
|
|
82
82
|
};
|
|
83
|
+
const nameOf = ({ provider, account }) => `${provider}:${account}`;
|
|
84
|
+
/** The stored accounts of `scopes`, or of the asked account's own scope; the asked account must be stored. */
|
|
85
|
+
export const readableAccounts = async (store, asked, scopes) => {
|
|
86
|
+
const stored = await store.accounts.storedAccounts();
|
|
87
|
+
const own = stored.find((one) => nameOf(one) === nameOf(asked));
|
|
88
|
+
if (!own || (asked.scope !== undefined && asked.scope !== own.scope))
|
|
89
|
+
throw new CliError("not_found", `no ${asked.provider} account ${asked.account} in the store`);
|
|
90
|
+
const allowed = scopes ?? [own.scope];
|
|
91
|
+
return stored.filter((one) => allowed.includes(one.scope));
|
|
92
|
+
};
|
|
83
93
|
/**
|
|
84
|
-
* The accounts each identity is read in: for the messenger asked, only the account asked
|
|
85
|
-
* second account of the same messenger is somebody else's view; for a linked messenger, every
|
|
86
|
-
* of this store that saw that identity.
|
|
94
|
+
* The accounts each identity is read in, among `readable` only: for the messenger asked, only the account asked
|
|
95
|
+
* about — a second account of the same messenger is somebody else's view; for a linked messenger, every readable
|
|
96
|
+
* account of this store that saw that identity.
|
|
87
97
|
*/
|
|
88
|
-
export const readsOf = (record, asked
|
|
89
|
-
.
|
|
90
|
-
.
|
|
98
|
+
export const readsOf = (record, asked, readable) => {
|
|
99
|
+
const scopeOf = new Map(readable.map((one) => [nameOf(one), one.scope]));
|
|
100
|
+
return record.identities.flatMap((identity) => (identity.provider === asked.provider ? [asked.account] : identity.accounts).flatMap((account) => {
|
|
101
|
+
const scope = scopeOf.get(nameOf({ provider: identity.provider, account }));
|
|
102
|
+
return identity.accounts.includes(account) && scope !== undefined
|
|
103
|
+
? [{ key: { provider: identity.provider, account }, scope, identity }]
|
|
104
|
+
: [];
|
|
105
|
+
}));
|
|
106
|
+
};
|
|
91
107
|
/**
|
|
92
108
|
* What the store knows about one person, across every identity linked to them. Reads the store
|
|
93
109
|
* only: nothing is fetched, nothing marked read. Identity is by id, never by name.
|
|
@@ -97,13 +113,17 @@ export const personContext = async (store, asked, reference, options = {}) => {
|
|
|
97
113
|
const record = await store.people.personOf({ provider: asked.provider, id: found.id });
|
|
98
114
|
if (!record)
|
|
99
115
|
throw new CliError("not_found", `no person ${found.id} in the store`);
|
|
116
|
+
const readable = await readableAccounts(store, asked, options.scopes);
|
|
100
117
|
return {
|
|
101
118
|
person: { ...record, provider: asked.provider, id: found.id },
|
|
102
|
-
...(await recordContext(store, record, readsOf(record, asked), options)),
|
|
119
|
+
...(await recordContext(store, record, readsOf(record, asked, readable), readable, options)),
|
|
103
120
|
};
|
|
104
121
|
};
|
|
105
|
-
/**
|
|
106
|
-
|
|
122
|
+
/**
|
|
123
|
+
* `personContext` of a person already found, read in the identities and accounts `reads` names; their calendar
|
|
124
|
+
* events in every calendar account of `readable`.
|
|
125
|
+
*/
|
|
126
|
+
export const recordContext = async (store, record, reads, readable, { messages = CONTEXT_MESSAGES, bytes = CONTEXT_BYTES, since, now = Date.now() } = {}) => {
|
|
107
127
|
const recent = (message) => since === undefined || Date.parse(message.timestamp) >= since;
|
|
108
128
|
const shared = [];
|
|
109
129
|
const notRead = [];
|
|
@@ -165,9 +185,17 @@ export const recordContext = async (store, record, reads, { messages = CONTEXT_M
|
|
|
165
185
|
cut ||= named.hasMore;
|
|
166
186
|
}
|
|
167
187
|
const personId = Number(record.uid);
|
|
168
|
-
const
|
|
188
|
+
const calendars = [];
|
|
189
|
+
for (const one of readable)
|
|
190
|
+
if ((await store.calendar.calendars(one.id)).length)
|
|
191
|
+
calendars.push(one);
|
|
192
|
+
const accountIds = calendars.map(({ id }) => id);
|
|
193
|
+
const nothing = { items: [], cut: false };
|
|
194
|
+
const upcoming = accountIds.length ? await eventsOnce(store, { personId, accountIds, from: now }, messages) : nothing;
|
|
169
195
|
const upcomingIds = new Set(upcoming.items.map(({ id }) => id));
|
|
170
|
-
const past =
|
|
196
|
+
const past = accountIds.length
|
|
197
|
+
? await eventsOnce(store, { personId, accountIds, to: now, newest: true, ...(since === undefined ? {} : { from: since }) }, messages)
|
|
198
|
+
: nothing;
|
|
171
199
|
cut ||= upcoming.cut || past.cut;
|
|
172
200
|
direct.sort(newestFirst);
|
|
173
201
|
const each = [...direct, ...beyond].sort(newestFirst);
|
|
@@ -183,7 +211,13 @@ export const recordContext = async (store, record, reads, { messages = CONTEXT_M
|
|
|
183
211
|
};
|
|
184
212
|
cut ||= direct.length > messages || groups.length > messages || mentions.length > messages;
|
|
185
213
|
const kept = withinBytes(lists, bytes);
|
|
214
|
+
const read = [
|
|
215
|
+
...reads.map(({ key, scope }) => ({ ...key, scope })),
|
|
216
|
+
...calendars.map(({ provider, account, scope }) => ({ provider, account, scope })),
|
|
217
|
+
];
|
|
218
|
+
const accounts = [...new Map(read.map((one) => [nameOf(one), one])).values()].sort((a, b) => nameOf(a).localeCompare(nameOf(b)));
|
|
186
219
|
return {
|
|
220
|
+
accounts,
|
|
187
221
|
shared: shared.sort((a, b) => Date.parse(b.lastMessageAt ?? "") - Date.parse(a.lastMessageAt ?? "")),
|
|
188
222
|
last: {
|
|
189
223
|
fromThem: each.find((message) => !message.outgoing) ?? null,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseMeetingReference } from "../meetings/index.js";
|
|
3
|
-
import { CONTEXT_BYTES, CONTEXT_MESSAGES, personContext,
|
|
3
|
+
import { CONTEXT_BYTES, CONTEXT_MESSAGES, personContext, readableAccounts, toContext, } from "./person-context.js";
|
|
4
4
|
import { personMeetingContext } from "./person-meeting-context.js";
|
|
5
5
|
export const PREPARE_BYTES = 96 * 1024;
|
|
6
6
|
const MEETINGS = 5;
|
|
@@ -34,7 +34,6 @@ export const personPreparation = async (store, asked, reference, options = {}) =
|
|
|
34
34
|
coverage: { included: items.length, hasMore: over || cut, cutBy: cut ? "bytes" : over ? "limit" : null },
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
const reads = readsOf(context.person, asked);
|
|
38
37
|
const partial = new Set(context.notRead.map((chat) => `${chat.provider}/${chat.account}/${chat.chatId}`));
|
|
39
38
|
const waiting = [];
|
|
40
39
|
for (const chat of context.shared.filter((one) => one.kind === "dialog")) {
|
|
@@ -51,10 +50,10 @@ export const personPreparation = async (store, asked, reference, options = {}) =
|
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
waiting.sort((a, b) => Date.parse(b.message.timestamp) - Date.parse(a.message.timestamp));
|
|
54
|
-
const accounts =
|
|
53
|
+
const accounts = context.accounts.map(({ provider, account }) => ({ provider, account }));
|
|
55
54
|
const held = await store.people.preparation(context.person.uid, { accounts, limit });
|
|
56
|
-
const
|
|
57
|
-
const meetings = await meetingsOf(store, context.person.uid,
|
|
55
|
+
const readable = await readableAccounts(store, asked, options.scopes);
|
|
56
|
+
const meetings = await meetingsOf(store, context.person.uid, readable, options.since, () => left);
|
|
58
57
|
const sections = {
|
|
59
58
|
waiting: budgeted({ items: waiting, hasMore: false }),
|
|
60
59
|
tasks: budgeted(held.tasks),
|
|
@@ -44,9 +44,15 @@ export interface SearchedAccount {
|
|
|
44
44
|
account: string;
|
|
45
45
|
}
|
|
46
46
|
/** A resource not read, or a `--source` entry naming no account the search reads. */
|
|
47
|
+
/**
|
|
48
|
+
* `reason` is the sentence for a person; `code` and `why` (a dotted reason such as `query.unknown-value`) are for a
|
|
49
|
+
* program, and `token` is the part of the query the source refused, when the refusal points at one.
|
|
50
|
+
*/
|
|
47
51
|
export type Skipped<R extends string> = {
|
|
48
52
|
code: ErrorCode;
|
|
49
53
|
reason: string;
|
|
54
|
+
why?: string;
|
|
55
|
+
token?: string;
|
|
50
56
|
} & ({
|
|
51
57
|
resource: R;
|
|
52
58
|
source?: undefined;
|