@tetrixdev/ai-bridge 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tetrixdev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @tetrixdev/ai-bridge
2
+
3
+ A local CLI bridge that connects your AI command-line tools (Codex, Claude, Gemini) to web applications via WebSocket. The bridge runs on your machine, receives AI requests from a server, pipes them through your locally installed CLI tools, and streams normalized responses back -- letting web apps use your own AI subscriptions without touching your credentials.
4
+
5
+ ## Quick Start
6
+
7
+ The **connection token** is generated from the web application that uses the AI Bridge server package (for example, `php artisan ai-bridge:token` for Laravel apps). The **server URL** is the WebSocket server address provided by that application (typically `wss://your-app.com/api/ai-bridge/ws`).
8
+
9
+ ```bash
10
+ npx @tetrixdev/ai-bridge --server wss://your-app.com/api/ai-bridge/ws --token YOUR_CONNECTION_TOKEN
11
+ ```
12
+
13
+ Or using environment variables:
14
+
15
+ ```bash
16
+ export AI_BRIDGE_SERVER=wss://your-app.com/api/ai-bridge/ws
17
+ export AI_BRIDGE_TOKEN=YOUR_CONNECTION_TOKEN
18
+ npx @tetrixdev/ai-bridge
19
+ ```
20
+
21
+ ## Options
22
+
23
+ | Flag | Environment Variable | Description |
24
+ |------|---------------------|-------------|
25
+ | `--server <url>` | `AI_BRIDGE_SERVER` | WebSocket server URL (`wss://...`) |
26
+ | `--token <token>` | `AI_BRIDGE_TOKEN` | Connection token from the web app |
27
+ | `--test` | | Test mode -- responds with mock data instead of calling real CLIs |
28
+ | `--debug` | | Enable verbose debug logging |
29
+
30
+ ## Supported Providers
31
+
32
+ | Provider | CLI Binary | Session Resume | Streaming | Thinking | Server Tools |
33
+ |----------|-----------|----------------|-----------|----------|--------------|
34
+ | **Codex** (OpenAI) | `codex` | Yes | NDJSON | Yes | Yes |
35
+ | **Claude** (Anthropic) | `claude` | Yes | NDJSON | Yes | Yes |
36
+ | **Gemini** (Google) | `gemini` | Yes | NDJSON | Partial | Yes |
37
+
38
+ The bridge auto-detects which CLIs are installed on startup.
39
+
40
+ **Server-defined tools** registered by the web application are exposed to every provider as Bash wrapper scripts placed on the CLI's `PATH`; the CLI invokes them as ordinary shell commands and the bridge routes the call back through the WebSocket. For Codex, the bridge runs `codex exec` with a workspace-write sandbox and network access enabled so the wrapper scripts can reach the bridge — this is handled automatically when tools are present.
41
+
42
+ ## Test Mode
43
+
44
+ Use `--test` to verify your WebSocket connection and protocol behaviour without needing a real CLI installed. Note that `--server` and `--token` are still required in test mode — the WebSocket connection to the server is what test mode exercises.
45
+
46
+ ```bash
47
+ npx @tetrixdev/ai-bridge --server wss://your-app.com/api/ai-bridge/ws --token TOKEN --test
48
+ ```
49
+
50
+ In test mode, AI requests receive mock streaming responses (thinking block + text block + done event) that exercise the full protocol.
51
+
52
+ ## Troubleshooting
53
+
54
+ **Get detailed diagnostics with `--debug`**
55
+ For detailed diagnostic output, add `--debug` to the command. This logs each WebSocket message, provider command, and session operation, which is the fastest way to pin down a confusing error before filing a support request.
56
+
57
+ **"Authentication token is required" / "Server URL is required"**
58
+ The token is generated by your web application (e.g. `php artisan ai-bridge:token` for Laravel apps). The server URL is the WebSocket endpoint exposed by that application (typically `wss://your-app.com/api/ai-bridge/ws`). See your application's documentation for the exact values.
59
+
60
+ **"Connection rejected: invalid or expired token"**
61
+ Your token has expired or was revoked. Generate a new one from your web application's admin interface and restart the bridge.
62
+
63
+ **"No AI CLI tools detected"**
64
+ Install one or more supported CLIs:
65
+ - Codex: https://github.com/openai/codex
66
+ - Claude: https://claude.ai/download
67
+ - Gemini: https://github.com/google-gemini/gemini-cli
68
+
69
+ **"Authentication required — run \`<provider\> auth login\`"**
70
+ Your AI CLI's authentication session has expired. Run the indicated login command (e.g. `claude auth login`) and then restart the bridge.
71
+
72
+ **Where are sessions stored?**
73
+ Session mappings are persisted to `~/.ai-bridge/sessions.json` so conversations can be resumed across bridge restarts. You can delete this file to clear all sessions.
74
+
75
+ ## Protocol
76
+
77
+ See [PROTOCOL.md](./PROTOCOL.md) for the full wire format specification.
78
+
79
+ ## License
80
+
81
+ MIT