@nookplot/runtime 0.5.145 → 0.5.147

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 (153) hide show
  1. package/dist/__tests__/apiMarketplace.test.js +2 -189
  2. package/dist/__tests__/apiMarketplace.test.js.map +1 -1
  3. package/dist/__tests__/autonomous.dedup.test.js +0 -11
  4. package/dist/__tests__/autonomous.dedup.test.js.map +1 -1
  5. package/dist/__tests__/autonomous.getAvailableActions.test.js +1 -13
  6. package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -1
  7. package/dist/__tests__/autonomous.v11OpenSignals.test.js +10 -0
  8. package/dist/__tests__/autonomous.v11OpenSignals.test.js.map +1 -1
  9. package/dist/__tests__/bdAgentPack.test.js +1 -1
  10. package/dist/__tests__/bdAgentPack.test.js.map +1 -1
  11. package/dist/__tests__/bounties.test.js +0 -12
  12. package/dist/__tests__/bounties.test.js.map +1 -1
  13. package/dist/__tests__/codegen-drift.test.js +1 -3
  14. package/dist/__tests__/codegen-drift.test.js.map +1 -1
  15. package/dist/__tests__/conversation/modelThresholdsParity.test.js +14 -19
  16. package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -1
  17. package/dist/__tests__/economy.frontierInference.test.d.ts +2 -0
  18. package/dist/__tests__/economy.frontierInference.test.d.ts.map +1 -0
  19. package/dist/__tests__/economy.frontierInference.test.js +61 -0
  20. package/dist/__tests__/economy.frontierInference.test.js.map +1 -0
  21. package/dist/__tests__/economy.surplusBranch.test.js +2 -66
  22. package/dist/__tests__/economy.surplusBranch.test.js.map +1 -1
  23. package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
  24. package/dist/__tests__/helpers/mockRuntime.js +0 -7
  25. package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
  26. package/dist/__tests__/pack.test.js +14 -14
  27. package/dist/__tests__/packLoader.test.js +4 -4
  28. package/dist/__tests__/presetLoader.test.js +42 -42
  29. package/dist/__tests__/sandbox.test.js +24 -24
  30. package/dist/__tests__/surplusInference.test.js +54 -8
  31. package/dist/__tests__/surplusInference.test.js.map +1 -1
  32. package/dist/actionCatalog.d.ts.map +1 -1
  33. package/dist/actionCatalog.generated.d.ts +1 -1
  34. package/dist/actionCatalog.generated.d.ts.map +1 -1
  35. package/dist/actionCatalog.generated.js +27 -152
  36. package/dist/actionCatalog.generated.js.map +1 -1
  37. package/dist/actionCatalog.js +10 -0
  38. package/dist/actionCatalog.js.map +1 -1
  39. package/dist/api-marketplace.d.ts +0 -146
  40. package/dist/api-marketplace.d.ts.map +1 -1
  41. package/dist/api-marketplace.js +0 -218
  42. package/dist/api-marketplace.js.map +1 -1
  43. package/dist/autonomous.d.ts +9 -16
  44. package/dist/autonomous.d.ts.map +1 -1
  45. package/dist/autonomous.js +59 -276
  46. package/dist/autonomous.js.map +1 -1
  47. package/dist/bounties.d.ts +0 -8
  48. package/dist/bounties.d.ts.map +1 -1
  49. package/dist/bounties.js +0 -2
  50. package/dist/bounties.js.map +1 -1
  51. package/dist/contentSafety.d.ts +1 -1
  52. package/dist/contentSafety.d.ts.map +1 -1
  53. package/dist/contentSafety.js +2 -6
  54. package/dist/contentSafety.js.map +1 -1
  55. package/dist/conversation/modelLimits.js +17 -17
  56. package/dist/discovery.js +1 -1
  57. package/dist/discovery.js.map +1 -1
  58. package/dist/economy.d.ts +15 -10
  59. package/dist/economy.d.ts.map +1 -1
  60. package/dist/economy.js +29 -16
  61. package/dist/economy.js.map +1 -1
  62. package/dist/frontierPass.d.ts +30 -0
  63. package/dist/frontierPass.d.ts.map +1 -0
  64. package/dist/frontierPass.js +42 -0
  65. package/dist/frontierPass.js.map +1 -0
  66. package/dist/identity.d.ts +0 -51
  67. package/dist/identity.d.ts.map +1 -1
  68. package/dist/identity.js +0 -50
  69. package/dist/identity.js.map +1 -1
  70. package/dist/index.d.ts +3 -18
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +2 -15
  73. package/dist/index.js.map +1 -1
  74. package/dist/inference/surplusInference.d.ts +29 -1
  75. package/dist/inference/surplusInference.d.ts.map +1 -1
  76. package/dist/inference/surplusInference.js +132 -15
  77. package/dist/inference/surplusInference.js.map +1 -1
  78. package/dist/signalActionMap.d.ts.map +1 -1
  79. package/dist/signalActionMap.js +13 -15
  80. package/dist/signalActionMap.js.map +1 -1
  81. package/dist/swarms.d.ts +0 -13
  82. package/dist/swarms.d.ts.map +1 -1
  83. package/dist/swarms.js +0 -4
  84. package/dist/swarms.js.map +1 -1
  85. package/dist/tools.js +1 -1
  86. package/dist/tools.js.map +1 -1
  87. package/dist/types.d.ts +1 -22
  88. package/dist/types.d.ts.map +1 -1
  89. package/package.json +1 -1
  90. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts +0 -2
  91. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts.map +0 -1
  92. package/dist/__tests__/autonomous.goalBootstrap.test.js +0 -148
  93. package/dist/__tests__/autonomous.goalBootstrap.test.js.map +0 -1
  94. package/dist/__tests__/autonomous.miningTrack.test.d.ts +0 -2
  95. package/dist/__tests__/autonomous.miningTrack.test.d.ts.map +0 -1
  96. package/dist/__tests__/autonomous.miningTrack.test.js +0 -38
  97. package/dist/__tests__/autonomous.miningTrack.test.js.map +0 -1
  98. package/dist/__tests__/autonomous.payApi.test.d.ts +0 -2
  99. package/dist/__tests__/autonomous.payApi.test.d.ts.map +0 -1
  100. package/dist/__tests__/autonomous.payApi.test.js +0 -73
  101. package/dist/__tests__/autonomous.payApi.test.js.map +0 -1
  102. package/dist/__tests__/autonomous.workspaceOpportunity.test.d.ts +0 -2
  103. package/dist/__tests__/autonomous.workspaceOpportunity.test.d.ts.map +0 -1
  104. package/dist/__tests__/autonomous.workspaceOpportunity.test.js +0 -212
  105. package/dist/__tests__/autonomous.workspaceOpportunity.test.js.map +0 -1
  106. package/dist/__tests__/goalLoop.test.d.ts +0 -2
  107. package/dist/__tests__/goalLoop.test.d.ts.map +0 -1
  108. package/dist/__tests__/goalLoop.test.js +0 -358
  109. package/dist/__tests__/goalLoop.test.js.map +0 -1
  110. package/dist/__tests__/loadProfile.test.d.ts +0 -8
  111. package/dist/__tests__/loadProfile.test.d.ts.map +0 -1
  112. package/dist/__tests__/loadProfile.test.js +0 -134
  113. package/dist/__tests__/loadProfile.test.js.map +0 -1
  114. package/dist/__tests__/mining.test.d.ts +0 -2
  115. package/dist/__tests__/mining.test.d.ts.map +0 -1
  116. package/dist/__tests__/mining.test.js +0 -306
  117. package/dist/__tests__/mining.test.js.map +0 -1
  118. package/dist/__tests__/signalActionMap.test.d.ts +0 -17
  119. package/dist/__tests__/signalActionMap.test.d.ts.map +0 -1
  120. package/dist/__tests__/signalActionMap.test.js +0 -165
  121. package/dist/__tests__/signalActionMap.test.js.map +0 -1
  122. package/dist/__tests__/usdcBudget.test.d.ts +0 -2
  123. package/dist/__tests__/usdcBudget.test.d.ts.map +0 -1
  124. package/dist/__tests__/usdcBudget.test.js +0 -128
  125. package/dist/__tests__/usdcBudget.test.js.map +0 -1
  126. package/dist/__tests__/x402.test.d.ts +0 -2
  127. package/dist/__tests__/x402.test.d.ts.map +0 -1
  128. package/dist/__tests__/x402.test.js +0 -117
  129. package/dist/__tests__/x402.test.js.map +0 -1
  130. package/dist/goal/goalLoop.d.ts +0 -78
  131. package/dist/goal/goalLoop.d.ts.map +0 -1
  132. package/dist/goal/goalLoop.js +0 -388
  133. package/dist/goal/goalLoop.js.map +0 -1
  134. package/dist/goal/goalPrompts.d.ts +0 -20
  135. package/dist/goal/goalPrompts.d.ts.map +0 -1
  136. package/dist/goal/goalPrompts.js +0 -54
  137. package/dist/goal/goalPrompts.js.map +0 -1
  138. package/dist/goal/types.d.ts +0 -102
  139. package/dist/goal/types.d.ts.map +0 -1
  140. package/dist/goal/types.js +0 -7
  141. package/dist/goal/types.js.map +0 -1
  142. package/dist/loadProfile.d.ts +0 -100
  143. package/dist/loadProfile.d.ts.map +0 -1
  144. package/dist/loadProfile.js +0 -221
  145. package/dist/loadProfile.js.map +0 -1
  146. package/dist/usdcBudget.d.ts +0 -90
  147. package/dist/usdcBudget.d.ts.map +0 -1
  148. package/dist/usdcBudget.js +0 -155
  149. package/dist/usdcBudget.js.map +0 -1
  150. package/dist/x402.d.ts +0 -69
  151. package/dist/x402.d.ts.map +0 -1
  152. package/dist/x402.js +0 -139
  153. package/dist/x402.js.map +0 -1
@@ -1,100 +0,0 @@
1
- /**
2
- * Profile-aware credential loading for @nookplot/runtime.
3
- *
4
- * The SDK normally takes `{ apiKey, gatewayUrl }` at instantiation —
5
- * developers pass keys directly. This helper is for developers who want
6
- * the SDK to read from `~/.nookplot/` like @nookplot/cli and @nookplot/mcp
7
- * do, so a user running multiple forged agents can point the SDK at
8
- * whichever scope is active in their shell.
9
- *
10
- * Reads from the same files the rest of the Nookplot stack uses:
11
- * ~/.nookplot/credentials.json ← creator API key (shared)
12
- * ~/.nookplot/profiles/<name>/profile.json ← per-agent scope
13
- * ~/.nookplot/active-profile ← sticky default (CLI-written)
14
- *
15
- * Resolution order:
16
- * 1. Explicit `name` argument to loadProfile()
17
- * 2. NOOKPLOT_PROFILE env var
18
- * 3. Sticky default from ~/.nookplot/active-profile
19
- * 4. null (load default creds only, no scope)
20
- *
21
- * @module loadProfile
22
- *
23
- * @example Basic usage — pick up whatever profile is active
24
- * ```ts
25
- * import { NookplotRuntime } from "@nookplot/runtime";
26
- * import { loadProfile } from "@nookplot/runtime/loadProfile";
27
- *
28
- * const creds = loadProfile(); // respects NOOKPLOT_PROFILE env + sticky default
29
- * if (!creds) throw new Error("No credentials — run `nookplot register` first");
30
- *
31
- * const runtime = new NookplotRuntime({
32
- * apiKey: creds.apiKey,
33
- * gatewayUrl: creds.gatewayUrl,
34
- * });
35
- * ```
36
- *
37
- * @example Explicit profile override
38
- * ```ts
39
- * const creds = loadProfile("jeffs-researcher");
40
- * ```
41
- *
42
- * @example Multi-agent — run two SDK instances in parallel
43
- * ```ts
44
- * const researcherCreds = loadProfile("jeffs-researcher");
45
- * const writerCreds = loadProfile("jeffs-writer");
46
- *
47
- * const researcher = new NookplotRuntime({ apiKey: researcherCreds!.apiKey, ... });
48
- * const writer = new NookplotRuntime({ apiKey: writerCreds!.apiKey, ... });
49
- * // Both clients share the creator's API key but scope to different forged agents.
50
- * ```
51
- */
52
- export interface LoadedProfile {
53
- /** Creator's API key (shared across all forged agents owned by this creator). */
54
- apiKey: string;
55
- /** Creator's wallet address. */
56
- address: string;
57
- /** Creator's private key — only read if developer passes { requirePrivateKey }. */
58
- privateKey: string;
59
- /** Gateway base URL, honoring NOOKPLOT_GATEWAY_URL env if set. */
60
- gatewayUrl: string;
61
- /** Present when a profile was active — the forged agent's address to scope to. */
62
- scopedAgentAddress?: string;
63
- /** Present when a profile was active — the profile's name (for logging). */
64
- profileName?: string;
65
- /** Display name of the creator (not the scoped forged agent). */
66
- displayName?: string;
67
- }
68
- /**
69
- * Resolve the active profile name in priority order.
70
- * Exported for testing + for developers who want to see which profile
71
- * WOULD be used without actually loading credentials.
72
- */
73
- export declare function resolveActiveProfileName(explicitName?: string): string | null;
74
- /**
75
- * Load credentials, optionally merging a named profile's scope on top.
76
- *
77
- * Returns null if no `credentials.json` exists — the developer should
78
- * surface a clear "run `nookplot register` first" message in that case.
79
- *
80
- * Does not throw on invalid profiles — if the named profile doesn't
81
- * exist or is malformed, falls back to plain creator-direct credentials
82
- * (matches @nookplot/mcp's fail-open behavior so stale env vars don't
83
- * break unrelated commands).
84
- */
85
- export declare function loadProfile(name?: string): LoadedProfile | null;
86
- /**
87
- * List all profiles registered on the local machine. Each entry includes
88
- * the profile name + its metadata. Useful for SDK consumers who want to
89
- * enumerate the user's forged agents programmatically.
90
- *
91
- * Returns an empty array if ~/.nookplot/profiles doesn't exist. Never
92
- * throws — invalid profiles are silently skipped.
93
- */
94
- export declare function listProfiles(): Array<{
95
- name: string;
96
- scopedAgentAddress: string;
97
- displayName?: string;
98
- hermesProfile?: string;
99
- }>;
100
- //# sourceMappingURL=loadProfile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadProfile.d.ts","sourceRoot":"","sources":["../src/loadProfile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAMH,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAsBD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa7E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAwE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BhI"}
@@ -1,221 +0,0 @@
1
- /**
2
- * Profile-aware credential loading for @nookplot/runtime.
3
- *
4
- * The SDK normally takes `{ apiKey, gatewayUrl }` at instantiation —
5
- * developers pass keys directly. This helper is for developers who want
6
- * the SDK to read from `~/.nookplot/` like @nookplot/cli and @nookplot/mcp
7
- * do, so a user running multiple forged agents can point the SDK at
8
- * whichever scope is active in their shell.
9
- *
10
- * Reads from the same files the rest of the Nookplot stack uses:
11
- * ~/.nookplot/credentials.json ← creator API key (shared)
12
- * ~/.nookplot/profiles/<name>/profile.json ← per-agent scope
13
- * ~/.nookplot/active-profile ← sticky default (CLI-written)
14
- *
15
- * Resolution order:
16
- * 1. Explicit `name` argument to loadProfile()
17
- * 2. NOOKPLOT_PROFILE env var
18
- * 3. Sticky default from ~/.nookplot/active-profile
19
- * 4. null (load default creds only, no scope)
20
- *
21
- * @module loadProfile
22
- *
23
- * @example Basic usage — pick up whatever profile is active
24
- * ```ts
25
- * import { NookplotRuntime } from "@nookplot/runtime";
26
- * import { loadProfile } from "@nookplot/runtime/loadProfile";
27
- *
28
- * const creds = loadProfile(); // respects NOOKPLOT_PROFILE env + sticky default
29
- * if (!creds) throw new Error("No credentials — run `nookplot register` first");
30
- *
31
- * const runtime = new NookplotRuntime({
32
- * apiKey: creds.apiKey,
33
- * gatewayUrl: creds.gatewayUrl,
34
- * });
35
- * ```
36
- *
37
- * @example Explicit profile override
38
- * ```ts
39
- * const creds = loadProfile("jeffs-researcher");
40
- * ```
41
- *
42
- * @example Multi-agent — run two SDK instances in parallel
43
- * ```ts
44
- * const researcherCreds = loadProfile("jeffs-researcher");
45
- * const writerCreds = loadProfile("jeffs-writer");
46
- *
47
- * const researcher = new NookplotRuntime({ apiKey: researcherCreds!.apiKey, ... });
48
- * const writer = new NookplotRuntime({ apiKey: writerCreds!.apiKey, ... });
49
- * // Both clients share the creator's API key but scope to different forged agents.
50
- * ```
51
- */
52
- import { existsSync, readFileSync } from "node:fs";
53
- import { homedir } from "node:os";
54
- import { join } from "node:path";
55
- function nookplotDir() {
56
- return join(homedir(), ".nookplot");
57
- }
58
- function credentialsPath() {
59
- return join(nookplotDir(), "credentials.json");
60
- }
61
- function profilePath(name) {
62
- return join(nookplotDir(), "profiles", name, "profile.json");
63
- }
64
- function activeProfilePath() {
65
- return join(nookplotDir(), "active-profile");
66
- }
67
- /**
68
- * Resolve the active profile name in priority order.
69
- * Exported for testing + for developers who want to see which profile
70
- * WOULD be used without actually loading credentials.
71
- */
72
- export function resolveActiveProfileName(explicitName) {
73
- if (explicitName)
74
- return explicitName;
75
- const env = process.env.NOOKPLOT_PROFILE;
76
- if (env)
77
- return env;
78
- try {
79
- if (existsSync(activeProfilePath())) {
80
- const content = readFileSync(activeProfilePath(), "utf-8").trim();
81
- if (content)
82
- return content;
83
- }
84
- }
85
- catch {
86
- // Permissions error or disk issue — fall through
87
- }
88
- return null;
89
- }
90
- /**
91
- * Load credentials, optionally merging a named profile's scope on top.
92
- *
93
- * Returns null if no `credentials.json` exists — the developer should
94
- * surface a clear "run `nookplot register` first" message in that case.
95
- *
96
- * Does not throw on invalid profiles — if the named profile doesn't
97
- * exist or is malformed, falls back to plain creator-direct credentials
98
- * (matches @nookplot/mcp's fail-open behavior so stale env vars don't
99
- * break unrelated commands).
100
- */
101
- export function loadProfile(name) {
102
- // 1. Load base credentials — the shared creator API key.
103
- if (!existsSync(credentialsPath()))
104
- return null;
105
- let creds;
106
- try {
107
- creds = JSON.parse(readFileSync(credentialsPath(), "utf-8"));
108
- }
109
- catch {
110
- return null;
111
- }
112
- if (!creds.apiKey || !creds.address || !creds.privateKey || !creds.gatewayUrl) {
113
- return null;
114
- }
115
- // 2. Honor NOOKPLOT_GATEWAY_URL env if set (matches SDK + MCP convention).
116
- const gatewayUrl = process.env.NOOKPLOT_GATEWAY_URL ?? creds.gatewayUrl;
117
- // 3. Resolve profile (if any) and read its scope.
118
- const profileName = resolveActiveProfileName(name);
119
- if (!profileName) {
120
- return {
121
- apiKey: creds.apiKey,
122
- address: creds.address,
123
- privateKey: creds.privateKey,
124
- gatewayUrl,
125
- displayName: creds.displayName,
126
- };
127
- }
128
- const pPath = profilePath(profileName);
129
- if (!existsSync(pPath)) {
130
- // Stale profile reference — fall back to creator-direct. Matches
131
- // @nookplot/mcp's fail-open pattern.
132
- return {
133
- apiKey: creds.apiKey,
134
- address: creds.address,
135
- privateKey: creds.privateKey,
136
- gatewayUrl,
137
- displayName: creds.displayName,
138
- };
139
- }
140
- try {
141
- const p = JSON.parse(readFileSync(pPath, "utf-8"));
142
- if (typeof p.scopedAgentAddress !== "string" || p.scopedAgentAddress.length === 0) {
143
- // Malformed profile — fall back.
144
- return {
145
- apiKey: creds.apiKey,
146
- address: creds.address,
147
- privateKey: creds.privateKey,
148
- gatewayUrl,
149
- displayName: creds.displayName,
150
- };
151
- }
152
- return {
153
- apiKey: creds.apiKey,
154
- address: creds.address,
155
- privateKey: creds.privateKey,
156
- gatewayUrl,
157
- scopedAgentAddress: p.scopedAgentAddress,
158
- profileName,
159
- displayName: creds.displayName,
160
- };
161
- }
162
- catch {
163
- // JSON parse error on profile — fall back to creator-direct.
164
- return {
165
- apiKey: creds.apiKey,
166
- address: creds.address,
167
- privateKey: creds.privateKey,
168
- gatewayUrl,
169
- displayName: creds.displayName,
170
- };
171
- }
172
- }
173
- /**
174
- * List all profiles registered on the local machine. Each entry includes
175
- * the profile name + its metadata. Useful for SDK consumers who want to
176
- * enumerate the user's forged agents programmatically.
177
- *
178
- * Returns an empty array if ~/.nookplot/profiles doesn't exist. Never
179
- * throws — invalid profiles are silently skipped.
180
- */
181
- export function listProfiles() {
182
- const dir = join(nookplotDir(), "profiles");
183
- if (!existsSync(dir))
184
- return [];
185
- const out = [];
186
- try {
187
- const { readdirSync, statSync } = require("node:fs");
188
- for (const name of readdirSync(dir).sort()) {
189
- const full = join(dir, name);
190
- try {
191
- if (!statSync(full).isDirectory())
192
- continue;
193
- }
194
- catch {
195
- continue;
196
- }
197
- const pPath = join(full, "profile.json");
198
- if (!existsSync(pPath))
199
- continue;
200
- try {
201
- const p = JSON.parse(readFileSync(pPath, "utf-8"));
202
- if (typeof p.scopedAgentAddress !== "string")
203
- continue;
204
- out.push({
205
- name,
206
- scopedAgentAddress: p.scopedAgentAddress,
207
- displayName: p.displayName,
208
- hermesProfile: p.hermesProfile,
209
- });
210
- }
211
- catch {
212
- // Skip invalid profiles
213
- }
214
- }
215
- }
216
- catch {
217
- // Missing dir or perms — return empty
218
- }
219
- return out;
220
- }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,QAAQ,EAAE,GAAG,OAAO,CAAC,SAAS,CAA6B,CAAC;QACjF,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;oBAAE,SAAS;YAC9C,CAAC;YAAC,MAAM,CAAC;gBAAC,SAAS;YAAC,CAAC;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;YACzC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;gBAAE,SAAS;YACjC,IAAI,CAAC;gBACH,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAgB,CAAC;gBAClE,IAAI,OAAO,CAAC,CAAC,kBAAkB,KAAK,QAAQ;oBAAE,SAAS;gBACvD,GAAG,CAAC,IAAI,CAAC;oBACP,IAAI;oBACJ,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;oBACxC,WAAW,EAAE,CAAC,CAAC,WAAW;oBAC1B,aAAa,EAAE,CAAC,CAAC,aAAa;iBAC/B,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,sCAAsC;IACxC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,90 +0,0 @@
1
- /**
2
- * UsdcBudget — a hard-stop, rolling-window USDC spend cap for the per-call x402
3
- * `pay_api` action.
4
- *
5
- * A first-class sibling to the goal loop's `budgetNook`, with two deliberate
6
- * differences: it is **money-denominated** (USDC base units) and it **enforces**
7
- * (`budgetNook` is soft/warn-only — `goalLoop.ts:190`). One tracker per agent
8
- * process, hung off `runtime.usdcBudget`, so every `pay_api` dispatch site
9
- * (reactive + goal-loop, TS + the Python mirror) shares the SAME ledger and the
10
- * cap holds no matter which path spends.
11
- *
12
- * Enforcement model (zero overshoot):
13
- * 1. Before paying, a dispatch site asks `maxForNextCall()` for the largest
14
- * amount this call may spend (min of the per-call ceiling and remaining
15
- * daily headroom). It passes that as `payAndCall`'s `maxAmountBaseUnits`,
16
- * which aborts BEFORE signing if the 402 quote exceeds it.
17
- * 2. After a successful pay, the site `record()`s the exact amount.
18
- * 3. The goal loop reads `isExhausted()` and terminates with `blocked_budget`
19
- * once the daily cap is fully consumed (the consumer that finally makes the
20
- * `blocked_budget` outcome live — see `goal/types.ts`).
21
- *
22
- * Amounts are USDC base units (6 decimals): 1 USDC = 1_000_000n.
23
- * A `dailyCapBaseUnits` of 0n means "unlimited" (cap disabled); likewise 0n for
24
- * the per-call ceiling means "no per-call ceiling".
25
- *
26
- * @module usdcBudget
27
- */
28
- /** USDC has 6 decimals on Base. */
29
- export declare const USDC_DECIMALS = 6;
30
- /** Default daily cap when nothing is configured: $10/day. Conservative
31
- * safety net for a runaway buyer — operators raise it via `X402_DAILY_USDC_CAP`
32
- * (or `dailyCapBaseUnits: 0n` to disable). pay_api is the only consumer, so a
33
- * non-zero default never affects non-buying agents. */
34
- export declare const DEFAULT_DAILY_USDC_CAP_BASE_UNITS: bigint;
35
- export interface UsdcBudgetCheck {
36
- allowed: boolean;
37
- /** Human-readable reason when `allowed` is false. */
38
- reason?: string;
39
- /** Remaining daily headroom in base units; -1n when unlimited. */
40
- remainingBaseUnits: bigint;
41
- }
42
- export interface UsdcBudgetOptions {
43
- /** Daily cap in USDC base units. 0n = unlimited. Default: 10 USDC. */
44
- dailyCapBaseUnits?: bigint;
45
- /** Per-call ceiling in USDC base units. 0n = no per-call ceiling. Default: 0n. */
46
- perCallCapBaseUnits?: bigint;
47
- /** Rolling window length in ms (default 24h). */
48
- windowMs?: number;
49
- /** Clock injection for deterministic tests. Default `Date.now`. */
50
- now?: () => number;
51
- }
52
- /** Parse a USDC display amount ("10", "0.5") into base units. Returns 0n
53
- * (unlimited) for empty / non-positive / unparseable input. */
54
- export declare function parseUsdcToBaseUnits(display: string | undefined): bigint;
55
- /** Format base units as a `$x.xx` USDC string for log/agent messages. */
56
- export declare function formatUsdc(baseUnits: bigint): string;
57
- export declare class UsdcBudget {
58
- /** Daily cap in USDC base units. 0n = unlimited. */
59
- readonly dailyCapBaseUnits: bigint;
60
- /** Per-call ceiling in USDC base units. 0n = none. */
61
- readonly perCallCapBaseUnits: bigint;
62
- private readonly windowMs;
63
- private readonly now;
64
- private spentBaseUnits;
65
- private windowStartMs;
66
- constructor(opts?: UsdcBudgetOptions);
67
- /** Roll the spend window when the current 24h period has elapsed. */
68
- private roll;
69
- /** Pre-pay check for a known quote. Honors both the per-call ceiling and the
70
- * remaining daily headroom. */
71
- check(amountBaseUnits: bigint): UsdcBudgetCheck;
72
- /** The largest amount a single call may spend right now (min of per-call
73
- * ceiling and remaining daily headroom). `undefined` = unlimited. `0n` =
74
- * budget already exhausted (caller should not pay at all). */
75
- maxForNextCall(): bigint | undefined;
76
- /** Record a completed spend (call AFTER a successful payment). */
77
- record(amountBaseUnits: bigint): void;
78
- /** Remaining daily headroom in base units; -1n when unlimited. */
79
- remaining(): bigint;
80
- /** True when a daily cap is set and fully consumed — the goal loop's
81
- * `blocked_budget` trigger. Always false when unlimited. */
82
- isExhausted(): boolean;
83
- /** Spent-so-far in the current window (base units). */
84
- get spent(): bigint;
85
- }
86
- /** Build a UsdcBudget from explicit options falling back to env
87
- * (`X402_DAILY_USDC_CAP`, `X402_PER_CALL_USDC_CAP`, both USDC display units)
88
- * and finally the conservative default daily cap. */
89
- export declare function createUsdcBudget(opts?: UsdcBudgetOptions): UsdcBudget;
90
- //# sourceMappingURL=usdcBudget.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usdcBudget.d.ts","sourceRoot":"","sources":["../src/usdcBudget.ts"],"names":[],"mappings":"AAAA;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e,EAAE,MAAM,GAAG,IAAI;IAKrC,kEAAkE;IAClE,SAAS,IAAI,MAAM;IAOnB;iEAC6D;IAC7D,WAAW,IAAI,OAAO;IAMtB,uDAAuD;IACvD,IAAI,KAAK,IAAI,MAAM,CAGlB;CACF;AAED;;sDAEsD;AACtD,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,iBAAsB,GAAG,UAAU,CAWzE"}
@@ -1,155 +0,0 @@
1
- /**
2
- * UsdcBudget — a hard-stop, rolling-window USDC spend cap for the per-call x402
3
- * `pay_api` action.
4
- *
5
- * A first-class sibling to the goal loop's `budgetNook`, with two deliberate
6
- * differences: it is **money-denominated** (USDC base units) and it **enforces**
7
- * (`budgetNook` is soft/warn-only — `goalLoop.ts:190`). One tracker per agent
8
- * process, hung off `runtime.usdcBudget`, so every `pay_api` dispatch site
9
- * (reactive + goal-loop, TS + the Python mirror) shares the SAME ledger and the
10
- * cap holds no matter which path spends.
11
- *
12
- * Enforcement model (zero overshoot):
13
- * 1. Before paying, a dispatch site asks `maxForNextCall()` for the largest
14
- * amount this call may spend (min of the per-call ceiling and remaining
15
- * daily headroom). It passes that as `payAndCall`'s `maxAmountBaseUnits`,
16
- * which aborts BEFORE signing if the 402 quote exceeds it.
17
- * 2. After a successful pay, the site `record()`s the exact amount.
18
- * 3. The goal loop reads `isExhausted()` and terminates with `blocked_budget`
19
- * once the daily cap is fully consumed (the consumer that finally makes the
20
- * `blocked_budget` outcome live — see `goal/types.ts`).
21
- *
22
- * Amounts are USDC base units (6 decimals): 1 USDC = 1_000_000n.
23
- * A `dailyCapBaseUnits` of 0n means "unlimited" (cap disabled); likewise 0n for
24
- * the per-call ceiling means "no per-call ceiling".
25
- *
26
- * @module usdcBudget
27
- */
28
- /** USDC has 6 decimals on Base. */
29
- export const USDC_DECIMALS = 6;
30
- const USDC_ONE = 1000000n;
31
- /** Default daily cap when nothing is configured: $10/day. Conservative
32
- * safety net for a runaway buyer — operators raise it via `X402_DAILY_USDC_CAP`
33
- * (or `dailyCapBaseUnits: 0n` to disable). pay_api is the only consumer, so a
34
- * non-zero default never affects non-buying agents. */
35
- export const DEFAULT_DAILY_USDC_CAP_BASE_UNITS = 10n * USDC_ONE;
36
- const WINDOW_MS = 24 * 60 * 60 * 1000;
37
- /** Parse a USDC display amount ("10", "0.5") into base units. Returns 0n
38
- * (unlimited) for empty / non-positive / unparseable input. */
39
- export function parseUsdcToBaseUnits(display) {
40
- if (!display)
41
- return 0n;
42
- const trimmed = display.trim();
43
- if (!/^\d+(\.\d+)?$/.test(trimmed))
44
- return 0n;
45
- const [whole, frac = ""] = trimmed.split(".");
46
- const fracPadded = (frac + "000000").slice(0, USDC_DECIMALS);
47
- return BigInt(whole) * USDC_ONE + BigInt(fracPadded || "0");
48
- }
49
- /** Format base units as a `$x.xx` USDC string for log/agent messages. */
50
- export function formatUsdc(baseUnits) {
51
- const whole = baseUnits / USDC_ONE;
52
- const frac = (baseUnits % USDC_ONE).toString().padStart(USDC_DECIMALS, "0").replace(/0+$/, "");
53
- return frac ? `$${whole}.${frac}` : `$${whole}`;
54
- }
55
- export class UsdcBudget {
56
- /** Daily cap in USDC base units. 0n = unlimited. */
57
- dailyCapBaseUnits;
58
- /** Per-call ceiling in USDC base units. 0n = none. */
59
- perCallCapBaseUnits;
60
- windowMs;
61
- now;
62
- spentBaseUnits = 0n;
63
- windowStartMs;
64
- constructor(opts = {}) {
65
- this.dailyCapBaseUnits = opts.dailyCapBaseUnits ?? DEFAULT_DAILY_USDC_CAP_BASE_UNITS;
66
- this.perCallCapBaseUnits = opts.perCallCapBaseUnits ?? 0n;
67
- this.windowMs = opts.windowMs ?? WINDOW_MS;
68
- this.now = opts.now ?? (() => Date.now());
69
- this.windowStartMs = this.now();
70
- }
71
- /** Roll the spend window when the current 24h period has elapsed. */
72
- roll() {
73
- const t = this.now();
74
- if (t - this.windowStartMs >= this.windowMs) {
75
- this.spentBaseUnits = 0n;
76
- this.windowStartMs = t;
77
- }
78
- }
79
- /** Pre-pay check for a known quote. Honors both the per-call ceiling and the
80
- * remaining daily headroom. */
81
- check(amountBaseUnits) {
82
- this.roll();
83
- if (this.perCallCapBaseUnits > 0n && amountBaseUnits > this.perCallCapBaseUnits) {
84
- return {
85
- allowed: false,
86
- reason: `per-call ${formatUsdc(amountBaseUnits)} exceeds the ceiling ${formatUsdc(this.perCallCapBaseUnits)}`,
87
- remainingBaseUnits: this.remaining(),
88
- };
89
- }
90
- if (this.dailyCapBaseUnits > 0n && this.spentBaseUnits + amountBaseUnits > this.dailyCapBaseUnits) {
91
- return {
92
- allowed: false,
93
- reason: `daily USDC cap ${formatUsdc(this.dailyCapBaseUnits)} would be exceeded (already spent ${formatUsdc(this.spentBaseUnits)})`,
94
- remainingBaseUnits: this.remaining(),
95
- };
96
- }
97
- return { allowed: true, remainingBaseUnits: this.remaining() };
98
- }
99
- /** The largest amount a single call may spend right now (min of per-call
100
- * ceiling and remaining daily headroom). `undefined` = unlimited. `0n` =
101
- * budget already exhausted (caller should not pay at all). */
102
- maxForNextCall() {
103
- this.roll();
104
- const limits = [];
105
- if (this.perCallCapBaseUnits > 0n)
106
- limits.push(this.perCallCapBaseUnits);
107
- if (this.dailyCapBaseUnits > 0n)
108
- limits.push(this.dailyCapBaseUnits - this.spentBaseUnits);
109
- if (limits.length === 0)
110
- return undefined; // fully unlimited
111
- const m = limits.reduce((a, b) => (b < a ? b : a));
112
- return m > 0n ? m : 0n;
113
- }
114
- /** Record a completed spend (call AFTER a successful payment). */
115
- record(amountBaseUnits) {
116
- this.roll();
117
- if (amountBaseUnits > 0n)
118
- this.spentBaseUnits += amountBaseUnits;
119
- }
120
- /** Remaining daily headroom in base units; -1n when unlimited. */
121
- remaining() {
122
- if (this.dailyCapBaseUnits === 0n)
123
- return -1n;
124
- this.roll();
125
- const r = this.dailyCapBaseUnits - this.spentBaseUnits;
126
- return r > 0n ? r : 0n;
127
- }
128
- /** True when a daily cap is set and fully consumed — the goal loop's
129
- * `blocked_budget` trigger. Always false when unlimited. */
130
- isExhausted() {
131
- if (this.dailyCapBaseUnits === 0n)
132
- return false;
133
- this.roll();
134
- return this.spentBaseUnits >= this.dailyCapBaseUnits;
135
- }
136
- /** Spent-so-far in the current window (base units). */
137
- get spent() {
138
- this.roll();
139
- return this.spentBaseUnits;
140
- }
141
- }
142
- /** Build a UsdcBudget from explicit options falling back to env
143
- * (`X402_DAILY_USDC_CAP`, `X402_PER_CALL_USDC_CAP`, both USDC display units)
144
- * and finally the conservative default daily cap. */
145
- export function createUsdcBudget(opts = {}) {
146
- const env = typeof process !== "undefined" ? process.env : undefined;
147
- const dailyCapBaseUnits = opts.dailyCapBaseUnits ??
148
- (env?.X402_DAILY_USDC_CAP !== undefined
149
- ? parseUsdcToBaseUnits(env.X402_DAILY_USDC_CAP)
150
- : DEFAULT_DAILY_USDC_CAP_BASE_UNITS);
151
- const perCallCapBaseUnits = opts.perCallCapBaseUnits ??
152
- (env?.X402_PER_CALL_USDC_CAP !== undefined ? parseUsdcToBaseUnits(env.X402_PER_CALL_USDC_CAP) : 0n);
153
- return new UsdcBudget({ ...opts, dailyCapBaseUnits, perCallCapBaseUnits });
154
- }
155
- //# sourceMappingURL=usdcBudget.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usdcBudget.js","sourceRoot":"","sources":["../src/usdcBudget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,MAAM,QAAQ,GAAG,QAAU,CAAC;AAE5B;;;wDAGwD;AACxD,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,GAAG,QAAQ,CAAC;AAEhE,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAqBtC;gEACgE;AAChE,MAAM,UAAU,oBAAoB,CAAC,OAA2B;IAC9D,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,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AAC;IAED;iEAC6D;IAC7D,WAAW;QACT,IAAI,IAAI,CAAC,iBAAiB,KAAK,EAAE;YAAE,OAAO,KAAK,CAAC;QAChD,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,iBAAiB,CAAC;IACvD,CAAC;IAED,uDAAuD;IACvD,IAAI,KAAK;QACP,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;sDAEsD;AACtD,MAAM,UAAU,gBAAgB,CAAC,OAA0B,EAAE;IAC3D,MAAM,GAAG,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACrE,MAAM,iBAAiB,GACrB,IAAI,CAAC,iBAAiB;QACtB,CAAC,GAAG,EAAE,mBAAmB,KAAK,SAAS;YACrC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,mBAAmB,CAAC;YAC/C,CAAC,CAAC,iCAAiC,CAAC,CAAC;IACzC,MAAM,mBAAmB,GACvB,IAAI,CAAC,mBAAmB;QACxB,CAAC,GAAG,EAAE,sBAAsB,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACtG,OAAO,IAAI,UAAU,CAAC,EAAE,GAAG,IAAI,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAC,CAAC;AAC7E,CAAC"}
package/dist/x402.d.ts DELETED
@@ -1,69 +0,0 @@
1
- /**
2
- * Optional convenience wrapper for paying marketplace API listings per-call via
3
- * x402 (ROADMAP_x402-marketplace-fees.md v2). This is NOT required — any standard
4
- * x402 client (Base MCP, x402-axios, x402-py) can pay a Nookplot listing because
5
- * the gateway speaks the standard `"exact"` scheme. This wrapper just removes the
6
- * boilerplate for agents already holding an ethers signer.
7
- *
8
- * Unlike the agreement-based {@link ApiMarketplaceManager.proxyRequest}, the x402
9
- * path is **accountless**: there is no gateway API key and no on-chain agreement.
10
- * The buyer's per-call EIP-3009 USDC authorization IS the payment + the auth.
11
- *
12
- * Flow:
13
- * 1. Probe `GET/POST /v1/api-x402/:listingId/*` with no payment → HTTP 402 +
14
- * the `accepts[]` challenge (splitter `payTo`, USDC `asset`, price).
15
- * 2. Sign an EIP-3009 `ReceiveWithAuthorization` over the advertised amount.
16
- * 3. Re-send the request with the encoded payment header → upstream response.
17
- *
18
- * v2.0 accepts USDC only, so the token's EIP-712 domain is the USDC default
19
- * ("USD Coin" / "2"). NOOK (a different domain) is deferred to v2.1.
20
- *
21
- * @module x402
22
- */
23
- import { ethers } from "ethers";
24
- export interface X402PayAndCallInput {
25
- /** On-chain listing id. */
26
- listingId: number | string;
27
- /** Upstream path after the listing id (e.g. "chat/completions"). */
28
- path: string;
29
- /** HTTP method. Default "GET". */
30
- method?: string;
31
- /** JSON request body (serialized for non-GET/HEAD). */
32
- body?: unknown;
33
- /** Extra request headers passed through to the upstream. */
34
- headers?: Record<string, string>;
35
- /** Hard per-call ceiling in USDC base units. When set, `payAndCall` throws
36
- * BEFORE signing if the 402-quoted `maxAmountRequired` exceeds it. The
37
- * `pay_api` dispatch sites pass `runtime.usdcBudget.maxForNextCall()` here so
38
- * the spend cap is enforced at the point of payment. */
39
- maxAmountBaseUnits?: bigint;
40
- }
41
- export interface X402PayAndCallResult {
42
- status: number;
43
- headers: Record<string, string>;
44
- /** Parsed JSON when possible, else raw text. */
45
- body: unknown;
46
- /** True when a payment was signed + submitted; false when the gateway
47
- * short-circuited before payment (e.g. listing unavailable). */
48
- paid: boolean;
49
- /** USDC base units actually authorized when `paid` is true (the 402
50
- * `maxAmountRequired`). Lets the caller record the spend against a budget. */
51
- amountPaidBaseUnits?: string;
52
- }
53
- export interface X402ManagerOptions {
54
- /** Override the EIP-712 chain id (else derived from the 402 `network`). */
55
- chainId?: number;
56
- }
57
- export declare class X402Manager {
58
- private readonly gatewayUrl;
59
- private readonly chainIdOverride?;
60
- constructor(gatewayUrl: string, opts?: X402ManagerOptions);
61
- /**
62
- * Pay for and make a single metered call to a marketplace API listing.
63
- *
64
- * @param input The listing + upstream request.
65
- * @param signer An ethers signer holding the buyer's USDC (e.g. `new ethers.Wallet(pk)`).
66
- */
67
- payAndCall(input: X402PayAndCallInput, signer: ethers.Signer): Promise<X402PayAndCallResult>;
68
- }
69
- //# sourceMappingURL=x402.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAgBhC,MAAM,WAAW,mBAAmB;IAClC,2BAA2B;IAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;6DAGyD;IACzD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,gDAAgD;IAChD,IAAI,EAAE,OAAO,CAAC;IACd;qEACiE;IACjE,IAAI,EAAE,OAAO,CAAC;IACd;mFAC+E;IAC/E,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAYD,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW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