@tambo-ai/react 0.64.1 → 0.65.1
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/README.md +304 -327
- package/dist/hooks/use-tambo-threads.d.ts +0 -12
- package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
- package/dist/hooks/use-tambo-threads.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp/__tests__/elicitation.test.js +7 -3
- package/dist/mcp/__tests__/elicitation.test.js.map +1 -1
- package/dist/mcp/__tests__/mcp-hooks.test.js +149 -123
- package/dist/mcp/__tests__/mcp-hooks.test.js.map +1 -1
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js +176 -120
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/dist/mcp/__tests__/use-mcp-servers.test.js +12 -9
- package/dist/mcp/__tests__/use-mcp-servers.test.js.map +1 -1
- package/dist/mcp/elicitation.d.ts +4 -40
- package/dist/mcp/elicitation.d.ts.map +1 -1
- package/dist/mcp/elicitation.js +1 -1
- package/dist/mcp/elicitation.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +2 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts +14 -26
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +4 -7
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/mcp/mcp-hooks.d.ts +27 -78
- package/dist/mcp/mcp-hooks.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.d.ts +27 -45
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +36 -87
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/model/mcp-server-info.d.ts +74 -0
- package/dist/model/mcp-server-info.d.ts.map +1 -0
- package/dist/model/mcp-server-info.js +29 -0
- package/dist/model/mcp-server-info.js.map +1 -0
- package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js +22 -8
- package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/dist/providers/__tests__/tambo-thread-provider.test.js +318 -129
- package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/tambo-client-provider.d.ts +4 -0
- package/dist/providers/tambo-client-provider.d.ts.map +1 -1
- package/dist/providers/tambo-client-provider.js +3 -0
- package/dist/providers/tambo-client-provider.js.map +1 -1
- package/dist/providers/tambo-mcp-token-provider.d.ts +3 -0
- package/dist/providers/tambo-mcp-token-provider.d.ts.map +1 -1
- package/dist/providers/tambo-mcp-token-provider.js +11 -3
- package/dist/providers/tambo-mcp-token-provider.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +1 -0
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +10 -5
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.d.ts +37 -0
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js +162 -2
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/providers/tambo-stubs.d.ts.map +1 -1
- package/dist/providers/tambo-stubs.js +10 -1
- package/dist/providers/tambo-stubs.js.map +1 -1
- package/esm/hooks/use-tambo-threads.d.ts +0 -12
- package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
- package/esm/hooks/use-tambo-threads.js.map +1 -1
- package/esm/index.d.ts +3 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -2
- package/esm/index.js.map +1 -1
- package/esm/mcp/__tests__/elicitation.test.js +8 -4
- package/esm/mcp/__tests__/elicitation.test.js.map +1 -1
- package/esm/mcp/__tests__/mcp-hooks.test.js +149 -123
- package/esm/mcp/__tests__/mcp-hooks.test.js.map +1 -1
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js +178 -122
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/esm/mcp/__tests__/use-mcp-servers.test.js +12 -9
- package/esm/mcp/__tests__/use-mcp-servers.test.js.map +1 -1
- package/esm/mcp/elicitation.d.ts +4 -40
- package/esm/mcp/elicitation.d.ts.map +1 -1
- package/esm/mcp/elicitation.js +2 -2
- package/esm/mcp/elicitation.js.map +1 -1
- package/esm/mcp/index.d.ts +2 -1
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +1 -1
- package/esm/mcp/index.js.map +1 -1
- package/esm/mcp/mcp-client.d.ts +14 -26
- package/esm/mcp/mcp-client.d.ts.map +1 -1
- package/esm/mcp/mcp-client.js +3 -5
- package/esm/mcp/mcp-client.js.map +1 -1
- package/esm/mcp/mcp-hooks.d.ts +27 -78
- package/esm/mcp/mcp-hooks.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.d.ts +27 -45
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +35 -86
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/model/mcp-server-info.d.ts +74 -0
- package/esm/model/mcp-server-info.d.ts.map +1 -0
- package/esm/model/mcp-server-info.js +25 -0
- package/esm/model/mcp-server-info.js.map +1 -0
- package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js +23 -9
- package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/esm/providers/__tests__/tambo-thread-provider.test.js +319 -130
- package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/esm/providers/index.d.ts +1 -1
- package/esm/providers/index.d.ts.map +1 -1
- package/esm/providers/index.js +1 -1
- package/esm/providers/index.js.map +1 -1
- package/esm/providers/tambo-client-provider.d.ts +4 -0
- package/esm/providers/tambo-client-provider.d.ts.map +1 -1
- package/esm/providers/tambo-client-provider.js +3 -0
- package/esm/providers/tambo-client-provider.js.map +1 -1
- package/esm/providers/tambo-mcp-token-provider.d.ts +3 -0
- package/esm/providers/tambo-mcp-token-provider.d.ts.map +1 -1
- package/esm/providers/tambo-mcp-token-provider.js +13 -5
- package/esm/providers/tambo-mcp-token-provider.js.map +1 -1
- package/esm/providers/tambo-provider.d.ts +1 -0
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +11 -6
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.d.ts +37 -0
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js +161 -2
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/providers/tambo-stubs.d.ts.map +1 -1
- package/esm/providers/tambo-stubs.js +10 -1
- package/esm/providers/tambo-stubs.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,+CAOe;AACf,6BAAgC;AAChC,4EAAiD;AAMjD,6EAAkE;AAClE,qEAAgE;AAgBnD,QAAA,oBAAoB,GAAG,IAAA,qBAAa,EAAuB;IACtE,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,yBAAyB,EAAE,EAAE;IAC7B;;OAEG;IACH,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC3B;;OAEG;IACH,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB;;OAEG;IACH,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB;;OAEG;IACH,kBAAkB,EAA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,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,oBAAoB,IAAI,+BAA+B,EACvD,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,qFAAqF;IACrF,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,WAAgB;IACpC,OAAO,CACL,WAAW;QACX,OAAO,WAAW,KAAK,QAAQ;QAC/B,WAAW,CAAC,IAAI,KAAK,QAAQ;QAC7B,WAAW,CAAC,UAAU,CACvB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,GAAG,YAAY,eAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,6CAA6C;IAC7C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,OAAQ,GAAW,CAAC,SAAS,KAAK,UAAU;QAC5C,OAAQ,GAAW,CAAC,IAAI,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { ZodSchema } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\nimport { assertValidName } from \"../util/validate-component-name\";\nimport { assertNoZodRecord } from \"../util/validate-zod-schema\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\nexport const TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: TamboTool[];\n\n /**\n * A function to call when an unknown tool is called. If this function is not\n * provided, an error will be thrown when a tool call is requested by the\n * server.\n *\n * Note that this is generally only for agents, where the agent code may\n * request tool calls that are not registered in the tool registry.\n */\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @param props.tools - The tools to register\n * @param props.onCallUnregisteredTool - The function to call when an unknown tool is called (optional)\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({\n children,\n components: userComponents,\n tools: userTools,\n onCallUnregisteredTool,\n}) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n // Validate tool name\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas\n if (tool.toolSchema && isZodSchema(tool.toolSchema)) {\n assertNoZodRecord(tool.toolSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(tool.name, \"tool\");\n\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolRegistry[tool.name]) {\n throw new Error(`Tool ${tool.name} not found in registry`);\n }\n\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList, toolRegistry],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate component name\n assertValidName(name, \"component\");\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include z.record()\n if (propsSchema && isZodSchema(propsSchema)) {\n assertNoZodRecord(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n useEffect(() => {\n if (userTools) {\n registerTools(userTools, false);\n }\n }, [registerTools, userTools]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n onCallUnregisteredTool,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\nfunction getSerializedProps(\n propsDefinition: any,\n propsSchema: any,\n name: string,\n) {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition;\n }\n\n if (isZodSchema(propsSchema)) {\n try {\n return zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n // try to roughly detect JSONSchema, should always be an object with a properties key\n if (isJSONSchema(propsSchema)) {\n return propsSchema;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Checks if the propsSchema is a JSON Schema. This is a rough check, and the\n * server will provide the definitive check.\n * @param propsSchema - The props schema to check\n * @returns True if the props schema is a JSON Schema, false otherwise\n */\nfunction isJSONSchema(propsSchema: any) {\n return (\n propsSchema &&\n typeof propsSchema === \"object\" &&\n propsSchema.type === \"object\" &&\n propsSchema.properties\n );\n}\n\n/**\n * Since we require a certain zod version, we need to check if the object is a ZodSchema\n * @param obj - The object to check\n * @returns True if the object is a ZodSchema, false otherwise\n */\nfunction isZodSchema(obj: unknown): obj is ZodSchema {\n if (obj instanceof ZodSchema) {\n return true;\n }\n // try to detect if the object is a ZodSchema\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as any).safeParse === \"function\" &&\n typeof (obj as any)._def === \"object\"\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,+CAQe;AACf,6BAAgC;AAChC,4EAAiD;AAMjD,8DAKkC;AAClC,6EAAkE;AAClE,qEAAgE;AAEhE;;;;;GAKG;AACH,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEjC,4BAA4B;QAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAElC,6BAA6B;QAC7B,uDAAuD;QACvD,IAAI,aAAa,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;QAE/B,0EAA0E;QAC1E,IACE,aAAa,CAAC,MAAM,IAAI,CAAC;YACzB,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC;YACnD,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,EACnD,CAAC;YACD,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,sDAAsD;aACjD,IAAI,aAAa,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACnC,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED,yEAAyE;QACzE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KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { ZodSchema } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\nimport {\n getMcpServerUniqueKey,\n McpServerInfo,\n MCPTransport,\n type NormalizedMcpServerInfo,\n} from \"../model/mcp-server-info\";\nimport { assertValidName } from \"../util/validate-component-name\";\nimport { assertNoZodRecord } from \"../util/validate-zod-schema\";\n\n/**\n * Derives a short, meaningful key from a server URL.\n * Strips TLDs and common prefixes to get a human-readable identifier.\n * For example, \"https://mcp.linear.app/mcp\" becomes \"linear\".\n * @returns A lowercased, human-readable key derived from the URL\n */\nfunction deriveServerKey(url: string): string {\n try {\n const parsed = new URL(url);\n const hostname = parsed.hostname;\n\n // Split hostname into parts\n const parts = hostname.split(\".\");\n\n // Remove common TLD patterns\n // Handle cases like: .com, .org, .co.uk, .com.au, etc.\n let relevantParts = [...parts];\n\n // If we have 3+ parts and the last two are short (likely TLD like .co.uk)\n if (\n relevantParts.length >= 3 &&\n relevantParts[relevantParts.length - 1].length <= 3 &&\n relevantParts[relevantParts.length - 2].length <= 3\n ) {\n relevantParts = relevantParts.slice(0, -2);\n }\n // Otherwise just remove the last part (TLD like .com)\n else if (relevantParts.length >= 2) {\n relevantParts = relevantParts.slice(0, -1);\n }\n\n // From what's left, prefer the rightmost part that's not a common prefix\n // Common prefixes: www, api, mcp, app, etc.\n const commonPrefixes = new Set([\n \"www\",\n \"api\",\n \"mcp\",\n \"app\",\n \"staging\",\n \"dev\",\n \"prod\",\n ]);\n\n // Work backwards through the parts to find a meaningful name\n for (let i = relevantParts.length - 1; i >= 0; i--) {\n const part = relevantParts[i];\n if (part && !commonPrefixes.has(part.toLowerCase())) {\n return part.toLowerCase();\n }\n }\n\n // Fallback: use the last relevant part even if it's a common prefix\n return relevantParts[relevantParts.length - 1]?.toLowerCase() || hostname;\n } catch {\n // If URL parsing fails, just return a sanitized version of the input\n return url.replace(/[^a-zA-Z0-9]/g, \"_\").toLowerCase();\n }\n}\n\n/**\n * Normalizes an MCP server info object, ensuring it has a serverKey.\n * If serverKey is not provided, derives it from the URL.\n * @returns The normalized MCP server info object\n */\nfunction normalizeServerInfo(\n server: McpServerInfo | string,\n): NormalizedMcpServerInfo {\n const base: McpServerInfo =\n typeof server === \"string\"\n ? {\n url: server,\n transport: MCPTransport.HTTP,\n }\n : server;\n\n const serverKey = base.serverKey ?? deriveServerKey(base.url);\n const transport = base.transport ?? MCPTransport.HTTP;\n\n return { ...base, transport, serverKey };\n}\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n mcpServerInfos: NormalizedMcpServerInfo[];\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n registerMcpServer: (info: McpServerInfo) => void;\n registerMcpServers: (infos: McpServerInfo[]) => void;\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\nexport const TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n mcpServerInfos: [],\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n /**\n *\n */\n registerMcpServer: () => {},\n /**\n *\n */\n registerMcpServers: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: TamboTool[];\n /** The MCP servers to register */\n mcpServers?: (McpServerInfo | string)[];\n\n /**\n * A function to call when an unknown tool is called. If this function is not\n * provided, an error will be thrown when a tool call is requested by the\n * server.\n *\n * Note that this is generally only for agents, where the agent code may\n * request tool calls that are not registered in the tool registry.\n */\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>;\n}\n\n/**\n * The TamboRegistryProvider is a React provider that provides a component\n * registry to the descendants of the provider.\n * @param props - The props for the TamboRegistryProvider\n * @param props.children - The children to wrap\n * @param props.components - The components to register\n * @param props.tools - The tools to register\n * @param props.mcpServers - The MCP servers to register\n * @param props.onCallUnregisteredTool - The function to call when an unknown tool is called (optional)\n * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({\n children,\n components: userComponents,\n tools: userTools,\n mcpServers: userMcpServers,\n onCallUnregisteredTool,\n}) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n const [staticMcpServerInfos, setStaticMcpServerInfos] = useState<\n NormalizedMcpServerInfo[]\n >([]);\n const [dynamicMcpServerInfos, setDynamicMcpServerInfos] = useState<\n NormalizedMcpServerInfo[]\n >([]);\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n // Validate tool name\n assertValidName(tool.name, \"tool\");\n\n // Validate tool schemas\n if (tool.toolSchema && isZodSchema(tool.toolSchema)) {\n assertNoZodRecord(tool.toolSchema, `toolSchema of tool \"${tool.name}\"`);\n }\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const registerMcpServer = useCallback((info: McpServerInfo | string) => {\n const normalized = normalizeServerInfo(info);\n setDynamicMcpServerInfos((prev) => [...prev, normalized]);\n }, []);\n\n const registerMcpServers = useCallback(\n (infos: (McpServerInfo | string)[]) => {\n const normalized = infos.map(normalizeServerInfo);\n setDynamicMcpServerInfos((prev) => [...prev, ...normalized]);\n },\n [],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n // Validate component and tool names\n assertValidName(componentName, \"component\");\n assertValidName(tool.name, \"tool\");\n\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n if (!toolRegistry[tool.name]) {\n throw new Error(`Tool ${tool.name} not found in registry`);\n }\n\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList, toolRegistry],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate component name\n assertValidName(name, \"component\");\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Validate that the propsSchema does not include z.record()\n if (propsSchema && isZodSchema(propsSchema)) {\n assertNoZodRecord(propsSchema, `propsSchema of component \"${name}\"`);\n }\n\n // Convert propsSchema to JSON Schema if it exists\n const props = getSerializedProps(propsDefinition, propsSchema, name);\n\n setComponentList((prev) => {\n if (prev[name] && warnOnOverwrite) {\n console.warn(`overwriting component ${name}`);\n }\n return {\n ...prev,\n [name]: {\n component,\n loadingComponent,\n name,\n description,\n props,\n contextTools: [],\n },\n };\n });\n if (associatedTools) {\n registerTools(associatedTools);\n setComponentToolAssociations((prev) => ({\n ...prev,\n [name]: associatedTools.map((tool) => tool.name),\n }));\n }\n },\n [registerTools],\n );\n useEffect(() => {\n if (userComponents) {\n userComponents.forEach((component) => {\n registerComponent(component, false);\n });\n }\n }, [registerComponent, userComponents]);\n\n useEffect(() => {\n if (userTools) {\n registerTools(userTools, false);\n }\n }, [registerTools, userTools]);\n\n useEffect(() => {\n if (!userMcpServers || userMcpServers.length === 0) {\n setStaticMcpServerInfos([]);\n return;\n }\n\n // Normalize servers from props and ensure all have serverKey and transport\n const normalized = userMcpServers.map(normalizeServerInfo);\n setStaticMcpServerInfos(normalized);\n }, [userMcpServers]);\n\n const mcpServerInfos: NormalizedMcpServerInfo[] = useMemo(() => {\n const allServers = [...staticMcpServerInfos, ...dynamicMcpServerInfos];\n if (allServers.length === 0) {\n return allServers;\n }\n\n // 1. Deduplicate by connection identity using a stable key\n const byKey = new Map<string, NormalizedMcpServerInfo>();\n for (const server of allServers) {\n const key = getMcpServerUniqueKey(server);\n byKey.set(key, server);\n }\n\n const deduped = Array.from(byKey.values());\n\n // 2. Ensure serverKey uniqueness for readable, unambiguous prefixes\n const seen = new Map<string, number>();\n return deduped.map((server) => {\n const baseKey = server.serverKey;\n const count = (seen.get(baseKey) ?? 0) + 1;\n seen.set(baseKey, count);\n\n if (count === 1) {\n return server;\n }\n\n return {\n ...server,\n serverKey: `${baseKey}-${count}`,\n };\n });\n }, [staticMcpServerInfos, dynamicMcpServerInfos]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n mcpServerInfos,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n registerMcpServer,\n registerMcpServers,\n onCallUnregisteredTool,\n };\n\n return (\n <TamboRegistryContext.Provider value={value}>\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * The useTamboRegistry hook provides access to the component registry\n * to the descendants of the TamboRegistryProvider.\n * @returns The component registry\n */\nexport const useTamboRegistry = () => {\n return useContext(TamboRegistryContext);\n};\n\n/**\n * Hook to access the MCP server metadata from TamboRegistryProvider.\n * This provides access to the registered MCP server configurations (metadata only, not connections).\n *\n * This hook can be used anywhere within the TamboProvider hierarchy to access\n * the list of configured MCP servers without needing to be inside TamboMcpProvider.\n * @returns Array of MCP server metadata\n * @example\n * ```tsx\n * function MyComponent() {\n * const mcpServers = useTamboMcpServerInfos();\n *\n * return (\n * <div>\n * <h3>Configured MCP Servers:</h3>\n * {mcpServers.map((server) => (\n * <div key={server.url}>\n * {server.name || server.url}\n * </div>\n * ))}\n * </div>\n * );\n * }\n * ```\n *\n * The returned objects are `NormalizedMcpServerInfo` instances, meaning both\n * `serverKey` and `transport` are always populated (with `transport`\n * defaulting to HTTP when not explicitly specified).\n */\nexport const useTamboMcpServerInfos = (): NormalizedMcpServerInfo[] => {\n return useContext(TamboRegistryContext).mcpServerInfos;\n};\nfunction getSerializedProps(\n propsDefinition: any,\n propsSchema: any,\n name: string,\n) {\n if (propsDefinition) {\n console.warn(`propsDefinition is deprecated. Use propsSchema instead.`);\n return propsDefinition;\n }\n\n if (isZodSchema(propsSchema)) {\n try {\n return zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\n // try to roughly detect JSONSchema, should always be an object with a properties key\n if (isJSONSchema(propsSchema)) {\n return propsSchema;\n }\n\n throw new Error(`Invalid props schema for ${name}`);\n}\n\n/**\n * Checks if the propsSchema is a JSON Schema. This is a rough check, and the\n * server will provide the definitive check.\n * @param propsSchema - The props schema to check\n * @returns True if the props schema is a JSON Schema, false otherwise\n */\nfunction isJSONSchema(propsSchema: any) {\n return (\n propsSchema &&\n typeof propsSchema === \"object\" &&\n propsSchema.type === \"object\" &&\n propsSchema.properties\n );\n}\n\n/**\n * Since we require a certain zod version, we need to check if the object is a ZodSchema\n * @param obj - The object to check\n * @returns True if the object is a ZodSchema, false otherwise\n */\nfunction isZodSchema(obj: unknown): obj is ZodSchema {\n if (obj instanceof ZodSchema) {\n return true;\n }\n // try to detect if the object is a ZodSchema\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as any).safeParse === \"function\" &&\n typeof (obj as any)._def === \"object\"\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD,OAAO,EAEL,gCAAgC,EACjC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAQ1B;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACxE,2CAA2C;IAC3C,MAAM,EAAE,WAAW,CAAC;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,mDAAmD;IACnD,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9D,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;CACrE;
|
|
1
|
+
{"version":3,"file":"tambo-stubs.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD,OAAO,EAEL,gCAAgC,EACjC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAQ1B;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACxE,2CAA2C;IAC3C,MAAM,EAAE,WAAW,CAAC;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,mDAAmD;IACnD,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9D,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;CACrE;AAqKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,CAsH1C,CAAC"}
|
|
@@ -60,7 +60,13 @@ const TamboStubClientProvider = ({ children, client, queryClient, threads, proje
|
|
|
60
60
|
queryClient.setQueryData(["threads", projectId, contextKey], threads);
|
|
61
61
|
}
|
|
62
62
|
}, [threads, projectId, contextKey, queryClient]);
|
|
63
|
-
return (react_1.default.createElement(tambo_client_provider_1.TamboClientContext.Provider, { value: {
|
|
63
|
+
return (react_1.default.createElement(tambo_client_provider_1.TamboClientContext.Provider, { value: {
|
|
64
|
+
client,
|
|
65
|
+
queryClient,
|
|
66
|
+
isUpdatingToken,
|
|
67
|
+
mcpAccessToken: null,
|
|
68
|
+
setMcpAccessToken: () => { },
|
|
69
|
+
} }, children));
|
|
64
70
|
};
|
|
65
71
|
/**
|
|
66
72
|
* Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props
|
|
@@ -71,10 +77,13 @@ const TamboStubRegistryProvider = ({ children, componentList, toolRegistry, comp
|
|
|
71
77
|
componentList,
|
|
72
78
|
toolRegistry,
|
|
73
79
|
componentToolAssociations,
|
|
80
|
+
mcpServerInfos: [],
|
|
74
81
|
registerComponent,
|
|
75
82
|
registerTool,
|
|
76
83
|
registerTools,
|
|
77
84
|
addToolAssociation,
|
|
85
|
+
registerMcpServer: () => { },
|
|
86
|
+
registerMcpServers: () => { },
|
|
78
87
|
} }, children));
|
|
79
88
|
};
|
|
80
89
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,uDAAoD;AACpD,+CAA4D;AAE5D,sFAAuE;AAEvE,mEAA6D;AAC7D,yEAGoC;AACpC,2FAAqF;AACrF,qFAG0C;AAC1C,+EAA0E;AAC1E,qDAG0B;AAC1B,uEAAiE;AACjE,mEAIiC;AAsBjC;;;GAGG;AACH,MAAM,uBAAuB,GASzB,CAAC,EACH,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,eAAe,GAChB,EAAE,EAAE;IACH,4DAA4D;IAC5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,CAAC;YACZ,kCAAkC;YACl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,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa;QAChE,kBAAkB,EAChB,SAAS,CAAC,kBAAkB,IAAI,QAAQ,CAAC,kBAAkB;KAC9D,CAAC;IAEF,OAAO,CACL,8BAAC,uBAAuB,IACtB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,KAAK;QAEtB,8BAAC,yBAAyB,IACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,yBAAyB,EAAE,yBAAyB,EACpD,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,EAC1D,YAAY,EAAE,qBAAqB,CAAC,YAAY,EAChD,aAAa,EAAE,qBAAqB,CAAC,aAAa,EAClD,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;YAE5D,8BAAC,uBAAuB,OAAK,kBAAkB;gBAC7C,8BAAC,4DAA2B,IAAC,cAAc,EAAE,cAAc;oBACzD,8BAAC,kEAA8B;wBAC7B,8BAAC,iDAAsB;4BACrB,8BAAC,uDAAyB;gCACxB,8BAAC,uCAAsB,QAAE,QAAQ,CAA0B,CACjC,CACL,CACM,CACL,CACN,CACA,CACJ,CAC3B,CAAC;AACJ,CAAC,CAAC;AAvHW,QAAA,iBAAiB,qBAuH5B","sourcesContent":["\"use client\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport { TamboContextAttachmentProvider } from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport { TamboInteractableProvider } from \"./tambo-interactable-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboGenerationStageProvider,\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n isUpdatingToken: boolean;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({\n children,\n client,\n queryClient,\n threads,\n projectId,\n contextKey,\n isUpdatingToken,\n}) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider\n value={{ client, queryClient, isUpdatingToken }}\n >\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n // Extract generation stage info from the thread\n const generationStage =\n (threadContextProps.thread?.generationStage as GenerationStage) ??\n GenerationStage.IDLE;\n const statusMessage = threadContextProps.thread?.statusMessage ?? \"\";\n\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n <TamboGenerationStageProvider\n generationStage={generationStage}\n statusMessage={statusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n streaming: overrides.streaming ?? true,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n isUpdatingToken={false}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-stubs.js","sourceRoot":"","sources":["../../src/providers/tambo-stubs.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,uDAAoD;AACpD,+CAA4D;AAE5D,sFAAuE;AAEvE,mEAA6D;AAC7D,yEAGoC;AACpC,2FAAqF;AACrF,qFAG0C;AAC1C,+EAA0E;AAC1E,qDAG0B;AAC1B,uEAAiE;AACjE,mEAIiC;AAsBjC;;;GAGG;AACH,MAAM,uBAAuB,GASzB,CAAC,EACH,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP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typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { PropsWithChildren, useEffect } from \"react\";\nimport { TamboComponent, TamboTool } from \"../model/component-metadata\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { TamboThread } from \"../model/tambo-thread\";\nimport { TamboClientContext } from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n} from \"./tambo-component-provider\";\nimport { TamboContextAttachmentProvider } from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n} from \"./tambo-context-helpers-provider\";\nimport { TamboInteractableProvider } from \"./tambo-interactable-provider\";\nimport {\n TamboCompositeProvider,\n type TamboContextProps,\n} from \"./tambo-provider\";\nimport { TamboRegistryContext } from \"./tambo-registry-provider\";\nimport {\n TamboGenerationStageProvider,\n TamboThreadContext,\n TamboThreadContextProps,\n} from \"./tambo-thread-provider\";\n\n/**\n * TamboStubProvider props - includes all the data that would normally be inferred\n */\nexport interface TamboStubProviderProps extends Partial<TamboContextProps> {\n /** Required: The thread data to display */\n thread: TamboThread;\n /** Optional: Components registry - defaults to empty */\n components?: TamboComponent[];\n /** Optional: Tools registry - defaults to empty */\n tools?: TamboTool[];\n /** Optional: Threads data to populate thread list - overrides useTamboThreadList() */\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n /** Optional: Project ID to use for query cache - defaults to thread.projectId */\n projectId?: string;\n /** Optional: Context key for thread list queries */\n contextKey?: string;\n /** Optional: Configuration for which context helpers are enabled/disabled */\n contextHelpers?: TamboContextHelpersProviderProps[\"contextHelpers\"];\n}\n\n/**\n * Stub client provider that accepts a client and queryClient as props\n * @returns The TamboStubClientProvider component\n */\nconst TamboStubClientProvider: React.FC<\n PropsWithChildren<{\n client: TamboAI;\n queryClient: QueryClient;\n isUpdatingToken: boolean;\n threads?: Partial<TamboAI.Beta.Threads.ThreadsOffsetAndLimit>;\n projectId?: string;\n contextKey?: string;\n }>\n> = ({\n children,\n client,\n queryClient,\n threads,\n projectId,\n contextKey,\n isUpdatingToken,\n}) => {\n // Prepopulate the query cache with threads data if provided\n useEffect(() => {\n if (threads) {\n // Set the project ID in the cache\n queryClient.setQueryData([\"projectId\"], projectId);\n\n // Set the threads data in the cache using the same query key pattern as useTamboThreadList\n queryClient.setQueryData([\"threads\", projectId, contextKey], threads);\n }\n }, [threads, projectId, contextKey, queryClient]);\n\n return (\n <TamboClientContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n mcpAccessToken: null,\n setMcpAccessToken: () => {},\n }}\n >\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * Stub registry provider that accepts componentList, toolRegistry, and componentToolAssociations as props\n * @returns The TamboStubRegistryProvider component\n */\nconst TamboStubRegistryProvider: React.FC<\n PropsWithChildren<{\n componentList: Record<string, any>;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n }>\n> = ({\n children,\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n}) => {\n return (\n <TamboRegistryContext.Provider\n value={{\n componentList,\n toolRegistry,\n componentToolAssociations,\n mcpServerInfos: [],\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n registerMcpServer: () => {},\n registerMcpServers: () => {},\n }}\n >\n {children}\n </TamboRegistryContext.Provider>\n );\n};\n\n/**\n * Stub thread provider that accepts all thread context props\n * @returns The TamboStubThreadProvider component\n */\nconst TamboStubThreadProvider: React.FC<\n PropsWithChildren<TamboThreadContextProps>\n> = ({ children, ...threadContextProps }) => {\n // Extract generation stage info from the thread\n const generationStage =\n (threadContextProps.thread?.generationStage as GenerationStage) ??\n GenerationStage.IDLE;\n const statusMessage = threadContextProps.thread?.statusMessage ?? \"\";\n\n return (\n <TamboThreadContext.Provider value={threadContextProps}>\n <TamboGenerationStageProvider\n generationStage={generationStage}\n statusMessage={statusMessage}\n >\n {children}\n </TamboGenerationStageProvider>\n </TamboThreadContext.Provider>\n );\n};\n\n/**\n * Default no-op functions that throw errors - used when callbacks are not provided\n * @returns The default callbacks\n */\nconst createDefaultCallbacks = () => ({\n switchCurrentThread: () => {\n throw new Error(\"switchCurrentThread not implemented in stub\");\n },\n startNewThread: () => {\n throw new Error(\"startNewThread not implemented in stub\");\n },\n updateThreadName: () => {\n throw new Error(\"updateThreadName not implemented in stub\");\n },\n generateThreadName: () => {\n throw new Error(\"generateThreadName not implemented in stub\");\n },\n addThreadMessage: () => {\n throw new Error(\"addThreadMessage not implemented in stub\");\n },\n updateThreadMessage: () => {\n throw new Error(\"updateThreadMessage not implemented in stub\");\n },\n setInputValue: () => {\n throw new Error(\"setInputValue not implemented in stub\");\n },\n sendThreadMessage: () => {\n throw new Error(\"sendThreadMessage not implemented in stub\");\n },\n registerComponent: () => {\n throw new Error(\"registerComponent not implemented in stub\");\n },\n registerTool: () => {\n throw new Error(\"registerTool not implemented in stub\");\n },\n registerTools: () => {\n throw new Error(\"registerTools not implemented in stub\");\n },\n addToolAssociation: () => {\n throw new Error(\"addToolAssociation not implemented in stub\");\n },\n cancel: () => {\n throw new Error(\"cancel not implemented in stub\");\n },\n});\n\n/**\n * The TamboStubProvider provides a way to use the Tambo API with static/stub data.\n * This is useful for testing, samples, and static UI development.\n *\n * Unlike TamboProvider, all data must be provided as props rather than being inferred.\n * @example\n * ```tsx\n * import { TamboStubProvider } from '@tambo-ai/react-sdk';\n *\n * const exampleThread = {\n * id: \"example-thread\",\n * messages: [\n * {\n * id: \"msg-1\",\n * role: \"user\",\n * content: [{ type: \"text\", text: \"Hello!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * },\n * {\n * id: \"msg-2\",\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hi there!\" }],\n * createdAt: new Date().toISOString(),\n * threadId: \"example-thread\",\n * componentState: {},\n * }\n * ],\n * createdAt: new Date().toISOString(),\n * projectId: \"example-project\",\n * updatedAt: new Date().toISOString(),\n * metadata: {},\n * };\n *\n * const exampleThreadList = [exampleThread];\n *\n * function MyComponent() {\n * return (\n * <TamboStubProvider\n * thread={exampleThread}\n * components={[]}\n * tools={[]}\n * threads={exampleThreadList}\n * projectId=\"example-project\"\n * >\n * <MessageThreadFull />\n * </TamboStubProvider>\n * );\n * }\n * ```\n * @param props - The props for the TamboStubProvider\n * @param props.children - The children to wrap\n * @param props.thread - The thread data to display\n * @param props.components - Optional components registry\n * @param props.tools - Optional tools registry\n * @param props.threads - Optional threads data to populate thread list (overrides useTamboThreadList)\n * @param props.projectId - Optional project ID for query cache (defaults to thread.projectId)\n * @param props.contextKey - Optional context key for thread list queries\n * @param props.contextHelpers - Optional configuration for which context helpers are enabled/disabled\n * @returns The TamboStubProvider component\n */\nexport const TamboStubProvider: React.FC<\n PropsWithChildren<TamboStubProviderProps>\n> = ({\n children,\n thread,\n components = [],\n tools = [],\n threads,\n projectId,\n contextKey,\n contextHelpers,\n ...overrides\n}) => {\n const defaults = createDefaultCallbacks();\n\n // Create stub client and queryClient\n const stubClient = {} as TamboAI;\n const stubQueryClient = new QueryClient();\n\n // Use provided projectId or fall back to thread's projectId\n const resolvedProjectId = projectId ?? thread.projectId;\n\n // Build component registry from components prop\n const componentList = components.reduce(\n (acc, component) => {\n acc[component.name] = {\n component: component.component,\n loadingComponent: component.loadingComponent,\n name: component.name,\n description: component.description,\n props: component.propsDefinition ?? {},\n contextTools: [],\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n // Build tool registry from tools prop\n const toolRegistry = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n },\n {} as Record<string, TamboTool>,\n );\n\n // Build tool associations from components\n const componentToolAssociations = components.reduce(\n (acc, component) => {\n if (component.associatedTools) {\n acc[component.name] = component.associatedTools.map(\n (tool) => tool.name,\n );\n }\n return acc;\n },\n {} as Record<string, string[]>,\n );\n\n // Merge defaults with provided overrides\n const threadContextProps: TamboThreadContextProps = {\n thread,\n switchCurrentThread:\n overrides.switchCurrentThread ?? defaults.switchCurrentThread,\n startNewThread: overrides.startNewThread ?? defaults.startNewThread,\n updateThreadName: overrides.updateThreadName ?? defaults.updateThreadName,\n generateThreadName:\n overrides.generateThreadName ?? defaults.generateThreadName,\n addThreadMessage: overrides.addThreadMessage ?? defaults.addThreadMessage,\n updateThreadMessage:\n overrides.updateThreadMessage ?? defaults.updateThreadMessage,\n streaming: overrides.streaming ?? true,\n sendThreadMessage:\n overrides.sendThreadMessage ?? defaults.sendThreadMessage,\n cancel: overrides.cancel ?? defaults.cancel,\n };\n\n const componentContextProps: TamboComponentContextProps = {\n registerComponent:\n overrides.registerComponent ?? defaults.registerComponent,\n registerTool: overrides.registerTool ?? defaults.registerTool,\n registerTools: overrides.registerTools ?? defaults.registerTools,\n addToolAssociation:\n overrides.addToolAssociation ?? defaults.addToolAssociation,\n };\n\n return (\n <TamboStubClientProvider\n client={stubClient}\n queryClient={stubQueryClient}\n threads={threads}\n projectId={resolvedProjectId}\n contextKey={contextKey}\n isUpdatingToken={false}\n >\n <TamboStubRegistryProvider\n componentList={componentList}\n toolRegistry={toolRegistry}\n componentToolAssociations={componentToolAssociations}\n registerComponent={componentContextProps.registerComponent}\n registerTool={componentContextProps.registerTool}\n registerTools={componentContextProps.registerTools}\n addToolAssociation={componentContextProps.addToolAssociation}\n >\n <TamboStubThreadProvider {...threadContextProps}>\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboContextHelpersProvider>\n </TamboStubThreadProvider>\n </TamboStubRegistryProvider>\n </TamboStubClientProvider>\n );\n};\n"]}
|
|
@@ -12,18 +12,6 @@ interface UseTamboThreadListConfig {
|
|
|
12
12
|
*/
|
|
13
13
|
contextKey?: string;
|
|
14
14
|
}
|
|
15
|
-
interface UseTamboThreadListConfig {
|
|
16
|
-
/**
|
|
17
|
-
* The projectId to get the threads for. If not provided, the current project
|
|
18
|
-
* will be used.
|
|
19
|
-
*/
|
|
20
|
-
projectId?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The context key to get the threads for. If not provided, all threads for
|
|
23
|
-
* the project will be returned.
|
|
24
|
-
*/
|
|
25
|
-
contextKey?: string;
|
|
26
|
-
}
|
|
27
15
|
/**
|
|
28
16
|
* Get all the threads for the specified project.
|
|
29
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED
|
|
1
|
+
{"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,SAAS,EAAE,UAAU,EAAE,GAAE,wBAA6B,EACxD,OAAO,GAAE,OAAO,CACd,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-tambo-threads.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAepD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,EAAE,SAAS,EAAE,UAAU,KAA+B,EAAE,EACxD,UAEI,EAAE;IAEN,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,GAAG,aAAa,CAAC;QAClE,GAAI,OAA8C;QAClD,QAAQ,EAAE,CAAC,WAAW,CAAC;QACvB,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC;QACtD,CAAC;KACF,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,SAAS,IAAI,gBAAgB,CAAC;IAEvD,MAAM,WAAW,GAAG,aAAa,CAAC;QAChC,GAAG,OAAO;QACV,OAAO,EAAE,CAAC,CAAC,gBAAgB;QAC3B,QAAQ,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,CAAC;QACnD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAClE,UAAU;aACX,CAAC,CAAC;YACH,OAAO,UAAU,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import type TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { UseQueryOptions } from \"@tanstack/react-query\";\nimport { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTamboQuery } from \"./react-query-hooks\";\n\ninterface UseTamboThreadListConfig {\n /**\n * The projectId to get the threads for. If not provided, the current project\n * will be used.\n */\n projectId?: string;\n /**\n * The context key to get the threads for. If not provided, all threads for\n * the project will be returned.\n */\n contextKey?: string;\n}\n\n/**\n * Get all the threads for the specified project.\n *\n * If contextKey is empty, then all threads for the project will be returned.\n * If contextKey is not empty, then only the threads for the specified context\n * key will be returned.\n * @param config - The config for the useTamboThreadList hook\n * @param config.projectId - The projectId to get the threads for\n * @param config.contextKey - The context key to get the threads for\n * @returns The threads for the specified project and optional context key\n */\nexport function useTamboThreadList(\n { projectId, contextKey }: UseTamboThreadListConfig = {},\n options: Partial<\n UseQueryOptions<TamboAI.Beta.Threads.ThreadsOffsetAndLimit | null>\n > = {},\n) {\n const client = useTamboClient();\n const { data: queriedProjectId, ...projectIdState } = useTamboQuery({\n ...(options as unknown as UseQueryOptions<string>),\n queryKey: [\"projectId\"],\n queryFn: async () => {\n return (await client.beta.projects.getCurrent()).id;\n },\n });\n const currentProjectId = projectId ?? queriedProjectId;\n\n const threadState = useTamboQuery({\n ...options,\n enabled: !!currentProjectId,\n queryKey: [\"threads\", currentProjectId, contextKey],\n queryFn: async () => {\n if (!currentProjectId) {\n return null;\n }\n const threadIter = await client.beta.threads.list(currentProjectId, {\n contextKey,\n });\n return threadIter;\n },\n });\n\n return currentProjectId ? threadState : { data: null, ...projectIdState };\n}\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { useTamboStreamingProps } from "./hooks/use-streaming-props";
|
|
|
6
6
|
export * from "./hooks/use-suggestions";
|
|
7
7
|
export { useTamboStreamStatus, type PropStatus, type StreamStatus, } from "./hooks/use-tambo-stream-status";
|
|
8
8
|
export { useTamboVoice } from "./hooks/use-tambo-voice";
|
|
9
|
-
export { TamboClientProvider, TamboComponentProvider, TamboContextAttachmentProvider, TamboContextHelpersProvider, TamboPropStreamProvider, TamboProvider, TamboStubProvider, TamboThreadInputProvider, TamboThreadProvider, useIsTamboTokenUpdating, useTambo, useTamboClient, useTamboContextAttachment, useTamboContextHelpers, useTamboGenerationStage, useTamboStream, useTamboThread, useTamboThreadInput, type ContextAttachment, type ContextAttachmentState, type ContextHelperData, type TamboComponent, type TamboContextAttachmentProviderProps, type TamboContextHelpersContextProps, type TamboContextHelpersProviderProps, type TamboRegistryContext, type TamboStubProviderProps, type TamboThreadInputContextProps, type TamboThreadProviderProps, } from "./providers";
|
|
9
|
+
export { TamboClientProvider, TamboComponentProvider, TamboContextAttachmentProvider, TamboContextHelpersProvider, TamboPropStreamProvider, TamboProvider, TamboRegistryProvider, TamboStubProvider, TamboThreadInputProvider, TamboThreadProvider, useIsTamboTokenUpdating, useTambo, useTamboClient, useTamboContextAttachment, useTamboContextHelpers, useTamboGenerationStage, useTamboMcpServerInfos, useTamboStream, useTamboThread, useTamboThreadInput, type ContextAttachment, type ContextAttachmentState, type ContextHelperData, type TamboComponent, type TamboContextAttachmentProviderProps, type TamboContextHelpersContextProps, type TamboContextHelpersProviderProps, type TamboRegistryContext, type TamboStubProviderProps, type TamboThreadInputContextProps, type TamboThreadProviderProps, } from "./providers";
|
|
10
10
|
export type { APIError, RateLimitError, TamboAIError, } from "@tambo-ai/typescript-sdk";
|
|
11
11
|
export type { Suggestion, SuggestionGenerateParams, SuggestionGenerateResponse, SuggestionListResponse, } from "@tambo-ai/typescript-sdk/resources/beta/threads/suggestions";
|
|
12
12
|
export { useTamboThreadList } from "./hooks/use-tambo-threads";
|
|
@@ -19,4 +19,6 @@ export { withTamboInteractable as withInteractable, type InteractableConfig, typ
|
|
|
19
19
|
export { useCurrentInteractablesSnapshot, useTamboInteractable, } from "./providers/tambo-interactable-provider";
|
|
20
20
|
export { currentPageContextHelper, currentTimeContextHelper, } from "./context-helpers";
|
|
21
21
|
export type { AdditionalContext, ContextHelperFn, ContextHelpers, } from "./context-helpers";
|
|
22
|
+
export type { McpServerInfo, NormalizedMcpServerInfo, } from "./model/mcp-server-info";
|
|
23
|
+
export { MCPTransport } from "./model/mcp-server-info";
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAC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rB,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,KAAK,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAEnF,YAAY,EACV,0BAA0B,IAAI,qBAAqB,EACnD,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,IAAI,gBAAgB,EACzC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,GAChC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACV,aAAa,EACb,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -7,13 +7,14 @@ export * from "./hooks/use-suggestions";
|
|
|
7
7
|
export { useTamboStreamStatus, } from "./hooks/use-tambo-stream-status";
|
|
8
8
|
export { useTamboVoice } from "./hooks/use-tambo-voice";
|
|
9
9
|
// Re-export provider components
|
|
10
|
-
export { TamboClientProvider, TamboComponentProvider, TamboContextAttachmentProvider, TamboContextHelpersProvider, TamboPropStreamProvider, TamboProvider, TamboStubProvider, TamboThreadInputProvider, TamboThreadProvider, useIsTamboTokenUpdating, useTambo, useTamboClient, useTamboContextAttachment, useTamboContextHelpers, useTamboGenerationStage, useTamboStream, useTamboThread, useTamboThreadInput, } from "./providers";
|
|
10
|
+
export { TamboClientProvider, TamboComponentProvider, TamboContextAttachmentProvider, TamboContextHelpersProvider, TamboPropStreamProvider, TamboProvider, TamboRegistryProvider, TamboStubProvider, TamboThreadInputProvider, TamboThreadProvider, useIsTamboTokenUpdating, useTambo, useTamboClient, useTamboContextAttachment, useTamboContextHelpers, useTamboGenerationStage, useTamboMcpServerInfos, useTamboStream, useTamboThread, useTamboThreadInput, } from "./providers";
|
|
11
11
|
export { useTamboThreadList } from "./hooks/use-tambo-threads";
|
|
12
12
|
export { GenerationStage, } from "./model/generate-component-response";
|
|
13
13
|
export { withTamboInteractable as withInteractable, } from "./providers/hoc/with-tambo-interactable";
|
|
14
14
|
export { useCurrentInteractablesSnapshot, useTamboInteractable, } from "./providers/tambo-interactable-provider";
|
|
15
15
|
// Context helpers exports
|
|
16
16
|
export { currentPageContextHelper, currentTimeContextHelper, } from "./context-helpers";
|
|
17
|
-
|
|
17
|
+
export { MCPTransport } from "./model/mcp-server-info";
|
|
18
|
+
// Note: Full MCP exports like TamboMcpProvider are available separately in the
|
|
18
19
|
// @tambo-ai/react/mcp package
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AAExK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAA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EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,2BAA2B,EAC3B,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,QAAQ,EACR,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,mBAAmB,GAYpB,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC;AAQ7C,OAAO,EACL,qBAAqB,IAAI,gBAAgB,GAG1C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,yCAAyC,CAAC;AAEjD,0BAA0B;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,+EAA+E;AAC/E,8BAA8B","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. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n} from \"./hooks/use-current-message\";\nexport { useMessageImages, type StagedImage } from \"./hooks/use-message-images\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\nexport { useTamboVoice } from \"./hooks/use-tambo-voice\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextAttachmentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboRegistryProvider,\n TamboStubProvider,\n TamboThreadInputProvider,\n TamboThreadProvider,\n useIsTamboTokenUpdating,\n useTambo,\n useTamboClient,\n useTamboContextAttachment,\n useTamboContextHelpers,\n useTamboGenerationStage,\n useTamboMcpServerInfos,\n useTamboStream,\n useTamboThread,\n useTamboThreadInput,\n type ContextAttachment,\n type ContextAttachmentState,\n type ContextHelperData,\n type TamboComponent,\n type TamboContextAttachmentProviderProps,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n type TamboThreadInputContextProps,\n type TamboThreadProviderProps,\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 { type InitialTamboThreadMessage } from \"./providers/tambo-thread-provider\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport {\n useCurrentInteractablesSnapshot,\n useTamboInteractable,\n} from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n\n// MCP server metadata types (used by TamboProvider / registry / MCP provider)\nexport type {\n McpServerInfo,\n NormalizedMcpServerInfo,\n} from \"./model/mcp-server-info\";\nexport { MCPTransport } from \"./model/mcp-server-info\";\n\n// Note: Full MCP exports like TamboMcpProvider are available separately in the\n// @tambo-ai/react/mcp package\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
2
|
import { useElicitation, } from "../elicitation";
|
|
3
3
|
// Create a mock RequestHandlerExtra for testing
|
|
4
4
|
function createMockExtra() {
|
|
@@ -28,6 +28,7 @@ describe("useElicitation", () => {
|
|
|
28
28
|
it("sets elicitation state when called", async () => {
|
|
29
29
|
const { result } = renderHook(() => useElicitation());
|
|
30
30
|
const request = {
|
|
31
|
+
method: "elicitation/create",
|
|
31
32
|
params: {
|
|
32
33
|
message: "Please provide your name",
|
|
33
34
|
requestedSchema: {
|
|
@@ -64,6 +65,7 @@ describe("useElicitation", () => {
|
|
|
64
65
|
it("resolves promise when resolveElicitation is called with accept", async () => {
|
|
65
66
|
const { result } = renderHook(() => useElicitation());
|
|
66
67
|
const request = {
|
|
68
|
+
method: "elicitation/create",
|
|
67
69
|
params: {
|
|
68
70
|
message: "Enter your email",
|
|
69
71
|
requestedSchema: {
|
|
@@ -99,6 +101,7 @@ describe("useElicitation", () => {
|
|
|
99
101
|
it("resolves promise when resolveElicitation is called with decline", async () => {
|
|
100
102
|
const { result } = renderHook(() => useElicitation());
|
|
101
103
|
const request = {
|
|
104
|
+
method: "elicitation/create",
|
|
102
105
|
params: {
|
|
103
106
|
message: "Provide input",
|
|
104
107
|
requestedSchema: {
|
|
@@ -126,6 +129,7 @@ describe("useElicitation", () => {
|
|
|
126
129
|
it("resolves promise when resolveElicitation is called with cancel", async () => {
|
|
127
130
|
const { result } = renderHook(() => useElicitation());
|
|
128
131
|
const request = {
|
|
132
|
+
method: "elicitation/create",
|
|
129
133
|
params: {
|
|
130
134
|
message: "Provide input",
|
|
131
135
|
requestedSchema: {
|
|
@@ -154,6 +158,7 @@ describe("useElicitation", () => {
|
|
|
154
158
|
const { result } = renderHook(() => useElicitation());
|
|
155
159
|
// First elicitation
|
|
156
160
|
const request1 = {
|
|
161
|
+
method: "elicitation/create",
|
|
157
162
|
params: {
|
|
158
163
|
message: "First request",
|
|
159
164
|
requestedSchema: {
|
|
@@ -183,13 +188,12 @@ describe("useElicitation", () => {
|
|
|
183
188
|
});
|
|
184
189
|
// Second elicitation
|
|
185
190
|
const request2 = {
|
|
191
|
+
method: "elicitation/create",
|
|
186
192
|
params: {
|
|
187
193
|
message: "Second request",
|
|
188
194
|
requestedSchema: {
|
|
189
195
|
type: "object",
|
|
190
|
-
properties: {
|
|
191
|
-
field2: { type: "number" },
|
|
192
|
-
},
|
|
196
|
+
properties: { field2: { type: "number" } },
|
|
193
197
|
},
|
|
194
198
|
},
|
|
195
199
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elicitation.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/elicitation.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,cAAc,GAGf,MAAM,gBAAgB,CAAC;AAOxB,gDAAgD;AAChD,SAAS,eAAe;IAItB,OAAO;QACL,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QACpC,SAAS,EAAE,iBAAiB;QAE5B,gBAAgB,EAAE,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAQ;QAEzC,WAAW,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAQ;KAClD,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,EA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,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, act } from \"@testing-library/react\";\nimport {\n useElicitation,\n type TamboElicitationRequest,\n type TamboElicitationResponse,\n} from \"../elicitation\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n ClientNotification,\n ClientRequest,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n// Create a mock RequestHandlerExtra for testing\nfunction createMockExtra(): RequestHandlerExtra<\n ClientRequest,\n ClientNotification\n> {\n return {\n signal: new AbortController().signal,\n requestId: \"test-request-id\",\n\n sendNotification: (async () => {}) as any,\n\n sendRequest: (async () => ({ _meta: {} })) as any,\n };\n}\n\ndescribe(\"useElicitation\", () => {\n it(\"initializes with null state\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(result.current.elicitation).toBeNull();\n expect(result.current.resolveElicitation).toBeNull();\n });\n\n it(\"provides state setters\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(typeof result.current.setElicitation).toBe(\"function\");\n expect(typeof result.current.setResolveElicitation).toBe(\"function\");\n });\n\n it(\"provides a default elicitation handler\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(typeof result.current.defaultElicitationHandler).toBe(\"function\");\n });\n\n describe(\"defaultElicitationHandler\", () => {\n it(\"sets elicitation state when called\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Please provide your name\",\n requestedSchema: {\n type: \"object\",\n properties: {\n name: { type: \"string\", description: \"Your name\" },\n },\n required: [\"name\"],\n },\n },\n };\n\n // Start the handler but don't await yet\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n // Elicitation should be set\n expect(result.current.elicitation).toEqual({\n message: \"Please provide your name\",\n requestedSchema: request.params.requestedSchema,\n signal: extra.signal,\n });\n\n // Resolve callback should be set\n expect(result.current.resolveElicitation).not.toBeNull();\n\n // Clean up by resolving\n act(() => {\n result.current.resolveElicitation?.({\n action: \"cancel\",\n });\n });\n\n await handlerPromise!;\n });\n\n it(\"resolves promise when resolveElicitation is called with accept\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Enter your email\",\n requestedSchema: {\n type: \"object\",\n properties: {\n email: {\n type: \"string\",\n format: \"email\",\n description: \"Email address\",\n },\n },\n },\n },\n };\n\n // Start the handler\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n // Resolve with accept\n const response: TamboElicitationResponse = {\n action: \"accept\",\n content: { email: \"test@example.com\" },\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n // Wait for promise to resolve\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"resolves promise when resolveElicitation is called with decline\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Provide input\",\n requestedSchema: {\n type: \"object\",\n properties: {\n value: { type: \"string\" },\n },\n },\n },\n };\n\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n const response: TamboElicitationResponse = {\n action: \"decline\",\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"resolves promise when resolveElicitation is called with cancel\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Provide input\",\n requestedSchema: {\n type: \"object\",\n properties: {\n value: { type: \"string\" },\n },\n },\n },\n };\n\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n const response: TamboElicitationResponse = {\n action: \"cancel\",\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"handles multiple sequential elicitations\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n // First elicitation\n const request1: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"First request\",\n requestedSchema: {\n type: \"object\",\n properties: {\n field1: { type: \"string\" },\n },\n },\n },\n };\n\n let promise1: Promise<TamboElicitationResponse>;\n const extra1 = createMockExtra();\n act(() => {\n promise1 = result.current.defaultElicitationHandler(request1, extra1);\n });\n\n expect(result.current.elicitation?.message).toBe(\"First request\");\n\n act(() => {\n result.current.resolveElicitation?.({\n action: \"accept\",\n content: { field1: \"value1\" },\n });\n });\n\n const result1 = await promise1!;\n expect(result1).toEqual({\n action: \"accept\",\n content: { field1: \"value1\" },\n });\n\n // Second elicitation\n const request2: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Second request\",\n requestedSchema: {\n type: \"object\",\n properties: {\n field2: { type: \"number\" },\n },\n },\n },\n };\n\n let promise2: Promise<TamboElicitationResponse>;\n const extra2 = createMockExtra();\n act(() => {\n promise2 = result.current.defaultElicitationHandler(request2, extra2);\n });\n\n expect(result.current.elicitation?.message).toBe(\"Second request\");\n\n act(() => {\n result.current.resolveElicitation?.({\n action: \"accept\",\n content: { field2: 42 },\n });\n });\n\n const result2 = await promise2!;\n expect(result2).toEqual({\n action: \"accept\",\n content: { field2: 42 },\n });\n });\n\n it(\"maintains stable handler reference across re-renders\", () => {\n const { result, rerender } = renderHook(() => useElicitation());\n\n const firstHandler = result.current.defaultElicitationHandler;\n\n rerender();\n\n const secondHandler = result.current.defaultElicitationHandler;\n\n expect(firstHandler).toBe(secondHandler);\n });\n });\n\n describe(\"state management\", () => {\n it(\"allows manual state updates via setElicitation\", () => {\n const { result } = renderHook(() => useElicitation());\n\n const customElicitation: TamboElicitationRequest = {\n message: \"Custom message\",\n requestedSchema: {\n type: \"object\",\n properties: {\n custom: { type: \"boolean\" },\n },\n },\n };\n\n act(() => {\n result.current.setElicitation(customElicitation);\n });\n\n expect(result.current.elicitation).toEqual(customElicitation);\n });\n\n it(\"allows clearing elicitation state\", () => {\n const { result } = renderHook(() => useElicitation());\n\n const elicitation: TamboElicitationRequest = {\n message: \"Test\",\n requestedSchema: {\n type: \"object\",\n properties: {},\n },\n };\n\n act(() => {\n result.current.setElicitation(elicitation);\n });\n\n expect(result.current.elicitation).not.toBeNull();\n\n act(() => {\n result.current.setElicitation(null);\n });\n\n expect(result.current.elicitation).toBeNull();\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"elicitation.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/elicitation.test.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,cAAc,GAGf,MAAM,gBAAgB,CAAC;AAExB,gDAAgD;AAChD,SAAS,eAAe;IAItB,OAAO;QACL,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QACpC,SAAS,EAAE,iBAAiB;QAE5B,gBAAgB,EAAE,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAQ;QAEzC,WAAW,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAQ;KAClD,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,EAAE,MAAM,EAAE,GAAG,UA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P,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n ClientNotification,\n ClientRequest,\n ElicitRequest,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { act, renderHook } from \"@testing-library/react\";\nimport {\n useElicitation,\n type TamboElicitationRequest,\n type TamboElicitationResponse,\n} from \"../elicitation\";\n\n// Create a mock RequestHandlerExtra for testing\nfunction createMockExtra(): RequestHandlerExtra<\n ClientRequest,\n ClientNotification\n> {\n return {\n signal: new AbortController().signal,\n requestId: \"test-request-id\",\n\n sendNotification: (async () => {}) as any,\n\n sendRequest: (async () => ({ _meta: {} })) as any,\n };\n}\n\ndescribe(\"useElicitation\", () => {\n it(\"initializes with null state\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(result.current.elicitation).toBeNull();\n expect(result.current.resolveElicitation).toBeNull();\n });\n\n it(\"provides state setters\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(typeof result.current.setElicitation).toBe(\"function\");\n expect(typeof result.current.setResolveElicitation).toBe(\"function\");\n });\n\n it(\"provides a default elicitation handler\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(typeof result.current.defaultElicitationHandler).toBe(\"function\");\n });\n\n describe(\"defaultElicitationHandler\", () => {\n it(\"sets elicitation state when called\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: ElicitRequest = {\n method: \"elicitation/create\",\n params: {\n message: \"Please provide your name\",\n requestedSchema: {\n type: \"object\",\n properties: {\n name: { type: \"string\", description: \"Your name\" },\n },\n required: [\"name\"],\n },\n },\n };\n\n // Start the handler but don't await yet\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n // Elicitation should be set\n expect(result.current.elicitation).toEqual({\n message: \"Please provide your name\",\n requestedSchema: request.params.requestedSchema,\n signal: extra.signal,\n });\n\n // Resolve callback should be set\n expect(result.current.resolveElicitation).not.toBeNull();\n\n // Clean up by resolving\n act(() => {\n result.current.resolveElicitation?.({\n action: \"cancel\",\n });\n });\n\n await handlerPromise!;\n });\n\n it(\"resolves promise when resolveElicitation is called with accept\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: ElicitRequest = {\n method: \"elicitation/create\",\n params: {\n message: \"Enter your email\",\n requestedSchema: {\n type: \"object\",\n properties: {\n email: {\n type: \"string\",\n format: \"email\",\n description: \"Email address\",\n },\n },\n },\n },\n };\n\n // Start the handler\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n // Resolve with accept\n const response: TamboElicitationResponse = {\n action: \"accept\",\n content: { email: \"test@example.com\" },\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n // Wait for promise to resolve\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"resolves promise when resolveElicitation is called with decline\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: ElicitRequest = {\n method: \"elicitation/create\",\n params: {\n message: \"Provide input\",\n requestedSchema: {\n type: \"object\",\n properties: {\n value: { type: \"string\" },\n },\n },\n },\n };\n\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n const response: TamboElicitationResponse = {\n action: \"decline\",\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"resolves promise when resolveElicitation is called with cancel\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: ElicitRequest = {\n method: \"elicitation/create\",\n params: {\n message: \"Provide input\",\n requestedSchema: {\n type: \"object\",\n properties: {\n value: { type: \"string\" },\n },\n },\n },\n };\n\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n const response: TamboElicitationResponse = {\n action: \"cancel\",\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"handles multiple sequential elicitations\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n // First elicitation\n const request1: ElicitRequest = {\n method: \"elicitation/create\",\n params: {\n message: \"First request\",\n requestedSchema: {\n type: \"object\",\n properties: {\n field1: { type: \"string\" },\n },\n },\n },\n };\n\n let promise1: Promise<TamboElicitationResponse>;\n const extra1 = createMockExtra();\n act(() => {\n promise1 = result.current.defaultElicitationHandler(request1, extra1);\n });\n\n expect(result.current.elicitation?.message).toBe(\"First request\");\n\n act(() => {\n result.current.resolveElicitation?.({\n action: \"accept\",\n content: { field1: \"value1\" },\n });\n });\n\n const result1 = await promise1!;\n expect(result1).toEqual({\n action: \"accept\",\n content: { field1: \"value1\" },\n });\n\n // Second elicitation\n const request2: ElicitRequest = {\n method: \"elicitation/create\",\n params: {\n message: \"Second request\",\n requestedSchema: {\n type: \"object\",\n properties: { field2: { type: \"number\" } },\n },\n },\n };\n\n let promise2: Promise<TamboElicitationResponse>;\n const extra2 = createMockExtra();\n act(() => {\n promise2 = result.current.defaultElicitationHandler(request2, extra2);\n });\n\n expect(result.current.elicitation?.message).toBe(\"Second request\");\n\n act(() => {\n result.current.resolveElicitation?.({\n action: \"accept\",\n content: { field2: 42 },\n });\n });\n\n const result2 = await promise2!;\n expect(result2).toEqual({\n action: \"accept\",\n content: { field2: 42 },\n });\n });\n\n it(\"maintains stable handler reference across re-renders\", () => {\n const { result, rerender } = renderHook(() => useElicitation());\n\n const firstHandler = result.current.defaultElicitationHandler;\n\n rerender();\n\n const secondHandler = result.current.defaultElicitationHandler;\n\n expect(firstHandler).toBe(secondHandler);\n });\n });\n\n describe(\"state management\", () => {\n it(\"allows manual state updates via setElicitation\", () => {\n const { result } = renderHook(() => useElicitation());\n\n const customElicitation: TamboElicitationRequest = {\n message: \"Custom message\",\n requestedSchema: {\n type: \"object\",\n properties: {\n custom: { type: \"boolean\" },\n },\n },\n };\n\n act(() => {\n result.current.setElicitation(customElicitation);\n });\n\n expect(result.current.elicitation).toEqual(customElicitation);\n });\n\n it(\"allows clearing elicitation state\", () => {\n const { result } = renderHook(() => useElicitation());\n\n const elicitation: TamboElicitationRequest = {\n message: \"Test\",\n requestedSchema: {\n type: \"object\",\n properties: {},\n },\n };\n\n act(() => {\n result.current.setElicitation(elicitation);\n });\n\n expect(result.current.elicitation).not.toBeNull();\n\n act(() => {\n result.current.setElicitation(null);\n });\n\n expect(result.current.elicitation).toBeNull();\n });\n });\n});\n"]}
|