@ax-llm/ax 11.0.32 → 11.0.34

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
@@ -1488,6 +1488,7 @@ declare class AxFunctionError extends Error {
1488
1488
  field: string;
1489
1489
  message: string;
1490
1490
  }[];
1491
+ toString(): string;
1491
1492
  }
1492
1493
  type AxChatResponseFunctionCall = {
1493
1494
  id: string;
@@ -1671,6 +1672,7 @@ declare class AxAssertionError extends Error {
1671
1672
  title: string;
1672
1673
  description: string;
1673
1674
  }[];
1675
+ toString(): string;
1674
1676
  }
1675
1677
 
1676
1678
  type AxFieldProcessorProcess = (value: AxFieldValue, context?: Readonly<{
package/index.d.ts CHANGED
@@ -1488,6 +1488,7 @@ declare class AxFunctionError extends Error {
1488
1488
  field: string;
1489
1489
  message: string;
1490
1490
  }[];
1491
+ toString(): string;
1491
1492
  }
1492
1493
  type AxChatResponseFunctionCall = {
1493
1494
  id: string;
@@ -1671,6 +1672,7 @@ declare class AxAssertionError extends Error {
1671
1672
  title: string;
1672
1673
  description: string;
1673
1674
  }[];
1675
+ toString(): string;
1674
1676
  }
1675
1677
 
1676
1678
  type AxFieldProcessorProcess = (value: AxFieldValue, context?: Readonly<{
package/index.js CHANGED
@@ -3984,6 +3984,12 @@ var AxAssertionError = class extends Error {
3984
3984
  });
3985
3985
  return extraFields;
3986
3986
  };
3987
+ toString() {
3988
+ return `${this.name}: ${this.message}`;
3989
+ }
3990
+ [Symbol.for("nodejs.util.inspect.custom")](_depth, _options) {
3991
+ return this.toString();
3992
+ }
3987
3993
  };
3988
3994
  var assertAssertions = async (asserts, values) => {
3989
3995
  for (const assert of asserts) {
@@ -4767,6 +4773,9 @@ function matchesContent(content, prefix, startIndex = 0, prefixCache = globalPre
4767
4773
  );
4768
4774
  for (let i = 0; i < prefixes.length - 1; i++) {
4769
4775
  const partialPrefix = prefixes[i];
4776
+ if (partialPrefix === "\n" || partialPrefix === ":") {
4777
+ continue;
4778
+ }
4770
4779
  if (partialPrefix && contentEnd.endsWith(partialPrefix)) {
4771
4780
  return -2;
4772
4781
  }
@@ -5421,6 +5430,17 @@ var ValidationError = class extends Error {
5421
5430
  description: `The section labeled '${field.title}' either was not generated by the LLM or does not match the expected format of '${toFieldType(field.type)}'. ${this.message} Please revise your response to ensure it conforms to the specified format.`
5422
5431
  }));
5423
5432
  };
5433
+ toString() {
5434
+ return [
5435
+ `${this.name}: ${this.message}`,
5436
+ ...this.fields.map(
5437
+ (field) => ` - ${field.title}: Expected format '${toFieldType(field.type)}'`
5438
+ )
5439
+ ].join("\n");
5440
+ }
5441
+ [Symbol.for("nodejs.util.inspect.custom")](_depth, _options) {
5442
+ return this.toString();
5443
+ }
5424
5444
  };
5425
5445
  function handleValidationError(mem, errorFields, ai, promptTemplate, sessionId) {
5426
5446
  mem.add(
@@ -5538,7 +5558,7 @@ var streamingExtractValues = (sig, values, xstate, content, streamingValidation
5538
5558
  }
5539
5559
  const isFirst = xstate.extractedFields.length === 0;
5540
5560
  const prefix = (isFirst ? "" : "\n") + field.title + ":";
5541
- let e = matchesContent(content, prefix, xstate.s === 0 ? 0 : xstate.s + 1);
5561
+ let e = matchesContent(content, prefix, xstate.s);
5542
5562
  switch (e) {
5543
5563
  case -1:
5544
5564
  if (streamingValidation && values.length == 0 && !field.isOptional) {
@@ -5904,6 +5924,15 @@ var AxFunctionError = class extends Error {
5904
5924
  this.name = this.constructor.name;
5905
5925
  }
5906
5926
  getFields = () => this.fields;
5927
+ toString() {
5928
+ return [
5929
+ `${this.name}: Function validation error`,
5930
+ ...this.fields.map((field) => ` - ${field.field}: ${field.message}`)
5931
+ ].join("\n");
5932
+ }
5933
+ [Symbol.for("nodejs.util.inspect.custom")](_depth, _options) {
5934
+ return this.toString();
5935
+ }
5907
5936
  };
5908
5937
  var FunctionError = class extends Error {
5909
5938
  constructor(fields, func, funcId) {
@@ -5932,6 +5961,19 @@ var FunctionError = class extends Error {
5932
5961
  return `Errors In Function Arguments: Fix the following invalid arguments to '${this.func.name}'
5933
5962
  ${bulletPoints.join("\n")}`;
5934
5963
  };
5964
+ toString() {
5965
+ return [
5966
+ `${this.name}: Function execution error in '${this.func.name}'`,
5967
+ ...this.fields.map((field) => {
5968
+ const description = this.getFieldDescription(field.field);
5969
+ return ` - ${field.field}: ${field.message}${description ? ` (${description})` : ""}`;
5970
+ }),
5971
+ this.funcId ? ` Function ID: ${this.funcId}` : ""
5972
+ ].join("\n");
5973
+ }
5974
+ [Symbol.for("nodejs.util.inspect.custom")](_depth, _options) {
5975
+ return this.toString();
5976
+ }
5935
5977
  };
5936
5978
  var AxFunctionProcessor = class {
5937
5979
  funcList = [];
@@ -6446,7 +6488,7 @@ var AxGen = class extends AxProgramWithSignature {
6446
6488
  }
6447
6489
  }
6448
6490
  }
6449
- throw new Error(`Unable to fix validation error: ${err?.message}`);
6491
+ throw new Error(`Unable to fix validation error: ${err?.toString()}`);
6450
6492
  }
6451
6493
  throw new Error(`Max steps reached: ${maxSteps}`);
6452
6494
  }