llmist 1.0.0 → 1.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.d.cts CHANGED
@@ -1269,12 +1269,22 @@ declare class HumanInputException extends Error {
1269
1269
  constructor(question: string);
1270
1270
  }
1271
1271
 
1272
+ interface ErrorFormatterOptions {
1273
+ /** Custom argument prefix for block format examples. Default: "!!!ARG:" */
1274
+ argPrefix?: string;
1275
+ /** Custom start prefix for block format examples. Default: "!!!GADGET_START:" */
1276
+ startPrefix?: string;
1277
+ /** Custom end prefix for block format examples. Default: "!!!GADGET_END" */
1278
+ endPrefix?: string;
1279
+ }
1280
+
1272
1281
  declare class GadgetExecutor {
1273
1282
  private readonly registry;
1274
1283
  private readonly onHumanInputRequired?;
1275
1284
  private readonly defaultGadgetTimeoutMs?;
1276
1285
  private readonly logger;
1277
- constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined);
1286
+ private readonly errorFormatter;
1287
+ constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined, errorFormatterOptions?: ErrorFormatterOptions);
1278
1288
  /**
1279
1289
  * Creates a promise that rejects with a TimeoutException after the specified timeout.
1280
1290
  */
@@ -1303,10 +1313,11 @@ declare class StreamParser {
1303
1313
  */
1304
1314
  private parseGadgetName;
1305
1315
  /**
1306
- * Truncate verbose parse errors to avoid context overflow.
1307
- * Keeps first meaningful line and limits total length.
1316
+ * Extract the error message from a parse error.
1317
+ * Preserves full message since the error formatter adds contextual help
1318
+ * that benefits from precise, detailed error information.
1308
1319
  */
1309
- private truncateParseError;
1320
+ private extractParseError;
1310
1321
  /**
1311
1322
  * Parse parameter string using block format
1312
1323
  */
package/dist/index.d.ts CHANGED
@@ -1269,12 +1269,22 @@ declare class HumanInputException extends Error {
1269
1269
  constructor(question: string);
1270
1270
  }
1271
1271
 
1272
+ interface ErrorFormatterOptions {
1273
+ /** Custom argument prefix for block format examples. Default: "!!!ARG:" */
1274
+ argPrefix?: string;
1275
+ /** Custom start prefix for block format examples. Default: "!!!GADGET_START:" */
1276
+ startPrefix?: string;
1277
+ /** Custom end prefix for block format examples. Default: "!!!GADGET_END" */
1278
+ endPrefix?: string;
1279
+ }
1280
+
1272
1281
  declare class GadgetExecutor {
1273
1282
  private readonly registry;
1274
1283
  private readonly onHumanInputRequired?;
1275
1284
  private readonly defaultGadgetTimeoutMs?;
1276
1285
  private readonly logger;
1277
- constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined);
1286
+ private readonly errorFormatter;
1287
+ constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined, errorFormatterOptions?: ErrorFormatterOptions);
1278
1288
  /**
1279
1289
  * Creates a promise that rejects with a TimeoutException after the specified timeout.
1280
1290
  */
@@ -1303,10 +1313,11 @@ declare class StreamParser {
1303
1313
  */
1304
1314
  private parseGadgetName;
1305
1315
  /**
1306
- * Truncate verbose parse errors to avoid context overflow.
1307
- * Keeps first meaningful line and limits total length.
1316
+ * Extract the error message from a parse error.
1317
+ * Preserves full message since the error formatter adds contextual help
1318
+ * that benefits from precise, detailed error information.
1308
1319
  */
1309
- private truncateParseError;
1320
+ private extractParseError;
1310
1321
  /**
1311
1322
  * Parse parameter string using block format
1312
1323
  */
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  mockLLM,
11
11
  validateAndApplyDefaults,
12
12
  validateGadgetParams
13
- } from "./chunk-53MM55JS.js";
13
+ } from "./chunk-OIPLYP7M.js";
14
14
  import {
15
15
  AgentBuilder,
16
16
  AnthropicMessagesProvider,
@@ -74,7 +74,7 @@ import {
74
74
  resolveRulesTemplate,
75
75
  runWithHandlers,
76
76
  stream
77
- } from "./chunk-T24KLXY4.js";
77
+ } from "./chunk-VXPZQZF5.js";
78
78
 
79
79
  // src/index.ts
80
80
  init_builder();
@@ -1446,6 +1446,89 @@ var init_hook_validators = __esm({
1446
1446
  }
1447
1447
  });
1448
1448
 
1449
+ // src/gadgets/error-formatter.ts
1450
+ var GadgetErrorFormatter;
1451
+ var init_error_formatter = __esm({
1452
+ "src/gadgets/error-formatter.ts"() {
1453
+ "use strict";
1454
+ init_constants();
1455
+ GadgetErrorFormatter = class {
1456
+ argPrefix;
1457
+ startPrefix;
1458
+ endPrefix;
1459
+ constructor(options = {}) {
1460
+ this.argPrefix = options.argPrefix ?? GADGET_ARG_PREFIX;
1461
+ this.startPrefix = options.startPrefix ?? GADGET_START_PREFIX;
1462
+ this.endPrefix = options.endPrefix ?? GADGET_END_PREFIX;
1463
+ }
1464
+ /**
1465
+ * Format a Zod validation error with full gadget instructions.
1466
+ *
1467
+ * @param gadgetName - Name of the gadget that was called
1468
+ * @param zodError - The Zod validation error
1469
+ * @param gadget - The gadget instance (for generating instructions)
1470
+ * @returns Formatted error message with usage instructions
1471
+ */
1472
+ formatValidationError(gadgetName, zodError, gadget) {
1473
+ const parts = [];
1474
+ parts.push(`Error: Invalid parameters for '${gadgetName}':`);
1475
+ for (const issue of zodError.issues) {
1476
+ const path = issue.path.join(".") || "root";
1477
+ parts.push(` - ${path}: ${issue.message}`);
1478
+ }
1479
+ parts.push("");
1480
+ parts.push("Gadget Usage:");
1481
+ parts.push(gadget.getInstruction(this.argPrefix));
1482
+ return parts.join("\n");
1483
+ }
1484
+ /**
1485
+ * Format a parse error with block format reference.
1486
+ *
1487
+ * @param gadgetName - Name of the gadget that was called
1488
+ * @param parseError - The parse error message
1489
+ * @param gadget - The gadget instance if found (for generating instructions)
1490
+ * @returns Formatted error message with format reference
1491
+ */
1492
+ formatParseError(gadgetName, parseError, gadget) {
1493
+ const parts = [];
1494
+ parts.push(`Error: Failed to parse parameters for '${gadgetName}':`);
1495
+ parts.push(` ${parseError}`);
1496
+ if (gadget) {
1497
+ parts.push("");
1498
+ parts.push("Gadget Usage:");
1499
+ parts.push(gadget.getInstruction(this.argPrefix));
1500
+ }
1501
+ parts.push("");
1502
+ parts.push("Block Format Reference:");
1503
+ parts.push(` ${this.startPrefix}${gadgetName}`);
1504
+ parts.push(` ${this.argPrefix}parameterName`);
1505
+ parts.push(" parameter value here");
1506
+ parts.push(` ${this.endPrefix}`);
1507
+ return parts.join("\n");
1508
+ }
1509
+ /**
1510
+ * Format a registry error (gadget not found) with available gadgets list.
1511
+ *
1512
+ * @param gadgetName - Name of the gadget that was not found
1513
+ * @param availableGadgets - List of available gadget names
1514
+ * @returns Formatted error message with available gadgets
1515
+ */
1516
+ formatRegistryError(gadgetName, availableGadgets) {
1517
+ const parts = [];
1518
+ parts.push(`Error: Gadget '${gadgetName}' not found.`);
1519
+ if (availableGadgets.length > 0) {
1520
+ parts.push("");
1521
+ parts.push(`Available gadgets: ${availableGadgets.join(", ")}`);
1522
+ } else {
1523
+ parts.push("");
1524
+ parts.push("No gadgets are currently registered.");
1525
+ }
1526
+ return parts.join("\n");
1527
+ }
1528
+ };
1529
+ }
1530
+ });
1531
+
1449
1532
  // src/gadgets/exceptions.ts
1450
1533
  var BreakLoopException, HumanInputException, TimeoutException;
1451
1534
  var init_exceptions = __esm({
@@ -1484,15 +1567,18 @@ var init_executor = __esm({
1484
1567
  "src/gadgets/executor.ts"() {
1485
1568
  "use strict";
1486
1569
  init_logger();
1570
+ init_error_formatter();
1487
1571
  init_exceptions();
1488
1572
  GadgetExecutor = class {
1489
- constructor(registry, onHumanInputRequired, logger, defaultGadgetTimeoutMs) {
1573
+ constructor(registry, onHumanInputRequired, logger, defaultGadgetTimeoutMs, errorFormatterOptions) {
1490
1574
  this.registry = registry;
1491
1575
  this.onHumanInputRequired = onHumanInputRequired;
1492
1576
  this.defaultGadgetTimeoutMs = defaultGadgetTimeoutMs;
1493
1577
  this.logger = logger ?? createLogger({ name: "llmist:executor" });
1578
+ this.errorFormatter = new GadgetErrorFormatter(errorFormatterOptions);
1494
1579
  }
1495
1580
  logger;
1581
+ errorFormatter;
1496
1582
  /**
1497
1583
  * Creates a promise that rejects with a TimeoutException after the specified timeout.
1498
1584
  */
@@ -1517,11 +1603,12 @@ var init_executor = __esm({
1517
1603
  const gadget = this.registry.get(call.gadgetName);
1518
1604
  if (!gadget) {
1519
1605
  this.logger.error("Gadget not found", { gadgetName: call.gadgetName });
1606
+ const availableGadgets = this.registry.getNames();
1520
1607
  return {
1521
1608
  gadgetName: call.gadgetName,
1522
1609
  invocationId: call.invocationId,
1523
1610
  parameters: call.parameters ?? {},
1524
- error: `Gadget '${call.gadgetName}' not found in registry`,
1611
+ error: this.errorFormatter.formatRegistryError(call.gadgetName, availableGadgets),
1525
1612
  executionTimeMs: Date.now() - startTime
1526
1613
  };
1527
1614
  }
@@ -1531,25 +1618,26 @@ var init_executor = __esm({
1531
1618
  parseError: call.parseError,
1532
1619
  rawParameters: call.parametersRaw
1533
1620
  });
1621
+ const parseErrorMessage = call.parseError ?? "Failed to parse parameters";
1534
1622
  return {
1535
1623
  gadgetName: call.gadgetName,
1536
1624
  invocationId: call.invocationId,
1537
1625
  parameters: {},
1538
- error: call.parseError ?? "Failed to parse parameters",
1626
+ error: this.errorFormatter.formatParseError(call.gadgetName, parseErrorMessage, gadget),
1539
1627
  executionTimeMs: Date.now() - startTime
1540
1628
  };
1541
1629
  }
1542
1630
  if (gadget.parameterSchema) {
1543
1631
  const validationResult = gadget.parameterSchema.safeParse(rawParameters);
1544
1632
  if (!validationResult.success) {
1545
- const formattedIssues = validationResult.error.issues.map((issue) => {
1546
- const path = issue.path.join(".") || "root";
1547
- return `${path}: ${issue.message}`;
1548
- }).join("; ");
1549
- const validationError = `Invalid parameters: ${formattedIssues}`;
1633
+ const validationError = this.errorFormatter.formatValidationError(
1634
+ call.gadgetName,
1635
+ validationResult.error,
1636
+ gadget
1637
+ );
1550
1638
  this.logger.error("Gadget parameter validation failed", {
1551
1639
  gadgetName: call.gadgetName,
1552
- error: validationError
1640
+ issueCount: validationResult.error.issues.length
1553
1641
  });
1554
1642
  return {
1555
1643
  gadgetName: call.gadgetName,
@@ -1838,17 +1926,12 @@ var init_parser = __esm({
1838
1926
  return { actualName: gadgetName, invocationId: `gadget_${++globalInvocationCounter}` };
1839
1927
  }
1840
1928
  /**
1841
- * Truncate verbose parse errors to avoid context overflow.
1842
- * Keeps first meaningful line and limits total length.
1929
+ * Extract the error message from a parse error.
1930
+ * Preserves full message since the error formatter adds contextual help
1931
+ * that benefits from precise, detailed error information.
1843
1932
  */
1844
- truncateParseError(error, format) {
1845
- const message = error instanceof Error ? error.message : String(error);
1846
- const firstLine = message.split("\n")[0];
1847
- const maxLen = 200;
1848
- if (firstLine.length <= maxLen) {
1849
- return firstLine;
1850
- }
1851
- return `${firstLine.slice(0, maxLen)}... (${message.length} chars total)`;
1933
+ extractParseError(error) {
1934
+ return error instanceof Error ? error.message : String(error);
1852
1935
  }
1853
1936
  /**
1854
1937
  * Parse parameter string using block format
@@ -1858,7 +1941,7 @@ var init_parser = __esm({
1858
1941
  try {
1859
1942
  return { parameters: parseBlockParams(cleaned, { argPrefix: this.argPrefix }) };
1860
1943
  } catch (error) {
1861
- return { parseError: this.truncateParseError(error, "block") };
1944
+ return { parseError: this.extractParseError(error) };
1862
1945
  }
1863
1946
  }
1864
1947
  // Feed a chunk of text and get parsed events