opencode-plugin-litellm 1.4.1 → 1.4.3
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 +22 -6
- package/package.json +1 -1
- package/src/plugin/v2.ts +6 -0
- package/src/types/index.ts +2 -0
- package/src/utils/litellm-api.ts +2 -17
- package/src/utils/reasoning-efforts.ts +90 -0
package/README.md
CHANGED
|
@@ -211,12 +211,28 @@ Here, `openai/gpt-4o` keeps your custom name; every other model from the proxy i
|
|
|
211
211
|
All discovered models — reasoning-tier included — register under your single
|
|
212
212
|
LiteLLM provider and are invoked through `/v1/chat/completions`.
|
|
213
213
|
|
|
214
|
-
If LiteLLM reports per-model reasoning-effort support
|
|
215
|
-
`
|
|
216
|
-
`
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
214
|
+
If LiteLLM reports per-model reasoning-effort support, the plugin automatically
|
|
215
|
+
surfaces it as OpenCode variants. Explicit `reasoning_effort_levels` (or
|
|
216
|
+
`supports_reasoning_efforts`) lists take precedence, including empty lists.
|
|
217
|
+
Otherwise, per-level `supports_*_reasoning_effort` flags enable discovery:
|
|
218
|
+
`low`, `medium`, and `high` are included unless explicitly disabled, while
|
|
219
|
+
optional levels such as `none`, `minimal`, `xhigh`, and `max` require an explicit
|
|
220
|
+
`true`. This handles sparse metadata such as GPT-6 Astra's `xhigh`/`max` flags
|
|
221
|
+
without losing its baseline levels. No levels are inferred from
|
|
222
|
+
`supports_reasoning: true` alone, or from negative-only effort flags when
|
|
223
|
+
reasoning support is unknown. Inferred variants are also suppressed when
|
|
224
|
+
`supported_openai_params` lists neither `reasoning_effort` nor `reasoning`.
|
|
225
|
+
Metadata is read from `model_info`, falling back to `litellm_params` for
|
|
226
|
+
missing/null values.
|
|
227
|
+
|
|
228
|
+
When explicit effort lists are absent, known GPT-5 Pro restrictions also apply:
|
|
229
|
+
GPT-5 Pro is limited to `high`, and GPT-5.2 Pro / GPT-5.4 Pro to `medium`, `high`,
|
|
230
|
+
and explicitly supported `xhigh`. These restrictions use the upstream model key
|
|
231
|
+
or `litellm_params.model`, including provider prefixes and dated snapshots, so
|
|
232
|
+
deployment aliases work too. An explicit effort list can override this fallback.
|
|
233
|
+
|
|
234
|
+
Each variant sets `reasoningEffort` to the reported level, so you can switch
|
|
235
|
+
between effort levels from the model picker without hand-curating every entry.
|
|
220
236
|
|
|
221
237
|
> **Note**: OpenAI's reasoning-tier models (gpt-5, o1, o3, o4) reject
|
|
222
238
|
> requests that combine `reasoning_effort` with function tools on
|
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.4.
|
|
4
|
+
"version": "1.4.3",
|
|
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",
|
package/src/plugin/v2.ts
CHANGED
|
@@ -487,6 +487,12 @@ async function reconcileProviderSources(
|
|
|
487
487
|
const definition = Plugin.define({
|
|
488
488
|
id: 'opencode-litellm',
|
|
489
489
|
async setup(context) {
|
|
490
|
+
// OpenCode 1.18.x embeds a v2 plugin host whose context has no `provider`
|
|
491
|
+
// domain. It still calls `setup` on any plugin that exports one, but those
|
|
492
|
+
// versions are served by the `server()` entrypoint below. Bail out before
|
|
493
|
+
// touching the logger so `server()`'s client-backed logging stays intact.
|
|
494
|
+
if (!context.provider) return
|
|
495
|
+
|
|
490
496
|
initV2Logging()
|
|
491
497
|
|
|
492
498
|
const pluginOptions = asRecord(context.options)
|
package/src/types/index.ts
CHANGED
|
@@ -67,6 +67,8 @@ export interface LiteLLMModelInfo {
|
|
|
67
67
|
supports_vision?: boolean
|
|
68
68
|
supports_reasoning?: boolean
|
|
69
69
|
supports_reasoning_efforts?: string[]
|
|
70
|
+
reasoning_effort_levels?: string[] | null
|
|
71
|
+
supported_openai_params?: string[] | null
|
|
70
72
|
supports_pdf_input?: boolean
|
|
71
73
|
supports_audio_input?: boolean
|
|
72
74
|
input_cost_per_token?: number
|
package/src/utils/litellm-api.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LiteLLMModel, LiteLLMModelInfo, LiteLLMModelInfoResponse, LiteLLMModelsResponse } from '../types'
|
|
2
2
|
import { CAPABILITY_FLAGS } from './model-capabilities'
|
|
3
|
+
import { resolveReasoningEfforts } from './reasoning-efforts'
|
|
3
4
|
|
|
4
5
|
export const DEFAULT_LITELLM_URL = 'http://localhost:4000'
|
|
5
6
|
const MODELS_ENDPOINT = '/v1/models'
|
|
@@ -136,23 +137,7 @@ export async function discoverLiteLLMModelInfo(
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
const reasoningEffortPattern = /^supports_([a-z]+)_reasoning_effort$/
|
|
141
|
-
const efforts = new Set<string>()
|
|
142
|
-
for (const source of [info, entry.litellm_params]) {
|
|
143
|
-
if (!source || typeof source !== 'object') continue
|
|
144
|
-
for (const [key, value] of Object.entries(source)) {
|
|
145
|
-
const match = key.match(reasoningEffortPattern)
|
|
146
|
-
if (match && value === true) {
|
|
147
|
-
efforts.add(match[1])
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (efforts.size > 0) {
|
|
152
|
-
info.supports_reasoning_efforts = [
|
|
153
|
-
...new Set([...(info.supports_reasoning_efforts ?? []), ...efforts]),
|
|
154
|
-
]
|
|
155
|
-
}
|
|
140
|
+
info.supports_reasoning_efforts = resolveReasoningEfforts(info, entry.litellm_params)
|
|
156
141
|
|
|
157
142
|
// Index under every alias LiteLLM may use for this model — the
|
|
158
143
|
// `/v1/models` id can match any of them depending on how the
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { LiteLLMModelInfo } from '../types'
|
|
2
|
+
|
|
3
|
+
// LiteLLM's sparse flags do not encode these provider restrictions reliably.
|
|
4
|
+
// Constrain inference only; explicit deployment effort lists still win.
|
|
5
|
+
// https://developers.openai.com/api/docs/models/gpt-5-pro
|
|
6
|
+
// https://developers.openai.com/api/docs/models/gpt-5.2-pro
|
|
7
|
+
// https://developers.openai.com/api/docs/models/gpt-5.4-pro
|
|
8
|
+
const RESTRICTED_EFFORTS = new Map<string, readonly string[]>([
|
|
9
|
+
['gpt-5-pro', ['high']],
|
|
10
|
+
['gpt-5.2-pro', ['medium', 'high', 'xhigh']],
|
|
11
|
+
['gpt-5.4-pro', ['medium', 'high', 'xhigh']],
|
|
12
|
+
])
|
|
13
|
+
|
|
14
|
+
function restrictedReasoningEfforts(...identifiers: unknown[]): readonly string[] | undefined {
|
|
15
|
+
for (const identifier of identifiers) {
|
|
16
|
+
if (typeof identifier !== 'string') continue
|
|
17
|
+
// Keys can include provider/region prefixes or dated OpenAI snapshots.
|
|
18
|
+
const model = identifier.split('/').pop()?.replace(/-\d{4}-\d{2}-\d{2}$/, '')
|
|
19
|
+
if (!model) continue
|
|
20
|
+
const efforts = RESTRICTED_EFFORTS.get(model)
|
|
21
|
+
if (efforts) return efforts
|
|
22
|
+
}
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Resolve discovery metadata without assuming every reasoning model accepts effort options. */
|
|
27
|
+
export function resolveReasoningEfforts(
|
|
28
|
+
info: LiteLLMModelInfo,
|
|
29
|
+
params?: Record<string, unknown>,
|
|
30
|
+
): string[] | undefined {
|
|
31
|
+
const metadata: Record<string, unknown> = { ...params }
|
|
32
|
+
for (const [key, value] of Object.entries(info)) {
|
|
33
|
+
if (value != null) metadata[key] = value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (metadata.supports_reasoning === false) return []
|
|
37
|
+
|
|
38
|
+
// Explicit lists are authoritative, including an empty list. In particular,
|
|
39
|
+
// reasoning_effort_levels can describe models that do not accept medium.
|
|
40
|
+
for (const key of ['reasoning_effort_levels', 'supports_reasoning_efforts']) {
|
|
41
|
+
const levels = metadata[key]
|
|
42
|
+
if (Array.isArray(levels)) {
|
|
43
|
+
return [...new Set(levels.filter((level): level is string => typeof level === 'string'))]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Some search models carry effort flags even though their request handler
|
|
48
|
+
// rejects reasoning altogether. Accept either chat or Responses API naming.
|
|
49
|
+
const supportedParams = metadata.supported_openai_params
|
|
50
|
+
if (
|
|
51
|
+
Array.isArray(supportedParams) &&
|
|
52
|
+
!supportedParams.includes('reasoning_effort') &&
|
|
53
|
+
!supportedParams.includes('reasoning')
|
|
54
|
+
) return []
|
|
55
|
+
|
|
56
|
+
const flags = new Map<string, boolean>()
|
|
57
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
58
|
+
const match = key.match(/^supports_([a-z]+)_reasoning_effort$/)
|
|
59
|
+
if (match && typeof value === 'boolean') flags.set(match[1], value)
|
|
60
|
+
}
|
|
61
|
+
if (flags.size === 0) return undefined
|
|
62
|
+
// Negative flags only rule out levels; they do not establish reasoning support.
|
|
63
|
+
if (metadata.supports_reasoning !== true && ![...flags.values()].includes(true)) return undefined
|
|
64
|
+
|
|
65
|
+
// LiteLLM's per-level flags are sparse: medium/high have no standard flags,
|
|
66
|
+
// and low is opt-out. Requiring an explicit true hides these baseline levels
|
|
67
|
+
// on models such as GPT-6 Astra, whose only positive flags are xhigh/max.
|
|
68
|
+
// Keep optional levels opt-in rather than guessing none/minimal support.
|
|
69
|
+
// See litellm/router_utils/reasoning_effort_capability.py upstream.
|
|
70
|
+
const efforts = new Set<string>()
|
|
71
|
+
for (const effort of ['low', 'medium', 'high']) {
|
|
72
|
+
if (flags.get(effort) !== false) efforts.add(effort)
|
|
73
|
+
}
|
|
74
|
+
for (const [effort, supported] of flags) {
|
|
75
|
+
if (supported) efforts.add(effort)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const restricted = restrictedReasoningEfforts(metadata.key, params?.model)
|
|
79
|
+
if (restricted) {
|
|
80
|
+
for (const effort of efforts) {
|
|
81
|
+
if (!restricted.includes(effort)) efforts.delete(effort)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const order = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']
|
|
86
|
+
return [
|
|
87
|
+
...order.filter((effort) => efforts.has(effort)),
|
|
88
|
+
...[...efforts].filter((effort) => !order.includes(effort)),
|
|
89
|
+
]
|
|
90
|
+
}
|