@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,83 @@
1
+ "use client";
2
+
3
+ import { AuiConfig, AuiProvider } from "@assistant-ui/react";
4
+ import { HarnessCloudThreadList } from "@assistant-ui/react-harness-sdk";
5
+ import { useSyncExternalStore } from "react";
6
+ import { Thread } from "@/components/assistant-ui/elements/thread.aui";
7
+ import { Button } from "@/components/ui/button";
8
+ import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard";
9
+
10
+ const credential = async () => {
11
+ const response = await fetch("/api/credential", { cache: "no-store" });
12
+ if (!response.ok) throw new Error(await response.text());
13
+ const { token } = (await response.json()) as { token: string };
14
+ return token;
15
+ };
16
+
17
+ const ShareThread = () => {
18
+ const { isCopied, copyToClipboard } = useCopyToClipboard();
19
+ return (
20
+ <Button
21
+ variant="outline"
22
+ size="sm"
23
+ onClick={() => copyToClipboard(window.location.href)}
24
+ >
25
+ {isCopied ? "Link copied" : "Share this chat"}
26
+ </Button>
27
+ );
28
+ };
29
+
30
+ const ConnectedAssistant = ({ threadId }: { threadId: string }) => {
31
+ const config = AuiConfig({
32
+ threads: HarnessCloudThreadList({
33
+ url: "/api/chat",
34
+ origin: process.env.NEXT_PUBLIC_ASSISTANT_HARNESS_URL!,
35
+ workspaceId: process.env.NEXT_PUBLIC_ASSISTANT_WORKSPACE_ID!,
36
+ credential,
37
+ threadId,
38
+ onThreadIdChange: (threadId) => {
39
+ window.location.hash = threadId ?? crypto.randomUUID();
40
+ },
41
+ }),
42
+ });
43
+ return (
44
+ <AuiProvider config={config}>
45
+ <div className="flex h-dvh flex-col">
46
+ <header className="flex items-center justify-between border-b px-6 py-3">
47
+ <div>
48
+ <h1 className="font-semibold">Shared chat</h1>
49
+ <p className="text-muted-foreground text-sm">
50
+ Open the same link in another browser to chat together.
51
+ </p>
52
+ </div>
53
+ <ShareThread />
54
+ </header>
55
+ <div className="min-h-0 flex-1">
56
+ <Thread />
57
+ </div>
58
+ </div>
59
+ </AuiProvider>
60
+ );
61
+ };
62
+
63
+ export const Assistant = () => {
64
+ const threadId = useSyncExternalStore(
65
+ subscribeToHash,
66
+ currentThreadId,
67
+ () => null,
68
+ );
69
+ if (threadId === null)
70
+ return (
71
+ <p className="p-6" role="status">
72
+ Connecting to your chat…
73
+ </p>
74
+ );
75
+ return <ConnectedAssistant threadId={threadId} />;
76
+ };
77
+
78
+ const currentThreadId = () => window.location.hash.slice(1) || "main";
79
+
80
+ const subscribeToHash = (onChange: () => void) => {
81
+ window.addEventListener("hashchange", onChange);
82
+ return () => window.removeEventListener("hashchange", onChange);
83
+ };
@@ -0,0 +1,139 @@
1
+ @import "tailwindcss";
2
+ @import "tw-animate-css";
3
+ @import "tw-shimmer";
4
+
5
+ @custom-variant data-open (&:where([data-state="open"], [data-open]:not([data-open="false"])));
6
+ @custom-variant data-closed (&:where([data-state="closed"], [data-closed]:not([data-closed="false"])));
7
+
8
+ @theme inline {
9
+ @keyframes collapsible-down {
10
+ from {
11
+ height: 0;
12
+ }
13
+ to {
14
+ height: var(
15
+ --radix-collapsible-content-height,
16
+ var(--collapsible-panel-height, auto)
17
+ );
18
+ }
19
+ }
20
+ @keyframes collapsible-up {
21
+ from {
22
+ height: var(
23
+ --radix-collapsible-content-height,
24
+ var(--collapsible-panel-height, auto)
25
+ );
26
+ }
27
+ to {
28
+ height: 0;
29
+ }
30
+ }
31
+ }
32
+
33
+ @custom-variant dark (&:is(.dark *));
34
+
35
+ @theme inline {
36
+ --color-background: var(--background);
37
+ --color-foreground: var(--foreground);
38
+ --font-sans: var(--font-inter);
39
+ --font-mono: var(--font-ibm-plex-mono);
40
+ --color-chart-5: var(--chart-5);
41
+ --color-chart-4: var(--chart-4);
42
+ --color-chart-3: var(--chart-3);
43
+ --color-chart-2: var(--chart-2);
44
+ --color-chart-1: var(--chart-1);
45
+ --color-ring: var(--ring);
46
+ --color-input: var(--input);
47
+ --color-border: var(--border);
48
+ --color-destructive: var(--destructive);
49
+ --color-accent-foreground: var(--accent-foreground);
50
+ --color-accent: var(--accent);
51
+ --color-muted-foreground: var(--muted-foreground);
52
+ --color-muted: var(--muted);
53
+ --color-secondary-foreground: var(--secondary-foreground);
54
+ --color-secondary: var(--secondary);
55
+ --color-primary-foreground: var(--primary-foreground);
56
+ --color-primary: var(--primary);
57
+ --color-popover-foreground: var(--popover-foreground);
58
+ --color-popover: var(--popover);
59
+ --color-card-foreground: var(--card-foreground);
60
+ --color-card: var(--card);
61
+ --radius-sm: calc(var(--radius) - 4px);
62
+ --radius-md: calc(var(--radius) - 2px);
63
+ --radius-lg: var(--radius);
64
+ --radius-xl: calc(var(--radius) + 4px);
65
+ --radius-2xl: calc(var(--radius) + 8px);
66
+ --radius-3xl: 1.5rem;
67
+ }
68
+
69
+ :root {
70
+ --radius: 0.625rem;
71
+ --background: oklch(1 0 0);
72
+ --foreground: oklch(0.141 0.005 285.823);
73
+ --card: oklch(1 0 0);
74
+ --card-foreground: oklch(0.141 0.005 285.823);
75
+ --popover: oklch(1 0 0);
76
+ --popover-foreground: oklch(0.141 0.005 285.823);
77
+ --primary: oklch(0.21 0.006 285.885);
78
+ --primary-foreground: oklch(0.985 0 0);
79
+ --secondary: oklch(0.967 0.001 286.375);
80
+ --secondary-foreground: oklch(0.21 0.006 285.885);
81
+ --muted: oklch(0.967 0.001 286.375);
82
+ --muted-foreground: oklch(0.552 0.016 285.938);
83
+ --accent: oklch(0.967 0.001 286.375);
84
+ --accent-foreground: oklch(0.21 0.006 285.885);
85
+ --destructive: oklch(0.577 0.245 27.325);
86
+ --border: oklch(0.92 0.004 286.32);
87
+ --input: oklch(0.92 0.004 286.32);
88
+ --ring: oklch(0.705 0.015 286.067);
89
+ --chart-1: oklch(0.646 0.222 41.116);
90
+ --chart-2: oklch(0.6 0.118 184.704);
91
+ --chart-3: oklch(0.398 0.07 227.392);
92
+ --chart-4: oklch(0.828 0.189 84.429);
93
+ --chart-5: oklch(0.769 0.188 70.08);
94
+ }
95
+
96
+ .dark {
97
+ --background: oklch(0.141 0.005 285.823);
98
+ --foreground: oklch(0.985 0 0);
99
+ --card: oklch(0.21 0.006 285.885);
100
+ --card-foreground: oklch(0.985 0 0);
101
+ --popover: oklch(0.21 0.006 285.885);
102
+ --popover-foreground: oklch(0.985 0 0);
103
+ --primary: oklch(0.92 0.004 286.32);
104
+ --primary-foreground: oklch(0.21 0.006 285.885);
105
+ --secondary: oklch(0.274 0.006 286.033);
106
+ --secondary-foreground: oklch(0.985 0 0);
107
+ --muted: oklch(0.274 0.006 286.033);
108
+ --muted-foreground: oklch(0.705 0.015 286.067);
109
+ --accent: oklch(0.274 0.006 286.033);
110
+ --accent-foreground: oklch(0.985 0 0);
111
+ --destructive: oklch(0.704 0.191 22.216);
112
+ --border: oklch(1 0 0 / 10%);
113
+ --input: oklch(1 0 0 / 15%);
114
+ --ring: oklch(0.552 0.016 285.938);
115
+ --chart-1: oklch(0.488 0.243 264.376);
116
+ --chart-2: oklch(0.696 0.17 162.48);
117
+ --chart-3: oklch(0.769 0.188 70.08);
118
+ --chart-4: oklch(0.627 0.265 303.9);
119
+ --chart-5: oklch(0.645 0.246 16.439);
120
+ }
121
+
122
+ @layer base {
123
+ * {
124
+ @apply border-border;
125
+ }
126
+
127
+ :root {
128
+ color-scheme: light;
129
+ }
130
+
131
+ :root.dark {
132
+ color-scheme: dark;
133
+ }
134
+
135
+ body {
136
+ @apply bg-background text-foreground;
137
+ font-optical-sizing: auto;
138
+ }
139
+ }
@@ -0,0 +1,37 @@
1
+ import type { Metadata } from "next";
2
+ import { IBM_Plex_Mono, Inter } from "next/font/google";
3
+ import { TooltipProvider } from "@/components/ui/tooltip";
4
+ import "./globals.css";
5
+
6
+ const inter = Inter({
7
+ variable: "--font-inter",
8
+ subsets: ["latin"],
9
+ axes: ["opsz"],
10
+ });
11
+
12
+ const ibmPlexMono = IBM_Plex_Mono({
13
+ variable: "--font-ibm-plex-mono",
14
+ subsets: ["latin"],
15
+ weight: ["400", "500", "600"],
16
+ });
17
+
18
+ export const metadata: Metadata = {
19
+ title: "Shared cloud chat",
20
+ description: "Generated by create-assistant-ui",
21
+ };
22
+
23
+ const RootLayout = ({
24
+ children,
25
+ }: Readonly<{
26
+ children: React.ReactNode;
27
+ }>) => {
28
+ return (
29
+ <html lang="en" className="dark">
30
+ <body className={`${inter.variable} ${ibmPlexMono.variable} antialiased`}>
31
+ <TooltipProvider>{children}</TooltipProvider>
32
+ </body>
33
+ </html>
34
+ );
35
+ };
36
+
37
+ export default RootLayout;
@@ -0,0 +1,5 @@
1
+ import { Assistant } from "./assistant";
2
+
3
+ const Home = () => <Assistant />;
4
+
5
+ export default Home;
@@ -0,0 +1,59 @@
1
+ "use client";
2
+
3
+ import { useAui, useAuiState } from "@assistant-ui/react";
4
+ import { useAttachmentSrc } from "@/hooks/use-attachment-src";
5
+
6
+ export function useAttachmentState() {
7
+ const aui = useAui();
8
+ const isComposer = aui.attachment.source !== "message";
9
+ const src = useAttachmentSrc();
10
+
11
+ const isImage = useAuiState((s) => s.attachment.type === "image");
12
+ const name = useAuiState((s) => s.attachment.name);
13
+ const typeLabel = useAuiState((s) => {
14
+ const type = s.attachment.type;
15
+ switch (type) {
16
+ case "image":
17
+ return "Image";
18
+ case "document":
19
+ return "Document";
20
+ case "file":
21
+ return "File";
22
+ default:
23
+ return type;
24
+ }
25
+ });
26
+
27
+ // An attachment on a submission is still being prepared, whether or not the
28
+ // adapter reports progress while it uploads.
29
+ const uploadState = useAuiState((s) =>
30
+ s.attachment.status.type === "incomplete" &&
31
+ s.attachment.status.reason === "error"
32
+ ? "error"
33
+ : s.attachment.status.type === "running" ||
34
+ (s.optional.message?.submission !== undefined &&
35
+ s.attachment.status.type !== "complete")
36
+ ? "uploading"
37
+ : undefined,
38
+ );
39
+ const isUploading = uploadState === "uploading";
40
+ const isError = uploadState === "error";
41
+
42
+ const errorMessage = useAuiState((s) =>
43
+ s.attachment.status.type === "incomplete" &&
44
+ s.attachment.status.reason === "error"
45
+ ? (s.attachment.status.message ?? "Upload failed")
46
+ : undefined,
47
+ );
48
+
49
+ return {
50
+ isComposer,
51
+ src,
52
+ isImage,
53
+ name,
54
+ typeLabel,
55
+ isUploading,
56
+ isError,
57
+ errorMessage,
58
+ };
59
+ }
@@ -0,0 +1,246 @@
1
+ "use client";
2
+
3
+ import {
4
+ type PropsWithChildren,
5
+ useState,
6
+ type FC,
7
+ isValidElement,
8
+ } from "react";
9
+ import {
10
+ XIcon,
11
+ PlusIcon,
12
+ FileText,
13
+ Loader2Icon,
14
+ AlertCircleIcon,
15
+ } from "lucide-react";
16
+ import {
17
+ AttachmentPrimitive,
18
+ ComposerPrimitive,
19
+ MessagePrimitive,
20
+ } from "@assistant-ui/react";
21
+ import {
22
+ Tooltip,
23
+ TooltipContent,
24
+ TooltipProvider,
25
+ TooltipTrigger,
26
+ } from "@/components/ui/tooltip";
27
+ import {
28
+ Dialog,
29
+ DialogTitle,
30
+ DialogContent,
31
+ DialogTrigger,
32
+ } from "@/components/ui/dialog";
33
+ import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
34
+ import { TooltipIconButton } from "@/components/assistant-ui/elements/tooltip-icon-button";
35
+ import { useAttachmentState } from "./attachment-state";
36
+ import { cn } from "@/lib/utils";
37
+
38
+ type AttachmentPreviewProps = {
39
+ src: string;
40
+ name: string;
41
+ };
42
+
43
+ const AttachmentPreview: FC<AttachmentPreviewProps> = ({ src, name }) => {
44
+ const [isLoaded, setIsLoaded] = useState(false);
45
+ return (
46
+ <img
47
+ src={src}
48
+ alt={`Preview of ${name}`}
49
+ className={cn(
50
+ "block h-auto max-h-[80vh] w-auto max-w-full rounded-sm object-contain transition-opacity duration-300 motion-reduce:transition-none",
51
+ isLoaded
52
+ ? "aui-attachment-preview-image-loaded opacity-100"
53
+ : "aui-attachment-preview-image-loading opacity-0",
54
+ )}
55
+ onLoad={() => setIsLoaded(true)}
56
+ />
57
+ );
58
+ };
59
+
60
+ type AttachmentPreviewDialogProps = PropsWithChildren<{
61
+ src: string | undefined;
62
+ name: string;
63
+ }>;
64
+
65
+ const AttachmentPreviewDialog: FC<AttachmentPreviewDialogProps> = ({
66
+ children,
67
+ src,
68
+ name,
69
+ }) => {
70
+ if (!src) return children;
71
+
72
+ return (
73
+ <Dialog>
74
+ <DialogTrigger
75
+ nativeButton={false}
76
+ className="aui-attachment-preview-trigger cursor-zoom-in"
77
+ render={
78
+ isValidElement(children) ? (
79
+ children
80
+ ) : (
81
+ <button type="button">{children}</button>
82
+ )
83
+ }
84
+ />
85
+ <DialogContent className="aui-attachment-preview-dialog-content [&>button]:bg-foreground/60 [&>button]:hover:bg-foreground/80 [&_svg]:text-background p-2 sm:max-w-3xl [&>button]:rounded-full [&>button]:p-1 [&>button]:opacity-100 [&>button]:ring-0!">
86
+ <DialogTitle className="aui-sr-only sr-only">
87
+ Preview {name}
88
+ </DialogTitle>
89
+ <div className="aui-attachment-preview bg-background relative mx-auto flex max-h-[80dvh] w-full items-center justify-center overflow-hidden rounded-sm">
90
+ <AttachmentPreview src={src} name={name} />
91
+ </div>
92
+ </DialogContent>
93
+ </Dialog>
94
+ );
95
+ };
96
+
97
+ const AttachmentThumb: FC<{ src: string | undefined }> = ({ src }) => {
98
+ return (
99
+ <Avatar className="aui-attachment-tile-avatar h-full w-full rounded-none after:hidden">
100
+ <AvatarImage
101
+ src={src}
102
+ alt=""
103
+ className="aui-attachment-tile-image rounded-none object-cover"
104
+ />
105
+ <AvatarFallback>
106
+ <FileText className="aui-attachment-tile-fallback-icon text-muted-foreground/80 size-6 stroke-[1.5]" />
107
+ </AvatarFallback>
108
+ </Avatar>
109
+ );
110
+ };
111
+
112
+ const AttachmentUI: FC = () => {
113
+ const {
114
+ isComposer,
115
+ src,
116
+ isImage,
117
+ name,
118
+ typeLabel,
119
+ isUploading,
120
+ isError,
121
+ errorMessage,
122
+ } = useAttachmentState();
123
+
124
+ return (
125
+ <TooltipProvider>
126
+ <Tooltip>
127
+ <AttachmentPrimitive.Root
128
+ className={cn(
129
+ "aui-attachment-root relative",
130
+ isComposer &&
131
+ "animate-in fade-in-0 zoom-in-95 duration-200 motion-reduce:animate-none",
132
+ isImage &&
133
+ !isComposer &&
134
+ "aui-attachment-root-message only:*:first:size-24",
135
+ )}
136
+ >
137
+ <AttachmentPreviewDialog src={src} name={name}>
138
+ <TooltipTrigger
139
+ render={
140
+ <div
141
+ className={cn(
142
+ "aui-attachment-tile bg-muted hover:after:bg-foreground/10 focus-visible:ring-ring/50 relative size-14 overflow-hidden rounded-[calc(var(--composer-radius,1rem)-var(--composer-padding,8px))] transition-transform outline-none after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:ring-1 after:ring-black/10 after:transition-colors after:ring-inset focus-visible:ring-1 motion-reduce:transition-none dark:after:ring-white/10",
143
+ src
144
+ ? "cursor-zoom-in active:scale-[0.96]"
145
+ : "cursor-default",
146
+ isError &&
147
+ "after:ring-destructive/60 dark:after:ring-destructive/60",
148
+ )}
149
+ role={src ? "button" : "group"}
150
+ tabIndex={0}
151
+ aria-label={`${src ? `Preview ${name}` : `${typeLabel} attachment ${name}`}${
152
+ isError
153
+ ? ", upload failed"
154
+ : isUploading
155
+ ? ", uploading"
156
+ : ""
157
+ }`}
158
+ />
159
+ }
160
+ >
161
+ <AttachmentThumb src={src} />
162
+ {isUploading && (
163
+ <div
164
+ aria-hidden="true"
165
+ className="aui-attachment-tile-uploading bg-background/60 animate-in fade-in-0 absolute inset-0 flex items-center justify-center backdrop-blur-[2px] motion-reduce:animate-none"
166
+ >
167
+ <Loader2Icon className="text-muted-foreground size-4 animate-spin" />
168
+ </div>
169
+ )}
170
+ {isError && (
171
+ <div
172
+ aria-hidden="true"
173
+ className="aui-attachment-tile-error bg-background/70 animate-in fade-in-0 absolute inset-0 flex items-center justify-center backdrop-blur-[2px] motion-reduce:animate-none"
174
+ >
175
+ <AlertCircleIcon className="text-destructive size-4" />
176
+ </div>
177
+ )}
178
+ </TooltipTrigger>
179
+ </AttachmentPreviewDialog>
180
+ {isComposer && <AttachmentRemove name={name} />}
181
+ </AttachmentPrimitive.Root>
182
+ <TooltipContent side="top">
183
+ <AttachmentPrimitive.Name />
184
+ {errorMessage && (
185
+ <p className="aui-attachment-error-message">{errorMessage}</p>
186
+ )}
187
+ </TooltipContent>
188
+ </Tooltip>
189
+ </TooltipProvider>
190
+ );
191
+ };
192
+
193
+ const AttachmentRemove: FC<{ name: string }> = ({ name }) => {
194
+ return (
195
+ <AttachmentPrimitive.Remove
196
+ render={
197
+ <TooltipIconButton
198
+ tooltip={`Remove ${name}`}
199
+ className="aui-attachment-tile-remove absolute end-1 top-1 size-5 rounded-full bg-black/50! text-white after:absolute after:-inset-1.5 hover:bg-black/70! hover:text-white! active:scale-[0.96] motion-reduce:transition-none"
200
+ side="top"
201
+ />
202
+ }
203
+ >
204
+ <XIcon className="aui-attachment-remove-icon size-3 stroke-[2.5]" />
205
+ </AttachmentPrimitive.Remove>
206
+ );
207
+ };
208
+
209
+ export const UserMessageAttachments: FC = () => {
210
+ return (
211
+ <div className="aui-user-message-attachments-end col-span-full col-start-1 row-start-1 flex w-full flex-row justify-end gap-2 empty:hidden">
212
+ <MessagePrimitive.Attachments>
213
+ {() => <AttachmentUI />}
214
+ </MessagePrimitive.Attachments>
215
+ </div>
216
+ );
217
+ };
218
+
219
+ export const ComposerAttachments: FC = () => {
220
+ return (
221
+ <div className="aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden">
222
+ <ComposerPrimitive.Attachments>
223
+ {() => <AttachmentUI />}
224
+ </ComposerPrimitive.Attachments>
225
+ </div>
226
+ );
227
+ };
228
+
229
+ export const ComposerAddAttachment: FC = () => {
230
+ return (
231
+ <ComposerPrimitive.AddAttachment
232
+ render={
233
+ <TooltipIconButton
234
+ tooltip="Add Attachment"
235
+ side="bottom"
236
+ variant="ghost"
237
+ size="icon"
238
+ className="aui-composer-add-attachment text-muted-foreground hover:text-foreground hover:bg-muted-foreground/15 dark:border-muted-foreground/15 dark:hover:bg-muted-foreground/30 size-7 rounded-full active:scale-[0.96] motion-reduce:transition-none"
239
+ aria-label="Add Attachment"
240
+ />
241
+ }
242
+ >
243
+ <PlusIcon className="aui-attachment-add-icon size-4" />
244
+ </ComposerPrimitive.AddAttachment>
245
+ );
246
+ };
@@ -0,0 +1,19 @@
1
+ "use client";
2
+
3
+ import { Collapsible } from "@base-ui/react/collapsible";
4
+ import { forwardRef } from "react";
5
+
6
+ export const CollapsibleRoot = forwardRef<
7
+ React.ComponentRef<typeof Collapsible.Root>,
8
+ React.ComponentPropsWithoutRef<typeof Collapsible.Root>
9
+ >(function CollapsibleRoot(props, ref) {
10
+ return <Collapsible.Root ref={ref} data-slot="collapsible" {...props} />;
11
+ });
12
+
13
+ export function CollapsibleTrigger({ ...props }: Collapsible.Trigger.Props) {
14
+ return <Collapsible.Trigger data-slot="collapsible-trigger" {...props} />;
15
+ }
16
+
17
+ export function CollapsibleContent({ ...props }: Collapsible.Panel.Props) {
18
+ return <Collapsible.Panel data-slot="collapsible-content" {...props} />;
19
+ }