@wirecat/cli-core 0.642.0 → 0.644.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 +197 -0
- package/dist/attachments/ocr.js +27 -18
- package/dist/attachments/picture-reading.d.ts +51 -0
- package/dist/attachments/picture-reading.js +207 -0
- package/dist/background/backfill.d.ts +4 -2
- package/dist/background/backfill.js +3 -3
- package/dist/background/schedules.d.ts +23 -1
- package/dist/background/schedules.js +45 -17
- package/dist/background/units.d.ts +2 -0
- package/dist/background/units.js +8 -9
- package/dist/calendar/cli/index.js +10 -2
- package/dist/calendar/feeds.js +2 -2
- package/dist/calendar/server-search.js +2 -2
- package/dist/calendar/source.d.ts +4 -3
- package/dist/calendar/sync.js +12 -10
- package/dist/calendar/testing/source-contract.js +5 -4
- package/dist/calendar/testing/source.js +3 -2
- package/dist/cli/complete-command.d.ts +23 -0
- package/dist/cli/complete-command.js +80 -0
- package/dist/cli/context.js +7 -1
- package/dist/cli/effects.d.ts +2 -0
- package/dist/cli/effects.js +2 -0
- package/dist/cli/envelope.js +6 -1
- package/dist/cli/help/first-screen.js +5 -0
- package/dist/cli/index.d.ts +4 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/list-query.d.ts +3 -1
- package/dist/cli/list-query.js +5 -3
- package/dist/cli/local-only-command.js +9 -0
- package/dist/cli/messenger/backfill-command.js +1 -1
- package/dist/cli/messenger/chat-queries.js +2 -1
- package/dist/cli/messenger/complete-command.d.ts +4 -7
- package/dist/cli/messenger/complete-command.js +31 -98
- package/dist/cli/messenger/contacts-command.js +4 -0
- package/dist/cli/messenger/guard-commands.js +1 -1
- package/dist/cli/messenger/images-command.js +32 -0
- package/dist/cli/messenger/list-result-queries.d.ts +1 -0
- package/dist/cli/messenger/list-result-queries.js +2 -1
- package/dist/cli/messenger/mentions-command.js +3 -3
- package/dist/cli/messenger/message-items.js +1 -0
- package/dist/cli/messenger/messages-command.js +7 -6
- package/dist/cli/messenger/people-queries.d.ts +2 -2
- package/dist/cli/messenger/people-queries.js +4 -4
- package/dist/cli/messenger/search-answers.js +2 -2
- package/dist/cli/messenger/search-command.js +3 -3
- package/dist/cli/messenger/searches-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.js +4 -0
- package/dist/cli/messenger/tasks-analysis-command.js +1 -1
- package/dist/cli/messenger/tasks-command.js +2 -2
- package/dist/cli/model-catalogue-command.js +2 -0
- package/dist/cli/picture-reading-command.d.ts +12 -0
- package/dist/cli/picture-reading-command.js +82 -0
- package/dist/cli/program.d.ts +6 -0
- package/dist/cli/program.js +28 -2
- package/dist/cli/schedule/agent-start.d.ts +23 -0
- package/dist/cli/schedule/agent-start.js +115 -0
- package/dist/cli/schedule/harnesses.d.ts +203 -0
- package/dist/cli/schedule/harnesses.js +278 -0
- package/dist/cli/schedule/schedule-command.d.ts +9 -5
- package/dist/cli/schedule/schedule-command.js +89 -79
- package/dist/cli/shared-command-exports.d.ts +186 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/cli/untrusted-marks.d.ts +25 -0
- package/dist/cli/untrusted-marks.js +102 -0
- package/dist/crm/cli/index.d.ts +1 -0
- package/dist/crm/cli/index.js +6 -5
- package/dist/crm/cli/store.d.ts +30 -0
- package/dist/crm/cli/store.js +63 -0
- package/dist/crm/source.d.ts +6 -4
- package/dist/crm/sync.js +10 -6
- package/dist/crm/testing/source-contract.js +9 -7
- package/dist/crm/testing/source.js +6 -2
- package/dist/crm/testing/sync-contract.js +4 -4
- package/dist/crm/writes.d.ts +5 -2
- package/dist/crm/writes.js +1 -1
- package/dist/documents.d.ts +1 -0
- package/dist/documents.js +1 -0
- package/dist/domain/addresses.d.ts +2 -0
- package/dist/domain/addresses.js +7 -0
- package/dist/domain/attachments.d.ts +2 -0
- package/dist/domain/attachments.js +2 -1
- package/dist/domain/models.d.ts +2 -0
- package/dist/entities/attachment-results.d.ts +3 -0
- package/dist/entities/attachment-results.js +3 -0
- package/dist/entities/attachment.d.ts +2 -0
- package/dist/entities/attachment.js +8 -1
- package/dist/entities/hit.d.ts +1 -0
- package/dist/entities/index.d.ts +21 -4
- package/dist/entities/index.js +3 -2
- package/dist/entities/list-results.d.ts +33 -5
- package/dist/entities/list-results.js +33 -5
- package/dist/errors/reasons.js +31 -2
- package/dist/mail/cli/index.js +7 -6
- package/dist/mcp/agent.d.ts +2 -1
- package/dist/mcp/agent.js +5 -0
- package/dist/mcp/app-server.js +10 -0
- package/dist/mcp/surface.d.ts +7 -2
- package/dist/mcp/surface.js +49 -10
- package/dist/meetings/cli/index.js +6 -1
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/mcp/index.js +6 -3
- package/dist/meetings/participant-search.d.ts +2 -2
- package/dist/meetings/project-discovery.d.ts +1 -1
- package/dist/meetings/project-evidence-answer.js +2 -2
- package/dist/meetings/reads.d.ts +2 -2
- package/dist/meetings/reads.js +6 -6
- package/dist/meetings/store.d.ts +2 -1
- package/dist/meetings/testing/contract.js +6 -6
- package/dist/meetings/testing/memory.js +7 -2
- package/dist/models/ai.d.ts +1 -1
- package/dist/models/ai.js +3 -1
- package/dist/models/anthropic.js +15 -9
- package/dist/models/index.js +5 -3
- package/dist/models/openai.js +24 -11
- package/dist/models/types.d.ts +8 -0
- package/dist/models/types.js +11 -1
- package/dist/ports/app.d.ts +17 -1
- package/dist/ports/app.js +63 -3
- package/dist/search/lucene/plain.js +45 -3
- package/dist/search/lucene/registry.d.ts +15 -4
- package/dist/search/lucene/registry.js +70 -12
- package/dist/search/lucene/types.d.ts +2 -0
- package/dist/search/lucene/types.js +12 -0
- package/dist/sends/upload.d.ts +8 -1
- package/dist/sends/upload.js +35 -14
- package/dist/services/account-groups.d.ts +11 -0
- package/dist/services/account-groups.js +29 -0
- package/dist/services/agenda.js +1 -0
- package/dist/services/attachments.d.ts +18 -4
- package/dist/services/attachments.js +66 -15
- package/dist/services/conversations.d.ts +2 -4
- package/dist/services/conversations.js +1 -1
- package/dist/services/deal-context.js +5 -5
- package/dist/services/documents/ingestion.js +3 -3
- package/dist/services/documents/knowledge.d.ts +6 -6
- package/dist/services/documents/knowledge.js +1 -2
- package/dist/services/events-search.d.ts +3 -3
- package/dist/services/events-search.js +7 -7
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/meeting-project-discovery.js +1 -1
- package/dist/services/message-resolution.js +10 -3
- package/dist/services/messages-search.js +6 -4
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.d.ts +3 -3
- package/dist/services/notes-search.js +3 -3
- package/dist/services/organization-context.js +12 -9
- package/dist/services/people.d.ts +2 -0
- package/dist/services/people.js +4 -2
- package/dist/services/pictures.d.ts +9 -0
- package/dist/services/pictures.js +34 -28
- package/dist/services/project-status/index.js +1 -1
- package/dist/services/project-status/signals/payments.js +4 -2
- package/dist/services/project-status/signals/promises.js +5 -2
- package/dist/services/proposals/kinds/action.js +1 -1
- package/dist/services/proposals/kinds/fact.js +1 -1
- package/dist/services/proposals/kinds/findings.d.ts +2 -1
- package/dist/services/proposals/kinds/findings.js +12 -5
- package/dist/services/proposals/kinds/identity-link.js +1 -1
- package/dist/services/proposals/kinds/identity-split.js +1 -1
- package/dist/services/proposals/kinds/key-document.js +1 -1
- package/dist/services/proposals/kinds/mail-findings.d.ts +1 -1
- package/dist/services/proposals/kinds/mail-findings.js +11 -5
- package/dist/services/proposals/kinds/meeting-findings.js +10 -4
- package/dist/services/proposals/kinds/memory.js +1 -1
- package/dist/services/proposals/kinds/organization.js +1 -1
- package/dist/services/proposals/kinds/relationship-update.js +1 -1
- package/dist/services/proposals/kinds/relationship.js +1 -1
- package/dist/services/proposals/kinds/shared.d.ts +3 -2
- package/dist/services/proposals/kinds/shared.js +4 -4
- package/dist/services/proposals/kinds/source-review.js +1 -1
- package/dist/services/proposals/kinds/task-close.js +2 -2
- package/dist/services/proposals/registry.js +1 -1
- package/dist/services/proposals/types.d.ts +2 -1
- package/dist/services/search-all-business.js +3 -4
- package/dist/services/search-all.js +13 -14
- package/dist/services/searches.d.ts +2 -4
- package/dist/services/searches.js +1 -4
- package/dist/services/stored-project-gathering.js +6 -1
- package/dist/services/tags.d.ts +2 -4
- package/dist/services/tags.js +1 -1
- package/dist/services/tasks.d.ts +1 -1
- package/dist/services/tasks.js +4 -3
- package/dist/store/account-store.d.ts +2 -1
- package/dist/store/account-store.js +3 -1
- package/dist/store/accounts.d.ts +2 -0
- package/dist/store/accounts.js +8 -0
- package/dist/store/chats.d.ts +5 -0
- package/dist/store/chats.js +4 -0
- package/dist/store/evidence-findings.d.ts +9 -0
- package/dist/store/exports.d.ts +1 -1
- package/dist/store/exports.js +1 -1
- package/dist/store/identity-links.d.ts +3 -1
- package/dist/store/mail-findings.d.ts +9 -0
- package/dist/store/meeting-findings.d.ts +9 -0
- package/dist/store/searches.d.ts +3 -2
- package/dist/store/sqlite/accounts.js +37 -0
- package/dist/store/sqlite/agent-actions.d.ts +2 -1
- package/dist/store/sqlite/agent-actions.js +10 -4
- package/dist/store/sqlite/business-contracts.d.ts +3 -1
- package/dist/store/sqlite/business-contracts.js +7 -3
- package/dist/store/sqlite/business-search.d.ts +2 -1
- package/dist/store/sqlite/business-search.js +6 -4
- package/dist/store/sqlite/deals.d.ts +6 -4
- package/dist/store/sqlite/deals.js +12 -7
- package/dist/store/sqlite/evidence-findings.js +78 -9
- package/dist/store/sqlite/facts.d.ts +2 -1
- package/dist/store/sqlite/facts.js +6 -2
- package/dist/store/sqlite/finance.d.ts +4 -2
- package/dist/store/sqlite/finance.js +13 -6
- package/dist/store/sqlite/findings-core.d.ts +56 -2
- package/dist/store/sqlite/findings-core.js +109 -22
- package/dist/store/sqlite/identities.d.ts +4 -0
- package/dist/store/sqlite/identities.js +12 -3
- package/dist/store/sqlite/identity-proposals.js +34 -4
- package/dist/store/sqlite/lucene-fields.d.ts +2 -0
- package/dist/store/sqlite/lucene-fields.js +28 -2
- package/dist/store/sqlite/lucene.js +21 -10
- package/dist/store/sqlite/mail-findings.js +60 -22
- package/dist/store/sqlite/meeting-findings.js +53 -7
- package/dist/store/sqlite/meeting-participant-search.js +4 -5
- package/dist/store/sqlite/meetings.js +7 -3
- package/dist/store/sqlite/memories.d.ts +4 -2
- package/dist/store/sqlite/memories.js +13 -6
- package/dist/store/sqlite/money-transactions.d.ts +3 -1
- package/dist/store/sqlite/money-transactions.js +7 -3
- package/dist/store/sqlite/name-traces.d.ts +3 -3
- package/dist/store/sqlite/name-traces.js +29 -2
- package/dist/store/sqlite/orders.d.ts +3 -1
- package/dist/store/sqlite/orders.js +5 -2
- package/dist/store/sqlite/people-list.js +67 -22
- package/dist/store/sqlite/person-match-scan.d.ts +3 -1
- package/dist/store/sqlite/person-match-scan.js +97 -7
- package/dist/store/sqlite/products.d.ts +3 -1
- package/dist/store/sqlite/products.js +5 -2
- package/dist/store/sqlite/proposed-actions.d.ts +2 -1
- package/dist/store/sqlite/proposed-actions.js +7 -3
- package/dist/store/sqlite/query-filter.d.ts +4 -0
- package/dist/store/sqlite/query-filter.js +14 -0
- package/dist/store/sqlite/reads.d.ts +1 -0
- package/dist/store/sqlite/reads.js +14 -0
- package/dist/store/sqlite/records.d.ts +3 -1
- package/dist/store/sqlite/records.js +7 -5
- package/dist/store/sqlite/rows-page.d.ts +3 -0
- package/dist/store/sqlite/rows-page.js +4 -0
- package/dist/store/sqlite/searches.d.ts +2 -1
- package/dist/store/sqlite/searches.js +3 -1
- package/dist/store/sqlite/subscriptions.d.ts +5 -2
- package/dist/store/sqlite/subscriptions.js +13 -6
- package/dist/store/sqlite/task-board.js +27 -0
- package/dist/store/sqlite/task-find.d.ts +15 -0
- package/dist/store/sqlite/task-find.js +1 -0
- package/dist/store/sqlite/wallets.d.ts +3 -1
- package/dist/store/sqlite/wallets.js +7 -3
- package/dist/store/sqlite/work-tasks.d.ts +3 -11
- package/dist/store/sqlite/work-tasks.js +8 -4
- package/package.json +2 -2
- package/parity.json +24 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type QueryAst } from "@wirecat/cli-base/query";
|
|
2
|
+
import type { ListResult } from "@wirecat/cli-base/standards";
|
|
2
3
|
import type * as v from "valibot";
|
|
3
4
|
import { type Engine, type LoadEngine } from "../attachments/extract.js";
|
|
4
5
|
import { type OcrPipeline } from "../attachments/ocr.js";
|
|
@@ -77,6 +78,12 @@ export interface AttachmentTextSet {
|
|
|
77
78
|
/** What the stored text was before, if any. */
|
|
78
79
|
replaced: TextOrigin | null;
|
|
79
80
|
}
|
|
81
|
+
/** A picture the owner's coding agent read, as `images read` answers it. */
|
|
82
|
+
export interface PictureRead extends AttachmentTextSet {
|
|
83
|
+
/** `agent:claude`, `agent:codex/<model>`: what the store keeps as the text's extractor. */
|
|
84
|
+
extractor: string;
|
|
85
|
+
text: string;
|
|
86
|
+
}
|
|
80
87
|
export interface AttachmentBytes {
|
|
81
88
|
ref: string;
|
|
82
89
|
attachment: number;
|
|
@@ -111,10 +118,7 @@ export interface AttachmentsService {
|
|
|
111
118
|
limit: number;
|
|
112
119
|
offset?: number;
|
|
113
120
|
query?: QueryAst;
|
|
114
|
-
}): Promise<
|
|
115
|
-
items: AttachmentItem[];
|
|
116
|
-
has_more: boolean;
|
|
117
|
-
}>;
|
|
121
|
+
}): Promise<ListResult<AttachmentItem>>;
|
|
118
122
|
/**
|
|
119
123
|
* Copies files the store already holds to `output`, never over a file there, and never asks the messenger: one
|
|
120
124
|
* not held locally is an error before anything is written. The store keeps pointing at its own copy.
|
|
@@ -132,5 +136,15 @@ export interface AttachmentsService {
|
|
|
132
136
|
attachment?: number;
|
|
133
137
|
text: string;
|
|
134
138
|
}): Promise<AttachmentTextSet>;
|
|
139
|
+
/**
|
|
140
|
+
* Gives one picture to the coding agent the owner chose in `picture_reading` and keeps the text it read. Refused
|
|
141
|
+
* while that setting is `never`. The bytes come from the saved copy, else from the messenger; none are kept.
|
|
142
|
+
*/
|
|
143
|
+
readPicture(target: {
|
|
144
|
+
chat: string;
|
|
145
|
+
message?: string;
|
|
146
|
+
attachment?: number;
|
|
147
|
+
signal?: AbortSignal;
|
|
148
|
+
}): Promise<PictureRead>;
|
|
135
149
|
}
|
|
136
150
|
export declare const attachmentsService: (deps: ServiceDeps) => AttachmentsService;
|
|
@@ -9,17 +9,20 @@ import { classify, engineMissing, extractText, importEngine, MAX_TEXT_CHARS, } f
|
|
|
9
9
|
import { attachmentMaxBytes } from "../attachments/limits.js";
|
|
10
10
|
import { ocrImage, ocrPdf } from "../attachments/ocr.js";
|
|
11
11
|
import { pdfPreview } from "../attachments/pdf-preview.js";
|
|
12
|
+
import { pictureExtractor, pictureReaderOf, readPictureReading, readPictureWithAgent, } from "../attachments/picture-reading.js";
|
|
12
13
|
import { retainedBytes, transferMime, validateWindow } from "../attachments/transfer.js";
|
|
13
14
|
import { NOT_FILES } from "../domain/attachments.js";
|
|
14
15
|
import { formatLocator, isLocator, parseLocator } from "../domain/locator.js";
|
|
15
16
|
import { withRecovery } from "../domain/recovery.js";
|
|
16
17
|
import { attachment as attachmentEntity } from "../entities/attachment.js";
|
|
18
|
+
import { capability } from "../ports/messenger.js";
|
|
17
19
|
import { refusedPlace } from "../sends/upload.js";
|
|
18
20
|
import { attachmentColumns, queryFilter, } from "../store/store.js";
|
|
19
21
|
import { batchProgress } from "./batch.js";
|
|
20
22
|
import { accountStore } from "./deps.js";
|
|
21
|
-
import { save } from "./file-download.js";
|
|
23
|
+
import { refreshedFiles, save } from "./file-download.js";
|
|
22
24
|
import { chatIdIn } from "./message-resolution.js";
|
|
25
|
+
import { PICTURE_MAX_BYTES, pictureBytes } from "./pictures.js";
|
|
23
26
|
export const ATTACHMENT_QUERY = {
|
|
24
27
|
entity: "attachment",
|
|
25
28
|
backend: "sql",
|
|
@@ -150,6 +153,22 @@ const messageOf = async (deps, store, chat, message) => {
|
|
|
150
153
|
throw new CliError("validation_error", "which message? give its id after the chat");
|
|
151
154
|
return { chatId: await chatIdIn(deps.messenger, chat, store, { includeLeft: true }), messageId: message.trim() };
|
|
152
155
|
};
|
|
156
|
+
const oneFile = async (store, chatId, messageId, attachment) => {
|
|
157
|
+
const files = (await store.attachments.attachments({ chatId, messageId, limit: 1000 })).filter(({ kind }) => !NOT_FILES.has(kind));
|
|
158
|
+
if (files.length === 0)
|
|
159
|
+
throw new CliError("not_found", `the local store holds no message ${messageId} with a file in chat ${chatId}`);
|
|
160
|
+
const chosen = attachment === undefined
|
|
161
|
+
? files.length === 1
|
|
162
|
+
? files[0]
|
|
163
|
+
: undefined
|
|
164
|
+
: files.find(({ position }) => position === attachment - 1);
|
|
165
|
+
if (!chosen)
|
|
166
|
+
throw new CliError("validation_error", attachment === undefined
|
|
167
|
+
? `message ${messageId} has ${files.length} files — name one with --attachment (${files.map(({ position }) => position + 1).join(", ")})`
|
|
168
|
+
: `message ${messageId} has no file number ${attachment} — it has ${files.map(({ position }) => position + 1).join(", ")}`);
|
|
169
|
+
return chosen;
|
|
170
|
+
};
|
|
171
|
+
const PICTURE_NAME = /\.(png|jpe?g|webp)$/i;
|
|
153
172
|
export const attachmentsService = (deps) => ({
|
|
154
173
|
extract: async ({ chat, message: onlyMessage, paths, fromDir, cursor, scanLimit: requestedScanLimit, limit: requestedLimit, download, onItem, signal, load = importEngine, ocr, concurrency = 1, } = {}) => {
|
|
155
174
|
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 8 || (concurrency !== 1 && !ocr))
|
|
@@ -350,7 +369,7 @@ export const attachmentsService = (deps) => ({
|
|
|
350
369
|
chats.set(node.value, await chatIdIn(deps.messenger, node.value, store, { includeLeft: true }));
|
|
351
370
|
const where = query ? queryFilter(query, attachmentColumns(chats), { command: "attachments list" }) : undefined;
|
|
352
371
|
const views = await store.attachments.attachments({ ...(where ? { where } : {}), offset, limit: limit + 1 });
|
|
353
|
-
return { items: views.slice(0, limit).map((view) => itemOf(account, view)),
|
|
372
|
+
return { items: views.slice(0, limit).map((view) => itemOf(account, view)), hasMore: views.length > limit };
|
|
354
373
|
},
|
|
355
374
|
show: async ({ chat, message, attachment, page, load, ...window }) => {
|
|
356
375
|
validateWindow(window);
|
|
@@ -458,19 +477,7 @@ export const attachmentsService = (deps) => ({
|
|
|
458
477
|
const store = await accountStore(deps);
|
|
459
478
|
const { account } = store;
|
|
460
479
|
const { chatId, messageId } = await messageOf(deps, store, chat, message);
|
|
461
|
-
const
|
|
462
|
-
if (files.length === 0)
|
|
463
|
-
throw new CliError("not_found", `the local store holds no message ${messageId} with a file in chat ${chatId}`);
|
|
464
|
-
const chosen = attachment === undefined
|
|
465
|
-
? files.length === 1
|
|
466
|
-
? files[0]
|
|
467
|
-
: undefined
|
|
468
|
-
: files.find(({ position }) => position === attachment - 1);
|
|
469
|
-
if (!chosen) {
|
|
470
|
-
throw new CliError("validation_error", attachment === undefined
|
|
471
|
-
? `message ${messageId} has ${files.length} files — name one with --attachment (${files.map(({ position }) => position + 1).join(", ")})`
|
|
472
|
-
: `message ${messageId} has no file number ${attachment} — it has ${files.map(({ position }) => position + 1).join(", ")}`);
|
|
473
|
-
}
|
|
480
|
+
const chosen = await oneFile(store, chatId, messageId, attachment);
|
|
474
481
|
await store.attachments.keepAttachmentText(chosen.pk, { text, origin: "agent", extractor: "agent" });
|
|
475
482
|
return {
|
|
476
483
|
ref: formatLocator({ ...account, chat: chatId, message: messageId }),
|
|
@@ -480,4 +487,48 @@ export const attachmentsService = (deps) => ({
|
|
|
480
487
|
replaced: chosen.text?.origin ?? null,
|
|
481
488
|
};
|
|
482
489
|
},
|
|
490
|
+
readPicture: async ({ chat, message, attachment, signal }) => {
|
|
491
|
+
const env = deps.env ?? process.env;
|
|
492
|
+
const reader = pictureReaderOf(readPictureReading(env), deps.messenger.app.command);
|
|
493
|
+
const store = await accountStore(deps);
|
|
494
|
+
const { account } = store;
|
|
495
|
+
const { chatId, messageId } = await messageOf(deps, store, chat, message);
|
|
496
|
+
const chosen = await oneFile(store, chatId, messageId, attachment);
|
|
497
|
+
const ref = formatLocator({ ...account, chat: chatId, message: messageId });
|
|
498
|
+
const notPicture = new CliError("validation_error", `file ${chosen.position + 1} of ${ref} is not a picture`, {
|
|
499
|
+
reason: "picture-reading.not-a-picture",
|
|
500
|
+
});
|
|
501
|
+
if (chosen.kind !== "photo" && !chosen.mime?.startsWith("image/") && !PICTURE_NAME.test(chosen.name ?? ""))
|
|
502
|
+
throw notPicture;
|
|
503
|
+
const localPath = chosen.localPath !== null && !refusedPlace(chosen.localPath, deps.messenger.app, env) ? chosen.localPath : null;
|
|
504
|
+
const bytes = await pictureBytes({ localPath, position: chosen.position }, async () => (await capability(await deps.connection(), "download", "download attachments")(chatId, messageId)).files, async (file) => {
|
|
505
|
+
const refreshed = refreshedFiles([file]);
|
|
506
|
+
if (refreshed.length > 0)
|
|
507
|
+
await store.attachments.keepProviderRefs(chatId, messageId, refreshed).catch(() => undefined);
|
|
508
|
+
});
|
|
509
|
+
if (!bytes)
|
|
510
|
+
throw new CliError("not_found", `file ${chosen.position + 1} of ${ref} could not be fetched, or is over ${PICTURE_MAX_BYTES / 1024 / 1024} MB`, { reason: "picture-reading.unavailable-file" });
|
|
511
|
+
const mime = transferMime(Buffer.from(bytes.subarray(0, 16)), null);
|
|
512
|
+
if (!mime.startsWith("image/"))
|
|
513
|
+
throw notPicture;
|
|
514
|
+
const read = await readPictureWithAgent({ ...reader, bytes, mime, env, ...(signal ? { signal } : {}) });
|
|
515
|
+
const text = read.slice(0, MAX_TEXT_CHARS);
|
|
516
|
+
const extractor = pictureExtractor(reader.agent, reader.model);
|
|
517
|
+
await store.attachments.keepAttachmentText(chosen.pk, {
|
|
518
|
+
text,
|
|
519
|
+
origin: "agent",
|
|
520
|
+
extractor,
|
|
521
|
+
contentSha256: createHash("sha256").update(bytes).digest("hex"),
|
|
522
|
+
bytes: bytes.length,
|
|
523
|
+
});
|
|
524
|
+
return {
|
|
525
|
+
ref,
|
|
526
|
+
attachment: chosen.position + 1,
|
|
527
|
+
origin: "agent",
|
|
528
|
+
extractor,
|
|
529
|
+
chars: text.length,
|
|
530
|
+
replaced: chosen.text?.origin ?? null,
|
|
531
|
+
text,
|
|
532
|
+
};
|
|
533
|
+
},
|
|
483
534
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type QueryAst } from "@wirecat/cli-base/query";
|
|
2
|
+
import type { ListResult } from "@wirecat/cli-base/standards";
|
|
2
3
|
import type * as v from "valibot";
|
|
3
4
|
import type { Id, Message } from "../domain/models.js";
|
|
4
5
|
import { conversation } from "../entities/conversation.js";
|
|
@@ -42,10 +43,7 @@ export interface ConversationsService {
|
|
|
42
43
|
limit: number;
|
|
43
44
|
offset?: number;
|
|
44
45
|
query?: QueryAst;
|
|
45
|
-
}): Promise<
|
|
46
|
-
items: ConversationItem[];
|
|
47
|
-
has_more: boolean;
|
|
48
|
-
}>;
|
|
46
|
+
}): Promise<ListResult<ConversationItem>>;
|
|
49
47
|
/** By the conversation's id, or as the conversation a message is in. */
|
|
50
48
|
show(target: {
|
|
51
49
|
id: string;
|
|
@@ -95,7 +95,7 @@ export const conversationsService = (deps) => {
|
|
|
95
95
|
const where = query ? queryFilter(query, CONVERSATION_COLUMNS, { command: "conversations list" }) : undefined;
|
|
96
96
|
const page = await store.conversations.conversations(chatId, { limit, offset, ...(where ? { where } : {}) });
|
|
97
97
|
const account = await deps.account();
|
|
98
|
-
return { items: page.items.map((one) => conversationItem(account, one)),
|
|
98
|
+
return { items: page.items.map((one) => conversationItem(account, one)), hasMore: page.hasMore };
|
|
99
99
|
},
|
|
100
100
|
show: async (target) => {
|
|
101
101
|
const store = await accountStore(deps);
|
|
@@ -43,10 +43,10 @@ export const dealContext = async (store, reference, { accounts, limit = SECTION_
|
|
|
43
43
|
for (const [way, invoiceFilter, paymentFilter] of ways) {
|
|
44
44
|
const invoiceRows = await store.finance.invoices({ ...invoiceFilter, limit: STORE_PAGE });
|
|
45
45
|
const paymentRows = await store.finance.payments({ ...paymentFilter, limit: STORE_PAGE });
|
|
46
|
-
complete &&= invoiceRows.
|
|
47
|
-
for (const invoice of notRejected(invoiceRows))
|
|
46
|
+
complete &&= !invoiceRows.hasMore && !paymentRows.hasMore;
|
|
47
|
+
for (const invoice of notRejected(invoiceRows.items))
|
|
48
48
|
invoices.push([invoice, way]);
|
|
49
|
-
for (const payment of notRejected(paymentRows))
|
|
49
|
+
for (const payment of notRejected(paymentRows.items))
|
|
50
50
|
payments.push([payment, way]);
|
|
51
51
|
}
|
|
52
52
|
const only = ways.length === 1 ? ways[0]?.[0] : undefined;
|
|
@@ -75,7 +75,7 @@ export const dealContext = async (store, reference, { accounts, limit = SECTION_
|
|
|
75
75
|
const said = talks.counts.messages + talks.counts.mail + talks.counts.meetings;
|
|
76
76
|
const stages = await store.deals.stages(deal.ref);
|
|
77
77
|
const tasks = await openTasksOf(store, project ? [{ ref: project.ref, key: project.key }] : []);
|
|
78
|
-
const opened = await store.tasks.find({
|
|
78
|
+
const { items: opened, hasMore } = await store.tasks.find({
|
|
79
79
|
where: { sql: "t.source_group = ?", params: [deal.ref] },
|
|
80
80
|
limit: STORE_PAGE,
|
|
81
81
|
});
|
|
@@ -89,7 +89,7 @@ export const dealContext = async (store, reference, { accounts, limit = SECTION_
|
|
|
89
89
|
project: task.project,
|
|
90
90
|
dueAt: task.dueAt,
|
|
91
91
|
});
|
|
92
|
-
tasks.full ||=
|
|
92
|
+
tasks.full ||= hasMore;
|
|
93
93
|
tasks.tasks.sort((a, b) => (a.dueAt ?? "~").localeCompare(b.dueAt ?? "~") || a.ref.localeCompare(b.ref));
|
|
94
94
|
return {
|
|
95
95
|
deal,
|
|
@@ -35,10 +35,10 @@ export const documentIngestion = (store, options) => {
|
|
|
35
35
|
const stale = async (ref) => {
|
|
36
36
|
for (const status of ["proposed", "confirmed"]) {
|
|
37
37
|
for (let batch = 0;; batch++) {
|
|
38
|
-
const
|
|
39
|
-
for (const memory of
|
|
38
|
+
const { items, hasMore } = await store.memories.list({ subject: ref, status, limit: 500 });
|
|
39
|
+
for (const memory of items)
|
|
40
40
|
await store.memories.markStale(memory.ref, "owner");
|
|
41
|
-
if (
|
|
41
|
+
if (!hasMore)
|
|
42
42
|
break;
|
|
43
43
|
if (batch >= 20)
|
|
44
44
|
throw new CliError("provider_error", "memory invalidation exceeded its batch bound");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { QueryAst } from "@wirecat/cli-base/query";
|
|
2
|
+
import type { ListResult } from "@wirecat/cli-base/standards";
|
|
2
3
|
import type { Author, Decider, Fact, Link, LinkInput, LinkListFilter, Memory, MemoryInput, MessageStore, Note } from "../../store/index.js";
|
|
3
4
|
export interface DocumentKnowledge {
|
|
4
5
|
documents(principal: string, query: QueryAst | undefined, page: {
|
|
@@ -35,14 +36,12 @@ export interface DocumentKnowledge {
|
|
|
35
36
|
kind?: Memory["kind"];
|
|
36
37
|
status?: Memory["status"];
|
|
37
38
|
limit?: number;
|
|
38
|
-
|
|
39
|
+
offset?: number;
|
|
40
|
+
}): Promise<ListResult<Memory>>;
|
|
39
41
|
memory(principal: string, ref: string, memoryRef: string, action?: "show"): Promise<Memory>;
|
|
40
42
|
/** `by` decides: the owner, or an agent for the owner that did not propose it. */
|
|
41
43
|
memory(principal: string, ref: string, memoryRef: string, action: "confirm" | "stale", by: Decider): Promise<Memory>;
|
|
42
|
-
searchMemories(principal: string, ref: string, query: string, scope?: Memory["scope"]): Promise<
|
|
43
|
-
items: Memory[];
|
|
44
|
-
limit_reached: boolean;
|
|
45
|
-
}>;
|
|
44
|
+
searchMemories(principal: string, ref: string, query: string, scope?: Memory["scope"]): Promise<ListResult<Memory>>;
|
|
46
45
|
addFact(principal: string, ref: string, input: {
|
|
47
46
|
statement: string;
|
|
48
47
|
type: Fact["type"];
|
|
@@ -55,7 +54,8 @@ export interface DocumentKnowledge {
|
|
|
55
54
|
type?: Fact["type"];
|
|
56
55
|
status?: Fact["status"];
|
|
57
56
|
limit?: number;
|
|
58
|
-
|
|
57
|
+
offset?: number;
|
|
58
|
+
}): Promise<ListResult<Fact>>;
|
|
59
59
|
fact(principal: string, ref: string, factRef: string, action?: "show"): Promise<Fact>;
|
|
60
60
|
/** `by` decides: the owner, or an agent for the owner that did not propose it; only the owner reverses. */
|
|
61
61
|
fact(principal: string, ref: string, factRef: string, action: "confirm" | "reverse", by: Decider): Promise<Fact>;
|
|
@@ -121,8 +121,7 @@ export const documentKnowledge = (store, folder) => {
|
|
|
121
121
|
},
|
|
122
122
|
searchMemories: async (principal, ref, query, scope) => {
|
|
123
123
|
await document(principal, ref);
|
|
124
|
-
|
|
125
|
-
return { items, limit_reached: items.length === 200 };
|
|
124
|
+
return store.memories.search(query, { subject: ref, ...(scope ? { scope } : {}), limit: 200 });
|
|
126
125
|
},
|
|
127
126
|
addFact: async (principal, ref, { statement, type, scope, by, supersedes, occurredAt }) => {
|
|
128
127
|
await document(principal, ref);
|
|
@@ -54,11 +54,11 @@ export interface EventsFound {
|
|
|
54
54
|
by: "words" | "words and meaning";
|
|
55
55
|
/** Why meaning was not searched, when it was not. */
|
|
56
56
|
meaning_skipped?: string;
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
items: FoundEvent[];
|
|
58
|
+
hasMore: boolean;
|
|
59
59
|
/** More events matched than one search reads (50,000); the later ones were not read — narrow the query. */
|
|
60
60
|
truncated?: true;
|
|
61
|
-
|
|
61
|
+
nextOffset?: number;
|
|
62
62
|
}
|
|
63
63
|
/** The calendar accounts the store holds: every account whose provider is of the `events` kind. */
|
|
64
64
|
export declare const calendarAccounts: (store: MessageStore) => Promise<AccountKey[]>;
|
|
@@ -65,7 +65,7 @@ export const searchEvents = async (store, query, { limit = 20, offset = 0, accou
|
|
|
65
65
|
});
|
|
66
66
|
const accountIds = accounts === undefined ? undefined : await accountIdsOf(store, accounts);
|
|
67
67
|
if (accountIds?.length === 0)
|
|
68
|
-
return { query, by: "words",
|
|
68
|
+
return { query, by: "words", items: [], hasMore: false };
|
|
69
69
|
const words = plainQueryWords(asked === undefined ? query : questionText(query));
|
|
70
70
|
const window = offset + limit;
|
|
71
71
|
let meaningSkipped;
|
|
@@ -109,9 +109,9 @@ export const searchEvents = async (store, query, { limit = 20, offset = 0, accou
|
|
|
109
109
|
query,
|
|
110
110
|
by,
|
|
111
111
|
...skipped,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
...(found.hasMore && window <= MAX_EVENTS_OFFSET ? {
|
|
112
|
+
items: found.items.map((hit) => foundEvent(hit, query, ["words"])),
|
|
113
|
+
hasMore: found.hasMore,
|
|
114
|
+
...(found.hasMore && window <= MAX_EVENTS_OFFSET ? { nextOffset: window } : {}),
|
|
115
115
|
...truncated,
|
|
116
116
|
};
|
|
117
117
|
const ranked = new Map();
|
|
@@ -129,12 +129,12 @@ export const searchEvents = async (store, query, { limit = 20, offset = 0, accou
|
|
|
129
129
|
return {
|
|
130
130
|
query,
|
|
131
131
|
by,
|
|
132
|
-
|
|
132
|
+
items: ordered.slice(offset, window).map(({ hit, by: halves }) => {
|
|
133
133
|
const cosine = cosines.get(keyOf(hit));
|
|
134
134
|
return { ...foundEvent(hit, query, halves), ...(cosine === undefined ? {} : { meaning_score: cosine }) };
|
|
135
135
|
}),
|
|
136
|
-
|
|
137
|
-
...(hasMore && window <= MAX_EVENTS_OFFSET ? {
|
|
136
|
+
hasMore: hasMore,
|
|
137
|
+
...(hasMore && window <= MAX_EVENTS_OFFSET ? { nextOffset: window } : {}),
|
|
138
138
|
...truncated,
|
|
139
139
|
};
|
|
140
140
|
};
|
package/dist/services/index.d.ts
CHANGED
|
@@ -174,7 +174,7 @@ export { QUERY_LIMITS, QUERY_VERSION } from "../search/lucene/types.js";
|
|
|
174
174
|
export { questionLookup } from "../search/question-plan.js";
|
|
175
175
|
export { type SearchTotal, TOTAL_CAP } from "../search/total.js";
|
|
176
176
|
export { TASK_KINDS, TASK_ORIGINS, type TaskKind, type TaskOrigin } from "../tasks/index.js";
|
|
177
|
-
export { type AccountScopeChange, addGroupMember, type ChatScope, type ChatScopeChange, type GroupMemberChange, type GroupMemberMove, type GroupStore, listAccountGroups, moveGroupMember, removeGroupMember, setAccountScope, setChatScope, } from "./account-groups.js";
|
|
177
|
+
export { type AccountScopeChange, addGroupMember, type ChatScope, type ChatScopeChange, deleteAccountGroup, type GroupMemberChange, type GroupMemberMove, type GroupStore, listAccountGroups, moveGroupMember, removeGroupMember, renameAccountGroup, setAccountScope, setChatScope, } from "./account-groups.js";
|
|
178
178
|
export type { AdminFound, AdminQuery, AdminSelection, AdminStatisticsService } from "./admin-statistics.js";
|
|
179
179
|
export { adminStatisticsService } from "./admin-statistics.js";
|
|
180
180
|
export { GAP_BOUNDS, type GapPlan, type GapRepair, gapsService, type RepairOptions } from "./archive-gaps.js";
|
package/dist/services/index.js
CHANGED
|
@@ -133,7 +133,7 @@ export { QUERY_LIMITS, QUERY_VERSION } from "../search/lucene/types.js";
|
|
|
133
133
|
export { questionLookup } from "../search/question-plan.js";
|
|
134
134
|
export { TOTAL_CAP } from "../search/total.js";
|
|
135
135
|
export { TASK_KINDS, TASK_ORIGINS } from "../tasks/index.js";
|
|
136
|
-
export { addGroupMember, listAccountGroups, moveGroupMember, removeGroupMember, setAccountScope, setChatScope, } from "./account-groups.js";
|
|
136
|
+
export { addGroupMember, deleteAccountGroup, listAccountGroups, moveGroupMember, removeGroupMember, renameAccountGroup, setAccountScope, setChatScope, } from "./account-groups.js";
|
|
137
137
|
export { adminStatisticsService } from "./admin-statistics.js";
|
|
138
138
|
export { GAP_BOUNDS, gapsService } from "./archive-gaps.js";
|
|
139
139
|
export { countersService } from "./counters.js";
|
|
@@ -159,7 +159,7 @@ export const readMeetingProjectDiscovery = async (ports, projectName, original)
|
|
|
159
159
|
limits: { limit: input.limit, maxReadBytes: input.maxReadBytes, maxVocabularyReadBytes, maxTerms },
|
|
160
160
|
project,
|
|
161
161
|
term,
|
|
162
|
-
|
|
162
|
+
items: result.items.map((hit) => cited(hit, input.accountId)),
|
|
163
163
|
association: "unconfirmed-word-evidence",
|
|
164
164
|
vocabularyFingerprint: found.fingerprint,
|
|
165
165
|
hasMore,
|
|
@@ -175,7 +175,9 @@ export const senderAmong = async (store, accounts, reference, field = "from") =>
|
|
|
175
175
|
}
|
|
176
176
|
catch (error) {
|
|
177
177
|
if (error instanceof CliError && error.code === "not_found") {
|
|
178
|
-
throw new CliError("not_found", `${field}:${reference} — ${error.message}
|
|
178
|
+
throw new CliError("not_found", `${field}:${reference} — ${error.message}; a part of the name: ${field}:*${reference}*`, {
|
|
179
|
+
reason: "query.no-match",
|
|
180
|
+
});
|
|
179
181
|
}
|
|
180
182
|
throw error;
|
|
181
183
|
}
|
|
@@ -184,8 +186,13 @@ export const senderAmong = async (store, accounts, reference, field = "from") =>
|
|
|
184
186
|
export const MOST_NAME_MATCHES = 50;
|
|
185
187
|
/** `candidates` are shaped as an ambiguous name's are: `{id, name, username}` for people, `{id, title}` for chats. */
|
|
186
188
|
const patternRefused = (field, pattern, what, found, near) => {
|
|
187
|
-
if (found === 0)
|
|
188
|
-
|
|
189
|
+
if (found === 0) {
|
|
190
|
+
const inside = `*${pattern.replace(/^\*+|\*+$/gu, "")}*`;
|
|
191
|
+
const [closest] = near;
|
|
192
|
+
throw new CliError("not_found", `${field}:${pattern} — no ${what} fits${near.length ? `; near: ${near.map(({ label }) => label).join(", ")}` : ""}` +
|
|
193
|
+
` — a pattern matches the whole name: ${pattern === inside ? "" : `write ${field}:${inside} for a part of it, or `}` +
|
|
194
|
+
`the name: ${field}:${JSON.stringify(closest?.label ?? pattern.replace(/[*?]/gu, ""))}`, { reason: "query.no-match", candidates: near.map(({ candidate }) => candidate) });
|
|
195
|
+
}
|
|
189
196
|
throw new CliError("validation_error", `${field}:${pattern} fits ${found} ${what}, more than ${MOST_NAME_MATCHES} — write more of the name`, { reason: "query.too-large", budget: "name matches", limit: MOST_NAME_MATCHES, complete: false });
|
|
190
197
|
};
|
|
191
198
|
/** Every sender a name pattern (`from:Ярослав*`) fits, through the names each messenger's accounts have seen. */
|
|
@@ -4,7 +4,7 @@ import { parseLocator } from "../domain/locator.js";
|
|
|
4
4
|
import { isImportedProvider, kindIn, UNKNOWN_PROVIDER } from "../domain/providers.js";
|
|
5
5
|
import { syncsOneChat } from "../ports/traits.js";
|
|
6
6
|
import { PRESET_VERSION } from "../search/lucene/presets.js";
|
|
7
|
-
import { FIELD_VERSION, validateAst, validateFields } from "../search/lucene/registry.js";
|
|
7
|
+
import { FIELD_VERSION, isPresence, validateAst, validateFields } from "../search/lucene/registry.js";
|
|
8
8
|
import { hasStems, hasText, isStemmed, } from "../search/lucene/resolved.js";
|
|
9
9
|
import { inSource, sourceOf } from "../search/query.js";
|
|
10
10
|
import { createStemmer, DEFAULT_STEMMERS } from "../search/stem.js";
|
|
@@ -33,7 +33,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
|
|
|
33
33
|
if (request.ast !== undefined && request.exact)
|
|
34
34
|
searchError("query.conflict", { start: 0, end: 0 }, "an AST names its fields — use field exact instead of exact");
|
|
35
35
|
const ast = request.ast !== undefined
|
|
36
|
-
? validateAst(request.ast)
|
|
36
|
+
? validateAst(request.ast, { presence: true })
|
|
37
37
|
: request.text === undefined
|
|
38
38
|
? {
|
|
39
39
|
version: 1,
|
|
@@ -49,7 +49,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
|
|
|
49
49
|
span: { start: 0, end: 0 },
|
|
50
50
|
},
|
|
51
51
|
}
|
|
52
|
-
: validateFields(parseLucene(request.text, { ...MESSAGE_PARSING, defaultField: request.exact ? "exact" : "text" }));
|
|
52
|
+
: validateFields(parseLucene(request.text, { ...MESSAGE_PARSING, defaultField: request.exact ? "exact" : "text" }), { presence: true });
|
|
53
53
|
const timezone = timezoneOf(request.timezone);
|
|
54
54
|
const stored = await store.accounts.accounts();
|
|
55
55
|
// A fresh store has no row yet for the account it runs as; "every account" still means that one.
|
|
@@ -102,6 +102,8 @@ export const prepareLucene = async (store, account, request, messenger) => {
|
|
|
102
102
|
...node,
|
|
103
103
|
clauses: await Promise.all(node.clauses.map(async ({ occur, node }) => ({ occur, node: await resolve(node) }))),
|
|
104
104
|
};
|
|
105
|
+
if (isPresence(node))
|
|
106
|
+
return node;
|
|
105
107
|
if (node.field === "chat" && node.operator === "wildcard")
|
|
106
108
|
return anyOf(node, await chatsMatchingIn(chatLookup, scopeAccounts, node.value), (chat) => ({ chat }));
|
|
107
109
|
if (node.field === "chat")
|
|
@@ -254,7 +256,7 @@ export const coverageOf = async (store, { scopeAccounts, selectedChat }, messeng
|
|
|
254
256
|
for (const chat of await store.chats.chatCompleteness(selected, chatIds))
|
|
255
257
|
completeness.push({ ...chat, ...selected });
|
|
256
258
|
const wanted = new Set(chatIds);
|
|
257
|
-
for (const one of await store.chats.
|
|
259
|
+
for (const one of await store.chats.chatsNewest(selected))
|
|
258
260
|
if (wanted.has(one.chatId))
|
|
259
261
|
stats.set(statKey(selected, one.chatId), one);
|
|
260
262
|
}
|
|
@@ -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;
|
|
@@ -139,11 +139,11 @@ export interface NotesFound {
|
|
|
139
139
|
by: "words" | "words and meaning";
|
|
140
140
|
/** Why meaning was not searched, when it was not. */
|
|
141
141
|
meaning_skipped?: string;
|
|
142
|
-
|
|
142
|
+
items: FoundNote[];
|
|
143
143
|
/** How many notes match the query, every page together, as Elasticsearch's `hits.total`. */
|
|
144
144
|
total?: SearchTotal;
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
hasMore: boolean;
|
|
146
|
+
nextOffset?: number;
|
|
147
147
|
/** What the notes found link to, most linked first. */
|
|
148
148
|
linked: LinkedRecord[];
|
|
149
149
|
/** Documents whose picture is nearest the words, best first; only when `pictures` was asked for. Never in `hits`. */
|
|
@@ -543,10 +543,10 @@ export const searchNotes = async (store, query, { limit = 20, offset = 0, tag, f
|
|
|
543
543
|
...(filter === undefined ? {} : { filter }),
|
|
544
544
|
by: meaning === undefined ? "words" : "words and meaning",
|
|
545
545
|
...(meaningSkipped === undefined ? {} : { meaning_skipped: meaningSkipped }),
|
|
546
|
-
hits,
|
|
546
|
+
items: hits,
|
|
547
547
|
total,
|
|
548
|
-
|
|
549
|
-
...(hasMore && window <= MAX_NOTES_OFFSET ? {
|
|
548
|
+
hasMore: hasMore,
|
|
549
|
+
...(hasMore && window <= MAX_NOTES_OFFSET ? { nextOffset: window } : {}),
|
|
550
550
|
linked: [...counts.values()].sort((a, b) => b.notes - a.notes || (a.name ?? a.ref ?? "").localeCompare(b.name ?? b.ref ?? "")),
|
|
551
551
|
...lane,
|
|
552
552
|
};
|
|
@@ -23,8 +23,8 @@ export const openTasksOf = async (store, projects) => {
|
|
|
23
23
|
const tasks = [];
|
|
24
24
|
let full = false;
|
|
25
25
|
for (const project of projects) {
|
|
26
|
-
const found = await store.tasks.find({ project: project.ref, limit: STORE_PAGE });
|
|
27
|
-
full ||=
|
|
26
|
+
const { items: found, hasMore } = await store.tasks.find({ project: project.ref, limit: STORE_PAGE });
|
|
27
|
+
full ||= hasMore;
|
|
28
28
|
for (const task of found)
|
|
29
29
|
if (!isClosedState(task.status))
|
|
30
30
|
tasks.push({
|
|
@@ -78,8 +78,8 @@ export const organizationContext = async (store, reference, { accounts, limit =
|
|
|
78
78
|
limit: STORE_PAGE,
|
|
79
79
|
...(accounts === undefined ? {} : { accounts }),
|
|
80
80
|
});
|
|
81
|
-
dealsFull ||= found.
|
|
82
|
-
for (const deal of found)
|
|
81
|
+
dealsFull ||= found.hasMore;
|
|
82
|
+
for (const deal of found.items)
|
|
83
83
|
deals.push(deal);
|
|
84
84
|
}
|
|
85
85
|
const catalog = new Map((await store.knowledge.projects()).map((project) => [project.ref, project]));
|
|
@@ -96,14 +96,17 @@ export const organizationContext = async (store, reference, { accounts, limit =
|
|
|
96
96
|
}
|
|
97
97
|
const invoiceRows = await store.finance.invoices({ counterparty: ref, limit: STORE_PAGE });
|
|
98
98
|
const paymentRows = await store.finance.payments({ party: ref, limit: STORE_PAGE });
|
|
99
|
-
const invoices = notRejected(invoiceRows).map((invoice) => [invoice, "counterparty"]);
|
|
100
|
-
const payments = notRejected(paymentRows).map((payment) => [
|
|
99
|
+
const invoices = notRejected(invoiceRows.items).map((invoice) => [invoice, "counterparty"]);
|
|
100
|
+
const payments = notRejected(paymentRows.items).map((payment) => [
|
|
101
|
+
payment,
|
|
102
|
+
"counterparty",
|
|
103
|
+
]);
|
|
101
104
|
const orders = [];
|
|
102
105
|
let ordersFull = false;
|
|
103
106
|
for (const side of ["customer", "supplier"]) {
|
|
104
107
|
const found = await store.orders.list({ [side]: ref, limit: STORE_PAGE });
|
|
105
|
-
ordersFull ||= found.
|
|
106
|
-
for (const order of notRejected(found))
|
|
108
|
+
ordersFull ||= found.hasMore;
|
|
109
|
+
for (const order of notRejected(found.items))
|
|
107
110
|
orders.push({
|
|
108
111
|
ref: order.ref,
|
|
109
112
|
title: order.title,
|
|
@@ -114,7 +117,7 @@ export const organizationContext = async (store, reference, { accounts, limit =
|
|
|
114
117
|
side,
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
|
-
const financeComplete = invoiceRows.
|
|
120
|
+
const financeComplete = !invoiceRows.hasMore && !paymentRows.hasMore && !ordersFull;
|
|
118
121
|
const members = [];
|
|
119
122
|
for (const person of people)
|
|
120
123
|
if (person.roles.some((role) => isUsable(role.standing))) {
|
package/dist/services/people.js
CHANGED
|
@@ -58,7 +58,7 @@ export const peopleService = (deps) => {
|
|
|
58
58
|
const held = stored ? { store: await deps.store(), account: await deps.account() } : await storeIfOpen(deps);
|
|
59
59
|
if (held && (await held.store.people.countContacts(held.account)) > 0)
|
|
60
60
|
return storedContacts(held.store, held.account, options);
|
|
61
|
-
for (const term of [options.name, options.notes])
|
|
61
|
+
for (const term of [options.name, options.notes, options.email, options.phone])
|
|
62
62
|
if (term)
|
|
63
63
|
queryError("query.unsupported-field", term.span, `${term.field}: reads the contacts kept in the local store, and it keeps none yet; \`contacts sync\` fills it`, { command: "contacts list" }, { supported: [] });
|
|
64
64
|
return contactsIn(chats ?? (await (await deps.store()).chats.chats(await deps.account(), {})).items, options, deps.messenger.partnerOf);
|
|
@@ -252,7 +252,7 @@ export const phoneOf = (typed) => {
|
|
|
252
252
|
}
|
|
253
253
|
return digits;
|
|
254
254
|
};
|
|
255
|
-
const storedContacts = async (store, account, { order, name, notes, limit, offset }) => {
|
|
255
|
+
const storedContacts = async (store, account, { order, name, notes, email, phone, limit, offset, }) => {
|
|
256
256
|
// Chats saved since the last refresh may have moved someone up; the order is worked out again here.
|
|
257
257
|
if (order === "recent")
|
|
258
258
|
await store.people.refreshRecency(account);
|
|
@@ -260,6 +260,8 @@ const storedContacts = async (store, account, { order, name, notes, limit, offse
|
|
|
260
260
|
const filter = {
|
|
261
261
|
...(query === undefined ? {} : { query }),
|
|
262
262
|
...(notes ? { notes: notes.value.replace(/^\*+|\*+$/g, "") } : {}),
|
|
263
|
+
...(email ? { email: email.value.replace(/^\*+|\*+$/g, "") } : {}),
|
|
264
|
+
...(phone ? { phone: phone.value.replace(/^\*+|\*+$/g, "") } : {}),
|
|
263
265
|
};
|
|
264
266
|
return store.people.contacts(account, {
|
|
265
267
|
order,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Id } from "../domain/models.js";
|
|
2
|
+
import { type RemoteFile } from "../ports/messenger.js";
|
|
2
3
|
import type { ServiceDeps } from "./deps.js";
|
|
3
4
|
import type { MessagesService } from "./messages.js";
|
|
4
5
|
/** A bigger file is no photo a chat sends: skipping it costs a vector, reading it costs memory. */
|
|
@@ -33,6 +34,14 @@ export interface PictureLane {
|
|
|
33
34
|
export declare const PICTURES_OFF = "picture search is off for this profile \u2014 set pictureSearch to true in its config to turn it on";
|
|
34
35
|
/** What CLIP's text side can use of a Lucene query: the words, without fields, operators and quotes. */
|
|
35
36
|
export declare const plainWords: (query: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* A picture's bytes: the saved copy when it is a regular file small enough, else a fresh download through the
|
|
39
|
+
* messenger. `read` is told which file was downloaded, so its refreshed reference can be kept.
|
|
40
|
+
*/
|
|
41
|
+
export declare const pictureBytes: (picture: {
|
|
42
|
+
localPath: string | null;
|
|
43
|
+
position: number;
|
|
44
|
+
}, files: () => Promise<RemoteFile[]>, read: (file: RemoteFile) => Promise<void>) => Promise<Uint8Array | undefined>;
|
|
36
45
|
export declare const picturesService: (deps: ServiceDeps) => {
|
|
37
46
|
/**
|
|
38
47
|
* Gives the images no vector yet one, reading each through the messenger's own download and keeping nothing
|