@wirecat/cli-core 0.556.0 → 0.557.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.
@@ -38,6 +38,7 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
+ limit?: undefined;
41
42
  event_id?: undefined;
42
43
  series_id?: undefined;
43
44
  page?: undefined;
@@ -53,11 +54,11 @@ export declare const meetingTools: ({
53
54
  format?: undefined;
54
55
  transcript_id?: undefined;
55
56
  query?: undefined;
56
- limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
+ limit?: undefined;
61
62
  event_id?: undefined;
62
63
  series_id?: undefined;
63
64
  page?: undefined;
@@ -75,11 +76,11 @@ export declare const meetingTools: ({
75
76
  format?: undefined;
76
77
  transcript_id?: undefined;
77
78
  query?: undefined;
78
- limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
+ limit?: undefined;
83
84
  event_id?: undefined;
84
85
  series_id?: undefined;
85
86
  page?: undefined;
@@ -101,7 +102,6 @@ export declare const meetingTools: ({
101
102
  minimum: number;
102
103
  };
103
104
  query?: undefined;
104
- limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,6 +188,7 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
+ limit?: undefined;
191
192
  event_id?: undefined;
192
193
  series_id?: undefined;
193
194
  page?: undefined;
@@ -203,11 +204,11 @@ export declare const meetingTools: ({
203
204
  format?: undefined;
204
205
  transcript_id?: undefined;
205
206
  query?: undefined;
206
- limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
+ limit?: undefined;
211
212
  event_id?: undefined;
212
213
  series_id?: undefined;
213
214
  page?: undefined;
@@ -225,11 +226,11 @@ export declare const meetingTools: ({
225
226
  format?: undefined;
226
227
  transcript_id?: undefined;
227
228
  query?: undefined;
228
- limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
+ limit?: undefined;
233
234
  event_id?: undefined;
234
235
  series_id?: undefined;
235
236
  page?: undefined;
@@ -251,7 +252,6 @@ export declare const meetingTools: ({
251
252
  minimum: number;
252
253
  };
253
254
  query?: undefined;
254
- limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,6 +338,7 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
+ limit?: undefined;
341
342
  event_id?: undefined;
342
343
  series_id?: undefined;
343
344
  page?: undefined;
@@ -353,11 +354,11 @@ export declare const meetingTools: ({
353
354
  format?: undefined;
354
355
  transcript_id?: undefined;
355
356
  query?: undefined;
356
- limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
+ limit?: undefined;
361
362
  event_id?: undefined;
362
363
  series_id?: undefined;
363
364
  page?: undefined;
@@ -375,11 +376,11 @@ export declare const meetingTools: ({
375
376
  format?: undefined;
376
377
  transcript_id?: undefined;
377
378
  query?: undefined;
378
- limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
+ limit?: undefined;
383
384
  event_id?: undefined;
384
385
  series_id?: undefined;
385
386
  page?: undefined;
@@ -401,7 +402,6 @@ export declare const meetingTools: ({
401
402
  minimum: number;
402
403
  };
403
404
  query?: undefined;
404
- limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,6 +488,7 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
+ limit?: undefined;
491
492
  event_id?: undefined;
492
493
  series_id?: undefined;
493
494
  page?: undefined;
@@ -503,11 +504,11 @@ export declare const meetingTools: ({
503
504
  format?: undefined;
504
505
  transcript_id?: undefined;
505
506
  query?: undefined;
506
- limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
+ limit?: undefined;
511
512
  event_id?: undefined;
512
513
  series_id?: undefined;
513
514
  page?: undefined;
@@ -525,11 +526,11 @@ export declare const meetingTools: ({
525
526
  format?: undefined;
526
527
  transcript_id?: undefined;
527
528
  query?: undefined;
528
- limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
+ limit?: undefined;
533
534
  event_id?: undefined;
534
535
  series_id?: undefined;
535
536
  page?: undefined;
@@ -551,7 +552,6 @@ export declare const meetingTools: ({
551
552
  minimum: number;
552
553
  };
553
554
  query?: undefined;
554
- limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,6 +638,7 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
+ limit?: undefined;
641
642
  event_id?: undefined;
642
643
  series_id?: undefined;
643
644
  page?: undefined;
@@ -653,11 +654,11 @@ export declare const meetingTools: ({
653
654
  format?: undefined;
654
655
  transcript_id?: undefined;
655
656
  query?: undefined;
656
- limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
+ limit?: undefined;
661
662
  event_id?: undefined;
662
663
  series_id?: undefined;
663
664
  page?: undefined;
@@ -675,11 +676,11 @@ export declare const meetingTools: ({
675
676
  format?: undefined;
676
677
  transcript_id?: undefined;
677
678
  query?: undefined;
678
- limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
+ limit?: undefined;
683
684
  event_id?: undefined;
684
685
  series_id?: undefined;
685
686
  page?: undefined;
@@ -701,7 +702,6 @@ export declare const meetingTools: ({
701
702
  minimum: number;
702
703
  };
703
704
  query?: undefined;
704
- limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -0,0 +1,4 @@
1
+ import type { MessageStore } from "../../../store/index.js";
2
+ import type { ProposalKind } from "../types.js";
3
+ export declare const invoiceKind: (store: Pick<MessageStore, "finance">) => ProposalKind;
4
+ export declare const paymentKind: (store: Pick<MessageStore, "finance">) => ProposalKind;
@@ -0,0 +1,40 @@
1
+ import { kept, proposerOfAuthor, pushed } from "./shared.js";
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
+ });
20
+ /**
21
+ * An agent's or an import's invoice or payment. One kind per entity, because the registry routes an id by its prefix
22
+ * and the id is the entry's own ref (`payment:12`), as a fact's is. Only the owner decides money.
23
+ */
24
+ const financeKind = (store, kind) => ({
25
+ kind,
26
+ prefix: kind,
27
+ list: async (filter) => {
28
+ const status = filter.status ?? "proposed";
29
+ const options = { ...pushed(filter), ...(status === "all" ? {} : { review: status }) };
30
+ const entries = kind === "invoice" ? await store.finance.invoices(options) : await store.finance.payments(options);
31
+ return kept(entries.map((entry) => rowOf(kind, entry)), filter);
32
+ },
33
+ get: async (id) => rowOf(kind, kind === "invoice" ? await store.finance.invoice(id) : await store.finance.payment(id)),
34
+ decide: async (id, { confirm, by, reason }) => {
35
+ const entry = confirm ? await store.finance.confirm(id, by, reason) : await store.finance.reject(id, by, reason);
36
+ return { id, kind, status: confirm ? "confirmed" : "rejected", made: confirm ? [entry.ref] : [] };
37
+ },
38
+ });
39
+ export const invoiceKind = (store) => financeKind(store, "invoice");
40
+ export const paymentKind = (store) => financeKind(store, "payment");
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { mayDecide } from "../../store/decisions.js";
3
3
  import { actionKind } from "./kinds/action.js";
4
4
  import { factKind } from "./kinds/fact.js";
5
+ import { invoiceKind, paymentKind } from "./kinds/finance.js";
5
6
  import { findingsKind } from "./kinds/findings.js";
6
7
  import { keyDocumentKind } from "./kinds/key-document.js";
7
8
  import { memoryKind } from "./kinds/memory.js";
@@ -122,6 +123,8 @@ export const proposalRegistry = (store) => {
122
123
  relationshipUpdateKind(store),
123
124
  keyDocumentKind(store),
124
125
  factKind(store),
126
+ invoiceKind(store),
127
+ paymentKind(store),
125
128
  memoryKind(store),
126
129
  findingsKind(store),
127
130
  ])
@@ -38,6 +38,7 @@ export { EVENT_FIELDS, type EventChunkToEmbed, type EventHit, type EventQuery, t
38
38
  export type { EvidenceSource } from "./sqlite/evidence-sources.js";
39
39
  export type { Fact, FactInput, FactsStore, PaymentFilter } from "./sqlite/facts.js";
40
40
  export type { FileListQuery, FilesStore, StoredFile } from "./sqlite/files.js";
41
+ export type { Allocation, FinanceStore, Invoice, InvoiceDetail, InvoiceInput, InvoiceLine, InvoiceLineInput, OpenTotal, Party, Payment as FinancePayment, PaymentDetail as FinancePaymentDetail, PaymentInput as FinancePaymentInput, } from "./sqlite/finance.js";
41
42
  export { IMPORTED_DOCUMENT_QUERY, type ImportedDocuments } from "./sqlite/imported-documents.js";
42
43
  export type { Involvement, InvolvementStore } from "./sqlite/involvements.js";
43
44
  export type { Annotation, KnowledgeRelation, KnowledgeStore, KnowledgeTarget, LabelledType, Organization, Project, Reminder, } from "./sqlite/knowledge.js";
@@ -20,6 +20,7 @@ export declare const ENTITY_TABLES: {
20
20
  readonly file: "files";
21
21
  readonly identity: "identities";
22
22
  readonly image: "attachments";
23
+ readonly invoice: "invoices";
23
24
  readonly meeting: "meetings";
24
25
  readonly meeting_transcript: "meeting_transcripts";
25
26
  readonly meeting_transcript_row: "meeting_transcript_rows";
@@ -27,6 +28,7 @@ export declare const ENTITY_TABLES: {
27
28
  readonly message: "messages";
28
29
  readonly note: "notes";
29
30
  readonly organization: "organizations";
31
+ readonly payment: "payments";
30
32
  readonly person: "persons";
31
33
  readonly place: "places";
32
34
  readonly project: "projects";
@@ -19,6 +19,7 @@ export const ENTITY_TABLES = {
19
19
  file: "files",
20
20
  identity: "identities",
21
21
  image: "attachments",
22
+ invoice: "invoices",
22
23
  meeting: "meetings",
23
24
  meeting_transcript: "meeting_transcripts",
24
25
  meeting_transcript_row: "meeting_transcript_rows",
@@ -26,6 +27,7 @@ export const ENTITY_TABLES = {
26
27
  message: "messages",
27
28
  note: "notes",
28
29
  organization: "organizations",
30
+ payment: "payments",
29
31
  person: "persons",
30
32
  place: "places",
31
33
  project: "projects",
@@ -0,0 +1,199 @@
1
+ import { type FinanceReview, type InvoiceDirection, type InvoiceStatus, type MoneyDirection } from "../../domain/finance.js";
2
+ import { type Money } from "../../domain/money.js";
3
+ import { type Decider } from "../decisions.js";
4
+ import { type Actor, type ProposedByFilter } from "./actors.js";
5
+ import { type Author } from "./memories.js";
6
+ import type { StoreContext } from "./open.js";
7
+ /** A `person:` or `organization:` on an invoice or a payment, with its name so a list needs no lookup. */
8
+ export interface Party {
9
+ ref: string;
10
+ name: string | null;
11
+ /** The owner's own person row. */
12
+ owner: boolean;
13
+ }
14
+ interface Reviewed {
15
+ review: FinanceReview;
16
+ /** `name` is a bot's handle and `kind` whether it is an agent or a rule; both `null` for a person. */
17
+ author: {
18
+ type: Actor["type"];
19
+ id: string;
20
+ name: string | null;
21
+ kind: "agent" | "rule" | null;
22
+ };
23
+ model: string | null;
24
+ confirmedBy: {
25
+ type: Actor["type"];
26
+ id: string;
27
+ } | null;
28
+ source: string;
29
+ /** Why an agent or an import proposed it. */
30
+ reason: string | null;
31
+ project: string | null;
32
+ projectName: string | null;
33
+ createdAt: string;
34
+ updatedAt: string;
35
+ }
36
+ export interface Invoice extends Reviewed {
37
+ id: string;
38
+ ref: string;
39
+ /** One line, as a list or the review inbox prints it. */
40
+ title: string;
41
+ direction: InvoiceDirection;
42
+ number: string | null;
43
+ issuer: Party | null;
44
+ counterparty: Party;
45
+ currency: string;
46
+ total: string;
47
+ /** Settled by confirmed payments. */
48
+ paid: string;
49
+ /** Still owed: `total − paid`. */
50
+ open: string;
51
+ issueDate: string | null;
52
+ dueDate: string | null;
53
+ status: InvoiceStatus;
54
+ }
55
+ export interface InvoiceLine {
56
+ position: number;
57
+ description: string;
58
+ quantity: string;
59
+ unitPrice: string | null;
60
+ amount: string;
61
+ }
62
+ export interface Allocation {
63
+ payment: string;
64
+ invoice: string;
65
+ amount: string;
66
+ currency: string;
67
+ createdAt: string;
68
+ }
69
+ export interface InvoiceDetail extends Invoice {
70
+ lines: InvoiceLine[];
71
+ allocations: Allocation[];
72
+ }
73
+ export interface Payment extends Reviewed {
74
+ id: string;
75
+ ref: string;
76
+ title: string;
77
+ direction: MoneyDirection;
78
+ payer: Party | null;
79
+ payee: Party | null;
80
+ amount: string;
81
+ currency: string;
82
+ /** `YYYY-MM-DD`. */
83
+ date: string;
84
+ reference: string | null;
85
+ /** Allocated to invoices, confirmed or not. */
86
+ allocated: string;
87
+ unallocated: string;
88
+ }
89
+ export interface PaymentDetail extends Payment {
90
+ allocations: Allocation[];
91
+ }
92
+ interface Written {
93
+ /** The owner's entry is confirmed at once; a bot's waits as proposed for the owner. */
94
+ by: Author;
95
+ project?: string;
96
+ /** Where a bot's row came from, such as `agent` or an importer's name; the owner's is always `owner`. */
97
+ source?: string;
98
+ /** Why a bot proposes it, kept for the reviewer. */
99
+ reason?: string;
100
+ }
101
+ export interface InvoiceLineInput {
102
+ description: string;
103
+ /** A decimal string; `1` when not given. */
104
+ quantity?: string;
105
+ /** Decimal strings in the invoice's currency. Give either or both: both must agree, quantity × unit price. */
106
+ unitPrice?: string;
107
+ amount?: string;
108
+ }
109
+ export interface InvoiceInput extends Written {
110
+ direction: InvoiceDirection;
111
+ number?: string;
112
+ /** `person:` or `organization:`. */
113
+ issuer?: string;
114
+ counterparty: string;
115
+ currency: string;
116
+ /** `YYYY-MM-DD`. */
117
+ issueDate?: string;
118
+ dueDate?: string;
119
+ /** Kept as a draft until `issueInvoice`; otherwise issued at once. */
120
+ draft?: boolean;
121
+ lines: InvoiceLineInput[];
122
+ /** The total printed on the invoice: refused when it is not the sum of the lines. */
123
+ total?: string;
124
+ }
125
+ export interface PaymentInput extends Written {
126
+ direction: MoneyDirection;
127
+ payer?: string;
128
+ payee?: string;
129
+ amount: string;
130
+ currency: string;
131
+ date: string;
132
+ reference?: string;
133
+ /** Invoices it settles, in the payment's currency; a bot's count only once the owner confirms the payment. */
134
+ allocations?: {
135
+ invoice: string;
136
+ amount: string;
137
+ }[];
138
+ }
139
+ interface ListFilter {
140
+ project?: string;
141
+ review?: FinanceReview;
142
+ proposedBy?: ProposedByFilter;
143
+ /** 1–500, 100 by default; newest written first. */
144
+ limit?: number;
145
+ }
146
+ export interface OpenTotal extends Money {
147
+ invoices: number;
148
+ }
149
+ export interface FinanceStore {
150
+ addInvoice(input: InvoiceInput): Promise<InvoiceDetail>;
151
+ invoice(reference: string): Promise<InvoiceDetail>;
152
+ invoices(filter?: ListFilter & {
153
+ direction?: InvoiceDirection;
154
+ status?: InvoiceStatus;
155
+ /** Issued or partly paid. */
156
+ open?: boolean;
157
+ counterparty?: string;
158
+ }): Promise<Invoice[]>;
159
+ /** The owner sends a draft: its status then follows its allocations. */
160
+ issueInvoice(reference: string, by: Author): Promise<InvoiceDetail>;
161
+ /** The owner cancels an invoice no confirmed payment is allocated to; proposed allocations to it go. */
162
+ voidInvoice(reference: string, by: Author): Promise<InvoiceDetail>;
163
+ addPayment(input: PaymentInput): Promise<PaymentDetail>;
164
+ payment(reference: string): Promise<PaymentDetail>;
165
+ payments(filter?: ListFilter & {
166
+ direction?: MoneyDirection;
167
+ party?: string;
168
+ }): Promise<Payment[]>;
169
+ /**
170
+ * Settles part of an invoice with part of a payment, in one currency, never beyond either. The owner allocates any
171
+ * payment; a bot only one it proposed that is still proposed.
172
+ */
173
+ allocate(input: {
174
+ payment: string;
175
+ invoice: string;
176
+ amount: string;
177
+ by: Author;
178
+ }): Promise<Allocation>;
179
+ /**
180
+ * The owner confirms a proposed `invoice:` or `payment:`; only the owner decides money. A payment whose allocations
181
+ * would settle more than an invoice's total, given the confirmed payments by then, is refused and stays proposed.
182
+ */
183
+ confirm(reference: string, by: Decider, reason?: string): Promise<InvoiceDetail | PaymentDetail>;
184
+ /** The owner turns a proposal down; it stays, `rejected`, and its allocations go. */
185
+ reject(reference: string, by: Decider, reason?: string): Promise<InvoiceDetail | PaymentDetail>;
186
+ /** What is still owed on confirmed open invoices, per direction and per currency: nothing is converted. */
187
+ openTotals(filter?: {
188
+ project?: string;
189
+ }): Promise<{
190
+ receivable: OpenTotal[];
191
+ payable: OpenTotal[];
192
+ }>;
193
+ }
194
+ type FinanceOperations = {
195
+ [K in keyof FinanceStore]: FinanceStore[K] extends (...args: infer A) => Promise<infer R> ? (...args: A) => R : never;
196
+ };
197
+ export declare const financeOperationsOver: (context: StoreContext) => FinanceOperations;
198
+ export declare const financeStoreOver: (context: StoreContext) => FinanceStore;
199
+ export {};