@wirecat/cli-core 0.641.0 → 0.643.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 +218 -0
- package/dist/analysis/provider.d.ts +1 -1
- package/dist/analysis/provider.js +2 -1
- package/dist/attachments/gateway-ocr.js +13 -8
- 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 +28 -2
- package/dist/background/schedules.js +73 -20
- 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/mcp/index.d.ts +12 -12
- 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/ai-model-command.js +6 -3
- package/dist/cli/analysis-choice.js +20 -4
- 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/enrichment-consents-command.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.d.ts +10 -0
- package/dist/cli/local-only-command.js +112 -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/conversations-command.js +1 -1
- 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/replies-consents-command.js +12 -6
- 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 +4 -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/search-harder-consents-command.js +16 -1
- 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 +2 -1
- package/dist/documents.js +2 -1
- 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/embeddings/remote.d.ts +2 -1
- package/dist/embeddings/remote.js +5 -3
- 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 +38 -1
- 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.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 +17 -4
- package/dist/models/ai.js +22 -14
- package/dist/models/anthropic.js +15 -9
- package/dist/models/endpoint.d.ts +5 -0
- package/dist/models/endpoint.js +13 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +14 -4
- package/dist/models/local-only.d.ts +17 -0
- package/dist/models/local-only.js +42 -0
- package/dist/models/openai.js +24 -11
- package/dist/models/purpose.d.ts +24 -0
- package/dist/models/purpose.js +26 -0
- 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/replies/rendering.js +10 -10
- 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/embeddings-maintenance.js +4 -1
- package/dist/services/enrichment.d.ts +1 -1
- package/dist/services/enrichment.js +27 -0
- 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-model.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/search-harder.d.ts +11 -1
- package/dist/services/search-harder.js +38 -5
- 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/speech/openai.js +2 -0
- package/dist/speech/transcribe.d.ts +5 -2
- package/dist/speech/transcribe.js +14 -5
- 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
|
@@ -80,7 +80,7 @@ export const QUERY_FIELDS = [
|
|
|
80
80
|
name: "from",
|
|
81
81
|
example: "from:Alice*",
|
|
82
82
|
index: "identities / sender index",
|
|
83
|
-
aliases: [],
|
|
83
|
+
aliases: ["sender"],
|
|
84
84
|
type: "kw",
|
|
85
85
|
operators: names,
|
|
86
86
|
normalization: NAMES,
|
|
@@ -341,8 +341,8 @@ export const QUERY_FIELDS = [
|
|
|
341
341
|
[
|
|
342
342
|
"title",
|
|
343
343
|
'title:"quarterly report"',
|
|
344
|
-
"documents.metadata, then the title column",
|
|
345
|
-
"every word, folded as text is
|
|
344
|
+
"documents.metadata, then the title column; chats.title_folded; email_words, then the subject",
|
|
345
|
+
"every word, folded as text is: of a note's or a file's title, inside a chat's title, of a mail's subject (as subject:)",
|
|
346
346
|
"txt",
|
|
347
347
|
],
|
|
348
348
|
[
|
|
@@ -434,23 +434,81 @@ export const QUERY_FIELDS = [
|
|
|
434
434
|
];
|
|
435
435
|
const MESSAGES = { entity: "message", backend: "sql", fields: QUERY_FIELDS };
|
|
436
436
|
const NEAR_FIELDS = new Set(["text", "exact", "transcript", "content"]);
|
|
437
|
-
|
|
438
|
-
|
|
437
|
+
const CANONICAL = new Map(QUERY_FIELDS.flatMap(({ name, aliases }) => aliases.map((alias) => [alias, name])));
|
|
438
|
+
/** `field:*`, which Lucene also writes `_exists_:field`: the field has a value. */
|
|
439
|
+
export const isPresence = (node) => node.operator === "wildcard" && node.value === "*";
|
|
440
|
+
/** The fields a message or a mail may lack, so `field:*` asks something of them. */
|
|
441
|
+
export const PRESENCE = new Set(["from", "to", "cc", "bcc", "subject", "title", "topic", "participants_count"]);
|
|
442
|
+
// Every message has a chat and a date: `chat:*` keeps them all, as Lucene's `_exists_` would.
|
|
443
|
+
const ALWAYS = new Set(["chat", "date"]);
|
|
444
|
+
const EVERY_DATE = { operator: "range", value: "*", upper: "*", lower_inclusive: true, upper_inclusive: true };
|
|
445
|
+
const PRESENCE_INSTEAD = {
|
|
446
|
+
text: "has:text",
|
|
447
|
+
exact: "has:text",
|
|
448
|
+
body: "has:text",
|
|
449
|
+
content: "has:file",
|
|
450
|
+
transcript: "has:transcript",
|
|
451
|
+
size: "has:attachment",
|
|
452
|
+
url: "has:link",
|
|
453
|
+
link: "has:link",
|
|
454
|
+
domain: "has:link",
|
|
455
|
+
};
|
|
456
|
+
// Fields matched anywhere inside their value, so a pattern's stars are not needed.
|
|
457
|
+
const CONTAINED = new Set(["title", "site", "author"]);
|
|
458
|
+
const notPresent = (node) => searchError("query.unsupported-operator", node.span, `${node.field}:* asks whether ${node.field} has a value, which search answers for ` +
|
|
459
|
+
`${[...PRESENCE, ...ALWAYS].join(", ")}${PRESENCE_INSTEAD[node.field] ? `; write ${PRESENCE_INSTEAD[node.field]}` : ""}`);
|
|
460
|
+
// A tree without an alias or `_exists_` comes back as the same object.
|
|
461
|
+
const canonical = (node) => {
|
|
462
|
+
if (node.kind === "boolean") {
|
|
463
|
+
const clauses = node.clauses.map((clause) => {
|
|
464
|
+
const inner = canonical(clause.node);
|
|
465
|
+
return inner === clause.node ? clause : { ...clause, node: inner };
|
|
466
|
+
});
|
|
467
|
+
return clauses.every((clause, at) => clause === node.clauses[at]) ? node : { ...node, clauses };
|
|
468
|
+
}
|
|
469
|
+
const field = CANONICAL.get(node.field);
|
|
470
|
+
if (node.field !== "_exists_")
|
|
471
|
+
return field ? { ...node, field } : node;
|
|
472
|
+
const { implicit: _, ...rest } = node;
|
|
473
|
+
return { ...rest, field: CANONICAL.get(node.value) ?? node.value, operator: "wildcard", value: "*" };
|
|
474
|
+
};
|
|
475
|
+
const everyDate = (node) => node.kind === "boolean"
|
|
476
|
+
? { ...node, clauses: node.clauses.map((clause) => ({ ...clause, node: everyDate(clause.node) })) }
|
|
477
|
+
: isPresence(node) && ALWAYS.has(node.field)
|
|
478
|
+
? { kind: "predicate", field: "date", ...EVERY_DATE, span: node.span }
|
|
479
|
+
: node;
|
|
480
|
+
/**
|
|
481
|
+
* Field, operator and value of every term, against the message fields; an alias becomes its field's name.
|
|
482
|
+
* `presence` is message and mail search, whose compiler answers `field:*` for the fields a message may lack.
|
|
483
|
+
*/
|
|
484
|
+
export const validateFields = (written, { presence = false } = {}) => {
|
|
485
|
+
const root = canonical(written.root);
|
|
486
|
+
const ast = root === written.root ? written : { ...written, root };
|
|
439
487
|
for (const node of walkQuery(ast.root)) {
|
|
488
|
+
if (presence && isPresence(node)) {
|
|
489
|
+
if (PRESENCE.has(node.field) || ALWAYS.has(node.field))
|
|
490
|
+
continue;
|
|
491
|
+
const known = QUERY_FIELDS.find(({ name }) => name === node.field);
|
|
492
|
+
if (known && (!known.operators.includes("wildcard") || PRESENCE_INSTEAD[node.field]))
|
|
493
|
+
notPresent(node);
|
|
494
|
+
}
|
|
440
495
|
const field = QUERY_FIELDS.find(({ name }) => name === node.field);
|
|
441
496
|
if (!field && ["after", "before"].includes(node.field)) {
|
|
442
497
|
const plain = ["term", "phrase"].includes(node.operator) && /^[\w:.+-]+$/u.test(node.value);
|
|
443
|
-
searchError("
|
|
498
|
+
searchError("query.legacy-date-field", node.span, plain ? `use date${node.field === "after" ? ">=" : "<"}${node.value}` : "use date>=YYYY-MM-DD or date:[a TO b]");
|
|
444
499
|
}
|
|
445
500
|
if (node.slop !== undefined && !NEAR_FIELDS.has(node.field))
|
|
446
501
|
searchError("query.unsupported-operator", node.span, `"a b"~N takes words: ${[...NEAR_FIELDS].join(", ")}`);
|
|
447
502
|
if (node.slop !== undefined && node.slop > MOST_WORDS_APART)
|
|
448
503
|
searchError("query.invalid-number", node.span, `words at most ${MOST_WORDS_APART} apart: "a b"~${MOST_WORDS_APART}`);
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
searchError("query.unsupported-operator", node.span, `${field.name} takes ${field.operators.join(", ")}`
|
|
504
|
+
if (field && node.operator === "wildcard" && !field.operators.includes("wildcard")) {
|
|
505
|
+
const part = node.value.replace(/[*?]/gu, "");
|
|
506
|
+
searchError("query.unsupported-operator", node.span, `${field.name} takes ${field.operators.join(", ")}` +
|
|
507
|
+
(CONTAINED.has(field.name) && part ? `; ${field.name}:${part} already finds it inside a word` : ""));
|
|
508
|
+
}
|
|
452
509
|
}
|
|
453
|
-
|
|
510
|
+
const valid = validateQuery(ast, MESSAGES, SEARCH_QUERY);
|
|
511
|
+
return presence ? { ...valid, root: everyDate(valid.root) } : valid;
|
|
454
512
|
};
|
|
455
513
|
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
456
514
|
const validSpan = (value) => record(value) &&
|
|
@@ -460,7 +518,7 @@ const validSpan = (value) => record(value) &&
|
|
|
460
518
|
Number(value.end) >= Number(value.start) &&
|
|
461
519
|
Number(value.end) <= QUERY_LIMITS.bytes;
|
|
462
520
|
/** Checks a received query tree — MCP input, a stored search — against cli-base's schema, the limits, then its fields. */
|
|
463
|
-
export const validateAst = (input) => {
|
|
521
|
+
export const validateAst = (input, options = {}) => {
|
|
464
522
|
const failure = { start: 0, end: 0 };
|
|
465
523
|
if (!record(input) || input.version !== 1 || input.language !== "lucene-v1")
|
|
466
524
|
searchError("query.unsupported-version", failure);
|
|
@@ -493,7 +551,7 @@ export const validateAst = (input) => {
|
|
|
493
551
|
(node.upper === undefined || node.lower_inclusive === undefined || node.upper_inclusive === undefined));
|
|
494
552
|
if (open)
|
|
495
553
|
searchError("query.invalid-ast", open.span);
|
|
496
|
-
return validateFields(parsed.output);
|
|
554
|
+
return validateFields(parsed.output, options);
|
|
497
555
|
};
|
|
498
556
|
export const QUERY_OPERATORS = [
|
|
499
557
|
{
|
|
@@ -38,3 +38,5 @@ export declare function outOfTime(limitMs?: number): never;
|
|
|
38
38
|
/** A search limit that leaves the answer without a part, such as its total, rather than failing it. */
|
|
39
39
|
export declare const isQueryLimit: (error: unknown) => boolean;
|
|
40
40
|
export declare function exhausted(budget: string): never;
|
|
41
|
+
/** A pattern checked word by word over more messages than a search may read: what to write instead. */
|
|
42
|
+
export declare function tooWideTerm([term]: string[], budget: string): never;
|
|
@@ -46,3 +46,15 @@ export function exhausted(budget) {
|
|
|
46
46
|
complete: false,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
/** A pattern checked word by word over more messages than a search may read: what to write instead. */
|
|
50
|
+
export function tooWideTerm([term], budget) {
|
|
51
|
+
if (term === undefined)
|
|
52
|
+
exhausted(budget);
|
|
53
|
+
const part = term
|
|
54
|
+
.replace(/[*?]+/gu, " ")
|
|
55
|
+
.trim()
|
|
56
|
+
.split(/\s+/u)
|
|
57
|
+
.sort((a, b) => b.length - a.length)[0] ?? term;
|
|
58
|
+
throw new CliError("validation_error", `search exceeded its ${budget} budget: ${term} is checked word by word, and too many messages hold it — ` +
|
|
59
|
+
`write *${part}* (any word holding it, read from the index), more of the word, or add chat: or date:`, { reason: "query.too-large", budget, term, complete: false });
|
|
60
|
+
}
|
package/dist/sends/upload.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StickerFile, Upload, UploadKind, UploadSource } from "../domain/attachments.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type AppIdentity } from "../ports/app.js";
|
|
3
3
|
/** The most `uploadBytes` holds in memory; an adapter that can stream uses `uploadBlob` and has no such cap. */
|
|
4
4
|
export declare const MAX_BUFFERED_UPLOAD_BYTES: number;
|
|
5
5
|
export declare const uploadSize: (source: UploadSource) => number;
|
|
@@ -9,6 +9,13 @@ export declare const uploadBlob: (source: UploadSource, type?: string) => Promis
|
|
|
9
9
|
export declare const uploadBytes: (source: UploadSource) => Promise<Uint8Array>;
|
|
10
10
|
/** `[".jpg", ".jpeg"]` as help says it: ".jpg or .jpeg". */
|
|
11
11
|
export declare const typesText: (types: readonly string[]) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Refuses a file or folder a read-only process would write outside its scheduled run's work folder. The run names
|
|
14
|
+
* that empty folder in `<PREFIX>_WORK_FOLDER` on the agent it starts, and it is read from there, so neither a `cd` nor
|
|
15
|
+
* a variable the agent sets moves it: a download or an export it asks for can never name a start-up file, an SSH key
|
|
16
|
+
* or another tool's settings. Locked with no run's folder, it writes no file.
|
|
17
|
+
*/
|
|
18
|
+
export declare const refuseLockedOutput: (path: string, app: AppIdentity, env: NodeJS.ProcessEnv, flag: string) => void;
|
|
12
19
|
/** Protect known credential/state paths without refusing ordinary hidden developer folders. */
|
|
13
20
|
export declare const refusedPlace: (path: string, app: AppIdentity, env: NodeJS.ProcessEnv, platform?: NodeJS.Platform) => boolean;
|
|
14
21
|
export declare const readUpload: (kind: UploadKind, path: string, { app, env, anyFile, photoTypes, }: {
|
package/dist/sends/upload.js
CHANGED
|
@@ -2,6 +2,7 @@ import { openAsBlob, realpathSync } from "node:fs";
|
|
|
2
2
|
import { open, stat } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { CliError, resolvePaths } from "@wirecat/cli-base";
|
|
5
|
+
import { ancestorValue, envName, readOnlyLockOf } from "../ports/app.js";
|
|
5
6
|
import { storePath, wirecatDirectory } from "../store/path.js";
|
|
6
7
|
/** The most `uploadBytes` holds in memory; an adapter that can stream uses `uploadBlob` and has no such cap. */
|
|
7
8
|
export const MAX_BUFFERED_UPLOAD_BYTES = 256 * 1024 * 1024;
|
|
@@ -117,30 +118,50 @@ const WIRECAT_APPS = [
|
|
|
117
118
|
{ appName: "cli-messaging", prefix: "MESSAGING" },
|
|
118
119
|
{ appName: "cli-common", prefix: "CLI_COMMON" },
|
|
119
120
|
];
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
const own = [
|
|
123
|
-
...[{ appName: app.appName, prefix: app.envPrefix }, ...WIRECAT_APPS].flatMap((one) => Object.values(resolvePaths({ ...one, env, platform }))),
|
|
124
|
-
// The shared WireCat folder: the store, its backups beside it, the models.
|
|
125
|
-
wirecatDirectory(env, platform),
|
|
126
|
-
];
|
|
127
|
-
// The store file and its -wal and -shm, not its folder: MESSAGING_STORE may sit in the home folder.
|
|
128
|
-
const store = resolve(storePath(env));
|
|
121
|
+
/** Where `path` really is: its nearest existing ancestor's real path, as a write may create the rest under a symlink. */
|
|
122
|
+
const realPathOf = (path) => {
|
|
129
123
|
let ancestor = resolve(path);
|
|
130
|
-
let real = ancestor;
|
|
131
|
-
// Downloads may create missing descendants of a symlinked directory.
|
|
132
124
|
for (;;) {
|
|
133
125
|
try {
|
|
134
|
-
|
|
135
|
-
break;
|
|
126
|
+
return resolve(realpathSync(ancestor), relative(ancestor, resolve(path)));
|
|
136
127
|
}
|
|
137
128
|
catch {
|
|
138
129
|
const parent = dirname(ancestor);
|
|
139
130
|
if (parent === ancestor)
|
|
140
|
-
|
|
131
|
+
return resolve(path);
|
|
141
132
|
ancestor = parent;
|
|
142
133
|
}
|
|
143
134
|
}
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Refuses a file or folder a read-only process would write outside its scheduled run's work folder. The run names
|
|
138
|
+
* that empty folder in `<PREFIX>_WORK_FOLDER` on the agent it starts, and it is read from there, so neither a `cd` nor
|
|
139
|
+
* a variable the agent sets moves it: a download or an export it asks for can never name a start-up file, an SSH key
|
|
140
|
+
* or another tool's settings. Locked with no run's folder, it writes no file.
|
|
141
|
+
*/
|
|
142
|
+
export const refuseLockedOutput = (path, app, env, flag) => {
|
|
143
|
+
const lock = readOnlyLockOf(app, env);
|
|
144
|
+
if (lock === undefined)
|
|
145
|
+
return;
|
|
146
|
+
const named = ancestorValue(envName(app, "WORK_FOLDER"), env);
|
|
147
|
+
const work = named ? realPathOf(named) : undefined;
|
|
148
|
+
const real = realPathOf(path);
|
|
149
|
+
if (work !== undefined && (real === work || real.startsWith(`${work}${sep}`)))
|
|
150
|
+
return;
|
|
151
|
+
throw new CliError("permission_error", work === undefined
|
|
152
|
+
? `this process is read-only (${lock}) — ${flag} writes a file only inside a scheduled run's work folder`
|
|
153
|
+
: `this process is read-only (${lock}) — ${flag} writes only inside its run's work folder, ${work}`, { reason: "read-only.output-outside", param: flag });
|
|
154
|
+
};
|
|
155
|
+
/** Protect known credential/state paths without refusing ordinary hidden developer folders. */
|
|
156
|
+
export const refusedPlace = (path, app, env, platform = process.platform) => {
|
|
157
|
+
const own = [
|
|
158
|
+
...[{ appName: app.appName, prefix: app.envPrefix }, ...WIRECAT_APPS].flatMap((one) => Object.values(resolvePaths({ ...one, env, platform }))),
|
|
159
|
+
// The shared WireCat folder: the store, its backups beside it, the models.
|
|
160
|
+
wirecatDirectory(env, platform),
|
|
161
|
+
];
|
|
162
|
+
// The store file and its -wal and -shm, not its folder: MESSAGING_STORE may sit in the home folder.
|
|
163
|
+
const store = resolve(storePath(env));
|
|
164
|
+
const real = realPathOf(path);
|
|
144
165
|
// macOS and Windows find `~/.SSH` at `~/.ssh`, so the names are compared the way their file systems do.
|
|
145
166
|
const folded = platform === "darwin" || platform === "win32";
|
|
146
167
|
const fold = (text) => (folded ? text.toLowerCase() : text);
|
|
@@ -47,6 +47,17 @@ export declare const addGroupMember: (at: GroupStore, change: GroupMemberChange)
|
|
|
47
47
|
export declare const removeGroupMember: (at: GroupStore, change: GroupMemberChange) => Promise<GroupMembership>;
|
|
48
48
|
/** Out of one group and into another in one write: what a drag between groups does. */
|
|
49
49
|
export declare const moveGroupMember: (at: GroupStore, move: GroupMemberMove) => Promise<GroupMembership>;
|
|
50
|
+
/**
|
|
51
|
+
* A new name for a group, with its members. Nothing else in the store names a group: a run that still asks for the
|
|
52
|
+
* old name (`MEMO_GROUP`, a lock, `--source group:`) is refused with the groups there are, never given another group.
|
|
53
|
+
*/
|
|
54
|
+
export declare const renameAccountGroup: (at: GroupStore, rename: {
|
|
55
|
+
from: string;
|
|
56
|
+
to: string;
|
|
57
|
+
reserved?: ReadonlySet<string>;
|
|
58
|
+
}) => Promise<GroupMembership>;
|
|
59
|
+
/** The group and its memberships go; its accounts stay, in their other groups and in `all`. */
|
|
60
|
+
export declare const deleteAccountGroup: (at: GroupStore, group: string) => Promise<GroupMembership>;
|
|
50
61
|
/**
|
|
51
62
|
* The owner's choice of which side of his life an account is on, as the store now holds it. Moving an account to work
|
|
52
63
|
* lets work views and meeting preparation read it, so a command over this is the owner's alone (`grantsAuthority`).
|
|
@@ -93,6 +93,35 @@ export const moveGroupMember = async (at, move) => {
|
|
|
93
93
|
});
|
|
94
94
|
return listAccountGroups(at);
|
|
95
95
|
};
|
|
96
|
+
/** A group the owner saved, by its exact name: `all` and the other built-in names are no saved group. */
|
|
97
|
+
const savedGroup = async (at, name) => {
|
|
98
|
+
if (NOT_GROUP_NAMES.has(name.toLowerCase()))
|
|
99
|
+
fail("validation_error", `"${name}" is built in — it cannot be renamed or deleted`);
|
|
100
|
+
const saved = await at.store.accounts.accountGroups();
|
|
101
|
+
if (!Object.hasOwn(saved, name))
|
|
102
|
+
fail("not_found", `no group "${name}" — groups here: ${Object.keys(saved).join(", ") || "none"}`);
|
|
103
|
+
return name;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* A new name for a group, with its members. Nothing else in the store names a group: a run that still asks for the
|
|
107
|
+
* old name (`MEMO_GROUP`, a lock, `--source group:`) is refused with the groups there are, never given another group.
|
|
108
|
+
*/
|
|
109
|
+
export const renameAccountGroup = async (at, rename) => {
|
|
110
|
+
unlocked(at);
|
|
111
|
+
const from = await savedGroup(at, rename.from);
|
|
112
|
+
const to = usableGroup(rename.to, rename.reserved);
|
|
113
|
+
if (hasGroup((await contextOf(at)).membership.groups, to))
|
|
114
|
+
fail("validation_error", `group "${to}" already exists`);
|
|
115
|
+
if (!(await at.store.accounts.renameAccountGroup(from, to)))
|
|
116
|
+
fail("validation_error", `group "${to}" already exists`);
|
|
117
|
+
return listAccountGroups(at);
|
|
118
|
+
};
|
|
119
|
+
/** The group and its memberships go; its accounts stay, in their other groups and in `all`. */
|
|
120
|
+
export const deleteAccountGroup = async (at, group) => {
|
|
121
|
+
unlocked(at);
|
|
122
|
+
await at.store.accounts.saveAccountGroup(await savedGroup(at, group), undefined);
|
|
123
|
+
return listAccountGroups(at);
|
|
124
|
+
};
|
|
96
125
|
/**
|
|
97
126
|
* The owner's choice of which side of his life an account is on, as the store now holds it. Moving an account to work
|
|
98
127
|
* lets work views and meeting preparation read it, so a command over this is the owner's alone (`grantsAuthority`).
|
package/dist/services/agenda.js
CHANGED
|
@@ -55,6 +55,7 @@ export const agendaService = (deps, now = Date.now) => ({
|
|
|
55
55
|
params: where?.params ?? [],
|
|
56
56
|
},
|
|
57
57
|
})
|
|
58
|
+
.then((found) => found.items)
|
|
58
59
|
.catch((error) => {
|
|
59
60
|
// An account that never had a task has no inbox project yet.
|
|
60
61
|
if (error instanceof Error && "code" in error && error.code === "not_found")
|
|
@@ -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);
|
|
@@ -33,7 +33,10 @@ export const embeddingTarget = (deps, choice = chosenTextModel(deps.env).id) =>
|
|
|
33
33
|
price: remote.price,
|
|
34
34
|
installed: true,
|
|
35
35
|
perBatch: PER_REQUEST * concurrency,
|
|
36
|
-
open: async () => (await import("../embeddings/remote.js")).openRemote(remote, apiKey, {
|
|
36
|
+
open: async () => (await import("../embeddings/remote.js")).openRemote(remote, apiKey, {
|
|
37
|
+
concurrency,
|
|
38
|
+
env: deps.env ?? process.env,
|
|
39
|
+
}),
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
const model = textModel(choice, deps.env);
|
|
@@ -22,7 +22,7 @@ export interface EnrichOptions {
|
|
|
22
22
|
signal?: AbortSignal;
|
|
23
23
|
}
|
|
24
24
|
/** Why a run stopped or failed, from a fixed list, so a window can say it in its own words. */
|
|
25
|
-
export declare const ENRICHMENT_REASON_IDS: readonly ["enrichment.no-key", "enrichment.key-rejected", "enrichment.unreachable", "enrichment.rate-limited", "enrichment.bad-replies", "enrichment.cancelled", "enrichment.error"];
|
|
25
|
+
export declare const ENRICHMENT_REASON_IDS: readonly ["enrichment.no-key", "enrichment.key-rejected", "enrichment.unreachable", "enrichment.rate-limited", "enrichment.bad-replies", "enrichment.cancelled", "enrichment.local-only", "enrichment.address-refused", "enrichment.error"];
|
|
26
26
|
export type EnrichmentReasonId = (typeof ENRICHMENT_REASON_IDS)[number];
|
|
27
27
|
export type EnrichRun = {
|
|
28
28
|
status: "off";
|