@stackfactor/agent-utils 1.0.3 → 1.0.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAioBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCApfO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAyyBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz2B8B,GAAG,KAAG,MAAM;;AAo6BzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAiqBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAphBO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAy0BF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz4B8B,GAAG,KAAG,MAAM;;AAo8BzD,wBAOE"}
@@ -577,24 +577,21 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
577
577
  ? `${JSON_ESCAPE_INSTRUCTION}\n\n---\n\n${systemPrompt}`
578
578
  : JSON_ESCAPE_INSTRUCTION;
579
579
  }
580
- // Build tools array, adding progress reporting tool if callback provided
581
- // Create a shared progress tracker for both tool and callbacks
580
+ // Build tools array and progress callback for agentic mode
582
581
  const progressTracker = { current: minPercent };
583
582
  const agentTools = [...tools];
583
+ let trackingProgressCallback = null;
584
584
  if (onProgressReport) {
585
- // Wrap the progress callback to update the tracker
586
- const trackingProgressCallback = (data) => {
585
+ trackingProgressCallback = (data) => {
587
586
  if (typeof data.progress === "number") {
588
587
  progressTracker.current = data.progress;
589
588
  }
590
589
  onProgressReport(data);
591
590
  };
592
- agentTools.push(getAIProgressTool(trackingProgressCallback, minPercent, maxPercent));
593
591
  }
594
- // Create the agent with tools
592
+ // Create the agent with tools and progress callback
595
593
  const agent = createAgent(agentName, modelName, systemPrompt, agentTools, null, // responseFormat
596
- config, null, // onReportProgress handled via tools array
597
- minPercent, maxPercent);
594
+ config, trackingProgressCallback, minPercent, maxPercent);
598
595
  // Run the agent with callback that includes current progress
599
596
  const callbackWithProgress = onProgressReport
600
597
  ? (data) => onProgressReport({ ...data, progress: progressTracker.current })
@@ -639,7 +636,20 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
639
636
  }
640
637
  }
641
638
  if (expectsJsonResponse) {
642
- throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `Agent returned non-JSON response when JSON was expected: ${rawContent.substring(0, 100)}...`);
639
+ let preview = "";
640
+ if (typeof rawContent === "string") {
641
+ preview = rawContent.substring(0, 100);
642
+ }
643
+ else if (typeof rawContent === "object" && rawContent !== null) {
644
+ preview = JSON.stringify(rawContent).substring(0, 100);
645
+ }
646
+ else if (rawContent !== undefined && rawContent !== null) {
647
+ preview = String(rawContent).substring(0, 100);
648
+ }
649
+ else {
650
+ preview = "[empty response]";
651
+ }
652
+ throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `Agent returned non-JSON response when JSON was expected: ${preview}...`);
643
653
  }
644
654
  return rawContent;
645
655
  }
@@ -713,7 +723,20 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
713
723
  return JSON.stringify(extracted);
714
724
  }
715
725
  if (expectsJsonResponse) {
716
- throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${rawContent.substring(0, 100)}...`);
726
+ let preview = "";
727
+ if (typeof rawContent === "string") {
728
+ preview = rawContent.substring(0, 100);
729
+ }
730
+ else if (typeof rawContent === "object" && rawContent !== null) {
731
+ preview = JSON.stringify(rawContent).substring(0, 100);
732
+ }
733
+ else if (rawContent !== undefined && rawContent !== null) {
734
+ preview = String(rawContent).substring(0, 100);
735
+ }
736
+ else {
737
+ preview = "[empty response]";
738
+ }
739
+ throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${preview}...`);
717
740
  }
718
741
  return rawContent;
719
742
  }
@@ -841,7 +864,20 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
841
864
  return JSON.stringify(extracted);
842
865
  }
843
866
  if (expectsJsonResponse) {
844
- throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${rawContent.substring(0, 100)}...`);
867
+ let preview = "";
868
+ if (typeof rawContent === "string") {
869
+ preview = rawContent.substring(0, 100);
870
+ }
871
+ else if (typeof rawContent === "object" && rawContent !== null) {
872
+ preview = JSON.stringify(rawContent).substring(0, 100);
873
+ }
874
+ else if (rawContent !== undefined && rawContent !== null) {
875
+ preview = String(rawContent).substring(0, 100);
876
+ }
877
+ else {
878
+ preview = "[empty response]";
879
+ }
880
+ throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${preview}...`);
845
881
  }
846
882
  return rawContent;
847
883
  }
@@ -928,7 +964,19 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
928
964
  }
929
965
  // Return raw content as last resort - but throw if JSON was expected
930
966
  if (expectsJsonResponse) {
931
- const preview = typeof rawContent === "string" ? rawContent.substring(0, 100) : "";
967
+ let preview = "";
968
+ if (typeof rawContent === "string") {
969
+ preview = rawContent.substring(0, 100);
970
+ }
971
+ else if (typeof rawContent === "object" && rawContent !== null) {
972
+ preview = JSON.stringify(rawContent).substring(0, 100);
973
+ }
974
+ else if (rawContent !== undefined && rawContent !== null) {
975
+ preview = String(rawContent).substring(0, 100);
976
+ }
977
+ else {
978
+ preview = "[empty response]";
979
+ }
932
980
  throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${preview}...`);
933
981
  }
934
982
  return rawContent;
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAioBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCApfO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAyyBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz2B8B,GAAG,KAAG,MAAM;;AAo6BzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAiqBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAphBO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAy0BF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz4B8B,GAAG,KAAG,MAAM;;AAo8BzD,wBAOE"}
@@ -572,24 +572,21 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
572
572
  ? `${JSON_ESCAPE_INSTRUCTION}\n\n---\n\n${systemPrompt}`
573
573
  : JSON_ESCAPE_INSTRUCTION;
574
574
  }
575
- // Build tools array, adding progress reporting tool if callback provided
576
- // Create a shared progress tracker for both tool and callbacks
575
+ // Build tools array and progress callback for agentic mode
577
576
  const progressTracker = { current: minPercent };
578
577
  const agentTools = [...tools];
578
+ let trackingProgressCallback = null;
579
579
  if (onProgressReport) {
580
- // Wrap the progress callback to update the tracker
581
- const trackingProgressCallback = (data) => {
580
+ trackingProgressCallback = (data) => {
582
581
  if (typeof data.progress === "number") {
583
582
  progressTracker.current = data.progress;
584
583
  }
585
584
  onProgressReport(data);
586
585
  };
587
- agentTools.push(getAIProgressTool(trackingProgressCallback, minPercent, maxPercent));
588
586
  }
589
- // Create the agent with tools
587
+ // Create the agent with tools and progress callback
590
588
  const agent = createAgent(agentName, modelName, systemPrompt, agentTools, null, // responseFormat
591
- config, null, // onReportProgress handled via tools array
592
- minPercent, maxPercent);
589
+ config, trackingProgressCallback, minPercent, maxPercent);
593
590
  // Run the agent with callback that includes current progress
594
591
  const callbackWithProgress = onProgressReport
595
592
  ? (data) => onProgressReport({ ...data, progress: progressTracker.current })
@@ -634,7 +631,20 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
634
631
  }
635
632
  }
636
633
  if (expectsJsonResponse) {
637
- throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `Agent returned non-JSON response when JSON was expected: ${rawContent.substring(0, 100)}...`);
634
+ let preview = "";
635
+ if (typeof rawContent === "string") {
636
+ preview = rawContent.substring(0, 100);
637
+ }
638
+ else if (typeof rawContent === "object" && rawContent !== null) {
639
+ preview = JSON.stringify(rawContent).substring(0, 100);
640
+ }
641
+ else if (rawContent !== undefined && rawContent !== null) {
642
+ preview = String(rawContent).substring(0, 100);
643
+ }
644
+ else {
645
+ preview = "[empty response]";
646
+ }
647
+ throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `Agent returned non-JSON response when JSON was expected: ${preview}...`);
638
648
  }
639
649
  return rawContent;
640
650
  }
@@ -708,7 +718,20 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
708
718
  return JSON.stringify(extracted);
709
719
  }
710
720
  if (expectsJsonResponse) {
711
- throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${rawContent.substring(0, 100)}...`);
721
+ let preview = "";
722
+ if (typeof rawContent === "string") {
723
+ preview = rawContent.substring(0, 100);
724
+ }
725
+ else if (typeof rawContent === "object" && rawContent !== null) {
726
+ preview = JSON.stringify(rawContent).substring(0, 100);
727
+ }
728
+ else if (rawContent !== undefined && rawContent !== null) {
729
+ preview = String(rawContent).substring(0, 100);
730
+ }
731
+ else {
732
+ preview = "[empty response]";
733
+ }
734
+ throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${preview}...`);
712
735
  }
713
736
  return rawContent;
714
737
  }
@@ -836,7 +859,20 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
836
859
  return JSON.stringify(extracted);
837
860
  }
838
861
  if (expectsJsonResponse) {
839
- throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${rawContent.substring(0, 100)}...`);
862
+ let preview = "";
863
+ if (typeof rawContent === "string") {
864
+ preview = rawContent.substring(0, 100);
865
+ }
866
+ else if (typeof rawContent === "object" && rawContent !== null) {
867
+ preview = JSON.stringify(rawContent).substring(0, 100);
868
+ }
869
+ else if (rawContent !== undefined && rawContent !== null) {
870
+ preview = String(rawContent).substring(0, 100);
871
+ }
872
+ else {
873
+ preview = "[empty response]";
874
+ }
875
+ throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${preview}...`);
840
876
  }
841
877
  return rawContent;
842
878
  }
@@ -923,7 +959,19 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
923
959
  }
924
960
  // Return raw content as last resort - but throw if JSON was expected
925
961
  if (expectsJsonResponse) {
926
- const preview = typeof rawContent === "string" ? rawContent.substring(0, 100) : "";
962
+ let preview = "";
963
+ if (typeof rawContent === "string") {
964
+ preview = rawContent.substring(0, 100);
965
+ }
966
+ else if (typeof rawContent === "object" && rawContent !== null) {
967
+ preview = JSON.stringify(rawContent).substring(0, 100);
968
+ }
969
+ else if (rawContent !== undefined && rawContent !== null) {
970
+ preview = String(rawContent).substring(0, 100);
971
+ }
972
+ else {
973
+ preview = "[empty response]";
974
+ }
927
975
  throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, `LLM returned non-JSON response when JSON was expected: ${preview}...`);
928
976
  }
929
977
  return rawContent;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "restricted"
5
5
  },
6
- "version": "1.0.3",
6
+ "version": "1.0.5",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",