@aeye/core 0.5.4 → 0.6.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 (117) hide show
  1. package/README.md +51 -4
  2. package/aeye-core-schema.md +11 -7
  3. package/dist/common.d.ts +30 -5
  4. package/dist/common.d.ts.map +1 -1
  5. package/dist/common.js +134 -129
  6. package/dist/common.js.map +1 -1
  7. package/dist/delivery.d.ts +39 -0
  8. package/dist/delivery.d.ts.map +1 -0
  9. package/dist/delivery.js +127 -0
  10. package/dist/delivery.js.map +1 -0
  11. package/dist/errors.d.ts +60 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +84 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/prompt.d.ts +101 -9
  20. package/dist/prompt.d.ts.map +1 -1
  21. package/dist/prompt.js +163 -141
  22. package/dist/prompt.js.map +1 -1
  23. package/dist/schema/analyze.d.ts +94 -0
  24. package/dist/schema/analyze.d.ts.map +1 -0
  25. package/dist/schema/analyze.js +221 -0
  26. package/dist/schema/analyze.js.map +1 -0
  27. package/dist/schema/any-value.d.ts +32 -0
  28. package/dist/schema/any-value.d.ts.map +1 -0
  29. package/dist/schema/any-value.js +77 -0
  30. package/dist/schema/any-value.js.map +1 -0
  31. package/dist/schema/budget.d.ts +114 -0
  32. package/dist/schema/budget.d.ts.map +1 -0
  33. package/dist/schema/budget.js +223 -0
  34. package/dist/schema/budget.js.map +1 -0
  35. package/dist/schema/consistency.d.ts +27 -0
  36. package/dist/schema/consistency.d.ts.map +1 -0
  37. package/dist/schema/consistency.js +110 -0
  38. package/dist/schema/consistency.js.map +1 -0
  39. package/dist/schema/cycle-breaker.d.ts +14 -0
  40. package/dist/schema/cycle-breaker.d.ts.map +1 -0
  41. package/dist/schema/cycle-breaker.js +157 -0
  42. package/dist/schema/cycle-breaker.js.map +1 -0
  43. package/dist/schema/decode.d.ts +31 -0
  44. package/dist/schema/decode.d.ts.map +1 -0
  45. package/dist/schema/decode.js +207 -0
  46. package/dist/schema/decode.js.map +1 -0
  47. package/dist/schema/descriptor.d.ts +300 -0
  48. package/dist/schema/descriptor.d.ts.map +1 -0
  49. package/dist/schema/descriptor.js +15 -0
  50. package/dist/schema/descriptor.js.map +1 -0
  51. package/dist/schema/dialects/anthropic.d.ts +34 -0
  52. package/dist/schema/dialects/anthropic.d.ts.map +1 -0
  53. package/dist/schema/dialects/anthropic.js +77 -0
  54. package/dist/schema/dialects/anthropic.js.map +1 -0
  55. package/dist/schema/dialects/google.d.ts +47 -0
  56. package/dist/schema/dialects/google.d.ts.map +1 -0
  57. package/dist/schema/dialects/google.js +91 -0
  58. package/dist/schema/dialects/google.js.map +1 -0
  59. package/dist/schema/dialects/lenient.d.ts +4 -0
  60. package/dist/schema/dialects/lenient.d.ts.map +1 -0
  61. package/dist/schema/dialects/lenient.js +26 -0
  62. package/dist/schema/dialects/lenient.js.map +1 -0
  63. package/dist/schema/dialects/openai.d.ts +40 -0
  64. package/dist/schema/dialects/openai.d.ts.map +1 -0
  65. package/dist/schema/dialects/openai.js +81 -0
  66. package/dist/schema/dialects/openai.js.map +1 -0
  67. package/dist/schema/dialects/xai.d.ts +23 -0
  68. package/dist/schema/dialects/xai.d.ts.map +1 -0
  69. package/dist/schema/dialects/xai.js +53 -0
  70. package/dist/schema/dialects/xai.js.map +1 -0
  71. package/dist/schema/enum-values.d.ts +44 -0
  72. package/dist/schema/enum-values.d.ts.map +1 -0
  73. package/dist/schema/enum-values.js +56 -0
  74. package/dist/schema/enum-values.js.map +1 -0
  75. package/dist/schema/expressible.d.ts +59 -0
  76. package/dist/schema/expressible.d.ts.map +1 -0
  77. package/dist/schema/expressible.js +161 -0
  78. package/dist/schema/expressible.js.map +1 -0
  79. package/dist/schema/index.d.ts +20 -0
  80. package/dist/schema/index.d.ts.map +1 -0
  81. package/dist/schema/index.js +20 -0
  82. package/dist/schema/index.js.map +1 -0
  83. package/dist/schema/json-schema.d.ts +64 -0
  84. package/dist/schema/json-schema.d.ts.map +1 -0
  85. package/dist/schema/json-schema.js +2 -0
  86. package/dist/schema/json-schema.js.map +1 -0
  87. package/dist/schema/registry.d.ts +73 -0
  88. package/dist/schema/registry.d.ts.map +1 -0
  89. package/dist/schema/registry.js +135 -0
  90. package/dist/schema/registry.js.map +1 -0
  91. package/dist/schema/strictify.d.ts +19 -0
  92. package/dist/schema/strictify.d.ts.map +1 -0
  93. package/dist/schema/strictify.js +237 -0
  94. package/dist/schema/strictify.js.map +1 -0
  95. package/dist/schema/to-json-schema.d.ts +29 -0
  96. package/dist/schema/to-json-schema.d.ts.map +1 -0
  97. package/dist/schema/to-json-schema.js +691 -0
  98. package/dist/schema/to-json-schema.js.map +1 -0
  99. package/dist/schema/walk-key.d.ts +24 -0
  100. package/dist/schema/walk-key.d.ts.map +1 -0
  101. package/dist/schema/walk-key.js +33 -0
  102. package/dist/schema/walk-key.js.map +1 -0
  103. package/dist/to.js +1 -1
  104. package/dist/to.js.map +1 -1
  105. package/dist/tool.d.ts +32 -3
  106. package/dist/tool.d.ts.map +1 -1
  107. package/dist/tool.js +41 -0
  108. package/dist/tool.js.map +1 -1
  109. package/dist/types.d.ts +265 -8
  110. package/dist/types.d.ts.map +1 -1
  111. package/dist/types.js +4 -1
  112. package/dist/types.js.map +1 -1
  113. package/package.json +72 -72
  114. package/dist/schema.d.ts +0 -840
  115. package/dist/schema.d.ts.map +0 -1
  116. package/dist/schema.js +0 -2478
  117. package/dist/schema.js.map +0 -1
package/dist/schema.d.ts DELETED
@@ -1,840 +0,0 @@
1
- import z from 'zod';
2
- /**
3
- * Provider family for a `FormatDescriptor`. The three known wire dialects
4
- * (`'openai'`, `'anthropic'`, `'google'`) are autocomplete hints; any string
5
- * is accepted so users can register custom descriptors via
6
- * `registerDescriptor` and reference them by family name in
7
- * `ModelInfo.strictFormat`. `'lenient'` is the no-rewrite catch-all and is
8
- * not registerable as a custom family.
9
- *
10
- * Use this type wherever you need to talk about a descriptor family —
11
- * registry functions, model declarations, etc.
12
- */
13
- export type DescriptorFamily = 'openai' | 'anthropic' | 'google' | (string & {});
14
- /**
15
- * Documented ceilings on how BIG one strict schema may be, as opposed to which
16
- * keywords it may use. Every limit here is a SUM taken over a single schema —
17
- * one tool's `parameters`, or one structured-output schema — not a per-request
18
- * allowance shared between them (that is `maxStrictTools` and friends, which
19
- * the `SchemaBudget` spends across the whole request).
20
- *
21
- * A schema that exceeds one of these is a guaranteed provider rejection under
22
- * strict mode, so `SchemaBudget.allocate` treats it like any other
23
- * infeasibility and degrades that ONE item to the family's non-strict
24
- * descriptor, where no size rule applies. The rest of the request is
25
- * unaffected.
26
- *
27
- * Declared as one object rather than six optional fields on purpose: a
28
- * provider documents these together, and the object being present is what says
29
- * "this dialect publishes size limits". Adding a rule here is then a compile
30
- * error at every descriptor that declares the group, which is the point
31
- * (a missed limit is invisible until a 400).
32
- */
33
- export interface SchemaSizeLimits {
34
- /** Maximum object properties in one schema, summed over every nesting level. */
35
- readonly maxObjectProperties: number;
36
- /** Maximum levels of nested containers below the schema root. */
37
- readonly maxNestingDepth: number;
38
- /**
39
- * Maximum total characters over the schema's property names, `enum` values
40
- * and `const` values together.
41
- */
42
- readonly maxTotalStringChars: number;
43
- /** Maximum `enum` values summed across every enum property in one schema. */
44
- readonly maxTotalEnumValues: number;
45
- /**
46
- * The single-enum value count above which `maxLargeEnumStringChars` starts
47
- * to apply. A smaller enum is bounded only by the two totals above.
48
- */
49
- readonly largeEnumValueCount: number;
50
- /**
51
- * Maximum total characters of ONE enum's string values, applied only to an
52
- * enum carrying more than `largeEnumValueCount` values.
53
- */
54
- readonly maxLargeEnumStringChars: number;
55
- }
56
- /**
57
- * Format descriptor — describes the JSON Schema dialect of a target.
58
- *
59
- * Each provider/strict combination is represented by one descriptor. The
60
- * descriptor controls both how `strictify` rewrites a Zod schema (preprocesses
61
- * for record-as-array, tuple-as-object, etc.) and how `toJSONSchema` emits the
62
- * matching JSON Schema. Every `if (strict)` decision in the conversion
63
- * pipeline dispatches off a descriptor field, so adding a new dialect is a
64
- * matter of declaring a new `FormatDescriptor` and registering it.
65
- */
66
- export interface FormatDescriptor {
67
- /** Stable id used as the cache key inside `strictify`. */
68
- readonly id: string;
69
- /**
70
- * Provider family for this descriptor. The three built-in wire dialects
71
- * are `'openai'` / `'anthropic'` / `'google'`; `'lenient'` is the
72
- * no-rewrite catch-all. Custom descriptors registered via
73
- * `registerDescriptor` may use any string here — the family is the
74
- * lookup key used by `getDescriptor(family, strict)`.
75
- */
76
- readonly family: DescriptorFamily | 'lenient';
77
- /** True if this descriptor represents the strict variant for its family. */
78
- readonly strict: boolean;
79
- /** When true, every object field appears in `required[]` (OpenAI strict). */
80
- readonly objectAllFieldsRequired: boolean;
81
- /** When true, every object emits `additionalProperties: false`. */
82
- readonly objectClosedByDefault: boolean;
83
- /** How to encode `z.record(K, V)`. */
84
- readonly recordEncoding: 'array-of-pairs' | 'open-record';
85
- /**
86
- * How to encode `z.tuple([...])`.
87
- * - `object-numeric-keys`: OpenAI-strict workaround (`{ "0": A, "1": B, ... }`)
88
- * - `prefix-items`: standard JSON Schema `prefixItems` (Anthropic / Google)
89
- * - `items-union`: collapse to homogeneous `items: { anyOf: [...] }` (last-resort)
90
- */
91
- readonly tupleEncoding: 'object-numeric-keys' | 'prefix-items' | 'items-union';
92
- readonly allowAllOf: boolean;
93
- readonly allowAnyOf: boolean;
94
- readonly allowOneOf: boolean;
95
- /** Whether `{ $ref: '#' }` self-reference is permitted. */
96
- readonly allowRootRef: boolean;
97
- readonly allowDefsRef: boolean;
98
- /** Reserved: emit Google-style `propertyOrdering` hints. */
99
- readonly emitPropertyOrdering: boolean;
100
- /** Whitelist of `format:` values to emit, or `'all'` to pass through. */
101
- readonly supportedStringFormats: ReadonlySet<string> | 'all';
102
- readonly allowPattern: boolean;
103
- readonly allowMultiplePatterns: boolean;
104
- readonly allowMinMaxLength: boolean;
105
- readonly allowMinMaxItems: boolean;
106
- readonly allowMinimumMaximum: boolean;
107
- /** When true, `optional` becomes `T|null` (because every prop must be required). */
108
- readonly optionalAsNullable: boolean;
109
- /**
110
- * How `z.any()` / `z.unknown()` is encoded.
111
- * - `recursive-strict`: self-referencing $defs/Any with array-of-pairs records
112
- * (OpenAI strict has no open-object support). REQUIRES `allowAnyOf` and
113
- * `allowDefsRef`.
114
- * - `recursive-open`: $defs/Any with `additionalProperties: <self>` records.
115
- * REQUIRES `allowAnyOf` and `allowDefsRef`.
116
- * - `flat`: a non-recursive `anyOf` over the JSON value types
117
- * (`string`/`number`/`boolean`/`null`/`array`/open-`object`). Used by
118
- * descriptors that reject recursive `$defs/Any` definitions (Anthropic
119
- * strict). Equivalent to TypeScript `any` — accepts every JSON value
120
- * without imposing any structural constraints. REQUIRES `allowAnyOf`
121
- * (no `$defs` needed).
122
- * - `unconstrained`: the empty schema `{}` (plus any `description`). Per
123
- * JSON Schema, a schema with no assertion keywords validates EVERY
124
- * instance — which is exactly what "any JSON value" means — and it
125
- * introduces no keyword a restrictive dialect could reject. REQUIRES
126
- * NOTHING, so it's the only encoding available to a dialect that forbids
127
- * both combinators and named `$defs`/`$ref` (Google — see `GOOGLE_STRICT`).
128
- *
129
- * The `REQUIRES` notes above are enforced by `checkDescriptorConsistency`,
130
- * which `registerDescriptor` runs so a self-contradictory descriptor is
131
- * caught at declaration time rather than as a provider HTTP 400.
132
- */
133
- readonly anyEncoding: 'recursive-strict' | 'recursive-open' | 'flat' | 'unconstrained';
134
- /** Maximum number of tools that can carry `strict: true` in one request. */
135
- readonly maxStrictTools?: number;
136
- /** Maximum total optional parameters across all strict schemas in one request. */
137
- readonly maxStrictOptionalParams?: number;
138
- /** Maximum total union-type parameters across all strict schemas in one request. */
139
- readonly maxStrictUnionTypes?: number;
140
- /**
141
- * Documented ceilings on the SIZE of one strict schema (properties, nesting,
142
- * total string bytes, enum values), or `undefined` when the dialect
143
- * publishes none. See {@link SchemaSizeLimits} for what each bound counts and
144
- * why it is per-schema rather than per-request.
145
- *
146
- * Only a STRICT descriptor declares these: they are Structured-Outputs rules
147
- * — the API compiles the schema into a decoder and rejects one it cannot —
148
- * and a non-strict schema is a best-effort hint the API does not compile. So
149
- * degrading the offending item to the family's non-strict descriptor is both
150
- * the fix and the reason the limits stop applying to it
151
- * (`SchemaBudget.allocate`, `checkSchemaSizeLimits`).
152
- *
153
- * The measurement is taken from the ZOD schema, not from the emitted JSON,
154
- * so it is deliberately CONSERVATIVE where an encoding is descriptor-
155
- * dependent (a record counts as its widest encoding, a tuple as its
156
- * numeric-key one). Over-counting costs strictness on a schema that would
157
- * have fit; under-counting costs an HTTP 400, so the round goes up.
158
- */
159
- readonly schemaSizeLimits?: SchemaSizeLimits;
160
- /**
161
- * Maximum number of values ONE emitted `enum` may carry, or `undefined`
162
- * (the default) for no cap.
163
- *
164
- * This is deliberately NOT one of the per-request budget fields above. Those
165
- * are strict-mode allowances the SchemaBudget spends across a whole request,
166
- * degrading an item that no longer fits to the family's non-strict
167
- * descriptor; this one is a property of the dialect itself — it fires whatever the strictness — so it is enforced
168
- * structurally at the point an `enum` is emitted (`convertSchema`), where
169
- * the cardinality is actually known.
170
- *
171
- * Over the cap the emitter **widens** rather than truncates: it drops the
172
- * `enum` keyword entirely, emits the node's plain scalar `type`
173
- * (`{type: 'string'}` for a string enum), and puts EVERY value into the
174
- * node's `description`. Nothing becomes unreachable — the model still has
175
- * the complete list and can name any member — and the cardinality the
176
- * dialect could not compile is simply no longer on the wire.
177
- *
178
- * The trade this makes is enforcement: a widened node no longer rejects a
179
- * value structurally, so whatever validates the model's output afterwards
180
- * has to. `Tool.parse` does, against the ORIGINAL zod schema — the enum is
181
- * still there, only the emitted JSON Schema widened — so a hallucinated
182
- * member comes back as a normal, re-promptable validation error.
183
- *
184
- * **`GOOGLE_STRICT`/`GOOGLE_NON_STRICT` declare 40. Every other built-in
185
- * declares no cap.** Two earlier rounds of live measurement against
186
- * `google/gemini-3-flash-preview` through OpenRouter (2026-08-23) — single
187
- * enums up to 2048 SYNTHETIC values, 20 tools each with a 96-value enum, and
188
- * an eleven-tool roster modelled on a real kind-authoring agent — all
189
- * returned HTTP 200 and concluded there was no reproducible limit. **That
190
- * conclusion was wrong, because none of those enums used the CONTENT of a
191
- * real session.** A third round replayed the exact wire bytes of a real
192
- * product request — `fn_load`'s `names` array, enum-constrained to the
193
- * session's actual 98 known component/fn names (`default_renderer`,
194
- * `QueryWidget`, `ConfirmPrompt`, `list_widget_types`, …) — and it 400'd,
195
- * reproducibly, twice, byte-for-byte identical to what the provider was
196
- * actually sent. Bisecting that same real value list: 90 values passes, 93
197
- * fails. Bisecting what changes between the passing synthetic probes and the
198
- * failing real one: 98 SHORT synthetic values (`n0`..`n97`, 284 chars) pass;
199
- * 206 short values matching the REAL list's total character count (714
200
- * chars) also pass; only the REAL, longer, dictionary-like/identifier-shaped
201
- * values fail, and only past ~92 of them. So the limit tracks neither raw
202
- * member count nor total character/byte budget — most likely actual
203
- * tokenized grammar-state count, which short repetitive synthetic strings
204
- * compress far below what real identifier text does at the same count or
205
- * character budget. This is why the first two rounds' synthetic and
206
- * lightly-realistic probes never tripped it.
207
- *
208
- * **The widen-to-string fallback this field triggers was verified against
209
- * the exact failing real schema**: dropping `enum` and putting the same 98
210
- * values into the `description` of a plain string field returned HTTP 200
211
- * with the expected tool call — confirming the fallback mechanism actually
212
- * fixes the failure it exists for, not just a synthetic stand-in.
213
- *
214
- * **40 is not a measured edge — it is a conservative floor with roughly 2x
215
- * margin under the real one (90 passes / 93 fails) measured on this one real
216
- * value set.** Given the failure tracks content, not just count, a different
217
- * session's actual name list could plausibly fail at a different count; 40
218
- * was also the cap this exact product ran under in production for months
219
- * before a since-reverted attempt to remove it, which is corroborating
220
- * evidence it holds in practice, not just in this one measurement.
221
- *
222
- * The reliability comparison from the earlier rounds still stands and is
223
- * why a cap is preferable to leaving every enum uncapped "to be safe" at a
224
- * much lower number: `enum` vs plain-string-with-full-list, 10 trials each
225
- * over confusable near-duplicate names at 96 and 512 values, scored 10/10
226
- * on-target with zero off-list answers for BOTH encodings. So there is no
227
- * reliability cost to raising this cap later if a higher safe value is
228
- * measured — only downside risk to leaving it too high.
229
- *
230
- * One trap for whoever measures this next: with `max_tokens` at 64, a
231
- * forced-tool probe can come back `finish_reason: 'length'` with no tool
232
- * call and empty content, which reads exactly like a grammar that produced
233
- * nothing. It usually is not — this model spends reasoning tokens first.
234
- * Give a forced-tool probe room before calling an empty completion a
235
- * failure.
236
- *
237
- * So: set this only where a provider is MEASURED to reject a large enum
238
- * using the SESSION'S OWN real content, not synthetic stand-ins, and set it
239
- * conservatively below the measured edge until more value sets are tested.
240
- * An `enum` that fits is the more correct encoding, because it is the one
241
- * the model cannot answer outside of.
242
- */
243
- readonly maxEnumValues?: number;
244
- /**
245
- * Whether the descriptor can express recursive `$ref` schemas (`$ref: '#'`
246
- * to root, or any `$ref: '#/$defs/X'` whose target transitively references
247
- * itself). OpenAI / Google strict / Lenient: true. Anthropic strict: false
248
- * — Anthropic's tool `input_schema` validator explicitly rejects circular
249
- * `$defs` graphs.
250
- *
251
- * When `false`, the JSON-Schema emitter detects cycles in the source
252
- * schema and replaces the offending back-edge with the descriptor's flat
253
- * "any" shape (see `anyEncoding`) carrying a description that names the
254
- * `$defs` entry it would otherwise have referenced. Non-cyclic shared
255
- * `$ref` reuse is unaffected — those still emit as a `$ref` to a `$defs`
256
- * entry.
257
- */
258
- readonly supportsRecursion: boolean;
259
- /**
260
- * Instruction appended after the schema text when a Prompt's/Tool's schema
261
- * can't be expressed as this descriptor's structured output and is instead
262
- * delivered to the model as PROMPT TEXT (see `canExpress` and the ai-layer
263
- * `applySchemaDeliveryFallback`). Steers the model to emit a single raw JSON
264
- * object rather than echoing the schema or wrapping it in prose/fences.
265
- *
266
- * Optional — descriptors that omit it fall back to
267
- * `DEFAULT_JSON_FALLBACK_INSTRUCTION` via `getJsonFallbackInstruction`.
268
- */
269
- readonly jsonFallbackInstruction?: string;
270
- }
271
- /**
272
- * Default instruction used when a `FormatDescriptor` omits
273
- * `jsonFallbackInstruction`. Appended after the schema text when a schema is
274
- * delivered as prompt text instead of as structured output.
275
- */
276
- export declare const DEFAULT_JSON_FALLBACK_INSTRUCTION = "Return ONLY a single raw JSON object conforming to the schema above \u2014 no markdown code fences, no prose, and do NOT echo the schema itself.";
277
- /**
278
- * Resolve the prompt-text fallback instruction for a descriptor, falling back
279
- * to `DEFAULT_JSON_FALLBACK_INSTRUCTION` when the descriptor doesn't declare
280
- * one of its own.
281
- */
282
- export declare function getJsonFallbackInstruction(descriptor: FormatDescriptor): string;
283
- /** Lenient descriptor — no rewrites, no closure, formats pass through. Default for unsupported models. */
284
- export declare const LENIENT: FormatDescriptor;
285
- /**
286
- * OpenAI strict — current behavior verbatim. Records→pairs,
287
- * tuples→numeric-keys, optional→nullable.
288
- *
289
- * No documented per-request slot limit (max strict tools / optional params /
290
- * union types) — the SchemaBudget treats those caps as `undefined` for OpenAI.
291
- *
292
- * OpenAI DOES document per-SCHEMA size limits for Structured Outputs, and they
293
- * are declared below (`schemaSizeLimits`). Verified against
294
- * developers.openai.com/api/docs/guides/structured-outputs on 2026-08-23,
295
- * section "Supported schemas": *"A schema may have up to 5000 object
296
- * properties total, with up to 10 levels of nesting"*, *"total string length of
297
- * all property names, definition names, enum values, and const values cannot
298
- * exceed 120,000 characters"*, *"A schema may have up to 1000 enum values
299
- * across all enum properties"*, and *"For a single enum property with string
300
- * values, the total string length of all enum values cannot exceed 15,000
301
- * characters when there are more than 250 enum values"*. Every one of those
302
- * numbers was raised in July 2025 (100→5000 properties, 15,000→120,000
303
- * characters, 500→1000 enum values, 7,500→15,000 for the >250-value enum) —
304
- * the pre-raise figures are still widely quoted secondhand, so they are named
305
- * here to keep a future reader from "correcting" these downward.
306
- *
307
- * Scope is Structured Outputs, i.e. a tool carrying `strict: true` or a
308
- * `json_schema` response format — the function-calling guide defines strict
309
- * mode as "leveraging our structured outputs feature", and non-strict function
310
- * calling is best-effort with no compiled decoder. That is exactly why
311
- * degrading the over-size item to `OPENAI_NON_STRICT` is a complete answer.
312
- */
313
- export declare const OPENAI_STRICT: FormatDescriptor;
314
- /** OpenAI non-strict — alias of LENIENT but tagged with the openai family. */
315
- export declare const OPENAI_NON_STRICT: FormatDescriptor;
316
- /**
317
- * Anthropic strict — Claude 4.5+ only (Opus 4.7/4.6/4.5, Sonnet 4.6/4.5,
318
- * Haiku 4.5). Per Anthropic's structured-outputs docs:
319
- *
320
- * - `additionalProperties` may **only** be `false` (no schema-valued open
321
- * records), so `z.record(...)` falls back to the OpenAI-style
322
- * array-of-pairs workaround.
323
- * - Non-cyclic `$ref` / `$defs` reuse is supported and used freely — only
324
- * *circular* `$defs` graphs are rejected by the API
325
- * (`Circular reference detected in schema definitions: …`). The emitter
326
- * sets `supportsRecursion: false` so the cycle-breaker replaces the
327
- * offending back-edge with the flat "any" shape (see `anyEncoding`) and
328
- * leaves shared non-cyclic `$ref`s alone. Root self-reference (`$ref: '#'`)
329
- * is always cyclic by definition, so `allowRootRef` stays `false`.
330
- * - Numerical (`minimum`/`maximum`/`multipleOf`) and string-length
331
- * (`minLength`/`maxLength`) constraints are not supported and are dropped.
332
- * - `prefixItems` and other positional tuple keywords are not in the
333
- * supported list, so tuples collapse to a homogeneous `items: anyOf`.
334
- * - Supported formats include `uri` (unlike OpenAI strict). We pass all
335
- * formats through and let Anthropic ignore unknowns.
336
- */
337
- export declare const ANTHROPIC_STRICT: FormatDescriptor;
338
- export declare const ANTHROPIC_NON_STRICT: FormatDescriptor;
339
- /**
340
- * Google Gemini strict — per `ai.google.dev/gemini-api/docs/structured-output`:
341
- *
342
- * - Supported keywords: types, `properties`, `required`, `additionalProperties`,
343
- * `enum`, `format` (date-time/date/time only), `minimum`, `maximum`, `items`,
344
- * `prefixItems`, `minItems`, `maxItems`, `title`, `description`,
345
- * `propertyOrdering`. Recursion via `$ref: "#"` (root self-ref).
346
- * - Combinators (`allOf`, `anyOf`, `oneOf`) are NOT in the supported list;
347
- * we conservatively flag them off so unions degrade to a representable form
348
- * rather than emit something Gemini ignores.
349
- * - String constraints (`minLength`, `maxLength`, `pattern` formats beyond the
350
- * three documented) are not supported.
351
- * - `propertyOrdering` is REQUIRED for Gemini 2.0 strict; we always emit it
352
- * on object schemas under this descriptor.
353
- * - `z.any()` / `z.unknown()` uses the `unconstrained` encoding. Every other
354
- * "any" encoding needs `anyOf` and/or a named `$defs/Any` — both of which
355
- * this descriptor forbids two lines below — so the recursive `$defs/Any`
356
- * this descriptor used to declare was a schema it says it cannot emit.
357
- * Gemini compiles the tool schemas into a decoding grammar whenever the
358
- * caller forces a tool call (`toolChoice: 'required'` → Google's function
359
- * calling mode `ANY`), and a self-referencing `$defs/Any` failed that
360
- * compile with `400 INVALID_ARGUMENT` — the same request succeeded under
361
- * `toolChoice: 'auto'`, where no grammar is built. Reported against
362
- * `google/gemini-3-flash-preview` via OpenRouter as 100% reproducible.
363
- *
364
- * **That 400 no longer reproduces (re-measured 2026-08-23)** and the
365
- * encoding stays anyway. Same model, same route, upstream pinned to Google
366
- * AI Studio with fallbacks off, `tool_choice` forced to one named tool: the
367
- * hand-built recursive `$defs/Any` tool, and the product's real 32 KB gin
368
- * `api_set` schema carrying nine `#/$defs/Any` references, both answered
369
- * HTTP 200 with a valid tool call. So the upstream either fixed or now
370
- * sanitizes it. The descriptor still declares what this dialect's own
371
- * documented keyword list supports; depending on a provider's current
372
- * leniency for a shape we say it cannot express is how the first version of
373
- * this descriptor shipped a guaranteed 400 in the first place.
374
- */
375
- export declare const GOOGLE_STRICT: FormatDescriptor;
376
- /**
377
- * Google Gemini non-strict — LENIENT's permissive rules EXCEPT for the "any"
378
- * encoding.
379
- *
380
- * Gemini rejects a self-referencing `$defs/Any` when it has to build a
381
- * decoding grammar, and it builds one whenever a tool call is forced —
382
- * independent of any per-tool `strict` flag, which Google's function-calling
383
- * API doesn't even have. So the `unconstrained` encoding is a property of the
384
- * DIALECT, not of strict mode, and belongs on both Google descriptors.
385
- *
386
- * Everything else stays LENIENT deliberately: the restrictions on
387
- * `GOOGLE_STRICT` come from the documented structured-output keyword list,
388
- * which is a grammar-mode concern, and tightening them here would push
389
- * ordinary Gemini schemas onto the prompt-text delivery fallback for no
390
- * measured reason.
391
- */
392
- export declare const GOOGLE_NON_STRICT: FormatDescriptor;
393
- /**
394
- * Report the ways a `FormatDescriptor` contradicts itself — settings that ask
395
- * the emitter to produce a keyword the same descriptor forbids, or a limit
396
- * that would quietly strip every constraint it governs. Returns one
397
- * human-readable line per problem; an empty array means the descriptor is
398
- * internally consistent.
399
- *
400
- * This exists because a contradiction here is invisible until a provider
401
- * answers HTTP 400: `GOOGLE_STRICT` shipped with `allowAnyOf: false` +
402
- * `allowDefsRef: false` AND `anyEncoding: 'recursive-open'` (which needs
403
- * both), so every `z.any()` in a Gemini tool schema emitted exactly the
404
- * `anyOf` + `$defs/Any` shape the descriptor declared unrepresentable.
405
- * Nothing checked, so nothing caught it.
406
- *
407
- * Called by `registerDescriptor` (which warns) and asserted over every
408
- * built-in by the test suite.
409
- *
410
- * @example
411
- * ```ts
412
- * checkDescriptorConsistency(GOOGLE_STRICT); // → []
413
- * checkDescriptorConsistency({ ...GOOGLE_STRICT, anyEncoding: 'flat' });
414
- * // → ["anyEncoding 'flat' emits `anyOf`, but allowAnyOf is false"]
415
- * ```
416
- */
417
- export declare function checkDescriptorConsistency(descriptor: FormatDescriptor): string[];
418
- /**
419
- * Register a custom `FormatDescriptor` so it can be looked up by `id` or
420
- * by `(family, strict)`. Useful for adding support for a new provider
421
- * dialect or for registering a tweaked variant of an existing family.
422
- *
423
- * The descriptor's `id` and `family` become the lookup keys. If a
424
- * descriptor with the same id is already registered, the new one
425
- * replaces it. The family slot tracks one strict and one lenient
426
- * variant; registering a third variant overwrites the matching slot.
427
- *
428
- * Built-in descriptors (`OPENAI_STRICT`, `LENIENT`, etc.) are seeded at
429
- * module load — you don't need to register them manually. They CAN be
430
- * overridden by registering a same-id descriptor afterwards, but doing
431
- * so is generally a sign that you should pick a different id.
432
- *
433
- * @example
434
- * ```ts
435
- * import { registerDescriptor, OPENAI_STRICT } from '@aeye/core';
436
- *
437
- * // A tighter OpenAI-flavored descriptor: same wire shape but with
438
- * // pattern support disabled (some downstream tools choke on regex).
439
- * registerDescriptor({
440
- * ...OPENAI_STRICT,
441
- * id: 'openai-no-regex',
442
- * family: 'openai-no-regex',
443
- * allowPattern: false,
444
- * allowMultiplePatterns: false,
445
- * });
446
- *
447
- * // Now resolvable:
448
- * getDescriptor('openai-no-regex', true); // → the registered descriptor
449
- * getDescriptorById('openai-no-regex'); // → same
450
- * ```
451
- *
452
- * A descriptor that contradicts itself (see `checkDescriptorConsistency`) is
453
- * still registered — the caller may know something we don't — but each
454
- * problem is warned once at registration, because the alternative is finding
455
- * out from a provider's HTTP 400.
456
- */
457
- export declare function registerDescriptor(descriptor: FormatDescriptor): void;
458
- /**
459
- * Resolve a descriptor by family + strictness.
460
- *
461
- * Built-in families (`'openai'`, `'anthropic'`, `'google'`) always
462
- * resolve. Custom families registered via `registerDescriptor` resolve
463
- * once they're registered. Unknown families fall back to `LENIENT`
464
- * (safe default — strict mode silently degrades for unrecognized models).
465
- *
466
- * @param family - provider family (built-in or registered)
467
- * @param strict - whether the strict variant is wanted
468
- */
469
- export declare function getDescriptor(family: DescriptorFamily, strict: boolean): FormatDescriptor;
470
- /**
471
- * Look up a descriptor by id. Returns LENIENT for unknown ids (safe default).
472
- * Custom descriptors registered via `registerDescriptor` are reachable here
473
- * by their `id`.
474
- */
475
- export declare function getDescriptorById(id: string | undefined): FormatDescriptor;
476
- /**
477
- * True if `family` has at least one registered descriptor (strict or
478
- * lenient). Used by `@aeye/ai`'s `resolveStrictFormat` fallback chain to
479
- * decide whether a model id prefix or provider name is a recognized
480
- * dialect.
481
- */
482
- export declare function hasDescriptorFamily(family: string | undefined): boolean;
483
- /**
484
- * Resolve descriptor from various input shapes (boolean, options object, or descriptor).
485
- * Used by `toJSONSchema` to support its overloaded signature.
486
- */
487
- export declare function resolveDescriptor(input: FormatDescriptor | ToJSONSchemaOptions | boolean | undefined): FormatDescriptor;
488
- /**
489
- * Decide whether `schema` can be expressed as structured output under
490
- * `descriptor`'s JSON-Schema dialect. Returns `false` when the schema uses a
491
- * construct the descriptor forbids, so the caller can DROP the wire schema and
492
- * deliver it as prompt text instead (see the ai-layer
493
- * `applySchemaDeliveryFallback`).
494
- *
495
- * Walks the Zod schema in the same style as `strictify`/`convert`, honoring:
496
- * - **unions** (`z.union` / `z.discriminatedUnion` → `anyOf`) when
497
- * `!descriptor.allowAnyOf` (e.g. Gemini strict rejects `anyOf`);
498
- * - **intersections** (`z.intersection` → `allOf`) when `!descriptor.allowAllOf`;
499
- * - **recursion** (a self-referential `z.lazy` cycle → `$ref`): a cycle back to
500
- * the ROOT is fine when `descriptor.allowRootRef && descriptor.supportsRecursion`
501
- * (Gemini supports `$ref: '#'`); a non-root cycle needs
502
- * `descriptor.allowDefsRef && descriptor.supportsRecursion`.
503
- *
504
- * `ZodNullable` / `ZodOptional` are transparent wrappers here (nullability is
505
- * NOT treated as a union), so only genuine `z.union(...)` trips `allowAnyOf`.
506
- * Non-combinator, non-recursive schemas (plain objects, arrays, primitives)
507
- * are always expressible. The structure mirrors the descriptor flags so more
508
- * feasibility checks are easy to add.
509
- */
510
- export declare function canExpress(schema: z.ZodType | z.core.$ZodType, descriptor: FormatDescriptor): boolean;
511
- /**
512
- * Recursively transforms a Zod schema to a target dialect.
513
- *
514
- * For LENIENT, returns the input schema unchanged (no rewrites). For strict
515
- * descriptors, installs preprocesses that accept the dialect's wire shape
516
- * (e.g. array-of-pairs records, numeric-key tuple objects) and normalize them
517
- * back to the natural Zod shape before validation.
518
- *
519
- * Repeated calls with the same `(schema, descriptor)` return the cached
520
- * transformed schema. Different descriptors share the same outer entry but
521
- * map to different inner values — bounded by the small descriptor count.
522
- *
523
- * @param schema - input Zod schema
524
- * @param descriptor - target dialect descriptor (defaults to OPENAI_STRICT)
525
- */
526
- export declare function strictify<S extends z.ZodType>(schema: S, descriptor?: FormatDescriptor): S;
527
- /**
528
- * Produce a NON-FAILING variant of `schema` that keeps every transform
529
- * (`preprocess`, `codec`, `pipe`, `transform`) but drops validation. Parsing
530
- * a wire value through the result runs the decode preprocesses installed by
531
- * `strictify` (array-of-pairs → record, numeric-key object → tuple, null →
532
- * undefined) and yields the conceptual value, without ever rejecting.
533
- *
534
- * Recursion (`z.lazy` self-reference) is handled with a per-call memo map: an
535
- * in-flight node is recorded as a thunk and re-encounters resolve to
536
- * `z.lazy(thunk)`, so a self-referential schema relaxes in finite time and
537
- * never infinite-loops.
538
- */
539
- export declare function relaxValidation(schema: z.ZodType): z.ZodType;
540
- /**
541
- * DECODE a model's wire `value` back to the conceptual shape a custom parser
542
- * expects — symmetric with how `strictify` ENCODEs the request for the wire.
543
- *
544
- * Runs the descriptor's decode transforms (via `relaxValidation(strictify(...))`)
545
- * without imposing validation, so array-of-pairs records, numeric-key tuples,
546
- * and null-for-optional fields are normalized before a provider-agnostic
547
- * custom parser sees them. Best-effort: NEVER throws — if the relaxed decoder
548
- * can't parse the value it is returned unchanged.
549
- *
550
- * @param schema - the PRE-strictify conceptual schema (strictify runs internally)
551
- * @param value - the model's raw wire value (already `JSON.parse`d)
552
- * @param descriptor - the wire dialect the request was encoded with
553
- */
554
- export declare function decodeWire(schema: z.ZodType, value: unknown, descriptor: FormatDescriptor): unknown;
555
- /**
556
- * Format specification for JSON Schema generation
557
- */
558
- /**
559
- * Family name for `ToJSONSchemaOptions.format`. Alias of `DescriptorFamily`
560
- * — the three built-in dialects (`'openai'`, `'anthropic'`, `'google'`)
561
- * plus any string registered via `registerDescriptor`.
562
- *
563
- * @deprecated Prefer `DescriptorFamily`. Both refer to the same widened type.
564
- */
565
- export type JSONSchemaFormat = DescriptorFamily;
566
- /**
567
- * Options for toJSONSchema
568
- */
569
- export interface ToJSONSchemaOptions {
570
- /**
571
- * Whether to use strict mode (all fields required, additionalProperties: false)
572
- */
573
- strict: boolean;
574
- /**
575
- * The target format for the JSON Schema. Resolves to a named FormatDescriptor.
576
- * Built-in (`'openai'` / `'anthropic'` / `'google'`) or any string
577
- * registered via `registerDescriptor`.
578
- */
579
- format?: DescriptorFamily;
580
- }
581
- export type JSONSchemaType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'null' | 'integer';
582
- /**
583
- * JSON Schema type definition
584
- */
585
- export interface JSONSchema {
586
- type?: JSONSchemaType | JSONSchemaType[];
587
- properties?: Record<string, JSONSchema>;
588
- items?: JSONSchema;
589
- prefixItems?: JSONSchema[];
590
- required?: string[];
591
- additionalProperties?: boolean | JSONSchema;
592
- propertyNames?: JSONSchema;
593
- enum?: any[];
594
- anyOf?: JSONSchema[];
595
- allOf?: JSONSchema[];
596
- additionalItems?: boolean | JSONSchema;
597
- not?: JSONSchema;
598
- $ref?: string;
599
- description?: string;
600
- default?: any;
601
- pattern?: string;
602
- format?: string;
603
- minimum?: number;
604
- maximum?: number;
605
- exclusiveMinimum?: number;
606
- exclusiveMaximum?: number;
607
- multipleOf?: number;
608
- minItems?: number;
609
- maxItems?: number;
610
- const?: any;
611
- title?: string;
612
- $defs?: Record<string, JSONSchema>;
613
- /** Gemini-specific: deterministic property emission order for strict mode. */
614
- propertyOrdering?: string[];
615
- [metadata: string]: unknown;
616
- }
617
- /**
618
- * Converts a Zod schema to JSON Schema with support for different provider dialects.
619
- *
620
- * Accepts either a boolean (legacy: true = OPENAI_STRICT, false = LENIENT),
621
- * an options object `{ strict, format? }`, or a `FormatDescriptor` directly.
622
- *
623
- * @param schema - The Zod schema to convert
624
- * @param options - Configuration options for the conversion
625
- * @returns JSON Schema object compatible with the resolved dialect
626
- *
627
- * @example
628
- * ```typescript
629
- * const schema = z.object({
630
- * name: z.string(),
631
- * age: z.number().optional(),
632
- * });
633
- *
634
- * // For OpenAI strict mode
635
- * const jsonSchema = toJSONSchema(schema, { strict: true, format: 'openai' });
636
- *
637
- * // For Anthropic strict mode
638
- * const anthropic = toJSONSchema(schema, ANTHROPIC_STRICT);
639
- * ```
640
- */
641
- export declare function toJSONSchema(schema: z.ZodType, options: ToJSONSchemaOptions | boolean | FormatDescriptor): JSONSchema;
642
- /**
643
- * One emitted `enum` node's contribution to a dialect's size limits. A dialect
644
- * bounds the TOTAL number of enum values in a schema and, separately, the
645
- * character length of a SINGLE large enum — so the per-enum breakdown has to
646
- * survive the walk; a pair of totals cannot answer the second question
647
- * (two enums, one long-valued and one many-valued, would answer it wrongly).
648
- */
649
- export interface EnumFeature {
650
- /** How many members the enum emits. */
651
- readonly valueCount: number;
652
- /**
653
- * Total character length of its STRING members. Non-string members
654
- * contribute nothing: the character rules are written for string values.
655
- */
656
- readonly stringValueChars: number;
657
- }
658
- /**
659
- * Structural feature counts for a Zod schema, used by the SchemaBudget to
660
- * decide whether an item fits a descriptor's per-request budget, whether it
661
- * fits the dialect's per-schema size limits, and whether the descriptor can
662
- * express it at all.
663
- */
664
- export interface SchemaFeatures {
665
- /** True if the schema (or any subschema) uses `z.lazy` / self-recursion. */
666
- hasRecursion: boolean;
667
- /** Count of `z.optional()` leaves anywhere in the schema. */
668
- optionalParameterCount: number;
669
- /**
670
- * Count of union-shaped nodes — `z.union`, `z.discriminatedUnion`, plus
671
- * `z.nullable` (which on the wire under OpenAI strict becomes a type
672
- * array `[T, "null"]`, also counts toward Anthropic's union-type budget).
673
- */
674
- unionTypeCount: number;
675
- /** Count of `z.record` nodes. */
676
- recordCount: number;
677
- /** Count of `z.tuple` nodes. */
678
- tupleCount: number;
679
- /** One entry per emitted `enum` node, in walk order. */
680
- enums: readonly EnumFeature[];
681
- /**
682
- * Object properties the schema emits, summed over every nesting level. A
683
- * record counts as the 2 properties its widest encoding emits
684
- * (`{key, value}` pairs) and a tuple as one per item (numeric-key
685
- * encoding) — the count is descriptor-independent, so it takes the largest
686
- * encoding any dialect could choose (see `schemaSizeLimits`).
687
- */
688
- objectPropertyCount: number;
689
- /** Deepest container nesting below the root (an object of scalars is 1). */
690
- maxNestingDepth: number;
691
- /**
692
- * Total characters over property names plus `enum` and `const` string
693
- * values — the "total string size" a dialect bounds. `$defs` entry names are
694
- * NOT included: they are generated at emit time, are few, and are short
695
- * relative to a 120,000-character budget.
696
- */
697
- stringSizeChars: number;
698
- }
699
- /**
700
- * Walk a Zod schema once and count its structural features. Result is
701
- * cached per schema in a WeakMap — second-and-subsequent calls are O(1) and
702
- * the entry is GC'd with the schema (same OOM-safe pattern as `strictify`).
703
- *
704
- * The walk is EAGER (it has to descend to count), so its cycle guard keys on
705
- * `walkKey`, not on object identity: a `z.lazy` that rebuilds its inner schema
706
- * per call would otherwise never re-enter the same object and the walk would
707
- * never terminate. That is not hypothetical — it is a measured, reproducible
708
- * heap-death, and this function is on the hot path of EVERY tool of EVERY
709
- * request to a strict-family model (`SchemaBudget.allocate`).
710
- */
711
- export declare function analyzeSchema(schema: z.ZodType | z.core.$ZodType): SchemaFeatures;
712
- /**
713
- * Report the ways ONE schema exceeds the descriptor's documented per-schema
714
- * size limits (`FormatDescriptor.schemaSizeLimits`). Empty means it fits, or
715
- * that the dialect publishes no limits.
716
- *
717
- * This is a FEASIBILITY question, not a budget one: the numbers bound a single
718
- * schema, so no other tool in the request can change the answer, and
719
- * `SchemaBudget.allocate` therefore treats a hit exactly like an
720
- * unrepresentable keyword — that item degrades to the family's non-strict
721
- * descriptor and the rest of the request is untouched.
722
- *
723
- * Exported because "why did my tool silently stop being strict?" needs an
724
- * answer a caller can print; each line names the bound and the measurement.
725
- *
726
- * @example
727
- * ```ts
728
- * checkSchemaSizeLimits(z.object({ pick: z.enum(tenThousandNames) }), OPENAI_STRICT);
729
- * // → ['enum values 10000 exceed maxTotalEnumValues 1000']
730
- * ```
731
- */
732
- export declare function checkSchemaSizeLimits(schema: z.ZodType | z.core.$ZodType, descriptor: FormatDescriptor): readonly string[];
733
- /**
734
- * Per-request strict-mode allocator.
735
- *
736
- * Constructed once per outgoing request with the chosen model's strictest
737
- * descriptor. Tracks remaining slots (strict tools, optional parameters,
738
- * union types) against the descriptor's documented per-request limits and
739
- * decides per-tool / per-output whether to emit strict or fall back to the
740
- * SAME FAMILY's non-strict descriptor (`degraded` — never the family-blind
741
- * `LENIENT`, which would undo dialect rules that outlive strict mode).
742
- *
743
- * Selection guarantees that any tool with `strict: true` (hard requirement)
744
- * has a model that supports the family — `allocate` therefore always grants
745
- * strict for `requested === true` (subject only to feasibility, not budget;
746
- * if `true` items overflow the budget the API call will fail, which is the
747
- * correct behavior for hard requirements).
748
- *
749
- * Numeric `strict: <priority>` items are allocated greedily after `true`
750
- * items have consumed their share of the budget. Caller is expected to
751
- * pre-sort by descending priority before iterating.
752
- */
753
- export declare class SchemaBudget {
754
- private readonly descriptor;
755
- /**
756
- * What an item that does NOT get strict is emitted through: the descriptor's
757
- * own family, non-strict.
758
- *
759
- * It is deliberately NOT the family-blind `LENIENT`. A dialect restriction
760
- * can belong to the DIALECT rather than to strict mode — `GOOGLE_NON_STRICT`
761
- * exists for exactly one such rule, the `unconstrained` encoding of
762
- * `z.any()`, because Gemini builds a decoding grammar whenever a tool call is
763
- * forced, with no per-tool strict flag involved. Degrading to `LENIENT` put
764
- * the self-referencing `$defs/Any` that encoding was created to avoid back on
765
- * the Google wire — and it did so for every gin/query-style recursive `anyOf`
766
- * schema, i.e. the schemas that ALWAYS degrade, since `GOOGLE_STRICT` cannot
767
- * express `anyOf` at all (measured: the product's real `api_set` tool schema
768
- * allocates to `lenient` under `GOOGLE_STRICT`, and its emitted JSON carries
769
- * nine `#/$defs/Any` references).
770
- *
771
- * For the other families this is behaviour-neutral by construction:
772
- * `OPENAI_NON_STRICT` and `ANTHROPIC_NON_STRICT` are `LENIENT` with a family
773
- * tag, and a family with no registered non-strict variant resolves to
774
- * `LENIENT` (`getDescriptor`). Only the pinned `descriptor` id on the tool
775
- * changes, which round-trips through `getDescriptorById`.
776
- */
777
- private readonly degraded;
778
- private remainingTools;
779
- private remainingOptionalParams;
780
- private remainingUnionTypes;
781
- constructor(descriptor: FormatDescriptor);
782
- /**
783
- * Decide the effective descriptor for a tool's parameter schema given the
784
- * dev's strict request, the schema's features, and the remaining budget.
785
- *
786
- * Returns the family's NON-STRICT descriptor (`LENIENT` for a family that
787
- * registers none) when:
788
- * - `requested === false`
789
- * - the schema uses a feature the descriptor can't represent
790
- * - the schema exceeds the dialect's per-schema size limits
791
- * (`checkSchemaSizeLimits`)
792
- * - the descriptor has slot limits and the budget is exhausted (only
793
- * applies to `requested` being a positive number; `true` always wins
794
- * subject to feasibility and size)
795
- *
796
- * Returns the strict descriptor (and decrements the budget) otherwise.
797
- */
798
- allocateTool(schema: z.ZodType | z.core.$ZodType, requested: boolean | number | undefined): FormatDescriptor;
799
- /**
800
- * Same as `allocateTool` but for the request's structured-output schema.
801
- * The output schema doesn't consume a tool slot but it does count toward
802
- * the optional-parameter and union-type budgets — descriptors document
803
- * those limits as "across all strict schemas in one request".
804
- */
805
- allocateOutput(schema: z.ZodType | z.core.$ZodType, requested: boolean | number | undefined): FormatDescriptor;
806
- /** Snapshot of remaining budget. Useful for telemetry / debug logs. */
807
- remaining(): {
808
- strictTools: number;
809
- optionalParams: number;
810
- unionTypes: number;
811
- };
812
- private allocate;
813
- }
814
- /**
815
- * Compare two descriptors and return the one with the tighter per-request
816
- * budget. Used by providers to pick a single descriptor for a SchemaBudget
817
- * shared between `convertTools` and `convertResponseFormat` — Anthropic's
818
- * documented limits apply across the whole request, so the strictest
819
- * descriptor wins.
820
- *
821
- * `schemaSizeLimits` deliberately does NOT participate. Those bounds are
822
- * per-schema, so they are evaluated against whichever descriptor this returns
823
- * rather than shared between the two — and every provider here passes two
824
- * descriptors resolved from the SAME family, so there is nothing to break the
825
- * tie on. Ranking six size bounds against three slot budgets would be an
826
- * invented ordering, not a documented one.
827
- */
828
- export declare function strictestOf(a: FormatDescriptor, b: FormatDescriptor): FormatDescriptor;
829
- /**
830
- * Convert a `boolean | number | undefined` strict request into a numeric
831
- * priority for sorting. Used by providers to allocate strict slots in
832
- * descending priority order.
833
- *
834
- * - `true` → `+Infinity` (hard requirement; always first in line)
835
- * - `false` → `-Infinity` (always lenient; never wants strict)
836
- * - `number > 0` → the number itself
837
- * - `number <= 0` or `undefined` → `0` (no preference)
838
- */
839
- export declare function strictPriority(requested: boolean | number | undefined): number;
840
- //# sourceMappingURL=schema.d.ts.map