@sparkelf/dsh-knowledge-base 0.5.4 → 0.6.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/README.md +36 -0
- package/lib/client.js +767 -622
- package/lib/client.js.map +1 -1
- package/lib/index.js +219 -34
- package/lib/types/client/KnowledgeMemory.d.ts +13 -0
- package/lib/types/client/locales.d.ts +6 -0
- package/lib/types/guardianSession.d.ts +23 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/memoryRoutes.d.ts +7 -1
- package/lib/types/memorySettings.d.ts +83 -12
- package/package.json +1 -1
|
@@ -1,40 +1,111 @@
|
|
|
1
1
|
/** File name inside one user's directory. */
|
|
2
2
|
export declare const MEMORY_SETTINGS_FILE = "settings.json";
|
|
3
|
+
/** Current persisted schema version. */
|
|
4
|
+
export declare const MEMORY_SETTINGS_VERSION = 2;
|
|
5
|
+
/** Shortest allowed consolidation interval, in minutes. */
|
|
6
|
+
export declare const MEMORY_CONSOLIDATION_INTERVAL_MIN = 15;
|
|
7
|
+
/** Longest allowed consolidation interval, in minutes. */
|
|
8
|
+
export declare const MEMORY_CONSOLIDATION_INTERVAL_MAX = 1440;
|
|
9
|
+
/** Default consolidation interval, in minutes. */
|
|
10
|
+
export declare const MEMORY_CONSOLIDATION_INTERVAL_DEFAULT = 60;
|
|
3
11
|
/** Persisted settings shape. */
|
|
4
12
|
export interface MemorySettings {
|
|
5
|
-
version:
|
|
13
|
+
version: typeof MEMORY_SETTINGS_VERSION;
|
|
6
14
|
/** `false` means paused: no new memories are learned. */
|
|
7
15
|
memoryEnabled: boolean;
|
|
16
|
+
/** How often the guardian consolidates memory, in minutes (15–1440). */
|
|
17
|
+
consolidationIntervalMinutes: number;
|
|
8
18
|
}
|
|
9
19
|
/** The paused default for a user who has never confirmed the enable dialog. */
|
|
10
20
|
export declare const DEFAULT_MEMORY_SETTINGS: Readonly<MemorySettings>;
|
|
21
|
+
/** A malformed interval or write patch; the route maps this to HTTP 400. */
|
|
22
|
+
export declare class MemorySettingsError extends Error {
|
|
23
|
+
readonly code: 'invalid-interval' | 'invalid-settings';
|
|
24
|
+
readonly name = "MemorySettingsError";
|
|
25
|
+
constructor(code: 'invalid-interval' | 'invalid-settings', message: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Where the first-read default for a principal comes from.
|
|
29
|
+
*
|
|
30
|
+
* The store deliberately does not know what an administrator is. The Host
|
|
31
|
+
* injects this seam with the existing DataOps principal projection, so the KB
|
|
32
|
+
* package keeps no hard-coded role names and a deployment can change the rule
|
|
33
|
+
* without editing this module.
|
|
34
|
+
*/
|
|
35
|
+
export interface MemorySettingsDefaultPolicy {
|
|
36
|
+
/**
|
|
37
|
+
* Whether a user with no settings file starts enabled.
|
|
38
|
+
*
|
|
39
|
+
* A rejection is treated as "paused": a backend hiccup must not turn memory on
|
|
40
|
+
* silently, and it must not make the settings page unreadable either.
|
|
41
|
+
*/
|
|
42
|
+
memoryEnabled(userId: string): boolean | Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
/** Optional per-read override, used by the route that already resolved the principal. */
|
|
45
|
+
export interface MemorySettingsReadOptions {
|
|
46
|
+
/** Explicit first-read default; when omitted the constructor policy decides. */
|
|
47
|
+
defaultEnabled?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A partial write; at least one field must be present. */
|
|
50
|
+
export interface MemorySettingsPatch {
|
|
51
|
+
memoryEnabled?: boolean;
|
|
52
|
+
consolidationIntervalMinutes?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate one consolidation interval.
|
|
56
|
+
*
|
|
57
|
+
* The guard is strict on purpose: a fractional value or a value outside
|
|
58
|
+
* 15–1440 is a client bug, not a number to clamp silently. The route turns this
|
|
59
|
+
* error into a 400 so the page can show the allowed range.
|
|
60
|
+
*
|
|
61
|
+
* @param value - raw value from an API body or a hand-edited file.
|
|
62
|
+
* @returns the accepted integer.
|
|
63
|
+
* @throws {MemorySettingsError} when the value is not an integer in range.
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeConsolidationInterval(value: unknown): number;
|
|
11
66
|
/**
|
|
12
67
|
* Atomic settings store over `<usersRoot>/<userId>/settings.json`.
|
|
13
68
|
*
|
|
14
69
|
* `read()` tolerates a corrupt file by returning the paused default; the next
|
|
15
|
-
*
|
|
16
|
-
*
|
|
70
|
+
* write rewrites it. This keeps the memory page usable after a partial write or
|
|
71
|
+
* a hand-edited file instead of failing the whole route.
|
|
17
72
|
*/
|
|
18
73
|
export declare class MemorySettingsStore {
|
|
19
74
|
private readonly usersRoot;
|
|
20
|
-
|
|
75
|
+
private readonly defaultPolicy?;
|
|
76
|
+
constructor(usersRoot: string, defaultPolicy?: MemorySettingsDefaultPolicy);
|
|
21
77
|
/** Absolute settings file for one user. */
|
|
22
78
|
filePath(userId: string): string;
|
|
79
|
+
/** The first-read default for one user, from the injected policy. */
|
|
80
|
+
private defaultFor;
|
|
23
81
|
/**
|
|
24
82
|
* Read one user's settings.
|
|
25
83
|
*
|
|
26
|
-
* Missing
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
84
|
+
* Missing content uses {@link MemorySettingsReadOptions.defaultEnabled} or the
|
|
85
|
+
* injected policy. Malformed content stays paused even for an administrator:
|
|
86
|
+
* a corrupt file is not evidence that the administrator opted in. A file with
|
|
87
|
+
* a boolean `memoryEnabled` is accepted even if `version`/the interval is
|
|
88
|
+
* missing, so old settings files keep their explicit choice.
|
|
30
89
|
*/
|
|
31
|
-
read(userId: string): Promise<MemorySettings>;
|
|
90
|
+
read(userId: string, options?: MemorySettingsReadOptions): Promise<MemorySettings>;
|
|
32
91
|
/** Whether learning is enabled for this user (default `false`). */
|
|
33
|
-
isEnabled(userId: string): Promise<boolean>;
|
|
92
|
+
isEnabled(userId: string, options?: MemorySettingsReadOptions): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Persist a partial settings change in one atomic write.
|
|
95
|
+
*
|
|
96
|
+
* The current value is read first so a page that saves only the interval
|
|
97
|
+
* cannot accidentally pause memory (nor enable it). An explicit boolean in
|
|
98
|
+
* the patch always wins; an absent field is preserved.
|
|
99
|
+
*
|
|
100
|
+
* @returns the normalized settings actually written.
|
|
101
|
+
*/
|
|
102
|
+
save(userId: string, patch: MemorySettingsPatch, options?: MemorySettingsReadOptions): Promise<MemorySettings>;
|
|
34
103
|
/**
|
|
35
|
-
* Persist the enable/pause switch atomically.
|
|
104
|
+
* Persist the enable/pause switch atomically, preserving the interval.
|
|
36
105
|
*
|
|
37
106
|
* @returns the normalized settings actually written.
|
|
38
107
|
*/
|
|
39
|
-
setEnabled(userId: string, enabled: boolean): Promise<MemorySettings>;
|
|
108
|
+
setEnabled(userId: string, enabled: boolean, options?: MemorySettingsReadOptions): Promise<MemorySettings>;
|
|
109
|
+
/** Persist one interval while preserving the switch. */
|
|
110
|
+
setConsolidationInterval(userId: string, minutes: number, options?: MemorySettingsReadOptions): Promise<MemorySettings>;
|
|
40
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkelf/dsh-knowledge-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "DataOps-backed knowledge base for DeepSeek Harness: a left-sidebar destination, Settings configuration, and index tooling over a mounted NAS view.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|