@ax-llm/ax 10.0.47 → 10.0.48

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
@@ -84,6 +84,7 @@ __export(index_exports, {
84
84
  AxDefaultResultReranker: () => AxDefaultResultReranker,
85
85
  AxDockerSession: () => AxDockerSession,
86
86
  AxEmbeddingAdapter: () => AxEmbeddingAdapter,
87
+ AxFunctionError: () => AxFunctionError,
87
88
  AxFunctionProcessor: () => AxFunctionProcessor,
88
89
  AxGen: () => AxGen,
89
90
  AxHFDataLoader: () => AxHFDataLoader,
@@ -319,7 +320,7 @@ var AxAIServiceError = class extends Error {
319
320
  super(message);
320
321
  this.url = url;
321
322
  this.requestBody = requestBody;
322
- this.name = "AxAIServiceError";
323
+ this.name = this.constructor.name;
323
324
  this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
324
325
  this.errorId = crypto.randomUUID();
325
326
  this.context = context;
@@ -356,7 +357,7 @@ var AxAIServiceStatusError = class extends AxAIServiceError {
356
357
  });
357
358
  this.status = status;
358
359
  this.statusText = statusText;
359
- this.name = "AxAIServiceStatusError";
360
+ this.name = this.constructor.name;
360
361
  }
361
362
  };
362
363
  var AxAIServiceNetworkError = class extends AxAIServiceError {
@@ -367,14 +368,14 @@ var AxAIServiceNetworkError = class extends AxAIServiceError {
367
368
  ...context
368
369
  });
369
370
  this.originalError = originalError;
370
- this.name = "AxAIServiceNetworkError";
371
+ this.name = this.constructor.name;
371
372
  this.stack = originalError.stack;
372
373
  }
373
374
  };
374
375
  var AxAIServiceResponseError = class extends AxAIServiceError {
375
376
  constructor(message, url, requestBody, context) {
376
377
  super(message, url, requestBody, context);
377
- this.name = "AxAIServiceResponseError";
378
+ this.name = this.constructor.name;
378
379
  }
379
380
  };
380
381
  var AxAIServiceStreamTerminatedError = class extends AxAIServiceError {
@@ -384,7 +385,7 @@ var AxAIServiceStreamTerminatedError = class extends AxAIServiceError {
384
385
  ...context
385
386
  });
386
387
  this.lastChunk = lastChunk;
387
- this.name = "AxAIServiceStreamTerminatedError";
388
+ this.name = this.constructor.name;
388
389
  }
389
390
  };
390
391
  var AxAIServiceTimeoutError = class extends AxAIServiceError {
@@ -393,13 +394,13 @@ var AxAIServiceTimeoutError = class extends AxAIServiceError {
393
394
  timeoutMs,
394
395
  ...context
395
396
  });
396
- this.name = "AxAIServiceTimeoutError";
397
+ this.name = this.constructor.name;
397
398
  }
398
399
  };
399
400
  var AxAIServiceAuthenticationError = class extends AxAIServiceError {
400
401
  constructor(url, requestBody, context) {
401
402
  super("Authentication failed", url, requestBody, context);
402
- this.name = "AxAIServiceAuthenticationError";
403
+ this.name = this.constructor.name;
403
404
  }
404
405
  };
405
406
  function calculateRetryDelay(attempt, config) {
@@ -3817,21 +3818,13 @@ var AxMemory = class {
3817
3818
 
3818
3819
  // dsp/asserts.ts
3819
3820
  var AxAssertionError = class extends Error {
3820
- values;
3821
- optional;
3822
3821
  constructor({
3823
- message,
3824
- values,
3825
- optional
3822
+ message
3826
3823
  }) {
3827
3824
  super(message);
3828
- this.values = values;
3829
- this.optional = optional;
3830
3825
  this.name = this.constructor.name;
3831
3826
  this.stack = new Error().stack;
3832
3827
  }
3833
- getValue = () => this.values;
3834
- getOptional = () => this.optional;
3835
3828
  getFixingInstructions = () => {
3836
3829
  const extraFields = [];
3837
3830
  extraFields.push({
@@ -3844,13 +3837,16 @@ var AxAssertionError = class extends Error {
3844
3837
  };
3845
3838
  var assertAssertions = (asserts, values) => {
3846
3839
  for (const assert of asserts) {
3847
- const { fn, message, optional } = assert;
3840
+ const { fn, message } = assert;
3848
3841
  const res = fn(values);
3849
3842
  if (res === void 0) {
3850
3843
  continue;
3851
3844
  }
3852
- if (!res && message) {
3853
- throw new AxAssertionError({ message, values, optional });
3845
+ if (!res) {
3846
+ if (!message) {
3847
+ throw new Error(`Assertion Failed: No message provided for assertion`);
3848
+ }
3849
+ throw new AxAssertionError({ message });
3854
3850
  }
3855
3851
  }
3856
3852
  };
@@ -3866,13 +3862,13 @@ var assertStreamingAssertions = (asserts, values, xstate, content, final) => {
3866
3862
  }
3867
3863
  const currValue = content.substring(xstate.s);
3868
3864
  for (const assert of fieldAsserts) {
3869
- const { message, optional, fn } = assert;
3865
+ const { message, fn } = assert;
3870
3866
  const res = fn(currValue, final);
3871
3867
  if (res === void 0) {
3872
3868
  continue;
3873
3869
  }
3874
3870
  if (!res && message) {
3875
- throw new AxAssertionError({ message, values, optional });
3871
+ throw new AxAssertionError({ message });
3876
3872
  }
3877
3873
  }
3878
3874
  };
@@ -5126,13 +5122,11 @@ var ValidationError = class extends Error {
5126
5122
  super(message);
5127
5123
  this.fields = fields;
5128
5124
  this.name = this.constructor.name;
5129
- Error.captureStackTrace(this, this.constructor);
5130
5125
  }
5131
- getFields = () => this.fields;
5132
5126
  getFixingInstructions = () => {
5133
5127
  return this.fields.map((field) => ({
5134
5128
  name: "outputError",
5135
- title: "Error In Output",
5129
+ title: "Errors In Output Fields",
5136
5130
  description: `Please fix and return the field \`${field.title}\` of type \`${toFieldType(field.type)}\`, ${this.message}.`
5137
5131
  }));
5138
5132
  };
@@ -5490,6 +5484,49 @@ var validateJSONSchema = (schema) => {
5490
5484
  };
5491
5485
 
5492
5486
  // dsp/functions.ts
5487
+ var AxFunctionError = class extends Error {
5488
+ constructor(fields) {
5489
+ super();
5490
+ this.fields = fields;
5491
+ this.name = this.constructor.name;
5492
+ }
5493
+ getFields = () => this.fields;
5494
+ };
5495
+ var FunctionError = class extends Error {
5496
+ fields;
5497
+ func;
5498
+ constructor({
5499
+ fields,
5500
+ func
5501
+ }) {
5502
+ super();
5503
+ this.fields = fields;
5504
+ this.func = func;
5505
+ this.name = this.constructor.name;
5506
+ }
5507
+ getFieldDescription(fieldName) {
5508
+ if (!this.func.parameters?.properties?.[fieldName]) {
5509
+ return "";
5510
+ }
5511
+ const fieldSchema = this.func.parameters.properties[fieldName];
5512
+ let description = fieldSchema.description;
5513
+ if (fieldSchema.enum?.length) {
5514
+ description += ` Allowed values are: ${fieldSchema.enum.join(", ")}`;
5515
+ }
5516
+ return description;
5517
+ }
5518
+ getFixingInstructions = () => {
5519
+ return this.fields.map((fieldError) => {
5520
+ const schemaDescription = this.getFieldDescription(fieldError.field);
5521
+ const fullDescription = schemaDescription ? `${fieldError.message}. ${schemaDescription}` : fieldError.message;
5522
+ return {
5523
+ name: "functionArgumentError",
5524
+ title: `Errors in Function '${this.func.name}' Arguments`,
5525
+ description: `Please fix the argument '${fieldError.field}' in function '${this.func.name}': ${fullDescription}`
5526
+ };
5527
+ });
5528
+ };
5529
+ };
5493
5530
  var AxFunctionProcessor = class {
5494
5531
  funcList = [];
5495
5532
  constructor(funcList) {
@@ -5530,7 +5567,17 @@ var AxFunctionProcessor = class {
5530
5567
  if (!fnSpec.func) {
5531
5568
  throw new Error("No handler for function: " + func.name);
5532
5569
  }
5533
- return await this.executeFunction(fnSpec, func, options);
5570
+ try {
5571
+ return await this.executeFunction(fnSpec, func, options);
5572
+ } catch (e) {
5573
+ if (e instanceof AxFunctionError) {
5574
+ throw new FunctionError({
5575
+ fields: e.getFields(),
5576
+ func: fnSpec
5577
+ });
5578
+ }
5579
+ throw e;
5580
+ }
5534
5581
  };
5535
5582
  };
5536
5583
  var parseFunctions = (newFuncs, existingFuncs) => {
@@ -5609,11 +5656,11 @@ var AxGen = class extends AxProgramWithSignature {
5609
5656
  this.functions = parseFunctions(options.functions);
5610
5657
  }
5611
5658
  }
5612
- addAssert = (fn, message, optional) => {
5613
- this.asserts.push({ fn, message, optional });
5659
+ addAssert = (fn, message) => {
5660
+ this.asserts.push({ fn, message });
5614
5661
  };
5615
- addStreamingAssert = (fieldName, fn, message, optional) => {
5616
- this.streamingAsserts.push({ fieldName, fn, message, optional });
5662
+ addStreamingAssert = (fieldName, fn, message) => {
5663
+ this.streamingAsserts.push({ fieldName, fn, message });
5617
5664
  };
5618
5665
  async forwardSendRequest({
5619
5666
  ai,
@@ -5863,6 +5910,9 @@ var AxGen = class extends AxProgramWithSignature {
5863
5910
  const e1 = e;
5864
5911
  errorFields = e1.getFixingInstructions();
5865
5912
  err = e;
5913
+ } else if (e instanceof FunctionError) {
5914
+ errorFields = e.getFixingInstructions();
5915
+ err = e;
5866
5916
  } else if (e instanceof AxAIServiceStreamTerminatedError) {
5867
5917
  } else {
5868
5918
  throw e;
@@ -5878,9 +5928,6 @@ var AxGen = class extends AxProgramWithSignature {
5878
5928
  }
5879
5929
  }
5880
5930
  }
5881
- if (err instanceof AxAssertionError && err.getOptional()) {
5882
- return err.getValue();
5883
- }
5884
5931
  throw new Error(`Unable to fix validation error: ${err?.message}`);
5885
5932
  }
5886
5933
  throw new Error(`Max steps reached: ${maxSteps}`);
@@ -7940,6 +7987,7 @@ var AxRAG = class extends AxChainOfThought {
7940
7987
  AxDefaultResultReranker,
7941
7988
  AxDockerSession,
7942
7989
  AxEmbeddingAdapter,
7990
+ AxFunctionError,
7943
7991
  AxFunctionProcessor,
7944
7992
  AxGen,
7945
7993
  AxHFDataLoader,