@devicai/ui 0.43.0 → 0.45.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 (87) hide show
  1. package/README.md +34 -2
  2. package/dist/cjs/api/client.js +26 -2
  3. package/dist/cjs/api/client.js.map +1 -1
  4. package/dist/cjs/api/types.js.map +1 -1
  5. package/dist/cjs/components/AICommandBar/AICommandBar.js +2 -1
  6. package/dist/cjs/components/AICommandBar/AICommandBar.js.map +1 -1
  7. package/dist/cjs/components/AICommandBar/useAICommandBar.js +3 -2
  8. package/dist/cjs/components/AICommandBar/useAICommandBar.js.map +1 -1
  9. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js +2 -1
  10. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  11. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js +3 -2
  12. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  13. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js +2 -1
  14. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  15. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js +3 -2
  16. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  17. package/dist/cjs/components/ChatDrawer/ChatDrawer.js +3 -2
  18. package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
  19. package/dist/cjs/components/ChatDrawer/ChatMessages.js +4 -4
  20. package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -1
  21. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js +10 -4
  22. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  23. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js +60 -0
  24. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -0
  25. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js +61 -7
  26. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  27. package/dist/cjs/hooks/useDevicChat.js +14 -5
  28. package/dist/cjs/hooks/useDevicChat.js.map +1 -1
  29. package/dist/cjs/hooks/usePolling.js +50 -1
  30. package/dist/cjs/hooks/usePolling.js.map +1 -1
  31. package/dist/cjs/index.js +3 -0
  32. package/dist/cjs/index.js.map +1 -1
  33. package/dist/cjs/provider/DevicProvider.js +3 -1
  34. package/dist/cjs/provider/DevicProvider.js.map +1 -1
  35. package/dist/cjs/styles.css +1 -1
  36. package/dist/esm/api/client.d.ts +31 -3
  37. package/dist/esm/api/client.js +26 -2
  38. package/dist/esm/api/client.js.map +1 -1
  39. package/dist/esm/api/types.d.ts +57 -0
  40. package/dist/esm/api/types.js.map +1 -1
  41. package/dist/esm/components/AICommandBar/AICommandBar.js +2 -1
  42. package/dist/esm/components/AICommandBar/AICommandBar.js.map +1 -1
  43. package/dist/esm/components/AICommandBar/AICommandBar.types.d.ts +7 -0
  44. package/dist/esm/components/AICommandBar/useAICommandBar.d.ts +2 -0
  45. package/dist/esm/components/AICommandBar/useAICommandBar.js +4 -3
  46. package/dist/esm/components/AICommandBar/useAICommandBar.js.map +1 -1
  47. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js +2 -1
  48. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  49. package/dist/esm/components/AIElementWrapper/AIElementWrapper.types.d.ts +7 -0
  50. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.d.ts +2 -0
  51. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js +4 -3
  52. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  53. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js +2 -1
  54. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  55. package/dist/esm/components/AIGenerationButton/AIGenerationButton.types.d.ts +7 -0
  56. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.d.ts +2 -0
  57. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js +4 -3
  58. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  59. package/dist/esm/components/ChatDrawer/ChatDrawer.js +3 -2
  60. package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
  61. package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +15 -0
  62. package/dist/esm/components/ChatDrawer/ChatMessages.d.ts +1 -1
  63. package/dist/esm/components/ChatDrawer/ChatMessages.js +4 -4
  64. package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -1
  65. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.d.ts +7 -1
  66. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js +10 -4
  67. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  68. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.d.ts +29 -0
  69. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js +58 -0
  70. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -0
  71. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js +61 -7
  72. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  73. package/dist/esm/hooks/index.d.ts +1 -1
  74. package/dist/esm/hooks/useDevicChat.d.ts +3 -1
  75. package/dist/esm/hooks/useDevicChat.js +15 -6
  76. package/dist/esm/hooks/useDevicChat.js.map +1 -1
  77. package/dist/esm/hooks/usePolling.d.ts +17 -0
  78. package/dist/esm/hooks/usePolling.js +48 -2
  79. package/dist/esm/hooks/usePolling.js.map +1 -1
  80. package/dist/esm/index.d.ts +2 -2
  81. package/dist/esm/index.js +1 -1
  82. package/dist/esm/provider/DevicProvider.d.ts +1 -1
  83. package/dist/esm/provider/DevicProvider.js +3 -1
  84. package/dist/esm/provider/DevicProvider.js.map +1 -1
  85. package/dist/esm/provider/types.d.ts +22 -0
  86. package/dist/esm/styles.css +1 -1
  87. package/package.json +1 -1
@@ -2,6 +2,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { useState, useMemo, useRef, useEffect, useCallback } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import { isDarkTheme, themeVars } from '../theme.js';
5
+ import { ConnectFieldsForm } from './ConnectFieldsForm.js';
5
6
  import { IntegrationLogo } from './IntegrationLogo.js';
6
7
  import { useIntegrations } from './useIntegrations.js';
7
8
 
@@ -78,6 +79,10 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
78
79
  const [busyApp, setBusyApp] = useState(null);
79
80
  /** Authorization URL surfaced as a link when the popup was blocked. */
80
81
  const [blockedUrl, setBlockedUrl] = useState(null);
82
+ /** The app whose credentials are being asked for, with what the server asked
83
+ * and every way it can be connected. Rendered inside that app's own card,
84
+ * where the user pressed Connect. */
85
+ const [setupPrompt, setSetupPrompt] = useState(null);
81
86
  const [query, setQuery] = useState("");
82
87
  const visible = useMemo(() => integrations.filter((i) => matches(i, query)), [integrations, query]);
83
88
  // Report the listing without making the caller's identity part of the
@@ -96,6 +101,7 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
96
101
  if (isOpen && !wasOpenRef.current) {
97
102
  setBlockedUrl(null);
98
103
  setActionError(null);
104
+ setSetupPrompt(null);
99
105
  setQuery("");
100
106
  // The very first open of an uncontrolled modal is already covered by the
101
107
  // hook switching on; asking again here would double every first open.
@@ -159,19 +165,37 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
159
165
  if (pollRef.current !== null)
160
166
  window.clearInterval(pollRef.current);
161
167
  }, []);
162
- const handleConnect = async (integration) => {
163
- if (!client || busyApp)
168
+ /**
169
+ * Connects an app, asking for credentials only if it needs them.
170
+ *
171
+ * Optimistic: the request goes out first, and the form appears only when the
172
+ * server answers that something is missing. Most apps take an API key rather
173
+ * than an OAuth round trip, so this is the path that used to fail outright.
174
+ */
175
+ const handleConnect = async (integration, values) => {
176
+ if (!client || (busyApp && busyApp !== integration.app))
164
177
  return;
165
178
  setActionError(null);
166
179
  setBlockedUrl(null);
167
180
  setBusyApp(integration.app);
168
181
  const nonce = newNonce();
169
182
  const returnTo = `${window.location.origin}/?devic_oauth=${nonce}`;
170
- // Opened empty inside the click, navigated once the URL is known.
183
+ // Opened empty inside the click, navigated once the URL is known. Both
184
+ // entry points are gestures — the card's button and the form's submit —
185
+ // so this holds on the retry too.
171
186
  const popup = window.open("", "devic-oauth", "width=520,height=680,menubar=no,toolbar=no");
172
187
  try {
173
- const { authorizationUrl } = await client.connectIntegration(integration.app, { ...scope, returnTo });
188
+ const { connected, authorizationUrl } = await client.connectIntegration(integration.app, { ...scope, returnTo, ...values });
189
+ // Nothing to authorise: the key the user typed is the account. Close the
190
+ // window that was opened in case it was needed and re-read the listing.
191
+ if (connected || !authorizationUrl) {
192
+ popup?.close();
193
+ setSetupPrompt(null);
194
+ finishConnect();
195
+ return;
196
+ }
174
197
  pendingRef.current = { app: integration.app, returnTo };
198
+ setSetupPrompt(null);
175
199
  if (popup && !popup.closed) {
176
200
  popupRef.current = popup;
177
201
  popup.location.href = authorizationUrl;
@@ -193,8 +217,38 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
193
217
  catch (err) {
194
218
  popup?.close();
195
219
  pendingRef.current = null;
196
- setActionError(err instanceof Error ? err.message : String(err));
197
220
  setBusyApp(null);
221
+ const setup = err?.setupRequired;
222
+ if (setup) {
223
+ await openSetupForm(integration, setup);
224
+ return;
225
+ }
226
+ setActionError(err instanceof Error ? err.message : String(err));
227
+ }
228
+ };
229
+ /**
230
+ * Opens the credentials form for an app that needs one.
231
+ *
232
+ * `stage: "app"` is not the end user's to fix — it means the developer who
233
+ * embedded this widget has not registered an application with the provider
234
+ * yet. Asking a stranger for someone else's client secret would be both
235
+ * useless and a good way to teach them to hand credentials to a form, so it
236
+ * is reported as unavailable instead.
237
+ */
238
+ const openSetupForm = async (integration, setup) => {
239
+ if (setup.stage === "app") {
240
+ setActionError(`${integration.name} is not available yet — it still needs to be set up ` +
241
+ `by the app's provider.`);
242
+ return;
243
+ }
244
+ try {
245
+ const { schemes } = await client.getIntegrationAuth(integration.app, scope);
246
+ if (!schemes.length)
247
+ throw new Error(setup.message);
248
+ setSetupPrompt({ app: integration.app, setup, schemes });
249
+ }
250
+ catch (err) {
251
+ setActionError(err instanceof Error ? err.message : String(err));
198
252
  }
199
253
  };
200
254
  const handleDisconnect = async (app, account) => {
@@ -225,7 +279,7 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
225
279
  }, children: "Open the authorisation page" }), " ", "and come back \u2014 then use Refresh."] })), loading && integrations.length === 0 ? (jsx("div", { className: "devic-int-loading", children: "Loading apps\u2026" })) : integrations.length === 0 ? (jsx("div", { className: "devic-int-empty", children: "No apps available here yet." })) : visible.length === 0 ? (jsxs("div", { className: "devic-int-empty", children: ["No apps match \u201C", query.trim(), "\u201D."] })) : (jsx("div", { className: "devic-int-grid", children: visible.map((integration) => {
226
280
  const cardState = stateOf(integration);
227
281
  const busy = busyApp === integration.app;
228
- return (jsxs("div", { className: "devic-int-card", "data-state": cardState.key, children: [jsxs("div", { className: "devic-int-card-head", children: [jsx(IntegrationLogo, { integration: integration }), jsxs("span", { className: "devic-int-state", children: [jsx("span", { className: "devic-int-dot", "data-ok": cardState.key === "connected", "data-off": cardState.key === "disconnected", "aria-hidden": "true" }), cardState.label] })] }), jsx("div", { className: "devic-int-name", title: integration.name, children: integration.name }), integration.description && (jsx("div", { className: "devic-int-description", title: integration.description, children: integration.description })), jsx("button", { type: "button", className: `devic-int-btn devic-int-btn-block${cardState.key === "connected"
282
+ return (jsxs("div", { className: "devic-int-card", "data-state": cardState.key, children: [jsxs("div", { className: "devic-int-card-head", children: [jsx(IntegrationLogo, { integration: integration }), jsxs("span", { className: "devic-int-state", children: [jsx("span", { className: "devic-int-dot", "data-ok": cardState.key === "connected", "data-off": cardState.key === "disconnected", "aria-hidden": "true" }), cardState.label] })] }), jsx("div", { className: "devic-int-name", title: integration.name, children: integration.name }), integration.description && (jsx("div", { className: "devic-int-description", title: integration.description, children: integration.description })), setupPrompt?.app === integration.app ? (jsx(ConnectFieldsForm, { integration: integration, schemes: setupPrompt.schemes, initialScheme: setupPrompt.setup.authScheme, onlyFields: setupPrompt.setup.fields, submitting: busy, onCancel: () => setSetupPrompt(null), onSubmit: (values) => handleConnect(integration, values) })) : (jsx("button", { type: "button", className: `devic-int-btn devic-int-btn-block${cardState.key === "connected"
229
283
  ? ""
230
284
  : " devic-int-btn-primary"}`, onClick: () => handleConnect(integration), disabled: busy || !!busyApp, title: cardState.key === "connected"
231
285
  ? "Sign in with a different account. The one connected now is replaced."
@@ -238,7 +292,7 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
238
292
  : // Not "Add account": one account per app is all
239
293
  // the assistant can use, and connecting again
240
294
  // retires the previous one.
241
- "Switch account" }), integration.accounts.length > 0 && (jsx("ul", { className: "devic-int-accounts", children: integration.accounts.map((account) => (jsxs("li", { className: "devic-int-account", children: [jsx("span", { className: "devic-int-dot", "data-ok": !account.needsReconnect, "aria-hidden": "true" }), jsxs("span", { className: "devic-int-account-label", children: [accountLabel(account), account.needsReconnect && (jsxs("span", { className: "devic-int-account-warn", children: [" ", "\u00B7 reconnect required"] }))] }), jsx("button", { type: "button", className: "devic-int-unlink", onClick: () => handleDisconnect(integration.app, account), disabled: !!busyApp, title: "Disconnect this account", "aria-label": `Disconnect ${integration.name}`, children: "\u00D7" })] }, account.id))) }))] }, integration.app));
295
+ "Switch account" })), integration.accounts.length > 0 && (jsx("ul", { className: "devic-int-accounts", children: integration.accounts.map((account) => (jsxs("li", { className: "devic-int-account", children: [jsx("span", { className: "devic-int-dot", "data-ok": !account.needsReconnect, "aria-hidden": "true" }), jsxs("span", { className: "devic-int-account-label", children: [accountLabel(account), account.needsReconnect && (jsxs("span", { className: "devic-int-account-warn", children: [" ", "\u00B7 reconnect required"] }))] }), jsx("button", { type: "button", className: "devic-int-unlink", onClick: () => handleDisconnect(integration.app, account), disabled: !!busyApp, title: "Disconnect this account", "aria-label": `Disconnect ${integration.name}`, children: "\u00D7" })] }, account.id))) }))] }, integration.app));
242
296
  }) }))] }), jsxs("div", { className: "devic-int-footer", children: [jsx("span", { children: "Only you can see and use the accounts you connect here." }), jsx("button", { type: "button", className: "devic-int-btn devic-int-btn-small", onClick: () => void refresh(true), disabled: loading || !!busyApp, children: "Refresh" })] })] }) }), document.body);
243
297
  }
244
298
 
@@ -1 +1 @@
1
- {"version":3,"file":"IntegrationsModal.js","sources":["../../../../src/components/IntegrationsModal/IntegrationsModal.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type JSX,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { Integration, IntegrationAccount } from \"../../api/types\";\nimport { isDarkTheme, themeVars, type DevicTheme } from \"../theme\";\nimport { IntegrationLogo } from \"./IntegrationLogo\";\nimport { useIntegrations, type IntegrationsState } from \"./useIntegrations\";\nimport \"./IntegrationsModal.css\";\n\n/** Message the OAuth callback page posts back to this window when it is done. */\ninterface CallbackMessage {\n source?: string;\n type?: string;\n app?: string;\n status?: string;\n returnTo?: string;\n}\n\nexport interface IntegrationsModalProps {\n /** Whether the modal is visible. */\n isOpen: boolean;\n onClose: () => void;\n /** Assistant whose offered apps are shown. */\n assistantId: string;\n /** Tenant of the end user (falls back to the provider's tenantId). */\n tenantId?: string;\n /** Subtenant of the end user (falls back to the provider's subtenantId). */\n subtenantId?: string;\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 /** Modal title. @default \"Connected apps\" */\n title?: string;\n /** Search field placeholder. @default \"Search connected apps\" */\n searchPlaceholder?: string;\n /** Called after an account is connected or disconnected. */\n onChange?: (integrations: Integration[]) => void;\n /**\n * Colours and font. Same names as the drawer's style options, and the drawer\n * passes its own down — a dialog opening in the default light palette over a\n * themed application is the one thing this must not do.\n */\n theme?: DevicTheme;\n /**\n * Listing loaded elsewhere (see `useIntegrations`). The drawer already has to\n * load it to decide whether its button exists, and passing it down is what\n * keeps opening the modal from asking for the very same thing again.\n */\n state?: IntegrationsState;\n}\n\nfunction PlugIcon(): JSX.Element {\n return (\n <svg\n width=\"16\"\n height=\"16\"\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=\"M12 22v-5\" />\n <path d=\"M9 8V2\" />\n <path d=\"M15 8V2\" />\n <path d=\"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z\" />\n </svg>\n );\n}\n\nfunction SearchIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\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 <circle cx=\"11\" cy=\"11\" r=\"7\" />\n <path d=\"m20 20-3.5-3.5\" />\n </svg>\n );\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\n/** How the card describes an app at a glance. */\nfunction stateOf(integration: Integration): {\n key: \"connected\" | \"reconnect\" | \"disconnected\";\n label: string;\n} {\n if (integration.connected) return { key: \"connected\", label: \"Connected\" };\n if (integration.accounts.some((a) => a.needsReconnect)) {\n return { key: \"reconnect\", label: \"Needs reconnection\" };\n }\n return { key: \"disconnected\", label: \"Not connected\" };\n}\n\nfunction accountLabel(account: IntegrationAccount): string {\n if (!account.connectedAt) return account.status.toLowerCase();\n const when = new Date(account.connectedAt);\n if (Number.isNaN(when.getTime())) return account.status.toLowerCase();\n return `connected ${when.toLocaleDateString()}`;\n}\n\nfunction matches(integration: Integration, query: string): boolean {\n const q = query.trim().toLowerCase();\n if (!q) return true;\n return (\n integration.name.toLowerCase().includes(q) ||\n integration.app.toLowerCase().includes(q) ||\n (integration.description ?? \"\").toLowerCase().includes(q)\n );\n}\n\n/**\n * Modal where the END USER of an application manages their *own* third-party\n * accounts: the apps the developer offered to tenants of this assistant, each\n * with the accounts this tenant has connected, and the buttons to add or\n * remove one.\n *\n * Backed by `/api/v1/tenant-integrations`, which resolves the tenant\n * server-side, so what is listed here is only ever this tenant's — never the\n * workspace-wide accounts an admin connected, and never another tenant's.\n *\n * Connecting opens the provider's consent screen in a popup. The popup is\n * opened empty *before* the request that produces its URL, because browsers\n * only honour `window.open` inside the gesture that triggered it: opening it\n * after the round trip is what gets it blocked. When it is blocked anyway, the\n * URL is offered as a link instead.\n */\nexport function IntegrationsModal({\n isOpen,\n onClose,\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n title = \"Connected apps\",\n searchPlaceholder = \"Search connected apps\",\n onChange,\n theme,\n state,\n}: IntegrationsModalProps): JSX.Element | null {\n // Hooks cannot be skipped, so the fallback is always built and only fetches\n // when nobody handed a listing down.\n const own = useIntegrations({\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n enabled: isOpen && !state,\n });\n const { integrations, loading, error: loadError, refresh, client, scope } =\n state ?? own;\n\n /** Errors from connecting or disconnecting, kept apart from load failures. */\n const [actionError, setActionError] = useState<string | null>(null);\n const error = actionError ?? loadError;\n /** App slug with a connect/disconnect in flight, so only its card is busy. */\n const [busyApp, setBusyApp] = useState<string | null>(null);\n /** Authorization URL surfaced as a link when the popup was blocked. */\n const [blockedUrl, setBlockedUrl] = useState<{ app: string; url: string } | null>(\n null\n );\n const [query, setQuery] = useState(\"\");\n\n const visible = useMemo(\n () => integrations.filter((i) => matches(i, query)),\n [integrations, query]\n );\n\n // Report the listing without making the caller's identity part of the\n // dependency: an inline arrow would fire this on every render.\n const onChangeRef = useRef(onChange);\n onChangeRef.current = onChange;\n useEffect(() => {\n if (integrations.length) onChangeRef.current?.(integrations);\n }, [integrations]);\n\n // Reopening starts clean, and re-reads: accounts may have been connected or\n // revoked elsewhere since the last look.\n const wasOpenRef = useRef(false);\n const openedBeforeRef = useRef(false);\n useEffect(() => {\n if (isOpen && !wasOpenRef.current) {\n setBlockedUrl(null);\n setActionError(null);\n setQuery(\"\");\n // The very first open of an uncontrolled modal is already covered by the\n // hook switching on; asking again here would double every first open.\n if (state || openedBeforeRef.current) void refresh();\n openedBeforeRef.current = true;\n }\n wasOpenRef.current = isOpen;\n // `state.refresh` is stable per scope; re-running on every render of the\n // owner is exactly what this must not do.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n // Escape closes\n useEffect(() => {\n if (!isOpen) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isOpen, onClose]);\n\n /** The round trip currently in flight, if any. */\n const pendingRef = useRef<{ app: string; returnTo: string } | null>(null);\n const popupRef = useRef<Window | null>(null);\n const pollRef = useRef<number | null>(null);\n\n const finishConnect = 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 setBusyApp(null);\n void refresh(true);\n }, [refresh]);\n\n // The callback page tells us it is done. Treat the message as a nudge, never\n // as the result: what is displayed comes from re-reading the server, so a\n // forged message can at worst cause one redundant fetch.\n useEffect(() => {\n if (!isOpen) return;\n const onMessage = (event: MessageEvent) => {\n const data = event.data as CallbackMessage | undefined;\n if (!data || data.source !== \"devic\") return;\n if (data.type !== \"integration-connected\") return;\n const pending = pendingRef.current;\n if (!pending || data.returnTo !== pending.returnTo) return;\n popupRef.current?.close();\n finishConnect();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n }, [isOpen, finishConnect]);\n\n // Stop polling if the modal goes away mid-flow.\n useEffect(\n () => () => {\n if (pollRef.current !== null) window.clearInterval(pollRef.current);\n },\n []\n );\n\n const handleConnect = async (integration: Integration) => {\n if (!client || busyApp) return;\n setActionError(null);\n setBlockedUrl(null);\n setBusyApp(integration.app);\n\n const nonce = newNonce();\n const returnTo = `${window.location.origin}/?devic_oauth=${nonce}`;\n // Opened empty inside the click, navigated once the URL is known.\n const popup = window.open(\n \"\",\n \"devic-oauth\",\n \"width=520,height=680,menubar=no,toolbar=no\"\n );\n\n try {\n const { authorizationUrl } = await client.connectIntegration(\n integration.app,\n { ...scope, returnTo }\n );\n pendingRef.current = { app: integration.app, returnTo };\n if (popup && !popup.closed) {\n popupRef.current = popup;\n popup.location.href = authorizationUrl;\n // The user may close the popup without the callback ever posting back\n // — a cancelled consent screen, or a provider that lands somewhere\n // else. Watching for the close is what keeps the card from staying\n // busy forever.\n pollRef.current = window.setInterval(() => {\n if (popup.closed) finishConnect();\n }, 700);\n } else {\n // Blocked (Safari, in-app browsers, extensions): hand over the URL.\n setBlockedUrl({ app: integration.app, url: authorizationUrl });\n setBusyApp(null);\n }\n } catch (err) {\n popup?.close();\n pendingRef.current = null;\n setActionError(err instanceof Error ? err.message : String(err));\n setBusyApp(null);\n }\n };\n\n const handleDisconnect = async (app: string, account: IntegrationAccount) => {\n if (!client || busyApp) return;\n setBusyApp(app);\n setActionError(null);\n try {\n await client.disconnectIntegration(account.id, scope);\n await refresh(true);\n } catch (err) {\n setActionError(err instanceof Error ? err.message : String(err));\n } finally {\n setBusyApp(null);\n }\n };\n\n if (!isOpen) return null;\n\n return createPortal(\n // The variables go on the overlay, not on the modal: the backdrop is part\n // of the dialog, and a portal inherits nothing from the drawer that opened\n // it.\n <div\n className=\"devic-int-overlay\"\n style={themeVars(theme)}\n data-dark={isDarkTheme(theme)}\n onClick={onClose}\n >\n <div\n className=\"devic-int-modal\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"devic-int-header\">\n <h3 className=\"devic-int-title\">\n <PlugIcon />\n {title}\n </h3>\n <button\n className=\"devic-int-close\"\n onClick={onClose}\n type=\"button\"\n aria-label=\"Close\"\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-int-search\">\n <SearchIcon />\n <input\n type=\"search\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={searchPlaceholder}\n aria-label={searchPlaceholder}\n autoComplete=\"off\"\n />\n </div>\n\n <div className=\"devic-int-body\">\n {error && <div className=\"devic-int-error\">{error}</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 {loading && integrations.length === 0 ? (\n <div className=\"devic-int-loading\">Loading apps…</div>\n ) : integrations.length === 0 ? (\n <div className=\"devic-int-empty\">No apps available here yet.</div>\n ) : visible.length === 0 ? (\n <div className=\"devic-int-empty\">\n No apps match “{query.trim()}”.\n </div>\n ) : (\n <div className=\"devic-int-grid\">\n {visible.map((integration) => {\n const cardState = stateOf(integration);\n const busy = busyApp === integration.app;\n return (\n <div\n key={integration.app}\n className=\"devic-int-card\"\n data-state={cardState.key}\n >\n <div className=\"devic-int-card-head\">\n <IntegrationLogo integration={integration} />\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={integration.name}>\n {integration.name}\n </div>\n\n {integration.description && (\n <div\n className=\"devic-int-description\"\n title={integration.description}\n >\n {integration.description}\n </div>\n )}\n\n <button\n type=\"button\"\n className={`devic-int-btn devic-int-btn-block${\n cardState.key === \"connected\"\n ? \"\"\n : \" devic-int-btn-primary\"\n }`}\n onClick={() => handleConnect(integration)}\n disabled={busy || !!busyApp}\n title={\n cardState.key === \"connected\"\n ? \"Sign in with a different account. The one connected now is replaced.\"\n : undefined\n }\n >\n {busy\n ? \"Waiting…\"\n : cardState.key === \"disconnected\"\n ? \"Connect\"\n : cardState.key === \"reconnect\"\n ? \"Reconnect\"\n : // Not \"Add account\": one account per app is all\n // the assistant can use, and connecting again\n // retires the previous one.\n \"Switch account\"}\n </button>\n\n {integration.accounts.length > 0 && (\n <ul className=\"devic-int-accounts\">\n {integration.accounts.map((account) => (\n <li key={account.id} className=\"devic-int-account\">\n <span\n className=\"devic-int-dot\"\n data-ok={!account.needsReconnect}\n aria-hidden=\"true\"\n />\n <span className=\"devic-int-account-label\">\n {accountLabel(account)}\n {account.needsReconnect && (\n <span className=\"devic-int-account-warn\">\n {\" \"}\n · reconnect required\n </span>\n )}\n </span>\n <button\n type=\"button\"\n className=\"devic-int-unlink\"\n onClick={() =>\n handleDisconnect(integration.app, account)\n }\n disabled={!!busyApp}\n title=\"Disconnect this account\"\n aria-label={`Disconnect ${integration.name}`}\n >\n ×\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n })}\n </div>\n )}\n </div>\n\n <div className=\"devic-int-footer\">\n <span>Only you can see and use the accounts you connect here.</span>\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-small\"\n onClick={() => void refresh(true)}\n disabled={loading || !!busyApp}\n >\n Refresh\n </button>\n </div>\n </div>\n </div>,\n document.body\n );\n}\n\nexport default IntegrationsModal;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;AA0DA,SAAS,QAAQ,GAAA;AACf,IAAA,QACEA,IAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EAC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MAAA,EAAA,EAAM,SAAS,EAAC,wBAAwB,EAAA,QAAA,EAAA,CACrC,GAAG,EAAA,2BAAA,CAAA,EAAA,CAEC,CACR,CAAA,EAAA,CACI,EACPC,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,kBAAkB,EAC5B,OAAO,EAAE,MACP,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,EAE5C,QAAQ,EAAE,CAAC,CAAC,OAAO,EACnB,KAAK,EAAC,yBAAyB,EAAA,YAAA,EACnB,CAAA,WAAA,EAAc,WAAW,CAAC,IAAI,CAAA,CAAE,EAAA,QAAA,EAAA,QAAA,EAAA,CAGrC,CAAA,EAAA,EA1BF,OAAO,CAAC,EAAE,CA2Bd,CACN,CAAC,EAAA,CACC,CACN,CAAA,EAAA,EA1FI,WAAW,CAAC,GAAG,CA2FhB;4BAEV,CAAC,CAAC,GACE,CACP,CAAA,EAAA,CACG,EAEND,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,kBAAkB,EAAA,QAAA,EAAA,CAC/BC,GAAA,CAAA,MAAA,EAAA,EAAA,QAAA,EAAA,yDAAA,EAAA,CAAoE,EACpEA,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mCAAmC,EAC7C,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACjC,QAAQ,EAAE,OAAO,IAAI,CAAC,CAAC,OAAO,EAAA,QAAA,EAAA,SAAA,EAAA,CAGvB,IACL,CAAA,EAAA,CACF,EAAA,CACF,EACN,QAAQ,CAAC,IAAI,CACd;AACH;;;;"}
1
+ {"version":3,"file":"IntegrationsModal.js","sources":["../../../../src/components/IntegrationsModal/IntegrationsModal.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type JSX,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { DevicApiError } from \"../../api/client\";\nimport type {\n Integration,\n IntegrationAccount,\n IntegrationAuthScheme,\n IntegrationSetupRequired,\n} from \"../../api/types\";\nimport { isDarkTheme, themeVars, type DevicTheme } from \"../theme\";\nimport { ConnectFieldsForm } from \"./ConnectFieldsForm\";\nimport { IntegrationLogo } from \"./IntegrationLogo\";\nimport { useIntegrations, type IntegrationsState } from \"./useIntegrations\";\nimport \"./IntegrationsModal.css\";\n\n/** Message the OAuth callback page posts back to this window when it is done. */\ninterface CallbackMessage {\n source?: string;\n type?: string;\n app?: string;\n status?: string;\n returnTo?: string;\n}\n\nexport interface IntegrationsModalProps {\n /** Whether the modal is visible. */\n isOpen: boolean;\n onClose: () => void;\n /** Assistant whose offered apps are shown. */\n assistantId: string;\n /** Tenant of the end user (falls back to the provider's tenantId). */\n tenantId?: string;\n /** Subtenant of the end user (falls back to the provider's subtenantId). */\n subtenantId?: string;\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 /** Modal title. @default \"Connected apps\" */\n title?: string;\n /** Search field placeholder. @default \"Search connected apps\" */\n searchPlaceholder?: string;\n /** Called after an account is connected or disconnected. */\n onChange?: (integrations: Integration[]) => void;\n /**\n * Colours and font. Same names as the drawer's style options, and the drawer\n * passes its own down — a dialog opening in the default light palette over a\n * themed application is the one thing this must not do.\n */\n theme?: DevicTheme;\n /**\n * Listing loaded elsewhere (see `useIntegrations`). The drawer already has to\n * load it to decide whether its button exists, and passing it down is what\n * keeps opening the modal from asking for the very same thing again.\n */\n state?: IntegrationsState;\n}\n\nfunction PlugIcon(): JSX.Element {\n return (\n <svg\n width=\"16\"\n height=\"16\"\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=\"M12 22v-5\" />\n <path d=\"M9 8V2\" />\n <path d=\"M15 8V2\" />\n <path d=\"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z\" />\n </svg>\n );\n}\n\nfunction SearchIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\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 <circle cx=\"11\" cy=\"11\" r=\"7\" />\n <path d=\"m20 20-3.5-3.5\" />\n </svg>\n );\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\n/** How the card describes an app at a glance. */\nfunction stateOf(integration: Integration): {\n key: \"connected\" | \"reconnect\" | \"disconnected\";\n label: string;\n} {\n if (integration.connected) return { key: \"connected\", label: \"Connected\" };\n if (integration.accounts.some((a) => a.needsReconnect)) {\n return { key: \"reconnect\", label: \"Needs reconnection\" };\n }\n return { key: \"disconnected\", label: \"Not connected\" };\n}\n\nfunction accountLabel(account: IntegrationAccount): string {\n if (!account.connectedAt) return account.status.toLowerCase();\n const when = new Date(account.connectedAt);\n if (Number.isNaN(when.getTime())) return account.status.toLowerCase();\n return `connected ${when.toLocaleDateString()}`;\n}\n\nfunction matches(integration: Integration, query: string): boolean {\n const q = query.trim().toLowerCase();\n if (!q) return true;\n return (\n integration.name.toLowerCase().includes(q) ||\n integration.app.toLowerCase().includes(q) ||\n (integration.description ?? \"\").toLowerCase().includes(q)\n );\n}\n\n/**\n * Modal where the END USER of an application manages their *own* third-party\n * accounts: the apps the developer offered to tenants of this assistant, each\n * with the accounts this tenant has connected, and the buttons to add or\n * remove one.\n *\n * Backed by `/api/v1/tenant-integrations`, which resolves the tenant\n * server-side, so what is listed here is only ever this tenant's — never the\n * workspace-wide accounts an admin connected, and never another tenant's.\n *\n * Connecting opens the provider's consent screen in a popup. The popup is\n * opened empty *before* the request that produces its URL, because browsers\n * only honour `window.open` inside the gesture that triggered it: opening it\n * after the round trip is what gets it blocked. When it is blocked anyway, the\n * URL is offered as a link instead.\n */\nexport function IntegrationsModal({\n isOpen,\n onClose,\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n title = \"Connected apps\",\n searchPlaceholder = \"Search connected apps\",\n onChange,\n theme,\n state,\n}: IntegrationsModalProps): JSX.Element | null {\n // Hooks cannot be skipped, so the fallback is always built and only fetches\n // when nobody handed a listing down.\n const own = useIntegrations({\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n enabled: isOpen && !state,\n });\n const { integrations, loading, error: loadError, refresh, client, scope } =\n state ?? own;\n\n /** Errors from connecting or disconnecting, kept apart from load failures. */\n const [actionError, setActionError] = useState<string | null>(null);\n const error = actionError ?? loadError;\n /** App slug with a connect/disconnect in flight, so only its card is busy. */\n const [busyApp, setBusyApp] = useState<string | null>(null);\n /** Authorization URL surfaced as a link when the popup was blocked. */\n const [blockedUrl, setBlockedUrl] = useState<{ app: string; url: string } | null>(\n null\n );\n /** The app whose credentials are being asked for, with what the server asked\n * and every way it can be connected. Rendered inside that app's own card,\n * where the user pressed Connect. */\n const [setupPrompt, setSetupPrompt] = useState<{\n app: string;\n setup: IntegrationSetupRequired;\n schemes: IntegrationAuthScheme[];\n } | null>(null);\n const [query, setQuery] = useState(\"\");\n\n const visible = useMemo(\n () => integrations.filter((i) => matches(i, query)),\n [integrations, query]\n );\n\n // Report the listing without making the caller's identity part of the\n // dependency: an inline arrow would fire this on every render.\n const onChangeRef = useRef(onChange);\n onChangeRef.current = onChange;\n useEffect(() => {\n if (integrations.length) onChangeRef.current?.(integrations);\n }, [integrations]);\n\n // Reopening starts clean, and re-reads: accounts may have been connected or\n // revoked elsewhere since the last look.\n const wasOpenRef = useRef(false);\n const openedBeforeRef = useRef(false);\n useEffect(() => {\n if (isOpen && !wasOpenRef.current) {\n setBlockedUrl(null);\n setActionError(null);\n setSetupPrompt(null);\n setQuery(\"\");\n // The very first open of an uncontrolled modal is already covered by the\n // hook switching on; asking again here would double every first open.\n if (state || openedBeforeRef.current) void refresh();\n openedBeforeRef.current = true;\n }\n wasOpenRef.current = isOpen;\n // `state.refresh` is stable per scope; re-running on every render of the\n // owner is exactly what this must not do.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n // Escape closes\n useEffect(() => {\n if (!isOpen) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isOpen, onClose]);\n\n /** The round trip currently in flight, if any. */\n const pendingRef = useRef<{ app: string; returnTo: string } | null>(null);\n const popupRef = useRef<Window | null>(null);\n const pollRef = useRef<number | null>(null);\n\n const finishConnect = 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 setBusyApp(null);\n void refresh(true);\n }, [refresh]);\n\n // The callback page tells us it is done. Treat the message as a nudge, never\n // as the result: what is displayed comes from re-reading the server, so a\n // forged message can at worst cause one redundant fetch.\n useEffect(() => {\n if (!isOpen) return;\n const onMessage = (event: MessageEvent) => {\n const data = event.data as CallbackMessage | undefined;\n if (!data || data.source !== \"devic\") return;\n if (data.type !== \"integration-connected\") return;\n const pending = pendingRef.current;\n if (!pending || data.returnTo !== pending.returnTo) return;\n popupRef.current?.close();\n finishConnect();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n }, [isOpen, finishConnect]);\n\n // Stop polling if the modal goes away mid-flow.\n useEffect(\n () => () => {\n if (pollRef.current !== null) window.clearInterval(pollRef.current);\n },\n []\n );\n\n /**\n * Connects an app, asking for credentials only if it needs them.\n *\n * Optimistic: the request goes out first, and the form appears only when the\n * server answers that something is missing. Most apps take an API key rather\n * than an OAuth round trip, so this is the path that used to fail outright.\n */\n const handleConnect = async (\n integration: Integration,\n values?: { authScheme: string; accountFields: Record<string, string> }\n ) => {\n if (!client || (busyApp && busyApp !== integration.app)) return;\n setActionError(null);\n setBlockedUrl(null);\n setBusyApp(integration.app);\n\n const nonce = newNonce();\n const returnTo = `${window.location.origin}/?devic_oauth=${nonce}`;\n // Opened empty inside the click, navigated once the URL is known. Both\n // entry points are gestures — the card's button and the form's submit —\n // so this holds on the retry too.\n const popup = window.open(\n \"\",\n \"devic-oauth\",\n \"width=520,height=680,menubar=no,toolbar=no\"\n );\n\n try {\n const { connected, authorizationUrl } = await client.connectIntegration(\n integration.app,\n { ...scope, returnTo, ...values }\n );\n\n // Nothing to authorise: the key the user typed is the account. Close the\n // window that was opened in case it was needed and re-read the listing.\n if (connected || !authorizationUrl) {\n popup?.close();\n setSetupPrompt(null);\n finishConnect();\n return;\n }\n\n pendingRef.current = { app: integration.app, returnTo };\n setSetupPrompt(null);\n if (popup && !popup.closed) {\n popupRef.current = popup;\n popup.location.href = authorizationUrl;\n // The user may close the popup without the callback ever posting back\n // — a cancelled consent screen, or a provider that lands somewhere\n // else. Watching for the close is what keeps the card from staying\n // busy forever.\n pollRef.current = window.setInterval(() => {\n if (popup.closed) finishConnect();\n }, 700);\n } else {\n // Blocked (Safari, in-app browsers, extensions): hand over the URL.\n setBlockedUrl({ app: integration.app, url: authorizationUrl });\n setBusyApp(null);\n }\n } catch (err) {\n popup?.close();\n pendingRef.current = null;\n setBusyApp(null);\n const setup = (err as DevicApiError)?.setupRequired;\n if (setup) {\n await openSetupForm(integration, setup);\n return;\n }\n setActionError(err instanceof Error ? err.message : String(err));\n }\n };\n\n /**\n * Opens the credentials form for an app that needs one.\n *\n * `stage: \"app\"` is not the end user's to fix — it means the developer who\n * embedded this widget has not registered an application with the provider\n * yet. Asking a stranger for someone else's client secret would be both\n * useless and a good way to teach them to hand credentials to a form, so it\n * is reported as unavailable instead.\n */\n const openSetupForm = async (\n integration: Integration,\n setup: IntegrationSetupRequired\n ) => {\n if (setup.stage === \"app\") {\n setActionError(\n `${integration.name} is not available yet — it still needs to be set up ` +\n `by the app's provider.`\n );\n return;\n }\n try {\n const { schemes } = await client!.getIntegrationAuth(\n integration.app,\n scope\n );\n if (!schemes.length) throw new Error(setup.message);\n setSetupPrompt({ app: integration.app, setup, schemes });\n } catch (err) {\n setActionError(err instanceof Error ? err.message : String(err));\n }\n };\n\n const handleDisconnect = async (app: string, account: IntegrationAccount) => {\n if (!client || busyApp) return;\n setBusyApp(app);\n setActionError(null);\n try {\n await client.disconnectIntegration(account.id, scope);\n await refresh(true);\n } catch (err) {\n setActionError(err instanceof Error ? err.message : String(err));\n } finally {\n setBusyApp(null);\n }\n };\n\n if (!isOpen) return null;\n\n return createPortal(\n // The variables go on the overlay, not on the modal: the backdrop is part\n // of the dialog, and a portal inherits nothing from the drawer that opened\n // it.\n <div\n className=\"devic-int-overlay\"\n style={themeVars(theme)}\n data-dark={isDarkTheme(theme)}\n onClick={onClose}\n >\n <div\n className=\"devic-int-modal\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"devic-int-header\">\n <h3 className=\"devic-int-title\">\n <PlugIcon />\n {title}\n </h3>\n <button\n className=\"devic-int-close\"\n onClick={onClose}\n type=\"button\"\n aria-label=\"Close\"\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-int-search\">\n <SearchIcon />\n <input\n type=\"search\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={searchPlaceholder}\n aria-label={searchPlaceholder}\n autoComplete=\"off\"\n />\n </div>\n\n <div className=\"devic-int-body\">\n {error && <div className=\"devic-int-error\">{error}</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 {loading && integrations.length === 0 ? (\n <div className=\"devic-int-loading\">Loading apps…</div>\n ) : integrations.length === 0 ? (\n <div className=\"devic-int-empty\">No apps available here yet.</div>\n ) : visible.length === 0 ? (\n <div className=\"devic-int-empty\">\n No apps match “{query.trim()}”.\n </div>\n ) : (\n <div className=\"devic-int-grid\">\n {visible.map((integration) => {\n const cardState = stateOf(integration);\n const busy = busyApp === integration.app;\n return (\n <div\n key={integration.app}\n className=\"devic-int-card\"\n data-state={cardState.key}\n >\n <div className=\"devic-int-card-head\">\n <IntegrationLogo integration={integration} />\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={integration.name}>\n {integration.name}\n </div>\n\n {integration.description && (\n <div\n className=\"devic-int-description\"\n title={integration.description}\n >\n {integration.description}\n </div>\n )}\n\n {/* The form replaces this app's button rather than opening\n a dialog of its own: it belongs to the card the user\n pressed, and the modal is already a dialog. */}\n {setupPrompt?.app === integration.app ? (\n <ConnectFieldsForm\n integration={integration}\n schemes={setupPrompt.schemes}\n initialScheme={setupPrompt.setup.authScheme}\n onlyFields={setupPrompt.setup.fields}\n submitting={busy}\n onCancel={() => setSetupPrompt(null)}\n onSubmit={(values) => handleConnect(integration, values)}\n />\n ) : (\n <button\n type=\"button\"\n className={`devic-int-btn devic-int-btn-block${\n cardState.key === \"connected\"\n ? \"\"\n : \" devic-int-btn-primary\"\n }`}\n onClick={() => handleConnect(integration)}\n disabled={busy || !!busyApp}\n title={\n cardState.key === \"connected\"\n ? \"Sign in with a different account. The one connected now is replaced.\"\n : undefined\n }\n >\n {busy\n ? \"Waiting…\"\n : cardState.key === \"disconnected\"\n ? \"Connect\"\n : cardState.key === \"reconnect\"\n ? \"Reconnect\"\n : // Not \"Add account\": one account per app is all\n // the assistant can use, and connecting again\n // retires the previous one.\n \"Switch account\"}\n </button>\n )}\n\n {integration.accounts.length > 0 && (\n <ul className=\"devic-int-accounts\">\n {integration.accounts.map((account) => (\n <li key={account.id} className=\"devic-int-account\">\n <span\n className=\"devic-int-dot\"\n data-ok={!account.needsReconnect}\n aria-hidden=\"true\"\n />\n <span className=\"devic-int-account-label\">\n {accountLabel(account)}\n {account.needsReconnect && (\n <span className=\"devic-int-account-warn\">\n {\" \"}\n · reconnect required\n </span>\n )}\n </span>\n <button\n type=\"button\"\n className=\"devic-int-unlink\"\n onClick={() =>\n handleDisconnect(integration.app, account)\n }\n disabled={!!busyApp}\n title=\"Disconnect this account\"\n aria-label={`Disconnect ${integration.name}`}\n >\n ×\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n })}\n </div>\n )}\n </div>\n\n <div className=\"devic-int-footer\">\n <span>Only you can see and use the accounts you connect here.</span>\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-small\"\n onClick={() => void refresh(true)}\n disabled={loading || !!busyApp}\n >\n Refresh\n </button>\n </div>\n </div>\n </div>,\n document.body\n );\n}\n\nexport default IntegrationsModal;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;AAiEA,SAAS,QAAQ,GAAA;AACf,IAAA,QACEA,IAAA,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,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,WAAW,EAAA,CAAG,EACtBA,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,QAAQ,EAAA,CAAG,EACnBA,GAAA,CA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AI,CACd;AACH;;;;"}
@@ -1,6 +1,6 @@
1
1
  export { useDevicChat } from './useDevicChat';
2
2
  export type { UseDevicChatOptions, UseDevicChatResult } from './useDevicChat';
3
- export { usePolling } from './usePolling';
3
+ export { usePolling, resolvePollingInterval, DEFAULT_POLLING_INTERVAL_MS, MIN_POLLING_INTERVAL_MS, } from './usePolling';
4
4
  export type { UsePollingOptions, UsePollingResult } from './usePolling';
5
5
  export { useModelInterface } from './useModelInterface';
6
6
  export type { UseModelInterfaceOptions, UseModelInterfaceResult, PendingWidgetCall, HandleToolCallsResult, } from './useModelInterface';
@@ -49,7 +49,9 @@ export interface UseDevicChatOptions {
49
49
  */
50
50
  modelInterfaceTools?: ModelInterfaceTool[];
51
51
  /**
52
- * Polling interval for async mode (ms)
52
+ * How often (ms) the conversation in progress is polled for new content.
53
+ * Overrides the DevicProvider's `pollingInterval`. Values below 250 ms are
54
+ * clamped.
53
55
  * @default 1000
54
56
  */
55
57
  pollingInterval?: number;
@@ -3,9 +3,15 @@ import 'react/jsx-runtime';
3
3
  import { useOptionalDevicContext } from '../provider/DevicContext.js';
4
4
  import { DevicApiClient, DevicApiError } from '../api/client.js';
5
5
  import { createLogger } from '../utils/logger.js';
6
- import { usePolling } from './usePolling.js';
6
+ import { resolvePollingInterval, usePolling } from './usePolling.js';
7
7
  import { useModelInterface } from './useModelInterface.js';
8
8
 
9
+ /**
10
+ * Cadence for the handoff watch, which only waits for the parent thread to
11
+ * leave `handed_off` and so does not need the main conversation's rhythm.
12
+ * A configured `pollingInterval` still wins over it.
13
+ */
14
+ const DEFAULT_HANDOFF_POLL_INTERVAL_MS = 5000;
9
15
  /**
10
16
  * Main hook for managing chat with a Devic assistant
11
17
  *
@@ -29,7 +35,7 @@ import { useModelInterface } from './useModelInterface.js';
29
35
  * ```
30
36
  */
31
37
  function useDevicChat(options) {
32
- const { assistantId, chatUid: initialChatUid, apiKey: propsApiKey, baseUrl: propsBaseUrl, tenantId, tenantMetadata, subtenantId, subtenantMetadata, tags, enabledTools, modelInterfaceTools = [], pollingInterval = 1000, onMessageSent, onMessageReceived, onToolCall, onError, onChatCreated, onFileUpload, debug: propsDebug, } = options;
38
+ const { assistantId, chatUid: initialChatUid, apiKey: propsApiKey, baseUrl: propsBaseUrl, tenantId, tenantMetadata, subtenantId, subtenantMetadata, tags, enabledTools, modelInterfaceTools = [], pollingInterval: propsPollingInterval, onMessageSent, onMessageReceived, onToolCall, onError, onChatCreated, onFileUpload, debug: propsDebug, } = options;
33
39
  // Get context (may be null if not wrapped in provider)
34
40
  const context = useOptionalDevicContext();
35
41
  // Resolve configuration
@@ -46,6 +52,8 @@ function useDevicChat(options) {
46
52
  };
47
53
  // Provider tags + hook tags, deduped. Per-message tags are merged at send time.
48
54
  const resolvedTags = useMemo(() => Array.from(new Set([...(context?.tags ?? []), ...(tags ?? [])])), [context?.tags, tags]);
55
+ const pollingInterval = resolvePollingInterval(propsPollingInterval, context?.pollingInterval);
56
+ const handoffPollingInterval = resolvePollingInterval(propsPollingInterval, context?.pollingInterval, DEFAULT_HANDOFF_POLL_INTERVAL_MS);
49
57
  const debug = propsDebug ?? context?.debug ?? false;
50
58
  const log = useMemo(() => createLogger(debug), [debug]);
51
59
  const logRef = useRef(log);
@@ -521,8 +529,9 @@ function useDevicChat(options) {
521
529
  setIsLoading(false);
522
530
  }
523
531
  }, [assistantId, resolvedTenantId, resumeFromRealtimeStatus, mergeRecalledMemories]);
524
- // Handoff polling: while handedOff is true, poll the realtime endpoint every 5s
525
- // to detect when the parent thread is no longer in handed_off state.
532
+ // Handoff polling: while handedOff is true, poll the realtime endpoint every
533
+ // 5s (or the configured cadence) to detect when the parent thread is no
534
+ // longer in handed_off state.
526
535
  useEffect(() => {
527
536
  if (!handedOff || !chatUid || !clientRef.current)
528
537
  return;
@@ -544,14 +553,14 @@ function useDevicChat(options) {
544
553
  }
545
554
  catch { }
546
555
  };
547
- handoffPollRef.current = setInterval(pollHandoff, 5000);
556
+ handoffPollRef.current = setInterval(pollHandoff, handoffPollingInterval);
548
557
  return () => {
549
558
  if (handoffPollRef.current) {
550
559
  clearInterval(handoffPollRef.current);
551
560
  handoffPollRef.current = null;
552
561
  }
553
562
  };
554
- }, [handedOff, chatUid, assistantId]);
563
+ }, [handedOff, chatUid, assistantId, handoffPollingInterval]);
555
564
  // Called by HandoffSubagentWidget when the subthread reaches a terminal state
556
565
  const onHandoffCompleted = useCallback(() => {
557
566
  logRef.current.log('[useDevicChat] onHandoffCompleted called');