@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.cjs CHANGED
@@ -15193,18 +15193,31 @@ var AxFlow = class extends AxProgramWithSignature {
15193
15193
  super(signature);
15194
15194
  }
15195
15195
  // Implementation
15196
- node(name, signatureOrAxGen, options) {
15197
- if (signatureOrAxGen instanceof AxGen) {
15196
+ node(name, signatureOrAxGenOrClass, options) {
15197
+ if (signatureOrAxGenOrClass instanceof AxGen) {
15198
15198
  this.nodes.set(name, {
15199
15199
  inputs: {},
15200
15200
  outputs: {}
15201
15201
  });
15202
15202
  this.nodeGenerators.set(
15203
15203
  name,
15204
- signatureOrAxGen
15204
+ signatureOrAxGenOrClass
15205
15205
  );
15206
- } else {
15207
- const signature = signatureOrAxGen;
15206
+ } else if (signatureOrAxGenOrClass instanceof AxSignature) {
15207
+ this.nodes.set(name, {
15208
+ inputs: {},
15209
+ outputs: {}
15210
+ });
15211
+ this.nodeGenerators.set(name, new AxGen(signatureOrAxGenOrClass, options));
15212
+ } else if (typeof signatureOrAxGenOrClass === "function" && signatureOrAxGenOrClass.prototype instanceof AxProgramWithSignature) {
15213
+ this.nodes.set(name, {
15214
+ inputs: {},
15215
+ outputs: {}
15216
+ });
15217
+ const programInstance = new signatureOrAxGenOrClass();
15218
+ this.nodeGenerators.set(name, programInstance);
15219
+ } else if (typeof signatureOrAxGenOrClass === "string") {
15220
+ const signature = signatureOrAxGenOrClass;
15208
15221
  if (!signature) {
15209
15222
  throw new Error(
15210
15223
  `Invalid signature for node '${name}': signature cannot be empty`
@@ -15215,11 +15228,15 @@ var AxFlow = class extends AxProgramWithSignature {
15215
15228
  outputs: {}
15216
15229
  });
15217
15230
  this.nodeGenerators.set(name, new AxGen(signature, options));
15231
+ } else {
15232
+ throw new Error(
15233
+ `Invalid second argument for node '${name}': expected string, AxSignature, AxGen instance, or class extending AxProgramWithSignature`
15234
+ );
15218
15235
  }
15219
15236
  return this;
15220
15237
  }
15221
- n(name, signatureOrAxGen, options) {
15222
- return this.node(name, signatureOrAxGen, options);
15238
+ n(name, signatureOrAxGenOrClass, options) {
15239
+ return this.node(name, signatureOrAxGenOrClass, options);
15223
15240
  }
15224
15241
  /**
15225
15242
  * Applies a synchronous transformation to the state object.
@@ -15302,15 +15319,15 @@ var AxFlow = class extends AxProgramWithSignature {
15302
15319
  `Node '${nodeName}' not found. Make sure to define it with .node() first.`
15303
15320
  );
15304
15321
  }
15305
- const nodeGenerator = this.nodeGenerators.get(nodeName);
15306
- if (!nodeGenerator) {
15307
- throw new Error(`Node generator for '${nodeName}' not found.`);
15322
+ const nodeProgram = this.nodeGenerators.get(nodeName);
15323
+ if (!nodeProgram) {
15324
+ throw new Error(`Node program for '${nodeName}' not found.`);
15308
15325
  }
15309
15326
  const step = async (state, context3) => {
15310
15327
  const ai = dynamicContext?.ai ?? context3.mainAi;
15311
15328
  const options = dynamicContext?.options ?? context3.mainOptions;
15312
15329
  const nodeInputs = mapping(state);
15313
- const result = await nodeGenerator.forward(ai, nodeInputs, options);
15330
+ const result = await nodeProgram.forward(ai, nodeInputs, options);
15314
15331
  return {
15315
15332
  ...state,
15316
15333
  [`${nodeName}Result`]: result
@@ -15644,15 +15661,15 @@ var AxFlowSubContextImpl = class {
15644
15661
  }
15645
15662
  steps = [];
15646
15663
  execute(nodeName, mapping, dynamicContext) {
15647
- const nodeGenerator = this.nodeGenerators.get(nodeName);
15648
- if (!nodeGenerator) {
15649
- throw new Error(`Node generator for '${nodeName}' not found.`);
15664
+ const nodeProgram = this.nodeGenerators.get(nodeName);
15665
+ if (!nodeProgram) {
15666
+ throw new Error(`Node program for '${nodeName}' not found.`);
15650
15667
  }
15651
15668
  this.steps.push(async (state, context3) => {
15652
15669
  const ai = dynamicContext?.ai ?? context3.mainAi;
15653
15670
  const options = dynamicContext?.options ?? context3.mainOptions;
15654
15671
  const nodeInputs = mapping(state);
15655
- const result = await nodeGenerator.forward(ai, nodeInputs, options);
15672
+ const result = await nodeProgram.forward(ai, nodeInputs, options);
15656
15673
  return {
15657
15674
  ...state,
15658
15675
  [`${nodeName}Result`]: result
@@ -15678,15 +15695,15 @@ var AxFlowTypedSubContextImpl = class {
15678
15695
  }
15679
15696
  steps = [];
15680
15697
  execute(nodeName, mapping, dynamicContext) {
15681
- const nodeGenerator = this.nodeGenerators.get(nodeName);
15682
- if (!nodeGenerator) {
15683
- throw new Error(`Node generator for '${nodeName}' not found.`);
15698
+ const nodeProgram = this.nodeGenerators.get(nodeName);
15699
+ if (!nodeProgram) {
15700
+ throw new Error(`Node program for '${nodeName}' not found.`);
15684
15701
  }
15685
15702
  this.steps.push(async (state, context3) => {
15686
15703
  const ai = dynamicContext?.ai ?? context3.mainAi;
15687
15704
  const options = dynamicContext?.options ?? context3.mainOptions;
15688
15705
  const nodeInputs = mapping(state);
15689
- const result = await nodeGenerator.forward(ai, nodeInputs, options);
15706
+ const result = await nodeProgram.forward(ai, nodeInputs, options);
15690
15707
  return {
15691
15708
  ...state,
15692
15709
  [`${nodeName}Result`]: result