opencode-plugin-litellm 1.11.0 → 1.11.1

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.
Files changed (3) hide show
  1. package/README.md +18 -17
  2. package/package.json +5 -1
  3. package/src/plugin/v2.ts +43 -22
package/README.md CHANGED
@@ -18,13 +18,16 @@
18
18
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](./LICENSE)
19
19
  [![TypeScript](https://img.shields.io/badge/TypeScript-strict-3178c6?style=flat-square&logo=typescript&logoColor=white)](./tsconfig.json)
20
20
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen?style=flat-square)](./CONTRIBUTING.md)
21
+ [![Sponsor](https://img.shields.io/badge/sponsor-GitHub%20Sponsors-ea4aaa?style=flat-square&logo=githubsponsors&logoColor=white)](https://github.com/sponsors/yuseferi)
21
22
 
22
23
  Auto-detect a running LiteLLM proxy, pull every model from `/v1/models`, and register them in OpenCode.
23
24
  **No model lists to hand-maintain. No restart loops. No surprises.**
24
25
 
25
26
  <img src="https://raw.githubusercontent.com/yuseferi/opencode-litellm/main/assets/architecture.svg" alt="How opencode-litellm works: OpenCode registers discovered LiteLLM models through the provider API and refreshes its provider registry from a disk cache" width="100%" />
26
27
 
27
- [Quickstart](#-quickstart) · [Configuration](#%EF%B8%8F-configuration) · [How it works](#-how-it-works) · [FAQ](#-faq) · [Contributing](./CONTRIBUTING.md)
28
+ [Quickstart](#-quickstart) · [Configuration](#%EF%B8%8F-configuration) · [How it works](#-how-it-works) · [FAQ](#-faq) · [Contributing](./CONTRIBUTING.md) · [Sponsor](#-sponsor)
29
+
30
+ **Enjoying the plugin? [⭐ Star the repo](https://github.com/yuseferi/opencode-litellm)** — stars are how other OpenCode users find it.
28
31
 
29
32
  </div>
30
33
 
@@ -46,9 +49,9 @@ Maintaining a `models` block in `opencode.json` for every model your LiteLLM pro
46
49
 
47
50
  ## 🚀 Quickstart
48
51
 
49
- After a V2-compatible release is published, install the plugin from the CLI
50
- and configure the shared background service. If your OpenCode 2 executable is
51
- named `opencode2`, use it in place of `opencode` below.
52
+ Install the plugin from the CLI and configure the shared background service.
53
+ If your OpenCode 2 executable is named `opencode2`, use it in place of
54
+ `opencode` below.
52
55
 
53
56
  ```bash
54
57
  opencode plugin add opencode-plugin-litellm
@@ -58,10 +61,6 @@ opencode service set env LITELLM_API_KEY YOUR_API_KEY
58
61
 
59
62
  Then open OpenCode and select a discovered model under `litellm/...`.
60
63
 
61
- > **RFC status:** OpenCode 2 support is not yet included in the published npm
62
- > package. For now, `plugin add` installs the previous release, not this RFC
63
- > implementation.
64
-
65
64
  For a local LiteLLM proxy on port 4000, the base URL can be omitted and the
66
65
  plugin will detect it automatically. The [configuration section](#%EF%B8%8F-configuration)
67
66
  also shows how to configure a provider directly in `opencode.json`.
@@ -334,7 +333,7 @@ If your LiteLLM proxy requires a master key, expose it via any of these approach
334
333
  | Env var (alias) | `export LITELLM_MASTER_KEY=sk-...` |
335
334
  | Config | `"settings": { "apiKey": "{env:LITELLM_API_KEY}" }` |
336
335
 
337
- The env var path lets you commit `opencode.json` without leaking secrets. `/connect` credentials are read from OpenCode's auth store (`~/.local/share/opencode/auth.json`) and applied to health checks, model discovery, and completion-time requests on BOTH OpenCode 1 and OpenCode 2. On OpenCode 2, a credential saved through `/connect` is a first-class integration connection: the plugin registers the **LiteLLM** integration with an API-key form, uses the stored key for discovery, and lets OpenCode inject it into completion requests — the key never appears in `opencode.json` or provider settings. A credential the user saves in the box (the active connection or the auth-store entry) wins over `LITELLM_API_KEY` / `LITELLM_MASTER_KEY`; the environment is a box-level fallback, never an override of a saved key.
336
+ The env var path lets you commit `opencode.json` without leaking secrets. `/connect` credentials are read from wherever OpenCode keeps them — the provider's connection on OpenCode 2, and OpenCode's auth store (`~/.local/share/opencode/auth.json`) on OpenCode 1 and on 2.x boxes that still write it — and applied to health checks, model discovery, and completion-time requests on BOTH OpenCode 1 and OpenCode 2. On OpenCode 2, a credential saved through `/connect` is a first-class integration connection: the plugin registers the **LiteLLM** integration with an API-key form, uses the stored key for discovery, and lets OpenCode inject it into completion requests — the key never appears in `opencode.json` or provider settings. A config-defined provider keeps its key on an integration named after its own id, so a `litellm-team-a` provider uses the key connected for `litellm-team-a` and falls back to the plugin's `litellm` integration only when that one has no connection. A credential the user saves in the box (the active connection or the auth-store entry) wins over `LITELLM_API_KEY` / `LITELLM_MASTER_KEY`; the environment is a box-level fallback, never an override of a saved key.
338
337
 
339
338
  #### Web UI connect (OpenCode 2)
340
339
 
@@ -790,6 +789,16 @@ See [`CONTRIBUTING.md`](./CONTRIBUTING.md) for the full contributor workflow.
790
789
 
791
790
  Have an idea? [Open an issue](https://github.com/yuseferi/opencode-litellm/issues/new).
792
791
 
792
+ ## 💖 Sponsor
793
+
794
+ This plugin is free, MIT-licensed, and stays that way. If it saves you time, you can
795
+ support its maintenance through **[GitHub Sponsors](https://github.com/sponsors/yuseferi)** —
796
+ one-off or recurring, cancel anytime.
797
+
798
+ [![Sponsor yuseferi on GitHub Sponsors](https://img.shields.io/badge/sponsor-GitHub%20Sponsors-ea4aaa?style=flat-square&logo=githubsponsors&logoColor=white)](https://github.com/sponsors/yuseferi)
799
+
800
+ Not in a position to sponsor? A bug report or a PR helps just as much.
801
+
793
802
  ## 🙏 Acknowledgements
794
803
 
795
804
  Inspired by [`opencode-lmstudio`](https://github.com/agustif/opencode-lmstudio) by [@agustif](https://github.com/agustif) — the architectural blueprint for OpenCode model-discovery plugins.
@@ -799,11 +808,3 @@ Built on top of [LiteLLM](https://github.com/BerriAI/litellm) by the [BerriAI](h
799
808
  ## 📄 License
800
809
 
801
810
  [MIT](./LICENSE) © [Yusef Mohamadi](https://github.com/yuseferi)
802
-
803
- ---
804
-
805
- <div align="center">
806
-
807
- If this project saved you time, consider giving it a ⭐ on [GitHub](https://github.com/yuseferi/opencode-litellm).
808
-
809
- </div>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "opencode-plugin-litellm",
4
- "version": "1.11.0",
4
+ "version": "1.11.1",
5
5
  "description": "OpenCode CLI (v1 and v2) and Desktop plugin for LiteLLM proxy support with auto-detection and dynamic model discovery",
6
6
  "type": "module",
7
7
  "main": "./src/index.ts",
@@ -33,6 +33,10 @@
33
33
  "url": "https://github.com/yuseferi/opencode-litellm/issues"
34
34
  },
35
35
  "homepage": "https://github.com/yuseferi/opencode-litellm#readme",
36
+ "funding": {
37
+ "type": "github",
38
+ "url": "https://github.com/sponsors/yuseferi"
39
+ },
36
40
  "publishConfig": {
37
41
  "access": "public",
38
42
  "provenance": true
package/src/plugin/v2.ts CHANGED
@@ -533,23 +533,43 @@ async function makeProviderSource(
533
533
  const settings = { ...pluginOptions, ...providerSettings }
534
534
  const customHeaders = providerHeaders(pluginOptions, settings, provider)
535
535
  const configuredBaseURL = readString(settings.baseURL)
536
- // Credential plus dialog form answers. A provider wired to its own
537
- // integration keeps using exactly that one; otherwise the plugin's
538
- // registered integration is consulted, so a gateway can be connected
539
- // entirely from the web UI with no hand-written config.
540
- let connected: ConnectedLiteLLM | undefined = await readConnectedConfig(
541
- context,
542
- provider?.integrationID ?? LITELLM_INTEGRATION_ID,
543
- )
544
- // A base URL configured for another proxy turns the sign-in off.
545
- if (connected?.credentialID && !signInReaches(connected.baseURL, configuredBaseURL)) {
546
- connected = undefined
536
+ // Credential plus dialog form answers. Which integration to read depends on
537
+ // how the provider got here:
538
+ // 1. a provider wired to its own integration keeps using exactly that one;
539
+ // 2. a config-defined provider owns no integrationID, but `/connect` files
540
+ // its key under an integration named after the provider id — so for
541
+ // `litellm-a` the key lives in `litellm-a`, not in `litellm`;
542
+ // 3. the plugin's registered integration is the fallback, so a gateway can
543
+ // be connected entirely from the web UI with no hand-written config.
544
+ const idHint = provider?.id ?? readString(pluginOptions.providerID)
545
+ const integrationCandidates: string[] = []
546
+ if (provider?.integrationID) {
547
+ // Explicitly linked: authoritative, never widened to another integration.
548
+ integrationCandidates.push(provider.integrationID)
549
+ } else {
550
+ if (idHint) integrationCandidates.push(idHint)
551
+ if (!integrationCandidates.includes(LITELLM_INTEGRATION_ID)) {
552
+ integrationCandidates.push(LITELLM_INTEGRATION_ID)
553
+ }
554
+ }
555
+ let connected: ConnectedLiteLLM | undefined
556
+ // The integration that actually supplied the credential. Recorded on the
557
+ // source so refresh and `credential.switched` re-read the same one.
558
+ let connectedIntegrationID: string | undefined
559
+ for (const candidateID of integrationCandidates) {
560
+ const candidate = await readConnectedConfig(context, candidateID)
561
+ // A base URL configured for another proxy turns the sign-in off.
562
+ if (
563
+ !candidate ||
564
+ (candidate.credentialID && !signInReaches(candidate.baseURL, configuredBaseURL))
565
+ ) {
566
+ continue
567
+ }
568
+ connected = candidate
569
+ connectedIntegrationID = candidateID
570
+ break
547
571
  }
548
- const id =
549
- provider?.id ??
550
- readString(pluginOptions.providerID) ??
551
- connected?.providerID ??
552
- CHAT_PROVIDER_ID
572
+ const id = idHint ?? connected?.providerID ?? CHAT_PROVIDER_ID
553
573
  const connectedApiKey = connected?.apiKey
554
574
  // Precedence rule: an explicit settings/plugin-options apiKey is the
555
575
  // operator's deliberate config and stays first; then a credential the user
@@ -559,16 +579,17 @@ async function makeProviderSource(
559
579
  // override of the user's explicit choice.
560
580
  const settingsApiKey = readString(providerSettings.apiKey) ?? readString(pluginOptions.apiKey)
561
581
  const envApiKey = process.env.LITELLM_API_KEY ?? process.env.LITELLM_MASTER_KEY
562
- // The key OpenCode itself stored for this provider in the box auth store
563
- // (/connect journey). A config-defined provider carries no integrationID, so
564
- // the host-integration path above cannot see it — read the store directly,
565
- // exactly like the v1 entrypoint does. Still ahead of the env: a saved
566
- // credential is the user's explicit choice and beats the box-level fallback.
582
+ // The key OpenCode stored for this provider in the box auth store — the
583
+ // `/connect` journey on boxes that still keep `auth.json`. OpenCode 2.3 keeps
584
+ // credentials in its own database instead, so this is the legacy fallback;
585
+ // the connection read above is the current path. Still ahead of the env: a
586
+ // saved credential is the user's explicit choice and beats the box-level
587
+ // fallback.
567
588
  const storedKey = await getOpenCodeStoredApiKey(id)
568
589
  const usesConnectionCredential = settingsApiKey === undefined && connectedApiKey !== undefined
569
590
  const integrationID =
570
591
  provider?.integrationID ??
571
- (usesConnectionCredential ? LITELLM_INTEGRATION_ID : undefined)
592
+ (usesConnectionCredential ? connectedIntegrationID : undefined)
572
593
  const apiKey = settingsApiKey ?? connectedApiKey ?? storedKey ?? envApiKey
573
594
  const filters = readModelFilters(settings)
574
595
  const capabilities = parseModelCapabilities(settings.modelCapabilities)