dsh-model-allowance 1.1.0 → 1.1.1

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.
@@ -126,6 +126,8 @@ export function bindingWindow(windows) {
126
126
  * @property {string} name Fixture identity, used in failure messages.
127
127
  * @property {string} [route] Route to read; defaults to the adapter's first.
128
128
  * @property {object} [response] Recorded JSON body, for an endpoint adapter.
129
+ * @property {readonly object[]} [responses] Recorded JSON bodies, one per
130
+ * request in order, for a read that performs several calls.
129
131
  * @property {number} [httpStatus] Recorded HTTP status; defaults to 200.
130
132
  * @property {Record<string, unknown>} [services] Host services the read uses,
131
133
  * for a `readWithEnv` adapter.
@@ -153,6 +155,8 @@ export function bindingWindow(windows) {
153
155
  * @param {'amount'|'quota'} spec.kind Quantity dimension of the reading.
154
156
  * @param {boolean} [spec.modelScoped] Whether the reading is per model.
155
157
  * @param {string} [spec.consoleUrl] Provider console for a manual check.
158
+ * @param {string} [spec.setupUrl] Guide that walks obtaining this provider's
159
+ * credentials, carried by the unconfigured reading so the card can link it.
156
160
  * @param {{name: {zh: string, en: string}, mark: {icon?: string, color: string}}} spec.display
157
161
  * Display metadata the browser needs to name and draw the route.
158
162
  * @param {string} [spec.service] Host service this adapter reads through.
@@ -190,6 +194,11 @@ export function defineAdapter(spec) {
190
194
  throw new Error(`${where} needs an https console link`)
191
195
  }
192
196
  }
197
+ if (spec.setupUrl !== undefined) {
198
+ if (typeof spec.setupUrl !== 'string' || !spec.setupUrl.startsWith('https://')) {
199
+ throw new Error(`${where} needs an https setup guide link`)
200
+ }
201
+ }
193
202
  if (spec.status !== undefined) {
194
203
  if (typeof spec.status !== 'object' || spec.status === null) {
195
204
  throw new Error(`${where} declares an unreadable status source`)
@@ -259,6 +268,7 @@ export function defineAdapter(spec) {
259
268
  kind: spec.kind,
260
269
  ...(spec.modelScoped === true ? { modelScoped: true } : {}),
261
270
  ...(spec.consoleUrl === undefined ? {} : { consoleUrl: spec.consoleUrl }),
271
+ ...(spec.setupUrl === undefined ? {} : { setupUrl: spec.setupUrl }),
262
272
  service: spec.service,
263
273
  http: hasEndpoint ? Object.freeze({ endpoint: spec.endpoint, auth: spec.auth }) : undefined,
264
274
  credentialRefs: Object.freeze([...(spec.credentialRefs ?? [])]),
package/lib/providers.js CHANGED
@@ -43,15 +43,13 @@ import {
43
43
  openaiCodexAdapters,
44
44
  opencodeAdapters,
45
45
  openrouterAdapters,
46
- qwenTokenPlanAdapters,
47
- qwenTokenPlanCnAdapters,
48
- qwenTokenPlanIndividualAdapters,
49
46
  radiusAdapters,
50
47
  togetherAdapters,
51
48
  typesafeAdapters,
52
49
  vercelAiGatewayAdapters,
53
50
  xaiAdapters,
54
51
  } from './providers/placeholder.js'
52
+ import { qwenTokenPlanAdapters } from './providers/qwen_token_plan.js'
55
53
  import { KIND_AMOUNT, KIND_QUOTA } from './providers/shared.js'
56
54
  import { xiaomiAdapters } from './providers/xiaomi.js'
57
55
  import { zaiAdapters } from './providers/zai.js'
@@ -71,6 +69,8 @@ import { zaiAdapters } from './providers/zai.js'
71
69
  * @property {readonly import('./providers/shared.js').BalanceWindow[]} [windows] Per-window detail for a metered plan.
72
70
  * @property {{kind: 'amount'|'percent', delta: number, at: number}} [consumption] Movement since the previous reading.
73
71
  * @property {string} [consoleUrl] Provider console for a manual top-up or quota check.
72
+ * @property {string} [setupUrl] Guide that walks obtaining the credentials the
73
+ * reading needs, for `status === 'unconfigured'`.
74
74
  * @property {number} [updatedAt] Epoch milliseconds of the reading.
75
75
  * @property {string} [error] Failure detail for `status === 'failed'`.
76
76
  */
@@ -97,6 +97,7 @@ import { zaiAdapters } from './providers/zai.js'
97
97
  * @property {'amount'|'quota'} kind Quantity dimension of the reading.
98
98
  * @property {boolean} [modelScoped] Whether the reading is per provider-owned model.
99
99
  * @property {string} [consoleUrl] Provider console for a manual check.
100
+ * @property {string} [setupUrl] Guide that walks obtaining this provider's credentials.
100
101
  * @property {string} [service] Host service this adapter reads through, when it needs no key.
101
102
  * @property {{endpoint: string, auth: 'bearer'|'raw'}} [http] Endpoint and signing
102
103
  * style, when the service performs the request.
@@ -127,6 +128,7 @@ export const PROVIDER_ADAPTERS = Object.freeze([
127
128
  ...kimiCodingAdapters,
128
129
  ...opencodeGoAdapters,
129
130
  ...xiaomiAdapters,
131
+ ...qwenTokenPlanAdapters,
130
132
  // Placeholder adapters (unsupported status)
131
133
  ...amazonBedrockAdapters,
132
134
  ...antLingAdapters,
@@ -152,9 +154,6 @@ export const PROVIDER_ADAPTERS = Object.freeze([
152
154
  ...openaiCodexAdapters,
153
155
  ...opencodeAdapters,
154
156
  ...openrouterAdapters,
155
- ...qwenTokenPlanAdapters,
156
- ...qwenTokenPlanCnAdapters,
157
- ...qwenTokenPlanIndividualAdapters,
158
157
  ...radiusAdapters,
159
158
  ...togetherAdapters,
160
159
  ...typesafeAdapters,
package/lib/remote.js CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
10
+ import { testQwenPlanCredentials } from './providers/qwen_token_plan.js'
10
11
 
11
12
  /**
12
13
  * Apply the protocol's `@Remote` marker to a method without decorator syntax.
@@ -89,6 +90,22 @@ export class BalanceController extends TypertRemoteService {
89
90
  return await this.ctx.modelAllowance.list()
90
91
  }
91
92
 
93
+ /**
94
+ * Walk a provider's credential chain against the live endpoints.
95
+ *
96
+ * The settings page calls this with the AccessKey pair the user entered,
97
+ * before it saves: a stored credential is one the vendor accepted. The
98
+ * values travel to the vendor's own endpoints and nowhere else, and are
99
+ * never written to the store by this call.
100
+ *
101
+ * @param {string} accessKeyId AccessKey ID candidate.
102
+ * @param {string} secretAccessKey AccessKey secret candidate.
103
+ * @returns {Promise<{ok: true} | {ok: false, error: string}>} The outcome.
104
+ */
105
+ async testCredentials(accessKeyId, secretAccessKey) {
106
+ return await testQwenPlanCredentials({ accessKeyId, secretAccessKey })
107
+ }
108
+
92
109
  /**
93
110
  * Read one provider's platform status.
94
111
  *
@@ -208,6 +225,7 @@ BalanceController.__applyRemoteMarkers = [
208
225
  markRemote(BalanceController.prototype, 'capabilities'),
209
226
  markRemote(BalanceController.prototype, 'balance'),
210
227
  markRemote(BalanceController.prototype, 'list'),
228
+ markRemote(BalanceController.prototype, 'testCredentials'),
211
229
  markRemote(BalanceController.prototype, 'status'),
212
230
  markRemote(BalanceController.prototype, 'schedule'),
213
231
  markRemote(BalanceController.prototype, 'defaultProvider'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-allowance",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "Shows the current conversation model's provider balance or remaining allowance in the composer.",
6
6
  "license": "MIT",