@sortedyuan/provider-deepseek 0.0.0-stage → 0.2.0
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.md +53 -2
- package/dist/deepseek-model.d.ts +25 -0
- package/dist/deepseek-model.d.ts.map +1 -0
- package/dist/deepseek-model.js +107 -0
- package/dist/deepseek-model.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +34 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +16 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +2 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +33 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yuan
|
|
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.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@sortedyuan/provider-deepseek`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DeepSeek model adapter for May.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { May, InMemoryContext } from "@sortedyuan/core";
|
|
7
|
+
import { DeepSeekModel } from "@sortedyuan/provider-deepseek";
|
|
8
|
+
|
|
9
|
+
const may = new May({
|
|
10
|
+
model: new DeepSeekModel({
|
|
11
|
+
apiKey: process.env.DEEPSEEK_API_KEY!,
|
|
12
|
+
model: "deepseek-v4-flash",
|
|
13
|
+
maxTokens: 4096,
|
|
14
|
+
}),
|
|
15
|
+
context: new InMemoryContext(),
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The adapter uses DeepSeek's streaming Chat Completions endpoint and preserves
|
|
20
|
+
`reasoning_content` across tool-call turns.
|
|
21
|
+
|
|
22
|
+
## Live integration test
|
|
23
|
+
|
|
24
|
+
The regular test suite is fully offline. To run the opt-in test against the
|
|
25
|
+
real API, fill in `~/.may/config.json` and run:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pnpm test:integration:deepseek
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Expected configuration:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"providers": {
|
|
36
|
+
"deepseek": {
|
|
37
|
+
"adapter": "deepseek-chat",
|
|
38
|
+
"apiKey": "",
|
|
39
|
+
"baseURL": "https://api.deepseek.com"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"models": {
|
|
43
|
+
"deepseek": {
|
|
44
|
+
"provider": "deepseek",
|
|
45
|
+
"model": "deepseek-v4-flash"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"defaultModel": "deepseek"
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Do not commit this file or print its contents in logs.
|
|
53
|
+
|
|
54
|
+
See the [DeepSeek API documentation](https://api-docs.deepseek.com/zh-cn/).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Model, ModelEvent, ModelRequest, ModelStreamOptions } from "@sortedyuan/core";
|
|
2
|
+
/** Provider/model metadata determines concrete supported values. */
|
|
3
|
+
export type DeepSeekReasoningEffort = string;
|
|
4
|
+
export interface DeepSeekModelOptions {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
model: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
thinking?: "enabled" | "disabled";
|
|
9
|
+
reasoningEffort?: DeepSeekReasoningEffort;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
fetch?: typeof globalThis.fetch;
|
|
12
|
+
}
|
|
13
|
+
export declare class DeepSeekModel implements Model {
|
|
14
|
+
private readonly apiKey;
|
|
15
|
+
private readonly model;
|
|
16
|
+
private readonly baseURL;
|
|
17
|
+
private readonly thinking;
|
|
18
|
+
private readonly reasoningEffort;
|
|
19
|
+
private readonly maxTokens;
|
|
20
|
+
private readonly fetchImplementation;
|
|
21
|
+
constructor(options: DeepSeekModelOptions);
|
|
22
|
+
stream(request: ModelRequest, options: ModelStreamOptions): AsyncIterable<ModelEvent>;
|
|
23
|
+
private createRequest;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=deepseek-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek-model.d.ts","sourceRoot":"","sources":["../src/deepseek-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAc1B,oEAAoE;AACpE,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAClC,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,qBAAa,aAAc,YAAW,KAAK;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAC9D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsC;IACtE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA0B;IAE9D,YAAY,OAAO,EAAE,oBAAoB,EAsBxC;IAEM,MAAM,CACX,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,kBAAkB,GAC1B,aAAa,CAAC,UAAU,CAAC,CAyB3B;IAED,OAAO,CAAC,aAAa;CAqBtB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { streamOpenAICompatibleResponse, toOpenAICompatibleMessages, toOpenAICompatibleTools, } from "@sortedyuan/provider-openai-compatible";
|
|
2
|
+
import { parseRetryAfterMs } from "@sortedyuan/provider-openai-compatible/http";
|
|
3
|
+
import { DeepSeekApiError, DeepSeekFinishReasonError, DeepSeekProtocolError, } from "./errors.js";
|
|
4
|
+
export class DeepSeekModel {
|
|
5
|
+
apiKey;
|
|
6
|
+
model;
|
|
7
|
+
baseURL;
|
|
8
|
+
thinking;
|
|
9
|
+
reasoningEffort;
|
|
10
|
+
maxTokens;
|
|
11
|
+
fetchImplementation;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
if (options.apiKey.trim() === "") {
|
|
14
|
+
throw new TypeError("apiKey must not be empty");
|
|
15
|
+
}
|
|
16
|
+
if (options.model.trim() === "") {
|
|
17
|
+
throw new TypeError("model must not be empty");
|
|
18
|
+
}
|
|
19
|
+
if (options.maxTokens !== undefined &&
|
|
20
|
+
(!Number.isSafeInteger(options.maxTokens) || options.maxTokens < 1)) {
|
|
21
|
+
throw new RangeError("maxTokens must be a positive safe integer");
|
|
22
|
+
}
|
|
23
|
+
this.apiKey = options.apiKey;
|
|
24
|
+
this.model = options.model;
|
|
25
|
+
this.baseURL = (options.baseURL ?? "https://api.deepseek.com")
|
|
26
|
+
.replace(/\/+$/, "");
|
|
27
|
+
this.thinking = options.thinking;
|
|
28
|
+
this.reasoningEffort = options.reasoningEffort;
|
|
29
|
+
this.maxTokens = options.maxTokens;
|
|
30
|
+
this.fetchImplementation = options.fetch ?? globalThis.fetch;
|
|
31
|
+
}
|
|
32
|
+
async *stream(request, options) {
|
|
33
|
+
if (request.responseFormat !== undefined)
|
|
34
|
+
throw new TypeError("DeepSeek adapter does not support responseFormat");
|
|
35
|
+
const response = await this.fetchImplementation(`${this.baseURL}/chat/completions`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
"authorization": `Bearer ${this.apiKey}`,
|
|
39
|
+
"content-type": "application/json",
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(this.createRequest(request)),
|
|
42
|
+
signal: options.signal,
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok)
|
|
45
|
+
throw await createApiError(response);
|
|
46
|
+
yield* streamOpenAICompatibleResponse(response, {
|
|
47
|
+
signal: options.signal,
|
|
48
|
+
providerName: "DeepSeek",
|
|
49
|
+
protocolError: (message, errorOptions) => new DeepSeekProtocolError(message, errorOptions),
|
|
50
|
+
finishReasonError: (finishReason) => new DeepSeekFinishReasonError(finishReason),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
createRequest(request) {
|
|
54
|
+
const body = {
|
|
55
|
+
model: this.model,
|
|
56
|
+
messages: toOpenAICompatibleMessages(request.messages),
|
|
57
|
+
stream: true,
|
|
58
|
+
stream_options: { include_usage: true },
|
|
59
|
+
};
|
|
60
|
+
if (request.tools.length > 0) {
|
|
61
|
+
body.tools = toOpenAICompatibleTools(request.tools);
|
|
62
|
+
}
|
|
63
|
+
if (this.thinking !== undefined) {
|
|
64
|
+
body.thinking = { type: this.thinking };
|
|
65
|
+
}
|
|
66
|
+
if (this.reasoningEffort !== undefined) {
|
|
67
|
+
body.reasoning_effort = this.reasoningEffort;
|
|
68
|
+
}
|
|
69
|
+
if (this.maxTokens !== undefined)
|
|
70
|
+
body.max_tokens = this.maxTokens;
|
|
71
|
+
return body;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function createApiError(response) {
|
|
75
|
+
const text = await response.text();
|
|
76
|
+
let message = text || `DeepSeek request failed with status ${response.status}`;
|
|
77
|
+
let providerType;
|
|
78
|
+
let providerCode;
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(text);
|
|
81
|
+
if (typeof parsed.error?.message === "string") {
|
|
82
|
+
message = parsed.error.message;
|
|
83
|
+
}
|
|
84
|
+
if (typeof parsed.error?.type === "string") {
|
|
85
|
+
providerType = parsed.error.type;
|
|
86
|
+
}
|
|
87
|
+
if (typeof parsed.error?.code === "string") {
|
|
88
|
+
providerCode = parsed.error.code;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Keep the response text as the error message when it is not JSON.
|
|
93
|
+
}
|
|
94
|
+
const errorOptions = {
|
|
95
|
+
status: response.status,
|
|
96
|
+
message,
|
|
97
|
+
};
|
|
98
|
+
if (providerType !== undefined)
|
|
99
|
+
errorOptions.providerType = providerType;
|
|
100
|
+
if (providerCode !== undefined)
|
|
101
|
+
errorOptions.providerCode = providerCode;
|
|
102
|
+
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
103
|
+
if (retryAfterMs !== undefined)
|
|
104
|
+
errorOptions.retryAfterMs = retryAfterMs;
|
|
105
|
+
return new DeepSeekApiError(errorOptions);
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=deepseek-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek-model.js","sourceRoot":"","sources":["../src/deepseek-model.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAChF,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAgBrB,MAAM,OAAO,aAAa;IACP,MAAM,CAAS;IACf,KAAK,CAAS;IACd,OAAO,CAAS;IAChB,QAAQ,CAAqC;IAC7C,eAAe,CAAsC;IACrD,SAAS,CAAqB;IAC9B,mBAAmB,CAA0B;IAE9D,YAAY,OAA6B;QACvC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;QACjD,CAAC;QACD,IACE,OAAO,CAAC,SAAS,KAAK,SAAS;YAC/B,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,EACnE,CAAC;YACD,MAAM,IAAI,UAAU,CAAC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;IAErC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAE7B,CAAC;QACF,IAAI,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC9C,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,IAAI,OAAO,MAAM,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3C,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QACnC,CAAC;QACD,IAAI,OAAO,MAAM,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3C,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QACnC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,mEAAmE;IACrE,CAAC;IAED,MAAM,YAAY,GAAsD;QACtE,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO;KACR,CAAC;IACF,IAAI,YAAY,KAAK,SAAS;QAAE,YAAY,CAAC,YAAY,GAAG,YAAY,CAAC;IACzE,IAAI,YAAY,KAAK,SAAS;QAAE,YAAY,CAAC,YAAY,GAAG,YAAY,CAAC;IACzE,MAAM,YAAY,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5E,IAAI,YAAY,KAAK,SAAS;QAAE,YAAY,CAAC,YAAY,GAAG,YAAY,CAAC;IACzE,OAAO,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class DeepSeekError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(code: string, message: string, options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
export declare class DeepSeekApiError extends DeepSeekError {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly providerType: string | undefined;
|
|
8
|
+
readonly providerCode: string | undefined;
|
|
9
|
+
readonly retryAfterMs: number | undefined;
|
|
10
|
+
constructor(options: {
|
|
11
|
+
status: number;
|
|
12
|
+
message: string;
|
|
13
|
+
providerType?: string;
|
|
14
|
+
providerCode?: string;
|
|
15
|
+
retryAfterMs?: number;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export declare class DeepSeekProtocolError extends DeepSeekError {
|
|
19
|
+
constructor(message: string, options?: ErrorOptions);
|
|
20
|
+
}
|
|
21
|
+
export declare class DeepSeekFinishReasonError extends DeepSeekError {
|
|
22
|
+
readonly finishReason: string;
|
|
23
|
+
constructor(finishReason: string);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAIhE;CACF;AAED,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1C,YAAY,OAAO,EAAE;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,EAMA;CACF;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAElD;CACF;AAED,qBAAa,yBAA0B,SAAQ,aAAa;IAC1D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,YAAY,YAAY,EAAE,MAAM,EAM/B;CACF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class DeepSeekError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class DeepSeekApiError extends DeepSeekError {
|
|
10
|
+
status;
|
|
11
|
+
providerType;
|
|
12
|
+
providerCode;
|
|
13
|
+
retryAfterMs;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super("DEEPSEEK_API_ERROR", options.message);
|
|
16
|
+
this.status = options.status;
|
|
17
|
+
this.providerType = options.providerType;
|
|
18
|
+
this.providerCode = options.providerCode;
|
|
19
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class DeepSeekProtocolError extends DeepSeekError {
|
|
23
|
+
constructor(message, options) {
|
|
24
|
+
super("DEEPSEEK_PROTOCOL_ERROR", message, options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class DeepSeekFinishReasonError extends DeepSeekError {
|
|
28
|
+
finishReason;
|
|
29
|
+
constructor(finishReason) {
|
|
30
|
+
super("DEEPSEEK_INCOMPLETE_RESPONSE", `DeepSeek stopped with finish reason \"${finishReason}\"`);
|
|
31
|
+
this.finishReason = finishReason;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe,EAAE,OAAsB;QAC/D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACxC,MAAM,CAAS;IACf,YAAY,CAAqB;IACjC,YAAY,CAAqB;IACjC,YAAY,CAAqB;IAE1C,YAAY,OAMX;QACC,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,aAAa;IACjD,YAAY,CAAS;IAE9B,YAAY,YAAoB;QAC9B,KAAK,CACH,8BAA8B,EAC9B,yCAAyC,YAAY,IAAI,CAC1D,CAAC;QACF,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OpenAICompatibleMessage, OpenAICompatibleToolDefinition } from "@sortedyuan/provider-openai-compatible";
|
|
2
|
+
export interface DeepSeekChatRequest {
|
|
3
|
+
model: string;
|
|
4
|
+
messages: OpenAICompatibleMessage[];
|
|
5
|
+
stream: true;
|
|
6
|
+
stream_options: {
|
|
7
|
+
include_usage: true;
|
|
8
|
+
};
|
|
9
|
+
tools?: OpenAICompatibleToolDefinition[];
|
|
10
|
+
thinking?: {
|
|
11
|
+
type: "enabled" | "disabled";
|
|
12
|
+
};
|
|
13
|
+
reasoning_effort?: string;
|
|
14
|
+
max_tokens?: number;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,wCAAwC,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,MAAM,EAAE,IAAI,CAAC;IACb,cAAc,EAAE;QAAE,aAAa,EAAE,IAAI,CAAA;KAAE,CAAC;IACxC,KAAK,CAAC,EAAE,8BAA8B,EAAE,CAAC;IACzC,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,GAAG,UAAU,CAAA;KAAE,CAAC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sortedyuan/provider-deepseek",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "DeepSeek model adapter for May.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"!dist/.tsbuildinfo"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@sortedyuan/core": "0.2.0",
|
|
20
|
+
"@sortedyuan/provider-openai-compatible": "0.2.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@sortedyuan/config": "0.3.1"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -b",
|
|
31
|
+
"clean": "tsc -b --clean",
|
|
32
|
+
"test": "pnpm run build && node --test test/*.test.mjs",
|
|
33
|
+
"test:coverage": "pnpm run build && node --test --experimental-test-coverage test/*.test.mjs",
|
|
34
|
+
"test:integration": "pnpm --filter @sortedyuan/config run build && pnpm run build && node --test test-integration/*.test.mjs"
|
|
35
|
+
}
|
|
6
36
|
}
|