@devicai/ui 0.49.0 → 0.51.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 (119) hide show
  1. package/dist/cjs/api/assistantInfo.js.map +1 -1
  2. package/dist/cjs/api/client.js.map +1 -1
  3. package/dist/cjs/api/types.js.map +1 -1
  4. package/dist/cjs/components/AICommandBar/AICommandBar.js.map +1 -1
  5. package/dist/cjs/components/AICommandBar/useAICommandBar.js.map +1 -1
  6. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  7. package/dist/cjs/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
  8. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  9. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  10. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  11. package/dist/cjs/components/ChatDrawer/ChatDrawer.js +99 -8
  12. package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
  13. package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -1
  14. package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -1
  15. package/dist/cjs/components/ChatDrawer/ConversationSelector.js.map +1 -1
  16. package/dist/cjs/components/ChatDrawer/ErrorBoundary.js.map +1 -1
  17. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  18. package/dist/cjs/components/ChatDrawer/LimitBanner.js.map +1 -1
  19. package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
  20. package/dist/cjs/components/ChatDrawer/ReferenceChip.js.map +1 -1
  21. package/dist/cjs/components/ChatDrawer/ToolTimeline.js.map +1 -1
  22. package/dist/cjs/components/ChatDrawer/UsageBar.js.map +1 -1
  23. package/dist/cjs/components/ChatDrawer/pastedText.js.map +1 -1
  24. package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
  25. package/dist/cjs/components/Feedback/FeedbackModal.js.map +1 -1
  26. package/dist/cjs/components/Feedback/MessageActions.js.map +1 -1
  27. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
  28. package/dist/cjs/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
  29. package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
  30. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js +22 -10
  31. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
  32. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  33. package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js +43 -18
  34. package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
  35. package/dist/cjs/components/IntegrationsModal/McpConnectForm.js.map +1 -1
  36. package/dist/cjs/components/IntegrationsModal/McpServersSection.js.map +1 -1
  37. package/dist/cjs/components/IntegrationsModal/integrationChoice.js +59 -0
  38. package/dist/cjs/components/IntegrationsModal/integrationChoice.js.map +1 -0
  39. package/dist/cjs/components/IntegrationsModal/useIntegrations.js.map +1 -1
  40. package/dist/cjs/components/IntegrationsModal/useTenantMcp.js.map +1 -1
  41. package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
  42. package/dist/cjs/components/theme.js.map +1 -1
  43. package/dist/cjs/hooks/useDevicChat.js.map +1 -1
  44. package/dist/cjs/hooks/useModelInterface.js.map +1 -1
  45. package/dist/cjs/hooks/usePolling.js.map +1 -1
  46. package/dist/cjs/hooks/useSpeechRecording.js.map +1 -1
  47. package/dist/cjs/index.js +5 -0
  48. package/dist/cjs/index.js.map +1 -1
  49. package/dist/cjs/provider/DevicContext.js.map +1 -1
  50. package/dist/cjs/provider/DevicProvider.js.map +1 -1
  51. package/dist/cjs/provider/sharedSession.js.map +1 -1
  52. package/dist/cjs/styles.css +1 -1
  53. package/dist/cjs/utils/avatar.js.map +1 -1
  54. package/dist/cjs/utils/index.js.map +1 -1
  55. package/dist/cjs/utils/logger.js.map +1 -1
  56. package/dist/cjs/utils/toolGroups.js.map +1 -1
  57. package/dist/esm/api/assistantInfo.js.map +1 -1
  58. package/dist/esm/api/client.js.map +1 -1
  59. package/dist/esm/api/types.d.ts +16 -0
  60. package/dist/esm/api/types.js.map +1 -1
  61. package/dist/esm/components/AICommandBar/AICommandBar.js.map +1 -1
  62. package/dist/esm/components/AICommandBar/useAICommandBar.js.map +1 -1
  63. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  64. package/dist/esm/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
  65. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  66. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  67. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  68. package/dist/esm/components/ChatDrawer/ChatDrawer.js +100 -9
  69. package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
  70. package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -1
  71. package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -1
  72. package/dist/esm/components/ChatDrawer/ConversationSelector.js.map +1 -1
  73. package/dist/esm/components/ChatDrawer/ErrorBoundary.js.map +1 -1
  74. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  75. package/dist/esm/components/ChatDrawer/LimitBanner.js.map +1 -1
  76. package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
  77. package/dist/esm/components/ChatDrawer/ReferenceChip.js.map +1 -1
  78. package/dist/esm/components/ChatDrawer/ToolTimeline.js.map +1 -1
  79. package/dist/esm/components/ChatDrawer/UsageBar.js.map +1 -1
  80. package/dist/esm/components/ChatDrawer/pastedText.js.map +1 -1
  81. package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
  82. package/dist/esm/components/Feedback/FeedbackModal.js.map +1 -1
  83. package/dist/esm/components/Feedback/MessageActions.js.map +1 -1
  84. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
  85. package/dist/esm/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
  86. package/dist/esm/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
  87. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.d.ts +17 -1
  88. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js +22 -10
  89. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
  90. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  91. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.d.ts +22 -3
  92. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js +44 -19
  93. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
  94. package/dist/esm/components/IntegrationsModal/McpConnectForm.js.map +1 -1
  95. package/dist/esm/components/IntegrationsModal/McpServersSection.js.map +1 -1
  96. package/dist/esm/components/IntegrationsModal/index.d.ts +1 -0
  97. package/dist/esm/components/IntegrationsModal/integrationChoice.d.ts +16 -0
  98. package/dist/esm/components/IntegrationsModal/integrationChoice.js +54 -0
  99. package/dist/esm/components/IntegrationsModal/integrationChoice.js.map +1 -0
  100. package/dist/esm/components/IntegrationsModal/useIntegrations.js.map +1 -1
  101. package/dist/esm/components/IntegrationsModal/useTenantMcp.js.map +1 -1
  102. package/dist/esm/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
  103. package/dist/esm/components/theme.js.map +1 -1
  104. package/dist/esm/hooks/useDevicChat.js.map +1 -1
  105. package/dist/esm/hooks/useModelInterface.js.map +1 -1
  106. package/dist/esm/hooks/usePolling.js.map +1 -1
  107. package/dist/esm/hooks/useSpeechRecording.js.map +1 -1
  108. package/dist/esm/index.d.ts +1 -1
  109. package/dist/esm/index.js +1 -0
  110. package/dist/esm/index.js.map +1 -1
  111. package/dist/esm/provider/DevicContext.js.map +1 -1
  112. package/dist/esm/provider/DevicProvider.js.map +1 -1
  113. package/dist/esm/provider/sharedSession.js.map +1 -1
  114. package/dist/esm/styles.css +1 -1
  115. package/dist/esm/utils/avatar.js.map +1 -1
  116. package/dist/esm/utils/index.js.map +1 -1
  117. package/dist/esm/utils/logger.js.map +1 -1
  118. package/dist/esm/utils/toolGroups.js.map +1 -1
  119. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"IntegrationsToggle.js","sources":["../../../../../src/components/IntegrationsModal/IntegrationsToggle.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState, type JSX } from \"react\";\nimport type { Integration } from \"../../api/types\";\nimport { IntegrationLogo } from \"./IntegrationLogo\";\nimport type { IntegrationsState } from \"./useIntegrations\";\nimport \"./IntegrationsModal.css\";\n\nexport interface IntegrationsToggleProps {\n /** Shared listing (see `useIntegrations`). */\n state: IntegrationsState;\n /** Slugs currently switched off. */\n disabled: string[];\n /** Called with the full new list of switched-off slugs. */\n onChange: (disabled: string[]) => void;\n /** Opens the connected-apps modal, to connect one more. */\n onManage?: () => void;\n /** Tooltip and accessible name. @default \"Apps in this chat\" */\n label?: string;\n /** Light-on-dark, for a dark composer. */\n dark?: boolean;\n /** Disables the control while a message is in flight. */\n busy?: boolean;\n className?: string;\n}\n\n/** A plug, matching the weight of the attach and mic icons beside it. */\nfunction PlugIcon(): JSX.Element {\n return (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M9 2v6\" />\n <path d=\"M15 2v6\" />\n <path d=\"M6 8h12v3a6 6 0 0 1-12 0z\" />\n <path d=\"M12 17v5\" />\n </svg>\n );\n}\n\n/**\n * Which apps the assistant may reach on the next message.\n *\n * Only apps the end user has actually connected appear: an app they have not\n * set up is not something they can switch off, and listing it here would turn\n * this into a second, worse version of the connect dialog.\n *\n * The choice lives in the caller and travels with each message. Nothing is\n * remembered on the server and nothing is disconnected — switching Gmail off\n * for a question about a spreadsheet must not cost an OAuth round trip to\n * undo, which is the whole reason this exists next to the composer rather than\n * inside the apps dialog.\n */\nexport function IntegrationsToggle({\n state,\n disabled,\n onChange,\n onManage,\n label = \"Apps in this chat\",\n dark = false,\n busy = false,\n className = \"\",\n}: IntegrationsToggleProps): JSX.Element | null {\n const [open, setOpen] = useState(false);\n const ref = useRef<HTMLDivElement>(null);\n\n const connected = useMemo(\n () => state.integrations.filter((i) => i.connected),\n [state.integrations]\n );\n\n // Closing on an outside click and on Escape, the two ways every popover is\n // expected to close. Bound only while open so a drawer full of these costs\n // nothing when they are all shut.\n useEffect(() => {\n if (!open) return;\n const onPointerDown = (e: MouseEvent) => {\n if (!ref.current?.contains(e.target as Node)) setOpen(false);\n };\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n e.stopPropagation();\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n document.addEventListener(\"keydown\", onKeyDown, true);\n return () => {\n document.removeEventListener(\"mousedown\", onPointerDown);\n document.removeEventListener(\"keydown\", onKeyDown, true);\n };\n }, [open]);\n\n // An end user with nothing connected has nothing to switch: the button would\n // open an empty box. It appears the moment they connect their first app.\n if (!state.offered || connected.length === 0) return null;\n\n const off = new Set(disabled);\n const offCount = connected.filter((i) => off.has(i.app)).length;\n\n const toggle = (integration: Integration) => {\n const next = new Set(off);\n if (next.has(integration.app)) next.delete(integration.app);\n else next.add(integration.app);\n // Only apps still on offer are kept: carrying a slug for an app the user\n // has since disconnected would silently switch it off again if they ever\n // reconnected it.\n onChange(connected.filter((i) => next.has(i.app)).map((i) => i.app));\n };\n\n return (\n <div\n className={`devic-int-toggle ${className}`.trim()}\n data-dark={dark}\n ref={ref}\n >\n <button\n type=\"button\"\n className=\"devic-input-btn devic-int-toggle-btn\"\n onClick={() => setOpen((v) => !v)}\n disabled={busy}\n title={\n offCount\n ? `${label} — ${offCount} switched off`\n : label\n }\n aria-label={label}\n aria-expanded={open}\n aria-haspopup=\"dialog\"\n data-some-off={offCount > 0 || undefined}\n >\n <PlugIcon />\n {offCount > 0 && (\n <span className=\"devic-int-toggle-badge\" aria-hidden=\"true\">\n {offCount}\n </span>\n )}\n </button>\n\n {open && (\n <div className=\"devic-int-toggle-popover\" role=\"dialog\" aria-label={label}>\n <div className=\"devic-int-toggle-head\">\n <strong>{label}</strong>\n <span>\n Switched off here, an app sits out your next message. It stays\n connected.\n </span>\n </div>\n\n <ul className=\"devic-int-toggle-list\">\n {connected.map((integration) => {\n const on = !off.has(integration.app);\n return (\n <li key={integration.app}>\n <label className=\"devic-int-toggle-row\">\n <span className=\"devic-int-toggle-app\">\n <IntegrationLogo integration={integration} />\n <span className=\"devic-int-toggle-name\">\n {integration.name}\n </span>\n </span>\n <input\n type=\"checkbox\"\n className=\"devic-int-toggle-switch\"\n checked={on}\n onChange={() => toggle(integration)}\n aria-label={`Use ${integration.name} in this chat`}\n />\n </label>\n </li>\n );\n })}\n </ul>\n\n {onManage && (\n <button\n type=\"button\"\n className=\"devic-int-toggle-manage\"\n onClick={() => {\n setOpen(false);\n onManage();\n }}\n >\n Manage connected apps\n </button>\n )}\n </div>\n )}\n </div>\n );\n}\n\nexport default IntegrationsToggle;\n"],"names":["_jsxs","_jsx","useState","useRef","useMemo","useEffect","IntegrationLogo"],"mappings":";;;;;;AAwBA;AACA,SAAS,QAAQ,GAAA;AACf,IAAA,QACEA,eAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,aAAA,EACV,MAAM,EAAA,QAAA,EAAA,CAElBC,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EA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B,EAAA,QAAA,EAAA,CACrCA,eAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,sBAAsB,EAAA,QAAA,EAAA,CACpCC,eAACK,+BAAe,EAAA,EAAC,WAAW,EAAE,WAAW,EAAA,CAAI,EAC7CL,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,uBAAuB,EAAA,QAAA,EACpC,WAAW,CAAC,IAAI,EAAA,CACZ,CAAA,EAAA,CACF,EACPA,cAAA,CAAA,OAAA,EAAA,EACE,IAAI,EAAC,UAAU,EACf,SAAS,EAAC,yBAAyB,EACnC,OAAO,EAAE,EAAE,EACX,QAAQ,EAAE,MAAM,MAAM,CAAC,WAAW,CAAC,EAAA,YAAA,EACvB,CAAA,IAAA,EAAO,WAAW,CAAC,IAAI,CAAA,aAAA,CAAe,EAAA,CAClD,CAAA,EAAA,CACI,EAAA,EAfD,WAAW,CAAC,GAAG,CAgBnB;AAET,wBAAA,CAAC,CAAC,EAAA,CACC,EAEJ,QAAQ,KACPA,2BACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,yBAAyB,EACnC,OAAO,EAAE,MAAK;4BACZ,OAAO,CAAC,KAAK,CAAC;AACd,4BAAA,QAAQ,EAAE;AACZ,wBAAA,CAAC,sCAGM,CACV,CAAA,EAAA,CACG,CACP,CAAA,EAAA,CACG;AAEV;;;;"}
1
+ {"version":3,"file":"IntegrationsToggle.js","sources":["../../../../../src/components/IntegrationsModal/IntegrationsToggle.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState, type JSX } from \"react\";\nimport type { Integration, TenantMcpServer } from \"../../api/types\";\nimport { IntegrationLogo } from \"./IntegrationLogo\";\nimport type { IntegrationsState } from \"./useIntegrations\";\nimport type { TenantMcpState } from \"./useTenantMcp\";\nimport \"./IntegrationsModal.css\";\n\nexport interface IntegrationsToggleProps {\n /** Shared listing (see `useIntegrations`). */\n state: IntegrationsState;\n /**\n * The tenant's own MCP servers, when the assistant offers them (see\n * `useTenantMcp`). Their connected servers are listed under the apps and\n * switch off the same way — a server the end user connected is as much\n * theirs to leave out of a message as an account is.\n */\n mcp?: TenantMcpState;\n /**\n * What is switched off right now. App slugs, and the `toggleId` of a\n * connected MCP server — one list, because that is what the message carries\n * and what the server keeps for the rest of the turn.\n */\n disabled: string[];\n /** Called with the full new list of switched-off entries. */\n onChange: (disabled: string[]) => void;\n /** Opens the connected-apps modal, to connect one more. */\n onManage?: () => void;\n /** Tooltip and accessible name. @default \"Apps in this chat\" */\n label?: string;\n /** Light-on-dark, for a dark composer. */\n dark?: boolean;\n /** Disables the control while a message is in flight. */\n busy?: boolean;\n /**\n * Whether the requests that decide if this control exists are still running.\n *\n * Holds an inert plug in the row rather than letting the attach and mic\n * buttons shift sideways the moment the answer lands.\n */\n loading?: boolean;\n className?: string;\n}\n\n/** A plug, matching the weight of the attach and mic icons beside it. */\nfunction PlugIcon(): JSX.Element {\n return (\n <svg\n width=\"18\"\n height=\"18\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M9 2v6\" />\n <path d=\"M15 2v6\" />\n <path d=\"M6 8h12v3a6 6 0 0 1-12 0z\" />\n <path d=\"M12 17v5\" />\n </svg>\n );\n}\n\n/** A server's own logo when it has one, its initial when it does not. */\nfunction McpBadge({ server }: { server: TenantMcpServer }): JSX.Element {\n if (server.logoUrl) {\n return (\n <img\n className=\"devic-int-toggle-mcp-logo\"\n src={server.logoUrl}\n alt=\"\"\n aria-hidden=\"true\"\n />\n );\n }\n return (\n <span\n className=\"devic-int-toggle-mcp-logo devic-int-toggle-mcp-fallback\"\n aria-hidden=\"true\"\n >\n {server.name.slice(0, 1).toUpperCase()}\n </span>\n );\n}\n\n/**\n * Which apps the assistant may reach on the next message.\n *\n * Only apps the end user has actually connected appear: an app they have not\n * set up is not something they can switch off, and listing it here would turn\n * this into a second, worse version of the connect dialog.\n *\n * The choice lives in the caller and travels with each message. Nothing is\n * remembered on the server and nothing is disconnected — switching Gmail off\n * for a question about a spreadsheet must not cost an OAuth round trip to\n * undo, which is the whole reason this exists next to the composer rather than\n * inside the apps dialog.\n */\nexport function IntegrationsToggle({\n state,\n mcp,\n disabled,\n onChange,\n onManage,\n label = \"Apps in this chat\",\n dark = false,\n busy = false,\n loading = false,\n className = \"\",\n}: IntegrationsToggleProps): JSX.Element | null {\n const [open, setOpen] = useState(false);\n const ref = useRef<HTMLDivElement>(null);\n\n const connected = useMemo(\n () => state.integrations.filter((i) => i.connected),\n [state.integrations]\n );\n\n // Connected and usable: one still waiting for its consent screen, or whose\n // last probe failed, contributes no tools, so switching it off would be\n // switching off nothing. It belongs in the panel that can fix it, not here.\n const mcpServers = useMemo(\n () =>\n (mcp?.servers ?? []).filter(\n (s) => s.connection?.status === \"active\" && !!s.connection.toggleId\n ),\n [mcp?.servers]\n );\n\n // Closing on an outside click and on Escape, the two ways every popover is\n // expected to close. Bound only while open so a drawer full of these costs\n // nothing when they are all shut.\n useEffect(() => {\n if (!open) return;\n const onPointerDown = (e: MouseEvent) => {\n if (!ref.current?.contains(e.target as Node)) setOpen(false);\n };\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n e.stopPropagation();\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n document.addEventListener(\"keydown\", onKeyDown, true);\n return () => {\n document.removeEventListener(\"mousedown\", onPointerDown);\n document.removeEventListener(\"keydown\", onKeyDown, true);\n };\n }, [open]);\n\n // An end user with nothing connected has nothing to switch: the button would\n // open an empty box. It appears the moment they connect their first app — or\n // their first MCP server, which is as switchable as an account is.\n const hasApps = state.offered && connected.length > 0;\n const hasMcp = !!mcp?.offered && mcpServers.length > 0;\n\n if (!hasApps && !hasMcp) {\n if (!loading) return null;\n // Still being decided: hold the slot, inert, so the row does not shift.\n return (\n <div className={`devic-int-toggle ${className}`.trim()} data-dark={dark}>\n <button\n type=\"button\"\n className=\"devic-input-btn devic-int-toggle-btn devic-int-toggle-btn-loading\"\n disabled\n aria-busy=\"true\"\n aria-label={`${label} (loading)`}\n title={label}\n >\n <PlugIcon />\n </button>\n </div>\n );\n }\n\n const off = new Set(disabled);\n\n /** Everything still on offer, so a stale entry can never survive a rewrite. */\n const liveIds = [\n ...connected.map((i) => i.app),\n ...mcpServers.map((s) => s.connection!.toggleId as string),\n ];\n const offCount = liveIds.filter((id) => off.has(id)).length;\n\n const flip = (id: string) => {\n const next = new Set(off);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n // Only what is still on offer is kept: carrying an entry for an app or a\n // server the user has since disconnected would silently switch it off again\n // if they ever connected it back.\n onChange(liveIds.filter((candidate) => next.has(candidate)));\n };\n\n return (\n <div\n className={`devic-int-toggle ${className}`.trim()}\n data-dark={dark}\n ref={ref}\n >\n <button\n type=\"button\"\n className=\"devic-input-btn devic-int-toggle-btn\"\n onClick={() => setOpen((v) => !v)}\n disabled={busy}\n title={\n offCount\n ? `${label} — ${offCount} switched off`\n : label\n }\n aria-label={label}\n aria-expanded={open}\n aria-haspopup=\"dialog\"\n data-some-off={offCount > 0 || undefined}\n >\n <PlugIcon />\n {offCount > 0 && (\n <span className=\"devic-int-toggle-badge\" aria-hidden=\"true\">\n {offCount}\n </span>\n )}\n </button>\n\n {open && (\n <div className=\"devic-int-toggle-popover\" role=\"dialog\" aria-label={label}>\n <div className=\"devic-int-toggle-head\">\n <strong>{label}</strong>\n <span>\n Switched off here, {hasMcp && !hasApps ? \"a server\" : \"an app\"}{\" \"}\n sits out your next message. It stays connected.\n </span>\n </div>\n\n <ul className=\"devic-int-toggle-list\">\n {connected.map((integration) => (\n <li key={integration.app}>\n <label className=\"devic-int-toggle-row\">\n <span className=\"devic-int-toggle-app\">\n <IntegrationLogo integration={integration} />\n <span className=\"devic-int-toggle-name\">\n {integration.name}\n </span>\n </span>\n <input\n type=\"checkbox\"\n className=\"devic-int-toggle-switch\"\n checked={!off.has(integration.app)}\n onChange={() => flip(integration.app)}\n aria-label={`Use ${integration.name} in this chat`}\n />\n </label>\n </li>\n ))}\n\n {/* Named apart only when both kinds are present: with servers\n alone the heading would label the entire list. */}\n {hasMcp && hasApps && (\n <li className=\"devic-int-toggle-group\" aria-hidden=\"true\">\n MCP servers\n </li>\n )}\n\n {mcpServers.map((server) => {\n const id = server.connection!.toggleId as string;\n return (\n <li key={id}>\n <label className=\"devic-int-toggle-row\">\n <span className=\"devic-int-toggle-app\">\n <McpBadge server={server} />\n <span className=\"devic-int-toggle-name\">\n {server.name}\n </span>\n </span>\n <input\n type=\"checkbox\"\n className=\"devic-int-toggle-switch\"\n checked={!off.has(id)}\n onChange={() => flip(id)}\n aria-label={`Use ${server.name} in this chat`}\n />\n </label>\n </li>\n );\n })}\n </ul>\n\n {onManage && (\n <button\n type=\"button\"\n className=\"devic-int-toggle-manage\"\n onClick={() => {\n setOpen(false);\n onManage();\n }}\n >\n {hasMcp && !hasApps\n ? \"Manage connected servers\"\n : \"Manage connected apps\"}\n </button>\n )}\n </div>\n )}\n </div>\n );\n}\n\nexport default IntegrationsToggle;\n"],"names":["_jsxs","_jsx","useState","useRef","useMemo","useEffect","IntegrationLogo"],"mappings":";;;;;;AA2CA;AACA,SAAS,QAAQ,GAAA;AACf,IAAA,QACEA,eAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,aAAA,EACV,MAAM,EAAA,QAAA,EAAA,CAElBC,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,QAAQ,EAAA,CAAG,EACnBA,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,SAAS,EAAA,CAAG,EACpBA,cAAA,CAAA,MAAA,E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I,EAAA,CACP,CAAA,EAAA,CACF,EACPA,cAAA,CAAA,OAAA,EAAA,EACE,IAAI,EAAC,UAAU,EACf,SAAS,EAAC,yBAAyB,EACnC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EACrB,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC,EAAA,YAAA,EACZ,OAAO,MAAM,CAAC,IAAI,CAAA,aAAA,CAAe,GAC7C,CAAA,EAAA,CACI,EAAA,EAfD,EAAE,CAgBN;AAET,4BAAA,CAAC,CAAC,CAAA,EAAA,CACC,EAEJ,QAAQ,KACPA,2BACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,yBAAyB,EACnC,OAAO,EAAE,MAAK;4BACZ,OAAO,CAAC,KAAK,CAAC;AACd,4BAAA,QAAQ,EAAE;AACZ,wBAAA,CAAC,EAAA,QAAA,EAEA,MAAM,IAAI,CAAC;AACV,8BAAE;8BACA,uBAAuB,EAAA,CACpB,CACV,IACG,CACP,CAAA,EAAA,CACG;AAEV;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"McpConnectForm.js","sources":["../../../../../src/components/IntegrationsModal/McpConnectForm.tsx"],"sourcesContent":["import { useMemo, useState, type FormEvent, type JSX } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { TenantMcpAuthInput, TenantMcpServer } from \"../../api/types\";\nimport { isDarkTheme, themeVars, type DevicTheme } from \"../theme\";\n\nexport interface McpConnectFormProps {\n /**\n * The server being connected. `null` is the \"add your own\" case, where the\n * url and the name are the end user's to type.\n */\n server: TenantMcpServer | null;\n submitting?: boolean;\n error?: string | null;\n /**\n * The redirect URI the end user must authorise on their own OAuth\n * application, when the server told us it has no dynamic registration.\n */\n callbackUrl?: string;\n /** Open the client-credentials fields already expanded. */\n needsClientCredentials?: boolean;\n theme?: DevicTheme;\n onCancel: () => void;\n onSubmit: (values: {\n url?: string;\n name?: string;\n auth: TenantMcpAuthInput;\n }) => void;\n}\n\n/**\n * What an MCP server asks the end user for.\n *\n * Both ways in end here — a server the developer listed and one the user\n * brings — because the difference between them is only who typed the url.\n * Everything after that is the same question: a key, or a trip to a consent\n * screen.\n *\n * A dialog rather than something inside a card: the OAuth-application fields\n * carry a redirect URI the user has to copy somewhere else, which does not fit\n * in a column of a grid without becoming a stack of clipped text.\n *\n * Values go straight into the connection and are never kept here.\n */\nexport function McpConnectForm({\n server,\n submitting,\n error,\n callbackUrl,\n needsClientCredentials,\n theme,\n onCancel,\n onSubmit,\n}: McpConnectFormProps): JSX.Element {\n const custom = !server;\n const [url, setUrl] = useState(server?.url ?? \"\");\n const [name, setName] = useState(server?.name ?? \"\");\n const [key, setKey] = useState(\"\");\n const [clientId, setClientId] = useState(\"\");\n const [clientSecret, setClientSecret] = useState(\"\");\n const [showClient, setShowClient] = useState(!!needsClientCredentials);\n const [copied, setCopied] = useState(false);\n const [touched, setTouched] = useState(false);\n\n // A server the user brings could be anything, so the form offers both ways\n // and lets them say. One the developer listed already declared how it\n // authenticates, and asking again would only invite a wrong answer.\n const [mode, setMode] = useState<TenantMcpAuthInput[\"mode\"]>(\n server?.authMode ?? \"oauth\"\n );\n\n const headerLabel = server?.headerName\n ? `${server.headerName} value`\n : \"API key\";\n\n const urlInvalid = useMemo(\n () => custom && touched && !/^https:\\/\\/.+/i.test(url.trim()),\n [custom, touched, url]\n );\n const keyInvalid = touched && mode === \"header\" && !key.trim();\n\n const handleSubmit = (event: FormEvent) => {\n event.preventDefault();\n setTouched(true);\n if (submitting) return;\n if (custom && !/^https:\\/\\/.+/i.test(url.trim())) return;\n if (mode === \"header\" && !key.trim()) return;\n\n onSubmit({\n url: custom ? url.trim() : undefined,\n name: name.trim() || undefined,\n auth: {\n mode,\n headerValue: mode === \"header\" ? key.trim() : undefined,\n upstreamOAuth:\n mode === \"oauth\" && clientId.trim()\n ? {\n clientId: clientId.trim(),\n clientSecret: clientSecret.trim() || undefined,\n }\n : undefined,\n },\n });\n };\n\n const title = custom ? \"Add an MCP server\" : `Connect ${server.name}`;\n\n return createPortal(\n <div\n className=\"devic-int-overlay devic-int-overlay-stacked\"\n style={themeVars(theme)}\n data-dark={isDarkTheme(theme)}\n onClick={onCancel}\n >\n <form\n className=\"devic-int-connect-dialog\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n onClick={(e) => e.stopPropagation()}\n onSubmit={handleSubmit}\n >\n <div className=\"devic-int-connect-header\">\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 ?? \"M\").slice(0, 1).toUpperCase()}\n </span>\n )}\n <div className=\"devic-int-connect-heading\">\n <strong>{title}</strong>\n <span>\n {mode === \"oauth\"\n ? \"You'll be sent to the server to finish authorising.\"\n : mode === \"header\"\n ? \"Your key goes straight to the server — only you can use it.\"\n : \"This server needs no credentials.\"}\n </span>\n </div>\n <button\n type=\"button\"\n className=\"devic-int-close\"\n onClick={onCancel}\n aria-label=\"Close\"\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-int-connect-body\">\n {error && <div className=\"devic-int-error\">{error}</div>}\n\n {custom && (\n <>\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">Server URL</span>\n <input\n autoFocus\n type=\"url\"\n value={url}\n onChange={(e) => setUrl(e.target.value)}\n placeholder=\"https://mcp.example.com/sse\"\n spellCheck={false}\n autoComplete=\"off\"\n aria-invalid={urlInvalid || undefined}\n data-invalid={urlInvalid || undefined}\n />\n <small className=\"devic-int-connect-hint\">\n Must be reachable over https on a public address.\n </small>\n </label>\n\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Name <em>(optional)</em>\n </span>\n <input\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder=\"What you want to call it\"\n autoComplete=\"off\"\n />\n </label>\n\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">Authentication</span>\n <select\n value={mode}\n onChange={(e) =>\n setMode(e.target.value as TenantMcpAuthInput[\"mode\"])\n }\n >\n <option value=\"oauth\">Sign in (OAuth)</option>\n <option value=\"header\">API key</option>\n <option value=\"none\">None</option>\n </select>\n </label>\n </>\n )}\n\n {mode === \"header\" && (\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">{headerLabel}</span>\n <input\n autoFocus={!custom}\n type=\"password\"\n value={key}\n onChange={(e) => setKey(e.target.value)}\n autoComplete=\"new-password\"\n spellCheck={false}\n aria-invalid={keyInvalid || undefined}\n data-invalid={keyInvalid || undefined}\n />\n </label>\n )}\n\n {mode === \"oauth\" && (custom || server?.allowClientCredentials) && (\n <div className=\"devic-int-mcp-advanced\">\n {/* Not a detail to bury: a server whose authorization server has\n no dynamic client registration cannot be connected at all\n without these, and the message that says so arrives only\n after the first attempt. */}\n {needsClientCredentials && (\n <div className=\"devic-int-notice\">\n This server needs its own OAuth application. Register one with\n it and paste the details below.\n </div>\n )}\n <button\n type=\"button\"\n className=\"devic-int-mcp-disclosure\"\n onClick={() => setShowClient((prev) => !prev)}\n aria-expanded={showClient}\n >\n {showClient ? \"▾\" : \"▸\"} Use my own OAuth application\n </button>\n\n {showClient && (\n <>\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Client ID <em>(optional)</em>\n </span>\n <input\n type=\"text\"\n value={clientId}\n onChange={(e) => setClientId(e.target.value)}\n autoComplete=\"off\"\n spellCheck={false}\n />\n </label>\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Client secret <em>(optional)</em>\n </span>\n <input\n type=\"password\"\n value={clientSecret}\n onChange={(e) => setClientSecret(e.target.value)}\n autoComplete=\"new-password\"\n spellCheck={false}\n />\n </label>\n {callbackUrl && (\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Authorised redirect URI\n </span>\n <input readOnly value={callbackUrl} spellCheck={false} />\n <small className=\"devic-int-connect-hint\">\n Add this to your OAuth application, exactly as shown.{\" \"}\n <button\n type=\"button\"\n className=\"devic-int-mcp-copy\"\n onClick={() => {\n void navigator.clipboard\n ?.writeText(callbackUrl)\n .then(() => setCopied(true))\n .catch(() => undefined);\n }}\n >\n {copied ? \"Copied\" : \"Copy\"}\n </button>\n </small>\n </label>\n )}\n </>\n )}\n </div>\n )}\n </div>\n\n <div className=\"devic-int-connect-actions\">\n <button\n type=\"button\"\n className=\"devic-int-btn\"\n onClick={onCancel}\n disabled={submitting}\n >\n Cancel\n </button>\n <button\n type=\"submit\"\n className=\"devic-int-btn devic-int-btn-primary\"\n disabled={submitting}\n >\n {submitting ? \"Connecting…\" : mode === \"oauth\" ? \"Continue\" : \"Connect\"}\n </button>\n </div>\n </form>\n </div>,\n document.body\n );\n}\n\nexport default McpConnectForm;\n"],"names":["theme","useState","useMemo","createPortal","_jsx","themeVars","isDarkTheme","_jsxs","_Fragment"],"mappings":";;;;;;;AA6BA;;;;;;;;;;;;;AAaG;SACa,cAAc,CAAC,EAC7B,MAAM,EACN,UAAU,EACV,KAAK,EACL,WAAW,EACX,sBAAsB,SACtBA,OAAK,EACL,QAAQ,EACR,QAAQ,GACY,EAAA;AACpB,IAAA,MAAM,MAAM,GAAG,CAAC,MAAM;AACtB,IAAA,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAGC,cAAQ,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC;AACjD,IAAA,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGA,cAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;IACpD,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAGA,cAAQ,CAAC,EAAE,CAAC;IAClC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAGA,cAAQ,CAAC,EAAE,CAAC;IAC5C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAC,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E,UAAU,EAAE,KAAK,EAAA,CAAI,EACzDG,eAAA,CAAA,OAAA,EAAA,EAAO,SAAS,EAAC,wBAAwB,EAAA,QAAA,EAAA,CAAA,uDAAA,EACe,GAAG,EACzDH,cAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,oBAAoB,EAC9B,OAAO,EAAE,MAAK;gEACZ,KAAK,SAAS,CAAC;sEACX,SAAS,CAAC,WAAW;qEACtB,IAAI,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC;AAC1B,qEAAA,KAAK,CAAC,MAAM,SAAS,CAAC;AAC3B,4DAAA,CAAC,YAEA,MAAM,GAAG,QAAQ,GAAG,MAAM,EAAA,CACpB,IACH,CAAA,EAAA,CACF,CACT,IACA,CACJ,CAAA,EAAA,CACG,CACP,CAAA,EAAA,CACG,EAENG,eAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,2BAA2B,EAAA,QAAA,EAAA,CACxCH,2BACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,eAAe,EACzB,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,UAAU,EAAA,QAAA,EAAA,QAAA,EAAA,CAGb,EACTA,cAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,qCAAqC,EAC/C,QAAQ,EAAE,UAAU,YAEnB,UAAU,GAAG,aAAa,GAAG,IAAI,KAAK,OAAO,GAAG,UAAU,GAAG,SAAS,EAAA,CAChE,CAAA,EAAA,CACL,IACD,EAAA,CACH,EACN,QAAQ,CAAC,IAAI,CACd;AACH;;;;"}
1
+ {"version":3,"file":"McpConnectForm.js","sources":["../../../../../src/components/IntegrationsModal/McpConnectForm.tsx"],"sourcesContent":["import { useMemo, useState, type FormEvent, type JSX } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { TenantMcpAuthInput, TenantMcpServer } from \"../../api/types\";\nimport { isDarkTheme, themeVars, type DevicTheme } from \"../theme\";\n\nexport interface McpConnectFormProps {\n /**\n * The server being connected. `null` is the \"add your own\" case, where the\n * url and the name are the end user's to type.\n */\n server: TenantMcpServer | null;\n submitting?: boolean;\n error?: string | null;\n /**\n * The redirect URI the end user must authorise on their own OAuth\n * application, when the server told us it has no dynamic registration.\n */\n callbackUrl?: string;\n /** Open the client-credentials fields already expanded. */\n needsClientCredentials?: boolean;\n theme?: DevicTheme;\n onCancel: () => void;\n onSubmit: (values: {\n url?: string;\n name?: string;\n auth: TenantMcpAuthInput;\n }) => void;\n}\n\n/**\n * What an MCP server asks the end user for.\n *\n * Both ways in end here — a server the developer listed and one the user\n * brings — because the difference between them is only who typed the url.\n * Everything after that is the same question: a key, or a trip to a consent\n * screen.\n *\n * A dialog rather than something inside a card: the OAuth-application fields\n * carry a redirect URI the user has to copy somewhere else, which does not fit\n * in a column of a grid without becoming a stack of clipped text.\n *\n * Values go straight into the connection and are never kept here.\n */\nexport function McpConnectForm({\n server,\n submitting,\n error,\n callbackUrl,\n needsClientCredentials,\n theme,\n onCancel,\n onSubmit,\n}: McpConnectFormProps): JSX.Element {\n const custom = !server;\n const [url, setUrl] = useState(server?.url ?? \"\");\n const [name, setName] = useState(server?.name ?? \"\");\n const [key, setKey] = useState(\"\");\n const [clientId, setClientId] = useState(\"\");\n const [clientSecret, setClientSecret] = useState(\"\");\n const [showClient, setShowClient] = useState(!!needsClientCredentials);\n const [copied, setCopied] = useState(false);\n const [touched, setTouched] = useState(false);\n\n // A server the user brings could be anything, so the form offers both ways\n // and lets them say. One the developer listed already declared how it\n // authenticates, and asking again would only invite a wrong answer.\n const [mode, setMode] = useState<TenantMcpAuthInput[\"mode\"]>(\n server?.authMode ?? \"oauth\"\n );\n\n const headerLabel = server?.headerName\n ? `${server.headerName} value`\n : \"API key\";\n\n const urlInvalid = useMemo(\n () => custom && touched && !/^https:\\/\\/.+/i.test(url.trim()),\n [custom, touched, url]\n );\n const keyInvalid = touched && mode === \"header\" && !key.trim();\n\n const handleSubmit = (event: FormEvent) => {\n event.preventDefault();\n setTouched(true);\n if (submitting) return;\n if (custom && !/^https:\\/\\/.+/i.test(url.trim())) return;\n if (mode === \"header\" && !key.trim()) return;\n\n onSubmit({\n url: custom ? url.trim() : undefined,\n name: name.trim() || undefined,\n auth: {\n mode,\n headerValue: mode === \"header\" ? key.trim() : undefined,\n upstreamOAuth:\n mode === \"oauth\" && clientId.trim()\n ? {\n clientId: clientId.trim(),\n clientSecret: clientSecret.trim() || undefined,\n }\n : undefined,\n },\n });\n };\n\n const title = custom ? \"Add an MCP server\" : `Connect ${server.name}`;\n\n return createPortal(\n <div\n className=\"devic-int-overlay devic-int-overlay-stacked\"\n style={themeVars(theme)}\n data-dark={isDarkTheme(theme)}\n onClick={onCancel}\n >\n <form\n className=\"devic-int-connect-dialog\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n onClick={(e) => e.stopPropagation()}\n onSubmit={handleSubmit}\n >\n <div className=\"devic-int-connect-header\">\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 ?? \"M\").slice(0, 1).toUpperCase()}\n </span>\n )}\n <div className=\"devic-int-connect-heading\">\n <strong>{title}</strong>\n <span>\n {mode === \"oauth\"\n ? \"You'll be sent to the server to finish authorising.\"\n : mode === \"header\"\n ? \"Your key goes straight to the server — only you can use it.\"\n : \"This server needs no credentials.\"}\n </span>\n </div>\n <button\n type=\"button\"\n className=\"devic-int-close\"\n onClick={onCancel}\n aria-label=\"Close\"\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-int-connect-body\">\n {error && <div className=\"devic-int-error\">{error}</div>}\n\n {custom && (\n <>\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">Server URL</span>\n <input\n autoFocus\n type=\"url\"\n value={url}\n onChange={(e) => setUrl(e.target.value)}\n placeholder=\"https://mcp.example.com/sse\"\n spellCheck={false}\n autoComplete=\"off\"\n aria-invalid={urlInvalid || undefined}\n data-invalid={urlInvalid || undefined}\n />\n <small className=\"devic-int-connect-hint\">\n Must be reachable over https on a public address.\n </small>\n </label>\n\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Name <em>(optional)</em>\n </span>\n <input\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder=\"What you want to call it\"\n autoComplete=\"off\"\n />\n </label>\n\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">Authentication</span>\n <select\n value={mode}\n onChange={(e) =>\n setMode(e.target.value as TenantMcpAuthInput[\"mode\"])\n }\n >\n <option value=\"oauth\">Sign in (OAuth)</option>\n <option value=\"header\">API key</option>\n <option value=\"none\">None</option>\n </select>\n </label>\n </>\n )}\n\n {mode === \"header\" && (\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">{headerLabel}</span>\n <input\n autoFocus={!custom}\n type=\"password\"\n value={key}\n onChange={(e) => setKey(e.target.value)}\n autoComplete=\"new-password\"\n spellCheck={false}\n aria-invalid={keyInvalid || undefined}\n data-invalid={keyInvalid || undefined}\n />\n </label>\n )}\n\n {mode === \"oauth\" && (custom || server?.allowClientCredentials) && (\n <div className=\"devic-int-mcp-advanced\">\n {/* Not a detail to bury: a server whose authorization server has\n no dynamic client registration cannot be connected at all\n without these, and the message that says so arrives only\n after the first attempt. */}\n {needsClientCredentials && (\n <div className=\"devic-int-notice\">\n This server needs its own OAuth application. Register one with\n it and paste the details below.\n </div>\n )}\n <button\n type=\"button\"\n className=\"devic-int-mcp-disclosure\"\n onClick={() => setShowClient((prev) => !prev)}\n aria-expanded={showClient}\n >\n {showClient ? \"▾\" : \"▸\"} Use my own OAuth application\n </button>\n\n {showClient && (\n <>\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Client ID <em>(optional)</em>\n </span>\n <input\n type=\"text\"\n value={clientId}\n onChange={(e) => setClientId(e.target.value)}\n autoComplete=\"off\"\n spellCheck={false}\n />\n </label>\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Client secret <em>(optional)</em>\n </span>\n <input\n type=\"password\"\n value={clientSecret}\n onChange={(e) => setClientSecret(e.target.value)}\n autoComplete=\"new-password\"\n spellCheck={false}\n />\n </label>\n {callbackUrl && (\n <label className=\"devic-int-connect-field\">\n <span className=\"devic-int-connect-label\">\n Authorised redirect URI\n </span>\n <input readOnly value={callbackUrl} spellCheck={false} />\n <small className=\"devic-int-connect-hint\">\n Add this to your OAuth application, exactly as shown.{\" \"}\n <button\n type=\"button\"\n className=\"devic-int-mcp-copy\"\n onClick={() => {\n void navigator.clipboard\n ?.writeText(callbackUrl)\n .then(() => setCopied(true))\n .catch(() => undefined);\n }}\n >\n {copied ? \"Copied\" : \"Copy\"}\n </button>\n </small>\n </label>\n )}\n </>\n )}\n </div>\n )}\n </div>\n\n <div className=\"devic-int-connect-actions\">\n <button\n type=\"button\"\n className=\"devic-int-btn\"\n onClick={onCancel}\n disabled={submitting}\n >\n Cancel\n </button>\n <button\n type=\"submit\"\n className=\"devic-int-btn devic-int-btn-primary\"\n disabled={submitting}\n >\n {submitting ? \"Connecting…\" : mode === \"oauth\" ? \"Continue\" : \"Connect\"}\n </button>\n </div>\n </form>\n </div>,\n document.body\n );\n}\n\nexport default McpConnectForm;\n"],"names":["theme","useState","useMemo","createPortal","_jsx","themeVars","isDarkTheme","_jsxs","_Fragment"],"mappings":";;;;;;;AA6BA;;;;;;;;;;;;;AAaG;SACa,cAAc,CAAC,EAC7B,MAAM,EACN,UAAU,EACV,KAAK,EACL,WAAW,EACX,sBAAsB,SACtBA,OAAK,EACL,QAAQ,EACR,QAAQ,GACY,EAAA;AACpB,IAAA,MAAM,MAAM,GAAG,CAAC,MAAM;AACtB,IAAA,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAGC,cAAQ,CAAC,MAAM,EAAE,GAA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OAAO,GAAG,UAAU,GAAG,SAAS,EAAA,CAChE,CAAA,EAAA,CACL,IACD,EAAA,CACH,EACN,QAAQ,CAAC,IAAI,CACd;AACH;;"}
@@ -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,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,CAAC,CAAA,CAAA,EAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA,CAAE;AAC5E;AAEA,SAAS,OAAO,CAAC,MAAuB,EAAA;AAItC,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM;IACxC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE;IACxE,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE;IAC7E,IAAI,MAAM,KAAK,cAAc;QAC3B,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,qBAAqB,EAAE;IAC3D,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE;AACxD;AAEA,SAAS,OAAO,CAAC,MAAuB,EAAE,KAAa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AAC,EAAA,CACE,CACP,EAEA,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,CAAA,aAAA,EAAgB,MAAM,CAAC,UAAU,CAAA,WAAA,EAC/B,MAAM,CAAC,UAAU,KAAK,CAAC,GAAG,EAAE,GAAG,GACjC,CAAA,qBAAA;AACF,sBAAE,SAAS,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\";\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,GAAG,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,GAAG,SAAS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AM,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;;"}
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var index = require('../../utils/index.js');
4
+
5
+ /**
6
+ * What the end user switched off, remembered between visits.
7
+ *
8
+ * Held in the browser and nowhere else: it is a preference of whoever is at
9
+ * this keyboard, not of the tenant, and the server deliberately keeps nothing
10
+ * beyond the turn it was sent for.
11
+ *
12
+ * The key names the assistant AND the tenant it was made under, because a
13
+ * choice about one end user's Gmail means nothing to the next one — and a
14
+ * widget that switched an app off for a colleague who happens to share a
15
+ * browser profile would be a bug with a very long tail.
16
+ */
17
+ const PREFIX = "devic:integrations:off";
18
+ function integrationChoiceKey(assistantId, tenantId, subtenantId) {
19
+ return `${PREFIX}:${assistantId}:${tenantId ?? ""}:${subtenantId ?? ""}`;
20
+ }
21
+ /** Reads the remembered list, tolerating anything that is not one. */
22
+ function readIntegrationChoice(key) {
23
+ const stored = index.storage.get(key);
24
+ if (!Array.isArray(stored))
25
+ return [];
26
+ return stored.filter((id) => typeof id === "string" && !!id);
27
+ }
28
+ function writeIntegrationChoice(key, disabled) {
29
+ // An empty list is the default, and leaving a `[]` behind in every visitor's
30
+ // storage for every assistant they ever opened is litter.
31
+ if (disabled.length === 0)
32
+ index.storage.remove(key);
33
+ else
34
+ index.storage.set(key, disabled);
35
+ }
36
+ /**
37
+ * Drops what is no longer on offer.
38
+ *
39
+ * Without this, remembering the choice would quietly reintroduce the bug the
40
+ * switch was written to avoid: disconnect an app, connect it again months
41
+ * later, and find it switched off for reasons nobody can reconstruct. The same
42
+ * goes for an MCP server the tenant removed.
43
+ *
44
+ * Returns the SAME array when nothing was stale, so a caller can use identity
45
+ * to avoid a pointless render.
46
+ */
47
+ function pruneIntegrationChoice(disabled, liveIds) {
48
+ if (disabled.length === 0)
49
+ return disabled;
50
+ const live = new Set(liveIds);
51
+ const next = disabled.filter((id) => live.has(id));
52
+ return next.length === disabled.length ? disabled : next;
53
+ }
54
+
55
+ exports.integrationChoiceKey = integrationChoiceKey;
56
+ exports.pruneIntegrationChoice = pruneIntegrationChoice;
57
+ exports.readIntegrationChoice = readIntegrationChoice;
58
+ exports.writeIntegrationChoice = writeIntegrationChoice;
59
+ //# sourceMappingURL=integrationChoice.js.map
@@ -0,0 +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 +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;A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AAK,CAAC,WAAW,CAAA,CAAA,EAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,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;;;;"}
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,E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CAAC;QAClB;AACF,IAAA,CAAC,EACD,CAACA,QAAM,EAAE,KAAK,CAAC,CAChB;;;;;AAMD,IAAA,MAAM,GAAG,GAAG,CAAA,EAAGA,QAAM,GAAG,GAAG,GAAG,GAAG,CAAA,CAAA,EAAI,KAAK,CAAC,WAAW,CAAA,CAAA,EAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,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;;"}
@@ -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,I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;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,UAAU,CAAC,IAAI,CAAC;YAChB,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;AACL,QAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE;QAC/B,OAAO;QACP,KAAK;;;AAGL,QAAA,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO;AAC3B,QAAA,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,WAAW;AACnC,QAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;QACpC,OAAO;QACP,OAAO;gBACPN,QAAM;QACN,KAAK;KACN;AACH;;;;"}
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,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