prefix-safe-json 0.0.1-alpha.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/LICENSE-APACHE +114 -0
- package/LICENSE-MIT +21 -0
- package/README.md +169 -0
- package/dist/coordinator/coordinator.d.ts +43 -0
- package/dist/coordinator/coordinator.d.ts.map +1 -0
- package/dist/coordinator/coordinator.js +407 -0
- package/dist/coordinator/coordinator.js.map +1 -0
- package/dist/coordinator/protocol.d.ts +61 -0
- package/dist/coordinator/protocol.d.ts.map +1 -0
- package/dist/coordinator/protocol.js +2 -0
- package/dist/coordinator/protocol.js.map +1 -0
- package/dist/coordinator/types.d.ts +84 -0
- package/dist/coordinator/types.d.ts.map +1 -0
- package/dist/coordinator/types.js +7 -0
- package/dist/coordinator/types.js.map +1 -0
- package/dist/diagnostics/codes.d.ts +24 -0
- package/dist/diagnostics/codes.d.ts.map +1 -0
- package/dist/diagnostics/codes.js +28 -0
- package/dist/diagnostics/codes.js.map +1 -0
- package/dist/diagnostics/factory.d.ts +8 -0
- package/dist/diagnostics/factory.d.ts.map +1 -0
- package/dist/diagnostics/factory.js +17 -0
- package/dist/diagnostics/factory.js.map +1 -0
- package/dist/grammar/frame.d.ts +58 -0
- package/dist/grammar/frame.d.ts.map +1 -0
- package/dist/grammar/frame.js +87 -0
- package/dist/grammar/frame.js.map +1 -0
- package/dist/grammar/pointer.d.ts +10 -0
- package/dist/grammar/pointer.d.ts.map +1 -0
- package/dist/grammar/pointer.js +20 -0
- package/dist/grammar/pointer.js.map +1 -0
- package/dist/grammar/stack.d.ts +73 -0
- package/dist/grammar/stack.d.ts.map +1 -0
- package/dist/grammar/stack.js +168 -0
- package/dist/grammar/stack.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer/scanner.d.ts +108 -0
- package/dist/lexer/scanner.d.ts.map +1 -0
- package/dist/lexer/scanner.js +676 -0
- package/dist/lexer/scanner.js.map +1 -0
- package/dist/lexer/states.d.ts +35 -0
- package/dist/lexer/states.d.ts.map +1 -0
- package/dist/lexer/states.js +39 -0
- package/dist/lexer/states.js.map +1 -0
- package/dist/lexer/tokens.d.ts +22 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +22 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/limits.d.ts +14 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +23 -0
- package/dist/limits.js.map +1 -0
- package/dist/parser.d.ts +6 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +949 -0
- package/dist/parser.js.map +1 -0
- package/dist/providers/adapter.d.ts +10 -0
- package/dist/providers/adapter.d.ts.map +1 -0
- package/dist/providers/adapter.js +2 -0
- package/dist/providers/adapter.js.map +1 -0
- package/dist/providers/anthropic.d.ts +45 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +112 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/gemini.d.ts +31 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +94 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/openai-compatible.d.ts +33 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai-compatible.js +160 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/providers/openai.d.ts +48 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +205 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +35 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +55 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/semantic/builder.d.ts +55 -0
- package/dist/semantic/builder.d.ts.map +1 -0
- package/dist/semantic/builder.js +140 -0
- package/dist/semantic/builder.js.map +1 -0
- package/dist/semantic/events.d.ts +2 -0
- package/dist/semantic/events.d.ts.map +1 -0
- package/dist/semantic/events.js +5 -0
- package/dist/semantic/events.js.map +1 -0
- package/dist/semantic/snapshot.d.ts +49 -0
- package/dist/semantic/snapshot.d.ts.map +1 -0
- package/dist/semantic/snapshot.js +228 -0
- package/dist/semantic/snapshot.js.map +1 -0
- package/dist/types.d.ts +156 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utf8/decoder.d.ts +53 -0
- package/dist/utf8/decoder.d.ts.map +1 -0
- package/dist/utf8/decoder.js +318 -0
- package/dist/utf8/decoder.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Snapshot builder — constructs stableValue from committed events
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/**
|
|
5
|
+
* Maintains the stable value by processing committed events.
|
|
6
|
+
* Only committed values appear in the stable value.
|
|
7
|
+
*/
|
|
8
|
+
export class SnapshotBuilder {
|
|
9
|
+
root = undefined;
|
|
10
|
+
hasRoot = false;
|
|
11
|
+
/**
|
|
12
|
+
* Maps each open container's grammar frame to its corresponding node in
|
|
13
|
+
* the stable-value tree, so a newly-opened child container can attach
|
|
14
|
+
* directly to its parent in O(1) via initContainerForFrame() instead of
|
|
15
|
+
* re-parsing a JSON Pointer path string and re-walking from the root on
|
|
16
|
+
* every single container open (see initContainerForFrame).
|
|
17
|
+
*/
|
|
18
|
+
frameNodes = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* Process a value_committed event and integrate it into the stable value.
|
|
21
|
+
*/
|
|
22
|
+
processEvent(event) {
|
|
23
|
+
if (event.type !== "value_committed")
|
|
24
|
+
return;
|
|
25
|
+
const { path, value } = event;
|
|
26
|
+
// Parse the JSON Pointer path to navigate to the parent
|
|
27
|
+
const segments = parsePointer(path);
|
|
28
|
+
if (segments.length === 0)
|
|
29
|
+
return;
|
|
30
|
+
// Ensure root exists
|
|
31
|
+
if (!this.hasRoot) {
|
|
32
|
+
// We need a container at root — determine from the first segment
|
|
33
|
+
// This shouldn't happen if events are emitted correctly,
|
|
34
|
+
// because container events come before child value events.
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const parentSegments = segments.slice(0, -1);
|
|
38
|
+
const lastSegment = segments[segments.length - 1];
|
|
39
|
+
if (lastSegment === undefined)
|
|
40
|
+
return;
|
|
41
|
+
let target = this.root;
|
|
42
|
+
for (const seg of parentSegments) {
|
|
43
|
+
if (target === null || target === undefined)
|
|
44
|
+
return;
|
|
45
|
+
if (typeof target === "object" && !Array.isArray(target)) {
|
|
46
|
+
target = target[seg];
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(target)) {
|
|
49
|
+
const idx = parseInt(seg, 10);
|
|
50
|
+
if (isNaN(idx))
|
|
51
|
+
return;
|
|
52
|
+
target = target[idx];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return; // Can't navigate into scalar
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (target === null || target === undefined)
|
|
59
|
+
return;
|
|
60
|
+
if (typeof target === "object" && !Array.isArray(target)) {
|
|
61
|
+
safeSet(target, lastSegment, value);
|
|
62
|
+
}
|
|
63
|
+
else if (Array.isArray(target)) {
|
|
64
|
+
const idx = parseInt(lastSegment, 10);
|
|
65
|
+
if (!isNaN(idx)) {
|
|
66
|
+
target[idx] = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Initialize the root as an object container.
|
|
72
|
+
* `frame` is registered so child containers can find it in O(1).
|
|
73
|
+
*/
|
|
74
|
+
initRootObject(frame) {
|
|
75
|
+
if (!this.hasRoot) {
|
|
76
|
+
this.root = {};
|
|
77
|
+
this.hasRoot = true;
|
|
78
|
+
}
|
|
79
|
+
if (frame)
|
|
80
|
+
this.frameNodes.set(frame, this.root);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Initialize the root as an array container.
|
|
84
|
+
* `frame` is registered so child containers can find it in O(1).
|
|
85
|
+
*/
|
|
86
|
+
initRootArray(frame) {
|
|
87
|
+
if (!this.hasRoot) {
|
|
88
|
+
this.root = [];
|
|
89
|
+
this.hasRoot = true;
|
|
90
|
+
}
|
|
91
|
+
if (frame)
|
|
92
|
+
this.frameNodes.set(frame, this.root);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Initialize a nested container for the given (already-pushed) grammar
|
|
96
|
+
* frame, attaching it directly to its parent's node.
|
|
97
|
+
*
|
|
98
|
+
* Uses frame._parent/_segment (see grammar/frame.ts) plus the frameNodes
|
|
99
|
+
* map instead of re-parsing frame.path and walking the tree from the
|
|
100
|
+
* root on every call — that walk is O(depth), and calling it once for
|
|
101
|
+
* every one of N nested containers made opening N levels cost O(N^2)
|
|
102
|
+
* total, independent of the grammar-stack path-string fix.
|
|
103
|
+
*/
|
|
104
|
+
initContainerForFrame(frame, type) {
|
|
105
|
+
if (!this.hasRoot)
|
|
106
|
+
return;
|
|
107
|
+
const parent = frame._parent;
|
|
108
|
+
const segment = frame._segment;
|
|
109
|
+
if (!parent || segment === null || segment === undefined)
|
|
110
|
+
return;
|
|
111
|
+
const parentNode = this.frameNodes.get(parent);
|
|
112
|
+
if (parentNode === undefined || parentNode === null)
|
|
113
|
+
return;
|
|
114
|
+
const newContainer = type === "object" ? {} : [];
|
|
115
|
+
if (typeof parentNode === "object" && !Array.isArray(parentNode)) {
|
|
116
|
+
safeSet(parentNode, segment, newContainer);
|
|
117
|
+
}
|
|
118
|
+
else if (Array.isArray(parentNode)) {
|
|
119
|
+
const idx = typeof segment === "number" ? segment : parseInt(segment, 10);
|
|
120
|
+
if (!isNaN(idx)) {
|
|
121
|
+
parentNode[idx] = newContainer;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.frameNodes.set(frame, newContainer);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a deep clone of the current stable value.
|
|
131
|
+
*/
|
|
132
|
+
getStableValue() {
|
|
133
|
+
if (!this.hasRoot)
|
|
134
|
+
return undefined;
|
|
135
|
+
return deepClone(this.root);
|
|
136
|
+
}
|
|
137
|
+
get hasRootValue() {
|
|
138
|
+
return this.hasRoot;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Parse a JSON Pointer string into segments.
|
|
143
|
+
* Handles ~0 (~) and ~1 (/) unescaping.
|
|
144
|
+
*/
|
|
145
|
+
function parsePointer(pointer) {
|
|
146
|
+
if (pointer === "")
|
|
147
|
+
return [];
|
|
148
|
+
if (!pointer.startsWith("/"))
|
|
149
|
+
return [];
|
|
150
|
+
return pointer
|
|
151
|
+
.slice(1)
|
|
152
|
+
.split("/")
|
|
153
|
+
.map((seg) => seg.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Assign a JSON-derived key onto a plain object without going through the
|
|
157
|
+
* inherited `__proto__` accessor. Bracket assignment (obj[key] = value) on a
|
|
158
|
+
* plain object silently reassigns the object's prototype instead of creating
|
|
159
|
+
* an own property when key === "__proto__", which makes that field vanish
|
|
160
|
+
* from Object.keys()/JSON.stringify(). defineProperty always creates a real
|
|
161
|
+
* own data property, matching native JSON.parse's behavior for such keys.
|
|
162
|
+
*/
|
|
163
|
+
function safeSet(obj, key, value) {
|
|
164
|
+
Object.defineProperty(obj, key, {
|
|
165
|
+
value,
|
|
166
|
+
writable: true,
|
|
167
|
+
enumerable: true,
|
|
168
|
+
configurable: true,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Deep clone a JSON value.
|
|
173
|
+
* Iterative (explicit work-stack) rather than recursive: a recursive
|
|
174
|
+
* implementation overflows the JS call stack around ~5000 levels of nesting,
|
|
175
|
+
* well below values maxDepth's type otherwise permits.
|
|
176
|
+
*/
|
|
177
|
+
function deepClone(value) {
|
|
178
|
+
if (value === null || typeof value !== "object") {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
const root = Array.isArray(value) ? [] : {};
|
|
182
|
+
const stack = [
|
|
183
|
+
{ src: value, dst: root },
|
|
184
|
+
];
|
|
185
|
+
while (stack.length > 0) {
|
|
186
|
+
const frame = stack.pop();
|
|
187
|
+
if (!frame)
|
|
188
|
+
continue;
|
|
189
|
+
const { src, dst } = frame;
|
|
190
|
+
if (Array.isArray(src)) {
|
|
191
|
+
const dstArr = dst;
|
|
192
|
+
for (let i = 0; i < src.length; i++) {
|
|
193
|
+
const child = src[i];
|
|
194
|
+
if (child !== null && typeof child === "object") {
|
|
195
|
+
const childClone = Array.isArray(child) ? [] : {};
|
|
196
|
+
dstArr[i] = childClone;
|
|
197
|
+
stack.push({
|
|
198
|
+
src: child,
|
|
199
|
+
dst: childClone,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
dstArr[i] = child;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const srcObj = src;
|
|
209
|
+
const dstObj = dst;
|
|
210
|
+
for (const key of Object.keys(srcObj)) {
|
|
211
|
+
const child = srcObj[key];
|
|
212
|
+
if (child !== null && typeof child === "object") {
|
|
213
|
+
const childClone = Array.isArray(child) ? [] : {};
|
|
214
|
+
safeSet(dstObj, key, childClone);
|
|
215
|
+
stack.push({
|
|
216
|
+
src: child,
|
|
217
|
+
dst: childClone,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
safeSet(dstObj, key, child);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return root;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAChD,MAAM,UAAU,GAAc,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC7D,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;oBACjC,KAAK,CAAC,IAAI,CAAC;wBACT,GAAG,EAAE,KAA+B;wBACpC,GAAG,EAAE,UAAoC;qBAC1C,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/** Standard JSON value type. */
|
|
2
|
+
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export type JsonArray = JsonValue[];
|
|
7
|
+
/** Why the LLM stream ended. */
|
|
8
|
+
export type StreamEndReason = "complete" | "length" | "network_error" | "provider_error" | "cancelled" | "unknown";
|
|
9
|
+
/** Returned by `push()` after feeding a chunk. */
|
|
10
|
+
export interface PushResult {
|
|
11
|
+
/** Number of bytes accepted from this chunk. */
|
|
12
|
+
acceptedBytes: number;
|
|
13
|
+
/** Number of semantic events emitted during this push. */
|
|
14
|
+
emittedEvents: number;
|
|
15
|
+
/** Current syntactic status of the document. */
|
|
16
|
+
syntax: SyntaxStatus;
|
|
17
|
+
/** If true, the parser will not accept further input. */
|
|
18
|
+
terminal: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type SyntaxStatus = "empty" | "incomplete" | "root_complete" | "invalid";
|
|
21
|
+
/** Immutable snapshot of parser state. */
|
|
22
|
+
export interface ParserSnapshot {
|
|
23
|
+
/** Whether we are still collecting or the stream is finished. */
|
|
24
|
+
phase: "collecting" | "finished";
|
|
25
|
+
/** Current syntactic status. */
|
|
26
|
+
syntax: SyntaxStatus;
|
|
27
|
+
/** JSON value built from only fully-committed fields. */
|
|
28
|
+
stableValue?: JsonValue;
|
|
29
|
+
/** Whether the root JSON container has been closed. */
|
|
30
|
+
rootComplete: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the parsed result is safe for tool execution.
|
|
33
|
+
* True only when root is complete, stream finished normally,
|
|
34
|
+
* no pending tokens, no fatal diagnostics, no duplicate keys,
|
|
35
|
+
* and no structural/lossy repairs.
|
|
36
|
+
*/
|
|
37
|
+
executable: boolean;
|
|
38
|
+
/** Tokens still awaiting more data. */
|
|
39
|
+
pending: readonly PendingToken[];
|
|
40
|
+
/** Repairs applied (populated at finish). */
|
|
41
|
+
repairs: readonly RepairAction[];
|
|
42
|
+
/** All diagnostics emitted so far. */
|
|
43
|
+
diagnostics: readonly Diagnostic[];
|
|
44
|
+
/** Total bytes received via push(). */
|
|
45
|
+
receivedBytes: number;
|
|
46
|
+
/** Bytes successfully consumed by the parser. */
|
|
47
|
+
consumedBytes: number;
|
|
48
|
+
}
|
|
49
|
+
/** A value that is in-progress and not yet committed. */
|
|
50
|
+
export interface PendingToken {
|
|
51
|
+
type: "string" | "number" | "literal" | "unicode_escape" | "surrogate" | "object_key";
|
|
52
|
+
path: string;
|
|
53
|
+
buffered: string;
|
|
54
|
+
byteOffset: number;
|
|
55
|
+
}
|
|
56
|
+
/** Describes a deterministic repair applied at stream end. */
|
|
57
|
+
export interface RepairAction {
|
|
58
|
+
code: string;
|
|
59
|
+
byteRange: readonly [number, number];
|
|
60
|
+
impact: "representation_preserving" | "root_preserving" | "structural" | "lossy";
|
|
61
|
+
description: string;
|
|
62
|
+
}
|
|
63
|
+
/** Structured parse diagnostic. */
|
|
64
|
+
export interface Diagnostic {
|
|
65
|
+
code: string;
|
|
66
|
+
severity: "info" | "warning" | "error" | "fatal";
|
|
67
|
+
byteOffset: number;
|
|
68
|
+
path?: string;
|
|
69
|
+
recoverable: boolean;
|
|
70
|
+
message: string;
|
|
71
|
+
}
|
|
72
|
+
export type ParserEvent = ValueCommittedEvent | ContainerClosedEvent | RepairAppliedEvent | DiagnosticEvent | DocumentCompleteEvent | StreamFinishedEvent;
|
|
73
|
+
export interface ValueCommittedEvent {
|
|
74
|
+
type: "value_committed";
|
|
75
|
+
sequence: number;
|
|
76
|
+
path: string;
|
|
77
|
+
operation: "add";
|
|
78
|
+
value: JsonValue;
|
|
79
|
+
byteRange: readonly [number, number];
|
|
80
|
+
}
|
|
81
|
+
export interface ContainerClosedEvent {
|
|
82
|
+
type: "container_closed";
|
|
83
|
+
sequence: number;
|
|
84
|
+
path: string;
|
|
85
|
+
container: "object" | "array";
|
|
86
|
+
}
|
|
87
|
+
export interface RepairAppliedEvent {
|
|
88
|
+
type: "repair_applied";
|
|
89
|
+
sequence: number;
|
|
90
|
+
repair: RepairAction;
|
|
91
|
+
}
|
|
92
|
+
export interface DiagnosticEvent {
|
|
93
|
+
type: "diagnostic";
|
|
94
|
+
sequence: number;
|
|
95
|
+
diagnostic: Diagnostic;
|
|
96
|
+
}
|
|
97
|
+
export interface DocumentCompleteEvent {
|
|
98
|
+
type: "document_complete";
|
|
99
|
+
sequence: number;
|
|
100
|
+
executable: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface StreamFinishedEvent {
|
|
103
|
+
type: "stream_finished";
|
|
104
|
+
sequence: number;
|
|
105
|
+
outcome: "valid" | "truncated" | "salvaged" | "invalid";
|
|
106
|
+
}
|
|
107
|
+
/** Returned by `finish()`. */
|
|
108
|
+
export interface FinalResult {
|
|
109
|
+
/** Final syntactic status. */
|
|
110
|
+
syntax: SyntaxStatus;
|
|
111
|
+
/** Overall parse outcome. */
|
|
112
|
+
outcome: "valid" | "truncated" | "salvaged" | "invalid";
|
|
113
|
+
/** JSON value from committed fields only. */
|
|
114
|
+
stableValue?: JsonValue;
|
|
115
|
+
/** Whether the result is safe for tool execution. */
|
|
116
|
+
executable: boolean;
|
|
117
|
+
/** All repairs applied during finalization. */
|
|
118
|
+
repairs: readonly RepairAction[];
|
|
119
|
+
/** All diagnostics. */
|
|
120
|
+
diagnostics: readonly Diagnostic[];
|
|
121
|
+
/** Total received bytes. */
|
|
122
|
+
receivedBytes: number;
|
|
123
|
+
/** Consumed bytes. */
|
|
124
|
+
consumedBytes: number;
|
|
125
|
+
}
|
|
126
|
+
/** The incremental parser API. */
|
|
127
|
+
export interface IncrementalJsonParser {
|
|
128
|
+
/** Feed a chunk of data. */
|
|
129
|
+
push(chunk: string | Uint8Array): PushResult;
|
|
130
|
+
/** Get a snapshot of the current parser state. */
|
|
131
|
+
snapshot(): ParserSnapshot;
|
|
132
|
+
/** Drain and return all unconsumed events, clearing the queue. */
|
|
133
|
+
drainEvents(): readonly ParserEvent[];
|
|
134
|
+
/** Signal stream completion. Must be called exactly once. */
|
|
135
|
+
finish(meta?: {
|
|
136
|
+
reason?: StreamEndReason;
|
|
137
|
+
providerReason?: string;
|
|
138
|
+
}): FinalResult;
|
|
139
|
+
}
|
|
140
|
+
export interface RepairOptions {
|
|
141
|
+
readonly rawControlCharacters: "reject" | "escape";
|
|
142
|
+
readonly trailingData: "reject" | "isolate";
|
|
143
|
+
readonly closeContainersAtFinish: "disabled" | "safe-only";
|
|
144
|
+
}
|
|
145
|
+
export interface ParserOptions {
|
|
146
|
+
limits?: Partial<ParserLimits>;
|
|
147
|
+
repairs?: Partial<RepairOptions>;
|
|
148
|
+
}
|
|
149
|
+
export interface ParserLimits {
|
|
150
|
+
maxInputBytes: number;
|
|
151
|
+
maxDepth: number;
|
|
152
|
+
maxStringBytes: number;
|
|
153
|
+
maxQueuedEvents: number;
|
|
154
|
+
maxTrailingDataBytes: number;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AAc,CAAC;IAE3B,kEAAkE;IAClE,WAAW,IAAI,SAAS,WAAW,EAAE,CAAC;IAEtC,6DAA6D;IAC7D,MAAM,CAAC,IAAI,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,WAAW,CAAC;CACjB;AAID,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,oBAAoB,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACnD,QAAQ,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,uBAAuB,EAAE,UAAU,GAAG,WAAW,CAAC;CAC5D;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAClC;AAID,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,EAAE,MAAM,CAAC;CAC9B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,oCAAoC;AACpC,8EAA8E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Result of decoding a chunk of bytes. */
|
|
2
|
+
export interface DecodeResult {
|
|
3
|
+
/** Decoded code points as a string. */
|
|
4
|
+
text: string;
|
|
5
|
+
/** Number of bytes consumed (may be less than input if trailing incomplete sequence). */
|
|
6
|
+
consumed: number;
|
|
7
|
+
/** Errors encountered during decoding. */
|
|
8
|
+
errors: Utf8Error[];
|
|
9
|
+
/** True if BOM was detected and stripped during this chunk. */
|
|
10
|
+
strippedBom: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface Utf8Error {
|
|
13
|
+
kind: "invalid_start_byte" | "invalid_continuation" | "overlong" | "out_of_range";
|
|
14
|
+
byteOffset: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Incremental UTF-8 decoder that handles multi-byte characters
|
|
18
|
+
* split across chunk boundaries.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Utf8Decoder {
|
|
21
|
+
/** Pending bytes from an incomplete multi-byte sequence. */
|
|
22
|
+
private pending;
|
|
23
|
+
/** Expected total length of the current multi-byte sequence. */
|
|
24
|
+
private pendingExpected;
|
|
25
|
+
/** Total bytes processed across all push() calls. */
|
|
26
|
+
private totalOffset;
|
|
27
|
+
private bomBuffer;
|
|
28
|
+
private checkedForBom;
|
|
29
|
+
/**
|
|
30
|
+
* Decode a chunk of bytes, returning decoded text and any errors.
|
|
31
|
+
* Incomplete trailing multi-byte sequences are buffered for the next call.
|
|
32
|
+
*/
|
|
33
|
+
decode(bytes: Uint8Array): DecodeResult;
|
|
34
|
+
/**
|
|
35
|
+
* Check if there are buffered incomplete bytes.
|
|
36
|
+
*/
|
|
37
|
+
hasIncomplete(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Get the byte offset where the incomplete sequence started.
|
|
40
|
+
*/
|
|
41
|
+
incompleteByteOffset(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Decode a complete multi-byte UTF-8 sequence into a code point.
|
|
44
|
+
* Returns an error for invalid continuation, overlong, or out-of-range sequences.
|
|
45
|
+
*/
|
|
46
|
+
private decodeSequence;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert a string to its UTF-8 byte representation.
|
|
50
|
+
* Utility for tests and string-mode push().
|
|
51
|
+
*/
|
|
52
|
+
export declare function stringToUtf8(str: string): Uint8Array;
|
|
53
|
+
//# sourceMappingURL=decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../src/utf8/decoder.ts"],"names":[],"mappings":"AAeA,2CAA2C;AAC3C,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,yFAAyF;IACzF,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,+DAA+D;IAC/D,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EACA,oBAAoB,GACpB,sBAAsB,GACtB,UAAU,GACV,cAAc,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,4DAA4D;IAC5D,OAAO,CAAC,OAAO,CAAgB;IAC/B,gEAAgE;IAChE,OAAO,CAAC,eAAe,CAAK;IAC5B,qDAAqD;IACrD,OAAO,CAAC,WAAW,CAAK;IAExB,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,aAAa,CAAS;IAE9B;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY;IAyMvC;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,oBAAoB,IAAI,MAAM;IAK9B;;;OAGG;IACH,OAAO,CAAC,cAAc;CAwDvB;AAoBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAGpD"}
|