@ex-machina/opencode-anthropic-auth 1.5.1 → 1.6.0

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/dist/transform.js +19 -8
  2. package/package.json +1 -1
package/dist/transform.js CHANGED
@@ -1,5 +1,19 @@
1
1
  import { buildBillingHeaderValue } from './cch';
2
2
  import { CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_IDENTITY, OPENCODE_IDENTITY, PARAGRAPH_REMOVAL_ANCHORS, REQUIRED_BETAS, TEXT_REPLACEMENTS, TOOL_PREFIX, USER_AGENT, } from './constants';
3
+ /**
4
+ * Prefix a tool name with TOOL_PREFIX and uppercase the first character.
5
+ * Claude Code uses PascalCase tool names (e.g. mcp_Bash, mcp_Read);
6
+ * lowercase names (mcp_bash, mcp_read) are flagged as non-Claude-Code clients.
7
+ */
8
+ function prefixName(name) {
9
+ return `${TOOL_PREFIX}${name.charAt(0).toUpperCase()}${name.slice(1)}`;
10
+ }
11
+ /**
12
+ * Reverse prefixName: strip TOOL_PREFIX and restore the original leading case.
13
+ */
14
+ function unprefixName(name) {
15
+ return `${name.charAt(0).toLowerCase()}${name.slice(1)}`;
16
+ }
3
17
  /**
4
18
  * Merge headers from a Request object and/or a RequestInit headers value
5
19
  * into a single Headers instance.
@@ -68,7 +82,7 @@ export function prefixToolNames(body) {
68
82
  if (parsed.tools && Array.isArray(parsed.tools)) {
69
83
  parsed.tools = parsed.tools.map((tool) => ({
70
84
  ...tool,
71
- name: tool.name ? `${TOOL_PREFIX}${tool.name}` : tool.name,
85
+ name: tool.name ? prefixName(tool.name) : tool.name,
72
86
  }));
73
87
  }
74
88
  if (parsed.messages && Array.isArray(parsed.messages)) {
@@ -76,10 +90,7 @@ export function prefixToolNames(body) {
76
90
  if (msg.content && Array.isArray(msg.content)) {
77
91
  msg.content = msg.content.map((block) => {
78
92
  if (block.type === 'tool_use' && block.name) {
79
- return {
80
- ...block,
81
- name: `${TOOL_PREFIX}${block.name}`,
82
- };
93
+ return { ...block, name: prefixName(block.name) };
83
94
  }
84
95
  return block;
85
96
  });
@@ -97,7 +108,7 @@ export function prefixToolNames(body) {
97
108
  * Strip TOOL_PREFIX from tool names in streaming response text.
98
109
  */
99
110
  export function stripToolPrefix(text) {
100
- return text.replace(/"name"\s*:\s*"mcp_([^"]+)"/g, '"name": "$1"');
111
+ return text.replace(/"name"\s*:\s*"mcp_([^"]+)"/g, (_match, name) => `"name": "${unprefixName(name)}"`);
101
112
  }
102
113
  /**
103
114
  * Check if TLS verification should be skipped for custom API endpoints.
@@ -321,7 +332,7 @@ export function rewriteRequestBody(body) {
321
332
  if (parsed.tools && Array.isArray(parsed.tools)) {
322
333
  parsed.tools = parsed.tools.map((tool) => ({
323
334
  ...tool,
324
- name: tool.name ? `${TOOL_PREFIX}${tool.name}` : tool.name,
335
+ name: tool.name ? prefixName(tool.name) : tool.name,
325
336
  }));
326
337
  }
327
338
  if (parsed.messages && Array.isArray(parsed.messages)) {
@@ -329,7 +340,7 @@ export function rewriteRequestBody(body) {
329
340
  if (msg.content && Array.isArray(msg.content)) {
330
341
  msg.content = msg.content.map((block) => {
331
342
  if (block.type === 'tool_use' && block.name) {
332
- return { ...block, name: `${TOOL_PREFIX}${block.name}` };
343
+ return { ...block, name: prefixName(block.name) };
333
344
  }
334
345
  return block;
335
346
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ex-machina/opencode-anthropic-auth",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ex-machina-co/opencode-anthropic-auth"