prefix-safe-json 0.0.1-alpha.4 → 0.1.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 (135) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +2 -2
  3. package/package.json +2 -1
  4. package/dist/coordinator/coordinator.d.ts +0 -53
  5. package/dist/coordinator/coordinator.d.ts.map +0 -1
  6. package/dist/coordinator/coordinator.js +0 -448
  7. package/dist/coordinator/coordinator.js.map +0 -1
  8. package/dist/coordinator/diagnostic-codes.d.ts +0 -11
  9. package/dist/coordinator/diagnostic-codes.d.ts.map +0 -1
  10. package/dist/coordinator/diagnostic-codes.js +0 -22
  11. package/dist/coordinator/diagnostic-codes.js.map +0 -1
  12. package/dist/coordinator/protocol.d.ts +0 -61
  13. package/dist/coordinator/protocol.d.ts.map +0 -1
  14. package/dist/coordinator/protocol.js +0 -2
  15. package/dist/coordinator/protocol.js.map +0 -1
  16. package/dist/coordinator/types.d.ts +0 -104
  17. package/dist/coordinator/types.d.ts.map +0 -1
  18. package/dist/coordinator/types.js +0 -7
  19. package/dist/coordinator/types.js.map +0 -1
  20. package/dist/diagnostics/codes.d.ts +0 -24
  21. package/dist/diagnostics/codes.d.ts.map +0 -1
  22. package/dist/diagnostics/codes.js +0 -28
  23. package/dist/diagnostics/codes.js.map +0 -1
  24. package/dist/diagnostics/factory.d.ts +0 -8
  25. package/dist/diagnostics/factory.d.ts.map +0 -1
  26. package/dist/diagnostics/factory.js +0 -17
  27. package/dist/diagnostics/factory.js.map +0 -1
  28. package/dist/gate/decide.d.ts +0 -27
  29. package/dist/gate/decide.d.ts.map +0 -1
  30. package/dist/gate/decide.js +0 -138
  31. package/dist/gate/decide.js.map +0 -1
  32. package/dist/gate/gate.d.ts +0 -25
  33. package/dist/gate/gate.d.ts.map +0 -1
  34. package/dist/gate/gate.js +0 -96
  35. package/dist/gate/gate.js.map +0 -1
  36. package/dist/gate/types.d.ts +0 -184
  37. package/dist/gate/types.d.ts.map +0 -1
  38. package/dist/gate/types.js +0 -2
  39. package/dist/gate/types.js.map +0 -1
  40. package/dist/grammar/frame.d.ts +0 -58
  41. package/dist/grammar/frame.d.ts.map +0 -1
  42. package/dist/grammar/frame.js +0 -87
  43. package/dist/grammar/frame.js.map +0 -1
  44. package/dist/grammar/pointer.d.ts +0 -10
  45. package/dist/grammar/pointer.d.ts.map +0 -1
  46. package/dist/grammar/pointer.js +0 -20
  47. package/dist/grammar/pointer.js.map +0 -1
  48. package/dist/grammar/stack.d.ts +0 -73
  49. package/dist/grammar/stack.d.ts.map +0 -1
  50. package/dist/grammar/stack.js +0 -168
  51. package/dist/grammar/stack.js.map +0 -1
  52. package/dist/guard/ai-sdk.d.ts +0 -48
  53. package/dist/guard/ai-sdk.d.ts.map +0 -1
  54. package/dist/guard/ai-sdk.js +0 -51
  55. package/dist/guard/ai-sdk.js.map +0 -1
  56. package/dist/guard/provider-guard.d.ts +0 -4
  57. package/dist/guard/provider-guard.d.ts.map +0 -1
  58. package/dist/guard/provider-guard.js +0 -38
  59. package/dist/guard/provider-guard.js.map +0 -1
  60. package/dist/guard/types.d.ts +0 -48
  61. package/dist/guard/types.d.ts.map +0 -1
  62. package/dist/guard/types.js +0 -2
  63. package/dist/guard/types.js.map +0 -1
  64. package/dist/index.d.ts +0 -45
  65. package/dist/index.d.ts.map +0 -1
  66. package/dist/index.js +0 -45
  67. package/dist/index.js.map +0 -1
  68. package/dist/lexer/scanner.d.ts +0 -106
  69. package/dist/lexer/scanner.d.ts.map +0 -1
  70. package/dist/lexer/scanner.js +0 -658
  71. package/dist/lexer/scanner.js.map +0 -1
  72. package/dist/lexer/states.d.ts +0 -31
  73. package/dist/lexer/states.d.ts.map +0 -1
  74. package/dist/lexer/states.js +0 -35
  75. package/dist/lexer/states.js.map +0 -1
  76. package/dist/lexer/tokens.d.ts +0 -22
  77. package/dist/lexer/tokens.d.ts.map +0 -1
  78. package/dist/lexer/tokens.js +0 -22
  79. package/dist/lexer/tokens.js.map +0 -1
  80. package/dist/limits.d.ts +0 -14
  81. package/dist/limits.d.ts.map +0 -1
  82. package/dist/limits.js +0 -23
  83. package/dist/limits.js.map +0 -1
  84. package/dist/parser.d.ts +0 -6
  85. package/dist/parser.d.ts.map +0 -1
  86. package/dist/parser.js +0 -922
  87. package/dist/parser.js.map +0 -1
  88. package/dist/providers/adapter.d.ts +0 -10
  89. package/dist/providers/adapter.d.ts.map +0 -1
  90. package/dist/providers/adapter.js +0 -2
  91. package/dist/providers/adapter.js.map +0 -1
  92. package/dist/providers/ai-sdk.d.ts +0 -58
  93. package/dist/providers/ai-sdk.d.ts.map +0 -1
  94. package/dist/providers/ai-sdk.js +0 -212
  95. package/dist/providers/ai-sdk.js.map +0 -1
  96. package/dist/providers/anthropic.d.ts +0 -45
  97. package/dist/providers/anthropic.d.ts.map +0 -1
  98. package/dist/providers/anthropic.js +0 -112
  99. package/dist/providers/anthropic.js.map +0 -1
  100. package/dist/providers/gemini.d.ts +0 -31
  101. package/dist/providers/gemini.d.ts.map +0 -1
  102. package/dist/providers/gemini.js +0 -94
  103. package/dist/providers/gemini.js.map +0 -1
  104. package/dist/providers/openai-compatible.d.ts +0 -33
  105. package/dist/providers/openai-compatible.d.ts.map +0 -1
  106. package/dist/providers/openai-compatible.js +0 -160
  107. package/dist/providers/openai-compatible.js.map +0 -1
  108. package/dist/providers/openai.d.ts +0 -55
  109. package/dist/providers/openai.d.ts.map +0 -1
  110. package/dist/providers/openai.js +0 -263
  111. package/dist/providers/openai.js.map +0 -1
  112. package/dist/providers/openrouter.d.ts +0 -35
  113. package/dist/providers/openrouter.d.ts.map +0 -1
  114. package/dist/providers/openrouter.js +0 -55
  115. package/dist/providers/openrouter.js.map +0 -1
  116. package/dist/semantic/builder.d.ts +0 -55
  117. package/dist/semantic/builder.d.ts.map +0 -1
  118. package/dist/semantic/builder.js +0 -140
  119. package/dist/semantic/builder.js.map +0 -1
  120. package/dist/semantic/events.d.ts +0 -2
  121. package/dist/semantic/events.d.ts.map +0 -1
  122. package/dist/semantic/events.js +0 -5
  123. package/dist/semantic/events.js.map +0 -1
  124. package/dist/semantic/snapshot.d.ts +0 -56
  125. package/dist/semantic/snapshot.d.ts.map +0 -1
  126. package/dist/semantic/snapshot.js +0 -230
  127. package/dist/semantic/snapshot.js.map +0 -1
  128. package/dist/types.d.ts +0 -156
  129. package/dist/types.d.ts.map +0 -1
  130. package/dist/types.js +0 -5
  131. package/dist/types.js.map +0 -1
  132. package/dist/utf8/decoder.d.ts +0 -53
  133. package/dist/utf8/decoder.d.ts.map +0 -1
  134. package/dist/utf8/decoder.js +0 -323
  135. package/dist/utf8/decoder.js.map +0 -1
@@ -1,61 +0,0 @@
1
- export type ProviderName = "openai" | "anthropic" | "gemini" | "openrouter" | "openai-compatible" | "ai-sdk" | "unknown";
2
- export interface NormalizedEventBase {
3
- /**
4
- * Deterministic sequence number assigned by the stream coordinator.
5
- */
6
- readonly sequence: number;
7
- readonly provider: ProviderName;
8
- readonly rawEventType?: string;
9
- readonly providerRequestId?: string;
10
- }
11
- export type NormalizedToolStreamEvent = ToolCallStartEvent | ToolCallIdentityEvent | ToolCallNameDeltaEvent | ToolCallArgumentsDeltaEvent | ToolCallEndEvent | ProviderDiagnosticEvent | ProviderStreamEndEvent;
12
- export interface ToolCallStartEvent extends NormalizedEventBase {
13
- readonly type: "tool_call_start";
14
- readonly callRef: ProviderCallRef;
15
- readonly toolCallId?: string;
16
- readonly toolIndex?: number;
17
- readonly name?: string;
18
- }
19
- export interface ToolCallIdentityEvent extends NormalizedEventBase {
20
- readonly type: "tool_call_identity";
21
- readonly callRef: ProviderCallRef;
22
- readonly toolCallId?: string;
23
- readonly toolIndex?: number;
24
- }
25
- export interface ToolCallNameDeltaEvent extends NormalizedEventBase {
26
- readonly type: "tool_call_name_delta";
27
- readonly callRef: ProviderCallRef;
28
- readonly delta: string;
29
- }
30
- export interface ToolCallArgumentsDeltaEvent extends NormalizedEventBase {
31
- readonly type: "tool_call_arguments_delta";
32
- readonly callRef: ProviderCallRef;
33
- readonly delta: string | Uint8Array;
34
- }
35
- export type StreamEndReason = "complete" | "length" | "cancelled" | "provider_error" | "network_error" | "unknown";
36
- export interface ToolCallEndEvent extends NormalizedEventBase {
37
- readonly type: "tool_call_end";
38
- readonly callRef: ProviderCallRef;
39
- readonly reason: StreamEndReason;
40
- readonly providerReason?: string;
41
- }
42
- export interface ProviderDiagnosticEvent extends NormalizedEventBase {
43
- readonly type: "provider_diagnostic";
44
- readonly code: string;
45
- readonly severity: "info" | "warning" | "error" | "fatal";
46
- readonly message: string;
47
- readonly callRef?: ProviderCallRef;
48
- }
49
- export interface ProviderStreamEndEvent extends NormalizedEventBase {
50
- readonly type: "provider_stream_end";
51
- readonly reason: StreamEndReason;
52
- readonly providerReason?: string;
53
- }
54
- export interface ProviderCallRef {
55
- /**
56
- * Deterministic provider-local identity.
57
- * e.g. "content-block:0"
58
- */
59
- readonly sourceKey: string;
60
- }
61
- //# sourceMappingURL=protocol.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/coordinator/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,mBAAmB,GACnB,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,MAAM,MAAM,yBAAyB,GACjC,kBAAkB,GAClB,qBAAqB,GACrB,sBAAsB,GACtB,2BAA2B,GAC3B,gBAAgB,GAChB,uBAAuB,GACvB,sBAAsB,CAAC;AAE3B,MAAM,WAAW,kBAAmB,S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mBAAmB;IAClE,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;IAC1D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC;CACpC;AAED,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=protocol.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/coordinator/protocol.ts"],"names":[],"mappings":""}
@@ -1,104 +0,0 @@
1
- import { ParserSnapshot, ParserEvent } from "../types.js";
2
- import { NormalizedToolStreamEvent, ProviderName, StreamEndReason } from "./protocol.js";
3
- export interface CoordinatorLimits {
4
- readonly maxToolCalls: number;
5
- readonly maxToolNameBytes: number;
6
- readonly maxTrailingDataBytes: number;
7
- readonly maxNormalizedEvents: number;
8
- }
9
- export declare const DEFAULT_COORDINATOR_LIMITS: CoordinatorLimits;
10
- export interface ToolCallState {
11
- readonly internalId: string;
12
- readonly provider: ProviderName;
13
- readonly toolCallId?: string;
14
- readonly toolIndex?: number;
15
- readonly name?: string;
16
- readonly nameComplete: boolean;
17
- readonly parser: ParserSnapshot;
18
- readonly status: "collecting" | "complete" | "truncated" | "salvaged" | "invalid" | "cancelled";
19
- /**
20
- * Result of validating `parser.stableValue` against the JSON Schema
21
- * registered for this call's tool name (see `toolSchemas` on
22
- * `createToolCallStreamCoordinator`). `undefined` when no schema was
23
- * registered for this tool, or the call never reached a "complete"
24
- * outcome (there's nothing meaningful to validate). This is a *separate*
25
- * concern from `parser.executable` — that flag means "the data is
26
- * structurally complete and wasn't fabricated by truncation"; this one
27
- * means "the data matches the shape the tool declared it needs." Both
28
- * must hold for the coordinator's own `executable` (on the
29
- * `tool_call_finished` event) to be true.
30
- */
31
- readonly schemaValid?: boolean;
32
- }
33
- /**
34
- * A JSON Schema object (draft-07, matching ajv's default). Kept as `object`
35
- * rather than a specific type-checked shape so callers can pass whatever
36
- * JSON Schema library/types they already have without a forced dependency
37
- * on this package's own schema typings.
38
- */
39
- export type JsonSchemaLike = object;
40
- export interface ToolCallCoordinatorSnapshot {
41
- readonly calls: readonly ToolCallState[];
42
- readonly diagnostics: readonly CoordinatorDiagnostic[];
43
- readonly eventsProcessed: number;
44
- readonly isFinished: boolean;
45
- }
46
- export type ToolCallCoordinatorEvent = {
47
- readonly type: "tool_call_discovered";
48
- readonly sequence: number;
49
- readonly internalId: string;
50
- readonly provider: ProviderName;
51
- } | {
52
- readonly type: "tool_call_identity_updated";
53
- readonly sequence: number;
54
- readonly internalId: string;
55
- readonly toolCallId?: string;
56
- readonly toolIndex?: number;
57
- } | {
58
- readonly type: "tool_name_updated";
59
- readonly sequence: number;
60
- readonly internalId: string;
61
- readonly name: string;
62
- readonly complete: boolean;
63
- } | {
64
- readonly type: "tool_argument_event";
65
- readonly sequence: number;
66
- readonly internalId: string;
67
- readonly event: ParserEvent;
68
- } | {
69
- readonly type: "tool_call_finished";
70
- readonly sequence: number;
71
- readonly internalId: string;
72
- readonly outcome: "complete" | "truncated" | "salvaged" | "invalid" | "cancelled";
73
- readonly executable: boolean;
74
- } | {
75
- readonly type: "coordinator_diagnostic";
76
- readonly sequence: number;
77
- readonly diagnostic: CoordinatorDiagnostic;
78
- } | {
79
- readonly type: "provider_stream_finished";
80
- readonly sequence: number;
81
- readonly reason: StreamEndReason;
82
- };
83
- export interface CoordinatorDiagnostic {
84
- readonly code: string;
85
- readonly severity: "info" | "warning" | "error" | "fatal";
86
- readonly message: string;
87
- readonly internalId?: string;
88
- }
89
- export interface CoordinatorPushResult {
90
- readonly accepted: boolean;
91
- }
92
- export interface ToolCallCoordinatorFinalResult {
93
- readonly calls: readonly ToolCallState[];
94
- }
95
- export interface ToolCallStreamCoordinator {
96
- push(event: NormalizedToolStreamEvent): CoordinatorPushResult;
97
- snapshot(): ToolCallCoordinatorSnapshot;
98
- drainEvents(): readonly ToolCallCoordinatorEvent[];
99
- finish(meta?: {
100
- reason?: StreamEndReason;
101
- providerReason?: string;
102
- }): ToolCallCoordinatorFinalResult;
103
- }
104
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/coordinator/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACtC;AAED,eAAO,MAAM,0BAA0B,EAAE,iBAKxC,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAEhC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YA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AAK,EAAE,yBAAyB,GAAG,qBAAqB,CAAC;IAC9D,QAAQ,IAAI,2BAA2B,CAAC;IACxC,WAAW,IAAI,SAAS,wBAAwB,EAAE,CAAC;IACnD,MAAM,CAAC,IAAI,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,8BAA8B,CAAC;CACpC"}
@@ -1,7 +0,0 @@
1
- export const DEFAULT_COORDINATOR_LIMITS = {
2
- maxToolCalls: 128,
3
- maxToolNameBytes: 1024,
4
- maxTrailingDataBytes: 65536,
5
- maxNormalizedEvents: 100000,
6
- };
7
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/coordinator/types.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC3D,YAAY,EAAE,GAAG;IACjB,gBAAgB,EAAE,IAAI;IACtB,oBAAoB,EAAE,KAAK;IAC3B,mBAAmB,EAAE,MAAM;CAC5B,CAAC"}
@@ -1,24 +0,0 @@
1
- /** All known diagnostic codes. */
2
- export declare const DiagnosticCode: {
3
- readonly E_UNEXPECTED_TOKEN: "E_UNEXPECTED_TOKEN";
4
- readonly E_DUPLICATE_KEY: "E_DUPLICATE_KEY";
5
- readonly E_INCOMPLETE_UTF8: "E_INCOMPLETE_UTF8";
6
- readonly E_INVALID_UTF8: "E_INVALID_UTF8";
7
- readonly E_INCOMPLETE_UNICODE_ESCAPE: "E_INCOMPLETE_UNICODE_ESCAPE";
8
- readonly E_INVALID_UNICODE_ESCAPE: "E_INVALID_UNICODE_ESCAPE";
9
- readonly E_UNPAIRED_SURROGATE: "E_UNPAIRED_SURROGATE";
10
- readonly E_UNTERMINATED_STRING: "E_UNTERMINATED_STRING";
11
- readonly E_INCOMPLETE_NUMBER: "E_INCOMPLETE_NUMBER";
12
- readonly E_INCOMPLETE_LITERAL: "E_INCOMPLETE_LITERAL";
13
- readonly E_TRAILING_DATA: "E_TRAILING_DATA";
14
- readonly E_STREAM_TRUNCATED: "E_STREAM_TRUNCATED";
15
- readonly E_LIMIT_DEPTH: "E_LIMIT_DEPTH";
16
- readonly E_LIMIT_INPUT_BYTES: "E_LIMIT_INPUT_BYTES";
17
- readonly E_LIMIT_STRING_BYTES: "E_LIMIT_STRING_BYTES";
18
- readonly E_LIMIT_EVENT_QUEUE: "E_LIMIT_EVENT_QUEUE";
19
- readonly E_PUSH_AFTER_FINISH: "E_PUSH_AFTER_FINISH";
20
- readonly W_RAW_CONTROL_CHARACTER: "W_RAW_CONTROL_CHARACTER";
21
- readonly W_TRAILING_TEXT_ISOLATED: "W_TRAILING_TEXT_ISOLATED";
22
- };
23
- export type DiagnosticCodeValue = (typeof DiagnosticCode)[keyof typeof DiagnosticCode];
24
- //# sourceMappingURL=codes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/diagnostics/codes.ts"],"names":[],"mappings":"AAIA,kCAAkC;AAClC,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;CAuBjB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAC7B,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC"}
@@ -1,28 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Diagnostic codes
3
- // ---------------------------------------------------------------------------
4
- /** All known diagnostic codes. */
5
- export const DiagnosticCode = {
6
- // --- Errors ---
7
- E_UNEXPECTED_TOKEN: "E_UNEXPECTED_TOKEN",
8
- E_DUPLICATE_KEY: "E_DUPLICATE_KEY",
9
- E_INCOMPLETE_UTF8: "E_INCOMPLETE_UTF8",
10
- E_INVALID_UTF8: "E_INVALID_UTF8",
11
- E_INCOMPLETE_UNICODE_ESCAPE: "E_INCOMPLETE_UNICODE_ESCAPE",
12
- E_INVALID_UNICODE_ESCAPE: "E_INVALID_UNICODE_ESCAPE",
13
- E_UNPAIRED_SURROGATE: "E_UNPAIRED_SURROGATE",
14
- E_UNTERMINATED_STRING: "E_UNTERMINATED_STRING",
15
- E_INCOMPLETE_NUMBER: "E_INCOMPLETE_NUMBER",
16
- E_INCOMPLETE_LITERAL: "E_INCOMPLETE_LITERAL",
17
- E_TRAILING_DATA: "E_TRAILING_DATA",
18
- E_STREAM_TRUNCATED: "E_STREAM_TRUNCATED",
19
- E_LIMIT_DEPTH: "E_LIMIT_DEPTH",
20
- E_LIMIT_INPUT_BYTES: "E_LIMIT_INPUT_BYTES",
21
- E_LIMIT_STRING_BYTES: "E_LIMIT_STRING_BYTES",
22
- E_LIMIT_EVENT_QUEUE: "E_LIMIT_EVENT_QUEUE",
23
- E_PUSH_AFTER_FINISH: "E_PUSH_AFTER_FINISH",
24
- // --- Warnings ---
25
- W_RAW_CONTROL_CHARACTER: "W_RAW_CONTROL_CHARACTER",
26
- W_TRAILING_TEXT_ISOLATED: "W_TRAILING_TEXT_ISOLATED",
27
- };
28
- //# sourceMappingURL=codes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/diagnostics/codes.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,kCAAkC;AAClC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,iBAAiB;IACjB,kBAAkB,EAAE,oBAAoB;IACxC,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,cAAc,EAAE,gBAAgB;IAChC,2BAA2B,EAAE,6BAA6B;IAC1D,wBAAwB,EAAE,0BAA0B;IACpD,oBAAoB,EAAE,sBAAsB;IAC5C,qBAAqB,EAAE,uBAAuB;IAC9C,mBAAmB,EAAE,qBAAqB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,eAAe,EAAE,iBAAiB;IAClC,kBAAkB,EAAE,oBAAoB;IACxC,aAAa,EAAE,eAAe;IAC9B,mBAAmB,EAAE,qBAAqB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,mBAAmB,EAAE,qBAAqB;IAC1C,mBAAmB,EAAE,qBAAqB;IAE1C,mBAAmB;IACnB,uBAAuB,EAAE,yBAAyB;IAClD,wBAAwB,EAAE,0BAA0B;CAC5C,CAAC"}
@@ -1,8 +0,0 @@
1
- import type { Diagnostic } from "../types.js";
2
- type Severity = Diagnostic["severity"];
3
- /**
4
- * Creates a Diagnostic object.
5
- */
6
- export declare function createDiagnostic(code: string, severity: Severity, byteOffset: number, message: string, recoverable: boolean, path?: string): Diagnostic;
7
- export {};
8
- //# sourceMappingURL=factory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/diagnostics/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,KAAK,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;AAEvC;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,OAAO,EACpB,IAAI,CAAC,EAAE,MAAM,GACZ,UAAU,CAYZ"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Creates a Diagnostic object.
3
- */
4
- export function createDiagnostic(code, severity, byteOffset, message, recoverable, path) {
5
- const diag = {
6
- code,
7
- severity,
8
- byteOffset,
9
- message,
10
- recoverable,
11
- };
12
- if (path !== undefined) {
13
- diag.path = path;
14
- }
15
- return diag;
16
- }
17
- //# sourceMappingURL=factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/diagnostics/factory.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,QAAkB,EAClB,UAAkB,EAClB,OAAe,EACf,WAAoB,EACpB,IAAa;IAEb,MAAM,IAAI,GAAe;QACvB,IAAI;QACJ,QAAQ;QACR,UAAU;QACV,OAAO;QACP,WAAW;KACZ,CAAC;IACF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,27 +0,0 @@
1
- import { CoordinatorDiagnostic, ToolCallState } from "../coordinator/types.js";
2
- import { StreamEndReason } from "../coordinator/protocol.js";
3
- import { ExecuteDecision, NonExecutableDecision } from "./types.js";
4
- export interface DecisionContext {
5
- /**
6
- * The stream-level end reason - what actually happened to the underlying
7
- * provider stream, not any single call's own (possibly still-"collecting")
8
- * status. Stream-wide fail-closed conditions (provider_error) key off this
9
- * rather than per-call state.
10
- */
11
- readonly streamEndReason: StreamEndReason;
12
- /**
13
- * The provider's own pre-normalization reason string for the stream-end
14
- * event, when one was given (`ProviderStreamEndEvent.providerReason`).
15
- * Observability only, mirrored onto `DecisionEvidence.providerReason` -
16
- * never consulted by the decision logic itself.
17
- */
18
- readonly streamEndProviderReason?: string;
19
- /**
20
- * The coordinator's full, unfiltered diagnostics list (`snapshot().diagnostics`).
21
- * `decideExecution` splits this into per-call (`internalId` matches) and
22
- * global (`internalId` undefined) subsets itself.
23
- */
24
- readonly diagnostics: readonly CoordinatorDiagnostic[];
25
- }
26
- export declare function decideExecution(call: ToolCallState, ctx: DecisionContext): ExecuteDecision | NonExecutableDecision;
27
- //# sourceMappingURL=decide.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decide.d.ts","sourceRoot":"","sources":["../../src/gate/decide.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAoB,eAAe,EAAmB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEvG,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAE1C;;;;;OAKG;IACH,QAAQ,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACxD;AAeD,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,eAAe,GACnB,eAAe,GAAG,qBAAqB,CA+HzC"}
@@ -1,138 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Pure execution-decision mapping.
3
- //
4
- // Deliberately a standalone function (no coordinator/adapter dependency) so
5
- // the entire decision table can be unit-tested directly against hand-built
6
- // ToolCallState fixtures, without spinning up a full push()/finish()
7
- // pipeline for every row of the table.
8
- //
9
- // Priority order matters and is intentional: every fail-closed disqualifier
10
- // (resource limits, provider errors, content-policy terminations, schema
11
- // mismatches, malformed content, positively-observed truncation) is checked
12
- // before the single positive "execute" branch. "execute" is reached only
13
- // once nothing above has disqualified the call - it is the last positive
14
- // case, never the first check made, so a future status value that happens
15
- // to superficially resemble "complete" still can't skip the checks ahead of
16
- // it.
17
- // ---------------------------------------------------------------------------
18
- import { DiagnosticCode } from "../diagnostics/codes.js";
19
- import { CONTENT_FILTERED_DIAGNOSTIC_CODE } from "../coordinator/diagnostic-codes.js";
20
- const PARSER_RESOURCE_LIMIT_CODES = new Set([
21
- DiagnosticCode.E_LIMIT_DEPTH,
22
- DiagnosticCode.E_LIMIT_INPUT_BYTES,
23
- DiagnosticCode.E_LIMIT_STRING_BYTES,
24
- DiagnosticCode.E_LIMIT_EVENT_QUEUE,
25
- ]);
26
- const COORDINATOR_RESOURCE_LIMIT_CODES = new Set([
27
- "E_COORDINATOR_LIMIT_CALLS",
28
- "E_COORDINATOR_LIMIT_EVENTS",
29
- "E_TOOL_NAME_LIMIT",
30
- ]);
31
- export function decideExecution(call, ctx) {
32
- const parserDiagnostics = call.parser.diagnostics;
33
- const callCoordinatorDiagnostics = ctx.diagnostics.filter((d) => d.internalId === call.internalId);
34
- const globalCoordinatorDiagnostics = ctx.diagnostics.filter((d) => d.internalId === undefined);
35
- const coordinatorDiagnostics = [
36
- ...globalCoordinatorDiagnostics,
37
- ...callCoordinatorDiagnostics,
38
- ];
39
- const evidence = {
40
- provider: call.provider,
41
- providerReason: ctx.streamEndProviderReason,
42
- streamEndReason: ctx.streamEndReason,
43
- terminalConfirmed: ctx.streamEndReason !== "unknown",
44
- structurallyComplete: call.parser.rootComplete,
45
- parserExecutable: call.parser.executable,
46
- schemaValid: call.schemaValid,
47
- receivedBytes: call.parser.receivedBytes,
48
- };
49
- const common = {
50
- internalId: call.internalId,
51
- toolCallId: call.toolCallId,
52
- toolIndex: call.toolIndex,
53
- name: call.name,
54
- stableValue: call.parser.stableValue,
55
- parserDiagnostics,
56
- coordinatorDiagnostics,
57
- evidence,
58
- };
59
- function reject(reason) {
60
- return { ...common, action: "reject", executable: false, reason };
61
- }
62
- function retry(reason) {
63
- return { ...common, action: "retry", executable: false, reason };
64
- }
65
- // --- Universal fail-closed checks ---------------------------------------
66
- // Evaluated first and unconditionally, regardless of call.status, so a
67
- // resource limit, a provider-side failure, or a content-policy
68
- // termination always wins over whatever the structural status looks like.
69
- const hasResourceLimit = parserDiagnostics.some((d) => PARSER_RESOURCE_LIMIT_CODES.has(d.code)) ||
70
- callCoordinatorDiagnostics.some((d) => COORDINATOR_RESOURCE_LIMIT_CODES.has(d.code)) ||
71
- globalCoordinatorDiagnostics.some((d) => d.code === "E_COORDINATOR_LIMIT_EVENTS");
72
- if (hasResourceLimit) {
73
- return reject("resource_limit");
74
- }
75
- if (ctx.streamEndReason === "provider_error") {
76
- return reject("provider_error");
77
- }
78
- const isContentFiltered = globalCoordinatorDiagnostics.some((d) => d.code === CONTENT_FILTERED_DIAGNOSTIC_CODE);
79
- if (isContentFiltered) {
80
- return reject("content_filtered");
81
- }
82
- // --- Status-specific handling --------------------------------------------
83
- // Exhaustive over ToolCallState["status"] with no `default`: if a future
84
- // coordinator version adds a new status literal without a matching case
85
- // here, `noImplicitReturns` fails the build - not a silent runtime gap.
86
- switch (call.status) {
87
- case "complete": {
88
- if (call.schemaValid === false) {
89
- return reject("schema_invalid");
90
- }
91
- // The ONLY positive branch in this entire function, reached only
92
- // after every disqualifying check above has already passed. The
93
- // `call.name !== undefined` check is defensive/redundant with the
94
- // coordinator's own invariant (a call only reaches status "complete"
95
- // when its name is known) - narrowing on it here is what lets
96
- // `ExecuteDecision.name` be typed as a required `string` instead of
97
- // `string | undefined`, so it never needs re-checking at every call
98
- // site. If the invariant were ever violated, this still fails closed
99
- // to "stream_incomplete" rather than fabricating a name.
100
- if (call.parser.executable === true &&
101
- call.parser.stableValue !== undefined &&
102
- call.name !== undefined) {
103
- const decision = {
104
- ...common,
105
- name: call.name,
106
- action: "execute",
107
- executable: true,
108
- reason: "complete",
109
- value: call.parser.stableValue,
110
- };
111
- return decision;
112
- }
113
- // Root closed, syntactically valid, but not trusted: the parser's
114
- // own executable contract failed it (stream-end-reason mismatch or
115
- // trailing data), even though nothing here required a repair.
116
- return retry("stream_incomplete");
117
- }
118
- case "truncated":
119
- // The parser positively observed an open string/number/literal or an
120
- // unclosed container - a real, raw mid-value cut, not a matter of
121
- // interpretation.
122
- return retry("truncated");
123
- case "invalid":
124
- // Duplicate key, unexpected token, or a missing/conflicting tool
125
- // identity - a genuine content defect, independent of how the stream
126
- // ended.
127
- return reject("malformed");
128
- case "salvaged":
129
- // Root only closed via a safe-container-closing repair; the JSON
130
- // *looks* complete, but provider metadata never confirmed genuine
131
- // completion. This is the container-level truncation case.
132
- return retry("stream_incomplete");
133
- case "cancelled":
134
- case "collecting":
135
- return retry("stream_incomplete");
136
- }
137
- }
138
- //# sourceMappingURL=decide.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/gate/decide.ts"],"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ClB,CAAC;YACD,kEAAkE;YAClE,mEAAmE;YACnE,8DAA8D;YAC9D,OAAO,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QAED,KAAK,WAAW;YACd,qEAAqE;YACrE,kEAAkE;YAClE,kBAAkB;YAClB,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC;QAE5B,KAAK,SAAS;YACZ,iEAAiE;YACjE,qEAAqE;YACrE,SAAS;YACT,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;QAE7B,KAAK,UAAU;YACb,iEAAiE;YACjE,kEAAkE;YAClE,2DAA2D;YAC3D,OAAO,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAEpC,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
@@ -1,25 +0,0 @@
1
- import { CoordinatorLimits, JsonSchemaLike } from "../coordinator/types.js";
2
- import { ParserOptions } from "../types.js";
3
- import { ToolCallExecutionGate } from "./types.js";
4
- /**
5
- * Creates a fail-closed execution-decision gate for streamed LLM tool calls.
6
- * Wraps a `ToolCallStreamCoordinator` (same constructor arguments) and adds
7
- * exactly one operation: turn each call's settled state into an
8
- * `ExecutionDecision` (`execute` / `retry` / `reject`) via a deterministic,
9
- * fully-typed decision table. See `docs/EXECUTION_GATE.md`.
10
- *
11
- * ```ts
12
- * const gate = createToolCallExecutionGate(undefined, undefined, {
13
- * write_file: { type: "object", required: ["path", "content"], properties: {
14
- * path: { type: "string" }, content: { type: "string" } } },
15
- * });
16
- * for (const raw of providerEvents) {
17
- * for (const normalized of adapter.push(raw)) gate.push(normalized);
18
- * }
19
- * for (const decision of gate.finish().decisions) {
20
- * if (decision.action === "execute") await tools[decision.name](decision.value);
21
- * }
22
- * ```
23
- */
24
- export declare function createToolCallExecutionGate(limits?: Partial<CoordinatorLimits>, parserOptions?: ParserOptions, toolSchemas?: Record<string, JsonSchemaLike>): ToolCallExecutionGate;
25
- //# sourceMappingURL=gate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/gate/gate.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,iBAAiB,EAEjB,cAAc,EAGf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAEL,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AA+EpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACnC,aAAa,CAAC,EAAE,aAAa,EAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAC3C,qBAAqB,CAEvB"}
package/dist/gate/gate.js DELETED
@@ -1,96 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // ToolCallExecutionGate — high-level execution safety layer.
3
- //
4
- // Built by composition over ToolCallStreamCoordinator, not by extending or
5
- // reimplementing it: the gate holds a coordinator instance and adds exactly
6
- // one thing coordinator state doesn't already capture - which stream-end
7
- // reason actually got applied - then maps every ToolCallState through the
8
- // pure decideExecution() table. No re-parsing, no duplicate event pipeline.
9
- // ---------------------------------------------------------------------------
10
- import { createToolCallStreamCoordinator } from "../coordinator/coordinator.js";
11
- import { decideExecution } from "./decide.js";
12
- class DefaultToolCallExecutionGate {
13
- coordinator;
14
- // Mirrors the coordinator's own "first provider_stream_end (from push(),
15
- // or from finish()'s meta if none arrived) wins" rule - see push()/finish()
16
- // below and DefaultToolCallStreamCoordinator.finish()'s matching
17
- // `if (!this.isFinished)` guard. streamEndProviderReason is captured
18
- // alongside streamEndReason purely for DecisionEvidence.providerReason -
19
- // it is never read by decideExecution()'s own logic.
20
- streamEndReason;
21
- streamEndProviderReason;
22
- streamEndCaptured = false;
23
- constructor(limits, parserOptions, toolSchemas) {
24
- this.coordinator = createToolCallStreamCoordinator(limits, parserOptions, toolSchemas);
25
- }
26
- push(event) {
27
- if (event.type === "provider_stream_end" && !this.streamEndCaptured) {
28
- this.streamEndCaptured = true;
29
- this.streamEndReason = event.reason;
30
- this.streamEndProviderReason = event.providerReason;
31
- }
32
- return this.coordinator.push(event);
33
- }
34
- snapshot() {
35
- const snap = this.coordinator.snapshot();
36
- const ctx = {
37
- // Pre-finish, no stream-end reason has been observed yet ("unknown"
38
- // is a neutral placeholder here, not a claim anything went wrong) -
39
- // every in-flight call is still "collecting" regardless, so this
40
- // never influences whether something looks executable.
41
- streamEndReason: this.streamEndReason ?? "unknown",
42
- streamEndProviderReason: this.streamEndProviderReason,
43
- diagnostics: snap.diagnostics,
44
- };
45
- return snap.calls.map((call) => decideExecution(call, ctx));
46
- }
47
- drainEvents() {
48
- return this.coordinator.drainEvents();
49
- }
50
- finish(meta) {
51
- if (!this.streamEndCaptured) {
52
- this.streamEndCaptured = true;
53
- this.streamEndReason = meta?.reason ?? "unknown";
54
- this.streamEndProviderReason = meta?.providerReason;
55
- }
56
- const result = this.coordinator.finish(meta);
57
- const diagnostics = this.coordinator.snapshot().diagnostics;
58
- // Unlike snapshot() above, this point is only ever reached after
59
- // streamEndCaptured is guaranteed true (set on entry to this method, or
60
- // already true from an earlier push()/finish() call) - and every path
61
- // that sets streamEndCaptured sets streamEndReason to a defined value in
62
- // the same branch, so the pre-finish "unknown" placeholder never applies
63
- // here.
64
- const ctx = {
65
- streamEndReason: this.streamEndReason,
66
- streamEndProviderReason: this.streamEndProviderReason,
67
- diagnostics,
68
- };
69
- const decisions = result.calls.map((call) => decideExecution(call, ctx));
70
- return { decisions, diagnostics };
71
- }
72
- }
73
- /**
74
- * Creates a fail-closed execution-decision gate for streamed LLM tool calls.
75
- * Wraps a `ToolCallStreamCoordinator` (same constructor arguments) and adds
76
- * exactly one operation: turn each call's settled state into an
77
- * `ExecutionDecision` (`execute` / `retry` / `reject`) via a deterministic,
78
- * fully-typed decision table. See `docs/EXECUTION_GATE.md`.
79
- *
80
- * ```ts
81
- * const gate = createToolCallExecutionGate(undefined, undefined, {
82
- * write_file: { type: "object", required: ["path", "content"], properties: {
83
- * path: { type: "string" }, content: { type: "string" } } },
84
- * });
85
- * for (const raw of providerEvents) {
86
- * for (const normalized of adapter.push(raw)) gate.push(normalized);
87
- * }
88
- * for (const decision of gate.finish().decisions) {
89
- * if (decision.action === "execute") await tools[decision.name](decision.value);
90
- * }
91
- * ```
92
- */
93
- export function createToolCallExecutionGate(limits, parserOptions, toolSchemas) {
94
- return new DefaultToolCallExecutionGate(limits, parserOptions, toolSchemas);
95
- }
96
- //# sourceMappingURL=gate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gate.js","sourceRoot":"","sources":["../../src/gate/gate.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6DAA6D;AAC7D,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC5E,8EAA8E;AAE9E,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAUhF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAO9C,MAAM,4BAA4B;IACf,WAAW,CAA4B;IAExD,yEAAyE;IACzE,4EAA4E;IAC5E,iEAAiE;IACjE,qEAAqE;IACrE,yEAAyE;IACzE,qDAAqD;IAC7C,eAAe,CAA8B;IAC7C,uBAAuB,CAAqB;IAC5C,iBAAiB,GAAG,KAAK,CAAC;IAElC,YACE,MAAmC,EACnC,aAA6B,EAC7B,WAA4C;QAE5C,IAAI,CAAC,WAAW,GAAG,+BAA+B,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,CAAC,KAAgC;QACnC,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACpE,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;Y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