@autoview/cli 0.1.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 (297) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +407 -0
  3. package/lib/AutoViewAgent.d.ts +109 -0
  4. package/lib/AutoViewAgent.js +123 -0
  5. package/lib/AutoViewAgent.js.map +1 -0
  6. package/lib/agent/emitMcpServer.d.ts +15 -0
  7. package/lib/agent/emitMcpServer.js +157 -0
  8. package/lib/agent/emitMcpServer.js.map +1 -0
  9. package/lib/agent/emitReport.d.ts +14 -0
  10. package/lib/agent/emitReport.js +85 -0
  11. package/lib/agent/emitReport.js.map +1 -0
  12. package/lib/agent/toolSurface.d.ts +130 -0
  13. package/lib/agent/toolSurface.js +342 -0
  14. package/lib/agent/toolSurface.js.map +1 -0
  15. package/lib/agent/verifyAgentTasks.d.ts +87 -0
  16. package/lib/agent/verifyAgentTasks.js +126 -0
  17. package/lib/agent/verifyAgentTasks.js.map +1 -0
  18. package/lib/cli/main.d.ts +2 -0
  19. package/lib/cli/main.js +295 -0
  20. package/lib/cli/main.js.map +1 -0
  21. package/lib/compiler/AutoViewInterfaceCompiler.d.ts +27 -0
  22. package/lib/compiler/AutoViewInterfaceCompiler.js +68 -0
  23. package/lib/compiler/AutoViewInterfaceCompiler.js.map +1 -0
  24. package/lib/constants/AutoViewFrontendTemplate.d.ts +1 -0
  25. package/lib/constants/AutoViewFrontendTemplate.js +46 -0
  26. package/lib/constants/AutoViewFrontendTemplate.js.map +1 -0
  27. package/lib/constants/AutoViewSystemPromptConstant.d.ts +5 -0
  28. package/lib/constants/AutoViewSystemPromptConstant.js +4 -0
  29. package/lib/constants/AutoViewSystemPromptConstant.js.map +1 -0
  30. package/lib/context/IAutoViewAgentContext.d.ts +60 -0
  31. package/lib/context/IAutoViewAgentContext.js +3 -0
  32. package/lib/context/IAutoViewAgentContext.js.map +1 -0
  33. package/lib/fromSwagger.d.ts +53 -0
  34. package/lib/fromSwagger.js +513 -0
  35. package/lib/fromSwagger.js.map +1 -0
  36. package/lib/generateDeterministic.d.ts +26 -0
  37. package/lib/generateDeterministic.js +75 -0
  38. package/lib/generateDeterministic.js.map +1 -0
  39. package/lib/index.d.ts +15 -0
  40. package/lib/index.js +41 -0
  41. package/lib/index.js.map +1 -0
  42. package/lib/orchestrate/orchestrateAutoView.d.ts +17 -0
  43. package/lib/orchestrate/orchestrateAutoView.js +491 -0
  44. package/lib/orchestrate/orchestrateAutoView.js.map +1 -0
  45. package/lib/orchestrate/orchestrateAutoViewProductPlan.d.ts +37 -0
  46. package/lib/orchestrate/orchestrateAutoViewProductPlan.js +109 -0
  47. package/lib/orchestrate/orchestrateAutoViewProductPlan.js.map +1 -0
  48. package/lib/orchestrate/orchestrateAutoViewRender.d.ts +133 -0
  49. package/lib/orchestrate/orchestrateAutoViewRender.js +943 -0
  50. package/lib/orchestrate/orchestrateAutoViewRender.js.map +1 -0
  51. package/lib/orchestrate/orchestrateAutoViewRenderDeterministic.d.ts +24 -0
  52. package/lib/orchestrate/orchestrateAutoViewRenderDeterministic.js +92 -0
  53. package/lib/orchestrate/orchestrateAutoViewRenderDeterministic.js.map +1 -0
  54. package/lib/orchestrate/orchestrateAutoViewReview.d.ts +48 -0
  55. package/lib/orchestrate/orchestrateAutoViewReview.js +328 -0
  56. package/lib/orchestrate/orchestrateAutoViewReview.js.map +1 -0
  57. package/lib/orchestrate/orchestrateAutoViewScaffold.d.ts +45 -0
  58. package/lib/orchestrate/orchestrateAutoViewScaffold.js +586 -0
  59. package/lib/orchestrate/orchestrateAutoViewScaffold.js.map +1 -0
  60. package/lib/orchestrate/orchestrateAutoViewSdkStudy.d.ts +26 -0
  61. package/lib/orchestrate/orchestrateAutoViewSdkStudy.js +85 -0
  62. package/lib/orchestrate/orchestrateAutoViewSdkStudy.js.map +1 -0
  63. package/lib/orchestrate/structures/IAutoViewProductPlan.d.ts +96 -0
  64. package/lib/orchestrate/structures/IAutoViewProductPlan.js +3 -0
  65. package/lib/orchestrate/structures/IAutoViewProductPlan.js.map +1 -0
  66. package/lib/orchestrate/structures/IAutoViewProductPlanApplication.d.ts +38 -0
  67. package/lib/orchestrate/structures/IAutoViewProductPlanApplication.js +3 -0
  68. package/lib/orchestrate/structures/IAutoViewProductPlanApplication.js.map +1 -0
  69. package/lib/orchestrate/structures/IAutoViewRenderApplication.d.ts +38 -0
  70. package/lib/orchestrate/structures/IAutoViewRenderApplication.js +3 -0
  71. package/lib/orchestrate/structures/IAutoViewRenderApplication.js.map +1 -0
  72. package/lib/orchestrate/structures/IAutoViewReviewApplication.d.ts +40 -0
  73. package/lib/orchestrate/structures/IAutoViewReviewApplication.js +3 -0
  74. package/lib/orchestrate/structures/IAutoViewReviewApplication.js.map +1 -0
  75. package/lib/orchestrate/structures/IAutoViewSdkMap.d.ts +63 -0
  76. package/lib/orchestrate/structures/IAutoViewSdkMap.js +3 -0
  77. package/lib/orchestrate/structures/IAutoViewSdkMap.js.map +1 -0
  78. package/lib/orchestrate/structures/IAutoViewSdkStudyApplication.d.ts +37 -0
  79. package/lib/orchestrate/structures/IAutoViewSdkStudyApplication.js +3 -0
  80. package/lib/orchestrate/structures/IAutoViewSdkStudyApplication.js.map +1 -0
  81. package/lib/orchestrate/utils/HistoryMessage.d.ts +10 -0
  82. package/lib/orchestrate/utils/HistoryMessage.js +25 -0
  83. package/lib/orchestrate/utils/HistoryMessage.js.map +1 -0
  84. package/lib/orchestrate/utils/auditFrontendRuntime.d.ts +53 -0
  85. package/lib/orchestrate/utils/auditFrontendRuntime.js +362 -0
  86. package/lib/orchestrate/utils/auditFrontendRuntime.js.map +1 -0
  87. package/lib/orchestrate/utils/buildDeterministicPlan.d.ts +4 -0
  88. package/lib/orchestrate/utils/buildDeterministicPlan.js +233 -0
  89. package/lib/orchestrate/utils/buildDeterministicPlan.js.map +1 -0
  90. package/lib/orchestrate/utils/buildDeterministicSdkMap.d.ts +22 -0
  91. package/lib/orchestrate/utils/buildDeterministicSdkMap.js +154 -0
  92. package/lib/orchestrate/utils/buildDeterministicSdkMap.js.map +1 -0
  93. package/lib/orchestrate/utils/cacheNodeModules.d.ts +31 -0
  94. package/lib/orchestrate/utils/cacheNodeModules.js +134 -0
  95. package/lib/orchestrate/utils/cacheNodeModules.js.map +1 -0
  96. package/lib/orchestrate/utils/describeEndpointPropsShape.d.ts +37 -0
  97. package/lib/orchestrate/utils/describeEndpointPropsShape.js +192 -0
  98. package/lib/orchestrate/utils/describeEndpointPropsShape.js.map +1 -0
  99. package/lib/orchestrate/utils/describeEndpointRequestBodyShape.d.ts +22 -0
  100. package/lib/orchestrate/utils/describeEndpointRequestBodyShape.js +29 -0
  101. package/lib/orchestrate/utils/describeEndpointRequestBodyShape.js.map +1 -0
  102. package/lib/orchestrate/utils/describeEndpointResponseShape.d.ts +19 -0
  103. package/lib/orchestrate/utils/describeEndpointResponseShape.js +30 -0
  104. package/lib/orchestrate/utils/describeEndpointResponseShape.js.map +1 -0
  105. package/lib/orchestrate/utils/executeCachedBatch.d.ts +22 -0
  106. package/lib/orchestrate/utils/executeCachedBatch.js +64 -0
  107. package/lib/orchestrate/utils/executeCachedBatch.js.map +1 -0
  108. package/lib/orchestrate/utils/loadShoppingFixture.d.ts +33 -0
  109. package/lib/orchestrate/utils/loadShoppingFixture.js +17 -0
  110. package/lib/orchestrate/utils/loadShoppingFixture.js.map +1 -0
  111. package/lib/orchestrate/utils/normalizeProductPlanPaths.d.ts +24 -0
  112. package/lib/orchestrate/utils/normalizeProductPlanPaths.js +77 -0
  113. package/lib/orchestrate/utils/normalizeProductPlanPaths.js.map +1 -0
  114. package/lib/orchestrate/utils/renderJsonSchema.d.ts +23 -0
  115. package/lib/orchestrate/utils/renderJsonSchema.js +122 -0
  116. package/lib/orchestrate/utils/renderJsonSchema.js.map +1 -0
  117. package/lib/orchestrate/utils/renderResourcePage.d.ts +36 -0
  118. package/lib/orchestrate/utils/renderResourcePage.js +1415 -0
  119. package/lib/orchestrate/utils/renderResourcePage.js.map +1 -0
  120. package/lib/orchestrate/utils/validateFrontendTypecheck.d.ts +109 -0
  121. package/lib/orchestrate/utils/validateFrontendTypecheck.js +274 -0
  122. package/lib/orchestrate/utils/validateFrontendTypecheck.js.map +1 -0
  123. package/lib/preview/renderPreview.d.ts +22 -0
  124. package/lib/preview/renderPreview.js +198 -0
  125. package/lib/preview/renderPreview.js.map +1 -0
  126. package/lib/typings/compiler.d.ts +39 -0
  127. package/lib/typings/compiler.js +3 -0
  128. package/lib/typings/compiler.js.map +1 -0
  129. package/lib/typings/events.d.ts +106 -0
  130. package/lib/typings/events.js +3 -0
  131. package/lib/typings/events.js.map +1 -0
  132. package/lib/typings/index.d.ts +10 -0
  133. package/lib/typings/index.js +27 -0
  134. package/lib/typings/index.js.map +1 -0
  135. package/lib/typings/misc.d.ts +78 -0
  136. package/lib/typings/misc.js +3 -0
  137. package/lib/typings/misc.js.map +1 -0
  138. package/lib/utils/ArrayUtil.d.ts +8 -0
  139. package/lib/utils/ArrayUtil.js +30 -0
  140. package/lib/utils/ArrayUtil.js.map +1 -0
  141. package/lib/utils/StringUtil.d.ts +11 -0
  142. package/lib/utils/StringUtil.js +28 -0
  143. package/lib/utils/StringUtil.js.map +1 -0
  144. package/lib/utils/classifyEndpoints.d.ts +62 -0
  145. package/lib/utils/classifyEndpoints.js +216 -0
  146. package/lib/utils/classifyEndpoints.js.map +1 -0
  147. package/lib/utils/endpointFilter.d.ts +26 -0
  148. package/lib/utils/endpointFilter.js +0 -0
  149. package/lib/utils/endpointFilter.js.map +1 -0
  150. package/lib/utils/extractFields.d.ts +85 -0
  151. package/lib/utils/extractFields.js +231 -0
  152. package/lib/utils/extractFields.js.map +1 -0
  153. package/lib/utils/index.d.ts +13 -0
  154. package/lib/utils/index.js +30 -0
  155. package/lib/utils/index.js.map +1 -0
  156. package/lib/utils/normalizeForNestia.d.ts +34 -0
  157. package/lib/utils/normalizeForNestia.js +133 -0
  158. package/lib/utils/normalizeForNestia.js.map +1 -0
  159. package/lib/utils/resourcePlan.d.ts +39 -0
  160. package/lib/utils/resourcePlan.js +95 -0
  161. package/lib/utils/resourcePlan.js.map +1 -0
  162. package/lib/utils/sliceDocument.d.ts +17 -0
  163. package/lib/utils/sliceDocument.js +114 -0
  164. package/lib/utils/sliceDocument.js.map +1 -0
  165. package/lib/utils/toEndpoints.d.ts +90 -0
  166. package/lib/utils/toEndpoints.js +227 -0
  167. package/lib/utils/toEndpoints.js.map +1 -0
  168. package/lib/verify/runWorkflows.d.ts +25 -0
  169. package/lib/verify/runWorkflows.js +366 -0
  170. package/lib/verify/runWorkflows.js.map +1 -0
  171. package/lib/verify/workflows.d.ts +53 -0
  172. package/lib/verify/workflows.js +107 -0
  173. package/lib/verify/workflows.js.map +1 -0
  174. package/package.json +82 -0
  175. package/prompts/AUTOVIEW_RENDER.md +398 -0
  176. package/prompts/AUTOVIEW_REVIEW.md +60 -0
  177. package/prompts/AUTOVIEW_SDK_STUDY.md +89 -0
  178. package/src/AutoViewAgent.ts +222 -0
  179. package/src/agent/emitMcpServer.integration.test.ts +168 -0
  180. package/src/agent/emitMcpServer.test.ts +51 -0
  181. package/src/agent/emitMcpServer.ts +178 -0
  182. package/src/agent/emitReport.ts +117 -0
  183. package/src/agent/toolSurface.test.ts +243 -0
  184. package/src/agent/toolSurface.ts +501 -0
  185. package/src/agent/verifyAgentTasks.test.ts +106 -0
  186. package/src/agent/verifyAgentTasks.ts +171 -0
  187. package/src/cli/main.ts +363 -0
  188. package/src/compiler/AutoViewInterfaceCompiler.ts +69 -0
  189. package/src/constants/AutoViewFrontendTemplate.ts +42 -0
  190. package/src/constants/AutoViewSystemPromptConstant.ts +6 -0
  191. package/src/context/IAutoViewAgentContext.ts +84 -0
  192. package/src/fromSwagger.test.ts +269 -0
  193. package/src/fromSwagger.ts +500 -0
  194. package/src/generateDeterministic.test.ts +39 -0
  195. package/src/generateDeterministic.ts +77 -0
  196. package/src/index.ts +30 -0
  197. package/src/orchestrate/orchestrateAutoView.ts +590 -0
  198. package/src/orchestrate/orchestrateAutoViewProductPlan.ts +121 -0
  199. package/src/orchestrate/orchestrateAutoViewRender.ts +1117 -0
  200. package/src/orchestrate/orchestrateAutoViewRenderDeterministic.ts +101 -0
  201. package/src/orchestrate/orchestrateAutoViewReview.ts +272 -0
  202. package/src/orchestrate/orchestrateAutoViewScaffold.ts +627 -0
  203. package/src/orchestrate/orchestrateAutoViewSdkStudy.ts +90 -0
  204. package/src/orchestrate/renderNavTs.test.ts +74 -0
  205. package/src/orchestrate/structures/IAutoViewProductPlan.ts +119 -0
  206. package/src/orchestrate/structures/IAutoViewProductPlanApplication.ts +41 -0
  207. package/src/orchestrate/structures/IAutoViewRenderApplication.ts +40 -0
  208. package/src/orchestrate/structures/IAutoViewReviewApplication.ts +42 -0
  209. package/src/orchestrate/structures/IAutoViewSdkMap.ts +72 -0
  210. package/src/orchestrate/structures/IAutoViewSdkStudyApplication.ts +40 -0
  211. package/src/orchestrate/utils/HistoryMessage.ts +41 -0
  212. package/src/orchestrate/utils/auditFrontendRuntime.test.ts +18 -0
  213. package/src/orchestrate/utils/auditFrontendRuntime.ts +454 -0
  214. package/src/orchestrate/utils/buildDeterministicPlan.test.ts +170 -0
  215. package/src/orchestrate/utils/buildDeterministicPlan.ts +289 -0
  216. package/src/orchestrate/utils/buildDeterministicSdkMap.test.ts +90 -0
  217. package/src/orchestrate/utils/buildDeterministicSdkMap.ts +169 -0
  218. package/src/orchestrate/utils/cacheNodeModules.ts +136 -0
  219. package/src/orchestrate/utils/describeEndpointPropsShape.test.ts +86 -0
  220. package/src/orchestrate/utils/describeEndpointPropsShape.ts +202 -0
  221. package/src/orchestrate/utils/describeEndpointRequestBodyShape.test.ts +87 -0
  222. package/src/orchestrate/utils/describeEndpointRequestBodyShape.ts +31 -0
  223. package/src/orchestrate/utils/describeEndpointResponseShape.test.ts +70 -0
  224. package/src/orchestrate/utils/describeEndpointResponseShape.ts +32 -0
  225. package/src/orchestrate/utils/executeCachedBatch.ts +59 -0
  226. package/src/orchestrate/utils/loadShoppingFixture.ts +52 -0
  227. package/src/orchestrate/utils/normalizeProductPlanPaths.ts +92 -0
  228. package/src/orchestrate/utils/renderJsonSchema.test.ts +162 -0
  229. package/src/orchestrate/utils/renderJsonSchema.ts +133 -0
  230. package/src/orchestrate/utils/renderResourcePage.test.ts +468 -0
  231. package/src/orchestrate/utils/renderResourcePage.ts +1624 -0
  232. package/src/orchestrate/utils/validateFrontendTypecheck.test.ts +32 -0
  233. package/src/orchestrate/utils/validateFrontendTypecheck.ts +335 -0
  234. package/src/preview/renderPreview.ts +273 -0
  235. package/src/typings/compiler.ts +47 -0
  236. package/src/typings/events.ts +155 -0
  237. package/src/typings/index.ts +10 -0
  238. package/src/typings/misc.ts +93 -0
  239. package/src/utils/ArrayUtil.ts +16 -0
  240. package/src/utils/StringUtil.ts +29 -0
  241. package/src/utils/classifyEndpoints.test.ts +86 -0
  242. package/src/utils/classifyEndpoints.ts +291 -0
  243. package/src/utils/endpointFilter.test.ts +50 -0
  244. package/src/utils/endpointFilter.ts +0 -0
  245. package/src/utils/extractFields.test.ts +82 -0
  246. package/src/utils/extractFields.ts +306 -0
  247. package/src/utils/index.ts +13 -0
  248. package/src/utils/normalizeForNestia.test.ts +93 -0
  249. package/src/utils/normalizeForNestia.ts +139 -0
  250. package/src/utils/resourcePlan.test.ts +104 -0
  251. package/src/utils/resourcePlan.ts +180 -0
  252. package/src/utils/sliceDocument.test.ts +85 -0
  253. package/src/utils/sliceDocument.ts +119 -0
  254. package/src/utils/toEndpoints.test.ts +251 -0
  255. package/src/utils/toEndpoints.ts +343 -0
  256. package/src/verify/runWorkflows.ts +403 -0
  257. package/src/verify/workflows.test.ts +117 -0
  258. package/src/verify/workflows.ts +154 -0
  259. package/template/CLAUDE.md +140 -0
  260. package/template/Dockerfile +31 -0
  261. package/template/PROMPT.md +80 -0
  262. package/template/SANDBOX.md +70 -0
  263. package/template/app/api/health/route.ts +10 -0
  264. package/template/app/globals.css +97 -0
  265. package/template/app/layout.tsx +30 -0
  266. package/template/app/page.tsx +19 -0
  267. package/template/components/AppShell.tsx +114 -0
  268. package/template/components/auto/CatalogGrid.tsx +159 -0
  269. package/template/components/auto/ConfirmButton.tsx +67 -0
  270. package/template/components/auto/EmbeddedCollection.tsx +144 -0
  271. package/template/components/auto/ResourceDashboard.tsx +104 -0
  272. package/template/components/auto/ResourceDetail.tsx +93 -0
  273. package/template/components/auto/ResourceForm.tsx +235 -0
  274. package/template/components/auto/ResourceIcon.tsx +88 -0
  275. package/template/components/auto/ResourceLanding.tsx +155 -0
  276. package/template/components/auto/ResourceTable.tsx +223 -0
  277. package/template/components/auto/formatValue.tsx +186 -0
  278. package/template/components/auto/types.ts +42 -0
  279. package/template/components/ui/badge.tsx +40 -0
  280. package/template/components/ui/button.tsx +57 -0
  281. package/template/components/ui/card.tsx +86 -0
  282. package/template/components/ui/dialog.tsx +119 -0
  283. package/template/components/ui/input.tsx +23 -0
  284. package/template/components/ui/label.tsx +24 -0
  285. package/template/components/ui/pagination.tsx +117 -0
  286. package/template/components/ui/select.tsx +92 -0
  287. package/template/components/ui/sheet.tsx +135 -0
  288. package/template/components/ui/skeleton.tsx +15 -0
  289. package/template/components/ui/table.tsx +120 -0
  290. package/template/components/ui/tabs.tsx +55 -0
  291. package/template/lib/utils.ts +35 -0
  292. package/template/next.config.mjs +52 -0
  293. package/template/package.json +46 -0
  294. package/template/postcss.config.js +6 -0
  295. package/template/scripts/start-shopping-backend.sh +56 -0
  296. package/template/tailwind.config.ts +96 -0
  297. package/template/tsconfig.json +29 -0
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildToolSurface = buildToolSurface;
4
+ exports.analyzeConsumability = analyzeConsumability;
5
+ exports.coverToolSurface = coverToolSurface;
6
+ const classifyEndpoints_1 = require("../utils/classifyEndpoints");
7
+ const extractFields_1 = require("../utils/extractFields");
8
+ const toEndpoints_1 = require("../utils/toEndpoints");
9
+ const READ_ROLES = new Set(["list", "search", "detail"]);
10
+ /** Field names that identify a record (the value a path param consumes). */
11
+ const ID_NAMES = ["id", "uuid"];
12
+ /** The first identifying field name present (`id` preferred over `uuid`), or null. */
13
+ const firstIdName = (names) => {
14
+ var _a;
15
+ const set = new Set([...names].map((n) => n.toLowerCase()));
16
+ return (_a = ID_NAMES.find((n) => set.has(n))) !== null && _a !== void 0 ? _a : null;
17
+ };
18
+ /**
19
+ * Whether a read endpoint's response element carries an identifying field
20
+ * (`id` / `uuid`) — i.e. whether it can PRODUCE an id for a consumer. Handles
21
+ * both named component responses and INLINE response schemas, and collection
22
+ * wrappers named generically (`data`/`entries`) OR after the resource
23
+ * (`{ databases: [...] }`, DigitalOcean), including inline array items.
24
+ */
25
+ function producedIdField(op, doc) {
26
+ var _a;
27
+ // Named-type path (nestia/AutoBE convention).
28
+ if (op.responseBody !== null) {
29
+ const elementFields = op.responseBody.isArray
30
+ ? (0, extractFields_1.extractFields)(op.responseBody.typeName, doc)
31
+ : (() => {
32
+ var _a;
33
+ const top = (0, extractFields_1.extractFields)(op.responseBody.typeName, doc);
34
+ // The collection field is either generically named (`data`/`entries`)
35
+ // or named after the resource (`{ namespaces: [...] }`, common on
36
+ // DigitalOcean once nestia promotes the inline response to a named
37
+ // type). Fall back to the first array field so the latter is found —
38
+ // producedIdField only runs on list/search reads, so an array IS the
39
+ // collection.
40
+ const col = (_a = (0, extractFields_1.findCollectionField)(top)) !== null && _a !== void 0 ? _a : top.find((f) => f.kind === "array" && f.ref !== undefined);
41
+ return (col === null || col === void 0 ? void 0 : col.ref) !== undefined ? (0, extractFields_1.extractFields)(col.ref, doc) : top;
42
+ })();
43
+ const named = firstIdName(elementFields.map((f) => f.name));
44
+ if (named !== null)
45
+ return named;
46
+ // else: the promoted type was a dead/empty ref (nestia emits a `*.GetResponse`
47
+ // not registered in components, just like `*.GetQuery`) — fall through to the
48
+ // raw inline response schema, which still carries the real array.
49
+ }
50
+ // Inline response schema (DigitalOcean): introspect the raw schema.
51
+ if (op.responseSchema === null)
52
+ return null;
53
+ const { properties } = (0, extractFields_1.resolveProperties)(op.responseSchema, doc);
54
+ // The collection array: a known-named one, else the sole/first array property.
55
+ const arrayEntries = Object.entries(properties).filter(([, p]) => p.type === "array");
56
+ const collection = (_a = arrayEntries.find(([n]) => extractFields_1.COLLECTION_FIELD_NAMES.has(n.toLowerCase()))) !== null && _a !== void 0 ? _a : arrayEntries[0];
57
+ if (collection !== undefined) {
58
+ const items = collection[1].items;
59
+ if (items !== undefined) {
60
+ return firstIdName(Object.keys((0, extractFields_1.resolveProperties)(items, doc).properties));
61
+ }
62
+ }
63
+ // A single object (detail) returning an inline schema.
64
+ return firstIdName(Object.keys(properties));
65
+ }
66
+ /** Roles whose response is a browsable collection — the only legitimate id
67
+ * PRODUCERS. A `detail` read returns one object but needs the id to be called,
68
+ * so it cannot produce that id (circular); excluding it keeps navigability honest. */
69
+ const COLLECTION_ROLES = new Set(["list", "search"]);
70
+ /**
71
+ * The shared producer model used by BOTH the tool surface and the consumability
72
+ * report, so they never disagree on what is navigable. For each resource, the
73
+ * collection read (list/search) whose element exposes an id — keyed by the
74
+ * endpoint's CLASSIFIED resource (so a verb path like `/pet/findByStatus` is
75
+ * bucketed under `pet`, not `findByStatus`).
76
+ */
77
+ function producerIndex(document) {
78
+ var _a, _b;
79
+ const endpoints = (0, toEndpoints_1.toEndpoints)(document);
80
+ const roleOf = new Map();
81
+ const resourceOf = new Map();
82
+ for (const g of (0, classifyEndpoints_1.classifyEndpoints)(endpoints, document)) {
83
+ for (const c of g.endpoints) {
84
+ roleOf.set(c.endpoint, c.role);
85
+ resourceOf.set(c.endpoint, (_b = (_a = c.chain.at(-1)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : c.resource);
86
+ }
87
+ }
88
+ const producerOf = new Map();
89
+ const readableResources = new Set();
90
+ for (const e of endpoints) {
91
+ const role = roleOf.get(e);
92
+ const resource = resourceOf.get(e);
93
+ if (role === undefined || resource === undefined)
94
+ continue;
95
+ if (READ_ROLES.has(role))
96
+ readableResources.add(resource);
97
+ if (!COLLECTION_ROLES.has(role))
98
+ continue;
99
+ // A genuine producer ENUMERATES the resource. One that is itself scoped by
100
+ // that resource's own id (`/files/{file_id}/trash` → resource `files`, but
101
+ // it requires `file_id`) cannot produce that id — it is circular, so skip it.
102
+ const selfScoped = e.parameters.some((p) => resourceOfParam(e.path, p.name) === resource);
103
+ if (selfScoped)
104
+ continue;
105
+ const field = producedIdField(e, document);
106
+ if (field !== null && !producerOf.has(resource)) {
107
+ producerOf.set(resource, { tool: e.accessor.join("."), field });
108
+ }
109
+ }
110
+ const nested = nestedProducers(endpoints, document, roleOf);
111
+ return { endpoints, roleOf, producerOf, readableResources, nested };
112
+ }
113
+ /** The named element type of a read endpoint's response (for recursion). */
114
+ function responseElementTypeName(op, doc) {
115
+ var _a;
116
+ if (op.responseBody === null)
117
+ return null;
118
+ if (op.responseBody.isArray)
119
+ return op.responseBody.typeName;
120
+ const col = (0, extractFields_1.findCollectionField)((0, extractFields_1.extractFields)(op.responseBody.typeName, doc));
121
+ return (_a = col === null || col === void 0 ? void 0 : col.ref) !== null && _a !== void 0 ? _a : op.responseBody.typeName;
122
+ }
123
+ /**
124
+ * Resources whose ids are obtainable NESTED inside a read response, not from a
125
+ * dedicated endpoint — `order` detail returns `goods: IShoppingOrderGood[]`,
126
+ * `sale` returns `units: IShoppingSaleUnit[]` (each unit holds `stocks: […]`).
127
+ * Walks each read's response type graph (depth-bounded) and, for every
128
+ * array-field whose element carries an id, records WHICH read tool exposes it
129
+ * and the nested path — so the tool surface can hand the agent a real producer
130
+ * hint ("stockId ← sale.get, at units[].stocks[].id"), not just say it exists.
131
+ */
132
+ function nestedProducers(endpoints, doc, roleOf) {
133
+ const out = new Map();
134
+ const visit = (typeName, tool, parts, depth, seen) => {
135
+ if (depth > 3 || seen.has(typeName))
136
+ return;
137
+ seen.add(typeName);
138
+ for (const f of (0, extractFields_1.extractFields)(typeName, doc)) {
139
+ if (f.kind === "array" && f.ref !== undefined) {
140
+ const childParts = [...parts, f.name];
141
+ const idField = firstIdName((0, extractFields_1.extractFields)(f.ref, doc).map((x) => x.name));
142
+ const key = f.name.toLowerCase();
143
+ if (idField !== null) {
144
+ // Prefer the SHALLOWEST path (fewest array hops) — `sale → units[]`
145
+ // beats `order → goods[].units[]` for the same `units` id, so the
146
+ // agent is pointed at the most direct producer.
147
+ const existing = out.get(key);
148
+ if (existing === undefined || childParts.length < existing.path.split(".").length) {
149
+ out.set(key, {
150
+ tool,
151
+ path: childParts.map((p) => `${p}[]`).join("."),
152
+ field: idField,
153
+ });
154
+ }
155
+ }
156
+ visit(f.ref, tool, childParts, depth + 1, seen); // recurse: units → stocks
157
+ }
158
+ else if (f.kind === "ref" && f.ref !== undefined) {
159
+ visit(f.ref, tool, parts, depth + 1, seen);
160
+ }
161
+ }
162
+ };
163
+ for (const e of endpoints) {
164
+ const role = roleOf.get(e);
165
+ if (role === undefined || !READ_ROLES.has(role))
166
+ continue;
167
+ const el = responseElementTypeName(e, doc);
168
+ if (el !== null)
169
+ visit(el, e.accessor.join("."), [], 0, new Set());
170
+ }
171
+ return out;
172
+ }
173
+ /** The static path segment that an `{param}` addresses (`/sales/{saleId}` → `sales`). */
174
+ function resourceOfParam(path, param) {
175
+ const segs = path.split("/").filter((s) => s.length > 0);
176
+ for (let i = 0; i < segs.length; i++) {
177
+ if (segs[i] === `{${param}}`)
178
+ return i > 0 ? segs[i - 1] : null;
179
+ }
180
+ return null;
181
+ }
182
+ function paramType(schema) {
183
+ const type = schema === null || schema === void 0 ? void 0 : schema.type;
184
+ return type === "integer" || type === "number" ? "number" : "string";
185
+ }
186
+ /**
187
+ * Build the agent tool surface from an OpenAPI document.
188
+ */
189
+ function buildToolSurface(document) {
190
+ const { endpoints, roleOf, producerOf, nested } = producerIndex(document);
191
+ return endpoints.map((e) => {
192
+ const role = roleOf.get(e);
193
+ const readOnly = role !== undefined && READ_ROLES.has(role);
194
+ const method = e.method.toUpperCase();
195
+ const name = e.accessor.join(".");
196
+ const properties = {};
197
+ const required = [];
198
+ const producers = [];
199
+ for (const p of e.parameters) {
200
+ const resource = resourceOfParam(e.path, p.name);
201
+ const direct = resource !== null ? producerOf.get(resource) : undefined;
202
+ const nestedP = resource !== null ? nested.get(resource.toLowerCase()) : undefined;
203
+ let description = p.description || `path parameter ${p.name}`;
204
+ if (direct !== undefined && direct.tool !== name) {
205
+ // a dedicated list/search produces this id directly
206
+ producers.push({ param: p.name, tool: direct.tool, field: direct.field });
207
+ description = `the ${direct.field} of a ${resource}; obtain it from the \`${direct.tool}\` tool — use each item's \`${direct.field}\` field`;
208
+ }
209
+ else if (nestedP !== undefined && nestedP.tool !== name) {
210
+ // the id lives nested inside a parent read's response
211
+ producers.push({
212
+ param: p.name,
213
+ tool: nestedP.tool,
214
+ field: `${nestedP.path}.${nestedP.field}`,
215
+ });
216
+ description = `the ${nestedP.field} of a ${resource}; obtain it from the \`${nestedP.tool}\` tool's response at \`${nestedP.path}.${nestedP.field}\``;
217
+ }
218
+ properties[p.name] = { type: paramType(p.schema), description };
219
+ required.push(p.name);
220
+ }
221
+ if (e.query !== null) {
222
+ properties.query = {
223
+ type: "object",
224
+ description: "optional search / filter / pagination",
225
+ };
226
+ }
227
+ if (e.requestBody !== null) {
228
+ properties.body = {
229
+ type: "object",
230
+ description: `request body (${e.requestBody.typeName})`,
231
+ };
232
+ required.push("body");
233
+ }
234
+ const tag = readOnly ? "[READ]" : "[WRITE — mutates server state]";
235
+ const chainNote = producers.length > 0
236
+ ? ` Inputs come from: ${producers.map((p) => `${p.param} ← ${p.tool}.${p.field}`).join("; ")}.`
237
+ : "";
238
+ return {
239
+ name,
240
+ description: `${tag} ${e.description || `${method} ${e.path}`}`.trim() + chainNote,
241
+ inputSchema: { type: "object", properties, required },
242
+ annotations: {
243
+ readOnlyHint: readOnly,
244
+ destructiveHint: method === "DELETE",
245
+ idempotentHint: method === "GET" || method === "PUT" || method === "DELETE",
246
+ },
247
+ operation: {
248
+ method,
249
+ path: e.path,
250
+ pathParams: e.parameters.map((p) => p.name),
251
+ hasQuery: e.query !== null,
252
+ hasBody: e.requestBody !== null,
253
+ },
254
+ producers,
255
+ };
256
+ });
257
+ }
258
+ /**
259
+ * True when a path param names an entity identifier (`id`, `*_id`, `*Id`,
260
+ * `uuid`) — the kind that must be produced by another endpoint. A param that is
261
+ * a human-known key instead (`repository_name`, `template_key`, `scope`, a
262
+ * `slug`/`code`) is caller-supplied, so its absence of a producer is not a gap.
263
+ */
264
+ function isIdLikeParam(name) {
265
+ return /(^id$)|(_id$)|([a-z]Id$)|(^uuid$)|(_uuid$)|([a-z]Uuid$)/.test(name);
266
+ }
267
+ function analyzeConsumability(document) {
268
+ // ONE producer model, shared with the tool surface — so the report never
269
+ // claims an input is navigable that the tools give no producer hint for.
270
+ const { endpoints, roleOf, producerOf, readableResources, nested } = producerIndex(document);
271
+ const isReadTool = (e) => {
272
+ const role = roleOf.get(e);
273
+ return role !== undefined && READ_ROLES.has(role);
274
+ };
275
+ // Classify every id input once, then aggregate purely (no mutable counters).
276
+ const inputs = endpoints.flatMap((e) => e.parameters.map((p) => {
277
+ const resource = resourceOfParam(e.path, p.name);
278
+ const ref = { tool: e.accessor.join("."), param: p.name, resource: resource !== null && resource !== void 0 ? resource : "?" };
279
+ const status = resource !== null && producerOf.has(resource)
280
+ ? "resolved"
281
+ : resource !== null && nested.has(resource.toLowerCase())
282
+ ? "nested"
283
+ : // a non-id param (`username`, `scope`, `*_name`) is a caller-known
284
+ // key regardless of whether its resource is readable — not a gap.
285
+ !isIdLikeParam(p.name)
286
+ ? "userInput"
287
+ : // an entity id: readable resource but no producer traced =
288
+ // undetermined; never read at all = a genuine orphan.
289
+ resource !== null && readableResources.has(resource)
290
+ ? "untraceable"
291
+ : "orphan";
292
+ return Object.assign(Object.assign({}, ref), { status });
293
+ }));
294
+ const readTools = endpoints.filter(isReadTool).length;
295
+ return {
296
+ tools: endpoints.length,
297
+ readTools,
298
+ writeTools: endpoints.length - readTools,
299
+ referenceInputs: inputs.length,
300
+ resolved: inputs.filter((i) => i.status === "resolved").length,
301
+ nested: inputs.filter((i) => i.status === "nested").length,
302
+ untraceable: inputs
303
+ .filter((i) => i.status === "untraceable")
304
+ .map(({ tool, param, resource }) => ({ tool, param, resource })),
305
+ userInputs: inputs
306
+ .filter((i) => i.status === "userInput")
307
+ .map(({ tool, param, resource }) => ({ tool, param, resource })),
308
+ orphan: inputs
309
+ .filter((i) => i.status === "orphan")
310
+ .map(({ tool, param, resource }) => ({ tool, param, resource })),
311
+ };
312
+ }
313
+ /**
314
+ * Deterministic structural coverage of a tool surface — the LLM-independent
315
+ * verification: is the tool graph navigable (every id input has a declared
316
+ * producer)? Reported as a report card, distinct from running an agent.
317
+ */
318
+ function coverToolSurface(tools) {
319
+ // Classify every path param once, then aggregate purely (no mutable counters).
320
+ const inputs = tools.flatMap((t) => {
321
+ const producerParams = new Set(t.producers.map((p) => p.param));
322
+ return t.operation.pathParams.map((param) => ({
323
+ tool: t.name,
324
+ param,
325
+ resolved: producerParams.has(param),
326
+ }));
327
+ });
328
+ const readTools = tools.filter((t) => t.annotations.readOnlyHint).length;
329
+ const resolvedInputs = inputs.filter((i) => i.resolved).length;
330
+ return {
331
+ tools: tools.length,
332
+ readTools,
333
+ writeTools: tools.length - readTools,
334
+ referenceInputs: inputs.length,
335
+ resolvedInputs,
336
+ orphanInputs: inputs.length - resolvedInputs,
337
+ orphans: inputs
338
+ .filter((i) => !i.resolved)
339
+ .map(({ tool, param }) => ({ tool, param })),
340
+ };
341
+ }
342
+ //# sourceMappingURL=toolSurface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolSurface.js","sourceRoot":"","sources":["../../src/agent/toolSurface.ts"],"names":[],"mappings":";;AAyRA,4CAyEC;AA4CD,oDAoDC;AA2BD,4CAuBC;AAlfD,kEAGoC;AACpC,0DAKgC;AAChC,sDAAsE;AAoDtE,MAAM,UAAU,GAAG,IAAI,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
+ * Behavioral verification of an agent tool surface — the trust layer.
5
+ *
6
+ * The consumability report proves the surface is *structurally* navigable
7
+ * (every id has a producer). This proves it *behaviorally*: a real agent, given
8
+ * the tools, completes named tasks end-to-end against the live backend. It is
9
+ * how "the API works for an agent" is demonstrated rather than asserted — the
10
+ * agent analogue of the frontend's workflow verifier.
11
+ *
12
+ * The deterministic parts (tool conversion + HTTP execution) are pure and
13
+ * unit-tested; the agent loop is driven by a configurable model (the operator's
14
+ * choice via env / opts), since which model an API's agents will use is the
15
+ * operator's call, not ours.
16
+ */
17
+ /** OpenAI / OpenRouter function-calling tool shape. */
18
+ export interface IFunctionTool {
19
+ type: "function";
20
+ function: {
21
+ name: string;
22
+ description: string;
23
+ parameters: object;
24
+ };
25
+ }
26
+ /** OpenAI function names allow only `[a-zA-Z0-9_-]` — the dotted accessor (fine
27
+ * for MCP) is not valid, so sanitize for the function-calling path. */
28
+ export declare const functionName: (toolName: string) => string;
29
+ /** Convert the agent tool surface to OpenAI function-calling tools. */
30
+ export declare function toFunctionTools(tools: IAgentTool[]): IFunctionTool[];
31
+ /**
32
+ * Execute one tool call against a live backend: substitute path params, attach
33
+ * query / body, issue the HTTP request, return the response text. Pure aside
34
+ * from the network call — deterministic in how it maps a call to a request.
35
+ */
36
+ export declare function executeToolCall(tools: IAgentTool[], name: string, args: Record<string, unknown>, opts: {
37
+ baseUrl: string;
38
+ auth?: string;
39
+ }): Promise<{
40
+ ok: boolean;
41
+ text: string;
42
+ }>;
43
+ export interface IAgentTask {
44
+ id: string;
45
+ prompt: string;
46
+ /** Optional success predicate over the agent's final answer (e.g. contains a known value). */
47
+ expect?: (answer: string) => boolean;
48
+ }
49
+ export interface IAgentTaskResult {
50
+ id: string;
51
+ answer: string;
52
+ toolCalls: string[];
53
+ passed: boolean | null;
54
+ }
55
+ /** Minimal OpenAI-compatible client surface this verifier needs (so the SDK is injected, not imported). */
56
+ export interface IChatClient {
57
+ chat: {
58
+ completions: {
59
+ create(req: unknown): Promise<{
60
+ choices: Array<{
61
+ message: {
62
+ content: string | null;
63
+ tool_calls?: Array<{
64
+ id: string;
65
+ function: {
66
+ name: string;
67
+ arguments: string;
68
+ };
69
+ }>;
70
+ };
71
+ }>;
72
+ }>;
73
+ };
74
+ };
75
+ }
76
+ /**
77
+ * Run the agent through each task against the tool surface + backend. The chat
78
+ * client and model are injected by the caller (configurable, e.g. from `.env`).
79
+ */
80
+ export declare function verifyAgentTasks(document: OpenApi.IDocument, opts: {
81
+ client: IChatClient;
82
+ model: string;
83
+ baseUrl: string;
84
+ auth?: string;
85
+ tasks: IAgentTask[];
86
+ maxTurns?: number;
87
+ }): Promise<IAgentTaskResult[]>;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.functionName = void 0;
13
+ exports.toFunctionTools = toFunctionTools;
14
+ exports.executeToolCall = executeToolCall;
15
+ exports.verifyAgentTasks = verifyAgentTasks;
16
+ const toolSurface_1 = require("./toolSurface");
17
+ /** OpenAI function names allow only `[a-zA-Z0-9_-]` — the dotted accessor (fine
18
+ * for MCP) is not valid, so sanitize for the function-calling path. */
19
+ const functionName = (toolName) => toolName.replace(/[^A-Za-z0-9_-]/g, "_");
20
+ exports.functionName = functionName;
21
+ /** Convert the agent tool surface to OpenAI function-calling tools. */
22
+ function toFunctionTools(tools) {
23
+ return tools.map((t) => ({
24
+ type: "function",
25
+ function: {
26
+ name: (0, exports.functionName)(t.name),
27
+ description: t.description,
28
+ parameters: t.inputSchema,
29
+ },
30
+ }));
31
+ }
32
+ /**
33
+ * Execute one tool call against a live backend: substitute path params, attach
34
+ * query / body, issue the HTTP request, return the response text. Pure aside
35
+ * from the network call — deterministic in how it maps a call to a request.
36
+ */
37
+ function executeToolCall(tools, name, args, opts) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ var _a, _b;
40
+ const tool = tools.find((t) => t.name === name);
41
+ if (tool === undefined)
42
+ return { ok: false, text: `unknown tool: ${name}` };
43
+ let path = tool.operation.path;
44
+ for (const p of tool.operation.pathParams) {
45
+ path = path.replace(`{${p}}`, encodeURIComponent(String((_a = args[p]) !== null && _a !== void 0 ? _a : "")));
46
+ }
47
+ const url = new URL(opts.baseUrl.replace(/\/$/, "") + path);
48
+ if (tool.operation.hasQuery && args.query && typeof args.query === "object") {
49
+ for (const [k, v] of Object.entries(args.query)) {
50
+ if (v !== undefined && v !== null)
51
+ url.searchParams.set(k, String(v));
52
+ }
53
+ }
54
+ const method = tool.operation.method;
55
+ try {
56
+ const res = yield fetch(url, {
57
+ method,
58
+ headers: Object.assign({ "content-type": "application/json" }, (opts.auth ? { authorization: opts.auth } : {})),
59
+ body: ["GET", "HEAD", "DELETE"].includes(method) ? undefined : JSON.stringify((_b = args.body) !== null && _b !== void 0 ? _b : {}),
60
+ });
61
+ const text = yield res.text();
62
+ return { ok: res.ok, text };
63
+ }
64
+ catch (err) {
65
+ return { ok: false, text: `request failed: ${err instanceof Error ? err.message : String(err)}` };
66
+ }
67
+ });
68
+ }
69
+ /**
70
+ * Run the agent through each task against the tool surface + backend. The chat
71
+ * client and model are injected by the caller (configurable, e.g. from `.env`).
72
+ */
73
+ function verifyAgentTasks(document, opts) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ var _a, _b, _c;
76
+ const tools = (0, toolSurface_1.buildToolSurface)(document);
77
+ const fnTools = toFunctionTools(tools);
78
+ // function-calling sanitizes dotted names → map the sanitized name the model
79
+ // calls back to the real tool for execution.
80
+ const byFnName = new Map(tools.map((t) => [(0, exports.functionName)(t.name), t.name]));
81
+ const maxTurns = (_a = opts.maxTurns) !== null && _a !== void 0 ? _a : 10;
82
+ const results = [];
83
+ for (const task of opts.tasks) {
84
+ const messages = [
85
+ { role: "system", content: "You are an API agent. Use the provided tools to complete the task, then reply in plain text with the answer. Never ask the user questions." },
86
+ { role: "user", content: task.prompt },
87
+ ];
88
+ const toolCalls = [];
89
+ let answer = "(no answer)";
90
+ for (let turn = 0; turn < maxTurns; turn++) {
91
+ const resp = yield opts.client.chat.completions.create({
92
+ model: opts.model,
93
+ messages,
94
+ tools: fnTools,
95
+ tool_choice: "auto",
96
+ temperature: 0,
97
+ });
98
+ const msg = resp.choices[0].message;
99
+ messages.push(msg);
100
+ if (msg.tool_calls === undefined || msg.tool_calls.length === 0) {
101
+ answer = (_b = msg.content) !== null && _b !== void 0 ? _b : "";
102
+ break;
103
+ }
104
+ for (const tc of msg.tool_calls) {
105
+ let args = {};
106
+ try {
107
+ args = JSON.parse(tc.function.arguments || "{}");
108
+ }
109
+ catch ( /* keep {} */_d) { /* keep {} */ }
110
+ const realName = (_c = byFnName.get(tc.function.name)) !== null && _c !== void 0 ? _c : tc.function.name;
111
+ const result = yield executeToolCall(tools, realName, args, { baseUrl: opts.baseUrl, auth: opts.auth });
112
+ toolCalls.push(realName);
113
+ messages.push({ role: "tool", tool_call_id: tc.id, content: result.text.slice(0, 2500) });
114
+ }
115
+ }
116
+ results.push({
117
+ id: task.id,
118
+ answer,
119
+ toolCalls,
120
+ passed: task.expect ? task.expect(answer) : null,
121
+ });
122
+ }
123
+ return results;
124
+ });
125
+ }
126
+ //# sourceMappingURL=verifyAgentTasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyAgentTasks.js","sourceRoot":"","sources":["../../src/agent/verifyAgentTasks.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+BA,0CASC;AAOD,0CA8BC;AAoCD,4CAy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