@gatemux/dsh-gatemux-login-core 1.4.0 → 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 (3) hide show
  1. package/llm.js +26 -40
  2. package/package.json +1 -3
  3. package/search.js +11 -17
package/llm.js CHANGED
@@ -27,7 +27,7 @@ export { Config }
27
27
  /** Route owned by this plugin; distinct from the pi-ai `gatemux` route. */
28
28
  export const PROVIDER = 'gatemux-account'
29
29
  export const name = 'gatemux-account'
30
- export const inject = ['llm', 'deepseekAuth']
30
+ export const inject = ['llm']
31
31
 
32
32
  /** Listing value a model must carry to be reachable through this route's Messages transport. */
33
33
  const MESSAGES_PROTOCOL = 'anthropic-messages'
@@ -144,13 +144,6 @@ export function apply(ctx, config) {
144
144
  // Validate the composed configuration now so a misconfiguration fails loudly at load.
145
145
  baseOptions()
146
146
 
147
- // DSH 0.2.2-rc.4's deepseek-auth service owns the account credential candidates;
148
- // connect the GateMux deployment to this route so its account candidate serves it.
149
- ctx.effect(
150
- () => ctx.deepseekAuth.connect('account', PROVIDER, () => ({ baseURL: baseOptions().baseURL })),
151
- 'gatemux-account: account deployment',
152
- )
153
-
154
147
  // The catalog the endpoint last reported. Both the advertised model list and
155
148
  // every later capability resolution read it, because `modelInfo` derives a
156
149
  // model's context window and input modalities from `connection.models`: a
@@ -183,44 +176,37 @@ export function apply(ctx, config) {
183
176
  return entries.map(servedModel).filter(model => model !== undefined)
184
177
  }
185
178
 
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.
186
184
  const resolveAuth = async (connection, endpoint) => {
187
- const authorization = await ctx.deepseekAuth.authorize({
188
- consumer: 'gatemux-account',
189
- accepts: ['account'],
190
- destination: { url: endpoint },
191
- connections: { account: { baseURL: connection.baseURL } },
192
- })
193
- if (authorization === undefined) return undefined
185
+ const account = ctx.get('deepseekAccount')
186
+ const token = await account?.resolveToken(endpoint ?? connection.baseURL)
187
+ if (token === undefined) return undefined
194
188
  return {
195
- headers: authorization.headers,
196
- revoked: authorization.revoked,
189
+ // GateMux accepts `Authorization: Bearer`; it rejects the DeepSeek-only `x-dsh-auth-token` header.
190
+ headers: { authorization: `Bearer ${token}` },
197
191
  onRequestError: async (error) => {
192
+ if (!(error instanceof LlmError)) return error
193
+ const status = error.failure.status
194
+ // 402 insufficient_balance and an exhausted quota both mean the user must top up.
195
+ if (error.code === QUOTA_EXCEEDED_CODE) {
196
+ return new LlmError(error.message, ACCOUNT_QUOTA_EXCEEDED_CODE, { ...error.failure, cause: error })
197
+ }
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
+ if (status !== 401) return error
201
+ // 401 credential_invalid: the credential is revoked, expired, or suspended.
202
+ // Re-authorization is required, so the stored credential is dropped.
203
+ const rejected = new LlmError(error.message, 'ACCOUNT_TOKEN_INVALID', { ...error.failure, cause: error })
198
204
  try {
199
- // A sign-out ends every request carrying the released credential.
200
- if (authorization.revoked?.aborted === true) {
201
- return new LlmError(
202
- 'Signed out of GateMux while the request was running.',
203
- 'ACCOUNT_SIGN_IN_REQUIRED',
204
- { cause: error },
205
- )
206
- }
207
- if (!(error instanceof LlmError)) return error
208
- const status = error.failure.status
209
- // 402 insufficient_balance and an exhausted quota both mean the user must top up.
210
- if (error.code === QUOTA_EXCEEDED_CODE) {
211
- return new LlmError(error.message, ACCOUNT_QUOTA_EXCEEDED_CODE, { ...error.failure, cause: error })
212
- }
213
- // 403 scope_denied / model_not_allowed / ip_not_allowed stay AUTH: they
214
- // are configuration faults that re-authorizing the same way would not fix.
215
- if (status !== 401) return error
216
- // 401 credential_invalid: the credential is revoked, expired, or suspended.
217
- const rejected = new LlmError(error.message, 'ACCOUNT_TOKEN_INVALID', { ...error.failure, cause: error })
218
- await authorization.reject?.()
219
- return rejected
205
+ await account?.rejectToken(token)
220
206
  } catch (failure) {
221
- logger.warn('credential rejection handling failed', failure)
222
- return error
207
+ logger.warn('credential removal after rejection failed', failure)
223
208
  }
209
+ return rejected
224
210
  },
225
211
  }
226
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gatemux/dsh-gatemux-login-core",
3
- "version": "1.4.0",
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": {
@@ -27,7 +27,6 @@
27
27
  "@deepseek-ai/dsh-authorization": "^0.2.2-rc.4",
28
28
  "@deepseek-ai/dsh-credentials": "^0.2.2-rc.4",
29
29
  "@deepseek-ai/dsh-deepseek-account": "^0.2.2-rc.4",
30
- "@deepseek-ai/dsh-deepseek-auth": "^0.2.2-rc.4",
31
30
  "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.4",
32
31
  "@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.4",
33
32
  "@deepseek-ai/dsh-llm": "^0.2.2-rc.4",
@@ -40,7 +39,6 @@
40
39
  "@deepseek-ai/dsh-authorization": "^0.2.2-rc.4",
41
40
  "@deepseek-ai/dsh-credentials": "^0.2.2-rc.4",
42
41
  "@deepseek-ai/dsh-deepseek-account": "^0.2.2-rc.4",
43
- "@deepseek-ai/dsh-deepseek-auth": "^0.2.2-rc.4",
44
42
  "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.4",
45
43
  "@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.4",
46
44
  "@deepseek-ai/dsh-llm": "^0.2.2-rc.4",
package/search.js CHANGED
@@ -53,7 +53,7 @@ export const Config = Schema.object({
53
53
  export const name = 'gatemux-search'
54
54
 
55
55
  /** The web seam this provider registers into. */
56
- export const inject = ['web', 'deepseekAuth']
56
+ export const inject = ['web']
57
57
 
58
58
  /** One normalized result item, kept before the seam applies its own bounds. */
59
59
  function sourceOf(item, seen) {
@@ -158,13 +158,11 @@ 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
- const authorization = await this.ctx.deepseekAuth.authorize({
162
- consumer: 'gatemux-search',
163
- accepts: ['account'],
164
- destination: { url: this.endpoint },
165
- connections: { account: { baseURL: this.config.baseURL } },
166
- })
167
- if (authorization === undefined) {
161
+ // `ctx.deepseekAuth` is not part of a released DeepSeek Harness, so the
162
+ // released account service is what releases the credential here.
163
+ const account = this.ctx.get('deepseekAccount')
164
+ const token = await account?.resolveToken(this.endpoint)
165
+ if (token === undefined || token.length === 0) {
168
166
  throw new WebError(
169
167
  'Sign in with GateMux to use web search. The search is billed to your own GateMux balance.',
170
168
  'ACCOUNT_SIGN_IN_REQUIRED',
@@ -181,17 +179,16 @@ export class GateMuxSearchProvider {
181
179
  tools: [{ type: 'web_search_20250305', name: 'web_search', max_uses: this.config.maxUses }],
182
180
  }
183
181
  const timeout = AbortSignal.timeout(this.config.timeoutMs)
184
- const signals = [timeout]
185
- if (signal !== undefined) signals.push(signal)
186
- if (authorization.revoked !== undefined) signals.push(authorization.revoked)
187
- const fused = signals.length === 1 ? signals[0] : AbortSignal.any(signals)
182
+ const fused = signal === undefined ? timeout : AbortSignal.any([signal, timeout])
188
183
  let response
189
184
  try {
190
185
  response = await fetch(this.endpoint, {
191
186
  method: 'POST',
192
187
  redirect: 'error',
193
188
  headers: {
194
- ...authorization.headers,
189
+ // GateMux accepts the account's Bearer credential; the DeepSeek-only
190
+ // `x-dsh-auth-token` header is not used here.
191
+ authorization: `Bearer ${token}`,
195
192
  'anthropic-version': ANTHROPIC_VERSION,
196
193
  'content-type': 'application/json',
197
194
  accept: 'application/json',
@@ -201,9 +198,6 @@ export class GateMuxSearchProvider {
201
198
  })
202
199
  } catch (error) {
203
200
  if (signal?.aborted === true) throw new WebError('GateMux web search was cancelled', 'WEB_ABORTED')
204
- if (authorization.revoked?.aborted === true) {
205
- throw new WebError('Signed out of GateMux while the search was running.', 'ACCOUNT_SIGN_IN_REQUIRED', { cause: error })
206
- }
207
201
  throw new WebError(`GateMux web search request failed: ${String(error)}`, 'WEB_PROVIDER_ERROR', { cause: error })
208
202
  }
209
203
 
@@ -218,7 +212,7 @@ export class GateMuxSearchProvider {
218
212
  }
219
213
  if (response.status === 401) {
220
214
  try {
221
- await authorization.reject?.()
215
+ await account?.rejectToken(token)
222
216
  } catch {
223
217
  // The inference failure is the answer; a storage failure cannot replace it.
224
218
  }