prefix-safe-json 0.0.1-alpha.2 → 0.0.1-alpha.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/README.md +137 -4
- package/dist/coordinator/diagnostic-codes.d.ts +11 -0
- package/dist/coordinator/diagnostic-codes.d.ts.map +1 -0
- package/dist/coordinator/diagnostic-codes.js +22 -0
- package/dist/coordinator/diagnostic-codes.js.map +1 -0
- package/dist/coordinator/protocol.d.ts +1 -1
- package/dist/coordinator/protocol.d.ts.map +1 -1
- package/dist/gate/decide.d.ts +27 -0
- package/dist/gate/decide.d.ts.map +1 -0
- package/dist/gate/decide.js +138 -0
- package/dist/gate/decide.js.map +1 -0
- package/dist/gate/gate.d.ts +25 -0
- package/dist/gate/gate.d.ts.map +1 -0
- package/dist/gate/gate.js +96 -0
- package/dist/gate/gate.js.map +1 -0
- package/dist/gate/types.d.ts +184 -0
- package/dist/gate/types.d.ts.map +1 -0
- package/dist/gate/types.js +2 -0
- package/dist/gate/types.js.map +1 -0
- package/dist/guard/ai-sdk.d.ts +48 -0
- package/dist/guard/ai-sdk.d.ts.map +1 -0
- package/dist/guard/ai-sdk.js +51 -0
- package/dist/guard/ai-sdk.js.map +1 -0
- package/dist/guard/provider-guard.d.ts +4 -0
- package/dist/guard/provider-guard.d.ts.map +1 -0
- package/dist/guard/provider-guard.js +38 -0
- package/dist/guard/provider-guard.js.map +1 -0
- package/dist/guard/types.d.ts +48 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +2 -0
- package/dist/guard/types.js.map +1 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/lexer/scanner.d.ts +0 -2
- package/dist/lexer/scanner.d.ts.map +1 -1
- package/dist/lexer/scanner.js +3 -21
- package/dist/lexer/scanner.js.map +1 -1
- package/dist/lexer/states.d.ts +0 -4
- package/dist/lexer/states.d.ts.map +1 -1
- package/dist/lexer/states.js +0 -4
- package/dist/lexer/states.js.map +1 -1
- package/dist/parser.js +26 -53
- package/dist/parser.js.map +1 -1
- package/dist/providers/ai-sdk.d.ts +58 -0
- package/dist/providers/ai-sdk.d.ts.map +1 -0
- package/dist/providers/ai-sdk.js +212 -0
- package/dist/providers/ai-sdk.js.map +1 -0
- package/dist/providers/openai.d.ts +7 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +65 -7
- package/dist/providers/openai.js.map +1 -1
- package/dist/semantic/snapshot.d.ts +11 -4
- package/dist/semantic/snapshot.d.ts.map +1 -1
- package/dist/semantic/snapshot.js +11 -9
- package/dist/semantic/snapshot.js.map +1 -1
- package/package.json +8 -3
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { JsonValue, Diagnostic } from "../types.js";
|
|
2
|
+
import { CoordinatorDiagnostic, CoordinatorPushResult, ToolCallCoordinatorEvent } from "../coordinator/types.js";
|
|
3
|
+
import { NormalizedToolStreamEvent, ProviderName, StreamEndReason } from "../coordinator/protocol.js";
|
|
4
|
+
/**
|
|
5
|
+
* What to do with a tool call right now.
|
|
6
|
+
*
|
|
7
|
+
* - `"execute"`: the arguments are complete, unfabricated, and (if a schema
|
|
8
|
+
* was registered for this tool) schema-valid. Safe to run.
|
|
9
|
+
* - `"retry"`: the provider's output was incomplete or truncated. There is
|
|
10
|
+
* nothing wrong with the data received so far - there just isn't a
|
|
11
|
+
* trustworthy complete value yet. Re-request/continue generation.
|
|
12
|
+
* - `"reject"`: the data itself is the problem (malformed JSON, a schema
|
|
13
|
+
* mismatch, a resource limit, a provider-side error, or a content-policy
|
|
14
|
+
* termination). Re-sending the exact same partial input will not fix it.
|
|
15
|
+
*/
|
|
16
|
+
export type ExecutionAction = "execute" | "retry" | "reject";
|
|
17
|
+
/**
|
|
18
|
+
* Machine-readable classification of *why* an `ExecutionAction` was chosen.
|
|
19
|
+
* See `docs/EXECUTION_GATE.md` for the full decision table.
|
|
20
|
+
*/
|
|
21
|
+
export type ExecutionReason = "complete" | "truncated" | "stream_incomplete" | "schema_invalid" | "malformed" | "resource_limit" | "provider_error" | "content_filtered" | "unknown";
|
|
22
|
+
/**
|
|
23
|
+
* Why a decision came out the way it did - observability, not a second
|
|
24
|
+
* decision input. Every field here is read-only, derived state already held
|
|
25
|
+
* elsewhere (`ToolCallState`, the stream-level `DecisionContext`); nothing
|
|
26
|
+
* on this object ever feeds back into `decideExecution()`'s own logic, and
|
|
27
|
+
* changing what it reports can never change `action`/`executable`/`reason`.
|
|
28
|
+
*
|
|
29
|
+
* Deliberately excludes anything that would require new cross-layer
|
|
30
|
+
* plumbing to derive reliably (e.g. a received-chunk count - the parser
|
|
31
|
+
* only tracks cumulative bytes, not `push()` call counts, and adding that
|
|
32
|
+
* tracking purely to populate a metric here was judged not worth the
|
|
33
|
+
* coupling for this release).
|
|
34
|
+
*/
|
|
35
|
+
export interface DecisionEvidence {
|
|
36
|
+
/** Which provider adapter produced this call (`ToolCallState.provider`). */
|
|
37
|
+
readonly provider: ProviderName;
|
|
38
|
+
/**
|
|
39
|
+
* The provider's own, pre-normalization finish/stop reason string, when
|
|
40
|
+
* the stream-ending event carried one (e.g. `"length"`, `"max_output_tokens"`,
|
|
41
|
+
* `"content_filter"`). `undefined` when the stream never reported one, or
|
|
42
|
+
* reported one without a `providerReason` (e.g. a default `finish()` call
|
|
43
|
+
* with no `meta`).
|
|
44
|
+
*/
|
|
45
|
+
readonly providerReason?: string;
|
|
46
|
+
/** The normalized, library-level stream-end reason applied to this call. */
|
|
47
|
+
readonly streamEndReason: StreamEndReason;
|
|
48
|
+
/**
|
|
49
|
+
* Whether a real `provider_stream_end` reason was ever observed, as
|
|
50
|
+
* opposed to the neutral `"unknown"` default a gate reports before any
|
|
51
|
+
* stream-end signal has arrived at all. `true` here does NOT mean the
|
|
52
|
+
* reason was safe - a confirmed `"length"` still has `terminalConfirmed:
|
|
53
|
+
* true` - only that the stream's end state is genuinely known rather than
|
|
54
|
+
* merely unclassified or never observed.
|
|
55
|
+
*/
|
|
56
|
+
readonly terminalConfirmed: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the parser's root JSON container actually closed
|
|
59
|
+
* (`ToolCallState.parser.rootComplete`) - independent of whether that
|
|
60
|
+
* closure was genuine or reached via a safe-close repair, and independent
|
|
61
|
+
* of whether the stream-end reason makes it trustworthy. A syntactically
|
|
62
|
+
* complete value cut short by `length` has `structurallyComplete: true`
|
|
63
|
+
* and `parserExecutable: false` at the same time - that combination *is*
|
|
64
|
+
* the scenario this library exists to catch.
|
|
65
|
+
*/
|
|
66
|
+
readonly structurallyComplete: boolean;
|
|
67
|
+
/** `ToolCallState.parser.executable`, verbatim - the parser's own fail-closed verdict. */
|
|
68
|
+
readonly parserExecutable: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* `ToolCallState.schemaValid`, verbatim. `undefined` when no schema was
|
|
71
|
+
* registered for this tool, or the call never reached a structurally
|
|
72
|
+
* complete outcome.
|
|
73
|
+
*/
|
|
74
|
+
readonly schemaValid?: boolean;
|
|
75
|
+
/** Total bytes received for this call's argument stream (`ToolCallState.parser.receivedBytes`). */
|
|
76
|
+
readonly receivedBytes: number;
|
|
77
|
+
}
|
|
78
|
+
interface ExecutionDecisionCommon {
|
|
79
|
+
/** The coordinator's internal call identifier (see `ToolCallState.internalId`). */
|
|
80
|
+
readonly internalId: string;
|
|
81
|
+
readonly toolCallId?: string;
|
|
82
|
+
readonly toolIndex?: number;
|
|
83
|
+
readonly name?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Whatever was safely committed for this call, complete or not - present
|
|
86
|
+
* for both executable and non-executable decisions so a caller can see
|
|
87
|
+
* *what part* of a rejected/retried call was genuinely received (e.g. a
|
|
88
|
+
* `path` field that arrived before a `content` field got cut off).
|
|
89
|
+
* Never the source of truth for whether it's safe to act on - that's
|
|
90
|
+
* `action`/`executable`. Absent only when nothing was ever committed.
|
|
91
|
+
*/
|
|
92
|
+
readonly stableValue?: JsonValue;
|
|
93
|
+
/** This call's own parser diagnostics, verbatim (`ToolCallState.parser.diagnostics`). */
|
|
94
|
+
readonly parserDiagnostics: readonly Diagnostic[];
|
|
95
|
+
/** Coordinator-level diagnostics attributable to this call, verbatim. */
|
|
96
|
+
readonly coordinatorDiagnostics: readonly CoordinatorDiagnostic[];
|
|
97
|
+
/**
|
|
98
|
+
* Why this decision came out the way it did. See `DecisionEvidence` -
|
|
99
|
+
* always present, purely observational, never a second source of truth
|
|
100
|
+
* for `action`/`executable`/`reason`.
|
|
101
|
+
*/
|
|
102
|
+
readonly evidence: DecisionEvidence;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The one and only shape a decision can have when `action === "execute"`.
|
|
106
|
+
* `value` is a real, present `JsonValue` here - never `undefined`, never
|
|
107
|
+
* optional - because this is the single positive case: everything else in
|
|
108
|
+
* the gate exists to rule this out unless it's genuinely earned.
|
|
109
|
+
*/
|
|
110
|
+
export interface ExecuteDecision extends ExecutionDecisionCommon {
|
|
111
|
+
readonly action: "execute";
|
|
112
|
+
readonly executable: true;
|
|
113
|
+
readonly reason: "complete";
|
|
114
|
+
readonly value: JsonValue;
|
|
115
|
+
/**
|
|
116
|
+
* Narrowed to required here (unlike the inherited `name?: string`):
|
|
117
|
+
* the coordinator only ever transitions a call to `status: "complete"`
|
|
118
|
+
* when `name` is defined (see `DefaultToolCallStreamCoordinator.finishCall`
|
|
119
|
+
* - a call with no name is forced to `"invalid"` instead), so every
|
|
120
|
+
* `ExecuteDecision` genuinely has one. Encoding that here means
|
|
121
|
+
* `tools[decision.name](decision.value)` type-checks directly after
|
|
122
|
+
* narrowing on `action === "execute"`, with no non-null assertion needed.
|
|
123
|
+
*/
|
|
124
|
+
readonly name: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Every other outcome. `value` does not exist on this type at all (not
|
|
128
|
+
* `undefined` - absent) - TypeScript itself refuses code that reads a
|
|
129
|
+
* "final executable value" off a call the gate did not clear for execution.
|
|
130
|
+
*/
|
|
131
|
+
export interface NonExecutableDecision extends ExecutionDecisionCommon {
|
|
132
|
+
readonly action: "retry" | "reject";
|
|
133
|
+
readonly executable: false;
|
|
134
|
+
readonly reason: Exclude<ExecutionReason, "complete">;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* `ExecuteDecision | NonExecutableDecision` - a discriminated union on
|
|
138
|
+
* `action` (and redundantly on `executable`, for callers who prefer that
|
|
139
|
+
* check). Narrowing on either field gives you the right shape:
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* if (decision.action === "execute") {
|
|
143
|
+
* await tools[decision.name](decision.value); // JsonValue, not JsonValue|undefined
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export type ExecutionDecision = ExecuteDecision | NonExecutableDecision;
|
|
148
|
+
export interface ToolCallExecutionGateFinalResult {
|
|
149
|
+
/** One decision per tool call the coordinator ever created. */
|
|
150
|
+
readonly decisions: readonly ExecutionDecision[];
|
|
151
|
+
/**
|
|
152
|
+
* The full, unfiltered coordinator diagnostics list (same as
|
|
153
|
+
* `coordinator.snapshot().diagnostics`) - includes diagnostics with no
|
|
154
|
+
* associated call, e.g. `E_COORDINATOR_LIMIT_CALLS` fires for a call that
|
|
155
|
+
* hit the concurrent-call limit before a `ToolCallState` could even be
|
|
156
|
+
* created for it, so it can never appear in `decisions`.
|
|
157
|
+
*/
|
|
158
|
+
readonly diagnostics: readonly CoordinatorDiagnostic[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* High-level fail-closed execution decision layer built on top of
|
|
162
|
+
* `ToolCallStreamCoordinator`. Answers one question per tool call: is it
|
|
163
|
+
* safe to execute right now? Callers never need to touch parser lexical
|
|
164
|
+
* state, coordinator event mechanics, or JSON Pointer paths - push provider
|
|
165
|
+
* events in, read `ExecutionDecision`s out.
|
|
166
|
+
*/
|
|
167
|
+
export interface ToolCallExecutionGate {
|
|
168
|
+
push(event: NormalizedToolStreamEvent): CoordinatorPushResult;
|
|
169
|
+
/**
|
|
170
|
+
* In-flight view. Every decision here is `"retry"` or `"reject"` -
|
|
171
|
+
* `"execute"` is only ever returned once the stream has genuinely
|
|
172
|
+
* finished (see `finish()`), since schema validity and prefix-safety are
|
|
173
|
+
* both only meaningful once a call has settled.
|
|
174
|
+
*/
|
|
175
|
+
snapshot(): readonly ExecutionDecision[];
|
|
176
|
+
/** Drains the underlying coordinator's raw event queue, for advanced/UI consumers. */
|
|
177
|
+
drainEvents(): readonly ToolCallCoordinatorEvent[];
|
|
178
|
+
finish(meta?: {
|
|
179
|
+
reason?: StreamEndReason;
|
|
180
|
+
providerReason?: string;
|
|
181
|
+
}): ToolCallExecutionGateFinalResult;
|
|
182
|
+
}
|
|
183
|
+
export {};
|
|
184
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/gate/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEtG;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE7D;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,WAAW,GACX,mBAAmB,GACnB,gBAAgB,GAChB,WAAW,GACX,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,SAAS,CAAC;AAEd;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAEhC;;;;;;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AAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CACvD;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG,qBAAqB,CAAC;AAExE,MAAM,WAAW,gCAAgC;IAC/C,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAEjD;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACxD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,KAAK,EAAE,yBAAyB,GAAG,qBAAqB,CAAC;IAE9D;;;;;OAKG;IACH,QAAQ,IAAI,SAAS,iBAAiB,EAAE,CAAC;IAEzC,sFAAsF;IACtF,WAAW,IAAI,SAAS,wBAAwB,EAAE,CAAC;IAEnD,MAAM,CAAC,IAAI,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,gCAAgC,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/gate/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AiSdkExecutionGuard, ExecutionGuardOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @public (Experimental)
|
|
4
|
+
* Drop-in fail-closed execution guard for the Vercel AI SDK's `fullStream`.
|
|
5
|
+
* Composes `AiSdkStreamAdapter` with `createToolCallExecutionGate()` - same
|
|
6
|
+
* decision logic, same fail-closed guarantees, no new parser or coordinator.
|
|
7
|
+
* Does not depend on the `ai` package at runtime and does not import its
|
|
8
|
+
* types; `push()` accepts `unknown` and reads only the fields it needs.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const guard = createAiSdkExecutionGuard({
|
|
12
|
+
* schemas: {
|
|
13
|
+
* write_file: {
|
|
14
|
+
* type: "object",
|
|
15
|
+
* properties: { path: { type: "string" }, content: { type: "string" } },
|
|
16
|
+
* required: ["path", "content"],
|
|
17
|
+
* },
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* for await (const part of result.fullStream) {
|
|
22
|
+
* guard.push(part);
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const final = guard.finish();
|
|
26
|
+
* for (const decision of final.decisions) {
|
|
27
|
+
* if (decision.action === "execute") {
|
|
28
|
+
* await tools[decision.name](decision.value);
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Equivalent to composing the low-level API yourself:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const gate = createToolCallExecutionGate(undefined, undefined, schemas);
|
|
37
|
+
* const adapter = new AiSdkStreamAdapter();
|
|
38
|
+
* for await (const part of result.fullStream) {
|
|
39
|
+
* for (const normalized of adapter.push(part)) gate.push(normalized);
|
|
40
|
+
* }
|
|
41
|
+
* const final = gate.finish();
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Both APIs remain public; use this one for the common case, the low-level
|
|
45
|
+
* one when you need direct access to the adapter or gate instance.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createAiSdkExecutionGuard(options?: ExecutionGuardOptions): AiSdkExecutionGuard;
|
|
48
|
+
//# sourceMappingURL=ai-sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../src/guard/ai-sdk.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAE9F"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AiSdkStreamAdapter } from "../providers/ai-sdk.js";
|
|
2
|
+
import { createProviderExecutionGuard } from "./provider-guard.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public (Experimental)
|
|
5
|
+
* Drop-in fail-closed execution guard for the Vercel AI SDK's `fullStream`.
|
|
6
|
+
* Composes `AiSdkStreamAdapter` with `createToolCallExecutionGate()` - same
|
|
7
|
+
* decision logic, same fail-closed guarantees, no new parser or coordinator.
|
|
8
|
+
* Does not depend on the `ai` package at runtime and does not import its
|
|
9
|
+
* types; `push()` accepts `unknown` and reads only the fields it needs.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const guard = createAiSdkExecutionGuard({
|
|
13
|
+
* schemas: {
|
|
14
|
+
* write_file: {
|
|
15
|
+
* type: "object",
|
|
16
|
+
* properties: { path: { type: "string" }, content: { type: "string" } },
|
|
17
|
+
* required: ["path", "content"],
|
|
18
|
+
* },
|
|
19
|
+
* },
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* for await (const part of result.fullStream) {
|
|
23
|
+
* guard.push(part);
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* const final = guard.finish();
|
|
27
|
+
* for (const decision of final.decisions) {
|
|
28
|
+
* if (decision.action === "execute") {
|
|
29
|
+
* await tools[decision.name](decision.value);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Equivalent to composing the low-level API yourself:
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const gate = createToolCallExecutionGate(undefined, undefined, schemas);
|
|
38
|
+
* const adapter = new AiSdkStreamAdapter();
|
|
39
|
+
* for await (const part of result.fullStream) {
|
|
40
|
+
* for (const normalized of adapter.push(part)) gate.push(normalized);
|
|
41
|
+
* }
|
|
42
|
+
* const final = gate.finish();
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Both APIs remain public; use this one for the common case, the low-level
|
|
46
|
+
* one when you need direct access to the adapter or gate instance.
|
|
47
|
+
*/
|
|
48
|
+
export function createAiSdkExecutionGuard(options) {
|
|
49
|
+
return createProviderExecutionGuard(new AiSdkStreamAdapter(), options);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=ai-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../../src/guard/ai-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAGnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAA+B;IACvE,OAAO,4BAA4B,CAAC,IAAI,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ProviderStreamAdapter } from "../providers/adapter.js";
|
|
2
|
+
import { ExecutionGuard, ExecutionGuardOptions } from "./types.js";
|
|
3
|
+
export declare function createProviderExecutionGuard<TRawEvent>(adapter: ProviderStreamAdapter<TRawEvent>, options?: ExecutionGuardOptions): ExecutionGuard<TRawEvent>;
|
|
4
|
+
//# sourceMappingURL=provider-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-guard.d.ts","sourceRoot":"","sources":["../../src/guard/provider-guard.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnE,wBAAgB,4BAA4B,CAAC,SAAS,EACpD,OAAO,EAAE,qBAAqB,CAAC,SAAS,CAAC,EACzC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,cAAc,CAAC,SAAS,CAAC,CA0B3B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// createProviderExecutionGuard — internal composition helper.
|
|
3
|
+
//
|
|
4
|
+
// Not exported from the package root in this release. Every high-level
|
|
5
|
+
// per-provider guard (currently only createAiSdkExecutionGuard) is this
|
|
6
|
+
// function applied to one ProviderStreamAdapter instance - no duplicated
|
|
7
|
+
// state, no duplicated decision logic, no new parser or coordinator. Kept
|
|
8
|
+
// internal (rather than public) until a second provider guard actually
|
|
9
|
+
// needs it, per the "don't expose abstraction for its own sake" scoping
|
|
10
|
+
// this release deliberately holds to - promoting it to a public export is a
|
|
11
|
+
// non-breaking addition whenever that happens.
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
import { createToolCallExecutionGate } from "../gate/gate.js";
|
|
14
|
+
export function createProviderExecutionGuard(adapter, options) {
|
|
15
|
+
const gate = createToolCallExecutionGate(options?.limits, options?.parserOptions, options?.schemas);
|
|
16
|
+
return {
|
|
17
|
+
push(rawEvent) {
|
|
18
|
+
for (const normalized of adapter.push(rawEvent)) {
|
|
19
|
+
gate.push(normalized);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
snapshot() {
|
|
23
|
+
return gate.snapshot();
|
|
24
|
+
},
|
|
25
|
+
finish(meta) {
|
|
26
|
+
// If the provider stream already delivered its own terminal event
|
|
27
|
+
// through push() (the common case), the adapter is already
|
|
28
|
+
// `finished` and this is a no-op - meta is only consulted as a
|
|
29
|
+
// fail-closed backstop for a stream that ends without ever reporting
|
|
30
|
+
// why (see ProviderStreamAdapter.finish()'s own contract).
|
|
31
|
+
for (const normalized of adapter.finish(meta)) {
|
|
32
|
+
gate.push(normalized);
|
|
33
|
+
}
|
|
34
|
+
return gate.finish(meta);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=provider-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-guard.js","sourceRoot":"","sources":["../../src/guard/provider-guard.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8DAA8D;AAC9D,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,yEAAyE;AACzE,0EAA0E;AAC1E,uEAAuE;AACvE,wEAAwE;AACxE,4EAA4E;AAC5E,+CAA+C;AAC/C,8EAA8E;AAE9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAM9D,MAAM,UAAU,4BAA4B,CAC1C,OAAyC,EACzC,OAA+B;IAE/B,MAAM,IAAI,GAAG,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAEpG,OAAO;QACL,IAAI,CAAC,QAAmB;YACtB,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAChD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QAED,QAAQ;YACN,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;QAED,MAAM,CAAC,IAA4D;YACjE,kEAAkE;YAClE,2DAA2D;YAC3D,+DAA+D;YAC/D,qEAAqE;YACrE,2DAA2D;YAC3D,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACxB,CAAC;YACD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { StreamEndReason } from "../coordinator/protocol.js";
|
|
2
|
+
import { CoordinatorLimits, JsonSchemaLike } from "../coordinator/types.js";
|
|
3
|
+
import { ToolCallExecutionGateFinalResult, ExecutionDecision } from "../gate/types.js";
|
|
4
|
+
import { ParserOptions } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* High-level, provider-agnostic execution guard: composes a
|
|
7
|
+
* `ProviderStreamAdapter` with a `ToolCallExecutionGate` behind three
|
|
8
|
+
* methods. `push()`/`snapshot()`/`finish()` mirror the underlying gate's own
|
|
9
|
+
* shape exactly - this is a thinner call surface over the same object, not a
|
|
10
|
+
* parallel implementation with its own state or decision logic.
|
|
11
|
+
*/
|
|
12
|
+
export interface ExecutionGuard<TRawEvent = unknown> {
|
|
13
|
+
/** Feed one raw provider event (e.g. one `fullStream` part) through the adapter into the gate. */
|
|
14
|
+
push(rawEvent: TRawEvent): void;
|
|
15
|
+
/**
|
|
16
|
+
* In-flight view of every call's current decision. As with the underlying
|
|
17
|
+
* gate, every decision here is `"retry"` or `"reject"` - `"execute"` is
|
|
18
|
+
* only ever returned from `finish()`.
|
|
19
|
+
*/
|
|
20
|
+
snapshot(): readonly ExecutionDecision[];
|
|
21
|
+
/**
|
|
22
|
+
* Signals stream completion and returns the final decision for every tool
|
|
23
|
+
* call the stream ever produced. Safe to call even if the underlying
|
|
24
|
+
* provider stream already delivered its own terminal event through
|
|
25
|
+
* `push()` - `meta` is only used as a fallback for a stream that ends
|
|
26
|
+
* without ever reporting why.
|
|
27
|
+
*/
|
|
28
|
+
finish(meta?: {
|
|
29
|
+
reason?: StreamEndReason;
|
|
30
|
+
providerReason?: string;
|
|
31
|
+
}): ToolCallExecutionGateFinalResult;
|
|
32
|
+
}
|
|
33
|
+
/** Options accepted by every high-level provider execution guard factory. */
|
|
34
|
+
export interface ExecutionGuardOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Optional JSON Schema (draft-07) per tool name - same option
|
|
37
|
+
* `createToolCallExecutionGate()`/`createToolCallStreamCoordinator()`
|
|
38
|
+
* accept as their third constructor argument.
|
|
39
|
+
*/
|
|
40
|
+
schemas?: Record<string, JsonSchemaLike>;
|
|
41
|
+
/** Coordinator-level limits (concurrent tool calls, tool name size, etc.). */
|
|
42
|
+
limits?: Partial<CoordinatorLimits>;
|
|
43
|
+
/** Per-call parser configuration (resource limits, repairs). */
|
|
44
|
+
parserOptions?: ParserOptions;
|
|
45
|
+
}
|
|
46
|
+
/** A guard specialized for the Vercel AI SDK's `fullStream` part shape. See `createAiSdkExecutionGuard`. */
|
|
47
|
+
export type AiSdkExecutionGuard = ExecutionGuard<unknown>;
|
|
48
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,SAAS,GAAG,OAAO;IACjD,kGAAkG;IAClG,IAAI,CAAC,QAAQ,EAAE,SAAS,GAAG,IAAI,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,IAAI,SAAS,iBAAiB,EAAE,CAAC;IAEzC;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,gCAAgC,CAAC;CACxG;AAED,6EAA6E;AAC7E,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEzC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEpC,gEAAgE;IAChE,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,4GAA4G;AAC5G,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,25 @@ export { DiagnosticCode } from "./diagnostics/codes.js";
|
|
|
11
11
|
* Creates a stream coordinator for mapping overlapping multi-tool streams.
|
|
12
12
|
*/
|
|
13
13
|
export { createToolCallStreamCoordinator } from "./coordinator/coordinator.js";
|
|
14
|
-
export type { ToolCallStreamCoordinator, ToolCallState, JsonSchemaLike, } from "./coordinator/types.js";
|
|
15
|
-
export type { NormalizedToolStreamEvent } from "./coordinator/protocol.js";
|
|
14
|
+
export type { ToolCallStreamCoordinator, ToolCallState, JsonSchemaLike, CoordinatorLimits, CoordinatorDiagnostic, } from "./coordinator/types.js";
|
|
15
|
+
export type { NormalizedToolStreamEvent, ProviderName } from "./coordinator/protocol.js";
|
|
16
|
+
export { CONTENT_FILTERED_DIAGNOSTIC_CODE } from "./coordinator/diagnostic-codes.js";
|
|
17
|
+
/**
|
|
18
|
+
* @public (Stable)
|
|
19
|
+
* Fail-closed execution-decision layer built on top of the coordinator.
|
|
20
|
+
* Answers one question per tool call: is it safe to execute right now?
|
|
21
|
+
* See docs/EXECUTION_GATE.md.
|
|
22
|
+
*/
|
|
23
|
+
export { createToolCallExecutionGate } from "./gate/gate.js";
|
|
24
|
+
export type { ToolCallExecutionGate, ToolCallExecutionGateFinalResult, ExecutionDecision, ExecuteDecision, NonExecutableDecision, ExecutionAction, ExecutionReason, DecisionEvidence, } from "./gate/types.js";
|
|
25
|
+
/**
|
|
26
|
+
* @public (Experimental)
|
|
27
|
+
* Drop-in fail-closed execution guard for the Vercel AI SDK's `fullStream`.
|
|
28
|
+
* Composes `AiSdkStreamAdapter` and `createToolCallExecutionGate()` - see
|
|
29
|
+
* `docs/EXECUTION_GATE.md#high-level-guards`.
|
|
30
|
+
*/
|
|
31
|
+
export { createAiSdkExecutionGuard } from "./guard/ai-sdk.js";
|
|
32
|
+
export type { ExecutionGuard, AiSdkExecutionGuard, ExecutionGuardOptions } from "./guard/types.js";
|
|
16
33
|
export type { ProviderStreamAdapter } from "./providers/adapter.js";
|
|
17
34
|
/**
|
|
18
35
|
* @public (Experimental)
|
|
@@ -24,4 +41,5 @@ export { OpenAICompatibleStreamAdapter } from "./providers/openai-compatible.js"
|
|
|
24
41
|
export { AnthropicStreamAdapter } from "./providers/anthropic.js";
|
|
25
42
|
export { GeminiStreamAdapter } from "./providers/gemini.js";
|
|
26
43
|
export { OpenRouterStreamAdapter } from "./providers/openrouter.js";
|
|
44
|
+
export { AiSdkStreamAdapter } from "./providers/ai-sdk.js";
|
|
27
45
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,YAAY,EAEV,qBAAqB,EACrB,aAAa,EAGb,UAAU,EACV,cAAc,EACd,WAAW,EAGX,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EAGnB,SAAS,EACT,UAAU,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,YAAY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,EACrB,eAAe,EACf,eAAe,EACf,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB;;;;;GAKG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGnG,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,23 @@ export { DiagnosticCode } from "./diagnostics/codes.js";
|
|
|
14
14
|
* Creates a stream coordinator for mapping overlapping multi-tool streams.
|
|
15
15
|
*/
|
|
16
16
|
export { createToolCallStreamCoordinator } from "./coordinator/coordinator.js";
|
|
17
|
+
export { CONTENT_FILTERED_DIAGNOSTIC_CODE } from "./coordinator/diagnostic-codes.js";
|
|
18
|
+
// Execution Safety Gate API
|
|
19
|
+
/**
|
|
20
|
+
* @public (Stable)
|
|
21
|
+
* Fail-closed execution-decision layer built on top of the coordinator.
|
|
22
|
+
* Answers one question per tool call: is it safe to execute right now?
|
|
23
|
+
* See docs/EXECUTION_GATE.md.
|
|
24
|
+
*/
|
|
25
|
+
export { createToolCallExecutionGate } from "./gate/gate.js";
|
|
26
|
+
// High-level execution guards
|
|
27
|
+
/**
|
|
28
|
+
* @public (Experimental)
|
|
29
|
+
* Drop-in fail-closed execution guard for the Vercel AI SDK's `fullStream`.
|
|
30
|
+
* Composes `AiSdkStreamAdapter` and `createToolCallExecutionGate()` - see
|
|
31
|
+
* `docs/EXECUTION_GATE.md#high-level-guards`.
|
|
32
|
+
*/
|
|
33
|
+
export { createAiSdkExecutionGuard } from "./guard/ai-sdk.js";
|
|
17
34
|
/**
|
|
18
35
|
* @public (Experimental)
|
|
19
36
|
* Provider adapters for various LLM network shapes.
|
|
@@ -24,4 +41,5 @@ export { OpenAICompatibleStreamAdapter } from "./providers/openai-compatible.js"
|
|
|
24
41
|
export { AnthropicStreamAdapter } from "./providers/anthropic.js";
|
|
25
42
|
export { GeminiStreamAdapter } from "./providers/gemini.js";
|
|
26
43
|
export { OpenRouterStreamAdapter } from "./providers/openrouter.js";
|
|
44
|
+
export { AiSdkStreamAdapter } from "./providers/ai-sdk.js";
|
|
27
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gCAAgC;AAChC,8EAA8E;AAE9E;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiC3C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,kBAAkB;AAClB;;;GAGG;AACH,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gCAAgC;AAChC,8EAA8E;AAE9E;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiC3C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,kBAAkB;AAClB;;;GAGG;AACH,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAS/E,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAErF,4BAA4B;AAC5B;;;;;GAKG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAY7D,8BAA8B;AAC9B;;;;;GAKG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAM9D;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/lexer/scanner.d.ts
CHANGED
|
@@ -61,7 +61,6 @@ export declare class Scanner {
|
|
|
61
61
|
type: "string" | "number" | "literal" | "unicode_escape" | "surrogate" | "none";
|
|
62
62
|
buffer: string;
|
|
63
63
|
byteStart: number;
|
|
64
|
-
isKey: boolean;
|
|
65
64
|
};
|
|
66
65
|
/**
|
|
67
66
|
* Check numberBuffer against the parts of RFC 8259's number grammar that
|
|
@@ -95,7 +94,6 @@ export declare class Scanner {
|
|
|
95
94
|
private processSurrogatePending;
|
|
96
95
|
private processNumber;
|
|
97
96
|
private processLiteral;
|
|
98
|
-
private processTrailingWhitespace;
|
|
99
97
|
private beginString;
|
|
100
98
|
private beginNumber;
|
|
101
99
|
private beginLiteral;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../src/lexer/scanner.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO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AG,WAAW,GAAG,MAAM,CAAC;QAChF,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB;IA2CD;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IA2B1B;;;;;;;;;;OAUG;IACH,cAAc,IAAI,WAAW,GAAG,SAAS,GAAG,WAAW;IAuBvD;;;OAGG;IACH,eAAe,IAAI,OAAO;IA8B1B,OAAO,CAAC,iBAAiB;IAuCzB,OAAO,CAAC,aAAa;IAiErB,OAAO,CAAC,aAAa;IA6CrB,OAAO,CAAC,oBAAoB;IA8D5B,OAAO,CAAC,uBAAuB;IAqC/B,OAAO,CAAC,aAAa;IAiHrB,OAAO,CAAC,cAAc;IAwDtB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,YAAY;IA2BpB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,cAAc;CAWvB"}
|
package/dist/lexer/scanner.js
CHANGED
|
@@ -103,12 +103,6 @@ export class Scanner {
|
|
|
103
103
|
case ScannerState.LiteralNull:
|
|
104
104
|
this.processLiteral(ch, byteOffset, charByteLength);
|
|
105
105
|
break;
|
|
106
|
-
case ScannerState.TrailingWhitespace:
|
|
107
|
-
this.processTrailingWhitespace(ch, byteOffset);
|
|
108
|
-
break;
|
|
109
|
-
case ScannerState.TrailingData:
|
|
110
|
-
// Consume all trailing data silently — diagnostic was already emitted
|
|
111
|
-
break;
|
|
112
106
|
case ScannerState.Invalid:
|
|
113
107
|
case ScannerState.Finished:
|
|
114
108
|
// No-op — terminal states
|
|
@@ -155,21 +149,18 @@ export class Scanner {
|
|
|
155
149
|
type: this.stringIsKey ? "object_key" : "string",
|
|
156
150
|
buffer: this.stringBuffer,
|
|
157
151
|
byteStart: this.stringByteStart,
|
|
158
|
-
isKey: this.stringIsKey,
|
|
159
152
|
};
|
|
160
153
|
case ScannerState.UnicodeEscape:
|
|
161
154
|
return {
|
|
162
155
|
type: "unicode_escape",
|
|
163
156
|
buffer: this.unicodeHexBuffer,
|
|
164
157
|
byteStart: this.stringByteStart,
|
|
165
|
-
isKey: this.stringIsKey,
|
|
166
158
|
};
|
|
167
159
|
case ScannerState.UnicodeSurrogatePending:
|
|
168
160
|
return {
|
|
169
161
|
type: "surrogate",
|
|
170
162
|
buffer: this.stringBuffer,
|
|
171
163
|
byteStart: this.stringByteStart,
|
|
172
|
-
isKey: this.stringIsKey,
|
|
173
164
|
};
|
|
174
165
|
case ScannerState.NumberInteger:
|
|
175
166
|
case ScannerState.NumberFraction:
|
|
@@ -179,7 +170,6 @@ export class Scanner {
|
|
|
179
170
|
type: "number",
|
|
180
171
|
buffer: this.numberBuffer,
|
|
181
172
|
byteStart: this.numberByteStart,
|
|
182
|
-
isKey: false,
|
|
183
173
|
};
|
|
184
174
|
case ScannerState.LiteralTrue:
|
|
185
175
|
case ScannerState.LiteralFalse:
|
|
@@ -188,10 +178,9 @@ export class Scanner {
|
|
|
188
178
|
type: "literal",
|
|
189
179
|
buffer: this.literalTarget.slice(0, this.literalIndex),
|
|
190
180
|
byteStart: this.literalByteStart,
|
|
191
|
-
isKey: false,
|
|
192
181
|
};
|
|
193
182
|
default:
|
|
194
|
-
return { type: "none", buffer: "", byteStart: 0
|
|
183
|
+
return { type: "none", buffer: "", byteStart: 0 };
|
|
195
184
|
}
|
|
196
185
|
}
|
|
197
186
|
/**
|
|
@@ -245,7 +234,7 @@ export class Scanner {
|
|
|
245
234
|
return "invalid";
|
|
246
235
|
}
|
|
247
236
|
this.emitToken(TokenType.Number, this.numberBuffer, this.numberByteStart, this.currentByteOffset + 1);
|
|
248
|
-
this.state = ScannerState.
|
|
237
|
+
this.state = ScannerState.Finished;
|
|
249
238
|
return "finalized";
|
|
250
239
|
}
|
|
251
240
|
}
|
|
@@ -266,7 +255,7 @@ export class Scanner {
|
|
|
266
255
|
? TokenType.False
|
|
267
256
|
: TokenType.Null;
|
|
268
257
|
this.emitToken(type, this.literalTarget, this.literalByteStart, this.currentByteOffset + 1);
|
|
269
|
-
this.state = ScannerState.
|
|
258
|
+
this.state = ScannerState.Finished;
|
|
270
259
|
return true;
|
|
271
260
|
}
|
|
272
261
|
}
|
|
@@ -601,13 +590,6 @@ export class Scanner {
|
|
|
601
590
|
this.state = ScannerState.Invalid;
|
|
602
591
|
}
|
|
603
592
|
}
|
|
604
|
-
processTrailingWhitespace(ch, byteOffset) {
|
|
605
|
-
if (isWhitespace(ch))
|
|
606
|
-
return;
|
|
607
|
-
// Non-whitespace after root value
|
|
608
|
-
this.emitDiagnostic(DiagnosticCode.E_TRAILING_DATA, "error", byteOffset, `Unexpected data after root JSON value: ${JSON.stringify(ch)}`, false);
|
|
609
|
-
this.state = ScannerState.TrailingData;
|
|
610
|
-
}
|
|
611
593
|
// -----------------------------------------------------------------------
|
|
612
594
|
// Helpers
|
|
613
595
|
// -----------------------------------------------------------------------
|