yaml-flow 2.5.0 → 2.6.1
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/browser/card-compute.js +546 -0
- package/browser/live-cards.js +1381 -0
- package/browser/live-cards.schema.json +246 -0
- package/dist/card-compute/index.cjs +456 -0
- package/dist/card-compute/index.cjs.map +1 -0
- package/dist/card-compute/index.d.cts +85 -0
- package/dist/card-compute/index.d.ts +85 -0
- package/dist/card-compute/index.js +451 -0
- package/dist/card-compute/index.js.map +1 -0
- package/dist/index.cjs +454 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +454 -7
- package/dist/index.js.map +1 -1
- package/package.json +8 -2
- package/schema/live-cards.schema.json +246 -0
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, ValidationResult } 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, ValidationResult } 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((
|
|
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((
|
|
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
|
-
|
|
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
|
-
|
|
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((
|
|
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
|
-
|
|
3235
|
+
resolve2(stdout);
|
|
3236
3236
|
}
|
|
3237
3237
|
}
|
|
3238
3238
|
);
|
|
@@ -3280,6 +3280,453 @@ function createHttpAdapter(opts) {
|
|
|
3280
3280
|
};
|
|
3281
3281
|
}
|
|
3282
3282
|
|
|
3283
|
-
|
|
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 VALID_ELEMENT_KINDS = /* @__PURE__ */ new Set([
|
|
3586
|
+
"metric",
|
|
3587
|
+
"table",
|
|
3588
|
+
"chart",
|
|
3589
|
+
"form",
|
|
3590
|
+
"filter",
|
|
3591
|
+
"list",
|
|
3592
|
+
"notes",
|
|
3593
|
+
"todo",
|
|
3594
|
+
"alert",
|
|
3595
|
+
"narrative",
|
|
3596
|
+
"badge",
|
|
3597
|
+
"text",
|
|
3598
|
+
"markdown",
|
|
3599
|
+
"custom"
|
|
3600
|
+
]);
|
|
3601
|
+
var VALID_SOURCE_KINDS = /* @__PURE__ */ new Set(["api", "websocket", "static", "llm"]);
|
|
3602
|
+
var VALID_STATUSES = /* @__PURE__ */ new Set(["fresh", "stale", "loading", "error"]);
|
|
3603
|
+
var CARD_ALLOWED_KEYS = /* @__PURE__ */ new Set(["id", "type", "meta", "data", "view", "state", "compute"]);
|
|
3604
|
+
var SOURCE_ALLOWED_KEYS = /* @__PURE__ */ new Set(["id", "type", "meta", "data", "source", "state", "compute"]);
|
|
3605
|
+
function validateNode(node) {
|
|
3606
|
+
const errors = [];
|
|
3607
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) {
|
|
3608
|
+
return { ok: false, errors: ["Node must be a non-null object"] };
|
|
3609
|
+
}
|
|
3610
|
+
const n = node;
|
|
3611
|
+
if (typeof n.id !== "string" || !n.id) {
|
|
3612
|
+
errors.push("id: required, must be a non-empty string");
|
|
3613
|
+
}
|
|
3614
|
+
if (n.type !== "card" && n.type !== "source") {
|
|
3615
|
+
errors.push('type: must be "card" or "source"');
|
|
3616
|
+
return { ok: false, errors };
|
|
3617
|
+
}
|
|
3618
|
+
const allowed = n.type === "card" ? CARD_ALLOWED_KEYS : SOURCE_ALLOWED_KEYS;
|
|
3619
|
+
for (const key of Object.keys(n)) {
|
|
3620
|
+
if (!allowed.has(key)) errors.push(`Unknown top-level key: "${key}"`);
|
|
3621
|
+
}
|
|
3622
|
+
if (n.state == null || typeof n.state !== "object" || Array.isArray(n.state)) {
|
|
3623
|
+
errors.push("state: required, must be an object");
|
|
3624
|
+
} else {
|
|
3625
|
+
const state = n.state;
|
|
3626
|
+
if (state.status != null && !VALID_STATUSES.has(state.status)) {
|
|
3627
|
+
errors.push(`state.status: must be one of: ${[...VALID_STATUSES].join(", ")}`);
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
if (n.meta != null) {
|
|
3631
|
+
if (typeof n.meta !== "object" || Array.isArray(n.meta)) {
|
|
3632
|
+
errors.push("meta: must be an object");
|
|
3633
|
+
} else {
|
|
3634
|
+
const meta = n.meta;
|
|
3635
|
+
if (meta.title != null && typeof meta.title !== "string") errors.push("meta.title: must be a string");
|
|
3636
|
+
if (meta.tags != null && !Array.isArray(meta.tags)) errors.push("meta.tags: must be an array");
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3639
|
+
if (n.data != null) {
|
|
3640
|
+
if (typeof n.data !== "object" || Array.isArray(n.data)) {
|
|
3641
|
+
errors.push("data: must be an object");
|
|
3642
|
+
} else {
|
|
3643
|
+
const data = n.data;
|
|
3644
|
+
if (data.requires != null && !Array.isArray(data.requires)) errors.push("data.requires: must be an array of strings");
|
|
3645
|
+
if (data.provides != null && (typeof data.provides !== "object" || Array.isArray(data.provides))) errors.push("data.provides: must be an object");
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
if (n.compute != null) {
|
|
3649
|
+
if (typeof n.compute !== "object" || Array.isArray(n.compute)) {
|
|
3650
|
+
errors.push("compute: must be an object");
|
|
3651
|
+
} else {
|
|
3652
|
+
for (const [key, expr] of Object.entries(n.compute)) {
|
|
3653
|
+
if (!expr || typeof expr !== "object" || Array.isArray(expr)) {
|
|
3654
|
+
errors.push(`compute.${key}: must be a compute expression object`);
|
|
3655
|
+
} else if (!expr.fn) {
|
|
3656
|
+
errors.push(`compute.${key}: missing required "fn" property`);
|
|
3657
|
+
} else {
|
|
3658
|
+
const fn = expr.fn;
|
|
3659
|
+
if (!_fns[fn] && !_customFns[fn]) {
|
|
3660
|
+
errors.push(`compute.${key}: unknown function "${fn}"`);
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
if (n.type === "card") {
|
|
3667
|
+
if (n.source != null) errors.push('Card nodes must not have "source" \u2014 use type "source" instead');
|
|
3668
|
+
if (n.view == null || typeof n.view !== "object" || Array.isArray(n.view)) {
|
|
3669
|
+
errors.push("view: required for card nodes, must be an object");
|
|
3670
|
+
} else {
|
|
3671
|
+
const view = n.view;
|
|
3672
|
+
if (!Array.isArray(view.elements) || view.elements.length === 0) {
|
|
3673
|
+
errors.push("view.elements: required, must be a non-empty array");
|
|
3674
|
+
} else {
|
|
3675
|
+
view.elements.forEach((elem, i) => {
|
|
3676
|
+
if (!elem || typeof elem !== "object") {
|
|
3677
|
+
errors.push(`view.elements[${i}]: must be an object`);
|
|
3678
|
+
return;
|
|
3679
|
+
}
|
|
3680
|
+
if (!elem.kind || typeof elem.kind !== "string") {
|
|
3681
|
+
errors.push(`view.elements[${i}].kind: required, must be a string`);
|
|
3682
|
+
} else if (!VALID_ELEMENT_KINDS.has(elem.kind)) {
|
|
3683
|
+
errors.push(`view.elements[${i}].kind: unknown kind "${elem.kind}". Valid: ${[...VALID_ELEMENT_KINDS].join(", ")}`);
|
|
3684
|
+
}
|
|
3685
|
+
if (elem.data != null && (typeof elem.data !== "object" || Array.isArray(elem.data))) {
|
|
3686
|
+
errors.push(`view.elements[${i}].data: must be an object`);
|
|
3687
|
+
}
|
|
3688
|
+
});
|
|
3689
|
+
}
|
|
3690
|
+
if (view.layout != null && (typeof view.layout !== "object" || Array.isArray(view.layout))) {
|
|
3691
|
+
errors.push("view.layout: must be an object");
|
|
3692
|
+
}
|
|
3693
|
+
if (view.features != null && (typeof view.features !== "object" || Array.isArray(view.features))) {
|
|
3694
|
+
errors.push("view.features: must be an object");
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
if (n.type === "source") {
|
|
3699
|
+
if (n.view != null) errors.push('Source nodes must not have "view" \u2014 use type "card" instead');
|
|
3700
|
+
if (n.source == null || typeof n.source !== "object" || Array.isArray(n.source)) {
|
|
3701
|
+
errors.push("source: required for source nodes, must be an object");
|
|
3702
|
+
} else {
|
|
3703
|
+
const src = n.source;
|
|
3704
|
+
if (!src.kind || !VALID_SOURCE_KINDS.has(src.kind)) {
|
|
3705
|
+
errors.push(`source.kind: required, must be one of: ${[...VALID_SOURCE_KINDS].join(", ")}`);
|
|
3706
|
+
}
|
|
3707
|
+
if (typeof src.bindTo !== "string" || !src.bindTo) {
|
|
3708
|
+
errors.push("source.bindTo: required, must be a state path string");
|
|
3709
|
+
} else if (!src.bindTo.startsWith("state.")) {
|
|
3710
|
+
errors.push('source.bindTo: must start with "state."');
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
return { ok: errors.length === 0, errors };
|
|
3715
|
+
}
|
|
3716
|
+
var CardCompute = {
|
|
3717
|
+
run,
|
|
3718
|
+
eval: evalExpr,
|
|
3719
|
+
resolve,
|
|
3720
|
+
validate: validateNode,
|
|
3721
|
+
registerFunction,
|
|
3722
|
+
get functions() {
|
|
3723
|
+
const all = {};
|
|
3724
|
+
for (const k of Object.keys(_fns)) all[k] = _fns[k];
|
|
3725
|
+
for (const k of Object.keys(_customFns)) all[k] = _customFns[k];
|
|
3726
|
+
return all;
|
|
3727
|
+
}
|
|
3728
|
+
};
|
|
3729
|
+
|
|
3730
|
+
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
3731
|
//# sourceMappingURL=index.js.map
|
|
3285
3732
|
//# sourceMappingURL=index.js.map
|