@routedock/routedock 0.3.1 → 0.4.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 (58) hide show
  1. package/README.md +113 -12
  2. package/dist/{MppSessionHandler-1EL8QBAn.d.cts → MppSessionHandler-3QfCHI5x.d.ts} +40 -2
  3. package/dist/{MppSessionHandler-Bq4S-JTE.d.ts → MppSessionHandler-xu4Kxu6N.d.cts} +40 -2
  4. package/dist/{ProviderRegistry-w4_hkI_1.d.ts → ProviderRegistry-D9KqyuH-.d.cts} +16 -36
  5. package/dist/{ProviderRegistry-CyZ5eryO.d.cts → ProviderRegistry-DVi2uzgk.d.ts} +16 -36
  6. package/dist/{RouteDockClient-CjM2VyOd.d.ts → RouteDockClient-6rmgkbYb.d.cts} +124 -144
  7. package/dist/{RouteDockClient-CXvWXix5.d.cts → RouteDockClient-CnAkxwrW.d.ts} +124 -144
  8. package/dist/{SessionReconciler-Bw-PoBVl.d.ts → SessionReconciler-Cce9MXO1.d.ts} +10 -3
  9. package/dist/{SessionReconciler-Cz2nuOlJ.d.cts → SessionReconciler-Dpe9qXdD.d.cts} +10 -3
  10. package/dist/{SessionStore-BaYiegP0.d.ts → SessionStore-DkLBxFQu.d.cts} +28 -3
  11. package/dist/{SessionStore-B4-Hi4H8.d.cts → SessionStore-_ZkoBzFY.d.ts} +28 -3
  12. package/dist/SpendStore-BUclV02i.d.ts +73 -0
  13. package/dist/SpendStore-s_dfcemj.d.cts +73 -0
  14. package/dist/client.cjs +767 -482
  15. package/dist/client.d.cts +80 -10
  16. package/dist/client.d.ts +80 -10
  17. package/dist/client.js +733 -463
  18. package/dist/index.cjs +1295 -585
  19. package/dist/index.d.cts +13 -10
  20. package/dist/index.d.ts +13 -10
  21. package/dist/index.js +1247 -554
  22. package/dist/logger-DVa7VT4c.d.cts +41 -0
  23. package/dist/logger-DVa7VT4c.d.ts +41 -0
  24. package/dist/network.cjs +57 -0
  25. package/dist/network.d.cts +72 -0
  26. package/dist/network.d.ts +72 -0
  27. package/dist/network.js +49 -0
  28. package/dist/node.cjs +166 -0
  29. package/dist/node.d.cts +77 -0
  30. package/dist/node.d.ts +77 -0
  31. package/dist/node.js +159 -0
  32. package/dist/provider/fastify.cjs +847 -62
  33. package/dist/provider/fastify.d.cts +10 -3
  34. package/dist/provider/fastify.d.ts +10 -3
  35. package/dist/provider/fastify.js +848 -63
  36. package/dist/provider/hono.cjs +936 -60
  37. package/dist/provider/hono.d.cts +23 -8
  38. package/dist/provider/hono.d.ts +23 -8
  39. package/dist/provider/hono.js +937 -61
  40. package/dist/provider.cjs +894 -70
  41. package/dist/provider.d.cts +9 -8
  42. package/dist/provider.d.ts +9 -8
  43. package/dist/provider.js +895 -72
  44. package/dist/react.cjs +736 -431
  45. package/dist/react.d.cts +7 -5
  46. package/dist/react.d.ts +7 -5
  47. package/dist/react.js +725 -420
  48. package/dist/{routedockMiddleware-57gUaEMf.d.ts → routedockMiddleware-Cq9HOJEa.d.ts} +9 -2
  49. package/dist/{routedockMiddleware-DlyLrxp7.d.cts → routedockMiddleware-CxsWkSKa.d.cts} +9 -2
  50. package/dist/schema.cjs +7 -0
  51. package/dist/schema.js +7 -0
  52. package/dist/{sign-AKH67sft.d.cts → sign-Bq08SeFq.d.ts} +2 -2
  53. package/dist/{sign-BEq-OsSq.d.ts → sign-DqGE0Plv.d.cts} +2 -2
  54. package/dist/testing.d.cts +4 -3
  55. package/dist/testing.d.ts +4 -3
  56. package/dist/{logger-D8_Q2ytp.d.cts → types-DXaS5Wip.d.cts} +85 -47
  57. package/dist/{logger-D8_Q2ytp.d.ts → types-DXaS5Wip.d.ts} +85 -47
  58. package/package.json +50 -4
@@ -0,0 +1,73 @@
1
+ import { b as RouteDockLogger } from './logger-DVa7VT4c.cjs';
2
+
3
+ /**
4
+ * Daily spend accumulator, keyed by an ISO date (YYYY-MM-DD).
5
+ *
6
+ * Totals are decimal strings of integer microUSDC (1 USDC = 10^7 units) so
7
+ * the record stays JSON-serializable with no floating point precision loss.
8
+ */
9
+ interface DailySpend {
10
+ date: string;
11
+ /** Global accumulated spend for the day, in microUSDC (e.g. "5000000") */
12
+ totalMicros: string;
13
+ /** Per-endpoint accumulated spend for the day, keyed by origin URL, in microUSDC */
14
+ endpoints: Record<string, string>;
15
+ }
16
+ /**
17
+ * Durable backing store for the client's local daily spend cap.
18
+ *
19
+ * The spend cap is a financial safety control: if its accumulator lives only in
20
+ * heap memory, any crash, OOM kill, or container restart silently resets it to
21
+ * zero and the cap can be bypassed. Inject a persistent implementation
22
+ * (Redis, SQL, Supabase, a file, …) so the counter survives restarts.
23
+ *
24
+ * ### Sharing a store between processes
25
+ * The client serializes its own read → check → write with an in-memory mutex,
26
+ * but that only protects one `RouteDockClient` instance. If more than one
27
+ * process (or client) can use the same backing store — the MCP server and the
28
+ * E2E agent share `~/.routedock/spend.json` by default — a plain `read()` /
29
+ * `write()` pair is a lost-update race: two writers both read total X, both
30
+ * pass the cap check, and both write X + amount, so a payment vanishes from the
31
+ * accumulator and the cap can be exceeded. A store that is shared across
32
+ * processes MUST implement {@link SpendStore.update}, which the client uses
33
+ * instead of `read()` + `write()` whenever it is present.
34
+ */
35
+ interface SpendStore {
36
+ /** Return the persisted accumulator, or null if none has been written yet. */
37
+ read(): Promise<DailySpend | null>;
38
+ /** Persist the accumulator. */
39
+ write(state: DailySpend): Promise<void>;
40
+ /**
41
+ * Atomically read-modify-write the accumulator. Optional, but required for
42
+ * stores shared across processes (see above).
43
+ *
44
+ * Implementations must guarantee that no other writer can change the state
45
+ * between the read that produces `prev` and the write of `fn`'s result:
46
+ * `fn` receives the current state (or `null`), and returns the new state to
47
+ * persist, or `undefined` to leave the state unchanged (no write). If `fn`
48
+ * throws, nothing is written and the error propagates. `fn` is synchronous
49
+ * in spirit — keep it fast and free of side effects, because an
50
+ * implementation backed by optimistic concurrency (compare-and-swap) may
51
+ * call it more than once. Resolves to the state after the update.
52
+ */
53
+ update?(fn: (prev: DailySpend | null) => DailySpend | undefined): Promise<DailySpend | null>;
54
+ }
55
+ interface InMemorySpendStoreOptions {
56
+ /** Log a startup warning about non-durability. Defaults to true. */
57
+ warn?: boolean;
58
+ /** Log sink for the non-durability warning. Defaults to a console-backed logger. */
59
+ logger?: RouteDockLogger;
60
+ }
61
+ /**
62
+ * Default, non-durable {@link SpendStore}. Holds the accumulator on the heap, so
63
+ * it resets on every process restart. Logs a startup warning unless silenced.
64
+ * Use this only for development; inject a persistent store in production.
65
+ */
66
+ declare class InMemorySpendStore implements SpendStore {
67
+ private state;
68
+ constructor(options?: InMemorySpendStoreOptions);
69
+ read(): Promise<DailySpend | null>;
70
+ write(state: DailySpend): Promise<void>;
71
+ }
72
+
73
+ export { type DailySpend as D, InMemorySpendStore as I, type SpendStore as S, type InMemorySpendStoreOptions as a };