@tscgoods/claude-code-effort-discovery 0.3.1 → 0.4.0
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/scripts/lib.mjs +49 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscgoods/claude-code-effort-discovery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Claude Code plugin: discover which reasoning-effort levels your gateway model accepts, report them, and cap /effort to them.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/scripts/lib.mjs
CHANGED
|
@@ -94,8 +94,9 @@ export function normalizeBaseURL(input) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
97
|
+
* Anthropic Messages 协议档位探测:
|
|
98
|
+
* 先用非法档位判断网关是否真的校验;不校验就返回 no-validation,
|
|
99
|
+
* 绝不把“2xx”误当成“支持全部档位”。
|
|
99
100
|
*/
|
|
100
101
|
export async function probeAnthropic({ baseURL, apiKey, model, headers = {}, ladder = ANTHROPIC_LADDER, timeoutMs = 30_000 }) {
|
|
101
102
|
const base = normalizeBaseURL(baseURL)
|
|
@@ -104,8 +105,7 @@ export async function probeAnthropic({ baseURL, apiKey, model, headers = {}, lad
|
|
|
104
105
|
let withBeta = true
|
|
105
106
|
let unknown = false
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
const level = ladder[index]
|
|
108
|
+
const send = async (level) => {
|
|
109
109
|
const head = {
|
|
110
110
|
"Content-Type": "application/json",
|
|
111
111
|
"anthropic-version": "2023-06-01",
|
|
@@ -116,10 +116,8 @@ export async function probeAnthropic({ baseURL, apiKey, model, headers = {}, lad
|
|
|
116
116
|
head.Authorization = `Bearer ${apiKey}`
|
|
117
117
|
head["x-api-key"] = apiKey
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
let response
|
|
121
119
|
try {
|
|
122
|
-
response = await fetch(url, {
|
|
120
|
+
const response = await fetch(url, {
|
|
123
121
|
method: "POST",
|
|
124
122
|
headers: head,
|
|
125
123
|
body: JSON.stringify({
|
|
@@ -130,32 +128,63 @@ export async function probeAnthropic({ baseURL, apiKey, model, headers = {}, lad
|
|
|
130
128
|
}),
|
|
131
129
|
signal: AbortSignal.timeout(timeoutMs),
|
|
132
130
|
})
|
|
131
|
+
return { status: response.status, text: await response.text() }
|
|
133
132
|
} catch {
|
|
133
|
+
return undefined
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const fatal = (r) =>
|
|
138
|
+
r && [401, 403, 429].includes(r.status)
|
|
139
|
+
? { levels: null, source: `http-${r.status}`, at: Date.now() }
|
|
140
|
+
: undefined
|
|
141
|
+
|
|
142
|
+
// 1) sentinel
|
|
143
|
+
const sentinel = await send("effort-discovery-probe")
|
|
144
|
+
const fatalSentinel = fatal(sentinel)
|
|
145
|
+
if (fatalSentinel) return fatalSentinel
|
|
146
|
+
if (sentinel) {
|
|
147
|
+
if (sentinel.status >= 200 && sentinel.status < 300) {
|
|
148
|
+
return { levels: null, source: "no-validation", at: Date.now() }
|
|
149
|
+
}
|
|
150
|
+
const listed = parseLevels(sentinel.text)
|
|
151
|
+
if (listed) return { levels: listed, source: "validated", at: Date.now() }
|
|
152
|
+
if (
|
|
153
|
+
sentinel.status === 400 &&
|
|
154
|
+
/effort-2025-11-24|anthropic-beta/i.test(sentinel.text) &&
|
|
155
|
+
!/output_config|does not support|unsupported|invalid value/i.test(sentinel.text)
|
|
156
|
+
) {
|
|
157
|
+
withBeta = false
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 2) ladder
|
|
162
|
+
for (let index = 0; index < ladder.length; index++) {
|
|
163
|
+
const result = await send(ladder[index])
|
|
164
|
+
const fatalResult = fatal(result)
|
|
165
|
+
if (fatalResult) return fatalResult
|
|
166
|
+
if (!result) {
|
|
134
167
|
unknown = true
|
|
135
168
|
continue
|
|
136
169
|
}
|
|
170
|
+
if (result.status >= 200 && result.status < 300) {
|
|
171
|
+
return { levels: ladder.slice(index), source: "validated", at: Date.now() }
|
|
172
|
+
}
|
|
137
173
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const text = await response.text()
|
|
141
|
-
const mentionsBeta = /effort-2025-11-24|anthropic-beta/i.test(text)
|
|
142
|
-
const mentionsEffort = /output_config|effort|does not support/i.test(text)
|
|
174
|
+
const mentionsBeta = /effort-2025-11-24|anthropic-beta/i.test(result.text)
|
|
175
|
+
const mentionsEffort = /output_config|does not support|unsupported|invalid value/i.test(result.text)
|
|
143
176
|
|
|
144
|
-
if (
|
|
177
|
+
if (result.status === 400 && mentionsBeta && !mentionsEffort && withBeta) {
|
|
145
178
|
withBeta = false
|
|
146
179
|
index--
|
|
147
180
|
continue
|
|
148
181
|
}
|
|
149
|
-
|
|
150
|
-
|
|
182
|
+
if (result.status === 400 || result.status === 422) {
|
|
183
|
+
const listed = parseLevels(result.text)
|
|
184
|
+
if (listed) return { levels: listed, source: "validated", at: Date.now() }
|
|
151
185
|
if (!mentionsEffort && !mentionsBeta) unknown = true
|
|
152
186
|
continue
|
|
153
187
|
}
|
|
154
|
-
|
|
155
|
-
if (response.status === 401 || response.status === 403 || response.status === 429) {
|
|
156
|
-
return { levels: null, source: `http-${response.status}`, at: Date.now() }
|
|
157
|
-
}
|
|
158
|
-
|
|
159
188
|
unknown = true
|
|
160
189
|
}
|
|
161
190
|
|