llmist 1.1.0 → 1.2.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/{chunk-VXPZQZF5.js → chunk-KORMY3CD.js} +693 -375
- package/dist/chunk-KORMY3CD.js.map +1 -0
- package/dist/{chunk-OIPLYP7M.js → chunk-LELPPETT.js} +2 -2
- package/dist/cli.cjs +639 -321
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +638 -320
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -2
- package/dist/testing/index.cjs +638 -320
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-VXPZQZF5.js.map +0 -1
- /package/dist/{chunk-OIPLYP7M.js.map → chunk-LELPPETT.js.map} +0 -0
package/dist/testing/index.cjs
CHANGED
|
@@ -1446,6 +1446,364 @@ var init_hook_validators = __esm({
|
|
|
1446
1446
|
}
|
|
1447
1447
|
});
|
|
1448
1448
|
|
|
1449
|
+
// src/gadgets/schema-introspector.ts
|
|
1450
|
+
function getDef(schema) {
|
|
1451
|
+
return schema._def;
|
|
1452
|
+
}
|
|
1453
|
+
function getTypeName(schema) {
|
|
1454
|
+
const def = getDef(schema);
|
|
1455
|
+
return def?.type ?? def?.typeName;
|
|
1456
|
+
}
|
|
1457
|
+
function getShape(schema) {
|
|
1458
|
+
const def = getDef(schema);
|
|
1459
|
+
if (typeof def?.shape === "function") {
|
|
1460
|
+
return def.shape();
|
|
1461
|
+
}
|
|
1462
|
+
return def?.shape;
|
|
1463
|
+
}
|
|
1464
|
+
var SchemaIntrospector;
|
|
1465
|
+
var init_schema_introspector = __esm({
|
|
1466
|
+
"src/gadgets/schema-introspector.ts"() {
|
|
1467
|
+
"use strict";
|
|
1468
|
+
SchemaIntrospector = class {
|
|
1469
|
+
schema;
|
|
1470
|
+
cache = /* @__PURE__ */ new Map();
|
|
1471
|
+
constructor(schema) {
|
|
1472
|
+
this.schema = schema;
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Get the expected type at a JSON pointer path.
|
|
1476
|
+
*
|
|
1477
|
+
* @param pointer - JSON pointer path without leading / (e.g., "config/timeout", "items/0")
|
|
1478
|
+
* @returns Type hint for coercion decision
|
|
1479
|
+
*/
|
|
1480
|
+
getTypeAtPath(pointer) {
|
|
1481
|
+
const cached = this.cache.get(pointer);
|
|
1482
|
+
if (cached !== void 0) {
|
|
1483
|
+
return cached;
|
|
1484
|
+
}
|
|
1485
|
+
const result = this.resolveTypeAtPath(pointer);
|
|
1486
|
+
this.cache.set(pointer, result);
|
|
1487
|
+
return result;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Internal method to resolve type at path without caching.
|
|
1491
|
+
*/
|
|
1492
|
+
resolveTypeAtPath(pointer) {
|
|
1493
|
+
if (!pointer) {
|
|
1494
|
+
return this.getBaseType(this.schema);
|
|
1495
|
+
}
|
|
1496
|
+
const segments = pointer.split("/");
|
|
1497
|
+
let current = this.schema;
|
|
1498
|
+
for (const segment of segments) {
|
|
1499
|
+
current = this.unwrapSchema(current);
|
|
1500
|
+
const typeName = getTypeName(current);
|
|
1501
|
+
if (typeName === "object" || typeName === "ZodObject") {
|
|
1502
|
+
const shape = getShape(current);
|
|
1503
|
+
if (!shape || !(segment in shape)) {
|
|
1504
|
+
return "unknown";
|
|
1505
|
+
}
|
|
1506
|
+
current = shape[segment];
|
|
1507
|
+
} else if (typeName === "array" || typeName === "ZodArray") {
|
|
1508
|
+
if (!/^\d+$/.test(segment)) {
|
|
1509
|
+
return "unknown";
|
|
1510
|
+
}
|
|
1511
|
+
const def = getDef(current);
|
|
1512
|
+
const elementType = def?.element ?? def?.type;
|
|
1513
|
+
if (!elementType) {
|
|
1514
|
+
return "unknown";
|
|
1515
|
+
}
|
|
1516
|
+
current = elementType;
|
|
1517
|
+
} else if (typeName === "tuple" || typeName === "ZodTuple") {
|
|
1518
|
+
if (!/^\d+$/.test(segment)) {
|
|
1519
|
+
return "unknown";
|
|
1520
|
+
}
|
|
1521
|
+
const index = parseInt(segment, 10);
|
|
1522
|
+
const def = getDef(current);
|
|
1523
|
+
const items = def?.items;
|
|
1524
|
+
if (!items || index >= items.length) {
|
|
1525
|
+
return "unknown";
|
|
1526
|
+
}
|
|
1527
|
+
current = items[index];
|
|
1528
|
+
} else if (typeName === "record" || typeName === "ZodRecord") {
|
|
1529
|
+
const def = getDef(current);
|
|
1530
|
+
const valueType = def?.valueType;
|
|
1531
|
+
if (!valueType) {
|
|
1532
|
+
return "unknown";
|
|
1533
|
+
}
|
|
1534
|
+
current = valueType;
|
|
1535
|
+
} else {
|
|
1536
|
+
return "unknown";
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return this.getBaseType(current);
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Unwrap schema modifiers (optional, default, nullable, branded, etc.)
|
|
1543
|
+
* to get to the underlying type.
|
|
1544
|
+
*/
|
|
1545
|
+
unwrapSchema(schema) {
|
|
1546
|
+
let current = schema;
|
|
1547
|
+
let iterations = 0;
|
|
1548
|
+
const maxIterations = 20;
|
|
1549
|
+
while (iterations < maxIterations) {
|
|
1550
|
+
const typeName = getTypeName(current);
|
|
1551
|
+
const wrapperTypes = [
|
|
1552
|
+
"optional",
|
|
1553
|
+
"nullable",
|
|
1554
|
+
"default",
|
|
1555
|
+
"catch",
|
|
1556
|
+
"branded",
|
|
1557
|
+
"readonly",
|
|
1558
|
+
"pipeline",
|
|
1559
|
+
"ZodOptional",
|
|
1560
|
+
"ZodNullable",
|
|
1561
|
+
"ZodDefault",
|
|
1562
|
+
"ZodCatch",
|
|
1563
|
+
"ZodBranded",
|
|
1564
|
+
"ZodReadonly",
|
|
1565
|
+
"ZodPipeline"
|
|
1566
|
+
];
|
|
1567
|
+
if (typeName && wrapperTypes.includes(typeName)) {
|
|
1568
|
+
const def = getDef(current);
|
|
1569
|
+
const inner = def?.innerType ?? def?.in ?? def?.type;
|
|
1570
|
+
if (!inner || inner === current) break;
|
|
1571
|
+
current = inner;
|
|
1572
|
+
iterations++;
|
|
1573
|
+
continue;
|
|
1574
|
+
}
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1577
|
+
return current;
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Get the primitive type hint from an unwrapped schema.
|
|
1581
|
+
*/
|
|
1582
|
+
getBaseType(schema) {
|
|
1583
|
+
const unwrapped = this.unwrapSchema(schema);
|
|
1584
|
+
const typeName = getTypeName(unwrapped);
|
|
1585
|
+
switch (typeName) {
|
|
1586
|
+
// Primitive types
|
|
1587
|
+
case "string":
|
|
1588
|
+
case "ZodString":
|
|
1589
|
+
return "string";
|
|
1590
|
+
case "number":
|
|
1591
|
+
case "ZodNumber":
|
|
1592
|
+
case "bigint":
|
|
1593
|
+
case "ZodBigInt":
|
|
1594
|
+
return "number";
|
|
1595
|
+
case "boolean":
|
|
1596
|
+
case "ZodBoolean":
|
|
1597
|
+
return "boolean";
|
|
1598
|
+
// Literal types - check the literal value type
|
|
1599
|
+
case "literal":
|
|
1600
|
+
case "ZodLiteral": {
|
|
1601
|
+
const def = getDef(unwrapped);
|
|
1602
|
+
const values = def?.values;
|
|
1603
|
+
const value = values?.[0] ?? def?.value;
|
|
1604
|
+
if (typeof value === "string") return "string";
|
|
1605
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
1606
|
+
return "number";
|
|
1607
|
+
if (typeof value === "boolean") return "boolean";
|
|
1608
|
+
return "unknown";
|
|
1609
|
+
}
|
|
1610
|
+
// Enum - always string keys
|
|
1611
|
+
case "enum":
|
|
1612
|
+
case "ZodEnum":
|
|
1613
|
+
case "nativeEnum":
|
|
1614
|
+
case "ZodNativeEnum":
|
|
1615
|
+
return "string";
|
|
1616
|
+
// Union - return 'unknown' to let auto-coercion decide
|
|
1617
|
+
// Since multiple types are valid, we can't definitively say what the LLM intended
|
|
1618
|
+
// Auto-coercion will handle common cases (numbers, booleans) appropriately
|
|
1619
|
+
case "union":
|
|
1620
|
+
case "ZodUnion":
|
|
1621
|
+
return "unknown";
|
|
1622
|
+
// Discriminated union - complex, return unknown
|
|
1623
|
+
case "discriminatedUnion":
|
|
1624
|
+
case "ZodDiscriminatedUnion":
|
|
1625
|
+
return "unknown";
|
|
1626
|
+
// Intersection - check both sides
|
|
1627
|
+
case "intersection":
|
|
1628
|
+
case "ZodIntersection": {
|
|
1629
|
+
const def = getDef(unwrapped);
|
|
1630
|
+
const left = def?.left;
|
|
1631
|
+
const right = def?.right;
|
|
1632
|
+
if (!left || !right) return "unknown";
|
|
1633
|
+
const leftType = this.getBaseType(left);
|
|
1634
|
+
const rightType = this.getBaseType(right);
|
|
1635
|
+
if (leftType === rightType) return leftType;
|
|
1636
|
+
if (leftType === "string" || rightType === "string") return "string";
|
|
1637
|
+
return "unknown";
|
|
1638
|
+
}
|
|
1639
|
+
// Effects/transforms - return unknown to let Zod handle it
|
|
1640
|
+
case "effects":
|
|
1641
|
+
case "ZodEffects":
|
|
1642
|
+
return "unknown";
|
|
1643
|
+
// Lazy - can't resolve without evaluating
|
|
1644
|
+
case "lazy":
|
|
1645
|
+
case "ZodLazy":
|
|
1646
|
+
return "unknown";
|
|
1647
|
+
// Complex types - return unknown
|
|
1648
|
+
case "object":
|
|
1649
|
+
case "ZodObject":
|
|
1650
|
+
case "array":
|
|
1651
|
+
case "ZodArray":
|
|
1652
|
+
case "tuple":
|
|
1653
|
+
case "ZodTuple":
|
|
1654
|
+
case "record":
|
|
1655
|
+
case "ZodRecord":
|
|
1656
|
+
case "map":
|
|
1657
|
+
case "ZodMap":
|
|
1658
|
+
case "set":
|
|
1659
|
+
case "ZodSet":
|
|
1660
|
+
case "function":
|
|
1661
|
+
case "ZodFunction":
|
|
1662
|
+
case "promise":
|
|
1663
|
+
case "ZodPromise":
|
|
1664
|
+
case "date":
|
|
1665
|
+
case "ZodDate":
|
|
1666
|
+
return "unknown";
|
|
1667
|
+
// Unknown/any/never/void/undefined/null
|
|
1668
|
+
case "unknown":
|
|
1669
|
+
case "ZodUnknown":
|
|
1670
|
+
case "any":
|
|
1671
|
+
case "ZodAny":
|
|
1672
|
+
case "never":
|
|
1673
|
+
case "ZodNever":
|
|
1674
|
+
case "void":
|
|
1675
|
+
case "ZodVoid":
|
|
1676
|
+
case "undefined":
|
|
1677
|
+
case "ZodUndefined":
|
|
1678
|
+
case "null":
|
|
1679
|
+
case "ZodNull":
|
|
1680
|
+
return "unknown";
|
|
1681
|
+
default:
|
|
1682
|
+
return "unknown";
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
// src/gadgets/block-params.ts
|
|
1690
|
+
function parseBlockParams(content, options) {
|
|
1691
|
+
const argPrefix = options?.argPrefix ?? GADGET_ARG_PREFIX;
|
|
1692
|
+
const result = {};
|
|
1693
|
+
const seenPointers = /* @__PURE__ */ new Set();
|
|
1694
|
+
const introspector = options?.schema ? new SchemaIntrospector(options.schema) : void 0;
|
|
1695
|
+
const parts = content.split(argPrefix);
|
|
1696
|
+
for (let i = 1; i < parts.length; i++) {
|
|
1697
|
+
const part = parts[i];
|
|
1698
|
+
const newlineIndex = part.indexOf("\n");
|
|
1699
|
+
if (newlineIndex === -1) {
|
|
1700
|
+
const pointer2 = part.trim();
|
|
1701
|
+
if (pointer2) {
|
|
1702
|
+
if (seenPointers.has(pointer2)) {
|
|
1703
|
+
throw new Error(`Duplicate pointer: ${pointer2}`);
|
|
1704
|
+
}
|
|
1705
|
+
seenPointers.add(pointer2);
|
|
1706
|
+
setByPointer(result, pointer2, "", introspector);
|
|
1707
|
+
}
|
|
1708
|
+
continue;
|
|
1709
|
+
}
|
|
1710
|
+
const pointer = part.substring(0, newlineIndex).trim();
|
|
1711
|
+
let value = part.substring(newlineIndex + 1);
|
|
1712
|
+
if (value.endsWith("\n")) {
|
|
1713
|
+
value = value.slice(0, -1);
|
|
1714
|
+
}
|
|
1715
|
+
if (!pointer) {
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
if (seenPointers.has(pointer)) {
|
|
1719
|
+
throw new Error(`Duplicate pointer: ${pointer}`);
|
|
1720
|
+
}
|
|
1721
|
+
seenPointers.add(pointer);
|
|
1722
|
+
setByPointer(result, pointer, value, introspector);
|
|
1723
|
+
}
|
|
1724
|
+
return result;
|
|
1725
|
+
}
|
|
1726
|
+
function coerceValue(value, expectedType) {
|
|
1727
|
+
if (value.includes("\n")) {
|
|
1728
|
+
return value;
|
|
1729
|
+
}
|
|
1730
|
+
const trimmed = value.trim();
|
|
1731
|
+
if (expectedType === "string") {
|
|
1732
|
+
return value;
|
|
1733
|
+
}
|
|
1734
|
+
if (expectedType === "boolean") {
|
|
1735
|
+
if (trimmed === "true") return true;
|
|
1736
|
+
if (trimmed === "false") return false;
|
|
1737
|
+
return value;
|
|
1738
|
+
}
|
|
1739
|
+
if (expectedType === "number") {
|
|
1740
|
+
const num = Number(trimmed);
|
|
1741
|
+
if (!isNaN(num) && isFinite(num) && trimmed !== "") {
|
|
1742
|
+
return num;
|
|
1743
|
+
}
|
|
1744
|
+
return value;
|
|
1745
|
+
}
|
|
1746
|
+
if (trimmed === "true") return true;
|
|
1747
|
+
if (trimmed === "false") return false;
|
|
1748
|
+
if (trimmed !== "" && /^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
1749
|
+
const num = Number(trimmed);
|
|
1750
|
+
if (!isNaN(num) && isFinite(num)) {
|
|
1751
|
+
return num;
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
return value;
|
|
1755
|
+
}
|
|
1756
|
+
function setByPointer(obj, pointer, value, introspector) {
|
|
1757
|
+
const segments = pointer.split("/");
|
|
1758
|
+
let current = obj;
|
|
1759
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1760
|
+
const segment = segments[i];
|
|
1761
|
+
const nextSegment = segments[i + 1];
|
|
1762
|
+
const nextIsArrayIndex = /^\d+$/.test(nextSegment);
|
|
1763
|
+
if (Array.isArray(current)) {
|
|
1764
|
+
const index = parseInt(segment, 10);
|
|
1765
|
+
if (isNaN(index) || index < 0) {
|
|
1766
|
+
throw new Error(`Invalid array index: ${segment}`);
|
|
1767
|
+
}
|
|
1768
|
+
if (index > current.length) {
|
|
1769
|
+
throw new Error(`Array index gap: expected ${current.length}, got ${index}`);
|
|
1770
|
+
}
|
|
1771
|
+
if (current[index] === void 0) {
|
|
1772
|
+
current[index] = nextIsArrayIndex ? [] : {};
|
|
1773
|
+
}
|
|
1774
|
+
current = current[index];
|
|
1775
|
+
} else {
|
|
1776
|
+
const rec = current;
|
|
1777
|
+
if (rec[segment] === void 0) {
|
|
1778
|
+
rec[segment] = nextIsArrayIndex ? [] : {};
|
|
1779
|
+
}
|
|
1780
|
+
current = rec[segment];
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
const lastSegment = segments[segments.length - 1];
|
|
1784
|
+
const expectedType = introspector?.getTypeAtPath(pointer);
|
|
1785
|
+
const coercedValue = coerceValue(value, expectedType);
|
|
1786
|
+
if (Array.isArray(current)) {
|
|
1787
|
+
const index = parseInt(lastSegment, 10);
|
|
1788
|
+
if (isNaN(index) || index < 0) {
|
|
1789
|
+
throw new Error(`Invalid array index: ${lastSegment}`);
|
|
1790
|
+
}
|
|
1791
|
+
if (index > current.length) {
|
|
1792
|
+
throw new Error(`Array index gap: expected ${current.length}, got ${index}`);
|
|
1793
|
+
}
|
|
1794
|
+
current[index] = coercedValue;
|
|
1795
|
+
} else {
|
|
1796
|
+
current[lastSegment] = coercedValue;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
var init_block_params = __esm({
|
|
1800
|
+
"src/gadgets/block-params.ts"() {
|
|
1801
|
+
"use strict";
|
|
1802
|
+
init_constants();
|
|
1803
|
+
init_schema_introspector();
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1449
1807
|
// src/gadgets/error-formatter.ts
|
|
1450
1808
|
var GadgetErrorFormatter;
|
|
1451
1809
|
var init_error_formatter = __esm({
|
|
@@ -1557,325 +1915,7 @@ var init_exceptions = __esm({
|
|
|
1557
1915
|
this.gadgetName = gadgetName;
|
|
1558
1916
|
this.timeoutMs = timeoutMs;
|
|
1559
1917
|
}
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
|
|
1564
|
-
// src/gadgets/executor.ts
|
|
1565
|
-
var GadgetExecutor;
|
|
1566
|
-
var init_executor = __esm({
|
|
1567
|
-
"src/gadgets/executor.ts"() {
|
|
1568
|
-
"use strict";
|
|
1569
|
-
init_logger();
|
|
1570
|
-
init_error_formatter();
|
|
1571
|
-
init_exceptions();
|
|
1572
|
-
GadgetExecutor = class {
|
|
1573
|
-
constructor(registry, onHumanInputRequired, logger, defaultGadgetTimeoutMs, errorFormatterOptions) {
|
|
1574
|
-
this.registry = registry;
|
|
1575
|
-
this.onHumanInputRequired = onHumanInputRequired;
|
|
1576
|
-
this.defaultGadgetTimeoutMs = defaultGadgetTimeoutMs;
|
|
1577
|
-
this.logger = logger ?? createLogger({ name: "llmist:executor" });
|
|
1578
|
-
this.errorFormatter = new GadgetErrorFormatter(errorFormatterOptions);
|
|
1579
|
-
}
|
|
1580
|
-
logger;
|
|
1581
|
-
errorFormatter;
|
|
1582
|
-
/**
|
|
1583
|
-
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
1584
|
-
*/
|
|
1585
|
-
createTimeoutPromise(gadgetName, timeoutMs) {
|
|
1586
|
-
return new Promise((_, reject) => {
|
|
1587
|
-
setTimeout(() => {
|
|
1588
|
-
reject(new TimeoutException(gadgetName, timeoutMs));
|
|
1589
|
-
}, timeoutMs);
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
|
-
// Execute a gadget call asynchronously
|
|
1593
|
-
async execute(call) {
|
|
1594
|
-
const startTime = Date.now();
|
|
1595
|
-
this.logger.debug("Executing gadget", {
|
|
1596
|
-
gadgetName: call.gadgetName,
|
|
1597
|
-
invocationId: call.invocationId,
|
|
1598
|
-
parameters: call.parameters
|
|
1599
|
-
});
|
|
1600
|
-
const rawParameters = call.parameters ?? {};
|
|
1601
|
-
let validatedParameters = rawParameters;
|
|
1602
|
-
try {
|
|
1603
|
-
const gadget = this.registry.get(call.gadgetName);
|
|
1604
|
-
if (!gadget) {
|
|
1605
|
-
this.logger.error("Gadget not found", { gadgetName: call.gadgetName });
|
|
1606
|
-
const availableGadgets = this.registry.getNames();
|
|
1607
|
-
return {
|
|
1608
|
-
gadgetName: call.gadgetName,
|
|
1609
|
-
invocationId: call.invocationId,
|
|
1610
|
-
parameters: call.parameters ?? {},
|
|
1611
|
-
error: this.errorFormatter.formatRegistryError(call.gadgetName, availableGadgets),
|
|
1612
|
-
executionTimeMs: Date.now() - startTime
|
|
1613
|
-
};
|
|
1614
|
-
}
|
|
1615
|
-
if (call.parseError || !call.parameters) {
|
|
1616
|
-
this.logger.error("Gadget parameter parse error", {
|
|
1617
|
-
gadgetName: call.gadgetName,
|
|
1618
|
-
parseError: call.parseError,
|
|
1619
|
-
rawParameters: call.parametersRaw
|
|
1620
|
-
});
|
|
1621
|
-
const parseErrorMessage = call.parseError ?? "Failed to parse parameters";
|
|
1622
|
-
return {
|
|
1623
|
-
gadgetName: call.gadgetName,
|
|
1624
|
-
invocationId: call.invocationId,
|
|
1625
|
-
parameters: {},
|
|
1626
|
-
error: this.errorFormatter.formatParseError(call.gadgetName, parseErrorMessage, gadget),
|
|
1627
|
-
executionTimeMs: Date.now() - startTime
|
|
1628
|
-
};
|
|
1629
|
-
}
|
|
1630
|
-
if (gadget.parameterSchema) {
|
|
1631
|
-
const validationResult = gadget.parameterSchema.safeParse(rawParameters);
|
|
1632
|
-
if (!validationResult.success) {
|
|
1633
|
-
const validationError = this.errorFormatter.formatValidationError(
|
|
1634
|
-
call.gadgetName,
|
|
1635
|
-
validationResult.error,
|
|
1636
|
-
gadget
|
|
1637
|
-
);
|
|
1638
|
-
this.logger.error("Gadget parameter validation failed", {
|
|
1639
|
-
gadgetName: call.gadgetName,
|
|
1640
|
-
issueCount: validationResult.error.issues.length
|
|
1641
|
-
});
|
|
1642
|
-
return {
|
|
1643
|
-
gadgetName: call.gadgetName,
|
|
1644
|
-
invocationId: call.invocationId,
|
|
1645
|
-
parameters: rawParameters,
|
|
1646
|
-
error: validationError,
|
|
1647
|
-
executionTimeMs: Date.now() - startTime
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
validatedParameters = validationResult.data;
|
|
1651
|
-
}
|
|
1652
|
-
const timeoutMs = gadget.timeoutMs ?? this.defaultGadgetTimeoutMs;
|
|
1653
|
-
let result;
|
|
1654
|
-
if (timeoutMs && timeoutMs > 0) {
|
|
1655
|
-
this.logger.debug("Executing gadget with timeout", {
|
|
1656
|
-
gadgetName: call.gadgetName,
|
|
1657
|
-
timeoutMs
|
|
1658
|
-
});
|
|
1659
|
-
result = await Promise.race([
|
|
1660
|
-
Promise.resolve(gadget.execute(validatedParameters)),
|
|
1661
|
-
this.createTimeoutPromise(call.gadgetName, timeoutMs)
|
|
1662
|
-
]);
|
|
1663
|
-
} else {
|
|
1664
|
-
result = await Promise.resolve(gadget.execute(validatedParameters));
|
|
1665
|
-
}
|
|
1666
|
-
const executionTimeMs = Date.now() - startTime;
|
|
1667
|
-
this.logger.info("Gadget executed successfully", {
|
|
1668
|
-
gadgetName: call.gadgetName,
|
|
1669
|
-
invocationId: call.invocationId,
|
|
1670
|
-
executionTimeMs
|
|
1671
|
-
});
|
|
1672
|
-
this.logger.debug("Gadget result", {
|
|
1673
|
-
gadgetName: call.gadgetName,
|
|
1674
|
-
invocationId: call.invocationId,
|
|
1675
|
-
parameters: validatedParameters,
|
|
1676
|
-
result,
|
|
1677
|
-
executionTimeMs
|
|
1678
|
-
});
|
|
1679
|
-
return {
|
|
1680
|
-
gadgetName: call.gadgetName,
|
|
1681
|
-
invocationId: call.invocationId,
|
|
1682
|
-
parameters: validatedParameters,
|
|
1683
|
-
result,
|
|
1684
|
-
executionTimeMs
|
|
1685
|
-
};
|
|
1686
|
-
} catch (error) {
|
|
1687
|
-
if (error instanceof BreakLoopException) {
|
|
1688
|
-
this.logger.info("Gadget requested loop termination", {
|
|
1689
|
-
gadgetName: call.gadgetName,
|
|
1690
|
-
message: error.message
|
|
1691
|
-
});
|
|
1692
|
-
return {
|
|
1693
|
-
gadgetName: call.gadgetName,
|
|
1694
|
-
invocationId: call.invocationId,
|
|
1695
|
-
parameters: validatedParameters,
|
|
1696
|
-
result: error.message,
|
|
1697
|
-
breaksLoop: true,
|
|
1698
|
-
executionTimeMs: Date.now() - startTime
|
|
1699
|
-
};
|
|
1700
|
-
}
|
|
1701
|
-
if (error instanceof TimeoutException) {
|
|
1702
|
-
this.logger.error("Gadget execution timed out", {
|
|
1703
|
-
gadgetName: call.gadgetName,
|
|
1704
|
-
timeoutMs: error.timeoutMs,
|
|
1705
|
-
executionTimeMs: Date.now() - startTime
|
|
1706
|
-
});
|
|
1707
|
-
return {
|
|
1708
|
-
gadgetName: call.gadgetName,
|
|
1709
|
-
invocationId: call.invocationId,
|
|
1710
|
-
parameters: validatedParameters,
|
|
1711
|
-
error: error.message,
|
|
1712
|
-
executionTimeMs: Date.now() - startTime
|
|
1713
|
-
};
|
|
1714
|
-
}
|
|
1715
|
-
if (error instanceof HumanInputException) {
|
|
1716
|
-
this.logger.info("Gadget requested human input", {
|
|
1717
|
-
gadgetName: call.gadgetName,
|
|
1718
|
-
question: error.question
|
|
1719
|
-
});
|
|
1720
|
-
if (this.onHumanInputRequired) {
|
|
1721
|
-
try {
|
|
1722
|
-
const answer = await this.onHumanInputRequired(error.question);
|
|
1723
|
-
this.logger.debug("Human input received", {
|
|
1724
|
-
gadgetName: call.gadgetName,
|
|
1725
|
-
answerLength: answer.length
|
|
1726
|
-
});
|
|
1727
|
-
return {
|
|
1728
|
-
gadgetName: call.gadgetName,
|
|
1729
|
-
invocationId: call.invocationId,
|
|
1730
|
-
parameters: validatedParameters,
|
|
1731
|
-
result: answer,
|
|
1732
|
-
executionTimeMs: Date.now() - startTime
|
|
1733
|
-
};
|
|
1734
|
-
} catch (inputError) {
|
|
1735
|
-
this.logger.error("Human input callback error", {
|
|
1736
|
-
gadgetName: call.gadgetName,
|
|
1737
|
-
error: inputError instanceof Error ? inputError.message : String(inputError)
|
|
1738
|
-
});
|
|
1739
|
-
return {
|
|
1740
|
-
gadgetName: call.gadgetName,
|
|
1741
|
-
invocationId: call.invocationId,
|
|
1742
|
-
parameters: validatedParameters,
|
|
1743
|
-
error: inputError instanceof Error ? inputError.message : String(inputError),
|
|
1744
|
-
executionTimeMs: Date.now() - startTime
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
this.logger.warn("Human input required but no callback provided", {
|
|
1749
|
-
gadgetName: call.gadgetName
|
|
1750
|
-
});
|
|
1751
|
-
return {
|
|
1752
|
-
gadgetName: call.gadgetName,
|
|
1753
|
-
invocationId: call.invocationId,
|
|
1754
|
-
parameters: validatedParameters,
|
|
1755
|
-
error: "Human input required but not available (stdin is not interactive)",
|
|
1756
|
-
executionTimeMs: Date.now() - startTime
|
|
1757
|
-
};
|
|
1758
|
-
}
|
|
1759
|
-
const executionTimeMs = Date.now() - startTime;
|
|
1760
|
-
this.logger.error("Gadget execution failed", {
|
|
1761
|
-
gadgetName: call.gadgetName,
|
|
1762
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1763
|
-
executionTimeMs
|
|
1764
|
-
});
|
|
1765
|
-
return {
|
|
1766
|
-
gadgetName: call.gadgetName,
|
|
1767
|
-
invocationId: call.invocationId,
|
|
1768
|
-
parameters: validatedParameters,
|
|
1769
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1770
|
-
executionTimeMs
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
// Execute multiple gadget calls in parallel
|
|
1775
|
-
async executeAll(calls) {
|
|
1776
|
-
return Promise.all(calls.map((call) => this.execute(call)));
|
|
1777
|
-
}
|
|
1778
|
-
};
|
|
1779
|
-
}
|
|
1780
|
-
});
|
|
1781
|
-
|
|
1782
|
-
// src/gadgets/block-params.ts
|
|
1783
|
-
function parseBlockParams(content, options) {
|
|
1784
|
-
const argPrefix = options?.argPrefix ?? GADGET_ARG_PREFIX;
|
|
1785
|
-
const result = {};
|
|
1786
|
-
const seenPointers = /* @__PURE__ */ new Set();
|
|
1787
|
-
const parts = content.split(argPrefix);
|
|
1788
|
-
for (let i = 1; i < parts.length; i++) {
|
|
1789
|
-
const part = parts[i];
|
|
1790
|
-
const newlineIndex = part.indexOf("\n");
|
|
1791
|
-
if (newlineIndex === -1) {
|
|
1792
|
-
const pointer2 = part.trim();
|
|
1793
|
-
if (pointer2) {
|
|
1794
|
-
if (seenPointers.has(pointer2)) {
|
|
1795
|
-
throw new Error(`Duplicate pointer: ${pointer2}`);
|
|
1796
|
-
}
|
|
1797
|
-
seenPointers.add(pointer2);
|
|
1798
|
-
setByPointer(result, pointer2, "");
|
|
1799
|
-
}
|
|
1800
|
-
continue;
|
|
1801
|
-
}
|
|
1802
|
-
const pointer = part.substring(0, newlineIndex).trim();
|
|
1803
|
-
let value = part.substring(newlineIndex + 1);
|
|
1804
|
-
if (value.endsWith("\n")) {
|
|
1805
|
-
value = value.slice(0, -1);
|
|
1806
|
-
}
|
|
1807
|
-
if (!pointer) {
|
|
1808
|
-
continue;
|
|
1809
|
-
}
|
|
1810
|
-
if (seenPointers.has(pointer)) {
|
|
1811
|
-
throw new Error(`Duplicate pointer: ${pointer}`);
|
|
1812
|
-
}
|
|
1813
|
-
seenPointers.add(pointer);
|
|
1814
|
-
setByPointer(result, pointer, value);
|
|
1815
|
-
}
|
|
1816
|
-
return result;
|
|
1817
|
-
}
|
|
1818
|
-
function coerceValue(value) {
|
|
1819
|
-
if (value.includes("\n")) {
|
|
1820
|
-
return value;
|
|
1821
|
-
}
|
|
1822
|
-
const trimmed = value.trim();
|
|
1823
|
-
if (trimmed === "true") return true;
|
|
1824
|
-
if (trimmed === "false") return false;
|
|
1825
|
-
if (trimmed !== "" && /^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
1826
|
-
const num = Number(trimmed);
|
|
1827
|
-
if (!isNaN(num) && isFinite(num)) {
|
|
1828
|
-
return num;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
return value;
|
|
1832
|
-
}
|
|
1833
|
-
function setByPointer(obj, pointer, value) {
|
|
1834
|
-
const segments = pointer.split("/");
|
|
1835
|
-
let current = obj;
|
|
1836
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
1837
|
-
const segment = segments[i];
|
|
1838
|
-
const nextSegment = segments[i + 1];
|
|
1839
|
-
const nextIsArrayIndex = /^\d+$/.test(nextSegment);
|
|
1840
|
-
if (Array.isArray(current)) {
|
|
1841
|
-
const index = parseInt(segment, 10);
|
|
1842
|
-
if (isNaN(index) || index < 0) {
|
|
1843
|
-
throw new Error(`Invalid array index: ${segment}`);
|
|
1844
|
-
}
|
|
1845
|
-
if (index > current.length) {
|
|
1846
|
-
throw new Error(`Array index gap: expected ${current.length}, got ${index}`);
|
|
1847
|
-
}
|
|
1848
|
-
if (current[index] === void 0) {
|
|
1849
|
-
current[index] = nextIsArrayIndex ? [] : {};
|
|
1850
|
-
}
|
|
1851
|
-
current = current[index];
|
|
1852
|
-
} else {
|
|
1853
|
-
const rec = current;
|
|
1854
|
-
if (rec[segment] === void 0) {
|
|
1855
|
-
rec[segment] = nextIsArrayIndex ? [] : {};
|
|
1856
|
-
}
|
|
1857
|
-
current = rec[segment];
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
const lastSegment = segments[segments.length - 1];
|
|
1861
|
-
const coercedValue = coerceValue(value);
|
|
1862
|
-
if (Array.isArray(current)) {
|
|
1863
|
-
const index = parseInt(lastSegment, 10);
|
|
1864
|
-
if (isNaN(index) || index < 0) {
|
|
1865
|
-
throw new Error(`Invalid array index: ${lastSegment}`);
|
|
1866
|
-
}
|
|
1867
|
-
if (index > current.length) {
|
|
1868
|
-
throw new Error(`Array index gap: expected ${current.length}, got ${index}`);
|
|
1869
|
-
}
|
|
1870
|
-
current[index] = coercedValue;
|
|
1871
|
-
} else {
|
|
1872
|
-
current[lastSegment] = coercedValue;
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
var init_block_params = __esm({
|
|
1876
|
-
"src/gadgets/block-params.ts"() {
|
|
1877
|
-
"use strict";
|
|
1878
|
-
init_constants();
|
|
1918
|
+
};
|
|
1879
1919
|
}
|
|
1880
1920
|
});
|
|
1881
1921
|
|
|
@@ -2056,6 +2096,283 @@ var init_parser = __esm({
|
|
|
2056
2096
|
}
|
|
2057
2097
|
});
|
|
2058
2098
|
|
|
2099
|
+
// src/gadgets/executor.ts
|
|
2100
|
+
var GadgetExecutor;
|
|
2101
|
+
var init_executor = __esm({
|
|
2102
|
+
"src/gadgets/executor.ts"() {
|
|
2103
|
+
"use strict";
|
|
2104
|
+
init_constants();
|
|
2105
|
+
init_logger();
|
|
2106
|
+
init_block_params();
|
|
2107
|
+
init_error_formatter();
|
|
2108
|
+
init_exceptions();
|
|
2109
|
+
init_parser();
|
|
2110
|
+
GadgetExecutor = class {
|
|
2111
|
+
constructor(registry, onHumanInputRequired, logger, defaultGadgetTimeoutMs, errorFormatterOptions) {
|
|
2112
|
+
this.registry = registry;
|
|
2113
|
+
this.onHumanInputRequired = onHumanInputRequired;
|
|
2114
|
+
this.defaultGadgetTimeoutMs = defaultGadgetTimeoutMs;
|
|
2115
|
+
this.logger = logger ?? createLogger({ name: "llmist:executor" });
|
|
2116
|
+
this.errorFormatter = new GadgetErrorFormatter(errorFormatterOptions);
|
|
2117
|
+
this.argPrefix = errorFormatterOptions?.argPrefix ?? GADGET_ARG_PREFIX;
|
|
2118
|
+
}
|
|
2119
|
+
logger;
|
|
2120
|
+
errorFormatter;
|
|
2121
|
+
argPrefix;
|
|
2122
|
+
/**
|
|
2123
|
+
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
2124
|
+
*/
|
|
2125
|
+
createTimeoutPromise(gadgetName, timeoutMs) {
|
|
2126
|
+
return new Promise((_, reject) => {
|
|
2127
|
+
setTimeout(() => {
|
|
2128
|
+
reject(new TimeoutException(gadgetName, timeoutMs));
|
|
2129
|
+
}, timeoutMs);
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
// Execute a gadget call asynchronously
|
|
2133
|
+
async execute(call) {
|
|
2134
|
+
const startTime = Date.now();
|
|
2135
|
+
this.logger.debug("Executing gadget", {
|
|
2136
|
+
gadgetName: call.gadgetName,
|
|
2137
|
+
invocationId: call.invocationId,
|
|
2138
|
+
parameters: call.parameters
|
|
2139
|
+
});
|
|
2140
|
+
const rawParameters = call.parameters ?? {};
|
|
2141
|
+
let validatedParameters = rawParameters;
|
|
2142
|
+
try {
|
|
2143
|
+
const gadget = this.registry.get(call.gadgetName);
|
|
2144
|
+
if (!gadget) {
|
|
2145
|
+
this.logger.error("Gadget not found", { gadgetName: call.gadgetName });
|
|
2146
|
+
const availableGadgets = this.registry.getNames();
|
|
2147
|
+
return {
|
|
2148
|
+
gadgetName: call.gadgetName,
|
|
2149
|
+
invocationId: call.invocationId,
|
|
2150
|
+
parameters: call.parameters ?? {},
|
|
2151
|
+
error: this.errorFormatter.formatRegistryError(call.gadgetName, availableGadgets),
|
|
2152
|
+
executionTimeMs: Date.now() - startTime
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
if (call.parseError || !call.parameters) {
|
|
2156
|
+
this.logger.error("Gadget parameter parse error", {
|
|
2157
|
+
gadgetName: call.gadgetName,
|
|
2158
|
+
parseError: call.parseError,
|
|
2159
|
+
rawParameters: call.parametersRaw
|
|
2160
|
+
});
|
|
2161
|
+
const parseErrorMessage = call.parseError ?? "Failed to parse parameters";
|
|
2162
|
+
return {
|
|
2163
|
+
gadgetName: call.gadgetName,
|
|
2164
|
+
invocationId: call.invocationId,
|
|
2165
|
+
parameters: {},
|
|
2166
|
+
error: this.errorFormatter.formatParseError(call.gadgetName, parseErrorMessage, gadget),
|
|
2167
|
+
executionTimeMs: Date.now() - startTime
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
let schemaAwareParameters = rawParameters;
|
|
2171
|
+
const hasBlockFormat = call.parametersRaw?.includes(this.argPrefix);
|
|
2172
|
+
if (gadget.parameterSchema && hasBlockFormat) {
|
|
2173
|
+
try {
|
|
2174
|
+
const cleanedRaw = stripMarkdownFences(call.parametersRaw);
|
|
2175
|
+
const initialParse = parseBlockParams(cleanedRaw, { argPrefix: this.argPrefix });
|
|
2176
|
+
const parametersWereModified = !this.deepEquals(rawParameters, initialParse);
|
|
2177
|
+
if (parametersWereModified) {
|
|
2178
|
+
this.logger.debug("Parameters modified by interceptor, skipping re-parse", {
|
|
2179
|
+
gadgetName: call.gadgetName
|
|
2180
|
+
});
|
|
2181
|
+
schemaAwareParameters = rawParameters;
|
|
2182
|
+
} else {
|
|
2183
|
+
schemaAwareParameters = parseBlockParams(cleanedRaw, {
|
|
2184
|
+
argPrefix: this.argPrefix,
|
|
2185
|
+
schema: gadget.parameterSchema
|
|
2186
|
+
});
|
|
2187
|
+
this.logger.debug("Re-parsed parameters with schema", {
|
|
2188
|
+
gadgetName: call.gadgetName,
|
|
2189
|
+
original: rawParameters,
|
|
2190
|
+
schemaAware: schemaAwareParameters
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
} catch (error) {
|
|
2194
|
+
this.logger.warn("Schema-aware re-parsing failed, using original parameters", {
|
|
2195
|
+
gadgetName: call.gadgetName,
|
|
2196
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2197
|
+
});
|
|
2198
|
+
schemaAwareParameters = rawParameters;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
if (gadget.parameterSchema) {
|
|
2202
|
+
const validationResult = gadget.parameterSchema.safeParse(schemaAwareParameters);
|
|
2203
|
+
if (!validationResult.success) {
|
|
2204
|
+
const validationError = this.errorFormatter.formatValidationError(
|
|
2205
|
+
call.gadgetName,
|
|
2206
|
+
validationResult.error,
|
|
2207
|
+
gadget
|
|
2208
|
+
);
|
|
2209
|
+
this.logger.error("Gadget parameter validation failed", {
|
|
2210
|
+
gadgetName: call.gadgetName,
|
|
2211
|
+
issueCount: validationResult.error.issues.length
|
|
2212
|
+
});
|
|
2213
|
+
return {
|
|
2214
|
+
gadgetName: call.gadgetName,
|
|
2215
|
+
invocationId: call.invocationId,
|
|
2216
|
+
parameters: schemaAwareParameters,
|
|
2217
|
+
error: validationError,
|
|
2218
|
+
executionTimeMs: Date.now() - startTime
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
validatedParameters = validationResult.data;
|
|
2222
|
+
} else {
|
|
2223
|
+
validatedParameters = schemaAwareParameters;
|
|
2224
|
+
}
|
|
2225
|
+
const timeoutMs = gadget.timeoutMs ?? this.defaultGadgetTimeoutMs;
|
|
2226
|
+
let result;
|
|
2227
|
+
if (timeoutMs && timeoutMs > 0) {
|
|
2228
|
+
this.logger.debug("Executing gadget with timeout", {
|
|
2229
|
+
gadgetName: call.gadgetName,
|
|
2230
|
+
timeoutMs
|
|
2231
|
+
});
|
|
2232
|
+
result = await Promise.race([
|
|
2233
|
+
Promise.resolve(gadget.execute(validatedParameters)),
|
|
2234
|
+
this.createTimeoutPromise(call.gadgetName, timeoutMs)
|
|
2235
|
+
]);
|
|
2236
|
+
} else {
|
|
2237
|
+
result = await Promise.resolve(gadget.execute(validatedParameters));
|
|
2238
|
+
}
|
|
2239
|
+
const executionTimeMs = Date.now() - startTime;
|
|
2240
|
+
this.logger.info("Gadget executed successfully", {
|
|
2241
|
+
gadgetName: call.gadgetName,
|
|
2242
|
+
invocationId: call.invocationId,
|
|
2243
|
+
executionTimeMs
|
|
2244
|
+
});
|
|
2245
|
+
this.logger.debug("Gadget result", {
|
|
2246
|
+
gadgetName: call.gadgetName,
|
|
2247
|
+
invocationId: call.invocationId,
|
|
2248
|
+
parameters: validatedParameters,
|
|
2249
|
+
result,
|
|
2250
|
+
executionTimeMs
|
|
2251
|
+
});
|
|
2252
|
+
return {
|
|
2253
|
+
gadgetName: call.gadgetName,
|
|
2254
|
+
invocationId: call.invocationId,
|
|
2255
|
+
parameters: validatedParameters,
|
|
2256
|
+
result,
|
|
2257
|
+
executionTimeMs
|
|
2258
|
+
};
|
|
2259
|
+
} catch (error) {
|
|
2260
|
+
if (error instanceof BreakLoopException) {
|
|
2261
|
+
this.logger.info("Gadget requested loop termination", {
|
|
2262
|
+
gadgetName: call.gadgetName,
|
|
2263
|
+
message: error.message
|
|
2264
|
+
});
|
|
2265
|
+
return {
|
|
2266
|
+
gadgetName: call.gadgetName,
|
|
2267
|
+
invocationId: call.invocationId,
|
|
2268
|
+
parameters: validatedParameters,
|
|
2269
|
+
result: error.message,
|
|
2270
|
+
breaksLoop: true,
|
|
2271
|
+
executionTimeMs: Date.now() - startTime
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
if (error instanceof TimeoutException) {
|
|
2275
|
+
this.logger.error("Gadget execution timed out", {
|
|
2276
|
+
gadgetName: call.gadgetName,
|
|
2277
|
+
timeoutMs: error.timeoutMs,
|
|
2278
|
+
executionTimeMs: Date.now() - startTime
|
|
2279
|
+
});
|
|
2280
|
+
return {
|
|
2281
|
+
gadgetName: call.gadgetName,
|
|
2282
|
+
invocationId: call.invocationId,
|
|
2283
|
+
parameters: validatedParameters,
|
|
2284
|
+
error: error.message,
|
|
2285
|
+
executionTimeMs: Date.now() - startTime
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
if (error instanceof HumanInputException) {
|
|
2289
|
+
this.logger.info("Gadget requested human input", {
|
|
2290
|
+
gadgetName: call.gadgetName,
|
|
2291
|
+
question: error.question
|
|
2292
|
+
});
|
|
2293
|
+
if (this.onHumanInputRequired) {
|
|
2294
|
+
try {
|
|
2295
|
+
const answer = await this.onHumanInputRequired(error.question);
|
|
2296
|
+
this.logger.debug("Human input received", {
|
|
2297
|
+
gadgetName: call.gadgetName,
|
|
2298
|
+
answerLength: answer.length
|
|
2299
|
+
});
|
|
2300
|
+
return {
|
|
2301
|
+
gadgetName: call.gadgetName,
|
|
2302
|
+
invocationId: call.invocationId,
|
|
2303
|
+
parameters: validatedParameters,
|
|
2304
|
+
result: answer,
|
|
2305
|
+
executionTimeMs: Date.now() - startTime
|
|
2306
|
+
};
|
|
2307
|
+
} catch (inputError) {
|
|
2308
|
+
this.logger.error("Human input callback error", {
|
|
2309
|
+
gadgetName: call.gadgetName,
|
|
2310
|
+
error: inputError instanceof Error ? inputError.message : String(inputError)
|
|
2311
|
+
});
|
|
2312
|
+
return {
|
|
2313
|
+
gadgetName: call.gadgetName,
|
|
2314
|
+
invocationId: call.invocationId,
|
|
2315
|
+
parameters: validatedParameters,
|
|
2316
|
+
error: inputError instanceof Error ? inputError.message : String(inputError),
|
|
2317
|
+
executionTimeMs: Date.now() - startTime
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
this.logger.warn("Human input required but no callback provided", {
|
|
2322
|
+
gadgetName: call.gadgetName
|
|
2323
|
+
});
|
|
2324
|
+
return {
|
|
2325
|
+
gadgetName: call.gadgetName,
|
|
2326
|
+
invocationId: call.invocationId,
|
|
2327
|
+
parameters: validatedParameters,
|
|
2328
|
+
error: "Human input required but not available (stdin is not interactive)",
|
|
2329
|
+
executionTimeMs: Date.now() - startTime
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
const executionTimeMs = Date.now() - startTime;
|
|
2333
|
+
this.logger.error("Gadget execution failed", {
|
|
2334
|
+
gadgetName: call.gadgetName,
|
|
2335
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2336
|
+
executionTimeMs
|
|
2337
|
+
});
|
|
2338
|
+
return {
|
|
2339
|
+
gadgetName: call.gadgetName,
|
|
2340
|
+
invocationId: call.invocationId,
|
|
2341
|
+
parameters: validatedParameters,
|
|
2342
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2343
|
+
executionTimeMs
|
|
2344
|
+
};
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
// Execute multiple gadget calls in parallel
|
|
2348
|
+
async executeAll(calls) {
|
|
2349
|
+
return Promise.all(calls.map((call) => this.execute(call)));
|
|
2350
|
+
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Deep equality check for objects/arrays.
|
|
2353
|
+
* Used to detect if parameters were modified by an interceptor.
|
|
2354
|
+
*/
|
|
2355
|
+
deepEquals(a, b) {
|
|
2356
|
+
if (a === b) return true;
|
|
2357
|
+
if (a === null || b === null) return a === b;
|
|
2358
|
+
if (typeof a !== typeof b) return false;
|
|
2359
|
+
if (typeof a !== "object") return a === b;
|
|
2360
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
2361
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2362
|
+
if (a.length !== b.length) return false;
|
|
2363
|
+
return a.every((val, i) => this.deepEquals(val, b[i]));
|
|
2364
|
+
}
|
|
2365
|
+
const aObj = a;
|
|
2366
|
+
const bObj = b;
|
|
2367
|
+
const aKeys = Object.keys(aObj);
|
|
2368
|
+
const bKeys = Object.keys(bObj);
|
|
2369
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
2370
|
+
return aKeys.every((key) => this.deepEquals(aObj[key], bObj[key]));
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
});
|
|
2375
|
+
|
|
2059
2376
|
// src/agent/stream-processor.ts
|
|
2060
2377
|
var StreamProcessor;
|
|
2061
2378
|
var init_stream_processor = __esm({
|
|
@@ -2093,7 +2410,8 @@ var init_stream_processor = __esm({
|
|
|
2093
2410
|
options.registry,
|
|
2094
2411
|
options.onHumanInputRequired,
|
|
2095
2412
|
this.logger.getSubLogger({ name: "executor" }),
|
|
2096
|
-
options.defaultGadgetTimeoutMs
|
|
2413
|
+
options.defaultGadgetTimeoutMs,
|
|
2414
|
+
{ argPrefix: options.gadgetArgPrefix }
|
|
2097
2415
|
);
|
|
2098
2416
|
}
|
|
2099
2417
|
/**
|