@mochabug/adapt-sdk 0.4.1 → 0.4.3

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.
@@ -70,7 +70,34 @@ export interface ConvertFailure {
70
70
  * Check `success` first, then narrow on `kind` (`'json'` or `'binary'`)
71
71
  * for successful results.
72
72
  */
73
- export type ConvertResult = ConvertSuccessJson | ConvertSuccessBinary | ConvertFailure;
73
+ /**
74
+ * Successful conversion result for multiple signal descriptors.
75
+ *
76
+ * Returned when the conversion was created via {@link OpenAIConversion.fromSignals}.
77
+ * Contains per-signal results keyed by signal name.
78
+ */
79
+ export interface ConvertSuccessSignals {
80
+ success: true;
81
+ kind: 'signals';
82
+ /**
83
+ * Per-signal values in dispatch-ready format.
84
+ *
85
+ * JSON signals are raw values (the JTD-validated data).
86
+ * Binary signals are `{ data: Uint8Array, mimeType: string, filename?: string }`.
87
+ *
88
+ * This record can be passed directly to `dispatchExchange()` or `send()`.
89
+ */
90
+ signals: Record<string, unknown>;
91
+ }
92
+ /** Union of all successful conversion outcomes. */
93
+ export type ConvertSuccess = ConvertSuccessJson | ConvertSuccessBinary | ConvertSuccessSignals;
94
+ /**
95
+ * Discriminated union of conversion outcomes.
96
+ *
97
+ * Check `success` first, then narrow on `kind` (`'json'`, `'binary'`, or
98
+ * `'signals'`) for successful results.
99
+ */
100
+ export type ConvertResult = ConvertSuccess | ConvertFailure;
74
101
  /**
75
102
  * Converts JTD schemas or Adapt signal descriptors into OpenAI-compatible
76
103
  * JSON Schema (strict mode), and converts raw LLM output back into
@@ -123,7 +150,7 @@ export type ConvertResult = ConvertSuccessJson | ConvertSuccessBinary | ConvertF
123
150
  * const restored = OpenAIConversion.fromJSON(cached);
124
151
  * ```
125
152
  */
126
- export declare class OpenAIConversion {
153
+ export declare class OpenAIConversion<T extends ConvertSuccess = ConvertSuccess> {
127
154
  /** The OpenAI-specific JSON Schema to pass to the OpenAI API as the response format. */
128
155
  readonly schema: OpenAISchema;
129
156
  /**
@@ -145,6 +172,11 @@ export declare class OpenAIConversion {
145
172
  * Set when created via {@link fromSignal}; `undefined` when created via {@link fromJTD}.
146
173
  */
147
174
  readonly descriptor?: SignalDescriptorJson;
175
+ /**
176
+ * The original signal descriptors used to build this conversion.
177
+ * Set when created via {@link fromSignals}; `undefined` otherwise.
178
+ */
179
+ readonly descriptors?: SignalDescriptorJson[];
148
180
  /**
149
181
  * Build a conversion from a JTD schema.
150
182
  *
@@ -160,7 +192,7 @@ export declare class OpenAIConversion {
160
192
  * @throws If the schema contains an unknown JTD type, an unresolved `ref`,
161
193
  * or nesting exceeding 32 levels.
162
194
  */
163
- static fromJTD(jtdSchema: JTDSchemaJson): OpenAIConversion;
195
+ static fromJTD(jtdSchema: JTDSchemaJson): OpenAIConversion<ConvertSuccessJson>;
164
196
  /**
165
197
  * Build a conversion from an Adapt signal descriptor.
166
198
  *
@@ -175,18 +207,48 @@ export declare class OpenAIConversion {
175
207
  * @throws If the descriptor has no formats, or a format has neither
176
208
  * `jtdSchema` nor `mimeType`.
177
209
  */
178
- static fromSignal(descriptor: SignalDescriptorJson): OpenAIConversion;
210
+ static fromSignal(descriptor: SignalDescriptorJson): OpenAIConversion<ConvertSuccessJson | ConvertSuccessBinary>;
211
+ /**
212
+ * Build a conversion from multiple signal descriptors.
213
+ *
214
+ * Produces an object schema with one property per signal, suitable for
215
+ * use as structured output parameters. Each signal's schema is built via
216
+ * {@link fromSignal} internally.
217
+ *
218
+ * For OpenAI strict mode, optional signals are made nullable and all
219
+ * properties are added to `required`.
220
+ *
221
+ * If there is only one signal with a single format, the schema is
222
+ * unwrapped to avoid unnecessary nesting — the signal's format schema
223
+ * is used directly as the object property value.
224
+ *
225
+ * Receiver/transceiver compatible:
226
+ * ```ts
227
+ * const conv = OpenAIConversion.fromSignals(
228
+ * receiver.signals!,
229
+ * receiver.description,
230
+ * receiver.name
231
+ * );
232
+ * ```
233
+ *
234
+ * @param signals - Array of signal descriptors.
235
+ * @param description - Optional description for the compound schema.
236
+ * @param label - Optional label (not used by OpenAI, reserved for other providers).
237
+ * @returns A new {@link OpenAIConversion} with `descriptors` set.
238
+ * @throws If any signal has no formats or an invalid format.
239
+ */
240
+ static fromSignals(signals: SignalDescriptorJson[], description?: string, label?: string): OpenAIConversion<ConvertSuccessSignals>;
179
241
  /**
180
242
  * Restore an {@link OpenAIConversion} from its serialized form.
181
243
  *
182
244
  * 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.
245
+ * already-parsed plain object. The original `jtdSchema`, `descriptor`, or
246
+ * `descriptors` is re-processed through the corresponding factory, so the
247
+ * restored instance is fully functional.
186
248
  *
187
249
  * @param data - A JSON string or parsed object previously produced by {@link toJSON}.
188
250
  * @returns A fully reconstructed {@link OpenAIConversion}.
189
- * @throws If the serialized data contains neither `jtdSchema` nor `descriptor`.
251
+ * @throws If the serialized data contains neither `jtdSchema`, `descriptor`, nor `descriptors`.
190
252
  */
191
253
  static fromJSON(data: string | Record<string, unknown>): OpenAIConversion;
192
254
  private constructor();
@@ -213,7 +275,7 @@ export declare class OpenAIConversion {
213
275
  * @param json - The raw value returned by the OpenAI API (typically parsed JSON).
214
276
  * @returns A {@link ConvertResult} indicating success or failure with errors.
215
277
  */
216
- convert: (json: unknown) => ConvertResult;
278
+ convert: (json: unknown) => T | ConvertFailure;
217
279
  /**
218
280
  * Produce a JSON-serializable representation of this conversion.
219
281
  *
@@ -224,17 +286,7 @@ export declare class OpenAIConversion {
224
286
  *
225
287
  * Called automatically by `JSON.stringify(conv)`.
226
288
  */
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
- };
289
+ toJSON(): Record<string, unknown>;
238
290
  }
239
291
  /**
240
292
  * 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;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,EAAE,QAAQ,CAAC;IACf,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,IAAI,EAAE,UAAU,CAAC;IACjB,8DAA8D;IAC9D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oB,EAAE,EAC/B,WAAW,CAAC,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,gBAAgB,CAAC,qBAAqB,CAAC;IA2C1C;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB;IAwBzE,OAAO;IAgBP;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,GAAI,MAAM,OAAO,KAAG,CAAC,GAAG,cAAc,CAY3C;IAIF;;;;;;;;;OASG;IACH,MAAM;CAuBP;AAyPD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,aAAa,GACvB,gBAAgB,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,oBAAoB,GAC/B,gBAAgB,CAElB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mochabug/adapt-sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "The API toolkit to facilitate mochabug adapt plugin development",
5
5
  "publishConfig": {
6
6
  "access": "public"