@tambo-ai/react 0.57.0 → 0.58.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 +36 -0
- package/dist/hooks/react-query-hooks.d.ts +4 -4
- package/dist/hooks/react-query-hooks.js +4 -4
- package/dist/hooks/react-query-hooks.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +9 -0
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/model/component-metadata.d.ts +7 -0
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +18 -5
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/testing/tools.d.ts +1 -0
- package/dist/testing/tools.d.ts.map +1 -1
- package/dist/util/__tests__/content-parts.test.d.ts +2 -0
- package/dist/util/__tests__/content-parts.test.d.ts.map +1 -0
- package/dist/util/__tests__/content-parts.test.js +47 -0
- package/dist/util/__tests__/content-parts.test.js.map +1 -0
- package/dist/util/content-parts.d.ts +19 -0
- package/dist/util/content-parts.d.ts.map +1 -0
- package/dist/util/content-parts.js +40 -0
- package/dist/util/content-parts.js.map +1 -0
- package/dist/util/tool-caller.d.ts +4 -3
- package/dist/util/tool-caller.d.ts.map +1 -1
- package/dist/util/tool-caller.js +9 -5
- package/dist/util/tool-caller.js.map +1 -1
- package/esm/hooks/react-query-hooks.d.ts +4 -4
- package/esm/hooks/react-query-hooks.js +4 -4
- package/esm/hooks/react-query-hooks.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +9 -0
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/model/component-metadata.d.ts +7 -0
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +18 -5
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/testing/tools.d.ts +1 -0
- package/esm/testing/tools.d.ts.map +1 -1
- package/esm/util/__tests__/content-parts.test.d.ts +2 -0
- package/esm/util/__tests__/content-parts.test.d.ts.map +1 -0
- package/esm/util/__tests__/content-parts.test.js +45 -0
- package/esm/util/__tests__/content-parts.test.js.map +1 -0
- package/esm/util/content-parts.d.ts +19 -0
- package/esm/util/content-parts.d.ts.map +1 -0
- package/esm/util/content-parts.js +35 -0
- package/esm/util/content-parts.js.map +1 -0
- package/esm/util/tool-caller.d.ts +4 -3
- package/esm/util/tool-caller.d.ts.map +1 -1
- package/esm/util/tool-caller.js +9 -5
- package/esm/util/tool-caller.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow a value to a ChatCompletionContentPart by checking for an object with string `type`.
|
|
3
|
+
* We purposefully keep this guard permissive to support future part types.
|
|
4
|
+
* @returns true if the value looks like a content part
|
|
5
|
+
*/
|
|
6
|
+
export function isContentPart(val) {
|
|
7
|
+
return (!!val &&
|
|
8
|
+
typeof val === "object" &&
|
|
9
|
+
"type" in val &&
|
|
10
|
+
typeof val.type === "string");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard for arrays of content parts.
|
|
14
|
+
* @returns true if the value is an array of content parts
|
|
15
|
+
*/
|
|
16
|
+
export function isContentPartArray(val) {
|
|
17
|
+
return Array.isArray(val) && val.every((item) => isContentPart(item));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Safely convert an unknown value to a string suitable for a `{ type: "text" }` content part.
|
|
21
|
+
* Guarantees a string and avoids throwing on circular structures.
|
|
22
|
+
* @returns The string representation of the value
|
|
23
|
+
*/
|
|
24
|
+
export function toText(val) {
|
|
25
|
+
if (typeof val === "string")
|
|
26
|
+
return val;
|
|
27
|
+
try {
|
|
28
|
+
const json = JSON.stringify(val);
|
|
29
|
+
return json ?? String(val);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return String(val);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=content-parts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-parts.js","sourceRoot":"","sources":["../../src/util/content-parts.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAY;IAEZ,OAAO,CACL,CAAC,CAAC,GAAG;QACL,OAAO,GAAG,KAAK,QAAQ;QACvB,MAAM,IAAK,GAAW;QACtB,OAAQ,GAAW,CAAC,IAAI,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAY;IAEZ,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,GAAY;IACjC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACjC,OAAO,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import type TamboAI from \"@tambo-ai/typescript-sdk\";\n\n/**\n * Narrow a value to a ChatCompletionContentPart by checking for an object with string `type`.\n * We purposefully keep this guard permissive to support future part types.\n * @returns true if the value looks like a content part\n */\nexport function isContentPart(\n val: unknown,\n): val is TamboAI.Beta.Threads.ChatCompletionContentPart {\n return (\n !!val &&\n typeof val === \"object\" &&\n \"type\" in (val as any) &&\n typeof (val as any).type === \"string\"\n );\n}\n\n/**\n * Type guard for arrays of content parts.\n * @returns true if the value is an array of content parts\n */\nexport function isContentPartArray(\n val: unknown,\n): val is TamboAI.Beta.Threads.ChatCompletionContentPart[] {\n return Array.isArray(val) && val.every((item) => isContentPart(item));\n}\n\n/**\n * Safely convert an unknown value to a string suitable for a `{ type: \"text\" }` content part.\n * Guarantees a string and avoids throwing on circular structures.\n * @returns The string representation of the value\n */\nexport function toText(val: unknown): string {\n if (typeof val === \"string\") return val;\n try {\n const json = JSON.stringify(val);\n return json ?? String(val);\n } catch {\n return String(val);\n }\n}\n"]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import TamboAI from "@tambo-ai/typescript-sdk";
|
|
2
|
-
import { TamboToolRegistry } from "../model/component-metadata";
|
|
2
|
+
import { TamboTool, TamboToolRegistry } from "../model/component-metadata";
|
|
3
3
|
/**
|
|
4
4
|
* Process a message from the thread, invoking the appropriate tool and returning the result.
|
|
5
5
|
* @param message - The message to handle
|
|
6
6
|
* @param toolRegistry - The tool registry
|
|
7
|
-
* @returns The result of the tool call
|
|
7
|
+
* @returns The result of the tool call along with the tool definition
|
|
8
8
|
*/
|
|
9
9
|
export declare const handleToolCall: (message: TamboAI.Beta.Threads.ThreadMessage, toolRegistry: TamboToolRegistry, onCallUnregisteredTool?: (toolName: string, args: TamboAI.ToolCallParameter[]) => Promise<string>) => Promise<{
|
|
10
|
-
result:
|
|
10
|
+
result: unknown;
|
|
11
11
|
error?: string;
|
|
12
|
+
tamboTool?: TamboTool;
|
|
12
13
|
}>;
|
|
13
14
|
//# sourceMappingURL=tool-caller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-caller.d.ts","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAEL,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAGrC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAC3C,cAAc,iBAAiB,EAC/B,yBAAyB,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAC9B,OAAO,CAAC,MAAM,CAAC,KACnB,OAAO,CAAC;IACT,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"tool-caller.d.ts","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAEL,SAAS,EACT,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAGrC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAC3C,cAAc,iBAAiB,EAC/B,yBAAyB,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAC9B,OAAO,CAAC,MAAM,CAAC,KACnB,OAAO,CAAC;IACT,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAmCA,CAAC"}
|
package/esm/util/tool-caller.js
CHANGED
|
@@ -3,14 +3,14 @@ import { mapTamboToolToContextTool } from "./registry";
|
|
|
3
3
|
* Process a message from the thread, invoking the appropriate tool and returning the result.
|
|
4
4
|
* @param message - The message to handle
|
|
5
5
|
* @param toolRegistry - The tool registry
|
|
6
|
-
* @returns The result of the tool call
|
|
6
|
+
* @returns The result of the tool call along with the tool definition
|
|
7
7
|
*/
|
|
8
8
|
export const handleToolCall = async (message, toolRegistry, onCallUnregisteredTool) => {
|
|
9
9
|
if (!message?.toolCallRequest?.toolName) {
|
|
10
10
|
throw new Error("Tool name is required");
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
13
|
-
const tool = findTool(message.toolCallRequest.toolName, toolRegistry);
|
|
13
|
+
const { tool, tamboTool } = findTool(message.toolCallRequest.toolName, toolRegistry);
|
|
14
14
|
if (!tool) {
|
|
15
15
|
if (onCallUnregisteredTool) {
|
|
16
16
|
const result = await onCallUnregisteredTool(message.toolCallRequest.toolName, message.toolCallRequest.parameters);
|
|
@@ -22,6 +22,7 @@ export const handleToolCall = async (message, toolRegistry, onCallUnregisteredTo
|
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
result: await runToolChoice(message.toolCallRequest, tool),
|
|
25
|
+
tamboTool,
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
catch (error) {
|
|
@@ -35,12 +36,15 @@ export const handleToolCall = async (message, toolRegistry, onCallUnregisteredTo
|
|
|
35
36
|
const findTool = (toolName, toolRegistry) => {
|
|
36
37
|
const registryTool = toolRegistry[toolName];
|
|
37
38
|
if (!registryTool) {
|
|
38
|
-
return null;
|
|
39
|
+
return { tool: null, tamboTool: null };
|
|
39
40
|
}
|
|
40
41
|
const contextTool = mapTamboToolToContextTool(registryTool);
|
|
41
42
|
return {
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
tool: {
|
|
44
|
+
getComponentContext: registryTool.tool,
|
|
45
|
+
definition: contextTool,
|
|
46
|
+
},
|
|
47
|
+
tamboTool: registryTool,
|
|
44
48
|
};
|
|
45
49
|
};
|
|
46
50
|
const runToolChoice = async (toolCallRequest, tool) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-caller.js","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-caller.js","sourceRoot":"","sources":["../../src/util/tool-caller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;G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,QAAQ,CAAC,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,WAAW,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;IAC5D,OAAO;QACL,IAAI,EAAE;YACJ,mBAAmB,EAAE,YAAY,CAAC,IAAI;YACtC,UAAU,EAAE,WAAW;SACxB;QACD,SAAS,EAAE,YAAY;KACxB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,KAAK,EACzB,eAAwC,EACxC,IAA0B,EACZ,EAAE;IAChB,mEAAmE;IACnE,MAAM,eAAe,GACnB,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAEzE,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,eAAe,CAAC,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport {\n ComponentContextTool,\n TamboTool,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\nimport { mapTamboToolToContextTool } from \"./registry\";\n\n/**\n * Process a message from the thread, invoking the appropriate tool and returning the result.\n * @param message - The message to handle\n * @param toolRegistry - The tool registry\n * @returns The result of the tool call along with the tool definition\n */\nexport const handleToolCall = async (\n message: TamboAI.Beta.Threads.ThreadMessage,\n toolRegistry: TamboToolRegistry,\n onCallUnregisteredTool?: (\n toolName: string,\n args: TamboAI.ToolCallParameter[],\n ) => Promise<string>,\n): Promise<{\n result: unknown;\n error?: string;\n tamboTool?: TamboTool;\n}> => {\n if (!message?.toolCallRequest?.toolName) {\n throw new Error(\"Tool name is required\");\n }\n\n try {\n const { tool, tamboTool } = findTool(\n message.toolCallRequest.toolName,\n toolRegistry,\n );\n if (!tool) {\n if (onCallUnregisteredTool) {\n const result = await onCallUnregisteredTool(\n message.toolCallRequest.toolName,\n message.toolCallRequest.parameters,\n );\n return {\n result,\n };\n }\n throw new Error(\n `Tool ${message.toolCallRequest.toolName} not found in registry`,\n );\n }\n return {\n result: await runToolChoice(message.toolCallRequest, tool),\n tamboTool,\n };\n } catch (error) {\n console.error(\"Error in calling tool: \", error);\n return {\n result: `When attempting to call tool ${message.toolCallRequest.toolName} the following error occurred: ${error}. Explain to the user that the tool call failed and try again if needed.`,\n error: error instanceof Error ? error.message : \"Unknown error\",\n };\n }\n};\n\nconst findTool = (\n toolName: string,\n toolRegistry: TamboToolRegistry,\n):\n | {\n tool: ComponentContextTool;\n tamboTool: TamboTool;\n }\n | { tool: null; tamboTool: null } => {\n const registryTool = toolRegistry[toolName];\n\n if (!registryTool) {\n return { tool: null, tamboTool: null };\n }\n\n const contextTool = mapTamboToolToContextTool(registryTool);\n return {\n tool: {\n getComponentContext: registryTool.tool,\n definition: contextTool,\n },\n tamboTool: registryTool,\n };\n};\n\nconst runToolChoice = async (\n toolCallRequest: TamboAI.ToolCallRequest,\n tool: ComponentContextTool,\n): Promise<any> => {\n // Assumes parameters are in the order they are defined in the tool\n const parameterValues =\n toolCallRequest.parameters?.map((param) => param.parameterValue) ?? [];\n\n return await tool.getComponentContext(...parameterValues);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tambo-ai/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"description": "React client package for Tambo AI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
68
|
-
"@tambo-ai/typescript-sdk": "^0.
|
|
69
|
-
"@tanstack/react-query": "^5.90.
|
|
67
|
+
"@modelcontextprotocol/sdk": "^1.20.1",
|
|
68
|
+
"@tambo-ai/typescript-sdk": "^0.75.0",
|
|
69
|
+
"@tanstack/react-query": "^5.90.5",
|
|
70
70
|
"fast-equals": "^5.3.2",
|
|
71
71
|
"partial-json": "^0.1.7",
|
|
72
72
|
"react-fast-compare": "^3.2.2",
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
"eslint-plugin-react-hooks": "^6.1.1",
|
|
95
95
|
"jest": "^30.2.0",
|
|
96
96
|
"jest-environment-jsdom": "^30.2.0",
|
|
97
|
-
"lint-staged": "^16.2.
|
|
97
|
+
"lint-staged": "^16.2.4",
|
|
98
98
|
"prettier": "^3.6.2",
|
|
99
99
|
"prettier-2": "npm:prettier@^2",
|
|
100
100
|
"react": "^18.3.1",
|
|
101
101
|
"react-dom": "^18.3.1",
|
|
102
|
-
"ts-jest": "^29.4.
|
|
102
|
+
"ts-jest": "^29.4.5",
|
|
103
103
|
"typescript": "^5.9.3",
|
|
104
104
|
"typescript-eslint": "^8.46.0"
|
|
105
105
|
}
|