@mcp-use/inspector 12.0.4-canary.0 → 20.0.0-beta.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 (816) hide show
  1. package/README.md +39 -6
  2. package/dist/cdn/AnimatePresence-B4HhIdgq.js +393 -0
  3. package/dist/cdn/ChatTab-5ya_YTFV.js +13218 -0
  4. package/dist/cdn/CheckboxIndicator-BF2cKfbA.js +251 -0
  5. package/dist/cdn/ConnectionSettingsForm-iwNW86ZU.js +873 -0
  6. package/dist/cdn/ConnectionSettingsTab-CeK83dxn.js +145 -0
  7. package/dist/cdn/ElicitationTab-upPXq2q7.js +654 -0
  8. package/dist/cdn/FormContext-Cl51-7O7.js +135 -0
  9. package/dist/cdn/InspectorContext-DzXtgyTx.js +143 -0
  10. package/dist/cdn/JSONDisplay-D3RcyO9z.js +324 -0
  11. package/dist/cdn/ListTabHeader-8lULn-90.js +88 -0
  12. package/dist/cdn/ManufactOAuthCallback-DEM8mhWD.js +31 -0
  13. package/dist/cdn/NotificationsTab-CWopTIzT.js +290 -0
  14. package/dist/cdn/OAuthCallback-BxuOVgdb.js +58 -0
  15. package/dist/cdn/PromptsTab-Cspfnl6n.js +4400 -0
  16. package/dist/cdn/ResourcesTab-BczUMFil.js +584 -0
  17. package/dist/cdn/SamplingTab-6u5s845G.js +658 -0
  18. package/dist/cdn/ServerMetadataTab-DS0eiyyD.js +244 -0
  19. package/dist/cdn/StatusIcon-BGXOEU2u.js +66 -0
  20. package/dist/cdn/ToolsTab-CUhwP4rZ.js +2067 -0
  21. package/dist/cdn/ViewPreview-CxJc1Kht.js +237 -0
  22. package/dist/cdn/WidgetDebugContext-D4usL_MA.js +324 -0
  23. package/dist/cdn/WidgetWrapper-BJJtLqMb.js +2211 -0
  24. package/dist/cdn/apple-touch-icon.png +0 -0
  25. package/dist/cdn/basePath-B8HuhIMu.js +25 -0
  26. package/dist/cdn/bell-CGjAO_0s.js +10 -0
  27. package/dist/cdn/browser-CbQIH4w2.js +42 -0
  28. package/dist/cdn/brush-B_mKhyxG.js +17 -0
  29. package/dist/cdn/bundle-mjs-B0nmHDtp.js +1953 -0
  30. package/dist/cdn/card-DqjqAq0o.js +41 -0
  31. package/dist/cdn/cfWorker-Bxcs9rNe.js +10799 -0
  32. package/dist/cdn/checkbox-B4oUG6Rr.js +20 -0
  33. package/dist/cdn/chunk-BO2N2NFS-Cy167e0X.js +17500 -0
  34. package/dist/cdn/chunk-QUQL4437-XnDcYQEx.js +1508 -0
  35. package/dist/cdn/clock-CmUbSx_B.js +12 -0
  36. package/dist/cdn/code-V_0nf5rg.js +10 -0
  37. package/dist/cdn/createLucideIcon-C5fZZ6oB.js +38 -0
  38. package/dist/cdn/dialog-Dnl-pZsY.js +1028 -0
  39. package/dist/cdn/dist-DjXr_YO3.js +616 -0
  40. package/dist/cdn/dist-mRDqCgKU.js +2305 -0
  41. package/dist/cdn/external-link-CjmfT6rW.js +17 -0
  42. package/dist/cdn/eye-B7H96av8.js +29 -0
  43. package/dist/cdn/favicon-96x96.png +0 -0
  44. package/dist/cdn/favicon-black.svg +5 -8
  45. package/dist/cdn/favicon-white.svg +4 -7
  46. package/dist/cdn/favicon.ico +0 -0
  47. package/dist/cdn/favicon.svg +5 -0
  48. package/dist/cdn/folder-open-B3lu2rG_.js +7 -0
  49. package/dist/cdn/hash-BVQnWi7q.js +33 -0
  50. package/dist/cdn/highlighted-body-OFNGDK62-CoReNbTX.js +36 -0
  51. package/dist/cdn/history-Csw4rb44.js +17 -0
  52. package/dist/cdn/index-browser-CVUwR-Bu.js +1934 -0
  53. package/dist/cdn/info-CNiOwqkf.js +19 -0
  54. package/dist/cdn/input-BLxOA7V-.js +10215 -0
  55. package/dist/cdn/inspector-settings-layout-0VDsjeqb.js +4 -0
  56. package/dist/cdn/inspector.css +1 -2
  57. package/dist/cdn/inspector.js +10854 -133726
  58. package/dist/cdn/jsx-runtime-CIxvMpEo.js +180 -0
  59. package/dist/cdn/label-CBvG613A.js +60 -0
  60. package/dist/cdn/loader-circle-BLy9A_pp.js +7 -0
  61. package/dist/cdn/manufact-auth-0TVxpeTA.js +387 -0
  62. package/dist/cdn/maximize-2-CH5Lq90B.js +21 -0
  63. package/dist/cdn/maximize-BALCV_ep.js +21 -0
  64. package/dist/cdn/mermaid-GHXKKRXX-DgVIbk-D.js +2 -0
  65. package/dist/cdn/message-square-BnxdpJxZ.js +7 -0
  66. package/dist/cdn/not-found-BcNNsTjS.js +34 -0
  67. package/dist/cdn/pdf-CxFT9FER.js +16291 -0
  68. package/dist/cdn/play-vuZ5PLnI.js +7 -0
  69. package/dist/cdn/popover-C_SSrXT0.js +2005 -0
  70. package/dist/cdn/react-BIs9pQ3H.js +926 -0
  71. package/dist/cdn/react-yUi9mVK4.js +5411 -0
  72. package/dist/cdn/refresh-cw-BXY-Pa0U.js +21 -0
  73. package/dist/cdn/save-Tgil_AJZ.js +34 -0
  74. package/dist/cdn/schemaHelpers-DTV38jGq.js +16 -0
  75. package/dist/cdn/select-BZ_IoKxg.js +2594 -0
  76. package/dist/cdn/servers-Dm72iTpY.js +26 -0
  77. package/dist/cdn/shared-uMiV6Fx1.js +1700 -0
  78. package/dist/cdn/sheet-CerCdhxz.js +78 -0
  79. package/dist/cdn/site.webmanifest +21 -0
  80. package/dist/cdn/sparkles-BntO2rDR.js +23 -0
  81. package/dist/cdn/spinner-CWcJhIY_.js +15 -0
  82. package/dist/cdn/square-check-big-BvwQ17Bl.js +10 -0
  83. package/dist/cdn/switch-DtQOLb9R.js +664 -0
  84. package/dist/cdn/tabs-subtle-C5cy35sY.js +787 -0
  85. package/dist/cdn/telemetry-Ct6pVkM1.js +240 -0
  86. package/dist/cdn/textarea-Bj-CT7hC.js +14 -0
  87. package/dist/cdn/trash-2-RwpJY5SL.js +25 -0
  88. package/dist/cdn/useAriaLabelledBy-Bm9qHGK6.js +29 -0
  89. package/dist/cdn/useCompositeItem-CNJ6MXdi.js +26 -0
  90. package/dist/cdn/useConfig-CwxZ6Quj.js +208 -0
  91. package/dist/cdn/useHostedSession-BA39Aegc.js +153 -0
  92. package/dist/cdn/useMCPPrompts-D3_Hla_z.js +104 -0
  93. package/dist/cdn/useSavedRequests-Ci2I919u.js +51 -0
  94. package/dist/cdn/useViewHostProps-C7vjco2m.js +348 -0
  95. package/dist/cdn/web-app-manifest-192x192.png +0 -0
  96. package/dist/cdn/web-app-manifest-512x512.png +0 -0
  97. package/dist/cdn/wrench-DzGmCfnb.js +7 -0
  98. package/dist/cdn/x-C3vRQIYu.js +10 -0
  99. package/dist/cdn/zap-Mb-pbw2X.js +10 -0
  100. package/dist/cli.js +1060 -3601
  101. package/dist/client/auth/manufact-auth.d.ts +30 -0
  102. package/dist/client/auth/manufact-auth.d.ts.map +1 -0
  103. package/dist/client/chat-history/ChatHistoryHeader.d.ts +4 -0
  104. package/dist/client/chat-history/ChatHistoryHeader.d.ts.map +1 -0
  105. package/dist/client/chat-history/ChatHistoryPanel.d.ts +28 -0
  106. package/dist/client/chat-history/ChatHistoryPanel.d.ts.map +1 -0
  107. package/dist/client/chat-history/ChatHistoryRail.d.ts +5 -0
  108. package/dist/client/chat-history/ChatHistoryRail.d.ts.map +1 -0
  109. package/dist/client/chat-history/ChatList.d.ts +18 -0
  110. package/dist/client/chat-history/ChatList.d.ts.map +1 -0
  111. package/dist/client/chat-history/ChatTitleReveal.d.ts +10 -0
  112. package/dist/client/chat-history/ChatTitleReveal.d.ts.map +1 -0
  113. package/dist/client/chat-history/chat-events-to-inspector-messages.d.ts +13 -0
  114. package/dist/client/chat-history/chat-events-to-inspector-messages.d.ts.map +1 -0
  115. package/dist/client/chat-history/chat-title.d.ts +10 -0
  116. package/dist/client/chat-history/chat-title.d.ts.map +1 -0
  117. package/dist/client/chat-history/providers/local-storage.d.ts +21 -0
  118. package/dist/client/chat-history/providers/local-storage.d.ts.map +1 -0
  119. package/dist/client/chat-history/types.d.ts +39 -0
  120. package/dist/client/chat-history/types.d.ts.map +1 -0
  121. package/dist/client/chat-history/useChatHistory.d.ts +20 -0
  122. package/dist/client/chat-history/useChatHistory.d.ts.map +1 -0
  123. package/dist/client/chat-history/useChatTitleGeneration.d.ts +17 -0
  124. package/dist/client/chat-history/useChatTitleGeneration.d.ts.map +1 -0
  125. package/dist/client/components/AddToClientDropdown.d.ts.map +1 -1
  126. package/dist/client/components/ChatTab.d.ts +28 -3
  127. package/dist/client/components/ChatTab.d.ts.map +1 -1
  128. package/dist/client/components/IframeConsole.d.ts.map +1 -1
  129. package/dist/client/components/MCPAppsDebugControls.d.ts +2 -18
  130. package/dist/client/components/MCPAppsDebugControls.d.ts.map +1 -1
  131. package/dist/client/components/PromptsTab.d.ts +1 -1
  132. package/dist/client/components/PromptsTab.d.ts.map +1 -1
  133. package/dist/client/components/ResourcesTab.d.ts +1 -1
  134. package/dist/client/components/ResourcesTab.d.ts.map +1 -1
  135. package/dist/client/components/ToolsTab.d.ts +3 -3
  136. package/dist/client/components/ToolsTab.d.ts.map +1 -1
  137. package/dist/client/components/chat/AssistantMessage.d.ts +2 -1
  138. package/dist/client/components/chat/AssistantMessage.d.ts.map +1 -1
  139. package/dist/client/components/chat/ChatHeader.d.ts +20 -2
  140. package/dist/client/components/chat/ChatHeader.d.ts.map +1 -1
  141. package/dist/client/components/chat/ChatInput.d.ts +6 -2
  142. package/dist/client/components/chat/ChatInput.d.ts.map +1 -1
  143. package/dist/client/components/chat/ChatInputArea.d.ts +31 -3
  144. package/dist/client/components/chat/ChatInputArea.d.ts.map +1 -1
  145. package/dist/client/components/chat/ChatLandingForm.d.ts +5 -42
  146. package/dist/client/components/chat/ChatLandingForm.d.ts.map +1 -1
  147. package/dist/client/components/chat/ChatScrollToBottomButton.d.ts +7 -0
  148. package/dist/client/components/chat/ChatScrollToBottomButton.d.ts.map +1 -0
  149. package/dist/client/components/chat/ChatTraceView.d.ts +7 -0
  150. package/dist/client/components/chat/ChatTraceView.d.ts.map +1 -0
  151. package/dist/client/components/chat/ConfigurationDialog.d.ts +12 -2
  152. package/dist/client/components/chat/ConfigurationDialog.d.ts.map +1 -1
  153. package/dist/client/components/chat/ConfigureEmptyState.d.ts +2 -5
  154. package/dist/client/components/chat/ConfigureEmptyState.d.ts.map +1 -1
  155. package/dist/client/components/chat/CopyButton.d.ts.map +1 -1
  156. package/dist/client/components/chat/FloatingChatElicitation.d.ts +10 -0
  157. package/dist/client/components/chat/FloatingChatElicitation.d.ts.map +1 -0
  158. package/dist/client/components/chat/MessageList.d.ts +6 -11
  159. package/dist/client/components/chat/MessageList.d.ts.map +1 -1
  160. package/dist/client/components/chat/MessageMetaActions.d.ts +7 -0
  161. package/dist/client/components/chat/MessageMetaActions.d.ts.map +1 -0
  162. package/dist/client/components/chat/PromptsDropdown.d.ts +1 -1
  163. package/dist/client/components/chat/PromptsDropdown.d.ts.map +1 -1
  164. package/dist/client/components/chat/StreamingAssistantContent.d.ts +7 -0
  165. package/dist/client/components/chat/StreamingAssistantContent.d.ts.map +1 -0
  166. package/dist/client/components/chat/SystemPromptButton.d.ts +11 -0
  167. package/dist/client/components/chat/SystemPromptButton.d.ts.map +1 -0
  168. package/dist/client/components/chat/ToolCallDisplay.d.ts.map +1 -1
  169. package/dist/client/components/chat/ToolResultRenderer.d.ts +2 -9
  170. package/dist/client/components/chat/ToolResultRenderer.d.ts.map +1 -1
  171. package/dist/client/components/chat/ToolSelector.d.ts.map +1 -1
  172. package/dist/client/components/chat/UserMessage.d.ts +2 -1
  173. package/dist/client/components/chat/UserMessage.d.ts.map +1 -1
  174. package/dist/client/components/chat/chat-bar-styles.d.ts +6 -0
  175. package/dist/client/components/chat/chat-bar-styles.d.ts.map +1 -0
  176. package/dist/client/components/chat/conversion.d.ts +1 -1
  177. package/dist/client/components/chat/conversion.d.ts.map +1 -1
  178. package/dist/client/components/chat/freeTier.d.ts +11 -0
  179. package/dist/client/components/chat/freeTier.d.ts.map +1 -1
  180. package/dist/client/components/chat/providerMeta.d.ts +10 -1
  181. package/dist/client/components/chat/providerMeta.d.ts.map +1 -1
  182. package/dist/client/components/chat/streamdown-code-slim.d.ts +4 -0
  183. package/dist/client/components/chat/streamdown-code-slim.d.ts.map +1 -0
  184. package/dist/client/components/chat/system-prompt/local-storage.d.ts +5 -0
  185. package/dist/client/components/chat/system-prompt/local-storage.d.ts.map +1 -0
  186. package/dist/client/components/chat/system-prompt/types.d.ts +8 -0
  187. package/dist/client/components/chat/system-prompt/types.d.ts.map +1 -0
  188. package/dist/client/components/chat/system-prompt/useLocalSystemPrompt.d.ts +3 -0
  189. package/dist/client/components/chat/system-prompt/useLocalSystemPrompt.d.ts.map +1 -0
  190. package/dist/client/components/chat/system-prompt-default.d.ts +2 -0
  191. package/dist/client/components/chat/system-prompt-default.d.ts.map +1 -0
  192. package/dist/client/components/chat/trace.d.ts +84 -0
  193. package/dist/client/components/chat/trace.d.ts.map +1 -0
  194. package/dist/client/components/chat/types.d.ts +2 -1
  195. package/dist/client/components/chat/types.d.ts.map +1 -1
  196. package/dist/client/components/chat/useChatMessages.d.ts +4 -0
  197. package/dist/client/components/chat/useChatMessages.d.ts.map +1 -1
  198. package/dist/client/components/chat/useChatMessagesClientSide.d.ts +14 -2
  199. package/dist/client/components/chat/useChatMessagesClientSide.d.ts.map +1 -1
  200. package/dist/client/components/chat/useChatScrollToBottom.d.ts +13 -0
  201. package/dist/client/components/chat/useChatScrollToBottom.d.ts.map +1 -0
  202. package/dist/client/components/chat/useConfig.d.ts +2 -2
  203. package/dist/client/components/chat/useConfig.d.ts.map +1 -1
  204. package/dist/client/components/chat/useHostedChatMode.d.ts +14 -0
  205. package/dist/client/components/chat/useHostedChatMode.d.ts.map +1 -0
  206. package/dist/client/components/chat/useManagedCloudModel.d.ts +14 -0
  207. package/dist/client/components/chat/useManagedCloudModel.d.ts.map +1 -0
  208. package/dist/client/components/chat/utils.d.ts +0 -4
  209. package/dist/client/components/chat/utils.d.ts.map +1 -1
  210. package/dist/client/components/elicitation/shared/ElicitationAskUserPanel.d.ts +12 -0
  211. package/dist/client/components/elicitation/shared/ElicitationAskUserPanel.d.ts.map +1 -0
  212. package/dist/client/components/elicitation/shared/elicitationToAskUserQuestions.d.ts +9 -0
  213. package/dist/client/components/elicitation/shared/elicitationToAskUserQuestions.d.ts.map +1 -0
  214. package/dist/client/components/prompts/PromptExecutionPanel.d.ts +1 -1
  215. package/dist/client/components/prompts/PromptExecutionPanel.d.ts.map +1 -1
  216. package/dist/client/components/prompts/PromptInputForm.d.ts +1 -1
  217. package/dist/client/components/prompts/PromptInputForm.d.ts.map +1 -1
  218. package/dist/client/components/prompts/PromptResultDisplay.d.ts +1 -1
  219. package/dist/client/components/prompts/PromptResultDisplay.d.ts.map +1 -1
  220. package/dist/client/components/prompts/PromptsList.d.ts +1 -1
  221. package/dist/client/components/prompts/PromptsList.d.ts.map +1 -1
  222. package/dist/client/components/prompts/SavedPromptsList.d.ts.map +1 -1
  223. package/dist/client/components/resources/PropsConfigDialog.d.ts +1 -1
  224. package/dist/client/components/resources/PropsConfigDialog.d.ts.map +1 -1
  225. package/dist/client/components/resources/ResourceResultDisplay.d.ts +1 -1
  226. package/dist/client/components/resources/ResourceResultDisplay.d.ts.map +1 -1
  227. package/dist/client/components/resources/ResourcesList.d.ts +1 -1
  228. package/dist/client/components/resources/ResourcesList.d.ts.map +1 -1
  229. package/dist/client/components/shared/CollapsibleJSON.d.ts +6 -0
  230. package/dist/client/components/shared/CollapsibleJSON.d.ts.map +1 -0
  231. package/dist/client/components/shared/InspectorScrollArea.d.ts +9 -0
  232. package/dist/client/components/shared/InspectorScrollArea.d.ts.map +1 -0
  233. package/dist/client/components/shared/JSONDisplay.d.ts +5 -1
  234. package/dist/client/components/shared/JSONDisplay.d.ts.map +1 -1
  235. package/dist/client/components/shared/ListItem.d.ts +1 -3
  236. package/dist/client/components/shared/ListItem.d.ts.map +1 -1
  237. package/dist/client/components/shared/ListTabHeader.d.ts +4 -1
  238. package/dist/client/components/shared/ListTabHeader.d.ts.map +1 -1
  239. package/dist/client/components/shared/MarkdownRenderer.d.ts.map +1 -1
  240. package/dist/client/components/shared/SearchTabHeader.d.ts +28 -0
  241. package/dist/client/components/shared/SearchTabHeader.d.ts.map +1 -0
  242. package/dist/client/components/shared/StatusIcon.d.ts +12 -0
  243. package/dist/client/components/shared/StatusIcon.d.ts.map +1 -0
  244. package/dist/client/components/shared/index.d.ts +4 -1
  245. package/dist/client/components/shared/index.d.ts.map +1 -1
  246. package/dist/client/components/tools/SavedRequestsList.d.ts.map +1 -1
  247. package/dist/client/components/tools/ToolExecutionPanel.d.ts +1 -1
  248. package/dist/client/components/tools/ToolExecutionPanel.d.ts.map +1 -1
  249. package/dist/client/components/tools/ToolInputForm.d.ts +1 -1
  250. package/dist/client/components/tools/ToolInputForm.d.ts.map +1 -1
  251. package/dist/client/components/tools/ToolResultDisplay.d.ts +0 -6
  252. package/dist/client/components/tools/ToolResultDisplay.d.ts.map +1 -1
  253. package/dist/client/components/tools/ToolsList.d.ts +1 -1
  254. package/dist/client/components/tools/ToolsList.d.ts.map +1 -1
  255. package/dist/client/components/tools/useToolExecution.d.ts +26 -0
  256. package/dist/client/components/tools/useToolExecution.d.ts.map +1 -0
  257. package/dist/client/components/tools/useToolsTabNavigation.d.ts +35 -0
  258. package/dist/client/components/tools/useToolsTabNavigation.d.ts.map +1 -0
  259. package/dist/client/components/ui/WidgetWrapper.d.ts +2 -2
  260. package/dist/client/components/ui/WidgetWrapper.d.ts.map +1 -1
  261. package/dist/client/components/ui/alert-dialog.d.ts +8 -5
  262. package/dist/client/components/ui/alert-dialog.d.ts.map +1 -1
  263. package/dist/client/components/ui/ask-user-questions.d.ts +80 -0
  264. package/dist/client/components/ui/ask-user-questions.d.ts.map +1 -0
  265. package/dist/client/components/ui/badge.d.ts +32 -7
  266. package/dist/client/components/ui/badge.d.ts.map +1 -1
  267. package/dist/client/components/ui/button.d.ts +31 -11
  268. package/dist/client/components/ui/button.d.ts.map +1 -1
  269. package/dist/client/components/ui/chat-message.d.ts +23 -0
  270. package/dist/client/components/ui/chat-message.d.ts.map +1 -0
  271. package/dist/client/components/ui/checkbox.d.ts +2 -3
  272. package/dist/client/components/ui/checkbox.d.ts.map +1 -1
  273. package/dist/client/components/ui/client-icons.d.ts +0 -4
  274. package/dist/client/components/ui/client-icons.d.ts.map +1 -1
  275. package/dist/client/components/ui/command.d.ts +13 -64
  276. package/dist/client/components/ui/command.d.ts.map +1 -1
  277. package/dist/client/components/ui/dialog.d.ts +36 -12
  278. package/dist/client/components/ui/dialog.d.ts.map +1 -1
  279. package/dist/client/components/ui/dropdown-menu.d.ts +17 -48
  280. package/dist/client/components/ui/dropdown-menu.d.ts.map +1 -1
  281. package/dist/client/components/ui/dropdown.d.ts +30 -0
  282. package/dist/client/components/ui/dropdown.d.ts.map +1 -0
  283. package/dist/client/components/ui/file-thumbnail.d.ts +9 -0
  284. package/dist/client/components/ui/file-thumbnail.d.ts.map +1 -0
  285. package/dist/client/components/ui/label.d.ts +1 -2
  286. package/dist/client/components/ui/label.d.ts.map +1 -1
  287. package/dist/client/components/ui/menu-item.d.ts +52 -0
  288. package/dist/client/components/ui/menu-item.d.ts.map +1 -0
  289. package/dist/client/components/ui/mesh-tab-background.d.ts +10 -0
  290. package/dist/client/components/ui/mesh-tab-background.d.ts.map +1 -0
  291. package/dist/client/components/ui/not-found.d.ts.map +1 -1
  292. package/dist/client/components/ui/popover.d.ts +4 -5
  293. package/dist/client/components/ui/popover.d.ts.map +1 -1
  294. package/dist/client/components/ui/scroll-area.d.ts +4 -0
  295. package/dist/client/components/ui/scroll-area.d.ts.map +1 -0
  296. package/dist/client/components/ui/select.d.ts +50 -9
  297. package/dist/client/components/ui/select.d.ts.map +1 -1
  298. package/dist/client/components/ui/sheet.d.ts +9 -7
  299. package/dist/client/components/ui/sheet.d.ts.map +1 -1
  300. package/dist/client/components/ui/skeleton.d.ts +4 -0
  301. package/dist/client/components/ui/skeleton.d.ts.map +1 -0
  302. package/dist/client/components/ui/spinner.d.ts +1 -1
  303. package/dist/client/components/ui/spinner.d.ts.map +1 -1
  304. package/dist/client/components/ui/switch.d.ts +19 -7
  305. package/dist/client/components/ui/switch.d.ts.map +1 -1
  306. package/dist/client/components/ui/tabs-subtle.d.ts +25 -0
  307. package/dist/client/components/ui/tabs-subtle.d.ts.map +1 -0
  308. package/dist/client/components/ui/tooltip.d.ts +41 -6
  309. package/dist/client/components/ui/tooltip.d.ts.map +1 -1
  310. package/dist/client/context/InspectorContext.d.ts +6 -10
  311. package/dist/client/context/InspectorContext.d.ts.map +1 -1
  312. package/dist/client/context/WidgetDebugContext.d.ts +2 -3
  313. package/dist/client/context/WidgetDebugContext.d.ts.map +1 -1
  314. package/dist/client/hooks/use-merge-split.d.ts +36 -0
  315. package/dist/client/hooks/use-merge-split.d.ts.map +1 -0
  316. package/dist/client/hooks/use-proximity-hover-index.d.ts +27 -0
  317. package/dist/client/hooks/use-proximity-hover-index.d.ts.map +1 -0
  318. package/dist/client/hooks/use-proximity-hover.d.ts +26 -0
  319. package/dist/client/hooks/use-proximity-hover.d.ts.map +1 -0
  320. package/dist/client/hooks/use-touch-primary.d.ts +2 -0
  321. package/dist/client/hooks/use-touch-primary.d.ts.map +1 -0
  322. package/dist/client/hooks/useHostedSession.d.ts +4 -14
  323. package/dist/client/hooks/useHostedSession.d.ts.map +1 -1
  324. package/dist/client/hooks/useMCPPrompts.d.ts +1 -1
  325. package/dist/client/hooks/useMCPPrompts.d.ts.map +1 -1
  326. package/dist/client/hooks/useMcpAppsHostContext.d.ts +2 -2
  327. package/dist/client/hooks/useMcpAppsHostContext.d.ts.map +1 -1
  328. package/dist/client/hooks/usePropsLLM.d.ts +1 -1
  329. package/dist/client/hooks/usePropsLLM.d.ts.map +1 -1
  330. package/dist/client/hooks/useSavedRequests.d.ts +6 -0
  331. package/dist/client/hooks/useSavedRequests.d.ts.map +1 -0
  332. package/dist/client/hooks/useViewHostProps.d.ts +19 -0
  333. package/dist/client/hooks/useViewHostProps.d.ts.map +1 -0
  334. package/dist/client/index.d.ts +19 -2
  335. package/dist/client/index.d.ts.map +1 -1
  336. package/dist/client/index.js +19306 -16141
  337. package/dist/client/lib/elevated.d.ts +28 -0
  338. package/dist/client/lib/elevated.d.ts.map +1 -0
  339. package/dist/client/lib/font-weight.d.ts +10 -0
  340. package/dist/client/lib/font-weight.d.ts.map +1 -0
  341. package/dist/client/lib/icon-context.d.ts +15 -0
  342. package/dist/client/lib/icon-context.d.ts.map +1 -0
  343. package/dist/client/lib/shape-context.d.ts +21 -0
  344. package/dist/client/lib/shape-context.d.ts.map +1 -0
  345. package/dist/client/lib/springs.d.ts +32 -0
  346. package/dist/client/lib/springs.d.ts.map +1 -0
  347. package/dist/client/lib/surface-classes.d.ts +2 -0
  348. package/dist/client/lib/surface-classes.d.ts.map +1 -0
  349. package/dist/client/lib/surface-context.d.ts +7 -0
  350. package/dist/client/lib/surface-context.d.ts.map +1 -0
  351. package/dist/client/lib/utils.d.ts +1 -1
  352. package/dist/client/lib/utils.d.ts.map +1 -1
  353. package/dist/client/mcp-apps/csp.d.ts +26 -0
  354. package/dist/client/mcp-apps/csp.d.ts.map +1 -0
  355. package/dist/client/mcp-apps/debug/csp-suggestions.d.ts +17 -0
  356. package/dist/client/mcp-apps/debug/csp-suggestions.d.ts.map +1 -0
  357. package/dist/client/mcp-apps/logging-transport.d.ts +13 -0
  358. package/dist/client/mcp-apps/logging-transport.d.ts.map +1 -0
  359. package/dist/client/rpc-traffic-coalesce.d.ts +7 -0
  360. package/dist/client/rpc-traffic-coalesce.d.ts.map +1 -0
  361. package/dist/client/rpc-traffic-store.d.ts +37 -0
  362. package/dist/client/rpc-traffic-store.d.ts.map +1 -0
  363. package/dist/client/telemetry/capture.d.ts +7 -0
  364. package/dist/client/telemetry/capture.d.ts.map +1 -0
  365. package/dist/client/telemetry/events.d.ts +1 -1
  366. package/dist/client/telemetry/events.d.ts.map +1 -1
  367. package/dist/client/telemetry/index.d.ts +2 -1
  368. package/dist/client/telemetry/index.d.ts.map +1 -1
  369. package/dist/client/telemetry/init.d.ts +2 -0
  370. package/dist/client/telemetry/init.d.ts.map +1 -0
  371. package/dist/client/telemetry/utils.d.ts +5 -0
  372. package/dist/client/telemetry/utils.d.ts.map +1 -1
  373. package/dist/client/types/message-content-block.d.ts +19 -0
  374. package/dist/client/types/message-content-block.d.ts.map +1 -0
  375. package/dist/client/types/pending-requests.d.ts +17 -0
  376. package/dist/client/types/pending-requests.d.ts.map +1 -0
  377. package/dist/client/utils/basePath.d.ts +34 -0
  378. package/dist/client/utils/basePath.d.ts.map +1 -0
  379. package/dist/client/utils/browser.d.ts +5 -0
  380. package/dist/client/utils/browser.d.ts.map +1 -0
  381. package/dist/client/utils/format.d.ts +4 -0
  382. package/dist/client/utils/format.d.ts.map +1 -0
  383. package/dist/client/utils/highlightJson.d.ts +11 -0
  384. package/dist/client/utils/highlightJson.d.ts.map +1 -0
  385. package/dist/client/utils/jsonUtils.d.ts +4 -0
  386. package/dist/client/utils/jsonUtils.d.ts.map +1 -1
  387. package/dist/client/utils/mcpClientUtils.d.ts.map +1 -1
  388. package/dist/client/utils/servers.d.ts +14 -0
  389. package/dist/client/utils/servers.d.ts.map +1 -0
  390. package/dist/server/cdn-shell.d.ts +18 -0
  391. package/dist/server/cdn-shell.d.ts.map +1 -0
  392. package/dist/server/cdn-shell.js +10 -0
  393. package/dist/server/chunk-5B3SXGZP.js +43 -0
  394. package/dist/server/chunk-6XWDZEFF.js +194 -0
  395. package/dist/server/chunk-ESODOPDD.js +50 -0
  396. package/dist/server/chunk-IKTZUWSX.js +0 -0
  397. package/dist/server/{chunk-57KIBVKX.js → chunk-J67FVPHF.js} +27 -26
  398. package/dist/server/chunk-K2F2AJOI.js +619 -0
  399. package/dist/server/chunk-K2V2SDQD.js +40 -0
  400. package/dist/server/{chunk-ZPHNDECP.js → chunk-THQ67TSE.js} +31 -32
  401. package/dist/server/chunk-TPHRVELX.js +130 -0
  402. package/dist/server/chunk-WFT4JHYI.js +24 -0
  403. package/dist/server/cli.js +23 -25
  404. package/dist/server/create-dev-api-app.d.ts +4 -0
  405. package/dist/server/create-dev-api-app.d.ts.map +1 -0
  406. package/dist/server/create-dev-api-app.js +11 -0
  407. package/dist/server/favicon-links.d.ts +12 -0
  408. package/dist/server/favicon-links.d.ts.map +1 -0
  409. package/dist/server/favicon-links.js +11 -0
  410. package/dist/server/favicon-static.d.ts +4 -0
  411. package/dist/server/favicon-static.d.ts.map +1 -0
  412. package/dist/server/favicon-static.js +8 -0
  413. package/dist/server/index.d.ts +3 -4
  414. package/dist/server/index.d.ts.map +1 -1
  415. package/dist/server/index.js +13 -17
  416. package/dist/server/middleware.d.ts +14 -3
  417. package/dist/server/middleware.d.ts.map +1 -1
  418. package/dist/server/middleware.js +9 -9
  419. package/dist/server/proxy/index.d.ts +3 -0
  420. package/dist/server/proxy/index.d.ts.map +1 -0
  421. package/dist/server/proxy/index.js +12 -0
  422. package/dist/server/proxy/mcp-proxy.d.ts +99 -0
  423. package/dist/server/proxy/mcp-proxy.d.ts.map +1 -0
  424. package/dist/server/proxy/mcp-proxy.js +8 -0
  425. package/dist/server/proxy/oauth-proxy.d.ts +26 -0
  426. package/dist/server/proxy/oauth-proxy.d.ts.map +1 -0
  427. package/dist/server/proxy/oauth-proxy.js +9 -0
  428. package/dist/server/proxy-routes.d.ts +16 -0
  429. package/dist/server/proxy-routes.d.ts.map +1 -0
  430. package/dist/server/proxy-routes.js +10 -0
  431. package/dist/server/rpc-log-bus.js +73 -3
  432. package/dist/server/server.d.ts +3 -8
  433. package/dist/server/server.d.ts.map +1 -1
  434. package/dist/server/server.js +15 -92
  435. package/dist/server/version.js +1 -1
  436. package/dist/server/vite-dev-api-plugin.d.ts +4 -0
  437. package/dist/server/vite-dev-api-plugin.d.ts.map +1 -0
  438. package/dist/server/vite-dev-api-plugin.js +30 -0
  439. package/dist/web/apple-touch-icon.png +0 -0
  440. package/dist/web/assets/AnimatePresence-CthXziG2.js +9 -0
  441. package/dist/web/assets/ChatTab-CiAqtqhj.js +460 -0
  442. package/dist/web/assets/ConnectionSettingsTab-CTh6MFKE.js +1 -0
  443. package/dist/web/assets/ElicitationTab-B3Eg0_Jm.js +1 -0
  444. package/dist/web/assets/FormContext-Cqc_A12u.js +1 -0
  445. package/dist/web/assets/ListTabHeader-G-nQX18m.js +1 -0
  446. package/dist/web/assets/ManufactOAuthCallback-B-tdkUA2.js +1 -0
  447. package/dist/web/assets/NotificationsTab-BgLjxuos.js +1 -0
  448. package/dist/web/assets/OAuthCallback-Bp-jLoQs.js +1 -0
  449. package/dist/web/assets/PromptsTab-CA-SZs43.js +61 -0
  450. package/dist/web/assets/ResourcesTab-DdMIW_af.js +2 -0
  451. package/dist/web/assets/SamplingTab-DjyDG01W.js +1 -0
  452. package/dist/web/assets/ServerMetadataTab-Q4PlqP_B.js +1 -0
  453. package/dist/web/assets/ToolsTab-BHk8GCmd.js +8 -0
  454. package/dist/web/assets/ViewPreview-DWtmwzCb.js +1 -0
  455. package/dist/web/assets/WidgetWrapper-B43lqbld.js +34 -0
  456. package/dist/web/assets/brush--0LobUi4.js +1 -0
  457. package/dist/web/assets/bundle-mjs-8puS6ou7.js +1 -0
  458. package/dist/web/assets/checkbox-_GzEPQic.js +1 -0
  459. package/dist/web/assets/chunk-BO2N2NFS-BdIeB5Lr.js +131 -0
  460. package/dist/web/assets/code-tME-5H6D.js +1 -0
  461. package/dist/web/assets/createLucideIcon-B3b8EU0b.js +1 -0
  462. package/dist/web/assets/dist-DQjEDTKs.js +21 -0
  463. package/dist/web/assets/highlighted-body-OFNGDK62-Dp3e1QHL.js +1 -0
  464. package/dist/web/assets/index-Bbn-6QR2.js +475 -0
  465. package/dist/web/assets/index-BjH-Qp85.css +1 -0
  466. package/dist/web/assets/input-CjmxOFr6.js +1 -0
  467. package/dist/web/assets/inspector-settings-layout-yjKRJDai.js +1 -0
  468. package/dist/web/assets/jsx-runtime-Cjj9sGSy.js +1 -0
  469. package/dist/web/assets/label-B5Q_Zr8M.js +1 -0
  470. package/dist/web/assets/maximize-2-BTT9QQU9.js +1 -0
  471. package/dist/web/assets/maximize-_O55kFcr.js +1 -0
  472. package/dist/web/assets/mermaid-GHXKKRXX-yq1lkD3x.js +1 -0
  473. package/dist/web/assets/pdf-C3cfS_Ha.js +54 -0
  474. package/dist/web/assets/react-CU_d2d5K.js +1 -0
  475. package/dist/web/assets/refresh-cw-C9wQl8_d.js +1 -0
  476. package/dist/web/assets/save-B-MsgxX9.js +1 -0
  477. package/dist/web/assets/schemaHelpers-DLNTQr_6.js +1 -0
  478. package/dist/web/assets/select-C0xlfLAa.js +1 -0
  479. package/dist/web/assets/shared-Dfwy7nyg.js +1 -0
  480. package/dist/web/assets/sheet-CRPrEqAa.js +1 -0
  481. package/dist/web/assets/sparkles-2OAsc1aP.js +1 -0
  482. package/dist/web/assets/tabs-subtle-Dxgism9f.js +1 -0
  483. package/dist/web/assets/textarea-Ci09-en6.js +1 -0
  484. package/dist/web/assets/useConfig-b1f_iVFH.js +1 -0
  485. package/dist/web/assets/useMCPPrompts-CPskz9af.js +1 -0
  486. package/dist/web/assets/useViewHostProps-BgsQ2yYl.js +1 -0
  487. package/dist/web/assets/zap-Du2Uc5pa.js +1 -0
  488. package/dist/web/favicon-96x96.png +0 -0
  489. package/dist/web/favicon-black.svg +5 -8
  490. package/dist/web/favicon-white.svg +4 -7
  491. package/dist/web/favicon.ico +0 -0
  492. package/dist/web/favicon.svg +5 -0
  493. package/dist/web/index.html +13 -20
  494. package/dist/web/site.webmanifest +21 -0
  495. package/dist/web/web-app-manifest-192x192.png +0 -0
  496. package/dist/web/web-app-manifest-512x512.png +0 -0
  497. package/package.json +29 -30
  498. package/dist/client/components/FullscreenNavbar.d.ts +0 -9
  499. package/dist/client/components/FullscreenNavbar.d.ts.map +0 -1
  500. package/dist/client/components/LoginModal.d.ts +0 -11
  501. package/dist/client/components/LoginModal.d.ts.map +0 -1
  502. package/dist/client/components/MCPAppsRenderer.d.ts +0 -53
  503. package/dist/client/components/MCPAppsRenderer.d.ts.map +0 -1
  504. package/dist/client/components/McpUIRenderer.d.ts +0 -19
  505. package/dist/client/components/McpUIRenderer.d.ts.map +0 -1
  506. package/dist/client/components/OpenAIComponentRenderer.d.ts +0 -51
  507. package/dist/client/components/OpenAIComponentRenderer.d.ts.map +0 -1
  508. package/dist/client/components/chat/InlineElicitationCard.d.ts +0 -10
  509. package/dist/client/components/chat/InlineElicitationCard.d.ts.map +0 -1
  510. package/dist/client/components/chat/MCPUIResource.d.ts +0 -11
  511. package/dist/client/components/chat/MCPUIResource.d.ts.map +0 -1
  512. package/dist/client/components/elicitation/shared/ElicitationFormFields.d.ts +0 -21
  513. package/dist/client/components/elicitation/shared/ElicitationFormFields.d.ts.map +0 -1
  514. package/dist/client/components/elicitation/shared/index.d.ts +0 -3
  515. package/dist/client/components/elicitation/shared/index.d.ts.map +0 -1
  516. package/dist/client/components/elicitation/shared/useElicitationForm.d.ts +0 -23
  517. package/dist/client/components/elicitation/shared/useElicitationForm.d.ts.map +0 -1
  518. package/dist/client/components/logging/JsonRpcLoggerView.d.ts +0 -20
  519. package/dist/client/components/logging/JsonRpcLoggerView.d.ts.map +0 -1
  520. package/dist/client/components/prompts/PromptsTabHeader.d.ts +0 -17
  521. package/dist/client/components/prompts/PromptsTabHeader.d.ts.map +0 -1
  522. package/dist/client/components/prompts/index.d.ts +0 -6
  523. package/dist/client/components/prompts/index.d.ts.map +0 -1
  524. package/dist/client/components/resources/ResourcesTabHeader.d.ts +0 -16
  525. package/dist/client/components/resources/ResourcesTabHeader.d.ts.map +0 -1
  526. package/dist/client/components/resources/index.d.ts +0 -4
  527. package/dist/client/components/resources/index.d.ts.map +0 -1
  528. package/dist/client/components/shared/RpcPanel.d.ts +0 -21
  529. package/dist/client/components/shared/RpcPanel.d.ts.map +0 -1
  530. package/dist/client/components/tools/ToolsTabHeader.d.ts +0 -17
  531. package/dist/client/components/tools/ToolsTabHeader.d.ts.map +0 -1
  532. package/dist/client/components/tools/index.d.ts +0 -7
  533. package/dist/client/components/tools/index.d.ts.map +0 -1
  534. package/dist/client/components/ui/SandboxedIframe.d.ts +0 -64
  535. package/dist/client/components/ui/SandboxedIframe.d.ts.map +0 -1
  536. package/dist/client/components/ui/aurora-background.d.ts +0 -9
  537. package/dist/client/components/ui/aurora-background.d.ts.map +0 -1
  538. package/dist/client/constants/iframe.d.ts +0 -9
  539. package/dist/client/constants/iframe.d.ts.map +0 -1
  540. package/dist/client/constants/index.d.ts +0 -7
  541. package/dist/client/constants/index.d.ts.map +0 -1
  542. package/dist/client/constants/mcp-apps.d.ts +0 -39
  543. package/dist/client/constants/mcp-apps.d.ts.map +0 -1
  544. package/dist/client/hooks/usePrismTheme.d.ts +0 -5
  545. package/dist/client/hooks/usePrismTheme.d.ts.map +0 -1
  546. package/dist/client/lib/use-sandbox-remount-generation.d.ts +0 -9
  547. package/dist/client/lib/use-sandbox-remount-generation.d.ts.map +0 -1
  548. package/dist/client/lib/widget-fullscreen.d.ts +0 -17
  549. package/dist/client/lib/widget-fullscreen.d.ts.map +0 -1
  550. package/dist/client/telemetry/telemetry.d.ts +0 -42
  551. package/dist/client/telemetry/telemetry.d.ts.map +0 -1
  552. package/dist/client/types/elicitation.d.ts +0 -9
  553. package/dist/client/types/elicitation.d.ts.map +0 -1
  554. package/dist/client/utils/clipboard.d.ts +0 -6
  555. package/dist/client/utils/clipboard.d.ts.map +0 -1
  556. package/dist/client/utils/iframeConsoleInterceptor.d.ts +0 -6
  557. package/dist/client/utils/iframeConsoleInterceptor.d.ts.map +0 -1
  558. package/dist/client/utils/widget-detection.d.ts +0 -31
  559. package/dist/client/utils/widget-detection.d.ts.map +0 -1
  560. package/dist/llm/__tests__/messageFormat.test.d.ts +0 -2
  561. package/dist/llm/__tests__/messageFormat.test.d.ts.map +0 -1
  562. package/dist/llm/__tests__/providerToolResults.test.d.ts +0 -2
  563. package/dist/llm/__tests__/providerToolResults.test.d.ts.map +0 -1
  564. package/dist/llm/__tests__/toolResultParts.test.d.ts +0 -2
  565. package/dist/llm/__tests__/toolResultParts.test.d.ts.map +0 -1
  566. package/dist/llm/messageFormat.d.ts +0 -48
  567. package/dist/llm/messageFormat.d.ts.map +0 -1
  568. package/dist/llm/ndjson.d.ts +0 -5
  569. package/dist/llm/ndjson.d.ts.map +0 -1
  570. package/dist/llm/providers/anthropic.d.ts +0 -19
  571. package/dist/llm/providers/anthropic.d.ts.map +0 -1
  572. package/dist/llm/providers/google.d.ts +0 -19
  573. package/dist/llm/providers/google.d.ts.map +0 -1
  574. package/dist/llm/providers/index.d.ts +0 -19
  575. package/dist/llm/providers/index.d.ts.map +0 -1
  576. package/dist/llm/providers/ollama/index.d.ts +0 -18
  577. package/dist/llm/providers/ollama/index.d.ts.map +0 -1
  578. package/dist/llm/providers/ollama/utils.d.ts +0 -7
  579. package/dist/llm/providers/ollama/utils.d.ts.map +0 -1
  580. package/dist/llm/providers/openai.d.ts +0 -19
  581. package/dist/llm/providers/openai.d.ts.map +0 -1
  582. package/dist/llm/schemaUtils.d.ts +0 -2
  583. package/dist/llm/schemaUtils.d.ts.map +0 -1
  584. package/dist/llm/sse.d.ts +0 -15
  585. package/dist/llm/sse.d.ts.map +0 -1
  586. package/dist/llm/toolLoop.d.ts +0 -40
  587. package/dist/llm/toolLoop.d.ts.map +0 -1
  588. package/dist/llm/toolResultParts.d.ts +0 -28
  589. package/dist/llm/toolResultParts.d.ts.map +0 -1
  590. package/dist/llm/types.d.ts +0 -102
  591. package/dist/llm/types.d.ts.map +0 -1
  592. package/dist/server/chunk-63EJEHRP.js +0 -71
  593. package/dist/server/chunk-A4VH7AIP.js +0 -738
  594. package/dist/server/chunk-CVECQ7BJ.js +0 -78
  595. package/dist/server/chunk-IDMHJUEM.js +0 -42
  596. package/dist/server/chunk-KIJYOTYZ.js +0 -322
  597. package/dist/server/chunk-PJNKFX2R.js +0 -2351
  598. package/dist/server/chunk-QQ37LGLJ.js +0 -127
  599. package/dist/server/chunk-R4ISUE7T.js +0 -164
  600. package/dist/server/chunk-UTW44YSH.js +0 -322
  601. package/dist/server/file-utils.d.ts +0 -11
  602. package/dist/server/file-utils.d.ts.map +0 -1
  603. package/dist/server/file-utils.js +0 -11
  604. package/dist/server/routes/mcp-apps.d.ts +0 -12
  605. package/dist/server/routes/mcp-apps.d.ts.map +0 -1
  606. package/dist/server/shared-routes.d.ts +0 -11
  607. package/dist/server/shared-routes.d.ts.map +0 -1
  608. package/dist/server/shared-routes.js +0 -11
  609. package/dist/server/shared-static.d.ts +0 -57
  610. package/dist/server/shared-static.d.ts.map +0 -1
  611. package/dist/server/shared-static.js +0 -11
  612. package/dist/server/shared-utils.d.ts +0 -175
  613. package/dist/server/shared-utils.d.ts.map +0 -1
  614. package/dist/server/shared-utils.js +0 -21
  615. package/dist/server/transport-wrapper.d.ts +0 -6
  616. package/dist/server/transport-wrapper.d.ts.map +0 -1
  617. package/dist/server/transport-wrapper.js +0 -68
  618. package/dist/server/tunnel.d.ts +0 -11
  619. package/dist/server/tunnel.d.ts.map +0 -1
  620. package/dist/server/tunnel.js +0 -13
  621. package/dist/web/assets/1c-D19GPo3L.js +0 -1
  622. package/dist/web/assets/abnf-BR1TaWs-.js +0 -1
  623. package/dist/web/assets/accesslog-CZxiyYuK.js +0 -1
  624. package/dist/web/assets/actionscript-BS1fMZ9M.js +0 -1
  625. package/dist/web/assets/ada-Dhy1EabM.js +0 -1
  626. package/dist/web/assets/angelscript-Gjldi7xi.js +0 -1
  627. package/dist/web/assets/apache-Cx8TUABI.js +0 -1
  628. package/dist/web/assets/applescript-JfBNOabq.js +0 -1
  629. package/dist/web/assets/arcade-E6zGzFSx.js +0 -1
  630. package/dist/web/assets/arduino-D7Y37T_-.js +0 -1
  631. package/dist/web/assets/armasm-vpTNgAzt.js +0 -1
  632. package/dist/web/assets/asciidoc-DaVECsQY.js +0 -1
  633. package/dist/web/assets/aspectj-CdRAuqVM.js +0 -1
  634. package/dist/web/assets/autohotkey-DvZQekH9.js +0 -1
  635. package/dist/web/assets/autoit-oLytjhLA.js +0 -1
  636. package/dist/web/assets/avrasm-5Cf9yIw9.js +0 -1
  637. package/dist/web/assets/awk-Bf_S2P0n.js +0 -1
  638. package/dist/web/assets/axapta-DrOS6bUw.js +0 -1
  639. package/dist/web/assets/bash-DCVWALRV.js +0 -1
  640. package/dist/web/assets/basic-D0GZ3REU.js +0 -1
  641. package/dist/web/assets/bnf-D74FvP-b.js +0 -1
  642. package/dist/web/assets/brainfuck-DwUXsIlY.js +0 -3
  643. package/dist/web/assets/c-CPGbDsng.js +0 -1
  644. package/dist/web/assets/c-like-DLj4FsHF.js +0 -1
  645. package/dist/web/assets/cal-Czm5e2Qe.js +0 -1
  646. package/dist/web/assets/capnproto-CVJ2fID7.js +0 -1
  647. package/dist/web/assets/ceylon-DR5D2yFU.js +0 -1
  648. package/dist/web/assets/clean-CkIuagdM.js +0 -1
  649. package/dist/web/assets/clojure-VwyIEQaz.js +0 -1
  650. package/dist/web/assets/clojure-repl-jCSr2ntH.js +0 -1
  651. package/dist/web/assets/cmake-D2Zl_q65.js +0 -1
  652. package/dist/web/assets/coffeescript-C7Hfrw9O.js +0 -1
  653. package/dist/web/assets/coq-DAxtVI93.js +0 -1
  654. package/dist/web/assets/core-ICctFm9I.js +0 -4
  655. package/dist/web/assets/cos-0GHB8yn1.js +0 -1
  656. package/dist/web/assets/cpp-DdlDGc99.js +0 -1
  657. package/dist/web/assets/crmsh-C0vbH3xd.js +0 -1
  658. package/dist/web/assets/crystal-BloCCkus.js +0 -1
  659. package/dist/web/assets/csharp-YhN72Cls.js +0 -1
  660. package/dist/web/assets/csp-OAeIWScz.js +0 -1
  661. package/dist/web/assets/css-D1ih01yA.js +0 -1
  662. package/dist/web/assets/d-yGrz2xEC.js +0 -1
  663. package/dist/web/assets/dart-C3qG0xpq.js +0 -1
  664. package/dist/web/assets/delphi-CvoiTamH.js +0 -1
  665. package/dist/web/assets/diff-zDaBDf86.js +0 -1
  666. package/dist/web/assets/django-DBYOwnaY.js +0 -1
  667. package/dist/web/assets/dns-BWy_Oa_w.js +0 -1
  668. package/dist/web/assets/dockerfile-Cj5YqQiP.js +0 -1
  669. package/dist/web/assets/dos-AaJBzvG4.js +0 -1
  670. package/dist/web/assets/dsconfig-BgEbyf_A.js +0 -1
  671. package/dist/web/assets/dts-z64kku76.js +0 -1
  672. package/dist/web/assets/dust-C-6seNMG.js +0 -1
  673. package/dist/web/assets/ebnf-DC6yB_8o.js +0 -1
  674. package/dist/web/assets/elixir-DVZgqY4T.js +0 -1
  675. package/dist/web/assets/elm-Css3uC5x.js +0 -1
  676. package/dist/web/assets/erb-C538Iixw.js +0 -1
  677. package/dist/web/assets/erlang-DyDPiXgX.js +0 -1
  678. package/dist/web/assets/erlang-repl-CVIWmQKC.js +0 -1
  679. package/dist/web/assets/excel-BLHu7SPw.js +0 -1
  680. package/dist/web/assets/fix-JPCm4C-u.js +0 -1
  681. package/dist/web/assets/flix-DejUTEwL.js +0 -1
  682. package/dist/web/assets/fortran-CK7Rlzc4.js +0 -1
  683. package/dist/web/assets/fsharp-ZgHvh-ZT.js +0 -1
  684. package/dist/web/assets/gams-BIBfDr3x.js +0 -1
  685. package/dist/web/assets/gauss-DttPF6Qr.js +0 -1
  686. package/dist/web/assets/gcode-BXL931mb.js +0 -1
  687. package/dist/web/assets/gherkin-B7qFZ0rb.js +0 -1
  688. package/dist/web/assets/glsl-BSKhKy8T.js +0 -1
  689. package/dist/web/assets/gml-BcbsDsfr.js +0 -1
  690. package/dist/web/assets/go-BksciLaM.js +0 -1
  691. package/dist/web/assets/golo-D2QFLiUq.js +0 -1
  692. package/dist/web/assets/gradle-BH3VzvYn.js +0 -1
  693. package/dist/web/assets/groovy-Bv9ooqes.js +0 -1
  694. package/dist/web/assets/haml-CacWyVgj.js +0 -1
  695. package/dist/web/assets/handlebars-Cpp3MUlG.js +0 -1
  696. package/dist/web/assets/haskell-BQM3-EaA.js +0 -1
  697. package/dist/web/assets/haxe-Df4nG9sq.js +0 -1
  698. package/dist/web/assets/hsp-sHEckFHE.js +0 -1
  699. package/dist/web/assets/htmlbars-shnKLbrr.js +0 -1
  700. package/dist/web/assets/http-CNJ01fsj.js +0 -1
  701. package/dist/web/assets/hy-B3oY6sFO.js +0 -1
  702. package/dist/web/assets/index-C4BqUITd.css +0 -2
  703. package/dist/web/assets/index-DB2yAAMO.js +0 -848
  704. package/dist/web/assets/inform7-CNEOVpOE.js +0 -1
  705. package/dist/web/assets/ini-q6ZmK_Ll.js +0 -1
  706. package/dist/web/assets/irpf90-CHcNzzFG.js +0 -1
  707. package/dist/web/assets/isbl-ClZ-43Pe.js +0 -1
  708. package/dist/web/assets/java-C63Whuw3.js +0 -1
  709. package/dist/web/assets/javascript-BAgDYvOy.js +0 -1
  710. package/dist/web/assets/jboss-cli-qjpm-ZOy.js +0 -1
  711. package/dist/web/assets/json-DT8at3fD.js +0 -1
  712. package/dist/web/assets/julia-B3hjMqCS.js +0 -1
  713. package/dist/web/assets/julia-repl-BWC_EUt4.js +0 -1
  714. package/dist/web/assets/kotlin-DnDhVR1g.js +0 -2
  715. package/dist/web/assets/lasso-7_9jkuWm.js +0 -1
  716. package/dist/web/assets/latex-7NcBU-sp.js +0 -1
  717. package/dist/web/assets/ldif-BKsNETfE.js +0 -1
  718. package/dist/web/assets/leaf-Dr24XSMP.js +0 -1
  719. package/dist/web/assets/less-Da52wdLB.js +0 -1
  720. package/dist/web/assets/lisp-CxEhJv_S.js +0 -1
  721. package/dist/web/assets/livecodeserver-DyLLEQa3.js +0 -1
  722. package/dist/web/assets/livescript-DuMxIrKU.js +0 -1
  723. package/dist/web/assets/llvm-M9yuLNva.js +0 -1
  724. package/dist/web/assets/lsl-BP2wVZAx.js +0 -1
  725. package/dist/web/assets/lua-B0U8rByV.js +0 -1
  726. package/dist/web/assets/makefile-DL3DBvu0.js +0 -1
  727. package/dist/web/assets/markdown-jLDab-Ns.js +0 -1
  728. package/dist/web/assets/mathematica-2lChxOtk.js +0 -1
  729. package/dist/web/assets/matlab-BbPZe1tR.js +0 -1
  730. package/dist/web/assets/maxima-BdT1lNyu.js +0 -1
  731. package/dist/web/assets/mel-CxSMh57a.js +0 -1
  732. package/dist/web/assets/mercury-e3yoICSq.js +0 -1
  733. package/dist/web/assets/mipsasm--tpOiQ5I.js +0 -1
  734. package/dist/web/assets/mizar-DN4-ri-A.js +0 -1
  735. package/dist/web/assets/module-3nkmv-tD.js +0 -4
  736. package/dist/web/assets/mojolicious-lKYGBrCw.js +0 -1
  737. package/dist/web/assets/monkey-CvEgDQbs.js +0 -1
  738. package/dist/web/assets/moonscript-BgjEcnsm.js +0 -1
  739. package/dist/web/assets/n1ql-CtsXVmUQ.js +0 -1
  740. package/dist/web/assets/nginx-C6tprI2e.js +0 -1
  741. package/dist/web/assets/nim-B3y0lYop.js +0 -1
  742. package/dist/web/assets/nix-BczA7CjW.js +0 -1
  743. package/dist/web/assets/node-repl-DGgD94SZ.js +0 -1
  744. package/dist/web/assets/nsis-C_SmguFH.js +0 -1
  745. package/dist/web/assets/objectivec-2mUTCw1f.js +0 -1
  746. package/dist/web/assets/ocaml-Cn7F37_9.js +0 -1
  747. package/dist/web/assets/openscad-CkenTSp3.js +0 -1
  748. package/dist/web/assets/oxygene-D7pQi21T.js +0 -1
  749. package/dist/web/assets/parser3--pt_dbbu.js +0 -1
  750. package/dist/web/assets/perl-C0job7Qz.js +0 -1
  751. package/dist/web/assets/pf-CfWQAyKz.js +0 -1
  752. package/dist/web/assets/pgsql-CKshFhGu.js +0 -1
  753. package/dist/web/assets/php-CNUWaUh2.js +0 -1
  754. package/dist/web/assets/php-template-BCrABFi4.js +0 -1
  755. package/dist/web/assets/plaintext-ChYroSk0.js +0 -1
  756. package/dist/web/assets/pony-Bh4zwDWt.js +0 -1
  757. package/dist/web/assets/powershell-BuAlXUWx.js +0 -1
  758. package/dist/web/assets/processing-Bb5btTkH.js +0 -1
  759. package/dist/web/assets/profile-BOk16iWu.js +0 -1
  760. package/dist/web/assets/prolog-MHE4b3nq.js +0 -1
  761. package/dist/web/assets/properties-CZfxER-Q.js +0 -1
  762. package/dist/web/assets/protobuf-C_54DU4K.js +0 -1
  763. package/dist/web/assets/puppet-Z-t3L629.js +0 -1
  764. package/dist/web/assets/purebasic-CZKfEDHv.js +0 -1
  765. package/dist/web/assets/python-BvGG_JZE.js +0 -1
  766. package/dist/web/assets/python-repl-DaUVEuDx.js +0 -1
  767. package/dist/web/assets/q-CvWis_nQ.js +0 -1
  768. package/dist/web/assets/qml-2XPxalcH.js +0 -1
  769. package/dist/web/assets/r-DTTPbRAt.js +0 -1
  770. package/dist/web/assets/reasonml-CyJw_qBZ.js +0 -1
  771. package/dist/web/assets/rib-GYMKCC1Y.js +0 -1
  772. package/dist/web/assets/roboconf-CV_6N_o7.js +0 -1
  773. package/dist/web/assets/routeros-C11OKG9F.js +0 -1
  774. package/dist/web/assets/rpc-logger-TPNV75J4-CvwEntuM.js +0 -1
  775. package/dist/web/assets/rsl-rez9LEUy.js +0 -1
  776. package/dist/web/assets/ruby-_B4GQ_7D.js +0 -1
  777. package/dist/web/assets/ruleslanguage-jRg89I6w.js +0 -1
  778. package/dist/web/assets/rust-qdkaNniS.js +0 -1
  779. package/dist/web/assets/sas-BNjYSnSg.js +0 -1
  780. package/dist/web/assets/scala-CVLdU51z.js +0 -1
  781. package/dist/web/assets/scheme-Cneig3hI.js +0 -1
  782. package/dist/web/assets/scilab-DxKCNrof.js +0 -1
  783. package/dist/web/assets/scss-DQ23aG9u.js +0 -1
  784. package/dist/web/assets/shell-BgVIEdPP.js +0 -1
  785. package/dist/web/assets/smali-KZ0XB6tA.js +0 -2
  786. package/dist/web/assets/smalltalk-CYsrtMqX.js +0 -1
  787. package/dist/web/assets/sml-CwPjhShZ.js +0 -1
  788. package/dist/web/assets/sqf-Dyh-UyfR.js +0 -1
  789. package/dist/web/assets/sql-BqwecpD_.js +0 -1
  790. package/dist/web/assets/sql_more-CUF5pbmY.js +0 -1
  791. package/dist/web/assets/stan-Ddf5JFRA.js +0 -1
  792. package/dist/web/assets/stata-XlPupwqv.js +0 -3
  793. package/dist/web/assets/step21-CucMyzRd.js +0 -1
  794. package/dist/web/assets/stylus-nj6mAxkC.js +0 -1
  795. package/dist/web/assets/subunit-CiXRLQcz.js +0 -3
  796. package/dist/web/assets/swift-CIdqZMKK.js +0 -1
  797. package/dist/web/assets/taggerscript-m6_DnfoH.js +0 -1
  798. package/dist/web/assets/tap-DbEec7Q2.js +0 -1
  799. package/dist/web/assets/tcl-n8aGQ2H6.js +0 -1
  800. package/dist/web/assets/thrift-J1PtwUUl.js +0 -1
  801. package/dist/web/assets/tp-CnbYKLYQ.js +0 -1
  802. package/dist/web/assets/twig-BEBOjZvM.js +0 -1
  803. package/dist/web/assets/typescript-BwvhN9Dw.js +0 -1
  804. package/dist/web/assets/vala-BSRZa9oU.js +0 -1
  805. package/dist/web/assets/vbnet-BhOhpmOF.js +0 -1
  806. package/dist/web/assets/vbscript-BpRpQGFw.js +0 -1
  807. package/dist/web/assets/vbscript-html-z-0GWV6e.js +0 -1
  808. package/dist/web/assets/verilog-CE-mWkfc.js +0 -1
  809. package/dist/web/assets/vhdl-hkUj0_K7.js +0 -1
  810. package/dist/web/assets/vim-XK7W3JN3.js +0 -1
  811. package/dist/web/assets/x86asm-D0cmZUWd.js +0 -1
  812. package/dist/web/assets/xl-dRKa8VcI.js +0 -1
  813. package/dist/web/assets/xml-BGrFHpDb.js +0 -1
  814. package/dist/web/assets/xquery-B7qeO1Sf.js +0 -1
  815. package/dist/web/assets/yaml-DErfnXTM.js +0 -1
  816. package/dist/web/assets/zephir-O2ApOQbM.js +0 -1
@@ -1,2351 +0,0 @@
1
- // src/llm/toolResultParts.ts
2
- function makeText(text) {
3
- return { type: "text", text };
4
- }
5
- function makeImage(data, mimeType) {
6
- return {
7
- type: "image",
8
- url: `data:${mimeType};base64,${data}`,
9
- mimeType,
10
- data
11
- };
12
- }
13
- function isMcpResultShape(value) {
14
- if (!value || typeof value !== "object") return false;
15
- const v = value;
16
- if (Array.isArray(v.content)) return true;
17
- return "structuredContent" in v;
18
- }
19
- function isToolResultError(result) {
20
- return typeof result === "object" && result !== null && result.isError === true;
21
- }
22
- function blockToPart(block) {
23
- if (!block || typeof block !== "object") return null;
24
- switch (block.type) {
25
- case "text": {
26
- const text = block.text;
27
- return typeof text === "string" && text.length > 0 ? makeText(text) : null;
28
- }
29
- case "image": {
30
- const b = block;
31
- if (typeof b.data !== "string" || !b.data) return null;
32
- const mime = typeof b.mimeType === "string" && b.mimeType ? b.mimeType : "image/png";
33
- return makeImage(b.data, mime);
34
- }
35
- case "audio": {
36
- const b = block;
37
- const mime = typeof b.mimeType === "string" && b.mimeType ? b.mimeType : "audio/*";
38
- const bytes = typeof b.data === "string" ? b.data.length : 0;
39
- return makeText(`[audio: ${mime}, base64 omitted (${bytes} chars)]`);
40
- }
41
- case "resource": {
42
- const r = block.resource ?? {};
43
- if (typeof r.text === "string" && r.text.length > 0) {
44
- return makeText(r.text);
45
- }
46
- if (typeof r.blob === "string" && typeof r.mimeType === "string" && r.mimeType.startsWith("image/")) {
47
- return makeImage(r.blob, r.mimeType);
48
- }
49
- const uri = typeof r.uri === "string" ? r.uri : "<unknown>";
50
- const mime = typeof r.mimeType === "string" ? r.mimeType : "unknown";
51
- return makeText(`[resource: ${uri} (${mime})]`);
52
- }
53
- case "resource_link": {
54
- const b = block;
55
- const uri = typeof b.uri === "string" ? b.uri : "<unknown>";
56
- const name = typeof b.name === "string" ? ` "${b.name}"` : "";
57
- return makeText(`[resource_link${name}: ${uri}]`);
58
- }
59
- default: {
60
- return makeText(
61
- `[unsupported tool content block: ${String(block.type)}]`
62
- );
63
- }
64
- }
65
- }
66
- function stripMeta(value) {
67
- if (value && typeof value === "object" && !Array.isArray(value)) {
68
- const { _meta: _ignored, ...rest } = value;
69
- return rest;
70
- }
71
- return value;
72
- }
73
- function extractToolResultParts(result) {
74
- const stripped = stripMeta(result);
75
- if (typeof stripped === "string") {
76
- return stripped.length > 0 ? [makeText(stripped)] : [];
77
- }
78
- if (isMcpResultShape(stripped)) {
79
- const r = stripped;
80
- const parts = [];
81
- if (Array.isArray(r.content)) {
82
- for (const block of r.content) {
83
- const p = blockToPart(block);
84
- if (p) parts.push(p);
85
- }
86
- }
87
- if (r.structuredContent !== void 0) {
88
- try {
89
- parts.push(
90
- makeText(`structuredContent: ${JSON.stringify(r.structuredContent)}`)
91
- );
92
- } catch {
93
- }
94
- }
95
- if (r.isError) {
96
- parts.unshift(makeText("[tool reported isError=true]"));
97
- }
98
- return parts;
99
- }
100
- try {
101
- return [makeText(JSON.stringify(stripped))];
102
- } catch {
103
- return [makeText(String(stripped))];
104
- }
105
- }
106
- function collapseToString(parts) {
107
- if (parts.length === 0) return "";
108
- if (parts.every((p) => p.type === "text")) {
109
- return parts.map((p) => p.text).join("\n");
110
- }
111
- return null;
112
- }
113
- function toolResultToContent(result) {
114
- const parts = extractToolResultParts(result);
115
- const collapsed = collapseToString(parts);
116
- return collapsed !== null ? collapsed : parts;
117
- }
118
- function partitionToolContent(content) {
119
- if (typeof content === "string") {
120
- return { text: content, imageParts: [], isString: true };
121
- }
122
- const texts = [];
123
- const imageParts = [];
124
- for (const p of content) {
125
- if (p.type === "text") {
126
- if (p.text) texts.push(p.text);
127
- } else if (p.type === "image") {
128
- imageParts.push(p);
129
- }
130
- }
131
- return { text: texts.join("\n"), imageParts, isString: false };
132
- }
133
- function toolImageFollowupHeader(toolName, count) {
134
- return `(Tool "${toolName ?? "<tool>"}" returned the following image${count === 1 ? "" : "s"}:)`;
135
- }
136
-
137
- // src/llm/messageFormat.ts
138
- function extractText(m) {
139
- const raw = typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((x) => x?.text ?? "").join("\n") : JSON.stringify(m.content ?? "");
140
- if (raw.trim()) return raw.trim();
141
- if (m.parts?.length) {
142
- return m.parts.filter((p) => p.type === "text" && p.text).map((p) => p.text).join("").trim();
143
- }
144
- return "";
145
- }
146
- function convertMessagesToProvider(messages) {
147
- const out = [];
148
- messages.forEach((m, mi) => {
149
- if (m.role === "user") {
150
- const text2 = extractText(m) || "[no content]";
151
- if (m.attachments?.length) {
152
- const parts = [{ type: "text", text: text2 }];
153
- for (const a of m.attachments) {
154
- if (a.type === "image") {
155
- parts.push({
156
- type: "image",
157
- url: `data:${a.mimeType};base64,${a.data}`,
158
- mimeType: a.mimeType,
159
- data: a.data
160
- });
161
- }
162
- }
163
- out.push({ role: "user", content: parts });
164
- } else {
165
- out.push({ role: "user", content: text2 });
166
- }
167
- return;
168
- }
169
- const toolParts = (m.parts ?? []).filter(
170
- (p) => p.type === "tool-invocation" && p.toolInvocation && p.toolInvocation.result !== void 0
171
- );
172
- if (toolParts.length === 0) {
173
- const text2 = extractText(m) || "[no content]";
174
- out.push({ role: "assistant", content: text2 });
175
- return;
176
- }
177
- const text = extractText(m);
178
- const toolCalls = toolParts.map((p, i) => ({
179
- id: `call_${mi}_${i}_${p.toolInvocation.toolName}`,
180
- name: p.toolInvocation.toolName,
181
- args: p.toolInvocation.args
182
- }));
183
- out.push({
184
- role: "assistant",
185
- content: text,
186
- toolCalls
187
- });
188
- toolParts.forEach((p, i) => {
189
- const result = p.toolInvocation.result;
190
- out.push({
191
- role: "tool",
192
- content: toolResultToContent(result),
193
- toolCallId: `call_${mi}_${i}_${p.toolInvocation.toolName}`,
194
- toolName: p.toolInvocation.toolName,
195
- toolResult: result,
196
- toolIsError: isToolResultError(result)
197
- });
198
- });
199
- });
200
- return out;
201
- }
202
- function extractSystem(messages) {
203
- const sys = [];
204
- const rest = [];
205
- for (const m of messages) {
206
- if (m.role === "system") {
207
- if (typeof m.content === "string") sys.push(m.content);
208
- else if (Array.isArray(m.content)) {
209
- for (const p of m.content) if (p.type === "text") sys.push(p.text);
210
- }
211
- } else {
212
- rest.push(m);
213
- }
214
- }
215
- return {
216
- system: sys.length > 0 ? sys.join("\n\n") : void 0,
217
- rest
218
- };
219
- }
220
- function parseDataUrl(url) {
221
- const m = url.match(/^data:([^;,]+);base64,(.+)$/);
222
- if (!m) return null;
223
- return { mimeType: m[1], data: m[2] };
224
- }
225
-
226
- // src/llm/sse.ts
227
- async function* parseSSE(body, signal) {
228
- const reader = body.getReader();
229
- const decoder = new TextDecoder("utf-8");
230
- let buffer = "";
231
- try {
232
- while (true) {
233
- if (signal?.aborted) return;
234
- const { value, done } = await reader.read();
235
- if (done) break;
236
- buffer += decoder.decode(value, { stream: true });
237
- let sep;
238
- while ((sep = indexOfEventSeparator(buffer)) !== -1) {
239
- const raw = buffer.slice(0, sep);
240
- buffer = buffer.slice(sep).replace(/^(\r\n\r\n|\n\n|\r\r)/, "");
241
- const parsed = parseSseBlock(raw);
242
- if (parsed) yield parsed;
243
- }
244
- }
245
- if (buffer.trim()) {
246
- const parsed = parseSseBlock(buffer);
247
- if (parsed) yield parsed;
248
- }
249
- } finally {
250
- try {
251
- reader.releaseLock();
252
- } catch {
253
- }
254
- }
255
- }
256
- function indexOfEventSeparator(s) {
257
- const a = s.indexOf("\n\n");
258
- const b = s.indexOf("\r\n\r\n");
259
- if (a === -1) return b;
260
- if (b === -1) return a;
261
- return Math.min(a, b);
262
- }
263
- function parseSseBlock(raw) {
264
- let event;
265
- const dataLines = [];
266
- for (const line of raw.split(/\r?\n/)) {
267
- if (!line || line.startsWith(":")) continue;
268
- const idx = line.indexOf(":");
269
- const field = idx === -1 ? line : line.slice(0, idx);
270
- let value = idx === -1 ? "" : line.slice(idx + 1);
271
- if (value.startsWith(" ")) value = value.slice(1);
272
- if (field === "event") event = value;
273
- else if (field === "data") dataLines.push(value);
274
- }
275
- if (dataLines.length === 0) return null;
276
- return { event, data: dataLines.join("\n") };
277
- }
278
-
279
- // src/llm/providers/anthropic.ts
280
- var DEFAULT_ENDPOINT = "https://api.anthropic.com/v1/messages";
281
- var ANTHROPIC_VERSION = "2023-06-01";
282
- var DEFAULT_MAX_TOKENS = 4096;
283
- function buildImageBlock(p) {
284
- if (p.type !== "image") return null;
285
- if (p.data && p.mimeType) {
286
- return {
287
- type: "image",
288
- source: { type: "base64", media_type: p.mimeType, data: p.data }
289
- };
290
- }
291
- const parsed = parseDataUrl(p.url);
292
- if (parsed) {
293
- return {
294
- type: "image",
295
- source: {
296
- type: "base64",
297
- media_type: parsed.mimeType,
298
- data: parsed.data
299
- }
300
- };
301
- }
302
- return { type: "image", source: { type: "url", url: p.url } };
303
- }
304
- function toAnthropicContent(content) {
305
- if (typeof content === "string") {
306
- return [{ type: "text", text: content || "[no content]" }];
307
- }
308
- const blocks = [];
309
- for (const p of content) {
310
- if (p.type === "text") {
311
- if (p.text) blocks.push({ type: "text", text: p.text });
312
- } else {
313
- const img = buildImageBlock(p);
314
- if (img) blocks.push(img);
315
- }
316
- }
317
- if (blocks.length === 0) blocks.push({ type: "text", text: "[no content]" });
318
- return blocks;
319
- }
320
- function toAnthropicToolResultContent(content) {
321
- if (typeof content === "string") {
322
- return content;
323
- }
324
- const blocks = [];
325
- for (const p of content) {
326
- if (p.type === "text") {
327
- if (p.text) blocks.push({ type: "text", text: p.text });
328
- } else if (p.type === "image") {
329
- const img = buildImageBlock(p);
330
- if (img) blocks.push(img);
331
- }
332
- }
333
- if (blocks.length === 0) {
334
- return "[no content]";
335
- }
336
- return blocks;
337
- }
338
- function toAnthropicMessages(messages) {
339
- const out = [];
340
- for (const m of messages) {
341
- if (m.role === "tool") {
342
- const last = out[out.length - 1];
343
- const block = {
344
- type: "tool_result",
345
- tool_use_id: m.toolCallId,
346
- content: toAnthropicToolResultContent(m.content),
347
- ...m.toolIsError ? { is_error: true } : {}
348
- };
349
- if (last && last.role === "user" && Array.isArray(last.content)) {
350
- last.content.push(block);
351
- } else {
352
- out.push({ role: "user", content: [block] });
353
- }
354
- continue;
355
- }
356
- if (m.role === "assistant") {
357
- const blocks = [];
358
- const textContent = typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((p) => p.type === "text" ? p.text : "").join("") : "";
359
- if (textContent) blocks.push({ type: "text", text: textContent });
360
- if (m.toolCalls?.length) {
361
- for (const tc of m.toolCalls) {
362
- blocks.push({
363
- type: "tool_use",
364
- id: tc.id,
365
- name: tc.name,
366
- input: tc.args ?? {}
367
- });
368
- }
369
- }
370
- if (blocks.length === 0) {
371
- blocks.push({ type: "text", text: "[no content]" });
372
- }
373
- out.push({ role: "assistant", content: blocks });
374
- continue;
375
- }
376
- out.push({ role: "user", content: toAnthropicContent(m.content) });
377
- }
378
- return out;
379
- }
380
- function buildBody(params, stream) {
381
- const { config, messages, tools } = params;
382
- const { system, rest } = extractSystem(messages);
383
- const body = {
384
- model: config.model,
385
- max_tokens: config.maxTokens ?? DEFAULT_MAX_TOKENS,
386
- messages: toAnthropicMessages(rest),
387
- ...stream ? { stream: true } : {}
388
- };
389
- if (config.temperature !== void 0) body.temperature = config.temperature;
390
- if (system) body.system = system;
391
- if (tools && tools.length > 0) {
392
- body.tools = tools.map((t) => ({
393
- name: t.name,
394
- description: t.description,
395
- input_schema: t.inputSchema
396
- }));
397
- }
398
- return body;
399
- }
400
- async function* streamChat(params) {
401
- const { config, signal } = params;
402
- const res = await fetch(DEFAULT_ENDPOINT, {
403
- method: "POST",
404
- headers: {
405
- "Content-Type": "application/json",
406
- "x-api-key": config.apiKey,
407
- "anthropic-version": ANTHROPIC_VERSION,
408
- "anthropic-dangerous-direct-browser-access": "true"
409
- },
410
- body: JSON.stringify(buildBody(params, true)),
411
- signal
412
- });
413
- if (!res.ok || !res.body) {
414
- const text = await res.text().catch(() => "");
415
- throw new Error(
416
- `Anthropic request failed (${res.status} ${res.statusText}): ${text}`
417
- );
418
- }
419
- const blocks = /* @__PURE__ */ new Map();
420
- for await (const ev of parseSSE(res.body, signal)) {
421
- let parsed;
422
- try {
423
- parsed = JSON.parse(ev.data);
424
- } catch {
425
- continue;
426
- }
427
- const t = parsed?.type;
428
- if (t === "content_block_start") {
429
- const idx = parsed.index;
430
- const cb = parsed.content_block ?? {};
431
- if (cb.type === "tool_use") {
432
- blocks.set(idx, {
433
- kind: "tool_use",
434
- id: cb.id,
435
- name: cb.name,
436
- argsJson: "",
437
- emittedStart: false
438
- });
439
- yield {
440
- type: "tool-call-start",
441
- index: idx,
442
- toolCallId: cb.id,
443
- toolName: cb.name
444
- };
445
- const entry = blocks.get(idx);
446
- if (entry) entry.emittedStart = true;
447
- } else {
448
- blocks.set(idx, {
449
- kind: "text",
450
- argsJson: "",
451
- emittedStart: false
452
- });
453
- }
454
- } else if (t === "content_block_delta") {
455
- const idx = parsed.index;
456
- const d = parsed.delta ?? {};
457
- const entry = blocks.get(idx);
458
- if (!entry) continue;
459
- if (d.type === "text_delta" && typeof d.text === "string") {
460
- yield { type: "text-delta", delta: d.text };
461
- } else if (d.type === "input_json_delta" && typeof d.partial_json === "string" && entry.kind === "tool_use") {
462
- entry.argsJson += d.partial_json;
463
- yield {
464
- type: "tool-call-args-delta",
465
- index: idx,
466
- toolCallId: entry.id,
467
- toolName: entry.name,
468
- argsDelta: d.partial_json
469
- };
470
- }
471
- } else if (t === "content_block_stop") {
472
- const idx = parsed.index;
473
- const entry = blocks.get(idx);
474
- if (entry && entry.kind === "tool_use" && entry.id && entry.name) {
475
- let args = {};
476
- if (entry.argsJson) {
477
- try {
478
- args = JSON.parse(entry.argsJson);
479
- } catch {
480
- args = {};
481
- }
482
- }
483
- yield {
484
- type: "tool-call-ready",
485
- index: idx,
486
- toolCallId: entry.id,
487
- toolName: entry.name,
488
- args
489
- };
490
- }
491
- } else if (t === "message_stop") {
492
- } else if (t === "error") {
493
- yield {
494
- type: "error",
495
- message: parsed?.error?.message ?? "Anthropic stream error"
496
- };
497
- }
498
- }
499
- yield { type: "done" };
500
- }
501
- async function chat(params) {
502
- const { config, signal } = params;
503
- const res = await fetch(DEFAULT_ENDPOINT, {
504
- method: "POST",
505
- headers: {
506
- "Content-Type": "application/json",
507
- "x-api-key": config.apiKey,
508
- "anthropic-version": ANTHROPIC_VERSION,
509
- "anthropic-dangerous-direct-browser-access": "true"
510
- },
511
- body: JSON.stringify(buildBody(params, false)),
512
- signal
513
- });
514
- if (!res.ok) {
515
- const text2 = await res.text().catch(() => "");
516
- throw new Error(
517
- `Anthropic request failed (${res.status} ${res.statusText}): ${text2}`
518
- );
519
- }
520
- const json = await res.json();
521
- let text = "";
522
- const toolCalls = [];
523
- for (const block of json?.content ?? []) {
524
- if (block.type === "text" && typeof block.text === "string") {
525
- text += block.text;
526
- } else if (block.type === "tool_use") {
527
- toolCalls.push({
528
- id: block.id,
529
- name: block.name,
530
- args: block.input && typeof block.input === "object" ? block.input : {}
531
- });
532
- }
533
- }
534
- return { text, toolCalls };
535
- }
536
-
537
- // src/llm/schemaUtils.ts
538
- var ALLOWED_KEYS = /* @__PURE__ */ new Set([
539
- "type",
540
- "description",
541
- "enum",
542
- "properties",
543
- "required",
544
- "items",
545
- "format",
546
- "nullable",
547
- "minimum",
548
- "maximum",
549
- "minItems",
550
- "maxItems",
551
- "minLength",
552
- "maxLength",
553
- "pattern"
554
- ]);
555
- function sanitizeSchemaForGemini(schema) {
556
- if (!schema || typeof schema !== "object") {
557
- return { type: "object" };
558
- }
559
- const cleaned = clean(schema);
560
- if (typeof cleaned !== "object" || cleaned === null) {
561
- return { type: "object" };
562
- }
563
- const out = cleaned;
564
- if (!out.type) out.type = "object";
565
- return out;
566
- }
567
- function clean(value) {
568
- if (Array.isArray(value)) return value.map(clean);
569
- if (!value || typeof value !== "object") return value;
570
- const input = value;
571
- for (const key of ["oneOf", "anyOf", "allOf"]) {
572
- const arr = input[key];
573
- if (Array.isArray(arr) && arr.length === 1) {
574
- return clean(arr[0]);
575
- }
576
- }
577
- const out = {};
578
- for (const [k, v] of Object.entries(input)) {
579
- if (!ALLOWED_KEYS.has(k)) continue;
580
- if (k === "properties" && v && typeof v === "object") {
581
- const props = {};
582
- for (const [pk, pv] of Object.entries(v)) {
583
- props[pk] = clean(pv);
584
- }
585
- out[k] = props;
586
- } else if (k === "items") {
587
- out[k] = clean(v);
588
- } else {
589
- out[k] = v;
590
- }
591
- }
592
- return out;
593
- }
594
-
595
- // src/llm/providers/google.ts
596
- function normalizeModelId(model) {
597
- const trimmed = model.trim();
598
- return trimmed.startsWith("models/") ? trimmed.slice("models/".length) : trimmed;
599
- }
600
- function endpointFor(model, mode) {
601
- const action = mode === "stream" ? "streamGenerateContent?alt=sse" : "generateContent";
602
- return `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(
603
- normalizeModelId(model)
604
- )}:${action}`;
605
- }
606
- function buildInlineData(p) {
607
- if (p.type !== "image") return null;
608
- if (p.data && p.mimeType) {
609
- return { inlineData: { mimeType: p.mimeType, data: p.data } };
610
- }
611
- const parsed = parseDataUrl(p.url);
612
- if (parsed) {
613
- return {
614
- inlineData: { mimeType: parsed.mimeType, data: parsed.data }
615
- };
616
- }
617
- return null;
618
- }
619
- function toGeminiParts(content) {
620
- if (typeof content === "string") {
621
- return [{ text: content || "[no content]" }];
622
- }
623
- const parts = [];
624
- for (const p of content) {
625
- if (p.type === "text") {
626
- if (p.text) parts.push({ text: p.text });
627
- } else {
628
- const block = buildInlineData(p);
629
- if (block) parts.push(block);
630
- }
631
- }
632
- if (parts.length === 0) parts.push({ text: "[no content]" });
633
- return parts;
634
- }
635
- function buildGeminiToolResponse(content) {
636
- if (typeof content === "string") {
637
- let parsed;
638
- try {
639
- parsed = JSON.parse(content);
640
- } catch {
641
- parsed = { result: content };
642
- }
643
- if (!parsed || typeof parsed !== "object") {
644
- parsed = { result: parsed };
645
- }
646
- return { response: parsed, imageParts: [] };
647
- }
648
- const { text, imageParts } = partitionToolContent(content);
649
- const response = {};
650
- if (text) response.text = text;
651
- if (imageParts.length > 0) {
652
- response.images = imageParts.map((p) => ({
653
- mimeType: p.mimeType ?? "image/*",
654
- omitted: true
655
- }));
656
- response.note = "Image bytes were sent in the next user turn as inlineData.";
657
- }
658
- if (Object.keys(response).length === 0) {
659
- response.result = null;
660
- }
661
- return { response, imageParts };
662
- }
663
- function toGeminiContents(messages) {
664
- const out = [];
665
- for (const m of messages) {
666
- if (m.role === "tool") {
667
- const { response, imageParts } = buildGeminiToolResponse(m.content);
668
- const last = out[out.length - 1];
669
- const part = {
670
- functionResponse: {
671
- name: m.toolName,
672
- response
673
- }
674
- };
675
- if (last && last.role === "function") {
676
- last.parts.push(part);
677
- } else {
678
- out.push({ role: "function", parts: [part] });
679
- }
680
- if (imageParts.length > 0) {
681
- const userParts = [
682
- { text: toolImageFollowupHeader(m.toolName, imageParts.length) }
683
- ];
684
- for (const p of imageParts) {
685
- const block = buildInlineData(p);
686
- if (block) userParts.push(block);
687
- }
688
- out.push({ role: "user", parts: userParts });
689
- }
690
- continue;
691
- }
692
- if (m.role === "assistant") {
693
- const parts = [];
694
- const textContent = typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((p) => p.type === "text" ? p.text : "").join("") : "";
695
- if (textContent) parts.push({ text: textContent });
696
- if (m.toolCalls?.length) {
697
- for (const tc of m.toolCalls) {
698
- parts.push({
699
- functionCall: { name: tc.name, args: tc.args ?? {} }
700
- });
701
- }
702
- }
703
- if (parts.length === 0) parts.push({ text: "[no content]" });
704
- out.push({ role: "model", parts });
705
- continue;
706
- }
707
- out.push({ role: "user", parts: toGeminiParts(m.content) });
708
- }
709
- return out;
710
- }
711
- function buildBody2(params) {
712
- const { config, messages, tools } = params;
713
- const { system, rest } = extractSystem(messages);
714
- const body = {
715
- contents: toGeminiContents(rest)
716
- };
717
- if (system) {
718
- body.systemInstruction = { parts: [{ text: system }] };
719
- }
720
- const genConfig = {};
721
- if (config.temperature !== void 0)
722
- genConfig.temperature = config.temperature;
723
- if (config.maxTokens !== void 0)
724
- genConfig.maxOutputTokens = config.maxTokens;
725
- if (Object.keys(genConfig).length > 0) body.generationConfig = genConfig;
726
- if (tools && tools.length > 0) {
727
- body.tools = [
728
- {
729
- functionDeclarations: tools.map((t) => ({
730
- name: t.name,
731
- description: t.description,
732
- parameters: sanitizeSchemaForGemini(t.inputSchema)
733
- }))
734
- }
735
- ];
736
- }
737
- return body;
738
- }
739
- async function* streamChat2(params) {
740
- const { config, signal } = params;
741
- const url = `${endpointFor(config.model, "stream")}&key=${encodeURIComponent(
742
- config.apiKey
743
- )}`;
744
- const res = await fetch(url, {
745
- method: "POST",
746
- headers: { "Content-Type": "application/json" },
747
- body: JSON.stringify(buildBody2(params)),
748
- signal
749
- });
750
- if (!res.ok || !res.body) {
751
- const text = await res.text().catch(() => "");
752
- throw new Error(
753
- `Google request failed (${res.status} ${res.statusText}): ${text}`
754
- );
755
- }
756
- let toolCallCounter = 0;
757
- for await (const ev of parseSSE(res.body, signal)) {
758
- let parsed;
759
- try {
760
- parsed = JSON.parse(ev.data);
761
- } catch {
762
- continue;
763
- }
764
- const parts = parsed?.candidates?.[0]?.content?.parts ?? [];
765
- for (const p of parts) {
766
- if (typeof p.text === "string" && p.text.length > 0) {
767
- yield { type: "text-delta", delta: p.text };
768
- } else if (p.functionCall && typeof p.functionCall === "object") {
769
- const idx = toolCallCounter++;
770
- const id = `call_${idx}_${p.functionCall.name ?? "tool"}`;
771
- const name = p.functionCall.name ?? "";
772
- const args = p.functionCall.args && typeof p.functionCall.args === "object" ? p.functionCall.args : {};
773
- yield {
774
- type: "tool-call-start",
775
- index: idx,
776
- toolCallId: id,
777
- toolName: name
778
- };
779
- const argsJson = JSON.stringify(args);
780
- if (argsJson && argsJson !== "{}") {
781
- yield {
782
- type: "tool-call-args-delta",
783
- index: idx,
784
- toolCallId: id,
785
- toolName: name,
786
- argsDelta: argsJson
787
- };
788
- }
789
- yield {
790
- type: "tool-call-ready",
791
- index: idx,
792
- toolCallId: id,
793
- toolName: name,
794
- args
795
- };
796
- }
797
- }
798
- }
799
- yield { type: "done" };
800
- }
801
- async function chat2(params) {
802
- const { config, signal } = params;
803
- const url = `${endpointFor(config.model, "single")}?key=${encodeURIComponent(
804
- config.apiKey
805
- )}`;
806
- const res = await fetch(url, {
807
- method: "POST",
808
- headers: { "Content-Type": "application/json" },
809
- body: JSON.stringify(buildBody2(params)),
810
- signal
811
- });
812
- if (!res.ok) {
813
- const text2 = await res.text().catch(() => "");
814
- throw new Error(
815
- `Google request failed (${res.status} ${res.statusText}): ${text2}`
816
- );
817
- }
818
- const json = await res.json();
819
- let text = "";
820
- const toolCalls = [];
821
- const parts = json?.candidates?.[0]?.content?.parts ?? [];
822
- for (const p of parts) {
823
- if (typeof p.text === "string") text += p.text;
824
- else if (p.functionCall) {
825
- toolCalls.push({
826
- id: `call_${toolCalls.length}_${p.functionCall.name ?? "tool"}`,
827
- name: p.functionCall.name ?? "",
828
- args: p.functionCall.args && typeof p.functionCall.args === "object" ? p.functionCall.args : {}
829
- });
830
- }
831
- }
832
- return { text, toolCalls };
833
- }
834
-
835
- // src/llm/ndjson.ts
836
- async function* parseNDJSON(body, signal) {
837
- const reader = body.getReader();
838
- const decoder = new TextDecoder();
839
- let buffer = "";
840
- try {
841
- while (true) {
842
- if (signal?.aborted) return;
843
- const { done, value } = await reader.read();
844
- if (done) break;
845
- buffer += decoder.decode(value, { stream: true });
846
- const lines = buffer.split("\n");
847
- buffer = lines.pop() ?? "";
848
- for (const line of lines) {
849
- const trimmed = line.trim();
850
- if (!trimmed) continue;
851
- try {
852
- yield JSON.parse(trimmed);
853
- } catch {
854
- }
855
- }
856
- }
857
- const trailing = buffer.trim();
858
- if (trailing) {
859
- try {
860
- yield JSON.parse(trailing);
861
- } catch {
862
- }
863
- }
864
- } finally {
865
- reader.releaseLock();
866
- }
867
- }
868
-
869
- // src/llm/providers/ollama/utils.ts
870
- var DEFAULT_OLLAMA_BASE_URL = "http://localhost:11434";
871
- function normalizeOllamaBaseUrl(baseUrl) {
872
- const raw = (baseUrl || DEFAULT_OLLAMA_BASE_URL).trim();
873
- let end = raw.length;
874
- while (end > 0 && raw.charCodeAt(end - 1) === 47) {
875
- end--;
876
- }
877
- const trimmed = raw.slice(0, end);
878
- return trimmed.endsWith("/api") ? trimmed.slice(0, -4) : trimmed;
879
- }
880
- function buildOllamaApiUrl(baseUrl, path) {
881
- return `${normalizeOllamaBaseUrl(baseUrl)}${path}`;
882
- }
883
-
884
- // src/llm/providers/ollama/index.ts
885
- function toOllamaImages(content) {
886
- const images = [];
887
- for (const part of content) {
888
- if (part.type !== "image") continue;
889
- if (part.data) {
890
- images.push(part.data);
891
- continue;
892
- }
893
- const parsed = parseDataUrl(part.url);
894
- if (parsed?.data) {
895
- images.push(parsed.data);
896
- }
897
- }
898
- return images;
899
- }
900
- function toOllamaContent(content) {
901
- if (typeof content === "string") {
902
- return { content };
903
- }
904
- const text = content.filter(
905
- (part) => part.type === "text"
906
- ).map((part) => part.text).join("");
907
- const images = toOllamaImages(content);
908
- return {
909
- content: text,
910
- ...images.length > 0 ? { images } : {}
911
- };
912
- }
913
- function toOllamaMessages(messages) {
914
- return messages.map((message) => {
915
- if (message.role === "tool") {
916
- return {
917
- role: "tool",
918
- tool_name: message.toolName,
919
- content: typeof message.content === "string" ? message.content : JSON.stringify(message.toolResult ?? message.content)
920
- };
921
- }
922
- if (message.role === "assistant") {
923
- const content = typeof message.content === "string" ? { content: message.content } : toOllamaContent(message.content);
924
- return {
925
- role: "assistant",
926
- ...content,
927
- ...message.toolCalls?.length ? {
928
- tool_calls: message.toolCalls.map((toolCall, index) => ({
929
- type: "function",
930
- function: {
931
- index,
932
- name: toolCall.name,
933
- arguments: toolCall.args
934
- }
935
- }))
936
- } : {}
937
- };
938
- }
939
- return {
940
- role: message.role,
941
- ...toOllamaContent(message.content)
942
- };
943
- });
944
- }
945
- function buildBody3(params, stream) {
946
- const { config, messages, tools } = params;
947
- const body = {
948
- model: config.model,
949
- messages: toOllamaMessages(messages),
950
- stream
951
- };
952
- const options = {};
953
- if (config.temperature !== void 0)
954
- options.temperature = config.temperature;
955
- if (config.maxTokens !== void 0) options.num_predict = config.maxTokens;
956
- if (Object.keys(options).length > 0) body.options = options;
957
- if (tools && tools.length > 0) {
958
- body.tools = tools.map((tool) => ({
959
- type: "function",
960
- function: {
961
- name: tool.name,
962
- description: tool.description,
963
- parameters: tool.inputSchema
964
- }
965
- }));
966
- }
967
- return body;
968
- }
969
- function buildHeaders(config) {
970
- return {
971
- "Content-Type": "application/json",
972
- ...config.apiKey.trim() ? { Authorization: `Bearer ${config.apiKey.trim()}` } : {}
973
- };
974
- }
975
- function normalizeToolCalls(toolCalls) {
976
- if (!Array.isArray(toolCalls)) return [];
977
- return toolCalls.map((toolCall) => {
978
- const functionCall = toolCall && typeof toolCall === "object" ? toolCall.function : void 0;
979
- const name = typeof functionCall?.name === "string" ? functionCall.name : "";
980
- const rawArgs = functionCall?.arguments;
981
- const args = rawArgs && typeof rawArgs === "object" ? rawArgs : {};
982
- return {
983
- name,
984
- args
985
- };
986
- }).filter((toolCall) => toolCall.name);
987
- }
988
- async function* streamChat3(params) {
989
- const { config, signal } = params;
990
- const res = await fetch(buildOllamaApiUrl(config.baseUrl, "/api/chat"), {
991
- method: "POST",
992
- headers: buildHeaders(config),
993
- body: JSON.stringify(buildBody3(params, true)),
994
- signal
995
- });
996
- if (!res.ok || !res.body) {
997
- const text = await res.text().catch(() => "");
998
- throw new Error(
999
- `Ollama request failed (${res.status} ${res.statusText}): ${text}`
1000
- );
1001
- }
1002
- let toolCallsEmitted = false;
1003
- for await (const chunk of parseNDJSON(res.body, signal)) {
1004
- const message = chunk && typeof chunk === "object" ? chunk.message : void 0;
1005
- if (typeof message?.content === "string" && message.content.length > 0) {
1006
- yield { type: "text-delta", delta: message.content };
1007
- }
1008
- if (!toolCallsEmitted) {
1009
- const toolCalls = normalizeToolCalls(message?.tool_calls);
1010
- if (toolCalls.length > 0) {
1011
- for (const [index, toolCall] of toolCalls.entries()) {
1012
- const toolCallId = `call_${index}_${toolCall.name || "tool"}`;
1013
- yield {
1014
- type: "tool-call-start",
1015
- index,
1016
- toolCallId,
1017
- toolName: toolCall.name
1018
- };
1019
- const argsJson = JSON.stringify(toolCall.args);
1020
- if (argsJson && argsJson !== "{}") {
1021
- yield {
1022
- type: "tool-call-args-delta",
1023
- index,
1024
- toolCallId,
1025
- toolName: toolCall.name,
1026
- argsDelta: argsJson
1027
- };
1028
- }
1029
- yield {
1030
- type: "tool-call-ready",
1031
- index,
1032
- toolCallId,
1033
- toolName: toolCall.name,
1034
- args: toolCall.args
1035
- };
1036
- }
1037
- toolCallsEmitted = true;
1038
- }
1039
- }
1040
- if (chunk && typeof chunk === "object" && chunk.error) {
1041
- yield {
1042
- type: "error",
1043
- message: String(chunk.error)
1044
- };
1045
- }
1046
- }
1047
- yield { type: "done" };
1048
- }
1049
- async function chat3(params) {
1050
- const { config, signal } = params;
1051
- const res = await fetch(buildOllamaApiUrl(config.baseUrl, "/api/chat"), {
1052
- method: "POST",
1053
- headers: buildHeaders(config),
1054
- body: JSON.stringify(buildBody3(params, false)),
1055
- signal
1056
- });
1057
- if (!res.ok) {
1058
- const text = await res.text().catch(() => "");
1059
- throw new Error(
1060
- `Ollama request failed (${res.status} ${res.statusText}): ${text}`
1061
- );
1062
- }
1063
- const json = await res.json();
1064
- const message = json?.message ?? {};
1065
- return {
1066
- text: typeof message.content === "string" ? message.content : "",
1067
- toolCalls: normalizeToolCalls(message.tool_calls).map((tc, index) => ({
1068
- id: `call_${index}_${tc.name || "tool"}`,
1069
- name: tc.name,
1070
- args: tc.args
1071
- }))
1072
- };
1073
- }
1074
-
1075
- // src/llm/providers/openai.ts
1076
- var OPENAI_BASE_URL = "https://api.openai.com/v1";
1077
- function buildEndpoint(config, path) {
1078
- return `${config.baseUrl ?? OPENAI_BASE_URL}${path}`;
1079
- }
1080
- function buildHeaders2(config) {
1081
- const headers = {
1082
- "Content-Type": "application/json",
1083
- ...config.extraHeaders
1084
- };
1085
- if (config.apiKey) {
1086
- headers.Authorization = `Bearer ${config.apiKey}`;
1087
- }
1088
- return headers;
1089
- }
1090
- function toOpenAIContent(content) {
1091
- if (typeof content === "string") return content;
1092
- return content.map((p) => {
1093
- if (p.type === "text") return { type: "text", text: p.text };
1094
- return { type: "image_url", image_url: { url: p.url } };
1095
- });
1096
- }
1097
- function toOpenAIMessages(messages) {
1098
- const out = [];
1099
- for (const m of messages) {
1100
- if (m.role === "tool") {
1101
- const { text, imageParts } = partitionToolContent(m.content);
1102
- const fallback = imageParts.length > 0 ? "[image content; see next message]" : "[no content]";
1103
- out.push({
1104
- role: "tool",
1105
- tool_call_id: m.toolCallId,
1106
- content: text || fallback
1107
- });
1108
- if (imageParts.length > 0) {
1109
- const userParts = [
1110
- {
1111
- type: "text",
1112
- text: toolImageFollowupHeader(m.toolName, imageParts.length)
1113
- },
1114
- ...imageParts.map((p) => ({
1115
- type: "image_url",
1116
- image_url: { url: p.url }
1117
- }))
1118
- ];
1119
- out.push({ role: "user", content: userParts });
1120
- }
1121
- continue;
1122
- }
1123
- if (m.role === "assistant") {
1124
- const entry = {
1125
- role: "assistant",
1126
- content: typeof m.content === "string" && m.content.length > 0 ? m.content : null
1127
- };
1128
- if (m.toolCalls?.length) {
1129
- entry.tool_calls = m.toolCalls.map((tc) => ({
1130
- id: tc.id,
1131
- type: "function",
1132
- function: { name: tc.name, arguments: JSON.stringify(tc.args) }
1133
- }));
1134
- }
1135
- out.push(entry);
1136
- continue;
1137
- }
1138
- out.push({ role: m.role, content: toOpenAIContent(m.content) });
1139
- }
1140
- return out;
1141
- }
1142
- async function* streamChat4(params) {
1143
- const { config, messages, tools, signal } = params;
1144
- const body = {
1145
- model: config.model,
1146
- messages: toOpenAIMessages(messages),
1147
- stream: true
1148
- };
1149
- if (config.temperature !== void 0) body.temperature = config.temperature;
1150
- if (config.maxTokens !== void 0) body.max_tokens = config.maxTokens;
1151
- if (tools && tools.length > 0) {
1152
- body.tools = tools.map((t) => ({
1153
- type: "function",
1154
- function: {
1155
- name: t.name,
1156
- description: t.description,
1157
- parameters: t.inputSchema
1158
- }
1159
- }));
1160
- }
1161
- const endpoint = buildEndpoint(config, "/chat/completions");
1162
- const res = await fetch(endpoint, {
1163
- method: "POST",
1164
- headers: buildHeaders2(config),
1165
- body: JSON.stringify(body),
1166
- signal
1167
- });
1168
- if (!res.ok || !res.body) {
1169
- const text = await res.text().catch(() => "");
1170
- throw new Error(
1171
- `OpenAI request failed (${res.status} ${res.statusText}): ${text}`
1172
- );
1173
- }
1174
- const buffers = /* @__PURE__ */ new Map();
1175
- for await (const ev of parseSSE(res.body, signal)) {
1176
- if (!ev.data || ev.data === "[DONE]") continue;
1177
- let parsed;
1178
- try {
1179
- parsed = JSON.parse(ev.data);
1180
- } catch {
1181
- continue;
1182
- }
1183
- const choice = parsed?.choices?.[0];
1184
- if (!choice) continue;
1185
- const delta = choice.delta ?? {};
1186
- if (typeof delta.content === "string" && delta.content.length > 0) {
1187
- yield { type: "text-delta", delta: delta.content };
1188
- }
1189
- if (Array.isArray(delta.tool_calls)) {
1190
- for (const tc of delta.tool_calls) {
1191
- const idx = typeof tc.index === "number" ? tc.index : 0;
1192
- let buf = buffers.get(idx);
1193
- if (!buf) {
1194
- buf = {
1195
- id: tc.id ?? `call_${idx}`,
1196
- name: tc.function?.name ?? "",
1197
- argsJson: "",
1198
- started: false
1199
- };
1200
- buffers.set(idx, buf);
1201
- }
1202
- if (tc.id && !buf.id.startsWith("call_")) buf.id = tc.id;
1203
- else if (tc.id) buf.id = tc.id;
1204
- if (tc.function?.name) buf.name = tc.function.name;
1205
- if (!buf.started && buf.name) {
1206
- buf.started = true;
1207
- yield {
1208
- type: "tool-call-start",
1209
- index: idx,
1210
- toolCallId: buf.id,
1211
- toolName: buf.name
1212
- };
1213
- }
1214
- const argsChunk = tc.function?.arguments;
1215
- if (typeof argsChunk === "string" && argsChunk.length > 0) {
1216
- buf.argsJson += argsChunk;
1217
- if (buf.started) {
1218
- yield {
1219
- type: "tool-call-args-delta",
1220
- index: idx,
1221
- toolCallId: buf.id,
1222
- toolName: buf.name,
1223
- argsDelta: argsChunk
1224
- };
1225
- }
1226
- }
1227
- }
1228
- }
1229
- if (choice.finish_reason) {
1230
- for (const [idx, buf] of buffers) {
1231
- let args = {};
1232
- if (buf.argsJson) {
1233
- try {
1234
- args = JSON.parse(buf.argsJson);
1235
- } catch {
1236
- args = {};
1237
- }
1238
- }
1239
- yield {
1240
- type: "tool-call-ready",
1241
- index: idx,
1242
- toolCallId: buf.id,
1243
- toolName: buf.name,
1244
- args
1245
- };
1246
- }
1247
- buffers.clear();
1248
- }
1249
- }
1250
- yield { type: "done" };
1251
- }
1252
- async function chat4(params) {
1253
- const { config, messages, tools, signal } = params;
1254
- const body = {
1255
- model: config.model,
1256
- messages: toOpenAIMessages(messages)
1257
- };
1258
- if (config.temperature !== void 0) body.temperature = config.temperature;
1259
- if (config.maxTokens !== void 0) body.max_tokens = config.maxTokens;
1260
- if (tools && tools.length > 0) {
1261
- body.tools = tools.map((t) => ({
1262
- type: "function",
1263
- function: {
1264
- name: t.name,
1265
- description: t.description,
1266
- parameters: t.inputSchema
1267
- }
1268
- }));
1269
- }
1270
- const endpoint = buildEndpoint(config, "/chat/completions");
1271
- const res = await fetch(endpoint, {
1272
- method: "POST",
1273
- headers: buildHeaders2(config),
1274
- body: JSON.stringify(body),
1275
- signal
1276
- });
1277
- if (!res.ok) {
1278
- const text2 = await res.text().catch(() => "");
1279
- throw new Error(
1280
- `OpenAI request failed (${res.status} ${res.statusText}): ${text2}`
1281
- );
1282
- }
1283
- const json = await res.json();
1284
- const choice = json?.choices?.[0]?.message;
1285
- const text = typeof choice?.content === "string" ? choice.content : "";
1286
- const toolCalls = Array.isArray(choice?.tool_calls) ? choice.tool_calls.map((tc) => {
1287
- let args = {};
1288
- try {
1289
- args = JSON.parse(tc?.function?.arguments ?? "{}");
1290
- } catch {
1291
- args = {};
1292
- }
1293
- return {
1294
- id: tc.id,
1295
- name: tc.function?.name ?? "",
1296
- args
1297
- };
1298
- }) : [];
1299
- return { text, toolCalls };
1300
- }
1301
-
1302
- // src/llm/providers/index.ts
1303
- function withOpenRouter(params) {
1304
- return {
1305
- ...params,
1306
- config: {
1307
- ...params.config,
1308
- baseUrl: "https://openrouter.ai/api/v1",
1309
- extraHeaders: {
1310
- "HTTP-Referer": "https://inspector.mcp-use.com",
1311
- "X-Title": "mcp-use Inspector"
1312
- }
1313
- }
1314
- };
1315
- }
1316
- function streamChat5(params) {
1317
- switch (params.config.provider) {
1318
- case "openai":
1319
- case "openai-compatible":
1320
- return streamChat4(params);
1321
- case "anthropic":
1322
- return streamChat(params);
1323
- case "google":
1324
- return streamChat2(params);
1325
- case "openrouter":
1326
- return streamChat4(withOpenRouter(params));
1327
- case "ollama":
1328
- return streamChat3(params);
1329
- default:
1330
- throw new Error(`Unsupported LLM provider: ${params.config.provider}`);
1331
- }
1332
- }
1333
- function chat5(params) {
1334
- switch (params.config.provider) {
1335
- case "openai":
1336
- case "openai-compatible":
1337
- return chat4(params);
1338
- case "anthropic":
1339
- return chat(params);
1340
- case "google":
1341
- return chat2(params);
1342
- case "openrouter":
1343
- return chat4(withOpenRouter(params));
1344
- case "ollama":
1345
- return chat3(params);
1346
- default:
1347
- throw new Error(`Unsupported LLM provider: ${params.config.provider}`);
1348
- }
1349
- }
1350
-
1351
- // src/llm/toolLoop.ts
1352
- async function* runToolLoop(params) {
1353
- const { config, tools, callTool, signal } = params;
1354
- const maxSteps = params.maxSteps ?? 10;
1355
- const messages = [...params.messages];
1356
- for (let step = 0; step < maxSteps; step++) {
1357
- if (signal?.aborted) return;
1358
- const pendingToolCalls = [];
1359
- let assistantText = "";
1360
- try {
1361
- for await (const ev of streamChat5({
1362
- config,
1363
- messages,
1364
- tools,
1365
- signal
1366
- })) {
1367
- if (ev.type === "text-delta") {
1368
- assistantText += ev.delta;
1369
- } else if (ev.type === "tool-call-ready") {
1370
- pendingToolCalls.push({
1371
- id: ev.toolCallId,
1372
- name: ev.toolName,
1373
- args: ev.args
1374
- });
1375
- }
1376
- yield ev;
1377
- }
1378
- } catch (err) {
1379
- yield {
1380
- type: "error",
1381
- message: err instanceof Error ? err.message : String(err)
1382
- };
1383
- return;
1384
- }
1385
- if (pendingToolCalls.length === 0) {
1386
- return;
1387
- }
1388
- messages.push({
1389
- role: "assistant",
1390
- content: assistantText,
1391
- toolCalls: pendingToolCalls
1392
- });
1393
- for (const tc of pendingToolCalls) {
1394
- if (signal?.aborted) return;
1395
- let result;
1396
- let isError = false;
1397
- try {
1398
- result = await callTool(tc.name, tc.args);
1399
- isError = isToolResultError(result);
1400
- } catch (err) {
1401
- isError = true;
1402
- result = {
1403
- isError: true,
1404
- error: err instanceof Error ? err.message : String(err)
1405
- };
1406
- }
1407
- messages.push({
1408
- role: "tool",
1409
- content: toolResultToContent(result),
1410
- toolCallId: tc.id,
1411
- toolName: tc.name,
1412
- toolResult: result,
1413
- toolIsError: isError
1414
- });
1415
- yield {
1416
- type: "tool-result",
1417
- toolCallId: tc.id,
1418
- toolName: tc.name,
1419
- result,
1420
- isError
1421
- };
1422
- }
1423
- }
1424
- }
1425
- async function runToolLoopNonStreaming(params) {
1426
- const { config, tools, callTool, signal } = params;
1427
- const maxSteps = params.maxSteps ?? 10;
1428
- const messages = [...params.messages];
1429
- const transcriptToolCalls = [];
1430
- let finalText = "";
1431
- for (let step = 0; step < maxSteps; step++) {
1432
- if (signal?.aborted) break;
1433
- const { text, toolCalls } = await chat5({ config, messages, tools, signal });
1434
- if (toolCalls.length === 0) {
1435
- finalText = text;
1436
- break;
1437
- }
1438
- messages.push({
1439
- role: "assistant",
1440
- content: text,
1441
- toolCalls
1442
- });
1443
- for (const tc of toolCalls) {
1444
- let result;
1445
- let isError = false;
1446
- try {
1447
- result = await callTool(tc.name, tc.args);
1448
- isError = isToolResultError(result);
1449
- } catch (err) {
1450
- isError = true;
1451
- result = {
1452
- isError: true,
1453
- error: err instanceof Error ? err.message : String(err)
1454
- };
1455
- }
1456
- transcriptToolCalls.push({
1457
- toolName: tc.name,
1458
- args: tc.args,
1459
- result
1460
- });
1461
- messages.push({
1462
- role: "tool",
1463
- content: toolResultToContent(result),
1464
- toolCallId: tc.id,
1465
- toolName: tc.name,
1466
- toolResult: result,
1467
- toolIsError: isError
1468
- });
1469
- }
1470
- }
1471
- return { content: finalText, toolCalls: transcriptToolCalls };
1472
- }
1473
-
1474
- // src/server/shared-utils.ts
1475
- function toBase64(str) {
1476
- if (typeof window !== "undefined" && typeof window.btoa === "function") {
1477
- return window.btoa(str);
1478
- }
1479
- if (typeof Buffer !== "undefined") {
1480
- return Buffer.from(str).toString("base64");
1481
- }
1482
- throw new Error("No base64 encoding method available");
1483
- }
1484
- async function* handleChatRequestStream(requestBody) {
1485
- const { mcpServerUrl, llmConfig, authConfig, messages } = requestBody;
1486
- if (!mcpServerUrl || !llmConfig || !messages) {
1487
- throw new Error(
1488
- "Missing required fields: mcpServerUrl, llmConfig, messages"
1489
- );
1490
- }
1491
- const { MCPClient } = await import("mcp-use");
1492
- const client = new MCPClient();
1493
- const serverName = `inspector-${Date.now()}`;
1494
- const serverConfig = {
1495
- url: mcpServerUrl,
1496
- preventAutoAuth: true
1497
- };
1498
- if (authConfig && authConfig.type !== "none") {
1499
- serverConfig.headers = {};
1500
- if (authConfig.type === "basic" && authConfig.username && authConfig.password) {
1501
- const auth = toBase64(`${authConfig.username}:${authConfig.password}`);
1502
- serverConfig.headers.Authorization = `Basic ${auth}`;
1503
- } else if (authConfig.type === "bearer" && authConfig.token) {
1504
- serverConfig.headers.Authorization = `Bearer ${authConfig.token}`;
1505
- } else if (authConfig.type === "oauth") {
1506
- if (authConfig.oauthTokens?.access_token) {
1507
- const tokenType = authConfig.oauthTokens.token_type ? authConfig.oauthTokens.token_type.charAt(0).toUpperCase() + authConfig.oauthTokens.token_type.slice(1) : "Bearer";
1508
- serverConfig.headers.Authorization = `${tokenType} ${authConfig.oauthTokens.access_token}`;
1509
- }
1510
- }
1511
- }
1512
- try {
1513
- const url = new URL(mcpServerUrl);
1514
- if (url.username && url.password && (!authConfig || authConfig.type === "none")) {
1515
- const auth = toBase64(`${url.username}:${url.password}`);
1516
- serverConfig.headers = serverConfig.headers || {};
1517
- serverConfig.headers.Authorization = `Basic ${auth}`;
1518
- serverConfig.url = `${url.protocol}//${url.host}${url.pathname}${url.search}`;
1519
- }
1520
- } catch (error) {
1521
- console.warn("Failed to parse MCP server URL for auth:", error);
1522
- }
1523
- client.addServer(serverName, serverConfig);
1524
- try {
1525
- await client.createAllSessions();
1526
- const session = client.getAllActiveSessions()[serverName];
1527
- if (!session) {
1528
- throw new Error(`Failed to create MCP session for ${serverName}`);
1529
- }
1530
- const mcpTools = session.connector.tools ?? [];
1531
- const tools = mcpTools.map((t) => ({
1532
- name: t.name,
1533
- description: t.description,
1534
- inputSchema: t.inputSchema ?? {
1535
- type: "object"
1536
- }
1537
- }));
1538
- const providerMessages = [
1539
- {
1540
- role: "system",
1541
- content: "You are a helpful assistant with access to MCP tools. Help users interact with the MCP server."
1542
- },
1543
- ...convertMessagesToProvider(messages)
1544
- ];
1545
- const messageId = `msg-${Date.now()}`;
1546
- yield `data: ${JSON.stringify({ type: "message", id: messageId, role: "assistant" })}
1547
-
1548
- `;
1549
- const toolCallIdByIndex = /* @__PURE__ */ new Map();
1550
- for await (const ev of runToolLoop({
1551
- config: {
1552
- provider: llmConfig.provider,
1553
- model: llmConfig.model,
1554
- apiKey: llmConfig.apiKey,
1555
- temperature: llmConfig.temperature,
1556
- baseUrl: llmConfig.baseUrl
1557
- },
1558
- messages: providerMessages,
1559
- tools,
1560
- callTool: async (name, args) => {
1561
- return await session.connector.callTool(name, args);
1562
- },
1563
- maxSteps: 10
1564
- })) {
1565
- if (ev.type === "text-delta") {
1566
- yield `data: ${JSON.stringify({
1567
- type: "text",
1568
- id: messageId,
1569
- content: ev.delta
1570
- })}
1571
-
1572
- `;
1573
- } else if (ev.type === "tool-call-start") {
1574
- toolCallIdByIndex.set(ev.index, {
1575
- toolCallId: ev.toolCallId,
1576
- toolName: ev.toolName,
1577
- argsBuffer: ""
1578
- });
1579
- } else if (ev.type === "tool-call-args-delta") {
1580
- const rec = toolCallIdByIndex.get(ev.index);
1581
- if (rec) rec.argsBuffer += ev.argsDelta;
1582
- } else if (ev.type === "tool-call-ready") {
1583
- yield `data: ${JSON.stringify({
1584
- type: "tool-call",
1585
- id: messageId,
1586
- toolCallId: ev.toolCallId,
1587
- toolName: ev.toolName,
1588
- args: ev.args
1589
- })}
1590
-
1591
- `;
1592
- } else if (ev.type === "tool-result") {
1593
- yield `data: ${JSON.stringify({
1594
- type: "tool-result",
1595
- id: messageId,
1596
- toolCallId: ev.toolCallId,
1597
- toolName: ev.toolName,
1598
- result: ev.result
1599
- })}
1600
-
1601
- `;
1602
- } else if (ev.type === "error") {
1603
- yield `data: ${JSON.stringify({
1604
- type: "error",
1605
- id: messageId,
1606
- error: ev.message
1607
- })}
1608
-
1609
- `;
1610
- }
1611
- }
1612
- yield `data: ${JSON.stringify({ type: "done", id: messageId })}
1613
-
1614
- `;
1615
- } finally {
1616
- await client.closeAllSessions();
1617
- }
1618
- }
1619
- async function handleChatRequest(requestBody) {
1620
- const { mcpServerUrl, llmConfig, authConfig, messages } = requestBody;
1621
- if (!mcpServerUrl || !llmConfig || !messages) {
1622
- throw new Error(
1623
- "Missing required fields: mcpServerUrl, llmConfig, messages"
1624
- );
1625
- }
1626
- const { MCPClient } = await import("mcp-use");
1627
- const client = new MCPClient();
1628
- const serverName = `inspector-${Date.now()}`;
1629
- const serverConfig = {
1630
- url: mcpServerUrl,
1631
- preventAutoAuth: true
1632
- };
1633
- if (authConfig && authConfig.type !== "none") {
1634
- serverConfig.headers = {};
1635
- if (authConfig.type === "basic" && authConfig.username && authConfig.password) {
1636
- const auth = toBase64(`${authConfig.username}:${authConfig.password}`);
1637
- serverConfig.headers.Authorization = `Basic ${auth}`;
1638
- } else if (authConfig.type === "bearer" && authConfig.token) {
1639
- serverConfig.headers.Authorization = `Bearer ${authConfig.token}`;
1640
- } else if (authConfig.type === "oauth") {
1641
- if (authConfig.oauthTokens?.access_token) {
1642
- const tokenType = authConfig.oauthTokens.token_type ? authConfig.oauthTokens.token_type.charAt(0).toUpperCase() + authConfig.oauthTokens.token_type.slice(1) : "Bearer";
1643
- serverConfig.headers.Authorization = `${tokenType} ${authConfig.oauthTokens.access_token}`;
1644
- }
1645
- }
1646
- }
1647
- try {
1648
- const url = new URL(mcpServerUrl);
1649
- if (url.username && url.password && (!authConfig || authConfig.type === "none")) {
1650
- const auth = toBase64(`${url.username}:${url.password}`);
1651
- serverConfig.headers = serverConfig.headers || {};
1652
- serverConfig.headers.Authorization = `Basic ${auth}`;
1653
- serverConfig.url = `${url.protocol}//${url.host}${url.pathname}${url.search}`;
1654
- }
1655
- } catch (error) {
1656
- console.warn("Failed to parse MCP server URL for auth:", error);
1657
- }
1658
- client.addServer(serverName, serverConfig);
1659
- try {
1660
- await client.createAllSessions();
1661
- const session = client.getAllActiveSessions()[serverName];
1662
- if (!session) {
1663
- throw new Error(`Failed to create MCP session for ${serverName}`);
1664
- }
1665
- const mcpTools = session.connector.tools ?? [];
1666
- const tools = mcpTools.map((t) => ({
1667
- name: t.name,
1668
- description: t.description,
1669
- inputSchema: t.inputSchema ?? {
1670
- type: "object"
1671
- }
1672
- }));
1673
- const providerMessages = [
1674
- {
1675
- role: "system",
1676
- content: "You are a helpful assistant with access to MCP tools. Help users interact with the MCP server."
1677
- },
1678
- ...convertMessagesToProvider(messages)
1679
- ];
1680
- const { content, toolCalls } = await runToolLoopNonStreaming({
1681
- config: {
1682
- provider: llmConfig.provider,
1683
- model: llmConfig.model,
1684
- apiKey: llmConfig.apiKey,
1685
- temperature: llmConfig.temperature,
1686
- baseUrl: llmConfig.baseUrl
1687
- },
1688
- messages: providerMessages,
1689
- tools,
1690
- callTool: async (name, args) => {
1691
- return await session.connector.callTool(name, args);
1692
- },
1693
- maxSteps: 10
1694
- });
1695
- return {
1696
- content,
1697
- toolCalls: toolCalls.map((tc) => ({
1698
- name: tc.toolName,
1699
- arguments: tc.args,
1700
- result: tc.result
1701
- }))
1702
- };
1703
- } finally {
1704
- await client.closeAllSessions();
1705
- }
1706
- }
1707
- var widgetDataStore = /* @__PURE__ */ new Map();
1708
- setInterval(
1709
- () => {
1710
- const now = Date.now();
1711
- const ONE_HOUR = 60 * 60 * 1e3;
1712
- for (const [toolId, data] of widgetDataStore.entries()) {
1713
- if (now - data.timestamp > ONE_HOUR) {
1714
- widgetDataStore.delete(toolId);
1715
- }
1716
- }
1717
- },
1718
- 5 * 60 * 1e3
1719
- ).unref();
1720
- function storeWidgetData(data) {
1721
- const {
1722
- serverId,
1723
- uri,
1724
- toolInput,
1725
- toolOutput,
1726
- toolResponseMetadata,
1727
- resourceData,
1728
- toolId,
1729
- widgetCSP,
1730
- mcpAppsCsp,
1731
- mcpAppsPermissions,
1732
- devWidgetUrl,
1733
- devServerBaseUrl,
1734
- theme
1735
- } = data;
1736
- const debugWidget = process.env.DEBUG != null && process.env.DEBUG !== "" && process.env.DEBUG !== "0" && process.env.DEBUG.toLowerCase() !== "false";
1737
- if (debugWidget) {
1738
- console.log("[Widget Store] Received request for toolId:", toolId);
1739
- console.log("[Widget Store] Fields:", {
1740
- serverId,
1741
- uri,
1742
- hasResourceData: !!resourceData,
1743
- hasToolInput: !!toolInput,
1744
- hasToolOutput: !!toolOutput,
1745
- hasToolResponseMetadata: !!toolResponseMetadata,
1746
- toolResponseMetadata,
1747
- hasWidgetCSP: !!widgetCSP,
1748
- devWidgetUrl,
1749
- devServerBaseUrl
1750
- });
1751
- }
1752
- if (!serverId || !uri || !toolId || !resourceData) {
1753
- const missingFields = [];
1754
- if (!serverId) missingFields.push("serverId");
1755
- if (!uri) missingFields.push("uri");
1756
- if (!toolId) missingFields.push("toolId");
1757
- if (!resourceData) missingFields.push("resourceData");
1758
- console.error("[Widget Store] Missing required fields:", missingFields);
1759
- return {
1760
- success: false,
1761
- error: `Missing required fields: ${missingFields.join(", ")}`
1762
- };
1763
- }
1764
- widgetDataStore.set(toolId, {
1765
- serverId,
1766
- uri,
1767
- toolInput,
1768
- toolOutput,
1769
- toolResponseMetadata,
1770
- resourceData,
1771
- toolId,
1772
- timestamp: Date.now(),
1773
- widgetCSP,
1774
- mcpAppsCsp,
1775
- mcpAppsPermissions,
1776
- devWidgetUrl,
1777
- devServerBaseUrl,
1778
- theme
1779
- });
1780
- if (debugWidget) {
1781
- console.log("[Widget Store] Data stored successfully for toolId:", toolId);
1782
- }
1783
- return { success: true };
1784
- }
1785
- function getWidgetData(toolId) {
1786
- return widgetDataStore.get(toolId);
1787
- }
1788
- function generateWidgetContainerHtml(basePath, toolId) {
1789
- return `
1790
- <!DOCTYPE html>
1791
- <html>
1792
- <head>
1793
- <meta charset="utf-8">
1794
- <title>Loading Widget...</title>
1795
- </head>
1796
- <body>
1797
- <script>
1798
- (async function() {
1799
- try {
1800
- // Fetch the actual widget HTML using toolId
1801
- const response = await fetch('${basePath}/api/resources/widget-content/${toolId}');
1802
- const html = await response.text();
1803
-
1804
- // Replace entire document with widget HTML using proper method
1805
- document.open();
1806
- document.write(html);
1807
- document.close();
1808
- } catch (error) {
1809
- console.error('Failed to load widget:', error);
1810
- document.body.innerHTML = '<div style="padding: 20px; color: red;">Failed to load widget: ' + error.message + '</div>';
1811
- }
1812
- })();
1813
- </script>
1814
- </body>
1815
- </html>
1816
- `;
1817
- }
1818
- function generateWidgetContentHtml(widgetData) {
1819
- const {
1820
- serverId,
1821
- uri,
1822
- toolInput,
1823
- toolOutput,
1824
- toolResponseMetadata,
1825
- resourceData,
1826
- toolId,
1827
- theme,
1828
- playground
1829
- } = widgetData;
1830
- const debugWidget = process.env.DEBUG != null && process.env.DEBUG !== "" && process.env.DEBUG !== "0" && process.env.DEBUG.toLowerCase() !== "false";
1831
- if (debugWidget) {
1832
- console.log("[Widget Content] Using pre-fetched resource for:", {
1833
- serverId,
1834
- uri
1835
- });
1836
- }
1837
- let htmlContent = "";
1838
- const contentsArray = Array.isArray(resourceData?.contents) ? resourceData.contents : [];
1839
- const firstContent = contentsArray[0];
1840
- if (firstContent) {
1841
- if (typeof firstContent.text === "string") {
1842
- htmlContent = firstContent.text;
1843
- } else if (typeof firstContent.blob === "string") {
1844
- htmlContent = firstContent.blob;
1845
- }
1846
- }
1847
- if (!htmlContent && resourceData && typeof resourceData === "object") {
1848
- const recordContent = resourceData;
1849
- if (typeof recordContent.text === "string") {
1850
- htmlContent = recordContent.text;
1851
- } else if (typeof recordContent.blob === "string") {
1852
- htmlContent = recordContent.blob;
1853
- }
1854
- }
1855
- if (!htmlContent) {
1856
- return { html: "", error: "No HTML content found" };
1857
- }
1858
- const widgetStateKey = `openai-widget-state:${toolId}`;
1859
- const safeToolInput = JSON.stringify(toolInput ?? null).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
1860
- const safeToolOutput = JSON.stringify(toolOutput ?? null).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
1861
- const safeToolResponseMetadata = JSON.stringify(toolResponseMetadata ?? null).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
1862
- const safeToolId = JSON.stringify(toolId);
1863
- const safeWidgetStateKey = JSON.stringify(widgetStateKey);
1864
- const safeTheme = JSON.stringify(theme === "dark" ? "dark" : "light");
1865
- const locale = playground?.locale || "en-US";
1866
- const deviceType = playground?.deviceType || "desktop";
1867
- const capabilities = playground?.capabilities || {
1868
- hover: true,
1869
- touch: false
1870
- };
1871
- const safeAreaInsets = playground?.safeAreaInsets || {
1872
- top: 0,
1873
- right: 0,
1874
- bottom: 0,
1875
- left: 0
1876
- };
1877
- const safeLocale = JSON.stringify(locale);
1878
- const safeUserAgent = JSON.stringify({
1879
- device: { type: deviceType },
1880
- capabilities
1881
- });
1882
- const safeSafeArea = JSON.stringify({ insets: safeAreaInsets });
1883
- const apiScript = `
1884
- <script>
1885
- (function() {
1886
- 'use strict';
1887
-
1888
- // Change URL to "/" for React Router compatibility.
1889
- // Skip when loaded inside the inspector (widget-content endpoint)
1890
- // to prevent Vite HMR reloads from navigating to "/" (inspector SPA).
1891
- if (window.location.pathname !== '/' && !window.location.pathname.includes('/inspector/')) {
1892
- history.replaceState(null, '', '/');
1893
- }
1894
-
1895
- function emitWidgetRuntimeError(payload) {
1896
- var args = [{
1897
- message: payload && payload.message ? payload.message : "Unknown widget runtime error",
1898
- stack: payload && payload.stack ? payload.stack : undefined,
1899
- source: payload && payload.source ? payload.source : undefined,
1900
- fileName: payload && payload.fileName ? payload.fileName : undefined,
1901
- line: payload && payload.line ? payload.line : undefined,
1902
- column: payload && payload.column ? payload.column : undefined,
1903
- timestamp: payload && payload.timestamp ? payload.timestamp : Date.now(),
1904
- }];
1905
- try {
1906
- window.parent.postMessage(
1907
- {
1908
- type: "iframe-console-log",
1909
- level: "error",
1910
- args: args,
1911
- timestamp: new Date().toISOString(),
1912
- url: window.location.href,
1913
- toolId: ${safeToolId},
1914
- },
1915
- "*"
1916
- );
1917
- } catch (emitErr) {}
1918
- }
1919
-
1920
- window.addEventListener("error", function(event) {
1921
- var err = event && event.error;
1922
- var message =
1923
- (err && err.message) ||
1924
- (event && event.message) ||
1925
- "Unknown widget runtime error";
1926
- emitWidgetRuntimeError({
1927
- source: "window.error",
1928
- message: String(message),
1929
- stack: err && err.stack ? String(err.stack) : undefined,
1930
- fileName: event && event.filename ? String(event.filename) : undefined,
1931
- line: event && typeof event.lineno === "number" ? event.lineno : undefined,
1932
- column: event && typeof event.colno === "number" ? event.colno : undefined,
1933
- timestamp: Date.now(),
1934
- });
1935
- });
1936
-
1937
- window.addEventListener("unhandledrejection", function(event) {
1938
- var reason = event ? event.reason : undefined;
1939
- var message = "Unhandled promise rejection";
1940
- var stack = undefined;
1941
- if (reason && typeof reason === "object") {
1942
- message = String(reason.message || message);
1943
- stack = reason.stack ? String(reason.stack) : undefined;
1944
- } else if (typeof reason === "string") {
1945
- message = reason;
1946
- } else if (reason != null) {
1947
- message = String(reason);
1948
- }
1949
- emitWidgetRuntimeError({
1950
- source: "window.unhandledrejection",
1951
- message: message,
1952
- stack: stack,
1953
- timestamp: Date.now(),
1954
- });
1955
- });
1956
-
1957
- const openaiAPI = {
1958
- toolInput: ${safeToolInput},
1959
- toolOutput: ${safeToolOutput},
1960
- toolResponseMetadata: ${safeToolResponseMetadata},
1961
- displayMode: 'inline',
1962
- maxHeight: 600,
1963
- theme: ${safeTheme},
1964
- locale: ${safeLocale},
1965
- safeArea: ${safeSafeArea},
1966
- userAgent: ${safeUserAgent},
1967
- widgetState: null,
1968
-
1969
- async setWidgetState(state) {
1970
- this.widgetState = state;
1971
- try {
1972
- localStorage.setItem(${safeWidgetStateKey}, JSON.stringify(state));
1973
- } catch (err) {
1974
- console.error('[OpenAI Widget] Failed to save widget state:', err);
1975
- }
1976
- window.parent.postMessage({
1977
- type: 'openai:setWidgetState',
1978
- toolId: ${safeToolId},
1979
- state
1980
- }, '*');
1981
- },
1982
-
1983
- async callTool(toolName, params = {}) {
1984
- return new Promise((resolve, reject) => {
1985
- const requestId = \`tool_\${Date.now()}_\${Math.random()}\`;
1986
- const handler = (event) => {
1987
- if (event.data.type === 'openai:callTool:response' &&
1988
- event.data.requestId === requestId) {
1989
- window.removeEventListener('message', handler);
1990
- if (event.data.error) {
1991
- reject(new Error(event.data.error));
1992
- } else {
1993
- resolve(event.data.result);
1994
- }
1995
- }
1996
- };
1997
- window.addEventListener('message', handler);
1998
- window.parent.postMessage({
1999
- type: 'openai:callTool',
2000
- requestId,
2001
- toolName,
2002
- params
2003
- }, '*');
2004
- setTimeout(() => {
2005
- window.removeEventListener('message', handler);
2006
- reject(new Error('Tool call timeout'));
2007
- }, 30000);
2008
- });
2009
- },
2010
-
2011
- async sendFollowupTurn(message) {
2012
- const payload = typeof message === 'string'
2013
- ? { prompt: message }
2014
- : message;
2015
- window.parent.postMessage({
2016
- type: 'openai:sendFollowup',
2017
- message: payload.prompt || payload
2018
- }, '*');
2019
- },
2020
-
2021
- async requestDisplayMode(options = {}) {
2022
- const mode = options.mode || 'inline';
2023
- this.displayMode = mode;
2024
- window.parent.postMessage({
2025
- type: 'openai:requestDisplayMode',
2026
- mode
2027
- }, '*');
2028
- return { mode };
2029
- },
2030
-
2031
- async sendFollowUpMessage(args) {
2032
- const prompt = typeof args === 'string' ? args : (args?.prompt || '');
2033
- return this.sendFollowupTurn(prompt);
2034
- },
2035
-
2036
- async notifyIntrinsicHeight(height) {
2037
- console.log('[OpenAI Widget] notifyIntrinsicHeight called with:', height);
2038
- if (typeof height !== 'number' || height < 0) {
2039
- console.error('[OpenAI Widget] Invalid height value:', height);
2040
- throw new Error('Height must be a non-negative number');
2041
- }
2042
- const message = {
2043
- type: 'openai:notifyIntrinsicHeight',
2044
- height
2045
- };
2046
- console.log('[OpenAI Widget] Sending postMessage to parent:', message);
2047
- window.parent.postMessage(message, '*');
2048
- },
2049
-
2050
- openExternal(payload) {
2051
- const href = typeof payload === 'string' ? payload : payload?.href;
2052
- if (href) {
2053
- window.open(href, '_blank', 'noopener,noreferrer');
2054
- }
2055
- }
2056
- };
2057
-
2058
- // Report CSP violations to the inspector host
2059
- document.addEventListener('securitypolicyviolation', function(e) {
2060
- window.parent.postMessage({
2061
- type: 'openai:csp-violation',
2062
- toolId: ${safeToolId},
2063
- directive: e.violatedDirective,
2064
- effectiveDirective: e.effectiveDirective,
2065
- blockedUri: e.blockedURI,
2066
- sourceFile: e.sourceFile || null,
2067
- lineNumber: e.lineNumber,
2068
- columnNumber: e.columnNumber,
2069
- originalPolicy: e.originalPolicy,
2070
- disposition: e.disposition,
2071
- timestamp: Date.now(),
2072
- }, '*');
2073
- });
2074
-
2075
- Object.defineProperty(window, 'openai', {
2076
- value: openaiAPI,
2077
- writable: false,
2078
- configurable: false,
2079
- enumerable: true
2080
- });
2081
-
2082
- Object.defineProperty(window, 'webplus', {
2083
- value: openaiAPI,
2084
- writable: false,
2085
- configurable: false,
2086
- enumerable: true
2087
- });
2088
-
2089
- // Do not fire openai:set_globals here \u2014 window.openai is already set synchronously.
2090
- // useSyncExternalStore reads it on first render. Firing the event would cause a
2091
- // redundant second render (double flash at pending/final state).
2092
-
2093
- // Listen for widget state requests from inspector
2094
- window.addEventListener('message', (event) => {
2095
- if (event.data?.type === 'mcp-inspector:getWidgetState') {
2096
- window.parent.postMessage({
2097
- type: 'mcp-inspector:widgetStateResponse',
2098
- toolId: event.data.toolId,
2099
- state: openaiAPI.widgetState
2100
- }, '*');
2101
- return;
2102
- }
2103
- });
2104
-
2105
- // Listen for globals changes from parent (for displayMode, theme, etc.)
2106
- window.addEventListener('message', (event) => {
2107
- // Handle new general globalsChanged message
2108
- if (event.data?.type === 'openai:globalsChanged') {
2109
- const updates = event.data.updates || {};
2110
- let hasChanges = false;
2111
-
2112
- // Update displayMode
2113
- if (updates.displayMode && ['inline', 'pip', 'fullscreen'].includes(updates.displayMode)) {
2114
- openaiAPI.displayMode = updates.displayMode;
2115
- hasChanges = true;
2116
- }
2117
-
2118
- // Update theme
2119
- if (updates.theme && ['light', 'dark'].includes(updates.theme)) {
2120
- openaiAPI.theme = updates.theme;
2121
- hasChanges = true;
2122
- }
2123
-
2124
- // Update maxHeight
2125
- if (updates.maxHeight !== undefined && typeof updates.maxHeight === 'number') {
2126
- openaiAPI.maxHeight = updates.maxHeight;
2127
- hasChanges = true;
2128
- }
2129
-
2130
- // Update locale
2131
- if (updates.locale && typeof updates.locale === 'string') {
2132
- openaiAPI.locale = updates.locale;
2133
- hasChanges = true;
2134
- }
2135
-
2136
- // Update safeArea
2137
- if (updates.safeArea && typeof updates.safeArea === 'object') {
2138
- openaiAPI.safeArea = updates.safeArea;
2139
- hasChanges = true;
2140
- }
2141
-
2142
- // Update userAgent
2143
- if (updates.userAgent !== undefined) {
2144
- openaiAPI.userAgent = updates.userAgent;
2145
- hasChanges = true;
2146
- }
2147
-
2148
- // Dispatch set_globals event to notify React components if any changes occurred
2149
- if (hasChanges) {
2150
- try {
2151
- const globalsEvent = new CustomEvent('openai:set_globals', {
2152
- detail: {
2153
- globals: {
2154
- toolInput: openaiAPI.toolInput,
2155
- toolOutput: openaiAPI.toolOutput,
2156
- toolResponseMetadata: openaiAPI.toolResponseMetadata || null,
2157
- widgetState: openaiAPI.widgetState,
2158
- displayMode: openaiAPI.displayMode,
2159
- maxHeight: openaiAPI.maxHeight,
2160
- theme: openaiAPI.theme,
2161
- locale: openaiAPI.locale,
2162
- safeArea: openaiAPI.safeArea,
2163
- userAgent: openaiAPI.userAgent
2164
- }
2165
- }
2166
- });
2167
- window.dispatchEvent(globalsEvent);
2168
- } catch (err) {}
2169
- }
2170
- }
2171
- // Handle legacy displayModeChanged message for backward compatibility
2172
- else if (event.data?.type === 'openai:displayModeChanged') {
2173
- const newMode = event.data.mode;
2174
- if (newMode && ['inline', 'pip', 'fullscreen'].includes(newMode)) {
2175
- openaiAPI.displayMode = newMode;
2176
- // Dispatch set_globals event to notify React components
2177
- try {
2178
- const globalsEvent = new CustomEvent('openai:set_globals', {
2179
- detail: {
2180
- globals: {
2181
- toolInput: openaiAPI.toolInput,
2182
- toolOutput: openaiAPI.toolOutput,
2183
- toolResponseMetadata: openaiAPI.toolResponseMetadata || null,
2184
- widgetState: openaiAPI.widgetState,
2185
- displayMode: newMode,
2186
- maxHeight: openaiAPI.maxHeight,
2187
- theme: openaiAPI.theme,
2188
- locale: openaiAPI.locale,
2189
- safeArea: openaiAPI.safeArea,
2190
- userAgent: openaiAPI.userAgent
2191
- }
2192
- }
2193
- });
2194
- window.dispatchEvent(globalsEvent);
2195
- } catch (err) {}
2196
- }
2197
- }
2198
- });
2199
-
2200
- setTimeout(() => {
2201
- try {
2202
- const stored = localStorage.getItem(${safeWidgetStateKey});
2203
- if (stored && window.openai) {
2204
- window.openai.widgetState = JSON.parse(stored);
2205
- }
2206
- } catch (err) {}
2207
- }, 0);
2208
- })();
2209
- </script>
2210
- `;
2211
- let modifiedHtml;
2212
- if (htmlContent.includes("<html") && htmlContent.includes("<head")) {
2213
- modifiedHtml = htmlContent.replace("<head>", `<head>${apiScript}`);
2214
- } else {
2215
- modifiedHtml = `<!DOCTYPE html>
2216
- <html>
2217
- <head>
2218
- <meta charset="UTF-8">
2219
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
2220
- ${apiScript}
2221
- <title>Widget</title>
2222
- </head>
2223
- <body>
2224
- ${htmlContent}
2225
- </body>
2226
- </html>`;
2227
- }
2228
- if (debugWidget) {
2229
- console.log("[Widget Content] Generated HTML length:", modifiedHtml.length);
2230
- }
2231
- return { html: modifiedHtml };
2232
- }
2233
- function transformMcpAppsCspToSnakeCase(mcpAppsCsp) {
2234
- if (!mcpAppsCsp) return void 0;
2235
- const result = {};
2236
- if (mcpAppsCsp.connectDomains) {
2237
- result.connect_domains = mcpAppsCsp.connectDomains;
2238
- }
2239
- if (mcpAppsCsp.resourceDomains) {
2240
- result.resource_domains = mcpAppsCsp.resourceDomains;
2241
- }
2242
- if (mcpAppsCsp.frameDomains) {
2243
- result.frame_domains = mcpAppsCsp.frameDomains;
2244
- }
2245
- return Object.keys(result).length > 0 ? result : void 0;
2246
- }
2247
- function getWidgetSecurityHeaders(widgetCSP, devServerBaseUrl, frameAncestors) {
2248
- const trustedCdns = [
2249
- "https://persistent.oaistatic.com",
2250
- "https://*.oaistatic.com",
2251
- "https://unpkg.com",
2252
- "https://cdn.jsdelivr.net",
2253
- "https://cdnjs.cloudflare.com",
2254
- "https://cdn.skypack.dev",
2255
- "https://*.openai.com"
2256
- ];
2257
- const prodResourceDomains = [...trustedCdns];
2258
- if (widgetCSP?.resource_domains) {
2259
- prodResourceDomains.push(...widgetCSP.resource_domains);
2260
- }
2261
- const prodResourceDomainsStr = prodResourceDomains.join(" ");
2262
- let devServerOrigin = null;
2263
- const allResourceDomains = [...prodResourceDomains];
2264
- if (devServerBaseUrl) {
2265
- try {
2266
- devServerOrigin = new URL(devServerBaseUrl).origin;
2267
- allResourceDomains.push(devServerOrigin);
2268
- } catch (e) {
2269
- console.warn(`[CSP] Invalid devServerBaseUrl: ${devServerBaseUrl}`);
2270
- }
2271
- }
2272
- const resourceDomainsStr = allResourceDomains.join(" ");
2273
- let imgSrc = "'self' data: https: blob:";
2274
- if (devServerOrigin) {
2275
- imgSrc = `'self' data: https: blob: ${devServerOrigin}`;
2276
- }
2277
- let mediaSrc = "'self' data: https: blob:";
2278
- if (devServerOrigin) {
2279
- mediaSrc = `'self' data: https: blob: ${devServerOrigin}`;
2280
- }
2281
- let fontSrc = `'self' data: ${resourceDomainsStr}`;
2282
- if (devServerOrigin) {
2283
- fontSrc = `'self' data: https: http: ${resourceDomainsStr}`;
2284
- }
2285
- let connectSrc = "'self' https: wss: ws:";
2286
- if (widgetCSP?.connect_domains && widgetCSP.connect_domains.length > 0) {
2287
- connectSrc = `'self' ${widgetCSP.connect_domains.join(" ")} https: wss: ws:`;
2288
- }
2289
- let frameSrc = "'self' blob:";
2290
- const frameDomains = widgetCSP?.frame_domains || widgetCSP?.resource_domains;
2291
- if (frameDomains && frameDomains.length > 0) {
2292
- frameSrc = `'self' blob: ${frameDomains.join(" ")}`;
2293
- }
2294
- let frameAncestorsPolicy = "*";
2295
- if (frameAncestors) {
2296
- frameAncestorsPolicy = `'self' ${frameAncestors}`.trim();
2297
- }
2298
- const headers = {
2299
- "Content-Security-Policy": [
2300
- "default-src 'self'",
2301
- `script-src 'self' 'unsafe-inline' 'unsafe-eval' ${resourceDomainsStr}`,
2302
- "worker-src 'self' blob:",
2303
- `child-src 'self' blob: ${frameDomains?.join(" ") || ""}`.trim(),
2304
- `frame-src ${frameSrc}`,
2305
- `style-src 'self' 'unsafe-inline' ${resourceDomainsStr}`,
2306
- `img-src ${imgSrc}`,
2307
- `media-src ${mediaSrc}`,
2308
- `font-src ${fontSrc}`,
2309
- `connect-src ${connectSrc}`,
2310
- `frame-ancestors ${frameAncestorsPolicy}`
2311
- ].join("; "),
2312
- "X-Frame-Options": "SAMEORIGIN",
2313
- "X-Content-Type-Options": "nosniff",
2314
- "Cache-Control": "no-cache, no-store, must-revalidate",
2315
- Pragma: "no-cache",
2316
- Expires: "0"
2317
- };
2318
- if (devServerOrigin) {
2319
- const prodConnectSrc = "'self' https: wss: ws:";
2320
- let prodFrameSrc = "'self' blob:";
2321
- const prodFrameDomains = widgetCSP?.frame_domains || widgetCSP?.resource_domains;
2322
- if (prodFrameDomains && prodFrameDomains.length > 0) {
2323
- prodFrameSrc = `'self' blob: ${prodFrameDomains.join(" ")}`;
2324
- }
2325
- headers["Content-Security-Policy-Report-Only"] = [
2326
- "default-src 'self'",
2327
- `script-src 'self' 'unsafe-inline' 'unsafe-eval' ${prodResourceDomainsStr}`,
2328
- "worker-src 'self' blob:",
2329
- `child-src 'self' blob: ${prodFrameDomains?.join(" ") || ""}`.trim(),
2330
- `frame-src ${prodFrameSrc}`,
2331
- `style-src 'self' 'unsafe-inline' ${prodResourceDomainsStr}`,
2332
- "img-src 'self' data: https: blob:",
2333
- "media-src 'self' data: https: blob:",
2334
- `font-src 'self' data: ${prodResourceDomainsStr}`,
2335
- `connect-src ${prodConnectSrc}`,
2336
- `frame-ancestors ${frameAncestorsPolicy}`
2337
- ].join("; ");
2338
- }
2339
- return headers;
2340
- }
2341
-
2342
- export {
2343
- handleChatRequestStream,
2344
- handleChatRequest,
2345
- storeWidgetData,
2346
- getWidgetData,
2347
- generateWidgetContainerHtml,
2348
- generateWidgetContentHtml,
2349
- transformMcpAppsCspToSnakeCase,
2350
- getWidgetSecurityHeaders
2351
- };