@tambo-ai/react 0.59.0 → 0.62.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.
Files changed (135) hide show
  1. package/dist/__tests__/util/validate-zod-schema.test.js +25 -0
  2. package/dist/__tests__/util/validate-zod-schema.test.js.map +1 -1
  3. package/dist/hooks/index.d.ts +1 -0
  4. package/dist/hooks/index.d.ts.map +1 -1
  5. package/dist/hooks/index.js +3 -1
  6. package/dist/hooks/index.js.map +1 -1
  7. package/dist/hooks/react-query-hooks.d.ts +14 -1
  8. package/dist/hooks/react-query-hooks.d.ts.map +1 -1
  9. package/dist/hooks/react-query-hooks.js +13 -0
  10. package/dist/hooks/react-query-hooks.js.map +1 -1
  11. package/dist/hooks/use-tambo-voice.d.ts +21 -0
  12. package/dist/hooks/use-tambo-voice.d.ts.map +1 -0
  13. package/dist/hooks/use-tambo-voice.js +74 -0
  14. package/dist/hooks/use-tambo-voice.js.map +1 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/mcp/__tests__/elicitation.test.d.ts +2 -0
  20. package/dist/mcp/__tests__/elicitation.test.d.ts.map +1 -0
  21. package/dist/mcp/__tests__/elicitation.test.js +261 -0
  22. package/dist/mcp/__tests__/elicitation.test.js.map +1 -0
  23. package/dist/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
  24. package/dist/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
  25. package/dist/mcp/__tests__/mcp-hooks.test.js +504 -0
  26. package/dist/mcp/__tests__/mcp-hooks.test.js.map +1 -0
  27. package/dist/mcp/__tests__/tambo-mcp-provider.test.js +155 -16
  28. package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
  29. package/dist/mcp/elicitation.d.ts +80 -0
  30. package/dist/mcp/elicitation.d.ts.map +1 -0
  31. package/dist/mcp/elicitation.js +55 -0
  32. package/dist/mcp/elicitation.js.map +1 -0
  33. package/dist/mcp/index.d.ts +3 -2
  34. package/dist/mcp/index.d.ts.map +1 -1
  35. package/dist/mcp/index.js +2 -1
  36. package/dist/mcp/index.js.map +1 -1
  37. package/dist/mcp/mcp-client.d.ts +41 -9
  38. package/dist/mcp/mcp-client.d.ts.map +1 -1
  39. package/dist/mcp/mcp-client.js.map +1 -1
  40. package/dist/mcp/mcp-hooks.d.ts +20 -6
  41. package/dist/mcp/mcp-hooks.d.ts.map +1 -1
  42. package/dist/mcp/mcp-hooks.js +71 -24
  43. package/dist/mcp/mcp-hooks.js.map +1 -1
  44. package/dist/mcp/tambo-mcp-provider.d.ts +61 -7
  45. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  46. package/dist/mcp/tambo-mcp-provider.js +231 -172
  47. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  48. package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js +1 -1
  49. package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
  50. package/dist/providers/__tests__/tambo-thread-provider.test.js +170 -0
  51. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  52. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  53. package/dist/providers/tambo-interactable-provider.js +11 -4
  54. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  55. package/dist/providers/tambo-provider.d.ts +2 -0
  56. package/dist/providers/tambo-provider.d.ts.map +1 -1
  57. package/dist/providers/tambo-provider.js +4 -6
  58. package/dist/providers/tambo-provider.js.map +1 -1
  59. package/dist/providers/tambo-thread-provider.d.ts +6 -0
  60. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  61. package/dist/providers/tambo-thread-provider.js +112 -45
  62. package/dist/providers/tambo-thread-provider.js.map +1 -1
  63. package/dist/setupTests.js +10 -0
  64. package/dist/setupTests.js.map +1 -1
  65. package/dist/util/validate-zod-schema.d.ts.map +1 -1
  66. package/dist/util/validate-zod-schema.js +11 -0
  67. package/dist/util/validate-zod-schema.js.map +1 -1
  68. package/esm/__tests__/util/validate-zod-schema.test.js +25 -0
  69. package/esm/__tests__/util/validate-zod-schema.test.js.map +1 -1
  70. package/esm/hooks/index.d.ts +1 -0
  71. package/esm/hooks/index.d.ts.map +1 -1
  72. package/esm/hooks/index.js +1 -0
  73. package/esm/hooks/index.js.map +1 -1
  74. package/esm/hooks/react-query-hooks.d.ts +14 -1
  75. package/esm/hooks/react-query-hooks.d.ts.map +1 -1
  76. package/esm/hooks/react-query-hooks.js +13 -1
  77. package/esm/hooks/react-query-hooks.js.map +1 -1
  78. package/esm/hooks/use-tambo-voice.d.ts +21 -0
  79. package/esm/hooks/use-tambo-voice.d.ts.map +1 -0
  80. package/esm/hooks/use-tambo-voice.js +71 -0
  81. package/esm/hooks/use-tambo-voice.js.map +1 -0
  82. package/esm/index.d.ts +1 -0
  83. package/esm/index.d.ts.map +1 -1
  84. package/esm/index.js +3 -0
  85. package/esm/index.js.map +1 -1
  86. package/esm/mcp/__tests__/elicitation.test.d.ts +2 -0
  87. package/esm/mcp/__tests__/elicitation.test.d.ts.map +1 -0
  88. package/esm/mcp/__tests__/elicitation.test.js +259 -0
  89. package/esm/mcp/__tests__/elicitation.test.js.map +1 -0
  90. package/esm/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
  91. package/esm/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
  92. package/esm/mcp/__tests__/mcp-hooks.test.js +469 -0
  93. package/esm/mcp/__tests__/mcp-hooks.test.js.map +1 -0
  94. package/esm/mcp/__tests__/tambo-mcp-provider.test.js +155 -16
  95. package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
  96. package/esm/mcp/elicitation.d.ts +80 -0
  97. package/esm/mcp/elicitation.d.ts.map +1 -0
  98. package/esm/mcp/elicitation.js +52 -0
  99. package/esm/mcp/elicitation.js.map +1 -0
  100. package/esm/mcp/index.d.ts +3 -2
  101. package/esm/mcp/index.d.ts.map +1 -1
  102. package/esm/mcp/index.js +1 -1
  103. package/esm/mcp/index.js.map +1 -1
  104. package/esm/mcp/mcp-client.d.ts +41 -9
  105. package/esm/mcp/mcp-client.d.ts.map +1 -1
  106. package/esm/mcp/mcp-client.js.map +1 -1
  107. package/esm/mcp/mcp-hooks.d.ts +20 -6
  108. package/esm/mcp/mcp-hooks.d.ts.map +1 -1
  109. package/esm/mcp/mcp-hooks.js +73 -26
  110. package/esm/mcp/mcp-hooks.js.map +1 -1
  111. package/esm/mcp/tambo-mcp-provider.d.ts +61 -7
  112. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  113. package/esm/mcp/tambo-mcp-provider.js +231 -173
  114. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  115. package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js +1 -1
  116. package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
  117. package/esm/providers/__tests__/tambo-thread-provider.test.js +170 -0
  118. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  119. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  120. package/esm/providers/tambo-interactable-provider.js +11 -4
  121. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  122. package/esm/providers/tambo-provider.d.ts +2 -0
  123. package/esm/providers/tambo-provider.d.ts.map +1 -1
  124. package/esm/providers/tambo-provider.js +4 -6
  125. package/esm/providers/tambo-provider.js.map +1 -1
  126. package/esm/providers/tambo-thread-provider.d.ts +6 -0
  127. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  128. package/esm/providers/tambo-thread-provider.js +112 -45
  129. package/esm/providers/tambo-thread-provider.js.map +1 -1
  130. package/esm/setupTests.js +10 -0
  131. package/esm/setupTests.js.map +1 -1
  132. package/esm/util/validate-zod-schema.d.ts.map +1 -1
  133. package/esm/util/validate-zod-schema.js +11 -0
  134. package/esm/util/validate-zod-schema.js.map +1 -1
  135. package/package.json +10 -9
@@ -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,IAA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f,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mcp-hooks.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-hooks.test.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/mcp-hooks.test.tsx"],"names":[],"mappings":""}