@arikusi/deepseek-mcp-server 1.1.0 → 1.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/CHANGELOG.md +52 -1
- package/README.md +72 -18
- package/dist/config.d.ts +7 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -11
- package/dist/config.js.map +1 -1
- package/dist/cost.d.ts +30 -13
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +58 -19
- package/dist/cost.js.map +1 -1
- package/dist/deepseek-client.d.ts +8 -0
- package/dist/deepseek-client.d.ts.map +1 -1
- package/dist/deepseek-client.js +90 -48
- package/dist/deepseek-client.js.map +1 -1
- package/dist/errors.d.ts +71 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +74 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -614
- package/dist/index.js.map +1 -1
- package/dist/prompts/advanced.d.ts +8 -0
- package/dist/prompts/advanced.d.ts.map +1 -0
- package/dist/prompts/advanced.js +187 -0
- package/dist/prompts/advanced.js.map +1 -0
- package/dist/prompts/core.d.ts +8 -0
- package/dist/prompts/core.d.ts.map +1 -0
- package/dist/prompts/core.js +188 -0
- package/dist/prompts/core.js.map +1 -0
- package/dist/prompts/function-calling.d.ts +7 -0
- package/dist/prompts/function-calling.d.ts.map +1 -0
- package/dist/prompts/function-calling.js +87 -0
- package/dist/prompts/function-calling.js.map +1 -0
- package/dist/prompts/index.d.ts +7 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +13 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/schemas.d.ts +59 -20
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +9 -2
- package/dist/schemas.js.map +1 -1
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +16 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/deepseek-chat.d.ts +8 -0
- package/dist/tools/deepseek-chat.d.ts.map +1 -0
- package/dist/tools/deepseek-chat.js +184 -0
- package/dist/tools/deepseek-chat.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +20 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
16
16
|
### Fixed
|
|
17
17
|
- Nothing yet
|
|
18
18
|
|
|
19
|
+
## [1.2.0] - 2026-02-26
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- **Thinking Mode**: Enable enhanced reasoning on deepseek-chat with `thinking: {type: "enabled"}` parameter. Automatically filters incompatible params (temperature, top_p, etc.) with logged warnings.
|
|
23
|
+
- **JSON Output Mode**: Structured JSON responses with `json_mode: true`. Supported by both models. Warns if "json" word missing from prompt.
|
|
24
|
+
- **Cache-Aware Cost Tracking**: V3.2 API returns `prompt_cache_hit_tokens` and `prompt_cache_miss_tokens`. Cost display now shows cache hit ratio and savings.
|
|
25
|
+
- **CostBreakdown Interface**: `calculateCost()` returns structured `{inputCost, outputCost, totalCost, cacheHitRatio?, cacheSavings?}` instead of flat number.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- **DeepSeek V3.2 Pricing**: Unified pricing for both models — cache hit $0.028/1M, cache miss $0.28/1M, output $0.42/1M (replaces old per-model pricing).
|
|
29
|
+
- **max_tokens Limit**: Updated from 32768 to 65536 (reasoner max). Model-specific warnings: deepseek-chat warns above 8192, deepseek-reasoner warns above 65536.
|
|
30
|
+
- **Tool Description**: Updated to mention V3.2, thinking mode, JSON mode, and cache-aware cost tracking.
|
|
31
|
+
- **150 Tests**: Up from 126, covering thinking mode, JSON mode, cache tokens, and cost breakdown.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
- **Incorrect Cost Reports**: Old flat pricing ($0.14/$0.28 chat, $0.55/$2.19 reasoner) replaced with accurate V3.2 unified pricing.
|
|
35
|
+
|
|
36
|
+
## [1.1.1] - 2026-02-11
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
- **Custom Error Classes** (`src/errors.ts`): `BaseError`, `ConfigError`, `ApiError`, `RateLimitError`, `AuthenticationError`, `ValidationError`, `ConnectionError` with error cause chaining
|
|
40
|
+
- **DeepSeek Type Extensions** (`src/types.ts`): `DeepSeekRawResponse`, `DeepSeekStreamChunk`, `DeepSeekStreamDelta` types and `hasReasoningContent()`, `getErrorMessage()` type guards
|
|
41
|
+
- **Message Content Length Limit**: `MAX_MESSAGE_LENGTH` config (default: 100K chars) prevents excessive API costs
|
|
42
|
+
- **Optional Connection Test**: `SKIP_CONNECTION_TEST=true` env skips startup API call for faster boot
|
|
43
|
+
- **AI Discoverability**: `llms.txt` and `llms-full.txt` for LLM/AI agent consumption
|
|
44
|
+
- **New Tests**: 126 tests (up from 85) covering errors, server factory, tool handlers, prompt registration
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
- **Modular Architecture**: Monolithic `index.ts` (783 lines) split into focused modules:
|
|
48
|
+
- `src/server.ts`: McpServer factory with auto-version from package.json
|
|
49
|
+
- `src/tools/deepseek-chat.ts`: Tool handler (extracted from index.ts)
|
|
50
|
+
- `src/tools/index.ts`: Tool registration aggregator
|
|
51
|
+
- `src/prompts/core.ts`: 5 core reasoning prompts
|
|
52
|
+
- `src/prompts/advanced.ts`: 5 advanced prompts
|
|
53
|
+
- `src/prompts/function-calling.ts`: 2 function calling prompts
|
|
54
|
+
- `src/prompts/index.ts`: Prompt registration aggregator
|
|
55
|
+
- `src/index.ts`: Slim bootstrap (~80 lines)
|
|
56
|
+
- **DRY Refactoring** (`deepseek-client.ts`): Extracted `buildRequestParams()` and `wrapError()` methods (eliminated code duplication)
|
|
57
|
+
- **Type Safety**: Replaced 16 `any` casts with proper DeepSeek type extensions and type guards (`error: unknown` pattern)
|
|
58
|
+
- **Config**: `process.exit(1)` replaced with `throw ConfigError` for testability
|
|
59
|
+
- **Version**: Single source of truth from `package.json` via `createRequire` (no more manual sync)
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
- **Security**: Updated `@modelcontextprotocol/sdk` to fix cross-client data leak (GHSA-345p-7cg4-v4c7)
|
|
63
|
+
- **Security**: Fixed `hono` transitive dependency vulnerabilities (XSS, cache deception, IP spoofing)
|
|
64
|
+
- CI dist check updated for new file structure
|
|
65
|
+
|
|
19
66
|
## [1.1.0] - 2026-02-10
|
|
20
67
|
|
|
21
68
|
### Added
|
|
@@ -124,6 +171,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
124
171
|
|
|
125
172
|
## Version History
|
|
126
173
|
|
|
174
|
+
- **1.2.0** (2026-02-26): DeepSeek V3.2 support — thinking mode, JSON mode, cache-aware pricing, 150 tests
|
|
175
|
+
- **1.1.1** (2026-02-11): Modular architecture, type safety, security fixes, 126 tests
|
|
127
176
|
- **1.1.0** (2026-02-10): Function calling, config system, test suite
|
|
128
177
|
- **1.0.3** (2025-02-07): Cost tracking and prompt templates
|
|
129
178
|
- **1.0.0** (2025-01-13): Initial public release
|
|
@@ -135,7 +184,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
135
184
|
- [GitHub repository](https://github.com/arikusi/deepseek-mcp-server)
|
|
136
185
|
- [Issue tracker](https://github.com/arikusi/deepseek-mcp-server/issues)
|
|
137
186
|
|
|
138
|
-
[Unreleased]: https://github.com/arikusi/deepseek-mcp-server/compare/v1.
|
|
187
|
+
[Unreleased]: https://github.com/arikusi/deepseek-mcp-server/compare/v1.2.0...HEAD
|
|
188
|
+
[1.2.0]: https://github.com/arikusi/deepseek-mcp-server/compare/v1.1.1...v1.2.0
|
|
189
|
+
[1.1.1]: https://github.com/arikusi/deepseek-mcp-server/compare/v1.1.0...v1.1.1
|
|
139
190
|
[1.1.0]: https://github.com/arikusi/deepseek-mcp-server/compare/v1.0.3...v1.1.0
|
|
140
191
|
[1.0.3]: https://github.com/arikusi/deepseek-mcp-server/releases/tag/v1.0.3
|
|
141
192
|
[1.0.0]: https://github.com/arikusi/deepseek-mcp-server/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -48,14 +48,15 @@ That's it! Your MCP client can now use DeepSeek models!
|
|
|
48
48
|
|
|
49
49
|
## Features
|
|
50
50
|
|
|
51
|
-
- **DeepSeek
|
|
52
|
-
- **
|
|
51
|
+
- **DeepSeek V3.2**: Both models now run DeepSeek-V3.2 (since Sept 2025)
|
|
52
|
+
- **Thinking Mode**: Enable enhanced reasoning on deepseek-chat with `thinking: {type: "enabled"}`
|
|
53
|
+
- **JSON Output Mode**: Structured JSON responses with `json_mode: true`
|
|
53
54
|
- **Function Calling**: OpenAI-compatible tool use with up to 128 tool definitions
|
|
54
|
-
- **Cost Tracking**: Automatic cost calculation
|
|
55
|
+
- **Cache-Aware Cost Tracking**: Automatic cost calculation with cache hit/miss breakdown
|
|
55
56
|
- **Configurable**: Environment-based configuration with validation
|
|
56
57
|
- **12 Prompt Templates**: Pre-built templates for debugging, code review, function calling, and more
|
|
57
58
|
- **Streaming Support**: Real-time response generation
|
|
58
|
-
- **Tested**:
|
|
59
|
+
- **Tested**: 150 tests with 90%+ code coverage
|
|
59
60
|
- **Type-Safe**: Full TypeScript implementation
|
|
60
61
|
- **MCP Compatible**: Works with any MCP-compatible CLI (Claude Code, Gemini CLI, etc.)
|
|
61
62
|
|
|
@@ -142,11 +143,13 @@ Chat with DeepSeek AI models with automatic cost tracking and function calling s
|
|
|
142
143
|
- `content`: Message text
|
|
143
144
|
- `tool_call_id` (optional): Required for tool role messages
|
|
144
145
|
- `model` (optional): "deepseek-chat" (default) or "deepseek-reasoner"
|
|
145
|
-
- `temperature` (optional): 0-2, controls randomness (default: 1.0)
|
|
146
|
-
- `max_tokens` (optional): Maximum tokens to generate
|
|
146
|
+
- `temperature` (optional): 0-2, controls randomness (default: 1.0). Ignored when thinking mode is enabled.
|
|
147
|
+
- `max_tokens` (optional): Maximum tokens to generate (deepseek-chat: max 8192, deepseek-reasoner: max 65536)
|
|
147
148
|
- `stream` (optional): Enable streaming mode (default: false)
|
|
148
149
|
- `tools` (optional): Array of tool definitions for function calling (max 128)
|
|
149
150
|
- `tool_choice` (optional): "auto" | "none" | "required" | `{type: "function", function: {name: "..."}}`
|
|
151
|
+
- `thinking` (optional): Enable thinking mode `{type: "enabled"}` for enhanced reasoning
|
|
152
|
+
- `json_mode` (optional): Enable JSON output mode (supported by both models)
|
|
150
153
|
|
|
151
154
|
**Response includes:**
|
|
152
155
|
- Content with formatting
|
|
@@ -221,6 +224,40 @@ The reasoner model will show its thinking process in `<thinking>` tags followed
|
|
|
221
224
|
|
|
222
225
|
When the model decides to call a function, the response includes `tool_calls` with the function name and arguments. You can then send the result back using a `tool` role message with the matching `tool_call_id`.
|
|
223
226
|
|
|
227
|
+
**Thinking Mode Example:**
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"messages": [
|
|
232
|
+
{
|
|
233
|
+
"role": "user",
|
|
234
|
+
"content": "Analyze the time complexity of quicksort"
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
"model": "deepseek-chat",
|
|
238
|
+
"thinking": { "type": "enabled" }
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
When thinking mode is enabled, `temperature`, `top_p`, `frequency_penalty`, and `presence_penalty` are automatically ignored. The model provides enhanced reasoning capabilities similar to deepseek-reasoner.
|
|
243
|
+
|
|
244
|
+
**JSON Output Mode Example:**
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"messages": [
|
|
249
|
+
{
|
|
250
|
+
"role": "user",
|
|
251
|
+
"content": "Return a json object with name, age, and city fields for a sample user"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"model": "deepseek-chat",
|
|
255
|
+
"json_mode": true
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
JSON mode ensures the model outputs valid JSON. Include the word "json" in your prompt for best results. Supported by both `deepseek-chat` and `deepseek-reasoner`.
|
|
260
|
+
|
|
224
261
|
## Available Prompts
|
|
225
262
|
|
|
226
263
|
Pre-built prompt templates for common tasks (12 total):
|
|
@@ -247,20 +284,28 @@ Each prompt is optimized for the DeepSeek Reasoner model to provide detailed rea
|
|
|
247
284
|
|
|
248
285
|
## Models
|
|
249
286
|
|
|
287
|
+
Both models run **DeepSeek-V3.2** with unified pricing.
|
|
288
|
+
|
|
250
289
|
### deepseek-chat
|
|
251
290
|
|
|
252
291
|
- **Best for**: General conversations, coding, content generation
|
|
253
292
|
- **Speed**: Fast
|
|
254
|
-
- **Context**:
|
|
255
|
-
- **
|
|
293
|
+
- **Context**: 128K tokens
|
|
294
|
+
- **Max Output**: 8K tokens (default 4K)
|
|
295
|
+
- **Mode**: Non-thinking (can enable thinking via parameter)
|
|
296
|
+
- **Features**: Thinking mode, JSON mode, function calling, FIM completion
|
|
297
|
+
- **Pricing**: $0.028/1M cache hit, $0.28/1M cache miss, $0.42/1M output
|
|
256
298
|
|
|
257
|
-
### deepseek-reasoner
|
|
299
|
+
### deepseek-reasoner
|
|
258
300
|
|
|
259
301
|
- **Best for**: Complex reasoning, math, logic problems, multi-step tasks
|
|
260
302
|
- **Speed**: Slower (shows thinking process)
|
|
261
|
-
- **Context**:
|
|
262
|
-
- **
|
|
303
|
+
- **Context**: 128K tokens
|
|
304
|
+
- **Max Output**: 64K tokens (default 32K)
|
|
305
|
+
- **Mode**: Thinking (always active, chain-of-thought reasoning)
|
|
306
|
+
- **Features**: JSON mode, function calling
|
|
263
307
|
- **Output**: Both reasoning process and final answer
|
|
308
|
+
- **Pricing**: $0.028/1M cache hit, $0.28/1M cache miss, $0.42/1M output
|
|
264
309
|
|
|
265
310
|
## Configuration
|
|
266
311
|
|
|
@@ -273,6 +318,8 @@ The server is configured via environment variables. All settings except `DEEPSEE
|
|
|
273
318
|
| `SHOW_COST_INFO` | `true` | Show cost info in responses |
|
|
274
319
|
| `REQUEST_TIMEOUT` | `60000` | Request timeout in milliseconds |
|
|
275
320
|
| `MAX_RETRIES` | `2` | Maximum retry count for failed requests |
|
|
321
|
+
| `SKIP_CONNECTION_TEST` | `false` | Skip startup API connection test |
|
|
322
|
+
| `MAX_MESSAGE_LENGTH` | `100000` | Maximum message content length (characters) |
|
|
276
323
|
|
|
277
324
|
**Example with custom config:**
|
|
278
325
|
```bash
|
|
@@ -289,18 +336,25 @@ claude mcp add -s user deepseek npx @arikusi/deepseek-mcp-server \
|
|
|
289
336
|
```
|
|
290
337
|
deepseek-mcp-server/
|
|
291
338
|
├── src/
|
|
292
|
-
│ ├── index.ts #
|
|
339
|
+
│ ├── index.ts # Entry point, bootstrap (~80 lines)
|
|
340
|
+
│ ├── server.ts # McpServer factory (auto-version)
|
|
293
341
|
│ ├── deepseek-client.ts # DeepSeek API wrapper (OpenAI SDK)
|
|
294
342
|
│ ├── config.ts # Centralized config with Zod validation
|
|
295
343
|
│ ├── cost.ts # Cost calculation and formatting
|
|
296
344
|
│ ├── schemas.ts # Zod input validation schemas
|
|
297
|
-
│ ├── types.ts # TypeScript type
|
|
298
|
-
│ ├──
|
|
299
|
-
│ ├──
|
|
300
|
-
│ ├──
|
|
301
|
-
│
|
|
302
|
-
│ └──
|
|
345
|
+
│ ├── types.ts # TypeScript types + type guards
|
|
346
|
+
│ ├── errors.ts # Custom error classes
|
|
347
|
+
│ ├── tools/
|
|
348
|
+
│ │ ├── deepseek-chat.ts # deepseek_chat tool handler
|
|
349
|
+
│ │ └── index.ts # Tool registration aggregator
|
|
350
|
+
│ └── prompts/
|
|
351
|
+
│ ├── core.ts # 5 core reasoning prompts
|
|
352
|
+
│ ├── advanced.ts # 5 advanced prompts
|
|
353
|
+
│ ├── function-calling.ts # 2 function calling prompts
|
|
354
|
+
│ └── index.ts # Prompt registration aggregator
|
|
303
355
|
├── dist/ # Compiled JavaScript
|
|
356
|
+
├── llms.txt # AI discoverability index
|
|
357
|
+
├── llms-full.txt # Full docs for LLM context
|
|
304
358
|
├── vitest.config.ts # Test configuration
|
|
305
359
|
├── package.json
|
|
306
360
|
├── tsconfig.json
|
package/dist/config.d.ts
CHANGED
|
@@ -9,24 +9,30 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
9
9
|
showCostInfo: z.ZodDefault<z.ZodBoolean>;
|
|
10
10
|
requestTimeout: z.ZodDefault<z.ZodNumber>;
|
|
11
11
|
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
skipConnectionTest: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
+
maxMessageLength: z.ZodDefault<z.ZodNumber>;
|
|
12
14
|
}, "strip", z.ZodTypeAny, {
|
|
13
15
|
apiKey: string;
|
|
14
16
|
baseUrl: string;
|
|
15
17
|
showCostInfo: boolean;
|
|
16
18
|
requestTimeout: number;
|
|
17
19
|
maxRetries: number;
|
|
20
|
+
skipConnectionTest: boolean;
|
|
21
|
+
maxMessageLength: number;
|
|
18
22
|
}, {
|
|
19
23
|
apiKey: string;
|
|
20
24
|
baseUrl?: string | undefined;
|
|
21
25
|
showCostInfo?: boolean | undefined;
|
|
22
26
|
requestTimeout?: number | undefined;
|
|
23
27
|
maxRetries?: number | undefined;
|
|
28
|
+
skipConnectionTest?: boolean | undefined;
|
|
29
|
+
maxMessageLength?: number | undefined;
|
|
24
30
|
}>;
|
|
25
31
|
export type Config = z.infer<typeof ConfigSchema>;
|
|
26
32
|
/**
|
|
27
33
|
* Load configuration from environment variables.
|
|
28
34
|
* Validates with Zod and caches the result.
|
|
29
|
-
*
|
|
35
|
+
* Throws ConfigError if validation fails.
|
|
30
36
|
*/
|
|
31
37
|
export declare function loadConfig(): Config;
|
|
32
38
|
/**
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;EAQhB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAIlD;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAqCnC;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAKlC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
package/dist/config.js
CHANGED
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
* Loads and validates configuration from environment variables
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import { ConfigError } from './errors.js';
|
|
6
7
|
const ConfigSchema = z.object({
|
|
7
8
|
apiKey: z.string().min(1, 'DEEPSEEK_API_KEY is required'),
|
|
8
9
|
baseUrl: z.string().url().default('https://api.deepseek.com'),
|
|
9
10
|
showCostInfo: z.boolean().default(true),
|
|
10
11
|
requestTimeout: z.number().positive().default(60000),
|
|
11
12
|
maxRetries: z.number().min(0).max(10).default(2),
|
|
13
|
+
skipConnectionTest: z.boolean().default(false),
|
|
14
|
+
maxMessageLength: z.number().positive().default(100_000),
|
|
12
15
|
});
|
|
13
16
|
let cachedConfig = null;
|
|
14
17
|
/**
|
|
15
18
|
* Load configuration from environment variables.
|
|
16
19
|
* Validates with Zod and caches the result.
|
|
17
|
-
*
|
|
20
|
+
* Throws ConfigError if validation fails.
|
|
18
21
|
*/
|
|
19
22
|
export function loadConfig() {
|
|
20
23
|
const raw = {
|
|
@@ -27,19 +30,21 @@ export function loadConfig() {
|
|
|
27
30
|
maxRetries: process.env.MAX_RETRIES
|
|
28
31
|
? parseInt(process.env.MAX_RETRIES, 10)
|
|
29
32
|
: 2,
|
|
33
|
+
skipConnectionTest: process.env.SKIP_CONNECTION_TEST === 'true',
|
|
34
|
+
maxMessageLength: process.env.MAX_MESSAGE_LENGTH
|
|
35
|
+
? parseInt(process.env.MAX_MESSAGE_LENGTH, 10)
|
|
36
|
+
: 100_000,
|
|
30
37
|
};
|
|
31
38
|
const result = ConfigSchema.safeParse(raw);
|
|
32
39
|
if (!result.success) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
process.exit(1);
|
|
40
|
+
const issues = result.error.issues.map((issue) => ({
|
|
41
|
+
path: issue.path.join('.'),
|
|
42
|
+
message: issue.message,
|
|
43
|
+
}));
|
|
44
|
+
const hint = !raw.apiKey
|
|
45
|
+
? '\nPlease set your DeepSeek API key:\n export DEEPSEEK_API_KEY="your-api-key-here"'
|
|
46
|
+
: '';
|
|
47
|
+
throw new ConfigError(`Configuration validation failed${hint}`, issues);
|
|
43
48
|
}
|
|
44
49
|
cachedConfig = result.data;
|
|
45
50
|
return cachedConfig;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WA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GED
|
@@ -1,24 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cost Calculation Module
|
|
3
3
|
* Handles pricing and cost formatting for DeepSeek API requests
|
|
4
|
+
*
|
|
5
|
+
* DeepSeek V3.2 unified pricing (both deepseek-chat and deepseek-reasoner):
|
|
6
|
+
* - Cache hit input: $0.028/1M tokens
|
|
7
|
+
* - Cache miss input: $0.28/1M tokens
|
|
8
|
+
* - Output: $0.42/1M tokens
|
|
4
9
|
*/
|
|
5
|
-
/** DeepSeek pricing per 1M tokens (USD) */
|
|
10
|
+
/** DeepSeek V3.2 unified pricing per 1M tokens (USD) */
|
|
6
11
|
export declare const PRICING: {
|
|
7
|
-
readonly
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
readonly 'deepseek-reasoner': {
|
|
12
|
-
readonly prompt: 0.55;
|
|
13
|
-
readonly completion: 2.19;
|
|
14
|
-
};
|
|
12
|
+
readonly cache_hit: 0.028;
|
|
13
|
+
readonly cache_miss: 0.28;
|
|
14
|
+
readonly output: 0.42;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Cost breakdown for a request
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export interface CostBreakdown {
|
|
20
|
+
inputCost: number;
|
|
21
|
+
outputCost: number;
|
|
22
|
+
totalCost: number;
|
|
23
|
+
cacheHitRatio?: number;
|
|
24
|
+
cacheSavings?: number;
|
|
25
|
+
}
|
|
20
26
|
/**
|
|
21
|
-
*
|
|
27
|
+
* Calculate cost for a request based on token usage.
|
|
28
|
+
* Supports V3.2 cache hit/miss pricing. If cache fields are absent,
|
|
29
|
+
* treats all input tokens as cache miss (backward compatible).
|
|
22
30
|
*/
|
|
23
|
-
export declare function
|
|
31
|
+
export declare function calculateCost(usage: {
|
|
32
|
+
prompt_tokens: number;
|
|
33
|
+
completion_tokens: number;
|
|
34
|
+
prompt_cache_hit_tokens?: number;
|
|
35
|
+
prompt_cache_miss_tokens?: number;
|
|
36
|
+
}): CostBreakdown;
|
|
37
|
+
/**
|
|
38
|
+
* Format cost as readable USD string with optional cache savings info
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatCost(breakdown: CostBreakdown): string;
|
|
24
41
|
//# sourceMappingURL=cost.d.ts.map
|
package/dist/cost.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wDAAwD;AACxD,eAAO,MAAM,OAAO;;;;CAIV,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC,GAAG,aAAa,CA4ChB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM,CAqB3D"}
|
package/dist/cost.js
CHANGED
|
@@ -1,34 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cost Calculation Module
|
|
3
3
|
* Handles pricing and cost formatting for DeepSeek API requests
|
|
4
|
+
*
|
|
5
|
+
* DeepSeek V3.2 unified pricing (both deepseek-chat and deepseek-reasoner):
|
|
6
|
+
* - Cache hit input: $0.028/1M tokens
|
|
7
|
+
* - Cache miss input: $0.28/1M tokens
|
|
8
|
+
* - Output: $0.42/1M tokens
|
|
4
9
|
*/
|
|
5
|
-
/** DeepSeek pricing per 1M tokens (USD) */
|
|
10
|
+
/** DeepSeek V3.2 unified pricing per 1M tokens (USD) */
|
|
6
11
|
export const PRICING = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
'deepseek-reasoner': {
|
|
12
|
-
prompt: 0.55,
|
|
13
|
-
completion: 2.19,
|
|
14
|
-
},
|
|
12
|
+
cache_hit: 0.028,
|
|
13
|
+
cache_miss: 0.28,
|
|
14
|
+
output: 0.42,
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* Calculate cost for a request based on token usage
|
|
17
|
+
* Calculate cost for a request based on token usage.
|
|
18
|
+
* Supports V3.2 cache hit/miss pricing. If cache fields are absent,
|
|
19
|
+
* treats all input tokens as cache miss (backward compatible).
|
|
18
20
|
*/
|
|
19
|
-
export function calculateCost(
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export function calculateCost(usage) {
|
|
22
|
+
const { prompt_tokens, completion_tokens, prompt_cache_hit_tokens, prompt_cache_miss_tokens, } = usage;
|
|
23
|
+
let inputCost;
|
|
24
|
+
let cacheHitRatio;
|
|
25
|
+
let cacheSavings;
|
|
26
|
+
if (prompt_cache_hit_tokens !== undefined &&
|
|
27
|
+
prompt_cache_miss_tokens !== undefined) {
|
|
28
|
+
// V3.2 cache-aware pricing
|
|
29
|
+
const hitCost = (prompt_cache_hit_tokens / 1_000_000) * PRICING.cache_hit;
|
|
30
|
+
const missCost = (prompt_cache_miss_tokens / 1_000_000) * PRICING.cache_miss;
|
|
31
|
+
inputCost = hitCost + missCost;
|
|
32
|
+
if (prompt_tokens > 0) {
|
|
33
|
+
cacheHitRatio = prompt_cache_hit_tokens / prompt_tokens;
|
|
34
|
+
}
|
|
35
|
+
// Savings = what all-miss would cost minus actual cost
|
|
36
|
+
const allMissCost = (prompt_tokens / 1_000_000) * PRICING.cache_miss;
|
|
37
|
+
cacheSavings = allMissCost - inputCost;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Backward compatible: treat all input as cache miss
|
|
41
|
+
inputCost = (prompt_tokens / 1_000_000) * PRICING.cache_miss;
|
|
42
|
+
}
|
|
43
|
+
const outputCost = (completion_tokens / 1_000_000) * PRICING.output;
|
|
44
|
+
return {
|
|
45
|
+
inputCost,
|
|
46
|
+
outputCost,
|
|
47
|
+
totalCost: inputCost + outputCost,
|
|
48
|
+
cacheHitRatio,
|
|
49
|
+
cacheSavings,
|
|
50
|
+
};
|
|
24
51
|
}
|
|
25
52
|
/**
|
|
26
|
-
* Format cost as readable USD string
|
|
53
|
+
* Format cost as readable USD string with optional cache savings info
|
|
27
54
|
*/
|
|
28
|
-
export function formatCost(
|
|
55
|
+
export function formatCost(breakdown) {
|
|
56
|
+
const cost = breakdown.totalCost;
|
|
57
|
+
let formatted;
|
|
29
58
|
if (cost < 0.01) {
|
|
30
|
-
|
|
59
|
+
formatted = `$${cost.toFixed(4)}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
formatted = `$${cost.toFixed(2)}`;
|
|
63
|
+
}
|
|
64
|
+
if (breakdown.cacheHitRatio !== undefined &&
|
|
65
|
+
breakdown.cacheHitRatio > 0 &&
|
|
66
|
+
breakdown.cacheSavings !== undefined &&
|
|
67
|
+
breakdown.cacheSavings > 0) {
|
|
68
|
+
const pct = Math.round(breakdown.cacheHitRatio * 100);
|
|
69
|
+
formatted += ` (cache hit: ${pct}%, saved ~$${breakdown.cacheSavings.toFixed(4)})`;
|
|
31
70
|
}
|
|
32
|
-
return
|
|
71
|
+
return formatted;
|
|
33
72
|
}
|
|
34
73
|
//# sourceMappingURL=cost.js.map
|
package/dist/cost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost.js","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAAA
|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U;QACV,SAAS,EAAE,SAAS,GAAG,UAAU;QACjC,aAAa;QACb,YAAY;KACb,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,SAAwB;IACjD,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,CAAC;IACjC,IAAI,SAAiB,CAAC;IAEtB,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;QAChB,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC;IAED,IACE,SAAS,CAAC,aAAa,KAAK,SAAS;QACrC,SAAS,CAAC,aAAa,GAAG,CAAC;QAC3B,SAAS,CAAC,YAAY,KAAK,SAAS;QACpC,SAAS,CAAC,YAAY,GAAG,CAAC,EAC1B,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,GAAG,CAAC,CAAC;QACtD,SAAS,IAAI,gBAAgB,GAAG,cAAc,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACrF,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -6,6 +6,14 @@ import type { ChatCompletionParams, ChatCompletionResponse } from './types.js';
|
|
|
6
6
|
export declare class DeepSeekClient {
|
|
7
7
|
private client;
|
|
8
8
|
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Build request params shared between streaming and non-streaming
|
|
11
|
+
*/
|
|
12
|
+
private buildRequestParams;
|
|
13
|
+
/**
|
|
14
|
+
* Wrap caught errors with appropriate custom error class
|
|
15
|
+
*/
|
|
16
|
+
private wrapError;
|
|
9
17
|
/**
|
|
10
18
|
* Create a chat completion (non-streaming)
|
|
11
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepseek-client.d.ts","sourceRoot":"","sources":["../src/deepseek-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"deepseek-client.d.ts","sourceRoot":"","sources":["../src/deepseek-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EAKvB,MAAM,YAAY,CAAC;AAWpB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAS;;IAavB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAyD1B;;OAEG;IACH,OAAO,CAAC,SAAS;IAOjB;;OAEG;IACG,oBAAoB,CACxB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,sBAAsB,CAAC;IA+ClC;;;OAGG;IACG,6BAA6B,CACjC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,sBAAsB,CAAC;IA0GlC;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAazC"}
|