@tambo-ai/react 1.0.1 → 1.0.2
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/v1/hooks/use-tambo-v1.js +2 -2
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +2 -0
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.js +2 -2
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +2 -0
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/package.json +3 -3
|
@@ -108,7 +108,7 @@ function useTambo() {
|
|
|
108
108
|
]);
|
|
109
109
|
// Update a thread's name
|
|
110
110
|
const updateThreadName = (0, react_1.useCallback)(async (threadId, name) => {
|
|
111
|
-
await client.threads.update(threadId, { name });
|
|
111
|
+
await client.threads.update(threadId, { name, userKey });
|
|
112
112
|
if (threadMapRef.current[threadId]) {
|
|
113
113
|
dispatch({
|
|
114
114
|
type: "UPDATE_THREAD_NAME",
|
|
@@ -129,7 +129,7 @@ function useTambo() {
|
|
|
129
129
|
catch (error) {
|
|
130
130
|
console.warn("[useTambo] Failed to invalidate thread queries after rename:", error);
|
|
131
131
|
}
|
|
132
|
-
}, [client, dispatch, queryClient]);
|
|
132
|
+
}, [client, userKey, dispatch, queryClient]);
|
|
133
133
|
// Memoize the return object to prevent unnecessary re-renders
|
|
134
134
|
return (0, react_1.useMemo)(() => {
|
|
135
135
|
const thread = threadState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNb,4BAqOC;AApbD;;;;;GAKG;AAEH,sCAAwC;AAExC,+CAMe;AACf,iF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QAAQ,CAAC,YAAY;YACnC,eAAe,EAAE,WAAW,CAAC,eAAe;YAC5C,UAAU,EAAE,gBAAgB,CAAC,UAAU;YACvC,YAAY,EAAE,gBAAgB,CAAC,YAAY;YAC3C,cAAc,EAAE,gBAAgB,CAAC,cAAc;YAC/C,QAAQ;YACR,SAAS;YACT,SAAS;YACT,YAAY,EAAE,SAAS,CAAC,MAAM,KAAK,YAAY;YAC/C,gBAAgB;SACjB,CAAC;IACJ,CAAC,EAAE;QACD,SAAS;QACT,gBAAgB;QAChB,MAAM;QACN,WAAW;QACX,QAAQ;QACR,WAAW,CAAC,eAAe;QAC3B,gBAAgB;QAChB,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * useTambo - Main Hook\n *\n * Combines all contexts into a single hook for convenient access\n * to thread state, streaming status, registry, and client.\n */\n\nimport { EventType } from \"@ag-ui/core\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n useCallback,\n useContext,\n useMemo,\n useRef,\n type ReactElement,\n} from \"react\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboConfig } from \"../providers/tambo-v1-provider\";\nimport { useTamboAuthState } from \"./use-tambo-v1-auth-state\";\nimport type { TamboAuthState } from \"../types/auth\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { ComponentRenderer } from \"../components/v1-component-renderer\";\nimport {\n useStreamDispatch,\n useStreamState,\n useThreadManagement,\n type ThreadManagement,\n} from \"../providers/tambo-v1-stream-context\";\nimport type {\n Content,\n TamboToolDisplayProps,\n TamboThreadMessage,\n TamboToolUseContent,\n} from \"../types/message\";\nimport type { StreamingState } from \"../types/thread\";\nimport {\n isPlaceholderThreadId,\n type ThreadState,\n} from \"../utils/event-accumulator\";\n\n/**\n * Return type for useTambo hook\n */\nexport interface UseTamboReturn {\n /**\n * The Tambo API client instance\n */\n client: TamboAI;\n\n /**\n * Current thread state for the given threadId, or undefined if not loaded\n */\n thread: ThreadState | undefined;\n\n /**\n * Messages in the current thread\n */\n messages: TamboThreadMessage[];\n\n /**\n * Current streaming state\n */\n streamingState: StreamingState;\n\n /**\n * Whether the thread is currently streaming a response\n */\n isStreaming: boolean;\n\n /**\n * Whether the thread is waiting for the AI to start responding\n */\n isWaiting: boolean;\n\n /**\n * Whether the thread is idle (not streaming or waiting)\n */\n isIdle: boolean;\n\n /**\n * Register a component with the registry\n */\n registerComponent: TamboRegistryContextType[\"registerComponent\"];\n\n /**\n * Register a tool with the registry\n */\n registerTool: TamboRegistryContextType[\"registerTool\"];\n\n /**\n * Register multiple tools with the registry\n */\n registerTools: TamboRegistryContextType[\"registerTools\"];\n\n /**\n * The component registry (Map of name -> component definition)\n */\n componentList: TamboRegistryContextType[\"componentList\"];\n\n /**\n * The tool registry (Map of name -> tool definition)\n */\n toolRegistry: TamboRegistryContextType[\"toolRegistry\"];\n\n /**\n * Current thread ID (always available - uses \"placeholder\" for new threads)\n */\n currentThreadId: string;\n\n /**\n * Initialize a new thread in the stream context\n */\n initThread: ThreadManagement[\"initThread\"];\n\n /**\n * Switch the current active thread\n */\n switchThread: ThreadManagement[\"switchThread\"];\n\n /**\n * Start a new thread (generates a temporary ID)\n */\n startNewThread: ThreadManagement[\"startNewThread\"];\n\n /**\n * Dispatch function for stream events (advanced usage)\n */\n dispatch: ReturnType<typeof useStreamDispatch>;\n\n /**\n * Cancel the current run on this thread.\n * Optimistically updates local state and sends cancellation request to the API.\n * No-op if there's no active run or thread is a placeholder.\n */\n cancelRun: () => Promise<void>;\n\n /**\n * Current authentication state.\n * Use this to show auth-related UI or conditionally render features.\n */\n authState: TamboAuthState;\n\n /**\n * Shorthand for `authState.status === \"identified\"`.\n * When true, the SDK is ready to make API calls.\n */\n isIdentified: boolean;\n\n /**\n * Update a thread's name.\n * Useful for implementing manual thread renaming UI in history sidebars.\n * Cache invalidation is best-effort; failures will be logged and won't reject.\n * @param threadId - ID of the thread to rename\n * @param name - New name for the thread\n * @returns Promise that resolves when the update completes\n */\n updateThreadName: (threadId: string, name: string) => Promise<void>;\n}\n\n/**\n * Main hook for accessing Tambo functionality.\n *\n * Combines thread state, streaming status, registry, and client\n * into a single convenient hook.\n *\n * Messages returned include renderedComponent on component content blocks,\n * allowing direct rendering via {content.renderedComponent}.\n * @param threadId - Optional thread ID to get state for\n * @returns Combined context with thread state, messages, and utilities\n * @example\n * ```tsx\n * function ChatInterface() {\n * const {\n * thread,\n * messages,\n * isStreaming,\n * registerComponent,\n * } = useTambo('thread_123');\n *\n * return (\n * <div>\n * {messages.map(msg => <Message key={msg.id} message={msg} />)}\n * {isStreaming && <LoadingIndicator />}\n * </div>\n * );\n * }\n * ```\n */\n/**\n * Cache entry for a rendered component wrapper.\n * Stores the element and the props JSON used to create it.\n */\ninterface ComponentCacheEntry {\n element: ReactElement;\n propsJson: string;\n}\n\n/**\n *\n * @returns The combined Tambo context\n */\nexport function useTambo(): UseTamboReturn {\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const { userKey } = useTamboConfig();\n const streamState = useStreamState();\n const dispatch = useStreamDispatch();\n const registry = useContext(TamboRegistryContext);\n const threadManagement = useThreadManagement();\n const authState = useTamboAuthState();\n\n // Cache for rendered component wrappers - maintains stable element references\n // across renders when props haven't changed\n const componentCacheRef = useRef<Map<string, ComponentCacheEntry>>(new Map());\n\n // Get thread state for the current thread\n const threadState = streamState.threadMap[streamState.currentThreadId];\n\n // Keep a live snapshot of the threadMap for callbacks without forcing them to\n // re-create on every stream state update.\n const threadMapRef = useRef(streamState.threadMap);\n threadMapRef.current = streamState.threadMap;\n\n // Cancel the current run on this thread\n const cancelRun = useCallback(async () => {\n const runId = threadState?.streaming.runId;\n const threadId = streamState.currentThreadId;\n\n // No-op if there's no active run or thread is a placeholder\n if (!runId || isPlaceholderThreadId(threadId)) {\n return;\n }\n\n // Optimistically update local state with RUN_ERROR event\n dispatch({\n type: \"EVENT\",\n threadId,\n event: {\n type: EventType.RUN_ERROR,\n message: \"Run cancelled\",\n code: \"CANCELLED\",\n timestamp: Date.now(),\n },\n });\n\n // Call API to cancel the run\n try {\n await client.threads.runs.delete(runId, { threadId, userKey });\n } catch (error) {\n // Log but don't rethrow - local state is already updated\n console.warn(\"Failed to cancel run on server:\", error);\n }\n }, [\n client,\n userKey,\n streamState.currentThreadId,\n threadState?.streaming.runId,\n dispatch,\n ]);\n\n // Update a thread's name\n const updateThreadName = useCallback(\n async (threadId: string, name: string) => {\n await client.threads.update(threadId, { name });\n\n if (threadMapRef.current[threadId]) {\n dispatch({\n type: \"UPDATE_THREAD_NAME\",\n threadId,\n name: name,\n });\n }\n\n try {\n await Promise.all([\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n }),\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", threadId],\n }),\n ]);\n } catch (error) {\n console.warn(\n \"[useTambo] Failed to invalidate thread queries after rename:\",\n error,\n );\n }\n },\n [client, dispatch, queryClient],\n );\n\n // Memoize the return object to prevent unnecessary re-renders\n return useMemo(() => {\n const thread = threadState;\n const rawMessages = thread?.thread.messages ?? [];\n const streamingState: StreamingState = thread?.streaming ?? {\n status: \"idle\" as const,\n };\n\n // Build a set of tool_use IDs that have completed (have a matching tool_result)\n // We need to look across all messages since tool_result might be in a different message\n const completedToolIds = new Set<string>();\n for (const msg of rawMessages) {\n for (const content of msg.content) {\n if (content.type === \"tool_result\") {\n completedToolIds.add(content.toolUseId);\n }\n }\n }\n\n // Transform messages to add computed properties to content blocks\n const messages = rawMessages.map((message): TamboThreadMessage => {\n const transformedContent = message.content.map((content): Content => {\n // Transform tool_use content to add computed state\n if (content.type === \"tool_use\") {\n const hasCompleted = completedToolIds.has(content.id);\n const input = content.input ?? {};\n\n // Extract Tambo display props from input\n const tamboDisplayProps: TamboToolDisplayProps = {\n _tambo_statusMessage:\n typeof input._tambo_statusMessage === \"string\"\n ? input._tambo_statusMessage\n : undefined,\n _tambo_completionStatusMessage:\n typeof input._tambo_completionStatusMessage === \"string\"\n ? input._tambo_completionStatusMessage\n : undefined,\n };\n\n // Compute status message based on completion state\n const statusMessage = hasCompleted\n ? (tamboDisplayProps._tambo_completionStatusMessage ??\n `Called ${content.name}`)\n : (tamboDisplayProps._tambo_statusMessage ??\n `Calling ${content.name}`);\n\n // Filter out _tambo_* properties from input - consumers only see actual tool params\n const cleanInput: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(input)) {\n if (!key.startsWith(\"_tambo_\")) {\n cleanInput[key] = value;\n }\n }\n\n const v1Content: TamboToolUseContent = {\n ...content,\n input: cleanInput,\n hasCompleted,\n statusMessage,\n tamboDisplayProps,\n };\n return v1Content;\n }\n\n if (content.type !== \"component\") {\n return content;\n }\n\n const componentContent = content;\n const propsJson = JSON.stringify(componentContent.props ?? {});\n const cache = componentCacheRef.current;\n const cached = cache.get(componentContent.id);\n\n // Return cached element if props haven't changed\n if (cached?.propsJson === propsJson) {\n return {\n ...componentContent,\n renderedComponent: cached.element,\n };\n }\n\n // Create new wrapper element\n const element = React.createElement(ComponentRenderer, {\n key: componentContent.id,\n content: componentContent,\n threadId: streamState.currentThreadId,\n messageId: message.id,\n });\n\n // Update cache\n cache.set(componentContent.id, { element, propsJson });\n\n return {\n ...componentContent,\n renderedComponent: element,\n };\n });\n\n return {\n ...message,\n content: transformedContent,\n };\n });\n\n return {\n client,\n thread,\n messages,\n streamingState,\n isStreaming: streamingState.status === \"streaming\",\n isWaiting: streamingState.status === \"waiting\",\n isIdle: streamingState.status === \"idle\",\n registerComponent: registry.registerComponent,\n registerTool: registry.registerTool,\n registerTools: registry.registerTools,\n componentList: registry.componentList,\n toolRegistry: registry.toolRegistry,\n currentThreadId: streamState.currentThreadId,\n initThread: threadManagement.initThread,\n switchThread: threadManagement.switchThread,\n startNewThread: threadManagement.startNewThread,\n dispatch,\n cancelRun,\n authState,\n isIdentified: authState.status === \"identified\",\n updateThreadName,\n };\n }, [\n cancelRun,\n updateThreadName,\n client,\n threadState,\n registry,\n streamState.currentThreadId,\n threadManagement,\n dispatch,\n authState,\n ]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNb,4BAqOC;AApbD;;;;;GAKG;AAEH,sCAAwC;AAExC,+CAMe;AACf,iFAG+C;AAC/C,sEAAgE;AAChE,uEAA8D;AAE9D,qFAGiD;AACjD,+EAAwE;AACxE,kFAK8C;AAQ9C,kEAGoC;AA+JpC;;;GAGG;AACH,SAAgB,QAAQ;IACtB,MAAM,MAAM,GAAG,IAAA,sCAAc,GAAE,CAAC;IAChC,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,kCAAc,GAAE,CAAC;IACrC,MAAM,WAAW,GAAG,IAAA,wCAAc,GAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAA,2CAAiB,GAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAA,kBAAU,EAAC,8CAAoB,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,IAAA,6CAAmB,GAAE,CAAC;IAC/C,MAAM,SAAS,GAAG,IAAA,2CAAiB,GAAE,CAAC;IAEtC,8EAA8E;IAC9E,4CAA4C;IAC5C,MAAM,iBAAiB,GAAG,IAAA,cAAM,EAAmC,IAAI,GAAG,EAAE,CAAC,CAAC;IAE9E,0CAA0C;IAC1C,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IAEvE,8EAA8E;IAC9E,0CAA0C;IAC1C,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACnD,YAAY,CAAC,OAAO,G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AAM;YACN,MAAM;YACN,QAAQ;YACR,cAAc;YACd,WAAW,EAAE,cAAc,CAAC,MAAM,KAAK,WAAW;YAClD,SAAS,EAAE,cAAc,CAAC,MAAM,KAAK,SAAS;YAC9C,MAAM,EAAE,cAAc,CAAC,MAAM,KAAK,MAAM;YACxC,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;YAC7C,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,aAAa,EAAE,QAAQ,CAAC,aAAa;YACrC,aAAa,EAAE,QAAQ,CAAC,aAAa;YACrC,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,eAAe,EAAE,WAAW,CAAC,eAAe;YAC5C,UAAU,EAAE,gBAAgB,CAAC,UAAU;YACvC,YAAY,EAAE,gBAAgB,CAAC,YAAY;YAC3C,cAAc,EAAE,gBAAgB,CAAC,cAAc;YAC/C,QAAQ;YACR,SAAS;YACT,SAAS;YACT,YAAY,EAAE,SAAS,CAAC,MAAM,KAAK,YAAY;YAC/C,gBAAgB;SACjB,CAAC;IACJ,CAAC,EAAE;QACD,SAAS;QACT,gBAAgB;QAChB,MAAM;QACN,WAAW;QACX,QAAQ;QACR,WAAW,CAAC,eAAe;QAC3B,gBAAgB;QAChB,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * useTambo - Main Hook\n *\n * Combines all contexts into a single hook for convenient access\n * to thread state, streaming status, registry, and client.\n */\n\nimport { EventType } from \"@ag-ui/core\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n useCallback,\n useContext,\n useMemo,\n useRef,\n type ReactElement,\n} from \"react\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboConfig } from \"../providers/tambo-v1-provider\";\nimport { useTamboAuthState } from \"./use-tambo-v1-auth-state\";\nimport type { TamboAuthState } from \"../types/auth\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { ComponentRenderer } from \"../components/v1-component-renderer\";\nimport {\n useStreamDispatch,\n useStreamState,\n useThreadManagement,\n type ThreadManagement,\n} from \"../providers/tambo-v1-stream-context\";\nimport type {\n Content,\n TamboToolDisplayProps,\n TamboThreadMessage,\n TamboToolUseContent,\n} from \"../types/message\";\nimport type { StreamingState } from \"../types/thread\";\nimport {\n isPlaceholderThreadId,\n type ThreadState,\n} from \"../utils/event-accumulator\";\n\n/**\n * Return type for useTambo hook\n */\nexport interface UseTamboReturn {\n /**\n * The Tambo API client instance\n */\n client: TamboAI;\n\n /**\n * Current thread state for the given threadId, or undefined if not loaded\n */\n thread: ThreadState | undefined;\n\n /**\n * Messages in the current thread\n */\n messages: TamboThreadMessage[];\n\n /**\n * Current streaming state\n */\n streamingState: StreamingState;\n\n /**\n * Whether the thread is currently streaming a response\n */\n isStreaming: boolean;\n\n /**\n * Whether the thread is waiting for the AI to start responding\n */\n isWaiting: boolean;\n\n /**\n * Whether the thread is idle (not streaming or waiting)\n */\n isIdle: boolean;\n\n /**\n * Register a component with the registry\n */\n registerComponent: TamboRegistryContextType[\"registerComponent\"];\n\n /**\n * Register a tool with the registry\n */\n registerTool: TamboRegistryContextType[\"registerTool\"];\n\n /**\n * Register multiple tools with the registry\n */\n registerTools: TamboRegistryContextType[\"registerTools\"];\n\n /**\n * The component registry (Map of name -> component definition)\n */\n componentList: TamboRegistryContextType[\"componentList\"];\n\n /**\n * The tool registry (Map of name -> tool definition)\n */\n toolRegistry: TamboRegistryContextType[\"toolRegistry\"];\n\n /**\n * Current thread ID (always available - uses \"placeholder\" for new threads)\n */\n currentThreadId: string;\n\n /**\n * Initialize a new thread in the stream context\n */\n initThread: ThreadManagement[\"initThread\"];\n\n /**\n * Switch the current active thread\n */\n switchThread: ThreadManagement[\"switchThread\"];\n\n /**\n * Start a new thread (generates a temporary ID)\n */\n startNewThread: ThreadManagement[\"startNewThread\"];\n\n /**\n * Dispatch function for stream events (advanced usage)\n */\n dispatch: ReturnType<typeof useStreamDispatch>;\n\n /**\n * Cancel the current run on this thread.\n * Optimistically updates local state and sends cancellation request to the API.\n * No-op if there's no active run or thread is a placeholder.\n */\n cancelRun: () => Promise<void>;\n\n /**\n * Current authentication state.\n * Use this to show auth-related UI or conditionally render features.\n */\n authState: TamboAuthState;\n\n /**\n * Shorthand for `authState.status === \"identified\"`.\n * When true, the SDK is ready to make API calls.\n */\n isIdentified: boolean;\n\n /**\n * Update a thread's name.\n * Useful for implementing manual thread renaming UI in history sidebars.\n * Cache invalidation is best-effort; failures will be logged and won't reject.\n * @param threadId - ID of the thread to rename\n * @param name - New name for the thread\n * @returns Promise that resolves when the update completes\n */\n updateThreadName: (threadId: string, name: string) => Promise<void>;\n}\n\n/**\n * Main hook for accessing Tambo functionality.\n *\n * Combines thread state, streaming status, registry, and client\n * into a single convenient hook.\n *\n * Messages returned include renderedComponent on component content blocks,\n * allowing direct rendering via {content.renderedComponent}.\n * @param threadId - Optional thread ID to get state for\n * @returns Combined context with thread state, messages, and utilities\n * @example\n * ```tsx\n * function ChatInterface() {\n * const {\n * thread,\n * messages,\n * isStreaming,\n * registerComponent,\n * } = useTambo('thread_123');\n *\n * return (\n * <div>\n * {messages.map(msg => <Message key={msg.id} message={msg} />)}\n * {isStreaming && <LoadingIndicator />}\n * </div>\n * );\n * }\n * ```\n */\n/**\n * Cache entry for a rendered component wrapper.\n * Stores the element and the props JSON used to create it.\n */\ninterface ComponentCacheEntry {\n element: ReactElement;\n propsJson: string;\n}\n\n/**\n *\n * @returns The combined Tambo context\n */\nexport function useTambo(): UseTamboReturn {\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const { userKey } = useTamboConfig();\n const streamState = useStreamState();\n const dispatch = useStreamDispatch();\n const registry = useContext(TamboRegistryContext);\n const threadManagement = useThreadManagement();\n const authState = useTamboAuthState();\n\n // Cache for rendered component wrappers - maintains stable element references\n // across renders when props haven't changed\n const componentCacheRef = useRef<Map<string, ComponentCacheEntry>>(new Map());\n\n // Get thread state for the current thread\n const threadState = streamState.threadMap[streamState.currentThreadId];\n\n // Keep a live snapshot of the threadMap for callbacks without forcing them to\n // re-create on every stream state update.\n const threadMapRef = useRef(streamState.threadMap);\n threadMapRef.current = streamState.threadMap;\n\n // Cancel the current run on this thread\n const cancelRun = useCallback(async () => {\n const runId = threadState?.streaming.runId;\n const threadId = streamState.currentThreadId;\n\n // No-op if there's no active run or thread is a placeholder\n if (!runId || isPlaceholderThreadId(threadId)) {\n return;\n }\n\n // Optimistically update local state with RUN_ERROR event\n dispatch({\n type: \"EVENT\",\n threadId,\n event: {\n type: EventType.RUN_ERROR,\n message: \"Run cancelled\",\n code: \"CANCELLED\",\n timestamp: Date.now(),\n },\n });\n\n // Call API to cancel the run\n try {\n await client.threads.runs.delete(runId, { threadId, userKey });\n } catch (error) {\n // Log but don't rethrow - local state is already updated\n console.warn(\"Failed to cancel run on server:\", error);\n }\n }, [\n client,\n userKey,\n streamState.currentThreadId,\n threadState?.streaming.runId,\n dispatch,\n ]);\n\n // Update a thread's name\n const updateThreadName = useCallback(\n async (threadId: string, name: string) => {\n await client.threads.update(threadId, { name, userKey });\n\n if (threadMapRef.current[threadId]) {\n dispatch({\n type: \"UPDATE_THREAD_NAME\",\n threadId,\n name: name,\n });\n }\n\n try {\n await Promise.all([\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n }),\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", threadId],\n }),\n ]);\n } catch (error) {\n console.warn(\n \"[useTambo] Failed to invalidate thread queries after rename:\",\n error,\n );\n }\n },\n [client, userKey, dispatch, queryClient],\n );\n\n // Memoize the return object to prevent unnecessary re-renders\n return useMemo(() => {\n const thread = threadState;\n const rawMessages = thread?.thread.messages ?? [];\n const streamingState: StreamingState = thread?.streaming ?? {\n status: \"idle\" as const,\n };\n\n // Build a set of tool_use IDs that have completed (have a matching tool_result)\n // We need to look across all messages since tool_result might be in a different message\n const completedToolIds = new Set<string>();\n for (const msg of rawMessages) {\n for (const content of msg.content) {\n if (content.type === \"tool_result\") {\n completedToolIds.add(content.toolUseId);\n }\n }\n }\n\n // Transform messages to add computed properties to content blocks\n const messages = rawMessages.map((message): TamboThreadMessage => {\n const transformedContent = message.content.map((content): Content => {\n // Transform tool_use content to add computed state\n if (content.type === \"tool_use\") {\n const hasCompleted = completedToolIds.has(content.id);\n const input = content.input ?? {};\n\n // Extract Tambo display props from input\n const tamboDisplayProps: TamboToolDisplayProps = {\n _tambo_statusMessage:\n typeof input._tambo_statusMessage === \"string\"\n ? input._tambo_statusMessage\n : undefined,\n _tambo_completionStatusMessage:\n typeof input._tambo_completionStatusMessage === \"string\"\n ? input._tambo_completionStatusMessage\n : undefined,\n };\n\n // Compute status message based on completion state\n const statusMessage = hasCompleted\n ? (tamboDisplayProps._tambo_completionStatusMessage ??\n `Called ${content.name}`)\n : (tamboDisplayProps._tambo_statusMessage ??\n `Calling ${content.name}`);\n\n // Filter out _tambo_* properties from input - consumers only see actual tool params\n const cleanInput: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(input)) {\n if (!key.startsWith(\"_tambo_\")) {\n cleanInput[key] = value;\n }\n }\n\n const v1Content: TamboToolUseContent = {\n ...content,\n input: cleanInput,\n hasCompleted,\n statusMessage,\n tamboDisplayProps,\n };\n return v1Content;\n }\n\n if (content.type !== \"component\") {\n return content;\n }\n\n const componentContent = content;\n const propsJson = JSON.stringify(componentContent.props ?? {});\n const cache = componentCacheRef.current;\n const cached = cache.get(componentContent.id);\n\n // Return cached element if props haven't changed\n if (cached?.propsJson === propsJson) {\n return {\n ...componentContent,\n renderedComponent: cached.element,\n };\n }\n\n // Create new wrapper element\n const element = React.createElement(ComponentRenderer, {\n key: componentContent.id,\n content: componentContent,\n threadId: streamState.currentThreadId,\n messageId: message.id,\n });\n\n // Update cache\n cache.set(componentContent.id, { element, propsJson });\n\n return {\n ...componentContent,\n renderedComponent: element,\n };\n });\n\n return {\n ...message,\n content: transformedContent,\n };\n });\n\n return {\n client,\n thread,\n messages,\n streamingState,\n isStreaming: streamingState.status === \"streaming\",\n isWaiting: streamingState.status === \"waiting\",\n isIdle: streamingState.status === \"idle\",\n registerComponent: registry.registerComponent,\n registerTool: registry.registerTool,\n registerTools: registry.registerTools,\n componentList: registry.componentList,\n toolRegistry: registry.toolRegistry,\n currentThreadId: streamState.currentThreadId,\n initThread: threadManagement.initThread,\n switchThread: threadManagement.switchThread,\n startNewThread: threadManagement.startNewThread,\n dispatch,\n cancelRun,\n authState,\n isIdentified: authState.status === \"identified\",\n updateThreadName,\n };\n }, [\n cancelRun,\n updateThreadName,\n client,\n threadState,\n registry,\n streamState.currentThreadId,\n threadManagement,\n dispatch,\n authState,\n ]);\n}\n"]}
|
|
@@ -1084,6 +1084,7 @@ describe("useTambo", () => {
|
|
|
1084
1084
|
});
|
|
1085
1085
|
expect(mockUpdate).toHaveBeenCalledWith("thread_456", {
|
|
1086
1086
|
name: "My New Thread",
|
|
1087
|
+
userKey: undefined,
|
|
1087
1088
|
});
|
|
1088
1089
|
expect(result.current.thread?.thread.name).toBe("My New Thread");
|
|
1089
1090
|
const invalidatedKeys = invalidateQueriesSpy.mock.calls
|
|
@@ -1114,6 +1115,7 @@ describe("useTambo", () => {
|
|
|
1114
1115
|
});
|
|
1115
1116
|
expect(mockUpdate).toHaveBeenCalledWith("thread_789", {
|
|
1116
1117
|
name: "New Title",
|
|
1118
|
+
userKey: undefined,
|
|
1117
1119
|
});
|
|
1118
1120
|
const invalidatedKeys = invalidateQueriesSpy.mock.calls
|
|
1119
1121
|
.map(([arg]) => arg.queryKey)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uDAAyE;AACzE,kDAAyD;AACzD,+CAA0C;AAC1C,iFAAuE;A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;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { renderHook, act } from \"@testing-library/react\";\nimport React, { useReducer } from \"react\";\nimport { useTamboClient } from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { TamboStreamProvider } from \"../providers/tambo-v1-stream-context\";\nimport {\n streamReducer,\n type StreamState,\n type StreamAction,\n} from \"../utils/event-accumulator\";\nimport type {\n TamboComponentContent,\n TamboToolUseContent,\n} from \"../types/message\";\nimport { useTambo } from \"./use-tambo-v1\";\n\njest.mock(\"../../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n useTamboQueryClient: jest.fn(),\n}));\n\njest.mock(\"../providers/tambo-v1-provider\", () => {\n const actual = jest.requireActual(\"../providers/tambo-v1-provider\");\n return {\n ...actual,\n useTamboConfig: () => ({ userKey: undefined }),\n };\n});\n\njest.mock(\"./use-tambo-v1-auth-state\", () => ({\n useTamboAuthState: () => ({\n status: \"identified\",\n source: \"userKey\",\n }),\n}));\n\nimport { useTamboQueryClient } from \"../../providers/tambo-client-provider\";\n\ndescribe(\"useTambo\", () => {\n let queryClient: QueryClient;\n\n const mockTamboClient = {\n apiKey: \"\",\n threads: {\n messages: {\n list: jest.fn().mockResolvedValue({ messages: [], hasMore: false }),\n },\n runs: {\n delete: jest.fn().mockResolvedValue({}),\n },\n },\n } as unknown as TamboAI;\n\n const mockRegistry: TamboRegistryContextType = {\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n registerComponent: jest.fn(),\n registerTool: jest.fn(),\n registerTools: jest.fn(),\n addToolAssociation: jest.fn(),\n registerMcpServer: jest.fn(),\n registerMcpServers: jest.fn(),\n registerResource: jest.fn(),\n registerResources: jest.fn(),\n registerResourceSource: jest.fn(),\n };\n\n function TestWrapper({ children }: { children: React.ReactNode }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider>{children}</TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n }\n\n function createWrapperWithState(\n state: StreamState,\n registry: TamboRegistryContextType = mockRegistry,\n ) {\n const noopDispatch: React.Dispatch<StreamAction> = () => {};\n return function WrapperWithState({\n children,\n }: {\n children: React.ReactNode;\n }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={registry}>\n <TamboStreamProvider state={state} dispatch={noopDispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n // Wrapper that uses the real reducer so state updates properly\n function createWrapperWithRealReducer(\n initialState: StreamState,\n stateRef?: React.MutableRefObject<StreamState | undefined>,\n ) {\n return function WrapperWithRealReducer({\n children,\n }: {\n children: React.ReactNode;\n }) {\n const [state, dispatch] = useReducer(streamReducer, initialState);\n if (stateRef) {\n stateRef.current = state;\n }\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider state={state} dispatch={dispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n beforeEach(() => {\n queryClient = new QueryClient({\n defaultOptions: {\n queries: { retry: false },\n },\n });\n jest.mocked(useTamboClient).mockReturnValue(mockTamboClient);\n jest.mocked(useTamboQueryClient).mockReturnValue(queryClient);\n jest.clearAllMocks();\n delete (mockTamboClient.threads as any).update;\n });\n\n it(\"returns client from useTamboClient\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.client).toBe(mockTamboClient);\n });\n\n it(\"returns registry functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.registerComponent).toBe(\n mockRegistry.registerComponent,\n );\n expect(result.current.registerTool).toBe(mockRegistry.registerTool);\n expect(result.current.registerTools).toBe(mockRegistry.registerTools);\n expect(result.current.componentList).toBe(mockRegistry.componentList);\n expect(result.current.toolRegistry).toBe(mockRegistry.toolRegistry);\n });\n\n it(\"returns placeholder thread when no threadId provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Default state has placeholder thread for optimistic UI\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns thread state when switched to a thread\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns default streaming state when thread not loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.streamingState).toEqual({ status: \"idle\" });\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"returns thread streaming state when thread loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.streamingState.status).toBe(\"idle\");\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"provides dispatch function for advanced usage\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.dispatch).toBe(\"function\");\n });\n\n it(\"provides thread management functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.initThread).toBe(\"function\");\n expect(typeof result.current.switchThread).toBe(\"function\");\n expect(typeof result.current.startNewThread).toBe(\"function\");\n });\n\n it(\"initializes and switches threads\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initially has placeholder thread for optimistic UI\n expect(result.current.currentThreadId).toBe(\"placeholder\");\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n\n // Initialize a new thread\n act(() => {\n result.current.initThread(\"new_thread_1\");\n });\n\n // Switch to the new thread\n act(() => {\n result.current.switchThread(\"new_thread_1\");\n });\n\n expect(result.current.currentThreadId).toBe(\"new_thread_1\");\n });\n\n it(\"starts new thread with generated ID\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n let newThreadId: string;\n act(() => {\n newThreadId = result.current.startNewThread();\n });\n\n expect(newThreadId!).toBe(\"placeholder\");\n expect(result.current.currentThreadId).toBe(newThreadId!);\n expect(result.current.thread).toBeDefined();\n });\n\n it(\"uses current thread when no threadId argument provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to a thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n // Should use current thread from context (thread_123)\n expect(result.current.currentThreadId).toBe(\"thread_123\");\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n });\n\n describe(\"component content transformation\", () => {\n const createComponentContent = (\n id: string,\n name: string,\n props: Record<string, unknown>,\n ): TamboComponentContent => ({\n type: \"component\",\n id,\n name,\n props,\n streamingState: \"done\",\n });\n\n it(\"adds renderedComponent to component content blocks\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"preserves non-component content blocks unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n { type: \"text\", text: \"Hello world\" },\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hi\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const textContent = result.current.messages[0].content[0];\n expect(textContent.type).toBe(\"text\");\n expect(textContent).toEqual({ type: \"text\", text: \"Hello world\" });\n\n const componentContent = result.current.messages[0].content[1];\n expect(componentContent.type).toBe(\"component\");\n expect(\n (componentContent as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"caches rendered components and returns same reference when props unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result, rerender } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const firstRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Re-render with same state\n rerender();\n\n const secondRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Should return the same cached element reference\n expect(secondRender).toBe(firstRender);\n });\n\n it(\"handles empty props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {}),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles undefined props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: undefined,\n streamingState: \"done\",\n } as TamboComponentContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles multiple component content blocks in same message\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"ComponentA\", {\n value: 1,\n }),\n createComponentContent(\"comp_2\", \"ComponentB\", {\n value: 2,\n }),\n createComponentContent(\"comp_3\", \"ComponentC\", {\n value: 3,\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages[0].content).toHaveLength(3);\n result.current.messages[0].content.forEach((content) => {\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n it(\"uses currentThreadId from stream state\", () => {\n const state: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n // No explicit threadId - uses currentThreadId from state\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n // Component should render using the placeholder thread\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n describe(\"tool_use content transformation\", () => {\n it(\"adds computed properties to tool_use content\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.type).toBe(\"tool_use\");\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getWeather\");\n expect(content.tamboDisplayProps).toBeDefined();\n });\n\n it(\"sets hasCompleted to true when matching tool_result exists\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Called getWeather\");\n });\n\n it(\"uses _tambo_statusMessage when tool is in progress\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather for NYC...\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.statusMessage).toBe(\"Fetching weather for NYC...\");\n expect(content.tamboDisplayProps?._tambo_statusMessage).toBe(\n \"Fetching weather for NYC...\",\n );\n });\n\n it(\"uses _tambo_completionStatusMessage when tool is completed\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather...\",\n _tambo_completionStatusMessage: \"Got weather for NYC\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Got weather for NYC\");\n });\n\n it(\"filters _tambo_* properties from input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n units: \"celsius\",\n _tambo_statusMessage: \"Fetching...\",\n _tambo_completionStatusMessage: \"Done\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n // Input should only have non-_tambo_ properties\n expect(content.input).toEqual({ location: \"NYC\", units: \"celsius\" });\n expect(content.input._tambo_statusMessage).toBeUndefined();\n expect(content.input._tambo_completionStatusMessage).toBeUndefined();\n });\n\n it(\"handles tool_use with empty input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: {},\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getCurrentTime\");\n });\n\n it(\"handles tool_use with undefined input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: undefined,\n } as unknown as TamboToolUseContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n });\n\n it(\"handles multiple tool_use blocks with different completion states\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n {\n type: \"tool_use\",\n id: \"tool_2\",\n name: \"getTime\",\n input: { timezone: \"EST\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n // tool_2 has no result yet\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const tool1 = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n const tool2 = result.current.messages[0]\n .content[1] as TamboToolUseContent;\n\n expect(tool1.hasCompleted).toBe(true);\n expect(tool1.statusMessage).toBe(\"Called getWeather\");\n\n expect(tool2.hasCompleted).toBe(false);\n expect(tool2.statusMessage).toBe(\"Calling getTime\");\n });\n });\n\n describe(\"cancelRun\", () => {\n it(\"sets thread to idle and lastRunCancelled to true when cancelled\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before cancel: streaming and lastRunCancelled is false\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.isIdle).toBe(false);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After cancel: idle and lastRunCancelled is true\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Verify API was called to cancel the run\n expect(mockTamboClient.threads.runs.delete).toHaveBeenCalledWith(\n \"run_456\",\n { threadId: \"thread_123\" },\n );\n });\n\n it(\"is a no-op when there is no active run\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" }, // No runId\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Idle before\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Still idle, lastRunCancelled unchanged\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"is a no-op when on a placeholder thread\", async () => {\n const initialState: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_123\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before: streaming on placeholder\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After: state should be unchanged (placeholder threads are skipped)\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called for placeholder threads\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"still updates local state even if API call fails\", async () => {\n const consoleWarnSpy = jest\n .spyOn(console, \"warn\")\n .mockImplementation(() => {});\n\n // Make the API call fail\n jest\n .mocked(mockTamboClient.threads.runs.delete)\n .mockRejectedValueOnce(new Error(\"Network error\"));\n\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Local state should still be updated (optimistic update)\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Warning should have been logged\n expect(consoleWarnSpy).toHaveBeenCalledWith(\n \"Failed to cancel run on server:\",\n expect.any(Error),\n );\n\n consoleWarnSpy.mockRestore();\n });\n });\n\n describe(\"updateThreadName\", () => {\n it(\"updates local thread name and invalidates caches on success\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_456\", {\n name: \"My New Thread\",\n });\n\n expect(result.current.thread?.thread.name).toBe(\"My New Thread\");\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_456\"]);\n });\n\n it(\"does not create local thread state when thread isn't loaded\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n // Track the internal StreamState from the real reducer so we can assert we\n // don't create a local thread entry for threads that haven't been loaded.\n const stateRef: React.MutableRefObject<StreamState | undefined> = {\n current: undefined,\n };\n const initialState: StreamState = {\n threadMap: {},\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState, stateRef),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_789\", \"New Title\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_789\", {\n name: \"New Title\",\n });\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_789\"]);\n\n expect(stateRef.current?.threadMap.thread_789).toBeUndefined();\n\n act(() => {\n result.current.switchThread(\"thread_789\");\n });\n\n expect(result.current.thread).toBeUndefined();\n });\n\n it(\"propagates errors and does not update local state\", async () => {\n const mockUpdate = jest\n .fn()\n .mockRejectedValue(new Error(\"Network error\"));\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n let caughtError: unknown;\n await act(async () => {\n try {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n } catch (error) {\n caughtError = error;\n }\n });\n\n expect(caughtError).toBeInstanceOf(Error);\n expect((caughtError as Error).message).toBe(\"Network error\");\n expect(result.current.thread?.thread.name).toBe(\"Old Name\");\n expect(invalidateQueriesSpy).not.toHaveBeenCalled();\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uDAAyE;AACzE,kDAAyD;AACzD,+CAA0C;AAC1C,iFAAuE;AACvE,qFAGiD;AACjD,kFAA2E;AAC3E,kEAIoC;AAKpC,iDAA0C;AAE1C,IAAI,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxD,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;IACzB,mBAAmB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC/B,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACpE,OAAO;QACL,GAAG,MAAM;QACT,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5C,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;QACxB,MAAM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,CAAC;YACzB,MAAM,IAAA,WAAG,EAAC,KAAK,IAAI,EAAE;gBACnB,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;gBACvE,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,WAAW,GAAG,KAAK,CAAC;gBACtB,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC1C,MAAM,CAAE,WAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC7D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5D,MAAM,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { renderHook, act } from \"@testing-library/react\";\nimport React, { useReducer } from \"react\";\nimport { useTamboClient } from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { TamboStreamProvider } from \"../providers/tambo-v1-stream-context\";\nimport {\n streamReducer,\n type StreamState,\n type StreamAction,\n} from \"../utils/event-accumulator\";\nimport type {\n TamboComponentContent,\n TamboToolUseContent,\n} from \"../types/message\";\nimport { useTambo } from \"./use-tambo-v1\";\n\njest.mock(\"../../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n useTamboQueryClient: jest.fn(),\n}));\n\njest.mock(\"../providers/tambo-v1-provider\", () => {\n const actual = jest.requireActual(\"../providers/tambo-v1-provider\");\n return {\n ...actual,\n useTamboConfig: () => ({ userKey: undefined }),\n };\n});\n\njest.mock(\"./use-tambo-v1-auth-state\", () => ({\n useTamboAuthState: () => ({\n status: \"identified\",\n source: \"userKey\",\n }),\n}));\n\nimport { useTamboQueryClient } from \"../../providers/tambo-client-provider\";\n\ndescribe(\"useTambo\", () => {\n let queryClient: QueryClient;\n\n const mockTamboClient = {\n apiKey: \"\",\n threads: {\n messages: {\n list: jest.fn().mockResolvedValue({ messages: [], hasMore: false }),\n },\n runs: {\n delete: jest.fn().mockResolvedValue({}),\n },\n },\n } as unknown as TamboAI;\n\n const mockRegistry: TamboRegistryContextType = {\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n registerComponent: jest.fn(),\n registerTool: jest.fn(),\n registerTools: jest.fn(),\n addToolAssociation: jest.fn(),\n registerMcpServer: jest.fn(),\n registerMcpServers: jest.fn(),\n registerResource: jest.fn(),\n registerResources: jest.fn(),\n registerResourceSource: jest.fn(),\n };\n\n function TestWrapper({ children }: { children: React.ReactNode }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider>{children}</TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n }\n\n function createWrapperWithState(\n state: StreamState,\n registry: TamboRegistryContextType = mockRegistry,\n ) {\n const noopDispatch: React.Dispatch<StreamAction> = () => {};\n return function WrapperWithState({\n children,\n }: {\n children: React.ReactNode;\n }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={registry}>\n <TamboStreamProvider state={state} dispatch={noopDispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n // Wrapper that uses the real reducer so state updates properly\n function createWrapperWithRealReducer(\n initialState: StreamState,\n stateRef?: React.MutableRefObject<StreamState | undefined>,\n ) {\n return function WrapperWithRealReducer({\n children,\n }: {\n children: React.ReactNode;\n }) {\n const [state, dispatch] = useReducer(streamReducer, initialState);\n if (stateRef) {\n stateRef.current = state;\n }\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider state={state} dispatch={dispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n beforeEach(() => {\n queryClient = new QueryClient({\n defaultOptions: {\n queries: { retry: false },\n },\n });\n jest.mocked(useTamboClient).mockReturnValue(mockTamboClient);\n jest.mocked(useTamboQueryClient).mockReturnValue(queryClient);\n jest.clearAllMocks();\n delete (mockTamboClient.threads as any).update;\n });\n\n it(\"returns client from useTamboClient\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.client).toBe(mockTamboClient);\n });\n\n it(\"returns registry functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.registerComponent).toBe(\n mockRegistry.registerComponent,\n );\n expect(result.current.registerTool).toBe(mockRegistry.registerTool);\n expect(result.current.registerTools).toBe(mockRegistry.registerTools);\n expect(result.current.componentList).toBe(mockRegistry.componentList);\n expect(result.current.toolRegistry).toBe(mockRegistry.toolRegistry);\n });\n\n it(\"returns placeholder thread when no threadId provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Default state has placeholder thread for optimistic UI\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns thread state when switched to a thread\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns default streaming state when thread not loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.streamingState).toEqual({ status: \"idle\" });\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"returns thread streaming state when thread loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.streamingState.status).toBe(\"idle\");\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"provides dispatch function for advanced usage\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.dispatch).toBe(\"function\");\n });\n\n it(\"provides thread management functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.initThread).toBe(\"function\");\n expect(typeof result.current.switchThread).toBe(\"function\");\n expect(typeof result.current.startNewThread).toBe(\"function\");\n });\n\n it(\"initializes and switches threads\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initially has placeholder thread for optimistic UI\n expect(result.current.currentThreadId).toBe(\"placeholder\");\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n\n // Initialize a new thread\n act(() => {\n result.current.initThread(\"new_thread_1\");\n });\n\n // Switch to the new thread\n act(() => {\n result.current.switchThread(\"new_thread_1\");\n });\n\n expect(result.current.currentThreadId).toBe(\"new_thread_1\");\n });\n\n it(\"starts new thread with generated ID\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n let newThreadId: string;\n act(() => {\n newThreadId = result.current.startNewThread();\n });\n\n expect(newThreadId!).toBe(\"placeholder\");\n expect(result.current.currentThreadId).toBe(newThreadId!);\n expect(result.current.thread).toBeDefined();\n });\n\n it(\"uses current thread when no threadId argument provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to a thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n // Should use current thread from context (thread_123)\n expect(result.current.currentThreadId).toBe(\"thread_123\");\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n });\n\n describe(\"component content transformation\", () => {\n const createComponentContent = (\n id: string,\n name: string,\n props: Record<string, unknown>,\n ): TamboComponentContent => ({\n type: \"component\",\n id,\n name,\n props,\n streamingState: \"done\",\n });\n\n it(\"adds renderedComponent to component content blocks\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"preserves non-component content blocks unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n { type: \"text\", text: \"Hello world\" },\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hi\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const textContent = result.current.messages[0].content[0];\n expect(textContent.type).toBe(\"text\");\n expect(textContent).toEqual({ type: \"text\", text: \"Hello world\" });\n\n const componentContent = result.current.messages[0].content[1];\n expect(componentContent.type).toBe(\"component\");\n expect(\n (componentContent as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"caches rendered components and returns same reference when props unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result, rerender } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const firstRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Re-render with same state\n rerender();\n\n const secondRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Should return the same cached element reference\n expect(secondRender).toBe(firstRender);\n });\n\n it(\"handles empty props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {}),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles undefined props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: undefined,\n streamingState: \"done\",\n } as TamboComponentContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles multiple component content blocks in same message\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"ComponentA\", {\n value: 1,\n }),\n createComponentContent(\"comp_2\", \"ComponentB\", {\n value: 2,\n }),\n createComponentContent(\"comp_3\", \"ComponentC\", {\n value: 3,\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages[0].content).toHaveLength(3);\n result.current.messages[0].content.forEach((content) => {\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n it(\"uses currentThreadId from stream state\", () => {\n const state: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n // No explicit threadId - uses currentThreadId from state\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n // Component should render using the placeholder thread\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n describe(\"tool_use content transformation\", () => {\n it(\"adds computed properties to tool_use content\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.type).toBe(\"tool_use\");\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getWeather\");\n expect(content.tamboDisplayProps).toBeDefined();\n });\n\n it(\"sets hasCompleted to true when matching tool_result exists\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Called getWeather\");\n });\n\n it(\"uses _tambo_statusMessage when tool is in progress\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather for NYC...\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.statusMessage).toBe(\"Fetching weather for NYC...\");\n expect(content.tamboDisplayProps?._tambo_statusMessage).toBe(\n \"Fetching weather for NYC...\",\n );\n });\n\n it(\"uses _tambo_completionStatusMessage when tool is completed\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather...\",\n _tambo_completionStatusMessage: \"Got weather for NYC\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Got weather for NYC\");\n });\n\n it(\"filters _tambo_* properties from input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n units: \"celsius\",\n _tambo_statusMessage: \"Fetching...\",\n _tambo_completionStatusMessage: \"Done\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n // Input should only have non-_tambo_ properties\n expect(content.input).toEqual({ location: \"NYC\", units: \"celsius\" });\n expect(content.input._tambo_statusMessage).toBeUndefined();\n expect(content.input._tambo_completionStatusMessage).toBeUndefined();\n });\n\n it(\"handles tool_use with empty input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: {},\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getCurrentTime\");\n });\n\n it(\"handles tool_use with undefined input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: undefined,\n } as unknown as TamboToolUseContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n });\n\n it(\"handles multiple tool_use blocks with different completion states\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n {\n type: \"tool_use\",\n id: \"tool_2\",\n name: \"getTime\",\n input: { timezone: \"EST\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n // tool_2 has no result yet\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const tool1 = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n const tool2 = result.current.messages[0]\n .content[1] as TamboToolUseContent;\n\n expect(tool1.hasCompleted).toBe(true);\n expect(tool1.statusMessage).toBe(\"Called getWeather\");\n\n expect(tool2.hasCompleted).toBe(false);\n expect(tool2.statusMessage).toBe(\"Calling getTime\");\n });\n });\n\n describe(\"cancelRun\", () => {\n it(\"sets thread to idle and lastRunCancelled to true when cancelled\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before cancel: streaming and lastRunCancelled is false\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.isIdle).toBe(false);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After cancel: idle and lastRunCancelled is true\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Verify API was called to cancel the run\n expect(mockTamboClient.threads.runs.delete).toHaveBeenCalledWith(\n \"run_456\",\n { threadId: \"thread_123\" },\n );\n });\n\n it(\"is a no-op when there is no active run\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" }, // No runId\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Idle before\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Still idle, lastRunCancelled unchanged\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"is a no-op when on a placeholder thread\", async () => {\n const initialState: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_123\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before: streaming on placeholder\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After: state should be unchanged (placeholder threads are skipped)\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called for placeholder threads\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"still updates local state even if API call fails\", async () => {\n const consoleWarnSpy = jest\n .spyOn(console, \"warn\")\n .mockImplementation(() => {});\n\n // Make the API call fail\n jest\n .mocked(mockTamboClient.threads.runs.delete)\n .mockRejectedValueOnce(new Error(\"Network error\"));\n\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Local state should still be updated (optimistic update)\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Warning should have been logged\n expect(consoleWarnSpy).toHaveBeenCalledWith(\n \"Failed to cancel run on server:\",\n expect.any(Error),\n );\n\n consoleWarnSpy.mockRestore();\n });\n });\n\n describe(\"updateThreadName\", () => {\n it(\"updates local thread name and invalidates caches on success\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_456\", {\n name: \"My New Thread\",\n userKey: undefined,\n });\n\n expect(result.current.thread?.thread.name).toBe(\"My New Thread\");\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_456\"]);\n });\n\n it(\"does not create local thread state when thread isn't loaded\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n // Track the internal StreamState from the real reducer so we can assert we\n // don't create a local thread entry for threads that haven't been loaded.\n const stateRef: React.MutableRefObject<StreamState | undefined> = {\n current: undefined,\n };\n const initialState: StreamState = {\n threadMap: {},\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState, stateRef),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_789\", \"New Title\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_789\", {\n name: \"New Title\",\n userKey: undefined,\n });\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_789\"]);\n\n expect(stateRef.current?.threadMap.thread_789).toBeUndefined();\n\n act(() => {\n result.current.switchThread(\"thread_789\");\n });\n\n expect(result.current.thread).toBeUndefined();\n });\n\n it(\"propagates errors and does not update local state\", async () => {\n const mockUpdate = jest\n .fn()\n .mockRejectedValue(new Error(\"Network error\"));\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n let caughtError: unknown;\n await act(async () => {\n try {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n } catch (error) {\n caughtError = error;\n }\n });\n\n expect(caughtError).toBeInstanceOf(Error);\n expect((caughtError as Error).message).toBe(\"Network error\");\n expect(result.current.thread?.thread.name).toBe(\"Old Name\");\n expect(invalidateQueriesSpy).not.toHaveBeenCalled();\n });\n });\n});\n"]}
|
|
@@ -72,7 +72,7 @@ export function useTambo() {
|
|
|
72
72
|
]);
|
|
73
73
|
// Update a thread's name
|
|
74
74
|
const updateThreadName = useCallback(async (threadId, name) => {
|
|
75
|
-
await client.threads.update(threadId, { name });
|
|
75
|
+
await client.threads.update(threadId, { name, userKey });
|
|
76
76
|
if (threadMapRef.current[threadId]) {
|
|
77
77
|
dispatch({
|
|
78
78
|
type: "UPDATE_THREAD_NAME",
|
|
@@ -93,7 +93,7 @@ export function useTambo() {
|
|
|
93
93
|
catch (error) {
|
|
94
94
|
console.warn("[useTambo] Failed to invalidate thread queries after rename:", error);
|
|
95
95
|
}
|
|
96
|
-
}, [client, dispatch, queryClient]);
|
|
96
|
+
}, [client, userKey, dispatch, queryClient]);
|
|
97
97
|
// Memoize the return object to prevent unnecessary re-renders
|
|
98
98
|
return useMemo(() => {
|
|
99
99
|
const thread = threadState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,KAAK,EAAE,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,MAAM,GAEP,MAAM,OAAO,CAAC;AACf,OAAO,EACL,cAAc,EACd,mBAAmB,GACpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EACL,oBAAoB,GAErB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,GAEpB,MAAM,sCAAsC,CAAC;AAQ9C,OAAO,EACL,qBAAqB,GAEtB,MAAM,4BAA4B,CAAC;AA+JpC;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC;IAC1C,MAAM,EAAE,OAAO,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QACN,WAAW;QACX,QAAQ;QACR,WAAW,CAAC,eAAe;QAC3B,gBAAgB;QAChB,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * useTambo - Main Hook\n *\n * Combines all contexts into a single hook for convenient access\n * to thread state, streaming status, registry, and client.\n */\n\nimport { EventType } from \"@ag-ui/core\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n useCallback,\n useContext,\n useMemo,\n useRef,\n type ReactElement,\n} from \"react\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboConfig } from \"../providers/tambo-v1-provider\";\nimport { useTamboAuthState } from \"./use-tambo-v1-auth-state\";\nimport type { TamboAuthState } from \"../types/auth\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { ComponentRenderer } from \"../components/v1-component-renderer\";\nimport {\n useStreamDispatch,\n useStreamState,\n useThreadManagement,\n type ThreadManagement,\n} from \"../providers/tambo-v1-stream-context\";\nimport type {\n Content,\n TamboToolDisplayProps,\n TamboThreadMessage,\n TamboToolUseContent,\n} from \"../types/message\";\nimport type { StreamingState } from \"../types/thread\";\nimport {\n isPlaceholderThreadId,\n type ThreadState,\n} from \"../utils/event-accumulator\";\n\n/**\n * Return type for useTambo hook\n */\nexport interface UseTamboReturn {\n /**\n * The Tambo API client instance\n */\n client: TamboAI;\n\n /**\n * Current thread state for the given threadId, or undefined if not loaded\n */\n thread: ThreadState | undefined;\n\n /**\n * Messages in the current thread\n */\n messages: TamboThreadMessage[];\n\n /**\n * Current streaming state\n */\n streamingState: StreamingState;\n\n /**\n * Whether the thread is currently streaming a response\n */\n isStreaming: boolean;\n\n /**\n * Whether the thread is waiting for the AI to start responding\n */\n isWaiting: boolean;\n\n /**\n * Whether the thread is idle (not streaming or waiting)\n */\n isIdle: boolean;\n\n /**\n * Register a component with the registry\n */\n registerComponent: TamboRegistryContextType[\"registerComponent\"];\n\n /**\n * Register a tool with the registry\n */\n registerTool: TamboRegistryContextType[\"registerTool\"];\n\n /**\n * Register multiple tools with the registry\n */\n registerTools: TamboRegistryContextType[\"registerTools\"];\n\n /**\n * The component registry (Map of name -> component definition)\n */\n componentList: TamboRegistryContextType[\"componentList\"];\n\n /**\n * The tool registry (Map of name -> tool definition)\n */\n toolRegistry: TamboRegistryContextType[\"toolRegistry\"];\n\n /**\n * Current thread ID (always available - uses \"placeholder\" for new threads)\n */\n currentThreadId: string;\n\n /**\n * Initialize a new thread in the stream context\n */\n initThread: ThreadManagement[\"initThread\"];\n\n /**\n * Switch the current active thread\n */\n switchThread: ThreadManagement[\"switchThread\"];\n\n /**\n * Start a new thread (generates a temporary ID)\n */\n startNewThread: ThreadManagement[\"startNewThread\"];\n\n /**\n * Dispatch function for stream events (advanced usage)\n */\n dispatch: ReturnType<typeof useStreamDispatch>;\n\n /**\n * Cancel the current run on this thread.\n * Optimistically updates local state and sends cancellation request to the API.\n * No-op if there's no active run or thread is a placeholder.\n */\n cancelRun: () => Promise<void>;\n\n /**\n * Current authentication state.\n * Use this to show auth-related UI or conditionally render features.\n */\n authState: TamboAuthState;\n\n /**\n * Shorthand for `authState.status === \"identified\"`.\n * When true, the SDK is ready to make API calls.\n */\n isIdentified: boolean;\n\n /**\n * Update a thread's name.\n * Useful for implementing manual thread renaming UI in history sidebars.\n * Cache invalidation is best-effort; failures will be logged and won't reject.\n * @param threadId - ID of the thread to rename\n * @param name - New name for the thread\n * @returns Promise that resolves when the update completes\n */\n updateThreadName: (threadId: string, name: string) => Promise<void>;\n}\n\n/**\n * Main hook for accessing Tambo functionality.\n *\n * Combines thread state, streaming status, registry, and client\n * into a single convenient hook.\n *\n * Messages returned include renderedComponent on component content blocks,\n * allowing direct rendering via {content.renderedComponent}.\n * @param threadId - Optional thread ID to get state for\n * @returns Combined context with thread state, messages, and utilities\n * @example\n * ```tsx\n * function ChatInterface() {\n * const {\n * thread,\n * messages,\n * isStreaming,\n * registerComponent,\n * } = useTambo('thread_123');\n *\n * return (\n * <div>\n * {messages.map(msg => <Message key={msg.id} message={msg} />)}\n * {isStreaming && <LoadingIndicator />}\n * </div>\n * );\n * }\n * ```\n */\n/**\n * Cache entry for a rendered component wrapper.\n * Stores the element and the props JSON used to create it.\n */\ninterface ComponentCacheEntry {\n element: ReactElement;\n propsJson: string;\n}\n\n/**\n *\n * @returns The combined Tambo context\n */\nexport function useTambo(): UseTamboReturn {\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const { userKey } = useTamboConfig();\n const streamState = useStreamState();\n const dispatch = useStreamDispatch();\n const registry = useContext(TamboRegistryContext);\n const threadManagement = useThreadManagement();\n const authState = useTamboAuthState();\n\n // Cache for rendered component wrappers - maintains stable element references\n // across renders when props haven't changed\n const componentCacheRef = useRef<Map<string, ComponentCacheEntry>>(new Map());\n\n // Get thread state for the current thread\n const threadState = streamState.threadMap[streamState.currentThreadId];\n\n // Keep a live snapshot of the threadMap for callbacks without forcing them to\n // re-create on every stream state update.\n const threadMapRef = useRef(streamState.threadMap);\n threadMapRef.current = streamState.threadMap;\n\n // Cancel the current run on this thread\n const cancelRun = useCallback(async () => {\n const runId = threadState?.streaming.runId;\n const threadId = streamState.currentThreadId;\n\n // No-op if there's no active run or thread is a placeholder\n if (!runId || isPlaceholderThreadId(threadId)) {\n return;\n }\n\n // Optimistically update local state with RUN_ERROR event\n dispatch({\n type: \"EVENT\",\n threadId,\n event: {\n type: EventType.RUN_ERROR,\n message: \"Run cancelled\",\n code: \"CANCELLED\",\n timestamp: Date.now(),\n },\n });\n\n // Call API to cancel the run\n try {\n await client.threads.runs.delete(runId, { threadId, userKey });\n } catch (error) {\n // Log but don't rethrow - local state is already updated\n console.warn(\"Failed to cancel run on server:\", error);\n }\n }, [\n client,\n userKey,\n streamState.currentThreadId,\n threadState?.streaming.runId,\n dispatch,\n ]);\n\n // Update a thread's name\n const updateThreadName = useCallback(\n async (threadId: string, name: string) => {\n await client.threads.update(threadId, { name });\n\n if (threadMapRef.current[threadId]) {\n dispatch({\n type: \"UPDATE_THREAD_NAME\",\n threadId,\n name: name,\n });\n }\n\n try {\n await Promise.all([\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n }),\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", threadId],\n }),\n ]);\n } catch (error) {\n console.warn(\n \"[useTambo] Failed to invalidate thread queries after rename:\",\n error,\n );\n }\n },\n [client, dispatch, queryClient],\n );\n\n // Memoize the return object to prevent unnecessary re-renders\n return useMemo(() => {\n const thread = threadState;\n const rawMessages = thread?.thread.messages ?? [];\n const streamingState: StreamingState = thread?.streaming ?? {\n status: \"idle\" as const,\n };\n\n // Build a set of tool_use IDs that have completed (have a matching tool_result)\n // We need to look across all messages since tool_result might be in a different message\n const completedToolIds = new Set<string>();\n for (const msg of rawMessages) {\n for (const content of msg.content) {\n if (content.type === \"tool_result\") {\n completedToolIds.add(content.toolUseId);\n }\n }\n }\n\n // Transform messages to add computed properties to content blocks\n const messages = rawMessages.map((message): TamboThreadMessage => {\n const transformedContent = message.content.map((content): Content => {\n // Transform tool_use content to add computed state\n if (content.type === \"tool_use\") {\n const hasCompleted = completedToolIds.has(content.id);\n const input = content.input ?? {};\n\n // Extract Tambo display props from input\n const tamboDisplayProps: TamboToolDisplayProps = {\n _tambo_statusMessage:\n typeof input._tambo_statusMessage === \"string\"\n ? input._tambo_statusMessage\n : undefined,\n _tambo_completionStatusMessage:\n typeof input._tambo_completionStatusMessage === \"string\"\n ? input._tambo_completionStatusMessage\n : undefined,\n };\n\n // Compute status message based on completion state\n const statusMessage = hasCompleted\n ? (tamboDisplayProps._tambo_completionStatusMessage ??\n `Called ${content.name}`)\n : (tamboDisplayProps._tambo_statusMessage ??\n `Calling ${content.name}`);\n\n // Filter out _tambo_* properties from input - consumers only see actual tool params\n const cleanInput: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(input)) {\n if (!key.startsWith(\"_tambo_\")) {\n cleanInput[key] = value;\n }\n }\n\n const v1Content: TamboToolUseContent = {\n ...content,\n input: cleanInput,\n hasCompleted,\n statusMessage,\n tamboDisplayProps,\n };\n return v1Content;\n }\n\n if (content.type !== \"component\") {\n return content;\n }\n\n const componentContent = content;\n const propsJson = JSON.stringify(componentContent.props ?? {});\n const cache = componentCacheRef.current;\n const cached = cache.get(componentContent.id);\n\n // Return cached element if props haven't changed\n if (cached?.propsJson === propsJson) {\n return {\n ...componentContent,\n renderedComponent: cached.element,\n };\n }\n\n // Create new wrapper element\n const element = React.createElement(ComponentRenderer, {\n key: componentContent.id,\n content: componentContent,\n threadId: streamState.currentThreadId,\n messageId: message.id,\n });\n\n // Update cache\n cache.set(componentContent.id, { element, propsJson });\n\n return {\n ...componentContent,\n renderedComponent: element,\n };\n });\n\n return {\n ...message,\n content: transformedContent,\n };\n });\n\n return {\n client,\n thread,\n messages,\n streamingState,\n isStreaming: streamingState.status === \"streaming\",\n isWaiting: streamingState.status === \"waiting\",\n isIdle: streamingState.status === \"idle\",\n registerComponent: registry.registerComponent,\n registerTool: registry.registerTool,\n registerTools: registry.registerTools,\n componentList: registry.componentList,\n toolRegistry: registry.toolRegistry,\n currentThreadId: streamState.currentThreadId,\n initThread: threadManagement.initThread,\n switchThread: threadManagement.switchThread,\n startNewThread: threadManagement.startNewThread,\n dispatch,\n cancelRun,\n authState,\n isIdentified: authState.status === \"identified\",\n updateThreadName,\n };\n }, [\n cancelRun,\n updateThreadName,\n client,\n threadState,\n registry,\n streamState.currentThreadId,\n threadManagement,\n dispatch,\n authState,\n ]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,KAAK,EAAE,EACZ,WAAW,EACX,UAAU,EAC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AAM,KAAK,WAAW;YAClD,SAAS,EAAE,cAAc,CAAC,MAAM,KAAK,SAAS;YAC9C,MAAM,EAAE,cAAc,CAAC,MAAM,KAAK,MAAM;YACxC,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;YAC7C,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,aAAa,EAAE,QAAQ,CAAC,aAAa;YACrC,aAAa,EAAE,QAAQ,CAAC,aAAa;YACrC,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,eAAe,EAAE,WAAW,CAAC,eAAe;YAC5C,UAAU,EAAE,gBAAgB,CAAC,UAAU;YACvC,YAAY,EAAE,gBAAgB,CAAC,YAAY;YAC3C,cAAc,EAAE,gBAAgB,CAAC,cAAc;YAC/C,QAAQ;YACR,SAAS;YACT,SAAS;YACT,YAAY,EAAE,SAAS,CAAC,MAAM,KAAK,YAAY;YAC/C,gBAAgB;SACjB,CAAC;IACJ,CAAC,EAAE;QACD,SAAS;QACT,gBAAgB;QAChB,MAAM;QACN,WAAW;QACX,QAAQ;QACR,WAAW,CAAC,eAAe;QAC3B,gBAAgB;QAChB,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;AACL,CAAC","sourcesContent":["\"use client\";\n\n/**\n * useTambo - Main Hook\n *\n * Combines all contexts into a single hook for convenient access\n * to thread state, streaming status, registry, and client.\n */\n\nimport { EventType } from \"@ag-ui/core\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n useCallback,\n useContext,\n useMemo,\n useRef,\n type ReactElement,\n} from \"react\";\nimport {\n useTamboClient,\n useTamboQueryClient,\n} from \"../../providers/tambo-client-provider\";\nimport { useTamboConfig } from \"../providers/tambo-v1-provider\";\nimport { useTamboAuthState } from \"./use-tambo-v1-auth-state\";\nimport type { TamboAuthState } from \"../types/auth\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { ComponentRenderer } from \"../components/v1-component-renderer\";\nimport {\n useStreamDispatch,\n useStreamState,\n useThreadManagement,\n type ThreadManagement,\n} from \"../providers/tambo-v1-stream-context\";\nimport type {\n Content,\n TamboToolDisplayProps,\n TamboThreadMessage,\n TamboToolUseContent,\n} from \"../types/message\";\nimport type { StreamingState } from \"../types/thread\";\nimport {\n isPlaceholderThreadId,\n type ThreadState,\n} from \"../utils/event-accumulator\";\n\n/**\n * Return type for useTambo hook\n */\nexport interface UseTamboReturn {\n /**\n * The Tambo API client instance\n */\n client: TamboAI;\n\n /**\n * Current thread state for the given threadId, or undefined if not loaded\n */\n thread: ThreadState | undefined;\n\n /**\n * Messages in the current thread\n */\n messages: TamboThreadMessage[];\n\n /**\n * Current streaming state\n */\n streamingState: StreamingState;\n\n /**\n * Whether the thread is currently streaming a response\n */\n isStreaming: boolean;\n\n /**\n * Whether the thread is waiting for the AI to start responding\n */\n isWaiting: boolean;\n\n /**\n * Whether the thread is idle (not streaming or waiting)\n */\n isIdle: boolean;\n\n /**\n * Register a component with the registry\n */\n registerComponent: TamboRegistryContextType[\"registerComponent\"];\n\n /**\n * Register a tool with the registry\n */\n registerTool: TamboRegistryContextType[\"registerTool\"];\n\n /**\n * Register multiple tools with the registry\n */\n registerTools: TamboRegistryContextType[\"registerTools\"];\n\n /**\n * The component registry (Map of name -> component definition)\n */\n componentList: TamboRegistryContextType[\"componentList\"];\n\n /**\n * The tool registry (Map of name -> tool definition)\n */\n toolRegistry: TamboRegistryContextType[\"toolRegistry\"];\n\n /**\n * Current thread ID (always available - uses \"placeholder\" for new threads)\n */\n currentThreadId: string;\n\n /**\n * Initialize a new thread in the stream context\n */\n initThread: ThreadManagement[\"initThread\"];\n\n /**\n * Switch the current active thread\n */\n switchThread: ThreadManagement[\"switchThread\"];\n\n /**\n * Start a new thread (generates a temporary ID)\n */\n startNewThread: ThreadManagement[\"startNewThread\"];\n\n /**\n * Dispatch function for stream events (advanced usage)\n */\n dispatch: ReturnType<typeof useStreamDispatch>;\n\n /**\n * Cancel the current run on this thread.\n * Optimistically updates local state and sends cancellation request to the API.\n * No-op if there's no active run or thread is a placeholder.\n */\n cancelRun: () => Promise<void>;\n\n /**\n * Current authentication state.\n * Use this to show auth-related UI or conditionally render features.\n */\n authState: TamboAuthState;\n\n /**\n * Shorthand for `authState.status === \"identified\"`.\n * When true, the SDK is ready to make API calls.\n */\n isIdentified: boolean;\n\n /**\n * Update a thread's name.\n * Useful for implementing manual thread renaming UI in history sidebars.\n * Cache invalidation is best-effort; failures will be logged and won't reject.\n * @param threadId - ID of the thread to rename\n * @param name - New name for the thread\n * @returns Promise that resolves when the update completes\n */\n updateThreadName: (threadId: string, name: string) => Promise<void>;\n}\n\n/**\n * Main hook for accessing Tambo functionality.\n *\n * Combines thread state, streaming status, registry, and client\n * into a single convenient hook.\n *\n * Messages returned include renderedComponent on component content blocks,\n * allowing direct rendering via {content.renderedComponent}.\n * @param threadId - Optional thread ID to get state for\n * @returns Combined context with thread state, messages, and utilities\n * @example\n * ```tsx\n * function ChatInterface() {\n * const {\n * thread,\n * messages,\n * isStreaming,\n * registerComponent,\n * } = useTambo('thread_123');\n *\n * return (\n * <div>\n * {messages.map(msg => <Message key={msg.id} message={msg} />)}\n * {isStreaming && <LoadingIndicator />}\n * </div>\n * );\n * }\n * ```\n */\n/**\n * Cache entry for a rendered component wrapper.\n * Stores the element and the props JSON used to create it.\n */\ninterface ComponentCacheEntry {\n element: ReactElement;\n propsJson: string;\n}\n\n/**\n *\n * @returns The combined Tambo context\n */\nexport function useTambo(): UseTamboReturn {\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const { userKey } = useTamboConfig();\n const streamState = useStreamState();\n const dispatch = useStreamDispatch();\n const registry = useContext(TamboRegistryContext);\n const threadManagement = useThreadManagement();\n const authState = useTamboAuthState();\n\n // Cache for rendered component wrappers - maintains stable element references\n // across renders when props haven't changed\n const componentCacheRef = useRef<Map<string, ComponentCacheEntry>>(new Map());\n\n // Get thread state for the current thread\n const threadState = streamState.threadMap[streamState.currentThreadId];\n\n // Keep a live snapshot of the threadMap for callbacks without forcing them to\n // re-create on every stream state update.\n const threadMapRef = useRef(streamState.threadMap);\n threadMapRef.current = streamState.threadMap;\n\n // Cancel the current run on this thread\n const cancelRun = useCallback(async () => {\n const runId = threadState?.streaming.runId;\n const threadId = streamState.currentThreadId;\n\n // No-op if there's no active run or thread is a placeholder\n if (!runId || isPlaceholderThreadId(threadId)) {\n return;\n }\n\n // Optimistically update local state with RUN_ERROR event\n dispatch({\n type: \"EVENT\",\n threadId,\n event: {\n type: EventType.RUN_ERROR,\n message: \"Run cancelled\",\n code: \"CANCELLED\",\n timestamp: Date.now(),\n },\n });\n\n // Call API to cancel the run\n try {\n await client.threads.runs.delete(runId, { threadId, userKey });\n } catch (error) {\n // Log but don't rethrow - local state is already updated\n console.warn(\"Failed to cancel run on server:\", error);\n }\n }, [\n client,\n userKey,\n streamState.currentThreadId,\n threadState?.streaming.runId,\n dispatch,\n ]);\n\n // Update a thread's name\n const updateThreadName = useCallback(\n async (threadId: string, name: string) => {\n await client.threads.update(threadId, { name, userKey });\n\n if (threadMapRef.current[threadId]) {\n dispatch({\n type: \"UPDATE_THREAD_NAME\",\n threadId,\n name: name,\n });\n }\n\n try {\n await Promise.all([\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", \"list\"],\n }),\n queryClient.invalidateQueries({\n queryKey: [\"v1-threads\", threadId],\n }),\n ]);\n } catch (error) {\n console.warn(\n \"[useTambo] Failed to invalidate thread queries after rename:\",\n error,\n );\n }\n },\n [client, userKey, dispatch, queryClient],\n );\n\n // Memoize the return object to prevent unnecessary re-renders\n return useMemo(() => {\n const thread = threadState;\n const rawMessages = thread?.thread.messages ?? [];\n const streamingState: StreamingState = thread?.streaming ?? {\n status: \"idle\" as const,\n };\n\n // Build a set of tool_use IDs that have completed (have a matching tool_result)\n // We need to look across all messages since tool_result might be in a different message\n const completedToolIds = new Set<string>();\n for (const msg of rawMessages) {\n for (const content of msg.content) {\n if (content.type === \"tool_result\") {\n completedToolIds.add(content.toolUseId);\n }\n }\n }\n\n // Transform messages to add computed properties to content blocks\n const messages = rawMessages.map((message): TamboThreadMessage => {\n const transformedContent = message.content.map((content): Content => {\n // Transform tool_use content to add computed state\n if (content.type === \"tool_use\") {\n const hasCompleted = completedToolIds.has(content.id);\n const input = content.input ?? {};\n\n // Extract Tambo display props from input\n const tamboDisplayProps: TamboToolDisplayProps = {\n _tambo_statusMessage:\n typeof input._tambo_statusMessage === \"string\"\n ? input._tambo_statusMessage\n : undefined,\n _tambo_completionStatusMessage:\n typeof input._tambo_completionStatusMessage === \"string\"\n ? input._tambo_completionStatusMessage\n : undefined,\n };\n\n // Compute status message based on completion state\n const statusMessage = hasCompleted\n ? (tamboDisplayProps._tambo_completionStatusMessage ??\n `Called ${content.name}`)\n : (tamboDisplayProps._tambo_statusMessage ??\n `Calling ${content.name}`);\n\n // Filter out _tambo_* properties from input - consumers only see actual tool params\n const cleanInput: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(input)) {\n if (!key.startsWith(\"_tambo_\")) {\n cleanInput[key] = value;\n }\n }\n\n const v1Content: TamboToolUseContent = {\n ...content,\n input: cleanInput,\n hasCompleted,\n statusMessage,\n tamboDisplayProps,\n };\n return v1Content;\n }\n\n if (content.type !== \"component\") {\n return content;\n }\n\n const componentContent = content;\n const propsJson = JSON.stringify(componentContent.props ?? {});\n const cache = componentCacheRef.current;\n const cached = cache.get(componentContent.id);\n\n // Return cached element if props haven't changed\n if (cached?.propsJson === propsJson) {\n return {\n ...componentContent,\n renderedComponent: cached.element,\n };\n }\n\n // Create new wrapper element\n const element = React.createElement(ComponentRenderer, {\n key: componentContent.id,\n content: componentContent,\n threadId: streamState.currentThreadId,\n messageId: message.id,\n });\n\n // Update cache\n cache.set(componentContent.id, { element, propsJson });\n\n return {\n ...componentContent,\n renderedComponent: element,\n };\n });\n\n return {\n ...message,\n content: transformedContent,\n };\n });\n\n return {\n client,\n thread,\n messages,\n streamingState,\n isStreaming: streamingState.status === \"streaming\",\n isWaiting: streamingState.status === \"waiting\",\n isIdle: streamingState.status === \"idle\",\n registerComponent: registry.registerComponent,\n registerTool: registry.registerTool,\n registerTools: registry.registerTools,\n componentList: registry.componentList,\n toolRegistry: registry.toolRegistry,\n currentThreadId: streamState.currentThreadId,\n initThread: threadManagement.initThread,\n switchThread: threadManagement.switchThread,\n startNewThread: threadManagement.startNewThread,\n dispatch,\n cancelRun,\n authState,\n isIdentified: authState.status === \"identified\",\n updateThreadName,\n };\n }, [\n cancelRun,\n updateThreadName,\n client,\n threadState,\n registry,\n streamState.currentThreadId,\n threadManagement,\n dispatch,\n authState,\n ]);\n}\n"]}
|
|
@@ -1049,6 +1049,7 @@ describe("useTambo", () => {
|
|
|
1049
1049
|
});
|
|
1050
1050
|
expect(mockUpdate).toHaveBeenCalledWith("thread_456", {
|
|
1051
1051
|
name: "My New Thread",
|
|
1052
|
+
userKey: undefined,
|
|
1052
1053
|
});
|
|
1053
1054
|
expect(result.current.thread?.thread.name).toBe("My New Thread");
|
|
1054
1055
|
const invalidatedKeys = invalidateQueriesSpy.mock.calls
|
|
@@ -1079,6 +1080,7 @@ describe("useTambo", () => {
|
|
|
1079
1080
|
});
|
|
1080
1081
|
expect(mockUpdate).toHaveBeenCalledWith("thread_789", {
|
|
1081
1082
|
name: "New Title",
|
|
1083
|
+
userKey: undefined,
|
|
1082
1084
|
});
|
|
1083
1085
|
const invalidatedKeys = invalidateQueriesSpy.mock.calls
|
|
1084
1086
|
.map(([arg]) => arg.queryKey)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-v1.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,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EAAE,MAAM,EAAE;wBAC7B,oBAAoB,EAAE,IAAI,GAAG,EAAE;qBAChC;iBACF;gBACD,eAAe,EAAE,YAAY;aAC9B,CAAC;YAEF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE;gBAC9C,OAAO,EAAE,4BAA4B,CAAC,YAAY,CAAC;aACpD,CAAC,CAAC;YAEH,IAAI,WAAoB,CAAC;YACzB,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;gBACnB,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;gBACvE,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,WAAW,GAAG,KAAK,CAAC;gBACtB,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC1C,MAAM,CAAE,WAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC7D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5D,MAAM,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { renderHook, act } from \"@testing-library/react\";\nimport React, { useReducer } from \"react\";\nimport { useTamboClient } from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { TamboStreamProvider } from \"../providers/tambo-v1-stream-context\";\nimport {\n streamReducer,\n type StreamState,\n type StreamAction,\n} from \"../utils/event-accumulator\";\nimport type {\n TamboComponentContent,\n TamboToolUseContent,\n} from \"../types/message\";\nimport { useTambo } from \"./use-tambo-v1\";\n\njest.mock(\"../../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n useTamboQueryClient: jest.fn(),\n}));\n\njest.mock(\"../providers/tambo-v1-provider\", () => {\n const actual = jest.requireActual(\"../providers/tambo-v1-provider\");\n return {\n ...actual,\n useTamboConfig: () => ({ userKey: undefined }),\n };\n});\n\njest.mock(\"./use-tambo-v1-auth-state\", () => ({\n useTamboAuthState: () => ({\n status: \"identified\",\n source: \"userKey\",\n }),\n}));\n\nimport { useTamboQueryClient } from \"../../providers/tambo-client-provider\";\n\ndescribe(\"useTambo\", () => {\n let queryClient: QueryClient;\n\n const mockTamboClient = {\n apiKey: \"\",\n threads: {\n messages: {\n list: jest.fn().mockResolvedValue({ messages: [], hasMore: false }),\n },\n runs: {\n delete: jest.fn().mockResolvedValue({}),\n },\n },\n } as unknown as TamboAI;\n\n const mockRegistry: TamboRegistryContextType = {\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n registerComponent: jest.fn(),\n registerTool: jest.fn(),\n registerTools: jest.fn(),\n addToolAssociation: jest.fn(),\n registerMcpServer: jest.fn(),\n registerMcpServers: jest.fn(),\n registerResource: jest.fn(),\n registerResources: jest.fn(),\n registerResourceSource: jest.fn(),\n };\n\n function TestWrapper({ children }: { children: React.ReactNode }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider>{children}</TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n }\n\n function createWrapperWithState(\n state: StreamState,\n registry: TamboRegistryContextType = mockRegistry,\n ) {\n const noopDispatch: React.Dispatch<StreamAction> = () => {};\n return function WrapperWithState({\n children,\n }: {\n children: React.ReactNode;\n }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={registry}>\n <TamboStreamProvider state={state} dispatch={noopDispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n // Wrapper that uses the real reducer so state updates properly\n function createWrapperWithRealReducer(\n initialState: StreamState,\n stateRef?: React.MutableRefObject<StreamState | undefined>,\n ) {\n return function WrapperWithRealReducer({\n children,\n }: {\n children: React.ReactNode;\n }) {\n const [state, dispatch] = useReducer(streamReducer, initialState);\n if (stateRef) {\n stateRef.current = state;\n }\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider state={state} dispatch={dispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n beforeEach(() => {\n queryClient = new QueryClient({\n defaultOptions: {\n queries: { retry: false },\n },\n });\n jest.mocked(useTamboClient).mockReturnValue(mockTamboClient);\n jest.mocked(useTamboQueryClient).mockReturnValue(queryClient);\n jest.clearAllMocks();\n delete (mockTamboClient.threads as any).update;\n });\n\n it(\"returns client from useTamboClient\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.client).toBe(mockTamboClient);\n });\n\n it(\"returns registry functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.registerComponent).toBe(\n mockRegistry.registerComponent,\n );\n expect(result.current.registerTool).toBe(mockRegistry.registerTool);\n expect(result.current.registerTools).toBe(mockRegistry.registerTools);\n expect(result.current.componentList).toBe(mockRegistry.componentList);\n expect(result.current.toolRegistry).toBe(mockRegistry.toolRegistry);\n });\n\n it(\"returns placeholder thread when no threadId provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Default state has placeholder thread for optimistic UI\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns thread state when switched to a thread\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns default streaming state when thread not loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.streamingState).toEqual({ status: \"idle\" });\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"returns thread streaming state when thread loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.streamingState.status).toBe(\"idle\");\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"provides dispatch function for advanced usage\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.dispatch).toBe(\"function\");\n });\n\n it(\"provides thread management functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.initThread).toBe(\"function\");\n expect(typeof result.current.switchThread).toBe(\"function\");\n expect(typeof result.current.startNewThread).toBe(\"function\");\n });\n\n it(\"initializes and switches threads\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initially has placeholder thread for optimistic UI\n expect(result.current.currentThreadId).toBe(\"placeholder\");\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n\n // Initialize a new thread\n act(() => {\n result.current.initThread(\"new_thread_1\");\n });\n\n // Switch to the new thread\n act(() => {\n result.current.switchThread(\"new_thread_1\");\n });\n\n expect(result.current.currentThreadId).toBe(\"new_thread_1\");\n });\n\n it(\"starts new thread with generated ID\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n let newThreadId: string;\n act(() => {\n newThreadId = result.current.startNewThread();\n });\n\n expect(newThreadId!).toBe(\"placeholder\");\n expect(result.current.currentThreadId).toBe(newThreadId!);\n expect(result.current.thread).toBeDefined();\n });\n\n it(\"uses current thread when no threadId argument provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to a thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n // Should use current thread from context (thread_123)\n expect(result.current.currentThreadId).toBe(\"thread_123\");\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n });\n\n describe(\"component content transformation\", () => {\n const createComponentContent = (\n id: string,\n name: string,\n props: Record<string, unknown>,\n ): TamboComponentContent => ({\n type: \"component\",\n id,\n name,\n props,\n streamingState: \"done\",\n });\n\n it(\"adds renderedComponent to component content blocks\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"preserves non-component content blocks unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n { type: \"text\", text: \"Hello world\" },\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hi\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const textContent = result.current.messages[0].content[0];\n expect(textContent.type).toBe(\"text\");\n expect(textContent).toEqual({ type: \"text\", text: \"Hello world\" });\n\n const componentContent = result.current.messages[0].content[1];\n expect(componentContent.type).toBe(\"component\");\n expect(\n (componentContent as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"caches rendered components and returns same reference when props unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result, rerender } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const firstRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Re-render with same state\n rerender();\n\n const secondRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Should return the same cached element reference\n expect(secondRender).toBe(firstRender);\n });\n\n it(\"handles empty props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {}),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles undefined props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: undefined,\n streamingState: \"done\",\n } as TamboComponentContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles multiple component content blocks in same message\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"ComponentA\", {\n value: 1,\n }),\n createComponentContent(\"comp_2\", \"ComponentB\", {\n value: 2,\n }),\n createComponentContent(\"comp_3\", \"ComponentC\", {\n value: 3,\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages[0].content).toHaveLength(3);\n result.current.messages[0].content.forEach((content) => {\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n it(\"uses currentThreadId from stream state\", () => {\n const state: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n // No explicit threadId - uses currentThreadId from state\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n // Component should render using the placeholder thread\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n describe(\"tool_use content transformation\", () => {\n it(\"adds computed properties to tool_use content\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.type).toBe(\"tool_use\");\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getWeather\");\n expect(content.tamboDisplayProps).toBeDefined();\n });\n\n it(\"sets hasCompleted to true when matching tool_result exists\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Called getWeather\");\n });\n\n it(\"uses _tambo_statusMessage when tool is in progress\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather for NYC...\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.statusMessage).toBe(\"Fetching weather for NYC...\");\n expect(content.tamboDisplayProps?._tambo_statusMessage).toBe(\n \"Fetching weather for NYC...\",\n );\n });\n\n it(\"uses _tambo_completionStatusMessage when tool is completed\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather...\",\n _tambo_completionStatusMessage: \"Got weather for NYC\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Got weather for NYC\");\n });\n\n it(\"filters _tambo_* properties from input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n units: \"celsius\",\n _tambo_statusMessage: \"Fetching...\",\n _tambo_completionStatusMessage: \"Done\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n // Input should only have non-_tambo_ properties\n expect(content.input).toEqual({ location: \"NYC\", units: \"celsius\" });\n expect(content.input._tambo_statusMessage).toBeUndefined();\n expect(content.input._tambo_completionStatusMessage).toBeUndefined();\n });\n\n it(\"handles tool_use with empty input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: {},\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getCurrentTime\");\n });\n\n it(\"handles tool_use with undefined input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: undefined,\n } as unknown as TamboToolUseContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n });\n\n it(\"handles multiple tool_use blocks with different completion states\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n {\n type: \"tool_use\",\n id: \"tool_2\",\n name: \"getTime\",\n input: { timezone: \"EST\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n // tool_2 has no result yet\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const tool1 = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n const tool2 = result.current.messages[0]\n .content[1] as TamboToolUseContent;\n\n expect(tool1.hasCompleted).toBe(true);\n expect(tool1.statusMessage).toBe(\"Called getWeather\");\n\n expect(tool2.hasCompleted).toBe(false);\n expect(tool2.statusMessage).toBe(\"Calling getTime\");\n });\n });\n\n describe(\"cancelRun\", () => {\n it(\"sets thread to idle and lastRunCancelled to true when cancelled\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before cancel: streaming and lastRunCancelled is false\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.isIdle).toBe(false);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After cancel: idle and lastRunCancelled is true\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Verify API was called to cancel the run\n expect(mockTamboClient.threads.runs.delete).toHaveBeenCalledWith(\n \"run_456\",\n { threadId: \"thread_123\" },\n );\n });\n\n it(\"is a no-op when there is no active run\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" }, // No runId\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Idle before\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Still idle, lastRunCancelled unchanged\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"is a no-op when on a placeholder thread\", async () => {\n const initialState: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_123\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before: streaming on placeholder\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After: state should be unchanged (placeholder threads are skipped)\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called for placeholder threads\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"still updates local state even if API call fails\", async () => {\n const consoleWarnSpy = jest\n .spyOn(console, \"warn\")\n .mockImplementation(() => {});\n\n // Make the API call fail\n jest\n .mocked(mockTamboClient.threads.runs.delete)\n .mockRejectedValueOnce(new Error(\"Network error\"));\n\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Local state should still be updated (optimistic update)\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Warning should have been logged\n expect(consoleWarnSpy).toHaveBeenCalledWith(\n \"Failed to cancel run on server:\",\n expect.any(Error),\n );\n\n consoleWarnSpy.mockRestore();\n });\n });\n\n describe(\"updateThreadName\", () => {\n it(\"updates local thread name and invalidates caches on success\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_456\", {\n name: \"My New Thread\",\n });\n\n expect(result.current.thread?.thread.name).toBe(\"My New Thread\");\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_456\"]);\n });\n\n it(\"does not create local thread state when thread isn't loaded\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n // Track the internal StreamState from the real reducer so we can assert we\n // don't create a local thread entry for threads that haven't been loaded.\n const stateRef: React.MutableRefObject<StreamState | undefined> = {\n current: undefined,\n };\n const initialState: StreamState = {\n threadMap: {},\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState, stateRef),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_789\", \"New Title\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_789\", {\n name: \"New Title\",\n });\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_789\"]);\n\n expect(stateRef.current?.threadMap.thread_789).toBeUndefined();\n\n act(() => {\n result.current.switchThread(\"thread_789\");\n });\n\n expect(result.current.thread).toBeUndefined();\n });\n\n it(\"propagates errors and does not update local state\", async () => {\n const mockUpdate = jest\n .fn()\n .mockRejectedValue(new Error(\"Network error\"));\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n let caughtError: unknown;\n await act(async () => {\n try {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n } catch (error) {\n caughtError = error;\n }\n });\n\n expect(caughtError).toBeInstanceOf(Error);\n expect((caughtError as Error).message).toBe(\"Network error\");\n expect(result.current.thread?.thread.name).toBe(\"Old Name\");\n expect(invalidateQueriesSpy).not.toHaveBeenCalled();\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-v1.test.js","sourceRoot":"","sources":["../../../src/v1/hooks/use-tambo-v1.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EACL,oBAAoB,GAErB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EACL,aAAa,GAGd,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,IAAI,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxD,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;IACzB,mBAAmB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC/B,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACpE,OAAO;QACL,GAAG,MAAM;QACT,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5C,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;QACxB,MAAM,EAAE,YAAY;QACpB,MAAM,E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C,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { renderHook, act } from \"@testing-library/react\";\nimport React, { useReducer } from \"react\";\nimport { useTamboClient } from \"../../providers/tambo-client-provider\";\nimport {\n TamboRegistryContext,\n type TamboRegistryContext as TamboRegistryContextType,\n} from \"../../providers/tambo-registry-provider\";\nimport { TamboStreamProvider } from \"../providers/tambo-v1-stream-context\";\nimport {\n streamReducer,\n type StreamState,\n type StreamAction,\n} from \"../utils/event-accumulator\";\nimport type {\n TamboComponentContent,\n TamboToolUseContent,\n} from \"../types/message\";\nimport { useTambo } from \"./use-tambo-v1\";\n\njest.mock(\"../../providers/tambo-client-provider\", () => ({\n useTamboClient: jest.fn(),\n useTamboQueryClient: jest.fn(),\n}));\n\njest.mock(\"../providers/tambo-v1-provider\", () => {\n const actual = jest.requireActual(\"../providers/tambo-v1-provider\");\n return {\n ...actual,\n useTamboConfig: () => ({ userKey: undefined }),\n };\n});\n\njest.mock(\"./use-tambo-v1-auth-state\", () => ({\n useTamboAuthState: () => ({\n status: \"identified\",\n source: \"userKey\",\n }),\n}));\n\nimport { useTamboQueryClient } from \"../../providers/tambo-client-provider\";\n\ndescribe(\"useTambo\", () => {\n let queryClient: QueryClient;\n\n const mockTamboClient = {\n apiKey: \"\",\n threads: {\n messages: {\n list: jest.fn().mockResolvedValue({ messages: [], hasMore: false }),\n },\n runs: {\n delete: jest.fn().mockResolvedValue({}),\n },\n },\n } as unknown as TamboAI;\n\n const mockRegistry: TamboRegistryContextType = {\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n mcpServerInfos: [],\n resources: [],\n resourceSource: null,\n registerComponent: jest.fn(),\n registerTool: jest.fn(),\n registerTools: jest.fn(),\n addToolAssociation: jest.fn(),\n registerMcpServer: jest.fn(),\n registerMcpServers: jest.fn(),\n registerResource: jest.fn(),\n registerResources: jest.fn(),\n registerResourceSource: jest.fn(),\n };\n\n function TestWrapper({ children }: { children: React.ReactNode }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider>{children}</TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n }\n\n function createWrapperWithState(\n state: StreamState,\n registry: TamboRegistryContextType = mockRegistry,\n ) {\n const noopDispatch: React.Dispatch<StreamAction> = () => {};\n return function WrapperWithState({\n children,\n }: {\n children: React.ReactNode;\n }) {\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={registry}>\n <TamboStreamProvider state={state} dispatch={noopDispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n // Wrapper that uses the real reducer so state updates properly\n function createWrapperWithRealReducer(\n initialState: StreamState,\n stateRef?: React.MutableRefObject<StreamState | undefined>,\n ) {\n return function WrapperWithRealReducer({\n children,\n }: {\n children: React.ReactNode;\n }) {\n const [state, dispatch] = useReducer(streamReducer, initialState);\n if (stateRef) {\n stateRef.current = state;\n }\n return (\n <QueryClientProvider client={queryClient}>\n <TamboRegistryContext.Provider value={mockRegistry}>\n <TamboStreamProvider state={state} dispatch={dispatch}>\n {children}\n </TamboStreamProvider>\n </TamboRegistryContext.Provider>\n </QueryClientProvider>\n );\n };\n }\n\n beforeEach(() => {\n queryClient = new QueryClient({\n defaultOptions: {\n queries: { retry: false },\n },\n });\n jest.mocked(useTamboClient).mockReturnValue(mockTamboClient);\n jest.mocked(useTamboQueryClient).mockReturnValue(queryClient);\n jest.clearAllMocks();\n delete (mockTamboClient.threads as any).update;\n });\n\n it(\"returns client from useTamboClient\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.client).toBe(mockTamboClient);\n });\n\n it(\"returns registry functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.registerComponent).toBe(\n mockRegistry.registerComponent,\n );\n expect(result.current.registerTool).toBe(mockRegistry.registerTool);\n expect(result.current.registerTools).toBe(mockRegistry.registerTools);\n expect(result.current.componentList).toBe(mockRegistry.componentList);\n expect(result.current.toolRegistry).toBe(mockRegistry.toolRegistry);\n });\n\n it(\"returns placeholder thread when no threadId provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Default state has placeholder thread for optimistic UI\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns thread state when switched to a thread\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n expect(result.current.messages).toEqual([]);\n });\n\n it(\"returns default streaming state when thread not loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(result.current.streamingState).toEqual({ status: \"idle\" });\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"returns thread streaming state when thread loaded\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n expect(result.current.streamingState.status).toBe(\"idle\");\n expect(result.current.isIdle).toBe(true);\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isWaiting).toBe(false);\n });\n\n it(\"provides dispatch function for advanced usage\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.dispatch).toBe(\"function\");\n });\n\n it(\"provides thread management functions\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n expect(typeof result.current.initThread).toBe(\"function\");\n expect(typeof result.current.switchThread).toBe(\"function\");\n expect(typeof result.current.startNewThread).toBe(\"function\");\n });\n\n it(\"initializes and switches threads\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initially has placeholder thread for optimistic UI\n expect(result.current.currentThreadId).toBe(\"placeholder\");\n expect(result.current.thread).toBeDefined();\n expect(result.current.thread?.thread.id).toBe(\"placeholder\");\n\n // Initialize a new thread\n act(() => {\n result.current.initThread(\"new_thread_1\");\n });\n\n // Switch to the new thread\n act(() => {\n result.current.switchThread(\"new_thread_1\");\n });\n\n expect(result.current.currentThreadId).toBe(\"new_thread_1\");\n });\n\n it(\"starts new thread with generated ID\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n let newThreadId: string;\n act(() => {\n newThreadId = result.current.startNewThread();\n });\n\n expect(newThreadId!).toBe(\"placeholder\");\n expect(result.current.currentThreadId).toBe(newThreadId!);\n expect(result.current.thread).toBeDefined();\n });\n\n it(\"uses current thread when no threadId argument provided\", () => {\n const { result } = renderHook(() => useTambo(), {\n wrapper: TestWrapper,\n });\n\n // Initialize and switch to a thread\n act(() => {\n result.current.initThread(\"thread_123\");\n result.current.switchThread(\"thread_123\");\n });\n\n // Should use current thread from context (thread_123)\n expect(result.current.currentThreadId).toBe(\"thread_123\");\n expect(result.current.thread?.thread.id).toBe(\"thread_123\");\n });\n\n describe(\"component content transformation\", () => {\n const createComponentContent = (\n id: string,\n name: string,\n props: Record<string, unknown>,\n ): TamboComponentContent => ({\n type: \"component\",\n id,\n name,\n props,\n streamingState: \"done\",\n });\n\n it(\"adds renderedComponent to component content blocks\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"preserves non-component content blocks unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n { type: \"text\", text: \"Hello world\" },\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hi\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages).toHaveLength(1);\n const textContent = result.current.messages[0].content[0];\n expect(textContent.type).toBe(\"text\");\n expect(textContent).toEqual({ type: \"text\", text: \"Hello world\" });\n\n const componentContent = result.current.messages[0].content[1];\n expect(componentContent.type).toBe(\"component\");\n expect(\n (componentContent as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"caches rendered components and returns same reference when props unchanged\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result, rerender } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const firstRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Re-render with same state\n rerender();\n\n const secondRender = (\n result.current.messages[0].content[0] as TamboComponentContent\n ).renderedComponent;\n\n // Should return the same cached element reference\n expect(secondRender).toBe(firstRender);\n });\n\n it(\"handles empty props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {}),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles undefined props on components\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"component\",\n id: \"comp_1\",\n name: \"TestComponent\",\n props: undefined,\n streamingState: \"done\",\n } as TamboComponentContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n\n it(\"handles multiple component content blocks in same message\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"ComponentA\", {\n value: 1,\n }),\n createComponentContent(\"comp_2\", \"ComponentB\", {\n value: 2,\n }),\n createComponentContent(\"comp_3\", \"ComponentC\", {\n value: 3,\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n expect(result.current.messages[0].content).toHaveLength(3);\n result.current.messages[0].content.forEach((content) => {\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n it(\"uses currentThreadId from stream state\", () => {\n const state: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n createComponentContent(\"comp_1\", \"TestComponent\", {\n title: \"Hello\",\n }),\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n // No explicit threadId - uses currentThreadId from state\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n // Component should render using the placeholder thread\n const content = result.current.messages[0].content[0];\n expect(content.type).toBe(\"component\");\n expect(\n (content as TamboComponentContent).renderedComponent,\n ).toBeDefined();\n });\n });\n\n describe(\"tool_use content transformation\", () => {\n it(\"adds computed properties to tool_use content\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.type).toBe(\"tool_use\");\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getWeather\");\n expect(content.tamboDisplayProps).toBeDefined();\n });\n\n it(\"sets hasCompleted to true when matching tool_result exists\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Called getWeather\");\n });\n\n it(\"uses _tambo_statusMessage when tool is in progress\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather for NYC...\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.statusMessage).toBe(\"Fetching weather for NYC...\");\n expect(content.tamboDisplayProps?._tambo_statusMessage).toBe(\n \"Fetching weather for NYC...\",\n );\n });\n\n it(\"uses _tambo_completionStatusMessage when tool is completed\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n _tambo_statusMessage: \"Fetching weather...\",\n _tambo_completionStatusMessage: \"Got weather for NYC\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.hasCompleted).toBe(true);\n expect(content.statusMessage).toBe(\"Got weather for NYC\");\n });\n\n it(\"filters _tambo_* properties from input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: {\n location: \"NYC\",\n units: \"celsius\",\n _tambo_statusMessage: \"Fetching...\",\n _tambo_completionStatusMessage: \"Done\",\n },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n // Input should only have non-_tambo_ properties\n expect(content.input).toEqual({ location: \"NYC\", units: \"celsius\" });\n expect(content.input._tambo_statusMessage).toBeUndefined();\n expect(content.input._tambo_completionStatusMessage).toBeUndefined();\n });\n\n it(\"handles tool_use with empty input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: {},\n },\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n expect(content.statusMessage).toBe(\"Calling getCurrentTime\");\n });\n\n it(\"handles tool_use with undefined input\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getCurrentTime\",\n input: undefined,\n } as unknown as TamboToolUseContent,\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const content = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n expect(content.input).toEqual({});\n expect(content.hasCompleted).toBe(false);\n });\n\n it(\"handles multiple tool_use blocks with different completion states\", () => {\n const state: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [\n {\n id: \"msg_1\",\n role: \"assistant\",\n content: [\n {\n type: \"tool_use\",\n id: \"tool_1\",\n name: \"getWeather\",\n input: { location: \"NYC\" },\n },\n {\n type: \"tool_use\",\n id: \"tool_2\",\n name: \"getTime\",\n input: { timezone: \"EST\" },\n },\n ],\n createdAt: new Date().toISOString(),\n },\n {\n id: \"msg_2\",\n role: \"user\",\n content: [\n {\n type: \"tool_result\",\n toolUseId: \"tool_1\",\n content: [{ type: \"text\", text: \"Sunny\" }],\n },\n // tool_2 has no result yet\n ],\n createdAt: new Date().toISOString(),\n },\n ],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithState(state),\n });\n\n const tool1 = result.current.messages[0]\n .content[0] as TamboToolUseContent;\n const tool2 = result.current.messages[0]\n .content[1] as TamboToolUseContent;\n\n expect(tool1.hasCompleted).toBe(true);\n expect(tool1.statusMessage).toBe(\"Called getWeather\");\n\n expect(tool2.hasCompleted).toBe(false);\n expect(tool2.statusMessage).toBe(\"Calling getTime\");\n });\n });\n\n describe(\"cancelRun\", () => {\n it(\"sets thread to idle and lastRunCancelled to true when cancelled\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before cancel: streaming and lastRunCancelled is false\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.isIdle).toBe(false);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After cancel: idle and lastRunCancelled is true\n expect(result.current.isStreaming).toBe(false);\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Verify API was called to cancel the run\n expect(mockTamboClient.threads.runs.delete).toHaveBeenCalledWith(\n \"run_456\",\n { threadId: \"thread_123\" },\n );\n });\n\n it(\"is a no-op when there is no active run\", async () => {\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"idle\" }, // No runId\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Idle before\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Still idle, lastRunCancelled unchanged\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"is a no-op when on a placeholder thread\", async () => {\n const initialState: StreamState = {\n threadMap: {\n placeholder: {\n thread: {\n id: \"placeholder\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_123\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n // Before: streaming on placeholder\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // After: state should be unchanged (placeholder threads are skipped)\n expect(result.current.isStreaming).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(false);\n\n // API should not have been called for placeholder threads\n expect(mockTamboClient.threads.runs.delete).not.toHaveBeenCalled();\n });\n\n it(\"still updates local state even if API call fails\", async () => {\n const consoleWarnSpy = jest\n .spyOn(console, \"warn\")\n .mockImplementation(() => {});\n\n // Make the API call fail\n jest\n .mocked(mockTamboClient.threads.runs.delete)\n .mockRejectedValueOnce(new Error(\"Network error\"));\n\n const initialState: StreamState = {\n threadMap: {\n thread_123: {\n thread: {\n id: \"thread_123\",\n messages: [],\n status: \"streaming\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n },\n streaming: { status: \"streaming\", runId: \"run_456\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_123\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.cancelRun();\n });\n\n // Local state should still be updated (optimistic update)\n expect(result.current.isIdle).toBe(true);\n expect(result.current.thread?.thread.lastRunCancelled).toBe(true);\n\n // Warning should have been logged\n expect(consoleWarnSpy).toHaveBeenCalledWith(\n \"Failed to cancel run on server:\",\n expect.any(Error),\n );\n\n consoleWarnSpy.mockRestore();\n });\n });\n\n describe(\"updateThreadName\", () => {\n it(\"updates local thread name and invalidates caches on success\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_456\", {\n name: \"My New Thread\",\n userKey: undefined,\n });\n\n expect(result.current.thread?.thread.name).toBe(\"My New Thread\");\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_456\"]);\n });\n\n it(\"does not create local thread state when thread isn't loaded\", async () => {\n const mockUpdate = jest.fn().mockResolvedValue({});\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n // Track the internal StreamState from the real reducer so we can assert we\n // don't create a local thread entry for threads that haven't been loaded.\n const stateRef: React.MutableRefObject<StreamState | undefined> = {\n current: undefined,\n };\n const initialState: StreamState = {\n threadMap: {},\n currentThreadId: \"placeholder\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState, stateRef),\n });\n\n await act(async () => {\n await result.current.updateThreadName(\"thread_789\", \"New Title\");\n });\n\n expect(mockUpdate).toHaveBeenCalledWith(\"thread_789\", {\n name: \"New Title\",\n userKey: undefined,\n });\n const invalidatedKeys = invalidateQueriesSpy.mock.calls\n .map(([arg]) => (arg as any).queryKey)\n .filter(Boolean);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"list\"]);\n expect(invalidatedKeys).toContainEqual([\"v1-threads\", \"thread_789\"]);\n\n expect(stateRef.current?.threadMap.thread_789).toBeUndefined();\n\n act(() => {\n result.current.switchThread(\"thread_789\");\n });\n\n expect(result.current.thread).toBeUndefined();\n });\n\n it(\"propagates errors and does not update local state\", async () => {\n const mockUpdate = jest\n .fn()\n .mockRejectedValue(new Error(\"Network error\"));\n // TypeScript SDK will be updated to include this method\n (mockTamboClient.threads as any).update = mockUpdate;\n\n const invalidateQueriesSpy = jest.spyOn(queryClient, \"invalidateQueries\");\n\n const initialState: StreamState = {\n threadMap: {\n thread_456: {\n thread: {\n id: \"thread_456\",\n messages: [],\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n lastRunCancelled: false,\n name: \"Old Name\",\n },\n streaming: { status: \"idle\" },\n accumulatingToolArgs: new Map(),\n },\n },\n currentThreadId: \"thread_456\",\n };\n\n const { result } = renderHook(() => useTambo(), {\n wrapper: createWrapperWithRealReducer(initialState),\n });\n\n let caughtError: unknown;\n await act(async () => {\n try {\n await result.current.updateThreadName(\"thread_456\", \"My New Thread\");\n } catch (error) {\n caughtError = error;\n }\n });\n\n expect(caughtError).toBeInstanceOf(Error);\n expect((caughtError as Error).message).toBe(\"Network error\");\n expect(result.current.thread?.thread.name).toBe(\"Old Name\");\n expect(invalidateQueriesSpy).not.toHaveBeenCalled();\n });\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tambo-ai/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "React client package for Tambo AI!",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -76,11 +76,11 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@ag-ui/core": "^0.0.
|
|
79
|
+
"@ag-ui/core": "^0.0.44",
|
|
80
80
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
81
81
|
"@standard-community/standard-json": "^0.3.5",
|
|
82
82
|
"@standard-schema/spec": "^1.1.0",
|
|
83
|
-
"@tambo-ai/typescript-sdk": "^0.
|
|
83
|
+
"@tambo-ai/typescript-sdk": "^0.93.0",
|
|
84
84
|
"@tanstack/react-query": "^5.90.16",
|
|
85
85
|
"fast-equals": "^5.3.3",
|
|
86
86
|
"fast-json-patch": "^3.1.1",
|