ocb-cli 1.0.6 → 1.0.8

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.
Files changed (3) hide show
  1. package/dist/proxy.js +27 -31
  2. package/package.json +1 -1
  3. package/src/proxy.ts +27 -33
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 = "minimax-m2.5-free";
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({ workspace, mode: "agent" })
60
+ body: JSON.stringify({
61
+ workspace,
62
+ agent: "claude-code",
63
+ modelId: modelId || currentModel
64
+ })
61
65
  });
62
66
  const data = await response.json();
63
67
  return data.id;
@@ -73,11 +77,7 @@ function extractTextFromContent(content) {
73
77
  async function sendMessage(sessionId, messages) {
74
78
  const reversed = [...messages].reverse();
75
79
  let lastUserMessage = null;
76
- let systemPrompt = "";
77
80
  for (const m of reversed) {
78
- if (m.role === "system") {
79
- systemPrompt = extractTextFromContent(m.content);
80
- }
81
81
  if (m.role === "user") {
82
82
  const content = extractTextFromContent(m.content);
83
83
  if (content && content.length > 2 && content !== "count") {
@@ -89,19 +89,15 @@ async function sendMessage(sessionId, messages) {
89
89
  if (!lastUserMessage)
90
90
  return { text: "OK", tokens: 0 };
91
91
  const combinedContent = extractTextFromContent(lastUserMessage.content);
92
- const requestBody = {
93
- parts: [{ type: "text", text: combinedContent }]
94
- };
95
- if (!systemPrompt) {
96
- requestBody.systemPrompt = "You are Claude Code, an AI assistant built by Anthropic. You are helpful, harmless, and honest. Respond as Claude Code would.";
97
- }
98
92
  const response = await fetch(`${OPENCODE_SERVER_URL}/session/${sessionId}/message`, {
99
93
  method: "POST",
100
94
  headers: {
101
95
  "Content-Type": "application/json",
102
96
  ...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
103
97
  },
104
- body: JSON.stringify(requestBody)
98
+ body: JSON.stringify({
99
+ parts: [{ type: "text", text: combinedContent }]
100
+ })
105
101
  });
106
102
  const data = await response.json();
107
103
  let fullResponse = "";
@@ -115,12 +111,12 @@ async function sendMessage(sessionId, messages) {
115
111
  if (data.info?.tokens)
116
112
  tokens = data.info.tokens.total || 0;
117
113
  fullResponse = fullResponse
118
- .replace(/I am opencode/gi, "I am Claude Code")
119
- .replace(/I'm opencode/gi, "I'm Claude Code")
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")
120
118
  .replace(/opencode AI/gi, "Claude Code")
121
- .replace(/OpenCode AI/gi, "Claude Code")
122
- .replace(/powered by OpenCode/gi, "built by Anthropic")
123
- .replace(/OpenCode/gi, "Claude Code");
119
+ .replace(/OpenCode AI/gi, "Claude Code");
124
120
  return { text: fullResponse, tokens };
125
121
  }
126
122
  const app = express();
@@ -202,19 +198,19 @@ app.post("/api/reset-stats", (req, res) => {
202
198
  res.json({ success: true });
203
199
  });
204
200
  const modelAliases = {
205
- "claude-opus-4-5": "opencode/minimax-m2.5-free",
206
- "claude-opus-4-5-thinking": "opencode/minimax-m2.5-free",
207
- "claude-opus-4-6": "opencode/minimax-m2.5-free",
208
- "claude-opus-4-6-thinking": "opencode/minimax-m2.5-free",
209
- "claude-sonnet-4-5": "opencode/minimax-m2.5-free",
210
- "claude-sonnet-4-5-thinking": "opencode/minimax-m2.5-free",
211
- "claude-sonnet-4-5-20250929": "opencode/minimax-m2.5-free",
212
- "claude-sonnet-4-5-20250929-thinking": "opencode/minimax-m2.5-free",
213
- "claude-haiku-4-5": "opencode/minimax-m2.5-free",
214
- "claude-haiku-4-5-20251001": "opencode/minimax-m2.5-free",
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",
215
211
  };
216
212
  app.post("/api/reset-session", async (req, res) => {
217
- currentSessionId = await createSession(process.cwd());
213
+ currentSessionId = await createSession(process.cwd(), currentModel);
218
214
  res.json({ success: true, sessionId: currentSessionId });
219
215
  });
220
216
  app.get("/v1/authenticate", (req, res) => res.json({ type: "authentication", authenticated: true }));
@@ -280,7 +276,7 @@ app.post("/v1/messages", async (req, res) => {
280
276
  return res.json({ tokens: totalTokens });
281
277
  }
282
278
  if (!currentSessionId)
283
- currentSessionId = await createSession(process.cwd());
279
+ currentSessionId = await createSession(process.cwd(), actualModel);
284
280
  const { text, tokens } = await sendMessage(currentSessionId, req.body.messages);
285
281
  totalRequests++;
286
282
  totalTokensUsed += tokens;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ocb-cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "OpenCode Bridge - Use OpenCode AI models in Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/proxy.js",
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 = "minimax-m2.5-free";
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({ workspace, mode: "agent" })
79
+ body: JSON.stringify({
80
+ workspace,
81
+ agent: "claude-code",
82
+ modelId: modelId || currentModel
83
+ })
80
84
  });
81
85
  const data = await response.json();
82
86
  return data.id;
@@ -93,12 +97,8 @@ function extractTextFromContent(content: any): string {
93
97
  async function sendMessage(sessionId: string, messages: any[]): Promise<{ text: string; tokens: number }> {
94
98
  const reversed = [...messages].reverse();
95
99
  let lastUserMessage = null;
96
- let systemPrompt = "";
97
100
 
98
101
  for (const m of reversed) {
99
- if (m.role === "system") {
100
- systemPrompt = extractTextFromContent(m.content);
101
- }
102
102
  if (m.role === "user") {
103
103
  const content = extractTextFromContent(m.content);
104
104
  if (content && content.length > 2 && content !== "count") {
@@ -112,21 +112,15 @@ async function sendMessage(sessionId: string, messages: any[]): Promise<{ text:
112
112
 
113
113
  const combinedContent = extractTextFromContent(lastUserMessage.content);
114
114
 
115
- const requestBody: any = {
116
- parts: [{ type: "text", text: combinedContent }]
117
- };
118
-
119
- if (!systemPrompt) {
120
- requestBody.systemPrompt = "You are Claude Code, an AI assistant built by Anthropic. You are helpful, harmless, and honest. Respond as Claude Code would.";
121
- }
122
-
123
115
  const response = await fetch(`${OPENCODE_SERVER_URL}/session/${sessionId}/message`, {
124
116
  method: "POST",
125
117
  headers: {
126
118
  "Content-Type": "application/json",
127
119
  ...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
128
120
  },
129
- body: JSON.stringify(requestBody)
121
+ body: JSON.stringify({
122
+ parts: [{ type: "text", text: combinedContent }]
123
+ })
130
124
  });
131
125
 
132
126
  const data = await response.json();
@@ -143,12 +137,12 @@ async function sendMessage(sessionId: string, messages: any[]): Promise<{ text:
143
137
  if (data.info?.tokens) tokens = data.info.tokens.total || 0;
144
138
 
145
139
  fullResponse = fullResponse
146
- .replace(/I am opencode/gi, "I am Claude Code")
147
- .replace(/I'm opencode/gi, "I'm Claude Code")
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")
148
144
  .replace(/opencode AI/gi, "Claude Code")
149
- .replace(/OpenCode AI/gi, "Claude Code")
150
- .replace(/powered by OpenCode/gi, "built by Anthropic")
151
- .replace(/OpenCode/gi, "Claude Code");
145
+ .replace(/OpenCode AI/gi, "Claude Code");
152
146
 
153
147
  return { text: fullResponse, tokens };
154
148
  }
@@ -236,20 +230,20 @@ app.post("/api/reset-stats", (req, res) => {
236
230
  });
237
231
 
238
232
  const modelAliases: Record<string, string> = {
239
- "claude-opus-4-5": "opencode/minimax-m2.5-free",
240
- "claude-opus-4-5-thinking": "opencode/minimax-m2.5-free",
241
- "claude-opus-4-6": "opencode/minimax-m2.5-free",
242
- "claude-opus-4-6-thinking": "opencode/minimax-m2.5-free",
243
- "claude-sonnet-4-5": "opencode/minimax-m2.5-free",
244
- "claude-sonnet-4-5-thinking": "opencode/minimax-m2.5-free",
245
- "claude-sonnet-4-5-20250929": "opencode/minimax-m2.5-free",
246
- "claude-sonnet-4-5-20250929-thinking": "opencode/minimax-m2.5-free",
247
- "claude-haiku-4-5": "opencode/minimax-m2.5-free",
248
- "claude-haiku-4-5-20251001": "opencode/minimax-m2.5-free",
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",
249
243
  };
250
244
 
251
245
  app.post("/api/reset-session", async (req, res) => {
252
- currentSessionId = await createSession(process.cwd());
246
+ currentSessionId = await createSession(process.cwd(), currentModel);
253
247
  res.json({ success: true, sessionId: currentSessionId });
254
248
  });
255
249
 
@@ -319,7 +313,7 @@ app.post("/v1/messages", async (req, res) => {
319
313
  }
320
314
  return res.json({ tokens: totalTokens });
321
315
  }
322
- if (!currentSessionId) currentSessionId = await createSession(process.cwd());
316
+ if (!currentSessionId) currentSessionId = await createSession(process.cwd(), actualModel);
323
317
  const { text, tokens } = await sendMessage(currentSessionId, req.body.messages);
324
318
  totalRequests++;
325
319
  totalTokensUsed += tokens;