prefix-safe-json 0.1.0 → 0.2.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.
Files changed (134) hide show
  1. package/README.md +57 -3
  2. package/dist/coordinator/coordinator.d.ts +53 -0
  3. package/dist/coordinator/coordinator.d.ts.map +1 -0
  4. package/dist/coordinator/coordinator.js +477 -0
  5. package/dist/coordinator/coordinator.js.map +1 -0
  6. package/dist/coordinator/diagnostic-codes.d.ts +37 -0
  7. package/dist/coordinator/diagnostic-codes.d.ts.map +1 -0
  8. package/dist/coordinator/diagnostic-codes.js +48 -0
  9. package/dist/coordinator/diagnostic-codes.js.map +1 -0
  10. package/dist/coordinator/protocol.d.ts +62 -0
  11. package/dist/coordinator/protocol.d.ts.map +1 -0
  12. package/dist/coordinator/protocol.js +2 -0
  13. package/dist/coordinator/protocol.js.map +1 -0
  14. package/dist/coordinator/types.d.ts +104 -0
  15. package/dist/coordinator/types.d.ts.map +1 -0
  16. package/dist/coordinator/types.js +7 -0
  17. package/dist/coordinator/types.js.map +1 -0
  18. package/dist/diagnostics/codes.d.ts +24 -0
  19. package/dist/diagnostics/codes.d.ts.map +1 -0
  20. package/dist/diagnostics/codes.js +28 -0
  21. package/dist/diagnostics/codes.js.map +1 -0
  22. package/dist/diagnostics/factory.d.ts +8 -0
  23. package/dist/diagnostics/factory.d.ts.map +1 -0
  24. package/dist/diagnostics/factory.js +17 -0
  25. package/dist/diagnostics/factory.js.map +1 -0
  26. package/dist/gate/decide.d.ts +27 -0
  27. package/dist/gate/decide.d.ts.map +1 -0
  28. package/dist/gate/decide.js +179 -0
  29. package/dist/gate/decide.js.map +1 -0
  30. package/dist/gate/gate.d.ts +25 -0
  31. package/dist/gate/gate.d.ts.map +1 -0
  32. package/dist/gate/gate.js +96 -0
  33. package/dist/gate/gate.js.map +1 -0
  34. package/dist/gate/types.d.ts +184 -0
  35. package/dist/gate/types.d.ts.map +1 -0
  36. package/dist/gate/types.js +2 -0
  37. package/dist/gate/types.js.map +1 -0
  38. package/dist/grammar/frame.d.ts +58 -0
  39. package/dist/grammar/frame.d.ts.map +1 -0
  40. package/dist/grammar/frame.js +87 -0
  41. package/dist/grammar/frame.js.map +1 -0
  42. package/dist/grammar/pointer.d.ts +10 -0
  43. package/dist/grammar/pointer.d.ts.map +1 -0
  44. package/dist/grammar/pointer.js +20 -0
  45. package/dist/grammar/pointer.js.map +1 -0
  46. package/dist/grammar/stack.d.ts +73 -0
  47. package/dist/grammar/stack.d.ts.map +1 -0
  48. package/dist/grammar/stack.js +168 -0
  49. package/dist/grammar/stack.js.map +1 -0
  50. package/dist/guard/ai-sdk.d.ts +48 -0
  51. package/dist/guard/ai-sdk.d.ts.map +1 -0
  52. package/dist/guard/ai-sdk.js +51 -0
  53. package/dist/guard/ai-sdk.js.map +1 -0
  54. package/dist/guard/provider-guard.d.ts +4 -0
  55. package/dist/guard/provider-guard.d.ts.map +1 -0
  56. package/dist/guard/provider-guard.js +38 -0
  57. package/dist/guard/provider-guard.js.map +1 -0
  58. package/dist/guard/types.d.ts +48 -0
  59. package/dist/guard/types.d.ts.map +1 -0
  60. package/dist/guard/types.js +2 -0
  61. package/dist/guard/types.js.map +1 -0
  62. package/dist/index.d.ts +85 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +99 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/lexer/scanner.d.ts +106 -0
  67. package/dist/lexer/scanner.d.ts.map +1 -0
  68. package/dist/lexer/scanner.js +658 -0
  69. package/dist/lexer/scanner.js.map +1 -0
  70. package/dist/lexer/states.d.ts +31 -0
  71. package/dist/lexer/states.d.ts.map +1 -0
  72. package/dist/lexer/states.js +35 -0
  73. package/dist/lexer/states.js.map +1 -0
  74. package/dist/lexer/tokens.d.ts +22 -0
  75. package/dist/lexer/tokens.d.ts.map +1 -0
  76. package/dist/lexer/tokens.js +22 -0
  77. package/dist/lexer/tokens.js.map +1 -0
  78. package/dist/limits.d.ts +14 -0
  79. package/dist/limits.d.ts.map +1 -0
  80. package/dist/limits.js +23 -0
  81. package/dist/limits.js.map +1 -0
  82. package/dist/parser.d.ts +6 -0
  83. package/dist/parser.d.ts.map +1 -0
  84. package/dist/parser.js +922 -0
  85. package/dist/parser.js.map +1 -0
  86. package/dist/providers/adapter.d.ts +10 -0
  87. package/dist/providers/adapter.d.ts.map +1 -0
  88. package/dist/providers/adapter.js +2 -0
  89. package/dist/providers/adapter.js.map +1 -0
  90. package/dist/providers/ai-sdk.d.ts +63 -0
  91. package/dist/providers/ai-sdk.d.ts.map +1 -0
  92. package/dist/providers/ai-sdk.js +240 -0
  93. package/dist/providers/ai-sdk.js.map +1 -0
  94. package/dist/providers/anthropic.d.ts +45 -0
  95. package/dist/providers/anthropic.d.ts.map +1 -0
  96. package/dist/providers/anthropic.js +112 -0
  97. package/dist/providers/anthropic.js.map +1 -0
  98. package/dist/providers/gemini.d.ts +31 -0
  99. package/dist/providers/gemini.d.ts.map +1 -0
  100. package/dist/providers/gemini.js +94 -0
  101. package/dist/providers/gemini.js.map +1 -0
  102. package/dist/providers/openai-compatible.d.ts +33 -0
  103. package/dist/providers/openai-compatible.d.ts.map +1 -0
  104. package/dist/providers/openai-compatible.js +160 -0
  105. package/dist/providers/openai-compatible.js.map +1 -0
  106. package/dist/providers/openai.d.ts +55 -0
  107. package/dist/providers/openai.d.ts.map +1 -0
  108. package/dist/providers/openai.js +263 -0
  109. package/dist/providers/openai.js.map +1 -0
  110. package/dist/providers/openrouter.d.ts +35 -0
  111. package/dist/providers/openrouter.d.ts.map +1 -0
  112. package/dist/providers/openrouter.js +55 -0
  113. package/dist/providers/openrouter.js.map +1 -0
  114. package/dist/semantic/builder.d.ts +55 -0
  115. package/dist/semantic/builder.d.ts.map +1 -0
  116. package/dist/semantic/builder.js +140 -0
  117. package/dist/semantic/builder.js.map +1 -0
  118. package/dist/semantic/events.d.ts +2 -0
  119. package/dist/semantic/events.d.ts.map +1 -0
  120. package/dist/semantic/events.js +5 -0
  121. package/dist/semantic/events.js.map +1 -0
  122. package/dist/semantic/snapshot.d.ts +56 -0
  123. package/dist/semantic/snapshot.d.ts.map +1 -0
  124. package/dist/semantic/snapshot.js +230 -0
  125. package/dist/semantic/snapshot.js.map +1 -0
  126. package/dist/types.d.ts +156 -0
  127. package/dist/types.d.ts.map +1 -0
  128. package/dist/types.js +5 -0
  129. package/dist/types.js.map +1 -0
  130. package/dist/utf8/decoder.d.ts +53 -0
  131. package/dist/utf8/decoder.d.ts.map +1 -0
  132. package/dist/utf8/decoder.js +323 -0
  133. package/dist/utf8/decoder.js.map +1 -0
  134. package/package.json +2 -1
@@ -0,0 +1,168 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Grammar Stack — tracks nested JSON container state
3
+ // ---------------------------------------------------------------------------
4
+ import { createObjectFrame, createArrayFrame } from "./frame.js";
5
+ import { appendPointer } from "./pointer.js";
6
+ import { DiagnosticCode } from "../diagnostics/codes.js";
7
+ import { createDiagnostic } from "../diagnostics/factory.js";
8
+ /**
9
+ * Manages the stack of open JSON containers.
10
+ * Handles object/array nesting, expectations, and duplicate key detection.
11
+ */
12
+ export class GrammarStack {
13
+ stack = [];
14
+ diagnostics = [];
15
+ hasDuplicateKey = false;
16
+ maxDepth;
17
+ constructor(maxDepth) {
18
+ this.maxDepth = maxDepth;
19
+ }
20
+ /** Current depth (number of open containers). */
21
+ get depth() {
22
+ return this.stack.length;
23
+ }
24
+ /** Whether any duplicate key has been seen. */
25
+ get hasDuplicate() {
26
+ return this.hasDuplicateKey;
27
+ }
28
+ /** Get the current (top) frame, or undefined if empty. */
29
+ get current() {
30
+ return this.stack[this.stack.length - 1];
31
+ }
32
+ /**
33
+ * Push a new object container.
34
+ * Returns the frame, or null if depth limit exceeded.
35
+ */
36
+ pushObject(byteStart) {
37
+ if (this.stack.length >= this.maxDepth) {
38
+ this.diagnostics.push(createDiagnostic(DiagnosticCode.E_LIMIT_DEPTH, "fatal", byteStart, `Maximum nesting depth ${this.maxDepth} exceeded`, false));
39
+ return null;
40
+ }
41
+ const parent = this.current ?? null;
42
+ const frame = createObjectFrame(parent, this.currentSegment(), byteStart);
43
+ this.stack.push(frame);
44
+ return frame;
45
+ }
46
+ /**
47
+ * Push a new array container.
48
+ * Returns the frame, or null if depth limit exceeded.
49
+ */
50
+ pushArray(byteStart) {
51
+ if (this.stack.length >= this.maxDepth) {
52
+ this.diagnostics.push(createDiagnostic(DiagnosticCode.E_LIMIT_DEPTH, "fatal", byteStart, `Maximum nesting depth ${this.maxDepth} exceeded`, false));
53
+ return null;
54
+ }
55
+ const parent = this.current ?? null;
56
+ const frame = createArrayFrame(parent, this.currentSegment(), byteStart);
57
+ this.stack.push(frame);
58
+ return frame;
59
+ }
60
+ /**
61
+ * Pop the current container.
62
+ * Returns the popped frame.
63
+ */
64
+ pop() {
65
+ return this.stack.pop();
66
+ }
67
+ /**
68
+ * Register an object key. Returns true if the key is new.
69
+ * If duplicate, emits diagnostic and returns false.
70
+ */
71
+ registerObjectKey(key, byteOffset) {
72
+ const frame = this.current;
73
+ if (!frame || frame.containerType !== "object" || !frame.seenKeys) {
74
+ return false;
75
+ }
76
+ if (frame.seenKeys.has(key)) {
77
+ this.hasDuplicateKey = true;
78
+ this.diagnostics.push(createDiagnostic(DiagnosticCode.E_DUPLICATE_KEY, "error", byteOffset, `Duplicate object key: ${JSON.stringify(key)}`, false, frame.path));
79
+ return false;
80
+ }
81
+ frame.seenKeys.add(key);
82
+ frame.currentKey = key;
83
+ return true;
84
+ }
85
+ /**
86
+ * Get the JSON Pointer path for where the next value will go.
87
+ */
88
+ currentValuePath() {
89
+ const frame = this.current;
90
+ if (!frame)
91
+ return "";
92
+ if (frame.containerType === "object") {
93
+ if (frame.currentKey !== undefined) {
94
+ return appendPointer(frame.path, frame.currentKey);
95
+ }
96
+ return frame.path;
97
+ }
98
+ // array
99
+ return appendPointer(frame.path, frame.nextArrayIndex);
100
+ }
101
+ /**
102
+ * The key/index that would lead from the current frame to its next child,
103
+ * without flattening it into a full path string. Same underlying value
104
+ * currentValuePath() uses; kept as a raw segment so a newly-pushed child
105
+ * frame can capture it in O(1) and defer the expensive path-string join
106
+ * (see grammar/frame.ts) until something actually reads `.path`.
107
+ */
108
+ currentSegment() {
109
+ const frame = this.current;
110
+ if (!frame)
111
+ return null;
112
+ if (frame.containerType === "object") {
113
+ return frame.currentKey !== undefined ? frame.currentKey : null;
114
+ }
115
+ return frame.nextArrayIndex;
116
+ }
117
+ /**
118
+ * Advance the array index after an element value is committed.
119
+ */
120
+ advanceArrayIndex() {
121
+ const frame = this.current;
122
+ if (frame && frame.containerType === "array") {
123
+ frame.nextArrayIndex++;
124
+ }
125
+ }
126
+ /**
127
+ * Take accumulated diagnostics and clear.
128
+ */
129
+ takeDiagnostics() {
130
+ const result = this.diagnostics;
131
+ this.diagnostics = [];
132
+ return result;
133
+ }
134
+ /**
135
+ * Check if the stack is empty (no open containers).
136
+ */
137
+ isEmpty() {
138
+ return this.stack.length === 0;
139
+ }
140
+ /**
141
+ * Get all frames (for snapshot/pending info).
142
+ */
143
+ getFrames() {
144
+ return this.stack;
145
+ }
146
+ /**
147
+ * Determine if all open containers can be safely closed by just appending '}' or ']'.
148
+ * This is true if no container is waiting for a colon or a value.
149
+ */
150
+ canSafelyCloseAll() {
151
+ for (const frame of this.stack) {
152
+ if (frame.containerType === "object") {
153
+ if (frame.objectExpectation === "colon" ||
154
+ frame.objectExpectation === "value" ||
155
+ frame.objectExpectation === "key_after_comma") {
156
+ return false; // Missing colon or value or key
157
+ }
158
+ }
159
+ else {
160
+ if (frame.arrayExpectation === "value_after_comma") {
161
+ return false; // Missing value after comma
162
+ }
163
+ }
164
+ }
165
+ return true;
166
+ }
167
+ }
168
+ //# sourceMappingURL=stack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../src/grammar/stack.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,qDAAqD;AACrD,8EAA8E;AAG9E,OAAO,EAAE,i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zB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,eAAe;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,iBAAiB;QACf,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC,aAAa,KAAK,QAAQ,EAAE,CAAC;gBACrC,IACE,KAAK,CAAC,iBAAiB,KAAK,OAAO;oBACnC,KAAK,CAAC,iBAAiB,KAAK,OAAO;oBACnC,KAAK,CAAC,iBAAiB,KAAK,iBAAiB,EAC7C,CAAC;oBACD,OAAO,KAAK,CAAC,CAAC,gCAAgC;gBAChD,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,KAAK,CAAC,gBAAgB,KAAK,mBAAmB,EAAE,CAAC;oBACnD,OAAO,KAAK,CAAC,CAAC,4BAA4B;gBAC5C,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ import { AiSdkExecutionGuard, ExecutionGuardOptions } from "./types.js";
2
+ /**
3
+ * @public (Stable)
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 (Stable)
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @public (Stable)
3
+ * Creates a new Incremental JSON Parser instance.
4
+ */
5
+ export { createParser } from "./parser.js";
6
+ export type { IncrementalJsonParser, ParserOptions, PushResult, ParserSnapshot, FinalResult, ParserEvent, ValueCommittedEvent, ContainerClosedEvent, RepairAppliedEvent, DiagnosticEvent, DocumentCompleteEvent, StreamFinishedEvent, JsonValue, JsonObject, JsonArray, SyntaxStatus, StreamEndReason, PendingToken, RepairAction, Diagnostic, ParserLimits, } from "./types.js";
7
+ /** @public (Stable) Default resource limits applied when none are supplied to `createParser()`. */
8
+ export { DEFAULT_LIMITS } from "./limits.js";
9
+ /** @public (Stable) Machine-readable parser diagnostic codes (see `Diagnostic.code`). */
10
+ export { DiagnosticCode } from "./diagnostics/codes.js";
11
+ /**
12
+ * @public (Stable)
13
+ * Creates a stream coordinator for mapping overlapping multi-tool streams.
14
+ */
15
+ export { createToolCallStreamCoordinator } from "./coordinator/coordinator.js";
16
+ export type { ToolCallStreamCoordinator, ToolCallState, JsonSchemaLike, CoordinatorLimits, CoordinatorDiagnostic, } from "./coordinator/types.js";
17
+ export type { NormalizedToolStreamEvent, ProviderName } from "./coordinator/protocol.js";
18
+ /**
19
+ * @public (Stable)
20
+ * Diagnostic code a custom `ProviderStreamAdapter` can emit (as a
21
+ * stream-wide `provider_diagnostic`, no `callRef`) to signal a
22
+ * content-safety/policy termination - the gate matches on this exact code
23
+ * to report `reason: "content_filtered"`. See docs/EXECUTION_GATE.md.
24
+ */
25
+ export { CONTENT_FILTERED_DIAGNOSTIC_CODE } from "./coordinator/diagnostic-codes.js";
26
+ /**
27
+ * @public (Stable)
28
+ * Fail-closed execution-decision layer built on top of the coordinator.
29
+ * Answers one question per tool call: is it safe to execute right now?
30
+ * See docs/EXECUTION_GATE.md.
31
+ */
32
+ export { createToolCallExecutionGate } from "./gate/gate.js";
33
+ export type { ToolCallExecutionGate, ToolCallExecutionGateFinalResult, ExecutionDecision, ExecuteDecision, NonExecutableDecision, ExecutionAction, ExecutionReason, DecisionEvidence, } from "./gate/types.js";
34
+ /**
35
+ * @public (Stable)
36
+ * Drop-in fail-closed execution guard for the Vercel AI SDK's `fullStream`.
37
+ * Composes `AiSdkStreamAdapter` and `createToolCallExecutionGate()` - see
38
+ * `docs/EXECUTION_GATE.md#high-level-guards`.
39
+ */
40
+ export { createAiSdkExecutionGuard } from "./guard/ai-sdk.js";
41
+ export type { ExecutionGuard, AiSdkExecutionGuard, ExecutionGuardOptions } from "./guard/types.js";
42
+ export type { ProviderStreamAdapter } from "./providers/adapter.js";
43
+ /**
44
+ * @public (Experimental)
45
+ * OpenAI Chat Completions (legacy `function_call`) and Responses API
46
+ * streaming tool-call shape.
47
+ */
48
+ export { OpenAIStreamAdapter } from "./providers/openai.js";
49
+ /**
50
+ * @public (Experimental)
51
+ * Generic OpenAI-compatible `choices[].delta.tool_calls[]` streaming
52
+ * shape, shared by OpenAI's current API and most compatible endpoints.
53
+ */
54
+ export { OpenAICompatibleStreamAdapter } from "./providers/openai-compatible.js";
55
+ /**
56
+ * @public (Experimental)
57
+ * Anthropic Messages API streaming tool-call shape
58
+ * (`content_block_delta` / `input_json_delta`).
59
+ */
60
+ export { AnthropicStreamAdapter } from "./providers/anthropic.js";
61
+ /**
62
+ * @public (Experimental)
63
+ * Gemini's structured `functionCall` shape. Unlike the other adapters,
64
+ * Gemini delivers function-call arguments as an already-parsed object, not
65
+ * incremental raw JSON text - see docs/COMPATIBILITY.md for what that
66
+ * means for this adapter's guarantees.
67
+ */
68
+ export { GeminiStreamAdapter } from "./providers/gemini.js";
69
+ /**
70
+ * @public (Experimental)
71
+ * OpenRouter's streaming tool-call shape (a thin extension of the
72
+ * OpenAI-compatible shape above).
73
+ */
74
+ export { OpenRouterStreamAdapter } from "./providers/openrouter.js";
75
+ /**
76
+ * @public (Experimental)
77
+ * Vercel AI SDK's `fullStream` tool-call part shape
78
+ * (`tool-input-start`/`-delta`/`-end`, `tool-call`, `tool-result`,
79
+ * `tool-error`, `finish`, `error`, `abort`). Verified against `ai@5.0.240`,
80
+ * `ai@6.0.259`, `ai@7.0.70` - see docs/COMPATIBILITY.md. Prefer
81
+ * `createAiSdkExecutionGuard()` (Stable, above) for the common case; use
82
+ * this directly only if you need the adapter instance itself.
83
+ */
84
+ export { AiSdkStreamAdapter } from "./providers/ai-sdk.js";
85
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA;;;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,EACZ,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,mGAAmG;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,yFAAyF;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD;;;GAGG;AACH,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,YAAY,EACV,yBAAyB,EACzB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzF;;;;;;GAMG;AACH,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAGrF;;;;;GAKG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EACV,qBAAqB,EACrB,gCAAgC,EAChC,iBAAiB,EACjB,eAAe,EACf,qBAAqB,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;AAOpE;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;GAIG;AACH,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AAEjF;;;;GAIG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;GAIG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Public API — prefix-safe-json
3
+ //
4
+ // Every exported function/class carries its own `@public (Stable)` or
5
+ // `@public (Experimental)` classification directly above its own
6
+ // declaration - never one comment shared across multiple export
7
+ // statements, since a JSDoc/TSDoc comment attaches only to the single
8
+ // declaration immediately following it, not to every statement a reader's
9
+ // eye groups it with visually. Type-only exports grouped under a
10
+ // `// <Section> API` comment inherit the classification of the
11
+ // function/class they are declared alongside in that same section, unless
12
+ // individually annotated otherwise.
13
+ // ---------------------------------------------------------------------------
14
+ /**
15
+ * @public (Stable)
16
+ * Creates a new Incremental JSON Parser instance.
17
+ */
18
+ export { createParser } from "./parser.js";
19
+ /** @public (Stable) Default resource limits applied when none are supplied to `createParser()`. */
20
+ export { DEFAULT_LIMITS } from "./limits.js";
21
+ /** @public (Stable) Machine-readable parser diagnostic codes (see `Diagnostic.code`). */
22
+ export { DiagnosticCode } from "./diagnostics/codes.js";
23
+ // Coordinator API
24
+ /**
25
+ * @public (Stable)
26
+ * Creates a stream coordinator for mapping overlapping multi-tool streams.
27
+ */
28
+ export { createToolCallStreamCoordinator } from "./coordinator/coordinator.js";
29
+ /**
30
+ * @public (Stable)
31
+ * Diagnostic code a custom `ProviderStreamAdapter` can emit (as a
32
+ * stream-wide `provider_diagnostic`, no `callRef`) to signal a
33
+ * content-safety/policy termination - the gate matches on this exact code
34
+ * to report `reason: "content_filtered"`. See docs/EXECUTION_GATE.md.
35
+ */
36
+ export { CONTENT_FILTERED_DIAGNOSTIC_CODE } from "./coordinator/diagnostic-codes.js";
37
+ // Execution Safety Gate API
38
+ /**
39
+ * @public (Stable)
40
+ * Fail-closed execution-decision layer built on top of the coordinator.
41
+ * Answers one question per tool call: is it safe to execute right now?
42
+ * See docs/EXECUTION_GATE.md.
43
+ */
44
+ export { createToolCallExecutionGate } from "./gate/gate.js";
45
+ // High-level execution guards
46
+ /**
47
+ * @public (Stable)
48
+ * Drop-in fail-closed execution guard for the Vercel AI SDK's `fullStream`.
49
+ * Composes `AiSdkStreamAdapter` and `createToolCallExecutionGate()` - see
50
+ * `docs/EXECUTION_GATE.md#high-level-guards`.
51
+ */
52
+ export { createAiSdkExecutionGuard } from "./guard/ai-sdk.js";
53
+ // Provider adapters for various LLM network shapes. Each is independently
54
+ // classified below - see docs/COMPATIBILITY.md for what "verified" means
55
+ // per adapter (a specific tested SDK version vs. a documented wire shape).
56
+ // All six may change if the upstream API/SDK shape they target changes.
57
+ /**
58
+ * @public (Experimental)
59
+ * OpenAI Chat Completions (legacy `function_call`) and Responses API
60
+ * streaming tool-call shape.
61
+ */
62
+ export { OpenAIStreamAdapter } from "./providers/openai.js";
63
+ /**
64
+ * @public (Experimental)
65
+ * Generic OpenAI-compatible `choices[].delta.tool_calls[]` streaming
66
+ * shape, shared by OpenAI's current API and most compatible endpoints.
67
+ */
68
+ export { OpenAICompatibleStreamAdapter } from "./providers/openai-compatible.js";
69
+ /**
70
+ * @public (Experimental)
71
+ * Anthropic Messages API streaming tool-call shape
72
+ * (`content_block_delta` / `input_json_delta`).
73
+ */
74
+ export { AnthropicStreamAdapter } from "./providers/anthropic.js";
75
+ /**
76
+ * @public (Experimental)
77
+ * Gemini's structured `functionCall` shape. Unlike the other adapters,
78
+ * Gemini delivers function-call arguments as an already-parsed object, not
79
+ * incremental raw JSON text - see docs/COMPATIBILITY.md for what that
80
+ * means for this adapter's guarantees.
81
+ */
82
+ export { GeminiStreamAdapter } from "./providers/gemini.js";
83
+ /**
84
+ * @public (Experimental)
85
+ * OpenRouter's streaming tool-call shape (a thin extension of the
86
+ * OpenAI-compatible shape above).
87
+ */
88
+ export { OpenRouterStreamAdapter } from "./providers/openrouter.js";
89
+ /**
90
+ * @public (Experimental)
91
+ * Vercel AI SDK's `fullStream` tool-call part shape
92
+ * (`tool-input-start`/`-delta`/`-end`, `tool-call`, `tool-result`,
93
+ * `tool-error`, `finish`, `error`, `abort`). Verified against `ai@5.0.240`,
94
+ * `ai@6.0.259`, `ai@7.0.70` - see docs/COMPATIBILITY.md. Prefer
95
+ * `createAiSdkExecutionGuard()` (Stable, above) for the common case; use
96
+ * this directly only if you need the adapter instance itself.
97
+ */
98
+ export { AiSdkStreamAdapter } from "./providers/ai-sdk.js";
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gCAAgC;AAChC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,sEAAsE;AACtE,0EAA0E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