@adminide-stack/yantra-mobile 12.0.160 → 12.0.161-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.
Files changed (53) hide show
  1. package/lib/components/GatewayConnector/GatewayConnector.js +1 -1
  2. package/lib/components/GatewayConnector/GatewayConnector.js.map +1 -1
  3. package/lib/components/NavigationHeader/HeaderSkillsButton.js +1 -1
  4. package/lib/components/NavigationHeader/HeaderSkillsButton.js.map +1 -1
  5. package/lib/components/NavigationHeader/HeaderTasksButton.js +1 -1
  6. package/lib/components/NavigationHeader/HeaderTasksButton.js.map +1 -1
  7. package/lib/contexts/CdecliConnectionContext.js +2 -11
  8. package/lib/contexts/CdecliConnectionContext.js.map +1 -1
  9. package/lib/contexts/ChatLiveStreamContext.js +1 -1
  10. package/lib/contexts/ChatLiveStreamContext.js.map +1 -1
  11. package/lib/contexts/cdecliConnection.js +9 -0
  12. package/lib/contexts/cdecliConnection.js.map +1 -0
  13. package/lib/features/attachments/displayUserMessageText.js +3 -3
  14. package/lib/features/attachments/displayUserMessageText.js.map +1 -1
  15. package/lib/features/audio-input/AudioRecorderPanel.js +1 -1
  16. package/lib/features/audio-input/AudioRecorderPanel.js.map +1 -1
  17. package/lib/features/chat/ChatWidgetCard.js +3 -10
  18. package/lib/features/chat/ChatWidgetCard.js.map +1 -1
  19. package/lib/features/chat/TemplatesChatCards.js +1 -1
  20. package/lib/features/chat/TemplatesChatCards.js.map +1 -1
  21. package/lib/features/chat/chatWidgets.js +13 -52
  22. package/lib/features/chat/chatWidgets.js.map +1 -1
  23. package/lib/features/chat/hostTranscriptProtocol.js +82 -0
  24. package/lib/features/chat/hostTranscriptProtocol.js.map +1 -0
  25. package/lib/features/chat/transcriptProtocol.js +11 -0
  26. package/lib/features/chat/transcriptProtocol.js.map +1 -0
  27. package/lib/features/chat/useComputerAction.js +1 -1
  28. package/lib/features/chat/useComputerAction.js.map +1 -1
  29. package/lib/features/credits/FreeCreditsCard.js +94 -0
  30. package/lib/features/credits/FreeCreditsCard.js.map +1 -0
  31. package/lib/features/credits/freeCredits.js +92 -0
  32. package/lib/features/credits/freeCredits.js.map +1 -0
  33. package/lib/features/credits/useFreeCredits.js +47 -0
  34. package/lib/features/credits/useFreeCredits.js.map +1 -0
  35. package/lib/index.js +1 -1
  36. package/lib/index.js.map +1 -1
  37. package/lib/module.js +2 -1
  38. package/lib/module.js.map +1 -1
  39. package/lib/screens/Chat/index.js +30 -17
  40. package/lib/screens/Chat/index.js.map +1 -1
  41. package/lib/screens/ExpensesNative/useExpensesHostChat.js +1 -1
  42. package/lib/screens/Home/HomeScreen.js +18 -4
  43. package/lib/screens/Home/HomeScreen.js.map +1 -1
  44. package/lib/screens/InboxNative/useInboxHostChat.js +1 -1
  45. package/lib/screens/JobSearchNative/useJobSearchHostChat.js +1 -1
  46. package/lib/screens/LocalServicesNative/useLocalServicesHostChat.js +1 -1
  47. package/lib/screens/MoviesNative/useMoviesHostChat.js +1 -1
  48. package/lib/screens/ResumeNative/useResumeHostChat.js +1 -1
  49. package/lib/screens/ShoppingNative/useShoppingHostChat.js +1 -1
  50. package/lib/screens/StudyNative/useStudyHostChat.js +1 -1
  51. package/lib/screens/TravelNative/useTravelHostChat.js +1 -1
  52. package/lib/screens/WebBuilderNative/useWebBuilderHost.js +1 -1
  53. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"TemplatesChatCards.js","sources":["../../../src/features/chat/TemplatesChatCards.tsx"],"sourcesContent":["/**\n * The phone's cards for templates in the chat (common TEMPLATES_CHAT_PROTOCOL), the twins of the\n * web's TemplatesMessage and CanvasDesignMessage:\n *\n * - `templates`: one row that opens the Templates surface on that category in the app's surface\n * screen (signed in with this device). Where it opens is templatesRowTarget: the reply's own\n * Templates link when it has one, so a pick there can come back into this chat, else the\n * surface of this app's environment, to browse.\n * - `canvas-design`: the pages of a design the agent made from a template, side by side.\n */\nimport React, { memo, useCallback, useMemo, useState } from 'react';\nimport { Image, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';\nimport { MaterialCommunityIcons } from '@expo/vector-icons';\nimport { useNavigation, type NavigationProp, type ParamListBase } from '@react-navigation/native';\nimport {\n canvasDesignKindLabel,\n isTemplatesSurfaceUrl,\n templatesOpeningTitle,\n templatesSurfaceLinkWithOpening,\n templatesSurfaceUrl,\n type CanvasDesignAttachment,\n type TemplatesOpening,\n} from 'common';\nimport { config } from '../../config/env-config';\nimport { useChatLinkOpener } from '../links/chatLinkOpener';\nimport { openDesignNative, openSurfaceInApp } from '../links/openInApp';\nimport { designOpeningFromCard } from '../design/surface/designLinks';\n\nconst ACCENT = '#2563eb';\n/** The Templates surface's slug: `templates-surface.<env>` through SURFACE_URL_TEMPLATE. */\nexport const TEMPLATES_SURFACE_SLUG = 'templates';\n\n/** The Templates surface page for an opening, or null when the template has no `{slug}` (it would open another surface). */\nexport function templatesSurfaceLink(\n surfaceUrlTemplate: string | undefined,\n opening: TemplatesOpening | null | undefined,\n): string | null {\n const template = surfaceUrlTemplate?.trim();\n if (!template || !template.includes('{slug}')) return null;\n return templatesSurfaceUrl(template.replace(/\\{slug\\}/g, TEMPLATES_SURFACE_SLUG), opening);\n}\n\n/**\n * Where a templates row opens.\n *\n * - `reply`: the reply's own Templates link - the one the messenger gateway ended the reply with\n * (chatWidgets takes it out of the text for the row), carrying the reply's snapshot (`ys`) - with\n * the row's category and search added. It opens as that link would have from the text: the\n * gateway says it is a surface page and the app opens it in its surface screen, signed in. The\n * Templates page reads the snapshot and, when this chat may take a pick, offers \"Make it here in\n * the chat\", which sends the pick back here as the person's next turn.\n * - `browse`: a reply with no such link (older replies, or the agent asked for no surface). The\n * Templates surface of this app's own environment, on the category: browsing and \"Edit on the\n * web\" work, but with no snapshot the page has no chat to send a pick to.\n *\n * Null when neither exists (no surface template configured).\n */\nexport type TemplatesRowTarget = { kind: 'reply' | 'browse'; url: string };\n\nexport function templatesRowTarget(\n surfaceUrlTemplate: string | undefined,\n opening: TemplatesOpening | null | undefined,\n replyLink?: string | null,\n): TemplatesRowTarget | null {\n if (replyLink && isTemplatesSurfaceUrl(replyLink)) {\n return { kind: 'reply', url: templatesSurfaceLinkWithOpening(replyLink.trim(), opening) };\n }\n const url = templatesSurfaceLink(surfaceUrlTemplate, opening);\n return url ? { kind: 'browse', url } : null;\n}\n\nfunction palette(isDark: boolean) {\n return {\n card: isDark ? '#111827' : '#ffffff',\n border: isDark ? '#1f2937' : '#e5e7eb',\n title: isDark ? '#f1f5f9' : '#111827',\n muted: isDark ? '#94a3b8' : '#6b7280',\n iconBg: isDark ? '#1e293b' : '#eff6ff',\n icon: isDark ? '#60a5fa' : ACCENT,\n table: isDark ? '#0b1220' : '#f9fafb',\n pressed: isDark ? '#1f2937' : '#f3f4f6',\n };\n}\n\nconst styles = StyleSheet.create({\n card: { width: '100%', borderWidth: 1, borderRadius: 16, marginTop: 4, marginBottom: 8, overflow: 'hidden' },\n row: { flexDirection: 'row', alignItems: 'center', gap: 12, padding: 14 },\n icon: { width: 40, height: 40, borderRadius: 10, alignItems: 'center', justifyContent: 'center' },\n body: { flex: 1, minWidth: 0 },\n title: { fontSize: 15, fontWeight: '700', lineHeight: 20 },\n subtitle: { fontSize: 13, lineHeight: 18, marginTop: 2 },\n header: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 14, paddingVertical: 10 },\n badge: { borderRadius: 6, paddingHorizontal: 6, paddingVertical: 2 },\n badgeText: { fontSize: 11, fontWeight: '600' },\n pages: { paddingHorizontal: 12, paddingVertical: 12, gap: 10 },\n page: { width: 200, height: 150, borderRadius: 8 },\n count: { fontSize: 11 },\n openRow: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 6,\n paddingVertical: 12,\n borderTopWidth: StyleSheet.hairlineWidth,\n },\n openText: { fontSize: 14, fontWeight: '600' },\n});\n\n/** A `templates` widget: one row that opens the Templates surface on its category. */\nexport const TemplatesWidgetCard = memo(function TemplatesWidgetCard({\n opening,\n link,\n isDark,\n}: {\n opening: TemplatesOpening;\n /** The reply's Templates surface link (with its snapshot), when the reply carried one. */\n link?: string;\n isDark: boolean;\n}) {\n const navigation = useNavigation<NavigationProp<ParamListBase>>();\n const openChatLink = useChatLinkOpener();\n const colors = palette(isDark);\n const target = useMemo(() => templatesRowTarget(config.SURFACE_URL_TEMPLATE, opening, link), [opening, link]);\n const title = templatesOpeningTitle(opening);\n const design = useMemo(() => designOpeningFromCard(opening), [opening]);\n const open = useCallback(() => {\n // Design templates have a native gallery: the card opens it, not the web Templates page.\n if (design) {\n openDesignNative(navigation, design);\n return;\n }\n if (!target) return;\n // The reply's link opens the way a tapped link does (the gateway names its surface);\n // the browse page is this app's own surface, from its own config.\n if (target.kind === 'reply') openChatLink(target.url);\n else openSurfaceInApp(navigation, { surface: TEMPLATES_SURFACE_SLUG, url: target.url });\n }, [navigation, openChatLink, target, design]);\n if (!target && !design) return null;\n return (\n <Pressable\n onPress={open}\n accessibilityRole=\"button\"\n accessibilityLabel={`Browse ${title.charAt(0).toLowerCase()}${title.slice(1)}`}\n style={({ pressed }) => [\n styles.card,\n { borderColor: colors.border, backgroundColor: pressed ? colors.pressed : colors.card },\n ]}\n >\n <View style={styles.row}>\n <View style={[styles.icon, { backgroundColor: colors.iconBg }]}>\n <MaterialCommunityIcons name=\"view-grid-outline\" size={22} color={colors.icon} />\n </View>\n <View style={styles.body}>\n <Text style={[styles.title, { color: colors.title }]} numberOfLines={1}>\n Browse {title.charAt(0).toLowerCase() + title.slice(1)}\n </Text>\n <Text style={[styles.subtitle, { color: colors.muted }]} numberOfLines={1}>\n {opening.query ? `Matching “${opening.query}”` : 'Pick one to start from it'}\n </Text>\n </View>\n <MaterialCommunityIcons name=\"chevron-right\" size={20} color={colors.muted} />\n </View>\n </Pressable>\n );\n});\n\n/** One page; a render that will not load leaves a quiet tile, never a broken image. */\nfunction PagePreview({ uri, label, isDark }: { uri: string; label: string; isDark: boolean }) {\n const [failed, setFailed] = useState(false);\n const colors = palette(isDark);\n if (failed) {\n return (\n <View\n accessible\n accessibilityLabel={`${label} (preview unavailable)`}\n style={[\n styles.page,\n { backgroundColor: colors.border, alignItems: 'center', justifyContent: 'center' },\n ]}\n >\n <MaterialCommunityIcons name=\"image-off-outline\" size={22} color={colors.muted} />\n </View>\n );\n }\n return (\n <Image\n source={{ uri }}\n accessibilityLabel={label}\n resizeMode=\"contain\"\n onError={() => setFailed(true)}\n style={styles.page}\n />\n );\n}\n\n/** A `canvas-design` widget: what was made and its pages, side by side. */\nexport const CanvasDesignWidgetCard = memo(function CanvasDesignWidgetCard({\n design,\n isDark,\n}: {\n design: CanvasDesignAttachment;\n isDark: boolean;\n}) {\n const navigation = useNavigation<NavigationProp<ParamListBase>>();\n const colors = palette(isDark);\n const kind = canvasDesignKindLabel(design);\n const title = design.title ?? `Your ${kind.toLowerCase()}`;\n const pages = design.previews.length;\n const open = useCallback(\n () => openDesignNative(navigation, { templates: false, studio: { artifactId: design.artifactId } }),\n [navigation, design.artifactId],\n );\n return (\n <View\n accessibilityLabel={`${kind}: ${title}`}\n style={[styles.card, { borderColor: colors.border, backgroundColor: colors.card }]}\n >\n <View style={styles.header}>\n <View style={[styles.badge, { backgroundColor: colors.iconBg }]}>\n <Text style={[styles.badgeText, { color: colors.icon }]}>{kind}</Text>\n </View>\n <Text style={[styles.title, styles.body, { color: colors.title }]} numberOfLines={1}>\n {title}\n </Text>\n {pages > 1 ? <Text style={[styles.count, { color: colors.muted }]}>{pages} pages</Text> : null}\n </View>\n {pages > 0 ? (\n <ScrollView\n horizontal\n showsHorizontalScrollIndicator={false}\n contentContainerStyle={styles.pages}\n style={{ backgroundColor: colors.table }}\n >\n {design.previews.map((uri, i) => (\n <PagePreview\n key={`${i}:${uri}`}\n uri={uri}\n label={pages > 1 ? `${title}, page ${i + 1} of ${pages}` : title}\n isDark={isDark}\n />\n ))}\n </ScrollView>\n ) : null}\n <Pressable\n onPress={open}\n accessibilityRole=\"button\"\n accessibilityLabel={`Open ${title} in Design`}\n style={({ pressed }) => [\n styles.openRow,\n { borderColor: colors.border },\n pressed && { backgroundColor: colors.pressed },\n ]}\n >\n <MaterialCommunityIcons name=\"pencil-outline\" size={16} color={ACCENT} />\n <Text style={[styles.openText, { color: ACCENT }]}>Open in Design</Text>\n </Pressable>\n </View>\n );\n});\n"],"names":["TemplatesWidgetCard","CanvasDesignWidgetCard"],"mappings":"wpBAmBA,MAAM,MAAS,GAAA,SAAA;AAER,MAAM,sBAAyB,GAAA;AAGtB,SAAA,oBAAA,CAAqB,oBAAwC,OAA6D,EAAA;AACxI,EAAA,MAAM,WAAW,kBAAoB,IAAA,IAAA,GAAA,MAAA,GAAA,kBAAA,CAAA,IAAA,EAAA;AACrC,EAAA,IAAI,CAAC,QAAY,IAAA,CAAC,SAAS,QAAS,CAAA,QAAQ,GAAU,OAAA,IAAA;AACtD,EAAA,OAAO,oBAAoB,QAAS,CAAA,OAAA,CAAQ,WAAa,EAAA,sBAAsB,GAAG,OAAO,CAAA;AAC3F;AAqBgB,SAAA,kBAAA,CAAmB,kBAAwC,EAAA,OAAA,EAA8C,SAAsD,EAAA;AAC7K,EAAI,IAAA,SAAA,IAAa,qBAAsB,CAAA,SAAS,CAAG,EAAA;AACjD,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,OAAA;AAAA,MACN,GAAK,EAAA,+BAAA,CAAgC,SAAU,CAAA,IAAA,IAAQ,OAAO;AAAA,KAChE;AAAA;AAEF,EAAM,MAAA,GAAA,GAAM,oBAAqB,CAAA,kBAAA,EAAoB,OAAO,CAAA;AAC5D,EAAA,OAAO,GAAM,GAAA;AAAA,IACX,IAAM,EAAA,QAAA;AAAA,IACN;AAAA,GACE,GAAA,IAAA;AACN;AACA,SAAS,QAAQ,MAAiB,EAAA;AAChC,EAAO,OAAA;AAAA,IACL,IAAA,EAAM,SAAS,SAAY,GAAA,SAAA;AAAA,IAC3B,MAAA,EAAQ,SAAS,SAAY,GAAA,SAAA;AAAA,IAC7B,KAAA,EAAO,SAA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,IAAA,EAAA,EAAK,KAAO,EAAA,CAAC,OAAO,QAAU,EAAA;AAAA,QACvC,KAAO,EAAA;AAAA,OACR,GAAG,QAAc,EAAA,gBAAA,EAAA;AAAA,KACZ,EAAA;AAAA,GACJ,EAAA,CAAA;AACR,CAAC"}
1
+ {"version":3,"file":"TemplatesChatCards.js","sources":["../../../src/features/chat/TemplatesChatCards.tsx"],"sourcesContent":["/**\n * The phone's cards for templates in the chat (common TEMPLATES_CHAT_PROTOCOL), the twins of the\n * web's TemplatesMessage and CanvasDesignMessage:\n *\n * - `templates`: one row that opens the Templates surface on that category in the app's surface\n * screen (signed in with this device). Where it opens is templatesRowTarget: the reply's own\n * Templates link when it has one, so a pick there can come back into this chat, else the\n * surface of this app's environment, to browse.\n * - `canvas-design`: the pages of a design the agent made from a template, side by side.\n *\n * Host-only: this module imports `common` and the in-app browser, which the federated surface\n * remotes must not bundle. A remote's transcript reaches these cards through transcriptProtocol.\n */\nimport React, { memo, useCallback, useMemo, useState } from 'react';\nimport { Image, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';\nimport { MaterialCommunityIcons } from '@expo/vector-icons';\nimport { useNavigation, type NavigationProp, type ParamListBase } from '@react-navigation/native';\nimport {\n canvasDesignKindLabel,\n isTemplatesSurfaceUrl,\n templatesOpeningTitle,\n templatesSurfaceLinkWithOpening,\n templatesSurfaceUrl,\n type CanvasDesignAttachment,\n type TemplatesOpening,\n} from 'common';\nimport { config } from '../../config/env-config';\nimport { useChatLinkOpener } from '../links/chatLinkOpener';\nimport { openDesignNative, openSurfaceInApp } from '../links/openInApp';\nimport { designOpeningFromCard } from '../design/surface/designLinks';\n\nconst ACCENT = '#2563eb';\n/** The Templates surface's slug: `templates-surface.<env>` through SURFACE_URL_TEMPLATE. */\nexport const TEMPLATES_SURFACE_SLUG = 'templates';\n\n/** The Templates surface page for an opening, or null when the template has no `{slug}` (it would open another surface). */\nexport function templatesSurfaceLink(\n surfaceUrlTemplate: string | undefined,\n opening: TemplatesOpening | null | undefined,\n): string | null {\n const template = surfaceUrlTemplate?.trim();\n if (!template || !template.includes('{slug}')) return null;\n return templatesSurfaceUrl(template.replace(/\\{slug\\}/g, TEMPLATES_SURFACE_SLUG), opening);\n}\n\n/**\n * Where a templates row opens.\n *\n * - `reply`: the reply's own Templates link - the one the messenger gateway ended the reply with\n * (chatWidgets takes it out of the text for the row), carrying the reply's snapshot (`ys`) - with\n * the row's category and search added. It opens as that link would have from the text: the\n * gateway says it is a surface page and the app opens it in its surface screen, signed in. The\n * Templates page reads the snapshot and, when this chat may take a pick, offers \"Make it here in\n * the chat\", which sends the pick back here as the person's next turn.\n * - `browse`: a reply with no such link (older replies, or the agent asked for no surface). The\n * Templates surface of this app's own environment, on the category: browsing and \"Edit on the\n * web\" work, but with no snapshot the page has no chat to send a pick to.\n *\n * Null when neither exists (no surface template configured).\n */\nexport type TemplatesRowTarget = { kind: 'reply' | 'browse'; url: string };\n\nexport function templatesRowTarget(\n surfaceUrlTemplate: string | undefined,\n opening: TemplatesOpening | null | undefined,\n replyLink?: string | null,\n): TemplatesRowTarget | null {\n if (replyLink && isTemplatesSurfaceUrl(replyLink)) {\n return { kind: 'reply', url: templatesSurfaceLinkWithOpening(replyLink.trim(), opening) };\n }\n const url = templatesSurfaceLink(surfaceUrlTemplate, opening);\n return url ? { kind: 'browse', url } : null;\n}\n\nfunction palette(isDark: boolean) {\n return {\n card: isDark ? '#111827' : '#ffffff',\n border: isDark ? '#1f2937' : '#e5e7eb',\n title: isDark ? '#f1f5f9' : '#111827',\n muted: isDark ? '#94a3b8' : '#6b7280',\n iconBg: isDark ? '#1e293b' : '#eff6ff',\n icon: isDark ? '#60a5fa' : ACCENT,\n table: isDark ? '#0b1220' : '#f9fafb',\n pressed: isDark ? '#1f2937' : '#f3f4f6',\n };\n}\n\nconst styles = StyleSheet.create({\n card: { width: '100%', borderWidth: 1, borderRadius: 16, marginTop: 4, marginBottom: 8, overflow: 'hidden' },\n row: { flexDirection: 'row', alignItems: 'center', gap: 12, padding: 14 },\n icon: { width: 40, height: 40, borderRadius: 10, alignItems: 'center', justifyContent: 'center' },\n body: { flex: 1, minWidth: 0 },\n title: { fontSize: 15, fontWeight: '700', lineHeight: 20 },\n subtitle: { fontSize: 13, lineHeight: 18, marginTop: 2 },\n header: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 14, paddingVertical: 10 },\n badge: { borderRadius: 6, paddingHorizontal: 6, paddingVertical: 2 },\n badgeText: { fontSize: 11, fontWeight: '600' },\n pages: { paddingHorizontal: 12, paddingVertical: 12, gap: 10 },\n page: { width: 200, height: 150, borderRadius: 8 },\n count: { fontSize: 11 },\n openRow: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 6,\n paddingVertical: 12,\n borderTopWidth: StyleSheet.hairlineWidth,\n },\n openText: { fontSize: 14, fontWeight: '600' },\n});\n\n/** A `templates` widget: one row that opens the Templates surface on its category. */\nexport const TemplatesWidgetCard = memo(function TemplatesWidgetCard({\n opening,\n link,\n isDark,\n}: {\n opening: TemplatesOpening;\n /** The reply's Templates surface link (with its snapshot), when the reply carried one. */\n link?: string;\n isDark: boolean;\n}) {\n const navigation = useNavigation<NavigationProp<ParamListBase>>();\n const openChatLink = useChatLinkOpener();\n const colors = palette(isDark);\n const target = useMemo(() => templatesRowTarget(config.SURFACE_URL_TEMPLATE, opening, link), [opening, link]);\n const title = templatesOpeningTitle(opening);\n const design = useMemo(() => designOpeningFromCard(opening), [opening]);\n const open = useCallback(() => {\n // Design templates have a native gallery: the card opens it, not the web Templates page.\n if (design) {\n openDesignNative(navigation, design);\n return;\n }\n if (!target) return;\n // The reply's link opens the way a tapped link does (the gateway names its surface);\n // the browse page is this app's own surface, from its own config.\n if (target.kind === 'reply') openChatLink(target.url);\n else openSurfaceInApp(navigation, { surface: TEMPLATES_SURFACE_SLUG, url: target.url });\n }, [navigation, openChatLink, target, design]);\n if (!target && !design) return null;\n return (\n <Pressable\n onPress={open}\n accessibilityRole=\"button\"\n accessibilityLabel={`Browse ${title.charAt(0).toLowerCase()}${title.slice(1)}`}\n style={({ pressed }) => [\n styles.card,\n { borderColor: colors.border, backgroundColor: pressed ? colors.pressed : colors.card },\n ]}\n >\n <View style={styles.row}>\n <View style={[styles.icon, { backgroundColor: colors.iconBg }]}>\n <MaterialCommunityIcons name=\"view-grid-outline\" size={22} color={colors.icon} />\n </View>\n <View style={styles.body}>\n <Text style={[styles.title, { color: colors.title }]} numberOfLines={1}>\n Browse {title.charAt(0).toLowerCase() + title.slice(1)}\n </Text>\n <Text style={[styles.subtitle, { color: colors.muted }]} numberOfLines={1}>\n {opening.query ? `Matching “${opening.query}”` : 'Pick one to start from it'}\n </Text>\n </View>\n <MaterialCommunityIcons name=\"chevron-right\" size={20} color={colors.muted} />\n </View>\n </Pressable>\n );\n});\n\n/** One page; a render that will not load leaves a quiet tile, never a broken image. */\nfunction PagePreview({ uri, label, isDark }: { uri: string; label: string; isDark: boolean }) {\n const [failed, setFailed] = useState(false);\n const colors = palette(isDark);\n if (failed) {\n return (\n <View\n accessible\n accessibilityLabel={`${label} (preview unavailable)`}\n style={[\n styles.page,\n { backgroundColor: colors.border, alignItems: 'center', justifyContent: 'center' },\n ]}\n >\n <MaterialCommunityIcons name=\"image-off-outline\" size={22} color={colors.muted} />\n </View>\n );\n }\n return (\n <Image\n source={{ uri }}\n accessibilityLabel={label}\n resizeMode=\"contain\"\n onError={() => setFailed(true)}\n style={styles.page}\n />\n );\n}\n\n/** A `canvas-design` widget: what was made and its pages, side by side. */\nexport const CanvasDesignWidgetCard = memo(function CanvasDesignWidgetCard({\n design,\n isDark,\n}: {\n design: CanvasDesignAttachment;\n isDark: boolean;\n}) {\n const navigation = useNavigation<NavigationProp<ParamListBase>>();\n const colors = palette(isDark);\n const kind = canvasDesignKindLabel(design);\n const title = design.title ?? `Your ${kind.toLowerCase()}`;\n const pages = design.previews.length;\n const open = useCallback(\n () => openDesignNative(navigation, { templates: false, studio: { artifactId: design.artifactId } }),\n [navigation, design.artifactId],\n );\n return (\n <View\n accessibilityLabel={`${kind}: ${title}`}\n style={[styles.card, { borderColor: colors.border, backgroundColor: colors.card }]}\n >\n <View style={styles.header}>\n <View style={[styles.badge, { backgroundColor: colors.iconBg }]}>\n <Text style={[styles.badgeText, { color: colors.icon }]}>{kind}</Text>\n </View>\n <Text style={[styles.title, styles.body, { color: colors.title }]} numberOfLines={1}>\n {title}\n </Text>\n {pages > 1 ? <Text style={[styles.count, { color: colors.muted }]}>{pages} pages</Text> : null}\n </View>\n {pages > 0 ? (\n <ScrollView\n horizontal\n showsHorizontalScrollIndicator={false}\n contentContainerStyle={styles.pages}\n style={{ backgroundColor: colors.table }}\n >\n {design.previews.map((uri, i) => (\n <PagePreview\n key={`${i}:${uri}`}\n uri={uri}\n label={pages > 1 ? `${title}, page ${i + 1} of ${pages}` : title}\n isDark={isDark}\n />\n ))}\n </ScrollView>\n ) : null}\n <Pressable\n onPress={open}\n accessibilityRole=\"button\"\n accessibilityLabel={`Open ${title} in Design`}\n style={({ pressed }) => [\n styles.openRow,\n { borderColor: colors.border },\n pressed && { backgroundColor: colors.pressed },\n ]}\n >\n <MaterialCommunityIcons name=\"pencil-outline\" size={16} color={ACCENT} />\n <Text style={[styles.openText, { color: ACCENT }]}>Open in Design</Text>\n </Pressable>\n </View>\n );\n});\n"],"names":["TemplatesWidgetCard","CanvasDesignWidgetCard"],"mappings":"wpBAsBA,MAAM,MAAS,GAAA,SAAA;AAER,MAAM,sBAAyB,GAAA;AAGtB,SAAA,oBAAA,CAAqB,oBAAwC,OAA6D,EAAA;AACxI,EAAA,MAAM,WAAW,kBAAoB,IAAA,IAAA,GAAA,MAAA,GAAA,kBAAA,CAAA,IAAA,EAAA;AACrC,EAAA,IAAI,CAAC,QAAY,IAAA,CAAC,SAAS,QAAS,CAAA,QAAQ,GAAU,OAAA,IAAA;AACtD,EAAA,OAAO,oBAAoB,QAAS,CAAA,OAAA,CAAQ,WAAa,EAAA,sBAAsB,GAAG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,KAAK,CAAA,CAAA,GAAK,KAAO,EAAA,MAAA,EAAA,EAA3F,CAAG,EAAA,CAAC,CAAI,CAAA,EAAA,GAAG,CAAgG,CAAA,CAAE,GACpK,CAAgB,GAAA,IAAA;AAAA,oBACpB,IAAA,CAAC,SAAU,EAAA,EAAA,OAAA,EAAS,IAAM,EAAA,iBAAA,EAAkB,QAAS,EAAA,kBAAA,EAAoB,CAAQ,KAAA,EAAA,KAAK,CAAc,UAAA,CAAA,EAAA,KAAA,EAAO,CAAC;AAAA,MAClH;AAAA,KACF,KAAM,CAAC,MAAA,CAAO,OAAS,EAAA;AAAA,MACrB,aAAa,MAAO,CAAA;AAAA,OACnB,OAAW,IAAA;AAAA,MACZ,iBAAiB,MAAO,CAAA;AAAA,KACzB,CACW,EAAA,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,0BAAuB,IAAK,EAAA,gBAAA,EAAiB,IAAM,EAAA,EAAA,EAAI,OAAO,MAAQ,EAAA,CAAA;AAAA,sBACtE,GAAA,CAAA,IAAA,EAAA,EAAK,KAAO,EAAA,CAAC,OAAO,QAAU,EAAA;AAAA,QACvC,KAAO,EAAA;AAAA,OACR,GAAG,QAAc,EAAA,gBAAA,EAAA;AAAA,KACZ,EAAA;AAAA,GACJ,EAAA,CAAA;AACR,CAAC"}
@@ -1,27 +1,8 @@
1
- import {TEMPLATES_WIDGET,splitTemplatesSurfaceLink,parseTemplatesOpening,CANVAS_DESIGN_WIDGET,canvasDesignFromWidget}from'common';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 WIDGET_FENCE = /```(?:yantra:widget|json)[^\S\n]*\n?([\s\S]*?)```/gi;
1
+ import {transcriptProtocol}from'./transcriptProtocol.js';const WIDGET_FENCE = /```(?:yantra:widget|json)[^\S\n]*\n?([\s\S]*?)```/gi;
21
2
  const OPEN_WIDGET_TAIL = /```(?:yantra:widget|json)[^\S\n]*\n?\s*\{\s*"propsComponent"[\s\S]*$/i;
22
3
  const OPEN_YANTRA_WIDGET_TAIL = /```yantra:widget[\s\S]*$/i;
23
4
  function toWidget(body) {
24
- var _a, _b, _c, _d, _e, _f, _g;
5
+ var _a, _b, _c, _d;
25
6
  let parsed;
26
7
  try {
27
8
  parsed = JSON.parse(body.trim());
@@ -31,22 +12,9 @@ function toWidget(body) {
31
12
  if (!parsed || typeof parsed !== "object") return null;
32
13
  const obj = parsed;
33
14
  if (typeof obj.propsComponent !== "string" || !obj.propsComponent) return null;
34
- if (obj.propsComponent === TEMPLATES_WIDGET) {
35
- const contents = (_a = obj.propsConfiguration) == null ? void 0 : _a.contents;
36
- const opening = parseTemplatesOpening((_d = (_c = (_b = contents == null ? void 0 : contents.attachment) != null ? _b : obj.attachment) != null ? _c : contents) != null ? _d : {});
37
- return opening ? {
38
- component: TEMPLATES_WIDGET,
39
- attachment: __spreadValues({}, opening)
40
- } : null;
41
- }
42
- if (obj.propsComponent === CANVAS_DESIGN_WIDGET) {
43
- const design = canvasDesignFromWidget(obj);
44
- return design ? {
45
- component: CANVAS_DESIGN_WIDGET,
46
- attachment: __spreadValues({}, design)
47
- } : null;
48
- }
49
- const attachment = (_g = (_f = (_e = obj.propsConfiguration) == null ? void 0 : _e.contents) == null ? void 0 : _f.attachment) != null ? _g : obj.attachment;
15
+ const owned = (_a = transcriptProtocol()) == null ? void 0 : _a.readWidget(obj);
16
+ if (owned !== void 0) return owned;
17
+ const attachment = (_d = (_c = (_b = obj.propsConfiguration) == null ? void 0 : _b.contents) == null ? void 0 : _c.attachment) != null ? _d : obj.attachment;
50
18
  if (!attachment || typeof attachment !== "object") return null;
51
19
  return {
52
20
  component: obj.propsComponent,
@@ -54,6 +22,7 @@ function toWidget(body) {
54
22
  };
55
23
  }
56
24
  function splitChatWidgets(content, streaming = false) {
25
+ var _a, _b;
57
26
  const widgets = [];
58
27
  let text = content.replace(WIDGET_FENCE, (match, body) => {
59
28
  const widget = toWidget(body);
@@ -64,21 +33,13 @@ function splitChatWidgets(content, streaming = false) {
64
33
  if (streaming) {
65
34
  text = text.replace(OPEN_WIDGET_TAIL, "").replace(OPEN_YANTRA_WIDGET_TAIL, "");
66
35
  }
67
- const templates = widgets.map((w) => w.component).lastIndexOf(TEMPLATES_WIDGET);
68
- if (templates >= 0) {
69
- const {
70
- text: rest,
71
- url
72
- } = splitTemplatesSurfaceLink(text);
73
- if (url) {
74
- text = rest;
75
- widgets[templates] = __spreadProps(__spreadValues({}, widgets[templates]), {
76
- link: url
77
- });
78
- }
79
- }
80
- return {
81
- text: text.replace(/\n{3,}/g, "\n\n").trim(),
36
+ const split = {
37
+ text,
82
38
  widgets
83
39
  };
40
+ const settled = (_b = (_a = transcriptProtocol()) == null ? void 0 : _a.settleWidgets(split)) != null ? _b : split;
41
+ return {
42
+ text: settled.text.replace(/\n{3,}/g, "\n\n").trim(),
43
+ widgets: settled.widgets
44
+ };
84
45
  }export{splitChatWidgets};//# sourceMappingURL=chatWidgets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chatWidgets.js","sources":["../../../src/features/chat/chatWidgets.ts"],"sourcesContent":["/**\n * Widget envelopes in an assistant reply, for the mobile main chat.\n *\n * Skills end a reply with a card envelope in a fenced block:\n *\n * ```yantra:widget (or ```json)\n * {\"propsComponent\":\"travel\",\"propsConfiguration\":{\"contents\":{\"attachment\":{…}}}}\n * ```\n *\n * The web chat turns that into a card (parseChatWidget). The mobile chat had no\n * parser, so the envelope rendered as a raw JSON code block, and while\n * streaming it grew in place character by character. This pulls every envelope\n * out of the text and returns what the thread should show instead.\n *\n * A `templates` widget also takes over the Templates surface link the messenger\n * gateway ends the reply with when the agent asked for the surface\n * (`?ys=<snapshot>`, splitTemplatesSurfaceLink): its row opens that link, the\n * one that lets the Templates page send a pick back to this chat, and the line\n * leaves the text - one way into the same templates, not two.\n */\n\nimport {\n CANVAS_DESIGN_WIDGET,\n canvasDesignFromWidget,\n parseTemplatesOpening,\n splitTemplatesSurfaceLink,\n TEMPLATES_WIDGET,\n} from 'common';\n\nexport interface ChatWidget {\n component: string;\n attachment: Record<string, unknown>;\n /**\n * The surface link the reply carried for this widget (a `templates` widget's\n * Templates surface page, with the reply's snapshot). Absent on a reply that\n * had none - an older reply, or one where the agent asked for no surface.\n */\n link?: string;\n}\n\nexport interface ChatWidgetSplit {\n /** The reply with every widget envelope removed. */\n text: string;\n widgets: ChatWidget[];\n}\n\nconst WIDGET_FENCE = /```(?:yantra:widget|json)[^\\S\\n]*\\n?([\\s\\S]*?)```/gi;\n/** An envelope still streaming in: an opened widget fence with no closing fence yet. */\nconst OPEN_WIDGET_TAIL = /```(?:yantra:widget|json)[^\\S\\n]*\\n?\\s*\\{\\s*\"propsComponent\"[\\s\\S]*$/i;\n/** The same, before the JSON reaches the component key. */\nconst OPEN_YANTRA_WIDGET_TAIL = /```yantra:widget[\\s\\S]*$/i;\n\nfunction toWidget(body: string): ChatWidget | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(body.trim());\n } catch {\n return null;\n }\n if (!parsed || typeof parsed !== 'object') return null;\n const obj = parsed as {\n propsComponent?: unknown;\n propsConfiguration?: { contents?: { attachment?: unknown } };\n attachment?: unknown;\n };\n if (typeof obj.propsComponent !== 'string' || !obj.propsComponent) return null;\n // Templates to browse: every field optional, the opening sometimes flat in `contents`.\n if (obj.propsComponent === TEMPLATES_WIDGET) {\n const contents = obj.propsConfiguration?.contents as Record<string, unknown> | undefined;\n const opening = parseTemplatesOpening(contents?.attachment ?? obj.attachment ?? contents ?? {});\n return opening ? { component: TEMPLATES_WIDGET, attachment: { ...opening } } : null;\n }\n // A design made from a template, only with the canvas artifact it is.\n if (obj.propsComponent === CANVAS_DESIGN_WIDGET) {\n const design = canvasDesignFromWidget(obj as Record<string, unknown>);\n return design ? { component: CANVAS_DESIGN_WIDGET, attachment: { ...design } } : null;\n }\n // Canonical path, tolerating the flatter `attachment` the web parser also accepts.\n const attachment = obj.propsConfiguration?.contents?.attachment ?? obj.attachment;\n if (!attachment || typeof attachment !== 'object') return null;\n return { component: obj.propsComponent, attachment: attachment as Record<string, unknown> };\n}\n\nexport function splitChatWidgets(content: string, streaming = false): ChatWidgetSplit {\n const widgets: ChatWidget[] = [];\n let text = content.replace(WIDGET_FENCE, (match, body: string) => {\n const widget = toWidget(body);\n if (!widget) return match; // an ordinary ```json example stays in the answer\n widgets.push(widget);\n return '';\n });\n if (streaming) {\n // Hide an envelope that is still arriving rather than paint half of it.\n text = text.replace(OPEN_WIDGET_TAIL, '').replace(OPEN_YANTRA_WIDGET_TAIL, '');\n }\n // The gateway keeps the reply's LAST templates widget as the link's snapshot, so that one owns it.\n const templates = widgets.map((w) => w.component).lastIndexOf(TEMPLATES_WIDGET);\n if (templates >= 0) {\n const { text: rest, url } = splitTemplatesSurfaceLink(text);\n if (url) {\n text = rest;\n widgets[templates] = { ...widgets[templates], link: url };\n }\n }\n return { text: text.replace(/\\n{3,}/g, '\\n\\n').trim(), widgets };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAqCA,MAAM,YAAe,GAAA,qDAAA;AAErB,MAAM,gBAAmB,GAAA,uEAAA;AAEzB,MAAM,uBAA0B,GAAA,2BAAA;AAChC,SAAS,SAAS,IAAiC,EAAA;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A;AACP,MAAA,OAAA,CAAQ,SAAS,CAAA,GAAI,aAChB,CAAA,cAAA,CAAA,EAAA,EAAA,OAAA,CAAQ,SAAS,CADD,CAAA,EAAA;AAAA,QAEnB,IAAM,EAAA;AAAA,OACR,CAAA;AAAA;AACF;AAEF,EAAO,OAAA;AAAA,IACL,MAAM,IAAK,CAAA,OAAA,CAAQ,SAAW,EAAA,MAAM,EAAE,IAAK,EAAA;AAAA,IAC3C;AAAA,GACF;AACF"}
1
+ {"version":3,"file":"chatWidgets.js","sources":["../../../src/features/chat/chatWidgets.ts"],"sourcesContent":["/**\n * Widget envelopes in an assistant reply, for the mobile main chat.\n *\n * Skills end a reply with a card envelope in a fenced block:\n *\n * ```yantra:widget (or ```json)\n * {\"propsComponent\":\"travel\",\"propsConfiguration\":{\"contents\":{\"attachment\":{…}}}}\n * ```\n *\n * The web chat turns that into a card (parseChatWidget). The mobile chat had no\n * parser, so the envelope rendered as a raw JSON code block, and while\n * streaming it grew in place character by character. This pulls every envelope\n * out of the text and returns what the thread should show instead.\n *\n * A `templates` widget also takes over the Templates surface link the messenger\n * gateway ends the reply with when the agent asked for the surface\n * (`?ys=<snapshot>`, splitTemplatesSurfaceLink): its row opens that link, the\n * one that lets the Templates page send a pick back to this chat, and the line\n * leaves the text - one way into the same templates, not two.\n */\n\nimport { transcriptProtocol } from './transcriptProtocol';\n\nexport interface ChatWidget {\n component: string;\n attachment: Record<string, unknown>;\n /**\n * The surface link the reply carried for this widget (a `templates` widget's\n * Templates surface page, with the reply's snapshot). Absent on a reply that\n * had none - an older reply, or one where the agent asked for no surface.\n */\n link?: string;\n}\n\n/** A parsed envelope, as the model wrote it. */\nexport interface ChatWidgetEnvelope {\n propsComponent: string;\n propsConfiguration?: { contents?: { attachment?: unknown } };\n attachment?: unknown;\n [key: string]: unknown;\n}\n\nexport interface ChatWidgetSplit {\n /** The reply with every widget envelope removed. */\n text: string;\n widgets: ChatWidget[];\n}\n\nconst WIDGET_FENCE = /```(?:yantra:widget|json)[^\\S\\n]*\\n?([\\s\\S]*?)```/gi;\n/** An envelope still streaming in: an opened widget fence with no closing fence yet. */\nconst OPEN_WIDGET_TAIL = /```(?:yantra:widget|json)[^\\S\\n]*\\n?\\s*\\{\\s*\"propsComponent\"[\\s\\S]*$/i;\n/** The same, before the JSON reaches the component key. */\nconst OPEN_YANTRA_WIDGET_TAIL = /```yantra:widget[\\s\\S]*$/i;\n\nfunction toWidget(body: string): ChatWidget | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(body.trim());\n } catch {\n return null;\n }\n if (!parsed || typeof parsed !== 'object') return null;\n const obj = parsed as ChatWidgetEnvelope;\n if (typeof obj.propsComponent !== 'string' || !obj.propsComponent) return null;\n const owned = transcriptProtocol()?.readWidget(obj);\n if (owned !== undefined) return owned;\n // Canonical path, tolerating the flatter `attachment` the web parser also accepts.\n const attachment = obj.propsConfiguration?.contents?.attachment ?? obj.attachment;\n if (!attachment || typeof attachment !== 'object') return null;\n return { component: obj.propsComponent, attachment: attachment as Record<string, unknown> };\n}\n\nexport function splitChatWidgets(content: string, streaming = false): ChatWidgetSplit {\n const widgets: ChatWidget[] = [];\n let text = content.replace(WIDGET_FENCE, (match, body: string) => {\n const widget = toWidget(body);\n if (!widget) return match; // an ordinary ```json example stays in the answer\n widgets.push(widget);\n return '';\n });\n if (streaming) {\n // Hide an envelope that is still arriving rather than paint half of it.\n text = text.replace(OPEN_WIDGET_TAIL, '').replace(OPEN_YANTRA_WIDGET_TAIL, '');\n }\n const split = { text, widgets };\n const settled = transcriptProtocol()?.settleWidgets(split) ?? split;\n return { text: settled.text.replace(/\\n{3,}/g, '\\n\\n').trim(), widgets: settled.widgets };\n}\n"],"names":[],"mappings":"yDAiDA,MAAM,YAAe,GAAA,qDAAA;AAErB,MAAM,gBAAmB,GAAA,uEAAA;AAEzB,MAAM,uBAA0B,GAAA,2BAAA;AAChC,SAAS,SAAS,IAAiC,EAAA;AAtDnD,EAAA,IAAA,EAAA,EAAA,EAAA,EA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A,KAAA;AACpB,IAAA,OAAA,CAAQ,KAAK,MAAM,CAAA;AACnB,IAAO,OAAA,EAAA;AAAA,GACR,CAAA;AACD,EAAA,IAAI,SAAW,EAAA;AAEb,IAAA,IAAA,GAAO,KAAK,OAAQ,CAAA,gBAAA,EAAkB,EAAE,CAAE,CAAA,OAAA,CAAQ,yBAAyB,EAAE,CAAA;AAAA;AAE/E,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,IAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,MAAM,WAAU,EAAmB,GAAA,CAAA,EAAA,GAAA,kBAAA,EAAA,KAAnB,IAAsB,GAAA,MAAA,GAAA,EAAA,CAAA,aAAA,CAAc,WAApC,IAA8C,GAAA,EAAA,GAAA,KAAA;AAC9D,EAAO,OAAA;AAAA,IACL,MAAM,OAAQ,CAAA,IAAA,CAAK,QAAQ,SAAW,EAAA,MAAM,EAAE,IAAK,EAAA;AAAA,IACnD,SAAS,OAAQ,CAAA;AAAA,GACnB;AACF"}
@@ -0,0 +1,82 @@
1
+ import {jsx}from'react/jsx-runtime';import {surfaceReplyDisplayText,TEMPLATES_WIDGET,parseTemplatesOpening,CANVAS_DESIGN_WIDGET,toCanvasDesignAttachment,splitTemplatesSurfaceLink,canvasDesignFromWidget}from'common';import {TemplatesWidgetCard,CanvasDesignWidgetCard}from'./TemplatesChatCards.js';import {registerTranscriptProtocol}from'./transcriptProtocol.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
+ function readWidget(envelope) {
21
+ var _a, _b, _c, _d;
22
+ if (envelope.propsComponent === TEMPLATES_WIDGET) {
23
+ const contents = (_a = envelope.propsConfiguration) == null ? void 0 : _a.contents;
24
+ const opening = parseTemplatesOpening((_d = (_c = (_b = contents == null ? void 0 : contents.attachment) != null ? _b : envelope.attachment) != null ? _c : contents) != null ? _d : {});
25
+ return opening ? {
26
+ component: TEMPLATES_WIDGET,
27
+ attachment: __spreadValues({}, opening)
28
+ } : null;
29
+ }
30
+ if (envelope.propsComponent === CANVAS_DESIGN_WIDGET) {
31
+ const design = canvasDesignFromWidget(envelope);
32
+ return design ? {
33
+ component: CANVAS_DESIGN_WIDGET,
34
+ attachment: __spreadValues({}, design)
35
+ } : null;
36
+ }
37
+ return void 0;
38
+ }
39
+ const hostTranscriptProtocol = {
40
+ readWidget,
41
+ settleWidgets({
42
+ text,
43
+ widgets
44
+ }) {
45
+ const templates = widgets.map((w) => w.component).lastIndexOf(TEMPLATES_WIDGET);
46
+ if (templates < 0) return {
47
+ text,
48
+ widgets
49
+ };
50
+ const {
51
+ text: rest,
52
+ url
53
+ } = splitTemplatesSurfaceLink(text);
54
+ if (!url) return {
55
+ text,
56
+ widgets
57
+ };
58
+ const settled = [...widgets];
59
+ settled[templates] = __spreadProps(__spreadValues({}, settled[templates]), {
60
+ link: url
61
+ });
62
+ return {
63
+ text: rest,
64
+ widgets: settled
65
+ };
66
+ },
67
+ renderWidget(widget, isDark) {
68
+ if (widget.component === TEMPLATES_WIDGET) {
69
+ const opening = parseTemplatesOpening(widget.attachment);
70
+ return opening ? /* @__PURE__ */ jsx(TemplatesWidgetCard, { opening, link: widget.link, isDark }) : null;
71
+ }
72
+ if (widget.component === CANVAS_DESIGN_WIDGET) {
73
+ const design = toCanvasDesignAttachment(widget.attachment);
74
+ return design ? /* @__PURE__ */ jsx(CanvasDesignWidgetCard, { design, isDark }) : null;
75
+ }
76
+ return null;
77
+ },
78
+ userTurnText: surfaceReplyDisplayText
79
+ };
80
+ function registerHostTranscriptProtocol() {
81
+ return registerTranscriptProtocol(hostTranscriptProtocol);
82
+ }export{hostTranscriptProtocol,registerHostTranscriptProtocol};//# sourceMappingURL=hostTranscriptProtocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostTranscriptProtocol.js","sources":["../../../src/features/chat/hostTranscriptProtocol.tsx"],"sourcesContent":["/**\n * The host's half of transcriptProtocol: templates in a chat, read by common's\n * TEMPLATES_CHAT_PROTOCOL and drawn as TemplatesChatCards.\n *\n * Host-only: this module imports `common` and the in-app browser, which the federated surface\n * remotes must not bundle. A remote's transcript reaches it through the registered protocol. The\n * card is a host component; rendered inside the remote's tree it still reads the host's providers,\n * which wrap that tree (as the connect card does, useHostConnectorCard).\n */\nimport React from 'react';\nimport {\n CANVAS_DESIGN_WIDGET,\n canvasDesignFromWidget,\n parseTemplatesOpening,\n splitTemplatesSurfaceLink,\n surfaceReplyDisplayText,\n TEMPLATES_WIDGET,\n toCanvasDesignAttachment,\n} from 'common';\nimport type { ChatWidgetEnvelope } from './chatWidgets';\nimport { CanvasDesignWidgetCard, TemplatesWidgetCard } from './TemplatesChatCards';\nimport { registerTranscriptProtocol, type TranscriptProtocol } from './transcriptProtocol';\n\nfunction readWidget(envelope: ChatWidgetEnvelope) {\n // Templates to browse: every field optional, the opening sometimes flat in `contents`.\n if (envelope.propsComponent === TEMPLATES_WIDGET) {\n const contents = envelope.propsConfiguration?.contents as Record<string, unknown> | undefined;\n const opening = parseTemplatesOpening(contents?.attachment ?? envelope.attachment ?? contents ?? {});\n return opening ? { component: TEMPLATES_WIDGET, attachment: { ...opening } } : null;\n }\n // A design made from a template, only with the canvas artifact it is.\n if (envelope.propsComponent === CANVAS_DESIGN_WIDGET) {\n const design = canvasDesignFromWidget(envelope);\n return design ? { component: CANVAS_DESIGN_WIDGET, attachment: { ...design } } : null;\n }\n return undefined;\n}\n\nexport const hostTranscriptProtocol: TranscriptProtocol = {\n readWidget,\n settleWidgets({ text, widgets }) {\n // The gateway keeps the reply's LAST templates widget as the link's snapshot, so that one owns it.\n const templates = widgets.map((w) => w.component).lastIndexOf(TEMPLATES_WIDGET);\n if (templates < 0) return { text, widgets };\n const { text: rest, url } = splitTemplatesSurfaceLink(text);\n if (!url) return { text, widgets };\n const settled = [...widgets];\n settled[templates] = { ...settled[templates], link: url };\n return { text: rest, widgets: settled };\n },\n renderWidget(widget, isDark) {\n if (widget.component === TEMPLATES_WIDGET) {\n const opening = parseTemplatesOpening(widget.attachment);\n return opening ? <TemplatesWidgetCard opening={opening} link={widget.link} isDark={isDark} /> : null;\n }\n if (widget.component === CANVAS_DESIGN_WIDGET) {\n const design = toCanvasDesignAttachment(widget.attachment);\n return design ? <CanvasDesignWidgetCard design={design} isDark={isDark} /> : null;\n }\n return null;\n },\n userTurnText: surfaceReplyDisplayText,\n};\n\n/** Called once at startup, from this package's module (the host's, never a remote's). */\nexport function registerHostTranscriptProtocol(): () => void {\n return registerTranscriptProtocol(hostTranscriptProtocol);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,SAAS,WAAW,QAA8B,EAAA;AAdlD,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAgBE,EAAI,IAAA,QAAA,CAAS,mBAAmB,gBAAkB,EAAA;AAChD,IAAM,MAAA,QAAA,GAAA,CAAW,EAAS,GAAA,QAAA,CAAA,kBAAA,KAAT,IAA6B,GAAA,MAAA,GAAA,EAAA,CAAA,QAAA;AAC9C,IAAM,MAAA,OAAA,GAAU,qBAAsB,CAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,CAAA,EAAA,G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AAA,EAAA;AAAA,MAEnB,IAAM,EAAA;AAAA,KACR,CAAA;AACA,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,IAAA;AAAA,MACN,OAAS,EAAA;AAAA,KACX;AAAA,GACF;AAAA,EACA,YAAA,CAAa,QAAQ,MAAQ,EAAA;AAC3B,IAAI,IAAA,MAAA,CAAO,cAAc,gBAAkB,EAAA;AACzC,MAAM,MAAA,OAAA,GAAU,qBAAsB,CAAA,MAAA,CAAO,UAAU,CAAA;AACvD,MAAO,OAAA,OAAA,uBAAW,mBAAoB,EAAA,EAAA,OAAA,EAAkB,MAAM,MAAO,CAAA,IAAA,EAAM,QAAgB,CAAK,GAAA,IAAA;AAAA;AAElG,IAAI,IAAA,MAAA,CAAO,cAAc,oBAAsB,EAAA;AAC7C,MAAM,MAAA,MAAA,GAAS,wBAAyB,CAAA,MAAA,CAAO,UAAU,CAAA;AACzD,MAAA,OAAO,MAAS,mBAAA,GAAA,CAAC,sBAAuB,EAAA,EAAA,MAAA,EAAgB,QAAgB,CAAK,GAAA,IAAA;AAAA;AAE/E,IAAO,OAAA,IAAA;AAAA,GACT;AAAA,EACA,YAAc,EAAA;AAChB;AAGO,SAAS,8BAA6C,GAAA;AAC3D,EAAA,OAAO,2BAA2B,sBAAsB,CAAA;AAC1D"}
@@ -0,0 +1,11 @@
1
+ const PROTOCOL_KEY = "__yantraTranscriptProtocol__";
2
+ function registerTranscriptProtocol(protocol) {
3
+ const holder = globalThis;
4
+ holder[PROTOCOL_KEY] = protocol;
5
+ return () => {
6
+ if (holder[PROTOCOL_KEY] === protocol) delete holder[PROTOCOL_KEY];
7
+ };
8
+ }
9
+ function transcriptProtocol() {
10
+ return globalThis[PROTOCOL_KEY];
11
+ }export{registerTranscriptProtocol,transcriptProtocol};//# sourceMappingURL=transcriptProtocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcriptProtocol.js","sources":["../../../src/features/chat/transcriptProtocol.ts"],"sourcesContent":["/**\n * The protocol-shaped part of a chat transcript, provided by the host.\n *\n * ChatTranscript ships inside the federated surface remotes, which must not bundle `common`\n * (features/__tests__/remoteImportBoundary.test.ts). But any chat can carry a templates card or a\n * template pick, and those are read by common's TEMPLATES_CHAT_PROTOCOL, the module the web chat\n * uses. Canvas and Design run their chats inside the remote, so there is no host thread to clean\n * first. The host registers this at startup (hostTranscriptProtocol) and the transcript asks here.\n *\n * Kept on `globalThis`, as sessionRenewal's renewer is, so the host bundle and a federated remote\n * share one even when each carries its own copy of this module. Under a host that registers none\n * a chat still works: generic widgets still leave the text, and protocol widgets draw no card.\n *\n * No host imports here, and only types from the transcript: this file is what remotes bundle.\n */\nimport type { ReactNode } from 'react';\nimport type { ChatWidget, ChatWidgetEnvelope, ChatWidgetSplit } from './chatWidgets';\n\nexport interface TranscriptProtocol {\n /**\n * The widget an envelope makes when the protocol owns its component, null when that envelope\n * does not validate. Undefined leaves it to the generic reader.\n */\n readWidget: (envelope: ChatWidgetEnvelope) => ChatWidget | null | undefined;\n /** The reply once the protocol has moved what belongs to its widgets out of the text. */\n settleWidgets: (split: ChatWidgetSplit) => ChatWidgetSplit;\n /** The native card for a widget the protocol owns; nothing for any other. */\n renderWidget: (widget: ChatWidget, isDark: boolean) => ReactNode;\n /** The person's words for a control line, null when the turn is not one. */\n userTurnText: (text: string) => string | null;\n}\n\nconst PROTOCOL_KEY = '__yantraTranscriptProtocol__';\n\ntype ProtocolHolder = { [PROTOCOL_KEY]?: TranscriptProtocol };\n\n/** Register the host's protocol; the returned function unregisters it (only if still the current one). */\nexport function registerTranscriptProtocol(protocol: TranscriptProtocol): () => void {\n const holder = globalThis as unknown as ProtocolHolder;\n holder[PROTOCOL_KEY] = protocol;\n return () => {\n if (holder[PROTOCOL_KEY] === protocol) delete holder[PROTOCOL_KEY];\n };\n}\n\nexport function transcriptProtocol(): TranscriptProtocol | undefined {\n return (globalThis as unknown as ProtocolHolder)[PROTOCOL_KEY];\n}\n"],"names":[],"mappings":"AA8BA,MAAM,YAAe,GAAA,8BAAA;AAMd,SAAS,2BAA2B,QAA0C,EAAA;AACnF,EAAA,MAAM,MAAS,GAAA,UAAA;AACf,EAAA,MAAA,CAAO,YAAY,CAAI,GAAA,QAAA;AACvB,EAAA,OAAO,MAAM;AACX,IAAA,IAAI,OAAO,YAAY,CAAA,KAAM,QAAU,EAAA,OAAO,OAAO,YAAY,CAAA;AAAA,GACnE;AACF;AACO,SAAS,kBAAqD,GAAA;AACnE,EAAA,OAAQ,WAAyC,YAAY,CAAA;AAC/D"}
@@ -1,4 +1,4 @@
1
- import {useCallback}from'react';import {useCdecliConnection}from'../../contexts/CdecliConnectionContext.js';import {resolveMobileWebUrl,getPackagerHost}from'../../bridge/resolveMobileWebUrl.js';import {createAgentConnectorExec}from'../canvas/videoEditor/remoteMediaClient.js';import {ONE_TIME_CODE_TIMEOUT_MS}from'./oneTimeCode.js';import {COMPUTER_CONNECTOR}from'./toolActivity.js';const REFUSED = /HTTP 401/;
1
+ import {useCallback}from'react';import'react/jsx-runtime';import'react-native';import'common/graphql';import'../../config/env-config.js';import'../../hooks/usePrerequisiteIds.js';import'common';import'@react-native-async-storage/async-storage';import'expo-secure-store';import'../messaging/yantraChatOrg.js';import {useCdecliConnection}from'../../contexts/cdecliConnection.js';import'../../contexts/GatewayContext.js';import {resolveMobileWebUrl,getPackagerHost}from'../../bridge/resolveMobileWebUrl.js';import {createAgentConnectorExec}from'../canvas/videoEditor/remoteMediaClient.js';import {ONE_TIME_CODE_TIMEOUT_MS}from'./oneTimeCode.js';import {COMPUTER_CONNECTOR}from'./toolActivity.js';const REFUSED = /HTTP 401/;
2
2
  function useComputerAction(timeoutMs = ONE_TIME_CODE_TIMEOUT_MS) {
3
3
  const {
4
4
  obtainAgentToken,
@@ -1 +1 @@
1
- {"version":3,"file":"useComputerAction.js","sources":["../../../src/features/chat/useComputerAction.ts"],"sourcesContent":["/**\n * Run a yantra-computer action on the person's own Computer, from the phone.\n *\n * WHICH Computer is decided by an identity, and it must be the one the agent\n * uses: cdecli runs every connector action as the token's subject\n * (`CDECLI_USER_ID`) and the connector resolves the caller's Computer from it,\n * so the call names no workspace. The phone has no gateway exec lane, and one\n * would not do: the gateway runs as nobody, which the agent refuses for\n * per-user work. So this goes to the agent's direct exec lane (the transport\n * the native surfaces use, remoteMediaClient) at the endpoint the chat's own\n * session connects to, with the very token that session hands the agent\n * (CdecliConnection's obtainAgentToken) - the Computer this types on is the one\n * the agent is parked on, not a lookalike resolved from another identity.\n *\n * A 401 means the agent refused the token before running anything, so after\n * the connection re-mints (recoverAgentAuth, which also moves the chat's\n * session onto the new token) the call is sent once more; nothing can be\n * typed twice. Any other failure is the caller's to explain.\n */\nimport { useCallback } from 'react';\nimport { useCdecliConnection } from '../../contexts/CdecliConnectionContext';\nimport { getPackagerHost, resolveMobileWebUrl } from '../../bridge/resolveMobileWebUrl';\nimport { createAgentConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport { COMPUTER_CONNECTOR, ONE_TIME_CODE_TIMEOUT_MS, type ComputerAction } from './oneTimeCode';\n\n/** What the transport says when the agent refused the bearer (see remoteMediaClient's execAction). */\nconst REFUSED = /HTTP 401/;\n\nexport function useComputerAction(timeoutMs: number = ONE_TIME_CODE_TIMEOUT_MS): ComputerAction {\n const { obtainAgentToken, recoverAgentAuth, agentEndpoint } = useCdecliConnection();\n\n return useCallback(\n async (action: string, params: Record<string, unknown>) => {\n // A local agent endpoint is the Mac's; a device reaches it through the packager host.\n const endpoint = resolveMobileWebUrl(agentEndpoint, getPackagerHost());\n const run = (token: string) =>\n createAgentConnectorExec(token, endpoint)(COMPUTER_CONNECTOR, action, params, { timeoutMs });\n const token = await obtainAgentToken();\n if (!token) throw new Error(`${action} failed (HTTP 401): no session for the agent yet`);\n try {\n return await run(token);\n } catch (error) {\n if (!(error instanceof Error) || !REFUSED.test(error.message)) throw error;\n if (!(await recoverAgentAuth())) throw error;\n const fresh = await obtainAgentToken();\n if (!fresh) throw error;\n return run(fresh);\n }\n },\n [agentEndpoint, obtainAgentToken, recoverAgentAuth, timeoutMs],\n );\n}\n"],"names":["token"],"mappings":"+XA0BA,MAAM,OAAU,GAAA,UAAA;AACA,SAAA,iBAAA,CAAkB,YAAoB,wBAA0C,EAAA;AAC9F,EAAM,MAAA;AAAA,IACJ,gBAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,MACE,mBAAoB,EAAA;AACxB,EAAO,OAAA,WAAA,CAAY,OAAO,MAAA,EAAgB,MAAoC,KAAA;AAE5E,IAAA,MAAM,QAAW,GAAA,mBAAA,CAAoB,aAAe,EAAA,eAAA,EAAiB,CAAA;AACrE,IAAM,MAAA,GAAA,GAAM,CAACA,MAAkB,KAAA,wBAAA,CAAyBA,QAAO,QAAQ,CAAA,CAAE,kBAAoB,EAAA,MAAA,EAAQ,MAAQ,EAAA;AAAA,MAC3G;AAAA,KACD,CAAA;AACD,IAAM,MAAA,KAAA,GAAQ,MAAM,gBAAiB,EAAA;AACrC,IAAA,IAAI,CAAC,KAAO,EAAA,MAAM,IAAI,KAAM,CAAA,CAAA,EAAG,MAAM,CAAkD,gDAAA,CAAA,CAAA;AACvF,IAAI,IAAA;AACF,MAAO,OAAA,MAAM,IAAI,KAAK,CAAA;AAAA,aACf,KAAO,EAAA;AACd,MAAI,IAAA,EAAE,iBAAiB,KAAU,CAAA,IAAA,CAAC,QAAQ,IAAK,CAAA,KAAA,CAAM,OAAO,CAAA,EAAS,MAAA,KAAA;AACrE,MAAA,IAAI,CAAE,MAAM,gBAAiB,EAAA,EAAU,MAAA,KAAA;AACvC,MAAM,MAAA,KAAA,GAAQ,MAAM,gBAAiB,EAAA;AACrC,MAAI,IAAA,CAAC,OAAa,MAAA,KAAA;AAClB,MAAA,OAAO,IAAI,KAAK,CAAA;AAAA;AAClB,KACC,CAAC,aAAA,EAAe,gBAAkB,EAAA,gBAAA,EAAkB,SAAS,CAAC,CAAA;AACnE"}
1
+ {"version":3,"file":"useComputerAction.js","sources":["../../../src/features/chat/useComputerAction.ts"],"sourcesContent":["/**\n * Run a yantra-computer action on the person's own Computer, from the phone.\n *\n * WHICH Computer is decided by an identity, and it must be the one the agent\n * uses: cdecli runs every connector action as the token's subject\n * (`CDECLI_USER_ID`) and the connector resolves the caller's Computer from it,\n * so the call names no workspace. The phone has no gateway exec lane, and one\n * would not do: the gateway runs as nobody, which the agent refuses for\n * per-user work. So this goes to the agent's direct exec lane (the transport\n * the native surfaces use, remoteMediaClient) at the endpoint the chat's own\n * session connects to, with the very token that session hands the agent\n * (CdecliConnection's obtainAgentToken) - the Computer this types on is the one\n * the agent is parked on, not a lookalike resolved from another identity.\n *\n * A 401 means the agent refused the token before running anything, so after\n * the connection re-mints (recoverAgentAuth, which also moves the chat's\n * session onto the new token) the call is sent once more; nothing can be\n * typed twice. Any other failure is the caller's to explain.\n */\nimport { useCallback } from 'react';\nimport { useCdecliConnection } from '../../contexts/CdecliConnectionContext';\nimport { getPackagerHost, resolveMobileWebUrl } from '../../bridge/resolveMobileWebUrl';\nimport { createAgentConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport { COMPUTER_CONNECTOR, ONE_TIME_CODE_TIMEOUT_MS, type ComputerAction } from './oneTimeCode';\n\n/** What the transport says when the agent refused the bearer (see remoteMediaClient's execAction). */\nconst REFUSED = /HTTP 401/;\n\nexport function useComputerAction(timeoutMs: number = ONE_TIME_CODE_TIMEOUT_MS): ComputerAction {\n const { obtainAgentToken, recoverAgentAuth, agentEndpoint } = useCdecliConnection();\n\n return useCallback(\n async (action: string, params: Record<string, unknown>) => {\n // A local agent endpoint is the Mac's; a device reaches it through the packager host.\n const endpoint = resolveMobileWebUrl(agentEndpoint, getPackagerHost());\n const run = (token: string) =>\n createAgentConnectorExec(token, endpoint)(COMPUTER_CONNECTOR, action, params, { timeoutMs });\n const token = await obtainAgentToken();\n if (!token) throw new Error(`${action} failed (HTTP 401): no session for the agent yet`);\n try {\n return await run(token);\n } catch (error) {\n if (!(error instanceof Error) || !REFUSED.test(error.message)) throw error;\n if (!(await recoverAgentAuth())) throw error;\n const fresh = await obtainAgentToken();\n if (!fresh) throw error;\n return run(fresh);\n }\n },\n [agentEndpoint, obtainAgentToken, recoverAgentAuth, timeoutMs],\n );\n}\n"],"names":["token"],"mappings":"qrBA0BA,MAAM,OAAU,GAAA,UAAA;AACA,SAAA,iBAAA,CAAkB,YAAoB,wBAA0C,EAAA;AAC9F,EAAM,MAAA;AAAA,IACJ,gBAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,MACE,mBAAoB,EAAA;AACxB,EAAO,OAAA,WAAA,CAAY,OAAO,MAAA,EAAgB,MAAoC,KAAA;AAE5E,IAAA,MAAM,QAAW,GAAA,mBAAA,CAAoB,aAAe,EAAA,eAAA,EAAiB,CAAA;AACrE,IAAM,MAAA,GAAA,GAAM,CAACA,MAAkB,KAAA,wBAAA,CAAyBA,QAAO,QAAQ,CAAA,CAAE,kBAAoB,EAAA,MAAA,EAAQ,MAAQ,EAAA;AAAA,MAC3G;AAAA,KACD,CAAA;AACD,IAAM,MAAA,KAAA,GAAQ,MAAM,gBAAiB,EAAA;AACrC,IAAA,IAAI,CAAC,KAAO,EAAA,MAAM,IAAI,KAAM,CAAA,CAAA,EAAG,MAAM,CAAkD,gDAAA,CAAA,CAAA;AACvF,IAAI,IAAA;AACF,MAAO,OAAA,MAAM,IAAI,KAAK,CAAA;AAAA,aACf,KAAO,EAAA;AACd,MAAI,IAAA,EAAE,iBAAiB,KAAU,CAAA,IAAA,CAAC,QAAQ,IAAK,CAAA,KAAA,CAAM,OAAO,CAAA,EAAS,MAAA,KAAA;AACrE,MAAA,IAAI,CAAE,MAAM,gBAAiB,EAAA,EAAU,MAAA,KAAA;AACvC,MAAM,MAAA,KAAA,GAAQ,MAAM,gBAAiB,EAAA;AACrC,MAAI,IAAA,CAAC,OAAa,MAAA,KAAA;AAClB,MAAA,OAAO,IAAI,KAAK,CAAA;AAAA;AAClB,KACC,CAAC,aAAA,EAAe,gBAAkB,EAAA,gBAAA,EAAkB,SAAS,CAAC,CAAA;AACnE"}
@@ -0,0 +1,94 @@
1
+ import {jsxs,jsx}from'react/jsx-runtime';import {View,StyleSheet,Text,Pressable,ActivityIndicator}from'react-native';import {MaterialCommunityIcons}from'@expo/vector-icons';import {mobileColors}from'../../theme/mobileTokens.js';import {freeCreditsCardView}from'./freeCredits.js';const styles = StyleSheet.create({
2
+ card: {
3
+ width: "100%",
4
+ borderWidth: 1,
5
+ borderRadius: 16,
6
+ padding: 14,
7
+ marginTop: 4,
8
+ marginBottom: 8
9
+ },
10
+ row: {
11
+ flexDirection: "row",
12
+ alignItems: "flex-start",
13
+ gap: 12
14
+ },
15
+ icon: {
16
+ width: 36,
17
+ height: 36,
18
+ borderRadius: 10,
19
+ alignItems: "center",
20
+ justifyContent: "center"
21
+ },
22
+ body: {
23
+ flex: 1,
24
+ minWidth: 0
25
+ },
26
+ title: {
27
+ fontSize: 15,
28
+ fontWeight: "700",
29
+ lineHeight: 20
30
+ },
31
+ text: {
32
+ fontSize: 13,
33
+ lineHeight: 18,
34
+ marginTop: 2
35
+ },
36
+ error: {
37
+ fontSize: 12.5,
38
+ lineHeight: 17,
39
+ marginTop: 10
40
+ },
41
+ button: {
42
+ minHeight: 44,
43
+ borderRadius: 12,
44
+ marginTop: 12,
45
+ alignItems: "center",
46
+ justifyContent: "center"
47
+ },
48
+ buttonLabel: {
49
+ color: "#ffffff",
50
+ fontSize: 15,
51
+ fontWeight: "700"
52
+ }
53
+ });
54
+ function FreeCreditsCard({
55
+ status,
56
+ claiming,
57
+ error,
58
+ onClaim,
59
+ isDark = false
60
+ }) {
61
+ const color = mobileColors(isDark);
62
+ const {
63
+ title,
64
+ body
65
+ } = freeCreditsCardView(status);
66
+ return /* @__PURE__ */ jsxs(View, { style: [styles.card, {
67
+ backgroundColor: color.surface,
68
+ borderColor: color.primaryBorder
69
+ }], children: [
70
+ /* @__PURE__ */ jsxs(View, { style: styles.row, children: [
71
+ /* @__PURE__ */ jsx(View, { style: [styles.icon, {
72
+ backgroundColor: color.primarySoft
73
+ }], children: /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "gift-outline", size: 20, color: color.primary }) }),
74
+ /* @__PURE__ */ jsxs(View, { style: styles.body, children: [
75
+ /* @__PURE__ */ jsx(Text, { style: [styles.title, {
76
+ color: color.text
77
+ }], children: title }),
78
+ /* @__PURE__ */ jsx(Text, { style: [styles.text, {
79
+ color: color.textMuted
80
+ }], children: body })
81
+ ] })
82
+ ] }),
83
+ error ? /* @__PURE__ */ jsx(Text, { style: [styles.error, {
84
+ color: color.dangerText
85
+ }], accessibilityRole: "alert", children: error }) : null,
86
+ /* @__PURE__ */ jsx(Pressable, { onPress: onClaim, disabled: claiming, accessibilityRole: "button", accessibilityLabel: "Claim free credits", accessibilityState: {
87
+ disabled: claiming,
88
+ busy: claiming
89
+ }, style: [styles.button, {
90
+ backgroundColor: color.primary,
91
+ opacity: claiming ? 0.7 : 1
92
+ }], children: claiming ? /* @__PURE__ */ jsx(ActivityIndicator, { color: "#ffffff", accessibilityLabel: "Claiming" }) : /* @__PURE__ */ jsx(Text, { style: styles.buttonLabel, children: "Claim free credits" }) })
93
+ ] });
94
+ }export{FreeCreditsCard};//# sourceMappingURL=FreeCreditsCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FreeCreditsCard.js","sources":["../../../src/features/credits/FreeCreditsCard.tsx"],"sourcesContent":["/**\n * <FreeCreditsCard> - the claim offer as a touch card, on the chat home and under a reply that\n * asked to claim. Presentational only: the status and the claim live in useFreeCredits.\n */\nimport React from 'react';\nimport { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native';\nimport { MaterialCommunityIcons } from '@expo/vector-icons';\nimport { mobileColors } from '../../theme/mobileTokens';\nimport { freeCreditsCardView, type FreeCreditsStatus } from './freeCredits';\n\nconst styles = StyleSheet.create({\n card: { width: '100%', borderWidth: 1, borderRadius: 16, padding: 14, marginTop: 4, marginBottom: 8 },\n row: { flexDirection: 'row', alignItems: 'flex-start', gap: 12 },\n icon: { width: 36, height: 36, borderRadius: 10, alignItems: 'center', justifyContent: 'center' },\n body: { flex: 1, minWidth: 0 },\n title: { fontSize: 15, fontWeight: '700', lineHeight: 20 },\n text: { fontSize: 13, lineHeight: 18, marginTop: 2 },\n error: { fontSize: 12.5, lineHeight: 17, marginTop: 10 },\n button: { minHeight: 44, borderRadius: 12, marginTop: 12, alignItems: 'center', justifyContent: 'center' },\n buttonLabel: { color: '#ffffff', fontSize: 15, fontWeight: '700' },\n});\n\nexport function FreeCreditsCard({\n status,\n claiming,\n error,\n onClaim,\n isDark = false,\n}: {\n status: FreeCreditsStatus | null;\n claiming: boolean;\n error: string | null;\n onClaim: () => void;\n isDark?: boolean;\n}) {\n const color = mobileColors(isDark);\n const { title, body } = freeCreditsCardView(status);\n return (\n <View style={[styles.card, { backgroundColor: color.surface, borderColor: color.primaryBorder }]}>\n <View style={styles.row}>\n <View style={[styles.icon, { backgroundColor: color.primarySoft }]}>\n <MaterialCommunityIcons name=\"gift-outline\" size={20} color={color.primary} />\n </View>\n <View style={styles.body}>\n <Text style={[styles.title, { color: color.text }]}>{title}</Text>\n <Text style={[styles.text, { color: color.textMuted }]}>{body}</Text>\n </View>\n </View>\n {error ? (\n <Text style={[styles.error, { color: color.dangerText }]} accessibilityRole=\"alert\">\n {error}\n </Text>\n ) : null}\n <Pressable\n onPress={onClaim}\n disabled={claiming}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Claim free credits\"\n accessibilityState={{ disabled: claiming, busy: claiming }}\n style={[styles.button, { backgroundColor: color.primary, opacity: claiming ? 0.7 : 1 }]}\n >\n {claiming ? (\n <ActivityIndicator color=\"#ffffff\" accessibilityLabel=\"Claiming\" />\n ) : (\n <Text style={styles.buttonLabel}>Claim free credits</Text>\n )}\n </Pressable>\n </View>\n );\n}\n"],"names":[],"mappings":"uRASA,MAAM,MAAA,GAAS,WAAW,MAAO,CAAA;AAAA,EAC/B,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,MAAA;A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AAAA,IACC,wBAAS,GAAA,CAAA,IAAA,EAAA,EAAK,KAAO,EAAA,CAAC,OAAO,KAAO,EAAA;AAAA,MAC3C,OAAO,KAAM,CAAA;AAAA,KACd,CAAA,EAAG,iBAAkB,EAAA,OAAA,EACL,iBACL,CAAU,GAAA,IAAA;AAAA,oBACd,GAAA,CAAC,SAAU,EAAA,EAAA,OAAA,EAAS,OAAS,EAAA,QAAA,EAAU,UAAU,iBAAkB,EAAA,QAAA,EAAS,kBAAmB,EAAA,oBAAA,EAAqB,kBAAoB,EAAA;AAAA,MAC9I,QAAU,EAAA,QAAA;AAAA,MACV,IAAM,EAAA;AAAA,KACL,EAAA,KAAA,EAAO,CAAC,MAAA,CAAO,MAAQ,EAAA;AAAA,MACxB,iBAAiB,KAAM,CAAA,OAAA;AAAA,MACvB,OAAA,EAAS,WAAW,GAAM,GAAA;AAAA,KAC3B,CACY,EAAA,QAAA,EAAA,QAAA,mBAAY,GAAA,CAAA,iBAAA,EAAA,EAAkB,OAAM,SAAU,EAAA,kBAAA,EAAmB,UAAW,EAAA,CAAA,uBAAM,IAAK,EAAA,EAAA,KAAA,EAAO,MAAO,CAAA,WAAA,EAAa,gCAAkB,CACzI,EAAA;AAAA,GACJ,EAAA,CAAA;AACR"}
@@ -0,0 +1,92 @@
1
+ import {gql}from'@apollo/client/index.js';const FREE_CREDITS_STATUS_FIELDS = gql`
2
+ fragment FreeCreditsStatusFields on FreeCreditsStatus {
3
+ unlocked
4
+ source
5
+ offerAvailable
6
+ dailyCredits
7
+ monthlyCredits
8
+ }
9
+ `;
10
+ const FREE_CREDITS_STATUS_QUERY = gql`
11
+ query FreeCreditsStatus {
12
+ freeCreditsStatus {
13
+ ...FreeCreditsStatusFields
14
+ }
15
+ }
16
+ ${FREE_CREDITS_STATUS_FIELDS}
17
+ `;
18
+ const CLAIM_FREE_CREDITS_MUTATION = gql`
19
+ mutation ClaimFreeCredits {
20
+ claimFreeCredits {
21
+ ...FreeCreditsStatusFields
22
+ }
23
+ }
24
+ ${FREE_CREDITS_STATUS_FIELDS}
25
+ `;
26
+ const FREE_CREDITS_CLAIM_FAILED = "We couldn't unlock your free credits. Please try again.";
27
+ const orgContext = (orgName) => ({
28
+ headers: {
29
+ orgname: orgName
30
+ }
31
+ });
32
+ async function fetchFreeCreditsStatus(client, orgName) {
33
+ var _a;
34
+ try {
35
+ const {
36
+ data
37
+ } = await client.query({
38
+ query: FREE_CREDITS_STATUS_QUERY,
39
+ context: orgContext(orgName),
40
+ fetchPolicy: "network-only"
41
+ });
42
+ return (_a = data == null ? void 0 : data.freeCreditsStatus) != null ? _a : null;
43
+ } catch (e) {
44
+ return null;
45
+ }
46
+ }
47
+ async function claimFreeCredits(client, orgName) {
48
+ var _a;
49
+ const {
50
+ data,
51
+ errors
52
+ } = await client.mutate({
53
+ mutation: CLAIM_FREE_CREDITS_MUTATION,
54
+ context: orgContext(orgName),
55
+ errorPolicy: "all"
56
+ });
57
+ const status = data == null ? void 0 : data.claimFreeCredits;
58
+ if (!status) {
59
+ throw new Error(((_a = errors == null ? void 0 : errors[0]) == null ? void 0 : _a.message) || FREE_CREDITS_CLAIM_FAILED);
60
+ }
61
+ return status;
62
+ }
63
+ const LOCKED_REPLY = /haven['’]t claimed your free Yantra credits/i;
64
+ function isFreeCreditsLockedReply(text) {
65
+ return LOCKED_REPLY.test(text != null ? text : "");
66
+ }
67
+ function lockedTurnToResend(messages) {
68
+ var _a, _b;
69
+ const newest = messages[messages.length - 1];
70
+ if ((newest == null ? void 0 : newest.role) !== "assistant" || !isFreeCreditsLockedReply(newest.content)) return null;
71
+ for (let i = messages.length - 2; i >= 0; i -= 1) {
72
+ const prior = messages[i];
73
+ 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;
74
+ }
75
+ return null;
76
+ }
77
+ function shouldOfferFreeCredits(status) {
78
+ return Boolean((status == null ? void 0 : status.offerAvailable) && !status.unlocked);
79
+ }
80
+ function freeCreditsCardView(status) {
81
+ const title = "Unlock your free AI credits";
82
+ if (!(status == null ? void 0 : status.dailyCredits)) {
83
+ return {
84
+ title,
85
+ body: "Claim your free credits to start chatting with Yantra."
86
+ };
87
+ }
88
+ return {
89
+ title,
90
+ body: `Claim ${status.dailyCredits.toLocaleString()} free AI credits a day, up to ${status.monthlyCredits.toLocaleString()} a month.`
91
+ };
92
+ }export{CLAIM_FREE_CREDITS_MUTATION,FREE_CREDITS_CLAIM_FAILED,FREE_CREDITS_STATUS_QUERY,claimFreeCredits,fetchFreeCreditsStatus,freeCreditsCardView,isFreeCreditsLockedReply,lockedTurnToResend,shouldOfferFreeCredits};//# sourceMappingURL=freeCredits.js.map
@@ -0,0 +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\nconst FREE_CREDITS_STATUS_FIELDS = gql`\n fragment FreeCreditsStatusFields on FreeCreditsStatus {\n unlocked\n source\n offerAvailable\n dailyCredits\n monthlyCredits\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/** What the card says. The credit numbers are the server's, so it can never promise a stale amount. */\nexport function freeCreditsCardView(status: FreeCreditsStatus | null): FreeCreditsCardView {\n const title = 'Unlock your free AI credits';\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":"0CAkBA,MAAM,0BAA6B,GAAA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AAS5B,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,EACvC,OAAS,EAAA;AAAA,IACP,OAAS,EAAA;AAAA;AAEb,CAAA,CAAA;AAGsB,eAAA,sBAAA,CAAuB,QAAuB,OAAoD,EAAA;AApDxH,EAAA,IAAA,EAAA;AAqDE,EAAI,IAAA;AACF,IAAM,MAAA;AAAA,MACJ;AAAA,KACF,GAAI,MAAM,MAAA,CAAO,KAEd,CAAA;AAAA,MACD,KAAO,EAAA,yBAAA;AAAA,MACP,OAAA,EAAS,WAAW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