llm-exe 2.0.0-beta.8 → 2.1.0

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/dist/index.js CHANGED
@@ -61,7 +61,6 @@ __export(src_exports, {
61
61
  createPrompt: () => createPrompt,
62
62
  createState: () => createState,
63
63
  createStateItem: () => createStateItem,
64
- default: () => src_default,
65
64
  useExecutors: () => useExecutors,
66
65
  useLlm: () => useLlm,
67
66
  utils: () => utils_exports
@@ -499,64 +498,17 @@ function importHelpers(_helpers) {
499
498
  }
500
499
  __name(importHelpers, "importHelpers");
501
500
 
502
- // src/utils/modules/handlebars/index.ts
503
- var import_handlebars3 = __toESM(require("handlebars"));
504
-
505
- // src/utils/modules/handlebars/helpers/index.ts
506
- var helpers_exports = {};
507
- __export(helpers_exports, {
508
- eq: () => eq,
509
- getKeyOr: () => getKeyOr,
510
- getOr: () => getOr,
511
- hbsInTemplate: () => hbsInTemplate,
512
- ifCond: () => ifCond,
513
- indentJson: () => indentJson,
514
- join: () => join,
515
- jsonSchemaExample: () => jsonSchemaExample,
516
- neq: () => neq,
517
- objectToList: () => objectToList,
518
- pluralize: () => pluralize
519
- });
520
-
521
- // src/utils/modules/replaceTemplateString.ts
522
- function replaceTemplateString(templateString, substitutions = {}, configuration = {
523
- helpers: [],
524
- partials: []
525
- }) {
526
- if (!templateString) return templateString || "";
527
- const tempHelpers = [];
528
- const tempPartials = [];
529
- if (Array.isArray(configuration.helpers)) {
530
- registerHelpers(configuration.helpers, hbs);
531
- tempHelpers.push(...configuration.helpers.map((a) => a.name));
501
+ // src/utils/modules/toNumber.ts
502
+ function toNumber(value) {
503
+ if (typeof value === "number") {
504
+ return value;
532
505
  }
533
- if (Array.isArray(configuration.partials)) {
534
- registerPartials(configuration.partials, hbs);
535
- tempPartials.push(...configuration.partials.map((a) => a.name));
506
+ if (typeof value === "string" && value.trim() !== "") {
507
+ return Number(value);
536
508
  }
537
- const template = hbs.compile(templateString);
538
- const res = template(substitutions, {
539
- allowedProtoMethods: {
540
- substring: true
541
- }
542
- });
543
- tempHelpers.forEach(function(n) {
544
- hbs.unregisterHelper(n);
545
- });
546
- tempPartials.forEach(function(n) {
547
- hbs.unregisterPartial(n);
548
- });
549
- return res;
550
- }
551
- __name(replaceTemplateString, "replaceTemplateString");
552
-
553
- // src/utils/modules/handlebars/helpers/hbsInTemplate.ts
554
- function hbsInTemplate(arg1) {
555
- const data = this;
556
- const replace = replaceTemplateString(arg1, data);
557
- return replace;
509
+ return NaN;
558
510
  }
559
- __name(hbsInTemplate, "hbsInTemplate");
511
+ __name(toNumber, "toNumber");
560
512
 
561
513
  // src/utils/modules/get.ts
562
514
  function get(obj, path, defaultValue) {
@@ -570,44 +522,6 @@ function get(obj, path, defaultValue) {
570
522
  }
571
523
  __name(get, "get");
572
524
 
573
- // src/utils/modules/handlebars/helpers/getKeyOr.ts
574
- function getKeyOr(key, arg2) {
575
- const res = get(this, key);
576
- return typeof res !== "undefined" && res !== "" ? res : arg2;
577
- }
578
- __name(getKeyOr, "getKeyOr");
579
-
580
- // src/utils/modules/handlebars/helpers/getOr.ts
581
- function getOr(arg1, arg2) {
582
- return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
583
- }
584
- __name(getOr, "getOr");
585
-
586
- // src/utils/modules/handlebars/helpers/indentJson.ts
587
- function indentJson(arg1, collapse = "false") {
588
- if (typeof arg1 !== "object") {
589
- return replaceTemplateString(arg1 || "", this);
590
- }
591
- const replaced = maybeParseJSON(replaceTemplateString(maybeStringifyJSON(arg1), this));
592
- if (collapse == "true") {
593
- return JSON.stringify(replaced);
594
- }
595
- return JSON.stringify(replaced, null, 2);
596
- }
597
- __name(indentJson, "indentJson");
598
-
599
- // src/utils/modules/toNumber.ts
600
- function toNumber(value) {
601
- if (typeof value === "number") {
602
- return value;
603
- }
604
- if (typeof value === "string" && value.trim() !== "") {
605
- return Number(value);
606
- }
607
- return NaN;
608
- }
609
- __name(toNumber, "toNumber");
610
-
611
525
  // src/utils/modules/filterObjectOnSchema.ts
612
526
  function isObject(obj) {
613
527
  return obj === Object(obj);
@@ -672,6 +586,208 @@ function filterObjectOnSchema(schema, doc, detach, property) {
672
586
  }
673
587
  __name(filterObjectOnSchema, "filterObjectOnSchema");
674
588
 
589
+ // src/utils/modules/handlebars/hbs.ts
590
+ var import_handlebars = __toESM(require("handlebars"));
591
+
592
+ // src/utils/modules/handlebars/utils/registerPartials.ts
593
+ function _registerPartials(partials2, instance) {
594
+ if (partials2 && Array.isArray(partials2)) {
595
+ for (const partial of partials2) {
596
+ if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
597
+ if (instance) {
598
+ instance.registerPartial(partial.name, partial.template);
599
+ }
600
+ }
601
+ }
602
+ }
603
+ }
604
+ __name(_registerPartials, "_registerPartials");
605
+
606
+ // src/utils/modules/handlebars/utils/registerHelpers.ts
607
+ function _registerHelpers(helpers, instance) {
608
+ if (helpers && Array.isArray(helpers)) {
609
+ for (const helper of helpers) {
610
+ if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
611
+ if (instance) {
612
+ instance.registerHelper(helper.name, helper.handler);
613
+ }
614
+ }
615
+ }
616
+ }
617
+ }
618
+ __name(_registerHelpers, "_registerHelpers");
619
+
620
+ // src/utils/modules/getEnvironmentVariable.ts
621
+ function getEnvironmentVariable(name) {
622
+ if (typeof process === "object" && process?.env) {
623
+ return process.env[name];
624
+ } else {
625
+ return void 0;
626
+ }
627
+ }
628
+ __name(getEnvironmentVariable, "getEnvironmentVariable");
629
+
630
+ // src/utils/modules/handlebars/templates/index.ts
631
+ var MarkdownCode = `{{#if code}}\`\`\`{{#if language}}{{language}}{{/if}}
632
+ {{{code}}}
633
+ \`\`\`{{/if}}`;
634
+ var ThoughtActionResult = `
635
+ {{#if title}}{{#if attributes.stepsTaken.length}}{{title}}
636
+ {{/if}}{{/if}}
637
+ {{#each attributes.stepsTaken as | step |}}
638
+ {{#if step.thought}}Thought: {{step.result}}{{/if}}
639
+ {{#if step.result}}Action: {{step.action}}{{/if}}
640
+ {{#if step.result}}Result: {{step.result}}{{/if}}
641
+ {{/each}}`;
642
+ var ChatConversationHistory = `{{~#if title}}{{~#if chat_history.length}}{{title}}
643
+ {{~/if}}{{~/if}}
644
+ {{#each chat_history as | item |}}
645
+ {{~#eq item.role 'user'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../userName}}{{../mostRecentRoleSuffix}}{{else}}{{../userName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
646
+ {{/eq}}
647
+ {{~#eq item.role 'assistant'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../assistantName}}{{../mostRecentRoleSuffix}}{{else}}{{../assistantName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
648
+ {{/eq}}
649
+ {{~#eq item.role 'system'}}{{../systemName}}: {{{item.content}}}
650
+ {{/eq}}
651
+ {{~/each}}`;
652
+ var DialogueHistory = `{{>ChatConversationHistory title=title chat_history=(getKeyOr key []) assistantName=(getOr assistant 'Assistant') userName=(getOr user 'User') systemName=(getOr system 'System') mostRecentRolePrefix=mostRecentRolePrefix mostRecentRoleSuffix=mostRecentRoleSuffix mostRecentMessagePrefix=mostRecentMessagePrefix mostRecentMessageSuffix=mostRecentMessageSuffix}}`;
653
+ var SingleChatMessage = `{{~#eq role 'user'}}{{getOr name 'User'}}: {{{content}}}{{~/eq}}
654
+ {{~#eq role 'assistant'}}{{getOr assistant 'Assistant'}}: {{{content}}}{{~/eq}}
655
+ {{~#eq role 'system'}}{{getOr system 'System'}}: {{{content}}}{{~/eq}}`;
656
+ var ThoughtsAndObservations = `{{~#each thoughts as | step |}}
657
+ {{~#if step.thought}}Thought: {{{step.thought}}}
658
+ {{/if}}
659
+ {{~#if step.observation}}Observation: {{{step.observation}}}
660
+ {{/if}}
661
+ {{~/each}}`;
662
+ var JsonSchema = `{{#if (getKeyOr key false)}}
663
+ \`\`\`json
664
+ {{{indentJson (getKeyOr key) collapse}}}
665
+ \`\`\`
666
+ {{~/if}}`;
667
+ var JsonSchemaExampleJson = `{{#if (getOr key false)}}
668
+ \`\`\`json
669
+ {{{jsonSchemaExample key (getOr property '') collapse}}}
670
+ \`\`\`
671
+ {{~/if}}`;
672
+ var partials = {
673
+ JsonSchema,
674
+ JsonSchemaExampleJson,
675
+ MarkdownCode,
676
+ DialogueHistory,
677
+ SingleChatMessage,
678
+ ChatConversationHistory,
679
+ ThoughtsAndObservations,
680
+ ThoughtActionResult
681
+ };
682
+
683
+ // src/utils/modules/handlebars/helpers/index.ts
684
+ var helpers_exports = {};
685
+ __export(helpers_exports, {
686
+ cut: () => cutFn,
687
+ eq: () => eq,
688
+ getKeyOr: () => getKeyOr,
689
+ getOr: () => getOr,
690
+ ifCond: () => ifCond,
691
+ indentJson: () => indentJson,
692
+ join: () => join,
693
+ jsonSchemaExample: () => jsonSchemaExample,
694
+ neq: () => neq,
695
+ objectToList: () => objectToList,
696
+ pluralize: () => pluralize,
697
+ substring: () => substringFn,
698
+ with: () => withFn
699
+ });
700
+
701
+ // src/utils/modules/json.ts
702
+ var maybeStringifyJSON = /* @__PURE__ */ __name((objOrMaybeString) => {
703
+ if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
704
+ return objOrMaybeString;
705
+ }
706
+ try {
707
+ const result = JSON.stringify(objOrMaybeString);
708
+ return result;
709
+ } catch (error) {
710
+ }
711
+ return "";
712
+ }, "maybeStringifyJSON");
713
+ var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
714
+ if (!objOrMaybeJSON) return {};
715
+ if (typeof objOrMaybeJSON === "string") {
716
+ try {
717
+ const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
718
+ const result = JSON.parse(cleanMarkdown);
719
+ if (typeof result === "object" && result !== null) {
720
+ return result;
721
+ }
722
+ } catch (error) {
723
+ }
724
+ }
725
+ if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
726
+ return objOrMaybeJSON;
727
+ }
728
+ return {};
729
+ }, "maybeParseJSON");
730
+ function isObjectStringified(maybeObject) {
731
+ if (typeof maybeObject !== "string") return false;
732
+ const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
733
+ const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
734
+ if (!isMaybeObject && !isMaybeArray) {
735
+ return false;
736
+ }
737
+ let canDecode = false;
738
+ try {
739
+ JSON.parse(maybeObject);
740
+ canDecode = true;
741
+ } catch (error) {
742
+ canDecode = false;
743
+ }
744
+ return canDecode;
745
+ }
746
+ __name(isObjectStringified, "isObjectStringified");
747
+ function helpJsonMarkup(str) {
748
+ if (typeof str !== "string") {
749
+ return str;
750
+ }
751
+ const input = str.trim();
752
+ const markdownJsonStartsWith = "```json";
753
+ const markdownJsonEndsWith = "```";
754
+ if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
755
+ return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
756
+ }
757
+ return str;
758
+ }
759
+ __name(helpJsonMarkup, "helpJsonMarkup");
760
+
761
+ // src/utils/modules/replaceTemplateStringSimple.ts
762
+ function replaceTemplateStringSimple(template, context) {
763
+ return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
764
+ const keys = key.split(".");
765
+ let value = context;
766
+ for (const k of keys) {
767
+ if (value && typeof value === "object" && k in value) {
768
+ value = value[k];
769
+ } else {
770
+ return "";
771
+ }
772
+ }
773
+ return typeof value === "string" ? value : String(value);
774
+ });
775
+ }
776
+ __name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
777
+
778
+ // src/utils/modules/handlebars/helpers/indentJson.ts
779
+ function indentJson(arg1, collapse = "false") {
780
+ if (typeof arg1 !== "object") {
781
+ return replaceTemplateStringSimple(arg1 || "", this);
782
+ }
783
+ const replaced = maybeParseJSON(replaceTemplateStringSimple(maybeStringifyJSON(arg1), this));
784
+ if (collapse == "true") {
785
+ return JSON.stringify(replaced);
786
+ }
787
+ return JSON.stringify(replaced, null, 2);
788
+ }
789
+ __name(indentJson, "indentJson");
790
+
675
791
  // src/utils/modules/schemaExampleWith.ts
676
792
  function schemaExampleWith(schema, property) {
677
793
  if (schema.type === "array") {
@@ -691,7 +807,7 @@ function jsonSchemaExample(key, prop, collapse) {
691
807
  if (typeof result !== "object") {
692
808
  return "";
693
809
  }
694
- const replaced = maybeParseJSON(replaceTemplateString(maybeStringifyJSON(result), this));
810
+ const replaced = maybeParseJSON(replaceTemplateStringSimple(maybeStringifyJSON(result), this));
695
811
  if (collapse == "true") {
696
812
  return JSON.stringify(replaced);
697
813
  }
@@ -701,6 +817,19 @@ function jsonSchemaExample(key, prop, collapse) {
701
817
  }
702
818
  __name(jsonSchemaExample, "jsonSchemaExample");
703
819
 
820
+ // src/utils/modules/handlebars/helpers/getKeyOr.ts
821
+ function getKeyOr(key, arg2) {
822
+ const res = get(this, key);
823
+ return typeof res !== "undefined" && res !== "" ? res : arg2;
824
+ }
825
+ __name(getKeyOr, "getKeyOr");
826
+
827
+ // src/utils/modules/handlebars/helpers/getOr.ts
828
+ function getOr(arg1, arg2) {
829
+ return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
830
+ }
831
+ __name(getOr, "getOr");
832
+
704
833
  // src/utils/modules/handlebars/helpers/pluralize.ts
705
834
  function pluralize(arg1, arg2) {
706
835
  const [singular, plural] = arg1.split("|");
@@ -765,161 +894,73 @@ function join(array) {
765
894
  }
766
895
  __name(join, "join");
767
896
 
768
- // src/utils/modules/handlebars/templates/index.ts
769
- var MarkdownCode = `{{#if code}}\`\`\`{{#if language}}{{language}}{{/if}}
770
- {{{code}}}
771
- \`\`\`{{/if}}`;
772
- var ThoughtActionResult = `
773
- {{#if title}}{{#if attributes.stepsTaken.length}}{{title}}
774
- {{/if}}{{/if}}
775
- {{#each attributes.stepsTaken as | step |}}
776
- {{#if step.thought}}Thought: {{step.result}}{{/if}}
777
- {{#if step.result}}Action: {{step.action}}{{/if}}
778
- {{#if step.result}}Result: {{step.result}}{{/if}}
779
- {{/each}}`;
780
- var ChatConversationHistory = `{{~#if title}}{{~#if chat_history.length}}{{title}}
781
- {{~/if}}{{~/if}}
782
- {{#each chat_history as | item |}}
783
- {{~#eq item.role 'user'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../userName}}{{../mostRecentRoleSuffix}}{{else}}{{../userName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
784
- {{/eq}}
785
- {{~#eq item.role 'assistant'}}{{#if @last}}{{../mostRecentRolePrefix}}{{../assistantName}}{{../mostRecentRoleSuffix}}{{else}}{{../assistantName}}{{/if}}: {{#if @last}}{{../mostRecentMessagePrefix}}{{/if}}{{{item.content}}}{{#if @last}}{{../mostRecentMessageSuffix}}{{/if}}
786
- {{/eq}}
787
- {{~#eq item.role 'system'}}{{../systemName}}: {{{item.content}}}
788
- {{/eq}}
789
- {{~/each}}`;
790
- var DialogueHistory = `{{>ChatConversationHistory title=title chat_history=(getKeyOr key []) assistantName=(getOr assistant 'Assistant') userName=(getOr user 'User') systemName=(getOr system 'System') mostRecentRolePrefix=mostRecentRolePrefix mostRecentRoleSuffix=mostRecentRoleSuffix mostRecentMessagePrefix=mostRecentMessagePrefix mostRecentMessageSuffix=mostRecentMessageSuffix}}`;
791
- var SingleChatMessage = `{{~#eq role 'user'}}{{getOr name 'User'}}: {{{content}}}{{~/eq}}
792
- {{~#eq role 'assistant'}}{{getOr assistant 'Assistant'}}: {{{content}}}{{~/eq}}
793
- {{~#eq role 'system'}}{{getOr system 'System'}}: {{{content}}}{{~/eq}}`;
794
- var ThoughtsAndObservations = `{{~#each thoughts as | step |}}
795
- {{~#if step.thought}}Thought: {{{step.thought}}}
796
- {{/if}}
797
- {{~#if step.observation}}Observation: {{{step.observation}}}
798
- {{/if}}
799
- {{~/each}}`;
800
- var JsonSchema = `{{#if (getKeyOr key false)}}
801
- \`\`\`json
802
- {{{indentJson (getKeyOr key) collapse}}}
803
- \`\`\`
804
- {{~/if}}`;
805
- var JsonSchemaExampleJson = `{{#if (getOr key false)}}
806
- \`\`\`json
807
- {{{jsonSchemaExample key (getOr property '') collapse}}}
808
- \`\`\`
809
- {{~/if}}`;
810
- var partials = {
811
- JsonSchema,
812
- JsonSchemaExampleJson,
813
- MarkdownCode,
814
- DialogueHistory,
815
- SingleChatMessage,
816
- ChatConversationHistory,
817
- ThoughtsAndObservations,
818
- ThoughtActionResult
819
- };
897
+ // src/utils/modules/handlebars/helpers/cut.ts
898
+ function cutFn(str, arg) {
899
+ return str.toString().replace(new RegExp(arg, "g"), "");
900
+ }
901
+ __name(cutFn, "cutFn");
820
902
 
821
- // src/utils/modules/isPromise.ts
822
- function isPromise(value) {
823
- if (typeof value === "object" && value !== null && typeof value.then === "function") {
824
- return true;
903
+ // src/utils/modules/handlebars/helpers/substring.ts
904
+ function substringFn(str, start, end) {
905
+ if (start > end) {
906
+ return "";
907
+ }
908
+ if (str.length > end) {
909
+ return str.substring(start, end);
910
+ } else {
911
+ return str;
825
912
  }
826
- return Object.prototype.toString.call(value) === "[object AsyncFunction]";
827
913
  }
828
- __name(isPromise, "isPromise");
914
+ __name(substringFn, "substringFn");
829
915
 
830
- // src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
831
- function makeHandlebarsInstanceAsync(hbs2) {
832
- var _a;
916
+ // src/utils/modules/handlebars/helpers/with.ts
917
+ function withFn(options, context) {
918
+ return options.fn(context);
919
+ }
920
+ __name(withFn, "withFn");
921
+
922
+ // src/utils/modules/handlebars/utils/makeHandlebarsInstance.ts
923
+ function makeHandlebarsInstance(hbs2) {
833
924
  const handlebars = hbs2.create();
834
- const asyncCompiler = (_a = class extends hbs2.JavaScriptCompiler {
835
- constructor() {
836
- super();
837
- this.compiler = asyncCompiler;
838
- }
839
- mergeSource(varDeclarations) {
840
- const sources = super.mergeSource(varDeclarations);
841
- sources.prepend("return (async () => {");
842
- sources.add(" })()");
843
- return sources;
844
- }
845
- appendToBuffer(source, location, explicit) {
846
- if (!Array.isArray(source)) {
847
- source = [
848
- source
849
- ];
850
- }
851
- source = this.source.wrap(source, location);
852
- if (this.environment.isSimple) {
853
- return [
854
- "return await ",
855
- source,
856
- ";"
857
- ];
858
- }
859
- if (explicit) {
860
- return [
861
- "buffer += await ",
862
- source,
863
- ";"
864
- ];
925
+ const helperKeys = Object.keys(helpers_exports);
926
+ _registerHelpers(helperKeys.map((a) => ({
927
+ handler: helpers_exports[a],
928
+ name: a
929
+ })), handlebars);
930
+ handlebars.registerHelper("hbsInTemplate", function(str, substitutions) {
931
+ const template = handlebars.compile(str);
932
+ return template(substitutions, {
933
+ allowedProtoMethods: {
934
+ substring: true
865
935
  }
866
- source.appendToBuffer = true;
867
- source.prepend("await ");
868
- return source;
869
- }
870
- }, __name(_a, "asyncCompiler"), _a);
871
- handlebars.JavaScriptCompiler = asyncCompiler;
872
- const _compile = handlebars.compile;
873
- const _template = handlebars.VM.template;
874
- const _escapeExpression = handlebars.escapeExpression;
875
- function escapeExpression(value) {
876
- if (isPromise(value)) {
877
- return value.then((v) => _escapeExpression(v));
878
- }
879
- return _escapeExpression(value);
936
+ });
937
+ });
938
+ const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
939
+ if (helperPath) {
940
+ const externalHelpers = require(helperPath);
941
+ _registerHelpers(importHelpers(externalHelpers), handlebars);
880
942
  }
881
- __name(escapeExpression, "escapeExpression");
882
- function lookupProperty(containerLookupProperty) {
883
- return function(parent, propertyName) {
884
- if (isPromise(parent)) {
885
- if (typeof parent?.then === "function") {
886
- return parent.then((p) => containerLookupProperty(p, propertyName));
887
- }
888
- return parent().then((p) => containerLookupProperty(p, propertyName));
889
- }
890
- return containerLookupProperty(parent, propertyName);
891
- };
943
+ const contextPartialKeys = Object.keys(partials);
944
+ for (const contextPartialKey of contextPartialKeys) {
945
+ handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
946
+ }
947
+ const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
948
+ if (typeof process === "object" && partialsPath) {
949
+ const externalPartials = require(partialsPath);
950
+ _registerPartials(importPartials(externalPartials), handlebars);
892
951
  }
893
- __name(lookupProperty, "lookupProperty");
894
- handlebars.template = function(spec) {
895
- spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
896
- container.escapeExpression = escapeExpression;
897
- container.lookupProperty = lookupProperty(container.lookupProperty);
898
- if (depths.length == 0) {
899
- depths = [
900
- data.root
901
- ];
902
- }
903
- const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
904
- return v;
905
- };
906
- return _template(spec, handlebars);
907
- };
908
- handlebars.compile = function(template, options) {
909
- const compiled = _compile.apply(handlebars, [
910
- template,
911
- {
912
- ...options
913
- }
914
- ]);
915
- return function(context, execOptions) {
916
- context = context || {};
917
- return compiled.call(handlebars, context, execOptions);
918
- };
919
- };
920
952
  return handlebars;
921
953
  }
922
- __name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
954
+ __name(makeHandlebarsInstance, "makeHandlebarsInstance");
955
+
956
+ // src/utils/modules/isPromise.ts
957
+ function isPromise(value) {
958
+ if (typeof value === "object" && value !== null && typeof value.then === "function") {
959
+ return true;
960
+ }
961
+ return Object.prototype.toString.call(value) === "[object AsyncFunction]";
962
+ }
963
+ __name(isPromise, "isPromise");
923
964
 
924
965
  // src/utils/modules/handlebars/utils/appendContextPath.ts
925
966
  function appendContextPath(contextPath, id) {
@@ -976,10 +1017,10 @@ async function withFnAsync(context, options) {
976
1017
  if (arguments.length !== 2) {
977
1018
  throw new Error("#with requires exactly one argument");
978
1019
  }
979
- if (typeof context === "function") {
980
- context = context.call(this);
981
- } else if (isPromise(context)) {
1020
+ if (isPromise(context)) {
982
1021
  context = await context;
1022
+ } else if (typeof context === "function") {
1023
+ context = context.call(this);
983
1024
  }
984
1025
  const { fn } = options;
985
1026
  if (!isEmpty(context)) {
@@ -1006,10 +1047,10 @@ async function ifFnAsync(conditional, options) {
1006
1047
  if (arguments.length !== 2) {
1007
1048
  throw new Error("#if requires exactly one argument");
1008
1049
  }
1009
- if (typeof conditional === "function") {
1010
- conditional = conditional.call(this);
1011
- } else if (isPromise(conditional)) {
1050
+ if (isPromise(conditional)) {
1012
1051
  conditional = await conditional;
1052
+ } else if (typeof conditional === "function") {
1053
+ conditional = conditional.call(this);
1013
1054
  }
1014
1055
  if (!options.hash.includeZero && !conditional || isEmpty(conditional)) {
1015
1056
  return options.inverse(this);
@@ -1026,7 +1067,7 @@ function isReadableStream(obj) {
1026
1067
  __name(isReadableStream, "isReadableStream");
1027
1068
 
1028
1069
  // src/utils/modules/handlebars/helpers/async/each.ts
1029
- async function eachFnAsync(context, options) {
1070
+ async function eachFnAsync(arg1, options) {
1030
1071
  if (!options) {
1031
1072
  throw new Error("Must pass iterator to #each");
1032
1073
  }
@@ -1039,8 +1080,8 @@ async function eachFnAsync(context, options) {
1039
1080
  if (options.data && options.ids) {
1040
1081
  contextPath = `${appendContextPath(options.data.contextPath, options.ids[0])}.`;
1041
1082
  }
1042
- if (typeof context === "function") {
1043
- context = context.call(this);
1083
+ if (typeof arg1 === "function") {
1084
+ arg1 = arg1.call(this);
1044
1085
  }
1045
1086
  if (options.data) {
1046
1087
  data = createFrame(options.data);
@@ -1055,10 +1096,10 @@ async function eachFnAsync(context, options) {
1055
1096
  data.contextPath = contextPath + field;
1056
1097
  }
1057
1098
  }
1058
- ret.push(await fn(context[field], {
1099
+ ret.push(await fn(arg1[field], {
1059
1100
  data,
1060
1101
  blockParams: blockParams([
1061
- context[field],
1102
+ arg1[field],
1062
1103
  field
1063
1104
  ], [
1064
1105
  contextPath + field,
@@ -1067,41 +1108,41 @@ async function eachFnAsync(context, options) {
1067
1108
  }));
1068
1109
  }
1069
1110
  __name(execIteration, "execIteration");
1070
- if (context && typeof context === "object") {
1071
- if (isPromise(context)) {
1072
- context = await context;
1073
- }
1074
- if (Array.isArray(context)) {
1075
- for (let j = context.length; i < j; i++) {
1076
- if (i in context) {
1077
- await execIteration(i, i, i === context.length - 1);
1111
+ if (isPromise(arg1)) {
1112
+ arg1 = await arg1;
1113
+ }
1114
+ if (arg1 && typeof arg1 === "object") {
1115
+ if (Array.isArray(arg1)) {
1116
+ for (let j = arg1.length; i < j; i++) {
1117
+ if (i in arg1) {
1118
+ await execIteration(i, i, i === arg1.length - 1);
1078
1119
  }
1079
1120
  }
1080
- } else if (global.Symbol && context[global.Symbol.iterator]) {
1081
- const newContext = [], iterator = context[global.Symbol.iterator]();
1121
+ } else if (global.Symbol && arg1[global.Symbol.iterator]) {
1122
+ const newContext = [], iterator = arg1[global.Symbol.iterator]();
1082
1123
  for (let it = iterator.next(); !it.done; it = iterator.next()) {
1083
1124
  newContext.push(it.value);
1084
1125
  }
1085
- context = newContext;
1086
- for (let j = context.length; i < j; i++) {
1087
- await execIteration(i, i, i === context.length - 1);
1126
+ arg1 = newContext;
1127
+ for (let j = arg1.length; i < j; i++) {
1128
+ await execIteration(i, i, i === arg1.length - 1);
1088
1129
  }
1089
- } else if (isReadableStream(context)) {
1130
+ } else if (isReadableStream(arg1)) {
1090
1131
  const newContext = [];
1091
1132
  await new Promise((resolve, reject) => {
1092
- context.on("data", (item) => {
1133
+ arg1.on("data", (item) => {
1093
1134
  newContext.push(item);
1094
1135
  }).on("end", async () => {
1095
- context = newContext;
1096
- for (let j = context.length; i < j; i++) {
1097
- await execIteration(i, i, i === context.length - 1);
1136
+ arg1 = newContext;
1137
+ for (let j = arg1.length; i < j; i++) {
1138
+ await execIteration(i, i, i === arg1.length - 1);
1098
1139
  }
1099
1140
  resolve(true);
1100
1141
  }).once("error", (e) => reject(e));
1101
1142
  });
1102
1143
  } else {
1103
1144
  let priorKey;
1104
- for (const key of Object.keys(context)) {
1145
+ for (const key of Object.keys(arg1)) {
1105
1146
  if (priorKey !== void 0) {
1106
1147
  await execIteration(priorKey, i - 1);
1107
1148
  }
@@ -1144,105 +1185,174 @@ var asyncCoreOverrideHelpers = {
1144
1185
  unless: unlessFnAsync
1145
1186
  };
1146
1187
 
1147
- // src/utils/modules/getEnvironmentVariable.ts
1148
- function getEnvironmentVariable(name) {
1149
- if (typeof process === "object" && process?.env) {
1150
- return process.env[name];
1151
- } else {
1152
- return void 0;
1153
- }
1154
- }
1155
- __name(getEnvironmentVariable, "getEnvironmentVariable");
1156
-
1157
- // src/utils/modules/handlebars/index.ts
1158
- var __hbsAsync = makeHandlebarsInstanceAsync(import_handlebars3.default);
1159
- var __hbs = import_handlebars3.default;
1160
- function useHandlebars(hbsInstance, preferAsync = false) {
1161
- hbsInstance.registerHelper("with", function(context, options) {
1162
- return options.fn(context);
1163
- });
1164
- hbsInstance.registerHelper("cut", function(str, arg2) {
1165
- return str.toString().replace(new RegExp(arg2, "g"), "");
1166
- });
1167
- hbsInstance.registerHelper("substring", function(str, start, end) {
1168
- if (str.length > end) {
1169
- return str.substring(start, end);
1170
- } else {
1171
- return str;
1188
+ // src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
1189
+ function makeHandlebarsInstanceAsync(hbs2) {
1190
+ var _a;
1191
+ const handlebars = hbs2.create();
1192
+ const asyncCompiler = (_a = class extends hbs2.JavaScriptCompiler {
1193
+ constructor() {
1194
+ super();
1195
+ this.compiler = asyncCompiler;
1172
1196
  }
1173
- });
1174
- hbsInstance.registerHelper("unless", function(conditional, options) {
1175
- if (arguments.length !== 2) {
1176
- throw new Error("#unless requires exactly one argument");
1197
+ mergeSource(varDeclarations) {
1198
+ const sources = super.mergeSource(varDeclarations);
1199
+ sources.prepend("return (async () => {");
1200
+ sources.add(" })()");
1201
+ return sources;
1177
1202
  }
1178
- const ifFn = hbsInstance.helpers["if"];
1179
- return ifFn(conditional, {
1180
- fn: options.inverse,
1181
- inverse: options.fn,
1182
- hash: options.hash
1183
- });
1184
- });
1203
+ appendToBuffer(source, location, explicit) {
1204
+ if (!Array.isArray(source)) {
1205
+ source = [
1206
+ source
1207
+ ];
1208
+ }
1209
+ source = this.source.wrap(source, location);
1210
+ if (this.environment.isSimple) {
1211
+ return [
1212
+ "return await ",
1213
+ source,
1214
+ ";"
1215
+ ];
1216
+ }
1217
+ if (explicit) {
1218
+ return [
1219
+ "buffer += await ",
1220
+ source,
1221
+ ";"
1222
+ ];
1223
+ }
1224
+ source.appendToBuffer = true;
1225
+ source.prepend("await ");
1226
+ return source;
1227
+ }
1228
+ }, __name(_a, "asyncCompiler"), _a);
1229
+ handlebars.JavaScriptCompiler = asyncCompiler;
1230
+ const _compile = handlebars.compile;
1231
+ const _template = handlebars.VM.template;
1232
+ const _escapeExpression = handlebars.escapeExpression;
1233
+ function escapeExpression(value) {
1234
+ if (isPromise(value)) {
1235
+ return value.then((v) => _escapeExpression(v));
1236
+ }
1237
+ return _escapeExpression(value);
1238
+ }
1239
+ __name(escapeExpression, "escapeExpression");
1240
+ function lookupProperty(containerLookupProperty) {
1241
+ return function(parent, propertyName) {
1242
+ if (isPromise(parent)) {
1243
+ if (typeof parent?.then === "function") {
1244
+ return parent.then((p) => containerLookupProperty(p, propertyName));
1245
+ }
1246
+ return parent().then((p) => containerLookupProperty(p, propertyName));
1247
+ }
1248
+ return containerLookupProperty(parent, propertyName);
1249
+ };
1250
+ }
1251
+ __name(lookupProperty, "lookupProperty");
1252
+ handlebars.template = function(spec) {
1253
+ spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
1254
+ container.escapeExpression = escapeExpression;
1255
+ container.lookupProperty = lookupProperty(container.lookupProperty);
1256
+ if (depths.length == 0) {
1257
+ depths = [
1258
+ data.root
1259
+ ];
1260
+ }
1261
+ const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
1262
+ return v;
1263
+ };
1264
+ return _template(spec, handlebars);
1265
+ };
1266
+ handlebars.compile = function(template, options) {
1267
+ const compiled = _compile.apply(handlebars, [
1268
+ template,
1269
+ {
1270
+ ...options
1271
+ }
1272
+ ]);
1273
+ return function(context, execOptions) {
1274
+ context = context || {};
1275
+ return compiled.call(handlebars, context, execOptions);
1276
+ };
1277
+ };
1185
1278
  const helperKeys = Object.keys(helpers_exports);
1186
- registerHelpers(helperKeys.map((a) => ({
1279
+ _registerHelpers(helperKeys.map((a) => ({
1187
1280
  handler: helpers_exports[a],
1188
1281
  name: a
1189
- })), hbsInstance);
1190
- if (preferAsync) {
1191
- const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
1192
- registerHelpers(asyncHelperKeys.map((a) => ({
1193
- handler: asyncCoreOverrideHelpers[a],
1194
- name: a
1195
- })), hbsInstance);
1196
- }
1197
- const helperPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_HELPERS_PATH");
1198
- if (helperPath) {
1199
- const externalHelpers = require(helperPath);
1200
- registerHelpers(importHelpers(externalHelpers), hbsInstance);
1201
- }
1282
+ })), handlebars);
1283
+ const asyncHelperKeys = Object.keys(asyncCoreOverrideHelpers);
1284
+ _registerHelpers(asyncHelperKeys.map((a) => ({
1285
+ handler: asyncCoreOverrideHelpers[a],
1286
+ name: a
1287
+ })), handlebars);
1202
1288
  const contextPartialKeys = Object.keys(partials);
1203
1289
  for (const contextPartialKey of contextPartialKeys) {
1204
- hbsInstance.registerPartial(contextPartialKey, partials[contextPartialKey]);
1290
+ handlebars.registerPartial(contextPartialKey, partials[contextPartialKey]);
1205
1291
  }
1206
1292
  const partialsPath = getEnvironmentVariable("CUSTOM_PROMPT_TEMPLATE_PARTIALS_PATH");
1207
1293
  if (typeof process === "object" && partialsPath) {
1208
1294
  const externalPartials = require(partialsPath);
1209
- registerPartials(importPartials(externalPartials), hbsInstance);
1295
+ _registerPartials(importPartials(externalPartials), handlebars);
1210
1296
  }
1211
- return hbsInstance;
1297
+ return handlebars;
1212
1298
  }
1213
- __name(useHandlebars, "useHandlebars");
1214
- var hbsAsync = useHandlebars(__hbsAsync);
1215
- var hbs = useHandlebars(__hbs);
1216
- function registerPartials(partials2, instance) {
1217
- if (partials2 && Array.isArray(partials2)) {
1218
- for (const partial of partials2) {
1219
- if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
1220
- if (instance) {
1221
- instance.registerPartial(partial.name, partial.template);
1222
- } else {
1223
- hbs.registerPartial(partial.name, partial.template);
1224
- hbsAsync.registerPartial(partial.name, partial.template);
1225
- }
1226
- }
1227
- }
1299
+ __name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
1300
+
1301
+ // src/utils/modules/handlebars/hbs.ts
1302
+ var _hbsAsync = makeHandlebarsInstanceAsync(import_handlebars.default);
1303
+ var _hbs = makeHandlebarsInstance(import_handlebars.default);
1304
+
1305
+ // src/utils/modules/handlebars/index.ts
1306
+ var hbs = {
1307
+ handlebars: _hbs,
1308
+ registerHelpers: /* @__PURE__ */ __name((helpers) => {
1309
+ _registerHelpers(helpers, _hbs);
1310
+ }, "registerHelpers"),
1311
+ registerPartials: /* @__PURE__ */ __name((partials2) => {
1312
+ _registerPartials(partials2, _hbs);
1313
+ }, "registerPartials")
1314
+ };
1315
+ var hbsAsync = {
1316
+ handlebars: _hbsAsync,
1317
+ registerHelpers: /* @__PURE__ */ __name((helpers) => {
1318
+ _registerHelpers(helpers, _hbsAsync);
1319
+ }, "registerHelpers"),
1320
+ registerPartials: /* @__PURE__ */ __name((partials2) => {
1321
+ _registerPartials(partials2, _hbsAsync);
1322
+ }, "registerPartials")
1323
+ };
1324
+
1325
+ // src/utils/modules/replaceTemplateString.ts
1326
+ function replaceTemplateString(templateString, substitutions = {}, configuration = {
1327
+ helpers: [],
1328
+ partials: []
1329
+ }) {
1330
+ if (!templateString) return templateString || "";
1331
+ const tempHelpers = [];
1332
+ const tempPartials = [];
1333
+ if (Array.isArray(configuration.helpers)) {
1334
+ hbs.registerHelpers(configuration.helpers);
1335
+ tempHelpers.push(...configuration.helpers.map((a) => a.name));
1228
1336
  }
1229
- }
1230
- __name(registerPartials, "registerPartials");
1231
- function registerHelpers(helpers, instance) {
1232
- if (helpers && Array.isArray(helpers)) {
1233
- for (const helper of helpers) {
1234
- if (helper.name && typeof helper.name === "string" && typeof helper.handler === "function") {
1235
- if (instance) {
1236
- instance.registerHelper(helper.name, helper.handler);
1237
- } else {
1238
- hbs.registerHelper(helper.name, helper.handler);
1239
- hbsAsync.registerHelper(helper.name, helper.handler);
1240
- }
1241
- }
1242
- }
1337
+ if (Array.isArray(configuration.partials)) {
1338
+ hbs.registerPartials(configuration.partials);
1339
+ tempPartials.push(...configuration.partials.map((a) => a.name));
1243
1340
  }
1341
+ const template = hbs.handlebars.compile(templateString);
1342
+ const res = template(substitutions, {
1343
+ allowedProtoMethods: {
1344
+ substring: true
1345
+ }
1346
+ });
1347
+ tempHelpers.forEach(function(n) {
1348
+ hbs.handlebars.unregisterHelper(n);
1349
+ });
1350
+ tempPartials.forEach(function(n) {
1351
+ hbs.handlebars.unregisterPartial(n);
1352
+ });
1353
+ return res;
1244
1354
  }
1245
- __name(registerHelpers, "registerHelpers");
1355
+ __name(replaceTemplateString, "replaceTemplateString");
1246
1356
 
1247
1357
  // src/utils/modules/replaceTemplateStringAsync.ts
1248
1358
  async function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
@@ -1253,24 +1363,24 @@ async function replaceTemplateStringAsync(templateString, substitutions = {}, co
1253
1363
  const tempHelpers = [];
1254
1364
  const tempPartials = [];
1255
1365
  if (Array.isArray(configuration.helpers)) {
1256
- registerHelpers(configuration.helpers, hbsAsync);
1366
+ hbsAsync.registerHelpers(configuration.helpers);
1257
1367
  tempHelpers.push(...configuration.helpers.map((a) => a.name));
1258
1368
  }
1259
1369
  if (Array.isArray(configuration.partials)) {
1260
- registerPartials(configuration.partials, hbsAsync);
1370
+ hbsAsync.registerPartials(configuration.partials);
1261
1371
  tempPartials.push(...configuration.partials.map((a) => a.name));
1262
1372
  }
1263
- const template = hbsAsync.compile(templateString);
1373
+ const template = hbsAsync.handlebars.compile(templateString);
1264
1374
  const res = await template(substitutions, {
1265
1375
  allowedProtoMethods: {
1266
1376
  substring: true
1267
1377
  }
1268
1378
  });
1269
1379
  tempHelpers.forEach(function(n) {
1270
- hbsAsync.unregisterHelper(n);
1380
+ hbsAsync.handlebars.unregisterHelper(n);
1271
1381
  });
1272
1382
  tempPartials.forEach(function(n) {
1273
- hbsAsync.unregisterPartial(n);
1383
+ hbsAsync.handlebars.unregisterPartial(n);
1274
1384
  });
1275
1385
  return res;
1276
1386
  }
@@ -1293,65 +1403,17 @@ var asyncCallWithTimeout = /* @__PURE__ */ __name(async (asyncPromise, timeLimit
1293
1403
  });
1294
1404
  }, "asyncCallWithTimeout");
1295
1405
 
1296
- // src/utils/modules/json.ts
1297
- var maybeStringifyJSON = /* @__PURE__ */ __name((objOrMaybeString) => {
1298
- if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
1299
- return objOrMaybeString;
1300
- }
1301
- try {
1302
- const result = JSON.stringify(objOrMaybeString);
1303
- return result;
1304
- } catch (error) {
1305
- }
1306
- return "";
1307
- }, "maybeStringifyJSON");
1308
- var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
1309
- if (!objOrMaybeJSON) return {};
1310
- if (typeof objOrMaybeJSON === "string") {
1311
- try {
1312
- const cleanMarkdown = helpJsonMarkup(objOrMaybeJSON);
1313
- const result = JSON.parse(cleanMarkdown);
1314
- if (typeof result === "object" && result !== null) {
1315
- return result;
1316
- }
1317
- } catch (error) {
1318
- }
1319
- }
1320
- if (typeof objOrMaybeJSON === "object" && objOrMaybeJSON !== null) {
1321
- return objOrMaybeJSON;
1322
- }
1323
- return {};
1324
- }, "maybeParseJSON");
1325
- function isObjectStringified(maybeObject) {
1326
- if (typeof maybeObject !== "string") return false;
1327
- const isMaybeObject = maybeObject.substring(0, 1) === "{" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "}";
1328
- const isMaybeArray = maybeObject.substring(0, 1) === "[" && maybeObject.substring(maybeObject.length - 1, maybeObject.length) === "]";
1329
- if (!isMaybeObject && !isMaybeArray) {
1330
- return false;
1331
- }
1332
- let canDecode = false;
1333
- try {
1334
- JSON.parse(maybeObject);
1335
- canDecode = true;
1336
- } catch (error) {
1337
- canDecode = false;
1338
- }
1339
- return canDecode;
1406
+ // src/utils/modules/index.ts
1407
+ function registerHelpers(helpers) {
1408
+ hbs.registerHelpers(helpers);
1409
+ hbsAsync.registerHelpers(helpers);
1340
1410
  }
1341
- __name(isObjectStringified, "isObjectStringified");
1342
- function helpJsonMarkup(str) {
1343
- if (typeof str !== "string") {
1344
- return str;
1345
- }
1346
- const input = str.trim();
1347
- const markdownJsonStartsWith = "```json";
1348
- const markdownJsonEndsWith = "```";
1349
- if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(input.length - markdownJsonEndsWith.length, input.length) === markdownJsonEndsWith) {
1350
- return str.substring(markdownJsonStartsWith.length, input.length - markdownJsonEndsWith.length)?.trim();
1351
- }
1352
- return str;
1411
+ __name(registerHelpers, "registerHelpers");
1412
+ function registerPartials(partials2) {
1413
+ hbs.registerPartials(partials2);
1414
+ hbsAsync.registerPartials(partials2);
1353
1415
  }
1354
- __name(helpJsonMarkup, "helpJsonMarkup");
1416
+ __name(registerPartials, "registerPartials");
1355
1417
 
1356
1418
  // src/llm/output/_utils/getResultText.ts
1357
1419
  function getResultText(content) {
@@ -1370,7 +1432,7 @@ var _OpenAiFunctionParser = class _OpenAiFunctionParser extends BaseParser {
1370
1432
  this.parser = options.parser;
1371
1433
  }
1372
1434
  parse(text, _options) {
1373
- const functionUse = text.find((a) => a.type === "function_use");
1435
+ const functionUse = text?.find((a) => a.type === "function_use");
1374
1436
  if (functionUse && "name" in functionUse && "input" in functionUse) {
1375
1437
  return {
1376
1438
  name: functionUse.name,
@@ -1736,8 +1798,11 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
1736
1798
  }
1737
1799
  if (this.promptFn) {
1738
1800
  const prompt = this.promptFn(_input);
1739
- const promptFormatted = prompt.format(_input);
1740
- return promptFormatted;
1801
+ if (isPromise(prompt.formatAsync)) {
1802
+ return await prompt.formatAsync(_input);
1803
+ } else {
1804
+ return prompt.format(_input);
1805
+ }
1741
1806
  }
1742
1807
  throw new Error("Missing prompt");
1743
1808
  }
@@ -2103,7 +2168,8 @@ var anthropicChatV1 = {
2103
2168
  required: [
2104
2169
  true,
2105
2170
  "maxTokens required"
2106
- ]
2171
+ ],
2172
+ default: 4096
2107
2173
  },
2108
2174
  anthropicApiKey: {
2109
2175
  default: getEnvironmentVariable("ANTHROPIC_API_KEY")
@@ -2466,6 +2532,8 @@ function getOutputParser(config, response) {
2466
2532
  return OutputAnthropicClaude3Chat(response, config);
2467
2533
  case "amazon:meta.chat.v1":
2468
2534
  return OutputMetaLlama3Chat(response, config);
2535
+ // case "amazon:nova.chat.v1":
2536
+ // return OutputDefault(response, config);
2469
2537
  default: {
2470
2538
  if (config?.key?.startsWith("custom:")) {
2471
2539
  return OutputDefault(response, config);
@@ -2484,7 +2552,15 @@ async function apiRequest(url, options) {
2484
2552
  try {
2485
2553
  const response = await fetch(url, finalOptions);
2486
2554
  if (!response.ok) {
2487
- throw new Error(`HTTP error! Status: ${response.status}. Error`);
2555
+ let message = `HTTP error. Status: ${response.status}. Error Message: ${response?.statusText || "Unknown error."}`;
2556
+ if (url.startsWith("https://api.openai.com/")) {
2557
+ try {
2558
+ const body = await response.json();
2559
+ message = `HTTP error. Status Code: ${response.status}. Error Message: ${body?.error?.message || "No further details provided."}`;
2560
+ } catch (error) {
2561
+ }
2562
+ }
2563
+ throw new Error(message);
2488
2564
  }
2489
2565
  const responseData = await response.json();
2490
2566
  return responseData;
@@ -2495,23 +2571,6 @@ async function apiRequest(url, options) {
2495
2571
  }
2496
2572
  __name(apiRequest, "apiRequest");
2497
2573
 
2498
- // src/utils/modules/replaceTemplateStringSimple.ts
2499
- function replaceTemplateStringSimple(template, context) {
2500
- return template.replace(/{{\s*([\w.]+)\s*}}/g, (_match, key) => {
2501
- const keys = key.split(".");
2502
- let value = context;
2503
- for (const k of keys) {
2504
- if (value && typeof value === "object" && k in value) {
2505
- value = value[k];
2506
- } else {
2507
- return "";
2508
- }
2509
- }
2510
- return typeof value === "string" ? value : String(value);
2511
- });
2512
- }
2513
- __name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
2514
-
2515
2574
  // src/utils/modules/convertDotNotation.ts
2516
2575
  function convertDotNotation(obj) {
2517
2576
  const result = {};
@@ -2785,23 +2844,21 @@ __name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
2785
2844
  // src/llm/llm.call.ts
2786
2845
  async function useLlm_call(state, messages, _options) {
2787
2846
  const config = getLlmConfig(state.key);
2847
+ const { functionCallStrictInput = false } = _options || {};
2788
2848
  const input = mapBody(config.mapBody, Object.assign({}, state, {
2789
2849
  prompt: messages
2790
2850
  }));
2791
2851
  if (_options && _options?.jsonSchema) {
2792
2852
  if (state.provider === "openai.chat") {
2793
2853
  const curr = input["response_format"] || {};
2794
- const newObj = Object.assign(curr, {
2854
+ input["response_format"] = Object.assign(curr, {
2795
2855
  type: "json_schema",
2796
2856
  json_schema: {
2797
2857
  name: "output",
2858
+ strict: !!functionCallStrictInput,
2798
2859
  schema: cleanJsonSchemaFor(_options?.jsonSchema, "openai.chat")
2799
2860
  }
2800
2861
  });
2801
- if (typeof _options?.functionCallStrictInput === "undefined" || !!_options?.functionCallStrictInput) {
2802
- newObj["json_schema"]["strict"] = true;
2803
- }
2804
- input["response_format"] = newObj;
2805
2862
  }
2806
2863
  }
2807
2864
  if (_options && _options?.functionCall) {
@@ -2838,7 +2895,7 @@ async function useLlm_call(state, messages, _options) {
2838
2895
  function: Object.assign(props, {
2839
2896
  parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
2840
2897
  }, {
2841
- strict: true
2898
+ strict: functionCallStrictInput
2842
2899
  })
2843
2900
  };
2844
2901
  });
@@ -3016,9 +3073,13 @@ var embeddingConfigs = {
3016
3073
  headers: `{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json" }`,
3017
3074
  options: {
3018
3075
  input: {},
3019
- dimensions: {},
3076
+ dimensions: {
3077
+ default: 1536
3078
+ },
3020
3079
  encodingFormat: {},
3021
- openAiApiKey: {}
3080
+ openAiApiKey: {
3081
+ default: getEnvironmentVariable("OPENAI_API_KEY")
3082
+ }
3022
3083
  },
3023
3084
  mapBody: {
3024
3085
  input: {
@@ -3043,7 +3104,9 @@ var embeddingConfigs = {
3043
3104
  headers: `{"Content-Type": "application/json" }`,
3044
3105
  options: {
3045
3106
  input: {},
3046
- dimensions: {},
3107
+ dimensions: {
3108
+ default: 512
3109
+ },
3047
3110
  awsRegion: {
3048
3111
  default: getEnvironmentVariable("AWS_REGION"),
3049
3112
  required: [
@@ -4167,10 +4230,6 @@ function createStateItem(name, defaultValue) {
4167
4230
  return new DefaultStateItem(name, defaultValue);
4168
4231
  }
4169
4232
  __name(createStateItem, "createStateItem");
4170
-
4171
- // src/index.ts
4172
- var llmExe = {};
4173
- var src_default = llmExe;
4174
4233
  // Annotate the CommonJS export names for ESM import in node:
4175
4234
  0 && (module.exports = {
4176
4235
  BaseExecutor,