@alexpeng/dsh-custom-plugin 0.1.3 → 0.1.4
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 +20 -0
- package/README.i18n.yaml +2 -2
- package/README.md +9 -6
- package/README.zh.md +9 -6
- package/lib/client.js +134 -55
- package/lib/client.js.map +1 -1
- package/lib/index.js +277 -105
- package/lib/types/client/api.d.ts +4 -2
- package/lib/types/host-service.d.ts +27 -13
- package/lib/types/pricing.d.ts +37 -0
- package/lib/types/protocol.d.ts +10 -3
- package/lib/types/system-credentials.d.ts +25 -0
- package/lib/types/usage.d.ts +8 -4
- package/package.json +16 -15
package/lib/types/protocol.d.ts
CHANGED
|
@@ -66,9 +66,9 @@ export interface UsageRow {
|
|
|
66
66
|
cacheW: number;
|
|
67
67
|
reason: number;
|
|
68
68
|
calls: number;
|
|
69
|
-
/** Peak-hour (Beijing 09-12 / 14-18) portion of each counter;
|
|
70
|
-
* off-peak. Optional because rows persisted
|
|
71
|
-
* predate these fields. */
|
|
69
|
+
/** Peak-hour (Beijing Monday-Friday 09-12 / 14-18) portion of each counter;
|
|
70
|
+
* the rest, including weekends, is off-peak. Optional because rows persisted
|
|
71
|
+
* before the peak/off-peak split predate these fields. */
|
|
72
72
|
peakIn?: number;
|
|
73
73
|
peakCacheIn?: number;
|
|
74
74
|
peakCacheW?: number;
|
|
@@ -76,6 +76,8 @@ export interface UsageRow {
|
|
|
76
76
|
}
|
|
77
77
|
/** Day -> model -> counters. */
|
|
78
78
|
export type UsageMap = Record<string, Record<string, UsageRow>>;
|
|
79
|
+
/** Where the balance API key was resolved from, without exposing its value. */
|
|
80
|
+
export type CredentialStorage = 'system' | 'legacy-state' | 'environment' | 'dsh' | 'none';
|
|
79
81
|
/** The complete persisted state file shape. */
|
|
80
82
|
export interface CustomPluginState {
|
|
81
83
|
cfg: CustomPluginConfig;
|
|
@@ -86,6 +88,11 @@ export interface CustomPluginState {
|
|
|
86
88
|
apiKey: string;
|
|
87
89
|
usage: UsageMap;
|
|
88
90
|
}
|
|
91
|
+
/** Browser-safe state projection; the API key itself never crosses this boundary. */
|
|
92
|
+
export type CustomPluginPublicState = Omit<CustomPluginState, 'apiKey'> & {
|
|
93
|
+
apiKeyConfigured: boolean;
|
|
94
|
+
credentialStorage: CredentialStorage;
|
|
95
|
+
};
|
|
89
96
|
/** One timeline node: one direct user message in a session. */
|
|
90
97
|
export interface TimelineItem {
|
|
91
98
|
seq: number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional OS credential-store adapter.
|
|
3
|
+
*
|
|
4
|
+
* `keytar` is optional so the plugin still works in minimal/headless
|
|
5
|
+
* installations. When present, it delegates storage to the platform keyring
|
|
6
|
+
* (Windows Credential Manager, macOS Keychain, or the Linux Secret Service
|
|
7
|
+
* backend exposed by keytar). The caller owns the legacy state-file fallback.
|
|
8
|
+
* @module @alexpeng/dsh-custom-plugin/system-credentials
|
|
9
|
+
*/
|
|
10
|
+
export declare const CREDENTIAL_SERVICE = "@alexpeng/dsh-custom-plugin";
|
|
11
|
+
export declare const CREDENTIAL_ACCOUNT = "deepseek-api-key";
|
|
12
|
+
export interface CredentialStore {
|
|
13
|
+
readonly available: boolean;
|
|
14
|
+
get(): Promise<string>;
|
|
15
|
+
set(value: string): Promise<boolean>;
|
|
16
|
+
clear(): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
/** Safe wrapper around the optional keytar dependency. */
|
|
19
|
+
export declare class SystemCredentialStore implements CredentialStore {
|
|
20
|
+
private readonly keytar;
|
|
21
|
+
get available(): boolean;
|
|
22
|
+
get(): Promise<string>;
|
|
23
|
+
set(value: string): Promise<boolean>;
|
|
24
|
+
clear(): Promise<boolean>;
|
|
25
|
+
}
|
package/lib/types/usage.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module @alexpeng/dsh-custom-plugin/usage
|
|
4
4
|
*/
|
|
5
5
|
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
6
|
-
import type { UsageRow } from './protocol.ts';
|
|
6
|
+
import type { UsageMap, UsageRow } from './protocol.ts';
|
|
7
7
|
/** One adapter-reported token accounting record (counters are disjoint). */
|
|
8
8
|
export interface UsageRecord {
|
|
9
9
|
inputTokens?: number;
|
|
@@ -12,12 +12,16 @@ export interface UsageRecord {
|
|
|
12
12
|
cacheWriteTokens?: number;
|
|
13
13
|
reasoningTokens?: number;
|
|
14
14
|
}
|
|
15
|
+
/** Number of Beijing calendar days retained in the local usage ledger. */
|
|
16
|
+
export declare const USAGE_RETENTION_DAYS = 90;
|
|
15
17
|
/** Beijing-time (UTC+8) day key `YYYY-MM-DD`. */
|
|
16
18
|
export declare function dayKey(time?: number): string;
|
|
17
|
-
/** DeepSeek peak billing window: Beijing 09:00-12:00 /
|
|
18
|
-
*
|
|
19
|
-
* matches the published schedule on any host timezone. */
|
|
19
|
+
/** DeepSeek peak billing window: Beijing Monday-Friday 09:00-12:00 /
|
|
20
|
+
* 14:00-18:00; all weekend hours are off-peak. Evaluated on China Standard
|
|
21
|
+
* Time so the split matches the published schedule on any host timezone. */
|
|
20
22
|
export declare function isPeakHour(time: number): boolean;
|
|
23
|
+
/** Remove malformed or expired day buckets from the persisted usage ledger. */
|
|
24
|
+
export declare function pruneUsage(usage: UsageMap, now?: number, retentionDays?: number): number;
|
|
21
25
|
/** Fold one usage record into a ledger row, tracking the peak-hour portion. */
|
|
22
26
|
export declare function foldUsageRecord(row: UsageRow, usage: UsageRecord, peak: boolean): void;
|
|
23
27
|
/** Merge one aggregated row into a target row (scan folds per-session rows). */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexpeng/dsh-custom-plugin",
|
|
3
3
|
"description": "Custom convenience suite for the dsh web GUI: background colors with weather FX, liquid glass, a per-user-message timeline rail with stars and branching, multi-level project folders, prompt library, conversation export (JSON / Markdown / PDF-with-images), Mermaid rendering, quote reply, DeepSeek balance and daily token usage; dual-face plugin mounted without dsh source changes.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -40,18 +40,6 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=22"
|
|
42
42
|
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "tsc -p tsconfig.build.json && tsdown",
|
|
45
|
-
"bundle": "tsdown",
|
|
46
|
-
"watch": "tsdown --watch",
|
|
47
|
-
"typecheck": "tsc --noEmit",
|
|
48
|
-
"test": "vitest run",
|
|
49
|
-
"test:watch": "vitest",
|
|
50
|
-
"check:readme": "node scripts/check-readme-i18n.mjs",
|
|
51
|
-
"smoke": "node scripts/smoke.mjs",
|
|
52
|
-
"prepare": "pnpm build",
|
|
53
|
-
"prepublishOnly": "pnpm typecheck && pnpm test"
|
|
54
|
-
},
|
|
55
43
|
"peerDependencies": {
|
|
56
44
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
57
45
|
"@deepseek-ai/dsh-tools": "^0.1.1-rc.1"
|
|
@@ -88,5 +76,18 @@
|
|
|
88
76
|
"README.zh.md",
|
|
89
77
|
"README.i18n.yaml"
|
|
90
78
|
],
|
|
91
|
-
"license": "Apache-2.0"
|
|
92
|
-
|
|
79
|
+
"license": "Apache-2.0",
|
|
80
|
+
"optionalDependencies": {
|
|
81
|
+
"keytar": "7.9.0"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "tsc -p tsconfig.build.json && tsdown",
|
|
85
|
+
"bundle": "tsdown",
|
|
86
|
+
"watch": "tsdown --watch",
|
|
87
|
+
"typecheck": "tsc --noEmit",
|
|
88
|
+
"test": "vitest run",
|
|
89
|
+
"test:watch": "vitest",
|
|
90
|
+
"check:readme": "node scripts/check-readme-i18n.mjs",
|
|
91
|
+
"smoke": "node scripts/smoke.mjs"
|
|
92
|
+
}
|
|
93
|
+
}
|