opencode-anthropic-auth 0.0.7 → 0.0.9

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 (2) hide show
  1. package/index.mjs +34 -3
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -179,18 +179,49 @@ export async function AnthropicAuthPlugin({ client }) {
179
179
  );
180
180
  requestHeaders.delete("x-api-key");
181
181
 
182
- const TOOL_PREFIX = "oc_";
182
+ const TOOL_PREFIX = "mcp_";
183
183
  let body = requestInit.body;
184
184
  if (body && typeof body === "string") {
185
185
  try {
186
186
  const parsed = JSON.parse(body);
187
+
188
+ // Sanitize system prompt - server blocks "OpenCode" string
189
+ if (parsed.system && Array.isArray(parsed.system)) {
190
+ parsed.system = parsed.system.map(item => {
191
+ if (item.type === 'text' && item.text) {
192
+ return {
193
+ ...item,
194
+ text: item.text
195
+ .replace(/OpenCode/g, 'Claude Code')
196
+ .replace(/opencode/gi, 'Claude')
197
+ };
198
+ }
199
+ return item;
200
+ });
201
+ }
202
+
203
+ // Add prefix to tools definitions
187
204
  if (parsed.tools && Array.isArray(parsed.tools)) {
188
205
  parsed.tools = parsed.tools.map((tool) => ({
189
206
  ...tool,
190
207
  name: tool.name ? `${TOOL_PREFIX}${tool.name}` : tool.name,
191
208
  }));
192
- body = JSON.stringify(parsed);
193
209
  }
210
+ // Add prefix to tool_use blocks in messages
211
+ if (parsed.messages && Array.isArray(parsed.messages)) {
212
+ parsed.messages = parsed.messages.map((msg) => {
213
+ if (msg.content && Array.isArray(msg.content)) {
214
+ msg.content = msg.content.map((block) => {
215
+ if (block.type === "tool_use" && block.name) {
216
+ return { ...block, name: `${TOOL_PREFIX}${block.name}` };
217
+ }
218
+ return block;
219
+ });
220
+ }
221
+ return msg;
222
+ });
223
+ }
224
+ body = JSON.stringify(parsed);
194
225
  } catch (e) {
195
226
  // ignore parse errors
196
227
  }
@@ -241,7 +272,7 @@ export async function AnthropicAuthPlugin({ client }) {
241
272
  }
242
273
 
243
274
  let text = decoder.decode(value, { stream: true });
244
- text = text.replace(/"name"\s*:\s*"oc_([^"]+)"/g, '"name": "$1"');
275
+ text = text.replace(/"name"\s*:\s*"mcp_([^"]+)"/g, '"name": "$1"');
245
276
  controller.enqueue(encoder.encode(text));
246
277
  },
247
278
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-auth",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "main": "./index.mjs",
5
5
  "devDependencies": {
6
6
  "@opencode-ai/plugin": "^0.4.45"