@adminide-stack/clock-tik-mobile 0.0.0-stage → 12.0.37-alpha.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 (376) hide show
  1. package/.claude-flow/data/pending-insights.jsonl +43 -0
  2. package/.claude-flow/sessions/session-1794323376548.json +14 -0
  3. package/CHANGELOG.md +31 -0
  4. package/jest.config.cjs +22 -0
  5. package/lib/assets/home/loop-day.jpg +0 -0
  6. package/lib/assets/home/loop-day.mp4 +0 -0
  7. package/lib/assets/home/loop-time-back.jpg +0 -0
  8. package/lib/assets/home/loop-time-back.mp4 +0 -0
  9. package/lib/assets/home/loop-where.jpg +0 -0
  10. package/lib/assets/home/loop-where.mp4 +0 -0
  11. package/lib/assets/home/reel-gym.jpg +0 -0
  12. package/lib/assets/home/reel-gym.mp4 +0 -0
  13. package/lib/assets/home/reel-internet.jpg +0 -0
  14. package/lib/assets/home/reel-internet.mp4 +0 -0
  15. package/lib/assets/icon.png +0 -0
  16. package/lib/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
  17. package/lib/assets/lottie/lucy-mark-calendar.json +1827 -0
  18. package/lib/assets/lottie/lucy-mark-call.json +1470 -0
  19. package/lib/assets/lottie/lucy-mark-connect.json +2552 -0
  20. package/lib/assets/lottie/lucy-mark-details.json +1735 -0
  21. package/lib/assets/lottie/lucy-mark-email.json +1363 -0
  22. package/lib/assets/lottie/lucy-mark-message.json +1154 -0
  23. package/lib/assets/lottie/lucy-mark-search.json +1067 -0
  24. package/lib/assets/lottie/lucy-mark-think.json +1253 -0
  25. package/lib/assets/lottie/lucy-mark-write.json +1532 -0
  26. package/lib/assets/lottie/time-back.json +16458 -0
  27. package/lib/assets/lottie/where-lucy-works-chat.json +6170 -0
  28. package/lib/assets/lottie/where-lucy-works-cloud.json +10066 -0
  29. package/lib/assets/lottie/where-lucy-works-mine-none.json +2478 -0
  30. package/lib/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
  31. package/lib/assets/lottie/where-lucy-works-mine-online.json +7881 -0
  32. package/lib/assets/sounds/hours-back.m4a +0 -0
  33. package/lib/assets/sounds/meet-lucy.m4a +0 -0
  34. package/lib/assets/sounds/power-on.m4a +0 -0
  35. package/lib/assets/sounds/wind-back.m4a +0 -0
  36. package/lib/assets/sounds/youre-in.m4a +0 -0
  37. package/lib/chat/agent.js +358 -0
  38. package/lib/chat/agent.js.map +1 -0
  39. package/lib/chat/appFront.js +32 -0
  40. package/lib/chat/appFront.js.map +1 -0
  41. package/lib/chat/auth.js +370 -0
  42. package/lib/chat/auth.js.map +1 -0
  43. package/lib/chat/chores.js +360 -0
  44. package/lib/chat/chores.js.map +1 -0
  45. package/lib/chat/connectors.js +42 -0
  46. package/lib/chat/connectors.js.map +1 -0
  47. package/lib/chat/jobs.js +223 -0
  48. package/lib/chat/jobs.js.map +1 -0
  49. package/lib/chat/lucyMotion.js +6 -0
  50. package/lib/chat/lucyMotion.js.map +1 -0
  51. package/lib/chat/protocol.js +111 -0
  52. package/lib/chat/protocol.js.map +1 -0
  53. package/lib/chat/results.js +133 -0
  54. package/lib/chat/results.js.map +1 -0
  55. package/lib/chat/store.js +81 -0
  56. package/lib/chat/store.js.map +1 -0
  57. package/lib/chat/useDictation.js +168 -0
  58. package/lib/chat/useDictation.js.map +1 -0
  59. package/lib/chat/useLucyChat.js +451 -0
  60. package/lib/chat/useLucyChat.js.map +1 -0
  61. package/lib/chat/useMyComputer.js +32 -0
  62. package/lib/chat/useMyComputer.js.map +1 -0
  63. package/lib/chat/whereLucyWorks.js +52 -0
  64. package/lib/chat/whereLucyWorks.js.map +1 -0
  65. package/lib/chat/workspace.js +124 -0
  66. package/lib/chat/workspace.js.map +1 -0
  67. package/lib/components/AreaShot.js +289 -0
  68. package/lib/components/AreaShot.js.map +1 -0
  69. package/lib/components/Backdrops.js +262 -0
  70. package/lib/components/Backdrops.js.map +1 -0
  71. package/lib/components/BottomSheet.js +61 -0
  72. package/lib/components/BottomSheet.js.map +1 -0
  73. package/lib/components/ChatSheets.js +429 -0
  74. package/lib/components/ChatSheets.js.map +1 -0
  75. package/lib/components/ConnectorLogo.js +91 -0
  76. package/lib/components/ConnectorLogo.js.map +1 -0
  77. package/lib/components/CustomDrawer.js +534 -0
  78. package/lib/components/CustomDrawer.js.map +1 -0
  79. package/lib/components/IdeasPane.js +394 -0
  80. package/lib/components/IdeasPane.js.map +1 -0
  81. package/lib/components/ImessageSheet.js +261 -0
  82. package/lib/components/ImessageSheet.js.map +1 -0
  83. package/lib/components/KeyboardAvoider.js +29 -0
  84. package/lib/components/KeyboardAvoider.js.map +1 -0
  85. package/lib/components/Logo.js +81 -0
  86. package/lib/components/Logo.js.map +1 -0
  87. package/lib/components/LucyWorking.js +67 -0
  88. package/lib/components/LucyWorking.js.map +1 -0
  89. package/lib/components/Markdown.js +260 -0
  90. package/lib/components/Markdown.js.map +1 -0
  91. package/lib/components/Media.js +93 -0
  92. package/lib/components/Media.js.map +1 -0
  93. package/lib/components/MessagesAppIcon.js +23 -0
  94. package/lib/components/MessagesAppIcon.js.map +1 -0
  95. package/lib/components/MicButton.js +71 -0
  96. package/lib/components/MicButton.js.map +1 -0
  97. package/lib/components/ResultCards.js +974 -0
  98. package/lib/components/ResultCards.js.map +1 -0
  99. package/lib/components/SignInPrompt.js +148 -0
  100. package/lib/components/SignInPrompt.js.map +1 -0
  101. package/lib/components/SignedOut.js +38 -0
  102. package/lib/components/SignedOut.js.map +1 -0
  103. package/lib/components/TalkToLucyHero.js +487 -0
  104. package/lib/components/TalkToLucyHero.js.map +1 -0
  105. package/lib/components/TalkToLucySheet.js +182 -0
  106. package/lib/components/TalkToLucySheet.js.map +1 -0
  107. package/lib/components/WhereLucyWorks.js +277 -0
  108. package/lib/components/WhereLucyWorks.js.map +1 -0
  109. package/lib/components/WorkspaceSection.js +271 -0
  110. package/lib/components/WorkspaceSection.js.map +1 -0
  111. package/lib/components/YantraMark.js +13 -0
  112. package/lib/components/YantraMark.js.map +1 -0
  113. package/lib/components/drawerHeader.js +38 -0
  114. package/lib/components/drawerHeader.js.map +1 -0
  115. package/lib/components/lottieInstalled.js +6 -0
  116. package/lib/components/lottieInstalled.js.map +1 -0
  117. package/lib/components/ui.js +550 -0
  118. package/lib/components/ui.js.map +1 -0
  119. package/lib/components/useSignOut.js +7 -0
  120. package/lib/components/useSignOut.js.map +1 -0
  121. package/lib/components/viewport.js +121 -0
  122. package/lib/components/viewport.js.map +1 -0
  123. package/lib/components/voiceDial.js +10 -0
  124. package/lib/components/voiceDial.js.map +1 -0
  125. package/lib/compute.js +157 -0
  126. package/lib/compute.js.map +1 -0
  127. package/lib/config/env-config.js +21 -0
  128. package/lib/config/env-config.js.map +1 -0
  129. package/lib/config/routes.js +15 -0
  130. package/lib/config/routes.js.map +1 -0
  131. package/lib/content.js +25 -0
  132. package/lib/content.js.map +1 -0
  133. package/lib/hooks/keyboardCover.js +39 -0
  134. package/lib/hooks/keyboardCover.js.map +1 -0
  135. package/lib/hooks/useKeyboard.js +121 -0
  136. package/lib/hooks/useKeyboard.js.map +1 -0
  137. package/lib/hooks/useReducedMotion.js +13 -0
  138. package/lib/hooks/useReducedMotion.js.map +1 -0
  139. package/lib/imessage/openMessages.js +25 -0
  140. package/lib/imessage/openMessages.js.map +1 -0
  141. package/lib/imessage/platform.js +12 -0
  142. package/lib/imessage/platform.js.map +1 -0
  143. package/lib/imessage/textLink.js +262 -0
  144. package/lib/imessage/textLink.js.map +1 -0
  145. package/lib/index.js +1 -0
  146. package/lib/index.js.map +1 -0
  147. package/lib/live/card.js +28 -0
  148. package/lib/live/card.js.map +1 -0
  149. package/lib/live/liveActivity.js +144 -0
  150. package/lib/live/liveActivity.js.map +1 -0
  151. package/lib/module.js +3 -0
  152. package/lib/module.js.map +1 -0
  153. package/lib/offer/BlackFridayOffer.js +378 -0
  154. package/lib/offer/BlackFridayOffer.js.map +1 -0
  155. package/lib/offer/blackFriday.js +78 -0
  156. package/lib/offer/blackFriday.js.map +1 -0
  157. package/lib/offer/parts.js +624 -0
  158. package/lib/offer/parts.js.map +1 -0
  159. package/lib/offer/state.js +63 -0
  160. package/lib/offer/state.js.map +1 -0
  161. package/lib/push/push.js +142 -0
  162. package/lib/push/push.js.map +1 -0
  163. package/lib/push/usePushNotifications.js +39 -0
  164. package/lib/push/usePushNotifications.js.map +1 -0
  165. package/lib/routes.json +175 -0
  166. package/lib/screens/Account/index.js +209 -0
  167. package/lib/screens/Account/index.js.map +1 -0
  168. package/lib/screens/Chat/index.js +710 -0
  169. package/lib/screens/Chat/index.js.map +1 -0
  170. package/lib/screens/Chores/index.js +18 -0
  171. package/lib/screens/Chores/index.js.map +1 -0
  172. package/lib/screens/Connectors/index.js +17 -0
  173. package/lib/screens/Connectors/index.js.map +1 -0
  174. package/lib/screens/History/index.js +380 -0
  175. package/lib/screens/History/index.js.map +1 -0
  176. package/lib/screens/Home/index.js +2711 -0
  177. package/lib/screens/Home/index.js.map +1 -0
  178. package/lib/screens/Home/media.js +25 -0
  179. package/lib/screens/Home/media.js.map +1 -0
  180. package/lib/screens/Welcome/index.js +1066 -0
  181. package/lib/screens/Welcome/index.js.map +1 -0
  182. package/lib/talk/talkToLucy.js +139 -0
  183. package/lib/talk/talkToLucy.js.map +1 -0
  184. package/lib/theme/colors.js +29 -0
  185. package/lib/theme/colors.js.map +1 -0
  186. package/lib/theme/fonts.js +17 -0
  187. package/lib/theme/fonts.js.map +1 -0
  188. package/lib/theme/muse.js +134 -0
  189. package/lib/theme/muse.js.map +1 -0
  190. package/lib/utils/links.js +54 -0
  191. package/lib/utils/links.js.map +1 -0
  192. package/lib/utils/yantraLinks.js +68 -0
  193. package/lib/utils/yantraLinks.js.map +1 -0
  194. package/lib/welcome/flow.js +375 -0
  195. package/lib/welcome/flow.js.map +1 -0
  196. package/lib/welcome/haptics.js +125 -0
  197. package/lib/welcome/haptics.js.map +1 -0
  198. package/lib/welcome/parts.js +1996 -0
  199. package/lib/welcome/parts.js.map +1 -0
  200. package/lib/welcome/powerOn.js +29 -0
  201. package/lib/welcome/powerOn.js.map +1 -0
  202. package/lib/welcome/seen.js +41 -0
  203. package/lib/welcome/seen.js.map +1 -0
  204. package/lib/welcome/sound.js +110 -0
  205. package/lib/welcome/sound.js.map +1 -0
  206. package/package.json +66 -5
  207. package/rollup.config.mjs +42 -0
  208. package/src/.claude-flow/data/pending-insights.jsonl +19 -0
  209. package/src/.claude-flow/sessions/session-1795013028422.json +14 -0
  210. package/src/__tests__/auth.test.ts +94 -0
  211. package/src/__tests__/blackFriday.test.ts +75 -0
  212. package/src/__tests__/cardTokens.test.ts +77 -0
  213. package/src/__tests__/chores.test.ts +179 -0
  214. package/src/__tests__/choresList.test.ts +100 -0
  215. package/src/__tests__/content.test.ts +54 -0
  216. package/src/__tests__/dictation.test.ts +186 -0
  217. package/src/__tests__/haptics.test.ts +202 -0
  218. package/src/__tests__/jobs.test.ts +130 -0
  219. package/src/__tests__/keyboardCover.test.ts +84 -0
  220. package/src/__tests__/liveCard.test.ts +39 -0
  221. package/src/__tests__/lockedPhone.test.ts +355 -0
  222. package/src/__tests__/lucyMotion.test.ts +34 -0
  223. package/src/__tests__/platform.test.ts +32 -0
  224. package/src/__tests__/powerOn.test.ts +62 -0
  225. package/src/__tests__/protocol.test.ts +125 -0
  226. package/src/__tests__/push.test.ts +111 -0
  227. package/src/__tests__/results.test.ts +256 -0
  228. package/src/__tests__/sound.test.ts +248 -0
  229. package/src/__tests__/talkToLucy.test.ts +205 -0
  230. package/src/__tests__/textLink.test.ts +91 -0
  231. package/src/__tests__/voiceDial.test.ts +53 -0
  232. package/src/__tests__/welcomeFlow.test.ts +157 -0
  233. package/src/__tests__/whereLucyWorks.test.ts +81 -0
  234. package/src/__tests__/yantraLinks.test.ts +96 -0
  235. package/src/assets/home/loop-day.jpg +0 -0
  236. package/src/assets/home/loop-day.mp4 +0 -0
  237. package/src/assets/home/loop-time-back.jpg +0 -0
  238. package/src/assets/home/loop-time-back.mp4 +0 -0
  239. package/src/assets/home/loop-where.jpg +0 -0
  240. package/src/assets/home/loop-where.mp4 +0 -0
  241. package/src/assets/home/reel-gym.jpg +0 -0
  242. package/src/assets/home/reel-gym.mp4 +0 -0
  243. package/src/assets/home/reel-internet.jpg +0 -0
  244. package/src/assets/home/reel-internet.mp4 +0 -0
  245. package/src/assets/icon.png +0 -0
  246. package/src/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
  247. package/src/assets/lottie/lucy-mark-calendar.json +1827 -0
  248. package/src/assets/lottie/lucy-mark-call.json +1470 -0
  249. package/src/assets/lottie/lucy-mark-connect.json +2552 -0
  250. package/src/assets/lottie/lucy-mark-details.json +1735 -0
  251. package/src/assets/lottie/lucy-mark-email.json +1363 -0
  252. package/src/assets/lottie/lucy-mark-message.json +1154 -0
  253. package/src/assets/lottie/lucy-mark-search.json +1067 -0
  254. package/src/assets/lottie/lucy-mark-think.json +1253 -0
  255. package/src/assets/lottie/lucy-mark-write.json +1532 -0
  256. package/src/assets/lottie/time-back.json +16458 -0
  257. package/src/assets/lottie/where-lucy-works-chat.json +6170 -0
  258. package/src/assets/lottie/where-lucy-works-cloud.json +10066 -0
  259. package/src/assets/lottie/where-lucy-works-mine-none.json +2478 -0
  260. package/src/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
  261. package/src/assets/lottie/where-lucy-works-mine-online.json +7881 -0
  262. package/src/assets/sounds/hours-back.m4a +0 -0
  263. package/src/assets/sounds/meet-lucy.m4a +0 -0
  264. package/src/assets/sounds/power-on.m4a +0 -0
  265. package/src/assets/sounds/wind-back.m4a +0 -0
  266. package/src/assets/sounds/youre-in.m4a +0 -0
  267. package/src/chat/.claude-flow/data/pending-insights.jsonl +1 -0
  268. package/src/chat/agent.ts +376 -0
  269. package/src/chat/appFront.ts +39 -0
  270. package/src/chat/auth.ts +433 -0
  271. package/src/chat/chores.ts +394 -0
  272. package/src/chat/connectors.ts +65 -0
  273. package/src/chat/jobs.ts +228 -0
  274. package/src/chat/lucyMotion.ts +33 -0
  275. package/src/chat/protocol.ts +192 -0
  276. package/src/chat/results.ts +224 -0
  277. package/src/chat/store.ts +87 -0
  278. package/src/chat/useDictation.ts +201 -0
  279. package/src/chat/useLucyChat.ts +458 -0
  280. package/src/chat/useMyComputer.ts +41 -0
  281. package/src/chat/whereLucyWorks.ts +97 -0
  282. package/src/chat/workspace.ts +127 -0
  283. package/src/components/.claude-flow/data/pending-insights.jsonl +3 -0
  284. package/src/components/AreaShot.tsx +239 -0
  285. package/src/components/Backdrops.tsx +323 -0
  286. package/src/components/BottomSheet.tsx +96 -0
  287. package/src/components/ChatSheets.tsx +565 -0
  288. package/src/components/ConnectorLogo.tsx +116 -0
  289. package/src/components/CustomDrawer.tsx +526 -0
  290. package/src/components/IdeasPane.tsx +318 -0
  291. package/src/components/ImessageSheet.tsx +280 -0
  292. package/src/components/KeyboardAvoider.tsx +45 -0
  293. package/src/components/Logo.tsx +97 -0
  294. package/src/components/LucyWorking.tsx +122 -0
  295. package/src/components/Markdown.tsx +219 -0
  296. package/src/components/Media.tsx +173 -0
  297. package/src/components/MessagesAppIcon.tsx +51 -0
  298. package/src/components/MicButton.tsx +92 -0
  299. package/src/components/ResultCards.tsx +1067 -0
  300. package/src/components/SignInPrompt.tsx +182 -0
  301. package/src/components/SignedOut.tsx +47 -0
  302. package/src/components/TalkToLucyHero.tsx +540 -0
  303. package/src/components/TalkToLucySheet.tsx +208 -0
  304. package/src/components/VoiceOrb.tsx +364 -0
  305. package/src/components/WhereLucyWorks.tsx +261 -0
  306. package/src/components/WorkspaceSection.tsx +307 -0
  307. package/src/components/YantraMark.tsx +30 -0
  308. package/src/components/drawerHeader.tsx +46 -0
  309. package/src/components/kit.tsx +309 -0
  310. package/src/components/lottieInstalled.ts +7 -0
  311. package/src/components/ui.tsx +700 -0
  312. package/src/components/useSignOut.ts +21 -0
  313. package/src/components/viewport.tsx +166 -0
  314. package/src/components/voiceDial.ts +45 -0
  315. package/src/compute.ts +168 -0
  316. package/src/config/env-config.ts +37 -0
  317. package/src/config/routes.ts +28 -0
  318. package/src/content.ts +217 -0
  319. package/src/hooks/keyboardCover.ts +70 -0
  320. package/src/hooks/useKeyboard.ts +135 -0
  321. package/src/hooks/useReducedMotion.ts +19 -0
  322. package/src/imessage/openMessages.ts +53 -0
  323. package/src/imessage/platform.ts +32 -0
  324. package/src/imessage/textLink.ts +307 -0
  325. package/src/index.ts +24 -0
  326. package/src/live/card.ts +62 -0
  327. package/src/live/liveActivity.ts +192 -0
  328. package/src/module.ts +8 -0
  329. package/src/offer/BlackFridayOffer.tsx +394 -0
  330. package/src/offer/blackFriday.ts +109 -0
  331. package/src/offer/parts.tsx +650 -0
  332. package/src/offer/state.ts +78 -0
  333. package/src/push/push.ts +171 -0
  334. package/src/push/usePushNotifications.ts +47 -0
  335. package/src/screens/Account/index.tsx +310 -0
  336. package/src/screens/Chat/.claude-flow/data/pending-insights.jsonl +4 -0
  337. package/src/screens/Chat/index.tsx +891 -0
  338. package/src/screens/Chores/index.tsx +35 -0
  339. package/src/screens/Connectors/index.tsx +35 -0
  340. package/src/screens/History/index.tsx +346 -0
  341. package/src/screens/Home/index.tsx +2773 -0
  342. package/src/screens/Home/media.ts +31 -0
  343. package/src/screens/Welcome/index.tsx +1182 -0
  344. package/src/talk/talkToLucy.ts +187 -0
  345. package/src/theme/colors.ts +38 -0
  346. package/src/theme/fonts.ts +30 -0
  347. package/src/theme/muse.ts +86 -0
  348. package/src/utils/links.ts +84 -0
  349. package/src/utils/yantraLinks.ts +94 -0
  350. package/src/welcome/flow.ts +418 -0
  351. package/src/welcome/haptics.ts +179 -0
  352. package/src/welcome/parts.tsx +2160 -0
  353. package/src/welcome/powerOn.ts +84 -0
  354. package/src/welcome/seen.ts +68 -0
  355. package/src/welcome/sound.ts +173 -0
  356. package/tools/lottie/chat.motion +0 -0
  357. package/tools/lottie/cloud.motion +0 -0
  358. package/tools/lottie/generate.mjs +1209 -0
  359. package/tools/lottie/inter-glyphs.json +4416 -0
  360. package/tools/lottie/lucy-mark-calendar.motion +0 -0
  361. package/tools/lottie/lucy-mark-call.motion +0 -0
  362. package/tools/lottie/lucy-mark-connect.motion +0 -0
  363. package/tools/lottie/lucy-mark-details.motion +0 -0
  364. package/tools/lottie/lucy-mark-email.motion +0 -0
  365. package/tools/lottie/lucy-mark-message.motion +0 -0
  366. package/tools/lottie/lucy-mark-search.motion +0 -0
  367. package/tools/lottie/lucy-mark-think.motion +0 -0
  368. package/tools/lottie/lucy-mark-write.motion +0 -0
  369. package/tools/lottie/mark.json +1 -0
  370. package/tools/lottie/mine-none.motion +0 -0
  371. package/tools/lottie/mine-offline.motion +0 -0
  372. package/tools/lottie/mine-online.motion +0 -0
  373. package/tools/lottie/time-back.mjs +604 -0
  374. package/tools/sounds/render.mjs +730 -0
  375. package/tsconfig.json +17 -0
  376. package/README.md +0 -3
@@ -0,0 +1,891 @@
1
+ /**
2
+ * Lucy's chat, native: clockbook.com/#chat (clock-tik-browser pages/Home/chat/ChoresChat.tsx) on a phone, talking to the
3
+ * same agent (chat/agent.ts), in the Muse-style look (theme/muse.ts): no header bar, Lucy's avatar centred with what
4
+ * she is doing under her name, floating Back and "more" buttons, plain bubbles, approval cards for her questions and a
5
+ * floating composer. An empty chat offers Ideas; History keeps past chats on this phone.
6
+ *
7
+ * Opened from Home and the drawer with `prompt` (a chore to send straight away) and `at` (so the same chore twice sends
8
+ * twice). Signed-out people never get here: the sign-in prompt comes first.
9
+ */
10
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
11
+ import { FlatList, Keyboard, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native';
12
+ import { DrawerActions, useIsFocused, useNavigation, useRoute } from '@react-navigation/native';
13
+ import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
14
+ import { Ionicons } from '@expo/vector-icons';
15
+ // The web chat's own starters, read-only from the browser package's build.
16
+ import { CHAT_STARTERS } from '@adminide-stack/clock-tik-browser/lib/pages/Home/content.js';
17
+ import { AuthMobileNavigationRoutesEnum } from '@adminide-stack/user-auth0-client';
18
+ import { LucyWorking } from '../../components/LucyWorking';
19
+ import { BottomSheet } from '../../components/BottomSheet';
20
+ import { KeyboardAvoider } from '../../components/KeyboardAvoider';
21
+ import { ConnectorStack } from '../../components/ConnectorLogo';
22
+ import { Markdown } from '../../components/Markdown';
23
+ import { WhereLucyWorks } from '../../components/WhereLucyWorks';
24
+ import { ImessageSheet } from '../../components/ImessageSheet';
25
+ import { MessagesAppIcon } from '../../components/MessagesAppIcon';
26
+ import { ChoresPane, ConnectorsPane, HelpSheet, Sheet, useChoreCount } from '../../components/ChatSheets';
27
+ import { IdeasPane } from '../../components/IdeasPane';
28
+ import {
29
+ Bubble,
30
+ Button,
31
+ FloatingButton,
32
+ Group,
33
+ GroupLabel,
34
+ GroupRow,
35
+ IdeaRow,
36
+ LargeTitle,
37
+ HeaderCapsule,
38
+ LucyBadge,
39
+ TabBar,
40
+ type IconName,
41
+ type TabItem,
42
+ } from '../../components/ui';
43
+ import { motionFor } from '../../chat/lucyMotion';
44
+ import { pendingAsk, useLucyChat } from '../../chat/useLucyChat';
45
+ import { useMyComputer } from '../../chat/useMyComputer';
46
+ import { useDictation } from '../../chat/useDictation';
47
+ import { dictationProblem, MicButton } from '../../components/MicButton';
48
+ import { displayText, formatAskAnswers, type AskAnswer, type AskUser } from '../../chat/protocol';
49
+ import { laterWords, takeResults } from '../../chat/results';
50
+ import { ResultCards } from '../../components/ResultCards';
51
+ import type { ChatMessage } from '../../chat/store';
52
+ import { PROMPT_MAX, yantraAppUrl } from '../../utils/links';
53
+ import { TEXT_LUCY } from '../../imessage/platform';
54
+ import { CLOCKBOOK_ROUTES } from '../../config/routes';
55
+ import { useClockbookFonts } from '../../theme/fonts';
56
+ import { setChatOnScreen } from '../../push/push';
57
+ import { field, float, lift, PAD, radius, type, ui } from '../../theme/muse';
58
+
59
+ function greeting(now = new Date()): string {
60
+ const h = now.getHours();
61
+ if (h < 5) return 'Up late';
62
+ if (h < 12) return 'Good morning';
63
+ if (h < 17) return 'Good afternoon';
64
+ if (h < 21) return 'Good evening';
65
+ return 'Working late';
66
+ }
67
+
68
+ /** An emoji for each starter, as Muse's Ideas show one per row. */
69
+ function starterEmoji(label: string): string {
70
+ const l = label.toLowerCase();
71
+ if (l.includes('reschedule')) return '📞';
72
+ if (l.includes('schedule') || l.includes('book')) return '📅';
73
+ if (l.includes('remind')) return '⏰';
74
+ if (l.includes('bill') || l.includes('internet')) return '💸';
75
+ if (l.includes('cancel')) return '✂️';
76
+ return '✨';
77
+ }
78
+
79
+ /* ------------------------------------------------------------------------------------------------ pieces */
80
+
81
+ /**
82
+ * One of the two ways on, as the web chat's pills: icons, a label (with a quieter lead-in), and an arrow. They stand
83
+ * apart, one above the other, rather than sharing a card.
84
+ */
85
+ function WayPill({
86
+ leading,
87
+ lead,
88
+ label,
89
+ onPress,
90
+ }: {
91
+ leading: React.ReactNode;
92
+ lead?: string;
93
+ label: string;
94
+ onPress: () => void;
95
+ }) {
96
+ return (
97
+ <Pressable
98
+ accessibilityRole="button"
99
+ accessibilityLabel={lead ? `${lead} ${label}` : label}
100
+ onPress={onPress}
101
+ style={({ pressed }) => [c.way, pressed && { backgroundColor: ui.fill }]}
102
+ >
103
+ {leading}
104
+ {/* One line: on a narrow phone it shrinks a touch rather than cut "iMessage" short. */}
105
+ <Text style={c.wayText} numberOfLines={1} adjustsFontSizeToFit minimumFontScale={0.85}>
106
+ {lead ? <Text style={c.wayLead}>{lead} </Text> : null}
107
+ {label}
108
+ </Text>
109
+ <Ionicons name="arrow-forward" size={17} color={ui.ink} />
110
+ </Pressable>
111
+ );
112
+ }
113
+
114
+ function Empty({
115
+ onStart,
116
+ onText,
117
+ onConnect,
118
+ }: {
119
+ onStart: (prompt: string) => void;
120
+ onText: () => void;
121
+ onConnect: () => void;
122
+ }) {
123
+ const computer = useMyComputer();
124
+ return (
125
+ <ScrollView contentContainerStyle={c.empty} keyboardShouldPersistTaps="handled">
126
+ <View style={c.hello}>
127
+ <Text style={type.subhead}>{greeting()}</Text>
128
+ <Text style={[type.largeTitle, { marginTop: 4 }]} accessibilityRole="header">
129
+ What should Lucy take off your <Text style={{ color: ui.accentText }}>plate?</Text>
130
+ </Text>
131
+ <Text style={[type.callout, { marginTop: 8 }]}>
132
+ She makes the calls, books the time and keeps track. You approve what matters.
133
+ </Text>
134
+ </View>
135
+
136
+ <View style={c.where}>
137
+ <WhereLucyWorks computer={computer} desktopLink={yantraAppUrl()} />
138
+ </View>
139
+
140
+ <GroupLabel>Try one of these</GroupLabel>
141
+ {CHAT_STARTERS.map((st: { label: string; prompt: string }, i: number) => (
142
+ <IdeaRow
143
+ key={st.label}
144
+ emoji={starterEmoji(st.label)}
145
+ title={st.label}
146
+ body={st.prompt}
147
+ onPress={() => onStart(st.prompt)}
148
+ last={i === CHAT_STARTERS.length - 1}
149
+ />
150
+ ))}
151
+
152
+ <View style={c.ways}>
153
+ <WayPill
154
+ leading={<ConnectorStack ids={['google-calendar', 'google-gmail', 'site-login']} />}
155
+ label="Connect your apps"
156
+ onPress={onConnect}
157
+ />
158
+ <WayPill
159
+ leading={<MessagesAppIcon size={26} />}
160
+ lead="Prefer texting?"
161
+ label={TEXT_LUCY}
162
+ onPress={onText}
163
+ />
164
+ </View>
165
+ </ScrollView>
166
+ );
167
+ }
168
+
169
+ type Tab = 'chat' | 'ideas' | 'chores' | 'apps';
170
+
171
+ /**
172
+ * Lucy's question, as Muse's approval card: a raised card with what she is asking and the answers as buttons. One
173
+ * question with one choice sends on the tap; several (or a typed answer) send with the primary button.
174
+ */
175
+ function AskCard({ ask, onAnswer, disabled }: { ask: AskUser; onAnswer: (text: string) => void; disabled?: boolean }) {
176
+ const [answers, setAnswers] = useState<Record<string, AskAnswer>>({});
177
+ const get = (id: string): AskAnswer => answers[id] ?? { picked: [], text: '' };
178
+ const set = (id: string, a: AskAnswer) => setAnswers((prev) => ({ ...prev, [id]: a }));
179
+ const message = formatAskAnswers(ask, answers);
180
+ const single = ask.questions.length === 1 && !ask.questions[0].multiSelect;
181
+
182
+ return (
183
+ <View style={c.ask}>
184
+ {ask.questions.map((q) => {
185
+ const a = get(q.id);
186
+ return (
187
+ <View key={q.id} style={{ gap: 12 }}>
188
+ <View style={c.askHead}>
189
+ <View style={c.askIcon}>
190
+ <Ionicons name="help-circle-outline" size={20} color={ui.accentText} />
191
+ </View>
192
+ <View style={{ flex: 1 }}>
193
+ {q.header ? <Text style={type.caption}>{q.header}</Text> : null}
194
+ <Text style={type.headline}>{q.title}</Text>
195
+ </View>
196
+ </View>
197
+ <View style={{ gap: 8 }}>
198
+ {q.options.map((o) => {
199
+ const on = a.picked.includes(o.label);
200
+ return (
201
+ <Pressable
202
+ key={o.id}
203
+ disabled={disabled}
204
+ accessibilityRole={q.multiSelect ? 'checkbox' : 'radio'}
205
+ accessibilityState={{ checked: on, disabled }}
206
+ onPress={() => {
207
+ if (single) {
208
+ // One question, one choice: the tap is the answer.
209
+ onAnswer(
210
+ formatAskAnswers(ask, { [q.id]: { picked: [o.label], text: '' } }),
211
+ );
212
+ return;
213
+ }
214
+ const picked = q.multiSelect
215
+ ? on
216
+ ? a.picked.filter((p) => p !== o.label)
217
+ : [...a.picked, o.label]
218
+ : [o.label];
219
+ set(q.id, { ...a, picked });
220
+ }}
221
+ style={({ pressed }) => [
222
+ c.option,
223
+ on && c.optionOn,
224
+ pressed && { backgroundColor: on ? ui.accentSoft : '#E5E2DD' },
225
+ ]}
226
+ >
227
+ <View style={{ flex: 1 }}>
228
+ <Text style={[c.optionLabel, on && { color: ui.accentText }]}>
229
+ {o.label}
230
+ </Text>
231
+ {o.detail ? (
232
+ <Text style={[type.footnote, { marginTop: 2 }]}>{o.detail}</Text>
233
+ ) : null}
234
+ </View>
235
+ {single ? null : (
236
+ <Ionicons
237
+ name={on ? 'checkmark-circle' : 'ellipse-outline'}
238
+ size={21}
239
+ color={on ? ui.accent : ui.faint}
240
+ />
241
+ )}
242
+ </Pressable>
243
+ );
244
+ })}
245
+ </View>
246
+ {q.allowText ? (
247
+ <TextInput
248
+ editable={!disabled}
249
+ value={a.text}
250
+ onChangeText={(text) => set(q.id, { ...a, text })}
251
+ placeholder={
252
+ q.textPlaceholder ||
253
+ (q.options.length ? 'Or type your own answer' : 'Type your answer')
254
+ }
255
+ placeholderTextColor={ui.faint}
256
+ style={c.askInput}
257
+ multiline
258
+ />
259
+ ) : null}
260
+ </View>
261
+ );
262
+ })}
263
+ {!single || ask.questions[0].allowText ? (
264
+ <Button
265
+ label="Send answer"
266
+ icon="arrow-up"
267
+ disabled={disabled || !message}
268
+ onPress={() => onAnswer(message)}
269
+ />
270
+ ) : null}
271
+ </View>
272
+ );
273
+ }
274
+
275
+ interface RowProps {
276
+ m: ChatMessage;
277
+ /** Its place in the thread, and the thread: a result card's pick is read from what was sent after it. */
278
+ index: number;
279
+ thread: ChatMessage[];
280
+ last: boolean;
281
+ activity: string | null;
282
+ streaming: boolean;
283
+ onRetry: () => void;
284
+ /** Answers Lucy from one of her result cards, as if typed. */
285
+ onReply: (words: string) => void;
286
+ }
287
+
288
+ /** No words sent after a reply yet: one shared empty list, so its cards are not drawn again for nothing. */
289
+ const NO_WORDS: string[] = [];
290
+
291
+ function MessageRow(props: RowProps) {
292
+ if (props.m.role === 'user') {
293
+ return <Bubble from="you">{props.m.content.replace(/\*\*([^*]+)\*\*/g, '$1')}</Bubble>;
294
+ }
295
+ return <LucyRow {...props} />;
296
+ }
297
+
298
+ /** Lucy's reply: her words, her flights or products as cards (components/ResultCards.tsx), then how she is getting on. */
299
+ function LucyRow({ m, index, thread, last, activity, streaming, onRetry, onReply }: RowProps) {
300
+ const taken = useMemo(() => takeResults(m.content, m.id), [m.content, m.id]);
301
+ const text = displayText(taken.content);
302
+ const later = useMemo(
303
+ () => (taken.cards.length ? laterWords(thread, index) : NO_WORDS),
304
+ [taken.cards.length, thread, index],
305
+ );
306
+ const working = last && streaming;
307
+ const words = activity ?? 'Writing';
308
+ return (
309
+ <View style={{ gap: 8 }}>
310
+ {text ? (
311
+ <Bubble from="lucy">
312
+ <Markdown>{text}</Markdown>
313
+ </Bubble>
314
+ ) : null}
315
+ {taken.cards.length ? (
316
+ <ResultCards cards={taken.cards} later={later} busy={streaming} onReply={onReply} />
317
+ ) : null}
318
+ {working ? (
319
+ <View style={c.workingRow} accessible accessibilityLabel={activity ?? 'Lucy is writing'}>
320
+ <LucyWorking size={24} motion={motionFor(words)} />
321
+ {activity ? (
322
+ <Text style={type.footnote} numberOfLines={1}>
323
+ {activity}
324
+ </Text>
325
+ ) : null}
326
+ </View>
327
+ ) : null}
328
+ {m.error ? (
329
+ <View style={c.error}>
330
+ <Ionicons name="alert-circle-outline" size={18} color={ui.danger} />
331
+ <Text style={c.errorText}>{m.error}</Text>
332
+ {last ? (
333
+ <Pressable accessibilityRole="button" onPress={onRetry} hitSlop={6}>
334
+ <Text style={c.errorRetry}>Try again</Text>
335
+ </Pressable>
336
+ ) : null}
337
+ </View>
338
+ ) : null}
339
+ </View>
340
+ );
341
+ }
342
+
343
+ /** The floating composer: the message, then send (or Stop while Lucy replies with nothing typed). */
344
+ function Composer({
345
+ streaming,
346
+ onSend,
347
+ onStop,
348
+ onPlus,
349
+ draft,
350
+ }: {
351
+ streaming: boolean;
352
+ onSend: (t: string) => void;
353
+ onStop: () => void;
354
+ onPlus: () => void;
355
+ /** Text put in the box from outside (an idea to change first); `at` makes the same text twice land twice. */
356
+ draft?: { text: string; at: number } | null;
357
+ }) {
358
+ const [text, setText] = useState('');
359
+ const ready = text.trim().length > 0;
360
+ const input = useRef<TextInput>(null);
361
+ useEffect(() => {
362
+ if (!draft) return;
363
+ setText(draft.text);
364
+ // Let the box mount (the tab just changed) before the keyboard comes up.
365
+ const t = setTimeout(() => input.current?.focus(), 250);
366
+ return () => clearTimeout(t);
367
+ }, [draft]);
368
+ // A build without the speech module: the keyboard's own dictation mic does the same job, so open it.
369
+ const [keyboardHint, setKeyboardHint] = useState(false);
370
+ const dictation = useDictation({
371
+ onText: setText,
372
+ onProblem: (problem, detail) => {
373
+ if (problem === 'unavailable') {
374
+ setKeyboardHint(true);
375
+ input.current?.focus();
376
+ return;
377
+ }
378
+ dictationProblem(problem, detail);
379
+ },
380
+ });
381
+ const send = () => {
382
+ if (!ready) return;
383
+ // Sent while listening: end it without keeping what is still to come, or the words come back into the box.
384
+ if (dictation.listening) dictation.cancel();
385
+ onSend(text);
386
+ setText('');
387
+ };
388
+ const mic = () => (dictation.listening ? dictation.stop() : dictation.start(text));
389
+ return (
390
+ <View style={c.dock}>
391
+ <View style={c.composer}>
392
+ <Pressable
393
+ accessibilityRole="button"
394
+ accessibilityLabel="More ways to hand over"
395
+ onPress={onPlus}
396
+ hitSlop={6}
397
+ style={({ pressed }) => [c.plus, pressed && { backgroundColor: ui.bubbleYou }]}
398
+ >
399
+ <Ionicons name="add" size={22} color={ui.ink} />
400
+ </Pressable>
401
+ <TextInput
402
+ ref={input}
403
+ value={text}
404
+ onChangeText={setText}
405
+ onBlur={() => setKeyboardHint(false)}
406
+ maxLength={PROMPT_MAX * 4}
407
+ placeholder={dictation.listening ? 'Listening…' : 'Message Lucy'}
408
+ placeholderTextColor={dictation.listening ? ui.accentText : ui.faint}
409
+ style={c.input}
410
+ multiline
411
+ accessibilityLabel="Message Lucy"
412
+ />
413
+ {/* Muse's mic: there when there is nothing to send yet, or while listening. */}
414
+ {!ready || dictation.listening ? <MicButton listening={dictation.listening} onPress={mic} /> : null}
415
+ {streaming && !ready ? (
416
+ <Pressable
417
+ accessibilityRole="button"
418
+ accessibilityLabel="Stop Lucy"
419
+ onPress={onStop}
420
+ hitSlop={8}
421
+ style={[c.send, { backgroundColor: ui.ink }]}
422
+ >
423
+ <Ionicons name="stop" size={15} color={ui.surface} />
424
+ </Pressable>
425
+ ) : !ready ? null : (
426
+ <Pressable
427
+ accessibilityRole="button"
428
+ accessibilityLabel={streaming ? 'Send after this reply' : 'Send'}
429
+ accessibilityState={{ disabled: !ready }}
430
+ disabled={!ready}
431
+ onPress={send}
432
+ hitSlop={8}
433
+ style={({ pressed }) => [
434
+ c.send,
435
+ { backgroundColor: ready ? (pressed ? ui.accentPressed : ui.accent) : ui.fill },
436
+ ]}
437
+ >
438
+ <Ionicons name="arrow-up" size={19} color={ready ? ui.surface : ui.faint} />
439
+ </Pressable>
440
+ )}
441
+ </View>
442
+ <Text style={[type.caption, c.dockNote, keyboardHint && { color: ui.accentText }]}>
443
+ {keyboardHint
444
+ ? 'Tap the mic on your keyboard to speak.'
445
+ : 'Lucy asks before she pays or changes an account.'}
446
+ </Text>
447
+ </View>
448
+ );
449
+ }
450
+
451
+ function MoreMenu({
452
+ visible,
453
+ onClose,
454
+ onText,
455
+ onConnect,
456
+ onHelp,
457
+ }: {
458
+ visible: boolean;
459
+ onClose: () => void;
460
+ onText: () => void;
461
+ onConnect: () => void;
462
+ onHelp: () => void;
463
+ }) {
464
+ const insets = useSafeAreaInsets();
465
+ const rows: ReadonlyArray<{ icon?: IconName; leading?: React.ReactNode; label: string; on: () => void }> = [
466
+ {
467
+ leading: (
468
+ <View style={{ marginRight: 12 }}>
469
+ <MessagesAppIcon size={30} />
470
+ </View>
471
+ ),
472
+ label: TEXT_LUCY,
473
+ on: onText,
474
+ },
475
+ { icon: 'apps-outline', label: 'Connect your apps', on: onConnect },
476
+ { icon: 'help-circle-outline', label: 'How Lucy works', on: onHelp },
477
+ ];
478
+ return (
479
+ <BottomSheet
480
+ visible={visible}
481
+ onClose={onClose}
482
+ style={[c.menu, { paddingBottom: Math.max(insets.bottom, 12) }]}
483
+ >
484
+ <View style={c.grabber} />
485
+ <Group style={{ marginHorizontal: 0 }}>
486
+ {rows.map((r, i) => (
487
+ <GroupRow
488
+ key={r.label}
489
+ icon={r.icon}
490
+ leading={r.leading}
491
+ label={r.label}
492
+ onPress={r.on}
493
+ last={i === rows.length - 1}
494
+ />
495
+ ))}
496
+ </Group>
497
+ <Button label="Cancel" variant="secondary" onPress={onClose} style={{ marginTop: 10 }} />
498
+ </BottomSheet>
499
+ );
500
+ }
501
+
502
+ /* ------------------------------------------------------------------------------------------------ screen */
503
+
504
+ export default function ChatScreen() {
505
+ // Not a gate: only the "Where Lucy works" card still draws in the web's fonts; everything else is the system font.
506
+ useClockbookFonts();
507
+ const navigation = useNavigation<{
508
+ navigate: (r: string, p?: object) => void;
509
+ dispatch: (action: object) => void;
510
+ }>();
511
+ const route = useRoute<{
512
+ key: string;
513
+ name: string;
514
+ params?: { prompt?: string; open?: string; fresh?: number; at?: number };
515
+ }>();
516
+ const insets = useSafeAreaInsets();
517
+ const chat = useLucyChat(true);
518
+ const [imessageOpen, setImessageOpen] = useState(false);
519
+ const [menuOpen, setMenuOpen] = useState(false);
520
+ const [helpOpen, setHelpOpen] = useState(false);
521
+ // Muse's tabs: the chat, Ideas, Lucy's chores and the apps she can use.
522
+ const [tab, setTab] = useState<Tab>('chat');
523
+ const choreCount = useChoreCount(chat.phase === 'ready');
524
+ // Lucy's "done" notifications stay quiet while her chat is what the person is looking at: the reply is right here.
525
+ const focused = useIsFocused();
526
+ useEffect(() => {
527
+ setChatOnScreen(focused && tab === 'chat');
528
+ return () => setChatOnScreen(false);
529
+ }, [focused, tab]);
530
+ // The tab bar steps aside while typing, so the keyboard has the room.
531
+ const [typing, setTyping] = useState(false);
532
+ useEffect(() => {
533
+ const show = Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', () =>
534
+ setTyping(true),
535
+ );
536
+ const hide = Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', () =>
537
+ setTyping(false),
538
+ );
539
+ return () => {
540
+ show.remove();
541
+ hide.remove();
542
+ };
543
+ }, []);
544
+ const tabs: TabItem<Tab>[] = [
545
+ { key: 'chat', icon: 'chatbubble-outline', iconOn: 'chatbubble', label: 'Chat' },
546
+ { key: 'ideas', icon: 'bulb-outline', iconOn: 'bulb', label: 'Ideas' },
547
+ {
548
+ key: 'chores',
549
+ icon: 'checkbox-outline',
550
+ iconOn: 'checkbox',
551
+ label: 'Chores',
552
+ badge: choreCount.working || undefined,
553
+ },
554
+ { key: 'apps', icon: 'apps-outline', iconOn: 'apps', label: 'Apps' },
555
+ ];
556
+ const [draft, setDraft] = useState<{ text: string; at: number } | null>(null);
557
+ const editIdea = (prompt: string) => {
558
+ setTab('chat');
559
+ setDraft({ text: prompt, at: Date.now() });
560
+ };
561
+ const startIdea = (prompt: string) => {
562
+ setTab('chat');
563
+ chat.send(prompt);
564
+ };
565
+ // Room under a pane for the floating tab bar.
566
+ const paneBottom = 96 + insets.bottom;
567
+ const list = useRef<FlatList<ChatMessage>>(null);
568
+ const sentAt = useRef<number | null>(null);
569
+
570
+ // A chore handed over from Home: send it once the chat is ready (and only once per hand-over).
571
+ const { prompt, open, fresh, at } = route.params ?? {};
572
+ useEffect(() => {
573
+ if (chat.phase !== 'ready' || !prompt || !at || sentAt.current === at) return;
574
+ sentAt.current = at;
575
+ chat.send(prompt);
576
+ }, [chat.phase, prompt, at, chat]);
577
+ // A past chat picked on the History screen: open it here (once per pick).
578
+ const openedAt = useRef<number | null>(null);
579
+ useEffect(() => {
580
+ if (chat.phase !== 'ready' || !open || !at || openedAt.current === at) return;
581
+ openedAt.current = at;
582
+ setTab('chat');
583
+ chat.openChat(open);
584
+ }, [chat.phase, open, at, chat]);
585
+
586
+ // New chat, from the drawer: start one here (once per tap).
587
+ const freshAt = useRef<number | null>(null);
588
+ useEffect(() => {
589
+ if (chat.phase !== 'ready' || !fresh || freshAt.current === fresh) return;
590
+ freshAt.current = fresh;
591
+ setTab('chat');
592
+ chat.newChat();
593
+ }, [chat.phase, fresh, chat]);
594
+
595
+ // Lucy's question card: shown as soon as her reply holds a whole one (her run waits on it, stream open or not).
596
+ const ask = useMemo(() => pendingAsk(chat.messages), [chat.messages]);
597
+ const lastId = chat.messages[chat.messages.length - 1]?.id;
598
+
599
+ // A drawer screen, as Home: the menu button opens the drawer.
600
+ const openMenu = () => navigation.dispatch(DrawerActions.openDrawer());
601
+ // iOS won't present a sheet while the menu is still closing: let the menu go first.
602
+ const fromMenu = (open: () => void) => {
603
+ setMenuOpen(false);
604
+ setTimeout(open, 350);
605
+ };
606
+ const status = chat.streaming ? (chat.activity ?? 'Writing…') : chat.phase === 'connecting' ? 'Connecting…' : null;
607
+
608
+ return (
609
+ <SafeAreaView style={c.page} edges={['top', 'left', 'right']}>
610
+ <View style={c.header}>
611
+ <View style={c.headerSide}>
612
+ <FloatingButton icon="menu" label="Menu" onPress={openMenu} />
613
+ </View>
614
+ <LucyBadge status={tab === 'chat' ? status : null} />
615
+ <View style={[c.headerSide, { alignItems: 'flex-end' }]}>
616
+ <HeaderCapsule
617
+ actions={[
618
+ {
619
+ node: <MessagesAppIcon size={24} />,
620
+ label: TEXT_LUCY,
621
+ onPress: () => setImessageOpen(true),
622
+ },
623
+ {
624
+ icon: 'time-outline',
625
+ label: 'History',
626
+ onPress: () => navigation.navigate(CLOCKBOOK_ROUTES.HISTORY),
627
+ },
628
+ {
629
+ icon: 'create-outline',
630
+ label: 'New chat',
631
+ onPress: () => {
632
+ setTab('chat');
633
+ chat.newChat();
634
+ },
635
+ },
636
+ ]}
637
+ />
638
+ </View>
639
+ </View>
640
+
641
+ {/* Measured on the screen, on both platforms: the composer stays above the keyboard under this header. */}
642
+ <KeyboardAvoider style={{ flex: 1 }}>
643
+ {tab === 'ideas' ? (
644
+ <IdeasPane onSend={startIdea} onEdit={editIdea} bottom={paneBottom} />
645
+ ) : tab === 'chores' ? (
646
+ <ChoresPane active header={<LargeTitle>Chores</LargeTitle>} bottom={paneBottom} />
647
+ ) : tab === 'apps' ? (
648
+ <ConnectorsPane header={<LargeTitle>Apps</LargeTitle>} bottom={paneBottom} />
649
+ ) : chat.phase === 'connecting' ? (
650
+ <View style={c.center}>
651
+ <LucyWorking size={72} motion="connect" />
652
+ <Text style={c.centerText}>Connecting to Lucy…</Text>
653
+ </View>
654
+ ) : chat.phase === 'unavailable' ? (
655
+ <View style={c.center}>
656
+ <Text style={[type.title, { textAlign: 'center' }]}>Lucy can’t chat right now</Text>
657
+ <Text style={c.centerText}>{chat.problem}</Text>
658
+ <Button label="Try again" icon="refresh" onPress={chat.reconnect} />
659
+ </View>
660
+ ) : chat.messages.length === 0 ? (
661
+ <Empty onStart={chat.send} onText={() => setImessageOpen(true)} onConnect={() => setTab('apps')} />
662
+ ) : (
663
+ <FlatList
664
+ ref={list}
665
+ data={chat.messages}
666
+ keyExtractor={(m) => m.id}
667
+ contentContainerStyle={c.thread}
668
+ keyboardShouldPersistTaps="handled"
669
+ keyboardDismissMode="interactive"
670
+ onContentSizeChange={() => list.current?.scrollToEnd({ animated: true })}
671
+ renderItem={({ item, index }) => (
672
+ <MessageRow
673
+ m={item}
674
+ index={index}
675
+ thread={chat.messages}
676
+ last={index === chat.messages.length - 1}
677
+ activity={chat.activity}
678
+ streaming={chat.streaming}
679
+ onRetry={chat.retryLast}
680
+ onReply={chat.send}
681
+ />
682
+ )}
683
+ ListFooterComponent={
684
+ <View style={{ gap: 12 }}>
685
+ {ask ? <AskCard key={lastId} ask={ask} onAnswer={chat.answer} /> : null}
686
+ {chat.queued.map((q) => (
687
+ <View key={q} style={{ alignItems: 'flex-end', opacity: 0.55 }}>
688
+ <Bubble from="you">{q}</Bubble>
689
+ <Text style={[type.caption, { marginTop: 4 }]}>Sends after this reply</Text>
690
+ </View>
691
+ ))}
692
+ </View>
693
+ }
694
+ />
695
+ )}
696
+ {tab === 'chat' && chat.phase === 'ready' ? (
697
+ <Composer
698
+ streaming={chat.streaming}
699
+ onSend={chat.send}
700
+ onStop={chat.stop}
701
+ onPlus={() => setMenuOpen(true)}
702
+ draft={draft}
703
+ />
704
+ ) : null}
705
+ {typing ? (
706
+ <View style={{ height: 8 }} />
707
+ ) : (
708
+ <View style={[c.tabDock, { paddingBottom: Math.max(insets.bottom, 10) }]}>
709
+ <TabBar
710
+ tabs={tabs}
711
+ value={tab}
712
+ onChange={(k) => {
713
+ setTab(k);
714
+ if (k === 'chores') choreCount.refresh();
715
+ }}
716
+ />
717
+ </View>
718
+ )}
719
+ </KeyboardAvoider>
720
+
721
+ <MoreMenu
722
+ visible={menuOpen}
723
+ onClose={() => setMenuOpen(false)}
724
+ onText={() => fromMenu(() => setImessageOpen(true))}
725
+ onConnect={() => {
726
+ setMenuOpen(false);
727
+ setTab('apps');
728
+ }}
729
+ onHelp={() => fromMenu(() => setHelpOpen(true))}
730
+ />
731
+ <HelpSheet visible={helpOpen} onClose={() => setHelpOpen(false)} />
732
+ <ImessageSheet
733
+ visible={imessageOpen}
734
+ onClose={() => setImessageOpen(false)}
735
+ onChatHere={() => setImessageOpen(false)}
736
+ onSignIn={() => {
737
+ setImessageOpen(false);
738
+ navigation.navigate(AuthMobileNavigationRoutesEnum.Login, { redirect: 'back' });
739
+ }}
740
+ />
741
+ </SafeAreaView>
742
+ );
743
+ }
744
+
745
+ /* ------------------------------------------------------------------------------------------------ styles */
746
+
747
+ const c = StyleSheet.create({
748
+ page: { flex: 1, backgroundColor: ui.bg },
749
+ header: {
750
+ flexDirection: 'row',
751
+ alignItems: 'center',
752
+ justifyContent: 'space-between',
753
+ // The menu button sits exactly where the drawer screens' header puts it (Home, Chores, Connectors): PAD in from
754
+ // the edge, centred in the navigation bar's height (44 on iOS, 64 on Android) for its 38pt button.
755
+ paddingHorizontal: PAD,
756
+ paddingTop: Platform.OS === 'android' ? 13 : 3,
757
+ paddingBottom: 8,
758
+ },
759
+ // Both sides as wide as the three-icon capsule, so Lucy stays centred.
760
+ headerSide: { width: 116 },
761
+
762
+ // empty
763
+ empty: { paddingTop: 8, paddingBottom: 20 },
764
+ where: { paddingHorizontal: PAD, marginTop: 18 },
765
+ hello: { paddingHorizontal: PAD + 4 },
766
+ ideasTitle: { paddingHorizontal: PAD + 4, marginTop: 28, marginBottom: 2 },
767
+ ways: { paddingHorizontal: PAD, marginTop: 22, gap: 10 },
768
+ way: {
769
+ flexDirection: 'row',
770
+ alignItems: 'center',
771
+ gap: 10,
772
+ minHeight: 52,
773
+ paddingLeft: 12,
774
+ paddingRight: 16,
775
+ borderRadius: radius.pill,
776
+ backgroundColor: ui.surface,
777
+ borderWidth: StyleSheet.hairlineWidth,
778
+ borderColor: ui.hairline,
779
+ ...lift,
780
+ },
781
+ wayText: { flex: 1, fontSize: 15.5, fontWeight: '600', color: ui.ink },
782
+ wayLead: { fontWeight: '400', color: ui.muted },
783
+
784
+ // thread
785
+ thread: { paddingHorizontal: PAD, paddingTop: 12, paddingBottom: 16, gap: 12 },
786
+ workingRow: { flexDirection: 'row', alignItems: 'center', gap: 10 },
787
+ error: {
788
+ flexDirection: 'row',
789
+ alignItems: 'center',
790
+ flexWrap: 'wrap',
791
+ gap: 8,
792
+ padding: 12,
793
+ borderRadius: radius.button,
794
+ backgroundColor: ui.dangerSoft,
795
+ },
796
+ errorText: { flex: 1, fontSize: 14, lineHeight: 20, color: '#7A271A' },
797
+ errorRetry: { fontSize: 14, fontWeight: '600', color: ui.danger },
798
+
799
+ // ask (approval) card
800
+ ask: { padding: 16, gap: 16, borderRadius: radius.card, backgroundColor: ui.surface, ...lift },
801
+ askHead: { flexDirection: 'row', alignItems: 'flex-start', gap: 12 },
802
+ askIcon: {
803
+ width: 34,
804
+ height: 34,
805
+ borderRadius: 10,
806
+ backgroundColor: ui.accentSoft,
807
+ alignItems: 'center',
808
+ justifyContent: 'center',
809
+ },
810
+ option: {
811
+ flexDirection: 'row',
812
+ alignItems: 'center',
813
+ gap: 10,
814
+ minHeight: 48,
815
+ paddingVertical: 12,
816
+ paddingHorizontal: 16,
817
+ borderRadius: radius.button,
818
+ backgroundColor: ui.fill,
819
+ borderWidth: 1,
820
+ borderColor: 'transparent',
821
+ },
822
+ optionOn: { borderColor: ui.accent, backgroundColor: ui.accentSoft },
823
+ optionLabel: { fontSize: 16, fontWeight: '500', color: ui.ink },
824
+ askInput: {
825
+ fontSize: 16,
826
+ color: ui.ink,
827
+ minHeight: 46,
828
+ paddingHorizontal: 14,
829
+ paddingVertical: 12,
830
+ borderRadius: radius.button,
831
+ backgroundColor: ui.fill,
832
+ },
833
+
834
+ // states
835
+ center: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 14, paddingHorizontal: 32 },
836
+ centerText: { ...type.callout, color: ui.muted, textAlign: 'center' },
837
+
838
+ // composer
839
+ dock: { paddingHorizontal: PAD - 4, paddingTop: 6 },
840
+ tabDock: { paddingHorizontal: PAD + 8, paddingTop: 10 },
841
+ plus: {
842
+ width: 38,
843
+ height: 38,
844
+ borderRadius: 19,
845
+ backgroundColor: ui.accentSoft,
846
+ alignItems: 'center',
847
+ justifyContent: 'center',
848
+ },
849
+ composer: {
850
+ flexDirection: 'row',
851
+ alignItems: 'flex-end',
852
+ gap: 8,
853
+ minHeight: 52,
854
+ paddingLeft: 7,
855
+ paddingRight: 7,
856
+ paddingVertical: 7,
857
+ borderRadius: 28,
858
+ backgroundColor: ui.surface,
859
+ ...float,
860
+ },
861
+ input: {
862
+ flex: 1,
863
+ fontSize: 15.5,
864
+ lineHeight: 20,
865
+ color: ui.ink,
866
+ maxHeight: 130,
867
+ minHeight: 38,
868
+ paddingTop: 9,
869
+ paddingBottom: 9,
870
+ ...field,
871
+ },
872
+ send: { width: 38, height: 38, borderRadius: 19, alignItems: 'center', justifyContent: 'center' },
873
+ dockNote: { textAlign: 'center', marginTop: 6 },
874
+
875
+ // more menu
876
+ menu: {
877
+ backgroundColor: ui.bg,
878
+ borderTopLeftRadius: 22,
879
+ borderTopRightRadius: 22,
880
+ paddingHorizontal: PAD,
881
+ paddingTop: 8,
882
+ },
883
+ grabber: {
884
+ alignSelf: 'center',
885
+ width: 36,
886
+ height: 5,
887
+ borderRadius: 3,
888
+ backgroundColor: 'rgba(28,26,24,0.15)',
889
+ marginBottom: 14,
890
+ },
891
+ });