@ax-llm/ax 12.0.21 → 12.0.22

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.d.cts CHANGED
@@ -3717,6 +3717,25 @@ TState extends AxFlowState = IN> extends AxProgramWithSignature<IN, OUT> {
3717
3717
  [K in TName]: InferAxGen<TSig>;
3718
3718
  }, // Add new node to registry
3719
3719
  TState>;
3720
+ /**
3721
+ * Declares a reusable computational node using an AxSignature instance.
3722
+ * This allows using pre-configured signatures in the flow.
3723
+ *
3724
+ * @param name - The name of the node
3725
+ * @param signature - AxSignature instance to use for this node
3726
+ * @param options - Optional program forward options (same as AxGen)
3727
+ * @returns New AxFlow instance with updated TNodes type
3728
+ *
3729
+ * @example
3730
+ * ```typescript
3731
+ * const sig = new AxSignature('text:string -> summary:string')
3732
+ * flow.node('summarizer', sig, { temperature: 0.1 })
3733
+ * ```
3734
+ */
3735
+ node<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3736
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
3737
+ }, // Add new node to registry
3738
+ TState>;
3720
3739
  /**
3721
3740
  * Declares a reusable computational node using an existing AxGen instance.
3722
3741
  * This allows reusing pre-configured generators in the flow.
@@ -3736,14 +3755,40 @@ TState extends AxFlowState = IN> extends AxProgramWithSignature<IN, OUT> {
3736
3755
  }, // Add new node to registry with exact type
3737
3756
  TState>;
3738
3757
  /**
3739
- * Short alias for node() - supports both signature strings and AxGen instances
3758
+ * Declares a reusable computational node using a class that extends AxProgramWithSignature.
3759
+ * This allows using custom program classes in the flow.
3760
+ *
3761
+ * @param name - The name of the node
3762
+ * @param programClass - Class that extends AxProgramWithSignature to use for this node
3763
+ * @returns New AxFlow instance with updated TNodes type
3764
+ *
3765
+ * @example
3766
+ * ```typescript
3767
+ * class CustomProgram extends AxProgramWithSignature<{ input: string }, { output: string }> {
3768
+ * async forward(ai, values) { return { output: values.input.toUpperCase() } }
3769
+ * }
3770
+ * flow.node('custom', CustomProgram)
3771
+ * ```
3772
+ */
3773
+ node<TName extends string, TProgram extends new () => AxProgramWithSignature<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
3774
+ [K in TName]: InstanceType<TProgram>;
3775
+ }, // Add new node to registry with exact type
3776
+ TState>;
3777
+ /**
3778
+ * Short alias for node() - supports signature strings, AxSignature instances, AxGen instances, and program classes
3740
3779
  */
3741
3780
  n<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3742
3781
  [K in TName]: InferAxGen<TSig>;
3743
3782
  }, TState>;
3783
+ n<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3784
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
3785
+ }, TState>;
3744
3786
  n<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
3745
3787
  [K in TName]: TGen;
3746
3788
  }, TState>;
3789
+ n<TName extends string, TProgram extends new () => AxProgramWithSignature<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
3790
+ [K in TName]: InstanceType<TProgram>;
3791
+ }, TState>;
3747
3792
  /**
3748
3793
  * Applies a synchronous transformation to the state object.
3749
3794
  * Returns a new AxFlow type with the evolved state.
@@ -3951,7 +3996,7 @@ TState extends AxFlowState = IN> extends AxProgramWithSignature<IN, OUT> {
3951
3996
  declare class AxFlowTypedSubContextImpl<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> implements AxFlowTypedSubContext<TNodes, TState> {
3952
3997
  private readonly nodeGenerators;
3953
3998
  private readonly steps;
3954
- constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut>>);
3999
+ constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut> | AxProgramWithSignature<AxGenIn, AxGenOut>>);
3955
4000
  execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
3956
4001
  map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
3957
4002
  executeSteps(initialState: TState, context: Readonly<{
package/index.d.ts CHANGED
@@ -3717,6 +3717,25 @@ TState extends AxFlowState = IN> extends AxProgramWithSignature<IN, OUT> {
3717
3717
  [K in TName]: InferAxGen<TSig>;
3718
3718
  }, // Add new node to registry
3719
3719
  TState>;
3720
+ /**
3721
+ * Declares a reusable computational node using an AxSignature instance.
3722
+ * This allows using pre-configured signatures in the flow.
3723
+ *
3724
+ * @param name - The name of the node
3725
+ * @param signature - AxSignature instance to use for this node
3726
+ * @param options - Optional program forward options (same as AxGen)
3727
+ * @returns New AxFlow instance with updated TNodes type
3728
+ *
3729
+ * @example
3730
+ * ```typescript
3731
+ * const sig = new AxSignature('text:string -> summary:string')
3732
+ * flow.node('summarizer', sig, { temperature: 0.1 })
3733
+ * ```
3734
+ */
3735
+ node<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3736
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
3737
+ }, // Add new node to registry
3738
+ TState>;
3720
3739
  /**
3721
3740
  * Declares a reusable computational node using an existing AxGen instance.
3722
3741
  * This allows reusing pre-configured generators in the flow.
@@ -3736,14 +3755,40 @@ TState extends AxFlowState = IN> extends AxProgramWithSignature<IN, OUT> {
3736
3755
  }, // Add new node to registry with exact type
3737
3756
  TState>;
3738
3757
  /**
3739
- * Short alias for node() - supports both signature strings and AxGen instances
3758
+ * Declares a reusable computational node using a class that extends AxProgramWithSignature.
3759
+ * This allows using custom program classes in the flow.
3760
+ *
3761
+ * @param name - The name of the node
3762
+ * @param programClass - Class that extends AxProgramWithSignature to use for this node
3763
+ * @returns New AxFlow instance with updated TNodes type
3764
+ *
3765
+ * @example
3766
+ * ```typescript
3767
+ * class CustomProgram extends AxProgramWithSignature<{ input: string }, { output: string }> {
3768
+ * async forward(ai, values) { return { output: values.input.toUpperCase() } }
3769
+ * }
3770
+ * flow.node('custom', CustomProgram)
3771
+ * ```
3772
+ */
3773
+ node<TName extends string, TProgram extends new () => AxProgramWithSignature<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
3774
+ [K in TName]: InstanceType<TProgram>;
3775
+ }, // Add new node to registry with exact type
3776
+ TState>;
3777
+ /**
3778
+ * Short alias for node() - supports signature strings, AxSignature instances, AxGen instances, and program classes
3740
3779
  */
3741
3780
  n<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3742
3781
  [K in TName]: InferAxGen<TSig>;
3743
3782
  }, TState>;
3783
+ n<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3784
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
3785
+ }, TState>;
3744
3786
  n<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
3745
3787
  [K in TName]: TGen;
3746
3788
  }, TState>;
3789
+ n<TName extends string, TProgram extends new () => AxProgramWithSignature<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
3790
+ [K in TName]: InstanceType<TProgram>;
3791
+ }, TState>;
3747
3792
  /**
3748
3793
  * Applies a synchronous transformation to the state object.
3749
3794
  * Returns a new AxFlow type with the evolved state.
@@ -3951,7 +3996,7 @@ TState extends AxFlowState = IN> extends AxProgramWithSignature<IN, OUT> {
3951
3996
  declare class AxFlowTypedSubContextImpl<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> implements AxFlowTypedSubContext<TNodes, TState> {
3952
3997
  private readonly nodeGenerators;
3953
3998
  private readonly steps;
3954
- constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut>>);
3999
+ constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut> | AxProgramWithSignature<AxGenIn, AxGenOut>>);
3955
4000
  execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
3956
4001
  map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
3957
4002
  executeSteps(initialState: TState, context: Readonly<{
package/index.js CHANGED
@@ -15008,18 +15008,31 @@ var AxFlow = class extends AxProgramWithSignature {
15008
15008
  super(signature);
15009
15009
  }
15010
15010
  // Implementation
15011
- node(name, signatureOrAxGen, options) {
15012
- if (signatureOrAxGen instanceof AxGen) {
15011
+ node(name, signatureOrAxGenOrClass, options) {
15012
+ if (signatureOrAxGenOrClass instanceof AxGen) {
15013
15013
  this.nodes.set(name, {
15014
15014
  inputs: {},
15015
15015
  outputs: {}
15016
15016
  });
15017
15017
  this.nodeGenerators.set(
15018
15018
  name,
15019
- signatureOrAxGen
15019
+ signatureOrAxGenOrClass
15020
15020
  );
15021
- } else {
15022
- const signature = signatureOrAxGen;
15021
+ } else if (signatureOrAxGenOrClass instanceof AxSignature) {
15022
+ this.nodes.set(name, {
15023
+ inputs: {},
15024
+ outputs: {}
15025
+ });
15026
+ this.nodeGenerators.set(name, new AxGen(signatureOrAxGenOrClass, options));
15027
+ } else if (typeof signatureOrAxGenOrClass === "function" && signatureOrAxGenOrClass.prototype instanceof AxProgramWithSignature) {
15028
+ this.nodes.set(name, {
15029
+ inputs: {},
15030
+ outputs: {}
15031
+ });
15032
+ const programInstance = new signatureOrAxGenOrClass();
15033
+ this.nodeGenerators.set(name, programInstance);
15034
+ } else if (typeof signatureOrAxGenOrClass === "string") {
15035
+ const signature = signatureOrAxGenOrClass;
15023
15036
  if (!signature) {
15024
15037
  throw new Error(
15025
15038
  `Invalid signature for node '${name}': signature cannot be empty`
@@ -15030,11 +15043,15 @@ var AxFlow = class extends AxProgramWithSignature {
15030
15043
  outputs: {}
15031
15044
  });
15032
15045
  this.nodeGenerators.set(name, new AxGen(signature, options));
15046
+ } else {
15047
+ throw new Error(
15048
+ `Invalid second argument for node '${name}': expected string, AxSignature, AxGen instance, or class extending AxProgramWithSignature`
15049
+ );
15033
15050
  }
15034
15051
  return this;
15035
15052
  }
15036
- n(name, signatureOrAxGen, options) {
15037
- return this.node(name, signatureOrAxGen, options);
15053
+ n(name, signatureOrAxGenOrClass, options) {
15054
+ return this.node(name, signatureOrAxGenOrClass, options);
15038
15055
  }
15039
15056
  /**
15040
15057
  * Applies a synchronous transformation to the state object.
@@ -15117,15 +15134,15 @@ var AxFlow = class extends AxProgramWithSignature {
15117
15134
  `Node '${nodeName}' not found. Make sure to define it with .node() first.`
15118
15135
  );
15119
15136
  }
15120
- const nodeGenerator = this.nodeGenerators.get(nodeName);
15121
- if (!nodeGenerator) {
15122
- throw new Error(`Node generator for '${nodeName}' not found.`);
15137
+ const nodeProgram = this.nodeGenerators.get(nodeName);
15138
+ if (!nodeProgram) {
15139
+ throw new Error(`Node program for '${nodeName}' not found.`);
15123
15140
  }
15124
15141
  const step = async (state, context3) => {
15125
15142
  const ai = dynamicContext?.ai ?? context3.mainAi;
15126
15143
  const options = dynamicContext?.options ?? context3.mainOptions;
15127
15144
  const nodeInputs = mapping(state);
15128
- const result = await nodeGenerator.forward(ai, nodeInputs, options);
15145
+ const result = await nodeProgram.forward(ai, nodeInputs, options);
15129
15146
  return {
15130
15147
  ...state,
15131
15148
  [`${nodeName}Result`]: result
@@ -15459,15 +15476,15 @@ var AxFlowSubContextImpl = class {
15459
15476
  }
15460
15477
  steps = [];
15461
15478
  execute(nodeName, mapping, dynamicContext) {
15462
- const nodeGenerator = this.nodeGenerators.get(nodeName);
15463
- if (!nodeGenerator) {
15464
- throw new Error(`Node generator for '${nodeName}' not found.`);
15479
+ const nodeProgram = this.nodeGenerators.get(nodeName);
15480
+ if (!nodeProgram) {
15481
+ throw new Error(`Node program for '${nodeName}' not found.`);
15465
15482
  }
15466
15483
  this.steps.push(async (state, context3) => {
15467
15484
  const ai = dynamicContext?.ai ?? context3.mainAi;
15468
15485
  const options = dynamicContext?.options ?? context3.mainOptions;
15469
15486
  const nodeInputs = mapping(state);
15470
- const result = await nodeGenerator.forward(ai, nodeInputs, options);
15487
+ const result = await nodeProgram.forward(ai, nodeInputs, options);
15471
15488
  return {
15472
15489
  ...state,
15473
15490
  [`${nodeName}Result`]: result
@@ -15493,15 +15510,15 @@ var AxFlowTypedSubContextImpl = class {
15493
15510
  }
15494
15511
  steps = [];
15495
15512
  execute(nodeName, mapping, dynamicContext) {
15496
- const nodeGenerator = this.nodeGenerators.get(nodeName);
15497
- if (!nodeGenerator) {
15498
- throw new Error(`Node generator for '${nodeName}' not found.`);
15513
+ const nodeProgram = this.nodeGenerators.get(nodeName);
15514
+ if (!nodeProgram) {
15515
+ throw new Error(`Node program for '${nodeName}' not found.`);
15499
15516
  }
15500
15517
  this.steps.push(async (state, context3) => {
15501
15518
  const ai = dynamicContext?.ai ?? context3.mainAi;
15502
15519
  const options = dynamicContext?.options ?? context3.mainOptions;
15503
15520
  const nodeInputs = mapping(state);
15504
- const result = await nodeGenerator.forward(ai, nodeInputs, options);
15521
+ const result = await nodeProgram.forward(ai, nodeInputs, options);
15505
15522
  return {
15506
15523
  ...state,
15507
15524
  [`${nodeName}Result`]: result