opencode-anthropic-auth 0.0.8 → 0.0.10

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 +37 -4
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -70,6 +70,13 @@ async function exchange(code, verifier) {
70
70
  */
71
71
  export async function AnthropicAuthPlugin({ client }) {
72
72
  return {
73
+ "experimental.chat.system.transform": (input, output) => {
74
+ if (input.model.providerID === "anthropic") {
75
+ output.system.unshift(
76
+ "You are Claude Code, Anthropic's official CLI for Claude.",
77
+ );
78
+ }
79
+ },
73
80
  auth: {
74
81
  provider: "anthropic",
75
82
  async loader(getAuth, provider) {
@@ -147,7 +154,9 @@ export async function AnthropicAuthPlugin({ client }) {
147
154
  }
148
155
  }
149
156
  } else {
150
- for (const [key, value] of Object.entries(requestInit.headers)) {
157
+ for (const [key, value] of Object.entries(
158
+ requestInit.headers,
159
+ )) {
151
160
  if (typeof value !== "undefined") {
152
161
  requestHeaders.set(key, String(value));
153
162
  }
@@ -184,11 +193,29 @@ export async function AnthropicAuthPlugin({ client }) {
184
193
  if (body && typeof body === "string") {
185
194
  try {
186
195
  const parsed = JSON.parse(body);
196
+
197
+ // Sanitize system prompt - server blocks "OpenCode" string
198
+ if (parsed.system && Array.isArray(parsed.system)) {
199
+ parsed.system = parsed.system.map((item) => {
200
+ if (item.type === "text" && item.text) {
201
+ return {
202
+ ...item,
203
+ text: item.text
204
+ .replace(/OpenCode/g, "Claude Code")
205
+ .replace(/opencode/gi, "Claude"),
206
+ };
207
+ }
208
+ return item;
209
+ });
210
+ }
211
+
187
212
  // Add prefix to tools definitions
188
213
  if (parsed.tools && Array.isArray(parsed.tools)) {
189
214
  parsed.tools = parsed.tools.map((tool) => ({
190
215
  ...tool,
191
- name: tool.name ? `${TOOL_PREFIX}${tool.name}` : tool.name,
216
+ name: tool.name
217
+ ? `${TOOL_PREFIX}${tool.name}`
218
+ : tool.name,
192
219
  }));
193
220
  }
194
221
  // Add prefix to tool_use blocks in messages
@@ -197,7 +224,10 @@ export async function AnthropicAuthPlugin({ client }) {
197
224
  if (msg.content && Array.isArray(msg.content)) {
198
225
  msg.content = msg.content.map((block) => {
199
226
  if (block.type === "tool_use" && block.name) {
200
- return { ...block, name: `${TOOL_PREFIX}${block.name}` };
227
+ return {
228
+ ...block,
229
+ name: `${TOOL_PREFIX}${block.name}`,
230
+ };
201
231
  }
202
232
  return block;
203
233
  });
@@ -256,7 +286,10 @@ export async function AnthropicAuthPlugin({ client }) {
256
286
  }
257
287
 
258
288
  let text = decoder.decode(value, { stream: true });
259
- text = text.replace(/"name"\s*:\s*"mcp_([^"]+)"/g, '"name": "$1"');
289
+ text = text.replace(
290
+ /"name"\s*:\s*"mcp_([^"]+)"/g,
291
+ '"name": "$1"',
292
+ );
260
293
  controller.enqueue(encoder.encode(text));
261
294
  },
262
295
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-auth",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "main": "./index.mjs",
5
5
  "devDependencies": {
6
6
  "@opencode-ai/plugin": "^0.4.45"