yaml-flow 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +251 -2
- package/dist/batch/index.cjs +109 -0
- package/dist/batch/index.cjs.map +1 -0
- package/dist/batch/index.d.cts +126 -0
- package/dist/batch/index.d.ts +126 -0
- package/dist/batch/index.js +107 -0
- package/dist/batch/index.js.map +1 -0
- package/dist/config/index.cjs +80 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +71 -0
- package/dist/config/index.d.ts +71 -0
- package/dist/config/index.js +77 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.cjs +181 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +179 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -4,3 +4,5 @@ export { A as AgentActionEvent, C as COMPLETION_STRATEGIES, a as CONFLICT_STRATE
|
|
|
4
4
|
export { MemoryStore } from './stores/memory.cjs';
|
|
5
5
|
export { LocalStorageStore } from './stores/localStorage.cjs';
|
|
6
6
|
export { FileStore } from './stores/file.cjs';
|
|
7
|
+
export { BatchItemResult, BatchOptions, BatchProgress, BatchResult, batch } from './batch/index.cjs';
|
|
8
|
+
export { ConfigTemplates, Variables, resolveConfigTemplates, resolveVariables } from './config/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export { A as AgentActionEvent, C as COMPLETION_STRATEGIES, a as CONFLICT_STRATE
|
|
|
4
4
|
export { MemoryStore } from './stores/memory.js';
|
|
5
5
|
export { LocalStorageStore } from './stores/localStorage.js';
|
|
6
6
|
export { FileStore } from './stores/file.js';
|
|
7
|
+
export { BatchItemResult, BatchOptions, BatchProgress, BatchResult, batch } from './batch/index.js';
|
|
8
|
+
export { ConfigTemplates, Variables, resolveConfigTemplates, resolveVariables } from './config/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1513,6 +1513,184 @@ var FileStore = class {
|
|
|
1513
1513
|
}
|
|
1514
1514
|
};
|
|
1515
1515
|
|
|
1516
|
-
|
|
1516
|
+
// src/batch/runner.ts
|
|
1517
|
+
async function batch(items, options) {
|
|
1518
|
+
const {
|
|
1519
|
+
concurrency = 5,
|
|
1520
|
+
processor,
|
|
1521
|
+
onItemComplete,
|
|
1522
|
+
onItemError,
|
|
1523
|
+
onProgress,
|
|
1524
|
+
signal
|
|
1525
|
+
} = options;
|
|
1526
|
+
const total = items.length;
|
|
1527
|
+
const results = new Array(total);
|
|
1528
|
+
const batchStart = Date.now();
|
|
1529
|
+
let completed = 0;
|
|
1530
|
+
let failed = 0;
|
|
1531
|
+
let nextIndex = 0;
|
|
1532
|
+
function makeProgress(active) {
|
|
1533
|
+
const done = completed + failed;
|
|
1534
|
+
return {
|
|
1535
|
+
completed,
|
|
1536
|
+
failed,
|
|
1537
|
+
active,
|
|
1538
|
+
pending: total - done - active,
|
|
1539
|
+
total,
|
|
1540
|
+
percent: total === 0 ? 100 : Math.round(done / total * 100),
|
|
1541
|
+
elapsedMs: Date.now() - batchStart
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
if (total === 0) {
|
|
1545
|
+
return { items: [], completed: 0, failed: 0, total: 0, durationMs: 0 };
|
|
1546
|
+
}
|
|
1547
|
+
return new Promise((resolve) => {
|
|
1548
|
+
let active = 0;
|
|
1549
|
+
function tryStartNext() {
|
|
1550
|
+
while (active < concurrency && nextIndex < total) {
|
|
1551
|
+
if (signal?.aborted) {
|
|
1552
|
+
while (nextIndex < total) {
|
|
1553
|
+
const idx2 = nextIndex++;
|
|
1554
|
+
results[idx2] = {
|
|
1555
|
+
item: items[idx2],
|
|
1556
|
+
index: idx2,
|
|
1557
|
+
status: "failed",
|
|
1558
|
+
error: new Error("Batch aborted"),
|
|
1559
|
+
durationMs: 0
|
|
1560
|
+
};
|
|
1561
|
+
failed++;
|
|
1562
|
+
}
|
|
1563
|
+
if (active === 0 && completed + failed === total) {
|
|
1564
|
+
resolve({
|
|
1565
|
+
items: results,
|
|
1566
|
+
completed,
|
|
1567
|
+
failed,
|
|
1568
|
+
total,
|
|
1569
|
+
durationMs: Date.now() - batchStart
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
break;
|
|
1573
|
+
}
|
|
1574
|
+
const idx = nextIndex++;
|
|
1575
|
+
const item = items[idx];
|
|
1576
|
+
active++;
|
|
1577
|
+
const itemStart = Date.now();
|
|
1578
|
+
processor(item, idx).then((result) => {
|
|
1579
|
+
results[idx] = {
|
|
1580
|
+
item,
|
|
1581
|
+
index: idx,
|
|
1582
|
+
status: "completed",
|
|
1583
|
+
result,
|
|
1584
|
+
durationMs: Date.now() - itemStart
|
|
1585
|
+
};
|
|
1586
|
+
completed++;
|
|
1587
|
+
onItemComplete?.(item, result, idx);
|
|
1588
|
+
}).catch((err) => {
|
|
1589
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1590
|
+
results[idx] = {
|
|
1591
|
+
item,
|
|
1592
|
+
index: idx,
|
|
1593
|
+
status: "failed",
|
|
1594
|
+
error,
|
|
1595
|
+
durationMs: Date.now() - itemStart
|
|
1596
|
+
};
|
|
1597
|
+
failed++;
|
|
1598
|
+
onItemError?.(item, error, idx);
|
|
1599
|
+
}).finally(() => {
|
|
1600
|
+
active--;
|
|
1601
|
+
onProgress?.(makeProgress(active));
|
|
1602
|
+
if (completed + failed === total) {
|
|
1603
|
+
resolve({
|
|
1604
|
+
items: results,
|
|
1605
|
+
completed,
|
|
1606
|
+
failed,
|
|
1607
|
+
total,
|
|
1608
|
+
durationMs: Date.now() - batchStart
|
|
1609
|
+
});
|
|
1610
|
+
} else {
|
|
1611
|
+
tryStartNext();
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
tryStartNext();
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
// src/config/resolve-variables.ts
|
|
1621
|
+
function interpolateString(template, vars) {
|
|
1622
|
+
return template.replace(/\$\{([^}]+)\}/g, (match, key) => {
|
|
1623
|
+
const value = vars[key.trim()];
|
|
1624
|
+
return value !== void 0 ? String(value) : match;
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
function walkAndInterpolate(value, vars) {
|
|
1628
|
+
if (typeof value === "string") {
|
|
1629
|
+
return interpolateString(value, vars);
|
|
1630
|
+
}
|
|
1631
|
+
if (Array.isArray(value)) {
|
|
1632
|
+
return value.map((item) => walkAndInterpolate(item, vars));
|
|
1633
|
+
}
|
|
1634
|
+
if (value !== null && typeof value === "object") {
|
|
1635
|
+
const result = {};
|
|
1636
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1637
|
+
result[k] = walkAndInterpolate(v, vars);
|
|
1638
|
+
}
|
|
1639
|
+
return result;
|
|
1640
|
+
}
|
|
1641
|
+
return value;
|
|
1642
|
+
}
|
|
1643
|
+
function resolveVariables(config, variables) {
|
|
1644
|
+
return walkAndInterpolate(config, variables);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// src/config/resolve-config-templates.ts
|
|
1648
|
+
function mergeConfigs(template, taskConfig) {
|
|
1649
|
+
const merged = { ...template };
|
|
1650
|
+
for (const [key, value] of Object.entries(taskConfig)) {
|
|
1651
|
+
if (key === "config-template") continue;
|
|
1652
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && merged[key] !== null && typeof merged[key] === "object" && !Array.isArray(merged[key])) {
|
|
1653
|
+
merged[key] = {
|
|
1654
|
+
...merged[key],
|
|
1655
|
+
...value
|
|
1656
|
+
};
|
|
1657
|
+
} else {
|
|
1658
|
+
merged[key] = value;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
return merged;
|
|
1662
|
+
}
|
|
1663
|
+
function resolveConfigTemplates(config) {
|
|
1664
|
+
const templates = config["configTemplates"] ?? config["config-templates"] ?? {};
|
|
1665
|
+
const tasksKey = "tasks" in config ? "tasks" : "steps" in config ? "steps" : null;
|
|
1666
|
+
if (!tasksKey) return config;
|
|
1667
|
+
const tasks = config[tasksKey];
|
|
1668
|
+
if (!tasks || typeof tasks !== "object") return config;
|
|
1669
|
+
const resolvedTasks = {};
|
|
1670
|
+
for (const [name, task] of Object.entries(tasks)) {
|
|
1671
|
+
const taskConfig = task["config"];
|
|
1672
|
+
const templateName = taskConfig?.["config-template"];
|
|
1673
|
+
if (!templateName || !taskConfig) {
|
|
1674
|
+
resolvedTasks[name] = task;
|
|
1675
|
+
continue;
|
|
1676
|
+
}
|
|
1677
|
+
const template = templates[templateName];
|
|
1678
|
+
if (!template) {
|
|
1679
|
+
const { "config-template": _, ...rest } = taskConfig;
|
|
1680
|
+
resolvedTasks[name] = { ...task, config: rest };
|
|
1681
|
+
continue;
|
|
1682
|
+
}
|
|
1683
|
+
resolvedTasks[name] = {
|
|
1684
|
+
...task,
|
|
1685
|
+
config: mergeConfigs(template, taskConfig)
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
const result = { ...config, [tasksKey]: resolvedTasks };
|
|
1689
|
+
delete result["configTemplates"];
|
|
1690
|
+
delete result["config-templates"];
|
|
1691
|
+
return result;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
export { COMPLETION_STRATEGIES, CONFLICT_STRATEGIES, DEFAULTS, EXECUTION_MODES, EXECUTION_STATUS, FileStore, StepMachine as FlowEngine, LocalStorageStore, MemoryStore, StepMachine, TASK_STATUS, addDynamicTask, apply, applyAll, applyStepResult, batch, checkCircuitBreaker, computeAvailableOutputs, computeStepInput, createDefaultTaskState, createStepMachine as createEngine, createInitialExecutionState, createInitialState, createStepMachine, detectStuckState, extractReturnData, getAllTasks, getCandidateTasks, getProvides, getRequires, getTask, hasTask, isExecutionComplete, isNonActiveTask, isRepeatableTask, isTaskCompleted, isTaskRunning, loadStepFlow, next, resolveConfigTemplates, resolveVariables, validateStepFlowConfig };
|
|
1517
1695
|
//# sourceMappingURL=index.js.map
|
|
1518
1696
|
//# sourceMappingURL=index.js.map
|