@wirecat/cli-core 0.605.0 → 0.607.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 +284 -1
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/reads.js +5 -0
- package/dist/cli/app-mcp-command.d.ts +6 -2
- package/dist/cli/app-mcp-command.js +11 -2
- package/dist/cli/csv.d.ts +10 -0
- package/dist/cli/csv.js +22 -0
- package/dist/cli/early-refusal.d.ts +10 -0
- package/dist/cli/early-refusal.js +19 -0
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/profile-token.d.ts +29 -0
- package/dist/cli/profile-token.js +65 -0
- package/dist/cli/program.js +4 -2
- package/dist/cli/store-settings.js +38 -4
- package/dist/crm/cli/csv.d.ts +23 -0
- package/dist/crm/cli/csv.js +135 -0
- package/dist/crm/cli/index.d.ts +1 -1
- package/dist/crm/cli/index.js +36 -22
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- package/dist/crm/index.d.ts +2 -2
- package/dist/crm/index.js +1 -1
- package/dist/crm/source.d.ts +35 -5
- package/dist/crm/sync.d.ts +15 -7
- package/dist/crm/sync.js +169 -11
- package/dist/crm/writes.d.ts +6 -4
- package/dist/crm/writes.js +17 -13
- package/dist/documents.d.ts +2 -0
- package/dist/documents.js +2 -0
- package/dist/domain/business.d.ts +79 -0
- package/dist/domain/business.js +42 -0
- package/dist/domain/crm.d.ts +41 -2
- package/dist/domain/deals.d.ts +5 -2
- package/dist/domain/deals.js +5 -2
- package/dist/domain/finance.d.ts +2 -0
- package/dist/domain/finance.js +2 -2
- package/dist/domain/google-documents.d.ts +2 -0
- package/dist/domain/google-documents.js +3 -1
- package/dist/domain/money.d.ts +2 -0
- package/dist/domain/money.js +11 -3
- package/dist/domain/providers.d.ts +36 -1
- package/dist/domain/providers.js +69 -7
- package/dist/domain/record-fields.d.ts +42 -0
- package/dist/domain/record-fields.js +122 -0
- package/dist/domain/record-types.d.ts +489 -16
- package/dist/domain/record-types.js +374 -7
- package/dist/domain/records.d.ts +96 -5
- package/dist/domain/records.js +178 -32
- package/dist/domain/ref-summaries.js +5 -0
- package/dist/domain/references.d.ts +1 -1
- package/dist/domain/references.js +5 -0
- package/dist/domain/relations.d.ts +125 -0
- package/dist/domain/relations.js +107 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +16 -2
- package/dist/entities/deal.js +5 -1
- package/dist/entities/index.d.ts +29 -13
- package/dist/entities/relationship.d.ts +8 -2
- package/dist/entities/relationship.js +8 -2
- package/dist/entities/task-results.d.ts +10 -10
- package/dist/errors/reasons.js +73 -2
- package/dist/fetch/addresses.d.ts +5 -0
- package/dist/fetch/addresses.js +76 -0
- package/dist/fetch/page.d.ts +64 -0
- package/dist/fetch/page.js +256 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/mail/cli/review.js +20 -6
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/marks.d.ts +10 -5
- package/dist/mail/marks.js +16 -8
- package/dist/mail/review.d.ts +5 -0
- package/dist/meetings/calendar-text.d.ts +1 -1
- package/dist/meetings/calendar-text.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -2
- package/dist/search/account-list.d.ts +4 -0
- package/dist/search/account-list.js +19 -8
- package/dist/search/query.js +2 -2
- package/dist/services/events-search.js +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/ingest.d.ts +56 -8
- package/dist/services/ingest.js +95 -61
- package/dist/services/link-scorers/scan.js +2 -1
- package/dist/services/link-scorers/shared.js +2 -1
- package/dist/services/messages-search.js +3 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.js +1 -0
- package/dist/services/project-status/index.js +2 -1
- package/dist/services/proposals/kinds/contracts.d.ts +4 -0
- package/dist/services/proposals/kinds/contracts.js +9 -0
- package/dist/services/proposals/kinds/finance.d.ts +4 -0
- package/dist/services/proposals/kinds/finance.js +14 -35
- package/dist/services/proposals/kinds/orders.js +7 -30
- package/dist/services/proposals/kinds/shared.d.ts +27 -1
- package/dist/services/proposals/kinds/shared.js +34 -0
- package/dist/services/proposals/kinds/source-review.d.ts +4 -0
- package/dist/services/proposals/kinds/source-review.js +45 -0
- package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
- package/dist/services/proposals/kinds/subscriptions.js +24 -0
- package/dist/services/proposals/kinds/transactions.d.ts +4 -0
- package/dist/services/proposals/kinds/transactions.js +10 -0
- package/dist/services/proposals/registry.js +9 -0
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all.js +4 -3
- package/dist/services/search-kind.js +3 -3
- package/dist/services/stored-project-gathering.js +4 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +20 -4
- package/dist/store/index.js +4 -0
- package/dist/store/people.js +1 -1
- package/dist/store/project-transfer/request.d.ts +4 -1
- package/dist/store/project-transfer/schema.d.ts +9 -2
- package/dist/store/project-transfer/schema.js +4 -0
- package/dist/store/project-transfer/snapshot-model.d.ts +8 -2
- package/dist/store/source-review.d.ts +64 -0
- package/dist/store/source-review.js +7 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/accounts.js +24 -1
- package/dist/store/sqlite/added-sources.d.ts +82 -0
- package/dist/store/sqlite/added-sources.js +237 -0
- package/dist/store/sqlite/business-contracts.d.ts +90 -0
- package/dist/store/sqlite/business-contracts.js +182 -0
- package/dist/store/sqlite/calendar-events.js +7 -3
- package/dist/store/sqlite/calendar-forget.js +3 -0
- package/dist/store/sqlite/calendar.d.ts +21 -1
- package/dist/store/sqlite/calendar.js +27 -7
- package/dist/store/sqlite/chat-rekey.js +7 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +15 -1
- package/dist/store/sqlite/crm-rows.d.ts +44 -0
- package/dist/store/sqlite/crm-rows.js +195 -0
- package/dist/store/sqlite/crm-settings.d.ts +28 -0
- package/dist/store/sqlite/crm-settings.js +80 -0
- package/dist/store/sqlite/crm.d.ts +42 -11
- package/dist/store/sqlite/crm.js +402 -196
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +8 -5
- package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
- package/dist/store/sqlite/emails.js +2 -0
- package/dist/store/sqlite/entity-types.d.ts +14 -9
- package/dist/store/sqlite/entity-types.js +4 -10
- package/dist/store/sqlite/evidence-signature.d.ts +114 -0
- package/dist/store/sqlite/evidence-signature.js +349 -0
- package/dist/store/sqlite/evidence-sources.d.ts +2 -1
- package/dist/store/sqlite/evidence-sources.js +7 -3
- package/dist/store/sqlite/facts.d.ts +7 -2
- package/dist/store/sqlite/facts.js +21 -5
- package/dist/store/sqlite/finance.d.ts +18 -105
- package/dist/store/sqlite/finance.js +100 -219
- package/dist/store/sqlite/involvement-queue.js +4 -3
- package/dist/store/sqlite/knowledge.d.ts +14 -4
- package/dist/store/sqlite/knowledge.js +108 -102
- package/dist/store/sqlite/labelled.d.ts +3 -0
- package/dist/store/sqlite/labelled.js +11 -0
- package/dist/store/sqlite/link-kinds.d.ts +4 -3
- package/dist/store/sqlite/link-kinds.js +6 -2
- package/dist/store/sqlite/manifest.js +7 -0
- package/dist/store/sqlite/memories.d.ts +24 -10
- package/dist/store/sqlite/memories.js +73 -19
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +134 -0
- package/dist/store/sqlite/money-lines.d.ts +48 -0
- package/dist/store/sqlite/money-lines.js +76 -0
- package/dist/store/sqlite/money-transactions.d.ts +132 -0
- package/dist/store/sqlite/money-transactions.js +295 -0
- package/dist/store/sqlite/notes.d.ts +14 -4
- package/dist/store/sqlite/notes.js +43 -31
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/organizations.d.ts +8 -0
- package/dist/store/sqlite/organizations.js +14 -0
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/person-preparation.d.ts +1 -1
- package/dist/store/sqlite/person-preparation.js +3 -2
- package/dist/store/sqlite/private-people.js +2 -0
- package/dist/store/sqlite/products.d.ts +78 -0
- package/dist/store/sqlite/products.js +131 -0
- package/dist/store/sqlite/project-transfer/records.js +39 -3
- package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +11 -3
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.js +24 -7
- package/dist/store/sqlite/providers.d.ts +0 -4
- package/dist/store/sqlite/providers.js +20 -2
- package/dist/store/sqlite/record-matching.d.ts +80 -0
- package/dist/store/sqlite/record-matching.js +264 -0
- package/dist/store/sqlite/record-projection.d.ts +89 -0
- package/dist/store/sqlite/record-projection.js +50 -0
- package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
- package/dist/store/sqlite/record-projectors-direct.js +125 -0
- package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
- package/dist/store/sqlite/record-projectors-money.js +214 -0
- package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
- package/dist/store/sqlite/record-projectors-phone.js +212 -0
- package/dist/store/sqlite/record-projectors.d.ts +3 -44
- package/dist/store/sqlite/record-projectors.js +7 -67
- package/dist/store/sqlite/record-relations.d.ts +24 -0
- package/dist/store/sqlite/record-relations.js +92 -0
- package/dist/store/sqlite/record-remap.d.ts +12 -0
- package/dist/store/sqlite/record-remap.js +92 -0
- package/dist/store/sqlite/record-run.d.ts +71 -0
- package/dist/store/sqlite/record-run.js +179 -0
- package/dist/store/sqlite/record-settling.d.ts +9 -0
- package/dist/store/sqlite/record-settling.js +74 -0
- package/dist/store/sqlite/record-stamps.d.ts +13 -0
- package/dist/store/sqlite/record-stamps.js +30 -0
- package/dist/store/sqlite/record-writes.d.ts +43 -0
- package/dist/store/sqlite/record-writes.js +307 -0
- package/dist/store/sqlite/records.d.ts +52 -42
- package/dist/store/sqlite/records.js +123 -353
- package/dist/store/sqlite/ref-summaries.d.ts +6 -5
- package/dist/store/sqlite/ref-summaries.js +60 -8
- package/dist/store/sqlite/refunds.d.ts +31 -0
- package/dist/store/sqlite/refunds.js +112 -0
- package/dist/store/sqlite/relation-list.d.ts +43 -0
- package/dist/store/sqlite/relation-list.js +133 -0
- package/dist/store/sqlite/relation-proposals.d.ts +28 -6
- package/dist/store/sqlite/relation-proposals.js +134 -10
- package/dist/store/sqlite/relation-reads.d.ts +8 -0
- package/dist/store/sqlite/relation-reads.js +7 -0
- package/dist/store/sqlite/relation-roles.d.ts +26 -0
- package/dist/store/sqlite/relation-roles.js +91 -0
- package/dist/store/sqlite/reported-relations.d.ts +63 -0
- package/dist/store/sqlite/reported-relations.js +132 -0
- package/dist/store/sqlite/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -0
- package/dist/store/sqlite/schema/link-revisions.d.ts +136 -0
- package/dist/store/sqlite/schema/link-revisions.js +11 -0
- package/dist/store/sqlite/schema/links.d.ts +360 -0
- package/dist/store/sqlite/schema/links.js +32 -0
- package/dist/store/sqlite/schema.d.ts +2769 -306
- package/dist/store/sqlite/schema.js +258 -25
- package/dist/store/sqlite/source-review-marks.d.ts +54 -0
- package/dist/store/sqlite/source-review-marks.js +143 -0
- package/dist/store/sqlite/source-review.d.ts +54 -0
- package/dist/store/sqlite/source-review.js +221 -0
- package/dist/store/sqlite/stage-amounts.d.ts +14 -0
- package/dist/store/sqlite/stage-amounts.js +23 -0
- package/dist/store/sqlite/subscriptions.d.ts +135 -0
- package/dist/store/sqlite/subscriptions.js +294 -0
- package/dist/store/sqlite/text-input.d.ts +3 -0
- package/dist/store/sqlite/text-input.js +13 -0
- package/dist/store/sqlite/things.js +2 -9
- package/dist/store/sqlite/transaction.d.ts +15 -0
- package/dist/store/sqlite/transaction.js +57 -0
- package/dist/store/sqlite/wallets.d.ts +88 -0
- package/dist/store/sqlite/wallets.js +143 -0
- package/dist/store/store-errors.d.ts +1 -0
- package/dist/store/store-errors.js +45 -0
- package/dist/store/store.d.ts +19 -1
- package/dist/store/store.js +35 -6
- package/package.json +6 -3
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
package/dist/search/query.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import {
|
|
2
|
+
import { holdsKindOf, isKind, providerNamed } from "../domain/providers.js";
|
|
3
3
|
/** How the store tells a bot's copy from a personal account: `max-bot`, `telegram-bot`. */
|
|
4
4
|
export const isBotProvider = (provider) => provider.endsWith("-bot");
|
|
5
5
|
/** Whether an account of `provider` is inside `source`: also a kind (`messages`, `mail`) or a provider's alias (`tg`). */
|
|
@@ -8,7 +8,7 @@ export const inSource = (source, provider) => source === "all" ||
|
|
|
8
8
|
(source === "personal" && !isBotProvider(provider)) ||
|
|
9
9
|
source === provider ||
|
|
10
10
|
providerNamed(source)?.name === provider ||
|
|
11
|
-
(isKind(source) &&
|
|
11
|
+
(isKind(source) && holdsKindOf(provider, source));
|
|
12
12
|
const fail = (message) => {
|
|
13
13
|
throw new CliError("validation_error", message);
|
|
14
14
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import {
|
|
2
|
+
import { holdsKind } from "../domain/providers.js";
|
|
3
3
|
import { meaningFloor } from "../embeddings/models.js";
|
|
4
4
|
import { plainQuery } from "../search/lucene/plain.js";
|
|
5
5
|
import { questionLookup, questionText } from "../search/question-plan.js";
|
|
@@ -17,7 +17,7 @@ const accountIdsOf = async (store, accounts) => {
|
|
|
17
17
|
};
|
|
18
18
|
/** The calendar accounts the store holds: every account whose provider is of the `events` kind. */
|
|
19
19
|
export const calendarAccounts = async (store) => (await store.accounts.storedAccounts())
|
|
20
|
-
.filter(({ provider }) =>
|
|
20
|
+
.filter(({ provider }) => holdsKind(provider, "events"))
|
|
21
21
|
.map(({ provider, account }) => ({ provider, account }));
|
|
22
22
|
export const foundEvent = (hit, query, foundBy) => ({
|
|
23
23
|
ref: hit.ref,
|
package/dist/services/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { type ChatCoverage, chatCoverage } from "./chat-coverage.js";
|
|
|
6
6
|
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextEvidenceSender, ContextIndex, ContextReadLimits, ContextReadUsage, ContextRecordReader, ContextSource, ScopedContextEvidenceReader, } from "./context-evidence.js";
|
|
7
7
|
export { contextEvidenceFingerprint, createContextEvidenceReader } from "./context-evidence.js";
|
|
8
8
|
export { excerpt } from "./excerpt.js";
|
|
9
|
-
export { type IngestOptions, type IngestReceipt, ingest } from "./ingest.js";
|
|
9
|
+
export { type IngestLinesOptions, type IngestOptions, type IngestReceipt, type IngestVcardOptions, ingest, ingestLines, ingestVcard, jsonlLines, } from "./ingest.js";
|
|
10
10
|
export { aliasHits, chatSenders, chatTitle, combinedScore, DEFAULT_LIMIT as DEFAULT_LINK_SCAN_LIMIT, DEFAULT_THRESHOLD as DEFAULT_LINK_SCAN_THRESHOLD, emailDomain, type LinkCandidate, type LinkScorer, mailThread, memberChats, memberDialog, PERSON_SCORERS, PERSON_THRESHOLD as PERSON_LINK_SCAN_THRESHOLD, SCAN_BOT, SCORERS, type ScanInput as LinkScanInput, type ScannedProject, type ScannedProposal, type ScanResult as LinkScanResult, type ScorerInput, type Signal as LinkSignal, scanProjectLinks, } from "./link-scorers/index.js";
|
|
11
11
|
export type { MediaArchiveOptions, MediaArchivePorts } from "./media-archive.js";
|
|
12
12
|
export { archiveMedia, checkMediaArchive } from "./media-archive.js";
|
package/dist/services/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { AGENDA_DEFAULTS } from "./agenda.js";
|
|
|
5
5
|
export { chatCoverage } from "./chat-coverage.js";
|
|
6
6
|
export { contextEvidenceFingerprint, createContextEvidenceReader } from "./context-evidence.js";
|
|
7
7
|
export { excerpt } from "./excerpt.js";
|
|
8
|
-
export { ingest } from "./ingest.js";
|
|
8
|
+
export { ingest, ingestLines, ingestVcard, jsonlLines, } from "./ingest.js";
|
|
9
9
|
export { aliasHits, chatSenders, chatTitle, combinedScore, DEFAULT_LIMIT as DEFAULT_LINK_SCAN_LIMIT, DEFAULT_THRESHOLD as DEFAULT_LINK_SCAN_THRESHOLD, emailDomain, mailThread, memberChats, memberDialog, PERSON_SCORERS, PERSON_THRESHOLD as PERSON_LINK_SCAN_THRESHOLD, SCAN_BOT, SCORERS, scanProjectLinks, } from "./link-scorers/index.js";
|
|
10
10
|
export { archiveMedia, checkMediaArchive } from "./media-archive.js";
|
|
11
11
|
export { moveMediaArchive } from "./media-archive-move.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type IngestError } from "../domain/records.js";
|
|
2
|
+
import { type VcardIssue, type VcardOptions } from "../domain/vcard.js";
|
|
2
3
|
import type { MessageStore } from "../store/store.js";
|
|
3
4
|
export interface IngestOptions {
|
|
4
5
|
/** The account the caller means; the envelope's `source.account` must be this one. */
|
|
@@ -7,7 +8,10 @@ export interface IngestOptions {
|
|
|
7
8
|
dryRun?: boolean;
|
|
8
9
|
/** Records per transaction, 1000 by default. */
|
|
9
10
|
chunk?: number;
|
|
11
|
+
/** Every refusal as it happens, also the ones past the receipt's 1000. It must not use the store (see `RunOptions`). */
|
|
12
|
+
onIssue?: (issue: IngestError) => void;
|
|
10
13
|
}
|
|
14
|
+
export type IngestLinesOptions = IngestOptions;
|
|
11
15
|
export interface IngestReceipt {
|
|
12
16
|
dryRun: boolean;
|
|
13
17
|
source: {
|
|
@@ -20,26 +24,70 @@ export interface IngestReceipt {
|
|
|
20
24
|
unchanged: number;
|
|
21
25
|
deleted: number;
|
|
22
26
|
refused: number;
|
|
23
|
-
/**
|
|
27
|
+
/** The proposals this import made or changed, of every type that feeds money; the owner decides them in review. */
|
|
24
28
|
proposed: string[];
|
|
25
|
-
/** Kept, with no entity yet: each named role points at a record not imported, or one with no entity. */
|
|
29
|
+
/** Kept, with no entity yet: each named role or field points at a record not imported, or one with no entity. */
|
|
26
30
|
waiting: {
|
|
27
31
|
key: string;
|
|
28
32
|
pointer: string;
|
|
29
33
|
missing: string[];
|
|
30
34
|
}[];
|
|
31
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Changed or deleted at the source after the entity was made from it: the entity was not touched. `reason` and
|
|
37
|
+
* `candidates` say when the change named another entity's identifiers.
|
|
38
|
+
*/
|
|
32
39
|
flagged: {
|
|
33
40
|
key: string;
|
|
34
41
|
pointer: string;
|
|
35
42
|
entity: string;
|
|
43
|
+
reason?: string;
|
|
44
|
+
candidates?: string[];
|
|
45
|
+
}[];
|
|
46
|
+
/**
|
|
47
|
+
* A person, organization or project whose identifiers point at more than one entity (`record.ambiguous`), or at one
|
|
48
|
+
* the owner separated from them (`record.separated`): it waits, and the owner says which one it is.
|
|
49
|
+
*/
|
|
50
|
+
unmatched: {
|
|
51
|
+
key: string;
|
|
52
|
+
pointer: string;
|
|
53
|
+
reason: string;
|
|
54
|
+
candidates: string[];
|
|
55
|
+
}[];
|
|
56
|
+
/**
|
|
57
|
+
* Values that look like an identifier and were kept as data only, never matched: a phone without `+` when the
|
|
58
|
+
* envelope names no `options.phone_region` (`record.phone-region`).
|
|
59
|
+
*/
|
|
60
|
+
ignored: {
|
|
61
|
+
key: string;
|
|
62
|
+
pointer: string;
|
|
63
|
+
reason: string;
|
|
36
64
|
}[];
|
|
37
65
|
errors: IngestError[];
|
|
66
|
+
/** A list stopped at 1000 entries; the counts are exact. */
|
|
67
|
+
truncated: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Takes a v1 records envelope into the store: checks it, then writes per chunk in one transaction. The same import
|
|
71
|
+
* twice writes nothing new. A record with a lower revision than the stored one is refused, a delete is soft, a
|
|
72
|
+
* reference to a record not yet imported waits for it, and nothing is linked by name: a person, organization or
|
|
73
|
+
* project is linked by an exact strong identifier, or made. What feeds money totals becomes a proposal: an import
|
|
74
|
+
* never writes confirmed money.
|
|
75
|
+
*/
|
|
76
|
+
export declare const ingest: (store: Pick<MessageStore, "records">, envelope: unknown, { account, dryRun, chunk, onIssue }: IngestOptions) => Promise<IngestReceipt>;
|
|
77
|
+
/** The lines of a file or of stdin, one at a time, never the whole text. */
|
|
78
|
+
export declare const jsonlLines: (stream: NodeJS.ReadableStream) => AsyncIterable<string>;
|
|
79
|
+
/**
|
|
80
|
+
* `ingest` over a JSONL stream: the first non-empty line is the header (`schema_version`, `source`, `options`), each
|
|
81
|
+
* further non-empty line one record. Records are written per chunk as they arrive; a dry run is one transaction
|
|
82
|
+
* rolled back at the end, holding the store's write lock until then.
|
|
83
|
+
*/
|
|
84
|
+
export declare const ingestLines: (store: Pick<MessageStore, "records">, lines: AsyncIterable<string>, { account, dryRun, chunk, onIssue }: IngestOptions) => Promise<IngestReceipt>;
|
|
85
|
+
export interface IngestVcardOptions extends IngestOptions, Omit<VcardOptions, "account"> {
|
|
38
86
|
}
|
|
39
87
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* one is refused, a delete is soft, a reference to a record not yet imported waits for it, and nothing is linked by
|
|
43
|
-
* name. An invoice or a payment becomes a proposal: an import never writes confirmed money.
|
|
88
|
+
* A `.vcf` address book (`isVcard`) through `envelopeOfVcard`, then `ingest`: the receipt, and what the converter kept
|
|
89
|
+
* without matching (a national number with no `region`, a card repeated in the file).
|
|
44
90
|
*/
|
|
45
|
-
export declare const
|
|
91
|
+
export declare const ingestVcard: (store: Pick<MessageStore, "records">, text: string, { provider, batchId, region, ...options }: IngestVcardOptions) => Promise<IngestReceipt & {
|
|
92
|
+
vcard: VcardIssue[];
|
|
93
|
+
}>;
|
package/dist/services/ingest.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { envelopeErrors, headerErrors, jsonLine, pointerOf, recordErrors, } from "../domain/records.js";
|
|
3
|
+
import { envelopeOfVcard } from "../domain/vcard.js";
|
|
4
|
+
import { waitingPointer } from "../store/index.js";
|
|
5
|
+
const emptyReceipt = (dryRun, errors) => ({
|
|
3
6
|
dryRun,
|
|
4
7
|
source: null,
|
|
5
8
|
created: 0,
|
|
@@ -10,71 +13,102 @@ const emptyReceipt = (dryRun) => ({
|
|
|
10
13
|
proposed: [],
|
|
11
14
|
waiting: [],
|
|
12
15
|
flagged: [],
|
|
13
|
-
|
|
16
|
+
unmatched: [],
|
|
17
|
+
ignored: [],
|
|
18
|
+
errors,
|
|
19
|
+
truncated: false,
|
|
14
20
|
});
|
|
21
|
+
const receiptOf = (dryRun, source, run) => ({
|
|
22
|
+
dryRun,
|
|
23
|
+
source: { provider: source.provider, account: source.account, batchId: source.batch_id },
|
|
24
|
+
created: run.created,
|
|
25
|
+
updated: run.updated,
|
|
26
|
+
unchanged: run.unchanged,
|
|
27
|
+
deleted: run.deleted,
|
|
28
|
+
refused: run.refused,
|
|
29
|
+
proposed: run.proposed,
|
|
30
|
+
waiting: run.waiting.map(({ index, key, missing }) => ({ key, pointer: waitingPointer(index, missing), missing })),
|
|
31
|
+
flagged: run.flagged.map(({ index, ...flag }) => ({ ...flag, pointer: pointerOf("records", index) })),
|
|
32
|
+
unmatched: run.unmatched.map(({ index, key, reason, candidates }) => ({
|
|
33
|
+
key,
|
|
34
|
+
pointer: pointerOf("records", index, "fields"),
|
|
35
|
+
reason,
|
|
36
|
+
candidates,
|
|
37
|
+
})),
|
|
38
|
+
ignored: run.ignored.map(({ index, key, at, reason }) => ({
|
|
39
|
+
key,
|
|
40
|
+
pointer: pointerOf("records", index, ...at),
|
|
41
|
+
reason,
|
|
42
|
+
})),
|
|
43
|
+
errors: run.errors,
|
|
44
|
+
truncated: run.truncated,
|
|
45
|
+
});
|
|
46
|
+
const itemOf = (record, index) => {
|
|
47
|
+
const errors = recordErrors(record, index);
|
|
48
|
+
return { index, record: record, ...(errors.length > 0 ? { errors } : {}) };
|
|
49
|
+
};
|
|
50
|
+
const refusedAll = (dryRun, errors, onIssue) => {
|
|
51
|
+
for (const error of errors)
|
|
52
|
+
onIssue?.(error);
|
|
53
|
+
return emptyReceipt(dryRun, errors);
|
|
54
|
+
};
|
|
15
55
|
/**
|
|
16
|
-
* Takes a v1 records envelope
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
56
|
+
* Takes a v1 records envelope into the store: checks it, then writes per chunk in one transaction. The same import
|
|
57
|
+
* twice writes nothing new. A record with a lower revision than the stored one is refused, a delete is soft, a
|
|
58
|
+
* reference to a record not yet imported waits for it, and nothing is linked by name: a person, organization or
|
|
59
|
+
* project is linked by an exact strong identifier, or made. What feeds money totals becomes a proposal: an import
|
|
60
|
+
* never writes confirmed money.
|
|
20
61
|
*/
|
|
21
|
-
export const ingest = async (store, envelope, { account, dryRun = false, chunk = 1000 }) => {
|
|
22
|
-
const receipt = emptyReceipt(dryRun);
|
|
62
|
+
export const ingest = async (store, envelope, { account, dryRun = false, chunk = 1000, onIssue }) => {
|
|
23
63
|
const broken = envelopeErrors(envelope, account);
|
|
24
64
|
if (broken.length > 0)
|
|
25
|
-
return
|
|
26
|
-
const { source, records } = envelope;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
pointer: pointerOf("records", index, "external_id"),
|
|
45
|
-
code: "record.duplicate",
|
|
46
|
-
message: `another record of this envelope is ${valid.type} ${valid.external_id}`,
|
|
47
|
-
key: valid.key,
|
|
48
|
-
});
|
|
49
|
-
if (errors.length > 0) {
|
|
50
|
-
receipt.refused += 1;
|
|
51
|
-
for (const error of errors)
|
|
52
|
-
receipt.errors.push(error);
|
|
53
|
-
continue;
|
|
65
|
+
return refusedAll(dryRun, broken, onIssue);
|
|
66
|
+
const { source, records, options } = envelope;
|
|
67
|
+
const items = records.map(itemOf);
|
|
68
|
+
return receiptOf(dryRun, source, await store.records.run(source, items, { dryRun, chunk, options, onIssue }));
|
|
69
|
+
};
|
|
70
|
+
/** The lines of a file or of stdin, one at a time, never the whole text. */
|
|
71
|
+
export const jsonlLines = (stream) => createInterface({ input: stream, crlfDelay: Number.POSITIVE_INFINITY });
|
|
72
|
+
/**
|
|
73
|
+
* `ingest` over a JSONL stream: the first non-empty line is the header (`schema_version`, `source`, `options`), each
|
|
74
|
+
* further non-empty line one record. Records are written per chunk as they arrive; a dry run is one transaction
|
|
75
|
+
* rolled back at the end, holding the store's write lock until then.
|
|
76
|
+
*/
|
|
77
|
+
export const ingestLines = async (store, lines, { account, dryRun = false, chunk = 1000, onIssue }) => {
|
|
78
|
+
const iterator = lines[Symbol.asyncIterator]();
|
|
79
|
+
let header = {};
|
|
80
|
+
for (let next = await iterator.next(); !next.done; next = await iterator.next())
|
|
81
|
+
if (next.value.trim() !== "" && next.value !== "") {
|
|
82
|
+
header = jsonLine(next.value);
|
|
83
|
+
break;
|
|
54
84
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
85
|
+
const broken = headerErrors(header, account);
|
|
86
|
+
if (broken.length > 0) {
|
|
87
|
+
await iterator.return?.();
|
|
88
|
+
return refusedAll(dryRun, broken, onIssue);
|
|
58
89
|
}
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
const { source, options } = header;
|
|
91
|
+
async function* items() {
|
|
92
|
+
let index = 0;
|
|
93
|
+
for (let next = await iterator.next(); !next.done; next = await iterator.next()) {
|
|
94
|
+
if (next.value.trim() === "")
|
|
95
|
+
continue;
|
|
96
|
+
yield itemOf(jsonLine(next.value), index);
|
|
97
|
+
index += 1;
|
|
98
|
+
}
|
|
64
99
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return receipt;
|
|
100
|
+
return receiptOf(dryRun, source, await store.records.run(source, items(), { dryRun, chunk, options, onIssue }));
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* A `.vcf` address book (`isVcard`) through `envelopeOfVcard`, then `ingest`: the receipt, and what the converter kept
|
|
104
|
+
* without matching (a national number with no `region`, a card repeated in the file).
|
|
105
|
+
*/
|
|
106
|
+
export const ingestVcard = async (store, text, { provider, batchId, region, ...options }) => {
|
|
107
|
+
const { envelope, issues } = envelopeOfVcard(text, {
|
|
108
|
+
provider,
|
|
109
|
+
account: options.account,
|
|
110
|
+
batchId,
|
|
111
|
+
...(region === undefined ? {} : { region }),
|
|
112
|
+
});
|
|
113
|
+
return { ...(await ingest(store, envelope, options)), vcard: issues };
|
|
80
114
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseReference } from "../../domain/references.js";
|
|
3
|
+
import { isUsable } from "../../domain/relations.js";
|
|
3
4
|
import { BUILT_IN_PURPOSES } from "../project-purposes.js";
|
|
4
5
|
import { canonicalProjectRef } from "../stored-project-gathering.js";
|
|
5
6
|
import { aliasHits } from "./alias-hits.js";
|
|
@@ -32,7 +33,7 @@ const projectOf = async (store, reference) => {
|
|
|
32
33
|
const confirmedOf = async (store, project) => {
|
|
33
34
|
if (!project)
|
|
34
35
|
return { chats: [], people: [] };
|
|
35
|
-
const members = (await store.knowledge.relations(null, project.ref)).filter((one) => one.
|
|
36
|
+
const members = (await store.knowledge.relations(null, project.ref)).filter((one) => isUsable(one.standing) && one.kind === "member-of" && one.to === project.ref);
|
|
36
37
|
return {
|
|
37
38
|
chats: [...new Set(members.map((one) => one.from).filter((ref) => ref.startsWith("chat:")))].sort(),
|
|
38
39
|
people: [...new Set(members.map((one) => one.from).filter((ref) => ref.startsWith("person:")))].sort(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatReference } from "../../domain/references.js";
|
|
2
|
+
import { isUsable } from "../../domain/relations.js";
|
|
2
3
|
import { normalizeVocabularyName } from "../../domain/vocabulary.js";
|
|
3
4
|
const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4
5
|
const folded = (text) => text.normalize("NFKC").toLowerCase().replace(/\s+/gu, " ");
|
|
@@ -34,7 +35,7 @@ export const personRefOf = async (store, provider, id) => {
|
|
|
34
35
|
export const projectsOf = async (store, person, project) => new Set([
|
|
35
36
|
project,
|
|
36
37
|
...(await store.knowledge.relations(null, person))
|
|
37
|
-
.filter((one) => one.
|
|
38
|
+
.filter((one) => isUsable(one.standing) && one.kind === "member-of" && one.from === person && one.to.startsWith("project:"))
|
|
38
39
|
.map((one) => one.to),
|
|
39
40
|
]).size;
|
|
40
41
|
/** Each confirmed member's identities in one messenger, by member. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { calendarKey } from "../domain/calendar.js";
|
|
3
3
|
import { parseLocator } from "../domain/locator.js";
|
|
4
|
-
import { kindIn, UNKNOWN_PROVIDER } from "../domain/providers.js";
|
|
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
7
|
import { FIELD_VERSION, validateAst, validateFields } from "../search/lucene/registry.js";
|
|
@@ -235,7 +235,8 @@ export const coverageOf = async (store, { scopeAccounts, selectedChat }, messeng
|
|
|
235
235
|
const completeness = [];
|
|
236
236
|
const stats = new Map();
|
|
237
237
|
let inventoryComplete = scopeAccounts.length > 0;
|
|
238
|
-
|
|
238
|
+
// An import-only account holds what its import wrote: no fetch could add to it, so it says nothing of coverage.
|
|
239
|
+
for (const selected of scopeAccounts.filter(({ provider }) => !isImportedProvider(provider))) {
|
|
239
240
|
if (!(await store.sync.syncState(selected, CHAT_LIST_KEY))) {
|
|
240
241
|
inventoryComplete = false;
|
|
241
242
|
}
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
-
error?: undefined;
|
|
18
17
|
chatId: string;
|
|
19
18
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
20
19
|
algorithm: string;
|
|
21
20
|
fetchedAt: string | null;
|
|
22
21
|
source: string;
|
|
22
|
+
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
|
@@ -528,6 +528,7 @@ export const searchNotesOf = async (store, account, text, { accounts: list, app,
|
|
|
528
528
|
{ provider: "notes", account: INTERNAL_NOTES },
|
|
529
529
|
...(await store.notes.folders()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
530
530
|
...(await store.notes.documentsAccounts()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
531
|
+
...[await store.notes.addedAccount()].flatMap((added) => (added ? [{ provider: "notes", account: added.id }] : [])),
|
|
531
532
|
];
|
|
532
533
|
const named = list === undefined
|
|
533
534
|
? { accounts: held, skipped: [] }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { formatReference } from "../../domain/references.js";
|
|
3
|
+
import { isUsable } from "../../domain/relations.js";
|
|
3
4
|
import { chatCoverage } from "../chat-coverage.js";
|
|
4
5
|
import { LINK_PURPOSE, purposeRead, purposesOf } from "../project-purposes.js";
|
|
5
6
|
import { canonicalProjectRef, linkedChatsOf, storedChatCount, } from "../stored-project-gathering.js";
|
|
@@ -24,7 +25,7 @@ const childrenOf = async (store, root, catalog) => {
|
|
|
24
25
|
const below = [];
|
|
25
26
|
for (const parent of level)
|
|
26
27
|
for (const relation of await store.knowledge.relations(null, parent)) {
|
|
27
|
-
if (!relation.
|
|
28
|
+
if (!isUsable(relation.standing) || relation.kind !== "member-of" || relation.to !== parent)
|
|
28
29
|
continue;
|
|
29
30
|
if (!relation.from.startsWith("project:"))
|
|
30
31
|
continue;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MessageStore } from "../../../store/index.js";
|
|
2
|
+
import type { ProposalKind } from "../types.js";
|
|
3
|
+
/** An agent's or an import's contract with a value, by its own ref (`contract:12`); only the owner decides it. */
|
|
4
|
+
export declare const contractKind: (store: Pick<MessageStore, "contracts">) => ProposalKind;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { reviewedKind, reviewedRow } from "./shared.js";
|
|
2
|
+
/** An agent's or an import's contract with a value, by its own ref (`contract:12`); only the owner decides it. */
|
|
3
|
+
export const contractKind = (store) => reviewedKind({
|
|
4
|
+
type: "contract",
|
|
5
|
+
list: (options) => store.contracts.list(options),
|
|
6
|
+
get: (id) => store.contracts.get(id),
|
|
7
|
+
row: (contract) => reviewedRow("contract", contract, contract.deal),
|
|
8
|
+
decide: async (id, confirm, { by, reason }) => (confirm ? await store.contracts.confirm(id, by, reason) : await store.contracts.reject(id, by, reason)).ref,
|
|
9
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { MessageStore } from "../../../store/index.js";
|
|
2
2
|
import type { ProposalKind } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* An agent's or an import's invoice or payment. One kind per entity, because the registry routes an id by its prefix
|
|
5
|
+
* and the id is the entry's own ref (`payment:12`), as a fact's is. Only the owner decides money.
|
|
6
|
+
*/
|
|
3
7
|
export declare const invoiceKind: (store: Pick<MessageStore, "finance">) => ProposalKind;
|
|
4
8
|
export declare const paymentKind: (store: Pick<MessageStore, "finance">) => ProposalKind;
|
|
@@ -1,40 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const rowOf = (kind, entry) => ({
|
|
3
|
-
id: entry.ref,
|
|
4
|
-
kind,
|
|
5
|
-
status: entry.review,
|
|
6
|
-
project: entry.project,
|
|
7
|
-
subject: entry.ref,
|
|
8
|
-
object: "counterparty" in entry
|
|
9
|
-
? entry.counterparty.ref
|
|
10
|
-
: ((entry.direction === "in" ? entry.payer : entry.payee)?.ref ?? null),
|
|
11
|
-
summary: entry.title,
|
|
12
|
-
proposedBy: proposerOfAuthor(entry.author),
|
|
13
|
-
reason: entry.reason,
|
|
14
|
-
evidence: [],
|
|
15
|
-
score: null,
|
|
16
|
-
signals: null,
|
|
17
|
-
parts: null,
|
|
18
|
-
createdAt: entry.createdAt,
|
|
19
|
-
});
|
|
1
|
+
import { reviewedKind, reviewedRow } from "./shared.js";
|
|
20
2
|
/**
|
|
21
3
|
* An agent's or an import's invoice or payment. One kind per entity, because the registry routes an id by its prefix
|
|
22
4
|
* and the id is the entry's own ref (`payment:12`), as a fact's is. Only the owner decides money.
|
|
23
5
|
*/
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
6
|
+
export const invoiceKind = (store) => reviewedKind({
|
|
7
|
+
type: "invoice",
|
|
8
|
+
list: (options) => store.finance.invoices(options),
|
|
9
|
+
get: (id) => store.finance.invoice(id),
|
|
10
|
+
row: (invoice) => reviewedRow("invoice", invoice, invoice.counterparty.ref),
|
|
11
|
+
decide: async (id, confirm, { by, reason }) => (confirm ? await store.finance.confirm(id, by, reason) : await store.finance.reject(id, by, reason)).ref,
|
|
12
|
+
});
|
|
13
|
+
export const paymentKind = (store) => reviewedKind({
|
|
14
|
+
type: "payment",
|
|
15
|
+
list: (options) => store.finance.payments(options),
|
|
16
|
+
get: (id) => store.finance.payment(id),
|
|
17
|
+
row: (payment) => reviewedRow("payment", payment, (payment.direction === "in" ? payment.payer : payment.payee)?.ref ?? null),
|
|
18
|
+
decide: async (id, confirm, { by, reason }) => (confirm ? await store.finance.confirm(id, by, reason) : await store.finance.reject(id, by, reason)).ref,
|
|
38
19
|
});
|
|
39
|
-
export const invoiceKind = (store) => financeKind(store, "invoice");
|
|
40
|
-
export const paymentKind = (store) => financeKind(store, "payment");
|
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const rowOf = (order) => ({
|
|
3
|
-
id: order.ref,
|
|
4
|
-
kind: "order",
|
|
5
|
-
status: order.review,
|
|
6
|
-
project: order.project,
|
|
7
|
-
subject: order.ref,
|
|
8
|
-
object: order.supplier?.ref ?? null,
|
|
9
|
-
summary: order.title,
|
|
10
|
-
proposedBy: proposerOfAuthor(order.author),
|
|
11
|
-
reason: order.reason,
|
|
12
|
-
evidence: [],
|
|
13
|
-
score: null,
|
|
14
|
-
signals: null,
|
|
15
|
-
parts: null,
|
|
16
|
-
createdAt: order.createdAt,
|
|
17
|
-
});
|
|
1
|
+
import { reviewedKind, reviewedRow } from "./shared.js";
|
|
18
2
|
/** An agent's order, by its own ref (`order:12`) as invoices are; only the owner decides it. */
|
|
19
|
-
export const orderKind = (store) => ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return kept(orders.map(rowOf), filter);
|
|
26
|
-
},
|
|
27
|
-
get: async (id) => rowOf(await store.orders.get(id)),
|
|
28
|
-
decide: async (id, { confirm, by, reason }) => {
|
|
29
|
-
const order = confirm ? await store.orders.confirm(id, by, reason) : await store.orders.reject(id, by, reason);
|
|
30
|
-
return { id, kind: "order", status: confirm ? "confirmed" : "rejected", made: confirm ? [order.ref] : [] };
|
|
31
|
-
},
|
|
3
|
+
export const orderKind = (store) => reviewedKind({
|
|
4
|
+
type: "order",
|
|
5
|
+
list: (options) => store.orders.list(options),
|
|
6
|
+
get: (id) => store.orders.get(id),
|
|
7
|
+
row: (order) => reviewedRow("order", order, order.supplier?.ref ?? null),
|
|
8
|
+
decide: async (id, confirm, { by, reason }) => (confirm ? await store.orders.confirm(id, by, reason) : await store.orders.reject(id, by, reason)).ref,
|
|
32
9
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { DecidedType } from "../../../domain/record-types.js";
|
|
1
2
|
import type { Proposer } from "../../../store/decisions.js";
|
|
2
|
-
import type { ProposalFilter, ProposalRow } from "../types.js";
|
|
3
|
+
import type { Decision, ProposalFilter, ProposalKind, ProposalRow } from "../types.js";
|
|
3
4
|
/** A stored author as a proposer, with the kind read from its bot row. */
|
|
4
5
|
export declare const proposerOfAuthor: (author: {
|
|
5
6
|
type: "person" | "bot";
|
|
@@ -23,3 +24,28 @@ export declare const projectOf: (...refs: (string | null | undefined)[]) => stri
|
|
|
23
24
|
export declare const actionStatus: (status: string) => ProposalRow["status"];
|
|
24
25
|
/** The stored statuses a filter's status reads, so the store does the filtering when it can. */
|
|
25
26
|
export declare const storedStatus: (filter: ProposalFilter) => "proposed" | "rejected" | undefined;
|
|
27
|
+
/** What a reviewed store entry shows in the inbox: its own ref is the proposal's id. */
|
|
28
|
+
export interface ReviewedEntry {
|
|
29
|
+
ref: string;
|
|
30
|
+
review: "proposed" | "confirmed" | "rejected";
|
|
31
|
+
project: string | null;
|
|
32
|
+
title: string;
|
|
33
|
+
author: Parameters<typeof proposerOfAuthor>[0];
|
|
34
|
+
reason: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const reviewedRow: (kind: string, entry: ReviewedEntry, object: string | null) => ProposalRow;
|
|
38
|
+
/**
|
|
39
|
+
* A kind over a store whose rows carry `review`, routed by its own prefix as invoices are. Only the owner decides
|
|
40
|
+
* money: the store refuses an agent whatever the policy says.
|
|
41
|
+
*/
|
|
42
|
+
export declare const reviewedKind: <T>(spec: {
|
|
43
|
+
/** A type the record registry marks reviewed: its kind and its ref prefix both. */
|
|
44
|
+
type: DecidedType;
|
|
45
|
+
list: (options: ReturnType<typeof pushed> & {
|
|
46
|
+
review?: "proposed" | "confirmed" | "rejected";
|
|
47
|
+
}) => Promise<T[]>;
|
|
48
|
+
get: (id: string) => Promise<T>;
|
|
49
|
+
row: (entry: T) => ProposalRow;
|
|
50
|
+
decide: (id: string, confirm: boolean, decision: Pick<Decision, "by" | "reason">) => Promise<string>;
|
|
51
|
+
}) => ProposalKind;
|
|
@@ -47,3 +47,37 @@ export const storedStatus = (filter) => {
|
|
|
47
47
|
const status = filter.status ?? "proposed";
|
|
48
48
|
return status === "proposed" || status === "rejected" ? status : undefined;
|
|
49
49
|
};
|
|
50
|
+
export const reviewedRow = (kind, entry, object) => ({
|
|
51
|
+
id: entry.ref,
|
|
52
|
+
kind,
|
|
53
|
+
status: entry.review,
|
|
54
|
+
project: entry.project,
|
|
55
|
+
subject: entry.ref,
|
|
56
|
+
object,
|
|
57
|
+
summary: entry.title,
|
|
58
|
+
proposedBy: proposerOfAuthor(entry.author),
|
|
59
|
+
reason: entry.reason,
|
|
60
|
+
evidence: [],
|
|
61
|
+
score: null,
|
|
62
|
+
signals: null,
|
|
63
|
+
parts: null,
|
|
64
|
+
createdAt: entry.createdAt,
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* A kind over a store whose rows carry `review`, routed by its own prefix as invoices are. Only the owner decides
|
|
68
|
+
* money: the store refuses an agent whatever the policy says.
|
|
69
|
+
*/
|
|
70
|
+
export const reviewedKind = (spec) => ({
|
|
71
|
+
kind: spec.type,
|
|
72
|
+
prefix: spec.type,
|
|
73
|
+
list: async (filter) => {
|
|
74
|
+
const status = filter.status ?? "proposed";
|
|
75
|
+
const entries = await spec.list({ ...pushed(filter), ...(status === "all" ? {} : { review: status }) });
|
|
76
|
+
return kept(entries.map(spec.row), filter);
|
|
77
|
+
},
|
|
78
|
+
get: async (id) => spec.row(await spec.get(id)),
|
|
79
|
+
decide: async (id, { confirm, by, reason }) => {
|
|
80
|
+
const made = await spec.decide(id, confirm, { by, reason });
|
|
81
|
+
return { id, kind: spec.type, status: confirm ? "confirmed" : "rejected", made: confirm ? [made] : [] };
|
|
82
|
+
},
|
|
83
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MessageStore } from "../../../store/index.js";
|
|
2
|
+
import type { ProposalKind } from "../types.js";
|
|
3
|
+
/** A memory or fact whose sources changed, went or were contradicted; only the owner says whether it still holds. */
|
|
4
|
+
export declare const sourceReviewKind: (store: Pick<MessageStore, "knowledge" | "proposedActions">) => ProposalKind;
|