@amplitude/wizard 1.0.0-beta.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 (333) hide show
  1. package/LICENSE +47 -0
  2. package/README.md +119 -0
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +763 -0
  5. package/dist/package.json +144 -0
  6. package/dist/src/frameworks/android/android-wizard-agent.d.ts +6 -0
  7. package/dist/src/frameworks/android/android-wizard-agent.js +72 -0
  8. package/dist/src/frameworks/android/utils.d.ts +11 -0
  9. package/dist/src/frameworks/android/utils.js +32 -0
  10. package/dist/src/frameworks/django/django-wizard-agent.d.ts +8 -0
  11. package/dist/src/frameworks/django/django-wizard-agent.js +171 -0
  12. package/dist/src/frameworks/django/utils.d.ts +31 -0
  13. package/dist/src/frameworks/django/utils.js +305 -0
  14. package/dist/src/frameworks/fastapi/fastapi-wizard-agent.d.ts +11 -0
  15. package/dist/src/frameworks/fastapi/fastapi-wizard-agent.js +189 -0
  16. package/dist/src/frameworks/fastapi/utils.d.ts +26 -0
  17. package/dist/src/frameworks/fastapi/utils.js +257 -0
  18. package/dist/src/frameworks/flask/flask-wizard-agent.d.ts +8 -0
  19. package/dist/src/frameworks/flask/flask-wizard-agent.js +177 -0
  20. package/dist/src/frameworks/flask/utils.d.ts +28 -0
  21. package/dist/src/frameworks/flask/utils.js +343 -0
  22. package/dist/src/frameworks/flutter/flutter-wizard-agent.d.ts +4 -0
  23. package/dist/src/frameworks/flutter/flutter-wizard-agent.js +57 -0
  24. package/dist/src/frameworks/flutter/utils.d.ts +7 -0
  25. package/dist/src/frameworks/flutter/utils.js +64 -0
  26. package/dist/src/frameworks/generic/generic-wizard-agent.d.ts +2 -0
  27. package/dist/src/frameworks/generic/generic-wizard-agent.js +176 -0
  28. package/dist/src/frameworks/go/go-wizard-agent.d.ts +4 -0
  29. package/dist/src/frameworks/go/go-wizard-agent.js +57 -0
  30. package/dist/src/frameworks/go/utils.d.ts +5 -0
  31. package/dist/src/frameworks/go/utils.js +44 -0
  32. package/dist/src/frameworks/java/java-wizard-agent.d.ts +7 -0
  33. package/dist/src/frameworks/java/java-wizard-agent.js +73 -0
  34. package/dist/src/frameworks/java/utils.d.ts +15 -0
  35. package/dist/src/frameworks/java/utils.js +64 -0
  36. package/dist/src/frameworks/javascript-node/javascript-node-wizard-agent.d.ts +4 -0
  37. package/dist/src/frameworks/javascript-node/javascript-node-wizard-agent.js +57 -0
  38. package/dist/src/frameworks/javascript-web/javascript-web-wizard-agent.d.ts +3 -0
  39. package/dist/src/frameworks/javascript-web/javascript-web-wizard-agent.js +151 -0
  40. package/dist/src/frameworks/javascript-web/utils.d.ts +28 -0
  41. package/dist/src/frameworks/javascript-web/utils.js +153 -0
  42. package/dist/src/frameworks/nextjs/nextjs-wizard-agent.d.ts +7 -0
  43. package/dist/src/frameworks/nextjs/nextjs-wizard-agent.js +98 -0
  44. package/dist/src/frameworks/nextjs/utils.d.ts +12 -0
  45. package/dist/src/frameworks/nextjs/utils.js +51 -0
  46. package/dist/src/frameworks/python/python-wizard-agent.d.ts +7 -0
  47. package/dist/src/frameworks/python/python-wizard-agent.js +193 -0
  48. package/dist/src/frameworks/python/utils.d.ts +28 -0
  49. package/dist/src/frameworks/python/utils.js +146 -0
  50. package/dist/src/frameworks/react-native/react-native-wizard-agent.d.ts +6 -0
  51. package/dist/src/frameworks/react-native/react-native-wizard-agent.js +84 -0
  52. package/dist/src/frameworks/react-native/utils.d.ts +21 -0
  53. package/dist/src/frameworks/react-native/utils.js +82 -0
  54. package/dist/src/frameworks/react-router/react-router-wizard-agent.d.ts +7 -0
  55. package/dist/src/frameworks/react-router/react-router-wizard-agent.js +98 -0
  56. package/dist/src/frameworks/react-router/utils.d.ts +13 -0
  57. package/dist/src/frameworks/react-router/utils.js +160 -0
  58. package/dist/src/frameworks/swift/swift-wizard-agent.d.ts +7 -0
  59. package/dist/src/frameworks/swift/swift-wizard-agent.js +72 -0
  60. package/dist/src/frameworks/swift/utils.d.ts +12 -0
  61. package/dist/src/frameworks/swift/utils.js +82 -0
  62. package/dist/src/frameworks/unity/unity-wizard-agent.d.ts +6 -0
  63. package/dist/src/frameworks/unity/unity-wizard-agent.js +79 -0
  64. package/dist/src/frameworks/unity/utils.d.ts +12 -0
  65. package/dist/src/frameworks/unity/utils.js +66 -0
  66. package/dist/src/frameworks/unreal/unreal-wizard-agent.d.ts +6 -0
  67. package/dist/src/frameworks/unreal/unreal-wizard-agent.js +77 -0
  68. package/dist/src/frameworks/unreal/utils.d.ts +10 -0
  69. package/dist/src/frameworks/unreal/utils.js +29 -0
  70. package/dist/src/frameworks/vue/vue-wizard-agent.d.ts +4 -0
  71. package/dist/src/frameworks/vue/vue-wizard-agent.js +64 -0
  72. package/dist/src/lib/agent-hooks.d.ts +26 -0
  73. package/dist/src/lib/agent-hooks.js +118 -0
  74. package/dist/src/lib/agent-interface.d.ts +175 -0
  75. package/dist/src/lib/agent-interface.js +1217 -0
  76. package/dist/src/lib/agent-runner.d.ts +9 -0
  77. package/dist/src/lib/agent-runner.js +415 -0
  78. package/dist/src/lib/ampli-config.d.ts +105 -0
  79. package/dist/src/lib/ampli-config.js +178 -0
  80. package/dist/src/lib/api.d.ts +107 -0
  81. package/dist/src/lib/api.js +442 -0
  82. package/dist/src/lib/commandments.d.ts +1 -0
  83. package/dist/src/lib/commandments.js +24 -0
  84. package/dist/src/lib/console-query.d.ts +27 -0
  85. package/dist/src/lib/console-query.js +121 -0
  86. package/dist/src/lib/constants.d.ts +124 -0
  87. package/dist/src/lib/constants.js +170 -0
  88. package/dist/src/lib/detect-amplitude.d.ts +31 -0
  89. package/dist/src/lib/detect-amplitude.js +407 -0
  90. package/dist/src/lib/framework-config.d.ts +188 -0
  91. package/dist/src/lib/framework-config.js +21 -0
  92. package/dist/src/lib/health-checks/endpoints.d.ts +3 -0
  93. package/dist/src/lib/health-checks/endpoints.js +45 -0
  94. package/dist/src/lib/health-checks/index.d.ts +4 -0
  95. package/dist/src/lib/health-checks/index.js +22 -0
  96. package/dist/src/lib/health-checks/readiness.d.ts +24 -0
  97. package/dist/src/lib/health-checks/readiness.js +118 -0
  98. package/dist/src/lib/health-checks/statuspage.d.ts +9 -0
  99. package/dist/src/lib/health-checks/statuspage.js +104 -0
  100. package/dist/src/lib/health-checks/types.d.ts +31 -0
  101. package/dist/src/lib/health-checks/types.js +9 -0
  102. package/dist/src/lib/helper-functions.d.ts +1 -0
  103. package/dist/src/lib/helper-functions.js +5 -0
  104. package/dist/src/lib/middleware/benchmark.d.ts +54 -0
  105. package/dist/src/lib/middleware/benchmark.js +48 -0
  106. package/dist/src/lib/middleware/benchmarks/cache-tracker.d.ts +44 -0
  107. package/dist/src/lib/middleware/benchmarks/cache-tracker.js +80 -0
  108. package/dist/src/lib/middleware/benchmarks/compaction-tracker.d.ts +29 -0
  109. package/dist/src/lib/middleware/benchmarks/compaction-tracker.js +59 -0
  110. package/dist/src/lib/middleware/benchmarks/context-size-tracker.d.ts +26 -0
  111. package/dist/src/lib/middleware/benchmarks/context-size-tracker.js +55 -0
  112. package/dist/src/lib/middleware/benchmarks/cost-tracker.d.ts +16 -0
  113. package/dist/src/lib/middleware/benchmarks/cost-tracker.js +75 -0
  114. package/dist/src/lib/middleware/benchmarks/duration-tracker.d.ts +20 -0
  115. package/dist/src/lib/middleware/benchmarks/duration-tracker.js +39 -0
  116. package/dist/src/lib/middleware/benchmarks/index.d.ts +9 -0
  117. package/dist/src/lib/middleware/benchmarks/index.js +67 -0
  118. package/dist/src/lib/middleware/benchmarks/json-writer.d.ts +15 -0
  119. package/dist/src/lib/middleware/benchmarks/json-writer.js +144 -0
  120. package/dist/src/lib/middleware/benchmarks/summary.d.ts +9 -0
  121. package/dist/src/lib/middleware/benchmarks/summary.js +105 -0
  122. package/dist/src/lib/middleware/benchmarks/token-tracker.d.ts +40 -0
  123. package/dist/src/lib/middleware/benchmarks/token-tracker.js +76 -0
  124. package/dist/src/lib/middleware/benchmarks/turn-counter.d.ts +34 -0
  125. package/dist/src/lib/middleware/benchmarks/turn-counter.js +58 -0
  126. package/dist/src/lib/middleware/config.d.ts +24 -0
  127. package/dist/src/lib/middleware/config.js +96 -0
  128. package/dist/src/lib/middleware/index.d.ts +11 -0
  129. package/dist/src/lib/middleware/index.js +17 -0
  130. package/dist/src/lib/middleware/phase-detector.d.ts +8 -0
  131. package/dist/src/lib/middleware/phase-detector.js +63 -0
  132. package/dist/src/lib/middleware/pipeline.d.ts +29 -0
  133. package/dist/src/lib/middleware/pipeline.js +81 -0
  134. package/dist/src/lib/middleware/schemas.d.ts +27 -0
  135. package/dist/src/lib/middleware/schemas.js +84 -0
  136. package/dist/src/lib/middleware/types.d.ts +94 -0
  137. package/dist/src/lib/middleware/types.js +8 -0
  138. package/dist/src/lib/package-manager-detection.d.ts +42 -0
  139. package/dist/src/lib/package-manager-detection.js +292 -0
  140. package/dist/src/lib/registry.d.ts +3 -0
  141. package/dist/src/lib/registry.js +42 -0
  142. package/dist/src/lib/safe-tools.d.ts +2 -0
  143. package/dist/src/lib/safe-tools.js +214 -0
  144. package/dist/src/lib/wizard-session.d.ts +220 -0
  145. package/dist/src/lib/wizard-session.js +127 -0
  146. package/dist/src/lib/wizard-tools.d.ts +82 -0
  147. package/dist/src/lib/wizard-tools.js +499 -0
  148. package/dist/src/run.d.ts +19 -0
  149. package/dist/src/run.js +151 -0
  150. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.d.ts +30 -0
  151. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js +141 -0
  152. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.d.ts +29 -0
  153. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js +180 -0
  154. package/dist/src/steps/add-mcp-server-to-clients/clients/claude.d.ts +20 -0
  155. package/dist/src/steps/add-mcp-server-to-clients/clients/claude.js +63 -0
  156. package/dist/src/steps/add-mcp-server-to-clients/clients/codex.d.ts +28 -0
  157. package/dist/src/steps/add-mcp-server-to-clients/clients/codex.js +77 -0
  158. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.d.ts +24 -0
  159. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js +60 -0
  160. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.d.ts +27 -0
  161. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.js +101 -0
  162. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.d.ts +26 -0
  163. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.js +102 -0
  164. package/dist/src/steps/add-mcp-server-to-clients/defaults.d.ts +44 -0
  165. package/dist/src/steps/add-mcp-server-to-clients/defaults.js +123 -0
  166. package/dist/src/steps/add-mcp-server-to-clients/index.d.ts +19 -0
  167. package/dist/src/steps/add-mcp-server-to-clients/index.js +110 -0
  168. package/dist/src/steps/add-or-update-environment-variables.d.ts +10 -0
  169. package/dist/src/steps/add-or-update-environment-variables.js +188 -0
  170. package/dist/src/steps/index.d.ts +4 -0
  171. package/dist/src/steps/index.js +20 -0
  172. package/dist/src/steps/run-prettier.d.ts +5 -0
  173. package/dist/src/steps/run-prettier.js +90 -0
  174. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.d.ts +11 -0
  175. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js +11 -0
  176. package/dist/src/steps/upload-environment-variables/index.d.ts +6 -0
  177. package/dist/src/steps/upload-environment-variables/index.js +37 -0
  178. package/dist/src/steps/upload-environment-variables/providers/vercel.d.ts +15 -0
  179. package/dist/src/steps/upload-environment-variables/providers/vercel.js +145 -0
  180. package/dist/src/telemetry.d.ts +2 -0
  181. package/dist/src/telemetry.js +12 -0
  182. package/dist/src/ui/index.d.ts +8 -0
  183. package/dist/src/ui/index.js +16 -0
  184. package/dist/src/ui/logging-ui.d.ts +56 -0
  185. package/dist/src/ui/logging-ui.js +157 -0
  186. package/dist/src/ui/tui/App.d.ts +6 -0
  187. package/dist/src/ui/tui/App.js +34 -0
  188. package/dist/src/ui/tui/components/AmplitudeLogo.d.ts +5 -0
  189. package/dist/src/ui/tui/components/AmplitudeLogo.js +81 -0
  190. package/dist/src/ui/tui/components/AmplitudeTextLogo.d.ts +3 -0
  191. package/dist/src/ui/tui/components/AmplitudeTextLogo.js +31 -0
  192. package/dist/src/ui/tui/components/ConsoleView.d.ts +23 -0
  193. package/dist/src/ui/tui/components/ConsoleView.js +220 -0
  194. package/dist/src/ui/tui/components/TitleBar.d.ts +6 -0
  195. package/dist/src/ui/tui/components/TitleBar.js +16 -0
  196. package/dist/src/ui/tui/console-commands.d.ts +16 -0
  197. package/dist/src/ui/tui/console-commands.js +31 -0
  198. package/dist/src/ui/tui/context/CommandModeContext.d.ts +2 -0
  199. package/dist/src/ui/tui/context/CommandModeContext.js +3 -0
  200. package/dist/src/ui/tui/flows.d.ts +48 -0
  201. package/dist/src/ui/tui/flows.js +154 -0
  202. package/dist/src/ui/tui/hooks/useScreenInput.d.ts +13 -0
  203. package/dist/src/ui/tui/hooks/useScreenInput.js +18 -0
  204. package/dist/src/ui/tui/hooks/useStdoutDimensions.d.ts +9 -0
  205. package/dist/src/ui/tui/hooks/useStdoutDimensions.js +29 -0
  206. package/dist/src/ui/tui/ink-ui.d.ts +62 -0
  207. package/dist/src/ui/tui/ink-ui.js +142 -0
  208. package/dist/src/ui/tui/primitives/CardLayout.d.ts +12 -0
  209. package/dist/src/ui/tui/primitives/CardLayout.js +9 -0
  210. package/dist/src/ui/tui/primitives/ConfirmationInput.d.ts +13 -0
  211. package/dist/src/ui/tui/primitives/ConfirmationInput.js +35 -0
  212. package/dist/src/ui/tui/primitives/DissolveTransition.d.ts +21 -0
  213. package/dist/src/ui/tui/primitives/DissolveTransition.js +143 -0
  214. package/dist/src/ui/tui/primitives/EventPlanViewer.d.ts +9 -0
  215. package/dist/src/ui/tui/primitives/EventPlanViewer.js +9 -0
  216. package/dist/src/ui/tui/primitives/KagiSmallWebViewer.d.ts +7 -0
  217. package/dist/src/ui/tui/primitives/KagiSmallWebViewer.js +101 -0
  218. package/dist/src/ui/tui/primitives/LoadingBox.d.ts +8 -0
  219. package/dist/src/ui/tui/primitives/LoadingBox.js +9 -0
  220. package/dist/src/ui/tui/primitives/LogViewer.d.ts +11 -0
  221. package/dist/src/ui/tui/primitives/LogViewer.js +55 -0
  222. package/dist/src/ui/tui/primitives/PickerMenu.d.ts +20 -0
  223. package/dist/src/ui/tui/primitives/PickerMenu.js +212 -0
  224. package/dist/src/ui/tui/primitives/ProgressList.d.ts +15 -0
  225. package/dist/src/ui/tui/primitives/ProgressList.js +29 -0
  226. package/dist/src/ui/tui/primitives/PromptLabel.d.ts +11 -0
  227. package/dist/src/ui/tui/primitives/PromptLabel.js +12 -0
  228. package/dist/src/ui/tui/primitives/ReportViewer.d.ts +12 -0
  229. package/dist/src/ui/tui/primitives/ReportViewer.js +99 -0
  230. package/dist/src/ui/tui/primitives/ScreenErrorBoundary.d.ts +26 -0
  231. package/dist/src/ui/tui/primitives/ScreenErrorBoundary.js +29 -0
  232. package/dist/src/ui/tui/primitives/SlashCommandInput.d.ts +21 -0
  233. package/dist/src/ui/tui/primitives/SlashCommandInput.js +85 -0
  234. package/dist/src/ui/tui/primitives/SnakeGame.d.ts +1 -0
  235. package/dist/src/ui/tui/primitives/SnakeGame.js +1 -0
  236. package/dist/src/ui/tui/primitives/SplitView.d.ts +11 -0
  237. package/dist/src/ui/tui/primitives/SplitView.js +8 -0
  238. package/dist/src/ui/tui/primitives/TabContainer.d.ts +18 -0
  239. package/dist/src/ui/tui/primitives/TabContainer.js +30 -0
  240. package/dist/src/ui/tui/primitives/index.d.ts +23 -0
  241. package/dist/src/ui/tui/primitives/index.js +19 -0
  242. package/dist/src/ui/tui/router.d.ts +61 -0
  243. package/dist/src/ui/tui/router.js +104 -0
  244. package/dist/src/ui/tui/screen-registry.d.ts +19 -0
  245. package/dist/src/ui/tui/screen-registry.js +56 -0
  246. package/dist/src/ui/tui/screens/ActivationOptionsScreen.d.ts +12 -0
  247. package/dist/src/ui/tui/screens/ActivationOptionsScreen.js +57 -0
  248. package/dist/src/ui/tui/screens/AuthScreen.d.ts +18 -0
  249. package/dist/src/ui/tui/screens/AuthScreen.js +107 -0
  250. package/dist/src/ui/tui/screens/ChecklistScreen.d.ts +22 -0
  251. package/dist/src/ui/tui/screens/ChecklistScreen.js +122 -0
  252. package/dist/src/ui/tui/screens/DataIngestionCheckScreen.d.ts +24 -0
  253. package/dist/src/ui/tui/screens/DataIngestionCheckScreen.js +113 -0
  254. package/dist/src/ui/tui/screens/DataSetupScreen.d.ts +17 -0
  255. package/dist/src/ui/tui/screens/DataSetupScreen.js +73 -0
  256. package/dist/src/ui/tui/screens/IntroScreen.d.ts +16 -0
  257. package/dist/src/ui/tui/screens/IntroScreen.js +86 -0
  258. package/dist/src/ui/tui/screens/LoginScreen.d.ts +15 -0
  259. package/dist/src/ui/tui/screens/LoginScreen.js +65 -0
  260. package/dist/src/ui/tui/screens/LogoutScreen.d.ts +12 -0
  261. package/dist/src/ui/tui/screens/LogoutScreen.js +28 -0
  262. package/dist/src/ui/tui/screens/McpScreen.d.ts +26 -0
  263. package/dist/src/ui/tui/screens/McpScreen.js +148 -0
  264. package/dist/src/ui/tui/screens/OutageScreen.d.ts +10 -0
  265. package/dist/src/ui/tui/screens/OutageScreen.js +17 -0
  266. package/dist/src/ui/tui/screens/OutroScreen.d.ts +11 -0
  267. package/dist/src/ui/tui/screens/OutroScreen.js +69 -0
  268. package/dist/src/ui/tui/screens/RegionSelectScreen.d.ts +17 -0
  269. package/dist/src/ui/tui/screens/RegionSelectScreen.js +40 -0
  270. package/dist/src/ui/tui/screens/RunScreen.d.ts +16 -0
  271. package/dist/src/ui/tui/screens/RunScreen.js +212 -0
  272. package/dist/src/ui/tui/screens/SettingsOverrideScreen.d.ts +10 -0
  273. package/dist/src/ui/tui/screens/SettingsOverrideScreen.js +23 -0
  274. package/dist/src/ui/tui/screens/SetupScreen.d.ts +13 -0
  275. package/dist/src/ui/tui/screens/SetupScreen.js +73 -0
  276. package/dist/src/ui/tui/screens/SlackScreen.d.ts +25 -0
  277. package/dist/src/ui/tui/screens/SlackScreen.js +97 -0
  278. package/dist/src/ui/tui/services/mcp-installer.d.ts +25 -0
  279. package/dist/src/ui/tui/services/mcp-installer.js +82 -0
  280. package/dist/src/ui/tui/start-tui.d.ts +10 -0
  281. package/dist/src/ui/tui/start-tui.js +50 -0
  282. package/dist/src/ui/tui/store.d.ts +231 -0
  283. package/dist/src/ui/tui/store.js +568 -0
  284. package/dist/src/ui/tui/styles.d.ts +31 -0
  285. package/dist/src/ui/tui/styles.js +33 -0
  286. package/dist/src/ui/wizard-ui.d.ts +110 -0
  287. package/dist/src/ui/wizard-ui.js +18 -0
  288. package/dist/src/utils/ampli-settings.d.ts +37 -0
  289. package/dist/src/utils/ampli-settings.js +182 -0
  290. package/dist/src/utils/analytics.d.ts +35 -0
  291. package/dist/src/utils/analytics.js +133 -0
  292. package/dist/src/utils/anthropic-status.d.ts +17 -0
  293. package/dist/src/utils/anthropic-status.js +51 -0
  294. package/dist/src/utils/api-key-store.d.ts +35 -0
  295. package/dist/src/utils/api-key-store.js +176 -0
  296. package/dist/src/utils/bash.d.ts +2 -0
  297. package/dist/src/utils/bash.js +53 -0
  298. package/dist/src/utils/custom-headers.d.ts +9 -0
  299. package/dist/src/utils/custom-headers.js +23 -0
  300. package/dist/src/utils/debug.d.ts +23 -0
  301. package/dist/src/utils/debug.js +86 -0
  302. package/dist/src/utils/environment.d.ts +4 -0
  303. package/dist/src/utils/environment.js +76 -0
  304. package/dist/src/utils/file-utils.d.ts +2 -0
  305. package/dist/src/utils/file-utils.js +16 -0
  306. package/dist/src/utils/get-api-key.d.ts +17 -0
  307. package/dist/src/utils/get-api-key.js +50 -0
  308. package/dist/src/utils/logging.d.ts +9 -0
  309. package/dist/src/utils/logging.js +48 -0
  310. package/dist/src/utils/oauth.d.ts +53 -0
  311. package/dist/src/utils/oauth.js +354 -0
  312. package/dist/src/utils/package-json.d.ts +25 -0
  313. package/dist/src/utils/package-json.js +26 -0
  314. package/dist/src/utils/package-manager.d.ts +21 -0
  315. package/dist/src/utils/package-manager.js +208 -0
  316. package/dist/src/utils/semver.d.ts +21 -0
  317. package/dist/src/utils/semver.js +61 -0
  318. package/dist/src/utils/setup-utils.d.ts +82 -0
  319. package/dist/src/utils/setup-utils.js +467 -0
  320. package/dist/src/utils/shell-completions.d.ts +10 -0
  321. package/dist/src/utils/shell-completions.js +199 -0
  322. package/dist/src/utils/string.d.ts +1 -0
  323. package/dist/src/utils/string.js +8 -0
  324. package/dist/src/utils/types.d.ts +72 -0
  325. package/dist/src/utils/types.js +2 -0
  326. package/dist/src/utils/urls.d.ts +14 -0
  327. package/dist/src/utils/urls.js +69 -0
  328. package/dist/src/utils/vendor/is-unicorn-supported.d.ts +1 -0
  329. package/dist/src/utils/vendor/is-unicorn-supported.js +23 -0
  330. package/dist/src/utils/wizard-abort.d.ts +13 -0
  331. package/dist/src/utils/wizard-abort.js +56 -0
  332. package/man/amplitude-wizard.1 +170 -0
  333. package/package.json +144 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * Token tracking plugin for input/output tokens.
4
+ *
5
+ * Accumulates per-turn token usage (input_tokens + cache_read_input_tokens
6
+ * + cache_creation_input_tokens = total input; output_tokens = output).
7
+ * Respects the dedup flag from TurnCounterPlugin. Cache breakdown (r/5m/1h)
8
+ * is tracked by CacheTrackerPlugin for reporting and pricing.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.TokenTrackerPlugin = void 0;
12
+ class TokenTrackerPlugin {
13
+ name = 'tokens';
14
+ phaseInput = 0;
15
+ phaseOutput = 0;
16
+ totalInput = 0;
17
+ totalOutput = 0;
18
+ lastUsage = null;
19
+ phaseSnapshots = [];
20
+ currentPhase = 'setup';
21
+ phaseMessagesWithUsage = 0;
22
+ onMessage(message, ctx, store) {
23
+ if (message.type !== 'assistant')
24
+ return;
25
+ const turns = ctx.get('turns');
26
+ if (turns?.isDuplicate)
27
+ return;
28
+ const usage = message.message?.usage;
29
+ if (usage) {
30
+ const input = Number(usage.input_tokens ?? 0) +
31
+ Number(usage.cache_read_input_tokens ?? 0) +
32
+ Number(usage.cache_creation_input_tokens ?? 0);
33
+ const output = Number(usage.output_tokens ?? 0);
34
+ this.phaseInput += input;
35
+ this.phaseOutput += output;
36
+ this.totalInput += input;
37
+ this.totalOutput += output;
38
+ this.lastUsage = usage;
39
+ this.phaseMessagesWithUsage += 1;
40
+ }
41
+ store.set('tokens', this.getData());
42
+ }
43
+ onPhaseTransition(fromPhase, toPhase, _ctx, store) {
44
+ this.phaseSnapshots.push({
45
+ phase: fromPhase,
46
+ inputTokens: this.phaseInput,
47
+ outputTokens: this.phaseOutput,
48
+ messagesWithUsage: this.phaseMessagesWithUsage,
49
+ });
50
+ this.currentPhase = toPhase;
51
+ this.phaseInput = 0;
52
+ this.phaseOutput = 0;
53
+ this.phaseMessagesWithUsage = 0;
54
+ store.set('tokens', this.getData());
55
+ }
56
+ onFinalize(_resultMessage, _totalDurationMs, _ctx, store) {
57
+ this.phaseSnapshots.push({
58
+ phase: this.currentPhase,
59
+ inputTokens: this.phaseInput,
60
+ outputTokens: this.phaseOutput,
61
+ messagesWithUsage: this.phaseMessagesWithUsage,
62
+ });
63
+ store.set('tokens', this.getData());
64
+ }
65
+ getData() {
66
+ return {
67
+ phaseInput: this.phaseInput,
68
+ phaseOutput: this.phaseOutput,
69
+ totalInput: this.totalInput,
70
+ totalOutput: this.totalOutput,
71
+ lastUsage: this.lastUsage,
72
+ phaseSnapshots: [...this.phaseSnapshots],
73
+ };
74
+ }
75
+ }
76
+ exports.TokenTrackerPlugin = TokenTrackerPlugin;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Turn counting plugin with message deduplication.
3
+ *
4
+ * The SDK emits multiple assistant events per turn (one per content block)
5
+ * with the same message ID. This plugin deduplicates and publishes turn
6
+ * counts + a duplicate flag for downstream plugins.
7
+ */
8
+ import type { Middleware, MiddlewareContext, MiddlewareStore, SDKMessage } from '../types';
9
+ export interface TurnData {
10
+ /** Whether the current message is a duplicate of the last processed turn */
11
+ isDuplicate: boolean;
12
+ /** Turns in the current phase */
13
+ phaseTurns: number;
14
+ /** Total turns across all phases */
15
+ totalTurns: number;
16
+ /** Per-phase turn snapshots: [{ phase, turns }] */
17
+ phaseSnapshots: Array<{
18
+ phase: string;
19
+ turns: number;
20
+ }>;
21
+ }
22
+ export declare class TurnCounterPlugin implements Middleware {
23
+ readonly name = "turns";
24
+ private lastMessageId;
25
+ private phaseTurns;
26
+ private totalTurns;
27
+ private isDuplicate;
28
+ private phaseSnapshots;
29
+ private currentPhase;
30
+ onMessage(message: SDKMessage, _ctx: MiddlewareContext, store: MiddlewareStore): void;
31
+ onPhaseTransition(fromPhase: string, _toPhase: string, _ctx: MiddlewareContext, store: MiddlewareStore): void;
32
+ onFinalize(_resultMessage: SDKMessage, _totalDurationMs: number, _ctx: MiddlewareContext, store: MiddlewareStore): void;
33
+ private getData;
34
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ /**
3
+ * Turn counting plugin with message deduplication.
4
+ *
5
+ * The SDK emits multiple assistant events per turn (one per content block)
6
+ * with the same message ID. This plugin deduplicates and publishes turn
7
+ * counts + a duplicate flag for downstream plugins.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TurnCounterPlugin = void 0;
11
+ class TurnCounterPlugin {
12
+ name = 'turns';
13
+ lastMessageId = null;
14
+ phaseTurns = 0;
15
+ totalTurns = 0;
16
+ isDuplicate = false;
17
+ phaseSnapshots = [];
18
+ currentPhase = 'setup';
19
+ onMessage(message, _ctx, store) {
20
+ if (message.type !== 'assistant') {
21
+ this.isDuplicate = false;
22
+ store.set('turns', this.getData());
23
+ return;
24
+ }
25
+ const msgId = message.message?.id;
26
+ this.isDuplicate = msgId != null && msgId === this.lastMessageId;
27
+ if (msgId)
28
+ this.lastMessageId = msgId;
29
+ if (!this.isDuplicate) {
30
+ this.phaseTurns++;
31
+ this.totalTurns++;
32
+ }
33
+ store.set('turns', this.getData());
34
+ }
35
+ onPhaseTransition(fromPhase, _toPhase, _ctx, store) {
36
+ this.phaseSnapshots.push({ phase: fromPhase, turns: this.phaseTurns });
37
+ this.currentPhase = _toPhase;
38
+ this.phaseTurns = 0;
39
+ this.lastMessageId = null;
40
+ store.set('turns', this.getData());
41
+ }
42
+ onFinalize(_resultMessage, _totalDurationMs, _ctx, store) {
43
+ this.phaseSnapshots.push({
44
+ phase: this.currentPhase,
45
+ turns: this.phaseTurns,
46
+ });
47
+ store.set('turns', this.getData());
48
+ }
49
+ getData() {
50
+ return {
51
+ isDuplicate: this.isDuplicate,
52
+ phaseTurns: this.phaseTurns,
53
+ totalTurns: this.totalTurns,
54
+ phaseSnapshots: [...this.phaseSnapshots],
55
+ };
56
+ }
57
+ }
58
+ exports.TurnCounterPlugin = TurnCounterPlugin;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Benchmark configuration loader.
3
+ *
4
+ * Loads .benchmark-config.json from the working directory with sensible defaults.
5
+ * All fields are optional — missing fields fall back to defaults.
6
+ */
7
+ export interface BenchmarkConfig {
8
+ /** Enable/disable individual metric plugins */
9
+ plugins: Record<string, boolean>;
10
+ output: {
11
+ /** Path for the benchmark JSON output file */
12
+ benchmarkPath: string;
13
+ /** Whether to write the benchmark JSON file */
14
+ benchmarkEnabled: boolean;
15
+ /** Path for the main wizard debug log file */
16
+ logPath: string;
17
+ /** Whether to write the main wizard debug log */
18
+ logEnabled: boolean;
19
+ /** Suppress benchmark console output (disables the summary plugin) */
20
+ suppressWizardLogs: boolean;
21
+ };
22
+ }
23
+ export declare function loadBenchmarkConfig(installDir: string): BenchmarkConfig;
24
+ export declare function getDefaultConfig(): BenchmarkConfig;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ /**
3
+ * Benchmark configuration loader.
4
+ *
5
+ * Loads .benchmark-config.json from the working directory with sensible defaults.
6
+ * All fields are optional — missing fields fall back to defaults.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadBenchmarkConfig = loadBenchmarkConfig;
13
+ exports.getDefaultConfig = getDefaultConfig;
14
+ const fs_1 = __importDefault(require("fs"));
15
+ const path_1 = __importDefault(require("path"));
16
+ const zod_1 = require("zod");
17
+ const debug_1 = require("../../utils/debug");
18
+ const agent_interface_1 = require("../agent-interface");
19
+ const DEFAULT_CONFIG = {
20
+ plugins: {
21
+ tokens: true,
22
+ cache: true,
23
+ turns: true,
24
+ compactions: true,
25
+ contextSize: true,
26
+ cost: true,
27
+ duration: true,
28
+ summary: true,
29
+ jsonWriter: true,
30
+ },
31
+ output: {
32
+ benchmarkPath: '/tmp/amplitude-wizard-benchmark.json',
33
+ benchmarkEnabled: true,
34
+ logPath: '/tmp/amplitude-wizard.log',
35
+ logEnabled: true,
36
+ suppressWizardLogs: false,
37
+ },
38
+ };
39
+ const BenchmarkConfigFileSchema = zod_1.z
40
+ .object({
41
+ plugins: zod_1.z.record(zod_1.z.string(), zod_1.z.boolean()).optional(),
42
+ output: zod_1.z
43
+ .object({
44
+ benchmarkPath: zod_1.z.string(),
45
+ benchmarkEnabled: zod_1.z.boolean(),
46
+ logPath: zod_1.z.string(),
47
+ logEnabled: zod_1.z.boolean(),
48
+ suppressWizardLogs: zod_1.z.boolean(),
49
+ })
50
+ .partial()
51
+ .optional(),
52
+ })
53
+ .passthrough();
54
+ function loadBenchmarkConfig(installDir) {
55
+ const configPath = process.env.AMPLITUDE_WIZARD_BENCHMARK_CONFIG ??
56
+ path_1.default.join(installDir, '.benchmark-config.json');
57
+ try {
58
+ const raw = fs_1.default.readFileSync(configPath, 'utf-8');
59
+ const result = BenchmarkConfigFileSchema.safeParse(JSON.parse(raw));
60
+ if (!result.success)
61
+ throw result.error;
62
+ const parsed = result.data;
63
+ const config = {
64
+ plugins: { ...DEFAULT_CONFIG.plugins, ...parsed.plugins },
65
+ output: { ...DEFAULT_CONFIG.output, ...parsed.output },
66
+ };
67
+ // Env var overrides for parallel runs
68
+ if (process.env.AMPLITUDE_WIZARD_BENCHMARK_FILE) {
69
+ config.output.benchmarkPath = process.env.AMPLITUDE_WIZARD_BENCHMARK_FILE;
70
+ }
71
+ if (process.env.AMPLITUDE_WIZARD_LOG_FILE) {
72
+ config.output.logPath = process.env.AMPLITUDE_WIZARD_LOG_FILE;
73
+ }
74
+ // If benchmark output is disabled, disable the jsonWriter plugin
75
+ if (!config.output.benchmarkEnabled) {
76
+ config.plugins.jsonWriter = false;
77
+ }
78
+ (0, debug_1.logToFile)(`${agent_interface_1.AgentSignals.BENCHMARK} Loaded config from ${configPath}`);
79
+ return config;
80
+ }
81
+ catch {
82
+ // No config file or invalid JSON — use defaults
83
+ const config = structuredClone(DEFAULT_CONFIG);
84
+ // Env var overrides
85
+ if (process.env.AMPLITUDE_WIZARD_BENCHMARK_FILE) {
86
+ config.output.benchmarkPath = process.env.AMPLITUDE_WIZARD_BENCHMARK_FILE;
87
+ }
88
+ if (process.env.AMPLITUDE_WIZARD_LOG_FILE) {
89
+ config.output.logPath = process.env.AMPLITUDE_WIZARD_LOG_FILE;
90
+ }
91
+ return config;
92
+ }
93
+ }
94
+ function getDefaultConfig() {
95
+ return structuredClone(DEFAULT_CONFIG);
96
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Middleware system for wizard agent runs.
3
+ */
4
+ export { MiddlewarePipeline } from './pipeline';
5
+ export { PhaseDetector } from './phase-detector';
6
+ export type { Middleware, MiddlewareContext, MiddlewareStore } from './types';
7
+ export { loadBenchmarkConfig, getDefaultConfig } from './config';
8
+ export type { BenchmarkConfig } from './config';
9
+ export { createBenchmarkPipeline } from './benchmark';
10
+ export type { BenchmarkData, StepUsage } from './benchmark';
11
+ export { createPluginsFromConfig } from './benchmarks';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Middleware system for wizard agent runs.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createPluginsFromConfig = exports.createBenchmarkPipeline = exports.getDefaultConfig = exports.loadBenchmarkConfig = exports.PhaseDetector = exports.MiddlewarePipeline = void 0;
7
+ var pipeline_1 = require("./pipeline");
8
+ Object.defineProperty(exports, "MiddlewarePipeline", { enumerable: true, get: function () { return pipeline_1.MiddlewarePipeline; } });
9
+ var phase_detector_1 = require("./phase-detector");
10
+ Object.defineProperty(exports, "PhaseDetector", { enumerable: true, get: function () { return phase_detector_1.PhaseDetector; } });
11
+ var config_1 = require("./config");
12
+ Object.defineProperty(exports, "loadBenchmarkConfig", { enumerable: true, get: function () { return config_1.loadBenchmarkConfig; } });
13
+ Object.defineProperty(exports, "getDefaultConfig", { enumerable: true, get: function () { return config_1.getDefaultConfig; } });
14
+ var benchmark_1 = require("./benchmark");
15
+ Object.defineProperty(exports, "createBenchmarkPipeline", { enumerable: true, get: function () { return benchmark_1.createBenchmarkPipeline; } });
16
+ var benchmarks_1 = require("./benchmarks");
17
+ Object.defineProperty(exports, "createPluginsFromConfig", { enumerable: true, get: function () { return benchmarks_1.createPluginsFromConfig; } });
@@ -0,0 +1,8 @@
1
+ /** Phase transitions from [STATUS] in assistant text. Keep in sync with workflow "Status to report" bullets. */
2
+ import type { SDKMessage } from './types';
3
+ export declare class PhaseDetector {
4
+ private currentPhase;
5
+ detect(message: SDKMessage): string | null;
6
+ private getNextPhase;
7
+ reset(): void;
8
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /** Phase transitions from [STATUS] in assistant text. Keep in sync with workflow "Status to report" bullets. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PhaseDetector = void 0;
5
+ const PHASES_ORDER = [
6
+ '1.0-begin',
7
+ '1.1-edit',
8
+ '1.2-revise',
9
+ '1.3-conclude',
10
+ ];
11
+ const STATUS_PHRASES_BY_PHASE = {
12
+ '1.0-begin': [
13
+ 'Checking project structure',
14
+ 'Verifying Amplitude dependencies',
15
+ 'Generating events based on project',
16
+ ],
17
+ '1.1-edit': ['Inserting Amplitude capture code'],
18
+ '1.2-revise': [
19
+ 'Finding and correcting errors',
20
+ 'Report details of any errors you fix',
21
+ 'Linting, building and prettying',
22
+ ],
23
+ '1.3-conclude': ['Configured dashboard', 'Created setup report'],
24
+ };
25
+ class PhaseDetector {
26
+ currentPhase = 'setup';
27
+ detect(message) {
28
+ if (message.type !== 'assistant')
29
+ return null;
30
+ const nextPhase = this.getNextPhase();
31
+ if (nextPhase === null)
32
+ return null;
33
+ const content = message.message?.content;
34
+ if (!Array.isArray(content))
35
+ return null;
36
+ for (const block of content) {
37
+ if (block.type !== 'text' || typeof block.text !== 'string')
38
+ continue;
39
+ if (!block.text.includes('[STATUS]'))
40
+ continue;
41
+ const phrases = STATUS_PHRASES_BY_PHASE[nextPhase];
42
+ for (const phrase of phrases) {
43
+ if (block.text.includes(phrase)) {
44
+ this.currentPhase = nextPhase;
45
+ return nextPhase;
46
+ }
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ getNextPhase() {
52
+ if (this.currentPhase === 'setup')
53
+ return '1.0-begin';
54
+ const i = PHASES_ORDER.indexOf(this.currentPhase);
55
+ if (i < 0 || i >= PHASES_ORDER.length - 1)
56
+ return null;
57
+ return PHASES_ORDER[i + 1];
58
+ }
59
+ reset() {
60
+ this.currentPhase = 'setup';
61
+ }
62
+ }
63
+ exports.PhaseDetector = PhaseDetector;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Middleware pipeline orchestrator.
3
+ *
4
+ * Implements the same { onMessage, finalize } interface that runAgent() expects,
5
+ * while internally dispatching to an ordered list of middleware plugins.
6
+ */
7
+ import { PhaseDetector } from './phase-detector';
8
+ import type { Middleware, SDKMessage } from './types';
9
+ export declare class MiddlewarePipeline {
10
+ private middlewares;
11
+ private store;
12
+ private phaseDetector;
13
+ private autoDetectPhases;
14
+ private _currentPhase;
15
+ private _currentPhaseFreshContext;
16
+ constructor(middlewares: Middleware[], opts?: {
17
+ phaseDetector?: PhaseDetector;
18
+ autoDetectPhases?: boolean;
19
+ });
20
+ /** Feed an SDK message through all middleware (satisfies tracker.onMessage) */
21
+ onMessage(message: SDKMessage): void;
22
+ /** Finalize the run (satisfies tracker.finalize) */
23
+ finalize(resultMessage: SDKMessage, totalDurationMs: number): unknown;
24
+ /** Explicit phase start (for phased runner support) */
25
+ startPhase(name: string, freshContext: boolean): void;
26
+ private transitionPhase;
27
+ private createContext;
28
+ private createStore;
29
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Middleware pipeline orchestrator.
4
+ *
5
+ * Implements the same { onMessage, finalize } interface that runAgent() expects,
6
+ * while internally dispatching to an ordered list of middleware plugins.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MiddlewarePipeline = void 0;
10
+ const phase_detector_1 = require("./phase-detector");
11
+ class MiddlewarePipeline {
12
+ middlewares;
13
+ store = new Map();
14
+ phaseDetector;
15
+ autoDetectPhases;
16
+ _currentPhase = 'setup';
17
+ _currentPhaseFreshContext = true;
18
+ constructor(middlewares, opts) {
19
+ this.middlewares = middlewares;
20
+ this.phaseDetector = opts?.phaseDetector ?? new phase_detector_1.PhaseDetector();
21
+ this.autoDetectPhases = opts?.autoDetectPhases ?? true;
22
+ const ctx = this.createContext();
23
+ for (const mw of this.middlewares) {
24
+ mw.onInit?.(ctx);
25
+ }
26
+ }
27
+ /** Feed an SDK message through all middleware (satisfies tracker.onMessage) */
28
+ onMessage(message) {
29
+ // Phase detection first — updates context before middleware sees it
30
+ if (this.autoDetectPhases) {
31
+ const newPhase = this.phaseDetector.detect(message);
32
+ if (newPhase && newPhase !== this._currentPhase) {
33
+ this.transitionPhase(newPhase, false);
34
+ }
35
+ }
36
+ const ctx = this.createContext();
37
+ const storeHandle = this.createStore();
38
+ for (const mw of this.middlewares) {
39
+ mw.onMessage?.(message, ctx, storeHandle);
40
+ }
41
+ }
42
+ /** Finalize the run (satisfies tracker.finalize) */
43
+ finalize(resultMessage, totalDurationMs) {
44
+ const ctx = this.createContext();
45
+ const storeHandle = this.createStore();
46
+ let result;
47
+ for (const mw of this.middlewares) {
48
+ const r = mw.onFinalize?.(resultMessage, totalDurationMs, ctx, storeHandle);
49
+ if (r !== undefined)
50
+ result = r;
51
+ }
52
+ return result;
53
+ }
54
+ /** Explicit phase start (for phased runner support) */
55
+ startPhase(name, freshContext) {
56
+ this.transitionPhase(name, freshContext);
57
+ }
58
+ transitionPhase(newPhase, freshContext) {
59
+ const oldPhase = this._currentPhase;
60
+ this._currentPhase = newPhase;
61
+ this._currentPhaseFreshContext = freshContext;
62
+ const ctx = this.createContext();
63
+ const storeHandle = this.createStore();
64
+ for (const mw of this.middlewares) {
65
+ mw.onPhaseTransition?.(oldPhase, newPhase, ctx, storeHandle);
66
+ }
67
+ }
68
+ createContext() {
69
+ return {
70
+ currentPhase: this._currentPhase,
71
+ currentPhaseFreshContext: this._currentPhaseFreshContext,
72
+ get: (key) => this.store.get(key),
73
+ };
74
+ }
75
+ createStore() {
76
+ return {
77
+ set: (key, value) => this.store.set(key, value),
78
+ };
79
+ }
80
+ }
81
+ exports.MiddlewarePipeline = MiddlewarePipeline;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Zod schemas for SDK message validation.
3
+ *
4
+ * These schemas enforce the structural types defined in types.ts at runtime.
5
+ * Use `safeParseSDKMessage` at ingestion boundaries (the for-await loop in
6
+ * agent-interface.ts and the middleware pipeline) so malformed messages are
7
+ * logged and skipped rather than causing uncaught property-access errors.
8
+ */
9
+ import { z } from 'zod';
10
+ import type { SDKMessage, SDKUsage, SDKContentBlock, SDKCompactMetadata, SDKModelUsageEntry } from './types';
11
+ export declare const sdkUsageSchema: z.ZodType<SDKUsage>;
12
+ export declare const sdkContentBlockSchema: z.ZodType<SDKContentBlock>;
13
+ export declare const sdkCompactMetadataSchema: z.ZodType<SDKCompactMetadata>;
14
+ export declare const sdkModelUsageEntrySchema: z.ZodType<SDKModelUsageEntry>;
15
+ export declare const sdkMessageSchema: z.ZodType<SDKMessage>;
16
+ export type SDKMessageParseResult = {
17
+ ok: true;
18
+ message: SDKMessage;
19
+ } | {
20
+ ok: false;
21
+ error: z.ZodError;
22
+ };
23
+ /**
24
+ * Validate an unknown value as an SDKMessage.
25
+ * Returns a discriminated result so callers can log and skip bad messages.
26
+ */
27
+ export declare function safeParseSDKMessage(value: unknown): SDKMessageParseResult;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Zod schemas for SDK message validation.
4
+ *
5
+ * These schemas enforce the structural types defined in types.ts at runtime.
6
+ * Use `safeParseSDKMessage` at ingestion boundaries (the for-await loop in
7
+ * agent-interface.ts and the middleware pipeline) so malformed messages are
8
+ * logged and skipped rather than causing uncaught property-access errors.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.sdkMessageSchema = exports.sdkModelUsageEntrySchema = exports.sdkCompactMetadataSchema = exports.sdkContentBlockSchema = exports.sdkUsageSchema = void 0;
12
+ exports.safeParseSDKMessage = safeParseSDKMessage;
13
+ const zod_1 = require("zod");
14
+ // ── Leaf schemas ────────────────────────────────────────────────────────────
15
+ exports.sdkUsageSchema = zod_1.z.object({
16
+ input_tokens: zod_1.z.number().optional(),
17
+ output_tokens: zod_1.z.number().optional(),
18
+ cache_read_input_tokens: zod_1.z.number().optional(),
19
+ cache_creation_input_tokens: zod_1.z.number().optional(),
20
+ cache_creation: zod_1.z
21
+ .object({
22
+ ephemeral_5m_input_tokens: zod_1.z.number().optional(),
23
+ ephemeral_1h_input_tokens: zod_1.z.number().optional(),
24
+ })
25
+ .optional(),
26
+ total_cost_usd: zod_1.z.number().optional(),
27
+ });
28
+ exports.sdkContentBlockSchema = zod_1.z
29
+ .object({
30
+ type: zod_1.z.string(),
31
+ text: zod_1.z.string().optional(),
32
+ name: zod_1.z.string().optional(),
33
+ input: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
34
+ })
35
+ .passthrough();
36
+ exports.sdkCompactMetadataSchema = zod_1.z.object({
37
+ pre_tokens: zod_1.z.number().optional(),
38
+ trigger: zod_1.z.string().optional(),
39
+ });
40
+ exports.sdkModelUsageEntrySchema = zod_1.z.object({
41
+ inputTokens: zod_1.z.number().optional(),
42
+ outputTokens: zod_1.z.number().optional(),
43
+ cacheCreationInputTokens: zod_1.z.number().optional(),
44
+ cacheReadInputTokens: zod_1.z.number().optional(),
45
+ });
46
+ // ── SDKMessage ──────────────────────────────────────────────────────────────
47
+ exports.sdkMessageSchema = zod_1.z
48
+ .object({
49
+ type: zod_1.z.string(),
50
+ subtype: zod_1.z.string().optional(),
51
+ message: zod_1.z
52
+ .object({
53
+ id: zod_1.z.string().optional(),
54
+ usage: exports.sdkUsageSchema.optional(),
55
+ content: zod_1.z.array(exports.sdkContentBlockSchema).optional(),
56
+ })
57
+ .passthrough()
58
+ .optional(),
59
+ compact_metadata: exports.sdkCompactMetadataSchema.optional(),
60
+ is_error: zod_1.z.boolean().optional(),
61
+ result: zod_1.z.string().optional(),
62
+ errors: zod_1.z.array(zod_1.z.string()).optional(),
63
+ model: zod_1.z.string().optional(),
64
+ tools: zod_1.z.array(zod_1.z.unknown()).optional(),
65
+ mcp_servers: zod_1.z
66
+ .array(zod_1.z.object({ name: zod_1.z.string(), status: zod_1.z.string() }))
67
+ .optional(),
68
+ usage: exports.sdkUsageSchema.optional(),
69
+ total_cost_usd: zod_1.z.number().optional(),
70
+ num_turns: zod_1.z.number().optional(),
71
+ modelUsage: zod_1.z.record(zod_1.z.string(), exports.sdkModelUsageEntrySchema).optional(),
72
+ })
73
+ .passthrough();
74
+ /**
75
+ * Validate an unknown value as an SDKMessage.
76
+ * Returns a discriminated result so callers can log and skip bad messages.
77
+ */
78
+ function safeParseSDKMessage(value) {
79
+ const result = exports.sdkMessageSchema.safeParse(value);
80
+ if (result.success) {
81
+ return { ok: true, message: result.data };
82
+ }
83
+ return { ok: false, error: result.error };
84
+ }