@tscgoods/dsh-effort-discovery 0.3.1 → 0.3.2
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/lib/index.js +40 -11
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from "node:fs"
|
|
1
|
+
import { readFileSync, existsSync, appendFileSync } from "node:fs"
|
|
2
2
|
import { homedir } from "node:os"
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
import z from "@deepseek-ai/schemastery"
|
|
@@ -10,16 +10,28 @@ export const Config = z.object({
|
|
|
10
10
|
mode: z.union([z.const("transform"), z.const("off")]).default("transform"),
|
|
11
11
|
/** 探测缓存有效期(毫秒) */
|
|
12
12
|
ttlMs: z.number().default(6 * 60 * 60 * 1000).volatile(),
|
|
13
|
+
/** 把每次配置变换的输入/输出写到 ~/.cache/effort-discovery/dsh-transform.log(排障用) */
|
|
14
|
+
diag: z.boolean().default(false).volatile(),
|
|
13
15
|
})
|
|
14
16
|
|
|
15
|
-
const TARGET_ADAPTER = "
|
|
17
|
+
const TARGET_ADAPTER = "dsh-llm-pi-ai"
|
|
16
18
|
const LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"]
|
|
17
19
|
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
+
function cacheDir() {
|
|
21
|
+
return (
|
|
20
22
|
process.env.EFFORT_DISCOVERY_HOME ??
|
|
21
23
|
join(process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache"), "effort-discovery")
|
|
22
|
-
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function cachePath() {
|
|
28
|
+
return join(cacheDir(), "dsh.json")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function diag(line) {
|
|
32
|
+
try {
|
|
33
|
+
appendFileSync(join(cacheDir(), "dsh-transform.log"), new Date().toISOString() + " " + line + "\n")
|
|
34
|
+
} catch {}
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
function readCache() {
|
|
@@ -41,8 +53,8 @@ function readCache() {
|
|
|
41
53
|
export function narrowEfforts(model, levels) {
|
|
42
54
|
if (!Array.isArray(levels) || levels.length === 0) return undefined
|
|
43
55
|
const current = model?.reasoningEfforts
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
// current === false 往往只是 YAML 里没配/手写了“不推理”,不是上游证据。
|
|
57
|
+
// 既然探测到了档位,就以探测结果为准重新生成 map。
|
|
46
58
|
const declared = current && typeof current === "object" ? current : {}
|
|
47
59
|
const next = {}
|
|
48
60
|
const accepted = new Set(levels)
|
|
@@ -126,12 +138,29 @@ export default {
|
|
|
126
138
|
"internal/config",
|
|
127
139
|
(fiber, next) => {
|
|
128
140
|
const raw = next()
|
|
129
|
-
|
|
141
|
+
const entryName = String(fiber?.entry?.options?.name ?? "")
|
|
142
|
+
if (!entryName.includes(TARGET_ADAPTER)) return raw
|
|
130
143
|
const cache = readCache()
|
|
131
|
-
if (!cache)
|
|
144
|
+
if (!cache) {
|
|
145
|
+
if (config?.diag) diag(`no cache at ${cachePath()}`)
|
|
146
|
+
return raw
|
|
147
|
+
}
|
|
132
148
|
try {
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
const next = transformProviders(raw, cache)
|
|
150
|
+
if (config?.diag) {
|
|
151
|
+
const before = []
|
|
152
|
+
for (const profile of Object.values(raw?.providers ?? {})) {
|
|
153
|
+
for (const model of profile?.models ?? []) before.push(`${model.id}=${JSON.stringify(model.reasoningEfforts)}`)
|
|
154
|
+
}
|
|
155
|
+
const after = []
|
|
156
|
+
for (const profile of Object.values(next?.providers ?? {})) {
|
|
157
|
+
for (const model of profile?.models ?? []) after.push(`${model.id}=${JSON.stringify(model.reasoningEfforts)}`)
|
|
158
|
+
}
|
|
159
|
+
diag(`entry=${entryName}\n before: ${before.join(" | ")}\n after: ${after.join(" | ")}`)
|
|
160
|
+
}
|
|
161
|
+
return next
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (config?.diag) diag(`transform failed: ${String(error)}`)
|
|
135
164
|
return raw
|
|
136
165
|
}
|
|
137
166
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscgoods/dsh-effort-discovery",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "DeepSeek Harness (dsh) bundle: probe the gateway for the reasoning-effort levels each model accepts and narrow llm-pi-ai reasoningEfforts to them.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|