@adminide-stack/clock-tik-mobile 0.0.0-stage → 12.0.37-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-flow/data/pending-insights.jsonl +43 -0
- package/.claude-flow/sessions/session-1794323376548.json +14 -0
- package/CHANGELOG.md +41 -0
- package/jest.config.cjs +22 -0
- package/lib/assets/home/loop-day.jpg +0 -0
- package/lib/assets/home/loop-day.mp4 +0 -0
- package/lib/assets/home/loop-time-back.jpg +0 -0
- package/lib/assets/home/loop-time-back.mp4 +0 -0
- package/lib/assets/home/loop-where.jpg +0 -0
- package/lib/assets/home/loop-where.mp4 +0 -0
- package/lib/assets/home/reel-gym.jpg +0 -0
- package/lib/assets/home/reel-gym.mp4 +0 -0
- package/lib/assets/home/reel-internet.jpg +0 -0
- package/lib/assets/home/reel-internet.mp4 +0 -0
- package/lib/assets/icon.png +0 -0
- package/lib/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
- package/lib/assets/lottie/lucy-mark-calendar.json +1827 -0
- package/lib/assets/lottie/lucy-mark-call.json +1470 -0
- package/lib/assets/lottie/lucy-mark-connect.json +2552 -0
- package/lib/assets/lottie/lucy-mark-details.json +1735 -0
- package/lib/assets/lottie/lucy-mark-email.json +1363 -0
- package/lib/assets/lottie/lucy-mark-message.json +1154 -0
- package/lib/assets/lottie/lucy-mark-search.json +1067 -0
- package/lib/assets/lottie/lucy-mark-think.json +1253 -0
- package/lib/assets/lottie/lucy-mark-write.json +1532 -0
- package/lib/assets/lottie/time-back.json +16458 -0
- package/lib/assets/lottie/where-lucy-works-chat.json +6170 -0
- package/lib/assets/lottie/where-lucy-works-cloud.json +10066 -0
- package/lib/assets/lottie/where-lucy-works-mine-none.json +2478 -0
- package/lib/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
- package/lib/assets/lottie/where-lucy-works-mine-online.json +7881 -0
- package/lib/assets/sounds/hours-back.m4a +0 -0
- package/lib/assets/sounds/meet-lucy.m4a +0 -0
- package/lib/assets/sounds/power-on.m4a +0 -0
- package/lib/assets/sounds/wind-back.m4a +0 -0
- package/lib/assets/sounds/youre-in.m4a +0 -0
- package/lib/chat/agent.js +358 -0
- package/lib/chat/agent.js.map +1 -0
- package/lib/chat/appFront.js +32 -0
- package/lib/chat/appFront.js.map +1 -0
- package/lib/chat/auth.js +370 -0
- package/lib/chat/auth.js.map +1 -0
- package/lib/chat/chores.js +360 -0
- package/lib/chat/chores.js.map +1 -0
- package/lib/chat/connectors.js +45 -0
- package/lib/chat/connectors.js.map +1 -0
- package/lib/chat/jobs.js +223 -0
- package/lib/chat/jobs.js.map +1 -0
- package/lib/chat/lucyMotion.js +6 -0
- package/lib/chat/lucyMotion.js.map +1 -0
- package/lib/chat/protocol.js +111 -0
- package/lib/chat/protocol.js.map +1 -0
- package/lib/chat/results.js +133 -0
- package/lib/chat/results.js.map +1 -0
- package/lib/chat/store.js +81 -0
- package/lib/chat/store.js.map +1 -0
- package/lib/chat/useDictation.js +168 -0
- package/lib/chat/useDictation.js.map +1 -0
- package/lib/chat/useLucyChat.js +451 -0
- package/lib/chat/useLucyChat.js.map +1 -0
- package/lib/chat/useMyComputer.js +32 -0
- package/lib/chat/useMyComputer.js.map +1 -0
- package/lib/chat/whereLucyWorks.js +52 -0
- package/lib/chat/whereLucyWorks.js.map +1 -0
- package/lib/chat/workspace.js +124 -0
- package/lib/chat/workspace.js.map +1 -0
- package/lib/components/AreaShot.js +289 -0
- package/lib/components/AreaShot.js.map +1 -0
- package/lib/components/Backdrops.js +262 -0
- package/lib/components/Backdrops.js.map +1 -0
- package/lib/components/BottomSheet.js +61 -0
- package/lib/components/BottomSheet.js.map +1 -0
- package/lib/components/ChatSheets.js +429 -0
- package/lib/components/ChatSheets.js.map +1 -0
- package/lib/components/ConnectorLogo.js +91 -0
- package/lib/components/ConnectorLogo.js.map +1 -0
- package/lib/components/CustomDrawer.js +534 -0
- package/lib/components/CustomDrawer.js.map +1 -0
- package/lib/components/IdeasPane.js +394 -0
- package/lib/components/IdeasPane.js.map +1 -0
- package/lib/components/ImessageSheet.js +261 -0
- package/lib/components/ImessageSheet.js.map +1 -0
- package/lib/components/KeyboardAvoider.js +29 -0
- package/lib/components/KeyboardAvoider.js.map +1 -0
- package/lib/components/Logo.js +81 -0
- package/lib/components/Logo.js.map +1 -0
- package/lib/components/LucyWorking.js +67 -0
- package/lib/components/LucyWorking.js.map +1 -0
- package/lib/components/Markdown.js +260 -0
- package/lib/components/Markdown.js.map +1 -0
- package/lib/components/Media.js +93 -0
- package/lib/components/Media.js.map +1 -0
- package/lib/components/MessagesAppIcon.js +23 -0
- package/lib/components/MessagesAppIcon.js.map +1 -0
- package/lib/components/MicButton.js +71 -0
- package/lib/components/MicButton.js.map +1 -0
- package/lib/components/ResultCards.js +974 -0
- package/lib/components/ResultCards.js.map +1 -0
- package/lib/components/SignInPrompt.js +148 -0
- package/lib/components/SignInPrompt.js.map +1 -0
- package/lib/components/SignedOut.js +38 -0
- package/lib/components/SignedOut.js.map +1 -0
- package/lib/components/TalkToLucyHero.js +487 -0
- package/lib/components/TalkToLucyHero.js.map +1 -0
- package/lib/components/TalkToLucySheet.js +182 -0
- package/lib/components/TalkToLucySheet.js.map +1 -0
- package/lib/components/WhereLucyWorks.js +277 -0
- package/lib/components/WhereLucyWorks.js.map +1 -0
- package/lib/components/WorkspaceSection.js +271 -0
- package/lib/components/WorkspaceSection.js.map +1 -0
- package/lib/components/YantraMark.js +13 -0
- package/lib/components/YantraMark.js.map +1 -0
- package/lib/components/drawerHeader.js +38 -0
- package/lib/components/drawerHeader.js.map +1 -0
- package/lib/components/lottieInstalled.js +6 -0
- package/lib/components/lottieInstalled.js.map +1 -0
- package/lib/components/ui.js +550 -0
- package/lib/components/ui.js.map +1 -0
- package/lib/components/useSignOut.js +7 -0
- package/lib/components/useSignOut.js.map +1 -0
- package/lib/components/viewport.js +121 -0
- package/lib/components/viewport.js.map +1 -0
- package/lib/components/voiceDial.js +10 -0
- package/lib/components/voiceDial.js.map +1 -0
- package/lib/compute.js +157 -0
- package/lib/compute.js.map +1 -0
- package/lib/config/env-config.js +27 -0
- package/lib/config/env-config.js.map +1 -0
- package/lib/config/routes.js +15 -0
- package/lib/config/routes.js.map +1 -0
- package/lib/content.js +25 -0
- package/lib/content.js.map +1 -0
- package/lib/hooks/keyboardCover.js +39 -0
- package/lib/hooks/keyboardCover.js.map +1 -0
- package/lib/hooks/useKeyboard.js +121 -0
- package/lib/hooks/useKeyboard.js.map +1 -0
- package/lib/hooks/useReducedMotion.js +13 -0
- package/lib/hooks/useReducedMotion.js.map +1 -0
- package/lib/imessage/openMessages.js +25 -0
- package/lib/imessage/openMessages.js.map +1 -0
- package/lib/imessage/platform.js +12 -0
- package/lib/imessage/platform.js.map +1 -0
- package/lib/imessage/textLink.js +262 -0
- package/lib/imessage/textLink.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/live/card.js +28 -0
- package/lib/live/card.js.map +1 -0
- package/lib/live/liveActivity.js +144 -0
- package/lib/live/liveActivity.js.map +1 -0
- package/lib/module.js +3 -0
- package/lib/module.js.map +1 -0
- package/lib/offer/BlackFridayOffer.js +378 -0
- package/lib/offer/BlackFridayOffer.js.map +1 -0
- package/lib/offer/blackFriday.js +78 -0
- package/lib/offer/blackFriday.js.map +1 -0
- package/lib/offer/parts.js +624 -0
- package/lib/offer/parts.js.map +1 -0
- package/lib/offer/state.js +63 -0
- package/lib/offer/state.js.map +1 -0
- package/lib/push/push.js +142 -0
- package/lib/push/push.js.map +1 -0
- package/lib/push/usePushNotifications.js +39 -0
- package/lib/push/usePushNotifications.js.map +1 -0
- package/lib/routes.json +175 -0
- package/lib/screens/Account/index.js +209 -0
- package/lib/screens/Account/index.js.map +1 -0
- package/lib/screens/Chat/index.js +710 -0
- package/lib/screens/Chat/index.js.map +1 -0
- package/lib/screens/Chores/index.js +18 -0
- package/lib/screens/Chores/index.js.map +1 -0
- package/lib/screens/Connectors/index.js +17 -0
- package/lib/screens/Connectors/index.js.map +1 -0
- package/lib/screens/History/index.js +380 -0
- package/lib/screens/History/index.js.map +1 -0
- package/lib/screens/Home/index.js +2715 -0
- package/lib/screens/Home/index.js.map +1 -0
- package/lib/screens/Home/media.js +25 -0
- package/lib/screens/Home/media.js.map +1 -0
- package/lib/screens/Welcome/index.js +1066 -0
- package/lib/screens/Welcome/index.js.map +1 -0
- package/lib/talk/talkToLucy.js +139 -0
- package/lib/talk/talkToLucy.js.map +1 -0
- package/lib/theme/colors.js +29 -0
- package/lib/theme/colors.js.map +1 -0
- package/lib/theme/fonts.js +17 -0
- package/lib/theme/fonts.js.map +1 -0
- package/lib/theme/muse.js +134 -0
- package/lib/theme/muse.js.map +1 -0
- package/lib/utils/links.js +54 -0
- package/lib/utils/links.js.map +1 -0
- package/lib/utils/yantraLinks.js +68 -0
- package/lib/utils/yantraLinks.js.map +1 -0
- package/lib/welcome/flow.js +375 -0
- package/lib/welcome/flow.js.map +1 -0
- package/lib/welcome/haptics.js +125 -0
- package/lib/welcome/haptics.js.map +1 -0
- package/lib/welcome/parts.js +1996 -0
- package/lib/welcome/parts.js.map +1 -0
- package/lib/welcome/powerOn.js +29 -0
- package/lib/welcome/powerOn.js.map +1 -0
- package/lib/welcome/seen.js +41 -0
- package/lib/welcome/seen.js.map +1 -0
- package/lib/welcome/sound.js +110 -0
- package/lib/welcome/sound.js.map +1 -0
- package/package.json +66 -5
- package/rollup.config.mjs +42 -0
- package/src/.claude-flow/data/pending-insights.jsonl +19 -0
- package/src/.claude-flow/sessions/session-1795013028422.json +14 -0
- package/src/__tests__/auth.test.ts +94 -0
- package/src/__tests__/blackFriday.test.ts +75 -0
- package/src/__tests__/cardTokens.test.ts +77 -0
- package/src/__tests__/chores.test.ts +188 -0
- package/src/__tests__/choresList.test.ts +100 -0
- package/src/__tests__/connectLink.test.ts +21 -0
- package/src/__tests__/content.test.ts +54 -0
- package/src/__tests__/dictation.test.ts +186 -0
- package/src/__tests__/envConfig.test.ts +14 -0
- package/src/__tests__/haptics.test.ts +202 -0
- package/src/__tests__/jobs.test.ts +130 -0
- package/src/__tests__/keyboardCover.test.ts +84 -0
- package/src/__tests__/liveCard.test.ts +39 -0
- package/src/__tests__/lockedPhone.test.ts +355 -0
- package/src/__tests__/lucyMotion.test.ts +34 -0
- package/src/__tests__/platform.test.ts +32 -0
- package/src/__tests__/powerOn.test.ts +62 -0
- package/src/__tests__/protocol.test.ts +125 -0
- package/src/__tests__/push.test.ts +111 -0
- package/src/__tests__/results.test.ts +256 -0
- package/src/__tests__/sound.test.ts +248 -0
- package/src/__tests__/talkToLucy.test.ts +205 -0
- package/src/__tests__/textLink.test.ts +91 -0
- package/src/__tests__/voiceDial.test.ts +53 -0
- package/src/__tests__/welcomeFlow.test.ts +157 -0
- package/src/__tests__/whereLucyWorks.test.ts +81 -0
- package/src/__tests__/yantraLinks.test.ts +96 -0
- package/src/assets/home/loop-day.jpg +0 -0
- package/src/assets/home/loop-day.mp4 +0 -0
- package/src/assets/home/loop-time-back.jpg +0 -0
- package/src/assets/home/loop-time-back.mp4 +0 -0
- package/src/assets/home/loop-where.jpg +0 -0
- package/src/assets/home/loop-where.mp4 +0 -0
- package/src/assets/home/reel-gym.jpg +0 -0
- package/src/assets/home/reel-gym.mp4 +0 -0
- package/src/assets/home/reel-internet.jpg +0 -0
- package/src/assets/home/reel-internet.mp4 +0 -0
- package/src/assets/icon.png +0 -0
- package/src/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
- package/src/assets/lottie/lucy-mark-calendar.json +1827 -0
- package/src/assets/lottie/lucy-mark-call.json +1470 -0
- package/src/assets/lottie/lucy-mark-connect.json +2552 -0
- package/src/assets/lottie/lucy-mark-details.json +1735 -0
- package/src/assets/lottie/lucy-mark-email.json +1363 -0
- package/src/assets/lottie/lucy-mark-message.json +1154 -0
- package/src/assets/lottie/lucy-mark-search.json +1067 -0
- package/src/assets/lottie/lucy-mark-think.json +1253 -0
- package/src/assets/lottie/lucy-mark-write.json +1532 -0
- package/src/assets/lottie/time-back.json +16458 -0
- package/src/assets/lottie/where-lucy-works-chat.json +6170 -0
- package/src/assets/lottie/where-lucy-works-cloud.json +10066 -0
- package/src/assets/lottie/where-lucy-works-mine-none.json +2478 -0
- package/src/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
- package/src/assets/lottie/where-lucy-works-mine-online.json +7881 -0
- package/src/assets/sounds/hours-back.m4a +0 -0
- package/src/assets/sounds/meet-lucy.m4a +0 -0
- package/src/assets/sounds/power-on.m4a +0 -0
- package/src/assets/sounds/wind-back.m4a +0 -0
- package/src/assets/sounds/youre-in.m4a +0 -0
- package/src/chat/.claude-flow/data/pending-insights.jsonl +1 -0
- package/src/chat/agent.ts +376 -0
- package/src/chat/appFront.ts +39 -0
- package/src/chat/auth.ts +433 -0
- package/src/chat/chores.ts +394 -0
- package/src/chat/connectors.ts +75 -0
- package/src/chat/jobs.ts +228 -0
- package/src/chat/lucyMotion.ts +33 -0
- package/src/chat/protocol.ts +192 -0
- package/src/chat/results.ts +224 -0
- package/src/chat/store.ts +87 -0
- package/src/chat/useDictation.ts +201 -0
- package/src/chat/useLucyChat.ts +458 -0
- package/src/chat/useMyComputer.ts +41 -0
- package/src/chat/whereLucyWorks.ts +97 -0
- package/src/chat/workspace.ts +127 -0
- package/src/components/.claude-flow/data/pending-insights.jsonl +3 -0
- package/src/components/AreaShot.tsx +239 -0
- package/src/components/Backdrops.tsx +323 -0
- package/src/components/BottomSheet.tsx +96 -0
- package/src/components/ChatSheets.tsx +565 -0
- package/src/components/ConnectorLogo.tsx +116 -0
- package/src/components/CustomDrawer.tsx +526 -0
- package/src/components/IdeasPane.tsx +318 -0
- package/src/components/ImessageSheet.tsx +280 -0
- package/src/components/KeyboardAvoider.tsx +45 -0
- package/src/components/Logo.tsx +97 -0
- package/src/components/LucyWorking.tsx +122 -0
- package/src/components/Markdown.tsx +219 -0
- package/src/components/Media.tsx +173 -0
- package/src/components/MessagesAppIcon.tsx +51 -0
- package/src/components/MicButton.tsx +92 -0
- package/src/components/ResultCards.tsx +1067 -0
- package/src/components/SignInPrompt.tsx +182 -0
- package/src/components/SignedOut.tsx +47 -0
- package/src/components/TalkToLucyHero.tsx +540 -0
- package/src/components/TalkToLucySheet.tsx +208 -0
- package/src/components/VoiceOrb.tsx +364 -0
- package/src/components/WhereLucyWorks.tsx +261 -0
- package/src/components/WorkspaceSection.tsx +307 -0
- package/src/components/YantraMark.tsx +30 -0
- package/src/components/drawerHeader.tsx +46 -0
- package/src/components/kit.tsx +309 -0
- package/src/components/lottieInstalled.ts +7 -0
- package/src/components/ui.tsx +700 -0
- package/src/components/useSignOut.ts +21 -0
- package/src/components/viewport.tsx +166 -0
- package/src/components/voiceDial.ts +45 -0
- package/src/compute.ts +168 -0
- package/src/config/env-config.ts +50 -0
- package/src/config/routes.ts +28 -0
- package/src/content.ts +217 -0
- package/src/hooks/keyboardCover.ts +70 -0
- package/src/hooks/useKeyboard.ts +135 -0
- package/src/hooks/useReducedMotion.ts +19 -0
- package/src/imessage/openMessages.ts +53 -0
- package/src/imessage/platform.ts +32 -0
- package/src/imessage/textLink.ts +307 -0
- package/src/index.ts +24 -0
- package/src/live/card.ts +62 -0
- package/src/live/liveActivity.ts +192 -0
- package/src/module.ts +8 -0
- package/src/offer/BlackFridayOffer.tsx +394 -0
- package/src/offer/blackFriday.ts +109 -0
- package/src/offer/parts.tsx +650 -0
- package/src/offer/state.ts +78 -0
- package/src/push/push.ts +171 -0
- package/src/push/usePushNotifications.ts +47 -0
- package/src/screens/Account/index.tsx +310 -0
- package/src/screens/Chat/.claude-flow/data/pending-insights.jsonl +4 -0
- package/src/screens/Chat/index.tsx +891 -0
- package/src/screens/Chores/index.tsx +35 -0
- package/src/screens/Connectors/index.tsx +35 -0
- package/src/screens/History/index.tsx +346 -0
- package/src/screens/Home/index.tsx +2776 -0
- package/src/screens/Home/media.ts +31 -0
- package/src/screens/Welcome/index.tsx +1182 -0
- package/src/talk/talkToLucy.ts +187 -0
- package/src/theme/colors.ts +38 -0
- package/src/theme/fonts.ts +30 -0
- package/src/theme/muse.ts +86 -0
- package/src/utils/links.ts +84 -0
- package/src/utils/yantraLinks.ts +94 -0
- package/src/welcome/flow.ts +418 -0
- package/src/welcome/haptics.ts +179 -0
- package/src/welcome/parts.tsx +2160 -0
- package/src/welcome/powerOn.ts +84 -0
- package/src/welcome/seen.ts +68 -0
- package/src/welcome/sound.ts +173 -0
- package/tools/lottie/chat.motion +0 -0
- package/tools/lottie/cloud.motion +0 -0
- package/tools/lottie/generate.mjs +1209 -0
- package/tools/lottie/inter-glyphs.json +4416 -0
- package/tools/lottie/lucy-mark-calendar.motion +0 -0
- package/tools/lottie/lucy-mark-call.motion +0 -0
- package/tools/lottie/lucy-mark-connect.motion +0 -0
- package/tools/lottie/lucy-mark-details.motion +0 -0
- package/tools/lottie/lucy-mark-email.motion +0 -0
- package/tools/lottie/lucy-mark-message.motion +0 -0
- package/tools/lottie/lucy-mark-search.motion +0 -0
- package/tools/lottie/lucy-mark-think.motion +0 -0
- package/tools/lottie/lucy-mark-write.motion +0 -0
- package/tools/lottie/mark.json +1 -0
- package/tools/lottie/mine-none.motion +0 -0
- package/tools/lottie/mine-offline.motion +0 -0
- package/tools/lottie/mine-online.motion +0 -0
- package/tools/lottie/time-back.mjs +604 -0
- package/tools/sounds/render.mjs +730 -0
- package/tsconfig.json +17 -0
- package/README.md +0 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import {fetch as fetch$1}from'expo/fetch';import {inFront,whenInFront,onFront}from'./appFront.js';import {isLockedOut,getChatToken,agentUrl,clearChatToken,agentBackendUrl}from'./auth.js';import {SYSTEM_PROMPT,CONTINUE_PROMPT,toolLine,statusLine,visibleOutput,joinOutput}from'./protocol.js';var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __publicField = (obj, key, value) => {
|
|
21
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
class TurnError extends Error {
|
|
25
|
+
constructor(kind, message, retry, sessionId) {
|
|
26
|
+
super(message);
|
|
27
|
+
__publicField(this, "kind");
|
|
28
|
+
__publicField(this, "retry");
|
|
29
|
+
__publicField(this, "sessionId");
|
|
30
|
+
this.name = "TurnError";
|
|
31
|
+
this.kind = kind;
|
|
32
|
+
this.retry = retry;
|
|
33
|
+
this.sessionId = sessionId;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function newId(prefix) {
|
|
37
|
+
const r = () => Math.random().toString(16).slice(2, 10);
|
|
38
|
+
return `${prefix}-${Date.now().toString(16)}-${r()}${r()}`;
|
|
39
|
+
}
|
|
40
|
+
async function authed(path, init, retried = false) {
|
|
41
|
+
var _a;
|
|
42
|
+
const token = await getChatToken({
|
|
43
|
+
fresh: retried
|
|
44
|
+
});
|
|
45
|
+
const res = await fetch(`${agentUrl()}${path}`, __spreadProps(__spreadValues({}, init), {
|
|
46
|
+
headers: __spreadValues({
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
Authorization: `Bearer ${token}`
|
|
49
|
+
}, (_a = init.headers) != null ? _a : {})
|
|
50
|
+
}));
|
|
51
|
+
if (res.status === 401 && !retried) {
|
|
52
|
+
await clearChatToken();
|
|
53
|
+
return authed(path, init, true);
|
|
54
|
+
}
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
async function openSession() {
|
|
58
|
+
let res;
|
|
59
|
+
try {
|
|
60
|
+
res = await authed("/v1/agent/session", {
|
|
61
|
+
method: "POST",
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
system_prompt: SYSTEM_PROMPT,
|
|
64
|
+
permission_mode: "auto"
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
} catch (err) {
|
|
68
|
+
if (err.name === "ChatAuthError")
|
|
69
|
+
throw err;
|
|
70
|
+
throw new TurnError("network", "Could not reach Lucy. Check your connection.");
|
|
71
|
+
}
|
|
72
|
+
if (res.status === 401)
|
|
73
|
+
throw new TurnError("auth", "Sign in again to chat with Lucy");
|
|
74
|
+
if (!res.ok)
|
|
75
|
+
throw new TurnError("service", `Lucy could not start a chat (HTTP ${res.status})`);
|
|
76
|
+
const j = await res.json();
|
|
77
|
+
if (!j.session_id)
|
|
78
|
+
throw new TurnError("service", "Lucy could not start a chat");
|
|
79
|
+
return j.session_id;
|
|
80
|
+
}
|
|
81
|
+
async function cancelTurn(sessionId) {
|
|
82
|
+
await authed("/v1/chat/cancel", {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
"X-Session-ID": sessionId
|
|
86
|
+
}
|
|
87
|
+
}).catch(() => void 0);
|
|
88
|
+
}
|
|
89
|
+
function parseEvents(buffer) {
|
|
90
|
+
var _a;
|
|
91
|
+
const parts = buffer.replace(/\r\n/g, "\n").split("\n\n");
|
|
92
|
+
const rest = (_a = parts.pop()) != null ? _a : "";
|
|
93
|
+
const events = parts.map((block) => {
|
|
94
|
+
let event = "message";
|
|
95
|
+
const data = [];
|
|
96
|
+
for (const line of block.split("\n")) {
|
|
97
|
+
if (line.startsWith("event:"))
|
|
98
|
+
event = line.slice(6).trim();
|
|
99
|
+
else if (line.startsWith("data:"))
|
|
100
|
+
data.push(line.slice(5).replace(/^ /, ""));
|
|
101
|
+
}
|
|
102
|
+
if (!data.length)
|
|
103
|
+
return null;
|
|
104
|
+
try {
|
|
105
|
+
return {
|
|
106
|
+
event,
|
|
107
|
+
data: JSON.parse(data.join("\n"))
|
|
108
|
+
};
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return {
|
|
111
|
+
event,
|
|
112
|
+
data: {
|
|
113
|
+
text: data.join("\n")
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}).filter((e) => e !== null);
|
|
118
|
+
return {
|
|
119
|
+
events,
|
|
120
|
+
rest
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const AGENT_KEEPALIVE_MS = 15e3;
|
|
124
|
+
const SILENT_MS = 4e4;
|
|
125
|
+
const BACK_GRACE_MS = 3e3;
|
|
126
|
+
const LINE_CHECK_MS = 1e3;
|
|
127
|
+
function watchLine(stop) {
|
|
128
|
+
const line = new AbortController();
|
|
129
|
+
let heardAt = Date.now();
|
|
130
|
+
let backAt = 0;
|
|
131
|
+
let dead = false;
|
|
132
|
+
const endLine = () => line.abort();
|
|
133
|
+
stop.addEventListener("abort", endLine);
|
|
134
|
+
const stopFront = onFront(() => {
|
|
135
|
+
backAt = Date.now();
|
|
136
|
+
});
|
|
137
|
+
const timer = setInterval(() => {
|
|
138
|
+
if (dead || !inFront())
|
|
139
|
+
return;
|
|
140
|
+
const now = Date.now();
|
|
141
|
+
if (backAt && now - backAt < BACK_GRACE_MS)
|
|
142
|
+
return;
|
|
143
|
+
const missedWhileAway = backAt > heardAt && backAt - heardAt > AGENT_KEEPALIVE_MS;
|
|
144
|
+
if (missedWhileAway || now - heardAt > SILENT_MS) {
|
|
145
|
+
dead = true;
|
|
146
|
+
line.abort();
|
|
147
|
+
}
|
|
148
|
+
}, LINE_CHECK_MS);
|
|
149
|
+
return {
|
|
150
|
+
signal: line.signal,
|
|
151
|
+
heard: () => {
|
|
152
|
+
heardAt = Date.now();
|
|
153
|
+
},
|
|
154
|
+
dead: () => dead,
|
|
155
|
+
end: () => {
|
|
156
|
+
clearInterval(timer);
|
|
157
|
+
stopFront();
|
|
158
|
+
stop.removeEventListener("abort", endLine);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function streamOnce(message, sessionId, turnId, prefix, handlers, signal, job, heard = () => void 0) {
|
|
163
|
+
var _a, _b, _c, _d, _e, _f;
|
|
164
|
+
const token = await getChatToken();
|
|
165
|
+
const jobFields = job ? {
|
|
166
|
+
job,
|
|
167
|
+
backend_graphql_url: await agentBackendUrl().catch(() => void 0)
|
|
168
|
+
} : {};
|
|
169
|
+
let res;
|
|
170
|
+
try {
|
|
171
|
+
res = await fetch$1(`${agentUrl()}/v1/agent/chat`, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: {
|
|
174
|
+
"Content-Type": "application/json",
|
|
175
|
+
Accept: "text/event-stream",
|
|
176
|
+
Authorization: `Bearer ${token}`
|
|
177
|
+
},
|
|
178
|
+
body: JSON.stringify(__spreadValues({
|
|
179
|
+
message,
|
|
180
|
+
stream: true,
|
|
181
|
+
session_id: sessionId,
|
|
182
|
+
turn_id: turnId,
|
|
183
|
+
permission_mode: "auto"
|
|
184
|
+
}, jobFields)),
|
|
185
|
+
signal
|
|
186
|
+
});
|
|
187
|
+
} catch (err) {
|
|
188
|
+
if (signal.aborted)
|
|
189
|
+
throw new TurnError("stopped", "Stopped");
|
|
190
|
+
throw new TurnError("network", `Could not reach Lucy (${err.message})`, "resend");
|
|
191
|
+
}
|
|
192
|
+
if (res.status === 401) {
|
|
193
|
+
await clearChatToken();
|
|
194
|
+
throw new TurnError("auth", "Sign in again to chat with Lucy", "resend");
|
|
195
|
+
}
|
|
196
|
+
if (res.status === 409)
|
|
197
|
+
throw new TurnError("busy", "Lucy is still finishing the last message");
|
|
198
|
+
if ([429, 502, 503, 504].includes(res.status))
|
|
199
|
+
throw new TurnError("service", `Lucy is busy (HTTP ${res.status})`, "resend");
|
|
200
|
+
if (!res.ok || !res.body)
|
|
201
|
+
throw new TurnError("service", `Lucy could not take that (HTTP ${res.status})`);
|
|
202
|
+
let reply = prefix;
|
|
203
|
+
let held = "";
|
|
204
|
+
let done = false;
|
|
205
|
+
let buffer = "";
|
|
206
|
+
const reader = res.body.getReader();
|
|
207
|
+
const decoder = new TextDecoder();
|
|
208
|
+
const flushHeld = () => {
|
|
209
|
+
if (!held)
|
|
210
|
+
return;
|
|
211
|
+
reply = joinOutput(reply, held);
|
|
212
|
+
held = "";
|
|
213
|
+
handlers.onText(reply);
|
|
214
|
+
};
|
|
215
|
+
try {
|
|
216
|
+
for (; ; ) {
|
|
217
|
+
const {
|
|
218
|
+
value,
|
|
219
|
+
done: ended
|
|
220
|
+
} = await reader.read();
|
|
221
|
+
if (ended)
|
|
222
|
+
break;
|
|
223
|
+
heard();
|
|
224
|
+
buffer += decoder.decode(value, {
|
|
225
|
+
stream: true
|
|
226
|
+
});
|
|
227
|
+
const parsed = parseEvents(buffer);
|
|
228
|
+
buffer = parsed.rest;
|
|
229
|
+
for (const {
|
|
230
|
+
event,
|
|
231
|
+
data
|
|
232
|
+
} of parsed.events) {
|
|
233
|
+
switch (event) {
|
|
234
|
+
case "session":
|
|
235
|
+
if (data.session_id)
|
|
236
|
+
handlers.onSession(String(data.session_id));
|
|
237
|
+
break;
|
|
238
|
+
case "delta":
|
|
239
|
+
flushHeld();
|
|
240
|
+
reply += String((_a = data.text) != null ? _a : "");
|
|
241
|
+
handlers.onStatus(null);
|
|
242
|
+
handlers.onText(reply);
|
|
243
|
+
break;
|
|
244
|
+
case "output": {
|
|
245
|
+
const out = visibleOutput(String((_b = data.text) != null ? _b : ""));
|
|
246
|
+
if (!out)
|
|
247
|
+
break;
|
|
248
|
+
flushHeld();
|
|
249
|
+
if (out.startsWith("\u26A0"))
|
|
250
|
+
held = out;
|
|
251
|
+
else {
|
|
252
|
+
reply = joinOutput(reply, out);
|
|
253
|
+
handlers.onText(reply);
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case "status": {
|
|
258
|
+
const line = statusLine(String((_c = data.status) != null ? _c : ""));
|
|
259
|
+
if (line)
|
|
260
|
+
handlers.onStatus(/^queued/i.test(line) ? "Waiting for the last message to finish" : line);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case "tool_call":
|
|
264
|
+
handlers.onStatus(toolLine(String((_d = data.name) != null ? _d : ""), data.detail ? String(data.detail) : void 0));
|
|
265
|
+
break;
|
|
266
|
+
case "error": {
|
|
267
|
+
held = "";
|
|
268
|
+
const text = String((_e = data.error) != null ? _e : "Something went wrong");
|
|
269
|
+
const cls = String((_f = data.class) != null ? _f : "");
|
|
270
|
+
const retry = data.retry === "resend" || data.retry === "continue" ? data.retry : void 0;
|
|
271
|
+
if (cls === "session_busy" || /busy processing a previous message/i.test(text)) {
|
|
272
|
+
throw new TurnError("busy", "Lucy is still finishing the last message", void 0, sessionId);
|
|
273
|
+
}
|
|
274
|
+
const err = new TurnError("service", text, retry, sessionId);
|
|
275
|
+
err.partial = reply;
|
|
276
|
+
throw err;
|
|
277
|
+
}
|
|
278
|
+
case "done":
|
|
279
|
+
done = true;
|
|
280
|
+
break;
|
|
281
|
+
default:
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
} catch (err) {
|
|
287
|
+
if (signal.aborted)
|
|
288
|
+
throw new TurnError("stopped", "Stopped");
|
|
289
|
+
if (err instanceof TurnError)
|
|
290
|
+
throw err;
|
|
291
|
+
throw new TurnError("network", "The connection to Lucy dropped", "resend");
|
|
292
|
+
}
|
|
293
|
+
flushHeld();
|
|
294
|
+
if (!done && reply === prefix)
|
|
295
|
+
throw new TurnError("network", "The connection to Lucy dropped", "resend");
|
|
296
|
+
handlers.onStatus(null);
|
|
297
|
+
return reply;
|
|
298
|
+
}
|
|
299
|
+
const BACKOFF_MS = [3e3, 8e3, 15e3];
|
|
300
|
+
const MAX_PICKUPS = 12;
|
|
301
|
+
const SHUT_IN_FRONT_TRIES = 3;
|
|
302
|
+
const stoppedError = () => new TurnError("stopped", "Stopped");
|
|
303
|
+
const wait = (ms, signal) => new Promise((resolve, reject) => {
|
|
304
|
+
const onAbort = () => reject(stoppedError());
|
|
305
|
+
signal.addEventListener("abort", onAbort, {
|
|
306
|
+
once: true
|
|
307
|
+
});
|
|
308
|
+
setTimeout(() => {
|
|
309
|
+
signal.removeEventListener("abort", onAbort);
|
|
310
|
+
resolve();
|
|
311
|
+
}, ms);
|
|
312
|
+
});
|
|
313
|
+
async function sendTurn(message, sessionId, handlers, signal, job) {
|
|
314
|
+
var _a;
|
|
315
|
+
let turnId = newId("turn");
|
|
316
|
+
let text = message;
|
|
317
|
+
let prefix = "";
|
|
318
|
+
let attempt = 0;
|
|
319
|
+
let pickups = 0;
|
|
320
|
+
let shutInFront = 0;
|
|
321
|
+
for (; ; ) {
|
|
322
|
+
const line = watchLine(signal);
|
|
323
|
+
try {
|
|
324
|
+
return await streamOnce(text, sessionId, turnId, prefix, handlers, line.signal, job, line.heard);
|
|
325
|
+
} catch (err) {
|
|
326
|
+
if (signal.aborted)
|
|
327
|
+
throw stoppedError();
|
|
328
|
+
const away = !inFront();
|
|
329
|
+
const lost = err instanceof TurnError && err.kind === "network";
|
|
330
|
+
if (line.dead() || away && (lost || isLockedOut(err))) {
|
|
331
|
+
pickups += 1;
|
|
332
|
+
if (pickups > MAX_PICKUPS)
|
|
333
|
+
throw new TurnError("network", "The connection to Lucy dropped");
|
|
334
|
+
await whenInFront(signal, stoppedError);
|
|
335
|
+
handlers.onStatus("Reconnecting");
|
|
336
|
+
} else if (isLockedOut(err)) {
|
|
337
|
+
shutInFront += 1;
|
|
338
|
+
if (shutInFront > SHUT_IN_FRONT_TRIES)
|
|
339
|
+
throw err;
|
|
340
|
+
await wait(1e3, signal);
|
|
341
|
+
} else {
|
|
342
|
+
const e = err;
|
|
343
|
+
if (!(e instanceof TurnError) || !e.retry || attempt >= BACKOFF_MS.length || e.kind === "stopped")
|
|
344
|
+
throw e;
|
|
345
|
+
handlers.onStatus("Reconnecting");
|
|
346
|
+
await wait(BACKOFF_MS[attempt], signal);
|
|
347
|
+
attempt += 1;
|
|
348
|
+
if (e.retry === "continue") {
|
|
349
|
+
prefix = (_a = e.partial) != null ? _a : prefix;
|
|
350
|
+
text = CONTINUE_PROMPT;
|
|
351
|
+
turnId = newId("turn");
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
} finally {
|
|
355
|
+
line.end();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}export{BACK_GRACE_MS,SILENT_MS,TurnError,cancelTurn,openSession,sendTurn,watchLine};//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sources":["../../src/chat/agent.ts"],"sourcesContent":["/**\n * Lucy's agent over plain HTTP, as the web chat talks to it (@yantra/surface-kit agentChat.ts):\n * POST /v1/agent/session {system_prompt, permission_mode} -> {session_id}\n * POST /v1/agent/chat {message, stream, session_id, turn_id, permission_mode} -> SSE\n * POST /v1/chat/cancel X-Session-ID -> stops the turn on the agent\n * The reply streams as Server-Sent Events: session, delta, output, status, tool_call, tool_result, thinking, error, done.\n * React Native's fetch cannot read a body as it arrives; expo/fetch can.\n *\n * A turn outlives its line. The agent keeps running it when the line drops, and the same turn sent again is followed\n * to its end there, never run twice. So when the phone is locked or the app leaves the front mid-reply, the turn is\n * not failed: it waits for the app to be in front again and sends the same turn once more. A line that has gone\n * silent (the agent writes at least every 15 seconds) is let go the same way.\n */\nimport { fetch as streamFetch } from 'expo/fetch';\nimport { inFront, onFront, whenInFront } from './appFront';\nimport { agentBackendUrl, agentUrl, clearChatToken, getChatToken, isLockedOut } from './auth';\nimport type { JobRef } from './jobs';\nimport { CONTINUE_PROMPT, SYSTEM_PROMPT, joinOutput, statusLine, toolLine, visibleOutput } from './protocol';\n\nexport type TurnErrorKind = 'busy' | 'auth' | 'network' | 'service' | 'stopped';\n\nexport class TurnError extends Error {\n readonly kind: TurnErrorKind;\n /** What the agent asks for: send the same turn again, or carry on from a cut-off step. */\n readonly retry?: 'resend' | 'continue';\n readonly sessionId?: string;\n\n constructor(kind: TurnErrorKind, message: string, retry?: 'resend' | 'continue', sessionId?: string) {\n super(message);\n this.name = 'TurnError';\n this.kind = kind;\n this.retry = retry;\n this.sessionId = sessionId;\n }\n}\n\nfunction newId(prefix: string): string {\n const r = () => Math.random().toString(16).slice(2, 10);\n return `${prefix}-${Date.now().toString(16)}-${r()}${r()}`;\n}\n\nasync function authed(\n path: string,\n init: { method: string; headers?: Record<string, string>; body?: string },\n retried = false,\n) {\n const token = await getChatToken({ fresh: retried });\n const res = await fetch(`${agentUrl()}${path}`, {\n ...init,\n headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, ...(init.headers ?? {}) },\n });\n if (res.status === 401 && !retried) {\n await clearChatToken();\n return authed(path, init, true);\n }\n return res;\n}\n\n/** A new conversation with Lucy; its id is the chat's id from then on. */\nexport async function openSession(): Promise<string> {\n let res: Response;\n try {\n res = await authed('/v1/agent/session', {\n method: 'POST',\n body: JSON.stringify({ system_prompt: SYSTEM_PROMPT, permission_mode: 'auto' }),\n });\n } catch (err) {\n if ((err as Error).name === 'ChatAuthError') throw err;\n throw new TurnError('network', 'Could not reach Lucy. Check your connection.');\n }\n if (res.status === 401) throw new TurnError('auth', 'Sign in again to chat with Lucy');\n if (!res.ok) throw new TurnError('service', `Lucy could not start a chat (HTTP ${res.status})`);\n const j = (await res.json()) as { session_id?: string };\n if (!j.session_id) throw new TurnError('service', 'Lucy could not start a chat');\n return j.session_id;\n}\n\n/** Stops the turn on the agent; closing the stream alone would leave it running. */\nexport async function cancelTurn(sessionId: string): Promise<void> {\n await authed('/v1/chat/cancel', { method: 'POST', headers: { 'X-Session-ID': sessionId } }).catch(() => undefined);\n}\n\nexport interface TurnHandlers {\n /** The reply so far, whole, each time it grows. */\n onText: (text: string) => void;\n /** What Lucy is doing right now (a tool, a queue); null when she is writing. */\n onStatus: (line: string | null) => void;\n /** The session the turn landed on (it can differ from the one asked for). */\n onSession: (sessionId: string) => void;\n}\n\ninterface SseEvent {\n event: string;\n data: Record<string, unknown>;\n}\n\nfunction parseEvents(buffer: string): { events: SseEvent[]; rest: string } {\n const parts = buffer.replace(/\\r\\n/g, '\\n').split('\\n\\n');\n const rest = parts.pop() ?? '';\n const events = parts\n .map((block) => {\n let event = 'message';\n const data: string[] = [];\n for (const line of block.split('\\n')) {\n if (line.startsWith('event:')) event = line.slice(6).trim();\n else if (line.startsWith('data:')) data.push(line.slice(5).replace(/^ /, ''));\n }\n if (!data.length) return null;\n try {\n return { event, data: JSON.parse(data.join('\\n')) as Record<string, unknown> };\n } catch {\n return { event, data: { text: data.join('\\n') } };\n }\n })\n .filter((e): e is SseEvent => e !== null);\n return { events, rest };\n}\n\n/** The agent writes on every reply line at least this often (a keepalive while it works). */\nconst AGENT_KEEPALIVE_MS = 15_000;\n/** In front and nothing heard for this long: the line is gone (two keepalives missed, and some). */\nexport const SILENT_MS = 40_000;\n/** Back in front: what a live line held while the app was away arrives at once; nothing in this long, it is gone. */\nexport const BACK_GRACE_MS = 3_000;\nconst LINE_CHECK_MS = 1_000;\n\n/**\n * The line one try reads on. It ends when the turn is stopped, or when it has gone silent: in front for SILENT_MS with\n * nothing heard, or back in front after missing a keepalive while away and nothing heard in BACK_GRACE_MS.\n */\nexport function watchLine(stop: AbortSignal) {\n const line = new AbortController();\n let heardAt = Date.now();\n let backAt = 0;\n let dead = false;\n const endLine = () => line.abort();\n stop.addEventListener('abort', endLine);\n const stopFront = onFront(() => {\n backAt = Date.now();\n });\n const timer = setInterval(() => {\n if (dead || !inFront()) return;\n const now = Date.now();\n if (backAt && now - backAt < BACK_GRACE_MS) return;\n const missedWhileAway = backAt > heardAt && backAt - heardAt > AGENT_KEEPALIVE_MS;\n if (missedWhileAway || now - heardAt > SILENT_MS) {\n dead = true;\n line.abort();\n }\n }, LINE_CHECK_MS);\n return {\n signal: line.signal,\n /** Something arrived on the line. */\n heard: () => {\n heardAt = Date.now();\n },\n /** It was let go for its silence (not stopped). */\n dead: () => dead,\n end: () => {\n clearInterval(timer);\n stopFront();\n stop.removeEventListener('abort', endLine);\n },\n };\n}\n\n/** One turn, streamed. Resolves with the whole reply; rejects with a TurnError. */\nasync function streamOnce(\n message: string,\n sessionId: string,\n turnId: string,\n prefix: string,\n handlers: TurnHandlers,\n signal: AbortSignal,\n job?: JobRef,\n heard: () => void = () => undefined,\n): Promise<string> {\n const token = await getChatToken();\n // The chore record this turn is: the agent reports to it (at the backend this token was minted on), app or no app.\n const jobFields = job ? { job, backend_graphql_url: await agentBackendUrl().catch(() => undefined) } : {};\n let res: Awaited<ReturnType<typeof streamFetch>>;\n try {\n res = await streamFetch(`${agentUrl()}/v1/agent/chat`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'text/event-stream',\n Authorization: `Bearer ${token}`,\n },\n body: JSON.stringify({\n message,\n stream: true,\n session_id: sessionId,\n turn_id: turnId,\n permission_mode: 'auto',\n ...jobFields,\n }),\n signal,\n });\n } catch (err) {\n if (signal.aborted) throw new TurnError('stopped', 'Stopped');\n throw new TurnError('network', `Could not reach Lucy (${(err as Error).message})`, 'resend');\n }\n if (res.status === 401) {\n await clearChatToken();\n throw new TurnError('auth', 'Sign in again to chat with Lucy', 'resend');\n }\n if (res.status === 409) throw new TurnError('busy', 'Lucy is still finishing the last message');\n if ([429, 502, 503, 504].includes(res.status))\n throw new TurnError('service', `Lucy is busy (HTTP ${res.status})`, 'resend');\n if (!res.ok || !res.body) throw new TurnError('service', `Lucy could not take that (HTTP ${res.status})`);\n\n let reply = prefix;\n let held = '';\n let done = false;\n let buffer = '';\n const reader = res.body.getReader();\n const decoder = new TextDecoder();\n const flushHeld = () => {\n if (!held) return;\n reply = joinOutput(reply, held);\n held = '';\n handlers.onText(reply);\n };\n\n try {\n for (;;) {\n const { value, done: ended } = await reader.read();\n if (ended) break;\n heard();\n buffer += decoder.decode(value, { stream: true });\n const parsed = parseEvents(buffer);\n buffer = parsed.rest;\n for (const { event, data } of parsed.events) {\n switch (event) {\n case 'session':\n if (data.session_id) handlers.onSession(String(data.session_id));\n break;\n case 'delta':\n flushHeld();\n reply += String(data.text ?? '');\n handlers.onStatus(null);\n handlers.onText(reply);\n break;\n case 'output': {\n const out = visibleOutput(String(data.text ?? ''));\n if (!out) break;\n flushHeld();\n // A warning can be the preface of a failure: show it only if no error follows.\n if (out.startsWith('⚠')) held = out;\n else {\n reply = joinOutput(reply, out);\n handlers.onText(reply);\n }\n break;\n }\n case 'status': {\n const line = statusLine(String(data.status ?? ''));\n if (line)\n handlers.onStatus(/^queued/i.test(line) ? 'Waiting for the last message to finish' : line);\n break;\n }\n case 'tool_call':\n handlers.onStatus(\n toolLine(String(data.name ?? ''), data.detail ? String(data.detail) : undefined),\n );\n break;\n case 'error': {\n held = '';\n const text = String(data.error ?? 'Something went wrong');\n const cls = String(data.class ?? '');\n const retry = data.retry === 'resend' || data.retry === 'continue' ? data.retry : undefined;\n if (cls === 'session_busy' || /busy processing a previous message/i.test(text)) {\n throw new TurnError(\n 'busy',\n 'Lucy is still finishing the last message',\n undefined,\n sessionId,\n );\n }\n const err = new TurnError('service', text, retry, sessionId);\n // A cut-off step keeps what was written so far.\n (err as TurnError & { partial?: string }).partial = reply;\n throw err;\n }\n case 'done':\n done = true;\n break;\n default:\n break;\n }\n }\n }\n } catch (err) {\n if (signal.aborted) throw new TurnError('stopped', 'Stopped');\n if (err instanceof TurnError) throw err;\n throw new TurnError('network', 'The connection to Lucy dropped', 'resend');\n }\n flushHeld();\n if (!done && reply === prefix) throw new TurnError('network', 'The connection to Lucy dropped', 'resend');\n handlers.onStatus(null);\n return reply;\n}\n\nconst BACKOFF_MS = [3000, 8000, 15000];\n/** A turn's line is picked up again at most this often (each time only follows the turn on the agent). */\nconst MAX_PICKUPS = 12;\n/** In front with the keychain still shut (it opens a moment after the unlock): read again this often, a second apart. */\nconst SHUT_IN_FRONT_TRIES = 3;\nconst stoppedError = () => new TurnError('stopped', 'Stopped');\nconst wait = (ms: number, signal: AbortSignal) =>\n new Promise<void>((resolve, reject) => {\n const onAbort = () => reject(stoppedError());\n signal.addEventListener('abort', onAbort, { once: true });\n setTimeout(() => {\n signal.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n });\n\n/**\n * Sends `message` on `sessionId` and streams Lucy's reply, retrying the way the web chat does: a resend repeats the same\n * turn id (so the agent never runs it twice), a continue keeps the partial reply and asks Lucy to carry on.\n *\n * A line lost while the app was away (the phone locked, the app in the background), a keychain the lock shut, or a\n * line gone silent never fails the turn: once the app is in front, the same turn is sent again and followed to its end.\n */\nexport async function sendTurn(\n message: string,\n sessionId: string,\n handlers: TurnHandlers,\n signal: AbortSignal,\n job?: JobRef,\n): Promise<string> {\n let turnId = newId('turn');\n let text = message;\n let prefix = '';\n let attempt = 0;\n let pickups = 0;\n let shutInFront = 0;\n for (;;) {\n const line = watchLine(signal);\n try {\n return await streamOnce(text, sessionId, turnId, prefix, handlers, line.signal, job, line.heard);\n } catch (err) {\n if (signal.aborted) throw stoppedError();\n const away = !inFront();\n const lost = err instanceof TurnError && err.kind === 'network';\n if (line.dead() || (away && (lost || isLockedOut(err)))) {\n // The same turn again (resent, not retried): the agent follows the one it took to its end.\n pickups += 1;\n if (pickups > MAX_PICKUPS) throw new TurnError('network', 'The connection to Lucy dropped');\n await whenInFront(signal, stoppedError);\n handlers.onStatus('Reconnecting');\n } else if (isLockedOut(err)) {\n shutInFront += 1;\n if (shutInFront > SHUT_IN_FRONT_TRIES) throw err;\n await wait(1000, signal);\n } else {\n const e = err as TurnError & { partial?: string };\n if (!(e instanceof TurnError) || !e.retry || attempt >= BACKOFF_MS.length || e.kind === 'stopped')\n throw e;\n handlers.onStatus('Reconnecting');\n await wait(BACKOFF_MS[attempt], signal);\n attempt += 1;\n if (e.retry === 'continue') {\n prefix = e.partial ?? prefix;\n text = CONTINUE_PROMPT;\n turnId = newId('turn');\n }\n }\n } finally {\n line.end();\n }\n }\n}\n"],"names":["streamFetch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EAKnC,WAAY,CAAA,IAAA,EAAqB,OAAiB,EAAA,KAAA,EAA+B,SAAoB,EAAA;AACnG,IAAA,KAAA,CAAM,OAAO,CAAA;AALf,IAAS,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAET,IAAS,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AACT,IAAS,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AAGP,IAAA,IAAA,CAAK,IAAO,GAAA,WAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA;AACb,IAAA,IAAA,CAAK,SAAY,GAAA,SAAA;AAAA;AAErB;AACA,SAAS,MAAM,MAAwB,EAAA;AACrC,EAAM,MAAA,CAAA,GAAI,MAAM,IAAA,CAAK,MAAO,EAAA,CAAE,SAAS,EAAE,CAAA,CAAE,KAAM,CAAA,CAAA,EAAG,EAAE,CAAA;AACtD,EAAO,OAAA,CAAA,EAAG,MAAU,CAAA,CAAA,EAAA,IAAA,CAAK,GAAI,EAAA,CAAE,SAAS,EAAE,CAAA,CAAA,CAAA,EAAK,CAAE,EAAA,CAAA,EAAI,CAAE,EAAA,CAAA,CAAA;AACzD;AACA,eAAe,MAAO,CAAA,IAAA,EA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,MAAA;AACtB,UAAO,IAAA,GAAA,eAAA;AACP,UAAA,MAAA,GAAS,MAAM,MAAM,CAAA;AAAA;AACvB;AACF,KACA,SAAA;AACA,MAAA,IAAA,CAAK,GAAI,EAAA;AAAA;AACX;AAEJ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {AppState}from'react-native';function inFront() {
|
|
2
|
+
const state = AppState.currentState;
|
|
3
|
+
return state !== "background" && state !== "inactive";
|
|
4
|
+
}
|
|
5
|
+
function onFront(back) {
|
|
6
|
+
const sub = AppState.addEventListener("change", (state) => {
|
|
7
|
+
if (state === "active")
|
|
8
|
+
back();
|
|
9
|
+
});
|
|
10
|
+
return () => sub.remove();
|
|
11
|
+
}
|
|
12
|
+
function whenInFront(signal, stopped = () => new Error("Stopped")) {
|
|
13
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
14
|
+
return Promise.reject(stopped());
|
|
15
|
+
if (inFront())
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
let stopFront = () => void 0;
|
|
19
|
+
const onAbort = () => {
|
|
20
|
+
stopFront();
|
|
21
|
+
reject(stopped());
|
|
22
|
+
};
|
|
23
|
+
stopFront = onFront(() => {
|
|
24
|
+
stopFront();
|
|
25
|
+
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
|
|
26
|
+
resolve();
|
|
27
|
+
});
|
|
28
|
+
signal == null ? void 0 : signal.addEventListener("abort", onAbort, {
|
|
29
|
+
once: true
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}export{inFront,onFront,whenInFront};//# sourceMappingURL=appFront.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appFront.js","sources":["../../src/chat/appFront.ts"],"sourcesContent":["/**\n * Whether the app is in front. Locking the phone sends the app to the background, and iOS shuts its keychain a few\n * seconds later; an app in front is on an unlocked phone. Lucy's chat waits for the front again (rather than failing)\n * for anything that needs the keychain or a live line while the phone is locked.\n */\nimport { AppState } from 'react-native';\n\n/** In front: not in the background and not on its way there (locking passes through `inactive`). */\nexport function inFront(): boolean {\n const state = AppState.currentState;\n return state !== 'background' && state !== 'inactive';\n}\n\n/** Calls `back` each time the app comes to the front. Returns what stops it. */\nexport function onFront(back: () => void): () => void {\n const sub = AppState.addEventListener('change', (state) => {\n if (state === 'active') back();\n });\n return () => sub.remove();\n}\n\n/** Resolves once the app is in front (at once when it is); rejects with `stopped` when `signal` ends the wait. */\nexport function whenInFront(signal?: AbortSignal, stopped: () => Error = () => new Error('Stopped')): Promise<void> {\n if (signal?.aborted) return Promise.reject(stopped());\n if (inFront()) return Promise.resolve();\n return new Promise<void>((resolve, reject) => {\n let stopFront: () => void = () => undefined;\n const onAbort = () => {\n stopFront();\n reject(stopped());\n };\n stopFront = onFront(() => {\n stopFront();\n signal?.removeEventListener('abort', onAbort);\n resolve();\n });\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n"],"names":[],"mappings":"oCAQO,SAAS,OAAmB,GAAA;AACjC,EAAA,MAAM,QAAQ,QAAS,CAAA,YAAA;AACvB,EAAO,OAAA,KAAA,KAAU,gBAAgB,KAAU,KAAA,UAAA;AAC7C;AAGO,SAAS,QAAQ,IAA8B,EAAA;AACpD,EAAA,MAAM,GAAM,GAAA,QAAA,CAAS,gBAAiB,CAAA,QAAA,EAAU,CAAS,KAAA,KAAA;AACvD,IAAA,IAAI,KAAU,KAAA,QAAA;AAAU,MAAK,IAAA,EAAA;AAAA,GAC9B,CAAA;AACD,EAAO,OAAA,MAAM,IAAI,MAAO,EAAA;AAC1B;AAGO,SAAS,YAAY,MAAsB,EAAA,OAAA,GAAuB,MAAM,IAAI,KAAA,CAAM,SAAS,CAAkB,EAAA;AAClH,EAAA,IAAI,MAAQ,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAA,OAAA;AAAS,IAAO,OAAA,OAAA,CAAQ,MAAO,CAAA,OAAA,EAAS,CAAA;AACpD,EAAA,IAAI,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