@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,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which logo animation goes with what Lucy says she is doing. The words come from the tool she is using
|
|
3
|
+
* (toolLine in protocol.ts) or a status from the agent, so anything not recognised falls back to thinking.
|
|
4
|
+
*/
|
|
5
|
+
export const LUCY_MOTIONS = [
|
|
6
|
+
'think',
|
|
7
|
+
'write',
|
|
8
|
+
'call',
|
|
9
|
+
'calendar',
|
|
10
|
+
'email',
|
|
11
|
+
'search',
|
|
12
|
+
'message',
|
|
13
|
+
'details',
|
|
14
|
+
'connect',
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export type LucyMotion = (typeof LUCY_MOTIONS)[number];
|
|
18
|
+
|
|
19
|
+
const RULES: readonly (readonly [RegExp, LucyMotion])[] = [
|
|
20
|
+
[/connect|waiting|queued/, 'connect'],
|
|
21
|
+
[/\bcall|\bdial|\bphone/, 'call'],
|
|
22
|
+
[/calendar|schedul|\bbook|meeting|appointment/, 'calendar'],
|
|
23
|
+
[/e-?mail|inbox/, 'email'],
|
|
24
|
+
[/\blook|search|brows|\bfind|research/, 'search'],
|
|
25
|
+
[/messag|\btext|\bsms|\bsend/, 'message'],
|
|
26
|
+
[/\bwrit|draft/, 'write'],
|
|
27
|
+
[/\bwork|detail|\bread|\bedit|\bfile/, 'details'],
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export function motionFor(words: string): LucyMotion {
|
|
31
|
+
const text = words.toLowerCase();
|
|
32
|
+
return RULES.find(([rule]) => rule.test(text))?.[1] ?? 'think';
|
|
33
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Lucy's agent says, made readable: the same rules the web chat applies (@yantra/surface-kit agentChat.ts
|
|
3
|
+
* visibleAgentOutput, chat/askUser.ts), without the DOM. Pure functions; tested in __tests__/protocol.test.ts.
|
|
4
|
+
*/
|
|
5
|
+
// Lucy's own prompt and how she hands over results as cards, read-only from the browser package's build.
|
|
6
|
+
import { LUCY_SYSTEM_PROMPT } from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/lucy.js';
|
|
7
|
+
import {
|
|
8
|
+
RESULT_CARDS_PROMPT,
|
|
9
|
+
takeResultWidgets,
|
|
10
|
+
} from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/results.js';
|
|
11
|
+
|
|
12
|
+
export const MAX_QUESTIONS = 6;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* How to ask instead of asking in prose (the web's ASK_USER_SYSTEM_PROMPT), minus what this app does not draw yet:
|
|
16
|
+
* attachments and audio previews.
|
|
17
|
+
*/
|
|
18
|
+
export const ASK_USER_PROMPT = [
|
|
19
|
+
'CLARIFYING QUESTIONS: When you need information from the user before you can act (missing details, a choice between approaches), do NOT ask in prose. Instead reply with ONLY this marker (no other text before or after):',
|
|
20
|
+
'[ASK_USER]{"requestId":"<short-unique-id>","questions":[{"id":"<id>","title":"<the question>","options":[{"id":"<id>","label":"<choice>"}],"allowText":true,"textPlaceholder":"<hint for free-text>"}]}[/ASK_USER]',
|
|
21
|
+
`Rules: 1-${MAX_QUESTIONS} questions max, shown one at a time (the user can skip any, or type their own answer); options are optional (omit for pure free-text questions); keep titles short — they are echoed back as "**title:** answer", and a skipped question is left out. The UI renders this as an interactive card, so the raw marker is never shown to the user. Only use it when genuinely blocked on user input; if you can proceed with sensible assumptions, proceed.`,
|
|
22
|
+
'Optional fields: a question\'s "header" (a 1-2 word topic above it); "multiSelect":true when several options can apply (the answer is their labels, comma-separated). An option\'s "detail" (one line under the label).',
|
|
23
|
+
].join('\n');
|
|
24
|
+
|
|
25
|
+
/** The session's system prompt: Lucy, then how to ask. Set once, when the session opens. */
|
|
26
|
+
export const SYSTEM_PROMPT = `${LUCY_SYSTEM_PROMPT}\n\n${ASK_USER_PROMPT}`;
|
|
27
|
+
|
|
28
|
+
/** Sent with a new turn id when a step was cut off part-way (agentChat.ts AGENT_CONTINUE_PROMPT). */
|
|
29
|
+
export const CONTINUE_PROMPT =
|
|
30
|
+
'[Note from the app, not from the user: your last step was cut off by a temporary problem on our side, ' +
|
|
31
|
+
'after some of its actions had already run. Everything you already did is in the conversation above. ' +
|
|
32
|
+
"Carry on with the user's request from where you stopped, and do not repeat an action that already went through.]";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A turn as the agent gets it: the person's words, then how to hand over flights and products so the chat draws them
|
|
36
|
+
* as cards (components/ResultCards.tsx), for the agent alone, in the Yantra app's `<agent-context>` envelope (the web's
|
|
37
|
+
* lucyTurn). It rides every turn because a session keeps the system prompt it opened with. The thread, the chore
|
|
38
|
+
* record and History keep the words as typed.
|
|
39
|
+
*/
|
|
40
|
+
export function agentTurn(words: string): string {
|
|
41
|
+
return `${words}\n\n<agent-context>${RESULT_CARDS_PROMPT.trim()}</agent-context>`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line no-control-regex
|
|
45
|
+
const ANSI = /\u001b\[[0-9;]*m/g;
|
|
46
|
+
const TERMINAL_QUESTION =
|
|
47
|
+
/^\s*[╭╮╰╯│─┌┐└┘├┤]|^\s*(?:Answer 1-\d+(?: \(comma-separated\))? or type your own|Type your answer); Enter to skip:?\s*$|^ {2}(?:✓ |⨯ Skipped)/u;
|
|
48
|
+
const TERMINAL_ACCOUNTING =
|
|
49
|
+
/^\s*(?:⚡ Tokens: |💡 (?:Context growing fast|\d+ tool-use iterations detected|Session cost \$)|⚠ billing policy check unavailable \(.*allowing metered action\s*$|⚠ billing policy: .*\(CDECLI_BILLING_POLICY=warn: not blocking\)\s*$)/u;
|
|
50
|
+
|
|
51
|
+
/** A whole `output` event, minus the terminal's own furniture. */
|
|
52
|
+
export function visibleOutput(text: string): string {
|
|
53
|
+
return text
|
|
54
|
+
.replace(ANSI, '')
|
|
55
|
+
.replace(/\[CDECLI_ASK_USER_QUESTION\][\s\S]*?(?:\[\/CDECLI_ASK_USER_QUESTION\]|$)/g, '')
|
|
56
|
+
.split('\n')
|
|
57
|
+
.filter((line) => !/^\s*🧠/u.test(line) && !TERMINAL_ACCOUNTING.test(line) && !TERMINAL_QUESTION.test(line))
|
|
58
|
+
.join('\n')
|
|
59
|
+
.trimStart();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** What goes between the reply so far and a following output, so the output starts its own paragraph. */
|
|
63
|
+
export function joinOutput(reply: string, output: string): string {
|
|
64
|
+
if (!output) return reply;
|
|
65
|
+
if (!reply) return output;
|
|
66
|
+
if (reply.endsWith('\n\n')) return reply + output;
|
|
67
|
+
return reply + (reply.endsWith('\n') ? '\n' : '\n\n') + output;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* ----------------------------------------------------------------------------- question cards */
|
|
71
|
+
|
|
72
|
+
export interface AskOption {
|
|
73
|
+
id: string;
|
|
74
|
+
label: string;
|
|
75
|
+
detail?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface AskQuestion {
|
|
78
|
+
id: string;
|
|
79
|
+
header?: string;
|
|
80
|
+
title: string;
|
|
81
|
+
options: AskOption[];
|
|
82
|
+
allowText: boolean;
|
|
83
|
+
textPlaceholder?: string;
|
|
84
|
+
multiSelect: boolean;
|
|
85
|
+
}
|
|
86
|
+
export interface AskUser {
|
|
87
|
+
requestId: string;
|
|
88
|
+
questions: AskQuestion[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const ASK_RE = /\[ASK_USER\]([\s\S]*?)\[\/ASK_USER\]/;
|
|
92
|
+
const ASK_RE_ALL = /\[ASK_USER\][\s\S]*?(?:\[\/ASK_USER\]|$)/g;
|
|
93
|
+
|
|
94
|
+
/** The question card in a reply, if it has a whole one. */
|
|
95
|
+
export function parseAskUser(text: string): AskUser | null {
|
|
96
|
+
const m = ASK_RE.exec(text);
|
|
97
|
+
if (!m) return null;
|
|
98
|
+
let raw: { requestId?: string; questions?: unknown[] };
|
|
99
|
+
try {
|
|
100
|
+
raw = JSON.parse(m[1].trim());
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const questions = (Array.isArray(raw?.questions) ? raw.questions : [])
|
|
105
|
+
.slice(0, MAX_QUESTIONS)
|
|
106
|
+
.map((q, i): AskQuestion | null => {
|
|
107
|
+
const o = q as Record<string, unknown>;
|
|
108
|
+
const title = String(o.title ?? o.question ?? '').trim();
|
|
109
|
+
if (!title) return null;
|
|
110
|
+
const options = (Array.isArray(o.options) ? o.options : []).map((op, j): AskOption => {
|
|
111
|
+
if (typeof op === 'string') return { id: `o${j}`, label: op };
|
|
112
|
+
const p = op as Record<string, unknown>;
|
|
113
|
+
return {
|
|
114
|
+
id: String(p.id ?? `o${j}`),
|
|
115
|
+
label: String(p.label ?? ''),
|
|
116
|
+
detail: (p.detail ?? p.description) ? String(p.detail ?? p.description) : undefined,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
id: String(o.id ?? `q${i}`),
|
|
121
|
+
header: o.header ? String(o.header) : undefined,
|
|
122
|
+
title,
|
|
123
|
+
options: options.filter((op) => op.label),
|
|
124
|
+
allowText: o.allowText !== false,
|
|
125
|
+
textPlaceholder: o.textPlaceholder ? String(o.textPlaceholder) : undefined,
|
|
126
|
+
multiSelect: o.multiSelect === true,
|
|
127
|
+
};
|
|
128
|
+
})
|
|
129
|
+
.filter((q): q is AskQuestion => q !== null);
|
|
130
|
+
if (!questions.length) return null;
|
|
131
|
+
return { requestId: String(raw.requestId ?? 'ask'), questions };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** One answer: picked option labels, or typed text (typed text wins). Empty = skipped. */
|
|
135
|
+
export interface AskAnswer {
|
|
136
|
+
picked: string[];
|
|
137
|
+
text: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The answer message, as the web sends it: "**Title:** answer" paragraphs, skipped questions left out. */
|
|
141
|
+
export function formatAskAnswers(ask: AskUser, answers: Record<string, AskAnswer>): string {
|
|
142
|
+
return ask.questions
|
|
143
|
+
.map((q) => {
|
|
144
|
+
const a = answers[q.id];
|
|
145
|
+
const value = a?.text.trim() || (a?.picked.length ? a.picked.join(', ') : '');
|
|
146
|
+
if (!value) return '';
|
|
147
|
+
return `**${q.title.replace(/[::]\s*$/, '')}:** ${value}`;
|
|
148
|
+
})
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.join('\n\n');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* ----------------------------------------------------------------------------- display */
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A reply's text as the bubble shows it: no question block (it has its own card), no result blocks in any of the forms
|
|
157
|
+
* a model writes them (fenced, under a bare marker, or still streaming in: they draw as cards), and the web-only
|
|
158
|
+
* markers either dropped (Connect cards, other widgets) or reduced to a plain label (surface links).
|
|
159
|
+
*/
|
|
160
|
+
export function displayText(text: string): string {
|
|
161
|
+
return takeResultWidgets(text)
|
|
162
|
+
.content.replace(ASK_RE_ALL, '')
|
|
163
|
+
.replace(/\[CONNECTOR_CONNECT\][\s\S]*?(?:\[\/CONNECTOR_CONNECT\]|$)/g, '')
|
|
164
|
+
.replace(/```yantra:widget[\s\S]*?(?:```|$)/g, '')
|
|
165
|
+
.replace(/\[\[surface:[^|\]]+\|([^\]]+)\]\]/g, '$1')
|
|
166
|
+
.replace(/\[\[surface:([^\]]+)\]\]/g, '$1')
|
|
167
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
168
|
+
.trim();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** A short title for a chat in History: its first message. */
|
|
172
|
+
export function chatTitle(firstMessage: string): string {
|
|
173
|
+
const t = firstMessage.replace(/\*\*/g, '').replace(/\s+/g, ' ').trim();
|
|
174
|
+
return t.length > 60 ? `${t.slice(0, 57)}…` : t || 'New chat';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A progress line for a tool Lucy is using (the web's humanizeToolLine, in Clockbook's words). */
|
|
178
|
+
export function toolLine(name: string, detail?: string): string {
|
|
179
|
+
const n = `${name} ${detail ?? ''}`.toLowerCase();
|
|
180
|
+
if (/phone|call|dial|twilio|voice/.test(n)) return 'Making a call';
|
|
181
|
+
if (/calendar|schedule|booking|meeting/.test(n)) return 'Checking the calendar';
|
|
182
|
+
if (/mail|gmail|email/.test(n)) return 'Looking through email';
|
|
183
|
+
if (/search|web|browse|fetch|http|site|page/.test(n)) return 'Looking it up';
|
|
184
|
+
if (/message|sms|imessage|text/.test(n)) return 'Sending a message';
|
|
185
|
+
if (/file|read|write|edit/.test(n)) return 'Working through the details';
|
|
186
|
+
return 'Working on it';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** A status event's line without its leading glyphs. */
|
|
190
|
+
export function statusLine(status: string): string {
|
|
191
|
+
return status.replace(/^[^\p{L}\p{N}]+/u, '').trim();
|
|
192
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lucy's results on the phone. Her result blocks are read the way the web chat reads them (clock-tik-browser
|
|
3
|
+
* pages/Home/chat/results.ts: takeResults, cardPicks and the cards' view models, from its build as protocol.ts reads
|
|
4
|
+
* her prompt), so a reply draws the same flights and products here as there. What is the phone's own is here: how
|
|
5
|
+
* many rows a card shows before Show more and how it folds to a pick, the line under a card, the condition a
|
|
6
|
+
* product's title names, what a screen reader hears, and the surface with more than Lucy found (Travel or Shopping,
|
|
7
|
+
* on this environment's Yantra). Pure functions; tested in __tests__/results.test.ts. Drawn by
|
|
8
|
+
* components/ResultCards.tsx.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
cardPicks,
|
|
12
|
+
isFallbackFavicon,
|
|
13
|
+
takeResults,
|
|
14
|
+
type FlightLeg,
|
|
15
|
+
type FlightRow,
|
|
16
|
+
type FlightsCard,
|
|
17
|
+
type ListCard,
|
|
18
|
+
type ListKind,
|
|
19
|
+
type ListRow,
|
|
20
|
+
type ResultBadge,
|
|
21
|
+
type ResultCard,
|
|
22
|
+
type ResultLink,
|
|
23
|
+
} from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/results.js';
|
|
24
|
+
import { surfaceLink } from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/surfaces.js';
|
|
25
|
+
|
|
26
|
+
export { cardPicks, isFallbackFavicon, takeResults };
|
|
27
|
+
export type { FlightLeg, FlightRow, FlightsCard, ListCard, ListKind, ListRow, ResultBadge, ResultCard, ResultLink };
|
|
28
|
+
|
|
29
|
+
export const BADGES: Record<ResultBadge, string> = { pick: 'Lucy’s pick', cheapest: 'Cheapest', fastest: 'Fastest' };
|
|
30
|
+
|
|
31
|
+
/** Rows a flights card shows before Show more: three keep it about a screen tall on a phone. */
|
|
32
|
+
export const FIRST_ROWS = 3;
|
|
33
|
+
|
|
34
|
+
export interface ShownRows<T> {
|
|
35
|
+
rows: T[];
|
|
36
|
+
/** The fold's button ("Show 4 more", "Show fewer", "Show the other 6"); '' when there is nothing to fold. */
|
|
37
|
+
toggle: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The rows a card draws, in Lucy's order: the first few until it is opened, and one row past the cut shown rather
|
|
42
|
+
* than hidden behind "Show 1 more". Once a row was picked the card folds to it, and the others can be looked at again.
|
|
43
|
+
*/
|
|
44
|
+
export function shownRows<T extends { reply: string }>(
|
|
45
|
+
rows: T[],
|
|
46
|
+
open: boolean,
|
|
47
|
+
pick?: string,
|
|
48
|
+
first = FIRST_ROWS,
|
|
49
|
+
): ShownRows<T> {
|
|
50
|
+
const picked = pick ? rows.find((row) => row.reply === pick) : undefined;
|
|
51
|
+
if (picked) {
|
|
52
|
+
if (rows.length < 2) return { rows, toggle: '' };
|
|
53
|
+
if (open) return { rows, toggle: 'Show fewer' };
|
|
54
|
+
const others = rows.length - 1;
|
|
55
|
+
return { rows: [picked], toggle: others === 1 ? 'Show the other one' : `Show the other ${others}` };
|
|
56
|
+
}
|
|
57
|
+
if (rows.length <= first + 1) return { rows, toggle: '' };
|
|
58
|
+
return open
|
|
59
|
+
? { rows, toggle: 'Show fewer' }
|
|
60
|
+
: { rows: rows.slice(0, first), toggle: `Show ${rows.length - first} more` };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The word on a row's button: a product is chosen, anything else booked. */
|
|
64
|
+
export function actionWord(kind: ResultCard['kind']): 'Book' | 'Choose' {
|
|
65
|
+
return kind === 'products' ? 'Choose' : 'Book';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The line under a card: how a tap works, that Lucy has the pick, or to wait until she is done. */
|
|
69
|
+
export function noteFor(kind: ResultCard['kind'], picked: boolean, busy: boolean): string {
|
|
70
|
+
if (picked) return 'Lucy has your pick.';
|
|
71
|
+
if (busy) return `You can ${actionWord(kind).toLowerCase()} one when Lucy is done.`;
|
|
72
|
+
if (kind === 'products') return 'Tap Choose and Lucy takes it from there. Prices can change until it is bought.';
|
|
73
|
+
if (kind === 'flights')
|
|
74
|
+
return 'Tap Book and Lucy takes it from there, asking before she pays. Fares change until booked.';
|
|
75
|
+
return 'Tap Book and Lucy takes it from there, asking before she pays.';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The person's messages after the reply at `index`, in the order sent: what a card's pick is read from. */
|
|
79
|
+
export function laterWords(messages: ReadonlyArray<{ role: string; content: string }>, index: number): string[] {
|
|
80
|
+
return messages
|
|
81
|
+
.slice(index + 1)
|
|
82
|
+
.filter((m) => m.role === 'user')
|
|
83
|
+
.map((m) => m.content);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ─── More than Lucy found ────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
/** The surface a card's "more" opens: Shopping for products, Travel for flights, stays, cars and trains. */
|
|
89
|
+
export interface MoreSurface {
|
|
90
|
+
/** The surface's id ("travel"). */
|
|
91
|
+
id: string;
|
|
92
|
+
/** "Travel". */
|
|
93
|
+
title: string;
|
|
94
|
+
/** Its host's first label: "travel-surface". */
|
|
95
|
+
host: string;
|
|
96
|
+
/** "More flights in Travel". */
|
|
97
|
+
label: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const MORE_LABELS: Record<ResultCard['kind'], string> = {
|
|
101
|
+
flights: 'More flights in Travel',
|
|
102
|
+
stays: 'More stays in Travel',
|
|
103
|
+
cars: 'More cars in Travel',
|
|
104
|
+
trains: 'More trains in Travel',
|
|
105
|
+
buses: 'More buses in Travel',
|
|
106
|
+
travel: 'More in Travel',
|
|
107
|
+
products: 'More in Shopping',
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function moreSurface(kind: ResultCard['kind']): MoreSurface | null {
|
|
111
|
+
const link = surfaceLink(kind === 'products' ? 'shopping' : 'travel');
|
|
112
|
+
return link ? { id: link.id, title: link.title, host: link.host, label: MORE_LABELS[kind] } : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What the surface adds to a card: "Search beyond these 7". */
|
|
116
|
+
export function beyondLabel(count: number): string {
|
|
117
|
+
return count === 1 ? 'Search beyond this one' : `Search beyond these ${count}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The base every Yantra service hangs off, from the Yantra app's host (surface-kit auth.ts platformEnvBase; the web
|
|
122
|
+
* chat anchors it to the same app): a bare apex as it is (yantra.app), any longer host without its first label
|
|
123
|
+
* (idefront.<env> is <env>). '' for a host nothing hangs off: no dot (localhost) or a raw IP.
|
|
124
|
+
*/
|
|
125
|
+
export function platformBase(host: string): string {
|
|
126
|
+
const h = host.trim().toLowerCase();
|
|
127
|
+
if (!h.includes('.')) return '';
|
|
128
|
+
const parts = h.split('.');
|
|
129
|
+
if (parts.every((part) => /^\d+$/.test(part))) return '';
|
|
130
|
+
return parts.length <= 2 ? h : parts.slice(1).join('.');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A surface of this environment, `https://<host>.<base>/`, from the Yantra app's address (config YANTRA_APP_URL).
|
|
135
|
+
* Read with a pattern, not URL: React Native's URL has no hostname. '' when the address names no base.
|
|
136
|
+
*/
|
|
137
|
+
export function surfaceUrl(host: string, appUrl: string): string {
|
|
138
|
+
const m = /^(https?:)\/\/([^/?#:]+)/i.exec(appUrl.trim());
|
|
139
|
+
if (!m || !/^[a-z0-9-]{1,63}$/i.test(host)) return '';
|
|
140
|
+
const base = platformBase(m[2]);
|
|
141
|
+
return base ? `${m[1].toLowerCase()}//${host.toLowerCase()}.${base}/` : '';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ─── What a row says ─────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
/** "10:10 PM" as a row sets it: the time large, AM or PM small beside it. Anything else stays whole. */
|
|
147
|
+
export function splitClock(clock?: string): { time: string; half: string } {
|
|
148
|
+
const m = clock?.match(/^(\d{1,2}:\d{2})\s*([AP]M)$/i);
|
|
149
|
+
if (m) return { time: m[1], half: m[2].toUpperCase() };
|
|
150
|
+
return { time: clock || '–', half: '' };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** A leg's heading: "Outbound · Sat, Dec 12" on a round trip, the day alone when the rows leave on different days. */
|
|
154
|
+
export function legWhen(datedRows: boolean, legs: number, index: number, date?: string): string | undefined {
|
|
155
|
+
const roundTrip = legs > 1;
|
|
156
|
+
const parts = [roundTrip ? (index ? 'Return' : 'Outbound') : undefined, roundTrip || datedRows ? date : undefined];
|
|
157
|
+
return parts.filter(Boolean).join(' · ') || undefined;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const CONDITIONS: ReadonlyArray<readonly [RegExp, string]> = [
|
|
161
|
+
[/\bopen[\s-]?box\b/i, 'Open box'],
|
|
162
|
+
[/\bpre[\s-]?owned\b/i, 'Pre-owned'],
|
|
163
|
+
[/\brenewed\b/i, 'Renewed'],
|
|
164
|
+
[/\brestored\b/i, 'Restored'],
|
|
165
|
+
[/\brefurb(?:ished)?\b/i, 'Refurbished'],
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
/** The condition a product's title names (open box, pre-owned, restored...): a tile cuts a long title short. */
|
|
169
|
+
export function conditionOf(title: string): string | undefined {
|
|
170
|
+
return CONDITIONS.find(([pattern]) => pattern.test(title))?.[1];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** "+1" as a screen reader should hear it. */
|
|
174
|
+
function spokenShift(shift?: string): string {
|
|
175
|
+
if (!shift) return '';
|
|
176
|
+
const days = Number(shift);
|
|
177
|
+
if (days === 1) return ' the next day';
|
|
178
|
+
if (days > 1) return ` ${days} days later`;
|
|
179
|
+
if (days === -1) return ' the day before';
|
|
180
|
+
return ` ${-days} days before`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** What a screen reader hears for a flight: all the row shows, in a few short sentences (the web's describeFlight). */
|
|
184
|
+
export function describeFlight(row: FlightRow): string {
|
|
185
|
+
const legs = row.legs.map((leg, i) =>
|
|
186
|
+
[
|
|
187
|
+
row.legs.length > 1 ? (i ? 'Return' : 'Outbound') : undefined,
|
|
188
|
+
leg.date,
|
|
189
|
+
leg.from && leg.departs ? `leaves ${leg.from} ${leg.departs}` : leg.departs,
|
|
190
|
+
leg.to && leg.arrives ? `lands ${leg.to} ${leg.arrives}${spokenShift(leg.dayShift)}` : leg.arrives,
|
|
191
|
+
leg.duration,
|
|
192
|
+
leg.stops,
|
|
193
|
+
leg.via ? `via ${leg.via}` : undefined,
|
|
194
|
+
]
|
|
195
|
+
.filter(Boolean)
|
|
196
|
+
.join(', '),
|
|
197
|
+
);
|
|
198
|
+
return [
|
|
199
|
+
[row.airline, row.flightNumber].filter(Boolean).join(' '),
|
|
200
|
+
...row.badges.map((badge) => BADGES[badge]),
|
|
201
|
+
...legs,
|
|
202
|
+
row.fare,
|
|
203
|
+
row.selfTransfer ? 'Separate tickets' : undefined,
|
|
204
|
+
row.price,
|
|
205
|
+
]
|
|
206
|
+
.filter(Boolean)
|
|
207
|
+
.join('. ');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** What a screen reader hears for a product, a stay, a car or a train. */
|
|
211
|
+
export function describeItem(row: ListRow, condition?: string): string {
|
|
212
|
+
return [
|
|
213
|
+
row.title,
|
|
214
|
+
...row.badges.map((badge) => BADGES[badge]),
|
|
215
|
+
condition,
|
|
216
|
+
row.price ? `${row.price}${row.priceUnit ? ` ${row.priceUnit}` : ''}` : undefined,
|
|
217
|
+
row.wasPrice ? `was ${row.wasPrice}` : undefined,
|
|
218
|
+
row.rating ? `${row.rating} stars${row.reviews ? `, ${row.reviews} reviews` : ''}` : undefined,
|
|
219
|
+
row.seller,
|
|
220
|
+
row.detail,
|
|
221
|
+
]
|
|
222
|
+
.filter(Boolean)
|
|
223
|
+
.join('. ');
|
|
224
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat on this phone, per account: the open thread and past chats, as the web chat keeps them in localStorage
|
|
3
|
+
* (chat/thread.ts `cbh-chat:v1:<sub>`, chat/history.ts `cbh-history:v1:<sub>`). The agent holds each session's
|
|
4
|
+
* transcript too, so reopening a past chat and sending carries it on. Nothing here syncs with the web.
|
|
5
|
+
*/
|
|
6
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
7
|
+
|
|
8
|
+
export interface ChatMessage {
|
|
9
|
+
id: string;
|
|
10
|
+
role: 'user' | 'assistant';
|
|
11
|
+
content: string;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
/** A reply that failed: what went wrong, and whether sending again could fix it. */
|
|
14
|
+
error?: string;
|
|
15
|
+
/** The chore record this reply is (chat/jobs.ts): how it is read back when its stream did not finish here. */
|
|
16
|
+
jobId?: string;
|
|
17
|
+
/** The chore this reply is a turn of: its own id for a new one, the asking reply's chore for an answer. */
|
|
18
|
+
chore?: string;
|
|
19
|
+
/** Lucy is still on it, with nothing here streaming it (the screen left, the app reloaded): read from the record. */
|
|
20
|
+
pending?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Thread {
|
|
24
|
+
sessionId: string | null;
|
|
25
|
+
messages: ChatMessage[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PastChat extends Thread {
|
|
29
|
+
id: string;
|
|
30
|
+
title: string;
|
|
31
|
+
at: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const MAX_MESSAGES = 200;
|
|
35
|
+
const MAX_CHATS = 30;
|
|
36
|
+
const threadKey = (account: string) => `clockbook.lucy.thread:v1:${account}`;
|
|
37
|
+
const historyKey = (account: string) => `clockbook.lucy.history:v1:${account}`;
|
|
38
|
+
|
|
39
|
+
async function read<T>(key: string, fallback: T): Promise<T> {
|
|
40
|
+
try {
|
|
41
|
+
const raw = await AsyncStorage.getItem(key);
|
|
42
|
+
return raw ? (JSON.parse(raw) as T) : fallback;
|
|
43
|
+
} catch {
|
|
44
|
+
return fallback;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function write(key: string, value: unknown): Promise<void> {
|
|
49
|
+
try {
|
|
50
|
+
await AsyncStorage.setItem(key, JSON.stringify(value));
|
|
51
|
+
} catch {
|
|
52
|
+
// storage full or unavailable: the chat still works, it just is not kept
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const emptyThread = (): Thread => ({ sessionId: null, messages: [] });
|
|
57
|
+
|
|
58
|
+
export function loadThread(account: string): Promise<Thread> {
|
|
59
|
+
return read<Thread>(threadKey(account), emptyThread());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function saveThread(account: string, thread: Thread): Promise<void> {
|
|
63
|
+
return write(threadKey(account), { ...thread, messages: thread.messages.slice(-MAX_MESSAGES) });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function loadHistory(account: string): Promise<PastChat[]> {
|
|
67
|
+
return read<{ chats: PastChat[] }>(historyKey(account), { chats: [] }).then((h) => h.chats ?? []);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Files the thread under History (newest first), replacing an earlier copy of the same session. */
|
|
71
|
+
export async function archiveThread(account: string, thread: Thread, title: string): Promise<PastChat[]> {
|
|
72
|
+
if (!thread.messages.some((m) => m.role === 'user')) return loadHistory(account);
|
|
73
|
+
const chats = await loadHistory(account);
|
|
74
|
+
const id = thread.sessionId ?? `local-${Date.now()}`;
|
|
75
|
+
const next = [
|
|
76
|
+
{ id, title, at: Date.now(), sessionId: thread.sessionId, messages: thread.messages.slice(-MAX_MESSAGES) },
|
|
77
|
+
...chats.filter((c) => c.id !== id),
|
|
78
|
+
].slice(0, MAX_CHATS);
|
|
79
|
+
await write(historyKey(account), { chats: next });
|
|
80
|
+
return next;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function removePastChat(account: string, id: string): Promise<PastChat[]> {
|
|
84
|
+
const next = (await loadHistory(account)).filter((c) => c.id !== id);
|
|
85
|
+
await write(historyKey(account), { chats: next });
|
|
86
|
+
return next;
|
|
87
|
+
}
|