@ax-llm/ax 10.0.41 → 10.0.42

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
@@ -4878,9 +4878,6 @@ var checkMissingRequiredFields = (xstate, values, currentIndex) => {
4878
4878
  }
4879
4879
  };
4880
4880
  var streamingExtractValues = (sig, values, xstate, content) => {
4881
- if (content.endsWith("\n")) {
4882
- return true;
4883
- }
4884
4881
  const fields = sig.getOutputFields();
4885
4882
  for (const [index, field] of fields.entries()) {
4886
4883
  if (field.name in values) {
@@ -4896,10 +4893,6 @@ var streamingExtractValues = (sig, values, xstate, content) => {
4896
4893
  return true;
4897
4894
  }
4898
4895
  let prefixLen = prefix.length;
4899
- if (e - 1 >= 0 && content[e - 1] === "\n") {
4900
- e -= 1;
4901
- prefixLen += 1;
4902
- }
4903
4896
  if (xstate.currField) {
4904
4897
  const val = content.substring(xstate.s, e).trim();
4905
4898
  const parsedValue = validateAndParseFieldValue(xstate.currField, val);
@@ -4966,7 +4959,7 @@ var convertValueToType = (field, val) => {
4966
4959
  return val;
4967
4960
  }
4968
4961
  };
4969
- function* streamValues(sig, values, xstate, content) {
4962
+ function* streamValues(sig, values, xstate, content, final = false) {
4970
4963
  if (!xstate.currField) {
4971
4964
  return;
4972
4965
  }
@@ -4974,13 +4967,17 @@ function* streamValues(sig, values, xstate, content) {
4974
4967
  if (!xstate.streamedIndex) {
4975
4968
  xstate.streamedIndex = { [fieldName]: 0 };
4976
4969
  }
4977
- if (!xstate.currField.type || !xstate.currField.type.isArray && xstate.currField.type.name === "string") {
4978
- const pos = xstate.streamedIndex[fieldName] ?? 0;
4979
- const s = xstate.s + pos;
4980
- const v = content.substring(s);
4981
- yield { [fieldName]: pos === 0 ? v.trimStart() : v };
4982
- xstate.streamedIndex[fieldName] = pos + v.length;
4983
- return;
4970
+ if (!final) {
4971
+ if (!xstate.currField.type || !xstate.currField.type.isArray && xstate.currField.type.name === "string") {
4972
+ const pos = xstate.streamedIndex[fieldName] ?? 0;
4973
+ const s = xstate.s + pos;
4974
+ const v = content.substring(s);
4975
+ const v1 = v.replace(/[\s\n\t]+$/, "");
4976
+ const v2 = pos === 0 ? v1.trimStart() : v1;
4977
+ yield { [fieldName]: v2 };
4978
+ xstate.streamedIndex[fieldName] = pos + v1.length;
4979
+ return;
4980
+ }
4984
4981
  }
4985
4982
  for (const key of Object.keys(values)) {
4986
4983
  const value = values[key];
@@ -5406,6 +5403,7 @@ var AxGen = class extends AxProgramWithSignature {
5406
5403
  );
5407
5404
  this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
5408
5405
  }
5406
+ streamingExtractFinalValue(this.signature, values, xstate, content);
5409
5407
  assertStreamingAssertions(
5410
5408
  this.streamingAsserts,
5411
5409
  values,
@@ -5413,9 +5411,8 @@ var AxGen = class extends AxProgramWithSignature {
5413
5411
  content,
5414
5412
  true
5415
5413
  );
5416
- streamingExtractFinalValue(this.signature, values, xstate, content);
5417
5414
  assertAssertions(this.asserts, values);
5418
- yield* streamValues(this.signature, values, xstate, content);
5415
+ yield* streamValues(this.signature, values, xstate, content, true);
5419
5416
  }
5420
5417
  async processResponse({
5421
5418
  ai,