@agentxin-ai/plugin-playwright-cli 0.0.2

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 (2) hide show
  1. package/README.md +111 -0
  2. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # AgentXin Plugin: Playwright CLI Middleware
2
+
3
+ `@agentxin-ai/plugin-playwright-cli` adds browser automation support to AgentXin agents by bootstrapping `@playwright/cli` inside the agent sandbox and teaching the agent how to use it through `sandbox_shell`. Instead of registering a standalone tool, the middleware prepares the sandbox runtime, injects Playwright usage guidance into the system prompt, and keeps `playwright-cli` commands aligned with a managed Chromium configuration.
4
+
5
+ ## Key Features
6
+
7
+ - Bootstraps `@playwright/cli` globally inside the sandbox on first use.
8
+ - Installs the Chromium browser runtime required by `playwright-cli`.
9
+ - Writes embedded skill assets (`SKILL.md` plus reference docs) into the sandbox for agent self-guidance.
10
+ - Appends a Playwright-specific system prompt so the agent uses `sandbox_shell` with `playwright-cli` instead of unsupported alternatives.
11
+ - Re-checks bootstrap state before Playwright shell commands and re-installs automatically if the sandbox container was reset.
12
+ - Injects a managed config for `playwright-cli open` so Chromium is used by default when no browser/config is specified.
13
+ - Caps `playwright-cli open` shell calls to a short timeout so the browser session starts quickly without blocking the workflow.
14
+ - Validates agent drafts and warns when sandbox support or `SandboxShell` is missing.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pnpm add @agentxin-ai/plugin-playwright-cli
20
+ # or
21
+ npm install @agentxin-ai/plugin-playwright-cli
22
+ ```
23
+
24
+ > **Note**: Ensure the host service already provides `@agentxin-ai/plugin-sdk`, `@metad/contracts`, `@nestjs/common@^11`, `@nestjs/event-emitter`, `@langchain/core@^0.3`, `zod`, and `chalk`. These are treated as peer/runtime dependencies in the host environment.
25
+
26
+ ## Quick Start
27
+
28
+ 1. **Register the Plugin**
29
+ Start AgentXin with the package in your plugin list:
30
+ ```sh
31
+ PLUGINS=@agentxin-ai/plugin-playwright-cli
32
+ ```
33
+ The plugin registers the global `PlaywrightCliPluginModule`.
34
+ 2. **Enable Sandbox Support**
35
+ Turn on the agent sandbox feature for the team/agent that will run browser automation.
36
+ 3. **Add `SandboxShell` on the Same Agent**
37
+ This middleware relies on the `sandbox_shell` tool exposed by the `SandboxShell` middleware.
38
+ 4. **Add the Playwright Middleware**
39
+ In the AgentXin console (or agent definition), add a middleware entry with strategy `PlaywrightCLISkill`.
40
+ 5. **Optionally Configure the Bootstrap Behavior**
41
+ Example middleware block:
42
+ ```json
43
+ {
44
+ "type": "PlaywrightCLISkill",
45
+ "options": {
46
+ "cliVersion": "latest",
47
+ "skillsDir": "/workspace/.agentxin/skills/playwright-cli"
48
+ }
49
+ }
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ | Field | Type | Description | Default |
55
+ | ----- | ---- | ----------- | ------- |
56
+ | `cliVersion` | string | Version of `@playwright/cli` to install globally in the sandbox. | `"latest"` |
57
+ | `skillsDir` | string | Path inside the sandbox where `SKILL.md` and reference files are written. | `"/workspace/.agentxin/skills/playwright-cli"` |
58
+
59
+ ## Runtime Behavior
60
+
61
+ - On first use, the middleware checks `/workspace/.agentxin/.playwright-cli-bootstrap.json` to determine whether the sandbox is already bootstrapped.
62
+ - If bootstrap is missing or outdated, it installs `@playwright/cli`, installs Chromium via `playwright-cli install chromium`, writes skill assets, and refreshes the stamp file.
63
+ - A managed config is written to `/workspace/.agentxin/playwright-cli/cli.config.json` and is automatically injected into `playwright-cli open` commands when the command does not already specify `--browser` or `--config`.
64
+ - The middleware appends a system prompt that tells the agent to:
65
+ - use `playwright-cli` rather than `playwright` or `npx playwright`
66
+ - read the sandbox skill file before first use
67
+ - prefer headless, non-interactive workflows
68
+ - avoid `codegen`, UI mode, and `show`
69
+ - When the agent calls `sandbox_shell` with a Playwright command, the middleware ensures bootstrap has completed before the command runs.
70
+ - For `playwright-cli open` commands, `timeout_sec` is automatically capped to `15` seconds so the shell call returns promptly after the browser is launched. If the shell call times out, the browser session may still remain active in the sandbox.
71
+ - Non-Playwright `sandbox_shell` commands are passed through unchanged.
72
+
73
+ ## Validation Rules
74
+
75
+ The plugin contributes draft validation warnings in AgentXin when:
76
+
77
+ - the agent uses `PlaywrightCLISkill` but sandbox support is disabled
78
+ - the agent uses `PlaywrightCLISkill` without `SandboxShell` on the same agent
79
+
80
+ ## Sandbox Assets
81
+
82
+ During bootstrap, the plugin writes the following assets into the sandbox:
83
+
84
+ - `SKILL.md` with recommended `playwright-cli` command patterns
85
+ - reference documents for advanced topics such as session management, request mocking, tracing, storage state, video recording, test generation, and running custom code
86
+ - a managed Playwright config that pins default browser startup to Chromium
87
+ - a bootstrap stamp file used to avoid unnecessary reinstallation
88
+
89
+ ## Configuration Precedence
90
+
91
+ Configuration is resolved in this order, from lowest to highest priority:
92
+
93
+ 1. Built-in defaults
94
+ 2. Environment variables:
95
+ - `PLAYWRIGHT_CLI_VERSION`
96
+ - `PLAYWRIGHT_SKILLS_DIR`
97
+ 3. Plugin-level config resolved by the host plugin config resolver
98
+ 4. Middleware `options`
99
+
100
+ ## Development & Testing
101
+
102
+ ```bash
103
+ NX_DAEMON=false pnpm -C /path/to/agentxin-plugins/agentxinai exec nx build @agentxin-ai/plugin-playwright-cli
104
+ NX_DAEMON=false pnpm -C /path/to/agentxin-plugins/agentxinai exec nx test @agentxin-ai/plugin-playwright-cli
105
+ ```
106
+
107
+ TypeScript output is emitted to `middlewares/playwright-cli/dist`.
108
+
109
+ ## License
110
+
111
+ This project follows the [AGPL-3.0 License](../../../LICENSE) located at the repository root.
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@agentxin-ai/plugin-playwright-cli",
3
+ "version": "0.0.2",
4
+ "author": {
5
+ "name": "AgentXinAI",
6
+ "url": "https://agentxinai.cn"
7
+ },
8
+ "license": "AGPL-3.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/agentxin-ai/agentxin-plugins.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/agentxin-ai/agentxin-plugins/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "@agentxin-plugins-starter/source": "./src/index.ts",
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "!**/*.tsbuildinfo"
32
+ ],
33
+ "scripts": {
34
+ "prepack": "node ./scripts/copy-assets.mjs"
35
+ },
36
+ "dependencies": {
37
+ "tslib": "^2.3.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@metad/contracts": "^3.8.3",
41
+ "@agentxin-ai/plugin-sdk": "^3.8.3"
42
+ }
43
+ }