@jaralabs/codex-bridge 0.2.0 → 0.4.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/lib/auth.mjs +79 -0
- package/lib/capabilities.mjs +183 -0
- package/lib/plugin.ts +122 -23
- package/lib/resilience.mjs +182 -0
- package/lib/server.mjs +379 -208
- package/lib/tools-registry.mjs +57 -0
- package/package.json +11 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// tools-registry: tracks the list of MCP tools available to the bridge.
|
|
2
|
+
//
|
|
3
|
+
// In a normal ChatGPT Plus setup, the model "knows" about its tools via a
|
|
4
|
+
// system prompt that lists them. OpenCode does NOT inject the live MCP
|
|
5
|
+
// catalog into /v1/chat/completions (it only sends `tools` when the AI SDK
|
|
6
|
+
// explicitly enabled tool calling on the provider). To make the bridge feel
|
|
7
|
+
// like Plus, we maintain a small registry that the OpenCode plugin can
|
|
8
|
+
// populate via /v1/tools, and that handleChatCompletions injects into the
|
|
9
|
+
// system prompt when the model has no other source of tool awareness.
|
|
10
|
+
//
|
|
11
|
+
// The registry is in-memory and process-local. A real deployment would
|
|
12
|
+
// persist this to ~/.codex/tools_cache.json, but the bridge process is
|
|
13
|
+
// short-lived enough (one process per TUI session is overkill; the TUI
|
|
14
|
+
// restarts re-register via the plugin) that the in-memory map is fine.
|
|
15
|
+
|
|
16
|
+
const tools = new Map(); // name -> { server, description, parameters, serverType, command?, url? }
|
|
17
|
+
|
|
18
|
+
export function registerTool(name, meta) {
|
|
19
|
+
if (!name) return;
|
|
20
|
+
tools.set(name, {
|
|
21
|
+
server: meta.server || "unknown",
|
|
22
|
+
description: meta.description || "",
|
|
23
|
+
parameters: meta.parameters || { type: "object", properties: {} },
|
|
24
|
+
serverType: meta.serverType || "local",
|
|
25
|
+
command: meta.command,
|
|
26
|
+
url: meta.url,
|
|
27
|
+
registeredAt: Date.now(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function registerTools(list) {
|
|
32
|
+
if (!Array.isArray(list)) return;
|
|
33
|
+
for (const t of list) {
|
|
34
|
+
if (t?.name) registerTool(t.name, t);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function listTools() {
|
|
39
|
+
return Array.from(tools.entries()).map(([name, meta]) => ({ name, ...meta }));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function clearTools() {
|
|
43
|
+
tools.clear();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Render the registry as a system-prompt block. We use a compact format
|
|
47
|
+
// the model can parse: each tool on its own line with a JSON schema.
|
|
48
|
+
export function renderToolsSystemBlock() {
|
|
49
|
+
if (tools.size === 0) return "";
|
|
50
|
+
const lines = ["You have access to the following tools. To call one, emit a tool_call with the matching name and JSON arguments."];
|
|
51
|
+
for (const [name, meta] of tools.entries()) {
|
|
52
|
+
const params = JSON.stringify(meta.parameters || { type: "object" });
|
|
53
|
+
const desc = meta.description ? ` — ${meta.description}` : "";
|
|
54
|
+
lines.push(`- ${name}${desc} args=${params}`);
|
|
55
|
+
}
|
|
56
|
+
return lines.join("\n");
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaralabs/codex-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "OpenAI-compatible HTTP bridge that reuses a local ChatGPT Business / Team / Plus session via codex, so OpenCode can list and call those models without paying for the OpenAI API.",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"start": "bin/codex-bridge start",
|
|
@@ -32,7 +32,10 @@
|
|
|
32
32
|
"status": "bin/codex-bridge status",
|
|
33
33
|
"sync": "bin/codex-bridge sync",
|
|
34
34
|
"logs": "bin/codex-bridge logs",
|
|
35
|
-
"test": "node test/test.mjs"
|
|
35
|
+
"test": "node test/test.mjs",
|
|
36
|
+
"test:tools": "node test/test-tools.mjs",
|
|
37
|
+
"test:resilience": "node test/test-resilience.mjs",
|
|
38
|
+
"test:smoke": "node test/smoke.mjs"
|
|
36
39
|
},
|
|
37
40
|
"repository": {
|
|
38
41
|
"type": "git",
|
|
@@ -51,5 +54,9 @@
|
|
|
51
54
|
"coding-agent"
|
|
52
55
|
],
|
|
53
56
|
"author": "Andrew Jaramillo <javamillog1999@outlook.com>",
|
|
54
|
-
"license": "MIT"
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "^26.6.5",
|
|
60
|
+
"typescript": "^7.0.2"
|
|
61
|
+
}
|
|
55
62
|
}
|