| 1 | # Plugin-defined AI providers and OAuth |
| 2 | |
| 3 | A reviewed plugin can declare named AI providers in |
| 4 | `extensions.net.codewhale.providers` in `plugin.json` (or `[providers.<name>]` |
| 5 | in a legacy `plugin.toml`). These declarations extend the existing named |
| 6 | OpenAI-compatible routes; they do not replace the inference engine or create a |
| 7 | second turn loop. See [the complete example](examples/plugins/oauth-provider/plugin.json). |
| 8 | |
| 9 | The host owns authorization, callback handling, token storage and refresh. |
| 10 | Provider declarations contain public configuration only. Plugin JavaScript, |
| 11 | tools, the model transcript and frontends never receive OAuth token material. |
| 12 | No Codewhale release number is embedded in a declaration: compatibility follows |
| 13 | the manifest schema and the provider capability supported by the host. |
| 14 | |
| 15 | ## Declare and review a provider |
| 16 | |
| 17 | Copy the example to your plugin directory and change its provider ID, API base |
| 18 | URL, model IDs, OAuth endpoints, public client ID, scopes and optional resource. |
| 19 | Register the public OAuth client with the authorization server, permitting the |
| 20 | loopback redirect `http://127.0.0.1:<dynamic-port>/<callback-path>` and PKCE S256. |
| 21 | The host does not use a client secret. |
| 22 | Authorization and token endpoints must share the declared issuer origin; |
| 23 | cross-origin OIDC discovery is not part of this declaration. HTTPS is required, |
| 24 | with plain HTTP allowed only on local loopback for development. |
| 25 | |
| 26 | The provider ID must be a custom lowercase plugin-style identifier. It cannot |
| 27 | shadow a builtin provider, a configured custom provider or another plugin's |
| 28 | provider. The existing chooser may persist a model-only |
| 29 | `[providers.<plugin-provider-id>]` preference; that preference changes the |
| 30 | selected model, never the reviewed endpoint, authentication or headers. A table |
| 31 | containing any other provider setting remains a collision. Model IDs are exact |
| 32 | wire IDs, not renamed builtin model profiles. |
| 33 | Metadata not provided by the server remains unknown. Optional `http_headers` |
| 34 | can supply public project/group routing metadata to the existing HTTP client. |
| 35 | Authorization, cookies, host overrides and transport-control headers are |
| 36 | refused; never put credentials in a plugin manifest. Plugin requests use only |
| 37 | their reviewed public routing headers and do not inherit global headers from |
| 38 | other provider connections. |
| 39 | |
| 40 | Install, validate, trust and enable the bundle through Codewhale's existing |
| 41 | plugin commands. The review receipt covers the full manifest, the provider |
| 42 | capability, the API destination and OAuth endpoint origins. Installing a bundle |
| 43 | alone does not authorize it, contact an endpoint or start a login. A changed |
| 44 | manifest or capability requires a fresh review; start a new runtime after |
| 45 | changing declarations. |
| 46 | |
| 47 | Adding provider authority advances the activation policy to v5. With the |
| 48 | plugin host enabled, policy v8 permits namespaced aliases for commands |
| 49 | that collide with built-in names and Engine-brokered read-only Git review scopes. Receipts from the previous policy require an |
| 50 | explicit review again, including bundles without provider declarations. An |
| 51 | old review is never silently upgraded. |
| 52 | |
| 53 | ## Connect inside Codewhale |
| 54 | |
| 55 | After installation, review and enable the bundle, then start a new session. |
| 56 | Run `/connect` to open the provider picker, or `/connect <provider-id>` to authorize |
| 57 | an enabled plugin directly. The host runs its existing PKCE flow and then |
| 58 | refreshes the provider’s standard `/models` roster. Choose the model explicitly; |
| 59 | login never chooses the first model, changes billing groups, or copies another |
| 60 | application’s credentials. A provider selected from `/provider` uses the same |
| 61 | flow instead of asking for an API key. |
| 62 | |
| 63 | `/login` stays Codewhale-account sign-in. `/disconnect <provider-id>` removes only that |
| 64 | plugin’s local grant. `/logout` stays Codewhale account logout. |
| 65 | Plugin rosters are account-scoped and not reused from the disk cache. |
| 66 | The terminal is temporarily suspended during browser authorization, like the |
| 67 | built-in PKCE flows; device-code and remote revocation are not added here. |
| 68 | A successful authorization followed by a catalog failure retains the grant; |
| 69 | retry catalog refresh rather than copying a token or running a companion login. |
| 70 | |
| 71 | ## Terminal and noninteractive clients |
| 72 | |
| 73 | ```sh |
| 74 | codewhale auth plugin-login --provider example-oauth |
| 75 | codewhale --provider example-oauth --model example-chat exec 'Say hello.' |
| 76 | codewhale auth plugin-logout --provider example-oauth |
| 77 | ``` |
| 78 | |
| 79 | `plugin-login` opens the system browser and waits on an ephemeral IPv4 loopback |
| 80 | listener. Set `CODEWHALE_PLUGIN_OAUTH_NO_BROWSER=1` to open the printed URL |
| 81 | manually on the same machine. This is not a device-code or remote SSH flow. |
| 82 | Denial, malformed callbacks, mismatched state and a conflicting callback issuer |
| 83 | fail without storing new credentials. An issuer may supply the RFC 9207 `iss` |
| 84 | parameter; when present it must equal the reviewed issuer. |
| 85 | |
| 86 | The credential slot binds the exact provider ID, API base URL and complete OAuth |
| 87 | descriptor. A different plugin endpoint, client, issuer, scope or resource cannot |
| 88 | reuse that grant. Expiring tokens refresh under the existing secure-store entry |
| 89 | transaction, including rotation. Client construction and generic config-key |
| 90 | reads never resolve or expose the bearer; only the request worker accesses it. |
| 91 | Read-only diagnostics, including live diagnostic probes, do not refresh tokens |
| 92 | or migrate credential storage. A probe with an expired token therefore fails |
| 93 | without contacting the issuer. |
| 94 | Each actual request checks current plugin authority, binds its endpoint, OAuth |
| 95 | configuration and public headers to the reviewed declaration, then resolves the |
| 96 | current host-owned credential. Candidate routes or in-memory configuration edits |
| 97 | cannot borrow a receipt for a different endpoint or authentication configuration. Disabling or revoking a plugin stops a previously built |
| 98 | client before its next request. Requests and token exchange refuse redirects |
| 99 | that could forward credentials to another destination. |
| 100 | |
| 101 | Logout removes the local credential. Removing a plugin or changing its |
| 102 | manifest does not silently erase stored grants, nor does local logout revoke |
| 103 | an authorization-server session. Use that server's account page to revoke the |
| 104 | remote grant if needed. |
| 105 | |
| 106 | ## Current scope |
| 107 | |
| 108 | The declaration supports standard public-client authorization-code PKCE and |
| 109 | OpenAI-compatible Chat Completions, including streaming, and the existing |
| 110 | `/models` catalog. Token responses must specify Bearer token type and a positive |
| 111 | `expires_in`; tokens with an unknown lifetime are refused. HTTP failure bodies |
| 112 | from plugin endpoints are withheld so an echoed rotated opaque bearer cannot |
| 113 | leak into logs or frontends. It does not execute custom authorization/refresh callbacks, |
| 114 | load arbitrary inference protocol code, provide device authorization, use a |
| 115 | client secret or implement remote revocation. A server using another wire |
| 116 | protocol needs a host protocol adapter rather than a fictitious supported kind. |
| 117 | The existing plugin host still owns executable tools; provider declarations |
| 118 | remain data and do not require that experimental feature. |
| 119 | |
| 120 | Providers do not add session-context contributors or volatile prompt prefixes. |
| 121 | Inference continues through the existing logged turn loop and normal request |
| 122 | construction, so this extension has no new KV-cache-prefix effect. |
| 123 |