@juspay/neurolink 9.3.0 → 9.5.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 (128) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +8 -8
  3. package/dist/cli/commands/config.d.ts +3 -3
  4. package/dist/cli/index.js +1 -0
  5. package/dist/index.d.ts +35 -0
  6. package/dist/index.js +17 -0
  7. package/dist/lib/agent/directTools.d.ts +5 -5
  8. package/dist/lib/index.d.ts +35 -0
  9. package/dist/lib/index.js +17 -0
  10. package/dist/lib/neurolink.d.ts +12 -1
  11. package/dist/lib/neurolink.js +265 -4
  12. package/dist/lib/server/utils/validation.d.ts +8 -8
  13. package/dist/lib/types/generateTypes.d.ts +28 -0
  14. package/dist/lib/types/index.d.ts +6 -0
  15. package/dist/lib/types/index.js +12 -0
  16. package/dist/lib/types/modelTypes.d.ts +2 -2
  17. package/dist/lib/types/streamTypes.d.ts +35 -0
  18. package/dist/lib/types/workflowTypes.d.ts +558 -0
  19. package/dist/lib/types/workflowTypes.js +32 -0
  20. package/dist/lib/workflow/LAYER-EXAMPLES.d.ts +13 -0
  21. package/dist/lib/workflow/LAYER-EXAMPLES.js +312 -0
  22. package/dist/lib/workflow/PROMPT-EXAMPLES.d.ts +117 -0
  23. package/dist/lib/workflow/PROMPT-EXAMPLES.js +246 -0
  24. package/dist/lib/workflow/config.d.ts +1569 -0
  25. package/dist/lib/workflow/config.js +399 -0
  26. package/dist/lib/workflow/core/ensembleExecutor.d.ts +56 -0
  27. package/dist/lib/workflow/core/ensembleExecutor.js +398 -0
  28. package/dist/lib/workflow/core/judgeScorer.d.ts +26 -0
  29. package/dist/lib/workflow/core/judgeScorer.js +527 -0
  30. package/dist/lib/workflow/core/responseConditioner.d.ts +22 -0
  31. package/dist/lib/workflow/core/responseConditioner.js +226 -0
  32. package/dist/lib/workflow/core/types/conditionerTypes.d.ts +7 -0
  33. package/dist/lib/workflow/core/types/conditionerTypes.js +8 -0
  34. package/dist/lib/workflow/core/types/ensembleTypes.d.ts +7 -0
  35. package/dist/lib/workflow/core/types/ensembleTypes.js +8 -0
  36. package/dist/lib/workflow/core/types/index.d.ts +7 -0
  37. package/dist/lib/workflow/core/types/index.js +8 -0
  38. package/dist/lib/workflow/core/types/judgeTypes.d.ts +7 -0
  39. package/dist/lib/workflow/core/types/judgeTypes.js +8 -0
  40. package/dist/lib/workflow/core/types/layerTypes.d.ts +7 -0
  41. package/dist/lib/workflow/core/types/layerTypes.js +8 -0
  42. package/dist/lib/workflow/core/types/registryTypes.d.ts +7 -0
  43. package/dist/lib/workflow/core/types/registryTypes.js +8 -0
  44. package/dist/lib/workflow/core/workflowRegistry.d.ts +73 -0
  45. package/dist/lib/workflow/core/workflowRegistry.js +305 -0
  46. package/dist/lib/workflow/core/workflowRunner.d.ts +115 -0
  47. package/dist/lib/workflow/core/workflowRunner.js +554 -0
  48. package/dist/lib/workflow/index.d.ts +36 -0
  49. package/dist/lib/workflow/index.js +51 -0
  50. package/dist/lib/workflow/types.d.ts +19 -0
  51. package/dist/lib/workflow/types.js +10 -0
  52. package/dist/lib/workflow/utils/types/index.d.ts +7 -0
  53. package/dist/lib/workflow/utils/types/index.js +8 -0
  54. package/dist/lib/workflow/utils/types/metricsTypes.d.ts +7 -0
  55. package/dist/lib/workflow/utils/types/metricsTypes.js +8 -0
  56. package/dist/lib/workflow/utils/types/validationTypes.d.ts +7 -0
  57. package/dist/lib/workflow/utils/types/validationTypes.js +8 -0
  58. package/dist/lib/workflow/utils/workflowMetrics.d.ts +76 -0
  59. package/dist/lib/workflow/utils/workflowMetrics.js +312 -0
  60. package/dist/lib/workflow/utils/workflowValidation.d.ts +29 -0
  61. package/dist/lib/workflow/utils/workflowValidation.js +421 -0
  62. package/dist/lib/workflow/workflows/adaptiveWorkflow.d.ts +72 -0
  63. package/dist/lib/workflow/workflows/adaptiveWorkflow.js +367 -0
  64. package/dist/lib/workflow/workflows/consensusWorkflow.d.ts +69 -0
  65. package/dist/lib/workflow/workflows/consensusWorkflow.js +193 -0
  66. package/dist/lib/workflow/workflows/fallbackWorkflow.d.ts +49 -0
  67. package/dist/lib/workflow/workflows/fallbackWorkflow.js +226 -0
  68. package/dist/lib/workflow/workflows/multiJudgeWorkflow.d.ts +70 -0
  69. package/dist/lib/workflow/workflows/multiJudgeWorkflow.js +352 -0
  70. package/dist/neurolink.d.ts +12 -1
  71. package/dist/neurolink.js +265 -4
  72. package/dist/types/generateTypes.d.ts +28 -0
  73. package/dist/types/index.d.ts +6 -0
  74. package/dist/types/index.js +12 -0
  75. package/dist/types/streamTypes.d.ts +35 -0
  76. package/dist/types/workflowTypes.d.ts +558 -0
  77. package/dist/types/workflowTypes.js +31 -0
  78. package/dist/workflow/LAYER-EXAMPLES.d.ts +13 -0
  79. package/dist/workflow/LAYER-EXAMPLES.js +311 -0
  80. package/dist/workflow/PROMPT-EXAMPLES.d.ts +117 -0
  81. package/dist/workflow/PROMPT-EXAMPLES.js +245 -0
  82. package/dist/workflow/config.d.ts +1569 -0
  83. package/dist/workflow/config.js +398 -0
  84. package/dist/workflow/core/ensembleExecutor.d.ts +56 -0
  85. package/dist/workflow/core/ensembleExecutor.js +397 -0
  86. package/dist/workflow/core/judgeScorer.d.ts +26 -0
  87. package/dist/workflow/core/judgeScorer.js +526 -0
  88. package/dist/workflow/core/responseConditioner.d.ts +22 -0
  89. package/dist/workflow/core/responseConditioner.js +225 -0
  90. package/dist/workflow/core/types/conditionerTypes.d.ts +7 -0
  91. package/dist/workflow/core/types/conditionerTypes.js +7 -0
  92. package/dist/workflow/core/types/ensembleTypes.d.ts +7 -0
  93. package/dist/workflow/core/types/ensembleTypes.js +7 -0
  94. package/dist/workflow/core/types/index.d.ts +7 -0
  95. package/dist/workflow/core/types/index.js +7 -0
  96. package/dist/workflow/core/types/judgeTypes.d.ts +7 -0
  97. package/dist/workflow/core/types/judgeTypes.js +7 -0
  98. package/dist/workflow/core/types/layerTypes.d.ts +7 -0
  99. package/dist/workflow/core/types/layerTypes.js +7 -0
  100. package/dist/workflow/core/types/registryTypes.d.ts +7 -0
  101. package/dist/workflow/core/types/registryTypes.js +7 -0
  102. package/dist/workflow/core/workflowRegistry.d.ts +73 -0
  103. package/dist/workflow/core/workflowRegistry.js +304 -0
  104. package/dist/workflow/core/workflowRunner.d.ts +115 -0
  105. package/dist/workflow/core/workflowRunner.js +553 -0
  106. package/dist/workflow/index.d.ts +36 -0
  107. package/dist/workflow/index.js +50 -0
  108. package/dist/workflow/types.d.ts +19 -0
  109. package/dist/workflow/types.js +9 -0
  110. package/dist/workflow/utils/types/index.d.ts +7 -0
  111. package/dist/workflow/utils/types/index.js +7 -0
  112. package/dist/workflow/utils/types/metricsTypes.d.ts +7 -0
  113. package/dist/workflow/utils/types/metricsTypes.js +7 -0
  114. package/dist/workflow/utils/types/validationTypes.d.ts +7 -0
  115. package/dist/workflow/utils/types/validationTypes.js +7 -0
  116. package/dist/workflow/utils/workflowMetrics.d.ts +76 -0
  117. package/dist/workflow/utils/workflowMetrics.js +311 -0
  118. package/dist/workflow/utils/workflowValidation.d.ts +29 -0
  119. package/dist/workflow/utils/workflowValidation.js +420 -0
  120. package/dist/workflow/workflows/adaptiveWorkflow.d.ts +72 -0
  121. package/dist/workflow/workflows/adaptiveWorkflow.js +366 -0
  122. package/dist/workflow/workflows/consensusWorkflow.d.ts +69 -0
  123. package/dist/workflow/workflows/consensusWorkflow.js +192 -0
  124. package/dist/workflow/workflows/fallbackWorkflow.d.ts +49 -0
  125. package/dist/workflow/workflows/fallbackWorkflow.js +225 -0
  126. package/dist/workflow/workflows/multiJudgeWorkflow.d.ts +70 -0
  127. package/dist/workflow/workflows/multiJudgeWorkflow.js +351 -0
  128. package/package.json +3 -2
@@ -0,0 +1,399 @@
1
+ /**
2
+ * workflow/config.ts
3
+ * Configuration schemas, validation, and defaults
4
+ *
5
+ * Uses Zod for runtime validation and type safety
6
+ */
7
+ import { z } from "zod";
8
+ import { AIProviderName } from "../constants/enums.js";
9
+ // ============================================================================
10
+ // CONSTANTS
11
+ // ============================================================================
12
+ // Score scale constants for testing phase
13
+ export const MIN_SCORE = 0;
14
+ export const MAX_SCORE = 100;
15
+ // Reasoning length constraint for testing phase
16
+ export const MAX_REASONING_LENGTH = 200;
17
+ // Placeholder values for error cases
18
+ export const PLACEHOLDER_PROVIDER = "none";
19
+ export const PLACEHOLDER_MODEL = "none";
20
+ // Fixed creation timestamp for predefined workflows
21
+ export const WORKFLOW_CREATION_DATE = "2025-11-29T00:00:00.000Z";
22
+ // ============================================================================
23
+ // ZOD VALIDATION SCHEMAS
24
+ // ============================================================================
25
+ /**
26
+ * JSON-safe metadata validation
27
+ */
28
+ const JsonValueSchema = z.lazy(() => z.union([
29
+ z.string(),
30
+ z.number(),
31
+ z.boolean(),
32
+ z.null(),
33
+ z.array(JsonValueSchema),
34
+ z.record(z.string(), JsonValueSchema),
35
+ ]));
36
+ /**
37
+ * Provider name validation - accepts any AIProviderName enum value or string
38
+ */
39
+ const ProviderNameSchema = z
40
+ .union([z.nativeEnum(AIProviderName), z.string().min(1)])
41
+ .transform((val) => val);
42
+ /**
43
+ * Model configuration schema
44
+ */
45
+ export const ModelConfigSchema = z.object({
46
+ provider: ProviderNameSchema,
47
+ model: z.string().min(1, "Model name is required"),
48
+ weight: z.number().min(0).max(1).optional(),
49
+ temperature: z.number().min(0).max(2).optional(),
50
+ maxTokens: z.number().int().positive().optional(),
51
+ systemPrompt: z.string().optional(),
52
+ timeout: z.number().int().positive().optional(),
53
+ topP: z.number().min(0).max(1).optional(),
54
+ topK: z.number().int().positive().optional(),
55
+ presencePenalty: z.number().min(-2).max(2).optional(),
56
+ frequencyPenalty: z.number().min(-2).max(2).optional(),
57
+ label: z.string().optional(),
58
+ metadata: z.record(z.string(), JsonValueSchema).optional(),
59
+ });
60
+ /**
61
+ * Judge configuration schema
62
+ * NOTE: Testing phase enforces 0-100 score scale
63
+ */
64
+ export const JudgeConfigSchema = z.object({
65
+ provider: ProviderNameSchema,
66
+ model: z.string().min(1, "Judge model is required"),
67
+ criteria: z.array(z.string()).min(1, "At least one criterion required"),
68
+ outputFormat: z.enum(["scores", "ranking", "best", "detailed"]),
69
+ customPrompt: z.string().optional(),
70
+ systemPrompt: z.string().optional(),
71
+ temperature: z.number().min(0).max(2).optional(),
72
+ maxTokens: z.number().int().positive().optional(),
73
+ timeout: z.number().int().positive().optional(),
74
+ blindEvaluation: z.boolean().optional(),
75
+ includeReasoning: z.boolean(),
76
+ scoreScale: z.object({
77
+ min: z.literal(0),
78
+ max: z.literal(100),
79
+ }),
80
+ label: z.string().optional(),
81
+ metadata: z.record(z.string(), JsonValueSchema).optional(),
82
+ });
83
+ /**
84
+ * Conditioning configuration schema
85
+ */
86
+ export const ConditioningConfigSchema = z.object({
87
+ useConfidence: z.boolean(),
88
+ confidenceThresholds: z
89
+ .object({
90
+ high: z.number().min(0).max(1),
91
+ medium: z.number().min(0).max(1),
92
+ low: z.number().min(0).max(1),
93
+ })
94
+ .optional(),
95
+ toneAdjustment: z.enum(["soften", "strengthen", "neutral"]).optional(),
96
+ includeMetadata: z.boolean().optional(),
97
+ metadataFields: z.array(z.string()).optional(),
98
+ addConfidenceStatement: z.boolean().optional(),
99
+ addModelAttribution: z.boolean().optional(),
100
+ addExecutionTime: z.boolean().optional(),
101
+ metadata: z.record(z.string(), JsonValueSchema).optional(),
102
+ });
103
+ /**
104
+ * Model group schema for layer-based execution
105
+ */
106
+ export const ModelGroupSchema = z.object({
107
+ id: z.string().min(1, "Group ID is required"),
108
+ name: z.string().optional(),
109
+ description: z.string().optional(),
110
+ models: z
111
+ .array(ModelConfigSchema)
112
+ .min(1, "Group must have at least one model"),
113
+ executionStrategy: z.enum(["parallel", "sequential"]),
114
+ continueOnFailure: z.boolean().optional().default(true),
115
+ minSuccessful: z.number().int().positive().optional().default(1),
116
+ parallelism: z.number().int().positive().optional(),
117
+ timeout: z.number().int().positive().optional(),
118
+ metadata: z.record(z.string(), JsonValueSchema).optional(),
119
+ });
120
+ /**
121
+ * Execution configuration schema
122
+ */
123
+ export const ExecutionConfigSchema = z.object({
124
+ timeout: z.number().int().positive().optional(),
125
+ modelTimeout: z.number().int().positive().optional(),
126
+ judgeTimeout: z.number().int().positive().optional(),
127
+ retries: z.number().int().min(0).max(5).optional(),
128
+ retryDelay: z.number().int().positive().optional(),
129
+ retryableErrors: z.array(z.string()).optional(),
130
+ parallelism: z.number().int().positive().optional(),
131
+ earlyTermination: z.boolean().optional(),
132
+ minResponses: z.number().int().positive().optional(),
133
+ maxCost: z.number().positive().optional(),
134
+ costThreshold: z.number().positive().optional(),
135
+ enableMetrics: z.boolean().optional(),
136
+ enableTracing: z.boolean().optional(),
137
+ metadata: z.record(z.string(), JsonValueSchema).optional(),
138
+ });
139
+ /**
140
+ * Complete workflow configuration schema
141
+ */
142
+ const WorkflowConfigSchemaBase = z.object({
143
+ id: z.string().min(1, "Workflow ID is required"),
144
+ name: z.string().min(1, "Workflow name is required"),
145
+ description: z.string().optional(),
146
+ version: z.string().optional(),
147
+ type: z.enum(["ensemble", "chain", "adaptive", "custom"]),
148
+ models: z.array(ModelConfigSchema).min(1, "At least one model required"),
149
+ modelGroups: z.array(ModelGroupSchema).optional(),
150
+ defaultSystemPrompt: z.string().optional(),
151
+ defaultJudgePrompt: z.string().optional(),
152
+ judge: JudgeConfigSchema.optional(),
153
+ judges: z.array(JudgeConfigSchema).optional(),
154
+ conditioning: ConditioningConfigSchema.optional(),
155
+ execution: ExecutionConfigSchema.optional(),
156
+ tags: z.array(z.string()).optional(),
157
+ metadata: z.record(z.string(), JsonValueSchema).optional(),
158
+ createdAt: z.string().optional(),
159
+ updatedAt: z.string().optional(),
160
+ });
161
+ export const WorkflowConfigSchema = WorkflowConfigSchemaBase.refine((data) => {
162
+ // Cannot have both judge and judges
163
+ if (data.judge && data.judges) {
164
+ return false;
165
+ }
166
+ return true;
167
+ }, {
168
+ message: 'Cannot specify both "judge" and "judges" - use one or the other',
169
+ }).refine((data) => {
170
+ // Ensemble and adaptive need at least 2 models
171
+ // Check flat models array if modelGroups not provided
172
+ if (data.type === "ensemble" || data.type === "adaptive") {
173
+ if (data.modelGroups && data.modelGroups.length > 0) {
174
+ // Count total models across all groups
175
+ const totalModels = data.modelGroups.reduce((sum, group) => sum + group.models.length, 0);
176
+ return totalModels >= 2;
177
+ }
178
+ else {
179
+ // Check flat models array
180
+ return data.models.length >= 2;
181
+ }
182
+ }
183
+ return true;
184
+ }, {
185
+ message: "Ensemble and adaptive workflows require at least 2 models",
186
+ });
187
+ // ============================================================================
188
+ // DEFAULT CONFIGURATIONS
189
+ // ============================================================================
190
+ /**
191
+ * Default conditioning configuration
192
+ * NOTE: Testing phase - stub only, no actual conditioning applied
193
+ */
194
+ export const DEFAULT_CONDITIONING_CONFIG = {
195
+ useConfidence: true,
196
+ confidenceThresholds: {
197
+ high: 0.8,
198
+ medium: 0.5,
199
+ low: 0.3,
200
+ },
201
+ toneAdjustment: "neutral",
202
+ includeMetadata: false,
203
+ addConfidenceStatement: false,
204
+ addModelAttribution: false,
205
+ addExecutionTime: false,
206
+ };
207
+ /**
208
+ * Default execution configuration
209
+ */
210
+ export const DEFAULT_EXECUTION_CONFIG = {
211
+ timeout: 30000, // 30 seconds total
212
+ modelTimeout: 15000, // 15 seconds per model
213
+ judgeTimeout: 10000, // 10 seconds for judge
214
+ retries: 1,
215
+ retryDelay: 1000,
216
+ retryableErrors: ["ETIMEDOUT", "ECONNRESET", "ENOTFOUND"],
217
+ parallelism: 10,
218
+ earlyTermination: false,
219
+ minResponses: 1,
220
+ enableMetrics: true,
221
+ enableTracing: false,
222
+ };
223
+ /**
224
+ * Default score scale (0-100 for testing phase)
225
+ */
226
+ export const DEFAULT_SCORE_SCALE = {
227
+ min: 0,
228
+ max: 100,
229
+ };
230
+ // ============================================================================
231
+ // HELPER FUNCTIONS FOR MODEL GROUPS
232
+ // ============================================================================
233
+ /**
234
+ * Check if workflow uses layer-based execution (modelGroups)
235
+ * @param config - Workflow configuration
236
+ * @returns True if modelGroups is defined and has groups
237
+ */
238
+ export function usesModelGroups(config) {
239
+ return !!(config.modelGroups && config.modelGroups.length > 0);
240
+ }
241
+ /**
242
+ * Get all models from workflow (either from flat array or groups)
243
+ * @param config - Workflow configuration
244
+ * @returns Array of all model configs
245
+ */
246
+ export function getAllModels(config) {
247
+ if (usesModelGroups(config)) {
248
+ return config.modelGroups?.flatMap((group) => group.models) ?? [];
249
+ }
250
+ return config.models;
251
+ }
252
+ /**
253
+ * Get model groups (converts flat models to single group if needed)
254
+ * @param config - Workflow configuration
255
+ * @returns Array of model groups
256
+ */
257
+ export function getModelGroups(config) {
258
+ if (usesModelGroups(config)) {
259
+ return config.modelGroups ?? [];
260
+ }
261
+ // Convert flat models array to single parallel group for backward compatibility
262
+ return [
263
+ {
264
+ id: "default-group",
265
+ name: "All Models",
266
+ models: config.models,
267
+ executionStrategy: "parallel",
268
+ continueOnFailure: true,
269
+ minSuccessful: config.execution?.minResponses || 1,
270
+ },
271
+ ];
272
+ }
273
+ /**
274
+ * Default judge configuration values
275
+ */
276
+ export const DEFAULT_JUDGE_CONFIG = {
277
+ temperature: 0.1, // Low temperature for consistent judging
278
+ outputFormat: "detailed",
279
+ blindEvaluation: false,
280
+ includeReasoning: true,
281
+ scoreScale: DEFAULT_SCORE_SCALE,
282
+ };
283
+ // ============================================================================
284
+ // CONFIGURATION HELPERS
285
+ // ============================================================================
286
+ /**
287
+ * Merge configuration with defaults
288
+ * @param config - Workflow configuration to merge
289
+ * @returns Complete workflow configuration with defaults applied
290
+ */
291
+ export function mergeWithDefaults(config) {
292
+ return {
293
+ ...config,
294
+ conditioning: config.conditioning
295
+ ? { ...DEFAULT_CONDITIONING_CONFIG, ...config.conditioning }
296
+ : DEFAULT_CONDITIONING_CONFIG,
297
+ execution: config.execution
298
+ ? { ...DEFAULT_EXECUTION_CONFIG, ...config.execution }
299
+ : DEFAULT_EXECUTION_CONFIG,
300
+ createdAt: config.createdAt || new Date().toISOString(),
301
+ updatedAt: new Date().toISOString(),
302
+ };
303
+ }
304
+ /**
305
+ * Validate workflow configuration
306
+ * @param config - Partial workflow configuration to validate
307
+ * @returns Validation result with parsed data or error details
308
+ */
309
+ export function validateWorkflowConfig(config) {
310
+ const result = WorkflowConfigSchema.safeParse(config);
311
+ if (result.success) {
312
+ return { success: true, data: result.data };
313
+ }
314
+ return { success: false, error: result.error };
315
+ }
316
+ /**
317
+ * Create workflow configuration from partial
318
+ * @param partial - Partial configuration with required fields (id, name, type, models)
319
+ * @returns Complete workflow configuration with defaults applied
320
+ */
321
+ export function createWorkflowConfig(partial) {
322
+ const base = {
323
+ id: partial.id,
324
+ name: partial.name,
325
+ type: partial.type,
326
+ models: partial.models,
327
+ description: partial.description,
328
+ version: partial.version,
329
+ judge: partial.judge,
330
+ judges: partial.judges,
331
+ conditioning: partial.conditioning,
332
+ execution: partial.execution,
333
+ tags: partial.tags,
334
+ metadata: partial.metadata,
335
+ };
336
+ return mergeWithDefaults(base);
337
+ }
338
+ /**
339
+ * Validate model configuration
340
+ * @param config - Partial model configuration to validate
341
+ * @returns Validation result with parsed data or error details
342
+ */
343
+ export function validateModelConfig(config) {
344
+ const result = ModelConfigSchema.safeParse(config);
345
+ if (result.success) {
346
+ return { success: true, data: result.data };
347
+ }
348
+ return { success: false, error: result.error };
349
+ }
350
+ /**
351
+ * Validate judge configuration
352
+ * @param config - Partial judge configuration to validate
353
+ * @returns Validation result with parsed data or error details
354
+ */
355
+ export function validateJudgeConfig(config) {
356
+ const result = JudgeConfigSchema.safeParse(config);
357
+ if (result.success) {
358
+ return { success: true, data: result.data };
359
+ }
360
+ return { success: false, error: result.error };
361
+ }
362
+ /**
363
+ * Check if workflow has judge configuration
364
+ * @param config - Workflow configuration to check
365
+ * @returns True if workflow has at least one judge configured
366
+ */
367
+ export function hasJudge(config) {
368
+ return !!(config.judge || (config.judges && config.judges.length > 0));
369
+ }
370
+ /**
371
+ * Get all judges from workflow configuration
372
+ * @param config - Workflow configuration
373
+ * @returns Array of all judge configurations (empty if none)
374
+ */
375
+ export function getAllJudges(config) {
376
+ if (config.judges && config.judges.length > 0) {
377
+ return config.judges;
378
+ }
379
+ if (config.judge) {
380
+ return [config.judge];
381
+ }
382
+ return [];
383
+ }
384
+ /**
385
+ * Calculate estimated workflow cost (placeholder)
386
+ * TODO: Implement actual provider-specific pricing
387
+ * @param config - Workflow configuration
388
+ * @param estimatedTokens - Estimated number of tokens for the request
389
+ * @returns Estimated cost in USD
390
+ */
391
+ export function estimateWorkflowCost(config, estimatedTokens) {
392
+ const modelCount = config.models.length;
393
+ const judgeCount = getAllJudges(config).length;
394
+ // Placeholder cost calculation ($0.00001 per token)
395
+ const modelsCost = modelCount * estimatedTokens * 0.00001;
396
+ const judgesCost = judgeCount * estimatedTokens * 0.5 * 0.00001; // Judges use ~50% tokens
397
+ return modelsCost + judgesCost;
398
+ }
399
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,56 @@
1
+ /**
2
+ * workflow/core/ensembleExecutor.ts
3
+ * Parallel execution engine for ensemble workflows
4
+ */
5
+ import type { EnsembleResponse, ExecutionConfig, ModelGroup } from "../types.js";
6
+ import type { EnsembleExecutionResult, ExecuteEnsembleOptions } from "./types/index.js";
7
+ /**
8
+ * Execute ensemble of models in parallel
9
+ * @param options - Execution options including prompt and models
10
+ * @returns Ensemble execution result with all responses and metrics
11
+ */
12
+ export declare function executeEnsemble(options: ExecuteEnsembleOptions): Promise<EnsembleExecutionResult>;
13
+ /**
14
+ * Filter successful responses from ensemble result
15
+ * @param responses - Array of ensemble responses
16
+ * @returns Array of successful responses
17
+ */
18
+ export declare function getSuccessfulResponses(responses: EnsembleResponse[]): EnsembleResponse[];
19
+ /**
20
+ * Get response by model identifier
21
+ * @param responses - Array of ensemble responses
22
+ * @param provider - Provider name
23
+ * @param model - Model name
24
+ * @returns Response for specified model or undefined
25
+ */
26
+ export declare function getResponseByModel(responses: EnsembleResponse[], provider: string, model: string): EnsembleResponse | undefined;
27
+ /**
28
+ * Calculate total tokens used across all responses
29
+ * @param responses - Array of ensemble responses
30
+ * @returns Total token count
31
+ */
32
+ export declare function calculateTotalTokens(responses: EnsembleResponse[]): number;
33
+ /**
34
+ * Sort responses by response time
35
+ * @param responses - Array of ensemble responses
36
+ * @param ascending - Sort in ascending order (default: true)
37
+ * @returns Sorted array of responses
38
+ */
39
+ export declare function sortByResponseTime(responses: EnsembleResponse[], ascending?: boolean): EnsembleResponse[];
40
+ /**
41
+ * Get fastest successful response
42
+ * @param responses - Array of ensemble responses
43
+ * @returns Fastest successful response or undefined
44
+ */
45
+ export declare function getFastestResponse(responses: EnsembleResponse[]): EnsembleResponse | undefined;
46
+ /**
47
+ * Execute model groups sequentially (layers)
48
+ * Each group executes according to its executionStrategy
49
+ * @param groups - Array of model groups to execute
50
+ * @param prompt - User prompt
51
+ * @param executionConfig - Execution configuration
52
+ * @param systemPrompt - Direct system prompt override
53
+ * @param workflowDefaultSystemPrompt - Workflow-level default system prompt
54
+ * @returns Ensemble execution result with all responses
55
+ */
56
+ export declare function executeModelGroups(groups: ModelGroup[], prompt: string, _executionConfig?: ExecutionConfig, systemPrompt?: string, workflowDefaultSystemPrompt?: string): Promise<EnsembleExecutionResult>;