opencode-anthropic-auth 0.0.1 → 0.0.3

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.
@@ -0,0 +1,26 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ bump:
7
+ description: "Version bump type"
8
+ required: false
9
+ default: "patch"
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - uses: actions/setup-node@v4
18
+ with:
19
+ node-version: "20"
20
+ registry-url: "https://registry.npmjs.org"
21
+
22
+ - run: npm install
23
+
24
+ - run: npm publish --access public
25
+ env:
26
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SST
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bun.lock ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "workspaces": {
4
+ "": {
5
+ "name": "opencode-anthropic-auth",
6
+ "dependencies": {
7
+ "@openauthjs/openauth": "^0.4.3",
8
+ },
9
+ "devDependencies": {
10
+ "@opencode-ai/plugin": "^0.4.45",
11
+ },
12
+ },
13
+ },
14
+ "packages": {
15
+ "@openauthjs/openauth": ["@openauthjs/openauth@0.4.3", "", { "dependencies": { "@standard-schema/spec": "1.0.0-beta.3", "aws4fetch": "1.0.20", "jose": "5.9.6" }, "peerDependencies": { "arctic": "^2.2.2", "hono": "^4.0.0" } }, "sha512-RlnjqvHzqcbFVymEwhlUEuac4utA5h4nhSK/i2szZuQmxTIqbGUxZ+nM+avM+VV4Ing+/ZaNLKILoXS3yrkOOw=="],
16
+
17
+ "@opencode-ai/plugin": ["@opencode-ai/plugin@0.4.45", "", { "dependencies": { "@opencode-ai/sdk": "0.4.19" } }, "sha512-TuD+FNmA6vN+/B82qayCvOyTXRuAtfvU0U95UKSZoNrYgIBhpD/sW/oS65iUv5QwQqzO8BxI4DYWjmLIqCz8uw=="],
18
+
19
+ "@opencode-ai/sdk": ["@opencode-ai/sdk@0.4.19", "", {}, "sha512-7V+wDR1+m+TQZAraAh/bOSObiA/uysG1YIXZVe6gl1sQAXDtkG2FYCzs0gTZ/ORdkUKEnr3vyQIk895Mu0CC/w=="],
20
+
21
+ "@oslojs/asn1": ["@oslojs/asn1@1.0.0", "", { "dependencies": { "@oslojs/binary": "1.0.0" } }, "sha512-zw/wn0sj0j0QKbIXfIlnEcTviaCzYOY3V5rAyjR6YtOByFtJiT574+8p9Wlach0lZH9fddD4yb9laEAIl4vXQA=="],
22
+
23
+ "@oslojs/binary": ["@oslojs/binary@1.0.0", "", {}, "sha512-9RCU6OwXU6p67H4NODbuxv2S3eenuQ4/WFLrsq+K/k682xrznH5EVWA7N4VFk9VYVcbFtKqur5YQQZc0ySGhsQ=="],
24
+
25
+ "@oslojs/crypto": ["@oslojs/crypto@1.0.1", "", { "dependencies": { "@oslojs/asn1": "1.0.0", "@oslojs/binary": "1.0.0" } }, "sha512-7n08G8nWjAr/Yu3vu9zzrd0L9XnrJfpMioQcvCMxBIiF5orECHe5/3J0jmXRVvgfqMm/+4oxlQ+Sq39COYLcNQ=="],
26
+
27
+ "@oslojs/encoding": ["@oslojs/encoding@1.1.0", "", {}, "sha512-70wQhgYmndg4GCPxPPxPGevRKqTIJ2Nh4OkiMWmDAVYsTQ+Ta7Sq+rPevXyXGdzr30/qZBnyOalCszoMxlyldQ=="],
28
+
29
+ "@oslojs/jwt": ["@oslojs/jwt@0.2.0", "", { "dependencies": { "@oslojs/encoding": "0.4.1" } }, "sha512-bLE7BtHrURedCn4Mco3ma9L4Y1GR2SMBuIvjWr7rmQ4/W/4Jy70TIAgZ+0nIlk0xHz1vNP8x8DCns45Sb2XRbg=="],
30
+
31
+ "@standard-schema/spec": ["@standard-schema/spec@1.0.0-beta.3", "", {}, "sha512-0ifF3BjA1E8SY9C+nUew8RefNOIq0cDlYALPty4rhUm8Rrl6tCM8hBT4bhGhx7I7iXD0uAgt50lgo8dD73ACMw=="],
32
+
33
+ "arctic": ["arctic@2.3.4", "", { "dependencies": { "@oslojs/crypto": "1.0.1", "@oslojs/encoding": "1.1.0", "@oslojs/jwt": "0.2.0" } }, "sha512-+p30BOWsctZp+CVYCt7oAean/hWGW42sH5LAcRQX56ttEkFJWbzXBhmSpibbzwSJkRrotmsA+oAoJoVsU0f5xA=="],
34
+
35
+ "aws4fetch": ["aws4fetch@1.0.20", "", {}, "sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g=="],
36
+
37
+ "hono": ["hono@4.9.1", "", {}, "sha512-qfvdJ42t6CQE0N/iSCa8KsW8SQqYD67YB+TYbwPHlnALvX+s7ynh8otR1NEk5jXtUg73gpV/B82OSufDmwtX3w=="],
38
+
39
+ "jose": ["jose@5.9.6", "", {}, "sha512-AMlnetc9+CV9asI19zHmrgS/WYsWUwCn2R7RzlbJWD7F9eWYUTGyBmU9o6PxngtLGOiDGPRu+Uc4fhKzbpteZQ=="],
40
+
41
+ "@oslojs/jwt/@oslojs/encoding": ["@oslojs/encoding@0.4.1", "", {}, "sha512-hkjo6MuIK/kQR5CrGNdAPZhS01ZCXuWDRJ187zh6qqF2+yMHZpD9fAYpX8q2bOO6Ryhl3XpCT6kUX76N8hhm4Q=="],
42
+ }
43
+ }
package/index.mjs CHANGED
@@ -121,11 +121,28 @@ export async function AnthropicAuthPlugin({ client }) {
121
121
  });
122
122
  auth.access = json.access_token;
123
123
  }
124
+ // Add oauth-2025-04-20 beta to whatever betas are already present
125
+ const incomingBeta = init.headers?.["anthropic-beta"] || "";
126
+ const incomingBetasList = incomingBeta
127
+ .split(",")
128
+ .map((b) => b.trim())
129
+ .filter(Boolean);
130
+
131
+ // Add oauth beta and deduplicate
132
+ const mergedBetas = [
133
+ ...new Set([
134
+ "oauth-2025-04-20",
135
+ "claude-code-20250219",
136
+ "interleaved-thinking-2025-05-14",
137
+ "fine-grained-tool-streaming-2025-05-14",
138
+ ...incomingBetasList,
139
+ ]),
140
+ ].join(",");
141
+
124
142
  const headers = {
125
143
  ...init.headers,
126
144
  authorization: `Bearer ${auth.access}`,
127
- "anthropic-beta":
128
- "oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",
145
+ "anthropic-beta": mergedBetas,
129
146
  };
130
147
  delete headers["x-api-key"];
131
148
  return fetch(input, {
@@ -166,7 +183,18 @@ export async function AnthropicAuthPlugin({ client }) {
166
183
  method: "code",
167
184
  callback: async (code) => {
168
185
  const credentials = await exchange(code, verifier);
169
- return credentials;
186
+ if (credentials.type === "failed") return credentials;
187
+ const result = await fetch(
188
+ `https://api.anthropic.com/api/oauth/claude_cli/create_api_key`,
189
+ {
190
+ method: "POST",
191
+ headers: {
192
+ "Content-Type": "application/json",
193
+ authorization: `Bearer ${credentials.access}`,
194
+ },
195
+ },
196
+ ).then((r) => r.json());
197
+ return { type: "success", key: result.raw_key };
170
198
  },
171
199
  };
172
200
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-auth",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "./index.mjs",
5
5
  "devDependencies": {
6
6
  "@opencode-ai/plugin": "^0.4.45"
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bun
2
+ import { $ } from "bun";
3
+
4
+ const dir = new URL("..", import.meta.url).pathname;
5
+ process.chdir(dir);
6
+
7
+ const bumpType = process.argv[2] || "patch";
8
+
9
+ console.log(`Bumping ${bumpType} version...`);
10
+
11
+ // Bump version in package.json
12
+ await $`npm version ${bumpType} --no-git-tag-version`;
13
+
14
+ // Read the new version
15
+ const pkg = await Bun.file("./package.json").json();
16
+ const version = pkg.version;
17
+
18
+ console.log(`New version: ${version}`);
19
+
20
+ // Commit the version bump
21
+ await $`git add package.json`;
22
+ await $`git commit -m "Bump version to ${version}"`;
23
+ await $`git push`;
24
+
25
+ // Trigger GitHub workflow
26
+ console.log(`Triggering publish workflow...`);
27
+ await $`gh workflow run publish.yml -f bump="${bumpType}"`;
28
+
29
+ console.log(`✓ Version bumped to ${version} and publish workflow triggered`);