@chatpanel/bridge 0.1.0 → 0.1.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.
- package/README.md +29 -4
- package/package.json +3 -3
- package/src/engines/claude.js +14 -16
- package/src/engines/codex.js +1 -9
- package/src/engines/gemini.js +102 -0
- package/src/server.js +6 -4
package/README.md
CHANGED
|
@@ -7,22 +7,47 @@ so this bridges the gap.
|
|
|
7
7
|
- **Claude Code** — embedded via `@anthropic-ai/claude-agent-sdk`, using your
|
|
8
8
|
existing Claude Code login (or `ANTHROPIC_API_KEY`).
|
|
9
9
|
- **Codex** — driven via the `codex exec` CLI, using your `codex login`.
|
|
10
|
+
- **Gemini CLI** — driven via the `gemini -p` CLI, using your `gemini` login.
|
|
11
|
+
|
|
12
|
+
Bring whichever agent you already have installed — the extension auto-detects
|
|
13
|
+
the ones the bridge reports as available.
|
|
10
14
|
|
|
11
15
|
## Run it
|
|
12
16
|
|
|
17
|
+
**No clone, no install** — `npx` fetches the package (and its one dependency) and
|
|
18
|
+
starts the server:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx @chatpanel/bridge # → http://127.0.0.1:4319
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
…then leave it running and open the ChatPanel side panel. That's the whole setup.
|
|
25
|
+
|
|
26
|
+
Prefer a persistent command? Install it globally:
|
|
27
|
+
|
|
13
28
|
```bash
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
npm start # → http://127.0.0.1:4319
|
|
29
|
+
npm i -g @chatpanel/bridge
|
|
30
|
+
chatpanel-bridge # → http://127.0.0.1:4319
|
|
17
31
|
```
|
|
18
32
|
|
|
19
|
-
Prerequisites:
|
|
33
|
+
Prerequisites (the agents you want to use must already be set up):
|
|
20
34
|
|
|
21
35
|
- **Claude Code**: be signed in (`claude`) or set `ANTHROPIC_API_KEY`.
|
|
22
36
|
- **Codex**: `codex` on your `PATH` and `codex login` done.
|
|
23
37
|
|
|
24
38
|
The extension polls `/health` and shows each agent as available/unavailable.
|
|
25
39
|
|
|
40
|
+
## Develop (from source)
|
|
41
|
+
|
|
42
|
+
Only if you're hacking on the bridge itself:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/chatpanel/chatpanel-bridge
|
|
46
|
+
cd chatpanel-bridge
|
|
47
|
+
npm install
|
|
48
|
+
npm start # → http://127.0.0.1:4319
|
|
49
|
+
```
|
|
50
|
+
|
|
26
51
|
## API
|
|
27
52
|
|
|
28
53
|
| Method | Path | Purpose |
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/bridge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Local bridge that exposes Claude Code (Agent SDK)
|
|
6
|
-
"keywords": ["chatpanel", "claude-code", "codex", "chrome-extension", "ai-agents", "bridge"],
|
|
5
|
+
"description": "Local bridge that exposes the AI coding agents installed on your machine — Claude Code (Agent SDK), Codex (CLI), and Gemini CLI — to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
|
|
6
|
+
"keywords": ["chatpanel", "claude-code", "codex", "gemini-cli", "chrome-extension", "ai-agents", "bridge"],
|
|
7
7
|
"homepage": "https://chatpanel.net",
|
|
8
8
|
"repository": { "type": "git", "url": "git+https://github.com/chatpanel/chatpanel-bridge.git" },
|
|
9
9
|
"license": "MIT",
|
package/src/engines/claude.js
CHANGED
|
@@ -10,14 +10,6 @@
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import os from 'node:os';
|
|
12
12
|
|
|
13
|
-
// Always-on guidance so the coding agent behaves like a browser assistant by
|
|
14
|
-
// default: prefer the page context the extension attaches over scanning files.
|
|
15
|
-
const BASE_GUIDANCE =
|
|
16
|
-
'You are ChatPanel, an AI assistant living in a browser side panel. When the ' +
|
|
17
|
-
"user's message includes <context> blocks (extracted web pages or selections), " +
|
|
18
|
-
'answer primarily from those. Only read or modify local files when the user ' +
|
|
19
|
-
'explicitly asks about code or a project.';
|
|
20
|
-
|
|
21
13
|
let sdkPromise = null;
|
|
22
14
|
function loadSdk() {
|
|
23
15
|
if (!sdkPromise) sdkPromise = import('@anthropic-ai/claude-agent-sdk').catch(() => null);
|
|
@@ -86,11 +78,12 @@ export async function chat({ messages, system, options }, emit) {
|
|
|
86
78
|
// servers and CLAUDE.md apply. Turn the agent's "Use my local skills &
|
|
87
79
|
// config" off to run clean.
|
|
88
80
|
settingSources: options.useLocalConfig === false ? [] : ['user', 'project'],
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
// Native Claude Code system prompt. Only append the user's OWN system
|
|
82
|
+
// prompt if they set one — no ChatPanel persona is injected, so the agent
|
|
83
|
+
// is exactly as capable as it is in the terminal.
|
|
84
|
+
systemPrompt: system
|
|
85
|
+
? { type: 'preset', preset: 'claude_code', append: system }
|
|
86
|
+
: { type: 'preset', preset: 'claude_code' },
|
|
94
87
|
...(options.model ? { model: options.model } : {}),
|
|
95
88
|
...(process.env.CHATPANEL_MAX_TURNS ? { maxTurns: Number(process.env.CHATPANEL_MAX_TURNS) } : {}),
|
|
96
89
|
},
|
|
@@ -99,9 +92,14 @@ export async function chat({ messages, system, options }, emit) {
|
|
|
99
92
|
for await (const message of iterator) {
|
|
100
93
|
if (message.type === 'stream_event') {
|
|
101
94
|
const ev = message.event;
|
|
102
|
-
if (ev?.type === 'content_block_delta'
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
if (ev?.type === 'content_block_delta') {
|
|
96
|
+
if (ev.delta?.type === 'text_delta') {
|
|
97
|
+
streamedAny = true;
|
|
98
|
+
emit({ type: 'delta', text: ev.delta.text });
|
|
99
|
+
} else if (ev.delta?.type === 'thinking_delta') {
|
|
100
|
+
// Extended thinking — stream the reasoning text to the panel.
|
|
101
|
+
emit({ type: 'reasoning', text: ev.delta.thinking || '' });
|
|
102
|
+
}
|
|
105
103
|
}
|
|
106
104
|
} else if (message.type === 'assistant') {
|
|
107
105
|
for (const block of message.message.content) {
|
package/src/engines/codex.js
CHANGED
|
@@ -58,14 +58,6 @@ function ensureIsolatedHome() {
|
|
|
58
58
|
return ISO_HOME;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const BASE_GUIDANCE =
|
|
62
|
-
'You are ChatPanel, an AI assistant in a browser side panel. Answer the ' +
|
|
63
|
-
"user's question using the <context> blocks provided (web pages or selections). " +
|
|
64
|
-
'Do NOT search the filesystem or read local files for general questions — ' +
|
|
65
|
-
'everything you need is in the prompt. Only inspect files if the user explicitly ' +
|
|
66
|
-
'asks about local code or a project. When asked for a table, return GitHub-' +
|
|
67
|
-
'flavored Markdown.';
|
|
68
|
-
|
|
69
61
|
let installed = null;
|
|
70
62
|
export async function available() {
|
|
71
63
|
if (installed === null) {
|
|
@@ -82,7 +74,7 @@ export async function available() {
|
|
|
82
74
|
}
|
|
83
75
|
|
|
84
76
|
function buildPrompt(messages, system) {
|
|
85
|
-
let p = `${
|
|
77
|
+
let p = system ? `${system}\n\n` : '';
|
|
86
78
|
const history = messages.slice(0, -1);
|
|
87
79
|
const last = messages[messages.length - 1];
|
|
88
80
|
if (history.length) {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Gemini engine — drives the Gemini CLI (`gemini -p`) using your local login.
|
|
2
|
+
//
|
|
3
|
+
// Like the Codex engine, this shells out to the installed `gemini` binary in
|
|
4
|
+
// non-interactive mode: `gemini -p "<prompt>"` runs once, prints the answer to
|
|
5
|
+
// stdout, and exits. We run in an empty scratch dir for general chat so Gemini
|
|
6
|
+
// never crawls the bridge's own files; set a working dir on the agent to point
|
|
7
|
+
// it at a real project.
|
|
8
|
+
//
|
|
9
|
+
// Install: `npm i -g @google/gemini-cli`, then run `gemini` once to sign in.
|
|
10
|
+
|
|
11
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
12
|
+
import { mkdirSync } from 'node:fs';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
|
|
16
|
+
const TIMEOUT_MS = Number(process.env.CHATPANEL_GEMINI_TIMEOUT_MS) || 180_000;
|
|
17
|
+
const SCRATCH = path.join(os.tmpdir(), 'chatpanel-gemini-scratch');
|
|
18
|
+
|
|
19
|
+
let installed = null;
|
|
20
|
+
export async function available() {
|
|
21
|
+
if (installed === null) {
|
|
22
|
+
try {
|
|
23
|
+
const r = spawnSync('gemini', ['--version'], { stdio: 'ignore', timeout: 5000 });
|
|
24
|
+
installed = r.status === 0 || (r.status === null && r.error === undefined);
|
|
25
|
+
} catch {
|
|
26
|
+
installed = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return installed
|
|
30
|
+
? { ok: true }
|
|
31
|
+
: { ok: false, reason: 'gemini not found on PATH. Install @google/gemini-cli, then run `gemini` once to sign in.' };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function buildPrompt(messages, system) {
|
|
35
|
+
let p = system ? `${system}\n\n` : '';
|
|
36
|
+
const history = messages.slice(0, -1);
|
|
37
|
+
const last = messages[messages.length - 1];
|
|
38
|
+
if (history.length) {
|
|
39
|
+
p += 'Conversation so far:\n';
|
|
40
|
+
for (const m of history) p += `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content}\n\n`;
|
|
41
|
+
p += '---\n\n';
|
|
42
|
+
}
|
|
43
|
+
p += last ? last.content : '';
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function chat({ messages, system, options }, emit) {
|
|
48
|
+
try {
|
|
49
|
+
mkdirSync(SCRATCH, { recursive: true });
|
|
50
|
+
} catch {
|
|
51
|
+
/* best effort */
|
|
52
|
+
}
|
|
53
|
+
const cwd = options.workingDir ? path.resolve(options.workingDir) : SCRATCH;
|
|
54
|
+
|
|
55
|
+
// `-p` is non-interactive (no TTY prompts). `-m` picks the model. `-y` (yolo)
|
|
56
|
+
// auto-approves tool calls when the user opted into bypassPermissions — without
|
|
57
|
+
// it Gemini would block on an approval it can't show in a headless run.
|
|
58
|
+
const args = ['-p', buildPrompt(messages, system)];
|
|
59
|
+
if (options.model) args.push('-m', options.model);
|
|
60
|
+
if (options.permissionMode === 'bypassPermissions') args.push('-y');
|
|
61
|
+
|
|
62
|
+
await new Promise((resolve, reject) => {
|
|
63
|
+
let child;
|
|
64
|
+
try {
|
|
65
|
+
// stdin ignored: the prompt is passed via -p, and no TTY means no
|
|
66
|
+
// interactive "trust this folder?" dialog can block us.
|
|
67
|
+
child = spawn('gemini', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env } });
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return reject(new Error(`Failed to start gemini: ${e.message}`));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let out = '';
|
|
73
|
+
let err = '';
|
|
74
|
+
let streamed = false;
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
child.kill('SIGKILL');
|
|
77
|
+
reject(new Error(`Gemini timed out after ${Math.round(TIMEOUT_MS / 1000)}s.`));
|
|
78
|
+
}, TIMEOUT_MS);
|
|
79
|
+
|
|
80
|
+
child.stdout.on('data', (d) => {
|
|
81
|
+
const s = d.toString();
|
|
82
|
+
out += s;
|
|
83
|
+
streamed = true;
|
|
84
|
+
emit({ type: 'delta', text: s });
|
|
85
|
+
});
|
|
86
|
+
child.stderr.on('data', (d) => (err += d.toString()));
|
|
87
|
+
child.on('error', (e) => {
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
reject(new Error(`Failed to start gemini: ${e.message}`));
|
|
90
|
+
});
|
|
91
|
+
child.on('close', (code) => {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
if (code === 0) {
|
|
94
|
+
if (!streamed) emit({ type: 'delta', text: out.trim() || '(no output)' });
|
|
95
|
+
emit({ type: 'done', text: '' });
|
|
96
|
+
resolve();
|
|
97
|
+
} else {
|
|
98
|
+
reject(new Error(`Gemini exited ${code}: ${err.trim() || out.trim() || 'failed'}`));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
package/src/server.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// ChatPanel Bridge — a tiny localhost server that exposes the coding agents
|
|
3
|
-
// running on this machine (Claude Code via the Agent SDK, Codex
|
|
4
|
-
// the ChatPanel Chrome extension. Zero runtime dependencies
|
|
5
|
-
// Claude Agent SDK.
|
|
3
|
+
// running on this machine (Claude Code via the Agent SDK, Codex and Gemini via
|
|
4
|
+
// their CLIs) to the ChatPanel Chrome extension. Zero runtime dependencies
|
|
5
|
+
// beyond the optional Claude Agent SDK.
|
|
6
6
|
//
|
|
7
7
|
// GET /health → { ok, version, agents: [{id,label,available,reason}] }
|
|
8
8
|
// POST /chat → Server-Sent Events stream of { type, ... }:
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { createServer } from 'node:http';
|
|
18
18
|
import * as claude from './engines/claude.js';
|
|
19
19
|
import * as codex from './engines/codex.js';
|
|
20
|
+
import * as gemini from './engines/gemini.js';
|
|
20
21
|
|
|
21
22
|
const VERSION = '0.1.0';
|
|
22
23
|
const HOST = process.env.CHATPANEL_BRIDGE_HOST || '127.0.0.1';
|
|
@@ -25,6 +26,7 @@ const PORT = Number(process.env.CHATPANEL_BRIDGE_PORT) || 4319;
|
|
|
25
26
|
const ENGINES = {
|
|
26
27
|
claude: { engine: claude, label: 'Claude Code' },
|
|
27
28
|
codex: { engine: codex, label: 'Codex' },
|
|
29
|
+
gemini: { engine: gemini, label: 'Gemini CLI' },
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
// --------------------------------------------------------------------------
|
|
@@ -149,5 +151,5 @@ server.listen(PORT, HOST, async () => {
|
|
|
149
151
|
const a = await engine.available().catch(() => ({ ok: false }));
|
|
150
152
|
log('info', ` ${a.ok ? '✓' : '✕'} ${label}${a.ok ? '' : ' — ' + (a.reason || 'unavailable')}`);
|
|
151
153
|
}
|
|
152
|
-
log('info', 'Open the ChatPanel side panel; Claude Code
|
|
154
|
+
log('info', 'Open the ChatPanel side panel; installed agents (Claude Code, Codex, Gemini CLI) appear automatically.');
|
|
153
155
|
});
|