@tambo-ai/react 0.19.0 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/react-query-hooks.d.ts +8 -0
- package/dist/hooks/react-query-hooks.d.ts.map +1 -1
- package/dist/hooks/react-query-hooks.js +8 -0
- package/dist/hooks/react-query-hooks.js.map +1 -1
- package/dist/hooks/use-component-state.d.ts +0 -3
- package/dist/hooks/use-component-state.d.ts.map +1 -1
- package/dist/hooks/use-component-state.js +8 -26
- package/dist/hooks/use-component-state.js.map +1 -1
- package/dist/hooks/use-current-message.d.ts +27 -7
- package/dist/hooks/use-current-message.d.ts.map +1 -1
- package/dist/hooks/use-current-message.js +27 -7
- package/dist/hooks/use-current-message.js.map +1 -1
- package/dist/hooks/use-streaming-props.d.ts +0 -2
- package/dist/hooks/use-streaming-props.d.ts.map +1 -1
- package/dist/hooks/use-streaming-props.js +2 -3
- package/dist/hooks/use-streaming-props.js.map +1 -1
- package/dist/hooks/use-suggestions.d.ts +0 -1
- package/dist/hooks/use-suggestions.d.ts.map +1 -1
- package/dist/hooks/use-suggestions.js +0 -1
- package/dist/hooks/use-suggestions.js.map +1 -1
- package/dist/hooks/use-tambo-threads.d.ts +35 -5
- package/dist/hooks/use-tambo-threads.d.ts.map +1 -1
- package/dist/hooks/use-tambo-threads.js +9 -1
- package/dist/hooks/use-tambo-threads.js.map +1 -1
- package/dist/hooks/use-thread-input.d.ts +0 -1
- package/dist/hooks/use-thread-input.d.ts.map +1 -1
- package/dist/hooks/use-thread-input.js +0 -1
- package/dist/hooks/use-thread-input.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/model/component-metadata.d.ts +6 -3
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/model/generate-component-response.d.ts +9 -2
- package/dist/model/generate-component-response.d.ts.map +1 -1
- package/dist/model/generate-component-response.js +5 -0
- package/dist/model/generate-component-response.js.map +1 -1
- package/dist/model/tambo-thread.d.ts +4 -2
- package/dist/model/tambo-thread.d.ts.map +1 -1
- package/dist/model/tambo-thread.js.map +1 -1
- package/dist/model/validate-input.d.ts +5 -0
- package/dist/model/validate-input.d.ts.map +1 -1
- package/dist/model/validate-input.js +5 -1
- package/dist/model/validate-input.js.map +1 -1
- package/dist/providers/tambo-client-provider.d.ts +31 -0
- package/dist/providers/tambo-client-provider.d.ts.map +1 -1
- package/dist/providers/tambo-client-provider.js +21 -0
- package/dist/providers/tambo-client-provider.js.map +1 -1
- package/dist/providers/tambo-component-provider.d.ts +12 -0
- package/dist/providers/tambo-component-provider.d.ts.map +1 -1
- package/dist/providers/tambo-component-provider.js +24 -0
- package/dist/providers/tambo-component-provider.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +18 -1
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +25 -2
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.d.ts +14 -1
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js +25 -0
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts +25 -2
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +32 -26
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/dist/util/generate-component.d.ts +5 -1
- package/dist/util/generate-component.d.ts.map +1 -1
- package/dist/util/generate-component.js +5 -1
- package/dist/util/generate-component.js.map +1 -1
- package/dist/util/query-utils.d.ts +16 -0
- package/dist/util/query-utils.d.ts.map +1 -1
- package/dist/util/query-utils.js +16 -0
- package/dist/util/query-utils.js.map +1 -1
- package/dist/util/registry.d.ts +27 -1
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +29 -4
- package/dist/util/registry.js.map +1 -1
- package/dist/util/tool-caller.d.ts +6 -0
- package/dist/util/tool-caller.d.ts.map +1 -1
- package/dist/util/tool-caller.js +6 -0
- package/dist/util/tool-caller.js.map +1 -1
- package/esm/hooks/react-query-hooks.d.ts +8 -0
- package/esm/hooks/react-query-hooks.d.ts.map +1 -1
- package/esm/hooks/react-query-hooks.js +8 -0
- package/esm/hooks/react-query-hooks.js.map +1 -1
- package/esm/hooks/use-component-state.d.ts +0 -3
- package/esm/hooks/use-component-state.d.ts.map +1 -1
- package/esm/hooks/use-component-state.js +2 -23
- package/esm/hooks/use-component-state.js.map +1 -1
- package/esm/hooks/use-current-message.d.ts +27 -7
- package/esm/hooks/use-current-message.d.ts.map +1 -1
- package/esm/hooks/use-current-message.js +27 -7
- package/esm/hooks/use-current-message.js.map +1 -1
- package/esm/hooks/use-streaming-props.d.ts +0 -2
- package/esm/hooks/use-streaming-props.d.ts.map +1 -1
- package/esm/hooks/use-streaming-props.js +2 -3
- package/esm/hooks/use-streaming-props.js.map +1 -1
- package/esm/hooks/use-suggestions.d.ts +0 -1
- package/esm/hooks/use-suggestions.d.ts.map +1 -1
- package/esm/hooks/use-suggestions.js +0 -1
- package/esm/hooks/use-suggestions.js.map +1 -1
- package/esm/hooks/use-tambo-threads.d.ts +35 -5
- package/esm/hooks/use-tambo-threads.d.ts.map +1 -1
- package/esm/hooks/use-tambo-threads.js +9 -1
- package/esm/hooks/use-tambo-threads.js.map +1 -1
- package/esm/hooks/use-thread-input.d.ts +0 -1
- package/esm/hooks/use-thread-input.d.ts.map +1 -1
- package/esm/hooks/use-thread-input.js +0 -1
- package/esm/hooks/use-thread-input.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/model/component-metadata.d.ts +6 -3
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/model/generate-component-response.d.ts +9 -2
- package/esm/model/generate-component-response.d.ts.map +1 -1
- package/esm/model/generate-component-response.js +5 -0
- package/esm/model/generate-component-response.js.map +1 -1
- package/esm/model/tambo-thread.d.ts +4 -2
- package/esm/model/tambo-thread.d.ts.map +1 -1
- package/esm/model/tambo-thread.js.map +1 -1
- package/esm/model/validate-input.d.ts +5 -0
- package/esm/model/validate-input.d.ts.map +1 -1
- package/esm/model/validate-input.js +5 -1
- package/esm/model/validate-input.js.map +1 -1
- package/esm/providers/tambo-client-provider.d.ts +31 -0
- package/esm/providers/tambo-client-provider.d.ts.map +1 -1
- package/esm/providers/tambo-client-provider.js +21 -0
- package/esm/providers/tambo-client-provider.js.map +1 -1
- package/esm/providers/tambo-component-provider.d.ts +12 -0
- package/esm/providers/tambo-component-provider.d.ts.map +1 -1
- package/esm/providers/tambo-component-provider.js +24 -0
- package/esm/providers/tambo-component-provider.js.map +1 -1
- package/esm/providers/tambo-provider.d.ts +18 -1
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +25 -2
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.d.ts +14 -1
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js +25 -0
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts +25 -2
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +32 -26
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/esm/util/generate-component.d.ts +5 -1
- package/esm/util/generate-component.d.ts.map +1 -1
- package/esm/util/generate-component.js +5 -1
- package/esm/util/generate-component.js.map +1 -1
- package/esm/util/query-utils.d.ts +16 -0
- package/esm/util/query-utils.d.ts.map +1 -1
- package/esm/util/query-utils.js +16 -0
- package/esm/util/query-utils.js.map +1 -1
- package/esm/util/registry.d.ts +27 -1
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +28 -2
- package/esm/util/registry.js.map +1 -1
- package/esm/util/tool-caller.d.ts +6 -0
- package/esm/util/tool-caller.d.ts.map +1 -1
- package/esm/util/tool-caller.js +6 -0
- package/esm/util/tool-caller.js.map +1 -1
- package/package.json +4 -2
- package/dist/util/messages.d.ts +0 -3
- package/dist/util/messages.d.ts.map +0 -1
- package/dist/util/messages.js +0 -12
- package/dist/util/messages.js.map +0 -1
- package/esm/util/messages.d.ts +0 -3
- package/esm/util/messages.d.ts.map +0 -1
- package/esm/util/messages.js +0 -9
- package/esm/util/messages.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-client-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,OAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"tambo-client-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,OAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAwB1E,MAAM,kBAAkB,GAAG,aAAa,CACtC,SAAS,CACV,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAE5B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE;IAClD,MAAM,WAAW,GAAkB,EAAE,MAAM,EAAE,CAAC;IAC9C,IAAI,QAAQ,EAAE,CAAC;QACb,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IACjC,CAAC;IACD,IAAI,WAAW,EAAE,CAAC;QAChB,WAAW,CAAC,WAAW,GAAG,WAAW,CAAC;IACxC,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1D,MAAM,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC;IACxD,OAAO,CACL,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,IACxD,QAAQ,CACmB,CAC/B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,WAAW,CAAC;AAC7B,CAAC,CAAC","sourcesContent":["import TamboAI, { ClientOptions } from \"@tambo-ai/typescript-sdk\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport React, { createContext, PropsWithChildren, useState } from \"react\";\n\nexport interface TamboClientProviderProps {\n /**\n * The URL of the Tambo API (used for local development and debugging)\n */\n tamboUrl?: string;\n /**\n * The API key for the Tambo API\n */\n apiKey: string;\n /**\n * The environment to use for the Tambo API\n */\n environment?: \"production\" | \"staging\";\n}\n\nexport interface TamboClientContextProps {\n /** The TamboAI client */\n client: TamboAI;\n /** The tambo-specific query client */\n queryClient: QueryClient;\n}\n\nconst TamboClientContext = createContext<TamboClientContextProps | undefined>(\n undefined,\n);\n\n/**\n * The TamboClientProvider is a React provider that provides a TamboAI client\n * and a query client to the descendants of the provider.\n * @param props - The props for the TamboClientProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.environment - The environment to use for the Tambo API\n * @returns The TamboClientProvider component\n */\nexport const TamboClientProvider: React.FC<\n PropsWithChildren<TamboClientProviderProps>\n> = ({ children, tamboUrl, apiKey, environment }) => {\n const tamboConfig: ClientOptions = { apiKey };\n if (tamboUrl) {\n tamboConfig.baseURL = tamboUrl;\n }\n if (environment) {\n tamboConfig.environment = environment;\n }\n const [client] = useState(() => new TamboAI(tamboConfig));\n const [queryClient] = useState(() => new QueryClient());\n return (\n <TamboClientContext.Provider value={{ client, queryClient }}>\n {children}\n </TamboClientContext.Provider>\n );\n};\n\n/**\n * The useTamboClient hook provides access to the TamboAI client\n * to the descendants of the TamboClientProvider.\n * @returns The TamboAI client\n */\nexport const useTamboClient = () => {\n const context = React.useContext(TamboClientContext);\n if (context === undefined) {\n throw new Error(\"useTamboClient must be used within a TamboClientProvider\");\n }\n return context.client;\n};\n\n/**\n * The useTamboQueryClient hook provides access to the tambo-specific query client\n * to the descendants of the TamboClientProvider.\n * @returns The tambo-specific query client\n * @private\n */\nexport const useTamboQueryClient = () => {\n const context = React.useContext(TamboClientContext);\n if (context === undefined) {\n throw new Error(\n \"useTamboQueryClient must be used within a TamboClientProvider\",\n );\n }\n return context.queryClient;\n};\n"]}
|
|
@@ -6,6 +6,18 @@ export interface TamboComponentContextProps {
|
|
|
6
6
|
registerTools: (tools: TamboTool[]) => void;
|
|
7
7
|
addToolAssociation: (componentName: string, tool: TamboTool) => void;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The TamboComponentProvider is a React provider that provides component
|
|
11
|
+
* registration services to the descendants of the provider.
|
|
12
|
+
* @param props - The props for the TamboComponentProvider
|
|
13
|
+
* @param props.children - The children to wrap
|
|
14
|
+
* @returns The TamboComponentProvider component
|
|
15
|
+
*/
|
|
9
16
|
export declare const TamboComponentProvider: React.FC<PropsWithChildren>;
|
|
17
|
+
/**
|
|
18
|
+
* The useTamboComponent hook provides access to the component registration
|
|
19
|
+
* services to the descendants of the TamboComponentProvider.
|
|
20
|
+
* @returns The component registration services
|
|
21
|
+
*/
|
|
10
22
|
export declare const useTamboComponent: () => TamboComponentContextProps;
|
|
11
23
|
//# sourceMappingURL=tambo-component-provider.d.ts.map
|
|
@@ -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,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAIxE,MAAM,WAAW,0BAA0B;IACzC,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5C,kBAAkB,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACtE;
|
|
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,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAIxE,MAAM,WAAW,0BAA0B;IACzC,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5C,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"}
|
|
@@ -3,11 +3,30 @@ import React, { createContext, useContext } from "react";
|
|
|
3
3
|
import { useTamboClient } from "./tambo-client-provider";
|
|
4
4
|
import { useTamboRegistry } from "./tambo-registry-provider";
|
|
5
5
|
const TamboComponentContext = createContext({
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
6
9
|
registerComponent: () => { },
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
7
13
|
registerTool: () => { },
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
8
17
|
registerTools: () => { },
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
9
21
|
addToolAssociation: () => { },
|
|
10
22
|
});
|
|
23
|
+
/**
|
|
24
|
+
* The TamboComponentProvider is a React provider that provides component
|
|
25
|
+
* registration services to the descendants of the provider.
|
|
26
|
+
* @param props - The props for the TamboComponentProvider
|
|
27
|
+
* @param props.children - The children to wrap
|
|
28
|
+
* @returns The TamboComponentProvider component
|
|
29
|
+
*/
|
|
11
30
|
export const TamboComponentProvider = ({ children, }) => {
|
|
12
31
|
const client = useTamboClient();
|
|
13
32
|
const { registerComponent, addToolAssociation, registerTool, registerTools } = useTamboRegistry();
|
|
@@ -20,6 +39,11 @@ export const TamboComponentProvider = ({ children, }) => {
|
|
|
20
39
|
};
|
|
21
40
|
return (React.createElement(TamboComponentContext.Provider, { value: value }, children));
|
|
22
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* The useTamboComponent hook provides access to the component registration
|
|
44
|
+
* services to the descendants of the TamboComponentProvider.
|
|
45
|
+
* @returns The component registration services
|
|
46
|
+
*/
|
|
23
47
|
export const useTamboComponent = () => {
|
|
24
48
|
return useContext(TamboComponentContext);
|
|
25
49
|
};
|
|
@@ -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;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAS7D,MAAM,qBAAqB,GAAG,aAAa,CAA6B;IACtE,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC3B,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;CAC7B,CAAC,CAAC;AAEH,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,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 { TamboComponent, TamboTool } 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: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboComponentContext = createContext<TamboComponentContextProps>({\n registerComponent: () => {},\n registerTool: () => {},\n registerTools: () => {},\n addToolAssociation: () => {},\n});\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\nexport const useTamboComponent = () => {\n return useContext(TamboComponentContext);\n};\n"]}
|
|
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;AAE5E,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 { TamboComponent, TamboTool } 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: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\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"]}
|
|
@@ -3,10 +3,27 @@ import { TamboClientContextProps, TamboClientProviderProps } from "./tambo-clien
|
|
|
3
3
|
import { TamboComponentContextProps } from "./tambo-component-provider";
|
|
4
4
|
import { TamboRegistryProviderProps } from "./tambo-registry-provider";
|
|
5
5
|
import { TamboThreadContextProps } from "./tambo-thread-provider";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The TamboProvider gives full access to the whole Tambo API. This includes the
|
|
8
|
+
* TamboAI client, the component registry, and the current thread context.
|
|
9
|
+
* @param props - The props for the TamboProvider
|
|
10
|
+
* @param props.children - The children to wrap
|
|
11
|
+
* @param props.tamboUrl - The URL of the Tambo API
|
|
12
|
+
* @param props.apiKey - The API key for the Tambo API
|
|
13
|
+
* @param props.components - The components to register
|
|
14
|
+
* @param props.environment - The environment to use for the Tambo API
|
|
15
|
+
* @returns The TamboProvider component
|
|
16
|
+
*/
|
|
7
17
|
export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>>;
|
|
8
18
|
type TamboContextProps = TamboClientContextProps & TamboThreadContextProps & TamboComponentContextProps;
|
|
9
19
|
export declare const TamboContext: React.Context<TamboContextProps>;
|
|
20
|
+
/**
|
|
21
|
+
* The useTambo hook provides access to the Tambo API. This is the primary entrypoint
|
|
22
|
+
* for the Tambo React SDK.
|
|
23
|
+
*
|
|
24
|
+
* This includes the TamboAI client, the component registry, and the current thread context.
|
|
25
|
+
* @returns The Tambo API
|
|
26
|
+
*/
|
|
10
27
|
export declare const useTambo: () => TamboContextProps;
|
|
11
28
|
export {};
|
|
12
29
|
//# sourceMappingURL=tambo-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAGzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EAGxB,MAAM,yBAAyB,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAC5E,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EAGzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EAGxB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CAAC,wBAAwB,GAAG,0BAA0B,CAAC,CAiBzE,CAAC;AACF,KAAK,iBAAiB,GAAG,uBAAuB,GAC9C,uBAAuB,GACvB,0BAA0B,CAAC;AAE7B,eAAO,MAAM,YAAY,kCAExB,CAAC;AA6BF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
|
|
@@ -4,7 +4,17 @@ import { TamboClientProvider, useTamboClient, useTamboQueryClient, } from "./tam
|
|
|
4
4
|
import { TamboComponentProvider, useTamboComponent, } from "./tambo-component-provider";
|
|
5
5
|
import { TamboRegistryProvider, } from "./tambo-registry-provider";
|
|
6
6
|
import { TamboThreadProvider, useTamboThread, } from "./tambo-thread-provider";
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The TamboProvider gives full access to the whole Tambo API. This includes the
|
|
9
|
+
* TamboAI client, the component registry, and the current thread context.
|
|
10
|
+
* @param props - The props for the TamboProvider
|
|
11
|
+
* @param props.children - The children to wrap
|
|
12
|
+
* @param props.tamboUrl - The URL of the Tambo API
|
|
13
|
+
* @param props.apiKey - The API key for the Tambo API
|
|
14
|
+
* @param props.components - The components to register
|
|
15
|
+
* @param props.environment - The environment to use for the Tambo API
|
|
16
|
+
* @returns The TamboProvider component
|
|
17
|
+
*/
|
|
8
18
|
export const TamboProvider = ({ children, tamboUrl, apiKey, components, environment }) => {
|
|
9
19
|
return (React.createElement(TamboClientProvider, { tamboUrl: tamboUrl, apiKey: apiKey, environment: environment },
|
|
10
20
|
React.createElement(TamboRegistryProvider, { components: components },
|
|
@@ -13,7 +23,13 @@ export const TamboProvider = ({ children, tamboUrl, apiKey, components, environm
|
|
|
13
23
|
React.createElement(TamboCompositeProvider, null, children))))));
|
|
14
24
|
};
|
|
15
25
|
export const TamboContext = createContext({});
|
|
16
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* TamboCompositeProvider is a provider that combines the TamboClient,
|
|
28
|
+
* TamboThread, and TamboComponent providers
|
|
29
|
+
* @param props - The props for the TamboCompositeProvider
|
|
30
|
+
* @param props.children - The children to wrap
|
|
31
|
+
* @returns The wrapped component
|
|
32
|
+
*/
|
|
17
33
|
const TamboCompositeProvider = ({ children }) => {
|
|
18
34
|
const threads = useTamboThread();
|
|
19
35
|
const client = useTamboClient();
|
|
@@ -26,6 +42,13 @@ const TamboCompositeProvider = ({ children }) => {
|
|
|
26
42
|
...threads,
|
|
27
43
|
} }, children));
|
|
28
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* The useTambo hook provides access to the Tambo API. This is the primary entrypoint
|
|
47
|
+
* for the Tambo React SDK.
|
|
48
|
+
*
|
|
49
|
+
* This includes the TamboAI client, the component registry, and the current thread context.
|
|
50
|
+
* @returns The Tambo API
|
|
51
|
+
*/
|
|
29
52
|
export const useTambo = () => {
|
|
30
53
|
return useContext(TamboContext);
|
|
31
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAEL,mBAAmB,EAEnB,cAAc,EACd,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAA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";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport {\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n useTamboClient,\n useTamboQueryClient,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport {\n TamboThreadContextProps,\n TamboThreadProvider,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, and the current thread context.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps>\n> = ({ children, tamboUrl, apiKey, components, environment }) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n >\n <TamboRegistryProvider components={components}>\n <TamboThreadProvider>\n <TamboComponentProvider>\n <TamboCompositeProvider>{children}</TamboCompositeProvider>\n </TamboComponentProvider>\n </TamboThreadProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\ntype TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboComponentContextProps;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, and TamboComponent providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nconst TamboCompositeProvider: React.FC<PropsWithChildren> = ({ children }) => {\n const threads = useTamboThread();\n const client = useTamboClient();\n const queryClient = useTamboQueryClient();\n const componentRegistry = useTamboComponent();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n ...componentRegistry,\n ...threads,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, and the current thread context.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
|
|
@@ -10,9 +10,22 @@ export interface TamboRegistryContext {
|
|
|
10
10
|
addToolAssociation: (componentName: string, tool: TamboTool) => void;
|
|
11
11
|
}
|
|
12
12
|
export interface TamboRegistryProviderProps {
|
|
13
|
-
/** The
|
|
13
|
+
/** The components to register */
|
|
14
14
|
components?: TamboComponent[];
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* The TamboRegistryProvider is a React provider that provides a component
|
|
18
|
+
* registry to the descendants of the provider.
|
|
19
|
+
* @param props - The props for the TamboRegistryProvider
|
|
20
|
+
* @param props.children - The children to wrap
|
|
21
|
+
* @param props.components - The components to register
|
|
22
|
+
* @returns The TamboRegistryProvider component
|
|
23
|
+
*/
|
|
16
24
|
export declare const TamboRegistryProvider: React.FC<PropsWithChildren<TamboRegistryProviderProps>>;
|
|
25
|
+
/**
|
|
26
|
+
* The useTamboRegistry hook provides access to the component registry
|
|
27
|
+
* to the descendants of the TamboRegistryProvider.
|
|
28
|
+
* @returns The component registry
|
|
29
|
+
*/
|
|
17
30
|
export declare const useTamboRegistry: () => TamboRegistryContext;
|
|
18
31
|
//# sourceMappingURL=tambo-registry-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-registry-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,SAAS,EACV,MAAM,6BAA6B,CAAC;AAErC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EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,iBAAiB,CAAC,0BAA0B,CAAC,CAqI9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAE5B,CAAC"}
|
|
@@ -5,11 +5,31 @@ const TamboRegistryContext = createContext({
|
|
|
5
5
|
componentList: {},
|
|
6
6
|
toolRegistry: {},
|
|
7
7
|
componentToolAssociations: {},
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
8
11
|
registerComponent: () => { },
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
9
15
|
registerTool: () => { },
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
10
19
|
registerTools: () => { },
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
11
23
|
addToolAssociation: () => { },
|
|
12
24
|
});
|
|
25
|
+
/**
|
|
26
|
+
* The TamboRegistryProvider is a React provider that provides a component
|
|
27
|
+
* registry to the descendants of the provider.
|
|
28
|
+
* @param props - The props for the TamboRegistryProvider
|
|
29
|
+
* @param props.children - The children to wrap
|
|
30
|
+
* @param props.components - The components to register
|
|
31
|
+
* @returns The TamboRegistryProvider component
|
|
32
|
+
*/
|
|
13
33
|
export const TamboRegistryProvider = ({ children, components: userComponents }) => {
|
|
14
34
|
const [componentList, setComponentList] = useState({});
|
|
15
35
|
const [toolRegistry, setToolRegistry] = useState({});
|
|
@@ -99,6 +119,11 @@ export const TamboRegistryProvider = ({ children, components: userComponents })
|
|
|
99
119
|
};
|
|
100
120
|
return (React.createElement(TamboRegistryContext.Provider, { value: value }, children));
|
|
101
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* The useTamboRegistry hook provides access to the component registry
|
|
124
|
+
* to the descendants of the TamboRegistryProvider.
|
|
125
|
+
* @returns The component registry
|
|
126
|
+
*/
|
|
102
127
|
export const useTamboRegistry = () => {
|
|
103
128
|
return useContext(TamboRegistryContext);
|
|
104
129
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAiBjD,MAAM,oBAAoB,GAAG,aAAa,CAAuB;IAC/D,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,yBAAyB,EAAE,EAAE;IAC7B,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC3B,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;CAC7B,CAAC,CAAC;AAOH,MAAM,CAAC,MAAM,qBAAqB,GAE9B,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,EAAE;IAC/C,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAoB,EAAE,CAAC,CAAC;IAC1E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAC9C,EAAE,CACH,CAAC;IACF,MAAM,CAAC,yBAAyB,EAAE,4BAA4B,CAAC,GAAG,QAAQ,CAExE,EAAE,CAAC,CAAC;IAEN,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,IAAe,EAAE,eAAe,GAAG,IAAI,EAAE,EAAE;QAC1C,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;YACvB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,eAAe,EAAE,CAAC;gBACvC,OAAO,CAAC,IA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C,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBACnC,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC;IAExC,MAAM,KAAK,GAAG;QACZ,aAAa;QACb,YAAY;QACZ,yBAAyB;QACzB,iBAAiB;QACjB,YAAY;QACZ,aAAa;QACb,kBAAkB;KACnB,CAAC;IAEF,OAAO,CACL,oBAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACxC,QAAQ,CACqB,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n registerComponent: () => {},\n registerTool: () => {},\n registerTools: () => {},\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The
|
|
1
|
+
{"version":3,"file":"tambo-registry-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-registry-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,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AAc,CAAC,CAAC,CAAC;IAExC,MAAM,KAAK,GAAG;QACZ,aAAa;QACb,YAAY;QACZ,yBAAyB;QACzB,iBAAiB;QACjB,YAAY;QACZ,aAAa;QACb,kBAAkB;KACnB,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","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentRegistry,\n TamboComponent,\n TamboTool,\n} from \"../model/component-metadata\";\n\nexport interface TamboRegistryContext {\n componentList: ComponentRegistry;\n toolRegistry: Record<string, TamboTool>;\n componentToolAssociations: Record<string, string[]>;\n registerComponent: (options: TamboComponent) => void;\n registerTool: (tool: TamboTool) => void;\n registerTools: (tools: TamboTool[]) => void;\n addToolAssociation: (componentName: string, tool: TamboTool) => void;\n}\n\nconst TamboRegistryContext = createContext<TamboRegistryContext>({\n componentList: {},\n toolRegistry: {},\n componentToolAssociations: {},\n /**\n *\n */\n registerComponent: () => {},\n /**\n *\n */\n registerTool: () => {},\n /**\n *\n */\n registerTools: () => {},\n /**\n *\n */\n addToolAssociation: () => {},\n});\n\nexport interface TamboRegistryProviderProps {\n /** The components to register */\n components?: TamboComponent[];\n}\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 * @returns The TamboRegistryProvider component\n */\nexport const TamboRegistryProvider: React.FC<\n PropsWithChildren<TamboRegistryProviderProps>\n> = ({ children, components: userComponents }) => {\n const [componentList, setComponentList] = useState<ComponentRegistry>({});\n const [toolRegistry, setToolRegistry] = useState<Record<string, TamboTool>>(\n {},\n );\n const [componentToolAssociations, setComponentToolAssociations] = useState<\n Record<string, string[]>\n >({});\n\n const registerTool = useCallback(\n (tool: TamboTool, warnOnOverwrite = true) => {\n setToolRegistry((prev) => {\n if (prev[tool.name] && warnOnOverwrite) {\n console.warn(`Overwriting tool ${tool.name}`);\n }\n return {\n ...prev,\n [tool.name]: tool,\n };\n });\n },\n [],\n );\n\n const registerTools = useCallback(\n (tools: TamboTool[], warnOnOverwrite = true) => {\n tools.forEach((tool) => registerTool(tool, warnOnOverwrite));\n },\n [registerTool],\n );\n\n const addToolAssociation = useCallback(\n (componentName: string, tool: TamboTool) => {\n if (!componentList[componentName]) {\n throw new Error(`Component ${componentName} not found in registry`);\n }\n setComponentToolAssociations((prev) => ({\n ...prev,\n [componentName]: [...(prev[componentName] || []), tool.name],\n }));\n },\n [componentList],\n );\n\n const registerComponent = useCallback(\n (options: TamboComponent, warnOnOverwrite = true) => {\n const {\n name,\n description,\n component,\n propsSchema,\n propsDefinition,\n loadingComponent,\n associatedTools,\n } = options;\n\n // Validate that at least one props definition is provided\n if (!propsSchema && !propsDefinition) {\n throw new Error(\n `Component ${name} must have either propsSchema (recommended) or propsDefinition defined`,\n );\n }\n\n // Validate that only one props definition is provided\n if (propsSchema && propsDefinition) {\n throw new Error(\n `Component ${name} cannot have both propsSchema and propsDefinition defined. Use only one. We recommend using propsSchema.`,\n );\n }\n\n // Convert propsSchema to JSON Schema if it exists\n let props = propsDefinition;\n if (propsSchema) {\n try {\n props = zodToJsonSchema(propsSchema);\n } catch (error) {\n console.error(\n `Error converting ${name} props schema to JSON Schema:`,\n error,\n );\n }\n }\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 const value = {\n componentList,\n toolRegistry,\n componentToolAssociations,\n registerComponent,\n registerTool,\n registerTools,\n addToolAssociation,\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"]}
|
|
@@ -3,24 +3,35 @@ import React, { PropsWithChildren } from "react";
|
|
|
3
3
|
import { GenerationStage, TamboThreadMessage } from "../model/generate-component-response";
|
|
4
4
|
import { TamboThread } from "../model/tambo-thread";
|
|
5
5
|
export interface TamboThreadContextProps {
|
|
6
|
+
/** The current thread */
|
|
6
7
|
thread: TamboThread;
|
|
8
|
+
/** Switch to a different thread */
|
|
7
9
|
switchCurrentThread: (threadId: string, fetch?: boolean) => void;
|
|
10
|
+
/** Start a new thread */
|
|
8
11
|
startNewThread: () => void;
|
|
12
|
+
/** Add a message to the current thread */
|
|
9
13
|
addThreadMessage: (message: TamboThreadMessage, sendToServer: boolean) => Promise<TamboAI.Beta.Threads.ThreadMessage[]>;
|
|
14
|
+
/** Update a message in the current thread */
|
|
10
15
|
updateThreadMessage: (id: string, message: TamboThreadMessage, sendToServer: boolean) => Promise<void>;
|
|
11
|
-
|
|
16
|
+
/** The input value of the current thread */
|
|
12
17
|
inputValue: string;
|
|
18
|
+
/** Set the input value of the current thread */
|
|
13
19
|
setInputValue: (value: string) => void;
|
|
20
|
+
/** Send a message to the current thread */
|
|
14
21
|
sendThreadMessage: (message: string, options?: {
|
|
15
22
|
threadId?: string;
|
|
16
23
|
streamResponse?: boolean;
|
|
17
24
|
contextKey?: string;
|
|
18
25
|
}) => Promise<TamboThreadMessage>;
|
|
26
|
+
/** The generation stage of the current thread - updated as the thread progresses */
|
|
19
27
|
generationStage: GenerationStage;
|
|
28
|
+
/** The generation status message of the current thread - updated as the thread progresses */
|
|
20
29
|
generationStatusMessage: string;
|
|
30
|
+
/** Whether the thread is idle */
|
|
21
31
|
isIdle: boolean;
|
|
22
32
|
}
|
|
23
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* This is a stub entry for when the thread is not yet created, the first time
|
|
24
35
|
* the user sends a message
|
|
25
36
|
*
|
|
26
37
|
* Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,
|
|
@@ -28,6 +39,18 @@ export interface TamboThreadContextProps {
|
|
|
28
39
|
*/
|
|
29
40
|
export declare const PLACEHOLDER_THREAD: TamboThread;
|
|
30
41
|
export declare const TamboThreadContext: React.Context<TamboThreadContextProps>;
|
|
42
|
+
/**
|
|
43
|
+
* The TamboThreadProvider is a React provider that provides a thread context
|
|
44
|
+
* to the descendants of the provider.
|
|
45
|
+
* @param props - The props for the TamboThreadProvider
|
|
46
|
+
* @param props.children - The children to wrap
|
|
47
|
+
* @returns The TamboThreadProvider component
|
|
48
|
+
*/
|
|
31
49
|
export declare const TamboThreadProvider: React.FC<PropsWithChildren>;
|
|
50
|
+
/**
|
|
51
|
+
* The useTamboThread hook provides access to the current thread context
|
|
52
|
+
* to the descendants of the TamboThreadProvider.
|
|
53
|
+
* @returns All state and actions for the current thread
|
|
54
|
+
*/
|
|
32
55
|
export declare const useTamboThread: () => TamboThreadContextProps;
|
|
33
56
|
//# sourceMappingURL=tambo-thread-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-thread-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-thread-provider.tsx"],"names":[],"mappings":"AACA,OAAO,OAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE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AE,kBAAkB,EAC3B,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACnD,6CAA6C;IAC7C,mBAAmB,EAAE,CACnB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,2CAA2C;IAC3C,iBAAiB,EAAE,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,KACE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACjC,oFAAoF;IACpF,eAAe,EAAE,eAAe,CAAC;IACjC,6FAA6F;IAC7F,uBAAuB,EAAE,MAAM,CAAC;IAChC,iCAAiC;IACjC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAOhC,CAAC;AAEF,eAAO,MAAM,kBAAkB,wCA0C7B,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4d3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,+BAM1B,CAAC"}
|
|
@@ -7,7 +7,8 @@ import { getAvailableComponents, getClientContext } from "../util/registry";
|
|
|
7
7
|
import { handleToolCall } from "../util/tool-caller";
|
|
8
8
|
import { useTamboClient } from "./tambo-client-provider";
|
|
9
9
|
import { useTamboRegistry } from "./tambo-registry-provider";
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* This is a stub entry for when the thread is not yet created, the first time
|
|
11
12
|
* the user sends a message
|
|
12
13
|
*
|
|
13
14
|
* Note that the consumer needs to be careful never to send `PLACEHOLDER_THREAD.id` to the server,
|
|
@@ -23,25 +24,40 @@ export const PLACEHOLDER_THREAD = {
|
|
|
23
24
|
};
|
|
24
25
|
export const TamboThreadContext = createContext({
|
|
25
26
|
thread: PLACEHOLDER_THREAD,
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
26
30
|
switchCurrentThread: () => {
|
|
27
31
|
throw new Error("switchCurrentThread not implemented");
|
|
28
32
|
},
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
29
36
|
startNewThread: () => {
|
|
30
37
|
throw new Error("startNewThread not implemented");
|
|
31
38
|
},
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
32
42
|
addThreadMessage: () => {
|
|
33
43
|
throw new Error("updateThreadMessageHistory not implemented");
|
|
34
44
|
},
|
|
35
|
-
setLastThreadStatus: () => {
|
|
36
|
-
throw new Error("setLastThreadStatus not implemented");
|
|
37
|
-
},
|
|
38
45
|
inputValue: "",
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
39
49
|
setInputValue: () => {
|
|
40
50
|
throw new Error("setInputValue not implemented");
|
|
41
51
|
},
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
42
55
|
updateThreadMessage: () => {
|
|
43
56
|
throw new Error("updateThreadMessage not implemented");
|
|
44
57
|
},
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
45
61
|
sendThreadMessage: () => {
|
|
46
62
|
throw new Error("advance not implemented");
|
|
47
63
|
},
|
|
@@ -49,6 +65,13 @@ export const TamboThreadContext = createContext({
|
|
|
49
65
|
generationStatusMessage: "",
|
|
50
66
|
isIdle: true,
|
|
51
67
|
});
|
|
68
|
+
/**
|
|
69
|
+
* The TamboThreadProvider is a React provider that provides a thread context
|
|
70
|
+
* to the descendants of the provider.
|
|
71
|
+
* @param props - The props for the TamboThreadProvider
|
|
72
|
+
* @param props.children - The children to wrap
|
|
73
|
+
* @returns The TamboThreadProvider component
|
|
74
|
+
*/
|
|
52
75
|
export const TamboThreadProvider = ({ children, }) => {
|
|
53
76
|
const [threadMap, setThreadMap] = useState({
|
|
54
77
|
[PLACEHOLDER_THREAD.id]: PLACEHOLDER_THREAD,
|
|
@@ -209,26 +232,6 @@ export const TamboThreadProvider = ({ children, }) => {
|
|
|
209
232
|
await fetchThread(threadId);
|
|
210
233
|
}
|
|
211
234
|
}, [fetchThread, threadMap]);
|
|
212
|
-
const setLastThreadStatus = (status) => {
|
|
213
|
-
setThreadMap((prevMap) => {
|
|
214
|
-
if (!currentThreadId) {
|
|
215
|
-
return prevMap;
|
|
216
|
-
}
|
|
217
|
-
const headMessages = prevMap[currentThreadId].messages.slice(0, -1);
|
|
218
|
-
const lastMessage = prevMap[currentThreadId].messages[prevMap[currentThreadId].messages.length - 1];
|
|
219
|
-
const updatedLastMessage = {
|
|
220
|
-
...lastMessage,
|
|
221
|
-
status,
|
|
222
|
-
};
|
|
223
|
-
return {
|
|
224
|
-
...prevMap,
|
|
225
|
-
[currentThreadId]: {
|
|
226
|
-
...prevMap[currentThreadId],
|
|
227
|
-
messages: [...headMessages, updatedLastMessage],
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
235
|
const updateThreadStatus = useCallback((stage, statusMessage) => {
|
|
233
236
|
setThreadMap((prevMap) => {
|
|
234
237
|
return {
|
|
@@ -386,7 +389,6 @@ export const TamboThreadProvider = ({ children, }) => {
|
|
|
386
389
|
componentToolAssociations,
|
|
387
390
|
currentThread,
|
|
388
391
|
switchCurrentThread,
|
|
389
|
-
startNewThread,
|
|
390
392
|
addThreadMessage,
|
|
391
393
|
client,
|
|
392
394
|
updateThreadStatus,
|
|
@@ -398,7 +400,6 @@ export const TamboThreadProvider = ({ children, }) => {
|
|
|
398
400
|
startNewThread,
|
|
399
401
|
addThreadMessage,
|
|
400
402
|
updateThreadMessage,
|
|
401
|
-
setLastThreadStatus,
|
|
402
403
|
inputValue,
|
|
403
404
|
setInputValue,
|
|
404
405
|
sendThreadMessage,
|
|
@@ -409,6 +410,11 @@ export const TamboThreadProvider = ({ children, }) => {
|
|
|
409
410
|
GenerationStage.IDLE)),
|
|
410
411
|
} }, children));
|
|
411
412
|
};
|
|
413
|
+
/**
|
|
414
|
+
* The useTamboThread hook provides access to the current thread context
|
|
415
|
+
* to the descendants of the TamboThreadProvider.
|
|
416
|
+
* @returns All state and actions for the current thread
|
|
417
|
+
*/
|
|
412
418
|
export const useTamboThread = () => {
|
|
413
419
|
const context = useContext(TamboThreadContext);
|
|
414
420
|
if (context === undefined) {
|