@outputai/core 0.15.1-next.fd6bb62.0 → 0.16.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.
Files changed (82) hide show
  1. package/dist/credentials/index.d.ts +1 -1
  2. package/dist/credentials/types.d.ts +4 -4
  3. package/dist/evals/aggregate.d.ts +2 -0
  4. package/dist/evals/aggregate.js +11 -0
  5. package/dist/evals/eval_workflow.d.ts +20 -0
  6. package/dist/evals/eval_workflow.js +98 -0
  7. package/dist/evals/index.d.ts +7 -0
  8. package/dist/evals/index.js +4 -0
  9. package/dist/evals/interpret.d.ts +3 -0
  10. package/dist/evals/interpret.js +40 -0
  11. package/dist/evals/schemas.d.ts +96 -0
  12. package/dist/evals/schemas.js +60 -0
  13. package/dist/evals/verdict.d.ts +27 -0
  14. package/dist/evals/verdict.js +109 -0
  15. package/dist/evals/verify.d.ts +42 -0
  16. package/dist/evals/verify.js +19 -0
  17. package/package.json +57 -15
  18. package/src/consts.d.ts +2 -0
  19. package/src/helpers/path.js +34 -0
  20. package/src/http/fetch/index.d.ts +3 -5
  21. package/src/http/index.d.ts +1 -0
  22. package/src/interface/index.d.ts +1 -0
  23. package/src/llm/agent.js +147 -0
  24. package/src/llm/ai_provider.js +131 -0
  25. package/src/llm/ai_sdk_options.js +126 -0
  26. package/src/llm/consts.js +6 -0
  27. package/src/llm/deprecated_provider_aliases.js +8 -0
  28. package/src/llm/generate.js +98 -0
  29. package/src/llm/index.d.ts +697 -0
  30. package/src/llm/index.js +6 -0
  31. package/src/llm/judge.js +48 -0
  32. package/src/llm/prompt/content.js +70 -0
  33. package/src/llm/prompt/interpolations.js +58 -0
  34. package/src/llm/prompt/loader.js +67 -0
  35. package/src/llm/prompt/markup/attributes.js +52 -0
  36. package/src/llm/prompt/markup/nodes.js +71 -0
  37. package/src/llm/prompt/markup/tokenizer.js +3 -0
  38. package/src/llm/prompt/markup/tokens.js +26 -0
  39. package/src/llm/prompt/validations.js +129 -0
  40. package/src/llm/utils/cost.js +267 -0
  41. package/src/llm/utils/error_handler.js +53 -0
  42. package/src/llm/utils/file.js +42 -0
  43. package/src/llm/utils/google_vertex_auth.js +31 -0
  44. package/src/llm/utils/image.js +37 -0
  45. package/src/llm/utils/legacy_cost_attribute.js +75 -0
  46. package/src/llm/utils/metering.js +139 -0
  47. package/src/llm/utils/models.js +15 -0
  48. package/src/llm/utils/models_pricing.js +96 -0
  49. package/src/llm/utils/models_pricing_snapshot.json +4711 -0
  50. package/src/llm/utils/skills.js +74 -0
  51. package/src/llm/utils/sources.js +73 -0
  52. package/src/llm/utils/stream.js +75 -0
  53. package/src/llm/utils/tools.js +62 -0
  54. package/src/llm/utils/usage.js +155 -0
  55. package/src/llm/utils/usage_tools.js +23 -0
  56. package/src/llm/utils/web_search.js +155 -0
  57. package/src/llm/utils/wrap.js +279 -0
  58. package/src/llm/validations.js +234 -0
  59. package/src/worker/bundler_options.js +1 -9
  60. package/src/worker/interceptors/activity.js +0 -1
  61. package/src/worker/interceptors/workflow.js +0 -1
  62. package/src/worker/loader/workflows.js +16 -2
  63. package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +3 -7
  64. package/src/worker/webpack_loaders/workflow_rewriter/rewrite_activity_calls.js +27 -7
  65. package/src/worker/webpack_loaders/workflow_validator/npm_workflow_export_resolve.js +5 -6
  66. package/src/sdk/README.md +0 -47
  67. package/src/sdk/helpers/component_metadata.d.ts +0 -17
  68. package/src/sdk/helpers/component_metadata.js +0 -6
  69. package/src/sdk/helpers/index.d.ts +0 -12
  70. package/src/sdk/helpers/index.js +0 -3
  71. package/src/sdk/helpers/objects.d.ts +0 -56
  72. package/src/sdk/helpers/objects.js +0 -8
  73. package/src/sdk/helpers/path.d.ts +0 -11
  74. package/src/sdk/helpers/path.js +0 -32
  75. package/src/sdk/runtime/context.d.ts +0 -30
  76. package/src/sdk/runtime/context.js +0 -15
  77. package/src/sdk/runtime/events.d.ts +0 -13
  78. package/src/sdk/runtime/events.js +0 -5
  79. package/src/sdk/runtime/index.d.ts +0 -12
  80. package/src/sdk/runtime/index.js +0 -3
  81. package/src/sdk/runtime/tracing.d.ts +0 -48
  82. package/src/sdk/runtime/tracing.js +0 -11
@@ -0,0 +1,697 @@
1
+ import type {
2
+ GenerateTextResult as AIGenerateTextResult,
3
+ GenerateImageResult as AIGenerateImageResult,
4
+ StreamTextResult as AIStreamTextResult,
5
+ ToolSet,
6
+ ToolChoice,
7
+ StopCondition,
8
+ ModelMessage,
9
+ StreamTextOnChunkCallback,
10
+ GenerateTextOnEndCallback,
11
+ StreamTextOnErrorCallback
12
+ } from 'ai';
13
+ import type { Output as AIOutputNamespace } from 'ai';
14
+ import type { z } from 'zod';
15
+ import type { Attribute } from '#trace_attribute';
16
+ import type {
17
+ EvaluationBooleanResult,
18
+ EvaluationNumberResult,
19
+ EvaluationStringResult,
20
+ EvaluationVerdictResult
21
+ } from '#interface/evaluation_result';
22
+
23
+ type BaseAttribute = Attribute.BaseAttribute;
24
+
25
+ /** Full AI SDK module (values and types). Use `aiSdk.Output`, `aiSdk.tool`, `aiSdk.isStepCount`, `aiSdk.ToolSet`, and other AI SDK APIs. */
26
+ export * as aiSdk from 'ai';
27
+
28
+ /** Liquid interpolation variables, including nested objects and arrays. */
29
+ export type PromptVariables = Record<string, unknown>;
30
+
31
+ /**
32
+ * Represents a single message in a prompt conversation.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const msg: PromptMessage = {
37
+ * role: 'user',
38
+ * content: 'Hello, Claude!'
39
+ * };
40
+ * ```
41
+ */
42
+ export type PromptMessage = {
43
+ /** The message role. Authored prompt blocks support 'system', 'user', and 'assistant'. */
44
+ role: 'system' | 'user' | 'assistant';
45
+ /** The content of the message */
46
+ content: string;
47
+ /**
48
+ * Per-message provider options resolved at load from the role tag's `options` attribute and
49
+ * matching `config.messageOptions` sets. Authored as `<system options="set_a set_b">`.
50
+ * `options` is the only supported role-tag attribute and must have a value. Omitted when the tag
51
+ * has no effective `options`.
52
+ */
53
+ providerOptions?: Record<string, Record<string, unknown>>;
54
+ };
55
+
56
+ /**
57
+ * Configuration for LLM prompt generation.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const prompt: Prompt = {
62
+ * name: 'summarizePrompt',
63
+ * fileDir: '/app/prompts',
64
+ * variables: {},
65
+ * config: {
66
+ * provider: 'anthropic',
67
+ * model: 'claude-opus-4-1',
68
+ * temperature: 0.7,
69
+ * maxOutputTokens: 2048,
70
+ * maxSteps: 10,
71
+ * skills: []
72
+ * },
73
+ * messages: [{ role: 'user', content: 'Summarize this document.' }],
74
+ * instructions: null
75
+ * };
76
+ * ```
77
+ */
78
+ export type Prompt = {
79
+ /** Prompt name used in tracing and errors. */
80
+ name: string;
81
+
82
+ /** Base directory for resolving relative prompt resources such as skills. */
83
+ fileDir: string;
84
+
85
+ /** Interpolation values associated with the prompt. Defaults to `{}` when validated. */
86
+ variables: PromptVariables;
87
+
88
+ /** General configuration for the LLM */
89
+ config: {
90
+ /**
91
+ * LLM provider.
92
+ *
93
+ * Built-in: `'anthropic'`, `'openai'`, `'azure'`, `'amazon-bedrock'`, `'google-vertex'`,
94
+ * `'perplexity'`. Legacy aliases `'bedrock'` and `'vertex'` are deprecated but still accepted
95
+ * in prompts and normalized to their canonical names with a warning. Custom providers
96
+ * registered via {@link registerProvider} are also accepted.
97
+ */
98
+ provider: string;
99
+
100
+ /** Model name/identifier */
101
+ model: string;
102
+
103
+ /** Generation temperature. Supported range and behavior vary by provider. */
104
+ temperature?: number;
105
+
106
+ /** Maximum number of tokens in the response. */
107
+ maxOutputTokens?: number;
108
+
109
+ /**
110
+ * Maximum number of tokens in the response.
111
+ *
112
+ * @deprecated Use `maxOutputTokens`.
113
+ */
114
+ maxTokens?: number;
115
+
116
+ /** Nucleus sampling value. Usually set instead of `temperature`. */
117
+ topP?: number;
118
+
119
+ /** Limits sampling to the top K token choices. */
120
+ topK?: number;
121
+
122
+ /** Penalizes tokens that already appear in the prompt or generated output. */
123
+ presencePenalty?: number;
124
+
125
+ /** Penalizes tokens according to how often they appear. */
126
+ frequencyPenalty?: number;
127
+
128
+ /** Sequences that stop text generation when produced. */
129
+ stopSequences?: string[];
130
+
131
+ /** Tool-loop iterations when `stopWhen` is omitted. Always a positive integer after load (default 10). */
132
+ maxSteps: number;
133
+
134
+ /** Number of images to generate */
135
+ n?: number;
136
+
137
+ /** Maximum images to request per provider call */
138
+ maxImagesPerCall?: number;
139
+
140
+ /** Image size, for example `1024x1024` */
141
+ size?: `${number}x${number}`;
142
+
143
+ /** Image aspect ratio, for example `16:9` */
144
+ aspectRatio?: `${number}:${number}`;
145
+
146
+ /** Random seed for deterministic text or image generation when supported */
147
+ seed?: number;
148
+
149
+ /** Skill file or directory paths relative to the prompt file. Always a `string[]` after load (`[]` if unset). */
150
+ skills: string[];
151
+
152
+ /**
153
+ * Provider-specific tools with configuration.
154
+ *
155
+ * @example Vertex googleSearch with config
156
+ * ```yaml
157
+ * tools:
158
+ * googleSearch:
159
+ * mode: MODE_DYNAMIC
160
+ * dynamicThreshold: 0.8
161
+ * ```
162
+ *
163
+ * @example OpenAI webSearch with filters
164
+ * ```yaml
165
+ * tools:
166
+ * webSearch:
167
+ * searchContextSize: high
168
+ * filters:
169
+ * allowedDomains: [wikipedia.org]
170
+ * ```
171
+ */
172
+ tools?: Record<string, Record<string, unknown>>;
173
+
174
+ /** Provider-specific options */
175
+ providerOptions?: Record<string, unknown>;
176
+
177
+ /**
178
+ * Named, reusable per-message `providerOptions` sets, referenced from message blocks via the
179
+ * `options="<name>"` attribute. Each value is a provider-namespaced options object, e.g.
180
+ * `{ anthropic: { cacheControl: { type: 'ephemeral' } } }`.
181
+ */
182
+ messageOptions?: Record<string, Record<string, Record<string, unknown>>>;
183
+ };
184
+
185
+ /** Array of messages in the conversation */
186
+ messages: PromptMessage[];
187
+
188
+ /**
189
+ * The whole trimmed prompt body when its first meaningful token is plain text. Always set after
190
+ * `loadPrompt`: a non-empty string with `messages: []` for instruction mode, or `null` when the
191
+ * body starts with markup and is parsed into messages.
192
+ */
193
+ instructions: string | null;
194
+ };
195
+
196
+ /** Any AI SDK structured output specification. */
197
+ export type AnyAiOutput = AIOutputNamespace.Output<unknown, unknown, unknown>;
198
+
199
+ /**
200
+ * Structurally-compatible AI SDK 7 tool shape.
201
+ *
202
+ * This derives from AI SDK's `ToolSet` and widens only schema fields so tools from packages
203
+ * resolved with a different Zod peer instance remain assignable.
204
+ */
205
+ export type CompatibleTool = ToolSet[string] extends infer Tool ?
206
+ Tool extends unknown ? {
207
+ [K in keyof Tool]: K extends 'inputSchema' | 'outputSchema' | 'contextSchema' ? unknown : Tool[K];
208
+ } : never :
209
+ never;
210
+
211
+ /** AI SDK tools accepted by Output APIs without requiring one exact Zod peer instance. */
212
+ export type CompatibleToolSet = Record<string, CompatibleTool>;
213
+
214
+ /** Options for an LLM call using a prompt file. */
215
+ export type PromptFileCallOptions = {
216
+ /** Prompt file name (e.g. 'summary@v1') */
217
+ prompt: string;
218
+ /** Variables to interpolate into the prompt file */
219
+ variables?: PromptVariables;
220
+ /** Override the stack-resolved prompt directory */
221
+ promptDir?: string;
222
+ };
223
+
224
+ /** Options for an LLM call using a loaded or custom prompt. */
225
+ export type PromptObjectCallOptions = {
226
+ /** Loaded or custom prompt object. */
227
+ prompt: Prompt;
228
+ /** Prompt objects are already rendered and cannot receive interpolation variables. */
229
+ variables?: never;
230
+ /** Prompt objects are not resolved from a prompt directory. */
231
+ promptDir?: never;
232
+ };
233
+
234
+ /** Prompt file or loaded prompt options accepted by LLM calls. */
235
+ export type PromptCallOptions = PromptFileCallOptions | PromptObjectCallOptions;
236
+
237
+ /** Stop conditions accepted by text generation calls. */
238
+ export type StopWhen<Tools extends ToolSet = ToolSet> =
239
+ StopCondition<NoInfer<Tools>, Record<string, unknown>> |
240
+ Array<StopCondition<NoInfer<Tools>, Record<string, unknown>>>;
241
+
242
+ /** Shared options accepted by text generation calls. */
243
+ export type TextCallOptions<
244
+ Tools extends ToolSet = ToolSet,
245
+ OutputSpec extends AnyAiOutput = AnyAiOutput
246
+ > = PromptCallOptions & {
247
+ /** AI SDK tools, accepted structurally to tolerate different Zod peer versions. */
248
+ tools?: CompatibleToolSet;
249
+ /** Structured output specification */
250
+ output?: OutputSpec;
251
+ /** Tool choice, applied only when tools exist */
252
+ toolChoice?: ToolChoice<Tools>;
253
+ /** Caller stop condition; otherwise prompt `maxSteps` when tools exist */
254
+ stopWhen?: StopWhen<Tools>;
255
+ /** Abort signal for the request */
256
+ abortSignal?: AbortSignal;
257
+ };
258
+
259
+ /** Parameters accepted by {@link generateText}. */
260
+ export type GenerateTextParameters<
261
+ Tools extends ToolSet = ToolSet,
262
+ OutputSpec extends AnyAiOutput = AnyAiOutput
263
+ > = TextCallOptions<Tools, OutputSpec>;
264
+
265
+ /** Parameters accepted by {@link generateTextWithStreaming}. */
266
+ export type GenerateTextWithStreamingParameters<
267
+ Tools extends ToolSet = ToolSet,
268
+ OutputSpec extends AnyAiOutput = AnyAiOutput
269
+ > = TextCallOptions<Tools, OutputSpec> & {
270
+ /** Callback for every AI SDK 7 stream part, including lifecycle, boundary, terminal, text, reasoning, and tool parts. */
271
+ onChunk?: StreamTextOnChunkCallback<Tools>;
272
+ };
273
+
274
+ /** Parameters accepted by {@link streamText}. */
275
+ export type StreamTextParameters<
276
+ Tools extends ToolSet = ToolSet,
277
+ OutputSpec extends AnyAiOutput = AnyAiOutput
278
+ > = TextCallOptions<Tools, OutputSpec> & {
279
+ /** Callback for every AI SDK 7 stream part, including lifecycle, boundary, terminal, text, reasoning, and tool parts. */
280
+ onChunk?: StreamTextOnChunkCallback<Tools>;
281
+ /** Callback when a stream error occurs */
282
+ onError?: StreamTextOnErrorCallback;
283
+ /** Callback when the stream completes. Receives the wrapped AI SDK `onEnd` event with `result`, `cost`, and `sources`. */
284
+ onEnd?: WrappedStreamTextOnEndCallback<Tools>;
285
+ };
286
+
287
+ /** Runtime image bytes or an object with optional media type. */
288
+ export type GenerateImageInput =
289
+ | Buffer |
290
+ Uint8Array |
291
+ ArrayBuffer |
292
+ string |
293
+ {
294
+ data: Buffer | Uint8Array | ArrayBuffer | string;
295
+ mediaType?: string;
296
+ };
297
+
298
+ /** Image and mask inputs accepted by image generation calls. */
299
+ export type GenerateImageInputs =
300
+ | {
301
+ /** Runtime image inputs for image-to-image generation */
302
+ images: GenerateImageInput[];
303
+ /** Optional mask for image editing */
304
+ mask?: GenerateImageInput;
305
+ } |
306
+ {
307
+ images?: undefined;
308
+ mask?: never;
309
+ };
310
+
311
+ /** Parameters accepted by {@link generateImage}. */
312
+ export type GenerateImageParameters = PromptCallOptions & GenerateImageInputs & {
313
+ /** Abort signal for the request */
314
+ abortSignal?: AbortSignal;
315
+ };
316
+
317
+ /** Agent constructor options. */
318
+ export type OutputAgentConstructorParameters<
319
+ OutputSpec extends AnyAiOutput = AnyAiOutput
320
+ > = PromptCallOptions & {
321
+ /** Structured output specification */
322
+ output?: OutputSpec;
323
+ /** AI SDK tools available during the reasoning loop */
324
+ tools?: CompatibleToolSet;
325
+ /** Caller stop condition; otherwise prompt `maxSteps` when tools exist */
326
+ stopWhen?: StopWhen;
327
+ /** Pluggable message store. Opt-in; stateless by default. */
328
+ messageStore?: MessageStore;
329
+ };
330
+
331
+ /** Agent {@link Agent.generate} options. */
332
+ export type OutputAgentGenerateParameters = {
333
+ messages?: ModelMessage[];
334
+ abortSignal?: AbortSignal;
335
+ toolChoice?: ToolChoice<ToolSet>;
336
+ };
337
+
338
+ /** Agent {@link Agent.generateWithStreaming} options. Completion is the returned promise; use `onChunk` for progress. */
339
+ export type OutputAgentGenerateWithStreamingParameters = OutputAgentGenerateParameters & {
340
+ onChunk?: StreamTextOnChunkCallback<ToolSet>;
341
+ };
342
+
343
+ /** Agent {@link Agent.stream} options. `onEnd` receives {@link WrappedStreamTextOnEndEvent} (`result`, `cost`, `sources`). */
344
+ export type OutputAgentStreamParameters = OutputAgentGenerateWithStreamingParameters & {
345
+ onEnd?: WrappedStreamTextOnEndCallback<ToolSet>;
346
+ onError?: StreamTextOnErrorCallback;
347
+ };
348
+
349
+ /**
350
+ * One entry of `generateText().sources` after merge (tool URLs plus provider sources).
351
+ * Same item type as AI SDK `GenerateTextResult['sources']` (`sourceType: 'url' | 'document'`).
352
+ * `ai` does not export a named `Source` type.
353
+ */
354
+ export type ExtractedSource =
355
+ AIGenerateTextResult<ToolSet, Record<string, unknown>, AnyAiOutput>['sources'][number];
356
+
357
+ export type LLMGenerationUsageStatus = 'complete' | 'incomplete';
358
+
359
+ /** Token usage reported for one normalized LLM usage component. `tools` counts billable tool calls, not tokens. */
360
+ export interface LLMGenerationUsageItem {
361
+ group: 'input' | 'output' | 'tools';
362
+ label: string | null;
363
+ amount: number;
364
+ }
365
+
366
+ /** Normalized LLM token usage trace attribute. */
367
+ export interface LLMGenerationUsage extends BaseAttribute {
368
+ type: 'llm:generation:usage';
369
+ providerId: string;
370
+ modelId: string;
371
+ input: number | null;
372
+ output: number | null;
373
+ total: number | null;
374
+ status: LLMGenerationUsageStatus;
375
+ items: LLMGenerationUsageItem[];
376
+ }
377
+
378
+ /** One priced usage line in the legacy LLM cost event. */
379
+ export interface LLMUsageEventItem {
380
+ type: string;
381
+ ppm: number;
382
+ amount: number;
383
+ total: number;
384
+ }
385
+
386
+ /**
387
+ * Legacy `cost:llm:request` event payload.
388
+ *
389
+ * @deprecated Use the normalized `LLMGenerationUsage` and `LLMGenerationCost` payloads from the LLM generation metering event.
390
+ */
391
+ export interface LLMUsageEvent {
392
+ type: 'llm:usage';
393
+ modelId: string;
394
+ usage: LLMUsageEventItem[];
395
+ readonly total: number;
396
+ readonly tokensUsed: number;
397
+ }
398
+
399
+ export type LLMGenerationCostItemStatus = 'ok' | 'fallback' | 'uncertain' | 'missing';
400
+ export type LLMGenerationCostStatus = 'precise' | 'imprecise' | 'incomplete';
401
+ export type LLMGenerationCostPricingFreshness = 'live' | 'cached' | 'stale' | 'snapshot';
402
+
403
+ /** Context-based pricing tier applied to a normalized cost item. */
404
+ export interface LLMGenerationCostTier {
405
+ type: 'context';
406
+ size: number;
407
+ }
408
+
409
+ /** Cost calculated for one normalized LLM usage pricing segment. */
410
+ export interface LLMGenerationCostItem {
411
+ group: 'input' | 'output' | 'tools';
412
+ label: string | null;
413
+ amount: number;
414
+ ppm: number | null;
415
+ total: number | null;
416
+ status: LLMGenerationCostItemStatus;
417
+ tier?: LLMGenerationCostTier;
418
+ }
419
+
420
+ /** Normalized LLM generation cost trace attribute. */
421
+ export interface LLMGenerationCost extends BaseAttribute {
422
+ type: 'llm:generation:cost';
423
+ providerId: string;
424
+ modelId: string;
425
+ input: number | null;
426
+ output: number | null;
427
+ tools: number | null;
428
+ total: number | null;
429
+ status: LLMGenerationCostStatus;
430
+ /** How current the rate table was. Absent on costs recorded before this field existed. */
431
+ pricingFreshness?: LLMGenerationCostPricingFreshness | null;
432
+ items: LLMGenerationCostItem[];
433
+ }
434
+
435
+ /** Payload emitted by the `llm:generation:metering` event. */
436
+ export interface LLMGenerationMeteringEvent {
437
+ usage: LLMGenerationUsage;
438
+ cost: LLMGenerationCost | null;
439
+ }
440
+
441
+ /**
442
+ * `streamText` and agent `stream` `onEnd` event after the stream response wrapper: same as the AI SDK
443
+ * `onEnd` payload plus `result`, `cost`, and merged `sources`.
444
+ */
445
+ export type WrappedStreamTextOnEndEvent<Tools extends ToolSet = ToolSet> =
446
+ Parameters<GenerateTextOnEndCallback<Tools, Record<string, unknown>>>[0] & {
447
+ result: string;
448
+ cost: LLMGenerationCost | null;
449
+ sources: ExtractedSource[];
450
+ };
451
+
452
+ export type WrappedStreamTextOnEndCallback<Tools extends ToolSet = ToolSet> = (
453
+ event: WrappedStreamTextOnEndEvent<Tools>
454
+ ) => void | PromiseLike<void>;
455
+
456
+ /**
457
+ * Result from generateText including full AI SDK response metadata.
458
+ * Extends AI SDK's GenerateTextResult with a unified `result` field.
459
+ * @typeParam Tools - The tools available for the model to call (preserves typing on steps)
460
+ */
461
+ export type GenerateTextResult<
462
+ Tools extends ToolSet = ToolSet,
463
+ OutputSpec extends AnyAiOutput = AnyAiOutput
464
+ > = AIGenerateTextResult<Tools, Record<string, unknown>, OutputSpec> & {
465
+ /** Unified field name alias for 'text' */
466
+ result: string;
467
+ /** Calculated cost for the LLM call; `null` when pricing data is not available */
468
+ cost: LLMGenerationCost | null;
469
+ /** Merged tool + provider sources (url and document). Always an array. */
470
+ sources: ExtractedSource[];
471
+ };
472
+
473
+ /** Completed result from {@link generateTextWithStreaming}. */
474
+ export type GenerateTextWithStreamingResult<
475
+ Tools extends ToolSet = ToolSet,
476
+ OutputSpec extends AnyAiOutput = AnyAiOutput
477
+ > = GenerateTextResult<Tools, OutputSpec>;
478
+
479
+ /** Result from generateImage including a unified `result` field pointing at the first image. */
480
+ export type GenerateImageResult = AIGenerateImageResult & {
481
+ /** Unified field name alias for `image` */
482
+ result: AIGenerateImageResult['image'];
483
+ /** Calculated cost for the image generation call; `null` when pricing data is not available. */
484
+ cost: LLMGenerationCost | null;
485
+ };
486
+
487
+ /**
488
+ * Loads a prompt file and interpolates variables into its content.
489
+ *
490
+ * @param name - Name of the prompt file (without `.prompt` extension).
491
+ * @param variables - Variables to interpolate.
492
+ * @returns The loaded prompt object.
493
+ */
494
+ export function loadPrompt(
495
+ name: string,
496
+ variables?: PromptVariables,
497
+ promptDir?: string
498
+ ): Prompt;
499
+
500
+ /**
501
+ * Register a custom LLM provider for use in prompt files.
502
+ *
503
+ * @param name - Provider name (used in prompt config `provider` field)
504
+ * @param providerFn - Factory function that creates a model from a model name string
505
+ *
506
+ * @example
507
+ * ```ts
508
+ * import { createDeepSeek } from '@ai-sdk/deepseek';
509
+ * import { registerProvider } from '@outputai/core/llm';
510
+ *
511
+ * registerProvider('deepseek', createDeepSeek({ apiKey: '...' }));
512
+ * ```
513
+ */
514
+ export function registerProvider(
515
+ name: string,
516
+ providerFn: ( modelName: string ) => unknown
517
+ ): void;
518
+
519
+ /**
520
+ * Get the list of available provider names: built-in providers whose package is installed, plus custom registered ones.
521
+ *
522
+ * @returns Array of provider name strings
523
+ */
524
+ export function getProviderNames(): string[];
525
+
526
+ /**
527
+ * Arguments accepted by the LLM judge functions.
528
+ *
529
+ * The prompt file is resolved from the directory of the file calling the judge.
530
+ */
531
+ export type JudgeArgs = {
532
+ /** Prompt filename (without `.prompt` extension). */
533
+ prompt: string;
534
+ /** Variables to interpolate into the prompt. */
535
+ variables?: PromptVariables;
536
+ /** Output schema replacing the default one. It must keep the judged field and `reasoning`. */
537
+ schema?: z.ZodType;
538
+ };
539
+
540
+ /**
541
+ * Ask an LLM judge for a verdict. The default schema is `{ verdict: 'pass' | 'partial' | 'fail', reasoning: string }`.
542
+ *
543
+ * @param args - Judge arguments. See {@link JudgeArgs}.
544
+ * @returns Verdict result with the judge reasoning.
545
+ */
546
+ export function judgeVerdict( args: JudgeArgs ): Promise<EvaluationVerdictResult>;
547
+
548
+ /**
549
+ * Ask an LLM judge for a numeric score. The default schema is `{ score: number, reasoning: string }`.
550
+ *
551
+ * @param args - Judge arguments. See {@link JudgeArgs}.
552
+ * @returns Number result with the judge reasoning.
553
+ */
554
+ export function judgeScore( args: JudgeArgs ): Promise<EvaluationNumberResult>;
555
+
556
+ /**
557
+ * Ask an LLM judge for a true or false answer. The default schema is `{ result: boolean, reasoning: string }`.
558
+ *
559
+ * @param args - Judge arguments. See {@link JudgeArgs}.
560
+ * @returns Boolean result with the judge reasoning.
561
+ */
562
+ export function judgeBoolean( args: JudgeArgs ): Promise<EvaluationBooleanResult>;
563
+
564
+ /**
565
+ * Ask an LLM judge for a label. The default schema is `{ label: string, reasoning: string }`.
566
+ *
567
+ * @param args - Judge arguments. See {@link JudgeArgs}.
568
+ * @returns String result with the judge reasoning.
569
+ */
570
+ export function judgeLabel( args: JudgeArgs ): Promise<EvaluationStringResult>;
571
+
572
+ /**
573
+ * Use an LLM model to generate text.
574
+ *
575
+ * This function is a wrapper over the AI SDK's `generateText`.
576
+ * The prompt sets `model`, `messages`, generation settings, `maxSteps`, `skills`, and
577
+ * `providerOptions`. Pass either a prompt filename with optional `promptDir` / `variables`, or a
578
+ * loaded or custom {@link Prompt} object. Other call arguments are `tools`, `output`, `toolChoice`,
579
+ * `stopWhen`, and `abortSignal`.
580
+ *
581
+ * @param args - Generation arguments. See {@link GenerateTextParameters}.
582
+ * @returns AI SDK response with text and metadata.
583
+ */
584
+ export function generateText<
585
+ Tools extends ToolSet = ToolSet,
586
+ OutputSpec extends AnyAiOutput = AnyAiOutput
587
+ >(
588
+ args: GenerateTextParameters<Tools, OutputSpec>
589
+ ): Promise<GenerateTextResult<Tools, OutputSpec>>;
590
+
591
+ /**
592
+ * Generate text over streaming transport and return a completed response.
593
+ *
594
+ * The stream is consumed internally. `onChunk` runs as parts arrive. Provider or
595
+ * transport errors reject the returned promise with the mapped error. Use {@link streamText}
596
+ * when you need `onEnd` / `onError` stream observers.
597
+ *
598
+ * @param args - Streaming arguments. See {@link GenerateTextWithStreamingParameters}.
599
+ * @returns Completed response with parsed output and generateText-compatible metadata.
600
+ */
601
+ export function generateTextWithStreaming<
602
+ Tools extends ToolSet = ToolSet,
603
+ OutputSpec extends AnyAiOutput = AnyAiOutput
604
+ >(
605
+ args: GenerateTextWithStreamingParameters<Tools, OutputSpec>
606
+ ): Promise<GenerateTextWithStreamingResult<Tools, OutputSpec>>;
607
+
608
+ /**
609
+ * Use an LLM model to stream text generation.
610
+ *
611
+ * This function is a wrapper over the AI SDK's `streamText`.
612
+ * The prompt sets `model`, `messages`, generation settings, `maxSteps`, `skills`, and
613
+ * `providerOptions`. Pass either a prompt filename with optional `promptDir` / `variables`, or a
614
+ * loaded or custom {@link Prompt} object. Other call arguments match {@link generateText}, plus
615
+ * `onChunk`, `onEnd`, and `onError`. `onEnd` is wrapped to add `result`, `cost`, and merged
616
+ * `sources`.
617
+ *
618
+ * @param args - Streaming arguments. See {@link StreamTextParameters}.
619
+ * @returns AI SDK stream result with textStream, stream, and metadata promises.
620
+ */
621
+ export function streamText<
622
+ Tools extends ToolSet = ToolSet,
623
+ OutputSpec extends AnyAiOutput = AnyAiOutput
624
+ >(
625
+ args: StreamTextParameters<Tools, OutputSpec>
626
+ ): AIStreamTextResult<Tools, Record<string, unknown>, OutputSpec>;
627
+
628
+ /**
629
+ * Use an image model to generate images from a prompt filename or object.
630
+ *
631
+ * The prompt supplies `model`, instructions, `n`, `size`, `aspectRatio`, `seed`,
632
+ * `maxImagesPerCall`, and `providerOptions`. Pass either a prompt filename with optional
633
+ * `promptDir` / `variables`, or a loaded or custom {@link Prompt} object. Other call arguments are
634
+ * `images`, `mask`, and `abortSignal`.
635
+ *
636
+ * @param args - Image generation arguments. See {@link GenerateImageParameters}.
637
+ * @returns AI SDK image response with `result` aliasing the first image.
638
+ */
639
+ export function generateImage(
640
+ args: GenerateImageParameters
641
+ ): Promise<GenerateImageResult>;
642
+
643
+ /** Pluggable message store for multi-turn Agent interactions. */
644
+ export interface MessageStore {
645
+ getMessages(): ModelMessage[] | Promise<ModelMessage[]>;
646
+ addMessages( messages: ModelMessage[] ): void | Promise<void>;
647
+ }
648
+
649
+ /**
650
+ * Agent wraps an internal AI SDK ToolLoopAgent with Output.ai prompt loading and validation.
651
+ *
652
+ * @example Workflow step - variables per call, stateless
653
+ * ```ts
654
+ * const reviewer = new Agent({
655
+ * prompt: 'reviewer@v1',
656
+ * output: aiSdk.Output.object({ schema: z.object({ summary: z.string() }) })
657
+ * });
658
+ * const result = await reviewer.generate();
659
+ * ```
660
+ *
661
+ * @example Interactive - fixed setup, message history
662
+ * ```ts
663
+ * const chatbot = new Agent({
664
+ * prompt: 'chatbot@v1',
665
+ * messageStore: { getMessages() { return []; }, addMessages() {} }
666
+ * });
667
+ * const r1 = await chatbot.generate({ messages: [{ role: 'user', content: 'Hello' }] });
668
+ * ```
669
+ */
670
+ export declare class Agent<
671
+ OutputSpec extends AnyAiOutput = AnyAiOutput
672
+ > {
673
+ constructor( params: OutputAgentConstructorParameters<OutputSpec> );
674
+
675
+ /**
676
+ * Run the agent and return when complete.
677
+ * Same augmented shape as {@link generateText}: `result`, `cost`, merged `sources`.
678
+ */
679
+ generate( options?: OutputAgentGenerateParameters ): Promise<GenerateTextResult<ToolSet, OutputSpec>>;
680
+
681
+ /**
682
+ * Run the agent over streaming transport and return a completed response.
683
+ * `onChunk` runs as parts arrive. Provider and transport errors reject with the mapped error.
684
+ * Use {@link Agent.stream} when you need `onEnd` / `onError` stream observers.
685
+ */
686
+ generateWithStreaming(
687
+ options?: OutputAgentGenerateWithStreamingParameters
688
+ ): Promise<GenerateTextWithStreamingResult<ToolSet, OutputSpec>>;
689
+
690
+ /**
691
+ * Stream the agent's response.
692
+ * `onEnd` receives {@link WrappedStreamTextOnEndEvent} (`result`, `cost`, `sources`), matching {@link streamText}.
693
+ */
694
+ stream( options?: OutputAgentStreamParameters ): Promise<
695
+ AIStreamTextResult<ToolSet, Record<string, unknown>, OutputSpec>
696
+ >;
697
+ }
@@ -0,0 +1,6 @@
1
+ export { generateText, generateTextWithStreaming, streamText, generateImage } from './generate.js';
2
+ export { Agent } from './agent.js';
3
+ export { loadPrompt } from './prompt/loader.js';
4
+ export { registerProvider, getProviderNames } from './ai_provider.js';
5
+ export { judgeVerdict, judgeScore, judgeBoolean, judgeLabel } from './judge.js';
6
+ export * as aiSdk from 'ai';