@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.
- package/.claude-flow/data/pending-insights.jsonl +43 -0
- package/.claude-flow/sessions/session-1794323376548.json +14 -0
- package/CHANGELOG.md +31 -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 +42 -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 +21 -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 +2711 -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 +179 -0
- package/src/__tests__/choresList.test.ts +100 -0
- package/src/__tests__/content.test.ts +54 -0
- package/src/__tests__/dictation.test.ts +186 -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 +65 -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 +37 -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 +2773 -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,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of a view that runs to the bottom of the screen the keyboard still covers, in points.
|
|
3
|
+
*
|
|
4
|
+
* Android does one of two things when the keyboard comes up. An app drawn edge to edge (Android 16, which no longer
|
|
5
|
+
* lets an app opt out) keeps its full height and the keyboard lies over its bottom. An app that is not (Android 15
|
|
6
|
+
* and older: Expo 53 leaves edge to edge off and the app asks for `resize`) has its window shrunk to end at the
|
|
7
|
+
* keyboard: the system has made the room already. Padding by the whole keyboard on such a phone made the room twice
|
|
8
|
+
* and pushed the chat's composer up under the header.
|
|
9
|
+
*/
|
|
10
|
+
export function keyboardCover({
|
|
11
|
+
keyboard,
|
|
12
|
+
navBar = 0,
|
|
13
|
+
madeBySystem = 0,
|
|
14
|
+
}: {
|
|
15
|
+
/** The keyboard's height (0 while it is down). */
|
|
16
|
+
keyboard: number;
|
|
17
|
+
/** Android's navigation bar: the keyboard covers it too, but leaves it out of its height. */
|
|
18
|
+
navBar?: number;
|
|
19
|
+
/** How much the system shrank the view for the keyboard. */
|
|
20
|
+
madeBySystem?: number;
|
|
21
|
+
}): number {
|
|
22
|
+
if (keyboard <= 0) return 0;
|
|
23
|
+
return Math.max(0, Math.round(keyboard + navBar - Math.max(0, madeBySystem)));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Before the view has been measured with the keyboard up: whether the window shrinks for it. What it did the last time
|
|
28
|
+
* the keyboard came up decides; before that, whether the app is drawn under the system bars, as a window that is not
|
|
29
|
+
* (no insets at all) is the one Android shrinks.
|
|
30
|
+
*/
|
|
31
|
+
export function windowShrinksGuess(seen: boolean | null, insets: { top: number; bottom: number }): boolean {
|
|
32
|
+
return seen ?? (insets.top === 0 && insets.bottom === 0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A layout this soon before the keyboard's event can be the window already shrinking for it. */
|
|
36
|
+
const JUST_BEFORE_MS = 250;
|
|
37
|
+
/** Points of rounding between the keyboard's height and the shrink it causes. */
|
|
38
|
+
const SAME_HEIGHT = 2;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A view's height with the keyboard down, kept from its layouts, so the room the system made is that height less the
|
|
42
|
+
* view's height with the keyboard up.
|
|
43
|
+
*
|
|
44
|
+
* The latest height counts, not the tallest: the first layouts of a screen can be taller for a moment (before the
|
|
45
|
+
* status bar's inset arrives), and that was taken for 49 points of room the system never made. One exception: the
|
|
46
|
+
* shrunk layout can arrive just before the keyboard's own event, so a shrink of exactly the keyboard's height a moment
|
|
47
|
+
* before it is the keyboard's, and the height before it counts.
|
|
48
|
+
*/
|
|
49
|
+
export class RestHeight {
|
|
50
|
+
private height = 0;
|
|
51
|
+
|
|
52
|
+
private before = 0;
|
|
53
|
+
|
|
54
|
+
private at = Number.NEGATIVE_INFINITY;
|
|
55
|
+
|
|
56
|
+
/** A layout while the keyboard is down. */
|
|
57
|
+
seen(height: number, at: number): void {
|
|
58
|
+
if (height === this.height) return;
|
|
59
|
+
this.before = this.height;
|
|
60
|
+
this.height = height;
|
|
61
|
+
this.at = at;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The height to count from when a keyboard of this height came up at `at`; 0 before any layout. */
|
|
65
|
+
base(keyboard: number, at: number): number {
|
|
66
|
+
const shrink = this.before - this.height;
|
|
67
|
+
const keyboardsOwn = at - this.at <= JUST_BEFORE_MS && Math.abs(shrink - keyboard) <= SAME_HEIGHT;
|
|
68
|
+
return keyboardsOwn ? this.before : this.height;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the on-screen keyboard is. iOS says so as it starts to move (`keyboardWill…`), Android only once it has
|
|
3
|
+
* (`keyboardDid…`: it sends no "will" events).
|
|
4
|
+
*
|
|
5
|
+
* Each screen makes its own room, with `useKeyboardCover`: on Android the system sometimes has made it already (see
|
|
6
|
+
* `keyboardCover`).
|
|
7
|
+
*/
|
|
8
|
+
import { useCallback, useEffect, useRef, useState, type RefObject } from 'react';
|
|
9
|
+
import { Dimensions, Keyboard, Platform, type KeyboardEvent, type LayoutChangeEvent, type View } from 'react-native';
|
|
10
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
11
|
+
import { keyboardCover, RestHeight, windowShrinksGuess } from './keyboardCover';
|
|
12
|
+
|
|
13
|
+
export interface KeyboardState {
|
|
14
|
+
/** The keyboard is up. */
|
|
15
|
+
shown: boolean;
|
|
16
|
+
/** How tall it is, in points; 0 when it is down. */
|
|
17
|
+
height: number;
|
|
18
|
+
/** Where its top edge sits on the screen, in points; null when it is down. */
|
|
19
|
+
top: number | null;
|
|
20
|
+
/** How long it takes to move (iOS; 0 on Android). */
|
|
21
|
+
duration: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DOWN: KeyboardState = { shown: false, height: 0, top: null, duration: 0 };
|
|
25
|
+
|
|
26
|
+
export const KEYBOARD_SHOW = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
|
|
27
|
+
export const KEYBOARD_HIDE = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';
|
|
28
|
+
|
|
29
|
+
export function useKeyboard(): KeyboardState {
|
|
30
|
+
const [state, setState] = useState<KeyboardState>(DOWN);
|
|
31
|
+
// Android leaves the navigation bar out of the keyboard's height and puts its top that much too low: the keyboard
|
|
32
|
+
// also covers the bar, so its real top is the screen's bottom less both.
|
|
33
|
+
const navBar = useSafeAreaInsets().bottom;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const show = Keyboard.addListener(KEYBOARD_SHOW, (e: KeyboardEvent) =>
|
|
36
|
+
setState({
|
|
37
|
+
shown: true,
|
|
38
|
+
height: e.endCoordinates.height,
|
|
39
|
+
top:
|
|
40
|
+
Platform.OS === 'android'
|
|
41
|
+
? Dimensions.get('screen').height - e.endCoordinates.height - navBar
|
|
42
|
+
: e.endCoordinates.screenY,
|
|
43
|
+
duration: e.duration ?? 0,
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
// iOS also moves it without hiding (another keyboard, the suggestion bar): keep up with that.
|
|
47
|
+
const change =
|
|
48
|
+
Platform.OS === 'ios'
|
|
49
|
+
? Keyboard.addListener('keyboardWillChangeFrame', (e: KeyboardEvent) =>
|
|
50
|
+
setState((prev) =>
|
|
51
|
+
prev.shown
|
|
52
|
+
? {
|
|
53
|
+
shown: true,
|
|
54
|
+
height: e.endCoordinates.height,
|
|
55
|
+
top: e.endCoordinates.screenY,
|
|
56
|
+
duration: e.duration ?? 0,
|
|
57
|
+
}
|
|
58
|
+
: prev,
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
: null;
|
|
62
|
+
const hide = Keyboard.addListener(KEYBOARD_HIDE, (e: KeyboardEvent) =>
|
|
63
|
+
setState({ ...DOWN, duration: e?.duration ?? 0 }),
|
|
64
|
+
);
|
|
65
|
+
return () => {
|
|
66
|
+
show.remove();
|
|
67
|
+
change?.remove();
|
|
68
|
+
hide.remove();
|
|
69
|
+
};
|
|
70
|
+
}, [navBar]);
|
|
71
|
+
return state;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Whether this app's window shrinks for the keyboard, once a keyboard has shown it (one answer for the whole app). */
|
|
75
|
+
let shrinksSeen: boolean | null = null;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* How much of one view the keyboard covers, in points (0 while it is down), for a view that runs to the bottom of the
|
|
79
|
+
* screen: pad or scroll by `covers`. `view` is that view, and `onLayout` goes on it. Some Android phones shrink the
|
|
80
|
+
* window for the keyboard and some do not; the view's own height says which, and only what the system has not made
|
|
81
|
+
* room for counts (iOS never shrinks it).
|
|
82
|
+
*/
|
|
83
|
+
export function useKeyboardCover(view: RefObject<View | null>): {
|
|
84
|
+
keyboard: KeyboardState;
|
|
85
|
+
covers: number;
|
|
86
|
+
onLayout: (e: LayoutChangeEvent) => void;
|
|
87
|
+
} {
|
|
88
|
+
const keyboard = useKeyboard();
|
|
89
|
+
const insets = useSafeAreaInsets();
|
|
90
|
+
const android = Platform.OS === 'android';
|
|
91
|
+
// How much the system shrank the view for the keyboard now up, once measured.
|
|
92
|
+
const [measured, setMeasured] = useState<number | null>(null);
|
|
93
|
+
const rest = useRef(new RestHeight());
|
|
94
|
+
const up = useRef<{ keyboard: number; at: number } | null>(null);
|
|
95
|
+
const madeFrom = useCallback((height: number) => {
|
|
96
|
+
const shown = up.current;
|
|
97
|
+
if (!shown || height <= 0) return;
|
|
98
|
+
const made = Math.max(0, rest.current.base(shown.keyboard, shown.at) - height);
|
|
99
|
+
shrinksSeen = made >= shown.keyboard / 2;
|
|
100
|
+
setMeasured(made);
|
|
101
|
+
}, []);
|
|
102
|
+
const onLayout = useCallback(
|
|
103
|
+
(e: LayoutChangeEvent) => {
|
|
104
|
+
const { height } = e.nativeEvent.layout;
|
|
105
|
+
if (up.current) madeFrom(height);
|
|
106
|
+
else rest.current.seen(height, Date.now());
|
|
107
|
+
},
|
|
108
|
+
[madeFrom],
|
|
109
|
+
);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!android) return undefined;
|
|
112
|
+
const show = Keyboard.addListener(KEYBOARD_SHOW, (e: KeyboardEvent) => {
|
|
113
|
+
up.current = { keyboard: e.endCoordinates.height, at: Date.now() };
|
|
114
|
+
setMeasured(null);
|
|
115
|
+
view.current?.measure((_x, _y, _width, height) => madeFrom(height));
|
|
116
|
+
});
|
|
117
|
+
const hide = Keyboard.addListener(KEYBOARD_HIDE, () => {
|
|
118
|
+
up.current = null;
|
|
119
|
+
setMeasured(null);
|
|
120
|
+
});
|
|
121
|
+
return () => {
|
|
122
|
+
show.remove();
|
|
123
|
+
hide.remove();
|
|
124
|
+
};
|
|
125
|
+
}, [android, view, madeFrom]);
|
|
126
|
+
// The view's new height reaches JS a few frames after the keyboard's event; until it does, the room goes by what
|
|
127
|
+
// the window did before (or by the system bars), so the composer does not jump up under the header meanwhile.
|
|
128
|
+
const made = measured ?? (windowShrinksGuess(shrinksSeen, insets) ? keyboard.height : 0);
|
|
129
|
+
const covers = keyboardCover({
|
|
130
|
+
keyboard: keyboard.shown ? keyboard.height : 0,
|
|
131
|
+
navBar: android ? insets.bottom : 0,
|
|
132
|
+
madeBySystem: android ? made : 0,
|
|
133
|
+
});
|
|
134
|
+
return { keyboard, covers, onLayout };
|
|
135
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { AccessibilityInfo } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** The phone's "Reduce Motion" setting, kept current while the screen is open. */
|
|
5
|
+
export function useReducedMotion(): boolean {
|
|
6
|
+
const [reduced, setReduced] = useState(false);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
let alive = true;
|
|
9
|
+
AccessibilityInfo.isReduceMotionEnabled()
|
|
10
|
+
.then((value) => alive && setReduced(value))
|
|
11
|
+
.catch(() => undefined);
|
|
12
|
+
const sub = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduced);
|
|
13
|
+
return () => {
|
|
14
|
+
alive = false;
|
|
15
|
+
sub.remove();
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
return reduced;
|
|
19
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens the phone's own Messages app at Lucy's line with the first text ready.
|
|
3
|
+
*
|
|
4
|
+
* - iOS: the Messages app itself, by the `sms:` link, so the conversation with Lucy carries on there. Apple's in-app
|
|
5
|
+
* composer (MFMessageComposeViewController) is only the fallback: it sends one text and closes, which read as
|
|
6
|
+
* Messages opening and then shutting on the person.
|
|
7
|
+
* - Android: the phone's default SMS app (Telephony's default SMS package), which WhatsApp can never be (a bare `sms:`
|
|
8
|
+
* link goes to whichever app claims it, and WhatsApp claims it once picked "always"). The link is the last resort.
|
|
9
|
+
* The composer and the default SMS app come from expo-sms's native module; a build without it gets the link.
|
|
10
|
+
*/
|
|
11
|
+
import { Linking, Platform } from 'react-native';
|
|
12
|
+
import { requireOptionalNativeModule } from 'expo-modules-core';
|
|
13
|
+
|
|
14
|
+
interface ExpoSmsModule {
|
|
15
|
+
isAvailableAsync?: () => Promise<boolean>;
|
|
16
|
+
sendSMSAsync?: (addresses: string[], message: string, options: object) => Promise<{ result: string }>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let native: ExpoSmsModule | null | undefined;
|
|
20
|
+
function sms(): ExpoSmsModule | null {
|
|
21
|
+
if (native === undefined) native = requireOptionalNativeModule<ExpoSmsModule>('ExpoSMS');
|
|
22
|
+
return native;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MessagesTarget {
|
|
26
|
+
/** Lucy's line: the iCloud handle or the SMS number. Never print it. */
|
|
27
|
+
to: string;
|
|
28
|
+
/** The first text, hidden pairing code included. */
|
|
29
|
+
body: string;
|
|
30
|
+
/** The same as an `sms:` link, for builds without the native composer. */
|
|
31
|
+
href: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** True when Messages opened (or its composer showed); false when nothing on this phone could. */
|
|
35
|
+
export async function openMessages({ to, body, href }: MessagesTarget): Promise<boolean> {
|
|
36
|
+
if (Platform.OS === 'ios') {
|
|
37
|
+
const opened = await Linking.openURL(href)
|
|
38
|
+
.then(() => true)
|
|
39
|
+
.catch(() => false);
|
|
40
|
+
if (opened) return true;
|
|
41
|
+
}
|
|
42
|
+
const mod = sms();
|
|
43
|
+
if (mod?.sendSMSAsync && (await mod.isAvailableAsync?.().catch(() => false))) {
|
|
44
|
+
const sent = await mod
|
|
45
|
+
.sendSMSAsync([to], body, {})
|
|
46
|
+
.then(() => true)
|
|
47
|
+
.catch(() => false);
|
|
48
|
+
if (sent) return true;
|
|
49
|
+
}
|
|
50
|
+
return Linking.openURL(href)
|
|
51
|
+
.then(() => true)
|
|
52
|
+
.catch(() => false);
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Texting Lucy, said for the phone in the hand - as Yantra's app does (account/mobile features/channels
|
|
3
|
+
* HomeImessage.tsx, ConnectAppsSheet.tsx `smsOnly`). An iPhone texts Lucy's iMessage handle; an Android phone cannot
|
|
4
|
+
* text an Apple ID, so it texts the SMS/RCS number forwarding to the same line, in its Messages app. Everything that
|
|
5
|
+
* names the app or shows its icon reads from here, so an Android phone never sees "iMessage".
|
|
6
|
+
*/
|
|
7
|
+
import { Platform } from 'react-native';
|
|
8
|
+
|
|
9
|
+
export const ANDROID = Platform.OS === 'android';
|
|
10
|
+
|
|
11
|
+
/** The app Lucy is texted in: iMessage on Apple devices, Messages (SMS/RCS) on Android. */
|
|
12
|
+
export const MESSAGES_APP = ANDROID ? 'Messages' : 'iMessage';
|
|
13
|
+
|
|
14
|
+
/** The button that opens the texting sheet. */
|
|
15
|
+
export const TEXT_LUCY = `Text Lucy on ${MESSAGES_APP}`;
|
|
16
|
+
|
|
17
|
+
/** What the phone is called once it is linked. */
|
|
18
|
+
export const LINKED_THING = ANDROID ? 'phone' : 'iPhone';
|
|
19
|
+
|
|
20
|
+
/** Where the person can text Lucy from. */
|
|
21
|
+
export const TEXT_FROM = ANDROID ? 'your phone' : 'your iPhone, iPad or Mac';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The web's TEXT_STEPS (content.ts), with the button they name and the devices they promise matched to this phone.
|
|
25
|
+
*/
|
|
26
|
+
export function textSteps(steps: readonly { title: string; body: string }[]): { title: string; body: string }[] {
|
|
27
|
+
if (!ANDROID) return [...steps];
|
|
28
|
+
return steps.map((step) => ({
|
|
29
|
+
title: step.title,
|
|
30
|
+
body: step.body.replace(/Text Lucy on iMessage/g, TEXT_LUCY).replace(/iPhone, iPad or Mac/g, TEXT_FROM),
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
@@ -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';
|