@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,270 @@
1
+ import { createTransformer } from "../utils/createTransformer";
2
+ import { resolveBinding } from "../utils/resolveBinding";
3
+
4
+ // Map of old hook names to new hook names
5
+ const hookRenamingMap: Record<string, string> = {
6
+ useAssistantApi: "useAui",
7
+ useAssistantState: "useAuiState",
8
+ useAssistantEvent: "useAuiEvent",
9
+ };
10
+
11
+ // Map of old component names to new component names
12
+ const componentRenamingMap: Record<string, string> = {
13
+ AssistantIf: "AuiIf",
14
+ AssistantProvider: "AuiProvider",
15
+ };
16
+
17
+ const migrateAssistantApiToAui = createTransformer(
18
+ ({ j, root, markAsChanged }) => {
19
+ root.find(j.ImportDeclaration).forEach((path: any) => {
20
+ const source = path.value.source.value;
21
+ if (typeof source !== "string" || !source.startsWith("@assistant-ui/"))
22
+ return;
23
+ path.value.specifiers?.forEach((specifier: any, index: number) => {
24
+ if (
25
+ !j.ImportSpecifier.check(specifier) ||
26
+ !j.Identifier.check(specifier.imported)
27
+ )
28
+ return;
29
+ const oldName = specifier.imported.name;
30
+ const importKind = (specifier as { importKind?: string }).importKind;
31
+ const newName =
32
+ hookRenamingMap[oldName] ?? componentRenamingMap[oldName];
33
+ if (!newName) return;
34
+ if (
35
+ specifier.local?.name === oldName &&
36
+ path.value.importKind !== "type" &&
37
+ importKind !== "type"
38
+ ) {
39
+ const references = root
40
+ .find(j.Identifier, { name: oldName })
41
+ .paths()
42
+ .filter((reference: any) => {
43
+ const parent = reference.parent.value;
44
+ const node = reference.value;
45
+ if (parent.type.startsWith("Import") || parent.id === node)
46
+ return false;
47
+ if (
48
+ parent.key === node &&
49
+ !parent.computed &&
50
+ parent.value !== node
51
+ )
52
+ return false;
53
+ if (parent.property === node && !parent.computed) return false;
54
+ if (j.TSQualifiedName.check(parent) && parent.right === node)
55
+ return false;
56
+ if (
57
+ j.JSXAttribute.check(parent) ||
58
+ j.JSXNamespacedName.check(parent)
59
+ )
60
+ return false;
61
+ if (j.ExportSpecifier.check(parent)) {
62
+ if (
63
+ reference.parent.parent.value.source ||
64
+ parent.local !== node
65
+ )
66
+ return false;
67
+ }
68
+ return resolveBinding(j, reference, oldName) === specifier.local;
69
+ });
70
+ const canRename =
71
+ !resolveBinding(j, path, newName) &&
72
+ references.every(
73
+ (reference: any) => !resolveBinding(j, reference, newName),
74
+ );
75
+ if (canRename) {
76
+ for (const reference of references) {
77
+ const parent = reference.parent.value;
78
+ if (
79
+ (j.Property.check(parent) || j.ObjectProperty.check(parent)) &&
80
+ parent.shorthand
81
+ ) {
82
+ parent.shorthand = false;
83
+ parent.key = j.identifier(oldName);
84
+ parent.value = j.identifier(newName);
85
+ } else if (j.ExportSpecifier.check(parent)) {
86
+ reference.parent.replace(
87
+ j.exportSpecifier.from({
88
+ local: j.identifier(newName),
89
+ exported: j.Identifier.check(parent.exported)
90
+ ? j.identifier(parent.exported.name)
91
+ : parent.exported,
92
+ }),
93
+ );
94
+ } else {
95
+ reference.value.name = newName;
96
+ }
97
+ }
98
+ specifier.local.name = newName;
99
+ }
100
+ }
101
+ const replacement: any = j.importSpecifier(
102
+ j.identifier(newName),
103
+ j.Identifier.check(specifier.local)
104
+ ? j.identifier(specifier.local.name)
105
+ : null,
106
+ );
107
+ replacement.importKind = importKind;
108
+ replacement.comments = specifier.comments;
109
+ path.get("specifiers", index).replace(replacement);
110
+ markAsChanged();
111
+ });
112
+ });
113
+
114
+ const hookBindings = new Set<any>();
115
+ root.find(j.ImportDeclaration).forEach((path) => {
116
+ if (
117
+ !String(path.value.source.value).startsWith("@assistant-ui/") ||
118
+ path.value.importKind === "type"
119
+ )
120
+ return;
121
+ for (const specifier of path.value.specifiers ?? []) {
122
+ if (
123
+ j.ImportSpecifier.check(specifier) &&
124
+ j.Identifier.check(specifier.imported) &&
125
+ specifier.imported.name === "useAui" &&
126
+ (specifier as { importKind?: string }).importKind !== "type" &&
127
+ j.Identifier.check(specifier.local)
128
+ )
129
+ hookBindings.add(specifier.local);
130
+ }
131
+ });
132
+
133
+ const renamedDeclaratorIds = new Set<any>();
134
+ root.find(j.VariableDeclarator).forEach((path: any) => {
135
+ const { id, init } = path.value;
136
+ if (
137
+ j.Identifier.check(id) &&
138
+ id.name === "api" &&
139
+ j.CallExpression.check(init) &&
140
+ j.Identifier.check(init.callee) &&
141
+ hookBindings.has(
142
+ resolveBinding(j, path.get("init", "callee"), init.callee.name),
143
+ ) &&
144
+ !resolveBinding(j, path, "aui")
145
+ ) {
146
+ renamedDeclaratorIds.add(id);
147
+ }
148
+ });
149
+
150
+ // 3. Rename references governed by one of those declarators. Resolution
151
+ // is lexical (nearest enclosing declaration wins) rather than via
152
+ // ast-types scopes, which have no block granularity: a block-scoped
153
+ // `const api = other()` inside the same function must shadow.
154
+ if (renamedDeclaratorIds.size > 0) {
155
+ const bindsToRenamedApi = (path: any): boolean =>
156
+ renamedDeclaratorIds.has(resolveBinding(j, path, "api"));
157
+
158
+ const referencePaths: any[] = [];
159
+ root.find(j.Identifier, { name: "api" }).forEach((path: any) => {
160
+ const parent = path.parent.value;
161
+ if (j.ImportSpecifier.check(parent)) return;
162
+ // Declaration names (variable, function, class, type alias,
163
+ // interface) and TS type positions are not value references.
164
+ if (parent.id === path.value) return;
165
+ if (j.TSTypeReference?.check?.(parent)) return;
166
+ if (j.TSQualifiedName?.check?.(parent)) return;
167
+ // Any non-computed key position is a name, not a reference: object
168
+ // properties, object/class methods, class properties, TS signatures.
169
+ // Esprima-style shorthand reuses one node as key and value, so the
170
+ // value position must survive the guard.
171
+ if (
172
+ parent.key === path.value &&
173
+ !parent.computed &&
174
+ parent.value !== path.value
175
+ )
176
+ return;
177
+ if (
178
+ j.MemberExpression.check(parent) &&
179
+ parent.property === path.value &&
180
+ !parent.computed
181
+ )
182
+ return;
183
+ // JSXIdentifier extends Identifier, so JSX positions land here too:
184
+ // member properties (<config.api/>), namespace names, and lowercase
185
+ // element names (<api/> is an intrinsic tag) are not references.
186
+ if (
187
+ j.JSXMemberExpression?.check?.(parent) &&
188
+ parent.property === path.value
189
+ )
190
+ return;
191
+ if (j.JSXNamespacedName?.check?.(parent)) return;
192
+ if (
193
+ (j.JSXOpeningElement?.check?.(parent) ||
194
+ j.JSXClosingElement?.check?.(parent)) &&
195
+ parent.name === path.value
196
+ )
197
+ return;
198
+ if (j.JSXAttribute.check(parent)) return;
199
+ // The exported name of `export { api }` is the public alias, not a
200
+ // reference; only the local side is renamed (to `aui as api`). A
201
+ // source-bearing re-export binds in the other module, never here.
202
+ if (j.ExportSpecifier.check(parent)) {
203
+ const grandparent = path.parent.parent?.value;
204
+ if (
205
+ j.ExportNamedDeclaration.check(grandparent) &&
206
+ grandparent.source != null
207
+ )
208
+ return;
209
+ // Babel emits exportKind on ExportSpecifier for inline
210
+ // `export { type api }`; ast-types' typings omit it.
211
+ if (
212
+ grandparent?.exportKind === "type" ||
213
+ (parent as { exportKind?: string }).exportKind === "type"
214
+ )
215
+ return;
216
+ if (parent.exported === path.value && parent.local !== path.value)
217
+ return;
218
+ }
219
+ if (!bindsToRenamedApi(path)) return;
220
+ referencePaths.push(path);
221
+ });
222
+
223
+ for (const path of referencePaths) {
224
+ if (resolveBinding(j, path, "aui")) {
225
+ renamedDeclaratorIds.delete(resolveBinding(j, path, "api"));
226
+ }
227
+ }
228
+
229
+ for (const path of referencePaths) {
230
+ if (!bindsToRenamedApi(path)) continue;
231
+ const parent = path.parent.value;
232
+ if (
233
+ (j.Property.check(parent) || j.ObjectProperty.check(parent)) &&
234
+ parent.shorthand &&
235
+ parent.value === path.value
236
+ ) {
237
+ // `{ api }` in an object literal: keep the key, rename the value
238
+ parent.shorthand = false;
239
+ parent.key = j.identifier("api");
240
+ parent.value = j.identifier("aui");
241
+ } else if (
242
+ j.ExportSpecifier.check(parent) &&
243
+ parent.local === path.value
244
+ ) {
245
+ // `export { api }` / `export { api as name }`: rename the local
246
+ // binding, keep the public name. Replaced wholesale — recast keeps
247
+ // the shorthand form (dropping the alias) when only the fields of
248
+ // the original node change.
249
+ path.parent.replace(
250
+ j.exportSpecifier.from({
251
+ local: j.identifier("aui"),
252
+ exported: j.Identifier.check(parent.exported)
253
+ ? j.identifier(parent.exported.name)
254
+ : parent.exported,
255
+ }),
256
+ );
257
+ } else {
258
+ path.value.name = "aui";
259
+ }
260
+ markAsChanged();
261
+ }
262
+ for (const idNode of renamedDeclaratorIds) {
263
+ idNode.name = "aui";
264
+ markAsChanged();
265
+ }
266
+ }
267
+ },
268
+ );
269
+
270
+ export default migrateAssistantApiToAui;
@@ -0,0 +1,47 @@
1
+ import { createTransformer } from "../utils/createTransformer";
2
+
3
+ const eventNameMap: Record<string, string> = {
4
+ "thread.run-start": "thread.runStart",
5
+ "thread.run-end": "thread.runEnd",
6
+ "thread.model-context-update": "thread.modelContextUpdate",
7
+ "composer.attachment-add": "composer.attachmentAdd",
8
+ "thread-list-item.switched-to": "threadListItem.switchedTo",
9
+ "thread-list-item.switched-away": "threadListItem.switchedAway",
10
+ };
11
+
12
+ const migrateEventNamesToCamelCase = createTransformer(
13
+ ({ j, root, markAsChanged }) => {
14
+ root.find(j.Literal).forEach((path: any) => {
15
+ const node = path.value;
16
+
17
+ if (typeof node.value === "string") {
18
+ const oldEventName = node.value;
19
+
20
+ if (Object.hasOwn(eventNameMap, oldEventName)) {
21
+ const newEventName = eventNameMap[oldEventName];
22
+ node.value = newEventName;
23
+ markAsChanged();
24
+ }
25
+ }
26
+ });
27
+
28
+ root.find(j.TemplateLiteral).forEach((path: any) => {
29
+ const node = path.value;
30
+
31
+ node.quasis.forEach((quasi: any) => {
32
+ if (quasi.value && typeof quasi.value.raw === "string") {
33
+ const oldEventName = quasi.value.raw;
34
+
35
+ if (Object.hasOwn(eventNameMap, oldEventName)) {
36
+ const newEventName = eventNameMap[oldEventName];
37
+ quasi.value.raw = newEventName;
38
+ quasi.value.cooked = newEventName;
39
+ markAsChanged();
40
+ }
41
+ }
42
+ });
43
+ });
44
+ },
45
+ );
46
+
47
+ export default migrateEventNamesToCamelCase;
@@ -0,0 +1,372 @@
1
+ import { createTransformer } from "../utils/createTransformer";
2
+ import { resolveBinding } from "../utils/resolveBinding";
3
+
4
+ type ConditionFragment = {
5
+ expression: string;
6
+ negated: boolean;
7
+ };
8
+
9
+ // Map ThreadPrimitive.If props to condition expressions
10
+ const threadPropMap: Record<
11
+ string,
12
+ (value: unknown) => ConditionFragment | null
13
+ > = {
14
+ empty: (v) => ({
15
+ expression: "s.thread.isEmpty",
16
+ negated: v === false,
17
+ }),
18
+ running: (v) => ({
19
+ expression: "s.thread.isRunning",
20
+ negated: v === false,
21
+ }),
22
+ disabled: (v) => ({
23
+ expression: "s.thread.isDisabled",
24
+ negated: v === false,
25
+ }),
26
+ };
27
+
28
+ // Map MessagePrimitive.If props to condition expressions
29
+ const messagePropMap: Record<
30
+ string,
31
+ (value: unknown) => ConditionFragment | null
32
+ > = {
33
+ user: (v) => ({
34
+ expression: `s.message.role ${v === false ? "!==" : "==="} "user"`,
35
+ negated: false,
36
+ }),
37
+ assistant: (v) => ({
38
+ expression: `s.message.role ${v === false ? "!==" : "==="} "assistant"`,
39
+ negated: false,
40
+ }),
41
+ system: (v) => ({
42
+ expression: `s.message.role ${v === false ? "!==" : "==="} "system"`,
43
+ negated: false,
44
+ }),
45
+ hasBranches: (v) => ({
46
+ expression: v === false ? "true" : "s.message.branchCount >= 2",
47
+ negated: false,
48
+ }),
49
+ copied: (v) => ({
50
+ expression: "s.message.isCopied",
51
+ negated: v === false,
52
+ }),
53
+ last: (v) => ({
54
+ expression: "s.message.isLast",
55
+ negated: v === false,
56
+ }),
57
+ lastOrHover: (v) => ({
58
+ expression:
59
+ v === false ? "true" : "s.message.isHovering || s.message.isLast",
60
+ negated: false,
61
+ }),
62
+ speaking: (v) => ({
63
+ expression: "s.message.speech != null",
64
+ negated: v === false,
65
+ }),
66
+ hasAttachments: (v) =>
67
+ v === true
68
+ ? {
69
+ expression:
70
+ 's.message.role === "user" && !!s.message.attachments?.length',
71
+ negated: false,
72
+ }
73
+ : {
74
+ expression:
75
+ 's.message.role !== "user" || !s.message.attachments?.length',
76
+ negated: false,
77
+ },
78
+ hasContent: (v) => ({
79
+ expression: "s.message.parts.length > 0",
80
+ negated: v === false,
81
+ }),
82
+ submittedFeedback: (v) => {
83
+ if (v === null) {
84
+ return {
85
+ expression:
86
+ "(s.message.metadata.submittedFeedback?.type ?? null) === null",
87
+ negated: false,
88
+ };
89
+ }
90
+ return {
91
+ expression: `s.message.metadata.submittedFeedback?.type === "${v}"`,
92
+ negated: false,
93
+ };
94
+ },
95
+ };
96
+
97
+ // Map ComposerPrimitive.If props to condition expressions
98
+ const composerPropMap: Record<
99
+ string,
100
+ (value: unknown) => ConditionFragment | null
101
+ > = {
102
+ editing: (v) => ({
103
+ expression: "s.composer.isEditing",
104
+ negated: v === false,
105
+ }),
106
+ dictation: (v) => ({
107
+ expression: "s.composer.dictation != null",
108
+ negated: v === false,
109
+ }),
110
+ };
111
+
112
+ const primitiveMap: Record<
113
+ string,
114
+ Record<string, (value: unknown) => ConditionFragment | null>
115
+ > = {
116
+ ThreadPrimitive: threadPropMap,
117
+ MessagePrimitive: messagePropMap,
118
+ ComposerPrimitive: composerPropMap,
119
+ };
120
+
121
+ // Map of XPrimitive.Component → fixed condition (no props needed)
122
+ const fixedConditionMap: Record<string, Record<string, string>> = {
123
+ ThreadPrimitive: {
124
+ Empty: "s.thread.isEmpty",
125
+ },
126
+ };
127
+
128
+ // A prop value the maps cannot faithfully express as a static condition
129
+ // (dynamic expressions, `{undefined}`); elements carrying one are skipped
130
+ // so runtime behavior is never silently changed.
131
+ const UNSUPPORTED_VALUE: unique symbol = Symbol("unsupported");
132
+
133
+ /**
134
+ * Extract the value of a JSX attribute.
135
+ * - Boolean prop (no value): `<X.If user>` → `true`
136
+ * - `{true}` / `{false}`: → `true` / `false`
137
+ * - `{"positive"}`: → `"positive"`
138
+ * - `{null}`: → `null`
139
+ * - anything else (dynamic expressions): → UNSUPPORTED_VALUE
140
+ */
141
+ const getAttrValue = (j: any, attr: any): unknown => {
142
+ // Boolean attribute (no value), e.g. `<X.If user>`
143
+ if (attr.value === null || attr.value === undefined) {
144
+ return true;
145
+ }
146
+
147
+ // JSX expression container: `{true}`, `{false}`, `{"positive"}`, `{null}`
148
+ if (j.JSXExpressionContainer.check(attr.value)) {
149
+ const expr = attr.value.expression;
150
+ if (j.BooleanLiteral.check(expr)) return expr.value;
151
+ // NullLiteral bases Literal in ast-types but carries no `value` field,
152
+ // so it must be recognized before the generic Literal branch.
153
+ if (j.NullLiteral.check(expr)) return null;
154
+ if (j.Literal.check(expr)) {
155
+ if (expr.value === null) return null;
156
+ return expr.value;
157
+ }
158
+ return UNSUPPORTED_VALUE;
159
+ }
160
+
161
+ // String literal
162
+ if (j.StringLiteral.check(attr.value) || j.Literal.check(attr.value)) {
163
+ return attr.value.value;
164
+ }
165
+
166
+ return UNSUPPORTED_VALUE;
167
+ };
168
+
169
+ // Composed as a syntax tree so the printer parenthesizes by precedence;
170
+ // concatenated text lets `!` and `&&` reassociate a fragment's own operators.
171
+ const buildConditionString = (
172
+ j: any,
173
+ fragments: ConditionFragment[],
174
+ ): string => {
175
+ const parseExpression = (source: string) =>
176
+ j(`${source};`).find(j.ExpressionStatement).nodes()[0]!.expression;
177
+
178
+ const condition = fragments
179
+ .map((f) => {
180
+ const expression = parseExpression(f.expression);
181
+ return f.negated ? j.unaryExpression("!", expression) : expression;
182
+ })
183
+ .reduce((left: any, right: any) => j.logicalExpression("&&", left, right));
184
+
185
+ return j(condition).toSource();
186
+ };
187
+
188
+ const migratePrimitiveIfToAuiIf = createTransformer(
189
+ ({ j, root, markAsChanged }) => {
190
+ const importedPrimitives = new Map<
191
+ string,
192
+ { name: string; declaration: any; binding: any }
193
+ >();
194
+ const auiIfImports: { source: string; binding: any }[] = [];
195
+ const usedNames = new Set<string>();
196
+ root
197
+ .find(j.Identifier)
198
+ .forEach((path: any) => usedNames.add(path.value.name));
199
+ root
200
+ .find(j.JSXIdentifier)
201
+ .forEach((path: any) => usedNames.add(path.value.name));
202
+
203
+ root.find(j.ImportDeclaration).forEach((path: any) => {
204
+ const declaration = path.value;
205
+ const source = declaration.source.value;
206
+ if (
207
+ typeof source !== "string" ||
208
+ !source.startsWith("@assistant-ui/") ||
209
+ declaration.importKind === "type"
210
+ )
211
+ return;
212
+
213
+ declaration.specifiers?.forEach((specifier: any) => {
214
+ if (
215
+ !j.ImportSpecifier.check(specifier) ||
216
+ !j.Identifier.check(specifier.imported) ||
217
+ !j.Identifier.check(specifier.local) ||
218
+ (specifier as { importKind?: string }).importKind === "type"
219
+ )
220
+ return;
221
+ const name = specifier.imported.name;
222
+ const binding = specifier.local;
223
+ if (primitiveMap[name] || fixedConditionMap[name]) {
224
+ importedPrimitives.set(binding.name, { name, declaration, binding });
225
+ }
226
+ if (name === "AuiIf") auiIfImports.push({ source, binding });
227
+ });
228
+ });
229
+
230
+ if (importedPrimitives.size === 0) return;
231
+
232
+ const getPrimitive = (path: any, localName: string) => {
233
+ const primitive = importedPrimitives.get(localName);
234
+ return primitive &&
235
+ resolveBinding(j, path, localName) === primitive.binding
236
+ ? primitive
237
+ : undefined;
238
+ };
239
+
240
+ const getAuiIfName = (path: any, declaration: any) => {
241
+ const source = declaration.source.value;
242
+ const existing = auiIfImports.find(
243
+ (entry) =>
244
+ entry.source === source &&
245
+ !/^[a-z]/.test(entry.binding.name) &&
246
+ resolveBinding(j, path, entry.binding.name) === entry.binding,
247
+ );
248
+ if (existing) return existing.binding.name;
249
+
250
+ let name = "AuiIf";
251
+ for (let suffix = 1; usedNames.has(name); suffix++)
252
+ name = `AuiIf${suffix}`;
253
+ usedNames.add(name);
254
+ const binding = j.identifier(name);
255
+ declaration.specifiers.push(
256
+ j.importSpecifier(j.identifier("AuiIf"), binding),
257
+ );
258
+ auiIfImports.push({ source, binding });
259
+ return name;
260
+ };
261
+
262
+ // Opening and closing tags are rewritten together per element, so a
263
+ // skipped element can never be left with a mismatched closing tag.
264
+ const convertElementToAuiIf = (
265
+ elementPath: any,
266
+ conditionBody: string,
267
+ declaration: any,
268
+ ) => {
269
+ const localName = getAuiIfName(elementPath, declaration);
270
+ const arrowFnAst = j(`(s) => ${conditionBody}`)
271
+ .find(j.ArrowFunctionExpression)
272
+ .paths()[0]!.value;
273
+
274
+ const opening = elementPath.value.openingElement;
275
+ opening.name = j.jsxIdentifier(localName);
276
+ opening.attributes = [
277
+ j.jsxAttribute(
278
+ j.jsxIdentifier("condition"),
279
+ j.jsxExpressionContainer(arrowFnAst),
280
+ ),
281
+ ];
282
+ if (elementPath.value.closingElement) {
283
+ elementPath.value.closingElement.name = j.jsxIdentifier(localName);
284
+ }
285
+
286
+ markAsChanged();
287
+ };
288
+
289
+ // Process fixed-condition components: <ThreadPrimitive.Empty> → <AuiIf condition={...}>
290
+ root.find(j.JSXElement).forEach((path: any) => {
291
+ const name = path.value.openingElement.name;
292
+ if (!j.JSXMemberExpression.check(name)) return;
293
+ if (!j.JSXIdentifier.check(name.object)) return;
294
+ if (!j.JSXIdentifier.check(name.property)) return;
295
+
296
+ const primitive = getPrimitive(path, name.object.name);
297
+ if (!primitive) return;
298
+ const propertyName = name.property.name as string;
299
+ const conditionBody = fixedConditionMap[primitive.name]?.[propertyName];
300
+ if (!conditionBody) return;
301
+
302
+ // Only transform if there are no props (other than children, which are implicit)
303
+ const attrs: any[] = path.value.openingElement.attributes || [];
304
+ if (attrs.length > 0) return;
305
+
306
+ convertElementToAuiIf(path, conditionBody, primitive.declaration);
307
+ });
308
+
309
+ // Process JSX elements: <ThreadPrimitive.If ...> → <AuiIf condition={...}>
310
+ root.find(j.JSXElement).forEach((path: any) => {
311
+ const name = path.value.openingElement.name;
312
+
313
+ // Check for `<XPrimitive.If ...>`
314
+ if (!j.JSXMemberExpression.check(name)) return;
315
+ if (!j.JSXIdentifier.check(name.object)) return;
316
+ if (!j.JSXIdentifier.check(name.property)) return;
317
+ if (name.property.name !== "If") return;
318
+
319
+ const primitive = getPrimitive(path, name.object.name);
320
+ if (!primitive) return;
321
+ const propMap = primitiveMap[primitive.name];
322
+ if (!propMap) return;
323
+
324
+ // Extract props
325
+ const attrs: any[] = path.value.openingElement.attributes || [];
326
+ const fragments: ConditionFragment[] = [];
327
+ let hasUnknownProp = false;
328
+
329
+ for (const attr of attrs) {
330
+ if (!j.JSXAttribute.check(attr)) {
331
+ // JSX spread attributes — can't migrate
332
+ hasUnknownProp = true;
333
+ continue;
334
+ }
335
+ const propName =
336
+ typeof attr.name.name === "string" ? attr.name.name : null;
337
+ if (!propName) {
338
+ // e.g. JSXNamespacedName — not expressible as a condition
339
+ hasUnknownProp = true;
340
+ continue;
341
+ }
342
+
343
+ const mapper = propMap[propName];
344
+ if (!mapper) {
345
+ hasUnknownProp = true;
346
+ continue;
347
+ }
348
+
349
+ const value = getAttrValue(j, attr);
350
+ if (value === UNSUPPORTED_VALUE) {
351
+ hasUnknownProp = true;
352
+ continue;
353
+ }
354
+ const fragment = mapper(value);
355
+ if (fragment) {
356
+ fragments.push(fragment);
357
+ }
358
+ }
359
+
360
+ // If we couldn't map all props, skip this element
361
+ if (hasUnknownProp || fragments.length === 0) return;
362
+
363
+ convertElementToAuiIf(
364
+ path,
365
+ buildConditionString(j, fragments),
366
+ primitive.declaration,
367
+ );
368
+ });
369
+ },
370
+ );
371
+
372
+ export default migratePrimitiveIfToAuiIf;