vibefast-cli 0.1.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 (250) hide show
  1. package/FINAL-STATUS.md +144 -0
  2. package/HOW-IT-WORKS.md +559 -0
  3. package/PLAN.md +453 -0
  4. package/README.md +129 -0
  5. package/RECIPES-READY.md +172 -0
  6. package/STATUS.md +199 -0
  7. package/SUCCESS.md +259 -0
  8. package/TESTING-CHECKLIST.md +450 -0
  9. package/cloudflare-worker/.wrangler/state/v3/kv/64907821e2634080acce34618d2f3d4c/blobs/11f2769953c717e188062bc644da97c1fd1e4d6d0813a226ce7567dba759afab0000019a736fb8d4 +1 -0
  10. package/cloudflare-worker/.wrangler/state/v3/kv/miniflare-KVNamespaceObject/0b03767237c0408301af51ca35d4b09470cbc479c7e5f23cc9de774749d23c59.sqlite +0 -0
  11. package/cloudflare-worker/.wrangler/state/v3/kv/miniflare-KVNamespaceObject/0b03767237c0408301af51ca35d4b09470cbc479c7e5f23cc9de774749d23c59.sqlite-shm +0 -0
  12. package/cloudflare-worker/.wrangler/state/v3/kv/miniflare-KVNamespaceObject/0b03767237c0408301af51ca35d4b09470cbc479c7e5f23cc9de774749d23c59.sqlite-wal +0 -0
  13. package/cloudflare-worker/.wrangler/state/v3/r2/miniflare-R2BucketObject/d1cc388a1a0ef44dd5669fd1a165d168b61362136c8b5fa50aefd96c72688e54.sqlite +0 -0
  14. package/cloudflare-worker/.wrangler/state/v3/r2/miniflare-R2BucketObject/d1cc388a1a0ef44dd5669fd1a165d168b61362136c8b5fa50aefd96c72688e54.sqlite-shm +0 -0
  15. package/cloudflare-worker/.wrangler/state/v3/r2/miniflare-R2BucketObject/d1cc388a1a0ef44dd5669fd1a165d168b61362136c8b5fa50aefd96c72688e54.sqlite-wal +0 -0
  16. package/cloudflare-worker/.wrangler/state/v3/r2/vibefast-recipes/blobs/620e8cf7c35d9806da25dee237e1d7e8b2432bd98f755b60e2c7f08a48d2c7b90000019a73736484 +0 -0
  17. package/cloudflare-worker/MIGRATION.md +160 -0
  18. package/cloudflare-worker/QUICKSTART.md +200 -0
  19. package/cloudflare-worker/README.md +242 -0
  20. package/cloudflare-worker/generate-token.js +32 -0
  21. package/cloudflare-worker/mini-native@latest.zip +0 -0
  22. package/cloudflare-worker/setup.sh +143 -0
  23. package/cloudflare-worker/test-recipe/apps/native/src/app/mini/index.tsx +15 -0
  24. package/cloudflare-worker/test-recipe/recipe.json +16 -0
  25. package/cloudflare-worker/worker.js +308 -0
  26. package/cloudflare-worker/wrangler.toml +13 -0
  27. package/dist/commands/add.d.ts +3 -0
  28. package/dist/commands/add.d.ts.map +1 -0
  29. package/dist/commands/add.js +149 -0
  30. package/dist/commands/add.js.map +1 -0
  31. package/dist/commands/devices.d.ts +3 -0
  32. package/dist/commands/devices.d.ts.map +1 -0
  33. package/dist/commands/devices.js +35 -0
  34. package/dist/commands/devices.js.map +1 -0
  35. package/dist/commands/doctor.d.ts +3 -0
  36. package/dist/commands/doctor.d.ts.map +1 -0
  37. package/dist/commands/doctor.js +67 -0
  38. package/dist/commands/doctor.js.map +1 -0
  39. package/dist/commands/list.d.ts +3 -0
  40. package/dist/commands/list.d.ts.map +1 -0
  41. package/dist/commands/list.js +40 -0
  42. package/dist/commands/list.js.map +1 -0
  43. package/dist/commands/login.d.ts +3 -0
  44. package/dist/commands/login.d.ts.map +1 -0
  45. package/dist/commands/login.js +23 -0
  46. package/dist/commands/login.js.map +1 -0
  47. package/dist/commands/logout.d.ts +3 -0
  48. package/dist/commands/logout.d.ts.map +1 -0
  49. package/dist/commands/logout.js +16 -0
  50. package/dist/commands/logout.js.map +1 -0
  51. package/dist/commands/remove.d.ts +3 -0
  52. package/dist/commands/remove.d.ts.map +1 -0
  53. package/dist/commands/remove.js +67 -0
  54. package/dist/commands/remove.js.map +1 -0
  55. package/dist/core/__tests__/journal.test.d.ts +2 -0
  56. package/dist/core/__tests__/journal.test.d.ts.map +1 -0
  57. package/dist/core/__tests__/journal.test.js +101 -0
  58. package/dist/core/__tests__/journal.test.js.map +1 -0
  59. package/dist/core/__tests__/validate.test.d.ts +2 -0
  60. package/dist/core/__tests__/validate.test.d.ts.map +1 -0
  61. package/dist/core/__tests__/validate.test.js +53 -0
  62. package/dist/core/__tests__/validate.test.js.map +1 -0
  63. package/dist/core/archive.d.ts +2 -0
  64. package/dist/core/archive.d.ts.map +1 -0
  65. package/dist/core/archive.js +59 -0
  66. package/dist/core/archive.js.map +1 -0
  67. package/dist/core/auth.d.ts +15 -0
  68. package/dist/core/auth.d.ts.map +1 -0
  69. package/dist/core/auth.js +76 -0
  70. package/dist/core/auth.js.map +1 -0
  71. package/dist/core/codemod.d.ts +20 -0
  72. package/dist/core/codemod.d.ts.map +1 -0
  73. package/dist/core/codemod.js +150 -0
  74. package/dist/core/codemod.js.map +1 -0
  75. package/dist/core/fsx.d.ts +12 -0
  76. package/dist/core/fsx.d.ts.map +1 -0
  77. package/dist/core/fsx.js +70 -0
  78. package/dist/core/fsx.js.map +1 -0
  79. package/dist/core/http.d.ts +30 -0
  80. package/dist/core/http.d.ts.map +1 -0
  81. package/dist/core/http.js +95 -0
  82. package/dist/core/http.js.map +1 -0
  83. package/dist/core/journal.d.ts +18 -0
  84. package/dist/core/journal.d.ts.map +1 -0
  85. package/dist/core/journal.js +34 -0
  86. package/dist/core/journal.js.map +1 -0
  87. package/dist/core/log.d.ts +8 -0
  88. package/dist/core/log.d.ts.map +1 -0
  89. package/dist/core/log.js +9 -0
  90. package/dist/core/log.js.map +1 -0
  91. package/dist/core/pathGuard.d.ts +3 -0
  92. package/dist/core/pathGuard.d.ts.map +1 -0
  93. package/dist/core/pathGuard.js +18 -0
  94. package/dist/core/pathGuard.js.map +1 -0
  95. package/dist/core/paths.d.ts +11 -0
  96. package/dist/core/paths.d.ts.map +1 -0
  97. package/dist/core/paths.js +22 -0
  98. package/dist/core/paths.js.map +1 -0
  99. package/dist/core/validate.d.ts +8 -0
  100. package/dist/core/validate.d.ts.map +1 -0
  101. package/dist/core/validate.js +27 -0
  102. package/dist/core/validate.js.map +1 -0
  103. package/dist/index.d.ts +3 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +23 -0
  106. package/dist/index.js.map +1 -0
  107. package/docs/decisions.md +55 -0
  108. package/package.json +39 -0
  109. package/recipes/audio-recorder/apps/native/src/app/audio-recorder/index.tsx +5 -0
  110. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-player.tsx +301 -0
  111. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-recorder.tsx +373 -0
  112. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-waveform.tsx +270 -0
  113. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/index.ts +4 -0
  114. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/recording-list.tsx +89 -0
  115. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/audio-player-demo.tsx +66 -0
  116. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/audio-recorder-cloud.tsx +68 -0
  117. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/audio-recorder-interview.tsx +102 -0
  118. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/basic.tsx +27 -0
  119. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/index.ts +5 -0
  120. package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/with-recording-list-demo.tsx +82 -0
  121. package/recipes/audio-recorder/recipe.json +22 -0
  122. package/recipes/audio-recorder@latest.zip +0 -0
  123. package/recipes/charts/apps/native/src/app/charts/index.tsx +3 -0
  124. package/recipes/charts/apps/native/src/features/charts/README.md +185 -0
  125. package/recipes/charts/apps/native/src/features/charts/app/preview.tsx +223 -0
  126. package/recipes/charts/apps/native/src/features/charts/components/area-chart.tsx +40 -0
  127. package/recipes/charts/apps/native/src/features/charts/components/bar-chart.tsx +143 -0
  128. package/recipes/charts/apps/native/src/features/charts/components/candlestick-chart.tsx +196 -0
  129. package/recipes/charts/apps/native/src/features/charts/components/chart-card.tsx +65 -0
  130. package/recipes/charts/apps/native/src/features/charts/components/column-chart.tsx +143 -0
  131. package/recipes/charts/apps/native/src/features/charts/components/doughnut-chart.tsx +246 -0
  132. package/recipes/charts/apps/native/src/features/charts/components/index.ts +10 -0
  133. package/recipes/charts/apps/native/src/features/charts/components/line-chart.tsx +308 -0
  134. package/recipes/charts/apps/native/src/features/charts/components/radar-chart.tsx +180 -0
  135. package/recipes/charts/apps/native/src/features/charts/components/radial-bar-chart.tsx +188 -0
  136. package/recipes/charts/apps/native/src/features/charts/components/stacked-area-chart.tsx +265 -0
  137. package/recipes/charts/apps/native/src/features/charts/components/stacked-bar-chart.tsx +322 -0
  138. package/recipes/charts/apps/native/src/features/charts/data/mock-data.ts +183 -0
  139. package/recipes/charts/apps/native/src/features/charts/types/index.ts +66 -0
  140. package/recipes/charts/recipe.json +22 -0
  141. package/recipes/charts@latest.zip +0 -0
  142. package/recipes/chatbot/apps/native/src/app/chatbot/index.tsx +1 -0
  143. package/recipes/chatbot/apps/native/src/features/chatbot/app/index.tsx +302 -0
  144. package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-header-buttons.tsx +59 -0
  145. package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-input-bar.tsx +469 -0
  146. package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-markdown.tsx +575 -0
  147. package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-message-bubble.tsx +246 -0
  148. package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-settings-modal.tsx +161 -0
  149. package/recipes/chatbot/apps/native/src/features/chatbot/components/image-preview-list.tsx +115 -0
  150. package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/code-block.tsx +165 -0
  151. package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/index.ts +10 -0
  152. package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/table-renderer.tsx +129 -0
  153. package/recipes/chatbot/apps/native/src/features/chatbot/components/message-error-boundary.tsx +78 -0
  154. package/recipes/chatbot/apps/native/src/features/chatbot/components/message-list.tsx +173 -0
  155. package/recipes/chatbot/apps/native/src/features/chatbot/components/model-selector.tsx +283 -0
  156. package/recipes/chatbot/apps/native/src/features/chatbot/components/report-content-modal.tsx +188 -0
  157. package/recipes/chatbot/apps/native/src/features/chatbot/components/suggested-messages.tsx +67 -0
  158. package/recipes/chatbot/apps/native/src/features/chatbot/constants/models.ts +20 -0
  159. package/recipes/chatbot/apps/native/src/features/chatbot/constants/report-reasons.ts +9 -0
  160. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-attachment-cache.ts +143 -0
  161. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-chat-config.ts +664 -0
  162. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-chat-handlers.ts +359 -0
  163. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-chatbot-settings.ts +89 -0
  164. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-conversation.ts +79 -0
  165. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-image-picker.ts +122 -0
  166. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-keyboard-coordinator.ts +161 -0
  167. package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-smart-scroll-manager.ts +207 -0
  168. package/recipes/chatbot/apps/native/src/features/chatbot/models/index.ts +86 -0
  169. package/recipes/chatbot/apps/native/src/features/chatbot/models/models.ts +162 -0
  170. package/recipes/chatbot/apps/native/src/features/chatbot/models/providers.ts +62 -0
  171. package/recipes/chatbot/apps/native/src/features/chatbot/models/types.ts +40 -0
  172. package/recipes/chatbot/apps/native/src/features/chatbot/services/file-uploader.ts +238 -0
  173. package/recipes/chatbot/apps/native/src/features/chatbot/services/message-handler-service.ts +180 -0
  174. package/recipes/chatbot/apps/native/src/features/chatbot/types/index.ts +60 -0
  175. package/recipes/chatbot/apps/native/src/features/chatbot/utils/chat-telemetry.ts +91 -0
  176. package/recipes/chatbot/recipe.json +22 -0
  177. package/recipes/chatbot@latest.zip +0 -0
  178. package/recipes/image-generator/apps/native/src/app/image-generator/gallery.tsx +3 -0
  179. package/recipes/image-generator/apps/native/src/app/image-generator/index.tsx +3 -0
  180. package/recipes/image-generator/apps/native/src/features/image-generator/app/_layout.tsx +25 -0
  181. package/recipes/image-generator/apps/native/src/features/image-generator/app/gallery.tsx +217 -0
  182. package/recipes/image-generator/apps/native/src/features/image-generator/app/index.tsx +237 -0
  183. package/recipes/image-generator/apps/native/src/features/image-generator/components/gallery-image.tsx +26 -0
  184. package/recipes/image-generator/apps/native/src/features/image-generator/components/image-detail-modal.tsx +215 -0
  185. package/recipes/image-generator/apps/native/src/features/image-generator/components/image-model-selector.tsx +210 -0
  186. package/recipes/image-generator/apps/native/src/features/image-generator/components/image-placeholder.tsx +26 -0
  187. package/recipes/image-generator/apps/native/src/features/image-generator/hooks/use-image-gallery.ts +71 -0
  188. package/recipes/image-generator/apps/native/src/features/image-generator/hooks/use-image-generator-settings.ts +152 -0
  189. package/recipes/image-generator/apps/native/src/features/image-generator/hooks/use-image-generator.ts +93 -0
  190. package/recipes/image-generator/apps/native/src/features/image-generator/models/models.ts +66 -0
  191. package/recipes/image-generator/apps/native/src/features/image-generator/services/image-gallery-service.ts +98 -0
  192. package/recipes/image-generator/apps/native/src/features/image-generator/services/image-save-service.ts +121 -0
  193. package/recipes/image-generator/recipe.json +22 -0
  194. package/recipes/image-generator@latest.zip +0 -0
  195. package/recipes/quiz/apps/native/src/app/quiz/index.tsx +47 -0
  196. package/recipes/quiz/apps/native/src/features/quiz/components/question.tsx +67 -0
  197. package/recipes/quiz/apps/native/src/features/quiz/config.ts +11 -0
  198. package/recipes/quiz/apps/native/src/features/quiz/index.tsx +133 -0
  199. package/recipes/quiz/recipe.json +22 -0
  200. package/recipes/quiz@latest.zip +0 -0
  201. package/recipes/tracker-app/apps/native/src/app/tracker-app/index.tsx +1 -0
  202. package/recipes/tracker-app/apps/native/src/features/tracker-app/app/index.tsx +108 -0
  203. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/animated-number.tsx +102 -0
  204. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/calorie-card.tsx +66 -0
  205. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/circular-progress.tsx +97 -0
  206. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/floating-add-button.tsx +27 -0
  207. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/macro-card.tsx +80 -0
  208. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/promo-banner.tsx +98 -0
  209. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/recently-logged.tsx +64 -0
  210. package/recipes/tracker-app/apps/native/src/features/tracker-app/components/week-calendar.tsx +68 -0
  211. package/recipes/tracker-app/recipe.json +22 -0
  212. package/recipes/tracker-app@latest.zip +0 -0
  213. package/recipes/upload-all.sh +32 -0
  214. package/recipes/voice-bot/apps/native/src/app/voice-bot/index.tsx +27 -0
  215. package/recipes/voice-bot/apps/native/src/features/voice-bot/README.md +185 -0
  216. package/recipes/voice-bot/apps/native/src/features/voice-bot/components/conversation-status.tsx +76 -0
  217. package/recipes/voice-bot/apps/native/src/features/voice-bot/components/index.ts +4 -0
  218. package/recipes/voice-bot/apps/native/src/features/voice-bot/components/message-input.tsx +98 -0
  219. package/recipes/voice-bot/apps/native/src/features/voice-bot/components/voice-bot-screen.tsx +173 -0
  220. package/recipes/voice-bot/apps/native/src/features/voice-bot/components/voice-controls.tsx +73 -0
  221. package/recipes/voice-bot/apps/native/src/features/voice-bot/index.ts +3 -0
  222. package/recipes/voice-bot/apps/native/src/features/voice-bot/services/index.ts +1 -0
  223. package/recipes/voice-bot/apps/native/src/features/voice-bot/services/use-voice-bot.ts +161 -0
  224. package/recipes/voice-bot/apps/native/src/features/voice-bot/types.ts +29 -0
  225. package/recipes/voice-bot/recipe.json +22 -0
  226. package/recipes/voice-bot@latest.zip +0 -0
  227. package/scripts/create-recipes.mjs +189 -0
  228. package/src/commands/add.ts +183 -0
  229. package/src/commands/devices.ts +38 -0
  230. package/src/commands/doctor.ts +67 -0
  231. package/src/commands/list.ts +45 -0
  232. package/src/commands/login.ts +24 -0
  233. package/src/commands/logout.ts +15 -0
  234. package/src/commands/remove.ts +78 -0
  235. package/src/core/__tests__/journal.test.ts +119 -0
  236. package/src/core/__tests__/validate.test.ts +64 -0
  237. package/src/core/archive.ts +69 -0
  238. package/src/core/auth.ts +103 -0
  239. package/src/core/codemod.ts +211 -0
  240. package/src/core/fsx.ts +80 -0
  241. package/src/core/http.ts +136 -0
  242. package/src/core/journal.ts +64 -0
  243. package/src/core/log.ts +9 -0
  244. package/src/core/pathGuard.ts +22 -0
  245. package/src/core/paths.ts +33 -0
  246. package/src/core/validate.ts +44 -0
  247. package/src/index.ts +27 -0
  248. package/test-critical-cases.mjs +258 -0
  249. package/tsconfig.json +21 -0
  250. package/vitest.config.mts +12 -0
@@ -0,0 +1,575 @@
1
+ /**
2
+ * ChatMarkdown component for rendering markdown content in chat messages.
3
+ *
4
+ * This component has been refactored to improve modularity:
5
+ * - CodeBlock component extracted to ./markdown/code-block.tsx
6
+ * - TableRenderer component extracted to ./markdown/table-renderer.tsx
7
+ *
8
+ * The remaining code consists primarily of:
9
+ * - Style definitions (markdownStyles object)
10
+ * - Render rules configuration
11
+ * - Theme integration
12
+ *
13
+ * Requirements addressed:
14
+ * - 5.1: Extract CodeBlock component into separate file
15
+ * - 5.2: Extract table rendering logic into dedicated file
16
+ * - 5.3: Add JSDoc comments to exported functions
17
+ *
18
+ * Note: This file still exceeds 300 lines due to extensive style definitions
19
+ * and render rules, but the complex logic has been extracted into separate modules.
20
+ */
21
+
22
+ import * as Clipboard from 'expo-clipboard';
23
+ import MarkdownIt from 'markdown-it';
24
+ import React, { useCallback, useEffect, useMemo } from 'react';
25
+ import {
26
+ Image,
27
+ type ImageStyle,
28
+ Linking,
29
+ Platform,
30
+ StyleSheet,
31
+ Text,
32
+ type TextStyle,
33
+ UIManager,
34
+ View,
35
+ type ViewStyle,
36
+ } from 'react-native';
37
+ import Markdown, { type RenderRules } from 'react-native-markdown-display';
38
+ import { atomOneDark, github } from 'react-syntax-highlighter/styles/hljs';
39
+
40
+ import { useToast } from '@/components/ui/utils';
41
+ import { translate } from '@/lib';
42
+ import { useThemeConfig } from '@/lib/use-theme-config';
43
+
44
+ import { CodeBlock, TableRenderer } from './markdown';
45
+
46
+ const md = new MarkdownIt({
47
+ linkify: true,
48
+ breaks: true,
49
+ });
50
+
51
+ type ChatMarkdownProps = {
52
+ content: string;
53
+ };
54
+
55
+ /**
56
+ * Renders markdown content with syntax highlighting, tables, and rich formatting.
57
+ *
58
+ * @param content - Markdown string to render
59
+ * @param onPrepareLayoutAnimation - Optional callback to prepare FlashList for layout changes
60
+ * @returns Rendered markdown content
61
+ */
62
+ export const ChatMarkdown = React.memo(function ChatMarkdown({
63
+ content,
64
+ }: ChatMarkdownProps) {
65
+ const theme = useThemeConfig();
66
+ const toast = useToast();
67
+
68
+ useEffect(() => {
69
+ if (
70
+ Platform.OS === 'android' &&
71
+ typeof UIManager.setLayoutAnimationEnabledExperimental === 'function'
72
+ ) {
73
+ UIManager.setLayoutAnimationEnabledExperimental(true);
74
+ }
75
+ }, []);
76
+
77
+ const textColor = theme.colors.text as string;
78
+ const linkColor = theme.colors.primary as string;
79
+ const codeBg = theme.colors.muted as string;
80
+ const codeFg = theme.colors.foreground as string;
81
+ const subtleText = theme.colors.mutedForeground as string;
82
+ const borderColor = theme.colors.border as string;
83
+ const isDarkMode = theme.dark ?? false;
84
+
85
+ const monospaceFontFamily = useMemo(
86
+ () =>
87
+ Platform.select({
88
+ ios: 'Menlo-Regular',
89
+ android: 'monospace',
90
+ default: 'Menlo',
91
+ }) ?? 'Menlo',
92
+ [],
93
+ );
94
+
95
+ const columnDividerWidth = StyleSheet.hairlineWidth || 0.5;
96
+
97
+ const markdownStyles = useMemo(() => {
98
+ const codeBlockStyle = {
99
+ backgroundColor: codeBg,
100
+ borderBlockColor: borderColor,
101
+ paddingTop: 24,
102
+ paddingHorizontal: 14,
103
+ paddingBottom: 20,
104
+ borderRadius: 10,
105
+ marginVertical: 12,
106
+ } satisfies ViewStyle;
107
+
108
+ const styles = {
109
+ body: { fontSize: 17, lineHeight: 24, color: textColor },
110
+ text: { fontSize: 17, lineHeight: 24, color: textColor },
111
+ paragraph: { marginBottom: 10, color: textColor },
112
+ link: {
113
+ color: linkColor,
114
+ textDecorationLine: 'underline' as TextStyle['textDecorationLine'],
115
+ fontWeight: '500' as TextStyle['fontWeight'],
116
+ },
117
+ strong: {
118
+ fontWeight: '600' as TextStyle['fontWeight'],
119
+ color: textColor,
120
+ },
121
+ em: {
122
+ fontStyle: 'italic' as TextStyle['fontStyle'],
123
+ color: textColor,
124
+ },
125
+ code_inline: {
126
+ fontFamily: monospaceFontFamily,
127
+ fontSize: 15,
128
+ backgroundColor: codeBg,
129
+ borderColor: borderColor,
130
+ color: codeFg,
131
+ paddingHorizontal: 6,
132
+ paddingVertical: 3,
133
+ borderRadius: 6,
134
+ },
135
+ code_block: codeBlockStyle,
136
+ fence: codeBlockStyle,
137
+ blockquote: {
138
+ color: textColor,
139
+ backgroundColor: codeBg,
140
+ borderLeftColor: linkColor,
141
+ borderLeftWidth: 3,
142
+ paddingLeft: 12,
143
+ marginVertical: 12,
144
+ },
145
+ bullet_list: {
146
+ marginVertical: 8,
147
+ paddingLeft: 0,
148
+ },
149
+ ordered_list: {
150
+ marginVertical: 8,
151
+ paddingLeft: 0,
152
+ },
153
+ list_item: { marginBottom: 6, color: textColor },
154
+ table: {
155
+ minWidth: '100%',
156
+ backgroundColor: theme.colors.background,
157
+ },
158
+ thead: {
159
+ backgroundColor: codeBg,
160
+ },
161
+ tbody: {},
162
+ tr: {
163
+ borderBottomWidth: StyleSheet.hairlineWidth,
164
+ borderColor,
165
+ flexDirection: 'row',
166
+ },
167
+ th: {
168
+ flexGrow: 0,
169
+ flexShrink: 0,
170
+ minWidth: 140,
171
+ paddingVertical: 10,
172
+ paddingHorizontal: 16,
173
+ backgroundColor: codeBg,
174
+ borderLeftWidth: columnDividerWidth,
175
+ borderColor,
176
+ },
177
+ td: {
178
+ flexGrow: 0,
179
+ flexShrink: 0,
180
+ minWidth: 140,
181
+ paddingVertical: 10,
182
+ paddingHorizontal: 16,
183
+ borderLeftWidth: columnDividerWidth,
184
+ borderColor,
185
+ },
186
+ heading1: {
187
+ fontSize: 28,
188
+ fontWeight: '700',
189
+ color: textColor,
190
+ marginTop: 18,
191
+ marginBottom: 12,
192
+ },
193
+ heading2: {
194
+ fontSize: 22,
195
+ fontWeight: '700',
196
+ color: textColor,
197
+ marginTop: 16,
198
+ marginBottom: 10,
199
+ },
200
+ heading3: {
201
+ fontSize: 19,
202
+ fontWeight: '600',
203
+ color: textColor,
204
+ marginTop: 14,
205
+ marginBottom: 8,
206
+ },
207
+ heading4: {
208
+ fontSize: 17,
209
+ fontWeight: '600',
210
+ color: textColor,
211
+ marginTop: 12,
212
+ marginBottom: 8,
213
+ },
214
+ heading5: {
215
+ fontSize: 16,
216
+ fontWeight: '600',
217
+ color: textColor,
218
+ marginTop: 10,
219
+ marginBottom: 6,
220
+ },
221
+ heading6: {
222
+ fontSize: 15,
223
+ fontWeight: '600' as TextStyle['fontWeight'],
224
+ color: textColor,
225
+ marginTop: 8,
226
+ marginBottom: 6,
227
+ },
228
+ hr: {
229
+ backgroundColor: codeBg,
230
+ height: 1,
231
+ marginVertical: 14,
232
+ },
233
+ imageWrapper: {
234
+ marginVertical: 8,
235
+ borderRadius: 14,
236
+ overflow: 'hidden',
237
+ },
238
+ image: {
239
+ width: '100%',
240
+ aspectRatio: 16 / 9,
241
+ backgroundColor: codeBg,
242
+ },
243
+ image_caption: {
244
+ marginTop: 6,
245
+ fontSize: 13,
246
+ color: subtleText,
247
+ textAlign: 'center',
248
+ },
249
+ };
250
+
251
+ return styles as Record<string, TextStyle | ViewStyle | ImageStyle>;
252
+ }, [
253
+ borderColor,
254
+ codeBg,
255
+ codeFg,
256
+ linkColor,
257
+ subtleText,
258
+ textColor,
259
+ monospaceFontFamily,
260
+ theme.colors.background,
261
+ columnDividerWidth,
262
+ ]);
263
+
264
+ const codeSyntaxTheme = useMemo(() => {
265
+ const baseTheme = isDarkMode ? atomOneDark : github;
266
+ return {
267
+ ...baseTheme,
268
+ hljs: {
269
+ ...baseTheme.hljs,
270
+ background: 'transparent',
271
+ color: codeFg,
272
+ },
273
+ };
274
+ }, [codeFg, isDarkMode]);
275
+
276
+ const codeContentStyle = useMemo(
277
+ () =>
278
+ ({
279
+ backgroundColor: 'transparent',
280
+ padding: 0,
281
+ margin: 0,
282
+ }) satisfies ViewStyle,
283
+ [],
284
+ );
285
+
286
+ const tableScrollViewStyle = useMemo(
287
+ () =>
288
+ ({
289
+ marginVertical: 0,
290
+ }) satisfies ViewStyle,
291
+ [],
292
+ );
293
+
294
+ const tableScrollContentStyle = useMemo(
295
+ () =>
296
+ ({
297
+ flexGrow: 1,
298
+ }) satisfies ViewStyle,
299
+ [],
300
+ );
301
+
302
+ const tableOuterStyle = useMemo(
303
+ () =>
304
+ ({
305
+ borderWidth: 1,
306
+ borderColor,
307
+ borderRadius: 10,
308
+ overflow: 'hidden',
309
+ marginVertical: 12,
310
+ backgroundColor: theme.colors.background,
311
+ }) satisfies ViewStyle,
312
+ [borderColor, theme.colors.background],
313
+ );
314
+
315
+ const codeActionsContainerStyle = useMemo(
316
+ () =>
317
+ ({
318
+ position: 'absolute',
319
+ top: 12,
320
+ right: 12,
321
+ flexDirection: 'row',
322
+ alignItems: 'center',
323
+ justifyContent: 'flex-end',
324
+ }) satisfies ViewStyle,
325
+ [],
326
+ );
327
+
328
+ const codeActionButtonBaseStyle = useMemo(
329
+ () =>
330
+ ({
331
+ alignItems: 'center',
332
+ justifyContent: 'center',
333
+ borderRadius: 999,
334
+ borderWidth: 1,
335
+ borderColor,
336
+ paddingHorizontal: 12,
337
+ paddingVertical: 8,
338
+ backgroundColor: isDarkMode
339
+ ? 'rgba(15, 15, 15, 0.9)'
340
+ : 'rgba(255, 255, 255, 0.92)',
341
+ }) satisfies ViewStyle,
342
+ [borderColor, isDarkMode],
343
+ );
344
+
345
+ const codeToggleButtonSpacingStyle = useMemo(
346
+ () =>
347
+ ({
348
+ marginLeft: 16,
349
+ }) satisfies ViewStyle,
350
+ [],
351
+ );
352
+
353
+ const codeContentContainerStyle = useMemo(
354
+ () =>
355
+ ({
356
+ overflow: 'hidden',
357
+ marginTop: 24,
358
+ }) satisfies ViewStyle,
359
+ [],
360
+ );
361
+
362
+ const copyCodeToClipboard = useCallback(
363
+ async (code: string) => {
364
+ try {
365
+ if (!code.trim()) {
366
+ toast.warning(translate('chatbot.empty_message'), {
367
+ duration: 2000,
368
+ });
369
+ return;
370
+ }
371
+
372
+ await Clipboard.setStringAsync(code);
373
+ toast.success(translate('chatbot.copy_code_success'), {
374
+ duration: 2000,
375
+ });
376
+ } catch (error) {
377
+ console.error('[CHATBOT_FRONTEND] Copy code failed:', {
378
+ error: error instanceof Error ? error.message : 'Unknown error',
379
+ });
380
+ toast.error(translate('chatbot.copy_code_failed'), {
381
+ duration: 3000,
382
+ });
383
+ }
384
+ },
385
+ [toast],
386
+ );
387
+
388
+ // Memoize CodeBlock wrapper to pass all required props
389
+ const renderCodeBlockComponent = useCallback(
390
+ (
391
+ containerStyle: ViewStyle | TextStyle | ImageStyle,
392
+ content: string,
393
+ language: string,
394
+ ) => {
395
+ return (
396
+ <CodeBlock
397
+ containerStyle={containerStyle}
398
+ content={content}
399
+ language={language}
400
+ codeSyntaxTheme={codeSyntaxTheme}
401
+ monospaceFontFamily={monospaceFontFamily}
402
+ subtleText={subtleText}
403
+ codeContentStyle={codeContentStyle}
404
+ codeActionsContainerStyle={codeActionsContainerStyle}
405
+ codeActionButtonBaseStyle={codeActionButtonBaseStyle}
406
+ codeToggleButtonSpacingStyle={codeToggleButtonSpacingStyle}
407
+ codeContentContainerStyle={codeContentContainerStyle}
408
+ onCopyCode={copyCodeToClipboard}
409
+ />
410
+ );
411
+ },
412
+ [
413
+ codeSyntaxTheme,
414
+ monospaceFontFamily,
415
+ subtleText,
416
+ codeContentStyle,
417
+ codeActionsContainerStyle,
418
+ codeActionButtonBaseStyle,
419
+ codeToggleButtonSpacingStyle,
420
+ codeContentContainerStyle,
421
+ copyCodeToClipboard,
422
+ ],
423
+ );
424
+
425
+ const handleLinkPress = useCallback((url: string) => {
426
+ if (!url) {
427
+ return false;
428
+ }
429
+
430
+ Linking.openURL(url).catch(() => {
431
+ // Swallow errors so the renderer keeps flowing even if the link fails.
432
+ });
433
+
434
+ return true;
435
+ }, []);
436
+
437
+ const rules = useMemo<RenderRules>(() => {
438
+ const renderCodeBlock = (
439
+ node: any,
440
+ _children: React.ReactNode[],
441
+ _parent: any[],
442
+ styles: Record<string, any>,
443
+ _inheritedStyles: Record<string, any> = {},
444
+ ) => {
445
+ const rawContent = typeof node.content === 'string' ? node.content : '';
446
+ const trimmed = rawContent.replace(/\n+$/u, '');
447
+ const content = trimmed.length > 0 ? trimmed : rawContent;
448
+
449
+ const info = node.attributes?.info;
450
+ const className = node.attributes?.class;
451
+ const languageFromInfo =
452
+ typeof info === 'string' && info.trim().length > 0
453
+ ? info.trim().split(/\s+/u)[0]
454
+ : undefined;
455
+ const languageFromClass =
456
+ typeof className === 'string'
457
+ ? (className.match(/language-([\w-]+)/u)?.[1] ??
458
+ className.match(/lang-([\w-]+)/u)?.[1])
459
+ : undefined;
460
+ const language = (languageFromInfo ?? languageFromClass ?? '')
461
+ .replace(/^language-/u, '')
462
+ .toLowerCase();
463
+
464
+ const containerStyle =
465
+ styles.code_block ?? styles.fence ?? styles.code_inline;
466
+
467
+ return (
468
+ <React.Fragment key={node.key}>
469
+ {renderCodeBlockComponent(containerStyle, content, language)}
470
+ </React.Fragment>
471
+ );
472
+ };
473
+
474
+ return {
475
+ code: (node, _children, _parent, styles) => {
476
+ const content = node.content || '';
477
+ return (
478
+ <Text key={node.key} style={styles.code_inline}>
479
+ {content}
480
+ </Text>
481
+ );
482
+ },
483
+ code_block: renderCodeBlock,
484
+ fence: renderCodeBlock,
485
+ table: (node, children, _parent, styles) => {
486
+ return (
487
+ <TableRenderer
488
+ node={node}
489
+ styles={styles}
490
+ tableOuterStyle={tableOuterStyle}
491
+ tableScrollContentStyle={tableScrollContentStyle}
492
+ tableScrollViewStyle={tableScrollViewStyle}
493
+ columnDividerWidth={columnDividerWidth}
494
+ >
495
+ {children}
496
+ </TableRenderer>
497
+ );
498
+ },
499
+ link: (node, children, _parent, styles) => {
500
+ const href =
501
+ typeof node.attributes?.href === 'string' ? node.attributes.href : '';
502
+ const titleAttr =
503
+ typeof node.attributes?.title === 'string'
504
+ ? node.attributes.title.trim()
505
+ : '';
506
+ const fallbackLabel =
507
+ typeof node.content === 'string' && node.content.trim().length > 0
508
+ ? node.content.trim()
509
+ : href;
510
+ const linkLabel =
511
+ titleAttr.length > 0
512
+ ? titleAttr
513
+ : children && children.length > 0
514
+ ? children
515
+ : fallbackLabel;
516
+
517
+ return (
518
+ <Text
519
+ key={node.key}
520
+ style={styles.link}
521
+ onPress={() => {
522
+ if (href) {
523
+ handleLinkPress(href);
524
+ }
525
+ }}
526
+ >
527
+ {linkLabel}
528
+ </Text>
529
+ );
530
+ },
531
+ image: (node, _children, _parent, styles) => {
532
+ const sourceUri = node.attributes?.src;
533
+ if (!sourceUri) {
534
+ return null;
535
+ }
536
+
537
+ const alt = node.attributes?.alt ?? '';
538
+ const caption = alt.trim().length > 0 ? alt : undefined;
539
+
540
+ return (
541
+ <View key={node.key} style={styles.imageWrapper}>
542
+ <Image
543
+ source={{ uri: sourceUri }}
544
+ style={styles.image}
545
+ resizeMode="cover"
546
+ accessible
547
+ accessibilityLabel={caption ?? 'Markdown image'}
548
+ />
549
+ {caption ? (
550
+ <Text style={styles.image_caption}>{caption}</Text>
551
+ ) : null}
552
+ </View>
553
+ );
554
+ },
555
+ };
556
+ }, [
557
+ renderCodeBlockComponent,
558
+ tableOuterStyle,
559
+ tableScrollContentStyle,
560
+ tableScrollViewStyle,
561
+ columnDividerWidth,
562
+ handleLinkPress,
563
+ ]);
564
+
565
+ return (
566
+ <Markdown
567
+ markdownit={md}
568
+ style={markdownStyles}
569
+ onLinkPress={handleLinkPress}
570
+ rules={rules}
571
+ >
572
+ {content}
573
+ </Markdown>
574
+ );
575
+ });