claude-flow-novice 1.6.1 → 1.6.2

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 (244) hide show
  1. package/.claude/agents/cfn-loop/product-owner.md +54 -4
  2. package/.claude/commands/cfn-claude-sync.md +303 -0
  3. package/.claude/commands/cfn-loop-epic.md +290 -0
  4. package/.claude/commands/cfn-loop-single.md +168 -0
  5. package/.claude/commands/cfn-loop-sprints.md +384 -0
  6. package/.claude/commands/cfn-loop.md +180 -0
  7. package/.claude/commands/metrics-summary.md +58 -0
  8. package/.claude/commands/parse-epic.md +357 -0
  9. package/.claude/settings.json +4 -4
  10. package/.claude/settings.local.json +9 -2
  11. package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
  12. package/.claude-flow-novice/dist/mcp/server.js +21 -2
  13. package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
  14. package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
  15. package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
  16. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
  17. package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
  18. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
  19. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  20. package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
  21. package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
  22. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
  23. package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
  24. package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
  25. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
  26. package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
  27. package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
  28. package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
  29. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
  30. package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
  31. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
  32. package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
  33. package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
  34. package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
  35. package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
  36. package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
  37. package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
  38. package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
  39. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
  40. package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
  41. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
  42. package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
  43. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
  44. package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
  45. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
  46. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
  47. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
  48. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
  49. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
  50. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
  51. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
  52. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
  53. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
  54. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
  55. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
  56. package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
  57. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
  58. package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
  59. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
  60. package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
  61. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
  62. package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
  63. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
  64. package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
  65. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
  66. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
  67. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
  68. package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
  69. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
  70. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
  71. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
  72. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
  73. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
  74. package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
  75. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
  76. package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
  77. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
  78. package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
  79. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
  80. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
  81. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
  82. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
  83. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
  84. package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
  85. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
  86. package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
  87. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
  88. package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
  89. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
  90. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
  91. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
  92. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
  93. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
  94. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
  95. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
  96. package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
  97. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
  98. package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
  99. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
  100. package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
  101. package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
  102. package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
  103. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
  104. package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
  105. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
  106. package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
  107. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
  108. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
  109. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
  110. package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
  111. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
  112. package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
  113. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
  114. package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
  115. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
  116. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
  117. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
  118. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
  119. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
  120. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
  121. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
  122. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
  123. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
  124. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
  125. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
  126. package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
  127. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
  128. package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
  129. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
  130. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
  131. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
  132. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
  133. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
  134. package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
  135. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
  136. package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
  137. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
  138. package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
  139. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
  140. package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
  141. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
  142. package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
  143. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
  144. package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
  145. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
  146. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
  147. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
  148. package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
  149. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
  150. package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
  151. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
  152. package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
  153. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
  154. package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
  155. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
  156. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
  157. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
  158. package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
  159. package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
  160. package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
  161. package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
  162. package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
  163. package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
  164. package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
  165. package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
  166. package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
  167. package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
  168. package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
  169. package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
  170. package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
  171. package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
  172. package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
  173. package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
  174. package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
  175. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
  176. package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
  177. package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
  178. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
  179. package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
  180. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
  181. package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
  182. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
  183. package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
  184. package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
  185. package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
  186. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
  187. package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
  188. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
  189. package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
  190. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
  191. package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
  192. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
  193. package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
  194. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
  195. package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
  196. package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
  197. package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
  198. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
  199. package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
  200. package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
  201. package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
  202. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
  203. package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
  204. package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
  205. package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
  206. package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
  207. package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
  208. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
  209. package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
  210. package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
  211. package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
  212. package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
  213. package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
  214. package/.claude-flow-novice/metrics.db +0 -0
  215. package/.claude-flow-novice/metrics.db-shm +0 -0
  216. package/.claude-flow-novice/metrics.db-wal +0 -0
  217. package/CLAUDE.md +29 -0
  218. package/README.md +27 -0
  219. package/config/hooks/post-edit-pipeline.js +36 -2
  220. package/examples/metrics-counter-demo.ts +106 -0
  221. package/examples/persistent-metrics-demo.ts +83 -0
  222. package/examples/phase-5-multi-level-control.ts +282 -0
  223. package/examples/session-pool-optimizer-example.ts +311 -0
  224. package/package.json +15 -3
  225. package/scripts/check-routing-stats.cjs +122 -0
  226. package/scripts/pre-publish-validation.cjs +212 -0
  227. package/scripts/test-provider-routing.cjs +228 -0
  228. package/scripts/test-routing-telemetry.cjs +147 -0
  229. package/scripts/test-zai-10k.cjs +81 -0
  230. package/scripts/test-zai-api.cjs +191 -0
  231. package/scripts/test-zai-diagnostic.cjs +151 -0
  232. package/scripts/test-zai-final.cjs +128 -0
  233. package/scripts/test-zai-with-env.cjs +85 -0
  234. package/scripts/validate-coordination-cli.js +69 -0
  235. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  236. package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
  237. package/src/observability/metrics-counter.ts +347 -0
  238. package/src/observability/metrics-storage.ts +356 -0
  239. package/src/observability/telemetry.ts +658 -0
  240. package/src/slash-commands/cfn-claude-sync.js +533 -0
  241. package/src/slash-commands/index.js +5 -0
  242. package/src/slash-commands/metrics-summary-class.js +74 -0
  243. package/src/slash-commands/metrics-summary.js +335 -0
  244. package/src/slash-commands/register-all-commands.js +12 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/web/api/middleware/cache.ts"],"names":["cacheMiddleware","cache","defaultTtl","req","res","next","method","cacheKey","generateCacheKey","cached","get","Date","now","timestamp","ttl","setHeader","Math","floor","etag","json","data","originalJson","statusCode","getCacheTtl","generateETag","set","call","url","URL","originalUrl","headers","host","queryParams","URLSearchParams","search","sort","queryString","toString","path","pathname","userId","user","id","includes","crypto","require","hash","createHash","update","JSON","stringify","digest","conditionalRequest","ifNoneMatch","invalidateCache","pattern","getInvalidationPattern","key","keys","delete","warmCache","warmupFn","size","error","console","MemoryCache","Map","maxSize","cleanupInterval","cleanupIntervalMs","setInterval","cleanup","entry","undefined","oldestKey","value","clear","getStats","entries","Array","from","map","age","length","keysToDelete","push","destroy","clearInterval"],"mapp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3B;IAEA;;GAEC,GACDmB,QAAc;QACZ,IAAI,CAAC3E,KAAK,CAAC2E,KAAK;IAClB;IAEA;;GAEC,GACDd,OAAe;QACb,OAAO,IAAI,CAAC7D,KAAK,CAAC6D,IAAI;IACxB;IAEA;;GAEC,GACDe,WASE;QACA,MAAMC,UAAUC,MAAMC,IAAI,CAAC,IAAI,CAAC/E,KAAK,CAAC6E,OAAO,IAAIG,GAAG,CAAC,CAAC,CAACxB,KAAKe,MAAM,GAAM,CAAA;gBACtEf;gBACAyB,KAAKvE,KAAKC,GAAG,KAAK4D,MAAM3D,SAAS;gBACjCC,KAAK0D,MAAM1D,GAAG;gBACdgD,MAAMb,KAAKC,SAAS,CAACsB,MAAMpD,IAAI,EAAE+D,MAAM;YACzC,CAAA;QAEA,OAAO;YACLrB,MAAM,IAAI,CAAC7D,KAAK,CAAC6D,IAAI;YACrBK,SAAS,IAAI,CAACA,OAAO;YACrBW;QACF;IACF;IAEA;;GAEC,GACD,AAAQP,UAAgB;QACtB,MAAM3D,MAAMD,KAAKC,GAAG;QACpB,MAAMwE,eAAyB,EAAE;QAEjC,KAAK,MAAM,CAAC3B,KAAKe,MAAM,IAAI,IAAI,CAACvE,KAAK,CAAC6E,OAAO,GAAI;YAC/C,IAAIlE,MAAM4D,MAAM3D,SAAS,IAAI2D,MAAM1D,GAAG,EAAE;gBACtCsE,aAAaC,IAAI,CAAC5B;YACpB;QACF;QAEA,KAAK,MAAMA,OAAO2B,aAAc;YAC9B,IAAI,CAACnF,KAAK,CAAC0D,MAAM,CAACF;QACpB;IACF;IAEA;;GAEC,GACD6B,UAAgB;QACd,IAAI,IAAI,CAAClB,eAAe,EAAE;YACxBmB,cAAc,IAAI,CAACnB,eAAe;QACpC;QACA,IAAI,CAACQ,KAAK;IACZ;AACF"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Error Handler Middleware
3
+ *
4
+ * Centralized error handling for the transparency API server
5
+ *
6
+ * @module web/api/middleware/error-handler
7
+ */ /**
8
+ * API Error class
9
+ */ export class ApiError extends Error {
10
+ statusCode;
11
+ isOperational;
12
+ code;
13
+ details;
14
+ constructor(message, statusCode = 500, isOperational = true, code, details){
15
+ super(message);
16
+ this.name = 'ApiError';
17
+ this.statusCode = statusCode;
18
+ this.isOperational = isOperational;
19
+ this.code = code;
20
+ this.details = details;
21
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
22
+ if (Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, ApiError);
24
+ }
25
+ }
26
+ }
27
+ /**
28
+ * Validation Error class
29
+ */ export class ValidationError extends ApiError {
30
+ constructor(message, details){
31
+ super(message, 400, true, 'VALIDATION_ERROR', details);
32
+ this.name = 'ValidationError';
33
+ }
34
+ }
35
+ /**
36
+ * Not Found Error class
37
+ */ export class NotFoundError extends ApiError {
38
+ constructor(resource, id){
39
+ const message = id ? `${resource} with id '${id}' not found` : `${resource} not found`;
40
+ super(message, 404, true, 'NOT_FOUND', {
41
+ resource,
42
+ id
43
+ });
44
+ this.name = 'NotFoundError';
45
+ }
46
+ }
47
+ /**
48
+ * Unauthorized Error class
49
+ */ export class UnauthorizedError extends ApiError {
50
+ constructor(message = 'Unauthorized'){
51
+ super(message, 401, true, 'UNAUTHORIZED');
52
+ this.name = 'UnauthorizedError';
53
+ }
54
+ }
55
+ /**
56
+ * Forbidden Error class
57
+ */ export class ForbiddenError extends ApiError {
58
+ constructor(message = 'Forbidden'){
59
+ super(message, 403, true, 'FORBIDDEN');
60
+ this.name = 'ForbiddenError';
61
+ }
62
+ }
63
+ /**
64
+ * Rate Limit Error class
65
+ */ export class RateLimitError extends ApiError {
66
+ constructor(message = 'Rate limit exceeded'){
67
+ super(message, 429, true, 'RATE_LIMIT_EXCEEDED');
68
+ this.name = 'RateLimitError';
69
+ }
70
+ }
71
+ /**
72
+ * Error Handler Middleware Factory
73
+ */ export function errorHandler(logger) {
74
+ return (err, req, res, next)=>{
75
+ // Default error values
76
+ let statusCode = 500;
77
+ let errorCode = 'INTERNAL_SERVER_ERROR';
78
+ let message = 'Internal server error';
79
+ let details = undefined;
80
+ let isOperational = false;
81
+ // Handle known error types
82
+ if (err instanceof ApiError) {
83
+ statusCode = err.statusCode;
84
+ errorCode = err.code || 'API_ERROR';
85
+ message = err.message;
86
+ details = err.details;
87
+ isOperational = err.isOperational;
88
+ } else if (err.name === 'ValidationError') {
89
+ statusCode = 400;
90
+ errorCode = 'VALIDATION_ERROR';
91
+ message = err.message;
92
+ isOperational = true;
93
+ } else if (err.name === 'CastError') {
94
+ statusCode = 400;
95
+ errorCode = 'INVALID_ID';
96
+ message = 'Invalid ID format';
97
+ isOperational = true;
98
+ } else if (err.name === 'JsonWebTokenError') {
99
+ statusCode = 401;
100
+ errorCode = 'INVALID_TOKEN';
101
+ message = 'Invalid authentication token';
102
+ isOperational = true;
103
+ } else if (err.name === 'TokenExpiredError') {
104
+ statusCode = 401;
105
+ errorCode = 'TOKEN_EXPIRED';
106
+ message = 'Authentication token expired';
107
+ isOperational = true;
108
+ } else if (err.name === 'MulterError') {
109
+ statusCode = 400;
110
+ errorCode = 'FILE_UPLOAD_ERROR';
111
+ message = 'File upload error';
112
+ isOperational = true;
113
+ } else if (err.name === 'SyntaxError' && err.type === 'entity.parse.failed') {
114
+ statusCode = 400;
115
+ errorCode = 'INVALID_JSON';
116
+ message = 'Invalid JSON in request body';
117
+ isOperational = true;
118
+ }
119
+ // Log error
120
+ const logData = {
121
+ error: {
122
+ name: err.name,
123
+ message: err.message,
124
+ code: errorCode,
125
+ statusCode,
126
+ isOperational,
127
+ stack: err.stack
128
+ },
129
+ request: {
130
+ method: req.method,
131
+ url: req.originalUrl,
132
+ ip: req.ip,
133
+ userAgent: req.get('User-Agent'),
134
+ user: req.user?.id || 'anonymous'
135
+ },
136
+ details
137
+ };
138
+ if (isOperational) {
139
+ logger.warn('Operational error', logData);
140
+ } else {
141
+ logger.error('Non-operational error', logData);
142
+ }
143
+ // Build error response
144
+ const errorResponse = {
145
+ error: errorCode,
146
+ message,
147
+ timestamp: new Date().toISOString(),
148
+ requestId: req.requestId || 'unknown'
149
+ };
150
+ // Include details in development or for operational errors
151
+ if (process.env.NODE_ENV === 'development' || isOperational) {
152
+ if (details) {
153
+ errorResponse.details = details;
154
+ }
155
+ if (process.env.NODE_ENV === 'development') {
156
+ errorResponse.stack = err.stack;
157
+ }
158
+ }
159
+ // Include request path for debugging
160
+ if (process.env.NODE_ENV === 'development') {
161
+ errorResponse.path = req.path;
162
+ errorResponse.method = req.method;
163
+ }
164
+ res.status(statusCode).json(errorResponse);
165
+ };
166
+ }
167
+ /**
168
+ * Async Error Wrapper
169
+ *
170
+ * Wraps async route handlers to automatically catch errors
171
+ */ export function asyncHandler(fn) {
172
+ return (req, res, next)=>{
173
+ Promise.resolve(fn(req, res, next)).catch(next);
174
+ };
175
+ }
176
+ /**
177
+ * 404 Handler
178
+ */ export function notFoundHandler(req, res) {
179
+ res.status(404).json({
180
+ error: 'NOT_FOUND',
181
+ message: `Endpoint ${req.method} ${req.originalUrl} not found`,
182
+ timestamp: new Date().toISOString()
183
+ });
184
+ }
185
+ /**
186
+ * Create error from validation result
187
+ */ export function createValidationError(validationResult) {
188
+ const details = validationResult.errors?.map((error)=>({
189
+ field: error.path || error.field,
190
+ message: error.message,
191
+ value: error.value
192
+ }));
193
+ return new ValidationError('Validation failed', details);
194
+ }
195
+ /**
196
+ * Handle Prisma errors (if using Prisma ORM)
197
+ */ export function handlePrismaError(err) {
198
+ switch(err.code){
199
+ case 'P2002':
200
+ return new ApiError('Unique constraint violation', 409, true, 'UNIQUE_VIOLATION', {
201
+ target: err.meta?.target
202
+ });
203
+ case 'P2025':
204
+ return new NotFoundError('Record', err.meta?.cause);
205
+ case 'P2003':
206
+ return new ValidationError('Foreign key constraint violation', {
207
+ field: err.meta?.field_name
208
+ });
209
+ case 'P2014':
210
+ return new ApiError('Relation violation', 400, true, 'RELATION_VIOLATION', {
211
+ relation: err.meta?.relation_name
212
+ });
213
+ case 'P2021':
214
+ return new ApiError('Table does not exist', 500, false, 'TABLE_NOT_FOUND', {
215
+ table: err.meta?.table
216
+ });
217
+ default:
218
+ return new ApiError('Database error', 500, false, 'DATABASE_ERROR', {
219
+ code: err.code,
220
+ message: err.message
221
+ });
222
+ }
223
+ }
224
+ /**
225
+ * Handle Mongoose errors (if using Mongoose ODM)
226
+ */ export function handleMongooseError(err) {
227
+ if (err.name === 'ValidationError') {
228
+ const details = Object.keys(err.errors).map((key)=>({
229
+ field: key,
230
+ message: err.errors[key].message,
231
+ value: err.errors[key].value
232
+ }));
233
+ return new ValidationError('Validation failed', details);
234
+ }
235
+ if (err.name === 'CastError') {
236
+ return new ValidationError(`Invalid ${err.path}: ${err.value}`);
237
+ }
238
+ if (err.code === 11000) {
239
+ const field = Object.keys(err.keyPattern)[0];
240
+ return new ApiError('Duplicate field value', 409, true, 'DUPLICATE_FIELD', {
241
+ field
242
+ });
243
+ }
244
+ return new ApiError('Database error', 500, false, 'DATABASE_ERROR', {
245
+ name: err.name,
246
+ message: err.message
247
+ });
248
+ }
249
+
250
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/web/api/middleware/error-handler.ts"],"names":["ApiError","Error","statusCode","isOperational","code","details","message","name","captureStackTrace","ValidationError","NotFoundError","resource","id","UnauthorizedError","ForbiddenError","RateLimitError","errorHandler","logger","err","req","res","next","errorCode","undefined","type","logData","error","stack","request","method","url","originalUrl","ip","userAgent","get","user","warn","errorResponse","timestamp","Date","toISOString","requestId","process","env","NODE_ENV","path","status","json","asyncHandler","fn","Promise","resolve","catch","notFoundHandler","createValidationError","validationResult","errors","map","field","value","handlePrismaError","target","meta","cause","field_name","relation","relation_name","table","handleMongooseError","Object","keys","key","keyPattern"],"mappings":"AAAA;;;;;;CAMC,GAMD;;CAEC,GACD,OAAO,MAAMA,iBAAiBC;IACrBC,WAAmB;IACnBC,cAAuB;IACvBC,KAAc;IACdC,QAAc;IAErB,YACEC,OAAe,EACfJ,aAAqB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AAI,CAACpD,IAAIsC,MAAM,EAAEC,GAAG,CAACc,CAAAA,MAAQ,CAAA;gBAClDb,OAAOa;gBACPjE,SAASY,IAAIsC,MAAM,CAACe,IAAI,CAACjE,OAAO;gBAChCqD,OAAOzC,IAAIsC,MAAM,CAACe,IAAI,CAACZ,KAAK;YAC9B,CAAA;QACA,OAAO,IAAIlD,gBAAgB,qBAAqBJ;IAClD;IAEA,IAAIa,IAAIX,IAAI,KAAK,aAAa;QAC5B,OAAO,IAAIE,gBAAgB,CAAC,QAAQ,EAAES,IAAI2B,IAAI,CAAC,EAAE,EAAE3B,IAAIyC,KAAK,EAAE;IAChE;IAEA,IAAIzC,IAAId,IAAI,KAAK,OAAO;QACtB,MAAMsD,QAAQW,OAAOC,IAAI,CAACpD,IAAIsD,UAAU,CAAC,CAAC,EAAE;QAC5C,OAAO,IAAIxE,SAAS,yBAAyB,KAAK,MAAM,mBAAmB;YAAE0D;QAAM;IACrF;IAEA,OAAO,IAAI1D,SAAS,kBAAkB,KAAK,OAAO,kBAAkB;QAClEO,MAAMW,IAAIX,IAAI;QACdD,SAASY,IAAIZ,OAAO;IACtB;AACF"}
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Request Logger Middleware
3
+ *
4
+ * HTTP request logging middleware for the transparency API server
5
+ *
6
+ * @module web/api/middleware/request-logger
7
+ */ import { v4 as uuidv4 } from 'uuid';
8
+ /**
9
+ * Request Logger Middleware Factory
10
+ */ export function requestLogger(logger) {
11
+ return (req, res, next)=>{
12
+ // Generate unique request ID
13
+ const requestId = uuidv4().slice(0, 8);
14
+ req.requestId = requestId;
15
+ req.startTime = Date.now();
16
+ // Set request ID in response headers
17
+ res.setHeader('X-Request-ID', requestId);
18
+ // Log request start
19
+ const requestLog = {
20
+ requestId,
21
+ method: req.method,
22
+ url: req.originalUrl,
23
+ ip: req.ip || req.connection.remoteAddress,
24
+ userAgent: req.get('User-Agent'),
25
+ contentLength: req.get('Content-Length') || 0,
26
+ contentType: req.get('Content-Type'),
27
+ referer: req.get('Referer'),
28
+ user: req.user?.id || 'anonymous',
29
+ timestamp: new Date().toISOString()
30
+ };
31
+ logger.info('Request started', requestLog);
32
+ // Override res.end to log response
33
+ const originalEnd = res.end;
34
+ res.end = function(...args) {
35
+ // Calculate duration
36
+ const duration = req.startTime ? Date.now() - req.startTime : 0;
37
+ // Log response
38
+ const responseLog = {
39
+ requestId,
40
+ method: req.method,
41
+ url: req.originalUrl,
42
+ statusCode: res.statusCode,
43
+ contentLength: res.get('Content-Length') || 0,
44
+ duration: `${duration}ms`,
45
+ ip: req.ip || req.connection.remoteAddress,
46
+ user: req.user?.id || 'anonymous',
47
+ timestamp: new Date().toISOString()
48
+ };
49
+ // Log based on status code
50
+ if (res.statusCode >= 500) {
51
+ logger.error('Request completed with server error', responseLog);
52
+ } else if (res.statusCode >= 400) {
53
+ logger.warn('Request completed with client error', responseLog);
54
+ } else if (res.statusCode >= 300) {
55
+ logger.info('Request completed with redirect', responseLog);
56
+ } else {
57
+ logger.info('Request completed successfully', responseLog);
58
+ }
59
+ // Call original end
60
+ originalEnd.apply(this, args);
61
+ };
62
+ next();
63
+ };
64
+ }
65
+ /**
66
+ * Performance Logger Middleware
67
+ *
68
+ * Logs slow requests and performance metrics
69
+ */ export function performanceLogger(logger, thresholdMs = 1000) {
70
+ return (req, res, next)=>{
71
+ const startTime = Date.now();
72
+ res.on('finish', ()=>{
73
+ const duration = Date.now() - startTime;
74
+ if (duration > thresholdMs) {
75
+ logger.warn('Slow request detected', {
76
+ requestId: req.requestId,
77
+ method: req.method,
78
+ url: req.originalUrl,
79
+ duration: `${duration}ms`,
80
+ threshold: `${thresholdMs}ms`,
81
+ statusCode: res.statusCode,
82
+ user: req.user?.id || 'anonymous'
83
+ });
84
+ }
85
+ });
86
+ next();
87
+ };
88
+ }
89
+ /**
90
+ * Security Logger Middleware
91
+ *
92
+ * Logs security-related events and suspicious activity
93
+ */ export function securityLogger(logger) {
94
+ return (req, res, next)=>{
95
+ // Log suspicious user agents
96
+ const userAgent = req.get('User-Agent') || '';
97
+ const suspiciousPatterns = [
98
+ /bot/i,
99
+ /crawler/i,
100
+ /scanner/i,
101
+ /sqlmap/i,
102
+ /nikto/i,
103
+ /nmap/i,
104
+ /curl/i,
105
+ /wget/i
106
+ ];
107
+ if (suspiciousPatterns.some((pattern)=>pattern.test(userAgent))) {
108
+ logger.warn('Suspicious user agent detected', {
109
+ requestId: req.requestId,
110
+ userAgent,
111
+ ip: req.ip,
112
+ url: req.originalUrl,
113
+ method: req.method,
114
+ timestamp: new Date().toISOString()
115
+ });
116
+ }
117
+ // Log requests to sensitive endpoints
118
+ const sensitiveEndpoints = [
119
+ '/api/v1/system',
120
+ '/api/v1/admin',
121
+ '/api/v1/users',
122
+ '/api/v1/auth'
123
+ ];
124
+ if (sensitiveEndpoints.some((endpoint)=>req.path.startsWith(endpoint))) {
125
+ logger.info('Access to sensitive endpoint', {
126
+ requestId: req.requestId,
127
+ endpoint: req.path,
128
+ method: req.method,
129
+ ip: req.ip,
130
+ user: req.user?.id || 'anonymous',
131
+ timestamp: new Date().toISOString()
132
+ });
133
+ }
134
+ // Log failed authentication attempts
135
+ res.on('finish', ()=>{
136
+ if (res.statusCode === 401 && req.path.includes('/auth')) {
137
+ logger.warn('Authentication failed', {
138
+ requestId: req.requestId,
139
+ path: req.path,
140
+ method: req.method,
141
+ ip: req.ip,
142
+ userAgent,
143
+ timestamp: new Date().toISOString()
144
+ });
145
+ }
146
+ // Log authorization failures
147
+ if (res.statusCode === 403) {
148
+ logger.warn('Authorization failed', {
149
+ requestId: req.requestId,
150
+ path: req.path,
151
+ method: req.method,
152
+ ip: req.ip,
153
+ user: req.user?.id || 'anonymous',
154
+ timestamp: new Date().toISOString()
155
+ });
156
+ }
157
+ });
158
+ next();
159
+ };
160
+ }
161
+ /**
162
+ * API Metrics Logger Middleware
163
+ *
164
+ * Logs API usage metrics for monitoring and analytics
165
+ */ export function metricsLogger(logger) {
166
+ const metrics = {
167
+ requests: 0,
168
+ errors: 0,
169
+ totalDuration: 0,
170
+ endpointCounts: new Map(),
171
+ methodCounts: new Map(),
172
+ statusCounts: new Map()
173
+ };
174
+ // Log metrics every 5 minutes
175
+ setInterval(()=>{
176
+ if (metrics.requests > 0) {
177
+ logger.info('API metrics summary', {
178
+ period: '5 minutes',
179
+ totalRequests: metrics.requests,
180
+ errorRate: `${(metrics.errors / metrics.requests * 100).toFixed(2)}%`,
181
+ averageDuration: `${(metrics.totalDuration / metrics.requests).toFixed(2)}ms`,
182
+ topEndpoints: Array.from(metrics.endpointCounts.entries()).sort((a, b)=>b[1] - a[1]).slice(0, 10),
183
+ methodDistribution: Object.fromEntries(metrics.methodCounts),
184
+ statusDistribution: Object.fromEntries(metrics.statusCounts)
185
+ });
186
+ // Reset metrics
187
+ metrics.requests = 0;
188
+ metrics.errors = 0;
189
+ metrics.totalDuration = 0;
190
+ metrics.endpointCounts.clear();
191
+ metrics.methodCounts.clear();
192
+ metrics.statusCounts.clear();
193
+ }
194
+ }, 5 * 60 * 1000);
195
+ return (req, res, next)=>{
196
+ const startTime = Date.now();
197
+ res.on('finish', ()=>{
198
+ const duration = Date.now() - startTime;
199
+ const endpoint = `${req.method} ${req.route?.path || req.path}`;
200
+ // Update metrics
201
+ metrics.requests++;
202
+ metrics.totalDuration += duration;
203
+ if (res.statusCode >= 400) {
204
+ metrics.errors++;
205
+ }
206
+ // Count endpoints
207
+ metrics.endpointCounts.set(endpoint, (metrics.endpointCounts.get(endpoint) || 0) + 1);
208
+ // Count methods
209
+ metrics.methodCounts.set(req.method, (metrics.methodCounts.get(req.method) || 0) + 1);
210
+ // Count status codes
211
+ metrics.statusCounts.set(res.statusCode, (metrics.statusCounts.get(res.statusCode) || 0) + 1);
212
+ });
213
+ next();
214
+ };
215
+ }
216
+
217
+ //# sourceMappingURL=request-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/web/api/middleware/request-logger.ts"],"names":["v4","uuidv4","requestLogger","logger","req","res","next","requestId","slice","startTime","Date","now","setHeader","requestLog","method","url","originalUrl","ip","connection","remoteAddress","userAgent","get","contentLength","contentType","referer","user","id","timestamp","toISOString","info","originalEnd","end","args","duration","responseLog","statusCode","error","warn","apply","performanceLogger","thresholdMs","on","threshold","securityLogger","suspiciousPatterns","some","pattern","test","sensitiveEndpoints","endpoint","path","startsWith","includes","metricsLogger","metrics","requests","errors","totalDuration","endpointCounts","Map","methodCounts","statusCounts","setInterval","period","totalRequests","errorRate","toFixed","averageDuration","topEndpoints","Array","from","entries","sort","a","b","methodDistribution","Object","fromEntries","statusDistribution","clear","route","set"],"mappings":"AAAA;;;;;;CAMC,GAGD,SAASA,MAAMC,MAAM,QAAQ,OAAO;AAWpC;;CAEC,GACD,OAAO,SAASC,cAAcC,MAAc;IAC1C,OAAO,CAACC,KAA0BC,KAAeC;QAC/C,6BAA6B;QAC7B,MAAMC,YAAYN,SAASO,KAAK,CAAC,GAAG;QACpCJ,IAAIG,SAAS,GAAGA;QAChBH,IAAIK,SAAS,GAAGC,KAAKC,GAAG;QAExB,qCAAqC;QACrCN,IAAIO,SAAS,CAAC,gBAAgBL;QAE9B,oBAAoB;QACpB,MAAMM,aAAa;YACjBN;YACAO,QAAQV,IAAIU,MAAM;YAClBC,KAAKX,IAAIY,WAAW;YACpBC,IAAIb,IAAIa,EAAE,IAAIb,IAAIc,UAAU,CAACC,aAAa;YAC1CC,WAAWhB,IAAIiB,GAAG,CAAC;YACnBC,eAAelB,IAAIiB,GAAG,CAAC,qBAAqB;YAC5CE,aAAanB,IAAIiB,GAAG,CAAC;YACrBG,SAASpB,IAAIiB,GAAG,CAAC;YACjBI,MAAM,AAACrB,IAAYqB,IAAI,EAAEC,MAAM;YAC/BC,WAAW,IAAIjB,OAAOkB,WAAW;QACnC;QAEAzB,OAAO0B,IAAI,CAAC,mBAAmBhB;QAE/B,mCAAmC;QACnC,MAAMiB,cAAczB,IAAI0B,GAAG;QAC3B1B,IAAI0B,GAAG,GAAG,SAAyB,GAA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