dskcode 0.1.10 → 0.1.12
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/dist/chunk-DIZMSV5H.js +85 -0
- package/dist/chunk-DIZMSV5H.js.map +1 -0
- package/dist/chunk-FODNQIT4.js +626 -0
- package/dist/chunk-FODNQIT4.js.map +1 -0
- package/dist/deepseek-OIJOG3N5.js +8 -0
- package/dist/deepseek-OIJOG3N5.js.map +1 -0
- package/dist/index.js +1484 -181
- package/dist/index.js.map +1 -1
- package/dist/models-NQGNKB4T.js +19 -0
- package/dist/models-NQGNKB4T.js.map +1 -0
- package/package.json +1 -1
- package/dist/deepseek-7Y2G6EKM.js +0 -385
- package/dist/deepseek-7Y2G6EKM.js.map +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/provider/models.ts
|
|
2
|
+
var SUPPORTED_MODELS = {
|
|
3
|
+
"deepseek-v4-flash": {
|
|
4
|
+
id: "deepseek-v4-flash",
|
|
5
|
+
displayName: "DeepSeek V4 Flash",
|
|
6
|
+
/** 上下文窗口大小(token) */
|
|
7
|
+
contextWindow: 1e6,
|
|
8
|
+
/** 输入价格(元 / 百万 token,缓存未命中) */
|
|
9
|
+
inputPricePerMillion: 1,
|
|
10
|
+
/** 输出价格(元 / 百万 token) */
|
|
11
|
+
outputPricePerMillion: 2,
|
|
12
|
+
/** 输入价格(元 / 百万 token,缓存命中) */
|
|
13
|
+
cacheHitPricePerMillion: 0.02
|
|
14
|
+
},
|
|
15
|
+
"deepseek-v4-pro": {
|
|
16
|
+
id: "deepseek-v4-pro",
|
|
17
|
+
displayName: "DeepSeek V4 Pro",
|
|
18
|
+
/** 上下文窗口大小(token) */
|
|
19
|
+
contextWindow: 1e6,
|
|
20
|
+
/** 输入价格(元 / 百万 token,缓存未命中) */
|
|
21
|
+
inputPricePerMillion: 3,
|
|
22
|
+
/** 输出价格(元 / 百万 token) */
|
|
23
|
+
outputPricePerMillion: 6,
|
|
24
|
+
/** 输入价格(元 / 百万 token,缓存命中) */
|
|
25
|
+
cacheHitPricePerMillion: 0.025
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var SUPPORTED_MODEL_IDS = Object.keys(SUPPORTED_MODELS);
|
|
29
|
+
function isSupportedModel(model) {
|
|
30
|
+
return model in SUPPORTED_MODELS;
|
|
31
|
+
}
|
|
32
|
+
function getModelMeta(model) {
|
|
33
|
+
return SUPPORTED_MODELS[model];
|
|
34
|
+
}
|
|
35
|
+
function isCJK(char) {
|
|
36
|
+
const code = char.codePointAt(0);
|
|
37
|
+
return code >= 19968 && code <= 40959 || // CJK 扩展 A
|
|
38
|
+
code >= 13312 && code <= 19903 || // CJK 扩展 B 及其他
|
|
39
|
+
code >= 131072 && code <= 173791 || // CJK 兼容汉字
|
|
40
|
+
code >= 63744 && code <= 64255 || // 全角字符
|
|
41
|
+
code >= 65281 && code <= 65376;
|
|
42
|
+
}
|
|
43
|
+
function estimateTokens(text) {
|
|
44
|
+
let cjkCount = 0;
|
|
45
|
+
let otherCount = 0;
|
|
46
|
+
for (const char of text) {
|
|
47
|
+
if (isCJK(char)) {
|
|
48
|
+
cjkCount++;
|
|
49
|
+
} else {
|
|
50
|
+
otherCount++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const tokens = cjkCount * 0.6 + otherCount * 0.3;
|
|
54
|
+
return Math.max(1, Math.ceil(tokens));
|
|
55
|
+
}
|
|
56
|
+
function calculateCost(usage, model) {
|
|
57
|
+
const meta = SUPPORTED_MODELS[model];
|
|
58
|
+
const cached = usage.cachedPromptTokens ?? 0;
|
|
59
|
+
const nonCached = usage.promptTokens - cached;
|
|
60
|
+
const inputCost = nonCached * meta.inputPricePerMillion / 1e6;
|
|
61
|
+
const cacheHitCost = cached * meta.cacheHitPricePerMillion / 1e6;
|
|
62
|
+
const outputCost = usage.completionTokens * meta.outputPricePerMillion / 1e6;
|
|
63
|
+
return {
|
|
64
|
+
inputCost,
|
|
65
|
+
cacheHitCost,
|
|
66
|
+
outputCost,
|
|
67
|
+
totalCost: inputCost + cacheHitCost + outputCost
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function formatCost(cost) {
|
|
71
|
+
const total = cost.totalCost;
|
|
72
|
+
const formatted = total < 0.01 ? total.toFixed(6) : total.toFixed(4);
|
|
73
|
+
return `\u2248\xA5${formatted}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
SUPPORTED_MODELS,
|
|
78
|
+
SUPPORTED_MODEL_IDS,
|
|
79
|
+
isSupportedModel,
|
|
80
|
+
getModelMeta,
|
|
81
|
+
estimateTokens,
|
|
82
|
+
calculateCost,
|
|
83
|
+
formatCost
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=chunk-DIZMSV5H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider/models.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\r\n// 模型定义与校验\r\n// ---------------------------------------------------------------------------\r\n\r\nimport type { ModelId, ModelMeta } from \"./types.js\";\r\n\r\n/** 支持的模型及其元数据 */\r\nexport const SUPPORTED_MODELS: Record<ModelId, ModelMeta> = {\r\n \"deepseek-v4-flash\": {\r\n id: \"deepseek-v4-flash\",\r\n displayName: \"DeepSeek V4 Flash\",\r\n /** 上下文窗口大小(token) */\r\n contextWindow: 1_000_000,\r\n /** 输入价格(元 / 百万 token,缓存未命中) */\r\n inputPricePerMillion: 1,\r\n /** 输出价格(元 / 百万 token) */\r\n outputPricePerMillion: 2,\r\n /** 输入价格(元 / 百万 token,缓存命中) */\r\n cacheHitPricePerMillion: 0.02,\r\n },\r\n \"deepseek-v4-pro\": {\r\n id: \"deepseek-v4-pro\",\r\n displayName: \"DeepSeek V4 Pro\",\r\n /** 上下文窗口大小(token) */\r\n contextWindow: 1_000_000,\r\n /** 输入价格(元 / 百万 token,缓存未命中) */\r\n inputPricePerMillion: 3,\r\n /** 输出价格(元 / 百万 token) */\r\n outputPricePerMillion: 6,\r\n /** 输入价格(元 / 百万 token,缓存命中) */\r\n cacheHitPricePerMillion: 0.025,\r\n },\r\n};\r\n\r\n/** 支持的模型 ID 列表 */\r\nexport const SUPPORTED_MODEL_IDS: string[] = Object.keys(SUPPORTED_MODELS);\r\n\r\n/**\r\n * 判断模型标识是否受支持。\r\n * dskcode 仅支持 deepseek-v4-flash 和 deepseek-v4-pro 两个模型。\r\n */\r\nexport function isSupportedModel(model: string): model is ModelId {\r\n return model in SUPPORTED_MODELS;\r\n}\r\n\r\n/** 获取模型元数据(已校验) */\r\nexport function getModelMeta(model: ModelId): ModelMeta {\r\n return SUPPORTED_MODELS[model];\r\n}\r\n\r\n/**\r\n * CJK 字符 Unicode 范围检测。\r\n * 覆盖 CJK 统一汉字、扩展 A/B、兼容汉字等。\r\n */\r\nfunction isCJK(char: string): boolean {\r\n const code = char.codePointAt(0)!;\r\n // CJK 统一汉字\r\n return (\r\n (code >= 0x4e00 && code <= 0x9fff) ||\r\n // CJK 扩展 A\r\n (code >= 0x3400 && code <= 0x4dbf) ||\r\n // CJK 扩展 B 及其他\r\n (code >= 0x20000 && code <= 0x2a6df) ||\r\n // CJK 兼容汉字\r\n (code >= 0xf900 && code <= 0xfaff) ||\r\n // 全角字符\r\n (code >= 0xff01 && code <= 0xff60)\r\n );\r\n}\r\n\r\n/**\r\n * 估算文本的 token 数量。\r\n *\r\n * 根据 DeepSeek 官方文档的换算比例:\r\n * - 1 个英文字符 ≈ 0.3 个 token(即约 3.3 个字符 ≈ 1 token)\r\n * - 1 个中文字符 ≈ 0.6 个 token(即约 1.7 个字符 ≈ 1 token)\r\n *\r\n * 对文本中的 CJK 和非 CJK 字符分别估算后求和。\r\n */\r\nexport function estimateTokens(text: string): number {\r\n let cjkCount = 0;\r\n let otherCount = 0;\r\n for (const char of text) {\r\n if (isCJK(char)) {\r\n cjkCount++;\r\n } else {\r\n otherCount++;\r\n }\r\n }\r\n // CJK: 1 字符 ≈ 0.6 token → token 数 ≈ cjkCount × 0.6\r\n // 其他: 1 字符 ≈ 0.3 token → token 数 ≈ otherCount × 0.3\r\n const tokens = cjkCount * 0.6 + otherCount * 0.3;\r\n return Math.max(1, Math.ceil(tokens));\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// 费用计算\r\n// ---------------------------------------------------------------------------\r\n\r\nimport type { UsageInfo, CostInfo } from \"./types.js\";\r\n\r\n/**\r\n * 根据模型和 Token 使用量计算费用。\r\n *\r\n * 计费公式:\r\n * 输入费用(缓存未命中) = (promptTokens - cachedPromptTokens) × inputPrice / 1,000,000\r\n * 缓存命中费用 = cachedPromptTokens × cacheHitPrice / 1,000,000\r\n * 输出费用 = completionTokens × outputPrice / 1,000,000\r\n * 总费用 = 输入费用 + 缓存命中费用 + 输出费用\r\n *\r\n * @param usage Token 使用统计\r\n * @param model 模型标识\r\n * @returns 费用明细(单位:元)\r\n */\r\nexport function calculateCost(usage: UsageInfo, model: ModelId): CostInfo {\r\n const meta = SUPPORTED_MODELS[model];\r\n const cached = usage.cachedPromptTokens ?? 0;\r\n const nonCached = usage.promptTokens - cached;\r\n\r\n const inputCost = (nonCached * meta.inputPricePerMillion) / 1_000_000;\r\n const cacheHitCost = (cached * meta.cacheHitPricePerMillion) / 1_000_000;\r\n const outputCost = (usage.completionTokens * meta.outputPricePerMillion) / 1_000_000;\r\n\r\n return {\r\n inputCost,\r\n cacheHitCost,\r\n outputCost,\r\n totalCost: inputCost + cacheHitCost + outputCost,\r\n };\r\n}\r\n\r\n/**\r\n * 将费用格式化为易读的字符串,只展示合计费用。\r\n *\r\n * - 小于 0.01 元时显示到小数点后 6 位(如 ¥0.000032)\r\n * - 大于等于 0.01 元时显示到小数点后 4 位(如 ¥0.1234)\r\n */\r\nexport function formatCost(cost: CostInfo): string {\r\n const total = cost.totalCost;\r\n const formatted = total < 0.01 ? total.toFixed(6) : total.toFixed(4);\r\n return `≈¥${formatted}`;\r\n}"],"mappings":";AAOO,IAAM,mB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