opencode-muse-auth 0.1.2 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,8 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
- export declare const MuseCodeAuth: Plugin;
2
+ import { Plugin as V2Plugin } from "@opencode/plugin";
3
+ declare const _default: {
4
+ id: string;
5
+ setup: (context: V2Plugin.Context) => Promise<V2Plugin.Cleanup | void> | V2Plugin.Cleanup | void;
6
+ server: Plugin;
7
+ };
8
+ export default _default;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { Plugin as V2Plugin, Integration } from "@opencode/plugin";
1
2
  import { readCache, writeCache, deviceAuthorize, pollToken, mintKey } from "./auth.js";
2
- export const MuseCodeAuth = async () => {
3
+ const MuseCodeAuth = async () => {
3
4
  return {
4
5
  auth: {
5
6
  provider: "meta",
@@ -36,3 +37,61 @@ export const MuseCodeAuth = async () => {
36
37
  },
37
38
  };
38
39
  };
40
+ export default {
41
+ ...V2Plugin.define({
42
+ id: "muse-code-auth",
43
+ async setup(ctx) {
44
+ const methodID = Integration.MethodID.make("muse-code-subscription");
45
+ await ctx.integration.transform((editor) => {
46
+ editor.method.update({
47
+ integrationID: "meta",
48
+ method: {
49
+ id: methodID,
50
+ type: "oauth",
51
+ label: "Muse Code subscription (Meta device login)",
52
+ },
53
+ async authorize() {
54
+ const device = await deviceAuthorize();
55
+ const url = device.verification_uri_complete || device.verification_uri;
56
+ const callback = (async () => {
57
+ const access = await pollToken(device.device_code, device.interval, device.expires_in);
58
+ const minted = await mintKey(access);
59
+ return {
60
+ type: "oauth",
61
+ methodID,
62
+ access: minted.apiKey,
63
+ refresh: "",
64
+ expires: Number.MAX_SAFE_INTEGER,
65
+ metadata: { accountId: minted.accountId, ...(minted.email ? { email: minted.email } : {}) },
66
+ };
67
+ })();
68
+ // The runtime awaits this promise after displaying the device code.
69
+ // Attach a handler immediately in case the exchange fails first.
70
+ void callback.catch(() => { });
71
+ return {
72
+ url,
73
+ instructions: `Open ${url}\nEnter code: ${device.user_code}`,
74
+ mode: "auto",
75
+ expiresAt: Date.now() + device.expires_in * 1000,
76
+ callback,
77
+ };
78
+ },
79
+ label: (credential) => typeof credential.metadata?.email === "string"
80
+ ? credential.metadata.email : "Muse Code subscription",
81
+ });
82
+ });
83
+ // Meta's native provider expects a bearer inference key, not the
84
+ // short-lived OAuth token used to mint it. Honor the active connection.
85
+ await ctx.session.hook("http.request", async (event) => {
86
+ const connection = await ctx.integration.connection.active("meta");
87
+ if (!connection)
88
+ return;
89
+ const credential = await ctx.integration.connection.resolve(connection);
90
+ if (credential?.type === "oauth" && credential.methodID === methodID) {
91
+ event.request.headers.set("Authorization", `Bearer ${credential.access}`);
92
+ }
93
+ }, { providerID: "meta" });
94
+ },
95
+ }),
96
+ server: MuseCodeAuth,
97
+ };
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // OpenCode V2 resolves local directories through their root entrypoint.
2
+ export { default } from "./dist/index.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-muse-auth",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "Muse Spark in opencode billed to the Muse Code monthly subscription (Meta device login, no API key)",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,6 +27,7 @@
27
27
  "plugin"
28
28
  ],
29
29
  "files": [
30
+ "index.js",
30
31
  "dist",
31
32
  "README.md",
32
33
  "LICENSE",
@@ -39,8 +40,11 @@
39
40
  "prepublishOnly": "npm run build"
40
41
  },
41
42
  "devDependencies": {
42
- "@opencode-ai/plugin": "^1.18.31",
43
+ "@opencode-ai/plugin": "^1.19.0",
43
44
  "@types/node": "^22.20.3",
44
45
  "typescript": "^7.0.2"
46
+ },
47
+ "dependencies": {
48
+ "@opencode/plugin": "^2.0.27"
45
49
  }
46
50
  }