@c9up/polaris 0.0.0-stage → 0.1.1

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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1146 -2
  3. package/dist/Polaris.d.ts +80 -0
  4. package/dist/Polaris.d.ts.map +1 -0
  5. package/dist/Polaris.js +208 -0
  6. package/dist/Polaris.js.map +1 -0
  7. package/dist/PolarisClient.d.ts +184 -0
  8. package/dist/PolarisClient.d.ts.map +1 -0
  9. package/dist/PolarisClient.js +576 -0
  10. package/dist/PolarisClient.js.map +1 -0
  11. package/dist/PolarisProvider.d.ts +40 -0
  12. package/dist/PolarisProvider.d.ts.map +1 -0
  13. package/dist/PolarisProvider.js +79 -0
  14. package/dist/PolarisProvider.js.map +1 -0
  15. package/dist/augmentations.d.ts +18 -0
  16. package/dist/augmentations.d.ts.map +1 -0
  17. package/dist/augmentations.js +9 -0
  18. package/dist/augmentations.js.map +1 -0
  19. package/dist/budget.d.ts +77 -0
  20. package/dist/budget.d.ts.map +1 -0
  21. package/dist/budget.js +134 -0
  22. package/dist/budget.js.map +1 -0
  23. package/dist/catalog/catalog.d.ts +37 -0
  24. package/dist/catalog/catalog.d.ts.map +1 -0
  25. package/dist/catalog/catalog.js +145 -0
  26. package/dist/catalog/catalog.js.map +1 -0
  27. package/dist/catalog/discover.d.ts +64 -0
  28. package/dist/catalog/discover.d.ts.map +1 -0
  29. package/dist/catalog/discover.js +148 -0
  30. package/dist/catalog/discover.js.map +1 -0
  31. package/dist/catalog/index.d.ts +8 -0
  32. package/dist/catalog/index.d.ts.map +1 -0
  33. package/dist/catalog/index.js +8 -0
  34. package/dist/catalog/index.js.map +1 -0
  35. package/dist/commands/index.d.ts +82 -0
  36. package/dist/commands/index.d.ts.map +1 -0
  37. package/dist/commands/index.js +278 -0
  38. package/dist/commands/index.js.map +1 -0
  39. package/dist/cost.d.ts +50 -0
  40. package/dist/cost.d.ts.map +1 -0
  41. package/dist/cost.js +131 -0
  42. package/dist/cost.js.map +1 -0
  43. package/dist/drivers/anthropic.d.ts +44 -0
  44. package/dist/drivers/anthropic.d.ts.map +1 -0
  45. package/dist/drivers/anthropic.js +539 -0
  46. package/dist/drivers/anthropic.js.map +1 -0
  47. package/dist/drivers/openai-compatible.d.ts +54 -0
  48. package/dist/drivers/openai-compatible.d.ts.map +1 -0
  49. package/dist/drivers/openai-compatible.js +699 -0
  50. package/dist/drivers/openai-compatible.js.map +1 -0
  51. package/dist/drivers/status.d.ts +8 -0
  52. package/dist/drivers/status.d.ts.map +1 -0
  53. package/dist/drivers/status.js +21 -0
  54. package/dist/drivers/status.js.map +1 -0
  55. package/dist/errors.d.ts +79 -0
  56. package/dist/errors.d.ts.map +1 -0
  57. package/dist/errors.js +86 -0
  58. package/dist/errors.js.map +1 -0
  59. package/dist/extract.d.ts +38 -0
  60. package/dist/extract.d.ts.map +1 -0
  61. package/dist/extract.js +144 -0
  62. package/dist/extract.js.map +1 -0
  63. package/dist/index.d.ts +21 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +15 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/json-schema.d.ts +33 -0
  68. package/dist/json-schema.d.ts.map +1 -0
  69. package/dist/json-schema.js +508 -0
  70. package/dist/json-schema.js.map +1 -0
  71. package/dist/log.d.ts +47 -0
  72. package/dist/log.d.ts.map +1 -0
  73. package/dist/log.js +35 -0
  74. package/dist/log.js.map +1 -0
  75. package/dist/mcp/client.d.ts +81 -0
  76. package/dist/mcp/client.d.ts.map +1 -0
  77. package/dist/mcp/client.js +401 -0
  78. package/dist/mcp/client.js.map +1 -0
  79. package/dist/mcp/endpoint.d.ts +54 -0
  80. package/dist/mcp/endpoint.d.ts.map +1 -0
  81. package/dist/mcp/endpoint.js +158 -0
  82. package/dist/mcp/endpoint.js.map +1 -0
  83. package/dist/mcp/host.d.ts +42 -0
  84. package/dist/mcp/host.d.ts.map +1 -0
  85. package/dist/mcp/host.js +111 -0
  86. package/dist/mcp/host.js.map +1 -0
  87. package/dist/mcp/http.d.ts +32 -0
  88. package/dist/mcp/http.d.ts.map +1 -0
  89. package/dist/mcp/http.js +190 -0
  90. package/dist/mcp/http.js.map +1 -0
  91. package/dist/mcp/index.d.ts +23 -0
  92. package/dist/mcp/index.d.ts.map +1 -0
  93. package/dist/mcp/index.js +21 -0
  94. package/dist/mcp/index.js.map +1 -0
  95. package/dist/mcp/manifest.d.ts +36 -0
  96. package/dist/mcp/manifest.d.ts.map +1 -0
  97. package/dist/mcp/manifest.js +40 -0
  98. package/dist/mcp/manifest.js.map +1 -0
  99. package/dist/mcp/rpc.d.ts +39 -0
  100. package/dist/mcp/rpc.d.ts.map +1 -0
  101. package/dist/mcp/rpc.js +149 -0
  102. package/dist/mcp/rpc.js.map +1 -0
  103. package/dist/mcp/stdio.d.ts +24 -0
  104. package/dist/mcp/stdio.d.ts.map +1 -0
  105. package/dist/mcp/stdio.js +157 -0
  106. package/dist/mcp/stdio.js.map +1 -0
  107. package/dist/mcp/worker-main.d.ts +6 -0
  108. package/dist/mcp/worker-main.d.ts.map +1 -0
  109. package/dist/mcp/worker-main.js +17 -0
  110. package/dist/mcp/worker-main.js.map +1 -0
  111. package/dist/mcp/worker.d.ts +54 -0
  112. package/dist/mcp/worker.d.ts.map +1 -0
  113. package/dist/mcp/worker.js +166 -0
  114. package/dist/mcp/worker.js.map +1 -0
  115. package/dist/meter.d.ts +63 -0
  116. package/dist/meter.d.ts.map +1 -0
  117. package/dist/meter.js +94 -0
  118. package/dist/meter.js.map +1 -0
  119. package/dist/providers.d.ts +23 -0
  120. package/dist/providers.d.ts.map +1 -0
  121. package/dist/providers.js +21 -0
  122. package/dist/providers.js.map +1 -0
  123. package/dist/redact.d.ts +12 -0
  124. package/dist/redact.d.ts.map +1 -0
  125. package/dist/redact.js +77 -0
  126. package/dist/redact.js.map +1 -0
  127. package/dist/redis-budget.d.ts +45 -0
  128. package/dist/redis-budget.d.ts.map +1 -0
  129. package/dist/redis-budget.js +56 -0
  130. package/dist/redis-budget.js.map +1 -0
  131. package/dist/response.d.ts +39 -0
  132. package/dist/response.d.ts.map +1 -0
  133. package/dist/response.js +109 -0
  134. package/dist/response.js.map +1 -0
  135. package/dist/schema.d.ts +45 -0
  136. package/dist/schema.d.ts.map +1 -0
  137. package/dist/schema.js +43 -0
  138. package/dist/schema.js.map +1 -0
  139. package/dist/server-sent.d.ts +9 -0
  140. package/dist/server-sent.d.ts.map +1 -0
  141. package/dist/server-sent.js +74 -0
  142. package/dist/server-sent.js.map +1 -0
  143. package/dist/server-tools.d.ts +12 -0
  144. package/dist/server-tools.d.ts.map +1 -0
  145. package/dist/server-tools.js +71 -0
  146. package/dist/server-tools.js.map +1 -0
  147. package/dist/services/catalog.d.ts +19 -0
  148. package/dist/services/catalog.d.ts.map +1 -0
  149. package/dist/services/catalog.js +37 -0
  150. package/dist/services/catalog.js.map +1 -0
  151. package/dist/services/main.d.ts +23 -0
  152. package/dist/services/main.d.ts.map +1 -0
  153. package/dist/services/main.js +43 -0
  154. package/dist/services/main.js.map +1 -0
  155. package/dist/skills/folder.d.ts +32 -0
  156. package/dist/skills/folder.d.ts.map +1 -0
  157. package/dist/skills/folder.js +170 -0
  158. package/dist/skills/folder.js.map +1 -0
  159. package/dist/skills/frontmatter.d.ts +15 -0
  160. package/dist/skills/frontmatter.d.ts.map +1 -0
  161. package/dist/skills/frontmatter.js +92 -0
  162. package/dist/skills/frontmatter.js.map +1 -0
  163. package/dist/skills/index.d.ts +18 -0
  164. package/dist/skills/index.d.ts.map +1 -0
  165. package/dist/skills/index.js +18 -0
  166. package/dist/skills/index.js.map +1 -0
  167. package/dist/skills/kit.d.ts +39 -0
  168. package/dist/skills/kit.d.ts.map +1 -0
  169. package/dist/skills/kit.js +124 -0
  170. package/dist/skills/kit.js.map +1 -0
  171. package/dist/skills/skill.d.ts +67 -0
  172. package/dist/skills/skill.d.ts.map +1 -0
  173. package/dist/skills/skill.js +114 -0
  174. package/dist/skills/skill.js.map +1 -0
  175. package/dist/sse.d.ts +95 -0
  176. package/dist/sse.d.ts.map +1 -0
  177. package/dist/sse.js +117 -0
  178. package/dist/sse.js.map +1 -0
  179. package/dist/testing/FakeProvider.d.ts +85 -0
  180. package/dist/testing/FakeProvider.d.ts.map +1 -0
  181. package/dist/testing/FakeProvider.js +214 -0
  182. package/dist/testing/FakeProvider.js.map +1 -0
  183. package/dist/testing/index.d.ts +7 -0
  184. package/dist/testing/index.d.ts.map +1 -0
  185. package/dist/testing/index.js +7 -0
  186. package/dist/testing/index.js.map +1 -0
  187. package/dist/tool-modules.d.ts +17 -0
  188. package/dist/tool-modules.d.ts.map +1 -0
  189. package/dist/tool-modules.js +43 -0
  190. package/dist/tool-modules.js.map +1 -0
  191. package/dist/tools.d.ts +132 -0
  192. package/dist/tools.d.ts.map +1 -0
  193. package/dist/tools.js +250 -0
  194. package/dist/tools.js.map +1 -0
  195. package/dist/transport.d.ts +23 -0
  196. package/dist/transport.d.ts.map +1 -0
  197. package/dist/transport.js +83 -0
  198. package/dist/transport.js.map +1 -0
  199. package/dist/types.d.ts +397 -0
  200. package/dist/types.d.ts.map +1 -0
  201. package/dist/types.js +12 -0
  202. package/dist/types.js.map +1 -0
  203. package/package.json +97 -3
  204. package/src/Polaris.ts +304 -0
  205. package/src/PolarisClient.ts +828 -0
  206. package/src/PolarisProvider.ts +111 -0
  207. package/src/augmentations.ts +20 -0
  208. package/src/budget.ts +201 -0
  209. package/src/catalog/catalog.ts +180 -0
  210. package/src/catalog/discover.ts +234 -0
  211. package/src/catalog/index.ts +19 -0
  212. package/src/commands/index.ts +412 -0
  213. package/src/cost.ts +176 -0
  214. package/src/drivers/anthropic.ts +703 -0
  215. package/src/drivers/openai-compatible.ts +907 -0
  216. package/src/drivers/status.ts +30 -0
  217. package/src/errors.ts +202 -0
  218. package/src/extract.ts +214 -0
  219. package/src/index.ts +85 -0
  220. package/src/json-schema.ts +597 -0
  221. package/src/log.ts +86 -0
  222. package/src/mcp/client.ts +532 -0
  223. package/src/mcp/endpoint.ts +229 -0
  224. package/src/mcp/host.ts +140 -0
  225. package/src/mcp/http.ts +276 -0
  226. package/src/mcp/index.ts +51 -0
  227. package/src/mcp/manifest.ts +73 -0
  228. package/src/mcp/rpc.ts +197 -0
  229. package/src/mcp/stdio.ts +190 -0
  230. package/src/mcp/worker-main.ts +18 -0
  231. package/src/mcp/worker.ts +212 -0
  232. package/src/meter.ts +199 -0
  233. package/src/providers.ts +25 -0
  234. package/src/redact.ts +81 -0
  235. package/src/redis-budget.ts +85 -0
  236. package/src/response.ts +143 -0
  237. package/src/schema.ts +88 -0
  238. package/src/server-sent.ts +70 -0
  239. package/src/server-tools.ts +77 -0
  240. package/src/services/catalog.ts +43 -0
  241. package/src/services/main.ts +49 -0
  242. package/src/skills/folder.ts +231 -0
  243. package/src/skills/frontmatter.ts +92 -0
  244. package/src/skills/index.ts +38 -0
  245. package/src/skills/kit.ts +163 -0
  246. package/src/skills/skill.ts +171 -0
  247. package/src/sse.ts +194 -0
  248. package/src/testing/FakeProvider.ts +322 -0
  249. package/src/testing/index.ts +12 -0
  250. package/src/tool-modules.ts +49 -0
  251. package/src/tools.ts +399 -0
  252. package/src/transport.ts +107 -0
  253. package/src/types.ts +434 -0
@@ -0,0 +1,79 @@
1
+ /**
2
+ * PolarisProvider: binds the provider manager built from `config/polaris.ts`.
3
+ *
4
+ * register() binds `polaris.manager`, built on first resolve, unless the
5
+ * application bound its own first.
6
+ * boot() builds it and publishes it to `@c9up/polaris/services/main`;
7
+ * a missing or invalid config fails the boot here. Reads the
8
+ * tool catalog (`polaris.json`, written by `ream polaris:index`),
9
+ * binds it as `polaris.catalog` and publishes it to
10
+ * `@c9up/polaris/services/catalog`.
11
+ * shutdown() releases what it published, if it is still its own.
12
+ *
13
+ * Typed against the slice of ream's `AppContext` it uses rather than importing
14
+ * it, so ream stays an optional peer.
15
+ */
16
+ import { resolve } from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+ import "./augmentations.js";
19
+ import { Catalog } from "./catalog/catalog.js";
20
+ import { DEFAULT_MANIFEST } from "./catalog/discover.js";
21
+ import { E_POLARIS_MISSING_CONFIG } from "./errors.js";
22
+ import { Polaris, } from "./Polaris.js";
23
+ import { clearCatalog, getCatalog, setCatalog } from "./services/catalog.js";
24
+ import { clearPolaris, getPolaris, setPolaris } from "./services/main.js";
25
+ const TOKEN = "polaris.manager";
26
+ const CATALOG_TOKEN = "polaris.catalog";
27
+ export default class PolarisProvider {
28
+ #app;
29
+ #owned;
30
+ #ownedCatalog;
31
+ constructor(app) {
32
+ this.#app = app;
33
+ }
34
+ register() {
35
+ const container = this.#app.container;
36
+ if (container.has?.(TOKEN))
37
+ return;
38
+ container.singleton(TOKEN, () => {
39
+ const config = this.#app.config.get("polaris");
40
+ if (config === undefined)
41
+ throw new E_POLARIS_MISSING_CONFIG();
42
+ return new Polaris(config);
43
+ });
44
+ }
45
+ async boot() {
46
+ const manager = await this.#app.container.resolve(TOKEN);
47
+ this.#owned = manager;
48
+ setPolaris(manager);
49
+ const config = this.#app.config.get("polaris");
50
+ const options = config?.catalog;
51
+ if (options === false)
52
+ return;
53
+ const manifest = typeof options === "object" &&
54
+ options !== null &&
55
+ "manifest" in options &&
56
+ typeof options.manifest === "string"
57
+ ? options.manifest
58
+ : DEFAULT_MANIFEST;
59
+ const root = this.#app.appRoot === undefined
60
+ ? process.cwd()
61
+ : fileURLToPath(this.#app.appRoot);
62
+ const catalog = await Catalog.read(resolve(root, manifest));
63
+ this.#ownedCatalog = catalog;
64
+ this.#app.container.singleton(CATALOG_TOKEN, () => catalog);
65
+ setCatalog(catalog);
66
+ }
67
+ async shutdown() {
68
+ if (this.#owned !== undefined && getPolaris() === this.#owned) {
69
+ clearPolaris();
70
+ }
71
+ this.#owned = undefined;
72
+ if (this.#ownedCatalog !== undefined &&
73
+ getCatalog() === this.#ownedCatalog) {
74
+ clearCatalog();
75
+ }
76
+ this.#ownedCatalog = undefined;
77
+ }
78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IAAI,UAAU,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YAC/D,YAAY,EAAE,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IACC,IAAI,CAAC,aAAa,KAAK,SAAS;YAChC,UAAU,EAAE,KAAK,IAAI,CAAC,aAAa,EAClC,CAAC;YACF,YAAY,EAAE,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;IAChC,CAAC;CACD"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Tell ream's `ContainerBindings` what `container.resolve('polaris.manager')`
3
+ * and `container.resolve('polaris.catalog')` return. Loaded from the package barrel and from the provider, so an
4
+ * application writes no `declare module` of its own for it.
5
+ *
6
+ * Type-only: ream stays an optional peer.
7
+ */
8
+ import type { Catalog } from "./catalog/catalog.js";
9
+ import type { PolarisService } from "./Polaris.js";
10
+ declare module "@c9up/ream/types" {
11
+ interface ContainerBindings {
12
+ /** The provider manager, bound by `PolarisProvider`. */
13
+ "polaris.manager": PolarisService;
14
+ /** The tool and skill catalog, read from `polaris.json` by `PolarisProvider`. */
15
+ "polaris.catalog": Catalog;
16
+ }
17
+ }
18
+ //# sourceMappingURL=augmentations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentations.d.ts","sourceRoot":"","sources":["../src/augmentations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,QAAQ,kBAAkB,CAAC;IACjC,UAAU,iBAAiB;QAC1B,wDAAwD;QACxD,iBAAiB,EAAE,cAAc,CAAC;QAClC,iFAAiF;QACjF,iBAAiB,EAAE,OAAO,CAAC;KAC3B;CACD"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Tell ream's `ContainerBindings` what `container.resolve('polaris.manager')`
3
+ * and `container.resolve('polaris.catalog')` return. Loaded from the package barrel and from the provider, so an
4
+ * application writes no `declare module` of its own for it.
5
+ *
6
+ * Type-only: ream stays an optional peer.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=augmentations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentations.js","sourceRoot":"","sources":["../src/augmentations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Spending limits per scope (a user, a tenant), enforced before a request is
3
+ * sent.
4
+ *
5
+ * A request reserves its estimated cost first: the reservation is added to
6
+ * the scope's spend, and if the total goes past the limit the reservation is
7
+ * taken back and the request refused, before anything leaves the server.
8
+ * Once the reply is in, the reservation is replaced by the real cost.
9
+ * Reserving rather than reading the spend is what keeps two requests sent at
10
+ * the same moment from passing the limit together.
11
+ */
12
+ /**
13
+ * Where spend is kept. `add` must be atomic (a Redis `INCRBY`, an SQL
14
+ * `UPDATE … SET spent = spent + ?`): it is what reservations rely on.
15
+ */
16
+ export interface BudgetStore {
17
+ /**
18
+ * Add `amount` (a decimal string, possibly negative) to `key`, and answer
19
+ * the new total. `key` is the scope, followed by its period when the
20
+ * budget has one (`user:42@2026-12`). `expiresAt` (epoch milliseconds),
21
+ * given with a period, is when the key may be dropped: a store that keeps
22
+ * it for ever counts right, but grows with every period.
23
+ */
24
+ add(key: string, amount: string, expiresAt?: number): Promise<string>;
25
+ /**
26
+ * The decimals the store keeps, when it rounds what it adds (the Redis
27
+ * store keeps 9). A reservation then rounds its estimate and the final
28
+ * cost once each, half up, and moves the spend by their difference: what
29
+ * a request leaves in the store is its cost rounded once, whatever its
30
+ * estimate was. Rounding the estimate and the correction separately would
31
+ * not add up, and could undercount the spend. Leave it out for a store
32
+ * that keeps every decimal.
33
+ */
34
+ readonly decimals?: number;
35
+ }
36
+ /** How long spend counts before it starts again at zero, in UTC. */
37
+ export type BudgetPeriod = "day" | "month";
38
+ export interface BudgetConfig {
39
+ /** The limit of a scope, as a decimal string in the pricing currency; `undefined` for none. */
40
+ readonly limit: {
41
+ readonly [scope: string]: string;
42
+ } | ((scope: string) => string | undefined | Promise<string | undefined>);
43
+ /**
44
+ * Count spend per day or per month (UTC), from zero at the start of each.
45
+ * Default: no period, spend counts for as long as the store keeps it.
46
+ */
47
+ readonly period?: BudgetPeriod;
48
+ /** Where spend is kept. Default: in memory, for one process and its lifetime. */
49
+ readonly store?: BudgetStore;
50
+ }
51
+ /** A spend store in memory: one process, lost on restart. For tests and a single instance. */
52
+ export declare function memoryBudgetStore(): BudgetStore;
53
+ /** The key a scope's spend is kept under at `now`, and when that key may go. */
54
+ export declare function periodKey(scope: string, period: BudgetPeriod | undefined, now?: number): {
55
+ readonly key: string;
56
+ readonly expiresAt?: number;
57
+ };
58
+ /** What a reservation hands back to settle it. */
59
+ export interface Reservation {
60
+ /** Replace the reservation by what the request really cost. */
61
+ settle(cost: string): Promise<void>;
62
+ /** Take the whole reservation back (the request was never answered). */
63
+ release(): Promise<void>;
64
+ }
65
+ /** Resolve the limit of `scope`. */
66
+ export declare function limitOf(config: BudgetConfig, scope: string): Promise<string | undefined>;
67
+ /**
68
+ * Reserve `estimate` on `scope` for the current `period`, or refuse with
69
+ * `E_POLARIS_BUDGET_EXCEEDED` when that would go past `limit`. With no limit,
70
+ * nothing is reserved.
71
+ *
72
+ * The reservation keeps the key of the period it was made in: settled after
73
+ * midnight, it still lands on the day it counted against, and a reservation
74
+ * whose process died never settles but goes with its period's key.
75
+ */
76
+ export declare function reserve(store: BudgetStore, scope: string, limit: string | undefined, estimate: string, period?: BudgetPeriod): Promise<Reservation>;
77
+ //# sourceMappingURL=budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EA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AAC,CAM7B;AAED;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAC5B,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,YAAY,GACnB,OAAO,CAAC,WAAW,CAAC,CA4BtB"}
package/dist/budget.js ADDED
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Spending limits per scope (a user, a tenant), enforced before a request is
3
+ * sent.
4
+ *
5
+ * A request reserves its estimated cost first: the reservation is added to
6
+ * the scope's spend, and if the total goes past the limit the reservation is
7
+ * taken back and the request refused, before anything leaves the server.
8
+ * Once the reply is in, the reservation is replaced by the real cost.
9
+ * Reserving rather than reading the spend is what keeps two requests sent at
10
+ * the same moment from passing the limit together.
11
+ */
12
+ import { decimal } from "@c9up/atom";
13
+ import { add, exceeds, isZero, subtract } from "./cost.js";
14
+ import { E_POLARIS_BUDGET_EXCEEDED, E_POLARIS_INVALID_CONFIG, } from "./errors.js";
15
+ /** A spend store in memory: one process, lost on restart. For tests and a single instance. */
16
+ export function memoryBudgetStore() {
17
+ const spent = new Map();
18
+ // Expired keys are swept at most once per expiry passed, not on every add.
19
+ let nextSweep = Number.POSITIVE_INFINITY;
20
+ return {
21
+ async add(key, amount, expiresAt) {
22
+ const now = Date.now();
23
+ if (now >= nextSweep) {
24
+ nextSweep = Number.POSITIVE_INFINITY;
25
+ for (const [name, entry] of spent) {
26
+ if (entry.expiresAt === undefined)
27
+ continue;
28
+ if (entry.expiresAt <= now)
29
+ spent.delete(name);
30
+ else
31
+ nextSweep = Math.min(nextSweep, entry.expiresAt);
32
+ }
33
+ }
34
+ const total = add(spent.get(key)?.total ?? "0", amount);
35
+ spent.set(key, {
36
+ total,
37
+ ...(expiresAt !== undefined ? { expiresAt } : {}),
38
+ });
39
+ if (expiresAt !== undefined)
40
+ nextSweep = Math.min(nextSweep, expiresAt);
41
+ return total;
42
+ },
43
+ };
44
+ }
45
+ /**
46
+ * How long a period's spend is kept after the period ends: long enough for a
47
+ * request sent just before midnight to settle into the period it reserved on.
48
+ */
49
+ const GRACE_MS = 24 * 60 * 60 * 1000;
50
+ /** The key a scope's spend is kept under at `now`, and when that key may go. */
51
+ export function periodKey(scope, period, now = Date.now()) {
52
+ if (period === undefined)
53
+ return { key: scope };
54
+ const date = new Date(now);
55
+ const year = date.getUTCFullYear();
56
+ const month = date.getUTCMonth();
57
+ const day = date.getUTCDate();
58
+ const pad = (value) => String(value).padStart(2, "0");
59
+ const label = period === "month"
60
+ ? `${year}-${pad(month + 1)}`
61
+ : `${year}-${pad(month + 1)}-${pad(day)}`;
62
+ const end = period === "month"
63
+ ? Date.UTC(year, month + 1, 1)
64
+ : Date.UTC(year, month, day + 1);
65
+ return { key: `${scope}@${label}`, expiresAt: end + GRACE_MS };
66
+ }
67
+ const NOTHING = {
68
+ settle: async () => undefined,
69
+ release: async () => undefined,
70
+ };
71
+ /** Resolve the limit of `scope`. */
72
+ export async function limitOf(config, scope) {
73
+ return typeof config.limit === "function"
74
+ ? config.limit(scope)
75
+ : Object.hasOwn(config.limit, scope)
76
+ ? config.limit[scope]
77
+ : undefined;
78
+ }
79
+ /**
80
+ * Reserve `estimate` on `scope` for the current `period`, or refuse with
81
+ * `E_POLARIS_BUDGET_EXCEEDED` when that would go past `limit`. With no limit,
82
+ * nothing is reserved.
83
+ *
84
+ * The reservation keeps the key of the period it was made in: settled after
85
+ * midnight, it still lands on the day it counted against, and a reservation
86
+ * whose process died never settles but goes with its period's key.
87
+ */
88
+ export async function reserve(store, scope, limit, estimate, period) {
89
+ if (limit === undefined)
90
+ return NOTHING;
91
+ const round = rounding(store.decimals);
92
+ const reserved = round(estimate);
93
+ const { key, expiresAt } = periodKey(scope, period);
94
+ const move = (amount) => expiresAt === undefined
95
+ ? store.add(key, amount)
96
+ : store.add(key, amount, expiresAt);
97
+ const total = await move(reserved);
98
+ if (exceeds(total, limit)) {
99
+ await move(negate(reserved));
100
+ throw new E_POLARIS_BUDGET_EXCEEDED([scope, limit]);
101
+ }
102
+ let open = true;
103
+ return {
104
+ async settle(cost) {
105
+ if (!open)
106
+ return;
107
+ open = false;
108
+ const difference = subtract(round(cost), reserved);
109
+ if (!isZero(difference))
110
+ await move(difference);
111
+ },
112
+ async release() {
113
+ if (!open)
114
+ return;
115
+ open = false;
116
+ await move(negate(reserved));
117
+ },
118
+ };
119
+ }
120
+ /** Round an amount to the decimals a store keeps, or leave it as it is. */
121
+ function rounding(decimals) {
122
+ if (decimals === undefined)
123
+ return (amount) => amount;
124
+ if (!Number.isSafeInteger(decimals) || decimals < 0) {
125
+ throw new E_POLARIS_INVALID_CONFIG([
126
+ "budget.store.decimals must be a non-negative integer",
127
+ ]);
128
+ }
129
+ return (amount) => decimal(amount).toFixed(decimals, "half-up");
130
+ }
131
+ function negate(amount) {
132
+ return subtract("0", amount);
133
+ }
134
+ //# sourceMappingURL=budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budget.js","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EACN,yBAAyB,EACzB,wBAAwB,GACxB,MAAM,aAAa,CAAC;AA4CrB,8FAA8F;AAC9F,MAAM,UAAU,iBAAiB;IAChC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAiD,CAAC;IACvE,2EAA2E;IAC3E,IAAI,SAAS,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACzC,OAAO;QACN,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS;YAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,IAAI,GAAG,IAAI,SAAS,EAAE,CAAC;gBACtB,S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,CAAC,UAAU,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,CAAC,OAAO;YACZ,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,IAAI,GAAG,KAAK,CAAC;YACb,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9B,CAAC;KACD,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,SAAS,QAAQ,CAAC,QAA4B;IAC7C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;IACtD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,wBAAwB,CAAC;YAClC,sDAAsD;SACtD,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,MAAM,CAAC,MAAc;IAC7B,OAAO,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The application's tools and skills, read from `polaris.json`. A run is
3
+ * given them by name; only the modules of the tools asked for are imported.
4
+ *
5
+ * const tools = await catalog.tools(['canton_rate'])
6
+ * const skills = useSkills(await catalog.skills(['payroll']))
7
+ */
8
+ import { type ReadSkillOptions } from "../skills/folder.js";
9
+ import type { PolarisSkill } from "../skills/skill.js";
10
+ import type { PolarisTool } from "../tools.js";
11
+ import type { CatalogManifest, CatalogSkill, CatalogTool } from "./discover.js";
12
+ export declare class Catalog {
13
+ #private;
14
+ /** Paths in `manifest` are relative to `base`. */
15
+ constructor(manifest: CatalogManifest, base: string, path?: string);
16
+ /**
17
+ * Read a manifest. A file that does not exist gives an empty catalog,
18
+ * which says so when a name is asked of it; one that is not a manifest
19
+ * throws `E_POLARIS_INVALID_CATALOG`.
20
+ */
21
+ static read(path: string): Promise<Catalog>;
22
+ /** The tools found, by name and description, without importing them. */
23
+ get toolList(): readonly CatalogTool[];
24
+ /** The skills found, by name and description, without reading them. */
25
+ get skillList(): readonly CatalogSkill[];
26
+ /**
27
+ * The tools named, in that order; all of them when no name is given. Each
28
+ * module is imported once, on the first call that needs it.
29
+ */
30
+ tools(names?: readonly string[]): Promise<PolarisTool[]>;
31
+ /**
32
+ * The skills named, in that order; all of them when no name is given.
33
+ * Each is read from its folder on every call (see `readSkill`).
34
+ */
35
+ skills(names?: readonly string[], options?: ReadSkillOptions): Promise<PolarisSkill[]>;
36
+ }
37
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/catalog/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA+BhF,qBAAa,OAAO;;IAOnB,kDAAkD;gBACtC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAMlE;;;;OAIG;WACU,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBjD,wEAAwE;IACxE,IAAI,QAAQ,IAAI,SAAS,WAAW,EAAE,CAErC;IAED,uEAAuE;IACvE,IAAI,SAAS,IAAI,SAAS,YAAY,EAAE,CAEvC;IAYD;;;OAGG;IACG,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAwC9D;;;OAGG;IACG,MAAM,CACX,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,YAAY,EAAE,CAAC;CAe1B"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * The application's tools and skills, read from `polaris.json`. A run is
3
+ * given them by name; only the modules of the tools asked for are imported.
4
+ *
5
+ * const tools = await catalog.tools(['canton_rate'])
6
+ * const skills = useSkills(await catalog.skills(['payroll']))
7
+ */
8
+ import { existsSync } from "node:fs";
9
+ import { readFile } from "node:fs/promises";
10
+ import { dirname, resolve } from "node:path";
11
+ import { pathToFileURL } from "node:url";
12
+ import { E_POLARIS_INVALID_CATALOG } from "../errors.js";
13
+ import { isObject } from "../mcp/rpc.js";
14
+ import { readSkill } from "../skills/folder.js";
15
+ import { importToolModule } from "../tool-modules.js";
16
+ const REINDEX = "run `ream polaris:index`";
17
+ const isEntry = (value, path) => isObject(value) &&
18
+ typeof value.name === "string" &&
19
+ typeof value.description === "string" &&
20
+ typeof value[path] === "string";
21
+ function isManifest(value) {
22
+ return (isObject(value) &&
23
+ value.version === 1 &&
24
+ Array.isArray(value.tools) &&
25
+ value.tools.every((entry) => isEntry(entry, "module")) &&
26
+ Array.isArray(value.skills) &&
27
+ value.skills.every((entry) => isEntry(entry, "folder")));
28
+ }
29
+ /**
30
+ * A module's path as written, or its build output: in a build, `polaris.json`
31
+ * is copied beside the compiled code, where `x.ts` became `x.js`.
32
+ */
33
+ function compiled(path) {
34
+ if (existsSync(path))
35
+ return path;
36
+ const built = path.replace(/\.ts$/, ".js").replace(/\.mts$/, ".mjs");
37
+ return existsSync(built) ? built : path;
38
+ }
39
+ export class Catalog {
40
+ #manifest;
41
+ #base;
42
+ /** The manifest's path, for messages; `undefined` when there was none. */
43
+ #path;
44
+ #modules = new Map();
45
+ /** Paths in `manifest` are relative to `base`. */
46
+ constructor(manifest, base, path) {
47
+ this.#manifest = manifest;
48
+ this.#base = base;
49
+ this.#path = path;
50
+ }
51
+ /**
52
+ * Read a manifest. A file that does not exist gives an empty catalog,
53
+ * which says so when a name is asked of it; one that is not a manifest
54
+ * throws `E_POLARIS_INVALID_CATALOG`.
55
+ */
56
+ static async read(path) {
57
+ const absolute = resolve(path);
58
+ let text;
59
+ try {
60
+ text = await readFile(absolute, "utf8");
61
+ }
62
+ catch {
63
+ return new Catalog({ version: 1, tools: [], skills: [] }, dirname(absolute));
64
+ }
65
+ let manifest;
66
+ try {
67
+ manifest = JSON.parse(text);
68
+ }
69
+ catch {
70
+ manifest = undefined;
71
+ }
72
+ if (!isManifest(manifest)) {
73
+ throw new E_POLARIS_INVALID_CATALOG([
74
+ `'${path}' is not a polaris manifest; ${REINDEX}`,
75
+ ]);
76
+ }
77
+ return new Catalog(manifest, dirname(absolute), path);
78
+ }
79
+ /** The tools found, by name and description, without importing them. */
80
+ get toolList() {
81
+ return this.#manifest.tools;
82
+ }
83
+ /** The skills found, by name and description, without reading them. */
84
+ get skillList() {
85
+ return this.#manifest.skills;
86
+ }
87
+ #missing(kind, name) {
88
+ const where = this.#path === undefined
89
+ ? `no manifest was found; ${REINDEX}`
90
+ : `'${this.#path}' lists none; ${REINDEX} after adding one`;
91
+ throw new E_POLARIS_INVALID_CATALOG([
92
+ `no ${kind} is named '${name.slice(0, 64)}': ${where}`,
93
+ ]);
94
+ }
95
+ /**
96
+ * The tools named, in that order; all of them when no name is given. Each
97
+ * module is imported once, on the first call that needs it.
98
+ */
99
+ async tools(names) {
100
+ const entries = names === undefined
101
+ ? this.#manifest.tools
102
+ : names.map((name) => this.#manifest.tools.find((tool) => tool.name === name) ??
103
+ this.#missing("tool", name));
104
+ const tools = [];
105
+ for (const entry of entries) {
106
+ const exported = await this.#module(entry.module);
107
+ const tool = exported.find((item) => item.name === entry.name);
108
+ if (tool === undefined) {
109
+ throw new E_POLARIS_INVALID_CATALOG([
110
+ `'${entry.module}' no longer exports the tool '${entry.name}'; ${REINDEX}`,
111
+ ]);
112
+ }
113
+ tools.push(tool);
114
+ }
115
+ return tools;
116
+ }
117
+ #module(module) {
118
+ let loading = this.#modules.get(module);
119
+ if (loading === undefined) {
120
+ const url = pathToFileURL(compiled(resolve(this.#base, module))).href;
121
+ loading = importToolModule(url).then((found) => {
122
+ if (typeof found === "string") {
123
+ throw new E_POLARIS_INVALID_CATALOG([`'${module}' ${found}`]);
124
+ }
125
+ return found;
126
+ });
127
+ // A failed import is tried again on the next call, not remembered.
128
+ loading.catch(() => this.#modules.delete(module));
129
+ this.#modules.set(module, loading);
130
+ }
131
+ return loading;
132
+ }
133
+ /**
134
+ * The skills named, in that order; all of them when no name is given.
135
+ * Each is read from its folder on every call (see `readSkill`).
136
+ */
137
+ async skills(names, options) {
138
+ const entries = names === undefined
139
+ ? this.#manifest.skills
140
+ : names.map((name) => this.#manifest.skills.find((skill) => skill.name === name) ??
141
+ this.#missing("skill", name));
142
+ return Promise.all(entries.map((entry) => readSkill(resolve(this.#base, entry.folder), options)));
143
+ }
144
+ }
145
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/catalog/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAyB,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,MAAM,OAAO,GAAG,0BAA0B,C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AC,OAAO,EAAE,IAAI,CAAC,CAC7B,CAAC;QACL,OAAO,OAAO,CAAC,GAAG,CACjB,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACrB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CACrD,CACD,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Finding the application's tools and skills by convention: the folders and
3
+ * files its glob patterns match. `ream polaris:index` runs this at build and
4
+ * writes the result, `polaris.json`, so the running application reads a list
5
+ * instead of importing every tool module to learn its name.
6
+ */
7
+ /** `catalog` in `config/polaris.ts`. Paths are relative to the application. */
8
+ export interface CatalogConfig {
9
+ /**
10
+ * Glob patterns of tool folders or tool files. A folder holds tool
11
+ * modules; a file is one. Default `['app/tools']`; a modular application
12
+ * names its modules: `['app/modules/*\/tools', 'app/modules/*\/http/*_tool.ts']`.
13
+ */
14
+ readonly tools?: readonly string[];
15
+ /**
16
+ * Glob patterns of skill folders: a folder with a `SKILL.md` is a skill,
17
+ * another holds skills, one per sub-folder. Default `['resources/skills']`.
18
+ */
19
+ readonly skills?: readonly string[];
20
+ /** Where `ream polaris:index` writes the list. Default `polaris.json`. */
21
+ readonly manifest?: string;
22
+ }
23
+ export declare const DEFAULT_TOOL_PATTERNS: readonly string[];
24
+ export declare const DEFAULT_SKILL_PATTERNS: readonly string[];
25
+ export declare const DEFAULT_MANIFEST = "polaris.json";
26
+ /** What `polaris.json` holds. Paths are relative to it, with `/`. */
27
+ export interface CatalogManifest {
28
+ readonly version: 1;
29
+ readonly tools: readonly CatalogTool[];
30
+ readonly skills: readonly CatalogSkill[];
31
+ }
32
+ export interface CatalogTool {
33
+ readonly name: string;
34
+ readonly description: string;
35
+ /** The module that exports it. */
36
+ readonly module: string;
37
+ }
38
+ export interface CatalogSkill {
39
+ readonly name: string;
40
+ readonly description: string;
41
+ /** The folder that holds its `SKILL.md`. */
42
+ readonly folder: string;
43
+ }
44
+ export interface IndexCatalogOptions extends CatalogConfig {
45
+ /** The application's root. Default the current directory. */
46
+ readonly root?: string;
47
+ }
48
+ /**
49
+ * Find the tools and skills the patterns lead to, importing each tool module
50
+ * and reading each `SKILL.md` once. Throws `E_POLARIS_INVALID_CATALOG` when a
51
+ * module exports no tools, or when two tools or two skills share a name,
52
+ * naming both files; `E_POLARIS_INVALID_SKILL` for a skill folder that
53
+ * cannot be read. Paths in the result are relative to `base`.
54
+ */
55
+ export declare function indexCatalog(options?: IndexCatalogOptions, base?: string): Promise<CatalogManifest>;
56
+ /**
57
+ * {@link indexCatalog}, written to the manifest (`polaris.json` at the root
58
+ * unless `manifest` says otherwise). Returns the manifest and its path.
59
+ */
60
+ export declare function writeCatalog(options?: IndexCatalogOptions): Promise<{
61
+ manifest: CatalogManifest;
62
+ path: string;
63
+ }>;
64
+ //# sourceMappingURL=discover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../src/catalog/discover.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH,+EAA+E;AAC/E,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAkB,CAAC;AACtE,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAAyB,CAAC;AAC9E,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,S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