@adminide-stack/yantra-mobile 12.0.191-alpha.1 → 12.0.192-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/features/agent-chat/NativeAgentChat.js +15 -2
  2. package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
  3. package/lib/features/audio-input/NativeDictationBar.js +7 -3
  4. package/lib/features/audio-input/NativeDictationBar.js.map +1 -1
  5. package/lib/features/audio-input/speechParts.js +27 -0
  6. package/lib/features/audio-input/speechParts.js.map +1 -0
  7. package/lib/features/computer/ComputerAgentChatPane.js.map +1 -1
  8. package/lib/features/credits/FreeCreditsCard.js +1 -1
  9. package/lib/features/credits/FreeCreditsYesCard.js +93 -0
  10. package/lib/features/credits/FreeCreditsYesCard.js.map +1 -0
  11. package/lib/features/credits/freeCredits.js +1 -15
  12. package/lib/features/credits/freeCredits.js.map +1 -1
  13. package/lib/features/credits/lockedReply.js +44 -0
  14. package/lib/features/credits/lockedReply.js.map +1 -0
  15. package/lib/features/credits/useFreeCredits.js +8 -5
  16. package/lib/features/credits/useFreeCredits.js.map +1 -1
  17. package/lib/features/credits/useFreeCreditsYes.js +48 -0
  18. package/lib/features/credits/useFreeCreditsYes.js.map +1 -0
  19. package/lib/features/dictate/useVoiceQuestion.js +5 -3
  20. package/lib/features/dictate/useVoiceQuestion.js.map +1 -1
  21. package/lib/features/travel/airportCodes.js +76 -0
  22. package/lib/features/travel/airportCodes.js.map +1 -0
  23. package/lib/features/travel/airportIndex.js +1 -1
  24. package/lib/features/travel/airportIndex.js.map +1 -1
  25. package/lib/features/travel/parseTravelIntent.js +95 -124
  26. package/lib/features/travel/parseTravelIntent.js.map +1 -1
  27. package/lib/hooks/useHostFreeCreditsClaim.js +23 -0
  28. package/lib/hooks/useHostFreeCreditsClaim.js.map +1 -0
  29. package/lib/screens/Chat/index.js +11 -4
  30. package/lib/screens/Chat/index.js.map +1 -1
  31. package/lib/screens/ComputerNative/useComputerHostChat.js +5 -3
  32. package/lib/screens/ComputerNative/useComputerHostChat.js.map +1 -1
  33. package/lib/screens/ExpensesNative/useExpensesHostChat.js +5 -3
  34. package/lib/screens/ExpensesNative/useExpensesHostChat.js.map +1 -1
  35. package/lib/screens/InboxNative/useInboxHostChat.js +5 -3
  36. package/lib/screens/InboxNative/useInboxHostChat.js.map +1 -1
  37. package/lib/screens/JobSearchNative/useJobSearchHostChat.js +5 -3
  38. package/lib/screens/JobSearchNative/useJobSearchHostChat.js.map +1 -1
  39. package/lib/screens/LocalServicesNative/useLocalServicesHostChat.js +5 -3
  40. package/lib/screens/LocalServicesNative/useLocalServicesHostChat.js.map +1 -1
  41. package/lib/screens/MoviesNative/useMoviesHostChat.js +5 -3
  42. package/lib/screens/MoviesNative/useMoviesHostChat.js.map +1 -1
  43. package/lib/screens/ResumeNative/useResumeHostChat.js +5 -3
  44. package/lib/screens/ResumeNative/useResumeHostChat.js.map +1 -1
  45. package/lib/screens/ShoppingNative/useShoppingHostChat.js +5 -3
  46. package/lib/screens/ShoppingNative/useShoppingHostChat.js.map +1 -1
  47. package/lib/screens/StudyNative/useStudyHostChat.js +5 -3
  48. package/lib/screens/StudyNative/useStudyHostChat.js.map +1 -1
  49. package/lib/screens/TravelNative/useTravelHostChat.js +5 -3
  50. package/lib/screens/TravelNative/useTravelHostChat.js.map +1 -1
  51. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"freeCredits.js","sources":["../../../src/features/credits/freeCredits.ts"],"sourcesContent":["/**\n * The free tier is unlocked per organization - by claiming the offer or by joining through an\n * invite link - never handed out on sign-up. Until then every message is answered with a notice\n * to claim, so a person who cannot claim cannot use the app at all. On 2026-11-02 none of the\n * 11 newest phone accounts had claimed: the button only existed on the web.\n *\n * These are the web's two calls (`services/freeCredits.ts`) for the phone. They go through the\n * app's Apollo client: its auth link adds the token and keeps the `orgname` header set on a\n * call's context, and the resolvers take the org from that header.\n */\nimport { gql, type ApolloClient } from '@apollo/client';\n\nexport interface FreeCreditsStatus {\n unlocked: boolean;\n source: 'offer' | 'invite' | null;\n offerAvailable: boolean;\n dailyCredits: number;\n monthlyCredits: number;\n /**\n * The one-time starter grant (2026-11-03): claimed once, never refilled. Above 0 it is the whole\n * free tier, and `dailyCredits` and `monthlyCredits` are 0; 0 while the free tier is credits a day.\n * A backend from before it rejects the query, which reads as \"no offer\": ship billing first.\n */\n starterCredits: number;\n}\n\nconst FREE_CREDITS_STATUS_FIELDS = gql`\n fragment FreeCreditsStatusFields on FreeCreditsStatus {\n unlocked\n source\n offerAvailable\n dailyCredits\n monthlyCredits\n starterCredits\n }\n`;\n\nexport const FREE_CREDITS_STATUS_QUERY = gql`\n query FreeCreditsStatus {\n freeCreditsStatus {\n ...FreeCreditsStatusFields\n }\n }\n ${FREE_CREDITS_STATUS_FIELDS}\n`;\n\nexport const CLAIM_FREE_CREDITS_MUTATION = gql`\n mutation ClaimFreeCredits {\n claimFreeCredits {\n ...FreeCreditsStatusFields\n }\n }\n ${FREE_CREDITS_STATUS_FIELDS}\n`;\n\nexport const FREE_CREDITS_CLAIM_FAILED = \"We couldn't unlock your free credits. Please try again.\";\n\ntype GraphqlClient = Pick<ApolloClient<unknown>, 'query' | 'mutate'>;\n\nconst orgContext = (orgName: string) => ({ headers: { orgname: orgName } });\n\n/** The org's free-tier status, or null when it cannot be read (treated as \"no offer\"). */\nexport async function fetchFreeCreditsStatus(\n client: GraphqlClient,\n orgName: string,\n): Promise<FreeCreditsStatus | null> {\n try {\n const { data } = await client.query<{ freeCreditsStatus: FreeCreditsStatus }>({\n query: FREE_CREDITS_STATUS_QUERY,\n context: orgContext(orgName),\n fetchPolicy: 'network-only',\n });\n return data?.freeCreditsStatus ?? null;\n } catch {\n return null;\n }\n}\n\n/** Unlock the free tier through the offer. Throws with the server's reason when refused. */\nexport async function claimFreeCredits(client: GraphqlClient, orgName: string): Promise<FreeCreditsStatus> {\n const { data, errors } = await client.mutate<{ claimFreeCredits: FreeCreditsStatus }>({\n mutation: CLAIM_FREE_CREDITS_MUTATION,\n context: orgContext(orgName),\n errorPolicy: 'all',\n });\n const status = data?.claimFreeCredits;\n if (!status) {\n throw new Error(errors?.[0]?.message || FREE_CREDITS_CLAIM_FAILED);\n }\n return status;\n}\n\n/** The chat's answer to an org that has not claimed: cdecli's `creditsRefusalReason`. */\nconst LOCKED_REPLY = /haven['’]t claimed your free Yantra credits/i;\n\nexport function isFreeCreditsLockedReply(text: string | null | undefined): boolean {\n return LOCKED_REPLY.test(text ?? '');\n}\n\ninterface ChatTurn {\n role: string;\n content?: string | null;\n attachments?: readonly unknown[] | null;\n}\n\n/**\n * The turn the notice refused, when the notice is the newest reply: what to send again once the\n * credits are claimed. Null when the conversation has moved on, so an old notice further up the\n * thread never offers anything.\n */\nexport function lockedTurnToResend<T extends ChatTurn>(messages: readonly T[]): T | null {\n const newest = messages[messages.length - 1];\n if (newest?.role !== 'assistant' || !isFreeCreditsLockedReply(newest.content)) return null;\n for (let i = messages.length - 2; i >= 0; i -= 1) {\n const prior = messages[i];\n if (prior?.role === 'user' && (prior.content?.trim() || prior.attachments?.length)) return prior;\n }\n return null;\n}\n\n/** Offer the claim while it can still be claimed; say nothing when the status is unreadable. */\nexport function shouldOfferFreeCredits(status: FreeCreditsStatus | null): boolean {\n return Boolean(status?.offerAvailable && !status.unlocked);\n}\n\nexport interface FreeCreditsCardView {\n title: string;\n body: string;\n}\n\n/**\n * What the card says. The credit numbers are the server's, so it can never promise a stale amount,\n * and a starter grant, which never refills, is never offered as credits a day.\n */\nexport function freeCreditsCardView(status: FreeCreditsStatus | null): FreeCreditsCardView {\n const title = 'Unlock your free AI credits';\n if (status && status.starterCredits > 0) {\n return {\n title,\n body: `Claim ${status.starterCredits.toLocaleString()} free AI credits to start chatting with Yantra - a one-time start, no card needed.`,\n };\n }\n if (!status?.dailyCredits) {\n return { title, body: 'Claim your free credits to start chatting with Yantra.' };\n }\n return {\n title,\n body: `Claim ${status.dailyCredits.toL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AA,MAAA,GAAA,EAAA,CAAA,MAAA,CAAA,CAAA,EAAgB,OAAA,KAAA;AAAA;AAE7F,EAAO,OAAA,IAAA;AACT;AAGO,SAAS,uBAAuB,MAA2C,EAAA;AAChF,EAAA,OAAO,OAAQ,CAAA,CAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,cAAkB,KAAA,CAAC,OAAO,QAAQ,CAAA;AAC3D;AAUO,SAAS,oBAAoB,MAAuD,EAAA;AACzF,EAAA,MAAM,KAAQ,GAAA,6BAAA;AACd,EAAI,IAAA,MAAA,IAAU,MAAO,CAAA,cAAA,GAAiB,CAAG,EAAA;AACvC,IAAO,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAM,EAAA,CAAA,MAAA,EAAS,MAAO,CAAA,cAAA,CAAe,gBAAgB,CAAA,kFAAA;AAAA,KACvD;AAAA;AAEF,EAAI,IAAA,EAAC,iCAAQ,YAAc,CAAA,EAAA;AACzB,IAAO,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAM,EAAA;AAAA,KACR;AAAA;AAEF,EAAO,OAAA;AAAA,IACL,KAAA;AAAA,IACA,IAAA,EAAM,CAAS,MAAA,EAAA,MAAA,CAAO,YAAa,CAAA,cAAA,EAAgB,CAAiC,8BAAA,EAAA,MAAA,CAAO,cAAe,CAAA,cAAA,EAAgB,CAAA,SAAA;AAAA,GAC5H;AACF"}
1
+ {"version":3,"file":"freeCredits.js","sources":["../../../src/features/credits/freeCredits.ts"],"sourcesContent":["/**\n * The free tier is unlocked per organization - by claiming the offer or by joining through an\n * invite link - never handed out on sign-up. Until then every message is answered with a notice\n * to claim, so a person who cannot claim cannot use the app at all. On 2026-11-02 none of the\n * 11 newest phone accounts had claimed: the button only existed on the web.\n *\n * These are the web's two calls (`services/freeCredits.ts`) for the phone. They go through the\n * app's Apollo client: its auth link adds the token and keeps the `orgname` header set on a\n * call's context, and the resolvers take the org from that header.\n */\nimport { gql, type ApolloClient } from '@apollo/client';\n\nexport interface FreeCreditsStatus {\n unlocked: boolean;\n source: 'offer' | 'invite' | null;\n offerAvailable: boolean;\n dailyCredits: number;\n monthlyCredits: number;\n /**\n * The one-time starter grant (2026-11-03): claimed once, never refilled. Above 0 it is the whole\n * free tier, and `dailyCredits` and `monthlyCredits` are 0; 0 while the free tier is credits a day.\n * A backend from before it rejects the query, which reads as \"no offer\": ship billing first.\n */\n starterCredits: number;\n}\n\nconst FREE_CREDITS_STATUS_FIELDS = gql`\n fragment FreeCreditsStatusFields on FreeCreditsStatus {\n unlocked\n source\n offerAvailable\n dailyCredits\n monthlyCredits\n starterCredits\n }\n`;\n\nexport const FREE_CREDITS_STATUS_QUERY = gql`\n query FreeCreditsStatus {\n freeCreditsStatus {\n ...FreeCreditsStatusFields\n }\n }\n ${FREE_CREDITS_STATUS_FIELDS}\n`;\n\nexport const CLAIM_FREE_CREDITS_MUTATION = gql`\n mutation ClaimFreeCredits {\n claimFreeCredits {\n ...FreeCreditsStatusFields\n }\n }\n ${FREE_CREDITS_STATUS_FIELDS}\n`;\n\nexport const FREE_CREDITS_CLAIM_FAILED = \"We couldn't unlock your free credits. Please try again.\";\n\ntype GraphqlClient = Pick<ApolloClient<unknown>, 'query' | 'mutate'>;\n\nconst orgContext = (orgName: string) => ({ headers: { orgname: orgName } });\n\n/** The org's free-tier status, or null when it cannot be read (treated as \"no offer\"). */\nexport async function fetchFreeCreditsStatus(\n client: GraphqlClient,\n orgName: string,\n): Promise<FreeCreditsStatus | null> {\n try {\n const { data } = await client.query<{ freeCreditsStatus: FreeCreditsStatus }>({\n query: FREE_CREDITS_STATUS_QUERY,\n context: orgContext(orgName),\n fetchPolicy: 'network-only',\n });\n return data?.freeCreditsStatus ?? null;\n } catch {\n return null;\n }\n}\n\n/** Unlock the free tier through the offer. Throws with the server's reason when refused. */\nexport async function claimFreeCredits(client: GraphqlClient, orgName: string): Promise<FreeCreditsStatus> {\n const { data, errors } = await client.mutate<{ claimFreeCredits: FreeCreditsStatus }>({\n mutation: CLAIM_FREE_CREDITS_MUTATION,\n context: orgContext(orgName),\n errorPolicy: 'all',\n });\n const status = data?.claimFreeCredits;\n if (!status) {\n throw new Error(errors?.[0]?.message || FREE_CREDITS_CLAIM_FAILED);\n }\n return status;\n}\n\n// The chat's refusal for free credits never claimed, read without Apollo (lockedReply.ts): a\n// native surface's chat, which ships in a remote, reads it too.\nexport { isFreeCreditsLockedReply, lockedTurnToResend } from './lockedReply';\n\n/** Offer the claim while it can still be claimed; say nothing when the status is unreadable. */\nexport function shouldOfferFreeCredits(status: FreeCreditsStatus | null): boolean {\n return Boolean(status?.offerAvailable && !status.unlocked);\n}\n\nexport interface FreeCreditsCardView {\n title: string;\n body: string;\n}\n\n/**\n * What the card says. The credit numbers are the server's, so it can never promise a stale amount,\n * and a starter grant, which never refills, is never offered as credits a day.\n */\nexport function freeCreditsCardView(status: FreeCreditsStatus | null): FreeCreditsCardView {\n const title = 'Unlock your free AI credits';\n if (status && status.starterCredits > 0) {\n return {\n title,\n body: `Claim ${status.starterCredits.toLocaleString()} free AI credits to start chatting with Yantra - a one-time start, no card needed.`,\n };\n }\n if (!status?.dailyCredits) {\n return { title, body: 'Claim your free credits to start chatting with Yantra.' };\n }\n return {\n title,\n body: `Claim ${status.dailyCredits.toLocaleString()} free AI credits a day, up to ${status.monthlyCredits.toLocaleString()} a month.`,\n };\n}\n"],"names":[],"mappings":"0CAwBA,MAAM,0BAA6B,GAAA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AAU5B,MAAM,yBAA4B,GAAA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,EAMnC,0BAA0B;AAAA;AAEzB,MAAM,2BAA8B,GAAA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,EAMrC,0BAA0B;AAAA;AAEzB,MAAM,yBAA4B,GAAA;AAEzC,MAAM,UAAA,GAAa,CAAC,OAAqB,MAAA;AAAA,EAC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MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,cAAkB,KAAA,CAAC,OAAO,QAAQ,CAAA;AAC3D;AAUO,SAAS,oBAAoB,MAAuD,EAAA;AACzF,EAAA,MAAM,KAAQ,GAAA,6BAAA;AACd,EAAI,IAAA,MAAA,IAAU,MAAO,CAAA,cAAA,GAAiB,CAAG,EAAA;AACvC,IAAO,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAM,EAAA,CAAA,MAAA,EAAS,MAAO,CAAA,cAAA,CAAe,gBAAgB,CAAA,kFAAA;AAAA,KACvD;AAAA;AAEF,EAAI,IAAA,EAAC,iCAAQ,YAAc,CAAA,EAAA;AACzB,IAAO,OAAA;AAAA,MACL,KAAA;AAAA,MACA,IAAM,EAAA;AAAA,KACR;AAAA;AAEF,EAAO,OAAA;AAAA,IACL,KAAA;AAAA,IACA,IAAA,EAAM,CAAS,MAAA,EAAA,MAAA,CAAO,YAAa,CAAA,cAAA,EAAgB,CAAiC,8BAAA,EAAA,MAAA,CAAO,cAAe,CAAA,cAAA,EAAgB,CAAA,SAAA;AAAA,GAC5H;AACF"}
@@ -0,0 +1,44 @@
1
+ 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
+ const LOCKED_REPLY = /haven['’]t claimed your free Yantra credits/i;
21
+ const LOCKED_REPLY_ON_PHONE = "You haven't claimed your free Yantra credits yet.";
22
+ function isFreeCreditsLockedReply(text) {
23
+ return LOCKED_REPLY.test(text != null ? text : "");
24
+ }
25
+ function lockedTurnToResend(messages) {
26
+ var _a, _b;
27
+ const newest = messages[messages.length - 1];
28
+ if ((newest == null ? void 0 : newest.role) !== "assistant" || !isFreeCreditsLockedReply(newest.content)) return null;
29
+ for (let i = messages.length - 2; i >= 0; i -= 1) {
30
+ const prior = messages[i];
31
+ if ((prior == null ? void 0 : prior.role) === "user" && (((_a = prior.content) == null ? void 0 : _a.trim()) || ((_b = prior.attachments) == null ? void 0 : _b.length))) return prior;
32
+ }
33
+ return null;
34
+ }
35
+ function offeredFreeCredits(text) {
36
+ const match = (text != null ? text : "").match(/(\d[\d,]*)\s+free credits/i);
37
+ const credits = match ? Number(match[1].replace(/,/g, "")) : 0;
38
+ return Number.isFinite(credits) ? credits : 0;
39
+ }
40
+ function withLockedRepliesOnPhone(messages) {
41
+ return messages.map((msg) => msg.role === "assistant" && isFreeCreditsLockedReply(msg.content) ? __spreadProps(__spreadValues({}, msg), {
42
+ content: LOCKED_REPLY_ON_PHONE
43
+ }) : msg);
44
+ }export{LOCKED_REPLY_ON_PHONE,isFreeCreditsLockedReply,lockedTurnToResend,offeredFreeCredits,withLockedRepliesOnPhone};//# sourceMappingURL=lockedReply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockedReply.js","sources":["../../../src/features/credits/lockedReply.ts"],"sourcesContent":["/**\n * The chat's refusal for free credits an organization never claimed (cdecli's\n * creditsRefusalReason), read with nothing but text: no Apollo, so the chats of the native\n * surfaces, which ship in remotes that must not bundle the host's data stack, read it too.\n *\n * cdecli words it for every client: \"You haven't claimed your free Yantra credits yet. Send\n * your message again and I'll claim your 5,000 free credits for you, or claim them yourself\n * at https://yantra.app (...)\" (an older agent: \"Claim them at https://yantra.app (...) to get\n * 5,000 free credits to start, then send your message again.\"). On the phone the link is no\n * way on: the chat shows LOCKED_REPLY_ON_PHONE and a Yes that claims them and sends the\n * message again (FreeCreditsYesCard).\n */\n\nconst LOCKED_REPLY = /haven['’]t claimed your free Yantra credits/i;\n\n/** What a phone chat shows for the refusal: the Yes under it is the way on, not the web app. */\nexport const LOCKED_REPLY_ON_PHONE = \"You haven't claimed your free Yantra credits yet.\";\n\nexport function isFreeCreditsLockedReply(text: string | null | undefined): boolean {\n return LOCKED_REPLY.test(text ?? '');\n}\n\ninterface ChatTurn {\n role: string;\n content?: string | null;\n attachments?: readonly unknown[] | null;\n}\n\n/**\n * The turn the notice refused, when the notice is the newest reply: what to send again once the\n * credits are claimed. Null when the conversation has moved on, so an old notice further up the\n * thread never offers anything.\n */\nexport function lockedTurnToResend<T extends ChatTurn>(messages: readonly T[]): T | null {\n const newest = messages[messages.length - 1];\n if (newest?.role !== 'assistant' || !isFreeCreditsLockedReply(newest.content)) return null;\n for (let i = messages.length - 2; i >= 0; i -= 1) {\n const prior = messages[i];\n if (prior?.role === 'user' && (prior.content?.trim() || prior.attachments?.length)) return prior;\n }\n return null;\n}\n\n/** The free credits the refusal offers (\"5,000 free credits\" -> 5000), 0 when it names none. */\nexport function offeredFreeCredits(text: string | null | undefined): number {\n const match = (text ?? '').match(/(\\d[\\d,]*)\\s+free credits/i);\n const credits = match ? Number(match[1].replace(/,/g, '')) : 0;\n return Number.isFinite(credits) ? credits : 0;\n}\n\n/** A thread as a phone chat shows it: the refusal without its link to the web app. */\nexport function withLockedRepliesOnPhone<T extends { role: string; content: string }>(messages: ReadonlyArray<T>): T[] {\n return messages.map((msg) =>\n msg.role === 'assistant' && isFreeCreditsLockedReply(msg.content)\n ? { ...msg, content: LOCKED_REPLY_ON_PHONE }\n : msg,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,MAAM,YAA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AAC,CAAI,GAAA,CAAA;AAC7D,EAAA,OAAO,MAAO,CAAA,QAAA,CAAS,OAAO,CAAA,GAAI,OAAU,GAAA,CAAA;AAC9C;AAGO,SAAS,yBAGb,QAAiC,EAAA;AAClC,EAAO,OAAA,QAAA,CAAS,GAAI,CAAA,CAAA,GAAA,KAAO,GAAI,CAAA,IAAA,KAAS,WAAe,IAAA,wBAAA,CAAyB,GAAI,CAAA,OAAO,CAAI,GAAA,aAAA,CAAA,cAAA,CAAA,EAAA,EAC1F,GAD0F,CAAA,EAAA;AAAA,IAE7F,OAAS,EAAA;AAAA,OACP,GAAG,CAAA;AACT"}
@@ -1,4 +1,9 @@
1
- import {useApolloClient}from'@apollo/client/index.js';import {useState,useEffect,useCallback}from'react';import {fetchFreeCreditsStatus,claimFreeCredits,FREE_CREDITS_CLAIM_FAILED}from'./freeCredits.js';const claimListeners = /* @__PURE__ */ new Set();
1
+ import {useApolloClient}from'@apollo/client/index.js';import {useState,useEffect,useCallback}from'react';import {fetchFreeCreditsStatus,FREE_CREDITS_CLAIM_FAILED,claimFreeCredits}from'./freeCredits.js';const claimListeners = /* @__PURE__ */ new Set();
2
+ async function claimFreeCreditsForOrg(client, orgName) {
3
+ const next = await claimFreeCredits(client, orgName);
4
+ claimListeners.forEach((listener) => listener(orgName, next));
5
+ return next;
6
+ }
2
7
  function useFreeCredits(orgName) {
3
8
  const client = useApolloClient();
4
9
  const [status, setStatus] = useState(null);
@@ -28,9 +33,7 @@ function useFreeCredits(orgName) {
28
33
  setClaiming(true);
29
34
  setError(null);
30
35
  try {
31
- const next = await claimFreeCredits(client, orgName);
32
- claimListeners.forEach((listener) => listener(orgName, next));
33
- return next;
36
+ return await claimFreeCreditsForOrg(client, orgName);
34
37
  } catch (err) {
35
38
  setError(err instanceof Error ? err.message : FREE_CREDITS_CLAIM_FAILED);
36
39
  return null;
@@ -44,4 +47,4 @@ function useFreeCredits(orgName) {
44
47
  error,
45
48
  claim
46
49
  };
47
- }export{useFreeCredits};//# sourceMappingURL=useFreeCredits.js.map
50
+ }export{claimFreeCreditsForOrg,useFreeCredits};//# sourceMappingURL=useFreeCredits.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFreeCredits.js","sources":["../../../src/features/credits/useFreeCredits.ts"],"sourcesContent":["import { useApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useState } from 'react';\nimport {\n claimFreeCredits,\n fetchFreeCreditsStatus,\n FREE_CREDITS_CLAIM_FAILED,\n type FreeCreditsStatus,\n} from './freeCredits';\n\nexport interface FreeCredits {\n /** Null until read, and when it cannot be read. */\n status: FreeCreditsStatus | null;\n claiming: boolean;\n /** The last claim's failure, in the server's words. */\n error: string | null;\n /** Claim the offer; resolves to the new status, or null when it failed (see `error`). */\n claim: () => Promise<FreeCreditsStatus | null>;\n}\n\ntype ClaimListener = (orgName: string, status: FreeCreditsStatus) => void;\n\n/** A claim in one surface updates the others (the web uses a `window` event for this). */\nconst claimListeners = new Set<ClaimListener>();\n\n/** The org's free-tier offer for one surface. Idle while `orgName` is empty. */\nexport function useFreeCredits(orgName?: string | null): FreeCredits {\n const client = useApolloClient();\n const [status, setStatus] = useState<FreeCreditsStatus | null>(null);\n const [claiming, setClaiming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n if (!orgName) return undefined;\n let live = true;\n void fetchFreeCreditsStatus(client, orgName).then((next) => {\n // A read that started before a claim must not take the claim back.\n if (live) setStatus((current) => (current?.unlocked ? current : next));\n });\n return () => {\n live = false;\n };\n }, [client, orgName]);\n\n useEffect(() => {\n const onClaimed: ClaimListener = (claimedOrg, next) => {\n if (claimedOrg === orgName) setStatus(next);\n };\n claimListeners.add(onClaimed);\n return () => {\n claimListeners.delete(onClaimed);\n };\n }, [orgName]);\n\n const claim = useCallback(async () => {\n if (!orgName) return null;\n setClaiming(true);\n setError(null);\n try {\n const next = await claimFreeCredits(client, orgName);\n claimListeners.forEach((listener) => listener(orgName, next));\n return next;\n } catch (err) {\n setError(err instanceof Error ? err.message : FREE_CREDITS_CLAIM_FAILED);\n return null;\n } finally {\n setClaiming(false);\n }\n }, [client, orgName]);\n\n return { status, claiming, error, claim };\n}\n"],"names":[],"mappings":"0MAeA,MAAM,cAAA,uBAAqB,GAAmB,EAAA;AAGvC,SAAS,eAAe,OAAsC,EAAA;AACnE,EAAA,MAAM,SAAS,eAAgB,EAAA;AAC/B,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAmC,IAAI,CAAA;AACnE,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,KAAK,CAAA;AAC9C,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAwB,IAAI,CAAA;AACtD,EAAA,SAAA,CAAU,MAAM;AACd,IAAI,IAAA,CAAC,SAAgB,OAAA,MAAA;AACrB,IAAA,IAAI,IAAO,GAAA,IAAA;AACX,IAAA,KAAK,sBAAuB,CAAA,MAAA,EAAQ,OAAO,CAAA,CAAE,KAAK,CAAQ,IAAA,KAAA;AAExD,MAAA,IAAI,MAAgB,SAAA,CAAA,CAAA,OAAA,KAAA,CAAW,OAAS,IAAA,IAAA,GAAA,MAAA,GAAA,OAAA,CAAA,QAAA,IAAW,UAAU,IAAI,CAAA;AAAA,KAClE,CAAA;AACD,IAAA,OAAO,MAAM;AACX,MAAO,IAAA,GAAA,KAAA;AAAA,KACT;AAAA,GACC,EAAA,CAAC,MAAQ,EAAA,OAAO,CAAC,CAAA;AACpB,EAAA,SAAA,CAAU,MAAM;AACd,IAAM,MAAA,SAAA,GAA2B,CAAC,UAAA,EAAY,IAAS,KAAA;AACrD,MAAI,IAAA,UAAA,KAAe,OAAS,EAAA,SAAA,CAAU,IAAI,CAAA;AAAA,KAC5C;AACA,IAAA,cAAA,CAAe,IAAI,SAAS,CAAA;AAC5B,IAAA,OAAO,MAAM;AACX,MAAA,cAAA,CAAe,OAAO,SAAS,CAAA;AAAA,KACjC;AAAA,GACF,EAAG,CAAC,OAAO,CAAC,CAAA;AACZ,EAAM,MAAA,KAAA,GAAQ,YAAY,YAAY;AACpC,IAAI,IAAA,CAAC,SAAgB,OAAA,IAAA;AACrB,IAAA,WAAA,CAAY,IAAI,CAAA;AAChB,IAAA,QAAA,CAAS,IAAI,CAAA;AACb,IAAI,IAAA;AACF,MAAA,MAAM,IAAO,GAAA,MAAM,gBAAiB,CAAA,MAAA,EAAQ,OAAO,CAAA;AACnD,MAAA,cAAA,CAAe,OAAQ,CAAA,CAAA,QAAA,KAAY,QAAS,CAAA,OAAA,EAAS,IAAI,CAAC,CAAA;AAC1D,MAAO,OAAA,IAAA;AAAA,aACA,GAAK,EAAA;AACZ,MAAA,QAAA,CAAS,GAAe,YAAA,KAAA,GAAQ,GAAI,CAAA,OAAA,GAAU,yBAAyB,CAAA;AACvE,MAAO,OAAA,IAAA;AAAA,KACP,SAAA;AACA,MAAA,WAAA,CAAY,KAAK,CAAA;AAAA;AACnB,GACC,EAAA,CAAC,MAAQ,EAAA,OAAO,CAAC,CAAA;AACpB,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,QAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF"}
1
+ {"version":3,"file":"useFreeCredits.js","sources":["../../../src/features/credits/useFreeCredits.ts"],"sourcesContent":["import { useApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useState } from 'react';\nimport {\n claimFreeCredits,\n fetchFreeCreditsStatus,\n FREE_CREDITS_CLAIM_FAILED,\n type FreeCreditsStatus,\n} from './freeCredits';\n\nexport interface FreeCredits {\n /** Null until read, and when it cannot be read. */\n status: FreeCreditsStatus | null;\n claiming: boolean;\n /** The last claim's failure, in the server's words. */\n error: string | null;\n /** Claim the offer; resolves to the new status, or null when it failed (see `error`). */\n claim: () => Promise<FreeCreditsStatus | null>;\n}\n\ntype ClaimListener = (orgName: string, status: FreeCreditsStatus) => void;\n\n/** A claim in one surface updates the others (the web uses a `window` event for this). */\nconst claimListeners = new Set<ClaimListener>();\n\n/**\n * Claim the org's free credits through the offer, and tell every mounted useFreeCredits of\n * that org, so a card elsewhere (the home screen's) stops offering them. Throws with the\n * server's reason when refused.\n */\nexport async function claimFreeCreditsForOrg(\n client: Parameters<typeof claimFreeCredits>[0],\n orgName: string,\n): Promise<FreeCreditsStatus> {\n const next = await claimFreeCredits(client, orgName);\n claimListeners.forEach((listener) => listener(orgName, next));\n return next;\n}\n\n/** The org's free-tier offer for one surface. Idle while `orgName` is empty. */\nexport function useFreeCredits(orgName?: string | null): FreeCredits {\n const client = useApolloClient();\n const [status, setStatus] = useState<FreeCreditsStatus | null>(null);\n const [claiming, setClaiming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n if (!orgName) return undefined;\n let live = true;\n void fetchFreeCreditsStatus(client, orgName).then((next) => {\n // A read that started before a claim must not take the claim back.\n if (live) setStatus((current) => (current?.unlocked ? current : next));\n });\n return () => {\n live = false;\n };\n }, [client, orgName]);\n\n useEffect(() => {\n const onClaimed: ClaimListener = (claimedOrg, next) => {\n if (claimedOrg === orgName) setStatus(next);\n };\n claimListeners.add(onClaimed);\n return () => {\n claimListeners.delete(onClaimed);\n };\n }, [orgName]);\n\n const claim = useCallback(async () => {\n if (!orgName) return null;\n setClaiming(true);\n setError(null);\n try {\n return await claimFreeCreditsForOrg(client, orgName);\n } catch (err) {\n setError(err instanceof Error ? err.message : FREE_CREDITS_CLAIM_FAILED);\n return null;\n } finally {\n setClaiming(false);\n }\n }, [client, orgName]);\n\n return { status, claiming, error, claim };\n}\n"],"names":[],"mappings":"0MAeA,MAAM,cAAA,uBAAqB,GAAmB,EAAA;AAOxB,eAAA,sBAAA,CAAuB,QAAgD,OAA6C,EAAA;AACxI,EAAA,MAAM,IAAO,GAAA,MAAM,gBAAiB,CAAA,MAAA,EAAQ,OAAO,CAAA;AACnD,EAAA,cAAA,CAAe,OAAQ,CAAA,CAAA,QAAA,KAAY,QAAS,CAAA,OAAA,EAAS,IAAI,CA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AAA,CAAY,IAAI,CAAA;AAChB,IAAA,QAAA,CAAS,IAAI,CAAA;AACb,IAAI,IAAA;AACF,MAAO,OAAA,MAAM,sBAAuB,CAAA,MAAA,EAAQ,OAAO,CAAA;AAAA,aAC5C,GAAK,EAAA;AACZ,MAAA,QAAA,CAAS,GAAe,YAAA,KAAA,GAAQ,GAAI,CAAA,OAAA,GAAU,yBAAyB,CAAA;AACvE,MAAO,OAAA,IAAA;AAAA,KACP,SAAA;AACA,MAAA,WAAA,CAAY,KAAK,CAAA;AAAA;AACnB,GACC,EAAA,CAAC,MAAQ,EAAA,OAAO,CAAC,CAAA;AACpB,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,QAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF"}
@@ -0,0 +1,48 @@
1
+ import {useMemo,useState,useEffect,useRef,useCallback}from'react';import {lockedTurnToResend,offeredFreeCredits,withLockedRepliesOnPhone}from'./lockedReply.js';const FREE_CREDITS_YES_FAILED = "We couldn't claim your free credits. Please try again.";
2
+ function useFreeCreditsYes({
3
+ messages,
4
+ claim,
5
+ send,
6
+ busy = false
7
+ }) {
8
+ const lockedTurn = useMemo(() => claim ? lockedTurnToResend(messages) : null, [claim, messages]);
9
+ const credits = useMemo(() => {
10
+ var _a;
11
+ return lockedTurn ? offeredFreeCredits((_a = messages[messages.length - 1]) == null ? void 0 : _a.content) : 0;
12
+ }, [lockedTurn, messages]);
13
+ const shownMessages = useMemo(() => claim ? withLockedRepliesOnPhone(messages) : [...messages], [claim, messages]);
14
+ const [claiming, setClaiming] = useState(false);
15
+ const [error, setError] = useState(null);
16
+ useEffect(() => setError(null), [lockedTurn]);
17
+ const live = useRef(true);
18
+ useEffect(() => () => {
19
+ live.current = false;
20
+ }, []);
21
+ const onYes = useCallback(() => {
22
+ if (!claim || !lockedTurn || claiming) return;
23
+ setClaiming(true);
24
+ setError(null);
25
+ void claim().catch((err) => ({
26
+ unlocked: false,
27
+ error: err instanceof Error ? err.message : FREE_CREDITS_YES_FAILED
28
+ })).then((result) => {
29
+ if (!live.current) return;
30
+ setClaiming(false);
31
+ if (!result.unlocked) {
32
+ setError(result.error || FREE_CREDITS_YES_FAILED);
33
+ return;
34
+ }
35
+ send(lockedTurn.content, lockedTurn.attachments);
36
+ });
37
+ }, [claim, lockedTurn, claiming, send]);
38
+ const offer = lockedTurn && !busy ? {
39
+ credits,
40
+ claiming,
41
+ error,
42
+ onYes
43
+ } : null;
44
+ return {
45
+ shownMessages,
46
+ offer
47
+ };
48
+ }export{FREE_CREDITS_YES_FAILED,useFreeCreditsYes};//# sourceMappingURL=useFreeCreditsYes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFreeCreditsYes.js","sources":["../../../src/features/credits/useFreeCreditsYes.ts"],"sourcesContent":["/**\n * A chat's Yes to its newest reply refusing for free credits never claimed: the thread as the\n * phone shows it (the refusal without its link to the web app), and what the Yes card needs.\n * Yes claims the credits (claim, the host's) and sends the refused message again through send,\n * so the chat routes it as it first did (the Travel Agent's own flight search, the agent).\n *\n * Free of the data stack (no Apollo): a native surface's chat, which ships in a remote, uses it.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { MessageAttachment } from '../../hooks/useChatStream';\nimport { lockedTurnToResend, offeredFreeCredits, withLockedRepliesOnPhone } from './lockedReply';\n\nexport interface FreeCreditsYesOffer {\n /** What the refusal offered (\"5,000 free credits\"), 0 when it named no number. */\n credits: number;\n claiming: boolean;\n error: string | null;\n onYes: () => void;\n}\n\ninterface ChatRow {\n role: string;\n content: string;\n attachments?: MessageAttachment[];\n}\n\nexport const FREE_CREDITS_YES_FAILED = \"We couldn't claim your free credits. Please try again.\";\n\nexport function useFreeCreditsYes<T extends ChatRow>({\n messages,\n claim,\n send,\n busy = false,\n}: {\n messages: readonly T[];\n /** The host's claim; without one the refusal shows as the agent wrote it and no Yes is offered. */\n claim?: () => Promise<{ unlocked: boolean; error?: string }>;\n send: (text: string, attachments?: MessageAttachment[]) => void;\n /** A reply is running: no Yes until it ends. */\n busy?: boolean;\n}): { shownMessages: T[]; offer: FreeCreditsYesOffer | null } {\n const lockedTurn = useMemo(() => (claim ? lockedTurnToResend(messages) : null), [claim, messages]);\n const credits = useMemo(\n () => (lockedTurn ? offeredFreeCredits(messages[messages.length - 1]?.content) : 0),\n [lockedTurn, messages],\n );\n const shownMessages = useMemo(\n () => (claim ? withLockedRepliesOnPhone(messages) : [...messages]),\n [claim, messages],\n );\n\n const [claiming, setClaiming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n // A new refusal starts clean.\n useEffect(() => setError(null), [lockedTurn]);\n const live = useRef(true);\n useEffect(\n () => () => {\n live.current = false;\n },\n [],\n );\n\n const onYes = useCallback(() => {\n if (!claim || !lockedTurn || claiming) return;\n setClaiming(true);\n setError(null);\n void claim()\n .catch((err: unknown) => ({\n unlocked: false,\n error: err instanceof Error ? err.message : FREE_CREDITS_YES_FAILED,\n }))\n .then((result) => {\n if (!live.current) return;\n setClaiming(false);\n if (!result.unlocked) {\n setError(result.error || FREE_CREDITS_YES_FAILED);\n return;\n }\n send(lockedTurn.content, lockedTurn.attachments);\n });\n }, [claim, lockedTurn, claiming, send]);\n\n const offer = lockedTurn && !busy ? { credits, claiming, error, onYes } : null;\n return { shownMessages, offer };\n}\n"],"names":[],"mappings":"gKAuBO,MAAM,uBAA0B,GAAA;AAChC,SAAS,iBAAqC,CAAA;AAAA,EACnD,QAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAO,GAAA;AACT,CAaE,EAAA;AACA,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,MAAM,KAAQ,GAAA,kBAAA,CAAmB,QAAQ,CAAA,GAAI,IAAM,EAAA,CAAC,KAAO,EAAA,QAAQ,CAAC,CAAA;AAC/F,EAAM,MAAA,OAAA,GAAU,QAAQ,MAAG;AA5C7B,IAAA,IAAA,EAAA;AA4CgC,IAAa,OAAA,UAAA,GAAA,kBAAA,CAA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A,CAAC,OAAO,QAAU,EAAA;AACpB,QAAS,QAAA,CAAA,MAAA,CAAO,SAAS,uBAAuB,CAAA;AAChD,QAAA;AAAA;AAEF,MAAK,IAAA,CAAA,UAAA,CAAW,OAAS,EAAA,UAAA,CAAW,WAAW,CAAA;AAAA,KAChD,CAAA;AAAA,KACA,CAAC,KAAA,EAAO,UAAY,EAAA,QAAA,EAAU,IAAI,CAAC,CAAA;AACtC,EAAM,MAAA,KAAA,GAAQ,UAAc,IAAA,CAAC,IAAO,GAAA;AAAA,IAClC,OAAA;AAAA,IACA,QAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACE,GAAA,IAAA;AACJ,EAAO,OAAA;AAAA,IACL,aAAA;AAAA,IACA;AAAA,GACF;AACF"}
@@ -1,4 +1,4 @@
1
- import {useMemo,useState,useRef,useCallback,useEffect}from'react';import {speechRecognitionNative}from'./dictateVoice.js';function speechLanguage() {
1
+ import {useMemo,useState,useRef,useCallback,useEffect}from'react';import {NOTHING_HEARD,hearResult}from'../audio-input/speechParts.js';import {speechRecognitionNative}from'./dictateVoice.js';function speechLanguage() {
2
2
  try {
3
3
  const {
4
4
  locale
@@ -14,6 +14,7 @@ function useVoiceQuestion(onQuestion) {
14
14
  const [heard, setHeard] = useState("");
15
15
  const [error, setError] = useState(null);
16
16
  const heardRef = useRef("");
17
+ const partsRef = useRef(NOTHING_HEARD);
17
18
  const subsRef = useRef([]);
18
19
  const onQuestionRef = useRef(onQuestion);
19
20
  onQuestionRef.current = onQuestion;
@@ -40,9 +41,10 @@ function useVoiceQuestion(onQuestion) {
40
41
  return;
41
42
  }
42
43
  heardRef.current = "";
44
+ partsRef.current = NOTHING_HEARD;
43
45
  subsRef.current = [ears.addListener("result", (event) => {
44
- var _a2, _b, _c;
45
- heardRef.current = (_c = (_b = (_a2 = event.results) == null ? void 0 : _a2[0]) == null ? void 0 : _b.transcript) != null ? _c : heardRef.current;
46
+ partsRef.current = hearResult(partsRef.current, event);
47
+ heardRef.current = partsRef.current.text;
46
48
  setHeard(heardRef.current);
47
49
  }), ears.addListener("end", () => settle(true)), ears.addListener("error", (event) => {
48
50
  const quiet = event.error === "no-speech" || event.error === "aborted";
@@ -1 +1 @@
1
- {"version":3,"file":"useVoiceQuestion.js","sources":["../../../src/features/dictate/useVoiceQuestion.ts"],"sourcesContent":["/**\n * Asking about a note by voice: the phone's speech recognition hears the\n * question (through AirPods when they are in: it records with Bluetooth\n * allowed), on the device whenever the phone can, and hands over the words\n * once the person stops talking. What they said then goes the way a typed\n * question does, names the note knows hidden before it leaves the phone.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { speechRecognitionNative } from './dictateVoice';\n\n/** The phone's language as a recogniser takes it (\"en-US\"); English when it cannot tell. */\nexport function speechLanguage(): string {\n try {\n const { locale } = Intl.DateTimeFormat().resolvedOptions();\n return /^[a-z]{2,3}-[A-Z]{2}$/.test(locale) ? locale : 'en-US';\n } catch {\n return 'en-US';\n }\n}\n\nexport interface VoiceQuestion {\n /** This binary can hear a question. */\n available: boolean;\n listening: boolean;\n /** The words so far, while listening. */\n heard: string;\n error: string | null;\n start(): void;\n /** Done talking: send what was heard. */\n finish(): void;\n cancel(): void;\n}\n\nexport function useVoiceQuestion(onQuestion: (text: string) => void): VoiceQuestion {\n const ears = useMemo(() => speechRecognitionNative(), []);\n const [listening, setListening] = useState(false);\n const [heard, setHeard] = useState('');\n const [error, setError] = useState<string | null>(null);\n const heardRef = useRef('');\n const subsRef = useRef<Array<{ remove(): void }>>([]);\n const onQuestionRef = useRef(onQuestion);\n onQuestionRef.current = onQuestion;\n\n // Once per question, whichever of `end` and `error` comes first.\n const settle = useCallback((send: boolean) => {\n if (!subsRef.current.length) return;\n subsRef.current.forEach((s) => s.remove());\n subsRef.current = [];\n const text = heardRef.current.trim();\n heardRef.current = '';\n setHeard('');\n setListening(false);\n if (send && text) onQuestionRef.current(text);\n }, []);\n\n const start = useCallback(() => {\n if (!ears || subsRef.current.length) return;\n setError(null);\n void (async () => {\n const permission = await ears.requestPermissionsAsync().catch(() => ({ granted: false }));\n if (!permission.granted) {\n setError('Allow the microphone and speech recognition for Yantra in Settings to ask by voice.');\n return;\n }\n heardRef.current = '';\n subsRef.current = [\n ears.addListener('result', (event) => {\n heardRef.current = event.results?.[0]?.transcript ?? heardRef.current;\n setHeard(heardRef.current);\n }),\n ears.addListener('end', () => settle(true)),\n ears.addListener('error', (event) => {\n // Silence or a stop is not a failure: whatever was heard still goes.\n const quiet = event.error === 'no-speech' || event.error === 'aborted';\n if (!quiet) setError('The question was not heard. Try again, or type it.');\n settle(quiet);\n }),\n ];\n setListening(true);\n try {\n ears.start({\n lang: speechLanguage(),\n interimResults: true,\n continuous: false,\n addsPunctuation: true,\n // On the device when the phone can: then the question never leaves it until it is sent.\n requiresOnDeviceRecognition: ears.supportsOnDeviceRecognition?.() === true,\n });\n } catch {\n setError('The question was not heard. Try again, or type it.');\n settle(false);\n }\n })();\n }, [ears, settle]);\n\n const finish = useCallback(() => {\n try {\n ears?.stop();\n } catch {\n settle(true);\n }\n }, [ears, settle]);\n\n const cancel = useCallback(() => {\n try {\n ears?.abort();\n } catch {\n /* already stopped */\n }\n settle(false);\n }, [ears, settle]);\n\n useEffect(\n () => () => {\n if (!subsRef.current.length) return;\n subsRef.current.forEach((s) => s.remove());\n subsRef.current = [];\n try {\n ears?.abort();\n } catch {\n /* already stopped */\n }\n },\n [ears],\n );\n\n return { available: !!ears, listening, heard, error, start, finish, cancel };\n}\n"],"names":["_a"],"mappings":"0HAWO,SAAS,cAAyB,GAAA;AACvC,EAAI,IAAA;AACF,IAAM,MAAA;AAAA,MACJ;AAAA,KACE,GAAA,IAAA,CAAK,cAAe,EAAA,CAAE,eAAgB,EAAA;AAC1C,IAAA,OAAO,uBAAwB,CAAA,IAAA,CAAK,MAAM,CAAA,GAAI,MAAS,GAAA,OAAA;AAAA,GACjD,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,OAAA;AAAA;AAEX;AAaO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,CAAQ,UAAU,EAAC;AACnB,IAAI,IAAA;AACF,MAAM,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAA,KAAA,EAAA;AAAA,KACA,CAAA,OAAA,CAAA,EAAA;AAAA;AAER,GACF,EAAG,CAAC,IAAI,CAAC,CAAA;AACT,EAAO,OAAA;AAAA,IACL,SAAA,EAAW,CAAC,CAAC,IAAA;AAAA,IACb,SAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF"}
1
+ {"version":3,"file":"useVoiceQuestion.js","sources":["../../../src/features/dictate/useVoiceQuestion.ts"],"sourcesContent":["/**\n * Asking about a note by voice: the phone's speech recognition hears the\n * question (through AirPods when they are in: it records with Bluetooth\n * allowed), on the device whenever the phone can, and hands over the words\n * once the person stops talking. What they said then goes the way a typed\n * question does, names the note knows hidden before it leaves the phone.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { hearResult, NOTHING_HEARD, type HeardSoFar } from '../audio-input/speechParts';\nimport { speechRecognitionNative } from './dictateVoice';\n\n/** The phone's language as a recogniser takes it (\"en-US\"); English when it cannot tell. */\nexport function speechLanguage(): string {\n try {\n const { locale } = Intl.DateTimeFormat().resolvedOptions();\n return /^[a-z]{2,3}-[A-Z]{2}$/.test(locale) ? locale : 'en-US';\n } catch {\n return 'en-US';\n }\n}\n\nexport interface VoiceQuestion {\n /** This binary can hear a question. */\n available: boolean;\n listening: boolean;\n /** The words so far, while listening. */\n heard: string;\n error: string | null;\n start(): void;\n /** Done talking: send what was heard. */\n finish(): void;\n cancel(): void;\n}\n\nexport function useVoiceQuestion(onQuestion: (text: string) => void): VoiceQuestion {\n const ears = useMemo(() => speechRecognitionNative(), []);\n const [listening, setListening] = useState(false);\n const [heard, setHeard] = useState('');\n const [error, setError] = useState<string | null>(null);\n const heardRef = useRef('');\n // The parts heard so far: a pause closes one and the next results cover only the words after it.\n const partsRef = useRef<HeardSoFar>(NOTHING_HEARD);\n const subsRef = useRef<Array<{ remove(): void }>>([]);\n const onQuestionRef = useRef(onQuestion);\n onQuestionRef.current = onQuestion;\n\n // Once per question, whichever of `end` and `error` comes first.\n const settle = useCallback((send: boolean) => {\n if (!subsRef.current.length) return;\n subsRef.current.forEach((s) => s.remove());\n subsRef.current = [];\n const text = heardRef.current.trim();\n heardRef.current = '';\n setHeard('');\n setListening(false);\n if (send && text) onQuestionRef.current(text);\n }, []);\n\n const start = useCallback(() => {\n if (!ears || subsRef.current.length) return;\n setError(null);\n void (async () => {\n const permission = await ears.requestPermissionsAsync().catch(() => ({ granted: false }));\n if (!permission.granted) {\n setError('Allow the microphone and speech recognition for Yantra in Settings to ask by voice.');\n return;\n }\n heardRef.current = '';\n partsRef.current = NOTHING_HEARD;\n subsRef.current = [\n ears.addListener('result', (event) => {\n partsRef.current = hearResult(partsRef.current, event);\n heardRef.current = partsRef.current.text;\n setHeard(heardRef.current);\n }),\n ears.addListener('end', () => settle(true)),\n ears.addListener('error', (event) => {\n // Silence or a stop is not a failure: whatever was heard still goes.\n const quiet = event.error === 'no-speech' || event.error === 'aborted';\n if (!quiet) setError('The question was not heard. Try again, or type it.');\n settle(quiet);\n }),\n ];\n setListening(true);\n try {\n ears.start({\n lang: speechLanguage(),\n interimResults: true,\n continuous: false,\n addsPunctuation: true,\n // On the device when the phone can: then the question never leaves it until it is sent.\n requiresOnDeviceRecognition: ears.supportsOnDeviceRecognition?.() === true,\n });\n } catch {\n setError('The question was not heard. Try again, or type it.');\n settle(false);\n }\n })();\n }, [ears, settle]);\n\n const finish = useCallback(() => {\n try {\n ears?.stop();\n } catch {\n settle(true);\n }\n }, [ears, settle]);\n\n const cancel = useCallback(() => {\n try {\n ears?.abort();\n } catch {\n /* already stopped */\n }\n settle(false);\n }, [ears, settle]);\n\n useEffect(\n () => () => {\n if (!subsRef.current.length) return;\n subsRef.current.forEach((s) => s.remove());\n subsRef.current = [];\n try {\n ears?.abort();\n } catch {\n /* already stopped */\n }\n },\n [ears],\n );\n\n return { available: !!ears, listening, heard, error, start, finish, cancel };\n}\n"],"names":[],"mappings":"+LAYO,SAAS,cAAyB,GAAA;AACvC,EAAI,IAAA;AACF,IAAM,MAAA;AAAA,MACJ;AAAA,KACE,GAAA,IAAA,CAAK,cAAe,EAAA,CAAE,eAAgB,EAAA;AAC1C,IAAA,OAAO,uBAAwB,CAAA,IAAA,CAAK,MAAM,CAAA,GAAI,MAAS,GAAA,OAAA;AAAA,GACjD,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,OAAA;AAAA;AAEX;AAaO,SAAS,iBAAiB,UAAmD,EAAA;AAClF,EAAA,MAAM,OAAO,OAAQ,CAAA,MAAM,uBAAwB,EAAA,EAAG,EAAE,CAAA;AACxD,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA;AAChD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,EAAE,CAAA;AACrC,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAwB,IAAI,CAAA;AACtD,EAAM,MAAA,QAAA,GAAW,OAAO,EAAE,CAAA;AAE1B,EAAM,MAAA,QAAA,GAAW,OAAmB,aAAa,CAAA;AACjD,EAAM,MAAA,OAAA,GAAU,MAEZ,CAAA,EAAE,CAAA;AACN,EAAM,MAAA,aAAA,GAAgB,OAAO,UAAU,CAAA;AACvC,EAAA,aAAA,CAAc,OAAU,GAAA,UAAA;AAGxB,EAAM,MAAA,MAAA,GAAS,WAAY,CAAA,CAAC,IAAkB,KAAA;AAC5C,IAAI,IAAA,CAAC,OAAQ,CAAA,OAAA,CAAQ,MAAQ,EAAA;AAC7B,IAAA,OAAA,CAAQ,OAAQ,CAAA,OAAA,CAAQ,CAAK,CAAA,KAAA,CAAA,CAAE,QAAQ,CAAA;AACvC,IAAA,OAAA,CAAQ,UAAU,EAAC;AACnB,IA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R,IAAA,MAAA,CAAO,KAAK,CAAA;AAAA,GACX,EAAA,CAAC,IAAM,EAAA,MAAM,CAAC,CAAA;AACjB,EAAA,SAAA,CAAU,MAAM,MAAM;AACpB,IAAI,IAAA,CAAC,OAAQ,CAAA,OAAA,CAAQ,MAAQ,EAAA;AAC7B,IAAA,OAAA,CAAQ,OAAQ,CAAA,OAAA,CAAQ,CAAK,CAAA,KAAA,CAAA,CAAE,QAAQ,CAAA;AACvC,IAAA,OAAA,CAAQ,UAAU,EAAC;AACnB,IAAI,IAAA;AACF,MAAM,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAA,KAAA,EAAA;AAAA,KACA,CAAA,OAAA,CAAA,EAAA;AAAA;AAER,GACF,EAAG,CAAC,IAAI,CAAC,CAAA;AACT,EAAO,OAAA;AAAA,IACL,SAAA,EAAW,CAAC,CAAC,IAAA;AAAA,IACb,SAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF"}
@@ -0,0 +1,76 @@
1
+ const AIRPORT_CODES = {
2
+ ATL: "Atlanta, GA",
3
+ AUS: "Austin, TX",
4
+ BNA: "Nashville, TN",
5
+ BOS: "Boston, MA",
6
+ BWI: "Baltimore, MD",
7
+ CLT: "Charlotte, NC",
8
+ DCA: "Washington, DC",
9
+ DEN: "Denver, CO",
10
+ DFW: "Dallas, TX",
11
+ DTW: "Detroit, MI",
12
+ EWR: "Newark, NJ",
13
+ FLL: "Fort Lauderdale, FL",
14
+ HNL: "Honolulu, HI",
15
+ IAD: "Washington Dulles, DC",
16
+ IAH: "Houston, TX",
17
+ JFK: "New York, NY",
18
+ LAS: "Las Vegas, NV",
19
+ LAX: "Los Angeles, CA",
20
+ LGA: "New York LaGuardia, NY",
21
+ MCO: "Orlando, FL",
22
+ MDW: "Chicago Midway, IL",
23
+ MIA: "Miami, FL",
24
+ MSP: "Minneapolis, MN",
25
+ MSY: "New Orleans, LA",
26
+ OAK: "Oakland, CA",
27
+ ORD: "Chicago, IL",
28
+ PDX: "Portland, OR",
29
+ PHL: "Philadelphia, PA",
30
+ PHX: "Phoenix, AZ",
31
+ PIT: "Pittsburgh, PA",
32
+ RDU: "Raleigh, NC",
33
+ SAN: "San Diego, CA",
34
+ SAT: "San Antonio, TX",
35
+ SEA: "Seattle, WA",
36
+ SFO: "San Francisco, CA",
37
+ SJC: "San Jose, CA",
38
+ SLC: "Salt Lake City, UT",
39
+ STL: "St Louis, MO",
40
+ TPA: "Tampa, FL",
41
+ YYZ: "Toronto, ON",
42
+ YVR: "Vancouver, BC",
43
+ YUL: "Montreal, QC",
44
+ MEX: "Mexico City, Mexico",
45
+ CUN: "Cancun, Mexico",
46
+ LHR: "London Heathrow, UK",
47
+ LGW: "London Gatwick, UK",
48
+ STN: "London Stansted, UK",
49
+ MAN: "Manchester, UK",
50
+ EDI: "Edinburgh, UK",
51
+ DUB: "Dublin, Ireland",
52
+ CDG: "Paris, France",
53
+ AMS: "Amsterdam, Netherlands",
54
+ FRA: "Frankfurt, Germany",
55
+ MUC: "Munich, Germany",
56
+ BER: "Berlin, Germany",
57
+ ZRH: "Zurich, Switzerland",
58
+ MAD: "Madrid, Spain",
59
+ BCN: "Barcelona, Spain",
60
+ LIS: "Lisbon, Portugal",
61
+ FCO: "Rome, Italy",
62
+ MXP: "Milan, Italy",
63
+ DXB: "Dubai, UAE",
64
+ DEL: "Delhi, India",
65
+ BOM: "Mumbai, India",
66
+ BLR: "Bengaluru, India",
67
+ SIN: "Singapore",
68
+ BKK: "Bangkok, Thailand",
69
+ HKG: "Hong Kong",
70
+ NRT: "Tokyo Narita, Japan",
71
+ HND: "Tokyo Haneda, Japan",
72
+ ICN: "Seoul, South Korea",
73
+ SYD: "Sydney, Australia",
74
+ MEL: "Melbourne, Australia",
75
+ GRU: "Sao Paulo, Brazil"
76
+ };export{AIRPORT_CODES};//# sourceMappingURL=airportCodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airportCodes.js","sources":["../../../src/features/travel/airportCodes.ts"],"sourcesContent":["/**\n * The small table of airport labels chat words and airport fields resolve to (ATL ->\n * \"Atlanta, GA\"). Its own module so the airport index can read it while the chat parser\n * reads the index.\n */\nexport const AIRPORT_CODES: Record<string, string> = {\n ATL: 'Atlanta, GA',\n AUS: 'Austin, TX',\n BNA: 'Nashville, TN',\n BOS: 'Boston, MA',\n BWI: 'Baltimore, MD',\n CLT: 'Charlotte, NC',\n DCA: 'Washington, DC',\n DEN: 'Denver, CO',\n DFW: 'Dallas, TX',\n DTW: 'Detroit, MI',\n EWR: 'Newark, NJ',\n FLL: 'Fort Lauderdale, FL',\n HNL: 'Honolulu, HI',\n IAD: 'Washington Dulles, DC',\n IAH: 'Houston, TX',\n JFK: 'New York, NY',\n LAS: 'Las Vegas, NV',\n LAX: 'Los Angeles, CA',\n LGA: 'New York LaGuardia, NY',\n MCO: 'Orlando, FL',\n MDW: 'Chicago Midway, IL',\n MIA: 'Miami, FL',\n MSP: 'Minneapolis, MN',\n MSY: 'New Orleans, LA',\n OAK: 'Oakland, CA',\n ORD: 'Chicago, IL',\n PDX: 'Portland, OR',\n PHL: 'Philadelphia, PA',\n PHX: 'Phoenix, AZ',\n PIT: 'Pittsburgh, PA',\n RDU: 'Raleigh, NC',\n SAN: 'San Diego, CA',\n SAT: 'San Antonio, TX',\n SEA: 'Seattle, WA',\n SFO: 'San Francisco, CA',\n SJC: 'San Jose, CA',\n SLC: 'Salt Lake City, UT',\n STL: 'St Louis, MO',\n TPA: 'Tampa, FL',\n YYZ: 'Toronto, ON',\n YVR: 'Vancouver, BC',\n YUL: 'Montreal, QC',\n MEX: 'Mexico City, Mexico',\n CUN: 'Cancun, Mexico',\n LHR: 'London Heathrow, UK',\n LGW: 'London Gatwick, UK',\n STN: 'London Stansted, UK',\n MAN: 'Manchester, UK',\n EDI: 'Edinburgh, UK',\n DUB: 'Dublin, Ireland',\n CDG: 'Paris, France',\n AMS: 'Amsterdam, Netherlands',\n FRA: 'Frankfurt, Germany',\n MUC: 'Munich, Germany',\n BER: 'Berlin, Germany',\n ZRH: 'Zurich, Switzerland',\n MAD: 'Madrid, Spain',\n BCN: 'Barcelona, Spain',\n LIS: 'Lisbon, Portugal',\n FCO: 'Rome, Italy',\n MXP: 'Milan, Italy',\n DXB: 'Dubai, UAE',\n DEL: 'Delhi, India',\n BOM: 'Mumbai, India',\n BLR: 'Bengaluru, India',\n SIN: 'Singapore',\n BKK: 'Bangkok, Thailand',\n HKG: 'Hong Kong',\n NRT: 'Tokyo Narita, Japan',\n HND: 'Tokyo Haneda, Japan',\n ICN: 'Seoul, South Korea',\n SYD: 'Sydney, Australia',\n MEL: 'Melbourne, Australia',\n GRU: 'Sao Paulo, Brazil',\n};\n"],"names":[],"mappings":"AAKO,MAAM,aAAwC,GAAA;AAAA,EACnD,GAAK,EAAA,aAAA;AAAA,EACL,GAAK,EAAA,YAAA;AAAA,EACL,GAAK,EAAA,eAAA;AAAA,EACL,GAAK,EAAA,YAAA;AAAA,EACL,GAAK,EAAA,eAAA;AAAA,EACL,GAAK,EAAA,eAAA;AAAA,EACL,GAAK,EAAA,gBAAA;AAAA,EACL,GAAK,EAAA,YAAA;AAAA,EACL,GAAK,EAAA,YAAA;AAAA,EACL,GAAK,EAAA,aAAA;AAAA,EACL,GAAK,EAAA,YAAA;AAAA,EACL,GAAK,EAAA,qBAAA;AAAA,EACL,GAAK,EAAA,cAAA;AAAA,EACL,GAAK,EAAA,uBAAA;AAAA,EACL,GAAK,EAAA,aAAA;AAAA,EACL,GAAK,EAAA,cAAA;AAAA,EACL,GAAK,EAAA,eAAA;AAAA,EACL,GAAK,EAAA,iBAAA;AAAA,EACL,GAAK,EAAA,wBAAA;AAAA,EACL,GAAK,EAAA,aAAA;AAAA,EACL,GAAK,EAAA,oBAAA;AAAA,EACL,GAAK,EAAA,WAAA;AAAA,EACL,GAAK,EAAA,iBAAA;AAAA,EACL,GAAK,EAAA,iBAAA;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AAA;AAAA,EACL,GAAK,EAAA,mBAAA;AAAA,EACL,GAAK,EAAA,WAAA;AAAA,EACL,GAAK,EAAA,qBAAA;AAAA,EACL,GAAK,EAAA,qBAAA;AAAA,EACL,GAAK,EAAA,oBAAA;AAAA,EACL,GAAK,EAAA,mBAAA;AAAA,EACL,GAAK,EAAA,sBAAA;AAAA,EACL,GAAK,EAAA;AACP"}
@@ -1,4 +1,4 @@
1
- import {AIRPORT_CODES}from'./parseTravelIntent.js';import {AIRPORTS_SOURCE,AIRPORT_REGIONS_SOURCE,AIRPORT_COUNTRIES_SOURCE}from'./airportIndexData.js';const CITY_ALIASES = {
1
+ import {AIRPORT_CODES}from'./airportCodes.js';import {AIRPORTS_SOURCE,AIRPORT_REGIONS_SOURCE,AIRPORT_COUNTRIES_SOURCE}from'./airportIndexData.js';const CITY_ALIASES = {
2
2
  bombay: "BOM",
3
3
  calcutta: "CCU",
4
4
  goa: "GOI",
@@ -1 +1 @@
1
- {"version":3,"file":"airportIndex.js","sources":["../../../src/features/travel/airportIndex.ts"],"sourcesContent":["/**\n * Every airport with scheduled passenger service, for the flight From / To fields:\n * suggestions as the person types, and the airport a typed or picked place means.\n *\n * The flight connector takes IATA codes only. The field used to offer street-level\n * place suggestions and then look the text up in a table of ~70 cities, so \"Hyd\" and\n * \"Hyderabad, Telangana, India\" both ended in \"Could not find an airport\".\n */\nimport { AIRPORT_CODES } from './parseTravelIntent';\nimport { AIRPORTS_SOURCE, AIRPORT_COUNTRIES_SOURCE, AIRPORT_REGIONS_SOURCE } from './airportIndexData';\n\nexport interface Airport {\n /** IATA code, e.g. HYD. */\n code: string;\n city: string;\n /** Airport name without a trailing \"Airport\", e.g. \"Rajiv Gandhi International\". */\n name: string;\n /** ISO country code. */\n country: string;\n countryName: string;\n regionName: string;\n size: 'L' | 'M' | 'S';\n}\n\ninterface Entry {\n airport: Airport;\n cityKey: string;\n nameKey: string;\n aliasKeys: string[];\n /** Words of the city, name and alternate names. */\n words: Set<string>;\n /** Words of the airport's own name, not its town's (\"heathrow\", \"gatwick\", \"kennedy\"). */\n nameWords: Set<string>;\n /** Words of its state and country, so \"Hyderabad India\" needs no comma. */\n placeWords: Set<string>;\n countryKey: string;\n regionKey: string;\n /** \"GA\" of US-GA - how \"Atlanta, GA, USA\" names the state. */\n regionCode: string;\n /** In the hand-kept city table as its city's main airport. */\n primary: boolean;\n /** Names that point straight at it (CITY_ALIASES: \"Bombay\", \"NYC\"). */\n explicitAliases: string[];\n /** That table's city (\"Dallas\" for DFW, \"Delhi\" for DEL), when it has the airport. */\n preferredCityKey: string;\n}\n\n/** Older, local and short names the source does not carry, or spreads over several airports. */\nconst CITY_ALIASES: Record<string, string> = {\n bombay: 'BOM',\n calcutta: 'CCU',\n goa: 'GOI',\n peking: 'PEK',\n saigon: 'SGN',\n 'ho chi minh': 'SGN',\n ny: 'JFK',\n nyc: 'JFK',\n sf: 'SFO',\n la: 'LAX',\n dc: 'DCA',\n 'washington dc': 'DCA',\n vegas: 'LAS',\n};\n\n/** In the hand-kept table, but not their city's main airport. */\nconst SECONDARY_AIRPORTS = new Set(['EWR', 'IAD', 'LGA', 'LGW', 'MDW', 'STN']);\n\n/** How place suggestions spell a country (\"Atlanta, GA, USA\"). */\nconst COUNTRY_ALIASES: Record<string, string> = {\n us: 'US',\n usa: 'US',\n america: 'US',\n uk: 'GB',\n england: 'GB',\n uae: 'AE',\n};\n\n/** Words that say \"airport\" without naming one (\"JFK Airport\", \"Heathrow intl\"). */\nconst FILLER = new Set(['airport', 'airports', 'international', 'intl', 'the']);\n\n/**\n * Airport-name words too common to name one airport: \"new\" is not Baghdad's\n * \"New Al Muthana\", \"santa\" no single field.\n */\nconst NAME_STOPWORDS = new Set([\n 'regional',\n 'municipal',\n 'county',\n 'national',\n 'airfield',\n 'airstrip',\n 'field',\n 'island',\n 'general',\n 'memorial',\n 'metropolitan',\n 'executive',\n 'north',\n 'south',\n 'santa',\n 'saint',\n 'airbase',\n]);\n\n/**\n * A small field that IS the town typed (\"Tok\", Alaska) is still a worse guess, while\n * typing, than the hub the letters begin (\"Tokyo\"); a whole name decides on the match.\n */\nconst SIZE_BONUS = {\n typing: { L: 35, M: 12, S: 0 },\n whole: { L: 6, M: 3, S: 0 },\n} as const;\n\n/** Lower-case ASCII words: accents folded, punctuation dropped. */\nexport function foldPlace(text: string): string {\n return text\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, ' ')\n .trim();\n}\n\nfunction table(source: string): Map<string, string> {\n const map = new Map<string, string>();\n for (const line of source.split('\\n')) {\n const cut = line.indexOf('|');\n if (cut > 0) map.set(line.slice(0, cut), line.slice(cut + 1));\n }\n return map;\n}\n\nlet index: { entries: Entry[]; byCode: Map<string, Entry> } | null = null;\n\nfunction airportIndex(): { entries: Entry[]; byCode: Map<string, Entry> } {\n if (index) return index;\n const countries = table(AIRPORT_COUNTRIES_SOURCE);\n const regions = table(AIRPORT_REGIONS_SOURCE);\n const entries: Entry[] = [];\n const byCode = new Map<string, Entry>();\n const rows = AIRPORTS_SOURCE.split('\\n')\n .map((line) => line.split('|'))\n .filter(([code, city]) => code?.length === 3 && Boolean(city));\n for (const [code, city, name, country, region, size, alternates] of rows) {\n const airport: Airport = {\n code,\n city,\n name,\n country,\n countryName: countries.get(country) ?? country,\n regionName: regions.get(region) ?? '',\n size: (size as Airport['size']) || 'S',\n };\n const aliasKeys = (alternates ? alternates.split(';') : []).map(foldPlace).filter(Boolean);\n const cityKey = foldPlace(city);\n const nameKey = foldPlace(name);\n const preferredLabel = AIRPORT_CODES[code];\n const entry: Entry = {\n airport,\n cityKey,\n nameKey,\n aliasKeys,\n words: new Set([cityKey, nameKey, ...aliasKeys].join(' ').split(' ').filter(Boolean)),\n nameWords: new Set(\n nameKey\n .split(' ')\n .filter(\n (word) =>\n word.length >= 5 &&\n !FILLER.has(word) &&\n !NAME_STOPWORDS.has(word) &&\n !cityKey.split(' ').includes(word),\n ),\n ),\n placeWords: new Set(\n [foldPlace(airport.countryName), foldPlace(airport.regionName)].join(' ').split(' ').filter(Boolean),\n ),\n countryKey: foldPlace(airport.countryName),\n regionKey: foldPlace(airport.regionName),\n regionCode: foldPlace(region.split('-')[1] ?? ''),\n primary: Boolean(preferredLabel) && !SECONDARY_AIRPORTS.has(code),\n explicitAliases: [],\n preferredCityKey: preferredLabel ? foldPlace(preferredLabel.split(',')[0] ?? '') : '',\n };\n entries.push(entry);\n byCode.set(code, entry);\n }\n for (const [alias, code] of Object.entries(CITY_ALIASES)) byCode.get(code)?.explicitAliases.push(alias);\n index = { entries, byCode };\n return index;\n}\n\nexport function airportByCode(code: string): Airport | undefined {\n return airportIndex().byCode.get(code.trim().toUpperCase())?.airport;\n}\n\n/** What a picked airport reads as in its field - and resolves back from: \"Hyderabad (HYD)\". */\nexport function airportLabel(airport: Pick<Airport, 'city' | 'code'>): string {\n return `${airport.city} (${airport.code})`;\n}\n\n/** \"Rajiv Gandhi International · Telangana, India\" */\nexport function airportDetail(airport: Airport): string {\n const where = [airport.regionName, airport.countryName].filter(Boolean).join(', ');\n return [airport.name !== airport.city ? airport.name : '', where].filter(Boolean).join(' · ');\n}\n\ninterface Query {\n /** The place itself: the first comma part, minus \"airport\" words. */\n place: string;\n placeWords: string[];\n /** The rest (\"GA, USA\", \"Telangana, India\"): which state or country is meant. */\n hints: string[];\n}\n\nfunction toQuery(text: string): Query | null {\n const [first, ...rest] = text.split(',');\n const placeWords = foldPlace(first ?? '')\n .split(' ')\n .filter((word) => word && !FILLER.has(word));\n if (!placeWords.length) return null;\n return { place: placeWords.join(' '), placeWords, hints: rest.map(foldPlace).filter(Boolean) };\n}\n\n/** How well an airport matches the place typed: 0 = not at all. */\nfunction placeScore(entry: Entry, query: Query, prefixes: boolean): number {\n const { place, placeWords } = query;\n if (entry.preferredCityKey === place) return 105;\n if (entry.cityKey === place) return 100;\n if (entry.explicitAliases.includes(place)) return 98;\n if (entry.aliasKeys.includes(place)) return 95;\n if (place.length === 3 && entry.airport.code === place.toUpperCase()) return 90;\n if (entry.nameKey === place) return 85;\n // One word names a city, a code or an airport (\"Heathrow\"); \"York\" is not New York.\n const named = (word: string) => entry.words.has(word) || entry.placeWords.has(word);\n if (\n placeWords.length === 1\n ? entry.nameWords.has(place)\n : placeWords.some((word) => entry.words.has(word)) && placeWords.every(named)\n ) {\n return 75;\n }\n if (!prefixes || place.length < 2) return 0;\n if (entry.cityKey.startsWith(place)) return 60;\n if ([...entry.explicitAliases, ...entry.aliasKeys].some((alias) => alias.startsWith(place))) return 55;\n if (entry.nameKey.startsWith(place)) return 50;\n const last = placeWords[placeWords.length - 1];\n const lead = placeWords.slice(0, -1);\n if (lead.every((word) => entry.words.has(word)) && [...entry.words].some((word) => word.startsWith(last))) {\n return 40;\n }\n return 0;\n}\n\n/**\n * The state or country named after the place picks between same-named cities - and\n * outweighs a city's usual airport: \"Portland, ME\" is Portland, Maine.\n */\nfunction hintScore(entry: Entry, query: Query): number {\n let score = 0;\n for (const hint of query.hints) {\n if (hint === entry.countryKey || COUNTRY_ALIASES[hint] === entry.airport.country) score += 20;\n else if (hint === entry.regionKey || hint === entry.regionCode) score += 30;\n }\n return score;\n}\n\nfunction ranked(text: string, prefixes: boolean, floor: number): Entry[] {\n const query = toQuery(text);\n if (!query) return [];\n const sizeBonus = prefixes ? SIZE_BONUS.typing : SIZE_BONUS.whole;\n const scored: Array<{ entry: Entry; score: number }> = [];\n for (const entry of airportIndex().entries) {\n const match = placeScore(entry, query, prefixes);\n if (match >= floor) {\n // The city itself begins with it: \"was\" is Washington before Baltimore/Washington.\n const cityLead = entry.cityKey.startsWith(query.place) ? 3 : 0;\n const primary = entry.primary ? 8 : 0;\n const score = match + hintScore(entry, query) + sizeBonus[entry.airport.size] + primary + cityLead;\n scored.push({ entry, score });\n }\n }\n return scored\n .sort(\n (a, b) =>\n b.score - a.score ||\n a.entry.airport.city.localeCompare(b.entry.airport.city) ||\n a.entry.airport.code.localeCompare(b.entry.airport.code),\n )\n .map((row) => row.entry);\n}\n\n/** The best match's city keeps its other airports next to it: Paris CDG, ORY, then Paramaribo. */\nfunction topCityFirst(entries: Entry[]): Entry[] {\n const [top] = entries;\n if (!top) return entries;\n const sameCity = (entry: Entry) => entry.cityKey === top.cityKey && entry.airport.country === top.airport.country;\n return [...entries.filter(sameCity), ...entries.filter((entry) => !sameCity(entry))];\n}\n\n/** Airports for what is typed so far, best first: \"hyd\" -> HYD, HDD, ... */\nexport function searchAirports(text: string, limit = 6): Airport[] {\n const trimmed = text.trim();\n if (trimmed.length < 2) return [];\n const picked = trimmed.match(/\\(([A-Za-z]{3})\\)\\s*$/);\n if (picked) {\n const airport = airportByCode(picked[1]);\n return airport ? [airport] : [];\n }\n return topCityFirst(ranked(trimmed, true, 40))\n .slice(0, limit)\n .map((entry) => entry.airport);\n}\n\n/**\n * The airport a whole place means: \"HYD\", \"Hyd\", \"Hyderabad\", \"Hyderabad, Telangana,\n * India\", \"Portland, ME, USA\", \"JFK Airport\". Not a prefix guess - \"Hyder\" is no airport.\n */\nexport function resolveAirport(text: string): Airport | undefined {\n const picked = text.match(/\\(([A-Za-z]{3})\\)/);\n const byCode = picked ? airportByCode(picked[1]) : undefined;\n return byCode ?? ranked(text, false, 70)[0]?.airport;\n}\n"],"names":[],"mappings":"uJA8CA,MAAM,YAAuC,GAAA;AAAA,EAC3C,MAAQ,EAAA,KAAA;AAAA,EACR,QAAU,EAAA,KAAA;AAAA,EACV,GAAK,EAAA,KAAA;AAAA,EACL,MAAQ,EAAA,KAAA;AAAA,EACR,MAAQ,EAAA,KAAA;AAAA,EACR,aAAe,EAAA,KAAA;AAAA,EACf,EAAI,EAAA,KAAA;AAAA,EACJ,GAAK,EAAA,KAAA;AAAA,EACL,EAAI,EAAA,KAAA;AAAA,EACJ,EAAI,EAAA,KAAA;AAAA,EACJ,EAAI,EAAA,KAAA;AAAA,EACJ,eAAiB,EAAA,KAAA;AAAA,EACjB,KAAO,EAAA;AACT,CAAA;AAGA,MAAM,k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ndex.ts"],"sourcesContent":["/**\n * Every airport with scheduled passenger service, for the flight From / To fields:\n * suggestions as the person types, and the airport a typed or picked place means.\n *\n * The flight connector takes IATA codes only. The field used to offer street-level\n * place suggestions and then look the text up in a table of ~70 cities, so \"Hyd\" and\n * \"Hyderabad, Telangana, India\" both ended in \"Could not find an airport\".\n */\nimport { AIRPORT_CODES } from './airportCodes';\nimport { AIRPORTS_SOURCE, AIRPORT_COUNTRIES_SOURCE, AIRPORT_REGIONS_SOURCE } from './airportIndexData';\n\nexport interface Airport {\n /** IATA code, e.g. HYD. */\n code: string;\n city: string;\n /** Airport name without a trailing \"Airport\", e.g. \"Rajiv Gandhi International\". */\n name: string;\n /** ISO country code. */\n country: string;\n countryName: string;\n regionName: string;\n size: 'L' | 'M' | 'S';\n}\n\ninterface Entry {\n airport: Airport;\n cityKey: string;\n nameKey: string;\n aliasKeys: string[];\n /** Words of the city, name and alternate names. */\n words: Set<string>;\n /** Words of the airport's own name, not its town's (\"heathrow\", \"gatwick\", \"kennedy\"). */\n nameWords: Set<string>;\n /** Words of its state and country, so \"Hyderabad India\" needs no comma. */\n placeWords: Set<string>;\n countryKey: string;\n regionKey: string;\n /** \"GA\" of US-GA - how \"Atlanta, GA, USA\" names the state. */\n regionCode: string;\n /** In the hand-kept city table as its city's main airport. */\n primary: boolean;\n /** Names that point straight at it (CITY_ALIASES: \"Bombay\", \"NYC\"). */\n explicitAliases: string[];\n /** That table's city (\"Dallas\" for DFW, \"Delhi\" for DEL), when it has the airport. */\n preferredCityKey: string;\n}\n\n/** Older, local and short names the source does not carry, or spreads over several airports. */\nconst CITY_ALIASES: Record<string, string> = {\n bombay: 'BOM',\n calcutta: 'CCU',\n goa: 'GOI',\n peking: 'PEK',\n saigon: 'SGN',\n 'ho chi minh': 'SGN',\n ny: 'JFK',\n nyc: 'JFK',\n sf: 'SFO',\n la: 'LAX',\n dc: 'DCA',\n 'washington dc': 'DCA',\n vegas: 'LAS',\n};\n\n/** In the hand-kept table, but not their city's main airport. */\nconst SECONDARY_AIRPORTS = new Set(['EWR', 'IAD', 'LGA', 'LGW', 'MDW', 'STN']);\n\n/** How place suggestions spell a country (\"Atlanta, GA, USA\"). */\nconst COUNTRY_ALIASES: Record<string, string> = {\n us: 'US',\n usa: 'US',\n america: 'US',\n uk: 'GB',\n england: 'GB',\n uae: 'AE',\n};\n\n/** Words that say \"airport\" without naming one (\"JFK Airport\", \"Heathrow intl\"). */\nconst FILLER = new Set(['airport', 'airports', 'international', 'intl', 'the']);\n\n/**\n * Airport-name words too common to name one airport: \"new\" is not Baghdad's\n * \"New Al Muthana\", \"santa\" no single field.\n */\nconst NAME_STOPWORDS = new Set([\n 'regional',\n 'municipal',\n 'county',\n 'national',\n 'airfield',\n 'airstrip',\n 'field',\n 'island',\n 'general',\n 'memorial',\n 'metropolitan',\n 'executive',\n 'north',\n 'south',\n 'santa',\n 'saint',\n 'airbase',\n]);\n\n/**\n * A small field that IS the town typed (\"Tok\", Alaska) is still a worse guess, while\n * typing, than the hub the letters begin (\"Tokyo\"); a whole name decides on the match.\n */\nconst SIZE_BONUS = {\n typing: { L: 35, M: 12, S: 0 },\n whole: { L: 6, M: 3, S: 0 },\n} as const;\n\n/** Lower-case ASCII words: accents folded, punctuation dropped. */\nexport function foldPlace(text: string): string {\n return text\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, ' ')\n .trim();\n}\n\nfunction table(source: string): Map<string, string> {\n const map = new Map<string, string>();\n for (const line of source.split('\\n')) {\n const cut = line.indexOf('|');\n if (cut > 0) map.set(line.slice(0, cut), line.slice(cut + 1));\n }\n return map;\n}\n\nlet index: { entries: Entry[]; byCode: Map<string, Entry> } | null = null;\n\nfunction airportIndex(): { entries: Entry[]; byCode: Map<string, Entry> } {\n if (index) return index;\n const countries = table(AIRPORT_COUNTRIES_SOURCE);\n const regions = table(AIRPORT_REGIONS_SOURCE);\n const entries: Entry[] = [];\n const byCode = new Map<string, Entry>();\n const rows = AIRPORTS_SOURCE.split('\\n')\n .map((line) => line.split('|'))\n .filter(([code, city]) => code?.length === 3 && Boolean(city));\n for (const [code, city, name, country, region, size, alternates] of rows) {\n const airport: Airport = {\n code,\n city,\n name,\n country,\n countryName: countries.get(country) ?? country,\n regionName: regions.get(region) ?? '',\n size: (size as Airport['size']) || 'S',\n };\n const aliasKeys = (alternates ? alternates.split(';') : []).map(foldPlace).filter(Boolean);\n const cityKey = foldPlace(city);\n const nameKey = foldPlace(name);\n const preferredLabel = AIRPORT_CODES[code];\n const entry: Entry = {\n airport,\n cityKey,\n nameKey,\n aliasKeys,\n words: new Set([cityKey, nameKey, ...aliasKeys].join(' ').split(' ').filter(Boolean)),\n nameWords: new Set(\n nameKey\n .split(' ')\n .filter(\n (word) =>\n word.length >= 5 &&\n !FILLER.has(word) &&\n !NAME_STOPWORDS.has(word) &&\n !cityKey.split(' ').includes(word),\n ),\n ),\n placeWords: new Set(\n [foldPlace(airport.countryName), foldPlace(airport.regionName)].join(' ').split(' ').filter(Boolean),\n ),\n countryKey: foldPlace(airport.countryName),\n regionKey: foldPlace(airport.regionName),\n regionCode: foldPlace(region.split('-')[1] ?? ''),\n primary: Boolean(preferredLabel) && !SECONDARY_AIRPORTS.has(code),\n explicitAliases: [],\n preferredCityKey: preferredLabel ? foldPlace(preferredLabel.split(',')[0] ?? '') : '',\n };\n entries.push(entry);\n byCode.set(code, entry);\n }\n for (const [alias, code] of Object.entries(CITY_ALIASES)) byCode.get(code)?.explicitAliases.push(alias);\n index = { entries, byCode };\n return index;\n}\n\nexport function airportByCode(code: string): Airport | undefined {\n return airportIndex().byCode.get(code.trim().toUpperCase())?.airport;\n}\n\n/** What a picked airport reads as in its field - and resolves back from: \"Hyderabad (HYD)\". */\nexport function airportLabel(airport: Pick<Airport, 'city' | 'code'>): string {\n return `${airport.city} (${airport.code})`;\n}\n\n/** \"Rajiv Gandhi International · Telangana, India\" */\nexport function airportDetail(airport: Airport): string {\n const where = [airport.regionName, airport.countryName].filter(Boolean).join(', ');\n return [airport.name !== airport.city ? airport.name : '', where].filter(Boolean).join(' · ');\n}\n\ninterface Query {\n /** The place itself: the first comma part, minus \"airport\" words. */\n place: string;\n placeWords: string[];\n /** The rest (\"GA, USA\", \"Telangana, India\"): which state or country is meant. */\n hints: string[];\n}\n\nfunction toQuery(text: string): Query | null {\n const [first, ...rest] = text.split(',');\n const placeWords = foldPlace(first ?? '')\n .split(' ')\n .filter((word) => word && !FILLER.has(word));\n if (!placeWords.length) return null;\n return { place: placeWords.join(' '), placeWords, hints: rest.map(foldPlace).filter(Boolean) };\n}\n\n/** How well an airport matches the place typed: 0 = not at all. */\nfunction placeScore(entry: Entry, query: Query, prefixes: boolean): number {\n const { place, placeWords } = query;\n if (entry.preferredCityKey === place) return 105;\n if (entry.cityKey === place) return 100;\n if (entry.explicitAliases.includes(place)) return 98;\n if (entry.aliasKeys.includes(place)) return 95;\n if (place.length === 3 && entry.airport.code === place.toUpperCase()) return 90;\n if (entry.nameKey === place) return 85;\n // One word names a city, a code or an airport (\"Heathrow\"); \"York\" is not New York.\n const named = (word: string) => entry.words.has(word) || entry.placeWords.has(word);\n if (\n placeWords.length === 1\n ? entry.nameWords.has(place)\n : placeWords.some((word) => entry.words.has(word)) && placeWords.every(named)\n ) {\n return 75;\n }\n if (!prefixes || place.length < 2) return 0;\n if (entry.cityKey.startsWith(place)) return 60;\n if ([...entry.explicitAliases, ...entry.aliasKeys].some((alias) => alias.startsWith(place))) return 55;\n if (entry.nameKey.startsWith(place)) return 50;\n const last = placeWords[placeWords.length - 1];\n const lead = placeWords.slice(0, -1);\n if (lead.every((word) => entry.words.has(word)) && [...entry.words].some((word) => word.startsWith(last))) {\n return 40;\n }\n return 0;\n}\n\n/**\n * The state or country named after the place picks between same-named cities - and\n * outweighs a city's usual airport: \"Portland, ME\" is Portland, Maine.\n */\nfunction hintScore(entry: Entry, query: Query): number {\n let score = 0;\n for (const hint of query.hints) {\n if (hint === entry.countryKey || COUNTRY_ALIASES[hint] === entry.airport.country) score += 20;\n else if (hint === entry.regionKey || hint === entry.regionCode) score += 30;\n }\n return score;\n}\n\nfunction ranked(text: string, prefixes: boolean, floor: number): Entry[] {\n const query = toQuery(text);\n if (!query) return [];\n const sizeBonus = prefixes ? SIZE_BONUS.typing : SIZE_BONUS.whole;\n const scored: Array<{ entry: Entry; score: number }> = [];\n for (const entry of airportIndex().entries) {\n const match = placeScore(entry, query, prefixes);\n if (match >= floor) {\n // The city itself begins with it: \"was\" is Washington before Baltimore/Washington.\n const cityLead = entry.cityKey.startsWith(query.place) ? 3 : 0;\n const primary = entry.primary ? 8 : 0;\n const score = match + hintScore(entry, query) + sizeBonus[entry.airport.size] + primary + cityLead;\n scored.push({ entry, score });\n }\n }\n return scored\n .sort(\n (a, b) =>\n b.score - a.score ||\n a.entry.airport.city.localeCompare(b.entry.airport.city) ||\n a.entry.airport.code.localeCompare(b.entry.airport.code),\n )\n .map((row) => row.entry);\n}\n\n/** The best match's city keeps its other airports next to it: Paris CDG, ORY, then Paramaribo. */\nfunction topCityFirst(entries: Entry[]): Entry[] {\n const [top] = entries;\n if (!top) return entries;\n const sameCity = (entry: Entry) => entry.cityKey === top.cityKey && entry.airport.country === top.airport.country;\n return [...entries.filter(sameCity), ...entries.filter((entry) => !sameCity(entry))];\n}\n\n/** Airports for what is typed so far, best first: \"hyd\" -> HYD, HDD, ... */\nexport function searchAirports(text: string, limit = 6): Airport[] {\n const trimmed = text.trim();\n if (trimmed.length < 2) return [];\n const picked = trimmed.match(/\\(([A-Za-z]{3})\\)\\s*$/);\n if (picked) {\n const airport = airportByCode(picked[1]);\n return airport ? [airport] : [];\n }\n return topCityFirst(ranked(trimmed, true, 40))\n .slice(0, limit)\n .map((entry) => entry.airport);\n}\n\n/**\n * The airport a whole place means: \"HYD\", \"Hyd\", \"Hyderabad\", \"Hyderabad, Telangana,\n * India\", \"Portland, ME, USA\", \"JFK Airport\". Not a prefix guess - \"Hyder\" is no airport.\n */\nexport function resolveAirport(text: string): Airport | undefined {\n const picked = text.match(/\\(([A-Za-z]{3})\\)/);\n const byCode = picked ? airportByCode(picked[1]) : undefined;\n return byCode ?? ranked(text, false, 70)[0]?.airport;\n}\n"],"names":[],"mappings":"kJA8CA,MAAM,YAAuC,GAAA;AAAA,EAC3C,MAAQ,EAAA,KAAA;AAAA,EACR,QAAU,EAAA,KAAA;AAAA,EACV,GAAK,EAAA,KAAA;AAAA,EACL,MAAQ,EAAA,KAAA;AAAA,EACR,MAAQ,EAAA,KAAA;AAAA,EACR,aAAe,EAAA,KAAA;AAAA,EACf,EAAI,EAAA,KAAA;AAAA,EACJ,GAAK,EAAA,KAAA;AAAA,EACL,EAAI,EAAA,KAAA;AAAA,EACJ,EAAI,EAAA,KAAA;AAAA,EACJ,EAAI,EAAA,KAAA;AAAA,EACJ,eAAiB,EAAA,KAAA;AAAA,EACjB,KAAO,EAAA;AACT,CAAA;AAGA,MAAM,kBAAA,mBAAyB,IAAA,GAAA,CAAI,CAAC,KAAA,EAAO,OAAO,KAAO,EAAA,KAAA,EAAO,KAAO,EAAA,KAAK,CAAC,CAAA;AAG7E,MAAM,eAA0C,GAAA;AAAA,EAC9C,EAAI,EAAA,IAAA;AAAA,EACJ,GAAK,EAAA,IAAA;AAAA,EACL,OAAS,EAAA,IAAA;AAAA,EACT,EAAI,EAAA,IAAA;AAAA,EACJ,OAAS,EAAA,IAAA;AAAA,EACT,GAAK,EAAA;AACP,CAAA;AAGA,MAAM,MAAA,uBAAa,GAAI,CAAA,CAAC,WAAW,UAAY,EAAA,eAAA,EAAiB,MAAQ,EAAA,KAAK,CAAC,CAAA;AAM9E,MAAM,cAAA,uBAAqB,GAAI,CAAA,CAAC,YAAY,WAAa,EAAA,QAAA,EAAU,YAAY,UAAY,EAAA,UAAA,EAAY,SAAS,QAAU,EAAA,SAAA,EAAW,YAAY,cAAgB,EAAA,WAAA,EAAa,SAAS,OAAS,EAAA,OAAA,EAAS,OAAS,EAAA,SAAS,CAAC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