@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
|
@@ -3,12 +3,16 @@ import { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQu
|
|
|
3
3
|
* Wrapper around useQuery that uses the internal tambo query client.
|
|
4
4
|
*
|
|
5
5
|
* Use this instead of useQuery from @tanstack/react-query
|
|
6
|
+
* @param options - The options for the query, same as useQuery from @tanstack/react-query
|
|
7
|
+
* @returns The query result
|
|
6
8
|
*/
|
|
7
9
|
export declare function useTamboQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>): UseQueryResult<TData, TError>;
|
|
8
10
|
/**
|
|
9
11
|
* Wrapper around useMutation that uses the internal tambo query client.
|
|
10
12
|
*
|
|
11
13
|
* Use this instead of useMutation from @tanstack/react-query
|
|
14
|
+
* @param options - The options for the mutation, same as useMutation from @tanstack/react-query
|
|
15
|
+
* @returns The mutation result
|
|
12
16
|
*/
|
|
13
17
|
export declare function useTamboMutation<TData = unknown, TError = Error, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
14
18
|
/**
|
|
@@ -17,6 +21,10 @@ export declare function useTamboMutation<TData = unknown, TError = Error, TVaria
|
|
|
17
21
|
export type UseTamboMutationResult<TData = unknown, TError = Error, TVariables = void, TContext = unknown> = UseMutationResult<TData, TError, TVariables, TContext>;
|
|
18
22
|
/**
|
|
19
23
|
* Hook for creating a mutation with the tambo query client.
|
|
24
|
+
*
|
|
25
|
+
* Use this instead of useMutation from @tanstack/react-query
|
|
26
|
+
* @param options - The options for the mutation, same as useMutation from @tanstack/react-query
|
|
27
|
+
* @returns The mutation result
|
|
20
28
|
*/
|
|
21
29
|
export declare function useTamboMutationResult<TData = unknown, TError = Error, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
22
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query-hooks.d.ts","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,kBAAkB,EAClB,iBAAiB,EAEjB,eAAe,EACf,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B
|
|
1
|
+
{"version":3,"file":"react-query-hooks.d.ts","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,kBAAkB,EAClB,iBAAiB,EAEjB,eAAe,EACf,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,KAAK,EACd,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,OAAO,EAAE,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,iCAGjE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAClB,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,0DAGjE;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAChC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,IAChB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAE3D;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAClB,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,0DAEjE;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,IACZ,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -10,6 +10,8 @@ const tambo_client_provider_1 = require("../providers/tambo-client-provider");
|
|
|
10
10
|
* Wrapper around useQuery that uses the internal tambo query client.
|
|
11
11
|
*
|
|
12
12
|
* Use this instead of useQuery from @tanstack/react-query
|
|
13
|
+
* @param options - The options for the query, same as useQuery from @tanstack/react-query
|
|
14
|
+
* @returns The query result
|
|
13
15
|
*/
|
|
14
16
|
function useTamboQuery(options) {
|
|
15
17
|
const queryClient = (0, tambo_client_provider_1.useTamboQueryClient)();
|
|
@@ -19,6 +21,8 @@ function useTamboQuery(options) {
|
|
|
19
21
|
* Wrapper around useMutation that uses the internal tambo query client.
|
|
20
22
|
*
|
|
21
23
|
* Use this instead of useMutation from @tanstack/react-query
|
|
24
|
+
* @param options - The options for the mutation, same as useMutation from @tanstack/react-query
|
|
25
|
+
* @returns The mutation result
|
|
22
26
|
*/
|
|
23
27
|
function useTamboMutation(options) {
|
|
24
28
|
const queryClient = (0, tambo_client_provider_1.useTamboQueryClient)();
|
|
@@ -26,6 +30,10 @@ function useTamboMutation(options) {
|
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* Hook for creating a mutation with the tambo query client.
|
|
33
|
+
*
|
|
34
|
+
* Use this instead of useMutation from @tanstack/react-query
|
|
35
|
+
* @param options - The options for the mutation, same as useMutation from @tanstack/react-query
|
|
36
|
+
* @returns The mutation result
|
|
29
37
|
*/
|
|
30
38
|
function useTamboMutationResult(options) {
|
|
31
39
|
return useTamboMutation(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query-hooks.js","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"react-query-hooks.js","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":";;AAmBA,sCAQC;AASD,4CAQC;AAmBD,wDAOC;AAtED,gBAAgB;AAChB,uDAQ+B;AAC/B,8EAAyE;AAEzE;;;;;;GAMG;AACH,SAAgB,aAAa,CAK3B,OAAgE;IAChE,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,OAAO,IAAA,sBAAQ,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAK9B,OAAgE;IAChE,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,OAAO,IAAA,yBAAW,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAYD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAKpC,OAAgE;IAChE,OAAO,gBAAgB,CAAsC,OAAO,CAAC,CAAC;AACxE,CAAC","sourcesContent":["// tamboHooks.ts\nimport {\n QueryKey,\n useMutation,\n UseMutationOptions,\n UseMutationResult,\n useQuery,\n UseQueryOptions,\n UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useTamboQueryClient } from \"../providers/tambo-client-provider\";\n\n/**\n * Wrapper around useQuery that uses the internal tambo query client.\n *\n * Use this instead of useQuery from @tanstack/react-query\n * @param options - The options for the query, same as useQuery from @tanstack/react-query\n * @returns The query result\n */\nexport function useTamboQuery<\n TQueryFnData = unknown,\n TError = Error,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>) {\n const queryClient = useTamboQueryClient();\n return useQuery(options, queryClient);\n}\n\n/**\n * Wrapper around useMutation that uses the internal tambo query client.\n *\n * Use this instead of useMutation from @tanstack/react-query\n * @param options - The options for the mutation, same as useMutation from @tanstack/react-query\n * @returns The mutation result\n */\nexport function useTamboMutation<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n>(options: UseMutationOptions<TData, TError, TVariables, TContext>) {\n const queryClient = useTamboQueryClient();\n return useMutation(options, queryClient);\n}\n\n/**\n * Type alias for the result of a mutation.\n */\nexport type UseTamboMutationResult<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n> = UseMutationResult<TData, TError, TVariables, TContext>;\n\n/**\n * Hook for creating a mutation with the tambo query client.\n *\n * Use this instead of useMutation from @tanstack/react-query\n * @param options - The options for the mutation, same as useMutation from @tanstack/react-query\n * @returns The mutation result\n */\nexport function useTamboMutationResult<\n TData = unknown,\n TError = Error,\n TVariables = void,\n TContext = unknown,\n>(options: UseMutationOptions<TData, TError, TVariables, TContext>) {\n return useTamboMutation<TData, TError, TVariables, TContext>(options);\n}\n\n/**\n * Type alias for the result of a query.\n */\nexport type UseTamboQueryResult<\n TData = unknown,\n TError = Error,\n> = UseQueryResult<TData, TError>;\n"]}
|
|
@@ -9,16 +9,13 @@ type StateUpdateResult<T> = [
|
|
|
9
9
|
/**
|
|
10
10
|
* A React hook that provides state management and passes user updates to Tambo.
|
|
11
11
|
* Benefits: Passes user changes to AI, and when threads are returned, state is preserved.
|
|
12
|
-
*
|
|
13
12
|
* @param keyName - The unique key to identify this state within the message's componentState object
|
|
14
13
|
* @param initialValue - Optional initial value for the state, used if no value exists in the message
|
|
15
14
|
* @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls
|
|
16
|
-
*
|
|
17
15
|
* @returns A tuple containing:
|
|
18
16
|
* - The current state value
|
|
19
17
|
* - A setter function to update the state (updates UI immediately, debounces server sync)
|
|
20
18
|
* - A metadata object with properties like isPending to track sync status
|
|
21
|
-
*
|
|
22
19
|
* @example
|
|
23
20
|
* // Basic usage
|
|
24
21
|
* const [count, setCount, { isPending }] = useTamboComponentState("counter", 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AASA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"use-component-state.d.ts","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":"AASA,UAAU,kBAAkB;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAC1B,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI;IAC/B,IAAI,EAAE,kBAAkB;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,CAAC,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AACpC,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useTamboComponentState = useTamboComponentState;
|
|
4
7
|
const react_1 = require("react");
|
|
8
|
+
const react_fast_compare_1 = __importDefault(require("react-fast-compare"));
|
|
5
9
|
const use_debounce_1 = require("use-debounce");
|
|
6
10
|
const providers_1 = require("../providers");
|
|
7
11
|
const use_current_message_1 = require("./use-current-message");
|
|
12
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
8
13
|
function useTamboComponentState(keyName, initialValue, debounceTime = 300) {
|
|
9
14
|
const { threadId, messageId } = (0, use_current_message_1.useTamboMessageContext)();
|
|
10
15
|
const { updateThreadMessage } = (0, providers_1.useTamboThread)();
|
|
@@ -24,41 +29,18 @@ function useTamboComponentState(keyName, initialValue, debounceTime = 300) {
|
|
|
24
29
|
message &&
|
|
25
30
|
cachedInitialValue !== undefined &&
|
|
26
31
|
(!message.componentState || !(keyName in message.componentState));
|
|
27
|
-
// Helper function to check if two values are deeply equal
|
|
28
|
-
const isEqual = (a, b) => {
|
|
29
|
-
if (a === b)
|
|
30
|
-
return true;
|
|
31
|
-
// Handle primitive types
|
|
32
|
-
if (typeof a !== "object" ||
|
|
33
|
-
typeof b !== "object" ||
|
|
34
|
-
a === null ||
|
|
35
|
-
b === null)
|
|
36
|
-
return false;
|
|
37
|
-
// For objects and arrays, do a shallow comparison for simplicity
|
|
38
|
-
// This could be enhanced with a proper deep equality check if needed
|
|
39
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
40
|
-
if (a.length !== b.length)
|
|
41
|
-
return false;
|
|
42
|
-
return a.every((val, idx) => val === b[idx]);
|
|
43
|
-
}
|
|
44
|
-
const keysA = Object.keys(a);
|
|
45
|
-
const keysB = Object.keys(b);
|
|
46
|
-
if (keysA.length !== keysB.length)
|
|
47
|
-
return false;
|
|
48
|
-
return keysA.every((key) => a[key] === b[key]);
|
|
49
|
-
};
|
|
50
32
|
// Sync local state with message state on initial load and when message changes
|
|
51
33
|
(0, react_1.useEffect)(() => {
|
|
52
34
|
if (message?.componentState && keyName in message.componentState) {
|
|
53
35
|
const messageState = message.componentState[keyName];
|
|
54
36
|
// If this is a user-initiated state that matches what we're getting from server,
|
|
55
37
|
// we can clear the lastUserValue flag since it's been synchronized
|
|
56
|
-
if (lastUserValue !== null &&
|
|
38
|
+
if (lastUserValue !== null && (0, react_fast_compare_1.default)(messageState, lastUserValue)) {
|
|
57
39
|
setLastUserValue(null);
|
|
58
40
|
}
|
|
59
41
|
// Update local state with server state unless user has specifically changed this value
|
|
60
42
|
// This allows streaming updates to continue while protecting user edits
|
|
61
|
-
if (lastUserValue === null || !
|
|
43
|
+
if (lastUserValue === null || !(0, react_fast_compare_1.default)(localState, lastUserValue)) {
|
|
62
44
|
setLocalState(messageState);
|
|
63
45
|
}
|
|
64
46
|
}
|
|
@@ -97,7 +79,7 @@ function useTamboComponentState(keyName, initialValue, debounceTime = 300) {
|
|
|
97
79
|
client.beta.threads.messages.updateComponentState(threadId, messageId, componentStateUpdate),
|
|
98
80
|
]);
|
|
99
81
|
// Only clear the lastUserValue when we've successfully synced this exact value
|
|
100
|
-
if (
|
|
82
|
+
if ((0, react_fast_compare_1.default)(newValue, lastUserValue)) {
|
|
101
83
|
setLastUserValue(null);
|
|
102
84
|
}
|
|
103
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":";;AA8DA,wDA0NC;AAxRD,iCAAyD;AACzD,+CAAoD;AACpD,4CAA8D;AAC9D,+DAG+B;AAwD/B,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AS,EAAC,GAAG,EAAE;QACb,IAAI,gBAAgB,EAAE,CAAC;YACrB,eAAe,EAAE,CAAC;YAClB,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAExC,uCAAuC;IACvC,sEAAsE;IACtE,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAC1B,CAAC,QAAW,EAAE,EAAE;QACd,wCAAwC;QACxC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3B,aAAa,CAAC,QAAQ,CAAC,CAAC;QAExB,mDAAmD;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CACV,4CAA4C,SAAS,cAAc,OAAO,GAAG,CAC9E,CAAC;YACF,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EACD,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAC7C,CAAC;IAEF,gDAAgD;IAChD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n *\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n *\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n *\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\n\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 300,\n): StateUpdateResult<S> {\n const { threadId, messageId } = useTamboMessageContext();\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Helper function to check if two values are deeply equal\n const isEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n\n // Handle primitive types\n if (\n typeof a !== \"object\" ||\n typeof b !== \"object\" ||\n a === null ||\n b === null\n )\n return false;\n\n // For objects and arrays, do a shallow comparison for simplicity\n // This could be enhanced with a proper deep equality check if needed\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((val, idx) => val === b[idx]);\n }\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n return keysA.every((key) => a[key] === b[key]);\n };\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // If this is a user-initiated state that matches what we're getting from server,\n // we can clear the lastUserValue flag since it's been synchronized\n if (lastUserValue !== null && isEqual(messageState, lastUserValue)) {\n setLastUserValue(null);\n }\n\n // Update local state with server state unless user has specifically changed this value\n // This allows streaming updates to continue while protecting user edits\n if (lastUserValue === null || !isEqual(localState, lastUserValue)) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one\n else if (cachedInitialValue !== undefined && !localState) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedSave = useDebouncedCallback(async (newValue: S) => {\n if (!message) {\n console.warn(\n `Cannot update missing message ${messageId} for state key \"${keyName}\"`,\n );\n setLastUserValue(null);\n return;\n }\n\n setIsPending(true);\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n\n // Only clear the lastUserValue when we've successfully synced this exact value\n if (isEqual(newValue, lastUserValue)) {\n setLastUserValue(null);\n }\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedSave(newValue);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n setLastUserValue(null);\n }\n },\n [debouncedSave, message, messageId, keyName],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedSave.flush();\n setLastUserValue(null);\n };\n }, [debouncedSave]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-component-state.js","sourceRoot":"","sources":["../../src/hooks/use-component-state.tsx"],"names":[],"mappings":";;;;;AA2DA,wDA8LC;AAzPD,iCAAyD;AAC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AAC,CAAC;IAEpB,oDAAoD;IACpD,OAAO,CAAC,UAAe,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport isEqual from \"react-fast-compare\";\nimport { useDebouncedCallback } from \"use-debounce\";\nimport { useTamboClient, useTamboThread } from \"../providers\";\nimport {\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./use-current-message\";\n// Define metadata interface for better extensibility\ninterface ComponentStateMeta {\n isPending: boolean;\n}\n\ntype StateUpdateResult<T> = [\n currentState: T,\n setState: (newState: T) => void,\n meta: ComponentStateMeta,\n];\n\n/**\n * A React hook that provides state management and passes user updates to Tambo.\n * Benefits: Passes user changes to AI, and when threads are returned, state is preserved.\n * @param keyName - The unique key to identify this state within the message's componentState object\n * @param initialValue - Optional initial value for the state, used if no value exists in the message\n * @param debounceTime - Optional debounce time in milliseconds (default: 300ms) to limit API calls\n * @returns A tuple containing:\n * - The current state value\n * - A setter function to update the state (updates UI immediately, debounces server sync)\n * - A metadata object with properties like isPending to track sync status\n * @example\n * // Basic usage\n * const [count, setCount, { isPending }] = useTamboComponentState(\"counter\", 0);\n *\n * // Usage with object state\n * const [formState, setFormState] = useTamboComponentState(\"myForm\", {\n * name: \"\",\n * email: \"\",\n * message: \"\"\n * });\n *\n * // Handling form input\n * const handleChange = (e) => {\n * setFormState({\n * ...formState,\n * [e.target.name]: e.target.value\n * });\n * };\n */\nexport function useTamboComponentState<S = undefined>(\n keyName: string,\n initialValue?: S,\n debounceTime?: number,\n): StateUpdateResult<S | undefined>;\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue: S,\n debounceTime?: number,\n): StateUpdateResult<S>;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function useTamboComponentState<S>(\n keyName: string,\n initialValue?: S,\n debounceTime = 300,\n): StateUpdateResult<S> {\n const { threadId, messageId } = useTamboMessageContext();\n const { updateThreadMessage } = useTamboThread();\n const client = useTamboClient();\n const message = useTamboCurrentMessage();\n\n // Initial value management\n const [cachedInitialValue] = useState(() => initialValue);\n // UI state management\n const [localState, setLocalState] = useState<S | undefined>(\n cachedInitialValue,\n );\n // Synchronization state\n const [isPending, setIsPending] = useState(false);\n // Track the last user-initiated value instead of a simple boolean flag\n const [lastUserValue, setLastUserValue] = useState<S | null>(null);\n const [haveInitialized, setHaveInitialized] = useState(false);\n\n // Determine if we need to initialize state\n const shouldInitialize =\n !haveInitialized &&\n message &&\n cachedInitialValue !== undefined &&\n (!message.componentState || !(keyName in message.componentState));\n\n // Sync local state with message state on initial load and when message changes\n useEffect(() => {\n if (message?.componentState && keyName in message.componentState) {\n const messageState = message.componentState[keyName] as S;\n\n // If this is a user-initiated state that matches what we're getting from server,\n // we can clear the lastUserValue flag since it's been synchronized\n if (lastUserValue !== null && isEqual(messageState, lastUserValue)) {\n setLastUserValue(null);\n }\n\n // Update local state with server state unless user has specifically changed this value\n // This allows streaming updates to continue while protecting user edits\n if (lastUserValue === null || !isEqual(localState, lastUserValue)) {\n setLocalState(messageState);\n }\n }\n // Otherwise fall back to initial value if we have one\n else if (cachedInitialValue !== undefined && !localState) {\n setLocalState(cachedInitialValue);\n }\n }, [\n keyName,\n message?.componentState,\n cachedInitialValue,\n lastUserValue,\n localState,\n ]);\n\n // Create debounced save function for efficient server synchronization\n const debouncedSave = useDebouncedCallback(async (newValue: S) => {\n if (!message) {\n console.warn(\n `Cannot update missing message ${messageId} for state key \"${keyName}\"`,\n );\n setLastUserValue(null);\n return;\n }\n\n setIsPending(true);\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: newValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: newValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n\n // Only clear the lastUserValue when we've successfully synced this exact value\n if (isEqual(newValue, lastUserValue)) {\n setLastUserValue(null);\n }\n } catch (err) {\n console.error(\n `Failed to save component state for key \"${keyName}\":`,\n err,\n );\n } finally {\n setIsPending(false);\n }\n }, debounceTime);\n\n // Initialize state on first render if needed\n const initializeState = useCallback(async () => {\n if (!message) {\n console.warn(\n `Cannot initialize state for missing message ${messageId} with key \"${keyName}\"`,\n );\n return;\n }\n\n try {\n const messageUpdate = {\n ...message,\n componentState: {\n ...message.componentState,\n [keyName]: cachedInitialValue,\n },\n };\n\n const componentStateUpdate = {\n state: { [keyName]: cachedInitialValue },\n };\n\n await Promise.all([\n updateThreadMessage(messageId, messageUpdate, false),\n client.beta.threads.messages.updateComponentState(\n threadId,\n messageId,\n componentStateUpdate,\n ),\n ]);\n } catch (err) {\n console.warn(\n `Failed to initialize component state for key \"${keyName}\":`,\n err,\n );\n }\n }, [\n cachedInitialValue,\n client.beta.threads.messages,\n keyName,\n message,\n messageId,\n threadId,\n updateThreadMessage,\n ]);\n\n // Send initial state when component mounts\n useEffect(() => {\n if (shouldInitialize) {\n initializeState();\n setHaveInitialized(true);\n }\n }, [initializeState, shouldInitialize]);\n\n // setValue function for updating state\n // Updates local state immediately and schedules debounced server sync\n const setValue = useCallback(\n (newValue: S) => {\n // Track this as a user-initiated update\n setLastUserValue(newValue);\n setLocalState(newValue);\n\n // Only trigger server updates if we have a message\n if (message) {\n debouncedSave(newValue);\n } else {\n console.warn(\n `Cannot update server for missing message ${messageId} with key \"${keyName}\"`,\n );\n setLastUserValue(null);\n }\n },\n [debouncedSave, message, messageId, keyName],\n );\n\n // Ensure pending changes are flushed on unmount\n useEffect(() => {\n return () => {\n debouncedSave.flush();\n setLastUserValue(null);\n };\n }, [debouncedSave]);\n\n // Return the local state for immediate UI rendering\n return [localState as S, setValue, { isPending }];\n}\n"]}
|
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Wraps all components, so that they can find what thread and message they are in
|
|
4
|
+
* @param props - props for the TamboMessageProvider
|
|
5
|
+
* @param props.children - The children to wrap
|
|
6
|
+
* @param props.threadId - The threadId of the thread
|
|
7
|
+
* @param props.messageId - The messageId of the message
|
|
8
|
+
* @returns The wrapped component
|
|
9
|
+
*/
|
|
3
10
|
export declare const TamboMessageProvider: React.FC<PropsWithChildren<{
|
|
4
11
|
threadId: string;
|
|
5
12
|
messageId: string;
|
|
6
13
|
}>>;
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a component with a ComponentMessageProvider - this allows the provider
|
|
16
|
+
* to be used outside of a TSX file
|
|
17
|
+
* @param children - The children to wrap
|
|
18
|
+
* @param threadId - The threadId of the thread
|
|
19
|
+
* @param messageId - The messageId of the message
|
|
20
|
+
* @returns The wrapped component
|
|
21
|
+
*/
|
|
9
22
|
export declare function wrapWithTamboMessageProvider(children: React.ReactNode, threadId: string, messageId: string): React.JSX.Element;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
23
|
+
/**
|
|
24
|
+
* Hook used inside a component wrapped with ComponentMessageProvider, to get
|
|
25
|
+
* the threadId and messageId
|
|
26
|
+
* @returns The threadId and messageId
|
|
27
|
+
*/
|
|
12
28
|
export declare const useTamboMessageContext: () => {
|
|
13
29
|
threadId: string;
|
|
14
30
|
messageId: string;
|
|
15
31
|
};
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
32
|
+
/**
|
|
33
|
+
* Hook used inside a component wrapped with ComponentMessageProvider, to get
|
|
34
|
+
* the current message. The current thread will be fetched from the server, if
|
|
35
|
+
* it is not already in the cache.
|
|
36
|
+
* @returns The current message that is used to render the component
|
|
37
|
+
*/
|
|
18
38
|
export declare const useTamboCurrentMessage: () => import("..").TamboThreadMessage | undefined;
|
|
19
39
|
//# sourceMappingURL=use-current-message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAQ5E
|
|
1
|
+
{"version":3,"file":"use-current-message.d.ts","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AAQ5E;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAa3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,qBAOlB;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;cApDvB,MAAM;eACL,MAAM;CA2DlB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,mDASlC,CAAC"}
|
|
@@ -38,7 +38,14 @@ exports.wrapWithTamboMessageProvider = wrapWithTamboMessageProvider;
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const providers_1 = require("../providers");
|
|
40
40
|
const TamboMessageContext = (0, react_1.createContext)({});
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Wraps all components, so that they can find what thread and message they are in
|
|
43
|
+
* @param props - props for the TamboMessageProvider
|
|
44
|
+
* @param props.children - The children to wrap
|
|
45
|
+
* @param props.threadId - The threadId of the thread
|
|
46
|
+
* @param props.messageId - The messageId of the message
|
|
47
|
+
* @returns The wrapped component
|
|
48
|
+
*/
|
|
42
49
|
const TamboMessageProvider = ({ children, threadId, messageId }) => {
|
|
43
50
|
// Use a unique key={...} to force a re-render when the messageId changes - this
|
|
44
51
|
// make sure that if the rendered component is swapped into a tree (like if
|
|
@@ -46,13 +53,22 @@ const TamboMessageProvider = ({ children, threadId, messageId }) => {
|
|
|
46
53
|
return (react_1.default.createElement(TamboMessageContext.Provider, { value: { threadId, messageId }, key: `${threadId}-${messageId}` }, children));
|
|
47
54
|
};
|
|
48
55
|
exports.TamboMessageProvider = TamboMessageProvider;
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
56
|
+
/**
|
|
57
|
+
* Wraps a component with a ComponentMessageProvider - this allows the provider
|
|
58
|
+
* to be used outside of a TSX file
|
|
59
|
+
* @param children - The children to wrap
|
|
60
|
+
* @param threadId - The threadId of the thread
|
|
61
|
+
* @param messageId - The messageId of the message
|
|
62
|
+
* @returns The wrapped component
|
|
63
|
+
*/
|
|
51
64
|
function wrapWithTamboMessageProvider(children, threadId, messageId) {
|
|
52
65
|
return (react_1.default.createElement(exports.TamboMessageProvider, { threadId: threadId, messageId: messageId }, children));
|
|
53
66
|
}
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
67
|
+
/**
|
|
68
|
+
* Hook used inside a component wrapped with ComponentMessageProvider, to get
|
|
69
|
+
* the threadId and messageId
|
|
70
|
+
* @returns The threadId and messageId
|
|
71
|
+
*/
|
|
56
72
|
const useTamboMessageContext = () => {
|
|
57
73
|
const context = (0, react_1.useContext)(TamboMessageContext);
|
|
58
74
|
if (!context) {
|
|
@@ -61,8 +77,12 @@ const useTamboMessageContext = () => {
|
|
|
61
77
|
return context;
|
|
62
78
|
};
|
|
63
79
|
exports.useTamboMessageContext = useTamboMessageContext;
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
80
|
+
/**
|
|
81
|
+
* Hook used inside a component wrapped with ComponentMessageProvider, to get
|
|
82
|
+
* the current message. The current thread will be fetched from the server, if
|
|
83
|
+
* it is not already in the cache.
|
|
84
|
+
* @returns The current message that is used to render the component
|
|
85
|
+
*/
|
|
66
86
|
const useTamboCurrentMessage = () => {
|
|
67
87
|
const { messageId, threadId } = (0, exports.useTamboMessageContext)();
|
|
68
88
|
const { thread } = (0, providers_1.useTamboThread)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-current-message.js","sourceRoot":"","sources":["../../src/hooks/use-current-message.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,oEAUC;AAlDD,+CAA4E;AAC5E,4CAA8C;AAE9C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAGtC,EAA6C,CAAC,CAAC;AAElD;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAE7B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IACxC,gFAAgF;IAChF,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CACL,8BAAC,mBAAmB,CAAC,QAAQ,IAC3B,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,EAC9B,GAAG,EAAE,GAAG,QAAQ,IAAI,SAAS,EAAE,IAE9B,QAAQ,CACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B;AAEF;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,QAAyB,EACzB,QAAgB,EAChB,SAAiB;IAEjB,OAAO,CACL,8BAAC,4BAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,IAC3D,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AACD;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC;AAEF;;;;;GAKG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAA,8BAAsB,GAAE,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,0BAAc,GAAE,CAAC;IACpC,IAAI,MAAM,CAAC,EAAE,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,EAAE,QAAQ,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,sBAAsB,0BASjC","sourcesContent":["import React, { createContext, PropsWithChildren, useContext } from \"react\";\nimport { useTamboThread } from \"../providers\";\n\nconst TamboMessageContext = createContext<{\n threadId: string;\n messageId: string;\n}>({} as { threadId: string; messageId: string });\n\n/**\n * Wraps all components, so that they can find what thread and message they are in\n * @param props - props for the TamboMessageProvider\n * @param props.children - The children to wrap\n * @param props.threadId - The threadId of the thread\n * @param props.messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport const TamboMessageProvider: React.FC<\n PropsWithChildren<{ threadId: string; messageId: string }>\n> = ({ children, threadId, messageId }) => {\n // Use a unique key={...} to force a re-render when the messageId changes - this\n // make sure that if the rendered component is swapped into a tree (like if\n // you always show the last rendered component) then the state/etc is correct\n return (\n <TamboMessageContext.Provider\n value={{ threadId, messageId }}\n key={`${threadId}-${messageId}`}\n >\n {children}\n </TamboMessageContext.Provider>\n );\n};\n\n/**\n * Wraps a component with a ComponentMessageProvider - this allows the provider\n * to be used outside of a TSX file\n * @param children - The children to wrap\n * @param threadId - The threadId of the thread\n * @param messageId - The messageId of the message\n * @returns The wrapped component\n */\nexport function wrapWithTamboMessageProvider(\n children: React.ReactNode,\n threadId: string,\n messageId: string,\n) {\n return (\n <TamboMessageProvider threadId={threadId} messageId={messageId}>\n {children}\n </TamboMessageProvider>\n );\n}\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the threadId and messageId\n * @returns The threadId and messageId\n */\nexport const useTamboMessageContext = () => {\n const context = useContext(TamboMessageContext);\n if (!context) {\n throw new Error(\n \"useTamboMessageContext must be used within a TamboMessageProvider\",\n );\n }\n return context;\n};\n\n/**\n * Hook used inside a component wrapped with ComponentMessageProvider, to get\n * the current message. The current thread will be fetched from the server, if\n * it is not already in the cache.\n * @returns The current message that is used to render the component\n */\nexport const useTamboCurrentMessage = () => {\n const { messageId, threadId } = useTamboMessageContext();\n const { thread } = useTamboThread();\n if (thread.id && threadId && thread.id !== threadId) {\n console.warn(`Thread ID mismatch ${thread.id} !== ${threadId}`);\n }\n\n const message = thread.messages.find((m) => m.id === messageId);\n return message;\n};\n"]}
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This hook streamlines the common pattern of updating component state when receiving new
|
|
5
5
|
* streamed values from Tambo, eliminating the need to write repetitive useEffect code.
|
|
6
|
-
*
|
|
7
6
|
* @param currentState - The current state object from useTamboComponentState
|
|
8
7
|
* @param setState - The setState function from useTamboComponentState
|
|
9
8
|
* @param streamingProps - An object mapping state keys to prop values that should update the state
|
|
10
|
-
*
|
|
11
9
|
* @example
|
|
12
10
|
* ```tsx
|
|
13
11
|
* // Instead of writing a complex useEffect:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-streaming-props.d.ts","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"use-streaming-props.d.ts","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClE,YAAY,EAAE,CAAC,GAAG,SAAS,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,QAwB3B"}
|
|
@@ -7,11 +7,9 @@ const react_1 = require("react");
|
|
|
7
7
|
*
|
|
8
8
|
* This hook streamlines the common pattern of updating component state when receiving new
|
|
9
9
|
* streamed values from Tambo, eliminating the need to write repetitive useEffect code.
|
|
10
|
-
*
|
|
11
10
|
* @param currentState - The current state object from useTamboComponentState
|
|
12
11
|
* @param setState - The setState function from useTamboComponentState
|
|
13
12
|
* @param streamingProps - An object mapping state keys to prop values that should update the state
|
|
14
|
-
*
|
|
15
13
|
* @example
|
|
16
14
|
* ```tsx
|
|
17
15
|
* // Instead of writing a complex useEffect:
|
|
@@ -43,7 +41,8 @@ function useTamboStreamingProps(currentState, setState, streamingProps) {
|
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
43
|
}
|
|
44
|
+
// Only run when streamingProps change
|
|
46
45
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
-
}, [
|
|
46
|
+
}, [...Object.values(streamingProps)]);
|
|
48
47
|
}
|
|
49
48
|
//# sourceMappingURL=use-streaming-props.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-streaming-props.js","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-streaming-props.js","sourceRoot":"","sources":["../../src/hooks/use-streaming-props.tsx"],"names":[],"mappings":";;AAuBA,wDA2BC;AAlDD,iCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,sBAAsB,CACpC,YAA2B,EAC3B,QAA4B,EAC5B,cAA0B;IAE1B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,YAAY,GAAG,KAAK,CAAC;YACzB,MAAM,OAAO,GAAe,EAAE,CAAC;YAE/B,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACtD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;oBACvD,YAAY,GAAG,IAAI,CAAC;oBACpB,OAAO,CAAC,GAAc,CAAC,GAAG,KAAmB,CAAC;gBAChD,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,EAAE,CAAC;gBACjB,QAAQ,CAAC;oBACP,GAAG,YAAY;oBACf,GAAG,OAAO;iBACX,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,sCAAsC;QACtC,uDAAuD;IACzD,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { useEffect } from \"react\";\n\n/**\n * A helper hook that automatically updates Tambo component state when specified props change.\n *\n * This hook streamlines the common pattern of updating component state when receiving new\n * streamed values from Tambo, eliminating the need to write repetitive useEffect code.\n * @param currentState - The current state object from useTamboComponentState\n * @param setState - The setState function from useTamboComponentState\n * @param streamingProps - An object mapping state keys to prop values that should update the state\n * @example\n * ```tsx\n * // Instead of writing a complex useEffect:\n * const [emailState, setEmailState] = useTamboComponentState(\"email\", initialState);\n *\n * // Simply use:\n * useTamboStreamingProps(emailState, setEmailState, {\n * subject: aiGeneratedSubject,\n * body: aiGeneratedBody,\n * usersEmail: usersEmail\n * });\n * ```\n */\nexport function useTamboStreamingProps<T extends Record<string, any>>(\n currentState: T | undefined,\n setState: (state: T) => void,\n streamingProps: Partial<T>,\n) {\n useEffect(() => {\n if (currentState) {\n let shouldUpdate = false;\n const updates: Partial<T> = {};\n\n Object.entries(streamingProps).forEach(([key, value]) => {\n if (value !== undefined && value !== currentState[key]) {\n shouldUpdate = true;\n updates[key as keyof T] = value as T[keyof T];\n }\n });\n\n if (shouldUpdate) {\n setState({\n ...currentState,\n ...updates,\n });\n }\n }\n // Only run when streamingProps change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...Object.values(streamingProps)]);\n}\n"]}
|
|
@@ -38,7 +38,6 @@ export interface useTamboSuggestionsResultInternal {
|
|
|
38
38
|
type useTamboSuggestionsResult = CombinedMutationResult<any, Error> & useTamboSuggestionsResultInternal;
|
|
39
39
|
/**
|
|
40
40
|
* Hook for managing Tambo AI suggestions in a thread
|
|
41
|
-
*
|
|
42
41
|
* @param options - Configuration options for suggestion generation
|
|
43
42
|
* @returns Object containing suggestions state and control functions
|
|
44
43
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-suggestions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAO/C,OAAO,EACL,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EAGpB,MAAM,qBAAqB,CAAC;AAG7B;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,4EAA4E;IAC5E,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAC/C,8CAA8C;IAC9C,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,MAAM,EAAE,CAAC,aAAa,EAAE;QACtB,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,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,CAAC,aAAa,EAAE;QACtB,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpB,0DAA0D;IAC1D,YAAY,EAAE,sBAAsB,CAClC,IAAI,EACJ,KAAK,EACL;QAAE,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,CACxE,CAAC;IAEF,0DAA0D;IAC1D,cAAc,EAAE,sBAAsB,CACpC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,0BAA0B,GAAG,SAAS,EACvE,KAAK,EACL,eAAe,CAChB,CAAC;IAEF,yDAAyD;IACzD,iBAAiB,EAAE,mBAAmB,CACpC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,0BAA0B,GAAG,SAAS,EACvE,KAAK,CACN,CAAC;CACH;AAED,KAAK,yBAAyB,GAAG,sBAAsB,CAAC,GAAG,EAAE,KAAK,CAAC,GACjE,iCAAiC,CAAC;AAEpC;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,yBAAyB,CAmI3B"}
|
|
@@ -13,7 +13,6 @@ const react_query_hooks_1 = require("./react-query-hooks");
|
|
|
13
13
|
const use_thread_input_1 = require("./use-thread-input");
|
|
14
14
|
/**
|
|
15
15
|
* Hook for managing Tambo AI suggestions in a thread
|
|
16
|
-
*
|
|
17
16
|
* @param options - Configuration options for suggestion generation
|
|
18
17
|
* @returns Object containing suggestions state and control functions
|
|
19
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-suggestions.js","sourceRoot":"","sources":["../../src/hooks/use-suggestions.ts"],"names":[],"mappings":";;AA4EA,kDAqIC;AAhND,iCAA4C;AAC5C,4DAAwD;AAC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AAU,CAAC,cAAc,CAAC,CAAC;YAC3C,CAAC;YACD,uBAAuB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC;KACF,CAAC,CAAC;IAEH,gCAAgC;IAChC,MAAM,qBAAqB,GAAG,IAAA,0CAAsB,EAIlD;QACA,UAAU,EAAE,KAAK,EAAE,eAAgC,EAAE,EAAE;YACrD,IAAI,CAAC,eAAe,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBAC3C,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,8CAA8C;YAC9C,MAAM,UAAU,GAAG,IAAA,iCAAsB,EACvC,aAAa,EACb,YAAY,EACZ,yBAAyB,CAC1B,CAAC;YAEF,OAAO,MAAM,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CACxD,MAAM,CAAC,EAAE,EACT,eAAe,EACf;gBACE,cAAc;gBACd,6DAA6D;gBAC7D,mBAAmB,EAAE,CAAC,UAAU,CAAC;aAClC,EACD,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CACnC,CAAC;QACJ,CAAC;QACD,yBAAyB;QACzB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,mEAAmE;IACnE,8DAA8D;IAC9D,MAAM,WAAW,GAAG,iBAAiB;QACnC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,IAAI,qBAAqB,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9D,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;QACL,WAAW;QACX,MAAM,EAAE,mBAAmB,CAAC,WAAW;QACvC,oBAAoB;QACpB,YAAY,EAAE,mBAAmB;QACjC,cAAc,EAAE,qBAAqB;QACrC,iBAAiB;QACjB,GAAG,IAAA,oCAAsB,EAAC,mBAAmB,EAAE,qBAAqB,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { useEffect, useState } from \"react\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTambo } from \"../providers/tambo-provider\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport {\n CombinedMutationResult,\n combineMutationResults,\n} from \"../util/query-utils\";\nimport { getAvailableComponents } from \"../util/registry\";\nimport {\n UseTamboMutationResult,\n UseTamboQueryResult,\n useTamboMutationResult,\n useTamboQuery,\n} from \"./react-query-hooks\";\nimport { INPUT_ERROR_MESSAGES, useTamboThreadInput } from \"./use-thread-input\";\n\n/**\n * Configuration options for the useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsOptions {\n /** Maximum number of suggestions to generate (1-10, default 3) */\n maxSuggestions?: number;\n}\n\n/**\n * Return value interface for useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsResultInternal {\n /** List of available suggestions (also available in generateResult.data) */\n suggestions: TamboAI.Beta.Threads.Suggestion[];\n /** ID of the currently selected suggestion */\n selectedSuggestionId: string | null;\n /**\n * Accept and apply a suggestion (also available in acceptResult.mutateAsync)\n * @param suggestion - The suggestion to accept\n * @param shouldSubmit - Whether to automatically submit after accepting (default: false)\n */\n accept: (acceptOptions: {\n suggestion: TamboAI.Beta.Threads.Suggestion;\n shouldSubmit?: boolean;\n }) => Promise<void>;\n\n /** Result and network state for accepting a suggestion */\n acceptResult: UseTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >;\n\n /** Result and network state for generating suggestions */\n generateResult: UseTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >;\n\n /** The full suggestions query object from React Query */\n suggestionsResult: UseTamboQueryResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error\n >;\n}\n\ntype useTamboSuggestionsResult = CombinedMutationResult<any, Error> &\n useTamboSuggestionsResultInternal;\n\n/**\n * Hook for managing Tambo AI suggestions in a thread\n *\n * @param options - Configuration options for suggestion generation\n * @returns Object containing suggestions state and control functions\n */\nexport function useTamboSuggestions(\n options: useTamboSuggestionsOptions = {},\n): useTamboSuggestionsResult {\n const { maxSuggestions = 3 } = options;\n const { thread } = useTamboThread();\n const { sendThreadMessage } = useTambo();\n const tamboClient = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n\n const [selectedSuggestionId, setSelectedSuggestionId] = useState<\n string | null\n >(null);\n const { setValue: setInputValue } = useTamboThreadInput();\n\n const latestMessage = thread.messages[thread.messages.length - 1];\n const isLatestFromTambo = latestMessage?.role === \"assistant\";\n const latestMessageId = latestMessage?.id;\n\n // Reset selected suggestion when the message changes\n useEffect(() => {\n setSelectedSuggestionId(null);\n }, [latestMessageId]);\n\n // Use React Query to fetch suggestions when a new hydra message is received\n const suggestionsResult = useTamboQuery({\n // Only include latestMessageId in the queryKey if the message is from hydra\n queryKey: [\"suggestions\", isLatestFromTambo ? latestMessageId : null],\n queryFn: async () => {\n if (!latestMessageId || !isLatestFromTambo) {\n return [];\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n );\n },\n // Only run the query if we have a valid message from hydra\n enabled: Boolean(latestMessageId && isLatestFromTambo),\n // Don't refetch on window focus or reconnect\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n // Don't retry on failure\n retry: false,\n });\n\n // Accept suggestion mutation\n const acceptMutationState = useTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >({\n mutationFn: async ({ suggestion, shouldSubmit = false }) => {\n const validation = validateInput(suggestion.detailedSuggestion);\n if (!validation.isValid) {\n if (validation.error) {\n throw validation.error;\n }\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n if (shouldSubmit) {\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n });\n } else {\n setInputValue(validation.sanitizedInput);\n }\n setSelectedSuggestionId(suggestion.id);\n },\n });\n\n // Generate suggestions mutation\n const generateMutationState = useTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >({\n mutationFn: async (abortController: AbortController) => {\n if (!latestMessageId || !isLatestFromTambo) {\n return undefined;\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n { signal: abortController.signal },\n );\n },\n // Don't retry on failure\n retry: false,\n });\n\n // Use the query data if available, otherwise use the mutation data\n // Only return suggestions if the latest message is from hydra\n const suggestions = isLatestFromTambo\n ? (suggestionsResult.data ?? generateMutationState.data ?? [])\n : [];\n\n return {\n suggestions,\n accept: acceptMutationState.mutateAsync,\n selectedSuggestionId,\n acceptResult: acceptMutationState,\n generateResult: generateMutationState,\n suggestionsResult,\n ...combineMutationResults(acceptMutationState, generateMutationState),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-suggestions.js","sourceRoot":"","sources":["../../src/hooks/use-suggestions.ts"],"names":[],"mappings":";;AA2EA,kDAqIC;AA/MD,iCAA4C;AAC5C,4DAAwD;AACxD,8EAAoE;AACpE,gEAAuD;AACvD,kFAAwE;AACxE,8EAAoE;AACpE,qDAG6B;AAC7B,+CAA0D;AAC1D,2DAK6B;AAC7B,yDAA+E;AAoD/E;;;;GAIG;AACH,SAAgB,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EAAE,cAAc,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,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iB,EAAE,CAAC;gBAC3C,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,8CAA8C;YAC9C,MAAM,UAAU,GAAG,IAAA,iCAAsB,EACvC,aAAa,EACb,YAAY,EACZ,yBAAyB,CAC1B,CAAC;YAEF,OAAO,MAAM,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CACxD,MAAM,CAAC,EAAE,EACT,eAAe,EACf;gBACE,cAAc;gBACd,6DAA6D;gBAC7D,mBAAmB,EAAE,CAAC,UAAU,CAAC;aAClC,EACD,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CACnC,CAAC;QACJ,CAAC;QACD,yBAAyB;QACzB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,mEAAmE;IACnE,8DAA8D;IAC9D,MAAM,WAAW,GAAG,iBAAiB;QACnC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,IAAI,qBAAqB,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9D,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;QACL,WAAW;QACX,MAAM,EAAE,mBAAmB,CAAC,WAAW;QACvC,oBAAoB;QACpB,YAAY,EAAE,mBAAmB;QACjC,cAAc,EAAE,qBAAqB;QACrC,iBAAiB;QACjB,GAAG,IAAA,oCAAsB,EAAC,mBAAmB,EAAE,qBAAqB,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { useEffect, useState } from \"react\";\nimport { validateInput } from \"../model/validate-input\";\nimport { useTamboClient } from \"../providers/tambo-client-provider\";\nimport { useTambo } from \"../providers/tambo-provider\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { useTamboThread } from \"../providers/tambo-thread-provider\";\nimport {\n CombinedMutationResult,\n combineMutationResults,\n} from \"../util/query-utils\";\nimport { getAvailableComponents } from \"../util/registry\";\nimport {\n UseTamboMutationResult,\n UseTamboQueryResult,\n useTamboMutationResult,\n useTamboQuery,\n} from \"./react-query-hooks\";\nimport { INPUT_ERROR_MESSAGES, useTamboThreadInput } from \"./use-thread-input\";\n\n/**\n * Configuration options for the useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsOptions {\n /** Maximum number of suggestions to generate (1-10, default 3) */\n maxSuggestions?: number;\n}\n\n/**\n * Return value interface for useTamboSuggestions hook\n */\nexport interface useTamboSuggestionsResultInternal {\n /** List of available suggestions (also available in generateResult.data) */\n suggestions: TamboAI.Beta.Threads.Suggestion[];\n /** ID of the currently selected suggestion */\n selectedSuggestionId: string | null;\n /**\n * Accept and apply a suggestion (also available in acceptResult.mutateAsync)\n * @param suggestion - The suggestion to accept\n * @param shouldSubmit - Whether to automatically submit after accepting (default: false)\n */\n accept: (acceptOptions: {\n suggestion: TamboAI.Beta.Threads.Suggestion;\n shouldSubmit?: boolean;\n }) => Promise<void>;\n\n /** Result and network state for accepting a suggestion */\n acceptResult: UseTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >;\n\n /** Result and network state for generating suggestions */\n generateResult: UseTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >;\n\n /** The full suggestions query object from React Query */\n suggestionsResult: UseTamboQueryResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error\n >;\n}\n\ntype useTamboSuggestionsResult = CombinedMutationResult<any, Error> &\n useTamboSuggestionsResultInternal;\n\n/**\n * Hook for managing Tambo AI suggestions in a thread\n * @param options - Configuration options for suggestion generation\n * @returns Object containing suggestions state and control functions\n */\nexport function useTamboSuggestions(\n options: useTamboSuggestionsOptions = {},\n): useTamboSuggestionsResult {\n const { maxSuggestions = 3 } = options;\n const { thread } = useTamboThread();\n const { sendThreadMessage } = useTambo();\n const tamboClient = useTamboClient();\n const { componentList, toolRegistry, componentToolAssociations } =\n useTamboRegistry();\n\n const [selectedSuggestionId, setSelectedSuggestionId] = useState<\n string | null\n >(null);\n const { setValue: setInputValue } = useTamboThreadInput();\n\n const latestMessage = thread.messages[thread.messages.length - 1];\n const isLatestFromTambo = latestMessage?.role === \"assistant\";\n const latestMessageId = latestMessage?.id;\n\n // Reset selected suggestion when the message changes\n useEffect(() => {\n setSelectedSuggestionId(null);\n }, [latestMessageId]);\n\n // Use React Query to fetch suggestions when a new hydra message is received\n const suggestionsResult = useTamboQuery({\n // Only include latestMessageId in the queryKey if the message is from hydra\n queryKey: [\"suggestions\", isLatestFromTambo ? latestMessageId : null],\n queryFn: async () => {\n if (!latestMessageId || !isLatestFromTambo) {\n return [];\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n );\n },\n // Only run the query if we have a valid message from hydra\n enabled: Boolean(latestMessageId && isLatestFromTambo),\n // Don't refetch on window focus or reconnect\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n // Don't retry on failure\n retry: false,\n });\n\n // Accept suggestion mutation\n const acceptMutationState = useTamboMutationResult<\n void,\n Error,\n { suggestion: TamboAI.Beta.Threads.Suggestion; shouldSubmit?: boolean }\n >({\n mutationFn: async ({ suggestion, shouldSubmit = false }) => {\n const validation = validateInput(suggestion.detailedSuggestion);\n if (!validation.isValid) {\n if (validation.error) {\n throw validation.error;\n }\n throw new Error(INPUT_ERROR_MESSAGES.VALIDATION);\n }\n\n if (shouldSubmit) {\n await sendThreadMessage(validation.sanitizedInput, {\n threadId: thread.id,\n });\n } else {\n setInputValue(validation.sanitizedInput);\n }\n setSelectedSuggestionId(suggestion.id);\n },\n });\n\n // Generate suggestions mutation\n const generateMutationState = useTamboMutationResult<\n TamboAI.Beta.Threads.Suggestions.SuggestionGenerateResponse | undefined,\n Error,\n AbortController\n >({\n mutationFn: async (abortController: AbortController) => {\n if (!latestMessageId || !isLatestFromTambo) {\n return undefined;\n }\n\n // Get registered components from the registry\n const components = getAvailableComponents(\n componentList,\n toolRegistry,\n componentToolAssociations,\n );\n\n return await tamboClient.beta.threads.suggestions.generate(\n thread.id,\n latestMessageId,\n {\n maxSuggestions,\n // The API expects an array of arrays for availableComponents\n availableComponents: [components],\n },\n { signal: abortController.signal },\n );\n },\n // Don't retry on failure\n retry: false,\n });\n\n // Use the query data if available, otherwise use the mutation data\n // Only return suggestions if the latest message is from hydra\n const suggestions = isLatestFromTambo\n ? (suggestionsResult.data ?? generateMutationState.data ?? [])\n : [];\n\n return {\n suggestions,\n accept: acceptMutationState.mutateAsync,\n selectedSuggestionId,\n acceptResult: acceptMutationState,\n generateResult: generateMutationState,\n suggestionsResult,\n ...combineMutationResults(acceptMutationState, generateMutationState),\n };\n}\n"]}
|
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
interface UseTamboThreadListConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The projectId to get the threads for. If not provided, the current project
|
|
4
|
+
* will be used.
|
|
5
|
+
*/
|
|
6
|
+
projectId?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The context key to get the threads for. If not provided, all threads for
|
|
9
|
+
* the project will be returned.
|
|
10
|
+
*/
|
|
11
|
+
contextKey?: string;
|
|
12
|
+
}
|
|
13
|
+
interface UseTamboThreadListConfig {
|
|
14
|
+
/**
|
|
15
|
+
* The projectId to get the threads for. If not provided, the current project
|
|
16
|
+
* will be used.
|
|
17
|
+
*/
|
|
5
18
|
projectId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The context key to get the threads for. If not provided, all threads for
|
|
21
|
+
* the project will be returned.
|
|
22
|
+
*/
|
|
6
23
|
contextKey?: string;
|
|
7
|
-
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get all the threads for the specified project.
|
|
27
|
+
*
|
|
28
|
+
* If contextKey is empty, then all threads for the project will be returned.
|
|
29
|
+
* If contextKey is not empty, then only the threads for the specified context
|
|
30
|
+
* key will be returned.
|
|
31
|
+
* @param config - The config for the useTamboThreadList hook
|
|
32
|
+
* @param config.projectId - The projectId to get the threads for
|
|
33
|
+
* @param config.contextKey - The context key to get the threads for
|
|
34
|
+
* @returns The threads for the specified project and optional context key
|
|
35
|
+
*/
|
|
36
|
+
export declare function useTamboThreadList({ projectId, contextKey, }?: UseTamboThreadListConfig): import("@tanstack/query-core").QueryObserverRefetchErrorResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverSuccessResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverLoadingErrorResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverPendingResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | import("@tanstack/query-core").QueryObserverPlaceholderResult<import("@tambo-ai/typescript-sdk/resources/beta").ThreadsOffsetAndLimit | null, Error> | {
|
|
8
37
|
error: Error;
|
|
9
38
|
isError: true;
|
|
10
39
|
isPending: false;
|
|
@@ -135,4 +164,5 @@ export declare function useTamboThreadList({ projectId, contextKey, }?: {
|
|
|
135
164
|
promise: Promise<string>;
|
|
136
165
|
data: null;
|
|
137
166
|
};
|
|
167
|
+
export {};
|
|
138
168
|
//# sourceMappingURL=use-tambo-threads.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"use-tambo-threads.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tambo-threads.ts"],"names":[],"mappings":"AAGA,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,wBAAwB;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,SAAS,EACT,UAAU,GACX,GAAE,wBAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyB/B"}
|
|
@@ -4,7 +4,15 @@ exports.useTamboThreadList = useTamboThreadList;
|
|
|
4
4
|
const tambo_client_provider_1 = require("../providers/tambo-client-provider");
|
|
5
5
|
const react_query_hooks_1 = require("./react-query-hooks");
|
|
6
6
|
/**
|
|
7
|
-
* Get the threads for the specified project
|
|
7
|
+
* Get all the threads for the specified project.
|
|
8
|
+
*
|
|
9
|
+
* If contextKey is empty, then all threads for the project will be returned.
|
|
10
|
+
* If contextKey is not empty, then only the threads for the specified context
|
|
11
|
+
* key will be returned.
|
|
12
|
+
* @param config - The config for the useTamboThreadList hook
|
|
13
|
+
* @param config.projectId - The projectId to get the threads for
|
|
14
|
+
* @param config.contextKey - The context key to get the threads for
|
|
15
|
+
* @returns The threads for the specified project and optional context key
|
|
8
16
|
*/
|
|
9
17
|
function useTamboThreadList({ projectId, contextKey, } = {}) {
|
|
10
18
|
const client = (0, tambo_client_provider_1.useTamboClient)();
|