@hasna/economy 0.3.28 → 0.5.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.
Files changed (216) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +18 -22
  4. package/SECURITY.md +1 -1
  5. package/dist/chunks/agent-registry-store-tpnhx3wj.js +39 -0
  6. package/dist/chunks/billing-bkpxy4kv.js +13 -0
  7. package/dist/chunks/config-j9mv3ehk.js +15 -0
  8. package/dist/chunks/index-2hwzmfgv.js +3407 -0
  9. package/dist/chunks/index-axh32d30.js +1313 -0
  10. package/dist/chunks/index-emvs5ph2.js +2085 -0
  11. package/dist/chunks/index-ez9thsr7.js +3440 -0
  12. package/dist/chunks/index-hesxq90g.js +62 -0
  13. package/dist/chunks/index-k540hfww.js +258 -0
  14. package/dist/chunks/index-kgy9b6bf.js +451 -0
  15. package/dist/chunks/index-kn5572kd.js +124 -0
  16. package/dist/chunks/index-p35cyhc4.js +4 -0
  17. package/dist/chunks/index-w3bvv0ns.js +26 -0
  18. package/dist/chunks/index-zpvea08j.js +3372 -0
  19. package/dist/chunks/menubar-6xtkt17h.js +296 -0
  20. package/dist/chunks/open-projects-6z4pq6mx.js +39 -0
  21. package/dist/chunks/pricing-f80p81gr.js +29 -0
  22. package/dist/chunks/pricing-vf2pycmh.js +30 -0
  23. package/dist/chunks/pricing-y21mcjsa.js +30 -0
  24. package/dist/chunks/serve-0k69e4h9.js +4655 -0
  25. package/dist/chunks/sqlite-store-501f32ts.js +258 -0
  26. package/dist/chunks/sqlite-store-fq4natnf.js +256 -0
  27. package/dist/chunks/sqlite-store-st99garx.js +258 -0
  28. package/dist/chunks/third-party-sqlite-5e85fxa2.js +11 -0
  29. package/dist/chunks/tui-7f8f951w.js +22 -0
  30. package/dist/chunks/watch-mm1j39vy.js +196 -0
  31. package/dist/chunks/webhooks-k4fh2t9c.js +109 -0
  32. package/dist/cli/commands/brief.d.ts.map +1 -1
  33. package/dist/cli/commands/extras.d.ts.map +1 -1
  34. package/dist/cli/commands/journal.d.ts +3 -0
  35. package/dist/cli/commands/journal.d.ts.map +1 -0
  36. package/dist/cli/commands/menubar.d.ts +97 -4
  37. package/dist/cli/commands/menubar.d.ts.map +1 -1
  38. package/dist/cli/commands/tui.d.ts +1 -1
  39. package/dist/cli/commands/tui.d.ts.map +1 -1
  40. package/dist/cli/commands/watch.d.ts.map +1 -1
  41. package/dist/cli/index.js +1524 -9998
  42. package/dist/db/cloud.d.ts +18 -12
  43. package/dist/db/cloud.d.ts.map +1 -1
  44. package/dist/db/database.d.ts +33 -12
  45. package/dist/db/database.d.ts.map +1 -1
  46. package/dist/db/ingest-concurrency-worker.d.ts +2 -0
  47. package/dist/db/ingest-concurrency-worker.d.ts.map +1 -0
  48. package/dist/db/ingest-errors.d.ts +9 -0
  49. package/dist/db/ingest-errors.d.ts.map +1 -0
  50. package/dist/db/ingest-schema.d.ts +3 -0
  51. package/dist/db/ingest-schema.d.ts.map +1 -0
  52. package/dist/db/ingest-specs.d.ts +8 -0
  53. package/dist/db/ingest-specs.d.ts.map +1 -0
  54. package/dist/db/ingest-test-contract.d.ts +3 -0
  55. package/dist/db/ingest-test-contract.d.ts.map +1 -0
  56. package/dist/db/ingest-validation.d.ts +12 -0
  57. package/dist/db/ingest-validation.d.ts.map +1 -0
  58. package/dist/db/ingest.d.ts +27 -0
  59. package/dist/db/ingest.d.ts.map +1 -0
  60. package/dist/db/legacy-schema.d.ts +7 -0
  61. package/dist/db/legacy-schema.d.ts.map +1 -0
  62. package/dist/db/observation-contract.d.ts +3 -0
  63. package/dist/db/observation-contract.d.ts.map +1 -0
  64. package/dist/db/observation-provenance.d.ts +23 -0
  65. package/dist/db/observation-provenance.d.ts.map +1 -0
  66. package/dist/db/observation-schema.d.ts +24 -0
  67. package/dist/db/observation-schema.d.ts.map +1 -0
  68. package/dist/db/pg-connection.d.ts +10 -0
  69. package/dist/db/pg-connection.d.ts.map +1 -0
  70. package/dist/db/pg-migrate.d.ts +4 -9
  71. package/dist/db/pg-migrate.d.ts.map +1 -1
  72. package/dist/db/pg-migrations.d.ts.map +1 -1
  73. package/dist/db/pg-protocol.d.ts +28 -0
  74. package/dist/db/pg-protocol.d.ts.map +1 -0
  75. package/dist/db/sqlite-store.d.ts +4 -0
  76. package/dist/db/sqlite-store.d.ts.map +1 -0
  77. package/dist/db/sync-pg.d.ts +17 -21
  78. package/dist/db/sync-pg.d.ts.map +1 -1
  79. package/dist/db/third-party-sqlite.d.ts +10 -0
  80. package/dist/db/third-party-sqlite.d.ts.map +1 -0
  81. package/dist/index.d.ts +3 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +1281 -2405
  84. package/dist/ingest/claude-quota.d.ts.map +1 -1
  85. package/dist/ingest/claude.d.ts.map +1 -1
  86. package/dist/ingest/codex-quota.d.ts.map +1 -1
  87. package/dist/ingest/codex.d.ts +25 -0
  88. package/dist/ingest/codex.d.ts.map +1 -1
  89. package/dist/ingest/collection-outcome.d.ts +17 -0
  90. package/dist/ingest/collection-outcome.d.ts.map +1 -0
  91. package/dist/ingest/cursor.d.ts.map +1 -1
  92. package/dist/ingest/gemini.d.ts.map +1 -1
  93. package/dist/ingest/hermes.d.ts +1 -1
  94. package/dist/ingest/hermes.d.ts.map +1 -1
  95. package/dist/ingest/loops.d.ts +9 -0
  96. package/dist/ingest/loops.d.ts.map +1 -1
  97. package/dist/ingest/opencode.d.ts +1 -1
  98. package/dist/ingest/opencode.d.ts.map +1 -1
  99. package/dist/ingest/pi.d.ts +1 -1
  100. package/dist/ingest/pi.d.ts.map +1 -1
  101. package/dist/ingest/quota-observation.d.ts +16 -0
  102. package/dist/ingest/quota-observation.d.ts.map +1 -0
  103. package/dist/ingest/source-time.d.ts +4 -0
  104. package/dist/ingest/source-time.d.ts.map +1 -0
  105. package/dist/lib/accounts-store.d.ts +109 -0
  106. package/dist/lib/accounts-store.d.ts.map +1 -0
  107. package/dist/lib/accounts.d.ts +2 -1
  108. package/dist/lib/accounts.d.ts.map +1 -1
  109. package/dist/lib/analytics.d.ts.map +1 -1
  110. package/dist/lib/api-display-url.d.ts +19 -0
  111. package/dist/lib/api-display-url.d.ts.map +1 -0
  112. package/dist/lib/autosync-gate.d.ts +22 -0
  113. package/dist/lib/autosync-gate.d.ts.map +1 -0
  114. package/dist/lib/billing-diff.d.ts +18 -40
  115. package/dist/lib/billing-diff.d.ts.map +1 -1
  116. package/dist/lib/brief.d.ts +2 -0
  117. package/dist/lib/brief.d.ts.map +1 -1
  118. package/dist/lib/budget-decimal.d.ts +14 -0
  119. package/dist/lib/budget-decimal.d.ts.map +1 -0
  120. package/dist/lib/cloud-ingest.d.ts +30 -1
  121. package/dist/lib/cloud-ingest.d.ts.map +1 -1
  122. package/dist/lib/cloud-storage.d.ts +166 -10
  123. package/dist/lib/cloud-storage.d.ts.map +1 -1
  124. package/dist/lib/gatherer.d.ts.map +1 -1
  125. package/dist/lib/ingest-batches.d.ts +21 -0
  126. package/dist/lib/ingest-batches.d.ts.map +1 -0
  127. package/dist/lib/ingest-journal-client.d.ts +37 -0
  128. package/dist/lib/ingest-journal-client.d.ts.map +1 -0
  129. package/dist/lib/ingest-journal-lock.d.ts +5 -0
  130. package/dist/lib/ingest-journal-lock.d.ts.map +1 -0
  131. package/dist/lib/ingest-journal-maintenance.d.ts +92 -0
  132. package/dist/lib/ingest-journal-maintenance.d.ts.map +1 -0
  133. package/dist/lib/ingest-journal-operation.d.ts +55 -0
  134. package/dist/lib/ingest-journal-operation.d.ts.map +1 -0
  135. package/dist/lib/ingest-journal.d.ts +73 -0
  136. package/dist/lib/ingest-journal.d.ts.map +1 -0
  137. package/dist/lib/money-display.d.ts +13 -0
  138. package/dist/lib/money-display.d.ts.map +1 -0
  139. package/dist/lib/periods.d.ts +12 -0
  140. package/dist/lib/periods.d.ts.map +1 -1
  141. package/dist/lib/pricing.d.ts +14 -0
  142. package/dist/lib/pricing.d.ts.map +1 -1
  143. package/dist/lib/savings.d.ts +64 -7
  144. package/dist/lib/savings.d.ts.map +1 -1
  145. package/dist/lib/serve-auth.d.ts.map +1 -1
  146. package/dist/lib/store/index.d.ts +29 -22
  147. package/dist/lib/store/index.d.ts.map +1 -1
  148. package/dist/lib/summary-contract.d.ts +32 -0
  149. package/dist/lib/summary-contract.d.ts.map +1 -0
  150. package/dist/lib/summary-test-contract.d.ts +3 -0
  151. package/dist/lib/summary-test-contract.d.ts.map +1 -0
  152. package/dist/lib/sync-all.d.ts +4 -0
  153. package/dist/lib/sync-all.d.ts.map +1 -1
  154. package/dist/lib/sync-maintenance.d.ts.map +1 -1
  155. package/dist/lib/sync-report.d.ts +4 -0
  156. package/dist/lib/sync-report.d.ts.map +1 -0
  157. package/dist/lib/test-keychain-fixture.d.ts +9 -0
  158. package/dist/lib/test-keychain-fixture.d.ts.map +1 -0
  159. package/dist/mcp/agent-registry-store.d.ts +30 -0
  160. package/dist/mcp/agent-registry-store.d.ts.map +1 -0
  161. package/dist/mcp/agent-registry.d.ts +78 -0
  162. package/dist/mcp/agent-registry.d.ts.map +1 -0
  163. package/dist/mcp/harness.d.ts +26 -0
  164. package/dist/mcp/harness.d.ts.map +1 -0
  165. package/dist/mcp/index.js +3219 -3357
  166. package/dist/mcp/ingest-journal-tool.d.ts +2 -0
  167. package/dist/mcp/ingest-journal-tool.d.ts.map +1 -0
  168. package/dist/mcp/server.d.ts.map +1 -1
  169. package/dist/openapi.d.ts.map +1 -1
  170. package/dist/otel/index.js +2197 -121
  171. package/dist/server/human-auth.d.ts +20 -0
  172. package/dist/server/human-auth.d.ts.map +1 -0
  173. package/dist/server/index.js +10477 -6378
  174. package/dist/server/legacy-inventory.d.ts +52 -0
  175. package/dist/server/legacy-inventory.d.ts.map +1 -0
  176. package/dist/server/legacy-operations.d.ts +64 -0
  177. package/dist/server/legacy-operations.d.ts.map +1 -0
  178. package/dist/server/legacy-plan.d.ts +55 -0
  179. package/dist/server/legacy-plan.d.ts.map +1 -0
  180. package/dist/server/legacy-preservation.d.ts +58 -0
  181. package/dist/server/legacy-preservation.d.ts.map +1 -0
  182. package/dist/server/pg-sync-worker.js +195 -21
  183. package/dist/server/serve.d.ts +20 -18
  184. package/dist/server/serve.d.ts.map +1 -1
  185. package/dist/server/service-admission.d.ts +10 -0
  186. package/dist/server/service-admission.d.ts.map +1 -0
  187. package/dist/server/service-dispatcher.d.ts +45 -0
  188. package/dist/server/service-dispatcher.d.ts.map +1 -0
  189. package/dist/server/service-operations.d.ts +5 -0
  190. package/dist/server/service-operations.d.ts.map +1 -0
  191. package/dist/server/service-protocol.d.ts +50 -0
  192. package/dist/server/service-protocol.d.ts.map +1 -0
  193. package/dist/server/service-worker.d.ts +2 -0
  194. package/dist/server/service-worker.d.ts.map +1 -0
  195. package/dist/server/service-worker.js +8029 -0
  196. package/dist/types/index.d.ts +66 -0
  197. package/dist/types/index.d.ts.map +1 -1
  198. package/docs/README.md +1 -1
  199. package/docs/cli.md +2 -3
  200. package/docs/configuration.md +25 -12
  201. package/docs/cost-reporting.md +49 -0
  202. package/docs/historical-data-reconciliation.md +203 -0
  203. package/docs/ingest-journal.md +108 -0
  204. package/docs/ingestion.md +61 -5
  205. package/docs/mcp.md +5 -3
  206. package/docs/native-budget-save.md +84 -0
  207. package/docs/native-human-auth.md +102 -0
  208. package/docs/otel.md +8 -2
  209. package/docs/rest-api.md +4 -4
  210. package/package.json +17 -20
  211. package/postinstall.js +52 -1
  212. package/dashboard/README.md +0 -26
  213. package/dist/cli/brains.d.ts +0 -3
  214. package/dist/cli/brains.d.ts.map +0 -1
  215. package/dist/lib/test-hermetic-accounts.d.ts +0 -6
  216. package/dist/lib/test-hermetic-accounts.d.ts.map +0 -1
@@ -1,8 +1,14 @@
1
- import { resolveStorageClient, type HasnaStorageClient } from "./contracts-client/storage.js";
2
- /** Transport overrides (test injection: fetchImpl, headers, timeout, retry). */
3
- type StorageClientOverrides = Parameters<typeof resolveStorageClient>[2];
1
+ import { createClientTransport, type CredentialChainOptions } from "@hasna/contracts/client";
2
+ import { type HasnaStorageClient } from "@hasna/contracts/client/storage";
3
+ import type { ClientTransportResolution } from "@hasna/contracts/client";
4
4
  /** The economy app slug used for the HASNA_<APP>_* env lookups. */
5
5
  export declare const ECONOMY_APP = "economy";
6
+ /**
7
+ * The @hasna/contracts transport overrides (test injection: fetchImpl, headers,
8
+ * timeout, retry, sleepImpl) plus the tier-1 credential chain options
9
+ * (`--api-key` / `--profile` and the injectable `security` runner tests use).
10
+ */
11
+ export type EconomyStorageClientOverrides = Parameters<typeof createClientTransport>[2];
6
12
  export type EconomyCloudStorage = {
7
13
  /** True when reads/writes must go to the cloud HTTP API. */
8
14
  readonly active: true;
@@ -12,16 +18,130 @@ export type EconomyCloudStorage = {
12
18
  readonly active: false;
13
19
  readonly client: null;
14
20
  };
21
+ /**
22
+ * Explicit local-store opt-in variables. The on-box SQLite store is served
23
+ * only when one of these is set to a truthy value; without either of them (and
24
+ * without a resolved credential) the client fails closed.
25
+ */
26
+ export declare const LOCAL_STORAGE_OPT_IN_KEYS: readonly ["HASNA_ECONOMY_LOCAL", "ECONOMY_LOCAL"];
27
+ /**
28
+ * Every env name that can configure an economy authority or credential,
29
+ * resolver-derived — the one spelling the resolver itself looks for, so a
30
+ * second copy can never fall behind it.
31
+ */
32
+ export declare function economyAuthorityEnvKeys(): string[];
33
+ /**
34
+ * Does the ENVIRONMENT itself configure an economy authority or credential?
35
+ *
36
+ * Deliberately narrower than "does a credential resolve": answering it must not
37
+ * touch the Keychain or the filesystem, because doing so would defeat the
38
+ * isolation the local-opt-in short-circuit exists to provide (the @hasna/todos
39
+ * `local-opt-in.ts` pattern, owner directive 2026-09-04). It reads the env
40
+ * dictionary and nothing else.
41
+ *
42
+ * A DECLARED-BUT-BLANK variable counts as absent HERE — a blank has always been
43
+ * this package's spelling for "not configured", and helpers in the wild blank
44
+ * rather than delete. It is NOT absent once we do go hosted: the resolver
45
+ * refuses a blank loudly rather than falling through to another identity, which
46
+ * is the behaviour that matters at that point.
47
+ */
48
+ export declare function hasEconomyEnvAuthorityIntent(env: Record<string, string | undefined>): boolean;
49
+ /**
50
+ * True when SOMETHING configures a hosted authority for economy: the
51
+ * `HASNA_ECONOMY_API_URL` env key (or its legacy alias), the Keychain
52
+ * `api-url` item, or the `~/.hasna/economy/config/credentials` file.
53
+ *
54
+ * It asks the SAME three sources, in the same order and through the same
55
+ * @hasna/contracts entry points, that `createClientTransport` consults before
56
+ * it falls back to the fleet gateway; the gateway default is deliberately NOT
57
+ * one of them, because a default that always applies would make this always
58
+ * true. It drives the fail-closed message's way-out branch: an opted-in run
59
+ * with a configured authority is a half-applied hosted run, and the error says
60
+ * so instead of inviting the operator to use a different dataset.
61
+ */
62
+ export declare function hostedAuthorityConfigured(env: Record<string, string | undefined>, options?: EconomyStorageClientOverrides): boolean;
63
+ /**
64
+ * The environment as the resolver should see it: every authority/credential
65
+ * variable that is DECLARED BUT BLANK removed.
66
+ *
67
+ * A blank has always been this package's spelling for "not configured" — it is
68
+ * how the CLI's spawned-process fixtures neutralise an inherited fleet
69
+ * environment and how consumer fixtures still write it. @hasna/contracts takes
70
+ * the opposite and, for its purposes, correct view: a declared-but-blank
71
+ * credential is a misconfiguration it refuses loudly rather than resolving
72
+ * around. Both are right at their own layer: a blank that means "unset" at the
73
+ * economy seam is not a credential the operator named.
74
+ */
75
+ export declare function economyResolverEnv<T extends Record<string, string | undefined>>(env: T): T;
76
+ /**
77
+ * Build the resolver's inputs: the normalised environment AND the credential
78
+ * options that keep the machine's Keychain tier reachable across it.
79
+ *
80
+ * Dropping a declared-but-blank variable hands @hasna/contracts a COPY, and
81
+ * the resolver gates its ambient tiers on object identity (`env === process.env`,
82
+ * or the registry symbol its own snapshot carries). A copy is, by that test, a
83
+ * caller-built world — the hermetic seam — so the Keychain is outside it and
84
+ * tier 3 turns itself off silently, dropping a station from its Keychain
85
+ * identity to the next tier in the chain. The gate is decided HERE, on the
86
+ * original env, and carried across as the documented `keychain.enabled` control
87
+ * rather than being left to an identity test the copy cannot pass (hasna/apps#1788).
88
+ */
89
+ export declare function economyResolverInputs<T extends Record<string, string | undefined>>(env: T, credentials?: CredentialChainOptions): {
90
+ env: T;
91
+ credentials: CredentialChainOptions;
92
+ };
93
+ /**
94
+ * Resolve the authenticated economy HTTP storage client for this environment.
95
+ *
96
+ * There is no `local` branch here on purpose: a client never infers a local
97
+ * dataset from missing configuration. When nothing resolves, the shared
98
+ * resolver THROWS and the caller decides (see {@link resolveEconomyCloudStorage}).
99
+ */
100
+ export interface ResolvedEconomyStorageClient {
101
+ transport: "http";
102
+ client: HasnaStorageClient;
103
+ resolution: ClientTransportResolution;
104
+ }
105
+ /** The one call the storage seam makes: resolve the http client from the env. */
106
+ export declare function resolveEconomyStorageClient(name: string, env: Record<string, string | undefined>, overrides?: EconomyStorageClientOverrides): ResolvedEconomyStorageClient;
107
+ /**
108
+ * The one line a local run prints, so an unhosted run can never be mistaken for
109
+ * a hosted one that came back empty (owner directive 2026-09-04). It goes to
110
+ * stderr, so `--json` stdout stays machine-readable.
111
+ */
112
+ export declare function localEconomyNotice(): string;
113
+ /**
114
+ * The fail-closed error for a run with no credential and no local opt-in.
115
+ *
116
+ * The message is the documentation surface: it carries the resolver's own
117
+ * diagnostic (which names the Keychain item, the credentials file it looked
118
+ * for, and `HASNA_ECONOMY_API_KEY`) and adds the local opt-in, which the shared
119
+ * resolver cannot know about.
120
+ */
121
+ export declare function credentialRequiredError(env: NodeJS.ProcessEnv, cause?: unknown): Error;
15
122
  /**
16
123
  * Resolve the economy client storage transport for the current environment.
17
124
  *
18
- * Returns `{ active: true, client }` only when the contracts seam resolves to
19
- * the http transport (HASNA_ECONOMY_API_URL + HASNA_ECONOMY_API_KEY set).
20
- * Otherwise `{ active: false }` (local store). Throws when an API URL is set
21
- * without a key (the seam reports the resolution as misconfigured).
125
+ * Returns `{ active: true, client }` only when @hasna/contracts resolves an
126
+ * authenticated HTTP transport (a credential from any tier, authority defaulted
127
+ * to the fleet gateway). Returns `{ active: false }` (local store) only when
128
+ * the explicit local opt-in (`HASNA_ECONOMY_LOCAL=1` / `ECONOMY_LOCAL=1`) is
129
+ * set AND no hosted authority or credential resolves. Throws in every other
130
+ * unconfigured case — the error names the required API environment so a
131
+ * missing-env run can never silently serve the local dataset.
132
+ */
133
+ export declare function resolveEconomyCloudStorage(env?: NodeJS.ProcessEnv, overrides?: EconomyStorageClientOverrides): EconomyCloudStorage;
134
+ /**
135
+ * Memoized {@link resolveEconomyCloudStorage} for the process lifetime.
136
+ *
137
+ * A local-mode resolution (the explicit opt-in) announces itself on stderr with
138
+ * one line, once per process, so an unhosted run is never mistaken for a hosted
139
+ * one that came back empty (owner directive 2026-09-04). The notice goes to
140
+ * stderr so `--json` stdout stays machine-readable. The memoization never
141
+ * stalls a credential rotation: the @hasna/contracts transport behind a hosted
142
+ * client re-resolves its credential on EVERY request, so a long-lived MCP
143
+ * server or SDK consumer picks up a new key without a restart.
22
144
  */
23
- export declare function resolveEconomyCloudStorage(env?: NodeJS.ProcessEnv, overrides?: StorageClientOverrides): EconomyCloudStorage;
24
- /** Memoized {@link resolveEconomyCloudStorage} for the process lifetime. */
25
145
  export declare function economyCloudStorage(env?: NodeJS.ProcessEnv): EconomyCloudStorage;
26
146
  /** Test-only: drop the memoized resolution so a new env can be resolved. */
27
147
  export declare function resetEconomyCloudStorageCache(): void;
@@ -44,5 +164,41 @@ export declare function cloudListItems<T = unknown>(storage: ActiveEconomyCloudS
44
164
  * body if the server does not use the `{ data }` envelope.
45
165
  */
46
166
  export declare function cloudObject<T = unknown>(storage: ActiveEconomyCloudStorage, path: string, query?: CloudQuery): Promise<T>;
47
- export {};
167
+ /**
168
+ * The transport decision, rendered for operators (the `economy status` /
169
+ * `economy transport` surfaces and diagnostics). Reports WHERE the authority and
170
+ * credential came from — never the credential value.
171
+ */
172
+ export interface EconomyTransportAuthority {
173
+ /** `<origin>/v1` base for the server API, or null when nothing resolved. */
174
+ baseUrl: string | null;
175
+ /** An env key NAME, a Keychain reference, a file PATH, or `"default"`. */
176
+ apiUrlSource: string | null;
177
+ /** An env key NAME, a Keychain reference, or a file PATH. Never a value. */
178
+ apiKeySource: string | null;
179
+ /** Which tier of the credential chain supplied the key. */
180
+ apiKeyTier: string | null;
181
+ /** Human-readable warning, or null. Never contains secret values. */
182
+ warning: string | null;
183
+ }
184
+ export interface EconomyTransportReport {
185
+ ok: boolean;
186
+ /** True when this process is a client of a resolved store (hosted or local). */
187
+ selected: boolean;
188
+ transport: "http" | "sqlite";
189
+ /** `"local-opt-in"` for the explicit local lane, else the http transport source. */
190
+ source: string | null;
191
+ authority: EconomyTransportAuthority | null;
192
+ /** Human-readable issues when `ok` is false (the fail-closed refusal). */
193
+ issues: string[];
194
+ }
195
+ /**
196
+ * Resolve the economy transport and report the decision WITHOUT throwing.
197
+ *
198
+ * The one surface that must not fail the process on a missing credential: a
199
+ * status command that throws would turn "tell me why I am unconfigured" into a
200
+ * crash. Everything else calls {@link resolveEconomyCloudStorage} and fails
201
+ * closed.
202
+ */
203
+ export declare function economyTransportReport(env?: NodeJS.ProcessEnv, overrides?: EconomyStorageClientOverrides): EconomyTransportReport;
48
204
  //# sourceMappingURL=cloud-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-storage.d.ts","sourceRoot":"","sources":["../../src/lib/cloud-storage.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAE9F,gFAAgF;AAChF,KAAK,sBAAsB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE,mEAAmE;AACnE,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,MAAM,MAAM,mBAAmB,GAC3B;IACE,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;CACrC,GACD;IACE,QAAQ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,eAAe,EAAE,CAAA;CAC5B;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,oBAAoB,GAAG,CAAC,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;AAShF,eAAO,MAAM,kBAAkB,EAAE,oBAkNhC,CAAA"}
1
+ {"version":3,"file":"gatherer.d.ts","sourceRoot":"","sources":["../../src/lib/gatherer.ts"],"names":[],"mappings":"AASA,UAAU,eAAe;IACvB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,UAAU,eAAe;IACvB,QAAQ,EAAE,eAAe,EAAE,CAAA;CAC5B;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,oBAAoB,GAAG,CAAC,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;AAShF,eAAO,MAAM,kBAAkB,EAAE,oBAkNhC,CAAA"}
@@ -0,0 +1,21 @@
1
+ export interface IngestBatch {
2
+ schema_version: 1;
3
+ idempotency_key: string;
4
+ [table: string]: unknown;
5
+ }
6
+ /** Stable table/PK order produces repeatable keys for the exact same staged
7
+ * observations. Each bounded command commits independently; there is no hidden
8
+ * retry or claim that a whole multi-command scan is a single transaction. */
9
+ export declare function ingestBatches(body: Record<string, Record<string, unknown>[]>): Generator<IngestBatch>;
10
+ export interface IngestBatchReceipt {
11
+ idempotency_key: string;
12
+ operation_key?: string;
13
+ replayed: boolean;
14
+ }
15
+ export declare class IngestBatchFailure extends Error {
16
+ readonly pending_key: string;
17
+ readonly completed: IngestBatchReceipt[];
18
+ readonly pending_command: IngestBatch;
19
+ constructor(pending_key: string, completed: IngestBatchReceipt[], pending_command: IngestBatch);
20
+ }
21
+ //# sourceMappingURL=ingest-batches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-batches.d.ts","sourceRoot":"","sources":["../../src/lib/ingest-batches.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,cAAc,EAAE,CAAC,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CACzB;AACD;;6EAE6E;AAC7E,wBAAiB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,CA2BtG;AAED,MAAM,WAAW,kBAAkB;IAAG,eAAe,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE;AAC1G,qBAAa,kBAAmB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM;IAAE,QAAQ,CAAC,SAAS,EAAE,kBAAkB,EAAE;IAAE,QAAQ,CAAC,eAAe,EAAE,WAAW;gBAApG,WAAW,EAAE,MAAM,EAAW,SAAS,EAAE,kBAAkB,EAAE,EAAW,eAAe,EAAE,WAAW;CAI1H"}
@@ -0,0 +1,37 @@
1
+ import { type IngestJournalOperation } from './ingest-journal-operation.js';
2
+ /** Operational recovery state is local; Economy receipts and Trash custody are hosted. */
3
+ export declare function ingestJournal(input: IngestJournalOperation): Promise<{
4
+ retired: number;
5
+ remaining: number;
6
+ target: string;
7
+ commands: number;
8
+ completed: number;
9
+ rejected: number;
10
+ pending: number;
11
+ bytes: number;
12
+ reserved_bytes: number;
13
+ schema: "economy.ingest-journal.v1";
14
+ action: "status" | "reconcile" | "maintain";
15
+ } | {
16
+ retired: number;
17
+ target: string;
18
+ commands: number;
19
+ completed: number;
20
+ rejected: number;
21
+ pending: number;
22
+ bytes: number;
23
+ reserved_bytes: number;
24
+ schema: "economy.ingest-journal.v1";
25
+ action: "status" | "reconcile" | "maintain";
26
+ }>;
27
+ /** CLI/MCP errors never echo an upstream message, URL, credential or file body. */
28
+ export declare function ingestJournalError(error: unknown): {
29
+ error: {
30
+ code: string;
31
+ message: string;
32
+ reason?: string;
33
+ target?: string;
34
+ fields?: string[];
35
+ };
36
+ };
37
+ //# sourceMappingURL=ingest-journal-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-journal-client.d.ts","sourceRoot":"","sources":["../../src/lib/ingest-journal-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2D,KAAK,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAEpI,0FAA0F;AAC1F,wBAAsB,aAAa,CAAC,KAAK,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;GAKhE;AAED,mFAAmF;AACnF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAapJ"}
@@ -0,0 +1,5 @@
1
+ /** A kernel-owned lock: process exit releases ownership without deleting a
2
+ * lockfile or treating elapsed time as proof that another process is dead.
3
+ * The empty, permanent file must never be replaced while this target exists. */
4
+ export declare function withIngestJournalLock<T>(directory: string, action: () => Promise<T>): Promise<T>;
5
+ //# sourceMappingURL=ingest-journal-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-journal-lock.d.ts","sourceRoot":"","sources":["../../src/lib/ingest-journal-lock.ts"],"names":[],"mappings":"AAGA;;gFAEgF;AAChF,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsBtG"}
@@ -0,0 +1,92 @@
1
+ import type { ActiveEconomyCloudStorage } from './cloud-storage.js';
2
+ import type { IngestBatch } from './ingest-batches.js';
3
+ import { IngestJournal } from './ingest-journal.js';
4
+ export declare class JournalMaintenanceError extends Error {
5
+ readonly reason: string;
6
+ readonly target: string;
7
+ readonly code = "INGEST_JOURNAL_MAINTENANCE_REQUIRED";
8
+ constructor(reason: string, target: string);
9
+ }
10
+ interface Entry {
11
+ id: string;
12
+ originalPath: string;
13
+ kind: string;
14
+ sha256: string;
15
+ sizeBytes: number;
16
+ mode: number;
17
+ state: string;
18
+ stationId: string;
19
+ }
20
+ interface Operation {
21
+ id: string;
22
+ entryId: string;
23
+ path: string;
24
+ kind: string;
25
+ phase: string;
26
+ receipt?: {
27
+ sha256: string;
28
+ sizeBytes: number;
29
+ mode: number;
30
+ };
31
+ }
32
+ export interface JournalRecovery {
33
+ snapshot(path: string): {
34
+ sha256: string;
35
+ };
36
+ doctor(): Promise<{
37
+ station: {
38
+ id: string;
39
+ } | null;
40
+ retentionDays: number;
41
+ }>;
42
+ pending(limit: number): Array<{
43
+ id: string;
44
+ path?: string;
45
+ phase: string;
46
+ }>;
47
+ journal: {
48
+ read(id: string): Operation;
49
+ };
50
+ api: {
51
+ get(id: string): Promise<Entry>;
52
+ };
53
+ put(path: string, options?: {
54
+ retentionDays?: number;
55
+ }): Promise<Entry>;
56
+ recover(id: string, options: {
57
+ takeAbandonedLock: boolean;
58
+ }): Promise<unknown>;
59
+ }
60
+ export type JournalRecoveryFactory = (root: string, checkpoint: (point: string, operation: Operation) => Promise<void>, deadline: number) => Promise<JournalRecovery>;
61
+ /** A single permanent anchor prevents a changed principal from treating retired
62
+ * keys as new commands. It contains no credential and never grows with scans. */
63
+ export declare function verifyJournalAuthority(journal: IngestJournal, cloud: ActiveEconomyCloudStorage): Promise<void>;
64
+ /** Explicit opt-in precedes importing Trash or resolving any of its credentials.
65
+ * Non-fleet Economy authorities also require an explicit Trash URL. */
66
+ export declare function recoveryFactory(cloud: ActiveEconomyCloudStorage, env?: NodeJS.ProcessEnv): JournalRecoveryFactory;
67
+ /** All callers hold the target kernel lock. Only one immutable maintenance
68
+ * manifest exists at a time, and Trash captures that manifest after both files.
69
+ * Trash's own journal owns all transfer/staging/commit recovery. */
70
+ export declare class IngestJournalMaintenance {
71
+ readonly journal: IngestJournal;
72
+ readonly cloud: ActiveEconomyCloudStorage;
73
+ readonly factory: JournalRecoveryFactory;
74
+ readonly control: string;
75
+ readonly operationRoot: string;
76
+ constructor(journal: IngestJournal, cloud: ActiveEconomyCloudStorage, factory?: JournalRecoveryFactory);
77
+ private manifest;
78
+ private pending;
79
+ private backend;
80
+ private entry;
81
+ private pairFile;
82
+ /** Recover only the exact current transaction, never another collector POST. */
83
+ recover(): Promise<void>;
84
+ private finish;
85
+ maintain(limit?: number): Promise<{
86
+ retired: number;
87
+ remaining: number;
88
+ }>;
89
+ admit(command: IngestBatch): Promise<void>;
90
+ }
91
+ export {};
92
+ //# sourceMappingURL=ingest-journal-maintenance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-journal-maintenance.d.ts","sourceRoot":"","sources":["../../src/lib/ingest-journal-maintenance.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBA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yB;IAK3C,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,OAAO;YAKD,OAAO;YAsBP,KAAK;YAML,QAAQ;IA2BtB,gFAAgF;IAC1E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAQhB,MAAM;IA+Bd,QAAQ,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAgCrE,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAWjD"}
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ import type { ActiveEconomyCloudStorage } from './cloud-storage.js';
3
+ /** Local operational journal controls; these never invoke the original ingest
4
+ * POST. CLI/MCP share this schema and return errors as nonzero/isError. */
5
+ export declare const ingestJournalOperationSchema: z.ZodDiscriminatedUnion<"action", [z.ZodObject<{
6
+ action: z.ZodLiteral<"status">;
7
+ }, "strict", z.ZodTypeAny, {
8
+ action: "status";
9
+ }, {
10
+ action: "status";
11
+ }>, z.ZodObject<{
12
+ action: z.ZodLiteral<"reconcile">;
13
+ }, "strict", z.ZodTypeAny, {
14
+ action: "reconcile";
15
+ }, {
16
+ action: "reconcile";
17
+ }>, z.ZodObject<{
18
+ action: z.ZodLiteral<"maintain">;
19
+ confirm: z.ZodLiteral<true>;
20
+ limit: z.ZodDefault<z.ZodNumber>;
21
+ }, "strict", z.ZodTypeAny, {
22
+ limit: number;
23
+ action: "maintain";
24
+ confirm: true;
25
+ }, {
26
+ action: "maintain";
27
+ confirm: true;
28
+ limit?: number | undefined;
29
+ }>]>;
30
+ export type IngestJournalOperation = z.input<typeof ingestJournalOperationSchema>;
31
+ export declare function runIngestJournalOperation(cloud: ActiveEconomyCloudStorage, input: IngestJournalOperation): Promise<{
32
+ retired: number;
33
+ remaining: number;
34
+ target: string;
35
+ commands: number;
36
+ completed: number;
37
+ rejected: number;
38
+ pending: number;
39
+ bytes: number;
40
+ reserved_bytes: number;
41
+ schema: "economy.ingest-journal.v1";
42
+ action: "status" | "reconcile" | "maintain";
43
+ } | {
44
+ retired: number;
45
+ target: string;
46
+ commands: number;
47
+ completed: number;
48
+ rejected: number;
49
+ pending: number;
50
+ bytes: number;
51
+ reserved_bytes: number;
52
+ schema: "economy.ingest-journal.v1";
53
+ action: "status" | "reconcile" | "maintain";
54
+ }>;
55
+ //# sourceMappingURL=ingest-journal-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-journal-operation.d.ts","sourceRoot":"","sources":["../../src/lib/ingest-journal-operation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAKnE;2EAC2E;AAC3E,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,CAAA;AACF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AACjF,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,yBAAyB,EAAE,KAAK,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;GAgB9G"}
@@ -0,0 +1,73 @@
1
+ import type { IngestBatch } from './ingest-batches.js';
2
+ import type { ActiveEconomyCloudStorage } from './cloud-storage.js';
3
+ export declare const MAX_COMMANDS = 1000;
4
+ export declare const MAX_BYTES: number;
5
+ export declare const RECEIPT_RESERVE = 4096;
6
+ export declare const MAINTENANCE_RESERVE = 16384;
7
+ export declare class PendingIngestError extends Error {
8
+ readonly pending_keys: string[];
9
+ readonly code = "INGEST_RECONCILIATION_REQUIRED";
10
+ constructor(pending_keys: string[]);
11
+ }
12
+ export interface Intent {
13
+ version: 1;
14
+ target: string;
15
+ body_hash: string;
16
+ command: IngestBatch;
17
+ }
18
+ export interface IngestRefusal {
19
+ status: 400 | 409 | 413 | 422;
20
+ code: 'ingest_refused' | 'legacy_aggregate_requires_migration';
21
+ reason: 'invalid_ingest' | 'ingest_conflict' | 'ingest_too_large' | 'unprocessable_ingest' | 'legacy_aggregate_requires_migration';
22
+ }
23
+ export declare function definitiveIngestRefusal(status: number, body: unknown): IngestRefusal | null;
24
+ export declare function getIngestJournalPath(): string;
25
+ export declare function secureDirectory(path: string): void;
26
+ export declare function readJson(path: string, max: number): unknown;
27
+ export declare function createExact(path: string, value: unknown): boolean;
28
+ export declare function unwrap(raw: unknown): any;
29
+ export declare function verifyIngestReceipt(raw: unknown, command: IngestBatch): any;
30
+ export declare function sameReceipt(left: unknown, right: unknown): boolean;
31
+ export declare function lookupJournalReceipt(cloud: ActiveEconomyCloudStorage, key: string, bodyHash: string, timeoutMs?: number): Promise<unknown | null>;
32
+ /** Operational intent only. Immutable intent and receipt files are retained;
33
+ * absence of a receipt never authorizes another POST, including after restart. */
34
+ export declare class IngestJournal {
35
+ readonly directory: string;
36
+ readonly target: string;
37
+ private inventoryBytes;
38
+ private readonly freshlyStaged;
39
+ constructor(cloud: ActiveEconomyCloudStorage, path?: string);
40
+ names(): string[];
41
+ file(key: string, kind: 'intent' | 'receipt' | 'refusal'): string;
42
+ intent(name: string): Intent;
43
+ status(): {
44
+ target: string;
45
+ commands: number;
46
+ completed: number;
47
+ rejected: number;
48
+ pending: number;
49
+ bytes: number;
50
+ reserved_bytes: number;
51
+ };
52
+ canStage(command: IngestBatch, status?: {
53
+ target: string;
54
+ commands: number;
55
+ completed: number;
56
+ rejected: number;
57
+ pending: number;
58
+ bytes: number;
59
+ reserved_bytes: number;
60
+ }): boolean;
61
+ receipt(command: IngestBatch): ReturnType<typeof verifyIngestReceipt>;
62
+ stage(command: IngestBatch): boolean;
63
+ accept(command: IngestBatch, raw: unknown): any;
64
+ /** Only the caller which staged this fresh intent may record its own first
65
+ * POST's definitive refusal. Existing uncertain intents cannot be converted. */
66
+ recordRefusal(command: IngestBatch, refusal: IngestRefusal): void;
67
+ refusal(command: IngestBatch): IngestRefusal | null;
68
+ reconcileCommand(cloud: ActiveEconomyCloudStorage, command: IngestBatch, timeoutMs?: number): Promise<any | null>;
69
+ assertCloud(cloud: ActiveEconomyCloudStorage): void;
70
+ lookupReceipt(cloud: ActiveEconomyCloudStorage, command: IngestBatch, timeoutMs?: number): Promise<ReturnType<typeof verifyIngestReceipt> | null>;
71
+ reconcilePending(cloud: ActiveEconomyCloudStorage): Promise<void>;
72
+ }
73
+ //# sourceMappingURL=ingest-journal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-journal.d.ts","sourceRoot":"","sources":["../../src/lib/ingest-journal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAEnE,eAAO,MAAM,YAAY,OAAK,CAAA;AAC9B,eAAO,MAAM,SAAS,QAAa,CAAA;AACnC,eAAO,MAAM,eAAe,OAAK,CAAA;AACjC,eAAO,MAAM,mBAAmB,QAAM,CAAA;AAEtC,qBAAa,kBAAmB,SAAQ,KAAK;IAEhC,QAAQ,CAAC,YAAY,EAAC,MAAM,EAAE;IAD1C,QAAQ,CAAC,IAAI,oCAAiC;gBACzB,YAAY,EAAC,MAAM,EAAE;CAC1C;AACD,MAAM,WAAW,MAAM;IAAE,OAAO,EAAC,CAAC,CAAC;IAAA,MAAM,EAAC,MAAM,CAAC;IAAA,SAAS,EAAC,MAAM,CAAC;IAAA,OAAO,EAAC,WAAW,CAAA;CAAC;AACtF,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,CAAA;IACtB,IAAI,EAAC,gBAAgB,GAAC,qCAAqC,CAAA;IAC3D,MAAM,EAAC,gBAAgB,GAAC,iBAAiB,GAAC,kBAAkB,GAAC,sBAAsB,GAAC,qCAAqC,CAAA;CACzH;AACD,wBAAgB,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M,CAAC;QAAA,QAAQ,EAAC,MAAM,CAAC;QAAA,SAAS,EAAC,MAAM,CAAC;QAAA,QAAQ,EAAC,MAAM,CAAC;QAAA,OAAO,EAAC,MAAM,CAAC;QAAA,KAAK,EAAC,MAAM,CAAC;QAAA,cAAc,EAAC,MAAM,CAAA;KAAC;IAU3H,QAAQ,CAAC,OAAO,EAAC,WAAW,EAAC,MAAM;gBAVlB,MAAM;kBAAU,MAAM;mBAAW,MAAM;kBAAU,MAAM;iBAAS,MAAM;eAAO,MAAM;wBAAgB,MAAM;KAUzE,GAAE,OAAO;IAS1D,OAAO,CAAC,OAAO,EAAC,WAAW,GAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC;IAMnE,KAAK,CAAC,OAAO,EAAC,WAAW,GAAE,OAAO;IAWlC,MAAM,CAAC,OAAO,EAAC,WAAW,EAAC,GAAG,EAAC,OAAO,GAAE,GAAG;IAe3C;oFACgF;IAChF,aAAa,CAAC,OAAO,EAAC,WAAW,EAAC,OAAO,EAAC,aAAa,GAAE,IAAI;IAa7D,OAAO,CAAC,OAAO,EAAC,WAAW,GAAE,aAAa,GAAC,IAAI;IAUzC,gBAAgB,CAAC,KAAK,EAAC,yBAAyB,EAAC,OAAO,EAAC,WAAW,EAAC,SAAS,SAAO,GAAE,OAAO,CAAC,GAAG,GAAC,IAAI,CAAC;IAI9G,WAAW,CAAC,KAAK,EAAC,yBAAyB,GAAE,IAAI;IAC3C,aAAa,CAAC,KAAK,EAAC,yBAAyB,EAAC,OAAO,EAAC,WAAW,EAAC,SAAS,SAAO,GAAE,OAAO,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,GAAC,IAAI,CAAC;IAKxI,gBAAgB,CAAC,KAAK,EAAC,yBAAyB,GAAE,OAAO,CAAC,IAAI,CAAC;CAiBrE"}
@@ -0,0 +1,13 @@
1
+ /** Unknown is a reporting state, never an implicit zero-dollar amount. */
2
+ export declare function formatReportedUsd(value: number | null | undefined): string;
3
+ export declare function formatSourcedUsd(value: number, basis?: string): string;
4
+ export declare function formatPlanMoney(plan: {
5
+ monthly_fee_usd: number;
6
+ included_usage_usd: number;
7
+ fee_basis?: string;
8
+ included_basis?: string;
9
+ }): {
10
+ fee: string;
11
+ included: string;
12
+ };
13
+ //# sourceMappingURL=money-display.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money-display.d.ts","sourceRoot":"","sources":["../../src/lib/money-display.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAG1E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,eAAe,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjG,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAGpC"}
@@ -1,6 +1,18 @@
1
1
  import type { Period } from '../types/index.js';
2
+ export interface CalendarPeriodBounds {
3
+ time_zone: 'UTC';
4
+ start_date: string | null;
5
+ end_date_exclusive: string | null;
6
+ }
7
+ /** Existing daily records use UTC. A week starts on Sunday; ranges are half-open. */
8
+ export declare function calendarPeriodBounds(period: Period, now?: Date): CalendarPeriodBounds;
9
+ /** Column names are code-owned identifiers; only generated ISO dates enter SQL. */
10
+ export declare function calendarPeriodWhere(period: Period, column: string, now?: Date): string;
2
11
  export declare function usageSnapshotFilterForPeriod(period: Period): {
3
12
  date?: string;
4
13
  since?: string;
14
+ before?: string;
5
15
  };
16
+ /** Lifetime aggregates overlap a period but cannot be allocated into its days. */
17
+ export declare function sessionOverlapWhere(period: Period, alias: string, now?: Date): string;
6
18
  //# sourceMappingURL=periods.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"periods.d.ts","sourceRoot":"","sources":["../../src/lib/periods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAM/C,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAsB9F"}
1
+ {"version":3,"file":"periods.d.ts","sourceRoot":"","sources":["../../src/lib/periods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAM/C,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,KAAK,CAAA;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAa,GAAG,oBAAoB,CAgC3F;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAa,GAAG,MAAM,CAO5F;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAK/G;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,MAAM,EAAC,MAAM,EAAC,KAAK,EAAC,MAAM,EAAC,GAAG,OAAW,GAAE,MAAM,CAIpF"}
@@ -8,6 +8,20 @@ export declare function getPricingFromDb(db: Database, model: string): ModelPric
8
8
  export declare function getPricing(model: string): ModelPricing | null;
9
9
  export declare function computeCost(model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number, cacheWrite1hTokens?: number, cacheStorageTokenHours?: number): number;
10
10
  export declare function computeCostFromDb(db: Database, model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number, cacheWrite1hTokens?: number, cacheStorageTokenHours?: number): number;
11
+ export type CostAssessment = {
12
+ usd: number;
13
+ pricing: 'configured' | 'catalog' | 'explicit_free';
14
+ } | {
15
+ usd: null;
16
+ pricing: 'missing';
17
+ };
18
+ export declare class UnknownModelPricingError extends Error {
19
+ readonly code = "MODEL_PRICING_UNAVAILABLE";
20
+ constructor();
21
+ }
22
+ /** Token estimates describe usage value, never the account's billing route. */
23
+ export declare function assessCostFromDb(db: Database, model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number, cacheWrite1hTokens?: number, cacheStorageTokenHours?: number): CostAssessment;
11
24
  export declare function getPricingFromRows(rows: DbModelPricing[], model: string): ModelPricing | null;
12
25
  export declare function estimateCostFromRows(rows: DbModelPricing[], model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number, cacheWrite1hTokens?: number, cacheStorageTokenHours?: number): number;
26
+ export declare function assessCostFromRows(rows: DbModelPricing[], model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number, cacheWrite1hTokens?: number, cacheStorageTokenHours?: number): CostAssessment;
13
27
  //# sourceMappingURL=pricing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/lib/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAA6E,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAIlI,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,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