create-sidekick-app 0.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/LICENSE.md +202 -0
  2. package/NOTICE +27 -0
  3. package/README.md +29 -2
  4. package/dist/index.js +59 -0
  5. package/package.json +65 -4
  6. package/template/base/ai-chat/.env.example +6 -0
  7. package/template/base/ai-chat/.prettierignore +2 -0
  8. package/template/base/ai-chat/.prettierrc.json +5 -0
  9. package/template/base/ai-chat/README.md +38 -0
  10. package/template/base/ai-chat/_gitignore +41 -0
  11. package/template/base/ai-chat/components.json +23 -0
  12. package/template/base/ai-chat/next.config.ts +5 -0
  13. package/template/base/ai-chat/package.json +61 -0
  14. package/template/base/ai-chat/postcss.config.mjs +5 -0
  15. package/template/base/ai-chat/src/app/api/chat/route.ts +141 -0
  16. package/template/base/ai-chat/src/app/api/instant/route.ts +5 -0
  17. package/template/base/ai-chat/src/app/chat/[id]/page.tsx +20 -0
  18. package/template/base/ai-chat/src/app/globals.css +124 -0
  19. package/template/base/ai-chat/src/app/layout.tsx +34 -0
  20. package/template/base/ai-chat/src/app/page.tsx +6 -0
  21. package/template/base/ai-chat/src/components/AuthGate.tsx +15 -0
  22. package/template/base/ai-chat/src/components/Chat.tsx +228 -0
  23. package/template/base/ai-chat/src/components/InstantProvider.tsx +18 -0
  24. package/template/base/ai-chat/src/components/Login.tsx +163 -0
  25. package/template/base/ai-chat/src/components/Sidebar.tsx +100 -0
  26. package/template/base/ai-chat/src/components/ai-elements/agent.tsx +142 -0
  27. package/template/base/ai-chat/src/components/ai-elements/artifact.tsx +149 -0
  28. package/template/base/ai-chat/src/components/ai-elements/attachments.tsx +427 -0
  29. package/template/base/ai-chat/src/components/ai-elements/audio-player.tsx +229 -0
  30. package/template/base/ai-chat/src/components/ai-elements/canvas.tsx +26 -0
  31. package/template/base/ai-chat/src/components/ai-elements/chain-of-thought.tsx +223 -0
  32. package/template/base/ai-chat/src/components/ai-elements/checkpoint.tsx +72 -0
  33. package/template/base/ai-chat/src/components/ai-elements/code-block.tsx +556 -0
  34. package/template/base/ai-chat/src/components/ai-elements/commit.tsx +449 -0
  35. package/template/base/ai-chat/src/components/ai-elements/confirmation.tsx +173 -0
  36. package/template/base/ai-chat/src/components/ai-elements/connection.tsx +28 -0
  37. package/template/base/ai-chat/src/components/ai-elements/context.tsx +410 -0
  38. package/template/base/ai-chat/src/components/ai-elements/controls.tsx +19 -0
  39. package/template/base/ai-chat/src/components/ai-elements/conversation.tsx +167 -0
  40. package/template/base/ai-chat/src/components/ai-elements/edge.tsx +144 -0
  41. package/template/base/ai-chat/src/components/ai-elements/environment-variables.tsx +325 -0
  42. package/template/base/ai-chat/src/components/ai-elements/file-tree.tsx +298 -0
  43. package/template/base/ai-chat/src/components/ai-elements/image.tsx +25 -0
  44. package/template/base/ai-chat/src/components/ai-elements/inline-citation.tsx +294 -0
  45. package/template/base/ai-chat/src/components/ai-elements/jsx-preview.tsx +250 -0
  46. package/template/base/ai-chat/src/components/ai-elements/message.tsx +356 -0
  47. package/template/base/ai-chat/src/components/ai-elements/mic-selector.tsx +372 -0
  48. package/template/base/ai-chat/src/components/ai-elements/model-selector.tsx +214 -0
  49. package/template/base/ai-chat/src/components/ai-elements/node.tsx +72 -0
  50. package/template/base/ai-chat/src/components/ai-elements/open-in-chat.tsx +367 -0
  51. package/template/base/ai-chat/src/components/ai-elements/package-info.tsx +235 -0
  52. package/template/base/ai-chat/src/components/ai-elements/panel.tsx +16 -0
  53. package/template/base/ai-chat/src/components/ai-elements/persona.tsx +280 -0
  54. package/template/base/ai-chat/src/components/ai-elements/plan.tsx +144 -0
  55. package/template/base/ai-chat/src/components/ai-elements/prompt-input.tsx +1341 -0
  56. package/template/base/ai-chat/src/components/ai-elements/queue.tsx +275 -0
  57. package/template/base/ai-chat/src/components/ai-elements/reasoning.tsx +229 -0
  58. package/template/base/ai-chat/src/components/ai-elements/sandbox.tsx +128 -0
  59. package/template/base/ai-chat/src/components/ai-elements/schema-display.tsx +473 -0
  60. package/template/base/ai-chat/src/components/ai-elements/shimmer.tsx +78 -0
  61. package/template/base/ai-chat/src/components/ai-elements/snippet.tsx +141 -0
  62. package/template/base/ai-chat/src/components/ai-elements/sources.tsx +78 -0
  63. package/template/base/ai-chat/src/components/ai-elements/speech-input.tsx +324 -0
  64. package/template/base/ai-chat/src/components/ai-elements/stack-trace.tsx +531 -0
  65. package/template/base/ai-chat/src/components/ai-elements/suggestion.tsx +55 -0
  66. package/template/base/ai-chat/src/components/ai-elements/task.tsx +88 -0
  67. package/template/base/ai-chat/src/components/ai-elements/terminal.tsx +277 -0
  68. package/template/base/ai-chat/src/components/ai-elements/test-results.tsx +497 -0
  69. package/template/base/ai-chat/src/components/ai-elements/tool.tsx +174 -0
  70. package/template/base/ai-chat/src/components/ai-elements/toolbar.tsx +17 -0
  71. package/template/base/ai-chat/src/components/ai-elements/transcription.tsx +126 -0
  72. package/template/base/ai-chat/src/components/ai-elements/voice-selector.tsx +525 -0
  73. package/template/base/ai-chat/src/components/ai-elements/web-preview.tsx +282 -0
  74. package/template/base/ai-chat/src/components/ui/accordion.tsx +66 -0
  75. package/template/base/ai-chat/src/components/ui/alert.tsx +66 -0
  76. package/template/base/ai-chat/src/components/ui/avatar.tsx +109 -0
  77. package/template/base/ai-chat/src/components/ui/badge.tsx +48 -0
  78. package/template/base/ai-chat/src/components/ui/button-group.tsx +83 -0
  79. package/template/base/ai-chat/src/components/ui/button.tsx +64 -0
  80. package/template/base/ai-chat/src/components/ui/card.tsx +92 -0
  81. package/template/base/ai-chat/src/components/ui/carousel.tsx +241 -0
  82. package/template/base/ai-chat/src/components/ui/collapsible.tsx +33 -0
  83. package/template/base/ai-chat/src/components/ui/command.tsx +184 -0
  84. package/template/base/ai-chat/src/components/ui/dialog.tsx +158 -0
  85. package/template/base/ai-chat/src/components/ui/dropdown-menu.tsx +257 -0
  86. package/template/base/ai-chat/src/components/ui/hover-card.tsx +44 -0
  87. package/template/base/ai-chat/src/components/ui/input-group.tsx +170 -0
  88. package/template/base/ai-chat/src/components/ui/input.tsx +21 -0
  89. package/template/base/ai-chat/src/components/ui/popover.tsx +89 -0
  90. package/template/base/ai-chat/src/components/ui/progress.tsx +31 -0
  91. package/template/base/ai-chat/src/components/ui/scroll-area.tsx +58 -0
  92. package/template/base/ai-chat/src/components/ui/select.tsx +190 -0
  93. package/template/base/ai-chat/src/components/ui/separator.tsx +28 -0
  94. package/template/base/ai-chat/src/components/ui/spinner.tsx +16 -0
  95. package/template/base/ai-chat/src/components/ui/switch.tsx +35 -0
  96. package/template/base/ai-chat/src/components/ui/tabs.tsx +91 -0
  97. package/template/base/ai-chat/src/components/ui/textarea.tsx +18 -0
  98. package/template/base/ai-chat/src/components/ui/tooltip.tsx +57 -0
  99. package/template/base/ai-chat/src/instant.perms.ts +34 -0
  100. package/template/base/ai-chat/src/instant.schema.ts +107 -0
  101. package/template/base/ai-chat/src/lib/adminDb.ts +8 -0
  102. package/template/base/ai-chat/src/lib/db.ts +8 -0
  103. package/template/base/ai-chat/src/lib/mockModel.ts +119 -0
  104. package/template/base/ai-chat/src/lib/utils.ts +6 -0
  105. package/template/base/ai-chat/tsconfig.json +33 -0
  106. package/template/base/bun-react/.env.example +2 -0
  107. package/template/base/bun-react/README.md +12 -0
  108. package/template/base/bun-react/_gitignore +34 -0
  109. package/template/base/bun-react/bun-env.d.ts +17 -0
  110. package/template/base/bun-react/bunfig.toml +4 -0
  111. package/template/base/bun-react/package.json +22 -0
  112. package/template/base/bun-react/src/App.tsx +168 -0
  113. package/template/base/bun-react/src/frontend.tsx +20 -0
  114. package/template/base/bun-react/src/getUnusedPort.ts +32 -0
  115. package/template/base/bun-react/src/index.css +25 -0
  116. package/template/base/bun-react/src/index.html +13 -0
  117. package/template/base/bun-react/src/index.ts +21 -0
  118. package/template/base/bun-react/src/instant.perms.ts +24 -0
  119. package/template/base/bun-react/src/instant.schema.ts +46 -0
  120. package/template/base/bun-react/src/lib/db.ts +8 -0
  121. package/template/base/bun-react/src/logo.svg +1 -0
  122. package/template/base/bun-react/tsconfig.json +36 -0
  123. package/template/base/expo/.env.example +2 -0
  124. package/template/base/expo/README.md +18 -0
  125. package/template/base/expo/_gitignore +41 -0
  126. package/template/base/expo/app/+not-found.tsx +16 -0
  127. package/template/base/expo/app/_layout.tsx +37 -0
  128. package/template/base/expo/app/index.tsx +64 -0
  129. package/template/base/expo/app.json +42 -0
  130. package/template/base/expo/assets/fonts/SpaceMono-Regular.ttf +0 -0
  131. package/template/base/expo/assets/images/adaptive-icon.png +0 -0
  132. package/template/base/expo/assets/images/favicon.png +0 -0
  133. package/template/base/expo/assets/images/icon.png +0 -0
  134. package/template/base/expo/assets/images/partial-react-logo.png +0 -0
  135. package/template/base/expo/assets/images/react-logo.png +0 -0
  136. package/template/base/expo/assets/images/react-logo@2x.png +0 -0
  137. package/template/base/expo/assets/images/react-logo@3x.png +0 -0
  138. package/template/base/expo/assets/images/splash-icon.png +0 -0
  139. package/template/base/expo/babel.config.js +12 -0
  140. package/template/base/expo/constants/Colors.ts +26 -0
  141. package/template/base/expo/eslint.config.js +10 -0
  142. package/template/base/expo/global.css +3 -0
  143. package/template/base/expo/hooks/useColorScheme.ts +1 -0
  144. package/template/base/expo/hooks/useColorScheme.web.ts +21 -0
  145. package/template/base/expo/hooks/useThemeColor.ts +21 -0
  146. package/template/base/expo/instant.perms.ts +24 -0
  147. package/template/base/expo/instant.schema.ts +44 -0
  148. package/template/base/expo/lib/db.ts +7 -0
  149. package/template/base/expo/metro.config.js +6 -0
  150. package/template/base/expo/nativewind-env.d.ts +1 -0
  151. package/template/base/expo/package.json +57 -0
  152. package/template/base/expo/scripts/reset-project.js +112 -0
  153. package/template/base/expo/tailwind.config.js +9 -0
  154. package/template/base/expo/tsconfig.json +18 -0
  155. package/template/base/next-js-app-dir/.env.example +2 -0
  156. package/template/base/next-js-app-dir/README.md +18 -0
  157. package/template/base/next-js-app-dir/_gitignore +41 -0
  158. package/template/base/next-js-app-dir/next.config.ts +7 -0
  159. package/template/base/next-js-app-dir/package.json +27 -0
  160. package/template/base/next-js-app-dir/postcss.config.mjs +5 -0
  161. package/template/base/next-js-app-dir/public/file.svg +1 -0
  162. package/template/base/next-js-app-dir/public/globe.svg +1 -0
  163. package/template/base/next-js-app-dir/public/next.svg +1 -0
  164. package/template/base/next-js-app-dir/public/vercel.svg +1 -0
  165. package/template/base/next-js-app-dir/public/window.svg +1 -0
  166. package/template/base/next-js-app-dir/src/app/favicon.ico +0 -0
  167. package/template/base/next-js-app-dir/src/app/globals.css +26 -0
  168. package/template/base/next-js-app-dir/src/app/layout.tsx +34 -0
  169. package/template/base/next-js-app-dir/src/app/page.tsx +169 -0
  170. package/template/base/next-js-app-dir/src/instant.perms.ts +24 -0
  171. package/template/base/next-js-app-dir/src/instant.schema.ts +50 -0
  172. package/template/base/next-js-app-dir/src/lib/db.ts +8 -0
  173. package/template/base/next-js-app-dir/tsconfig.json +41 -0
  174. package/template/base/solidjs-vite/README.md +15 -0
  175. package/template/base/solidjs-vite/_gitignore +25 -0
  176. package/template/base/solidjs-vite/index.html +15 -0
  177. package/template/base/solidjs-vite/package.json +25 -0
  178. package/template/base/solidjs-vite/src/App.tsx +171 -0
  179. package/template/base/solidjs-vite/src/index.css +25 -0
  180. package/template/base/solidjs-vite/src/index.tsx +16 -0
  181. package/template/base/solidjs-vite/src/instant.perms.ts +24 -0
  182. package/template/base/solidjs-vite/src/instant.schema.ts +46 -0
  183. package/template/base/solidjs-vite/src/lib/db.ts +8 -0
  184. package/template/base/solidjs-vite/tsconfig.json +20 -0
  185. package/template/base/solidjs-vite/vite.config.ts +11 -0
  186. package/template/base/sveltekit/README.md +15 -0
  187. package/template/base/sveltekit/_gitignore +26 -0
  188. package/template/base/sveltekit/package.json +25 -0
  189. package/template/base/sveltekit/src/app.css +25 -0
  190. package/template/base/sveltekit/src/app.html +11 -0
  191. package/template/base/sveltekit/src/instant.perms.ts +24 -0
  192. package/template/base/sveltekit/src/instant.schema.ts +46 -0
  193. package/template/base/sveltekit/src/lib/db.ts +8 -0
  194. package/template/base/sveltekit/src/routes/+layout.svelte +6 -0
  195. package/template/base/sveltekit/src/routes/+page.svelte +236 -0
  196. package/template/base/sveltekit/src/routes/+page.ts +1 -0
  197. package/template/base/sveltekit/svelte.config.js +10 -0
  198. package/template/base/sveltekit/tsconfig.json +14 -0
  199. package/template/base/sveltekit/vite.config.ts +7 -0
  200. package/template/base/tanstack-start/.cta.json +12 -0
  201. package/template/base/tanstack-start/README.md +17 -0
  202. package/template/base/tanstack-start/_gitignore +13 -0
  203. package/template/base/tanstack-start/package.json +43 -0
  204. package/template/base/tanstack-start/public/favicon.ico +0 -0
  205. package/template/base/tanstack-start/public/logo192.png +0 -0
  206. package/template/base/tanstack-start/public/logo512.png +0 -0
  207. package/template/base/tanstack-start/public/manifest.json +25 -0
  208. package/template/base/tanstack-start/public/robots.txt +3 -0
  209. package/template/base/tanstack-start/public/tanstack-circle-logo.png +0 -0
  210. package/template/base/tanstack-start/public/tanstack-word-logo-white.svg +1 -0
  211. package/template/base/tanstack-start/src/components/Header.tsx +21 -0
  212. package/template/base/tanstack-start/src/instant.perms.ts +24 -0
  213. package/template/base/tanstack-start/src/instant.schema.ts +50 -0
  214. package/template/base/tanstack-start/src/lib/adminDb.ts +12 -0
  215. package/template/base/tanstack-start/src/lib/db.ts +9 -0
  216. package/template/base/tanstack-start/src/logo.svg +12 -0
  217. package/template/base/tanstack-start/src/routeTree.gen.ts +104 -0
  218. package/template/base/tanstack-start/src/router.tsx +22 -0
  219. package/template/base/tanstack-start/src/routes/__root.tsx +70 -0
  220. package/template/base/tanstack-start/src/routes/api/instant.ts +18 -0
  221. package/template/base/tanstack-start/src/routes/index.tsx +238 -0
  222. package/template/base/tanstack-start/src/routes/login.tsx +140 -0
  223. package/template/base/tanstack-start/src/styles.css +18 -0
  224. package/template/base/tanstack-start/tsconfig.json +28 -0
  225. package/template/base/tanstack-start/vite.config.ts +33 -0
  226. package/template/base/tanstack-start-with-tanstack-query/.cta.json +12 -0
  227. package/template/base/tanstack-start-with-tanstack-query/README.md +18 -0
  228. package/template/base/tanstack-start-with-tanstack-query/_gitignore +13 -0
  229. package/template/base/tanstack-start-with-tanstack-query/package.json +46 -0
  230. package/template/base/tanstack-start-with-tanstack-query/public/favicon.ico +0 -0
  231. package/template/base/tanstack-start-with-tanstack-query/public/logo192.png +0 -0
  232. package/template/base/tanstack-start-with-tanstack-query/public/logo512.png +0 -0
  233. package/template/base/tanstack-start-with-tanstack-query/public/manifest.json +25 -0
  234. package/template/base/tanstack-start-with-tanstack-query/public/robots.txt +3 -0
  235. package/template/base/tanstack-start-with-tanstack-query/public/tanstack-circle-logo.png +0 -0
  236. package/template/base/tanstack-start-with-tanstack-query/public/tanstack-word-logo-white.svg +1 -0
  237. package/template/base/tanstack-start-with-tanstack-query/src/components/Header.tsx +21 -0
  238. package/template/base/tanstack-start-with-tanstack-query/src/instant.perms.ts +24 -0
  239. package/template/base/tanstack-start-with-tanstack-query/src/instant.schema.ts +50 -0
  240. package/template/base/tanstack-start-with-tanstack-query/src/lib/adminDb.ts +9 -0
  241. package/template/base/tanstack-start-with-tanstack-query/src/lib/db.ts +11 -0
  242. package/template/base/tanstack-start-with-tanstack-query/src/lib/instantQuery.ts +93 -0
  243. package/template/base/tanstack-start-with-tanstack-query/src/logo.svg +12 -0
  244. package/template/base/tanstack-start-with-tanstack-query/src/routeTree.gen.ts +104 -0
  245. package/template/base/tanstack-start-with-tanstack-query/src/router.tsx +108 -0
  246. package/template/base/tanstack-start-with-tanstack-query/src/routes/__root.tsx +76 -0
  247. package/template/base/tanstack-start-with-tanstack-query/src/routes/api/instant.ts +16 -0
  248. package/template/base/tanstack-start-with-tanstack-query/src/routes/index.tsx +231 -0
  249. package/template/base/tanstack-start-with-tanstack-query/src/routes/login.tsx +140 -0
  250. package/template/base/tanstack-start-with-tanstack-query/src/styles.css +17 -0
  251. package/template/base/tanstack-start-with-tanstack-query/tsconfig.json +28 -0
  252. package/template/base/tanstack-start-with-tanstack-query/vite.config.ts +33 -0
  253. package/template/base/vite-react/README.md +16 -0
  254. package/template/base/vite-react/_gitignore +26 -0
  255. package/template/base/vite-react/eslint.config.js +23 -0
  256. package/template/base/vite-react/index.html +13 -0
  257. package/template/base/vite-react/package.json +35 -0
  258. package/template/base/vite-react/public/favicon.svg +1 -0
  259. package/template/base/vite-react/src/App.tsx +167 -0
  260. package/template/base/vite-react/src/index.css +1 -0
  261. package/template/base/vite-react/src/instant.perms.ts +24 -0
  262. package/template/base/vite-react/src/instant.schema.ts +51 -0
  263. package/template/base/vite-react/src/lib/db.ts +8 -0
  264. package/template/base/vite-react/src/main.tsx +10 -0
  265. package/template/base/vite-react/tsconfig.app.json +25 -0
  266. package/template/base/vite-react/tsconfig.json +7 -0
  267. package/template/base/vite-react/tsconfig.node.json +24 -0
  268. package/template/base/vite-react/vite.config.ts +8 -0
  269. package/template/base/vite-vanilla/.env.example +2 -0
  270. package/template/base/vite-vanilla/README.md +17 -0
  271. package/template/base/vite-vanilla/_gitignore +25 -0
  272. package/template/base/vite-vanilla/index.html +13 -0
  273. package/template/base/vite-vanilla/package.json +20 -0
  274. package/template/base/vite-vanilla/pnpm-lock.yaml +707 -0
  275. package/template/base/vite-vanilla/public/vite.svg +1 -0
  276. package/template/base/vite-vanilla/src/instant.perms.ts +24 -0
  277. package/template/base/vite-vanilla/src/instant.schema.ts +50 -0
  278. package/template/base/vite-vanilla/src/lib/db.ts +11 -0
  279. package/template/base/vite-vanilla/src/main.ts +242 -0
  280. package/template/base/vite-vanilla/src/style.css +96 -0
  281. package/template/base/vite-vanilla/src/typescript.svg +1 -0
  282. package/template/base/vite-vanilla/src/vite-env.d.ts +1 -0
  283. package/template/base/vite-vanilla/tsconfig.json +24 -0
  284. package/template/base/vue-vite/README.md +15 -0
  285. package/template/base/vue-vite/_gitignore +43 -0
  286. package/template/base/vue-vite/env.d.ts +1 -0
  287. package/template/base/vue-vite/index.html +12 -0
  288. package/template/base/vue-vite/package.json +34 -0
  289. package/template/base/vue-vite/src/App.vue +238 -0
  290. package/template/base/vue-vite/src/assets/main.css +25 -0
  291. package/template/base/vue-vite/src/instant.perms.ts +24 -0
  292. package/template/base/vue-vite/src/instant.schema.ts +46 -0
  293. package/template/base/vue-vite/src/lib/db.ts +8 -0
  294. package/template/base/vue-vite/src/main.ts +6 -0
  295. package/template/base/vue-vite/tsconfig.app.json +15 -0
  296. package/template/base/vue-vite/tsconfig.json +11 -0
  297. package/template/base/vue-vite/tsconfig.node.json +27 -0
  298. package/template/base/vue-vite/vite.config.ts +16 -0
  299. package/template/rules/AGENTS.md +436 -0
@@ -0,0 +1,410 @@
1
+ 'use client';
2
+
3
+ import type { LanguageModelUsage } from 'ai';
4
+ import type { ComponentProps } from 'react';
5
+
6
+ import { Button } from '@/components/ui/button';
7
+ import {
8
+ HoverCard,
9
+ HoverCardContent,
10
+ HoverCardTrigger,
11
+ } from '@/components/ui/hover-card';
12
+ import { Progress } from '@/components/ui/progress';
13
+ import { cn } from '@/lib/utils';
14
+ import { createContext, useContext, useMemo } from 'react';
15
+ import { getUsage } from 'tokenlens';
16
+
17
+ const PERCENT_MAX = 100;
18
+ const ICON_RADIUS = 10;
19
+ const ICON_VIEWBOX = 24;
20
+ const ICON_CENTER = 12;
21
+ const ICON_STROKE_WIDTH = 2;
22
+
23
+ type ModelId = string;
24
+
25
+ interface ContextSchema {
26
+ usedTokens: number;
27
+ maxTokens: number;
28
+ usage?: LanguageModelUsage;
29
+ modelId?: ModelId;
30
+ }
31
+
32
+ const ContextContext = createContext<ContextSchema | null>(null);
33
+
34
+ const useContextValue = () => {
35
+ const context = useContext(ContextContext);
36
+
37
+ if (!context) {
38
+ throw new Error('Context components must be used within Context');
39
+ }
40
+
41
+ return context;
42
+ };
43
+
44
+ export type ContextProps = ComponentProps<typeof HoverCard> & ContextSchema;
45
+
46
+ export const Context = ({
47
+ usedTokens,
48
+ maxTokens,
49
+ usage,
50
+ modelId,
51
+ ...props
52
+ }: ContextProps) => {
53
+ const contextValue = useMemo(
54
+ () => ({ maxTokens, modelId, usage, usedTokens }),
55
+ [maxTokens, modelId, usage, usedTokens],
56
+ );
57
+
58
+ return (
59
+ <ContextContext.Provider value={contextValue}>
60
+ <HoverCard closeDelay={0} openDelay={0} {...props} />
61
+ </ContextContext.Provider>
62
+ );
63
+ };
64
+
65
+ const ContextIcon = () => {
66
+ const { usedTokens, maxTokens } = useContextValue();
67
+ const circumference = 2 * Math.PI * ICON_RADIUS;
68
+ const usedPercent = usedTokens / maxTokens;
69
+ const dashOffset = circumference * (1 - usedPercent);
70
+
71
+ return (
72
+ <svg
73
+ aria-label="Model context usage"
74
+ height="20"
75
+ role="img"
76
+ style={{ color: 'currentcolor' }}
77
+ viewBox={`0 0 ${ICON_VIEWBOX} ${ICON_VIEWBOX}`}
78
+ width="20"
79
+ >
80
+ <circle
81
+ cx={ICON_CENTER}
82
+ cy={ICON_CENTER}
83
+ fill="none"
84
+ opacity="0.25"
85
+ r={ICON_RADIUS}
86
+ stroke="currentColor"
87
+ strokeWidth={ICON_STROKE_WIDTH}
88
+ />
89
+ <circle
90
+ cx={ICON_CENTER}
91
+ cy={ICON_CENTER}
92
+ fill="none"
93
+ opacity="0.7"
94
+ r={ICON_RADIUS}
95
+ stroke="currentColor"
96
+ strokeDasharray={`${circumference} ${circumference}`}
97
+ strokeDashoffset={dashOffset}
98
+ strokeLinecap="round"
99
+ strokeWidth={ICON_STROKE_WIDTH}
100
+ style={{ transform: 'rotate(-90deg)', transformOrigin: 'center' }}
101
+ />
102
+ </svg>
103
+ );
104
+ };
105
+
106
+ export type ContextTriggerProps = ComponentProps<typeof Button>;
107
+
108
+ export const ContextTrigger = ({ children, ...props }: ContextTriggerProps) => {
109
+ const { usedTokens, maxTokens } = useContextValue();
110
+ const usedPercent = usedTokens / maxTokens;
111
+ const renderedPercent = new Intl.NumberFormat('en-US', {
112
+ maximumFractionDigits: 1,
113
+ style: 'percent',
114
+ }).format(usedPercent);
115
+
116
+ return (
117
+ <HoverCardTrigger asChild>
118
+ {children ?? (
119
+ <Button type="button" variant="ghost" {...props}>
120
+ <span className="text-muted-foreground font-medium">
121
+ {renderedPercent}
122
+ </span>
123
+ <ContextIcon />
124
+ </Button>
125
+ )}
126
+ </HoverCardTrigger>
127
+ );
128
+ };
129
+
130
+ export type ContextContentProps = ComponentProps<typeof HoverCardContent>;
131
+
132
+ export const ContextContent = ({
133
+ className,
134
+ ...props
135
+ }: ContextContentProps) => (
136
+ <HoverCardContent
137
+ className={cn('min-w-60 divide-y overflow-hidden p-0', className)}
138
+ {...props}
139
+ />
140
+ );
141
+
142
+ export type ContextContentHeaderProps = ComponentProps<'div'>;
143
+
144
+ export const ContextContentHeader = ({
145
+ children,
146
+ className,
147
+ ...props
148
+ }: ContextContentHeaderProps) => {
149
+ const { usedTokens, maxTokens } = useContextValue();
150
+ const usedPercent = usedTokens / maxTokens;
151
+ const displayPct = new Intl.NumberFormat('en-US', {
152
+ maximumFractionDigits: 1,
153
+ style: 'percent',
154
+ }).format(usedPercent);
155
+ const used = new Intl.NumberFormat('en-US', {
156
+ notation: 'compact',
157
+ }).format(usedTokens);
158
+ const total = new Intl.NumberFormat('en-US', {
159
+ notation: 'compact',
160
+ }).format(maxTokens);
161
+
162
+ return (
163
+ <div className={cn('w-full space-y-2 p-3', className)} {...props}>
164
+ {children ?? (
165
+ <>
166
+ <div className="flex items-center justify-between gap-3 text-xs">
167
+ <p>{displayPct}</p>
168
+ <p className="text-muted-foreground font-mono">
169
+ {used} / {total}
170
+ </p>
171
+ </div>
172
+ <div className="space-y-2">
173
+ <Progress className="bg-muted" value={usedPercent * PERCENT_MAX} />
174
+ </div>
175
+ </>
176
+ )}
177
+ </div>
178
+ );
179
+ };
180
+
181
+ export type ContextContentBodyProps = ComponentProps<'div'>;
182
+
183
+ export const ContextContentBody = ({
184
+ children,
185
+ className,
186
+ ...props
187
+ }: ContextContentBodyProps) => (
188
+ <div className={cn('w-full p-3', className)} {...props}>
189
+ {children}
190
+ </div>
191
+ );
192
+
193
+ export type ContextContentFooterProps = ComponentProps<'div'>;
194
+
195
+ export const ContextContentFooter = ({
196
+ children,
197
+ className,
198
+ ...props
199
+ }: ContextContentFooterProps) => {
200
+ const { modelId, usage } = useContextValue();
201
+ const costUSD = modelId
202
+ ? getUsage({
203
+ modelId,
204
+ usage: {
205
+ input: usage?.inputTokens ?? 0,
206
+ output: usage?.outputTokens ?? 0,
207
+ },
208
+ }).costUSD?.totalUSD
209
+ : undefined;
210
+ const totalCost = new Intl.NumberFormat('en-US', {
211
+ currency: 'USD',
212
+ style: 'currency',
213
+ }).format(costUSD ?? 0);
214
+
215
+ return (
216
+ <div
217
+ className={cn(
218
+ 'bg-secondary flex w-full items-center justify-between gap-3 p-3 text-xs',
219
+ className,
220
+ )}
221
+ {...props}
222
+ >
223
+ {children ?? (
224
+ <>
225
+ <span className="text-muted-foreground">Total cost</span>
226
+ <span>{totalCost}</span>
227
+ </>
228
+ )}
229
+ </div>
230
+ );
231
+ };
232
+
233
+ export type ContextInputUsageProps = ComponentProps<'div'>;
234
+
235
+ export const ContextInputUsage = ({
236
+ className,
237
+ children,
238
+ ...props
239
+ }: ContextInputUsageProps) => {
240
+ const { usage, modelId } = useContextValue();
241
+ const inputTokens = usage?.inputTokens ?? 0;
242
+
243
+ if (children) {
244
+ return children;
245
+ }
246
+
247
+ if (!inputTokens) {
248
+ return null;
249
+ }
250
+
251
+ const inputCost = modelId
252
+ ? getUsage({
253
+ modelId,
254
+ usage: { input: inputTokens, output: 0 },
255
+ }).costUSD?.totalUSD
256
+ : undefined;
257
+ const inputCostText = new Intl.NumberFormat('en-US', {
258
+ currency: 'USD',
259
+ style: 'currency',
260
+ }).format(inputCost ?? 0);
261
+
262
+ return (
263
+ <div
264
+ className={cn('flex items-center justify-between text-xs', className)}
265
+ {...props}
266
+ >
267
+ <span className="text-muted-foreground">Input</span>
268
+ <TokensWithCost costText={inputCostText} tokens={inputTokens} />
269
+ </div>
270
+ );
271
+ };
272
+
273
+ export type ContextOutputUsageProps = ComponentProps<'div'>;
274
+
275
+ export const ContextOutputUsage = ({
276
+ className,
277
+ children,
278
+ ...props
279
+ }: ContextOutputUsageProps) => {
280
+ const { usage, modelId } = useContextValue();
281
+ const outputTokens = usage?.outputTokens ?? 0;
282
+
283
+ if (children) {
284
+ return children;
285
+ }
286
+
287
+ if (!outputTokens) {
288
+ return null;
289
+ }
290
+
291
+ const outputCost = modelId
292
+ ? getUsage({
293
+ modelId,
294
+ usage: { input: 0, output: outputTokens },
295
+ }).costUSD?.totalUSD
296
+ : undefined;
297
+ const outputCostText = new Intl.NumberFormat('en-US', {
298
+ currency: 'USD',
299
+ style: 'currency',
300
+ }).format(outputCost ?? 0);
301
+
302
+ return (
303
+ <div
304
+ className={cn('flex items-center justify-between text-xs', className)}
305
+ {...props}
306
+ >
307
+ <span className="text-muted-foreground">Output</span>
308
+ <TokensWithCost costText={outputCostText} tokens={outputTokens} />
309
+ </div>
310
+ );
311
+ };
312
+
313
+ export type ContextReasoningUsageProps = ComponentProps<'div'>;
314
+
315
+ export const ContextReasoningUsage = ({
316
+ className,
317
+ children,
318
+ ...props
319
+ }: ContextReasoningUsageProps) => {
320
+ const { usage, modelId } = useContextValue();
321
+ const reasoningTokens = usage?.reasoningTokens ?? 0;
322
+
323
+ if (children) {
324
+ return children;
325
+ }
326
+
327
+ if (!reasoningTokens) {
328
+ return null;
329
+ }
330
+
331
+ const reasoningCost = modelId
332
+ ? getUsage({
333
+ modelId,
334
+ usage: { reasoningTokens },
335
+ }).costUSD?.totalUSD
336
+ : undefined;
337
+ const reasoningCostText = new Intl.NumberFormat('en-US', {
338
+ currency: 'USD',
339
+ style: 'currency',
340
+ }).format(reasoningCost ?? 0);
341
+
342
+ return (
343
+ <div
344
+ className={cn('flex items-center justify-between text-xs', className)}
345
+ {...props}
346
+ >
347
+ <span className="text-muted-foreground">Reasoning</span>
348
+ <TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />
349
+ </div>
350
+ );
351
+ };
352
+
353
+ export type ContextCacheUsageProps = ComponentProps<'div'>;
354
+
355
+ export const ContextCacheUsage = ({
356
+ className,
357
+ children,
358
+ ...props
359
+ }: ContextCacheUsageProps) => {
360
+ const { usage, modelId } = useContextValue();
361
+ const cacheTokens = usage?.cachedInputTokens ?? 0;
362
+
363
+ if (children) {
364
+ return children;
365
+ }
366
+
367
+ if (!cacheTokens) {
368
+ return null;
369
+ }
370
+
371
+ const cacheCost = modelId
372
+ ? getUsage({
373
+ modelId,
374
+ usage: { cacheReads: cacheTokens, input: 0, output: 0 },
375
+ }).costUSD?.totalUSD
376
+ : undefined;
377
+ const cacheCostText = new Intl.NumberFormat('en-US', {
378
+ currency: 'USD',
379
+ style: 'currency',
380
+ }).format(cacheCost ?? 0);
381
+
382
+ return (
383
+ <div
384
+ className={cn('flex items-center justify-between text-xs', className)}
385
+ {...props}
386
+ >
387
+ <span className="text-muted-foreground">Cache</span>
388
+ <TokensWithCost costText={cacheCostText} tokens={cacheTokens} />
389
+ </div>
390
+ );
391
+ };
392
+
393
+ const TokensWithCost = ({
394
+ tokens,
395
+ costText,
396
+ }: {
397
+ tokens?: number;
398
+ costText?: string;
399
+ }) => (
400
+ <span>
401
+ {tokens === undefined
402
+ ? '—'
403
+ : new Intl.NumberFormat('en-US', {
404
+ notation: 'compact',
405
+ }).format(tokens)}
406
+ {costText ? (
407
+ <span className="text-muted-foreground ml-2">• {costText}</span>
408
+ ) : null}
409
+ </span>
410
+ );
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+
3
+ import type { ComponentProps } from 'react';
4
+
5
+ import { cn } from '@/lib/utils';
6
+ import { Controls as ControlsPrimitive } from '@xyflow/react';
7
+
8
+ export type ControlsProps = ComponentProps<typeof ControlsPrimitive>;
9
+
10
+ export const Controls = ({ className, ...props }: ControlsProps) => (
11
+ <ControlsPrimitive
12
+ className={cn(
13
+ 'bg-card gap-px overflow-hidden rounded-md border p-1 shadow-none!',
14
+ '[&>button]:hover:bg-secondary! [&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent!',
15
+ className,
16
+ )}
17
+ {...props}
18
+ />
19
+ );
@@ -0,0 +1,167 @@
1
+ 'use client';
2
+
3
+ import type { ComponentProps } from 'react';
4
+
5
+ import { Button } from '@/components/ui/button';
6
+ import { cn } from '@/lib/utils';
7
+ import { ArrowDownIcon, DownloadIcon } from 'lucide-react';
8
+ import { useCallback } from 'react';
9
+ import { StickToBottom, useStickToBottomContext } from 'use-stick-to-bottom';
10
+
11
+ export type ConversationProps = ComponentProps<typeof StickToBottom>;
12
+
13
+ export const Conversation = ({ className, ...props }: ConversationProps) => (
14
+ <StickToBottom
15
+ className={cn('relative flex-1 overflow-y-hidden', className)}
16
+ initial="smooth"
17
+ resize="smooth"
18
+ role="log"
19
+ {...props}
20
+ />
21
+ );
22
+
23
+ export type ConversationContentProps = ComponentProps<
24
+ typeof StickToBottom.Content
25
+ >;
26
+
27
+ export const ConversationContent = ({
28
+ className,
29
+ ...props
30
+ }: ConversationContentProps) => (
31
+ <StickToBottom.Content
32
+ className={cn('flex flex-col gap-8 p-4', className)}
33
+ {...props}
34
+ />
35
+ );
36
+
37
+ export type ConversationEmptyStateProps = ComponentProps<'div'> & {
38
+ title?: string;
39
+ description?: string;
40
+ icon?: React.ReactNode;
41
+ };
42
+
43
+ export const ConversationEmptyState = ({
44
+ className,
45
+ title = 'No messages yet',
46
+ description = 'Start a conversation to see messages here',
47
+ icon,
48
+ children,
49
+ ...props
50
+ }: ConversationEmptyStateProps) => (
51
+ <div
52
+ className={cn(
53
+ 'flex size-full flex-col items-center justify-center gap-3 p-8 text-center',
54
+ className,
55
+ )}
56
+ {...props}
57
+ >
58
+ {children ?? (
59
+ <>
60
+ {icon && <div className="text-muted-foreground">{icon}</div>}
61
+ <div className="space-y-1">
62
+ <h3 className="text-sm font-medium">{title}</h3>
63
+ {description && (
64
+ <p className="text-muted-foreground text-sm">{description}</p>
65
+ )}
66
+ </div>
67
+ </>
68
+ )}
69
+ </div>
70
+ );
71
+
72
+ export type ConversationScrollButtonProps = ComponentProps<typeof Button>;
73
+
74
+ export const ConversationScrollButton = ({
75
+ className,
76
+ ...props
77
+ }: ConversationScrollButtonProps) => {
78
+ const { isAtBottom, scrollToBottom } = useStickToBottomContext();
79
+
80
+ const handleScrollToBottom = useCallback(() => {
81
+ scrollToBottom();
82
+ }, [scrollToBottom]);
83
+
84
+ return (
85
+ !isAtBottom && (
86
+ <Button
87
+ className={cn(
88
+ 'dark:bg-background dark:hover:bg-muted absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full',
89
+ className,
90
+ )}
91
+ onClick={handleScrollToBottom}
92
+ size="icon"
93
+ type="button"
94
+ variant="outline"
95
+ {...props}
96
+ >
97
+ <ArrowDownIcon className="size-4" />
98
+ </Button>
99
+ )
100
+ );
101
+ };
102
+
103
+ export interface ConversationMessage {
104
+ role: 'user' | 'assistant' | 'system' | 'data' | 'tool';
105
+ content: string;
106
+ }
107
+
108
+ export type ConversationDownloadProps = Omit<
109
+ ComponentProps<typeof Button>,
110
+ 'onClick'
111
+ > & {
112
+ messages: ConversationMessage[];
113
+ filename?: string;
114
+ formatMessage?: (message: ConversationMessage, index: number) => string;
115
+ };
116
+
117
+ const defaultFormatMessage = (message: ConversationMessage): string => {
118
+ const roleLabel =
119
+ message.role.charAt(0).toUpperCase() + message.role.slice(1);
120
+ return `**${roleLabel}:** ${message.content}`;
121
+ };
122
+
123
+ export const messagesToMarkdown = (
124
+ messages: ConversationMessage[],
125
+ formatMessage: (
126
+ message: ConversationMessage,
127
+ index: number,
128
+ ) => string = defaultFormatMessage,
129
+ ): string => messages.map((msg, i) => formatMessage(msg, i)).join('\n\n');
130
+
131
+ export const ConversationDownload = ({
132
+ messages,
133
+ filename = 'conversation.md',
134
+ formatMessage = defaultFormatMessage,
135
+ className,
136
+ children,
137
+ ...props
138
+ }: ConversationDownloadProps) => {
139
+ const handleDownload = useCallback(() => {
140
+ const markdown = messagesToMarkdown(messages, formatMessage);
141
+ const blob = new Blob([markdown], { type: 'text/markdown' });
142
+ const url = URL.createObjectURL(blob);
143
+ const link = document.createElement('a');
144
+ link.href = url;
145
+ link.download = filename;
146
+ document.body.append(link);
147
+ link.click();
148
+ link.remove();
149
+ URL.revokeObjectURL(url);
150
+ }, [messages, filename, formatMessage]);
151
+
152
+ return (
153
+ <Button
154
+ className={cn(
155
+ 'dark:bg-background dark:hover:bg-muted absolute top-4 right-4 rounded-full',
156
+ className,
157
+ )}
158
+ onClick={handleDownload}
159
+ size="icon"
160
+ type="button"
161
+ variant="outline"
162
+ {...props}
163
+ >
164
+ {children ?? <DownloadIcon className="size-4" />}
165
+ </Button>
166
+ );
167
+ };