@ax-llm/ax 13.0.8 → 13.0.10
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/index.cjs +53 -55
- package/index.cjs.map +1 -1
- package/index.d.cts +61 -8
- package/index.d.ts +61 -8
- package/index.js +53 -55
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -301,6 +301,10 @@ type AxLoggerData = {
|
|
|
301
301
|
value: AxChatResponseResult & {
|
|
302
302
|
delta?: string;
|
|
303
303
|
};
|
|
304
|
+
} | {
|
|
305
|
+
name: 'ChatResponseStreamingDoneResult';
|
|
306
|
+
index: number;
|
|
307
|
+
value: AxChatResponseResult;
|
|
304
308
|
} | {
|
|
305
309
|
name: 'FunctionError';
|
|
306
310
|
index: number;
|
|
@@ -4332,7 +4336,7 @@ interface AxFlowBranchContext {
|
|
|
4332
4336
|
currentBranchValue?: unknown;
|
|
4333
4337
|
}
|
|
4334
4338
|
interface AxFlowExecutionStep {
|
|
4335
|
-
type: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel';
|
|
4339
|
+
type: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel' | 'derive';
|
|
4336
4340
|
nodeName?: string;
|
|
4337
4341
|
dependencies: string[];
|
|
4338
4342
|
produces: string[];
|
|
@@ -4391,10 +4395,34 @@ declare class AxFlowExecutionPlanner {
|
|
|
4391
4395
|
* @param mapTransform - Transformation function (for map steps)
|
|
4392
4396
|
* @param mergeOptions - Options for merge operations (result key, merge function)
|
|
4393
4397
|
*/
|
|
4394
|
-
addExecutionStep(stepFunction: AxFlowStepFunction, nodeName?: string, mapping?: (state: any) => any, stepType?: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel', mapTransform?: (state: any) => any, mergeOptions?: {
|
|
4398
|
+
addExecutionStep(stepFunction: AxFlowStepFunction, nodeName?: string, mapping?: (state: any) => any, stepType?: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel' | 'derive', mapTransform?: (state: any) => any, mergeOptions?: {
|
|
4395
4399
|
resultKey?: string;
|
|
4396
4400
|
mergeFunction?: (...args: any[]) => any;
|
|
4401
|
+
}, deriveOptions?: {
|
|
4402
|
+
inputFieldName: string;
|
|
4403
|
+
outputFieldName: string;
|
|
4404
|
+
batchSize?: number;
|
|
4397
4405
|
}): void;
|
|
4406
|
+
/**
|
|
4407
|
+
* Analyzes a step function to determine what fields it produces.
|
|
4408
|
+
*
|
|
4409
|
+
* This method analyzes the step function to understand what new fields
|
|
4410
|
+
* it adds to the state. It uses a mock state approach:
|
|
4411
|
+
* 1. Creates a mock state with sample data
|
|
4412
|
+
* 2. Runs the step function on the mock state
|
|
4413
|
+
* 3. Compares the result to see what fields were added
|
|
4414
|
+
*
|
|
4415
|
+
* @param stepFunction - The step function to analyze
|
|
4416
|
+
* @returns Array of field names that the step function produces
|
|
4417
|
+
*/
|
|
4418
|
+
private analyzeStepFunctionProduction;
|
|
4419
|
+
/**
|
|
4420
|
+
* Analyzes step function source code to determine what fields it produces.
|
|
4421
|
+
*
|
|
4422
|
+
* @param stepFunction - The step function to analyze
|
|
4423
|
+
* @returns Array of field names that the step function produces
|
|
4424
|
+
*/
|
|
4425
|
+
private analyzeStepFunctionSource;
|
|
4398
4426
|
/**
|
|
4399
4427
|
* Analyzes a map transformation function to determine what fields it produces.
|
|
4400
4428
|
*
|
|
@@ -4551,7 +4579,7 @@ declare class AxFlowExecutionPlanner {
|
|
|
4551
4579
|
* providing compile-time type safety and superior IntelliSense.
|
|
4552
4580
|
*
|
|
4553
4581
|
* @example
|
|
4554
|
-
* ```
|
|
4582
|
+
* ```
|
|
4555
4583
|
* const flow = new AxFlow<{ topic: string }, { finalAnswer: string }>()
|
|
4556
4584
|
* .node('summarizer', 'text:string -> summary:string')
|
|
4557
4585
|
* .node('critic', 'summary:string -> critique:string')
|
|
@@ -4656,7 +4684,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4656
4684
|
* @returns New AxFlow instance with updated TNodes type
|
|
4657
4685
|
*
|
|
4658
4686
|
* @example
|
|
4659
|
-
* ```
|
|
4687
|
+
* ```
|
|
4660
4688
|
* flow.node('summarizer', 'text:string -> summary:string')
|
|
4661
4689
|
* flow.node('analyzer', 'text:string -> analysis:string, confidence:number', { debug: true })
|
|
4662
4690
|
* ```
|
|
@@ -4675,7 +4703,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4675
4703
|
* @returns New AxFlow instance with updated TNodes type
|
|
4676
4704
|
*
|
|
4677
4705
|
* @example
|
|
4678
|
-
* ```
|
|
4706
|
+
* ```
|
|
4679
4707
|
* const sig = new AxSignature('text:string -> summary:string')
|
|
4680
4708
|
* flow.node('summarizer', sig, { temperature: 0.1 })
|
|
4681
4709
|
* ```
|
|
@@ -4693,7 +4721,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4693
4721
|
* @returns New AxFlow instance with updated TNodes type
|
|
4694
4722
|
*
|
|
4695
4723
|
* @example
|
|
4696
|
-
* ```
|
|
4724
|
+
* ```
|
|
4697
4725
|
* class CustomProgram extends AxProgram<{ input: string }, { output: string }> {
|
|
4698
4726
|
* async forward(ai, values) { return { output: values.input.toUpperCase() } }
|
|
4699
4727
|
* }
|
|
@@ -4739,7 +4767,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4739
4767
|
* @returns New AxFlow instance with updated TState type
|
|
4740
4768
|
*
|
|
4741
4769
|
* @example
|
|
4742
|
-
* ```
|
|
4770
|
+
* ```
|
|
4743
4771
|
* flow.map(state => ({ ...state, processedText: state.text.toLowerCase() }))
|
|
4744
4772
|
* ```
|
|
4745
4773
|
*/
|
|
@@ -4754,7 +4782,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4754
4782
|
* @returns New AxFlow instance with updated TState type
|
|
4755
4783
|
*
|
|
4756
4784
|
* @example
|
|
4757
|
-
* ```
|
|
4785
|
+
* ```
|
|
4758
4786
|
* // Parallel map with multiple transforms
|
|
4759
4787
|
* flow.map([
|
|
4760
4788
|
* state => ({ ...state, result1: processA(state.data) }),
|
|
@@ -4975,6 +5003,31 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4975
5003
|
* Short alias for endWhile()
|
|
4976
5004
|
*/
|
|
4977
5005
|
end(): this;
|
|
5006
|
+
/**
|
|
5007
|
+
* Derives a new field from an existing field by applying a transform function.
|
|
5008
|
+
*
|
|
5009
|
+
* If the input field contains an array, the transform function is applied to each
|
|
5010
|
+
* array element in parallel with batch size control. If the input field contains
|
|
5011
|
+
* a scalar value, the transform function is applied directly.
|
|
5012
|
+
*
|
|
5013
|
+
* @param outputFieldName - Name of the field to store the result
|
|
5014
|
+
* @param inputFieldName - Name of the existing field to transform
|
|
5015
|
+
* @param transformFn - Function to apply to each element (for arrays) or the value directly (for scalars)
|
|
5016
|
+
* @param options - Options including batch size for parallel processing
|
|
5017
|
+
* @returns this (for chaining)
|
|
5018
|
+
*
|
|
5019
|
+
* @example
|
|
5020
|
+
* ```typescript
|
|
5021
|
+
* // Parallel processing of array items
|
|
5022
|
+
* flow.derive('processedItems', 'items', (item, index) => processItem(item), { batchSize: 5 })
|
|
5023
|
+
*
|
|
5024
|
+
* // Direct transformation of scalar value
|
|
5025
|
+
* flow.derive('upperText', 'text', (text) => text.toUpperCase())
|
|
5026
|
+
* ```
|
|
5027
|
+
*/
|
|
5028
|
+
derive<T>(outputFieldName: string, inputFieldName: string, transformFn: (value: any, index?: number, state?: TState) => T, options?: {
|
|
5029
|
+
batchSize?: number;
|
|
5030
|
+
}): this;
|
|
4978
5031
|
/**
|
|
4979
5032
|
* Gets execution plan information for debugging automatic parallelization
|
|
4980
5033
|
*
|
package/index.d.ts
CHANGED
|
@@ -301,6 +301,10 @@ type AxLoggerData = {
|
|
|
301
301
|
value: AxChatResponseResult & {
|
|
302
302
|
delta?: string;
|
|
303
303
|
};
|
|
304
|
+
} | {
|
|
305
|
+
name: 'ChatResponseStreamingDoneResult';
|
|
306
|
+
index: number;
|
|
307
|
+
value: AxChatResponseResult;
|
|
304
308
|
} | {
|
|
305
309
|
name: 'FunctionError';
|
|
306
310
|
index: number;
|
|
@@ -4332,7 +4336,7 @@ interface AxFlowBranchContext {
|
|
|
4332
4336
|
currentBranchValue?: unknown;
|
|
4333
4337
|
}
|
|
4334
4338
|
interface AxFlowExecutionStep {
|
|
4335
|
-
type: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel';
|
|
4339
|
+
type: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel' | 'derive';
|
|
4336
4340
|
nodeName?: string;
|
|
4337
4341
|
dependencies: string[];
|
|
4338
4342
|
produces: string[];
|
|
@@ -4391,10 +4395,34 @@ declare class AxFlowExecutionPlanner {
|
|
|
4391
4395
|
* @param mapTransform - Transformation function (for map steps)
|
|
4392
4396
|
* @param mergeOptions - Options for merge operations (result key, merge function)
|
|
4393
4397
|
*/
|
|
4394
|
-
addExecutionStep(stepFunction: AxFlowStepFunction, nodeName?: string, mapping?: (state: any) => any, stepType?: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel', mapTransform?: (state: any) => any, mergeOptions?: {
|
|
4398
|
+
addExecutionStep(stepFunction: AxFlowStepFunction, nodeName?: string, mapping?: (state: any) => any, stepType?: 'execute' | 'map' | 'merge' | 'parallel-map' | 'parallel' | 'derive', mapTransform?: (state: any) => any, mergeOptions?: {
|
|
4395
4399
|
resultKey?: string;
|
|
4396
4400
|
mergeFunction?: (...args: any[]) => any;
|
|
4401
|
+
}, deriveOptions?: {
|
|
4402
|
+
inputFieldName: string;
|
|
4403
|
+
outputFieldName: string;
|
|
4404
|
+
batchSize?: number;
|
|
4397
4405
|
}): void;
|
|
4406
|
+
/**
|
|
4407
|
+
* Analyzes a step function to determine what fields it produces.
|
|
4408
|
+
*
|
|
4409
|
+
* This method analyzes the step function to understand what new fields
|
|
4410
|
+
* it adds to the state. It uses a mock state approach:
|
|
4411
|
+
* 1. Creates a mock state with sample data
|
|
4412
|
+
* 2. Runs the step function on the mock state
|
|
4413
|
+
* 3. Compares the result to see what fields were added
|
|
4414
|
+
*
|
|
4415
|
+
* @param stepFunction - The step function to analyze
|
|
4416
|
+
* @returns Array of field names that the step function produces
|
|
4417
|
+
*/
|
|
4418
|
+
private analyzeStepFunctionProduction;
|
|
4419
|
+
/**
|
|
4420
|
+
* Analyzes step function source code to determine what fields it produces.
|
|
4421
|
+
*
|
|
4422
|
+
* @param stepFunction - The step function to analyze
|
|
4423
|
+
* @returns Array of field names that the step function produces
|
|
4424
|
+
*/
|
|
4425
|
+
private analyzeStepFunctionSource;
|
|
4398
4426
|
/**
|
|
4399
4427
|
* Analyzes a map transformation function to determine what fields it produces.
|
|
4400
4428
|
*
|
|
@@ -4551,7 +4579,7 @@ declare class AxFlowExecutionPlanner {
|
|
|
4551
4579
|
* providing compile-time type safety and superior IntelliSense.
|
|
4552
4580
|
*
|
|
4553
4581
|
* @example
|
|
4554
|
-
* ```
|
|
4582
|
+
* ```
|
|
4555
4583
|
* const flow = new AxFlow<{ topic: string }, { finalAnswer: string }>()
|
|
4556
4584
|
* .node('summarizer', 'text:string -> summary:string')
|
|
4557
4585
|
* .node('critic', 'summary:string -> critique:string')
|
|
@@ -4656,7 +4684,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4656
4684
|
* @returns New AxFlow instance with updated TNodes type
|
|
4657
4685
|
*
|
|
4658
4686
|
* @example
|
|
4659
|
-
* ```
|
|
4687
|
+
* ```
|
|
4660
4688
|
* flow.node('summarizer', 'text:string -> summary:string')
|
|
4661
4689
|
* flow.node('analyzer', 'text:string -> analysis:string, confidence:number', { debug: true })
|
|
4662
4690
|
* ```
|
|
@@ -4675,7 +4703,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4675
4703
|
* @returns New AxFlow instance with updated TNodes type
|
|
4676
4704
|
*
|
|
4677
4705
|
* @example
|
|
4678
|
-
* ```
|
|
4706
|
+
* ```
|
|
4679
4707
|
* const sig = new AxSignature('text:string -> summary:string')
|
|
4680
4708
|
* flow.node('summarizer', sig, { temperature: 0.1 })
|
|
4681
4709
|
* ```
|
|
@@ -4693,7 +4721,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4693
4721
|
* @returns New AxFlow instance with updated TNodes type
|
|
4694
4722
|
*
|
|
4695
4723
|
* @example
|
|
4696
|
-
* ```
|
|
4724
|
+
* ```
|
|
4697
4725
|
* class CustomProgram extends AxProgram<{ input: string }, { output: string }> {
|
|
4698
4726
|
* async forward(ai, values) { return { output: values.input.toUpperCase() } }
|
|
4699
4727
|
* }
|
|
@@ -4739,7 +4767,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4739
4767
|
* @returns New AxFlow instance with updated TState type
|
|
4740
4768
|
*
|
|
4741
4769
|
* @example
|
|
4742
|
-
* ```
|
|
4770
|
+
* ```
|
|
4743
4771
|
* flow.map(state => ({ ...state, processedText: state.text.toLowerCase() }))
|
|
4744
4772
|
* ```
|
|
4745
4773
|
*/
|
|
@@ -4754,7 +4782,7 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4754
4782
|
* @returns New AxFlow instance with updated TState type
|
|
4755
4783
|
*
|
|
4756
4784
|
* @example
|
|
4757
|
-
* ```
|
|
4785
|
+
* ```
|
|
4758
4786
|
* // Parallel map with multiple transforms
|
|
4759
4787
|
* flow.map([
|
|
4760
4788
|
* state => ({ ...state, result1: processA(state.data) }),
|
|
@@ -4975,6 +5003,31 @@ TState extends AxFlowState = IN> implements AxFlowable<IN, OUT> {
|
|
|
4975
5003
|
* Short alias for endWhile()
|
|
4976
5004
|
*/
|
|
4977
5005
|
end(): this;
|
|
5006
|
+
/**
|
|
5007
|
+
* Derives a new field from an existing field by applying a transform function.
|
|
5008
|
+
*
|
|
5009
|
+
* If the input field contains an array, the transform function is applied to each
|
|
5010
|
+
* array element in parallel with batch size control. If the input field contains
|
|
5011
|
+
* a scalar value, the transform function is applied directly.
|
|
5012
|
+
*
|
|
5013
|
+
* @param outputFieldName - Name of the field to store the result
|
|
5014
|
+
* @param inputFieldName - Name of the existing field to transform
|
|
5015
|
+
* @param transformFn - Function to apply to each element (for arrays) or the value directly (for scalars)
|
|
5016
|
+
* @param options - Options including batch size for parallel processing
|
|
5017
|
+
* @returns this (for chaining)
|
|
5018
|
+
*
|
|
5019
|
+
* @example
|
|
5020
|
+
* ```typescript
|
|
5021
|
+
* // Parallel processing of array items
|
|
5022
|
+
* flow.derive('processedItems', 'items', (item, index) => processItem(item), { batchSize: 5 })
|
|
5023
|
+
*
|
|
5024
|
+
* // Direct transformation of scalar value
|
|
5025
|
+
* flow.derive('upperText', 'text', (text) => text.toUpperCase())
|
|
5026
|
+
* ```
|
|
5027
|
+
*/
|
|
5028
|
+
derive<T>(outputFieldName: string, inputFieldName: string, transformFn: (value: any, index?: number, state?: TState) => T, options?: {
|
|
5029
|
+
batchSize?: number;
|
|
5030
|
+
}): this;
|
|
4978
5031
|
/**
|
|
4979
5032
|
* Gets execution plan information for debugging automatic parallelization
|
|
4980
5033
|
*
|