opencode-anthropic-auth 0.0.5 → 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.
- package/.github/workflows/publish.yml +6 -1
- package/index.mjs +49 -1
- package/package.json +1 -1
|
@@ -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: "
|
|
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
|
@@ -151,10 +151,58 @@ export async function AnthropicAuthPlugin({ client }) {
|
|
|
151
151
|
"anthropic-beta": mergedBetas,
|
|
152
152
|
};
|
|
153
153
|
delete headers["x-api-key"];
|
|
154
|
-
|
|
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, {
|
|
155
173
|
...init,
|
|
174
|
+
body,
|
|
156
175
|
headers,
|
|
157
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;
|
|
158
206
|
},
|
|
159
207
|
};
|
|
160
208
|
}
|