@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.js CHANGED
@@ -4783,9 +4783,6 @@ var checkMissingRequiredFields = (xstate, values, currentIndex) => {
4783
4783
  }
4784
4784
  };
4785
4785
  var streamingExtractValues = (sig, values, xstate, content) => {
4786
- if (content.endsWith("\n")) {
4787
- return true;
4788
- }
4789
4786
  const fields = sig.getOutputFields();
4790
4787
  for (const [index, field] of fields.entries()) {
4791
4788
  if (field.name in values) {
@@ -4801,10 +4798,6 @@ var streamingExtractValues = (sig, values, xstate, content) => {
4801
4798
  return true;
4802
4799
  }
4803
4800
  let prefixLen = prefix.length;
4804
- if (e - 1 >= 0 && content[e - 1] === "\n") {
4805
- e -= 1;
4806
- prefixLen += 1;
4807
- }
4808
4801
  if (xstate.currField) {
4809
4802
  const val = content.substring(xstate.s, e).trim();
4810
4803
  const parsedValue = validateAndParseFieldValue(xstate.currField, val);
@@ -4871,7 +4864,7 @@ var convertValueToType = (field, val) => {
4871
4864
  return val;
4872
4865
  }
4873
4866
  };
4874
- function* streamValues(sig, values, xstate, content) {
4867
+ function* streamValues(sig, values, xstate, content, final = false) {
4875
4868
  if (!xstate.currField) {
4876
4869
  return;
4877
4870
  }
@@ -4879,13 +4872,17 @@ function* streamValues(sig, values, xstate, content) {
4879
4872
  if (!xstate.streamedIndex) {
4880
4873
  xstate.streamedIndex = { [fieldName]: 0 };
4881
4874
  }
4882
- if (!xstate.currField.type || !xstate.currField.type.isArray && xstate.currField.type.name === "string") {
4883
- const pos = xstate.streamedIndex[fieldName] ?? 0;
4884
- const s = xstate.s + pos;
4885
- const v = content.substring(s);
4886
- yield { [fieldName]: pos === 0 ? v.trimStart() : v };
4887
- xstate.streamedIndex[fieldName] = pos + v.length;
4888
- return;
4875
+ if (!final) {
4876
+ if (!xstate.currField.type || !xstate.currField.type.isArray && xstate.currField.type.name === "string") {
4877
+ const pos = xstate.streamedIndex[fieldName] ?? 0;
4878
+ const s = xstate.s + pos;
4879
+ const v = content.substring(s);
4880
+ const v1 = v.replace(/[\s\n\t]+$/, "");
4881
+ const v2 = pos === 0 ? v1.trimStart() : v1;
4882
+ yield { [fieldName]: v2 };
4883
+ xstate.streamedIndex[fieldName] = pos + v1.length;
4884
+ return;
4885
+ }
4889
4886
  }
4890
4887
  for (const key of Object.keys(values)) {
4891
4888
  const value = values[key];
@@ -5311,6 +5308,7 @@ var AxGen = class extends AxProgramWithSignature {
5311
5308
  );
5312
5309
  this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
5313
5310
  }
5311
+ streamingExtractFinalValue(this.signature, values, xstate, content);
5314
5312
  assertStreamingAssertions(
5315
5313
  this.streamingAsserts,
5316
5314
  values,
@@ -5318,9 +5316,8 @@ var AxGen = class extends AxProgramWithSignature {
5318
5316
  content,
5319
5317
  true
5320
5318
  );
5321
- streamingExtractFinalValue(this.signature, values, xstate, content);
5322
5319
  assertAssertions(this.asserts, values);
5323
- yield* streamValues(this.signature, values, xstate, content);
5320
+ yield* streamValues(this.signature, values, xstate, content, true);
5324
5321
  }
5325
5322
  async processResponse({
5326
5323
  ai,