@adminide-stack/yantra-mobile 12.0.167-alpha.0 → 12.0.168-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 (134) hide show
  1. package/lib/assets/kinds/character.webp +0 -0
  2. package/lib/assets/kinds/image.webp +0 -0
  3. package/lib/assets/kinds/video.webp +0 -0
  4. package/lib/assets/kinds/website.webp +0 -0
  5. package/lib/bridge/handlers/NavigationBridgeHandler.js +3 -2
  6. package/lib/bridge/handlers/NavigationBridgeHandler.js.map +1 -1
  7. package/lib/components/CustomDrawer.js +6 -2
  8. package/lib/components/CustomDrawer.js.map +1 -1
  9. package/lib/features/agent-chat/NativeAgentChat.js +17 -3
  10. package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
  11. package/lib/features/chat/ApprovalCard.js +8 -2
  12. package/lib/features/chat/ApprovalCard.js.map +1 -1
  13. package/lib/features/chat/AskUserCard.js +5 -3
  14. package/lib/features/chat/AskUserCard.js.map +1 -1
  15. package/lib/features/chat/ComposerModeSwitch.js +147 -0
  16. package/lib/features/chat/ComposerModeSwitch.js.map +1 -0
  17. package/lib/features/templates/__tests__/buildKinds.test.ts +54 -0
  18. package/lib/features/templates/__tests__/buildTemplateCards.test.ts +58 -6
  19. package/lib/features/templates/__tests__/templateSuggestion.test.ts +30 -0
  20. package/lib/features/templates/buildKinds.js +114 -0
  21. package/lib/features/templates/buildKinds.js.map +1 -0
  22. package/lib/features/templates/buildKinds.ts +189 -0
  23. package/lib/features/templates/buildTemplateCards.js +63 -18
  24. package/lib/features/templates/buildTemplateCards.js.map +1 -1
  25. package/lib/features/templates/buildTemplateCards.ts +88 -18
  26. package/lib/features/templates/index.ts +2 -0
  27. package/lib/features/templates/templateSuggestion.js +34 -0
  28. package/lib/features/templates/templateSuggestion.js.map +1 -0
  29. package/lib/features/templates/templateSuggestion.ts +57 -0
  30. package/lib/features/webbuilder/WebBuilderExperience.js +188 -28
  31. package/lib/features/webbuilder/WebBuilderExperience.js.map +1 -1
  32. package/lib/features/webbuilder/approvalsLink.js +6 -0
  33. package/lib/features/webbuilder/approvalsLink.js.map +1 -0
  34. package/lib/features/webbuilder/buildFragments.js +19 -4
  35. package/lib/features/webbuilder/buildFragments.js.map +1 -1
  36. package/lib/features/webbuilder/components/CloudSheet.js +18 -5
  37. package/lib/features/webbuilder/components/CloudSheet.js.map +1 -1
  38. package/lib/features/webbuilder/components/CodeView.js +7 -3
  39. package/lib/features/webbuilder/components/CodeView.js.map +1 -1
  40. package/lib/features/webbuilder/components/DomainFinder.js +263 -0
  41. package/lib/features/webbuilder/components/DomainFinder.js.map +1 -0
  42. package/lib/features/webbuilder/components/DraftsSheet.js +298 -0
  43. package/lib/features/webbuilder/components/DraftsSheet.js.map +1 -0
  44. package/lib/features/webbuilder/components/ImageEditPanel.js +266 -0
  45. package/lib/features/webbuilder/components/ImageEditPanel.js.map +1 -0
  46. package/lib/features/webbuilder/components/MentionMenu.js +155 -0
  47. package/lib/features/webbuilder/components/MentionMenu.js.map +1 -0
  48. package/lib/features/webbuilder/components/NotesSheet.js +138 -0
  49. package/lib/features/webbuilder/components/NotesSheet.js.map +1 -0
  50. package/lib/features/webbuilder/components/PreviewFrame.js.map +1 -1
  51. package/lib/features/webbuilder/components/ProjectChat.js +17 -3
  52. package/lib/features/webbuilder/components/ProjectChat.js.map +1 -1
  53. package/lib/features/webbuilder/components/PublishSheet.js +200 -15
  54. package/lib/features/webbuilder/components/PublishSheet.js.map +1 -1
  55. package/lib/features/webbuilder/components/ShareSheet.js +48 -6
  56. package/lib/features/webbuilder/components/ShareSheet.js.map +1 -1
  57. package/lib/features/webbuilder/components/SiteCopyProgress.js +169 -0
  58. package/lib/features/webbuilder/components/SiteCopyProgress.js.map +1 -0
  59. package/lib/features/webbuilder/components/SiteStatusSheet.js +145 -2
  60. package/lib/features/webbuilder/components/SiteStatusSheet.js.map +1 -1
  61. package/lib/features/webbuilder/drafts.js +167 -0
  62. package/lib/features/webbuilder/drafts.js.map +1 -0
  63. package/lib/features/webbuilder/maskPng.js +113 -0
  64. package/lib/features/webbuilder/maskPng.js.map +1 -0
  65. package/lib/features/webbuilder/previewProbe.js.map +1 -1
  66. package/lib/features/webbuilder/stepLabels.js +21 -1
  67. package/lib/features/webbuilder/stepLabels.js.map +1 -1
  68. package/lib/features/webbuilder/web/chat/mentions.js +106 -0
  69. package/lib/features/webbuilder/web/chat/mentions.js.map +1 -0
  70. package/lib/features/webbuilder/web/chat/siteCopy.js +121 -0
  71. package/lib/features/webbuilder/web/chat/siteCopy.js.map +1 -0
  72. package/lib/features/webbuilder/web/code/imageEdit.js +30 -0
  73. package/lib/features/webbuilder/web/code/imageEdit.js.map +1 -0
  74. package/lib/features/webbuilder/web/design/linkedDesign.js +26 -0
  75. package/lib/features/webbuilder/web/design/linkedDesign.js.map +1 -0
  76. package/lib/features/webbuilder/web/project/buildLink.js +3 -0
  77. package/lib/features/webbuilder/web/project/buildLink.js.map +1 -0
  78. package/lib/features/webbuilder/web/project/drafts.js +57 -0
  79. package/lib/features/webbuilder/web/project/drafts.js.map +1 -0
  80. package/lib/features/webbuilder/web/project/navHistory.js +7 -0
  81. package/lib/features/webbuilder/web/project/navHistory.js.map +1 -0
  82. package/lib/features/webbuilder/web/project/serverSettings.js +15 -4
  83. package/lib/features/webbuilder/web/project/serverSettings.js.map +1 -1
  84. package/lib/features/webbuilder/web/publish/domainShop.js +79 -0
  85. package/lib/features/webbuilder/web/publish/domainShop.js.map +1 -0
  86. package/lib/features/webbuilder/web/publish/publishRequest.js +11 -0
  87. package/lib/features/webbuilder/web/publish/publishRequest.js.map +1 -0
  88. package/lib/features/webbuilder/web/publish/review/freshness.js +13 -0
  89. package/lib/features/webbuilder/web/publish/review/freshness.js.map +1 -0
  90. package/lib/features/webbuilder/web/publish/review/ignores.js +94 -0
  91. package/lib/features/webbuilder/web/publish/review/ignores.js.map +1 -0
  92. package/lib/features/webbuilder/web/publish/review/seo.js +230 -0
  93. package/lib/features/webbuilder/web/publish/review/seo.js.map +1 -0
  94. package/lib/features/webbuilder/web/publish/siteHealth.js +27 -3
  95. package/lib/features/webbuilder/web/publish/siteHealth.js.map +1 -1
  96. package/lib/features/webbuilder/web/publish/siteInsights.js +120 -3
  97. package/lib/features/webbuilder/web/publish/siteInsights.js.map +1 -1
  98. package/lib/features/webbuilder/web/sharing/shareLink.js +9 -0
  99. package/lib/features/webbuilder/web/sharing/shareLink.js.map +1 -0
  100. package/lib/features/webbuilder/web/webServices.js +1 -1
  101. package/lib/features/webbuilder/web/webServices.js.map +1 -1
  102. package/lib/hooks/useMarketplaceTemplateCards.js +3 -4
  103. package/lib/hooks/useMarketplaceTemplateCards.js.map +1 -1
  104. package/lib/hooks/useMarketplaceTemplateGroups.js +12 -5
  105. package/lib/hooks/useMarketplaceTemplateGroups.js.map +1 -1
  106. package/lib/hooks/useTemplatesResourceUri.js +12 -0
  107. package/lib/hooks/useTemplatesResourceUri.js.map +1 -0
  108. package/lib/screens/Chat/index.js +4 -22
  109. package/lib/screens/Chat/index.js.map +1 -1
  110. package/lib/screens/Home/HomeScreen.js +165 -179
  111. package/lib/screens/Home/HomeScreen.js.map +1 -1
  112. package/lib/screens/Home/components/BuildKindPicker.js +248 -0
  113. package/lib/screens/Home/components/BuildKindPicker.js.map +1 -0
  114. package/lib/screens/Home/components/BuildTemplatesSection.js +556 -117
  115. package/lib/screens/Home/components/BuildTemplatesSection.js.map +1 -1
  116. package/lib/screens/Home/components/KindThumb.js +444 -0
  117. package/lib/screens/Home/components/KindThumb.js.map +1 -0
  118. package/lib/screens/Home/components/TemplateSuggestionBanner.js +73 -0
  119. package/lib/screens/Home/components/TemplateSuggestionBanner.js.map +1 -0
  120. package/lib/screens/Home/components/buildTheme.js +68 -0
  121. package/lib/screens/Home/components/buildTheme.js.map +1 -0
  122. package/lib/screens/WebBuilder/index.js +11 -1
  123. package/lib/screens/WebBuilder/index.js.map +1 -1
  124. package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js +55 -0
  125. package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js.map +1 -0
  126. package/lib/screens/WebBuilderNative/codeWorkspaceApi.js +4 -0
  127. package/lib/screens/WebBuilderNative/codeWorkspaceApi.js.map +1 -1
  128. package/lib/screens/WebBuilderNative/index.js +31 -4
  129. package/lib/screens/WebBuilderNative/index.js.map +1 -1
  130. package/lib/screens/WebBuilderNative/useWebBuilderHost.js +1 -0
  131. package/lib/screens/WebBuilderNative/useWebBuilderHost.js.map +1 -1
  132. package/lib/screens/WebBuilderNative/webbuilderTransport.js +5 -5
  133. package/lib/screens/WebBuilderNative/webbuilderTransport.js.map +1 -1
  134. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"previewProbe.js","sources":["../../../src/features/webbuilder/previewProbe.ts"],"sourcesContent":["/**\n * Is a sandbox preview actually serving? (web `sandbox/previewProbe.ts`, #f99bd580, #fbd72c42)\n * e2b - and the platform's sandbox domain in front of it - answers a stopped dev server\n * or an expired sandbox with its own page, sometimes as HTTP 200, which a WebView shows\n * raw. So a preview is framed only once a probe saw the site itself answer.\n *\n * A phone has no CORS: the body is always readable, so the classification is exact.\n *\n * Private previews (`previewAccess.ts`): the proxy answers a private sandbox that is running with 401\n * (\"This preview is private\") to anyone without a session - the probe included, which never carries a\n * token - so 401 reads as serving: the WebView brings the token. A private sandbox that is paused gets\n * the proxy's own 502 JSON, which never wakes it: nothing to frame, the same as e2b's \"Paused sandbox\n * ... not found\" (web `sandbox/previewProbe.ts`).\n */\n\nexport const CLOSED_PORT_RE =\n /Closed Port Error|Update Port Error|Could Not Find|Connection refused on port|no service (running|listening|waiting)|THERE'?S NO SERVICE LISTENING|Port 3000 is no longer|is no longer running|no longer active/i;\nexport const SANDBOX_GONE_RE =\n /\\bSANDBOX_GONE\\b|Sandbox Not Found|Paused sandbox .+ not found|sandbox \\S+ not found|sandbox .*wasn'?t found|not found \\(404\\)|no sandbox found|does not exist|sandbox.*expired|sandbox.*killed|probably not running anymore|not running anymore|cannot be resumed|was (?:killed|deleted|destroyed)/i;\n\n/**\n * `open`: the site answered (or the proxy's private-preview gate did); `port-closed`: the sandbox runs, its\n * dev server does not; `gone`: no sandbox to show (expired, or a private one asleep); `unknown`: no answer.\n */\nexport type PreviewProbe = 'open' | 'port-closed' | 'gone' | 'unknown';\n\n/**\n * The sandbox proxy's answer for a private sandbox that is paused (asleep): 502 JSON\n * `{\"sandboxId\",\"state\":\"paused\",\"message\":\"Sandbox <id> is paused (asleep)\",\"code\":502}`.\n */\nexport const PAUSED_PREVIEW_RE = /\"state\"\\s*:\\s*\"paused\"|\\bis paused \\(asleep\\)/i;\n\n/** The proxy's 401 for a private preview opened without a session (its HTML page or its plain text). */\nexport const PRIVATE_PREVIEW_RE = /This preview (?:is private|link has expired)/i;\n\n/** Only the start of a page is read: e2b's own pages say what they are near the top. */\nconst SNIFF_CHARS = 6_000;\nconst PROBE_TIMEOUT_MS = 8_000;\n\n/** What an HTTP answer from a preview URL means. */\nexport function classifyPreviewAnswer(status: number, body: string): PreviewProbe {\n const head = String(body || '').slice(0, SNIFF_CHARS);\n if (SANDBOX_GONE_RE.test(head)) return 'gone';\n if (status === 502 && PAUSED_PREVIEW_RE.test(head)) return 'gone';\n if (CLOSED_PORT_RE.test(head)) return 'port-closed';\n if (status >= 500) return 'port-closed';\n if (status === 404 && /e2b|sandbox/i.test(head)) return 'gone';\n return 'open';\n}\n\n/** One probe of a preview URL (GET, short timeout). Never throws. */\nexport async function probePreview(url: string, fetchImpl: typeof fetch = fetch): Promise<PreviewProbe> {\n if (!/^https?:\\/\\//i.test(url)) return 'unknown';\n const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS) : null;\n try {\n const res = await fetchImpl(url, { method: 'GET', ...(controller ? { signal: controller.signal } : {}) });\n const body = await res.text().catch(() => '');\n return classifyPreviewAnswer(res.status, body);\n } catch {\n return 'unknown';\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n\n/** The site answered, or nothing did (no network to judge by): frame it. A known-dead page is never framed. */\nexport function mayFrame(probe: PreviewProbe): boolean {\n return probe === 'open' || probe === 'unknown';\n}\n\n/**\n * The proxy's answer that a preview is private: its 401 page, or its 502 for a private sandbox asleep.\n * Someone opening the plain link (no session) sees that, never the site.\n */\nexport function isPrivatePreviewAnswer(status: number, body: string): boolean {\n const head = String(body || '').slice(0, SNIFF_CHARS);\n return (status === 401 && PRIVATE_PREVIEW_RE.test(head)) || (status === 502 && PAUSED_PREVIEW_RE.test(head));\n}\n\n/** How long a share waits to learn whether its preview is private. */\nconst PRIVACY_TIMEOUT_MS = 5_000;\n/** A preview found public is believed this long; a private one stays private (E2B sets it at creation). */\nconst PUBLIC_ANSWER_MS = 10 * 60_000;\nconst privacyAnswers = new Map<string, { until: number; answer: Promise<boolean | null> }>();\n\n/** `https://<host>` of a link, lowercased: one answer per sandbox port. */\nfunction originOf(url: string): string | null {\n const m = /^(https:\\/\\/[^/?#\\s]+)/i.exec(String(url || '').trim());\n return m ? m[1].toLowerCase() : null;\n}\n\nasync function askPrivacy(url: string, fetchImpl: typeof fetch): Promise<boolean | null> {\n const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), PRIVACY_TIMEOUT_MS) : null;\n try {\n const res = await fetchImpl(url, {\n method: 'GET',\n credentials: 'omit',\n ...(controller ? { signal: controller.signal } : {}),\n });\n const body = await res.text().catch(() => '');\n return isPrivatePreviewAnswer(res.status, body);\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n\n/**\n * Would someone with the plain link see only \"This preview is private\"? One GET of the raw URL without\n * cookies (Android shares the WebView's cookies with fetch, and this phone may hold a session) and never\n * with a token. True/false once the proxy answered; null when nothing did (offline, timeout). Kept per\n * sandbox port, so the check a screen starts makes a later share instant. Never throws.\n */\nexport function probePreviewPrivacy(url: string, fetchImpl: typeof fetch = fetch): Promise<boolean | null> {\n const origin = originOf(url);\n if (!origin) return Promise.resolve(null);\n const cached = privacyAnswers.get(origin);\n if (cached && cached.until > Date.now()) return cached.answer;\n const entry = { until: Date.now() + PUBLIC_ANSWER_MS, answer: askPrivacy(url, fetchImpl) };\n privacyAnswers.set(origin, entry);\n entry.answer\n .then((value) => {\n if (value === true) entry.until = Number.POSITIVE_INFINITY;\n else if (value === null && privacyAnswers.get(origin) === entry) privacyAnswers.delete(origin);\n })\n .catch(() => undefined);\n return entry.answer;\n}\n\n/** Test hook: forget the privacy answers. */\nexport function resetPreviewPrivacyAnswers(): void {\n privacyAnswers.clear();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAeO,MAAM,cAAiB,GAAA;AACvB,MAAM,eAAkB,GAAA;AAYxB,MAAM,iBAAoB,GAAA;AAG1B,MAAM,kBAAqB,GAAA;AAGlC,MAAM,WAAc,GAAA,GAAA;AACpB,MAAM,gBAAmB,GAAA,GAAA;AAGT,SAAA,qBAAA,CAAsB,QAAgB,IAA4B,EAAA;AAChF,EAAA,MAAM,OAAO,MAAO,CAAA,IAAA,IAAQ,EAAE,CAAE,CAAA,KAAA,CAAM,GAAG,WAAW,CAAA;AACpD,EAAA,IAAI,eAAgB,CAAA,IAAA,CAAK,IAAI,CAAA,EAAU,OAAA,MAAA;AACvC,EAAA,IAAI,WAAW,GAAO,IAAA,iBAAA,CAAkB,IAAK,CAAA,IAAI,GAAU,OAAA,MAAA;AAC3D,EAAA,IAAI,cAAe,CAAA,IAAA,CAAK,IAAI,CAAA,EAAU,OAAA,aAAA;AACtC,EAAI,IAAA,MAAA,IAAU,KAAY,OAAA,aAAA;AAC1B,EAAA,IAAI,WAAW,GAAO,IAAA,cAAA,CAAe,IAAK,CAAA,IAAI,GAAU,OAAA,MAAA;AACxD,EAAO,OAAA,MAAA;AACT;AAGsB,eAAA,YAAA,CAAa,GAAa,EAAA,SAAA,GAA0B,KAA8B,EAAA;AACtG,EAAA,IAAI,CAAC,eAAA,CAAgB,IAAK,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MAAO,CAAA,KAAA,GAAQ,KAAK,GAAI,EAAA,SAAU,MAAO,CAAA,MAAA;AACvD,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,KAAA,EAAO,IAAK,CAAA,GAAA,EAAQ,GAAA,gBAAA;AAAA,IACpB,MAAA,EAAQ,UAAW,CAAA,GAAA,EAAK,SAAS;AAAA,GACnC;AACA,EAAe,cAAA,CAAA,GAAA,CAAI,QAAQ,KAAK,CAAA;AAChC,EAAM,KAAA,CAAA,MAAA,CAAO,KAAK,CAAS,KAAA,KAAA;AACzB,IAAA,IAAI,KAAU,KAAA,IAAA,EAAY,KAAA,CAAA,KAAA,GAAQ,MAAO,CAAA,iBAAA;AAAA,SAA2B,IAAA,KAAA,KAAU,QAAQ,cAAe,CAAA,GAAA,CAAI,MAAM,CAAM,KAAA,KAAA,EAAsB,cAAA,CAAA,MAAA,CAAO,MAAM,CAAA;AAAA,GACzJ,CAAA,CAAE,KAAM,CAAA,MAAM,MAAS,CAAA;AACxB,EAAA,OAAO,KAAM,CAAA,MAAA;AACf"}
1
+ {"version":3,"file":"previewProbe.js","sources":["../../../src/features/webbuilder/previewProbe.ts"],"sourcesContent":["/**\n * Is a sandbox preview actually serving? (web `sandbox/previewProbe.ts`, #f99bd580, #fbd72c42)\n * e2b - and the platform's sandbox domain in front of it - answers a stopped dev server\n * or an expired sandbox with its own page, sometimes as HTTP 200, which a WebView shows\n * raw. So a preview is framed only once a probe saw the site itself answer.\n *\n * A phone has no CORS: the body is always readable, so the classification is exact.\n *\n * Private previews (`previewAccess.ts`): the proxy answers a private sandbox that is running with 401\n * (\"This preview is private\") to anyone without a session - the probe included, which never carries a\n * token - so 401 reads as serving: the WebView brings the token. A private sandbox that is paused gets\n * the proxy's own 502 JSON, which never wakes it: nothing to frame, the same as e2b's \"Paused sandbox\n * ... not found\" (web `sandbox/previewProbe.ts`).\n */\n\nexport const CLOSED_PORT_RE =\n /Closed Port Error|Update Port Error|Could Not Find|Connection refused on port|no service (running|listening|waiting)|THERE'?S NO SERVICE LISTENING|Port 3000 is no longer|is no longer running|no longer active/i;\nexport const SANDBOX_GONE_RE =\n /\\bSANDBOX_GONE\\b|Sandbox Not Found|Paused sandbox .+ not found|sandbox \\S+ not found|sandbox .*wasn'?t found|not found \\(404\\)|no sandbox found|does not exist|sandbox.*expired|sandbox.*killed|probably not running anymore|not running anymore|cannot be resumed|was (?:killed|deleted|destroyed)/i;\n\n/**\n * `open`: the site answered (or the proxy's private-preview gate did); `port-closed`: the sandbox runs, its\n * dev server does not; `gone`: no sandbox to show (expired, or a private one asleep); `unknown`: no answer.\n */\nexport type PreviewProbe = 'open' | 'port-closed' | 'gone' | 'unknown';\n\n/**\n * The sandbox proxy's answer for a private sandbox that is paused (asleep): 502 JSON\n * `{\"sandboxId\",\"state\":\"paused\",\"message\":\"Sandbox <id> is paused (asleep)\",\"code\":502}`.\n */\nexport const PAUSED_PREVIEW_RE = /\"state\"\\s*:\\s*\"paused\"|\\bis paused \\(asleep\\)/i;\n\n/** The proxy's 401 for a private preview opened without a session (its HTML page or its plain text). */\nexport const PRIVATE_PREVIEW_RE = /This preview (?:is private|link has expired)/i;\n\n/** Only the start of a page is read: e2b's own pages say what they are near the top. */\nconst SNIFF_CHARS = 6_000;\nconst PROBE_TIMEOUT_MS = 8_000;\n\n/** What an HTTP answer from a preview URL means. */\nexport function classifyPreviewAnswer(status: number, body: string): PreviewProbe {\n const head = String(body || '').slice(0, SNIFF_CHARS);\n if (SANDBOX_GONE_RE.test(head)) return 'gone';\n // The sandbox proxy's paused (asleep) private sandbox: it never wakes it, so nothing to show (web 0.9).\n if (status === 502 && PAUSED_PREVIEW_RE.test(head)) return 'gone';\n if (CLOSED_PORT_RE.test(head)) return 'port-closed';\n if (status >= 500) return 'port-closed';\n if (status === 404 && /e2b|sandbox/i.test(head)) return 'gone';\n return 'open';\n}\n\n/** One probe of a preview URL (GET, short timeout). Never throws. */\nexport async function probePreview(url: string, fetchImpl: typeof fetch = fetch): Promise<PreviewProbe> {\n if (!/^https?:\\/\\//i.test(url)) return 'unknown';\n const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS) : null;\n try {\n const res = await fetchImpl(url, { method: 'GET', ...(controller ? { signal: controller.signal } : {}) });\n const body = await res.text().catch(() => '');\n return classifyPreviewAnswer(res.status, body);\n } catch {\n return 'unknown';\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n\n/** The site answered, or nothing did (no network to judge by): frame it. A known-dead page is never framed. */\nexport function mayFrame(probe: PreviewProbe): boolean {\n return probe === 'open' || probe === 'unknown';\n}\n\n/**\n * The proxy's answer that a preview is private: its 401 page, or its 502 for a private sandbox asleep.\n * Someone opening the plain link (no session) sees that, never the site.\n */\nexport function isPrivatePreviewAnswer(status: number, body: string): boolean {\n const head = String(body || '').slice(0, SNIFF_CHARS);\n return (status === 401 && PRIVATE_PREVIEW_RE.test(head)) || (status === 502 && PAUSED_PREVIEW_RE.test(head));\n}\n\n/** How long a share waits to learn whether its preview is private. */\nconst PRIVACY_TIMEOUT_MS = 5_000;\n/** A preview found public is believed this long; a private one stays private (E2B sets it at creation). */\nconst PUBLIC_ANSWER_MS = 10 * 60_000;\nconst privacyAnswers = new Map<string, { until: number; answer: Promise<boolean | null> }>();\n\n/** `https://<host>` of a link, lowercased: one answer per sandbox port. */\nfunction originOf(url: string): string | null {\n const m = /^(https:\\/\\/[^/?#\\s]+)/i.exec(String(url || '').trim());\n return m ? m[1].toLowerCase() : null;\n}\n\nasync function askPrivacy(url: string, fetchImpl: typeof fetch): Promise<boolean | null> {\n const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), PRIVACY_TIMEOUT_MS) : null;\n try {\n const res = await fetchImpl(url, {\n method: 'GET',\n credentials: 'omit',\n ...(controller ? { signal: controller.signal } : {}),\n });\n const body = await res.text().catch(() => '');\n return isPrivatePreviewAnswer(res.status, body);\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n\n/**\n * Would someone with the plain link see only \"This preview is private\"? One GET of the raw URL without\n * cookies (Android shares the WebView's cookies with fetch, and this phone may hold a session) and never\n * with a token. True/false once the proxy answered; null when nothing did (offline, timeout). Kept per\n * sandbox port, so the check a screen starts makes a later share instant. Never throws.\n */\nexport function probePreviewPrivacy(url: string, fetchImpl: typeof fetch = fetch): Promise<boolean | null> {\n const origin = originOf(url);\n if (!origin) return Promise.resolve(null);\n const cached = privacyAnswers.get(origin);\n if (cached && cached.until > Date.now()) return cached.answer;\n const entry = { until: Date.now() + PUBLIC_ANSWER_MS, answer: askPrivacy(url, fetchImpl) };\n privacyAnswers.set(origin, entry);\n entry.answer\n .then((value) => {\n if (value === true) entry.until = Number.POSITIVE_INFINITY;\n else if (value === null && privacyAnswers.get(origin) === entry) privacyAnswers.delete(origin);\n })\n .catch(() => undefined);\n return entry.answer;\n}\n\n/** Test hook: forget the privacy answers. */\nexport function resetPreviewPrivacyAnswers(): void {\n privacyAnswers.clear();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAeO,MAAM,cAAiB,GAAA;AACvB,MAAM,eAAkB,GAAA;AAYxB,MAAM,iBAAoB,GAAA;AAG1B,MAAM,kBAAqB,GAAA;AAGlC,MAAM,WAAc,GAAA,GAAA;AACpB,MAAM,gBAAmB,GAAA,GAAA;AAGT,SAAA,qBAAA,CAAsB,QAAgB,IAA4B,EAAA;AAChF,EAAA,MAAM,OAAO,MAAO,CAAA,IAAA,IAAQ,EAAE,CAAE,CAAA,KAAA,CAAM,GAAG,WAAW,CAAA;AACpD,EAAA,IAAI,eAAgB,CAAA,IAAA,CAAK,IAAI,CAAA,EAAU,OAAA,MAAA;AAEvC,EAAA,IAAI,WAAW,GAAO,IAAA,iBAAA,CAAkB,IAAK,CAAA,IAAI,GAAU,OAAA,MAAA;AAC3D,EAAA,IAAI,cAAe,CAAA,IAAA,CAAK,IAAI,CAAA,EAAU,OA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AQgB,SAAA,mBAAA,CAAoB,GAAa,EAAA,SAAA,GAA0B,KAAgC,EAAA;AACzG,EAAM,MAAA,MAAA,GAAS,SAAS,GAAG,CAAA;AAC3B,EAAA,IAAI,CAAC,MAAA,EAAe,OAAA,OAAA,CAAQ,QAAQ,IAAI,CAAA;AACxC,EAAM,MAAA,MAAA,GAAS,cAAe,CAAA,GAAA,CAAI,MAAM,CAAA;AACxC,EAAA,IAAI,UAAU,MAAO,CAAA,KAAA,GAAQ,KAAK,GAAI,EAAA,SAAU,MAAO,CAAA,MAAA;AACvD,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,KAAA,EAAO,IAAK,CAAA,GAAA,EAAQ,GAAA,gBAAA;AAAA,IACpB,MAAA,EAAQ,UAAW,CAAA,GAAA,EAAK,SAAS;AAAA,GACnC;AACA,EAAe,cAAA,CAAA,GAAA,CAAI,QAAQ,KAAK,CAAA;AAChC,EAAM,KAAA,CAAA,MAAA,CAAO,KAAK,CAAS,KAAA,KAAA;AACzB,IAAA,IAAI,KAAU,KAAA,IAAA,EAAY,KAAA,CAAA,KAAA,GAAQ,MAAO,CAAA,iBAAA;AAAA,SAA2B,IAAA,KAAA,KAAU,QAAQ,cAAe,CAAA,GAAA,CAAI,MAAM,CAAM,KAAA,KAAA,EAAsB,cAAA,CAAA,MAAA,CAAO,MAAM,CAAA;AAAA,GACzJ,CAAA,CAAE,KAAM,CAAA,MAAM,MAAS,CAAA;AACxB,EAAA,OAAO,KAAM,CAAA,MAAA;AACf"}
@@ -17,7 +17,27 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- const ACTION_LABELS = [[/^(BROWSER_CHECK|FINISH)$/i, "Testing your site in a browser"], [/UNPUBLISH/i, "Taking the site offline"], [/TERMINATE|STOP_SANDBOX|KILL_SANDBOX/i, "Shutting down the preview"], [/EXPORT|ZIP/i, "Packaging your code"], [/DEPLOY|PUBLISH/i, "Publishing"], [/GITHUB|_PUSH\b|COMMIT/i, "Saving to GitHub"], [/SNAPSHOT|RESTORE_POINT|SAVE_VERSION/i, "Saving a restore point"], [/RESTORE|ROLLBACK/i, "Restoring a version"], [/CREATE_SANDBOX|RESUME|CONNECT_SANDBOX|CREATE_PROJECT/i, "Setting up your project"], [/SCREENSHOT|PROBE|HEALTH|CHECK_PREVIEW|QA\b/i, "Checking the preview"], [/START|DEV_SERVER|PREVIEW/i, "Starting the preview"], [/DATABASE|SUPABASE|SQL|MIGRAT/i, "Setting up the database"], [/IMAGE|LOGO|PHOTO/i, "Creating images"], [/EDIT_FILES|WRITE_FILES|SET_CONTENT|EDIT|WRITE/i, "Building your site"], [/READ_FILES|LIST_FILES|READ|LIST/i, "Reading your site"], [/INSTALL|PACKAGES?/i, "Installing packages"], [/BUILD|TYPECHECK|LINT/i, "Checking the build"]];
20
+ const ACTION_LABELS = [
21
+ [/^(BROWSER_CHECK|FINISH)$/i, "Testing your site in a browser"],
22
+ [/UNPUBLISH/i, "Taking the site offline"],
23
+ [/TERMINATE|STOP_SANDBOX|KILL_SANDBOX/i, "Shutting down the preview"],
24
+ [/EXPORT|ZIP/i, "Packaging your code"],
25
+ [/DEPLOY|PUBLISH/i, "Publishing"],
26
+ // Before CLONE (git): a website copy ("make resortifi.com here", yantra-webbuilder 1.1.0; web 0.9.1).
27
+ [/CLONE_WEBSITE/i, "Copying the website"],
28
+ [/GITHUB|_PUSH\b|COMMIT/i, "Saving to GitHub"],
29
+ [/SNAPSHOT|RESTORE_POINT|SAVE_VERSION/i, "Saving a restore point"],
30
+ [/RESTORE|ROLLBACK/i, "Restoring a version"],
31
+ [/CREATE_SANDBOX|RESUME|CONNECT_SANDBOX|CREATE_PROJECT/i, "Setting up your project"],
32
+ [/SCREENSHOT|PROBE|HEALTH|CHECK_PREVIEW|QA\b/i, "Checking the preview"],
33
+ [/START|DEV_SERVER|PREVIEW/i, "Starting the preview"],
34
+ [/DATABASE|SUPABASE|SQL|MIGRAT/i, "Setting up the database"],
35
+ [/IMAGE|LOGO|PHOTO/i, "Creating images"],
36
+ [/EDIT_FILES|WRITE_FILES|SET_CONTENT|EDIT|WRITE/i, "Building your site"],
37
+ [/READ_FILES|LIST_FILES|READ|LIST/i, "Reading your site"],
38
+ [/INSTALL|PACKAGES?/i, "Installing packages"],
39
+ [/BUILD|TYPECHECK|LINT/i, "Checking the build"]
40
+ ];
21
41
  function commandLabel(command) {
22
42
  if (/\b(npm|yarn|pnpm|bun)\s+(i|install|add)\b/i.test(command)) return "Installing packages";
23
43
  if (/\b(build|tsc|lint|test|vitest|jest|typecheck)\b/i.test(command)) return "Checking the build";
@@ -1 +1 @@
1
- {"version":3,"file":"stepLabels.js","sources":["../../../src/features/webbuilder/stepLabels.ts"],"sourcesContent":["/**\n * Plain-language names for the agent's tool steps in Web Builder (\"Building your site\",\n * \"Testing your site in a browser\") in place of connector slugs - web `chat/stepLabels.ts`\n * (#479, #496). Consecutive steps with the same name merge into one row. Pure.\n */\nimport type { ToolStep } from '../chat/toolActivity';\n\nconst ACTION_LABELS: Array<[RegExp, string]> = [\n [/^(BROWSER_CHECK|FINISH)$/i, 'Testing your site in a browser'],\n [/UNPUBLISH/i, 'Taking the site offline'],\n [/TERMINATE|STOP_SANDBOX|KILL_SANDBOX/i, 'Shutting down the preview'],\n [/EXPORT|ZIP/i, 'Packaging your code'],\n [/DEPLOY|PUBLISH/i, 'Publishing'],\n [/GITHUB|_PUSH\\b|COMMIT/i, 'Saving to GitHub'],\n [/SNAPSHOT|RESTORE_POINT|SAVE_VERSION/i, 'Saving a restore point'],\n [/RESTORE|ROLLBACK/i, 'Restoring a version'],\n [/CREATE_SANDBOX|RESUME|CONNECT_SANDBOX|CREATE_PROJECT/i, 'Setting up your project'],\n [/SCREENSHOT|PROBE|HEALTH|CHECK_PREVIEW|QA\\b/i, 'Checking the preview'],\n [/START|DEV_SERVER|PREVIEW/i, 'Starting the preview'],\n [/DATABASE|SUPABASE|SQL|MIGRAT/i, 'Setting up the database'],\n [/IMAGE|LOGO|PHOTO/i, 'Creating images'],\n [/EDIT_FILES|WRITE_FILES|SET_CONTENT|EDIT|WRITE/i, 'Building your site'],\n [/READ_FILES|LIST_FILES|READ|LIST/i, 'Reading your site'],\n [/INSTALL|PACKAGES?/i, 'Installing packages'],\n [/BUILD|TYPECHECK|LINT/i, 'Checking the build'],\n];\n\nfunction commandLabel(command: string): string {\n if (/\\b(npm|yarn|pnpm|bun)\\s+(i|install|add)\\b/i.test(command)) return 'Installing packages';\n if (/\\b(build|tsc|lint|test|vitest|jest|typecheck)\\b/i.test(command)) return 'Checking the build';\n if (/\\b(dev|preview|serve|start)\\b/i.test(command)) return 'Starting the preview';\n if (/\\bcurl\\b|\\bwget\\b/i.test(command)) return 'Checking the preview';\n return 'Running a check';\n}\n\n// Bare tool names the agent runs, as the person's words; anything else shaped like a tool id is generic.\nconst TOOL_LABELS: Array<[RegExp, string]> = [\n [/^(read|glob|grep|ls|notebook_?read)$/i, 'Reading your site'],\n [/^(edit|multi_?edit|write|str_replace_editor|notebook_?edit)$/i, 'Building your site'],\n [/^todo_?write$/i, 'Planning the work'],\n [/^(web_?fetch|web_?search|web_?scrape|tool_?search)$/i, 'Looking things up'],\n];\n\nexport const GENERIC_STEP_LABEL = 'Working on your site';\n\n/** A tool id rather than words: `execute_action`, `mcp__cdecli__…`, `WebFetch`, or one cut short (\"execute_action —\"). */\nfunction isToolId(label: string): boolean {\n const t = label.replace(/\\s*[—–-]\\s*$/, '').trim();\n return /__|_/.test(t) || /^mcp\\b/i.test(t) || (/^[A-Za-z][A-Za-z0-9]*$/.test(t) && /[a-z][A-Z]/.test(t));\n}\n\n/** A step title for people: `fallback` when the label is missing or is a tool id. */\nexport function readableStepLabel(label: string | null | undefined, fallback: string): string {\n const t = (label ?? '').trim();\n return t && !isToolId(t) ? t : fallback;\n}\n\n/** The connector action a raw step ran (`WEBBUILDER_WRITE_FILES`), even when its line was cut short; null if none. */\nexport function stepAction(step: Pick<ToolStep, 'label' | 'detail'>): string | null {\n const executing = /Executing\\s+([A-Z0-9_]{3,})/.exec(step.label);\n if (executing) return executing[1];\n const detail = (step.detail ?? '').trim().replace(/(?:…|\\.\\.\\.)$/, '');\n return /\\/([A-Z][A-Z0-9_]{2,})\\s*$/.exec(detail)?.[1] ?? null;\n}\n\n/** One raw step as a plain-language label. */\nexport function friendlyStepLabel(step: Pick<ToolStep, 'label' | 'detail'>): string {\n const label = step.label.trim();\n let detail = (step.detail ?? '').trim();\n // cdecli's own row: \"🚀 Executing WEBBUILDER_WRITE_FILES on yantra-webbuilder\".\n const executing = /Executing\\s+([A-Z0-9_]+)\\s+on\\s+([\\w-]+)/.exec(label);\n if (executing) detail = `${executing[2]}/${executing[1]}`;\n if (/updating task plan/i.test(label)) return 'Planning the work';\n if (/^\\{.*\\}$/.test(label)) return 'Looking things up';\n // `execute_action — yantra-<connector>/<ACTION>`: the action says what is happening.\n const rawAction = stepAction({ label, detail });\n if (rawAction) {\n // WEBBUILDER_BUILD_X: the connector's own prefix must not match \"BUILD\".\n const prefix = detail\n .split('/')[0]\n .replace(/^yantra-/i, '')\n .replace(/[-_]/g, '')\n .toUpperCase();\n const action = prefix && rawAction.startsWith(`${prefix}_`) ? rawAction.slice(prefix.length + 1) : rawAction;\n const hit = ACTION_LABELS.find(([re]) => re.test(action));\n return hit ? hit[1] : GENERIC_STEP_LABEL;\n }\n if (/^Editing files$/i.test(label)) return 'Building your site';\n if (/^Reading files$/i.test(label)) return 'Reading your site';\n if (/^Running a command$/i.test(label)) return commandLabel(detail);\n if (/^Searching tools$/i.test(label)) return 'Getting ready';\n if (/^Running\\s/i.test(label)) return GENERIC_STEP_LABEL;\n const tool = label.replace(/^mcp__[^_]+__/i, '').replace(/\\s*[—–-]\\s*$/, '');\n if (/^bash$/i.test(tool)) return commandLabel(detail);\n const hit = TOOL_LABELS.find(([re]) => re.test(tool));\n if (hit) return hit[1];\n if (!label || isToolId(label)) return GENERIC_STEP_LABEL;\n return label;\n}\n\n/** The agent wrote the site's content: a write / edit / content action finished, or the final check ran. */\nexport function firstContentLanded(steps: readonly ToolStep[]): boolean {\n return steps.some((s) => {\n const action = stepAction(s) ?? '';\n if (/(?:^|_)FINISH$/.test(action)) return true;\n if (s.status !== 'done') return false;\n return (\n /(?:WRITE_FILES|EDIT_FILES|SET_CONTENT|APPLY_CONTENT)$/.test(action) ||\n /^Editing files$/i.test(s.label.trim())\n );\n });\n}\n\n/** The steps with friendly names, a run of the same name merged into one row. */\nexport function friendlySteps(steps: readonly ToolStep[]): ToolStep[] {\n const out: ToolStep[] = [];\n for (const step of steps) {\n const label = friendlyStepLabel(step);\n const last = out[out.length - 1];\n if (last && last.label === label) {\n last.count = (last.count ?? 1) + (step.count ?? 1);\n last.status = step.status;\n } else {\n out.push({ ...step, label, detail: undefined, count: step.count });\n }\n }\n return out;\n}\n"],"names":["hit"],"mappings":";;;;;;;;;;;;;;;;;;;AAMA,MAAM,aAAyC,GAAA,CAAC,CAAC,2BAAA,EAA6B,gCAAgC,CAAG,EAAA,CAAC,YAAc,EAAA,yBAAyB,CAAG,EAAA,CAAC,sCAAwC,EAAA,2BAA2B,GAAG,CAAC,aAAA,EAAe,qBAAqB,CAAA,EAAG,CAAC,iBAAA,EAAmB,YAAY,CAAA,EAAG,CAAC,wBAA0B,EAAA,kBAAkB,CAAG,EAAA,CAAC,sCAAwC,EAAA,wBAAwB,CAAG,EAAA,CAAC,qBAAqB,qBAAqB,CAAA,EAAG,CAAC,uDAAA,EAAyD,yBAAyB,CAAA,EAAG,CAAC,6CAAA,EAA+C,sBAAsB,CAAG,EAAA,CAAC,2BAA6B,EAAA,sBAAsB,CAAG,EAAA,CAAC,+BAAiC,EAAA,yBAAyB,GAAG,CAAC,mBAAA,EAAqB,iBAAiB,CAAA,EAAG,CAAC,gDAAA,EAAkD,oBAAoB,CAAA,EAAG,CAAC,kCAAoC,EAAA,mBAAmB,CAAG,EAAA,CAAC,sBAAsB,qBAAqB,CAAA,EAAG,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ain-language names for the agent's tool steps in Web Builder (\"Building your site\",\n * \"Testing your site in a browser\") in place of connector slugs - web `chat/stepLabels.ts`\n * (#479, #496). Consecutive steps with the same name merge into one row. Pure.\n */\nimport type { ToolStep } from '../chat/toolActivity';\n\nconst ACTION_LABELS: Array<[RegExp, string]> = [\n [/^(BROWSER_CHECK|FINISH)$/i, 'Testing your site in a browser'],\n [/UNPUBLISH/i, 'Taking the site offline'],\n [/TERMINATE|STOP_SANDBOX|KILL_SANDBOX/i, 'Shutting down the preview'],\n [/EXPORT|ZIP/i, 'Packaging your code'],\n [/DEPLOY|PUBLISH/i, 'Publishing'],\n // Before CLONE (git): a website copy (\"make resortifi.com here\", yantra-webbuilder 1.1.0; web 0.9.1).\n [/CLONE_WEBSITE/i, 'Copying the website'],\n [/GITHUB|_PUSH\\b|COMMIT/i, 'Saving to GitHub'],\n [/SNAPSHOT|RESTORE_POINT|SAVE_VERSION/i, 'Saving a restore point'],\n [/RESTORE|ROLLBACK/i, 'Restoring a version'],\n [/CREATE_SANDBOX|RESUME|CONNECT_SANDBOX|CREATE_PROJECT/i, 'Setting up your project'],\n [/SCREENSHOT|PROBE|HEALTH|CHECK_PREVIEW|QA\\b/i, 'Checking the preview'],\n [/START|DEV_SERVER|PREVIEW/i, 'Starting the preview'],\n [/DATABASE|SUPABASE|SQL|MIGRAT/i, 'Setting up the database'],\n [/IMAGE|LOGO|PHOTO/i, 'Creating images'],\n [/EDIT_FILES|WRITE_FILES|SET_CONTENT|EDIT|WRITE/i, 'Building your site'],\n [/READ_FILES|LIST_FILES|READ|LIST/i, 'Reading your site'],\n [/INSTALL|PACKAGES?/i, 'Installing packages'],\n [/BUILD|TYPECHECK|LINT/i, 'Checking the build'],\n];\n\nfunction commandLabel(command: string): string {\n if (/\\b(npm|yarn|pnpm|bun)\\s+(i|install|add)\\b/i.test(command)) return 'Installing packages';\n if (/\\b(build|tsc|lint|test|vitest|jest|typecheck)\\b/i.test(command)) return 'Checking the build';\n if (/\\b(dev|preview|serve|start)\\b/i.test(command)) return 'Starting the preview';\n if (/\\bcurl\\b|\\bwget\\b/i.test(command)) return 'Checking the preview';\n return 'Running a check';\n}\n\n// Bare tool names the agent runs, as the person's words; anything else shaped like a tool id is generic.\nconst TOOL_LABELS: Array<[RegExp, string]> = [\n [/^(read|glob|grep|ls|notebook_?read)$/i, 'Reading your site'],\n [/^(edit|multi_?edit|write|str_replace_editor|notebook_?edit)$/i, 'Building your site'],\n [/^todo_?write$/i, 'Planning the work'],\n [/^(web_?fetch|web_?search|web_?scrape|tool_?search)$/i, 'Looking things up'],\n];\n\nexport const GENERIC_STEP_LABEL = 'Working on your site';\n\n/** A tool id rather than words: `execute_action`, `mcp__cdecli__…`, `WebFetch`, or one cut short (\"execute_action —\"). */\nfunction isToolId(label: string): boolean {\n const t = label.replace(/\\s*[—–-]\\s*$/, '').trim();\n return /__|_/.test(t) || /^mcp\\b/i.test(t) || (/^[A-Za-z][A-Za-z0-9]*$/.test(t) && /[a-z][A-Z]/.test(t));\n}\n\n/** A step title for people: `fallback` when the label is missing or is a tool id. */\nexport function readableStepLabel(label: string | null | undefined, fallback: string): string {\n const t = (label ?? '').trim();\n return t && !isToolId(t) ? t : fallback;\n}\n\n/** The connector action a raw step ran (`WEBBUILDER_WRITE_FILES`), even when its line was cut short; null if none. */\nexport function stepAction(step: Pick<ToolStep, 'label' | 'detail'>): string | null {\n const executing = /Executing\\s+([A-Z0-9_]{3,})/.exec(step.label);\n if (executing) return executing[1];\n const detail = (step.detail ?? '').trim().replace(/(?:…|\\.\\.\\.)$/, '');\n return /\\/([A-Z][A-Z0-9_]{2,})\\s*$/.exec(detail)?.[1] ?? null;\n}\n\n/** One raw step as a plain-language label. */\nexport function friendlyStepLabel(step: Pick<ToolStep, 'label' | 'detail'>): string {\n const label = step.label.trim();\n let detail = (step.detail ?? '').trim();\n // cdecli's own row: \"🚀 Executing WEBBUILDER_WRITE_FILES on yantra-webbuilder\".\n const executing = /Executing\\s+([A-Z0-9_]+)\\s+on\\s+([\\w-]+)/.exec(label);\n if (executing) detail = `${executing[2]}/${executing[1]}`;\n if (/updating task plan/i.test(label)) return 'Planning the work';\n if (/^\\{.*\\}$/.test(label)) return 'Looking things up';\n // `execute_action — yantra-<connector>/<ACTION>`: the action says what is happening.\n const rawAction = stepAction({ label, detail });\n if (rawAction) {\n // WEBBUILDER_BUILD_X: the connector's own prefix must not match \"BUILD\".\n const prefix = detail\n .split('/')[0]\n .replace(/^yantra-/i, '')\n .replace(/[-_]/g, '')\n .toUpperCase();\n const action = prefix && rawAction.startsWith(`${prefix}_`) ? rawAction.slice(prefix.length + 1) : rawAction;\n const hit = ACTION_LABELS.find(([re]) => re.test(action));\n return hit ? hit[1] : GENERIC_STEP_LABEL;\n }\n if (/^Editing files$/i.test(label)) return 'Building your site';\n if (/^Reading files$/i.test(label)) return 'Reading your site';\n if (/^Running a command$/i.test(label)) return commandLabel(detail);\n if (/^Searching tools$/i.test(label)) return 'Getting ready';\n if (/^Running\\s/i.test(label)) return GENERIC_STEP_LABEL;\n const tool = label.replace(/^mcp__[^_]+__/i, '').replace(/\\s*[—–-]\\s*$/, '');\n if (/^bash$/i.test(tool)) return commandLabel(detail);\n const hit = TOOL_LABELS.find(([re]) => re.test(tool));\n if (hit) return hit[1];\n if (!label || isToolId(label)) return GENERIC_STEP_LABEL;\n return label;\n}\n\n/** The agent wrote the site's content: a write / edit / content action finished, or the final check ran. */\nexport function firstContentLanded(steps: readonly ToolStep[]): boolean {\n return steps.some((s) => {\n const action = stepAction(s) ?? '';\n if (/(?:^|_)FINISH$/.test(action)) return true;\n if (s.status !== 'done') return false;\n return (\n /(?:WRITE_FILES|EDIT_FILES|SET_CONTENT|APPLY_CONTENT)$/.test(action) ||\n /^Editing files$/i.test(s.label.trim())\n );\n });\n}\n\n/** The steps with friendly names, a run of the same name merged into one row. */\nexport function friendlySteps(steps: readonly ToolStep[]): ToolStep[] {\n const out: ToolStep[] = [];\n for (const step of steps) {\n const label = friendlyStepLabel(step);\n const last = out[out.length - 1];\n if (last && last.label === label) {\n last.count = (last.count ?? 1) + (step.count ?? 1);\n last.status = step.status;\n } else {\n out.push({ ...step, label, detail: undefined, count: step.count });\n }\n }\n return out;\n}\n"],"names":["hit"],"mappings":";;;;;;;;;;;;;;;;;;;AAMA,MAAM,aAAyC,GAAA;AAAA,EAAC,CAAC,6BAA6B,gCAAgC,CAAA;AAAA,EAAG,CAAC,cAAc,yBAAyB,CAAA;AAAA,EAAG,CAAC,wCAAwC,2BAA2B,CAAA;AAAA,EAAG,CAAC,eAAe,qBAAqB,CAAA;AAAA,EAAG,CAAC,mBAAmB,YAAY,CAAA;AAAA;AAAA,EAE3S,CAAC,kBAAkB,qBAAqB,CAAA;AAAA,EAAG,CAAC,0BAA0B,kBAAkB,CAAA;AAAA,EAAG,CAAC,wCAAwC,wBAAwB,CAAA;AAAA,EAAG,CAAC,qBAAqB,qBAAqB,CAAA;AAAA,EAAG,CAAC,yDAAyD,yBAAyB,CAAA;AAAA,EAAG,CAAC,+CAA+C,sBAAsB,CAAA;AAAA,EAAG,CAAC,6BAA6B,sBAAsB,CAAA;AAAA,EAAG,CAAC,iCAAiC,yBAAyB,CAAA;AAAA,EAAG,CAAC,qBAAqB,iBAAiB,CAAA;AAAA,EAAG,CAAC,kDAAkD,oBAAoB,CAAA;AAAA,EAAG,CAAC,oCAAoC,mBAAmB,CAAA;AAAA,EAAG,CAAC,sBAAsB,qBAAqB,CAAA;AAAA,EAAG,CAAC,yBAAyB,oBAAoB;AAAC,CAAA;AAC9uB,SAAS,aAAa,OAAyB,EAAA;AAC7C,EAAA,IAAI,4CAA6C,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,qBAAA;AACvE,EAAA,IAAI,kDAAmD,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,oBAAA;AAC7E,EAAA,IAAI,gCAAiC,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,sBAAA;AAC3D,EAAA,IAAI,oBAAqB,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AAE,KAAM,CAAA,IAAA,EAAM,CAAA;AAAA,GACtH,CAAA;AACH;AAGO,SAAS,cAAc,KAAwC,EAAA;AAtFtE,EAAA,IAAA,EAAA,EAAA,EAAA;AAuFE,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAM,MAAA,KAAA,GAAQ,kBAAkB,IAAI,CAAA;AACpC,IAAA,MAAM,IAAO,GAAA,GAAA,CAAI,GAAI,CAAA,MAAA,GAAS,CAAC,CAAA;AAC/B,IAAI,IAAA,IAAA,IAAQ,IAAK,CAAA,KAAA,KAAU,KAAO,EAAA;AAChC,MAAA,IAAA,CAAK,UAAS,EAAK,GAAA,IAAA,CAAA,KAAA,KAAL,YAAc,CAAM,KAAA,CAAA,EAAA,GAAA,IAAA,CAAK,UAAL,IAAc,GAAA,EAAA,GAAA,CAAA,CAAA;AAChD,MAAA,IAAA,CAAK,SAAS,IAAK,CAAA,MAAA;AAAA,KACd,MAAA;AACL,MAAI,GAAA,CAAA,IAAA,CAAK,iCACJ,IADI,CAAA,EAAA;AAAA,QAEP,KAAA;AAAA,QACA,MAAQ,EAAA,MAAA;AAAA,QACR,OAAO,IAAK,CAAA;AAAA,OACb,CAAA,CAAA;AAAA;AACH;AAEF,EAAO,OAAA,GAAA;AACT"}
@@ -0,0 +1,106 @@
1
+ const TOKEN_CHAR = /[\w./\-[\]:]/;
2
+ const MAX_QUERY = 120;
3
+ function activeMentionQuery(text, caret) {
4
+ const end = Math.max(0, Math.min(caret, text.length));
5
+ let i = end - 1;
6
+ while (i >= 0 && end - i <= MAX_QUERY + 1) {
7
+ const ch = text[i];
8
+ if (ch === "@") {
9
+ const before = i > 0 ? text[i - 1] : "";
10
+ if (before && !/[\s([{"'`]/.test(before)) return null;
11
+ return {
12
+ start: i,
13
+ query: text.slice(i + 1, end)
14
+ };
15
+ }
16
+ if (!TOKEN_CHAR.test(ch)) return null;
17
+ i--;
18
+ }
19
+ return null;
20
+ }
21
+ const baseName = (path) => path.slice(path.lastIndexOf("/") + 1);
22
+ const dirName = (path) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
23
+ const MENTIONABLE_FILE = /\.(tsx?|jsx?|mjs|css|scss|html|md|mdx|json|svg|png|jpe?g|webp|gif|avif|ico)$/i;
24
+ const NOISE_FILE = /(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb|tsconfig[^/]*\.json|components\.json)$/i;
25
+ function mentionableFile(path) {
26
+ return MENTIONABLE_FILE.test(path) && !NOISE_FILE.test(path);
27
+ }
28
+ function mentionCatalog(routes, files) {
29
+ const out = [];
30
+ const seen = /* @__PURE__ */ new Set();
31
+ for (const r of routes) {
32
+ const path = String(r.path || "").trim();
33
+ if (!path.startsWith("/") || /[\s*]/.test(path) || seen.has(path)) continue;
34
+ seen.add(path);
35
+ out.push({
36
+ kind: "page",
37
+ token: path,
38
+ label: r.label || path,
39
+ detail: path
40
+ });
41
+ }
42
+ for (const f of files) {
43
+ if (!f || seen.has(f) || !mentionableFile(f)) continue;
44
+ seen.add(f);
45
+ out.push({
46
+ kind: "file",
47
+ token: f,
48
+ label: baseName(f),
49
+ detail: dirName(f)
50
+ });
51
+ }
52
+ return out;
53
+ }
54
+ function filterMentions(items, query, limit = 8) {
55
+ const q = query.trim().toLowerCase();
56
+ const scored = [];
57
+ items.forEach((item, index) => {
58
+ const label = item.label.toLowerCase();
59
+ const token = item.token.toLowerCase();
60
+ let score;
61
+ if (!q) score = item.kind === "page" ? 0 : 1;
62
+ else if (label === q || token === q || token === `/${q}`) score = 0;
63
+ else if (label.startsWith(q) || token.startsWith(q) || token.startsWith(`/${q}`)) score = 1;
64
+ else if (label.includes(q)) score = 2;
65
+ else if (token.includes(q)) score = 3;
66
+ else return;
67
+ scored.push({
68
+ item,
69
+ score: score * 2 + (item.kind === "page" ? 0 : 1),
70
+ index
71
+ });
72
+ });
73
+ return scored.sort((a, b) => a.score - b.score || a.index - b.index).slice(0, limit).map((s) => s.item);
74
+ }
75
+ function insertMention(text, at, caret, item) {
76
+ const end = Math.max(at.start + 1, Math.min(caret, text.length));
77
+ const after = text.slice(end);
78
+ const insert = `@${item.token}${after.startsWith(" ") ? "" : " "}`;
79
+ const next = text.slice(0, at.start) + insert + after;
80
+ return {
81
+ text: next,
82
+ caret: at.start + insert.length + (after.startsWith(" ") ? 1 : 0)
83
+ };
84
+ }
85
+ const MENTION_IN_TEXT = /(^|[\s([{"'`])@([\w./\-[\]:]+)/g;
86
+ function mentionedItems(text, items) {
87
+ const byToken = new Map(items.map((i) => [i.token, i]));
88
+ const out = [];
89
+ const seen = /* @__PURE__ */ new Set();
90
+ for (const m of String(text || "").matchAll(MENTION_IN_TEXT)) {
91
+ const raw = m[2];
92
+ const token = byToken.has(raw) ? raw : raw.replace(/[.:,;!?\]]+$/, "");
93
+ const item = byToken.get(token);
94
+ if (!item || seen.has(item.token)) continue;
95
+ seen.add(item.token);
96
+ out.push(item);
97
+ }
98
+ return out;
99
+ }
100
+ const MAX_NOTED = 12;
101
+ function mentionNote(items) {
102
+ if (!items.length) return null;
103
+ const parts = items.slice(0, MAX_NOTED).map((i) => i.kind === "page" ? `page ${i.token}` : `file ${i.token}`);
104
+ const more = items.length > MAX_NOTED ? ` (and ${items.length - MAX_NOTED} more)` : "";
105
+ return `[Mentions] The user points at: ${parts.join("; ")}${more}. "@<path>" in the message means these; open them first and keep the change to them unless the message asks for more.`;
106
+ }export{activeMentionQuery,filterMentions,insertMention,mentionCatalog,mentionNote,mentionableFile,mentionedItems};//# sourceMappingURL=mentions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mentions.js","sources":["../../../../../src/features/webbuilder/web/chat/mentions.ts"],"sourcesContent":["/**\n * \"@\" mentions in the composer: point the AI at a page or a file of the site. Pure.\n *\n * Typing \"@\" at the start of a word opens a list of the site's pages and files; picking one writes a\n * readable token into the message (\"@/pricing\", \"@src/components/Hero.tsx\"). The message keeps the\n * token as the person wrote it, and the send adds one hidden note, \"[Mentions] ...\", that names what\n * each token points at so the agent opens those files first.\n */\nimport type { PreviewRoute } from '../../previewRoutes';\n\nexport type MentionKind = 'page' | 'file';\n\nexport interface MentionItem {\n kind: MentionKind;\n /** What is written after \"@\": the page path (\"/pricing\") or the file path (\"src/App.tsx\"). */\n token: string;\n /** \"Pricing\", \"Hero.tsx\". */\n label: string;\n /** \"/pricing\", \"src/components\". */\n detail: string;\n}\n\nexport interface MentionQuery {\n /** Index of the \"@\" in the text. */\n start: number;\n /** What was typed after \"@\", up to the caret. */\n query: string;\n}\n\n/** Characters a token is made of (paths: letters, digits, \"/\", \".\", \"-\", \"_\", \"[\", \"]\", \":\"). */\nconst TOKEN_CHAR = /[\\w./\\-[\\]:]/;\nconst MAX_QUERY = 120;\n\n/**\n * The mention being typed at the caret: an \"@\" at the start of the text or after a space or an opening\n * bracket, followed by token characters only. An email (\"me@site.com\") is not a mention.\n */\nexport function activeMentionQuery(text: string, caret: number): MentionQuery | null {\n const end = Math.max(0, Math.min(caret, text.length));\n let i = end - 1;\n while (i >= 0 && end - i <= MAX_QUERY + 1) {\n const ch = text[i];\n if (ch === '@') {\n const before = i > 0 ? text[i - 1] : '';\n if (before && !/[\\s([{\"'`]/.test(before)) return null;\n return { start: i, query: text.slice(i + 1, end) };\n }\n if (!TOKEN_CHAR.test(ch)) return null;\n i--;\n }\n return null;\n}\n\nconst baseName = (path: string) => path.slice(path.lastIndexOf('/') + 1);\nconst dirName = (path: string) => (path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '');\n\n/** Files worth pointing at: source, styles, content and public assets (not lockfiles or config noise). */\nconst MENTIONABLE_FILE = /\\.(tsx?|jsx?|mjs|css|scss|html|md|mdx|json|svg|png|jpe?g|webp|gif|avif|ico)$/i;\nconst NOISE_FILE =\n /(^|\\/)(package-lock\\.json|yarn\\.lock|pnpm-lock\\.yaml|bun\\.lockb|tsconfig[^/]*\\.json|components\\.json)$/i;\n\nexport function mentionableFile(path: string): boolean {\n return MENTIONABLE_FILE.test(path) && !NOISE_FILE.test(path);\n}\n\n/** Pages and files as mention items, pages first (each list keeps its own order). */\nexport function mentionCatalog(routes: ReadonlyArray<PreviewRoute>, files: ReadonlyArray<string>): MentionItem[] {\n const out: MentionItem[] = [];\n const seen = new Set<string>();\n for (const r of routes) {\n const path = String(r.path || '').trim();\n if (!path.startsWith('/') || /[\\s*]/.test(path) || seen.has(path)) continue;\n seen.add(path);\n out.push({ kind: 'page', token: path, label: r.label || path, detail: path });\n }\n for (const f of files) {\n if (!f || seen.has(f) || !mentionableFile(f)) continue;\n seen.add(f);\n out.push({ kind: 'file', token: f, label: baseName(f), detail: dirName(f) });\n }\n return out;\n}\n\n/**\n * The items matching what was typed, best first: an exact or prefix match on the name beats a match\n * inside the path; pages stay ahead of files on a tie. Empty query: the pages, then the first files.\n */\nexport function filterMentions(items: ReadonlyArray<MentionItem>, query: string, limit = 8): MentionItem[] {\n const q = query.trim().toLowerCase();\n const scored: Array<{ item: MentionItem; score: number; index: number }> = [];\n items.forEach((item, index) => {\n const label = item.label.toLowerCase();\n const token = item.token.toLowerCase();\n let score: number;\n if (!q) score = item.kind === 'page' ? 0 : 1;\n else if (label === q || token === q || token === `/${q}`) score = 0;\n else if (label.startsWith(q) || token.startsWith(q) || token.startsWith(`/${q}`)) score = 1;\n else if (label.includes(q)) score = 2;\n else if (token.includes(q)) score = 3;\n else return;\n scored.push({ item, score: score * 2 + (item.kind === 'page' ? 0 : 1), index });\n });\n return scored\n .sort((a, b) => a.score - b.score || a.index - b.index)\n .slice(0, limit)\n .map((s) => s.item);\n}\n\n/** The text with the typed \"@query\" replaced by \"@token \" and where the caret goes. */\nexport function insertMention(\n text: string,\n at: MentionQuery,\n caret: number,\n item: Pick<MentionItem, 'token'>,\n): { text: string; caret: number } {\n const end = Math.max(at.start + 1, Math.min(caret, text.length));\n const after = text.slice(end);\n const insert = `@${item.token}${after.startsWith(' ') ? '' : ' '}`;\n const next = text.slice(0, at.start) + insert + after;\n return { text: next, caret: at.start + insert.length + (after.startsWith(' ') ? 1 : 0) };\n}\n\nconst MENTION_IN_TEXT = /(^|[\\s([{\"'`])@([\\w./\\-[\\]:]+)/g;\n\n/** The known items the message mentions, once each, in the order they appear. */\nexport function mentionedItems(text: string, items: ReadonlyArray<MentionItem>): MentionItem[] {\n const byToken = new Map(items.map((i) => [i.token, i] as const));\n const out: MentionItem[] = [];\n const seen = new Set<string>();\n for (const m of String(text || '').matchAll(MENTION_IN_TEXT)) {\n // A sentence may end right after the token (\"look at @/pricing.\").\n const raw = m[2];\n const token = byToken.has(raw) ? raw : raw.replace(/[.:,;!?\\]]+$/, '');\n const item = byToken.get(token);\n if (!item || seen.has(item.token)) continue;\n seen.add(item.token);\n out.push(item);\n }\n return out;\n}\n\nconst MAX_NOTED = 12;\n\n/** The hidden note for the agent (\"[Mentions] ...\"), or null when the message mentions nothing known. */\nexport function mentionNote(items: ReadonlyArray<MentionItem>): string | null {\n if (!items.length) return null;\n const parts = items.slice(0, MAX_NOTED).map((i) => (i.kind === 'page' ? `page ${i.token}` : `file ${i.token}`));\n const more = items.length > MAX_NOTED ? ` (and ${items.length - MAX_NOTED} more)` : '';\n return `[Mentions] The user points at: ${parts.join('; ')}${more}. \"@<path>\" in the message means these; open them first and keep the change to them unless the message asks for more.`;\n}\n"],"names":[],"mappings":"AA2BA,MAAM,UAAa,GAAA,cAAA;AACnB,MAAM,SAAY,GAAA,GAAA;AAMF,SAAA,kBAAA,CAAmB,MAAc,KAAoC,EAAA;AACnF,EAAM,MAAA,GAAA,GAAM,KAAK,GAAI,CAAA,CAAA,EAAG,KAAK,GAAI,CAAA,KAAA,EAAO,IAAK,CAAA,MAAM,CAAC,CAAA;AACpD,EAAA,IAAI,IAAI,GAAM,GAAA,CAAA;AACd,EAAA,OAAO,CAAK,IAAA,CAAA,IAAK,GAAM,GAAA,CAAA,IAAK,YAAY,CAAG,EAAA;AACzC,IAAM,MAAA,EAAA,GAAK,KAAK,CAAC,CAAA;AAC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A;AACnB,IAAA,GAAA,CAAI,KAAK,IAAI,CAAA;AAAA;AAEf,EAAO,OAAA,GAAA;AACT;AACA,MAAM,SAAY,GAAA,EAAA;AAGX,SAAS,YAAY,KAAkD,EAAA;AAC5E,EAAI,IAAA,CAAC,KAAM,CAAA,MAAA,EAAe,OAAA,IAAA;AAC1B,EAAA,MAAM,QAAQ,KAAM,CAAA,KAAA,CAAM,GAAG,SAAS,CAAA,CAAE,IAAI,CAAK,CAAA,KAAA,CAAA,CAAE,IAAS,KAAA,MAAA,GAAS,QAAQ,CAAE,CAAA,KAAK,KAAK,CAAQ,KAAA,EAAA,CAAA,CAAE,KAAK,CAAE,CAAA,CAAA;AAC1G,EAAM,MAAA,IAAA,GAAO,MAAM,MAAS,GAAA,SAAA,GAAY,SAAS,KAAM,CAAA,MAAA,GAAS,SAAS,CAAW,MAAA,CAAA,GAAA,EAAA;AACpF,EAAA,OAAO,kCAAkC,KAAM,CAAA,IAAA,CAAK,IAAI,CAAC,GAAG,IAAI,CAAA,qHAAA,CAAA;AAClE"}
@@ -0,0 +1,121 @@
1
+ function previewFrom(text) {
2
+ const m = /https?:\/\/\d{2,5}-([a-z0-9]{4,128})\.[a-z0-9.-]+/i.exec(text);
3
+ return m ? {
4
+ sandboxId: m[1].toLowerCase()
5
+ } : null;
6
+ }
7
+ const COPY_STATUS_ACTION = "WEBBUILDER_CLONE_WEBSITE_STATUS";
8
+ const PHASES = {
9
+ starting: "Starting",
10
+ setup: "Preparing the browser",
11
+ discover: "Reading the sitemap",
12
+ capture: "Visiting pages",
13
+ assets: "Downloading images, fonts and files",
14
+ write: "Writing the copy",
15
+ verify: "Comparing the copy with the original",
16
+ install: "Putting the copy in your project",
17
+ done: "Done",
18
+ failed: "Stopped"
19
+ };
20
+ const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
21
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : 0;
22
+ const str = (v) => typeof v === "string" ? v : "";
23
+ function hostOf(url) {
24
+ try {
25
+ return new URL(url).host.replace(/^www\./, "");
26
+ } catch (e) {
27
+ return url;
28
+ }
29
+ }
30
+ function pageLabel(url, title) {
31
+ const t = (title != null ? title : "").replace(/\s+/g, " ").trim();
32
+ if (t) {
33
+ const head = t.split(/\s+[|\u00b7\u2022\u2013\u2014-]\s+/)[0].trim();
34
+ return (head || t).slice(0, 80);
35
+ }
36
+ try {
37
+ const u = new URL(url);
38
+ const path = decodeURI(u.pathname).replace(/\/+$/, "");
39
+ return path || "/";
40
+ } catch (e) {
41
+ return url.slice(0, 80);
42
+ }
43
+ }
44
+ function page(v) {
45
+ if (typeof v === "string") return v ? {
46
+ url: v,
47
+ label: pageLabel(v)
48
+ } : null;
49
+ if (!isObj(v)) return null;
50
+ const url = str(v.url);
51
+ return url ? {
52
+ url,
53
+ label: pageLabel(url, str(v.title))
54
+ } : null;
55
+ }
56
+ const JPEG_DATA_URL = /^data:image\/jpeg;base64,[A-Za-z0-9+/]+=*$/;
57
+ function siteCopyView(data, prev) {
58
+ const d = isObj(data) ? data : {};
59
+ const statusRaw = str(d.status);
60
+ const status = statusRaw === "running" || statusRaw === "done" || statusRaw === "failed" ? statusRaw : "none";
61
+ const p = isObj(d.progress) ? d.progress : {};
62
+ const thumbId = Number.isInteger(d.thumbId) ? d.thumbId : null;
63
+ let thumb = prev && prev.jobId === (str(d.jobId) || null) ? prev.thumb : null;
64
+ if (isObj(d.thumb) && Number.isInteger(d.thumb.id) && JPEG_DATA_URL.test(str(d.thumb.dataUrl))) {
65
+ const url = str(d.thumb.url);
66
+ thumb = {
67
+ id: d.thumb.id,
68
+ url,
69
+ label: pageLabel(url, str(d.thumb.title)),
70
+ src: str(d.thumb.dataUrl)
71
+ };
72
+ }
73
+ const result = isObj(d.result) ? d.result : {};
74
+ const error = isObj(d.error) ? str(d.error.message) || null : null;
75
+ const pages = (v, max) => (Array.isArray(v) ? v : []).map(page).filter((x) => !!x).slice(0, max);
76
+ return {
77
+ status,
78
+ jobId: str(d.jobId) || null,
79
+ site: str(d.site) || hostOf(str(d.url)),
80
+ phase: status === "done" ? PHASES.done : status === "failed" ? PHASES.failed : PHASES[str(d.phase)] || PHASES.starting,
81
+ summary: str(d.summary),
82
+ elapsedSec: num(d.elapsedSec),
83
+ pagesDone: num(p.pagesDone),
84
+ pagesQueued: num(p.pagesQueued),
85
+ files: num(p.assets),
86
+ current: pages(d.current, 3),
87
+ recent: pages(d.recent, 6),
88
+ thumbId,
89
+ thumb,
90
+ matchPercent: typeof result.matchPercent === "number" ? result.matchPercent : null,
91
+ error
92
+ };
93
+ }
94
+ function copyCounts(v) {
95
+ const out = [`${v.pagesDone} page${v.pagesDone === 1 ? "" : "s"} copied`];
96
+ if (v.pagesQueued) out.push(`${v.pagesQueued} to go`);
97
+ if (v.files) out.push(`${v.files} file${v.files === 1 ? "" : "s"}`);
98
+ return out;
99
+ }
100
+ const COPY_LINE = /\bCopying\s+(\S+)[^\n]{0,160}?\blive preview\b[^\n]*/gi;
101
+ function copyLine(text) {
102
+ var _a;
103
+ let found = null;
104
+ for (const m of String(text || "").matchAll(COPY_LINE)) {
105
+ const sandboxId = (_a = previewFrom(m[0])) == null ? void 0 : _a.sandboxId;
106
+ if (!sandboxId) continue;
107
+ const site = m[1].replace(/^[`*_"'(]+|[`*_"'),.:;!?]+$/g, "").replace(/^https?:\/\//i, "").replace(/\/+$/, "");
108
+ found = {
109
+ sandboxId,
110
+ site
111
+ };
112
+ }
113
+ return found;
114
+ }
115
+ function copyPollIntervalMs(elapsedMs, status) {
116
+ if (status !== "running") return 5e3;
117
+ return elapsedMs < 3 * 6e4 ? 3e3 : 5e3;
118
+ }
119
+ function copyStatusUnavailable(error) {
120
+ return /unknown webbuilder action|not on its allow-list|unknown sandbox action|view access/i.test(error != null ? error : "");
121
+ }export{COPY_STATUS_ACTION,copyCounts,copyLine,copyPollIntervalMs,copyStatusUnavailable,pageLabel,siteCopyView};//# sourceMappingURL=siteCopy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"siteCopy.js","sources":["../../../../../src/features/webbuilder/web/chat/siteCopy.ts"],"sourcesContent":["/**\n * A website copy seen from the build view. Pure.\n *\n * \"Make resortifi.com here\": the agent copies a live site into the sandbox with yantra-webbuilder's\n * WEBBUILDER_CLONE_WEBSITE (1.1.0+), and one call waits minutes. The build view polls\n * WEBBUILDER_CLONE_WEBSITE_STATUS and shows the page being copied (a small picture of it), the counts\n * and the newest pages, so the person sees it working instead of a spinner.\n *\n * The page cannot see the agent's tool params (in project mode every step reads\n * WEBBUILDER_PROJECT_ACTION), so it learns about a copy from the agent's own line, which design-pro\n * makes exact: \"Copying resortifi.com into the live preview (preview `https://3000-<sandbox>…`)\".\n */\n/** The sandbox id of a live preview address in a line (web `agentBuild.previewFrom`). */\nfunction previewFrom(text: string): { sandboxId: string } | null {\n const m = /https?:\\/\\/\\d{2,5}-([a-z0-9]{4,128})\\.[a-z0-9.-]+/i.exec(text);\n return m ? { sandboxId: m[1].toLowerCase() } : null;\n}\n\nexport const COPY_STATUS_ACTION = 'WEBBUILDER_CLONE_WEBSITE_STATUS' as const;\n\nexport type SiteCopyStatus = 'none' | 'running' | 'done' | 'failed';\n\nexport interface SiteCopyPage {\n url: string;\n /** \"Rooms & Suites\", else the path (\"/rooms\"). */\n label: string;\n}\n\nexport interface SiteCopyView {\n status: SiteCopyStatus;\n jobId: string | null;\n /** \"resortifi.com\" */\n site: string;\n /** \"Visiting pages\", \"Downloading images, fonts and files\"... */\n phase: string;\n summary: string;\n elapsedSec: number;\n pagesDone: number;\n pagesQueued: number;\n files: number;\n /** Pages being copied right now. */\n current: SiteCopyPage[];\n /** Newest first. */\n recent: SiteCopyPage[];\n /** Id of the newest picture the connector has (sent back as sinceThumb). */\n thumbId: number | null;\n /** The newest picture received so far (kept between polls that leave it out). */\n thumb: (SiteCopyPage & { id: number; src: string }) | null;\n matchPercent: number | null;\n error: string | null;\n}\n\nconst PHASES: Record<string, string> = {\n starting: 'Starting',\n setup: 'Preparing the browser',\n discover: 'Reading the sitemap',\n capture: 'Visiting pages',\n assets: 'Downloading images, fonts and files',\n write: 'Writing the copy',\n verify: 'Comparing the copy with the original',\n install: 'Putting the copy in your project',\n done: 'Done',\n failed: 'Stopped',\n};\n\nconst isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v);\nconst num = (v: unknown): number => (typeof v === 'number' && Number.isFinite(v) ? v : 0);\nconst str = (v: unknown): string => (typeof v === 'string' ? v : '');\n\nfunction hostOf(url: string): string {\n try {\n return new URL(url).host.replace(/^www\\./, '');\n } catch {\n return url;\n }\n}\n\n/** A page as people name it: its title before \" | Brand\", else its path. */\nexport function pageLabel(url: string, title?: string | null): string {\n const t = (title ?? '').replace(/\\s+/g, ' ').trim();\n if (t) {\n const head = t.split(/\\s+[|\\u00b7\\u2022\\u2013\\u2014-]\\s+/)[0].trim();\n return (head || t).slice(0, 80);\n }\n try {\n const u = new URL(url);\n const path = decodeURI(u.pathname).replace(/\\/+$/, '');\n return path || '/';\n } catch {\n return url.slice(0, 80);\n }\n}\n\nfunction page(v: unknown): SiteCopyPage | null {\n if (typeof v === 'string') return v ? { url: v, label: pageLabel(v) } : null;\n if (!isObj(v)) return null;\n const url = str(v.url);\n return url ? { url, label: pageLabel(url, str(v.title)) } : null;\n}\n\nconst JPEG_DATA_URL = /^data:image\\/jpeg;base64,[A-Za-z0-9+/]+=*$/;\n\n/** The status answer as the build view's model; `prev` keeps the picture the answer leaves out. */\nexport function siteCopyView(data: unknown, prev: SiteCopyView | null): SiteCopyView {\n const d = isObj(data) ? data : {};\n const statusRaw = str(d.status);\n const status: SiteCopyStatus =\n statusRaw === 'running' || statusRaw === 'done' || statusRaw === 'failed' ? statusRaw : 'none';\n const p = isObj(d.progress) ? d.progress : {};\n const thumbId = Number.isInteger(d.thumbId) ? (d.thumbId as number) : null;\n let thumb = prev && prev.jobId === (str(d.jobId) || null) ? prev.thumb : null;\n if (isObj(d.thumb) && Number.isInteger(d.thumb.id) && JPEG_DATA_URL.test(str(d.thumb.dataUrl))) {\n const url = str(d.thumb.url);\n thumb = { id: d.thumb.id as number, url, label: pageLabel(url, str(d.thumb.title)), src: str(d.thumb.dataUrl) };\n }\n const result = isObj(d.result) ? d.result : {};\n const error = isObj(d.error) ? str(d.error.message) || null : null;\n const pages = (v: unknown, max: number) =>\n (Array.isArray(v) ? v : [])\n .map(page)\n .filter((x): x is SiteCopyPage => !!x)\n .slice(0, max);\n return {\n status,\n jobId: str(d.jobId) || null,\n site: str(d.site) || hostOf(str(d.url)),\n phase:\n status === 'done'\n ? PHASES.done\n : status === 'failed'\n ? PHASES.failed\n : PHASES[str(d.phase)] || PHASES.starting,\n summary: str(d.summary),\n elapsedSec: num(d.elapsedSec),\n pagesDone: num(p.pagesDone),\n pagesQueued: num(p.pagesQueued),\n files: num(p.assets),\n current: pages(d.current, 3),\n recent: pages(d.recent, 6),\n thumbId,\n thumb,\n matchPercent: typeof result.matchPercent === 'number' ? result.matchPercent : null,\n error,\n };\n}\n\n/** \"6 pages copied\", \"9 to go\", \"160 files\": the counts worth showing. */\nexport function copyCounts(v: Pick<SiteCopyView, 'pagesDone' | 'pagesQueued' | 'files'>): string[] {\n const out = [`${v.pagesDone} page${v.pagesDone === 1 ? '' : 's'} copied`];\n if (v.pagesQueued) out.push(`${v.pagesQueued} to go`);\n if (v.files) out.push(`${v.files} file${v.files === 1 ? '' : 's'}`);\n return out;\n}\n\nconst COPY_LINE = /\\bCopying\\s+(\\S+)[^\\n]{0,160}?\\blive preview\\b[^\\n]*/gi;\n\n/**\n * The site and sandbox of the agent's latest copy line (\"Copying resortifi.com into the live preview\n * (preview `https://3000-<sandbox>…`)\"); null when it said none.\n */\nexport function copyLine(text: string | null | undefined): { sandboxId: string; site: string } | null {\n let found: { sandboxId: string; site: string } | null = null;\n for (const m of String(text || '').matchAll(COPY_LINE)) {\n const sandboxId = previewFrom(m[0])?.sandboxId;\n if (!sandboxId) continue;\n const site = m[1]\n .replace(/^[`*_\"'(]+|[`*_\"'),.:;!?]+$/g, '')\n .replace(/^https?:\\/\\//i, '')\n .replace(/\\/+$/, '');\n found = { sandboxId, site };\n }\n return found;\n}\n\n/** The turn ran (or runs) a website copy directly (not through the project proxy): its step's label names the action. */\nexport function copyStepSeen(steps: ReadonlyArray<{ label?: string; detail?: string }>): boolean {\n return steps.some((st) => /(?:^|_)CLONE_WEBSITE\\b/.test(`${st.label ?? ''} ${st.detail ?? ''}`));\n}\n\n/** Poll fast while pages are being copied, slower while waiting for the copy to start or after 3 minutes. */\nexport function copyPollIntervalMs(elapsedMs: number, status: SiteCopyStatus | undefined): number {\n if (status !== 'running') return 5_000;\n return elapsedMs < 3 * 60_000 ? 3_000 : 5_000;\n}\n\n/** A status answer that says the action is not there (older connector or server): stop asking. */\nexport function copyStatusUnavailable(error: string | null | undefined): boolean {\n return /unknown webbuilder action|not on its allow-list|unknown sandbox action|view access/i.test(error ?? '');\n}\n"],"names":[],"mappings":"AAaA,SAAS,YAAY,IAEZ,EAAA;AACP,EAAM,MAAA,CAAA,GAAI,oDAAqD,CAAA,IAAA,CAAK,IAAI,CAAA;AACxE,EAAA,OAAO,CAAI,GAAA;AAAA,IACT,SAAW,EAAA,CAAA,CAAE,CAAC,CAAA,CAAE,WAAY;AAAA,GAC1B,GAAA,IAAA;AACN;AACO,MAAM,kBAAqB,GAAA;AAiClC,MAAM,MAAiC,GAAA;AAAA,EACrC,QAAU,EAAA,UAAA;AAAA,EACV,KAAO,EAAA,uBAAA;AAAA,EACP,QAAU,EAAA,qBAAA;AAAA,EACV,OAAS,EAAA,gBAAA;AAAA,EACT,MAAQ,EAAA,qCAAA;AAAA,EACR,KAAO,EAAA,kBAAA;AAAA,EACP,MAAQ,EAAA,sCAAA;AAAA,EACR,OAAS,EAAA,kCAAA;AAAA,EACT,IAAM,EAAA,MAAA;AAAA,EACN,MAAQ,EAAA;AACV,CAAA;AACA,MAAM,KAAQ,GAAA,CAAC,CAA6C,KAAA,CAAC,CAAC,CAAA,IAAK,OAAO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AAA,IAAA,EAAA;AAkKE,EAAA,IAAI,KAGO,GAAA,IAAA;AACX,EAAA,KAAA,MAAW,KAAK,MAAO,CAAA,IAAA,IAAQ,EAAE,CAAE,CAAA,QAAA,CAAS,SAAS,CAAG,EAAA;AACtD,IAAA,MAAM,aAAY,EAAY,GAAA,WAAA,CAAA,CAAA,CAAE,CAAC,CAAC,MAAhB,IAAmB,GAAA,MAAA,GAAA,EAAA,CAAA,SAAA;AACrC,IAAA,IAAI,CAAC,SAAW,EAAA;AAChB,IAAA,MAAM,IAAO,GAAA,CAAA,CAAE,CAAC,CAAA,CAAE,QAAQ,8BAAgC,EAAA,EAAE,CAAE,CAAA,OAAA,CAAQ,eAAiB,EAAA,EAAE,CAAE,CAAA,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAC7G,IAAQ,KAAA,GAAA;AAAA,MACN,SAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEF,EAAO,OAAA,KAAA;AACT;AAWgB,SAAA,kBAAA,CAAmB,WAAmB,MAA4C,EAAA;AAChG,EAAI,IAAA,MAAA,KAAW,WAAkB,OAAA,GAAA;AACjC,EAAO,OAAA,SAAA,GAAY,CAAI,GAAA,GAAA,GAAS,GAAQ,GAAA,GAAA;AAC1C;AAGO,SAAS,sBAAsB,KAA2C,EAAA;AAC/E,EAAO,OAAA,qFAAA,CAAsF,IAAK,CAAA,KAAA,IAAA,IAAA,GAAA,KAAA,GAAS,EAAE,CAAA;AAC/G"}
@@ -0,0 +1,30 @@
1
+ const EDITABLE_IMAGE = /\.(png|jpe?g|webp|avif)$/i;
2
+ const MAX_IMAGE_EDIT_BYTES = 2e6;
3
+ const IMAGE_EDIT_PROMPT_MAX = 400;
4
+ function isEditableImagePath(path) {
5
+ return EDITABLE_IMAGE.test(String(path || ""));
6
+ }
7
+ function imageMimeFor(path) {
8
+ const ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
9
+ return ext === "jpg" || ext === "jpeg" ? "image/jpeg" : `image/${ext}`;
10
+ }
11
+ const baseName = (path) => path.slice(path.lastIndexOf("/") + 1);
12
+ function maskFileName(path) {
13
+ const base = baseName(path);
14
+ const dot = base.lastIndexOf(".");
15
+ return `${dot > 0 ? base.slice(0, dot) : base}-mask.png`;
16
+ }
17
+ function imageEditTurn(input) {
18
+ const path = input.path.trim();
19
+ const words = input.prompt.replace(/\s+/g, " ").trim().slice(0, IMAGE_EDIT_PROMPT_MAX);
20
+ if (!isEditableImagePath(path)) return null;
21
+ if (input.mode === "change" && !words) return null;
22
+ const name = baseName(path);
23
+ const text = input.mode === "change" ? `Edit ${name}: ${words}` : `Remove the painted area from ${name}${words ? ` (${words})` : ""}`;
24
+ const action = input.mode === "change" ? `yantra-image-generation YANTRA_IMAGE_INPAINT {"imageUrl": <first attachment>, "maskUrl": <second attachment>, "prompt": the user's words}` : `yantra-image-generation YANTRA_IMAGE_ERASE {"imageUrl": <first attachment>, "maskUrl": <second attachment>}`;
25
+ const note = `[Image edit] The user painted an area of ${path} in this site and wants it ${input.mode === "change" ? "changed" : "removed"}. The first attachment is that image as it is now; the second is the mask (white = the painted area, black = keep). Run ${action}, then download the result and write it to ${path} in the sandbox, in the same format and size (convert or resize the result if needed). Change nothing else. Reply when the page shows the new image.`;
26
+ return {
27
+ text,
28
+ note
29
+ };
30
+ }export{IMAGE_EDIT_PROMPT_MAX,MAX_IMAGE_EDIT_BYTES,imageEditTurn,imageMimeFor,isEditableImagePath,maskFileName};//# sourceMappingURL=imageEdit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageEdit.js","sources":["../../../../../src/features/webbuilder/web/code/imageEdit.ts"],"sourcesContent":["/**\n * Edit an image of the site with AI: paint the area, say what it should become (or remove it). Pure.\n *\n * The code view shows the image; the person paints a mask over it. The turn carries the original image and\n * the mask as attachments (uploaded, so the image tools can fetch them) and a hidden \"[Image edit]\" note:\n * run yantra-image-generation INPAINT (change the area) or ERASE (remove it) with the mask, then write the\n * result back to the same file.\n */\n\nexport type ImageEditMode = 'change' | 'remove';\n\n/** Formats the image tools read and write; others (svg, ico, gif) are left out. */\nconst EDITABLE_IMAGE = /\\.(png|jpe?g|webp|avif)$/i;\nexport const MAX_IMAGE_EDIT_BYTES = 2_000_000;\nexport const IMAGE_EDIT_PROMPT_MAX = 400;\n\nexport function isEditableImagePath(path: string | null | undefined): boolean {\n return EDITABLE_IMAGE.test(String(path || ''));\n}\n\nexport function imageMimeFor(path: string): string {\n const ext = path.slice(path.lastIndexOf('.') + 1).toLowerCase();\n return ext === 'jpg' || ext === 'jpeg' ? 'image/jpeg' : `image/${ext}`;\n}\n\nconst baseName = (path: string) => path.slice(path.lastIndexOf('/') + 1);\n\n/** \"hero.jpg\" -> \"hero-mask.png\" (the mask is always a PNG). */\nexport function maskFileName(path: string): string {\n const base = baseName(path);\n const dot = base.lastIndexOf('.');\n return `${dot > 0 ? base.slice(0, dot) : base}-mask.png`;\n}\n\n/** The visible message and the hidden note for one edit; null when there is nothing to send. */\nexport function imageEditTurn(input: {\n path: string;\n mode: ImageEditMode;\n prompt: string;\n}): { text: string; note: string } | null {\n const path = input.path.trim();\n const words = input.prompt.replace(/\\s+/g, ' ').trim().slice(0, IMAGE_EDIT_PROMPT_MAX);\n if (!isEditableImagePath(path)) return null;\n if (input.mode === 'change' && !words) return null;\n const name = baseName(path);\n const text =\n input.mode === 'change'\n ? `Edit ${name}: ${words}`\n : `Remove the painted area from ${name}${words ? ` (${words})` : ''}`;\n const action =\n input.mode === 'change'\n ? `yantra-image-generation YANTRA_IMAGE_INPAINT {\"imageUrl\": <first attachment>, \"maskUrl\": <second attachment>, \"prompt\": the user's words}`\n : `yantra-image-generation YANTRA_IMAGE_ERASE {\"imageUrl\": <first attachment>, \"maskUrl\": <second attachment>}`;\n const note =\n `[Image edit] The user painted an area of ${path} in this site and wants it ${input.mode === 'change' ? 'changed' : 'removed'}. ` +\n `The first attachment is that image as it is now; the second is the mask (white = the painted area, black = keep). ` +\n `Run ${action}, then download the result and write it to ${path} in the sandbox, in the same format and size ` +\n '(convert or resize the result if needed). Change nothing else. Reply when the page shows the new image.';\n return { text, note };\n}\n"],"names":[],"mappings":"AAYA,MAAM,cAAiB,GAAA,2BAAA;AAChB,MAAM,oBAAuB,GAAA;AAC7B,MAAM,qBAAwB,GAAA;AAC9B,SAAS,oBAAoB,IAA0C,EAAA;AAC5E,EAAA,OAAO,cAAe,CAAA,IAAA,CAAK,MAAO,CAAA,IAAA,IAAQ,EAAE,CAAC,CAAA;AAC/C;AACO,SAAS,aAAa,IAAsB,EAAA;AACjD,EAAM,MAAA,GAAA,GAAM,KAAK,KAAM,CAAA,IAAA,CAAK,YAAY,GAAG,CAAA,GAAI,CAAC,CAAA,CAAE,WAAY,EAAA;AAC9D,EAAA,OAAO,QAAQ,KAAS,IAAA,GAAA,KAAQ,MAAS,GAAA,YAAA,GAAe,SAAS,GAAG,CAAA,CAAA;AACtE;AACA,MAAM,QAAA,GAAW,CAAC,IAAiB,KAAA,IAAA,CAAK,MAAM,IAAK,CAAA,WAAA,CAAY,GAAG,CAAA,GAAI,CAAC,CAAA;AAGhE,SAAS,aAAa,IAAsB,EAAA;AACjD,EAAM,MAAA,IAAA,GAAO,SAAS,IAAI,CAAA;AAC1B,EAAM,MAAA,GAAA,GAAM,IAAK,CAAA,WAAA,CAAY,GAAG,CAAA;AAChC,EAAO,OAAA,CAAA,EAAG,MAAM,CAAI,GAAA,IAAA,CAAK,MAAM,CAAG,EAAA,GAAG,IAAI,IAAI,CAAA,SAAA,CAAA;AAC/C;AAGO,SAAS,cAAc,KAOrB,EAAA;AACP,EAAM,MAAA,IAAA,GAAO,KAAM,CAAA,IAAA,CAAK,IAAK,EAAA;AAC7B,EAAM,MAAA,KAAA,GAAQ,KAAM,CAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAE,IAAK,EAAA,CAAE,KAAM,CAAA,CAAA,EAAG,qBAAqB,CAAA;AACrF,EAAA,IAAI,CAAC,mBAAA,CAAoB,IAAI,CAAA,EAAU,OAAA,IAAA;AACvC,EAAA,IAAI,KAAM,CAAA,IAAA,KAAS,QAAY,IAAA,CAAC,OAAc,OAAA,IAAA;AAC9C,EAAM,MAAA,IAAA,GAAO,SAAS,IAAI,CAAA;AAC1B,EAAA,MAAM,OAAO,KAAM,CAAA,IAAA,KAAS,QAAW,GAAA,CAAA,KAAA,EAAQ,IAAI,CAAK,EAAA,EAAA,KAAK,CAAK,CAAA,GAAA,CAAA,6BAAA,EAAgC,IAAI,CAAG,EAAA,KAAA,GAAQ,CAAK,EAAA,EAAA,KAAK,MAAM,EAAE,CAAA,CAAA;AACnI,EAAA,MAAM,MAAS,GAAA,KAAA,CAAM,IAAS,KAAA,QAAA,GAAW,CAA8I,yIAAA,CAAA,GAAA,CAAA,2GAAA,CAAA;AACvL,EAAA,MAAM,IAAO,GAAA,CAAA,yCAAA,EAA4C,IAAI,CAAA,2BAAA,EAA8B,KAAM,CAAA,IAAA,KAAS,QAAW,GAAA,SAAA,GAAY,SAAS,CAAA,wHAAA,EAAqI,MAAM,CAAA,2CAAA,EAA8C,IAAI,CAAA,oJAAA,CAAA;AACvU,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA;AAAA,GACF;AACF"}
@@ -0,0 +1,26 @@
1
+ function str(raw, max = 200) {
2
+ return typeof raw === "string" ? raw.trim().slice(0, max) : "";
3
+ }
4
+ function asObject(raw) {
5
+ return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : null;
6
+ }
7
+ function isoOrNull(raw) {
8
+ const s = str(raw, 40);
9
+ return s && !Number.isNaN(Date.parse(s)) ? s : null;
10
+ }
11
+ function toLinkedDesign(raw) {
12
+ const r = asObject(raw);
13
+ if (!r) return null;
14
+ const id = str(r.id, 120);
15
+ const designVersion = str(r.designVersion, 64);
16
+ const at = isoOrNull(r.at);
17
+ if (!id || !designVersion || !at) return null;
18
+ return {
19
+ id,
20
+ title: str(r.title, 120) || "Design",
21
+ designVersion,
22
+ projectVersion: str(r.projectVersion, 32),
23
+ direction: r.direction === "pushed" ? "pushed" : "pulled",
24
+ at
25
+ };
26
+ }export{toLinkedDesign};//# sourceMappingURL=linkedDesign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linkedDesign.js","sources":["../../../../../src/features/webbuilder/web/design/linkedDesign.ts"],"sourcesContent":["/**\n * A project bound to a design (the yantra-web-design studio). Pure.\n *\n * A design and a Web Builder project hold the same thing in the same currency:\n * one self-contained HTML document. So the two can be bound rather than\n * copy-pasted - the design opens here as a real project, and what is built\n * here goes back to the design board, which is what \"connected\" has to mean if\n * the design is to stay the design and not become a dead picture of one.\n *\n * TWO WAYS MEANS TWO WRITERS, so the whole file is really about one question:\n * who moved since the last time the two sides agreed? The link remembers both\n * versions at that moment. The design's is the connector's own token (a hash of\n * the document, handed back by every design read). The project's is a local\n * fingerprint of the html we last exchanged - it is compared only with itself,\n * so it needs no agreement with anyone, only stability.\n *\n * Nothing here decides FOR the user when both have moved. It names what\n * happened and what each way out costs; a merge nobody asked for is how a\n * design board quietly loses an afternoon.\n */\n\nexport const WEB_DESIGN_CONNECTOR_ID = 'yantra-web-design';\nexport const DESIGN_SAVE_ACTION = 'YANTRA_DESIGN_SAVE';\nexport const DESIGN_GET_ACTION = 'YANTRA_DESIGN_GET_DESIGN';\nexport const DESIGN_LIST_ACTION = 'YANTRA_DESIGN_LIST_DESIGNS';\n\n/** How many designs the picker asks for. */\nexport const DESIGN_LIST_LIMIT = 24;\n\n/** What the two sides agreed on, and when. Stored in the project's settings. */\nexport interface LinkedDesign {\n /** The design id in the user's library. */\n id: string;\n title: string;\n /** The design's own version (connector token) at the last exchange. */\n designVersion: string;\n /** Our fingerprint of the html at the last exchange. */\n projectVersion: string;\n /** Which way that exchange went. */\n direction: 'pulled' | 'pushed';\n at: string;\n}\n\n/** One design as the picker and the seed need it. */\nexport interface DesignRead {\n id: string;\n title: string;\n html: string;\n version: string;\n systemId: string;\n templateId: string;\n updatedAt: string;\n}\n\nfunction str(raw: unknown, max = 200): string {\n return typeof raw === 'string' ? raw.trim().slice(0, max) : '';\n}\n\nfunction asObject(raw: unknown): Record<string, unknown> | null {\n return raw && typeof raw === 'object' && !Array.isArray(raw) ? (raw as Record<string, unknown>) : null;\n}\n\nfunction isoOrNull(raw: unknown): string | null {\n const s = str(raw, 40);\n return s && !Number.isNaN(Date.parse(s)) ? s : null;\n}\n\n/**\n * Our own fingerprint of a project's html - FNV-1a, 32 bits, hex.\n *\n * Deliberately not the connector's sha-256: this value is only ever compared\n * with an earlier value of itself, it must work in a browser with no secure\n * context and no await, and a cryptographic hash would promise a strength that\n * nothing here relies on.\n */\nexport function projectFingerprint(html: string | null | undefined): string {\n let h = 0x811c9dc5;\n const s = html ?? '';\n for (let i = 0; i < s.length; i += 1) {\n h ^= s.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0).toString(16).padStart(8, '0');\n}\n\n/** A stored link, or null when the project is not bound to a design. */\nexport function toLinkedDesign(raw: unknown): LinkedDesign | null {\n const r = asObject(raw);\n if (!r) return null;\n const id = str(r.id, 120);\n const designVersion = str(r.designVersion, 64);\n const at = isoOrNull(r.at);\n if (!id || !designVersion || !at) return null;\n return {\n id,\n title: str(r.title, 120) || 'Design',\n designVersion,\n projectVersion: str(r.projectVersion, 32),\n direction: r.direction === 'pushed' ? 'pushed' : 'pulled',\n at,\n };\n}\n\n/** The link to store after an exchange went through. */\nexport function linkAfter(opts: {\n design: Pick<DesignRead, 'id' | 'title'>;\n designVersion: string;\n html: string;\n direction: LinkedDesign['direction'];\n now?: number;\n}): LinkedDesign {\n return {\n id: opts.design.id,\n title: opts.design.title || 'Design',\n designVersion: opts.designVersion,\n projectVersion: projectFingerprint(opts.html),\n direction: opts.direction,\n at: new Date(opts.now ?? Date.now()).toISOString(),\n };\n}\n\n/** One design out of a GET_DESIGN / LIST_DESIGNS reply. */\nexport function parseDesignRead(raw: unknown): DesignRead | null {\n const r = asObject(raw);\n if (!r) return null;\n const id = str(r.id, 120);\n const html = typeof r.html === 'string' ? r.html : '';\n const version = str(r.version, 64);\n if (!id || !html || !version) return null;\n return {\n id,\n title: str(r.title, 120) || 'Design',\n html,\n version,\n systemId: str(r.systemId, 80),\n templateId: str(r.templateId, 80),\n updatedAt: isoOrNull(r.updatedAt) ?? '',\n };\n}\n\n/** The gallery, newest first, dropping rows that are not readable designs. */\nexport function parseDesignList(raw: unknown): DesignRead[] {\n const r = asObject(raw);\n const rows = Array.isArray(r?.designs) ? r!.designs : [];\n return rows.map(parseDesignRead).filter((d): d is DesignRead => d !== null);\n}\n\n/**\n * The note that rides the seeding turn. The HTML goes with it as an attachment;\n * this tells the agent what it is looking at and what to do with it.\n */\nexport function designSeedNote(design: Pick<DesignRead, 'id' | 'title'>): string {\n // One clean line: the note's own shape is quotes and parentheses, so a\n // title carrying either must not be able to break it.\n const title = design.title.replace(/[\"\\\\]/g, '').replace(/\\s+/g, ' ').trim() || 'Design';\n return (\n `[Design] \"${title}\" (design ${design.id}): the attached HTML is the design this site is built from. ` +\n 'Match its layout, spacing, type and colours, and keep its copy. It is one self-contained document - ' +\n 'split it into the pages and components the site needs, but nothing in it is a placeholder unless it says so.'\n );\n}\n\n/** The user's bubble for that turn. */\nexport function designSeedMessage(design: Pick<DesignRead, 'title'>): string {\n return `Build this site from my design \"${design.title || 'Design'}\".`;\n}\n\n/** YANTRA_DESIGN_SAVE params for pushing the project's page back. */\nexport function pushParams(opts: {\n link: LinkedDesign | null;\n html: string;\n title?: string;\n /** Omit to force the write (the user said to overwrite). */\n guard?: boolean;\n}): Record<string, unknown> {\n const params: Record<string, unknown> = { html: opts.html };\n if (opts.link) {\n params.id = opts.link.id;\n if (opts.guard !== false) params.expectVersion = opts.link.designVersion;\n }\n const title = str(opts.title, 120);\n if (title) params.title = title;\n return params;\n}\n\nexport type PushResult =\n | { ok: true; id: string; version: string; updatedAt: string }\n | { ok: false; stale: boolean; message: string };\n\nconst PUSH_FAILED = 'The design could not be saved.';\n\n/** What SAVE answered. A refusal over `expectVersion` is a stale push, not a failure to write. */\nexport function parsePushAnswer(raw: unknown, error?: unknown): PushResult {\n const message = str(typeof error === 'string' ? error : asObject(error)?.message, 400);\n if (message) return { ok: false, stale: /changed since you read it/i.test(message), message };\n const r = asObject(raw);\n const id = str(r?.id, 120);\n const version = str(r?.version, 64);\n if (!r || !id || !version) return { ok: false, stale: false, message: PUSH_FAILED };\n return { ok: true, id, version, updatedAt: isoOrNull(r.updatedAt) ?? new Date().toISOString() };\n}\n\n/** Who has moved since the two sides last agreed. */\nexport type Drift = 'unlinked' | 'same' | 'design-moved' | 'project-moved' | 'both-moved';\n\nexport function driftOf(opts: {\n link: LinkedDesign | null;\n /** The design's version as the library reports it now; null when it could not be read. */\n designVersion: string | null;\n /** The project's page as it stands now. */\n html: string | null | undefined;\n}): Drift {\n const { link } = opts;\n if (!link) return 'unlinked';\n // An unreadable design is not a moved one - saying \"it changed\" because a\n // request failed would send the user to resolve a conflict that is not there.\n const designMoved = opts.designVersion !== null && opts.designVersion !== link.designVersion;\n const projectMoved = projectFingerprint(opts.html) !== link.projectVersion;\n if (designMoved && projectMoved) return 'both-moved';\n if (designMoved) return 'design-moved';\n if (projectMoved) return 'project-moved';\n return 'same';\n}\n\n/** What the user is told, in their own terms. Empty when there is nothing to say. */\nexport function driftNote(drift: Drift, title: string): string {\n const name = title.trim() || 'the design';\n switch (drift) {\n case 'design-moved':\n return `\"${name}\" changed on the design board since this site was built from it. Pull it in to build from the new version - what is here now stays until you do.`;\n case 'project-moved':\n return `This site has changed since \"${name}\" was last written. Push it back when you want the design board to show what is here.`;\n case 'both-moved':\n return `Both have changed since they were last in step: \"${name}\" moved on the design board, and this site moved here. Pulling replaces what is here; pushing replaces what is on the board. There is no merge - pick the one you want to keep.`;\n default:\n return '';\n }\n}\n"],"names":[],"mappings":"AAqDA,SAAS,GAAA,CAAI,GAAc,EAAA,GAAA,GAAM,GAAa,EAAA;AAC5C,EAAO,OAAA,OAAO,QAAQ,QAAW,GAAA,GAAA,CAAI,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inkKey(c) {
2
+ return (c == null ? void 0 : c.channelId) || (c == null ? void 0 : c.agentChannelId) || (c == null ? void 0 : c.sandboxId) || null;
3
+ }export{buildLinkKey};//# sourceMappingURL=buildLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildLink.js","sources":["../../../../../src/features/webbuilder/web/project/buildLink.ts"],"sourcesContent":["/**\n * The open build in the URL (`?build=`): the project's channel when it has one, so a reload or a shared\n * link survives the agent moving the project to a new sandbox; a sandbox id from an older link still\n * finds its project through the moves this browser saw. Pure.\n */\nimport type { WebBuilderArtifact } from '../types';\nimport type { KeyValueStore } from '../state/storageKeys';\nimport { storageKeys } from '../state/storageKeys';\n\nconst MAX_MOVES = 100;\n\ntype BuildIds = Pick<WebBuilderArtifact, 'channelId' | 'agentChannelId' | 'sandboxId'>;\n\n/** The id a build link names: its channel (stable across sandbox moves), else its sandbox. */\nexport function buildLinkKey(c: BuildIds | null | undefined): string | null {\n return c?.channelId || c?.agentChannelId || c?.sandboxId || null;\n}\n\nfunction readMoves(store: KeyValueStore | null): Record<string, string> {\n try {\n const v = JSON.parse(store?.getItem(storageKeys.sandboxMoves()) ?? '{}');\n return v && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, string>) : {};\n } catch {\n return {};\n }\n}\n\n/** A project left `previousSandboxId` for another sandbox: remember which project it was. */\nexport function rememberSandboxMove(\n store: KeyValueStore | null,\n previousSandboxId: string | null | undefined,\n channelId: string | null | undefined,\n): void {\n const from = String(previousSandboxId || '').trim();\n const to = String(channelId || '').trim();\n if (!from || !to || from === to) return;\n const moves = readMoves(store);\n if (moves[from] === to) return;\n delete moves[from];\n moves[from] = to;\n const kept = Object.entries(moves).slice(-MAX_MOVES);\n try {\n store?.setItem(storageKeys.sandboxMoves(), JSON.stringify(Object.fromEntries(kept)));\n } catch {\n /* storage full or blocked: old links just fall back to Home */\n }\n}\n\nexport function projectForSandbox(store: KeyValueStore | null, sandboxId: string | null | undefined): string | null {\n const id = String(sandboxId || '').trim();\n return (id && readMoves(store)[id]) || null;\n}\n\n/** The build a link names: by channel or sandbox, else the project an old sandbox id moved to. */\nexport function buildForLink<T extends BuildIds>(\n builds: readonly T[],\n want: string | null | undefined,\n movedTo: (sandboxId: string) => string | null,\n): T | null {\n const id = String(want || '').trim();\n if (!id) return null;\n const direct = builds.find((c) => c.channelId === id || c.agentChannelId === id || c.sandboxId === id);\n if (direct) return direct;\n const project = movedTo(id);\n return project ? (builds.find((c) => c.channelId === project || c.agentChannelId === project) ?? null) : null;\n}\n\n/** Board pages a `?build=` link may page through looking for its build before it gives up. */\nexport const BUILD_LINK_MAX_PAGES = 5;\n\nexport type BuildLinkStep = 'open' | 'wait' | 'load-more' | 'not-found';\n\n/**\n * What a pending `?build=` link does next. It never waits on a board that has settled: it pages on while\n * more builds exist (bounded), then says the build isn't there. A failed load keeps waiting, since the\n * board shows its own error with Retry and the link may still match after it.\n */\nexport function buildLinkStep(o: {\n matched: boolean;\n loading: boolean;\n pagesSettled: number;\n hasMore: boolean;\n error: boolean;\n maxPages?: number;\n}): BuildLinkStep {\n if (o.matched) return 'open';\n if (o.loading || o.pagesSettled === 0 || o.error) return 'wait';\n if (o.hasMore && o.pagesSettled < (o.maxPages ?? BUILD_LINK_MAX_PAGES)) return 'load-more';\n return 'not-found';\n}\n\n/**\n * The sandbox moves the board's cards made since the last look: a project's card that now shows another sandbox\n * left the previous one (`[previous, channel]` pairs), whatever moved it (the server's current build, a restore,\n * a reply). `seen` (channel -> sandbox) is updated in place. Pure apart from that map.\n */\nexport function cardSandboxMoves(\n seen: Map<string, string>,\n cards: ReadonlyArray<BuildIds>,\n): Array<[previousSandboxId: string, channelId: string]> {\n const moves: Array<[string, string]> = [];\n for (const c of cards) {\n const channel = c.channelId || c.agentChannelId;\n const sandbox = c.sandboxId;\n if (!channel || !sandbox) continue;\n const before = seen.get(channel);\n if (before && before !== sandbox) moves.push([before, channel]);\n seen.set(channel, sandbox);\n }\n return moves;\n}\n"],"names":[],"mappings":"AAYO,SAAS,aAAa,CAA+C,EAAA;AAC1E,EAAA,OAAA,CAAO,CAAG,IAAA,IAAA,GAAA,MAAA,GAAA,CAAA,CAAA,SAAA,MAAa,CAAG,IAAA,IAAA,GAAA,MAAA,GAAA,CAAA,CAAA,cAAA,CAAA,KAAkB,uBAAG,SAAa,CAAA,IAAA,IAAA;AAC9D"}
@@ -0,0 +1,57 @@
1
+ const DRAFT_NAME_MAX = 60;
2
+ const MAX_OPEN_DRAFTS = 5;
3
+ const DRAFT_ID_RE = /^d_[A-Za-z0-9_-]{4,64}$/;
4
+ const SANDBOX_ID_RE = /^[A-Za-z0-9_-]{4,128}$/;
5
+ const SHA_RE = /^[a-f0-9]{7,40}$/i;
6
+ function normalizeDraftName(raw) {
7
+ if (typeof raw !== "string") return null;
8
+ const name = raw.replace(/[\u0000-\u001F\u007F]/g, " ").replace(/\s+/g, " ").trim().slice(0, DRAFT_NAME_MAX);
9
+ return name || null;
10
+ }
11
+ const httpsOrNull = (raw) => {
12
+ if (typeof raw !== "string") return null;
13
+ try {
14
+ const u = new URL(raw);
15
+ return u.protocol === "https:" ? u.toString().replace(/\/$/, "") : null;
16
+ } catch (e) {
17
+ return null;
18
+ }
19
+ };
20
+ function normalizeDrafts(raw) {
21
+ if (!Array.isArray(raw)) return [];
22
+ const out = [];
23
+ const seen = /* @__PURE__ */ new Set();
24
+ for (const d of raw) {
25
+ if (!d || typeof d !== "object") continue;
26
+ const r = d;
27
+ const id = typeof r.id === "string" ? r.id : "";
28
+ const sandboxId = typeof r.sandboxId === "string" ? r.sandboxId : "";
29
+ const name = normalizeDraftName(r.name);
30
+ if (!DRAFT_ID_RE.test(id) || !SANDBOX_ID_RE.test(sandboxId) || !name || seen.has(id)) continue;
31
+ seen.add(id);
32
+ out.push({
33
+ id,
34
+ name,
35
+ sandboxId,
36
+ previewUrl: httpsOrNull(r.previewUrl),
37
+ baseSandboxId: typeof r.baseSandboxId === "string" && SANDBOX_ID_RE.test(r.baseSandboxId) ? r.baseSandboxId : null,
38
+ baseHead: typeof r.baseHead === "string" && SHA_RE.test(r.baseHead) ? r.baseHead.toLowerCase() : null,
39
+ createdBy: typeof r.createdBy === "string" && r.createdBy ? r.createdBy : null,
40
+ createdAt: typeof r.createdAt === "string" && !Number.isNaN(Date.parse(r.createdAt)) ? r.createdAt : ""
41
+ });
42
+ }
43
+ return out;
44
+ }
45
+ function suggestDraftName(existing) {
46
+ const taken = new Set(existing.map((d) => d.name.toLowerCase()));
47
+ for (let n = 1; ; n++) if (!taken.has(`draft ${n}`)) return `Draft ${n}`;
48
+ }
49
+ function draftTurnNote(draft, sandboxId) {
50
+ return `[Draft] This turn works in the draft "${draft.name}"${sandboxId ? ` (sandbox ${sandboxId})` : ""}: a copy of the project the user is trying out. Change only that sandbox. Do not publish it, do not record it as the project's build, and do not boot a new sandbox if it is gone (say so instead). The user accepts the draft into the project when they are happy with it.`;
51
+ }
52
+ function projectChangedSinceDraft(draft, projectHead) {
53
+ const base = (draft.baseHead || "").toLowerCase();
54
+ const head = (projectHead || "").toLowerCase();
55
+ if (!base || !head) return false;
56
+ return !(head.startsWith(base) || base.startsWith(head));
57
+ }export{DRAFT_NAME_MAX,MAX_OPEN_DRAFTS,draftTurnNote,normalizeDraftName,normalizeDrafts,projectChangedSinceDraft,suggestDraftName};//# sourceMappingURL=drafts.js.map