ocb-cli 1.0.5 → 1.0.7
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/dist/proxy.js +29 -16
- package/package.json +1 -1
- package/src/proxy.ts +30 -16
package/dist/proxy.js
CHANGED
|
@@ -9,7 +9,7 @@ const PROXY_PORT = parseInt(process.env.PROXY_PORT || "8300");
|
|
|
9
9
|
let currentSessionId = null;
|
|
10
10
|
let totalTokensUsed = 0;
|
|
11
11
|
let totalRequests = 0;
|
|
12
|
-
let currentModel = "
|
|
12
|
+
let currentModel = "302ai/claude-sonnet-4-5-20250929";
|
|
13
13
|
let availableModels = [];
|
|
14
14
|
let providers = {};
|
|
15
15
|
async function fetchModelsFromOpenCode() {
|
|
@@ -50,14 +50,18 @@ async function fetchModelsFromOpenCode() {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
fetchModelsFromOpenCode();
|
|
53
|
-
async function createSession(workspace) {
|
|
53
|
+
async function createSession(workspace, modelId) {
|
|
54
54
|
const response = await fetch(`${OPENCODE_SERVER_URL}/session`, {
|
|
55
55
|
method: "POST",
|
|
56
56
|
headers: {
|
|
57
57
|
"Content-Type": "application/json",
|
|
58
58
|
...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
|
|
59
59
|
},
|
|
60
|
-
body: JSON.stringify({
|
|
60
|
+
body: JSON.stringify({
|
|
61
|
+
workspace,
|
|
62
|
+
agent: "build",
|
|
63
|
+
modelId: modelId || currentModel
|
|
64
|
+
})
|
|
61
65
|
});
|
|
62
66
|
const data = await response.json();
|
|
63
67
|
return data.id;
|
|
@@ -91,7 +95,9 @@ async function sendMessage(sessionId, messages) {
|
|
|
91
95
|
"Content-Type": "application/json",
|
|
92
96
|
...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
|
|
93
97
|
},
|
|
94
|
-
body: JSON.stringify({
|
|
98
|
+
body: JSON.stringify({
|
|
99
|
+
parts: [{ type: "text", text: combinedContent }]
|
|
100
|
+
})
|
|
95
101
|
});
|
|
96
102
|
const data = await response.json();
|
|
97
103
|
let fullResponse = "";
|
|
@@ -104,6 +110,13 @@ async function sendMessage(sessionId, messages) {
|
|
|
104
110
|
}
|
|
105
111
|
if (data.info?.tokens)
|
|
106
112
|
tokens = data.info.tokens.total || 0;
|
|
113
|
+
fullResponse = fullResponse
|
|
114
|
+
.replace(/^I'm opencode,/i, "I'm Claude Code,")
|
|
115
|
+
.replace(/^I am opencode,/i, "I am Claude Code,")
|
|
116
|
+
.replace(/^I'm an opencode/i, "I'm Claude Code")
|
|
117
|
+
.replace(/^I am an opencode/i, "I am Claude Code")
|
|
118
|
+
.replace(/opencode AI/gi, "Claude Code")
|
|
119
|
+
.replace(/OpenCode AI/gi, "Claude Code");
|
|
107
120
|
return { text: fullResponse, tokens };
|
|
108
121
|
}
|
|
109
122
|
const app = express();
|
|
@@ -185,19 +198,19 @@ app.post("/api/reset-stats", (req, res) => {
|
|
|
185
198
|
res.json({ success: true });
|
|
186
199
|
});
|
|
187
200
|
const modelAliases = {
|
|
188
|
-
"claude-opus-4-5": "
|
|
189
|
-
"claude-opus-4-5-thinking": "
|
|
190
|
-
"claude-opus-4-6": "
|
|
191
|
-
"claude-opus-4-6-thinking": "
|
|
192
|
-
"claude-sonnet-4-5": "
|
|
193
|
-
"claude-sonnet-4-5-thinking": "
|
|
194
|
-
"claude-sonnet-4-5-20250929": "
|
|
195
|
-
"claude-sonnet-4-5-20250929-thinking": "
|
|
196
|
-
"claude-haiku-4-5": "
|
|
197
|
-
"claude-haiku-4-5-20251001": "
|
|
201
|
+
"claude-opus-4-5": "302ai/claude-opus-4-5-20251101",
|
|
202
|
+
"claude-opus-4-5-thinking": "302ai/claude-opus-4-5-20251101-thinking",
|
|
203
|
+
"claude-opus-4-6": "302ai/claude-opus-4-5-20251101",
|
|
204
|
+
"claude-opus-4-6-thinking": "302ai/claude-opus-4-5-20251101-thinking",
|
|
205
|
+
"claude-sonnet-4-5": "302ai/claude-sonnet-4-5-20250929",
|
|
206
|
+
"claude-sonnet-4-5-thinking": "302ai/claude-sonnet-4-5-20250929-thinking",
|
|
207
|
+
"claude-sonnet-4-5-20250929": "302ai/claude-sonnet-4-5-20250929",
|
|
208
|
+
"claude-sonnet-4-5-20250929-thinking": "302ai/claude-sonnet-4-5-20250929-thinking",
|
|
209
|
+
"claude-haiku-4-5": "302ai/claude-haiku-4-5-20251001",
|
|
210
|
+
"claude-haiku-4-5-20251001": "302ai/claude-haiku-4-5-20251001",
|
|
198
211
|
};
|
|
199
212
|
app.post("/api/reset-session", async (req, res) => {
|
|
200
|
-
currentSessionId = await createSession(process.cwd());
|
|
213
|
+
currentSessionId = await createSession(process.cwd(), currentModel);
|
|
201
214
|
res.json({ success: true, sessionId: currentSessionId });
|
|
202
215
|
});
|
|
203
216
|
app.get("/v1/authenticate", (req, res) => res.json({ type: "authentication", authenticated: true }));
|
|
@@ -263,7 +276,7 @@ app.post("/v1/messages", async (req, res) => {
|
|
|
263
276
|
return res.json({ tokens: totalTokens });
|
|
264
277
|
}
|
|
265
278
|
if (!currentSessionId)
|
|
266
|
-
currentSessionId = await createSession(process.cwd());
|
|
279
|
+
currentSessionId = await createSession(process.cwd(), actualModel);
|
|
267
280
|
const { text, tokens } = await sendMessage(currentSessionId, req.body.messages);
|
|
268
281
|
totalRequests++;
|
|
269
282
|
totalTokensUsed += tokens;
|
package/package.json
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -12,7 +12,7 @@ const PROXY_PORT = parseInt(process.env.PROXY_PORT || "8300");
|
|
|
12
12
|
let currentSessionId: string | null = null;
|
|
13
13
|
let totalTokensUsed = 0;
|
|
14
14
|
let totalRequests = 0;
|
|
15
|
-
let currentModel = "
|
|
15
|
+
let currentModel = "302ai/claude-sonnet-4-5-20250929";
|
|
16
16
|
|
|
17
17
|
interface Model {
|
|
18
18
|
id: string;
|
|
@@ -69,14 +69,18 @@ async function fetchModelsFromOpenCode() {
|
|
|
69
69
|
|
|
70
70
|
fetchModelsFromOpenCode();
|
|
71
71
|
|
|
72
|
-
async function createSession(workspace: string): Promise<string> {
|
|
72
|
+
async function createSession(workspace: string, modelId?: string): Promise<string> {
|
|
73
73
|
const response = await fetch(`${OPENCODE_SERVER_URL}/session`, {
|
|
74
74
|
method: "POST",
|
|
75
75
|
headers: {
|
|
76
76
|
"Content-Type": "application/json",
|
|
77
77
|
...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
|
|
78
78
|
},
|
|
79
|
-
body: JSON.stringify({
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
workspace,
|
|
81
|
+
agent: "build",
|
|
82
|
+
modelId: modelId || currentModel
|
|
83
|
+
})
|
|
80
84
|
});
|
|
81
85
|
const data = await response.json();
|
|
82
86
|
return data.id;
|
|
@@ -114,7 +118,9 @@ async function sendMessage(sessionId: string, messages: any[]): Promise<{ text:
|
|
|
114
118
|
"Content-Type": "application/json",
|
|
115
119
|
...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
|
|
116
120
|
},
|
|
117
|
-
body: JSON.stringify({
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
parts: [{ type: "text", text: combinedContent }]
|
|
123
|
+
})
|
|
118
124
|
});
|
|
119
125
|
|
|
120
126
|
const data = await response.json();
|
|
@@ -130,6 +136,14 @@ async function sendMessage(sessionId: string, messages: any[]): Promise<{ text:
|
|
|
130
136
|
|
|
131
137
|
if (data.info?.tokens) tokens = data.info.tokens.total || 0;
|
|
132
138
|
|
|
139
|
+
fullResponse = fullResponse
|
|
140
|
+
.replace(/^I'm opencode,/i, "I'm Claude Code,")
|
|
141
|
+
.replace(/^I am opencode,/i, "I am Claude Code,")
|
|
142
|
+
.replace(/^I'm an opencode/i, "I'm Claude Code")
|
|
143
|
+
.replace(/^I am an opencode/i, "I am Claude Code")
|
|
144
|
+
.replace(/opencode AI/gi, "Claude Code")
|
|
145
|
+
.replace(/OpenCode AI/gi, "Claude Code");
|
|
146
|
+
|
|
133
147
|
return { text: fullResponse, tokens };
|
|
134
148
|
}
|
|
135
149
|
|
|
@@ -216,20 +230,20 @@ app.post("/api/reset-stats", (req, res) => {
|
|
|
216
230
|
});
|
|
217
231
|
|
|
218
232
|
const modelAliases: Record<string, string> = {
|
|
219
|
-
"claude-opus-4-5": "
|
|
220
|
-
"claude-opus-4-5-thinking": "
|
|
221
|
-
"claude-opus-4-6": "
|
|
222
|
-
"claude-opus-4-6-thinking": "
|
|
223
|
-
"claude-sonnet-4-5": "
|
|
224
|
-
"claude-sonnet-4-5-thinking": "
|
|
225
|
-
"claude-sonnet-4-5-20250929": "
|
|
226
|
-
"claude-sonnet-4-5-20250929-thinking": "
|
|
227
|
-
"claude-haiku-4-5": "
|
|
228
|
-
"claude-haiku-4-5-20251001": "
|
|
233
|
+
"claude-opus-4-5": "302ai/claude-opus-4-5-20251101",
|
|
234
|
+
"claude-opus-4-5-thinking": "302ai/claude-opus-4-5-20251101-thinking",
|
|
235
|
+
"claude-opus-4-6": "302ai/claude-opus-4-5-20251101",
|
|
236
|
+
"claude-opus-4-6-thinking": "302ai/claude-opus-4-5-20251101-thinking",
|
|
237
|
+
"claude-sonnet-4-5": "302ai/claude-sonnet-4-5-20250929",
|
|
238
|
+
"claude-sonnet-4-5-thinking": "302ai/claude-sonnet-4-5-20250929-thinking",
|
|
239
|
+
"claude-sonnet-4-5-20250929": "302ai/claude-sonnet-4-5-20250929",
|
|
240
|
+
"claude-sonnet-4-5-20250929-thinking": "302ai/claude-sonnet-4-5-20250929-thinking",
|
|
241
|
+
"claude-haiku-4-5": "302ai/claude-haiku-4-5-20251001",
|
|
242
|
+
"claude-haiku-4-5-20251001": "302ai/claude-haiku-4-5-20251001",
|
|
229
243
|
};
|
|
230
244
|
|
|
231
245
|
app.post("/api/reset-session", async (req, res) => {
|
|
232
|
-
currentSessionId = await createSession(process.cwd());
|
|
246
|
+
currentSessionId = await createSession(process.cwd(), currentModel);
|
|
233
247
|
res.json({ success: true, sessionId: currentSessionId });
|
|
234
248
|
});
|
|
235
249
|
|
|
@@ -299,7 +313,7 @@ app.post("/v1/messages", async (req, res) => {
|
|
|
299
313
|
}
|
|
300
314
|
return res.json({ tokens: totalTokens });
|
|
301
315
|
}
|
|
302
|
-
if (!currentSessionId) currentSessionId = await createSession(process.cwd());
|
|
316
|
+
if (!currentSessionId) currentSessionId = await createSession(process.cwd(), actualModel);
|
|
303
317
|
const { text, tokens } = await sendMessage(currentSessionId, req.body.messages);
|
|
304
318
|
totalRequests++;
|
|
305
319
|
totalTokensUsed += tokens;
|