@tambo-ai/react 0.59.0 → 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/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-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 +151 -12
- package/dist/mcp/__tests__/tambo-mcp-provider.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 +3 -2
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +2 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts +41 -9
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/mcp/mcp-hooks.d.ts +20 -6
- package/dist/mcp/mcp-hooks.d.ts.map +1 -1
- package/dist/mcp/mcp-hooks.js +71 -24
- package/dist/mcp/mcp-hooks.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.d.ts +60 -6
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +231 -172
- package/dist/mcp/tambo-mcp-provider.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-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +0 -4
- package/dist/providers/tambo-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/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-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 +151 -12
- package/esm/mcp/__tests__/tambo-mcp-provider.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 +3 -2
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +1 -1
- package/esm/mcp/index.js.map +1 -1
- package/esm/mcp/mcp-client.d.ts +41 -9
- package/esm/mcp/mcp-client.d.ts.map +1 -1
- package/esm/mcp/mcp-client.js.map +1 -1
- package/esm/mcp/mcp-hooks.d.ts +20 -6
- package/esm/mcp/mcp-hooks.d.ts.map +1 -1
- package/esm/mcp/mcp-hooks.js +73 -26
- package/esm/mcp/mcp-hooks.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.d.ts +60 -6
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +231 -173
- package/esm/mcp/tambo-mcp-provider.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-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +0 -4
- package/esm/providers/tambo-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"]}
|
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,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,4BAAc,GAAE,CAAC,CAAC;QAEtD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAChC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,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BACzB,eAAe,EAAE;oBACf,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;qBAC5B;iBACF;aACF,CAAC;YAEF,IAAA,WAAG,EAAC,GAAG,EAAE;gBACP,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,4BAAc,GAAE,CAAC,CAAC;YAEtD,MAAM,WAAW,GAA4B;gBAC3C,OAAO,EAAE,MAAM;gBACf,eAAe,EAAE;oBACf,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE,EAAE;iBACf;aACF,CAAC;YAEF,IAAA,WAAG,EAAC,GAAG,EAAE;gBACP,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-hooks.test.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/mcp-hooks.test.tsx"],"names":[],"mappings":""}
|