@wirecat/cli-core 0.622.0 → 0.624.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 +108 -0
- package/dist/background/backfill.d.ts +1 -1
- package/dist/background/backfill.js +1 -1
- package/dist/background/budget.d.ts +2 -0
- package/dist/background/report/stored-templates.d.ts +21 -3
- package/dist/background/report/stored-templates.js +34 -6
- package/dist/background/schedules.d.ts +10 -27
- package/dist/background/schedules.js +8 -167
- package/dist/background/timers.d.ts +19 -0
- package/dist/background/timers.js +175 -0
- package/dist/background/when.d.ts +49 -0
- package/dist/background/when.js +84 -0
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/calendar/prepare.d.ts +14 -0
- package/dist/cli/app-doctor-command.js +2 -1
- package/dist/cli/envelope.d.ts +28 -0
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.js +3 -2
- package/dist/cli/messenger/messages-search-command.js +4 -0
- package/dist/cli/program.js +6 -3
- package/dist/cli/schedule/schedule-command.d.ts +100 -3
- package/dist/cli/schedule/schedule-command.js +277 -113
- package/dist/cli/templates-command.js +45 -20
- package/dist/domain/display-names.d.ts +19 -0
- package/dist/domain/display-names.js +59 -0
- package/dist/domain/person-kinds.d.ts +9 -0
- package/dist/domain/person-kinds.js +67 -0
- package/dist/entities/index.d.ts +2 -1
- package/dist/entities/list-results.d.ts +2 -0
- package/dist/entities/list-results.js +2 -0
- package/dist/entities/template.d.ts +1 -1
- package/dist/entities/template.js +1 -1
- package/dist/errors/reasons.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/surface.js +23 -2
- package/dist/search/lucene/resolved.d.ts +1 -0
- package/dist/search/lucene/types.d.ts +8 -0
- package/dist/search/lucene/types.js +7 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/messages-combined.js +3 -2
- package/dist/services/messages-discovery.js +3 -2
- package/dist/services/messages-search.js +1 -0
- package/dist/services/messages.d.ts +2 -0
- package/dist/services/people.js +1 -1
- package/dist/services/search-harder.d.ts +6 -1
- package/dist/services/search-harder.js +9 -2
- package/dist/store/identity-links.d.ts +3 -3
- package/dist/store/identity-links.js +3 -3
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.js +3 -0
- package/dist/store/people.d.ts +21 -2
- package/dist/store/people.js +35 -15
- package/dist/store/sqlite/lucene.js +12 -11
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/migrations.generated.js +7 -0
- package/dist/store/sqlite/name-traces.d.ts +17 -0
- package/dist/store/sqlite/name-traces.js +112 -0
- package/dist/store/sqlite/notes.js +6 -3
- package/dist/store/sqlite/people-list.d.ts +59 -0
- package/dist/store/sqlite/people-list.js +275 -0
- package/dist/store/sqlite/person-match-scan.js +33 -0
- package/dist/store/sqlite/person-ties.d.ts +14 -0
- package/dist/store/sqlite/person-ties.js +66 -0
- package/dist/store/sqlite/schema.d.ts +16 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/package.json +3 -3
- package/parity.json +29 -0
|
@@ -2,19 +2,20 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { CliError
|
|
5
|
+
import { CliError } from "@wirecat/cli-base";
|
|
6
6
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
7
7
|
import { queryFieldsOf } from "@wirecat/cli-base/query";
|
|
8
8
|
import { Command, Option } from "commander";
|
|
9
9
|
import { checkTemplate, defaultTemplate, REPORT_CHANNELS, renderReport, } from "../background/report/render.js";
|
|
10
|
-
import { checkTemplateSave, previewView, shippedLanguages, TEMPLATE_KEYS, templateKeyOf, } from "../background/report/stored-templates.js";
|
|
10
|
+
import { checkTemplateSave, previewView, reportKeyOf, reportKeysOf, shippedLanguages, TEMPLATE_KEYS, templateKeyOf, } from "../background/report/stored-templates.js";
|
|
11
|
+
import { listSchedules } from "../background/schedules.js";
|
|
11
12
|
import { template } from "../entities/index.js";
|
|
12
13
|
import { agentOf } from "../runs/run-context.js";
|
|
13
14
|
import { openStore } from "../store/store.js";
|
|
14
15
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
15
16
|
import { itemOf, listOf } from "./envelope.js";
|
|
16
17
|
import { queryTerms, withQuery } from "./list-query.js";
|
|
17
|
-
import { ownerLanguageOf } from "./schedule/schedule-command.js";
|
|
18
|
+
import { ownerLanguageOf, scheduleState } from "./schedule/schedule-command.js";
|
|
18
19
|
const withStore = async (env, work) => {
|
|
19
20
|
const store = await openStore({ env });
|
|
20
21
|
try {
|
|
@@ -53,18 +54,32 @@ const TEMPLATES_QUERY = {
|
|
|
53
54
|
};
|
|
54
55
|
const matching = (rows, terms) => rows.filter((row) => [...terms].every(([field, value]) => String(row[field]).toLowerCase() === value.toLowerCase()));
|
|
55
56
|
/** The key, its message kind and the language, refused when cli-core ships no template in that language. */
|
|
56
|
-
const addressOf = async (key, given, env) => {
|
|
57
|
-
const known = templateKeyOf(key)
|
|
57
|
+
const addressOf = async (key, given, env, state) => {
|
|
58
|
+
const known = templateKeyOf(key) ??
|
|
59
|
+
reportKeyOf(key, [
|
|
60
|
+
...listSchedules(state, { kind: "agent" }).map((one) => one.name),
|
|
61
|
+
// A removed schedule's templates stay in the store, and must still be shown and reset.
|
|
62
|
+
...(await withStore(env, (store) => store.templates.list())).flatMap((row) => row.key.startsWith("report/") ? [row.key.slice("report/".length)] : []),
|
|
63
|
+
]);
|
|
58
64
|
if (!known)
|
|
59
|
-
throw new CliError("validation_error", `no template ${key}; the keys are ${TEMPLATE_KEYS.map((one) => one.key).join(", ")}`, {
|
|
65
|
+
throw new CliError("validation_error", `no template ${key}; the keys are ${TEMPLATE_KEYS.map((one) => one.key).join(", ")}, or report/<schedule> for an agent schedule's digest`, {
|
|
60
66
|
reason: "template.unknown-key",
|
|
61
67
|
});
|
|
62
68
|
const language = (given.locale ?? (await ownerLanguageOf(env))).trim().toLowerCase();
|
|
63
69
|
const languages = shippedLanguages(known.kind);
|
|
64
70
|
if (!languages.includes(language))
|
|
65
71
|
throw new CliError("validation_error", `${key} has templates in ${languages.join(", ")}; a ${language} one would never be used`, { reason: "template.unknown-language" });
|
|
66
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
address: { key, channel: given.channel, language },
|
|
74
|
+
kind: known.kind,
|
|
75
|
+
channel: given.channel,
|
|
76
|
+
...(known.schedule ? { schedule: known.schedule } : {}),
|
|
77
|
+
};
|
|
67
78
|
};
|
|
79
|
+
/** The stored body that applies to `address`: its own, else the one its digest falls back to; undefined for shipped. */
|
|
80
|
+
const appliedBody = (store, address, kind, schedule) => reportKeysOf(kind, schedule)
|
|
81
|
+
.map((key) => store.templates.get({ ...address, key })?.body)
|
|
82
|
+
.find((body) => body !== undefined);
|
|
68
83
|
const refuseAgent = (env) => {
|
|
69
84
|
// A template decides what every later digest says to the owner; an agent could make it hide or invent things.
|
|
70
85
|
if (agentOf(env))
|
|
@@ -72,7 +87,7 @@ const refuseAgent = (env) => {
|
|
|
72
87
|
reason: "template.owner-only",
|
|
73
88
|
});
|
|
74
89
|
};
|
|
75
|
-
const stateOf = (app, env) =>
|
|
90
|
+
const stateOf = (app, env) => scheduleState({ app, env });
|
|
76
91
|
const historyOf = (store, address) => store.templates.history(address).map((entry) => ({
|
|
77
92
|
id: entry.id,
|
|
78
93
|
saved_at: new Date(entry.savedAt).toISOString(),
|
|
@@ -100,15 +115,21 @@ export const templatesCommand = (app, options) => {
|
|
|
100
115
|
const terms = queryTerms(words, TEMPLATES_QUERY, "templates list");
|
|
101
116
|
const env = options.env();
|
|
102
117
|
const stored = await withStore(env, (store) => store.templates.list());
|
|
103
|
-
const
|
|
104
|
-
const
|
|
118
|
+
const own = [...new Set(stored.map((one) => one.key))].flatMap((key) => {
|
|
119
|
+
const known = reportKeyOf(key, [key.slice("report/".length)]);
|
|
120
|
+
return known?.schedule ? [known] : [];
|
|
121
|
+
});
|
|
122
|
+
const items = [...TEMPLATE_KEYS, ...own].flatMap((known) => REPORT_CHANNELS.flatMap((channel) => shippedLanguages(known.kind).map((language) => {
|
|
123
|
+
const rowOf = (key) => stored.find((one) => one.key === key && one.channel === channel && one.language === language);
|
|
124
|
+
const row = rowOf(known.key);
|
|
125
|
+
const inherited = !row && "schedule" in known && reportKeysOf(known.kind, known.schedule).some((key) => rowOf(key));
|
|
105
126
|
return {
|
|
106
127
|
key: known.key,
|
|
107
128
|
channel,
|
|
108
129
|
language,
|
|
109
130
|
about: known.about,
|
|
110
131
|
renders: true,
|
|
111
|
-
source: row ? "stored" : "default",
|
|
132
|
+
source: row ? "stored" : inherited ? "inherited" : "default",
|
|
112
133
|
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
113
134
|
updated_by: row?.updatedBy ?? null,
|
|
114
135
|
};
|
|
@@ -127,13 +148,14 @@ export const templatesCommand = (app, options) => {
|
|
|
127
148
|
.addOption(localeOption())
|
|
128
149
|
.action(async function (key, given) {
|
|
129
150
|
const env = options.env();
|
|
130
|
-
const { address, kind, channel } = await addressOf(key, given, env);
|
|
151
|
+
const { address, kind, channel, schedule } = await addressOf(key, given, env, stateOf(app, env));
|
|
131
152
|
const item = await withStore(env, (store) => {
|
|
132
153
|
const row = store.templates.get(address);
|
|
154
|
+
const applied = appliedBody(store, address, kind, schedule);
|
|
133
155
|
return {
|
|
134
156
|
...address,
|
|
135
|
-
source: row ? "stored" : "default",
|
|
136
|
-
body:
|
|
157
|
+
source: row ? "stored" : applied === undefined ? "default" : "inherited",
|
|
158
|
+
body: applied ?? defaultTemplate(kind, channel, address.language),
|
|
137
159
|
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
138
160
|
updated_by: row?.updatedBy ?? null,
|
|
139
161
|
history: historyOf(store, address),
|
|
@@ -159,9 +181,9 @@ export const templatesCommand = (app, options) => {
|
|
|
159
181
|
.action(async function (key, given) {
|
|
160
182
|
const env = options.env();
|
|
161
183
|
refuseAgent(env);
|
|
162
|
-
const { address, kind, channel } = await addressOf(key, given, env);
|
|
184
|
+
const { address, kind, channel, schedule } = await addressOf(key, given, env, stateOf(app, env));
|
|
163
185
|
const { current, previous } = await withStore(env, (store) => ({
|
|
164
|
-
current: store
|
|
186
|
+
current: appliedBody(store, address, kind, schedule),
|
|
165
187
|
previous: store.templates.history(address, 1)[0]?.body,
|
|
166
188
|
}));
|
|
167
189
|
const effective = current ?? defaultTemplate(kind, channel, address.language);
|
|
@@ -197,6 +219,7 @@ export const templatesCommand = (app, options) => {
|
|
|
197
219
|
body,
|
|
198
220
|
state: stateOf(app, env),
|
|
199
221
|
now: Date.now(),
|
|
222
|
+
...(schedule ? { schedule } : {}),
|
|
200
223
|
});
|
|
201
224
|
const problems = checks.flatMap((check) => check.problems.map((problem) => `${check.against}: ${problem}`));
|
|
202
225
|
if (problems.length > 0)
|
|
@@ -228,10 +251,12 @@ export const templatesCommand = (app, options) => {
|
|
|
228
251
|
.option("--file <file>", "preview this draft instead of the template that applies; - reads stdin")
|
|
229
252
|
.action(async function (key, given) {
|
|
230
253
|
const env = options.env();
|
|
231
|
-
const { address, kind, channel } = await addressOf(key, given, env);
|
|
232
|
-
const stored = given.file === undefined
|
|
254
|
+
const { address, kind, channel, schedule } = await addressOf(key, given, env, stateOf(app, env));
|
|
255
|
+
const stored = given.file === undefined
|
|
256
|
+
? await withStore(env, (store) => appliedBody(store, address, kind, schedule))
|
|
257
|
+
: undefined;
|
|
233
258
|
const body = given.file === undefined ? stored : readFileSync(given.file === "-" ? 0 : given.file, "utf8");
|
|
234
|
-
const { against, view } = previewView(stateOf(app, env), kind, address.language, Date.now());
|
|
259
|
+
const { against, view } = previewView(stateOf(app, env), kind, address.language, Date.now(), schedule);
|
|
235
260
|
const rendering = await renderReport(view, channel, body === undefined ? {} : { template: body });
|
|
236
261
|
const problems = body === undefined ? [] : (await checkTemplate(view, channel, body)).problems;
|
|
237
262
|
options.output(itemOf({
|
|
@@ -255,7 +280,7 @@ export const templatesCommand = (app, options) => {
|
|
|
255
280
|
.action(async function (key, given) {
|
|
256
281
|
const env = options.env();
|
|
257
282
|
refuseAgent(env);
|
|
258
|
-
const { address } = await addressOf(key, given, env);
|
|
283
|
+
const { address } = await addressOf(key, given, env, stateOf(app, env));
|
|
259
284
|
const changed = await withStore(env, (store) => store.templates.reset(address));
|
|
260
285
|
options.diagnostic(changed
|
|
261
286
|
? `${key} ${address.channel} ${address.language} uses the shipped template again`
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** What a person can be shown as when their name has nothing to read. */
|
|
2
|
+
export interface NameFallbacks {
|
|
3
|
+
username?: string | null;
|
|
4
|
+
phone?: string | null;
|
|
5
|
+
email?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`), or a
|
|
9
|
+
* placeholder such as `null` or «Без имени», gives way to the username, then the phone, then the email; the stored name
|
|
10
|
+
* stays as it came.
|
|
11
|
+
*/
|
|
12
|
+
export declare const displayName: (name: string | null | undefined, fallbacks?: NameFallbacks) => string | null;
|
|
13
|
+
/**
|
|
14
|
+
* The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
|
|
15
|
+
* `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
|
|
16
|
+
*/
|
|
17
|
+
export declare const nameKey: (name: string | null | undefined) => string | null;
|
|
18
|
+
/** Whether a shown name has anything to read: not null, not only punctuation. */
|
|
19
|
+
export declare const isReadable: (shown: string | null) => boolean;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { foldName } from "../resolve.js";
|
|
2
|
+
const QUOTES = [
|
|
3
|
+
['"', '"'],
|
|
4
|
+
["'", "'"],
|
|
5
|
+
["«", "»"],
|
|
6
|
+
["“", "”"],
|
|
7
|
+
["„", "“"],
|
|
8
|
+
["‘", "’"],
|
|
9
|
+
["`", "`"],
|
|
10
|
+
];
|
|
11
|
+
const READABLE = /[\p{L}\p{N}]/u;
|
|
12
|
+
/** What a source writes when it has no name: no name at all. */
|
|
13
|
+
const PLACEHOLDERS = new Set(["null", "undefined", "none", "без имени", "deleted account", "удалённый аккаунт"]);
|
|
14
|
+
const unquoted = (text) => {
|
|
15
|
+
let at = text.replace(/\s+/gu, " ").trim();
|
|
16
|
+
for (;;) {
|
|
17
|
+
const pair = QUOTES.find(([open, close]) => at.length >= 2 && at.startsWith(open) && at.endsWith(close));
|
|
18
|
+
if (pair === undefined)
|
|
19
|
+
return at;
|
|
20
|
+
at = at.slice(pair[0].length, at.length - pair[1].length).trim();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const given = (value) => {
|
|
24
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
25
|
+
return text === "" ? undefined : text;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`), or a
|
|
29
|
+
* placeholder such as `null` or «Без имени», gives way to the username, then the phone, then the email; the stored name
|
|
30
|
+
* stays as it came.
|
|
31
|
+
*/
|
|
32
|
+
export const displayName = (name, fallbacks = {}) => {
|
|
33
|
+
const unwrapped = typeof name === "string" ? unquoted(name) : "";
|
|
34
|
+
const cleaned = PLACEHOLDERS.has(unwrapped.toLowerCase()) ? "" : unwrapped;
|
|
35
|
+
if (READABLE.test(cleaned))
|
|
36
|
+
return cleaned;
|
|
37
|
+
const username = given(fallbacks.username);
|
|
38
|
+
return ((username === undefined ? undefined : username.startsWith("@") ? username : `@${username}`) ??
|
|
39
|
+
given(fallbacks.phone) ??
|
|
40
|
+
given(fallbacks.email) ??
|
|
41
|
+
(cleaned === "" ? null : cleaned));
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
|
|
45
|
+
* `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
|
|
46
|
+
*/
|
|
47
|
+
export const nameKey = (name) => {
|
|
48
|
+
if (typeof name !== "string")
|
|
49
|
+
return null;
|
|
50
|
+
const unwrapped = unquoted(name);
|
|
51
|
+
if (PLACEHOLDERS.has(unwrapped.toLowerCase()))
|
|
52
|
+
return null;
|
|
53
|
+
const words = foldName(unwrapped)
|
|
54
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
55
|
+
.filter((word) => word !== "");
|
|
56
|
+
return words.length === 0 ? null : words.sort().join(" ");
|
|
57
|
+
};
|
|
58
|
+
/** Whether a shown name has anything to read: not null, not only punctuation. */
|
|
59
|
+
export const isReadable = (shown) => shown !== null && READABLE.test(shown);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** What a person in the store is, for a list that shows the useful ones and keeps the noise apart. */
|
|
2
|
+
export declare const PERSON_KINDS: readonly ["person", "organization", "automated", "unsorted"];
|
|
3
|
+
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
4
|
+
/** What decided a kind, besides the ties that make someone a `person`. */
|
|
5
|
+
export type KindSignal = "bot" | "no-reply" | "bulk-mail" | "bulk-never-replied" | "automated-name" | "organization" | "role-address" | "company-name" | "no-tie" | "no-name";
|
|
6
|
+
/** A sender that is a program: «Notifications», «Рассылка», «no-reply». */
|
|
7
|
+
export declare const isAutomatedName: (name: string | null) => boolean;
|
|
8
|
+
/** A legal form or a word only a business calls itself: «ООО Ромашка», «CZECH AIRLINES», «OpenWeather Team». */
|
|
9
|
+
export declare const isCompanyName: (name: string | null) => boolean;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** What a person in the store is, for a list that shows the useful ones and keeps the noise apart. */
|
|
2
|
+
export const PERSON_KINDS = ["person", "organization", "automated", "unsorted"];
|
|
3
|
+
const AUTOMATED_WORDS = new Set([
|
|
4
|
+
"noreply",
|
|
5
|
+
"notification",
|
|
6
|
+
"notifications",
|
|
7
|
+
"newsletter",
|
|
8
|
+
"newsletters",
|
|
9
|
+
"digest",
|
|
10
|
+
"alerts",
|
|
11
|
+
"mailer",
|
|
12
|
+
"robot",
|
|
13
|
+
]);
|
|
14
|
+
const AUTOMATED_STEMS = ["уведомлени", "рассылк", "оповещени", "noreply", "donotreply", "робот"];
|
|
15
|
+
const LEGAL_FORMS = new Set(["ооо", "оао", "зао", "пао", "ао", "ип", "llc", "ltd", "limited", "inc", "corp", "gmbh"]);
|
|
16
|
+
const COMPANY_WORDS = new Set([
|
|
17
|
+
"airlines",
|
|
18
|
+
"airways",
|
|
19
|
+
"bank",
|
|
20
|
+
"банк",
|
|
21
|
+
"hotel",
|
|
22
|
+
"hotels",
|
|
23
|
+
"отель",
|
|
24
|
+
"гостиница",
|
|
25
|
+
"hostel",
|
|
26
|
+
"хостел",
|
|
27
|
+
"апартаменты",
|
|
28
|
+
"team",
|
|
29
|
+
"support",
|
|
30
|
+
"поддержка",
|
|
31
|
+
"service",
|
|
32
|
+
"services",
|
|
33
|
+
"сервис",
|
|
34
|
+
"служба",
|
|
35
|
+
"shop",
|
|
36
|
+
"store",
|
|
37
|
+
"магазин",
|
|
38
|
+
"company",
|
|
39
|
+
"компания",
|
|
40
|
+
"agency",
|
|
41
|
+
"агентство",
|
|
42
|
+
"restaurant",
|
|
43
|
+
"ресторан",
|
|
44
|
+
"clinic",
|
|
45
|
+
"клиника",
|
|
46
|
+
"delivery",
|
|
47
|
+
"доставка",
|
|
48
|
+
]);
|
|
49
|
+
const wordsOf = (name) => name
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.split(/[^\p{L}\p{N}-]+/u)
|
|
52
|
+
.filter((word) => word !== "");
|
|
53
|
+
/** A sender that is a program: «Notifications», «Рассылка», «no-reply». */
|
|
54
|
+
export const isAutomatedName = (name) => {
|
|
55
|
+
if (name === null)
|
|
56
|
+
return false;
|
|
57
|
+
return wordsOf(name).some((word) => {
|
|
58
|
+
const bare = word.includes("-") ? word.replaceAll("-", "") : word;
|
|
59
|
+
return AUTOMATED_WORDS.has(bare) || AUTOMATED_STEMS.some((stem) => bare.startsWith(stem));
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
/** A legal form or a word only a business calls itself: «ООО Ромашка», «CZECH AIRLINES», «OpenWeather Team». */
|
|
63
|
+
export const isCompanyName = (name) => {
|
|
64
|
+
if (name === null)
|
|
65
|
+
return false;
|
|
66
|
+
return wordsOf(name.replaceAll(".", "")).some((word) => LEGAL_FORMS.has(word) || COMPANY_WORDS.has(word));
|
|
67
|
+
};
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -4199,6 +4199,7 @@ export declare const ENTITIES: {
|
|
|
4199
4199
|
readonly name: v.StringSchema<undefined>;
|
|
4200
4200
|
readonly kind: v.PicklistSchema<["command", "agent"], undefined>;
|
|
4201
4201
|
readonly when: v.StringSchema<undefined>;
|
|
4202
|
+
readonly paused: v.OptionalSchema<v.LiteralSchema<true, undefined>, undefined>;
|
|
4202
4203
|
readonly notify: v.OptionalSchema<v.PicklistSchema<["always", "failures", "never"], undefined>, undefined>;
|
|
4203
4204
|
readonly deliver_to: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
4204
4205
|
readonly last: v.NullableSchema<v.StrictObjectSchema<{
|
|
@@ -11941,7 +11942,7 @@ export declare const ENTITIES: {
|
|
|
11941
11942
|
readonly language: v.StringSchema<undefined>;
|
|
11942
11943
|
readonly about: v.StringSchema<undefined>;
|
|
11943
11944
|
readonly renders: v.BooleanSchema<undefined>;
|
|
11944
|
-
readonly source: v.PicklistSchema<["stored", "default"], undefined>;
|
|
11945
|
+
readonly source: v.PicklistSchema<["stored", "inherited", "default"], undefined>;
|
|
11945
11946
|
readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
|
|
11946
11947
|
readonly updated_by: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
11947
11948
|
}, undefined>;
|
|
@@ -48,6 +48,8 @@ export declare const scheduledJob: v.StrictObjectSchema<{
|
|
|
48
48
|
readonly name: v.StringSchema<undefined>;
|
|
49
49
|
readonly kind: v.PicklistSchema<["command", "agent"], undefined>;
|
|
50
50
|
readonly when: v.StringSchema<undefined>;
|
|
51
|
+
/** Kept without its timer: `schedule run` runs it, `schedule resume` puts it back on its timer. */
|
|
52
|
+
readonly paused: v.OptionalSchema<v.LiteralSchema<true, undefined>, undefined>;
|
|
51
53
|
/** When a finished run shows a desktop notice: `always`, `failures` or `never`; the default is shown, not left out. */
|
|
52
54
|
readonly notify: v.OptionalSchema<v.PicklistSchema<["always", "failures", "never"], undefined>, undefined>;
|
|
53
55
|
/** Where a run's result is sent after it: `telegram-bot:<profile>/<chat>` or `email:<profile>/<address>`. */
|
|
@@ -32,6 +32,8 @@ export const scheduledJob = v.strictObject({
|
|
|
32
32
|
name: text,
|
|
33
33
|
kind: v.picklist(["command", "agent"]),
|
|
34
34
|
when: text,
|
|
35
|
+
/** Kept without its timer: `schedule run` runs it, `schedule resume` puts it back on its timer. */
|
|
36
|
+
paused: v.optional(v.literal(true)),
|
|
35
37
|
/** When a finished run shows a desktop notice: `always`, `failures` or `never`; the default is shown, not left out. */
|
|
36
38
|
notify: v.optional(v.picklist(["always", "failures", "never"])),
|
|
37
39
|
/** Where a run's result is sent after it: `telegram-bot:<profile>/<chat>` or `email:<profile>/<address>`. */
|
|
@@ -5,7 +5,7 @@ export declare const template: v.StrictObjectSchema<{
|
|
|
5
5
|
readonly language: v.StringSchema<undefined>;
|
|
6
6
|
readonly about: v.StringSchema<undefined>;
|
|
7
7
|
readonly renders: v.BooleanSchema<undefined>;
|
|
8
|
-
readonly source: v.PicklistSchema<["stored", "default"], undefined>;
|
|
8
|
+
readonly source: v.PicklistSchema<["stored", "inherited", "default"], undefined>;
|
|
9
9
|
readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
|
|
10
10
|
readonly updated_by: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
11
11
|
}, undefined>;
|
|
@@ -6,7 +6,7 @@ export const template = v.strictObject({
|
|
|
6
6
|
language: text,
|
|
7
7
|
about: text,
|
|
8
8
|
renders: v.boolean(),
|
|
9
|
-
source: v.picklist(["stored", "default"]),
|
|
9
|
+
source: v.picklist(["stored", "inherited", "default"]),
|
|
10
10
|
updated_at: v.nullable(time),
|
|
11
11
|
updated_by: v.nullable(text),
|
|
12
12
|
});
|
package/dist/errors/reasons.js
CHANGED
|
@@ -381,6 +381,7 @@ const OTHERS = [
|
|
|
381
381
|
],
|
|
382
382
|
validation("identity.same", "the two identities are one person already"),
|
|
383
383
|
validation("identity.shared-phone", "more than six people share the phone number, so it proposes no one"),
|
|
384
|
+
validation("identity.common-name", "more than six people have the name, so it proposes no one"),
|
|
384
385
|
validation("identity.shared-email", "more than six people share the address, so it proposes no one"),
|
|
385
386
|
validation("identity-link.dedicated-review", "an identity link is staged and decided through the people review"),
|
|
386
387
|
["transcription.no-key", "authentication_error", "no OpenAI key is set for transcription"],
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type { CounterField, CounterObservation, CounterObservations, CounterStat
|
|
|
5
5
|
export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
|
|
6
6
|
export { CRM_KINDS, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmRecords, type CrmScope, type CrmScopeSetting, type CrmStage, type CrmUser, type CrmValue, isCrmUserId, isItemKind, normalCrmUserId, } from "./domain/crm.js";
|
|
7
7
|
export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, type DealKind, type DealRole, type DealStatus, STAGE_OUTCOMES, type StageOutcome, } from "./domain/deals.js";
|
|
8
|
+
export { displayName, type NameFallbacks, nameKey } from "./domain/display-names.js";
|
|
8
9
|
export { FINANCE_REVIEWS, type FinanceReview, INVOICE_DIRECTIONS, INVOICE_STATUSES, type InvoiceDirection, type InvoiceStatus, MONEY_DIRECTIONS, type MoneyDirection, } from "./domain/finance.js";
|
|
9
10
|
export { type FormattedText, type HtmlFormatting, type MarkdownFormatting, type TextSpan, validateFormattedText, } from "./domain/formatting.js";
|
|
10
11
|
export { DEFAULT_LINK_CONFIG, type DeepLinkTarget, formatLink, LINK_VERSION, type LinkConfig, type LinkForm, linkConfigOf, linkFor, linkTargetOf, parseLink, refsForLink, } from "./domain/links.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { bareCheck, checkWords } from "./domain/checks.js";
|
|
|
4
4
|
export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
|
|
5
5
|
export { CRM_KINDS, isCrmUserId, isItemKind, normalCrmUserId, } from "./domain/crm.js";
|
|
6
6
|
export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, STAGE_OUTCOMES, } from "./domain/deals.js";
|
|
7
|
+
export { displayName, nameKey } from "./domain/display-names.js";
|
|
7
8
|
export { FINANCE_REVIEWS, INVOICE_DIRECTIONS, INVOICE_STATUSES, MONEY_DIRECTIONS, } from "./domain/finance.js";
|
|
8
9
|
export { validateFormattedText, } from "./domain/formatting.js";
|
|
9
10
|
export { DEFAULT_LINK_CONFIG, formatLink, LINK_VERSION, linkConfigOf, linkFor, linkTargetOf, parseLink, refsForLink, } from "./domain/links.js";
|
package/dist/mcp/surface.js
CHANGED
|
@@ -9,6 +9,27 @@ import { agentArguments } from "./text.js";
|
|
|
9
9
|
import { answered, commandOf, entryRunner, failed, inputOf, outputSchemaOf, READ, syncAllowedFor, UNTRUSTED, UNTRUSTED_NEUTRAL, WRITE, } from "./tool.js";
|
|
10
10
|
const MATCHES = 8;
|
|
11
11
|
const ANSWER = answerSchema();
|
|
12
|
+
// The listing shows an agent only what it acts on; the server still checks every answer against the full envelope,
|
|
13
|
+
// and tools_search gives each command's full answer. meta.ranking alone took 2,800 characters of every connect.
|
|
14
|
+
const agentAnswer = (prefix, writes) => {
|
|
15
|
+
const meta = v.pipe(v.looseObject({}), v.description(`run facts; ${prefix}_tools_search shows the full answer`));
|
|
16
|
+
const next = v.optional(v.pipe(v.array(v.looseObject({})), v.description("steps to run next: command and args")));
|
|
17
|
+
return v.looseObject(writes
|
|
18
|
+
? { item: v.optional(v.unknown()), next, meta }
|
|
19
|
+
: {
|
|
20
|
+
items: v.optional(v.array(v.unknown())),
|
|
21
|
+
item: v.optional(v.unknown()),
|
|
22
|
+
page: v.optional(v.looseObject({ has_more: v.boolean() })),
|
|
23
|
+
next,
|
|
24
|
+
missing: v.optional(v.array(v.looseObject({ field: v.string(), why: v.string() }))),
|
|
25
|
+
meta,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const listedAs = (prefix, writes) => {
|
|
29
|
+
const checked = toStandardJsonSchema(ANSWER);
|
|
30
|
+
const shown = toStandardJsonSchema(agentAnswer(prefix, writes))["~standard"].jsonSchema;
|
|
31
|
+
return { "~standard": { ...checked["~standard"], jsonSchema: shown } };
|
|
32
|
+
};
|
|
12
33
|
export const normal = (command) => command
|
|
13
34
|
.trim()
|
|
14
35
|
.toLowerCase()
|
|
@@ -152,7 +173,7 @@ isMessenger) => {
|
|
|
152
173
|
arguments: v.optional(v.pipe(v.record(v.string(), v.unknown()), v.description("that command's arguments"))),
|
|
153
174
|
});
|
|
154
175
|
server.registerTool(`${prefix}_read`, {
|
|
155
|
-
outputSchema:
|
|
176
|
+
outputSchema: listedAs(prefix, false),
|
|
156
177
|
title: "Run a reading command",
|
|
157
178
|
description: `Run one command that only reads, with the arguments ${prefix}_tools_search showed. ${untrusted}`,
|
|
158
179
|
inputSchema: toStandardJsonSchema(call),
|
|
@@ -160,7 +181,7 @@ isMessenger) => {
|
|
|
160
181
|
}, runner(false));
|
|
161
182
|
if (Object.values(commands).some((one) => one.writes))
|
|
162
183
|
server.registerTool(`${prefix}_write`, {
|
|
163
|
-
outputSchema:
|
|
184
|
+
outputSchema: listedAs(prefix, true),
|
|
164
185
|
title: "Run a writing command",
|
|
165
186
|
description: `Run one command that changes something — ${messenger ? "sends, edits, deletes, joins" : "creates, edits, deletes"} — with the arguments ${prefix}_tools_search showed. ${untrusted}`,
|
|
166
187
|
inputSchema: toStandardJsonSchema(call),
|
|
@@ -22,6 +22,14 @@ export declare const MESSAGE_PARSING: {
|
|
|
22
22
|
/** Further apart than this, two words are rarely about one thing, even in a long message. */
|
|
23
23
|
export declare const MOST_WORDS_APART = 50;
|
|
24
24
|
export declare function searchError(reason: string, span: Span, alternative?: string): never;
|
|
25
|
+
/**
|
|
26
|
+
* A search's time limit: the default keeps agents and MCP to 2 s; a run whose caller set a time limit itself
|
|
27
|
+
* (Desktop's `--timeout 30s`) may use it, less the time to answer.
|
|
28
|
+
*/
|
|
29
|
+
export declare const searchTimeLimit: (deadline: {
|
|
30
|
+
endsAt: number;
|
|
31
|
+
explicit?: true;
|
|
32
|
+
} | undefined, now?: number) => number | undefined;
|
|
25
33
|
/**
|
|
26
34
|
* The search ran out of time, not the query out of bounds: a valid query over a large store. `timeout`, so a caller
|
|
27
35
|
* does not tell the person to fix what they typed.
|
|
@@ -22,6 +22,13 @@ export const MOST_WORDS_APART = 50;
|
|
|
22
22
|
export function searchError(reason, span, alternative) {
|
|
23
23
|
queryError(reason, span, alternative, SEARCH_QUERY);
|
|
24
24
|
}
|
|
25
|
+
/** Time to print a search's own time-limit answer before the run's deadline cuts it. */
|
|
26
|
+
const ANSWER_MS = 1000;
|
|
27
|
+
/**
|
|
28
|
+
* A search's time limit: the default keeps agents and MCP to 2 s; a run whose caller set a time limit itself
|
|
29
|
+
* (Desktop's `--timeout 30s`) may use it, less the time to answer.
|
|
30
|
+
*/
|
|
31
|
+
export const searchTimeLimit = (deadline, now = Date.now()) => deadline?.explicit ? Math.max(QUERY_LIMITS.milliseconds, deadline.endsAt - now - ANSWER_MS) : undefined;
|
|
25
32
|
/**
|
|
26
33
|
* The search ran out of time, not the query out of bounds: a valid query over a large store. `timeout`, so a caller
|
|
27
34
|
* does not tell the person to fix what they typed.
|
package/dist/services/index.d.ts
CHANGED
|
@@ -215,7 +215,7 @@ export { RESOURCES_SEARCHED, type SearchAllFound, type SearchAllItem, type Searc
|
|
|
215
215
|
export { type MeetingSearchCoverage, type MeetingSearchCursor, type ResourceWithMeetings, type SearchAllIncludingMeetingsFound, type SearchAllIncludingMeetingsRequest, searchAllIncludingMeetings, } from "./search-all-deprecated.js";
|
|
216
216
|
export { type MeetingAccountCoverage, type MeetingSearchItem, MOST_HITS_PER_MEETING, } from "./search-all-meetings.js";
|
|
217
217
|
export { CATCH_UP_BOUNDS, type CatchUpOptions, type CatchUpResult, catchUpSearch, validateCatchUp, } from "./search-catchup.js";
|
|
218
|
-
export { HARDER_MODELS, HARDER_REASON_IDS, type HarderOptions, type HarderReasonId, type HarderResult, readHarderSetting, writeHarderSetting, } from "./search-harder.js";
|
|
218
|
+
export { HARDER_MODELS, HARDER_REASON_IDS, type HarderOptions, type HarderReasonId, type HarderResult, harderRanking, readHarderSetting, writeHarderSetting, } from "./search-harder.js";
|
|
219
219
|
export { accountsOfKind, groupLockOf, listContextOf, type SearchKind } from "./search-kind.js";
|
|
220
220
|
export type { SearchRefreshed, SyncOptions } from "./search-refresh.js";
|
|
221
221
|
export { SYNC_BOUNDS, SYNC_KEY } from "./search-refresh.js";
|
package/dist/services/index.js
CHANGED
|
@@ -166,7 +166,7 @@ export { RESOURCES_SEARCHED, searchAll, } from "./search-all.js";
|
|
|
166
166
|
export { searchAllIncludingMeetings, } from "./search-all-deprecated.js";
|
|
167
167
|
export { MOST_HITS_PER_MEETING, } from "./search-all-meetings.js";
|
|
168
168
|
export { CATCH_UP_BOUNDS, catchUpSearch, validateCatchUp, } from "./search-catchup.js";
|
|
169
|
-
export { HARDER_MODELS, HARDER_REASON_IDS, readHarderSetting, writeHarderSetting, } from "./search-harder.js";
|
|
169
|
+
export { HARDER_MODELS, HARDER_REASON_IDS, harderRanking, readHarderSetting, writeHarderSetting, } from "./search-harder.js";
|
|
170
170
|
export { accountsOfKind, groupLockOf, listContextOf } from "./search-kind.js";
|
|
171
171
|
export { SYNC_BOUNDS, SYNC_KEY } from "./search-refresh.js";
|
|
172
172
|
export { SERVER_BOUNDS, SERVER_SEARCH_KEY, } from "./server-search.js";
|
|
@@ -30,8 +30,9 @@ export const searchCombined = async (store, account, request, messenger = {}, op
|
|
|
30
30
|
const check = () => {
|
|
31
31
|
if (request.signal?.aborted)
|
|
32
32
|
throw new CliError("validation_error", "search was aborted", { reason: "query.aborted", complete: false });
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const limitMs = request.timeLimitMs ?? QUERY_LIMITS.milliseconds;
|
|
34
|
+
if (performance.now() - started > limitMs)
|
|
35
|
+
outOfTime(limitMs);
|
|
35
36
|
};
|
|
36
37
|
check();
|
|
37
38
|
const spans = request.ast === undefined && !request.exact && request.text !== undefined
|
|
@@ -87,8 +87,9 @@ export const searchDiscovery = async (store, account, asked, messenger = {}, mea
|
|
|
87
87
|
const check = () => {
|
|
88
88
|
if (request.signal?.aborted)
|
|
89
89
|
throw new CliError("validation_error", "search was aborted", { reason: "query.aborted", complete: false });
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const limitMs = request.timeLimitMs ?? QUERY_LIMITS.milliseconds;
|
|
91
|
+
if (performance.now() - started > limitMs)
|
|
92
|
+
outOfTime(limitMs);
|
|
92
93
|
};
|
|
93
94
|
const union = new Map();
|
|
94
95
|
let truncated = false;
|
|
@@ -141,6 +141,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
|
|
|
141
141
|
...(request.senders === undefined ? {} : { senders: request.senders }),
|
|
142
142
|
...(selectedChat ? { chat: selectedChat } : {}),
|
|
143
143
|
...(request.signal ? { signal: request.signal } : {}),
|
|
144
|
+
...(request.timeLimitMs === undefined ? {} : { timeLimitMs: request.timeLimitMs }),
|
|
144
145
|
newest: request.newest,
|
|
145
146
|
...(stemmer ? { stemmer } : {}),
|
|
146
147
|
...(unstemmed ? { unstemmed: true } : {}),
|
|
@@ -50,6 +50,8 @@ export interface SearchQuery {
|
|
|
50
50
|
timezone?: string;
|
|
51
51
|
ast?: unknown;
|
|
52
52
|
signal?: AbortSignal;
|
|
53
|
+
/** Longer than the 2 s default when the caller set the run's time limit itself (`searchTimeLimit`). */
|
|
54
|
+
timeLimitMs?: number;
|
|
53
55
|
chat?: string;
|
|
54
56
|
/** A messenger the store holds, or `all` — the same as `in:` in the query. The account it runs as when unset. */
|
|
55
57
|
source?: string;
|
package/dist/services/people.js
CHANGED
|
@@ -139,7 +139,7 @@ export const peopleService = (deps) => {
|
|
|
139
139
|
else if (known.name !== person.name || known.username !== person.username)
|
|
140
140
|
changed += 1;
|
|
141
141
|
}
|
|
142
|
-
await store.people.
|
|
142
|
+
await store.people.saveAddressBook(account, people);
|
|
143
143
|
return {
|
|
144
144
|
added,
|
|
145
145
|
changed,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type KeyringStore } from "@wirecat/cli-base";
|
|
2
|
+
import type { Ranking } from "@wirecat/cli-base/standards";
|
|
2
3
|
import * as v from "valibot";
|
|
3
|
-
import { type ModelAdapter } from "../models/index.js";
|
|
4
|
+
import { type ModelAdapter, type ModelUsage } from "../models/index.js";
|
|
4
5
|
import type { AppIdentity } from "../ports/app.js";
|
|
5
6
|
import { type EnrichmentProvider } from "./enrichment-setting.js";
|
|
6
7
|
/**
|
|
@@ -34,10 +35,14 @@ export interface HarderResult {
|
|
|
34
35
|
/** Hits sent to the model; 0 when nothing left this machine. */
|
|
35
36
|
sent: number;
|
|
36
37
|
cost_usd: number | null;
|
|
38
|
+
/** Tokens as the provider reported them; absent when nothing came back. */
|
|
39
|
+
usage?: ModelUsage;
|
|
37
40
|
ms: number;
|
|
38
41
|
reason?: string;
|
|
39
42
|
reason_id?: HarderReasonId;
|
|
40
43
|
}
|
|
44
|
+
/** The result as the answer's `meta.ranking`: the same facts, with the reason as its code alone. */
|
|
45
|
+
export declare const harderRanking: ({ reason: _reason, ...rest }: HarderResult) => Ranking;
|
|
41
46
|
export interface HarderOptions {
|
|
42
47
|
/** The tool whose keyring entry holds the key; without it only the environment's key is read. */
|
|
43
48
|
app?: AppIdentity;
|
|
@@ -47,6 +47,8 @@ export const HARDER_REASON_IDS = [
|
|
|
47
47
|
"harder.bad-reply",
|
|
48
48
|
"harder.error",
|
|
49
49
|
];
|
|
50
|
+
/** The result as the answer's `meta.ranking`: the same facts, with the reason as its code alone. */
|
|
51
|
+
export const harderRanking = ({ reason: _reason, ...rest }) => rest;
|
|
50
52
|
// The search lab's prompt, word for word, except that the records travel as the gateway's untrusted data.
|
|
51
53
|
const PROMPT = "Today is {as_of}. A person searches their own archive of messages, mails, notes, calendar entries and phone " +
|
|
52
54
|
"records with the question below. Here are {n} candidate records, numbered, in the data.\n\n" +
|
|
@@ -185,7 +187,7 @@ const ask = async (access, options, request) => {
|
|
|
185
187
|
model: access.model,
|
|
186
188
|
...(access.custom ? { base_url: access.endpoint } : {}),
|
|
187
189
|
});
|
|
188
|
-
return { text: answer.text, cost };
|
|
190
|
+
return { text: answer.text, cost, ...(answer.usage ? { usage: answer.usage } : {}) };
|
|
189
191
|
}
|
|
190
192
|
catch (error) {
|
|
191
193
|
return { reason_id: reasonOf(error, limit.signal.aborted) };
|
|
@@ -241,7 +243,11 @@ export const reorderHarder = async (question, hits, { laterPage, access: given,
|
|
|
241
243
|
picked = v.parse(Reply, jsonOf(answer.text)).records;
|
|
242
244
|
}
|
|
243
245
|
catch {
|
|
244
|
-
return plain("harder.bad-reply", {
|
|
246
|
+
return plain("harder.bad-reply", {
|
|
247
|
+
...sent,
|
|
248
|
+
cost_usd: answer.cost,
|
|
249
|
+
...(answer.usage ? { usage: answer.usage } : {}),
|
|
250
|
+
});
|
|
245
251
|
}
|
|
246
252
|
const first = [...new Set(picked.filter((i) => i >= 0 && i < candidates.length))];
|
|
247
253
|
const chosen = new Set(first);
|
|
@@ -258,6 +264,7 @@ export const reorderHarder = async (question, hits, { laterPage, access: given,
|
|
|
258
264
|
endpoint: access.endpoint,
|
|
259
265
|
...sent,
|
|
260
266
|
cost_usd: answer.cost,
|
|
267
|
+
...(answer.usage ? { usage: answer.usage } : {}),
|
|
261
268
|
ms: Date.now() - started,
|
|
262
269
|
},
|
|
263
270
|
};
|