llm-exe 2.0.0-beta.8 → 2.0.0-beta.9

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.d.mts CHANGED
@@ -1221,6 +1221,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1221
1221
  };
1222
1222
  };
1223
1223
 
1224
- declare const llmExe: {};
1225
-
1226
- export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, llmExe as default, useExecutors, useLlm, index as utils };
1224
+ export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
package/dist/index.d.ts CHANGED
@@ -1221,6 +1221,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1221
1221
  };
1222
1222
  };
1223
1223
 
1224
- declare const llmExe: {};
1225
-
1226
- export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, llmExe as default, useExecutors, useLlm, index as utils };
1224
+ export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
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,8 +498,8 @@ 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"));
501
+ // src/utils/modules/handlebars/hbs.ts
502
+ var import_handlebars = __toESM(require("handlebars"));
504
503
 
505
504
  // src/utils/modules/handlebars/helpers/index.ts
506
505
  var helpers_exports = {};
@@ -818,109 +817,6 @@ var partials = {
818
817
  ThoughtActionResult
819
818
  };
820
819
 
821
- // src/utils/modules/isPromise.ts
822
- function isPromise(value) {
823
- if (typeof value === "object" && value !== null && typeof value.then === "function") {
824
- return true;
825
- }
826
- return Object.prototype.toString.call(value) === "[object AsyncFunction]";
827
- }
828
- __name(isPromise, "isPromise");
829
-
830
- // src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
831
- function makeHandlebarsInstanceAsync(hbs2) {
832
- var _a;
833
- 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
- ];
865
- }
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);
880
- }
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
- };
892
- }
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
- return handlebars;
921
- }
922
- __name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
923
-
924
820
  // src/utils/modules/handlebars/utils/appendContextPath.ts
925
821
  function appendContextPath(contextPath, id) {
926
822
  return (contextPath ? `${contextPath}.` : "") + id;
@@ -971,15 +867,24 @@ function isEmpty(value) {
971
867
  }
972
868
  __name(isEmpty, "isEmpty");
973
869
 
870
+ // src/utils/modules/isPromise.ts
871
+ function isPromise(value) {
872
+ if (typeof value === "object" && value !== null && typeof value.then === "function") {
873
+ return true;
874
+ }
875
+ return Object.prototype.toString.call(value) === "[object AsyncFunction]";
876
+ }
877
+ __name(isPromise, "isPromise");
878
+
974
879
  // src/utils/modules/handlebars/helpers/async/with.ts
975
880
  async function withFnAsync(context, options) {
976
881
  if (arguments.length !== 2) {
977
882
  throw new Error("#with requires exactly one argument");
978
883
  }
979
- if (typeof context === "function") {
980
- context = context.call(this);
981
- } else if (isPromise(context)) {
884
+ if (isPromise(context)) {
982
885
  context = await context;
886
+ } else if (typeof context === "function") {
887
+ context = context.call(this);
983
888
  }
984
889
  const { fn } = options;
985
890
  if (!isEmpty(context)) {
@@ -1006,10 +911,10 @@ async function ifFnAsync(conditional, options) {
1006
911
  if (arguments.length !== 2) {
1007
912
  throw new Error("#if requires exactly one argument");
1008
913
  }
1009
- if (typeof conditional === "function") {
1010
- conditional = conditional.call(this);
1011
- } else if (isPromise(conditional)) {
914
+ if (isPromise(conditional)) {
1012
915
  conditional = await conditional;
916
+ } else if (typeof conditional === "function") {
917
+ conditional = conditional.call(this);
1013
918
  }
1014
919
  if (!options.hash.includeZero && !conditional || isEmpty(conditional)) {
1015
920
  return options.inverse(this);
@@ -1026,7 +931,7 @@ function isReadableStream(obj) {
1026
931
  __name(isReadableStream, "isReadableStream");
1027
932
 
1028
933
  // src/utils/modules/handlebars/helpers/async/each.ts
1029
- async function eachFnAsync(context, options) {
934
+ async function eachFnAsync(arg1, options) {
1030
935
  if (!options) {
1031
936
  throw new Error("Must pass iterator to #each");
1032
937
  }
@@ -1039,8 +944,8 @@ async function eachFnAsync(context, options) {
1039
944
  if (options.data && options.ids) {
1040
945
  contextPath = `${appendContextPath(options.data.contextPath, options.ids[0])}.`;
1041
946
  }
1042
- if (typeof context === "function") {
1043
- context = context.call(this);
947
+ if (typeof arg1 === "function") {
948
+ arg1 = arg1.call(this);
1044
949
  }
1045
950
  if (options.data) {
1046
951
  data = createFrame(options.data);
@@ -1055,10 +960,10 @@ async function eachFnAsync(context, options) {
1055
960
  data.contextPath = contextPath + field;
1056
961
  }
1057
962
  }
1058
- ret.push(await fn(context[field], {
963
+ ret.push(await fn(arg1[field], {
1059
964
  data,
1060
965
  blockParams: blockParams([
1061
- context[field],
966
+ arg1[field],
1062
967
  field
1063
968
  ], [
1064
969
  contextPath + field,
@@ -1067,41 +972,41 @@ async function eachFnAsync(context, options) {
1067
972
  }));
1068
973
  }
1069
974
  __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);
975
+ if (isPromise(arg1)) {
976
+ arg1 = await arg1;
977
+ }
978
+ if (arg1 && typeof arg1 === "object") {
979
+ if (Array.isArray(arg1)) {
980
+ for (let j = arg1.length; i < j; i++) {
981
+ if (i in arg1) {
982
+ await execIteration(i, i, i === arg1.length - 1);
1078
983
  }
1079
984
  }
1080
- } else if (global.Symbol && context[global.Symbol.iterator]) {
1081
- const newContext = [], iterator = context[global.Symbol.iterator]();
985
+ } else if (global.Symbol && arg1[global.Symbol.iterator]) {
986
+ const newContext = [], iterator = arg1[global.Symbol.iterator]();
1082
987
  for (let it = iterator.next(); !it.done; it = iterator.next()) {
1083
988
  newContext.push(it.value);
1084
989
  }
1085
- context = newContext;
1086
- for (let j = context.length; i < j; i++) {
1087
- await execIteration(i, i, i === context.length - 1);
990
+ arg1 = newContext;
991
+ for (let j = arg1.length; i < j; i++) {
992
+ await execIteration(i, i, i === arg1.length - 1);
1088
993
  }
1089
- } else if (isReadableStream(context)) {
994
+ } else if (isReadableStream(arg1)) {
1090
995
  const newContext = [];
1091
996
  await new Promise((resolve, reject) => {
1092
- context.on("data", (item) => {
997
+ arg1.on("data", (item) => {
1093
998
  newContext.push(item);
1094
999
  }).on("end", async () => {
1095
- context = newContext;
1096
- for (let j = context.length; i < j; i++) {
1097
- await execIteration(i, i, i === context.length - 1);
1000
+ arg1 = newContext;
1001
+ for (let j = arg1.length; i < j; i++) {
1002
+ await execIteration(i, i, i === arg1.length - 1);
1098
1003
  }
1099
1004
  resolve(true);
1100
1005
  }).once("error", (e) => reject(e));
1101
1006
  });
1102
1007
  } else {
1103
1008
  let priorKey;
1104
- for (const key of Object.keys(context)) {
1009
+ for (const key of Object.keys(arg1)) {
1105
1010
  if (priorKey !== void 0) {
1106
1011
  await execIteration(priorKey, i - 1);
1107
1012
  }
@@ -1154,9 +1059,7 @@ function getEnvironmentVariable(name) {
1154
1059
  }
1155
1060
  __name(getEnvironmentVariable, "getEnvironmentVariable");
1156
1061
 
1157
- // src/utils/modules/handlebars/index.ts
1158
- var __hbsAsync = makeHandlebarsInstanceAsync(import_handlebars3.default);
1159
- var __hbs = import_handlebars3.default;
1062
+ // src/utils/modules/handlebars/useHandlebars.ts
1160
1063
  function useHandlebars(hbsInstance, preferAsync = false) {
1161
1064
  hbsInstance.registerHelper("with", function(context, options) {
1162
1065
  return options.fn(context);
@@ -1211,8 +1114,106 @@ function useHandlebars(hbsInstance, preferAsync = false) {
1211
1114
  return hbsInstance;
1212
1115
  }
1213
1116
  __name(useHandlebars, "useHandlebars");
1214
- var hbsAsync = useHandlebars(__hbsAsync);
1117
+
1118
+ // src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
1119
+ function makeHandlebarsInstanceAsync(hbs2) {
1120
+ var _a;
1121
+ const handlebars = hbs2.create();
1122
+ const asyncCompiler = (_a = class extends hbs2.JavaScriptCompiler {
1123
+ constructor() {
1124
+ super();
1125
+ this.compiler = asyncCompiler;
1126
+ }
1127
+ mergeSource(varDeclarations) {
1128
+ const sources = super.mergeSource(varDeclarations);
1129
+ sources.prepend("return (async () => {");
1130
+ sources.add(" })()");
1131
+ return sources;
1132
+ }
1133
+ appendToBuffer(source, location, explicit) {
1134
+ if (!Array.isArray(source)) {
1135
+ source = [
1136
+ source
1137
+ ];
1138
+ }
1139
+ source = this.source.wrap(source, location);
1140
+ if (this.environment.isSimple) {
1141
+ return [
1142
+ "return await ",
1143
+ source,
1144
+ ";"
1145
+ ];
1146
+ }
1147
+ if (explicit) {
1148
+ return [
1149
+ "buffer += await ",
1150
+ source,
1151
+ ";"
1152
+ ];
1153
+ }
1154
+ source.appendToBuffer = true;
1155
+ source.prepend("await ");
1156
+ return source;
1157
+ }
1158
+ }, __name(_a, "asyncCompiler"), _a);
1159
+ handlebars.JavaScriptCompiler = asyncCompiler;
1160
+ const _compile = handlebars.compile;
1161
+ const _template = handlebars.VM.template;
1162
+ const _escapeExpression = handlebars.escapeExpression;
1163
+ function escapeExpression(value) {
1164
+ if (isPromise(value)) {
1165
+ return value.then((v) => _escapeExpression(v));
1166
+ }
1167
+ return _escapeExpression(value);
1168
+ }
1169
+ __name(escapeExpression, "escapeExpression");
1170
+ function lookupProperty(containerLookupProperty) {
1171
+ return function(parent, propertyName) {
1172
+ if (isPromise(parent)) {
1173
+ if (typeof parent?.then === "function") {
1174
+ return parent.then((p) => containerLookupProperty(p, propertyName));
1175
+ }
1176
+ return parent().then((p) => containerLookupProperty(p, propertyName));
1177
+ }
1178
+ return containerLookupProperty(parent, propertyName);
1179
+ };
1180
+ }
1181
+ __name(lookupProperty, "lookupProperty");
1182
+ handlebars.template = function(spec) {
1183
+ spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
1184
+ container.escapeExpression = escapeExpression;
1185
+ container.lookupProperty = lookupProperty(container.lookupProperty);
1186
+ if (depths.length == 0) {
1187
+ depths = [
1188
+ data.root
1189
+ ];
1190
+ }
1191
+ const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
1192
+ return v;
1193
+ };
1194
+ return _template(spec, handlebars);
1195
+ };
1196
+ handlebars.compile = function(template, options) {
1197
+ const compiled = _compile.apply(handlebars, [
1198
+ template,
1199
+ {
1200
+ ...options
1201
+ }
1202
+ ]);
1203
+ return function(context, execOptions) {
1204
+ context = context || {};
1205
+ return compiled.call(handlebars, context, execOptions);
1206
+ };
1207
+ };
1208
+ return handlebars;
1209
+ }
1210
+ __name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
1211
+
1212
+ // src/utils/modules/handlebars/hbs.ts
1213
+ var __hbsAsync = makeHandlebarsInstanceAsync(import_handlebars.default);
1214
+ var __hbs = import_handlebars.default.create();
1215
1215
  var hbs = useHandlebars(__hbs);
1216
+ var hbsAsync = useHandlebars(__hbsAsync, true);
1216
1217
  function registerPartials(partials2, instance) {
1217
1218
  if (partials2 && Array.isArray(partials2)) {
1218
1219
  for (const partial of partials2) {
@@ -2844,7 +2845,7 @@ async function useLlm_call(state, messages, _options) {
2844
2845
  });
2845
2846
  }
2846
2847
  }
2847
- const body = JSON.stringify(input);
2848
+ const body = typeof input === "string" ? input : JSON.stringify(input);
2848
2849
  const url = replaceTemplateStringSimple(config.endpoint, state);
2849
2850
  const headers = await parseHeaders(config, state, {
2850
2851
  url,
@@ -3172,7 +3173,7 @@ async function createEmbedding_call(state, _input, _options) {
3172
3173
  const input = mapBody(config.mapBody, Object.assign({}, state, {
3173
3174
  input: _input
3174
3175
  }));
3175
- const body = JSON.stringify(input);
3176
+ const body = typeof input === "string" ? input : JSON.stringify(input);
3176
3177
  const url = replaceTemplateStringSimple(config.endpoint, state);
3177
3178
  const headers = await parseHeaders(config, state, {
3178
3179
  url,
@@ -4167,10 +4168,6 @@ function createStateItem(name, defaultValue) {
4167
4168
  return new DefaultStateItem(name, defaultValue);
4168
4169
  }
4169
4170
  __name(createStateItem, "createStateItem");
4170
-
4171
- // src/index.ts
4172
- var llmExe = {};
4173
- var src_default = llmExe;
4174
4171
  // Annotate the CommonJS export names for ESM import in node:
4175
4172
  0 && (module.exports = {
4176
4173
  BaseExecutor,
package/dist/index.mjs CHANGED
@@ -450,7 +450,7 @@ function importHelpers(_helpers) {
450
450
  }
451
451
  __name(importHelpers, "importHelpers");
452
452
 
453
- // src/utils/modules/handlebars/index.ts
453
+ // src/utils/modules/handlebars/hbs.ts
454
454
  import Handlebars from "handlebars";
455
455
 
456
456
  // src/utils/modules/handlebars/helpers/index.ts
@@ -769,109 +769,6 @@ var partials = {
769
769
  ThoughtActionResult
770
770
  };
771
771
 
772
- // src/utils/modules/isPromise.ts
773
- function isPromise(value) {
774
- if (typeof value === "object" && value !== null && typeof value.then === "function") {
775
- return true;
776
- }
777
- return Object.prototype.toString.call(value) === "[object AsyncFunction]";
778
- }
779
- __name(isPromise, "isPromise");
780
-
781
- // src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
782
- function makeHandlebarsInstanceAsync(hbs2) {
783
- var _a;
784
- const handlebars = hbs2.create();
785
- const asyncCompiler = (_a = class extends hbs2.JavaScriptCompiler {
786
- constructor() {
787
- super();
788
- this.compiler = asyncCompiler;
789
- }
790
- mergeSource(varDeclarations) {
791
- const sources = super.mergeSource(varDeclarations);
792
- sources.prepend("return (async () => {");
793
- sources.add(" })()");
794
- return sources;
795
- }
796
- appendToBuffer(source, location, explicit) {
797
- if (!Array.isArray(source)) {
798
- source = [
799
- source
800
- ];
801
- }
802
- source = this.source.wrap(source, location);
803
- if (this.environment.isSimple) {
804
- return [
805
- "return await ",
806
- source,
807
- ";"
808
- ];
809
- }
810
- if (explicit) {
811
- return [
812
- "buffer += await ",
813
- source,
814
- ";"
815
- ];
816
- }
817
- source.appendToBuffer = true;
818
- source.prepend("await ");
819
- return source;
820
- }
821
- }, __name(_a, "asyncCompiler"), _a);
822
- handlebars.JavaScriptCompiler = asyncCompiler;
823
- const _compile = handlebars.compile;
824
- const _template = handlebars.VM.template;
825
- const _escapeExpression = handlebars.escapeExpression;
826
- function escapeExpression(value) {
827
- if (isPromise(value)) {
828
- return value.then((v) => _escapeExpression(v));
829
- }
830
- return _escapeExpression(value);
831
- }
832
- __name(escapeExpression, "escapeExpression");
833
- function lookupProperty(containerLookupProperty) {
834
- return function(parent, propertyName) {
835
- if (isPromise(parent)) {
836
- if (typeof parent?.then === "function") {
837
- return parent.then((p) => containerLookupProperty(p, propertyName));
838
- }
839
- return parent().then((p) => containerLookupProperty(p, propertyName));
840
- }
841
- return containerLookupProperty(parent, propertyName);
842
- };
843
- }
844
- __name(lookupProperty, "lookupProperty");
845
- handlebars.template = function(spec) {
846
- spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
847
- container.escapeExpression = escapeExpression;
848
- container.lookupProperty = lookupProperty(container.lookupProperty);
849
- if (depths.length == 0) {
850
- depths = [
851
- data.root
852
- ];
853
- }
854
- const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
855
- return v;
856
- };
857
- return _template(spec, handlebars);
858
- };
859
- handlebars.compile = function(template, options) {
860
- const compiled = _compile.apply(handlebars, [
861
- template,
862
- {
863
- ...options
864
- }
865
- ]);
866
- return function(context, execOptions) {
867
- context = context || {};
868
- return compiled.call(handlebars, context, execOptions);
869
- };
870
- };
871
- return handlebars;
872
- }
873
- __name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
874
-
875
772
  // src/utils/modules/handlebars/utils/appendContextPath.ts
876
773
  function appendContextPath(contextPath, id) {
877
774
  return (contextPath ? `${contextPath}.` : "") + id;
@@ -922,15 +819,24 @@ function isEmpty(value) {
922
819
  }
923
820
  __name(isEmpty, "isEmpty");
924
821
 
822
+ // src/utils/modules/isPromise.ts
823
+ function isPromise(value) {
824
+ if (typeof value === "object" && value !== null && typeof value.then === "function") {
825
+ return true;
826
+ }
827
+ return Object.prototype.toString.call(value) === "[object AsyncFunction]";
828
+ }
829
+ __name(isPromise, "isPromise");
830
+
925
831
  // src/utils/modules/handlebars/helpers/async/with.ts
926
832
  async function withFnAsync(context, options) {
927
833
  if (arguments.length !== 2) {
928
834
  throw new Error("#with requires exactly one argument");
929
835
  }
930
- if (typeof context === "function") {
931
- context = context.call(this);
932
- } else if (isPromise(context)) {
836
+ if (isPromise(context)) {
933
837
  context = await context;
838
+ } else if (typeof context === "function") {
839
+ context = context.call(this);
934
840
  }
935
841
  const { fn } = options;
936
842
  if (!isEmpty(context)) {
@@ -957,10 +863,10 @@ async function ifFnAsync(conditional, options) {
957
863
  if (arguments.length !== 2) {
958
864
  throw new Error("#if requires exactly one argument");
959
865
  }
960
- if (typeof conditional === "function") {
961
- conditional = conditional.call(this);
962
- } else if (isPromise(conditional)) {
866
+ if (isPromise(conditional)) {
963
867
  conditional = await conditional;
868
+ } else if (typeof conditional === "function") {
869
+ conditional = conditional.call(this);
964
870
  }
965
871
  if (!options.hash.includeZero && !conditional || isEmpty(conditional)) {
966
872
  return options.inverse(this);
@@ -977,7 +883,7 @@ function isReadableStream(obj) {
977
883
  __name(isReadableStream, "isReadableStream");
978
884
 
979
885
  // src/utils/modules/handlebars/helpers/async/each.ts
980
- async function eachFnAsync(context, options) {
886
+ async function eachFnAsync(arg1, options) {
981
887
  if (!options) {
982
888
  throw new Error("Must pass iterator to #each");
983
889
  }
@@ -990,8 +896,8 @@ async function eachFnAsync(context, options) {
990
896
  if (options.data && options.ids) {
991
897
  contextPath = `${appendContextPath(options.data.contextPath, options.ids[0])}.`;
992
898
  }
993
- if (typeof context === "function") {
994
- context = context.call(this);
899
+ if (typeof arg1 === "function") {
900
+ arg1 = arg1.call(this);
995
901
  }
996
902
  if (options.data) {
997
903
  data = createFrame(options.data);
@@ -1006,10 +912,10 @@ async function eachFnAsync(context, options) {
1006
912
  data.contextPath = contextPath + field;
1007
913
  }
1008
914
  }
1009
- ret.push(await fn(context[field], {
915
+ ret.push(await fn(arg1[field], {
1010
916
  data,
1011
917
  blockParams: blockParams([
1012
- context[field],
918
+ arg1[field],
1013
919
  field
1014
920
  ], [
1015
921
  contextPath + field,
@@ -1018,41 +924,41 @@ async function eachFnAsync(context, options) {
1018
924
  }));
1019
925
  }
1020
926
  __name(execIteration, "execIteration");
1021
- if (context && typeof context === "object") {
1022
- if (isPromise(context)) {
1023
- context = await context;
1024
- }
1025
- if (Array.isArray(context)) {
1026
- for (let j = context.length; i < j; i++) {
1027
- if (i in context) {
1028
- await execIteration(i, i, i === context.length - 1);
927
+ if (isPromise(arg1)) {
928
+ arg1 = await arg1;
929
+ }
930
+ if (arg1 && typeof arg1 === "object") {
931
+ if (Array.isArray(arg1)) {
932
+ for (let j = arg1.length; i < j; i++) {
933
+ if (i in arg1) {
934
+ await execIteration(i, i, i === arg1.length - 1);
1029
935
  }
1030
936
  }
1031
- } else if (global.Symbol && context[global.Symbol.iterator]) {
1032
- const newContext = [], iterator = context[global.Symbol.iterator]();
937
+ } else if (global.Symbol && arg1[global.Symbol.iterator]) {
938
+ const newContext = [], iterator = arg1[global.Symbol.iterator]();
1033
939
  for (let it = iterator.next(); !it.done; it = iterator.next()) {
1034
940
  newContext.push(it.value);
1035
941
  }
1036
- context = newContext;
1037
- for (let j = context.length; i < j; i++) {
1038
- await execIteration(i, i, i === context.length - 1);
942
+ arg1 = newContext;
943
+ for (let j = arg1.length; i < j; i++) {
944
+ await execIteration(i, i, i === arg1.length - 1);
1039
945
  }
1040
- } else if (isReadableStream(context)) {
946
+ } else if (isReadableStream(arg1)) {
1041
947
  const newContext = [];
1042
948
  await new Promise((resolve, reject) => {
1043
- context.on("data", (item) => {
949
+ arg1.on("data", (item) => {
1044
950
  newContext.push(item);
1045
951
  }).on("end", async () => {
1046
- context = newContext;
1047
- for (let j = context.length; i < j; i++) {
1048
- await execIteration(i, i, i === context.length - 1);
952
+ arg1 = newContext;
953
+ for (let j = arg1.length; i < j; i++) {
954
+ await execIteration(i, i, i === arg1.length - 1);
1049
955
  }
1050
956
  resolve(true);
1051
957
  }).once("error", (e) => reject(e));
1052
958
  });
1053
959
  } else {
1054
960
  let priorKey;
1055
- for (const key of Object.keys(context)) {
961
+ for (const key of Object.keys(arg1)) {
1056
962
  if (priorKey !== void 0) {
1057
963
  await execIteration(priorKey, i - 1);
1058
964
  }
@@ -1105,9 +1011,7 @@ function getEnvironmentVariable(name) {
1105
1011
  }
1106
1012
  __name(getEnvironmentVariable, "getEnvironmentVariable");
1107
1013
 
1108
- // src/utils/modules/handlebars/index.ts
1109
- var __hbsAsync = makeHandlebarsInstanceAsync(Handlebars);
1110
- var __hbs = Handlebars;
1014
+ // src/utils/modules/handlebars/useHandlebars.ts
1111
1015
  function useHandlebars(hbsInstance, preferAsync = false) {
1112
1016
  hbsInstance.registerHelper("with", function(context, options) {
1113
1017
  return options.fn(context);
@@ -1162,8 +1066,106 @@ function useHandlebars(hbsInstance, preferAsync = false) {
1162
1066
  return hbsInstance;
1163
1067
  }
1164
1068
  __name(useHandlebars, "useHandlebars");
1165
- var hbsAsync = useHandlebars(__hbsAsync);
1069
+
1070
+ // src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
1071
+ function makeHandlebarsInstanceAsync(hbs2) {
1072
+ var _a;
1073
+ const handlebars = hbs2.create();
1074
+ const asyncCompiler = (_a = class extends hbs2.JavaScriptCompiler {
1075
+ constructor() {
1076
+ super();
1077
+ this.compiler = asyncCompiler;
1078
+ }
1079
+ mergeSource(varDeclarations) {
1080
+ const sources = super.mergeSource(varDeclarations);
1081
+ sources.prepend("return (async () => {");
1082
+ sources.add(" })()");
1083
+ return sources;
1084
+ }
1085
+ appendToBuffer(source, location, explicit) {
1086
+ if (!Array.isArray(source)) {
1087
+ source = [
1088
+ source
1089
+ ];
1090
+ }
1091
+ source = this.source.wrap(source, location);
1092
+ if (this.environment.isSimple) {
1093
+ return [
1094
+ "return await ",
1095
+ source,
1096
+ ";"
1097
+ ];
1098
+ }
1099
+ if (explicit) {
1100
+ return [
1101
+ "buffer += await ",
1102
+ source,
1103
+ ";"
1104
+ ];
1105
+ }
1106
+ source.appendToBuffer = true;
1107
+ source.prepend("await ");
1108
+ return source;
1109
+ }
1110
+ }, __name(_a, "asyncCompiler"), _a);
1111
+ handlebars.JavaScriptCompiler = asyncCompiler;
1112
+ const _compile = handlebars.compile;
1113
+ const _template = handlebars.VM.template;
1114
+ const _escapeExpression = handlebars.escapeExpression;
1115
+ function escapeExpression(value) {
1116
+ if (isPromise(value)) {
1117
+ return value.then((v) => _escapeExpression(v));
1118
+ }
1119
+ return _escapeExpression(value);
1120
+ }
1121
+ __name(escapeExpression, "escapeExpression");
1122
+ function lookupProperty(containerLookupProperty) {
1123
+ return function(parent, propertyName) {
1124
+ if (isPromise(parent)) {
1125
+ if (typeof parent?.then === "function") {
1126
+ return parent.then((p) => containerLookupProperty(p, propertyName));
1127
+ }
1128
+ return parent().then((p) => containerLookupProperty(p, propertyName));
1129
+ }
1130
+ return containerLookupProperty(parent, propertyName);
1131
+ };
1132
+ }
1133
+ __name(lookupProperty, "lookupProperty");
1134
+ handlebars.template = function(spec) {
1135
+ spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
1136
+ container.escapeExpression = escapeExpression;
1137
+ container.lookupProperty = lookupProperty(container.lookupProperty);
1138
+ if (depths.length == 0) {
1139
+ depths = [
1140
+ data.root
1141
+ ];
1142
+ }
1143
+ const v = spec.main(container, context, container.helpers, container.partials, data, blockParams2, depths);
1144
+ return v;
1145
+ };
1146
+ return _template(spec, handlebars);
1147
+ };
1148
+ handlebars.compile = function(template, options) {
1149
+ const compiled = _compile.apply(handlebars, [
1150
+ template,
1151
+ {
1152
+ ...options
1153
+ }
1154
+ ]);
1155
+ return function(context, execOptions) {
1156
+ context = context || {};
1157
+ return compiled.call(handlebars, context, execOptions);
1158
+ };
1159
+ };
1160
+ return handlebars;
1161
+ }
1162
+ __name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
1163
+
1164
+ // src/utils/modules/handlebars/hbs.ts
1165
+ var __hbsAsync = makeHandlebarsInstanceAsync(Handlebars);
1166
+ var __hbs = Handlebars.create();
1166
1167
  var hbs = useHandlebars(__hbs);
1168
+ var hbsAsync = useHandlebars(__hbsAsync, true);
1167
1169
  function registerPartials(partials2, instance) {
1168
1170
  if (partials2 && Array.isArray(partials2)) {
1169
1171
  for (const partial of partials2) {
@@ -2795,7 +2797,7 @@ async function useLlm_call(state, messages, _options) {
2795
2797
  });
2796
2798
  }
2797
2799
  }
2798
- const body = JSON.stringify(input);
2800
+ const body = typeof input === "string" ? input : JSON.stringify(input);
2799
2801
  const url = replaceTemplateStringSimple(config.endpoint, state);
2800
2802
  const headers = await parseHeaders(config, state, {
2801
2803
  url,
@@ -3123,7 +3125,7 @@ async function createEmbedding_call(state, _input, _options) {
3123
3125
  const input = mapBody(config.mapBody, Object.assign({}, state, {
3124
3126
  input: _input
3125
3127
  }));
3126
- const body = JSON.stringify(input);
3128
+ const body = typeof input === "string" ? input : JSON.stringify(input);
3127
3129
  const url = replaceTemplateStringSimple(config.endpoint, state);
3128
3130
  const headers = await parseHeaders(config, state, {
3129
3131
  url,
@@ -4118,10 +4120,6 @@ function createStateItem(name, defaultValue) {
4118
4120
  return new DefaultStateItem(name, defaultValue);
4119
4121
  }
4120
4122
  __name(createStateItem, "createStateItem");
4121
-
4122
- // src/index.ts
4123
- var llmExe = {};
4124
- var src_default = llmExe;
4125
4123
  export {
4126
4124
  BaseExecutor,
4127
4125
  BaseParser,
@@ -4145,7 +4143,6 @@ export {
4145
4143
  createPrompt,
4146
4144
  createState,
4147
4145
  createStateItem,
4148
- src_default as default,
4149
4146
  useExecutors,
4150
4147
  useLlm,
4151
4148
  utils_exports as utils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-exe",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "Simplify building LLM-powered apps with easy-to-use base components, supporting text and chat-based prompts with handlebars template engine, output parsers, and flexible function calling capabilities.",
5
5
  "keywords": [
6
6
  "ai",
package/readme.md CHANGED
@@ -26,7 +26,7 @@ npm i llm-exe
26
26
  ```
27
27
 
28
28
  ```typescript
29
- import * as llmExe from "llm-exe"
29
+ import llmExe from "llm-exe"
30
30
 
31
31
  // or
32
32