From c4184814c6cf7eca07a611e10a1e75c006142c9b Mon Sep 17 00:00:00 2001 From: Stephane Segning Lambou Date: Tue, 26 May 2026 11:18:46 +0200 Subject: [PATCH 1/2] fix(plugin): slim main entry to plugin function only OpenCode's plugin loader iterates every named export of the resolved plugin module and requires each value to be a function (or `{ server: fn }`). The package's `dist/index.js` re-exported two number constants (`DEFAULT_HTTP_TIMEOUT_MS`, `DEFAULT_SYNC_INTERVAL_MINUTES`), which caused `TypeError: Plugin export is not a function` on load. Every other named function (validateConfig, fetchModels, FileCacheStore, even the factory itself) would also have been invoked as a plugin. Restructure so the OpenCode entry exposes only the plugin function, and move the library API to a `./lib` subpath via the `exports` map. - src/index.ts: re-exports only `default` from ./opencode.js - src/lib.ts (new): holds the former named exports - package.json: adds `exports` map with `.` (plugin) and `./lib` (API) - docs/troubleshooting.md: updates embedder example to `/lib` subpath Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/troubleshooting.md | 2 +- packages/opencode-oauth2/package.json | 11 ++++++++ packages/opencode-oauth2/src/index.ts | 40 ++++----------------------- packages/opencode-oauth2/src/lib.ts | 31 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 packages/opencode-oauth2/src/lib.ts diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 14bb170..1029d5a 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -148,7 +148,7 @@ echo "$jwt" | cut -d. -f2 | base64 -d 2>/dev/null | jq '{aud, iss, sub}' The principled fix on the embedder side: ```ts -import { OAuth2ModelSyncPlugin } from "@vymalo/opencode-oauth2"; +import { OAuth2ModelSyncPlugin } from "@vymalo/opencode-oauth2/lib"; const runtime = new OAuth2ModelSyncPlugin(cfg, { /* ... */ }); await runtime.initialize(); await runtime.start({ warmup: true, interactive: false }); diff --git a/packages/opencode-oauth2/package.json b/packages/opencode-oauth2/package.json index a12a9df..905d068 100644 --- a/packages/opencode-oauth2/package.json +++ b/packages/opencode-oauth2/package.json @@ -25,6 +25,17 @@ "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + }, + "./lib": { + "types": "./dist/lib.d.ts", + "import": "./dist/lib.js" + }, + "./package.json": "./package.json" + }, "sideEffects": false, "files": [ "dist" diff --git a/packages/opencode-oauth2/src/index.ts b/packages/opencode-oauth2/src/index.ts index df6500d..3f2c4d7 100644 --- a/packages/opencode-oauth2/src/index.ts +++ b/packages/opencode-oauth2/src/index.ts @@ -1,35 +1,5 @@ -export { - DEFAULT_HTTP_TIMEOUT_MS, - DEFAULT_SYNC_INTERVAL_MINUTES, - type OAuth2ModelSyncConfig, - type OAuth2ModelSyncConfigInput, - type OAuthServerConfig, - type OAuthServerConfigInput, - validateConfig -} from "./config.js"; - -export { createJsonConsoleLogger, type LogLevel, type Logger } from "./logging.js"; - -export { buildModelsUrl, fetchModels } from "./model-discovery.js"; - -export { diffModels, normalizeModelId, normalizeModelList } from "./model-normalization.js"; - -export { OAuth2ModelSyncPlugin, type PluginOptions } from "./plugin.js"; - -export { resolveCacheDir, FileCacheStore } from "./cache.js"; - -export { - createOpencodeOauth2Plugin, - OpencodeOauth2Plugin, - OpencodeOauth2Plugin as default -} from "./opencode.js"; -export type { OpenCodePluginFactoryOptions } from "./opencode.js"; - -export type { - CachedServerState, - ModelDiff, - NormalizedModel, - RawModel, - ServerSnapshot, - TokenSet -} from "./types.js"; +// OpenCode plugin entry. The host iterates every named export of this module +// and rejects any export that isn't a Plugin function (or { server: Plugin }). +// Only the plugin function lives here; the library API is in ./lib.ts and is +// exposed via the "./lib" subpath in package.json. +export { default } from "./opencode.js"; diff --git a/packages/opencode-oauth2/src/lib.ts b/packages/opencode-oauth2/src/lib.ts new file mode 100644 index 0000000..484dfdc --- /dev/null +++ b/packages/opencode-oauth2/src/lib.ts @@ -0,0 +1,31 @@ +export { + DEFAULT_HTTP_TIMEOUT_MS, + DEFAULT_SYNC_INTERVAL_MINUTES, + type OAuth2ModelSyncConfig, + type OAuth2ModelSyncConfigInput, + type OAuthServerConfig, + type OAuthServerConfigInput, + validateConfig +} from "./config.js"; + +export { createJsonConsoleLogger, type LogLevel, type Logger } from "./logging.js"; + +export { buildModelsUrl, fetchModels } from "./model-discovery.js"; + +export { diffModels, normalizeModelId, normalizeModelList } from "./model-normalization.js"; + +export { OAuth2ModelSyncPlugin, type PluginOptions } from "./plugin.js"; + +export { resolveCacheDir, FileCacheStore } from "./cache.js"; + +export { createOpencodeOauth2Plugin } from "./opencode.js"; +export type { OpenCodePluginFactoryOptions } from "./opencode.js"; + +export type { + CachedServerState, + ModelDiff, + NormalizedModel, + RawModel, + ServerSnapshot, + TokenSet +} from "./types.js"; From b8641d1a41e1f273cce922558eca648bc53cb327 Mon Sep 17 00:00:00 2001 From: Stephane Segning Lambou Date: Tue, 26 May 2026 11:22:47 +0200 Subject: [PATCH 2/2] chore: bump version to 0.2.1 Patch release for the plugin-entry fix. Co-Authored-By: Claude Opus 4.7 (1M context) --- package.json | 2 +- packages/opencode-oauth2/package.json | 2 +- packages/plugin-bundle/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0793334..fe8de04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opencode-oauth2-workspace", - "version": "0.2.0", + "version": "0.2.1", "private": true, "description": "Workspace for @vymalo/opencode-oauth2 — OAuth2/OIDC-secured OpenAI-compatible providers for OpenCode.", "packageManager": "pnpm@11.3.0", diff --git a/packages/opencode-oauth2/package.json b/packages/opencode-oauth2/package.json index 905d068..8c3bd1c 100644 --- a/packages/opencode-oauth2/package.json +++ b/packages/opencode-oauth2/package.json @@ -1,6 +1,6 @@ { "name": "@vymalo/opencode-oauth2", - "version": "0.2.0", + "version": "0.2.1", "description": "OpenCode plugin for OAuth2/OIDC-secured, OpenAI-compatible model providers with periodic model sync.", "license": "MIT", "author": "vymalo contributors", diff --git a/packages/plugin-bundle/package.json b/packages/plugin-bundle/package.json index e8ef53c..27dd9b8 100644 --- a/packages/plugin-bundle/package.json +++ b/packages/plugin-bundle/package.json @@ -1,6 +1,6 @@ { "name": "@vymalo/opencode-oauth2-bundle", - "version": "0.2.0", + "version": "0.2.1", "private": true, "type": "module", "scripts": {