vite-plugin-ai-annotator 1.14.7 → 1.14.9
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.
- package/dist/annotator-toolbar.d.ts +2 -0
- package/dist/annotator-toolbar.js +35 -81
- package/dist/index.cjs +35 -35
- package/dist/mcp-tools.d.ts +25 -0
- package/dist/nuxt-module.js +21 -19
- package/dist/nuxt-module.js.map +2 -2
- package/dist/utils/logger.d.ts +0 -1
- package/dist/utils/version.d.ts +1 -0
- package/dist/utils/xpath.d.ts +0 -4
- package/dist/vite-plugin.js +20 -17
- package/dist/vite-plugin.js.map +2 -2
- package/dist/ws-server.d.ts +5 -5
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared MCP tool definitions for AI Annotator
|
|
3
|
+
*
|
|
4
|
+
* Registers all 9 MCP tools on a McpServer instance.
|
|
5
|
+
* Used by both ws-server.ts (HTTP MCP) and mcp-stdio.ts (stdio MCP).
|
|
6
|
+
*/
|
|
7
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import type { BrowserSession, PageContext, ElementData, SelectionResult, ScreenshotResult, InjectResult, ConsoleEntry } from './rpc/define';
|
|
9
|
+
import type { RpcError } from './rpc/types.generated';
|
|
10
|
+
export interface AnnotatorConnection {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
getPageContext(timeout?: number): Promise<PageContext | RpcError>;
|
|
13
|
+
getSelectedElements(timeout?: number): Promise<ElementData[] | RpcError>;
|
|
14
|
+
triggerSelection(mode: 'inspect' | 'selector', selector?: string, selectorType?: 'css' | 'xpath', timeout?: number): Promise<SelectionResult | RpcError>;
|
|
15
|
+
captureScreenshot(type: 'viewport' | 'element', selector?: string, quality?: number, timeout?: number): Promise<ScreenshotResult | RpcError>;
|
|
16
|
+
clearSelection(): void;
|
|
17
|
+
injectCSS(css: string, timeout?: number): Promise<InjectResult | RpcError>;
|
|
18
|
+
injectJS(code: string, timeout?: number): Promise<InjectResult | RpcError>;
|
|
19
|
+
getConsole(clear?: boolean, timeout?: number): Promise<ConsoleEntry[] | RpcError>;
|
|
20
|
+
}
|
|
21
|
+
export type GetConnection = (sessionId?: string) => AnnotatorConnection | {
|
|
22
|
+
error: string;
|
|
23
|
+
};
|
|
24
|
+
export type ListSessions = () => Promise<BrowserSession[]>;
|
|
25
|
+
export declare function registerMcpTools(mcp: McpServer, listSessions: ListSessions, getConnection: GetConnection): void;
|
package/dist/nuxt-module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/nuxt-module.ts
|
|
2
|
-
import { defineNuxtModule, addVitePlugin
|
|
2
|
+
import { defineNuxtModule, addVitePlugin } from "@nuxt/kit";
|
|
3
3
|
|
|
4
4
|
// src/vite-plugin.ts
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -1199,7 +1199,7 @@ function injectSourceLocations(code, id, root) {
|
|
|
1199
1199
|
const s = new MagicString(code);
|
|
1200
1200
|
const relativePath = relative(root, id);
|
|
1201
1201
|
let hasChanges = false;
|
|
1202
|
-
const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^>]
|
|
1202
|
+
const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*)((?:\s+(?:[^>"'\/=]+(?:=(?:"[^"]*"|'[^']*'|[^\s>"']+))?|\s))*)\s*\/?>/g;
|
|
1203
1203
|
const skipTags = /* @__PURE__ */ new Set([
|
|
1204
1204
|
"script",
|
|
1205
1205
|
"style",
|
|
@@ -1333,10 +1333,6 @@ var AiAnnotatorServer = class {
|
|
|
1333
1333
|
env: process.env,
|
|
1334
1334
|
stdio: this.options.verbose ? "inherit" : "pipe"
|
|
1335
1335
|
});
|
|
1336
|
-
if (!this.options.verbose && this.serverProcess.stdout) {
|
|
1337
|
-
this.serverProcess.stdout.on("data", (_data) => {
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
1336
|
if (!this.options.verbose && this.serverProcess.stderr) {
|
|
1341
1337
|
this.serverProcess.stderr.on("data", (data) => {
|
|
1342
1338
|
console.error(`[ai-annotator-server] Error: ${data}`);
|
|
@@ -1351,7 +1347,12 @@ var AiAnnotatorServer = class {
|
|
|
1351
1347
|
}
|
|
1352
1348
|
this.serverProcess = null;
|
|
1353
1349
|
});
|
|
1354
|
-
|
|
1350
|
+
const deadline = Date.now() + 5e3;
|
|
1351
|
+
while (Date.now() < deadline) {
|
|
1352
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1353
|
+
if (await this.isServerRunning()) return;
|
|
1354
|
+
}
|
|
1355
|
+
this.log("Server did not respond to health check within 5 seconds");
|
|
1355
1356
|
}
|
|
1356
1357
|
async stop() {
|
|
1357
1358
|
if (this.serverProcess) {
|
|
@@ -1457,36 +1458,38 @@ function aiAnnotator(options = {}) {
|
|
|
1457
1458
|
},
|
|
1458
1459
|
// For SSR frameworks like Nuxt - intercept HTML responses
|
|
1459
1460
|
configureServer(server) {
|
|
1461
|
+
server.httpServer?.on("close", () => {
|
|
1462
|
+
serverManager.stop();
|
|
1463
|
+
});
|
|
1460
1464
|
server.middlewares.use((_req, res, next) => {
|
|
1461
1465
|
if (!serverManager) {
|
|
1462
1466
|
return next();
|
|
1463
1467
|
}
|
|
1464
|
-
const originalWrite = res.write.bind(res);
|
|
1465
1468
|
const originalEnd = res.end.bind(res);
|
|
1466
1469
|
let chunks = [];
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
const contentType = res.getHeader("content-type");
|
|
1470
|
-
if (typeof contentType === "string" && contentType.includes("text/html")) {
|
|
1471
|
-
isHtml = true;
|
|
1472
|
-
}
|
|
1473
|
-
if (isHtml && chunk) {
|
|
1470
|
+
res.write = function(chunk, ..._args) {
|
|
1471
|
+
if (chunk) {
|
|
1474
1472
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
1475
|
-
return true;
|
|
1476
1473
|
}
|
|
1477
|
-
return
|
|
1474
|
+
return true;
|
|
1478
1475
|
};
|
|
1479
1476
|
res.end = function(chunk, ...args) {
|
|
1480
1477
|
if (chunk) {
|
|
1481
1478
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
1482
1479
|
}
|
|
1480
|
+
const contentType = res.getHeader("content-type");
|
|
1481
|
+
const isHtml = typeof contentType === "string" && contentType.includes("text/html");
|
|
1483
1482
|
if (isHtml && chunks.length > 0) {
|
|
1484
1483
|
const html = Buffer.concat(chunks).toString("utf-8");
|
|
1485
1484
|
const injectedHtml = injectScriptIntoHtml(html, serverManager.getInjectScript());
|
|
1486
1485
|
res.setHeader("content-length", Buffer.byteLength(injectedHtml));
|
|
1487
1486
|
return originalEnd(injectedHtml, ...args);
|
|
1488
1487
|
}
|
|
1489
|
-
|
|
1488
|
+
if (chunks.length > 0) {
|
|
1489
|
+
const body = Buffer.concat(chunks);
|
|
1490
|
+
return originalEnd(body, ...args);
|
|
1491
|
+
}
|
|
1492
|
+
return originalEnd(void 0, ...args);
|
|
1490
1493
|
};
|
|
1491
1494
|
next();
|
|
1492
1495
|
});
|
|
@@ -1518,7 +1521,6 @@ var nuxt_module_default = defineNuxtModule({
|
|
|
1518
1521
|
return;
|
|
1519
1522
|
}
|
|
1520
1523
|
addVitePlugin(aiAnnotator(options));
|
|
1521
|
-
addWebpackPlugin(aiAnnotator(options));
|
|
1522
1524
|
console.log("[ai-annotator] Nuxt module initialized");
|
|
1523
1525
|
}
|
|
1524
1526
|
});
|