@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/WebMcpServer.ts DELETED
@@ -1,447 +0,0 @@
1
- import { MessageChannelServerTransport, createTransportPair } from '@opentiny/next'
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
3
- import { z, ZodObject, ZodLiteral, ZodType, ZodOptional } from 'zod'
4
- import {
5
- SetLevelRequestSchema,
6
- SubscribeRequestSchema,
7
- UnsubscribeRequestSchema,
8
- ListResourcesRequestSchema,
9
- RootsListChangedNotificationSchema
10
- } from '@modelcontextprotocol/sdk/types.js'
11
- import type {
12
- ToolCallback,
13
- RegisteredTool,
14
- PromptCallback,
15
- RegisteredPrompt,
16
- ResourceMetadata,
17
- ResourceTemplate,
18
- RegisteredResource,
19
- ReadResourceCallback,
20
- RegisteredResourceTemplate,
21
- ReadResourceTemplateCallback
22
- } from '@modelcontextprotocol/sdk/server/mcp.js'
23
- import type {
24
- Result,
25
- Request,
26
- Notification,
27
- Implementation,
28
- ToolAnnotations,
29
- ServerCapabilities,
30
- ClientCapabilities,
31
- ElicitResult,
32
- ElicitRequest,
33
- ListRootsRequest,
34
- CreateMessageRequest,
35
- LoggingMessageNotification,
36
- ResourceUpdatedNotification,
37
- SubscribeRequest,
38
- UnsubscribeRequest,
39
- SetLevelRequest,
40
- ListResourcesRequest,
41
- RootsListChangedNotification
42
- } from '@modelcontextprotocol/sdk/types.js'
43
- import type { ZodRawShape, ZodTypeDef } from 'zod'
44
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'
45
- import type { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js'
46
- import type {
47
- RequestOptions,
48
- NotificationOptions,
49
- RequestHandlerExtra
50
- } from '@modelcontextprotocol/sdk/shared/protocol.js'
51
-
52
- type PromptArgsRawShape = {
53
- [k: string]: ZodType<string, ZodTypeDef, string> | ZodOptional<ZodType<string, ZodTypeDef, string>>
54
- }
55
-
56
- type SendRequestT = Request
57
- type SendNotificationT = Notification
58
- type SendResultT = Result
59
-
60
- /**
61
- * High-level Web MCP server that provides a simpler API for working with resources, tools, and prompts.
62
- * For advanced usage (like sending notifications or setting custom request handlers), use the underlying
63
- * Server instance available via the `server` property.
64
- */
65
- export class WebMcpServer {
66
- public readonly server: McpServer
67
- public transport: Transport | undefined
68
-
69
- constructor(serverInfo?: Implementation, options?: ServerOptions) {
70
- const info: Implementation = {
71
- name: 'web-mcp-server',
72
- version: '1.0.0'
73
- }
74
-
75
- const capabilities: ServerCapabilities = {
76
- prompts: { listChanged: true },
77
- resources: { subscribe: true, listChanged: true },
78
- tools: { listChanged: true },
79
- completions: {},
80
- logging: {}
81
- }
82
-
83
- this.server = new McpServer(serverInfo || info, options || { capabilities })
84
-
85
- this.server.server.oninitialized = () => {
86
- this.oninitialized?.()
87
- }
88
-
89
- this.server.server.onclose = () => {
90
- this.onclose?.()
91
- }
92
-
93
- this.server.server.onerror = (error: Error) => {
94
- this.onerror?.(error)
95
- }
96
-
97
- this.server.server.setRequestHandler(SetLevelRequestSchema, async () => {
98
- return {}
99
- })
100
- }
101
-
102
- /**
103
- * Connects the server to a transport via the specified option.
104
- */
105
- async connect(options: Transport | string): Promise<Transport> {
106
- if (typeof (options as Transport)['start'] === 'function') {
107
- this.transport = options as Transport
108
- this.transport.onclose = undefined
109
- this.transport.onerror = undefined
110
- this.transport.onmessage = undefined
111
- } else {
112
- this.transport = new MessageChannelServerTransport(options as string)
113
- await (this.transport as MessageChannelServerTransport).listen()
114
- }
115
-
116
- await this.server.connect(this.transport)
117
- return this.transport
118
- }
119
-
120
- /**
121
- * Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification).
122
- */
123
- oninitialized?: () => void
124
-
125
- /**
126
- * Callback for when the connection is closed for any reason.
127
- *
128
- * This is invoked when close() is called as well.
129
- */
130
- onclose?: () => void
131
-
132
- /**
133
- * Callback for when an error occurs.
134
- *
135
- * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
136
- */
137
- onerror?: (error: Error) => void
138
-
139
- /**
140
- * Closes the connection.
141
- */
142
- async close(): Promise<void> {
143
- await this.server.close()
144
- }
145
-
146
- /**
147
- * Registers a tool with a config object and callback.
148
- */
149
- registerTool<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape>(
150
- name: string,
151
- config: {
152
- title?: string
153
- description?: string
154
- inputSchema?: InputArgs
155
- outputSchema?: OutputArgs
156
- annotations?: ToolAnnotations
157
- },
158
- cb: ToolCallback<InputArgs>
159
- ): RegisteredTool {
160
- return this.server.registerTool(name, config, cb)
161
- }
162
-
163
- /**
164
- * Registers a prompt with a config object and callback.
165
- */
166
- registerPrompt<Args extends PromptArgsRawShape>(
167
- name: string,
168
- config: {
169
- title?: string
170
- description?: string
171
- argsSchema?: Args
172
- },
173
- cb: PromptCallback<Args>
174
- ): RegisteredPrompt {
175
- return this.server.registerPrompt(name, config, cb)
176
- }
177
-
178
- /**
179
- * Registers a resource with a config object and callback.
180
- * For static resources, use a URI string. For dynamic resources, use a ResourceTemplate.
181
- */
182
- registerResource(
183
- name: string,
184
- uriOrTemplate: string,
185
- config: ResourceMetadata,
186
- readCallback: ReadResourceCallback
187
- ): RegisteredResource
188
- registerResource(
189
- name: string,
190
- uriOrTemplate: ResourceTemplate,
191
- config: ResourceMetadata,
192
- readCallback: ReadResourceTemplateCallback
193
- ): RegisteredResourceTemplate
194
- registerResource(
195
- name: string,
196
- uriOrTemplate: string | ResourceTemplate,
197
- config: ResourceMetadata,
198
- readCallback: ReadResourceCallback | ReadResourceTemplateCallback
199
- ): RegisteredResource | RegisteredResourceTemplate {
200
- if (typeof uriOrTemplate === 'string') {
201
- return this.server.registerResource(name, uriOrTemplate, config, readCallback as ReadResourceCallback)
202
- } else {
203
- return this.server.registerResource(name, uriOrTemplate, config, readCallback as ReadResourceTemplateCallback)
204
- }
205
- }
206
-
207
- /**
208
- * Checks if the server is connected to a transport.
209
- * @returns True if the server is connected
210
- */
211
- isConnected() {
212
- return this.server.isConnected()
213
- }
214
-
215
- /**
216
- * Sends a resource list changed event to the client, if connected.
217
- */
218
- sendResourceListChanged() {
219
- this.server.sendResourceListChanged()
220
- }
221
-
222
- /**
223
- * Sends a tool list changed event to the client, if connected.
224
- */
225
- sendToolListChanged() {
226
- this.server.sendToolListChanged()
227
- }
228
-
229
- /**
230
- * Sends a prompt list changed event to the client, if connected.
231
- */
232
- sendPromptListChanged() {
233
- this.server.sendPromptListChanged()
234
- }
235
-
236
- /**
237
- * After initialization has completed, this will be populated with the client's reported capabilities.
238
- */
239
- getClientCapabilities(): ClientCapabilities | undefined {
240
- return this.server.server.getClientCapabilities()
241
- }
242
-
243
- /**
244
- * After initialization has completed, this will be populated with information about the client's name and version.
245
- */
246
- getClientVersion(): Implementation | undefined {
247
- return this.server.server.getClientVersion()
248
- }
249
-
250
- /**
251
- * Sends a ping to the client to check if it is still connected.
252
- */
253
- async ping() {
254
- return await this.server.server.ping()
255
- }
256
-
257
- /**
258
- * Creates a LLM message to be sent to the client.
259
- */
260
- async createMessage(params: CreateMessageRequest['params'], options?: RequestOptions) {
261
- return await this.server.server.createMessage(params, options)
262
- }
263
-
264
- /**
265
- * Elicits input from the client, such as a prompt or resource.
266
- */
267
- async elicitInput(params: ElicitRequest['params'], options?: RequestOptions): Promise<ElicitResult> {
268
- return await this.server.server.elicitInput(params, options)
269
- }
270
-
271
- /**
272
- * Lists the root resources available to the client.
273
- */
274
- async listRoots(params?: ListRootsRequest['params'], options?: RequestOptions) {
275
- return await this.server.server.listRoots(params, options)
276
- }
277
-
278
- /**
279
- * Sends a logging message to the client.
280
- */
281
- async sendLoggingMessage(params: LoggingMessageNotification['params']) {
282
- return await this.server.server.sendLoggingMessage(params)
283
- }
284
-
285
- /**
286
- * Sends a resource updated notification to the client.
287
- */
288
- async sendResourceUpdated(params: ResourceUpdatedNotification['params']) {
289
- return await this.server.server.sendResourceUpdated(params)
290
- }
291
-
292
- /**
293
- * Sends a request and wait for a response.
294
- *
295
- * Do not use this method to emit notifications! Use notification() instead.
296
- */
297
- request<T extends ZodType<object>>(
298
- request: SendRequestT,
299
- resultSchema: T,
300
- options?: RequestOptions
301
- ): Promise<z.infer<T>> {
302
- return this.server.server.request(request, resultSchema, options)
303
- }
304
-
305
- /**
306
- * Emits a notification, which is a one-way message that does not expect a response.
307
- */
308
- async notification(notification: SendNotificationT, options?: NotificationOptions): Promise<void> {
309
- return await this.server.server.notification(notification, options)
310
- }
311
-
312
- /**
313
- * Registers a handler to invoke when this protocol object receives a request with the given method.
314
- *
315
- * Note that this will replace any previous request handler for the same method.
316
- */
317
- setRequestHandler<
318
- T extends ZodObject<{
319
- method: ZodLiteral<string>
320
- }>
321
- >(
322
- requestSchema: T,
323
- handler: (
324
- request: z.infer<T>,
325
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
326
- ) => SendResultT | Promise<SendResultT>
327
- ): void {
328
- this.server.server.setRequestHandler(requestSchema, handler)
329
- }
330
-
331
- /**
332
- * Removes the request handler for the given method.
333
- */
334
- removeRequestHandler(method: string): void {
335
- this.server.server.removeRequestHandler(method)
336
- }
337
-
338
- /**
339
- * Registers a handler to invoke when this protocol object receives a notification with the given method.
340
- *
341
- * Note that this will replace any previous notification handler for the same method.
342
- */
343
- setNotificationHandler<
344
- T extends ZodObject<{
345
- method: ZodLiteral<string>
346
- }>
347
- >(notificationSchema: T, handler: (notification: z.infer<T>) => void | Promise<void>): void {
348
- this.server.server.setNotificationHandler(notificationSchema, handler)
349
- }
350
-
351
- /**
352
- * Removes the notification handler for the given method.
353
- */
354
- removeNotificationHandler(method: string): void {
355
- this.server.server.removeNotificationHandler(method)
356
- }
357
-
358
- /**
359
- * Registers a handler for the subscribe request.
360
- */
361
- onSubscribe(
362
- handler: (
363
- request: SubscribeRequest,
364
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
365
- ) => SendResultT | Promise<SendResultT>
366
- ): void {
367
- this.server.server.setRequestHandler(SubscribeRequestSchema, handler)
368
- }
369
-
370
- /**
371
- * Registers a handler for the unsubscribe request.
372
- */
373
- onUnsubscribe(
374
- handler: (
375
- request: UnsubscribeRequest,
376
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
377
- ) => SendResultT | Promise<SendResultT>
378
- ): void {
379
- this.server.server.setRequestHandler(UnsubscribeRequestSchema, handler)
380
- }
381
-
382
- /**
383
- * Registers a handler for the set log level request.
384
- */
385
- onSetLogLevel(
386
- handler: (
387
- request: SetLevelRequest,
388
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
389
- ) => SendResultT | Promise<SendResultT>
390
- ): void {
391
- this.server.server.setRequestHandler(SetLevelRequestSchema, handler)
392
- }
393
-
394
- /**
395
- * Registers a handler for the list tools request.
396
- */
397
- onListResources(
398
- handler: (
399
- request: ListResourcesRequest,
400
- extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
401
- ) => SendResultT | Promise<SendResultT>
402
- ): void {
403
- this.server.server.setRequestHandler(ListResourcesRequestSchema, handler)
404
- }
405
-
406
- /**
407
- * Registers a handler for the roots list changed notification.
408
- */
409
- onRootsListChanged(handler: (notification: RootsListChangedNotification) => void | Promise<void>): void {
410
- this.server.server.setNotificationHandler(RootsListChangedNotificationSchema, handler)
411
- }
412
-
413
- /**
414
- * Close the transport for window.addEventListener('pagehide')
415
- */
416
- async onPagehide(event: PageTransitionEvent) {
417
- if (event.persisted) {
418
- return
419
- }
420
-
421
- if (this.transport && typeof this.transport['close'] === 'function') {
422
- await this.transport.close()
423
- }
424
- }
425
- }
426
-
427
- /**
428
- * Creates a new MessageChannelServerTransport instance.
429
- */
430
- export const createMessageChannelServerTransport = (endpoint: string, globalObject?: object) =>
431
- new MessageChannelServerTransport(endpoint, globalObject)
432
-
433
- /**
434
- * Creates a pair of transports for communication between a server and client using MessageChannel.
435
- */
436
- export const createMessageChannelPairTransport = () => createTransportPair()
437
-
438
- /**
439
- * Checks if the transport is a MessageChannelServerTransport.
440
- */
441
- export const isMessageChannelServerTransport = (transport: unknown): transport is MessageChannelServerTransport =>
442
- transport instanceof MessageChannelServerTransport
443
-
444
- /**
445
- * Checks if the server is an instance of MCP Server.
446
- */
447
- export const isMcpServer = (server: unknown): server is McpServer => server instanceof McpServer