yaml-flow 2.5.0 → 2.6.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
@@ -10,3 +10,4 @@ export { ConfigTemplates, Variables, resolveConfigTemplates, resolveVariables }
10
10
  export { addNode, addProvides, addRequires, applyEvent, createLiveGraph, disableNode, drainTokens, enableNode, getDownstream, getNode, getUnreachableNodes, getUnreachableTokens, getUpstream, injectTokens, inspect, removeNode, removeProvides, removeRequires, resetNode, restore, schedule, snapshot } from './continuous-event-graph/index.cjs';
11
11
  export { B as BlockedTask, D as DownstreamResult, L as LiveGraph, a as LiveGraphHealth, b as LiveGraphSnapshot, N as NodeInfo, P as PendingTask, S as ScheduleResult, U as UnreachableNodesResult, c as UnreachableTokensResult, d as UnresolvedDependency, e as UpstreamResult } from './types-C2lOwquM.cjs';
12
12
  export { CliAdapterOptions, HttpAdapterOptions, InferAndApplyResult, InferenceAdapter, InferenceHints, InferenceOptions, InferenceResult, InferredCompletion, applyInferences, buildInferencePrompt, createCliAdapter, createHttpAdapter, inferAndApply, inferCompletions } from './inference/index.cjs';
13
+ export { CardCompute, ComputeExpr, ComputeFn, ComputeNode, EvalFn } from './card-compute/index.cjs';
package/dist/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export { ConfigTemplates, Variables, resolveConfigTemplates, resolveVariables }
10
10
  export { addNode, addProvides, addRequires, applyEvent, createLiveGraph, disableNode, drainTokens, enableNode, getDownstream, getNode, getUnreachableNodes, getUnreachableTokens, getUpstream, injectTokens, inspect, removeNode, removeProvides, removeRequires, resetNode, restore, schedule, snapshot } from './continuous-event-graph/index.js';
11
11
  export { B as BlockedTask, D as DownstreamResult, L as LiveGraph, a as LiveGraphHealth, b as LiveGraphSnapshot, N as NodeInfo, P as PendingTask, S as ScheduleResult, U as UnreachableNodesResult, c as UnreachableTokensResult, d as UnresolvedDependency, e as UpstreamResult } from './types-mS_pPftm.js';
12
12
  export { CliAdapterOptions, HttpAdapterOptions, InferAndApplyResult, InferenceAdapter, InferenceHints, InferenceOptions, InferenceResult, InferredCompletion, applyInferences, buildInferencePrompt, createCliAdapter, createHttpAdapter, inferAndApply, inferCompletions } from './inference/index.js';
13
+ export { CardCompute, ComputeExpr, ComputeFn, ComputeNode, EvalFn } from './card-compute/index.js';
package/dist/index.js CHANGED
@@ -253,7 +253,7 @@ var StepMachine = class {
253
253
  }
254
254
  }
255
255
  sleep(ms) {
256
- return new Promise((resolve) => setTimeout(resolve, ms));
256
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
257
257
  }
258
258
  async run(initialData) {
259
259
  const runId = generateRunId();
@@ -2155,7 +2155,7 @@ async function batch(items, options) {
2155
2155
  if (total === 0) {
2156
2156
  return { items: [], completed: 0, failed: 0, total: 0, durationMs: 0 };
2157
2157
  }
2158
- return new Promise((resolve) => {
2158
+ return new Promise((resolve2) => {
2159
2159
  let active = 0;
2160
2160
  function tryStartNext() {
2161
2161
  while (active < concurrency && nextIndex < total) {
@@ -2172,7 +2172,7 @@ async function batch(items, options) {
2172
2172
  failed++;
2173
2173
  }
2174
2174
  if (active === 0 && completed + failed === total) {
2175
- resolve({
2175
+ resolve2({
2176
2176
  items: results,
2177
2177
  completed,
2178
2178
  failed,
@@ -2211,7 +2211,7 @@ async function batch(items, options) {
2211
2211
  active--;
2212
2212
  onProgress?.(makeProgress(active));
2213
2213
  if (completed + failed === total) {
2214
- resolve({
2214
+ resolve2({
2215
2215
  items: results,
2216
2216
  completed,
2217
2217
  failed,
@@ -3212,7 +3212,7 @@ function createCliAdapter(opts) {
3212
3212
  const timeout = opts.timeout ?? 6e4;
3213
3213
  return {
3214
3214
  analyze: (prompt) => {
3215
- return new Promise((resolve, reject) => {
3215
+ return new Promise((resolve2, reject) => {
3216
3216
  const args = opts.args(prompt);
3217
3217
  const child = execFile(
3218
3218
  opts.command,
@@ -3232,7 +3232,7 @@ stderr: ${stderr.slice(0, 500)}` : "") + `
3232
3232
  ${error.message}`
3233
3233
  ));
3234
3234
  } else {
3235
- resolve(stdout);
3235
+ resolve2(stdout);
3236
3236
  }
3237
3237
  }
3238
3238
  );
@@ -3280,6 +3280,321 @@ function createHttpAdapter(opts) {
3280
3280
  };
3281
3281
  }
3282
3282
 
3283
- export { COMPLETION_STRATEGIES, CONFLICT_STRATEGIES, DEFAULTS, EXECUTION_MODES, EXECUTION_STATUS, FileStore, StepMachine as FlowEngine, LocalStorageStore, MemoryStore, StepMachine, TASK_STATUS, addDynamicTask, addNode, addProvides, addRequires, apply, applyAll, applyEvent, applyInferences, applyStepResult, batch, buildInferencePrompt, checkCircuitBreaker, computeAvailableOutputs, computeStepInput, createCliAdapter, createDefaultTaskState, createStepMachine as createEngine, createHttpAdapter, createInitialExecutionState, createInitialState, createLiveGraph, createStepMachine, detectStuckState, disableNode, drainTokens, enableNode, exportGraphConfig, exportGraphConfigToFile, extractReturnData, flowToMermaid, getAllTasks, getCandidateTasks, getDownstream, getNode, getProvides, getRequires, getTask, getUnreachableNodes, getUnreachableTokens, getUpstream, graphToMermaid, hasTask, inferAndApply, inferCompletions, injectTokens, inspect, isExecutionComplete, isNonActiveTask, isRepeatableTask, isTaskCompleted, isTaskRunning, loadGraphConfig, loadStepFlow, next, planExecution, removeNode, removeProvides, removeRequires, resetNode, resolveConfigTemplates, resolveVariables, restore, schedule, snapshot, validateGraph, validateGraphConfig, validateStepFlowConfig };
3283
+ // src/card-compute/index.ts
3284
+ function deepGet(obj, path) {
3285
+ if (!path || !obj) return void 0;
3286
+ const parts = path.split(".");
3287
+ let cur = obj;
3288
+ for (let i = 0; i < parts.length; i++) {
3289
+ if (cur == null) return void 0;
3290
+ cur = cur[parts[i]];
3291
+ }
3292
+ return cur;
3293
+ }
3294
+ function deepSet(obj, path, value) {
3295
+ const parts = path.split(".");
3296
+ let cur = obj;
3297
+ for (let i = 0; i < parts.length - 1; i++) {
3298
+ if (cur[parts[i]] == null || typeof cur[parts[i]] !== "object") cur[parts[i]] = {};
3299
+ cur = cur[parts[i]];
3300
+ }
3301
+ cur[parts[parts.length - 1]] = value;
3302
+ }
3303
+ var _fns = {};
3304
+ _fns.sum = (input, _e, opts) => {
3305
+ const a = Array.isArray(input) ? input : [];
3306
+ return opts.field ? a.reduce((s, r) => s + (Number(r[opts.field]) || 0), 0) : a.reduce((s, v) => s + (Number(v) || 0), 0);
3307
+ };
3308
+ _fns.avg = (input, _e, opts) => {
3309
+ const s = _fns.sum(input, _e, opts);
3310
+ const n = Array.isArray(input) ? input.length : 1;
3311
+ return n ? s / n : 0;
3312
+ };
3313
+ _fns.min = (input, _e, opts) => {
3314
+ const a = Array.isArray(input) ? input : [];
3315
+ const vals = opts.field ? a.map((r) => Number(r[opts.field])) : a.map(Number);
3316
+ return vals.length ? Math.min(...vals) : 0;
3317
+ };
3318
+ _fns.max = (input, _e, opts) => {
3319
+ const a = Array.isArray(input) ? input : [];
3320
+ const vals = opts.field ? a.map((r) => Number(r[opts.field])) : a.map(Number);
3321
+ return vals.length ? Math.max(...vals) : 0;
3322
+ };
3323
+ _fns.count = (input) => Array.isArray(input) ? input.length : input != null ? 1 : 0;
3324
+ _fns.first = (input) => Array.isArray(input) ? input[0] : input;
3325
+ _fns.last = (input) => Array.isArray(input) ? input[input.length - 1] : input;
3326
+ _fns.add = (input) => {
3327
+ const a = Array.isArray(input) ? input : [];
3328
+ return a.reduce((s, v) => s + Number(v), 0);
3329
+ };
3330
+ _fns.sub = (input) => {
3331
+ const a = Array.isArray(input) ? input : [];
3332
+ return a.length >= 2 ? Number(a[0]) - Number(a[1]) : 0;
3333
+ };
3334
+ _fns.mul = (input) => {
3335
+ const a = Array.isArray(input) ? input : [];
3336
+ return a.reduce((s, v) => s * Number(v), 1);
3337
+ };
3338
+ _fns.div = (input) => {
3339
+ const a = Array.isArray(input) ? input : [];
3340
+ return a.length >= 2 && Number(a[1]) !== 0 ? Number(a[0]) / Number(a[1]) : 0;
3341
+ };
3342
+ _fns.round = (input, _e, opts) => {
3343
+ const decimals = opts.decimals != null ? opts.decimals : 0;
3344
+ const factor = Math.pow(10, decimals);
3345
+ return Math.round(Number(input) * factor) / factor;
3346
+ };
3347
+ _fns.abs = (input) => Math.abs(Number(input));
3348
+ _fns.mod = (input) => {
3349
+ const a = Array.isArray(input) ? input : [];
3350
+ return a.length >= 2 ? Number(a[0]) % Number(a[1]) : 0;
3351
+ };
3352
+ _fns.gt = (input) => {
3353
+ const a = Array.isArray(input) ? input : [];
3354
+ return a.length >= 2 && Number(a[0]) > Number(a[1]);
3355
+ };
3356
+ _fns.gte = (input) => {
3357
+ const a = Array.isArray(input) ? input : [];
3358
+ return a.length >= 2 && Number(a[0]) >= Number(a[1]);
3359
+ };
3360
+ _fns.lt = (input) => {
3361
+ const a = Array.isArray(input) ? input : [];
3362
+ return a.length >= 2 && Number(a[0]) < Number(a[1]);
3363
+ };
3364
+ _fns.lte = (input) => {
3365
+ const a = Array.isArray(input) ? input : [];
3366
+ return a.length >= 2 && Number(a[0]) <= Number(a[1]);
3367
+ };
3368
+ _fns.eq = (input) => {
3369
+ const a = Array.isArray(input) ? input : [];
3370
+ return a.length >= 2 && a[0] === a[1];
3371
+ };
3372
+ _fns.neq = (input) => {
3373
+ const a = Array.isArray(input) ? input : [];
3374
+ return a.length >= 2 && a[0] !== a[1];
3375
+ };
3376
+ _fns.and = (input) => {
3377
+ const a = Array.isArray(input) ? input : [];
3378
+ return a.every(Boolean);
3379
+ };
3380
+ _fns.or = (input) => {
3381
+ const a = Array.isArray(input) ? input : [];
3382
+ return a.some(Boolean);
3383
+ };
3384
+ _fns.not = (input) => !input;
3385
+ _fns.concat = (input) => {
3386
+ const a = Array.isArray(input) ? input : [];
3387
+ return a.map((v) => v != null ? String(v) : "").join("");
3388
+ };
3389
+ _fns.upper = (input) => String(input || "").toUpperCase();
3390
+ _fns.lower = (input) => String(input || "").toLowerCase();
3391
+ _fns.template = (input, _e, opts) => {
3392
+ let t = String(opts.format || "");
3393
+ if (input && typeof input === "object" && !Array.isArray(input)) {
3394
+ for (const k of Object.keys(input)) {
3395
+ const v = input[k];
3396
+ t = t.split("{{" + k + "}}").join(v != null ? String(v) : "");
3397
+ }
3398
+ }
3399
+ return t;
3400
+ };
3401
+ _fns.join = (input, _e, opts) => {
3402
+ const a = Array.isArray(input) ? input : [];
3403
+ const sep = opts.separator != null ? String(opts.separator) : ", ";
3404
+ return a.map((v) => v != null ? String(v) : "").join(sep);
3405
+ };
3406
+ _fns.split = (input, _e, opts) => {
3407
+ const sep = opts.separator != null ? String(opts.separator) : ",";
3408
+ return String(input || "").split(sep).map((s) => s.trim());
3409
+ };
3410
+ _fns.trim = (input) => String(input || "").trim();
3411
+ _fns.pluck = (input, _e, opts) => Array.isArray(input) ? input.map((r) => r[opts.field]) : [];
3412
+ _fns.filter = (input, _e, opts) => {
3413
+ if (!Array.isArray(input)) return [];
3414
+ if (opts.field) return input.filter((r) => !!r[opts.field]);
3415
+ return input.filter(Boolean);
3416
+ };
3417
+ _fns.map = (input) => Array.isArray(input) ? input.slice() : [];
3418
+ _fns.sort = (input, _e, opts) => {
3419
+ const a = Array.isArray(input) ? input.slice() : [];
3420
+ const f = opts.field;
3421
+ const dir = opts.direction === "desc" ? -1 : 1;
3422
+ if (f) return a.sort((x, y) => x[f] > y[f] ? dir : x[f] < y[f] ? -dir : 0);
3423
+ return a.sort((x, y) => x > y ? dir : x < y ? -dir : 0);
3424
+ };
3425
+ _fns.slice = (input, _e, opts) => Array.isArray(input) ? input.slice(opts.start || 0, opts.end) : input;
3426
+ _fns.flat = (input, _e, opts) => {
3427
+ const depth = opts.depth != null ? opts.depth : 1;
3428
+ return Array.isArray(input) ? input.flat(depth) : [input];
3429
+ };
3430
+ _fns.unique = (input) => {
3431
+ if (!Array.isArray(input)) return [input];
3432
+ const seen = /* @__PURE__ */ new Set();
3433
+ return input.filter((v) => {
3434
+ const key = typeof v === "object" ? JSON.stringify(v) : v;
3435
+ if (seen.has(key)) return false;
3436
+ seen.add(key);
3437
+ return true;
3438
+ });
3439
+ };
3440
+ _fns.group = (input, _e, opts) => {
3441
+ const a = Array.isArray(input) ? input : [];
3442
+ const g = {};
3443
+ a.forEach((r) => {
3444
+ const k = String(r[opts.field] || "");
3445
+ if (!g[k]) g[k] = [];
3446
+ g[k].push(r);
3447
+ });
3448
+ return g;
3449
+ };
3450
+ _fns.flatten_keys = (input) => {
3451
+ if (!input || typeof input !== "object" || Array.isArray(input)) return [];
3452
+ const result = [];
3453
+ for (const k of Object.keys(input)) {
3454
+ const vals = Array.isArray(input[k]) ? input[k] : [input[k]];
3455
+ vals.forEach((v) => result.push({ key: k, value: v }));
3456
+ }
3457
+ return result;
3458
+ };
3459
+ _fns.entries = (input) => {
3460
+ if (!input || typeof input !== "object" || Array.isArray(input)) return [];
3461
+ return Object.keys(input).map((k) => ({ key: k, value: input[k] }));
3462
+ };
3463
+ _fns.from_entries = (input) => {
3464
+ if (!Array.isArray(input)) return {};
3465
+ const obj = {};
3466
+ input.forEach((item) => {
3467
+ if (item.key != null) obj[item.key] = item.value;
3468
+ });
3469
+ return obj;
3470
+ };
3471
+ _fns.length = (input) => {
3472
+ if (Array.isArray(input)) return input.length;
3473
+ if (typeof input === "string") return input.length;
3474
+ if (input && typeof input === "object") return Object.keys(input).length;
3475
+ return 0;
3476
+ };
3477
+ _fns.get = (input, _e, opts) => deepGet(input, opts.field || opts.path || "");
3478
+ _fns.default = (input, _e, opts) => input != null ? input : opts.value;
3479
+ _fns.coalesce = (input) => {
3480
+ const a = Array.isArray(input) ? input : [];
3481
+ for (let i = 0; i < a.length; i++) {
3482
+ if (a[i] != null) return a[i];
3483
+ }
3484
+ return null;
3485
+ };
3486
+ _fns.now = () => (/* @__PURE__ */ new Date()).toISOString();
3487
+ _fns.diff_days = (input) => {
3488
+ const a = Array.isArray(input) ? input : [];
3489
+ return a.length >= 2 ? Math.floor((new Date(a[0]).getTime() - new Date(a[1]).getTime()) / 864e5) : 0;
3490
+ };
3491
+ _fns.format_date = (input, _e, opts) => {
3492
+ try {
3493
+ const d = new Date(input);
3494
+ if (opts.format === "iso") return d.toISOString();
3495
+ if (opts.format === "date") return d.toLocaleDateString();
3496
+ if (opts.format === "time") return d.toLocaleTimeString();
3497
+ return d.toLocaleDateString();
3498
+ } catch {
3499
+ return String(input);
3500
+ }
3501
+ };
3502
+ _fns.parse_date = (input) => {
3503
+ try {
3504
+ return new Date(input).toISOString();
3505
+ } catch {
3506
+ return null;
3507
+ }
3508
+ };
3509
+ _fns.to_number = (input) => Number(input) || 0;
3510
+ _fns.to_string = (input) => input != null ? String(input) : "";
3511
+ _fns.to_bool = (input) => !!input;
3512
+ _fns.type_of = (input) => Array.isArray(input) ? "array" : typeof input;
3513
+ _fns.is_null = (input) => input == null;
3514
+ _fns.is_empty = (input) => {
3515
+ if (input == null) return true;
3516
+ if (Array.isArray(input)) return input.length === 0;
3517
+ if (typeof input === "string") return input.length === 0;
3518
+ if (typeof input === "object") return Object.keys(input).length === 0;
3519
+ return false;
3520
+ };
3521
+ var _customFns = {};
3522
+ function evalExpr(expr, node) {
3523
+ if (expr == null) return expr;
3524
+ if (typeof expr !== "object" || Array.isArray(expr)) return expr;
3525
+ const e = expr;
3526
+ if (!e.fn) return expr;
3527
+ let input = e.input;
3528
+ if (typeof input === "string" && input.startsWith("state.")) {
3529
+ input = deepGet(node, input);
3530
+ } else if (Array.isArray(input)) {
3531
+ input = input.map((v) => {
3532
+ if (typeof v === "string" && v.startsWith("state.")) return deepGet(node, v);
3533
+ if (v && typeof v === "object" && v.fn) return evalExpr(v, node);
3534
+ return v;
3535
+ });
3536
+ } else if (input && typeof input === "object" && input.fn) {
3537
+ input = evalExpr(input, node);
3538
+ }
3539
+ if (e.fn === "if") {
3540
+ const cond = evalExpr(e.cond, node);
3541
+ if (cond) {
3542
+ return e.then && typeof e.then === "object" && e.then.fn ? evalExpr(e.then, node) : e.then;
3543
+ } else {
3544
+ return e.else && typeof e.else === "object" && e.else.fn ? evalExpr(e.else, node) : e.else;
3545
+ }
3546
+ }
3547
+ if (e.fn === "filter" && Array.isArray(input) && e.where) {
3548
+ return input.filter((item) => {
3549
+ const tmp = { state: { ...node.state, $: item } };
3550
+ return evalExpr(e.where, tmp);
3551
+ });
3552
+ }
3553
+ if (e.fn === "map" && Array.isArray(input) && e.apply) {
3554
+ return input.map((item) => {
3555
+ const tmp = { state: { ...node.state, $: item } };
3556
+ return evalExpr(e.apply, tmp);
3557
+ });
3558
+ }
3559
+ const fn = _customFns[e.fn] || _fns[e.fn];
3560
+ if (!fn) {
3561
+ console.warn('CardCompute: unknown function "' + e.fn + '"');
3562
+ return void 0;
3563
+ }
3564
+ return fn(input, evalExpr, e);
3565
+ }
3566
+ function run(node) {
3567
+ if (!node || !node.compute) return node;
3568
+ if (!node.state) node.state = {};
3569
+ for (const key of Object.keys(node.compute)) {
3570
+ try {
3571
+ const val = evalExpr(node.compute[key], node);
3572
+ deepSet(node.state, key, val);
3573
+ } catch (err) {
3574
+ console.error(`CardCompute.run error on "${node.id || "?"}.${key}":`, err);
3575
+ }
3576
+ }
3577
+ return node;
3578
+ }
3579
+ function resolve(node, path) {
3580
+ return deepGet(node, path);
3581
+ }
3582
+ function registerFunction(name, fn) {
3583
+ _customFns[name] = fn;
3584
+ }
3585
+ var CardCompute = {
3586
+ run,
3587
+ eval: evalExpr,
3588
+ resolve,
3589
+ registerFunction,
3590
+ get functions() {
3591
+ const all = {};
3592
+ for (const k of Object.keys(_fns)) all[k] = _fns[k];
3593
+ for (const k of Object.keys(_customFns)) all[k] = _customFns[k];
3594
+ return all;
3595
+ }
3596
+ };
3597
+
3598
+ export { COMPLETION_STRATEGIES, CONFLICT_STRATEGIES, CardCompute, DEFAULTS, EXECUTION_MODES, EXECUTION_STATUS, FileStore, StepMachine as FlowEngine, LocalStorageStore, MemoryStore, StepMachine, TASK_STATUS, addDynamicTask, addNode, addProvides, addRequires, apply, applyAll, applyEvent, applyInferences, applyStepResult, batch, buildInferencePrompt, checkCircuitBreaker, computeAvailableOutputs, computeStepInput, createCliAdapter, createDefaultTaskState, createStepMachine as createEngine, createHttpAdapter, createInitialExecutionState, createInitialState, createLiveGraph, createStepMachine, detectStuckState, disableNode, drainTokens, enableNode, exportGraphConfig, exportGraphConfigToFile, extractReturnData, flowToMermaid, getAllTasks, getCandidateTasks, getDownstream, getNode, getProvides, getRequires, getTask, getUnreachableNodes, getUnreachableTokens, getUpstream, graphToMermaid, hasTask, inferAndApply, inferCompletions, injectTokens, inspect, isExecutionComplete, isNonActiveTask, isRepeatableTask, isTaskCompleted, isTaskRunning, loadGraphConfig, loadStepFlow, next, planExecution, removeNode, removeProvides, removeRequires, resetNode, resolveConfigTemplates, resolveVariables, restore, schedule, snapshot, validateGraph, validateGraphConfig, validateStepFlowConfig };
3284
3599
  //# sourceMappingURL=index.js.map
3285
3600
  //# sourceMappingURL=index.js.map