@mochabug/adapt-sdk 0.3.12 → 0.4.1
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/index.d.ts +256 -0
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/cjs/anthropic.cjs +2 -0
- package/dist/cjs/anthropic.cjs.map +7 -0
- package/dist/cjs/cel.cjs +3 -3
- package/dist/cjs/cel.cjs.map +1 -1
- package/dist/cjs/gemini.cjs +2 -0
- package/dist/cjs/gemini.cjs.map +7 -0
- package/dist/cjs/openai.cjs +2 -0
- package/dist/cjs/openai.cjs.map +7 -0
- package/dist/cjs/signals.cjs +1 -1
- package/dist/cjs/signals.cjs.map +3 -3
- package/dist/esm/anthropic.mjs +2 -0
- package/dist/esm/anthropic.mjs.map +7 -0
- package/dist/esm/cel.mjs +3 -3
- package/dist/esm/cel.mjs.map +2 -2
- package/dist/esm/gemini.mjs +2 -0
- package/dist/esm/gemini.mjs.map +7 -0
- package/dist/esm/openai.mjs +2 -0
- package/dist/esm/openai.mjs.map +7 -0
- package/dist/esm/signals.mjs +1 -1
- package/dist/esm/signals.mjs.map +3 -3
- package/dist/gemini/index.d.ts +219 -0
- package/dist/gemini/index.d.ts.map +1 -0
- package/dist/openai/index.d.ts +253 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/signals/index.d.ts +3 -110
- package/dist/signals/index.d.ts.map +1 -1
- package/package.json +18 -2
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import type { JTDSchemaJson, SignalDescriptorJson } from '../api';
|
|
2
|
+
/**
|
|
3
|
+
* JSON Schema subset accepted by the OpenAI structured-output API (strict mode).
|
|
4
|
+
*
|
|
5
|
+
* This is the provider-specific representation produced by {@link OpenAIConversion}.
|
|
6
|
+
* It covers the keywords that OpenAI inspects when constraining model output in
|
|
7
|
+
* strict mode: `type`, `properties`, `required`, `additionalProperties`, `enum`,
|
|
8
|
+
* `format`, `items`, `minimum`/`maximum`, `anyOf`, `$defs`, `$ref`, and
|
|
9
|
+
* `description`.
|
|
10
|
+
*/
|
|
11
|
+
export interface OpenAISchema {
|
|
12
|
+
type?: string | string[];
|
|
13
|
+
description?: string;
|
|
14
|
+
properties?: Record<string, OpenAISchema>;
|
|
15
|
+
required?: string[];
|
|
16
|
+
additionalProperties?: false;
|
|
17
|
+
enum?: (string | number | null)[];
|
|
18
|
+
format?: string;
|
|
19
|
+
items?: OpenAISchema;
|
|
20
|
+
minimum?: number;
|
|
21
|
+
maximum?: number;
|
|
22
|
+
anyOf?: OpenAISchema[];
|
|
23
|
+
$defs?: Record<string, OpenAISchema>;
|
|
24
|
+
$ref?: string;
|
|
25
|
+
}
|
|
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;
|
|
74
|
+
/**
|
|
75
|
+
* Converts JTD schemas or Adapt signal descriptors into OpenAI-compatible
|
|
76
|
+
* JSON Schema (strict mode), and converts raw LLM output back into
|
|
77
|
+
* validated data.
|
|
78
|
+
*
|
|
79
|
+
* ### JTD form mapping
|
|
80
|
+
* - **type** -- mapped to the corresponding JSON Schema `type` (`string`,
|
|
81
|
+
* `number`, `integer`, `boolean`). Integer sub-types (int8 .. uint32) add
|
|
82
|
+
* `minimum`/`maximum` bounds. `timestamp` becomes `string` with
|
|
83
|
+
* `format: "date-time"`.
|
|
84
|
+
* - **enum** -- mapped to `type: "string"` with an `enum` array.
|
|
85
|
+
* - **elements** -- mapped to `type: "array"` with `items`.
|
|
86
|
+
* - **properties / optionalProperties** -- mapped to `type: "object"` with
|
|
87
|
+
* `properties`, `required`, and `additionalProperties: false`. OpenAI
|
|
88
|
+
* strict mode requires all properties to be present, so **optional
|
|
89
|
+
* properties are made required and nullable** (their schemas are wrapped
|
|
90
|
+
* with a `"null"` type variant). During {@link convert}, null values for
|
|
91
|
+
* optional properties are stripped back out.
|
|
92
|
+
* - **values** -- mapped to an array of `{key, value}` objects because
|
|
93
|
+
* OpenAI strict mode does not support `additionalProperties`. During
|
|
94
|
+
* {@link convert}, the array is coerced back into a plain `Record`.
|
|
95
|
+
* - **discriminator** -- mapped to `anyOf` with one variant per mapping
|
|
96
|
+
* entry. Each variant is a flat object containing the discriminator key
|
|
97
|
+
* (with a single-value `enum`) plus the variant's own properties.
|
|
98
|
+
*
|
|
99
|
+
* ### Unstructured schemas
|
|
100
|
+
* Empty JTD schemas or schemas with only `additionalProperties: true` are
|
|
101
|
+
* considered unstructured. They produce an empty `{}` JSON Schema with
|
|
102
|
+
* `strict: false`, and during {@link convert} the raw string output is
|
|
103
|
+
* parsed via `JSON.parse` back into an arbitrary value.
|
|
104
|
+
*
|
|
105
|
+
* ### MIME formats
|
|
106
|
+
* MIME signal formats become `type: "string"` with a description requesting
|
|
107
|
+
* base64-encoded content. On {@link convert}, the base64 string is decoded
|
|
108
|
+
* into a {@link ConvertSuccessBinary} result.
|
|
109
|
+
*
|
|
110
|
+
* ### Serialization
|
|
111
|
+
* `JSON.stringify(conv)` produces a JSON-safe object via {@link toJSON}.
|
|
112
|
+
* Use {@link fromJSON} to restore a fully functional instance from the
|
|
113
|
+
* serialized form (string or parsed object).
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* const conv = OpenAIConversion.fromJTD(jtdSchema);
|
|
117
|
+
* conv.schema; // OpenAI JSON Schema to pass to the LLM
|
|
118
|
+
* conv.strict; // whether strict mode applies
|
|
119
|
+
* conv.convert(output); // coerce + validate -> ConvertResult
|
|
120
|
+
*
|
|
121
|
+
* // Serialize & restore
|
|
122
|
+
* const cached = JSON.stringify(conv);
|
|
123
|
+
* const restored = OpenAIConversion.fromJSON(cached);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare class OpenAIConversion {
|
|
127
|
+
/** The OpenAI-specific JSON Schema to pass to the OpenAI API as the response format. */
|
|
128
|
+
readonly schema: OpenAISchema;
|
|
129
|
+
/**
|
|
130
|
+
* Whether the schema qualifies for OpenAI strict structured-output mode.
|
|
131
|
+
*
|
|
132
|
+
* This is `false` when the root JTD schema is empty or unstructured (e.g.
|
|
133
|
+
* the empty schema `{}` or a properties form with no real properties and
|
|
134
|
+
* `additionalProperties: true`). In that case `schema` is `{}` and the
|
|
135
|
+
* model output is unconstrained.
|
|
136
|
+
*/
|
|
137
|
+
readonly strict: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* The original JTD schema used to build this conversion.
|
|
140
|
+
* Set when created via {@link fromJTD}; `undefined` when created via {@link fromSignal}.
|
|
141
|
+
*/
|
|
142
|
+
readonly jtdSchema?: JTDSchemaJson;
|
|
143
|
+
/**
|
|
144
|
+
* The original signal descriptor used to build this conversion.
|
|
145
|
+
* Set when created via {@link fromSignal}; `undefined` when created via {@link fromJTD}.
|
|
146
|
+
*/
|
|
147
|
+
readonly descriptor?: SignalDescriptorJson;
|
|
148
|
+
/**
|
|
149
|
+
* Build a conversion from a JTD schema.
|
|
150
|
+
*
|
|
151
|
+
* Recursively converts every JTD form into the equivalent OpenAI JSON Schema
|
|
152
|
+
* node. Definitions (`jtdSchema.definitions`) are emitted as `$defs` at the
|
|
153
|
+
* root level, and references become `$ref` pointers.
|
|
154
|
+
*
|
|
155
|
+
* If the root schema is unstructured, the result has an empty `schema` and
|
|
156
|
+
* `strict: false`.
|
|
157
|
+
*
|
|
158
|
+
* @param jtdSchema - A valid JTD schema (RFC 8927).
|
|
159
|
+
* @returns A new {@link OpenAIConversion} with `jtdSchema` set.
|
|
160
|
+
* @throws If the schema contains an unknown JTD type, an unresolved `ref`,
|
|
161
|
+
* or nesting exceeding 32 levels.
|
|
162
|
+
*/
|
|
163
|
+
static fromJTD(jtdSchema: JTDSchemaJson): OpenAIConversion;
|
|
164
|
+
/**
|
|
165
|
+
* Build a conversion from an Adapt signal descriptor.
|
|
166
|
+
*
|
|
167
|
+
* If the descriptor has a single format, its schema is used directly
|
|
168
|
+
* (unwrapped). If it has multiple formats, a wrapper object schema is
|
|
169
|
+
* produced with `format_0`, `format_1`, ... properties -- each made
|
|
170
|
+
* required and nullable so the LLM populates exactly one and sets the
|
|
171
|
+
* rest to `null`.
|
|
172
|
+
*
|
|
173
|
+
* @param descriptor - An Adapt signal descriptor with one or more formats.
|
|
174
|
+
* @returns A new {@link OpenAIConversion} with `descriptor` set.
|
|
175
|
+
* @throws If the descriptor has no formats, or a format has neither
|
|
176
|
+
* `jtdSchema` nor `mimeType`.
|
|
177
|
+
*/
|
|
178
|
+
static fromSignal(descriptor: SignalDescriptorJson): OpenAIConversion;
|
|
179
|
+
/**
|
|
180
|
+
* Restore an {@link OpenAIConversion} from its serialized form.
|
|
181
|
+
*
|
|
182
|
+
* Accepts either the JSON string produced by `JSON.stringify(conv)` or the
|
|
183
|
+
* already-parsed plain object. The original `jtdSchema` or `descriptor` is
|
|
184
|
+
* re-processed through the corresponding factory, so the restored instance
|
|
185
|
+
* is fully functional.
|
|
186
|
+
*
|
|
187
|
+
* @param data - A JSON string or parsed object previously produced by {@link toJSON}.
|
|
188
|
+
* @returns A fully reconstructed {@link OpenAIConversion}.
|
|
189
|
+
* @throws If the serialized data contains neither `jtdSchema` nor `descriptor`.
|
|
190
|
+
*/
|
|
191
|
+
static fromJSON(data: string | Record<string, unknown>): OpenAIConversion;
|
|
192
|
+
private constructor();
|
|
193
|
+
/**
|
|
194
|
+
* Convert raw LLM output into a validated result.
|
|
195
|
+
*
|
|
196
|
+
* For JTD-based conversions, the value is coerced to conform to the original
|
|
197
|
+
* JTD schema:
|
|
198
|
+
* - Non-integer numbers are rounded for integer types.
|
|
199
|
+
* - Null values on optional properties are stripped (OpenAI required+nullable
|
|
200
|
+
* encoding is reversed).
|
|
201
|
+
* - `{key, value}` arrays from the values form are reassembled into Records.
|
|
202
|
+
* - Unstructured/empty schemas parse the raw JSON string via `JSON.parse`.
|
|
203
|
+
*
|
|
204
|
+
* The coerced value is then validated against the JTD schema. Returns
|
|
205
|
+
* {@link ConvertSuccessJson} on success.
|
|
206
|
+
*
|
|
207
|
+
* For MIME-based conversions, the value is expected to be a base64 string
|
|
208
|
+
* which is decoded into raw bytes. Returns {@link ConvertSuccessBinary}.
|
|
209
|
+
*
|
|
210
|
+
* For multi-format signals, the first non-null `format_N` property is
|
|
211
|
+
* selected and converted individually.
|
|
212
|
+
*
|
|
213
|
+
* @param json - The raw value returned by the OpenAI API (typically parsed JSON).
|
|
214
|
+
* @returns A {@link ConvertResult} indicating success or failure with errors.
|
|
215
|
+
*/
|
|
216
|
+
convert: (json: unknown) => ConvertResult;
|
|
217
|
+
/**
|
|
218
|
+
* Produce a JSON-serializable representation of this conversion.
|
|
219
|
+
*
|
|
220
|
+
* The output includes the OpenAI `schema`, `strict` flag, and either the
|
|
221
|
+
* original `jtdSchema` or `descriptor` (whichever was used to create this
|
|
222
|
+
* instance), which is sufficient to fully restore the conversion via
|
|
223
|
+
* {@link fromJSON}.
|
|
224
|
+
*
|
|
225
|
+
* Called automatically by `JSON.stringify(conv)`.
|
|
226
|
+
*/
|
|
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
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Convenience alias for {@link OpenAIConversion.fromJTD}.
|
|
241
|
+
*
|
|
242
|
+
* @param jtdSchema - A valid JTD schema (RFC 8927).
|
|
243
|
+
* @returns A new {@link OpenAIConversion}.
|
|
244
|
+
*/
|
|
245
|
+
export declare function convertToOpenAISchema(jtdSchema: JTDSchemaJson): OpenAIConversion;
|
|
246
|
+
/**
|
|
247
|
+
* Convenience alias for {@link OpenAIConversion.fromSignal}.
|
|
248
|
+
*
|
|
249
|
+
* @param descriptor - An Adapt signal descriptor.
|
|
250
|
+
* @returns A new {@link OpenAIConversion}.
|
|
251
|
+
*/
|
|
252
|
+
export declare function convertSignalToOpenAISchema(descriptor: SignalDescriptorJson): OpenAIConversion;
|
|
253
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAOhB;;;;;;;;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;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAA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AAS,EAAE,aAAa,GACvB,gBAAgB,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,oBAAoB,GAC/B,gBAAgB,CAElB"}
|
package/dist/signals/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export declare function fuzzJTD(schema: JTDSchemaJson, definitions?: Record<stri
|
|
|
5
5
|
* Validate a value against a JTD schema, returning an array of error messages.
|
|
6
6
|
* Delegates to the `jtd` npm package for spec-compliant validation.
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function validateJsonAgainstJTD(schema: JTDSchemaJson, value: unknown, definitions?: Record<string, JTDSchemaJson>): string[];
|
|
9
9
|
/** Validate a JSON value against a single SignalFormatJson. */
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function validateJsonAgainstSignal(format: SignalFormatJson, jsonValue: unknown): string[];
|
|
11
11
|
/** Validate a JSON value against a SignalDescriptorJson (valid if value matches ANY JTD format). */
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function validateJsonAgainstSignal(descriptor: SignalDescriptorJson, jsonValue: unknown): string[];
|
|
13
13
|
/**
|
|
14
14
|
* Convert JTD (JSON Type Definition) schema to JSON Schema for validation.
|
|
15
15
|
*
|
|
@@ -24,28 +24,6 @@ export declare function validateValueAgainstSignal(descriptor: SignalDescriptorJ
|
|
|
24
24
|
* - Discriminator form: { discriminator: "...", mapping: {...} }
|
|
25
25
|
*/
|
|
26
26
|
export declare function jtdToJsonSchema(jtdSchema: JTDSchemaJson, definitions?: Record<string, JTDSchemaJson>, isRoot?: boolean): any;
|
|
27
|
-
export interface UniversalJsonSchema {
|
|
28
|
-
type?: string | string[];
|
|
29
|
-
title?: string;
|
|
30
|
-
description?: string;
|
|
31
|
-
enum?: (string | number | null)[];
|
|
32
|
-
format?: 'date-time' | 'date' | 'time';
|
|
33
|
-
properties?: Record<string, UniversalJsonSchema>;
|
|
34
|
-
required?: string[];
|
|
35
|
-
additionalProperties?: false;
|
|
36
|
-
items?: UniversalJsonSchema;
|
|
37
|
-
}
|
|
38
|
-
export interface ConversionSuccess {
|
|
39
|
-
success: true;
|
|
40
|
-
schema: UniversalJsonSchema;
|
|
41
|
-
}
|
|
42
|
-
export interface ConversionFailure {
|
|
43
|
-
success: false;
|
|
44
|
-
error: string;
|
|
45
|
-
}
|
|
46
|
-
export type ConversionResult = ConversionSuccess | ConversionFailure;
|
|
47
|
-
/** Convert JTD schema to Universal JSON Schema compatible with Claude, Gemini, and OpenAI. */
|
|
48
|
-
export declare function jtdToUniversalJsonSchema(jtdSchema: JTDSchemaJson): ConversionResult;
|
|
49
27
|
export declare const MAX_VALIDATION_DEPTH = 32;
|
|
50
28
|
export declare const MAX_VALIDATION_ERRORS = 100;
|
|
51
29
|
/** Validate that the input is a valid JTD schema. */
|
|
@@ -56,17 +34,6 @@ export declare function validateJTDSchema(schema: unknown): {
|
|
|
56
34
|
valid: false;
|
|
57
35
|
error: string;
|
|
58
36
|
};
|
|
59
|
-
/**
|
|
60
|
-
* Validate that the input is a valid JTD schema compatible with universal JSON schema
|
|
61
|
-
* (Anthropic Claude, Google Gemini, and OpenAI structured outputs).
|
|
62
|
-
*/
|
|
63
|
-
export declare function validateUniversalJTD(schema: unknown): {
|
|
64
|
-
valid: true;
|
|
65
|
-
schema: JTDSchemaJson;
|
|
66
|
-
} | {
|
|
67
|
-
valid: false;
|
|
68
|
-
error: string;
|
|
69
|
-
};
|
|
70
37
|
/** Parse and validate a JSON string. */
|
|
71
38
|
export declare function validateJSON(jsonString: string): {
|
|
72
39
|
valid: boolean;
|
|
@@ -81,80 +48,6 @@ export declare function validateJTDSchemaString(schemaString: string): {
|
|
|
81
48
|
valid: false;
|
|
82
49
|
error: string;
|
|
83
50
|
};
|
|
84
|
-
/** Parse a JSON string and validate it as a universal JTD schema (compatible with Claude, Gemini, OpenAI). */
|
|
85
|
-
export declare function validateUniversalJTDSchemaString(schemaString: string): {
|
|
86
|
-
valid: true;
|
|
87
|
-
schema: JTDSchemaJson;
|
|
88
|
-
} | {
|
|
89
|
-
valid: false;
|
|
90
|
-
error: string;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Monaco editor JSON schema configuration for JTD schemas compatible with
|
|
94
|
-
* Anthropic Claude, Google Gemini, and OpenAI structured outputs.
|
|
95
|
-
* This is a restricted subset of JTD that excludes discriminator unions, refs, and values (dictionaries).
|
|
96
|
-
*/
|
|
97
|
-
export declare const UNIVERSAL_JTD_SCHEMA_CONFIG: {
|
|
98
|
-
uri: string;
|
|
99
|
-
fileMatch: string[];
|
|
100
|
-
schema: {
|
|
101
|
-
$schema: string;
|
|
102
|
-
title: string;
|
|
103
|
-
description: string;
|
|
104
|
-
type: string;
|
|
105
|
-
properties: {
|
|
106
|
-
type: {
|
|
107
|
-
description: string;
|
|
108
|
-
enum: string[];
|
|
109
|
-
};
|
|
110
|
-
enum: {
|
|
111
|
-
description: string;
|
|
112
|
-
type: string;
|
|
113
|
-
items: {
|
|
114
|
-
type: string;
|
|
115
|
-
};
|
|
116
|
-
minItems: number;
|
|
117
|
-
};
|
|
118
|
-
elements: {
|
|
119
|
-
description: string;
|
|
120
|
-
$ref: string;
|
|
121
|
-
};
|
|
122
|
-
properties: {
|
|
123
|
-
description: string;
|
|
124
|
-
type: string;
|
|
125
|
-
additionalProperties: {
|
|
126
|
-
$ref: string;
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
optionalProperties: {
|
|
130
|
-
description: string;
|
|
131
|
-
type: string;
|
|
132
|
-
additionalProperties: {
|
|
133
|
-
$ref: string;
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
nullable: {
|
|
137
|
-
description: string;
|
|
138
|
-
type: string;
|
|
139
|
-
};
|
|
140
|
-
metadata: {
|
|
141
|
-
description: string;
|
|
142
|
-
type: string;
|
|
143
|
-
properties: {
|
|
144
|
-
title: {
|
|
145
|
-
type: string;
|
|
146
|
-
description: string;
|
|
147
|
-
};
|
|
148
|
-
description: {
|
|
149
|
-
type: string;
|
|
150
|
-
description: string;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
additionalProperties: boolean;
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
51
|
/** Monaco editor JSON schema configuration for JTD schema IntelliSense and validation. */
|
|
159
52
|
export declare const JTD_SCHEMA_CONFIG: {
|
|
160
53
|
uri: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signals/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,QAAQ,CAAC;AAWhB,0DAA0D;AAC1D,wBAAgB,OAAO,CACrB,MAAM,EAAE,aAAa,EACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC3C,MAAM,GAAE,MAAU,GACjB,OAAO,CA8ET;AA0GD;;;GAGG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signals/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,QAAQ,CAAC;AAWhB,0DAA0D;AAC1D,wBAAgB,OAAO,CACrB,MAAM,EAAE,aAAa,EACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC3C,MAAM,GAAE,MAAU,GACjB,OAAO,CA8ET;AA0GD;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,OAAO,EACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAC1C,MAAM,EAAE,CA6BV;AAMD,+DAA+D;AAC/D,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,OAAO,GACjB,MAAM,EA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|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The API toolkit to facilitate mochabug adapt plugin development",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -44,6 +44,21 @@
|
|
|
44
44
|
"types": "./dist/signals/index.d.ts",
|
|
45
45
|
"import": "./dist/esm/signals.mjs",
|
|
46
46
|
"require": "./dist/cjs/signals.cjs"
|
|
47
|
+
},
|
|
48
|
+
"./gemini": {
|
|
49
|
+
"types": "./dist/gemini/index.d.ts",
|
|
50
|
+
"import": "./dist/esm/gemini.mjs",
|
|
51
|
+
"require": "./dist/cjs/gemini.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./openai": {
|
|
54
|
+
"types": "./dist/openai/index.d.ts",
|
|
55
|
+
"import": "./dist/esm/openai.mjs",
|
|
56
|
+
"require": "./dist/cjs/openai.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./anthropic": {
|
|
59
|
+
"types": "./dist/anthropic/index.d.ts",
|
|
60
|
+
"import": "./dist/esm/anthropic.mjs",
|
|
61
|
+
"require": "./dist/cjs/anthropic.cjs"
|
|
47
62
|
}
|
|
48
63
|
},
|
|
49
64
|
"scripts": {
|
|
@@ -77,6 +92,7 @@
|
|
|
77
92
|
"@jest/globals": "^30.3.0",
|
|
78
93
|
"@types/jest": "^30.0.0",
|
|
79
94
|
"@types/react": "^19.2.14",
|
|
95
|
+
"ajv": "^8.18.0",
|
|
80
96
|
"babel-jest": "^30.3.0",
|
|
81
97
|
"esbuild": "^0.27.4",
|
|
82
98
|
"jest": "^30.3.0",
|
|
@@ -89,7 +105,7 @@
|
|
|
89
105
|
"@connectrpc/connect": "^2.1.1",
|
|
90
106
|
"fuse.js": "^7.1.0",
|
|
91
107
|
"jtd": "^0.1.1",
|
|
92
|
-
"path-to-regexp": "^8.
|
|
108
|
+
"path-to-regexp": "^8.4.1"
|
|
93
109
|
},
|
|
94
110
|
"peerDependencies": {
|
|
95
111
|
"react": "^19.0.0"
|