@mastra/react 1.12.0-alpha.9 → 1.13.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{accumulator-BQGsraqS.cjs → accumulator-BmD8-x9I.cjs} +52 -4
- package/dist/accumulator-BmD8-x9I.cjs.map +1 -0
- package/dist/{accumulator-C8kIc450.js → accumulator-D9jAph99.js} +52 -4
- package/dist/accumulator-D9jAph99.js.map +1 -0
- package/dist/chat/index.cjs +1 -1
- package/dist/chat/index.js +1 -2
- package/dist/combine-by-ids-D_lp6Dvq.cjs.map +1 -1
- package/dist/experiments-B7vRMK5T.js +306 -0
- package/dist/experiments-B7vRMK5T.js.map +1 -0
- package/dist/experiments-CJw1N3FB.cjs +353 -0
- package/dist/experiments-CJw1N3FB.cjs.map +1 -0
- package/dist/hooks/agents/index.cjs +2 -2
- package/dist/hooks/agents/index.cjs.map +1 -1
- package/dist/hooks/agents/index.js +2 -2
- package/dist/hooks/agents/index.js.map +1 -1
- package/dist/hooks/auth/index.cjs +2 -2
- package/dist/hooks/auth/index.cjs.map +1 -1
- package/dist/hooks/auth/index.js +2 -2
- package/dist/hooks/auth/index.js.map +1 -1
- package/dist/hooks/capabilities/index.cjs +58 -1
- package/dist/hooks/capabilities/index.cjs.map +1 -1
- package/dist/hooks/capabilities/index.d.ts +4 -0
- package/dist/hooks/capabilities/index.d.ts.map +1 -1
- package/dist/hooks/capabilities/index.js +55 -2
- package/dist/hooks/capabilities/index.js.map +1 -1
- package/dist/hooks/capabilities/use-span-aggregate-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-span-aggregate-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-span-query-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-span-query-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-thread-query-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-thread-query-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-trace-query-delta-polling-available.d.ts +10 -0
- package/dist/hooks/capabilities/use-trace-query-delta-polling-available.d.ts.map +1 -0
- package/dist/hooks/configuration/index.cjs.map +1 -1
- package/dist/hooks/datasets/index.cjs +25 -1
- package/dist/hooks/datasets/index.cjs.map +1 -1
- package/dist/hooks/datasets/index.js +25 -2
- package/dist/hooks/datasets/index.js.map +1 -1
- package/dist/hooks/datasets/use-datasets.d.ts +7 -0
- package/dist/hooks/datasets/use-datasets.d.ts.map +1 -1
- package/dist/hooks/embedders/index.cjs.map +1 -1
- package/dist/hooks/experiments/index.cjs +9 -235
- package/dist/hooks/experiments/index.d.ts +1 -0
- package/dist/hooks/experiments/index.d.ts.map +1 -1
- package/dist/hooks/experiments/index.js +1 -229
- package/dist/hooks/experiments/usage-accumulator.d.ts +25 -0
- package/dist/hooks/experiments/usage-accumulator.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiment-item-usage.d.ts +2 -7
- package/dist/hooks/experiments/use-experiment-item-usage.d.ts.map +1 -1
- package/dist/hooks/experiments/use-experiments-list-metrics.d.ts +19 -0
- package/dist/hooks/experiments/use-experiments-list-metrics.d.ts.map +1 -0
- package/dist/hooks/feedback/index.cjs.map +1 -1
- package/dist/hooks/llm/index.cjs.map +1 -1
- package/dist/hooks/logs/index.cjs.map +1 -1
- package/dist/hooks/mcps/index.cjs.map +1 -1
- package/dist/hooks/memory/index.cjs +10 -10
- package/dist/hooks/memory/index.cjs.map +1 -1
- package/dist/hooks/memory/index.js +10 -10
- package/dist/hooks/memory/index.js.map +1 -1
- package/dist/hooks/metrics/index.cjs +13 -11
- package/dist/hooks/metrics/index.cjs.map +1 -1
- package/dist/hooks/metrics/index.js +13 -11
- package/dist/hooks/metrics/index.js.map +1 -1
- package/dist/hooks/processors/index.cjs.map +1 -1
- package/dist/hooks/prompt-blocks/index.cjs.map +1 -1
- package/dist/hooks/query/index.cjs.map +1 -1
- package/dist/hooks/review/index.cjs +2 -2
- package/dist/hooks/review/index.cjs.map +1 -1
- package/dist/hooks/review/index.js +1 -1
- package/dist/hooks/schedules/index.cjs.map +1 -1
- package/dist/hooks/scores/index.cjs.map +1 -1
- package/dist/hooks/templates/index.cjs +20 -18
- package/dist/hooks/templates/index.cjs.map +1 -1
- package/dist/hooks/templates/index.js +20 -18
- package/dist/hooks/templates/index.js.map +1 -1
- package/dist/hooks/templates/use-templates.d.ts.map +1 -1
- package/dist/hooks/tool-providers/index.cjs +1 -1
- package/dist/hooks/tool-providers/index.cjs.map +1 -1
- package/dist/hooks/tool-providers/index.js +1 -1
- package/dist/hooks/tool-providers/index.js.map +1 -1
- package/dist/hooks/tools/index.cjs.map +1 -1
- package/dist/hooks/traces/index.cjs +292 -9
- package/dist/hooks/traces/index.cjs.map +1 -1
- package/dist/hooks/traces/index.d.ts +2 -0
- package/dist/hooks/traces/index.d.ts.map +1 -1
- package/dist/hooks/traces/index.js +285 -10
- package/dist/hooks/traces/index.js.map +1 -1
- package/dist/hooks/traces/use-query-spans.d.ts +27 -0
- package/dist/hooks/traces/use-query-spans.d.ts.map +1 -0
- package/dist/hooks/traces/use-query-threads.d.ts +30 -0
- package/dist/hooks/traces/use-query-threads.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-query.d.ts +50 -1
- package/dist/hooks/traces/use-trace-query.d.ts.map +1 -1
- package/dist/hooks/traces/use-traces.d.ts +37 -37
- package/dist/hooks/vectors/index.cjs.map +1 -1
- package/dist/hooks/voice/index.cjs.map +1 -1
- package/dist/hooks/workflows/index.cjs +1 -1
- package/dist/hooks/workflows/index.cjs.map +1 -1
- package/dist/hooks/workflows/index.js +1 -1
- package/dist/hooks/workspace/index.cjs +1 -1
- package/dist/hooks/workspace/index.cjs.map +1 -1
- package/dist/hooks/workspace/index.js +1 -1
- package/dist/hooks/workspace/index.js.map +1 -1
- package/dist/{hooks-CIutb3DO.cjs → hooks-C6CJtoOR.cjs} +6 -4
- package/dist/hooks-C6CJtoOR.cjs.map +1 -0
- package/dist/{hooks-0L0RNfau.js → hooks-DG-Y1KFe.js} +2 -2
- package/dist/{hooks-0L0RNfau.js.map → hooks-DG-Y1KFe.js.map} +1 -1
- package/dist/{hooks-FVbeHlov.js → hooks-DvLSZtUd.js} +6 -4
- package/dist/{hooks-FVbeHlov.js.map → hooks-DvLSZtUd.js.map} +1 -1
- package/dist/{hooks-_YevKidX.cjs → hooks-XYsmqFCz.cjs} +2 -2
- package/dist/hooks-XYsmqFCz.cjs.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/mastra-db/accumulator.d.ts +0 -6
- package/dist/lib/mastra-db/accumulator.d.ts.map +1 -1
- package/dist/mastra-client-context-DzX3f0RF.cjs.map +1 -1
- package/dist/ui/index.cjs +4 -4
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.js +3 -3
- package/dist/ui/index.js.map +1 -1
- package/dist/use-in-view-B6eJO9Zi.cjs.map +1 -1
- package/dist/voice-BOtUdMi8.cjs.map +1 -1
- package/package.json +7 -7
- package/dist/accumulator-BQGsraqS.cjs.map +0 -1
- package/dist/accumulator-C8kIc450.js.map +0 -1
- package/dist/hooks/experiments/index.cjs.map +0 -1
- package/dist/hooks/experiments/index.js.map +0 -1
- package/dist/hooks-CIutb3DO.cjs.map +0 -1
- 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',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BAAAA,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,CAAS;EACd,UAAU,CAAC,gBAAgB;EAC3B,eAAe,OAAO,kBAAkB;EACxC,GAAG;CACL,CAAC;AACH;AAWA,MAAa,0BAA0B,EACrC,iBAC4D,CAAC,MAAM;CACnE,MAAM,SAASD,8B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AAkB,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 =
|
|
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,aAAa,CAAC;CAE/C,MAAM,aAAa,SAAS;EAC1B,UAAU,CAAC,yBAAyB,UAAU,KAAI,MAAK,EAAE,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Aa,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,iBAC4D,CAAC,MAAM;CACnE,MAAM,SAAS,gBAAgB;CAC/B,MAAM,EAAE,MAAM,eAAe,WA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,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,
|
|
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"}
|