@opentiny/next-sdk 0.4.2 → 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 (88) hide show
  1. package/dist/{SimulatorMask-BHVXyogh-CARX3Rff.js → SimulatorMask-BHVXyogh-CKmEDsYG.js} +1 -1
  2. package/dist/{index-R_HIbfUX.js → index-CHMa2zG4.js} +1065 -1042
  3. package/dist/index.js +1 -1
  4. package/dist/page-tools/a11y/config.d.ts +6 -3
  5. package/dist/page-tools/a11y/constants.d.ts +20 -0
  6. package/dist/page-tools/a11y/utils.d.ts +14 -0
  7. package/dist/page-tools/constants.d.ts +4 -2
  8. package/dist/page-tools/context.d.ts +2 -0
  9. package/dist/page-tools/handlers/hover.d.ts +9 -0
  10. package/dist/page-tools/schema.d.ts +3 -3
  11. package/dist/page-tools/utils/dom.d.ts +8 -2
  12. package/dist/runtime.js +19 -172
  13. package/package.json +6 -1
  14. package/WebMcpClient.ts +0 -505
  15. package/WebMcpServer.ts +0 -447
  16. package/agent/AgentModelProvider.ts +0 -932
  17. package/agent/type.ts +0 -91
  18. package/agent/utils/generateReActPrompt.ts +0 -71
  19. package/agent/utils/getAISDKTools.ts +0 -34
  20. package/agent/utils/getBuiltinMcpTools.ts +0 -86
  21. package/agent/utils/parseReActAction.ts +0 -34
  22. package/core.ts +0 -26
  23. package/index.ts +0 -91
  24. package/page-tools/a11y/build.ts +0 -74
  25. package/page-tools/a11y/config.ts +0 -465
  26. package/page-tools/a11y/constants.ts +0 -131
  27. package/page-tools/a11y/search.ts +0 -127
  28. package/page-tools/a11y/types.ts +0 -105
  29. package/page-tools/a11y/utils.ts +0 -239
  30. package/page-tools/a11y/vnode.ts +0 -439
  31. package/page-tools/a11y-tree.ts +0 -14
  32. package/page-tools/bridge.ts +0 -722
  33. package/page-tools/configs/console-cloud.ts +0 -172
  34. package/page-tools/constants.ts +0 -12
  35. package/page-tools/context.ts +0 -50
  36. package/page-tools/effects.ts +0 -345
  37. package/page-tools/handlers/browserState.ts +0 -12
  38. package/page-tools/handlers/click.ts +0 -30
  39. package/page-tools/handlers/executeJavascript.ts +0 -22
  40. package/page-tools/handlers/fill.ts +0 -65
  41. package/page-tools/handlers/scroll.ts +0 -66
  42. package/page-tools/handlers/searchTree.ts +0 -27
  43. package/page-tools/handlers/select.ts +0 -39
  44. package/page-tools/initialize-builtin-WebMCP.ts +0 -20
  45. package/page-tools/page-agent-highlight/index.ts +0 -245
  46. package/page-tools/page-agent-mask/SimulatorMask.module.css +0 -14
  47. package/page-tools/page-agent-mask/SimulatorMask.ts +0 -299
  48. package/page-tools/page-agent-mask/checkDarkMode.ts +0 -181
  49. package/page-tools/page-agent-mask/cursor-border.svg +0 -3
  50. package/page-tools/page-agent-mask/cursor-fill.svg +0 -5
  51. package/page-tools/page-agent-mask/cursor.module.css +0 -70
  52. package/page-tools/page-agent-mask/hauwei.svg +0 -25
  53. package/page-tools/page-agent-prompt.md +0 -139
  54. package/page-tools/page-agent-tool-event.ts +0 -113
  55. package/page-tools/page-agent-tool.ts +0 -207
  56. package/page-tools/page-state-cache.ts +0 -78
  57. package/page-tools/schema.ts +0 -52
  58. package/page-tools/tool-config.ts +0 -100
  59. package/page-tools/utils/dom.ts +0 -158
  60. package/page-tools/utils/scroll.ts +0 -58
  61. package/remoter/QrCode.ts +0 -54
  62. package/remoter/createRemoter.ts +0 -957
  63. package/remoter/svgs/chat.svg +0 -43
  64. package/remoter/svgs/icon-copy.svg +0 -25
  65. package/remoter/svgs/link.svg +0 -28
  66. package/remoter/svgs/logo.svg +0 -45
  67. package/remoter/svgs/qrcode.svg +0 -35
  68. package/remoter/svgs/scan.svg +0 -21
  69. package/remoter/tooltips.ts +0 -260
  70. package/runtime.html +0 -39
  71. package/runtime.ts +0 -44
  72. package/script/utils.ts +0 -26
  73. package/skills/index.ts +0 -287
  74. package/test/page-tools/a11y/build.test.ts +0 -638
  75. package/test/page-tools/a11y/config.test.ts +0 -370
  76. package/test/page-tools/configs/console-cloud.test.ts +0 -168
  77. package/test/page-tools/page-agent-highlight.test.ts +0 -110
  78. package/test/page-tools/page-agent-tool-dispatch.test.ts +0 -208
  79. package/test/page-tools/page-agent-tool.test.ts +0 -102
  80. package/test/page-tools/tool-config.test.ts +0 -112
  81. package/test/page-tools/utils/dom.test.ts +0 -122
  82. package/tsconfig.json +0 -16
  83. package/utils/builtinProxy.ts +0 -144
  84. package/utils/env.ts +0 -13
  85. package/utils/uuid.ts +0 -10
  86. package/vite.config.runtime.ts +0 -22
  87. package/vite.config.ts +0 -63
  88. package/vitest.config.ts +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentiny/next-sdk",
3
- "version": "0.4.2",
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",
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