@bratsos/workflow-engine 0.0.11 → 0.2.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 (49) hide show
  1. package/README.md +270 -513
  2. package/dist/chunk-D7RVRRM2.js +3 -0
  3. package/dist/chunk-D7RVRRM2.js.map +1 -0
  4. package/dist/chunk-HL3OJG7W.js +1033 -0
  5. package/dist/chunk-HL3OJG7W.js.map +1 -0
  6. package/dist/chunk-MUWP5SF2.js +33 -0
  7. package/dist/chunk-MUWP5SF2.js.map +1 -0
  8. package/dist/chunk-NYKMT46J.js +1143 -0
  9. package/dist/chunk-NYKMT46J.js.map +1 -0
  10. package/dist/chunk-P4KMGCT3.js +2292 -0
  11. package/dist/chunk-P4KMGCT3.js.map +1 -0
  12. package/dist/chunk-SPXBCZLB.js +17 -0
  13. package/dist/chunk-SPXBCZLB.js.map +1 -0
  14. package/dist/cli/sync-models.d.ts +1 -0
  15. package/dist/cli/sync-models.js +210 -0
  16. package/dist/cli/sync-models.js.map +1 -0
  17. package/dist/client-D4PoxADF.d.ts +798 -0
  18. package/dist/client.d.ts +5 -0
  19. package/dist/client.js +4 -0
  20. package/dist/client.js.map +1 -0
  21. package/dist/index-DAzCfO1R.d.ts +217 -0
  22. package/dist/index.d.ts +569 -0
  23. package/dist/index.js +399 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/interface-MMqhfQQK.d.ts +411 -0
  26. package/dist/kernel/index.d.ts +26 -0
  27. package/dist/kernel/index.js +3 -0
  28. package/dist/kernel/index.js.map +1 -0
  29. package/dist/kernel/testing/index.d.ts +44 -0
  30. package/dist/kernel/testing/index.js +85 -0
  31. package/dist/kernel/testing/index.js.map +1 -0
  32. package/dist/persistence/index.d.ts +2 -0
  33. package/dist/persistence/index.js +6 -0
  34. package/dist/persistence/index.js.map +1 -0
  35. package/dist/persistence/prisma/index.d.ts +37 -0
  36. package/dist/persistence/prisma/index.js +5 -0
  37. package/dist/persistence/prisma/index.js.map +1 -0
  38. package/dist/plugins-BCnDUwIc.d.ts +415 -0
  39. package/dist/ports-tU3rzPXJ.d.ts +245 -0
  40. package/dist/stage-BPw7m9Wx.d.ts +144 -0
  41. package/dist/testing/index.d.ts +264 -0
  42. package/dist/testing/index.js +920 -0
  43. package/dist/testing/index.js.map +1 -0
  44. package/package.json +11 -1
  45. package/skills/workflow-engine/SKILL.md +234 -348
  46. package/skills/workflow-engine/references/03-runtime-setup.md +111 -426
  47. package/skills/workflow-engine/references/05-persistence-setup.md +32 -0
  48. package/skills/workflow-engine/references/07-testing-patterns.md +141 -474
  49. package/skills/workflow-engine/references/08-common-patterns.md +118 -431
@@ -0,0 +1,569 @@
1
+ import { M as ModelKey } from './client-D4PoxADF.js';
2
+ export { A as AIBatch, a as AIBatchHandle, b as AIBatchProvider, c as AIBatchRequest, d as AIBatchResult, e as AICallType, f as AIEmbedResult, g as AIHelper, h as AIObjectResult, i as AIStreamResult, j as AITextResult, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, B as BatchLogFn, D as DEFAULT_MODEL_KEY, E as EmbedOptions, m as EnhancedStageContext, I as InferInput, L as LogContext, n as ModelConfig, o as ModelRegistry, p as ModelStats, q as ModelStatsTracker, r as ModelSyncConfig, N as NoInputSchema, O as ObjectOptions, R as RecordCallParams, S as SimpleStageResult, s as StreamOptions, t as SyncStageDefinition, T as TextOptions, W as WorkflowEventType, u as WorkflowSSEEvent, v as calculateCost, w as createAIHelper, x as defineAsyncBatchStage, y as defineStage, z as getDefaultModel, C as getModel, F as getModelById, G as getRegisteredModel, H as listModels, J as listRegisteredModels, K as modelSupportsBatch, P as printAvailableModels, Q as registerModels, U as requireStageOutput } from './client-D4PoxADF.js';
3
+ import { L as LogLevel } from './stage-BPw7m9Wx.js';
4
+ export { S as Stage, a as StageResult } from './stage-BPw7m9Wx.js';
5
+ export { C as CommandResult, I as IdempotencyInProgressError, y as InferWorkflowStageIds, J as JobExecuteCommand, a as JobExecuteResult, b as Kernel, c as KernelCommand, d as KernelCommandType, e as KernelConfig, W as KernelWorkflowRegistry, L as LeaseReapStaleCommand, f as LeaseReapStaleResult, O as OutboxFlushCommand, g as OutboxFlushResult, P as PluginDefinition, h as PluginReplayDLQCommand, i as PluginReplayDLQResult, j as PluginRunner, k as PluginRunnerConfig, R as RunCancelCommand, l as RunCancelResult, m as RunClaimPendingCommand, n as RunClaimPendingResult, o as RunCreateCommand, p as RunCreateResult, q as RunRerunFromCommand, r as RunRerunFromResult, s as RunTransitionCommand, t as RunTransitionResult, S as StagePollSuspendedCommand, u as StagePollSuspendedResult, z as Workflow, A as WorkflowBuilder, v as createKernel, w as createPluginRunner, x as definePlugin } from './plugins-BCnDUwIc.js';
6
+ import z$1, { z } from 'zod';
7
+ export { A as AICallLogger, i as AICallRecord, h as AIHelperStats, r as ArtifactType, g as CreateAICallInput, f as CreateLogInput, C as CreateOutboxEventInput, a as CreateRunInput, b as CreateStageInput, D as DequeueResult, E as EnqueueJobInput, I as IdempotencyRecord, J as JobQueue, j as JobRecord, k as JobStatus, L as LogLevel, O as OutboxRecord, o as SaveArtifactInput, s as StaleVersionError, S as Status, U as UpdateRunInput, e as UpdateStageInput, d as UpsertStageInput, p as WorkflowArtifactRecord, q as WorkflowLogRecord, l as WorkflowPersistence, W as WorkflowRunRecord, c as WorkflowStageRecord, n as WorkflowStageStatus, m as WorkflowStatus } from './interface-MMqhfQQK.js';
8
+ export { P as PrismaAICallLogger, a as PrismaJobQueue, c as PrismaWorkflowPersistence, e as createPrismaAICallLogger, f as createPrismaJobQueue, g as createPrismaWorkflowPersistence } from './index-DAzCfO1R.js';
9
+ import { ToolSet } from 'ai';
10
+ export { B as BlobStore, C as Clock, E as EventSink, J as JobTransport, K as KernelEvent, a as KernelEventType, P as Persistence, S as Scheduler } from './ports-tU3rzPXJ.js';
11
+
12
+ /**
13
+ * Config Presets - Common configuration patterns for workflow stages
14
+ *
15
+ * These presets provide standardized schemas for common stage configurations,
16
+ * reducing boilerplate and ensuring consistency across stages.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { defineStage } from "./stage-factory";
21
+ * import { withAIConfig, withStandardConfig } from "./config-presets";
22
+ *
23
+ * // Use AI-focused config preset
24
+ * const myStage = defineStage({
25
+ * id: "my-stage",
26
+ * name: "My Stage",
27
+ * schemas: {
28
+ * input: z.object({ data: z.string() }),
29
+ * output: z.object({ result: z.string() }),
30
+ * config: withAIConfig(z.object({
31
+ * customField: z.string(),
32
+ * })),
33
+ * },
34
+ * async execute(ctx) {
35
+ * // ctx.config.model, ctx.config.temperature available
36
+ * // plus ctx.config.customField
37
+ * },
38
+ * });
39
+ *
40
+ * // Use standard config preset (includes AI + concurrency + feature flags)
41
+ * const fullStage = defineStage({
42
+ * id: "full-stage",
43
+ * name: "Full Stage",
44
+ * schemas: {
45
+ * input: "none",
46
+ * output: z.object({ result: z.string() }),
47
+ * config: withStandardConfig(z.object({
48
+ * specificOption: z.boolean().default(true),
49
+ * })),
50
+ * },
51
+ * async execute(ctx) {
52
+ * // All standard config + custom fields available
53
+ * },
54
+ * });
55
+ * ```
56
+ */
57
+
58
+ /**
59
+ * AI/LLM configuration options
60
+ */
61
+ declare const AIConfigSchema: z.ZodObject<{
62
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
63
+ temperature: z.ZodDefault<z.ZodNumber>;
64
+ maxTokens: z.ZodOptional<z.ZodNumber>;
65
+ }, z.core.$strip>;
66
+ type AIConfig = z.infer<typeof AIConfigSchema>;
67
+ /**
68
+ * Concurrency and rate limiting configuration
69
+ */
70
+ declare const ConcurrencyConfigSchema: z.ZodObject<{
71
+ concurrency: z.ZodDefault<z.ZodNumber>;
72
+ delayMs: z.ZodDefault<z.ZodNumber>;
73
+ maxRetries: z.ZodDefault<z.ZodNumber>;
74
+ }, z.core.$strip>;
75
+ type ConcurrencyConfig = z.infer<typeof ConcurrencyConfigSchema>;
76
+ /**
77
+ * Feature flag configuration for conditional behavior
78
+ */
79
+ declare const FeatureFlagsConfigSchema: z.ZodObject<{
80
+ featureFlags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
81
+ }, z.core.$strip>;
82
+ type FeatureFlagsConfig = z.infer<typeof FeatureFlagsConfigSchema>;
83
+ /**
84
+ * Logging and debugging configuration
85
+ */
86
+ declare const DebugConfigSchema: z.ZodObject<{
87
+ verbose: z.ZodDefault<z.ZodBoolean>;
88
+ dryRun: z.ZodDefault<z.ZodBoolean>;
89
+ }, z.core.$strip>;
90
+ type DebugConfig = z.infer<typeof DebugConfigSchema>;
91
+ /**
92
+ * Add AI configuration to any schema
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const myConfig = withAIConfig(z.object({
97
+ * customField: z.string(),
98
+ * }));
99
+ * // Result has: model, temperature, maxTokens, customField
100
+ * ```
101
+ */
102
+ declare function withAIConfig<T extends z.ZodRawShape>(schema: z.ZodObject<T>): z.ZodObject<(keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
103
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
104
+ temperature: z.ZodDefault<z.ZodNumber>;
105
+ maxTokens: z.ZodOptional<z.ZodNumber>;
106
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
107
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
108
+ temperature: z.ZodDefault<z.ZodNumber>;
109
+ maxTokens: z.ZodOptional<z.ZodNumber>;
110
+ }) extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.core.$strip>;
111
+ /**
112
+ * Add concurrency configuration to any schema
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const myConfig = withConcurrency(z.object({
117
+ * items: z.array(z.string()),
118
+ * }));
119
+ * // Result has: concurrency, delayMs, maxRetries, items
120
+ * ```
121
+ */
122
+ declare function withConcurrency<T extends z.ZodRawShape>(schema: z.ZodObject<T>): z.ZodObject<(keyof T & ("concurrency" | "delayMs" | "maxRetries") extends never ? T & {
123
+ concurrency: z.ZodDefault<z.ZodNumber>;
124
+ delayMs: z.ZodDefault<z.ZodNumber>;
125
+ maxRetries: z.ZodDefault<z.ZodNumber>;
126
+ } : { [K in keyof T as K extends "concurrency" | "delayMs" | "maxRetries" ? never : K]: T[K]; } & {
127
+ concurrency: z.ZodDefault<z.ZodNumber>;
128
+ delayMs: z.ZodDefault<z.ZodNumber>;
129
+ maxRetries: z.ZodDefault<z.ZodNumber>;
130
+ }) extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.core.$strip>;
131
+ /**
132
+ * Add feature flags configuration to any schema
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const myConfig = withFeatureFlags(z.object({
137
+ * setting: z.boolean(),
138
+ * }));
139
+ * // Result has: featureFlags, setting
140
+ * ```
141
+ */
142
+ declare function withFeatureFlags<T extends z.ZodRawShape>(schema: z.ZodObject<T>): z.ZodObject<(keyof T & "featureFlags" extends never ? T & {
143
+ featureFlags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
144
+ } : { [K in keyof T as K extends "featureFlags" ? never : K]: T[K]; } & {
145
+ featureFlags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
146
+ }) extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.core.$strip>;
147
+ /**
148
+ * Standard config preset combining AI + Concurrency + Feature Flags
149
+ *
150
+ * This is the recommended preset for most stages that need:
151
+ * - AI/LLM operations
152
+ * - Parallel processing
153
+ * - Feature flagging
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const myConfig = withStandardConfig(z.object({
158
+ * customOption: z.boolean().default(true),
159
+ * }));
160
+ * // Result has all standard fields plus customOption
161
+ * ```
162
+ */
163
+ declare function withStandardConfig<T extends z.ZodRawShape>(schema: z.ZodObject<T>): z.ZodObject<(keyof (keyof (keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
164
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
165
+ temperature: z.ZodDefault<z.ZodNumber>;
166
+ maxTokens: z.ZodOptional<z.ZodNumber>;
167
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
168
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
169
+ temperature: z.ZodDefault<z.ZodNumber>;
170
+ maxTokens: z.ZodOptional<z.ZodNumber>;
171
+ }) & ("concurrency" | "delayMs" | "maxRetries") extends never ? ((keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
172
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
173
+ temperature: z.ZodDefault<z.ZodNumber>;
174
+ maxTokens: z.ZodOptional<z.ZodNumber>;
175
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
176
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
177
+ temperature: z.ZodDefault<z.ZodNumber>;
178
+ maxTokens: z.ZodOptional<z.ZodNumber>;
179
+ }) extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never) & {
180
+ concurrency: z.ZodDefault<z.ZodNumber>;
181
+ delayMs: z.ZodDefault<z.ZodNumber>;
182
+ maxRetries: z.ZodDefault<z.ZodNumber>;
183
+ } : (((keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
184
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
185
+ temperature: z.ZodDefault<z.ZodNumber>;
186
+ maxTokens: z.ZodOptional<z.ZodNumber>;
187
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
188
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
189
+ temperature: z.ZodDefault<z.ZodNumber>;
190
+ maxTokens: z.ZodOptional<z.ZodNumber>;
191
+ }) extends infer T_4 ? { [k_1 in keyof T_4]: T_4[k_1]; } : never) extends infer T_3 extends z.core.util.SomeObject ? { [K_1 in keyof T_3 as K_1 extends "concurrency" | "delayMs" | "maxRetries" ? never : K_1]: T_3[K_1]; } : never) & {
192
+ concurrency: z.ZodDefault<z.ZodNumber>;
193
+ delayMs: z.ZodDefault<z.ZodNumber>;
194
+ maxRetries: z.ZodDefault<z.ZodNumber>;
195
+ }) & "featureFlags" extends never ? ((keyof (keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
196
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
197
+ temperature: z.ZodDefault<z.ZodNumber>;
198
+ maxTokens: z.ZodOptional<z.ZodNumber>;
199
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
200
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
201
+ temperature: z.ZodDefault<z.ZodNumber>;
202
+ maxTokens: z.ZodOptional<z.ZodNumber>;
203
+ }) & ("concurrency" | "delayMs" | "maxRetries") extends never ? ((keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
204
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
205
+ temperature: z.ZodDefault<z.ZodNumber>;
206
+ maxTokens: z.ZodOptional<z.ZodNumber>;
207
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
208
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
209
+ temperature: z.ZodDefault<z.ZodNumber>;
210
+ maxTokens: z.ZodOptional<z.ZodNumber>;
211
+ }) extends infer T_6 ? { [k_1 in keyof T_6]: T_6[k_1]; } : never) & {
212
+ concurrency: z.ZodDefault<z.ZodNumber>;
213
+ delayMs: z.ZodDefault<z.ZodNumber>;
214
+ maxRetries: z.ZodDefault<z.ZodNumber>;
215
+ } : (((keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
216
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
217
+ temperature: z.ZodDefault<z.ZodNumber>;
218
+ maxTokens: z.ZodOptional<z.ZodNumber>;
219
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
220
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
221
+ temperature: z.ZodDefault<z.ZodNumber>;
222
+ maxTokens: z.ZodOptional<z.ZodNumber>;
223
+ }) extends infer T_8 ? { [k_1 in keyof T_8]: T_8[k_1]; } : never) extends infer T_7 extends z.core.util.SomeObject ? { [K_1 in keyof T_7 as K_1 extends "concurrency" | "delayMs" | "maxRetries" ? never : K_1]: T_7[K_1]; } : never) & {
224
+ concurrency: z.ZodDefault<z.ZodNumber>;
225
+ delayMs: z.ZodDefault<z.ZodNumber>;
226
+ maxRetries: z.ZodDefault<z.ZodNumber>;
227
+ }) extends infer T_5 ? { [k_2 in keyof T_5]: T_5[k_2]; } : never) & {
228
+ featureFlags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
229
+ } : (((keyof (keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
230
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
231
+ temperature: z.ZodDefault<z.ZodNumber>;
232
+ maxTokens: z.ZodOptional<z.ZodNumber>;
233
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
234
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
235
+ temperature: z.ZodDefault<z.ZodNumber>;
236
+ maxTokens: z.ZodOptional<z.ZodNumber>;
237
+ }) & ("concurrency" | "delayMs" | "maxRetries") extends never ? ((keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
238
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
239
+ temperature: z.ZodDefault<z.ZodNumber>;
240
+ maxTokens: z.ZodOptional<z.ZodNumber>;
241
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
242
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
243
+ temperature: z.ZodDefault<z.ZodNumber>;
244
+ maxTokens: z.ZodOptional<z.ZodNumber>;
245
+ }) extends infer T_11 ? { [k_1 in keyof T_11]: T_11[k_1]; } : never) & {
246
+ concurrency: z.ZodDefault<z.ZodNumber>;
247
+ delayMs: z.ZodDefault<z.ZodNumber>;
248
+ maxRetries: z.ZodDefault<z.ZodNumber>;
249
+ } : (((keyof T & ("model" | "temperature" | "maxTokens") extends never ? T & {
250
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
251
+ temperature: z.ZodDefault<z.ZodNumber>;
252
+ maxTokens: z.ZodOptional<z.ZodNumber>;
253
+ } : { [K in keyof T as K extends "model" | "temperature" | "maxTokens" ? never : K]: T[K]; } & {
254
+ model: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<"gemini-2.5-flash", string>>>;
255
+ temperature: z.ZodDefault<z.ZodNumber>;
256
+ maxTokens: z.ZodOptional<z.ZodNumber>;
257
+ }) extends infer T_13 ? { [k_1 in keyof T_13]: T_13[k_1]; } : never) extends infer T_12 extends z.core.util.SomeObject ? { [K_1 in keyof T_12 as K_1 extends "concurrency" | "delayMs" | "maxRetries" ? never : K_1]: T_12[K_1]; } : never) & {
258
+ concurrency: z.ZodDefault<z.ZodNumber>;
259
+ delayMs: z.ZodDefault<z.ZodNumber>;
260
+ maxRetries: z.ZodDefault<z.ZodNumber>;
261
+ }) extends infer T_10 ? { [k_2 in keyof T_10]: T_10[k_2]; } : never) extends infer T_9 extends z.core.util.SomeObject ? { [K_2 in keyof T_9 as K_2 extends "featureFlags" ? never : K_2]: T_9[K_2]; } : never) & {
262
+ featureFlags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
263
+ }) extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.core.$strip>;
264
+
265
+ /**
266
+ * Model Mapping for Batch Providers
267
+ *
268
+ * Dynamically maps models from the registry to provider-specific batch API identifiers.
269
+ * Uses the `supportsAsyncBatch` flag and OpenRouter ID prefix to determine compatibility.
270
+ */
271
+
272
+ declare const BatchProviderName: z$1.ZodEnum<{
273
+ google: "google";
274
+ anthropic: "anthropic";
275
+ openai: "openai";
276
+ }>;
277
+ type BatchProviderName = z$1.infer<typeof BatchProviderName>;
278
+ /**
279
+ * Get the provider-specific model ID, with fallback to default
280
+ *
281
+ * @param modelKey - The ModelKey from model-helper.ts (optional)
282
+ * @param provider - The batch provider
283
+ * @returns Provider-specific model ID
284
+ * @throws Error if model is not supported by the provider
285
+ */
286
+ declare function resolveModelForProvider(modelKey: ModelKey | undefined, provider: BatchProviderName): string;
287
+ /**
288
+ * Get the best provider for a given ModelKey
289
+ * Returns the provider that natively supports the model
290
+ */
291
+ declare function getBestProviderForModel(modelKey: ModelKey): BatchProviderName | undefined;
292
+
293
+ /**
294
+ * Low-Level Batch Provider Types
295
+ *
296
+ * These types are used internally by batch providers (Google, Anthropic, OpenAI).
297
+ * They have more fields than the high-level user-facing types in ai/ai-helper.ts.
298
+ *
299
+ * For the user-facing batch API, see:
300
+ * - AIBatchRequest - simple request with id, prompt, schema
301
+ * - AIBatchResult<T> - result with id, result, tokens
302
+ * - AIBatchHandle - handle with id, status, provider
303
+ *
304
+ * These provider-level types include additional fields like:
305
+ * - BatchHandle: requestCount, createdAt, metadata
306
+ * - BaseBatchRequest: model, system, maxTokens, temperature, tools
307
+ * - RawBatchResult: raw text before parsing, index
308
+ */
309
+
310
+ /** Tool choice options compatible with AI SDK */
311
+ type BatchToolChoice = "auto" | "required" | "none" | {
312
+ type: "tool";
313
+ toolName: string;
314
+ };
315
+ /**
316
+ * Handle returned when a batch is submitted
317
+ */
318
+ interface BatchHandle {
319
+ /** Unique identifier for the batch (provider-specific format) */
320
+ id: string;
321
+ /** Provider name (google, anthropic, openai) */
322
+ provider: string;
323
+ /** Number of requests in the batch */
324
+ requestCount: number;
325
+ /** When the batch was created */
326
+ createdAt: Date;
327
+ /** Provider-specific metadata */
328
+ metadata?: Record<string, unknown>;
329
+ }
330
+ /**
331
+ * Status of a batch job
332
+ */
333
+ interface BatchStatus {
334
+ /** Current state of the batch */
335
+ state: BatchState;
336
+ /** Number of requests processed so far */
337
+ processedCount: number;
338
+ /** Total number of requests in the batch */
339
+ totalCount: number;
340
+ /** Number of successful requests (if available) */
341
+ succeededCount?: number;
342
+ /** Number of failed requests (if available) */
343
+ failedCount?: number;
344
+ /** Error message if batch failed */
345
+ error?: string;
346
+ /** Estimated completion time (if available) */
347
+ estimatedCompletion?: Date;
348
+ /** Total input tokens used (available when batch is complete) */
349
+ totalInputTokens?: number;
350
+ /** Total output tokens used (available when batch is complete) */
351
+ totalOutputTokens?: number;
352
+ }
353
+ type BatchState = "pending" | "processing" | "completed" | "failed" | "cancelled";
354
+ /**
355
+ * Result of a single request in a batch
356
+ */
357
+ interface BatchResult<T> {
358
+ /** Index in the original request array */
359
+ index: number;
360
+ /** Custom ID if provided */
361
+ customId?: string;
362
+ /** Parsed/validated data */
363
+ data: T;
364
+ /** Input tokens used */
365
+ inputTokens: number;
366
+ /** Output tokens used */
367
+ outputTokens: number;
368
+ /** Status of this individual result */
369
+ status: "succeeded" | "failed";
370
+ /** Error message if this specific request failed */
371
+ error?: string;
372
+ }
373
+ /**
374
+ * Raw result from a provider (before schema validation)
375
+ */
376
+ interface RawBatchResult {
377
+ index: number;
378
+ customId?: string;
379
+ text: string;
380
+ inputTokens: number;
381
+ outputTokens: number;
382
+ error?: string;
383
+ }
384
+ /**
385
+ * Base request configuration shared across providers
386
+ */
387
+ interface BaseBatchRequest {
388
+ /** The prompt/content to send */
389
+ prompt: string;
390
+ /** Optional custom ID for tracking */
391
+ customId?: string;
392
+ /** Model to use - accepts ModelKey from model-helper.ts */
393
+ model?: ModelKey;
394
+ /** System prompt (if supported) */
395
+ system?: string;
396
+ /** Maximum tokens to generate */
397
+ maxTokens?: number;
398
+ /** Temperature for generation */
399
+ temperature?: number;
400
+ /** Optional Zod schema for structured output */
401
+ schema?: z.ZodTypeAny;
402
+ /** Tool definitions (same as AI SDK generateText/streamText) */
403
+ tools?: ToolSet;
404
+ /** Tool choice mode */
405
+ toolChoice?: BatchToolChoice;
406
+ }
407
+ /**
408
+ * Request with schema for structured output
409
+ */
410
+ interface BatchRequestWithSchema<TSchema extends z.ZodTypeAny> extends BaseBatchRequest {
411
+ schema: TSchema;
412
+ }
413
+ /**
414
+ * Request without schema (plain text output)
415
+ */
416
+ interface BatchRequestText extends BaseBatchRequest {
417
+ schema?: never;
418
+ }
419
+ /**
420
+ * Union type for batch requests
421
+ */
422
+ type BatchRequest<TSchema extends z.ZodTypeAny = z.ZodTypeAny> = BatchRequestWithSchema<TSchema> | BatchRequestText;
423
+ /**
424
+ * Interface that all batch providers must implement
425
+ */
426
+ interface BatchProvider<TRequest extends BaseBatchRequest = BaseBatchRequest, TRawResult extends RawBatchResult = RawBatchResult> {
427
+ /** Provider name (google, anthropic, openai) */
428
+ readonly name: string;
429
+ /** Whether this provider supports batching */
430
+ readonly supportsBatching: boolean;
431
+ /**
432
+ * Submit requests to batch processing
433
+ * @param requests Array of requests to process
434
+ * @param options Provider-specific options
435
+ * @returns Handle to track the batch
436
+ */
437
+ submit(requests: TRequest[], options?: BatchSubmitOptions): Promise<BatchHandle>;
438
+ /**
439
+ * Check the status of a batch
440
+ * @param handle Batch handle from submit()
441
+ * @returns Current status
442
+ */
443
+ checkStatus(handle: BatchHandle): Promise<BatchStatus>;
444
+ /**
445
+ * Retrieve results from a completed batch
446
+ * @param handle Batch handle from submit()
447
+ * @returns Array of raw results
448
+ */
449
+ getResults(handle: BatchHandle): Promise<TRawResult[]>;
450
+ /**
451
+ * Cancel a running batch (optional - not all providers support this)
452
+ * @param handle Batch handle from submit()
453
+ */
454
+ cancel?(handle: BatchHandle): Promise<void>;
455
+ }
456
+ interface BatchSubmitOptions {
457
+ /** Display name for the batch (if supported) */
458
+ displayName?: string;
459
+ /** Completion window (e.g., "24h" for OpenAI) */
460
+ completionWindow?: string;
461
+ /** Custom metadata to attach */
462
+ metadata?: Record<string, string>;
463
+ }
464
+ /**
465
+ * Serialized batch for persistence during workflow suspension
466
+ */
467
+ interface SerializedBatch {
468
+ handle: BatchHandle;
469
+ providerName: string;
470
+ /** Serialized schema definitions (if any) */
471
+ schemaDefinitions?: unknown[];
472
+ }
473
+ /**
474
+ * Logger interface for batch operations
475
+ */
476
+ interface BatchLogger {
477
+ log: (level: LogLevel, message: string, meta?: Record<string, unknown>) => void;
478
+ }
479
+ /**
480
+ * Aggregated metrics for a batch
481
+ */
482
+ interface BatchMetrics {
483
+ provider: string;
484
+ model: string;
485
+ requestCount: number;
486
+ totalInputTokens: number;
487
+ totalOutputTokens: number;
488
+ estimatedCost: number;
489
+ actualDuration: number;
490
+ successRate: number;
491
+ }
492
+ interface GoogleBatchRequest extends BaseBatchRequest {
493
+ }
494
+ interface AnthropicBatchRequest extends BaseBatchRequest {
495
+ }
496
+ interface OpenAIBatchRequest extends BaseBatchRequest {
497
+ }
498
+
499
+ /**
500
+ * Google Batch Provider
501
+ *
502
+ * Implements batch processing using Google's GenAI Batch API.
503
+ * Uses inline requests for simpler API.
504
+ */
505
+
506
+ interface GoogleBatchProviderConfig {
507
+ apiKey?: string;
508
+ }
509
+ declare class GoogleBatchProvider implements BatchProvider<GoogleBatchRequest, RawBatchResult> {
510
+ readonly name = "google";
511
+ readonly supportsBatching = true;
512
+ private ai;
513
+ private logger?;
514
+ constructor(config?: GoogleBatchProviderConfig, logger?: BatchLogger);
515
+ submit(requests: GoogleBatchRequest[], options?: BatchSubmitOptions): Promise<BatchHandle>;
516
+ checkStatus(handle: BatchHandle): Promise<BatchStatus>;
517
+ getResults(handle: BatchHandle, customIds?: string[]): Promise<RawBatchResult[]>;
518
+ cancel(handle: BatchHandle): Promise<void>;
519
+ private mapState;
520
+ }
521
+
522
+ /**
523
+ * Anthropic Batch Provider
524
+ *
525
+ * Implements batch processing using Anthropic's Message Batches API.
526
+ * Supports up to 10,000 requests per batch with 24h processing window.
527
+ */
528
+
529
+ interface AnthropicBatchProviderConfig {
530
+ apiKey?: string;
531
+ }
532
+ declare class AnthropicBatchProvider implements BatchProvider<AnthropicBatchRequest, RawBatchResult> {
533
+ readonly name = "anthropic";
534
+ readonly supportsBatching = true;
535
+ private client;
536
+ private logger?;
537
+ constructor(config?: AnthropicBatchProviderConfig, logger?: BatchLogger);
538
+ submit(requests: AnthropicBatchRequest[], options?: BatchSubmitOptions): Promise<BatchHandle>;
539
+ checkStatus(handle: BatchHandle): Promise<BatchStatus>;
540
+ getResults(handle: BatchHandle): Promise<RawBatchResult[]>;
541
+ cancel(handle: BatchHandle): Promise<void>;
542
+ private mapStatus;
543
+ }
544
+
545
+ /**
546
+ * OpenAI Batch Provider
547
+ *
548
+ * Implements batch processing using OpenAI's Batch API.
549
+ * Note: OpenAI requires JSONL file uploads for batches.
550
+ * Supports up to 50,000 requests per batch with 24h processing window.
551
+ */
552
+
553
+ interface OpenAIBatchProviderConfig {
554
+ apiKey?: string;
555
+ }
556
+ declare class OpenAIBatchProvider implements BatchProvider<OpenAIBatchRequest, RawBatchResult> {
557
+ readonly name = "openai";
558
+ readonly supportsBatching = true;
559
+ private client;
560
+ private logger?;
561
+ constructor(config?: OpenAIBatchProviderConfig, logger?: BatchLogger);
562
+ submit(requests: OpenAIBatchRequest[], options?: BatchSubmitOptions): Promise<BatchHandle>;
563
+ checkStatus(handle: BatchHandle): Promise<BatchStatus>;
564
+ getResults(handle: BatchHandle): Promise<RawBatchResult[]>;
565
+ cancel(handle: BatchHandle): Promise<void>;
566
+ private mapStatus;
567
+ }
568
+
569
+ export { type AIConfig, AIConfigSchema, AnthropicBatchProvider, type AnthropicBatchProviderConfig, type AnthropicBatchRequest, type BaseBatchRequest, type BatchHandle, type BatchLogger, type BatchMetrics, type BatchProvider, type BatchRequest, type BatchRequestText, type BatchRequestWithSchema, type BatchResult, type BatchState, type BatchStatus, type BatchSubmitOptions, type ConcurrencyConfig, ConcurrencyConfigSchema, type DebugConfig, DebugConfigSchema, type FeatureFlagsConfig, FeatureFlagsConfigSchema, GoogleBatchProvider, type GoogleBatchProviderConfig, type GoogleBatchRequest, ModelKey, OpenAIBatchProvider, type OpenAIBatchProviderConfig, type OpenAIBatchRequest, type RawBatchResult, type SerializedBatch, getBestProviderForModel, resolveModelForProvider, withAIConfig, withConcurrency, withFeatureFlags, withStandardConfig };