@devicai/ui 0.57.0 → 0.59.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 (223) hide show
  1. package/README.md +186 -0
  2. package/dist/cjs/api/assistantInfo.js.map +1 -1
  3. package/dist/cjs/api/client.js +17 -1
  4. package/dist/cjs/api/client.js.map +1 -1
  5. package/dist/cjs/api/types.js.map +1 -1
  6. package/dist/cjs/components/AICommandBar/AICommandBar.js +12 -8
  7. package/dist/cjs/components/AICommandBar/AICommandBar.js.map +1 -1
  8. package/dist/cjs/components/AICommandBar/useAICommandBar.js +12 -6
  9. package/dist/cjs/components/AICommandBar/useAICommandBar.js.map +1 -1
  10. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js +19 -15
  11. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  12. package/dist/cjs/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
  13. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js +12 -6
  14. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  15. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js +13 -7
  16. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  17. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js +11 -5
  18. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  19. package/dist/cjs/components/ChatDrawer/ChatDrawer.js +28 -13
  20. package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
  21. package/dist/cjs/components/ChatDrawer/ChatInput.js +21 -15
  22. package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -1
  23. package/dist/cjs/components/ChatDrawer/ChatMessages.js +54 -13
  24. package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -1
  25. package/dist/cjs/components/ChatDrawer/CompactionWidget.js +13 -4
  26. package/dist/cjs/components/ChatDrawer/CompactionWidget.js.map +1 -1
  27. package/dist/cjs/components/ChatDrawer/ConversationSelector.js +6 -4
  28. package/dist/cjs/components/ChatDrawer/ConversationSelector.js.map +1 -1
  29. package/dist/cjs/components/ChatDrawer/ErrorBoundary.js.map +1 -1
  30. package/dist/cjs/components/ChatDrawer/GuardrailNotice.js +40 -0
  31. package/dist/cjs/components/ChatDrawer/GuardrailNotice.js.map +1 -0
  32. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js +3 -1
  33. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  34. package/dist/cjs/components/ChatDrawer/LimitBanner.js +19 -9
  35. package/dist/cjs/components/ChatDrawer/LimitBanner.js.map +1 -1
  36. package/dist/cjs/components/ChatDrawer/QueueNotice.js +19 -7
  37. package/dist/cjs/components/ChatDrawer/QueueNotice.js.map +1 -1
  38. package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js +17 -5
  39. package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
  40. package/dist/cjs/components/ChatDrawer/ReferenceChip.js +3 -1
  41. package/dist/cjs/components/ChatDrawer/ReferenceChip.js.map +1 -1
  42. package/dist/cjs/components/ChatDrawer/ToolTimeline.js.map +1 -1
  43. package/dist/cjs/components/ChatDrawer/UsageBar.js +23 -18
  44. package/dist/cjs/components/ChatDrawer/UsageBar.js.map +1 -1
  45. package/dist/cjs/components/ChatDrawer/pastedText.js.map +1 -1
  46. package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js +20 -9
  47. package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
  48. package/dist/cjs/components/Feedback/FeedbackModal.js +5 -1
  49. package/dist/cjs/components/Feedback/FeedbackModal.js.map +1 -1
  50. package/dist/cjs/components/Feedback/MessageActions.js +3 -1
  51. package/dist/cjs/components/Feedback/MessageActions.js.map +1 -1
  52. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js +12 -8
  53. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
  54. package/dist/cjs/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
  55. package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js +5 -3
  56. package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
  57. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js +12 -3
  58. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
  59. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  60. package/dist/cjs/components/IntegrationsModal/IntegrationsPanel.js +34 -24
  61. package/dist/cjs/components/IntegrationsModal/IntegrationsPanel.js.map +1 -1
  62. package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js +15 -6
  63. package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
  64. package/dist/cjs/components/IntegrationsModal/McpConnectForm.js +15 -7
  65. package/dist/cjs/components/IntegrationsModal/McpConnectForm.js.map +1 -1
  66. package/dist/cjs/components/IntegrationsModal/McpServersSection.js +32 -19
  67. package/dist/cjs/components/IntegrationsModal/McpServersSection.js.map +1 -1
  68. package/dist/cjs/components/IntegrationsModal/integrationChoice.js.map +1 -1
  69. package/dist/cjs/components/IntegrationsModal/useIntegrations.js +3 -1
  70. package/dist/cjs/components/IntegrationsModal/useIntegrations.js.map +1 -1
  71. package/dist/cjs/components/IntegrationsModal/useTenantMcp.js +3 -1
  72. package/dist/cjs/components/IntegrationsModal/useTenantMcp.js.map +1 -1
  73. package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js +63 -40
  74. package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
  75. package/dist/cjs/components/theme.js.map +1 -1
  76. package/dist/cjs/hooks/useDevicChat.js +21 -7
  77. package/dist/cjs/hooks/useDevicChat.js.map +1 -1
  78. package/dist/cjs/hooks/useModelInterface.js.map +1 -1
  79. package/dist/cjs/hooks/usePolling.js +117 -7
  80. package/dist/cjs/hooks/usePolling.js.map +1 -1
  81. package/dist/cjs/hooks/useSpeechRecording.js +8 -4
  82. package/dist/cjs/hooks/useSpeechRecording.js.map +1 -1
  83. package/dist/cjs/i18n/translate.js +48 -0
  84. package/dist/cjs/i18n/translate.js.map +1 -0
  85. package/dist/cjs/i18n/useTranslations.js +57 -0
  86. package/dist/cjs/i18n/useTranslations.js.map +1 -0
  87. package/dist/cjs/index.js +11 -0
  88. package/dist/cjs/index.js.map +1 -1
  89. package/dist/cjs/provider/DevicContext.js.map +1 -1
  90. package/dist/cjs/provider/DevicProvider.js +5 -1
  91. package/dist/cjs/provider/DevicProvider.js.map +1 -1
  92. package/dist/cjs/provider/sharedSession.js.map +1 -1
  93. package/dist/cjs/styles.css +1 -1
  94. package/dist/cjs/utils/avatar.js.map +1 -1
  95. package/dist/cjs/utils/consumeChatStream.js +44 -0
  96. package/dist/cjs/utils/consumeChatStream.js.map +1 -0
  97. package/dist/cjs/utils/index.js.map +1 -1
  98. package/dist/cjs/utils/logger.js.map +1 -1
  99. package/dist/cjs/utils/toolGroups.js.map +1 -1
  100. package/dist/esm/api/assistantInfo.js.map +1 -1
  101. package/dist/esm/api/client.d.ts +5 -1
  102. package/dist/esm/api/client.js +17 -1
  103. package/dist/esm/api/client.js.map +1 -1
  104. package/dist/esm/api/types.d.ts +12 -1
  105. package/dist/esm/api/types.js.map +1 -1
  106. package/dist/esm/components/AICommandBar/AICommandBar.js +13 -9
  107. package/dist/esm/components/AICommandBar/AICommandBar.js.map +1 -1
  108. package/dist/esm/components/AICommandBar/AICommandBar.types.d.ts +16 -0
  109. package/dist/esm/components/AICommandBar/useAICommandBar.d.ts +2 -0
  110. package/dist/esm/components/AICommandBar/useAICommandBar.js +13 -7
  111. package/dist/esm/components/AICommandBar/useAICommandBar.js.map +1 -1
  112. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js +19 -15
  113. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  114. package/dist/esm/components/AIElementWrapper/AIElementWrapper.types.d.ts +16 -0
  115. package/dist/esm/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
  116. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.d.ts +2 -0
  117. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js +13 -7
  118. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  119. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js +14 -8
  120. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  121. package/dist/esm/components/AIGenerationButton/AIGenerationButton.types.d.ts +16 -0
  122. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.d.ts +2 -0
  123. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js +12 -6
  124. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  125. package/dist/esm/components/ChatDrawer/ChatDrawer.js +29 -14
  126. package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
  127. package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +41 -0
  128. package/dist/esm/components/ChatDrawer/ChatInput.js +21 -15
  129. package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -1
  130. package/dist/esm/components/ChatDrawer/ChatMessages.d.ts +1 -1
  131. package/dist/esm/components/ChatDrawer/ChatMessages.js +54 -13
  132. package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -1
  133. package/dist/esm/components/ChatDrawer/CompactionWidget.js +13 -4
  134. package/dist/esm/components/ChatDrawer/CompactionWidget.js.map +1 -1
  135. package/dist/esm/components/ChatDrawer/ConversationSelector.js +6 -4
  136. package/dist/esm/components/ChatDrawer/ConversationSelector.js.map +1 -1
  137. package/dist/esm/components/ChatDrawer/ErrorBoundary.js.map +1 -1
  138. package/dist/esm/components/ChatDrawer/GuardrailNotice.d.ts +36 -0
  139. package/dist/esm/components/ChatDrawer/GuardrailNotice.js +38 -0
  140. package/dist/esm/components/ChatDrawer/GuardrailNotice.js.map +1 -0
  141. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js +3 -1
  142. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  143. package/dist/esm/components/ChatDrawer/LimitBanner.js +19 -9
  144. package/dist/esm/components/ChatDrawer/LimitBanner.js.map +1 -1
  145. package/dist/esm/components/ChatDrawer/QueueNotice.js +19 -7
  146. package/dist/esm/components/ChatDrawer/QueueNotice.js.map +1 -1
  147. package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js +17 -5
  148. package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
  149. package/dist/esm/components/ChatDrawer/ReferenceChip.js +3 -1
  150. package/dist/esm/components/ChatDrawer/ReferenceChip.js.map +1 -1
  151. package/dist/esm/components/ChatDrawer/ToolTimeline.js.map +1 -1
  152. package/dist/esm/components/ChatDrawer/UsageBar.js +23 -18
  153. package/dist/esm/components/ChatDrawer/UsageBar.js.map +1 -1
  154. package/dist/esm/components/ChatDrawer/index.d.ts +2 -0
  155. package/dist/esm/components/ChatDrawer/pastedText.js.map +1 -1
  156. package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js +20 -9
  157. package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
  158. package/dist/esm/components/Feedback/FeedbackModal.js +5 -1
  159. package/dist/esm/components/Feedback/FeedbackModal.js.map +1 -1
  160. package/dist/esm/components/Feedback/MessageActions.js +3 -1
  161. package/dist/esm/components/Feedback/MessageActions.js.map +1 -1
  162. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js +12 -8
  163. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
  164. package/dist/esm/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
  165. package/dist/esm/components/IntegrationsModal/IntegrationsHint.js +5 -3
  166. package/dist/esm/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
  167. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js +12 -3
  168. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
  169. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  170. package/dist/esm/components/IntegrationsModal/IntegrationsPanel.d.ts +1 -1
  171. package/dist/esm/components/IntegrationsModal/IntegrationsPanel.js +34 -24
  172. package/dist/esm/components/IntegrationsModal/IntegrationsPanel.js.map +1 -1
  173. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.d.ts +1 -1
  174. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js +15 -6
  175. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
  176. package/dist/esm/components/IntegrationsModal/McpConnectForm.js +15 -7
  177. package/dist/esm/components/IntegrationsModal/McpConnectForm.js.map +1 -1
  178. package/dist/esm/components/IntegrationsModal/McpServersSection.js +32 -19
  179. package/dist/esm/components/IntegrationsModal/McpServersSection.js.map +1 -1
  180. package/dist/esm/components/IntegrationsModal/integrationChoice.js.map +1 -1
  181. package/dist/esm/components/IntegrationsModal/useIntegrations.js +3 -1
  182. package/dist/esm/components/IntegrationsModal/useIntegrations.js.map +1 -1
  183. package/dist/esm/components/IntegrationsModal/useTenantMcp.js +3 -1
  184. package/dist/esm/components/IntegrationsModal/useTenantMcp.js.map +1 -1
  185. package/dist/esm/components/ThreadStateTag/ThreadStateTag.js +63 -40
  186. package/dist/esm/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
  187. package/dist/esm/components/theme.js.map +1 -1
  188. package/dist/esm/hooks/index.d.ts +1 -1
  189. package/dist/esm/hooks/useDevicChat.d.ts +6 -0
  190. package/dist/esm/hooks/useDevicChat.js +23 -9
  191. package/dist/esm/hooks/useDevicChat.js.map +1 -1
  192. package/dist/esm/hooks/useModelInterface.js.map +1 -1
  193. package/dist/esm/hooks/usePolling.d.ts +35 -0
  194. package/dist/esm/hooks/usePolling.js +114 -8
  195. package/dist/esm/hooks/usePolling.js.map +1 -1
  196. package/dist/esm/hooks/useSpeechRecording.js +8 -4
  197. package/dist/esm/hooks/useSpeechRecording.js.map +1 -1
  198. package/dist/esm/i18n/index.d.ts +4 -0
  199. package/dist/esm/i18n/translate.d.ts +23 -0
  200. package/dist/esm/i18n/translate.js +43 -0
  201. package/dist/esm/i18n/translate.js.map +1 -0
  202. package/dist/esm/i18n/types.d.ts +27 -0
  203. package/dist/esm/i18n/useTranslations.d.ts +32 -0
  204. package/dist/esm/i18n/useTranslations.js +53 -0
  205. package/dist/esm/i18n/useTranslations.js.map +1 -0
  206. package/dist/esm/index.d.ts +4 -2
  207. package/dist/esm/index.js +3 -0
  208. package/dist/esm/index.js.map +1 -1
  209. package/dist/esm/provider/DevicContext.js.map +1 -1
  210. package/dist/esm/provider/DevicProvider.d.ts +1 -1
  211. package/dist/esm/provider/DevicProvider.js +5 -1
  212. package/dist/esm/provider/DevicProvider.js.map +1 -1
  213. package/dist/esm/provider/sharedSession.js.map +1 -1
  214. package/dist/esm/provider/types.d.ts +51 -0
  215. package/dist/esm/styles.css +1 -1
  216. package/dist/esm/utils/avatar.js.map +1 -1
  217. package/dist/esm/utils/consumeChatStream.d.ts +6 -0
  218. package/dist/esm/utils/consumeChatStream.js +42 -0
  219. package/dist/esm/utils/consumeChatStream.js.map +1 -0
  220. package/dist/esm/utils/index.js.map +1 -1
  221. package/dist/esm/utils/logger.js.map +1 -1
  222. package/dist/esm/utils/toolGroups.js.map +1 -1
  223. package/package.json +3 -1
@@ -3,6 +3,7 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var React = require('react');
5
5
  var McpConnectForm = require('./McpConnectForm.js');
6
+ var useTranslations = require('../../i18n/useTranslations.js');
6
7
 
7
8
  /** A random value tying an OAuth round trip to the window that started it. */
8
9
  function newNonce() {
@@ -11,15 +12,16 @@ function newNonce() {
11
12
  return c.randomUUID();
12
13
  return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
13
14
  }
14
- function stateOf(server) {
15
+ function stateOf(t, server) {
15
16
  const status = server.connection?.status;
16
17
  if (status === "active")
17
- return { key: "connected", label: "Connected" };
18
- if (status === "error")
19
- return { key: "reconnect", label: "Needs attention" };
18
+ return { key: "connected", label: t("Connected") };
19
+ if (status === "error") {
20
+ return { key: "reconnect", label: t("Needs attention") };
21
+ }
20
22
  if (status === "pending_auth")
21
- return { key: "reconnect", label: "Waiting for sign-in" };
22
- return { key: "disconnected", label: "Not connected" };
23
+ return { key: "reconnect", label: t("Waiting for sign-in") };
24
+ return { key: "disconnected", label: t("Not connected") };
23
25
  }
24
26
  function matches(server, query) {
25
27
  const q = query.trim().toLowerCase();
@@ -48,6 +50,7 @@ function keyOf(server) {
48
50
  * cancelled consent screen posts nothing back, so the close is watched too.
49
51
  */
50
52
  function McpServersSection({ state, theme, query = "", }) {
53
+ const t = useTranslations.useTranslations();
51
54
  const { servers, allowCustom, limits, loading, client, scope, refresh } = state;
52
55
  const [actionError, setActionError] = React.useState(null);
53
56
  const [busyKey, setBusyKey] = React.useState(null);
@@ -143,7 +146,7 @@ function McpServersSection({ state, theme, query = "", }) {
143
146
  if (result.status === "error") {
144
147
  popup?.close();
145
148
  setBusyKey(null);
146
- setFormError(result.error ?? "The server could not be reached.");
149
+ setFormError(result.error ?? t("The server could not be reached."));
147
150
  return;
148
151
  }
149
152
  if (!result.authorizationUrl) {
@@ -199,32 +202,42 @@ function McpServersSection({ state, theme, query = "", }) {
199
202
  // over an empty box, which says less than saying nothing.
200
203
  if (!servers.length && !allowCustom)
201
204
  return null;
202
- return (jsxRuntime.jsxs("div", { className: "devic-int-mcp-section", children: [jsxRuntime.jsxs("div", { className: "devic-int-mcp-heading", children: [jsxRuntime.jsx("h4", { children: "MCP servers" }), jsxRuntime.jsx("span", { children: "Connect a server and its tools become available in this chat." })] }), actionError && jsxRuntime.jsx("div", { className: "devic-int-error", children: actionError }), blockedUrl && (jsxRuntime.jsxs("div", { className: "devic-int-notice", children: ["Your browser blocked the pop-up.", " ", jsxRuntime.jsx("a", { href: blockedUrl.url, target: "_blank", rel: "noopener noreferrer", onClick: () => {
205
+ return (jsxRuntime.jsxs("div", { className: "devic-int-mcp-section", children: [jsxRuntime.jsxs("div", { className: "devic-int-mcp-heading", children: [jsxRuntime.jsx("h4", { children: t("MCP servers") }), jsxRuntime.jsx("span", { children: t("Connect a server and its tools become available in this chat.") })] }), actionError && jsxRuntime.jsx("div", { className: "devic-int-error", children: actionError }), blockedUrl && (jsxRuntime.jsxs("div", { className: "devic-int-notice", children: [t("Your browser blocked the pop-up."), " ", jsxRuntime.jsx("a", { href: blockedUrl.url, target: "_blank", rel: "noopener noreferrer", onClick: () => {
203
206
  pendingRef.current = null;
204
207
  setBlockedUrl(null);
205
- }, children: "Open the authorisation page" }), " ", "and come back \u2014 then use Refresh."] })), visible.length > 0 && (jsxRuntime.jsx("div", { className: "devic-int-grid", children: visible.map((server) => {
206
- const cardState = stateOf(server);
208
+ }, children: t("Open the authorisation page") }), " ", t("and come back then use Refresh.")] })), visible.length > 0 && (jsxRuntime.jsx("div", { className: "devic-int-grid", children: visible.map((server) => {
209
+ const cardState = stateOf(t, server);
207
210
  const rowKey = keyOf(server);
208
211
  const busy = busyKey === rowKey;
209
212
  const connection = server.connection;
210
213
  return (jsxRuntime.jsxs("div", { className: "devic-int-card", "data-state": cardState.key, children: [jsxRuntime.jsxs("div", { className: "devic-int-card-head", children: [server.logoUrl ? (jsxRuntime.jsx("img", { className: "devic-int-mcp-logo", src: server.logoUrl, alt: "", "aria-hidden": "true" })) : (jsxRuntime.jsx("span", { className: "devic-int-mcp-logo devic-int-mcp-logo-fallback", children: server.name.slice(0, 1).toUpperCase() })), jsxRuntime.jsxs("span", { className: "devic-int-state", children: [jsxRuntime.jsx("span", { className: "devic-int-dot", "data-ok": cardState.key === "connected", "data-off": cardState.key === "disconnected", "aria-hidden": "true" }), cardState.label] })] }), jsxRuntime.jsx("div", { className: "devic-int-name", title: server.name, children: server.name }), jsxRuntime.jsx("div", { className: "devic-int-description", title: server.description ?? server.url, children: server.description ?? server.url }), connection?.shared && (
211
214
  // Worth saying before they wonder why they cannot remove it.
212
- jsxRuntime.jsx("div", { className: "devic-int-mcp-note", children: "Connected for everyone on this account" })), connection?.status === "active" &&
213
- typeof connection.toolCount === "number" && (jsxRuntime.jsxs("div", { className: "devic-int-mcp-note", children: [connection.toolCount, " tool", connection.toolCount === 1 ? "" : "s", " available"] })), connection?.lastProbeError && (jsxRuntime.jsx("div", { className: "devic-int-mcp-note devic-int-mcp-note-warn", title: connection.lastProbeError, children: connection.lastProbeError })), jsxRuntime.jsx("button", { type: "button", className: `devic-int-btn devic-int-btn-block${cardState.key === "connected" ? "" : " devic-int-btn-primary"}`, onClick: () => openPrompt(server), disabled: busy ||
215
+ jsxRuntime.jsx("div", { className: "devic-int-mcp-note", children: t("Connected for everyone on this account") })), connection?.status === "active" &&
216
+ typeof connection.toolCount === "number" && (jsxRuntime.jsx("div", { className: "devic-int-mcp-note", children: connection.toolCount === 1
217
+ ? t("1 tool available")
218
+ : t("{count} tools available", {
219
+ count: connection.toolCount,
220
+ }) })), connection?.lastProbeError && (jsxRuntime.jsx("div", { className: "devic-int-mcp-note devic-int-mcp-note-warn", title: connection.lastProbeError, children: connection.lastProbeError })), jsxRuntime.jsx("button", { type: "button", className: `devic-int-btn devic-int-btn-block${cardState.key === "connected" ? "" : " devic-int-btn-primary"}`, onClick: () => openPrompt(server), disabled: busy ||
214
221
  !!busyKey ||
215
222
  connection?.readOnly ||
216
223
  (!connection && atLimit), title: connection?.readOnly
217
- ? "This server was connected for the whole account."
224
+ ? t("This server was connected for the whole account.")
218
225
  : !connection && atLimit
219
- ? `You can have ${limits.maxServers} connected at a time.`
226
+ ? t("You can have {max} connected at a time.", {
227
+ max: limits.maxServers,
228
+ })
220
229
  : undefined, children: busy
221
- ? "Waiting…"
230
+ ? t("Waiting…")
222
231
  : cardState.key === "disconnected"
223
- ? "Connect"
224
- : "Reconnect" }), connection && !connection.readOnly && (jsxRuntime.jsx("button", { type: "button", className: "devic-int-btn devic-int-btn-block devic-int-mcp-remove", onClick: () => void disconnect(server), disabled: !!busyKey, children: "Disconnect" }))] }, rowKey));
232
+ ? t("Connect")
233
+ : t("Reconnect") }), connection && !connection.readOnly && (jsxRuntime.jsx("button", { type: "button", className: "devic-int-btn devic-int-btn-block devic-int-mcp-remove", onClick: () => void disconnect(server), disabled: !!busyKey, children: t("Disconnect") }))] }, rowKey));
225
234
  }) })), allowCustom && (jsxRuntime.jsx("button", { type: "button", className: "devic-int-btn devic-int-mcp-add", onClick: () => openPrompt(null), disabled: loading || !!busyKey || atLimit, title: atLimit
226
- ? `You can have ${limits.maxServers} MCP server${limits.maxServers === 1 ? "" : "s"} connected at a time.`
227
- : undefined, children: "+ Add your own MCP" })), prompt && (jsxRuntime.jsx(McpConnectForm.McpConnectForm, { server: prompt.server, callbackUrl: prompt.callbackUrl, needsClientCredentials: prompt.needsClientCredentials, submitting: busyKey === (prompt.server ? keyOf(prompt.server) : "new"), error: formError, theme: theme, onCancel: () => {
235
+ ? limits.maxServers === 1
236
+ ? t("You can have 1 MCP server connected at a time.")
237
+ : t("You can have {max} MCP servers connected at a time.", {
238
+ max: limits.maxServers,
239
+ })
240
+ : undefined, children: t("+ Add your own MCP") })), prompt && (jsxRuntime.jsx(McpConnectForm.McpConnectForm, { server: prompt.server, callbackUrl: prompt.callbackUrl, needsClientCredentials: prompt.needsClientCredentials, submitting: busyKey === (prompt.server ? keyOf(prompt.server) : "new"), error: formError, theme: theme, onCancel: () => {
228
241
  setPrompt(null);
229
242
  setFormError(null);
230
243
  }, onSubmit: submit }))] }));
@@ -1 +1 @@
1
- {"version":3,"file":"McpServersSection.js","sources":["../../../../../src/components/IntegrationsModal/McpServersSection.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, type JSX } from \"react\";\nimport type {\n TenantMcpAuthInput,\n TenantMcpConnectResult,\n TenantMcpServer,\n} from \"../../api/types\";\nimport type { DevicTheme } from \"../theme\";\nimport { McpConnectForm } from \"./McpConnectForm\";\nimport type { TenantMcpState } from \"./useTenantMcp\";\n\nexport interface McpServersSectionProps {\n state: TenantMcpState;\n theme?: DevicTheme;\n /** Filter typed in the modal's search box. */\n query?: string;\n}\n\n/** Message the OAuth callback page posts back when an MCP connection is done. */\ninterface McpCallbackMessage {\n source?: string;\n type?: string;\n status?: string;\n returnTo?: string;\n}\n\n/** A random value tying an OAuth round trip to the window that started it. */\nfunction newNonce(): string {\n const c = typeof crypto !== \"undefined\" ? crypto : undefined;\n if (c?.randomUUID) return c.randomUUID();\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\nfunction stateOf(server: TenantMcpServer): {\n key: \"connected\" | \"reconnect\" | \"disconnected\";\n label: string;\n} {\n const status = server.connection?.status;\n if (status === \"active\") return { key: \"connected\", label: \"Connected\" };\n if (status === \"error\") return { key: \"reconnect\", label: \"Needs attention\" };\n if (status === \"pending_auth\")\n return { key: \"reconnect\", label: \"Waiting for sign-in\" };\n return { key: \"disconnected\", label: \"Not connected\" };\n}\n\nfunction matches(server: TenantMcpServer, query: string): boolean {\n const q = query.trim().toLowerCase();\n if (!q) return true;\n return (\n server.name.toLowerCase().includes(q) ||\n server.url.toLowerCase().includes(q) ||\n (server.description ?? \"\").toLowerCase().includes(q)\n );\n}\n\n/** Identity of a row, stable whether or not it has been connected yet. */\nfunction keyOf(server: TenantMcpServer): string {\n return server.connection?.id ?? server.templateId ?? server.url;\n}\n\n/**\n * The MCP servers section of the connected-apps panel.\n *\n * The end user sees one list: the servers their developer left ready to\n * connect, the ones they added themselves, and — unless it was switched off —\n * a button to add another. Both routes open the same form, because the only\n * difference between them is who typed the url.\n *\n * Connecting opens a consent screen in a popup. The popup is opened empty\n * *before* the request that produces its URL, because browsers only honour\n * `window.open` inside the gesture that triggered it; opening it after the\n * round trip is what gets it blocked. Two endings are watched, not one — a\n * cancelled consent screen posts nothing back, so the close is watched too.\n */\nexport function McpServersSection({\n state,\n theme,\n query = \"\",\n}: McpServersSectionProps): JSX.Element | null {\n const { servers, allowCustom, limits, loading, client, scope, refresh } = state;\n\n const [actionError, setActionError] = useState<string | null>(null);\n const [busyKey, setBusyKey] = useState<string | null>(null);\n const [blockedUrl, setBlockedUrl] = useState<{ url: string } | null>(null);\n /** The row whose form is open. `null` inside the object is \"add your own\". */\n const [prompt, setPrompt] = useState<{\n server: TenantMcpServer | null;\n callbackUrl?: string;\n needsClientCredentials?: boolean;\n } | null>(null);\n const [formError, setFormError] = useState<string | null>(null);\n\n const pendingRef = useRef<{ returnTo: string } | null>(null);\n const popupRef = useRef<Window | null>(null);\n const pollRef = useRef<number | null>(null);\n\n const finish = useCallback(() => {\n if (pollRef.current !== null) {\n window.clearInterval(pollRef.current);\n pollRef.current = null;\n }\n pendingRef.current = null;\n popupRef.current = null;\n setBusyKey(null);\n void refresh();\n }, [refresh]);\n\n // The callback page says it is done. A nudge, never the result: what is shown\n // comes from re-reading the server, so a forged message costs one extra fetch\n // and nothing else.\n useEffect(() => {\n const onMessage = (event: MessageEvent) => {\n const data = event.data as McpCallbackMessage | undefined;\n if (!data || data.source !== \"devic\") return;\n if (data.type !== \"mcp-connected\") return;\n const pending = pendingRef.current;\n if (!pending || data.returnTo !== pending.returnTo) return;\n popupRef.current?.close();\n finish();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n }, [finish]);\n\n useEffect(\n () => () => {\n if (pollRef.current !== null) window.clearInterval(pollRef.current);\n },\n []\n );\n\n const openPrompt = (server: TenantMcpServer | null) => {\n setFormError(null);\n setActionError(null);\n setBlockedUrl(null);\n setPrompt({ server });\n };\n\n const submit = async (values: {\n url?: string;\n name?: string;\n auth: TenantMcpAuthInput;\n }) => {\n if (!client || !prompt) return;\n const server = prompt.server;\n const rowKey = server ? keyOf(server) : \"new\";\n setBusyKey(rowKey);\n setFormError(null);\n\n const nonce = newNonce();\n const returnTo = `${window.location.origin}/?devic_mcp=${nonce}`;\n // Opened empty inside the submit gesture and navigated once the URL is\n // known. Skipped when no browser is involved at all.\n const popup =\n values.auth.mode === \"oauth\"\n ? window.open(\n \"\",\n \"devic-mcp-oauth\",\n \"width=520,height=680,menubar=no,toolbar=no\"\n )\n : null;\n\n try {\n const existing = server?.connection;\n const result: TenantMcpConnectResult = existing\n ? await client.reconnectMcpServer(existing.id, {\n ...scope,\n returnTo,\n auth: values.auth,\n })\n : await client.connectMcpServer({\n ...scope,\n returnTo,\n templateId: server?.templateId,\n url: values.url,\n name: values.name,\n auth: values.auth,\n });\n\n if (result.requiresClientCredentials) {\n // Not a failure the user can do nothing about: they own the server, so\n // the form reopens with the fields and the redirect URI to authorise.\n popup?.close();\n setBusyKey(null);\n setPrompt({\n server,\n callbackUrl: result.callbackUrl,\n needsClientCredentials: true,\n });\n setFormError(result.error ?? null);\n return;\n }\n\n if (result.status === \"error\") {\n popup?.close();\n setBusyKey(null);\n setFormError(result.error ?? \"The server could not be reached.\");\n return;\n }\n\n if (!result.authorizationUrl) {\n // Connected outright: the key the user typed is the credential.\n popup?.close();\n setPrompt(null);\n finish();\n return;\n }\n\n pendingRef.current = { returnTo };\n setPrompt(null);\n if (popup && !popup.closed) {\n popupRef.current = popup;\n popup.location.href = result.authorizationUrl;\n pollRef.current = window.setInterval(() => {\n if (popup.closed) finish();\n }, 700);\n } else {\n // Blocked (Safari, in-app browsers, extensions): hand over the URL.\n setBlockedUrl({ url: result.authorizationUrl });\n setBusyKey(null);\n }\n } catch (err) {\n popup?.close();\n pendingRef.current = null;\n setBusyKey(null);\n setFormError(err instanceof Error ? err.message : String(err));\n }\n };\n\n const disconnect = async (server: TenantMcpServer) => {\n const connection = server.connection;\n if (!client || !connection || busyKey) return;\n setBusyKey(keyOf(server));\n setActionError(null);\n try {\n await client.disconnectMcpServer(connection.id, scope);\n await refresh();\n } catch (err) {\n setActionError(err instanceof Error ? err.message : String(err));\n } finally {\n setBusyKey(null);\n }\n };\n\n const visible = servers.filter((s) => matches(s, query));\n const atLimit = limits.used >= limits.maxServers;\n\n // Nothing offered and nothing addable: the whole section would be a heading\n // over an empty box, which says less than saying nothing.\n if (!servers.length && !allowCustom) return null;\n\n return (\n <div className=\"devic-int-mcp-section\">\n <div className=\"devic-int-mcp-heading\">\n <h4>MCP servers</h4>\n <span>Connect a server and its tools become available in this chat.</span>\n </div>\n\n {actionError && <div className=\"devic-int-error\">{actionError}</div>}\n\n {blockedUrl && (\n <div className=\"devic-int-notice\">\n Your browser blocked the pop-up.{\" \"}\n <a\n href={blockedUrl.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={() => {\n pendingRef.current = null;\n setBlockedUrl(null);\n }}\n >\n Open the authorisation page\n </a>{\" \"}\n and come back — then use Refresh.\n </div>\n )}\n\n {visible.length > 0 && (\n <div className=\"devic-int-grid\">\n {visible.map((server) => {\n const cardState = stateOf(server);\n const rowKey = keyOf(server);\n const busy = busyKey === rowKey;\n const connection = server.connection;\n return (\n <div\n key={rowKey}\n className=\"devic-int-card\"\n data-state={cardState.key}\n >\n <div className=\"devic-int-card-head\">\n {server.logoUrl ? (\n <img\n className=\"devic-int-mcp-logo\"\n src={server.logoUrl}\n alt=\"\"\n aria-hidden=\"true\"\n />\n ) : (\n <span className=\"devic-int-mcp-logo devic-int-mcp-logo-fallback\">\n {server.name.slice(0, 1).toUpperCase()}\n </span>\n )}\n <span className=\"devic-int-state\">\n <span\n className=\"devic-int-dot\"\n data-ok={cardState.key === \"connected\"}\n data-off={cardState.key === \"disconnected\"}\n aria-hidden=\"true\"\n />\n {cardState.label}\n </span>\n </div>\n\n <div className=\"devic-int-name\" title={server.name}>\n {server.name}\n </div>\n\n <div\n className=\"devic-int-description\"\n title={server.description ?? server.url}\n >\n {server.description ?? server.url}\n </div>\n\n {connection?.shared && (\n // Worth saying before they wonder why they cannot remove it.\n <div className=\"devic-int-mcp-note\">\n Connected for everyone on this account\n </div>\n )}\n\n {connection?.status === \"active\" &&\n typeof connection.toolCount === \"number\" && (\n <div className=\"devic-int-mcp-note\">\n {connection.toolCount} tool\n {connection.toolCount === 1 ? \"\" : \"s\"} available\n </div>\n )}\n\n {connection?.lastProbeError && (\n <div\n className=\"devic-int-mcp-note devic-int-mcp-note-warn\"\n title={connection.lastProbeError}\n >\n {connection.lastProbeError}\n </div>\n )}\n\n <button\n type=\"button\"\n className={`devic-int-btn devic-int-btn-block${\n cardState.key === \"connected\" ? \"\" : \" devic-int-btn-primary\"\n }`}\n onClick={() => openPrompt(server)}\n disabled={\n busy ||\n !!busyKey ||\n connection?.readOnly ||\n (!connection && atLimit)\n }\n title={\n connection?.readOnly\n ? \"This server was connected for the whole account.\"\n : !connection && atLimit\n ? `You can have ${limits.maxServers} connected at a time.`\n : undefined\n }\n >\n {busy\n ? \"Waiting…\"\n : cardState.key === \"disconnected\"\n ? \"Connect\"\n : \"Reconnect\"}\n </button>\n\n {connection && !connection.readOnly && (\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-block devic-int-mcp-remove\"\n onClick={() => void disconnect(server)}\n disabled={!!busyKey}\n >\n Disconnect\n </button>\n )}\n </div>\n );\n })}\n </div>\n )}\n\n {allowCustom && (\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-mcp-add\"\n onClick={() => openPrompt(null)}\n disabled={loading || !!busyKey || atLimit}\n title={\n atLimit\n ? `You can have ${limits.maxServers} MCP server${\n limits.maxServers === 1 ? \"\" : \"s\"\n } connected at a time.`\n : undefined\n }\n >\n + Add your own MCP\n </button>\n )}\n\n {prompt && (\n <McpConnectForm\n server={prompt.server}\n callbackUrl={prompt.callbackUrl}\n needsClientCredentials={prompt.needsClientCredentials}\n submitting={\n busyKey === (prompt.server ? keyOf(prompt.server) : \"new\")\n }\n error={formError}\n theme={theme}\n onCancel={() => {\n setPrompt(null);\n setFormError(null);\n }}\n onSubmit={submit}\n />\n )}\n </div>\n );\n}\n\nexport default McpServersSection;\n"],"names":["useState","useRef","useCallback","useEffect","_jsxs","_jsx","McpConnectForm"],"mappings":";;;;;;AAyBA;AACA,SAAS,QAAQ,GAAA;AACf,IAAA,MAAM,CAAC,GA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EAAA,QAAA,EAAA,oBAAA,EAAA,CAIR,CACV,EAEA,MAAM,KACLA,cAAA,CAACC,6BAAc,EAAA,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,EACrD,UAAU,EACR,OAAO,MAAM,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,EAE5D,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAK;oBACb,SAAS,CAAC,IAAI,CAAC;oBACf,YAAY,CAAC,IAAI,CAAC;gBACpB,CAAC,EACD,QAAQ,EAAE,MAAM,GAChB,CACH,CAAA,EAAA,CACG;AAEV;;"}
1
+ {"version":3,"file":"McpServersSection.js","sources":["../../../../../src/components/IntegrationsModal/McpServersSection.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, type JSX } from \"react\";\nimport type {\n TenantMcpAuthInput,\n TenantMcpConnectResult,\n TenantMcpServer,\n} from \"../../api/types\";\nimport type { DevicTheme } from \"../theme\";\nimport { McpConnectForm } from \"./McpConnectForm\";\nimport type { TenantMcpState } from \"./useTenantMcp\";\nimport { useTranslations, type Translator } from \"../../i18n\";\n\nexport interface McpServersSectionProps {\n state: TenantMcpState;\n theme?: DevicTheme;\n /** Filter typed in the modal's search box. */\n query?: string;\n}\n\n/** Message the OAuth callback page posts back when an MCP connection is done. */\ninterface McpCallbackMessage {\n source?: string;\n type?: string;\n status?: string;\n returnTo?: string;\n}\n\n/** A random value tying an OAuth round trip to the window that started it. */\nfunction newNonce(): string {\n const c = typeof crypto !== \"undefined\" ? crypto : undefined;\n if (c?.randomUUID) return c.randomUUID();\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\nfunction stateOf(\n t: Translator,\n server: TenantMcpServer\n): {\n key: \"connected\" | \"reconnect\" | \"disconnected\";\n label: string;\n} {\n const status = server.connection?.status;\n if (status === \"active\") return { key: \"connected\", label: t(\"Connected\") };\n if (status === \"error\") {\n return { key: \"reconnect\", label: t(\"Needs attention\") };\n }\n if (status === \"pending_auth\")\n return { key: \"reconnect\", label: t(\"Waiting for sign-in\") };\n return { key: \"disconnected\", label: t(\"Not connected\") };\n}\n\nfunction matches(server: TenantMcpServer, query: string): boolean {\n const q = query.trim().toLowerCase();\n if (!q) return true;\n return (\n server.name.toLowerCase().includes(q) ||\n server.url.toLowerCase().includes(q) ||\n (server.description ?? \"\").toLowerCase().includes(q)\n );\n}\n\n/** Identity of a row, stable whether or not it has been connected yet. */\nfunction keyOf(server: TenantMcpServer): string {\n return server.connection?.id ?? server.templateId ?? server.url;\n}\n\n/**\n * The MCP servers section of the connected-apps panel.\n *\n * The end user sees one list: the servers their developer left ready to\n * connect, the ones they added themselves, and — unless it was switched off —\n * a button to add another. Both routes open the same form, because the only\n * difference between them is who typed the url.\n *\n * Connecting opens a consent screen in a popup. The popup is opened empty\n * *before* the request that produces its URL, because browsers only honour\n * `window.open` inside the gesture that triggered it; opening it after the\n * round trip is what gets it blocked. Two endings are watched, not one — a\n * cancelled consent screen posts nothing back, so the close is watched too.\n */\nexport function McpServersSection({\n state,\n theme,\n query = \"\",\n}: McpServersSectionProps): JSX.Element | null {\n const t = useTranslations();\n const { servers, allowCustom, limits, loading, client, scope, refresh } = state;\n\n const [actionError, setActionError] = useState<string | null>(null);\n const [busyKey, setBusyKey] = useState<string | null>(null);\n const [blockedUrl, setBlockedUrl] = useState<{ url: string } | null>(null);\n /** The row whose form is open. `null` inside the object is \"add your own\". */\n const [prompt, setPrompt] = useState<{\n server: TenantMcpServer | null;\n callbackUrl?: string;\n needsClientCredentials?: boolean;\n } | null>(null);\n const [formError, setFormError] = useState<string | null>(null);\n\n const pendingRef = useRef<{ returnTo: string } | null>(null);\n const popupRef = useRef<Window | null>(null);\n const pollRef = useRef<number | null>(null);\n\n const finish = useCallback(() => {\n if (pollRef.current !== null) {\n window.clearInterval(pollRef.current);\n pollRef.current = null;\n }\n pendingRef.current = null;\n popupRef.current = null;\n setBusyKey(null);\n void refresh();\n }, [refresh]);\n\n // The callback page says it is done. A nudge, never the result: what is shown\n // comes from re-reading the server, so a forged message costs one extra fetch\n // and nothing else.\n useEffect(() => {\n const onMessage = (event: MessageEvent) => {\n const data = event.data as McpCallbackMessage | undefined;\n if (!data || data.source !== \"devic\") return;\n if (data.type !== \"mcp-connected\") return;\n const pending = pendingRef.current;\n if (!pending || data.returnTo !== pending.returnTo) return;\n popupRef.current?.close();\n finish();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n }, [finish]);\n\n useEffect(\n () => () => {\n if (pollRef.current !== null) window.clearInterval(pollRef.current);\n },\n []\n );\n\n const openPrompt = (server: TenantMcpServer | null) => {\n setFormError(null);\n setActionError(null);\n setBlockedUrl(null);\n setPrompt({ server });\n };\n\n const submit = async (values: {\n url?: string;\n name?: string;\n auth: TenantMcpAuthInput;\n }) => {\n if (!client || !prompt) return;\n const server = prompt.server;\n const rowKey = server ? keyOf(server) : \"new\";\n setBusyKey(rowKey);\n setFormError(null);\n\n const nonce = newNonce();\n const returnTo = `${window.location.origin}/?devic_mcp=${nonce}`;\n // Opened empty inside the submit gesture and navigated once the URL is\n // known. Skipped when no browser is involved at all.\n const popup =\n values.auth.mode === \"oauth\"\n ? window.open(\n \"\",\n \"devic-mcp-oauth\",\n \"width=520,height=680,menubar=no,toolbar=no\"\n )\n : null;\n\n try {\n const existing = server?.connection;\n const result: TenantMcpConnectResult = existing\n ? await client.reconnectMcpServer(existing.id, {\n ...scope,\n returnTo,\n auth: values.auth,\n })\n : await client.connectMcpServer({\n ...scope,\n returnTo,\n templateId: server?.templateId,\n url: values.url,\n name: values.name,\n auth: values.auth,\n });\n\n if (result.requiresClientCredentials) {\n // Not a failure the user can do nothing about: they own the server, so\n // the form reopens with the fields and the redirect URI to authorise.\n popup?.close();\n setBusyKey(null);\n setPrompt({\n server,\n callbackUrl: result.callbackUrl,\n needsClientCredentials: true,\n });\n setFormError(result.error ?? null);\n return;\n }\n\n if (result.status === \"error\") {\n popup?.close();\n setBusyKey(null);\n setFormError(result.error ?? t(\"The server could not be reached.\"));\n return;\n }\n\n if (!result.authorizationUrl) {\n // Connected outright: the key the user typed is the credential.\n popup?.close();\n setPrompt(null);\n finish();\n return;\n }\n\n pendingRef.current = { returnTo };\n setPrompt(null);\n if (popup && !popup.closed) {\n popupRef.current = popup;\n popup.location.href = result.authorizationUrl;\n pollRef.current = window.setInterval(() => {\n if (popup.closed) finish();\n }, 700);\n } else {\n // Blocked (Safari, in-app browsers, extensions): hand over the URL.\n setBlockedUrl({ url: result.authorizationUrl });\n setBusyKey(null);\n }\n } catch (err) {\n popup?.close();\n pendingRef.current = null;\n setBusyKey(null);\n setFormError(err instanceof Error ? err.message : String(err));\n }\n };\n\n const disconnect = async (server: TenantMcpServer) => {\n const connection = server.connection;\n if (!client || !connection || busyKey) return;\n setBusyKey(keyOf(server));\n setActionError(null);\n try {\n await client.disconnectMcpServer(connection.id, scope);\n await refresh();\n } catch (err) {\n setActionError(err instanceof Error ? err.message : String(err));\n } finally {\n setBusyKey(null);\n }\n };\n\n const visible = servers.filter((s) => matches(s, query));\n const atLimit = limits.used >= limits.maxServers;\n\n // Nothing offered and nothing addable: the whole section would be a heading\n // over an empty box, which says less than saying nothing.\n if (!servers.length && !allowCustom) return null;\n\n return (\n <div className=\"devic-int-mcp-section\">\n <div className=\"devic-int-mcp-heading\">\n <h4>{t(\"MCP servers\")}</h4>\n <span>\n {t(\"Connect a server and its tools become available in this chat.\")}\n </span>\n </div>\n\n {actionError && <div className=\"devic-int-error\">{actionError}</div>}\n\n {blockedUrl && (\n <div className=\"devic-int-notice\">\n {t(\"Your browser blocked the pop-up.\")}{\" \"}\n <a\n href={blockedUrl.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={() => {\n pendingRef.current = null;\n setBlockedUrl(null);\n }}\n >\n {t(\"Open the authorisation page\")}\n </a>{\" \"}\n {t(\"and come back — then use Refresh.\")}\n </div>\n )}\n\n {visible.length > 0 && (\n <div className=\"devic-int-grid\">\n {visible.map((server) => {\n const cardState = stateOf(t, server);\n const rowKey = keyOf(server);\n const busy = busyKey === rowKey;\n const connection = server.connection;\n return (\n <div\n key={rowKey}\n className=\"devic-int-card\"\n data-state={cardState.key}\n >\n <div className=\"devic-int-card-head\">\n {server.logoUrl ? (\n <img\n className=\"devic-int-mcp-logo\"\n src={server.logoUrl}\n alt=\"\"\n aria-hidden=\"true\"\n />\n ) : (\n <span className=\"devic-int-mcp-logo devic-int-mcp-logo-fallback\">\n {server.name.slice(0, 1).toUpperCase()}\n </span>\n )}\n <span className=\"devic-int-state\">\n <span\n className=\"devic-int-dot\"\n data-ok={cardState.key === \"connected\"}\n data-off={cardState.key === \"disconnected\"}\n aria-hidden=\"true\"\n />\n {cardState.label}\n </span>\n </div>\n\n <div className=\"devic-int-name\" title={server.name}>\n {server.name}\n </div>\n\n <div\n className=\"devic-int-description\"\n title={server.description ?? server.url}\n >\n {server.description ?? server.url}\n </div>\n\n {connection?.shared && (\n // Worth saying before they wonder why they cannot remove it.\n <div className=\"devic-int-mcp-note\">\n {t(\"Connected for everyone on this account\")}\n </div>\n )}\n\n {connection?.status === \"active\" &&\n typeof connection.toolCount === \"number\" && (\n <div className=\"devic-int-mcp-note\">\n {connection.toolCount === 1\n ? t(\"1 tool available\")\n : t(\"{count} tools available\", {\n count: connection.toolCount,\n })}\n </div>\n )}\n\n {connection?.lastProbeError && (\n <div\n className=\"devic-int-mcp-note devic-int-mcp-note-warn\"\n title={connection.lastProbeError}\n >\n {connection.lastProbeError}\n </div>\n )}\n\n <button\n type=\"button\"\n className={`devic-int-btn devic-int-btn-block${\n cardState.key === \"connected\" ? \"\" : \" devic-int-btn-primary\"\n }`}\n onClick={() => openPrompt(server)}\n disabled={\n busy ||\n !!busyKey ||\n connection?.readOnly ||\n (!connection && atLimit)\n }\n title={\n connection?.readOnly\n ? t(\"This server was connected for the whole account.\")\n : !connection && atLimit\n ? t(\"You can have {max} connected at a time.\", {\n max: limits.maxServers,\n })\n : undefined\n }\n >\n {busy\n ? t(\"Waiting…\")\n : cardState.key === \"disconnected\"\n ? t(\"Connect\")\n : t(\"Reconnect\")}\n </button>\n\n {connection && !connection.readOnly && (\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-block devic-int-mcp-remove\"\n onClick={() => void disconnect(server)}\n disabled={!!busyKey}\n >\n {t(\"Disconnect\")}\n </button>\n )}\n </div>\n );\n })}\n </div>\n )}\n\n {allowCustom && (\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-mcp-add\"\n onClick={() => openPrompt(null)}\n disabled={loading || !!busyKey || atLimit}\n title={\n atLimit\n ? limits.maxServers === 1\n ? t(\"You can have 1 MCP server connected at a time.\")\n : t(\"You can have {max} MCP servers connected at a time.\", {\n max: limits.maxServers,\n })\n : undefined\n }\n >\n {t(\"+ Add your own MCP\")}\n </button>\n )}\n\n {prompt && (\n <McpConnectForm\n server={prompt.server}\n callbackUrl={prompt.callbackUrl}\n needsClientCredentials={prompt.needsClientCredentials}\n submitting={\n busyKey === (prompt.server ? keyOf(prompt.server) : \"new\")\n }\n error={formError}\n theme={theme}\n onCancel={() => {\n setPrompt(null);\n setFormError(null);\n }}\n onSubmit={submit}\n />\n )}\n </div>\n );\n}\n\nexport default McpServersSection;\n"],"names":["useTranslations","useState","useRef","useCallback","useEffect","_jsxs","_jsx","McpConnectForm"],"mappings":";;;;;;;AA0BA;AACA,SAAS,QAAQ,GAAA;AACf,IAAA,MAAM,CAAC,GAAG,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,GAAG,SAAS;IAC5D,IAAI,CAAC,EAAE,UAAU;AAAE,QAAA,OAAO,CAAC,CAAC,UAAU,EAAE;IACxC,OAAO,CAAA,EAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE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A,WAAW,KACVA,cAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,iCAAiC,EAC3C,OAAO,EAAE,MAAM,UAAU,CAAC,IAAI,CAAC,EAC/B,QAAQ,EAAE,OAAO,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,EACzC,KAAK,EACH;AACE,sBAAE,MAAM,CAAC,UAAU,KAAK;AACtB,0BAAE,CAAC,CAAC,gDAAgD;AACpD,0BAAE,CAAC,CAAC,qDAAqD,EAAE;4BACvD,GAAG,EAAE,MAAM,CAAC,UAAU;yBACvB;AACL,sBAAE,SAAS,EAAA,QAAA,EAGd,CAAC,CAAC,oBAAoB,CAAC,EAAA,CACjB,CACV,EAEA,MAAM,KACLA,eAACC,6BAAc,EAAA,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,EACrD,UAAU,EACR,OAAO,MAAM,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,EAE5D,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAK;oBACb,SAAS,CAAC,IAAI,CAAC;oBACf,YAAY,CAAC,IAAI,CAAC;gBACpB,CAAC,EACD,QAAQ,EAAE,MAAM,GAChB,CACH,CAAA,EAAA,CACG;AAEV;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"integrationChoice.js","sources":["../../../../../src/components/IntegrationsModal/integrationChoice.ts"],"sourcesContent":["import { storage } from \"../../utils\";\n\n/**\n * What the end user switched off, remembered between visits.\n *\n * Held in the browser and nowhere else: it is a preference of whoever is at\n * this keyboard, not of the tenant, and the server deliberately keeps nothing\n * beyond the turn it was sent for.\n *\n * The key names the assistant AND the tenant it was made under, because a\n * choice about one end user's Gmail means nothing to the next one — and a\n * widget that switched an app off for a colleague who happens to share a\n * browser profile would be a bug with a very long tail.\n */\nconst PREFIX = \"devic:integrations:off\";\n\nexport function integrationChoiceKey(\n assistantId: string,\n tenantId?: string,\n subtenantId?: string\n): string {\n return `${PREFIX}:${assistantId}:${tenantId ?? \"\"}:${subtenantId ?? \"\"}`;\n}\n\n/** Reads the remembered list, tolerating anything that is not one. */\nexport function readIntegrationChoice(key: string): string[] {\n const stored = storage.get<unknown>(key);\n if (!Array.isArray(stored)) return [];\n return stored.filter((id): id is string => typeof id === \"string\" && !!id);\n}\n\nexport function writeIntegrationChoice(key: string, disabled: string[]): void {\n // An empty list is the default, and leaving a `[]` behind in every visitor's\n // storage for every assistant they ever opened is litter.\n if (disabled.length === 0) storage.remove(key);\n else storage.set(key, disabled);\n}\n\n/**\n * Drops what is no longer on offer.\n *\n * Without this, remembering the choice would quietly reintroduce the bug the\n * switch was written to avoid: disconnect an app, connect it again months\n * later, and find it switched off for reasons nobody can reconstruct. The same\n * goes for an MCP server the tenant removed.\n *\n * Returns the SAME array when nothing was stale, so a caller can use identity\n * to avoid a pointless render.\n */\nexport function pruneIntegrationChoice(\n disabled: string[],\n liveIds: string[]\n): string[] {\n if (disabled.length === 0) return disabled;\n const live = new Set(liveIds);\n const next = disabled.filter((id) => live.has(id));\n return next.length === disabled.length ? disabled : next;\n}\n"],"names":["storage"],"mappings":";;;;AAEA;;;;;;;;;;;AAWG;AACH,MAAM,MAAM,GAAG,wBAAwB;SAEvB,oBAAoB,CAClC,WAAmB,EACnB,QAAiB,EACjB,WAAoB,EAAA;AAEpB,IAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,WAAW,CAAA,CAAA,EAAI,QAAQ,IAAI,EAAE,CAAA,CAAA,EAAI,WAAW,IAAI,EAAE,EAAE;AAC1E;AAEA;AACM,SAAU,qBAAqB,CAAC,GAAW,EAAA;IAC/C,MAAM,MAAM,GAAGA,aAAO,CAAC,GAAG,CAAU,GAAG,CAAC;AACxC,IAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AAAE,QAAA,OAAO,EAAE;AACrC,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAmB,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;AAC5E;AAEM,SAAU,sBAAsB,CAAC,GAAW,EAAE,QAAkB,EAAA;;;AAGpE,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAAA,aAAO,CAAC,MAAM,CAAC,GAAG,CAAC;;AACzC,QAAAA,aAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC;AACjC;AAEA;;;;;;;;;;AAUG;AACG,SAAU,sBAAsB,CACpC,QAAkB,EAClB,OAAiB,EAAA;AAEjB,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,QAAQ;AAC1C,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;AAC7B,IAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClD,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,GAAG,QAAQ,GAAG,IAAI;AAC1D;;;;;"}
1
+ {"version":3,"file":"integrationChoice.js","sources":["../../../../../src/components/IntegrationsModal/integrationChoice.ts"],"sourcesContent":["import { storage } from \"../../utils\";\n\n/**\n * What the end user switched off, remembered between visits.\n *\n * Held in the browser and nowhere else: it is a preference of whoever is at\n * this keyboard, not of the tenant, and the server deliberately keeps nothing\n * beyond the turn it was sent for.\n *\n * The key names the assistant AND the tenant it was made under, because a\n * choice about one end user's Gmail means nothing to the next one — and a\n * widget that switched an app off for a colleague who happens to share a\n * browser profile would be a bug with a very long tail.\n */\nconst PREFIX = \"devic:integrations:off\";\n\nexport function integrationChoiceKey(\n assistantId: string,\n tenantId?: string,\n subtenantId?: string\n): string {\n return `${PREFIX}:${assistantId}:${tenantId ?? \"\"}:${subtenantId ?? \"\"}`;\n}\n\n/** Reads the remembered list, tolerating anything that is not one. */\nexport function readIntegrationChoice(key: string): string[] {\n const stored = storage.get<unknown>(key);\n if (!Array.isArray(stored)) return [];\n return stored.filter((id): id is string => typeof id === \"string\" && !!id);\n}\n\nexport function writeIntegrationChoice(key: string, disabled: string[]): void {\n // An empty list is the default, and leaving a `[]` behind in every visitor's\n // storage for every assistant they ever opened is litter.\n if (disabled.length === 0) storage.remove(key);\n else storage.set(key, disabled);\n}\n\n/**\n * Drops what is no longer on offer.\n *\n * Without this, remembering the choice would quietly reintroduce the bug the\n * switch was written to avoid: disconnect an app, connect it again months\n * later, and find it switched off for reasons nobody can reconstruct. The same\n * goes for an MCP server the tenant removed.\n *\n * Returns the SAME array when nothing was stale, so a caller can use identity\n * to avoid a pointless render.\n */\nexport function pruneIntegrationChoice(\n disabled: string[],\n liveIds: string[]\n): string[] {\n if (disabled.length === 0) return disabled;\n const live = new Set(liveIds);\n const next = disabled.filter((id) => live.has(id));\n return next.length === disabled.length ? disabled : next;\n}\n"],"names":["storage"],"mappings":";;;;AAEA;;;;;;;;;;;AAWG;AACH,MAAM,MAAM,GAAG,wBAAwB;SAEvB,oBAAoB,CAClC,WAAmB,EACnB,QAAiB,EACjB,WAAoB,EAAA;AAEpB,IAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,WAAW,CAAA,CAAA,EAAI,QAAQ,IAAI,EAAE,CAAA,CAAA,EAAI,WAAW,IAAI,EAAE,EAAE;AAC1E;AAEA;AACM,SAAU,qBAAqB,CAAC,GAAW,EAAA;IAC/C,MAAM,MAAM,GAAGA,aAAO,CAAC,GAAG,CAAU,GAAG,CAAC;AACxC,IAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AAAE,QAAA,OAAO,EAAE;AACrC,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAmB,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;AAC5E;AAEM,SAAU,sBAAsB,CAAC,GAAW,EAAE,QAAkB,EAAA;;;AAGpE,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAAA,aAAO,CAAC,MAAM,CAAC,GAAG,CAAC;;AACzC,QAAAA,aAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC;AACjC;AAEA;;;;;;;;;;AAUG;AACG,SAAU,sBAAsB,CACpC,QAAkB,EAClB,OAAiB,EAAA;AAEjB,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,QAAQ;AAC1C,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;AAC7B,IAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClD,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,GAAG,QAAQ,GAAG,IAAI;AAC1D;;;;;;;"}
@@ -4,6 +4,7 @@ var React = require('react');
4
4
  var client = require('../../api/client.js');
5
5
  require('react/jsx-runtime');
6
6
  var DevicContext = require('../../provider/DevicContext.js');
7
+ var useTranslations = require('../../i18n/useTranslations.js');
7
8
 
8
9
  /** A 4xx here means "not for you", not "something broke". */
9
10
  function isRefusal(err) {
@@ -21,6 +22,7 @@ function isRefusal(err) {
21
22
  */
22
23
  function useIntegrations(options) {
23
24
  const { assistantId, tenantId, subtenantId, apiKey, baseUrl, enabled = true, } = options;
25
+ const t = useTranslations.useTranslations();
24
26
  const context = DevicContext.useOptionalDevicContext();
25
27
  const resolvedBaseUrl = baseUrl || context?.baseUrl || "https://api.devic.ai";
26
28
  const resolvedTenantId = tenantId || context?.tenantId;
@@ -48,7 +50,7 @@ function useIntegrations(options) {
48
50
  const [settled, setSettled] = React.useState(false);
49
51
  const refresh = React.useCallback(async (dropCache = false) => {
50
52
  if (!client$1) {
51
- setError("No credentials configured");
53
+ setError(t("No credentials configured"));
52
54
  setSettled(true);
53
55
  return;
54
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useIntegrations.js","sources":["../../../../../src/components/IntegrationsModal/useIntegrations.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { DevicApiError } from \"../../api/client\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { Integration } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\n\n/** What identifies the end user in front of the widget. */\nexport interface IntegrationsScope {\n assistantId: string;\n tenantId?: string;\n subtenantId?: string;\n}\n\nexport interface UseIntegrationsOptions extends IntegrationsScope {\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /**\n * Fetch when this turns true, and only then. The launcher passes the drawer's\n * open state so a widget nobody opens costs no request at all.\n */\n enabled?: boolean;\n}\n\nexport interface IntegrationsState {\n integrations: Integration[];\n loading: boolean;\n error: string | null;\n /**\n * Whether this assistant offers connected apps to its tenants at all.\n *\n * False before the first answer arrives, and false again if the server said\n * no — which it does for a disabled catalogue, a missing tenant, and an\n * assistant that does not exist, deliberately without distinguishing them.\n * Anything that hangs off this flag stays hidden until the server has said\n * yes, so nothing ever appears and then disappears.\n */\n offered: boolean;\n /** True once a first answer (or refusal) has arrived. */\n settled: boolean;\n refresh: (dropCache?: boolean) => Promise<void>;\n client: DevicApiClient | null;\n scope: IntegrationsScope;\n}\n\n/** A 4xx here means \"not for you\", not \"something broke\". */\nfunction isRefusal(err: unknown): boolean {\n const status = (err as DevicApiError)?.statusCode;\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * The apps an assistant offers to its tenants, with the accounts THIS tenant\n * has connected — loaded once and shared.\n *\n * Both the header button and the modal need the same listing: the button to\n * know whether it should exist and which logos to show, the modal to fill\n * itself. Fetching it in each of them would double every round trip and let the\n * two disagree for a moment after connecting an account.\n */\nexport function useIntegrations(\n options: UseIntegrationsOptions\n): IntegrationsState {\n const {\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n enabled = true,\n } = options;\n\n const context = useOptionalDevicContext();\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedTenantSession = context?.getTenantSession;\n const onSessionExpired = context?.onSessionExpired;\n\n const client = useMemo(\n () =>\n resolvedApiKey || resolvedTenantSession\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n getTenantSession: resolvedTenantSession,\n onSessionExpired,\n })\n : null,\n [resolvedApiKey, resolvedTenantSession, resolvedBaseUrl]\n );\n\n const scope = useMemo(\n () => ({\n assistantId,\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [assistantId, resolvedTenantId, resolvedSubtenantId]\n );\n\n const [integrations, setIntegrations] = useState<Integration[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [offered, setOffered] = useState(false);\n const [settled, setSettled] = useState(false);\n\n const refresh = useCallback(\n async (dropCache = false) => {\n if (!client) {\n setError(\"No credentials configured\");\n setSettled(true);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n // The server caches a scope's connections briefly; after an OAuth round\n // trip that cache is exactly one step behind, so drop it first.\n if (dropCache) {\n await client.refreshIntegrations(scope).catch(() => undefined);\n }\n const list = await client.getIntegrations(scope);\n setIntegrations(list);\n setOffered(list.length > 0);\n } catch (err) {\n setIntegrations([]);\n setOffered(false);\n setError(err instanceof Error ? err.message : String(err));\n if (!isRefusal(err)) {\n // A refusal is an ordinary answer and stays quiet. A 500 or a dead\n // network is not, and swallowing it entirely would leave an\n // integrator with a button that never appears and no reason why.\n console.warn(\"[devic-ui] could not load connected apps\", err);\n }\n } finally {\n setLoading(false);\n setSettled(true);\n }\n },\n [client, scope]\n );\n\n // Once per scope, not once per render of whatever switched it on. A new\n // assistant or tenant is a different listing altogether, so it loads again —\n // and the previous tenant's apps are dropped first, because showing them\n // while the new ones arrive would name accounts that are not this user's.\n const key = `${client ? \"k\" : \"-\"}|${scope.assistantId}|${scope.tenantId ?? \"\"}|${scope.subtenantId ?? \"\"}`;\n const loadedKeyRef = useRef<string | null>(null);\n useEffect(() => {\n if (!enabled || loadedKeyRef.current === key) return;\n if (loadedKeyRef.current !== null) {\n setIntegrations([]);\n setOffered(false);\n setSettled(false);\n }\n loadedKeyRef.current = key;\n void refresh();\n }, [enabled, key, refresh]);\n\n return {\n integrations,\n loading,\n error,\n offered,\n settled,\n refresh,\n client,\n scope,\n };\n}\n"],"names":["useOptionalDevicContext","client","useMemo","DevicApiClient","useState","useCallback","useRef","useEffect"],"mappings":";;;;;;;AA8CA;AACA,SAAS,SAAS,CAAC,GAAY,EAAA;AAC7B,IAAA,MAAM,MAAM,GAAI,GAAqB,EAAE,UAAU;AACjD,IAAA,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;AACpE;AAEA;;;;;;;;AAQG;AACG,SAAU,eAAe,CAC7B,OAA+B,EAAA;AAE/B,IAAA,MAAM,EACJ,WAAW,EACX,QAAQ,EACR,WAAW,EACX,MAAM,EACN,OAAO,EACP,OAAO,GAAG,IAAI,GACf,GAAG,OAAO;AAEX,IAAA,MAAM,OAAO,GAAGA,oCAAuB,EAAE;IACzC,MAAM,eAAe,GAAG,OAAO,IAAI,OAAO,EAAE,OAAO,IAAI,sBAAsB;AAC7E,IAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,OAAO,EAAE,QAAQ;AACtD,IAAA,MAAM,mBAAmB,GAAG,WAAW,IAAI,OAAO,EAAE,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E,CAAC;YACnB,UAAU,CAAC,KAAK,CAAC;YACjB,UAAU,CAAC,KAAK,CAAC;QACnB;AACA,QAAA,YAAY,CAAC,OAAO,GAAG,GAAG;QAC1B,KAAK,OAAO,EAAE;IAChB,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3B,OAAO;QACL,YAAY;QACZ,OAAO;QACP,KAAK;QACL,OAAO;QACP,OAAO;QACP,OAAO;gBACPN,QAAM;QACN,KAAK;KACN;AACH;;"}
1
+ {"version":3,"file":"useIntegrations.js","sources":["../../../../../src/components/IntegrationsModal/useIntegrations.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { DevicApiError } from \"../../api/client\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { Integration } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\nimport { useTranslations } from \"../../i18n\";\n\n/** What identifies the end user in front of the widget. */\nexport interface IntegrationsScope {\n assistantId: string;\n tenantId?: string;\n subtenantId?: string;\n}\n\nexport interface UseIntegrationsOptions extends IntegrationsScope {\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /**\n * Fetch when this turns true, and only then. The launcher passes the drawer's\n * open state so a widget nobody opens costs no request at all.\n */\n enabled?: boolean;\n}\n\nexport interface IntegrationsState {\n integrations: Integration[];\n loading: boolean;\n error: string | null;\n /**\n * Whether this assistant offers connected apps to its tenants at all.\n *\n * False before the first answer arrives, and false again if the server said\n * no — which it does for a disabled catalogue, a missing tenant, and an\n * assistant that does not exist, deliberately without distinguishing them.\n * Anything that hangs off this flag stays hidden until the server has said\n * yes, so nothing ever appears and then disappears.\n */\n offered: boolean;\n /** True once a first answer (or refusal) has arrived. */\n settled: boolean;\n refresh: (dropCache?: boolean) => Promise<void>;\n client: DevicApiClient | null;\n scope: IntegrationsScope;\n}\n\n/** A 4xx here means \"not for you\", not \"something broke\". */\nfunction isRefusal(err: unknown): boolean {\n const status = (err as DevicApiError)?.statusCode;\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * The apps an assistant offers to its tenants, with the accounts THIS tenant\n * has connected — loaded once and shared.\n *\n * Both the header button and the modal need the same listing: the button to\n * know whether it should exist and which logos to show, the modal to fill\n * itself. Fetching it in each of them would double every round trip and let the\n * two disagree for a moment after connecting an account.\n */\nexport function useIntegrations(\n options: UseIntegrationsOptions\n): IntegrationsState {\n const {\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n enabled = true,\n } = options;\n\n const t = useTranslations();\n const context = useOptionalDevicContext();\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedTenantSession = context?.getTenantSession;\n const onSessionExpired = context?.onSessionExpired;\n\n const client = useMemo(\n () =>\n resolvedApiKey || resolvedTenantSession\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n getTenantSession: resolvedTenantSession,\n onSessionExpired,\n })\n : null,\n [resolvedApiKey, resolvedTenantSession, resolvedBaseUrl]\n );\n\n const scope = useMemo(\n () => ({\n assistantId,\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [assistantId, resolvedTenantId, resolvedSubtenantId]\n );\n\n const [integrations, setIntegrations] = useState<Integration[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [offered, setOffered] = useState(false);\n const [settled, setSettled] = useState(false);\n\n const refresh = useCallback(\n async (dropCache = false) => {\n if (!client) {\n setError(t(\"No credentials configured\"));\n setSettled(true);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n // The server caches a scope's connections briefly; after an OAuth round\n // trip that cache is exactly one step behind, so drop it first.\n if (dropCache) {\n await client.refreshIntegrations(scope).catch(() => undefined);\n }\n const list = await client.getIntegrations(scope);\n setIntegrations(list);\n setOffered(list.length > 0);\n } catch (err) {\n setIntegrations([]);\n setOffered(false);\n setError(err instanceof Error ? err.message : String(err));\n if (!isRefusal(err)) {\n // A refusal is an ordinary answer and stays quiet. A 500 or a dead\n // network is not, and swallowing it entirely would leave an\n // integrator with a button that never appears and no reason why.\n console.warn(\"[devic-ui] could not load connected apps\", err);\n }\n } finally {\n setLoading(false);\n setSettled(true);\n }\n },\n [client, scope]\n );\n\n // Once per scope, not once per render of whatever switched it on. A new\n // assistant or tenant is a different listing altogether, so it loads again —\n // and the previous tenant's apps are dropped first, because showing them\n // while the new ones arrive would name accounts that are not this user's.\n const key = `${client ? \"k\" : \"-\"}|${scope.assistantId}|${scope.tenantId ?? \"\"}|${scope.subtenantId ?? \"\"}`;\n const loadedKeyRef = useRef<string | null>(null);\n useEffect(() => {\n if (!enabled || loadedKeyRef.current === key) return;\n if (loadedKeyRef.current !== null) {\n setIntegrations([]);\n setOffered(false);\n setSettled(false);\n }\n loadedKeyRef.current = key;\n void refresh();\n }, [enabled, key, refresh]);\n\n return {\n integrations,\n loading,\n error,\n offered,\n settled,\n refresh,\n client,\n scope,\n };\n}\n"],"names":["useTranslations","useOptionalDevicContext","client","useMemo","DevicApiClient","useState","useCallback","useRef","useEffect"],"mappings":";;;;;;;;AA+CA;AACA,SAAS,SAAS,CAAC,GAAY,EAAA;AAC7B,IAAA,MAAM,MAAM,GAAI,GAAqB,EAAE,UAAU;AACjD,IAAA,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;AACpE;AAEA;;;;;;;;AAQG;AACG,SAAU,eAAe,CAC7B,OAA+B,EAAA;AAE/B,IAAA,MAAM,EACJ,WAAW,EACX,QAAQ,EACR,WAAW,EACX,MAAM,EACN,OAAO,EACP,OAAO,GAAG,IAAI,GACf,GAAG,OAAO;AAEX,IAAA,MAAM,CAA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CAAA,CAAA,EAAI,KAAK,CAAC,WAAW,IAAI,EAAE,EAAE;AAC3G,IAAA,MAAM,YAAY,GAAGK,YAAM,CAAgB,IAAI,CAAC;IAChDC,eAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,KAAK,GAAG;YAAE;AAC9C,QAAA,IAAI,YAAY,CAAC,OAAO,KAAK,IAAI,EAAE;YACjC,eAAe,CAAC,EAAE,CAAC;YACnB,UAAU,CAAC,KAAK,CAAC;YACjB,UAAU,CAAC,KAAK,CAAC;QACnB;AACA,QAAA,YAAY,CAAC,OAAO,GAAG,GAAG;QAC1B,KAAK,OAAO,EAAE;IAChB,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3B,OAAO;QACL,YAAY;QACZ,OAAO;QACP,KAAK;QACL,OAAO;QACP,OAAO;QACP,OAAO;gBACPN,QAAM;QACN,KAAK;KACN;AACH;;;;"}
@@ -4,6 +4,7 @@ var React = require('react');
4
4
  var client = require('../../api/client.js');
5
5
  require('react/jsx-runtime');
6
6
  var DevicContext = require('../../provider/DevicContext.js');
7
+ var useTranslations = require('../../i18n/useTranslations.js');
7
8
 
8
9
  /** A 4xx here means "not for you", not "something broke". */
9
10
  function isRefusal(err) {
@@ -21,6 +22,7 @@ const NO_LIMITS = { maxServers: 0, maxToolsPerServer: 0, used: 0 };
21
22
  */
22
23
  function useTenantMcp(options) {
23
24
  const { assistantId, tenantId, subtenantId, apiKey, baseUrl, enabled = true } = options;
25
+ const t = useTranslations.useTranslations();
24
26
  const context = DevicContext.useOptionalDevicContext();
25
27
  const resolvedBaseUrl = baseUrl || context?.baseUrl || "https://api.devic.ai";
26
28
  const resolvedTenantId = tenantId || context?.tenantId;
@@ -47,7 +49,7 @@ function useTenantMcp(options) {
47
49
  const [settled, setSettled] = React.useState(false);
48
50
  const refresh = React.useCallback(async () => {
49
51
  if (!client$1) {
50
- setError("No credentials configured");
52
+ setError(t("No credentials configured"));
51
53
  setSettled(true);
52
54
  return;
53
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useTenantMcp.js","sources":["../../../../../src/components/IntegrationsModal/useTenantMcp.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { DevicApiError } from \"../../api/client\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { TenantMcpListing, TenantMcpServer } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\nimport type { IntegrationsScope } from \"./useIntegrations\";\n\nexport interface UseTenantMcpOptions extends IntegrationsScope {\n apiKey?: string;\n baseUrl?: string;\n /**\n * Fetch when this turns true, and only then. The modal passes its own open\n * state, so a panel nobody opens costs no request at all.\n */\n enabled?: boolean;\n}\n\nexport interface TenantMcpState {\n servers: TenantMcpServer[];\n loading: boolean;\n error: string | null;\n /** Whether this assistant offers MCP servers to its tenants at all. */\n offered: boolean;\n /** Whether the end user may add a server of their own. */\n allowCustom: boolean;\n limits: { maxServers: number; maxToolsPerServer: number; used: number };\n /** True once a first answer (or refusal) has arrived. */\n settled: boolean;\n refresh: () => Promise<void>;\n client: DevicApiClient | null;\n scope: IntegrationsScope;\n}\n\n/** A 4xx here means \"not for you\", not \"something broke\". */\nfunction isRefusal(err: unknown): boolean {\n const status = (err as DevicApiError)?.statusCode;\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\nconst NO_LIMITS = { maxServers: 0, maxToolsPerServer: 0, used: 0 };\n\n/**\n * The MCP servers an assistant offers its tenants, together with the ones this\n * tenant has connected — loaded once and shared.\n *\n * Deliberately a sibling of `useIntegrations` rather than part of it: the two\n * answer different endpoints, and folding them together would mean an assistant\n * that offers only one of them pays for both on every open.\n */\nexport function useTenantMcp(options: UseTenantMcpOptions): TenantMcpState {\n const { assistantId, tenantId, subtenantId, apiKey, baseUrl, enabled = true } =\n options;\n\n const context = useOptionalDevicContext();\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedTenantSession = context?.getTenantSession;\n const onSessionExpired = context?.onSessionExpired;\n\n const client = useMemo(\n () =>\n resolvedApiKey || resolvedTenantSession\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n getTenantSession: resolvedTenantSession,\n onSessionExpired,\n })\n : null,\n [resolvedApiKey, resolvedTenantSession, resolvedBaseUrl]\n );\n\n const scope = useMemo(\n () => ({\n assistantId,\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [assistantId, resolvedTenantId, resolvedSubtenantId]\n );\n\n const [listing, setListing] = useState<TenantMcpListing | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [settled, setSettled] = useState(false);\n\n const refresh = useCallback(async () => {\n if (!client) {\n setError(\"No credentials configured\");\n setSettled(true);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n setListing(await client.getMcpServers(scope));\n } catch (err) {\n setListing(null);\n setError(err instanceof Error ? err.message : String(err));\n if (!isRefusal(err)) {\n // A refusal is an ordinary answer — a disabled feature, a missing\n // tenant — and stays quiet. A 500 is not, and swallowing it would\n // leave an integrator with a panel that never appears and no reason.\n console.warn(\"[devic-ui] could not load MCP servers\", err);\n }\n } finally {\n setLoading(false);\n setSettled(true);\n }\n }, [client, scope]);\n\n // Once per scope, not once per render of whatever switched it on. A different\n // tenant is a different listing, and the previous one is dropped first:\n // showing it while the new one arrives would name servers that are not this\n // user's.\n const key = `${client ? \"k\" : \"-\"}|${scope.assistantId}|${scope.tenantId ?? \"\"}|${scope.subtenantId ?? \"\"}`;\n const loadedKeyRef = useRef<string | null>(null);\n useEffect(() => {\n if (!enabled || loadedKeyRef.current === key) return;\n if (loadedKeyRef.current !== null) {\n setListing(null);\n setSettled(false);\n }\n loadedKeyRef.current = key;\n void refresh();\n }, [enabled, key, refresh]);\n\n return {\n servers: listing?.servers ?? [],\n loading,\n error,\n // Offered only once the server has said so. Anything hanging off this stays\n // hidden until then, so nothing appears and then disappears.\n offered: !!listing?.offered,\n allowCustom: !!listing?.allowCustom,\n limits: listing?.limits ?? NO_LIMITS,\n settled,\n refresh,\n client,\n scope,\n };\n}\n"],"names":["useOptionalDevicContext","client","useMemo","DevicApiClient","useState","useCallback","useRef","useEffect"],"mappings":";;;;;;;AAiCA;AACA,SAAS,SAAS,CAAC,GAAY,EAAA;AAC7B,IAAA,MAAM,MAAM,GAAI,GAAqB,EAAE,UAAU;AACjD,IAAA,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;AACpE;AAEA,MAAM,SAAS,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE;AAElE;;;;;;;AAOG;AACG,SAAU,YAAY,CAAC,OAA4B,EAAA;AACvD,IAAA,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,EAAE,GAC3E,OAAO;AAET,IAAA,MAAM,OAAO,GAAGA,oCAAuB,EAAE;IACzC,MAAM,eAAe,GAAG,OAAO,IAAI,OAAO,EAAE,OAAO,IAAI,sBAAsB;AAC7E,IAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,OAAO,EAAE,QAAQ;AACtD,IAAA,MAAM,mBAAmB,GAAG,WAAW,IAAI,OAAO,EAAE,WAAW;AAC/D,IAAA,MAAM,cAAc,GAAG,MAAM,IAAI,OAAO,EAAE,MAAM;AAChD,IAAA,MAAM,qBAAqB,GAAG,OAAO,EAAE,gBAAgB;AACvD,IAAA,MAAM,gBAAgB,GAAG,OAAO,EAAE,gBAAgB;IAElD,MAAMC,QAAM,GAAGC,aAAO,CACpB,MACE,cAA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ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { DevicApiError } from \"../../api/client\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { TenantMcpListing, TenantMcpServer } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\nimport type { IntegrationsScope } from \"./useIntegrations\";\nimport { useTranslations } from \"../../i18n\";\n\nexport interface UseTenantMcpOptions extends IntegrationsScope {\n apiKey?: string;\n baseUrl?: string;\n /**\n * Fetch when this turns true, and only then. The modal passes its own open\n * state, so a panel nobody opens costs no request at all.\n */\n enabled?: boolean;\n}\n\nexport interface TenantMcpState {\n servers: TenantMcpServer[];\n loading: boolean;\n error: string | null;\n /** Whether this assistant offers MCP servers to its tenants at all. */\n offered: boolean;\n /** Whether the end user may add a server of their own. */\n allowCustom: boolean;\n limits: { maxServers: number; maxToolsPerServer: number; used: number };\n /** True once a first answer (or refusal) has arrived. */\n settled: boolean;\n refresh: () => Promise<void>;\n client: DevicApiClient | null;\n scope: IntegrationsScope;\n}\n\n/** A 4xx here means \"not for you\", not \"something broke\". */\nfunction isRefusal(err: unknown): boolean {\n const status = (err as DevicApiError)?.statusCode;\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\nconst NO_LIMITS = { maxServers: 0, maxToolsPerServer: 0, used: 0 };\n\n/**\n * The MCP servers an assistant offers its tenants, together with the ones this\n * tenant has connected — loaded once and shared.\n *\n * Deliberately a sibling of `useIntegrations` rather than part of it: the two\n * answer different endpoints, and folding them together would mean an assistant\n * that offers only one of them pays for both on every open.\n */\nexport function useTenantMcp(options: UseTenantMcpOptions): TenantMcpState {\n const { assistantId, tenantId, subtenantId, apiKey, baseUrl, enabled = true } =\n options;\n\n const t = useTranslations();\n const context = useOptionalDevicContext();\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedTenantSession = context?.getTenantSession;\n const onSessionExpired = context?.onSessionExpired;\n\n const client = useMemo(\n () =>\n resolvedApiKey || resolvedTenantSession\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n getTenantSession: resolvedTenantSession,\n onSessionExpired,\n })\n : null,\n [resolvedApiKey, resolvedTenantSession, resolvedBaseUrl]\n );\n\n const scope = useMemo(\n () => ({\n assistantId,\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [assistantId, resolvedTenantId, resolvedSubtenantId]\n );\n\n const [listing, setListing] = useState<TenantMcpListing | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [settled, setSettled] = useState(false);\n\n const refresh = useCallback(async () => {\n if (!client) {\n setError(t(\"No credentials configured\"));\n setSettled(true);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n setListing(await client.getMcpServers(scope));\n } catch (err) {\n setListing(null);\n setError(err instanceof Error ? err.message : String(err));\n if (!isRefusal(err)) {\n // A refusal is an ordinary answer — a disabled feature, a missing\n // tenant — and stays quiet. A 500 is not, and swallowing it would\n // leave an integrator with a panel that never appears and no reason.\n console.warn(\"[devic-ui] could not load MCP servers\", err);\n }\n } finally {\n setLoading(false);\n setSettled(true);\n }\n }, [client, scope]);\n\n // Once per scope, not once per render of whatever switched it on. A different\n // tenant is a different listing, and the previous one is dropped first:\n // showing it while the new one arrives would name servers that are not this\n // user's.\n const key = `${client ? \"k\" : \"-\"}|${scope.assistantId}|${scope.tenantId ?? \"\"}|${scope.subtenantId ?? \"\"}`;\n const loadedKeyRef = useRef<string | null>(null);\n useEffect(() => {\n if (!enabled || loadedKeyRef.current === key) return;\n if (loadedKeyRef.current !== null) {\n setListing(null);\n setSettled(false);\n }\n loadedKeyRef.current = key;\n void refresh();\n }, [enabled, key, refresh]);\n\n return {\n servers: listing?.servers ?? [],\n loading,\n error,\n // Offered only once the server has said so. Anything hanging off this stays\n // hidden until then, so nothing appears and then disappears.\n offered: !!listing?.offered,\n allowCustom: !!listing?.allowCustom,\n limits: listing?.limits ?? NO_LIMITS,\n settled,\n refresh,\n client,\n scope,\n };\n}\n"],"names":["useTranslations","useOptionalDevicContext","client","useMemo","DevicApiClient","useState","useCallback","useRef","useEffect"],"mappings":";;;;;;;;AAkCA;AACA,SAAS,SAAS,CAAC,GAAY,EAAA;AAC7B,IAAA,MAAM,MAAM,GAAI,GAAqB,EAAE,UAAU;AACjD,IAAA,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;AACpE;AAEA,MAAM,SAAS,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE;AAElE;;;;;;;AAOG;AACG,SAAU,YAAY,CAAC,OAA4B,EAAA;AACvD,IAAA,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,EAAE,GAC3E,OAAO;AAET,IAAA,MAAM,CAAC,GAAGA,+BAAe,EAAE;AAC3B,IAAA,MAAM,OAAO,GAAGC,oCAAuB,EAAE;IACzC,MAAM,eAAe,GAAG,OAAO,IAAI,OAAO,EAAE,OAAO,IAAI,sBAAsB;AAC7E,IAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,OAAO,EAAE,QAAQ;AACtD,IAAA,MAAM,mBAAmB,GAAG,WAAW,IAAI,OAAO,EAAE,WAAW;AAC/D,IAAA,MAAM,cAAc,GAAG,MAAM,IAAI,OAAO,EAAE,MAAM;AAChD,IAAA,MAAM,qBAAqB,GAAG,OAAO,EAAE,gBAAgB;AACvD,IAAA,MAAM,gBAAgB,GAAG,OAAO,EAAE,gBAAgB;IAElD,MAAMC,QAAM,GAAGC,aAAO,CACpB,MACE,cAAc,IAAI;UACd,IAAIC,qBAAc,CAAC;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