@tambo-ai/react 0.69.0 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/hooks/use-tambo-threads.test.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -5
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/model/component-metadata.d.ts +88 -241
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/model/mcp-server-info.d.ts +3 -3
- package/dist/model/mcp-server-info.js.map +1 -1
- package/dist/providers/hooks/use-tambo-session-token.test.js.map +1 -1
- package/dist/providers/tambo-component-provider.d.ts +2 -2
- package/dist/providers/tambo-component-provider.d.ts.map +1 -1
- package/dist/providers/tambo-component-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +1 -1
- package/dist/providers/tambo-registry-provider.d.ts +4 -4
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js +11 -8
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +31 -0
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +42 -52
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/providers/tambo-stubs.d.ts +2 -2
- package/dist/providers/tambo-stubs.d.ts.map +1 -1
- package/dist/providers/tambo-stubs.js.map +1 -1
- package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +110 -142
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.test.js +362 -445
- package/dist/providers/tambo-thread-provider.test.js.map +1 -1
- package/dist/schema/index.d.ts +1 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -5
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/schema.d.ts +7 -24
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +34 -105
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/schema.test.js +26 -124
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/testing/tools.d.ts +2 -12
- package/dist/testing/tools.d.ts.map +1 -1
- package/dist/testing/tools.js +1 -20
- package/dist/testing/tools.js.map +1 -1
- package/dist/testing/types.d.ts +2 -2
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/types.js.map +1 -1
- package/dist/util/registry-validators.d.ts +2 -2
- package/dist/util/registry-validators.d.ts.map +1 -1
- package/dist/util/registry-validators.js +37 -17
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/util/registry-validators.test.js +64 -25
- package/dist/util/registry-validators.test.js.map +1 -1
- package/dist/util/registry.d.ts +4 -10
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +6 -22
- package/dist/util/registry.js.map +1 -1
- package/dist/util/registry.test.js +1 -47
- package/dist/util/registry.test.js.map +1 -1
- package/dist/util/tool-caller.d.ts +2 -2
- package/dist/util/tool-caller.d.ts.map +1 -1
- package/dist/util/tool-caller.js +5 -12
- package/dist/util/tool-caller.js.map +1 -1
- package/dist/v1/index.d.ts +35 -0
- package/dist/v1/index.d.ts.map +1 -0
- package/dist/v1/index.js +47 -0
- package/dist/v1/index.js.map +1 -0
- package/dist/v1/types/component.d.ts +47 -0
- package/dist/v1/types/component.d.ts.map +1 -0
- package/dist/v1/types/component.js +11 -0
- package/dist/v1/types/component.js.map +1 -0
- package/dist/v1/types/event.d.ts +63 -0
- package/dist/v1/types/event.d.ts.map +1 -0
- package/dist/v1/types/event.js +9 -0
- package/dist/v1/types/event.js.map +1 -0
- package/dist/v1/types/message.d.ts +39 -0
- package/dist/v1/types/message.d.ts.map +1 -0
- package/dist/v1/types/message.js +10 -0
- package/dist/v1/types/message.js.map +1 -0
- package/dist/v1/types/thread.d.ts +54 -0
- package/dist/v1/types/thread.d.ts.map +1 -0
- package/dist/v1/types/thread.js +9 -0
- package/dist/v1/types/thread.js.map +1 -0
- package/dist/v1/types/tool.d.ts +52 -0
- package/dist/v1/types/tool.d.ts.map +1 -0
- package/dist/v1/types/tool.js +11 -0
- package/dist/v1/types/tool.js.map +1 -0
- package/esm/hooks/use-tambo-threads.test.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/mcp/index.d.ts +4 -5
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +4 -5
- package/esm/mcp/index.js.map +1 -1
- package/esm/model/component-metadata.d.ts +88 -241
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/model/mcp-server-info.d.ts +3 -3
- package/esm/model/mcp-server-info.js.map +1 -1
- package/esm/providers/hooks/use-tambo-session-token.test.js.map +1 -1
- package/esm/providers/tambo-component-provider.d.ts +2 -2
- package/esm/providers/tambo-component-provider.d.ts.map +1 -1
- package/esm/providers/tambo-component-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +1 -1
- package/esm/providers/tambo-registry-provider.d.ts +4 -4
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js +11 -8
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +31 -0
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +42 -52
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/providers/tambo-stubs.d.ts +2 -2
- package/esm/providers/tambo-stubs.d.ts.map +1 -1
- package/esm/providers/tambo-stubs.js.map +1 -1
- package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +110 -142
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.test.js +329 -445
- package/esm/providers/tambo-thread-provider.test.js.map +1 -1
- package/esm/schema/index.d.ts +1 -2
- package/esm/schema/index.d.ts.map +1 -1
- package/esm/schema/index.js +1 -2
- package/esm/schema/index.js.map +1 -1
- package/esm/schema/schema.d.ts +7 -24
- package/esm/schema/schema.d.ts.map +1 -1
- package/esm/schema/schema.js +34 -103
- package/esm/schema/schema.js.map +1 -1
- package/esm/schema/schema.test.js +27 -125
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/testing/tools.d.ts +2 -12
- package/esm/testing/tools.d.ts.map +1 -1
- package/esm/testing/tools.js +2 -20
- package/esm/testing/tools.js.map +1 -1
- package/esm/testing/types.d.ts +2 -2
- package/esm/testing/types.d.ts.map +1 -1
- package/esm/testing/types.js.map +1 -1
- package/esm/util/registry-validators.d.ts +2 -2
- package/esm/util/registry-validators.d.ts.map +1 -1
- package/esm/util/registry-validators.js +38 -18
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/util/registry-validators.test.js +64 -25
- package/esm/util/registry-validators.test.js.map +1 -1
- package/esm/util/registry.d.ts +4 -10
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +7 -22
- package/esm/util/registry.js.map +1 -1
- package/esm/util/registry.test.js +3 -49
- package/esm/util/registry.test.js.map +1 -1
- package/esm/util/tool-caller.d.ts +2 -2
- package/esm/util/tool-caller.d.ts.map +1 -1
- package/esm/util/tool-caller.js +5 -12
- package/esm/util/tool-caller.js.map +1 -1
- package/esm/v1/index.d.ts +35 -0
- package/esm/v1/index.d.ts.map +1 -0
- package/esm/v1/index.js +46 -0
- package/esm/v1/index.js.map +1 -0
- package/esm/v1/types/component.d.ts +47 -0
- package/esm/v1/types/component.d.ts.map +1 -0
- package/esm/v1/types/component.js +10 -0
- package/esm/v1/types/component.js.map +1 -0
- package/esm/v1/types/event.d.ts +63 -0
- package/esm/v1/types/event.d.ts.map +1 -0
- package/esm/v1/types/event.js +8 -0
- package/esm/v1/types/event.js.map +1 -0
- package/esm/v1/types/message.d.ts +39 -0
- package/esm/v1/types/message.d.ts.map +1 -0
- package/esm/v1/types/message.js +9 -0
- package/esm/v1/types/message.js.map +1 -0
- package/esm/v1/types/thread.d.ts +54 -0
- package/esm/v1/types/thread.d.ts.map +1 -0
- package/esm/v1/types/thread.js +8 -0
- package/esm/v1/types/thread.js.map +1 -0
- package/esm/v1/types/tool.d.ts +52 -0
- package/esm/v1/types/tool.d.ts.map +1 -0
- package/esm/v1/types/tool.js +10 -0
- package/esm/v1/types/tool.js.map +1 -0
- package/package.json +18 -8
- package/dist/schema/zod.d.ts +0 -57
- package/dist/schema/zod.d.ts.map +0 -1
- package/dist/schema/zod.js +0 -191
- package/dist/schema/zod.js.map +0 -1
- package/dist/schema/zod.test.d.ts +0 -2
- package/dist/schema/zod.test.d.ts.map +0 -1
- package/dist/schema/zod.test.js +0 -663
- package/dist/schema/zod.test.js.map +0 -1
- package/esm/schema/zod.d.ts +0 -57
- package/esm/schema/zod.d.ts.map +0 -1
- package/esm/schema/zod.js +0 -180
- package/esm/schema/zod.js.map +0 -1
- package/esm/schema/zod.test.d.ts +0 -2
- package/esm/schema/zod.test.d.ts.map +0 -1
- package/esm/schema/zod.test.js +0 -628
- package/esm/schema/zod.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToolAnnotations as MCPToolAnnotations } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { JSONSchema7 } from \"json-schema\";\nimport { ComponentType } from \"react\";\nimport {\n ZodFunction as Zod3Function,\n ZodTuple as Zod3FunctionArgs,\n ZodType as Zod3FunctionReturns,\n infer as Zod3Infer,\n} from \"zod/v3\";\nimport {\n $ZodFunction as Zod4Function,\n $ZodFunctionArgs as Zod4FunctionArgs,\n $ZodType as Zod4FunctionReturns,\n infer as Zod4Infer,\n} from \"zod/v4/core\";\n\n/**\n * A schema type that accepts either a Standard Schema compliant validator\n * (e.g., Zod, Valibot, ArkType) or a raw JSON Schema object.\n *\n * Standard Schema is a specification that provides a unified interface for\n * TypeScript validation libraries. Libraries like Zod implement this spec,\n * allowing us to accept any compliant validator without depending on a specific library.\n * @see https://standardschema.dev/\n */\nexport type SupportedSchema<Shape = unknown> =\n | StandardSchemaV1<Shape, Shape>\n | JSONSchema7;\n\n/**\n * Annotations describing a tool's behavior, aligned with the MCP (Model Context Protocol)\n * specification. These hints help clients understand how tools behave and can be used\n * to optimize tool execution strategies.\n * @see https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations\n */\nexport type ToolAnnotations = MCPToolAnnotations & {\n /**\n * Indicates that the tool is safe to be called repeatedly while a response is\n * being streamed. This is typically used for read-only tools that do not\n * cause side effects.\n */\n tamboStreamableHint?: boolean;\n};\n\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: JSONSchema7;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n /**\n * Optional per-tool call limit. When set, this overrides the project's\n * global tool call limit for this specific tool.\n *\n * This is useful for tools that should only be called once or twice\n * regardless of the project's global limit.\n */\n maxCalls?: number;\n /**\n * Annotations describing the tool's behavior. See {@link ToolAnnotations}.\n */\n annotations?: ToolAnnotations;\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<\n string,\n TamboTool | TamboToolWithToolSchema\n>;\n\n/**\n * A JSON Schema that is compatible with the MCP.\n * This is a simplified JSON Schema that is compatible with the MCPClient and the tool's inputSchema.\n *\n * Do not export this type from the SDK.\n */\nexport type JSONSchemaLite = JSONSchema7 & {\n description?: string;\n};\n\ntype MaybeAsync<T> = T | Promise<T>;\n\n/**\n * TamboTool is a type that represents a tool that can be registered with Tambo.\n *\n * It is preferable to use the `defineTool` helper function to create tools, as\n * it provides better type inference and safety.\n * @example\n * ```ts\n * import { TamboTool, defineTool } from \"@tambo-ai/react\";\n * import { z } from \"zod\";\n *\n * const locationToLatLon = defineTool({\n * name: \"location_to_latlon\",\n * description:\n * \"Fetch latitude and longitude from a location string. Returns an object with 'lat' and 'lon' properties.\",\n * tool: async ({ location }) => getLatLonFromLocation(location),\n * inputSchema: z.object({\n * location: z.string(),\n * }),\n * outputSchema: z.object({\n * lat: z.number(),\n * lon: z.number(),\n * }),\n * });\n * ```\n * Alternatively, you manually construct a TamboTool with type safety by passing\n * the expected parameter and return types as generics:\n * ```ts\n * import { TamboTool } from \"@tambo-ai/react\";\n * import { z } from \"zod\";\n *\n * const locationToLatLon: TamboTool<{ location: string }, { lat: number; lon: number }> = {\n * name: \"location_to_latlon\",\n * description:\n * \"Fetch latitude and longitude from a location string. Returns an object with 'lat' and 'lon' properties.\",\n * tool: async ({ location }) => getLatLonFromLocation(location),\n * inputSchema: z.object({\n * location: z.string(),\n * }),\n * outputSchema: z.object({\n * lat: z.number(),\n * lon: z.number(),\n * }),\n * });\n * ```\n */\nexport interface TamboTool<\n Params = any,\n Returns = any,\n Rest extends any[] = [],\n> {\n /**\n * Unique identifier for the tool\n */\n name: string;\n /**\n * Description of what the tool does - used by AI to determine when to use it\n */\n description: string;\n /**\n * Optional human-readable name of the tool for display purposes.\n */\n title?: string;\n /**\n * Optional limit for how many times this tool may be called while\n * generating a single response. If present, this value overrides the\n * project's global `maxToolCallLimit` for this tool.\n * @example 1\n */\n maxCalls?: number;\n /**\n * Annotations describing the tool's behavior, aligned with the MCP specification.\n * Use `tamboStreamableHint: true` to enable streaming execution of partial tool calls.\n * @see {@link ToolAnnotations}\n * @example\n * ```ts\n * const setTextTool: TamboTool<{ text: string }> = {\n * name: \"set_text\",\n * description: \"Set the displayed text\",\n * annotations: {\n * tamboStreamableHint: true, // tool is safe for streaming calls\n * },\n * tool: ({ text }) => setText(text),\n * inputSchema: z.object({ text: z.string() }),\n * outputSchema: z.void(),\n * };\n * ```\n */\n annotations?: ToolAnnotations;\n\n /**\n * The function that implements the tool's logic. This function will be called\n * by Tambo when the model decides to invoke the tool.\n * @param params - The input parameters for the tool. These are validated\n * against the inputSchema before being passed so are guaranteed to be correct\n * when called by the model.\n * @returns The result of the tool execution, which can be a value or a\n * Promise resolving to a value\n */\n tool: (params: Params, ...rest: Rest) => MaybeAsync<Returns>;\n\n /**\n * The schema for the tool's input parameters. This can be a validator from\n * any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) or a\n * raw JSON Schema object.\n *\n * This schema is used to validate and parse the parameters before passing\n * them to the tool function.\n */\n inputSchema: SupportedSchema | unknown;\n\n /**\n * The schema for the tool's output/return value. This can be any Standard Schema\n * compliant validator (Zod, Valibot, ArkType, etc.) or a raw JSON Schema object.\n *\n * This is used to inform the model about the structure of the tool's return value\n * and is not used for runtime validation at this stage.\n */\n outputSchema: SupportedSchema | unknown;\n\n /**\n * Optional function to transform the tool's return value into an array of content parts.\n * If not provided, the return value will be converted to a string and wrapped in a text content part.\n * @param result - The result returned by the tool function\n * @returns An array of content parts to be sent back to the AI\n */\n transformToContent?: (\n result: any,\n ) =>\n | Promise<TamboAI.Beta.Threads.ChatCompletionContentPart[]>\n | TamboAI.Beta.Threads.ChatCompletionContentPart[];\n}\n\n/**\n * Simplified interface for tools using the deprecated toolSchema format.\n * This interface uses simple `any` types to avoid complex type instantiation.\n * Use `defineTamboTool()` for full type inference when creating tools.\n * @deprecated Use TamboTool with `inputSchema`/`outputSchema` instead.\n */\nexport type TamboToolWithToolSchema<\n Args extends any[] = any[],\n Returns = any,\n> = Omit<TamboTool, \"tool\" | \"inputSchema\" | \"outputSchema\"> & {\n tool: (...args: Args) => MaybeAsync<Returns>;\n /** @deprecated Use `inputSchema`/`outputSchema` properties instead. */\n toolSchema: unknown;\n};\n\n// NOTE(lachieh): this comment mirrors the one from `TamboTool` above\n/**\n * TamboTool is a type that represents a tool that can be registered with Tambo.\n *\n * It is preferable to use the `defineTool` helper function to create tools, as\n * it provides better type inference and safety.\n * @example\n * ```ts\n * import { TamboTool, defineTool } from \"@tambo-ai/react\";\n * import { z } from \"zod\";\n *\n * const locationToLatLon = defineTool({\n * name: \"location_to_latlon\",\n * description:\n * \"Fetch latitude and longitude from a location string. Returns an object with 'lat' and 'lon' properties.\",\n * tool: async ({ location }) => getLatLonFromLocation(location),\n * inputSchema: z.object({\n * location: z.string(),\n * }),\n * outputSchema: z.object({\n * lat: z.number(),\n * lon: z.number(),\n * }),\n * });\n * ```\n * Alternatively, you manually construct a TamboTool with type safety by passing\n * the expected parameter and return types as generics:\n * ```ts\n * import { TamboTool } from \"@tambo-ai/react\";\n * import { z } from \"zod\";\n *\n * const locationToLatLon: TamboTool<{ location: string }, { lat: number; lon: number }> = {\n * name: \"location_to_latlon\",\n * description:\n * \"Fetch latitude and longitude from a location string. Returns an object with 'lat' and 'lon' properties.\",\n * tool: async ({ location }) => getLatLonFromLocation(location),\n * inputSchema: z.object({\n * location: z.string(),\n * }),\n * outputSchema: z.object({\n * lat: z.number(),\n * lon: z.number(),\n * }),\n * });\n * ```\n */\nexport type TamboToolBase<Params = any, Returns = any> =\n | TamboToolWithToolSchema\n | TamboTool<Params, Returns>;\n\n/**\n * A tool that uses JSON Schema compliant input and output schemas.\n * This does not provide type safety for the tool's parameters and return value.\n * @internal\n */\nexport type TamboToolJSONSchema<\n Args extends unknown[] = unknown[],\n Returns = unknown,\n> = Omit<TamboTool<Args, Returns>, \"tool\" | \"inputSchema\" | \"outputSchema\"> & {\n tool: (...args: Args) => MaybeAsync<Returns>;\n inputSchema: JSONSchemaLite;\n outputSchema: JSONSchemaLite;\n};\n\n/**\n * A tool that could not be matched to any known schema types.\n * This means type safety cannot be guaranteed.\n * @internal\n */\nexport type TamboToolUnknown = Omit<\n TamboTool,\n \"tool\" | \"inputSchema\" | \"outputSchema\"\n> & {\n tool: (...args: unknown[]) => MaybeAsync<unknown>;\n inputSchema: unknown;\n outputSchema: unknown;\n};\n\n/**\n * A tool that uses Standard Schema compliant input and output schemas.\n * This provides full type safety for the tool's parameters and return value.\n * @internal\n */\nexport type TamboToolStandardSchema<\n Input extends StandardSchemaV1 = StandardSchemaV1,\n Output extends StandardSchemaV1 = StandardSchemaV1,\n> = Omit<\n TamboTool<\n StandardSchemaV1.InferOutput<Input>,\n StandardSchemaV1.InferOutput<Output>\n >,\n \"tool\" | \"inputSchema\" | \"outputSchema\"\n> & {\n tool: (\n ...args: [StandardSchemaV1.InferOutput<Input>]\n ) => MaybeAsync<StandardSchemaV1.InferOutput<Output>>;\n inputSchema: Input;\n outputSchema: Output;\n};\n\ntype TamboToolZod3Function<\n Args extends Zod3FunctionArgs,\n Returns extends Zod3FunctionReturns,\n> = Omit<\n TamboToolWithToolSchema<Zod3Infer<Args>, Zod3Infer<Returns>>,\n \"toolSchema\"\n> & {\n tool: (...args: Zod3Infer<Args>) => MaybeAsync<Zod3Infer<Returns>>;\n /** @deprecated Use `inputSchema`/`outputSchema` properties instead. */\n toolSchema: Zod3Function<Args, Returns>;\n};\n\ntype TamboToolZod4Function<\n Args extends Zod4FunctionArgs,\n Returns extends Zod4FunctionReturns,\n> = Omit<\n TamboToolWithToolSchema<Zod4Infer<Args>, Zod4Infer<Returns>>,\n \"toolSchema\"\n> & {\n tool: (...args: Zod4Infer<Args>) => MaybeAsync<Zod4Infer<Returns>>;\n /** @deprecated Use `inputSchema`/`outputSchema` properties instead. */\n toolSchema: Zod4Function<Args, Returns>;\n};\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * Schema describing the component's props. Accepts any Standard Schema\n * compliant validator (Zod, Valibot, ArkType, etc.) or a raw JSON Schema\n * object.\n *\n * Either this or propsDefinition must be provided, but not both.\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const component: TamboComponent = {\n * name: \"MyComponent\",\n * description: \"A sample component\",\n * component: MyComponent,\n * propsSchema: z.object({\n * title: z.string(),\n * count: z.number().optional()\n * })\n * };\n * ```\n */\n propsSchema?: SupportedSchema;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n * @deprecated Use propsSchema instead.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: (TamboTool | TamboToolWithToolSchema)[];\n /** Annotations describing the component's behavior. */\n annotations?: ToolAnnotations;\n}\n\nexport interface RegisterToolsFn {\n /**\n * Registers one or more Tambo tools.\n * @param tools - An array of Tambo tools to register\n */\n (tools: TamboTool[]): void;\n (tools: (TamboTool | TamboToolWithToolSchema)[]): void;\n}\n\n/**\n * Function interface for registering a Tambo tool with full type inference.\n * This function has multiple overloads to handle different schema types. This\n * is a utility function and does not perform any runtime logic.\n */\nexport interface RegisterToolFn {\n /**\n * @deprecated Use `inputSchema`/`outputSchema` instead. toolSchema is deprecated\n * and will be removed in future versions.\n * @example\n * ```diff\n * import { z } from \"zod/v3\";\n * const myTool = defineTamboTool({\n * ...\n * - toolSchema: z.function()\n * - .arguments(z.tuple([z.string()]))\n * - .returns(z.number()),\n * + inputSchema: z.object({\n * + input: z.string().describe(\"Input description\")\n * + }),\n * + outputSchema: z.number().describe(\"Result description\"),\n * });\n */\n <Args extends Zod3FunctionArgs, Returns extends Zod3FunctionReturns>(\n tool: TamboToolZod3Function<Args, Returns>,\n warnOnOverwrite?: boolean,\n ): void;\n /**\n * @deprecated Use `inputSchema`/`outputSchema` instead. toolSchema is deprecated\n * and will be removed in future versions.\n * @example\n * ```diff\n * import { z } from \"zod/v4\";\n * const myTool = defineTamboTool({\n * ...\n * - toolSchema: z.function({\n * - input: z.tuple([z.string()]),\n * - output: z.number(),\n * - }),\n * + inputSchema: z.object({\n * + input: z.string().describe(\"Input description\")\n * + }),\n * + outputSchema: z.number().describe(\"Result description\"),\n * });\n */\n <Args extends Zod4FunctionArgs, Returns extends Zod4FunctionReturns>(\n tool: TamboToolZod4Function<Args, Returns>,\n warnOnOverwrite?: boolean,\n ): void;\n (tool: TamboToolWithToolSchema, warnOnOverwrite?: boolean): void;\n <Args extends StandardSchemaV1, Returns extends StandardSchemaV1>(\n tool: TamboToolStandardSchema<Args, Returns>,\n warnOnOverwrite?: boolean,\n ): void;\n <Args extends any[], Returns = any>(\n tool: TamboToolJSONSchema<Args, Returns>,\n warnOnOverwrite?: boolean,\n ): void;\n (tool: TamboToolUnknown, warnOnOverwrite?: boolean): void;\n (tool: TamboTool, warnOnOverwrite?: boolean): void;\n}\n\n/**\n * Function interface for defining a Tambo tool with full type inference. This\n * function has multiple overloads to handle different schema types. This is a\n * utility function and does not perform any runtime logic.\n */\nexport interface DefineToolFn {\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * Tambo uses the [standard-schema.dev](https://standard-schema.dev) spec which means you can use any Standard Schema\n * compliant validator (Zod, Valibot, ArkType, etc.). This definition ensures the input and output types are correctly\n * inferred from the provided schemas.\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTamboTool({\n * // ...\n * inputSchema: z.object({\n * input: z.string().describe(\"Input description\")\n * }),\n * outputSchema: z.number().describe(\"Result description\"),\n * });\n * ```\n * @see {@link https://standard-schema.dev/}\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n <Input extends StandardSchemaV1, Output extends StandardSchemaV1>(\n tool: TamboToolStandardSchema<Input, Output>,\n ): TamboToolStandardSchema<Input, Output>;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This tool uses the deprecated `toolSchema` format which uses a zod function schema. If you are using a validation\n * library that implements StandardSchema.dev, please switch to using separate `inputSchema` and `outputSchema`\n * properties instead. See example below.\n * @example\n * ```diff\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTamboTool({\n * // ...\n * - toolSchema: z.function({\n * - input: z.tuple([z.string()]),\n * - output: z.number(),\n * - })\n * + inputSchema: z.object({\n * + input: z.string().describe(\"Input description\")\n * + }),\n * + outputSchema: z.number().describe(\"Result description\"),\n * });\n * @see {@link https://standard-schema.dev/}\n * @param tool The tool definition to register\n * @returns The registered tool definition\n * @deprecated Using `toolSchema` is deprecated. Please use separate `inputSchema` and `outputSchema` properties instead.\n * Note that use of `toolSchema` will be removed in a future release.\n * ```\n */\n <Args extends Zod3FunctionArgs, Returns extends Zod3FunctionReturns>(\n tool: TamboToolZod3Function<Args, Returns>,\n ): TamboToolZod3Function<Args, Returns>;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This tool uses the deprecated `toolSchema` format which uses a zod function schema. If you are using a validation\n * library that implements standard-schema.dev, please switch to using separate `inputSchema` and `outputSchema`\n * properties instead. See example below.\n * @param tool The tool definition to register\n * @returns The registered tool definition\n * @deprecated Using `toolSchema` is deprecated. Please use separate `inputSchema` and `outputSchema` properties instead.\n * Note that use of `toolSchema` will be removed in a future release.\n * @example\n * ```diff\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTamboTool({\n * // ...\n * - toolSchema: z.function({\n * - input: z.tuple([z.string()]),\n * - output: z.number(),\n * - })\n * + inputSchema: z.object({\n * + input: z.string().describe(\"Input description\")\n * + }),\n * + outputSchema: z.number().describe(\"Result description\"),\n * });\n * ```\n */\n <Args extends Zod4FunctionArgs, Returns extends Zod4FunctionReturns>(\n tool: TamboToolZod4Function<Args, Returns>,\n ): TamboToolZod4Function<Args, Returns>;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This tool uses the deprecated `toolSchema` property which uses a zod function schema. If you are using a validation\n * library that implements standard-schema.dev, please switch to using separate `inputSchema` and `outputSchema`\n * properties instead. See example below.\n * @param tool The tool definition to register\n * @returns The registered tool definition\n * @deprecated Using `toolSchema` is deprecated. Please use separate `inputSchema` and `outputSchema` properties instead.\n * Note that use of `toolSchema` will be removed in a future release.\n * @example\n * ```diff\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTamboTool({\n * // ...\n * - toolSchema: { ... }\n * + inputSchema: z.object({ ... }),\n * + outputSchema: z.number(),\n * });\n * ```\n */\n (tool: TamboToolWithToolSchema): TamboToolWithToolSchema;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This tool definition matched to JSON Schema input and output schemas which allows does not guarantee type\n * safety. If you are using a validation library that implements\n * [Standard Schema](https://standardschema.dev/#what-tools-frameworks-accept-speccompliant-schemas), please ensure\n * your schemas are correctly typed.\n * @see {@link https://standard-schema.dev/}\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n <I extends any[], O = any>(\n tool: TamboToolJSONSchema<I, O>,\n ): TamboToolJSONSchema<I, O>;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This tool definition could not be matched to any known schema types which means type safety cannot be\n * guaranteed. If you are using a validation library that implements\n * [Standard Schema](https://standardschema.dev/#what-tools-frameworks-accept-speccompliant-schemas), please ensure\n * your schemas are correctly typed.\n * @example\n * ```typescript\n * const myTool = defineTamboTool({\n * name: \"myTool\",\n * description: \"An example tool\",\n * tool: (input) => { ... },\n * inputSchema: yourInputSchema,\n * outputSchema: yourOutputSchema,\n * });\n * @param tool The tool definition to register\n * @returns The registered tool definition\n * ```\n */\n (tool: TamboToolUnknown): TamboToolUnknown;\n (tool: TamboTool): TamboTool;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToolAnnotations as MCPToolAnnotations } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { JSONSchema7 } from \"json-schema\";\nimport { ComponentType } from \"react\";\n\n/**\n * A schema type that accepts either a Standard Schema compliant validator\n * (e.g., Zod, Valibot, ArkType) or a raw JSON Schema object.\n *\n * Standard Schema is a specification that provides a unified interface for\n * TypeScript validation libraries. Libraries like Zod implement this spec,\n * allowing us to accept any compliant validator without depending on a specific library.\n * @see https://standardschema.dev/\n */\nexport type SupportedSchema<Input = unknown, Output = Input> =\n | StandardSchemaV1<Input, Output>\n | JSONSchema7;\n\n/**\n * Annotations describing a tool's behavior, aligned with the MCP (Model Context Protocol)\n * specification. These hints help clients understand how tools behave and can be used\n * to optimize tool execution strategies.\n * @see https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations\n */\nexport type ToolAnnotations = MCPToolAnnotations & {\n /**\n * Indicates that the tool is safe to be called repeatedly while a response is\n * being streamed. This is typically used for read-only tools that do not\n * cause side effects.\n */\n tamboStreamableHint?: boolean;\n};\n\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: JSONSchema7;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n /**\n * Optional per-tool call limit. When set, this overrides the project's\n * global tool call limit for this specific tool.\n *\n * This is useful for tools that should only be called once or twice\n * regardless of the project's global limit.\n */\n maxCalls?: number;\n /**\n * Annotations describing the tool's behavior. See {@link ToolAnnotations}.\n */\n annotations?: ToolAnnotations;\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\n/**\n * A JSON Schema that is compatible with the MCP.\n * This is a simplified JSON Schema that is compatible with the MCPClient and the tool's inputSchema.\n *\n * Do not export this type from the SDK.\n */\nexport type JSONSchemaLite = JSONSchema7 & {\n description?: string;\n};\n\ntype MaybeAsync<T> = T | Promise<T>;\n\n/**\n * TamboTool is a type that represents a tool that can be registered with Tambo.\n *\n * It is preferable to use the `defineTool` helper function to create tools, as\n * it provides better type inference and safety.\n * @example\n * ```ts\n * import { TamboTool, defineTool } from \"@tambo-ai/react\";\n * import { z } from \"zod\";\n *\n * const locationToLatLon = defineTool({\n * name: \"location_to_latlon\",\n * description:\n * \"Fetch latitude and longitude from a location string. Returns an object with 'lat' and 'lon' properties.\",\n * tool: async ({ location }) => getLatLonFromLocation(location),\n * inputSchema: z.object({\n * location: z.string(),\n * }),\n * outputSchema: z.object({\n * lat: z.number(),\n * lon: z.number(),\n * }),\n * });\n * ```\n */\nexport interface TamboTool<\n Params = any,\n Returns = any,\n Rest extends any[] = [],\n> {\n /**\n * Unique identifier for the tool\n */\n name: string;\n /**\n * Description of what the tool does - used by AI to determine when to use it\n */\n description: string;\n /**\n * Optional human-readable name of the tool for display purposes.\n */\n title?: string;\n /**\n * Optional limit for how many times this tool may be called while\n * generating a single response. If present, this value overrides the\n * project's global `maxToolCallLimit` for this tool.\n * @example 1\n */\n maxCalls?: number;\n /**\n * Annotations describing the tool's behavior, aligned with the MCP specification.\n * Use `tamboStreamableHint: true` to enable streaming execution of partial tool calls.\n * @see {@link ToolAnnotations}\n * @example\n * ```ts\n * const setTextTool: TamboTool<{ text: string }> = {\n * name: \"set_text\",\n * description: \"Set the displayed text\",\n * annotations: {\n * tamboStreamableHint: true, // tool is safe for streaming calls\n * },\n * tool: ({ text }) => setText(text),\n * inputSchema: z.object({ text: z.string() }),\n * outputSchema: z.void(),\n * };\n * ```\n */\n annotations?: ToolAnnotations;\n\n /**\n * The function that implements the tool's logic. This function will be called\n * by Tambo when the model decides to invoke the tool.\n * @param params - The input parameters for the tool. These are validated\n * against the inputSchema before being passed so are guaranteed to be correct\n * when called by the model.\n * @returns The result of the tool execution, which can be a value or a\n * Promise resolving to a value\n */\n tool: (params: Params, ...rest: Rest) => MaybeAsync<Returns>;\n\n /**\n * The schema for the tool's input parameters. This can be a validator from\n * any Standard Schema compliant library (Zod 3.24+, Zod 4.x) or a\n * raw JSON Schema object.\n *\n * This schema is used to validate and parse the parameters before passing\n * them to the tool function.\n */\n inputSchema: SupportedSchema<Params>;\n\n /**\n * The schema for the tool's output/return value. This can be any Standard Schema\n * compliant validator (Zod 3.24+, Zod 4.x) or a raw JSON Schema object.\n *\n * This is used to inform the model about the structure of the tool's return value\n * and is not used for runtime validation at this stage.\n */\n outputSchema: SupportedSchema<Returns>;\n\n /**\n * Optional function to transform the tool's return value into an array of content parts.\n * If not provided, the return value will be converted to a string and wrapped in a text content part.\n * @param result - The result returned by the tool function\n * @returns An array of content parts to be sent back to the AI\n */\n transformToContent?: (\n result: any,\n ) =>\n | Promise<TamboAI.Beta.Threads.ChatCompletionContentPart[]>\n | TamboAI.Beta.Threads.ChatCompletionContentPart[];\n}\n\n/**\n * A tool that uses JSON Schema compliant input and output schemas.\n * This does not provide type safety for the tool's parameters and return value.\n * @internal\n */\nexport type TamboToolJSONSchema<\n Args extends unknown[] = unknown[],\n Returns = unknown,\n> = Omit<TamboTool<Args, Returns>, \"tool\" | \"inputSchema\" | \"outputSchema\"> & {\n tool: (...args: Args) => MaybeAsync<Returns>;\n inputSchema: JSONSchemaLite;\n outputSchema: JSONSchemaLite;\n};\n\n/**\n * A tool that could not be matched to any known schema types.\n * This means type safety cannot be guaranteed.\n * @internal\n */\nexport type TamboToolUnknown = Omit<\n TamboTool,\n \"tool\" | \"inputSchema\" | \"outputSchema\"\n> & {\n tool: (...args: unknown[]) => MaybeAsync<unknown>;\n inputSchema: SupportedSchema;\n outputSchema: SupportedSchema;\n};\n\n/**\n * A tool that uses Standard Schema compliant input and output schemas.\n * This provides full type safety for the tool's parameters and return value.\n * @internal\n */\nexport type TamboToolStandardSchema<\n Input extends StandardSchemaV1 = StandardSchemaV1,\n Output extends StandardSchemaV1 = StandardSchemaV1,\n> = Omit<\n TamboTool<\n StandardSchemaV1.InferOutput<Input>,\n StandardSchemaV1.InferOutput<Output>\n >,\n \"tool\" | \"inputSchema\" | \"outputSchema\"\n> & {\n tool: (\n ...args: [StandardSchemaV1.InferOutput<Input>]\n ) => MaybeAsync<StandardSchemaV1.InferOutput<Output>>;\n inputSchema: Input;\n outputSchema: Output;\n};\n\n/**\n * If you're seeing this type, it means that you are using a deprecated and now\n * unsupported schema type for defining Tambo tools.\n *\n * Follow the migration guide to update your tool definitions to use\n * inputSchema and outputSchema with either Standard Schema compliant validators\n * (like Zod 3.25.76, Zod 4.x) or raw JSON Schema objects.\n * @deprecated replace `toolSchema` with `inputSchema` and `outputSchema` instead.\n * @see {@link https://docs.tambo.ai/api-reference/migration/toolschema}\n */\nexport type UnsupportedSchemaTamboTool = Omit<\n TamboTool,\n \"tool\" | \"inputSchema\" | \"outputSchema\"\n> & {\n /**\n * @deprecated replace `toolSchema` with `inputSchema` and `outputSchema` instead.\n */\n toolSchema: any;\n tool: (...args: any[]) => MaybeAsync<any>;\n inputSchema?: never;\n outputSchema?: never;\n};\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * Schema describing the component's props. Accepts any Standard Schema\n * compliant validator (Zod, Valibot, ArkType, etc.) or a raw JSON Schema\n * object.\n *\n * Either this or propsDefinition must be provided, but not both.\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const component: TamboComponent = {\n * name: \"MyComponent\",\n * description: \"A sample component\",\n * component: MyComponent,\n * propsSchema: z.object({\n * title: z.string(),\n * count: z.number().optional()\n * })\n * };\n * ```\n */\n propsSchema?: SupportedSchema;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n * @deprecated Use propsSchema instead.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n /** Annotations describing the component's behavior. */\n annotations?: ToolAnnotations;\n}\n\ntype OptionalSchemaProps<T> = Omit<T, \"inputSchema\" | \"outputSchema\"> & {\n inputSchema?: T extends { inputSchema: infer I } ? I : never;\n outputSchema?: T extends { outputSchema: infer O } ? O : never;\n};\n\n/**\n * Registers one or more Tambo tools.\n * @param tools - An array of Tambo tools to register\n * @param warnOnOverwrite - Whether to warn if any tool is being overwritten\n */\nexport interface RegisterToolsFn {\n /**\n * @deprecated Follow the {@link https://docs.tambo.ai/api-reference/migration/toolschema | Migration Guide} to update\n * your tool definitions to use `inputSchema` and `outputSchema` instead.\n */\n (tools: UnsupportedSchemaTamboTool[], warnOnOverwrite?: boolean): void;\n /**\n * Register one or more Tambo tools. For better type inference, consider registering tools individually using the\n * `registerTool` function or use the `defineTool` helper when defining your tools.\n * @example\n * ```typescript\n * import { defineTool } from \"@tambo-ai/react\";\n * const tools = [\n * defineTool({...});\n * defineTool({...});\n * ];\n * registerTools(tools);\n * @param tools - An array of Tambo tools to register\n * @param warnOnOverwrite - Whether to warn if any tool is being overwritten\n */\n (tools: TamboTool[], warnOnOverwrite?: boolean): void;\n}\n\n/**\n * Function interface for registering a Tambo tool with full type inference.\n * This function has multiple overloads to handle different schema types. This\n * is a utility function and does not perform any runtime logic.\n */\nexport interface RegisterToolFn {\n <Args extends StandardSchemaV1, Returns extends StandardSchemaV1>(\n tool: TamboToolStandardSchema<Args, Returns>,\n warnOnOverwrite?: boolean,\n ): void;\n <Args extends any[], Returns = any>(\n tool: TamboToolJSONSchema<Args, Returns>,\n warnOnOverwrite?: boolean,\n ): void;\n (tool: TamboToolUnknown, warnOnOverwrite?: boolean): void;\n (tool: TamboTool, warnOnOverwrite?: boolean): void;\n /**\n * @deprecated Follow the {@link https://docs.tambo.ai/api-reference/migration/toolschema | Migration Guide} to update\n * your tool definitions to use `inputSchema` and `outputSchema` instead.\n * @param tool - The unsupported schema Tambo tool to register\n * @param warnOnOverwrite - Whether to warn if the tool is being overwritten\n */\n (tool: UnsupportedSchemaTamboTool, warnOnOverwrite?: boolean): void;\n}\n\n/**\n * Function interface for defining a Tambo tool with full type inference. This function has multiple overloads to handle\n * different schema types. This is a utility function and does not perform any runtime logic.\n */\nexport interface DefineToolFn {\n /**\n * @deprecated Follow the {@link https://docs.tambo.ai/api-reference/migration/toolschema | Migration Guide} to update\n * your tool definitions to use `inputSchema` and `outputSchema` instead.\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n (tool: UnsupportedSchemaTamboTool): typeof tool;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * Tambo uses the [standard-schema.dev](https://standard-schema.dev) spec which means you can use any Standard Schema\n * compliant validator (Zod 3.24+, Zod 4.x). This definition ensures the input and output types are correctly\n * inferred from the provided schemas.\n * @example\n * ```typescript\n * import { z } from \"zod/v4\";\n *\n * const myTool = defineTool({\n * name: \"myTool\",\n * description: \"An example tool\",\n * inputSchema: z.object({\n * input: z.string().describe(\"Input description\")\n * }),\n * outputSchema: z.number().describe(\"Result description\"),\n * tool: ({ input }) => input.length,\n * });\n * ```\n * @see {@link https://standard-schema.dev/}\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n <Input extends StandardSchemaV1, Output extends StandardSchemaV1>(\n tool: OptionalSchemaProps<TamboToolStandardSchema<Input, Output>>,\n ): TamboToolStandardSchema<Input, Output>;\n /**\n * Provides type safety for defining a Tambo Tool with JSON Schema input and output.\n *\n * This overload is used when providing raw JSON Schema objects instead of StandardSchema validators.\n * Type inference is limited when using raw JSON Schema.\n * @see {@link https://standard-schema.dev/}\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n <I extends any[], O = any>(\n tool: OptionalSchemaProps<TamboToolJSONSchema<I, O>>,\n ): TamboToolJSONSchema<I, O>;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This overload is used when the schema types could not be matched to known types.\n * Type safety cannot be guaranteed.\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n (tool: OptionalSchemaProps<TamboToolUnknown>): TamboToolUnknown;\n /**\n * Provides type safety for defining a Tambo Tool.\n *\n * This overload is used when providing a fully defined TamboTool.\n * @param tool The tool definition to register\n * @returns The registered tool definition\n */\n (tool: OptionalSchemaProps<TamboTool>): TamboTool;\n}\n"]}
|
|
@@ -14,9 +14,9 @@ export declare enum MCPTransport {
|
|
|
14
14
|
* The `handlers` field is intentionally typed as `unknown` here so the core
|
|
15
15
|
* SDK does not depend on the MCP subpackage. In the `@tambo-ai/react/mcp`
|
|
16
16
|
* subpackage this is treated as `Partial<MCPHandlers>` (with
|
|
17
|
-
* `elicitation` / `sampling` callbacks).
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* `elicitation` / `sampling` callbacks). The `@modelcontextprotocol/sdk` is
|
|
18
|
+
* included automatically with `@tambo-ai/react`. See the React SDK README for
|
|
19
|
+
* any additional optional peer dependencies needed for MCP features.
|
|
20
20
|
*/
|
|
21
21
|
export interface McpServerInfo {
|
|
22
22
|
/** Optional name for the MCP server */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server-info.js","sourceRoot":"","sources":["../../src/model/mcp-server-info.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AA+DD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAsE;IAEtE,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa;QACxC,CAAC,CAAC,IAAI,CAAC,SAAS,CACZ,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC;aACrC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAU,CAAC;aAC9C,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAC1C;QACH,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,GAAG,UAAU,CAAC,GAAG,IAAI,UAAU,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;AACvF,CAAC","sourcesContent":["/**\n * The transport protocol to use for MCP connections.\n */\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\n}\n\n/**\n * User-provided configuration for an MCP server.\n *\n * This is the type accepted by `TamboProvider` / `TamboRegistryProvider` in\n * the `mcpServers` prop.\n *\n * The `handlers` field is intentionally typed as `unknown` here so the core\n * SDK does not depend on the MCP subpackage. In the `@tambo-ai/react/mcp`\n * subpackage this is treated as `Partial<MCPHandlers>` (with\n * `elicitation` / `sampling` callbacks). See the React SDK README for
|
|
1
|
+
{"version":3,"file":"mcp-server-info.js","sourceRoot":"","sources":["../../src/model/mcp-server-info.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AA+DD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAsE;IAEtE,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa;QACxC,CAAC,CAAC,IAAI,CAAC,SAAS,CACZ,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC;aACrC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAU,CAAC;aAC9C,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAC1C;QACH,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,GAAG,UAAU,CAAC,GAAG,IAAI,UAAU,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;AACvF,CAAC","sourcesContent":["/**\n * The transport protocol to use for MCP connections.\n */\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\n}\n\n/**\n * User-provided configuration for an MCP server.\n *\n * This is the type accepted by `TamboProvider` / `TamboRegistryProvider` in\n * the `mcpServers` prop.\n *\n * The `handlers` field is intentionally typed as `unknown` here so the core\n * SDK does not depend on the MCP subpackage. In the `@tambo-ai/react/mcp`\n * subpackage this is treated as `Partial<MCPHandlers>` (with\n * `elicitation` / `sampling` callbacks). The `@modelcontextprotocol/sdk` is\n * included automatically with `@tambo-ai/react`. See the React SDK README for\n * any additional optional peer dependencies needed for MCP features.\n */\nexport interface McpServerInfo {\n /** Optional name for the MCP server */\n name?: string;\n /** The URL of the MCP server to connect to */\n url: string;\n /** Optional description of the MCP server */\n description?: string;\n /** The transport type to use (SSE or HTTP). Defaults to HTTP for string URLs */\n transport?: MCPTransport;\n /** Optional custom headers to include in requests */\n customHeaders?: Record<string, string>;\n /**\n * Optional short name for namespacing MCP resources, prompts, and tools.\n * When multiple MCP servers are configured, this key is used to prefix:\n * - prompts: `<serverKey>:<promptName>`\n * - resources: `<serverKey>:<resourceUrl>`\n * - tools: `<serverKey>__<toolName>`\n *\n * If not provided, a key will be derived from the URL hostname.\n * For example, \"https://mcp.linear.app/mcp\" becomes \"linear\".\n */\n serverKey?: string;\n /**\n * Optional handlers for elicitation and sampling requests from the server.\n *\n * In the MCP subpackage this is interpreted as `Partial<MCPHandlers>`,\n * i.e. `{ elicitation?: MCPElicitationHandler; sampling?: MCPSamplingHandler }`.\n *\n * Note: These callbacks should be stable (e.g., wrapped in useCallback or\n * defined outside the component) to avoid constant re-registration of the\n * MCP server on every render.\n */\n handlers?: unknown;\n}\n\n/**\n * Normalized MCP server metadata used internally by the registry and MCP\n * provider.\n *\n * This is equivalent to `McpServerInfo` except that:\n * - `serverKey` is guaranteed to be present\n * - `transport` is resolved to a concrete value (defaults to HTTP)\n */\nexport interface NormalizedMcpServerInfo extends McpServerInfo {\n transport: MCPTransport;\n serverKey: string;\n}\n\n/**\n * Creates a stable identifier for an MCP server based on its connection properties.\n * Two servers with the same URL, transport, and headers will have the same key.\n *\n * This is used by both the registry and MCP provider to deduplicate servers,\n * so it lives alongside the shared server metadata type.\n * @returns A stable string key identifying the server\n */\nexport function getMcpServerUniqueKey(\n serverInfo: Pick<McpServerInfo, \"url\" | \"transport\" | \"customHeaders\">,\n): string {\n const headerStr = serverInfo.customHeaders\n ? JSON.stringify(\n Object.entries(serverInfo.customHeaders)\n .map(([k, v]) => [k.toLowerCase(), v] as const)\n .sort(([a], [b]) => a.localeCompare(b)),\n )\n : \"\";\n\n return `${serverInfo.url}|${serverInfo.transport ?? MCPTransport.HTTP}|${headerStr}`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-session-token.test.js","sourceRoot":"","sources":["../../../src/providers/hooks/use-tambo-session-token.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAIjE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,MAAM,iBAAiB,GAAG;QACxB,YAAY,EAAE,mBAAmB;QACjC,UAAU,EAAE,IAAI,EAAE,SAAS;QAC3B,UAAU,EAAE,QAAQ;KACrB,CAAC;IAEF,MAAM,WAAW,GAAG;QAClB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;KAC2B,CAAC;IAEjD,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,WAAW;KACe,CAAC;IAEnC,MAAM,WAAW,GAAG;QAClB,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,EAAE;KACoC,CAAC;IACjD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;QAClC,cAAc,EAAE;YACd,OAAO,EAAE;gBACP,KAAK,EAAE,KAAK;gBACZ,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF,CAAC,CAAC;IAEH,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,aAAa,EAAE,CAAC;QACpB,WAAmB,CAAC,MAAM,GAAG,EAAE,CAAC;QACjC,WAA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AAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { act, renderHook } from \"@testing-library/react\";\nimport { DeepPartial } from \"ts-essentials\";\nimport { useTamboSessionToken } from \"./use-tambo-session-token\";\n\ntype PartialTamboAI = DeepPartial<TamboAI>;\n\ndescribe(\"useTamboSessionToken\", () => {\n const mockTokenResponse = {\n access_token: \"test-access-token\",\n expires_in: 3600, // 1 hour\n token_type: \"Bearer\",\n };\n\n const mockAuthApi = {\n getToken: jest.fn(),\n } satisfies DeepPartial<TamboAI[\"beta\"][\"auth\"]>;\n\n const mockBeta = {\n auth: mockAuthApi,\n } satisfies PartialTamboAI[\"beta\"];\n\n const mockTamboAI = {\n apiKey: \"\",\n beta: mockBeta,\n bearer: \"\",\n } satisfies PartialTamboAI as unknown as TamboAI;\n const queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n retry: false,\n refetchOnWindowFocus: false,\n },\n },\n });\n\n beforeEach(() => {\n jest.clearAllMocks();\n jest.clearAllTimers();\n jest.useFakeTimers();\n (mockTamboAI as any).bearer = \"\";\n queryClient.clear();\n });\n\n afterEach(async () => {\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n jest.useRealTimers();\n jest.resetAllMocks();\n });\n\n it(\"should return null initially when no userToken is provided\", () => {\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, undefined),\n );\n\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: false,\n });\n expect(mockAuthApi.getToken).not.toHaveBeenCalled();\n });\n\n it(\"should fetch and return session token when userToken is provided\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(1);\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n expect(mockTamboAI.bearer).toBe(mockTokenResponse.access_token);\n // Verify the hook was called with correct parameters\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(2);\n expect(mockAuthApi.getToken).toHaveBeenCalledWith(expect.any(Object));\n });\n\n it(\"should call getToken with correct token exchange parameters\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n const callArgs = mockAuthApi.getToken.mock.calls[0][0];\n const tokenRequestString = new TextDecoder().decode(callArgs);\n const tokenRequest = new URLSearchParams(tokenRequestString);\n\n expect(tokenRequest.get(\"grant_type\")).toBe(\n \"urn:ietf:params:oauth:grant-type:token-exchange\",\n );\n expect(tokenRequest.get(\"subject_token\")).toBe(\"user-token\");\n expect(tokenRequest.get(\"subject_token_type\")).toBe(\n \"urn:ietf:params:oauth:token-type:access_token\",\n );\n });\n\n it(\"should set bearer token on client\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n });\n expect(mockTamboAI.bearer).toBe(\"test-access-token\");\n });\n\n it(\"should handle different token responses\", async () => {\n const customTokenResponse = {\n access_token: \"custom-access-token\",\n expires_in: 7200, // 2 hours\n token_type: \"Bearer\",\n };\n\n mockAuthApi.getToken.mockResolvedValue(customTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: customTokenResponse,\n isFetching: false,\n });\n expect(mockTamboAI.bearer).toBe(\"custom-access-token\");\n });\n\n it(\"should not fetch token when userToken changes to undefined\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result, rerender } = renderHook(\n ({ userToken }) =>\n useTamboSessionToken(mockTamboAI, queryClient, userToken),\n {\n initialProps: { userToken: \"user-token\" as string | undefined },\n },\n );\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(1);\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(2);\n\n // Clear mock and change userToken to undefined\n jest.clearAllMocks();\n\n act(() => {\n rerender({ userToken: undefined });\n });\n\n expect(mockAuthApi.getToken).not.toHaveBeenCalled();\n });\n\n it(\"should refetch token when userToken changes\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result, rerender } = renderHook(\n ({ userToken }) =>\n useTamboSessionToken(mockTamboAI, queryClient, userToken),\n {\n initialProps: { userToken: \"user-token-1\" },\n },\n );\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(1);\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(2);\n\n // Mock response for new token\n mockAuthApi.getToken.mockResolvedValue({\n ...mockTokenResponse,\n access_token: \"new-access-token\",\n });\n\n // Change userToken\n act(() => {\n rerender({ userToken: \"user-token-2\" });\n });\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: { access_token: \"new-access-token\" },\n isFetching: false,\n });\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(4);\n });\n\n it(\"should reset token when userToken becomes null\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result, rerender } = renderHook(\n ({ userToken }) =>\n useTamboSessionToken(mockTamboAI, queryClient, userToken),\n {\n initialProps: { userToken: \"user-token\" as string | undefined },\n },\n );\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n\n // Change userToken to undefined\n rerender({ userToken: undefined });\n await act(async () => {\n await jest.runAllTimersAsync();\n });\n\n // Token should reset to null (hook doesn't reset it to null when userToken is undefined)\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: false,\n });\n });\n\n it(\"should not update state if component is unmounted during token fetch\", async () => {\n let resolvePromise: (value: any) => void;\n const promise = new Promise((resolve) => {\n resolvePromise = resolve;\n });\n\n mockAuthApi.getToken.mockReturnValue(promise);\n\n const { result, unmount } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n // Unmount before the promise resolves\n unmount();\n\n // Now resolve the promise\n act(() => {\n resolvePromise!(mockTokenResponse);\n });\n\n // Token should still be null since component was unmounted\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n });\n\n it(\"should set isUpdating to true while fetching token\", () => {\n mockAuthApi.getToken.mockImplementation(async () => {\n return await new Promise(() => {}); // Never resolves\n });\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n // Should be updating immediately when userToken is provided\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n });\n\n it(\"should set isUpdating to false after token fetch completes\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n // Should be updating initially\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n // Should not be updating after completion\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n });\n\n it(\"should set isUpdating to false after token fetch fails\", async () => {\n mockAuthApi.getToken.mockRejectedValue(new Error(\"Token fetch failed\"));\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n // Should be updating initially\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n await act(async () => {\n await jest.runAllTimersAsync();\n });\n\n // Should not be updating after failure\n expect(result.current).toMatchObject({\n data: undefined,\n error: expect.any(Error),\n isFetching: false,\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-session-token.test.js","sourceRoot":"","sources":["../../../src/providers/hooks/use-tambo-session-token.test.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,MAAM,iBAAiB,GAAG;QACxB,YAAY,EAAE,mBAAmB;QACjC,UAAU,EAAE,IAAI,EAAE,SAAS;QAC3B,UAAU,EAAE,QAAQ;KACrB,CAAC;IAEF,MAAM,WAAW,GAAG;QAClB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;KACkC,CAAC;IAExD,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,WAAW;KACe,CAAC;IAEnC,MAAM,WAAW,GAAG;QAClB,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,EAAE;KACoC,CAAC;IACjD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;QAClC,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MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;YACnC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,uCAAuC;QACvC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;YACnC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { act, renderHook } from \"@testing-library/react\";\nimport { useTamboSessionToken } from \"./use-tambo-session-token\";\nimport type { PartialTamboAI } from \"../../testing/types\";\n\ndescribe(\"useTamboSessionToken\", () => {\n const mockTokenResponse = {\n access_token: \"test-access-token\",\n expires_in: 3600, // 1 hour\n token_type: \"Bearer\",\n };\n\n const mockAuthApi = {\n getToken: jest.fn(),\n } satisfies NonNullable<PartialTamboAI[\"beta\"]>[\"auth\"];\n\n const mockBeta = {\n auth: mockAuthApi,\n } satisfies PartialTamboAI[\"beta\"];\n\n const mockTamboAI = {\n apiKey: \"\",\n beta: mockBeta,\n bearer: \"\",\n } satisfies PartialTamboAI as unknown as TamboAI;\n const queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n retry: false,\n refetchOnWindowFocus: false,\n },\n },\n });\n\n beforeEach(() => {\n jest.clearAllMocks();\n jest.clearAllTimers();\n jest.useFakeTimers();\n (mockTamboAI as any).bearer = \"\";\n queryClient.clear();\n });\n\n afterEach(async () => {\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n jest.useRealTimers();\n jest.resetAllMocks();\n });\n\n it(\"should return null initially when no userToken is provided\", () => {\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, undefined),\n );\n\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: false,\n });\n expect(mockAuthApi.getToken).not.toHaveBeenCalled();\n });\n\n it(\"should fetch and return session token when userToken is provided\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(1);\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n expect(mockTamboAI.bearer).toBe(mockTokenResponse.access_token);\n // Verify the hook was called with correct parameters\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(2);\n expect(mockAuthApi.getToken).toHaveBeenCalledWith(expect.any(Object));\n });\n\n it(\"should call getToken with correct token exchange parameters\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n const callArgs = mockAuthApi.getToken.mock.calls[0][0];\n const tokenRequestString = new TextDecoder().decode(callArgs);\n const tokenRequest = new URLSearchParams(tokenRequestString);\n\n expect(tokenRequest.get(\"grant_type\")).toBe(\n \"urn:ietf:params:oauth:grant-type:token-exchange\",\n );\n expect(tokenRequest.get(\"subject_token\")).toBe(\"user-token\");\n expect(tokenRequest.get(\"subject_token_type\")).toBe(\n \"urn:ietf:params:oauth:token-type:access_token\",\n );\n });\n\n it(\"should set bearer token on client\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n });\n expect(mockTamboAI.bearer).toBe(\"test-access-token\");\n });\n\n it(\"should handle different token responses\", async () => {\n const customTokenResponse = {\n access_token: \"custom-access-token\",\n expires_in: 7200, // 2 hours\n token_type: \"Bearer\",\n };\n\n mockAuthApi.getToken.mockResolvedValue(customTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: customTokenResponse,\n isFetching: false,\n });\n expect(mockTamboAI.bearer).toBe(\"custom-access-token\");\n });\n\n it(\"should not fetch token when userToken changes to undefined\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result, rerender } = renderHook(\n ({ userToken }) =>\n useTamboSessionToken(mockTamboAI, queryClient, userToken),\n {\n initialProps: { userToken: \"user-token\" as string | undefined },\n },\n );\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(1);\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(2);\n\n // Clear mock and change userToken to undefined\n jest.clearAllMocks();\n\n act(() => {\n rerender({ userToken: undefined });\n });\n\n expect(mockAuthApi.getToken).not.toHaveBeenCalled();\n });\n\n it(\"should refetch token when userToken changes\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result, rerender } = renderHook(\n ({ userToken }) =>\n useTamboSessionToken(mockTamboAI, queryClient, userToken),\n {\n initialProps: { userToken: \"user-token-1\" },\n },\n );\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(1);\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(2);\n\n // Mock response for new token\n mockAuthApi.getToken.mockResolvedValue({\n ...mockTokenResponse,\n access_token: \"new-access-token\",\n });\n\n // Change userToken\n act(() => {\n rerender({ userToken: \"user-token-2\" });\n });\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: { access_token: \"new-access-token\" },\n isFetching: false,\n });\n expect(mockAuthApi.getToken).toHaveBeenCalledTimes(4);\n });\n\n it(\"should reset token when userToken becomes null\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result, rerender } = renderHook(\n ({ userToken }) =>\n useTamboSessionToken(mockTamboAI, queryClient, userToken),\n {\n initialProps: { userToken: \"user-token\" as string | undefined },\n },\n );\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n\n // Change userToken to undefined\n rerender({ userToken: undefined });\n await act(async () => {\n await jest.runAllTimersAsync();\n });\n\n // Token should reset to null (hook doesn't reset it to null when userToken is undefined)\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: false,\n });\n });\n\n it(\"should not update state if component is unmounted during token fetch\", async () => {\n let resolvePromise: (value: any) => void;\n const promise = new Promise((resolve) => {\n resolvePromise = resolve;\n });\n\n mockAuthApi.getToken.mockReturnValue(promise);\n\n const { result, unmount } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n // Unmount before the promise resolves\n unmount();\n\n // Now resolve the promise\n act(() => {\n resolvePromise!(mockTokenResponse);\n });\n\n // Token should still be null since component was unmounted\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n });\n\n it(\"should set isUpdating to true while fetching token\", () => {\n mockAuthApi.getToken.mockImplementation(async () => {\n return await new Promise(() => {}); // Never resolves\n });\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n // Should be updating immediately when userToken is provided\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n });\n\n it(\"should set isUpdating to false after token fetch completes\", async () => {\n mockAuthApi.getToken.mockResolvedValue(mockTokenResponse);\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n // Should be updating initially\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n await act(async () => {\n await jest.runOnlyPendingTimersAsync();\n });\n\n // Should not be updating after completion\n expect(result.current).toMatchObject({\n data: mockTokenResponse,\n isFetching: false,\n });\n });\n\n it(\"should set isUpdating to false after token fetch fails\", async () => {\n mockAuthApi.getToken.mockRejectedValue(new Error(\"Token fetch failed\"));\n\n const { result } = renderHook(() =>\n useTamboSessionToken(mockTamboAI, queryClient, \"user-token\"),\n );\n\n // Should be updating initially\n expect(result.current).toMatchObject({\n data: undefined,\n isFetching: true,\n });\n\n await act(async () => {\n await jest.runAllTimersAsync();\n });\n\n // Should not be updating after failure\n expect(result.current).toMatchObject({\n data: undefined,\n error: expect.any(Error),\n isFetching: false,\n });\n });\n});\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { RegisterToolFn, RegisterToolsFn, TamboComponent, TamboTool
|
|
2
|
+
import { RegisterToolFn, RegisterToolsFn, TamboComponent, TamboTool } from "../model/component-metadata";
|
|
3
3
|
export interface TamboComponentContextProps {
|
|
4
4
|
registerComponent: (options: TamboComponent) => void;
|
|
5
5
|
registerTool: RegisterToolFn;
|
|
6
6
|
registerTools: RegisterToolsFn;
|
|
7
|
-
addToolAssociation: (componentName: string, tool: TamboTool
|
|
7
|
+
addToolAssociation: (componentName: string, tool: TamboTool) => void;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* The TamboComponentProvider is a React provider that provides component
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-component-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-component-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,
|
|
1
|
+
{"version":3,"file":"tambo-component-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-component-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,EACV,MAAM,6BAA6B,CAAC;AAIrC,MAAM,WAAW,0BAA0B;IACzC,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,cAAc,CAAC;IAC7B,aAAa,EAAE,eAAe,CAAC;IAC/B,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACtE;AAqBD;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAoB9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,kCAE7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-component-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-component-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"tambo-component-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-component-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;AAO5E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAS7D,MAAM,qBAAqB,GAAG,aAAa,CAA6B;IACtE;;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,EAAE,GAAG,EAAE,GAAE,CAAC;CAC7B,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgC,CAAC,EAClE,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,GAC1E,gBAAgB,EAAE,CAAC;IAErB,MAAM,KAAK,GAAG;QACZ,MAAM;QACN,iBAAiB;QACjB,YAAY;QACZ,aAAa;QACb,kBAAkB;KACnB,CAAC;IAEF,OAAO,CACL,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACzC,QAAQ,CACsB,CAClC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,OAAO,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport {\n RegisterToolFn,\n RegisterToolsFn,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\nimport { useTamboClient } from \"./tambo-client-provider\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\nexport interface TamboComponentContextProps {\n registerComponent: (options: TamboComponent) => void;\n registerTool: RegisterToolFn;\n registerTools: RegisterToolsFn;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboComponentContext = createContext<TamboComponentContextProps>({\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\n/**\n * The TamboComponentProvider is a React provider that provides component\n * registration services to the descendants of the provider.\n * @param props - The props for the TamboComponentProvider\n * @param props.children - The children to wrap\n * @returns The TamboComponentProvider component\n */\nexport const TamboComponentProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const client = useTamboClient();\n const { registerComponent, addToolAssociation, registerTool, registerTools } =\n useTamboRegistry();\n\n const value = {\n client,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n };\n\n return (\n <TamboComponentContext.Provider value={value}>\n {children}\n </TamboComponentContext.Provider>\n );\n};\n\n/**\n * The useTamboComponent hook provides access to the component registration\n * services to the descendants of the TamboComponentProvider.\n * @returns The component registration services\n */\nexport const useTamboComponent = () => {\n return useContext(TamboComponentContext);\n};\n"]}
|
|
@@ -36,7 +36,7 @@ export declare const useCurrentInteractablesSnapshot: () => {
|
|
|
36
36
|
propsSchema?: import("../schema").SupportedSchema;
|
|
37
37
|
propsDefinition?: any;
|
|
38
38
|
loadingComponent?: React.ComponentType<any>;
|
|
39
|
-
associatedTools?:
|
|
39
|
+
associatedTools?: import(".").TamboTool[];
|
|
40
40
|
annotations?: import("..").ToolAnnotations;
|
|
41
41
|
}[];
|
|
42
42
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type TamboAI from "@tambo-ai/typescript-sdk";
|
|
2
2
|
import React, { PropsWithChildren } from "react";
|
|
3
|
-
import type { ComponentRegistry, RegisterToolFn, RegisterToolsFn, TamboComponent, TamboTool, TamboToolRegistry
|
|
3
|
+
import type { ComponentRegistry, RegisterToolFn, RegisterToolsFn, TamboComponent, TamboTool, TamboToolRegistry } from "../model/component-metadata";
|
|
4
4
|
import type { McpServerInfo, NormalizedMcpServerInfo } from "../model/mcp-server-info";
|
|
5
5
|
import type { ListResourceItem, ResourceSource } from "../model/resource-info";
|
|
6
6
|
export interface TamboRegistryContext {
|
|
@@ -10,10 +10,10 @@ export interface TamboRegistryContext {
|
|
|
10
10
|
mcpServerInfos: NormalizedMcpServerInfo[];
|
|
11
11
|
resources: ListResourceItem[];
|
|
12
12
|
resourceSource: ResourceSource | null;
|
|
13
|
-
registerComponent: (options: TamboComponent) => void;
|
|
13
|
+
registerComponent: (options: TamboComponent, warnOnOverwrite?: boolean) => void;
|
|
14
14
|
registerTool: RegisterToolFn;
|
|
15
15
|
registerTools: RegisterToolsFn;
|
|
16
|
-
addToolAssociation: (componentName: string, tool: TamboTool
|
|
16
|
+
addToolAssociation: (componentName: string, tool: TamboTool) => void;
|
|
17
17
|
registerMcpServer: (info: McpServerInfo) => void;
|
|
18
18
|
registerMcpServers: (infos: McpServerInfo[]) => void;
|
|
19
19
|
registerResource: (resource: ListResourceItem) => void;
|
|
@@ -26,7 +26,7 @@ export interface TamboRegistryProviderProps {
|
|
|
26
26
|
/** The components to register */
|
|
27
27
|
components?: TamboComponent[];
|
|
28
28
|
/** The tools to register */
|
|
29
|
-
tools?:
|
|
29
|
+
tools?: TamboTool[];
|
|
30
30
|
/** The MCP servers to register */
|
|
31
31
|
mcpServers?: (McpServerInfo | string)[];
|
|
32
32
|
/** The static resources to register */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,EACT,iBAAiB,
|
|
1
|
+
{"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAe/E,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,YAAY,EAAE,iBAAiB,CAAC;IAChC,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,cAAc,EAAE,uBAAuB,EAAE,CAAC;IAC1C,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,iBAAiB,EAAE,CACjB,OAAO,EAAE,cAAc,EACvB,eAAe,CAAC,EAAE,OAAO,KACtB,IAAI,CAAC;IACV,YAAY,EAAE,cAAc,CAAC;IAC7B,aAAa,EAAE,eAAe,CAAC;IAC/B,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACrE,iBAAiB,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD,kBAAkB,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,IAAI,CAAC;IACrD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACvD,iBAAiB,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;IAC3D,sBAAsB,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IACzD,sBAAsB,CAAC,EAAE,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAC9B,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,eAAO,MAAM,oBAAoB,qCA2C/B,CAAC;AAEH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,kCAAkC;IAClC,UAAU,CAAC,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IACxC,uCAAuC;IACvC,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAE/B;;;OAGG;IACH,aAAa,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAEhD;;;OAGG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;IAE5C;;;;;;;OAOG;IACH,sBAAsB,CAAC,EAAE,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAC9B,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,iBAAiB,CAAC,0BAA0B,CAAC,CA8N9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAE5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,sBAAsB,QAAO,uBAAuB,EAEhE,CAAC"}
|
|
@@ -69,21 +69,24 @@ export const TamboRegistryProvider = ({ children, components: userComponents, to
|
|
|
69
69
|
const [dynamicMcpServerInfos, setDynamicMcpServerInfos] = useState([]);
|
|
70
70
|
const [staticResources, setStaticResources] = useState([]);
|
|
71
71
|
const [resourceSource, setResourceSource] = useState(null);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
72
|
+
const registryWithTool = useCallback((warnOnOverwrite) => {
|
|
73
|
+
return (registry, tool) => {
|
|
74
|
+
validateTool(tool);
|
|
75
|
+
if (registry[tool.name] && warnOnOverwrite) {
|
|
76
76
|
console.warn(`Overwriting tool ${tool.name}`);
|
|
77
77
|
}
|
|
78
78
|
return {
|
|
79
|
-
...
|
|
79
|
+
...registry,
|
|
80
80
|
[tool.name]: tool,
|
|
81
81
|
};
|
|
82
|
-
}
|
|
82
|
+
};
|
|
83
83
|
}, []);
|
|
84
|
+
const registerTool = useCallback((tool, warnOnOverwrite = true) => {
|
|
85
|
+
setToolRegistry((registry) => registryWithTool(warnOnOverwrite)(registry, tool));
|
|
86
|
+
}, [registryWithTool]);
|
|
84
87
|
const registerTools = useCallback((tools, warnOnOverwrite = true) => {
|
|
85
|
-
|
|
86
|
-
}, [
|
|
88
|
+
setToolRegistry((existingRegistry) => tools.reduce(registryWithTool(warnOnOverwrite), existingRegistry));
|
|
89
|
+
}, [registryWithTool]);
|
|
87
90
|
const registerMcpServer = useCallback((info) => {
|
|
88
91
|
const normalized = normalizeServerInfo(info);
|
|
89
92
|
setDynamicMcpServerInfos((prev) => [...prev, normalized]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AAef,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,uBAAuB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AA8B,EAAE;IACpE,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC,cAAc,CAAC;AACzD,CAAC,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 type {\n ComponentRegistry,\n RegisterToolFn,\n RegisterToolsFn,\n TamboComponent,\n TamboTool,\n TamboToolRegistry,\n TamboToolWithToolSchema,\n} from \"../model/component-metadata\";\nimport type {\n McpServerInfo,\n NormalizedMcpServerInfo,\n} from \"../model/mcp-server-info\";\nimport type { ListResourceItem, ResourceSource } from \"../model/resource-info\";\nimport {\n deduplicateMcpServers,\n normalizeServerInfo,\n} from \"../util/mcp-server-utils\";\nimport {\n validateAndPrepareComponent,\n validateTool,\n validateToolAssociation,\n} from \"../util/registry-validators\";\nimport {\n validateResource,\n validateResourceSource,\n} from \"../util/resource-validators\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: TamboToolRegistry;\n componentToolAssociations: Record<string, string[]>;\n mcpServerInfos: NormalizedMcpServerInfo[];\n resources: ListResourceItem[];\n resourceSource: ResourceSource | null;\n registerComponent: (options: TamboComponent) => void;\n registerTool: RegisterToolFn;\n registerTools: RegisterToolsFn;\n addToolAssociation: (\n componentName: string,\n tool: TamboTool | TamboToolWithToolSchema,\n ) => void;\n registerMcpServer: (info: McpServerInfo) => void;\n registerMcpServers: (infos: McpServerInfo[]) => void;\n registerResource: (resource: ListResourceItem) => void;\n registerResources: (resources: ListResourceItem[]) => void;\n registerResourceSource: (source: ResourceSource) => 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 resources: [],\n resourceSource: null,\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 *\n */\n registerResource: () => {},\n /**\n *\n */\n registerResources: () => {},\n /**\n *\n */\n registerResourceSource: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n /** The tools to register */\n tools?: (TamboTool | TamboToolWithToolSchema)[];\n /** The MCP servers to register */\n mcpServers?: (McpServerInfo | string)[];\n /** The static resources to register */\n resources?: ListResourceItem[];\n\n /**\n * Dynamic resource search function. Must be paired with getResource.\n * Called when useTamboMcpResourceList() is used to fetch resources.\n */\n listResources?: ResourceSource[\"listResources\"];\n\n /**\n * Dynamic resource fetch function. Must be paired with listResources.\n * Called when useTamboMcpResource() is used to fetch a specific resource.\n */\n getResource?: ResourceSource[\"getResource\"];\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.resources - The static resources to register\n * @param props.listResources - The dynamic resource search function (must be paired with getResource)\n * @param props.getResource - The dynamic resource fetch function (must be paired with listResources)\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 resources: userResources,\n listResources: userListResources,\n getResource: userGetResource,\n onCallUnregisteredTool,\n}) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<TamboToolRegistry>({});\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 const [staticResources, setStaticResources] = useState<ListResourceItem[]>(\n [],\n );\n const [resourceSource, setResourceSource] = useState<ResourceSource | null>(\n null,\n );\n\n const registerTool = useCallback(\n (tool: TamboTool | TamboToolWithToolSchema, warnOnOverwrite = true) => {\n validateTool(tool);\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 (\n tools: (TamboTool | TamboToolWithToolSchema)[],\n warnOnOverwrite = true,\n ) => {\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 | TamboToolWithToolSchema) => {\n validateToolAssociation(\n componentName,\n tool.name,\n !!componentList[componentName],\n !!toolRegistry[tool.name],\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 loadingComponent,\n associatedTools,\n } = options;\n\n const { props } = validateAndPrepareComponent(options);\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 useEffect(() => {\n // Validate that listResources and getResource are both provided or both omitted\n validateResourceSource(userListResources, userGetResource);\n\n // Set static resources from props\n if (userResources) {\n userResources.forEach((resource) => validateResource(resource));\n setStaticResources(userResources);\n } else {\n setStaticResources([]);\n }\n\n // Set resource source from props\n if (userListResources && userGetResource) {\n setResourceSource({\n listResources: userListResources,\n getResource: userGetResource,\n });\n } else {\n setResourceSource(null);\n }\n }, [userResources, userListResources, userGetResource]);\n\n const registerResource = useCallback((resource: ListResourceItem) => {\n validateResource(resource);\n setStaticResources((prev) => [...prev, resource]);\n }, []);\n\n const registerResources = useCallback((resources: ListResourceItem[]) => {\n resources.forEach((resource) => validateResource(resource));\n setStaticResources((prev) => [...prev, ...resources]);\n }, []);\n\n const registerResourceSource = useCallback((source: ResourceSource) => {\n validateResourceSource(source.listResources, source.getResource);\n setResourceSource(source);\n }, []);\n\n const mcpServerInfos: NormalizedMcpServerInfo[] = useMemo(() => {\n const allServers = [...staticMcpServerInfos, ...dynamicMcpServerInfos];\n return deduplicateMcpServers(allServers);\n }, [staticMcpServerInfos, dynamicMcpServerInfos]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n mcpServerInfos,\n resources: staticResources,\n resourceSource,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n registerMcpServer,\n registerMcpServers,\n registerResource,\n registerResources,\n registerResourceSource,\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};\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAA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B,kBAAkB;QAClB,gBAAgB;QAChB,iBAAiB;QACjB,sBAAsB;QACtB,sBAAsB;KACvB,CAAC;IAEF,OAAO,CACL,oBAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACxC,QAAQ,CACqB,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAA8B,EAAE;IACpE,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC,cAAc,CAAC;AACzD,CAAC,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 type {\n ComponentRegistry,\n RegisterToolFn,\n RegisterToolsFn,\n TamboComponent,\n TamboTool,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\nimport type {\n McpServerInfo,\n NormalizedMcpServerInfo,\n} from \"../model/mcp-server-info\";\nimport type { ListResourceItem, ResourceSource } from \"../model/resource-info\";\nimport {\n deduplicateMcpServers,\n normalizeServerInfo,\n} from \"../util/mcp-server-utils\";\nimport {\n validateAndPrepareComponent,\n validateTool,\n validateToolAssociation,\n} from \"../util/registry-validators\";\nimport {\n validateResource,\n validateResourceSource,\n} from \"../util/resource-validators\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: TamboToolRegistry;\n componentToolAssociations: Record<string, string[]>;\n mcpServerInfos: NormalizedMcpServerInfo[];\n resources: ListResourceItem[];\n resourceSource: ResourceSource | null;\n registerComponent: (\n options: TamboComponent,\n warnOnOverwrite?: boolean,\n ) => void;\n registerTool: RegisterToolFn;\n registerTools: RegisterToolsFn;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n registerMcpServer: (info: McpServerInfo) => void;\n registerMcpServers: (infos: McpServerInfo[]) => void;\n registerResource: (resource: ListResourceItem) => void;\n registerResources: (resources: ListResourceItem[]) => void;\n registerResourceSource: (source: ResourceSource) => 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 resources: [],\n resourceSource: null,\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 *\n */\n registerResource: () => {},\n /**\n *\n */\n registerResources: () => {},\n /**\n *\n */\n registerResourceSource: () => {},\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 /** The static resources to register */\n resources?: ListResourceItem[];\n\n /**\n * Dynamic resource search function. Must be paired with getResource.\n * Called when useTamboMcpResourceList() is used to fetch resources.\n */\n listResources?: ResourceSource[\"listResources\"];\n\n /**\n * Dynamic resource fetch function. Must be paired with listResources.\n * Called when useTamboMcpResource() is used to fetch a specific resource.\n */\n getResource?: ResourceSource[\"getResource\"];\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.resources - The static resources to register\n * @param props.listResources - The dynamic resource search function (must be paired with getResource)\n * @param props.getResource - The dynamic resource fetch function (must be paired with listResources)\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 resources: userResources,\n listResources: userListResources,\n getResource: userGetResource,\n onCallUnregisteredTool,\n}) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<TamboToolRegistry>({});\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 const [staticResources, setStaticResources] = useState<ListResourceItem[]>(\n [],\n );\n const [resourceSource, setResourceSource] = useState<ResourceSource | null>(\n null,\n );\n\n const registryWithTool = useCallback((warnOnOverwrite: boolean) => {\n return (registry: TamboToolRegistry, tool: unknown): TamboToolRegistry => {\n validateTool(tool);\n\n if (registry[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n\n return {\n ...registry,\n [tool.name]: tool,\n };\n };\n }, []);\n\n const registerTool = useCallback<RegisterToolFn>(\n (tool: unknown, warnOnOverwrite = true) => {\n setToolRegistry((registry) =>\n registryWithTool(warnOnOverwrite)(registry, tool),\n );\n },\n [registryWithTool],\n );\n\n const registerTools = useCallback<RegisterToolsFn>(\n (tools, warnOnOverwrite = true) => {\n setToolRegistry((existingRegistry) =>\n tools.reduce(registryWithTool(warnOnOverwrite), existingRegistry),\n );\n },\n [registryWithTool],\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 validateToolAssociation(\n componentName,\n tool.name,\n !!componentList[componentName],\n !!toolRegistry[tool.name],\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 loadingComponent,\n associatedTools,\n } = options;\n\n const { props } = validateAndPrepareComponent(options);\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 useEffect(() => {\n // Validate that listResources and getResource are both provided or both omitted\n validateResourceSource(userListResources, userGetResource);\n\n // Set static resources from props\n if (userResources) {\n userResources.forEach((resource) => validateResource(resource));\n setStaticResources(userResources);\n } else {\n setStaticResources([]);\n }\n\n // Set resource source from props\n if (userListResources && userGetResource) {\n setResourceSource({\n listResources: userListResources,\n getResource: userGetResource,\n });\n } else {\n setResourceSource(null);\n }\n }, [userResources, userListResources, userGetResource]);\n\n const registerResource = useCallback((resource: ListResourceItem) => {\n validateResource(resource);\n setStaticResources((prev) => [...prev, resource]);\n }, []);\n\n const registerResources = useCallback((resources: ListResourceItem[]) => {\n resources.forEach((resource) => validateResource(resource));\n setStaticResources((prev) => [...prev, ...resources]);\n }, []);\n\n const registerResourceSource = useCallback((source: ResourceSource) => {\n validateResourceSource(source.listResources, source.getResource);\n setResourceSource(source);\n }, []);\n\n const mcpServerInfos: NormalizedMcpServerInfo[] = useMemo(() => {\n const allServers = [...staticMcpServerInfos, ...dynamicMcpServerInfos];\n return deduplicateMcpServers(allServers);\n }, [staticMcpServerInfos, dynamicMcpServerInfos]);\n\n const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n mcpServerInfos,\n resources: staticResources,\n resourceSource,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\n registerMcpServer,\n registerMcpServers,\n registerResource,\n registerResources,\n registerResourceSource,\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};\n"]}
|
|
@@ -106,6 +106,37 @@ describe("TamboRegistryProvider", () => {
|
|
|
106
106
|
});
|
|
107
107
|
expect(result.current.toolRegistry["max-tool"].maxCalls).toBe(4);
|
|
108
108
|
});
|
|
109
|
+
it("should warn when overwriting an existing tool by default", () => {
|
|
110
|
+
const wrapper = ({ children }) => (React.createElement(TamboRegistryProvider, null, children));
|
|
111
|
+
const { result } = renderHook(() => useTamboRegistry(), { wrapper });
|
|
112
|
+
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
113
|
+
// Register a tool
|
|
114
|
+
act(() => {
|
|
115
|
+
result.current.registerTool(mockTools[0]);
|
|
116
|
+
});
|
|
117
|
+
// Register the same tool again (should warn by default)
|
|
118
|
+
act(() => {
|
|
119
|
+
result.current.registerTool(mockTools[0]);
|
|
120
|
+
});
|
|
121
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining("Overwriting tool test-tool-1"));
|
|
122
|
+
consoleWarnSpy.mockRestore();
|
|
123
|
+
});
|
|
124
|
+
it("should not warn when overwriting a tool if warnOnOverwrite is false", () => {
|
|
125
|
+
const wrapper = ({ children }) => (React.createElement(TamboRegistryProvider, null, children));
|
|
126
|
+
const { result } = renderHook(() => useTamboRegistry(), { wrapper });
|
|
127
|
+
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
128
|
+
// Register a tool
|
|
129
|
+
act(() => {
|
|
130
|
+
result.current.registerTool(mockTools[0], false);
|
|
131
|
+
});
|
|
132
|
+
// Register the same tool again with warnOnOverwrite=false
|
|
133
|
+
act(() => {
|
|
134
|
+
result.current.registerTool(mockTools[0], false);
|
|
135
|
+
});
|
|
136
|
+
// Should not warn about "Registering new tool"
|
|
137
|
+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(expect.stringContaining("Overwriting tool test-tool-1"));
|
|
138
|
+
consoleWarnSpy.mockRestore();
|
|
139
|
+
});
|
|
109
140
|
it("should handle tool association with components", () => {
|
|
110
141
|
const wrapper = ({ children }) => (React.createElement(TamboRegistryProvider, { components: mockComponents }, children));
|
|
111
142
|
const { result } = renderHook(() => useTamboRegistry(), { wrapper });
|