aigate 0.1.0

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/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # AIProxy — npm installer
2
+
3
+ Install **AIProxy** globally via npm. This package bootstraps a self-contained Python virtual environment and installs the [aiguard](https://pypi.org/project/aiguard/) PyPI package automatically.
4
+
5
+ ## Prerequisites
6
+
7
+ - **Node.js** 16+
8
+ - **Python** 3.11+ (must be on your `PATH`)
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install -g aiproxy
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```bash
19
+ # Start the proxy server
20
+ guard start
21
+
22
+ # Or use the full command name
23
+ aiproxy server start
24
+
25
+ # Interactive onboarding wizard
26
+ aiproxy onboard
27
+
28
+ # View all commands
29
+ aiproxy --help
30
+ ```
31
+
32
+ ## How it works
33
+
34
+ 1. `npm install -g aiproxy` downloads this wrapper package
35
+ 2. The `postinstall` script locates Python 3.11+ on your system
36
+ 3. A virtual environment is created inside the npm package directory
37
+ 4. The `aiguard` Python package is installed from PyPI into that venv
38
+ 5. The `aiproxy` / `aiguard` / `guard` commands delegate to the Python CLI
39
+
40
+ No global Python packages are modified — everything stays isolated in the venv.
41
+
42
+ ## Upgrade
43
+
44
+ ```bash
45
+ npm update -g aiproxy
46
+ ```
47
+
48
+ ## Uninstall
49
+
50
+ ```bash
51
+ npm uninstall -g aiproxy
52
+ ```
53
+
54
+ This removes the package and its bundled virtual environment.
55
+
56
+ ## Troubleshooting
57
+
58
+ | Issue | Fix |
59
+ |-------|-----|
60
+ | `Python 3.11+ is required` | Install Python 3.11+ and ensure `python3` is on your PATH |
61
+ | `guard binary not found` after install | Run `npm rebuild aiproxy` |
62
+ | Permission errors on Linux | Avoid `sudo npm install -g`; configure npm prefix instead: `npm config set prefix ~/.npm-global` |
63
+
64
+ ## Publishing (maintainers)
65
+
66
+ ```bash
67
+ cd deployments/npm
68
+ # Bump version in package.json to match pyproject.toml
69
+ npm publish
70
+ ```
package/bin/aiproxy.js ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * bin/aiproxy.js — Thin wrapper that delegates all commands to the
5
+ * Python `guard` CLI installed in the package's virtual environment.
6
+ *
7
+ * Usage:
8
+ * aiproxy start → guard start
9
+ * aiproxy shield list → guard shield list
10
+ * aiguard --help → guard --help
11
+ * guard --help → guard --help
12
+ */
13
+
14
+ const { spawn } = require("child_process");
15
+ const path = require("path");
16
+ const fs = require("fs");
17
+
18
+ const PACKAGE_DIR = path.resolve(__dirname, "..");
19
+ const VENV_DIR = path.join(PACKAGE_DIR, ".venv");
20
+ const IS_WIN = process.platform === "win32";
21
+
22
+ function venvBin(name) {
23
+ return IS_WIN
24
+ ? path.join(VENV_DIR, "Scripts", `${name}.exe`)
25
+ : path.join(VENV_DIR, "bin", name);
26
+ }
27
+
28
+ // ---------------------------------------------------------------------------
29
+ // Resolve the Python guard CLI
30
+ // ---------------------------------------------------------------------------
31
+
32
+ const guardBin = venvBin("guard");
33
+ const pythonBin = venvBin("python");
34
+
35
+ if (!fs.existsSync(guardBin) && !fs.existsSync(pythonBin)) {
36
+ console.error(
37
+ "❌ AIProxy Python environment not found.\n" +
38
+ " Run `npm rebuild aiproxy` to reinstall, or check that Python 3.11+ is available.\n"
39
+ );
40
+ process.exit(1);
41
+ }
42
+
43
+ // Prefer the installed `guard` script; fall back to `python -m aiguard.cli.main`
44
+ const useGuardBin = fs.existsSync(guardBin);
45
+ const cmd = useGuardBin ? guardBin : pythonBin;
46
+ const args = useGuardBin
47
+ ? process.argv.slice(2)
48
+ : ["-m", "aiguard.cli.main", ...process.argv.slice(2)];
49
+
50
+ // ---------------------------------------------------------------------------
51
+ // Spawn the Python process, forwarding stdio and exit code
52
+ // ---------------------------------------------------------------------------
53
+
54
+ const child = spawn(cmd, args, {
55
+ stdio: "inherit",
56
+ env: {
57
+ ...process.env,
58
+ // Ensure the venv's bin dir is first on PATH so sub-processes find
59
+ // the right Python (e.g., for shield logic modules).
60
+ PATH: `${path.dirname(guardBin)}${path.delimiter}${process.env.PATH || ""}`,
61
+ VIRTUAL_ENV: VENV_DIR,
62
+ },
63
+ });
64
+
65
+ child.on("error", (err) => {
66
+ console.error(`❌ Failed to start AIProxy: ${err.message}`);
67
+ process.exit(1);
68
+ });
69
+
70
+ child.on("close", (code) => {
71
+ process.exit(code ?? 1);
72
+ });
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "aigate",
3
+ "version": "0.1.0",
4
+ "description": "Anti-virus for AI — intercept prompt injections, PII leaks, and policy violations before they reach the model.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "keywords": [
9
+ "ai",
10
+ "security",
11
+ "proxy",
12
+ "llm",
13
+ "prompt-injection",
14
+ "pii",
15
+ "guardrails",
16
+ "anthropic",
17
+ "openai",
18
+ "claude",
19
+ "cursor",
20
+ "aiproxy",
21
+ "aiguardian",
22
+ "aiguard"
23
+ ],
24
+ "homepage": "https://github.com/aibuildspace/aigate.git",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/aibuildspace/aigate.git"
28
+ },
29
+ "license": "MIT",
30
+ "author": "Sean Preusse",
31
+ "bin": {
32
+ "aiproxy": "./bin/aiproxy.js",
33
+ "aiguard": "./bin/aiproxy.js",
34
+ "guard": "./bin/aiproxy.js"
35
+ },
36
+ "scripts": {
37
+ "postinstall": "node postinstall.js"
38
+ },
39
+ "files": [
40
+ "bin/",
41
+ "postinstall.js",
42
+ "README.md",
43
+ "LICENSE"
44
+ ],
45
+ "engines": {
46
+ "node": ">=16.0.0"
47
+ },
48
+ "os": [
49
+ "darwin",
50
+ "linux",
51
+ "win32"
52
+ ]
53
+ }
package/postinstall.js ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * postinstall.js — Creates a self-contained Python virtual environment
5
+ * and installs the aiguard PyPI package into it.
6
+ *
7
+ * Requirements: Python 3.11+ must be available on the system.
8
+ */
9
+
10
+ const { execSync } = require("child_process");
11
+ const path = require("path");
12
+ const fs = require("fs");
13
+
14
+ const PACKAGE_DIR = __dirname;
15
+ const VENV_DIR = path.join(PACKAGE_DIR, ".venv");
16
+ const IS_WIN = process.platform === "win32";
17
+ const MIN_PYTHON = [3, 11];
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Helpers
21
+ // ---------------------------------------------------------------------------
22
+
23
+ function findPython() {
24
+ const candidates = IS_WIN
25
+ ? ["python", "python3", "py -3"]
26
+ : ["python3", "python"];
27
+
28
+ for (const cmd of candidates) {
29
+ try {
30
+ const version = execSync(`${cmd} --version 2>&1`, {
31
+ encoding: "utf-8",
32
+ }).trim();
33
+
34
+ const match = version.match(/Python (\d+)\.(\d+)\.(\d+)/);
35
+ if (!match) continue;
36
+
37
+ const major = parseInt(match[1], 10);
38
+ const minor = parseInt(match[2], 10);
39
+
40
+ if (
41
+ major > MIN_PYTHON[0] ||
42
+ (major === MIN_PYTHON[0] && minor >= MIN_PYTHON[1])
43
+ ) {
44
+ return { cmd, version: `${major}.${minor}.${match[3]}` };
45
+ }
46
+ } catch {
47
+ // not found — try next
48
+ }
49
+ }
50
+ return null;
51
+ }
52
+
53
+ function venvBin(name) {
54
+ return IS_WIN
55
+ ? path.join(VENV_DIR, "Scripts", `${name}.exe`)
56
+ : path.join(VENV_DIR, "bin", name);
57
+ }
58
+
59
+ // ---------------------------------------------------------------------------
60
+ // Main
61
+ // ---------------------------------------------------------------------------
62
+
63
+ function main() {
64
+ console.log("\n🛡️ AIProxy — installing Python backend …\n");
65
+
66
+ // 1. Locate Python
67
+ const py = findPython();
68
+ if (!py) {
69
+ console.error(
70
+ `\n❌ Python ${MIN_PYTHON.join(".")}+ is required but was not found on your PATH.\n` +
71
+ ` Install it from https://www.python.org/downloads/ and try again.\n`
72
+ );
73
+ process.exit(1);
74
+ }
75
+ console.log(` Found ${py.cmd} (${py.version})`);
76
+
77
+ // 2. Create virtual environment (skip if already present and valid)
78
+ const venvPython = venvBin("python");
79
+ if (!fs.existsSync(venvPython)) {
80
+ console.log(" Creating virtual environment …");
81
+ execSync(`${py.cmd} -m venv "${VENV_DIR}"`, {
82
+ stdio: "inherit",
83
+ cwd: PACKAGE_DIR,
84
+ });
85
+ } else {
86
+ console.log(" Virtual environment already exists");
87
+ }
88
+
89
+ // 3. Upgrade pip silently then install aiguard
90
+ const pip = venvBin("pip");
91
+ console.log(" Upgrading pip …");
92
+ execSync(`"${pip}" install --upgrade pip --quiet`, {
93
+ stdio: "inherit",
94
+ cwd: PACKAGE_DIR,
95
+ });
96
+
97
+ console.log(" Installing aiguard from PyPI …");
98
+ execSync(`"${pip}" install --upgrade aiguard`, {
99
+ stdio: "inherit",
100
+ cwd: PACKAGE_DIR,
101
+ });
102
+
103
+ // 4. Verify installation
104
+ const guard = venvBin("guard");
105
+ if (fs.existsSync(guard)) {
106
+ console.log("\n✅ AIProxy installed successfully!");
107
+ console.log(
108
+ " Run `aiproxy --help` or `guard --help` to get started.\n"
109
+ );
110
+ } else {
111
+ console.error(
112
+ "\n⚠️ Installation completed but the guard binary was not found."
113
+ );
114
+ console.error(" Try running: pip install aiguard\n");
115
+ process.exit(1);
116
+ }
117
+ }
118
+
119
+ main();