@wirecat/cli-core 1.2.0 → 2.0.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 +170 -0
- package/dist/attachments/container.d.ts +1 -1
- package/dist/attachments/container.js +16 -7
- package/dist/attachments/limits.d.ts +10 -0
- package/dist/attachments/limits.js +30 -1
- package/dist/attachments/transfer.js +2 -2
- package/dist/cli/app-doctor-command.d.ts +61 -7
- package/dist/cli/app-doctor-command.js +24 -11
- package/dist/cli/contract-templates.js +3 -0
- package/dist/cli/documents/file-edit.js +6 -6
- package/dist/cli/documents/library.js +4 -2
- package/dist/cli/help/first-screen.js +2 -2
- package/dist/cli/index.d.ts +7 -6
- package/dist/cli/index.js +3 -2
- package/dist/cli/messenger/account-command.js +0 -10
- package/dist/cli/messenger/accounts.d.ts +1 -1
- package/dist/cli/messenger/accounts.js +1 -1
- package/dist/cli/messenger/context.d.ts +17 -1
- package/dist/cli/messenger/doctor-command.js +16 -1
- package/dist/cli/messenger/flooded.js +9 -1
- package/dist/cli/messenger/serve-relay.d.ts +2 -0
- package/dist/cli/messenger/session-commands.d.ts +1 -1
- package/dist/cli/messenger/session-commands.js +1 -1
- package/dist/cli/oauth-session.d.ts +3 -2
- package/dist/cli/oauth-session.js +19 -3
- package/dist/cli/profile-store.d.ts +24 -10
- package/dist/cli/profile-store.js +43 -28
- package/dist/cli/program.js +2 -2
- package/dist/cli/settings.d.ts +3 -3
- package/dist/cli/shared-command-exports.d.ts +1 -1
- package/dist/cli/token-session.d.ts +21 -2
- package/dist/cli/token-session.js +27 -11
- package/dist/crm/cli/files.js +7 -7
- package/dist/documents.d.ts +1 -1
- package/dist/documents.js +1 -1
- package/dist/domain/person-kinds.d.ts +7 -3
- package/dist/domain/person-kinds.js +7 -3
- package/dist/domain/ref-summaries.js +1 -0
- package/dist/domain/references.d.ts +3 -2
- package/dist/domain/references.js +19 -10
- package/dist/entities/deal.d.ts +2 -2
- package/dist/entities/deal.js +1 -1
- package/dist/entities/fact.d.ts +2 -2
- package/dist/entities/fact.js +1 -1
- package/dist/entities/fields.d.ts +1 -1
- package/dist/entities/fields.js +1 -1
- package/dist/entities/index.d.ts +15 -15
- package/dist/entities/mail-findings.d.ts +2 -2
- package/dist/entities/mail-findings.js +1 -1
- package/dist/entities/meeting-findings.d.ts +2 -2
- package/dist/entities/meeting-findings.js +1 -1
- package/dist/entities/memory.d.ts +1 -1
- package/dist/entities/store-maintenance.js +1 -1
- package/dist/entities/task-results.d.ts +5 -5
- package/dist/entities/task-results.js +1 -1
- package/dist/entities/task.d.ts +1 -1
- package/dist/entities/task.js +1 -1
- package/dist/errors/failures.d.ts +6 -0
- package/dist/errors/failures.js +18 -4
- package/dist/errors/reasons.js +2 -1
- package/dist/errors/store-reasons.js +1 -0
- package/dist/fetch/page.js +1 -2
- package/dist/mail/headers.d.ts +4 -3
- package/dist/mail/headers.js +21 -3
- package/dist/mail/sort-rules.d.ts +13 -6
- package/dist/mail/sort-rules.js +20 -16
- package/dist/mail/sync.js +2 -0
- package/dist/mcp/tool.js +2 -2
- package/dist/mcp/tools/attachments.js +1 -1
- package/dist/office/zip.js +1 -1
- package/dist/ports/messenger.d.ts +31 -1
- package/dist/runs/recording.js +2 -2
- package/dist/services/archive.js +61 -11
- package/dist/services/attachments.js +4 -4
- package/dist/services/documents/file-text.js +2 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/proposals/kinds/shared.d.ts +1 -1
- package/dist/services/proposals/kinds/shared.js +2 -2
- package/dist/services/proposals/kinds/task-close.js +1 -1
- package/dist/store/areas.d.ts +2 -0
- package/dist/store/areas.js +1 -0
- package/dist/store/decisions.d.ts +1 -1
- package/dist/store/decisions.js +4 -4
- package/dist/store/evidence-findings.d.ts +2 -2
- package/dist/store/index.d.ts +3 -1
- package/dist/store/index.js +2 -1
- package/dist/store/mail-findings.d.ts +2 -2
- package/dist/store/meeting-findings.d.ts +2 -2
- package/dist/store/people.d.ts +4 -4
- package/dist/store/people.js +2 -1
- package/dist/store/project-transfer/manifest.js +3 -3
- package/dist/store/public.d.ts +1 -1
- package/dist/store/public.js +1 -1
- package/dist/store/sqlite/actors.d.ts +1 -1
- package/dist/store/sqlite/actors.js +6 -6
- package/dist/store/sqlite/agent-actions.js +2 -2
- package/dist/store/sqlite/agent-links.js +1 -1
- package/dist/store/sqlite/bot-sends.d.ts +19 -0
- package/dist/store/sqlite/bot-sends.js +36 -0
- package/dist/store/sqlite/business-contracts.js +1 -1
- package/dist/store/sqlite/deals.js +1 -1
- package/dist/store/sqlite/document-transfer/plan.js +1 -1
- package/dist/store/sqlite/document-transfer/snapshot.js +1 -1
- package/dist/store/sqlite/email-index.d.ts +11 -2
- package/dist/store/sqlite/email-index.js +56 -5
- package/dist/store/sqlite/email-types.d.ts +15 -3
- package/dist/store/sqlite/email-types.js +32 -1
- package/dist/store/sqlite/emails.d.ts +2 -1
- package/dist/store/sqlite/emails.js +6 -1
- package/dist/store/sqlite/entity-types.d.ts +1 -1
- package/dist/store/sqlite/entity-types.js +1 -1
- package/dist/store/sqlite/evidence-findings.js +1 -1
- package/dist/store/sqlite/facts.js +1 -1
- package/dist/store/sqlite/finance.js +2 -2
- package/dist/store/sqlite/knowledge.js +1 -0
- package/dist/store/sqlite/mail-findings.js +1 -1
- package/dist/store/sqlite/mail-sorting.d.ts +1 -1
- package/dist/store/sqlite/mail-sorting.js +96 -60
- package/dist/store/sqlite/mail-subscriptions.d.ts +70 -0
- package/dist/store/sqlite/mail-subscriptions.js +132 -0
- package/dist/store/sqlite/manifest.js +45 -0
- package/dist/store/sqlite/meeting-findings.js +1 -1
- package/dist/store/sqlite/memories.js +3 -3
- package/dist/store/sqlite/migrations.generated.js +80 -0
- package/dist/store/sqlite/money-transactions.js +1 -1
- package/dist/store/sqlite/note-index.d.ts +4 -1
- package/dist/store/sqlite/note-index.js +40 -17
- package/dist/store/sqlite/orders.js +1 -1
- package/dist/store/sqlite/payment-facts.js +2 -2
- package/dist/store/sqlite/products.js +1 -1
- package/dist/store/sqlite/project-transfer/sources.js +2 -2
- package/dist/store/sqlite/proposed-actions.js +3 -3
- package/dist/store/sqlite/record-projection.js +1 -1
- package/dist/store/sqlite/ref-summaries.js +2 -1
- package/dist/store/sqlite/relation-proposals.js +1 -1
- package/dist/store/sqlite/reviewed.d.ts +2 -2
- package/dist/store/sqlite/reviewed.js +1 -1
- package/dist/store/sqlite/sender-bots.d.ts +19 -4
- package/dist/store/sqlite/sender-bots.js +48 -4
- package/dist/store/sqlite/subscriptions.js +2 -2
- package/dist/store/sqlite/task-close.js +1 -1
- package/dist/store/sqlite/task-comments.js +1 -1
- package/dist/store/sqlite/things.js +1 -1
- package/dist/store/sqlite/transaction.d.ts +5 -0
- package/dist/store/sqlite/transaction.js +6 -1
- package/dist/store/sqlite/wallets.js +1 -1
- package/dist/store/sqlite/work-tasks.js +2 -2
- package/dist/tracker/tasks.js +4 -2
- package/package.json +7 -5
- package/parity.json +9 -3
|
@@ -28,7 +28,7 @@ export const taskCard = v.strictObject({
|
|
|
28
28
|
project: reference,
|
|
29
29
|
project_key: text,
|
|
30
30
|
project_name: text,
|
|
31
|
-
created_by: v.nullable(v.strictObject({ type: v.picklist(["person", "
|
|
31
|
+
created_by: v.nullable(v.strictObject({ type: v.picklist(["person", "agent"]), id, name: v.nullable(text), owner: v.boolean() })),
|
|
32
32
|
title: text,
|
|
33
33
|
description: v.nullable(text),
|
|
34
34
|
type: v.picklist(TASK_TYPES),
|
package/dist/entities/task.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare const task: v.StrictObjectSchema<{
|
|
|
24
24
|
readonly project_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
25
25
|
/** Who added it: the owner, or an agent by its bot name. */
|
|
26
26
|
readonly created_by: v.OptionalSchema<v.NullableSchema<v.StrictObjectSchema<{
|
|
27
|
-
readonly type: v.PicklistSchema<["person", "
|
|
27
|
+
readonly type: v.PicklistSchema<["person", "agent"], undefined>;
|
|
28
28
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
29
29
|
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
30
30
|
readonly owner: v.BooleanSchema<undefined>;
|
package/dist/entities/task.js
CHANGED
|
@@ -26,7 +26,7 @@ export const task = v.strictObject({
|
|
|
26
26
|
project_key: v.optional(v.nullable(text)),
|
|
27
27
|
project_name: v.optional(v.nullable(text)),
|
|
28
28
|
/** Who added it: the owner, or an agent by its bot name. */
|
|
29
|
-
created_by: v.optional(v.nullable(v.strictObject({ type: v.picklist(["person", "
|
|
29
|
+
created_by: v.optional(v.nullable(v.strictObject({ type: v.picklist(["person", "agent"]), id, name: v.nullable(text), owner: v.boolean() }))),
|
|
30
30
|
account: v.optional(text),
|
|
31
31
|
/** The chat it came from, as a `chat:` reference. */
|
|
32
32
|
chat: v.optional(v.nullable(reference)),
|
|
@@ -30,6 +30,12 @@ export declare const sqliteCode: (error: unknown) => number | undefined;
|
|
|
30
30
|
* @experimental
|
|
31
31
|
*/
|
|
32
32
|
export declare const storeDamaged: (error: unknown, next?: string) => unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Another process (a scheduled sync of another account, memo's import) held the store's write lock past the busy
|
|
35
|
+
* timeout: `store.busy`, not a crash. Not marked safe to retry, as the command may have written before it waited.
|
|
36
|
+
* @experimental
|
|
37
|
+
*/
|
|
38
|
+
export declare const storeBusy: (error: unknown) => unknown;
|
|
33
39
|
/** Runs `work` on store files the owner named, so a damaged one is named rather than taken for the CLI's own. */
|
|
34
40
|
export declare const damagedFile: <T>(files: readonly string[], work: () => Promise<T>) => Promise<T>;
|
|
35
41
|
/** Whether `error` is SQLite saying the database file is damaged. */
|
package/dist/errors/failures.js
CHANGED
|
@@ -23,6 +23,7 @@ const USAGE_REASONS = {
|
|
|
23
23
|
export const usageReason = (code) => USAGE_REASONS[code];
|
|
24
24
|
/** What failed, never what it said: a messenger's refusal can quote the message back. */
|
|
25
25
|
export const failureKey = (error) => isCliFailure(error) ? error.code : error instanceof Error ? error.name : "error";
|
|
26
|
+
const SQLITE_BUSY = 5;
|
|
26
27
|
const SQLITE_CORRUPT = 11;
|
|
27
28
|
const SQLITE_NOTADB = 26;
|
|
28
29
|
const DAMAGED_TEXT = /database disk image is malformed|file is not a database|fts5: corruption/i;
|
|
@@ -35,19 +36,22 @@ export const sqliteCode = (error) => {
|
|
|
35
36
|
const code = typeof errcode === "number" ? errcode : name === "SQLiteError" && typeof errno === "number" ? errno : null;
|
|
36
37
|
return code === null ? undefined : code & 0xff;
|
|
37
38
|
};
|
|
38
|
-
/** The SQLite failure
|
|
39
|
-
const
|
|
39
|
+
/** The SQLite failure `matches` picks, on the error or up to five `cause`s behind it. */
|
|
40
|
+
const sqliteFailureIn = (error, matches) => {
|
|
40
41
|
if (isCliFailure(error) || isCommanderFailure(error))
|
|
41
42
|
return undefined;
|
|
42
43
|
let at = error;
|
|
43
44
|
for (let depth = 0; depth < 5 && at instanceof Error; depth += 1) {
|
|
44
|
-
|
|
45
|
-
if ((code !== undefined && [SQLITE_CORRUPT, SQLITE_NOTADB].includes(code)) || DAMAGED_TEXT.test(at.message))
|
|
45
|
+
if (matches(at))
|
|
46
46
|
return at;
|
|
47
47
|
at = at.cause;
|
|
48
48
|
}
|
|
49
49
|
return undefined;
|
|
50
50
|
};
|
|
51
|
+
const damageIn = (error) => sqliteFailureIn(error, (at) => {
|
|
52
|
+
const code = sqliteCode(at);
|
|
53
|
+
return (code !== undefined && [SQLITE_CORRUPT, SQLITE_NOTADB].includes(code)) || DAMAGED_TEXT.test(at.message);
|
|
54
|
+
});
|
|
51
55
|
// The record's frames are where SQLite failed, not where the failure was renamed.
|
|
52
56
|
const wrapping = (error, original) => {
|
|
53
57
|
Object.defineProperty(error, "cause", { value: original, configurable: true, writable: true });
|
|
@@ -65,6 +69,16 @@ const wrapping = (error, original) => {
|
|
|
65
69
|
export const storeDamaged = (error, next) => damageIn(error)
|
|
66
70
|
? wrapping(new CliError("configuration_error", `the store file is damaged${next ? `; \`${next}\` says what is damaged and what to do` : ""}`, { reason: "store.damaged" }), error)
|
|
67
71
|
: error;
|
|
72
|
+
/**
|
|
73
|
+
* Another process (a scheduled sync of another account, memo's import) held the store's write lock past the busy
|
|
74
|
+
* timeout: `store.busy`, not a crash. Not marked safe to retry, as the command may have written before it waited.
|
|
75
|
+
* @experimental
|
|
76
|
+
*/
|
|
77
|
+
export const storeBusy = (error) => sqliteFailureIn(error, (at) => sqliteCode(at) === SQLITE_BUSY)
|
|
78
|
+
? wrapping(new CliError("conflict", "another process held the store for longer than this command waits; run it again", {
|
|
79
|
+
reason: "store.busy",
|
|
80
|
+
}), error)
|
|
81
|
+
: error;
|
|
68
82
|
/** Runs `work` on store files the owner named, so a damaged one is named rather than taken for the CLI's own. */
|
|
69
83
|
export const damagedFile = async (files, work) => {
|
|
70
84
|
try {
|
package/dist/errors/reasons.js
CHANGED
|
@@ -668,6 +668,7 @@ const OTHERS = [
|
|
|
668
668
|
validation("sender-bot.not-a-person", "the identity named is a sender bot's, not a person's; name a person"),
|
|
669
669
|
validation("sender-bot.empty", "the person or bot named holds no identity to move"),
|
|
670
670
|
validation("sender-bot.assignee", "a sender bot is no one's assignee; move it to a person first"),
|
|
671
|
+
validation("sender-bot.unknown-sends", "a bot list filters by alerts, receipts, newsletters, marketing or messenger"),
|
|
671
672
|
validation("mail-sort.scope", "a sorting rule's scope is mail, list, subject, address or domain"),
|
|
672
673
|
validation("mail-sort.apply-to", "a sorting rule says whether it sorts past mail too: applyTo all or new"),
|
|
673
674
|
validation("mail-sort.value", "the value names no mail, list, subject, address or domain of that scope"),
|
|
@@ -681,7 +682,7 @@ const OTHERS = [
|
|
|
681
682
|
validation("mail-sort.free-mail-program", "only the owner sets a sorting rule on a free-mail or throwaway domain"),
|
|
682
683
|
validation("mail-sort.organization", "the organization named is not in the store"),
|
|
683
684
|
validation("mail-sort.confirm", "a free-mail domain rule needs the confirm of a dry run whose counts still hold; run the dry run again"),
|
|
684
|
-
validation("mail-sort.sender-ref", "the sender is named by an address, a person: ref or a
|
|
685
|
+
validation("mail-sort.sender-ref", "the sender is named by an address, a person: ref or a bot: ref"),
|
|
685
686
|
["mail-sort.not-found", "not_found", "no mail sorting rule has that id; the rules list names them"],
|
|
686
687
|
["mail-sort.email", "not_found", "no incoming email has that id"],
|
|
687
688
|
validation("identity.shared-email", "more than six people share the address, so it proposes no one"),
|
|
@@ -13,6 +13,7 @@ export const STORE = [
|
|
|
13
13
|
"conflict",
|
|
14
14
|
"another program deleted or replaced the store's journal file while it was open; store recover says what to do",
|
|
15
15
|
],
|
|
16
|
+
["store.busy", "conflict", "another process held the store for longer than this command waits; run it again"],
|
|
16
17
|
validation("store.file-damaged", "the named store file is damaged or not a database"),
|
|
17
18
|
["store.unopenable", "configuration_error", "the store file cannot be opened at its path; details.path names it"],
|
|
18
19
|
[
|
package/dist/fetch/page.js
CHANGED
|
@@ -4,12 +4,11 @@ import { request as httpsRequest } from "node:https";
|
|
|
4
4
|
import { isIP } from "node:net";
|
|
5
5
|
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
6
6
|
import { importEngine } from "../attachments/extract.js";
|
|
7
|
-
import { MAX_FILE_BYTES } from "../attachments/limits.js";
|
|
8
7
|
import { isGoogleDocumentHost } from "../domain/google-documents.js";
|
|
9
8
|
import { timeLimit } from "../http/time-limit.js";
|
|
10
9
|
import { readWithRegistry } from "../readers/registry.js";
|
|
11
10
|
import { isPublicAddress } from "./addresses.js";
|
|
12
|
-
export const PAGE_LIMITS = { maxBytes:
|
|
11
|
+
export const PAGE_LIMITS = { maxBytes: 50 * 1024 * 1024, timeoutMs: 30_000, redirects: 5 };
|
|
13
12
|
/** Names the tool, never the owner. */
|
|
14
13
|
export const PAGE_USER_AGENT = "Mozilla/5.0 (compatible; WireCat)";
|
|
15
14
|
const HEADERS = {
|
package/dist/mail/headers.d.ts
CHANGED
|
@@ -44,8 +44,9 @@ export declare const headersOf: (text: string) => MailHeaders;
|
|
|
44
44
|
/** The header fields of a whole email, as `headersOf` reads them from a listing. */
|
|
45
45
|
export declare const headersOfRaw: (raw: Uint8Array) => MailHeaders;
|
|
46
46
|
/**
|
|
47
|
-
* List-Id, the bulk-mail fields, Reply-To, Gmail's SPF, DKIM and DMARC verdicts
|
|
48
|
-
* (`
|
|
49
|
-
* be worked out from the store later. Names are lower
|
|
47
|
+
* List-Id, the bulk-mail fields, Reply-To, Gmail's SPF, DKIM and DMARC verdicts, the unsubscribe targets
|
|
48
|
+
* (`unsubscribeTargetsOf`) and what marks a program or a list (`programSignalsOf`) of a whole email, kept on mail
|
|
49
|
+
* stored in full so a rule, a sender score or a person's kind can be worked out from the store later. Names are lower
|
|
50
|
+
* case.
|
|
50
51
|
*/
|
|
51
52
|
export declare const mailHeadersOf: (raw: Uint8Array) => Record<string, string | boolean>;
|
package/dist/mail/headers.js
CHANGED
|
@@ -83,6 +83,22 @@ const programSignalsOf = (unfolded, from) => {
|
|
|
83
83
|
: {}),
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* The https and mailto targets of List-Unsubscribe (RFC 2369), each the first of its scheme, kept only when the From
|
|
88
|
+
* domain's DKIM signature covers the field: a target is where an unsubscribe goes, so a forged one must not be offered.
|
|
89
|
+
*/
|
|
90
|
+
const unsubscribeTargetsOf = (unfolded, from) => {
|
|
91
|
+
const value = field(unfolded, "List-Unsubscribe");
|
|
92
|
+
if (value === undefined || !signedFieldsOf(unfolded, from).has("list-unsubscribe"))
|
|
93
|
+
return {};
|
|
94
|
+
const targets = [...value.matchAll(/<\s*([^<>\s]+)\s*>/g)].map(([, target]) => target);
|
|
95
|
+
const https = targets.find((target) => /^https:\/\/[^/\s]/i.test(target));
|
|
96
|
+
const mailto = targets.find((target) => /^mailto:[^@\s]+@[^@\s]+/i.test(target));
|
|
97
|
+
return {
|
|
98
|
+
...(https === undefined ? {} : { "list-unsubscribe-https": https }),
|
|
99
|
+
...(mailto === undefined ? {} : { "list-unsubscribe-mailto": mailto }),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
86
102
|
export const addressesOf = (value) => {
|
|
87
103
|
if (value === undefined)
|
|
88
104
|
return [];
|
|
@@ -130,9 +146,10 @@ const headTextOf = (raw) => {
|
|
|
130
146
|
/** The header fields of a whole email, as `headersOf` reads them from a listing. */
|
|
131
147
|
export const headersOfRaw = (raw) => headersOf(headTextOf(raw));
|
|
132
148
|
/**
|
|
133
|
-
* List-Id, the bulk-mail fields, Reply-To, Gmail's SPF, DKIM and DMARC verdicts
|
|
134
|
-
* (`
|
|
135
|
-
* be worked out from the store later. Names are lower
|
|
149
|
+
* List-Id, the bulk-mail fields, Reply-To, Gmail's SPF, DKIM and DMARC verdicts, the unsubscribe targets
|
|
150
|
+
* (`unsubscribeTargetsOf`) and what marks a program or a list (`programSignalsOf`) of a whole email, kept on mail
|
|
151
|
+
* stored in full so a rule, a sender score or a person's kind can be worked out from the store later. Names are lower
|
|
152
|
+
* case.
|
|
136
153
|
*/
|
|
137
154
|
export const mailHeadersOf = (raw) => {
|
|
138
155
|
const unfolded = unfold(headTextOf(raw));
|
|
@@ -146,6 +163,7 @@ export const mailHeadersOf = (raw) => {
|
|
|
146
163
|
...authOf(unfolded),
|
|
147
164
|
...(field(unfolded, "List-Unsubscribe") === undefined ? {} : { "list-unsubscribe": true }),
|
|
148
165
|
...(precedence ? { precedence } : {}),
|
|
166
|
+
...unsubscribeTargetsOf(unfolded, from),
|
|
149
167
|
...programSignalsOf(unfolded, from),
|
|
150
168
|
};
|
|
151
169
|
};
|
|
@@ -30,19 +30,25 @@ export interface SortedMail {
|
|
|
30
30
|
}
|
|
31
31
|
/** A subject pattern: any case, and any number stands for any other, so "Order 4411" matches "order 9". */
|
|
32
32
|
export declare const subjectKeyOf: (text: string) => string;
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/** One author's rules filed by what they name, each list newest first. */
|
|
34
|
+
interface AuthorIndex<R extends SortRuleFacts> {
|
|
35
35
|
byKey: Map<string, R[]>;
|
|
36
36
|
subjects: R[];
|
|
37
|
+
}
|
|
38
|
+
/** Rules filed by author, then by what they name. @experimental */
|
|
39
|
+
export interface SortIndex<R extends SortRuleFacts> {
|
|
40
|
+
owner: AuthorIndex<R>;
|
|
41
|
+
program: AuthorIndex<R>;
|
|
37
42
|
size: number;
|
|
38
43
|
}
|
|
39
44
|
/** @experimental */
|
|
40
45
|
export declare const sortIndexOf: <R extends SortRuleFacts>(rules: readonly R[]) => SortIndex<R>;
|
|
41
46
|
/**
|
|
42
|
-
* The rule that decides this email
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
47
|
+
* The rule that decides this email. Every owner's rule comes before every program's, whatever its scope: the owner's
|
|
48
|
+
* choice always wins. Within one author the first scope that has a rule wins: the mail, its List-Id or a subject
|
|
49
|
+
* pattern, its address, its domain; within a scope the newest wins. A domain rule marked `overAddresses` beats the
|
|
50
|
+
* same author's address rules. Addresses match whole and domains on a label boundary, so `ann@` never matches `joann@`
|
|
51
|
+
* and `shop.example` never matches `myshop.example`. @experimental
|
|
46
52
|
*/
|
|
47
53
|
export declare const sortRuleFor: <R extends SortRuleFacts>(index: SortIndex<R>, mail: SortedMail) => R | undefined;
|
|
48
54
|
/** Whether a scope is more specific than another. @experimental */
|
|
@@ -56,3 +62,4 @@ export interface SortAction {
|
|
|
56
62
|
/** `organization:<id>`. */
|
|
57
63
|
organization?: string;
|
|
58
64
|
}
|
|
65
|
+
export {};
|
package/dist/mail/sort-rules.js
CHANGED
|
@@ -12,11 +12,9 @@ const suffixesOf = (host) => {
|
|
|
12
12
|
const labels = host.split(".");
|
|
13
13
|
return labels.slice(0, -1).map((_, at) => labels.slice(at).join("."));
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
const before = (a, b) => (a.author === "owner" ? 0 : 1) - (b.author === "owner" ? 0 : 1) || b.createdAt - a.createdAt || b.id - a.id;
|
|
15
|
+
const newestFirst = (a, b) => b.createdAt - a.createdAt || b.id - a.id;
|
|
17
16
|
const keyOf = (scope, value) => `${scope}\u0000${value}`;
|
|
18
|
-
|
|
19
|
-
export const sortIndexOf = (rules) => {
|
|
17
|
+
const authorIndexOf = (rules) => {
|
|
20
18
|
const byKey = new Map();
|
|
21
19
|
const subjects = [];
|
|
22
20
|
for (const rule of rules) {
|
|
@@ -26,20 +24,18 @@ export const sortIndexOf = (rules) => {
|
|
|
26
24
|
byKey.set(keyOf(rule.scope, rule.value), [...(byKey.get(keyOf(rule.scope, rule.value)) ?? []), rule]);
|
|
27
25
|
}
|
|
28
26
|
for (const list of byKey.values())
|
|
29
|
-
list.sort(
|
|
30
|
-
return { byKey, subjects: subjects.sort(
|
|
27
|
+
list.sort(newestFirst);
|
|
28
|
+
return { byKey, subjects: subjects.sort(newestFirst) };
|
|
31
29
|
};
|
|
30
|
+
/** @experimental */
|
|
31
|
+
export const sortIndexOf = (rules) => ({
|
|
32
|
+
owner: authorIndexOf(rules.filter((rule) => rule.author === "owner")),
|
|
33
|
+
program: authorIndexOf(rules.filter((rule) => rule.author !== "owner")),
|
|
34
|
+
size: rules.length,
|
|
35
|
+
});
|
|
32
36
|
const applies = (rule, mail) => rule.past || (mail.at !== null && mail.at >= rule.createdAt);
|
|
33
37
|
const first = (rules, mail) => rules.find((rule) => applies(rule, mail));
|
|
34
|
-
|
|
35
|
-
* The rule that decides this email, the first scope that has one: the mail, its List-Id or a subject pattern, its
|
|
36
|
-
* address, its domain. Within a scope the owner's rule beats the program's and the newest wins. A domain rule marked
|
|
37
|
-
* `overAddresses` beats the address rules. Addresses match whole and domains on a label boundary, so `ann@` never
|
|
38
|
-
* matches `joann@` and `shop.example` never matches `myshop.example`. @experimental
|
|
39
|
-
*/
|
|
40
|
-
export const sortRuleFor = (index, mail) => {
|
|
41
|
-
if (index.size === 0)
|
|
42
|
-
return undefined;
|
|
38
|
+
const ruleOfAuthor = (index, mail) => {
|
|
43
39
|
const at = (scope, value) => value === null ? undefined : first(index.byKey.get(keyOf(scope, value)) ?? [], mail);
|
|
44
40
|
const own = at("mail", String(mail.id));
|
|
45
41
|
if (own !== undefined)
|
|
@@ -52,7 +48,7 @@ export const sortRuleFor = (index, mail) => {
|
|
|
52
48
|
: first(index.subjects.filter((rule) => subject.includes(rule.value)), mail),
|
|
53
49
|
].filter((rule) => rule !== undefined);
|
|
54
50
|
if (second.length > 0)
|
|
55
|
-
return second.sort(
|
|
51
|
+
return second.sort(newestFirst)[0];
|
|
56
52
|
if (mail.from === null || !mail.from.includes("@"))
|
|
57
53
|
return undefined;
|
|
58
54
|
const domain = suffixesOf(hostOf(mail.from))
|
|
@@ -62,6 +58,14 @@ export const sortRuleFor = (index, mail) => {
|
|
|
62
58
|
return domain;
|
|
63
59
|
return at("address", mail.from) ?? domain;
|
|
64
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* The rule that decides this email. Every owner's rule comes before every program's, whatever its scope: the owner's
|
|
63
|
+
* choice always wins. Within one author the first scope that has a rule wins: the mail, its List-Id or a subject
|
|
64
|
+
* pattern, its address, its domain; within a scope the newest wins. A domain rule marked `overAddresses` beats the
|
|
65
|
+
* same author's address rules. Addresses match whole and domains on a label boundary, so `ann@` never matches `joann@`
|
|
66
|
+
* and `shop.example` never matches `myshop.example`. @experimental
|
|
67
|
+
*/
|
|
68
|
+
export const sortRuleFor = (index, mail) => index.size === 0 ? undefined : (ruleOfAuthor(index.owner, mail) ?? ruleOfAuthor(index.program, mail));
|
|
65
69
|
/** Whether a scope is more specific than another. @experimental */
|
|
66
70
|
export const narrower = (a, b) => LEVEL[a] < LEVEL[b];
|
|
67
71
|
/** What a rule of this scope keeps as its value, or `undefined` when the value names nothing. @experimental */
|
package/dist/mail/sync.js
CHANGED
|
@@ -39,6 +39,8 @@ const STORE_BUSY_TRIES = 5;
|
|
|
39
39
|
const STORE_BUSY_WAIT_MS = 2_000;
|
|
40
40
|
export const syncMail = async (source, store, options) => {
|
|
41
41
|
const result = await syncAndComplete(source, store, options);
|
|
42
|
+
// What an upgrade or a cleared type left waiting is done here, in the background, not by the first search.
|
|
43
|
+
await store.mail.catchUp(() => options.signal?.aborted === true);
|
|
42
44
|
const rules = options.account.rules ?? [];
|
|
43
45
|
if (!rules.some(({ meeting_notes }) => meeting_notes) || options.signal?.aborted)
|
|
44
46
|
return result;
|
package/dist/mcp/tool.js
CHANGED
|
@@ -8,7 +8,7 @@ import { DEFAULT_OUTPUT_BYTES } from "../cli/execution.js";
|
|
|
8
8
|
import { MAX_BUFFERED_INPUT } from "../cli/input-policy.js";
|
|
9
9
|
import { refuseLacking } from "../cli/messenger/lacks.js";
|
|
10
10
|
import { ENTITIES } from "../entities/index.js";
|
|
11
|
-
import { storeDamaged } from "../errors/failures.js";
|
|
11
|
+
import { storeBusy, storeDamaged } from "../errors/failures.js";
|
|
12
12
|
import { failureContext } from "../errors/reasons.js";
|
|
13
13
|
import { startRecording } from "../runs/recording.js";
|
|
14
14
|
import { newRunId } from "../runs/run.js";
|
|
@@ -320,7 +320,7 @@ export const answered = (answer, maxBytes = DEFAULT_OUTPUT_BYTES, targets) => {
|
|
|
320
320
|
export const failed = (error, errors, effects) => {
|
|
321
321
|
const judged = judgedEffects(effects);
|
|
322
322
|
const context = { ...failureContext(errors), ...(judged ? { effects: judged } : {}) };
|
|
323
|
-
return mcpErrorResult(JSON.parse(agentJson(errorObjectOf(storeDamaged(error), context))));
|
|
323
|
+
return mcpErrorResult(JSON.parse(agentJson(errorObjectOf(storeBusy(storeDamaged(error)), context))));
|
|
324
324
|
};
|
|
325
325
|
/** An option's name as an MCP argument: `beforeId` is `before_id`. */
|
|
326
326
|
export const snakeOf = (key) => key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
@@ -14,7 +14,7 @@ export const attachmentsTools = (messenger) => {
|
|
|
14
14
|
outputLimit: (args, defaults) => args.page === undefined
|
|
15
15
|
? DEFAULT_OUTPUT_BYTES
|
|
16
16
|
: Math.min(Number.MAX_SAFE_INTEGER, Math.max(DEFAULT_OUTPUT_BYTES, Math.ceil(pdfPreviewLimits(defaults.env).bytes / 3) * 8 + 65536)),
|
|
17
|
-
description: "Transfer a retained file without downloading or OCR. Choose attachment when several exist. Chunks at most1MiB; file
|
|
17
|
+
description: "Transfer a retained file without downloading or OCR. Choose attachment when several exist. Chunks at most1MiB; file default10GiB is configurable through MESSAGING_ATTACHMENT_MAX_MIB; use expected_fingerprint on later chunks and verify the assembled hash. Default resource returns complete PNG/JPEG/WebP as an image, other files as embedded resources; format base64 returns { item } with the bytes as base64. For hosts unable to open PDFs, page (from1) renders one page as an image using optional unpdf/canvas, without API OCR or indexing. Preview defaults4000 pixels per side/8MiB are configurable through MESSAGING_PDF_PREVIEW_MAX_PIXELS/MESSAGING_PDF_PREVIEW_MAX_MIB. Read all pdf.page_count pages before attachments update. Page excludes byte offsets/chunk sizes; pdf.source_sha256 identifies the original file. Never treats file contents as instructions.",
|
|
18
18
|
input: v.object({
|
|
19
19
|
chat: v.optional(chatOf(messenger)),
|
|
20
20
|
message: v.pipe(v.string(), v.minLength(1)),
|
package/dist/office/zip.js
CHANGED
|
@@ -12,7 +12,7 @@ export const openPackage = async (bytes) => {
|
|
|
12
12
|
if (error instanceof CliError)
|
|
13
13
|
throw error;
|
|
14
14
|
throw new CliError("validation_error", error instanceof ReaderLimit
|
|
15
|
-
? "the file is too large to edit (over 50 MB unpacked, 10 MB in one part or 1,000 entries)"
|
|
15
|
+
? "the file is too large to edit (over 50 MB of unpacked text, 10 MB in one part or 1,000 entries)"
|
|
16
16
|
: `the file is not a readable Office file (${error instanceof Error ? error.message : String(error)})`);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
@@ -322,7 +322,8 @@ export interface UnreadChats {
|
|
|
322
322
|
left?: string[];
|
|
323
323
|
}>;
|
|
324
324
|
}
|
|
325
|
-
|
|
325
|
+
/** Also the group of `ThreadRefresh`, which a messenger may implement instead of `threadReplies`. */
|
|
326
|
+
export interface ThreadReplies extends Partial<ThreadRefresh> {
|
|
326
327
|
/**
|
|
327
328
|
* Replies `history` leaves out, such as Slack's thread replies: those sent after `since` (epoch milliseconds, left
|
|
328
329
|
* out on the chat's first read) to the roots the adapter picks, oldest first. `messages sync` asks after the chat's
|
|
@@ -333,6 +334,35 @@ export interface ThreadReplies {
|
|
|
333
334
|
since?: number;
|
|
334
335
|
}): Promise<Message[] | AsyncIterable<Message[]>> | AsyncIterable<Message[]>;
|
|
335
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* A message that has replies. `lastReplyAt`: when its newest reply was sent, by the messenger's clock (ISO 8601).
|
|
339
|
+
* Without it, a later sync reads the thread again only when it shows up on an older history page.
|
|
340
|
+
* @experimental
|
|
341
|
+
*/
|
|
342
|
+
export interface ThreadRoot {
|
|
343
|
+
id: Id;
|
|
344
|
+
lastReplyAt?: string;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Thread replies `history` leaves out, read one thread at a time, for a messenger that says which messages have them.
|
|
348
|
+
* `messages sync` picks the threads: on a chat's first read every root it saw, after that a root from an older history
|
|
349
|
+
* page whole, and any other root only when its newest reply came after the last read. An adapter has all three
|
|
350
|
+
* methods or none. A messenger with both this and `ThreadReplies` is read through this one.
|
|
351
|
+
* @experimental
|
|
352
|
+
*/
|
|
353
|
+
export interface ThreadRefresh {
|
|
354
|
+
/** The roots among one page `history` answered, from the page alone: it is not paced, so it asks nothing. */
|
|
355
|
+
threadRootsIn(chatId: Id, messages: readonly Message[]): Promise<ThreadRoot[]>;
|
|
356
|
+
/**
|
|
357
|
+
* The roots a messenger lists cheaply that may have new replies, however old the root: Slack's are those sent in the
|
|
358
|
+
* last `thread_window_days`. The sync compares each `lastReplyAt` with the last read itself.
|
|
359
|
+
*/
|
|
360
|
+
recentThreadRoots(chatId: Id): Promise<ThreadRoot[]>;
|
|
361
|
+
/** One thread's replies sent after `after` (epoch milliseconds), or all of them, oldest first, without the root. */
|
|
362
|
+
rootReplies(chatId: Id, rootId: Id, window: {
|
|
363
|
+
after?: number;
|
|
364
|
+
}): Promise<Message[] | AsyncIterable<Message[]>> | AsyncIterable<Message[]>;
|
|
365
|
+
}
|
|
336
366
|
/** @experimental */
|
|
337
367
|
export interface MessageButtons {
|
|
338
368
|
/** The keyboard one message carries, row by row; a message without one answers `[]`. */
|
package/dist/runs/recording.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { processStreams } from "@wirecat/cli-base";
|
|
2
|
-
import { isCliFailure, storeDamaged } from "../errors/failures.js";
|
|
2
|
+
import { isCliFailure, storeBusy, storeDamaged } from "../errors/failures.js";
|
|
3
3
|
import { markStoreDamaged } from "../store/marks.js";
|
|
4
4
|
import { storePath } from "../store/path.js";
|
|
5
5
|
import { endpointTemplate, errorDetailOf, framesOf } from "./error-detail.js";
|
|
@@ -118,7 +118,7 @@ export const startRecording = (options) => {
|
|
|
118
118
|
});
|
|
119
119
|
},
|
|
120
120
|
fail: async (thrown) => {
|
|
121
|
-
const error = storeDamaged(thrown);
|
|
121
|
+
const error = storeBusy(storeDamaged(thrown));
|
|
122
122
|
markStoreDamaged(thrown, {
|
|
123
123
|
store: storePath(options.env),
|
|
124
124
|
command: `${options.app.command} ${options.command}`,
|
package/dist/services/archive.js
CHANGED
|
@@ -123,15 +123,24 @@ export const archiveService = (deps) => {
|
|
|
123
123
|
return { chat: limit.chatId ?? null, fetched: 0, complete: false, ranges: [], limited: "group_too_large" };
|
|
124
124
|
}
|
|
125
125
|
const windowed = limit?.keepFrom !== undefined && !(limit.keepFrom <= (options.sinceMs ?? Number.NEGATIVE_INFINITY));
|
|
126
|
+
const roots = new Map();
|
|
127
|
+
const startedAt = Date.now();
|
|
126
128
|
const fetched = await fetchInto({
|
|
127
|
-
history: (window) =>
|
|
129
|
+
history: async (window) => {
|
|
130
|
+
const page = await history(chat, { ...window, reactions: false });
|
|
131
|
+
if (refreshes(connection) && !options.window && page.items[0])
|
|
132
|
+
pagedRoots(roots, await connection.threadRootsIn(page.items[0].chatId, page.items), window.before);
|
|
133
|
+
return page;
|
|
134
|
+
},
|
|
128
135
|
store,
|
|
129
136
|
account,
|
|
130
137
|
fetching: deps.messenger.fetching ?? FETCHING,
|
|
131
138
|
...options,
|
|
132
139
|
...(windowed ? { sinceMs: limit.keepFrom } : {}),
|
|
133
140
|
});
|
|
134
|
-
const replies = fetched.chat && !options.window
|
|
141
|
+
const replies = fetched.chat && !options.window
|
|
142
|
+
? await savedReplies(connection, store, account, fetched.chat, { roots, startedAt }, options.stop)
|
|
143
|
+
: 0;
|
|
135
144
|
const read = replies > 0 ? { ...fetched, fetched: fetched.fetched + replies } : fetched;
|
|
136
145
|
const result = windowed && read.reachedSince ? { ...read, limited: "older_than_window" } : read;
|
|
137
146
|
if (result.limited && limit?.keepFrom !== undefined)
|
|
@@ -169,7 +178,7 @@ export const archiveService = (deps) => {
|
|
|
169
178
|
const upToDate = heldToNewest(await deps.store(), await deps.account(), deps.messenger.fetching ?? FETCHING, {
|
|
170
179
|
...options,
|
|
171
180
|
catchUp: catchingUp ? (options.catchUp ?? {}) : false,
|
|
172
|
-
threads: connection.threadReplies !== undefined,
|
|
181
|
+
threads: connection.threadReplies !== undefined || refreshes(connection),
|
|
173
182
|
});
|
|
174
183
|
const finished = () => options.onChat?.({ chats: chats.length, done: answer.items.length, fetched: answer.fetched });
|
|
175
184
|
finished();
|
|
@@ -428,18 +437,32 @@ const heldToNewest = (store, account, fetching, options) => async (chat) => {
|
|
|
428
437
|
return !Number.isNaN(startedAt) && startedAt < options.sinceMs;
|
|
429
438
|
};
|
|
430
439
|
const threadsKey = (chatId) => `threads:${chatId}`;
|
|
440
|
+
const refreshes = (connection) => connection.threadRootsIn !== undefined &&
|
|
441
|
+
connection.recentThreadRoots !== undefined &&
|
|
442
|
+
connection.rootReplies !== undefined;
|
|
443
|
+
const pagedRoots = (into, roots, before) => {
|
|
444
|
+
for (const root of roots)
|
|
445
|
+
into.set(root.id, { ...root, whole: before !== undefined || into.get(root.id)?.whole === true });
|
|
446
|
+
};
|
|
447
|
+
/** `since` is this machine's clock, a reply's time the messenger's: the overlap keeps one sent while they differ. */
|
|
448
|
+
const THREAD_CLOCK_SKEW_MS = 60_000;
|
|
431
449
|
/**
|
|
432
450
|
* The replies a messenger's history pages leave out, saved without a held stretch: they say nothing of the history
|
|
433
|
-
* around them. `since` is when the last read of them started
|
|
451
|
+
* around them. `since` is when the last read of them started: before its history pages, so a reply sent while they
|
|
452
|
+
* were read is asked for again.
|
|
434
453
|
*/
|
|
435
|
-
const savedReplies = async (connection, store, account, chatId, stop) => {
|
|
436
|
-
if (
|
|
454
|
+
const savedReplies = async (connection, store, account, chatId, { roots, startedAt }, stop) => {
|
|
455
|
+
if (stop.aborted)
|
|
456
|
+
return 0;
|
|
457
|
+
const stored = Number((await store.sync.syncState(account, threadsKey(chatId)))?.value);
|
|
458
|
+
const point = Number.isFinite(stored) ? stored : undefined;
|
|
459
|
+
const batches = refreshes(connection)
|
|
460
|
+
? refreshedThreads(connection, chatId, roots, point, stop)
|
|
461
|
+
: connection.threadReplies
|
|
462
|
+
? await readyBatches(connection.threadReplies(chatId, point === undefined ? {} : { since: point }))
|
|
463
|
+
: undefined;
|
|
464
|
+
if (!batches)
|
|
437
465
|
return 0;
|
|
438
|
-
const startedAt = Date.now();
|
|
439
|
-
const point = Number((await store.sync.syncState(account, threadsKey(chatId)))?.value);
|
|
440
|
-
// Awaited first: the flood wrapper turns every adapter method async, so batches arrive inside a promise.
|
|
441
|
-
const answer = await connection.threadReplies(chatId, Number.isFinite(point) ? { since: point } : {});
|
|
442
|
-
const batches = Symbol.asyncIterator in answer ? answer : [answer];
|
|
443
466
|
let saved = 0;
|
|
444
467
|
for await (const replies of batches) {
|
|
445
468
|
if (replies.length > 0)
|
|
@@ -452,6 +475,33 @@ const savedReplies = async (connection, store, account, chatId, stop) => {
|
|
|
452
475
|
await store.sync.setSyncState(account, threadsKey(chatId), String(startedAt));
|
|
453
476
|
return saved;
|
|
454
477
|
};
|
|
478
|
+
// Awaited first: the flood wrapper turns every adapter method async, so batches arrive inside a promise.
|
|
479
|
+
const readyBatches = async (answer) => {
|
|
480
|
+
const ready = await answer;
|
|
481
|
+
return Symbol.asyncIterator in ready ? ready : [ready];
|
|
482
|
+
};
|
|
483
|
+
/** One thread at a time, so each is saved as it comes: the roots the pages showed, then the messenger's recent ones. */
|
|
484
|
+
async function* refreshedThreads(connection, chatId, roots, point, stop) {
|
|
485
|
+
const after = point === undefined ? undefined : point - THREAD_CLOCK_SKEW_MS;
|
|
486
|
+
const all = new Map(roots);
|
|
487
|
+
for (const root of await connection.recentThreadRoots(chatId)) {
|
|
488
|
+
const paged = all.get(root.id);
|
|
489
|
+
all.set(root.id, {
|
|
490
|
+
...root,
|
|
491
|
+
lastReplyAt: newest(paged?.lastReplyAt, root.lastReplyAt),
|
|
492
|
+
whole: paged?.whole ?? false,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
for (const root of all.values()) {
|
|
496
|
+
if (stop.aborted)
|
|
497
|
+
return;
|
|
498
|
+
const replied = Date.parse(root.lastReplyAt ?? "");
|
|
499
|
+
if (after !== undefined && !root.whole && !(replied > after))
|
|
500
|
+
continue;
|
|
501
|
+
yield* await readyBatches(connection.rootReplies(chatId, root.id, after === undefined || root.whole ? {} : { after }));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const newest = (one, other) => one === undefined || (other !== undefined && Date.parse(other) > Date.parse(one)) ? other : one;
|
|
455
505
|
/** When the message a held stretch starts at was sent: by time the key is the time; by id, the stored message says. */
|
|
456
506
|
const timeOfKey = async (store, account, chatId, key, byTime, fallback) => {
|
|
457
507
|
if (byTime)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { constants, mkdirSync } from "node:fs";
|
|
3
|
-
import { lstat, open,
|
|
3
|
+
import { lstat, open, stat } from "node:fs/promises";
|
|
4
4
|
import { CliError } from "@wirecat/cli-base";
|
|
5
5
|
import { queryFieldsOf, timezoneOf, walkQuery } from "@wirecat/cli-base/query";
|
|
6
6
|
import { directoryPaths } from "../attachments/directory.js";
|
|
7
7
|
import { documentExtractor, documentKind } from "../attachments/documents.js";
|
|
8
8
|
import { classify, engineMissing, extractText, importEngine, MAX_TEXT_CHARS, } from "../attachments/extract.js";
|
|
9
|
-
import { attachmentMaxBytes } from "../attachments/limits.js";
|
|
9
|
+
import { asBytes, attachmentMaxBytes, readWhole, sizeText } from "../attachments/limits.js";
|
|
10
10
|
import { ocrImage, ocrPdf } from "../attachments/ocr.js";
|
|
11
11
|
import { pdfPreview } from "../attachments/pdf-preview.js";
|
|
12
12
|
import { pictureExtractor, pictureReaderOf, readPictureReading, readPictureWithAgent, } from "../attachments/picture-reading.js";
|
|
@@ -47,7 +47,7 @@ const outcome = async (file, path, load, signal, noFollow = false, ocr, env = pr
|
|
|
47
47
|
status: "too-large",
|
|
48
48
|
issue: withRecovery({
|
|
49
49
|
code: "validation_error",
|
|
50
|
-
message: `attachment exceeds ${maxBytes
|
|
50
|
+
message: `attachment exceeds ${sizeText(maxBytes)}; configure MESSAGING_ATTACHMENT_MAX_MIB`,
|
|
51
51
|
setting: "MESSAGING_ATTACHMENT_MAX_MIB",
|
|
52
52
|
}),
|
|
53
53
|
});
|
|
@@ -68,7 +68,7 @@ const outcome = async (file, path, load, signal, noFollow = false, ocr, env = pr
|
|
|
68
68
|
return { status: "missing" };
|
|
69
69
|
if (opened.size > maxBytes)
|
|
70
70
|
return tooLarge();
|
|
71
|
-
bytes =
|
|
71
|
+
bytes = asBytes(await readWhole(handle, signal));
|
|
72
72
|
}
|
|
73
73
|
finally {
|
|
74
74
|
await handle.close();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { engineHint, extractText, importEngine, MAX_TEXT_CHARS } from "../../attachments/extract.js";
|
|
3
|
-
import { attachmentMaxBytes } from "../../attachments/limits.js";
|
|
3
|
+
import { attachmentMaxBytes, sizeText } from "../../attachments/limits.js";
|
|
4
4
|
const READABLE = new Set([
|
|
5
5
|
"application/pdf",
|
|
6
6
|
"application/msword",
|
|
@@ -46,6 +46,6 @@ export const fileText = async (bytes, file, command, env = process.env) => {
|
|
|
46
46
|
? "file could not be read as text; it may be damaged or protected"
|
|
47
47
|
: read.status === "unsupported"
|
|
48
48
|
? "file contents do not match its type"
|
|
49
|
-
: `file is too large for the document readers (over ${
|
|
49
|
+
: `file is too large for the document readers (over ${sizeText(attachmentMaxBytes(env))}, or over ${MAX_TEXT_CHARS} characters of text)`;
|
|
50
50
|
throw new CliError("validation_error", reason);
|
|
51
51
|
};
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
+
error?: undefined;
|
|
17
18
|
chatId: string;
|
|
18
19
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
19
20
|
algorithm: string;
|
|
20
21
|
fetchedAt: string | null;
|
|
21
22
|
source: string;
|
|
22
|
-
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
|
@@ -4,7 +4,7 @@ import type { Proposer } from "../../../store/decisions.js";
|
|
|
4
4
|
import type { Decision, ProposalFilter, ProposalKind, ProposalRow } from "../types.js";
|
|
5
5
|
/** A stored author as a proposer, with the kind read from its bot row. */
|
|
6
6
|
export declare const proposerOfAuthor: (author: {
|
|
7
|
-
type: "person" | "
|
|
7
|
+
type: "person" | "agent";
|
|
8
8
|
id: string;
|
|
9
9
|
name: string | null;
|
|
10
10
|
kind: "agent" | "rule" | null;
|
|
@@ -4,13 +4,13 @@ export const proposerOfAuthor = (author) => {
|
|
|
4
4
|
return { type: "person", id: author.id };
|
|
5
5
|
if (author.name === null)
|
|
6
6
|
return { type: "unknown" };
|
|
7
|
-
return { type: "
|
|
7
|
+
return { type: "agent", id: author.id, name: author.name, kind: author.kind ?? "agent" };
|
|
8
8
|
};
|
|
9
9
|
const byMatches = (row, by) => {
|
|
10
10
|
if (by === undefined)
|
|
11
11
|
return true;
|
|
12
12
|
const proposer = row.proposedBy;
|
|
13
|
-
if (proposer.type !== "
|
|
13
|
+
if (proposer.type !== "agent")
|
|
14
14
|
return false;
|
|
15
15
|
if (by === "agent" || by === "rule")
|
|
16
16
|
return proposer.kind === by;
|