@tambo-ai/react 1.2.5 → 1.2.6
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/context-helpers/current-interactables-context-helper.d.ts +1 -1
- package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.js +2 -2
- package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.test.js +3 -3
- package/dist/context-helpers/current-interactables-context-helper.test.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/model/tambo-interactable.d.ts +5 -2
- package/dist/model/tambo-interactable.d.ts.map +1 -1
- package/dist/model/tambo-interactable.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.js +5 -0
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.js +14 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js +79 -0
- package/dist/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.js +2 -2
- package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.test.js +3 -3
- package/esm/context-helpers/current-interactables-context-helper.test.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/model/tambo-interactable.d.ts +5 -2
- package/esm/model/tambo-interactable.d.ts.map +1 -1
- package/esm/model/tambo-interactable.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.js +5 -0
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.js +14 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js +79 -0
- package/esm/v1/hooks/use-tambo-v1-suggestions.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EACL,UAAU,EACV,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EACL,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAgC,cAAc,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EACL,SAAS,EAIT,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,IAAI,OAAO,K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GAA4B,EAAE;IAClE,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC/C,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;KAC/C,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAEjE;;;;;;;;;GASG;AACH,SAAS,mBAAmB,CAC1B,MAA+B,EAC/B,UAAsB;IAEtB,qEAAqE;IACrE,8EAA8E;IAC9E,wEAAwE;IACxE,0EAA0E;IAC1E,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO;QACL,GAAG,MAAM;QACT,GAAG;QACH,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["import React, {\n createContext,\n FC,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n ServerType,\n getMcpServerUniqueKey,\n type NormalizedMcpServerInfo,\n} from \"@tambo-ai/client\";\nimport { useTamboMcpToken } from \"../providers/tambo-mcp-token-provider\";\nimport {\n useTamboMcpServerInfos,\n useTamboRegistry,\n} from \"../providers/tambo-registry-provider\";\nimport { isContentPartArray, toText } from \"../util/content-parts\";\nimport { type ElicitationContextState, useElicitation } from \"./elicitation\";\nimport {\n MCPClient,\n MCPElicitationHandler,\n MCPHandlers,\n MCPSamplingHandler,\n MCPTransport,\n} from \"@tambo-ai/client\";\n\n/**\n * Extracts error message from MCP tool result content.\n * Handles both array and string content formats.\n * Always returns a string, even for invalid/null inputs.\n * @returns The extracted error message as a string\n */\nexport function extractErrorMessage(content: unknown): string {\n if (content === undefined || content === null) {\n return \"Unknown error occurred\";\n }\n\n if (Array.isArray(content)) {\n const textItems = content\n .filter((item) => item?.type === \"text\" && typeof item.text === \"string\")\n .map((item) => item.text);\n\n return textItems.length > 0\n ? textItems.join(\" \")\n : \"Error occurred but no details provided\";\n }\n\n if (typeof content === \"object\") {\n return JSON.stringify(content);\n }\n\n return `${content}`;\n}\n\n/**\n * Normalized MCP server information as consumed by the provider.\n *\n * Extends `NormalizedMcpServerInfo` from the core model by:\n * - adding a stable `key` derived from URL/transport/headers\n * - adding `serverType` to distinguish internal vs browser-side servers\n *\n * The `handlers` field is inherited from `McpServerInfo` (via\n * `NormalizedMcpServerInfo`) as `Partial<MCPHandlers>` — no redeclaration\n * needed here.\n *\n * The registry is responsible for producing `NormalizedMcpServerInfo`\n * instances; this type adds the MCP-specific wiring needed to connect and\n * track clients.\n */\ninterface McpServerConfig extends NormalizedMcpServerInfo {\n /**\n * Stable identity for this server derived from its URL/transport/headers.\n * Present for all server states (connected or failed).\n */\n key: string;\n /**\n * Type of server - determines how resources are resolved.\n * Internal servers are resolved server-side, browser-side servers are resolved client-side.\n */\n serverType: ServerType;\n}\n\n/**\n * Connected MCP server with an active client.\n */\nexport interface ConnectedMcpServer extends McpServerConfig {\n client: MCPClient;\n}\n\n/**\n * Failed MCP server with a connection error.\n */\nexport interface FailedMcpServer extends McpServerConfig {\n client?: never;\n connectionError: Error;\n}\n\n/**\n * An active or failed MCP server, with access to the MCP client.\n */\nexport type McpServer = ConnectedMcpServer | FailedMcpServer;\n\n/**\n * Provider-level MCP handlers that receive the McpServerInfo as context in addition to the request.\n * These handlers are applied to all MCP servers unless overridden by per-server handlers.\n *\n * Handlers receive three parameters:\n * 1. request - The MCP request\n * 2. extra - RequestHandlerExtra containing AbortSignal and other metadata\n * 3. serverInfo - Configuration of the MCP server that triggered this request\n */\nexport interface ProviderMCPHandlers {\n elicitation?: (\n request: Parameters<MCPElicitationHandler>[0],\n extra: Parameters<MCPElicitationHandler>[1],\n serverInfo: McpServerConfig,\n ) => ReturnType<MCPElicitationHandler>;\n sampling?: (\n request: Parameters<MCPSamplingHandler>[0],\n extra: Parameters<MCPSamplingHandler>[1],\n serverInfo: McpServerConfig,\n ) => ReturnType<MCPSamplingHandler>;\n}\n\n/**\n * Context value for MCP provider including server list and elicitation state\n */\ninterface McpProviderContextValue extends ElicitationContextState {\n servers: McpServer[];\n}\n\nconst McpProviderContext = createContext<McpProviderContextValue>({\n servers: [],\n elicitation: null,\n resolveElicitation: null,\n});\n\n// Constant for the internal Tambo MCP server name\nconst TAMBO_INTERNAL_MCP_SERVER_NAME = \"__tambo_internal_mcp_server__\";\n\n/**\n * Creates a stable hash of a string for use as a cache key.\n * Uses Java-style string hashing (DJB2-like) for deterministic results.\n *\n * Note: We use a synchronous hash instead of crypto.subtle.digest because:\n * - crypto.subtle.digest is async, which adds complexity in React hooks (useMemo, useEffect)\n * - This is not for security, just for creating a stable identifier to detect token changes\n * - Synchronous hashing avoids race conditions and simplifies component lifecycle\n * @param input - The string to hash\n * @returns A compact base36 hash string\n */\nfunction hashString(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n hash = (Math.imul(31, hash) + input.charCodeAt(i)) | 0;\n }\n return (hash >>> 0).toString(36);\n}\n\n/**\n * Safely closes an MCP client, handling both sync and async close methods.\n * Logs errors but doesn't throw.\n */\nfunction closeClientSafely(server: McpServer): void {\n if (!server?.client?.close) return;\n\n try {\n const closeResult = server.client.close();\n // If it returns a promise, handle errors but don't wait\n if (closeResult && typeof closeResult.catch === \"function\") {\n void closeResult.catch((error) => {\n const url = server.url ?? \"(unknown url)\";\n console.error(`Error closing MCP client for ${url}:`, error);\n });\n }\n } catch (error) {\n const url = server.url ?? \"(unknown url)\";\n console.error(`Error closing MCP client for ${url}:`, error);\n }\n}\n\n/**\n * Builds effective handlers for a server, with per-server overrides taking\n * precedence over provider-level handlers.\n * @returns The effective handlers with per-server overrides applied\n */\nfunction buildEffectiveHandlers(\n serverInfo: McpServerConfig,\n providerElicitationHandler: ProviderMCPHandlers[\"elicitation\"] | undefined,\n providerSamplingHandler: ProviderMCPHandlers[\"sampling\"] | undefined,\n): Partial<MCPHandlers> {\n const effectiveHandlers: Partial<MCPHandlers> = {};\n\n if (serverInfo.handlers?.elicitation) {\n effectiveHandlers.elicitation = serverInfo.handlers.elicitation;\n } else if (providerElicitationHandler) {\n effectiveHandlers.elicitation = async (\n request: Parameters<MCPElicitationHandler>[0],\n extra: Parameters<MCPElicitationHandler>[1],\n ) => await providerElicitationHandler(request, extra, serverInfo);\n }\n\n if (serverInfo.handlers?.sampling) {\n effectiveHandlers.sampling = serverInfo.handlers.sampling;\n } else if (providerSamplingHandler) {\n effectiveHandlers.sampling = async (\n request: Parameters<MCPSamplingHandler>[0],\n extra: Parameters<MCPSamplingHandler>[1],\n ) => await providerSamplingHandler(request, extra, serverInfo);\n }\n\n return effectiveHandlers;\n}\n\n/**\n * Hook to compute the stable map of server configurations from registry servers\n * and the internal Tambo MCP server (when token is available).\n * @returns A map of server key to server configuration\n */\nfunction useServerConfigs(\n mcpServers: NormalizedMcpServerInfo[],\n mcpAccessToken: string | null | undefined,\n tamboBaseUrl: string | null | undefined,\n): Map<string, McpServerConfig> {\n return useMemo(() => {\n const serverMap = new Map<string, McpServerConfig>();\n\n // Add user-provided MCP servers (browser-side)\n mcpServers.forEach((server) => {\n const serverInfo = normalizeServerInfo(server, ServerType.BROWSER_SIDE);\n serverMap.set(serverInfo.key, serverInfo);\n });\n\n // Add internal Tambo MCP server if we have an access token and a base URL\n if (mcpAccessToken && tamboBaseUrl) {\n const base = new URL(tamboBaseUrl);\n base.pathname = `${base.pathname.replace(/\\/+$/, \"\")}/mcp`;\n const tamboMcpUrl = base.toString();\n const tokenHash = hashString(mcpAccessToken);\n const internalServer: NormalizedMcpServerInfo = {\n name: TAMBO_INTERNAL_MCP_SERVER_NAME,\n url: tamboMcpUrl,\n transport: MCPTransport.HTTP,\n serverKey: `tambo-${tokenHash}`,\n customHeaders: {\n Authorization: `Bearer ${mcpAccessToken}`,\n },\n };\n const serverInfo = normalizeServerInfo(\n internalServer,\n ServerType.TAMBO_INTERNAL,\n );\n serverMap.set(serverInfo.key, serverInfo);\n }\n\n return serverMap;\n }, [mcpServers, mcpAccessToken, tamboBaseUrl]);\n}\n\ninterface ToolOwnershipRefs {\n toolOwnerRef: React.MutableRefObject<Map<string, string>>;\n keyToToolsRef: React.MutableRefObject<Map<string, Set<string>>>;\n}\n\n/**\n * Registers tools from a connected MCP server with deduplication.\n */\nasync function registerServerTools(\n client: MCPClient,\n serverInfo: McpServerConfig,\n key: string,\n shouldPrefix: boolean,\n clientMap: Map<string, McpServer>,\n ownershipRefs: ToolOwnershipRefs,\n registerTool: ReturnType<typeof useTamboRegistry>[\"registerTool\"],\n): Promise<void> {\n const { toolOwnerRef, keyToToolsRef } = ownershipRefs;\n\n try {\n const tools = await client.listTools();\n\n tools.forEach((tool) => {\n const toolName = shouldPrefix\n ? `${serverInfo.serverKey}__${tool.name}`\n : tool.name;\n\n // Skip if another server already owns this tool\n const currentOwner = toolOwnerRef.current.get(toolName);\n if (currentOwner && currentOwner !== key) {\n return;\n }\n\n // Record ownership\n if (!currentOwner) {\n toolOwnerRef.current.set(toolName, key);\n if (!keyToToolsRef.current.has(key)) {\n keyToToolsRef.current.set(key, new Set());\n }\n keyToToolsRef.current.get(key)!.add(toolName);\n }\n\n registerTool({\n description: tool.description ?? \"\",\n name: toolName,\n tool: async (args: Record<string, unknown> = {}) => {\n const server = clientMap.get(key);\n if (!server?.client) {\n throw new Error(\n `MCP server for tool ${tool.name} is not connected`,\n );\n }\n const result = await server.client.callTool(tool.name, args);\n if (result.isError) {\n const errorMessage = extractErrorMessage(result.content);\n throw new Error(errorMessage);\n }\n return result.content;\n },\n inputSchema: tool.inputSchema ?? {},\n outputSchema: {},\n transformToContent: (content: unknown) => {\n if (isContentPartArray(content)) {\n return content;\n }\n return [{ type: \"text\", text: toText(content) }];\n },\n ...(\"maxCalls\" in tool && tool.maxCalls !== undefined\n ? { maxCalls: tool.maxCalls }\n : {}),\n });\n });\n } catch (error) {\n console.error(\n `Failed to register tools from MCP server ${serverInfo.url}:`,\n error,\n );\n }\n}\n\n/**\n * Releases tool ownership for a server being removed.\n */\nfunction releaseToolOwnership(\n key: string,\n ownershipRefs: ToolOwnershipRefs,\n): void {\n const { toolOwnerRef, keyToToolsRef } = ownershipRefs;\n const owned = keyToToolsRef.current.get(key);\n if (owned) {\n for (const name of owned) {\n toolOwnerRef.current.delete(name);\n }\n keyToToolsRef.current.delete(key);\n }\n}\n\n/**\n * This provider is used to register tools from MCP servers.\n * It automatically includes an internal Tambo MCP server when an MCP access token is available.\n *\n * **BREAKING CHANGE**: This provider no longer accepts `mcpServers` as a prop.\n * Instead, pass `mcpServers` to `TamboProvider` or `TamboRegistryProvider`.\n * This provider must be wrapped inside `TamboProvider` to access the MCP server registry.\n * @param props - The provider props\n * @param props.handlers - Optional handlers applied to all MCP servers unless overridden per-server\n * @param props.contextKey - Optional context key for fetching threadless MCP tokens when not in a thread\n * @param props.children - The children to wrap\n * @returns The TamboMcpProvider component\n */\nexport const TamboMcpProvider: FC<{\n handlers?: ProviderMCPHandlers;\n contextKey?: string;\n children: React.ReactNode;\n}> = ({ handlers, contextKey, children }) => {\n const { registerTool } = useTamboRegistry();\n const { mcpAccessToken, tamboBaseUrl } = useTamboMcpToken(contextKey);\n const mcpServers = useTamboMcpServerInfos();\n const providerSamplingHandler = handlers?.sampling;\n\n // Elicitation state and default handler\n const { elicitation, resolveElicitation, defaultElicitationHandler } =\n useElicitation();\n\n // Use provided handler or fall back to default\n const providerElicitationHandler =\n handlers?.elicitation ?? defaultElicitationHandler;\n\n // Stable reference to track active clients by server key\n const clientMapRef = useRef<Map<string, McpServer>>(new Map());\n // Track tool ownership to prevent duplicate registrations across servers\n const toolOwnerRef = useRef<Map<string, string>>(new Map());\n const keyToToolsRef = useRef<Map<string, Set<string>>>(new Map());\n const ownershipRefs: ToolOwnershipRefs = { toolOwnerRef, keyToToolsRef };\n\n // State for exposing connected servers to consumers\n const [connectedMcpServers, setConnectedMcpServers] = useState<McpServer[]>(\n [],\n );\n\n // Compute server configurations from registry and internal server\n const currentServersMap = useServerConfigs(\n mcpServers,\n mcpAccessToken,\n tamboBaseUrl,\n );\n\n // Main effect: manage client lifecycle (create/remove)\n useClientLifecycle(\n currentServersMap,\n clientMapRef,\n ownershipRefs,\n providerElicitationHandler,\n providerSamplingHandler,\n registerTool,\n setConnectedMcpServers,\n );\n\n // Update handlers when they change (without recreating clients)\n useHandlerUpdates(\n currentServersMap,\n clientMapRef,\n providerElicitationHandler,\n providerSamplingHandler,\n );\n\n // Cleanup on unmount: close all clients\n useCleanupOnUnmount(clientMapRef, ownershipRefs);\n\n const contextValue = useMemo(\n () => ({\n servers: connectedMcpServers,\n elicitation,\n resolveElicitation,\n }),\n [connectedMcpServers, elicitation, resolveElicitation],\n );\n\n return (\n <McpProviderContext.Provider value={contextValue}>\n {children}\n </McpProviderContext.Provider>\n );\n};\n\n/**\n * Hook to manage client lifecycle: creating clients for new servers,\n * removing clients for servers that are no longer in the list.\n */\nfunction useClientLifecycle(\n currentServersMap: Map<string, McpServerConfig>,\n clientMapRef: React.MutableRefObject<Map<string, McpServer>>,\n ownershipRefs: ToolOwnershipRefs,\n providerElicitationHandler: ProviderMCPHandlers[\"elicitation\"] | undefined,\n providerSamplingHandler: ProviderMCPHandlers[\"sampling\"] | undefined,\n registerTool: ReturnType<typeof useTamboRegistry>[\"registerTool\"],\n setConnectedMcpServers: React.Dispatch<React.SetStateAction<McpServer[]>>,\n): void {\n useEffect(() => {\n const clientMap = clientMapRef.current;\n const currentKeys = new Set(currentServersMap.keys());\n const existingKeys = new Set(clientMap.keys());\n\n // 1. Remove clients that are no longer in the current server list\n const keysToRemove = Array.from(existingKeys).filter(\n (key) => !currentKeys.has(key),\n );\n keysToRemove.forEach((key) => {\n const server = clientMap.get(key);\n if (server) {\n closeClientSafely(server);\n }\n releaseToolOwnership(key, ownershipRefs);\n clientMap.delete(key);\n });\n\n // 2. Add new clients for servers that don't exist yet\n const keysToAdd = Array.from(currentKeys).filter(\n (key) => !existingKeys.has(key),\n );\n\n async function addClients(keys: string[]) {\n await Promise.allSettled(\n keys.map(async (key) => {\n const serverInfo = currentServersMap.get(key)!;\n\n try {\n const effectiveHandlers = buildEffectiveHandlers(\n serverInfo,\n providerElicitationHandler,\n providerSamplingHandler,\n );\n\n const client = await MCPClient.create(\n serverInfo.url,\n serverInfo.transport,\n serverInfo.customHeaders,\n undefined,\n undefined,\n effectiveHandlers,\n );\n\n const connectedServer: ConnectedMcpServer = {\n ...serverInfo,\n client,\n };\n\n clientMap.set(key, connectedServer);\n setConnectedMcpServers(Array.from(clientMap.values()));\n\n // Register tools from this server\n const shouldPrefix = currentServersMap.size > 1;\n await registerServerTools(\n client,\n serverInfo,\n key,\n shouldPrefix,\n clientMap,\n ownershipRefs,\n registerTool,\n );\n } catch (error) {\n const failedServer: FailedMcpServer = {\n ...serverInfo,\n connectionError: error as Error,\n };\n clientMap.set(key, failedServer);\n setConnectedMcpServers(Array.from(clientMap.values()));\n console.error(\n `Failed to connect to MCP server ${serverInfo.url}:`,\n error,\n );\n }\n }),\n );\n }\n\n if (keysToAdd.length > 0) {\n addClients(keysToAdd).catch((err) => {\n console.error(\"Unexpected error in addClients:\", err);\n });\n }\n\n // Update state after removals\n if (keysToRemove.length > 0) {\n setConnectedMcpServers(Array.from(clientMap.values()));\n }\n // Note: refs (clientMapRef, ownershipRefs) and setters (setConnectedMcpServers)\n // are intentionally excluded from deps as they are stable references\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n currentServersMap,\n providerElicitationHandler,\n providerSamplingHandler,\n registerTool,\n ]);\n}\n\n/**\n * Hook to update handlers on connected clients when provider handlers change.\n */\nfunction useHandlerUpdates(\n currentServersMap: Map<string, McpServerConfig>,\n clientMapRef: React.MutableRefObject<Map<string, McpServer>>,\n providerElicitationHandler: ProviderMCPHandlers[\"elicitation\"] | undefined,\n providerSamplingHandler: ProviderMCPHandlers[\"sampling\"] | undefined,\n): void {\n useEffect(() => {\n const clientMap = clientMapRef.current;\n\n clientMap.forEach((server, key) => {\n if (!server.client) {\n return; // Skip failed servers\n }\n\n const serverInfo = currentServersMap.get(key);\n if (!serverInfo) {\n return; // Server was removed, handled by lifecycle effect\n }\n\n // Build effective handlers and update the client\n const effectiveElicitationHandler =\n serverInfo.handlers?.elicitation ??\n (providerElicitationHandler\n ? async (\n request: Parameters<MCPElicitationHandler>[0],\n extra: Parameters<MCPElicitationHandler>[1],\n ) => await providerElicitationHandler(request, extra, serverInfo)\n : undefined);\n\n const effectiveSamplingHandler =\n serverInfo.handlers?.sampling ??\n (providerSamplingHandler\n ? async (\n request: Parameters<MCPSamplingHandler>[0],\n extra: Parameters<MCPSamplingHandler>[1],\n ) => await providerSamplingHandler(request, extra, serverInfo)\n : undefined);\n\n server.client.updateElicitationHandler?.(effectiveElicitationHandler);\n server.client.updateSamplingHandler?.(effectiveSamplingHandler);\n });\n // Note: clientMapRef is intentionally excluded from deps as it's a stable ref\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentServersMap, providerElicitationHandler, providerSamplingHandler]);\n}\n\n/**\n * Hook to cleanup all clients and tool ownership on component unmount.\n */\nfunction useCleanupOnUnmount(\n clientMapRef: React.MutableRefObject<Map<string, McpServer>>,\n ownershipRefs: ToolOwnershipRefs,\n): void {\n useEffect(() => {\n const clientMap = clientMapRef.current;\n const { toolOwnerRef, keyToToolsRef } = ownershipRefs;\n return () => {\n clientMap.forEach((server) => {\n closeClientSafely(server);\n });\n clientMap.clear();\n toolOwnerRef.current.clear();\n keyToToolsRef.current.clear();\n };\n // Only run cleanup on unmount\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\n/**\n * Hook to access the actual MCP servers, as they are connected (or fail to\n * connect).\n *\n * You can call methods on the MCP client that is included in the MCP server\n * object.\n *\n * If the server fails to connect, the `client` property will be `undefined` and\n * the `connectionError` property will be set.\n *\n * For example, to forcibly disconnect and reconnect all MCP servers:\n *\n * ```tsx\n * const mcpServers = useTamboMcpServers();\n * mcpServers.forEach((mcpServer) => {\n * mcpServer.client?.reconnect();\n * });\n * ```\n *\n * Note that the MCP servers are not guaranteed to be in the same order as the\n * input array, because they are added as they are connected.\n * @returns The MCP servers\n */\nexport const useTamboMcpServers = () => {\n return useContext(McpProviderContext).servers;\n};\n\n/**\n * Hook to access MCP elicitation state from TamboMcpProvider.\n * This provides access to the current elicitation request and methods to respond to it.\n *\n * The elicitation state is automatically managed by TamboMcpProvider when MCP servers\n * request user input through the elicitation protocol.\n * @returns The elicitation state with current request and response handler\n * @example\n * ```tsx\n * function ElicitationUI() {\n * const { elicitation, resolveElicitation } = useTamboMcpElicitation();\n *\n * if (!elicitation) return null;\n *\n * return (\n * <div>\n * <p>{elicitation.message}</p>\n * <button onClick={() => resolveElicitation?.({ action: \"accept\", content: {} })}>\n * Accept\n * </button>\n * </div>\n * );\n * }\n * ```\n */\nexport const useTamboMcpElicitation = (): ElicitationContextState => {\n const context = useContext(McpProviderContext);\n return {\n elicitation: context.elicitation,\n resolveElicitation: context.resolveElicitation,\n };\n};\n\n/**\n * @deprecated Use `useTamboMcpElicitation` instead.\n * This hook will be removed in a future version.\n */\nexport const useTamboElicitationContext = useTamboMcpElicitation;\n\n/**\n * Normalizes registry server metadata into a `McpServerConfig`.\n *\n * Accepts a `NormalizedMcpServerInfo`, which already guarantees a concrete\n * `transport`, a `serverKey` derived by the registry, and a typed\n * `handlers` field (`Partial<MCPHandlers>`).\n * @param server - The normalized MCP server info from the registry\n * @param serverType - The type of server (internal vs browser-side)\n * @returns The server config with typed handlers, unique key, and server type\n */\nfunction normalizeServerInfo(\n server: NormalizedMcpServerInfo,\n serverType: ServerType,\n): McpServerConfig {\n // Always use getMcpServerUniqueKey for connection identity to ensure\n // that changes to URL, transport, or customHeaders trigger client recreation.\n // The serverKey is kept for namespacing purposes (readable short name),\n // but the connection identity key must include all connection properties.\n const key = getMcpServerUniqueKey(server);\n return {\n ...server,\n key,\n serverType,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAA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AM,EAAE,EAAE;gBAC3B,iBAAiB,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7B,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC,CAAC;QACF,8BAA8B;QAC9B,uDAAuD;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO,UAAU,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC;AAChD,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAA4B,EAAE;IAClE,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC/C,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;KAC/C,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAEjE;;;;;;;;;GASG;AACH,SAAS,mBAAmB,CAC1B,MAA+B,EAC/B,UAAsB;IAEtB,qEAAqE;IACrE,8EAA8E;IAC9E,wEAAwE;IACxE,0EAA0E;IAC1E,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO;QACL,GAAG,MAAM;QACT,GAAG;QACH,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["import React, {\n createContext,\n FC,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n ServerType,\n getMcpServerUniqueKey,\n type NormalizedMcpServerInfo,\n} from \"@tambo-ai/client\";\nimport { useTamboMcpToken } from \"../providers/tambo-mcp-token-provider\";\nimport {\n useTamboMcpServerInfos,\n useTamboRegistry,\n} from \"../providers/tambo-registry-provider\";\nimport { isContentPartArray, toText } from \"../util/content-parts\";\nimport { type ElicitationContextState, useElicitation } from \"./elicitation\";\nimport {\n MCPClient,\n MCPElicitationHandler,\n MCPHandlers,\n MCPSamplingHandler,\n MCPTransport,\n} from \"@tambo-ai/client\";\n\n/**\n * Extracts error message from MCP tool result content.\n * Handles both array and string content formats.\n * Always returns a string, even for invalid/null inputs.\n * @returns The extracted error message as a string\n */\nexport function extractErrorMessage(content: unknown): string {\n if (content === undefined || content === null) {\n return \"Unknown error occurred\";\n }\n\n if (Array.isArray(content)) {\n const textItems = content\n .filter((item) => item?.type === \"text\" && typeof item.text === \"string\")\n .map((item) => item.text);\n\n return textItems.length > 0\n ? textItems.join(\" \")\n : \"Error occurred but no details provided\";\n }\n\n if (typeof content === \"object\") {\n return JSON.stringify(content);\n }\n\n return `${content}`;\n}\n\n/**\n * Normalized MCP server information as consumed by the provider.\n *\n * Extends `NormalizedMcpServerInfo` from the core model by:\n * - adding a stable `key` derived from URL/transport/headers\n * - adding `serverType` to distinguish internal vs browser-side servers\n *\n * The `handlers` field is inherited from `McpServerInfo` (via\n * `NormalizedMcpServerInfo`) as `Partial<MCPHandlers>` — no redeclaration\n * needed here.\n *\n * The registry is responsible for producing `NormalizedMcpServerInfo`\n * instances; this type adds the MCP-specific wiring needed to connect and\n * track clients.\n */\ninterface McpServerConfig extends NormalizedMcpServerInfo {\n /**\n * Stable identity for this server derived from its URL/transport/headers.\n * Present for all server states (connected or failed).\n */\n key: string;\n /**\n * Type of server - determines how resources are resolved.\n * Internal servers are resolved server-side, browser-side servers are resolved client-side.\n */\n serverType: ServerType;\n}\n\n/**\n * Connected MCP server with an active client.\n */\nexport interface ConnectedMcpServer extends McpServerConfig {\n client: MCPClient;\n}\n\n/**\n * Failed MCP server with a connection error.\n */\nexport interface FailedMcpServer extends McpServerConfig {\n client?: never;\n connectionError: Error;\n}\n\n/**\n * An active or failed MCP server, with access to the MCP client.\n */\nexport type McpServer = ConnectedMcpServer | FailedMcpServer;\n\n/**\n * Provider-level MCP handlers that receive the McpServerInfo as context in addition to the request.\n * These handlers are applied to all MCP servers unless overridden by per-server handlers.\n *\n * Handlers receive three parameters:\n * 1. request - The MCP request\n * 2. extra - RequestHandlerExtra containing AbortSignal and other metadata\n * 3. serverInfo - Configuration of the MCP server that triggered this request\n */\nexport interface ProviderMCPHandlers {\n elicitation?: (\n request: Parameters<MCPElicitationHandler>[0],\n extra: Parameters<MCPElicitationHandler>[1],\n serverInfo: McpServerConfig,\n ) => ReturnType<MCPElicitationHandler>;\n sampling?: (\n request: Parameters<MCPSamplingHandler>[0],\n extra: Parameters<MCPSamplingHandler>[1],\n serverInfo: McpServerConfig,\n ) => ReturnType<MCPSamplingHandler>;\n}\n\n/**\n * Context value for MCP provider including server list and elicitation state\n */\ninterface McpProviderContextValue extends ElicitationContextState {\n servers: McpServer[];\n}\n\nconst McpProviderContext = createContext<McpProviderContextValue>({\n servers: [],\n elicitation: null,\n resolveElicitation: null,\n});\n\n// Constant for the internal Tambo MCP server name\nconst TAMBO_INTERNAL_MCP_SERVER_NAME = \"__tambo_internal_mcp_server__\";\n\n/**\n * Creates a stable hash of a string for use as a cache key.\n * Uses Java-style string hashing (DJB2-like) for deterministic results.\n *\n * Note: We use a synchronous hash instead of crypto.subtle.digest because:\n * - crypto.subtle.digest is async, which adds complexity in React hooks (useMemo, useEffect)\n * - This is not for security, just for creating a stable identifier to detect token changes\n * - Synchronous hashing avoids race conditions and simplifies component lifecycle\n * @param input - The string to hash\n * @returns A compact base36 hash string\n */\nfunction hashString(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n hash = (Math.imul(31, hash) + input.charCodeAt(i)) | 0;\n }\n return (hash >>> 0).toString(36);\n}\n\n/**\n * Safely closes an MCP client, handling both sync and async close methods.\n * Logs errors but doesn't throw.\n */\nfunction closeClientSafely(server: McpServer): void {\n if (!server?.client?.close) return;\n\n try {\n const closeResult = server.client.close();\n // If it returns a promise, handle errors but don't wait\n if (closeResult && typeof closeResult.catch === \"function\") {\n void closeResult.catch((error) => {\n const url = server.url ?? \"(unknown url)\";\n console.error(`Error closing MCP client for ${url}:`, error);\n });\n }\n } catch (error) {\n const url = server.url ?? \"(unknown url)\";\n console.error(`Error closing MCP client for ${url}:`, error);\n }\n}\n\n/**\n * Builds effective handlers for a server, with per-server overrides taking\n * precedence over provider-level handlers.\n * @returns The effective handlers with per-server overrides applied\n */\nfunction buildEffectiveHandlers(\n serverInfo: McpServerConfig,\n providerElicitationHandler: ProviderMCPHandlers[\"elicitation\"] | undefined,\n providerSamplingHandler: ProviderMCPHandlers[\"sampling\"] | undefined,\n): Partial<MCPHandlers> {\n const effectiveHandlers: Partial<MCPHandlers> = {};\n\n if (serverInfo.handlers?.elicitation) {\n effectiveHandlers.elicitation = serverInfo.handlers.elicitation;\n } else if (providerElicitationHandler) {\n effectiveHandlers.elicitation = async (\n request: Parameters<MCPElicitationHandler>[0],\n extra: Parameters<MCPElicitationHandler>[1],\n ) => await providerElicitationHandler(request, extra, serverInfo);\n }\n\n if (serverInfo.handlers?.sampling) {\n effectiveHandlers.sampling = serverInfo.handlers.sampling;\n } else if (providerSamplingHandler) {\n effectiveHandlers.sampling = async (\n request: Parameters<MCPSamplingHandler>[0],\n extra: Parameters<MCPSamplingHandler>[1],\n ) => await providerSamplingHandler(request, extra, serverInfo);\n }\n\n return effectiveHandlers;\n}\n\n/**\n * Hook to compute the stable map of server configurations from registry servers\n * and the internal Tambo MCP server (when token is available).\n * @returns A map of server key to server configuration\n */\nfunction useServerConfigs(\n mcpServers: NormalizedMcpServerInfo[],\n mcpAccessToken: string | null | undefined,\n tamboBaseUrl: string | null | undefined,\n): Map<string, McpServerConfig> {\n return useMemo(() => {\n const serverMap = new Map<string, McpServerConfig>();\n\n // Add user-provided MCP servers (browser-side)\n mcpServers.forEach((server) => {\n const serverInfo = normalizeServerInfo(server, ServerType.BROWSER_SIDE);\n serverMap.set(serverInfo.key, serverInfo);\n });\n\n // Add internal Tambo MCP server if we have an access token and a base URL\n if (mcpAccessToken && tamboBaseUrl) {\n const base = new URL(tamboBaseUrl);\n base.pathname = `${base.pathname.replace(/\\/+$/, \"\")}/mcp`;\n const tamboMcpUrl = base.toString();\n const tokenHash = hashString(mcpAccessToken);\n const internalServer: NormalizedMcpServerInfo = {\n name: TAMBO_INTERNAL_MCP_SERVER_NAME,\n url: tamboMcpUrl,\n transport: MCPTransport.HTTP,\n serverKey: `tambo-${tokenHash}`,\n customHeaders: {\n Authorization: `Bearer ${mcpAccessToken}`,\n },\n };\n const serverInfo = normalizeServerInfo(\n internalServer,\n ServerType.TAMBO_INTERNAL,\n );\n serverMap.set(serverInfo.key, serverInfo);\n }\n\n return serverMap;\n }, [mcpServers, mcpAccessToken, tamboBaseUrl]);\n}\n\ninterface ToolOwnershipRefs {\n toolOwnerRef: React.MutableRefObject<Map<string, string>>;\n keyToToolsRef: React.MutableRefObject<Map<string, Set<string>>>;\n}\n\n/**\n * Registers tools from a connected MCP server with deduplication.\n */\nasync function registerServerTools(\n client: MCPClient,\n serverInfo: McpServerConfig,\n key: string,\n shouldPrefix: boolean,\n clientMap: Map<string, McpServer>,\n ownershipRefs: ToolOwnershipRefs,\n registerTool: ReturnType<typeof useTamboRegistry>[\"registerTool\"],\n): Promise<void> {\n const { toolOwnerRef, keyToToolsRef } = ownershipRefs;\n\n try {\n const tools = await client.listTools();\n\n tools.forEach((tool) => {\n const toolName = shouldPrefix\n ? `${serverInfo.serverKey}__${tool.name}`\n : tool.name;\n\n // Skip if another server already owns this tool\n const currentOwner = toolOwnerRef.current.get(toolName);\n if (currentOwner && currentOwner !== key) {\n return;\n }\n\n // Record ownership\n if (!currentOwner) {\n toolOwnerRef.current.set(toolName, key);\n if (!keyToToolsRef.current.has(key)) {\n keyToToolsRef.current.set(key, new Set());\n }\n keyToToolsRef.current.get(key)!.add(toolName);\n }\n\n registerTool({\n description: tool.description ?? \"\",\n name: toolName,\n tool: async (args: Record<string, unknown> = {}) => {\n const server = clientMap.get(key);\n if (!server?.client) {\n throw new Error(\n `MCP server for tool ${tool.name} is not connected`,\n );\n }\n const result = await server.client.callTool(tool.name, args);\n if (result.isError) {\n const errorMessage = extractErrorMessage(result.content);\n throw new Error(errorMessage);\n }\n return result.content;\n },\n inputSchema: tool.inputSchema ?? {},\n outputSchema: {},\n transformToContent: (content: unknown) => {\n if (isContentPartArray(content)) {\n return content;\n }\n return [{ type: \"text\", text: toText(content) }];\n },\n ...(\"maxCalls\" in tool && tool.maxCalls !== undefined\n ? { maxCalls: tool.maxCalls }\n : {}),\n });\n });\n } catch (error) {\n console.error(\n `Failed to register tools from MCP server ${serverInfo.url}:`,\n error,\n );\n }\n}\n\n/**\n * Releases tool ownership for a server being removed.\n */\nfunction releaseToolOwnership(\n key: string,\n ownershipRefs: ToolOwnershipRefs,\n): void {\n const { toolOwnerRef, keyToToolsRef } = ownershipRefs;\n const owned = keyToToolsRef.current.get(key);\n if (owned) {\n for (const name of owned) {\n toolOwnerRef.current.delete(name);\n }\n keyToToolsRef.current.delete(key);\n }\n}\n\n/**\n * This provider is used to register tools from MCP servers.\n * It automatically includes an internal Tambo MCP server when an MCP access token is available.\n *\n * **BREAKING CHANGE**: This provider no longer accepts `mcpServers` as a prop.\n * Instead, pass `mcpServers` to `TamboProvider` or `TamboRegistryProvider`.\n * This provider must be wrapped inside `TamboProvider` to access the MCP server registry.\n * @param props - The provider props\n * @param props.handlers - Optional handlers applied to all MCP servers unless overridden per-server\n * @param props.contextKey - Optional context key for fetching threadless MCP tokens when not in a thread\n * @param props.children - The children to wrap\n * @returns The TamboMcpProvider component\n */\nexport const TamboMcpProvider: FC<{\n handlers?: ProviderMCPHandlers;\n contextKey?: string;\n children: React.ReactNode;\n}> = ({ handlers, contextKey, children }) => {\n const { registerTool } = useTamboRegistry();\n const { mcpAccessToken, tamboBaseUrl } = useTamboMcpToken(contextKey);\n const mcpServers = useTamboMcpServerInfos();\n const providerSamplingHandler = handlers?.sampling;\n\n // Elicitation state and default handler\n const { elicitation, resolveElicitation, defaultElicitationHandler } =\n useElicitation();\n\n // Use provided handler or fall back to default\n const providerElicitationHandler =\n handlers?.elicitation ?? defaultElicitationHandler;\n\n // Stable reference to track active clients by server key\n const clientMapRef = useRef(new Map<string, McpServer>());\n // Track tool ownership to prevent duplicate registrations across servers\n const toolOwnerRef = useRef(new Map<string, string>());\n const keyToToolsRef = useRef(new Map<string, Set<string>>());\n const ownershipRefs: ToolOwnershipRefs = { toolOwnerRef, keyToToolsRef };\n\n // State for exposing connected servers to consumers\n const [connectedMcpServers, setConnectedMcpServers] = useState<McpServer[]>(\n [],\n );\n\n // Compute server configurations from registry and internal server\n const currentServersMap = useServerConfigs(\n mcpServers,\n mcpAccessToken,\n tamboBaseUrl,\n );\n\n // Main effect: manage client lifecycle (create/remove)\n useClientLifecycle(\n currentServersMap,\n clientMapRef,\n ownershipRefs,\n providerElicitationHandler,\n providerSamplingHandler,\n registerTool,\n setConnectedMcpServers,\n );\n\n // Update handlers when they change (without recreating clients)\n useHandlerUpdates(\n currentServersMap,\n clientMapRef,\n providerElicitationHandler,\n providerSamplingHandler,\n );\n\n // Cleanup on unmount: close all clients\n useCleanupOnUnmount(clientMapRef, ownershipRefs);\n\n const contextValue = useMemo(\n () => ({\n servers: connectedMcpServers,\n elicitation,\n resolveElicitation,\n }),\n [connectedMcpServers, elicitation, resolveElicitation],\n );\n\n return (\n <McpProviderContext.Provider value={contextValue}>\n {children}\n </McpProviderContext.Provider>\n );\n};\n\n/**\n * Hook to manage client lifecycle: creating clients for new servers,\n * removing clients for servers that are no longer in the list.\n */\nfunction useClientLifecycle(\n currentServersMap: Map<string, McpServerConfig>,\n clientMapRef: React.MutableRefObject<Map<string, McpServer>>,\n ownershipRefs: ToolOwnershipRefs,\n providerElicitationHandler: ProviderMCPHandlers[\"elicitation\"] | undefined,\n providerSamplingHandler: ProviderMCPHandlers[\"sampling\"] | undefined,\n registerTool: ReturnType<typeof useTamboRegistry>[\"registerTool\"],\n setConnectedMcpServers: React.Dispatch<React.SetStateAction<McpServer[]>>,\n): void {\n useEffect(() => {\n const clientMap = clientMapRef.current;\n const currentKeys = new Set(currentServersMap.keys());\n const existingKeys = new Set(clientMap.keys());\n\n // 1. Remove clients that are no longer in the current server list\n const keysToRemove = Array.from(existingKeys).filter(\n (key) => !currentKeys.has(key),\n );\n keysToRemove.forEach((key) => {\n const server = clientMap.get(key);\n if (server) {\n closeClientSafely(server);\n }\n releaseToolOwnership(key, ownershipRefs);\n clientMap.delete(key);\n });\n\n // 2. Add new clients for servers that don't exist yet\n const keysToAdd = Array.from(currentKeys).filter(\n (key) => !existingKeys.has(key),\n );\n\n async function addClients(keys: string[]) {\n await Promise.allSettled(\n keys.map(async (key) => {\n const serverInfo = currentServersMap.get(key)!;\n\n try {\n const effectiveHandlers = buildEffectiveHandlers(\n serverInfo,\n providerElicitationHandler,\n providerSamplingHandler,\n );\n\n const client = await MCPClient.create(\n serverInfo.url,\n serverInfo.transport,\n serverInfo.customHeaders,\n undefined,\n undefined,\n effectiveHandlers,\n );\n\n const connectedServer: ConnectedMcpServer = {\n ...serverInfo,\n client,\n };\n\n clientMap.set(key, connectedServer);\n setConnectedMcpServers(Array.from(clientMap.values()));\n\n // Register tools from this server\n const shouldPrefix = currentServersMap.size > 1;\n await registerServerTools(\n client,\n serverInfo,\n key,\n shouldPrefix,\n clientMap,\n ownershipRefs,\n registerTool,\n );\n } catch (error) {\n const failedServer: FailedMcpServer = {\n ...serverInfo,\n connectionError: error as Error,\n };\n clientMap.set(key, failedServer);\n setConnectedMcpServers(Array.from(clientMap.values()));\n console.error(\n `Failed to connect to MCP server ${serverInfo.url}:`,\n error,\n );\n }\n }),\n );\n }\n\n if (keysToAdd.length > 0) {\n addClients(keysToAdd).catch((err) => {\n console.error(\"Unexpected error in addClients:\", err);\n });\n }\n\n // Update state after removals\n if (keysToRemove.length > 0) {\n setConnectedMcpServers(Array.from(clientMap.values()));\n }\n // Note: refs (clientMapRef, ownershipRefs) and setters (setConnectedMcpServers)\n // are intentionally excluded from deps as they are stable references\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n currentServersMap,\n providerElicitationHandler,\n providerSamplingHandler,\n registerTool,\n ]);\n}\n\n/**\n * Hook to update handlers on connected clients when provider handlers change.\n */\nfunction useHandlerUpdates(\n currentServersMap: Map<string, McpServerConfig>,\n clientMapRef: React.MutableRefObject<Map<string, McpServer>>,\n providerElicitationHandler: ProviderMCPHandlers[\"elicitation\"] | undefined,\n providerSamplingHandler: ProviderMCPHandlers[\"sampling\"] | undefined,\n): void {\n useEffect(() => {\n const clientMap = clientMapRef.current;\n\n clientMap.forEach((server, key) => {\n if (!server.client) {\n return; // Skip failed servers\n }\n\n const serverInfo = currentServersMap.get(key);\n if (!serverInfo) {\n return; // Server was removed, handled by lifecycle effect\n }\n\n // Build effective handlers and update the client\n const effectiveElicitationHandler =\n serverInfo.handlers?.elicitation ??\n (providerElicitationHandler\n ? async (\n request: Parameters<MCPElicitationHandler>[0],\n extra: Parameters<MCPElicitationHandler>[1],\n ) => await providerElicitationHandler(request, extra, serverInfo)\n : undefined);\n\n const effectiveSamplingHandler =\n serverInfo.handlers?.sampling ??\n (providerSamplingHandler\n ? async (\n request: Parameters<MCPSamplingHandler>[0],\n extra: Parameters<MCPSamplingHandler>[1],\n ) => await providerSamplingHandler(request, extra, serverInfo)\n : undefined);\n\n server.client.updateElicitationHandler?.(effectiveElicitationHandler);\n server.client.updateSamplingHandler?.(effectiveSamplingHandler);\n });\n // Note: clientMapRef is intentionally excluded from deps as it's a stable ref\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentServersMap, providerElicitationHandler, providerSamplingHandler]);\n}\n\n/**\n * Hook to cleanup all clients and tool ownership on component unmount.\n */\nfunction useCleanupOnUnmount(\n clientMapRef: React.MutableRefObject<Map<string, McpServer>>,\n ownershipRefs: ToolOwnershipRefs,\n): void {\n useEffect(() => {\n const clientMap = clientMapRef.current;\n const { toolOwnerRef, keyToToolsRef } = ownershipRefs;\n return () => {\n clientMap.forEach((server) => {\n closeClientSafely(server);\n });\n clientMap.clear();\n toolOwnerRef.current.clear();\n keyToToolsRef.current.clear();\n };\n // Only run cleanup on unmount\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\n/**\n * Hook to access the actual MCP servers, as they are connected (or fail to\n * connect).\n *\n * You can call methods on the MCP client that is included in the MCP server\n * object.\n *\n * If the server fails to connect, the `client` property will be `undefined` and\n * the `connectionError` property will be set.\n *\n * For example, to forcibly disconnect and reconnect all MCP servers:\n *\n * ```tsx\n * const mcpServers = useTamboMcpServers();\n * mcpServers.forEach((mcpServer) => {\n * mcpServer.client?.reconnect();\n * });\n * ```\n *\n * Note that the MCP servers are not guaranteed to be in the same order as the\n * input array, because they are added as they are connected.\n * @returns The MCP servers\n */\nexport const useTamboMcpServers = () => {\n return useContext(McpProviderContext).servers;\n};\n\n/**\n * Hook to access MCP elicitation state from TamboMcpProvider.\n * This provides access to the current elicitation request and methods to respond to it.\n *\n * The elicitation state is automatically managed by TamboMcpProvider when MCP servers\n * request user input through the elicitation protocol.\n * @returns The elicitation state with current request and response handler\n * @example\n * ```tsx\n * function ElicitationUI() {\n * const { elicitation, resolveElicitation } = useTamboMcpElicitation();\n *\n * if (!elicitation) return null;\n *\n * return (\n * <div>\n * <p>{elicitation.message}</p>\n * <button onClick={() => resolveElicitation?.({ action: \"accept\", content: {} })}>\n * Accept\n * </button>\n * </div>\n * );\n * }\n * ```\n */\nexport const useTamboMcpElicitation = (): ElicitationContextState => {\n const context = useContext(McpProviderContext);\n return {\n elicitation: context.elicitation,\n resolveElicitation: context.resolveElicitation,\n };\n};\n\n/**\n * @deprecated Use `useTamboMcpElicitation` instead.\n * This hook will be removed in a future version.\n */\nexport const useTamboElicitationContext = useTamboMcpElicitation;\n\n/**\n * Normalizes registry server metadata into a `McpServerConfig`.\n *\n * Accepts a `NormalizedMcpServerInfo`, which already guarantees a concrete\n * `transport`, a `serverKey` derived by the registry, and a typed\n * `handlers` field (`Partial<MCPHandlers>`).\n * @param server - The normalized MCP server info from the registry\n * @param serverType - The type of server (internal vs browser-side)\n * @returns The server config with typed handlers, unique key, and server type\n */\nfunction normalizeServerInfo(\n server: NormalizedMcpServerInfo,\n serverType: ServerType,\n): McpServerConfig {\n // Always use getMcpServerUniqueKey for connection identity to ensure\n // that changes to URL, transport, or customHeaders trigger client recreation.\n // The serverKey is kept for namespacing purposes (readable short name),\n // but the connection identity key must include all connection properties.\n const key = getMcpServerUniqueKey(server);\n return {\n ...server,\n key,\n serverType,\n };\n}\n"]}
|
|
@@ -4,7 +4,7 @@ export interface TamboInteractableComponent<Props = Record<string, unknown>, Sta
|
|
|
4
4
|
id: string;
|
|
5
5
|
/** Current props for the component */
|
|
6
6
|
props: Props;
|
|
7
|
-
/** Whether the component is currently selected for interaction,
|
|
7
|
+
/** Whether the component is currently selected for interaction. When set, Tambo focuses on this component when responding to the next message. Automatically cleared after the message is sent. */
|
|
8
8
|
isSelected?: boolean;
|
|
9
9
|
/** Current state for the component */
|
|
10
10
|
state?: State;
|
|
@@ -30,7 +30,10 @@ export interface TamboInteractableContext {
|
|
|
30
30
|
setInteractableState: (componentId: string, key: string, value: unknown) => void;
|
|
31
31
|
/** Get state for a specific interactable component */
|
|
32
32
|
getInteractableComponentState: (componentId: string) => Record<string, unknown> | undefined;
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Set whether an interactable component is selected for interaction.
|
|
35
|
+
* Selections are one-shot: they are automatically cleared after the next message is sent.
|
|
36
|
+
*/
|
|
34
37
|
setInteractableSelected: (componentId: string, isSelected: boolean) => void;
|
|
35
38
|
/** Clear all interactable component selections */
|
|
36
39
|
clearInteractableSelections: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-interactable.d.ts","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEvE,MAAM,WAAW,0BAA0B,CACzC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC/B,SAAQ,cAAc;IACtB,oDAAoD;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,KAAK,EAAE,KAAK,CAAC;IACb,
|
|
1
|
+
{"version":3,"file":"tambo-interactable.d.ts","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEvE,MAAM,WAAW,0BAA0B,CACzC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC/B,SAAQ,cAAc;IACtB,oDAAoD;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,KAAK,EAAE,KAAK,CAAC;IACb,mMAAmM;IACnM,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sCAAsC;IACtC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,mDAAmD;IACnD,WAAW,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,wBAAwB;IACvC,0CAA0C;IAC1C,sBAAsB,EAAE,0BAA0B,EAAE,CAAC;IACrD,uCAAuC;IACvC,wBAAwB,EAAE,CACxB,SAAS,EAAE,IAAI,CAAC,0BAA0B,EAAE,IAAI,GAAG,WAAW,CAAC,KAC5D,MAAM,CAAC;IACZ,6CAA6C;IAC7C,2BAA2B,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,+CAA+C;IAC/C,gCAAgC,EAAE,CAChC,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC1B,MAAM,CAAC;IACZ,0CAA0C;IAC1C,wBAAwB,EAAE,CACxB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3B,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAE3B,EAAE,EAAE,MAAM,KACP,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAClD,wDAAwD;IACxD,+BAA+B,EAAE,CAC/B,aAAa,EAAE,MAAM,KAClB,0BAA0B,EAAE,CAAC;IAClC,wCAAwC;IACxC,8BAA8B,EAAE,MAAM,IAAI,CAAC;IAC3C,sDAAsD;IACtD,oBAAoB,EAAE,CACpB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,KACX,IAAI,CAAC;IACV,sDAAsD;IACtD,6BAA6B,EAAE,CAC7B,WAAW,EAAE,MAAM,KAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACzC;;;OAGG;IACH,uBAAuB,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5E,kDAAkD;IAClD,2BAA2B,EAAE,MAAM,IAAI,CAAC;CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-interactable.js","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"","sourcesContent":["import { SupportedSchema, TamboComponent } from \"./component-metadata\";\n\nexport interface TamboInteractableComponent<\n Props = Record<string, unknown>,\n State = Record<string, unknown>,\n> extends TamboComponent {\n /** Unique identifier for this component instance */\n id: string;\n /** Current props for the component */\n props: Props;\n /** Whether the component is currently selected for interaction,
|
|
1
|
+
{"version":3,"file":"tambo-interactable.js","sourceRoot":"","sources":["../../src/model/tambo-interactable.ts"],"names":[],"mappings":"","sourcesContent":["import { SupportedSchema, TamboComponent } from \"./component-metadata\";\n\nexport interface TamboInteractableComponent<\n Props = Record<string, unknown>,\n State = Record<string, unknown>,\n> extends TamboComponent {\n /** Unique identifier for this component instance */\n id: string;\n /** Current props for the component */\n props: Props;\n /** Whether the component is currently selected for interaction. When set, Tambo focuses on this component when responding to the next message. Automatically cleared after the message is sent. */\n isSelected?: boolean;\n /** Current state for the component */\n state?: State;\n /** Optional schema for validating state updates */\n stateSchema?: SupportedSchema<State>;\n}\n\nexport interface TamboInteractableContext {\n /** List of all interactable components */\n interactableComponents: TamboInteractableComponent[];\n /** Add a new interactable component */\n addInteractableComponent: (\n component: Omit<TamboInteractableComponent, \"id\" | \"createdAt\">,\n ) => string;\n /** Remove an interactable component by ID */\n removeInteractableComponent: (id: string) => void;\n /** Update an interactable component's props */\n updateInteractableComponentProps: (\n id: string,\n newProps: Record<string, any>,\n ) => string;\n /** Get an interactable component by ID */\n getInteractableComponent: <\n P = Record<string, unknown>,\n S = Record<string, unknown>,\n >(\n id: string,\n ) => TamboInteractableComponent<P, S> | undefined;\n /** Get all interactable components by component name */\n getInteractableComponentsByName: (\n componentName: string,\n ) => TamboInteractableComponent[];\n /** Clear all interactable components */\n clearAllInteractableComponents: () => void;\n /** Set state for a specific interactable component */\n setInteractableState: (\n componentId: string,\n key: string,\n value: unknown,\n ) => void;\n /** Get state for a specific interactable component */\n getInteractableComponentState: (\n componentId: string,\n ) => Record<string, unknown> | undefined;\n /**\n * Set whether an interactable component is selected for interaction.\n * Selections are one-shot: they are automatically cleared after the next message is sent.\n */\n setInteractableSelected: (componentId: string, isSelected: boolean) => void;\n /** Clear all interactable component selections */\n clearInteractableSelections: () => void;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-interactables-additional-context.test.js","sourceRoot":"","sources":["../../src/providers/tambo-interactables-additional-context.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,E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B,oBAAC,sBAAsB;gBACrB,oBAAC,yBAAyB;oBACxB,oBAAC,gBAAgB,IAAC,KAAK,EAAC,mBAAmB,GAAG;oBAC9C,oBAAC,aAAa,OAAG,CACS,CACL,CACP,CACrB,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CACjC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CACvC,CAAC;YACF,MAAM,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,kDAAkD;QACnF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { render, waitFor } from \"@testing-library/react\";\nimport React from \"react\";\nimport { z } from \"zod/v4\";\nimport { withTamboInteractable } from \"../hoc/with-tambo-interactable\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useCurrentInteractablesSnapshot,\n} from \"./tambo-interactable-provider\";\nimport { TamboStubProvider } from \"../v1/providers/tambo-v1-stub-provider\";\n\nfunction wrapperWithProviders(children: React.ReactNode) {\n return (\n <TamboStubProvider>\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n </TamboStubProvider>\n );\n}\n\ndescribe(\"Interactables AdditionalContext (provider-based)\", () => {\n test(\"registers default helper and returns payload with description and components\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"hello\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n expect(Array.isArray(entry?.context?.components)).toBe(true);\n const comp = entry!.context.components[0];\n expect(comp.componentName).toBe(\"Note\");\n expect(comp.props).toEqual({ title: \"hello\" });\n });\n });\n\n test(\"returns null when no interactable components are present\", async () => {\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <div>No interactables here</div>\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeUndefined(); // Should be filtered out when helper returns null\n });\n });\n\n test(\"context includes proper AI prompt with clear instructions\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A simple note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"test\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n expect(Array.isArray(entry?.context?.components)).toBe(true);\n });\n });\n\n test(\"includes component metadata in expected format\", async () => {\n const Note: React.FC<{ title: string; color?: string }> = ({\n title,\n color = \"white\",\n }) => <div className={`note-${color}`}>{title}</div>;\n\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A colorful note component\",\n propsSchema: z.object({\n title: z.string(),\n color: z.string().optional(),\n }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"test note\" color=\"blue\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n const component = entry!.context.components[0];\n\n expect(component).toMatchObject({\n id: expect.any(String),\n componentName: \"Note\",\n description: \"A colorful note component\",\n props: { title: \"test note\", color: \"blue\" },\n propsSchema: \"Available - use component-specific update tools\",\n });\n });\n });\n\n test(\"snapshot hook returns immutable copies\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n const TestComponent = () => {\n const snapshot = useCurrentInteractablesSnapshot();\n const [testResult, setTestResult] = React.useState<string>(\"pending\");\n\n React.useEffect(() => {\n if (snapshot.length > 0) {\n const originalLength = snapshot.length;\n\n // Try to mutate the returned array and props\n snapshot.push({\n id: \"fake\",\n name: \"Fake\",\n description: \"\",\n component: () => null,\n props: {},\n } as any);\n (snapshot[0].props as any).title = \"MUTATED\";\n\n // The mutations should succeed on the returned copy, proving it's a separate object\n if (\n snapshot.length === originalLength + 1 &&\n snapshot[0].props.title === \"MUTATED\"\n ) {\n setTestResult(\"mutation-successful-but-isolated\");\n } else {\n setTestResult(\"mutation-failed\");\n }\n }\n }, [snapshot]);\n\n return <div data-testid=\"test-result\">{testResult}</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"immutable test\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n const result = getByTestId(\"test-result\").textContent;\n expect(result).toBe(\"mutation-successful-but-isolated\");\n });\n });\n\n test(\"multiple interactables from same provider appear in context\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const Counter: React.FC<{ count: number }> = ({ count }) => (\n <div>{count}</div>\n );\n\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n const InteractableCounter = withTamboInteractable(Counter, {\n componentName: \"Counter\",\n description: \"A counter\",\n propsSchema: z.object({ count: z.number() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"first\" />\n <InteractableCounter count={42} />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry?.context?.components).toHaveLength(2);\n\n const components = entry!.context.components;\n expect(components[0].componentName).toBe(\"Note\");\n expect(components[0].props).toEqual({ title: \"first\" });\n expect(components[1].componentName).toBe(\"Counter\");\n expect(components[1].props).toEqual({ count: 42 });\n });\n });\n\n test(\"can be disabled by returning null\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n // Create a context helpers provider with a disabled interactables helper\n const DisabledContextHelpers = ({\n children,\n }: {\n children: React.ReactNode;\n }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n [\"interactables\"]: () => null,\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n );\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n <TamboStubProvider>\n <DisabledContextHelpers>\n <TamboInteractableProvider>\n <InteractableNote title=\"should not appear\" />\n <TestComponent />\n </TamboInteractableProvider>\n </DisabledContextHelpers>\n </TamboStubProvider>,\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeUndefined(); // Should be filtered out when helper returns null\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-interactables-additional-context.test.js","sourceRoot":"","sources":["../../src/providers/tambo-interactables-additional-context.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,SAAS,oBAAoB,CAAC,QAAyB;IACrD,OAAO,CACL,oBAAC,iBAAiB;QAChB,oBAAC,2BAA2B,QAAE,QAAQ,CAA+B,CACnD,CACrB,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAChE,IAAI,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;QAC9F,MAAM,IAAI,GAAgC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,iCAAM,KAAK,CAAO,CAAC;QAE5E,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,IAAI,EAAE;YACnD,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,QAAQ;YACrB,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;SAC7C,CAAC,CAAC;QAEH,IAAI,gBAAgB,GAAU,EAAE,CAAC;QACjC,MAAM,aAAa,GAAG,GAAG,EAAE;YACzB,MAAM,EAAE,oBAAoB,EAAE,GAAG,sBAAsB,EAAE,CAAC;YAE1D,KAAK,CAAC,SAAS,CA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AC,oBAAoB,CAAC,CAAC,CAAC;YAE3B,OAAO,4CAAiB,OAAO,YAAY,CAAC;QAC9C,CAAC,CAAC;QAEF,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAC5B,oBAAC,iBAAiB;YAChB,oBAAC,sBAAsB;gBACrB,oBAAC,yBAAyB;oBACxB,oBAAC,gBAAgB,IAAC,KAAK,EAAC,mBAAmB,GAAG;oBAC9C,oBAAC,aAAa,OAAG,CACS,CACL,CACP,CACrB,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,EAAE;YACjB,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CACjC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CACvC,CAAC;YACF,MAAM,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,kDAAkD;QACnF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { render, waitFor } from \"@testing-library/react\";\nimport React from \"react\";\nimport { z } from \"zod/v4\";\nimport { withTamboInteractable } from \"../hoc/with-tambo-interactable\";\nimport {\n TamboContextHelpersProvider,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useCurrentInteractablesSnapshot,\n} from \"./tambo-interactable-provider\";\nimport { TamboStubProvider } from \"../v1/providers/tambo-v1-stub-provider\";\n\nfunction wrapperWithProviders(children: React.ReactNode) {\n return (\n <TamboStubProvider>\n <TamboContextHelpersProvider>{children}</TamboContextHelpersProvider>\n </TamboStubProvider>\n );\n}\n\ndescribe(\"Interactables AdditionalContext (provider-based)\", () => {\n test(\"registers default helper and returns payload with description and components\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"hello\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n expect(Array.isArray(entry?.context?.components)).toBe(true);\n const comp = entry!.context.components[0];\n expect(comp.componentName).toBe(\"Note\");\n expect(comp.props).toEqual({ title: \"hello\" });\n });\n });\n\n test(\"returns null when no interactable components are present\", async () => {\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <div>No interactables here</div>\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeUndefined(); // Should be filtered out when helper returns null\n });\n });\n\n test(\"context includes proper AI prompt with clear instructions\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A simple note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"test\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeDefined();\n expect(Array.isArray(entry?.context?.components)).toBe(true);\n });\n });\n\n test(\"includes component metadata in expected format\", async () => {\n const Note: React.FC<{ title: string; color?: string }> = ({\n title,\n color = \"white\",\n }) => <div className={`note-${color}`}>{title}</div>;\n\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A colorful note component\",\n propsSchema: z.object({\n title: z.string(),\n color: z.string().optional(),\n }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"test note\" color=\"blue\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n const component = entry!.context.components[0];\n\n expect(component).toMatchObject({\n id: expect.any(String),\n componentName: \"Note\",\n description: \"A colorful note component\",\n props: { title: \"test note\", color: \"blue\" },\n propsSchema: \"Available - use component-specific update tools\",\n });\n });\n });\n\n test(\"snapshot hook returns immutable copies\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n const TestComponent = () => {\n const snapshot = useCurrentInteractablesSnapshot();\n const [testResult, setTestResult] = React.useState(\"pending\");\n\n React.useEffect(() => {\n if (snapshot.length > 0) {\n const originalLength = snapshot.length;\n\n // Try to mutate the returned array and props\n snapshot.push({\n id: \"fake\",\n name: \"Fake\",\n description: \"\",\n component: () => null,\n props: {},\n } as any);\n (snapshot[0].props as any).title = \"MUTATED\";\n\n // The mutations should succeed on the returned copy, proving it's a separate object\n if (\n snapshot.length === originalLength + 1 &&\n snapshot[0].props.title === \"MUTATED\"\n ) {\n setTestResult(\"mutation-successful-but-isolated\");\n } else {\n setTestResult(\"mutation-failed\");\n }\n }\n }, [snapshot]);\n\n return <div data-testid=\"test-result\">{testResult}</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"immutable test\" />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n const result = getByTestId(\"test-result\").textContent;\n expect(result).toBe(\"mutation-successful-but-isolated\");\n });\n });\n\n test(\"multiple interactables from same provider appear in context\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const Counter: React.FC<{ count: number }> = ({ count }) => (\n <div>{count}</div>\n );\n\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n const InteractableCounter = withTamboInteractable(Counter, {\n componentName: \"Counter\",\n description: \"A counter\",\n propsSchema: z.object({ count: z.number() }),\n });\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n wrapperWithProviders(\n <TamboInteractableProvider>\n <InteractableNote title=\"first\" />\n <InteractableCounter count={42} />\n <TestComponent />\n </TamboInteractableProvider>,\n ),\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry?.context?.components).toHaveLength(2);\n\n const components = entry!.context.components;\n expect(components[0].componentName).toBe(\"Note\");\n expect(components[0].props).toEqual({ title: \"first\" });\n expect(components[1].componentName).toBe(\"Counter\");\n expect(components[1].props).toEqual({ count: 42 });\n });\n });\n\n test(\"can be disabled by returning null\", async () => {\n const Note: React.FC<{ title: string }> = ({ title }) => <div>{title}</div>;\n const InteractableNote = withTamboInteractable(Note, {\n componentName: \"Note\",\n description: \"A note\",\n propsSchema: z.object({ title: z.string() }),\n });\n\n // Create a context helpers provider with a disabled interactables helper\n const DisabledContextHelpers = ({\n children,\n }: {\n children: React.ReactNode;\n }) => (\n <TamboContextHelpersProvider\n contextHelpers={{\n [\"interactables\"]: () => null,\n }}\n >\n {children}\n </TamboContextHelpersProvider>\n );\n\n let capturedContexts: any[] = [];\n const TestComponent = () => {\n const { getAdditionalContext } = useTamboContextHelpers();\n\n React.useEffect(() => {\n let mounted = true;\n void getAdditionalContext().then((contexts) => {\n if (mounted) {\n capturedContexts = contexts;\n }\n });\n return () => {\n mounted = false;\n };\n }, [getAdditionalContext]);\n\n return <div data-testid=\"ready\">ready</div>;\n };\n\n const { getByTestId } = render(\n <TamboStubProvider>\n <DisabledContextHelpers>\n <TamboInteractableProvider>\n <InteractableNote title=\"should not appear\" />\n <TestComponent />\n </TamboInteractableProvider>\n </DisabledContextHelpers>\n </TamboStubProvider>,\n );\n\n await waitFor(() => {\n expect(getByTestId(\"ready\")).toBeInTheDocument();\n const entry = capturedContexts.find(\n (c: any) => c.name === \"interactables\",\n );\n expect(entry).toBeUndefined(); // Should be filtered out when helper returns null\n });\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1-send-message.d.ts","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AAMtE,OAAO,EAEL,KAAK,oBAAoB,IAAI,aAAa,EAC3C,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-send-message.d.ts","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AAMtE,OAAO,EAEL,KAAK,oBAAoB,IAAI,aAAa,EAC3C,MAAM,yCAAyC,CAAC;AASjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAsKnD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B;;;OAGG;IACH,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,eAAe,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACzC;AAED;;GAEG;AACH,KAAK,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAC7D,KAAK,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,SAAS,GAAG,YAAY,CAAC;IACjC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAgFD;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CA4DhC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,MAAM;;;;uCAsQpD"}
|
|
@@ -14,6 +14,7 @@ import { useStreamDispatch, useStreamState, } from "../providers/tambo-v1-stream
|
|
|
14
14
|
import { useTamboConfig } from "../providers/tambo-v1-provider.js";
|
|
15
15
|
import { useTamboAuthState } from "./use-tambo-v1-auth-state.js";
|
|
16
16
|
import { useTamboContextHelpers } from "../../providers/tambo-context-helpers-provider.js";
|
|
17
|
+
import { useTamboInteractable } from "../../providers/tambo-interactable-provider.js";
|
|
17
18
|
import { isPlaceholderThreadId } from "@tambo-ai/client";
|
|
18
19
|
import { toAvailableComponents, toAvailableTools } from "@tambo-ai/client";
|
|
19
20
|
import { handleEventStream } from "@tambo-ai/client";
|
|
@@ -279,6 +280,7 @@ export function useTamboSendMessage(threadId) {
|
|
|
279
280
|
const registry = useContext(TamboRegistryContext);
|
|
280
281
|
const queryClient = useTamboQueryClient();
|
|
281
282
|
const { getAdditionalContext } = useTamboContextHelpers();
|
|
283
|
+
const { clearInteractableSelections } = useTamboInteractable();
|
|
282
284
|
const authState = useTamboAuthState();
|
|
283
285
|
if (!registry) {
|
|
284
286
|
throw new Error("useTamboSendMessage must be used within TamboRegistryProvider");
|
|
@@ -334,6 +336,9 @@ export function useTamboSendMessage(threadId) {
|
|
|
334
336
|
for (const helperContext of helperContexts) {
|
|
335
337
|
additionalContext[helperContext.name] = helperContext.context;
|
|
336
338
|
}
|
|
339
|
+
// Clear interactable selections after capturing context so they only
|
|
340
|
+
// apply to this single message send.
|
|
341
|
+
clearInteractableSelections();
|
|
337
342
|
// Create the run stream
|
|
338
343
|
// Include initialMessages only on first send (new thread creation)
|
|
339
344
|
const { stream, initialThreadId } = await createRunStream({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1-send-message.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;GAIG;AAEH,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAsB,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,kBAAkB,GAEnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,cAAc,EACd,mBAAmB,GACpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EACL,oBAAoB,GAErB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,iBAAiB,EAC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AC;QACjE,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * Send Message Hook\n *\n * React Query mutation hook for sending messages and handling streaming responses.\n */\n\nimport React, { useContext } from \"react\";\nimport { EventType, type RunErrorEvent } from \"@ag-ui/core\";\nimport {\n asTamboCustomEvent,\n type RunAwaitingInputEvent,\n} from \"@tambo-ai/client\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport type { Stream } from \"@tambo-ai/typescript-sdk/core/streaming\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboMutation } from \"../../hooks/react-query-hooks\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistry,\n} from \"../../providers/tambo-registry-provider\";\nimport {\n useStreamDispatch,\n useStreamState,\n} from \"../providers/tambo-v1-stream-context\";\nimport { useTamboConfig } from \"../providers/tambo-v1-provider\";\nimport { useTamboAuthState } from \"./use-tambo-v1-auth-state\";\nimport { useTamboContextHelpers } from \"../../providers/tambo-context-helpers-provider\";\nimport type { InitialInputMessage, InputMessage } from \"../types/message\";\nimport type { ToolChoice } from \"@tambo-ai/client\";\nimport { isPlaceholderThreadId, type StreamAction } from \"@tambo-ai/client\";\nimport { toAvailableComponents, toAvailableTools } from \"@tambo-ai/client\";\nimport { handleEventStream } from \"@tambo-ai/client\";\nimport {\n executeAllPendingTools,\n createThrottledStreamableExecutor,\n} from \"@tambo-ai/client\";\nimport type { ToolResultContent } from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\nimport type { RunCreateParams } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\nimport { ToolCallTracker } from \"@tambo-ai/client\";\n\n/**\n * Dispatches synthetic AG-UI events to show a user message in the thread.\n * @param dispatch - Stream state dispatcher\n * @param targetThreadId - Thread to add the message to\n * @param messageId - Stable ID for the user message\n * @param messageText - Text content of the message\n */\nfunction dispatchUserMessage(\n dispatch: React.Dispatch<StreamAction>,\n targetThreadId: string,\n messageId: string,\n messageText: string,\n): void {\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId,\n role: \"user\" as const,\n },\n });\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId,\n delta: messageText,\n },\n });\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId,\n },\n });\n}\n\n/**\n * Dispatches synthetic events for tool results as optimistic local state.\n * The server doesn't echo these back for client-side tools.\n * @param dispatch - Stream state dispatcher\n * @param targetThreadId - Thread to add results to\n * @param toolResults - Tool execution results to dispatch\n */\nfunction dispatchToolResults(\n dispatch: React.Dispatch<StreamAction>,\n targetThreadId: string,\n toolResults: ToolResultContent[],\n): void {\n if (toolResults.length === 0) return;\n\n const toolResultMessageId = `msg_tool_result_${Date.now()}`;\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: toolResultMessageId,\n role: \"user\" as const,\n },\n });\n\n for (const result of toolResults) {\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TOOL_CALL_RESULT,\n toolCallId: result.toolUseId,\n messageId: toolResultMessageId,\n content:\n result.content\n .filter((c) => c.type === \"text\")\n .map((c) => (c as { type: \"text\"; text: string }).text)\n .join(\"\") || JSON.stringify(result.content),\n },\n });\n }\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: toolResultMessageId,\n },\n });\n}\n\n/**\n * Checks whether a thread name should be auto-generated based on config\n * and the current thread state.\n * @param threadId - The thread ID (undefined or placeholder means no)\n * @param threadAlreadyHasName - Whether the thread already has a name\n * @param preMutationMessageCount - Message count before the current mutation\n * @param autoGenerateNameThreshold - Minimum message count to trigger generation\n * @returns Whether to generate a thread name\n */\nfunction shouldGenerateThreadName(\n threadId: string | undefined,\n threadAlreadyHasName: boolean,\n preMutationMessageCount: number,\n autoGenerateNameThreshold: number,\n): threadId is string {\n return (\n !threadAlreadyHasName &&\n !!threadId &&\n !isPlaceholderThreadId(threadId) &&\n // +2 accounts for the user message and assistant response just added\n preMutationMessageCount + 2 >= autoGenerateNameThreshold\n );\n}\n\n/**\n * Generates a thread name via the beta API, dispatches the name update,\n * and invalidates the thread list cache. Errors are logged, never thrown.\n * @param client - The Tambo API client\n * @param dispatch - Stream state dispatcher\n * @param queryClient - React Query client for cache invalidation\n * @param threadId - The thread to generate a name for\n */\nasync function generateThreadName(\n client: TamboAI,\n dispatch: React.Dispatch<StreamAction>,\n queryClient: ReturnType<typeof useTamboQueryClient>,\n threadId: string,\n): Promise<void> {\n try {\n const threadWithName = await client.beta.threads.generateName(threadId);\n if (threadWithName.name) {\n dispatch({\n type: \"UPDATE_THREAD_NAME\",\n threadId,\n name: threadWithName.name,\n });\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n });\n }\n } catch (error) {\n console.error(\n \"[useTamboSendMessage] Failed to auto-generate thread name:\",\n error,\n );\n }\n}\n\n/**\n * Options for sending a message\n */\nexport interface SendMessageOptions {\n /**\n * The message to send\n */\n message: InputMessage;\n\n /**\n * User message text for optimistic display.\n * If provided, synthetic AG-UI events will be dispatched to show\n * the user message in the thread immediately after getting the threadId.\n */\n userMessageText?: string;\n\n /**\n * Enable debug logging for the stream\n */\n debug?: boolean;\n\n /**\n * How the model should use tools. Defaults to \"auto\".\n * - \"auto\": Model decides whether to use tools\n * - \"required\": Model must use at least one tool\n * - \"none\": Model cannot use tools\n * - { name: \"toolName\" }: Model must use the specified tool\n */\n toolChoice?: ToolChoice;\n}\n\n/**\n * Parameters for creating a run stream\n */\nexport interface CreateRunStreamParams {\n client: TamboAI;\n threadId: string | undefined;\n message: InputMessage;\n registry: TamboRegistry;\n userKey: string | undefined;\n /**\n * Previous run ID for continuing a thread with existing messages.\n * Required when threadId is provided and the thread has previous runs.\n */\n previousRunId: string | undefined;\n /**\n * Additional context gathered from context helpers (including interactables).\n * Merged into the message's additionalContext before sending.\n */\n additionalContext?: Record<string, unknown>;\n /**\n * How the model should use tools.\n */\n toolChoice?: ToolChoice;\n /**\n * Initial messages to seed the thread with when creating a new thread.\n * Only used when threadId is undefined (new thread creation).\n */\n initialMessages?: InitialInputMessage[];\n}\n\n/**\n * Stream types from the SDK\n */\ntype RunStream = Stream<TamboAI.Threads.Runs.RunRunResponse>;\ntype CreateStream = Stream<TamboAI.Threads.Runs.RunCreateResponse>;\n\n/**\n * Result from creating a run stream\n */\nexport interface CreateRunStreamResult {\n stream: RunStream | CreateStream;\n initialThreadId: string | undefined;\n}\n\n/**\n * Parameters for executing tools and continuing the run\n */\ninterface ExecuteToolsParams {\n event: RunAwaitingInputEvent;\n toolTracker: ToolCallTracker;\n registry: TamboRegistry;\n client: TamboAI;\n threadId: string;\n runId: string;\n userKey: string | undefined;\n additionalContext?: Record<string, unknown>;\n toolChoice?: ToolChoice;\n}\n\n/**\n * Result from executing tools and continuing the run\n */\ninterface ExecuteToolsResult {\n stream: RunStream;\n toolResults: ToolResultContent[];\n}\n\n/**\n * Executes pending tools and returns a continuation stream.\n *\n * This function does NOT process the continuation stream - it just executes\n * the tools and returns the new stream for the caller to process. This enables\n * the flat loop pattern that correctly handles multi-round tool execution.\n * @param params - The parameters for tool execution\n * @returns The continuation stream and tool results for optimistic local state updates\n */\nasync function executeToolsAndContinue(\n params: ExecuteToolsParams,\n): Promise<ExecuteToolsResult> {\n const {\n event,\n toolTracker,\n registry,\n client,\n threadId,\n runId,\n userKey,\n additionalContext,\n toolChoice,\n } = params;\n\n const pendingToolCallIds = event.value.pendingToolCalls.map(\n (tc) => tc.toolCallId,\n );\n const toolCallsToExecute = toolTracker.getToolCallsById(pendingToolCallIds);\n\n // Execute tools\n const toolResults = await executeAllPendingTools(\n toolCallsToExecute,\n registry.toolRegistry,\n );\n\n // Clear executed tool calls before continuing\n toolTracker.clearToolCalls(pendingToolCallIds);\n\n // Return the continuation stream and tool results\n const stream = await client.threads.runs.run(threadId, {\n message: {\n role: \"user\",\n content: toolResults,\n additionalContext,\n },\n previousRunId: runId,\n availableComponents: toAvailableComponents(registry.componentList),\n tools: toAvailableTools(registry.toolRegistry),\n userKey,\n toolChoice,\n });\n\n return { stream, toolResults };\n}\n\n/**\n * Creates a run stream by calling the appropriate API method.\n *\n * If threadId is provided, runs on existing thread via client.threads.runs.run().\n * If no threadId, creates new thread via client.threads.runs.create().\n * @param params - The parameters for creating the run stream\n * @returns The stream and initial thread ID (undefined if creating new thread)\n */\nexport async function createRunStream(\n params: CreateRunStreamParams,\n): Promise<CreateRunStreamResult> {\n const {\n client,\n threadId,\n message,\n registry,\n userKey,\n previousRunId,\n additionalContext,\n toolChoice,\n initialMessages,\n } = params;\n\n // Merge helper context with any caller-provided additionalContext on the message\n const mergedContext =\n additionalContext || message.additionalContext\n ? {\n ...((message.additionalContext as Record<string, unknown>) ?? {}),\n ...additionalContext,\n }\n : undefined;\n const messageWithContext: InputMessage = mergedContext\n ? { ...message, additionalContext: mergedContext }\n : message;\n\n // Convert registry components/tools to API format\n const availableComponents = toAvailableComponents(registry.componentList);\n const availableTools = toAvailableTools(registry.toolRegistry);\n\n if (threadId) {\n // Run on existing thread\n const stream = await client.threads.runs.run(threadId, {\n message: messageWithContext,\n availableComponents,\n tools: availableTools,\n userKey,\n previousRunId,\n toolChoice,\n });\n return { stream, initialThreadId: threadId };\n } else {\n // Create new thread - include initialMessages if provided\n const threadConfig: RunCreateParams.Thread = {};\n if (userKey) {\n threadConfig.userKey = userKey;\n }\n if (initialMessages?.length) {\n threadConfig.initialMessages = initialMessages;\n }\n\n const stream = await client.threads.runs.create({\n message: messageWithContext,\n availableComponents,\n tools: availableTools,\n thread: Object.keys(threadConfig).length > 0 ? threadConfig : undefined,\n toolChoice,\n });\n // threadId will be extracted from first event (RUN_STARTED)\n return { stream, initialThreadId: undefined };\n }\n}\n\n/**\n * Hook to send a message and handle streaming responses.\n *\n * This hook handles two scenarios:\n * - If threadId provided: runs on existing thread via client.threads.runs.run()\n * - If no threadId: creates new thread via client.threads.runs.create()\n *\n * The hook:\n * - Sends a user message to the API\n * - Streams AG-UI events in real-time\n * - Dispatches events to the stream reducer\n * - Extracts threadId from events when creating new thread\n * - Handles tool execution (Phase 6)\n * - Invalidates thread queries on completion\n * @param threadId - Optional thread ID to send message to. If not provided, creates new thread\n * @returns React Query mutation object with threadId in mutation result\n * @example\n * ```tsx\n * function ChatInput({ threadId }: { threadId?: string }) {\n * const sendMessage = useTamboSendMessage(threadId);\n *\n * const handleSubmit = async (text: string) => {\n * const result = await sendMessage.mutateAsync({\n * message: {\n * role: \"user\",\n * content: [{ type: \"text\", text }],\n * },\n * });\n *\n * // If threadId wasn't provided, a new thread was created\n * if (!threadId) {\n * console.log(\"Created thread:\", result.threadId);\n * }\n * };\n *\n * return (\n * <div>\n * <input onSubmit={handleSubmit} />\n * {sendMessage.isPending && <Spinner />}\n * </div>\n * );\n * }\n * ```\n */\nexport function useTamboSendMessage(threadId?: string) {\n const client = useTamboClient();\n const dispatch = useStreamDispatch();\n const streamState = useStreamState();\n const {\n userKey,\n autoGenerateThreadName = true,\n autoGenerateNameThreshold = 3,\n initialMessages,\n } = useTamboConfig();\n const registry = useContext(TamboRegistryContext);\n const queryClient = useTamboQueryClient();\n const { getAdditionalContext } = useTamboContextHelpers();\n const authState = useTamboAuthState();\n\n if (!registry) {\n throw new Error(\n \"useTamboSendMessage must be used within TamboRegistryProvider\",\n );\n }\n\n // Placeholder ID isn't a valid API thread ID - treat as new thread creation\n const isNewThread = isPlaceholderThreadId(threadId);\n const apiThreadId = isNewThread ? undefined : threadId;\n\n // Get previousRunId from the thread's streaming state (active run) or\n // lastCompletedRunId (persisted after run finishes / loaded from API).\n // The latter is essential after page reload when streaming state is gone.\n const threadState = apiThreadId\n ? streamState.threadMap[apiThreadId]\n : undefined;\n const previousRunId =\n threadState?.streaming.runId ?? threadState?.lastCompletedRunId;\n\n return useTamboMutation({\n mutationFn: async (options: SendMessageOptions) => {\n if (authState.status !== \"identified\") {\n const messages: Record<string, string> = {\n unauthenticated:\n \"Cannot send message: no userKey or userToken provided. \" +\n \"Configure authentication in TamboProvider.\",\n exchanging:\n \"Cannot send message: token exchange is still in progress. \" +\n \"Wait for authentication to complete.\",\n error:\n \"Cannot send message: token exchange failed. \" +\n \"Check your userToken configuration.\",\n invalid:\n \"Cannot send message: both userKey and userToken were provided. \" +\n \"You must provide one or the other, not both.\",\n };\n throw new Error(messages[authState.status]);\n }\n\n const { message, userMessageText, debug = false, toolChoice } = options;\n\n // Capture pre-mutation state for auto thread name generation\n const existingThread = streamState.threadMap[apiThreadId ?? \"\"];\n const preMutationMessageCount =\n existingThread?.thread.messages.length ?? 0;\n const threadAlreadyHasName = !!existingThread?.thread.name;\n\n const toolTracker = new ToolCallTracker(registry.toolRegistry);\n const throttledStreamable = createThrottledStreamableExecutor(\n toolTracker,\n registry.toolRegistry,\n );\n\n // Generate a stable message ID for the user message\n const userMessageId = userMessageText\n ? `user_msg_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`\n : undefined;\n\n // Add user message immediately for instant feedback\n // Use threadId (which could be temp_xxx for new threads) for display\n if (threadId && userMessageText && userMessageId) {\n dispatchUserMessage(dispatch, threadId, userMessageId, userMessageText);\n }\n\n // Gather additional context from all registered context helpers.\n // TODO: This snapshot is captured once and reused for the entire multi-round\n // tool loop. If interactables change during streaming (e.g. user interactions),\n // continuations will send stale context. Re-gather before each continuation\n // if freshness matters.\n const helperContexts = await getAdditionalContext();\n const additionalContext: Record<string, unknown> = {};\n for (const helperContext of helperContexts) {\n additionalContext[helperContext.name] = helperContext.context;\n }\n\n // Create the run stream\n // Include initialMessages only on first send (new thread creation)\n const { stream, initialThreadId } = await createRunStream({\n client,\n threadId: apiThreadId,\n message,\n registry,\n userKey,\n previousRunId,\n additionalContext,\n toolChoice,\n initialMessages: isNewThread ? initialMessages : undefined,\n });\n\n let actualThreadId = initialThreadId;\n let runId: string | undefined;\n let currentStream: CreateRunStreamResult[\"stream\"] = stream;\n\n try {\n // Outer loop handles stream replacement for multi-round tool execution.\n // When we hit awaiting_input, we execute tools, get a new stream, and continue.\n // This flat loop pattern correctly handles tool→AI→tool→AI chains.\n while (true) {\n let pendingAwaitingInput: RunAwaitingInputEvent | undefined;\n\n // Process current stream until completion or awaiting_input\n for await (const event of handleEventStream(currentStream, {\n debug,\n })) {\n // Extract threadId and runId from RUN_STARTED event\n if (event.type === EventType.RUN_STARTED) {\n runId = event.runId;\n actualThreadId ??= event.threadId;\n\n // For threads with no ID at all: add user message now that we have the real threadId\n // Note: temp thread migration (temp_xxx -> real ID) is handled automatically\n // by the reducer when it sees RUN_STARTED with a different threadId\n if (!threadId && userMessageText && userMessageId) {\n dispatchUserMessage(\n dispatch,\n actualThreadId,\n userMessageId,\n userMessageText,\n );\n }\n } else if (!actualThreadId) {\n throw new Error(\n `Expected first event to be RUN_STARTED with threadId, got: ${event.type}`,\n );\n }\n\n toolTracker.handleEvent(event);\n\n // Parse partial JSON once for TOOL_CALL_ARGS — reused by both dispatch and streamable execution\n const parsedToolArgs =\n event.type === EventType.TOOL_CALL_ARGS\n ? toolTracker.parsePartialArgs(event.toolCallId)\n : undefined;\n\n dispatch({\n type: \"EVENT\",\n event,\n threadId: actualThreadId,\n parsedToolArgs,\n toolSchemas: toolTracker.toolSchemas,\n });\n\n // Schedule debounced streamable tool execution with the same pre-parsed args\n if (parsedToolArgs && event.type === EventType.TOOL_CALL_ARGS) {\n throttledStreamable.schedule(event.toolCallId, parsedToolArgs);\n }\n\n // Handle custom events\n if (event.type === EventType.CUSTOM) {\n const customEvent = asTamboCustomEvent(event);\n\n if (customEvent?.name === \"tambo.run.awaiting_input\") {\n pendingAwaitingInput = customEvent;\n break; // Exit stream loop to handle tool execution\n }\n }\n }\n\n // Flush any pending debounced streamable calls before continuing\n throttledStreamable.flush();\n\n // If stream finished without awaiting_input, we're done\n if (!pendingAwaitingInput) {\n break;\n }\n\n // Execute tools and get continuation stream\n // These checks should never fail since awaiting_input comes after RUN_STARTED\n if (!runId || !actualThreadId) {\n throw new Error(\n \"Cannot continue run after awaiting_input: missing runId or threadId\",\n );\n }\n\n const { stream: continuationStream, toolResults } =\n await executeToolsAndContinue({\n event: pendingAwaitingInput,\n toolTracker,\n registry,\n client,\n threadId: actualThreadId,\n runId,\n userKey,\n additionalContext,\n toolChoice,\n });\n\n dispatchToolResults(dispatch, actualThreadId, toolResults);\n\n currentStream = continuationStream;\n }\n\n return {\n threadId: actualThreadId,\n preMutationMessageCount,\n threadAlreadyHasName,\n };\n } catch (error) {\n // Dispatch a synthetic RUN_ERROR event to clean up thread state\n // This ensures the thread doesn't stay stuck in \"streaming\" status\n if (actualThreadId) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown streaming error\";\n const errorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: errorMessage,\n };\n dispatch({\n type: \"EVENT\",\n event: errorEvent,\n threadId: actualThreadId,\n });\n }\n throw error;\n }\n },\n onSuccess: async (result) => {\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", result.threadId],\n });\n\n if (\n autoGenerateThreadName &&\n shouldGenerateThreadName(\n result.threadId,\n result.threadAlreadyHasName,\n result.preMutationMessageCount,\n autoGenerateNameThreshold,\n )\n ) {\n await generateThreadName(\n client,\n dispatch,\n queryClient,\n result.threadId,\n );\n }\n },\n onError: (error) => {\n console.error(\"[useTamboSendMessage] Mutation failed:\", error);\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1-send-message.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1-send-message.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;GAIG;AAEH,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAsB,MAAM,aAAa,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AE,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;aAC1C,CAAC,CAAC;YAEH,IACE,sBAAsB;gBACtB,wBAAwB,CACtB,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,oBAAoB,EAC3B,MAAM,CAAC,uBAAuB,EAC9B,yBAAyB,CAC1B,EACD,CAAC;gBACD,MAAM,kBAAkB,CACtB,MAAM,EACN,QAAQ,EACR,WAAW,EACX,MAAM,CAAC,QAAQ,CAChB,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;QACjE,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * Send Message Hook\n *\n * React Query mutation hook for sending messages and handling streaming responses.\n */\n\nimport React, { useContext } from \"react\";\nimport { EventType, type RunErrorEvent } from \"@ag-ui/core\";\nimport {\n asTamboCustomEvent,\n type RunAwaitingInputEvent,\n} from \"@tambo-ai/client\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport type { Stream } from \"@tambo-ai/typescript-sdk/core/streaming\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboMutation } from \"../../hooks/react-query-hooks\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistry,\n} from \"../../providers/tambo-registry-provider\";\nimport {\n useStreamDispatch,\n useStreamState,\n} from \"../providers/tambo-v1-stream-context\";\nimport { useTamboConfig } from \"../providers/tambo-v1-provider\";\nimport { useTamboAuthState } from \"./use-tambo-v1-auth-state\";\nimport { useTamboContextHelpers } from \"../../providers/tambo-context-helpers-provider\";\nimport { useTamboInteractable } from \"../../providers/tambo-interactable-provider\";\nimport type { InitialInputMessage, InputMessage } from \"../types/message\";\nimport type { ToolChoice } from \"@tambo-ai/client\";\nimport { isPlaceholderThreadId, type StreamAction } from \"@tambo-ai/client\";\nimport { toAvailableComponents, toAvailableTools } from \"@tambo-ai/client\";\nimport { handleEventStream } from \"@tambo-ai/client\";\nimport {\n executeAllPendingTools,\n createThrottledStreamableExecutor,\n} from \"@tambo-ai/client\";\nimport type { ToolResultContent } from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\nimport type { RunCreateParams } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\nimport { ToolCallTracker } from \"@tambo-ai/client\";\n\n/**\n * Dispatches synthetic AG-UI events to show a user message in the thread.\n * @param dispatch - Stream state dispatcher\n * @param targetThreadId - Thread to add the message to\n * @param messageId - Stable ID for the user message\n * @param messageText - Text content of the message\n */\nfunction dispatchUserMessage(\n dispatch: React.Dispatch<StreamAction>,\n targetThreadId: string,\n messageId: string,\n messageText: string,\n): void {\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId,\n role: \"user\" as const,\n },\n });\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_CONTENT,\n messageId,\n delta: messageText,\n },\n });\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId,\n },\n });\n}\n\n/**\n * Dispatches synthetic events for tool results as optimistic local state.\n * The server doesn't echo these back for client-side tools.\n * @param dispatch - Stream state dispatcher\n * @param targetThreadId - Thread to add results to\n * @param toolResults - Tool execution results to dispatch\n */\nfunction dispatchToolResults(\n dispatch: React.Dispatch<StreamAction>,\n targetThreadId: string,\n toolResults: ToolResultContent[],\n): void {\n if (toolResults.length === 0) return;\n\n const toolResultMessageId = `msg_tool_result_${Date.now()}`;\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_START,\n messageId: toolResultMessageId,\n role: \"user\" as const,\n },\n });\n\n for (const result of toolResults) {\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TOOL_CALL_RESULT,\n toolCallId: result.toolUseId,\n messageId: toolResultMessageId,\n content:\n result.content\n .filter((c) => c.type === \"text\")\n .map((c) => (c as { type: \"text\"; text: string }).text)\n .join(\"\") || JSON.stringify(result.content),\n },\n });\n }\n\n dispatch({\n type: \"EVENT\",\n threadId: targetThreadId,\n event: {\n type: EventType.TEXT_MESSAGE_END,\n messageId: toolResultMessageId,\n },\n });\n}\n\n/**\n * Checks whether a thread name should be auto-generated based on config\n * and the current thread state.\n * @param threadId - The thread ID (undefined or placeholder means no)\n * @param threadAlreadyHasName - Whether the thread already has a name\n * @param preMutationMessageCount - Message count before the current mutation\n * @param autoGenerateNameThreshold - Minimum message count to trigger generation\n * @returns Whether to generate a thread name\n */\nfunction shouldGenerateThreadName(\n threadId: string | undefined,\n threadAlreadyHasName: boolean,\n preMutationMessageCount: number,\n autoGenerateNameThreshold: number,\n): threadId is string {\n return (\n !threadAlreadyHasName &&\n !!threadId &&\n !isPlaceholderThreadId(threadId) &&\n // +2 accounts for the user message and assistant response just added\n preMutationMessageCount + 2 >= autoGenerateNameThreshold\n );\n}\n\n/**\n * Generates a thread name via the beta API, dispatches the name update,\n * and invalidates the thread list cache. Errors are logged, never thrown.\n * @param client - The Tambo API client\n * @param dispatch - Stream state dispatcher\n * @param queryClient - React Query client for cache invalidation\n * @param threadId - The thread to generate a name for\n */\nasync function generateThreadName(\n client: TamboAI,\n dispatch: React.Dispatch<StreamAction>,\n queryClient: ReturnType<typeof useTamboQueryClient>,\n threadId: string,\n): Promise<void> {\n try {\n const threadWithName = await client.beta.threads.generateName(threadId);\n if (threadWithName.name) {\n dispatch({\n type: \"UPDATE_THREAD_NAME\",\n threadId,\n name: threadWithName.name,\n });\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n });\n }\n } catch (error) {\n console.error(\n \"[useTamboSendMessage] Failed to auto-generate thread name:\",\n error,\n );\n }\n}\n\n/**\n * Options for sending a message\n */\nexport interface SendMessageOptions {\n /**\n * The message to send\n */\n message: InputMessage;\n\n /**\n * User message text for optimistic display.\n * If provided, synthetic AG-UI events will be dispatched to show\n * the user message in the thread immediately after getting the threadId.\n */\n userMessageText?: string;\n\n /**\n * Enable debug logging for the stream\n */\n debug?: boolean;\n\n /**\n * How the model should use tools. Defaults to \"auto\".\n * - \"auto\": Model decides whether to use tools\n * - \"required\": Model must use at least one tool\n * - \"none\": Model cannot use tools\n * - { name: \"toolName\" }: Model must use the specified tool\n */\n toolChoice?: ToolChoice;\n}\n\n/**\n * Parameters for creating a run stream\n */\nexport interface CreateRunStreamParams {\n client: TamboAI;\n threadId: string | undefined;\n message: InputMessage;\n registry: TamboRegistry;\n userKey: string | undefined;\n /**\n * Previous run ID for continuing a thread with existing messages.\n * Required when threadId is provided and the thread has previous runs.\n */\n previousRunId: string | undefined;\n /**\n * Additional context gathered from context helpers (including interactables).\n * Merged into the message's additionalContext before sending.\n */\n additionalContext?: Record<string, unknown>;\n /**\n * How the model should use tools.\n */\n toolChoice?: ToolChoice;\n /**\n * Initial messages to seed the thread with when creating a new thread.\n * Only used when threadId is undefined (new thread creation).\n */\n initialMessages?: InitialInputMessage[];\n}\n\n/**\n * Stream types from the SDK\n */\ntype RunStream = Stream<TamboAI.Threads.Runs.RunRunResponse>;\ntype CreateStream = Stream<TamboAI.Threads.Runs.RunCreateResponse>;\n\n/**\n * Result from creating a run stream\n */\nexport interface CreateRunStreamResult {\n stream: RunStream | CreateStream;\n initialThreadId: string | undefined;\n}\n\n/**\n * Parameters for executing tools and continuing the run\n */\ninterface ExecuteToolsParams {\n event: RunAwaitingInputEvent;\n toolTracker: ToolCallTracker;\n registry: TamboRegistry;\n client: TamboAI;\n threadId: string;\n runId: string;\n userKey: string | undefined;\n additionalContext?: Record<string, unknown>;\n toolChoice?: ToolChoice;\n}\n\n/**\n * Result from executing tools and continuing the run\n */\ninterface ExecuteToolsResult {\n stream: RunStream;\n toolResults: ToolResultContent[];\n}\n\n/**\n * Executes pending tools and returns a continuation stream.\n *\n * This function does NOT process the continuation stream - it just executes\n * the tools and returns the new stream for the caller to process. This enables\n * the flat loop pattern that correctly handles multi-round tool execution.\n * @param params - The parameters for tool execution\n * @returns The continuation stream and tool results for optimistic local state updates\n */\nasync function executeToolsAndContinue(\n params: ExecuteToolsParams,\n): Promise<ExecuteToolsResult> {\n const {\n event,\n toolTracker,\n registry,\n client,\n threadId,\n runId,\n userKey,\n additionalContext,\n toolChoice,\n } = params;\n\n const pendingToolCallIds = event.value.pendingToolCalls.map(\n (tc) => tc.toolCallId,\n );\n const toolCallsToExecute = toolTracker.getToolCallsById(pendingToolCallIds);\n\n // Execute tools\n const toolResults = await executeAllPendingTools(\n toolCallsToExecute,\n registry.toolRegistry,\n );\n\n // Clear executed tool calls before continuing\n toolTracker.clearToolCalls(pendingToolCallIds);\n\n // Return the continuation stream and tool results\n const stream = await client.threads.runs.run(threadId, {\n message: {\n role: \"user\",\n content: toolResults,\n additionalContext,\n },\n previousRunId: runId,\n availableComponents: toAvailableComponents(registry.componentList),\n tools: toAvailableTools(registry.toolRegistry),\n userKey,\n toolChoice,\n });\n\n return { stream, toolResults };\n}\n\n/**\n * Creates a run stream by calling the appropriate API method.\n *\n * If threadId is provided, runs on existing thread via client.threads.runs.run().\n * If no threadId, creates new thread via client.threads.runs.create().\n * @param params - The parameters for creating the run stream\n * @returns The stream and initial thread ID (undefined if creating new thread)\n */\nexport async function createRunStream(\n params: CreateRunStreamParams,\n): Promise<CreateRunStreamResult> {\n const {\n client,\n threadId,\n message,\n registry,\n userKey,\n previousRunId,\n additionalContext,\n toolChoice,\n initialMessages,\n } = params;\n\n // Merge helper context with any caller-provided additionalContext on the message\n const mergedContext =\n additionalContext || message.additionalContext\n ? {\n ...((message.additionalContext as Record<string, unknown>) ?? {}),\n ...additionalContext,\n }\n : undefined;\n const messageWithContext: InputMessage = mergedContext\n ? { ...message, additionalContext: mergedContext }\n : message;\n\n // Convert registry components/tools to API format\n const availableComponents = toAvailableComponents(registry.componentList);\n const availableTools = toAvailableTools(registry.toolRegistry);\n\n if (threadId) {\n // Run on existing thread\n const stream = await client.threads.runs.run(threadId, {\n message: messageWithContext,\n availableComponents,\n tools: availableTools,\n userKey,\n previousRunId,\n toolChoice,\n });\n return { stream, initialThreadId: threadId };\n } else {\n // Create new thread - include initialMessages if provided\n const threadConfig: RunCreateParams.Thread = {};\n if (userKey) {\n threadConfig.userKey = userKey;\n }\n if (initialMessages?.length) {\n threadConfig.initialMessages = initialMessages;\n }\n\n const stream = await client.threads.runs.create({\n message: messageWithContext,\n availableComponents,\n tools: availableTools,\n thread: Object.keys(threadConfig).length > 0 ? threadConfig : undefined,\n toolChoice,\n });\n // threadId will be extracted from first event (RUN_STARTED)\n return { stream, initialThreadId: undefined };\n }\n}\n\n/**\n * Hook to send a message and handle streaming responses.\n *\n * This hook handles two scenarios:\n * - If threadId provided: runs on existing thread via client.threads.runs.run()\n * - If no threadId: creates new thread via client.threads.runs.create()\n *\n * The hook:\n * - Sends a user message to the API\n * - Streams AG-UI events in real-time\n * - Dispatches events to the stream reducer\n * - Extracts threadId from events when creating new thread\n * - Handles tool execution (Phase 6)\n * - Invalidates thread queries on completion\n * @param threadId - Optional thread ID to send message to. If not provided, creates new thread\n * @returns React Query mutation object with threadId in mutation result\n * @example\n * ```tsx\n * function ChatInput({ threadId }: { threadId?: string }) {\n * const sendMessage = useTamboSendMessage(threadId);\n *\n * const handleSubmit = async (text: string) => {\n * const result = await sendMessage.mutateAsync({\n * message: {\n * role: \"user\",\n * content: [{ type: \"text\", text }],\n * },\n * });\n *\n * // If threadId wasn't provided, a new thread was created\n * if (!threadId) {\n * console.log(\"Created thread:\", result.threadId);\n * }\n * };\n *\n * return (\n * <div>\n * <input onSubmit={handleSubmit} />\n * {sendMessage.isPending && <Spinner />}\n * </div>\n * );\n * }\n * ```\n */\nexport function useTamboSendMessage(threadId?: string) {\n const client = useTamboClient();\n const dispatch = useStreamDispatch();\n const streamState = useStreamState();\n const {\n userKey,\n autoGenerateThreadName = true,\n autoGenerateNameThreshold = 3,\n initialMessages,\n } = useTamboConfig();\n const registry = useContext(TamboRegistryContext);\n const queryClient = useTamboQueryClient();\n const { getAdditionalContext } = useTamboContextHelpers();\n const { clearInteractableSelections } = useTamboInteractable();\n const authState = useTamboAuthState();\n\n if (!registry) {\n throw new Error(\n \"useTamboSendMessage must be used within TamboRegistryProvider\",\n );\n }\n\n // Placeholder ID isn't a valid API thread ID - treat as new thread creation\n const isNewThread = isPlaceholderThreadId(threadId);\n const apiThreadId = isNewThread ? undefined : threadId;\n\n // Get previousRunId from the thread's streaming state (active run) or\n // lastCompletedRunId (persisted after run finishes / loaded from API).\n // The latter is essential after page reload when streaming state is gone.\n const threadState = apiThreadId\n ? streamState.threadMap[apiThreadId]\n : undefined;\n const previousRunId =\n threadState?.streaming.runId ?? threadState?.lastCompletedRunId;\n\n return useTamboMutation({\n mutationFn: async (options: SendMessageOptions) => {\n if (authState.status !== \"identified\") {\n const messages: Record<string, string> = {\n unauthenticated:\n \"Cannot send message: no userKey or userToken provided. \" +\n \"Configure authentication in TamboProvider.\",\n exchanging:\n \"Cannot send message: token exchange is still in progress. \" +\n \"Wait for authentication to complete.\",\n error:\n \"Cannot send message: token exchange failed. \" +\n \"Check your userToken configuration.\",\n invalid:\n \"Cannot send message: both userKey and userToken were provided. \" +\n \"You must provide one or the other, not both.\",\n };\n throw new Error(messages[authState.status]);\n }\n\n const { message, userMessageText, debug = false, toolChoice } = options;\n\n // Capture pre-mutation state for auto thread name generation\n const existingThread = streamState.threadMap[apiThreadId ?? \"\"];\n const preMutationMessageCount =\n existingThread?.thread.messages.length ?? 0;\n const threadAlreadyHasName = !!existingThread?.thread.name;\n\n const toolTracker = new ToolCallTracker(registry.toolRegistry);\n const throttledStreamable = createThrottledStreamableExecutor(\n toolTracker,\n registry.toolRegistry,\n );\n\n // Generate a stable message ID for the user message\n const userMessageId = userMessageText\n ? `user_msg_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`\n : undefined;\n\n // Add user message immediately for instant feedback\n // Use threadId (which could be temp_xxx for new threads) for display\n if (threadId && userMessageText && userMessageId) {\n dispatchUserMessage(dispatch, threadId, userMessageId, userMessageText);\n }\n\n // Gather additional context from all registered context helpers.\n // TODO: This snapshot is captured once and reused for the entire multi-round\n // tool loop. If interactables change during streaming (e.g. user interactions),\n // continuations will send stale context. Re-gather before each continuation\n // if freshness matters.\n const helperContexts = await getAdditionalContext();\n const additionalContext: Record<string, unknown> = {};\n for (const helperContext of helperContexts) {\n additionalContext[helperContext.name] = helperContext.context;\n }\n\n // Clear interactable selections after capturing context so they only\n // apply to this single message send.\n clearInteractableSelections();\n\n // Create the run stream\n // Include initialMessages only on first send (new thread creation)\n const { stream, initialThreadId } = await createRunStream({\n client,\n threadId: apiThreadId,\n message,\n registry,\n userKey,\n previousRunId,\n additionalContext,\n toolChoice,\n initialMessages: isNewThread ? initialMessages : undefined,\n });\n\n let actualThreadId = initialThreadId;\n let runId: string | undefined;\n let currentStream: CreateRunStreamResult[\"stream\"] = stream;\n\n try {\n // Outer loop handles stream replacement for multi-round tool execution.\n // When we hit awaiting_input, we execute tools, get a new stream, and continue.\n // This flat loop pattern correctly handles tool→AI→tool→AI chains.\n while (true) {\n let pendingAwaitingInput: RunAwaitingInputEvent | undefined;\n\n // Process current stream until completion or awaiting_input\n for await (const event of handleEventStream(currentStream, {\n debug,\n })) {\n // Extract threadId and runId from RUN_STARTED event\n if (event.type === EventType.RUN_STARTED) {\n runId = event.runId;\n actualThreadId ??= event.threadId;\n\n // For threads with no ID at all: add user message now that we have the real threadId\n // Note: temp thread migration (temp_xxx -> real ID) is handled automatically\n // by the reducer when it sees RUN_STARTED with a different threadId\n if (!threadId && userMessageText && userMessageId) {\n dispatchUserMessage(\n dispatch,\n actualThreadId,\n userMessageId,\n userMessageText,\n );\n }\n } else if (!actualThreadId) {\n throw new Error(\n `Expected first event to be RUN_STARTED with threadId, got: ${event.type}`,\n );\n }\n\n toolTracker.handleEvent(event);\n\n // Parse partial JSON once for TOOL_CALL_ARGS — reused by both dispatch and streamable execution\n const parsedToolArgs =\n event.type === EventType.TOOL_CALL_ARGS\n ? toolTracker.parsePartialArgs(event.toolCallId)\n : undefined;\n\n dispatch({\n type: \"EVENT\",\n event,\n threadId: actualThreadId,\n parsedToolArgs,\n toolSchemas: toolTracker.toolSchemas,\n });\n\n // Schedule debounced streamable tool execution with the same pre-parsed args\n if (parsedToolArgs && event.type === EventType.TOOL_CALL_ARGS) {\n throttledStreamable.schedule(event.toolCallId, parsedToolArgs);\n }\n\n // Handle custom events\n if (event.type === EventType.CUSTOM) {\n const customEvent = asTamboCustomEvent(event);\n\n if (customEvent?.name === \"tambo.run.awaiting_input\") {\n pendingAwaitingInput = customEvent;\n break; // Exit stream loop to handle tool execution\n }\n }\n }\n\n // Flush any pending debounced streamable calls before continuing\n throttledStreamable.flush();\n\n // If stream finished without awaiting_input, we're done\n if (!pendingAwaitingInput) {\n break;\n }\n\n // Execute tools and get continuation stream\n // These checks should never fail since awaiting_input comes after RUN_STARTED\n if (!runId || !actualThreadId) {\n throw new Error(\n \"Cannot continue run after awaiting_input: missing runId or threadId\",\n );\n }\n\n const { stream: continuationStream, toolResults } =\n await executeToolsAndContinue({\n event: pendingAwaitingInput,\n toolTracker,\n registry,\n client,\n threadId: actualThreadId,\n runId,\n userKey,\n additionalContext,\n toolChoice,\n });\n\n dispatchToolResults(dispatch, actualThreadId, toolResults);\n\n currentStream = continuationStream;\n }\n\n return {\n threadId: actualThreadId,\n preMutationMessageCount,\n threadAlreadyHasName,\n };\n } catch (error) {\n // Dispatch a synthetic RUN_ERROR event to clean up thread state\n // This ensures the thread doesn't stay stuck in \"streaming\" status\n if (actualThreadId) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown streaming error\";\n const errorEvent: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n message: errorMessage,\n };\n dispatch({\n type: \"EVENT\",\n event: errorEvent,\n threadId: actualThreadId,\n });\n }\n throw error;\n }\n },\n onSuccess: async (result) => {\n await queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", result.threadId],\n });\n\n if (\n autoGenerateThreadName &&\n shouldGenerateThreadName(\n result.threadId,\n result.threadAlreadyHasName,\n result.preMutationMessageCount,\n autoGenerateNameThreshold,\n )\n ) {\n await generateThreadName(\n client,\n dispatch,\n queryClient,\n result.threadId,\n );\n }\n },\n onError: (error) => {\n console.error(\"[useTamboSendMessage] Mutation failed:\", error);\n },\n });\n}\n"]}
|