opencode-plugin-litellm 1.6.0 → 1.6.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.
package/README.md CHANGED
@@ -245,6 +245,31 @@ between effort levels from the model picker without hand-curating every entry.
245
245
  > `mode: "responses"` the plugin routes it to `/v1/responses` automatically;
246
246
  > otherwise reach it without `reasoningEffort`. See the FAQ entry below.
247
247
 
248
+ On OpenCode 2, models whose effective package is `@opencode/ai/providers/anthropic`
249
+ or `@opencode/ai/providers/anthropic-compatible` get the same levels in the
250
+ shape that runtime reads, `{ thinking: { type: "adaptive", display: "summarized" }, effort }`,
251
+ for models LiteLLM reports with `supports_adaptive_thinking`, with `none`
252
+ becoming `thinking: { type: "disabled" }` (dropped when `thinking_always_on`).
253
+ Models without adaptive thinking get no variants on those packages, since
254
+ `reasoningEffort` would be ignored there. To reach Claude over the proxy's
255
+ `/v1/messages` while the rest of the catalog keeps its usual transport, split it
256
+ with [`includeModels`/`excludeModels`](#splitting-one-proxy-into-multiple-providers-includemodels--excludemodels):
257
+
258
+ ```jsonc
259
+ {
260
+ "providers": {
261
+ "litellm": {
262
+ "package": "@opencode/ai/providers/openai-compatible",
263
+ "settings": { "baseURL": "http://localhost:4000/v1", "excludeModels": ["*claude*"] }
264
+ },
265
+ "litellm-claude": {
266
+ "package": "@opencode/ai/providers/anthropic-compatible",
267
+ "settings": { "baseURL": "http://localhost:4000/v1", "includeModels": ["*claude*"] }
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
248
273
  ### Responses API models
249
274
 
250
275
  LiteLLM reports `mode` per model on `/v1/model/info` (the plugin fetches it
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.6.0",
4
+ "version": "1.6.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",
@@ -333,7 +333,8 @@ export function toConfigModel(
333
333
  * config (or translated into `Model.Info` on OpenCode 2). `responsesIds`
334
334
  * lists the subset that must be invoked through the OpenAI Responses API;
335
335
  * callers route those accordingly without inspecting each entry. `hints`
336
- * carries per-model upstream facts OpenCode 2 maps to `compatibility`.
336
+ * carries per-model upstream facts OpenCode 2 maps to `compatibility` and
337
+ * `variants`.
337
338
  */
338
339
  export interface DiscoveredModels {
339
340
  models: Record<string, unknown>
@@ -447,6 +448,8 @@ export async function discoverModels(
447
448
  const params = info?.supported_openai_params
448
449
  hints[model.id] = {
449
450
  acceptsCacheControl: Array.isArray(params) && params.includes('cache_control'),
451
+ adaptiveThinking: info?.supports_adaptive_thinking === true,
452
+ thinkingAlwaysOn: info?.thinking_always_on === true,
450
453
  }
451
454
  }
452
455
 
package/src/plugin/v2.ts CHANGED
@@ -39,6 +39,11 @@ const CHAT_COMPLETIONS_PACKAGES = new Set([
39
39
  OPENAI_COMPATIBLE_PACKAGE,
40
40
  '@opencode/ai/providers/openai/chat',
41
41
  ])
42
+ const ANTHROPIC_PACKAGES = new Set([
43
+ '@opencode/ai/providers/anthropic',
44
+ '@opencode/ai/providers/anthropic-compatible',
45
+ ])
46
+ const ADAPTIVE_THINKING = { type: 'adaptive', display: 'summarized' }
42
47
  // Runtime package that talks to `/v1/responses`. OpenCode 2 lets one model
43
48
  // override the provider's package, so Responses models stay under their
44
49
  // original provider id and no sibling provider is needed here.
@@ -126,6 +131,29 @@ function numberOrZero(value: unknown): number {
126
131
  return typeof value === 'number' && Number.isFinite(value) ? value : 0
127
132
  }
128
133
 
134
+ /**
135
+ * Discovery spells every effort level as `{ reasoningEffort }`, which the
136
+ * OpenAI runtimes read. The Anthropic runtimes read `thinking` and `effort`
137
+ * instead, so on those packages the levels are respelled the way OpenCode's
138
+ * own catalog does for adaptive-thinking Claude models. A model that does
139
+ * not report adaptive thinking gets no variants rather than inert ones.
140
+ */
141
+ function anthropicVariants(
142
+ variants: Model.Info['variants'],
143
+ hints: ModelHints | undefined,
144
+ ): Model.Info['variants'] {
145
+ if (!hints?.adaptiveThinking) return []
146
+ return variants.flatMap((variant) => {
147
+ const effort = variant.settings?.reasoningEffort
148
+ if (typeof effort !== 'string') return []
149
+ if (effort === 'none') {
150
+ if (hints.thinkingAlwaysOn) return []
151
+ return [{ ...variant, settings: { thinking: { type: 'disabled' } } }]
152
+ }
153
+ return [{ ...variant, settings: { thinking: ADAPTIVE_THINKING, effort } }]
154
+ })
155
+ }
156
+
129
157
  interface ToProviderModelsOptions {
130
158
  /** The provider's runtime package; models not overridden inherit it. */
131
159
  providerPackage: string
@@ -172,11 +200,14 @@ function toProviderModels(
172
200
  : []
173
201
 
174
202
  const rawVariants = asRecord(entry.variants)
175
- const variants = Object.entries(rawVariants).map(([id, settings]) => ({
203
+ const openAIVariants = Object.entries(rawVariants).map(([id, settings]) => ({
176
204
  id: id as Model.VariantID,
177
205
  settings: asRecord(settings),
178
206
  })) as Model.Info['variants']
179
207
  const pkg = responsesIds.has(modelID) ? RESPONSES_PACKAGE : options.providerPackage
208
+ const variants = ANTHROPIC_PACKAGES.has(pkg)
209
+ ? anthropicVariants(openAIVariants, hints[modelID])
210
+ : openAIVariants
180
211
  const compatibility = resolveCompatibility(
181
212
  inferCompatibility(hints[modelID], CHAT_COMPLETIONS_PACKAGES.has(pkg)),
182
213
  Object.hasOwn(overrides, modelID) ? overrides[modelID] : undefined,
@@ -71,6 +71,8 @@ export interface LiteLLMModelInfo {
71
71
  supported_openai_params?: string[] | null
72
72
  supports_pdf_input?: boolean
73
73
  supports_audio_input?: boolean
74
+ supports_adaptive_thinking?: boolean
75
+ thinking_always_on?: boolean
74
76
  input_cost_per_token?: number
75
77
  output_cost_per_token?: number
76
78
  cache_read_input_token_cost?: number
@@ -5,8 +5,9 @@ import { join } from 'node:path'
5
5
 
6
6
  /**
7
7
  * Facts about a discovered model's upstream that OpenCode 2 turns into
8
- * `Model.Info.compatibility`. They ride alongside the config-shaped model
9
- * entries (which have no field for them) through discovery and the cache.
8
+ * `Model.Info.compatibility` and `variants`. They ride alongside the
9
+ * config-shaped model entries (which have no field for them) through
10
+ * discovery and the cache.
10
11
  */
11
12
  export interface ModelHints {
12
13
  /**
@@ -14,6 +15,13 @@ export interface ModelHints {
14
15
  * Chat Completions (`supported_openai_params` lists `cache_control`).
15
16
  */
16
17
  acceptsCacheControl: boolean
18
+ /**
19
+ * The model takes `thinking: { type: "adaptive" }` plus an `effort` level
20
+ * (`supports_adaptive_thinking`).
21
+ */
22
+ adaptiveThinking: boolean
23
+ /** Thinking cannot be turned off (`thinking_always_on`). */
24
+ thinkingAlwaysOn: boolean
17
25
  }
18
26
 
19
27
  /**
@@ -21,7 +29,7 @@ export interface ModelHints {
21
29
  * from older plugin versions are ignored rather than deserialized into
22
30
  * an incompatible structure.
23
31
  */
24
- const CACHE_VERSION = 4
32
+ const CACHE_VERSION = 5
25
33
 
26
34
  /**
27
35
  * Maximum age of a cache entry before it's treated as a miss. Without a
@@ -158,8 +166,12 @@ function normalizeHints(value: unknown): Record<string, ModelHints> {
158
166
  const out: Record<string, ModelHints> = {}
159
167
  for (const [id, hint] of Object.entries(value as Record<string, unknown>)) {
160
168
  if (!hint || typeof hint !== 'object' || Array.isArray(hint)) continue
161
- const { acceptsCacheControl } = hint as Record<string, unknown>
162
- out[id] = { acceptsCacheControl: acceptsCacheControl === true }
169
+ const { acceptsCacheControl, adaptiveThinking, thinkingAlwaysOn } = hint as Record<string, unknown>
170
+ out[id] = {
171
+ acceptsCacheControl: acceptsCacheControl === true,
172
+ adaptiveThinking: adaptiveThinking === true,
173
+ thinkingAlwaysOn: thinkingAlwaysOn === true,
174
+ }
163
175
  }
164
176
  return out
165
177
  }