opencode-anthropic-auth 0.0.9 → 0.0.11
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/index.mjs +25 -8
- 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(
|
|
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
|
}
|
|
@@ -187,13 +196,13 @@ export async function AnthropicAuthPlugin({ client }) {
|
|
|
187
196
|
|
|
188
197
|
// Sanitize system prompt - server blocks "OpenCode" string
|
|
189
198
|
if (parsed.system && Array.isArray(parsed.system)) {
|
|
190
|
-
parsed.system = parsed.system.map(item => {
|
|
191
|
-
if (item.type ===
|
|
199
|
+
parsed.system = parsed.system.map((item) => {
|
|
200
|
+
if (item.type === "text" && item.text) {
|
|
192
201
|
return {
|
|
193
202
|
...item,
|
|
194
203
|
text: item.text
|
|
195
|
-
.replace(/OpenCode/g,
|
|
196
|
-
.replace(/opencode/gi,
|
|
204
|
+
.replace(/OpenCode/g, "Claude Code")
|
|
205
|
+
.replace(/opencode/gi, "Claude"),
|
|
197
206
|
};
|
|
198
207
|
}
|
|
199
208
|
return item;
|
|
@@ -204,7 +213,9 @@ export async function AnthropicAuthPlugin({ client }) {
|
|
|
204
213
|
if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
205
214
|
parsed.tools = parsed.tools.map((tool) => ({
|
|
206
215
|
...tool,
|
|
207
|
-
name: tool.name
|
|
216
|
+
name: tool.name
|
|
217
|
+
? `${TOOL_PREFIX}${tool.name}`
|
|
218
|
+
: tool.name,
|
|
208
219
|
}));
|
|
209
220
|
}
|
|
210
221
|
// Add prefix to tool_use blocks in messages
|
|
@@ -213,7 +224,10 @@ export async function AnthropicAuthPlugin({ client }) {
|
|
|
213
224
|
if (msg.content && Array.isArray(msg.content)) {
|
|
214
225
|
msg.content = msg.content.map((block) => {
|
|
215
226
|
if (block.type === "tool_use" && block.name) {
|
|
216
|
-
return {
|
|
227
|
+
return {
|
|
228
|
+
...block,
|
|
229
|
+
name: `${TOOL_PREFIX}${block.name}`,
|
|
230
|
+
};
|
|
217
231
|
}
|
|
218
232
|
return block;
|
|
219
233
|
});
|
|
@@ -272,7 +286,10 @@ export async function AnthropicAuthPlugin({ client }) {
|
|
|
272
286
|
}
|
|
273
287
|
|
|
274
288
|
let text = decoder.decode(value, { stream: true });
|
|
275
|
-
text = text.replace(
|
|
289
|
+
text = text.replace(
|
|
290
|
+
/"name"\s*:\s*"mcp_([^"]+)"/g,
|
|
291
|
+
'"name": "$1"',
|
|
292
|
+
);
|
|
276
293
|
controller.enqueue(encoder.encode(text));
|
|
277
294
|
},
|
|
278
295
|
});
|