dsh-sub2api 0.10.2 → 0.10.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/CHANGELOG.md +12 -0
- package/lib/adapter.js +38 -1
- package/lib/index.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.3
|
|
4
|
+
|
|
5
|
+
- **A request can no longer go out with no key.** When the adapter could not
|
|
6
|
+
reach the host's credential service, the transport treated that as "no key"
|
|
7
|
+
and sent the request without an `Authorization` header; the gateway answered
|
|
8
|
+
`401 API key is required in Authorization header`, which reads as a bad key and
|
|
9
|
+
sends you hunting the wrong problem. The key now also comes from the plugin's
|
|
10
|
+
own session record, and when neither source has one the plugin says so in the
|
|
11
|
+
log instead of failing at the far end.
|
|
12
|
+
- The resolver is a named export so this path is testable: a keyless request and
|
|
13
|
+
a request with a wrong key are indistinguishable from the caller.
|
|
14
|
+
|
|
3
15
|
## 0.10.2
|
|
4
16
|
|
|
5
17
|
- **One retry against the current host when the configured one cannot be
|
package/lib/adapter.js
CHANGED
|
@@ -60,6 +60,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
60
60
|
* @param {import("./sub2api/catalog.js").ModelCatalog} deps.catalog
|
|
61
61
|
* @param {() => string} deps.apiBase
|
|
62
62
|
* @param {() => string} deps.apiKeyEnv credential reference holding the key
|
|
63
|
+
* @param {() => {apiKey: () => Promise<string | undefined>}} [deps.session] fallback key source
|
|
63
64
|
* @param {() => number} deps.timeoutMs
|
|
64
65
|
* @param {() => number} deps.idleTimeoutMs
|
|
65
66
|
* @param {{warn: Function}} [deps.logger]
|
|
@@ -110,7 +111,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
|
|
|
110
111
|
this.service = new OpenAiLlmService({
|
|
111
112
|
config,
|
|
112
113
|
provider: PROVIDER,
|
|
113
|
-
credentials: () =>
|
|
114
|
+
credentials: () => resolveCredentials(deps),
|
|
114
115
|
images: () => optionalService(deps.ctx, "attachments"),
|
|
115
116
|
});
|
|
116
117
|
return this.service;
|
|
@@ -392,6 +393,42 @@ export function selectedEffort(model, id) {
|
|
|
392
393
|
}
|
|
393
394
|
|
|
394
395
|
/** Read an optional host service without letting an absent one abort the call. */
|
|
396
|
+
/**
|
|
397
|
+
* The credential resolver handed to the transport.
|
|
398
|
+
*
|
|
399
|
+
* The host's `credentials` service is the right source, but it is not a hard
|
|
400
|
+
* requirement: the same key also lives in this plugin's own session record. The
|
|
401
|
+
* transport treats a missing resolver as "no key" and sends the request without
|
|
402
|
+
* an `Authorization` header, which the gateway answers with a 401 that reads
|
|
403
|
+
* exactly like a bad key — so falling back to the stored record, and saying so
|
|
404
|
+
* when neither source has anything, is what keeps that failure diagnosable.
|
|
405
|
+
*
|
|
406
|
+
* Exported because this path cannot be exercised from the outside: a request
|
|
407
|
+
* with no key and a request with a wrong key look identical to a caller.
|
|
408
|
+
* @param {object} deps adapter dependencies
|
|
409
|
+
* @returns {any} a resolver, or undefined when no key source exists
|
|
410
|
+
*/
|
|
411
|
+
export function resolveCredentials(deps) {
|
|
412
|
+
const service = optionalService(deps.ctx, "credentials");
|
|
413
|
+
if (service !== undefined) return service;
|
|
414
|
+
|
|
415
|
+
const stored = deps.session?.();
|
|
416
|
+
if (stored !== undefined) {
|
|
417
|
+
return {
|
|
418
|
+
resolve: async () => {
|
|
419
|
+
const value = await stored.apiKey().catch(() => undefined);
|
|
420
|
+
return typeof value === "string" && value !== "" ? { value } : undefined;
|
|
421
|
+
},
|
|
422
|
+
set: async () => {},
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
deps.logger?.warn?.(
|
|
427
|
+
"[sub2api] 取不到凭据:ctx.get('credentials') 为空且会话里没有密钥,请求会不带密钥发出",
|
|
428
|
+
);
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
431
|
+
|
|
395
432
|
function optionalService(ctx, name) {
|
|
396
433
|
try {
|
|
397
434
|
return ctx?.get?.(name);
|
package/lib/index.js
CHANGED
|
@@ -127,6 +127,9 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
127
127
|
catalog,
|
|
128
128
|
apiBase: () => cfg().apiBase,
|
|
129
129
|
apiKeyEnv: () => cfg().apiKeyEnv,
|
|
130
|
+
// The transport prefers the host's credential service; this is the
|
|
131
|
+
// fallback when that service is not reachable from the adapter.
|
|
132
|
+
session: () => session,
|
|
130
133
|
timeoutMs: () => cfg().requestTimeoutMs,
|
|
131
134
|
idleTimeoutMs: () => cfg().streamIdleTimeoutMs,
|
|
132
135
|
transportRetries: () => cfg().retries,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "Official Psapi provider for DeepSeek Harness: email sign-in or sign-up, automatic key and model provisioning, one panel for balance and recharge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|