@aeye/schema 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -1
- package/dist/index.js +32 -3
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -721,6 +721,18 @@ declare class Printer {
|
|
|
721
721
|
/** The shape plus a `type X = …` line for every named type it reaches. */
|
|
722
722
|
full(s: AnySchema): string;
|
|
723
723
|
}
|
|
724
|
+
/**
|
|
725
|
+
* The `$defs` key of each named type in an env. A qualified name (`api/HttpHeader`)
|
|
726
|
+
* needs JSON Pointer escapes in a ref (`#/$defs/api~1HttpHeader`): valid JSON
|
|
727
|
+
* Schema, but OpenAI's endpoint refuses it ("reference ... not found") while
|
|
728
|
+
* other providers read it. So every key keeps to `[A-Za-z0-9_.-]`: a name
|
|
729
|
+
* already in it is its own key; any other character becomes `_`, and a key that
|
|
730
|
+
* would collide gets `_2`, `_3`, ... The map is built from the whole env (in name
|
|
731
|
+
* order), so it is the same for every profile and every render of that env,
|
|
732
|
+
* whichever types a schema happens to reach. No dialect wants the raw names
|
|
733
|
+
* (models read the keys only as labels), so this is not a profile rule.
|
|
734
|
+
*/
|
|
735
|
+
declare function defKeysOf(env: ReadonlyMap<string, AnySchema>): ReadonlyMap<string, string>;
|
|
724
736
|
/** Nodes an inlining (no `$defs`) compile may make before it restarts as `inlineOnce`. */
|
|
725
737
|
declare const INLINE_BUDGET = 4000;
|
|
726
738
|
/** Thrown inside a compile that inlined past `INLINE_BUDGET`; `Bound.render` restarts it. */
|
|
@@ -744,6 +756,7 @@ declare class Compiler {
|
|
|
744
756
|
readonly nodes: Node[];
|
|
745
757
|
/** Named types emitted into `$defs` (defs mode). */
|
|
746
758
|
readonly defs: Map<string, DefTarget>;
|
|
759
|
+
private _defKeys;
|
|
747
760
|
/** Named types the JSON-text escapes mention: defined once, in the root description. */
|
|
748
761
|
readonly glossary: Set<string>;
|
|
749
762
|
/** Without `$defs`: recursive named types inlined so far (`inlineOnce` mode). */
|
|
@@ -776,6 +789,8 @@ declare class Compiler {
|
|
|
776
789
|
guarded(s: AnySchema, outer?: AnySchema): Node;
|
|
777
790
|
/** A use of a named type. */
|
|
778
791
|
ref(name: string): Node;
|
|
792
|
+
/** The `$defs` key of a named type (`defKeysOf`): only `[A-Za-z0-9_.-]`, unique, stable per env. */
|
|
793
|
+
defKey(name: string): string;
|
|
779
794
|
private defRef;
|
|
780
795
|
/**
|
|
781
796
|
* The escape hatch: a string holding JSON text in the CODE shape, used for
|
|
@@ -2732,4 +2747,4 @@ declare function ginNamedTypes<T extends Record<string, unknown> = {}>(registry:
|
|
|
2732
2747
|
readonly [K in keyof T]: SchemaOf<T[K]>;
|
|
2733
2748
|
} & Record<string, AnySchema>;
|
|
2734
2749
|
|
|
2735
|
-
export { ANTHROPIC_NON_STRICT, ANTHROPIC_STRICT, ANTHROPIC_STRICT_OUTPUT, type Adjustment, type AllowRefs, type AnySchema, AnyType, ArrayType, type Audience, type Bindable, BooleanType, Bound, type Brand, Bundle, type Check, CodecType, Compiler, ConditionalType, type ConstraintSupport, type CopyStats, Cx, DEFAULT_ERROR_FORMAT, DEFAULT_JSON_INSTRUCTION, DEFERRED_SPAN, type DecodedCall, DefTarget, DefaultType, type DeferredSpec, type Defs, DependentType, type DispatchCase, DispatchType, type DynamicDefs, DynamicModule, type DynamicOptions, type EncodeTextOptions, type Encoder, EnumType, type EnvOf, type ErrorDetail, type ErrorFormat, type ErrorFormatInput, FAILED, type FillOptions, GIN_BUILTINS, GOOGLE_NON_STRICT, GOOGLE_OPENAPI, GOOGLE_STRICT, type GinRegistryLike, type GinSchema, type GinTypeDef, type Helper, type HelperOptions, type HelperSet, INLINE_BUDGET, type ImportReport, InlineBudgetExceeded, IntersectionType, type Issue, type IssueKind, type ItemName, type ItemOut, type JsonSchema, type JsonValue, LENIENT, type LimitName, LiteralType, type LiteralValue, type Loose, MINIMAL, type Merge, type Meta, type Missing, type ModelLike, ModelProfile, type ModelRequestLimits, type ModelSchema, type ModelSchemaDialect, type ModelSchemaLimits, type ModelSchemaRuleKey, type ModelSchemaRules, type ModelSchemaSide, Module, NeverType, Node, type NodeImpl, NotType, NullType, NullableType, type NumberOptions, NumberType, OLLAMA, OPENAI_FINETUNED_STRICT, OPENAI_NON_STRICT, OPENAI_STRICT, type ObjectExtras, type ObjectOut, type ObjectRestOut, ObjectType, OptionalType, type OutOf, type OutputItem, PEOPLE, type ParseOptions, type ParseResult, type PathSeg, Printer, type Profile, type ProfileAdjustment, type ProfileFamily, type ProfileForOptions, RecordType, type RefFree, type RefMarker, RefType, type RefsOf, Rejection, Rendered, RenderedRequest, RequestEntry, type RequestItem, RequestLimitError, type RequestLimits, type RequestOptions, type RequestSchema, type Resolve, type ResolvedErrorFormat, type ResolvedModelSchema, type ResultOut, type RuleIssue, SCHEMA_DATA_KEY, Schema, SchemaDefinitionError, type SchemaError, type SchemaKind, type SchemaLimits, type SchemaMeasure, type SchemaOf, SchemaParseError, type SchemaTarget, type Shape, type ShapeRefs, type Simplify, type Strictness, type StringOptions, StringType, type Text, type ToolItem, TupleType, UnionType, type View, XAI_NON_STRICT, XAI_STRICT, ZERO_MEASURE, a, addMeasures, applySchemaRules, brokenLimits, deferEncode, deferSchema, deferredRequest, didYouMean, editDistance, errorFormat, familyOf, familyProfile, fillDeferred, formatErrors, formatIssues, formatPath, fromGin, fromJSONSchema, getProfile, getSchemaBase, ginNamedTypes, hasDeferred, isBasicPattern, isNever, issueKind, measureJson, mergeErrorFormats, mergeModelSchema, modelPath, modelSchemaOf, nearest, newStats, overLimits, plainDeferred, planRequest, profileFor, rankNear, readJsonText, registerProfile, registerSchemaBase, registerSchemaHelpers, resolveModelSchema, rulesFamily, rulesFor, schemaBases, schemaData, schemaHelpers, shortType, sideProfiles, staticBundle, strictPriority, suggestionBudget, suggestionFor, validateModelSchema, variant, viewOf };
|
|
2750
|
+
export { ANTHROPIC_NON_STRICT, ANTHROPIC_STRICT, ANTHROPIC_STRICT_OUTPUT, type Adjustment, type AllowRefs, type AnySchema, AnyType, ArrayType, type Audience, type Bindable, BooleanType, Bound, type Brand, Bundle, type Check, CodecType, Compiler, ConditionalType, type ConstraintSupport, type CopyStats, Cx, DEFAULT_ERROR_FORMAT, DEFAULT_JSON_INSTRUCTION, DEFERRED_SPAN, type DecodedCall, DefTarget, DefaultType, type DeferredSpec, type Defs, DependentType, type DispatchCase, DispatchType, type DynamicDefs, DynamicModule, type DynamicOptions, type EncodeTextOptions, type Encoder, EnumType, type EnvOf, type ErrorDetail, type ErrorFormat, type ErrorFormatInput, FAILED, type FillOptions, GIN_BUILTINS, GOOGLE_NON_STRICT, GOOGLE_OPENAPI, GOOGLE_STRICT, type GinRegistryLike, type GinSchema, type GinTypeDef, type Helper, type HelperOptions, type HelperSet, INLINE_BUDGET, type ImportReport, InlineBudgetExceeded, IntersectionType, type Issue, type IssueKind, type ItemName, type ItemOut, type JsonSchema, type JsonValue, LENIENT, type LimitName, LiteralType, type LiteralValue, type Loose, MINIMAL, type Merge, type Meta, type Missing, type ModelLike, ModelProfile, type ModelRequestLimits, type ModelSchema, type ModelSchemaDialect, type ModelSchemaLimits, type ModelSchemaRuleKey, type ModelSchemaRules, type ModelSchemaSide, Module, NeverType, Node, type NodeImpl, NotType, NullType, NullableType, type NumberOptions, NumberType, OLLAMA, OPENAI_FINETUNED_STRICT, OPENAI_NON_STRICT, OPENAI_STRICT, type ObjectExtras, type ObjectOut, type ObjectRestOut, ObjectType, OptionalType, type OutOf, type OutputItem, PEOPLE, type ParseOptions, type ParseResult, type PathSeg, Printer, type Profile, type ProfileAdjustment, type ProfileFamily, type ProfileForOptions, RecordType, type RefFree, type RefMarker, RefType, type RefsOf, Rejection, Rendered, RenderedRequest, RequestEntry, type RequestItem, RequestLimitError, type RequestLimits, type RequestOptions, type RequestSchema, type Resolve, type ResolvedErrorFormat, type ResolvedModelSchema, type ResultOut, type RuleIssue, SCHEMA_DATA_KEY, Schema, SchemaDefinitionError, type SchemaError, type SchemaKind, type SchemaLimits, type SchemaMeasure, type SchemaOf, SchemaParseError, type SchemaTarget, type Shape, type ShapeRefs, type Simplify, type Strictness, type StringOptions, StringType, type Text, type ToolItem, TupleType, UnionType, type View, XAI_NON_STRICT, XAI_STRICT, ZERO_MEASURE, a, addMeasures, applySchemaRules, brokenLimits, defKeysOf, deferEncode, deferSchema, deferredRequest, didYouMean, editDistance, errorFormat, familyOf, familyProfile, fillDeferred, formatErrors, formatIssues, formatPath, fromGin, fromJSONSchema, getProfile, getSchemaBase, ginNamedTypes, hasDeferred, isBasicPattern, isNever, issueKind, measureJson, mergeErrorFormats, mergeModelSchema, modelPath, modelSchemaOf, nearest, newStats, overLimits, plainDeferred, planRequest, profileFor, rankNear, readJsonText, registerProfile, registerSchemaBase, registerSchemaHelpers, resolveModelSchema, rulesFamily, rulesFor, schemaBases, schemaData, schemaHelpers, shortType, sideProfiles, staticBundle, strictPriority, suggestionBudget, suggestionFor, validateModelSchema, variant, viewOf };
|
package/dist/index.js
CHANGED
|
@@ -1472,6 +1472,29 @@ function sharedLenient() {
|
|
|
1472
1472
|
}
|
|
1473
1473
|
return sharedLenientRendered;
|
|
1474
1474
|
}
|
|
1475
|
+
var SAFE_DEF_KEY = /^[A-Za-z0-9_.-]+$/;
|
|
1476
|
+
var defKeyMaps = /* @__PURE__ */ new WeakMap();
|
|
1477
|
+
function defKeysOf(env) {
|
|
1478
|
+
const known = defKeyMaps.get(env);
|
|
1479
|
+
if (known) return known;
|
|
1480
|
+
const keys = /* @__PURE__ */ new Map();
|
|
1481
|
+
const taken = /* @__PURE__ */ new Set();
|
|
1482
|
+
for (const name of env.keys()) {
|
|
1483
|
+
if (SAFE_DEF_KEY.test(name)) {
|
|
1484
|
+
keys.set(name, name);
|
|
1485
|
+
taken.add(name);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
for (const name of [...env.keys()].filter((n) => !SAFE_DEF_KEY.test(n)).sort()) {
|
|
1489
|
+
const base = name.replace(/[^A-Za-z0-9_.-]/g, "_") || "_";
|
|
1490
|
+
let key = base;
|
|
1491
|
+
for (let n = 2; taken.has(key); n++) key = `${base}_${n}`;
|
|
1492
|
+
taken.add(key);
|
|
1493
|
+
keys.set(name, key);
|
|
1494
|
+
}
|
|
1495
|
+
defKeyMaps.set(env, keys);
|
|
1496
|
+
return keys;
|
|
1497
|
+
}
|
|
1475
1498
|
var INLINE_BUDGET = 4e3;
|
|
1476
1499
|
var InlineBudgetExceeded = class extends Error {
|
|
1477
1500
|
};
|
|
@@ -1492,6 +1515,7 @@ var Compiler = class {
|
|
|
1492
1515
|
nodes = [];
|
|
1493
1516
|
/** Named types emitted into `$defs` (defs mode). */
|
|
1494
1517
|
defs = /* @__PURE__ */ new Map();
|
|
1518
|
+
_defKeys;
|
|
1495
1519
|
/** Named types the JSON-text escapes mention: defined once, in the root description. */
|
|
1496
1520
|
glossary = /* @__PURE__ */ new Set();
|
|
1497
1521
|
/** Without `$defs`: recursive named types inlined so far (`inlineOnce` mode). */
|
|
@@ -1604,11 +1628,15 @@ var Compiler = class {
|
|
|
1604
1628
|
this.stack.pop();
|
|
1605
1629
|
return n;
|
|
1606
1630
|
}
|
|
1631
|
+
/** The `$defs` key of a named type (`defKeysOf`): only `[A-Za-z0-9_.-]`, unique, stable per env. */
|
|
1632
|
+
defKey(name) {
|
|
1633
|
+
return (this._defKeys ??= defKeysOf(this.env)).get(name) ?? name.replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
1634
|
+
}
|
|
1607
1635
|
defRef(name, def) {
|
|
1608
1636
|
const n = this.node({
|
|
1609
1637
|
deps: [def],
|
|
1610
|
-
//
|
|
1611
|
-
emit: () => ({ $ref: `#/$defs/${
|
|
1638
|
+
// A pointer-safe key (`shop/Product` is `#/$defs/shop_Product`): no `~0`/`~1` escapes, which OpenAI can't resolve.
|
|
1639
|
+
emit: () => ({ $ref: `#/$defs/${this.defKey(name)}` }),
|
|
1612
1640
|
run: (v, cx) => def.run(v, cx),
|
|
1613
1641
|
encode: (v, st) => def.encode(v, st),
|
|
1614
1642
|
child: (seg) => def.child(seg)
|
|
@@ -1833,7 +1861,7 @@ ${defs2}`;
|
|
|
1833
1861
|
${note}` : note };
|
|
1834
1862
|
}
|
|
1835
1863
|
const defs = {};
|
|
1836
|
-
for (const [name, def] of this.compiler.defs) defs[name] = def.json();
|
|
1864
|
+
for (const [name, def] of this.compiler.defs) defs[this.compiler.defKey(name)] = def.json();
|
|
1837
1865
|
this._json = this.compiler.defs.size ? { ...body, $defs: defs } : body;
|
|
1838
1866
|
return this._json;
|
|
1839
1867
|
}
|
|
@@ -5251,6 +5279,7 @@ export {
|
|
|
5251
5279
|
addMeasures,
|
|
5252
5280
|
applySchemaRules,
|
|
5253
5281
|
brokenLimits,
|
|
5282
|
+
defKeysOf,
|
|
5254
5283
|
deferEncode,
|
|
5255
5284
|
deferSchema,
|
|
5256
5285
|
deferredRequest,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeye/schema",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "@aeye/schema - LLM-first schema builder: named and dynamic types, per-model rendering, request-wide budgets, copy-light decoding",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"author": "ClickerMonkey",
|
|
58
58
|
"dependencies": {},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@aeye/gin": "0.11.
|
|
61
|
-
"@aeye/query": "0.11.
|
|
60
|
+
"@aeye/gin": "0.11.2",
|
|
61
|
+
"@aeye/query": "0.11.2",
|
|
62
62
|
"expect-type": "^1.3.0",
|
|
63
63
|
"handlebars": "^4.7.0",
|
|
64
64
|
"tinybench": "^2.9.0",
|