@tambo-ai/react 0.21.4 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/hooks/use-component-state.js +3 -2
  2. package/dist/hooks/use-component-state.js.map +1 -1
  3. package/dist/hooks/use-current-message.d.ts +12 -9
  4. package/dist/hooks/use-current-message.d.ts.map +1 -1
  5. package/dist/hooks/use-current-message.js +5 -4
  6. package/dist/hooks/use-current-message.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/model/component-metadata.d.ts +10 -1
  12. package/dist/model/component-metadata.d.ts.map +1 -1
  13. package/dist/model/component-metadata.js.map +1 -1
  14. package/dist/providers/tambo-mcp-provider.d.ts +10 -0
  15. package/dist/providers/tambo-mcp-provider.d.ts.map +1 -0
  16. package/dist/providers/tambo-mcp-provider.js +65 -0
  17. package/dist/providers/tambo-mcp-provider.js.map +1 -0
  18. package/dist/testing/tools.js.map +1 -1
  19. package/dist/util/mcp-client.d.ts +198 -0
  20. package/dist/util/mcp-client.d.ts.map +1 -0
  21. package/dist/util/mcp-client.js +108 -0
  22. package/dist/util/mcp-client.js.map +1 -0
  23. package/dist/util/mcp-tools-client.d.ts +96 -0
  24. package/dist/util/mcp-tools-client.d.ts.map +1 -0
  25. package/dist/util/mcp-tools-client.js +178 -0
  26. package/dist/util/mcp-tools-client.js.map +1 -0
  27. package/dist/util/registry.d.ts.map +1 -1
  28. package/dist/util/registry.js +18 -0
  29. package/dist/util/registry.js.map +1 -1
  30. package/esm/hooks/use-component-state.js +3 -2
  31. package/esm/hooks/use-component-state.js.map +1 -1
  32. package/esm/hooks/use-current-message.d.ts +12 -9
  33. package/esm/hooks/use-current-message.d.ts.map +1 -1
  34. package/esm/hooks/use-current-message.js +5 -4
  35. package/esm/hooks/use-current-message.js.map +1 -1
  36. package/esm/index.d.ts +1 -0
  37. package/esm/index.d.ts.map +1 -1
  38. package/esm/index.js +1 -0
  39. package/esm/index.js.map +1 -1
  40. package/esm/model/component-metadata.d.ts +10 -1
  41. package/esm/model/component-metadata.d.ts.map +1 -1
  42. package/esm/model/component-metadata.js.map +1 -1
  43. package/esm/providers/tambo-mcp-provider.d.ts +10 -0
  44. package/esm/providers/tambo-mcp-provider.d.ts.map +1 -0
  45. package/esm/providers/tambo-mcp-provider.js +61 -0
  46. package/esm/providers/tambo-mcp-provider.js.map +1 -0
  47. package/esm/testing/tools.js.map +1 -1
  48. package/esm/util/mcp-client.d.ts +198 -0
  49. package/esm/util/mcp-client.d.ts.map +1 -0
  50. package/esm/util/mcp-client.js +104 -0
  51. package/esm/util/mcp-client.js.map +1 -0
  52. package/esm/util/mcp-tools-client.d.ts +96 -0
  53. package/esm/util/mcp-tools-client.d.ts.map +1 -0
  54. package/esm/util/mcp-tools-client.js +174 -0
  55. package/esm/util/mcp-tools-client.js.map +1 -0
  56. package/esm/util/registry.d.ts.map +1 -1
  57. package/esm/util/registry.js +18 -0
  58. package/esm/util/registry.js.map +1 -1
  59. package/package.json +8 -7
@@ -7,10 +7,11 @@ const providers_1 = require("../providers");
7
7
  const use_current_message_1 = require("./use-current-message");
8
8
  // eslint-disable-next-line jsdoc/require-jsdoc
9
9
  function useTamboComponentState(keyName, initialValue, debounceTime = 500) {
10
- const { threadId, messageId } = (0, use_current_message_1.useTamboMessageContext)();
11
- const { updateThreadMessage } = (0, providers_1.useTamboThread)();
10
+ const { messageId } = (0, use_current_message_1.useTamboMessageContext)();
11
+ const { updateThreadMessage, thread } = (0, providers_1.useTamboThread)();
12
12
  const client = (0, providers_1.useTamboClient)();
13
13
  const message = (0, use_current_message_1.useTamboCurrentMessage)();
14
+ const threadId = thread.id;
14
15
  // Initial value management
15
16
  const [cachedInitialValue] = (0, react_1.useState)(() => initialValue);
16
17
  // UI state management
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-state.js","sourceR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AAC,CAAC;QAExB,mDAAmD;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,MAAM,aAAa,GAAG;gBACpB,GAAG,OAAO;gBACV,cAAc,EAAE;oBACd,GAAG,OAAO,CAAC,cAAc;oBACzB,CAAC,OAAO,CAAC,EAAE,QAAQ;iBACpB;aACF,CAAC;YAEF,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CACV,4CAA4C,SAAS,cAAc,OAAO,GAAG,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,mBAAmB,EAAE,SAAS,CAAC,CACzE,CAAC;IAEF,gDAAgD;IAChD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const { threadId, messageId } = useTamboMessageContext();\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // Only update local state if we haven't had any user changes yet\n if (lastUserValue === null) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one and no user changes\n else if (\n cachedInitialValue !== undefined &&\n !localState &&\n lastUserValue === null\n ) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedServerWrite = useDebouncedCallback(async (newValue: S) => {\n setIsPending(true);\n try {\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n );\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedServerWrite(newValue);\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n updateThreadMessage(messageId, messageUpdate, false);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n }\n },\n [message, debouncedServerWrite, keyName, updateThreadMessage, messageId],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedServerWrite.flush();\n };\n }, [debouncedServerWrite]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
1
+ {"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":";;AA0DA,wDA2KC;AArOD,iCAAyD;AACzD,+CAAoD;AACpD,4CAA8D;AAC9D,+DAG+B;AAmD/B,+CAA+C;AAC/C,SAAgB,sBAAsB,CACpC,OAAe,EACf,YAAgB,EAChB,YAAY,GAAG,GAAG;IAElB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,4CAAsB,GAAE,CAAC;IAC/C,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,IAAA,0BAAc,GAAE,CAAC;IACzD,MAAM,MAAM,GAAG,IAAA,0BAAc,GAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAA,4CAAsB,GAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;IAE3B,2BAA2B;IAC3B,MAAM,CAAC,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC;IAC1D,sBAAsB;IACtB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAC1C,kBAAkB,CACnB,CAAC;IACF,wBAAwB;IACxB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAClD,uEAAuE;IACvE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAW,IAAI,CAAC,CAAC;IACnE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,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EAAE,CAAC;YAClB,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAExC,uCAAuC;IACvC,sEAAsE;IACtE,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAC1B,CAAC,QAAW,EAAE,EAAE;QACd,wCAAwC;QACxC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3B,aAAa,CAAC,QAAQ,CAAC,CAAC;QAExB,mDAAmD;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,MAAM,aAAa,GAAG;gBACpB,GAAG,OAAO;gBACV,cAAc,EAAE;oBACd,GAAG,OAAO,CAAC,cAAc;oBACzB,CAAC,OAAO,CAAC,EAAE,QAAQ;iBACpB;aACF,CAAC;YAEF,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CACV,4CAA4C,SAAS,cAAc,OAAO,GAAG,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,mBAAmB,EAAE,SAAS,CAAC,CACzE,CAAC;IAEF,gDAAgD;IAChD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 500,\n): StateUpdateResult<S> {\n const { messageId } = useTamboMessageContext();\n const { updateThreadMessage, thread } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n const threadId = thread.id;\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // Only update local state if we haven't had any user changes yet\n if (lastUserValue === null) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one and no user changes\n else if (\n cachedInitialValue !== undefined &&\n !localState &&\n lastUserValue === null\n ) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedServerWrite = useDebouncedCallback(async (newValue: S) => {\n setIsPending(true);\n try {\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n );\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedServerWrite(newValue);\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n updateThreadMessage(messageId, messageUpdate, false);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n }\n },\n [message, debouncedServerWrite, keyName, updateThreadMessage, messageId],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedServerWrite.flush();\n };\n }, [debouncedServerWrite]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
@@ -1,16 +1,21 @@
1
1
  import React, { PropsWithChildren } from "react";
2
+ interface TamboMessageContextProps {
3
+ /**
4
+ * The threadId of the thread
5
+ * @deprecated Use the thread object from the TamboThreadProvider instead
6
+ */
7
+ threadId?: string;
8
+ /** The messageId of the message */
9
+ messageId: string;
10
+ }
2
11
  /**
3
12
  * Wraps all components, so that they can find what thread and message they are in
4
13
  * @param props - props for the TamboMessageProvider
5
14
  * @param props.children - The children to wrap
6
- * @param props.threadId - The threadId of the thread
7
15
  * @param props.messageId - The messageId of the message
8
16
  * @returns The wrapped component
9
17
  */
10
- export declare const TamboMessageProvider: React.FC<PropsWithChildren<{
11
- threadId: string;
12
- messageId: string;
13
- }>>;
18
+ export declare const TamboMessageProvider: React.FC<PropsWithChildren<TamboMessageContextProps>>;
14
19
  /**
15
20
  * Wraps a component with a ComponentMessageProvider - this allows the provider
16
21
  * to be used outside of a TSX file
@@ -25,10 +30,7 @@ export declare function wrapWithTamboMessageProvider(children: React.ReactNode,
25
30
  * the threadId and messageId
26
31
  * @returns The threadId and messageId
27
32
  */
28
- export declare const useTamboMessageContext: () => {
29
- threadId: string;
30
- messageId: string;
31
- };
33
+ export declare const useTamboMessageContext: () => TamboMessageContextProps;
32
34
  /**
33
35
  * Hook used inside a component wrapped with ComponentMessageProvider, to get
34
36
  * the current message. The current thread will be fetched from the server, if
@@ -36,4 +38,5 @@ export declare const useTamboMessageContext: () => {
36
38
  * @returns The current message that is used to render the component
37
39
  */
38
40
  export declare const useTamboCurrentMessage: () => import("..").TamboThreadMessage | undefined;
41
+ export {};
39
42
  //# sourceMappingURL=use-current-message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAQ5E;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAa3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;cApDvB,MAAM;eACL,MAAM;CA2DlB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
1
+ {"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAG5E,UAAU,wBAAwB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC,wBAAwB,CAAC,CAU5C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,gCAQlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
@@ -37,20 +37,21 @@ exports.useTamboCurrentMessage = exports.useTamboMessageContext = exports.TamboM
37
37
  exports.wrapWithTamboMessageProvider = wrapWithTamboMessageProvider;
38
38
  const react_1 = __importStar(require("react"));
39
39
  const providers_1 = require("../providers");
40
- const TamboMessageContext = (0, react_1.createContext)({});
40
+ const TamboMessageContext = (0, react_1.createContext)({
41
+ messageId: "",
42
+ });
41
43
  /**
42
44
  * Wraps all components, so that they can find what thread and message they are in
43
45
  * @param props - props for the TamboMessageProvider
44
46
  * @param props.children - The children to wrap
45
- * @param props.threadId - The threadId of the thread
46
47
  * @param props.messageId - The messageId of the message
47
48
  * @returns The wrapped component
48
49
  */
49
- const TamboMessageProvider = ({ children, threadId, messageId }) => {
50
+ const TamboMessageProvider = ({ children, messageId }) => {
50
51
  // Use a unique key={...} to force a re-render when the messageId changes - this
51
52
  // make sure that if the rendered component is swapped into a tree (like if
52
53
  // you always show the last rendered component) then the state/etc is correct
53
- return (react_1.default.createElement(TamboMessageContext.Provider, { value: { threadId, messageId }, key: `${threadId}-${messageId}` }, children));
54
+ return (react_1.default.createElement(TamboMessageContext.Provider, { value: { messageId }, key: messageId }, children));
54
55
  };
55
56
  exports.TamboMessageProvider = TamboMessageProvider;
56
57
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,sBAAsB,0BASjC","sourcesContent":["import React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\nconst TamboMessageContext = createContext<{\n threadId: string;\n messageId: string;\n}>({} as { threadId: string; messageId: string });\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.threadId - The threadId of the thread\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<{ threadId: string; messageId: string }>\n> = ({ children, threadId, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider\n value={{ threadId, messageId }}\n key={`${threadId}-${messageId}`}\n >\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
1
+ {"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,oEAUC;AAvDD,+CAA4E;AAC5E,4CAA8C;AAY9C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAA2B;IAClE,SAAS,EAAE,EAAE;CACd,CAAC,CAAC;AAEH;;;;;;GAMG;AACI,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IAC9B,gFAAgF;IAChF,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,8BAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,IAC/D,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,oBAAoB,wBAW/B;AAEF;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,QAAyB,EACzB,QAAgB,EAChB,SAAiB;IAEjB,OAAO,CACL,8BAAC,4BAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,IAC3D,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AACD;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC;AAEF;;;;;GAKG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAA,8BAAsB,GAAE,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,0BAAc,GAAE,CAAC;IACpC,IAAI,MAAM,CAAC,EAAE,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,sBAAsB,0BASjC","sourcesContent":["import React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\ninterface TamboMessageContextProps {\n /**\n * The threadId of the thread\n * @deprecated Use the thread object from the TamboThreadProvider instead\n */\n threadId?: string;\n /** The messageId of the message */\n messageId: string;\n}\n\nconst TamboMessageContext = createContext<TamboMessageContextProps>({\n messageId: \"\",\n});\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<TamboMessageContextProps>\n> = ({ children, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider value={{ messageId }} key={messageId}>\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -11,4 +11,5 @@ export { useTamboThreadList } from "./hooks/use-tambo-threads";
11
11
  export { type ComponentContextToolMetadata, type ComponentRegistry, type ParameterSpec, type RegisteredComponent, type TamboTool, } from "./model/component-metadata";
12
12
  export { GenerationStage, type TamboThreadMessage, } from "./model/generate-component-response";
13
13
  export { type TamboThread } from "./model/tambo-thread";
14
+ export { TamboMcpProvider } from "./providers/tambo-mcp-provider";
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC"}
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThread = exports.useTamboClient = exports.useTambo = exports.TamboThreadProvider = exports.TamboProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboThreadInput = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
17
+ exports.TamboMcpProvider = exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThread = exports.useTamboClient = exports.useTambo = exports.TamboThreadProvider = exports.TamboProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboThreadInput = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
18
18
  /** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */
19
19
  var use_component_state_1 = require("./hooks/use-component-state");
20
20
  Object.defineProperty(exports, "useTamboComponentState", { enumerable: true, get: function () { return use_component_state_1.useTamboComponentState; } });
@@ -40,4 +40,6 @@ var use_tambo_threads_1 = require("./hooks/use-tambo-threads");
40
40
  Object.defineProperty(exports, "useTamboThreadList", { enumerable: true, get: function () { return use_tambo_threads_1.useTamboThreadList; } });
41
41
  var generate_component_response_1 = require("./model/generate-component-response");
42
42
  Object.defineProperty(exports, "GenerationStage", { enumerable: true, get: function () { return generate_component_response_1.GenerationStage; } });
43
+ var tambo_mcp_provider_1 = require("./providers/tambo-mcp-provider");
44
+ Object.defineProperty(exports, "TamboMcpProvider", { enumerable: true, get: function () { return tambo_mcp_provider_1.TamboMcpProvider; } });
43
45
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wKAAwK;AACxK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAIqC;AAHnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AAExB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,6DAA+D;AAAtD,uHAAA,mBAAmB,OAAA;AAE5B,gCAAgC;AAChC,yCAUqB;AATnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,0GAAA,aAAa,OAAA;AACb,gHAAA,mBAAmB,OAAA;AACnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AAiBhB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wKAAwK;AACxK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAIqC;AAHnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AAExB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,6DAA+D;AAAtD,uHAAA,mBAAmB,OAAA;AAE5B,gCAAgC;AAChC,yCAUqB;AATnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,0GAAA,aAAa,OAAA;AACb,gHAAA,mBAAmB,OAAA;AACnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AAiBhB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA;AAIjB,qEAAkE;AAAzD,sHAAA,gBAAgB,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\nexport { TamboMcpProvider } from \"./providers/tambo-mcp-provider\";\n"]}
@@ -24,11 +24,20 @@ export interface RegisteredComponent extends TamboAI.AvailableComponent {
24
24
  }
25
25
  export type ComponentRegistry = Record<string, RegisteredComponent>;
26
26
  export type TamboToolRegistry = Record<string, TamboTool>;
27
+ /**
28
+ * A JSON Schema that is compatible with the MCP.
29
+ * This is a simplified JSON Schema that is compatible with the MCPClient and the toolSchema.
30
+ *
31
+ * Do not export this type from the SDK.
32
+ */
33
+ export type JSONSchemaLite = ReturnType<typeof zodToJsonSchema> & {
34
+ description?: string;
35
+ };
27
36
  export interface TamboTool<Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>, Returns extends z.ZodTypeAny = z.ZodTypeAny> {
28
37
  name: string;
29
38
  description: string;
30
39
  tool: (...args: z.infer<Args>) => z.infer<Returns>;
31
- toolSchema: z.ZodFunction<Args, Returns>;
40
+ toolSchema: z.ZodFunction<Args, Returns> | JSONSchemaLite;
32
41
  }
33
42
  export type TamboToolAssociations = Record<string, string[]>;
34
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"component-metadata.d.ts","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AACtD,+FAA+F;AAC/F,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,GAAG;IACnD,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;CAC7C,CAAC;AAEF;;;GAG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AC,GAAG,CAAC,CAAC;IACtC,uDAAuD;IACvD,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;CAC/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { JSONSchema7 } from \"json-schema\";\nimport { ComponentType } from \"react\";\nimport z from \"zod\";\nimport type zodToJsonSchema from \"zod-to-json-schema\";\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: ReturnType<typeof zodToJsonSchema>;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation using zod-to-json-schema.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\nexport interface TamboTool<\n Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>,\n Returns extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n name: string;\n description: string;\n tool: (...args: z.infer<Args>) => z.infer<Returns>;\n toolSchema: z.ZodFunction<Args, Returns>;\n}\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * A zod schema for the component props. (Recommended)\n * Either this or propsDefinition must be provided, but not both.\n */\n propsSchema?: z.ZodTypeAny | JSONSchema7;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n * @deprecated Use propsSchema instead.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n}\n"]}
1
+ {"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { JSONSchema7 } from \"json-schema\";\nimport { ComponentType } from \"react\";\nimport z from \"zod\";\nimport type zodToJsonSchema from \"zod-to-json-schema\";\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: ReturnType<typeof zodToJsonSchema>;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation using zod-to-json-schema.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\n/**\n * A JSON Schema that is compatible with the MCP.\n * This is a simplified JSON Schema that is compatible with the MCPClient and the toolSchema.\n *\n * Do not export this type from the SDK.\n */\nexport type JSONSchemaLite = ReturnType<typeof zodToJsonSchema> & {\n description?: string;\n};\n\nexport interface TamboTool<\n Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>,\n Returns extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n name: string;\n description: string;\n tool: (...args: z.infer<Args>) => z.infer<Returns>;\n toolSchema: z.ZodFunction<Args, Returns> | JSONSchemaLite;\n}\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * A zod schema for the component props. (Recommended)\n * Either this or propsDefinition must be provided, but not both.\n */\n propsSchema?: z.ZodTypeAny | JSONSchema7;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n * @deprecated Use propsSchema instead.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { FC } from "react";
2
+ /**
3
+ * This provider is used to register tools from MCP servers.
4
+ * @returns the wrapped children
5
+ */
6
+ export declare const TamboMcpProvider: FC<{
7
+ mcpServers: string[];
8
+ children: React.ReactNode;
9
+ }>;
10
+ //# sourceMappingURL=tambo-mcp-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAKtC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CA6DA,CAAC"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TamboMcpProvider = void 0;
4
+ const react_1 = require("react");
5
+ const mcp_client_1 = require("../util/mcp-client");
6
+ const tambo_registry_provider_1 = require("./tambo-registry-provider");
7
+ /**
8
+ * This provider is used to register tools from MCP servers.
9
+ * @returns the wrapped children
10
+ */
11
+ const TamboMcpProvider = ({ mcpServers, children }) => {
12
+ const { registerTool } = (0, tambo_registry_provider_1.useTamboRegistry)();
13
+ (0, react_1.useEffect)(() => {
14
+ if (!mcpServers) {
15
+ return;
16
+ }
17
+ async function registerMcpServers(mcpServers) {
18
+ // Maps tool names to the MCP client that registered them
19
+ const mcpServerMap = new Map();
20
+ const serverToolLists = mcpServers.map(async (mcpServer) => {
21
+ const mcpClient = await mcp_client_1.MCPClient.create(mcpServer, mcp_client_1.MCPTransport.SSE);
22
+ const tools = await mcpClient.listTools();
23
+ tools.forEach((tool) => {
24
+ mcpServerMap.set(tool.name, mcpClient);
25
+ });
26
+ return tools;
27
+ });
28
+ const toolResults = await Promise.allSettled(serverToolLists);
29
+ // Just log the failed tools, we can't do anything about them
30
+ const failedTools = toolResults.filter((result) => result.status === "rejected");
31
+ if (failedTools.length > 0) {
32
+ console.error("Failed to register tools from MCP servers:", failedTools.map((result) => result.reason));
33
+ }
34
+ // Register the successful tools
35
+ const allTools = toolResults
36
+ .filter((result) => result.status === "fulfilled")
37
+ .map((result) => result.value)
38
+ .flat();
39
+ allTools.forEach((tool) => {
40
+ registerTool({
41
+ description: tool.description ?? "",
42
+ name: tool.name,
43
+ tool: async (args) => {
44
+ const mcpServer = mcpServerMap.get(tool.name);
45
+ if (!mcpServer) {
46
+ // should never happen
47
+ throw new Error(`MCP server for tool ${tool.name} not found`);
48
+ }
49
+ const result = await mcpServer.callTool(tool.name, args);
50
+ if (result.isError) {
51
+ // TODO: is there a better way to handle this?
52
+ throw new Error(`${result.content}`);
53
+ }
54
+ return result.content;
55
+ },
56
+ toolSchema: tool.inputSchema,
57
+ });
58
+ });
59
+ }
60
+ registerMcpServers(mcpServers);
61
+ }, [mcpServers, registerTool]);
62
+ return children;
63
+ };
64
+ exports.TamboMcpProvider = TamboMcpProvider;
65
+ //# sourceMappingURL=tambo-mcp-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-mcp-provider.tsx"],"names":[],"mappings":";;;AAAA,iCAAsC;AAEtC,mDAA6D;AAC7D,uEAA6D;AAE7D;;;GAGG;AACI,MAAM,gBAAgB,GAGxB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAChC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,0CAAgB,GAAE,CAAC;IAE5C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QACD,KAAK,UAAU,kBAAkB,CAAC,UAAoB;YACpD,yDAAyD;YACzD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;YAClD,MAAM,eAAe,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;gBACzD,MAAM,SAAS,GAAG,MAAM,sBAAS,CAAC,MAAM,CAAC,SAAS,EAAE,yBAAY,CAAC,GAAG,CAAC,CAAC;gBACtE,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,CAAC;gBAC1C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBACrB,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;gBACH,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,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GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;wBACvC,CAAC;wBACD,OAAO,MAAM,CAAC,OAAO,CAAC;oBACxB,CAAC;oBACD,UAAU,EAAE,IAAI,CAAC,WAAsC;iBACxD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAhEW,QAAA,gBAAgB,oBAgE3B","sourcesContent":["import { FC, useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { MCPClient, MCPTransport } from \"../util/mcp-client\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: string[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: string[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const mcpClient = await MCPClient.create(mcpServer, MCPTransport.SSE);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n // TODO: is there a better way to handle this?\n throw new Error(`${result.content}`);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":";;;;;AASA,8CA0BC;AAlCD,4EAAiD;AAGjD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,YAA8B;IAC9D,OAAO,YAAY,CAAC,GAAG,CACrB,CAAC,EACC,SAAS,EAAE,UAAU,EACrB,WAAW,EACX,eAAe,EACf,GAAG,cAAc,EAClB,EAAE,EAAE,CAAC,CAAC;QACL,GAAG,cAAc;QACjB,KAAK,EAAE,IAAA,4BAAe,EAAC,WAA2B,CAAC;QACnD,YAAY,EAAE,eAAe,EAAE,GAAG,CAChC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;YAC9C,GAAG,SAAS;YACZ,UAAU,EAAE,UAAU;iBACnB,UAAU,EAAE;iBACZ,KAAK,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,KAAa,EAAE,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,EAAE;gBACzB,MAAM,EAAE,IAAA,4BAAe,EAAC,CAAC,CAAC;gBAC1B,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,IAAI,EAAG,IAAA,4BAAe,EAAC,CAAC,CAAS,CAAC,IAAI;aACvC,CAAC,CAAC;SACN,CAAC,CACH;KACF,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport { TamboComponent } from \"../providers\";\n\n/**\n * Serializes the registry for testing purposes\n * @param mockRegistry - The registry to serialize\n * @returns The serialized registry\n */\nexport function serializeRegistry(mockRegistry: TamboComponent[]) {\n return mockRegistry.map(\n ({\n component: _component,\n propsSchema,\n associatedTools,\n ...componentEntry\n }) => ({\n ...componentEntry,\n props: zodToJsonSchema(propsSchema as z.ZodTypeAny),\n contextTools: associatedTools?.map(\n ({ toolSchema, tool: _tool, ...toolEntry }) => ({\n ...toolEntry,\n parameters: toolSchema\n .parameters()\n .items.map((p: z.ZodTypeAny, index: number) => ({\n name: `param${index + 1}`,\n schema: zodToJsonSchema(p),\n isRequired: true,\n description: p.description,\n type: (zodToJsonSchema(p) as any).type,\n })),\n }),\n ),\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":";;;;;AASA,8CA0BC;AAlCD,4EAAiD;AAGjD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,YAA8B;IAC9D,OAAO,YAAY,CAAC,GAAG,CACrB,CAAC,EACC,SAAS,EAAE,UAAU,EACrB,WAAW,EACX,eAAe,EACf,GAAG,cAAc,EAClB,EAAE,EAAE,CAAC,CAAC;QACL,GAAG,cAAc;QACjB,KAAK,EAAE,IAAA,4BAAe,EAAC,WAA2B,CAAC;QACnD,YAAY,EAAE,eAAe,EAAE,GAAG,CAChC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;YAC9C,GAAG,SAAS;YACZ,UAAU,EAAG,UAAsC;iBAChD,UAAU,EAAE;iBACZ,KAAK,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,KAAa,EAAE,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,EAAE;gBACzB,MAAM,EAAE,IAAA,4BAAe,EAAC,CAAC,CAAC;gBAC1B,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,IAAI,EAAG,IAAA,4BAAe,EAAC,CAAC,CAAS,CAAC,IAAI;aACvC,CAAC,CAAC;SACN,CAAC,CACH;KACF,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport { TamboComponent } from \"../providers\";\n\n/**\n * Serializes the registry for testing purposes\n * @param mockRegistry - The registry to serialize\n * @returns The serialized registry\n */\nexport function serializeRegistry(mockRegistry: TamboComponent[]) {\n return mockRegistry.map(\n ({\n component: _component,\n propsSchema,\n associatedTools,\n ...componentEntry\n }) => ({\n ...componentEntry,\n props: zodToJsonSchema(propsSchema as z.ZodTypeAny),\n contextTools: associatedTools?.map(\n ({ toolSchema, tool: _tool, ...toolEntry }) => ({\n ...toolEntry,\n parameters: (toolSchema as z.ZodFunction<any, any>)\n .parameters()\n .items.map((p: z.ZodTypeAny, index: number) => ({\n name: `param${index + 1}`,\n schema: zodToJsonSchema(p),\n isRequired: true,\n description: p.description,\n type: (zodToJsonSchema(p) as any).type,\n })),\n }),\n ),\n }),\n );\n}\n"]}
@@ -0,0 +1,198 @@
1
+ import { JSONSchema7 } from "json-schema";
2
+ export declare enum MCPTransport {
3
+ SSE = "sse",
4
+ HTTP = "http"
5
+ }
6
+ /**
7
+ * A client for interacting with MCP (Model Context Protocol) servers.
8
+ * Provides a simple interface for listing and calling tools exposed by the server.
9
+ * @example
10
+ * ```typescript
11
+ * const mcp = await MCPClient.create('https://api.example.com/mcp');
12
+ * const tools = await mcp.listTools();
13
+ * const result = await mcp.callTool('toolName', { arg1: 'value1' });
14
+ * ```
15
+ */
16
+ export declare class MCPClient {
17
+ private client;
18
+ private transport;
19
+ /**
20
+ * Private constructor to enforce using the static create method.
21
+ * @param endpoint - The URL of the MCP server to connect to
22
+ * @param transport - The transport to use for the MCP client
23
+ * @param headers - Optional custom headers to include in requests
24
+ */
25
+ private constructor();
26
+ /**
27
+ * Creates and initializes a new MCPClient instance.
28
+ * This is the recommended way to create an MCPClient as it handles both
29
+ * instantiation and connection setup.
30
+ * @param endpoint - The URL of the MCP server to connect to
31
+ * @param headers - Optional custom headers to include in requests
32
+ * @returns A connected MCPClient instance ready for use
33
+ * @throws Will throw an error if connection fails
34
+ */
35
+ static create(endpoint: string, transport?: MCPTransport, headers?: Record<string, string>): Promise<MCPClient>;
36
+ /**
37
+ * Retrieves a complete list of all available tools from the MCP server.
38
+ * Handles pagination automatically by following cursors until all tools are fetched.
39
+ * @returns A complete list of all available tools and their descriptions
40
+ * @throws Will throw an error if any server request fails during pagination
41
+ */
42
+ listTools(): Promise<MCPToolSpec[]>;
43
+ /**
44
+ * Calls a specific tool on the MCP server with the provided arguments.
45
+ * @param name - The name of the tool to call
46
+ * @param args - Arguments to pass to the tool, must match the tool's expected schema
47
+ * @returns The result from the tool execution
48
+ * @throws Will throw an error if the tool call fails or if arguments are invalid
49
+ */
50
+ callTool(name: string, args: Record<string, unknown>): Promise<import("zod").objectOutputType<{
51
+ _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
52
+ } & {
53
+ content: import("zod").ZodArray<import("zod").ZodUnion<[import("zod").ZodObject<{
54
+ type: import("zod").ZodLiteral<"text">;
55
+ text: import("zod").ZodString;
56
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
57
+ type: import("zod").ZodLiteral<"text">;
58
+ text: import("zod").ZodString;
59
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
60
+ type: import("zod").ZodLiteral<"text">;
61
+ text: import("zod").ZodString;
62
+ }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
63
+ type: import("zod").ZodLiteral<"image">;
64
+ data: import("zod").ZodString;
65
+ mimeType: import("zod").ZodString;
66
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
67
+ type: import("zod").ZodLiteral<"image">;
68
+ data: import("zod").ZodString;
69
+ mimeType: import("zod").ZodString;
70
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
71
+ type: import("zod").ZodLiteral<"image">;
72
+ data: import("zod").ZodString;
73
+ mimeType: import("zod").ZodString;
74
+ }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
75
+ type: import("zod").ZodLiteral<"audio">;
76
+ data: import("zod").ZodString;
77
+ mimeType: import("zod").ZodString;
78
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
79
+ type: import("zod").ZodLiteral<"audio">;
80
+ data: import("zod").ZodString;
81
+ mimeType: import("zod").ZodString;
82
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
83
+ type: import("zod").ZodLiteral<"audio">;
84
+ data: import("zod").ZodString;
85
+ mimeType: import("zod").ZodString;
86
+ }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
87
+ type: import("zod").ZodLiteral<"resource">;
88
+ resource: import("zod").ZodUnion<[import("zod").ZodObject<import("zod").objectUtil.extendShape<{
89
+ uri: import("zod").ZodString;
90
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
91
+ }, {
92
+ text: import("zod").ZodString;
93
+ }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
94
+ uri: import("zod").ZodString;
95
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
96
+ }, {
97
+ text: import("zod").ZodString;
98
+ }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<import("zod").objectUtil.extendShape<{
99
+ uri: import("zod").ZodString;
100
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
101
+ }, {
102
+ text: import("zod").ZodString;
103
+ }>, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<import("zod").objectUtil.extendShape<{
104
+ uri: import("zod").ZodString;
105
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
106
+ }, {
107
+ blob: import("zod").ZodString;
108
+ }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
109
+ uri: import("zod").ZodString;
110
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
111
+ }, {
112
+ blob: import("zod").ZodString;
113
+ }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<import("zod").objectUtil.extendShape<{
114
+ uri: import("zod").ZodString;
115
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
116
+ }, {
117
+ blob: import("zod").ZodString;
118
+ }>, import("zod").ZodTypeAny, "passthrough">>]>;
119
+ }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
120
+ type: import("zod").ZodLiteral<"resource">;
121
+ resource: import("zod").ZodUnion<[import("zod").ZodObject<import("zod").objectUtil.extendShape<{
122
+ uri: import("zod").ZodString;
123
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
124
+ }, {
125
+ text: import("zod").ZodString;
126
+ }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
127
+ uri: import("zod").ZodString;
128
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
129
+ }, {
130
+ text: import("zod").ZodString;
131
+ }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<import("zod").objectUtil.extendShape<{
132
+ uri: import("zod").ZodString;
133
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
134
+ }, {
135
+ text: import("zod").ZodString;
136
+ }>, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<import("zod").objectUtil.extendShape<{
137
+ uri: import("zod").ZodString;
138
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
139
+ }, {
140
+ blob: import("zod").ZodString;
141
+ }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
142
+ uri: import("zod").ZodString;
143
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
144
+ }, {
145
+ blob: import("zod").ZodString;
146
+ }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<import("zod").objectUtil.extendShape<{
147
+ uri: import("zod").ZodString;
148
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
149
+ }, {
150
+ blob: import("zod").ZodString;
151
+ }>, import("zod").ZodTypeAny, "passthrough">>]>;
152
+ }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
153
+ type: import("zod").ZodLiteral<"resource">;
154
+ resource: import("zod").ZodUnion<[import("zod").ZodObject<import("zod").objectUtil.extendShape<{
155
+ uri: import("zod").ZodString;
156
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
157
+ }, {
158
+ text: import("zod").ZodString;
159
+ }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
160
+ uri: import("zod").ZodString;
161
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
162
+ }, {
163
+ text: import("zod").ZodString;
164
+ }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<import("zod").objectUtil.extendShape<{
165
+ uri: import("zod").ZodString;
166
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
167
+ }, {
168
+ text: import("zod").ZodString;
169
+ }>, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<import("zod").objectUtil.extendShape<{
170
+ uri: import("zod").ZodString;
171
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
172
+ }, {
173
+ blob: import("zod").ZodString;
174
+ }>, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<import("zod").objectUtil.extendShape<{
175
+ uri: import("zod").ZodString;
176
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
177
+ }, {
178
+ blob: import("zod").ZodString;
179
+ }>, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<import("zod").objectUtil.extendShape<{
180
+ uri: import("zod").ZodString;
181
+ mimeType: import("zod").ZodOptional<import("zod").ZodString>;
182
+ }, {
183
+ blob: import("zod").ZodString;
184
+ }>, import("zod").ZodTypeAny, "passthrough">>]>;
185
+ }, import("zod").ZodTypeAny, "passthrough">>]>, "many">;
186
+ isError: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
187
+ }, import("zod").ZodTypeAny, "passthrough"> | import("zod").objectOutputType<{
188
+ _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
189
+ } & {
190
+ toolResult: import("zod").ZodUnknown;
191
+ }, import("zod").ZodTypeAny, "passthrough">>;
192
+ }
193
+ export interface MCPToolSpec {
194
+ name: string;
195
+ description?: string;
196
+ inputSchema?: JSONSchema7;
197
+ }
198
+ //# sourceMappingURL=mcp-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/util/mcp-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AACD;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAqD;IAEtE;;;;;OAKG;IACH,OAAO;IAoBP;;;;;;;;OAQG;WACU,MAAM,CACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,YAAgC,EAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;IAMrB;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAiCzC;;;;;;OAMG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAO3D;AASD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}