llmist 1.4.0 → 1.5.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/cli.cjs CHANGED
@@ -830,38 +830,83 @@ function formatParamsAsBlock(params, prefix = "", argPrefix = GADGET_ARG_PREFIX)
830
830
  }
831
831
  return lines.join("\n");
832
832
  }
833
- function formatSchemaAsPlainText(schema, indent = "") {
833
+ function formatParamLine(key, propObj, isRequired, indent = "") {
834
+ const type = propObj.type;
835
+ const description = propObj.description;
836
+ const enumValues = propObj.enum;
837
+ let line = `${indent}- ${key}`;
838
+ if (type === "array") {
839
+ const items = propObj.items;
840
+ const itemType = items?.type || "any";
841
+ line += ` (array of ${itemType})`;
842
+ } else if (type === "object" && propObj.properties) {
843
+ line += " (object)";
844
+ } else {
845
+ line += ` (${type})`;
846
+ }
847
+ if (isRequired && indent !== "") {
848
+ line += " [required]";
849
+ }
850
+ if (description) {
851
+ line += `: ${description}`;
852
+ }
853
+ if (enumValues) {
854
+ line += ` - one of: ${enumValues.map((v) => `"${v}"`).join(", ")}`;
855
+ }
856
+ return line;
857
+ }
858
+ function formatSchemaAsPlainText(schema, indent = "", atRoot = true) {
834
859
  const lines = [];
835
860
  const properties = schema.properties || {};
836
861
  const required = schema.required || [];
837
- for (const [key, prop] of Object.entries(properties)) {
838
- const propObj = prop;
839
- const type = propObj.type;
840
- const description = propObj.description;
841
- const isRequired = required.includes(key);
842
- const enumValues = propObj.enum;
843
- let line = `${indent}- ${key}`;
844
- if (type === "array") {
845
- const items = propObj.items;
846
- const itemType = items?.type || "any";
847
- line += ` (array of ${itemType})`;
848
- } else if (type === "object" && propObj.properties) {
849
- line += " (object)";
850
- } else {
851
- line += ` (${type})`;
862
+ if (atRoot && indent === "") {
863
+ const requiredProps = [];
864
+ const optionalProps = [];
865
+ for (const [key, prop] of Object.entries(properties)) {
866
+ if (required.includes(key)) {
867
+ requiredProps.push([key, prop]);
868
+ } else {
869
+ optionalProps.push([key, prop]);
870
+ }
852
871
  }
853
- if (isRequired) {
854
- line += " [required]";
872
+ const reqCount = requiredProps.length;
873
+ const optCount = optionalProps.length;
874
+ if (reqCount > 0 || optCount > 0) {
875
+ const parts = [];
876
+ if (reqCount > 0) parts.push(`${reqCount} required`);
877
+ if (optCount > 0) parts.push(`${optCount} optional`);
878
+ lines.push(parts.join(", "));
879
+ lines.push("");
855
880
  }
856
- if (description) {
857
- line += `: ${description}`;
881
+ if (reqCount > 0) {
882
+ lines.push("REQUIRED Parameters:");
883
+ for (const [key, prop] of requiredProps) {
884
+ lines.push(formatParamLine(key, prop, true, ""));
885
+ const propObj = prop;
886
+ if (propObj.type === "object" && propObj.properties) {
887
+ lines.push(formatSchemaAsPlainText(propObj, " ", false));
888
+ }
889
+ }
858
890
  }
859
- if (enumValues) {
860
- line += ` - one of: ${enumValues.map((v) => `"${v}"`).join(", ")}`;
891
+ if (optCount > 0) {
892
+ if (reqCount > 0) lines.push("");
893
+ lines.push("OPTIONAL Parameters:");
894
+ for (const [key, prop] of optionalProps) {
895
+ lines.push(formatParamLine(key, prop, false, ""));
896
+ const propObj = prop;
897
+ if (propObj.type === "object" && propObj.properties) {
898
+ lines.push(formatSchemaAsPlainText(propObj, " ", false));
899
+ }
900
+ }
861
901
  }
862
- lines.push(line);
863
- if (type === "object" && propObj.properties) {
864
- lines.push(formatSchemaAsPlainText(propObj, indent + " "));
902
+ return lines.join("\n");
903
+ }
904
+ for (const [key, prop] of Object.entries(properties)) {
905
+ const isRequired = required.includes(key);
906
+ lines.push(formatParamLine(key, prop, isRequired, indent));
907
+ const propObj = prop;
908
+ if (propObj.type === "object" && propObj.properties) {
909
+ lines.push(formatSchemaAsPlainText(propObj, indent + " ", false));
865
910
  }
866
911
  }
867
912
  return lines.join("\n");
@@ -912,10 +957,11 @@ var init_gadget = __esm({
912
957
  * Generate instruction text for the LLM.
913
958
  * Combines name, description, and parameter schema into a formatted instruction.
914
959
  *
915
- * @param argPrefix - Optional custom argument prefix for block format examples
960
+ * @param optionsOrArgPrefix - Optional custom prefixes for examples, or just argPrefix string for backwards compatibility
916
961
  * @returns Formatted instruction string
917
962
  */
918
- getInstruction(argPrefix) {
963
+ getInstruction(optionsOrArgPrefix) {
964
+ const options = typeof optionsOrArgPrefix === "string" ? { argPrefix: optionsOrArgPrefix } : optionsOrArgPrefix;
919
965
  const parts = [];
920
966
  parts.push(this.description);
921
967
  if (this.parameterSchema) {
@@ -929,18 +975,25 @@ var init_gadget = __esm({
929
975
  }
930
976
  if (this.examples && this.examples.length > 0) {
931
977
  parts.push("\n\nExamples:");
932
- const effectiveArgPrefix = argPrefix ?? GADGET_ARG_PREFIX;
978
+ const effectiveArgPrefix = options?.argPrefix ?? GADGET_ARG_PREFIX;
979
+ const effectiveStartPrefix = options?.startPrefix ?? GADGET_START_PREFIX;
980
+ const effectiveEndPrefix = options?.endPrefix ?? GADGET_END_PREFIX;
981
+ const gadgetName = this.name || this.constructor.name;
933
982
  this.examples.forEach((example, index) => {
934
983
  if (index > 0) {
935
984
  parts.push("");
985
+ parts.push("---");
986
+ parts.push("");
936
987
  }
937
988
  if (example.comment) {
938
989
  parts.push(`# ${example.comment}`);
939
990
  }
940
- parts.push("Input:");
991
+ parts.push(`${effectiveStartPrefix}${gadgetName}`);
941
992
  parts.push(formatParamsAsBlock(example.params, "", effectiveArgPrefix));
993
+ parts.push(effectiveEndPrefix);
942
994
  if (example.output !== void 0) {
943
- parts.push("Output:");
995
+ parts.push("");
996
+ parts.push("Expected Output:");
944
997
  parts.push(example.output);
945
998
  }
946
999
  });
@@ -6526,7 +6579,7 @@ var import_commander2 = require("commander");
6526
6579
  // package.json
6527
6580
  var package_default = {
6528
6581
  name: "llmist",
6529
- version: "1.3.1",
6582
+ version: "1.4.0",
6530
6583
  description: "Universal TypeScript LLM client with streaming-first agent framework. Works with any model - no structured outputs or native tool calling required. Implements its own flexible grammar for function calling.",
6531
6584
  type: "module",
6532
6585
  main: "dist/index.cjs",