@tambo-ai/react 0.58.1 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/react-query-hooks.d.ts +14 -1
- package/dist/hooks/react-query-hooks.d.ts.map +1 -1
- package/dist/hooks/react-query-hooks.js +13 -0
- package/dist/hooks/react-query-hooks.js.map +1 -1
- package/dist/hooks/use-tambo-stream-status.js +1 -1
- package/dist/hooks/use-tambo-stream-status.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/__tests__/elicitation.test.d.ts +2 -0
- package/dist/mcp/__tests__/elicitation.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/elicitation.test.js +261 -0
- package/dist/mcp/__tests__/elicitation.test.js.map +1 -0
- package/dist/mcp/__tests__/mcp-client.test.js +0 -266
- package/dist/mcp/__tests__/mcp-client.test.js.map +1 -1
- package/dist/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
- package/dist/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/mcp-hooks.test.js +504 -0
- package/dist/mcp/__tests__/mcp-hooks.test.js.map +1 -0
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js +361 -16
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/dist/mcp/__tests__/use-mcp-servers.test.js +34 -9
- package/dist/mcp/__tests__/use-mcp-servers.test.js.map +1 -1
- package/dist/mcp/elicitation.d.ts +80 -0
- package/dist/mcp/elicitation.d.ts.map +1 -0
- package/dist/mcp/elicitation.js +55 -0
- package/dist/mcp/elicitation.js.map +1 -0
- package/dist/mcp/index.d.ts +4 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +5 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts +51 -86
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +22 -159
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/mcp/mcp-hooks.d.ts +107 -0
- package/dist/mcp/mcp-hooks.d.ts.map +1 -0
- package/dist/mcp/mcp-hooks.js +103 -0
- package/dist/mcp/mcp-hooks.js.map +1 -0
- package/dist/mcp/tambo-mcp-provider.d.ts +86 -4
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +275 -106
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js +3 -1
- package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/dist/providers/__tests__/tambo-thread-provider.test.js +25 -12
- package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +11 -4
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-mcp-token-provider.d.ts +34 -0
- package/dist/providers/tambo-mcp-token-provider.d.ts.map +1 -0
- package/dist/providers/tambo-mcp-token-provider.js +69 -0
- package/dist/providers/tambo-mcp-token-provider.js.map +1 -0
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +7 -9
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +14 -0
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/esm/hooks/react-query-hooks.d.ts +14 -1
- package/esm/hooks/react-query-hooks.d.ts.map +1 -1
- package/esm/hooks/react-query-hooks.js +13 -1
- package/esm/hooks/react-query-hooks.js.map +1 -1
- package/esm/hooks/use-tambo-stream-status.js +1 -1
- package/esm/hooks/use-tambo-stream-status.js.map +1 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/mcp/__tests__/elicitation.test.d.ts +2 -0
- package/esm/mcp/__tests__/elicitation.test.d.ts.map +1 -0
- package/esm/mcp/__tests__/elicitation.test.js +259 -0
- package/esm/mcp/__tests__/elicitation.test.js.map +1 -0
- package/esm/mcp/__tests__/mcp-client.test.js +0 -266
- package/esm/mcp/__tests__/mcp-client.test.js.map +1 -1
- package/esm/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
- package/esm/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
- package/esm/mcp/__tests__/mcp-hooks.test.js +469 -0
- package/esm/mcp/__tests__/mcp-hooks.test.js.map +1 -0
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js +361 -16
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/esm/mcp/__tests__/use-mcp-servers.test.js +34 -9
- package/esm/mcp/__tests__/use-mcp-servers.test.js.map +1 -1
- package/esm/mcp/elicitation.d.ts +80 -0
- package/esm/mcp/elicitation.d.ts.map +1 -0
- package/esm/mcp/elicitation.js +52 -0
- package/esm/mcp/elicitation.js.map +1 -0
- package/esm/mcp/index.d.ts +4 -1
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +2 -1
- package/esm/mcp/index.js.map +1 -1
- package/esm/mcp/mcp-client.d.ts +51 -86
- package/esm/mcp/mcp-client.d.ts.map +1 -1
- package/esm/mcp/mcp-client.js +22 -159
- package/esm/mcp/mcp-client.js.map +1 -1
- package/esm/mcp/mcp-hooks.d.ts +107 -0
- package/esm/mcp/mcp-hooks.d.ts.map +1 -0
- package/esm/mcp/mcp-hooks.js +99 -0
- package/esm/mcp/mcp-hooks.js.map +1 -0
- package/esm/mcp/tambo-mcp-provider.d.ts +86 -4
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +275 -107
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js +3 -1
- package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/esm/providers/__tests__/tambo-thread-provider.test.js +25 -12
- package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +11 -4
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-mcp-token-provider.d.ts +34 -0
- package/esm/providers/tambo-mcp-token-provider.d.ts.map +1 -0
- package/esm/providers/tambo-mcp-token-provider.js +31 -0
- package/esm/providers/tambo-mcp-token-provider.js.map +1 -0
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +7 -9
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +14 -0
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
1
|
+
import { QueriesOptions, QueriesResults, QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
2
2
|
/**
|
|
3
3
|
* Wrapper around useQuery that uses the internal tambo query client.
|
|
4
4
|
*
|
|
@@ -23,4 +23,17 @@ export type UseTamboMutationResult<TData = unknown, TError = Error, TVariables =
|
|
|
23
23
|
* Type alias for the result of a query.
|
|
24
24
|
*/
|
|
25
25
|
export type UseTamboQueryResult<TData = unknown, TError = Error> = UseQueryResult<TData, TError>;
|
|
26
|
+
/**
|
|
27
|
+
* Wrapper around useQueries that uses the internal tambo query client.
|
|
28
|
+
* @param options - The options for the queries, same as useQueries from `@tanstack/react-query`
|
|
29
|
+
* @param options.queries - The queries to run, same as queries from useQueries from `@tanstack/react-query`
|
|
30
|
+
* @param options.combine - The function to combine the results of the queries, same as combine from useQueries from `@tanstack/react-query`
|
|
31
|
+
* @param options.subscribed - Whether to subscribe to the queries, same as subscribed from useQueries from `@tanstack/react-query`
|
|
32
|
+
* @returns The queries result
|
|
33
|
+
*/
|
|
34
|
+
export declare function useTamboQueries<T extends any[], TCombinedResult = QueriesResults<T>>({ queries, ...options }: {
|
|
35
|
+
queries: readonly [...QueriesOptions<T>];
|
|
36
|
+
combine?: (result: QueriesResults<T>) => TCombinedResult;
|
|
37
|
+
subscribed?: boolean;
|
|
38
|
+
}): TCombinedResult;
|
|
26
39
|
//# sourceMappingURL=react-query-hooks.d.ts.map
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"react-query-hooks.d.ts","sourceRoot":"","sources":["../../src/hooks/react-query-hooks.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,cAAc,EACd,QAAQ,EAER,kBAAkB,EAClB,iBAAiB,EAGjB,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,0EAGjE;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;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,IACZ,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAElC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,CAAC,SAAS,GAAG,EAAE,EACf,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,EACnC,EACA,OAAO,EACP,GAAG,OAAO,EACX,EAAE;IACD,OAAO,EAAE,SAAS,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC;IACzD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,mBAGA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useTamboQuery = useTamboQuery;
|
|
4
4
|
exports.useTamboMutation = useTamboMutation;
|
|
5
|
+
exports.useTamboQueries = useTamboQueries;
|
|
5
6
|
// tamboHooks.ts
|
|
6
7
|
const react_query_1 = require("@tanstack/react-query");
|
|
7
8
|
const tambo_client_provider_1 = require("../providers/tambo-client-provider");
|
|
@@ -27,4 +28,16 @@ function useTamboMutation(options) {
|
|
|
27
28
|
const queryClient = (0, tambo_client_provider_1.useTamboQueryClient)();
|
|
28
29
|
return (0, react_query_1.useMutation)(options, queryClient);
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Wrapper around useQueries that uses the internal tambo query client.
|
|
33
|
+
* @param options - The options for the queries, same as useQueries from `@tanstack/react-query`
|
|
34
|
+
* @param options.queries - The queries to run, same as queries from useQueries from `@tanstack/react-query`
|
|
35
|
+
* @param options.combine - The function to combine the results of the queries, same as combine from useQueries from `@tanstack/react-query`
|
|
36
|
+
* @param options.subscribed - Whether to subscribe to the queries, same as subscribed from useQueries from `@tanstack/react-query`
|
|
37
|
+
* @returns The queries result
|
|
38
|
+
*/
|
|
39
|
+
function useTamboQueries({ queries, ...options }) {
|
|
40
|
+
const queryClient = (0, tambo_client_provider_1.useTamboQueryClient)();
|
|
41
|
+
return (0, react_query_1.useQueries)({ ...options, queries }, queryClient);
|
|
42
|
+
}
|
|
30
43
|
//# sourceMappingURL=react-query-hooks.js.map
|
|
@@ -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":";;AAsBA,sCAQC;AASD,4CAQC;AA4BD,0CAaC;AAxFD,gBAAgB;AAChB,uDAW+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;AAoBD;;;;;;;GAOG;AACH,SAAgB,eAAe,CAG7B,EACA,OAAO,EACP,GAAG,OAAO,EAKX;IACC,MAAM,WAAW,GAAG,IAAA,2CAAmB,GAAE,CAAC;IAC1C,OAAO,IAAA,wBAAU,EAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["// tamboHooks.ts\nimport {\n QueriesOptions,\n QueriesResults,\n QueryKey,\n useMutation,\n UseMutationOptions,\n UseMutationResult,\n useQueries,\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 * Type alias for the result of a query.\n */\nexport type UseTamboQueryResult<\n TData = unknown,\n TError = Error,\n> = UseQueryResult<TData, TError>;\n\n/**\n * Wrapper around useQueries that uses the internal tambo query client.\n * @param options - The options for the queries, same as useQueries from `@tanstack/react-query`\n * @param options.queries - The queries to run, same as queries from useQueries from `@tanstack/react-query`\n * @param options.combine - The function to combine the results of the queries, same as combine from useQueries from `@tanstack/react-query`\n * @param options.subscribed - Whether to subscribe to the queries, same as subscribed from useQueries from `@tanstack/react-query`\n * @returns The queries result\n */\nexport function useTamboQueries<\n T extends any[],\n TCombinedResult = QueriesResults<T>,\n>({\n queries,\n ...options\n}: {\n queries: readonly [...QueriesOptions<T>];\n combine?: (result: QueriesResults<T>) => TCombinedResult;\n subscribed?: boolean;\n}) {\n const queryClient = useTamboQueryClient();\n return useQueries({ ...options, queries }, queryClient);\n}\n"]}
|
|
@@ -203,7 +203,7 @@ function useTamboStreamStatus() {
|
|
|
203
203
|
: undefined;
|
|
204
204
|
const hasComponent = !!message?.component;
|
|
205
205
|
return deriveGlobalStreamStatus(generationStage, propStatus, hasComponent, generationError);
|
|
206
|
-
}, [generationStage, propStatus, message
|
|
206
|
+
}, [generationStage, propStatus, message]);
|
|
207
207
|
return {
|
|
208
208
|
streamStatus,
|
|
209
209
|
propStatus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tambo-stream-status.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-stream-status.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AA+Tb,oDAwCC;AAtWD,iCAAqD;AACrD,sFAAuE;AACvE,8EAA6E;AAC7E,+DAA+D;AAqE/D;;;;GAIG;AACH,SAAS,gBAAgB;IACvB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,4CAA4C;YAC5C,6DAA6D,CAChE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,uBAAuB,CAC9B,KAAwB,EACxB,eAAgC,EAChC,SAAiB;IAEjB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAU9C,EAAE,CAAC,CAAC;IAEN,mDAAmD;IACnD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;YACvB,0DAA0D;YAC1D,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CA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,EAAY,CAAC;IAE7E,sCAAsC;IACtC,MAAM,UAAU,GAAG,uBAAuB,CACxC,cAAc,EACd,eAAe,EACf,OAAO,EAAE,EAAE,IAAI,EAAE,CAClB,CAAC;IAEF,0EAA0E;IAC1E,MAAM,YAAY,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAChC,MAAM,eAAe,GAAG,OAAO,EAAE,KAAK;YACpC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC;QAC1C,OAAO,wBAAwB,CAC7B,eAAe,EACf,UAAU,EACV,YAAY,EACZ,eAAe,CAChB,CAAC;IACJ,CAAC,EAAE,CAAC,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IAEtE,OAAO;QACL,YAAY;QACZ,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { useTamboGenerationStage } from \"../providers/tambo-thread-provider\";\nimport { useTamboCurrentMessage } from \"./use-current-message\";\n\n/**\n * Global stream status flags for a specific component in a message.\n * Represents the aggregate state across all props for this component only.\n * Once a component completes, its status remains stable regardless of other generations.\n */\nexport interface StreamStatus {\n /**\n * Indicates no tokens have been received for any prop and generation is not active.\n * Useful for showing initial loading states before any data arrives.\n */\n isPending: boolean;\n\n /**\n * Indicates active streaming - either generation is streaming OR at least one prop is still streaming.\n * Use this to show loading animations or skeleton states during data transmission.\n */\n isStreaming: boolean;\n\n /**\n * Indicates successful completion - generation is complete AND every prop finished without error.\n * Safe to render the final component when this is true.\n */\n isSuccess: boolean;\n\n /**\n * Indicates a fatal error occurred in any prop or the stream itself.\n * Check streamError for details about what went wrong.\n */\n isError: boolean;\n\n /**\n * The first fatal error encountered during streaming (if any).\n * Will be undefined if no errors occurred.\n */\n streamError?: Error;\n}\n\n/**\n * Streaming status flags for individual component props.\n * Tracks the state of each prop as it streams from the LLM.\n */\nexport interface PropStatus {\n /**\n * Indicates no tokens have been received for this specific prop yet.\n * The prop value is still undefined, null, or empty string.\n */\n isPending: boolean;\n\n /**\n * Indicates at least one token has been received but streaming is not complete.\n * The prop has partial content that may still be updating.\n */\n isStreaming: boolean;\n\n /**\n * Indicates this prop has finished streaming successfully.\n * The prop value is complete and stable.\n */\n isSuccess: boolean;\n\n /**\n * The error that occurred during streaming (if any).\n * Will be undefined if no error occurred for this prop.\n */\n error?: Error;\n}\n\n/**\n * SSR Guard - throws during server-side rendering.\n * Ensures the hook is only used in browser contexts.\n * @throws {Error} When called during server-side rendering\n */\nfunction assertClientSide() {\n if (typeof window === \"undefined\") {\n throw new Error(\n \"useTamboStreamStatus can only be used in browser contexts. \" +\n \"This hook is not compatible with SSR/SSG. \" +\n \"Consider wrapping it in useEffect or using dynamic imports.\",\n );\n }\n}\n\n/**\n * Track streaming status for individual props by monitoring their values.\n * Monitors when props receive their first token and when they complete streaming.\n * Maintains stable state per message - once props complete for a message, they stay complete.\n * @template Props - The type of the component props being tracked\n * @param props - The current component props object\n * @param generationStage - The current generation stage from the LLM\n * @param messageId - The ID of the current message to track component-specific state\n * @returns A record mapping each prop key to its PropStatus\n */\nfunction usePropsStreamingStatus<Props extends Record<string, any>>(\n props: Props | undefined,\n generationStage: GenerationStage,\n messageId: string,\n): Record<keyof Props, PropStatus> {\n const [propTracking, setPropTracking] = useState<\n Record<\n string,\n {\n hasStarted: boolean;\n isComplete: boolean;\n error?: Error;\n messageId: string;\n }\n >\n >({});\n\n /** Reset tracking only when the message changes */\n useEffect(() => {\n setPropTracking((prev) => {\n // If we have tracking data for a different message, reset\n const hasOldMessageData = Object.values(prev).some(\n (track) => track.messageId && track.messageId !== messageId,\n );\n return hasOldMessageData ? {} : prev;\n });\n }, [messageId]);\n\n /** Track when props start streaming (receive first token) and when they complete */\n useEffect(() => {\n if (!props) return;\n\n setPropTracking((prev) => {\n const updated = { ...prev };\n let hasChanges = false;\n\n // First pass: identify which props are starting now\n const propsStartingNow: string[] = [];\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n if (justStarted) {\n propsStartingNow.push(key);\n }\n });\n\n // Second pass: update tracking and mark previous props as complete\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n /**\n * A prop is complete when it has started and either:\n * 1. A following prop has started, OR\n * 2. Generation is complete (for the final prop)\n */\n const hasFollowingPropStarted = propsStartingNow.some(\n (startingKey) => startingKey !== key,\n );\n const isGenerationComplete =\n generationStage === GenerationStage.COMPLETE;\n const isComplete =\n current.hasStarted &&\n (hasFollowingPropStarted || isGenerationComplete) &&\n !current.isComplete;\n\n // Once a prop is complete for this message, it stays complete\n if (current.isComplete && current.messageId === messageId) {\n // Skip - already complete for this message\n return;\n }\n\n if (justStarted || isComplete) {\n updated[key] = {\n ...current,\n hasStarted: justStarted ? true : current.hasStarted,\n isComplete: isComplete ? true : current.isComplete,\n messageId,\n };\n hasChanges = true;\n }\n });\n\n return hasChanges ? updated : prev;\n });\n }, [props, generationStage, messageId]);\n\n /** Convert tracking state to PropStatus objects */\n return useMemo(() => {\n if (!props) return {} as Record<keyof Props, PropStatus>;\n\n const result = {} as Record<keyof Props, PropStatus>;\n\n Object.keys(props).forEach((key) => {\n const tracking = propTracking[key] || {\n hasStarted: false,\n isComplete: false,\n messageId: \"\",\n };\n\n // If this prop is complete for this message, it stays complete\n const isCompleteForThisMessage =\n tracking.isComplete && tracking.messageId === messageId;\n\n // Only consider generation stage if this prop isn't already complete for this message\n const isGenerationStreaming =\n !isCompleteForThisMessage &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n\n result[key as keyof Props] = {\n isPending: !tracking.hasStarted && !isCompleteForThisMessage,\n isStreaming:\n tracking.hasStarted &&\n !isCompleteForThisMessage &&\n isGenerationStreaming,\n isSuccess: isCompleteForThisMessage,\n error: tracking.error,\n };\n });\n\n return result;\n }, [props, propTracking, generationStage, messageId]);\n}\n\n/**\n * Derives global StreamStatus from generation stage and individual prop statuses.\n * Aggregates individual prop states into a unified stream status.\n * @template Props - The type of the component props\n * @param generationStage - The current generation stage from the LLM\n * @param propStatus - Status record for each individual prop\n * @param hasComponent - Whether a component exists in the current message\n * @param generationError - Any error from the generation process itself\n * @returns The aggregated StreamStatus for the entire component\n */\nfunction deriveGlobalStreamStatus<Props extends Record<string, any>>(\n generationStage: GenerationStage,\n propStatus: Record<keyof Props, PropStatus>,\n hasComponent: boolean,\n generationError?: Error,\n): StreamStatus {\n const propStatuses = Object.values(propStatus) as PropStatus[];\n\n // If all props are already successful, the component is complete regardless of generation stage\n const allPropsSuccessful =\n propStatuses.length > 0 && propStatuses.every((p) => p.isSuccess);\n\n // Only consider generation stage if not all props are complete\n const isGenerationStreaming =\n !allPropsSuccessful &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n const isGenerationError = generationStage === GenerationStage.ERROR;\n\n /** Find first error from generation or any prop */\n const firstError =\n generationError ?? propStatuses.find((p) => p.error)?.error;\n\n return {\n /** isPending: no component yet OR (has component but no props have started) */\n isPending:\n !hasComponent ||\n (!isGenerationStreaming &&\n !allPropsSuccessful &&\n propStatuses.every((p) => p.isPending)),\n\n /** isStreaming: any prop is streaming (generation stage doesn't matter if props are complete) */\n isStreaming: propStatuses.some((p) => p.isStreaming),\n\n /** isSuccess: all props successful (component is stable once all props complete) */\n isSuccess: allPropsSuccessful,\n\n /** isError: generation error OR any prop error */\n isError:\n isGenerationError ||\n propStatuses.some((p) => p.error) ||\n !!generationError,\n\n streamError: firstError,\n };\n}\n\n/**\n * Hook that exposes per-prop and global streaming status for tambo-ai components.\n * Provides streaming readiness flags so consumers can show loaders, skeletons,\n * or errors while LLM-generated props stream in.\n * This hook tracks status for the specific component in the current message only.\n * Once a component's props complete streaming, they remain stable regardless of\n * other components being generated in the thread.\n * @template Props - The type of the component props being tracked (defaults to Record<string, any>)\n * @returns An object containing both global streamStatus and per-prop propStatus\n * @throws {Error} When used during SSR/SSG\n * @example\n * ```tsx\n * // Wait for entire stream\n * const { streamStatus } = useTamboStreamStatus();\n * if (!streamStatus.isSuccess) return <Spinner />;\n * return <Card {...props} />;\n * ```\n * @example\n * ```tsx\n * // Highlight in-flight props\n * const { propStatus } = useTamboStreamStatus<Props>();\n * <h2 className={propStatus.title.isStreaming ? \"animate-pulse\" : \"\"}>\n * {title}\n * </h2>\n * ```\n */\nexport function useTamboStreamStatus<\n Props extends Record<string, any> = Record<string, any>,\n>(): {\n streamStatus: StreamStatus;\n propStatus: Record<keyof Props, PropStatus>;\n} {\n /** SSR Guard - ensure client-side only execution */\n assertClientSide();\n\n const { generationStage } = useTamboGenerationStage();\n const message = useTamboCurrentMessage();\n\n /** Get the current component props from the message */\n const componentProps = (message?.component?.props as Props) || ({} as Props);\n\n /** Track per-prop streaming status */\n const propStatus = usePropsStreamingStatus(\n componentProps,\n generationStage,\n message?.id ?? \"\",\n );\n\n /** Derive global stream status from prop statuses and generation stage */\n const streamStatus = useMemo(() => {\n const generationError = message?.error\n ? new Error(message.error)\n : undefined;\n const hasComponent = !!message?.component;\n return deriveGlobalStreamStatus(\n generationStage,\n propStatus,\n hasComponent,\n generationError,\n );\n }, [generationStage, propStatus, message?.error, message?.component]);\n\n return {\n streamStatus,\n propStatus,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-tambo-stream-status.js","sourceRoot":"","sources":["../../src/hooks/use-tambo-stream-status.tsx"],"names":[],"mappings":";AAAA,YAAY,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sourcesContent":["\"use client\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { GenerationStage } from \"../model/generate-component-response\";\nimport { useTamboGenerationStage } from \"../providers/tambo-thread-provider\";\nimport { useTamboCurrentMessage } from \"./use-current-message\";\n\n/**\n * Global stream status flags for a specific component in a message.\n * Represents the aggregate state across all props for this component only.\n * Once a component completes, its status remains stable regardless of other generations.\n */\nexport interface StreamStatus {\n /**\n * Indicates no tokens have been received for any prop and generation is not active.\n * Useful for showing initial loading states before any data arrives.\n */\n isPending: boolean;\n\n /**\n * Indicates active streaming - either generation is streaming OR at least one prop is still streaming.\n * Use this to show loading animations or skeleton states during data transmission.\n */\n isStreaming: boolean;\n\n /**\n * Indicates successful completion - generation is complete AND every prop finished without error.\n * Safe to render the final component when this is true.\n */\n isSuccess: boolean;\n\n /**\n * Indicates a fatal error occurred in any prop or the stream itself.\n * Check streamError for details about what went wrong.\n */\n isError: boolean;\n\n /**\n * The first fatal error encountered during streaming (if any).\n * Will be undefined if no errors occurred.\n */\n streamError?: Error;\n}\n\n/**\n * Streaming status flags for individual component props.\n * Tracks the state of each prop as it streams from the LLM.\n */\nexport interface PropStatus {\n /**\n * Indicates no tokens have been received for this specific prop yet.\n * The prop value is still undefined, null, or empty string.\n */\n isPending: boolean;\n\n /**\n * Indicates at least one token has been received but streaming is not complete.\n * The prop has partial content that may still be updating.\n */\n isStreaming: boolean;\n\n /**\n * Indicates this prop has finished streaming successfully.\n * The prop value is complete and stable.\n */\n isSuccess: boolean;\n\n /**\n * The error that occurred during streaming (if any).\n * Will be undefined if no error occurred for this prop.\n */\n error?: Error;\n}\n\n/**\n * SSR Guard - throws during server-side rendering.\n * Ensures the hook is only used in browser contexts.\n * @throws {Error} When called during server-side rendering\n */\nfunction assertClientSide() {\n if (typeof window === \"undefined\") {\n throw new Error(\n \"useTamboStreamStatus can only be used in browser contexts. \" +\n \"This hook is not compatible with SSR/SSG. \" +\n \"Consider wrapping it in useEffect or using dynamic imports.\",\n );\n }\n}\n\n/**\n * Track streaming status for individual props by monitoring their values.\n * Monitors when props receive their first token and when they complete streaming.\n * Maintains stable state per message - once props complete for a message, they stay complete.\n * @template Props - The type of the component props being tracked\n * @param props - The current component props object\n * @param generationStage - The current generation stage from the LLM\n * @param messageId - The ID of the current message to track component-specific state\n * @returns A record mapping each prop key to its PropStatus\n */\nfunction usePropsStreamingStatus<Props extends Record<string, any>>(\n props: Props | undefined,\n generationStage: GenerationStage,\n messageId: string,\n): Record<keyof Props, PropStatus> {\n const [propTracking, setPropTracking] = useState<\n Record<\n string,\n {\n hasStarted: boolean;\n isComplete: boolean;\n error?: Error;\n messageId: string;\n }\n >\n >({});\n\n /** Reset tracking only when the message changes */\n useEffect(() => {\n setPropTracking((prev) => {\n // If we have tracking data for a different message, reset\n const hasOldMessageData = Object.values(prev).some(\n (track) => track.messageId && track.messageId !== messageId,\n );\n return hasOldMessageData ? {} : prev;\n });\n }, [messageId]);\n\n /** Track when props start streaming (receive first token) and when they complete */\n useEffect(() => {\n if (!props) return;\n\n setPropTracking((prev) => {\n const updated = { ...prev };\n let hasChanges = false;\n\n // First pass: identify which props are starting now\n const propsStartingNow: string[] = [];\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n if (justStarted) {\n propsStartingNow.push(key);\n }\n });\n\n // Second pass: update tracking and mark previous props as complete\n Object.entries(props).forEach(([key, value]) => {\n const current = prev[key] || {\n hasStarted: false,\n isComplete: false,\n };\n\n /** A prop starts streaming when it has a non-empty value for the first time */\n const hasContent =\n value !== undefined && value !== null && value !== \"\";\n const justStarted = hasContent && !current.hasStarted;\n\n /**\n * A prop is complete when it has started and either:\n * 1. A following prop has started, OR\n * 2. Generation is complete (for the final prop)\n */\n const hasFollowingPropStarted = propsStartingNow.some(\n (startingKey) => startingKey !== key,\n );\n const isGenerationComplete =\n generationStage === GenerationStage.COMPLETE;\n const isComplete =\n current.hasStarted &&\n (hasFollowingPropStarted || isGenerationComplete) &&\n !current.isComplete;\n\n // Once a prop is complete for this message, it stays complete\n if (current.isComplete && current.messageId === messageId) {\n // Skip - already complete for this message\n return;\n }\n\n if (justStarted || isComplete) {\n updated[key] = {\n ...current,\n hasStarted: justStarted ? true : current.hasStarted,\n isComplete: isComplete ? true : current.isComplete,\n messageId,\n };\n hasChanges = true;\n }\n });\n\n return hasChanges ? updated : prev;\n });\n }, [props, generationStage, messageId]);\n\n /** Convert tracking state to PropStatus objects */\n return useMemo(() => {\n if (!props) return {} as Record<keyof Props, PropStatus>;\n\n const result = {} as Record<keyof Props, PropStatus>;\n\n Object.keys(props).forEach((key) => {\n const tracking = propTracking[key] || {\n hasStarted: false,\n isComplete: false,\n messageId: \"\",\n };\n\n // If this prop is complete for this message, it stays complete\n const isCompleteForThisMessage =\n tracking.isComplete && tracking.messageId === messageId;\n\n // Only consider generation stage if this prop isn't already complete for this message\n const isGenerationStreaming =\n !isCompleteForThisMessage &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n\n result[key as keyof Props] = {\n isPending: !tracking.hasStarted && !isCompleteForThisMessage,\n isStreaming:\n tracking.hasStarted &&\n !isCompleteForThisMessage &&\n isGenerationStreaming,\n isSuccess: isCompleteForThisMessage,\n error: tracking.error,\n };\n });\n\n return result;\n }, [props, propTracking, generationStage, messageId]);\n}\n\n/**\n * Derives global StreamStatus from generation stage and individual prop statuses.\n * Aggregates individual prop states into a unified stream status.\n * @template Props - The type of the component props\n * @param generationStage - The current generation stage from the LLM\n * @param propStatus - Status record for each individual prop\n * @param hasComponent - Whether a component exists in the current message\n * @param generationError - Any error from the generation process itself\n * @returns The aggregated StreamStatus for the entire component\n */\nfunction deriveGlobalStreamStatus<Props extends Record<string, any>>(\n generationStage: GenerationStage,\n propStatus: Record<keyof Props, PropStatus>,\n hasComponent: boolean,\n generationError?: Error,\n): StreamStatus {\n const propStatuses = Object.values(propStatus) as PropStatus[];\n\n // If all props are already successful, the component is complete regardless of generation stage\n const allPropsSuccessful =\n propStatuses.length > 0 && propStatuses.every((p) => p.isSuccess);\n\n // Only consider generation stage if not all props are complete\n const isGenerationStreaming =\n !allPropsSuccessful &&\n generationStage === GenerationStage.STREAMING_RESPONSE;\n const isGenerationError = generationStage === GenerationStage.ERROR;\n\n /** Find first error from generation or any prop */\n const firstError =\n generationError ?? propStatuses.find((p) => p.error)?.error;\n\n return {\n /** isPending: no component yet OR (has component but no props have started) */\n isPending:\n !hasComponent ||\n (!isGenerationStreaming &&\n !allPropsSuccessful &&\n propStatuses.every((p) => p.isPending)),\n\n /** isStreaming: any prop is streaming (generation stage doesn't matter if props are complete) */\n isStreaming: propStatuses.some((p) => p.isStreaming),\n\n /** isSuccess: all props successful (component is stable once all props complete) */\n isSuccess: allPropsSuccessful,\n\n /** isError: generation error OR any prop error */\n isError:\n isGenerationError ||\n propStatuses.some((p) => p.error) ||\n !!generationError,\n\n streamError: firstError,\n };\n}\n\n/**\n * Hook that exposes per-prop and global streaming status for tambo-ai components.\n * Provides streaming readiness flags so consumers can show loaders, skeletons,\n * or errors while LLM-generated props stream in.\n * This hook tracks status for the specific component in the current message only.\n * Once a component's props complete streaming, they remain stable regardless of\n * other components being generated in the thread.\n * @template Props - The type of the component props being tracked (defaults to Record<string, any>)\n * @returns An object containing both global streamStatus and per-prop propStatus\n * @throws {Error} When used during SSR/SSG\n * @example\n * ```tsx\n * // Wait for entire stream\n * const { streamStatus } = useTamboStreamStatus();\n * if (!streamStatus.isSuccess) return <Spinner />;\n * return <Card {...props} />;\n * ```\n * @example\n * ```tsx\n * // Highlight in-flight props\n * const { propStatus } = useTamboStreamStatus<Props>();\n * <h2 className={propStatus.title.isStreaming ? \"animate-pulse\" : \"\"}>\n * {title}\n * </h2>\n * ```\n */\nexport function useTamboStreamStatus<\n Props extends Record<string, any> = Record<string, any>,\n>(): {\n streamStatus: StreamStatus;\n propStatus: Record<keyof Props, PropStatus>;\n} {\n /** SSR Guard - ensure client-side only execution */\n assertClientSide();\n\n const { generationStage } = useTamboGenerationStage();\n const message = useTamboCurrentMessage();\n\n /** Get the current component props from the message */\n const componentProps = (message?.component?.props as Props) || ({} as Props);\n\n /** Track per-prop streaming status */\n const propStatus = usePropsStreamingStatus(\n componentProps,\n generationStage,\n message?.id ?? \"\",\n );\n\n /** Derive global stream status from prop statuses and generation stage */\n const streamStatus = useMemo(() => {\n const generationError = message?.error\n ? new Error(message.error)\n : undefined;\n const hasComponent = !!message?.component;\n return deriveGlobalStreamStatus(\n generationStage,\n propStatus,\n hasComponent,\n generationError,\n );\n }, [generationStage, propStatus, message]);\n\n return {\n streamStatus,\n propStatus,\n };\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -59,4 +59,6 @@ Object.defineProperty(exports, "useTamboInteractable", { enumerable: true, get:
|
|
|
59
59
|
var context_helpers_1 = require("./context-helpers");
|
|
60
60
|
Object.defineProperty(exports, "currentPageContextHelper", { enumerable: true, get: function () { return context_helpers_1.currentPageContextHelper; } });
|
|
61
61
|
Object.defineProperty(exports, "currentTimeContextHelper", { enumerable: true, get: function () { return context_helpers_1.currentTimeContextHelper; } });
|
|
62
|
+
// Note MCP exports like TamboMcpProvider are available separately in the
|
|
63
|
+
// @tambo-ai/react/mcp package
|
|
62
64
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wKAAwK;;;;;;;;;;;;;;;;;AAExK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAGqC;AAFnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AAExB,iEAAgF;AAAvE,sHAAA,gBAAgB,OAAA;AACzB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,2EAIyC;AAHvC,+HAAA,oBAAoB,OAAA;AAKtB,gCAAgC;AAChC,yCAwBqB;AAvBnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,wHAAA,2BAA2B,OAAA;AAC3B,oHAAA,uBAAuB,OAAA;AACvB,0GAAA,aAAa,OAAA;AACb,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AACvB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,mHAAA,sBAAsB,OAAA;AACtB,oHAAA,uBAAuB,OAAA;AACvB,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,gHAAA,mBAAmB,OAAA;AAsBrB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA;AAUjB,mFAIiD;AAH/C,2HAAA,qBAAqB,OAAoB;AAI3C,uFAGiD;AAF/C,8IAAA,+BAA+B,OAAA;AAC/B,mIAAA,oBAAoB,OAAA;AAGtB,0BAA0B;AAC1B,qDAG2B;AAFzB,2HAAA,wBAAwB,OAAA;AACxB,2HAAA,wBAAwB,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n} from \"./hooks/use-current-message\";\nexport { useMessageImages, type StagedImage } from \"./hooks/use-message-images\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadInputProvider,\n TamboThreadProvider,\n useIsTamboTokenUpdating,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboGenerationStage,\n useTamboStream,\n useTamboThread,\n useTamboThreadInput,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n type TamboThreadInputContextProps,\n type TamboThreadProviderProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\nexport { type InitialTamboThreadMessage } from \"./providers/tambo-thread-provider\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport {\n useCurrentInteractablesSnapshot,\n useTamboInteractable,\n} from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wKAAwK;;;;;;;;;;;;;;;;;AAExK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAGqC;AAFnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AAExB,iEAAgF;AAAvE,sHAAA,gBAAgB,OAAA;AACzB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,2EAIyC;AAHvC,+HAAA,oBAAoB,OAAA;AAKtB,gCAAgC;AAChC,yCAwBqB;AAvBnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,wHAAA,2BAA2B,OAAA;AAC3B,oHAAA,uBAAuB,OAAA;AACvB,0GAAA,aAAa,OAAA;AACb,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AACvB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,mHAAA,sBAAsB,OAAA;AACtB,oHAAA,uBAAuB,OAAA;AACvB,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,gHAAA,mBAAmB,OAAA;AAsBrB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA;AAUjB,mFAIiD;AAH/C,2HAAA,qBAAqB,OAAoB;AAI3C,uFAGiD;AAF/C,8IAAA,+BAA+B,OAAA;AAC/B,mIAAA,oBAAoB,OAAA;AAGtB,0BAA0B;AAC1B,qDAG2B;AAFzB,2HAAA,wBAAwB,OAAA;AACxB,2HAAA,wBAAwB,OAAA;AAQ1B,yEAAyE;AACzE,8BAA8B","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n} from \"./hooks/use-current-message\";\nexport { useMessageImages, type StagedImage } from \"./hooks/use-message-images\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadInputProvider,\n TamboThreadProvider,\n useIsTamboTokenUpdating,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboGenerationStage,\n useTamboStream,\n useTamboThread,\n useTamboThreadInput,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n type TamboThreadInputContextProps,\n type TamboThreadProviderProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\nexport { type InitialTamboThreadMessage } from \"./providers/tambo-thread-provider\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport {\n useCurrentInteractablesSnapshot,\n useTamboInteractable,\n} from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n\n// Note MCP exports like TamboMcpProvider are available separately in the\n// @tambo-ai/react/mcp package\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elicitation.test.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/elicitation.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("@testing-library/react");
|
|
4
|
+
const elicitation_1 = require("../elicitation");
|
|
5
|
+
// Create a mock RequestHandlerExtra for testing
|
|
6
|
+
function createMockExtra() {
|
|
7
|
+
return {
|
|
8
|
+
signal: new AbortController().signal,
|
|
9
|
+
requestId: "test-request-id",
|
|
10
|
+
sendNotification: (async () => { }),
|
|
11
|
+
sendRequest: (async () => ({ _meta: {} })),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
describe("useElicitation", () => {
|
|
15
|
+
it("initializes with null state", () => {
|
|
16
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
17
|
+
expect(result.current.elicitation).toBeNull();
|
|
18
|
+
expect(result.current.resolveElicitation).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
it("provides state setters", () => {
|
|
21
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
22
|
+
expect(typeof result.current.setElicitation).toBe("function");
|
|
23
|
+
expect(typeof result.current.setResolveElicitation).toBe("function");
|
|
24
|
+
});
|
|
25
|
+
it("provides a default elicitation handler", () => {
|
|
26
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
27
|
+
expect(typeof result.current.defaultElicitationHandler).toBe("function");
|
|
28
|
+
});
|
|
29
|
+
describe("defaultElicitationHandler", () => {
|
|
30
|
+
it("sets elicitation state when called", async () => {
|
|
31
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
32
|
+
const request = {
|
|
33
|
+
params: {
|
|
34
|
+
message: "Please provide your name",
|
|
35
|
+
requestedSchema: {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
name: { type: "string", description: "Your name" },
|
|
39
|
+
},
|
|
40
|
+
required: ["name"],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
// Start the handler but don't await yet
|
|
45
|
+
let handlerPromise;
|
|
46
|
+
const extra = createMockExtra();
|
|
47
|
+
(0, react_1.act)(() => {
|
|
48
|
+
handlerPromise = result.current.defaultElicitationHandler(request, extra);
|
|
49
|
+
});
|
|
50
|
+
// Elicitation should be set
|
|
51
|
+
expect(result.current.elicitation).toEqual({
|
|
52
|
+
message: "Please provide your name",
|
|
53
|
+
requestedSchema: request.params.requestedSchema,
|
|
54
|
+
signal: extra.signal,
|
|
55
|
+
});
|
|
56
|
+
// Resolve callback should be set
|
|
57
|
+
expect(result.current.resolveElicitation).not.toBeNull();
|
|
58
|
+
// Clean up by resolving
|
|
59
|
+
(0, react_1.act)(() => {
|
|
60
|
+
result.current.resolveElicitation?.({
|
|
61
|
+
action: "cancel",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
await handlerPromise;
|
|
65
|
+
});
|
|
66
|
+
it("resolves promise when resolveElicitation is called with accept", async () => {
|
|
67
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
68
|
+
const request = {
|
|
69
|
+
params: {
|
|
70
|
+
message: "Enter your email",
|
|
71
|
+
requestedSchema: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
email: {
|
|
75
|
+
type: "string",
|
|
76
|
+
format: "email",
|
|
77
|
+
description: "Email address",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
// Start the handler
|
|
84
|
+
let handlerPromise;
|
|
85
|
+
const extra = createMockExtra();
|
|
86
|
+
(0, react_1.act)(() => {
|
|
87
|
+
handlerPromise = result.current.defaultElicitationHandler(request, extra);
|
|
88
|
+
});
|
|
89
|
+
// Resolve with accept
|
|
90
|
+
const response = {
|
|
91
|
+
action: "accept",
|
|
92
|
+
content: { email: "test@example.com" },
|
|
93
|
+
};
|
|
94
|
+
(0, react_1.act)(() => {
|
|
95
|
+
result.current.resolveElicitation?.(response);
|
|
96
|
+
});
|
|
97
|
+
// Wait for promise to resolve
|
|
98
|
+
const resolvedValue = await handlerPromise;
|
|
99
|
+
expect(resolvedValue).toEqual(response);
|
|
100
|
+
});
|
|
101
|
+
it("resolves promise when resolveElicitation is called with decline", async () => {
|
|
102
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
103
|
+
const request = {
|
|
104
|
+
params: {
|
|
105
|
+
message: "Provide input",
|
|
106
|
+
requestedSchema: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
value: { type: "string" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
let handlerPromise;
|
|
115
|
+
const extra = createMockExtra();
|
|
116
|
+
(0, react_1.act)(() => {
|
|
117
|
+
handlerPromise = result.current.defaultElicitationHandler(request, extra);
|
|
118
|
+
});
|
|
119
|
+
const response = {
|
|
120
|
+
action: "decline",
|
|
121
|
+
};
|
|
122
|
+
(0, react_1.act)(() => {
|
|
123
|
+
result.current.resolveElicitation?.(response);
|
|
124
|
+
});
|
|
125
|
+
const resolvedValue = await handlerPromise;
|
|
126
|
+
expect(resolvedValue).toEqual(response);
|
|
127
|
+
});
|
|
128
|
+
it("resolves promise when resolveElicitation is called with cancel", async () => {
|
|
129
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
130
|
+
const request = {
|
|
131
|
+
params: {
|
|
132
|
+
message: "Provide input",
|
|
133
|
+
requestedSchema: {
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
value: { type: "string" },
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
let handlerPromise;
|
|
142
|
+
const extra = createMockExtra();
|
|
143
|
+
(0, react_1.act)(() => {
|
|
144
|
+
handlerPromise = result.current.defaultElicitationHandler(request, extra);
|
|
145
|
+
});
|
|
146
|
+
const response = {
|
|
147
|
+
action: "cancel",
|
|
148
|
+
};
|
|
149
|
+
(0, react_1.act)(() => {
|
|
150
|
+
result.current.resolveElicitation?.(response);
|
|
151
|
+
});
|
|
152
|
+
const resolvedValue = await handlerPromise;
|
|
153
|
+
expect(resolvedValue).toEqual(response);
|
|
154
|
+
});
|
|
155
|
+
it("handles multiple sequential elicitations", async () => {
|
|
156
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
157
|
+
// First elicitation
|
|
158
|
+
const request1 = {
|
|
159
|
+
params: {
|
|
160
|
+
message: "First request",
|
|
161
|
+
requestedSchema: {
|
|
162
|
+
type: "object",
|
|
163
|
+
properties: {
|
|
164
|
+
field1: { type: "string" },
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
let promise1;
|
|
170
|
+
const extra1 = createMockExtra();
|
|
171
|
+
(0, react_1.act)(() => {
|
|
172
|
+
promise1 = result.current.defaultElicitationHandler(request1, extra1);
|
|
173
|
+
});
|
|
174
|
+
expect(result.current.elicitation?.message).toBe("First request");
|
|
175
|
+
(0, react_1.act)(() => {
|
|
176
|
+
result.current.resolveElicitation?.({
|
|
177
|
+
action: "accept",
|
|
178
|
+
content: { field1: "value1" },
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
const result1 = await promise1;
|
|
182
|
+
expect(result1).toEqual({
|
|
183
|
+
action: "accept",
|
|
184
|
+
content: { field1: "value1" },
|
|
185
|
+
});
|
|
186
|
+
// Second elicitation
|
|
187
|
+
const request2 = {
|
|
188
|
+
params: {
|
|
189
|
+
message: "Second request",
|
|
190
|
+
requestedSchema: {
|
|
191
|
+
type: "object",
|
|
192
|
+
properties: {
|
|
193
|
+
field2: { type: "number" },
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
let promise2;
|
|
199
|
+
const extra2 = createMockExtra();
|
|
200
|
+
(0, react_1.act)(() => {
|
|
201
|
+
promise2 = result.current.defaultElicitationHandler(request2, extra2);
|
|
202
|
+
});
|
|
203
|
+
expect(result.current.elicitation?.message).toBe("Second request");
|
|
204
|
+
(0, react_1.act)(() => {
|
|
205
|
+
result.current.resolveElicitation?.({
|
|
206
|
+
action: "accept",
|
|
207
|
+
content: { field2: 42 },
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
const result2 = await promise2;
|
|
211
|
+
expect(result2).toEqual({
|
|
212
|
+
action: "accept",
|
|
213
|
+
content: { field2: 42 },
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
it("maintains stable handler reference across re-renders", () => {
|
|
217
|
+
const { result, rerender } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
218
|
+
const firstHandler = result.current.defaultElicitationHandler;
|
|
219
|
+
rerender();
|
|
220
|
+
const secondHandler = result.current.defaultElicitationHandler;
|
|
221
|
+
expect(firstHandler).toBe(secondHandler);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
describe("state management", () => {
|
|
225
|
+
it("allows manual state updates via setElicitation", () => {
|
|
226
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
227
|
+
const customElicitation = {
|
|
228
|
+
message: "Custom message",
|
|
229
|
+
requestedSchema: {
|
|
230
|
+
type: "object",
|
|
231
|
+
properties: {
|
|
232
|
+
custom: { type: "boolean" },
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
(0, react_1.act)(() => {
|
|
237
|
+
result.current.setElicitation(customElicitation);
|
|
238
|
+
});
|
|
239
|
+
expect(result.current.elicitation).toEqual(customElicitation);
|
|
240
|
+
});
|
|
241
|
+
it("allows clearing elicitation state", () => {
|
|
242
|
+
const { result } = (0, react_1.renderHook)(() => (0, elicitation_1.useElicitation)());
|
|
243
|
+
const elicitation = {
|
|
244
|
+
message: "Test",
|
|
245
|
+
requestedSchema: {
|
|
246
|
+
type: "object",
|
|
247
|
+
properties: {},
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
(0, react_1.act)(() => {
|
|
251
|
+
result.current.setElicitation(elicitation);
|
|
252
|
+
});
|
|
253
|
+
expect(result.current.elicitation).not.toBeNull();
|
|
254
|
+
(0, react_1.act)(() => {
|
|
255
|
+
result.current.setElicitation(null);
|
|
256
|
+
});
|
|
257
|
+
expect(result.current.elicitation).toBeNull();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
//# sourceMappingURL=elicitation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elicitation.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/elicitation.test.tsx"],"names":[],"mappings":";;AAAA,kDAAyD;AACzD,gDAIwB;AAOxB,gDAAgD;AAChD,SAAS,eAAe;IAItB,OAAO;QACL,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QACpC,SAAS,EAAE,iBAAiB;QAE5B,gBAAgB,EAAE,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAQ;QAEzC,WAAW,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAQ;KAClD,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,M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W,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAElD,IAAA,WAAG,EAAC,GAAG,EAAE;gBACP,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { renderHook, act } from \"@testing-library/react\";\nimport {\n useElicitation,\n type TamboElicitationRequest,\n type TamboElicitationResponse,\n} from \"../elicitation\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n ClientNotification,\n ClientRequest,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n// Create a mock RequestHandlerExtra for testing\nfunction createMockExtra(): RequestHandlerExtra<\n ClientRequest,\n ClientNotification\n> {\n return {\n signal: new AbortController().signal,\n requestId: \"test-request-id\",\n\n sendNotification: (async () => {}) as any,\n\n sendRequest: (async () => ({ _meta: {} })) as any,\n };\n}\n\ndescribe(\"useElicitation\", () => {\n it(\"initializes with null state\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(result.current.elicitation).toBeNull();\n expect(result.current.resolveElicitation).toBeNull();\n });\n\n it(\"provides state setters\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(typeof result.current.setElicitation).toBe(\"function\");\n expect(typeof result.current.setResolveElicitation).toBe(\"function\");\n });\n\n it(\"provides a default elicitation handler\", () => {\n const { result } = renderHook(() => useElicitation());\n\n expect(typeof result.current.defaultElicitationHandler).toBe(\"function\");\n });\n\n describe(\"defaultElicitationHandler\", () => {\n it(\"sets elicitation state when called\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Please provide your name\",\n requestedSchema: {\n type: \"object\",\n properties: {\n name: { type: \"string\", description: \"Your name\" },\n },\n required: [\"name\"],\n },\n },\n };\n\n // Start the handler but don't await yet\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n // Elicitation should be set\n expect(result.current.elicitation).toEqual({\n message: \"Please provide your name\",\n requestedSchema: request.params.requestedSchema,\n signal: extra.signal,\n });\n\n // Resolve callback should be set\n expect(result.current.resolveElicitation).not.toBeNull();\n\n // Clean up by resolving\n act(() => {\n result.current.resolveElicitation?.({\n action: \"cancel\",\n });\n });\n\n await handlerPromise!;\n });\n\n it(\"resolves promise when resolveElicitation is called with accept\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Enter your email\",\n requestedSchema: {\n type: \"object\",\n properties: {\n email: {\n type: \"string\",\n format: \"email\",\n description: \"Email address\",\n },\n },\n },\n },\n };\n\n // Start the handler\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n // Resolve with accept\n const response: TamboElicitationResponse = {\n action: \"accept\",\n content: { email: \"test@example.com\" },\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n // Wait for promise to resolve\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"resolves promise when resolveElicitation is called with decline\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Provide input\",\n requestedSchema: {\n type: \"object\",\n properties: {\n value: { type: \"string\" },\n },\n },\n },\n };\n\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n const response: TamboElicitationResponse = {\n action: \"decline\",\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"resolves promise when resolveElicitation is called with cancel\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n const request: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Provide input\",\n requestedSchema: {\n type: \"object\",\n properties: {\n value: { type: \"string\" },\n },\n },\n },\n };\n\n let handlerPromise: Promise<TamboElicitationResponse>;\n const extra = createMockExtra();\n act(() => {\n handlerPromise = result.current.defaultElicitationHandler(\n request,\n extra,\n );\n });\n\n const response: TamboElicitationResponse = {\n action: \"cancel\",\n };\n\n act(() => {\n result.current.resolveElicitation?.(response);\n });\n\n const resolvedValue = await handlerPromise!;\n\n expect(resolvedValue).toEqual(response);\n });\n\n it(\"handles multiple sequential elicitations\", async () => {\n const { result } = renderHook(() => useElicitation());\n\n // First elicitation\n const request1: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"First request\",\n requestedSchema: {\n type: \"object\",\n properties: {\n field1: { type: \"string\" },\n },\n },\n },\n };\n\n let promise1: Promise<TamboElicitationResponse>;\n const extra1 = createMockExtra();\n act(() => {\n promise1 = result.current.defaultElicitationHandler(request1, extra1);\n });\n\n expect(result.current.elicitation?.message).toBe(\"First request\");\n\n act(() => {\n result.current.resolveElicitation?.({\n action: \"accept\",\n content: { field1: \"value1\" },\n });\n });\n\n const result1 = await promise1!;\n expect(result1).toEqual({\n action: \"accept\",\n content: { field1: \"value1\" },\n });\n\n // Second elicitation\n const request2: Parameters<\n typeof result.current.defaultElicitationHandler\n >[0] = {\n params: {\n message: \"Second request\",\n requestedSchema: {\n type: \"object\",\n properties: {\n field2: { type: \"number\" },\n },\n },\n },\n };\n\n let promise2: Promise<TamboElicitationResponse>;\n const extra2 = createMockExtra();\n act(() => {\n promise2 = result.current.defaultElicitationHandler(request2, extra2);\n });\n\n expect(result.current.elicitation?.message).toBe(\"Second request\");\n\n act(() => {\n result.current.resolveElicitation?.({\n action: \"accept\",\n content: { field2: 42 },\n });\n });\n\n const result2 = await promise2!;\n expect(result2).toEqual({\n action: \"accept\",\n content: { field2: 42 },\n });\n });\n\n it(\"maintains stable handler reference across re-renders\", () => {\n const { result, rerender } = renderHook(() => useElicitation());\n\n const firstHandler = result.current.defaultElicitationHandler;\n\n rerender();\n\n const secondHandler = result.current.defaultElicitationHandler;\n\n expect(firstHandler).toBe(secondHandler);\n });\n });\n\n describe(\"state management\", () => {\n it(\"allows manual state updates via setElicitation\", () => {\n const { result } = renderHook(() => useElicitation());\n\n const customElicitation: TamboElicitationRequest = {\n message: \"Custom message\",\n requestedSchema: {\n type: \"object\",\n properties: {\n custom: { type: \"boolean\" },\n },\n },\n };\n\n act(() => {\n result.current.setElicitation(customElicitation);\n });\n\n expect(result.current.elicitation).toEqual(customElicitation);\n });\n\n it(\"allows clearing elicitation state\", () => {\n const { result } = renderHook(() => useElicitation());\n\n const elicitation: TamboElicitationRequest = {\n message: \"Test\",\n requestedSchema: {\n type: \"object\",\n properties: {},\n },\n };\n\n act(() => {\n result.current.setElicitation(elicitation);\n });\n\n expect(result.current.elicitation).not.toBeNull();\n\n act(() => {\n result.current.setElicitation(null);\n });\n\n expect(result.current.elicitation).toBeNull();\n });\n });\n});\n"]}
|