@ohos-ports/assistant-ui 0.0.0-stage → 0.0.136-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/README.md +148 -2
  2. package/bin/assistant-ui.js +2 -0
  3. package/dist/codemods/utils/createTransformer.d.ts +15 -0
  4. package/dist/codemods/utils/createTransformer.d.ts.map +1 -0
  5. package/dist/codemods/utils/createTransformer.js +19 -0
  6. package/dist/codemods/utils/createTransformer.js.map +1 -0
  7. package/dist/codemods/utils/resolveBinding.d.ts +3 -0
  8. package/dist/codemods/utils/resolveBinding.d.ts.map +1 -0
  9. package/dist/codemods/utils/resolveBinding.js +77 -0
  10. package/dist/codemods/utils/resolveBinding.js.map +1 -0
  11. package/dist/codemods/v0-11/content-part-to-message-part.d.ts +3 -0
  12. package/dist/codemods/v0-11/content-part-to-message-part.d.ts.map +1 -0
  13. package/dist/codemods/v0-11/content-part-to-message-part.js +189 -0
  14. package/dist/codemods/v0-11/content-part-to-message-part.js.map +1 -0
  15. package/dist/codemods/v0-12/assistant-api-to-aui.d.ts +3 -0
  16. package/dist/codemods/v0-12/assistant-api-to-aui.d.ts.map +1 -0
  17. package/dist/codemods/v0-12/assistant-api-to-aui.js +117 -0
  18. package/dist/codemods/v0-12/assistant-api-to-aui.js.map +1 -0
  19. package/dist/codemods/v0-12/event-names-to-camelcase.d.ts +3 -0
  20. package/dist/codemods/v0-12/event-names-to-camelcase.d.ts.map +1 -0
  21. package/dist/codemods/v0-12/event-names-to-camelcase.js +38 -0
  22. package/dist/codemods/v0-12/event-names-to-camelcase.js.map +1 -0
  23. package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts +3 -0
  24. package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts.map +1 -0
  25. package/dist/codemods/v0-12/primitive-if-to-aui-if.js +226 -0
  26. package/dist/codemods/v0-12/primitive-if-to-aui-if.js.map +1 -0
  27. package/dist/codemods/v0-15/aui-accessor-calls-to-properties.d.ts +3 -0
  28. package/dist/codemods/v0-15/aui-accessor-calls-to-properties.d.ts.map +1 -0
  29. package/dist/codemods/v0-15/aui-accessor-calls-to-properties.js +85 -0
  30. package/dist/codemods/v0-15/aui-accessor-calls-to-properties.js.map +1 -0
  31. package/dist/codemods/v0-8/ui-package-split.d.ts +3 -0
  32. package/dist/codemods/v0-8/ui-package-split.d.ts.map +1 -0
  33. package/dist/codemods/v0-8/ui-package-split.js +102 -0
  34. package/dist/codemods/v0-8/ui-package-split.js.map +1 -0
  35. package/dist/codemods/v0-9/edge-package-split.d.ts +3 -0
  36. package/dist/codemods/v0-9/edge-package-split.d.ts.map +1 -0
  37. package/dist/codemods/v0-9/edge-package-split.js +47 -0
  38. package/dist/codemods/v0-9/edge-package-split.js.map +1 -0
  39. package/dist/commands/add.d.ts +17 -0
  40. package/dist/commands/add.d.ts.map +1 -0
  41. package/dist/commands/add.js +63 -0
  42. package/dist/commands/add.js.map +1 -0
  43. package/dist/commands/agent.d.ts +3 -0
  44. package/dist/commands/agent.d.ts.map +1 -0
  45. package/dist/commands/agent.js +27 -0
  46. package/dist/commands/agent.js.map +1 -0
  47. package/dist/commands/cloud.d.ts +25 -0
  48. package/dist/commands/cloud.d.ts.map +1 -0
  49. package/dist/commands/cloud.js +239 -0
  50. package/dist/commands/cloud.js.map +1 -0
  51. package/dist/commands/create.d.ts +58 -0
  52. package/dist/commands/create.d.ts.map +1 -0
  53. package/dist/commands/create.js +626 -0
  54. package/dist/commands/create.js.map +1 -0
  55. package/dist/commands/doctor.d.ts +22 -0
  56. package/dist/commands/doctor.d.ts.map +1 -0
  57. package/dist/commands/doctor.js +255 -0
  58. package/dist/commands/doctor.js.map +1 -0
  59. package/dist/commands/info.d.ts +6 -0
  60. package/dist/commands/info.d.ts.map +1 -0
  61. package/dist/commands/info.js +288 -0
  62. package/dist/commands/info.js.map +1 -0
  63. package/dist/commands/init.d.ts +13 -0
  64. package/dist/commands/init.d.ts.map +1 -0
  65. package/dist/commands/init.js +100 -0
  66. package/dist/commands/init.js.map +1 -0
  67. package/dist/commands/mcp.d.ts +3 -0
  68. package/dist/commands/mcp.d.ts.map +1 -0
  69. package/dist/commands/mcp.js +279 -0
  70. package/dist/commands/mcp.js.map +1 -0
  71. package/dist/commands/setup.d.ts +24 -0
  72. package/dist/commands/setup.d.ts.map +1 -0
  73. package/dist/commands/setup.js +136 -0
  74. package/dist/commands/setup.js.map +1 -0
  75. package/dist/commands/update.d.ts +3 -0
  76. package/dist/commands/update.d.ts.map +1 -0
  77. package/dist/commands/update.js +58 -0
  78. package/dist/commands/update.js.map +1 -0
  79. package/dist/commands/upgrade.d.ts +10 -0
  80. package/dist/commands/upgrade.d.ts.map +1 -0
  81. package/dist/commands/upgrade.js +38 -0
  82. package/dist/commands/upgrade.js.map +1 -0
  83. package/dist/index.d.ts +3 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +7 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/lib/agent-gate.d.ts +66 -0
  88. package/dist/lib/agent-gate.d.ts.map +1 -0
  89. package/dist/lib/agent-gate.js +180 -0
  90. package/dist/lib/agent-gate.js.map +1 -0
  91. package/dist/lib/agent-setup-hint.d.ts +20 -0
  92. package/dist/lib/agent-setup-hint.d.ts.map +1 -0
  93. package/dist/lib/agent-setup-hint.js +33 -0
  94. package/dist/lib/agent-setup-hint.js.map +1 -0
  95. package/dist/lib/agent-skill.d.ts +14 -0
  96. package/dist/lib/agent-skill.d.ts.map +1 -0
  97. package/dist/lib/agent-skill.js +83 -0
  98. package/dist/lib/agent-skill.js.map +1 -0
  99. package/dist/lib/cloud-abort.d.ts +2 -0
  100. package/dist/lib/cloud-abort.d.ts.map +1 -0
  101. package/dist/lib/cloud-abort.js +12 -0
  102. package/dist/lib/cloud-abort.js.map +1 -0
  103. package/dist/lib/cloud-auth.d.ts +30 -0
  104. package/dist/lib/cloud-auth.d.ts.map +1 -0
  105. package/dist/lib/cloud-auth.js +179 -0
  106. package/dist/lib/cloud-auth.js.map +1 -0
  107. package/dist/lib/cloud-config.d.ts +31 -0
  108. package/dist/lib/cloud-config.d.ts.map +1 -0
  109. package/dist/lib/cloud-config.js +128 -0
  110. package/dist/lib/cloud-config.js.map +1 -0
  111. package/dist/lib/cloud-organizations.d.ts +17 -0
  112. package/dist/lib/cloud-organizations.d.ts.map +1 -0
  113. package/dist/lib/cloud-organizations.js +36 -0
  114. package/dist/lib/cloud-organizations.js.map +1 -0
  115. package/dist/lib/cloud-provision.d.ts +20 -0
  116. package/dist/lib/cloud-provision.d.ts.map +1 -0
  117. package/dist/lib/cloud-provision.js +59 -0
  118. package/dist/lib/cloud-provision.js.map +1 -0
  119. package/dist/lib/cloud-remote.d.ts +37 -0
  120. package/dist/lib/cloud-remote.d.ts.map +1 -0
  121. package/dist/lib/cloud-remote.js +118 -0
  122. package/dist/lib/cloud-remote.js.map +1 -0
  123. package/dist/lib/cloud-setup-login.d.ts +9 -0
  124. package/dist/lib/cloud-setup-login.d.ts.map +1 -0
  125. package/dist/lib/cloud-setup-login.js +136 -0
  126. package/dist/lib/cloud-setup-login.js.map +1 -0
  127. package/dist/lib/cloud-url.d.ts +3 -0
  128. package/dist/lib/cloud-url.d.ts.map +1 -0
  129. package/dist/lib/cloud-url.js +10 -0
  130. package/dist/lib/cloud-url.js.map +1 -0
  131. package/dist/lib/create-project.d.ts +51 -0
  132. package/dist/lib/create-project.d.ts.map +1 -0
  133. package/dist/lib/create-project.js +458 -0
  134. package/dist/lib/create-project.js.map +1 -0
  135. package/dist/lib/handle-cli-error.d.ts +2 -0
  136. package/dist/lib/handle-cli-error.d.ts.map +1 -0
  137. package/dist/lib/handle-cli-error.js +16 -0
  138. package/dist/lib/handle-cli-error.js.map +1 -0
  139. package/dist/lib/init-finish.d.ts +46 -0
  140. package/dist/lib/init-finish.d.ts.map +1 -0
  141. package/dist/lib/init-finish.js +187 -0
  142. package/dist/lib/init-finish.js.map +1 -0
  143. package/dist/lib/install-ai-sdk-lib.d.ts +2 -0
  144. package/dist/lib/install-ai-sdk-lib.d.ts.map +1 -0
  145. package/dist/lib/install-ai-sdk-lib.js +21 -0
  146. package/dist/lib/install-ai-sdk-lib.js.map +1 -0
  147. package/dist/lib/install-edge-lib.d.ts +2 -0
  148. package/dist/lib/install-edge-lib.d.ts.map +1 -0
  149. package/dist/lib/install-edge-lib.js +14 -0
  150. package/dist/lib/install-edge-lib.js.map +1 -0
  151. package/dist/lib/run-spawn.d.ts +21 -0
  152. package/dist/lib/run-spawn.d.ts.map +1 -0
  153. package/dist/lib/run-spawn.js +118 -0
  154. package/dist/lib/run-spawn.js.map +1 -0
  155. package/dist/lib/safe-project-file.d.ts +2 -0
  156. package/dist/lib/safe-project-file.d.ts.map +1 -0
  157. package/dist/lib/safe-project-file.js +25 -0
  158. package/dist/lib/safe-project-file.js.map +1 -0
  159. package/dist/lib/setup-session.d.ts +44 -0
  160. package/dist/lib/setup-session.d.ts.map +1 -0
  161. package/dist/lib/setup-session.js +122 -0
  162. package/dist/lib/setup-session.js.map +1 -0
  163. package/dist/lib/transform-options.d.ts +7 -0
  164. package/dist/lib/transform-options.d.ts.map +1 -0
  165. package/dist/lib/transform-options.js +0 -0
  166. package/dist/lib/transform.d.ts +17 -0
  167. package/dist/lib/transform.d.ts.map +1 -0
  168. package/dist/lib/transform.js +75 -0
  169. package/dist/lib/transform.js.map +1 -0
  170. package/dist/lib/upgrade.d.ts +9 -0
  171. package/dist/lib/upgrade.d.ts.map +1 -0
  172. package/dist/lib/upgrade.js +68 -0
  173. package/dist/lib/upgrade.js.map +1 -0
  174. package/dist/lib/utils/config.d.ts +20 -0
  175. package/dist/lib/utils/config.d.ts.map +1 -0
  176. package/dist/lib/utils/config.js +28 -0
  177. package/dist/lib/utils/config.js.map +1 -0
  178. package/dist/lib/utils/download.d.ts +5 -0
  179. package/dist/lib/utils/download.d.ts.map +1 -0
  180. package/dist/lib/utils/download.js +40 -0
  181. package/dist/lib/utils/download.js.map +1 -0
  182. package/dist/lib/utils/file-scanner.d.ts +15 -0
  183. package/dist/lib/utils/file-scanner.d.ts.map +1 -0
  184. package/dist/lib/utils/file-scanner.js +37 -0
  185. package/dist/lib/utils/file-scanner.js.map +1 -0
  186. package/dist/lib/utils/logger.d.ts +9 -0
  187. package/dist/lib/utils/logger.d.ts.map +1 -0
  188. package/dist/lib/utils/logger.js +25 -0
  189. package/dist/lib/utils/logger.js.map +1 -0
  190. package/dist/lib/utils/package-installer.d.ts +9 -0
  191. package/dist/lib/utils/package-installer.d.ts.map +1 -0
  192. package/dist/lib/utils/package-installer.js +21 -0
  193. package/dist/lib/utils/package-installer.js.map +1 -0
  194. package/dist/lib/utils/package-json.d.ts +2 -0
  195. package/dist/lib/utils/package-json.d.ts.map +1 -0
  196. package/dist/lib/utils/package-json.js +10 -0
  197. package/dist/lib/utils/package-json.js.map +1 -0
  198. package/dist/lib/utils/package-manager.d.ts +24 -0
  199. package/dist/lib/utils/package-manager.d.ts.map +1 -0
  200. package/dist/lib/utils/package-manager.js +117 -0
  201. package/dist/lib/utils/package-manager.js.map +1 -0
  202. package/dist/lib/utils/registry.d.ts +6 -0
  203. package/dist/lib/utils/registry.d.ts.map +1 -0
  204. package/dist/lib/utils/registry.js +35 -0
  205. package/dist/lib/utils/registry.js.map +1 -0
  206. package/dist/lib/utils/workspace.d.ts +3 -0
  207. package/dist/lib/utils/workspace.d.ts.map +1 -0
  208. package/dist/lib/utils/workspace.js +27 -0
  209. package/dist/lib/utils/workspace.js.map +1 -0
  210. package/dist/program.d.ts +3 -0
  211. package/dist/program.d.ts.map +1 -0
  212. package/dist/program.js +22 -0
  213. package/dist/program.js.map +1 -0
  214. package/dist/run.d.ts +2 -0
  215. package/dist/run.d.ts.map +1 -0
  216. package/dist/run.js +8 -0
  217. package/dist/run.js.map +1 -0
  218. package/package.json +76 -4
  219. package/src/codemods/utils/createTransformer.ts +41 -0
  220. package/src/codemods/utils/resolveBinding.test.ts +107 -0
  221. package/src/codemods/utils/resolveBinding.ts +130 -0
  222. package/src/codemods/v0-11/README.md +246 -0
  223. package/src/codemods/v0-11/__tests__/content-part-to-message-part.test.ts +496 -0
  224. package/src/codemods/v0-11/content-part-to-message-part.ts +302 -0
  225. package/src/codemods/v0-12/__tests__/assistant-api-to-aui.test.ts +1220 -0
  226. package/src/codemods/v0-12/__tests__/event-names-to-camelcase.test.ts +150 -0
  227. package/src/codemods/v0-12/__tests__/primitive-if-to-aui-if.test.ts +1166 -0
  228. package/src/codemods/v0-12/assistant-api-to-aui.ts +270 -0
  229. package/src/codemods/v0-12/event-names-to-camelcase.ts +47 -0
  230. package/src/codemods/v0-12/primitive-if-to-aui-if.ts +372 -0
  231. package/src/codemods/v0-15/__tests__/aui-accessor-calls-to-properties.test.ts +210 -0
  232. package/src/codemods/v0-15/aui-accessor-calls-to-properties.ts +138 -0
  233. package/src/codemods/v0-8/__tests__/ui-package-split.test.ts +83 -0
  234. package/src/codemods/v0-8/ui-package-split.ts +159 -0
  235. package/src/codemods/v0-9/edge-package-split.test.ts +100 -0
  236. package/src/codemods/v0-9/edge-package-split.ts +70 -0
  237. package/src/commands/add.ts +111 -0
  238. package/src/commands/agent.ts +31 -0
  239. package/src/commands/cloud.test.ts +477 -0
  240. package/src/commands/cloud.ts +523 -0
  241. package/src/commands/create.ts +914 -0
  242. package/src/commands/doctor.ts +425 -0
  243. package/src/commands/info.ts +481 -0
  244. package/src/commands/init.ts +156 -0
  245. package/src/commands/mcp.test.ts +123 -0
  246. package/src/commands/mcp.ts +475 -0
  247. package/src/commands/setup.test.ts +285 -0
  248. package/src/commands/setup.ts +240 -0
  249. package/src/commands/update.ts +86 -0
  250. package/src/commands/upgrade.ts +66 -0
  251. package/src/index.ts +6 -0
  252. package/src/lib/agent-gate.test.ts +435 -0
  253. package/src/lib/agent-gate.ts +271 -0
  254. package/src/lib/agent-setup-hint.test.ts +134 -0
  255. package/src/lib/agent-setup-hint.ts +56 -0
  256. package/src/lib/agent-skill.ts +107 -0
  257. package/src/lib/cloud-abort.ts +12 -0
  258. package/src/lib/cloud-auth.test.ts +536 -0
  259. package/src/lib/cloud-auth.ts +299 -0
  260. package/src/lib/cloud-config.test.ts +220 -0
  261. package/src/lib/cloud-config.ts +217 -0
  262. package/src/lib/cloud-organizations.test.ts +76 -0
  263. package/src/lib/cloud-organizations.ts +55 -0
  264. package/src/lib/cloud-provision.test.ts +157 -0
  265. package/src/lib/cloud-provision.ts +96 -0
  266. package/src/lib/cloud-remote.test.ts +252 -0
  267. package/src/lib/cloud-remote.ts +236 -0
  268. package/src/lib/cloud-setup-login.test.ts +361 -0
  269. package/src/lib/cloud-setup-login.ts +240 -0
  270. package/src/lib/cloud-url.ts +21 -0
  271. package/src/lib/create-project-format.test.ts +122 -0
  272. package/src/lib/create-project.test.ts +158 -0
  273. package/src/lib/create-project.ts +717 -0
  274. package/src/lib/handle-cli-error.test.ts +67 -0
  275. package/src/lib/handle-cli-error.ts +17 -0
  276. package/src/lib/init-finish.ts +293 -0
  277. package/src/lib/install-ai-sdk-lib.ts +25 -0
  278. package/src/lib/install-edge-lib.ts +16 -0
  279. package/src/lib/run-spawn.test.ts +194 -0
  280. package/src/lib/run-spawn.ts +154 -0
  281. package/src/lib/safe-project-file.ts +31 -0
  282. package/src/lib/setup-session.test.ts +184 -0
  283. package/src/lib/setup-session.ts +179 -0
  284. package/src/lib/transform-files.test.ts +69 -0
  285. package/src/lib/transform-options.ts +6 -0
  286. package/src/lib/transform.test.ts +155 -0
  287. package/src/lib/transform.ts +131 -0
  288. package/src/lib/upgrade.ts +89 -0
  289. package/src/lib/utils/config.ts +60 -0
  290. package/src/lib/utils/download.ts +57 -0
  291. package/src/lib/utils/file-scanner.ts +51 -0
  292. package/src/lib/utils/logger.ts +22 -0
  293. package/src/lib/utils/package-installer.test.ts +39 -0
  294. package/src/lib/utils/package-installer.ts +40 -0
  295. package/src/lib/utils/package-json.ts +12 -0
  296. package/src/lib/utils/package-manager.ts +160 -0
  297. package/src/lib/utils/registry.test.ts +164 -0
  298. package/src/lib/utils/registry.ts +78 -0
  299. package/src/lib/utils/workspace.ts +34 -0
  300. package/src/program.ts +37 -0
  301. package/src/run.test.ts +23 -0
  302. package/src/run.ts +5 -0
  303. package/templates/cloud-harness/.assistant-ui/template.json +3 -0
  304. package/templates/cloud-harness/.env.example +1 -0
  305. package/templates/cloud-harness/.oxfmtrc.json +32 -0
  306. package/templates/cloud-harness/README.md +28 -0
  307. package/templates/cloud-harness/app/api/chat/route.ts +22 -0
  308. package/templates/cloud-harness/app/api/credential/route.ts +14 -0
  309. package/templates/cloud-harness/app/api/request-context.ts +16 -0
  310. package/templates/cloud-harness/app/assistant.tsx +83 -0
  311. package/templates/cloud-harness/app/favicon.ico +0 -0
  312. package/templates/cloud-harness/app/globals.css +139 -0
  313. package/templates/cloud-harness/app/layout.tsx +37 -0
  314. package/templates/cloud-harness/app/page.tsx +5 -0
  315. package/templates/cloud-harness/components/assistant-ui/elements/attachment-state.ts +59 -0
  316. package/templates/cloud-harness/components/assistant-ui/elements/attachment.aui.tsx +246 -0
  317. package/templates/cloud-harness/components/assistant-ui/elements/collapsible-root.tsx +19 -0
  318. package/templates/cloud-harness/components/assistant-ui/elements/markdown-text.tsx +238 -0
  319. package/templates/cloud-harness/components/assistant-ui/elements/thread.aui.tsx +521 -0
  320. package/templates/cloud-harness/components/assistant-ui/elements/tool-fallback.aui.tsx +1336 -0
  321. package/templates/cloud-harness/components/assistant-ui/elements/tooltip-icon-button.tsx +49 -0
  322. package/templates/cloud-harness/components/ui/avatar.tsx +109 -0
  323. package/templates/cloud-harness/components/ui/button.tsx +58 -0
  324. package/templates/cloud-harness/components/ui/collapsible.tsx +21 -0
  325. package/templates/cloud-harness/components/ui/dialog.tsx +159 -0
  326. package/templates/cloud-harness/components/ui/textarea.tsx +18 -0
  327. package/templates/cloud-harness/components/ui/tooltip.tsx +69 -0
  328. package/templates/cloud-harness/components.json +24 -0
  329. package/templates/cloud-harness/hooks/use-attachment-src.ts +46 -0
  330. package/templates/cloud-harness/hooks/use-copy-to-clipboard.ts +54 -0
  331. package/templates/cloud-harness/lib/utils.ts +1 -0
  332. package/templates/cloud-harness/next.config.ts +6 -0
  333. package/templates/cloud-harness/package.json +51 -0
  334. package/templates/cloud-harness/postcss.config.mjs +5 -0
  335. package/templates/cloud-harness/tsconfig.json +33 -0
  336. package/templates/cloud-harness/vendor/LICENSE +21 -0
  337. package/templates/cloud-harness/vendor/README.md +13 -0
  338. package/templates/cloud-harness/vendor/assistant-ui-react-harness-sdk-0.0.2.tgz +0 -0
  339. package/templates/cloud-harness/vendor/harness-sdk-0.3.1.tgz +0 -0
  340. package/templates/cloud-harness/vendor/provenance.json +38 -0
  341. package/templates/cloud-harness/vendor/statewire-0.19.3.tgz +0 -0
@@ -0,0 +1,154 @@
1
+ import { spawn } from "cross-spawn";
2
+
3
+ export class SpawnExitError extends Error {
4
+ code: number;
5
+ stderr: string;
6
+ stdout: string;
7
+
8
+ constructor(code: number, stderr = "", stdout = "") {
9
+ const output = [stdout, stderr].filter(Boolean).join("\n");
10
+ super(
11
+ output
12
+ ? `Process exited with code ${code}\n${output}`
13
+ : `Process exited with code ${code}`,
14
+ );
15
+ this.code = code;
16
+ this.stderr = stderr;
17
+ this.stdout = stdout;
18
+ }
19
+ }
20
+
21
+ export class SpawnSignalError extends Error {
22
+ signal: NodeJS.Signals;
23
+ forwarded: boolean;
24
+
25
+ constructor(signal: NodeJS.Signals, forwarded: boolean) {
26
+ super(`Process terminated by ${signal}`);
27
+ this.signal = signal;
28
+ this.forwarded = forwarded;
29
+ }
30
+ }
31
+
32
+ export interface SpawnResult {
33
+ code: number | null;
34
+ signal: NodeJS.Signals | null;
35
+ stdout: string;
36
+ stderr: string;
37
+ }
38
+
39
+ let activeSpawns = 0;
40
+
41
+ // A spawn that is forwarding a signal owns termination for that window, so
42
+ // callers with their own cleanup listeners defer to it instead of racing it.
43
+ export const hasActiveSpawn = (): boolean => activeSpawns > 0;
44
+
45
+ function spawnProcess(
46
+ command: string,
47
+ args: string[],
48
+ cwd: string | undefined,
49
+ captureOutput: boolean,
50
+ ): Promise<SpawnResult> {
51
+ return new Promise((resolve, reject) => {
52
+ const child = spawn(command, args, {
53
+ stdio: captureOutput ? ["ignore", "pipe", "pipe"] : "inherit",
54
+ cwd,
55
+ });
56
+ let forwardedSignal: NodeJS.Signals | null = null;
57
+ let escalated = false;
58
+ let settled = false;
59
+ let stdout = "";
60
+ let stderr = "";
61
+
62
+ if (captureOutput) {
63
+ child.stdout?.setEncoding("utf8");
64
+ child.stdout?.on("data", (chunk: string) => {
65
+ stdout += chunk;
66
+ });
67
+ child.stderr?.setEncoding("utf8");
68
+ child.stderr?.on("data", (chunk: string) => {
69
+ stderr += chunk;
70
+ });
71
+ }
72
+
73
+ const cleanup = () => {
74
+ activeSpawns -= 1;
75
+ process.off("SIGINT", onSigint);
76
+ process.off("SIGTERM", onSigterm);
77
+ };
78
+
79
+ const rejectForwardedSignal = () => {
80
+ if (settled || forwardedSignal === null) return false;
81
+ settled = true;
82
+ child.stdout?.destroy();
83
+ child.stderr?.destroy();
84
+ cleanup();
85
+ reject(new SpawnSignalError(forwardedSignal, true));
86
+ return true;
87
+ };
88
+
89
+ const forwardSignal = (signal: NodeJS.Signals) => {
90
+ if (forwardedSignal !== null) {
91
+ if (!escalated) {
92
+ escalated = true;
93
+ child.kill("SIGKILL");
94
+ return;
95
+ }
96
+
97
+ rejectForwardedSignal();
98
+ return;
99
+ }
100
+
101
+ forwardedSignal = signal;
102
+ child.kill(signal);
103
+ };
104
+ const onSigint = () => forwardSignal("SIGINT");
105
+ const onSigterm = () => forwardSignal("SIGTERM");
106
+
107
+ activeSpawns += 1;
108
+ process.on("SIGINT", onSigint);
109
+ process.on("SIGTERM", onSigterm);
110
+
111
+ child.on("error", (error) => {
112
+ if (settled) return;
113
+ if (rejectForwardedSignal()) return;
114
+ settled = true;
115
+ cleanup();
116
+ reject(error);
117
+ });
118
+ // "close" waits for stdio pipes, which a grandchild can hold open after
119
+ // the child is reaped, so a forwarded signal settles on "exit".
120
+ child.on("exit", () => {
121
+ rejectForwardedSignal();
122
+ });
123
+ child.on("close", (code, signal) => {
124
+ if (settled) return;
125
+ if (rejectForwardedSignal()) return;
126
+ settled = true;
127
+ cleanup();
128
+ resolve({ code, signal: signal ?? null, stdout, stderr });
129
+ });
130
+ });
131
+ }
132
+
133
+ export function runSpawn(
134
+ command: string,
135
+ args: string[],
136
+ cwd?: string,
137
+ ): Promise<void> {
138
+ return spawnProcess(command, args, cwd, false).then(({ code, signal }) => {
139
+ if (signal != null) {
140
+ throw new SpawnSignalError(signal, false);
141
+ }
142
+ if (code !== 0) {
143
+ throw new SpawnExitError(code || 1);
144
+ }
145
+ });
146
+ }
147
+
148
+ export function runSpawnCapture(
149
+ command: string,
150
+ args: string[],
151
+ cwd?: string,
152
+ ): Promise<SpawnResult> {
153
+ return spawnProcess(command, args, cwd, true);
154
+ }
@@ -0,0 +1,31 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ export const assertSafeProjectFile = (file: string, projectRoot: string) => {
5
+ try {
6
+ if (fs.lstatSync(file).isSymbolicLink()) {
7
+ throw new Error(`${file} is a symbolic link`);
8
+ }
9
+ } catch (error) {
10
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
11
+ }
12
+
13
+ const root = fs.realpathSync(projectRoot);
14
+ let parent = path.dirname(file);
15
+ const missing: string[] = [];
16
+ while (!fs.existsSync(parent)) {
17
+ const next = path.dirname(parent);
18
+ if (next === parent) break;
19
+ missing.unshift(path.basename(parent));
20
+ parent = next;
21
+ }
22
+ const resolvedParent = path.join(fs.realpathSync(parent), ...missing);
23
+ const relative = path.relative(root, resolvedParent);
24
+ if (
25
+ relative === ".." ||
26
+ relative.startsWith(`..${path.sep}`) ||
27
+ path.isAbsolute(relative)
28
+ ) {
29
+ throw new Error(`${file} has a parent directory outside the project`);
30
+ }
31
+ };
@@ -0,0 +1,184 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ boxed,
4
+ clipboardCommands,
5
+ copyToClipboard,
6
+ DEFAULT_DOCS_URL,
7
+ DEFAULT_SETUP_APP_URL,
8
+ DEFAULT_SETUP_SERVER,
9
+ parseCatalog,
10
+ parseProducts,
11
+ resolveEndpoints,
12
+ resolveProducts,
13
+ setupPrompt,
14
+ } from "./setup-session";
15
+
16
+ describe("parseProducts", () => {
17
+ it("defaults to assistant-ui and dedupes a list", () => {
18
+ expect(parseProducts(undefined)).toEqual(["assistant-ui"]);
19
+ expect(parseProducts(" ")).toEqual(["assistant-ui"]);
20
+ expect(parseProducts("assistant-ui, cloud,cloud")).toEqual([
21
+ "assistant-ui",
22
+ "cloud",
23
+ ]);
24
+ });
25
+
26
+ it("accepts slugs with path segments and refuses what is not a slug", () => {
27
+ expect(parseProducts("guides/latex")).toEqual(["guides/latex"]);
28
+ expect(() => parseProducts("cloud;rm")).toThrow('"cloud;rm"');
29
+ expect(() => parseProducts("../etc")).toThrow('"../etc"');
30
+ expect(() => parseProducts("guides//x")).toThrow('"guides//x"');
31
+ });
32
+ });
33
+
34
+ describe("resolveProducts", () => {
35
+ const catalog = `# assistant-ui catalog
36
+
37
+ ## assistant-ui
38
+
39
+ Slug: assistant-ui
40
+ Kind: Library
41
+
42
+ ## Assistant Cloud
43
+
44
+ Slug: cloud
45
+
46
+ - Thread persistence that saves during streaming
47
+
48
+ ## Guides and elements
49
+
50
+ - react-app: React project (https://docs.test/docs/installation.md, agent time 2–5 min)
51
+ - guides/latex: LaTeX math (https://docs.test/docs/guides/latex.md, agent time 2–5 min)
52
+ `;
53
+
54
+ it("reads names of products, guides and elements from the catalog", () => {
55
+ expect([...parseCatalog(catalog)]).toEqual([
56
+ ["assistant-ui", "assistant-ui"],
57
+ ["cloud", "Assistant Cloud"],
58
+ ["react-app", "React project"],
59
+ ["guides/latex", "LaTeX math"],
60
+ ]);
61
+ });
62
+
63
+ it("names products and points each at its install guide", async () => {
64
+ await expect(
65
+ resolveProducts(["cloud"], "https://docs.test", async () =>
66
+ parseCatalog(catalog),
67
+ ),
68
+ ).resolves.toEqual([
69
+ {
70
+ slug: "cloud",
71
+ name: "Assistant Cloud",
72
+ guide: "https://docs.test/install.md?items=cloud",
73
+ },
74
+ ]);
75
+ });
76
+
77
+ it("refuses a product the catalog does not list", async () => {
78
+ await expect(
79
+ resolveProducts(["nope"], "https://docs.test", async () =>
80
+ parseCatalog(catalog),
81
+ ),
82
+ ).rejects.toThrow(
83
+ 'unknown product "nope"; pick from assistant-ui, cloud, react-app, guides/latex',
84
+ );
85
+ });
86
+
87
+ it("falls back to the slug when the catalog is unreachable", async () => {
88
+ await expect(
89
+ resolveProducts(
90
+ ["assistant-ui"],
91
+ "https://docs.test",
92
+ async () => undefined,
93
+ ),
94
+ ).resolves.toEqual([
95
+ {
96
+ slug: "assistant-ui",
97
+ name: "assistant-ui",
98
+ guide: "https://docs.test/install.md?items=assistant-ui",
99
+ },
100
+ ]);
101
+ });
102
+ });
103
+
104
+ describe("resolveEndpoints", () => {
105
+ it("uses production unless a flag or the environment says otherwise", () => {
106
+ expect(resolveEndpoints({}, {})).toEqual({
107
+ docsUrl: "https://www.assistant-ui.com",
108
+ setupServer: "https://checkout.assistant-ui.com",
109
+ setupAppUrl: "https://setup.assistant-ui.com",
110
+ });
111
+ expect(
112
+ resolveEndpoints(
113
+ { setupServer: "http://localhost:8791/" },
114
+ {
115
+ ASSISTANT_UI_DOCS_URL: "http://localhost:3000",
116
+ ASSISTANT_UI_SETUP_APP_URL: "http://localhost:3011",
117
+ },
118
+ ),
119
+ ).toEqual({
120
+ docsUrl: "http://localhost:3000",
121
+ setupServer: "http://localhost:8791",
122
+ setupAppUrl: "http://localhost:3011",
123
+ });
124
+ });
125
+
126
+ it("opens the browser on the setup app and meets the agent on the setup worker by default", () => {
127
+ expect(DEFAULT_SETUP_APP_URL).toBe("https://setup.assistant-ui.com");
128
+ expect(DEFAULT_SETUP_SERVER).toBe("https://checkout.assistant-ui.com");
129
+ expect(DEFAULT_DOCS_URL).toBe("https://www.assistant-ui.com");
130
+ });
131
+
132
+ it("refuses plain http off this machine", () => {
133
+ expect(() => resolveEndpoints({ docsUrl: "http://evil.test" }, {})).toThrow(
134
+ "https",
135
+ );
136
+ });
137
+ });
138
+
139
+ describe("the prompt for a person", () => {
140
+ it("is the bare prompt, naming the command only for products other than the default", () => {
141
+ expect(setupPrompt()).toBe("install and set up assistant-ui");
142
+ expect(setupPrompt(["assistant-ui"])).toBe(setupPrompt());
143
+ expect(setupPrompt(["assistant-ui", "cloud"])).toBe(
144
+ "install and set up assistant-ui with `npx assistant-ui@latest setup --products assistant-ui,cloud`",
145
+ );
146
+ });
147
+
148
+ it("draws the prompt in a box", () => {
149
+ expect(boxed("hi", 1)).toBe(
150
+ ["┌────┐", "│ │", "│ hi │", "│ │", "└────┘"].join("\n"),
151
+ );
152
+ });
153
+
154
+ it("copies with the platform's clipboard command", async () => {
155
+ expect(clipboardCommands("darwin", {})).toEqual([
156
+ { command: "pbcopy", args: [] },
157
+ ]);
158
+ expect(clipboardCommands("win32", {})[0]?.command).toBe("clip");
159
+ expect(
160
+ clipboardCommands("linux", { WAYLAND_DISPLAY: "wayland-0" }).map(
161
+ (entry) => entry.command,
162
+ ),
163
+ ).toEqual(["wl-copy", "xclip", "xsel"]);
164
+ expect(
165
+ clipboardCommands("linux", {}).map((entry) => entry.command),
166
+ ).toEqual(["xclip", "xsel", "wl-copy"]);
167
+ });
168
+
169
+ it.skipIf(process.platform === "win32")(
170
+ "tries the next clipboard command when one fails",
171
+ async () => {
172
+ expect(
173
+ await copyToClipboard("x", [
174
+ { command: "no-such-clipboard-xyz", args: [] },
175
+ { command: "false", args: [] },
176
+ { command: "cat", args: [] },
177
+ ]),
178
+ ).toBe(true);
179
+ expect(await copyToClipboard("x", [{ command: "false", args: [] }])).toBe(
180
+ false,
181
+ );
182
+ },
183
+ );
184
+ });
@@ -0,0 +1,179 @@
1
+ import { spawn } from "node:child_process";
2
+ import type { Checkout } from "setup-agent";
3
+ import { parseSetupUrl } from "setup-agent/cli";
4
+
5
+ /** How an agent runs setup commands: `<SETUP_COMMAND> <url> <command>`. */
6
+ export const SETUP_COMMAND = "npx assistant-ui@latest setup";
7
+
8
+ /** The docs site: the catalog and the install guides. */
9
+ export const DEFAULT_DOCS_URL = "https://www.assistant-ui.com";
10
+ /** The setup worker the agent and the browser meet on. */
11
+ export const DEFAULT_SETUP_SERVER = "https://checkout.assistant-ui.com";
12
+ /** The setup app the user follows the setup in. */
13
+ export const DEFAULT_SETUP_APP_URL = "https://setup.assistant-ui.com";
14
+ const DEFAULT_PRODUCTS = ["assistant-ui"] as const;
15
+
16
+ /** A catalog slug: lowercase words joined by `-`, in `/`-separated segments (`guides/latex`). */
17
+ const SLUG = /^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)*$/;
18
+
19
+ /** The product slugs a `--products` list names, deduplicated; the default when empty. */
20
+ export const parseProducts = (value: string | undefined): string[] => {
21
+ const slugs = [
22
+ ...new Set(
23
+ (value ?? "")
24
+ .split(",")
25
+ .map((entry) => entry.trim())
26
+ .filter(Boolean),
27
+ ),
28
+ ];
29
+ for (const slug of slugs) {
30
+ if (!SLUG.test(slug)) throw new Error(`"${slug}" is not a product slug`);
31
+ }
32
+ return slugs.length > 0 ? slugs : [...DEFAULT_PRODUCTS];
33
+ };
34
+
35
+ /**
36
+ * Product names by slug, read from the catalog: its products are `## Name`
37
+ * sections with a `Slug: slug` line, its guides and elements are
38
+ * `- slug: Name (url, …)` bullets.
39
+ */
40
+ export const parseCatalog = (markdown: string): Map<string, string> => {
41
+ const names = new Map<string, string>();
42
+ for (const match of markdown.matchAll(/^## (.+)\n+Slug: (\S+)$/gm)) {
43
+ names.set(match[2]!, match[1]!.trim());
44
+ }
45
+ for (const match of markdown.matchAll(
46
+ /^- ([a-z0-9][a-z0-9/-]*): ([^(\n]+?) \(https?:\/\//gm,
47
+ )) {
48
+ names.set(match[1]!, match[2]!.trim());
49
+ }
50
+ return names;
51
+ };
52
+
53
+ const fetchCatalog = async (docsUrl: string) => {
54
+ try {
55
+ const response = await fetch(`${docsUrl}/catalog.md`, {
56
+ signal: AbortSignal.timeout(5000),
57
+ });
58
+ if (!response.ok) return undefined;
59
+ const names = parseCatalog(await response.text());
60
+ return names.size > 0 ? names : undefined;
61
+ } catch {
62
+ return undefined;
63
+ }
64
+ };
65
+
66
+ /** The products to seed a setup with, named from the catalog when it is reachable. */
67
+ export const resolveProducts = async (
68
+ slugs: readonly string[],
69
+ docsUrl: string,
70
+ catalog: () => Promise<Map<string, string> | undefined> = () =>
71
+ fetchCatalog(docsUrl),
72
+ ): Promise<Checkout.ProductSeed[]> => {
73
+ const names = await catalog();
74
+ if (names) {
75
+ const unknown = slugs.filter((slug) => !names.has(slug));
76
+ if (unknown.length > 0) {
77
+ throw new Error(
78
+ `unknown product ${unknown.map((slug) => `"${slug}"`).join(", ")}; pick from ${[...names.keys()].join(", ")}`,
79
+ );
80
+ }
81
+ }
82
+ return slugs.map((slug) => ({
83
+ slug,
84
+ name: names?.get(slug) ?? slug,
85
+ guide: `${docsUrl}/install.md?items=${slug}`,
86
+ }));
87
+ };
88
+
89
+ export type SetupEndpoints = {
90
+ docsUrl: string;
91
+ setupServer: string;
92
+ setupAppUrl: string;
93
+ };
94
+
95
+ /** The docs site, setup server and setup app, from flags, then the environment, then production. */
96
+ export const resolveEndpoints = (
97
+ options: { docsUrl?: string; setupServer?: string; setupAppUrl?: string },
98
+ env: NodeJS.ProcessEnv = process.env,
99
+ ): SetupEndpoints => ({
100
+ docsUrl: parseSetupUrl(
101
+ options.docsUrl ?? env.ASSISTANT_UI_DOCS_URL ?? DEFAULT_DOCS_URL,
102
+ ),
103
+ setupServer: parseSetupUrl(
104
+ options.setupServer ??
105
+ env.ASSISTANT_UI_SETUP_SERVER ??
106
+ DEFAULT_SETUP_SERVER,
107
+ ),
108
+ setupAppUrl: parseSetupUrl(
109
+ options.setupAppUrl ??
110
+ env.ASSISTANT_UI_SETUP_APP_URL ??
111
+ DEFAULT_SETUP_APP_URL,
112
+ ),
113
+ });
114
+
115
+ /** The prompt a person pastes into a coding agent, or the one it starts with. */
116
+ export const setupPrompt = (products?: readonly string[]) => {
117
+ const custom =
118
+ products !== undefined &&
119
+ (products.length !== DEFAULT_PRODUCTS.length ||
120
+ products.some((slug, index) => slug !== DEFAULT_PRODUCTS[index]));
121
+ return custom
122
+ ? `install and set up assistant-ui with \`npx assistant-ui@latest setup --products ${products.join(",")}\``
123
+ : "install and set up assistant-ui";
124
+ };
125
+
126
+ /** `text` framed in a box, one line per row, for the terminal. */
127
+ export const boxed = (text: string, padding = 2) => {
128
+ const lines = text.split("\n");
129
+ const width = Math.max(...lines.map((line) => line.length));
130
+ const pad = " ".repeat(padding);
131
+ const blank = `│${" ".repeat(width + padding * 2)}│`;
132
+ return [
133
+ `┌${"─".repeat(width + padding * 2)}┐`,
134
+ blank,
135
+ ...lines.map((line) => `│${pad}${line.padEnd(width)}${pad}│`),
136
+ blank,
137
+ `└${"─".repeat(width + padding * 2)}┘`,
138
+ ].join("\n");
139
+ };
140
+
141
+ type ClipboardCommand = { command: string; args: string[] };
142
+
143
+ /** The clipboard commands to try on this platform, in order. */
144
+ export const clipboardCommands = (
145
+ platform: NodeJS.Platform = process.platform,
146
+ env: NodeJS.ProcessEnv = process.env,
147
+ ): ClipboardCommand[] => {
148
+ if (platform === "darwin") return [{ command: "pbcopy", args: [] }];
149
+ if (platform === "win32") return [{ command: "clip", args: [] }];
150
+ const x11 = [
151
+ { command: "xclip", args: ["-selection", "clipboard"] },
152
+ { command: "xsel", args: ["--clipboard", "--input"] },
153
+ ];
154
+ return env.WAYLAND_DISPLAY
155
+ ? [{ command: "wl-copy", args: [] }, ...x11]
156
+ : [...x11, { command: "wl-copy", args: [] }];
157
+ };
158
+
159
+ const pipeTo = ({ command, args }: ClipboardCommand, text: string) =>
160
+ new Promise<boolean>((resolve) => {
161
+ const child = spawn(command, args, {
162
+ stdio: ["pipe", "ignore", "ignore"],
163
+ });
164
+ child.on("error", () => resolve(false));
165
+ child.on("exit", (code) => resolve(code === 0));
166
+ child.stdin.on("error", () => {});
167
+ child.stdin.end(text);
168
+ });
169
+
170
+ /** Copies `text` with the first clipboard command that works; false when none does. */
171
+ export const copyToClipboard = async (
172
+ text: string,
173
+ commands: ClipboardCommand[] = clipboardCommands(),
174
+ ) => {
175
+ for (const command of commands) {
176
+ if (await pipeTo(command, text)) return true;
177
+ }
178
+ return false;
179
+ };
@@ -0,0 +1,69 @@
1
+ import { describe, expect, it, onTestFinished } from "vitest";
2
+ import { mkdirSync, mkdtempSync, writeFileSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { dirname, join, relative } from "node:path";
5
+ import { getRelevantFiles } from "./transform";
6
+
7
+ const fixture = () => {
8
+ const directory = mkdtempSync(join(tmpdir(), "aui-transform-files-"));
9
+ onTestFinished(() => rmSync(directory, { recursive: true, force: true }));
10
+ const write = (
11
+ name: string,
12
+ source = 'import { useAssistantApi } from "@assistant-ui/react";',
13
+ ) => {
14
+ const file = join(directory, name);
15
+ mkdirSync(dirname(file), { recursive: true });
16
+ writeFileSync(file, source);
17
+ return file;
18
+ };
19
+ return { directory, write };
20
+ };
21
+
22
+ describe("codemod file discovery", () => {
23
+ it.each(["js", "jsx", "ts", "tsx"])(
24
+ "accepts an explicit .%s target",
25
+ (extension) => {
26
+ const { write } = fixture();
27
+ const file = write(`my app.${extension}`);
28
+ expect(getRelevantFiles(file)).toEqual([file]);
29
+ expect(getRelevantFiles(relative(process.cwd(), file))).toEqual([file]);
30
+ },
31
+ );
32
+
33
+ it("keeps directory discovery filters", () => {
34
+ const { directory, write } = fixture();
35
+ const wanted = write("src/app.tsx");
36
+ for (const file of [
37
+ "node_modules/dependency.ts",
38
+ "dist/index.js",
39
+ "build/app.js",
40
+ "app.min.js",
41
+ "app.bundle.js",
42
+ "README.md",
43
+ ])
44
+ write(file);
45
+ write("unrelated.ts", "export const value = 1;");
46
+ expect(getRelevantFiles(directory)).toEqual([wanted]);
47
+ });
48
+
49
+ it.each([
50
+ "export const value = 1;",
51
+ 'import { useAui } from "@/lib/aui"; const aui = useAui(); aui.thread().getState();',
52
+ ])("accepts explicitly named files without package text: %s", (source) => {
53
+ const { write } = fixture();
54
+ const file = write("app.tsx", source);
55
+ expect(getRelevantFiles(file)).toEqual([file]);
56
+ });
57
+
58
+ it("skips unsupported explicit files", () => {
59
+ const { write } = fixture();
60
+ expect(getRelevantFiles(write("README.md"))).toEqual([]);
61
+ });
62
+
63
+ it("rejects a missing target rather than silently reporting no work", () => {
64
+ const { directory } = fixture();
65
+ expect(() => getRelevantFiles(join(directory, "missing.tsx"))).toThrow(
66
+ /ENOENT/,
67
+ );
68
+ });
69
+ });
@@ -0,0 +1,6 @@
1
+ export interface TransformOptions {
2
+ dry?: boolean;
3
+ print?: boolean;
4
+ verbose?: boolean;
5
+ jscodeshift?: string;
6
+ }