@sembl/core 0.3.0 → 0.5.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.
- package/dist/index.cjs +463 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +234 -38
- package/dist/index.d.ts +234 -38
- package/dist/index.js +455 -76
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named string formats a field can be constrained to.
|
|
3
|
+
*
|
|
4
|
+
* Each one is validated locally, described in the prompt, and — where JSON
|
|
5
|
+
* Schema has a matching keyword — emitted in the schema dialects that honour
|
|
6
|
+
* it. They exist for the fields every pipeline ends up normalising by hand:
|
|
7
|
+
* a country that came back as "United States", a state as "Calif.", a
|
|
8
|
+
* currency as "dollars".
|
|
9
|
+
*
|
|
10
|
+
* - `"url"` — an absolute http(s) URL.
|
|
11
|
+
* - `"email"` — one address, no display name.
|
|
12
|
+
* - `"date"` — a calendar date as `YYYY-MM-DD`.
|
|
13
|
+
* - `"datetime"` — an ISO 8601 timestamp, e.g. `2026-09-05T14:30:00Z`.
|
|
14
|
+
* - `"iso-country"` — an ISO 3166-1 alpha-2 code: `US`, `DE`, `PT`.
|
|
15
|
+
* - `"us-state"` — a two-letter USPS state code: `CA`, `NY`, `DC`, `PR`.
|
|
16
|
+
* - `"us-state-name"` — a state's full name: `California`, `New York`.
|
|
17
|
+
* - `"currency"` — an ISO 4217 code: `USD`, `EUR`, `GBP`.
|
|
18
|
+
*/
|
|
19
|
+
type FieldFormat = "url" | "email" | "date" | "datetime" | "iso-country" | "us-state" | "us-state-name" | "currency";
|
|
20
|
+
declare const FIELD_FORMATS: readonly FieldFormat[];
|
|
21
|
+
/**
|
|
22
|
+
* Check a string against a format. Returns a message describing what was
|
|
23
|
+
* expected when the value does not conform, undefined when it does.
|
|
24
|
+
*/
|
|
25
|
+
declare function validateFormat(value: string, format: FieldFormat): string | undefined;
|
|
26
|
+
/** The phrase the prompt uses to state a format. */
|
|
27
|
+
declare function describeFormat(format: FieldFormat): string;
|
|
28
|
+
/**
|
|
29
|
+
* JSON Schema keywords for a format, in the standard dialect. The four with
|
|
30
|
+
* a JSON Schema `format` of their own use it; the code formats state their
|
|
31
|
+
* shape as a pattern, since a `format` a validator does not know is ignored.
|
|
32
|
+
*/
|
|
33
|
+
declare function formatToJsonSchema(format: FieldFormat): Record<string, unknown>;
|
|
34
|
+
|
|
1
35
|
/**
|
|
2
36
|
* Bounds a field's value beyond its type.
|
|
3
37
|
*
|
|
@@ -7,6 +41,8 @@
|
|
|
7
41
|
* each element, so `string[]` can carry both `maxItems` and `maxLength`.
|
|
8
42
|
*/
|
|
9
43
|
interface FieldConstraints {
|
|
44
|
+
/** A named string format: `"url"`, `"date"`, `"iso-country"`, `"currency"`, … */
|
|
45
|
+
format?: FieldFormat;
|
|
10
46
|
/** Maximum string length, inclusive */
|
|
11
47
|
maxLength?: number;
|
|
12
48
|
/** Minimum string length, inclusive */
|
|
@@ -83,30 +119,28 @@ interface SchemaBundle {
|
|
|
83
119
|
}
|
|
84
120
|
|
|
85
121
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* CMS fetch, a database query, a static map). Called at most once per distinct
|
|
91
|
-
* source id per coercion; the caller owns any caching across coercions.
|
|
92
|
-
*
|
|
93
|
-
* ```ts
|
|
94
|
-
* const enumResolver: EnumResolver = async (sourceId) => {
|
|
95
|
-
* const docs = await cms.taxonomy(sourceId);
|
|
96
|
-
* return docs.map((d) => d.slug);
|
|
97
|
-
* };
|
|
98
|
-
* ```
|
|
122
|
+
* What a resolver is told about the source it is asked for, beyond its id:
|
|
123
|
+
* which schema is being coerced and where in it the source is used. One
|
|
124
|
+
* resolver can then serve several taxonomies, log which field asked, or
|
|
125
|
+
* refuse a source that a required field depends on but it cannot vouch for.
|
|
99
126
|
*/
|
|
100
|
-
|
|
127
|
+
interface EnumResolverContext {
|
|
128
|
+
sourceId: string;
|
|
129
|
+
/** The schema being coerced — the root, not a nested one. */
|
|
130
|
+
schema: RuntimeSchema;
|
|
131
|
+
/** Whether a chain of required fields reaches the source. */
|
|
132
|
+
required: boolean;
|
|
133
|
+
/** Dotted paths of every field drawing from the source, e.g. `address.country`. */
|
|
134
|
+
paths: string[];
|
|
135
|
+
}
|
|
101
136
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* back to a free-form string. Successful resolution always yields a non-empty
|
|
107
|
-
* array; an empty result is treated as a failure, not as "no legal values",
|
|
108
|
-
* because a field with zero legal values is unsatisfiable.
|
|
137
|
+
* Resolves the legal values of a `@ValuesFrom` source at coercion time.
|
|
138
|
+
* Called once per distinct source id per coercion; caching is the caller's.
|
|
139
|
+
* The context argument is optional to accept — a resolver that only needs
|
|
140
|
+
* the id can ignore it.
|
|
109
141
|
*/
|
|
142
|
+
type EnumResolver = (sourceId: string, context: EnumResolverContext) => readonly string[] | Promise<readonly string[]>;
|
|
143
|
+
/** Resolved values keyed by source id. */
|
|
110
144
|
type ResolvedEnums = Readonly<Record<string, readonly string[]>>;
|
|
111
145
|
|
|
112
146
|
type JsonSchema = Record<string, unknown>;
|
|
@@ -433,14 +467,35 @@ interface ProviderConfig {
|
|
|
433
467
|
/** Optional max tokens for the response */
|
|
434
468
|
maxTokens?: number;
|
|
435
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* One earlier turn of a repair conversation. An assistant turn is the
|
|
472
|
+
* structured output the model produced; a user turn is what was said about
|
|
473
|
+
* it. Providers render them natively — as a tool call and its result, or as
|
|
474
|
+
* assistant and user messages — so the model sees its own rejected answer
|
|
475
|
+
* as its own rather than quoted back to it.
|
|
476
|
+
*/
|
|
477
|
+
type ProviderTurn = {
|
|
478
|
+
role: "assistant";
|
|
479
|
+
data: Record<string, unknown>;
|
|
480
|
+
} | {
|
|
481
|
+
role: "user";
|
|
482
|
+
text: string;
|
|
483
|
+
};
|
|
436
484
|
/**
|
|
437
485
|
* Request sent to a provider for structured output.
|
|
438
486
|
*/
|
|
439
487
|
interface ProviderRequest {
|
|
440
488
|
/** System prompt with semantic context */
|
|
441
489
|
systemPrompt: string;
|
|
442
|
-
/** User input to coerce */
|
|
490
|
+
/** User input to coerce — the first user turn of the conversation. */
|
|
443
491
|
userInput: string;
|
|
492
|
+
/**
|
|
493
|
+
* Turns after `userInput`, in order, for a repair or an empty-result
|
|
494
|
+
* retry: the rejected output as an assistant turn, then the correction as
|
|
495
|
+
* a user turn, and so on. Only sent to a provider whose `supportsHistory`
|
|
496
|
+
* is true; other providers get the correction folded into `userInput`.
|
|
497
|
+
*/
|
|
498
|
+
history?: ProviderTurn[];
|
|
444
499
|
/** JSON Schema for structured output */
|
|
445
500
|
jsonSchema: Record<string, unknown>;
|
|
446
501
|
/** The runtime schema being targeted */
|
|
@@ -507,6 +562,12 @@ interface Provider {
|
|
|
507
562
|
* Send a structured output request to the LLM.
|
|
508
563
|
*/
|
|
509
564
|
complete(request: ProviderRequest): Promise<ProviderResponse>;
|
|
565
|
+
/**
|
|
566
|
+
* Whether `complete` renders `request.history` as real turns. Leave unset
|
|
567
|
+
* (false) and repair corrections arrive as text inside `userInput`
|
|
568
|
+
* instead, which every provider can handle.
|
|
569
|
+
*/
|
|
570
|
+
readonly supportsHistory?: boolean;
|
|
510
571
|
}
|
|
511
572
|
|
|
512
573
|
/**
|
|
@@ -571,6 +632,12 @@ interface Source {
|
|
|
571
632
|
label?: string;
|
|
572
633
|
/** The text itself. */
|
|
573
634
|
text: string;
|
|
635
|
+
/**
|
|
636
|
+
* A cap on this source's own characters, applied before the coercion's
|
|
637
|
+
* total `maxInputChars`, so one huge page cannot starve the others. Cut
|
|
638
|
+
* with the coercion's `truncate` policy.
|
|
639
|
+
*/
|
|
640
|
+
maxChars?: number;
|
|
574
641
|
}
|
|
575
642
|
/**
|
|
576
643
|
* What a coercion accepts as input: a plain string, one labelled source, or
|
|
@@ -637,7 +704,9 @@ interface BudgetResult {
|
|
|
637
704
|
/**
|
|
638
705
|
* Fit a set of sources into a character budget.
|
|
639
706
|
*
|
|
640
|
-
*
|
|
707
|
+
* A source's own `maxChars` is applied first, on its own, so a page known to
|
|
708
|
+
* be huge can be capped without starving the sources beside it. Then the
|
|
709
|
+
* total budget, when there is one, covers the sources' text as a whole. When they exceed it, it is
|
|
641
710
|
* shared out so that every source that fits within an equal share keeps all
|
|
642
711
|
* of its text, and what those leave unused goes to the longer ones. A short
|
|
643
712
|
* email next to a long scraped page is therefore never touched; the page
|
|
@@ -645,7 +714,7 @@ interface BudgetResult {
|
|
|
645
714
|
* so the model knows the text is incomplete rather than reading a
|
|
646
715
|
* mid-sentence stop as the end.
|
|
647
716
|
*/
|
|
648
|
-
declare function budgetSources(sources: readonly Source[], maxChars: number, policy?: TruncatePolicy): BudgetResult;
|
|
717
|
+
declare function budgetSources(sources: readonly Source[], maxChars: number | undefined, policy?: TruncatePolicy): BudgetResult;
|
|
649
718
|
|
|
650
719
|
/**
|
|
651
720
|
* What to do with a present field that fails validation.
|
|
@@ -750,6 +819,8 @@ interface ProvenanceResult<T> {
|
|
|
750
819
|
* default `"throw"` policy, or when the response validated cleanly.
|
|
751
820
|
*/
|
|
752
821
|
issues: ResolvedIssue[];
|
|
822
|
+
/** Token usage summed over every call the coercion made. */
|
|
823
|
+
usage: CoerceUsage;
|
|
753
824
|
}
|
|
754
825
|
/**
|
|
755
826
|
* Extra prompt guidance for a provenance run.
|
|
@@ -765,6 +836,13 @@ interface ProvenanceOptions {
|
|
|
765
836
|
* Each annotation then also asks which source the value was read from.
|
|
766
837
|
*/
|
|
767
838
|
sourceLabels?: readonly string[];
|
|
839
|
+
/**
|
|
840
|
+
* Only these top-level fields are wrapped; every other field comes back
|
|
841
|
+
* as a plain value with no provenance. Halves the output on schemas where
|
|
842
|
+
* a human reviews a handful of fields and code checks the rest. All
|
|
843
|
+
* fields when absent.
|
|
844
|
+
*/
|
|
845
|
+
fields?: readonly string[];
|
|
768
846
|
}
|
|
769
847
|
/**
|
|
770
848
|
* The provenance guidance for a run, extended with the source rule when the
|
|
@@ -836,6 +914,20 @@ interface CoerceOptions {
|
|
|
836
914
|
* event.
|
|
837
915
|
*/
|
|
838
916
|
onInvalidField?: InvalidFieldPolicy;
|
|
917
|
+
/**
|
|
918
|
+
* With `coerceWithProvenance` / `partialCoerceWithProvenance`: annotate only
|
|
919
|
+
* these top-level fields. The rest come back plain, which roughly halves
|
|
920
|
+
* the output when a human reviews a few fields and code checks the others.
|
|
921
|
+
* Ignored by the plain coercions.
|
|
922
|
+
*/
|
|
923
|
+
provenanceFields?: readonly string[];
|
|
924
|
+
/**
|
|
925
|
+
* How many times to ask again when a non-empty input yields no fields at
|
|
926
|
+
* all. Default 0. A model occasionally answers `{}` for a page it could
|
|
927
|
+
* read; the retry tells it so and asks for every stated value. Counts
|
|
928
|
+
* separately from `maxRepairAttempts`.
|
|
929
|
+
*/
|
|
930
|
+
retryOnEmpty?: number;
|
|
839
931
|
/**
|
|
840
932
|
* Extra guidance for this extraction that is not part of the schema: facts
|
|
841
933
|
* about the source ("prices on this site are in cents"), context the model
|
|
@@ -869,6 +961,27 @@ interface CoerceOptions {
|
|
|
869
961
|
}
|
|
870
962
|
/** A hook applied to each source before it is budgeted and rendered. */
|
|
871
963
|
type PreprocessSource = (source: Source, index: number) => Source | string | Promise<Source | string>;
|
|
964
|
+
/**
|
|
965
|
+
* Token accounting for a whole coercion, summed over every provider call it
|
|
966
|
+
* made — the first attempt, repairs, and empty-result retries.
|
|
967
|
+
*/
|
|
968
|
+
interface CoerceUsage {
|
|
969
|
+
/** Provider calls made. */
|
|
970
|
+
calls: number;
|
|
971
|
+
promptTokens: number;
|
|
972
|
+
completionTokens: number;
|
|
973
|
+
totalTokens: number;
|
|
974
|
+
cacheReadTokens: number;
|
|
975
|
+
cacheWriteTokens: number;
|
|
976
|
+
}
|
|
977
|
+
/** The result of a detailed coercion: the data plus what it cost to get it. */
|
|
978
|
+
interface CoerceDetails<T> {
|
|
979
|
+
data: T;
|
|
980
|
+
/** Issues the `onInvalidField` policy absorbed. Empty under `"throw"`. */
|
|
981
|
+
issues: ResolvedIssue[];
|
|
982
|
+
/** Token usage summed over every call the coercion made. */
|
|
983
|
+
usage: CoerceUsage;
|
|
984
|
+
}
|
|
872
985
|
/**
|
|
873
986
|
* Coerce user input into a fully validated instance of the target schema.
|
|
874
987
|
* Throws CoerceError if validation fails (required fields missing, type
|
|
@@ -884,6 +997,44 @@ declare function coerce<T>(input: CoerceInput, options: CoerceOptions): Promise<
|
|
|
884
997
|
* cannot be resolved.
|
|
885
998
|
*/
|
|
886
999
|
declare function partialCoerce<T>(input: CoerceInput, options: CoerceOptions): Promise<Partial<T>>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Like {@link coerce}, but also returns the issues the `onInvalidField` policy
|
|
1002
|
+
* absorbed and the token usage of every call made — without the cost of
|
|
1003
|
+
* provenance. The one to use when a pipeline accounts for spend or shows
|
|
1004
|
+
* dropped fields but never needs per-field confidence.
|
|
1005
|
+
*/
|
|
1006
|
+
declare function coerceDetailed<T>(input: CoerceInput, options: CoerceOptions): Promise<CoerceDetails<T>>;
|
|
1007
|
+
/** Like {@link partialCoerce}, with the issues and usage of {@link coerceDetailed}. */
|
|
1008
|
+
declare function partialCoerceDetailed<T>(input: CoerceInput, options: CoerceOptions): Promise<CoerceDetails<Partial<T>>>;
|
|
1009
|
+
/** What {@link primeCache} produced: a record that the prefix was sent once. */
|
|
1010
|
+
interface PrimedPrefix {
|
|
1011
|
+
schemaId: string;
|
|
1012
|
+
mode: "coerce" | "partialCoerce";
|
|
1013
|
+
provenance: boolean;
|
|
1014
|
+
/** Usage of the warm-up call. `cacheWriteTokens` shows the prefix landed. */
|
|
1015
|
+
usage: CoerceUsage;
|
|
1016
|
+
primedAt: string;
|
|
1017
|
+
}
|
|
1018
|
+
/** Options for {@link primeCache}: the coercion options the batch will use. */
|
|
1019
|
+
interface PrimeCacheOptions extends CoerceOptions {
|
|
1020
|
+
mode?: "coerce" | "partialCoerce";
|
|
1021
|
+
provenance?: boolean;
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Send the stable prefix — system prompt and schema — once, ahead of a batch,
|
|
1025
|
+
* so a provider that caches it writes the cache before the batch starts.
|
|
1026
|
+
*
|
|
1027
|
+
* Meant to overlap the caller's own preparation: start it while fetching
|
|
1028
|
+
* pages, then pass the promise to `coerceMany` as `primed`. The batch then
|
|
1029
|
+
* fans out at once instead of running its first item alone. The warm-up
|
|
1030
|
+
* costs one call with a trivial input and a near-empty answer; the answer is
|
|
1031
|
+
* not validated and never returned.
|
|
1032
|
+
*
|
|
1033
|
+
* Only the prefix matters, so the same options the batch will use must be
|
|
1034
|
+
* passed — a different schema, mode, provenance setting or instructions is
|
|
1035
|
+
* a different prefix and warms nothing.
|
|
1036
|
+
*/
|
|
1037
|
+
declare function primeCache(options: PrimeCacheOptions): Promise<PrimedPrefix>;
|
|
887
1038
|
/**
|
|
888
1039
|
* Like {@link coerce}, but each field also comes back with how well the input
|
|
889
1040
|
* supported it and the text it was read from.
|
|
@@ -903,25 +1054,44 @@ declare function coerceWithProvenance<T>(input: CoerceInput, options: CoerceOpti
|
|
|
903
1054
|
*/
|
|
904
1055
|
declare function partialCoerceWithProvenance<T>(input: CoerceInput, options: CoerceOptions): Promise<ProvenanceResult<Partial<T>>>;
|
|
905
1056
|
|
|
1057
|
+
/** What a batch accepts: an array, or anything that can be iterated, lazily or not. */
|
|
1058
|
+
type CoerceManyInputs = Iterable<CoerceInput> | AsyncIterable<CoerceInput>;
|
|
906
1059
|
/** Options for {@link coerceMany}. Everything in `CoerceOptions` applies to each item. */
|
|
907
|
-
interface CoerceManyOptions extends CoerceOptions {
|
|
1060
|
+
interface CoerceManyOptions<T = unknown> extends CoerceOptions {
|
|
908
1061
|
/** How many items may be in flight at once. Default 4. */
|
|
909
1062
|
concurrency?: number;
|
|
910
1063
|
/** Which coercion to run per item. Default `"coerce"`. */
|
|
911
1064
|
mode?: "coerce" | "partialCoerce";
|
|
912
|
-
/** Ask for per-field provenance on every item. Default false. */
|
|
913
|
-
provenance?: boolean;
|
|
914
1065
|
/**
|
|
915
|
-
*
|
|
916
|
-
* the
|
|
917
|
-
|
|
918
|
-
|
|
1066
|
+
* Ask for provenance on every item: `true` for every field, or the names
|
|
1067
|
+
* of the top-level fields to annotate. Default false.
|
|
1068
|
+
*/
|
|
1069
|
+
provenance?: boolean | readonly string[];
|
|
1070
|
+
/**
|
|
1071
|
+
* How to warm a provider's prompt cache before fanning out, so the stable
|
|
1072
|
+
* prefix is written once and every item reads it.
|
|
1073
|
+
*
|
|
1074
|
+
* - `true` (default): run the first item alone, then fan out. No extra
|
|
1075
|
+
* call, but the batch waits for one full item.
|
|
1076
|
+
* - `"eager"`: send a warm-up call the moment the batch starts and fan out
|
|
1077
|
+
* as soon as it lands. One extra small call; no item waits on another.
|
|
1078
|
+
* The right choice when inputs stream in from an async iterable.
|
|
1079
|
+
* - `false`: fan out immediately.
|
|
1080
|
+
*
|
|
1081
|
+
* Ignored when `primed` is given.
|
|
919
1082
|
*/
|
|
920
|
-
primeCache?: boolean;
|
|
1083
|
+
primeCache?: boolean | "eager";
|
|
1084
|
+
/**
|
|
1085
|
+
* A prefix already warmed with {@link primeCache}, or the promise of one.
|
|
1086
|
+
* Start it while fetching inputs and hand it over here: the batch waits
|
|
1087
|
+
* for it (not for an item) and then fans out. A warm-up that fails is
|
|
1088
|
+
* traced and otherwise ignored — the batch runs, only colder.
|
|
1089
|
+
*/
|
|
1090
|
+
primed?: PrimedPrefix | Promise<PrimedPrefix>;
|
|
921
1091
|
/** How the batch backs off when the provider pushes back. */
|
|
922
1092
|
retry?: RetryOptions;
|
|
923
1093
|
/** Called as each item settles, in completion order, for progress. */
|
|
924
|
-
onItem?: (result: CoerceManyResult<
|
|
1094
|
+
onItem?: (result: CoerceManyResult<T>) => void;
|
|
925
1095
|
/** Stop starting new items; those not yet started fail with the reason. */
|
|
926
1096
|
signal?: AbortSignal;
|
|
927
1097
|
}
|
|
@@ -943,7 +1113,7 @@ interface RetryOptions {
|
|
|
943
1113
|
/** Longest pause, in milliseconds. Default 30000. */
|
|
944
1114
|
maxDelayMs?: number;
|
|
945
1115
|
}
|
|
946
|
-
/** One item's outcome. `index` is its position in the input
|
|
1116
|
+
/** One item's outcome. `index` is its position in the input sequence. */
|
|
947
1117
|
type CoerceManyResult<T> = {
|
|
948
1118
|
ok: true;
|
|
949
1119
|
index: number;
|
|
@@ -952,12 +1122,16 @@ type CoerceManyResult<T> = {
|
|
|
952
1122
|
provenance: Record<string, FieldProvenance>;
|
|
953
1123
|
/** Issues the `onInvalidField` policy absorbed for this item. */
|
|
954
1124
|
issues: ResolvedIssue[];
|
|
955
|
-
/**
|
|
1125
|
+
/** Token usage over every call this item made, repairs included. */
|
|
1126
|
+
usage: CoerceUsage;
|
|
1127
|
+
/** How many times the item was started, retries included. */
|
|
956
1128
|
attempts: number;
|
|
957
1129
|
} | {
|
|
958
1130
|
ok: false;
|
|
959
1131
|
index: number;
|
|
960
1132
|
error: unknown;
|
|
1133
|
+
/** Usage of the calls made before giving up. */
|
|
1134
|
+
usage: CoerceUsage;
|
|
961
1135
|
attempts: number;
|
|
962
1136
|
};
|
|
963
1137
|
/**
|
|
@@ -968,8 +1142,13 @@ type CoerceManyResult<T> = {
|
|
|
968
1142
|
* its own, so one bad listing cannot take down an import. Retryable provider
|
|
969
1143
|
* errors pause the whole batch and try the item again; anything else, a
|
|
970
1144
|
* `CoerceError` included, is that item's final answer.
|
|
1145
|
+
*
|
|
1146
|
+
* Inputs may be an array or any iterable, including an async one, so a
|
|
1147
|
+
* batch can start while its inputs are still being fetched. Every span an
|
|
1148
|
+
* item emits carries `itemIndex` (and `itemLabel` when the input is
|
|
1149
|
+
* labelled), so a trace sink can attribute usage under concurrency.
|
|
971
1150
|
*/
|
|
972
|
-
declare function coerceMany<T>(inputs:
|
|
1151
|
+
declare function coerceMany<T>(inputs: CoerceManyInputs, options: CoerceManyOptions<T>): Promise<CoerceManyResult<T>[]>;
|
|
973
1152
|
|
|
974
1153
|
/**
|
|
975
1154
|
* Build the input for a repair attempt: the original input (already rendered
|
|
@@ -984,6 +1163,12 @@ declare function coerceMany<T>(inputs: readonly CoerceInput[], options: CoerceMa
|
|
|
984
1163
|
* different wording can build their own and call the provider directly.
|
|
985
1164
|
*/
|
|
986
1165
|
declare function buildRepairInput(originalInput: string, rejected: Record<string, unknown>, issues: FieldValidationIssue[]): string;
|
|
1166
|
+
/**
|
|
1167
|
+
* The correction alone — what was wrong and what to do — for a provider that
|
|
1168
|
+
* carries the rejected output as a real assistant turn, so the model does not
|
|
1169
|
+
* need it quoted back.
|
|
1170
|
+
*/
|
|
1171
|
+
declare function buildRepairCorrection(issues: FieldValidationIssue[]): string;
|
|
987
1172
|
|
|
988
1173
|
/**
|
|
989
1174
|
* Configuration options shared by global and per-call config.
|
|
@@ -1003,6 +1188,8 @@ interface SemblGlobalConfig {
|
|
|
1003
1188
|
onInvalidField?: InvalidFieldPolicy;
|
|
1004
1189
|
/** Extra guidance rendered into every system prompt. */
|
|
1005
1190
|
instructions?: string | readonly string[];
|
|
1191
|
+
/** Retries when a non-empty input yields no fields. Default 0. */
|
|
1192
|
+
retryOnEmpty?: number;
|
|
1006
1193
|
/** Cap on total source characters sent to the model. Unbounded by default. */
|
|
1007
1194
|
maxInputChars?: number;
|
|
1008
1195
|
/** Which part of an over-budget source to cut. Default "tail". */
|
|
@@ -1028,6 +1215,8 @@ interface SemblCallConfig {
|
|
|
1028
1215
|
onInvalidField?: InvalidFieldPolicy;
|
|
1029
1216
|
/** Guidance for this call. Replaces, rather than extends, the global list. */
|
|
1030
1217
|
instructions?: string | readonly string[];
|
|
1218
|
+
/** Override the empty-result retry budget for this call */
|
|
1219
|
+
retryOnEmpty?: number;
|
|
1031
1220
|
/** Override the input character budget for this call */
|
|
1032
1221
|
maxInputChars?: number;
|
|
1033
1222
|
/** Override the truncation policy for this call */
|
|
@@ -1046,6 +1235,7 @@ interface ResolvedConfig {
|
|
|
1046
1235
|
maxRepairAttempts?: number;
|
|
1047
1236
|
onInvalidField?: InvalidFieldPolicy;
|
|
1048
1237
|
instructions?: string | readonly string[];
|
|
1238
|
+
retryOnEmpty?: number;
|
|
1049
1239
|
maxInputChars?: number;
|
|
1050
1240
|
truncate?: TruncatePolicy;
|
|
1051
1241
|
preprocess?: PreprocessSource;
|
|
@@ -1178,7 +1368,13 @@ declare function validatePartial(data: Record<string, unknown>, schema: RuntimeS
|
|
|
1178
1368
|
*/
|
|
1179
1369
|
declare class Tracer implements TraceContext {
|
|
1180
1370
|
private sinks;
|
|
1181
|
-
|
|
1371
|
+
private readonly baseAttributes;
|
|
1372
|
+
/**
|
|
1373
|
+
* `baseAttributes` are merged into every span this tracer opens — how a
|
|
1374
|
+
* batch stamps `itemIndex` on the spans of each item, so a sink can tell
|
|
1375
|
+
* whose `llmCall` it is looking at under concurrency.
|
|
1376
|
+
*/
|
|
1377
|
+
constructor(sinks?: TraceSink[], baseAttributes?: Record<string, unknown>);
|
|
1182
1378
|
startSpan(name: string, attributes?: Record<string, unknown>, parent?: TraceSpan): TraceSpan;
|
|
1183
1379
|
endSpan(span: TraceSpan): void;
|
|
1184
1380
|
addEvent(span: TraceSpan, name: string, attributes?: Record<string, unknown>): void;
|
|
@@ -1191,4 +1387,4 @@ declare class ConsoleSink implements TraceSink {
|
|
|
1191
1387
|
write(span: TraceSpan): void;
|
|
1192
1388
|
}
|
|
1193
1389
|
|
|
1194
|
-
export { type BudgetResult, CoerceError, type CoerceInput, type CoerceManyOptions, type CoerceManyResult, type CoerceOptions, Coercible, ConsoleSink, Constrain, type DeepPartial, type DefinedSchema, Describe, type EnumResolution, EnumResolutionError, type EnumResolver, type EnumSourceFailure, type EnumSourceUsage, type FieldBuilder, type FieldConfidence, type FieldConstraints, type FieldDescriptor, type FieldProvenance, type FieldType, type FieldValidationIssue, type Infer, type InferFields, type InvalidFieldPolicy, type IssueResolution, type JsonSchemaDialect, type JsonSchemaOptions, PROVENANCE_INSTRUCTIONS, type PreprocessSource, type PromptOptions, type ProvenanceOptions, type ProvenanceResult, type Provider, type ProviderConfig, type ProviderRequest, type ProviderResponse, type ProviderUsage, type ResolveIssuesOptions, type ResolveIssuesResult, type ResolvedEnums, type ResolvedIssue, type RetryOptions, type RuntimeSchema, SOURCE_INSTRUCTIONS, Schema, type SchemaBundle, SchemaRegistry, type SemblCallConfig, SemblConfig, type SemblGlobalConfig, type Source, type TraceContext, type TraceEvent, type TraceSink, type TraceSpan, Tracer, type TruncatePolicy, type TruncationRecord, type ValidationOptions, ValuesFrom, budgetSources, buildPrompt, buildRepairInput, bundleOf, coerce, coerceMany, coerceWithProvenance, collectEnumSources, defineSchema, field, isCoerceInput, isSource, normalizeInstructions, partialCoerce, partialCoerceWithProvenance, provenanceInstructions, renderSources, resolveEnumSources, resolveIssues, runtimeSchemaToJsonSchema, sembl, splitProvenance, toOpenAIJsonSchema, toProvenanceSchema, toSources, validatePartial, validateStrict };
|
|
1390
|
+
export { type BudgetResult, type CoerceDetails, CoerceError, type CoerceInput, type CoerceManyOptions, type CoerceManyResult, type CoerceOptions, type CoerceUsage, Coercible, ConsoleSink, Constrain, type DeepPartial, type DefinedSchema, Describe, type EnumResolution, EnumResolutionError, type EnumResolver, type EnumResolverContext, type EnumSourceFailure, type EnumSourceUsage, FIELD_FORMATS, type FieldBuilder, type FieldConfidence, type FieldConstraints, type FieldDescriptor, type FieldFormat, type FieldProvenance, type FieldType, type FieldValidationIssue, type Infer, type InferFields, type InvalidFieldPolicy, type IssueResolution, type JsonSchemaDialect, type JsonSchemaOptions, PROVENANCE_INSTRUCTIONS, type PreprocessSource, type PrimeCacheOptions, type PrimedPrefix, type PromptOptions, type ProvenanceOptions, type ProvenanceResult, type Provider, type ProviderConfig, type ProviderRequest, type ProviderResponse, type ProviderTurn, type ProviderUsage, type ResolveIssuesOptions, type ResolveIssuesResult, type ResolvedEnums, type ResolvedIssue, type RetryOptions, type RuntimeSchema, SOURCE_INSTRUCTIONS, Schema, type SchemaBundle, SchemaRegistry, type SemblCallConfig, SemblConfig, type SemblGlobalConfig, type Source, type TraceContext, type TraceEvent, type TraceSink, type TraceSpan, Tracer, type TruncatePolicy, type TruncationRecord, type ValidationOptions, ValuesFrom, budgetSources, buildPrompt, buildRepairCorrection, buildRepairInput, bundleOf, coerce, coerceDetailed, coerceMany, coerceWithProvenance, collectEnumSources, defineSchema, describeFormat, field, formatToJsonSchema, isCoerceInput, isSource, normalizeInstructions, partialCoerce, partialCoerceDetailed, partialCoerceWithProvenance, primeCache, provenanceInstructions, renderSources, resolveEnumSources, resolveIssues, runtimeSchemaToJsonSchema, sembl, splitProvenance, toOpenAIJsonSchema, toProvenanceSchema, toSources, validateFormat, validatePartial, validateStrict };
|