@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.
@@ -1394,6 +1394,104 @@ export const facts = sqliteTable("facts", {
1394
1394
  index("facts_by_author_type_author_id").on(table.authorType, table.authorId),
1395
1395
  index("facts_by_confirmed_by_type_confirmed_by_id").on(table.confirmedByType, table.confirmedById),
1396
1396
  ]);
1397
+ /** An invoice the owner issued or received; its total is the sum of its lines, its status follows allocations. */
1398
+ export const invoices = sqliteTable("invoices", {
1399
+ id: integer("id").primaryKey(),
1400
+ direction: text("direction").notNull(),
1401
+ number: text("number"),
1402
+ issuerType: text("issuer_type"),
1403
+ issuerId: integer("issuer_id"),
1404
+ counterpartyType: text("counterparty_type").notNull(),
1405
+ counterpartyId: integer("counterparty_id").notNull(),
1406
+ projectId: integer("project_id").references(() => projects.id),
1407
+ currency: text("currency").notNull(),
1408
+ /** Minor units of `currency`. */
1409
+ total: integer("total").notNull(),
1410
+ issueDate: text("issue_date"),
1411
+ dueDate: text("due_date"),
1412
+ status: text("status").notNull(),
1413
+ review: text("review").notNull(),
1414
+ authorType: text("author_type").notNull(),
1415
+ authorId: integer("author_id").notNull(),
1416
+ model: text("model"),
1417
+ confirmedByType: text("confirmed_by_type"),
1418
+ confirmedById: integer("confirmed_by_id"),
1419
+ source: text("source").notNull(),
1420
+ metadata: text("metadata"),
1421
+ createdAt: integer("created_at").notNull(),
1422
+ updatedAt: integer("updated_at").notNull(),
1423
+ deletedAt: integer("deleted_at"),
1424
+ }, (table) => [
1425
+ index("invoices_by_issuer_type_issuer_id").on(table.issuerType, table.issuerId),
1426
+ index("invoices_by_counterparty_type_counterparty_id").on(table.counterpartyType, table.counterpartyId),
1427
+ index("invoices_by_project_id").on(table.projectId),
1428
+ index("invoices_by_author_type_author_id").on(table.authorType, table.authorId),
1429
+ index("invoices_by_confirmed_by_type_confirmed_by_id").on(table.confirmedByType, table.confirmedById),
1430
+ ]);
1431
+ export const invoiceLines = sqliteTable("invoice_lines", {
1432
+ id: integer("id").primaryKey(),
1433
+ invoiceId: integer("invoice_id")
1434
+ .notNull()
1435
+ .references(() => invoices.id),
1436
+ position: integer("position").notNull(),
1437
+ description: text("description").notNull(),
1438
+ /** A decimal as text: never a float. */
1439
+ quantity: text("quantity").notNull(),
1440
+ unitPrice: integer("unit_price"),
1441
+ amount: integer("amount").notNull(),
1442
+ createdAt: integer("created_at").notNull(),
1443
+ updatedAt: integer("updated_at").notNull(),
1444
+ }, (table) => [unique().on(table.invoiceId, table.position)]);
1445
+ /** Money that moved to or from the owner, in minor units of its currency. */
1446
+ export const payments = sqliteTable("payments", {
1447
+ id: integer("id").primaryKey(),
1448
+ direction: text("direction").notNull(),
1449
+ payerType: text("payer_type"),
1450
+ payerId: integer("payer_id"),
1451
+ payeeType: text("payee_type"),
1452
+ payeeId: integer("payee_id"),
1453
+ amount: integer("amount").notNull(),
1454
+ currency: text("currency").notNull(),
1455
+ paymentDate: text("payment_date").notNull(),
1456
+ reference: text("reference"),
1457
+ projectId: integer("project_id").references(() => projects.id),
1458
+ review: text("review").notNull(),
1459
+ authorType: text("author_type").notNull(),
1460
+ authorId: integer("author_id").notNull(),
1461
+ model: text("model"),
1462
+ confirmedByType: text("confirmed_by_type"),
1463
+ confirmedById: integer("confirmed_by_id"),
1464
+ source: text("source").notNull(),
1465
+ metadata: text("metadata"),
1466
+ createdAt: integer("created_at").notNull(),
1467
+ updatedAt: integer("updated_at").notNull(),
1468
+ deletedAt: integer("deleted_at"),
1469
+ }, (table) => [
1470
+ index("payments_by_payer_type_payer_id").on(table.payerType, table.payerId),
1471
+ index("payments_by_payee_type_payee_id").on(table.payeeType, table.payeeId),
1472
+ index("payments_by_project_id").on(table.projectId),
1473
+ index("payments_by_author_type_author_id").on(table.authorType, table.authorId),
1474
+ index("payments_by_confirmed_by_type_confirmed_by_id").on(table.confirmedByType, table.confirmedById),
1475
+ ]);
1476
+ /** How much of a payment settles an invoice; triggers keep it within both and in one currency. */
1477
+ export const paymentAllocations = sqliteTable("payment_allocations", {
1478
+ id: integer("id").primaryKey(),
1479
+ paymentId: integer("payment_id")
1480
+ .notNull()
1481
+ .references(() => payments.id),
1482
+ invoiceId: integer("invoice_id")
1483
+ .notNull()
1484
+ .references(() => invoices.id),
1485
+ amount: integer("amount").notNull(),
1486
+ authorType: text("author_type").notNull(),
1487
+ authorId: integer("author_id").notNull(),
1488
+ createdAt: integer("created_at").notNull(),
1489
+ updatedAt: integer("updated_at").notNull(),
1490
+ }, (table) => [
1491
+ unique().on(table.paymentId, table.invoiceId),
1492
+ index("payment_allocations_by_invoice_id").on(table.invoiceId),
1493
+ index("payment_allocations_by_author_type_author_id").on(table.authorType, table.authorId),
1494
+ ]);
1397
1495
  export const proposedActions = sqliteTable("proposed_actions", {
1398
1496
  id: integer("id").primaryKey(),
1399
1497
  kind: text("kind").notNull(),
@@ -17,6 +17,8 @@ const REFERABLE = {
17
17
  fact: { tombstone: true },
18
18
  bot: { tombstone: false },
19
19
  event: { tombstone: true },
20
+ invoice: { tombstone: true },
21
+ payment: { tombstone: true },
20
22
  message: { tombstone: true },
21
23
  email: { tombstone: true },
22
24
  email_thread: { tombstone: true },
@@ -25,6 +25,7 @@ import { type MailStore } from "./sqlite/emails.js";
25
25
  import { type EventSearch } from "./sqlite/event-search.js";
26
26
  import { type FactsStore } from "./sqlite/facts.js";
27
27
  import { type FilesStore } from "./sqlite/files.js";
28
+ import { type FinanceStore } from "./sqlite/finance.js";
28
29
  import { type InvolvementStore } from "./sqlite/involvements.js";
29
30
  import { type KnowledgeStore } from "./sqlite/knowledge.js";
30
31
  import { type MeetingVectors } from "./sqlite/meeting-vectors.js";
@@ -95,6 +96,8 @@ export interface MessageStore {
95
96
  /** What any ref names, a page of them at a time: read once per page, never once per row. */
96
97
  readonly refs: RefsStore;
97
98
  readonly facts: FactsStore;
99
+ /** Invoices, payments and their allocations, in exact minor units; an agent's or an import's wait for the owner. */
100
+ readonly finance: FinanceStore;
98
101
  /** What agents concluded: summaries, digests, facts, preferences, each with evidence and a scope. */
99
102
  readonly memories: MemoriesStore;
100
103
  /** What an agent wants done outside the store, waiting for the owner's approval. */
@@ -24,6 +24,7 @@ import { eventSearchOver } from "./sqlite/event-search.js";
24
24
  import { evidenceFindingsStoreOver } from "./sqlite/evidence-findings.js";
25
25
  import { factsStoreOver } from "./sqlite/facts.js";
26
26
  import { filesStoreOver } from "./sqlite/files.js";
27
+ import { financeStoreOver } from "./sqlite/finance.js";
27
28
  import { involvementStoreOver } from "./sqlite/involvements.js";
28
29
  import { knowledgeStoreOver } from "./sqlite/knowledge.js";
29
30
  import { logPruner } from "./sqlite/log-pruning.js";
@@ -110,6 +111,7 @@ const storeOver = (context) => {
110
111
  summaries: async (texts, options) => refSummariesOf(context.database, texts, options),
111
112
  };
112
113
  const facts = once(() => factsStoreOver(context));
114
+ const finance = once(() => financeStoreOver(context));
113
115
  const memories = once(() => memoriesStoreOver(context));
114
116
  const proposedActions = once(() => proposedActionsStoreOver(context));
115
117
  const agentActions = once(() => agentActionsStoreOver(context, pruneLogsWhenDue));
@@ -210,6 +212,9 @@ const storeOver = (context) => {
210
212
  get facts() {
211
213
  return facts();
212
214
  },
215
+ get finance() {
216
+ return finance();
217
+ },
213
218
  get memories() {
214
219
  return memories();
215
220
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.556.0",
3
+ "version": "0.557.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",