@output.ai/llm 0.3.0-dev.pr341-d46aaf1 → 0.3.0-dev.pr341-daa6878

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@output.ai/llm",
3
- "version": "0.3.0-dev.pr341-d46aaf1",
3
+ "version": "0.3.0-dev.pr341-daa6878",
4
4
  "description": "Framework abstraction to interact with LLM models",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/ai_sdk.js CHANGED
@@ -5,6 +5,14 @@ import * as AI from 'ai';
5
5
  import { validateGenerateTextArgs, validateGenerateObjectArgs, validateGenerateArrayArgs, validateGenerateEnumArgs } from './validations.js';
6
6
  import { loadPrompt } from './prompt_loader.js';
7
7
 
8
+ const _deprecationWarned = new Set();
9
+ const warnDeprecated = ( name, message ) => {
10
+ if ( !_deprecationWarned.has( name ) ) {
11
+ _deprecationWarned.add( name );
12
+ process.emitWarning( message, { type: 'DeprecationWarning', code: `OUTPUT_DEP_${name.toUpperCase()}` } );
13
+ }
14
+ };
15
+
8
16
  const traceWrapper = async ( { traceId, resultProperty, fn } ) => {
9
17
  try {
10
18
  const response = await fn();
@@ -97,8 +105,17 @@ export async function generateText( { prompt, variables, ...extraAiSdkOptions }
97
105
  /**
98
106
  * Use an LLM model to generate an object with a fixed schema.
99
107
  *
100
- * @deprecated Use generateText() with Output.object({ schema }) instead:
101
- * generateText({ prompt, output: Output.object({ schema }) })
108
+ * @deprecated Since v0.3.0. Use generateText() with Output.object({ schema }) instead.
109
+ * Will be removed in v1.0.0.
110
+ *
111
+ * @example Migration:
112
+ * ```js
113
+ * // Before (deprecated):
114
+ * const { object } = await generateObject({ prompt: 'my_prompt', schema: MySchema });
115
+ *
116
+ * // After (recommended):
117
+ * const { output } = await generateText({ prompt: 'my_prompt', output: Output.object({ schema: MySchema }) });
118
+ * ```
102
119
  *
103
120
  * @param {object} args - Generation arguments
104
121
  * @param {string} args.prompt - Prompt file name
@@ -106,9 +123,13 @@ export async function generateText( { prompt, variables, ...extraAiSdkOptions }
106
123
  * @param {z.ZodType} args.schema - Output schema
107
124
  * @param {string} [args.schemaName] - Output schema name
108
125
  * @param {string} [args.schemaDescription] - Output schema description
126
+ * @see {@link generateText} for the recommended replacement
109
127
  * @returns {Promise<GenerateObjectResult>} AI SDK response with object and metadata
110
128
  */
111
129
  export async function generateObject( args ) {
130
+ warnDeprecated( 'generateObject',
131
+ 'generateObject() is deprecated since v0.3.0 and will be removed in v1.0.0. ' +
132
+ 'Use generateText() with Output.object({ schema }) instead.' );
112
133
  validateGenerateObjectArgs( args );
113
134
  const { prompt, variables, schema, schemaName, schemaDescription, ...extraAiSdkOptions } = args;
114
135
  const loadedPrompt = loadPrompt( prompt, variables );
@@ -127,8 +148,17 @@ export async function generateObject( args ) {
127
148
  /**
128
149
  * Use an LLM model to generate an array of values with a fixed schema.
129
150
  *
130
- * @deprecated Use generateText() with Output.array({ element }) instead:
131
- * generateText({ prompt, output: Output.array({ element: schema }) })
151
+ * @deprecated Since v0.3.0. Use generateText() with Output.array({ element }) instead.
152
+ * Will be removed in v1.0.0.
153
+ *
154
+ * @example Migration:
155
+ * ```js
156
+ * // Before (deprecated):
157
+ * const { object } = await generateArray({ prompt: 'my_prompt', schema: ItemSchema });
158
+ *
159
+ * // After (recommended):
160
+ * const { output } = await generateText({ prompt: 'my_prompt', output: Output.array({ element: ItemSchema }) });
161
+ * ```
132
162
  *
133
163
  * @param {object} args - Generation arguments
134
164
  * @param {string} args.prompt - Prompt file name
@@ -136,9 +166,13 @@ export async function generateObject( args ) {
136
166
  * @param {z.ZodType} args.schema - Output schema (array item)
137
167
  * @param {string} [args.schemaName] - Output schema name
138
168
  * @param {string} [args.schemaDescription] - Output schema description
169
+ * @see {@link generateText} for the recommended replacement
139
170
  * @returns {Promise<GenerateObjectResult>} AI SDK response with array and metadata
140
171
  */
141
172
  export async function generateArray( args ) {
173
+ warnDeprecated( 'generateArray',
174
+ 'generateArray() is deprecated since v0.3.0 and will be removed in v1.0.0. ' +
175
+ 'Use generateText() with Output.array({ element: schema }) instead.' );
142
176
  validateGenerateArrayArgs( args );
143
177
  const { prompt, variables, schema, schemaName, schemaDescription, ...extraAiSdkOptions } = args;
144
178
  const loadedPrompt = loadPrompt( prompt, variables );
@@ -157,16 +191,29 @@ export async function generateArray( args ) {
157
191
  /**
158
192
  * Use an LLM model to generate a result from an enum (array of string values).
159
193
  *
160
- * @deprecated Use generateText() with Output.choice({ options }) instead:
161
- * generateText({ prompt, output: Output.choice({ options: enumValues }) })
194
+ * @deprecated Since v0.3.0. Use generateText() with Output.choice({ options }) instead.
195
+ * Will be removed in v1.0.0.
196
+ *
197
+ * @example Migration:
198
+ * ```js
199
+ * // Before (deprecated):
200
+ * const { object } = await generateEnum({ prompt: 'my_prompt', enum: ['yes', 'no', 'maybe'] });
201
+ *
202
+ * // After (recommended):
203
+ * const { output } = await generateText({ prompt: 'my_prompt', output: Output.choice({ options: ['yes', 'no', 'maybe'] }) });
204
+ * ```
162
205
  *
163
206
  * @param {object} args - Generation arguments
164
207
  * @param {string} args.prompt - Prompt file name
165
208
  * @param {Record<string, string | number>} [args.variables] - Variables to interpolate
166
209
  * @param {string[]} args.enum - Allowed values for the generation
210
+ * @see {@link generateText} for the recommended replacement
167
211
  * @returns {Promise<GenerateObjectResult>} AI SDK response with enum value and metadata
168
212
  */
169
213
  export async function generateEnum( args ) {
214
+ warnDeprecated( 'generateEnum',
215
+ 'generateEnum() is deprecated since v0.3.0 and will be removed in v1.0.0. ' +
216
+ 'Use generateText() with Output.choice({ options }) instead.' );
170
217
  validateGenerateEnumArgs( args );
171
218
  const { prompt, variables, enum: _enum, ...extraAiSdkOptions } = args;
172
219
  const loadedPrompt = loadPrompt( prompt, variables );
package/src/index.d.ts CHANGED
@@ -254,8 +254,17 @@ export function generateText<
254
254
  /**
255
255
  * Use an LLM model to generate an object with a fixed schema.
256
256
  *
257
- * @deprecated Use generateText() with Output.object({ schema }) instead:
258
- * `generateText({ prompt, output: Output.object({ schema }) })`
257
+ * @deprecated Since v0.3.0. Use generateText() with Output.object({ schema }) instead.
258
+ * Will be removed in v1.0.0.
259
+ *
260
+ * @example Migration:
261
+ * ```ts
262
+ * // Before (deprecated):
263
+ * const { object } = await generateObject({ prompt: 'my_prompt', schema: MySchema });
264
+ *
265
+ * // After (recommended):
266
+ * const { output } = await generateText({ prompt: 'my_prompt', output: Output.object({ schema: MySchema }) });
267
+ * ```
259
268
  *
260
269
  * @param args - Generation arguments.
261
270
  * @param args.prompt - Prompt file name.
@@ -263,6 +272,7 @@ export function generateText<
263
272
  * @param args.schema - Output schema.
264
273
  * @param args.schemaName - Output schema name.
265
274
  * @param args.schemaDescription - Output schema description.
275
+ * @see {@link generateText} for the recommended replacement
266
276
  * @returns AI SDK response with object and metadata.
267
277
  */
268
278
  export function generateObject<TSchema extends z.ZodType>(
@@ -278,8 +288,17 @@ export function generateObject<TSchema extends z.ZodType>(
278
288
  /**
279
289
  * Use an LLM model to generate an array of values with a fixed schema.
280
290
  *
281
- * @deprecated Use generateText() with Output.array({ element }) instead:
282
- * `generateText({ prompt, output: Output.array({ element: schema }) })`
291
+ * @deprecated Since v0.3.0. Use generateText() with Output.array({ element }) instead.
292
+ * Will be removed in v1.0.0.
293
+ *
294
+ * @example Migration:
295
+ * ```ts
296
+ * // Before (deprecated):
297
+ * const { object } = await generateArray({ prompt: 'my_prompt', schema: ItemSchema });
298
+ *
299
+ * // After (recommended):
300
+ * const { output } = await generateText({ prompt: 'my_prompt', output: Output.array({ element: ItemSchema }) });
301
+ * ```
283
302
  *
284
303
  * @param args - Generation arguments.
285
304
  * @param args.prompt - Prompt file name.
@@ -287,6 +306,7 @@ export function generateObject<TSchema extends z.ZodType>(
287
306
  * @param args.schema - Output schema (array item).
288
307
  * @param args.schemaName - Output schema name.
289
308
  * @param args.schemaDescription - Output schema description.
309
+ * @see {@link generateText} for the recommended replacement
290
310
  * @returns AI SDK response with array and metadata.
291
311
  */
292
312
  export function generateArray<TSchema extends z.ZodType>(
@@ -302,13 +322,23 @@ export function generateArray<TSchema extends z.ZodType>(
302
322
  /**
303
323
  * Use an LLM model to generate a result from an enum (array of string values).
304
324
  *
305
- * @deprecated Use generateText() with Output.choice({ options }) instead:
306
- * `generateText({ prompt, output: Output.choice({ options: enumValues }) })`
325
+ * @deprecated Since v0.3.0. Use generateText() with Output.choice({ options }) instead.
326
+ * Will be removed in v1.0.0.
327
+ *
328
+ * @example Migration:
329
+ * ```ts
330
+ * // Before (deprecated):
331
+ * const { object } = await generateEnum({ prompt: 'my_prompt', enum: ['yes', 'no', 'maybe'] });
332
+ *
333
+ * // After (recommended):
334
+ * const { output } = await generateText({ prompt: 'my_prompt', output: Output.choice({ options: ['yes', 'no', 'maybe'] }) });
335
+ * ```
307
336
  *
308
337
  * @param args - Generation arguments.
309
338
  * @param args.prompt - Prompt file name.
310
339
  * @param args.variables - Variables to interpolate.
311
340
  * @param args.enum - Allowed values for the generation.
341
+ * @see {@link generateText} for the recommended replacement
312
342
  * @returns AI SDK response with enum value and metadata.
313
343
  */
314
344
  export function generateEnum<const TEnum extends readonly [string, ...string[]]>(