opencode-plugin-litellm 0.2.2 → 0.2.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/package.json +1 -1
- package/src/utils/format-model-name.ts +103 -27
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": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"description": "OpenCode plugin for LiteLLM proxy support with auto-detection and dynamic model discovery",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.ts",
|
|
@@ -14,6 +14,62 @@ export function extractModelOwner(model: LiteLLMModel): string | undefined {
|
|
|
14
14
|
return undefined
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Strip Vertex-style version pinning suffixes that have no place in a
|
|
19
|
+
* display name. LiteLLM exposes Anthropic-on-Vertex models with ids
|
|
20
|
+
* like `claude-opus-4-5@20251101` or `claude-sonnet-4-6@default`; those
|
|
21
|
+
* `@…` suffixes mean "this exact dated revision" or "the
|
|
22
|
+
* provider-default revision" and aren't part of the model's brand name.
|
|
23
|
+
*/
|
|
24
|
+
function stripVersionSuffix(part: string): string {
|
|
25
|
+
return part.replace(/@(default|\d{6,8})$/i, '')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Heuristic: does this numeric token look like a real version component
|
|
30
|
+
* (single or double digit) rather than a date stamp or build number?
|
|
31
|
+
*
|
|
32
|
+
* Anthropic / OpenAI version components are always 1–2 digits in
|
|
33
|
+
* practice (`3`, `4`, `5`, `16`); a 6–8 digit token is almost certainly
|
|
34
|
+
* a `YYYYMMDD` revision stamp like `20251101` and must NOT be merged
|
|
35
|
+
* with the digit before it.
|
|
36
|
+
*/
|
|
37
|
+
function looksLikeVersionComponent(token: string): boolean {
|
|
38
|
+
return /^\d{1,2}$/.test(token)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Collapse two adjacent numeric tokens at the end of a tokenised id
|
|
43
|
+
* into a single dotted version token. Anthropic uses dash-only ids
|
|
44
|
+
* (`claude-opus-4-5`) where the trailing `4-5` is really a `4.5`
|
|
45
|
+
* version pair, but the formatter would otherwise render it as
|
|
46
|
+
* "Claude Opus 4 5".
|
|
47
|
+
*
|
|
48
|
+
* Conservative on purpose:
|
|
49
|
+
* - Only the LAST adjacent pair is collapsed, so `gpt-3-5-turbo-16k`
|
|
50
|
+
* keeps `[3, 5, turbo, 16k]` (`turbo` between blocks the merge).
|
|
51
|
+
* - Both tokens must look like real version components (1–2 digits) —
|
|
52
|
+
* this avoids merging date stamps in ids like
|
|
53
|
+
* `claude-opus-4-5-20251101`, where the trailing `20251101` is a
|
|
54
|
+
* YYYYMMDD revision and must stay separate.
|
|
55
|
+
* - We refuse to collapse if the token immediately AFTER the pair is
|
|
56
|
+
* also numeric (would create ambiguity in `1-2-3` runs).
|
|
57
|
+
*/
|
|
58
|
+
function joinTrailingVersionPair(tokens: string[]): string[] {
|
|
59
|
+
for (let i = tokens.length - 1; i >= 1; i--) {
|
|
60
|
+
const a = tokens[i - 1]
|
|
61
|
+
const b = tokens[i]
|
|
62
|
+
if (looksLikeVersionComponent(a) && looksLikeVersionComponent(b)) {
|
|
63
|
+
const next = tokens[i + 1]
|
|
64
|
+
if (next === undefined || !/^\d+$/.test(next)) {
|
|
65
|
+
const merged = [...tokens.slice(0, i - 1), `${a}.${b}`, ...tokens.slice(i + 1)]
|
|
66
|
+
return merged
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return tokens
|
|
71
|
+
}
|
|
72
|
+
|
|
17
73
|
/**
|
|
18
74
|
* Categorize the model so we can attach sensible `modalities` metadata
|
|
19
75
|
* in the OpenCode provider config.
|
|
@@ -37,11 +93,23 @@ export function categorizeModel(model: LiteLLMModel): 'chat' | 'embedding' | 'im
|
|
|
37
93
|
/**
|
|
38
94
|
* Format a LiteLLM model ID into a human readable display name.
|
|
39
95
|
*
|
|
96
|
+
* Pre-processing:
|
|
97
|
+
* - Strip the first `provider/` segment (`vertex_ai/`, `openai/`, …).
|
|
98
|
+
* - Strip Vertex revision suffixes (`@<date>`, `@default`).
|
|
99
|
+
*
|
|
100
|
+
* Tokenisation post-processing:
|
|
101
|
+
* - Collapse a trailing pair of bare numeric tokens into a single
|
|
102
|
+
* dotted version. Anthropic uses dash-only ids — `claude-opus-4-7`
|
|
103
|
+
* would otherwise render as "Claude Opus 4 7" instead of
|
|
104
|
+
* "Claude Opus 4.7".
|
|
105
|
+
*
|
|
40
106
|
* Examples:
|
|
41
|
-
* "openai/gpt-4o-mini"
|
|
42
|
-
* "
|
|
43
|
-
* "
|
|
44
|
-
* "
|
|
107
|
+
* "openai/gpt-4o-mini" -> "GPT 4o Mini"
|
|
108
|
+
* "claude-opus-4-7" -> "Claude Opus 4.7"
|
|
109
|
+
* "claude-opus-4-5@20251101" -> "Claude Opus 4.5"
|
|
110
|
+
* "claude-sonnet-4-6@default" -> "Claude Sonnet 4.6"
|
|
111
|
+
* "bedrock/amazon.nova-pro-v1" -> "Amazon Nova Pro V1"
|
|
112
|
+
* "qwen/qwen3-30b-a3b" -> "Qwen3 30B A3B"
|
|
45
113
|
*/
|
|
46
114
|
export function formatModelName(model: LiteLLMModel): string {
|
|
47
115
|
const { id } = model
|
|
@@ -50,38 +118,46 @@ export function formatModelName(model: LiteLLMModel): string {
|
|
|
50
118
|
// ids like `bedrock/amazon.nova-pro-v1` still carry the vendor name
|
|
51
119
|
// through to the display.
|
|
52
120
|
const slashIdx = id.indexOf('/')
|
|
53
|
-
const
|
|
121
|
+
const afterProvider = slashIdx >= 0 ? id.slice(slashIdx + 1) : id
|
|
122
|
+
|
|
123
|
+
// Strip Vertex revision suffixes (`@20251101`, `@default`).
|
|
124
|
+
const modelPart = stripVersionSuffix(afterProvider)
|
|
54
125
|
|
|
55
126
|
const acronyms = new Set([
|
|
56
127
|
'gpt', 'oss', 'api', 'gguf', 'ggml', 'nomic', 'vl', 'it', 'mlx',
|
|
57
128
|
'llm', 'ai', 'sdk', 'aws', 'gcp', 'tts', 'stt', 'mm',
|
|
58
129
|
])
|
|
59
130
|
|
|
60
|
-
const
|
|
131
|
+
const rawTokens = modelPart
|
|
61
132
|
.split(/[-_.]/) // split on -, _ and .
|
|
62
133
|
.filter(Boolean)
|
|
63
|
-
.map((token) => {
|
|
64
|
-
const lower = token.toLowerCase()
|
|
65
|
-
if (acronyms.has(lower)) return token.toUpperCase()
|
|
66
|
-
// sizes (30b, 7b, 4k...)
|
|
67
|
-
if (/^\d+[bkmg]$/i.test(token)) return token.toUpperCase()
|
|
68
|
-
// quantizations (q4, q8...)
|
|
69
|
-
if (/^q\d+$/i.test(token)) return token.toUpperCase()
|
|
70
|
-
// semantic versions like 3.5
|
|
71
|
-
if (/^\d+\.\d+/.test(token)) return token
|
|
72
|
-
// shapes like a3b, e4b, 3n -> uppercase
|
|
73
|
-
if (/^[a-z]\d+[a-z]?$/i.test(token)) {
|
|
74
|
-
return token.toUpperCase()
|
|
75
|
-
}
|
|
76
|
-
// shapes like "4o" (OpenAI branding) — keep digit + lowercase letter
|
|
77
|
-
if (/^\d+[a-z]$/i.test(token)) {
|
|
78
|
-
return token.toLowerCase()
|
|
79
|
-
}
|
|
80
|
-
return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()
|
|
81
|
-
})
|
|
82
|
-
.join(' ')
|
|
83
134
|
|
|
84
|
-
|
|
135
|
+
// Collapse a trailing numeric pair (`4-5`) into a dotted version
|
|
136
|
+
// (`4.5`) for Anthropic-style ids. No-op when versions already use
|
|
137
|
+
// dots (which survive the split as separate tokens but only re-merge
|
|
138
|
+
// when both sides are pure digits).
|
|
139
|
+
const tokens = joinTrailingVersionPair(rawTokens).map((token) => {
|
|
140
|
+
const lower = token.toLowerCase()
|
|
141
|
+
if (acronyms.has(lower)) return token.toUpperCase()
|
|
142
|
+
// sizes (30b, 7b, 4k...)
|
|
143
|
+
if (/^\d+[bkmg]$/i.test(token)) return token.toUpperCase()
|
|
144
|
+
// quantizations (q4, q8...)
|
|
145
|
+
if (/^q\d+$/i.test(token)) return token.toUpperCase()
|
|
146
|
+
// dotted versions (3.5, 2.5, 4.7) — emitted by joinTrailingVersionPair
|
|
147
|
+
// or naturally present in dotted base_models.
|
|
148
|
+
if (/^\d+\.\d+/.test(token)) return token
|
|
149
|
+
// shapes like a3b, e4b, 3n -> uppercase
|
|
150
|
+
if (/^[a-z]\d+[a-z]?$/i.test(token)) {
|
|
151
|
+
return token.toUpperCase()
|
|
152
|
+
}
|
|
153
|
+
// shapes like "4o" (OpenAI branding) — keep digit + lowercase letter
|
|
154
|
+
if (/^\d+[a-z]$/i.test(token)) {
|
|
155
|
+
return token.toLowerCase()
|
|
156
|
+
}
|
|
157
|
+
return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
return tokens.join(' ') || id
|
|
85
161
|
}
|
|
86
162
|
|
|
87
163
|
/**
|