opencode-anthropic-auth 0.0.4 → 0.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.
@@ -8,6 +8,10 @@ on:
8
8
  required: false
9
9
  default: "patch"
10
10
 
11
+ permissions:
12
+ id-token: write
13
+ contents: read
14
+
11
15
  jobs:
12
16
  publish:
13
17
  runs-on: ubuntu-latest
@@ -16,7 +20,7 @@ jobs:
16
20
 
17
21
  - uses: actions/setup-node@v4
18
22
  with:
19
- node-version: "20"
23
+ node-version: "24"
20
24
  registry-url: "https://registry.npmjs.org"
21
25
 
22
26
  - run: npm install
@@ -24,3 +28,4 @@ jobs:
24
28
  - run: npm publish --access public
25
29
  env:
26
30
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31
+ NPM_CONFIG_PROVENANCE: false
package/index.mjs CHANGED
@@ -110,7 +110,9 @@ export async function AnthropicAuthPlugin({ client }) {
110
110
  }),
111
111
  },
112
112
  );
113
- if (!response.ok) return;
113
+ if (!response.ok) {
114
+ throw new Error(`Token refresh failed: ${response.status}`);
115
+ }
114
116
  const json = await response.json();
115
117
  await client.auth.set({
116
118
  path: {
@@ -149,10 +151,58 @@ export async function AnthropicAuthPlugin({ client }) {
149
151
  "anthropic-beta": mergedBetas,
150
152
  };
151
153
  delete headers["x-api-key"];
152
- return fetch(input, {
154
+
155
+ const TOOL_PREFIX = "oc_";
156
+ let body = init.body;
157
+ if (body && typeof body === "string") {
158
+ try {
159
+ const parsed = JSON.parse(body);
160
+ if (parsed.tools && Array.isArray(parsed.tools)) {
161
+ parsed.tools = parsed.tools.map((tool) => ({
162
+ ...tool,
163
+ name: tool.name ? `${TOOL_PREFIX}${tool.name}` : tool.name,
164
+ }));
165
+ body = JSON.stringify(parsed);
166
+ }
167
+ } catch (e) {
168
+ // ignore parse errors
169
+ }
170
+ }
171
+
172
+ const response = await fetch(input, {
153
173
  ...init,
174
+ body,
154
175
  headers,
155
176
  });
177
+
178
+ // Transform streaming response to rename tools back
179
+ if (response.body) {
180
+ const reader = response.body.getReader();
181
+ const decoder = new TextDecoder();
182
+ const encoder = new TextEncoder();
183
+
184
+ const stream = new ReadableStream({
185
+ async pull(controller) {
186
+ const { done, value } = await reader.read();
187
+ if (done) {
188
+ controller.close();
189
+ return;
190
+ }
191
+
192
+ let text = decoder.decode(value, { stream: true });
193
+ text = text.replace(/"name"\s*:\s*"oc_([^"]+)"/g, '"name": "$1"');
194
+ controller.enqueue(encoder.encode(text));
195
+ },
196
+ });
197
+
198
+ return new Response(stream, {
199
+ status: response.status,
200
+ statusText: response.statusText,
201
+ headers: response.headers,
202
+ });
203
+ }
204
+
205
+ return response;
156
206
  },
157
207
  };
158
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-auth",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "main": "./index.mjs",
5
5
  "devDependencies": {
6
6
  "@opencode-ai/plugin": "^0.4.45"