@chatpanel/bridge 0.2.0 → 0.2.1
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/package.json +1 -1
- package/src/engines/claude.js +32 -0
- package/src/server.js +42 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/bridge",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
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
6
|
"keywords": [
|
package/src/engines/claude.js
CHANGED
|
@@ -122,6 +122,38 @@ export async function chat({ messages, system, options }, emit) {
|
|
|
122
122
|
emit({ type: 'done', text: streamedAny ? '' : resultText });
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
// A fast, tool-free single-shot completion — used for prompt autocomplete. No
|
|
126
|
+
// claude_code preset, no tools, no local config: just a quick text continuation
|
|
127
|
+
// from a fast model (Haiku by default). Returns the completion string.
|
|
128
|
+
export async function complete({ prompt, system, model }) {
|
|
129
|
+
const sdk = await loadSdk();
|
|
130
|
+
if (!sdk) throw new Error('Claude Agent SDK not installed.');
|
|
131
|
+
const { query } = sdk;
|
|
132
|
+
let text = '';
|
|
133
|
+
const iterator = query({
|
|
134
|
+
prompt,
|
|
135
|
+
options: {
|
|
136
|
+
cwd: os.homedir(),
|
|
137
|
+
permissionMode: 'default',
|
|
138
|
+
allowedTools: [], // no tools — pure text completion
|
|
139
|
+
maxTurns: 1,
|
|
140
|
+
settingSources: [], // skip CLAUDE.md / MCP for a tiny completion
|
|
141
|
+
systemPrompt: system || "Continue the user's text briefly. Reply with only the continuation.",
|
|
142
|
+
model: model || 'haiku',
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
for await (const message of iterator) {
|
|
146
|
+
if (message.type === 'assistant') {
|
|
147
|
+
for (const block of message.message.content) {
|
|
148
|
+
if (block.type === 'text') text += block.text;
|
|
149
|
+
}
|
|
150
|
+
} else if (message.type === 'result' && message.subtype === 'success' && !text) {
|
|
151
|
+
text = message.result || '';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return text.trim();
|
|
155
|
+
}
|
|
156
|
+
|
|
125
157
|
function toolSummary(block) {
|
|
126
158
|
const i = block.input || {};
|
|
127
159
|
if (i.command) return String(i.command).slice(0, 60);
|
package/src/server.js
CHANGED
|
@@ -20,7 +20,7 @@ import * as codex from './engines/codex.js';
|
|
|
20
20
|
import * as gemini from './engines/gemini.js';
|
|
21
21
|
import { installService, uninstallService, serviceStatus } from './service.js';
|
|
22
22
|
|
|
23
|
-
const VERSION = '0.2.
|
|
23
|
+
const VERSION = '0.2.1';
|
|
24
24
|
const HOST = process.env.CHATPANEL_BRIDGE_HOST || '127.0.0.1';
|
|
25
25
|
const PORT = Number(process.env.CHATPANEL_BRIDGE_PORT) || 4319;
|
|
26
26
|
|
|
@@ -125,6 +125,46 @@ async function handleChat(req, res) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
// POST /complete → { agent, prompt, model? } → { text } — a fast, single-shot
|
|
129
|
+
// completion for prompt autocomplete. Uses the engine's complete() if it has one
|
|
130
|
+
// (Claude: Haiku, no tools), else a one-shot chat collected into text.
|
|
131
|
+
async function handleComplete(req, res) {
|
|
132
|
+
let body;
|
|
133
|
+
try {
|
|
134
|
+
body = await readBody(req);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return json(res, 400, { error: 'Bad JSON: ' + e.message });
|
|
137
|
+
}
|
|
138
|
+
const target = ENGINES[body.agent];
|
|
139
|
+
if (!target) return json(res, 404, { error: `Unknown agent "${body.agent}"` });
|
|
140
|
+
const prompt = String(body.prompt || '').slice(0, 6000);
|
|
141
|
+
if (!prompt) return json(res, 400, { error: 'Empty prompt' });
|
|
142
|
+
const model = body.model || '';
|
|
143
|
+
// The extension sends a strict "continue, don't answer" system prompt (with any
|
|
144
|
+
// page context already in `prompt`); fall back to a sensible default.
|
|
145
|
+
const system =
|
|
146
|
+
String(body.system || '').slice(0, 2000) ||
|
|
147
|
+
'You autocomplete an unfinished message the user is typing. Output ONLY the ' +
|
|
148
|
+
'few words that come next. Do not answer it. No quotes, no repetition.';
|
|
149
|
+
try {
|
|
150
|
+
let text = '';
|
|
151
|
+
if (typeof target.engine.complete === 'function') {
|
|
152
|
+
text = await target.engine.complete({ prompt, system, model });
|
|
153
|
+
} else {
|
|
154
|
+
await target.engine.chat(
|
|
155
|
+
{ messages: [{ role: 'user', content: prompt }], system, options: { model } },
|
|
156
|
+
(obj) => {
|
|
157
|
+
if (obj.type === 'delta') text += obj.text || '';
|
|
158
|
+
else if (obj.type === 'done' && obj.text) text += obj.text;
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return json(res, 200, { text: (text || '').trim() });
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return json(res, 502, { error: e?.message || String(e) });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
128
168
|
const server = createServer(async (req, res) => {
|
|
129
169
|
cors(req, res);
|
|
130
170
|
if (req.method === 'OPTIONS') {
|
|
@@ -135,6 +175,7 @@ const server = createServer(async (req, res) => {
|
|
|
135
175
|
try {
|
|
136
176
|
if (req.method === 'GET' && url.pathname === '/health') return handleHealth(res);
|
|
137
177
|
if (req.method === 'POST' && url.pathname === '/chat') return handleChat(req, res);
|
|
178
|
+
if (req.method === 'POST' && url.pathname === '/complete') return handleComplete(req, res);
|
|
138
179
|
json(res, 404, { error: 'Not found' });
|
|
139
180
|
} catch (e) {
|
|
140
181
|
json(res, 500, { error: e?.message || String(e) });
|