yaml-flow 2.6.0 → 2.7.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/browser/card-compute.js +100 -0
- package/dist/card-compute/index.cjs +132 -0
- package/dist/card-compute/index.cjs.map +1 -1
- package/dist/card-compute/index.d.cts +18 -1
- package/dist/card-compute/index.d.ts +18 -1
- package/dist/card-compute/index.js +132 -0
- package/dist/card-compute/index.js.map +1 -1
- package/dist/index.cjs +132 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/schema/live-cards.schema.json +246 -0
package/dist/index.d.cts
CHANGED
|
@@ -10,4 +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';
|
|
13
|
+
export { CardCompute, ComputeExpr, ComputeFn, ComputeNode, EvalFn, ValidationResult } from './card-compute/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +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';
|
|
13
|
+
export { CardCompute, ComputeExpr, ComputeFn, ComputeNode, EvalFn, ValidationResult } from './card-compute/index.js';
|
package/dist/index.js
CHANGED
|
@@ -3582,10 +3582,142 @@ function resolve(node, path) {
|
|
|
3582
3582
|
function registerFunction(name, fn) {
|
|
3583
3583
|
_customFns[name] = fn;
|
|
3584
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
|
+
}
|
|
3585
3716
|
var CardCompute = {
|
|
3586
3717
|
run,
|
|
3587
3718
|
eval: evalExpr,
|
|
3588
3719
|
resolve,
|
|
3720
|
+
validate: validateNode,
|
|
3589
3721
|
registerFunction,
|
|
3590
3722
|
get functions() {
|
|
3591
3723
|
const all = {};
|