ocb-cli 1.0.5 → 1.0.6
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 +18 -1
- package/package.json +1 -1
- package/src/proxy.ts +21 -1
package/dist/proxy.js
CHANGED
|
@@ -73,7 +73,11 @@ function extractTextFromContent(content) {
|
|
|
73
73
|
async function sendMessage(sessionId, messages) {
|
|
74
74
|
const reversed = [...messages].reverse();
|
|
75
75
|
let lastUserMessage = null;
|
|
76
|
+
let systemPrompt = "";
|
|
76
77
|
for (const m of reversed) {
|
|
78
|
+
if (m.role === "system") {
|
|
79
|
+
systemPrompt = extractTextFromContent(m.content);
|
|
80
|
+
}
|
|
77
81
|
if (m.role === "user") {
|
|
78
82
|
const content = extractTextFromContent(m.content);
|
|
79
83
|
if (content && content.length > 2 && content !== "count") {
|
|
@@ -85,13 +89,19 @@ async function sendMessage(sessionId, messages) {
|
|
|
85
89
|
if (!lastUserMessage)
|
|
86
90
|
return { text: "OK", tokens: 0 };
|
|
87
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
|
+
}
|
|
88
98
|
const response = await fetch(`${OPENCODE_SERVER_URL}/session/${sessionId}/message`, {
|
|
89
99
|
method: "POST",
|
|
90
100
|
headers: {
|
|
91
101
|
"Content-Type": "application/json",
|
|
92
102
|
...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
|
|
93
103
|
},
|
|
94
|
-
body: JSON.stringify(
|
|
104
|
+
body: JSON.stringify(requestBody)
|
|
95
105
|
});
|
|
96
106
|
const data = await response.json();
|
|
97
107
|
let fullResponse = "";
|
|
@@ -104,6 +114,13 @@ async function sendMessage(sessionId, messages) {
|
|
|
104
114
|
}
|
|
105
115
|
if (data.info?.tokens)
|
|
106
116
|
tokens = data.info.tokens.total || 0;
|
|
117
|
+
fullResponse = fullResponse
|
|
118
|
+
.replace(/I am opencode/gi, "I am Claude Code")
|
|
119
|
+
.replace(/I'm opencode/gi, "I'm Claude Code")
|
|
120
|
+
.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");
|
|
107
124
|
return { text: fullResponse, tokens };
|
|
108
125
|
}
|
|
109
126
|
const app = express();
|
package/package.json
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -93,8 +93,12 @@ function extractTextFromContent(content: any): string {
|
|
|
93
93
|
async function sendMessage(sessionId: string, messages: any[]): Promise<{ text: string; tokens: number }> {
|
|
94
94
|
const reversed = [...messages].reverse();
|
|
95
95
|
let lastUserMessage = null;
|
|
96
|
+
let systemPrompt = "";
|
|
96
97
|
|
|
97
98
|
for (const m of reversed) {
|
|
99
|
+
if (m.role === "system") {
|
|
100
|
+
systemPrompt = extractTextFromContent(m.content);
|
|
101
|
+
}
|
|
98
102
|
if (m.role === "user") {
|
|
99
103
|
const content = extractTextFromContent(m.content);
|
|
100
104
|
if (content && content.length > 2 && content !== "count") {
|
|
@@ -108,13 +112,21 @@ async function sendMessage(sessionId: string, messages: any[]): Promise<{ text:
|
|
|
108
112
|
|
|
109
113
|
const combinedContent = extractTextFromContent(lastUserMessage.content);
|
|
110
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
|
+
|
|
111
123
|
const response = await fetch(`${OPENCODE_SERVER_URL}/session/${sessionId}/message`, {
|
|
112
124
|
method: "POST",
|
|
113
125
|
headers: {
|
|
114
126
|
"Content-Type": "application/json",
|
|
115
127
|
...(OPENCODE_PASSWORD ? { "Authorization": `Basic ${Buffer.from(`opencode:${OPENCODE_PASSWORD}`).toString("base64")}` } : {})
|
|
116
128
|
},
|
|
117
|
-
body: JSON.stringify(
|
|
129
|
+
body: JSON.stringify(requestBody)
|
|
118
130
|
});
|
|
119
131
|
|
|
120
132
|
const data = await response.json();
|
|
@@ -130,6 +142,14 @@ async function sendMessage(sessionId: string, messages: any[]): Promise<{ text:
|
|
|
130
142
|
|
|
131
143
|
if (data.info?.tokens) tokens = data.info.tokens.total || 0;
|
|
132
144
|
|
|
145
|
+
fullResponse = fullResponse
|
|
146
|
+
.replace(/I am opencode/gi, "I am Claude Code")
|
|
147
|
+
.replace(/I'm opencode/gi, "I'm Claude Code")
|
|
148
|
+
.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");
|
|
152
|
+
|
|
133
153
|
return { text: fullResponse, tokens };
|
|
134
154
|
}
|
|
135
155
|
|