@mochabug/adapt-sdk 0.4.2 → 0.4.5
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/anthropic/anthropic-roundtrip.test.d.ts +2 -0
- package/dist/anthropic/anthropic-roundtrip.test.d.ts.map +1 -0
- package/dist/anthropic/anthropic.test.d.ts +2 -0
- package/dist/anthropic/anthropic.test.d.ts.map +1 -0
- package/dist/anthropic/index.d.ts +40 -65
- package/dist/anthropic/index.d.ts.map +1 -1
- package/dist/api/api.spec.d.ts +2 -0
- package/dist/api/api.spec.d.ts.map +1 -0
- package/dist/api/signal-api.spec.d.ts +17 -0
- package/dist/api/signal-api.spec.d.ts.map +1 -0
- package/dist/cel/cel.test.d.ts +2 -0
- package/dist/cel/cel.test.d.ts.map +1 -0
- package/dist/cjs/anthropic.cjs +1 -1
- package/dist/cjs/anthropic.cjs.map +4 -4
- package/dist/cjs/gemini.cjs +1 -1
- package/dist/cjs/gemini.cjs.map +4 -4
- package/dist/cjs/openai.cjs +1 -1
- package/dist/cjs/openai.cjs.map +4 -4
- package/dist/esm/anthropic.mjs +1 -1
- package/dist/esm/anthropic.mjs.map +4 -4
- package/dist/esm/gemini.mjs +1 -1
- package/dist/esm/gemini.mjs.map +4 -4
- package/dist/esm/openai.mjs +1 -1
- package/dist/esm/openai.mjs.map +4 -4
- package/dist/gemini/gemini-roundtrip.test.d.ts +2 -0
- package/dist/gemini/gemini-roundtrip.test.d.ts.map +1 -0
- package/dist/gemini/gemini.test.d.ts +2 -0
- package/dist/gemini/gemini.test.d.ts.map +1 -0
- package/dist/gemini/index.d.ts +40 -63
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/multi-format-regression.test.d.ts +2 -0
- package/dist/multi-format-regression.test.d.ts.map +1 -0
- package/dist/openai/index.d.ts +46 -67
- package/dist/openai/index.d.ts.map +1 -1
- package/dist/openai/openai-roundtrip.test.d.ts +2 -0
- package/dist/openai/openai-roundtrip.test.d.ts.map +1 -0
- package/dist/openai/openai.test.d.ts +2 -0
- package/dist/openai/openai.test.d.ts.map +1 -0
- package/dist/router/router.spec.d.ts +2 -0
- package/dist/router/router.spec.d.ts.map +1 -0
- package/dist/schema-utils.d.ts +80 -0
- package/dist/schema-utils.d.ts.map +1 -0
- package/dist/schema-utils.test.d.ts +2 -0
- package/dist/schema-utils.test.d.ts.map +1 -0
- package/dist/signals/signals.test.d.ts +2 -0
- package/dist/signals/signals.test.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/gemini/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JTDSchemaJson, SignalDescriptorJson } from '../api';
|
|
2
|
+
import { type ConvertSuccessJson, type ConvertSuccessBinary, type ConvertSuccessSignals, type ConvertFailure, type ConvertSuccess } from '../schema-utils';
|
|
2
3
|
/**
|
|
3
4
|
* JSON Schema subset accepted by the Gemini structured-output API.
|
|
4
5
|
*
|
|
@@ -21,54 +22,7 @@ export interface GeminiSchema {
|
|
|
21
22
|
minimum?: number;
|
|
22
23
|
maximum?: number;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
* Successful conversion result for a JTD format.
|
|
26
|
-
*
|
|
27
|
-
* Returned when the raw LLM output has been coerced to match the JTD schema
|
|
28
|
-
* and passes JTD validation. `data` contains the deserialized, coerced, and
|
|
29
|
-
* JTD-validated JSON value.
|
|
30
|
-
*/
|
|
31
|
-
export interface ConvertSuccessJson {
|
|
32
|
-
success: true;
|
|
33
|
-
kind: 'json';
|
|
34
|
-
/** The deserialized, coerced, and JTD-validated JSON value. */
|
|
35
|
-
data: unknown;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Successful conversion result for a MIME (binary) format.
|
|
39
|
-
*
|
|
40
|
-
* Returned when the raw LLM output matches a MIME format. The base64 string
|
|
41
|
-
* produced by the model is decoded into raw binary bytes.
|
|
42
|
-
*/
|
|
43
|
-
export interface ConvertSuccessBinary {
|
|
44
|
-
success: true;
|
|
45
|
-
kind: 'binary';
|
|
46
|
-
/** The concrete MIME type of the binary content (e.g. `"image/png"`). */
|
|
47
|
-
mimeType: string;
|
|
48
|
-
/** The raw binary data decoded from the base64 string returned by the LLM. */
|
|
49
|
-
data: Uint8Array;
|
|
50
|
-
/** Optional filename, provided by the caller if available. */
|
|
51
|
-
filename?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Failed conversion result.
|
|
55
|
-
*
|
|
56
|
-
* `errors` contains one or more human-readable strings describing validation
|
|
57
|
-
* or coercion failures. Each entry uses a JSON Pointer path prefix
|
|
58
|
-
* (e.g. `"/foo/bar: ..."`) to locate the problem within the data.
|
|
59
|
-
*/
|
|
60
|
-
export interface ConvertFailure {
|
|
61
|
-
success: false;
|
|
62
|
-
/** Array of human-readable error messages with JSON Pointer path prefixes. */
|
|
63
|
-
errors: string[];
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Discriminated union of conversion outcomes.
|
|
67
|
-
*
|
|
68
|
-
* Check `success` first, then narrow on `kind` (`'json'` or `'binary'`)
|
|
69
|
-
* for successful results.
|
|
70
|
-
*/
|
|
71
|
-
export type ConvertResult = ConvertSuccessJson | ConvertSuccessBinary | ConvertFailure;
|
|
25
|
+
export type { ConvertSuccessJson, ConvertSuccessBinary, ConvertSuccessSignals, ConvertFailure, ConvertSuccess, ConvertResult } from '../schema-utils';
|
|
72
26
|
/**
|
|
73
27
|
* Converts JTD schemas or Adapt signal descriptors into Gemini-compatible
|
|
74
28
|
* JSON Schema, and converts raw LLM output back into validated data.
|
|
@@ -110,7 +64,7 @@ export type ConvertResult = ConvertSuccessJson | ConvertSuccessBinary | ConvertF
|
|
|
110
64
|
* const restored = GeminiConversion.fromJSON(cached);
|
|
111
65
|
* ```
|
|
112
66
|
*/
|
|
113
|
-
export declare class GeminiConversion {
|
|
67
|
+
export declare class GeminiConversion<T extends ConvertSuccess = ConvertSuccess> {
|
|
114
68
|
/** The Gemini-specific JSON Schema to pass to the Gemini API as the response schema. */
|
|
115
69
|
readonly schema: GeminiSchema;
|
|
116
70
|
/**
|
|
@@ -123,6 +77,11 @@ export declare class GeminiConversion {
|
|
|
123
77
|
* Set when created via {@link fromSignal}; `undefined` when created via {@link fromJTD}.
|
|
124
78
|
*/
|
|
125
79
|
readonly descriptor?: SignalDescriptorJson;
|
|
80
|
+
/**
|
|
81
|
+
* The original signal descriptors used to build this conversion.
|
|
82
|
+
* Set when created via {@link fromSignals}; `undefined` otherwise.
|
|
83
|
+
*/
|
|
84
|
+
readonly descriptors?: SignalDescriptorJson[];
|
|
126
85
|
/**
|
|
127
86
|
* Build a conversion from a JTD schema.
|
|
128
87
|
*
|
|
@@ -135,7 +94,7 @@ export declare class GeminiConversion {
|
|
|
135
94
|
* @throws If the schema contains an unknown JTD type, an unresolved `ref`,
|
|
136
95
|
* or circular / excessively deep refs (exceeding 32 levels).
|
|
137
96
|
*/
|
|
138
|
-
static fromJTD(jtdSchema: JTDSchemaJson): GeminiConversion
|
|
97
|
+
static fromJTD(jtdSchema: JTDSchemaJson): GeminiConversion<ConvertSuccessJson>;
|
|
139
98
|
/**
|
|
140
99
|
* Build a conversion from an Adapt signal descriptor.
|
|
141
100
|
*
|
|
@@ -149,7 +108,33 @@ export declare class GeminiConversion {
|
|
|
149
108
|
* @throws If the descriptor has no formats, or a format has neither
|
|
150
109
|
* `jtdSchema` nor `mimeType`.
|
|
151
110
|
*/
|
|
152
|
-
static fromSignal(descriptor: SignalDescriptorJson): GeminiConversion
|
|
111
|
+
static fromSignal(descriptor: SignalDescriptorJson): GeminiConversion<ConvertSuccessJson | ConvertSuccessBinary>;
|
|
112
|
+
/**
|
|
113
|
+
* Build a conversion from multiple signal descriptors.
|
|
114
|
+
*
|
|
115
|
+
* Produces an object schema with one property per signal, suitable for
|
|
116
|
+
* use as structured output parameters. Each signal's schema is built via
|
|
117
|
+
* {@link fromSignal} internally.
|
|
118
|
+
*
|
|
119
|
+
* Optional signals are omitted from `required` (Gemini does not use the
|
|
120
|
+
* required+nullable pattern).
|
|
121
|
+
*
|
|
122
|
+
* Receiver/transceiver compatible:
|
|
123
|
+
* ```ts
|
|
124
|
+
* const conv = GeminiConversion.fromSignals(
|
|
125
|
+
* receiver.signals!,
|
|
126
|
+
* receiver.description,
|
|
127
|
+
* receiver.name
|
|
128
|
+
* );
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param signals - Array of signal descriptors.
|
|
132
|
+
* @param description - Optional description for the compound schema.
|
|
133
|
+
* @param label - Optional label (mapped to `title` on the schema).
|
|
134
|
+
* @returns A new {@link GeminiConversion} with `descriptors` set.
|
|
135
|
+
* @throws If any signal has no formats or an invalid format.
|
|
136
|
+
*/
|
|
137
|
+
static fromSignals(signals: SignalDescriptorJson[], description?: string, label?: string): GeminiConversion<ConvertSuccessSignals>;
|
|
153
138
|
/**
|
|
154
139
|
* Restore a {@link GeminiConversion} from its serialized form.
|
|
155
140
|
*
|
|
@@ -182,7 +167,7 @@ export declare class GeminiConversion {
|
|
|
182
167
|
* @param json - The raw value returned by the Gemini API (typically parsed JSON).
|
|
183
168
|
* @returns A {@link ConvertResult} indicating success or failure with errors.
|
|
184
169
|
*/
|
|
185
|
-
convert: (json: unknown) =>
|
|
170
|
+
convert: (json: unknown) => T | ConvertFailure;
|
|
186
171
|
/**
|
|
187
172
|
* Produce a JSON-serializable representation of this conversion.
|
|
188
173
|
*
|
|
@@ -192,15 +177,7 @@ export declare class GeminiConversion {
|
|
|
192
177
|
*
|
|
193
178
|
* Called automatically by `JSON.stringify(conv)`.
|
|
194
179
|
*/
|
|
195
|
-
toJSON():
|
|
196
|
-
schema: GeminiSchema;
|
|
197
|
-
descriptor: SignalDescriptorJson;
|
|
198
|
-
jtdSchema?: undefined;
|
|
199
|
-
} | {
|
|
200
|
-
schema: GeminiSchema;
|
|
201
|
-
jtdSchema: JTDSchemaJson | undefined;
|
|
202
|
-
descriptor?: undefined;
|
|
203
|
-
};
|
|
180
|
+
toJSON(): Record<string, unknown>;
|
|
204
181
|
}
|
|
205
182
|
/**
|
|
206
183
|
* Convenience alias for {@link GeminiConversion.fromJTD}.
|
|
@@ -208,12 +185,12 @@ export declare class GeminiConversion {
|
|
|
208
185
|
* @param jtdSchema - A valid JTD schema (RFC 8927).
|
|
209
186
|
* @returns A new {@link GeminiConversion}.
|
|
210
187
|
*/
|
|
211
|
-
export declare function convertToGeminiSchema(jtdSchema: JTDSchemaJson): GeminiConversion
|
|
188
|
+
export declare function convertToGeminiSchema(jtdSchema: JTDSchemaJson): GeminiConversion<ConvertSuccessJson>;
|
|
212
189
|
/**
|
|
213
190
|
* Convenience alias for {@link GeminiConversion.fromSignal}.
|
|
214
191
|
*
|
|
215
192
|
* @param descriptor - An Adapt signal descriptor.
|
|
216
193
|
* @returns A new {@link GeminiConversion}.
|
|
217
194
|
*/
|
|
218
|
-
export declare function convertSignalToGeminiSchema(descriptor: SignalDescriptorJson): GeminiConversion
|
|
195
|
+
export declare function convertSignalToGeminiSchema(descriptor: SignalDescriptorJson): GeminiConversion<ConvertSuccessJson | ConvertSuccessBinary>;
|
|
219
196
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gemini/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAErB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gemini/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAErB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAC;AAMzB;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EA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;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,WAAW,CAChB,OAAO,EAAE,oBAAoB,EAAE,EAC/B,WAAW,CAAC,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,gBAAgB,CAAC,qBAAqB,CAAC;IAuB1C;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB;IAwBzE,OAAO;IAcP;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,GAAI,MAAM,OAAO,KAAG,CAAC,GAAG,cAAc,CAW3C;IAIF;;;;;;;;OAQG;IACH,MAAM;CAeP;AA2ED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,aAAa,GACvB,gBAAgB,CAAC,kBAAkB,CAAC,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,oBAAoB,GAC/B,gBAAgB,CAAC,kBAAkB,GAAG,oBAAoB,CAAC,CAE7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-format-regression.test.d.ts","sourceRoot":"","sources":["../src/multi-format-regression.test.ts"],"names":[],"mappings":""}
|
package/dist/openai/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JTDSchemaJson, SignalDescriptorJson } from '../api';
|
|
2
|
+
import { type ConvertSuccessJson, type ConvertSuccessBinary, type ConvertSuccessSignals, type ConvertFailure, type ConvertSuccess } from '../schema-utils';
|
|
2
3
|
/**
|
|
3
4
|
* JSON Schema subset accepted by the OpenAI structured-output API (strict mode).
|
|
4
5
|
*
|
|
@@ -23,54 +24,7 @@ export interface OpenAISchema {
|
|
|
23
24
|
$defs?: Record<string, OpenAISchema>;
|
|
24
25
|
$ref?: string;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
* Successful conversion result for a JTD format.
|
|
28
|
-
*
|
|
29
|
-
* Returned when the raw LLM output has been coerced to match the JTD schema
|
|
30
|
-
* and passes JTD validation. `data` contains the deserialized, coerced, and
|
|
31
|
-
* JTD-validated JSON value.
|
|
32
|
-
*/
|
|
33
|
-
export interface ConvertSuccessJson {
|
|
34
|
-
success: true;
|
|
35
|
-
kind: 'json';
|
|
36
|
-
/** The deserialized, coerced, and JTD-validated JSON value. */
|
|
37
|
-
data: unknown;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Successful conversion result for a MIME (binary) format.
|
|
41
|
-
*
|
|
42
|
-
* Returned when the raw LLM output matches a MIME format. The base64 string
|
|
43
|
-
* produced by the model is decoded into raw binary bytes.
|
|
44
|
-
*/
|
|
45
|
-
export interface ConvertSuccessBinary {
|
|
46
|
-
success: true;
|
|
47
|
-
kind: 'binary';
|
|
48
|
-
/** The concrete MIME type of the binary content (e.g. `"image/png"`). */
|
|
49
|
-
mimeType: string;
|
|
50
|
-
/** The raw binary data decoded from the base64 string returned by the LLM. */
|
|
51
|
-
data: Uint8Array;
|
|
52
|
-
/** Optional filename, provided by the caller if available. */
|
|
53
|
-
filename?: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Failed conversion result.
|
|
57
|
-
*
|
|
58
|
-
* `errors` contains one or more human-readable strings describing validation
|
|
59
|
-
* or coercion failures. Each entry uses a JSON Pointer path prefix
|
|
60
|
-
* (e.g. `"/foo/bar: ..."`) to locate the problem within the data.
|
|
61
|
-
*/
|
|
62
|
-
export interface ConvertFailure {
|
|
63
|
-
success: false;
|
|
64
|
-
/** Array of human-readable error messages with JSON Pointer path prefixes. */
|
|
65
|
-
errors: string[];
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Discriminated union of conversion outcomes.
|
|
69
|
-
*
|
|
70
|
-
* Check `success` first, then narrow on `kind` (`'json'` or `'binary'`)
|
|
71
|
-
* for successful results.
|
|
72
|
-
*/
|
|
73
|
-
export type ConvertResult = ConvertSuccessJson | ConvertSuccessBinary | ConvertFailure;
|
|
27
|
+
export type { ConvertSuccessJson, ConvertSuccessBinary, ConvertSuccessSignals, ConvertFailure, ConvertSuccess, ConvertResult, } from '../schema-utils';
|
|
74
28
|
/**
|
|
75
29
|
* Converts JTD schemas or Adapt signal descriptors into OpenAI-compatible
|
|
76
30
|
* JSON Schema (strict mode), and converts raw LLM output back into
|
|
@@ -123,7 +77,7 @@ export type ConvertResult = ConvertSuccessJson | ConvertSuccessBinary | ConvertF
|
|
|
123
77
|
* const restored = OpenAIConversion.fromJSON(cached);
|
|
124
78
|
* ```
|
|
125
79
|
*/
|
|
126
|
-
export declare class OpenAIConversion {
|
|
80
|
+
export declare class OpenAIConversion<T extends ConvertSuccess = ConvertSuccess> {
|
|
127
81
|
/** The OpenAI-specific JSON Schema to pass to the OpenAI API as the response format. */
|
|
128
82
|
readonly schema: OpenAISchema;
|
|
129
83
|
/**
|
|
@@ -145,6 +99,11 @@ export declare class OpenAIConversion {
|
|
|
145
99
|
* Set when created via {@link fromSignal}; `undefined` when created via {@link fromJTD}.
|
|
146
100
|
*/
|
|
147
101
|
readonly descriptor?: SignalDescriptorJson;
|
|
102
|
+
/**
|
|
103
|
+
* The original signal descriptors used to build this conversion.
|
|
104
|
+
* Set when created via {@link fromSignals}; `undefined` otherwise.
|
|
105
|
+
*/
|
|
106
|
+
readonly descriptors?: SignalDescriptorJson[];
|
|
148
107
|
/**
|
|
149
108
|
* Build a conversion from a JTD schema.
|
|
150
109
|
*
|
|
@@ -160,7 +119,7 @@ export declare class OpenAIConversion {
|
|
|
160
119
|
* @throws If the schema contains an unknown JTD type, an unresolved `ref`,
|
|
161
120
|
* or nesting exceeding 32 levels.
|
|
162
121
|
*/
|
|
163
|
-
static fromJTD(jtdSchema: JTDSchemaJson): OpenAIConversion
|
|
122
|
+
static fromJTD(jtdSchema: JTDSchemaJson): OpenAIConversion<ConvertSuccessJson>;
|
|
164
123
|
/**
|
|
165
124
|
* Build a conversion from an Adapt signal descriptor.
|
|
166
125
|
*
|
|
@@ -175,18 +134,48 @@ export declare class OpenAIConversion {
|
|
|
175
134
|
* @throws If the descriptor has no formats, or a format has neither
|
|
176
135
|
* `jtdSchema` nor `mimeType`.
|
|
177
136
|
*/
|
|
178
|
-
static fromSignal(descriptor: SignalDescriptorJson): OpenAIConversion
|
|
137
|
+
static fromSignal(descriptor: SignalDescriptorJson, sharedDefs?: Record<string, JTDSchemaJson>): OpenAIConversion<ConvertSuccessJson | ConvertSuccessBinary>;
|
|
138
|
+
/**
|
|
139
|
+
* Build a conversion from multiple signal descriptors.
|
|
140
|
+
*
|
|
141
|
+
* Produces an object schema with one property per signal, suitable for
|
|
142
|
+
* use as structured output parameters. Each signal's schema is built via
|
|
143
|
+
* {@link fromSignal} internally.
|
|
144
|
+
*
|
|
145
|
+
* For OpenAI strict mode, optional signals are made nullable and all
|
|
146
|
+
* properties are added to `required`.
|
|
147
|
+
*
|
|
148
|
+
* If there is only one signal with a single format, the schema is
|
|
149
|
+
* unwrapped to avoid unnecessary nesting — the signal's format schema
|
|
150
|
+
* is used directly as the object property value.
|
|
151
|
+
*
|
|
152
|
+
* Receiver/transceiver compatible:
|
|
153
|
+
* ```ts
|
|
154
|
+
* const conv = OpenAIConversion.fromSignals(
|
|
155
|
+
* receiver.signals!,
|
|
156
|
+
* receiver.description,
|
|
157
|
+
* receiver.name
|
|
158
|
+
* );
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @param signals - Array of signal descriptors.
|
|
162
|
+
* @param description - Optional description for the compound schema.
|
|
163
|
+
* @param label - Optional label (not used by OpenAI, reserved for other providers).
|
|
164
|
+
* @returns A new {@link OpenAIConversion} with `descriptors` set.
|
|
165
|
+
* @throws If any signal has no formats or an invalid format.
|
|
166
|
+
*/
|
|
167
|
+
static fromSignals(signals: SignalDescriptorJson[], description?: string, label?: string): OpenAIConversion<ConvertSuccessSignals>;
|
|
179
168
|
/**
|
|
180
169
|
* Restore an {@link OpenAIConversion} from its serialized form.
|
|
181
170
|
*
|
|
182
171
|
* Accepts either the JSON string produced by `JSON.stringify(conv)` or the
|
|
183
|
-
* already-parsed plain object. The original `jtdSchema
|
|
184
|
-
* re-processed through the corresponding factory, so the
|
|
185
|
-
* is fully functional.
|
|
172
|
+
* already-parsed plain object. The original `jtdSchema`, `descriptor`, or
|
|
173
|
+
* `descriptors` is re-processed through the corresponding factory, so the
|
|
174
|
+
* restored instance is fully functional.
|
|
186
175
|
*
|
|
187
176
|
* @param data - A JSON string or parsed object previously produced by {@link toJSON}.
|
|
188
177
|
* @returns A fully reconstructed {@link OpenAIConversion}.
|
|
189
|
-
* @throws If the serialized data contains neither `jtdSchema` nor `
|
|
178
|
+
* @throws If the serialized data contains neither `jtdSchema`, `descriptor`, nor `descriptors`.
|
|
190
179
|
*/
|
|
191
180
|
static fromJSON(data: string | Record<string, unknown>): OpenAIConversion;
|
|
192
181
|
private constructor();
|
|
@@ -213,7 +202,7 @@ export declare class OpenAIConversion {
|
|
|
213
202
|
* @param json - The raw value returned by the OpenAI API (typically parsed JSON).
|
|
214
203
|
* @returns A {@link ConvertResult} indicating success or failure with errors.
|
|
215
204
|
*/
|
|
216
|
-
convert: (json: unknown) =>
|
|
205
|
+
convert: (json: unknown) => T | ConvertFailure;
|
|
217
206
|
/**
|
|
218
207
|
* Produce a JSON-serializable representation of this conversion.
|
|
219
208
|
*
|
|
@@ -224,17 +213,7 @@ export declare class OpenAIConversion {
|
|
|
224
213
|
*
|
|
225
214
|
* Called automatically by `JSON.stringify(conv)`.
|
|
226
215
|
*/
|
|
227
|
-
toJSON():
|
|
228
|
-
schema: OpenAISchema;
|
|
229
|
-
strict: boolean;
|
|
230
|
-
descriptor: SignalDescriptorJson;
|
|
231
|
-
jtdSchema?: undefined;
|
|
232
|
-
} | {
|
|
233
|
-
schema: OpenAISchema;
|
|
234
|
-
strict: boolean;
|
|
235
|
-
jtdSchema: JTDSchemaJson | undefined;
|
|
236
|
-
descriptor?: undefined;
|
|
237
|
-
};
|
|
216
|
+
toJSON(): Record<string, unknown>;
|
|
238
217
|
}
|
|
239
218
|
/**
|
|
240
219
|
* Convenience alias for {@link OpenAIConversion.fromJTD}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAErB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAErB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAcL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAC;AAOzB;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,oBAAoB,CAAC,EAAE,KAAK,CAAC;IAC7B,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;CAC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;;;;;;;OAsBG;IACH,OAAO,GAAI,MAAM,OAAO,KAAG,CAAC,GAAG,cAAc,CAW3C;IAIF;;;;;;;;;OASG;IACH,MAAM;CAuBP;AAsHD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,aAAa,GACvB,gBAAgB,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,oBAAoB,GAC/B,gBAAgB,CAElB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-roundtrip.test.d.ts","sourceRoot":"","sources":["../../src/openai/openai-roundtrip.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.test.d.ts","sourceRoot":"","sources":["../../src/openai/openai.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.spec.d.ts","sourceRoot":"","sources":["../../src/router/router.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for JSON Schema providers (OpenAI, Anthropic, Gemini).
|
|
3
|
+
*
|
|
4
|
+
* Contains constants, types, convert output pipeline, definition pooling,
|
|
5
|
+
* and schema inspection helpers used identically across providers.
|
|
6
|
+
*/
|
|
7
|
+
import type { JTDSchemaJson, SignalDescriptorJson, SignalFormatJson } from './api';
|
|
8
|
+
export declare const MAX_REF_DEPTH = 32;
|
|
9
|
+
export declare const INTEGER_BOUNDS: Record<string, {
|
|
10
|
+
minimum: number;
|
|
11
|
+
maximum: number;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const FLOAT32_BOUNDS: {
|
|
14
|
+
minimum: number;
|
|
15
|
+
maximum: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const UNSTRUCTURED_DESC: string;
|
|
18
|
+
export declare const UNSTRUCTURED_VARIANT_DESC: string;
|
|
19
|
+
export declare const VALUES_ARRAY_DESC: string;
|
|
20
|
+
export declare function nullableType(baseType: string, nullable: boolean): string | string[];
|
|
21
|
+
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
22
|
+
export declare function isUnstructuredSchema(schema: JTDSchemaJson): boolean;
|
|
23
|
+
export declare function isRootUnstructured(schema: JTDSchemaJson, defs: Record<string, JTDSchemaJson> | undefined): boolean;
|
|
24
|
+
export interface ConvertSuccessJson {
|
|
25
|
+
success: true;
|
|
26
|
+
kind: 'json';
|
|
27
|
+
data: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ConvertSuccessBinary {
|
|
30
|
+
success: true;
|
|
31
|
+
kind: 'binary';
|
|
32
|
+
mimeType: string;
|
|
33
|
+
data: Uint8Array;
|
|
34
|
+
filename?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ConvertSuccessSignals {
|
|
37
|
+
success: true;
|
|
38
|
+
kind: 'signals';
|
|
39
|
+
signals: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
export interface ConvertFailure {
|
|
42
|
+
success: false;
|
|
43
|
+
errors: string[];
|
|
44
|
+
}
|
|
45
|
+
export type ConvertSuccess = ConvertSuccessJson | ConvertSuccessBinary | ConvertSuccessSignals;
|
|
46
|
+
export type ConvertResult = ConvertSuccess | ConvertFailure;
|
|
47
|
+
export declare function convertJTDOutput(jtdSchema: JTDSchemaJson, json: unknown, coerce: (value: unknown, schema: JTDSchemaJson, defs: Record<string, JTDSchemaJson> | undefined, depth: number) => unknown): ConvertResult;
|
|
48
|
+
export declare function convertMimeOutput(mimeType: string, json: unknown): ConvertResult;
|
|
49
|
+
export declare function convertSingleFormatOutput(fmt: SignalFormatJson, json: unknown, coerce: (value: unknown, schema: JTDSchemaJson, defs: Record<string, JTDSchemaJson> | undefined, depth: number) => unknown): ConvertResult;
|
|
50
|
+
export declare function convertSignalOutput(descriptor: SignalDescriptorJson, json: unknown, coerce: (value: unknown, schema: JTDSchemaJson, defs: Record<string, JTDSchemaJson> | undefined, depth: number) => unknown): ConvertResult;
|
|
51
|
+
export declare function convertSignalsOutput(descriptors: SignalDescriptorJson[], json: unknown, coerce: (value: unknown, schema: JTDSchemaJson, defs: Record<string, JTDSchemaJson> | undefined, depth: number) => unknown): ConvertResult;
|
|
52
|
+
/** Minimal shape for $ref-bearing schemas (satisfied by OpenAISchema and AnthropicSchema). */
|
|
53
|
+
interface RefNode {
|
|
54
|
+
properties?: Record<string, RefNode>;
|
|
55
|
+
items?: RefNode;
|
|
56
|
+
anyOf?: RefNode[];
|
|
57
|
+
$defs?: Record<string, RefNode>;
|
|
58
|
+
$ref?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function walkSchema<T extends RefNode>(schema: T, fn: (node: T) => void): void;
|
|
61
|
+
/**
|
|
62
|
+
* Pre-scan all signal descriptors, pool their JTD definitions.
|
|
63
|
+
* Deduplicates identical definition SETS; renames conflicts with `_N` suffix.
|
|
64
|
+
*
|
|
65
|
+
* Equivalence is checked per-format: all definitions within a single format's
|
|
66
|
+
* `definitions` block are treated as a unit. Two formats with the same set of
|
|
67
|
+
* definition names and identical schemas (deep-equal) share their defs.
|
|
68
|
+
* If ANY definition name conflicts (same name, different schema), ALL defs
|
|
69
|
+
* from that format get their own namespace to preserve internal cross-references.
|
|
70
|
+
*
|
|
71
|
+
* Returns the merged JTD definitions and signal copies with:
|
|
72
|
+
* - refs rewritten to match merged names
|
|
73
|
+
* - definitions stripped (they live in the merged pool now)
|
|
74
|
+
*/
|
|
75
|
+
export declare function poolSignalDefinitions(signals: SignalDescriptorJson[]): {
|
|
76
|
+
mergedDefs: Record<string, JTDSchemaJson>;
|
|
77
|
+
signalsCopy: SignalDescriptorJson[];
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=schema-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../src/schema-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OA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AAO,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GACzH,aAAa,CA4Bf;AAMD,8FAA8F;AAC9F,UAAU,OAAO;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAMpF;AAsCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG;IACtE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC,CAwFA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.test.d.ts","sourceRoot":"","sources":["../src/schema-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.test.d.ts","sourceRoot":"","sources":["../../src/signals/signals.test.ts"],"names":[],"mappings":""}
|