@iblai/web-containers 2.1.0 → 2.3.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 (206) hide show
  1. package/dist/cjs/components/canvas/binary-artifact-utils.js +261 -36
  2. package/dist/cjs/components/canvas/binary-artifact-utils.js.map +1 -1
  3. package/dist/cjs/components/canvas/binary-canvas-component.js +571 -53
  4. package/dist/cjs/components/canvas/binary-canvas-component.js.map +1 -1
  5. package/dist/cjs/components/canvas/canvas-version-menu.js +41 -0
  6. package/dist/cjs/components/canvas/canvas-version-menu.js.map +1 -0
  7. package/dist/cjs/components/canvas/canvas-view.js +25 -37
  8. package/dist/cjs/components/canvas/canvas-view.js.map +1 -1
  9. package/dist/cjs/components/canvas/code-view.js +143 -0
  10. package/dist/cjs/components/canvas/code-view.js.map +1 -0
  11. package/dist/cjs/components/canvas/copy-text-button.js +26 -0
  12. package/dist/cjs/components/canvas/copy-text-button.js.map +1 -0
  13. package/dist/cjs/components/canvas/docx-preview.js +287 -0
  14. package/dist/cjs/components/canvas/docx-preview.js.map +1 -0
  15. package/dist/cjs/components/canvas/html-preview.js +503 -0
  16. package/dist/cjs/components/canvas/html-preview.js.map +1 -0
  17. package/dist/cjs/components/canvas/office-file-limits.js +302 -0
  18. package/dist/cjs/components/canvas/office-file-limits.js.map +1 -0
  19. package/dist/cjs/components/canvas/pdf-preview.js +459 -0
  20. package/dist/cjs/components/canvas/pdf-preview.js.map +1 -0
  21. package/dist/cjs/components/canvas/session-canvas-cards.js +62 -15
  22. package/dist/cjs/components/canvas/session-canvas-cards.js.map +1 -1
  23. package/dist/cjs/components/canvas/session-canvas-placement.js +1 -0
  24. package/dist/cjs/components/canvas/session-canvas-placement.js.map +1 -1
  25. package/dist/cjs/components/canvas/text-file-canvas.js +260 -0
  26. package/dist/cjs/components/canvas/text-file-canvas.js.map +1 -0
  27. package/dist/cjs/components/canvas/text-file-kinds.js +329 -0
  28. package/dist/cjs/components/canvas/text-file-kinds.js.map +1 -0
  29. package/dist/cjs/components/canvas/use-artifact-versions.js +136 -0
  30. package/dist/cjs/components/canvas/use-artifact-versions.js.map +1 -0
  31. package/dist/cjs/components/canvas/xlsx-preview.js +139 -0
  32. package/dist/cjs/components/canvas/xlsx-preview.js.map +1 -0
  33. package/dist/cjs/components/chat/chat-export.js.map +1 -1
  34. package/dist/cjs/components/chat/chat-host-context.js.map +1 -1
  35. package/dist/cjs/components/chat/chat-messages/canvas-message-preview.js +9 -4
  36. package/dist/cjs/components/chat/chat-messages/canvas-message-preview.js.map +1 -1
  37. package/dist/cjs/components/chat/chat-messages/message-preview.js +85 -55
  38. package/dist/cjs/components/chat/chat-messages/message-preview.js.map +1 -1
  39. package/dist/cjs/components/chat/index.js +212 -46
  40. package/dist/cjs/components/chat/index.js.map +1 -1
  41. package/dist/cjs/components/credit-balance.js +40 -34
  42. package/dist/cjs/components/credit-balance.js.map +1 -1
  43. package/dist/cjs/components/master-agent/master-agent.js +9 -0
  44. package/dist/cjs/components/master-agent/master-agent.js.map +1 -1
  45. package/dist/cjs/components/modals/user-profile-modal.js +5 -0
  46. package/dist/cjs/components/modals/user-profile-modal.js.map +1 -1
  47. package/dist/cjs/components/platform-navbar/index.js +4 -2
  48. package/dist/cjs/components/platform-navbar/index.js.map +1 -1
  49. package/dist/cjs/components/platform-sidebar/index.js +6 -0
  50. package/dist/cjs/components/platform-sidebar/index.js.map +1 -1
  51. package/dist/cjs/components/tenant-switch/index.js +3 -1
  52. package/dist/cjs/components/tenant-switch/index.js.map +1 -1
  53. package/dist/cjs/components/ui/bottom-sheet.js +98 -0
  54. package/dist/cjs/components/ui/bottom-sheet.js.map +1 -0
  55. package/dist/cjs/components/user-profile-dropdown/account-sheet.js +175 -0
  56. package/dist/cjs/components/user-profile-dropdown/account-sheet.js.map +1 -0
  57. package/dist/cjs/components/user-profile-dropdown/index.js +30 -10
  58. package/dist/cjs/components/user-profile-dropdown/index.js.map +1 -1
  59. package/dist/cjs/components/your-activity/activity-stats.js +50 -0
  60. package/dist/cjs/components/your-activity/activity-stats.js.map +1 -0
  61. package/dist/cjs/components/your-activity/your-activity-button.js +34 -0
  62. package/dist/cjs/components/your-activity/your-activity-button.js.map +1 -0
  63. package/dist/cjs/components/your-activity/your-activity-panel.js +91 -0
  64. package/dist/cjs/components/your-activity/your-activity-panel.js.map +1 -0
  65. package/dist/cjs/hooks/use-iframe-message-handler.js +8 -0
  66. package/dist/cjs/hooks/use-iframe-message-handler.js.map +1 -1
  67. package/dist/cjs/i18n/messages/en.json.js +54 -16
  68. package/dist/cjs/i18n/messages/en.json.js.map +1 -1
  69. package/dist/cjs/i18n/messages/es.json.js +54 -16
  70. package/dist/cjs/i18n/messages/es.json.js.map +1 -1
  71. package/dist/cjs/i18n/messages/fr.json.js +54 -16
  72. package/dist/cjs/i18n/messages/fr.json.js.map +1 -1
  73. package/dist/cjs/i18n/messages/zh.json.js +54 -16
  74. package/dist/cjs/i18n/messages/zh.json.js.map +1 -1
  75. package/dist/cjs/index.js +14 -0
  76. package/dist/cjs/index.js.map +1 -1
  77. package/dist/cjs/lib/html-preview-messages.js +405 -0
  78. package/dist/cjs/lib/html-preview-messages.js.map +1 -0
  79. package/dist/cjs/lib/html-preview-page-prelude.js +449 -0
  80. package/dist/cjs/lib/html-preview-page-prelude.js.map +1 -0
  81. package/dist/cjs/node_modules/.pnpm/pdfjs-dist@4.8.69/node_modules/pdfjs-dist/build/pdf.js +72 -36
  82. package/dist/cjs/node_modules/.pnpm/pdfjs-dist@4.8.69/node_modules/pdfjs-dist/build/pdf.js.map +1 -1
  83. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Outline.js +113 -0
  84. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Outline.js.map +1 -0
  85. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineContext.js +8 -0
  86. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineContext.js.map +1 -0
  87. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineItem.js +82 -0
  88. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineItem.js.map +1 -0
  89. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Ref.js +18 -0
  90. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Ref.js.map +1 -0
  91. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Thumbnail.js +54 -0
  92. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Thumbnail.js.map +1 -0
  93. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/index.js +16 -0
  94. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/index.js.map +1 -1
  95. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useCachedValue.js +20 -0
  96. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useCachedValue.js.map +1 -0
  97. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useOutlineContext.js +11 -0
  98. package/dist/cjs/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useOutlineContext.js.map +1 -0
  99. package/dist/cjs/web-containers/tsconfig.build.tsbuildinfo +1 -1
  100. package/dist/esm/components/canvas/binary-artifact-utils.js +248 -36
  101. package/dist/esm/components/canvas/binary-artifact-utils.js.map +1 -1
  102. package/dist/esm/components/canvas/binary-canvas-component.js +574 -56
  103. package/dist/esm/components/canvas/binary-canvas-component.js.map +1 -1
  104. package/dist/esm/components/canvas/canvas-version-menu.js +38 -0
  105. package/dist/esm/components/canvas/canvas-version-menu.js.map +1 -0
  106. package/dist/esm/components/canvas/canvas-view.js +26 -38
  107. package/dist/esm/components/canvas/canvas-view.js.map +1 -1
  108. package/dist/esm/components/canvas/code-view.js +140 -0
  109. package/dist/esm/components/canvas/code-view.js.map +1 -0
  110. package/dist/esm/components/canvas/copy-text-button.js +24 -0
  111. package/dist/esm/components/canvas/copy-text-button.js.map +1 -0
  112. package/dist/esm/components/canvas/docx-preview.js +285 -0
  113. package/dist/esm/components/canvas/docx-preview.js.map +1 -0
  114. package/dist/esm/components/canvas/html-preview.js +501 -0
  115. package/dist/esm/components/canvas/html-preview.js.map +1 -0
  116. package/dist/esm/components/canvas/office-file-limits.js +296 -0
  117. package/dist/esm/components/canvas/office-file-limits.js.map +1 -0
  118. package/dist/esm/components/canvas/pdf-preview.js +456 -0
  119. package/dist/esm/components/canvas/pdf-preview.js.map +1 -0
  120. package/dist/esm/components/canvas/session-canvas-cards.js +63 -16
  121. package/dist/esm/components/canvas/session-canvas-cards.js.map +1 -1
  122. package/dist/esm/components/canvas/session-canvas-placement.js +1 -0
  123. package/dist/esm/components/canvas/session-canvas-placement.js.map +1 -1
  124. package/dist/esm/components/canvas/text-file-canvas.js +258 -0
  125. package/dist/esm/components/canvas/text-file-canvas.js.map +1 -0
  126. package/dist/esm/components/canvas/text-file-kinds.js +322 -0
  127. package/dist/esm/components/canvas/text-file-kinds.js.map +1 -0
  128. package/dist/esm/components/canvas/use-artifact-versions.js +134 -0
  129. package/dist/esm/components/canvas/use-artifact-versions.js.map +1 -0
  130. package/dist/esm/components/canvas/xlsx-preview.js +137 -0
  131. package/dist/esm/components/canvas/xlsx-preview.js.map +1 -0
  132. package/dist/esm/components/chat/chat-export.js.map +1 -1
  133. package/dist/esm/components/chat/chat-host-context.js.map +1 -1
  134. package/dist/esm/components/chat/chat-messages/canvas-message-preview.js +10 -5
  135. package/dist/esm/components/chat/chat-messages/canvas-message-preview.js.map +1 -1
  136. package/dist/esm/components/chat/chat-messages/message-preview.js +85 -55
  137. package/dist/esm/components/chat/chat-messages/message-preview.js.map +1 -1
  138. package/dist/esm/components/chat/index.js +212 -46
  139. package/dist/esm/components/chat/index.js.map +1 -1
  140. package/dist/esm/components/credit-balance.js +42 -36
  141. package/dist/esm/components/credit-balance.js.map +1 -1
  142. package/dist/esm/components/master-agent/master-agent.js +9 -1
  143. package/dist/esm/components/master-agent/master-agent.js.map +1 -1
  144. package/dist/esm/components/modals/user-profile-modal.js +5 -0
  145. package/dist/esm/components/modals/user-profile-modal.js.map +1 -1
  146. package/dist/esm/components/platform-navbar/index.js +4 -2
  147. package/dist/esm/components/platform-navbar/index.js.map +1 -1
  148. package/dist/esm/components/platform-sidebar/index.js +6 -0
  149. package/dist/esm/components/platform-sidebar/index.js.map +1 -1
  150. package/dist/esm/components/tenant-switch/index.js +4 -2
  151. package/dist/esm/components/tenant-switch/index.js.map +1 -1
  152. package/dist/esm/components/ui/bottom-sheet.js +76 -0
  153. package/dist/esm/components/ui/bottom-sheet.js.map +1 -0
  154. package/dist/esm/components/user-profile-dropdown/account-sheet.js +154 -0
  155. package/dist/esm/components/user-profile-dropdown/account-sheet.js.map +1 -0
  156. package/dist/esm/components/user-profile-dropdown/index.js +30 -10
  157. package/dist/esm/components/user-profile-dropdown/index.js.map +1 -1
  158. package/dist/esm/components/your-activity/activity-stats.js +45 -0
  159. package/dist/esm/components/your-activity/activity-stats.js.map +1 -0
  160. package/dist/esm/components/your-activity/your-activity-button.js +32 -0
  161. package/dist/esm/components/your-activity/your-activity-button.js.map +1 -0
  162. package/dist/esm/components/your-activity/your-activity-panel.js +87 -0
  163. package/dist/esm/components/your-activity/your-activity-panel.js.map +1 -0
  164. package/dist/esm/hooks/use-iframe-message-handler.js +8 -0
  165. package/dist/esm/hooks/use-iframe-message-handler.js.map +1 -1
  166. package/dist/esm/i18n/messages/en.json.js +53 -16
  167. package/dist/esm/i18n/messages/en.json.js.map +1 -1
  168. package/dist/esm/i18n/messages/es.json.js +53 -16
  169. package/dist/esm/i18n/messages/es.json.js.map +1 -1
  170. package/dist/esm/i18n/messages/fr.json.js +53 -16
  171. package/dist/esm/i18n/messages/fr.json.js.map +1 -1
  172. package/dist/esm/i18n/messages/zh.json.js +53 -16
  173. package/dist/esm/i18n/messages/zh.json.js.map +1 -1
  174. package/dist/esm/index.js +5 -1
  175. package/dist/esm/index.js.map +1 -1
  176. package/dist/esm/lib/html-preview-messages.js +393 -0
  177. package/dist/esm/lib/html-preview-messages.js.map +1 -0
  178. package/dist/esm/lib/html-preview-page-prelude.js +444 -0
  179. package/dist/esm/lib/html-preview-page-prelude.js.map +1 -0
  180. package/dist/esm/node_modules/.pnpm/pdfjs-dist@4.8.69/node_modules/pdfjs-dist/build/pdf.js +37 -37
  181. package/dist/esm/node_modules/.pnpm/pdfjs-dist@4.8.69/node_modules/pdfjs-dist/build/pdf.js.map +1 -1
  182. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Outline.js +111 -0
  183. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Outline.js.map +1 -0
  184. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineContext.js +6 -0
  185. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineContext.js.map +1 -0
  186. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineItem.js +80 -0
  187. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/OutlineItem.js.map +1 -0
  188. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Ref.js +16 -0
  189. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Ref.js.map +1 -0
  190. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Thumbnail.js +52 -0
  191. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/Thumbnail.js.map +1 -0
  192. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/index.js +8 -0
  193. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/index.js.map +1 -1
  194. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useCachedValue.js +18 -0
  195. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useCachedValue.js.map +1 -0
  196. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useOutlineContext.js +9 -0
  197. package/dist/esm/node_modules/.pnpm/react-pdf@9.2.1_@types_react@19.1.17_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-pdf/dist/esm/shared/hooks/useOutlineContext.js.map +1 -0
  198. package/dist/esm/web-containers/tsconfig.build.tsbuildinfo +1 -1
  199. package/dist/index.d.ts +157 -10
  200. package/dist/next/index.d.ts +33 -7
  201. package/dist/package.json +4 -1
  202. package/package.json +7 -4
  203. package/dist/cjs/components/chat/chat-binary-artifact-utils.js +0 -110
  204. package/dist/cjs/components/chat/chat-binary-artifact-utils.js.map +0 -1
  205. package/dist/esm/components/chat/chat-binary-artifact-utils.js +0 -105
  206. package/dist/esm/components/chat/chat-binary-artifact-utils.js.map +0 -1
@@ -1,71 +1,461 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { useState, useEffect } from 'react';
2
+ import { useState, useRef, useMemo, useEffect, useCallback } from 'react';
3
3
  import { useT } from '../../i18n/context.js';
4
4
  import '../../packages/i18n/dist/index.esm.js';
5
- import { useLazyGetArtifactQuery } from '@iblai/data-layer';
5
+ import { getDmBaseUrl, useLazyGetArtifactQuery, useLazyListArtifactsQuery, useLazyGetSharedSessionIdQuery, CHAT_HISTORY_PAGE_SIZE } from '@iblai/data-layer';
6
+ import { isTauri, openExternalUrl } from '@iblai/web-utils';
7
+ import { cn } from '../../lib/utils.js';
6
8
  import { Button } from '../chat/ui/button.js';
9
+ import { Tabs, TabsList, TabsTrigger, TabsContent } from '../ui/tabs.js';
10
+ import { useChatHost } from '../chat/chat-host-context.js';
7
11
  import { downloadBlob } from './canvas-export-handlers.js';
8
- import { resolveBinaryMimeType, isImageMimeType, artifactFileToBlob, getPreviewIssue, buildBinaryFilename } from './binary-artifact-utils.js';
12
+ import { isTextViewerFile, resolveEffectiveFileExtension, resolveBinarySource, isBinaryUrlExpired, isTextViewerExtension, buildBinaryFilename, isHtmlExtension, resolveBinaryMimeType, looksLikeMarkup, isDmHostedUrl, inlineSourceToBlob, getPreviewIssue, findBinaryUrlInMessages, resolveBinaryPreviewKind } from './binary-artifact-utils.js';
13
+ import { CanvasVersionMenu, CanvasVersionBanner } from './canvas-version-menu.js';
14
+ import { CodeView } from './code-view.js';
15
+ import { CopyTextButton } from './copy-text-button.js';
16
+ import { DocxPreview } from './docx-preview.js';
17
+ import { HtmlPreview } from './html-preview.js';
18
+ import { PdfPreview } from './pdf-preview.js';
19
+ import { describeTextFile } from './text-file-kinds.js';
20
+ import { useArtifactVersions } from './use-artifact-versions.js';
21
+ import { XlsxPreview } from './xlsx-preview.js';
9
22
  import FileArchive from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/file-archive.js';
10
23
  import Download from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/download.js';
11
24
  import X from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/x.js';
12
25
 
26
+ // An html file is held and saved as bytes of no type, whether it came as
27
+ // text, inline or from a link. Typed as html, a blob: address of it would be
28
+ // a page of this app's own origin for anything that opened it.
29
+ const HTML_FILE_BLOB_TYPE = 'application/octet-stream';
30
+ const HTML_MIME_TYPE = /^\s*(?:text\/html|application\/xhtml\+xml)\b/i;
31
+ // The same for bytes of any name that a server or the backend calls html.
32
+ const neverHtml = (mimeType) => mimeType && HTML_MIME_TYPE.test(mimeType) ? HTML_FILE_BLOB_TYPE : mimeType;
33
+ // What a browser runs as a page when it is sent to the file's link. Opened
34
+ // away, script in such a file would run for the person who pressed Export, in
35
+ // a tab or in the system browser, so its link is never opened: the file is
36
+ // saved from its bytes or not at all.
37
+ const PAGE_EXTENSIONS = new Set([
38
+ 'html',
39
+ 'htm',
40
+ 'xhtml',
41
+ 'xht',
42
+ 'shtml',
43
+ 'svg',
44
+ 'svgz',
45
+ 'xml',
46
+ 'xsl',
47
+ 'xslt',
48
+ 'mht',
49
+ 'mhtml',
50
+ ]);
51
+ const PAGE_MIME_TYPES = new Set([
52
+ 'text/html',
53
+ 'application/xhtml+xml',
54
+ 'image/svg+xml',
55
+ 'application/xml',
56
+ 'text/xml',
57
+ 'application/xslt+xml',
58
+ ]);
59
+ const suffixOf = (name) => { var _a; return (_a = /\.([a-z0-9]+)$/.exec((name !== null && name !== void 0 ? name : '').trim().toLowerCase())) === null || _a === void 0 ? void 0 : _a[1]; };
60
+ // Storage can pick the type it answers with from the name the file is stored under.
61
+ const linkSuffix = (link) => {
62
+ try {
63
+ return suffixOf(decodeURIComponent(new URL(link, 'https://relative.invalid').pathname));
64
+ }
65
+ catch (_a) {
66
+ return undefined;
67
+ }
68
+ };
69
+ // The sub-tabs of the agent settings (Settings, Privacy, MCP) look like this.
70
+ const VIEW_TABS_LIST_CLASS = 'inline-flex h-auto max-w-full justify-start overflow-x-auto rounded-md bg-gray-100 p-1';
71
+ const VIEW_TAB_TRIGGER_CLASS = 'px-3 py-1.5 text-sm font-medium text-gray-700 data-[state=active]:bg-white data-[state=active]:text-gray-900';
72
+ const BODY_CLASS = 'flex min-h-0 flex-1 flex-col overflow-hidden bg-gray-50';
73
+ /** The viewer's body: the panel of the selected tab when there are tabs. */
74
+ function ViewBody({ tabbed, tab, children, }) {
75
+ if (!tabbed)
76
+ return jsx("div", { className: BODY_CLASS, children: children });
77
+ return (jsx(TabsContent, { value: tab, forceMount: true, className: cn(BODY_CLASS, 'mt-0 focus-visible:ring-inset'), children: children }));
78
+ }
79
+ const opensAsPage = (info) => [info.extension, suffixOf(info.title), linkSuffix(info.link)].some((suffix) => suffix !== undefined && PAGE_EXTENSIONS.has(suffix)) ||
80
+ info.mimeTypes.some((mimeType) => PAGE_MIME_TYPES.has((mimeType !== null && mimeType !== void 0 ? mimeType : '').split(';')[0].trim().toLowerCase()));
81
+ // A version row is saved data, and not always the string its type promises.
82
+ const textOf = (value) => (typeof value === 'string' ? value : '');
83
+ const describeArtifact = (artifact, dmUrl) => ({
84
+ source: resolveBinarySource(artifact, dmUrl),
85
+ title: artifact.title,
86
+ extension: artifact.file_extension,
87
+ mimeType: artifact.mime_type,
88
+ });
89
+ const readDetail = async ({ fetchArtifact, artifactId, org, userId, dmUrl, }) => describeArtifact((await fetchArtifact({ id: artifactId, org, userId }).unwrap()), dmUrl);
13
90
  /**
14
- * Read-only canvas for binary artifacts (pdf, images, …). Unlike the
15
- * rich-text canvas there is no editing of any kind: no formatting toolbar,
16
- * no highlight-to-edit, no AI rewrite controls, no version editing. The
17
- * only actions are viewing (when the browser can render the file) and a
18
- * plain export of the original bytes.
19
- *
20
- * The bytes are served base64-encoded by the artifact detail endpoint only
21
- * (`binary_content` is nulled on every embedded/streamed payload), so they
22
- * are fetched here on mount.
91
+ * The file's link as a shared chat holds it now. The chat is read a page at
92
+ * a time from its newest messages, as the chat itself reads it, until a
93
+ * message names the file.
94
+ */
95
+ const readSharedSessionLink = async ({ readSharedSession, artifactId, org, sessionId, }) => {
96
+ if (!readSharedSession || !sessionId)
97
+ return null;
98
+ for (let page = 1;; page += 1) {
99
+ const data = await readSharedSession({
100
+ org,
101
+ sessionId,
102
+ page,
103
+ pageSize: CHAT_HISTORY_PAGE_SIZE,
104
+ }).unwrap();
105
+ const url = findBinaryUrlInMessages(data === null || data === void 0 ? void 0 : data.results, artifactId);
106
+ if (url || !(data === null || data === void 0 ? void 0 : data.next))
107
+ return url;
108
+ }
109
+ };
110
+ /**
111
+ * A new link for a file whose link ran out or was refused. A shared chat is
112
+ * asked first: it is the only source its viewer is sure to be allowed. Of the
113
+ * artifact endpoints, the session's list carries the link without the file,
114
+ * so it comes before the detail endpoint, which still sends the whole file
115
+ * inline beside the link.
23
116
  */
24
- function BinaryCanvasComponent({ title, onClose, artifactId, org, userId, fileExtension, mimeType, }) {
117
+ const renewSource = async (lookup) => {
25
118
  var _a;
119
+ const { listArtifacts, artifactId, org, userId, sessionId, dmUrl } = lookup;
120
+ const shared = resolveBinarySource({ binary_url: await readSharedSessionLink(lookup).catch(() => null) }, dmUrl);
121
+ if (shared.kind === 'url')
122
+ return { source: shared };
123
+ if (sessionId) {
124
+ try {
125
+ const page = await listArtifacts({
126
+ org,
127
+ userId,
128
+ params: { session_id: sessionId },
129
+ }).unwrap();
130
+ const row = ((_a = page === null || page === void 0 ? void 0 : page.results) !== null && _a !== void 0 ? _a : []).find((item) => item.id === artifactId);
131
+ if (row === null || row === void 0 ? void 0 : row.binary_url)
132
+ return describeArtifact(row, dmUrl);
133
+ }
134
+ catch (_b) {
135
+ // The detail endpoint below is the other way to a link.
136
+ }
137
+ }
138
+ return readDetail(lookup);
139
+ };
140
+ /**
141
+ * Reads a file link. No cookies and no headers: the link carries its own
142
+ * permission, and storage refuses a request that also brings a sign-in header.
143
+ * The error of a failed read is dropped, never logged: it can name the link.
144
+ */
145
+ const fetchLinkBlob = async (url) => {
146
+ try {
147
+ const response = await fetch(url, { credentials: 'omit' });
148
+ if (!response.ok)
149
+ return 'refused';
150
+ return { blob: await response.blob() };
151
+ }
152
+ catch (_a) {
153
+ return 'unreachable';
154
+ }
155
+ };
156
+ // The desktop app's own `fetch` keeps a copy on disk of whatever it reads from
157
+ // storage, under the link it was read from, and logs that link. So there a
158
+ // storage link is shown, played or opened, and never read.
159
+ const mayReadLink = (url, dmUrl) => !isTauri() || isDmHostedUrl(url, dmUrl);
160
+ const withMimeType = (blob, mimeType) => {
161
+ const type = neverHtml(mimeType || blob.type);
162
+ return type && blob.type !== type ? blob.slice(0, blob.size, type) : blob;
163
+ };
164
+ // `openExternalUrl` replaces the current page on the web, which would take
165
+ // the person out of the chat the file belongs to.
166
+ const openLinkAway = async (url) => {
167
+ if (isTauri()) {
168
+ await openExternalUrl(url);
169
+ return;
170
+ }
171
+ window.open(url, '_blank', 'noopener,noreferrer');
172
+ };
173
+ const LoadingSpinner = () => (jsx("div", { className: "flex flex-1 items-center justify-center", "data-testid": "binary-canvas-loading", children: jsx("div", { className: "h-10 w-10 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" }) }));
174
+ /**
175
+ * Read-only canvas for binary artifacts (pdf, images, video, sound, Word,
176
+ * Excel, …). Unlike the rich-text canvas there is no editing of any kind: no
177
+ * formatting toolbar, no highlight-to-edit, no AI rewrite controls, no
178
+ * version editing. The only actions are viewing (when the file can be shown
179
+ * here) and a plain export of the original bytes.
180
+ *
181
+ * The file comes from its link (`binary_url`): the one the caller holds, or
182
+ * a new one when that has run out. A backend without links still sends the
183
+ * file inline on the detail endpoint. An svg and an html file are text
184
+ * artifacts: their text is the file, given by the caller (`content`) or read
185
+ * from the detail endpoint.
186
+ */
187
+ function BinaryCanvasComponent({ title, onClose, artifactId, org, userId, fileExtension, mimeType, binaryUrl: binaryUrlGiven, content: contentGiven, sessionId, versionUnavailable: versionUnavailableGiven, sharedSession, versionNumber, readOnly, }) {
188
+ var _a, _b, _c, _d;
26
189
  const t = useT();
190
+ const { config } = useChatHost();
191
+ const dmUrl = ((_a = config === null || config === void 0 ? void 0 : config.dmUrl) === null || _a === void 0 ? void 0 : _a.call(config)) || getDmBaseUrl();
27
192
  const [fetchArtifact] = useLazyGetArtifactQuery();
28
- const [blob, setBlob] = useState(null);
193
+ const [listArtifacts] = useLazyListArtifactsQuery();
194
+ const [readSharedSession] = useLazyGetSharedSessionIdQuery();
195
+ const [file, setFile] = useState(null);
29
196
  const [resolvedTitle, setResolvedTitle] = useState(title);
30
197
  const [resolvedExtension, setResolvedExtension] = useState(fileExtension);
31
198
  const [loadState, setLoadState] = useState('loading');
32
199
  // The file arrived but can't be displayed (malformed LLM output, render
33
200
  // failure) — export still works, so this is softer than loadState 'error'.
34
201
  const [previewFailed, setPreviewFailed] = useState(false);
202
+ // Why a Word or Excel file was not drawn, which picks the sentence shown.
203
+ const [tooLargeToPreview, setTooLargeToPreview] = useState(false);
204
+ // An html file that cannot be run here (no preview page, the desktop app,
205
+ // no answer): its text is shown or Retry is offered, and Export still saves it.
206
+ const [pageUnavailable, setPageUnavailable] = useState(null);
207
+ // A pdf whose bytes are in hand but that pdf.js cannot draw here is shown in a frame instead.
208
+ const [pdfInFrame, setPdfInFrame] = useState(false);
209
+ const [tab, setTab] = useState('preview');
210
+ const pageSerialRef = useRef(0);
35
211
  const [reloadToken, setReloadToken] = useState(0);
212
+ // The `binaryUrl` whose picture, video or sound would not load: the next load goes past it.
213
+ const [staleLink, setStaleLink] = useState(null);
214
+ const renewedForRef = useRef(null);
215
+ const exportingRef = useRef(false);
216
+ // Export could neither read the file nor save it.
217
+ const [saveFailed, setSaveFailed] = useState(false);
218
+ // Once the person has stepped through the versions, the list says which
219
+ // one is on screen; until then the caller does.
220
+ const [stepped, setStepped] = useState(false);
221
+ // The latest file arrived as bytes or with a link, whatever its name says.
222
+ const [cameAsBytes, setCameAsBytes] = useState(false);
223
+ // A host that keeps this viewer mounted and hands it another file, or
224
+ // another version of this one, decides what is on screen again. Object.is:
225
+ // an id that is NaN never equals itself, and this would then never settle.
226
+ const [opened, setOpened] = useState({ artifactId, versionNumber });
227
+ const sameArtifact = Object.is(opened.artifactId, artifactId);
228
+ if (!sameArtifact || !Object.is(opened.versionNumber, versionNumber)) {
229
+ setOpened({ artifactId, versionNumber });
230
+ setStepped(false);
231
+ if (!sameArtifact) {
232
+ setCameAsBytes(false);
233
+ setTab('preview');
234
+ }
235
+ }
236
+ const versions = useArtifactVersions({
237
+ artifactId,
238
+ org,
239
+ userId,
240
+ initialVersionNumber: versionNumber,
241
+ enabled: !sharedSession,
242
+ });
243
+ const earlier = versions.isViewingCurrent ? null : versions.viewing;
244
+ // A file that is text on the wire keeps every version's text; any other
245
+ // file keeps only its latest bytes. The name alone does not say which: a
246
+ // caller that calls an earlier version unavailable holds a file of bytes.
247
+ const keepsEveryVersion = !versionUnavailableGiven &&
248
+ !cameAsBytes &&
249
+ isTextViewerFile({
250
+ fileExtension: resolveEffectiveFileExtension(fileExtension, title),
251
+ binaryUrl: binaryUrlGiven,
252
+ });
253
+ const steppedVersions = useMemo(() => ({
254
+ ...versions,
255
+ goPrevious: () => {
256
+ setStepped(true);
257
+ versions.goPrevious();
258
+ },
259
+ goNext: () => {
260
+ setStepped(true);
261
+ versions.goNext();
262
+ },
263
+ backToLatest: () => {
264
+ setStepped(true);
265
+ versions.backToLatest();
266
+ },
267
+ restore: async () => {
268
+ setStepped(true);
269
+ return versions.restore();
270
+ },
271
+ }), [versions]);
272
+ const versionUnavailable = stepped
273
+ ? earlier !== null && !keepsEveryVersion
274
+ : Boolean(versionUnavailableGiven);
275
+ // An earlier version's text comes from the list once the person has stepped
276
+ // to it, and also when the caller opened it holding no text (a version
277
+ // saved as a partial update): reading the file would show the latest one
278
+ // under the earlier-version bar. Empty is then the whole file, not "none".
279
+ const earlierText = keepsEveryVersion && earlier !== null && (stepped || !contentGiven)
280
+ ? textOf(earlier.content)
281
+ : null;
282
+ const latestText = stepped
283
+ ? keepsEveryVersion && textOf((_b = versions.viewing) === null || _b === void 0 ? void 0 : _b.content)
284
+ : contentGiven;
285
+ // null: no text is held, so the file is read.
286
+ const heldText = earlierText !== null && earlierText !== void 0 ? earlierText : (latestText || null);
287
+ // The caller's link is the latest file's, or none for an earlier version.
288
+ const binaryUrl = (stepped && !keepsEveryVersion ? undefined : binaryUrlGiven) || undefined;
289
+ const lookup = useMemo(() => artifactId && org && userId
290
+ ? {
291
+ artifactId,
292
+ org,
293
+ userId,
294
+ sessionId,
295
+ dmUrl,
296
+ fetchArtifact,
297
+ listArtifacts,
298
+ readSharedSession: sharedSession ? readSharedSession : undefined,
299
+ }
300
+ : null, [
301
+ artifactId,
302
+ org,
303
+ userId,
304
+ sessionId,
305
+ dmUrl,
306
+ fetchArtifact,
307
+ listArtifacts,
308
+ sharedSession,
309
+ readSharedSession,
310
+ ]);
311
+ // One automatic renewal per link the caller gave. A host that feeds the
312
+ // renewed link back through `binaryUrl` would otherwise renew without end.
313
+ const claimRenewal = () => {
314
+ const given = binaryUrl !== null && binaryUrl !== void 0 ? binaryUrl : '';
315
+ if (renewedForRef.current !== null && renewedForRef.current !== given)
316
+ return false;
317
+ renewedForRef.current = given;
318
+ return true;
319
+ };
36
320
  useEffect(() => {
321
+ setSaveFailed(false);
322
+ if (versionUnavailable)
323
+ return;
37
324
  let cancelled = false;
38
- const load = async () => {
39
- if (!artifactId || !org || !userId) {
40
- setLoadState('error');
41
- return;
325
+ const present = async (found, fromProp) => {
326
+ var _a, _b;
327
+ const extension = found.extension || fileExtension || undefined;
328
+ const shownTitle = found.title || title;
329
+ const isHtml = isHtmlExtension(resolveEffectiveFileExtension(extension, shownTitle));
330
+ const type = isHtml
331
+ ? HTML_FILE_BLOB_TYPE
332
+ : neverHtml(resolveBinaryMimeType(extension, (_a = found.mimeType) !== null && _a !== void 0 ? _a : mimeType));
333
+ const kindFor = (mime) => resolveBinaryPreviewKind(mime, resolveEffectiveFileExtension(extension, shownTitle));
334
+ const show = (loaded) => {
335
+ if (loaded.mode === 'direct' || loaded.text === undefined)
336
+ setCameAsBytes(true);
337
+ setFile(loaded);
338
+ setResolvedTitle(shownTitle);
339
+ setResolvedExtension(extension);
340
+ setLoadState('ready');
341
+ };
342
+ const { source } = found;
343
+ // Only the artifact's own text is ever run as a page, never what a link
344
+ // answered with. Text that is not markup (an html file edited in the
345
+ // editor holds markdown) has nothing to run.
346
+ if (source.kind === 'text' && isHtml) {
347
+ const isPage = looksLikeMarkup(source.content);
348
+ setPreviewFailed(false);
349
+ show({
350
+ mode: 'blob',
351
+ blob: new Blob([source.content], { type: HTML_FILE_BLOB_TYPE }),
352
+ kind: isPage ? 'html' : 'none',
353
+ page: isPage ? { html: source.content, serial: ++pageSerialRef.current } : undefined,
354
+ text: source.content,
355
+ });
356
+ return 'shown';
42
357
  }
358
+ let bytes;
359
+ if (source.kind === 'url') {
360
+ const kind = kindFor(type);
361
+ const fromDm = isDmHostedUrl(source.url, dmUrl);
362
+ const drawnFromBytes = kind === 'docx' || kind === 'xlsx' || kind === 'pdf';
363
+ // The DM lets another site read its files but refuses to be framed;
364
+ // storage can be framed but lets no other site read. So a DM link is
365
+ // read into a blob, and a storage link is handed to the browser as is.
366
+ // That holds for video and sound too: the DM does not send a file in
367
+ // parts, and Safari and the desktop app play nothing from a server
368
+ // that does not, while a blob can always be read in parts. Word,
369
+ // Excel and pdf files are drawn from their bytes, so a storage link
370
+ // is tried once in case its bucket allows the read. A pdf that cannot
371
+ // be read is still framed from its link, as the browser can show it.
372
+ const fetched = (fromDm || drawnFromBytes) && mayReadLink(source.url, dmUrl)
373
+ ? await fetchLinkBlob(source.url)
374
+ : null;
375
+ if (cancelled)
376
+ return 'cancelled';
377
+ // An answer that refuses is about the link, wherever it is: a bucket
378
+ // that lets no other site read gives no answer at all. A read that
379
+ // could not be made says nothing about the link.
380
+ if (fetched === 'refused')
381
+ return 'refused';
382
+ if (fetched === null || typeof fetched === 'string') {
383
+ show({
384
+ mode: 'direct',
385
+ url: source.url,
386
+ mimeType: type,
387
+ namedType: (_b = found.mimeType) !== null && _b !== void 0 ? _b : mimeType,
388
+ fromProp,
389
+ kind: kind === 'docx' || kind === 'xlsx' ? 'none' : kind,
390
+ });
391
+ return 'shown';
392
+ }
393
+ bytes = withMimeType(fetched.blob, type);
394
+ }
395
+ else {
396
+ bytes = inlineSourceToBlob(source, type !== null && type !== void 0 ? type : 'application/octet-stream');
397
+ if (!bytes)
398
+ throw new Error('Artifact has no displayable content');
399
+ }
400
+ // Malformed LLM output (invalid SVG XML, non-PDF bytes, …) must show
401
+ // a clear message instead of the browser's raw parse error.
402
+ const issue = await getPreviewIssue(bytes, bytes.type);
403
+ if (cancelled)
404
+ return 'cancelled';
405
+ setPreviewFailed(issue !== null);
406
+ show({
407
+ mode: 'blob',
408
+ blob: bytes,
409
+ kind: kindFor(bytes.type),
410
+ text: source.kind === 'text' ? source.content : undefined,
411
+ });
412
+ return 'shown';
413
+ };
414
+ const load = async () => {
43
415
  setLoadState('loading');
44
416
  setPreviewFailed(false);
417
+ setTooLargeToPreview(false);
418
+ setPageUnavailable(null);
419
+ setPdfInFrame(false);
420
+ setFile(null);
45
421
  try {
46
- const artifact = (await fetchArtifact({
47
- id: artifactId,
48
- org,
49
- userId,
50
- }).unwrap());
51
- if (cancelled)
52
- return;
53
- // Binary artifacts carry base64 `binary_content`; text-based viewable
54
- // files (svg) carry their source in `content` — handle both.
55
- const file = artifactFileToBlob(artifact, fileExtension, mimeType);
56
- if (!file) {
57
- throw new Error('Artifact has no displayable content');
422
+ // A link that is not a web address counts as no link at all.
423
+ const givenSource = binaryUrl
424
+ ? resolveBinarySource({ binary_url: binaryUrl }, dmUrl)
425
+ : null;
426
+ const given = (givenSource === null || givenSource === void 0 ? void 0 : givenSource.kind) === 'url' ? givenSource.url : null;
427
+ const renewFirst = given !== null &&
428
+ lookup !== null &&
429
+ (binaryUrl === staleLink || (isBinaryUrlExpired(given) && claimRenewal()));
430
+ let found;
431
+ let fromProp = false;
432
+ if (given !== null && !renewFirst) {
433
+ found = { source: { kind: 'url', url: given } };
434
+ fromProp = true;
58
435
  }
59
- // Malformed LLM output (invalid SVG XML, non-PDF bytes, …) must show
60
- // a clear message instead of the browser's raw parse error.
61
- const issue = await getPreviewIssue(file.blob, file.mimeType);
62
- if (cancelled)
436
+ else if (given === null &&
437
+ heldText !== null &&
438
+ isTextViewerExtension(resolveEffectiveFileExtension(fileExtension, title))) {
439
+ found = { source: { kind: 'text', content: heldText } };
440
+ }
441
+ else if (lookup === null) {
442
+ setLoadState('error');
63
443
  return;
64
- setPreviewFailed(issue !== null);
65
- setBlob(file.blob);
66
- setResolvedTitle(artifact.title || title);
67
- setResolvedExtension(file.extension);
68
- setLoadState('ready');
444
+ }
445
+ else {
446
+ found = await (given !== null ? renewSource(lookup) : readDetail(lookup));
447
+ if (cancelled)
448
+ return;
449
+ }
450
+ let outcome = await present(found, fromProp);
451
+ if (outcome === 'refused' && fromProp && lookup !== null && claimRenewal()) {
452
+ const renewed = await renewSource(lookup);
453
+ if (cancelled)
454
+ return;
455
+ outcome = await present(renewed, false);
456
+ }
457
+ if (outcome === 'refused')
458
+ throw new Error('The file link was refused');
69
459
  }
70
460
  catch (error) {
71
461
  if (cancelled)
@@ -78,7 +468,21 @@ function BinaryCanvasComponent({ title, onClose, artifactId, org, userId, fileEx
78
468
  return () => {
79
469
  cancelled = true;
80
470
  };
81
- }, [artifactId, org, userId, reloadToken, fetchArtifact]);
471
+ }, [
472
+ binaryUrl,
473
+ heldText,
474
+ staleLink,
475
+ lookup,
476
+ dmUrl,
477
+ fileExtension,
478
+ mimeType,
479
+ versionUnavailable,
480
+ reloadToken,
481
+ ]);
482
+ const page = (file === null || file === void 0 ? void 0 : file.mode) === 'blob' ? file.page : undefined;
483
+ // A page is handed to its frame as text, so it needs no address of its own.
484
+ const blob = (file === null || file === void 0 ? void 0 : file.mode) === 'blob' && !page ? file.blob : null;
485
+ const directUrl = (file === null || file === void 0 ? void 0 : file.mode) === 'direct' ? file.url : null;
82
486
  // Object URL for the embedded viewer. Created and revoked inside one
83
487
  // effect so each mount gets a fresh URL — a memoized URL would be revoked
84
488
  // by StrictMode's cleanup pass and hand the viewer a dead blob: URL.
@@ -86,6 +490,22 @@ function BinaryCanvasComponent({ title, onClose, artifactId, org, userId, fileEx
86
490
  useEffect(() => {
87
491
  if (!blob)
88
492
  return;
493
+ // An svg can hold script. A blob: address is of this app's origin, so a
494
+ // person who opens the picture in a tab of its own would run that script
495
+ // as the app; a data: address has no origin of its own.
496
+ if (blob.type === 'image/svg+xml') {
497
+ let live = true;
498
+ const reader = new FileReader();
499
+ reader.onload = () => {
500
+ if (live && typeof reader.result === 'string')
501
+ setBlobUrl(reader.result);
502
+ };
503
+ reader.readAsDataURL(blob);
504
+ return () => {
505
+ live = false;
506
+ setBlobUrl(null);
507
+ };
508
+ }
89
509
  const url = URL.createObjectURL(blob);
90
510
  setBlobUrl(url);
91
511
  return () => {
@@ -93,25 +513,123 @@ function BinaryCanvasComponent({ title, onClose, artifactId, org, userId, fileEx
93
513
  URL.revokeObjectURL(url);
94
514
  };
95
515
  }, [blob]);
96
- const effectiveMime = (_a = blob === null || blob === void 0 ? void 0 : blob.type) !== null && _a !== void 0 ? _a : resolveBinaryMimeType(fileExtension, mimeType);
97
- const isPdf = effectiveMime === 'application/pdf';
98
- const isImage = isImageMimeType(effectiveMime);
99
- const canPreview = isPdf || isImage;
100
- const handleExport = () => {
101
- if (!blob)
516
+ const viewerUrl = directUrl !== null && directUrl !== void 0 ? directUrl : blobUrl;
517
+ const kind = (_c = file === null || file === void 0 ? void 0 : file.kind) !== null && _c !== void 0 ? _c : 'none';
518
+ const saveFile = (_d = config === null || config === void 0 ? void 0 : config.saveFile) !== null && _d !== void 0 ? _d : downloadBlob;
519
+ const handleExport = async () => {
520
+ var _a;
521
+ if (!file || exportingRef.current)
522
+ return;
523
+ const filename = buildBinaryFilename(resolvedTitle, resolvedExtension);
524
+ exportingRef.current = true;
525
+ setSaveFailed(false);
526
+ try {
527
+ if (file.mode === 'blob') {
528
+ await saveFile(file.blob, filename);
529
+ return;
530
+ }
531
+ const read = async (url) => mayReadLink(url, dmUrl) ? fetchLinkBlob(url) : 'unreachable';
532
+ const renewedLink = async () => {
533
+ var _a;
534
+ const renewed = lookup ? (_a = (await renewSource(lookup).catch(() => null))) === null || _a === void 0 ? void 0 : _a.source : null;
535
+ return (renewed === null || renewed === void 0 ? void 0 : renewed.kind) === 'url' ? renewed.url : null;
536
+ };
537
+ let link = file.url;
538
+ // A file can stay open longer than its link lasts.
539
+ const ranOut = isBinaryUrlExpired(link);
540
+ if (ranOut)
541
+ link = (_a = (await renewedLink())) !== null && _a !== void 0 ? _a : link;
542
+ let fetched = await read(link);
543
+ // An answer that refuses means the link is dead, so a new one is tried
544
+ // once before the link is opened away, where a dead one shows an error.
545
+ if (fetched === 'refused' && !ranOut) {
546
+ const renewed = await renewedLink();
547
+ if (renewed && renewed !== link) {
548
+ link = renewed;
549
+ fetched = await read(link);
550
+ }
551
+ }
552
+ if (fetched === 'refused' || fetched === 'unreachable') {
553
+ const runsWhenOpened = opensAsPage({
554
+ extension: resolveEffectiveFileExtension(resolvedExtension, resolvedTitle),
555
+ title: resolvedTitle,
556
+ link,
557
+ mimeTypes: [file.mimeType, file.namedType],
558
+ });
559
+ if (runsWhenOpened) {
560
+ setSaveFailed(true);
561
+ return;
562
+ }
563
+ await openLinkAway(link);
564
+ return;
565
+ }
566
+ await saveFile(withMimeType(fetched.blob, file.mimeType), filename);
567
+ }
568
+ catch (_b) {
569
+ console.error('[BinaryCanvas] Failed to save the file');
570
+ setSaveFailed(true);
571
+ }
572
+ finally {
573
+ exportingRef.current = false;
574
+ }
575
+ };
576
+ // A picture, video or sound that will not load from the link the caller
577
+ // gave may only need a new link. A file whose bytes are in hand does not.
578
+ const handlePreviewError = () => {
579
+ if ((file === null || file === void 0 ? void 0 : file.mode) === 'direct' && file.fromProp && lookup && claimRenewal()) {
580
+ setStaleLink(binaryUrl !== null && binaryUrl !== void 0 ? binaryUrl : null);
102
581
  return;
103
- downloadBlob(blob, buildBinaryFilename(resolvedTitle, resolvedExtension));
582
+ }
583
+ setPreviewFailed(true);
584
+ };
585
+ const handleOfficePreviewError = (reason) => {
586
+ setTooLargeToPreview(reason === 'too-large');
587
+ setPreviewFailed(true);
588
+ };
589
+ const handlePageUnavailable = useCallback((reason) => setPageUnavailable(reason), []);
590
+ const handlePdfFailed = useCallback(() => setPreviewFailed(true), []);
591
+ const handlePdfTooLarge = useCallback(() => {
592
+ setTooLargeToPreview(true);
593
+ setPreviewFailed(true);
594
+ }, []);
595
+ const handlePdfUnavailable = useCallback(() => setPdfInFrame(true), []);
596
+ const handleRetry = () => {
597
+ renewedForRef.current = null;
598
+ setStaleLink(null);
599
+ setReloadToken((v) => v + 1);
104
600
  };
105
601
  const displayTitle = (resolvedTitle === null || resolvedTitle === void 0 ? void 0 : resolvedTitle.trim()) || t('canvasBinaryCanvas.untitledFile');
106
- return (jsxs("div", { className: "flex h-full w-full flex-col overflow-hidden bg-white", "data-testid": "binary-canvas", children: [jsxs("div", { className: "flex min-h-[50px] flex-shrink-0 items-center gap-1 border-b border-gray-200 bg-white px-2 py-2 sm:min-h-[60px] sm:px-3 sm:py-3 md:px-4", children: [jsxs("div", { className: "mr-2 flex min-w-0 flex-1 items-center gap-1 overflow-hidden sm:gap-2", children: [jsx(FileArchive, { className: "h-4 w-4 flex-shrink-0 text-blue-600 sm:h-5 sm:w-5" }), jsx("span", { className: "block truncate text-left text-xs font-medium text-gray-900 sm:text-sm md:text-base", "data-testid": "binary-canvas-title", children: displayTitle })] }), jsxs("div", { className: "ml-1 flex flex-shrink-0 items-center gap-1 sm:gap-2", children: [jsxs(Button, { variant: "outline", size: "sm", className: "flex items-center gap-1 border-blue-200 bg-transparent px-1 text-xs whitespace-nowrap text-blue-600 sm:px-2 md:px-3", onClick: handleExport, disabled: loadState !== 'ready' || !blob, "data-testid": "binary-canvas-export", children: [jsx(Download, { className: "h-3.5 w-3.5 sm:mr-1" }), jsx("span", { className: "hidden sm:inline", children: t('canvasBinaryCanvas.export') })] }), onClose && (jsx(Button, { variant: "ghost", size: "sm", className: "h-8 w-8 p-0", onClick: onClose, "data-testid": "binary-canvas-close", children: jsx(X, { className: "h-4 w-4" }) }))] })] }), jsxs("div", { className: "flex min-h-0 flex-1 flex-col overflow-hidden bg-gray-50", children: [loadState === 'loading' && (jsx("div", { className: "flex flex-1 items-center justify-center", "data-testid": "binary-canvas-loading", children: jsx("div", { className: "h-10 w-10 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" }) })), loadState === 'error' && (jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", "data-testid": "binary-canvas-error", children: [jsx(FileArchive, { className: "h-10 w-10 text-gray-400" }), jsx("p", { className: "text-sm text-gray-600", children: t('canvasBinaryCanvas.loadError') }), jsx(Button, { variant: "outline", size: "sm", onClick: () => setReloadToken((v) => v + 1), "data-testid": "binary-canvas-retry", children: t('canvasBinaryCanvas.retry') })] })), loadState === 'ready' && !previewFailed && blobUrl && isPdf && (jsx("iframe", { src: blobUrl, title: displayTitle, className: "h-full w-full flex-1 border-0", "data-testid": "binary-canvas-pdf" })), loadState === 'ready' && !previewFailed && blobUrl && isImage && (jsx("div", { className: "flex flex-1 items-center justify-center overflow-auto p-4", children: jsx("img", { src: blobUrl, alt: displayTitle, className: "max-h-full max-w-full object-contain", "data-testid": "binary-canvas-image", onError: () => setPreviewFailed(true) }) })), loadState === 'ready' && (previewFailed || !canPreview) && (
107
- /* Two ways here: the file itself is malformed / failed to render
108
- (previewFailed), or this type has no in-canvas viewer at all
109
- (defensive — the chat chip offers Download for those instead of
110
- opening the canvas). Either way the original file still
111
- downloads fine. */
112
- jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", "data-testid": previewFailed ? 'binary-canvas-preview-error' : 'binary-canvas-fallback', children: [jsx(FileArchive, { className: "h-10 w-10 text-gray-400" }), jsx("p", { className: "text-sm text-gray-600", children: previewFailed
113
- ? t('canvasBinaryCanvas.previewFailed')
114
- : t('canvasBinaryCanvas.previewUnavailable') })] }))] })] }));
602
+ const view = versionUnavailable ? 'versionUnavailable' : loadState;
603
+ // An html page and an svg are text as well as something to look at. Where
604
+ // the page cannot be run or the picture cannot be drawn, the text is shown.
605
+ const sourceText = (file === null || file === void 0 ? void 0 : file.mode) === 'blob' ? file.text : undefined;
606
+ const hasPreview = (Boolean(page) && pageUnavailable !== 'not-here') || (kind === 'image' && !previewFailed);
607
+ const shownCode = view === 'ready' && (tab === 'code' || !hasPreview) ? sourceText : undefined;
608
+ const showsCode = shownCode !== undefined;
609
+ const showsTabs = view === 'ready' && sourceText !== undefined && hasPreview;
610
+ const previewShown = view === 'ready' && !previewFailed && !showsCode;
611
+ const tabs = [
612
+ { id: 'preview', label: t('canvasBinaryCanvas.preview') },
613
+ { id: 'code', label: t('canvasBinaryCanvas.code') },
614
+ ];
615
+ return (jsxs("div", { className: "flex h-full w-full flex-col overflow-hidden bg-white", "data-testid": "binary-canvas", children: [jsxs("div", { className: "flex min-h-[50px] flex-shrink-0 items-center gap-1 border-b border-gray-200 bg-white px-2 py-2 sm:min-h-[60px] sm:px-3 sm:py-3 md:px-4", children: [jsxs("div", { className: "mr-2 flex min-w-0 flex-1 items-center gap-1 overflow-hidden sm:gap-2", children: [jsx(FileArchive, { className: "h-4 w-4 flex-shrink-0 text-blue-600 sm:h-5 sm:w-5" }), jsx("span", { className: "block truncate text-left text-xs font-medium text-gray-900 sm:text-sm md:text-base", "data-testid": "binary-canvas-title", children: displayTitle }), jsx(CanvasVersionMenu, { versions: steppedVersions, disabled: view === 'loading' })] }), jsxs("div", { className: "ml-1 flex flex-shrink-0 items-center gap-1 sm:gap-2", children: [shownCode !== undefined && jsx(CopyTextButton, { text: shownCode }), jsxs(Button, { variant: "outline", size: "sm", className: "flex items-center gap-1 border-blue-200 bg-transparent px-1 text-xs whitespace-nowrap text-blue-600 sm:px-2 md:px-3", onClick: () => void handleExport(), disabled: view !== 'ready' || !file, "aria-label": t('canvasBinaryCanvas.export'), "data-testid": "binary-canvas-export", children: [jsx(Download, { className: "h-3.5 w-3.5 sm:mr-1", "aria-hidden": "true" }), jsx("span", { className: "hidden sm:inline", children: t('canvasBinaryCanvas.export') })] }), onClose && (jsx(Button, { variant: "ghost", size: "sm", className: "h-8 w-8 p-0", onClick: onClose, "aria-label": t('canvasBinaryCanvas.close'), "data-testid": "binary-canvas-close", children: jsx(X, { className: "h-4 w-4", "aria-hidden": "true" }) }))] })] }), saveFailed && (jsx("div", { role: "status", className: "flex-shrink-0 border-b border-gray-200 bg-gray-50 px-3 py-2 text-xs text-gray-700 sm:px-4 sm:text-sm", "data-testid": "binary-canvas-save-failed", children: t('canvasBinaryCanvas.saveFailed') })), jsx(CanvasVersionBanner, { versions: steppedVersions, readOnly: readOnly, restorable: keepsEveryVersion }), jsxs(Tabs, { value: tab, onValueChange: (value) => setTab(value), className: "flex min-h-0 flex-1 flex-col", children: [showsTabs && (jsx("div", { className: "flex flex-shrink-0 items-center border-b border-gray-200 bg-white px-2 py-2 sm:px-3 md:px-4", children: jsx(TabsList, { "aria-label": t('canvasBinaryCanvas.viewLabel'), className: VIEW_TABS_LIST_CLASS, "data-testid": "binary-canvas-view-tabs", children: tabs.map(({ id, label }) => (jsx(TabsTrigger, { value: id, className: VIEW_TAB_TRIGGER_CLASS, "data-testid": `binary-canvas-view-${id}`, children: label }, id))) }) })), jsxs(ViewBody, { tabbed: showsTabs, tab: tab, children: [view === 'versionUnavailable' && (jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", "data-testid": "binary-canvas-version-unavailable", children: [jsx(FileArchive, { className: "h-10 w-10 text-gray-400" }), jsx("p", { className: "text-sm text-gray-600", children: t('canvasBinaryCanvas.earlierVersionUnavailable') })] })), view === 'loading' && jsx(LoadingSpinner, {}), view === 'error' && (jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", "data-testid": "binary-canvas-error", children: [jsx(FileArchive, { className: "h-10 w-10 text-gray-400" }), jsx("p", { className: "text-sm text-gray-600", children: t('canvasBinaryCanvas.loadError') }), jsx(Button, { variant: "outline", size: "sm", onClick: handleRetry, "data-testid": "binary-canvas-retry", children: t('canvasBinaryCanvas.retry') })] })), shownCode !== undefined && (jsx(CodeView, { text: shownCode, language: describeTextFile({ fileExtension: resolvedExtension, title: resolvedTitle })
616
+ .language, label: displayTitle })), previewShown && blob && kind === 'pdf' && !pdfInFrame && (jsx(PdfPreview, { blob: blob, title: displayTitle, onFailed: handlePdfFailed, onTooLarge: handlePdfTooLarge, onUnavailable: handlePdfUnavailable })), previewShown && viewerUrl && kind === 'pdf' && (!blob || pdfInFrame) && (jsx("iframe", { src: viewerUrl, title: displayTitle, referrerPolicy: "no-referrer", className: "h-full w-full flex-1 border-0", "data-testid": "binary-canvas-pdf", "data-sentry-block": true })), previewShown && viewerUrl && kind === 'image' && (jsx("div", { className: "flex flex-1 items-center justify-center overflow-auto p-4", children: jsx("img", { src: viewerUrl, alt: displayTitle, referrerPolicy: "no-referrer", className: "max-h-full max-w-full object-contain", "data-testid": "binary-canvas-image", "data-sentry-block": true, onError: handlePreviewError }) })), previewShown && viewerUrl && kind === 'video' && (jsx("div", { className: "flex flex-1 items-center justify-center overflow-auto p-4", children: jsx("video", { src: viewerUrl, controls: true, playsInline: true, preload: "metadata", "aria-label": displayTitle, className: "max-h-full max-w-full", "data-testid": "binary-canvas-video", "data-sentry-block": true, onError: handlePreviewError }) })), previewShown && viewerUrl && kind === 'audio' && (jsx("div", { className: "flex flex-1 items-center justify-center overflow-auto p-4", children: jsx("audio", { src: viewerUrl, controls: true, preload: "metadata", "aria-label": displayTitle, className: "w-full max-w-md", "data-testid": "binary-canvas-audio", "data-sentry-block": true, onError: handlePreviewError }) })), previewShown && blob && kind === 'docx' && (jsx(DocxPreview, { blob: blob, title: displayTitle, onError: handleOfficePreviewError })), previewShown && blob && kind === 'xlsx' && (jsx(XlsxPreview, { blob: blob, title: displayTitle, onError: handleOfficePreviewError })), previewShown && page && pageUnavailable === 'no-answer' && (jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", "data-testid": "binary-canvas-page-error", children: [jsx(FileArchive, { className: "h-10 w-10 text-gray-400" }), jsx("p", { className: "text-sm text-gray-600", children: t('canvasBinaryCanvas.pageNotShown') }), jsx(Button, { variant: "outline", size: "sm", onClick: handleRetry, "data-testid": "binary-canvas-retry", children: t('canvasBinaryCanvas.retry') })] })), view === 'ready' && !previewFailed && page && !pageUnavailable && (
617
+ // Kept running under the Code tab: taking it away would start the
618
+ // page again. The attribute, with no display class beside it to
619
+ // outrank it, hides it under any stylesheet.
620
+ jsx("div", { hidden: showsCode, className: showsCode ? undefined : 'flex min-h-0 flex-1 flex-col', children: jsx(HtmlPreview, { html: page.html, title: displayTitle, onUnavailable: handlePageUnavailable }, page.serial) })), view === 'ready' && !showsCode && (previewFailed || kind === 'none') && (
621
+ /* Three ways here: the file is malformed, failed to render or is
622
+ too large to draw (previewFailed); its type has no viewer here
623
+ (an archive, a slide deck); or it is a Word or Excel file whose
624
+ bytes could not be read to draw it. Either way the original file
625
+ still downloads fine. A page that cannot be run and a picture
626
+ that cannot be drawn from the file's own text show that text
627
+ instead (showsCode). */
628
+ jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center", "data-testid": previewFailed ? 'binary-canvas-preview-error' : 'binary-canvas-fallback', children: [jsx(FileArchive, { className: "h-10 w-10 text-gray-400" }), jsx("p", { className: "text-sm text-gray-600", children: previewFailed
629
+ ? t(tooLargeToPreview
630
+ ? 'canvasBinaryCanvas.previewTooLarge'
631
+ : 'canvasBinaryCanvas.previewFailed')
632
+ : t('canvasBinaryCanvas.previewUnavailable') })] }))] })] })] }));
115
633
  }
116
634
 
117
635
  export { BinaryCanvasComponent };