@qilin-agent/util-values 0.0.0-stage → 3.1.3
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.i18n.yaml +43 -0
- package/README.md +94 -2
- package/README.zh.md +95 -0
- package/lib/index.js +923 -0
- package/lib/types/index.d.ts +78 -0
- package/lib/types/partial-json.d.ts +152 -0
- package/package.json +35 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Duplicate-install-safe JSON and immutable-value helpers. @module @qilin-agent/util-values */
|
|
2
|
+
/** A value that round-trips through JSON without loss. */
|
|
3
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Mark an unreachable closed-union branch.
|
|
8
|
+
* @param value - impossible value; an unhandled typed variant fails at the call site.
|
|
9
|
+
* @param context - optional switch-site label included in the failure message.
|
|
10
|
+
* @returns never; a runtime value that escaped its type always throws.
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertNever(value: never, context?: string): never;
|
|
13
|
+
/**
|
|
14
|
+
* Validate and detach lossless JSON in one read per property.
|
|
15
|
+
* @param value - candidate value to validate and detach.
|
|
16
|
+
* @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
|
|
17
|
+
*/
|
|
18
|
+
export declare function snapshotJsonValue<T>(value: T): T | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Test the same lossless JSON rules as {@link snapshotJsonValue} without detaching the value.
|
|
21
|
+
* @param value - candidate value to test.
|
|
22
|
+
* @returns whether the value survives a JSON round trip without loss.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isJsonValue(value: unknown): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Compare JSON-compatible values structurally.
|
|
27
|
+
* @param a - one JSON-compatible value.
|
|
28
|
+
* @param b - the other JSON-compatible value.
|
|
29
|
+
* @returns whether both values contain the same JSON data.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deepEqualJson(a: unknown, b: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
|
|
34
|
+
* @param value - value to freeze.
|
|
35
|
+
* @returns the same value after every reachable enumerable child is frozen.
|
|
36
|
+
*/
|
|
37
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
38
|
+
/**
|
|
39
|
+
* Weak-key lookup with a strongly retained iterable set of associated values.
|
|
40
|
+
*
|
|
41
|
+
* Each value must belong to only one key. The container performs no automatic
|
|
42
|
+
* cleanup; owners delete associations or clear the container at lifecycle end.
|
|
43
|
+
*/
|
|
44
|
+
export declare class WeakMapWithValues<Key extends object, Value> {
|
|
45
|
+
private keys;
|
|
46
|
+
private readonly valueSet;
|
|
47
|
+
/** Live strongly retained values in insertion order. */
|
|
48
|
+
readonly values: ReadonlySet<Value>;
|
|
49
|
+
/**
|
|
50
|
+
* Read the value associated with a key.
|
|
51
|
+
* @param key - weakly held lookup key.
|
|
52
|
+
* @returns the associated value, or absence.
|
|
53
|
+
*/
|
|
54
|
+
get(key: Key): Value | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Test whether a key has an association.
|
|
57
|
+
* @param key - weakly held lookup key.
|
|
58
|
+
* @returns whether the key is present.
|
|
59
|
+
*/
|
|
60
|
+
has(key: Key): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Associate one key with one caller-unique value.
|
|
63
|
+
* @param key - weakly held lookup key.
|
|
64
|
+
* @param value - strongly retained value that belongs to no other key.
|
|
65
|
+
* @returns this container.
|
|
66
|
+
*/
|
|
67
|
+
set(key: Key, value: Value): this;
|
|
68
|
+
/**
|
|
69
|
+
* Remove one association and its strongly retained value.
|
|
70
|
+
* @param key - weakly held lookup key.
|
|
71
|
+
* @returns whether an association was removed.
|
|
72
|
+
*/
|
|
73
|
+
delete(key: Key): boolean;
|
|
74
|
+
/** Remove every association and strongly retained value. */
|
|
75
|
+
clear(): void;
|
|
76
|
+
}
|
|
77
|
+
export { PartialArguments, type LengthReadOptions } from './partial-json.ts';
|
|
78
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
3
|
+
* that may still be streaming or from an already parsed object. Nothing is
|
|
4
|
+
* scanned until a reader asks; the view remembers every question it answered
|
|
5
|
+
* and reports changed answers when the owner refreshes for publication.
|
|
6
|
+
* Used for model tool-call arguments: a row reads the fields it
|
|
7
|
+
* cares about at whatever granularity it displays, at every stage of the call.
|
|
8
|
+
* @module @qilin-agent/util-values/src/partial-json
|
|
9
|
+
*/
|
|
10
|
+
import { type JsonValue } from './index.ts';
|
|
11
|
+
/** Granularity of a length read; a change is reported only when the rounded-up step moves. */
|
|
12
|
+
export interface LengthReadOptions {
|
|
13
|
+
/** Characters per step; defaults to 1 (every character counts). */
|
|
14
|
+
readonly step?: number;
|
|
15
|
+
/** Completed characters included in the displayed total; affects change detection only. */
|
|
16
|
+
readonly offset?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The view. A streaming instance grows through {@link PartialArguments.append};
|
|
20
|
+
* {@link PartialArguments.fromText} and {@link PartialArguments.fromObject} build
|
|
21
|
+
* sealed instances over a finished call. Every reader is total: an absent or
|
|
22
|
+
* differently typed field answers `undefined` (or `false`), never throws.
|
|
23
|
+
*/
|
|
24
|
+
export declare class PartialArguments {
|
|
25
|
+
#private;
|
|
26
|
+
/** The view of a call with no arguments available. */
|
|
27
|
+
static readonly EMPTY: PartialArguments;
|
|
28
|
+
/**
|
|
29
|
+
* View finished argument text without scanning it until a reader asks.
|
|
30
|
+
* @param text - the complete argument JSON text.
|
|
31
|
+
* @returns a sealed view.
|
|
32
|
+
*/
|
|
33
|
+
static fromText(text: string): PartialArguments;
|
|
34
|
+
/**
|
|
35
|
+
* View an already parsed argument payload, such as a PTC dispatch object.
|
|
36
|
+
* @param value - the parsed argument value.
|
|
37
|
+
* @returns a sealed view; a non-object payload has no fields.
|
|
38
|
+
*/
|
|
39
|
+
static fromObject(value: unknown): PartialArguments;
|
|
40
|
+
/**
|
|
41
|
+
* The source: text so far or a parsed object, plus whether it can still grow.
|
|
42
|
+
* These are the only enumerable fields, so two views over the same source
|
|
43
|
+
* compare equal structurally however far each has been read.
|
|
44
|
+
*/
|
|
45
|
+
private chunks;
|
|
46
|
+
private object;
|
|
47
|
+
private sealed;
|
|
48
|
+
/** Whether this view rejects further appends; does not scan text or register reads. */
|
|
49
|
+
get isSealed(): boolean;
|
|
50
|
+
/** Whether indexing or a content read found invalid JSON; unread value contents are not validated. */
|
|
51
|
+
get invalid(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Retain streamed argument text without scanning or comparing observed answers.
|
|
54
|
+
* @param fragment - the text following every fragment appended before.
|
|
55
|
+
*/
|
|
56
|
+
append(fragment: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Reconcile a streamed prefix with authoritative complete text without joining the fragments.
|
|
59
|
+
* @param text - the final argument text, which replaces missing or conflicting deltas.
|
|
60
|
+
* @returns this view sealed with its caches retained when every character matches; otherwise a new sealed view.
|
|
61
|
+
*/
|
|
62
|
+
settle(text: string): PartialArguments;
|
|
63
|
+
/**
|
|
64
|
+
* Compare observed answers and advance their publication baseline. Unread views remain unscanned.
|
|
65
|
+
* @returns whether any observed answer changed since its first read or the preceding refresh.
|
|
66
|
+
*/
|
|
67
|
+
refresh(): boolean;
|
|
68
|
+
private refreshRead;
|
|
69
|
+
/**
|
|
70
|
+
* Check whether no further fields can arrive.
|
|
71
|
+
* @returns whether the outer object closed, indexing failed, or the view is sealed; unread values are not validated.
|
|
72
|
+
*/
|
|
73
|
+
closed(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* List discovered fields in first-appearance order.
|
|
76
|
+
* @returns top-level keys seen so far, in first-appearance order.
|
|
77
|
+
*/
|
|
78
|
+
keys(): readonly string[];
|
|
79
|
+
/**
|
|
80
|
+
* Check whether a top-level field has appeared.
|
|
81
|
+
* @param key - argument name.
|
|
82
|
+
* @returns whether the field has appeared (a string opened or another value began).
|
|
83
|
+
*/
|
|
84
|
+
has(key: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Check whether a field's closing delimiter has arrived, without validating its contents.
|
|
87
|
+
* @param key - argument name.
|
|
88
|
+
* @returns whether its delimiter arrived and no content reader has reported an error for this value.
|
|
89
|
+
*/
|
|
90
|
+
complete(key: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Read string length without materializing its text.
|
|
93
|
+
* @param key - argument name.
|
|
94
|
+
* @param options - change granularity for a streaming string.
|
|
95
|
+
* @returns decoded UTF-16 length of the string field so far; undefined when absent or not a string.
|
|
96
|
+
*/
|
|
97
|
+
stringLength(key: string, options?: LengthReadOptions): number | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Check a string against a decoded UTF-16 length limit without materializing it.
|
|
100
|
+
* @param key - argument name.
|
|
101
|
+
* @param maxLength - decoded UTF-16 limit, floored to at least zero.
|
|
102
|
+
* @returns whether the string is longer than the limit; false when absent or not a string.
|
|
103
|
+
*/
|
|
104
|
+
stringExceeds(key: string, maxLength: number): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Read a decoded string, including a streaming prefix.
|
|
107
|
+
* @param key - argument name.
|
|
108
|
+
* @returns the string field's decoded text so far; undefined when absent or not a string.
|
|
109
|
+
*/
|
|
110
|
+
text(key: string): string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Read at most the first decoded UTF-16 units of a string.
|
|
113
|
+
* @param key - argument name.
|
|
114
|
+
* @param maxLength - maximum decoded UTF-16 length, floored to at least one.
|
|
115
|
+
* @returns the bounded string prefix; undefined when absent or not a string.
|
|
116
|
+
*/
|
|
117
|
+
textPrefix(key: string, maxLength: number): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Read a completed non-string argument.
|
|
120
|
+
* @param key - argument name.
|
|
121
|
+
* @returns the parsed non-string value once it closed; undefined while open, absent, or a string.
|
|
122
|
+
*/
|
|
123
|
+
value(key: string): JsonValue | undefined;
|
|
124
|
+
/** Answer a question and, on a streaming view, remember it for change detection. */
|
|
125
|
+
private remember;
|
|
126
|
+
private closedNow;
|
|
127
|
+
private keysNow;
|
|
128
|
+
private hasNow;
|
|
129
|
+
private completeNow;
|
|
130
|
+
private lengthNow;
|
|
131
|
+
private textNow;
|
|
132
|
+
private textPrefixNow;
|
|
133
|
+
private valueNow;
|
|
134
|
+
private chunkAt;
|
|
135
|
+
/** Materialize only a requested range, never the cumulative source. */
|
|
136
|
+
private slice;
|
|
137
|
+
private readString;
|
|
138
|
+
/** Locate new field ranges without decoding or parsing their contents. */
|
|
139
|
+
private scan;
|
|
140
|
+
/** Only raw quotes and their preceding backslash runs can terminate a string. */
|
|
141
|
+
private stringBoundary;
|
|
142
|
+
private step;
|
|
143
|
+
private fail;
|
|
144
|
+
private beginKey;
|
|
145
|
+
private stepKey;
|
|
146
|
+
private open;
|
|
147
|
+
private beginValue;
|
|
148
|
+
private stepScalar;
|
|
149
|
+
private stepNested;
|
|
150
|
+
private closeValue;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=partial-json.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qilin-agent/util-values",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Duplicate-install-safe value primitives for the QiLin",
|
|
4
|
+
"version": "3.1.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/kkutysllb/QiLin.git",
|
|
11
|
+
"directory": "packages/util/values"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "lib/types/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./lib/types/index.d.ts",
|
|
22
|
+
"default": "./lib/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./src/*": "./src/*",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"lib/index.js",
|
|
29
|
+
"lib/types/**/*.d.ts"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@qilin-agent/kylin": "~4.0.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@qilin-agent/kylin": "~4.0.3"
|
|
37
|
+
}
|
|
6
38
|
}
|