@adminide-stack/clock-tik-mobile 0.0.0-stage → 12.0.37-alpha.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.
- package/.claude-flow/data/pending-insights.jsonl +43 -0
- package/.claude-flow/sessions/session-1794323376548.json +14 -0
- package/CHANGELOG.md +41 -0
- package/jest.config.cjs +22 -0
- package/lib/assets/home/loop-day.jpg +0 -0
- package/lib/assets/home/loop-day.mp4 +0 -0
- package/lib/assets/home/loop-time-back.jpg +0 -0
- package/lib/assets/home/loop-time-back.mp4 +0 -0
- package/lib/assets/home/loop-where.jpg +0 -0
- package/lib/assets/home/loop-where.mp4 +0 -0
- package/lib/assets/home/reel-gym.jpg +0 -0
- package/lib/assets/home/reel-gym.mp4 +0 -0
- package/lib/assets/home/reel-internet.jpg +0 -0
- package/lib/assets/home/reel-internet.mp4 +0 -0
- package/lib/assets/icon.png +0 -0
- package/lib/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
- package/lib/assets/lottie/lucy-mark-calendar.json +1827 -0
- package/lib/assets/lottie/lucy-mark-call.json +1470 -0
- package/lib/assets/lottie/lucy-mark-connect.json +2552 -0
- package/lib/assets/lottie/lucy-mark-details.json +1735 -0
- package/lib/assets/lottie/lucy-mark-email.json +1363 -0
- package/lib/assets/lottie/lucy-mark-message.json +1154 -0
- package/lib/assets/lottie/lucy-mark-search.json +1067 -0
- package/lib/assets/lottie/lucy-mark-think.json +1253 -0
- package/lib/assets/lottie/lucy-mark-write.json +1532 -0
- package/lib/assets/lottie/time-back.json +16458 -0
- package/lib/assets/lottie/where-lucy-works-chat.json +6170 -0
- package/lib/assets/lottie/where-lucy-works-cloud.json +10066 -0
- package/lib/assets/lottie/where-lucy-works-mine-none.json +2478 -0
- package/lib/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
- package/lib/assets/lottie/where-lucy-works-mine-online.json +7881 -0
- package/lib/assets/sounds/hours-back.m4a +0 -0
- package/lib/assets/sounds/meet-lucy.m4a +0 -0
- package/lib/assets/sounds/power-on.m4a +0 -0
- package/lib/assets/sounds/wind-back.m4a +0 -0
- package/lib/assets/sounds/youre-in.m4a +0 -0
- package/lib/chat/agent.js +358 -0
- package/lib/chat/agent.js.map +1 -0
- package/lib/chat/appFront.js +32 -0
- package/lib/chat/appFront.js.map +1 -0
- package/lib/chat/auth.js +370 -0
- package/lib/chat/auth.js.map +1 -0
- package/lib/chat/chores.js +360 -0
- package/lib/chat/chores.js.map +1 -0
- package/lib/chat/connectors.js +45 -0
- package/lib/chat/connectors.js.map +1 -0
- package/lib/chat/jobs.js +223 -0
- package/lib/chat/jobs.js.map +1 -0
- package/lib/chat/lucyMotion.js +6 -0
- package/lib/chat/lucyMotion.js.map +1 -0
- package/lib/chat/protocol.js +111 -0
- package/lib/chat/protocol.js.map +1 -0
- package/lib/chat/results.js +133 -0
- package/lib/chat/results.js.map +1 -0
- package/lib/chat/store.js +81 -0
- package/lib/chat/store.js.map +1 -0
- package/lib/chat/useDictation.js +168 -0
- package/lib/chat/useDictation.js.map +1 -0
- package/lib/chat/useLucyChat.js +451 -0
- package/lib/chat/useLucyChat.js.map +1 -0
- package/lib/chat/useMyComputer.js +32 -0
- package/lib/chat/useMyComputer.js.map +1 -0
- package/lib/chat/whereLucyWorks.js +52 -0
- package/lib/chat/whereLucyWorks.js.map +1 -0
- package/lib/chat/workspace.js +124 -0
- package/lib/chat/workspace.js.map +1 -0
- package/lib/components/AreaShot.js +289 -0
- package/lib/components/AreaShot.js.map +1 -0
- package/lib/components/Backdrops.js +262 -0
- package/lib/components/Backdrops.js.map +1 -0
- package/lib/components/BottomSheet.js +61 -0
- package/lib/components/BottomSheet.js.map +1 -0
- package/lib/components/ChatSheets.js +429 -0
- package/lib/components/ChatSheets.js.map +1 -0
- package/lib/components/ConnectorLogo.js +91 -0
- package/lib/components/ConnectorLogo.js.map +1 -0
- package/lib/components/CustomDrawer.js +534 -0
- package/lib/components/CustomDrawer.js.map +1 -0
- package/lib/components/IdeasPane.js +394 -0
- package/lib/components/IdeasPane.js.map +1 -0
- package/lib/components/ImessageSheet.js +261 -0
- package/lib/components/ImessageSheet.js.map +1 -0
- package/lib/components/KeyboardAvoider.js +29 -0
- package/lib/components/KeyboardAvoider.js.map +1 -0
- package/lib/components/Logo.js +81 -0
- package/lib/components/Logo.js.map +1 -0
- package/lib/components/LucyWorking.js +67 -0
- package/lib/components/LucyWorking.js.map +1 -0
- package/lib/components/Markdown.js +260 -0
- package/lib/components/Markdown.js.map +1 -0
- package/lib/components/Media.js +93 -0
- package/lib/components/Media.js.map +1 -0
- package/lib/components/MessagesAppIcon.js +23 -0
- package/lib/components/MessagesAppIcon.js.map +1 -0
- package/lib/components/MicButton.js +71 -0
- package/lib/components/MicButton.js.map +1 -0
- package/lib/components/ResultCards.js +974 -0
- package/lib/components/ResultCards.js.map +1 -0
- package/lib/components/SignInPrompt.js +148 -0
- package/lib/components/SignInPrompt.js.map +1 -0
- package/lib/components/SignedOut.js +38 -0
- package/lib/components/SignedOut.js.map +1 -0
- package/lib/components/TalkToLucyHero.js +487 -0
- package/lib/components/TalkToLucyHero.js.map +1 -0
- package/lib/components/TalkToLucySheet.js +182 -0
- package/lib/components/TalkToLucySheet.js.map +1 -0
- package/lib/components/WhereLucyWorks.js +277 -0
- package/lib/components/WhereLucyWorks.js.map +1 -0
- package/lib/components/WorkspaceSection.js +271 -0
- package/lib/components/WorkspaceSection.js.map +1 -0
- package/lib/components/YantraMark.js +13 -0
- package/lib/components/YantraMark.js.map +1 -0
- package/lib/components/drawerHeader.js +38 -0
- package/lib/components/drawerHeader.js.map +1 -0
- package/lib/components/lottieInstalled.js +6 -0
- package/lib/components/lottieInstalled.js.map +1 -0
- package/lib/components/ui.js +550 -0
- package/lib/components/ui.js.map +1 -0
- package/lib/components/useSignOut.js +7 -0
- package/lib/components/useSignOut.js.map +1 -0
- package/lib/components/viewport.js +121 -0
- package/lib/components/viewport.js.map +1 -0
- package/lib/components/voiceDial.js +10 -0
- package/lib/components/voiceDial.js.map +1 -0
- package/lib/compute.js +157 -0
- package/lib/compute.js.map +1 -0
- package/lib/config/env-config.js +27 -0
- package/lib/config/env-config.js.map +1 -0
- package/lib/config/routes.js +15 -0
- package/lib/config/routes.js.map +1 -0
- package/lib/content.js +25 -0
- package/lib/content.js.map +1 -0
- package/lib/hooks/keyboardCover.js +39 -0
- package/lib/hooks/keyboardCover.js.map +1 -0
- package/lib/hooks/useKeyboard.js +121 -0
- package/lib/hooks/useKeyboard.js.map +1 -0
- package/lib/hooks/useReducedMotion.js +13 -0
- package/lib/hooks/useReducedMotion.js.map +1 -0
- package/lib/imessage/openMessages.js +25 -0
- package/lib/imessage/openMessages.js.map +1 -0
- package/lib/imessage/platform.js +12 -0
- package/lib/imessage/platform.js.map +1 -0
- package/lib/imessage/textLink.js +262 -0
- package/lib/imessage/textLink.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/live/card.js +28 -0
- package/lib/live/card.js.map +1 -0
- package/lib/live/liveActivity.js +144 -0
- package/lib/live/liveActivity.js.map +1 -0
- package/lib/module.js +3 -0
- package/lib/module.js.map +1 -0
- package/lib/offer/BlackFridayOffer.js +378 -0
- package/lib/offer/BlackFridayOffer.js.map +1 -0
- package/lib/offer/blackFriday.js +78 -0
- package/lib/offer/blackFriday.js.map +1 -0
- package/lib/offer/parts.js +624 -0
- package/lib/offer/parts.js.map +1 -0
- package/lib/offer/state.js +63 -0
- package/lib/offer/state.js.map +1 -0
- package/lib/push/push.js +142 -0
- package/lib/push/push.js.map +1 -0
- package/lib/push/usePushNotifications.js +39 -0
- package/lib/push/usePushNotifications.js.map +1 -0
- package/lib/routes.json +175 -0
- package/lib/screens/Account/index.js +209 -0
- package/lib/screens/Account/index.js.map +1 -0
- package/lib/screens/Chat/index.js +710 -0
- package/lib/screens/Chat/index.js.map +1 -0
- package/lib/screens/Chores/index.js +18 -0
- package/lib/screens/Chores/index.js.map +1 -0
- package/lib/screens/Connectors/index.js +17 -0
- package/lib/screens/Connectors/index.js.map +1 -0
- package/lib/screens/History/index.js +380 -0
- package/lib/screens/History/index.js.map +1 -0
- package/lib/screens/Home/index.js +2715 -0
- package/lib/screens/Home/index.js.map +1 -0
- package/lib/screens/Home/media.js +25 -0
- package/lib/screens/Home/media.js.map +1 -0
- package/lib/screens/Welcome/index.js +1066 -0
- package/lib/screens/Welcome/index.js.map +1 -0
- package/lib/talk/talkToLucy.js +139 -0
- package/lib/talk/talkToLucy.js.map +1 -0
- package/lib/theme/colors.js +29 -0
- package/lib/theme/colors.js.map +1 -0
- package/lib/theme/fonts.js +17 -0
- package/lib/theme/fonts.js.map +1 -0
- package/lib/theme/muse.js +134 -0
- package/lib/theme/muse.js.map +1 -0
- package/lib/utils/links.js +54 -0
- package/lib/utils/links.js.map +1 -0
- package/lib/utils/yantraLinks.js +68 -0
- package/lib/utils/yantraLinks.js.map +1 -0
- package/lib/welcome/flow.js +375 -0
- package/lib/welcome/flow.js.map +1 -0
- package/lib/welcome/haptics.js +125 -0
- package/lib/welcome/haptics.js.map +1 -0
- package/lib/welcome/parts.js +1996 -0
- package/lib/welcome/parts.js.map +1 -0
- package/lib/welcome/powerOn.js +29 -0
- package/lib/welcome/powerOn.js.map +1 -0
- package/lib/welcome/seen.js +41 -0
- package/lib/welcome/seen.js.map +1 -0
- package/lib/welcome/sound.js +110 -0
- package/lib/welcome/sound.js.map +1 -0
- package/package.json +66 -5
- package/rollup.config.mjs +42 -0
- package/src/.claude-flow/data/pending-insights.jsonl +19 -0
- package/src/.claude-flow/sessions/session-1795013028422.json +14 -0
- package/src/__tests__/auth.test.ts +94 -0
- package/src/__tests__/blackFriday.test.ts +75 -0
- package/src/__tests__/cardTokens.test.ts +77 -0
- package/src/__tests__/chores.test.ts +188 -0
- package/src/__tests__/choresList.test.ts +100 -0
- package/src/__tests__/connectLink.test.ts +21 -0
- package/src/__tests__/content.test.ts +54 -0
- package/src/__tests__/dictation.test.ts +186 -0
- package/src/__tests__/envConfig.test.ts +14 -0
- package/src/__tests__/haptics.test.ts +202 -0
- package/src/__tests__/jobs.test.ts +130 -0
- package/src/__tests__/keyboardCover.test.ts +84 -0
- package/src/__tests__/liveCard.test.ts +39 -0
- package/src/__tests__/lockedPhone.test.ts +355 -0
- package/src/__tests__/lucyMotion.test.ts +34 -0
- package/src/__tests__/platform.test.ts +32 -0
- package/src/__tests__/powerOn.test.ts +62 -0
- package/src/__tests__/protocol.test.ts +125 -0
- package/src/__tests__/push.test.ts +111 -0
- package/src/__tests__/results.test.ts +256 -0
- package/src/__tests__/sound.test.ts +248 -0
- package/src/__tests__/talkToLucy.test.ts +205 -0
- package/src/__tests__/textLink.test.ts +91 -0
- package/src/__tests__/voiceDial.test.ts +53 -0
- package/src/__tests__/welcomeFlow.test.ts +157 -0
- package/src/__tests__/whereLucyWorks.test.ts +81 -0
- package/src/__tests__/yantraLinks.test.ts +96 -0
- package/src/assets/home/loop-day.jpg +0 -0
- package/src/assets/home/loop-day.mp4 +0 -0
- package/src/assets/home/loop-time-back.jpg +0 -0
- package/src/assets/home/loop-time-back.mp4 +0 -0
- package/src/assets/home/loop-where.jpg +0 -0
- package/src/assets/home/loop-where.mp4 +0 -0
- package/src/assets/home/reel-gym.jpg +0 -0
- package/src/assets/home/reel-gym.mp4 +0 -0
- package/src/assets/home/reel-internet.jpg +0 -0
- package/src/assets/home/reel-internet.mp4 +0 -0
- package/src/assets/icon.png +0 -0
- package/src/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
- package/src/assets/lottie/lucy-mark-calendar.json +1827 -0
- package/src/assets/lottie/lucy-mark-call.json +1470 -0
- package/src/assets/lottie/lucy-mark-connect.json +2552 -0
- package/src/assets/lottie/lucy-mark-details.json +1735 -0
- package/src/assets/lottie/lucy-mark-email.json +1363 -0
- package/src/assets/lottie/lucy-mark-message.json +1154 -0
- package/src/assets/lottie/lucy-mark-search.json +1067 -0
- package/src/assets/lottie/lucy-mark-think.json +1253 -0
- package/src/assets/lottie/lucy-mark-write.json +1532 -0
- package/src/assets/lottie/time-back.json +16458 -0
- package/src/assets/lottie/where-lucy-works-chat.json +6170 -0
- package/src/assets/lottie/where-lucy-works-cloud.json +10066 -0
- package/src/assets/lottie/where-lucy-works-mine-none.json +2478 -0
- package/src/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
- package/src/assets/lottie/where-lucy-works-mine-online.json +7881 -0
- package/src/assets/sounds/hours-back.m4a +0 -0
- package/src/assets/sounds/meet-lucy.m4a +0 -0
- package/src/assets/sounds/power-on.m4a +0 -0
- package/src/assets/sounds/wind-back.m4a +0 -0
- package/src/assets/sounds/youre-in.m4a +0 -0
- package/src/chat/.claude-flow/data/pending-insights.jsonl +1 -0
- package/src/chat/agent.ts +376 -0
- package/src/chat/appFront.ts +39 -0
- package/src/chat/auth.ts +433 -0
- package/src/chat/chores.ts +394 -0
- package/src/chat/connectors.ts +75 -0
- package/src/chat/jobs.ts +228 -0
- package/src/chat/lucyMotion.ts +33 -0
- package/src/chat/protocol.ts +192 -0
- package/src/chat/results.ts +224 -0
- package/src/chat/store.ts +87 -0
- package/src/chat/useDictation.ts +201 -0
- package/src/chat/useLucyChat.ts +458 -0
- package/src/chat/useMyComputer.ts +41 -0
- package/src/chat/whereLucyWorks.ts +97 -0
- package/src/chat/workspace.ts +127 -0
- package/src/components/.claude-flow/data/pending-insights.jsonl +3 -0
- package/src/components/AreaShot.tsx +239 -0
- package/src/components/Backdrops.tsx +323 -0
- package/src/components/BottomSheet.tsx +96 -0
- package/src/components/ChatSheets.tsx +565 -0
- package/src/components/ConnectorLogo.tsx +116 -0
- package/src/components/CustomDrawer.tsx +526 -0
- package/src/components/IdeasPane.tsx +318 -0
- package/src/components/ImessageSheet.tsx +280 -0
- package/src/components/KeyboardAvoider.tsx +45 -0
- package/src/components/Logo.tsx +97 -0
- package/src/components/LucyWorking.tsx +122 -0
- package/src/components/Markdown.tsx +219 -0
- package/src/components/Media.tsx +173 -0
- package/src/components/MessagesAppIcon.tsx +51 -0
- package/src/components/MicButton.tsx +92 -0
- package/src/components/ResultCards.tsx +1067 -0
- package/src/components/SignInPrompt.tsx +182 -0
- package/src/components/SignedOut.tsx +47 -0
- package/src/components/TalkToLucyHero.tsx +540 -0
- package/src/components/TalkToLucySheet.tsx +208 -0
- package/src/components/VoiceOrb.tsx +364 -0
- package/src/components/WhereLucyWorks.tsx +261 -0
- package/src/components/WorkspaceSection.tsx +307 -0
- package/src/components/YantraMark.tsx +30 -0
- package/src/components/drawerHeader.tsx +46 -0
- package/src/components/kit.tsx +309 -0
- package/src/components/lottieInstalled.ts +7 -0
- package/src/components/ui.tsx +700 -0
- package/src/components/useSignOut.ts +21 -0
- package/src/components/viewport.tsx +166 -0
- package/src/components/voiceDial.ts +45 -0
- package/src/compute.ts +168 -0
- package/src/config/env-config.ts +50 -0
- package/src/config/routes.ts +28 -0
- package/src/content.ts +217 -0
- package/src/hooks/keyboardCover.ts +70 -0
- package/src/hooks/useKeyboard.ts +135 -0
- package/src/hooks/useReducedMotion.ts +19 -0
- package/src/imessage/openMessages.ts +53 -0
- package/src/imessage/platform.ts +32 -0
- package/src/imessage/textLink.ts +307 -0
- package/src/index.ts +24 -0
- package/src/live/card.ts +62 -0
- package/src/live/liveActivity.ts +192 -0
- package/src/module.ts +8 -0
- package/src/offer/BlackFridayOffer.tsx +394 -0
- package/src/offer/blackFriday.ts +109 -0
- package/src/offer/parts.tsx +650 -0
- package/src/offer/state.ts +78 -0
- package/src/push/push.ts +171 -0
- package/src/push/usePushNotifications.ts +47 -0
- package/src/screens/Account/index.tsx +310 -0
- package/src/screens/Chat/.claude-flow/data/pending-insights.jsonl +4 -0
- package/src/screens/Chat/index.tsx +891 -0
- package/src/screens/Chores/index.tsx +35 -0
- package/src/screens/Connectors/index.tsx +35 -0
- package/src/screens/History/index.tsx +346 -0
- package/src/screens/Home/index.tsx +2776 -0
- package/src/screens/Home/media.ts +31 -0
- package/src/screens/Welcome/index.tsx +1182 -0
- package/src/talk/talkToLucy.ts +187 -0
- package/src/theme/colors.ts +38 -0
- package/src/theme/fonts.ts +30 -0
- package/src/theme/muse.ts +86 -0
- package/src/utils/links.ts +84 -0
- package/src/utils/yantraLinks.ts +94 -0
- package/src/welcome/flow.ts +418 -0
- package/src/welcome/haptics.ts +179 -0
- package/src/welcome/parts.tsx +2160 -0
- package/src/welcome/powerOn.ts +84 -0
- package/src/welcome/seen.ts +68 -0
- package/src/welcome/sound.ts +173 -0
- package/tools/lottie/chat.motion +0 -0
- package/tools/lottie/cloud.motion +0 -0
- package/tools/lottie/generate.mjs +1209 -0
- package/tools/lottie/inter-glyphs.json +4416 -0
- package/tools/lottie/lucy-mark-calendar.motion +0 -0
- package/tools/lottie/lucy-mark-call.motion +0 -0
- package/tools/lottie/lucy-mark-connect.motion +0 -0
- package/tools/lottie/lucy-mark-details.motion +0 -0
- package/tools/lottie/lucy-mark-email.motion +0 -0
- package/tools/lottie/lucy-mark-message.motion +0 -0
- package/tools/lottie/lucy-mark-search.motion +0 -0
- package/tools/lottie/lucy-mark-think.motion +0 -0
- package/tools/lottie/lucy-mark-write.motion +0 -0
- package/tools/lottie/mark.json +1 -0
- package/tools/lottie/mine-none.motion +0 -0
- package/tools/lottie/mine-offline.motion +0 -0
- package/tools/lottie/mine-online.motion +0 -0
- package/tools/lottie/time-back.mjs +604 -0
- package/tools/sounds/render.mjs +730 -0
- package/tsconfig.json +17 -0
- package/README.md +0 -3
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Text Lucy on iMessage": an `sms:` link that opens Messages at the platform's iMessage line with the first text
|
|
3
|
+
* ready to send - the same link the web home builds (browser src/pages/Home/imessage/textLink.ts; keep the two in
|
|
4
|
+
* step).
|
|
5
|
+
*
|
|
6
|
+
* A phone the gateway has never seen cannot be told apart from a stranger, so its first text carries a one-time
|
|
7
|
+
* pairing code, hidden in the greeting as invisible characters: the person sees and sends "Hi Lucy", and the gateway
|
|
8
|
+
* links the phone to their account. A phone that already texts Lucy gets the plain greeting.
|
|
9
|
+
*
|
|
10
|
+
* Everything is asked of the backend Lucy's agent trusts, with the person's agent token (chat/auth.ts) - the token
|
|
11
|
+
* the web page's surface sign-in brings back - so the platform decides what they may see. The line's addresses only
|
|
12
|
+
* ever live inside `href`: the app opens it and never prints it.
|
|
13
|
+
*/
|
|
14
|
+
import { accountKey, agentBackendUrl, getChatToken } from '../chat/auth';
|
|
15
|
+
|
|
16
|
+
/** imessage: an Apple device texting the iCloud handle. sms: an Android phone texting the forwarding number. */
|
|
17
|
+
export type TextReach = 'imessage' | 'sms';
|
|
18
|
+
|
|
19
|
+
export interface TextLink {
|
|
20
|
+
/** The line `href` texts. A phone that is already linked keeps the line it is linked on. */
|
|
21
|
+
reach: TextReach;
|
|
22
|
+
/** The `sms:` link with the first text ready; null when that line is not answering. Never print it. */
|
|
23
|
+
href: string | null;
|
|
24
|
+
/** The line `href` texts and the text it carries, for the native Messages composer. Never print them. */
|
|
25
|
+
to: string | null;
|
|
26
|
+
body: string | null;
|
|
27
|
+
/** The person's phone already texts Lucy: the plain greeting, no code. */
|
|
28
|
+
linked: boolean;
|
|
29
|
+
/** When the hidden one-time code stops working (Unix ms); null when there is none. */
|
|
30
|
+
expiresAt: number | null;
|
|
31
|
+
/** The platform has an SMS/RCS number, so a phone without iMessage can text Lucy too. */
|
|
32
|
+
smsAvailable: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type TextLinkErrorKind = 'signed-out' | 'rate-limited' | 'failed';
|
|
36
|
+
|
|
37
|
+
export class TextLinkError extends Error {
|
|
38
|
+
readonly kind: TextLinkErrorKind;
|
|
39
|
+
|
|
40
|
+
constructor(kind: TextLinkErrorKind, message: string) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'TextLinkError';
|
|
43
|
+
this.kind = kind;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The gateway channel the iMessage line arrives on. SMS and RCS forwarded to the same Mac arrive on it too. */
|
|
48
|
+
export const IMESSAGE_CHANNEL = 'imessage-webhook';
|
|
49
|
+
|
|
50
|
+
/** What the person sees ready in Messages, and sends. */
|
|
51
|
+
export const LUCY_GREETING = 'Hi Lucy';
|
|
52
|
+
|
|
53
|
+
const MAX_MESSAGE = 300;
|
|
54
|
+
const TIMEOUT_MS = 8000;
|
|
55
|
+
/** The gateway's code lifetime (messenger-gateway pairing-service: 600 s). */
|
|
56
|
+
const CODE_TTL_MS = 10 * 60_000;
|
|
57
|
+
/** A minted code is reused until this close to its expiry: the gateway mints only five a minute. */
|
|
58
|
+
const REUSE_LEAD_MS = 2 * 60_000;
|
|
59
|
+
|
|
60
|
+
const ADDRESS_QUERY = `query ClockbookImessageLine { imessageBotAddress }`;
|
|
61
|
+
// Its own request: a backend that does not serve `smsBotNumber` fails this one alone, never the address.
|
|
62
|
+
const SMS_QUERY = `query ClockbookSmsLine { smsBotNumber }`;
|
|
63
|
+
const BINDINGS_QUERY = `query ClockbookTextBindings($chatSessionId: String) {
|
|
64
|
+
gatewayListBindings(chatSessionId: $chatSessionId) { channelType externalChatId externalAccountId }
|
|
65
|
+
}`;
|
|
66
|
+
const MINT_MUTATION = `mutation ClockbookPairingCode($input: GatewayPairingTokenInput!) {
|
|
67
|
+
gatewayGeneratePairingToken(input: $input) { token expiresAt }
|
|
68
|
+
}`;
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* The hidden code's wire format, shared with the messenger gateway and the web home (change them together):
|
|
72
|
+
* FRAME + four base-4 digits per byte of the token, high bits first, + FRAME. Every character is a Unicode
|
|
73
|
+
* default-ignorable, so Messages shows only the greeting. Tokens are base64url, so each character code is its byte.
|
|
74
|
+
*/
|
|
75
|
+
const HIDDEN_FRAME = '';
|
|
76
|
+
const HIDDEN_DIGITS = ['', '', '', ''];
|
|
77
|
+
|
|
78
|
+
export function encodeHiddenCode(token: string): string {
|
|
79
|
+
let out = HIDDEN_FRAME;
|
|
80
|
+
for (let i = 0; i < token.length; i += 1) {
|
|
81
|
+
const byte = token.charCodeAt(i) & 0xff;
|
|
82
|
+
for (let shift = 6; shift >= 0; shift -= 2) out += HIDDEN_DIGITS[(byte >> shift) & 3];
|
|
83
|
+
}
|
|
84
|
+
return out + HIDDEN_FRAME;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `?&body=` is the one form both iOS Messages and Android's messaging apps read the body from. */
|
|
88
|
+
export function smsHref(address: string, body: string): string {
|
|
89
|
+
return `sms:${address}?&body=${encodeURIComponent(body)}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface TextBinding {
|
|
93
|
+
channelType?: string | null;
|
|
94
|
+
externalChatId?: string | null;
|
|
95
|
+
externalAccountId?: string | null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The person's own one-on-one thread on the platform line: never a group chat, never a workspace's line. */
|
|
99
|
+
export function ownThread(bindings: readonly TextBinding[]): TextBinding | undefined {
|
|
100
|
+
return bindings.find(
|
|
101
|
+
(b) =>
|
|
102
|
+
b.channelType === IMESSAGE_CHANNEL &&
|
|
103
|
+
!String(b.externalChatId ?? '').includes(';+;') &&
|
|
104
|
+
!String(b.externalAccountId ?? '').startsWith('ws_'),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A linked thread keeps texting the way it is linked: texts the Mac's iPhone forwarded are SMS or RCS. */
|
|
109
|
+
export function threadReach(thread: TextBinding): TextReach {
|
|
110
|
+
return /^(SMS|RCS);/i.test(thread.externalChatId ?? '') ? 'sms' : 'imessage';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface TextLine {
|
|
114
|
+
imessage: string | null;
|
|
115
|
+
sms: string | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** An iPhone can text a number too; an Android phone cannot text an Apple ID, so nothing stands in for the number. */
|
|
119
|
+
export function lineAddress(line: TextLine, reach: TextReach): string | null {
|
|
120
|
+
if (reach === 'sms') return line.sms;
|
|
121
|
+
return line.imessage || line.sms;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The first text: the person's own words when they brought some, Lucy's greeting otherwise. */
|
|
125
|
+
export function firstText(message?: string): string {
|
|
126
|
+
const text = (message ?? '').trim().slice(0, MAX_MESSAGE).trim();
|
|
127
|
+
return text || LUCY_GREETING;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Never trust less than a minute of a just-minted code, nor more than its lifetime (the device clock may be off). */
|
|
131
|
+
export function normalizeExpiry(expiresAt: unknown, receivedAt: number): number {
|
|
132
|
+
const at = typeof expiresAt === 'string' ? Number(expiresAt) : expiresAt;
|
|
133
|
+
const latest = receivedAt + CODE_TTL_MS;
|
|
134
|
+
if (typeof at !== 'number' || !Number.isFinite(at) || at - receivedAt < 60_000) return latest;
|
|
135
|
+
return Math.min(at, latest);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface GqlReply<T> {
|
|
139
|
+
data?: T | null;
|
|
140
|
+
errors?: Array<{ message?: string; extensions?: { code?: string } | null }>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const RATE_LIMITED = /too many pairing|rate.?limit/i;
|
|
144
|
+
const SIGNED_OUT =
|
|
145
|
+
/unauthori[sz]ed|unauthenticated|not authenticated|jwt|token (is )?(expired|invalid)|session expired/i;
|
|
146
|
+
|
|
147
|
+
export function classifyError(message: string, code?: string | null): TextLinkError {
|
|
148
|
+
if (RATE_LIMITED.test(message)) return new TextLinkError('rate-limited', message);
|
|
149
|
+
if (code === 'UNAUTHENTICATED' || SIGNED_OUT.test(message)) return new TextLinkError('signed-out', message);
|
|
150
|
+
return new TextLinkError('failed', message || 'The platform could not answer.');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function post(url: string, token: string, query: string, variables: object | undefined, signal: AbortSignal) {
|
|
154
|
+
return fetch(url, {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
headers: { 'content-type': 'application/json', Authorization: `Bearer ${token}` },
|
|
157
|
+
body: JSON.stringify({ query, variables }),
|
|
158
|
+
signal,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One GraphQL call with the agent token; a 401 mints a fresh token and tries once more (as the web's retry). */
|
|
163
|
+
async function ask<T>(query: string, variables: object | undefined, signal?: AbortSignal): Promise<T> {
|
|
164
|
+
const url = await agentBackendUrl().catch(() => {
|
|
165
|
+
throw new TextLinkError('failed', 'Could not reach Lucy.');
|
|
166
|
+
});
|
|
167
|
+
const timeout = new AbortController();
|
|
168
|
+
const timer = setTimeout(() => timeout.abort(), TIMEOUT_MS);
|
|
169
|
+
const onAbort = () => timeout.abort();
|
|
170
|
+
signal?.addEventListener('abort', onAbort);
|
|
171
|
+
try {
|
|
172
|
+
let res = await post(url, await getChatToken(), query, variables, timeout.signal);
|
|
173
|
+
if (res.status === 401)
|
|
174
|
+
res = await post(url, await getChatToken({ fresh: true }), query, variables, timeout.signal);
|
|
175
|
+
if (res.status === 401) throw new TextLinkError('signed-out', 'The sign-in was refused.');
|
|
176
|
+
const json = (await res.json().catch(() => null)) as GqlReply<T> | null;
|
|
177
|
+
const first = json?.errors?.[0];
|
|
178
|
+
if (first) throw classifyError(String(first.message ?? ''), first.extensions?.code);
|
|
179
|
+
if (!res.ok || !json?.data) throw new TextLinkError('failed', `The platform answered ${res.status}.`);
|
|
180
|
+
return json.data;
|
|
181
|
+
} catch (err) {
|
|
182
|
+
if (err instanceof TextLinkError) throw err;
|
|
183
|
+
// getChatToken's own errors: no Auth0 session is a sign-in, the rest a failure.
|
|
184
|
+
if ((err as { kind?: string })?.kind === 'signed-out') throw new TextLinkError('signed-out', 'Sign in first.');
|
|
185
|
+
throw new TextLinkError('failed', (err as Error)?.message || 'Could not reach Lucy.');
|
|
186
|
+
} finally {
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
signal?.removeEventListener('abort', onAbort);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare const __DEV__: boolean | undefined;
|
|
193
|
+
/** Development builds say why a lookup came back empty (never the line's address itself). */
|
|
194
|
+
function devLog(what: string, detail: unknown): void {
|
|
195
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
196
|
+
// eslint-disable-next-line no-console
|
|
197
|
+
console.log(`[textLink] ${what}:`, detail);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A lookup that may come back empty; only a refused sign-in (or the caller giving up) gets through. */
|
|
202
|
+
function orElse<T>(promise: Promise<T>, fallback: T, signal?: AbortSignal, what = 'lookup'): Promise<T> {
|
|
203
|
+
return promise.catch((err: unknown) => {
|
|
204
|
+
if (signal?.aborted || (err instanceof TextLinkError && err.kind === 'signed-out')) throw err;
|
|
205
|
+
devLog(`${what} failed`, (err as Error)?.message ?? err);
|
|
206
|
+
return fallback;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** A fresh conversation for the phone to bridge into, as the gateway starts one for /newchat. */
|
|
211
|
+
function newConversationId(): string {
|
|
212
|
+
const c = (globalThis as { crypto?: Crypto }).crypto;
|
|
213
|
+
if (c?.randomUUID) return c.randomUUID();
|
|
214
|
+
const bytes = new Uint8Array(16);
|
|
215
|
+
if (c?.getRandomValues) c.getRandomValues(bytes);
|
|
216
|
+
else for (let i = 0; i < 16; i += 1) bytes[i] = Math.floor(Math.random() * 256);
|
|
217
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
218
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
219
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
220
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Codes minted in this session, per account: reopening the sheet reuses one. */
|
|
224
|
+
const codes = new Map<string, { token: string; expiresAt: number }>();
|
|
225
|
+
|
|
226
|
+
async function pairingCode(account: string, signal?: AbortSignal): Promise<{ token: string; expiresAt: number }> {
|
|
227
|
+
const kept = codes.get(account);
|
|
228
|
+
if (kept && kept.expiresAt - Date.now() > REUSE_LEAD_MS) return kept;
|
|
229
|
+
const data = await ask<{ gatewayGeneratePairingToken?: { token?: string | null; expiresAt?: unknown } | null }>(
|
|
230
|
+
MINT_MUTATION,
|
|
231
|
+
// `chatSession` like every other pairing entry point: the phone bridges into this chat only.
|
|
232
|
+
{ input: { channelType: IMESSAGE_CHANNEL, chatSessionId: newConversationId(), scope: 'chatSession' } },
|
|
233
|
+
signal,
|
|
234
|
+
);
|
|
235
|
+
const token = data.gatewayGeneratePairingToken?.token?.trim();
|
|
236
|
+
if (!token) throw new TextLinkError('failed', 'The platform did not mint a code.');
|
|
237
|
+
const code = { token, expiresAt: normalizeExpiry(data.gatewayGeneratePairingToken?.expiresAt, Date.now()) };
|
|
238
|
+
codes.set(account, code);
|
|
239
|
+
return code;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Forget every code minted here: on sign-out, so the next person on this phone gets their own. */
|
|
243
|
+
export function clearTextLinkCodes(): void {
|
|
244
|
+
codes.clear();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The link for a phone that texts on `reach`. Throws a TextLinkError: `signed-out` when the platform refused the
|
|
249
|
+
* sign-in, `rate-limited` after too many codes in a minute, `failed` otherwise.
|
|
250
|
+
*/
|
|
251
|
+
export async function fetchTextLink(
|
|
252
|
+
reach: TextReach,
|
|
253
|
+
{ message, signal }: { message?: string; signal?: AbortSignal } = {},
|
|
254
|
+
): Promise<TextLink> {
|
|
255
|
+
const [imessage, sms, bindings] = await Promise.all([
|
|
256
|
+
orElse(
|
|
257
|
+
ask<{ imessageBotAddress?: string | null }>(ADDRESS_QUERY, undefined, signal).then(
|
|
258
|
+
(d) => d.imessageBotAddress?.trim() || null,
|
|
259
|
+
),
|
|
260
|
+
null,
|
|
261
|
+
signal,
|
|
262
|
+
'imessageBotAddress',
|
|
263
|
+
),
|
|
264
|
+
orElse(
|
|
265
|
+
ask<{ smsBotNumber?: string | null }>(SMS_QUERY, undefined, signal).then(
|
|
266
|
+
(d) => d.smsBotNumber?.trim() || null,
|
|
267
|
+
),
|
|
268
|
+
null,
|
|
269
|
+
signal,
|
|
270
|
+
'smsBotNumber',
|
|
271
|
+
),
|
|
272
|
+
orElse(
|
|
273
|
+
ask<{ gatewayListBindings?: TextBinding[] | null }>(BINDINGS_QUERY, { chatSessionId: null }, signal).then(
|
|
274
|
+
(d) => d.gatewayListBindings ?? [],
|
|
275
|
+
),
|
|
276
|
+
[] as TextBinding[],
|
|
277
|
+
signal,
|
|
278
|
+
'gatewayListBindings',
|
|
279
|
+
),
|
|
280
|
+
]);
|
|
281
|
+
devLog('line', {
|
|
282
|
+
backend: await agentBackendUrl().catch(() => null),
|
|
283
|
+
imessageLine: imessage ? 'set' : 'empty',
|
|
284
|
+
smsLine: sms ? 'set' : 'empty',
|
|
285
|
+
bindings: bindings.length,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const thread = ownThread(bindings);
|
|
289
|
+
const route = thread ? threadReach(thread) : reach;
|
|
290
|
+
const address = lineAddress({ imessage, sms }, route);
|
|
291
|
+
const body = firstText(message);
|
|
292
|
+
const base = { reach: route, smsAvailable: Boolean(sms) };
|
|
293
|
+
if (!address) return { ...base, href: null, to: null, body: null, linked: Boolean(thread), expiresAt: null };
|
|
294
|
+
if (thread) return { ...base, href: smsHref(address, body), to: address, body, linked: true, expiresAt: null };
|
|
295
|
+
|
|
296
|
+
const account = accountKey(await getChatToken());
|
|
297
|
+
const code = await pairingCode(account, signal);
|
|
298
|
+
const coded = body + encodeHiddenCode(code.token);
|
|
299
|
+
return {
|
|
300
|
+
...base,
|
|
301
|
+
href: smsHref(address, coded),
|
|
302
|
+
to: address,
|
|
303
|
+
body: coded,
|
|
304
|
+
linked: false,
|
|
305
|
+
expiresAt: code.expiresAt,
|
|
306
|
+
};
|
|
307
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Feature } from '@common-stack/client-react';
|
|
2
|
+
import ClockbookMobileModule from './module';
|
|
3
|
+
|
|
4
|
+
export default new Feature(ClockbookMobileModule);
|
|
5
|
+
export { config } from './config/env-config';
|
|
6
|
+
export { CLOCKBOOK_ROUTES } from './config/routes';
|
|
7
|
+
export { colors } from './theme/colors';
|
|
8
|
+
export {
|
|
9
|
+
appBase,
|
|
10
|
+
appTextingLink,
|
|
11
|
+
chatLink,
|
|
12
|
+
businessBase,
|
|
13
|
+
businessLink,
|
|
14
|
+
openUrl,
|
|
15
|
+
openChore,
|
|
16
|
+
PROMPT_MAX,
|
|
17
|
+
yantraAppUrl,
|
|
18
|
+
} from './utils/links';
|
|
19
|
+
export { openYantraInSheet, openYantraUrl, signedInYantraLink } from './utils/yantraLinks';
|
|
20
|
+
export { SignInPrompt, useSignInGate, type SignInPurpose } from './components/SignInPrompt';
|
|
21
|
+
export { Mark, AnimatedMark } from './components/Logo';
|
|
22
|
+
// The drawer is loaded by the app's generated navigation from lib/components/CustomDrawer.js
|
|
23
|
+
// (config.json customDrawerPath); exported here so rollup emits it.
|
|
24
|
+
export { default as CustomDrawer } from './components/CustomDrawer';
|
package/src/live/card.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a Live Activity card says for one of Lucy's chores (live/liveActivity.ts shows it). Pure, so it is tested
|
|
3
|
+
* without a phone. CardState is the card's ContentState (portable-devices/mobile/targets/lucy-live) and what Yantra's
|
|
4
|
+
* pushes send as `content-state` (that folder's README.md): keep the three the same.
|
|
5
|
+
*/
|
|
6
|
+
export type CardKind = 'call' | 'shop' | 'general';
|
|
7
|
+
export type CardPhase = 'working' | 'asking' | 'done' | 'failed';
|
|
8
|
+
|
|
9
|
+
export interface CardState {
|
|
10
|
+
kind: CardKind;
|
|
11
|
+
phase: CardPhase;
|
|
12
|
+
/** The line under the title: what Lucy is doing now, her question, or how it ended. */
|
|
13
|
+
detail: string;
|
|
14
|
+
/** Unix seconds the timer counts from: the call's start on a call, else the chore's. */
|
|
15
|
+
startedAt?: number;
|
|
16
|
+
/** Picks so far, while shopping. */
|
|
17
|
+
count?: number;
|
|
18
|
+
/** Minutes Lucy spent on it, once done. */
|
|
19
|
+
minutesBack?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ASKS_CALL = /\b(call|phone|ring|dial)\b/i;
|
|
23
|
+
const IN_A_CALL = /\b(making a call|calling|on the line|ringing|on hold)\b/i;
|
|
24
|
+
const ASKS_SHOP = /\b(buy|order|shop|shopping|find me|cheapest|price|deal)\b/i;
|
|
25
|
+
|
|
26
|
+
/** The kind of chore, from what was asked or what Lucy says she is doing. A call stays a call. */
|
|
27
|
+
export function cardKind(text: string, current: CardKind = 'general'): CardKind {
|
|
28
|
+
if (current === 'call' || ASKS_CALL.test(text) || IN_A_CALL.test(text)) return 'call';
|
|
29
|
+
if (current === 'shop' || ASKS_SHOP.test(text)) return 'shop';
|
|
30
|
+
return current;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Whether a status line is the call itself starting: then the card's timer counts from now. */
|
|
34
|
+
export function callStarts(status: string): boolean {
|
|
35
|
+
return IN_A_CALL.test(status);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The card's title: the chore as asked, on one line. */
|
|
39
|
+
export function cardTitle(prompt: string): string {
|
|
40
|
+
const t = prompt.replace(/\s+/g, ' ').trim();
|
|
41
|
+
if (!t) return 'A chore for Lucy';
|
|
42
|
+
return t.length > 44 ? `${t.slice(0, 43).trimEnd()}…` : t;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A finished card's line: the first sentence of Lucy's last reply, without its question card or markup. */
|
|
46
|
+
export function cardSummary(reply: string): string {
|
|
47
|
+
const plain = reply
|
|
48
|
+
.replace(/\[ASK_USER\][\s\S]*?(?:\[\/ASK_USER\]|$)/g, '')
|
|
49
|
+
.replace(/```[\s\S]*?(?:```|$)/g, '')
|
|
50
|
+
.replace(/\[\[surface:[^|\]]+\|([^\]]+)\]\]/g, '$1')
|
|
51
|
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
|
52
|
+
.replace(/[*_#>`]/g, '')
|
|
53
|
+
.replace(/\s+/g, ' ')
|
|
54
|
+
.trim();
|
|
55
|
+
const first = /^(.+?[.!?])(\s|$)/.exec(plain)?.[1] ?? plain;
|
|
56
|
+
return first.length > 80 ? `${first.slice(0, 79).trimEnd()}…` : first;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Minutes Lucy spent, at least one. */
|
|
60
|
+
export function minutesSpent(fromSeconds: number, nowSeconds: number): number {
|
|
61
|
+
return Math.max(1, Math.round((nowSeconds - fromSeconds) / 60));
|
|
62
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lucy's chores on the Lock Screen and in the Dynamic Island (iOS Live Activities). The host app draws them
|
|
3
|
+
* (portable-devices/mobile/targets/lucy-live) and runs them through its LucyLiveActivity module
|
|
4
|
+
* (portable-devices/mobile/modules/lucy-live-activity); this file decides when a card starts, moves and ends, and
|
|
5
|
+
* card.ts what it says. Without the module (Android, web, Expo Go, a build from before it) every call does nothing.
|
|
6
|
+
*
|
|
7
|
+
* A card follows a chore by its id (the chat's chore), so the reply, the answer to Lucy's question and the end all land
|
|
8
|
+
* on the same card. While the app is open the chat stream moves it (chat/useLucyChat.ts). While the app is closed Yantra
|
|
9
|
+
* moves it: each chore's record carries its card's token (cardTokenFor, chat/jobs.ts), and the agent's reports on that
|
|
10
|
+
* record are pushed to the card (adminIde project-mgmt SurfaceJobNotifier; that README.md).
|
|
11
|
+
*/
|
|
12
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
13
|
+
import { Platform } from 'react-native';
|
|
14
|
+
import { requireOptionalNativeModule } from 'expo-modules-core';
|
|
15
|
+
import { callStarts, cardKind, cardSummary, cardTitle, minutesSpent, type CardState } from './card';
|
|
16
|
+
|
|
17
|
+
interface LucyLiveActivityModule {
|
|
18
|
+
areEnabled(): boolean;
|
|
19
|
+
start(choreId: string, title: string, state: CardState): Promise<string | null>;
|
|
20
|
+
update(choreId: string, state: CardState): Promise<void>;
|
|
21
|
+
end(choreId: string, state: CardState | null, dismissAfterSeconds: number): Promise<void>;
|
|
22
|
+
addListener(event: 'onPushToken', listener: (e: { choreId: string; token: string }) => void): { remove(): void };
|
|
23
|
+
addListener(event: 'onPushToStartToken', listener: (e: { token: string }) => void): { remove(): void };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const native = Platform.OS === 'ios' ? requireOptionalNativeModule<LucyLiveActivityModule>('LucyLiveActivity') : null;
|
|
27
|
+
|
|
28
|
+
/** How long a finished card stays on the Lock Screen. */
|
|
29
|
+
const DONE_SHOWN_S = 15 * 60;
|
|
30
|
+
const FAILED_SHOWN_S = 30 * 60;
|
|
31
|
+
/** A chore over this fast was a quick answer, read in the app: its card goes at once (as chores.ts QUICK_ANSWER_MS). */
|
|
32
|
+
const QUICK_S = 20;
|
|
33
|
+
|
|
34
|
+
interface Card {
|
|
35
|
+
title: string;
|
|
36
|
+
state: CardState;
|
|
37
|
+
/** Unix seconds the chore started, and the call within it. */
|
|
38
|
+
began: number;
|
|
39
|
+
callAt?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cards = new Map<string, Card>();
|
|
43
|
+
const nowS = () => Date.now() / 1000;
|
|
44
|
+
|
|
45
|
+
function enabled(): boolean {
|
|
46
|
+
try {
|
|
47
|
+
return Boolean(native?.areEnabled());
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function show(choreId: string, card: Card): void {
|
|
54
|
+
native?.update(choreId, card.state).catch(() => undefined);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A chore starts: its card goes up. (ActivityKit starts cards only while the app is in front, as it is here.) */
|
|
58
|
+
export function startChoreCard(choreId: string, prompt: string): void {
|
|
59
|
+
if (!native || cards.has(choreId) || !enabled()) return;
|
|
60
|
+
const began = nowS();
|
|
61
|
+
const card: Card = {
|
|
62
|
+
title: cardTitle(prompt),
|
|
63
|
+
began,
|
|
64
|
+
state: { kind: cardKind(prompt), phase: 'working', detail: 'Getting started', startedAt: began },
|
|
65
|
+
};
|
|
66
|
+
cards.set(choreId, card);
|
|
67
|
+
native.start(choreId, card.title, card.state).catch(() => cards.delete(choreId));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What Lucy says she is doing now. The call starting restarts the timer, so it shows the call's own length. */
|
|
71
|
+
export function choreCardStatus(choreId: string, status: string): void {
|
|
72
|
+
const card = cards.get(choreId);
|
|
73
|
+
const line = status.trim();
|
|
74
|
+
if (!card || !line || line === card.state.detail) return;
|
|
75
|
+
if (card.callAt === undefined && callStarts(line)) card.callAt = nowS();
|
|
76
|
+
card.state = {
|
|
77
|
+
...card.state,
|
|
78
|
+
kind: cardKind(line, card.state.kind),
|
|
79
|
+
phase: 'working',
|
|
80
|
+
detail: line,
|
|
81
|
+
startedAt: card.callAt ?? card.began,
|
|
82
|
+
};
|
|
83
|
+
show(choreId, card);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Lucy asks something: the card says so until she has her answer. */
|
|
87
|
+
export function choreCardAsks(choreId: string, question: string): void {
|
|
88
|
+
const card = cards.get(choreId);
|
|
89
|
+
if (!card || card.state.phase === 'asking') return;
|
|
90
|
+
card.state = { ...card.state, phase: 'asking', detail: question };
|
|
91
|
+
show(choreId, card);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Her answer is in: back to work. */
|
|
95
|
+
export function choreCardResumes(choreId: string): void {
|
|
96
|
+
const card = cards.get(choreId);
|
|
97
|
+
if (!card) return;
|
|
98
|
+
card.state = { ...card.state, phase: 'working', detail: 'Back on it' };
|
|
99
|
+
show(choreId, card);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The chore ends: done (with the time Lucy spent), failed, or stopped (gone at once). */
|
|
103
|
+
export function endChoreCard(choreId: string, outcome: 'done' | 'failed' | 'stopped', reply = ''): void {
|
|
104
|
+
const card = cards.get(choreId);
|
|
105
|
+
if (!card || !native) return;
|
|
106
|
+
cards.delete(choreId);
|
|
107
|
+
if (outcome === 'stopped') {
|
|
108
|
+
native.end(choreId, null, 0).catch(() => undefined);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const now = nowS();
|
|
112
|
+
const state: CardState =
|
|
113
|
+
outcome === 'done'
|
|
114
|
+
? {
|
|
115
|
+
...card.state,
|
|
116
|
+
phase: 'done',
|
|
117
|
+
detail: cardSummary(reply) || 'All done',
|
|
118
|
+
minutesBack: minutesSpent(card.began, now),
|
|
119
|
+
}
|
|
120
|
+
: { ...card.state, phase: 'failed', detail: 'Open Clockbook to see what happened' };
|
|
121
|
+
const shown = now - card.began < QUICK_S ? 0 : outcome === 'done' ? DONE_SHOWN_S : FAILED_SHOWN_S;
|
|
122
|
+
native.end(choreId, state, shown).catch(() => undefined);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type CardToken = { kind: 'card'; choreId: string; token: string } | { kind: 'start'; token: string };
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Each card's push token, by chore: Yantra moves the card with it while the app is closed (chat/jobs.ts puts it on the
|
|
129
|
+
* chore's record). Kept on the phone, since a card outlives the app's run (an answer to Lucy's question goes on the
|
|
130
|
+
* card started before), and iOS reports a card's token only when it is started.
|
|
131
|
+
*/
|
|
132
|
+
const CARD_TOKENS_KEY = 'clockbook.lucy.cardTokens';
|
|
133
|
+
const MAX_CARD_TOKENS = 30;
|
|
134
|
+
let cardTokens: Map<string, string> | null = null;
|
|
135
|
+
const cardTokenListeners = new Set<(choreId: string, token: string) => void>();
|
|
136
|
+
|
|
137
|
+
async function loadCardTokens(): Promise<Map<string, string>> {
|
|
138
|
+
if (cardTokens) return cardTokens;
|
|
139
|
+
let saved: [string, string][] = [];
|
|
140
|
+
try {
|
|
141
|
+
const raw = await AsyncStorage.getItem(CARD_TOKENS_KEY);
|
|
142
|
+
if (raw) saved = JSON.parse(raw) as [string, string][];
|
|
143
|
+
} catch {
|
|
144
|
+
// none kept
|
|
145
|
+
}
|
|
146
|
+
// A token reported while this was read is newer: it stays.
|
|
147
|
+
cardTokens = new Map([...(Array.isArray(saved) ? saved : []), ...(cardTokens ?? [])]);
|
|
148
|
+
return cardTokens;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function keepCardToken(choreId: string, token: string): void {
|
|
152
|
+
const tokens = cardTokens ?? new Map<string, string>();
|
|
153
|
+
cardTokens = tokens;
|
|
154
|
+
tokens.delete(choreId);
|
|
155
|
+
tokens.set(choreId, token);
|
|
156
|
+
while (tokens.size > MAX_CARD_TOKENS) tokens.delete(tokens.keys().next().value as string);
|
|
157
|
+
AsyncStorage.setItem(CARD_TOKENS_KEY, JSON.stringify([...tokens])).catch(() => undefined);
|
|
158
|
+
cardTokenListeners.forEach((l) => l(choreId, token));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The push token of a chore's card, when it has one. */
|
|
162
|
+
export async function cardTokenFor(choreId: string): Promise<string | undefined> {
|
|
163
|
+
return (await loadCardTokens()).get(choreId);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Told each time a card reports a (new) token. */
|
|
167
|
+
export function onCardToken(listener: (choreId: string, token: string) => void): () => void {
|
|
168
|
+
cardTokenListeners.add(listener);
|
|
169
|
+
return () => cardTokenListeners.delete(listener);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// From the app's start: a card reports its token once, a moment after it goes up.
|
|
173
|
+
native?.addListener('onPushToken', (e: { choreId: string; token: string }) => keepCardToken(e.choreId, e.token));
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The tokens Yantra needs to move cards while the app is closed: one per card (its updates and end) and, from
|
|
177
|
+
* iOS 17.2, one to start a card for a chore begun elsewhere. Card tokens go on each chore's record (chat/jobs.ts);
|
|
178
|
+
* push-to-start tokens have no place on Yantra yet (README.md).
|
|
179
|
+
*/
|
|
180
|
+
export function onCardTokens(listener: (token: CardToken) => void): () => void {
|
|
181
|
+
if (!native) return () => undefined;
|
|
182
|
+
const card = native.addListener('onPushToken', (e: { choreId: string; token: string }) =>
|
|
183
|
+
listener({ kind: 'card', choreId: e.choreId, token: e.token }),
|
|
184
|
+
);
|
|
185
|
+
const start = native.addListener('onPushToStartToken', (e: { token: string }) =>
|
|
186
|
+
listener({ kind: 'start', token: e.token }),
|
|
187
|
+
);
|
|
188
|
+
return () => {
|
|
189
|
+
card.remove();
|
|
190
|
+
start.remove();
|
|
191
|
+
};
|
|
192
|
+
}
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
import { Feature } from '@common-stack/client-react';
|
|
3
|
+
import { filteredRoutes } from './compute';
|
|
4
|
+
|
|
5
|
+
export default new Feature({
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
routeConfig: filteredRoutes as any,
|
|
8
|
+
});
|