@juspay/neurolink 9.26.2 → 9.28.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 (125) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +59 -9
  3. package/dist/cli/commands/config.d.ts +4 -4
  4. package/dist/cli/commands/mcp.d.ts +87 -0
  5. package/dist/cli/commands/mcp.js +1524 -0
  6. package/dist/cli/loop/optionsSchema.js +4 -0
  7. package/dist/core/modules/ToolsManager.js +29 -2
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +27 -1
  10. package/dist/lib/core/modules/ToolsManager.js +29 -2
  11. package/dist/lib/index.d.ts +2 -1
  12. package/dist/lib/index.js +27 -1
  13. package/dist/lib/mcp/agentExposure.d.ts +228 -0
  14. package/dist/lib/mcp/agentExposure.js +357 -0
  15. package/dist/lib/mcp/batching/index.d.ts +11 -0
  16. package/dist/lib/mcp/batching/index.js +11 -0
  17. package/dist/lib/mcp/batching/requestBatcher.d.ts +202 -0
  18. package/dist/lib/mcp/batching/requestBatcher.js +442 -0
  19. package/dist/lib/mcp/caching/index.d.ts +11 -0
  20. package/dist/lib/mcp/caching/index.js +11 -0
  21. package/dist/lib/mcp/caching/toolCache.d.ts +221 -0
  22. package/dist/lib/mcp/caching/toolCache.js +434 -0
  23. package/dist/lib/mcp/elicitation/elicitationManager.d.ts +169 -0
  24. package/dist/lib/mcp/elicitation/elicitationManager.js +377 -0
  25. package/dist/lib/mcp/elicitation/index.d.ts +11 -0
  26. package/dist/lib/mcp/elicitation/index.js +12 -0
  27. package/dist/lib/mcp/elicitation/types.d.ts +278 -0
  28. package/dist/lib/mcp/elicitation/types.js +11 -0
  29. package/dist/lib/mcp/elicitationProtocol.d.ts +228 -0
  30. package/dist/lib/mcp/elicitationProtocol.js +376 -0
  31. package/dist/lib/mcp/enhancedToolDiscovery.d.ts +205 -0
  32. package/dist/lib/mcp/enhancedToolDiscovery.js +482 -0
  33. package/dist/lib/mcp/index.d.ts +38 -1
  34. package/dist/lib/mcp/index.js +36 -3
  35. package/dist/lib/mcp/mcpRegistryClient.d.ts +332 -0
  36. package/dist/lib/mcp/mcpRegistryClient.js +489 -0
  37. package/dist/lib/mcp/mcpServerBase.d.ts +227 -0
  38. package/dist/lib/mcp/mcpServerBase.js +374 -0
  39. package/dist/lib/mcp/multiServerManager.d.ts +310 -0
  40. package/dist/lib/mcp/multiServerManager.js +580 -0
  41. package/dist/lib/mcp/routing/index.d.ts +11 -0
  42. package/dist/lib/mcp/routing/index.js +11 -0
  43. package/dist/lib/mcp/routing/toolRouter.d.ts +219 -0
  44. package/dist/lib/mcp/routing/toolRouter.js +417 -0
  45. package/dist/lib/mcp/serverCapabilities.d.ts +341 -0
  46. package/dist/lib/mcp/serverCapabilities.js +503 -0
  47. package/dist/lib/mcp/toolAnnotations.d.ts +154 -0
  48. package/dist/lib/mcp/toolAnnotations.js +240 -0
  49. package/dist/lib/mcp/toolConverter.d.ts +178 -0
  50. package/dist/lib/mcp/toolConverter.js +259 -0
  51. package/dist/lib/mcp/toolIntegration.d.ts +136 -0
  52. package/dist/lib/mcp/toolIntegration.js +335 -0
  53. package/dist/lib/memory/hippocampusInitializer.d.ts +2 -2
  54. package/dist/lib/memory/hippocampusInitializer.js +1 -1
  55. package/dist/lib/neurolink.d.ts +275 -2
  56. package/dist/lib/neurolink.js +596 -56
  57. package/dist/lib/providers/litellm.d.ts +10 -0
  58. package/dist/lib/providers/litellm.js +104 -2
  59. package/dist/lib/types/configTypes.d.ts +56 -0
  60. package/dist/lib/types/conversation.d.ts +2 -2
  61. package/dist/lib/types/generateTypes.d.ts +4 -0
  62. package/dist/lib/types/index.d.ts +2 -1
  63. package/dist/lib/types/modelTypes.d.ts +6 -6
  64. package/dist/lib/types/streamTypes.d.ts +2 -0
  65. package/dist/lib/types/tools.d.ts +2 -0
  66. package/dist/lib/utils/pricing.js +177 -17
  67. package/dist/lib/utils/schemaConversion.d.ts +6 -1
  68. package/dist/lib/utils/schemaConversion.js +50 -28
  69. package/dist/lib/workflow/config.d.ts +16 -16
  70. package/dist/mcp/agentExposure.d.ts +228 -0
  71. package/dist/mcp/agentExposure.js +356 -0
  72. package/dist/mcp/batching/index.d.ts +11 -0
  73. package/dist/mcp/batching/index.js +10 -0
  74. package/dist/mcp/batching/requestBatcher.d.ts +202 -0
  75. package/dist/mcp/batching/requestBatcher.js +441 -0
  76. package/dist/mcp/caching/index.d.ts +11 -0
  77. package/dist/mcp/caching/index.js +10 -0
  78. package/dist/mcp/caching/toolCache.d.ts +221 -0
  79. package/dist/mcp/caching/toolCache.js +433 -0
  80. package/dist/mcp/elicitation/elicitationManager.d.ts +169 -0
  81. package/dist/mcp/elicitation/elicitationManager.js +376 -0
  82. package/dist/mcp/elicitation/index.d.ts +11 -0
  83. package/dist/mcp/elicitation/index.js +11 -0
  84. package/dist/mcp/elicitation/types.d.ts +278 -0
  85. package/dist/mcp/elicitation/types.js +10 -0
  86. package/dist/mcp/elicitationProtocol.d.ts +228 -0
  87. package/dist/mcp/elicitationProtocol.js +375 -0
  88. package/dist/mcp/enhancedToolDiscovery.d.ts +205 -0
  89. package/dist/mcp/enhancedToolDiscovery.js +481 -0
  90. package/dist/mcp/index.d.ts +38 -1
  91. package/dist/mcp/index.js +36 -3
  92. package/dist/mcp/mcpRegistryClient.d.ts +332 -0
  93. package/dist/mcp/mcpRegistryClient.js +488 -0
  94. package/dist/mcp/mcpServerBase.d.ts +227 -0
  95. package/dist/mcp/mcpServerBase.js +373 -0
  96. package/dist/mcp/multiServerManager.d.ts +310 -0
  97. package/dist/mcp/multiServerManager.js +579 -0
  98. package/dist/mcp/routing/index.d.ts +11 -0
  99. package/dist/mcp/routing/index.js +10 -0
  100. package/dist/mcp/routing/toolRouter.d.ts +219 -0
  101. package/dist/mcp/routing/toolRouter.js +416 -0
  102. package/dist/mcp/serverCapabilities.d.ts +341 -0
  103. package/dist/mcp/serverCapabilities.js +502 -0
  104. package/dist/mcp/toolAnnotations.d.ts +154 -0
  105. package/dist/mcp/toolAnnotations.js +239 -0
  106. package/dist/mcp/toolConverter.d.ts +178 -0
  107. package/dist/mcp/toolConverter.js +258 -0
  108. package/dist/mcp/toolIntegration.d.ts +136 -0
  109. package/dist/mcp/toolIntegration.js +334 -0
  110. package/dist/memory/hippocampusInitializer.d.ts +2 -2
  111. package/dist/memory/hippocampusInitializer.js +1 -1
  112. package/dist/neurolink.d.ts +275 -2
  113. package/dist/neurolink.js +596 -56
  114. package/dist/providers/litellm.d.ts +10 -0
  115. package/dist/providers/litellm.js +104 -2
  116. package/dist/types/configTypes.d.ts +56 -0
  117. package/dist/types/conversation.d.ts +2 -2
  118. package/dist/types/generateTypes.d.ts +4 -0
  119. package/dist/types/index.d.ts +2 -1
  120. package/dist/types/streamTypes.d.ts +2 -0
  121. package/dist/types/tools.d.ts +2 -0
  122. package/dist/utils/pricing.js +177 -17
  123. package/dist/utils/schemaConversion.d.ts +6 -1
  124. package/dist/utils/schemaConversion.js +50 -28
  125. package/package.json +2 -2
@@ -0,0 +1,228 @@
1
+ /**
2
+ * MCP Elicitation Protocol
3
+ *
4
+ * Protocol-level interface for the MCP elicitation system that enables
5
+ * tools to request interactive user input during execution.
6
+ *
7
+ * This module provides:
8
+ * - Protocol message types for MCP elicitation requests/responses
9
+ * - Protocol-level handlers for different transport types
10
+ * - Utility functions for protocol message construction
11
+ * - Integration with the ElicitationManager
12
+ *
13
+ * Implements MCP 2024-11-05 elicitation specification.
14
+ *
15
+ * @module mcp/elicitationProtocol
16
+ * @since 8.39.0
17
+ */
18
+ import type { JsonValue } from "../types/common.js";
19
+ import type { Elicitation, ElicitationResponse, ElicitationType, ElicitationHandler, FormField, SelectOption } from "./elicitation/types.js";
20
+ import { ElicitationManager } from "./elicitation/elicitationManager.js";
21
+ /**
22
+ * MCP elicitation protocol message types
23
+ */
24
+ export type ElicitationProtocolMessageType = "elicitation/request" | "elicitation/response" | "elicitation/cancel";
25
+ /**
26
+ * Request params type
27
+ */
28
+ export type ElicitationRequestParams = {
29
+ type: ElicitationType;
30
+ message: string;
31
+ toolName: string;
32
+ serverId?: string;
33
+ timeout?: number;
34
+ optional?: boolean;
35
+ defaultValue?: JsonValue;
36
+ options?: Record<string, JsonValue>;
37
+ };
38
+ /**
39
+ * Response params type
40
+ */
41
+ export type ElicitationResponseParams = {
42
+ requestId: string;
43
+ responded: boolean;
44
+ value?: JsonValue;
45
+ cancelled?: boolean;
46
+ timedOut?: boolean;
47
+ error?: string;
48
+ };
49
+ /**
50
+ * Cancel params type
51
+ */
52
+ export type ElicitationCancelParams = {
53
+ requestId: string;
54
+ reason?: string;
55
+ };
56
+ /**
57
+ * Base protocol message structure
58
+ */
59
+ export type ElicitationProtocolMessage = {
60
+ jsonrpc: "2.0";
61
+ id: string;
62
+ method: ElicitationProtocolMessageType;
63
+ params: ElicitationRequestParams | ElicitationResponseParams | ElicitationCancelParams;
64
+ };
65
+ /**
66
+ * Elicitation request protocol message
67
+ */
68
+ export type ElicitationRequestMessage = {
69
+ jsonrpc: "2.0";
70
+ id: string;
71
+ method: "elicitation/request";
72
+ params: ElicitationRequestParams;
73
+ };
74
+ /**
75
+ * Elicitation response protocol message
76
+ */
77
+ export type ElicitationResponseMessage = {
78
+ jsonrpc: "2.0";
79
+ id: string;
80
+ method: "elicitation/response";
81
+ params: ElicitationResponseParams;
82
+ };
83
+ /**
84
+ * Elicitation cancel protocol message
85
+ */
86
+ export type ElicitationCancelMessage = {
87
+ jsonrpc: "2.0";
88
+ id: string;
89
+ method: "elicitation/cancel";
90
+ params: ElicitationCancelParams;
91
+ };
92
+ /**
93
+ * Protocol message union type
94
+ */
95
+ export type ElicitationProtocolPayload = ElicitationRequestMessage | ElicitationResponseMessage | ElicitationCancelMessage;
96
+ /**
97
+ * Protocol handler function type
98
+ */
99
+ export type ElicitationProtocolHandler = (message: ElicitationProtocolPayload) => Promise<ElicitationProtocolPayload | void>;
100
+ /**
101
+ * Protocol adapter configuration
102
+ */
103
+ export type ElicitationProtocolAdapterConfig = {
104
+ manager?: ElicitationManager;
105
+ defaultTimeout?: number;
106
+ enableLogging?: boolean;
107
+ customHandler?: ElicitationProtocolHandler;
108
+ };
109
+ /**
110
+ * Create an elicitation request protocol message
111
+ */
112
+ export declare function createElicitationRequest(params: ElicitationRequestParams): ElicitationRequestMessage;
113
+ /**
114
+ * Create an elicitation response protocol message
115
+ */
116
+ export declare function createElicitationResponse(requestId: string, response: Omit<ElicitationResponseParams, "requestId">): ElicitationResponseMessage;
117
+ /**
118
+ * Create an elicitation cancel protocol message
119
+ */
120
+ export declare function createElicitationCancel(requestId: string, reason?: string): ElicitationCancelMessage;
121
+ /**
122
+ * Check if a message is an elicitation protocol message
123
+ */
124
+ export declare function isElicitationProtocolMessage(message: unknown): message is ElicitationProtocolPayload;
125
+ /**
126
+ * Convert protocol message to Elicitation type
127
+ */
128
+ export declare function protocolMessageToElicitation(message: ElicitationRequestMessage): Elicitation;
129
+ /**
130
+ * Convert ElicitationResponse to protocol message
131
+ */
132
+ export declare function elicitationResponseToProtocol(response: ElicitationResponse): ElicitationResponseMessage;
133
+ /**
134
+ * Elicitation Protocol Adapter
135
+ *
136
+ * Bridges protocol-level messages with the ElicitationManager
137
+ */
138
+ export declare class ElicitationProtocolAdapter {
139
+ private manager;
140
+ private config;
141
+ constructor(config?: ElicitationProtocolAdapterConfig);
142
+ /**
143
+ * Handle incoming protocol message
144
+ */
145
+ handleMessage(message: ElicitationProtocolPayload): Promise<ElicitationProtocolPayload | void>;
146
+ /**
147
+ * Handle elicitation request
148
+ */
149
+ private handleRequest;
150
+ /**
151
+ * Handle elicitation response (for external responses)
152
+ */
153
+ private handleResponse;
154
+ /**
155
+ * Handle elicitation cancel
156
+ */
157
+ private handleCancel;
158
+ /**
159
+ * Send an elicitation request through the protocol
160
+ */
161
+ requestElicitation(params: ElicitationRequestParams): Promise<ElicitationResponse>;
162
+ /**
163
+ * Cancel a pending elicitation
164
+ */
165
+ cancelElicitation(requestId: string, reason?: string): void;
166
+ /**
167
+ * Get the underlying manager
168
+ */
169
+ getManager(): ElicitationManager;
170
+ /**
171
+ * Set protocol handler for the manager
172
+ */
173
+ setHandler(handler: ElicitationHandler): void;
174
+ /**
175
+ * Enable/disable the protocol
176
+ */
177
+ setEnabled(enabled: boolean): void;
178
+ /**
179
+ * Check if protocol is enabled
180
+ */
181
+ isEnabled(): boolean;
182
+ }
183
+ /**
184
+ * Create protocol-compliant confirmation request
185
+ */
186
+ export declare function createConfirmationRequest(message: string, options: {
187
+ toolName: string;
188
+ serverId?: string;
189
+ confirmLabel?: string;
190
+ cancelLabel?: string;
191
+ timeout?: number;
192
+ }): ElicitationRequestMessage;
193
+ /**
194
+ * Create protocol-compliant text input request
195
+ */
196
+ export declare function createTextInputRequest(message: string, options: {
197
+ toolName: string;
198
+ serverId?: string;
199
+ placeholder?: string;
200
+ defaultValue?: string;
201
+ minLength?: number;
202
+ maxLength?: number;
203
+ pattern?: string;
204
+ multiline?: boolean;
205
+ timeout?: number;
206
+ }): ElicitationRequestMessage;
207
+ /**
208
+ * Create protocol-compliant select request
209
+ */
210
+ export declare function createSelectRequest(message: string, selectOptions: SelectOption[], options: {
211
+ toolName: string;
212
+ serverId?: string;
213
+ defaultValue?: string;
214
+ timeout?: number;
215
+ }): ElicitationRequestMessage;
216
+ /**
217
+ * Create protocol-compliant form request
218
+ */
219
+ export declare function createFormRequest(message: string, fields: FormField[], options: {
220
+ toolName: string;
221
+ serverId?: string;
222
+ submitLabel?: string;
223
+ timeout?: number;
224
+ }): ElicitationRequestMessage;
225
+ /**
226
+ * Global protocol adapter instance
227
+ */
228
+ export declare const globalElicitationProtocol: ElicitationProtocolAdapter;
@@ -0,0 +1,376 @@
1
+ /**
2
+ * MCP Elicitation Protocol
3
+ *
4
+ * Protocol-level interface for the MCP elicitation system that enables
5
+ * tools to request interactive user input during execution.
6
+ *
7
+ * This module provides:
8
+ * - Protocol message types for MCP elicitation requests/responses
9
+ * - Protocol-level handlers for different transport types
10
+ * - Utility functions for protocol message construction
11
+ * - Integration with the ElicitationManager
12
+ *
13
+ * Implements MCP 2024-11-05 elicitation specification.
14
+ *
15
+ * @module mcp/elicitationProtocol
16
+ * @since 8.39.0
17
+ */
18
+ import { randomUUID } from "crypto";
19
+ import { logger } from "../utils/logger.js";
20
+ import { withTimeout } from "../utils/async/withTimeout.js";
21
+ import { ElicitationManager, globalElicitationManager, } from "./elicitation/elicitationManager.js";
22
+ /**
23
+ * Create an elicitation request protocol message
24
+ */
25
+ export function createElicitationRequest(params) {
26
+ return {
27
+ jsonrpc: "2.0",
28
+ id: randomUUID(),
29
+ method: "elicitation/request",
30
+ params: {
31
+ type: params.type,
32
+ message: params.message,
33
+ toolName: params.toolName,
34
+ serverId: params.serverId,
35
+ timeout: params.timeout,
36
+ optional: params.optional,
37
+ defaultValue: params.defaultValue,
38
+ options: params.options ?? {},
39
+ },
40
+ };
41
+ }
42
+ /**
43
+ * Create an elicitation response protocol message
44
+ */
45
+ export function createElicitationResponse(requestId, response) {
46
+ return {
47
+ jsonrpc: "2.0",
48
+ id: randomUUID(),
49
+ method: "elicitation/response",
50
+ params: {
51
+ requestId,
52
+ responded: response.responded,
53
+ value: response.value,
54
+ cancelled: response.cancelled,
55
+ timedOut: response.timedOut,
56
+ error: response.error,
57
+ },
58
+ };
59
+ }
60
+ /**
61
+ * Create an elicitation cancel protocol message
62
+ */
63
+ export function createElicitationCancel(requestId, reason) {
64
+ return {
65
+ jsonrpc: "2.0",
66
+ id: randomUUID(),
67
+ method: "elicitation/cancel",
68
+ params: {
69
+ requestId,
70
+ reason,
71
+ },
72
+ };
73
+ }
74
+ /**
75
+ * Check if a message is an elicitation protocol message
76
+ */
77
+ export function isElicitationProtocolMessage(message) {
78
+ if (typeof message !== "object" || message === null) {
79
+ return false;
80
+ }
81
+ const msg = message;
82
+ return (msg.jsonrpc === "2.0" &&
83
+ typeof msg.id === "string" &&
84
+ (msg.method === "elicitation/request" ||
85
+ msg.method === "elicitation/response" ||
86
+ msg.method === "elicitation/cancel") &&
87
+ typeof msg.params === "object" &&
88
+ msg.params !== null);
89
+ }
90
+ /**
91
+ * Convert protocol message to Elicitation type
92
+ */
93
+ export function protocolMessageToElicitation(message) {
94
+ const { type, message: displayMessage, toolName, serverId, timeout, optional, defaultValue, options, } = message.params;
95
+ const base = {
96
+ id: message.id,
97
+ type,
98
+ message: displayMessage,
99
+ toolName,
100
+ serverId,
101
+ timeout,
102
+ optional,
103
+ defaultValue,
104
+ };
105
+ // Add type-specific options
106
+ switch (type) {
107
+ case "confirmation":
108
+ return {
109
+ ...base,
110
+ type: "confirmation",
111
+ confirmLabel: options?.confirmLabel,
112
+ cancelLabel: options?.cancelLabel,
113
+ };
114
+ case "text":
115
+ return {
116
+ ...base,
117
+ type: "text",
118
+ placeholder: options?.placeholder,
119
+ minLength: options?.minLength,
120
+ maxLength: options?.maxLength,
121
+ pattern: options?.pattern,
122
+ multiline: options?.multiline,
123
+ };
124
+ case "select":
125
+ return {
126
+ ...base,
127
+ type: "select",
128
+ options: options?.options ?? [],
129
+ };
130
+ case "multiselect":
131
+ return {
132
+ ...base,
133
+ type: "multiselect",
134
+ options: options?.options ?? [],
135
+ minSelections: options?.minSelections,
136
+ maxSelections: options?.maxSelections,
137
+ };
138
+ case "form":
139
+ return {
140
+ ...base,
141
+ type: "form",
142
+ fields: options?.fields ?? [],
143
+ submitLabel: options?.submitLabel,
144
+ };
145
+ case "file":
146
+ return {
147
+ ...base,
148
+ type: "file",
149
+ accept: options?.accept,
150
+ multiple: options?.multiple,
151
+ maxSize: options?.maxSize,
152
+ };
153
+ case "secret":
154
+ return {
155
+ ...base,
156
+ type: "secret",
157
+ hint: options?.hint,
158
+ };
159
+ default:
160
+ return base;
161
+ }
162
+ }
163
+ /**
164
+ * Convert ElicitationResponse to protocol message
165
+ */
166
+ export function elicitationResponseToProtocol(response) {
167
+ return createElicitationResponse(response.requestId, {
168
+ responded: response.responded,
169
+ value: response.value,
170
+ cancelled: response.cancelled,
171
+ timedOut: response.timedOut,
172
+ error: response.error,
173
+ });
174
+ }
175
+ /**
176
+ * Elicitation Protocol Adapter
177
+ *
178
+ * Bridges protocol-level messages with the ElicitationManager
179
+ */
180
+ export class ElicitationProtocolAdapter {
181
+ manager;
182
+ config;
183
+ constructor(config = {}) {
184
+ this.manager = config.manager ?? globalElicitationManager;
185
+ this.config = {
186
+ manager: this.manager,
187
+ defaultTimeout: config.defaultTimeout ?? 60000,
188
+ enableLogging: config.enableLogging ?? false,
189
+ customHandler: config.customHandler,
190
+ };
191
+ }
192
+ /**
193
+ * Handle incoming protocol message
194
+ */
195
+ async handleMessage(message) {
196
+ if (this.config.enableLogging) {
197
+ logger.info("[ElicitationProtocol] Received:", message.method);
198
+ }
199
+ // Use custom handler if provided
200
+ if (this.config.customHandler) {
201
+ return await withTimeout(this.config.customHandler(message), this.config.defaultTimeout, `[ElicitationProtocol] Custom handler timed out after ${this.config.defaultTimeout}ms`);
202
+ }
203
+ switch (message.method) {
204
+ case "elicitation/request":
205
+ return this.handleRequest(message);
206
+ case "elicitation/response":
207
+ return this.handleResponse(message);
208
+ case "elicitation/cancel":
209
+ return this.handleCancel(message);
210
+ default:
211
+ if (this.config.enableLogging) {
212
+ logger.warn(`[ElicitationProtocol] Unhandled method: ${message.method}`);
213
+ }
214
+ return;
215
+ }
216
+ }
217
+ /**
218
+ * Handle elicitation request
219
+ */
220
+ async handleRequest(message) {
221
+ const elicitation = protocolMessageToElicitation(message);
222
+ // Use the manager to process the request
223
+ const response = await this.manager.request({
224
+ ...elicitation,
225
+ timeout: elicitation.timeout ?? this.config.defaultTimeout,
226
+ });
227
+ return elicitationResponseToProtocol(response);
228
+ }
229
+ /**
230
+ * Handle elicitation response (for external responses)
231
+ */
232
+ async handleResponse(_message) {
233
+ // Responses are typically handled by the manager internally
234
+ // This is for external systems sending responses
235
+ if (this.config.enableLogging) {
236
+ logger.info("[ElicitationProtocol] Response received (no action needed)");
237
+ }
238
+ }
239
+ /**
240
+ * Handle elicitation cancel
241
+ */
242
+ async handleCancel(message) {
243
+ this.manager.cancel(message.params.requestId, message.params.reason);
244
+ }
245
+ /**
246
+ * Send an elicitation request through the protocol
247
+ */
248
+ async requestElicitation(params) {
249
+ const message = createElicitationRequest(params);
250
+ const elicitation = protocolMessageToElicitation(message);
251
+ return this.manager.request({
252
+ ...elicitation,
253
+ timeout: elicitation.timeout ?? this.config.defaultTimeout,
254
+ });
255
+ }
256
+ /**
257
+ * Cancel a pending elicitation
258
+ */
259
+ cancelElicitation(requestId, reason) {
260
+ this.manager.cancel(requestId, reason);
261
+ }
262
+ /**
263
+ * Get the underlying manager
264
+ */
265
+ getManager() {
266
+ return this.manager;
267
+ }
268
+ /**
269
+ * Set protocol handler for the manager
270
+ */
271
+ setHandler(handler) {
272
+ this.manager.setHandler(handler);
273
+ }
274
+ /**
275
+ * Enable/disable the protocol
276
+ */
277
+ setEnabled(enabled) {
278
+ this.manager.setEnabled(enabled);
279
+ }
280
+ /**
281
+ * Check if protocol is enabled
282
+ */
283
+ isEnabled() {
284
+ return this.manager.isEnabled();
285
+ }
286
+ }
287
+ /**
288
+ * Create protocol-compliant confirmation request
289
+ */
290
+ export function createConfirmationRequest(message, options) {
291
+ const requestOptions = {};
292
+ if (options.confirmLabel !== undefined) {
293
+ requestOptions.confirmLabel = options.confirmLabel;
294
+ }
295
+ if (options.cancelLabel !== undefined) {
296
+ requestOptions.cancelLabel = options.cancelLabel;
297
+ }
298
+ return createElicitationRequest({
299
+ type: "confirmation",
300
+ message,
301
+ toolName: options.toolName,
302
+ serverId: options.serverId,
303
+ timeout: options.timeout,
304
+ options: requestOptions,
305
+ });
306
+ }
307
+ /**
308
+ * Create protocol-compliant text input request
309
+ */
310
+ export function createTextInputRequest(message, options) {
311
+ const requestOptions = {};
312
+ if (options.placeholder !== undefined) {
313
+ requestOptions.placeholder = options.placeholder;
314
+ }
315
+ if (options.minLength !== undefined) {
316
+ requestOptions.minLength = options.minLength;
317
+ }
318
+ if (options.maxLength !== undefined) {
319
+ requestOptions.maxLength = options.maxLength;
320
+ }
321
+ if (options.pattern !== undefined) {
322
+ requestOptions.pattern = options.pattern;
323
+ }
324
+ if (options.multiline !== undefined) {
325
+ requestOptions.multiline = options.multiline;
326
+ }
327
+ return createElicitationRequest({
328
+ type: "text",
329
+ message,
330
+ toolName: options.toolName,
331
+ serverId: options.serverId,
332
+ defaultValue: options.defaultValue,
333
+ timeout: options.timeout,
334
+ options: requestOptions,
335
+ });
336
+ }
337
+ /**
338
+ * Create protocol-compliant select request
339
+ */
340
+ export function createSelectRequest(message, selectOptions, options) {
341
+ return createElicitationRequest({
342
+ type: "select",
343
+ message,
344
+ toolName: options.toolName,
345
+ serverId: options.serverId,
346
+ defaultValue: options.defaultValue,
347
+ timeout: options.timeout,
348
+ options: {
349
+ options: selectOptions,
350
+ },
351
+ });
352
+ }
353
+ /**
354
+ * Create protocol-compliant form request
355
+ */
356
+ export function createFormRequest(message, fields, options) {
357
+ const requestOptions = {
358
+ fields: fields,
359
+ };
360
+ if (options.submitLabel !== undefined) {
361
+ requestOptions.submitLabel = options.submitLabel;
362
+ }
363
+ return createElicitationRequest({
364
+ type: "form",
365
+ message,
366
+ toolName: options.toolName,
367
+ serverId: options.serverId,
368
+ timeout: options.timeout,
369
+ options: requestOptions,
370
+ });
371
+ }
372
+ /**
373
+ * Global protocol adapter instance
374
+ */
375
+ export const globalElicitationProtocol = new ElicitationProtocolAdapter();
376
+ //# sourceMappingURL=elicitationProtocol.js.map