@mastra/react 1.11.1-alpha.6 → 1.12.0-alpha.11

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 (95) hide show
  1. package/dist/{accumulator-C8kIc450.js → accumulator-BfvVnXJr.js} +1 -2
  2. package/dist/{accumulator-C8kIc450.js.map → accumulator-BfvVnXJr.js.map} +1 -1
  3. package/dist/{accumulator-BQGsraqS.cjs → accumulator-CgLQ_3q3.cjs} +1 -2
  4. package/dist/{accumulator-BQGsraqS.cjs.map → accumulator-CgLQ_3q3.cjs.map} +1 -1
  5. package/dist/agent/hooks.d.ts +9 -0
  6. package/dist/agent/hooks.d.ts.map +1 -1
  7. package/dist/chat/index.cjs +1 -1
  8. package/dist/chat/index.js +1 -2
  9. package/dist/combine-by-ids-D_lp6Dvq.cjs.map +1 -1
  10. package/dist/hooks/agents/index.cjs +2 -2
  11. package/dist/hooks/agents/index.cjs.map +1 -1
  12. package/dist/hooks/agents/index.js +2 -2
  13. package/dist/hooks/agents/index.js.map +1 -1
  14. package/dist/hooks/auth/index.cjs +2 -2
  15. package/dist/hooks/auth/index.cjs.map +1 -1
  16. package/dist/hooks/auth/index.js +2 -2
  17. package/dist/hooks/auth/index.js.map +1 -1
  18. package/dist/hooks/capabilities/index.cjs +1 -1
  19. package/dist/hooks/capabilities/index.cjs.map +1 -1
  20. package/dist/hooks/capabilities/index.js +1 -1
  21. package/dist/hooks/capabilities/index.js.map +1 -1
  22. package/dist/hooks/configuration/index.cjs.map +1 -1
  23. package/dist/hooks/datasets/index.cjs +1 -1
  24. package/dist/hooks/datasets/index.cjs.map +1 -1
  25. package/dist/hooks/datasets/index.js +1 -1
  26. package/dist/hooks/datasets/index.js.map +1 -1
  27. package/dist/hooks/embedders/index.cjs.map +1 -1
  28. package/dist/hooks/experiments/index.cjs.map +1 -1
  29. package/dist/hooks/feedback/index.cjs.map +1 -1
  30. package/dist/hooks/feedback/use-feedback.d.ts +3 -3
  31. package/dist/hooks/llm/index.cjs.map +1 -1
  32. package/dist/hooks/logs/index.cjs.map +1 -1
  33. package/dist/hooks/logs/use-logs.d.ts +3 -3
  34. package/dist/hooks/mcps/index.cjs.map +1 -1
  35. package/dist/hooks/memory/index.cjs +10 -10
  36. package/dist/hooks/memory/index.cjs.map +1 -1
  37. package/dist/hooks/memory/index.js +10 -10
  38. package/dist/hooks/memory/index.js.map +1 -1
  39. package/dist/hooks/metrics/index.cjs +13 -11
  40. package/dist/hooks/metrics/index.cjs.map +1 -1
  41. package/dist/hooks/metrics/index.js +13 -11
  42. package/dist/hooks/metrics/index.js.map +1 -1
  43. package/dist/hooks/processors/index.cjs.map +1 -1
  44. package/dist/hooks/prompt-blocks/index.cjs.map +1 -1
  45. package/dist/hooks/query/index.cjs.map +1 -1
  46. package/dist/hooks/review/index.cjs.map +1 -1
  47. package/dist/hooks/schedules/index.cjs.map +1 -1
  48. package/dist/hooks/scores/index.cjs.map +1 -1
  49. package/dist/hooks/templates/index.cjs +20 -18
  50. package/dist/hooks/templates/index.cjs.map +1 -1
  51. package/dist/hooks/templates/index.js +20 -18
  52. package/dist/hooks/templates/index.js.map +1 -1
  53. package/dist/hooks/tool-providers/index.cjs +1 -1
  54. package/dist/hooks/tool-providers/index.cjs.map +1 -1
  55. package/dist/hooks/tool-providers/index.js +1 -1
  56. package/dist/hooks/tool-providers/index.js.map +1 -1
  57. package/dist/hooks/tools/index.cjs.map +1 -1
  58. package/dist/hooks/traces/index.cjs +6 -5
  59. package/dist/hooks/traces/index.cjs.map +1 -1
  60. package/dist/hooks/traces/index.js +6 -5
  61. package/dist/hooks/traces/index.js.map +1 -1
  62. package/dist/hooks/traces/types.d.ts +1 -0
  63. package/dist/hooks/traces/types.d.ts.map +1 -1
  64. package/dist/hooks/traces/use-traces.d.ts +4 -4
  65. package/dist/hooks/vectors/index.cjs.map +1 -1
  66. package/dist/hooks/voice/index.cjs.map +1 -1
  67. package/dist/hooks/workflows/index.cjs +1 -1
  68. package/dist/hooks/workflows/index.cjs.map +1 -1
  69. package/dist/hooks/workflows/index.js +1 -1
  70. package/dist/hooks/workspace/index.cjs +1 -1
  71. package/dist/hooks/workspace/index.cjs.map +1 -1
  72. package/dist/hooks/workspace/index.js +1 -1
  73. package/dist/hooks/workspace/index.js.map +1 -1
  74. package/dist/{hooks-CIwCEruG.cjs → hooks-B1i-oHae.cjs} +27 -5
  75. package/dist/hooks-B1i-oHae.cjs.map +1 -0
  76. package/dist/{hooks-CbX7Q4A3.js → hooks-CLfMO5cH.js} +27 -5
  77. package/dist/hooks-CLfMO5cH.js.map +1 -0
  78. package/dist/{hooks-_YevKidX.cjs → hooks-D8nOYPUd.cjs} +2 -2
  79. package/dist/hooks-D8nOYPUd.cjs.map +1 -0
  80. package/dist/{hooks-0L0RNfau.js → hooks-NaZLZreZ.js} +2 -2
  81. package/dist/{hooks-0L0RNfau.js.map → hooks-NaZLZreZ.js.map} +1 -1
  82. package/dist/index.cjs +3 -3
  83. package/dist/index.cjs.map +1 -1
  84. package/dist/index.js +3 -3
  85. package/dist/mastra-client-context-DzX3f0RF.cjs.map +1 -1
  86. package/dist/ui/index.cjs +4 -4
  87. package/dist/ui/index.cjs.map +1 -1
  88. package/dist/ui/index.js +3 -3
  89. package/dist/ui/index.js.map +1 -1
  90. package/dist/use-in-view-B6eJO9Zi.cjs.map +1 -1
  91. package/dist/voice-BOtUdMi8.cjs.map +1 -1
  92. package/package.json +4 -4
  93. package/dist/hooks-CIwCEruG.cjs.map +0 -1
  94. package/dist/hooks-CbX7Q4A3.js.map +0 -1
  95. package/dist/hooks-_YevKidX.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useMastraClient","useMastraClient","useCurrentUser","isUnauthenticatedError","useMastraClient","useMastraClient","useMastraClient","useMastraClient","useCurrentUser","isUnauthenticatedError","useMastraClient","useMastraClient","useMastraClient"],"sources":["../../../src/hooks/tool-providers/use-tool-providers.ts","../../../src/hooks/tool-providers/use-all-connections.ts","../../../src/hooks/tool-providers/use-all-provider-tools.ts","../../../src/hooks/tool-providers/use-authorize.ts","../../../src/hooks/tool-providers/use-disconnect-connection.ts","../../../src/hooks/tool-providers/use-existing-connections.ts","../../../src/hooks/tool-providers/use-provider-tools.ts","../../../src/hooks/tool-providers/use-toolkits.ts","../../../src/hooks/tool-providers/use-update-connection.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolProvidersResponse = Awaited<ReturnType<MastraClient['listToolProviders']>>;\n\nexport const useToolProviders = <TData = ToolProvidersResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ToolProvidersResponse, TData> } = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-providers'],\n queryFn: () => client.listToolProviders(),\n ...queryOptions,\n });\n};\n\nexport interface IntegrationTool {\n slug: string;\n name: string;\n description?: string;\n toolkit?: string;\n providerId: string;\n providerName: string;\n}\n\nexport const useAllIntegrationTools = ({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<IntegrationTool[]> } = {}) => {\n const client = useMastraClient();\n const { data: providersData, isLoading: isLoadingProviders } = useToolProviders();\n const providers = providersData?.providers ?? [];\n\n const toolsQuery = useQuery({\n queryKey: ['integration-tools-all', providers.map(p => p.id)],\n queryFn: async () => {\n const results: IntegrationTool[] = [];\n\n for (const provider of providers) {\n const response = await client.getToolProvider(provider.id).listTools();\n for (const tool of response.data) {\n results.push({\n ...tool,\n providerId: provider.id,\n providerName: provider.name,\n });\n }\n }\n\n return results;\n },\n enabled: providers.length > 0,\n ...queryOptions,\n });\n\n return {\n data: toolsQuery.data ?? [],\n isLoading: isLoadingProviders || toolsQuery.isLoading,\n };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\n/**\n * Stale time long enough to avoid refetching on every picker re-render but\n * short enough that an OAuth completion in a sibling tab is reflected\n * promptly (React Query also re-fetches on window focus by default).\n */\nconst STALE_TIME_MS = 30_000;\n\nexport interface UseAllConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage.\n */\n scopeToSelf?: boolean;\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n connections?: MastraQueryOptions<\n Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>\n >;\n };\n}\n\n/**\n * Fans out across every registered ToolProvider and every toolkit it\n * exposes to determine whether the caller has an existing connection for a\n * given `(providerId, toolkit)` pair.\n *\n * Used by the Builder tool picker to gate integration tool rows: if the\n * pair has no connection, the card cannot be selected and surfaces an\n * inline \"Connect\" button instead.\n *\n * Distinct from `useExistingConnections` (per-pair, used by `/integrations`)\n * to keep their query caches independent.\n */\nexport const useAllConnections = ({ scopeToSelf = false, queryOptions }: UseAllConnectionsOptions = {}) => {\n const client = useMastraClient();\n const providersQuery = useToolProviders();\n const providers = useMemo(() => providersQuery.data?.providers ?? [], [providersQuery.data?.providers]);\n\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n // 1. For every provider, list its toolkits.\n const toolkitsQueries = useQueries({\n queries: providers.map(provider => ({\n queryKey: ['tool-integration-services', provider.id],\n queryFn: () => client.getToolProvider(provider.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, toolkit) pairs.\n const pairs = useMemo(() => {\n const out: Array<{ providerId: string; toolkit: string }> = [];\n providers.forEach((provider, idx) => {\n const toolkits = toolkitsQueries[idx]?.data?.data ?? [];\n for (const toolkit of toolkits) {\n out.push({ providerId: provider.id, toolkit: toolkit.slug });\n }\n });\n return out;\n }, [providers, toolkitsQueries]);\n\n // 3. One listConnections call per pair. Include `authorId` in queryKey when\n // self-scoped so the cache is distinct from any unscoped admin reads.\n const connectionsQueries = useQueries({\n queries: pairs.map(pair => ({\n queryKey: scopeToSelf\n ? ['tool-integration-connections-all', pair.providerId, pair.toolkit, callerAuthorId]\n : ['tool-integration-connections-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listConnections({\n toolkit: pair.toolkit,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled: callerReady,\n staleTime: STALE_TIME_MS,\n ...queryOptions?.connections,\n })),\n });\n\n const isLoading =\n providersQuery.isLoading ||\n (scopeToSelf && currentUserQuery.isLoading) ||\n toolkitsQueries.some(q => q.isLoading) ||\n connectionsQueries.some(q => q.isLoading);\n\n // Build a per-pair list of connection summaries so callers can both gate\n // (\"does this row have any connection?\") and auto-pin (\"if exactly one\n // exists, write it into the form on toggle-on\").\n const connectionsByKey = useMemo(() => {\n const map = new Map<string, Array<{ connectionId: string; label?: string | null; status?: string }>>();\n pairs.forEach((pair, idx) => {\n const items = connectionsQueries[idx]?.data?.items ?? [];\n map.set(`${pair.providerId}:${pair.toolkit}`, items);\n });\n return map;\n }, [pairs, connectionsQueries]);\n\n // A toolkit \"has a connection\" only when at least one connection is active.\n // Pending/failed rows don't count — this keeps the card hint in sync with the\n // toolkit row control, which also treats only active connections as usable.\n const hasConnection = useCallback(\n (providerId: string, toolkit: string) =>\n (connectionsByKey.get(`${providerId}:${toolkit}`) ?? []).some(connection => connection.status === 'active'),\n [connectionsByKey],\n );\n\n const getConnections = useCallback(\n (providerId: string, toolkit: string) => connectionsByKey.get(`${providerId}:${toolkit}`) ?? [],\n [connectionsByKey],\n );\n\n return { hasConnection, getConnections, isLoading };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\nexport interface AvailableIntegrationTool {\n providerId: string;\n slug: string;\n toolkit: string;\n name?: string;\n description?: string;\n}\n\n/**\n * Upper bound for a single Composio-style `listTools` call. Composio's SDK has\n * no cursor — only `limit` — so we ask for a large page and fan out per\n * `toolkit` to avoid being truncated when many toolkits are allowlisted.\n */\nconst PER_SERVICE_LIMIT = 500;\n\n/**\n * Returns every tool surfaced by every registered ToolProvider, scoped to\n * the provider's `allowedToolkits`/`allowedTools` filter (enforced\n * server-side). Used to render the full available-tools list inline.\n */\nexport const useAllProviderTools = ({\n queryOptions,\n}: {\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n tools?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>>;\n };\n} = {}) => {\n const client = useMastraClient();\n const integrationsQuery = useToolProviders();\n const integrations = useMemo(() => integrationsQuery.data?.providers ?? [], [integrationsQuery.data?.providers]);\n\n // 1. For every integration, fetch its tool services.\n const serviceQueries = useQueries({\n queries: integrations.map(integration => ({\n queryKey: ['tool-integration-services', integration.id],\n queryFn: () => client.getToolProvider(integration.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, serviceSlug) pairs.\n const servicePairs = useMemo(() => {\n const pairs: Array<{ providerId: string; toolkit: string }> = [];\n integrations.forEach((integration, idx) => {\n const services = serviceQueries[idx]?.data?.data ?? [];\n for (const service of services) {\n pairs.push({ providerId: integration.id, toolkit: service.slug });\n }\n });\n return pairs;\n }, [integrations, serviceQueries]);\n\n // 3. Fan out one tools query per (integration, service).\n const toolsQueries = useQueries({\n queries: servicePairs.map(pair => ({\n queryKey: ['tool-integration-tools-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listTools({ toolkit: pair.toolkit, perPage: PER_SERVICE_LIMIT }),\n ...queryOptions?.tools,\n })),\n });\n\n const isLoading =\n integrationsQuery.isLoading || serviceQueries.some(q => q.isLoading) || toolsQueries.some(q => q.isLoading);\n\n const tools = useMemo<AvailableIntegrationTool[]>(() => {\n const out: AvailableIntegrationTool[] = [];\n servicePairs.forEach((pair, idx) => {\n const items = toolsQueries[idx]?.data?.data ?? [];\n for (const item of items) {\n const toolkit = (item as { toolkit?: string }).toolkit ?? pair.toolkit;\n out.push({\n providerId: pair.providerId,\n slug: item.slug,\n toolkit,\n name: (item as { name?: string }).name,\n description: (item as { description?: string }).description,\n });\n }\n });\n return out;\n }, [servicePairs, toolsQueries]);\n\n return { tools, isLoading };\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface AuthorizeArgs {\n providerId: string;\n toolkit: string;\n /**\n * Existing bucket id when re-authorizing; omit for a brand-new connection.\n * Semantics are provider-opaque; for Composio v1 this is the internal user\n * bucket the new connected account should be created under.\n */\n connectionId?: string;\n /**\n * Provider-specific connection fields collected from the picker (e.g.\n * Confluence subdomain). Forwarded to the server's `authorize` body.\n */\n config?: Record<string, unknown>;\n /**\n * Optional human label to persist on the resulting `tool_integration_connections` row.\n */\n label?: string | null;\n /**\n * Ownership scope of the OAuth bucket. `'per-author'` (default) buckets\n * under the caller's authorId.\n */\n scope?: 'per-author' | 'shared' | 'caller-supplied';\n}\n\nexport interface AuthorizeResult {\n status: 'completed' | 'failed';\n /**\n * The `authId` returned by `authorize`, exposed as `connectionId` because\n * for the v1 Composio adapter it is the `connected_account.id` that the\n * caller persists as `Connection.connectionId`.\n */\n connectionId: string;\n}\n\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 5 * 60_000;\n\nexport interface UseAuthorizeOptions {\n pollIntervalMs?: number;\n timeoutMs?: number;\n openPopup?: (url: string) => Window | null;\n queryOptions?: MastraMutationOptions<AuthorizeResult, AuthorizeArgs>;\n}\n\n/**\n * Drives the OAuth popup + polling loop for a `ToolProvider` provider.\n */\nexport const useAuthorize = (options: UseAuthorizeOptions = {}) => {\n const client = useMastraClient();\n const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const openPopup = options.openPopup ?? ((url: string) => window.open(url, '_blank', 'popup,width=600,height=700'));\n\n return useMutation<AuthorizeResult, Error, AuthorizeArgs>({\n mutationFn: async ({ providerId, toolkit, connectionId, config, label, scope }) => {\n const integration = client.getToolProvider(providerId);\n const normalizedConnectionId = connectionId?.trim();\n const { url, authId } = await integration.authorize({\n toolkit,\n ...(normalizedConnectionId ? { connectionId: normalizedConnectionId } : {}),\n ...(config ? { config } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(scope ? { scope } : {}),\n });\n\n const popup = openPopup(url);\n if (!popup) {\n throw new Error('Popup blocked. Please allow popups for this site.');\n }\n\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n await new Promise(resolve => setTimeout(resolve, pollIntervalMs));\n const { status } = await integration.getAuthStatus(authId);\n if (status === 'completed' || status === 'failed') {\n try {\n popup.close();\n } catch {\n // Cross-origin popups may refuse close(); ignore.\n }\n return { status, connectionId: authId };\n }\n }\n\n try {\n popup.close();\n } catch {\n // ignore\n }\n throw new Error('Authorization timed out');\n },\n ...options.queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface DisconnectConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * When `true`, the server skips the usage check and revokes the\n * connection at the provider before deleting the local row.\n */\n force?: boolean;\n}\n\n/**\n * Calls the provider-side revoke (best-effort) and drops the local\n * `tool_integration_connections` row. Server enforces the soft-vs-force rule.\n */\ntype DisconnectConnectionResponse = Awaited<\n ReturnType<ReturnType<MastraClient['getToolProvider']>['disconnectConnection']>\n>;\n\nexport const useDisconnectConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<DisconnectConnectionResponse, DisconnectConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, force }: DisconnectConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.disconnectConnection(connectionId, force ? { force } : undefined);\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface UseExistingConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage in the picker.\n */\n scopeToSelf?: boolean;\n}\n\ntype ConnectionsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>;\n\n/**\n * Lists existing provider connections for the caller, scoped to a tool\n * service. Powers the \"use existing connection\" path in the picker so\n * authors can pin previously-authorized accounts without re-running OAuth.\n *\n * The connection owner is resolved server-side from the request's auth\n * context. Admin callers receive cross-author rows by default; pass\n * `scopeToSelf: true` to narrow the response to the caller's own bucket\n * (used by the Builder edit view).\n */\nexport const useExistingConnections = <TData = ConnectionsResponse>({\n providerId,\n toolkit,\n scopeToSelf = false,\n queryOptions,\n}: UseExistingConnectionsOptions & {\n providerId: string | null | undefined;\n toolkit: string | null | undefined;\n queryOptions?: MastraQueryOptions<ConnectionsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n const enabled = !!providerId && !!toolkit && callerReady;\n\n return useQuery({\n queryKey: scopeToSelf\n ? ['tool-integration-connections', providerId, toolkit, callerAuthorId]\n : ['tool-integration-connections', providerId, toolkit],\n queryFn: () =>\n client.getToolProvider(providerId!).listConnections({\n toolkit: toolkit!,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ProviderToolsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useProviderTools = <TData = ProviderToolsResponse>({\n providerId,\n params,\n queryOptions,\n}: {\n providerId: string | null;\n params?: { toolkit?: string; search?: string };\n queryOptions?: MastraQueryOptions<ProviderToolsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-tools', providerId, params?.toolkit, params?.search],\n queryFn: () => client.getToolProvider(providerId!).listTools(params),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolkitsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useToolkits = <TData = ToolkitsResponse>({\n providerId,\n queryOptions,\n}: {\n providerId: string | null;\n queryOptions?: MastraQueryOptions<ToolkitsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-toolkits', providerId],\n queryFn: () => client.getToolProvider(providerId!).listToolkits(),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface UpdateConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * New display label. Pass `null` (or an empty string) to clear the label.\n */\n label: string | null;\n}\n\n/**\n * Renames a `tool_provider_connections` row in place. Server enforces\n * ownership (owner / admin / shared scope). On success, invalidates both\n * the per-toolkit and the fan-out connection lists so the picker re-fetches.\n */\ntype UpdateConnectionResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['updateConnection']>>;\n\nexport const useUpdateConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<UpdateConnectionResponse, UpdateConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, label }: UpdateConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.updateConnection(connectionId, { label });\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections-all', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;;;AAQA,MAAa,oBAAmD,EAC9D,iBACuE,CAAC,MAAoC;CAC5G,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU,CAAC,gBAAgB;EAC3B,eAAe,OAAO,kBAAkB;EACxC,GAAG;CACL,CAAC;AACH;AAWA,MAAa,0BAA0B,EACrC,iBAC4D,CAAC,MAAM;CACnE,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,MAAM,EAAE,MAAM,eAAe,WAAW,uBAAuB,iBAAiB;CAChF,MAAM,YAAY,eAAe,aAAa,CAAC;CAE/C,MAAM,cAAA,GAAA,sBAAA,SAAA,CAAsB;EAC1B,UAAU,CAAC,yBAAyB,UAAU,KAAI,MAAK,EAAE,EAAE,CAAC;EAC5D,SAAS,YAAY;GACnB,MAAM,UAA6B,CAAC;GAEpC,KAAK,MAAM,YAAY,WAAW;IAChC,MAAM,WAAW,MAAM,OAAO,gBAAgB,SAAS,EAAE,CAAC,CAAC,UAAU;IACrE,KAAK,MAAM,QAAQ,SAAS,MAC1B,QAAQ,KAAK;KACX,GAAG;KACH,YAAY,SAAS;KACrB,cAAc,SAAS;IACzB,CAAC;GAEL;GAEA,OAAO;EACT;EACA,SAAS,UAAU,SAAS;EAC5B,GAAG;CACL,CAAC;CAED,OAAO;EACL,MAAM,WAAW,QAAQ,CAAC;EAC1B,WAAW,sBAAsB,WAAW;CAC9C;AACF;;;;;;;;AChDA,MAAM,gBAAgB;;;;;;;;;;;;;AAkCtB,MAAa,qBAAqB,EAAE,cAAc,OAAO,iBAA2C,CAAC,MAAM;CACzG,MAAM,SAASC,8BAAAA,g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A0B,UAAU;EAC/C,eAAe,OAAO,gBAAgB,UAAW,CAAC,CAAC,aAAa;EAChE,GAAG;CACL,CAAC;AACH;;;ACJA,MAAa,uBAAuB,EAClC,iBAC4F,CAAC,MAAM;CACnG,MAAM,SAASC,8BAAAA,gBAAgB;CAC/B,MAAM,MAAA,GAAA,sBAAA,eAAA,CAAoB;CAE1B,QAAA,GAAA,sBAAA,YAAA,CAAmB;EACjB,YAAY,OAAO,EAAE,YAAY,cAAc,YAAkC;GAE/E,OADoB,OAAO,gBAAgB,UAC1B,CAAC,CAAC,iBAAiB,cAAc,EAAE,MAAM,CAAC;EAC7D;EACA,YAAY,OAAO,SAAS;GAC1B,GAAQ,kBAAkB,EAAE,UAAU,CAAC,gCAAgC,KAAK,UAAU,EAAE,CAAC;GACzF,GAAQ,kBAAkB,EAAE,UAAU,CAAC,oCAAoC,KAAK,UAAU,EAAE,CAAC;EAC/F;EACA,GAAG;CACL,CAAC;AACH"}
1
+ {"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","useMastraClient","useMemo","useCurrentUser","isUnauthenticatedError","useQueries","useCallback","useMastraClient","useMemo","useQueries","useMastraClient","useMutation","useMastraClient","useQueryClient","useMutation","useMastraClient","useCurrentUser","isUnauthenticatedError","useQuery","useMastraClient","useQuery","useMastraClient","useQuery","useMastraClient","useQueryClient","useMutation"],"sources":["../../../src/hooks/tool-providers/use-tool-providers.ts","../../../src/hooks/tool-providers/use-all-connections.ts","../../../src/hooks/tool-providers/use-all-provider-tools.ts","../../../src/hooks/tool-providers/use-authorize.ts","../../../src/hooks/tool-providers/use-disconnect-connection.ts","../../../src/hooks/tool-providers/use-existing-connections.ts","../../../src/hooks/tool-providers/use-provider-tools.ts","../../../src/hooks/tool-providers/use-toolkits.ts","../../../src/hooks/tool-providers/use-update-connection.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolProvidersResponse = Awaited<ReturnType<MastraClient['listToolProviders']>>;\n\nexport const useToolProviders = <TData = ToolProvidersResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ToolProvidersResponse, TData> } = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-providers'],\n queryFn: () => client.listToolProviders(),\n ...queryOptions,\n });\n};\n\nexport interface IntegrationTool {\n slug: string;\n name: string;\n description?: string;\n toolkit?: string;\n providerId: string;\n providerName: string;\n}\n\nexport const useAllIntegrationTools = ({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<IntegrationTool[]> } = {}) => {\n const client = useMastraClient();\n const { data: providersData, isLoading: isLoadingProviders } = useToolProviders();\n const providers = providersData?.providers ?? [];\n\n const toolsQuery = useQuery({\n queryKey: ['integration-tools-all', providers.map(p => p.id)],\n queryFn: async () => {\n const results: IntegrationTool[] = [];\n\n for (const provider of providers) {\n const response = await client.getToolProvider(provider.id).listTools();\n for (const tool of response.data) {\n results.push({\n ...tool,\n providerId: provider.id,\n providerName: provider.name,\n });\n }\n }\n\n return results;\n },\n enabled: providers.length > 0,\n ...queryOptions,\n });\n\n return {\n data: toolsQuery.data ?? [],\n isLoading: isLoadingProviders || toolsQuery.isLoading,\n };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\n/**\n * Stale time long enough to avoid refetching on every picker re-render but\n * short enough that an OAuth completion in a sibling tab is reflected\n * promptly (React Query also re-fetches on window focus by default).\n */\nconst STALE_TIME_MS = 30_000;\n\nexport interface UseAllConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage.\n */\n scopeToSelf?: boolean;\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n connections?: MastraQueryOptions<\n Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>\n >;\n };\n}\n\n/**\n * Fans out across every registered ToolProvider and every toolkit it\n * exposes to determine whether the caller has an existing connection for a\n * given `(providerId, toolkit)` pair.\n *\n * Used by the Builder tool picker to gate integration tool rows: if the\n * pair has no connection, the card cannot be selected and surfaces an\n * inline \"Connect\" button instead.\n *\n * Distinct from `useExistingConnections` (per-pair, used by `/integrations`)\n * to keep their query caches independent.\n */\nexport const useAllConnections = ({ scopeToSelf = false, queryOptions }: UseAllConnectionsOptions = {}) => {\n const client = useMastraClient();\n const providersQuery = useToolProviders();\n const providers = useMemo(() => providersQuery.data?.providers ?? [], [providersQuery.data?.providers]);\n\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n // 1. For every provider, list its toolkits.\n const toolkitsQueries = useQueries({\n queries: providers.map(provider => ({\n queryKey: ['tool-integration-services', provider.id],\n queryFn: () => client.getToolProvider(provider.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, toolkit) pairs.\n const pairs = useMemo(() => {\n const out: Array<{ providerId: string; toolkit: string }> = [];\n providers.forEach((provider, idx) => {\n const toolkits = toolkitsQueries[idx]?.data?.data ?? [];\n for (const toolkit of toolkits) {\n out.push({ providerId: provider.id, toolkit: toolkit.slug });\n }\n });\n return out;\n }, [providers, toolkitsQueries]);\n\n // 3. One listConnections call per pair. Include `authorId` in queryKey when\n // self-scoped so the cache is distinct from any unscoped admin reads.\n const connectionsQueries = useQueries({\n queries: pairs.map(pair => ({\n queryKey: scopeToSelf\n ? ['tool-integration-connections-all', pair.providerId, pair.toolkit, callerAuthorId]\n : ['tool-integration-connections-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listConnections({\n toolkit: pair.toolkit,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled: callerReady,\n staleTime: STALE_TIME_MS,\n ...queryOptions?.connections,\n })),\n });\n\n const isLoading =\n providersQuery.isLoading ||\n (scopeToSelf && currentUserQuery.isLoading) ||\n toolkitsQueries.some(q => q.isLoading) ||\n connectionsQueries.some(q => q.isLoading);\n\n // Build a per-pair list of connection summaries so callers can both gate\n // (\"does this row have any connection?\") and auto-pin (\"if exactly one\n // exists, write it into the form on toggle-on\").\n const connectionsByKey = useMemo(() => {\n const map = new Map<string, Array<{ connectionId: string; label?: string | null; status?: string }>>();\n pairs.forEach((pair, idx) => {\n const items = connectionsQueries[idx]?.data?.items ?? [];\n map.set(`${pair.providerId}:${pair.toolkit}`, items);\n });\n return map;\n }, [pairs, connectionsQueries]);\n\n // A toolkit \"has a connection\" only when at least one connection is active.\n // Pending/failed rows don't count — this keeps the card hint in sync with the\n // toolkit row control, which also treats only active connections as usable.\n const hasConnection = useCallback(\n (providerId: string, toolkit: string) =>\n (connectionsByKey.get(`${providerId}:${toolkit}`) ?? []).some(connection => connection.status === 'active'),\n [connectionsByKey],\n );\n\n const getConnections = useCallback(\n (providerId: string, toolkit: string) => connectionsByKey.get(`${providerId}:${toolkit}`) ?? [],\n [connectionsByKey],\n );\n\n return { hasConnection, getConnections, isLoading };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\nexport interface AvailableIntegrationTool {\n providerId: string;\n slug: string;\n toolkit: string;\n name?: string;\n description?: string;\n}\n\n/**\n * Upper bound for a single Composio-style `listTools` call. Composio's SDK has\n * no cursor — only `limit` — so we ask for a large page and fan out per\n * `toolkit` to avoid being truncated when many toolkits are allowlisted.\n */\nconst PER_SERVICE_LIMIT = 500;\n\n/**\n * Returns every tool surfaced by every registered ToolProvider, scoped to\n * the provider's `allowedToolkits`/`allowedTools` filter (enforced\n * server-side). Used to render the full available-tools list inline.\n */\nexport const useAllProviderTools = ({\n queryOptions,\n}: {\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n tools?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>>;\n };\n} = {}) => {\n const client = useMastraClient();\n const integrationsQuery = useToolProviders();\n const integrations = useMemo(() => integrationsQuery.data?.providers ?? [], [integrationsQuery.data?.providers]);\n\n // 1. For every integration, fetch its tool services.\n const serviceQueries = useQueries({\n queries: integrations.map(integration => ({\n queryKey: ['tool-integration-services', integration.id],\n queryFn: () => client.getToolProvider(integration.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, serviceSlug) pairs.\n const servicePairs = useMemo(() => {\n const pairs: Array<{ providerId: string; toolkit: string }> = [];\n integrations.forEach((integration, idx) => {\n const services = serviceQueries[idx]?.data?.data ?? [];\n for (const service of services) {\n pairs.push({ providerId: integration.id, toolkit: service.slug });\n }\n });\n return pairs;\n }, [integrations, serviceQueries]);\n\n // 3. Fan out one tools query per (integration, service).\n const toolsQueries = useQueries({\n queries: servicePairs.map(pair => ({\n queryKey: ['tool-integration-tools-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listTools({ toolkit: pair.toolkit, perPage: PER_SERVICE_LIMIT }),\n ...queryOptions?.tools,\n })),\n });\n\n const isLoading =\n integrationsQuery.isLoading || serviceQueries.some(q => q.isLoading) || toolsQueries.some(q => q.isLoading);\n\n const tools = useMemo<AvailableIntegrationTool[]>(() => {\n const out: AvailableIntegrationTool[] = [];\n servicePairs.forEach((pair, idx) => {\n const items = toolsQueries[idx]?.data?.data ?? [];\n for (const item of items) {\n const toolkit = (item as { toolkit?: string }).toolkit ?? pair.toolkit;\n out.push({\n providerId: pair.providerId,\n slug: item.slug,\n toolkit,\n name: (item as { name?: string }).name,\n description: (item as { description?: string }).description,\n });\n }\n });\n return out;\n }, [servicePairs, toolsQueries]);\n\n return { tools, isLoading };\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface AuthorizeArgs {\n providerId: string;\n toolkit: string;\n /**\n * Existing bucket id when re-authorizing; omit for a brand-new connection.\n * Semantics are provider-opaque; for Composio v1 this is the internal user\n * bucket the new connected account should be created under.\n */\n connectionId?: string;\n /**\n * Provider-specific connection fields collected from the picker (e.g.\n * Confluence subdomain). Forwarded to the server's `authorize` body.\n */\n config?: Record<string, unknown>;\n /**\n * Optional human label to persist on the resulting `tool_integration_connections` row.\n */\n label?: string | null;\n /**\n * Ownership scope of the OAuth bucket. `'per-author'` (default) buckets\n * under the caller's authorId.\n */\n scope?: 'per-author' | 'shared' | 'caller-supplied';\n}\n\nexport interface AuthorizeResult {\n status: 'completed' | 'failed';\n /**\n * The `authId` returned by `authorize`, exposed as `connectionId` because\n * for the v1 Composio adapter it is the `connected_account.id` that the\n * caller persists as `Connection.connectionId`.\n */\n connectionId: string;\n}\n\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 5 * 60_000;\n\nexport interface UseAuthorizeOptions {\n pollIntervalMs?: number;\n timeoutMs?: number;\n openPopup?: (url: string) => Window | null;\n queryOptions?: MastraMutationOptions<AuthorizeResult, AuthorizeArgs>;\n}\n\n/**\n * Drives the OAuth popup + polling loop for a `ToolProvider` provider.\n */\nexport const useAuthorize = (options: UseAuthorizeOptions = {}) => {\n const client = useMastraClient();\n const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const openPopup = options.openPopup ?? ((url: string) => window.open(url, '_blank', 'popup,width=600,height=700'));\n\n return useMutation<AuthorizeResult, Error, AuthorizeArgs>({\n mutationFn: async ({ providerId, toolkit, connectionId, config, label, scope }) => {\n const integration = client.getToolProvider(providerId);\n const normalizedConnectionId = connectionId?.trim();\n const { url, authId } = await integration.authorize({\n toolkit,\n ...(normalizedConnectionId ? { connectionId: normalizedConnectionId } : {}),\n ...(config ? { config } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(scope ? { scope } : {}),\n });\n\n const popup = openPopup(url);\n if (!popup) {\n throw new Error('Popup blocked. Please allow popups for this site.');\n }\n\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n await new Promise(resolve => setTimeout(resolve, pollIntervalMs));\n const { status } = await integration.getAuthStatus(authId);\n if (status === 'completed' || status === 'failed') {\n try {\n popup.close();\n } catch {\n // Cross-origin popups may refuse close(); ignore.\n }\n return { status, connectionId: authId };\n }\n }\n\n try {\n popup.close();\n } catch {\n // ignore\n }\n throw new Error('Authorization timed out');\n },\n ...options.queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface DisconnectConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * When `true`, the server skips the usage check and revokes the\n * connection at the provider before deleting the local row.\n */\n force?: boolean;\n}\n\n/**\n * Calls the provider-side revoke (best-effort) and drops the local\n * `tool_integration_connections` row. Server enforces the soft-vs-force rule.\n */\ntype DisconnectConnectionResponse = Awaited<\n ReturnType<ReturnType<MastraClient['getToolProvider']>['disconnectConnection']>\n>;\n\nexport const useDisconnectConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<DisconnectConnectionResponse, DisconnectConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, force }: DisconnectConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.disconnectConnection(connectionId, force ? { force } : undefined);\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface UseExistingConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage in the picker.\n */\n scopeToSelf?: boolean;\n}\n\ntype ConnectionsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>;\n\n/**\n * Lists existing provider connections for the caller, scoped to a tool\n * service. Powers the \"use existing connection\" path in the picker so\n * authors can pin previously-authorized accounts without re-running OAuth.\n *\n * The connection owner is resolved server-side from the request's auth\n * context. Admin callers receive cross-author rows by default; pass\n * `scopeToSelf: true` to narrow the response to the caller's own bucket\n * (used by the Builder edit view).\n */\nexport const useExistingConnections = <TData = ConnectionsResponse>({\n providerId,\n toolkit,\n scopeToSelf = false,\n queryOptions,\n}: UseExistingConnectionsOptions & {\n providerId: string | null | undefined;\n toolkit: string | null | undefined;\n queryOptions?: MastraQueryOptions<ConnectionsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n const enabled = !!providerId && !!toolkit && callerReady;\n\n return useQuery({\n queryKey: scopeToSelf\n ? ['tool-integration-connections', providerId, toolkit, callerAuthorId]\n : ['tool-integration-connections', providerId, toolkit],\n queryFn: () =>\n client.getToolProvider(providerId!).listConnections({\n toolkit: toolkit!,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ProviderToolsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useProviderTools = <TData = ProviderToolsResponse>({\n providerId,\n params,\n queryOptions,\n}: {\n providerId: string | null;\n params?: { toolkit?: string; search?: string };\n queryOptions?: MastraQueryOptions<ProviderToolsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-tools', providerId, params?.toolkit, params?.search],\n queryFn: () => client.getToolProvider(providerId!).listTools(params),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolkitsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useToolkits = <TData = ToolkitsResponse>({\n providerId,\n queryOptions,\n}: {\n providerId: string | null;\n queryOptions?: MastraQueryOptions<ToolkitsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-toolkits', providerId],\n queryFn: () => client.getToolProvider(providerId!).listToolkits(),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface UpdateConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * New display label. Pass `null` (or an empty string) to clear the label.\n */\n label: string | null;\n}\n\n/**\n * Renames a `tool_provider_connections` row in place. Server enforces\n * ownership (owner / admin / shared scope). On success, invalidates both\n * the per-toolkit and the fan-out connection lists so the picker re-fetches.\n */\ntype UpdateConnectionResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['updateConnection']>>;\n\nexport const useUpdateConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<UpdateConnectionResponse, UpdateConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, label }: UpdateConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.updateConnection(connectionId, { label });\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections-all', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;;;AAQA,MAAa,oBAAmD,EAC9D,iBACuE,CAAC,MAAoC;CAC5G,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CA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EAAE,YAAY,cAAc,YAAkC;GAE/E,OADoB,OAAO,gBAAgB,UAC1B,CAAC,CAAC,iBAAiB,cAAc,EAAE,MAAM,CAAC;EAC7D;EACA,YAAY,OAAO,SAAS;GAC1B,GAAQ,kBAAkB,EAAE,UAAU,CAAC,gCAAgC,KAAK,UAAU,EAAE,CAAC;GACzF,GAAQ,kBAAkB,EAAE,UAAU,CAAC,oCAAoC,KAAK,UAAU,EAAE,CAAC;EAC/F;EACA,GAAG;CACL,CAAC;AACH"}
@@ -184,7 +184,7 @@ const useAllProviderTools = ({ queryOptions } = {}) => {
184
184
  //#endregion
185
185
  //#region src/hooks/tool-providers/use-authorize.ts
186
186
  const DEFAULT_POLL_INTERVAL_MS = 2e3;
187
- const DEFAULT_TIMEOUT_MS = 5 * 6e4;
187
+ const DEFAULT_TIMEOUT_MS = 3e5;
188
188
  /**
189
189
  * Drives the OAuth popup + polling loop for a `ToolProvider` provider.
190
190
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/tool-providers/use-tool-providers.ts","../../../src/hooks/tool-providers/use-all-connections.ts","../../../src/hooks/tool-providers/use-all-provider-tools.ts","../../../src/hooks/tool-providers/use-authorize.ts","../../../src/hooks/tool-providers/use-disconnect-connection.ts","../../../src/hooks/tool-providers/use-existing-connections.ts","../../../src/hooks/tool-providers/use-provider-tools.ts","../../../src/hooks/tool-providers/use-toolkits.ts","../../../src/hooks/tool-providers/use-update-connection.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolProvidersResponse = Awaited<ReturnType<MastraClient['listToolProviders']>>;\n\nexport const useToolProviders = <TData = ToolProvidersResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ToolProvidersResponse, TData> } = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-providers'],\n queryFn: () => client.listToolProviders(),\n ...queryOptions,\n });\n};\n\nexport interface IntegrationTool {\n slug: string;\n name: string;\n description?: string;\n toolkit?: string;\n providerId: string;\n providerName: string;\n}\n\nexport const useAllIntegrationTools = ({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<IntegrationTool[]> } = {}) => {\n const client = useMastraClient();\n const { data: providersData, isLoading: isLoadingProviders } = useToolProviders();\n const providers = providersData?.providers ?? [];\n\n const toolsQuery = useQuery({\n queryKey: ['integration-tools-all', providers.map(p => p.id)],\n queryFn: async () => {\n const results: IntegrationTool[] = [];\n\n for (const provider of providers) {\n const response = await client.getToolProvider(provider.id).listTools();\n for (const tool of response.data) {\n results.push({\n ...tool,\n providerId: provider.id,\n providerName: provider.name,\n });\n }\n }\n\n return results;\n },\n enabled: providers.length > 0,\n ...queryOptions,\n });\n\n return {\n data: toolsQuery.data ?? [],\n isLoading: isLoadingProviders || toolsQuery.isLoading,\n };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\n/**\n * Stale time long enough to avoid refetching on every picker re-render but\n * short enough that an OAuth completion in a sibling tab is reflected\n * promptly (React Query also re-fetches on window focus by default).\n */\nconst STALE_TIME_MS = 30_000;\n\nexport interface UseAllConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage.\n */\n scopeToSelf?: boolean;\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n connections?: MastraQueryOptions<\n Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>\n >;\n };\n}\n\n/**\n * Fans out across every registered ToolProvider and every toolkit it\n * exposes to determine whether the caller has an existing connection for a\n * given `(providerId, toolkit)` pair.\n *\n * Used by the Builder tool picker to gate integration tool rows: if the\n * pair has no connection, the card cannot be selected and surfaces an\n * inline \"Connect\" button instead.\n *\n * Distinct from `useExistingConnections` (per-pair, used by `/integrations`)\n * to keep their query caches independent.\n */\nexport const useAllConnections = ({ scopeToSelf = false, queryOptions }: UseAllConnectionsOptions = {}) => {\n const client = useMastraClient();\n const providersQuery = useToolProviders();\n const providers = useMemo(() => providersQuery.data?.providers ?? [], [providersQuery.data?.providers]);\n\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n // 1. For every provider, list its toolkits.\n const toolkitsQueries = useQueries({\n queries: providers.map(provider => ({\n queryKey: ['tool-integration-services', provider.id],\n queryFn: () => client.getToolProvider(provider.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, toolkit) pairs.\n const pairs = useMemo(() => {\n const out: Array<{ providerId: string; toolkit: string }> = [];\n providers.forEach((provider, idx) => {\n const toolkits = toolkitsQueries[idx]?.data?.data ?? [];\n for (const toolkit of toolkits) {\n out.push({ providerId: provider.id, toolkit: toolkit.slug });\n }\n });\n return out;\n }, [providers, toolkitsQueries]);\n\n // 3. One listConnections call per pair. Include `authorId` in queryKey when\n // self-scoped so the cache is distinct from any unscoped admin reads.\n const connectionsQueries = useQueries({\n queries: pairs.map(pair => ({\n queryKey: scopeToSelf\n ? ['tool-integration-connections-all', pair.providerId, pair.toolkit, callerAuthorId]\n : ['tool-integration-connections-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listConnections({\n toolkit: pair.toolkit,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled: callerReady,\n staleTime: STALE_TIME_MS,\n ...queryOptions?.connections,\n })),\n });\n\n const isLoading =\n providersQuery.isLoading ||\n (scopeToSelf && currentUserQuery.isLoading) ||\n toolkitsQueries.some(q => q.isLoading) ||\n connectionsQueries.some(q => q.isLoading);\n\n // Build a per-pair list of connection summaries so callers can both gate\n // (\"does this row have any connection?\") and auto-pin (\"if exactly one\n // exists, write it into the form on toggle-on\").\n const connectionsByKey = useMemo(() => {\n const map = new Map<string, Array<{ connectionId: string; label?: string | null; status?: string }>>();\n pairs.forEach((pair, idx) => {\n const items = connectionsQueries[idx]?.data?.items ?? [];\n map.set(`${pair.providerId}:${pair.toolkit}`, items);\n });\n return map;\n }, [pairs, connectionsQueries]);\n\n // A toolkit \"has a connection\" only when at least one connection is active.\n // Pending/failed rows don't count — this keeps the card hint in sync with the\n // toolkit row control, which also treats only active connections as usable.\n const hasConnection = useCallback(\n (providerId: string, toolkit: string) =>\n (connectionsByKey.get(`${providerId}:${toolkit}`) ?? []).some(connection => connection.status === 'active'),\n [connectionsByKey],\n );\n\n const getConnections = useCallback(\n (providerId: string, toolkit: string) => connectionsByKey.get(`${providerId}:${toolkit}`) ?? [],\n [connectionsByKey],\n );\n\n return { hasConnection, getConnections, isLoading };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\nexport interface AvailableIntegrationTool {\n providerId: string;\n slug: string;\n toolkit: string;\n name?: string;\n description?: string;\n}\n\n/**\n * Upper bound for a single Composio-style `listTools` call. Composio's SDK has\n * no cursor — only `limit` — so we ask for a large page and fan out per\n * `toolkit` to avoid being truncated when many toolkits are allowlisted.\n */\nconst PER_SERVICE_LIMIT = 500;\n\n/**\n * Returns every tool surfaced by every registered ToolProvider, scoped to\n * the provider's `allowedToolkits`/`allowedTools` filter (enforced\n * server-side). Used to render the full available-tools list inline.\n */\nexport const useAllProviderTools = ({\n queryOptions,\n}: {\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n tools?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>>;\n };\n} = {}) => {\n const client = useMastraClient();\n const integrationsQuery = useToolProviders();\n const integrations = useMemo(() => integrationsQuery.data?.providers ?? [], [integrationsQuery.data?.providers]);\n\n // 1. For every integration, fetch its tool services.\n const serviceQueries = useQueries({\n queries: integrations.map(integration => ({\n queryKey: ['tool-integration-services', integration.id],\n queryFn: () => client.getToolProvider(integration.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, serviceSlug) pairs.\n const servicePairs = useMemo(() => {\n const pairs: Array<{ providerId: string; toolkit: string }> = [];\n integrations.forEach((integration, idx) => {\n const services = serviceQueries[idx]?.data?.data ?? [];\n for (const service of services) {\n pairs.push({ providerId: integration.id, toolkit: service.slug });\n }\n });\n return pairs;\n }, [integrations, serviceQueries]);\n\n // 3. Fan out one tools query per (integration, service).\n const toolsQueries = useQueries({\n queries: servicePairs.map(pair => ({\n queryKey: ['tool-integration-tools-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listTools({ toolkit: pair.toolkit, perPage: PER_SERVICE_LIMIT }),\n ...queryOptions?.tools,\n })),\n });\n\n const isLoading =\n integrationsQuery.isLoading || serviceQueries.some(q => q.isLoading) || toolsQueries.some(q => q.isLoading);\n\n const tools = useMemo<AvailableIntegrationTool[]>(() => {\n const out: AvailableIntegrationTool[] = [];\n servicePairs.forEach((pair, idx) => {\n const items = toolsQueries[idx]?.data?.data ?? [];\n for (const item of items) {\n const toolkit = (item as { toolkit?: string }).toolkit ?? pair.toolkit;\n out.push({\n providerId: pair.providerId,\n slug: item.slug,\n toolkit,\n name: (item as { name?: string }).name,\n description: (item as { description?: string }).description,\n });\n }\n });\n return out;\n }, [servicePairs, toolsQueries]);\n\n return { tools, isLoading };\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface AuthorizeArgs {\n providerId: string;\n toolkit: string;\n /**\n * Existing bucket id when re-authorizing; omit for a brand-new connection.\n * Semantics are provider-opaque; for Composio v1 this is the internal user\n * bucket the new connected account should be created under.\n */\n connectionId?: string;\n /**\n * Provider-specific connection fields collected from the picker (e.g.\n * Confluence subdomain). Forwarded to the server's `authorize` body.\n */\n config?: Record<string, unknown>;\n /**\n * Optional human label to persist on the resulting `tool_integration_connections` row.\n */\n label?: string | null;\n /**\n * Ownership scope of the OAuth bucket. `'per-author'` (default) buckets\n * under the caller's authorId.\n */\n scope?: 'per-author' | 'shared' | 'caller-supplied';\n}\n\nexport interface AuthorizeResult {\n status: 'completed' | 'failed';\n /**\n * The `authId` returned by `authorize`, exposed as `connectionId` because\n * for the v1 Composio adapter it is the `connected_account.id` that the\n * caller persists as `Connection.connectionId`.\n */\n connectionId: string;\n}\n\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 5 * 60_000;\n\nexport interface UseAuthorizeOptions {\n pollIntervalMs?: number;\n timeoutMs?: number;\n openPopup?: (url: string) => Window | null;\n queryOptions?: MastraMutationOptions<AuthorizeResult, AuthorizeArgs>;\n}\n\n/**\n * Drives the OAuth popup + polling loop for a `ToolProvider` provider.\n */\nexport const useAuthorize = (options: UseAuthorizeOptions = {}) => {\n const client = useMastraClient();\n const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const openPopup = options.openPopup ?? ((url: string) => window.open(url, '_blank', 'popup,width=600,height=700'));\n\n return useMutation<AuthorizeResult, Error, AuthorizeArgs>({\n mutationFn: async ({ providerId, toolkit, connectionId, config, label, scope }) => {\n const integration = client.getToolProvider(providerId);\n const normalizedConnectionId = connectionId?.trim();\n const { url, authId } = await integration.authorize({\n toolkit,\n ...(normalizedConnectionId ? { connectionId: normalizedConnectionId } : {}),\n ...(config ? { config } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(scope ? { scope } : {}),\n });\n\n const popup = openPopup(url);\n if (!popup) {\n throw new Error('Popup blocked. Please allow popups for this site.');\n }\n\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n await new Promise(resolve => setTimeout(resolve, pollIntervalMs));\n const { status } = await integration.getAuthStatus(authId);\n if (status === 'completed' || status === 'failed') {\n try {\n popup.close();\n } catch {\n // Cross-origin popups may refuse close(); ignore.\n }\n return { status, connectionId: authId };\n }\n }\n\n try {\n popup.close();\n } catch {\n // ignore\n }\n throw new Error('Authorization timed out');\n },\n ...options.queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface DisconnectConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * When `true`, the server skips the usage check and revokes the\n * connection at the provider before deleting the local row.\n */\n force?: boolean;\n}\n\n/**\n * Calls the provider-side revoke (best-effort) and drops the local\n * `tool_integration_connections` row. Server enforces the soft-vs-force rule.\n */\ntype DisconnectConnectionResponse = Awaited<\n ReturnType<ReturnType<MastraClient['getToolProvider']>['disconnectConnection']>\n>;\n\nexport const useDisconnectConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<DisconnectConnectionResponse, DisconnectConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, force }: DisconnectConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.disconnectConnection(connectionId, force ? { force } : undefined);\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface UseExistingConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage in the picker.\n */\n scopeToSelf?: boolean;\n}\n\ntype ConnectionsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>;\n\n/**\n * Lists existing provider connections for the caller, scoped to a tool\n * service. Powers the \"use existing connection\" path in the picker so\n * authors can pin previously-authorized accounts without re-running OAuth.\n *\n * The connection owner is resolved server-side from the request's auth\n * context. Admin callers receive cross-author rows by default; pass\n * `scopeToSelf: true` to narrow the response to the caller's own bucket\n * (used by the Builder edit view).\n */\nexport const useExistingConnections = <TData = ConnectionsResponse>({\n providerId,\n toolkit,\n scopeToSelf = false,\n queryOptions,\n}: UseExistingConnectionsOptions & {\n providerId: string | null | undefined;\n toolkit: string | null | undefined;\n queryOptions?: MastraQueryOptions<ConnectionsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n const enabled = !!providerId && !!toolkit && callerReady;\n\n return useQuery({\n queryKey: scopeToSelf\n ? ['tool-integration-connections', providerId, toolkit, callerAuthorId]\n : ['tool-integration-connections', providerId, toolkit],\n queryFn: () =>\n client.getToolProvider(providerId!).listConnections({\n toolkit: toolkit!,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ProviderToolsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useProviderTools = <TData = ProviderToolsResponse>({\n providerId,\n params,\n queryOptions,\n}: {\n providerId: string | null;\n params?: { toolkit?: string; search?: string };\n queryOptions?: MastraQueryOptions<ProviderToolsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-tools', providerId, params?.toolkit, params?.search],\n queryFn: () => client.getToolProvider(providerId!).listTools(params),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolkitsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useToolkits = <TData = ToolkitsResponse>({\n providerId,\n queryOptions,\n}: {\n providerId: string | null;\n queryOptions?: MastraQueryOptions<ToolkitsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-toolkits', providerId],\n queryFn: () => client.getToolProvider(providerId!).listToolkits(),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface UpdateConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * New display label. Pass `null` (or an empty string) to clear the label.\n */\n label: string | null;\n}\n\n/**\n * Renames a `tool_provider_connections` row in place. Server enforces\n * ownership (owner / admin / shared scope). On success, invalidates both\n * the per-toolkit and the fan-out connection lists so the picker re-fetches.\n */\ntype UpdateConnectionResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['updateConnection']>>;\n\nexport const useUpdateConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<UpdateConnectionResponse, UpdateConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, label }: UpdateConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.updateConnection(connectionId, { label });\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections-all', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;;AAQA,MAAa,oBAAmD,EAC9D,iBACuE,CAAC,MAAoC;CAC5G,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,gBAAgB;EAC3B,eAAe,OAAO,kBAAkB;EACxC,GAAG;CACL,CAAC;AACH;AAWA,MAAa,0BAA0B,EACrC,iBAC4D,CAAC,MAAM;CACnE,MAAM,SAAS,gBAAgB;CAC/B,MAAM,EAAE,MAAM,eAAe,WAAW,uBAAuB,iBAAiB;CAChF,MAAM,YAAY,eAAe,aA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OAAO,gBAAgB,UAAW,CAAC,CAAC,UAAU,MAAM;EACnE,GAAG;CACL,CAAC;AACH;;;;;;AChBA,MAAa,eAAyC,EACpD,YACA,mBAIkC;CAClC,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,0BAA0B,UAAU;EAC/C,eAAe,OAAO,gBAAgB,UAAW,CAAC,CAAC,aAAa;EAChE,GAAG;CACL,CAAC;AACH;;;ACJA,MAAa,uBAAuB,EAClC,iBAC4F,CAAC,MAAM;CACnG,MAAM,SAAS,gBAAgB;CAC/B,MAAM,KAAK,eAAe;CAE1B,OAAO,YAAY;EACjB,YAAY,OAAO,EAAE,YAAY,cAAc,YAAkC;GAE/E,OADoB,OAAO,gBAAgB,UAC1B,CAAC,CAAC,iBAAiB,cAAc,EAAE,MAAM,CAAC;EAC7D;EACA,YAAY,OAAO,SAAS;GAC1B,GAAQ,kBAAkB,EAAE,UAAU,CAAC,gCAAgC,KAAK,UAAU,EAAE,CAAC;GACzF,GAAQ,kBAAkB,EAAE,UAAU,CAAC,oCAAoC,KAAK,UAAU,EAAE,CAAC;EAC/F;EACA,GAAG;CACL,CAAC;AACH"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/tool-providers/use-tool-providers.ts","../../../src/hooks/tool-providers/use-all-connections.ts","../../../src/hooks/tool-providers/use-all-provider-tools.ts","../../../src/hooks/tool-providers/use-authorize.ts","../../../src/hooks/tool-providers/use-disconnect-connection.ts","../../../src/hooks/tool-providers/use-existing-connections.ts","../../../src/hooks/tool-providers/use-provider-tools.ts","../../../src/hooks/tool-providers/use-toolkits.ts","../../../src/hooks/tool-providers/use-update-connection.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolProvidersResponse = Awaited<ReturnType<MastraClient['listToolProviders']>>;\n\nexport const useToolProviders = <TData = ToolProvidersResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ToolProvidersResponse, TData> } = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-providers'],\n queryFn: () => client.listToolProviders(),\n ...queryOptions,\n });\n};\n\nexport interface IntegrationTool {\n slug: string;\n name: string;\n description?: string;\n toolkit?: string;\n providerId: string;\n providerName: string;\n}\n\nexport const useAllIntegrationTools = ({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<IntegrationTool[]> } = {}) => {\n const client = useMastraClient();\n const { data: providersData, isLoading: isLoadingProviders } = useToolProviders();\n const providers = providersData?.providers ?? [];\n\n const toolsQuery = useQuery({\n queryKey: ['integration-tools-all', providers.map(p => p.id)],\n queryFn: async () => {\n const results: IntegrationTool[] = [];\n\n for (const provider of providers) {\n const response = await client.getToolProvider(provider.id).listTools();\n for (const tool of response.data) {\n results.push({\n ...tool,\n providerId: provider.id,\n providerName: provider.name,\n });\n }\n }\n\n return results;\n },\n enabled: providers.length > 0,\n ...queryOptions,\n });\n\n return {\n data: toolsQuery.data ?? [],\n isLoading: isLoadingProviders || toolsQuery.isLoading,\n };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\n/**\n * Stale time long enough to avoid refetching on every picker re-render but\n * short enough that an OAuth completion in a sibling tab is reflected\n * promptly (React Query also re-fetches on window focus by default).\n */\nconst STALE_TIME_MS = 30_000;\n\nexport interface UseAllConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage.\n */\n scopeToSelf?: boolean;\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n connections?: MastraQueryOptions<\n Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>\n >;\n };\n}\n\n/**\n * Fans out across every registered ToolProvider and every toolkit it\n * exposes to determine whether the caller has an existing connection for a\n * given `(providerId, toolkit)` pair.\n *\n * Used by the Builder tool picker to gate integration tool rows: if the\n * pair has no connection, the card cannot be selected and surfaces an\n * inline \"Connect\" button instead.\n *\n * Distinct from `useExistingConnections` (per-pair, used by `/integrations`)\n * to keep their query caches independent.\n */\nexport const useAllConnections = ({ scopeToSelf = false, queryOptions }: UseAllConnectionsOptions = {}) => {\n const client = useMastraClient();\n const providersQuery = useToolProviders();\n const providers = useMemo(() => providersQuery.data?.providers ?? [], [providersQuery.data?.providers]);\n\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n // 1. For every provider, list its toolkits.\n const toolkitsQueries = useQueries({\n queries: providers.map(provider => ({\n queryKey: ['tool-integration-services', provider.id],\n queryFn: () => client.getToolProvider(provider.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, toolkit) pairs.\n const pairs = useMemo(() => {\n const out: Array<{ providerId: string; toolkit: string }> = [];\n providers.forEach((provider, idx) => {\n const toolkits = toolkitsQueries[idx]?.data?.data ?? [];\n for (const toolkit of toolkits) {\n out.push({ providerId: provider.id, toolkit: toolkit.slug });\n }\n });\n return out;\n }, [providers, toolkitsQueries]);\n\n // 3. One listConnections call per pair. Include `authorId` in queryKey when\n // self-scoped so the cache is distinct from any unscoped admin reads.\n const connectionsQueries = useQueries({\n queries: pairs.map(pair => ({\n queryKey: scopeToSelf\n ? ['tool-integration-connections-all', pair.providerId, pair.toolkit, callerAuthorId]\n : ['tool-integration-connections-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listConnections({\n toolkit: pair.toolkit,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled: callerReady,\n staleTime: STALE_TIME_MS,\n ...queryOptions?.connections,\n })),\n });\n\n const isLoading =\n providersQuery.isLoading ||\n (scopeToSelf && currentUserQuery.isLoading) ||\n toolkitsQueries.some(q => q.isLoading) ||\n connectionsQueries.some(q => q.isLoading);\n\n // Build a per-pair list of connection summaries so callers can both gate\n // (\"does this row have any connection?\") and auto-pin (\"if exactly one\n // exists, write it into the form on toggle-on\").\n const connectionsByKey = useMemo(() => {\n const map = new Map<string, Array<{ connectionId: string; label?: string | null; status?: string }>>();\n pairs.forEach((pair, idx) => {\n const items = connectionsQueries[idx]?.data?.items ?? [];\n map.set(`${pair.providerId}:${pair.toolkit}`, items);\n });\n return map;\n }, [pairs, connectionsQueries]);\n\n // A toolkit \"has a connection\" only when at least one connection is active.\n // Pending/failed rows don't count — this keeps the card hint in sync with the\n // toolkit row control, which also treats only active connections as usable.\n const hasConnection = useCallback(\n (providerId: string, toolkit: string) =>\n (connectionsByKey.get(`${providerId}:${toolkit}`) ?? []).some(connection => connection.status === 'active'),\n [connectionsByKey],\n );\n\n const getConnections = useCallback(\n (providerId: string, toolkit: string) => connectionsByKey.get(`${providerId}:${toolkit}`) ?? [],\n [connectionsByKey],\n );\n\n return { hasConnection, getConnections, isLoading };\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useQueries } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nimport { useToolProviders } from './use-tool-providers';\n\nexport interface AvailableIntegrationTool {\n providerId: string;\n slug: string;\n toolkit: string;\n name?: string;\n description?: string;\n}\n\n/**\n * Upper bound for a single Composio-style `listTools` call. Composio's SDK has\n * no cursor — only `limit` — so we ask for a large page and fan out per\n * `toolkit` to avoid being truncated when many toolkits are allowlisted.\n */\nconst PER_SERVICE_LIMIT = 500;\n\n/**\n * Returns every tool surfaced by every registered ToolProvider, scoped to\n * the provider's `allowedToolkits`/`allowedTools` filter (enforced\n * server-side). Used to render the full available-tools list inline.\n */\nexport const useAllProviderTools = ({\n queryOptions,\n}: {\n /** TanStack overrides applied to every fanned-out query, spread last. `select` must keep the default shape. */\n queryOptions?: {\n toolkits?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>>;\n tools?: MastraQueryOptions<Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>>;\n };\n} = {}) => {\n const client = useMastraClient();\n const integrationsQuery = useToolProviders();\n const integrations = useMemo(() => integrationsQuery.data?.providers ?? [], [integrationsQuery.data?.providers]);\n\n // 1. For every integration, fetch its tool services.\n const serviceQueries = useQueries({\n queries: integrations.map(integration => ({\n queryKey: ['tool-integration-services', integration.id],\n queryFn: () => client.getToolProvider(integration.id).listToolkits(),\n ...queryOptions?.toolkits,\n })),\n });\n\n // 2. Flatten to (providerId, serviceSlug) pairs.\n const servicePairs = useMemo(() => {\n const pairs: Array<{ providerId: string; toolkit: string }> = [];\n integrations.forEach((integration, idx) => {\n const services = serviceQueries[idx]?.data?.data ?? [];\n for (const service of services) {\n pairs.push({ providerId: integration.id, toolkit: service.slug });\n }\n });\n return pairs;\n }, [integrations, serviceQueries]);\n\n // 3. Fan out one tools query per (integration, service).\n const toolsQueries = useQueries({\n queries: servicePairs.map(pair => ({\n queryKey: ['tool-integration-tools-all', pair.providerId, pair.toolkit],\n queryFn: () =>\n client.getToolProvider(pair.providerId).listTools({ toolkit: pair.toolkit, perPage: PER_SERVICE_LIMIT }),\n ...queryOptions?.tools,\n })),\n });\n\n const isLoading =\n integrationsQuery.isLoading || serviceQueries.some(q => q.isLoading) || toolsQueries.some(q => q.isLoading);\n\n const tools = useMemo<AvailableIntegrationTool[]>(() => {\n const out: AvailableIntegrationTool[] = [];\n servicePairs.forEach((pair, idx) => {\n const items = toolsQueries[idx]?.data?.data ?? [];\n for (const item of items) {\n const toolkit = (item as { toolkit?: string }).toolkit ?? pair.toolkit;\n out.push({\n providerId: pair.providerId,\n slug: item.slug,\n toolkit,\n name: (item as { name?: string }).name,\n description: (item as { description?: string }).description,\n });\n }\n });\n return out;\n }, [servicePairs, toolsQueries]);\n\n return { tools, isLoading };\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface AuthorizeArgs {\n providerId: string;\n toolkit: string;\n /**\n * Existing bucket id when re-authorizing; omit for a brand-new connection.\n * Semantics are provider-opaque; for Composio v1 this is the internal user\n * bucket the new connected account should be created under.\n */\n connectionId?: string;\n /**\n * Provider-specific connection fields collected from the picker (e.g.\n * Confluence subdomain). Forwarded to the server's `authorize` body.\n */\n config?: Record<string, unknown>;\n /**\n * Optional human label to persist on the resulting `tool_integration_connections` row.\n */\n label?: string | null;\n /**\n * Ownership scope of the OAuth bucket. `'per-author'` (default) buckets\n * under the caller's authorId.\n */\n scope?: 'per-author' | 'shared' | 'caller-supplied';\n}\n\nexport interface AuthorizeResult {\n status: 'completed' | 'failed';\n /**\n * The `authId` returned by `authorize`, exposed as `connectionId` because\n * for the v1 Composio adapter it is the `connected_account.id` that the\n * caller persists as `Connection.connectionId`.\n */\n connectionId: string;\n}\n\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 5 * 60_000;\n\nexport interface UseAuthorizeOptions {\n pollIntervalMs?: number;\n timeoutMs?: number;\n openPopup?: (url: string) => Window | null;\n queryOptions?: MastraMutationOptions<AuthorizeResult, AuthorizeArgs>;\n}\n\n/**\n * Drives the OAuth popup + polling loop for a `ToolProvider` provider.\n */\nexport const useAuthorize = (options: UseAuthorizeOptions = {}) => {\n const client = useMastraClient();\n const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const openPopup = options.openPopup ?? ((url: string) => window.open(url, '_blank', 'popup,width=600,height=700'));\n\n return useMutation<AuthorizeResult, Error, AuthorizeArgs>({\n mutationFn: async ({ providerId, toolkit, connectionId, config, label, scope }) => {\n const integration = client.getToolProvider(providerId);\n const normalizedConnectionId = connectionId?.trim();\n const { url, authId } = await integration.authorize({\n toolkit,\n ...(normalizedConnectionId ? { connectionId: normalizedConnectionId } : {}),\n ...(config ? { config } : {}),\n ...(label !== undefined ? { label } : {}),\n ...(scope ? { scope } : {}),\n });\n\n const popup = openPopup(url);\n if (!popup) {\n throw new Error('Popup blocked. Please allow popups for this site.');\n }\n\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n await new Promise(resolve => setTimeout(resolve, pollIntervalMs));\n const { status } = await integration.getAuthStatus(authId);\n if (status === 'completed' || status === 'failed') {\n try {\n popup.close();\n } catch {\n // Cross-origin popups may refuse close(); ignore.\n }\n return { status, connectionId: authId };\n }\n }\n\n try {\n popup.close();\n } catch {\n // ignore\n }\n throw new Error('Authorization timed out');\n },\n ...options.queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface DisconnectConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * When `true`, the server skips the usage check and revokes the\n * connection at the provider before deleting the local row.\n */\n force?: boolean;\n}\n\n/**\n * Calls the provider-side revoke (best-effort) and drops the local\n * `tool_integration_connections` row. Server enforces the soft-vs-force rule.\n */\ntype DisconnectConnectionResponse = Awaited<\n ReturnType<ReturnType<MastraClient['getToolProvider']>['disconnectConnection']>\n>;\n\nexport const useDisconnectConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<DisconnectConnectionResponse, DisconnectConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, force }: DisconnectConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.disconnectConnection(connectionId, force ? { force } : undefined);\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isUnauthenticatedError, useCurrentUser } from '../auth';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface UseExistingConnectionsOptions {\n /**\n * When `true`, the hook forces the server-side `authorId` filter to the\n * caller's own userId. Builder edit view passes `scopeToSelf: true` so\n * admins see only their own connections, never other authors' rows.\n *\n * Non-admin callers see the same result either way — the server already\n * scopes to the caller's bucket — but the explicit filter keeps caches\n * consistent and prevents admin cross-author leakage in the picker.\n */\n scopeToSelf?: boolean;\n}\n\ntype ConnectionsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listConnections']>>;\n\n/**\n * Lists existing provider connections for the caller, scoped to a tool\n * service. Powers the \"use existing connection\" path in the picker so\n * authors can pin previously-authorized accounts without re-running OAuth.\n *\n * The connection owner is resolved server-side from the request's auth\n * context. Admin callers receive cross-author rows by default; pass\n * `scopeToSelf: true` to narrow the response to the caller's own bucket\n * (used by the Builder edit view).\n */\nexport const useExistingConnections = <TData = ConnectionsResponse>({\n providerId,\n toolkit,\n scopeToSelf = false,\n queryOptions,\n}: UseExistingConnectionsOptions & {\n providerId: string | null | undefined;\n toolkit: string | null | undefined;\n queryOptions?: MastraQueryOptions<ConnectionsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n const currentUserQuery = useCurrentUser();\n const callerAuthorId = currentUserQuery.data?.id;\n\n const callerReady = !scopeToSelf || currentUserQuery.isSuccess || isUnauthenticatedError(currentUserQuery.error);\n\n const enabled = !!providerId && !!toolkit && callerReady;\n\n return useQuery({\n queryKey: scopeToSelf\n ? ['tool-integration-connections', providerId, toolkit, callerAuthorId]\n : ['tool-integration-connections', providerId, toolkit],\n queryFn: () =>\n client.getToolProvider(providerId!).listConnections({\n toolkit: toolkit!,\n ...(scopeToSelf && callerAuthorId ? { authorId: callerAuthorId } : {}),\n }),\n enabled,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ProviderToolsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listTools']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useProviderTools = <TData = ProviderToolsResponse>({\n providerId,\n params,\n queryOptions,\n}: {\n providerId: string | null;\n params?: { toolkit?: string; search?: string };\n queryOptions?: MastraQueryOptions<ProviderToolsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-tools', providerId, params?.toolkit, params?.search],\n queryFn: () => client.getToolProvider(providerId!).listTools(params),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolkitsResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['listToolkits']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useToolkits = <TData = ToolkitsResponse>({\n providerId,\n queryOptions,\n}: {\n providerId: string | null;\n queryOptions?: MastraQueryOptions<ToolkitsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool-provider-toolkits', providerId],\n queryFn: () => client.getToolProvider(providerId!).listToolkits(),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport interface UpdateConnectionArgs {\n providerId: string;\n connectionId: string;\n /**\n * New display label. Pass `null` (or an empty string) to clear the label.\n */\n label: string | null;\n}\n\n/**\n * Renames a `tool_provider_connections` row in place. Server enforces\n * ownership (owner / admin / shared scope). On success, invalidates both\n * the per-toolkit and the fan-out connection lists so the picker re-fetches.\n */\ntype UpdateConnectionResponse = Awaited<ReturnType<ReturnType<MastraClient['getToolProvider']>['updateConnection']>>;\n\nexport const useUpdateConnection = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<UpdateConnectionResponse, UpdateConnectionArgs> } = {}) => {\n const client = useMastraClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ providerId, connectionId, label }: UpdateConnectionArgs) => {\n const integration = client.getToolProvider(providerId);\n return integration.updateConnection(connectionId, { label });\n },\n onSuccess: (_data, vars) => {\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections', vars.providerId] });\n void qc.invalidateQueries({ queryKey: ['tool-integration-connections-all', vars.providerId] });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;;AAQA,MAAa,oBAAmD,EAC9D,iBACuE,CAAC,MAAoC;CAC5G,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,gBAAgB;EAC3B,eAAe,OAAO,kBAAkB;EACxC,GAAG;CACL,CAAC;AACH;AAWA,MAAa,0BAA0B,EACrC,i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KkC;CAClC,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU;GAAC;GAAuB;GAAY,QAAQ;GAAS,QAAQ;EAAM;EAC7E,eAAe,OAAO,gBAAgB,UAAW,CAAC,CAAC,UAAU,MAAM;EACnE,GAAG;CACL,CAAC;AACH;;;;;;AChBA,MAAa,eAAyC,EACpD,YACA,mBAIkC;CAClC,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,0BAA0B,UAAU;EAC/C,eAAe,OAAO,gBAAgB,UAAW,CAAC,CAAC,aAAa;EAChE,GAAG;CACL,CAAC;AACH;;;ACJA,MAAa,uBAAuB,EAClC,iBAC4F,CAAC,MAAM;CACnG,MAAM,SAAS,gBAAgB;CAC/B,MAAM,KAAK,eAAe;CAE1B,OAAO,YAAY;EACjB,YAAY,OAAO,EAAE,YAAY,cAAc,YAAkC;GAE/E,OADoB,OAAO,gBAAgB,UAC1B,CAAC,CAAC,iBAAiB,cAAc,EAAE,MAAM,CAAC;EAC7D;EACA,YAAY,OAAO,SAAS;GAC1B,GAAQ,kBAAkB,EAAE,UAAU,CAAC,gCAAgC,KAAK,UAAU,EAAE,CAAC;GACzF,GAAQ,kBAAkB,EAAE,UAAU,CAAC,oCAAoC,KAAK,UAAU,EAAE,CAAC;EAC/F;EACA,GAAG;CACL,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useMastraClient","useMastraClient","RequestContext"],"sources":["../../../src/hooks/tools/use-all-tools.ts","../../../src/hooks/tools/use-execute-tool.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolsResponse = Awaited<ReturnType<MastraClient['listTools']>>;\ntype ToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getTool']>['details']>>;\n\nexport const useTools = <TData = ToolsResponse>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ToolsResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n return useQuery({\n queryKey: ['tools', requestContext],\n queryFn: () => client.listTools(requestContext),\n ...queryOptions,\n });\n};\n\nexport const useTool = <TData = ToolResponse>({\n toolId,\n requestContext,\n queryOptions,\n}: {\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ToolResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool', toolId, requestContext],\n queryFn: () => client.getTool(toolId).details(requestContext),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { RequestContext } from '@mastra/core/di';\n\nimport { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ntype ExecuteToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getTool']>['execute']>>;\ntype ExecuteToolVariables = { toolId: string; input: any; requestContext?: Record<string, any> };\n\nexport const useExecuteTool = ({\n queryOptions,\n}: {\n queryOptions?: MastraMutationOptions<ExecuteToolResponse, ExecuteToolVariables>;\n} = {}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ toolId, input, requestContext: playgroundRequestContext }: ExecuteToolVariables) => {\n const requestContext = new RequestContext();\n Object.entries(playgroundRequestContext ?? {}).forEach(([key, value]) => {\n requestContext.set(key, value);\n });\n\n const tool = client.getTool(toolId);\n return tool.execute({ data: input, requestContext });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;;AASA,MAAa,YAAmC,EAC9C,gBACA,iBAIE,CAAC,MAAoC;CACvC,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU,CAAC,SAAS,cAAc;EAClC,eAAe,OAAO,UAAU,cAAc;EAC9C,GAAG;CACL,CAAC;AACH;AAEA,MAAa,WAAiC,EAC5C,QACA,gBACA,mBAKkC;CAClC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU;GAAC;GAAQ;GAAQ;EAAc;EACzC,eAAe,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,cAAc;EAC5D,GAAG;CACL,CAAC;AACH;;;AC9BA,MAAa,kBAAkB,EAC7B,iBAGE,CAAC,MAAM;CACT,MAAM,SAASC,8BAAAA,gBAAgB;CAC/B,QAAA,GAAA,sBAAA,YAAA,CAAmB;EACjB,YAAY,OAAO,EAAE,QAAQ,OAAO,gBAAgB,+BAAqD;GACvG,MAAM,iBAAiB,IAAIC,gBAAAA,eAAe;GAC1C,OAAO,QAAQ,4BAA4B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;IACvE,eAAe,IAAI,KAAK,KAAK;GAC/B,CAAC;GAGD,OADa,OAAO,QAAQ,MAClB,CAAC,CAAC,QAAQ;IAAE,MAAM;IAAO;GAAe,CAAC;EACrD;EACA,GAAG;CACL,CAAC;AACH"}
1
+ {"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","useMastraClient","useMutation","RequestContext"],"sources":["../../../src/hooks/tools/use-all-tools.ts","../../../src/hooks/tools/use-execute-tool.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ToolsResponse = Awaited<ReturnType<MastraClient['listTools']>>;\ntype ToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getTool']>['details']>>;\n\nexport const useTools = <TData = ToolsResponse>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ToolsResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n return useQuery({\n queryKey: ['tools', requestContext],\n queryFn: () => client.listTools(requestContext),\n ...queryOptions,\n });\n};\n\nexport const useTool = <TData = ToolResponse>({\n toolId,\n requestContext,\n queryOptions,\n}: {\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ToolResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['tool', toolId, requestContext],\n queryFn: () => client.getTool(toolId).details(requestContext),\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport { RequestContext } from '@mastra/core/di';\n\nimport { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ntype ExecuteToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getTool']>['execute']>>;\ntype ExecuteToolVariables = { toolId: string; input: any; requestContext?: Record<string, any> };\n\nexport const useExecuteTool = ({\n queryOptions,\n}: {\n queryOptions?: MastraMutationOptions<ExecuteToolResponse, ExecuteToolVariables>;\n} = {}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ toolId, input, requestContext: playgroundRequestContext }: ExecuteToolVariables) => {\n const requestContext = new RequestContext();\n Object.entries(playgroundRequestContext ?? {}).forEach(([key, value]) => {\n requestContext.set(key, value);\n });\n\n const tool = client.getTool(toolId);\n return tool.execute({ data: input, requestContext });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;;AASA,MAAa,YAAmC,EAC9C,gBACA,iBAIE,CAAC,MAAoC;CACvC,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,CAAC,SAAS,cAAc;EAClC,eAAe,OAAO,UAAU,cAAc;EAC9C,GAAG;CACL,CAAC;AACH;AAEA,MAAa,WAAiC,EAC5C,QACA,gBACA,mBAKkC;CAClC,MAAM,SAASD,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU;GAAC;GAAQ;GAAQ;EAAc;EACzC,eAAe,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,cAAc;EAC5D,GAAG;CACL,CAAC;AACH;;;AC9BA,MAAa,kBAAkB,EAC7B,iBAGE,CAAC,MAAM;CACT,MAAM,SAASC,8BAAAA,gBAAgB;CAC/B,QAAA,GAAOC,sBAAAA,YAAAA,CAAY;EACjB,YAAY,OAAO,EAAE,QAAQ,OAAO,gBAAgB,+BAAqD;GACvG,MAAM,iBAAiB,IAAIC,gBAAAA,eAAe;GAC1C,OAAO,QAAQ,4BAA4B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;IACvE,eAAe,IAAI,KAAK,KAAK;GAC/B,CAAC;GAGD,OADa,OAAO,QAAQ,MAClB,CAAC,CAAC,QAAQ;IAAE,MAAM;IAAO;GAAe,CAAC;EACrD;EACA,GAAG;CACL,CAAC;AACH"}
@@ -19,7 +19,7 @@ let _mastra_core_observability = require("@mastra/core/observability");
19
19
  * through to the store's discovery refresh. Matching the server TTL keeps the
20
20
  * client from asking more often than the answer can change.
21
21
  */
22
- const DISCOVERY_STALE_TIME = 300 * 1e3;
22
+ const DISCOVERY_STALE_TIME = 3e5;
23
23
  //#endregion
24
24
  //#region src/hooks/traces/use-branch.ts
25
25
  /**
@@ -52,7 +52,8 @@ const ROOT_ENTITY_TYPES = {
52
52
  AGENT: "agent",
53
53
  WORKFLOW: "workflow_run",
54
54
  SCORER: "scorer",
55
- INGEST: "rag_ingestion"
55
+ INGEST: "rag_ingestion",
56
+ CLASSIFIER: "classifier"
56
57
  };
57
58
  //#endregion
58
59
  //#region src/hooks/traces/use-entity-names.ts
@@ -135,7 +136,7 @@ const useServiceNames = ({ queryOptions } = {}) => {
135
136
  };
136
137
  //#endregion
137
138
  //#region src/hooks/traces/use-span-detail.ts
138
- const IMMUTABLE_CACHE_TIME$1 = 1e3 * 60 * 60 * 24 * 30;
139
+ const IMMUTABLE_CACHE_TIME$1 = 2592e6;
139
140
  /**
140
141
  * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
141
142
  */
@@ -200,7 +201,7 @@ function useThreadHasOtherTraces({ threadId, queryOptions }) {
200
201
  }
201
202
  //#endregion
202
203
  //#region src/hooks/traces/use-trace-light-spans.ts
203
- const IMMUTABLE_CACHE_TIME = 1e3 * 60 * 60 * 24 * 30;
204
+ const IMMUTABLE_CACHE_TIME = 2592e6;
204
205
  /**
205
206
  * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
206
207
  */
@@ -551,7 +552,7 @@ const DEFAULT_POLLING_CONFIG = {
551
552
  deltaLimit: 100,
552
553
  pageModeRefetchIntervalMs: 1e4,
553
554
  page0StatusRefreshIntervalMs: 6e4,
554
- idleGuardThresholdMs: 15 * 6e4,
555
+ idleGuardThresholdMs: 9e5,
555
556
  minRefetchSpinMs: 400,
556
557
  deltaHighlightMs: 1e3
557
558
  };