@emqo/claudebridge 0.1.3 → 0.1.5
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/config.yaml.example +7 -5
- package/dist/cli.js +4 -3
- package/dist/core/agent.js +11 -5
- package/dist/core/keys.js +0 -2
- package/package.json +1 -1
package/config.yaml.example
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
endpoints
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
# Leave endpoints empty to use claude CLI's own authentication
|
|
2
|
+
# 留空则直接使用 claude CLI 自身的认证配置
|
|
3
|
+
endpoints: []
|
|
4
|
+
# - name: "default"
|
|
5
|
+
# base_url: ""
|
|
6
|
+
# api_key: "sk-your-api-key"
|
|
7
|
+
# model: "claude-sonnet-4-20250514"
|
|
6
8
|
|
|
7
9
|
locale: en # "zh" for Chinese
|
|
8
10
|
|
package/dist/cli.js
CHANGED
|
@@ -29,13 +29,14 @@ function removePid() { try {
|
|
|
29
29
|
catch { } }
|
|
30
30
|
const args = process.argv.slice(2);
|
|
31
31
|
if (args.includes("--help") || args.includes("-h")) {
|
|
32
|
-
console.log("Usage: claudebridge <start|stop|status|reload|init> [--config path] [--
|
|
32
|
+
console.log("Usage: claudebridge <start|stop|status|reload|init> [--config path] [--foreground|-f]");
|
|
33
33
|
process.exit(0);
|
|
34
34
|
}
|
|
35
35
|
const cmd = args.find(a => !a.startsWith("-")) || "start";
|
|
36
36
|
const cfgIdx = args.indexOf("--config");
|
|
37
37
|
const cfgPath = cfgIdx !== -1 ? args[cfgIdx + 1] : undefined;
|
|
38
38
|
const daemon = args.includes("--daemon") || args.includes("-d");
|
|
39
|
+
const foreground = args.includes("--foreground") || args.includes("-f");
|
|
39
40
|
const DEFAULT_CFG = join(DIR, "config.yaml");
|
|
40
41
|
switch (cmd) {
|
|
41
42
|
case "start": {
|
|
@@ -46,7 +47,7 @@ switch (cmd) {
|
|
|
46
47
|
}
|
|
47
48
|
const resolvedCfg = cfgPath || DEFAULT_CFG;
|
|
48
49
|
const childArgs = [ENTRY, "--config", resolvedCfg];
|
|
49
|
-
if (
|
|
50
|
+
if (!foreground) {
|
|
50
51
|
ensureDir();
|
|
51
52
|
const { openSync } = await import("fs");
|
|
52
53
|
const logFd = openSync(LOG_FILE, "a");
|
|
@@ -114,6 +115,6 @@ switch (cmd) {
|
|
|
114
115
|
break;
|
|
115
116
|
}
|
|
116
117
|
default:
|
|
117
|
-
console.log("Usage: claudebridge <start|stop|status|reload|init> [--config path] [--
|
|
118
|
+
console.log("Usage: claudebridge <start|stop|status|reload|init> [--config path] [--foreground|-f]");
|
|
118
119
|
process.exit(1);
|
|
119
120
|
}
|
package/dist/core/agent.js
CHANGED
|
@@ -63,10 +63,12 @@ export class AgentEngine {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
async _executeWithRetry(userId, prompt, platform, onChunk, memoryPrompt) {
|
|
66
|
-
const maxRetries = Math.min(this.rotator.count, 3);
|
|
66
|
+
const maxRetries = Math.max(Math.min(this.rotator.count, 3), 1);
|
|
67
67
|
let lastErr;
|
|
68
68
|
for (let i = 0; i < maxRetries; i++) {
|
|
69
|
-
const ep = this.rotator.
|
|
69
|
+
const ep = this.rotator.count
|
|
70
|
+
? this.rotator.next()
|
|
71
|
+
: { name: "cli-default", api_key: "", base_url: "", model: "" };
|
|
70
72
|
try {
|
|
71
73
|
return await this._execute(userId, prompt, platform, ep, onChunk, memoryPrompt);
|
|
72
74
|
}
|
|
@@ -103,7 +105,8 @@ export class AgentEngine {
|
|
|
103
105
|
if (this.config.agent.max_budget_usd)
|
|
104
106
|
args.push("--max-budget-usd", String(this.config.agent.max_budget_usd));
|
|
105
107
|
const env = { ...process.env };
|
|
106
|
-
|
|
108
|
+
if (ep.api_key)
|
|
109
|
+
env.ANTHROPIC_API_KEY = ep.api_key;
|
|
107
110
|
if (ep.base_url)
|
|
108
111
|
env.ANTHROPIC_BASE_URL = ep.base_url;
|
|
109
112
|
const child = spawn("claude", args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
@@ -179,9 +182,12 @@ export class AgentEngine {
|
|
|
179
182
|
});
|
|
180
183
|
}
|
|
181
184
|
_autoSummarize(userId, prompt, response) {
|
|
182
|
-
const ep = this.rotator.
|
|
185
|
+
const ep = this.rotator.count
|
|
186
|
+
? this.rotator.next()
|
|
187
|
+
: { name: "cli-default", api_key: "", base_url: "", model: "" };
|
|
183
188
|
const env = { ...process.env };
|
|
184
|
-
|
|
189
|
+
if (ep.api_key)
|
|
190
|
+
env.ANTHROPIC_API_KEY = ep.api_key;
|
|
185
191
|
if (ep.base_url)
|
|
186
192
|
env.ANTHROPIC_BASE_URL = ep.base_url;
|
|
187
193
|
const summaryPrompt = `Extract 1-3 key facts worth remembering about the user from this exchange. Output only bullet points, no preamble. If nothing worth remembering, output "NONE".\n\nUser: ${prompt.slice(0, 500)}\nAssistant: ${response.slice(0, 1000)}`;
|
package/dist/core/keys.js
CHANGED