@juspay/neurolink 9.3.0 → 9.4.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.
- package/CHANGELOG.md +6 -0
- package/README.md +8 -8
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/index.js +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +17 -0
- package/dist/lib/agent/directTools.d.ts +5 -5
- package/dist/lib/index.d.ts +35 -0
- package/dist/lib/index.js +17 -0
- package/dist/lib/neurolink.d.ts +12 -1
- package/dist/lib/neurolink.js +265 -4
- package/dist/lib/server/utils/validation.d.ts +8 -8
- package/dist/lib/types/generateTypes.d.ts +28 -0
- package/dist/lib/types/index.d.ts +6 -0
- package/dist/lib/types/index.js +12 -0
- package/dist/lib/types/modelTypes.d.ts +2 -2
- package/dist/lib/types/streamTypes.d.ts +35 -0
- package/dist/lib/types/workflowTypes.d.ts +558 -0
- package/dist/lib/types/workflowTypes.js +32 -0
- package/dist/lib/workflow/LAYER-EXAMPLES.d.ts +13 -0
- package/dist/lib/workflow/LAYER-EXAMPLES.js +312 -0
- package/dist/lib/workflow/PROMPT-EXAMPLES.d.ts +117 -0
- package/dist/lib/workflow/PROMPT-EXAMPLES.js +246 -0
- package/dist/lib/workflow/config.d.ts +1569 -0
- package/dist/lib/workflow/config.js +399 -0
- package/dist/lib/workflow/core/ensembleExecutor.d.ts +56 -0
- package/dist/lib/workflow/core/ensembleExecutor.js +398 -0
- package/dist/lib/workflow/core/judgeScorer.d.ts +26 -0
- package/dist/lib/workflow/core/judgeScorer.js +527 -0
- package/dist/lib/workflow/core/responseConditioner.d.ts +22 -0
- package/dist/lib/workflow/core/responseConditioner.js +226 -0
- package/dist/lib/workflow/core/types/conditionerTypes.d.ts +7 -0
- package/dist/lib/workflow/core/types/conditionerTypes.js +8 -0
- package/dist/lib/workflow/core/types/ensembleTypes.d.ts +7 -0
- package/dist/lib/workflow/core/types/ensembleTypes.js +8 -0
- package/dist/lib/workflow/core/types/index.d.ts +7 -0
- package/dist/lib/workflow/core/types/index.js +8 -0
- package/dist/lib/workflow/core/types/judgeTypes.d.ts +7 -0
- package/dist/lib/workflow/core/types/judgeTypes.js +8 -0
- package/dist/lib/workflow/core/types/layerTypes.d.ts +7 -0
- package/dist/lib/workflow/core/types/layerTypes.js +8 -0
- package/dist/lib/workflow/core/types/registryTypes.d.ts +7 -0
- package/dist/lib/workflow/core/types/registryTypes.js +8 -0
- package/dist/lib/workflow/core/workflowRegistry.d.ts +73 -0
- package/dist/lib/workflow/core/workflowRegistry.js +305 -0
- package/dist/lib/workflow/core/workflowRunner.d.ts +115 -0
- package/dist/lib/workflow/core/workflowRunner.js +554 -0
- package/dist/lib/workflow/index.d.ts +36 -0
- package/dist/lib/workflow/index.js +51 -0
- package/dist/lib/workflow/types.d.ts +19 -0
- package/dist/lib/workflow/types.js +10 -0
- package/dist/lib/workflow/utils/types/index.d.ts +7 -0
- package/dist/lib/workflow/utils/types/index.js +8 -0
- package/dist/lib/workflow/utils/types/metricsTypes.d.ts +7 -0
- package/dist/lib/workflow/utils/types/metricsTypes.js +8 -0
- package/dist/lib/workflow/utils/types/validationTypes.d.ts +7 -0
- package/dist/lib/workflow/utils/types/validationTypes.js +8 -0
- package/dist/lib/workflow/utils/workflowMetrics.d.ts +76 -0
- package/dist/lib/workflow/utils/workflowMetrics.js +312 -0
- package/dist/lib/workflow/utils/workflowValidation.d.ts +29 -0
- package/dist/lib/workflow/utils/workflowValidation.js +421 -0
- package/dist/lib/workflow/workflows/adaptiveWorkflow.d.ts +72 -0
- package/dist/lib/workflow/workflows/adaptiveWorkflow.js +367 -0
- package/dist/lib/workflow/workflows/consensusWorkflow.d.ts +69 -0
- package/dist/lib/workflow/workflows/consensusWorkflow.js +193 -0
- package/dist/lib/workflow/workflows/fallbackWorkflow.d.ts +49 -0
- package/dist/lib/workflow/workflows/fallbackWorkflow.js +226 -0
- package/dist/lib/workflow/workflows/multiJudgeWorkflow.d.ts +70 -0
- package/dist/lib/workflow/workflows/multiJudgeWorkflow.js +352 -0
- package/dist/neurolink.d.ts +12 -1
- package/dist/neurolink.js +265 -4
- package/dist/types/generateTypes.d.ts +28 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +12 -0
- package/dist/types/streamTypes.d.ts +35 -0
- package/dist/types/workflowTypes.d.ts +558 -0
- package/dist/types/workflowTypes.js +31 -0
- package/dist/workflow/LAYER-EXAMPLES.d.ts +13 -0
- package/dist/workflow/LAYER-EXAMPLES.js +311 -0
- package/dist/workflow/PROMPT-EXAMPLES.d.ts +117 -0
- package/dist/workflow/PROMPT-EXAMPLES.js +245 -0
- package/dist/workflow/config.d.ts +1569 -0
- package/dist/workflow/config.js +398 -0
- package/dist/workflow/core/ensembleExecutor.d.ts +56 -0
- package/dist/workflow/core/ensembleExecutor.js +397 -0
- package/dist/workflow/core/judgeScorer.d.ts +26 -0
- package/dist/workflow/core/judgeScorer.js +526 -0
- package/dist/workflow/core/responseConditioner.d.ts +22 -0
- package/dist/workflow/core/responseConditioner.js +225 -0
- package/dist/workflow/core/types/conditionerTypes.d.ts +7 -0
- package/dist/workflow/core/types/conditionerTypes.js +7 -0
- package/dist/workflow/core/types/ensembleTypes.d.ts +7 -0
- package/dist/workflow/core/types/ensembleTypes.js +7 -0
- package/dist/workflow/core/types/index.d.ts +7 -0
- package/dist/workflow/core/types/index.js +7 -0
- package/dist/workflow/core/types/judgeTypes.d.ts +7 -0
- package/dist/workflow/core/types/judgeTypes.js +7 -0
- package/dist/workflow/core/types/layerTypes.d.ts +7 -0
- package/dist/workflow/core/types/layerTypes.js +7 -0
- package/dist/workflow/core/types/registryTypes.d.ts +7 -0
- package/dist/workflow/core/types/registryTypes.js +7 -0
- package/dist/workflow/core/workflowRegistry.d.ts +73 -0
- package/dist/workflow/core/workflowRegistry.js +304 -0
- package/dist/workflow/core/workflowRunner.d.ts +115 -0
- package/dist/workflow/core/workflowRunner.js +553 -0
- package/dist/workflow/index.d.ts +36 -0
- package/dist/workflow/index.js +50 -0
- package/dist/workflow/types.d.ts +19 -0
- package/dist/workflow/types.js +9 -0
- package/dist/workflow/utils/types/index.d.ts +7 -0
- package/dist/workflow/utils/types/index.js +7 -0
- package/dist/workflow/utils/types/metricsTypes.d.ts +7 -0
- package/dist/workflow/utils/types/metricsTypes.js +7 -0
- package/dist/workflow/utils/types/validationTypes.d.ts +7 -0
- package/dist/workflow/utils/types/validationTypes.js +7 -0
- package/dist/workflow/utils/workflowMetrics.d.ts +76 -0
- package/dist/workflow/utils/workflowMetrics.js +311 -0
- package/dist/workflow/utils/workflowValidation.d.ts +29 -0
- package/dist/workflow/utils/workflowValidation.js +420 -0
- package/dist/workflow/workflows/adaptiveWorkflow.d.ts +72 -0
- package/dist/workflow/workflows/adaptiveWorkflow.js +366 -0
- package/dist/workflow/workflows/consensusWorkflow.d.ts +69 -0
- package/dist/workflow/workflows/consensusWorkflow.js +192 -0
- package/dist/workflow/workflows/fallbackWorkflow.d.ts +49 -0
- package/dist/workflow/workflows/fallbackWorkflow.js +225 -0
- package/dist/workflow/workflows/multiJudgeWorkflow.d.ts +70 -0
- package/dist/workflow/workflows/multiJudgeWorkflow.js +351 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [9.4.0](https://github.com/juspay/neurolink/compare/v9.3.0...v9.4.0) (2026-02-09)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **(workflow):** implement comprehensive workflow engine for multi-model orchestration ([9257385](https://github.com/juspay/neurolink/commit/9257385e4b961dd14e21f85250b4947be9c0e7b6))
|
|
6
|
+
|
|
1
7
|
## [9.3.0](https://github.com/juspay/neurolink/compare/v9.2.0...v9.3.0) (2026-02-08)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/README.md
CHANGED
|
@@ -178,14 +178,14 @@ NeuroLink is a comprehensive AI development platform. Every feature below is pro
|
|
|
178
178
|
|
|
179
179
|
**6 Core Tools** (work across all providers, zero configuration):
|
|
180
180
|
|
|
181
|
-
| Tool | Purpose | Auto-Available | Documentation
|
|
182
|
-
| -------------------- | ------------------------ | ----------------------- |
|
|
183
|
-
| `getCurrentTime` | Real-time clock access | ✅ | [Tool Reference](docs/sdk/custom-tools.md
|
|
184
|
-
| `readFile` | File system reading | ✅ | [Tool Reference](docs/sdk/custom-tools.md
|
|
185
|
-
| `writeFile` | File system writing | ✅ | [Tool Reference](docs/sdk/custom-tools.md
|
|
186
|
-
| `listDirectory` | Directory listing | ✅ | [Tool Reference](docs/sdk/custom-tools.md
|
|
187
|
-
| `calculateMath` | Mathematical operations | ✅ | [Tool Reference](docs/sdk/custom-tools.md
|
|
188
|
-
| `websearchGrounding` | Google Vertex web search | ⚠️ Requires credentials | [Tool Reference](docs/sdk/custom-tools.md
|
|
181
|
+
| Tool | Purpose | Auto-Available | Documentation |
|
|
182
|
+
| -------------------- | ------------------------ | ----------------------- | ------------------------------------------ |
|
|
183
|
+
| `getCurrentTime` | Real-time clock access | ✅ | [Tool Reference](docs/sdk/custom-tools.md) |
|
|
184
|
+
| `readFile` | File system reading | ✅ | [Tool Reference](docs/sdk/custom-tools.md) |
|
|
185
|
+
| `writeFile` | File system writing | ✅ | [Tool Reference](docs/sdk/custom-tools.md) |
|
|
186
|
+
| `listDirectory` | Directory listing | ✅ | [Tool Reference](docs/sdk/custom-tools.md) |
|
|
187
|
+
| `calculateMath` | Mathematical operations | ✅ | [Tool Reference](docs/sdk/custom-tools.md) |
|
|
188
|
+
| `websearchGrounding` | Google Vertex web search | ⚠️ Requires credentials | [Tool Reference](docs/sdk/custom-tools.md) |
|
|
189
189
|
|
|
190
190
|
**58+ External MCP Servers** supported (GitHub, PostgreSQL, Google Drive, Slack, and more):
|
|
191
191
|
|
|
@@ -61,8 +61,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
61
61
|
model?: string | undefined;
|
|
62
62
|
projectId?: string | undefined;
|
|
63
63
|
credentials?: string | undefined;
|
|
64
|
-
location?: string | undefined;
|
|
65
64
|
privateKey?: string | undefined;
|
|
65
|
+
location?: string | undefined;
|
|
66
66
|
serviceAccountKey?: string | undefined;
|
|
67
67
|
clientEmail?: string | undefined;
|
|
68
68
|
}>>;
|
|
@@ -201,8 +201,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
201
201
|
model?: string | undefined;
|
|
202
202
|
projectId?: string | undefined;
|
|
203
203
|
credentials?: string | undefined;
|
|
204
|
-
location?: string | undefined;
|
|
205
204
|
privateKey?: string | undefined;
|
|
205
|
+
location?: string | undefined;
|
|
206
206
|
serviceAccountKey?: string | undefined;
|
|
207
207
|
clientEmail?: string | undefined;
|
|
208
208
|
} | undefined;
|
|
@@ -570,8 +570,8 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
570
570
|
model?: string | undefined;
|
|
571
571
|
projectId?: string | undefined;
|
|
572
572
|
credentials?: string | undefined;
|
|
573
|
-
location?: string | undefined;
|
|
574
573
|
privateKey?: string | undefined;
|
|
574
|
+
location?: string | undefined;
|
|
575
575
|
serviceAccountKey?: string | undefined;
|
|
576
576
|
clientEmail?: string | undefined;
|
|
577
577
|
} | undefined;
|
package/dist/cli/index.js
CHANGED
|
@@ -26,6 +26,7 @@ catch {
|
|
|
26
26
|
// Environment variables should be set externally in production
|
|
27
27
|
}
|
|
28
28
|
// Enhanced CLI with Professional UX
|
|
29
|
+
// Note: Workflow functionality is accessed via generate/stream commands with --workflow-config option
|
|
29
30
|
const cli = initializeCliParser();
|
|
30
31
|
// Execute CLI
|
|
31
32
|
(async () => {
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,41 @@ export type { AnalyticsData, EvaluationData, TextGenerationOptions, TextGenerati
|
|
|
244
244
|
* @since 1.0.0
|
|
245
245
|
*/
|
|
246
246
|
export declare function generateText(options: import("./types/index.js").TextGenerationOptions): Promise<import("./types/index.js").TextGenerationResult>;
|
|
247
|
+
/**
|
|
248
|
+
* Workflow Engine for multi-model ensembles with judge-based evaluation
|
|
249
|
+
*
|
|
250
|
+
* Enables sophisticated AI orchestration patterns:
|
|
251
|
+
* - Ensemble execution (parallel multi-model)
|
|
252
|
+
* - Chain execution (sequential fallback)
|
|
253
|
+
* - Adaptive execution (tier-based quality/cost optimization)
|
|
254
|
+
* - Multi-judge voting for consensus
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* import { neurolink, CONSENSUS_3_WORKFLOW } from '@juspay/neurolink';
|
|
259
|
+
*
|
|
260
|
+
* // Use workflow via generate() with workflowConfig option
|
|
261
|
+
* const result = await neurolink.generate({
|
|
262
|
+
* input: { text: 'Explain quantum computing' },
|
|
263
|
+
* workflowConfig: CONSENSUS_3_WORKFLOW,
|
|
264
|
+
* });
|
|
265
|
+
*
|
|
266
|
+
* console.log('Best response:', result.content);
|
|
267
|
+
* console.log('Selected model:', result.workflow?.selectedModel);
|
|
268
|
+
* console.log('Total time:', result.workflow?.metrics?.totalTime);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export type { WorkflowConfig, WorkflowResult, ModelConfig, JudgeConfig, ModelGroup, EnsembleResponse, JudgeScores, MultiJudgeScores, WorkflowType, ExecutionStrategy, WorkflowValidationResult, } from "./workflow/types.js";
|
|
272
|
+
export { runWorkflow } from "./workflow/core/workflowRunner.js";
|
|
273
|
+
export type { RunWorkflowOptions } from "./workflow/core/workflowRunner.js";
|
|
274
|
+
export { registerWorkflow, getWorkflow, listWorkflows, clearRegistry as clearWorkflowRegistry, } from "./workflow/core/workflowRegistry.js";
|
|
275
|
+
export { CONSENSUS_3_WORKFLOW, CONSENSUS_3_FAST_WORKFLOW, createConsensus3WithPrompt, } from "./workflow/workflows/consensusWorkflow.js";
|
|
276
|
+
export { FAST_FALLBACK_WORKFLOW, AGGRESSIVE_FALLBACK_WORKFLOW, } from "./workflow/workflows/fallbackWorkflow.js";
|
|
277
|
+
export { MULTI_JUDGE_5_WORKFLOW, MULTI_JUDGE_3_WORKFLOW, createMultiJudgeWorkflow, } from "./workflow/workflows/multiJudgeWorkflow.js";
|
|
278
|
+
export { QUALITY_MAX_WORKFLOW, SPEED_FIRST_WORKFLOW, BALANCED_ADAPTIVE_WORKFLOW, createAdaptiveWorkflow, } from "./workflow/workflows/adaptiveWorkflow.js";
|
|
279
|
+
export { validateWorkflow } from "./workflow/utils/workflowValidation.js";
|
|
280
|
+
export { calculateModelMetrics, compareWorkflows, generateSummaryStats, } from "./workflow/utils/workflowMetrics.js";
|
|
281
|
+
export { WORKFLOW_ENGINE_VERSION, DEFAULT_SCORE_SCALE, } from "./workflow/index.js";
|
|
247
282
|
export type { AgentExecuteRequest, AgentExecuteResponse, AuthConfig, AuthenticatedUser, AuthResult, AuthStrategy, BodyParserConfig, CacheConfig, CacheEntry, CacheStore, CORSConfig, CreateRoutesOptions, DataEvent, DataStreamEvent, DataStreamEventType, DataStreamResponseConfig, DataStreamWriter, DataStreamWriterConfig, ErrorCategoryType, ErrorEvent, ErrorResponse, ErrorSeverityType, FinishEvent, HealthResponse, HttpMethod, LoggingConfig, MCPServerStatusResponse, MiddlewareDefinition, MiddlewareHandler, OpenAPIGeneratorConfig, OpenAPISpec, PropertySchema, RateLimitConfig as ServerRateLimitConfig, RateLimitMiddlewareConfig, RateLimitStore, ReadyResponse, RequiredServerAdapterConfig, RouteDefinition, RouteGroup, RouteHandler, ServerAdapterConfig, ServerAdapterErrorCodeType, ServerAdapterErrorContext, ServerAdapterEvents, ServerAdapterFactoryOptions, ServerContext, ServerFramework, ServerResponse, ServerStatus, SSEWriteOptions, StreamingConfig, TextDeltaEvent, TextEndEvent, TextStartEvent, ToolCallEvent, ToolExecuteRequest, ToolExecuteResponse, ToolResultEvent, ValidationConfig, ValidationResult, ValidationSchema, WebSocketAuthConfig, WebSocketConfig, WebSocketConnection, WebSocketHandler, WebSocketMessage, WebSocketMessageType, } from "./server/index.js";
|
|
248
283
|
/**
|
|
249
284
|
* Server Adapters for exposing NeuroLink as HTTP APIs
|
package/dist/index.js
CHANGED
|
@@ -289,6 +289,23 @@ export async function generateText(options) {
|
|
|
289
289
|
const neurolink = new NeuroLink();
|
|
290
290
|
return await neurolink.generateText(options);
|
|
291
291
|
}
|
|
292
|
+
// Workflow execution
|
|
293
|
+
export { runWorkflow } from "./workflow/core/workflowRunner.js";
|
|
294
|
+
// Workflow registry
|
|
295
|
+
export { registerWorkflow, getWorkflow, listWorkflows, clearRegistry as clearWorkflowRegistry, } from "./workflow/core/workflowRegistry.js";
|
|
296
|
+
// Pre-built workflows - Consensus
|
|
297
|
+
export { CONSENSUS_3_WORKFLOW, CONSENSUS_3_FAST_WORKFLOW, createConsensus3WithPrompt, } from "./workflow/workflows/consensusWorkflow.js";
|
|
298
|
+
// Pre-built workflows - Fallback
|
|
299
|
+
export { FAST_FALLBACK_WORKFLOW, AGGRESSIVE_FALLBACK_WORKFLOW, } from "./workflow/workflows/fallbackWorkflow.js";
|
|
300
|
+
// Pre-built workflows - Multi-judge
|
|
301
|
+
export { MULTI_JUDGE_5_WORKFLOW, MULTI_JUDGE_3_WORKFLOW, createMultiJudgeWorkflow, } from "./workflow/workflows/multiJudgeWorkflow.js";
|
|
302
|
+
// Pre-built workflows - Adaptive
|
|
303
|
+
export { QUALITY_MAX_WORKFLOW, SPEED_FIRST_WORKFLOW, BALANCED_ADAPTIVE_WORKFLOW, createAdaptiveWorkflow, } from "./workflow/workflows/adaptiveWorkflow.js";
|
|
304
|
+
// Validation and metrics
|
|
305
|
+
export { validateWorkflow } from "./workflow/utils/workflowValidation.js";
|
|
306
|
+
export { calculateModelMetrics, compareWorkflows, generateSummaryStats, } from "./workflow/utils/workflowMetrics.js";
|
|
307
|
+
// Workflow constants
|
|
308
|
+
export { WORKFLOW_ENGINE_VERSION, DEFAULT_SCORE_SCALE, } from "./workflow/index.js";
|
|
292
309
|
/**
|
|
293
310
|
* Server Adapters for exposing NeuroLink as HTTP APIs
|
|
294
311
|
*
|
|
@@ -221,11 +221,11 @@ export declare const directAgentTools: {
|
|
|
221
221
|
}, "strip", z.ZodTypeAny, {
|
|
222
222
|
content: string;
|
|
223
223
|
path: string;
|
|
224
|
-
mode: "create" | "
|
|
224
|
+
mode: "create" | "overwrite" | "append";
|
|
225
225
|
}, {
|
|
226
226
|
content: string;
|
|
227
227
|
path: string;
|
|
228
|
-
mode?: "create" | "
|
|
228
|
+
mode?: "create" | "overwrite" | "append" | undefined;
|
|
229
229
|
}>, {
|
|
230
230
|
success: boolean;
|
|
231
231
|
error: string;
|
|
@@ -236,7 +236,7 @@ export declare const directAgentTools: {
|
|
|
236
236
|
} | {
|
|
237
237
|
success: boolean;
|
|
238
238
|
path: string;
|
|
239
|
-
mode: "create" | "
|
|
239
|
+
mode: "create" | "overwrite" | "append";
|
|
240
240
|
size: number;
|
|
241
241
|
written: number;
|
|
242
242
|
error?: undefined;
|
|
@@ -251,7 +251,7 @@ export declare const directAgentTools: {
|
|
|
251
251
|
execute: (args: {
|
|
252
252
|
content: string;
|
|
253
253
|
path: string;
|
|
254
|
-
mode: "create" | "
|
|
254
|
+
mode: "create" | "overwrite" | "append";
|
|
255
255
|
}, options: import("ai").ToolExecutionOptions) => PromiseLike<{
|
|
256
256
|
success: boolean;
|
|
257
257
|
error: string;
|
|
@@ -262,7 +262,7 @@ export declare const directAgentTools: {
|
|
|
262
262
|
} | {
|
|
263
263
|
success: boolean;
|
|
264
264
|
path: string;
|
|
265
|
-
mode: "create" | "
|
|
265
|
+
mode: "create" | "overwrite" | "append";
|
|
266
266
|
size: number;
|
|
267
267
|
written: number;
|
|
268
268
|
error?: undefined;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -244,6 +244,41 @@ export type { AnalyticsData, EvaluationData, TextGenerationOptions, TextGenerati
|
|
|
244
244
|
* @since 1.0.0
|
|
245
245
|
*/
|
|
246
246
|
export declare function generateText(options: import("./types/index.js").TextGenerationOptions): Promise<import("./types/index.js").TextGenerationResult>;
|
|
247
|
+
/**
|
|
248
|
+
* Workflow Engine for multi-model ensembles with judge-based evaluation
|
|
249
|
+
*
|
|
250
|
+
* Enables sophisticated AI orchestration patterns:
|
|
251
|
+
* - Ensemble execution (parallel multi-model)
|
|
252
|
+
* - Chain execution (sequential fallback)
|
|
253
|
+
* - Adaptive execution (tier-based quality/cost optimization)
|
|
254
|
+
* - Multi-judge voting for consensus
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* import { neurolink, CONSENSUS_3_WORKFLOW } from '@juspay/neurolink';
|
|
259
|
+
*
|
|
260
|
+
* // Use workflow via generate() with workflowConfig option
|
|
261
|
+
* const result = await neurolink.generate({
|
|
262
|
+
* input: { text: 'Explain quantum computing' },
|
|
263
|
+
* workflowConfig: CONSENSUS_3_WORKFLOW,
|
|
264
|
+
* });
|
|
265
|
+
*
|
|
266
|
+
* console.log('Best response:', result.content);
|
|
267
|
+
* console.log('Selected model:', result.workflow?.selectedModel);
|
|
268
|
+
* console.log('Total time:', result.workflow?.metrics?.totalTime);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export type { WorkflowConfig, WorkflowResult, ModelConfig, JudgeConfig, ModelGroup, EnsembleResponse, JudgeScores, MultiJudgeScores, WorkflowType, ExecutionStrategy, WorkflowValidationResult, } from "./workflow/types.js";
|
|
272
|
+
export { runWorkflow } from "./workflow/core/workflowRunner.js";
|
|
273
|
+
export type { RunWorkflowOptions } from "./workflow/core/workflowRunner.js";
|
|
274
|
+
export { registerWorkflow, getWorkflow, listWorkflows, clearRegistry as clearWorkflowRegistry, } from "./workflow/core/workflowRegistry.js";
|
|
275
|
+
export { CONSENSUS_3_WORKFLOW, CONSENSUS_3_FAST_WORKFLOW, createConsensus3WithPrompt, } from "./workflow/workflows/consensusWorkflow.js";
|
|
276
|
+
export { FAST_FALLBACK_WORKFLOW, AGGRESSIVE_FALLBACK_WORKFLOW, } from "./workflow/workflows/fallbackWorkflow.js";
|
|
277
|
+
export { MULTI_JUDGE_5_WORKFLOW, MULTI_JUDGE_3_WORKFLOW, createMultiJudgeWorkflow, } from "./workflow/workflows/multiJudgeWorkflow.js";
|
|
278
|
+
export { QUALITY_MAX_WORKFLOW, SPEED_FIRST_WORKFLOW, BALANCED_ADAPTIVE_WORKFLOW, createAdaptiveWorkflow, } from "./workflow/workflows/adaptiveWorkflow.js";
|
|
279
|
+
export { validateWorkflow } from "./workflow/utils/workflowValidation.js";
|
|
280
|
+
export { calculateModelMetrics, compareWorkflows, generateSummaryStats, } from "./workflow/utils/workflowMetrics.js";
|
|
281
|
+
export { WORKFLOW_ENGINE_VERSION, DEFAULT_SCORE_SCALE, } from "./workflow/index.js";
|
|
247
282
|
export type { AgentExecuteRequest, AgentExecuteResponse, AuthConfig, AuthenticatedUser, AuthResult, AuthStrategy, BodyParserConfig, CacheConfig, CacheEntry, CacheStore, CORSConfig, CreateRoutesOptions, DataEvent, DataStreamEvent, DataStreamEventType, DataStreamResponseConfig, DataStreamWriter, DataStreamWriterConfig, ErrorCategoryType, ErrorEvent, ErrorResponse, ErrorSeverityType, FinishEvent, HealthResponse, HttpMethod, LoggingConfig, MCPServerStatusResponse, MiddlewareDefinition, MiddlewareHandler, OpenAPIGeneratorConfig, OpenAPISpec, PropertySchema, RateLimitConfig as ServerRateLimitConfig, RateLimitMiddlewareConfig, RateLimitStore, ReadyResponse, RequiredServerAdapterConfig, RouteDefinition, RouteGroup, RouteHandler, ServerAdapterConfig, ServerAdapterErrorCodeType, ServerAdapterErrorContext, ServerAdapterEvents, ServerAdapterFactoryOptions, ServerContext, ServerFramework, ServerResponse, ServerStatus, SSEWriteOptions, StreamingConfig, TextDeltaEvent, TextEndEvent, TextStartEvent, ToolCallEvent, ToolExecuteRequest, ToolExecuteResponse, ToolResultEvent, ValidationConfig, ValidationResult, ValidationSchema, WebSocketAuthConfig, WebSocketConfig, WebSocketConnection, WebSocketHandler, WebSocketMessage, WebSocketMessageType, } from "./server/index.js";
|
|
248
283
|
/**
|
|
249
284
|
* Server Adapters for exposing NeuroLink as HTTP APIs
|
package/dist/lib/index.js
CHANGED
|
@@ -289,6 +289,23 @@ export async function generateText(options) {
|
|
|
289
289
|
const neurolink = new NeuroLink();
|
|
290
290
|
return await neurolink.generateText(options);
|
|
291
291
|
}
|
|
292
|
+
// Workflow execution
|
|
293
|
+
export { runWorkflow } from "./workflow/core/workflowRunner.js";
|
|
294
|
+
// Workflow registry
|
|
295
|
+
export { registerWorkflow, getWorkflow, listWorkflows, clearRegistry as clearWorkflowRegistry, } from "./workflow/core/workflowRegistry.js";
|
|
296
|
+
// Pre-built workflows - Consensus
|
|
297
|
+
export { CONSENSUS_3_WORKFLOW, CONSENSUS_3_FAST_WORKFLOW, createConsensus3WithPrompt, } from "./workflow/workflows/consensusWorkflow.js";
|
|
298
|
+
// Pre-built workflows - Fallback
|
|
299
|
+
export { FAST_FALLBACK_WORKFLOW, AGGRESSIVE_FALLBACK_WORKFLOW, } from "./workflow/workflows/fallbackWorkflow.js";
|
|
300
|
+
// Pre-built workflows - Multi-judge
|
|
301
|
+
export { MULTI_JUDGE_5_WORKFLOW, MULTI_JUDGE_3_WORKFLOW, createMultiJudgeWorkflow, } from "./workflow/workflows/multiJudgeWorkflow.js";
|
|
302
|
+
// Pre-built workflows - Adaptive
|
|
303
|
+
export { QUALITY_MAX_WORKFLOW, SPEED_FIRST_WORKFLOW, BALANCED_ADAPTIVE_WORKFLOW, createAdaptiveWorkflow, } from "./workflow/workflows/adaptiveWorkflow.js";
|
|
304
|
+
// Validation and metrics
|
|
305
|
+
export { validateWorkflow } from "./workflow/utils/workflowValidation.js";
|
|
306
|
+
export { calculateModelMetrics, compareWorkflows, generateSummaryStats, } from "./workflow/utils/workflowMetrics.js";
|
|
307
|
+
// Workflow constants
|
|
308
|
+
export { WORKFLOW_ENGINE_VERSION, DEFAULT_SCORE_SCALE, } from "./workflow/index.js";
|
|
292
309
|
/**
|
|
293
310
|
* Server Adapters for exposing NeuroLink as HTTP APIs
|
|
294
311
|
*
|
package/dist/lib/neurolink.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Enhanced AI provider system with natural MCP tool access.
|
|
6
6
|
* Uses real MCP infrastructure for tool discovery and execution.
|
|
7
7
|
*/
|
|
8
|
+
import type { TextGenerationOptions, TextGenerationResult } from "./types/index.js";
|
|
8
9
|
import type { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
|
|
9
10
|
import type { RedisConversationMemoryManager } from "./core/redisConversationMemoryManager.js";
|
|
10
11
|
import { ExternalServerManager } from "./mcp/externalServerManager.js";
|
|
@@ -14,7 +15,7 @@ import type { NeurolinkConstructorConfig } from "./types/configTypes.js";
|
|
|
14
15
|
import type { ChatMessage } from "./types/conversation.js";
|
|
15
16
|
import type { ExternalMCPOperationResult, ExternalMCPServerInstance, ExternalMCPToolInfo } from "./types/externalMcp.js";
|
|
16
17
|
import type { GenerateOptions, GenerateResult } from "./types/generateTypes.js";
|
|
17
|
-
import type { ProviderStatus
|
|
18
|
+
import type { ProviderStatus } from "./types/index.js";
|
|
18
19
|
import type { MCPExecutableTool, MCPServerInfo, MCPStatus } from "./types/mcpTypes.js";
|
|
19
20
|
import type { ObservabilityConfig } from "./types/observability.js";
|
|
20
21
|
import type { StreamOptions, StreamResult } from "./types/streamTypes.js";
|
|
@@ -454,6 +455,16 @@ export declare class NeuroLink {
|
|
|
454
455
|
* @since 1.0.0
|
|
455
456
|
*/
|
|
456
457
|
generate(optionsOrPrompt: GenerateOptions | string): Promise<GenerateResult>;
|
|
458
|
+
/**
|
|
459
|
+
* Generate with workflow engine integration
|
|
460
|
+
* Returns both original and processed responses for AB testing
|
|
461
|
+
*/
|
|
462
|
+
private generateWithWorkflow;
|
|
463
|
+
/**
|
|
464
|
+
* Stream with workflow engine integration
|
|
465
|
+
* Progressive streaming: yields preliminary response (first model) then final synthesis
|
|
466
|
+
*/
|
|
467
|
+
private streamWithWorkflow;
|
|
457
468
|
/**
|
|
458
469
|
* BACKWARD COMPATIBILITY: Legacy generateText method
|
|
459
470
|
* Internally calls generate() and converts result format
|
package/dist/lib/neurolink.js
CHANGED
|
@@ -14,6 +14,7 @@ catch {
|
|
|
14
14
|
// Environment variables should be set externally in production
|
|
15
15
|
}
|
|
16
16
|
import { EventEmitter } from "events";
|
|
17
|
+
import { isNonNullObject } from "./utils/typeUtils.js";
|
|
17
18
|
import pLimit from "p-limit";
|
|
18
19
|
import { CIRCUIT_BREAKER, CIRCUIT_BREAKER_RESET_MS, MEMORY_THRESHOLDS, NANOSECOND_TO_MS_DIVISOR, PERFORMANCE_THRESHOLDS, PROVIDER_TIMEOUTS, RETRY_ATTEMPTS, RETRY_DELAYS, TOOL_TIMEOUTS, } from "./constants/index.js";
|
|
19
20
|
import { SYSTEM_LIMITS } from "./core/constants.js";
|
|
@@ -41,7 +42,9 @@ import { BinaryTaskClassifier } from "./utils/taskClassifier.js";
|
|
|
41
42
|
// Tool detection and execution imports
|
|
42
43
|
// Transformation utilities
|
|
43
44
|
import { extractToolNames, optimizeToolForCollection, transformAvailableTools, transformParamsForLogging, transformToolExecutions, transformToolExecutionsForMCP, transformToolsForMCP, transformToolsToDescriptions, transformToolsToExpectedFormat, } from "./utils/transformationUtils.js";
|
|
44
|
-
import {
|
|
45
|
+
import { runWorkflow } from "./workflow/core/workflowRunner.js";
|
|
46
|
+
import { getWorkflow } from "./workflow/core/workflowRegistry.js";
|
|
47
|
+
// Core types imported from core/types.js
|
|
45
48
|
/**
|
|
46
49
|
* NeuroLink - Universal AI Development Platform
|
|
47
50
|
*
|
|
@@ -1148,9 +1151,19 @@ Current user's request: ${currentInput}`;
|
|
|
1148
1151
|
* @returns The original prompt text as a string.
|
|
1149
1152
|
*/
|
|
1150
1153
|
_extractOriginalPrompt(optionsOrPrompt) {
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
+
if (typeof optionsOrPrompt === "string") {
|
|
1155
|
+
return optionsOrPrompt;
|
|
1156
|
+
}
|
|
1157
|
+
// Handle messages format (for workflow compatibility)
|
|
1158
|
+
const anyOptions = optionsOrPrompt;
|
|
1159
|
+
if (anyOptions.messages && anyOptions.messages.length > 0) {
|
|
1160
|
+
const lastMessage = anyOptions.messages[anyOptions.messages.length - 1];
|
|
1161
|
+
return typeof lastMessage.content === "string"
|
|
1162
|
+
? lastMessage.content
|
|
1163
|
+
: JSON.stringify(lastMessage.content);
|
|
1164
|
+
}
|
|
1165
|
+
// Handle input.text format
|
|
1166
|
+
return optionsOrPrompt.input?.text || "";
|
|
1154
1167
|
}
|
|
1155
1168
|
/**
|
|
1156
1169
|
* Generate AI content using the best available provider with MCP tool integration.
|
|
@@ -1377,6 +1390,10 @@ Current user's request: ${currentInput}`;
|
|
|
1377
1390
|
if (!options.input?.text || typeof options.input.text !== "string") {
|
|
1378
1391
|
throw new Error("Input text is required and must be a non-empty string");
|
|
1379
1392
|
}
|
|
1393
|
+
// Check if workflow is requested
|
|
1394
|
+
if (options.workflow || options.workflowConfig) {
|
|
1395
|
+
return await this.generateWithWorkflow(options);
|
|
1396
|
+
}
|
|
1380
1397
|
// Set session and user IDs from context for Langfuse spans and execute with proper async scoping
|
|
1381
1398
|
return await this.setLangfuseContextFromOptions(options, async () => {
|
|
1382
1399
|
if (this.conversationMemoryConfig?.conversationMemory?.mem0Enabled &&
|
|
@@ -1602,6 +1619,246 @@ Current user's request: ${currentInput}`;
|
|
|
1602
1619
|
return generateResult;
|
|
1603
1620
|
});
|
|
1604
1621
|
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Generate with workflow engine integration
|
|
1624
|
+
* Returns both original and processed responses for AB testing
|
|
1625
|
+
*/
|
|
1626
|
+
async generateWithWorkflow(options) {
|
|
1627
|
+
const workflowStartTime = Date.now();
|
|
1628
|
+
logger.debug("[NeuroLink] Executing workflow generation", {
|
|
1629
|
+
workflowId: options.workflow,
|
|
1630
|
+
hasInlineConfig: !!options.workflowConfig,
|
|
1631
|
+
prompt: options.input.text.substring(0, 100),
|
|
1632
|
+
startTime: workflowStartTime,
|
|
1633
|
+
});
|
|
1634
|
+
// Determine workflow configuration
|
|
1635
|
+
let workflowConfig;
|
|
1636
|
+
if (options.workflowConfig) {
|
|
1637
|
+
// Use inline config
|
|
1638
|
+
workflowConfig = options.workflowConfig;
|
|
1639
|
+
}
|
|
1640
|
+
else if (options.workflow) {
|
|
1641
|
+
// Look up predefined workflow
|
|
1642
|
+
workflowConfig = getWorkflow(options.workflow);
|
|
1643
|
+
if (!workflowConfig) {
|
|
1644
|
+
throw new Error(`Workflow '${options.workflow}' not found in registry`);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
else {
|
|
1648
|
+
throw new Error("Either workflow or workflowConfig must be provided");
|
|
1649
|
+
}
|
|
1650
|
+
// Execute workflow
|
|
1651
|
+
const workflowResult = await runWorkflow(workflowConfig, {
|
|
1652
|
+
prompt: options.input.text,
|
|
1653
|
+
conversationHistory: options.conversationHistory,
|
|
1654
|
+
timeout: options.timeout,
|
|
1655
|
+
verbose: false,
|
|
1656
|
+
metadata: options.context,
|
|
1657
|
+
});
|
|
1658
|
+
// Build GenerateResult with workflow data
|
|
1659
|
+
const generateResult = {
|
|
1660
|
+
// Primary output (backward compatible) - use the original best response
|
|
1661
|
+
content: workflowResult.content,
|
|
1662
|
+
// Provider info from selected response
|
|
1663
|
+
provider: workflowResult.selectedResponse?.provider ||
|
|
1664
|
+
workflowConfig.models[0]?.provider,
|
|
1665
|
+
model: workflowResult.selectedResponse?.model ||
|
|
1666
|
+
workflowConfig.models[0]?.model,
|
|
1667
|
+
// Basic usage info
|
|
1668
|
+
usage: workflowResult.usage
|
|
1669
|
+
? {
|
|
1670
|
+
input: workflowResult.usage.totalInputTokens,
|
|
1671
|
+
output: workflowResult.usage.totalOutputTokens,
|
|
1672
|
+
total: workflowResult.usage.totalTokens,
|
|
1673
|
+
}
|
|
1674
|
+
: undefined,
|
|
1675
|
+
// Performance
|
|
1676
|
+
responseTime: workflowResult.totalTime,
|
|
1677
|
+
// Workflow-specific data
|
|
1678
|
+
workflow: {
|
|
1679
|
+
originalResponse: workflowResult.originalContent || workflowResult.content, // Original unmodified best response
|
|
1680
|
+
processedResponse: workflowResult.content, // After conditioning (with metadata)
|
|
1681
|
+
ensembleResponses: workflowResult.ensembleResponses.map((r) => ({
|
|
1682
|
+
provider: r.provider,
|
|
1683
|
+
model: r.model,
|
|
1684
|
+
content: r.content,
|
|
1685
|
+
responseTime: r.responseTime,
|
|
1686
|
+
status: r.status,
|
|
1687
|
+
error: r.error,
|
|
1688
|
+
})),
|
|
1689
|
+
judgeScores: workflowResult.judgeScores
|
|
1690
|
+
? {
|
|
1691
|
+
scores: workflowResult.judgeScores.scores,
|
|
1692
|
+
reasoning: workflowResult.reasoning,
|
|
1693
|
+
selectedModel: `${workflowResult.selectedResponse?.provider}-${workflowResult.selectedResponse?.model}`,
|
|
1694
|
+
}
|
|
1695
|
+
: undefined,
|
|
1696
|
+
selectedModel: `${workflowResult.selectedResponse?.provider}-${workflowResult.selectedResponse?.model}`,
|
|
1697
|
+
metrics: {
|
|
1698
|
+
totalTime: workflowResult.totalTime,
|
|
1699
|
+
ensembleTime: workflowResult.ensembleTime,
|
|
1700
|
+
judgeTime: workflowResult.judgeTime,
|
|
1701
|
+
conditioningTime: workflowResult.conditioningTime,
|
|
1702
|
+
},
|
|
1703
|
+
workflowId: workflowResult.workflow,
|
|
1704
|
+
workflowName: workflowResult.workflowName,
|
|
1705
|
+
},
|
|
1706
|
+
};
|
|
1707
|
+
logger.debug("[NeuroLink] Workflow generation complete", {
|
|
1708
|
+
workflowId: workflowResult.workflow,
|
|
1709
|
+
selectedModel: generateResult.workflow?.selectedModel,
|
|
1710
|
+
score: workflowResult.score,
|
|
1711
|
+
totalTime: workflowResult.totalTime,
|
|
1712
|
+
});
|
|
1713
|
+
return generateResult;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Stream with workflow engine integration
|
|
1717
|
+
* Progressive streaming: yields preliminary response (first model) then final synthesis
|
|
1718
|
+
*/
|
|
1719
|
+
async streamWithWorkflow(options, startTime) {
|
|
1720
|
+
logger.debug("[NeuroLink] Executing workflow streaming (progressive)", {
|
|
1721
|
+
workflowId: options.workflow,
|
|
1722
|
+
hasInlineConfig: !!options.workflowConfig,
|
|
1723
|
+
prompt: options.input.text.substring(0, 100),
|
|
1724
|
+
});
|
|
1725
|
+
// Determine workflow configuration
|
|
1726
|
+
let workflowConfig;
|
|
1727
|
+
if (options.workflowConfig) {
|
|
1728
|
+
workflowConfig = options.workflowConfig;
|
|
1729
|
+
}
|
|
1730
|
+
else if (options.workflow) {
|
|
1731
|
+
workflowConfig = getWorkflow(options.workflow);
|
|
1732
|
+
if (!workflowConfig) {
|
|
1733
|
+
throw new Error(`Workflow '${options.workflow}' not found in registry`);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
else {
|
|
1737
|
+
throw new Error("Either workflow or workflowConfig must be provided");
|
|
1738
|
+
}
|
|
1739
|
+
// Import streaming workflow runner
|
|
1740
|
+
const { runWorkflowWithStreaming } = await import("./workflow/core/workflowRunner.js");
|
|
1741
|
+
// Execute workflow with progressive streaming
|
|
1742
|
+
const workflowStream = runWorkflowWithStreaming(workflowConfig, {
|
|
1743
|
+
prompt: options.input.text,
|
|
1744
|
+
conversationHistory: options.conversationHistory,
|
|
1745
|
+
timeout: options.timeout,
|
|
1746
|
+
verbose: false,
|
|
1747
|
+
metadata: options.context,
|
|
1748
|
+
streaming: true,
|
|
1749
|
+
});
|
|
1750
|
+
// Store final result for metadata
|
|
1751
|
+
let finalResult = null;
|
|
1752
|
+
let preliminaryTime = 0;
|
|
1753
|
+
// Create a generator that yields progressive chunks
|
|
1754
|
+
const stream = (async function* () {
|
|
1755
|
+
for await (const chunk of workflowStream) {
|
|
1756
|
+
if (chunk.type === "preliminary") {
|
|
1757
|
+
preliminaryTime = Date.now() - startTime;
|
|
1758
|
+
logger.debug("[NeuroLink] Streaming preliminary response", {
|
|
1759
|
+
responseTime: preliminaryTime,
|
|
1760
|
+
contentLength: chunk.content.length,
|
|
1761
|
+
});
|
|
1762
|
+
yield {
|
|
1763
|
+
content: chunk.content,
|
|
1764
|
+
type: "preliminary",
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
else if (chunk.type === "final") {
|
|
1768
|
+
finalResult = chunk.partialResult ?? null;
|
|
1769
|
+
const finalTime = Date.now() - startTime;
|
|
1770
|
+
logger.debug("[NeuroLink] Streaming final synthesis", {
|
|
1771
|
+
responseTime: finalTime,
|
|
1772
|
+
contentLength: chunk.content.length,
|
|
1773
|
+
});
|
|
1774
|
+
yield {
|
|
1775
|
+
content: chunk.content,
|
|
1776
|
+
type: "final",
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
})();
|
|
1781
|
+
const streamResult = {
|
|
1782
|
+
stream,
|
|
1783
|
+
// Provider info (will be from final result)
|
|
1784
|
+
provider: workflowConfig.models[0]?.provider,
|
|
1785
|
+
model: workflowConfig.models[0]?.model,
|
|
1786
|
+
// Metadata
|
|
1787
|
+
metadata: {
|
|
1788
|
+
streamId: `workflow-${workflowConfig.id}-${Date.now()}`,
|
|
1789
|
+
startTime,
|
|
1790
|
+
responseTime: 0, // Will be updated after stream completes
|
|
1791
|
+
},
|
|
1792
|
+
// Note: Workflow data will be populated after stream completes
|
|
1793
|
+
// For now, return placeholder that will be updated via stream metadata
|
|
1794
|
+
};
|
|
1795
|
+
// Wrap stream to capture final result and populate metadata
|
|
1796
|
+
const originalStream = streamResult.stream;
|
|
1797
|
+
streamResult.stream = (async function* () {
|
|
1798
|
+
for await (const chunk of originalStream) {
|
|
1799
|
+
yield chunk;
|
|
1800
|
+
}
|
|
1801
|
+
// After stream completes, update result with final workflow data
|
|
1802
|
+
if (finalResult) {
|
|
1803
|
+
const result = finalResult;
|
|
1804
|
+
const responseTime = Date.now() - startTime;
|
|
1805
|
+
// Update usage if available
|
|
1806
|
+
if (result.usage) {
|
|
1807
|
+
streamResult.usage = {
|
|
1808
|
+
input: result.usage.totalInputTokens,
|
|
1809
|
+
output: result.usage.totalOutputTokens,
|
|
1810
|
+
total: result.usage.totalTokens,
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
// Update metadata
|
|
1814
|
+
streamResult.metadata = {
|
|
1815
|
+
...streamResult.metadata,
|
|
1816
|
+
totalChunks: 2, // Preliminary + final
|
|
1817
|
+
responseTime,
|
|
1818
|
+
preliminaryTime,
|
|
1819
|
+
};
|
|
1820
|
+
// Build workflow data with proper type safety
|
|
1821
|
+
const ensembleResponses = result.ensembleResponses?.map((r) => ({
|
|
1822
|
+
provider: r.provider,
|
|
1823
|
+
model: r.model,
|
|
1824
|
+
content: r.content,
|
|
1825
|
+
responseTime: r.responseTime,
|
|
1826
|
+
status: r.status,
|
|
1827
|
+
error: r.error,
|
|
1828
|
+
})) ?? [];
|
|
1829
|
+
const judgeScores = result.judgeScores
|
|
1830
|
+
? {
|
|
1831
|
+
scores: result.judgeScores.scores,
|
|
1832
|
+
reasoning: result.reasoning ?? "",
|
|
1833
|
+
selectedModel: result.selectedResponse
|
|
1834
|
+
? `${result.selectedResponse.provider}-${result.selectedResponse.model}`
|
|
1835
|
+
: "unknown",
|
|
1836
|
+
}
|
|
1837
|
+
: undefined;
|
|
1838
|
+
streamResult.workflow = {
|
|
1839
|
+
originalResponse: result.originalContent ?? result.content ?? "",
|
|
1840
|
+
processedResponse: result.content ?? "",
|
|
1841
|
+
ensembleResponses,
|
|
1842
|
+
judgeScores,
|
|
1843
|
+
selectedModel: result.selectedResponse
|
|
1844
|
+
? `${result.selectedResponse.provider}-${result.selectedResponse.model}`
|
|
1845
|
+
: "unknown",
|
|
1846
|
+
metrics: {
|
|
1847
|
+
totalTime: result.totalTime ?? responseTime,
|
|
1848
|
+
ensembleTime: result.ensembleTime ?? 0,
|
|
1849
|
+
judgeTime: result.judgeTime,
|
|
1850
|
+
conditioningTime: result.conditioningTime,
|
|
1851
|
+
},
|
|
1852
|
+
workflowId: result.workflow ?? workflowConfig.id,
|
|
1853
|
+
workflowName: result.workflowName ?? workflowConfig.name,
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
})();
|
|
1857
|
+
logger.debug("[NeuroLink] Workflow streaming initialized", {
|
|
1858
|
+
workflowId: workflowConfig.id,
|
|
1859
|
+
});
|
|
1860
|
+
return streamResult;
|
|
1861
|
+
}
|
|
1605
1862
|
/**
|
|
1606
1863
|
* BACKWARD COMPATIBILITY: Legacy generateText method
|
|
1607
1864
|
* Internally calls generate() and converts result format
|
|
@@ -2135,6 +2392,10 @@ Current user's request: ${currentInput}`;
|
|
|
2135
2392
|
const originalPrompt = options.input.text; // Store the original prompt for memory storage
|
|
2136
2393
|
await this.validateStreamInput(options);
|
|
2137
2394
|
this.emitStreamStartEvents(options, startTime);
|
|
2395
|
+
// Check if workflow is requested
|
|
2396
|
+
if (options.workflow || options.workflowConfig) {
|
|
2397
|
+
return await this.streamWithWorkflow(options, startTime);
|
|
2398
|
+
}
|
|
2138
2399
|
// Set session and user IDs from context for Langfuse spans and execute with proper async scoping
|
|
2139
2400
|
return await this.setLangfuseContextFromOptions(options, async () => {
|
|
2140
2401
|
let enhancedOptions;
|