@wirecat/cli-core 0.687.0 → 0.688.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 +56 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/envelope.js +2 -3
- package/dist/cli/meeting-batch.js +5 -1
- package/dist/cli/meeting-passage-text.d.ts +1 -1
- package/dist/cli/meeting-passage-text.js +3 -5
- package/dist/cli/messenger/conversations-command.js +4 -0
- package/dist/cli/messenger/messages-search-command.js +6 -1
- package/dist/cli/messenger/search-answers.js +2 -0
- package/dist/cli/search-left-out.d.ts +3 -0
- package/dist/cli/search-left-out.js +12 -0
- package/dist/cli/store-settings.js +23 -4
- package/dist/cli/untrusted-marks.d.ts +2 -0
- package/dist/cli/untrusted-marks.js +6 -0
- package/dist/crm/cli/files.d.ts +68 -0
- package/dist/crm/cli/files.js +616 -0
- package/dist/crm/cli/index.d.ts +1 -0
- package/dist/crm/cli/index.js +3 -0
- package/dist/crm/cli/search-all.js +3 -2
- package/dist/crm/file-fetch.d.ts +15 -0
- package/dist/crm/file-fetch.js +61 -0
- package/dist/crm/index.d.ts +1 -0
- package/dist/crm/index.js +1 -0
- package/dist/crm/testing/files-contract.d.ts +17 -0
- package/dist/crm/testing/files-contract.js +142 -0
- package/dist/crm/testing/index.d.ts +1 -0
- package/dist/crm/testing/index.js +1 -0
- package/dist/crm/testing/source.d.ts +5 -0
- package/dist/crm/testing/source.js +3 -1
- package/dist/entities/hit.d.ts +3 -3
- package/dist/entities/hit.js +14 -3
- package/dist/entities/index.d.ts +1 -1
- package/dist/errors/reasons.js +12 -1
- package/dist/files/safe-name.d.ts +2 -1
- package/dist/files/safe-name.js +21 -3
- package/dist/meetings/mcp/passage.d.ts +6 -2
- package/dist/meetings/mcp/passage.js +7 -3
- package/dist/search/respell.d.ts +10 -0
- package/dist/search/respell.js +63 -0
- package/dist/search/stem.d.ts +16 -3
- package/dist/search/stem.js +32 -4
- package/dist/services/embeddings-search.js +169 -141
- package/dist/services/embeddings.d.ts +8 -0
- package/dist/services/messages-archive-search.js +55 -3
- package/dist/services/messages-search.d.ts +2 -1
- package/dist/services/messages-search.js +19 -7
- package/dist/services/messages.d.ts +8 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/named-chat.d.ts +20 -0
- package/dist/services/named-chat.js +63 -0
- package/dist/services/search-all.d.ts +7 -2
- package/dist/services/search-all.js +35 -1
- package/dist/store/exports.d.ts +1 -1
- package/dist/store/exports.js +1 -1
- package/dist/store/search-index.d.ts +2 -0
- package/dist/store/search-index.js +1 -0
- package/dist/store/sqlite/crm-files.d.ts +3 -0
- package/dist/store/sqlite/crm-files.js +2 -0
- package/dist/store/sqlite/crm-settings.d.ts +42 -1
- package/dist/store/sqlite/crm-settings.js +46 -2
- package/dist/store/sqlite/lucene-fields.d.ts +2 -0
- package/dist/store/sqlite/lucene-fields.js +6 -2
- package/dist/store/sqlite/lucene.js +2 -2
- package/dist/store/sqlite/stems.d.ts +2 -0
- package/dist/store/sqlite/stems.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,62 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.688.0 — 17.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`files list`, `files download` and `files sync` in every CRM CLI** whose adapter has `files`
|
|
13
|
+
(`addCrmCommands(program, { files: true })`). `files list --deal|--lead|--person|--organization <id>` reads a
|
|
14
|
+
record's files live; `files download <id>` saves one under the state folder (folders 700, file 600) or `--dir`, at
|
|
15
|
+
most 100 MB unless `--max-size` (up to 2048), and reads its text; `files sync` prefetches the files of your own deals
|
|
16
|
+
and leads changed in the last `files.days`, within per-run limits, and goes on where it stopped. A colleague's record
|
|
17
|
+
counts toward the day's limit of 100.
|
|
18
|
+
- **CRM file limits** as owner-only store settings `crm.<provider>:<account>.files.max_files`, `max_file_mb`,
|
|
19
|
+
`max_run_mb`, `run_minutes`, `days` and `max_total_mb`; a value outside its range is refused. The account's folder
|
|
20
|
+
is kept under `max_total_mb` by dropping the oldest files whose text is kept.
|
|
21
|
+
- **`search all` finds the text of downloaded CRM files** (`crm_file` hits, also under `--only crm`): a limited profile
|
|
22
|
+
only those of records assigned to it, in the CRM CLI's and in memo's and tg's `search all` alike.
|
|
23
|
+
- **`fetchCrmFile`** for adapters: a file link fetched over https from the account's own hosts only, never naming the
|
|
24
|
+
link in an error; **`crmFilesContract`** in `@wirecat/cli-core/crm/testing`.
|
|
25
|
+
- **`search messages` helps a query of plain words the way `search conversations` does.** A word no message holds is
|
|
26
|
+
searched beside its Latin spelling or nearest known spellings (a note says so). Without `chat:`, a word
|
|
27
|
+
the messages show is a name in one private chat has that chat's hits first, searched without the name
|
|
28
|
+
(a note says so). A query with fields, quotes, groups or operators is searched exactly as written.
|
|
29
|
+
- **`search conversations` over every chat searches first the private chat a name in the query points to.** The name
|
|
30
|
+
is learned from the messages, with no list of nicknames: the private chat that holds most of a word's uses, at least
|
|
31
|
+
twice as many as any other private chat, and writes it with a capital letter nearly every time («Петька, привет»).
|
|
32
|
+
That chat is searched without the name and its hits come first; a note says so. An ordinary word, spread over many chats in lower case, names none.
|
|
33
|
+
- **`search conversations` respells a query word that no message holds.** It searches the word's Latin spelling
|
|
34
|
+
(«ноксвел» → `noxvel`) or the nearest known spellings of that, and only when there are none, the word's own nearest
|
|
35
|
+
known spellings, up to two edits. A word any message holds is never respelled. A note says what was searched instead.
|
|
36
|
+
|
|
37
|
+
### Changed — may break callers
|
|
38
|
+
|
|
39
|
+
- **memo's, tg's and the MCP's `search all` apply each CRM copy's viewer rule to deals and leads too**, taking the
|
|
40
|
+
user that copy's own sync signed in as: a non-admin copy's colleagues' deals no longer show there, as they never
|
|
41
|
+
did in the CRM CLI. A copy with no recorded own user shows none of its deals and leads there; a copy whose sync
|
|
42
|
+
recorded no list of who may read it shows only its own user's.
|
|
43
|
+
- **`search all` has a new hit kind, `crm_file`**, in every CLI: a caller that switches over `kind` gets it.
|
|
44
|
+
- **`safeName` cuts a name to 200 bytes**, its extension kept, for every download that uses it.
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- **`meetings batch --format text|markdown` marks other people's text in a scheduled agent's run.** Transcript cues
|
|
49
|
+
and search hit excerpts and titles were printed with no untrusted marks; only JSON carried them. The report a host
|
|
50
|
+
formats with `formatMeetingBatch` now comes marked, so a host needs no change.
|
|
51
|
+
- **`callMeetingPassageTool` takes how the host prints a passage in this run.** Pass
|
|
52
|
+
`(result, format) => passageForRun(command, result, format)` as its new last argument, and the `meeting_passage`
|
|
53
|
+
text carries the same marks as `meetings passage` in a scheduled agent's run. Without it the text stays unmarked.
|
|
54
|
+
- **`search conversations --chat` no longer stops at 20 word hits.** The per-chat share that keeps a large group from
|
|
55
|
+
filling the list across chats also applied inside one chat, so a word used often there found only 20 messages.
|
|
56
|
+
- **A message search for «домен» no longer finds «дом» and «дома».** Snowball cuts some words to another word's stem.
|
|
57
|
+
When a query word's stem is under 4 letters, drops 2 or more letters, and the stored stems show the whole word is a
|
|
58
|
+
stem itself («доменов» → «домен»), the search keeps the word whole. The stems stored for messages do not change.
|
|
59
|
+
- **A message search for a word of 4 letters or more also finds the longer words it begins, as grep does.** Snowball
|
|
60
|
+
stems some forms of one word apart («журнал» → «журна», «журналом» → «журнал»), so a search found only the
|
|
61
|
+
forms that shared the typed word's stem. Quotes keep the old match: the word and its stem's forms only. The note now
|
|
62
|
+
says what was searched: `квартира → квартира… and words stemmed to квартир`.
|
|
63
|
+
|
|
8
64
|
## 0.687.0 — 16.11.2026
|
|
9
65
|
|
|
10
66
|
### Added
|
|
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
|
|
26
26
|
export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
27
|
+
action?: undefined;
|
|
27
28
|
name: string;
|
|
28
29
|
installed: boolean;
|
|
29
30
|
active: boolean;
|
|
30
31
|
servicePath: string;
|
|
31
32
|
timerPath: string;
|
|
32
|
-
action?: undefined;
|
|
33
33
|
} | {
|
|
34
34
|
active?: undefined;
|
|
35
35
|
name: string;
|
|
@@ -56,8 +56,8 @@ export interface CopyAge {
|
|
|
56
56
|
}
|
|
57
57
|
export declare const ageOf: (lastSync: string | undefined, now?: number) => CopyAge;
|
|
58
58
|
export declare const staleCopy: (provider: string, lastSync: string | undefined, now?: number) => {
|
|
59
|
-
missing?: undefined;
|
|
60
59
|
next?: undefined;
|
|
60
|
+
missing?: undefined;
|
|
61
61
|
meta?: undefined;
|
|
62
62
|
} | {
|
|
63
63
|
missing: {
|
package/dist/cli/envelope.js
CHANGED
|
@@ -10,7 +10,7 @@ import { environmentOf, setExitCode } from "./context.js";
|
|
|
10
10
|
import { largeAnswerSteps, SOFT_OUTPUT_BYTES } from "./output-budget.js";
|
|
11
11
|
import { withoutProviderRefs } from "./provider-refs.js";
|
|
12
12
|
import { nextStep, rootOf, runnable, stepLine, withLines, withSafety } from "./steps.js";
|
|
13
|
-
import {
|
|
13
|
+
import { runMarkOf, untrustedFieldsOf, withFieldsMarked, withUntrustedMarked } from "./untrusted-marks.js";
|
|
14
14
|
/** Every answer: a list or one thing, with items of `item` — any value where the command declares no entity. */
|
|
15
15
|
export const answerSchema = (item = v.unknown()) => v.union([listEnvelopeSchema(item), itemEnvelopeSchema(item)]);
|
|
16
16
|
const capped = (steps) => (steps.length > 0 ? { next: steps.slice(0, MAX_NEXT_STEPS) } : {});
|
|
@@ -185,8 +185,7 @@ export const renderAnswer = (command, { renderer, format, streams, compact, full
|
|
|
185
185
|
const root = rootOf(command);
|
|
186
186
|
const runnableSteps = runnable(root, body.next);
|
|
187
187
|
const next = environmentOf(command).agent ? runnableSteps : withLines(root, runnableSteps);
|
|
188
|
-
const
|
|
189
|
-
const mark = app ? untrustedMarkOf(app, env ?? process.env) : undefined;
|
|
188
|
+
const mark = runMarkOf(command);
|
|
190
189
|
const declared = untrustedFieldsOf(command);
|
|
191
190
|
const shown = mark === undefined ? body : withUntrustedMarked(declared ? withFieldsMarked(body, declared, mark) : body, mark);
|
|
192
191
|
const kept = withoutProviderRefs({ ...shown, ...(next.length > 0 ? { next } : {}) });
|
|
@@ -12,6 +12,7 @@ import { answerEntity } from "./answer-entity.js";
|
|
|
12
12
|
import { destroysNothing } from "./effects.js";
|
|
13
13
|
import { answerSchema, itemOf, listOf } from "./envelope.js";
|
|
14
14
|
import { pagingOf } from "./paging.js";
|
|
15
|
+
import { runMarkOf, withUntrustedMarked } from "./untrusted-marks.js";
|
|
15
16
|
const INDEX_BYTES = 4194304;
|
|
16
17
|
const parse = (command, args) => {
|
|
17
18
|
command
|
|
@@ -148,6 +149,9 @@ export const addMeetingBatchCommand = (program, deps) => {
|
|
|
148
149
|
fields,
|
|
149
150
|
failureContext: failureContext(),
|
|
150
151
|
});
|
|
152
|
+
// The host formats text and Markdown from the report; JSON is marked by `renderAnswer`.
|
|
153
|
+
const mark = format === "json" ? undefined : runMarkOf(action);
|
|
154
|
+
const shown = mark === undefined ? report : withUntrustedMarked(report, mark);
|
|
151
155
|
const issues = report.items
|
|
152
156
|
.filter((item) => !item.complete)
|
|
153
157
|
.map((item) => ({
|
|
@@ -167,7 +171,7 @@ export const addMeetingBatchCommand = (program, deps) => {
|
|
|
167
171
|
...(issues.length ? { issues } : {}),
|
|
168
172
|
...(report.output_limited ? { truncated: true } : {}),
|
|
169
173
|
},
|
|
170
|
-
}),
|
|
174
|
+
}), shown, format);
|
|
171
175
|
});
|
|
172
176
|
destroysNothing(command);
|
|
173
177
|
annotate(command, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
2
|
import type { MeetingPassageOutputFormat, MeetingPassageResult } from "../meetings/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* The passage as the host prints it from `meetings passage`'s `output
|
|
4
|
+
* The passage as the host prints it from `meetings passage`'s `output`, or as `callMeetingPassageTool` answers it: in a scheduled agent's run, text and Markdown
|
|
5
5
|
* are formatted again from the marked cues. The meetings module cannot read the run's mark; JSON is marked by
|
|
6
6
|
* `renderAnswer`.
|
|
7
7
|
*/
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { formatMeetingPassage } from "../services/meeting-passage-format.js";
|
|
2
|
-
import {
|
|
3
|
-
import { untrustedMarkOf, withUntrustedMarked } from "./untrusted-marks.js";
|
|
2
|
+
import { runMarkOf, withUntrustedMarked } from "./untrusted-marks.js";
|
|
4
3
|
/**
|
|
5
|
-
* The passage as the host prints it from `meetings passage`'s `output
|
|
4
|
+
* The passage as the host prints it from `meetings passage`'s `output`, or as `callMeetingPassageTool` answers it: in a scheduled agent's run, text and Markdown
|
|
6
5
|
* are formatted again from the marked cues. The meetings module cannot read the run's mark; JSON is marked by
|
|
7
6
|
* `renderAnswer`.
|
|
8
7
|
*/
|
|
9
8
|
export const passageForRun = (command, result, format) => {
|
|
10
|
-
const
|
|
11
|
-
const mark = app ? untrustedMarkOf(app, env ?? process.env) : undefined;
|
|
9
|
+
const mark = runMarkOf(command);
|
|
12
10
|
if (mark === undefined || format === "json")
|
|
13
11
|
return result;
|
|
14
12
|
return { ...result, content: formatMeetingPassage(withUntrustedMarked(result.packet, mark), format) };
|
|
@@ -626,6 +626,10 @@ export const conversationsSearchCommand = (messenger) => syncOptions(boundOption
|
|
|
626
626
|
if (refreshed)
|
|
627
627
|
for (const note of leftNotes(refreshed, rootOf(this)))
|
|
628
628
|
context.renderer.note(note);
|
|
629
|
+
for (const [word, forms] of Object.entries(found.respelled ?? {}))
|
|
630
|
+
context.renderer.note(`no message holds «${word}»: searched ${forms.map((form) => `«${form}»`).join(", ")} instead`);
|
|
631
|
+
if (found.named)
|
|
632
|
+
context.renderer.note(`«${found.named.word}» is a name in chat ${found.named.title ?? found.named.chatId} (${found.named.chatId}): its hits come first`);
|
|
629
633
|
if (found.words === "out-of-time")
|
|
630
634
|
context.renderer.note("the word half ran out of time, so these are by meaning alone; --timeout gives it longer");
|
|
631
635
|
renderAnswer(this, context, foundConversations("search conversations", found, limit, messenger, chat, window.meta), () => found.hits.map((hit) => `${hitLine(hit)}\n`).join(""));
|
|
@@ -7,6 +7,7 @@ import { syncsOneChat } from "../../ports/traits.js";
|
|
|
7
7
|
import { renderMessages } from "../../render/messages.js";
|
|
8
8
|
import { renderThreadLinks } from "../../render/thread-context.js";
|
|
9
9
|
import { searchTimeLimit } from "../../search/lucene/types.js";
|
|
10
|
+
import { START_LETTERS } from "../../search/stem.js";
|
|
10
11
|
import { environmentOf } from "../context.js";
|
|
11
12
|
import { REMOTE_READ } from "../effects.js";
|
|
12
13
|
import { renderAnswer } from "../envelope.js";
|
|
@@ -133,6 +134,10 @@ const searchAction = (messenger) => async function (given) {
|
|
|
133
134
|
const { command } = messenger.app;
|
|
134
135
|
for (const { from, to } of found.corrections)
|
|
135
136
|
context.renderer.note(`${from} → ${to.join(", ")}`);
|
|
137
|
+
for (const [word, forms] of Object.entries(found.respelled ?? {}))
|
|
138
|
+
context.renderer.note(`no message holds «${word}»: also searched ${forms.map((form) => `«${form}»`).join(", ")}`);
|
|
139
|
+
if (found.named)
|
|
140
|
+
context.renderer.note(`«${found.named.word}» is a name in chat ${found.named.title ?? found.named.chatId} (${found.named.chatId}): its hits come first`);
|
|
136
141
|
for (const { source, reason } of found.skipped ?? [])
|
|
137
142
|
context.renderer.note(`${source} not searched: ${reason}`);
|
|
138
143
|
if (found.meaningSkipped)
|
|
@@ -145,7 +150,7 @@ const searchAction = (messenger) => async function (given) {
|
|
|
145
150
|
const stemming = found.query?.stemming;
|
|
146
151
|
const forms = (stemming?.applied ? stemming.terms : []).filter(({ stemmer }) => stemmer !== "none");
|
|
147
152
|
if (forms.length > 0)
|
|
148
|
-
context.renderer.note(`also found other forms: ${forms.map(({ word, stem, stemmer }) => `${word} → ${stem}
|
|
153
|
+
context.renderer.note(`also found other forms: ${forms.map(({ word, stem, stemmer }) => `${word} → ${[...word].length >= START_LETTERS ? `${word}… and ` : ""}words stemmed to ${stem} (${stemmer})`).join(", ")} — --exact for the exact words only`);
|
|
149
154
|
if (stemming?.applied === false)
|
|
150
155
|
context.renderer.note(stemming.reason === "building"
|
|
151
156
|
? `other forms of words are not searched yet: the stems are ${Math.floor((stemming.done / Math.max(stemming.total, 1)) * 100)}% built — \`${command} store migrate\` finishes them`
|
|
@@ -295,6 +295,8 @@ const ALL_HIT_UNTRUSTED = {
|
|
|
295
295
|
// A CRM's copy is typed by the CRM's users; the owner's own deal is his, but one rule keeps a hit's marking simple.
|
|
296
296
|
deal: ["title", "excerpt"],
|
|
297
297
|
lead: ["title", "excerpt"],
|
|
298
|
+
// A client's file: its name and every word of it are someone else's.
|
|
299
|
+
crm_file: ["title", "excerpt"],
|
|
298
300
|
...BUSINESS_UNTRUSTED,
|
|
299
301
|
};
|
|
300
302
|
export const allHitItem = (item) => item.kind === "meeting"
|
|
@@ -11,6 +11,7 @@ declare const LIST_KEYS: {
|
|
|
11
11
|
readonly notes: "notes.list";
|
|
12
12
|
readonly events: "events.list";
|
|
13
13
|
readonly meetings: "meetings.list";
|
|
14
|
+
readonly crm_file: "files.list";
|
|
14
15
|
};
|
|
15
16
|
export type SearchedKind = keyof typeof LIST_KEYS;
|
|
16
17
|
export interface LeftOut<K extends SearchedKind> {
|
|
@@ -30,4 +31,6 @@ export declare const deniedKindsOf: <K extends SearchedKind>(permissions: Readon
|
|
|
30
31
|
* server's own stricter ones.
|
|
31
32
|
*/
|
|
32
33
|
export declare const deniedKinds: <K extends SearchedKind>(command: Command, app: AppIdentity, kinds: readonly K[]) => LeftOut<K>[];
|
|
34
|
+
/** The level the profile, `--permission` and an MCP server's own levels give `key` for this run. */
|
|
35
|
+
export declare const commandLevel: (command: Command, app: AppIdentity, key: PermissionKey) => Level;
|
|
33
36
|
export {};
|
|
@@ -12,6 +12,7 @@ const LIST_KEYS = {
|
|
|
12
12
|
notes: "notes.list",
|
|
13
13
|
events: "events.list",
|
|
14
14
|
meetings: "meetings.list",
|
|
15
|
+
crm_file: "files.list",
|
|
15
16
|
};
|
|
16
17
|
/**
|
|
17
18
|
* The kinds whose list `permissions` deny, for a CLI with levels of its own, such as memo's: `by` names who denies in
|
|
@@ -36,3 +37,14 @@ export const deniedKinds = (command, app, kinds) => {
|
|
|
36
37
|
});
|
|
37
38
|
return deniedKindsOf(permissions, kinds, `profile ${profile}`, environment.permissionDefaults);
|
|
38
39
|
};
|
|
40
|
+
/** The level the profile, `--permission` and an MCP server's own levels give `key` for this run. */
|
|
41
|
+
export const commandLevel = (command, app, key) => {
|
|
42
|
+
const environment = environmentOf(command);
|
|
43
|
+
const resolve = environment.resolveSettings ?? settingsFor(app).resolveSettings;
|
|
44
|
+
const { permissions } = resolve(withAgentLevels(command, command.optsWithGlobals()), {
|
|
45
|
+
env: environment.env ?? process.env,
|
|
46
|
+
needsProfile: false,
|
|
47
|
+
readOnly: true,
|
|
48
|
+
});
|
|
49
|
+
return levelFor(permissions, key, environment.permissionDefaults).level;
|
|
50
|
+
};
|
|
@@ -9,7 +9,7 @@ import { DEFAULT_STEMMERS, parseStemmers } from "../search/stem.js";
|
|
|
9
9
|
import { openCache } from "../store/open.js";
|
|
10
10
|
import { storePath } from "../store/path.js";
|
|
11
11
|
import { applyTaskCategoryEdits, editsFrom, readTaskCategoryEdits, sharedConfigPath, writeTaskCategoryEdits, } from "../store/shared-config.js";
|
|
12
|
-
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
|
+
import { accountGroupsOf, CRM_FILE_LIMITS, 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";
|
|
13
13
|
const SCRIPTS = {
|
|
14
14
|
"search_stemmers.cyrillic": "cyrillic",
|
|
15
15
|
"search_stemmers.latin": "latin",
|
|
@@ -34,9 +34,19 @@ export const STORE_SETTINGS = [
|
|
|
34
34
|
const GROUP_PREFIX = `${ACCOUNT_GROUPS_SETTING}.`;
|
|
35
35
|
/**
|
|
36
36
|
* A CRM account's: whether what it reports is a relationship or waits for review, what its company types mean, whose
|
|
37
|
-
* deals and leads its sync copies, which stages open a task,
|
|
37
|
+
* deals and leads its sync copies, which stages open a task, whether activities and tasks are read, and the limits
|
|
38
|
+
* of downloading its files.
|
|
38
39
|
*/
|
|
39
|
-
const CRM_SETTINGS = [
|
|
40
|
+
const CRM_SETTINGS = [
|
|
41
|
+
"links",
|
|
42
|
+
"company-types",
|
|
43
|
+
"scope",
|
|
44
|
+
"unassigned",
|
|
45
|
+
"self",
|
|
46
|
+
"stage-tasks",
|
|
47
|
+
"activities",
|
|
48
|
+
...Object.keys(CRM_FILE_LIMITS).map((name) => `files.${name}`),
|
|
49
|
+
].map((name) => `crm.<provider>:<account>.${name}`);
|
|
40
50
|
/**
|
|
41
51
|
* The store settings a CLI offers. Phone countries, task rules and account groups belong to messages; a CLI that is
|
|
42
52
|
* not a messenger would change them for tg and MAX without reading them itself.
|
|
@@ -51,7 +61,13 @@ export const offersStoreSetting = (app, setting) => app.messenger !== false || s
|
|
|
51
61
|
*/
|
|
52
62
|
export const isOwnerOnlyStoreSetting = (setting) => {
|
|
53
63
|
const name = parseCrmSetting(setting)?.name;
|
|
54
|
-
return name === "scope" ||
|
|
64
|
+
return (name === "scope" ||
|
|
65
|
+
name === "self" ||
|
|
66
|
+
name === "unassigned" ||
|
|
67
|
+
name === "stage-tasks" ||
|
|
68
|
+
name === "activities" ||
|
|
69
|
+
// An agent must not lift the limits on what it may download.
|
|
70
|
+
name?.startsWith("files.") === true);
|
|
55
71
|
};
|
|
56
72
|
export const isStoreSetting = (setting) => setting in SCRIPTS ||
|
|
57
73
|
setting === OWNER_LANGUAGES ||
|
|
@@ -277,8 +293,11 @@ const CRM_DEFAULTS = {
|
|
|
277
293
|
self: "",
|
|
278
294
|
"stage-tasks": {},
|
|
279
295
|
activities: "off",
|
|
296
|
+
...Object.fromEntries(Object.entries(CRM_FILE_LIMITS).map(([name, range]) => [`files.${name}`, range.default])),
|
|
280
297
|
};
|
|
281
298
|
const crmNote = (name, now) => {
|
|
299
|
+
if (name.startsWith("files."))
|
|
300
|
+
return `store-wide — files sync and files download of that account keep to it from the next run`;
|
|
282
301
|
if (name === "links")
|
|
283
302
|
return `store-wide — the next sync of that account writes what it reports as ${now === "review" ? "proposals for the owner to review" : "reported relationships"}; relationships already stored stay`;
|
|
284
303
|
if (name === "company-types")
|
|
@@ -5,6 +5,8 @@ import { type AppIdentity } from "../ports/app.js";
|
|
|
5
5
|
* agent's own start, so a command the agent runs cannot name another, and only a locked run has one.
|
|
6
6
|
*/
|
|
7
7
|
export declare const untrustedMarkOf: (app: AppIdentity, env: NodeJS.ProcessEnv) => string | undefined;
|
|
8
|
+
/** `untrustedMarkOf` for the app and environment the command runs in. */
|
|
9
|
+
export declare const runMarkOf: (command: Command) => string | undefined;
|
|
8
10
|
/** Other people's text between the run's markers, with every bracket and the mark taken out, so it can close none. */
|
|
9
11
|
export declare const marked: (text: string, mark: string, source: string, id?: string) => string;
|
|
10
12
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ancestorValue, envName, readOnlyLockOf } from "../ports/app.js";
|
|
2
|
+
import { environmentOf } from "./context.js";
|
|
2
3
|
const OPEN = "⟦";
|
|
3
4
|
const CLOSE = "⟧";
|
|
4
5
|
/**
|
|
@@ -11,6 +12,11 @@ export const untrustedMarkOf = (app, env) => {
|
|
|
11
12
|
const mark = ancestorValue(envName(app, "UNTRUSTED_MARK"), env);
|
|
12
13
|
return mark && /^[0-9a-f]{16}$/.test(mark) ? mark : undefined;
|
|
13
14
|
};
|
|
15
|
+
/** `untrustedMarkOf` for the app and environment the command runs in. */
|
|
16
|
+
export const runMarkOf = (command) => {
|
|
17
|
+
const { app, env } = environmentOf(command);
|
|
18
|
+
return app ? untrustedMarkOf(app, env ?? process.env) : undefined;
|
|
19
|
+
};
|
|
14
20
|
/** Other people's text between the run's markers, with every bracket and the mark taken out, so it can close none. */
|
|
15
21
|
export const marked = (text, mark, source, id) => {
|
|
16
22
|
const inside = text.replaceAll(OPEN, "").replaceAll(CLOSE, "").replaceAll(mark, "");
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../../ports/app.js";
|
|
3
|
+
import type { CrmFileLimits, CrmFileRow } from "../../store/store.js";
|
|
4
|
+
import type { CrmOpenableFile } from "../source.js";
|
|
5
|
+
import type { CrmRun, CrmWithin } from "./index.js";
|
|
6
|
+
/** `files download`'s own cap, and the most `--max-size` takes: Bitrix24's own largest file. */
|
|
7
|
+
export declare const DOWNLOAD_MB = 100;
|
|
8
|
+
export declare const MOST_DOWNLOAD_MB = 2048;
|
|
9
|
+
/** Where `files sync` is in its round, a sync state `config` never sets. */
|
|
10
|
+
export declare const FILES_ROUND = "crm:files-round";
|
|
11
|
+
export declare const FILES_DOWNLOAD_KEY = "files.download";
|
|
12
|
+
declare const SKIP_REASONS: readonly ["too-large", "run-files", "run-mb", "deadline", "disk-full", "unavailable"];
|
|
13
|
+
type SkipReason = (typeof SKIP_REASONS)[number];
|
|
14
|
+
export interface CrmFileContext {
|
|
15
|
+
app: AppIdentity;
|
|
16
|
+
run: CrmRun;
|
|
17
|
+
now: () => number;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export interface Downloaded {
|
|
21
|
+
row: CrmFileRow;
|
|
22
|
+
textStatus: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One file saved and read: under the account's folder (folders 700, file 600) or `dir`, its text through
|
|
26
|
+
* `extractText`, its row stored. A cut-off or refused download keeps no part, and no error names the link.
|
|
27
|
+
*/
|
|
28
|
+
export declare const downloadCrmFile: (context: CrmFileContext, file: CrmOpenableFile, assignee: string | null, { capBytes, capMb, flag, dir, limits, }: {
|
|
29
|
+
capBytes: number;
|
|
30
|
+
capMb: number;
|
|
31
|
+
flag: boolean;
|
|
32
|
+
dir?: string;
|
|
33
|
+
limits: CrmFileLimits;
|
|
34
|
+
}) => Promise<Downloaded>;
|
|
35
|
+
export interface CrmFileCommandOptions {
|
|
36
|
+
within: CrmWithin;
|
|
37
|
+
example: (command: Command, ...lines: string[]) => Command;
|
|
38
|
+
app: AppIdentity;
|
|
39
|
+
/** The CRM has leads: `--lead` is offered. True when absent. */
|
|
40
|
+
leads?: boolean;
|
|
41
|
+
now: () => number;
|
|
42
|
+
}
|
|
43
|
+
/** `files list`, `files download` and `files sync` (NEED-2701 C, NEED-2708 B). */
|
|
44
|
+
export declare const addCrmFileCommands: (program: Command, options: CrmFileCommandOptions) => void;
|
|
45
|
+
export interface FilesSyncReport {
|
|
46
|
+
owners: number;
|
|
47
|
+
downloaded: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
size: number;
|
|
51
|
+
path: string;
|
|
52
|
+
text_status: string;
|
|
53
|
+
}[];
|
|
54
|
+
skipped: {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
size: number | null;
|
|
58
|
+
reason: SkipReason;
|
|
59
|
+
}[];
|
|
60
|
+
complete: boolean;
|
|
61
|
+
stopped?: SkipReason;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One `files sync` run: the files of the sign-in's own deals and leads changed since the last complete round, and at
|
|
65
|
+
* most `files.days` back, newest first, under the run's limits. It stops at the first run limit and saves its place.
|
|
66
|
+
*/
|
|
67
|
+
export declare const syncFiles: (context: CrmFileContext, outOfTime: () => boolean, deadline?: (ms: number) => AbortSignal) => Promise<FilesSyncReport>;
|
|
68
|
+
export {};
|