prefix-safe-json 0.0.1-alpha.3 → 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 (123) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +72 -33
  3. package/package.json +8 -3
  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 -20
  29. package/dist/gate/decide.d.ts.map +0 -1
  30. package/dist/gate/decide.js +0 -127
  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 -80
  35. package/dist/gate/gate.js.map +0 -1
  36. package/dist/gate/types.d.ts +0 -122
  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/index.d.ts +0 -37
  53. package/dist/index.d.ts.map +0 -1
  54. package/dist/index.js +0 -37
  55. package/dist/index.js.map +0 -1
  56. package/dist/lexer/scanner.d.ts +0 -108
  57. package/dist/lexer/scanner.d.ts.map +0 -1
  58. package/dist/lexer/scanner.js +0 -676
  59. package/dist/lexer/scanner.js.map +0 -1
  60. package/dist/lexer/states.d.ts +0 -35
  61. package/dist/lexer/states.d.ts.map +0 -1
  62. package/dist/lexer/states.js +0 -39
  63. package/dist/lexer/states.js.map +0 -1
  64. package/dist/lexer/tokens.d.ts +0 -22
  65. package/dist/lexer/tokens.d.ts.map +0 -1
  66. package/dist/lexer/tokens.js +0 -22
  67. package/dist/lexer/tokens.js.map +0 -1
  68. package/dist/limits.d.ts +0 -14
  69. package/dist/limits.d.ts.map +0 -1
  70. package/dist/limits.js +0 -23
  71. package/dist/limits.js.map +0 -1
  72. package/dist/parser.d.ts +0 -6
  73. package/dist/parser.d.ts.map +0 -1
  74. package/dist/parser.js +0 -949
  75. package/dist/parser.js.map +0 -1
  76. package/dist/providers/adapter.d.ts +0 -10
  77. package/dist/providers/adapter.d.ts.map +0 -1
  78. package/dist/providers/adapter.js +0 -2
  79. package/dist/providers/adapter.js.map +0 -1
  80. package/dist/providers/ai-sdk.d.ts +0 -54
  81. package/dist/providers/ai-sdk.d.ts.map +0 -1
  82. package/dist/providers/ai-sdk.js +0 -191
  83. package/dist/providers/ai-sdk.js.map +0 -1
  84. package/dist/providers/anthropic.d.ts +0 -45
  85. package/dist/providers/anthropic.d.ts.map +0 -1
  86. package/dist/providers/anthropic.js +0 -112
  87. package/dist/providers/anthropic.js.map +0 -1
  88. package/dist/providers/gemini.d.ts +0 -31
  89. package/dist/providers/gemini.d.ts.map +0 -1
  90. package/dist/providers/gemini.js +0 -94
  91. package/dist/providers/gemini.js.map +0 -1
  92. package/dist/providers/openai-compatible.d.ts +0 -33
  93. package/dist/providers/openai-compatible.d.ts.map +0 -1
  94. package/dist/providers/openai-compatible.js +0 -160
  95. package/dist/providers/openai-compatible.js.map +0 -1
  96. package/dist/providers/openai.d.ts +0 -48
  97. package/dist/providers/openai.d.ts.map +0 -1
  98. package/dist/providers/openai.js +0 -205
  99. package/dist/providers/openai.js.map +0 -1
  100. package/dist/providers/openrouter.d.ts +0 -35
  101. package/dist/providers/openrouter.d.ts.map +0 -1
  102. package/dist/providers/openrouter.js +0 -55
  103. package/dist/providers/openrouter.js.map +0 -1
  104. package/dist/semantic/builder.d.ts +0 -55
  105. package/dist/semantic/builder.d.ts.map +0 -1
  106. package/dist/semantic/builder.js +0 -140
  107. package/dist/semantic/builder.js.map +0 -1
  108. package/dist/semantic/events.d.ts +0 -2
  109. package/dist/semantic/events.d.ts.map +0 -1
  110. package/dist/semantic/events.js +0 -5
  111. package/dist/semantic/events.js.map +0 -1
  112. package/dist/semantic/snapshot.d.ts +0 -49
  113. package/dist/semantic/snapshot.d.ts.map +0 -1
  114. package/dist/semantic/snapshot.js +0 -228
  115. package/dist/semantic/snapshot.js.map +0 -1
  116. package/dist/types.d.ts +0 -156
  117. package/dist/types.d.ts.map +0 -1
  118. package/dist/types.js +0 -5
  119. package/dist/types.js.map +0 -1
  120. package/dist/utf8/decoder.d.ts +0 -53
  121. package/dist/utf8/decoder.d.ts.map +0 -1
  122. package/dist/utf8/decoder.js +0 -323
  123. package/dist/utf8/decoder.js.map +0 -1
@@ -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,EA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AE,0BAA0B,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CAClC,CAAC;AAEN,MAAM,WAAW,qBAAqB;IACpC,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,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,KAAK,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,20 +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 coordinator's full, unfiltered diagnostics list (`snapshot().diagnostics`).
14
- * `decideExecution` splits this into per-call (`internalId` matches) and
15
- * global (`internalId` undefined) subsets itself.
16
- */
17
- readonly diagnostics: readonly CoordinatorDiagnostic[];
18
- }
19
- export declare function decideExecution(call: ToolCallState, ctx: DecisionContext): ExecuteDecision | NonExecutableDecision;
20
- //# 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,EAAE,eAAe,EAAmB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAErF,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,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,CAmHzC"}
@@ -1,127 +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 common = {
40
- internalId: call.internalId,
41
- toolCallId: call.toolCallId,
42
- toolIndex: call.toolIndex,
43
- name: call.name,
44
- stableValue: call.parser.stableValue,
45
- parserDiagnostics,
46
- coordinatorDiagnostics,
47
- };
48
- function reject(reason) {
49
- return { ...common, action: "reject", executable: false, reason };
50
- }
51
- function retry(reason) {
52
- return { ...common, action: "retry", executable: false, reason };
53
- }
54
- // --- Universal fail-closed checks ---------------------------------------
55
- // Evaluated first and unconditionally, regardless of call.status, so a
56
- // resource limit, a provider-side failure, or a content-policy
57
- // termination always wins over whatever the structural status looks like.
58
- const hasResourceLimit = parserDiagnostics.some((d) => PARSER_RESOURCE_LIMIT_CODES.has(d.code)) ||
59
- callCoordinatorDiagnostics.some((d) => COORDINATOR_RESOURCE_LIMIT_CODES.has(d.code)) ||
60
- globalCoordinatorDiagnostics.some((d) => d.code === "E_COORDINATOR_LIMIT_EVENTS");
61
- if (hasResourceLimit) {
62
- return reject("resource_limit");
63
- }
64
- if (ctx.streamEndReason === "provider_error") {
65
- return reject("provider_error");
66
- }
67
- const isContentFiltered = globalCoordinatorDiagnostics.some((d) => d.code === CONTENT_FILTERED_DIAGNOSTIC_CODE);
68
- if (isContentFiltered) {
69
- return reject("content_filtered");
70
- }
71
- // --- Status-specific handling --------------------------------------------
72
- // Exhaustive over ToolCallState["status"] with no `default`: if a future
73
- // coordinator version adds a new status literal without a matching case
74
- // here, `noImplicitReturns` fails the build - not a silent runtime gap.
75
- switch (call.status) {
76
- case "complete": {
77
- if (call.schemaValid === false) {
78
- return reject("schema_invalid");
79
- }
80
- // The ONLY positive branch in this entire function, reached only
81
- // after every disqualifying check above has already passed. The
82
- // `call.name !== undefined` check is defensive/redundant with the
83
- // coordinator's own invariant (a call only reaches status "complete"
84
- // when its name is known) - narrowing on it here is what lets
85
- // `ExecuteDecision.name` be typed as a required `string` instead of
86
- // `string | undefined`, so it never needs re-checking at every call
87
- // site. If the invariant were ever violated, this still fails closed
88
- // to "stream_incomplete" rather than fabricating a name.
89
- if (call.parser.executable === true &&
90
- call.parser.stableValue !== undefined &&
91
- call.name !== undefined) {
92
- const decision = {
93
- ...common,
94
- name: call.name,
95
- action: "execute",
96
- executable: true,
97
- reason: "complete",
98
- value: call.parser.stableValue,
99
- };
100
- return decision;
101
- }
102
- // Root closed, syntactically valid, but not trusted: the parser's
103
- // own executable contract failed it (stream-end-reason mismatch or
104
- // trailing data), even though nothing here required a repair.
105
- return retry("stream_incomplete");
106
- }
107
- case "truncated":
108
- // The parser positively observed an open string/number/literal or an
109
- // unclosed container - a real, raw mid-value cut, not a matter of
110
- // interpretation.
111
- return retry("truncated");
112
- case "invalid":
113
- // Duplicate key, unexpected token, or a missing/conflicting tool
114
- // identity - a genuine content defect, independent of how the stream
115
- // ended.
116
- return reject("malformed");
117
- case "salvaged":
118
- // Root only closed via a safe-container-closing repair; the JSON
119
- // *looks* complete, but provider metadata never confirmed genuine
120
- // completion. This is the container-level truncation case.
121
- return retry("stream_incomplete");
122
- case "cancelled":
123
- case "collecting":
124
- return retry("stream_incomplete");
125
- }
126
- }
127
- //# sourceMappingURL=decide.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/gate/decide.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mCAAmC;AACnC,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,qEAAqE;AACrE,uCAAuC;AACvC,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC5E,MAAM;AACN,8EAA8E;AAE9E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAoBtF,MAAM,2BAA2B,GAAwB,IAAI,GAAG,CAAC;IAC/D,cAAc,CAAC,aAAa;IAC5B,cAAc,CAAC,mBAAmB;IAClC,cAAc,CAAC,oBAAoB;IACnC,cAAc,CAAC,mBAAmB;CACnC,CAAC,CAAC;AAEH,MAAM,gCAAgC,GAAwB,IAAI,GAAG,CAAC;IACpE,2BAA2B;IAC3B,4BAA4B;IAC5B,mBAAmB;CACpB,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAC7B,IAAmB,EACnB,GAAoB;IAEpB,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IAClD,MAAM,0BAA0B,GAAG,GAAG,CAAC,WAAW,CAAC,MAAM,CACvD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CACxC,CAAC;IACF,MAAM,4BAA4B,GAAG,GAAG,CAAC,WAAW,CAAC,MAAM,CACzD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,SAAS,CAClC,CAAC;IACF,MAAM,sBAAsB,GAAG;QAC7B,GAAG,4BAA4B;QAC/B,GAAG,0BAA0B;KAC9B,CAAC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AC,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+DpB;;;;;;;;;;;;;;;;;;;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,80 +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.
18
- streamEndReason;
19
- streamEndCaptured = false;
20
- constructor(limits, parserOptions, toolSchemas) {
21
- this.coordinator = createToolCallStreamCoordinator(limits, parserOptions, toolSchemas);
22
- }
23
- push(event) {
24
- if (event.type === "provider_stream_end" && !this.streamEndCaptured) {
25
- this.streamEndCaptured = true;
26
- this.streamEndReason = event.reason;
27
- }
28
- return this.coordinator.push(event);
29
- }
30
- snapshot() {
31
- const snap = this.coordinator.snapshot();
32
- const ctx = {
33
- // Pre-finish, no stream-end reason has been observed yet ("unknown"
34
- // is a neutral placeholder here, not a claim anything went wrong) -
35
- // every in-flight call is still "collecting" regardless, so this
36
- // never influences whether something looks executable.
37
- streamEndReason: this.streamEndReason ?? "unknown",
38
- diagnostics: snap.diagnostics,
39
- };
40
- return snap.calls.map((call) => decideExecution(call, ctx));
41
- }
42
- drainEvents() {
43
- return this.coordinator.drainEvents();
44
- }
45
- finish(meta) {
46
- if (!this.streamEndCaptured) {
47
- this.streamEndCaptured = true;
48
- this.streamEndReason = meta?.reason ?? "unknown";
49
- }
50
- const result = this.coordinator.finish(meta);
51
- const diagnostics = this.coordinator.snapshot().diagnostics;
52
- const ctx = { streamEndReason: this.streamEndReason ?? "unknown", diagnostics };
53
- const decisions = result.calls.map((call) => decideExecution(call, ctx));
54
- return { decisions, diagnostics };
55
- }
56
- }
57
- /**
58
- * Creates a fail-closed execution-decision gate for streamed LLM tool calls.
59
- * Wraps a `ToolCallStreamCoordinator` (same constructor arguments) and adds
60
- * exactly one operation: turn each call's settled state into an
61
- * `ExecutionDecision` (`execute` / `retry` / `reject`) via a deterministic,
62
- * fully-typed decision table. See `docs/EXECUTION_GATE.md`.
63
- *
64
- * ```ts
65
- * const gate = createToolCallExecutionGate(undefined, undefined, {
66
- * write_file: { type: "object", required: ["path", "content"], properties: {
67
- * path: { type: "string" }, content: { type: "string" } } },
68
- * });
69
- * for (const raw of providerEvents) {
70
- * for (const normalized of adapter.push(raw)) gate.push(normalized);
71
- * }
72
- * for (const decision of gate.finish().decisions) {
73
- * if (decision.action === "execute") await tools[decision.name](decision.value);
74
- * }
75
- * ```
76
- */
77
- export function createToolCallExecutionGate(limits, parserOptions, toolSchemas) {
78
- return new DefaultToolCallExecutionGate(limits, parserOptions, toolSchemas);
79
- }
80
- //# 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,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AAI,CAAC,eAAe,GAAG,IAAI,EAAE,MAAM,IAAI,SAAS,CAAC;QACnD,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC;QAC5D,MAAM,GAAG,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,IAAI,SAAS,EAAE,WAAW,EAAE,CAAC;QAChF,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAEzE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IACpC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,2BAA2B,CACzC,MAAmC,EACnC,aAA6B,EAC7B,WAA4C;IAE5C,OAAO,IAAI,4BAA4B,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AAC9E,CAAC"}
@@ -1,122 +0,0 @@
1
- import { JsonValue, Diagnostic } from "../types.js";
2
- import { CoordinatorDiagnostic, CoordinatorPushResult, ToolCallCoordinatorEvent } from "../coordinator/types.js";
3
- import { NormalizedToolStreamEvent, 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
- interface ExecutionDecisionCommon {
23
- /** The coordinator's internal call identifier (see `ToolCallState.internalId`). */
24
- readonly internalId: string;
25
- readonly toolCallId?: string;
26
- readonly toolIndex?: number;
27
- readonly name?: string;
28
- /**
29
- * Whatever was safely committed for this call, complete or not - present
30
- * for both executable and non-executable decisions so a caller can see
31
- * *what part* of a rejected/retried call was genuinely received (e.g. a
32
- * `path` field that arrived before a `content` field got cut off).
33
- * Never the source of truth for whether it's safe to act on - that's
34
- * `action`/`executable`. Absent only when nothing was ever committed.
35
- */
36
- readonly stableValue?: JsonValue;
37
- /** This call's own parser diagnostics, verbatim (`ToolCallState.parser.diagnostics`). */
38
- readonly parserDiagnostics: readonly Diagnostic[];
39
- /** Coordinator-level diagnostics attributable to this call, verbatim. */
40
- readonly coordinatorDiagnostics: readonly CoordinatorDiagnostic[];
41
- }
42
- /**
43
- * The one and only shape a decision can have when `action === "execute"`.
44
- * `value` is a real, present `JsonValue` here - never `undefined`, never
45
- * optional - because this is the single positive case: everything else in
46
- * the gate exists to rule this out unless it's genuinely earned.
47
- */
48
- export interface ExecuteDecision extends ExecutionDecisionCommon {
49
- readonly action: "execute";
50
- readonly executable: true;
51
- readonly reason: "complete";
52
- readonly value: JsonValue;
53
- /**
54
- * Narrowed to required here (unlike the inherited `name?: string`):
55
- * the coordinator only ever transitions a call to `status: "complete"`
56
- * when `name` is defined (see `DefaultToolCallStreamCoordinator.finishCall`
57
- * - a call with no name is forced to `"invalid"` instead), so every
58
- * `ExecuteDecision` genuinely has one. Encoding that here means
59
- * `tools[decision.name](decision.value)` type-checks directly after
60
- * narrowing on `action === "execute"`, with no non-null assertion needed.
61
- */
62
- readonly name: string;
63
- }
64
- /**
65
- * Every other outcome. `value` does not exist on this type at all (not
66
- * `undefined` - absent) - TypeScript itself refuses code that reads a
67
- * "final executable value" off a call the gate did not clear for execution.
68
- */
69
- export interface NonExecutableDecision extends ExecutionDecisionCommon {
70
- readonly action: "retry" | "reject";
71
- readonly executable: false;
72
- readonly reason: Exclude<ExecutionReason, "complete">;
73
- }
74
- /**
75
- * `ExecuteDecision | NonExecutableDecision` - a discriminated union on
76
- * `action` (and redundantly on `executable`, for callers who prefer that
77
- * check). Narrowing on either field gives you the right shape:
78
- *
79
- * ```ts
80
- * if (decision.action === "execute") {
81
- * await tools[decision.name](decision.value); // JsonValue, not JsonValue|undefined
82
- * }
83
- * ```
84
- */
85
- export type ExecutionDecision = ExecuteDecision | NonExecutableDecision;
86
- export interface ToolCallExecutionGateFinalResult {
87
- /** One decision per tool call the coordinator ever created. */
88
- readonly decisions: readonly ExecutionDecision[];
89
- /**
90
- * The full, unfiltered coordinator diagnostics list (same as
91
- * `coordinator.snapshot().diagnostics`) - includes diagnostics with no
92
- * associated call, e.g. `E_COORDINATOR_LIMIT_CALLS` fires for a call that
93
- * hit the concurrent-call limit before a `ToolCallState` could even be
94
- * created for it, so it can never appear in `decisions`.
95
- */
96
- readonly diagnostics: readonly CoordinatorDiagnostic[];
97
- }
98
- /**
99
- * High-level fail-closed execution decision layer built on top of
100
- * `ToolCallStreamCoordinator`. Answers one question per tool call: is it
101
- * safe to execute right now? Callers never need to touch parser lexical
102
- * state, coordinator event mechanics, or JSON Pointer paths - push provider
103
- * events in, read `ExecutionDecision`s out.
104
- */
105
- export interface ToolCallExecutionGate {
106
- push(event: NormalizedToolStreamEvent): CoordinatorPushResult;
107
- /**
108
- * In-flight view. Every decision here is `"retry"` or `"reject"` -
109
- * `"execute"` is only ever returned once the stream has genuinely
110
- * finished (see `finish()`), since schema validity and prefix-safety are
111
- * both only meaningful once a call has settled.
112
- */
113
- snapshot(): readonly ExecutionDecision[];
114
- /** Drains the underlying coordinator's raw event queue, for advanced/UI consumers. */
115
- drainEvents(): readonly ToolCallCoordinatorEvent[];
116
- finish(meta?: {
117
- reason?: StreamEndReason;
118
- providerReason?: string;
119
- }): ToolCallExecutionGateFinalResult;
120
- }
121
- export {};
122
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
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,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAExF;;;;;;;;;;;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,UAAU,uBAAuB;IAC/B,mFAAmF;IACnF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC;IAEjC,yFAAyF;IACzF,QAAQ,CAAC,iBAAiB,EAAE,SAAS,UAAU,EAAE,CAAC;IAElD,yEAAyE;IACzE,QAAQ,CAAC,sBAAsB,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACnE;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,QAAQ,CAAC,M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