@wirecat/cli-core 0.608.0 → 0.610.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 +124 -1
- package/dist/background/deliver.d.ts +12 -1
- package/dist/background/deliver.js +38 -5
- package/dist/background/report/render.d.ts +61 -0
- package/dist/background/report/render.js +208 -0
- package/dist/background/report/schema.d.ts +66 -0
- package/dist/background/report/schema.js +191 -0
- package/dist/background/report/templates/morning-digest.email.en.liquid +79 -0
- package/dist/background/report/templates/morning-digest.email.ru.liquid +79 -0
- package/dist/background/report/templates/morning-digest.telegram.en.liquid +77 -0
- package/dist/background/report/templates/morning-digest.telegram.ru.liquid +77 -0
- package/dist/background/report/templates/morning-digest.text.en.liquid +76 -0
- package/dist/background/report/templates/morning-digest.text.ru.liquid +76 -0
- package/dist/background/report/view.d.ts +88 -0
- package/dist/background/report/view.js +152 -0
- package/dist/background/schedules.d.ts +6 -1
- package/dist/background/schedules.js +24 -7
- package/dist/cli/embedding-choice.d.ts +4 -1
- package/dist/cli/embedding-choice.js +6 -3
- package/dist/cli/messenger/models-command.js +46 -18
- package/dist/cli/messenger/search-answers.js +23 -2
- package/dist/cli/model-catalogue-command.d.ts +33 -0
- package/dist/cli/model-catalogue-command.js +110 -21
- package/dist/cli/schedule/schedule-command.js +18 -0
- package/dist/cli/search-left-out.d.ts +1 -0
- package/dist/cli/search-left-out.js +2 -0
- package/dist/cli/store-settings.js +39 -3
- package/dist/crm/cli/csv.d.ts +18 -5
- package/dist/crm/cli/csv.js +30 -19
- package/dist/crm/cli/index.d.ts +1 -0
- package/dist/crm/cli/index.js +1 -0
- package/dist/domain/business.d.ts +3 -0
- package/dist/domain/business.js +2 -0
- package/dist/embeddings/models.d.ts +185 -5
- package/dist/embeddings/models.js +119 -5
- package/dist/entities/hit.d.ts +13 -2
- package/dist/entities/hit.js +10 -2
- package/dist/entities/index.d.ts +31 -1
- package/dist/entities/index.js +2 -1
- package/dist/entities/model.d.ts +42 -1
- package/dist/entities/model.js +20 -1
- package/dist/errors/reasons.js +4 -0
- package/dist/render/liquid.d.ts +14 -0
- package/dist/render/liquid.js +30 -0
- package/dist/replies/template.js +3 -22
- package/dist/search/account-list.d.ts +3 -2
- package/dist/search/account-list.js +5 -4
- package/dist/search/lucene/plain.js +4 -1
- package/dist/search/question-plan.js +2 -1
- package/dist/sends/permissions.js +4 -0
- package/dist/services/embeddings-maintenance.d.ts +1 -1
- package/dist/services/embeddings-maintenance.js +6 -6
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/link-scorers/chat-senders.d.ts +2 -1
- package/dist/services/link-scorers/chat-senders.js +13 -4
- package/dist/services/link-scorers/types.d.ts +1 -1
- package/dist/services/meeting-model.d.ts +1 -1
- package/dist/services/meeting-model.js +4 -4
- package/dist/services/messages-meaning.js +25 -4
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/model-downloads.js +1 -1
- package/dist/services/notes-search.d.ts +1 -1
- package/dist/services/notes-search.js +2 -2
- package/dist/services/proposals/kinds/relationship.js +1 -0
- package/dist/services/proposals/registry.js +3 -1
- package/dist/services/proposals/types.d.ts +2 -0
- package/dist/services/search-all-business.d.ts +18 -0
- package/dist/services/search-all-business.js +38 -0
- package/dist/services/search-all-meetings.d.ts +1 -1
- package/dist/services/search-all-meetings.js +7 -2
- package/dist/services/search-all.d.ts +12 -6
- package/dist/services/search-all.js +48 -12
- package/dist/services/text-model-choice.d.ts +50 -0
- package/dist/services/text-model-choice.js +151 -0
- package/dist/store/exports.d.ts +3 -0
- package/dist/store/exports.js +3 -0
- package/dist/store/index.d.ts +5 -1
- package/dist/store/index.js +3 -0
- package/dist/store/sqlite/business-search.d.ts +44 -0
- package/dist/store/sqlite/business-search.js +141 -0
- package/dist/store/sqlite/finance.d.ts +12 -0
- package/dist/store/sqlite/finance.js +38 -2
- package/dist/store/sqlite/involvement-queue.d.ts +2 -7
- package/dist/store/sqlite/involvement-queue.js +11 -14
- package/dist/store/sqlite/money-lines.d.ts +12 -1
- package/dist/store/sqlite/money-lines.js +50 -4
- package/dist/store/sqlite/orders.js +5 -25
- package/dist/store/sqlite/owner-languages.d.ts +13 -0
- package/dist/store/sqlite/owner-languages.js +49 -0
- package/dist/store/sqlite/proposed-actions.d.ts +2 -0
- package/dist/store/sqlite/proposed-actions.js +4 -3
- package/dist/store/sqlite/records.d.ts +21 -0
- package/dist/store/sqlite/records.js +74 -13
- package/dist/store/sqlite/ref-summaries.d.ts +3 -1
- package/dist/store/sqlite/ref-summaries.js +4 -1
- package/dist/store/sqlite/reported-relations.d.ts +1 -0
- package/dist/store/sqlite/reported-relations.js +5 -1
- package/dist/store/sqlite/vectors.d.ts +2 -0
- package/dist/store/sqlite/vectors.js +5 -0
- package/dist/store/store.d.ts +2 -0
- package/dist/store/store.js +4 -4
- package/dist/store/vectors.d.ts +2 -0
- package/dist/store/vectors.js +1 -0
- package/dist/terminal/prompt.d.ts +4 -0
- package/dist/terminal/prompt.js +21 -2
- package/package.json +2 -2
- package/parity.json +13 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
import { type TextModel } from "../embeddings/models.js";
|
|
2
3
|
import type { AppIdentity } from "../ports/app.js";
|
|
4
|
+
import { type TextModelSwitch } from "../services/text-model-choice.js";
|
|
3
5
|
import { type Body } from "./envelope.js";
|
|
4
6
|
export declare const MODEL_CATALOGUE_QUERY: import("@wirecat/cli-base/query").QueryRegistry;
|
|
5
7
|
export interface ModelCatalogueOptions {
|
|
@@ -13,3 +15,34 @@ export interface ModelCatalogueOptions {
|
|
|
13
15
|
}
|
|
14
16
|
/** Provider composition supplies I/O and supported kinds; parsing, receipts and download policy stay shared. */
|
|
15
17
|
export declare const modelCatalogueCommand: (app: AppIdentity, options: ModelCatalogueOptions) => Command;
|
|
18
|
+
/** One text model as `models list`, `download`, `use` and `add` print it, in every CLI. */
|
|
19
|
+
export declare const textModelItem: (model: TextModel, env: NodeJS.ProcessEnv) => {
|
|
20
|
+
id: string;
|
|
21
|
+
kind: "text";
|
|
22
|
+
title: string;
|
|
23
|
+
languages: string;
|
|
24
|
+
licence: string;
|
|
25
|
+
terms?: string | undefined;
|
|
26
|
+
size?: "large" | "medium" | "small" | undefined;
|
|
27
|
+
dims: number;
|
|
28
|
+
chunks_per_second?: number | undefined;
|
|
29
|
+
custom?: boolean | undefined;
|
|
30
|
+
size_bytes: number;
|
|
31
|
+
downloaded: boolean;
|
|
32
|
+
default: boolean;
|
|
33
|
+
path: string;
|
|
34
|
+
};
|
|
35
|
+
export declare const SET_SUMMARY = "use this text model for every embed and search by meaning, in every CLI";
|
|
36
|
+
export declare const SET_DESCRIPTION: string;
|
|
37
|
+
/** What `models set` adds to the model it prints. */
|
|
38
|
+
export declare const switchFields: ({ previous, toEmbed, estimateSeconds }: TextModelSwitch) => {
|
|
39
|
+
previous: string;
|
|
40
|
+
to_embed: number | null;
|
|
41
|
+
estimate_seconds: number | null;
|
|
42
|
+
};
|
|
43
|
+
export declare const switchNotes: ({ model, previous, toEmbed, estimateSeconds }: TextModelSwitch) => string[];
|
|
44
|
+
export declare const ADD_DESCRIPTION = "add an ONNX embedding model from Hugging Face, pinned and checked by sha256";
|
|
45
|
+
export declare const addExample: (command: string) => string;
|
|
46
|
+
export declare const ADD_HELP = "\n--payload is JSON:\n repository the Hugging Face repository, owner/name\n revision a branch, tag or commit (main); pinned to the commit it names now\n onnx the ONNX file, e.g. onnx/model_quantized.onnx\n externalData the weights file the ONNX file keeps beside itself, if any\n dims the length of its vectors\n pooling mean, or sentence_embedding for a model with that output\n prefix {\"query\": \"...\", \"passage\": \"...\"}, put before a search and a stored text\n maxTokens the longest text it reads (512); a longer one is cut\n title, languages, licence, chunksPerSecond for models list; licence comes from the model card when left out\nThe repository needs tokenizer.json and tokenizer_config.json beside the ONNX file's folder.";
|
|
47
|
+
/** `--payload`'s JSON, refused with the reason when it does not parse. */
|
|
48
|
+
export declare const payloadOf: (text: string) => unknown;
|
|
@@ -4,12 +4,13 @@ import { annotate } from "@wirecat/cli-base/commands";
|
|
|
4
4
|
import { defineQuery } from "@wirecat/cli-base/query";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { isTextModelInstalled, textModelsDirectory } from "../embeddings/embed.js";
|
|
7
|
-
import { DEFAULT_TEXT_MODEL,
|
|
7
|
+
import { chosenTextModel, DEFAULT_TEXT_MODEL, textModel, textModels } from "../embeddings/models.js";
|
|
8
8
|
import { downloadTextModel } from "../services/model-downloads.js";
|
|
9
|
+
import { addCustomTextModel, useTextModel } from "../services/text-model-choice.js";
|
|
9
10
|
import { install, installedBytes, isInstalled, modelsDirectory } from "../speech/install.js";
|
|
10
11
|
import { DEFAULT_ORDER, orderedModels, speechModel } from "../speech/models.js";
|
|
11
12
|
import { stepLines } from "../terminal/step-lines.js";
|
|
12
|
-
import { FETCH, LOCAL_READ, NO_EFFECTS } from "./effects.js";
|
|
13
|
+
import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS } from "./effects.js";
|
|
13
14
|
import { itemOf, listOf } from "./envelope.js";
|
|
14
15
|
import { listQuery, nativeTerms, termField, typedQuery, withQuery } from "./list-query.js";
|
|
15
16
|
export const MODEL_CATALOGUE_QUERY = defineQuery({
|
|
@@ -39,23 +40,7 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
39
40
|
path: join(directory, id),
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
|
-
const text = (id, env) =>
|
|
43
|
-
const model = TEXT_MODELS.find((one) => one.id === id);
|
|
44
|
-
if (!model)
|
|
45
|
-
throw new CliError("validation_error", `unknown text model ${id}`);
|
|
46
|
-
const directory = textModelsDirectory(env);
|
|
47
|
-
return {
|
|
48
|
-
id,
|
|
49
|
-
kind: "text",
|
|
50
|
-
title: model.title,
|
|
51
|
-
languages: model.languages,
|
|
52
|
-
licence: model.licence,
|
|
53
|
-
size_bytes: model.files.reduce((sum, file) => sum + file.bytes, 0),
|
|
54
|
-
downloaded: isTextModelInstalled(model, directory),
|
|
55
|
-
default: id === DEFAULT_TEXT_MODEL,
|
|
56
|
-
path: join(directory, id),
|
|
57
|
-
};
|
|
58
|
-
};
|
|
43
|
+
const text = (id, env) => textModelItem(textModel(id, env), env);
|
|
59
44
|
const models = annotate(new Command("models"), { effects: NO_EFFECTS }).description("models that run on this machine");
|
|
60
45
|
withQuery(annotate(models.command("list"), {
|
|
61
46
|
effects: LOCAL_READ,
|
|
@@ -68,7 +53,7 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
68
53
|
const env = options.env();
|
|
69
54
|
const items = [
|
|
70
55
|
...(options.kinds.includes("audio") ? orderedModels().map((model) => audio(model.id, env)) : []),
|
|
71
|
-
...(options.kinds.includes("text") ?
|
|
56
|
+
...(options.kinds.includes("text") ? textModels(env).map((model) => textModelItem(model, env)) : []),
|
|
72
57
|
].filter((item) => (terms.get("kind") === undefined || item.kind === terms.get("kind")?.value) &&
|
|
73
58
|
(terms.get("id") === undefined || item.id === terms.get("id")?.value) &&
|
|
74
59
|
(terms.get("downloaded") === undefined || item.downloaded === (terms.get("downloaded")?.value === "true")));
|
|
@@ -92,7 +77,7 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
92
77
|
});
|
|
93
78
|
const env = options.env();
|
|
94
79
|
const bytes = downloadProgress(stepLines(options.diagnostic, Boolean(this.optsWithGlobals().json)), id);
|
|
95
|
-
if (
|
|
80
|
+
if (textModels(env).some((model) => model.id === id)) {
|
|
96
81
|
if (!options.kinds.includes("text"))
|
|
97
82
|
throw new CliError("validation_error", "this tool does not use text models");
|
|
98
83
|
await downloadTextModel(id, {
|
|
@@ -114,6 +99,44 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
114
99
|
options.output(itemOf(audio(id, env)), this);
|
|
115
100
|
}
|
|
116
101
|
});
|
|
102
|
+
if (options.kinds.includes("text")) {
|
|
103
|
+
annotate(models.command("set"), {
|
|
104
|
+
effects: LOCAL_WRITE,
|
|
105
|
+
output: { entity: "model", view: "chosen" },
|
|
106
|
+
examples: [`${app.command} models set e5-large`],
|
|
107
|
+
})
|
|
108
|
+
.summary(SET_SUMMARY)
|
|
109
|
+
.description(SET_DESCRIPTION)
|
|
110
|
+
.argument("<model>", "a downloaded text model id from models list")
|
|
111
|
+
.action(async function (id) {
|
|
112
|
+
const env = options.env();
|
|
113
|
+
const done = await useTextModel(id, { env, command: app.command });
|
|
114
|
+
for (const line of switchNotes(done))
|
|
115
|
+
options.diagnostic(line);
|
|
116
|
+
options.output(itemOf({ ...textModelItem(done.model, env), ...switchFields(done) }), this);
|
|
117
|
+
});
|
|
118
|
+
// A model added here is loaded by every CLI once chosen: an agent needs the owner's mcp.authority for it.
|
|
119
|
+
grantsAuthority(annotate(models.command("add"), {
|
|
120
|
+
effects: FETCH,
|
|
121
|
+
output: { entity: "model" },
|
|
122
|
+
examples: [addExample(app.command)],
|
|
123
|
+
}))
|
|
124
|
+
.description(ADD_DESCRIPTION)
|
|
125
|
+
.argument("<id>", "the id to give it: a-z, 0-9, . _ -")
|
|
126
|
+
.requiredOption("--payload <json>", "where the model is and how to run it, as JSON (below)")
|
|
127
|
+
.option("--offline", "refuse a call that needs the network")
|
|
128
|
+
.addHelpText("after", ADD_HELP)
|
|
129
|
+
.action(async function (id, given) {
|
|
130
|
+
if (options.offline?.() || this.optsWithGlobals().offline)
|
|
131
|
+
throw new CliError("permission_error", "adding a model reads Hugging Face; --offline was requested", {
|
|
132
|
+
reason: "model.offline",
|
|
133
|
+
});
|
|
134
|
+
const env = options.env();
|
|
135
|
+
const model = await addCustomTextModel(id, payloadOf(given.payload), { env });
|
|
136
|
+
options.diagnostic(`${model.id}: added — \`${app.command} models download ${model.id}\` fetches and checks it`);
|
|
137
|
+
options.output(itemOf(textModelItem(model, env)), this);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
117
140
|
if (options.jsonOption)
|
|
118
141
|
for (const command of models.commands)
|
|
119
142
|
command.option("--json", "print JSON");
|
|
@@ -134,3 +157,69 @@ const downloadProgress = (emit, label) => {
|
|
|
134
157
|
emit({ event: "progress", step: "download", done, total, unit: "bytes", label });
|
|
135
158
|
};
|
|
136
159
|
};
|
|
160
|
+
/** One text model as `models list`, `download`, `use` and `add` print it, in every CLI. */
|
|
161
|
+
export const textModelItem = (model, env) => {
|
|
162
|
+
const directory = textModelsDirectory(env);
|
|
163
|
+
return {
|
|
164
|
+
id: model.id,
|
|
165
|
+
kind: "text",
|
|
166
|
+
title: model.title,
|
|
167
|
+
languages: model.languages,
|
|
168
|
+
licence: model.licence,
|
|
169
|
+
...(model.terms ? { terms: model.terms } : {}),
|
|
170
|
+
...(model.size ? { size: model.size } : {}),
|
|
171
|
+
dims: model.dims,
|
|
172
|
+
...(model.chunksPerSecond === undefined ? {} : { chunks_per_second: model.chunksPerSecond }),
|
|
173
|
+
...(model.custom ? { custom: true } : {}),
|
|
174
|
+
size_bytes: model.files.reduce((sum, file) => sum + file.bytes, 0),
|
|
175
|
+
downloaded: isTextModelInstalled(model, directory),
|
|
176
|
+
default: model.id === chosenTextModel(env).id,
|
|
177
|
+
path: join(directory, model.id),
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
export const SET_SUMMARY = "use this text model for every embed and search by meaning, in every CLI";
|
|
181
|
+
export const SET_DESCRIPTION = "make a downloaded text model the one every embed and every search by meaning uses, in every WireCat CLI. " +
|
|
182
|
+
"Each model keeps its own vectors: the next syncs embed what the new one lacks, and switching back is instant";
|
|
183
|
+
/** What `models set` adds to the model it prints. */
|
|
184
|
+
export const switchFields = ({ previous, toEmbed, estimateSeconds }) => ({
|
|
185
|
+
previous,
|
|
186
|
+
to_embed: toEmbed,
|
|
187
|
+
estimate_seconds: estimateSeconds,
|
|
188
|
+
});
|
|
189
|
+
export const switchNotes = ({ model, previous, toEmbed, estimateSeconds }) => {
|
|
190
|
+
if (previous === model.id)
|
|
191
|
+
return [`${model.id} is already the model in use`];
|
|
192
|
+
const work = estimateSeconds === null
|
|
193
|
+
? ""
|
|
194
|
+
: `, about ${estimateSeconds < 120 ? `${estimateSeconds} s` : `${Math.ceil(estimateSeconds / 60)} min`} of embedding`;
|
|
195
|
+
const left = toEmbed === null ? "everything" : `about ${toEmbed} chunk${toEmbed === 1 ? "" : "s"}`;
|
|
196
|
+
return [
|
|
197
|
+
`${model.id} is now in use instead of ${previous}; ${previous}'s vectors stay, so switching back is instant`,
|
|
198
|
+
`the syncs embed ${left} with it${work}, a part each sync; until then search by meaning finds only what ` +
|
|
199
|
+
"it has embedded, and words find the rest",
|
|
200
|
+
];
|
|
201
|
+
};
|
|
202
|
+
export const ADD_DESCRIPTION = "add an ONNX embedding model from Hugging Face, pinned and checked by sha256";
|
|
203
|
+
export const addExample = (command) => `${command} models add e5-base --payload '{"repository":"Xenova/multilingual-e5-base",` +
|
|
204
|
+
`"onnx":"onnx/model_quantized.onnx","dims":768,"pooling":"mean","prefix":{"query":"query: ","passage":"passage: "}}'`;
|
|
205
|
+
export const ADD_HELP = `
|
|
206
|
+
--payload is JSON:
|
|
207
|
+
repository the Hugging Face repository, owner/name
|
|
208
|
+
revision a branch, tag or commit (main); pinned to the commit it names now
|
|
209
|
+
onnx the ONNX file, e.g. onnx/model_quantized.onnx
|
|
210
|
+
externalData the weights file the ONNX file keeps beside itself, if any
|
|
211
|
+
dims the length of its vectors
|
|
212
|
+
pooling mean, or sentence_embedding for a model with that output
|
|
213
|
+
prefix {"query": "...", "passage": "..."}, put before a search and a stored text
|
|
214
|
+
maxTokens the longest text it reads (512); a longer one is cut
|
|
215
|
+
title, languages, licence, chunksPerSecond for models list; licence comes from the model card when left out
|
|
216
|
+
The repository needs tokenizer.json and tokenizer_config.json beside the ONNX file's folder.`;
|
|
217
|
+
/** `--payload`'s JSON, refused with the reason when it does not parse. */
|
|
218
|
+
export const payloadOf = (text) => {
|
|
219
|
+
try {
|
|
220
|
+
return JSON.parse(text);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
throw new CliError("validation_error", `--payload is not JSON: ${error.message}`);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
@@ -11,7 +11,9 @@ import { parseDuration } from "../../domain/duration.js";
|
|
|
11
11
|
import { HOLDER } from "../../mail/marks.js";
|
|
12
12
|
import { readOnlyLockOf } from "../../ports/app.js";
|
|
13
13
|
import { aheadOf } from "../../services/moment.js";
|
|
14
|
+
import { openCache } from "../../store/open.js";
|
|
14
15
|
import { storePath } from "../../store/path.js";
|
|
16
|
+
import { ownerLanguages } from "../../store/store.js";
|
|
15
17
|
import { environmentOf, setExitCode } from "../context.js";
|
|
16
18
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE, REMOTE_WRITE } from "../effects.js";
|
|
17
19
|
import { itemOf, listOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
@@ -154,6 +156,20 @@ const runCapOf = (argv) => {
|
|
|
154
156
|
const cap = at < 0 ? Number.NaN : Number(argv[at + 1]);
|
|
155
157
|
return Number.isFinite(cap) ? cap : null;
|
|
156
158
|
};
|
|
159
|
+
/** The language a report is rendered in: the store's `owner_languages`, first one; Russian when it cannot be read. */
|
|
160
|
+
const ownerLanguageOf = async (env) => {
|
|
161
|
+
const path = storePath(env);
|
|
162
|
+
if (!existsSync(path))
|
|
163
|
+
return "ru";
|
|
164
|
+
const database = await openCache(path);
|
|
165
|
+
try {
|
|
166
|
+
const table = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'store_settings'").get();
|
|
167
|
+
return (table ? ownerLanguages(database)[0] : undefined) ?? "ru";
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
database.close();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
157
173
|
/**
|
|
158
174
|
* Runs the CLI's own commands, or an agent, later or on a timer — through systemd (Linux), launchd
|
|
159
175
|
* (macOS) or Task Scheduler (Windows). Every timer runs `schedule exec <file>`; the schedule file holds
|
|
@@ -429,6 +445,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
429
445
|
const last = await untilChildEnds(this, (signal) => runSchedule(app, system, context.env, scheduleFile(state, scheduleName(name)), {
|
|
430
446
|
timer: timer(),
|
|
431
447
|
agentRuns,
|
|
448
|
+
ownerLanguage: ownerLanguageOf,
|
|
432
449
|
...(agentInput ? { agentInput } : {}),
|
|
433
450
|
...(signal ? { signal } : {}),
|
|
434
451
|
}));
|
|
@@ -465,6 +482,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
465
482
|
const last = await untilChildEnds(this, (signal) => runSchedule(app, system, context.env, file, {
|
|
466
483
|
timer: timer(),
|
|
467
484
|
agentRuns,
|
|
485
|
+
ownerLanguage: ownerLanguageOf,
|
|
468
486
|
...(agentInput ? { agentInput } : {}),
|
|
469
487
|
untilUnlocked: true,
|
|
470
488
|
...(signal ? { signal } : {}),
|
|
@@ -5,6 +5,7 @@ import { type PermissionKey } from "../sends/permissions.js";
|
|
|
5
5
|
declare const LIST_KEYS: {
|
|
6
6
|
readonly deal: "deals.list";
|
|
7
7
|
readonly lead: "leads.list";
|
|
8
|
+
readonly business: "business.list";
|
|
8
9
|
readonly messages: "messages.list";
|
|
9
10
|
readonly mail: "mail.list";
|
|
10
11
|
readonly notes: "notes.list";
|
|
@@ -5,6 +5,8 @@ import { settingsFor } from "./settings.js";
|
|
|
5
5
|
const LIST_KEYS = {
|
|
6
6
|
deal: "deals.list",
|
|
7
7
|
lead: "leads.list",
|
|
8
|
+
// No command lists business data across its types yet; the key is the lane's own, so a profile can turn it off.
|
|
9
|
+
business: "business.list",
|
|
8
10
|
messages: "messages.list",
|
|
9
11
|
mail: "mail.list",
|
|
10
12
|
notes: "notes.list",
|
|
@@ -8,11 +8,12 @@ import { DEFAULT_STEMMERS, parseStemmers } from "../search/stem.js";
|
|
|
8
8
|
import { openCache } from "../store/open.js";
|
|
9
9
|
import { storePath } from "../store/path.js";
|
|
10
10
|
import { applyTaskCategoryEdits, editsFrom, readTaskCategoryEdits, sharedConfigPath, writeTaskCategoryEdits, } from "../store/shared-config.js";
|
|
11
|
-
import { accountGroupsOf, crmSettingsOf, DEFAULT_AGENT_CLOSE, DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, openStore, parseCrmSetting, parseCrmSettingValue, saveCrmSetting, savedAgentClose, savedFirstPassPerChat, savedPhoneCountries, savedStemmers, savedTaskCategories, saveStorePhoneCountries, stemmersOrigin, } from "../store/store.js";
|
|
11
|
+
import { accountGroupsOf, crmSettingsOf, DEFAULT_AGENT_CLOSE, DEFAULT_FIRST_PASS_PER_CHAT, DEFAULT_OWNER_LANGUAGES, firstPassPerChatOf, openStore, parseCrmSetting, parseCrmSettingValue, parseOwnerLanguages, saveCrmSetting, savedAgentClose, savedFirstPassPerChat, savedOwnerLanguages, savedPhoneCountries, savedStemmers, savedTaskCategories, saveOwnerLanguages, saveStorePhoneCountries, stemmersOrigin, } from "../store/store.js";
|
|
12
12
|
const SCRIPTS = {
|
|
13
13
|
"search_stemmers.cyrillic": "cyrillic",
|
|
14
14
|
"search_stemmers.latin": "latin",
|
|
15
15
|
};
|
|
16
|
+
const OWNER_LANGUAGES = "owner_languages";
|
|
16
17
|
const PHONE_COUNTRIES = "phone_countries";
|
|
17
18
|
const TASK_CATEGORIES = "task_categories";
|
|
18
19
|
const CATEGORY_PREFIX = `${TASK_CATEGORIES}.`;
|
|
@@ -22,6 +23,7 @@ const FIRST_PASS = "task_first_pass_per_chat";
|
|
|
22
23
|
/** Settings of the store file, not of a profile: the store is one file for every profile, tg and MAX. */
|
|
23
24
|
export const STORE_SETTINGS = [
|
|
24
25
|
...Object.keys(SCRIPTS),
|
|
26
|
+
OWNER_LANGUAGES,
|
|
25
27
|
PHONE_COUNTRIES,
|
|
26
28
|
`${CATEGORY_PREFIX}<name>`,
|
|
27
29
|
AGENT_CLOSE,
|
|
@@ -36,10 +38,11 @@ const CRM_SETTINGS = ["crm.<provider>:<account>.links", "crm.<provider>:<account
|
|
|
36
38
|
* not a messenger would change them for tg and MAX without reading them itself.
|
|
37
39
|
*/
|
|
38
40
|
export const storeSettingsOf = (app) => app.messenger === false
|
|
39
|
-
? [...Object.keys(SCRIPTS), ...CRM_SETTINGS]
|
|
41
|
+
? [...Object.keys(SCRIPTS), OWNER_LANGUAGES, ...CRM_SETTINGS]
|
|
40
42
|
: [...STORE_SETTINGS, `${GROUP_PREFIX}<name>`, ...CRM_SETTINGS];
|
|
41
|
-
export const offersStoreSetting = (app, setting) => app.messenger !== false || setting in SCRIPTS || parseCrmSetting(setting) !== undefined;
|
|
43
|
+
export const offersStoreSetting = (app, setting) => app.messenger !== false || setting in SCRIPTS || setting === OWNER_LANGUAGES || parseCrmSetting(setting) !== undefined;
|
|
42
44
|
export const isStoreSetting = (setting) => setting in SCRIPTS ||
|
|
45
|
+
setting === OWNER_LANGUAGES ||
|
|
43
46
|
setting === PHONE_COUNTRIES ||
|
|
44
47
|
setting === TASK_CATEGORIES ||
|
|
45
48
|
setting.startsWith(CATEGORY_PREFIX) ||
|
|
@@ -53,6 +56,8 @@ export const changeStoreSetting = async (app, env, setting, value) => {
|
|
|
53
56
|
return changeGroup(app, env, setting, value);
|
|
54
57
|
if (parseCrmSetting(setting))
|
|
55
58
|
return changeCrm(env, setting, value);
|
|
59
|
+
if (setting === OWNER_LANGUAGES)
|
|
60
|
+
return changeOwnerLanguages(env, value);
|
|
56
61
|
if (setting === PHONE_COUNTRIES)
|
|
57
62
|
return changePhoneCountries(app, env, value);
|
|
58
63
|
if (setting === TASK_CATEGORIES || setting.startsWith(CATEGORY_PREFIX))
|
|
@@ -77,6 +82,27 @@ export const changeStoreSetting = async (app, env, setting, value) => {
|
|
|
77
82
|
await store.close();
|
|
78
83
|
}
|
|
79
84
|
};
|
|
85
|
+
const changeOwnerLanguages = async (env, value) => {
|
|
86
|
+
const languages = value === undefined ? undefined : parseOwnerLanguages(value);
|
|
87
|
+
await (await openStore({ env })).close();
|
|
88
|
+
const database = await openCache(storePath(env));
|
|
89
|
+
try {
|
|
90
|
+
saveOwnerLanguages(database, languages, Date.now());
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
database.close();
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
result: {
|
|
97
|
+
store: storePath(env),
|
|
98
|
+
scope: "store",
|
|
99
|
+
setting: OWNER_LANGUAGES,
|
|
100
|
+
value: (languages ?? DEFAULT_OWNER_LANGUAGES).join(","),
|
|
101
|
+
},
|
|
102
|
+
note: "store-wide — what every WireCat tool writes for the owner is in the first language; " +
|
|
103
|
+
"a title quoted in the others stays as written",
|
|
104
|
+
};
|
|
105
|
+
};
|
|
80
106
|
const changePhoneCountries = async (app, env, value) => {
|
|
81
107
|
const countries = value === undefined ? undefined : parsePhoneCountries(value);
|
|
82
108
|
// Opened as a store first, so a new or older file gets its tables before the setting is written.
|
|
@@ -276,6 +302,7 @@ export const storeSettings = async (env) => {
|
|
|
276
302
|
let byDefault = false;
|
|
277
303
|
let unreadable = false;
|
|
278
304
|
let groups = {};
|
|
305
|
+
let ownerLanguages;
|
|
279
306
|
let phoneCountries;
|
|
280
307
|
let categories;
|
|
281
308
|
let agentClose = {};
|
|
@@ -289,6 +316,7 @@ export const storeSettings = async (env) => {
|
|
|
289
316
|
saved = table ? savedStemmers(database) : undefined;
|
|
290
317
|
byDefault = table ? stemmersOrigin(database)?.origin === "default" : false;
|
|
291
318
|
groups = table ? accountGroupsOf(database) : {};
|
|
319
|
+
ownerLanguages = table ? savedOwnerLanguages(database) : undefined;
|
|
292
320
|
phoneCountries = table ? savedPhoneCountries(database) : undefined;
|
|
293
321
|
categories = table ? savedTaskCategories(database) : undefined;
|
|
294
322
|
agentClose = table ? savedAgentClose(database) : {};
|
|
@@ -318,6 +346,14 @@ export const storeSettings = async (env) => {
|
|
|
318
346
|
});
|
|
319
347
|
return [
|
|
320
348
|
...stemmers,
|
|
349
|
+
unreadable
|
|
350
|
+
? { setting: OWNER_LANGUAGES, value: null, from: "store unreadable", scope: "store" }
|
|
351
|
+
: {
|
|
352
|
+
setting: OWNER_LANGUAGES,
|
|
353
|
+
value: (ownerLanguages ?? DEFAULT_OWNER_LANGUAGES).join(","),
|
|
354
|
+
from: ownerLanguages ? "store" : "default",
|
|
355
|
+
scope: "store",
|
|
356
|
+
},
|
|
321
357
|
unreadable
|
|
322
358
|
? { setting: PHONE_COUNTRIES, value: null, from: "store unreadable", scope: "store" }
|
|
323
359
|
: {
|
package/dist/crm/cli/csv.d.ts
CHANGED
|
@@ -5,17 +5,30 @@ import type { CrmField } from "../../domain/crm.js";
|
|
|
5
5
|
* table carries no `untrusted` marker for an agent.
|
|
6
6
|
*/
|
|
7
7
|
export declare const csvFormatOption: () => Option;
|
|
8
|
-
/**
|
|
8
|
+
/** A CRM's own field as the table needs it: `fields list`'s code, label and type. */
|
|
9
|
+
export type CsvField = Pick<CrmField, "code" | "label" | "type">;
|
|
10
|
+
/** What a page of CRM rows gives the table: its rows as `--json` answers them, and the CRM's own fields. */
|
|
9
11
|
export interface CsvPage {
|
|
10
|
-
items: Record<string, unknown>[];
|
|
11
|
-
fields:
|
|
12
|
+
items: readonly Record<string, unknown>[];
|
|
13
|
+
fields: readonly CsvField[];
|
|
12
14
|
page: number;
|
|
13
15
|
hasMore: boolean;
|
|
14
16
|
}
|
|
17
|
+
/** A deal's or a lead's columns when `--json=a,b` names none. */
|
|
18
|
+
export declare const DEAL_CSV_COLUMNS: readonly string[];
|
|
15
19
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* `--json=a,b` beside `--format csv` names its columns, `items.` or not, as `--json` would keep them; without it, the
|
|
21
|
+
* caller's own. `provider_metadata` among them stands for every custom field.
|
|
18
22
|
*/
|
|
23
|
+
export declare const csvColumnPaths: (command: Command, defaults?: readonly string[]) => string[];
|
|
24
|
+
/**
|
|
25
|
+
* A table is for a person's spreadsheet: JSON, JSON lines, compact rows and an agent's run each ask for another.
|
|
26
|
+
* Called before the CRM is read.
|
|
27
|
+
*/
|
|
28
|
+
export declare const refuseCsvConflict: (command: Command) => void;
|
|
29
|
+
/** stdout carries the table and nothing else; the way to the next page goes to stderr. */
|
|
30
|
+
export declare const printCsv: (command: Command, page: CsvPage, paths: readonly string[]) => void;
|
|
31
|
+
/** Reads a page in the profile's run and closes it before the table is printed. */
|
|
19
32
|
export declare const renderCsv: <R extends {
|
|
20
33
|
close?: () => Promise<void>;
|
|
21
34
|
}>(command: Command, open: (command: Command, access: {
|
package/dist/crm/cli/csv.js
CHANGED
|
@@ -9,7 +9,8 @@ import { fieldsOf } from "../../cli/result-fields.js";
|
|
|
9
9
|
* table carries no `untrusted` marker for an agent.
|
|
10
10
|
*/
|
|
11
11
|
export const csvFormatOption = () => annotateOption(new Option("--format <format>", "csv: this page as a table for a spreadsheet; --json=a,b picks its columns").choices(["csv"]), { mcp: false });
|
|
12
|
-
|
|
12
|
+
/** A deal's or a lead's columns when `--json=a,b` names none. */
|
|
13
|
+
export const DEAL_CSV_COLUMNS = [
|
|
13
14
|
"ref",
|
|
14
15
|
"title",
|
|
15
16
|
"status",
|
|
@@ -31,12 +32,15 @@ const DEFAULT_COLUMNS = [
|
|
|
31
32
|
];
|
|
32
33
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
34
|
const at = (item, path) => path.reduce((value, key) => (isRecord(value) ? value[key] : undefined), item);
|
|
34
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* One cell's text: a phone or an e-mail by its value, a party by its name, a list joined, so no cell holds JSON a
|
|
37
|
+
* spreadsheet cannot read.
|
|
38
|
+
*/
|
|
35
39
|
const flat = (value) => {
|
|
36
40
|
if (Array.isArray(value))
|
|
37
41
|
return value.map(flat).join("; ");
|
|
38
42
|
if (isRecord(value))
|
|
39
|
-
return value.name ?? value.ref ?? JSON.stringify(value);
|
|
43
|
+
return value.value ?? value.name ?? value.ref ?? JSON.stringify(value);
|
|
40
44
|
return value;
|
|
41
45
|
};
|
|
42
46
|
const MONEY = /^(-?\d+(?:\.\d+)?)\|([A-Za-z]{3})$/;
|
|
@@ -66,7 +70,7 @@ const customFieldsOf = (page) => {
|
|
|
66
70
|
for (const [code, value] of Object.entries(metadata))
|
|
67
71
|
if (!listed.has(code) && !extra.has(code)) {
|
|
68
72
|
const label = isRecord(value) && typeof value.label === "string" ? value.label : null;
|
|
69
|
-
extra.set(code, { code, label, type: "string"
|
|
73
|
+
extra.set(code, { code, label, type: "string" });
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
return [...page.fields, ...extra.values()];
|
|
@@ -89,18 +93,24 @@ const columnsOf = (page, paths) => {
|
|
|
89
93
|
return chosen.flatMap((field) => customColumns(field, headerOf(field)));
|
|
90
94
|
});
|
|
91
95
|
};
|
|
92
|
-
/**
|
|
93
|
-
|
|
96
|
+
/**
|
|
97
|
+
* `--json=a,b` beside `--format csv` names its columns, `items.` or not, as `--json` would keep them; without it, the
|
|
98
|
+
* caller's own. `provider_metadata` among them stands for every custom field.
|
|
99
|
+
*/
|
|
100
|
+
export const csvColumnPaths = (command, defaults = DEAL_CSV_COLUMNS) => {
|
|
94
101
|
const fields = command.optsWithGlobals().fields;
|
|
95
102
|
if (fields === undefined)
|
|
96
|
-
return
|
|
103
|
+
return [...defaults];
|
|
97
104
|
return fieldsOf(fields).map((path) => (path.startsWith("items.") ? path.slice("items.".length) : path));
|
|
98
105
|
};
|
|
99
106
|
const refuse = (message) => {
|
|
100
107
|
throw new CliError("validation_error", message, { reason: "output.conflict", param: "--format" });
|
|
101
108
|
};
|
|
102
|
-
/**
|
|
103
|
-
|
|
109
|
+
/**
|
|
110
|
+
* A table is for a person's spreadsheet: JSON, JSON lines, compact rows and an agent's run each ask for another.
|
|
111
|
+
* Called before the CRM is read.
|
|
112
|
+
*/
|
|
113
|
+
export const refuseCsvConflict = (command) => {
|
|
104
114
|
const globals = command.optsWithGlobals();
|
|
105
115
|
if (environmentOf(command).agent)
|
|
106
116
|
refuse("--format csv is a table for a spreadsheet; an agent reads the JSON answer");
|
|
@@ -111,12 +121,17 @@ const refuseOtherOutput = (command) => {
|
|
|
111
121
|
if (globals.json && globals.fields === undefined)
|
|
112
122
|
refuse("--format csv and --json ask for different output — --json=a,b picks the table's columns");
|
|
113
123
|
};
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
/** stdout carries the table and nothing else; the way to the next page goes to stderr. */
|
|
125
|
+
export const printCsv = (command, page, paths) => {
|
|
126
|
+
const columns = columnsOf(page, paths);
|
|
127
|
+
const { streams, renderer } = outputFor(command);
|
|
128
|
+
writeCsv(streams, columns.map((column) => column.header), page.items.map((item) => columns.map((column) => column.cell(item))));
|
|
129
|
+
if (page.hasMore)
|
|
130
|
+
renderer.note(`→ more rows: run it again with --page ${page.page + 1}`);
|
|
131
|
+
};
|
|
132
|
+
/** Reads a page in the profile's run and closes it before the table is printed. */
|
|
118
133
|
export const renderCsv = (command, open, read) => {
|
|
119
|
-
|
|
134
|
+
refuseCsvConflict(command);
|
|
120
135
|
return inCommandRun(command, async () => {
|
|
121
136
|
const run = await open(command, { readOnly: true });
|
|
122
137
|
let page;
|
|
@@ -126,10 +141,6 @@ export const renderCsv = (command, open, read) => {
|
|
|
126
141
|
finally {
|
|
127
142
|
await run.close?.();
|
|
128
143
|
}
|
|
129
|
-
|
|
130
|
-
const { streams, renderer } = outputFor(command);
|
|
131
|
-
writeCsv(streams, columns.map((column) => column.header), page.items.map((item) => columns.map((column) => column.cell(item))));
|
|
132
|
-
if (page.hasMore)
|
|
133
|
-
renderer.note(`→ more rows: run it again with --page ${page.page + 1}`);
|
|
144
|
+
printCsv(command, page, csvColumnPaths(command));
|
|
134
145
|
});
|
|
135
146
|
};
|
package/dist/crm/cli/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { AccountKey } from "../../store/types.js";
|
|
|
6
6
|
import type { CrmSource } from "../source.js";
|
|
7
7
|
import type { CrmWriteCapabilities } from "../writer.js";
|
|
8
8
|
import { type CrmWrites } from "../writes.js";
|
|
9
|
+
export { type CsvField, type CsvPage, csvColumnPaths, csvFormatOption, DEAL_CSV_COLUMNS, printCsv, refuseCsvConflict, } from "./csv.js";
|
|
9
10
|
/**
|
|
10
11
|
* The selected profile's CRM account, opened by the app for one command and closed once its answer is built, before
|
|
11
12
|
* anything is printed (WC-LIFE-4).
|
package/dist/crm/cli/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { closeCrmItem, createCrmItem, fieldPairsOf, moveCrmItem, pipelineOf, rem
|
|
|
19
19
|
import { csvFormatOption, renderCsv } from "./csv.js";
|
|
20
20
|
import { pipelineView } from "./pipeline-view.js";
|
|
21
21
|
import { addCrmSearchAll } from "./search-all.js";
|
|
22
|
+
export { csvColumnPaths, csvFormatOption, DEAL_CSV_COLUMNS, printCsv, refuseCsvConflict, } from "./csv.js";
|
|
22
23
|
const MOST = 500;
|
|
23
24
|
const DEAL_FIELDS = [
|
|
24
25
|
termField("status", "enum", "status:open", { values: DEAL_STATUSES }),
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type FinanceReview, type MoneyDirection } from "./finance.js";
|
|
2
2
|
export declare const CATALOG_KINDS: readonly ["product", "service"];
|
|
3
|
+
/** What the `business` lane of `search all` reads; transactions are too many to fold per query. */
|
|
4
|
+
export declare const BUSINESS_KINDS: readonly ["invoice", "payment", "order", "contract", "subscription", "product", "wallet"];
|
|
5
|
+
export type BusinessKind = (typeof BUSINESS_KINDS)[number];
|
|
3
6
|
export declare const CONTRACT_KINDS: readonly ["sale", "purchase", "service", "lease", "employment", "nda", "license", "other"];
|
|
4
7
|
export declare const CONTRACT_STATUSES: readonly ["draft", "active", "ended", "terminated"];
|
|
5
8
|
export declare const PERIOD_UNITS: readonly ["day", "week", "month", "year"];
|
package/dist/domain/business.js
CHANGED
|
@@ -2,6 +2,8 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { dayMonth, notes } from "./finance.js";
|
|
3
3
|
import { moneyLabel } from "./money.js";
|
|
4
4
|
export const CATALOG_KINDS = ["product", "service"];
|
|
5
|
+
/** What the `business` lane of `search all` reads; transactions are too many to fold per query. */
|
|
6
|
+
export const BUSINESS_KINDS = ["invoice", "payment", "order", "contract", "subscription", "product", "wallet"];
|
|
5
7
|
export const CONTRACT_KINDS = ["sale", "purchase", "service", "lease", "employment", "nda", "license", "other"];
|
|
6
8
|
export const CONTRACT_STATUSES = ["draft", "active", "ended", "terminated"];
|
|
7
9
|
export const PERIOD_UNITS = ["day", "week", "month", "year"];
|