@gatemux/dsh-gatemux-login-core 1.3.2 → 1.4.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.
Files changed (4) hide show
  1. package/account.js +37 -2
  2. package/llm.js +18 -18
  3. package/package.json +17 -17
  4. package/search.js +2 -0
package/account.js CHANGED
@@ -170,8 +170,17 @@ function apiErrorCode(body) {
170
170
  *
171
171
  * @param ctx - the account provider's lifetime.
172
172
  */
173
- function installGateMuxTaskCancellation(ctx) {
173
+ function installGateMuxTaskCancellation(ctx, account) {
174
174
  ctx.inject(['agents'], (scope) => {
175
+ const runningGateMuxTask = () => scope.agents.list().some(agent =>
176
+ agent.status === 'running' && agent.session.requestContext()?.provider === PROVIDER)
177
+ // DSH 0.2.2-rc.4 moved the account's running-task answer from inspecting
178
+ // ctx.agents to reports registered by the routes billing the account. The
179
+ // report is optional here so an older account base still constructs.
180
+ if (typeof account.registerRunningTaskReport === 'function') {
181
+ const dispose = account.registerRunningTaskReport(runningGateMuxTask)
182
+ if (typeof scope.effect === 'function') scope.effect(() => dispose, 'gatemux-account: running task report')
183
+ }
175
184
  scope.on('agent/error', ({ error }) => {
176
185
  if (error instanceof LlmError && error.code === 'ACCOUNT_SIGN_IN_REQUIRED') {
177
186
  scope.emit('deepseek-account/model-sign-in-required')
@@ -205,6 +214,8 @@ export class GateMuxAccount extends DeepSeekAccount {
205
214
  attempt
206
215
  listeners = new Set()
207
216
  detailsLifetime = new AbortController()
217
+ /** Aborts credentials released for in-flight requests when the account signs out. */
218
+ credentialRevoked = new AbortController()
208
219
  lastProfile
209
220
  refreshInFlight
210
221
  removing
@@ -216,7 +227,7 @@ export class GateMuxAccount extends DeepSeekAccount {
216
227
  */
217
228
  constructor(ctx, config = {}) {
218
229
  super(ctx)
219
- installGateMuxTaskCancellation(ctx)
230
+ installGateMuxTaskCancellation(ctx, this)
220
231
  const clientId = config.clientId ?? launchEnvironmentOf(ctx).get(CLIENT_ID_ENV)?.value
221
232
  if (typeof clientId !== 'string' || clientId.length === 0) {
222
233
  throw new GateMuxAuthError(
@@ -255,6 +266,7 @@ export class GateMuxAccount extends DeepSeekAccount {
255
266
  })
256
267
  ctx.effect(() => async () => {
257
268
  this.closed = true
269
+ this.credentialRevoked.abort()
258
270
  this.invalidateDetails()
259
271
  const active = this.attempt
260
272
  if (active !== undefined) {
@@ -370,6 +382,7 @@ export class GateMuxAccount extends DeepSeekAccount {
370
382
  if (this.closed) throw new GateMuxAuthError('provider is closed', 'protocol')
371
383
  if (this.attempt !== active) return this.getState()
372
384
  }
385
+ this.credentialRevoked = new AbortController()
373
386
  const attempt = {
374
387
  origin,
375
388
  loginSource,
@@ -445,6 +458,7 @@ export class GateMuxAccount extends DeepSeekAccount {
445
458
  }
446
459
  this.attempt = undefined
447
460
  this.ctx.emit('deepseek-account/signed-out')
461
+ this.credentialRevoked.abort()
448
462
  this.changed('credentials-changed')
449
463
  return this.getState()
450
464
  })().finally(() => { this.removing = undefined })
@@ -487,6 +501,26 @@ export class GateMuxAccount extends DeepSeekAccount {
487
501
  }
488
502
  }
489
503
 
504
+ /**
505
+ * Release the GateMux credential for one request. DSH 0.2.2-rc.4's
506
+ * deepseek-auth service calls this on the account stand-in; GateMux accepts
507
+ * the OAuth token as a Bearer header, unlike the DeepSeek account header.
508
+ * @param url - the request destination.
509
+ * @returns request headers, the revocation signal, and the rejection hook.
510
+ */
511
+ async resolveRequestCredential(url) {
512
+ const revoked = this.credentialRevoked.signal
513
+ const token = await this.resolveToken(url)
514
+ if (token === undefined) return undefined
515
+ return {
516
+ headers: { authorization: `Bearer ${token}` },
517
+ revoked,
518
+ reject: async () => {
519
+ try { await this.rejectToken(token) } catch { /* the destination's rejection is the failure to report */ }
520
+ },
521
+ }
522
+ }
523
+
490
524
  /** Resolve a token only for the GateMux REST origin, refreshing it when stale. */
491
525
  async resolveToken(url) {
492
526
  if (this.closed || this.removing !== undefined) return undefined
@@ -795,6 +829,7 @@ export class GateMuxAccount extends DeepSeekAccount {
795
829
  this.ctx.emit('deepseek-account/session-expired')
796
830
  this.attempt = undefined
797
831
  this.ctx.emit('deepseek-account/signed-out')
832
+ this.credentialRevoked.abort()
798
833
  this.changed('credentials-changed')
799
834
  return this.getState()
800
835
  })().finally(() => { this.removing = undefined })
package/llm.js CHANGED
@@ -176,15 +176,15 @@ export function apply(ctx, config) {
176
176
  return entries.map(servedModel).filter(model => model !== undefined)
177
177
  }
178
178
 
179
- const resolveAuth = async (connection) => {
179
+ // `ctx.deepseekAuth` is not part of a released DeepSeek Harness: the service
180
+ // and its base-bundle row land after 0.2.2-rc.5, so injecting it leaves this
181
+ // plugin pending forever and no adapter ever registers. The released account
182
+ // service already answers `resolveToken` / `rejectToken`, which is the same
183
+ // credential this route needs.
184
+ const resolveAuth = async (connection, endpoint) => {
180
185
  const account = ctx.get('deepseekAccount')
181
- const token = await account?.resolveToken(connection.baseURL)
182
- if (token === undefined) {
183
- throw new LlmError(
184
- 'Sign in with GateMux to use the GateMux model route. Model requests are billed to your own GateMux balance.',
185
- 'ACCOUNT_SIGN_IN_REQUIRED',
186
- )
187
- }
186
+ const token = await account?.resolveToken(endpoint ?? connection.baseURL)
187
+ if (token === undefined) return undefined
188
188
  return {
189
189
  // GateMux accepts `Authorization: Bearer`; it rejects the DeepSeek-only `x-dsh-auth-token` header.
190
190
  headers: { authorization: `Bearer ${token}` },
@@ -195,8 +195,8 @@ export function apply(ctx, config) {
195
195
  if (error.code === QUOTA_EXCEEDED_CODE) {
196
196
  return new LlmError(error.message, ACCOUNT_QUOTA_EXCEEDED_CODE, { ...error.failure, cause: error })
197
197
  }
198
- // 403 scope_denied / model_not_allowed / ip_not_allowed stay AUTH: they are
199
- // configuration faults that re-authorizing the same way would not fix.
198
+ // 403 scope_denied / model_not_allowed / ip_not_allowed stay AUTH: they
199
+ // are configuration faults that re-authorizing the same way would not fix.
200
200
  if (status !== 401) return error
201
201
  // 401 credential_invalid: the credential is revoked, expired, or suspended.
202
202
  // Re-authorization is required, so the stored credential is dropped.
@@ -211,6 +211,11 @@ export function apply(ctx, config) {
211
211
  }
212
212
  }
213
213
 
214
+ const missingCredential = () => new LlmError(
215
+ 'Sign in with GateMux to use the GateMux model route. Model requests are billed to your own GateMux balance.',
216
+ 'ACCOUNT_SIGN_IN_REQUIRED',
217
+ )
218
+
214
219
  ctx.llm.registerConfigurableProviders([
215
220
  { provider: PROVIDER, displayName: 'GateMux Account', settingsNs: ctx.fiber.entry?.options.id ?? name, settingsPath: [] },
216
221
  ])
@@ -218,17 +223,12 @@ export function apply(ctx, config) {
218
223
  registerDeepSeekProvider(ctx, PROVIDER, {
219
224
  options,
220
225
  resolveAuth,
226
+ missingCredential,
221
227
  providerName: 'GateMux Account',
222
228
  discoverModels: async (provider) => {
223
229
  const connection = baseOptions()
224
- let auth
225
- try {
226
- auth = await resolveAuth(connection)
227
- } catch (error) {
228
- // With no signed-in user the route advertises nothing rather than failing discovery.
229
- if (error instanceof LlmError && error.code === 'ACCOUNT_SIGN_IN_REQUIRED') return []
230
- throw error
231
- }
230
+ const auth = await resolveAuth(connection, listingUrl(connection.baseURL))
231
+ if (auth === undefined) return []
232
232
  try {
233
233
  discovered = await loadCatalog(connection, auth.headers)
234
234
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gatemux/dsh-gatemux-login-core",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "description": "GateMux account provider and model route for DeepSeek Harness. Shared code; install a region bundle instead of this package.",
6
6
  "publishConfig": {
@@ -24,26 +24,26 @@
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@deepseek-ai/cordis": "^4.0.4",
27
- "@deepseek-ai/dsh-authorization": "^0.2.2-rc.2",
28
- "@deepseek-ai/dsh-credentials": "^0.2.2-rc.2",
29
- "@deepseek-ai/dsh-deepseek-account": "^0.2.2-rc.2",
30
- "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.2",
31
- "@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.2",
32
- "@deepseek-ai/dsh-llm": "^0.2.2-rc.2",
33
- "@deepseek-ai/dsh-llm-deepseek": "^0.2.2-rc.2",
34
- "@deepseek-ai/dsh-web": "^0.2.2-rc.2",
27
+ "@deepseek-ai/dsh-authorization": "^0.2.2-rc.4",
28
+ "@deepseek-ai/dsh-credentials": "^0.2.2-rc.4",
29
+ "@deepseek-ai/dsh-deepseek-account": "^0.2.2-rc.4",
30
+ "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.4",
31
+ "@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.4",
32
+ "@deepseek-ai/dsh-llm": "^0.2.2-rc.4",
33
+ "@deepseek-ai/dsh-llm-deepseek": "^0.2.2-rc.4",
34
+ "@deepseek-ai/dsh-web": "^0.2.2-rc.4",
35
35
  "@deepseek-ai/schemastery": "^3.18.4"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@deepseek-ai/cordis": "^4.0.4",
39
- "@deepseek-ai/dsh-authorization": "^0.2.2-rc.2",
40
- "@deepseek-ai/dsh-credentials": "^0.2.2-rc.2",
41
- "@deepseek-ai/dsh-deepseek-account": "^0.2.2-rc.2",
42
- "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.2",
43
- "@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.2",
44
- "@deepseek-ai/dsh-llm": "^0.2.2-rc.2",
45
- "@deepseek-ai/dsh-llm-deepseek": "^0.2.2-rc.2",
46
- "@deepseek-ai/dsh-web": "^0.2.2-rc.2",
39
+ "@deepseek-ai/dsh-authorization": "^0.2.2-rc.4",
40
+ "@deepseek-ai/dsh-credentials": "^0.2.2-rc.4",
41
+ "@deepseek-ai/dsh-deepseek-account": "^0.2.2-rc.4",
42
+ "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.4",
43
+ "@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.4",
44
+ "@deepseek-ai/dsh-llm": "^0.2.2-rc.4",
45
+ "@deepseek-ai/dsh-llm-deepseek": "^0.2.2-rc.4",
46
+ "@deepseek-ai/dsh-web": "^0.2.2-rc.4",
47
47
  "@deepseek-ai/schemastery": "^3.18.4"
48
48
  }
49
49
  }
package/search.js CHANGED
@@ -158,6 +158,8 @@ export class GateMuxSearchProvider {
158
158
  */
159
159
  async search(request, signal) {
160
160
  if (signal?.aborted === true) throw new WebError('GateMux web search was cancelled', 'WEB_ABORTED')
161
+ // `ctx.deepseekAuth` is not part of a released DeepSeek Harness, so the
162
+ // released account service is what releases the credential here.
161
163
  const account = this.ctx.get('deepseekAccount')
162
164
  const token = await account?.resolveToken(this.endpoint)
163
165
  if (token === undefined || token.length === 0) {