@opentiny/next-sdk 0.4.1 → 0.4.3

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 (90) hide show
  1. package/dist/{SimulatorMask-BHVXyogh-iNUb4dyF.js → SimulatorMask-BHVXyogh-CKmEDsYG.js} +1 -1
  2. package/dist/core.js +1 -1
  3. package/dist/{index-CXK8CcKq.js → index-CHMa2zG4.js} +1985 -1434
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.js +69 -50
  6. package/dist/{initialize-builtin-WebMCP-rALfqS-o.js → initialize-builtin-WebMCP-JaoKwVlm.js} +355 -346
  7. package/dist/page-tools/a11y/build.d.ts +3 -4
  8. package/dist/page-tools/a11y/config.d.ts +99 -0
  9. package/dist/page-tools/a11y/constants.d.ts +22 -0
  10. package/dist/page-tools/a11y/search.d.ts +1 -1
  11. package/dist/page-tools/a11y/types.d.ts +13 -22
  12. package/dist/page-tools/a11y/utils.d.ts +46 -11
  13. package/dist/page-tools/a11y/vnode.d.ts +14 -11
  14. package/dist/page-tools/a11y-tree.d.ts +1 -0
  15. package/dist/page-tools/configs/console-cloud.d.ts +6 -0
  16. package/dist/page-tools/constants.d.ts +7 -17
  17. package/dist/page-tools/context.d.ts +14 -0
  18. package/dist/page-tools/handlers/hover.d.ts +9 -0
  19. package/dist/page-tools/handlers/searchTree.d.ts +2 -1
  20. package/dist/page-tools/page-agent-highlight/index.d.ts +12 -0
  21. package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +2 -0
  22. package/dist/page-tools/page-agent-tool-event.d.ts +26 -0
  23. package/dist/page-tools/schema.d.ts +4 -3
  24. package/dist/page-tools/tool-config.d.ts +50 -0
  25. package/dist/page-tools/utils/dom.d.ts +8 -2
  26. package/dist/runtime.d.ts +4 -1
  27. package/dist/runtime.js +22 -187
  28. package/dist/vitest.config.d.ts +2 -0
  29. package/package.json +26 -16
  30. package/WebMcpClient.ts +0 -505
  31. package/WebMcpServer.ts +0 -447
  32. package/agent/AgentModelProvider.ts +0 -932
  33. package/agent/type.ts +0 -91
  34. package/agent/utils/generateReActPrompt.ts +0 -71
  35. package/agent/utils/getAISDKTools.ts +0 -34
  36. package/agent/utils/getBuiltinMcpTools.ts +0 -86
  37. package/agent/utils/parseReActAction.ts +0 -34
  38. package/core.ts +0 -26
  39. package/index.ts +0 -56
  40. package/page-tools/a11y/build.ts +0 -70
  41. package/page-tools/a11y/constants.ts +0 -110
  42. package/page-tools/a11y/search.ts +0 -129
  43. package/page-tools/a11y/types.ts +0 -108
  44. package/page-tools/a11y/utils.ts +0 -266
  45. package/page-tools/a11y/vnode.ts +0 -229
  46. package/page-tools/a11y-tree.ts +0 -13
  47. package/page-tools/bridge.ts +0 -702
  48. package/page-tools/constants.ts +0 -72
  49. package/page-tools/context.ts +0 -13
  50. package/page-tools/effects.ts +0 -345
  51. package/page-tools/handlers/browserState.ts +0 -12
  52. package/page-tools/handlers/click.ts +0 -26
  53. package/page-tools/handlers/executeJavascript.ts +0 -22
  54. package/page-tools/handlers/fill.ts +0 -60
  55. package/page-tools/handlers/scroll.ts +0 -66
  56. package/page-tools/handlers/searchTree.ts +0 -30
  57. package/page-tools/handlers/select.ts +0 -34
  58. package/page-tools/initialize-builtin-WebMCP.ts +0 -20
  59. package/page-tools/page-agent-highlight/index.ts +0 -198
  60. package/page-tools/page-agent-mask/SimulatorMask.module.css +0 -14
  61. package/page-tools/page-agent-mask/SimulatorMask.ts +0 -279
  62. package/page-tools/page-agent-mask/checkDarkMode.ts +0 -181
  63. package/page-tools/page-agent-mask/cursor-border.svg +0 -3
  64. package/page-tools/page-agent-mask/cursor-fill.svg +0 -5
  65. package/page-tools/page-agent-mask/cursor.module.css +0 -70
  66. package/page-tools/page-agent-prompt.md +0 -139
  67. package/page-tools/page-agent-tool.ts +0 -175
  68. package/page-tools/page-state-cache.ts +0 -78
  69. package/page-tools/schema.ts +0 -51
  70. package/page-tools/utils/dom.ts +0 -155
  71. package/page-tools/utils/scroll.ts +0 -58
  72. package/remoter/QrCode.ts +0 -54
  73. package/remoter/createRemoter.ts +0 -957
  74. package/remoter/svgs/chat.svg +0 -43
  75. package/remoter/svgs/icon-copy.svg +0 -25
  76. package/remoter/svgs/link.svg +0 -28
  77. package/remoter/svgs/logo.svg +0 -45
  78. package/remoter/svgs/qrcode.svg +0 -35
  79. package/remoter/svgs/scan.svg +0 -21
  80. package/remoter/tooltips.ts +0 -260
  81. package/runtime.html +0 -39
  82. package/runtime.ts +0 -13
  83. package/script/utils.ts +0 -26
  84. package/skills/index.ts +0 -287
  85. package/tsconfig.json +0 -16
  86. package/utils/builtinProxy.ts +0 -144
  87. package/utils/env.ts +0 -13
  88. package/utils/uuid.ts +0 -10
  89. package/vite.config.runtime.ts +0 -22
  90. package/vite.config.ts +0 -63
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vite').UserConfig;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentiny/next-sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "type": "module",
5
5
  "homepage": "https://docs.opentiny.design/next-sdk/guide/",
6
6
  "repository": {
@@ -17,6 +17,11 @@
17
17
  "sdk",
18
18
  "agent"
19
19
  ],
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
20
25
  "license": "MIT",
21
26
  "author": "Chunhui Mo",
22
27
  "main": "dist/index.js",
@@ -34,38 +39,43 @@
34
39
  },
35
40
  "description": "A frontend intelligent application development toolkit designed to simplify WebAgent integration and usage, supporting multiple programming languages and frontend frameworks to help developers rapidly implement intelligent features",
36
41
  "dependencies": {
37
- "@modelcontextprotocol/sdk": "~1.25.2",
38
- "@opentiny/next": "^0.3.2",
39
- "@ai-sdk/openai": "^3.0.0",
40
42
  "@ai-sdk/deepseek": "1.0.30",
41
- "@ai-sdk/provider": "^3.0.0",
42
43
  "@ai-sdk/mcp": "^1.0.0",
44
+ "@ai-sdk/openai": "^3.0.0",
45
+ "@ai-sdk/provider": "^3.0.0",
43
46
  "@mcp-b/webmcp-polyfill": "^3.0.0",
47
+ "@modelcontextprotocol/sdk": "~1.25.2",
48
+ "@opentiny/next": "^0.3.2",
44
49
  "@page-agent/page-controller": "^1.10.0",
45
- "qrcode": "^1.5.4",
46
- "zod": "^3.25.76",
47
- "zod-to-json-schema": "^3.25.2",
48
- "ajv": "^8.17.1",
49
50
  "ai": "^6.0.0",
50
- "dom-accessibility-api": "^0.6.3",
51
+ "ai-motion": "^0.4.8",
52
+ "ajv": "^8.17.1",
51
53
  "aria-query": "^5.3.2",
52
- "tabbable": "^6.2.0",
53
54
  "diff": "^7.0.0",
54
- "ai-motion": "^0.4.8"
55
+ "dom-accessibility-api": "^0.6.3",
56
+ "qrcode": "^1.5.4",
57
+ "tabbable": "^6.2.0",
58
+ "zod": "^3.25.76",
59
+ "zod-to-json-schema": "^3.25.2"
55
60
  },
56
61
  "devDependencies": {
62
+ "@types/diff": "^7.0.0",
63
+ "@types/node": "^24.6.0",
64
+ "@types/qrcode": "^1.5.5",
65
+ "@vitest/ui": "^4.1.10",
66
+ "jsdom": "^29.1.1",
57
67
  "typescript": "~5.9.3",
58
68
  "vite": "^7.1.7",
59
69
  "vite-plugin-dts": "^3.9.1",
60
- "@types/qrcode": "^1.5.5",
61
- "@types/node": "^24.6.0",
62
- "@types/diff": "^7.0.0"
70
+ "vitest": "^4.1.10"
63
71
  },
64
72
  "publishConfig": {
65
73
  "access": "public"
66
74
  },
67
75
  "scripts": {
68
76
  "build": "vite build && vite build --config vite.config.runtime.ts",
69
- "build:runtime": "vite build --config vite.config.runtime.ts"
77
+ "build:runtime": "vite build --config vite.config.runtime.ts",
78
+ "test": "vitest run",
79
+ "test:watch": "vitest"
70
80
  }
71
81
  }
package/WebMcpClient.ts DELETED
@@ -1,505 +0,0 @@
1
- import { Client } from '@modelcontextprotocol/sdk/client/index.js'
2
- import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
3
- import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
4
- import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js'
5
- import { z, ZodObject, ZodLiteral, ZodType } from 'zod'
6
- import {
7
- ElicitRequestSchema,
8
- CallToolResultSchema,
9
- ListRootsRequestSchema,
10
- CreateMessageRequestSchema,
11
- LoggingMessageNotificationSchema,
12
- ToolListChangedNotificationSchema,
13
- ResourceUpdatedNotificationSchema,
14
- PromptListChangedNotificationSchema,
15
- ResourceListChangedNotificationSchema
16
- } from '@modelcontextprotocol/sdk/types.js'
17
- import {
18
- MessageChannelClientTransport,
19
- sseOptions,
20
- streamOptions,
21
- createSseProxy,
22
- createStreamProxy,
23
- createSocketProxy
24
- } from '@opentiny/next'
25
- import { setupBuiltinProxy } from './utils/builtinProxy'
26
- import type {
27
- Result,
28
- Request,
29
- Notification,
30
- Implementation,
31
- ServerCapabilities,
32
- ClientCapabilities,
33
- LoggingLevel,
34
- CompleteRequest,
35
- CallToolRequest,
36
- ListToolsRequest,
37
- GetPromptRequest,
38
- SubscribeRequest,
39
- UnsubscribeRequest,
40
- ListPromptsRequest,
41
- ReadResourceRequest,
42
- ListResourcesRequest,
43
- ListResourceTemplatesRequest,
44
- ElicitRequest,
45
- CreateMessageRequest,
46
- ListRootsRequest,
47
- ToolListChangedNotification,
48
- PromptListChangedNotification,
49
- ResourceListChangedNotification,
50
- ResourceUpdatedNotification,
51
- LoggingMessageNotification
52
- } from '@modelcontextprotocol/sdk/types.js'
53
- import type { ProxyOptions } from '@opentiny/next'
54
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'
55
- import type { ClientOptions } from '@modelcontextprotocol/sdk/client/index.js'
56
- import type { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js'
57
- import type { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
58
- import type {
59
- RequestOptions,
60
- NotificationOptions,
61
- RequestHandlerExtra
62
- } from '@modelcontextprotocol/sdk/shared/protocol.js'
63
-
64
- /**
65
- * Options for configuring the server transport.
66
- */
67
- export interface ClientConnectOptions {
68
- url: string
69
- token?: string
70
- sessionId?: string
71
- type?: 'channel' | 'sse' | 'stream' | 'socket'
72
- agent?: boolean
73
- builtin?: boolean
74
- onError?: (error: Error) => void
75
- }
76
-
77
- type SendRequestT = Request
78
- type SendNotificationT = Notification
79
- type SendResultT = Result
80
-
81
- /**
82
- * An MCP client on top of a pluggable transport.
83
- * The client will automatically begin the initialization flow with the server when connect() is called.
84
- */
85
- export class WebMcpClient {
86
- public readonly client: Client
87
- public transport: Transport | undefined
88
-
89
- constructor(clientInfo?: Implementation, options?: ClientOptions) {
90
- const info: Implementation = {
91
- name: 'web-mcp-client',
92
- version: '1.0.0'
93
- }
94
-
95
- const capabilities: ClientCapabilities = {
96
- roots: { listChanged: true },
97
- sampling: {},
98
- elicitation: {}
99
- }
100
-
101
- this.client = new Client(clientInfo || info, options || { capabilities })
102
-
103
- this.client.onclose = () => {
104
- this.onclose?.()
105
- }
106
-
107
- this.client.onerror = (error: Error) => {
108
- this.onerror?.(error)
109
- }
110
- }
111
-
112
- /**
113
- * Connects the client to a transport via the specified option.
114
- */
115
- async connect(options: Transport | ClientConnectOptions): Promise<{ transport: Transport; sessionId: string }> {
116
- // 1. 直连一个Transport时
117
- if (typeof (options as Transport)['start'] === 'function') {
118
- this.transport = options as Transport
119
- this.transport.onclose = undefined
120
- this.transport.onerror = undefined
121
- this.transport.onmessage = undefined
122
- await this.client.connect(this.transport)
123
- return { transport: this.transport, sessionId: this.transport.sessionId as string }
124
- }
125
-
126
- const { url, token, sessionId, type, agent, builtin, onError } = options as ClientConnectOptions
127
-
128
- if (agent) {
129
- const proxyOptions: ProxyOptions = { client: this.client, url, token, sessionId }
130
-
131
- const response: { transport: Transport; sessionId: string } =
132
- type === 'sse'
133
- ? await createSseProxy(proxyOptions)
134
- : type === 'socket'
135
- ? await createSocketProxy(proxyOptions)
136
- : await createStreamProxy(proxyOptions)
137
-
138
- response.transport.onerror = async (error: Error) => {
139
- onError?.(error)
140
- }
141
-
142
- if (builtin) {
143
- setupBuiltinProxy(response.transport)
144
- }
145
-
146
- return response
147
- }
148
-
149
- // 3. 非代理,通过 URL 连接时
150
- const endpoint = new URL(url)
151
- let transport: Transport | undefined
152
-
153
- if (type === 'channel') {
154
- transport = new MessageChannelClientTransport(url)
155
- await this.client.connect(transport)
156
- }
157
-
158
- if (type === 'sse') {
159
- const opts = sseOptions(token, sessionId) as SSEClientTransportOptions
160
- transport = new SSEClientTransport(endpoint, opts)
161
- await this.client.connect(transport)
162
- }
163
-
164
- if (type === 'socket') {
165
- transport = new WebSocketClientTransport(new URL(`${url}?sessionId=${sessionId}&token=${token}`))
166
- transport.sessionId = sessionId
167
- await this.client.connect(transport)
168
- }
169
-
170
- if (type === 'stream' || typeof transport === 'undefined') {
171
- const opts = streamOptions(token, sessionId) as StreamableHTTPClientTransportOptions
172
- transport = new StreamableHTTPClientTransport(endpoint, opts)
173
- await this.client.connect(transport)
174
- }
175
-
176
- this.transport = transport
177
- return { transport: this.transport, sessionId: this.transport.sessionId as string }
178
- }
179
-
180
- /**
181
- * Callback for when the connection is closed for any reason.
182
- *
183
- * This is invoked when close() is called as well.
184
- */
185
- onclose?: () => void
186
-
187
- /**
188
- * Callback for when an error occurs.
189
- *
190
- * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
191
- */
192
- onerror?: (error: Error) => void
193
-
194
- /**
195
- * Closes the connection.
196
- */
197
- async close(): Promise<void> {
198
- await this.client.close()
199
- }
200
-
201
- /**
202
- * After initialization has completed, this will be populated with the server's reported capabilities.
203
- */
204
- getServerCapabilities(): ServerCapabilities | undefined {
205
- return this.client.getServerCapabilities()
206
- }
207
-
208
- /**
209
- * After initialization has completed, this will be populated with information about the server's name and version.
210
- */
211
- getServerVersion(): Implementation | undefined {
212
- return this.client.getServerVersion()
213
- }
214
-
215
- /**
216
- * After initialization has completed, this may be populated with information about the server's instructions.
217
- */
218
- getInstructions(): string | undefined {
219
- return this.client.getInstructions()
220
- }
221
-
222
- /**
223
- * Sends a ping to the server to check if it is still connected.
224
- */
225
- async ping(options?: RequestOptions) {
226
- return await this.client.ping(options)
227
- }
228
-
229
- /**
230
- * Sends a completion request to the server.
231
- */
232
- async complete(params: CompleteRequest['params'], options?: RequestOptions) {
233
- return await this.client.complete(params, options)
234
- }
235
-
236
- /**
237
- * Sends a request for setting the logging level to the server.
238
- */
239
- async setLoggingLevel(level: LoggingLevel, options?: RequestOptions) {
240
- return await this.client.setLoggingLevel(level, options)
241
- }
242
-
243
- /**
244
- * Gets the prompt with the given params from the server.
245
- */
246
- async getPrompt(params: GetPromptRequest['params'], options?: RequestOptions) {
247
- return await this.client.getPrompt(params, options)
248
- }
249
-
250
- /**
251
- * Lists all prompts available on the server.
252
- */
253
- async listPrompts(params?: ListPromptsRequest['params'], options?: RequestOptions) {
254
- return await this.client.listPrompts(params, options)
255
- }
256
-
257
- /**
258
- * Lists all resources available on the server.
259
- */
260
- async listResources(params?: ListResourcesRequest['params'], options?: RequestOptions) {
261
- return await this.client.listResources(params, options)
262
- }
263
-
264
- /**
265
- * Lists all resource templates available on the server.
266
- */
267
- async listResourceTemplates(params?: ListResourceTemplatesRequest['params'], options?: RequestOptions) {
268
- return await this.client.listResourceTemplates(params, options)
269
- }
270
-
271
- /**
272
- * Reads the resource with the given params from the server.
273
- */
274
- async readResource(params: ReadResourceRequest['params'], options?: RequestOptions) {
275
- return await this.client.readResource(params, options)
276
- }
277
-
278
- /**
279
- * Subscribes to a resource on the server.
280
- */
281
- async subscribeResource(params: SubscribeRequest['params'], options?: RequestOptions) {
282
- return await this.client.subscribeResource(params, options)
283
- }
284
-
285
- /**
286
- * Unsubscribes from a resource on the server.
287
- */
288
- async unsubscribeResource(params: UnsubscribeRequest['params'], options?: RequestOptions) {
289
- return await this.client.unsubscribeResource(params, options)
290
- }
291
-
292
- /**
293
- * Calls a tool on the server with the given parameters.
294
- */
295
- async callTool(params: CallToolRequest['params'], options?: RequestOptions) {
296
- return await this.client.callTool(params, CallToolResultSchema, options)
297
- }
298
-
299
- /**
300
- * Lists all tools available on the server.
301
- */
302
- async listTools(params?: ListToolsRequest['params'], options?: RequestOptions) {
303
- return await this.client.listTools(params, options)
304
- }
305
-
306
- /**
307
- * Sends a notification for the roots list changed event to the server.
308
- */
309
- async sendRootsListChanged() {
310
- return await this.client.sendRootsListChanged()
311
- }
312
-
313
- /**
314
- * Sends a request and wait for a response.
315
- *
316
- * Do not use this method to emit notifications! Use notification() instead.
317
- */
318
- request<T extends ZodType<object>>(
319
- request: SendRequestT,
320
- resultSchema: T,
321
- options?: RequestOptions
322
- ): Promise<z.infer<T>> {
323
- return this.client.request(request, resultSchema, options)
324
- }
325
-
326
- /**
327
- * Emits a notification, which is a one-way message that does not expect a response.
328
- */
329
- async notification(notification: SendNotificationT, options?: NotificationOptions): Promise<void> {
330
- return await this.client.notification(notification, options)
331
- }
332
-
333
- /**
334
- * Registers a handler to invoke when this protocol object receives a request with the given method.
335
- *
336
- * Note that this will replace any previous request handler for the same method.
337
- */
338
- setRequestHandler<
339
- T extends ZodObject<{
340
- method: ZodLiteral<string>
341
- }>
342
- >(
343
- requestSchema: T,
344
- handler: (
345
- request: z.infer<T>,
346
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
347
- ) => SendResultT | Promise<SendResultT>
348
- ): void {
349
- this.client.setRequestHandler(requestSchema, handler)
350
- }
351
-
352
- /**
353
- * Removes the request handler for the given method.
354
- */
355
- removeRequestHandler(method: string): void {
356
- this.client.removeRequestHandler(method)
357
- }
358
-
359
- /**
360
- * Registers a handler to invoke when this protocol object receives a notification with the given method.
361
- *
362
- * Note that this will replace any previous notification handler for the same method.
363
- */
364
- setNotificationHandler<
365
- T extends ZodObject<{
366
- method: ZodLiteral<string>
367
- }>
368
- >(notificationSchema: T, handler: (notification: z.infer<T>) => void | Promise<void>): void {
369
- this.client.setNotificationHandler(notificationSchema, handler)
370
- }
371
-
372
- /**
373
- * Removes the notification handler for the given method.
374
- */
375
- removeNotificationHandler(method: string): void {
376
- this.client.removeNotificationHandler(method)
377
- }
378
-
379
- /**
380
- * Registers a handler for the elicitation request.
381
- */
382
- onElicit(
383
- handler: (
384
- request: ElicitRequest,
385
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
386
- ) => SendResultT | Promise<SendResultT>
387
- ): void {
388
- this.client.setRequestHandler(ElicitRequestSchema, handler)
389
- }
390
-
391
- /**
392
- * Registers a handler for the create LLM message request.
393
- */
394
- onCreateMessage(
395
- handler: (
396
- request: CreateMessageRequest,
397
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
398
- ) => SendResultT | Promise<SendResultT>
399
- ): void {
400
- this.client.setRequestHandler(CreateMessageRequestSchema, handler)
401
- }
402
-
403
- /**
404
- * Registers a handler for the list roots request.
405
- */
406
- onListRoots(
407
- handler: (
408
- request: ListRootsRequest,
409
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
410
- ) => SendResultT | Promise<SendResultT>
411
- ): void {
412
- this.client.setRequestHandler(ListRootsRequestSchema, handler)
413
- }
414
-
415
- /**
416
- * Registers a handler for the tool list changed notification.
417
- */
418
- onToolListChanged(handler: (notification: ToolListChangedNotification) => void | Promise<void>): void {
419
- this.client.setNotificationHandler(ToolListChangedNotificationSchema, handler)
420
- }
421
-
422
- /**
423
- * Registers a handler for the prompt list changed notification.
424
- */
425
- onPromptListChanged(handler: (notification: PromptListChangedNotification) => void | Promise<void>): void {
426
- this.client.setNotificationHandler(PromptListChangedNotificationSchema, handler)
427
- }
428
-
429
- /**
430
- * Registers a handler for the resource list changed notification.
431
- */
432
- onResourceListChanged(handler: (notification: ResourceListChangedNotification) => void | Promise<void>): void {
433
- this.client.setNotificationHandler(ResourceListChangedNotificationSchema, handler)
434
- }
435
-
436
- /**
437
- * Registers a handler for the resource updated notification.
438
- */
439
- onResourceUpdated(handler: (notification: ResourceUpdatedNotification) => void | Promise<void>): void {
440
- this.client.setNotificationHandler(ResourceUpdatedNotificationSchema, handler)
441
- }
442
-
443
- /**
444
- * Registers a handler for the logging message notification.
445
- */
446
- onLoggingMessage(handler: (notification: LoggingMessageNotification) => void | Promise<void>): void {
447
- this.client.setNotificationHandler(LoggingMessageNotificationSchema, handler)
448
- }
449
-
450
- /**
451
- * Close the transport for window.addEventListener('pagehide')
452
- */
453
- async onPagehide(event: PageTransitionEvent) {
454
- if (event.persisted) {
455
- return
456
- }
457
-
458
- if (isStreamableHTTPClientTransport(this.transport)) {
459
- await this.transport.terminateSession()
460
- } else if (this.transport && typeof this.transport['close'] === 'function') {
461
- await this.transport.close()
462
- }
463
- }
464
- }
465
-
466
- /**
467
- * Creates a new SSEClientTransport instance.
468
- */
469
- export const createSSEClientTransport = (url: URL, opts?: SSEClientTransportOptions) =>
470
- new SSEClientTransport(url, opts)
471
-
472
- /**
473
- * Creates a new StreamableHTTPClientTransport instance.
474
- */
475
- export const createStreamableHTTPClientTransport = (url: URL, opts?: StreamableHTTPClientTransportOptions) =>
476
- new StreamableHTTPClientTransport(url, opts)
477
-
478
- /**
479
- * Creates a new MessageChannelClientTransport instance.
480
- */
481
- export const createMessageChannelClientTransport = (endpoint: string, globalObject?: object) =>
482
- new MessageChannelClientTransport(endpoint, globalObject)
483
-
484
- /**
485
- * Checks if the transport is a SSEClientTransport.
486
- */
487
- export const isSSEClientTransport = (transport: unknown): transport is SSEClientTransport =>
488
- transport instanceof SSEClientTransport
489
-
490
- /**
491
- * Checks if the transport is a StreamableHTTPClientTransport.
492
- */
493
- export const isStreamableHTTPClientTransport = (transport: unknown): transport is StreamableHTTPClientTransport =>
494
- transport instanceof StreamableHTTPClientTransport
495
-
496
- /**
497
- * Checks if the transport is a MessageChannelClientTransport.
498
- */
499
- export const isMessageChannelClientTransport = (transport: unknown): transport is MessageChannelClientTransport =>
500
- transport instanceof MessageChannelClientTransport
501
-
502
- /**
503
- * Checks if the client is an instance of MCP Client.
504
- */
505
- export const isMcpClient = (client: unknown): client is Client => client instanceof Client