@deepseek-ai/dsh-deepseek-auth 0.0.0-stage → 0.2.3-alpha.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.
- package/LICENSE +21 -0
- package/README.i18n.yaml +58 -0
- package/README.md +178 -2
- package/README.zh.md +179 -0
- package/lib/index.js +227 -0
- package/lib/types/index.d.ts +94 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +232 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/types.d.ts +111 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +2 -0
- package/lib/types/types.js.map +1 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +55 -3
- package/src/index.ts +257 -0
- package/src/types.ts +115 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
|
2
|
+
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
|
3
|
+
# After editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/account/deepseek-auth/README.md
|
|
5
|
+
/:
|
|
6
|
+
en: 72aa9af5bb4b9d47
|
|
7
|
+
zh: 0474d8db22dbf845
|
|
8
|
+
/deepseek-ai-dsh-deepseek-auth:
|
|
9
|
+
en: 819d59b8b22bf985
|
|
10
|
+
zh: 3f919581e5639cca
|
|
11
|
+
/deepseek-ai-dsh-deepseek-auth/summary:
|
|
12
|
+
en: 27b451d236a03881
|
|
13
|
+
zh: 2eb02aed4c4ab1b3
|
|
14
|
+
/deepseek-ai-dsh-deepseek-auth/table-of-contents:
|
|
15
|
+
en: d152484eb41ac6b4
|
|
16
|
+
zh: 09388d293f9be9cb
|
|
17
|
+
/deepseek-ai-dsh-deepseek-auth/use-this-package:
|
|
18
|
+
en: 475c8fce4a8aa18f
|
|
19
|
+
zh: c5a2b3c20dc3ee53
|
|
20
|
+
/deepseek-ai-dsh-deepseek-auth/use-this-package/when-to-use-it:
|
|
21
|
+
en: 5ae5865ce8e74ca9
|
|
22
|
+
zh: f35aa7f2742a1e76
|
|
23
|
+
/deepseek-ai-dsh-deepseek-auth/use-this-package/authorizing-a-request:
|
|
24
|
+
en: 02b641a20536ed3e
|
|
25
|
+
zh: cf704140423f4091
|
|
26
|
+
/deepseek-ai-dsh-deepseek-auth/use-this-package/where-each-kind-s-credential-and-deployment-come-from:
|
|
27
|
+
en: b909920465406991
|
|
28
|
+
zh: babec6024f3741a0
|
|
29
|
+
/deepseek-ai-dsh-deepseek-auth/use-this-package/what-can-go-wrong:
|
|
30
|
+
en: 6b4a01982c7a435b
|
|
31
|
+
zh: 188c13fea190a619
|
|
32
|
+
/deepseek-ai-dsh-deepseek-auth/understand-the-implementation:
|
|
33
|
+
en: 6133f3219e92d614
|
|
34
|
+
zh: d4f47c8fe96bbb83
|
|
35
|
+
/deepseek-ai-dsh-deepseek-auth/understand-the-implementation/design-philosophy:
|
|
36
|
+
en: 781040be419e91c6
|
|
37
|
+
zh: fd7cfff0a180a6ca
|
|
38
|
+
/deepseek-ai-dsh-deepseek-auth/understand-the-implementation/source-map:
|
|
39
|
+
en: 28159a33fcde18a3
|
|
40
|
+
zh: 8e29411be0a9efe7
|
|
41
|
+
/deepseek-ai-dsh-deepseek-auth/understand-the-implementation/lifecycle:
|
|
42
|
+
en: 410428e4e26f97ee
|
|
43
|
+
zh: b0fff475dfebe3ad
|
|
44
|
+
/deepseek-ai-dsh-deepseek-auth/further-exploration:
|
|
45
|
+
en: 4d9c163447511873
|
|
46
|
+
zh: 39cd847064374250
|
|
47
|
+
/deepseek-ai-dsh-deepseek-auth/model-experience:
|
|
48
|
+
en: fe5289b96181fa86
|
|
49
|
+
zh: 186fd56ec8423081
|
|
50
|
+
/deepseek-ai-dsh-deepseek-auth/model-experience/kv-cache-effect:
|
|
51
|
+
en: 8d28a9884785f30c
|
|
52
|
+
zh: b1c45c04e1a543d7
|
|
53
|
+
/deepseek-ai-dsh-deepseek-auth/known-limitations-and-deferred-work:
|
|
54
|
+
en: d2fd57e36ce7b03a
|
|
55
|
+
zh: f105c8dbd169db9e
|
|
56
|
+
/deepseek-ai-dsh-deepseek-auth/known-limitations-and-deferred-work/dev-note:
|
|
57
|
+
en: e3eca6e1556f695c
|
|
58
|
+
zh: 7234e0729568e2e9
|
package/README.md
CHANGED
|
@@ -1,3 +1,179 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
description: "DeepSeek request authentication for plugins that call a DeepSeek API: one service chooses between the API key and the account sign-in, binds the credential to its deployment, and releases the request headers."
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# @deepseek-ai/dsh-deepseek-auth
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
`dsh-deepseek-auth` authenticates requests to DeepSeek APIs through `ctx.deepseekAuth`. A consumer names the credential kinds its API accepts, the API key, the account sign-in, or both, and the billing its settings choose. The service orders the kinds, binds each to the deployment its credential belongs to, and releases the headers of the first kind that has a credential. The DeepSeek model routes, the Search and Fetch APIs, and Messages search use it. It stores nothing: keys come from the credential store or the launch environment, and the sign-in from the account service.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Use this package](#use-this-package)
|
|
17
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
18
|
+
- [Further Exploration](#further-exploration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## Use this package
|
|
27
|
+
|
|
28
|
+
A plugin that calls a DeepSeek API asks this service for the credential of one request. The plugin sends the request itself and words its own failures.
|
|
29
|
+
|
|
30
|
+
### When to use it
|
|
31
|
+
|
|
32
|
+
Use it for every request a Host plugin sends to a DeepSeek deployment. Mount it in every composition that mounts a DeepSeek model route or a DeepSeek web provider; those plugins require it. It needs no configuration. It reads the credentials service and the account service when they are mounted and works without either.
|
|
33
|
+
|
|
34
|
+
### Authorizing a request
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
38
|
+
import type {} from '@deepseek-ai/dsh-deepseek-auth'
|
|
39
|
+
|
|
40
|
+
declare const ctx: Context
|
|
41
|
+
declare const route: string | undefined // provider route of the conversation's latest model request
|
|
42
|
+
declare const signal: AbortSignal
|
|
43
|
+
|
|
44
|
+
const authorization = await ctx.deepseekAuth.authorize({
|
|
45
|
+
consumer: 'my-plugin',
|
|
46
|
+
accepts: ['account', 'api-key'],
|
|
47
|
+
billing: 'auto',
|
|
48
|
+
route,
|
|
49
|
+
destination: { path: '/v1/tools/search' },
|
|
50
|
+
}, signal)
|
|
51
|
+
if (authorization === undefined) throw new Error('no DeepSeek credential is configured')
|
|
52
|
+
await fetch(authorization.endpoint, { method: 'POST', headers: authorization.headers, signal })
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`accepts` lists the kinds the destination API accepts; a kind outside it is never tried. When an API starts to accept another kind, its consumer adds that kind to `accepts`, and nothing else changes. `billing` is `api-key`, `account`, or `auto`, which follows the model route of the conversation:
|
|
56
|
+
|
|
57
|
+
| `billing` | Conversation's model route | Kinds tried, in order |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `api-key` | any | API key |
|
|
60
|
+
| `account` | any | account sign-in |
|
|
61
|
+
| `auto` | the route connected for the account sign-in, `deepseek-account` | account sign-in, then API key |
|
|
62
|
+
| `auto` | the route connected for the API key, `deepseek-official` | API key |
|
|
63
|
+
| `auto` | any other route, or no conversation | API key, then account sign-in |
|
|
64
|
+
|
|
65
|
+
A route belongs to the first two `auto` rows only while the plugin that registers it is mounted and has connected it. A conversation recorded on `deepseek-account` or `deepseek-official` whose plugin is not mounted follows the last row.
|
|
66
|
+
|
|
67
|
+
`destination` is a path appended to the origin of the chosen kind's deployment, or one absolute `url`. A kind serves an absolute URL only when the URL is under the origin of that kind's deployment and embeds no credentials, so a key is never sent to another origin.
|
|
68
|
+
|
|
69
|
+
An authorization carries the `kind`, the `endpoint`, and the request `headers`. An API key is sent as `Authorization: Bearer` unless `apiKeyHeaders` names `x-api-key` or both; the account sign-in is sent in the header the account service chooses. `reject()`, present for the account sign-in, invalidates the credential after the destination answered HTTP 401. `revoked`, also present for the account sign-in, aborts when the account signs out: the consumer ends the request it authenticated and reports that end as its own failure, not as the caller's cancellation.
|
|
70
|
+
|
|
71
|
+
`candidates(request)` returns the same kinds in the same order without reading a credential. Each candidate answers `configured()` for readiness checks and `resolve(signal)` for the credential, and names its `endpoint` and, for an API key, its `reference` for diagnostics. `routeKind(route)` names the kind a mounted model route plugin connected under that route id, and `undefined` for every other route.
|
|
72
|
+
|
|
73
|
+
### Where each kind's credential and deployment come from
|
|
74
|
+
|
|
75
|
+
| Kind | With its model route mounted | Without it |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| API key | The key reference and base URL of the `deepseek-official` route's settings, which the Models page edits | `DEEPSEEK_API_KEY`, sent to `https://api.deepseek.com` |
|
|
78
|
+
| Account sign-in | The account service's credential, sent to the origin of the `deepseek-account` route's base URL | The account service's credential, sent to the origin `DEEPSEEK_BASE_URL` names, the official API by default |
|
|
79
|
+
|
|
80
|
+
A model route plugin connects the provider route it registers and its settings from within `ctx.effect()`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
84
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
85
|
+
import type {} from '@deepseek-ai/dsh-deepseek-auth'
|
|
86
|
+
|
|
87
|
+
declare const ctx: Context
|
|
88
|
+
declare const settings: () => { baseURL: string; apiKeyEnv: string }
|
|
89
|
+
|
|
90
|
+
ctx.effect(() => ctx.deepseekAuth.connect('api-key', 'deepseek-official', () => {
|
|
91
|
+
const { baseURL, apiKeyEnv } = settings()
|
|
92
|
+
return { baseURL, reference: credentialRef(apiKeyEnv), owner: 'llm-deepseek' }
|
|
93
|
+
}))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The service calls the function for each request, so a settings change reaches the next request. While the connection exists, `auto` billing orders a conversation on that route by the connected kind. A request can carry its own connection of a kind in `connections`, which replaces the connected or default one: a model route passes the configuration generation it captured for one model request, and a consumer with its own endpoint and key passes those.
|
|
97
|
+
|
|
98
|
+
A key is read through the credentials service when one is mounted and through the launch environment otherwise, as [`dsh-credentials`](../../credentials/credentials/README.md) defines for references.
|
|
99
|
+
|
|
100
|
+
### What can go wrong
|
|
101
|
+
|
|
102
|
+
- `authorize()` returns `undefined` when no candidate has a credential. The consumer words the failure; `candidates()` supplies the kinds and the key reference to name.
|
|
103
|
+
- An API key that is blank or holds characters no HTTP header can carry fails with `DeepSeekAuthError` code `INVALID_CREDENTIAL`. The message names the owner and the reference to fix and never the key.
|
|
104
|
+
- A kind whose connection does not resolve, because the route's settings throw, a base URL does not parse, or `DEEPSEEK_BASE_URL` is no HTTP(S) URL, appears in `candidates()` as an unresolved entry. `authorize()` stops there with code `UNRESOLVED_CONNECTION` and does not try a later kind.
|
|
105
|
+
- A second `connect()` of one kind throws `DUPLICATE_CONNECTION`.
|
|
106
|
+
- Credential store failures propagate.
|
|
107
|
+
|
|
108
|
+
-----
|
|
109
|
+
|
|
110
|
+
<a id="understand-the-implementation"></a>
|
|
111
|
+
## Understand the implementation
|
|
112
|
+
|
|
113
|
+
<details>
|
|
114
|
+
<summary>Implementation internals — click to expand</summary>
|
|
115
|
+
|
|
116
|
+
This section explains the design decisions behind the service; the observable behavior is covered in [Use this package](#use-this-package).
|
|
117
|
+
|
|
118
|
+
### Design philosophy
|
|
119
|
+
|
|
120
|
+
- **Consumers declare what their API accepts; the service chooses.** DeepSeek adds account authentication to its APIs one at a time. A consumer's `accepts` list is the only place that records what one API accepts, so widening it is the whole change when an API gains a kind.
|
|
121
|
+
- **A credential is bound to its deployment.** Each kind has one deployment at a time, and a credential is released only for destinations under that deployment's origin.
|
|
122
|
+
- **The model routes are consumers.** The route plugins connect their settings and ask for authorization like every other consumer, so the transport and the model service hold no credential interface.
|
|
123
|
+
- **The service depends on no consumer.** It reads the credential store and the account service and names no model route: each route plugin passes its own route id when it connects, and `auto` billing compares the conversation's route with the connected ids.
|
|
124
|
+
|
|
125
|
+
### Source map
|
|
126
|
+
|
|
127
|
+
| File | Role |
|
|
128
|
+
|---|---|
|
|
129
|
+
| [`src/index.ts`](src/index.ts) | The service: connections, billing order, destination binding, the API-key and account sources, `DeepSeekAuthError` |
|
|
130
|
+
| [`src/types.ts`](src/types.ts) | Request, connection, candidate, and authorization types |
|
|
131
|
+
|
|
132
|
+
### Lifecycle
|
|
133
|
+
|
|
134
|
+
The service holds only the connections model route plugins registered; each disposer removes one. Nothing else is retained between requests: every `candidates()` call reads the connected settings again, and every `resolve()` reads the credential again.
|
|
135
|
+
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
-----
|
|
139
|
+
|
|
140
|
+
<a id="further-exploration"></a>
|
|
141
|
+
## Further Exploration
|
|
142
|
+
|
|
143
|
+
- [Account package map](../README.md) — the account service and this service.
|
|
144
|
+
- [DeepSeek account subsystem](../../../docs/subsystems/account.md) — the account sign-in and the request credentials this service releases.
|
|
145
|
+
- [Credential-reference seam](../../credentials/credentials/README.md) — how a key reference is read and checked.
|
|
146
|
+
- [DeepSeek request authentication](../../../.agents/notes/implemented/architecture/2026-11-10-deepseek-request-authentication.md) — the decision and its rejected alternatives.
|
|
147
|
+
|
|
148
|
+
-----
|
|
149
|
+
|
|
150
|
+
<a id="model-experience"></a>
|
|
151
|
+
## Model Experience
|
|
152
|
+
|
|
153
|
+
None, as the service releases request headers to Host plugins and contributes nothing to a model request's content. Its consumers word the failures a model reads.
|
|
154
|
+
|
|
155
|
+
#### KV Cache effect
|
|
156
|
+
|
|
157
|
+
No invalidation; no credential enters a request prefix.
|
|
158
|
+
|
|
159
|
+
## Known Limitations and Deferred Work
|
|
160
|
+
|
|
161
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
162
|
+
|
|
163
|
+
These limits define when this package is a poor fit or needs special care. They are current package constraints, not a task backlog.
|
|
164
|
+
|
|
165
|
+
- **One deployment per kind** — a second `deepseek-official` style route with its own key and endpoint cannot connect; a consumer that needs another key passes its own connection in the request.
|
|
166
|
+
- **A route counts as a DeepSeek route only while its plugin is connected** — a conversation recorded on `deepseek-account` or `deepseek-official` follows the order of other routes, API key and then account sign-in, while that plugin is not mounted, and so does a DeepSeek model reached through another provider plugin.
|
|
167
|
+
- **No credential validation** — `configured()` reports presence only, so a wrong key counts as configured until the destination rejects it.
|
|
168
|
+
|
|
169
|
+
<a id="dev-note"></a>
|
|
170
|
+
### Dev Note
|
|
171
|
+
|
|
172
|
+
<details>
|
|
173
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
174
|
+
|
|
175
|
+
This Dev Note is working context for maintainers: open questions and undecided directions. It is explicitly non-authoritative — shipped behavior, limits, and accepted rationale live in the sections above, the package code, and the linked Agent Note.
|
|
176
|
+
|
|
177
|
+
The speech and document APIs under `/v1/tools/` accept only the API key today. Their consumers declare `accepts: ['api-key']` and add `account` when the server accepts the account sign-in.
|
|
178
|
+
|
|
179
|
+
</details>
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "面向调用 DeepSeek API 的插件的 DeepSeek 请求鉴权:一个服务在 API 密钥与账号登录之间选择,把凭据绑定到它所属的部署,并释放请求头。"
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-deepseek-auth
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
`dsh-deepseek-auth` 通过 `ctx.deepseekAuth` 为发往 DeepSeek API 的请求鉴权。消费方给出其 API 接受的凭据种类(API 密钥、账号登录,或两者)以及其设置选择的计费方式。服务排定种类的顺序,把每一种绑定到其凭据所属的部署,并释放第一个持有凭据的种类的请求头。DeepSeek 模型路由、Search 与 Fetch API、Messages 搜索都使用它。它不存储任何东西:密钥来自凭据存储或启动环境,登录凭据来自账号服务。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [进一步探索](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与延期工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
调用 DeepSeek API 的插件向本服务索取一次请求的凭据。请求由插件自己发送,失败的措辞也由插件自己决定。
|
|
29
|
+
|
|
30
|
+
### 何时使用
|
|
31
|
+
|
|
32
|
+
Host 插件发往 DeepSeek 部署的每一个请求都使用它。凡是挂载了 DeepSeek 模型路由或 DeepSeek Web 提供方的组合都要挂载它,这些插件依赖它。它不需要配置。凭据服务和账号服务已挂载时它会读取它们,两者都没有时也能工作。
|
|
33
|
+
|
|
34
|
+
### 为请求鉴权
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
38
|
+
import type {} from '@deepseek-ai/dsh-deepseek-auth'
|
|
39
|
+
|
|
40
|
+
declare const ctx: Context
|
|
41
|
+
declare const route: string | undefined // provider route of the conversation's latest model request
|
|
42
|
+
declare const signal: AbortSignal
|
|
43
|
+
|
|
44
|
+
const authorization = await ctx.deepseekAuth.authorize({
|
|
45
|
+
consumer: 'my-plugin',
|
|
46
|
+
accepts: ['account', 'api-key'],
|
|
47
|
+
billing: 'auto',
|
|
48
|
+
route,
|
|
49
|
+
destination: { path: '/v1/tools/search' },
|
|
50
|
+
}, signal)
|
|
51
|
+
if (authorization === undefined) throw new Error('no DeepSeek credential is configured')
|
|
52
|
+
await fetch(authorization.endpoint, { method: 'POST', headers: authorization.headers, signal })
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`accepts` 列出目标 API 接受的种类,不在其中的种类不会被尝试。某个 API 开始接受另一种凭据时,它的消费方把该种类加入 `accepts`,其余不变。`billing` 取 `api-key`、`account` 或 `auto`,`auto` 跟随会话的模型路由:
|
|
56
|
+
|
|
57
|
+
| `billing` | 会话的模型路由 | 依次尝试的种类 |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `api-key` | 任意 | API 密钥 |
|
|
60
|
+
| `account` | 任意 | 账号登录 |
|
|
61
|
+
| `auto` | 为账号登录登记的路由,即 `deepseek-account` | 账号登录,然后 API 密钥 |
|
|
62
|
+
| `auto` | 为 API 密钥登记的路由,即 `deepseek-official` | API 密钥 |
|
|
63
|
+
| `auto` | 其他任何路由,或不在会话中 | API 密钥,然后账号登录 |
|
|
64
|
+
|
|
65
|
+
只有注册某条路由的插件已挂载并登记了它,该路由才属于前两行 `auto`。记录在 `deepseek-account` 或 `deepseek-official` 上的会话,在对应插件未挂载时按最后一行处理。
|
|
66
|
+
|
|
67
|
+
`destination` 是拼接到所选种类部署 origin 之后的路径,或一个绝对 `url`。只有当绝对 URL 位于某种类部署的 origin 之下且不内嵌凭据时,该种类才为它服务,因此密钥不会被发往其他 origin。
|
|
68
|
+
|
|
69
|
+
一次授权携带 `kind`、`endpoint` 和请求 `headers`。API 密钥以 `Authorization: Bearer` 发送,除非 `apiKeyHeaders` 指定 `x-api-key` 或两者;账号登录凭据放在账号服务选定的请求头里。`reject()` 只在账号登录时存在,用于在目标返回 HTTP 401 后作废该凭据。`revoked` 同样只在账号登录时存在,账号退出登录时中止:消费方结束它鉴权的请求,并把这次结束报告为自身的失败,而不是调用方的取消。
|
|
70
|
+
|
|
71
|
+
`candidates(request)` 以相同顺序返回相同的种类,但不读取凭据。每个候选用 `configured()` 回答就绪检查,用 `resolve(signal)` 给出凭据,并给出 `endpoint`,API 密钥还给出供诊断使用的 `reference`。`routeKind(route)` 给出已挂载的模型路由插件在该路由 id 下登记的种类,其他路由一律为 `undefined`。
|
|
72
|
+
|
|
73
|
+
### 每种凭据及其部署的来源
|
|
74
|
+
|
|
75
|
+
| 种类 | 其模型路由已挂载 | 未挂载 |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| API 密钥 | `deepseek-official` 路由设置里的密钥引用和 base URL,即 Models 页面编辑的那份 | `DEEPSEEK_API_KEY`,发往 `https://api.deepseek.com` |
|
|
78
|
+
| 账号登录 | 账号服务的凭据,发往 `deepseek-account` 路由 base URL 的 origin | 账号服务的凭据,发往 `DEEPSEEK_BASE_URL` 所指的 origin,默认为官方 API |
|
|
79
|
+
|
|
80
|
+
模型路由插件在 `ctx.effect()` 内登记它注册的提供方路由和自己的设置:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
84
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
85
|
+
import type {} from '@deepseek-ai/dsh-deepseek-auth'
|
|
86
|
+
|
|
87
|
+
declare const ctx: Context
|
|
88
|
+
declare const settings: () => { baseURL: string; apiKeyEnv: string }
|
|
89
|
+
|
|
90
|
+
ctx.effect(() => ctx.deepseekAuth.connect('api-key', 'deepseek-official', () => {
|
|
91
|
+
const { baseURL, apiKeyEnv } = settings()
|
|
92
|
+
return { baseURL, reference: credentialRef(apiKeyEnv), owner: 'llm-deepseek' }
|
|
93
|
+
}))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
服务对每个请求调用这个函数,所以设置的改动在下一个请求生效。连接存在期间,`auto` 计费按所登记的种类排定该路由上会话的顺序。请求可以在 `connections` 里携带某一种类自己的连接,它取代已登记的或默认的连接:模型路由传入它为一次模型请求捕获的那一代配置,拥有自己端点和密钥的消费方传入这两项。
|
|
97
|
+
|
|
98
|
+
密钥在凭据服务已挂载时经由它读取,否则经由启动环境读取,规则由 [`dsh-credentials`](../../credentials/credentials/README.zh.md) 为引用定义。
|
|
99
|
+
|
|
100
|
+
### 可能出错的地方
|
|
101
|
+
|
|
102
|
+
- 没有候选持有凭据时,`authorize()` 返回 `undefined`。失败的措辞由消费方决定;`candidates()` 提供要指出的种类和密钥引用。
|
|
103
|
+
- 空白的或含有 HTTP 请求头无法携带的字符的 API 密钥,以 `DeepSeekAuthError`(代码 `INVALID_CREDENTIAL`)失败。消息指出属主和要修正的引用,不包含密钥。
|
|
104
|
+
- 连接无法解析的种类(路由设置抛出、base URL 无法解析,或 `DEEPSEEK_BASE_URL` 不是 HTTP(S) URL)在 `candidates()` 中表现为未解析条目。`authorize()` 在此以代码 `UNRESOLVED_CONNECTION` 停止,不再尝试后面的种类。
|
|
105
|
+
- 对同一种类第二次 `connect()` 抛出 `DUPLICATE_CONNECTION`。
|
|
106
|
+
- 凭据存储的失败向上传播。
|
|
107
|
+
|
|
108
|
+
-----
|
|
109
|
+
|
|
110
|
+
<a id="understand-the-implementation"></a>
|
|
111
|
+
## 理解实现
|
|
112
|
+
|
|
113
|
+
<details>
|
|
114
|
+
<summary>实现细节——点击展开</summary>
|
|
115
|
+
|
|
116
|
+
本节解释服务背后的设计决策;可观察的行为见[使用本包](#use-this-package)。
|
|
117
|
+
|
|
118
|
+
### 设计理念
|
|
119
|
+
|
|
120
|
+
- **消费方声明其 API 接受什么,服务负责选择。** DeepSeek 逐个为它的 API 增加账号鉴权。消费方的 `accepts` 列表是记录某个 API 接受什么的唯一位置,所以 API 新增一种凭据时,扩充这个列表就是全部改动。
|
|
121
|
+
- **凭据绑定到它的部署。** 每个种类同一时间只有一个部署,凭据只释放给该部署 origin 之下的目标。
|
|
122
|
+
- **模型路由也是消费方。** 路由插件登记自己的设置,并和其他消费方一样索取授权,因此传输层和模型服务不带任何凭据接口。
|
|
123
|
+
- **服务不依赖任何消费方。** 它读取凭据存储和账号服务,自身不写任何模型路由的名字:每个路由插件在登记时传入自己的路由 id,`auto` 计费把会话的路由与已登记的 id 比较。
|
|
124
|
+
|
|
125
|
+
### 源码地图
|
|
126
|
+
|
|
127
|
+
| 文件 | 职责 |
|
|
128
|
+
|---|---|
|
|
129
|
+
| [`src/index.ts`](src/index.ts) | 服务本体:连接、计费顺序、目标绑定、API 密钥来源与账号来源、`DeepSeekAuthError` |
|
|
130
|
+
| [`src/types.ts`](src/types.ts) | 请求、连接、候选与授权的类型 |
|
|
131
|
+
|
|
132
|
+
### 生命周期
|
|
133
|
+
|
|
134
|
+
服务只保存模型路由插件登记的连接,每个 disposer 移除一个。请求之间不保留其他任何东西:每次 `candidates()` 调用都重新读取已登记的设置,每次 `resolve()` 都重新读取凭据。
|
|
135
|
+
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
-----
|
|
139
|
+
|
|
140
|
+
<a id="further-exploration"></a>
|
|
141
|
+
## 进一步探索
|
|
142
|
+
|
|
143
|
+
- [账号包映射](../README.zh.md)——账号服务与本服务。
|
|
144
|
+
- [DeepSeek 账号子系统](../../../docs/subsystems/account.zh.md)——账号登录以及本服务释放的请求凭据。
|
|
145
|
+
- [凭据引用 seam](../../credentials/credentials/README.zh.md)——密钥引用如何读取与检查。
|
|
146
|
+
- [DeepSeek 请求鉴权](../../../.agents/notes/implemented/architecture/2026-11-10-deepseek-request-authentication.zh.md)——决策及被否决的替代方案。
|
|
147
|
+
|
|
148
|
+
-----
|
|
149
|
+
|
|
150
|
+
<a id="model-experience"></a>
|
|
151
|
+
## 模型体验
|
|
152
|
+
|
|
153
|
+
无,因为本服务向 Host 插件释放请求头,不向模型请求的内容贡献任何东西。模型读到的失败文案由它的消费方措辞。
|
|
154
|
+
|
|
155
|
+
#### KV Cache 影响
|
|
156
|
+
|
|
157
|
+
不失效;没有凭据进入请求前缀。
|
|
158
|
+
|
|
159
|
+
## 已知限制与延期工作
|
|
160
|
+
|
|
161
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
162
|
+
|
|
163
|
+
这些限制说明本包在何时不适用或需要特别注意。它们是当前的包约束,不是任务积压。
|
|
164
|
+
|
|
165
|
+
- **每个种类一个部署**——第二条带有自己密钥和端点的 `deepseek-official` 式路由无法登记;需要另一把密钥的消费方在请求里传入自己的连接。
|
|
166
|
+
- **路由只在其插件已登记时才算 DeepSeek 路由**——记录在 `deepseek-account` 或 `deepseek-official` 上的会话,在对应插件未挂载时按其他路由的顺序处理(先 API 密钥,后账号登录);经由其他提供方插件访问的 DeepSeek 模型也是如此。
|
|
167
|
+
- **不校验凭据**——`configured()` 只报告是否存在,所以错误的密钥在目标拒绝它之前都算已配置。
|
|
168
|
+
|
|
169
|
+
<a id="dev-note"></a>
|
|
170
|
+
### 开发备注
|
|
171
|
+
|
|
172
|
+
<details>
|
|
173
|
+
<summary>维护者的工作上下文——点击展开</summary>
|
|
174
|
+
|
|
175
|
+
本开发备注是维护者的工作上下文:未决问题和尚未确定的方向。它明确不具权威性——已交付的行为、限制和已接受的理由见上文各节、包代码和链接的 Agent Note。
|
|
176
|
+
|
|
177
|
+
`/v1/tools/` 下的语音和文档 API 目前只接受 API 密钥。它们的消费方声明 `accepts: ['api-key']`,待服务端接受账号登录后再加入 `account`。
|
|
178
|
+
|
|
179
|
+
</details>
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import { credentialRef, credentialRefConfigured, normalizeApiKey, resolveCredentialRef } from "@deepseek-ai/dsh-credentials";
|
|
3
|
+
import { HarnessError } from "@deepseek-ai/dsh-error";
|
|
4
|
+
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
5
|
+
//#region lib/types/index.js
|
|
6
|
+
/**
|
|
7
|
+
* DeepSeek request authentication (`ctx.deepseekAuth`). DeepSeek APIs accept two kinds of credential, the API key and
|
|
8
|
+
* the account sign-in, and each API accepts one or both. A consumer names the kinds its API accepts and the billing
|
|
9
|
+
* its settings choose; this service orders the kinds, binds each to the deployment its credential belongs to, and
|
|
10
|
+
* releases the request headers of the first kind that has a credential. Model route plugins connect the deployment
|
|
11
|
+
* their settings name; without a connection the API key is `DEEPSEEK_API_KEY` at the official API and the account
|
|
12
|
+
* sign-in goes to the deployment `DEEPSEEK_BASE_URL` names.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const authorization = await ctx.deepseekAuth.authorize({
|
|
16
|
+
* consumer: name, accepts: ['account', 'api-key'], billing: 'auto', route, destination: { path: '/v1/tools/search' },
|
|
17
|
+
* }, signal)
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @module @deepseek-ai/dsh-deepseek-auth
|
|
21
|
+
*/
|
|
22
|
+
/** Base URL of the official DeepSeek API, where `DEEPSEEK_API_KEY` is sent without a connected API-key route. */
|
|
23
|
+
const OFFICIAL_BASE_URL = "https://api.deepseek.com";
|
|
24
|
+
/** Credential reference of the official DeepSeek API key. */
|
|
25
|
+
const DEEPSEEK_API_KEY = credentialRef("DEEPSEEK_API_KEY");
|
|
26
|
+
/**
|
|
27
|
+
* Launch-environment variable naming the DeepSeek deployment the model routes default to. Without a connected account
|
|
28
|
+
* route, its origin receives the account sign-in.
|
|
29
|
+
*/
|
|
30
|
+
const DEEPSEEK_BASE_URL_ENV = "DEEPSEEK_BASE_URL";
|
|
31
|
+
/** A DeepSeek authentication failure; `message` never contains a credential. */
|
|
32
|
+
var DeepSeekAuthError = class extends HarnessError {
|
|
33
|
+
/**
|
|
34
|
+
* @param message - what failed and what to change.
|
|
35
|
+
* @param code - the failure class.
|
|
36
|
+
* @param options - the underlying failure.
|
|
37
|
+
*/
|
|
38
|
+
constructor(message, code, options) {
|
|
39
|
+
super(message, code, options);
|
|
40
|
+
this.name = "DeepSeekAuthError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The diagnostic for a configured API key that cannot be sent. The key never enters the text: `reference` names where to
|
|
45
|
+
* fix it. The Models page is named as the writer it usually is, not as the only one, because the same value can arrive
|
|
46
|
+
* from a hand-edited `.env` or a shell export in a composition that mounts no credentials service.
|
|
47
|
+
* @param reason - why the key cannot be sent.
|
|
48
|
+
* @param owner - settings namespace or plugin name prefixed to the text.
|
|
49
|
+
* @param reference - the credential reference the key was read under.
|
|
50
|
+
* @returns the message of the `INVALID_CREDENTIAL` failure.
|
|
51
|
+
*/
|
|
52
|
+
function unusableKey(reason, owner, reference) {
|
|
53
|
+
return `${owner}: the API key resolved from ${reference} ${{
|
|
54
|
+
empty: `is blank; set ${reference} to the raw key (the web Models page writes it) or export it in the launching environment`,
|
|
55
|
+
illegalCharacters: `contains characters no HTTP header can carry; set ${reference} to the raw key alone (the web Models page writes it)`
|
|
56
|
+
}[reason]}`;
|
|
57
|
+
}
|
|
58
|
+
/** Marks a failure of the launch-environment deployment, apart from a failure of a connected route's settings. */
|
|
59
|
+
var DeploymentError = class extends Error {
|
|
60
|
+
/** @param cause - why the variable's value is no deployment URL. */
|
|
61
|
+
constructor(cause) {
|
|
62
|
+
super("unresolved deployment", { cause });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/** `ctx.deepseekAuth`: the two DeepSeek credential kinds behind one request-authorization operation. */
|
|
66
|
+
var DeepSeekAuth = class extends Service {
|
|
67
|
+
connections = /* @__PURE__ */ new Map();
|
|
68
|
+
/** @param ctx - Host context; the credentials service and the account service are read when mounted. */
|
|
69
|
+
constructor(ctx) {
|
|
70
|
+
super(ctx, "deepseekAuth");
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Connect the deployment a model route plugin's settings name for one kind. Call it from within `ctx.effect()`.
|
|
74
|
+
* @param kind - the kind the plugin's route bills.
|
|
75
|
+
* @param route - provider route the plugin registers; {@link routeKind} answers `kind` for it while connected.
|
|
76
|
+
* @param connection - reads the plugin's current settings; a throw marks the kind unresolved for that operation.
|
|
77
|
+
* @returns the disposer removing the connection.
|
|
78
|
+
* @throws {DeepSeekAuthError} code `DUPLICATE_CONNECTION` when the kind is already connected.
|
|
79
|
+
*/
|
|
80
|
+
connect(kind, route, connection) {
|
|
81
|
+
if (this.connections.has(kind)) throw new DeepSeekAuthError(`deepseek-auth: the ${kind} deployment is already connected`, "DUPLICATE_CONNECTION");
|
|
82
|
+
this.connections.set(kind, {
|
|
83
|
+
route,
|
|
84
|
+
connection
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
this.connections.delete(kind);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The kind that bills a conversation on one model route.
|
|
92
|
+
* @param route - provider route of a model request; undefined names none.
|
|
93
|
+
* @returns the kind connected under that route, or undefined for a route no plugin connected.
|
|
94
|
+
*/
|
|
95
|
+
routeKind(route) {
|
|
96
|
+
for (const [kind, connected] of this.connections) if (connected.route === route) return kind;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The kinds one request can authenticate with, in the order its billing tries them, each bound to its destination.
|
|
100
|
+
* Nothing is read from a credential store.
|
|
101
|
+
* @param request - the request.
|
|
102
|
+
* @returns candidates and unresolved kinds, first preferred; empty when the destination accepts no kind the
|
|
103
|
+
* billing allows or no allowed kind serves an absolute destination.
|
|
104
|
+
*/
|
|
105
|
+
candidates(request) {
|
|
106
|
+
return this.order(request).filter((kind) => request.accepts.includes(kind)).flatMap((kind) => this.candidate(kind, request));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Release the credential of the first candidate that has one. A later candidate is not read once an earlier one
|
|
110
|
+
* has a credential, fails to read, or does not resolve.
|
|
111
|
+
* @param request - the request.
|
|
112
|
+
* @param signal - cancellation for the lookups.
|
|
113
|
+
* @returns the authorization, or undefined when no candidate has a credential.
|
|
114
|
+
* @throws {DeepSeekAuthError} code `UNRESOLVED_CONNECTION` at an unresolved kind, `INVALID_CREDENTIAL` for an
|
|
115
|
+
* unusable API key; store failures propagate.
|
|
116
|
+
*/
|
|
117
|
+
async authorize(request, signal) {
|
|
118
|
+
for (const candidate of this.candidates(request)) {
|
|
119
|
+
if ("unresolved" in candidate) throw new DeepSeekAuthError(`deepseek-auth: the ${candidate.kind} ${candidate.unresolved} does not resolve: ${String(candidate.error)}`, "UNRESOLVED_CONNECTION", { cause: candidate.error });
|
|
120
|
+
const authorization = await candidate.resolve(signal);
|
|
121
|
+
if (authorization !== void 0) return authorization;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** The kinds the billing tries, in order, before the destination's accepted kinds narrow them. */
|
|
125
|
+
order(request) {
|
|
126
|
+
const billing = request.billing ?? "auto";
|
|
127
|
+
if (billing !== "auto") return [billing];
|
|
128
|
+
switch (this.routeKind(request.route)) {
|
|
129
|
+
case "account": return ["account", "api-key"];
|
|
130
|
+
case "api-key": return ["api-key"];
|
|
131
|
+
default: return ["api-key", "account"];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Bind one kind to the request's destination; empty when the kind does not serve an absolute destination. */
|
|
135
|
+
candidate(kind, request) {
|
|
136
|
+
let connection;
|
|
137
|
+
try {
|
|
138
|
+
connection = request.connections?.[kind] ?? this.connections.get(kind)?.connection() ?? this.unconnected(kind);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return [{
|
|
141
|
+
kind,
|
|
142
|
+
unresolved: error instanceof DeploymentError ? "deployment" : "connection",
|
|
143
|
+
error: error instanceof DeploymentError ? error.cause : error
|
|
144
|
+
}];
|
|
145
|
+
}
|
|
146
|
+
let endpoint;
|
|
147
|
+
try {
|
|
148
|
+
const deployment = new URL(connection.baseURL);
|
|
149
|
+
if ("path" in request.destination) endpoint = `${deployment.origin}${request.destination.path}`;
|
|
150
|
+
else {
|
|
151
|
+
const destination = new URL(request.destination.url);
|
|
152
|
+
if (destination.origin !== deployment.origin || destination.username !== "" || destination.password !== "") return [];
|
|
153
|
+
endpoint = request.destination.url;
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
return [{
|
|
157
|
+
kind,
|
|
158
|
+
unresolved: "connection",
|
|
159
|
+
error
|
|
160
|
+
}];
|
|
161
|
+
}
|
|
162
|
+
return [kind === "api-key" ? this.apiKey(connection, endpoint, request) : this.account(endpoint)];
|
|
163
|
+
}
|
|
164
|
+
/** The connection of a kind no model route plugin connected. */
|
|
165
|
+
unconnected(kind) {
|
|
166
|
+
if (kind === "api-key") return { baseURL: OFFICIAL_BASE_URL };
|
|
167
|
+
const configured = launchEnvironmentOf(this.ctx).get(DEEPSEEK_BASE_URL_ENV)?.value;
|
|
168
|
+
if (configured === void 0 || configured.length === 0) return { baseURL: OFFICIAL_BASE_URL };
|
|
169
|
+
try {
|
|
170
|
+
const url = new URL(configured);
|
|
171
|
+
if (!/^https?:$/u.test(url.protocol) || url.username.length > 0 || url.password.length > 0) throw new Error(`${DEEPSEEK_BASE_URL_ENV} must be an HTTP(S) URL without credentials`);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
throw new DeploymentError(error);
|
|
174
|
+
}
|
|
175
|
+
return { baseURL: configured };
|
|
176
|
+
}
|
|
177
|
+
/** The API key read under the connection's reference, sent in the headers the request names. */
|
|
178
|
+
apiKey(connection, endpoint, request) {
|
|
179
|
+
const { ctx } = this;
|
|
180
|
+
const reference = connection.reference ?? DEEPSEEK_API_KEY;
|
|
181
|
+
const owner = connection.owner ?? request.consumer;
|
|
182
|
+
return {
|
|
183
|
+
kind: "api-key",
|
|
184
|
+
endpoint,
|
|
185
|
+
reference,
|
|
186
|
+
configured: () => credentialRefConfigured(ctx, reference),
|
|
187
|
+
resolve: async (signal) => {
|
|
188
|
+
signal?.throwIfAborted();
|
|
189
|
+
const raw = await resolveCredentialRef(ctx, reference);
|
|
190
|
+
if (raw === void 0) return void 0;
|
|
191
|
+
const checked = normalizeApiKey(raw);
|
|
192
|
+
if (!checked.ok) throw new DeepSeekAuthError(unusableKey(checked.reason, owner, reference), "INVALID_CREDENTIAL");
|
|
193
|
+
const headers = {};
|
|
194
|
+
for (const header of request.apiKeyHeaders ?? ["authorization"]) headers[header] = header === "authorization" ? `Bearer ${checked.value}` : checked.value;
|
|
195
|
+
return {
|
|
196
|
+
kind: "api-key",
|
|
197
|
+
endpoint,
|
|
198
|
+
reference,
|
|
199
|
+
headers
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** The account sign-in the account service releases for the endpoint; absent without that service. */
|
|
205
|
+
account(endpoint) {
|
|
206
|
+
const { ctx } = this;
|
|
207
|
+
return {
|
|
208
|
+
kind: "account",
|
|
209
|
+
endpoint,
|
|
210
|
+
configured: async () => await ctx.get("deepseekAccount")?.resolveRequestCredential(endpoint) !== void 0,
|
|
211
|
+
resolve: async (signal) => {
|
|
212
|
+
signal?.throwIfAborted();
|
|
213
|
+
const credential = await ctx.get("deepseekAccount")?.resolveRequestCredential(endpoint);
|
|
214
|
+
if (credential === void 0) return void 0;
|
|
215
|
+
return {
|
|
216
|
+
kind: "account",
|
|
217
|
+
endpoint,
|
|
218
|
+
headers: credential.headers,
|
|
219
|
+
revoked: credential.revoked,
|
|
220
|
+
reject: () => credential.reject()
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
//#endregion
|
|
227
|
+
export { DeepSeekAuth, DeepSeekAuth as default, DeepSeekAuthError };
|