@ponydev/dsh-model-usage 1.0.6 → 1.0.7
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/CHANGELOG.md +5 -0
- package/lib/adapters.js +10 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/adapters.js
CHANGED
|
@@ -53,9 +53,18 @@ export async function fetchT(url, init, ms) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** 按顺序解析凭据 ref:优先注入作用域的 credentials 服务,再回退环境变量 */
|
|
56
|
+
function routeKeyRef(route) {
|
|
57
|
+
const base = String(route || '').toUpperCase().replace(/[^A-Z0-9]+/g, '_').replace(/^_+|_+$/g, '')
|
|
58
|
+
return base ? base + '_API_KEY' : null
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
export async function resolveKey(env) {
|
|
57
62
|
const cred = env.credentials
|
|
58
|
-
|
|
63
|
+
// 优先按路由派生的引用(如 opencode-go → OPENCODE_GO_API_KEY,与 DSH Models 页 apiKeyEnv 一致)
|
|
64
|
+
const refs = [...(env.refs || [])]
|
|
65
|
+
const derived = routeKeyRef(env.route)
|
|
66
|
+
if (derived && !refs.includes(derived)) refs.unshift(derived)
|
|
67
|
+
for (const ref of refs) {
|
|
59
68
|
if (!ref) continue
|
|
60
69
|
if (cred && typeof cred.resolve === 'function') {
|
|
61
70
|
for (let attempt = 0; attempt < 2; attempt++) {
|