yaml-flow 2.4.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/README.md +212 -0
- package/browser/card-compute.js +446 -0
- package/browser/live-cards.js +1381 -0
- package/browser/live-cards.schema.json +246 -0
- package/dist/card-compute/index.cjs +324 -0
- package/dist/card-compute/index.cjs.map +1 -0
- package/dist/card-compute/index.d.cts +68 -0
- package/dist/card-compute/index.d.ts +68 -0
- package/dist/card-compute/index.js +319 -0
- package/dist/card-compute/index.js.map +1 -0
- package/dist/{constants-DcCDDQON.d.ts → constants-BEbO2_OK.d.ts} +1 -1
- package/dist/{constants-Dbk6ArN5.d.cts → constants-BNjeIlZ8.d.cts} +1 -1
- package/dist/continuous-event-graph/index.d.cts +5 -135
- package/dist/continuous-event-graph/index.d.ts +5 -135
- package/dist/event-graph/index.d.cts +3 -3
- package/dist/event-graph/index.d.ts +3 -3
- package/dist/index.cjs +579 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +573 -5
- package/dist/index.js.map +1 -1
- package/dist/inference/index.cjs +450 -0
- package/dist/inference/index.cjs.map +1 -0
- package/dist/inference/index.d.cts +229 -0
- package/dist/inference/index.d.ts +229 -0
- package/dist/inference/index.js +443 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/types-C2lOwquM.d.cts +135 -0
- package/dist/{types-CTu8RqY0.d.cts → types-DAI_a2as.d.cts} +11 -0
- package/dist/{types-CTu8RqY0.d.ts → types-DAI_a2as.d.ts} +11 -0
- package/dist/types-mS_pPftm.d.ts +135 -0
- package/package.json +13 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var child_process = require('child_process');
|
|
4
|
+
|
|
3
5
|
// src/step-machine/reducer.ts
|
|
4
6
|
function applyStepResult(flow, state, stepName, stepResult) {
|
|
5
7
|
const stepConfig = flow.steps[stepName];
|
|
@@ -253,7 +255,7 @@ var StepMachine = class {
|
|
|
253
255
|
}
|
|
254
256
|
}
|
|
255
257
|
sleep(ms) {
|
|
256
|
-
return new Promise((
|
|
258
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
257
259
|
}
|
|
258
260
|
async run(initialData) {
|
|
259
261
|
const runId = generateRunId();
|
|
@@ -2155,7 +2157,7 @@ async function batch(items, options) {
|
|
|
2155
2157
|
if (total === 0) {
|
|
2156
2158
|
return { items: [], completed: 0, failed: 0, total: 0, durationMs: 0 };
|
|
2157
2159
|
}
|
|
2158
|
-
return new Promise((
|
|
2160
|
+
return new Promise((resolve2) => {
|
|
2159
2161
|
let active = 0;
|
|
2160
2162
|
function tryStartNext() {
|
|
2161
2163
|
while (active < concurrency && nextIndex < total) {
|
|
@@ -2172,7 +2174,7 @@ async function batch(items, options) {
|
|
|
2172
2174
|
failed++;
|
|
2173
2175
|
}
|
|
2174
2176
|
if (active === 0 && completed + failed === total) {
|
|
2175
|
-
|
|
2177
|
+
resolve2({
|
|
2176
2178
|
items: results,
|
|
2177
2179
|
completed,
|
|
2178
2180
|
failed,
|
|
@@ -2211,7 +2213,7 @@ async function batch(items, options) {
|
|
|
2211
2213
|
active--;
|
|
2212
2214
|
onProgress?.(makeProgress(active));
|
|
2213
2215
|
if (completed + failed === total) {
|
|
2214
|
-
|
|
2216
|
+
resolve2({
|
|
2215
2217
|
items: results,
|
|
2216
2218
|
completed,
|
|
2217
2219
|
failed,
|
|
@@ -3029,8 +3031,575 @@ function getDownstream(live, nodeName) {
|
|
|
3029
3031
|
return { nodeName, nodes, tokens: [...tokenSet] };
|
|
3030
3032
|
}
|
|
3031
3033
|
|
|
3034
|
+
// src/inference/core.ts
|
|
3035
|
+
var DEFAULT_THRESHOLD = 0.5;
|
|
3036
|
+
var DEFAULT_SYSTEM_PROMPT = `You are a workflow completion analyzer. Given a graph of tasks with their current states, evidence, and inference hints, determine which tasks appear to be completed based on the available evidence.
|
|
3037
|
+
|
|
3038
|
+
For each task you analyze, provide a JSON response. Be conservative \u2014 only mark tasks as completed when the evidence strongly supports it.`;
|
|
3039
|
+
function buildInferencePrompt(live, options = {}) {
|
|
3040
|
+
const { scope, context, systemPrompt } = options;
|
|
3041
|
+
const graphTasks = getAllTasks(live.config);
|
|
3042
|
+
const { state } = live;
|
|
3043
|
+
const candidates = getAnalyzableCandidates(live, scope);
|
|
3044
|
+
if (candidates.length === 0) {
|
|
3045
|
+
return "";
|
|
3046
|
+
}
|
|
3047
|
+
const lines = [];
|
|
3048
|
+
lines.push(systemPrompt || DEFAULT_SYSTEM_PROMPT);
|
|
3049
|
+
lines.push("");
|
|
3050
|
+
lines.push("## Graph State");
|
|
3051
|
+
lines.push("");
|
|
3052
|
+
lines.push(`Available tokens: ${state.availableOutputs.length > 0 ? state.availableOutputs.join(", ") : "(none)"}`);
|
|
3053
|
+
lines.push("");
|
|
3054
|
+
const completedTasks = Object.entries(state.tasks).filter(([_, ts]) => ts.status === "completed").map(([name]) => name);
|
|
3055
|
+
if (completedTasks.length > 0) {
|
|
3056
|
+
lines.push(`Completed tasks: ${completedTasks.join(", ")}`);
|
|
3057
|
+
lines.push("");
|
|
3058
|
+
}
|
|
3059
|
+
lines.push("## Tasks to Analyze");
|
|
3060
|
+
lines.push("");
|
|
3061
|
+
for (const taskName of candidates) {
|
|
3062
|
+
const taskConfig = graphTasks[taskName];
|
|
3063
|
+
const taskState = state.tasks[taskName];
|
|
3064
|
+
lines.push(`### ${taskName}`);
|
|
3065
|
+
if (taskConfig.description) {
|
|
3066
|
+
lines.push(`Description: ${taskConfig.description}`);
|
|
3067
|
+
}
|
|
3068
|
+
const requires = getRequires(taskConfig);
|
|
3069
|
+
const provides = getProvides(taskConfig);
|
|
3070
|
+
if (requires.length > 0) lines.push(`Requires: ${requires.join(", ")}`);
|
|
3071
|
+
if (provides.length > 0) lines.push(`Provides: ${provides.join(", ")}`);
|
|
3072
|
+
lines.push(`Current status: ${taskState?.status || "not-started"}`);
|
|
3073
|
+
const hints = taskConfig.inference;
|
|
3074
|
+
if (hints) {
|
|
3075
|
+
if (hints.criteria) lines.push(`Completion criteria: ${hints.criteria}`);
|
|
3076
|
+
if (hints.keywords?.length) lines.push(`Keywords: ${hints.keywords.join(", ")}`);
|
|
3077
|
+
if (hints.suggestedChecks?.length) lines.push(`Suggested checks: ${hints.suggestedChecks.join("; ")}`);
|
|
3078
|
+
}
|
|
3079
|
+
lines.push("");
|
|
3080
|
+
}
|
|
3081
|
+
if (context) {
|
|
3082
|
+
lines.push("## Additional Context / Evidence");
|
|
3083
|
+
lines.push("");
|
|
3084
|
+
lines.push(context);
|
|
3085
|
+
lines.push("");
|
|
3086
|
+
}
|
|
3087
|
+
lines.push("## Response Format");
|
|
3088
|
+
lines.push("");
|
|
3089
|
+
lines.push("Respond with a JSON array of objects, one per task you have evidence for:");
|
|
3090
|
+
lines.push("```json");
|
|
3091
|
+
lines.push("[");
|
|
3092
|
+
lines.push(" {");
|
|
3093
|
+
lines.push(' "taskName": "task-name",');
|
|
3094
|
+
lines.push(' "confidence": 0.0 to 1.0,');
|
|
3095
|
+
lines.push(' "reasoning": "explanation of why you believe this task is complete or not"');
|
|
3096
|
+
lines.push(" }");
|
|
3097
|
+
lines.push("]");
|
|
3098
|
+
lines.push("```");
|
|
3099
|
+
lines.push("");
|
|
3100
|
+
lines.push("Rules:");
|
|
3101
|
+
lines.push('- Only include tasks from the "Tasks to Analyze" section');
|
|
3102
|
+
lines.push("- confidence 0.0 = no evidence of completion, 1.0 = certain it is complete");
|
|
3103
|
+
lines.push("- If you have no evidence for a task, omit it from the array");
|
|
3104
|
+
lines.push("- Be conservative \u2014 require clear evidence before high confidence");
|
|
3105
|
+
lines.push("- Respond ONLY with the JSON array, no additional text");
|
|
3106
|
+
return lines.join("\n");
|
|
3107
|
+
}
|
|
3108
|
+
async function inferCompletions(live, adapter, options = {}) {
|
|
3109
|
+
options.threshold ?? DEFAULT_THRESHOLD;
|
|
3110
|
+
const analyzedNodes = getAnalyzableCandidates(live, options.scope);
|
|
3111
|
+
if (analyzedNodes.length === 0) {
|
|
3112
|
+
return { suggestions: [], promptUsed: "", rawResponse: "", analyzedNodes: [] };
|
|
3113
|
+
}
|
|
3114
|
+
const prompt = buildInferencePrompt(live, options);
|
|
3115
|
+
const rawResponse = await adapter.analyze(prompt);
|
|
3116
|
+
const suggestions = parseInferenceResponse(rawResponse, analyzedNodes);
|
|
3117
|
+
return {
|
|
3118
|
+
suggestions,
|
|
3119
|
+
promptUsed: prompt,
|
|
3120
|
+
rawResponse,
|
|
3121
|
+
analyzedNodes
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
function applyInferences(live, result, threshold = DEFAULT_THRESHOLD) {
|
|
3125
|
+
let current = live;
|
|
3126
|
+
for (const suggestion of result.suggestions) {
|
|
3127
|
+
if (suggestion.confidence < threshold) continue;
|
|
3128
|
+
const taskState = current.state.tasks[suggestion.taskName];
|
|
3129
|
+
if (!taskState) continue;
|
|
3130
|
+
if (taskState.status === "completed" || taskState.status === "running") continue;
|
|
3131
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3132
|
+
current = applyEvent(current, {
|
|
3133
|
+
type: "task-started",
|
|
3134
|
+
taskName: suggestion.taskName,
|
|
3135
|
+
timestamp: now
|
|
3136
|
+
});
|
|
3137
|
+
current = applyEvent(current, {
|
|
3138
|
+
type: "task-completed",
|
|
3139
|
+
taskName: suggestion.taskName,
|
|
3140
|
+
timestamp: now,
|
|
3141
|
+
result: "llm-inferred"
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3144
|
+
return current;
|
|
3145
|
+
}
|
|
3146
|
+
async function inferAndApply(live, adapter, options = {}) {
|
|
3147
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
3148
|
+
const inference = await inferCompletions(live, adapter, options);
|
|
3149
|
+
const updated = applyInferences(live, inference, threshold);
|
|
3150
|
+
const applied = inference.suggestions.filter((s) => s.confidence >= threshold);
|
|
3151
|
+
const skipped = inference.suggestions.filter((s) => s.confidence < threshold);
|
|
3152
|
+
return {
|
|
3153
|
+
live: updated,
|
|
3154
|
+
inference,
|
|
3155
|
+
applied,
|
|
3156
|
+
skipped
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
function getAnalyzableCandidates(live, scope) {
|
|
3160
|
+
const graphTasks = getAllTasks(live.config);
|
|
3161
|
+
const { state } = live;
|
|
3162
|
+
const candidates = [];
|
|
3163
|
+
for (const [name, config] of Object.entries(graphTasks)) {
|
|
3164
|
+
const taskState = state.tasks[name];
|
|
3165
|
+
if (taskState?.status === "completed" || taskState?.status === "running") continue;
|
|
3166
|
+
if (scope) {
|
|
3167
|
+
if (scope.includes(name)) candidates.push(name);
|
|
3168
|
+
} else {
|
|
3169
|
+
if (config.inference?.autoDetectable) candidates.push(name);
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
return candidates;
|
|
3173
|
+
}
|
|
3174
|
+
function parseInferenceResponse(rawResponse, validNodes, _threshold) {
|
|
3175
|
+
const validSet = new Set(validNodes);
|
|
3176
|
+
try {
|
|
3177
|
+
const jsonStr = extractJson(rawResponse);
|
|
3178
|
+
if (!jsonStr) return [];
|
|
3179
|
+
const parsed = JSON.parse(jsonStr);
|
|
3180
|
+
if (!Array.isArray(parsed)) return [];
|
|
3181
|
+
const suggestions = [];
|
|
3182
|
+
for (const item of parsed) {
|
|
3183
|
+
if (!item || typeof item !== "object") continue;
|
|
3184
|
+
if (typeof item.taskName !== "string") continue;
|
|
3185
|
+
if (typeof item.confidence !== "number") continue;
|
|
3186
|
+
if (!validSet.has(item.taskName)) continue;
|
|
3187
|
+
const confidence = Math.max(0, Math.min(1, item.confidence));
|
|
3188
|
+
suggestions.push({
|
|
3189
|
+
taskName: item.taskName,
|
|
3190
|
+
confidence,
|
|
3191
|
+
reasoning: typeof item.reasoning === "string" ? item.reasoning : "",
|
|
3192
|
+
detectionMethod: "llm-inferred"
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
return suggestions;
|
|
3196
|
+
} catch {
|
|
3197
|
+
return [];
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
function extractJson(text) {
|
|
3201
|
+
if (!text || typeof text !== "string") return null;
|
|
3202
|
+
const trimmed = text.trim();
|
|
3203
|
+
const fenceMatch = trimmed.match(/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/);
|
|
3204
|
+
if (fenceMatch) return fenceMatch[1].trim();
|
|
3205
|
+
const firstBracket = trimmed.indexOf("[");
|
|
3206
|
+
const lastBracket = trimmed.lastIndexOf("]");
|
|
3207
|
+
if (firstBracket !== -1 && lastBracket > firstBracket) {
|
|
3208
|
+
return trimmed.slice(firstBracket, lastBracket + 1);
|
|
3209
|
+
}
|
|
3210
|
+
if (trimmed.startsWith("[")) return trimmed;
|
|
3211
|
+
return null;
|
|
3212
|
+
}
|
|
3213
|
+
function createCliAdapter(opts) {
|
|
3214
|
+
const timeout = opts.timeout ?? 6e4;
|
|
3215
|
+
return {
|
|
3216
|
+
analyze: (prompt) => {
|
|
3217
|
+
return new Promise((resolve2, reject) => {
|
|
3218
|
+
const args = opts.args(prompt);
|
|
3219
|
+
const child = child_process.execFile(
|
|
3220
|
+
opts.command,
|
|
3221
|
+
opts.stdin ? opts.args("") : args,
|
|
3222
|
+
{
|
|
3223
|
+
timeout,
|
|
3224
|
+
cwd: opts.cwd,
|
|
3225
|
+
env: opts.env ? { ...process.env, ...opts.env } : void 0,
|
|
3226
|
+
maxBuffer: 10 * 1024 * 1024
|
|
3227
|
+
// 10MB
|
|
3228
|
+
},
|
|
3229
|
+
(error, stdout, stderr) => {
|
|
3230
|
+
if (error) {
|
|
3231
|
+
reject(new Error(
|
|
3232
|
+
`CLI adapter failed: ${opts.command} exited with ${error.code ?? "error"}` + (stderr ? `
|
|
3233
|
+
stderr: ${stderr.slice(0, 500)}` : "") + `
|
|
3234
|
+
${error.message}`
|
|
3235
|
+
));
|
|
3236
|
+
} else {
|
|
3237
|
+
resolve2(stdout);
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
);
|
|
3241
|
+
if (opts.stdin && child.stdin) {
|
|
3242
|
+
child.stdin.write(prompt);
|
|
3243
|
+
child.stdin.end();
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
}
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
function createHttpAdapter(opts) {
|
|
3250
|
+
const timeout = opts.timeout ?? 6e4;
|
|
3251
|
+
return {
|
|
3252
|
+
analyze: async (prompt) => {
|
|
3253
|
+
const body = opts.buildBody ? opts.buildBody(prompt) : { prompt };
|
|
3254
|
+
const controller = new AbortController();
|
|
3255
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
3256
|
+
try {
|
|
3257
|
+
const response = await fetch(opts.url, {
|
|
3258
|
+
method: "POST",
|
|
3259
|
+
headers: {
|
|
3260
|
+
"Content-Type": "application/json",
|
|
3261
|
+
...opts.headers ?? {}
|
|
3262
|
+
},
|
|
3263
|
+
body: JSON.stringify(body),
|
|
3264
|
+
signal: controller.signal
|
|
3265
|
+
});
|
|
3266
|
+
if (!response.ok) {
|
|
3267
|
+
const text = await response.text().catch(() => "");
|
|
3268
|
+
throw new Error(`HTTP ${response.status}: ${text.slice(0, 500)}`);
|
|
3269
|
+
}
|
|
3270
|
+
const json = await response.json();
|
|
3271
|
+
if (opts.extractResponse) {
|
|
3272
|
+
return opts.extractResponse(json);
|
|
3273
|
+
}
|
|
3274
|
+
if (typeof json.response === "string") return json.response;
|
|
3275
|
+
if (typeof json.text === "string") return json.text;
|
|
3276
|
+
if (typeof json.content === "string") return json.content;
|
|
3277
|
+
return JSON.stringify(json);
|
|
3278
|
+
} finally {
|
|
3279
|
+
clearTimeout(timer);
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
// src/card-compute/index.ts
|
|
3286
|
+
function deepGet(obj, path) {
|
|
3287
|
+
if (!path || !obj) return void 0;
|
|
3288
|
+
const parts = path.split(".");
|
|
3289
|
+
let cur = obj;
|
|
3290
|
+
for (let i = 0; i < parts.length; i++) {
|
|
3291
|
+
if (cur == null) return void 0;
|
|
3292
|
+
cur = cur[parts[i]];
|
|
3293
|
+
}
|
|
3294
|
+
return cur;
|
|
3295
|
+
}
|
|
3296
|
+
function deepSet(obj, path, value) {
|
|
3297
|
+
const parts = path.split(".");
|
|
3298
|
+
let cur = obj;
|
|
3299
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
3300
|
+
if (cur[parts[i]] == null || typeof cur[parts[i]] !== "object") cur[parts[i]] = {};
|
|
3301
|
+
cur = cur[parts[i]];
|
|
3302
|
+
}
|
|
3303
|
+
cur[parts[parts.length - 1]] = value;
|
|
3304
|
+
}
|
|
3305
|
+
var _fns = {};
|
|
3306
|
+
_fns.sum = (input, _e, opts) => {
|
|
3307
|
+
const a = Array.isArray(input) ? input : [];
|
|
3308
|
+
return opts.field ? a.reduce((s, r) => s + (Number(r[opts.field]) || 0), 0) : a.reduce((s, v) => s + (Number(v) || 0), 0);
|
|
3309
|
+
};
|
|
3310
|
+
_fns.avg = (input, _e, opts) => {
|
|
3311
|
+
const s = _fns.sum(input, _e, opts);
|
|
3312
|
+
const n = Array.isArray(input) ? input.length : 1;
|
|
3313
|
+
return n ? s / n : 0;
|
|
3314
|
+
};
|
|
3315
|
+
_fns.min = (input, _e, opts) => {
|
|
3316
|
+
const a = Array.isArray(input) ? input : [];
|
|
3317
|
+
const vals = opts.field ? a.map((r) => Number(r[opts.field])) : a.map(Number);
|
|
3318
|
+
return vals.length ? Math.min(...vals) : 0;
|
|
3319
|
+
};
|
|
3320
|
+
_fns.max = (input, _e, opts) => {
|
|
3321
|
+
const a = Array.isArray(input) ? input : [];
|
|
3322
|
+
const vals = opts.field ? a.map((r) => Number(r[opts.field])) : a.map(Number);
|
|
3323
|
+
return vals.length ? Math.max(...vals) : 0;
|
|
3324
|
+
};
|
|
3325
|
+
_fns.count = (input) => Array.isArray(input) ? input.length : input != null ? 1 : 0;
|
|
3326
|
+
_fns.first = (input) => Array.isArray(input) ? input[0] : input;
|
|
3327
|
+
_fns.last = (input) => Array.isArray(input) ? input[input.length - 1] : input;
|
|
3328
|
+
_fns.add = (input) => {
|
|
3329
|
+
const a = Array.isArray(input) ? input : [];
|
|
3330
|
+
return a.reduce((s, v) => s + Number(v), 0);
|
|
3331
|
+
};
|
|
3332
|
+
_fns.sub = (input) => {
|
|
3333
|
+
const a = Array.isArray(input) ? input : [];
|
|
3334
|
+
return a.length >= 2 ? Number(a[0]) - Number(a[1]) : 0;
|
|
3335
|
+
};
|
|
3336
|
+
_fns.mul = (input) => {
|
|
3337
|
+
const a = Array.isArray(input) ? input : [];
|
|
3338
|
+
return a.reduce((s, v) => s * Number(v), 1);
|
|
3339
|
+
};
|
|
3340
|
+
_fns.div = (input) => {
|
|
3341
|
+
const a = Array.isArray(input) ? input : [];
|
|
3342
|
+
return a.length >= 2 && Number(a[1]) !== 0 ? Number(a[0]) / Number(a[1]) : 0;
|
|
3343
|
+
};
|
|
3344
|
+
_fns.round = (input, _e, opts) => {
|
|
3345
|
+
const decimals = opts.decimals != null ? opts.decimals : 0;
|
|
3346
|
+
const factor = Math.pow(10, decimals);
|
|
3347
|
+
return Math.round(Number(input) * factor) / factor;
|
|
3348
|
+
};
|
|
3349
|
+
_fns.abs = (input) => Math.abs(Number(input));
|
|
3350
|
+
_fns.mod = (input) => {
|
|
3351
|
+
const a = Array.isArray(input) ? input : [];
|
|
3352
|
+
return a.length >= 2 ? Number(a[0]) % Number(a[1]) : 0;
|
|
3353
|
+
};
|
|
3354
|
+
_fns.gt = (input) => {
|
|
3355
|
+
const a = Array.isArray(input) ? input : [];
|
|
3356
|
+
return a.length >= 2 && Number(a[0]) > Number(a[1]);
|
|
3357
|
+
};
|
|
3358
|
+
_fns.gte = (input) => {
|
|
3359
|
+
const a = Array.isArray(input) ? input : [];
|
|
3360
|
+
return a.length >= 2 && Number(a[0]) >= Number(a[1]);
|
|
3361
|
+
};
|
|
3362
|
+
_fns.lt = (input) => {
|
|
3363
|
+
const a = Array.isArray(input) ? input : [];
|
|
3364
|
+
return a.length >= 2 && Number(a[0]) < Number(a[1]);
|
|
3365
|
+
};
|
|
3366
|
+
_fns.lte = (input) => {
|
|
3367
|
+
const a = Array.isArray(input) ? input : [];
|
|
3368
|
+
return a.length >= 2 && Number(a[0]) <= Number(a[1]);
|
|
3369
|
+
};
|
|
3370
|
+
_fns.eq = (input) => {
|
|
3371
|
+
const a = Array.isArray(input) ? input : [];
|
|
3372
|
+
return a.length >= 2 && a[0] === a[1];
|
|
3373
|
+
};
|
|
3374
|
+
_fns.neq = (input) => {
|
|
3375
|
+
const a = Array.isArray(input) ? input : [];
|
|
3376
|
+
return a.length >= 2 && a[0] !== a[1];
|
|
3377
|
+
};
|
|
3378
|
+
_fns.and = (input) => {
|
|
3379
|
+
const a = Array.isArray(input) ? input : [];
|
|
3380
|
+
return a.every(Boolean);
|
|
3381
|
+
};
|
|
3382
|
+
_fns.or = (input) => {
|
|
3383
|
+
const a = Array.isArray(input) ? input : [];
|
|
3384
|
+
return a.some(Boolean);
|
|
3385
|
+
};
|
|
3386
|
+
_fns.not = (input) => !input;
|
|
3387
|
+
_fns.concat = (input) => {
|
|
3388
|
+
const a = Array.isArray(input) ? input : [];
|
|
3389
|
+
return a.map((v) => v != null ? String(v) : "").join("");
|
|
3390
|
+
};
|
|
3391
|
+
_fns.upper = (input) => String(input || "").toUpperCase();
|
|
3392
|
+
_fns.lower = (input) => String(input || "").toLowerCase();
|
|
3393
|
+
_fns.template = (input, _e, opts) => {
|
|
3394
|
+
let t = String(opts.format || "");
|
|
3395
|
+
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
3396
|
+
for (const k of Object.keys(input)) {
|
|
3397
|
+
const v = input[k];
|
|
3398
|
+
t = t.split("{{" + k + "}}").join(v != null ? String(v) : "");
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
return t;
|
|
3402
|
+
};
|
|
3403
|
+
_fns.join = (input, _e, opts) => {
|
|
3404
|
+
const a = Array.isArray(input) ? input : [];
|
|
3405
|
+
const sep = opts.separator != null ? String(opts.separator) : ", ";
|
|
3406
|
+
return a.map((v) => v != null ? String(v) : "").join(sep);
|
|
3407
|
+
};
|
|
3408
|
+
_fns.split = (input, _e, opts) => {
|
|
3409
|
+
const sep = opts.separator != null ? String(opts.separator) : ",";
|
|
3410
|
+
return String(input || "").split(sep).map((s) => s.trim());
|
|
3411
|
+
};
|
|
3412
|
+
_fns.trim = (input) => String(input || "").trim();
|
|
3413
|
+
_fns.pluck = (input, _e, opts) => Array.isArray(input) ? input.map((r) => r[opts.field]) : [];
|
|
3414
|
+
_fns.filter = (input, _e, opts) => {
|
|
3415
|
+
if (!Array.isArray(input)) return [];
|
|
3416
|
+
if (opts.field) return input.filter((r) => !!r[opts.field]);
|
|
3417
|
+
return input.filter(Boolean);
|
|
3418
|
+
};
|
|
3419
|
+
_fns.map = (input) => Array.isArray(input) ? input.slice() : [];
|
|
3420
|
+
_fns.sort = (input, _e, opts) => {
|
|
3421
|
+
const a = Array.isArray(input) ? input.slice() : [];
|
|
3422
|
+
const f = opts.field;
|
|
3423
|
+
const dir = opts.direction === "desc" ? -1 : 1;
|
|
3424
|
+
if (f) return a.sort((x, y) => x[f] > y[f] ? dir : x[f] < y[f] ? -dir : 0);
|
|
3425
|
+
return a.sort((x, y) => x > y ? dir : x < y ? -dir : 0);
|
|
3426
|
+
};
|
|
3427
|
+
_fns.slice = (input, _e, opts) => Array.isArray(input) ? input.slice(opts.start || 0, opts.end) : input;
|
|
3428
|
+
_fns.flat = (input, _e, opts) => {
|
|
3429
|
+
const depth = opts.depth != null ? opts.depth : 1;
|
|
3430
|
+
return Array.isArray(input) ? input.flat(depth) : [input];
|
|
3431
|
+
};
|
|
3432
|
+
_fns.unique = (input) => {
|
|
3433
|
+
if (!Array.isArray(input)) return [input];
|
|
3434
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3435
|
+
return input.filter((v) => {
|
|
3436
|
+
const key = typeof v === "object" ? JSON.stringify(v) : v;
|
|
3437
|
+
if (seen.has(key)) return false;
|
|
3438
|
+
seen.add(key);
|
|
3439
|
+
return true;
|
|
3440
|
+
});
|
|
3441
|
+
};
|
|
3442
|
+
_fns.group = (input, _e, opts) => {
|
|
3443
|
+
const a = Array.isArray(input) ? input : [];
|
|
3444
|
+
const g = {};
|
|
3445
|
+
a.forEach((r) => {
|
|
3446
|
+
const k = String(r[opts.field] || "");
|
|
3447
|
+
if (!g[k]) g[k] = [];
|
|
3448
|
+
g[k].push(r);
|
|
3449
|
+
});
|
|
3450
|
+
return g;
|
|
3451
|
+
};
|
|
3452
|
+
_fns.flatten_keys = (input) => {
|
|
3453
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return [];
|
|
3454
|
+
const result = [];
|
|
3455
|
+
for (const k of Object.keys(input)) {
|
|
3456
|
+
const vals = Array.isArray(input[k]) ? input[k] : [input[k]];
|
|
3457
|
+
vals.forEach((v) => result.push({ key: k, value: v }));
|
|
3458
|
+
}
|
|
3459
|
+
return result;
|
|
3460
|
+
};
|
|
3461
|
+
_fns.entries = (input) => {
|
|
3462
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return [];
|
|
3463
|
+
return Object.keys(input).map((k) => ({ key: k, value: input[k] }));
|
|
3464
|
+
};
|
|
3465
|
+
_fns.from_entries = (input) => {
|
|
3466
|
+
if (!Array.isArray(input)) return {};
|
|
3467
|
+
const obj = {};
|
|
3468
|
+
input.forEach((item) => {
|
|
3469
|
+
if (item.key != null) obj[item.key] = item.value;
|
|
3470
|
+
});
|
|
3471
|
+
return obj;
|
|
3472
|
+
};
|
|
3473
|
+
_fns.length = (input) => {
|
|
3474
|
+
if (Array.isArray(input)) return input.length;
|
|
3475
|
+
if (typeof input === "string") return input.length;
|
|
3476
|
+
if (input && typeof input === "object") return Object.keys(input).length;
|
|
3477
|
+
return 0;
|
|
3478
|
+
};
|
|
3479
|
+
_fns.get = (input, _e, opts) => deepGet(input, opts.field || opts.path || "");
|
|
3480
|
+
_fns.default = (input, _e, opts) => input != null ? input : opts.value;
|
|
3481
|
+
_fns.coalesce = (input) => {
|
|
3482
|
+
const a = Array.isArray(input) ? input : [];
|
|
3483
|
+
for (let i = 0; i < a.length; i++) {
|
|
3484
|
+
if (a[i] != null) return a[i];
|
|
3485
|
+
}
|
|
3486
|
+
return null;
|
|
3487
|
+
};
|
|
3488
|
+
_fns.now = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
3489
|
+
_fns.diff_days = (input) => {
|
|
3490
|
+
const a = Array.isArray(input) ? input : [];
|
|
3491
|
+
return a.length >= 2 ? Math.floor((new Date(a[0]).getTime() - new Date(a[1]).getTime()) / 864e5) : 0;
|
|
3492
|
+
};
|
|
3493
|
+
_fns.format_date = (input, _e, opts) => {
|
|
3494
|
+
try {
|
|
3495
|
+
const d = new Date(input);
|
|
3496
|
+
if (opts.format === "iso") return d.toISOString();
|
|
3497
|
+
if (opts.format === "date") return d.toLocaleDateString();
|
|
3498
|
+
if (opts.format === "time") return d.toLocaleTimeString();
|
|
3499
|
+
return d.toLocaleDateString();
|
|
3500
|
+
} catch {
|
|
3501
|
+
return String(input);
|
|
3502
|
+
}
|
|
3503
|
+
};
|
|
3504
|
+
_fns.parse_date = (input) => {
|
|
3505
|
+
try {
|
|
3506
|
+
return new Date(input).toISOString();
|
|
3507
|
+
} catch {
|
|
3508
|
+
return null;
|
|
3509
|
+
}
|
|
3510
|
+
};
|
|
3511
|
+
_fns.to_number = (input) => Number(input) || 0;
|
|
3512
|
+
_fns.to_string = (input) => input != null ? String(input) : "";
|
|
3513
|
+
_fns.to_bool = (input) => !!input;
|
|
3514
|
+
_fns.type_of = (input) => Array.isArray(input) ? "array" : typeof input;
|
|
3515
|
+
_fns.is_null = (input) => input == null;
|
|
3516
|
+
_fns.is_empty = (input) => {
|
|
3517
|
+
if (input == null) return true;
|
|
3518
|
+
if (Array.isArray(input)) return input.length === 0;
|
|
3519
|
+
if (typeof input === "string") return input.length === 0;
|
|
3520
|
+
if (typeof input === "object") return Object.keys(input).length === 0;
|
|
3521
|
+
return false;
|
|
3522
|
+
};
|
|
3523
|
+
var _customFns = {};
|
|
3524
|
+
function evalExpr(expr, node) {
|
|
3525
|
+
if (expr == null) return expr;
|
|
3526
|
+
if (typeof expr !== "object" || Array.isArray(expr)) return expr;
|
|
3527
|
+
const e = expr;
|
|
3528
|
+
if (!e.fn) return expr;
|
|
3529
|
+
let input = e.input;
|
|
3530
|
+
if (typeof input === "string" && input.startsWith("state.")) {
|
|
3531
|
+
input = deepGet(node, input);
|
|
3532
|
+
} else if (Array.isArray(input)) {
|
|
3533
|
+
input = input.map((v) => {
|
|
3534
|
+
if (typeof v === "string" && v.startsWith("state.")) return deepGet(node, v);
|
|
3535
|
+
if (v && typeof v === "object" && v.fn) return evalExpr(v, node);
|
|
3536
|
+
return v;
|
|
3537
|
+
});
|
|
3538
|
+
} else if (input && typeof input === "object" && input.fn) {
|
|
3539
|
+
input = evalExpr(input, node);
|
|
3540
|
+
}
|
|
3541
|
+
if (e.fn === "if") {
|
|
3542
|
+
const cond = evalExpr(e.cond, node);
|
|
3543
|
+
if (cond) {
|
|
3544
|
+
return e.then && typeof e.then === "object" && e.then.fn ? evalExpr(e.then, node) : e.then;
|
|
3545
|
+
} else {
|
|
3546
|
+
return e.else && typeof e.else === "object" && e.else.fn ? evalExpr(e.else, node) : e.else;
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
if (e.fn === "filter" && Array.isArray(input) && e.where) {
|
|
3550
|
+
return input.filter((item) => {
|
|
3551
|
+
const tmp = { state: { ...node.state, $: item } };
|
|
3552
|
+
return evalExpr(e.where, tmp);
|
|
3553
|
+
});
|
|
3554
|
+
}
|
|
3555
|
+
if (e.fn === "map" && Array.isArray(input) && e.apply) {
|
|
3556
|
+
return input.map((item) => {
|
|
3557
|
+
const tmp = { state: { ...node.state, $: item } };
|
|
3558
|
+
return evalExpr(e.apply, tmp);
|
|
3559
|
+
});
|
|
3560
|
+
}
|
|
3561
|
+
const fn = _customFns[e.fn] || _fns[e.fn];
|
|
3562
|
+
if (!fn) {
|
|
3563
|
+
console.warn('CardCompute: unknown function "' + e.fn + '"');
|
|
3564
|
+
return void 0;
|
|
3565
|
+
}
|
|
3566
|
+
return fn(input, evalExpr, e);
|
|
3567
|
+
}
|
|
3568
|
+
function run(node) {
|
|
3569
|
+
if (!node || !node.compute) return node;
|
|
3570
|
+
if (!node.state) node.state = {};
|
|
3571
|
+
for (const key of Object.keys(node.compute)) {
|
|
3572
|
+
try {
|
|
3573
|
+
const val = evalExpr(node.compute[key], node);
|
|
3574
|
+
deepSet(node.state, key, val);
|
|
3575
|
+
} catch (err) {
|
|
3576
|
+
console.error(`CardCompute.run error on "${node.id || "?"}.${key}":`, err);
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
return node;
|
|
3580
|
+
}
|
|
3581
|
+
function resolve(node, path) {
|
|
3582
|
+
return deepGet(node, path);
|
|
3583
|
+
}
|
|
3584
|
+
function registerFunction(name, fn) {
|
|
3585
|
+
_customFns[name] = fn;
|
|
3586
|
+
}
|
|
3587
|
+
var CardCompute = {
|
|
3588
|
+
run,
|
|
3589
|
+
eval: evalExpr,
|
|
3590
|
+
resolve,
|
|
3591
|
+
registerFunction,
|
|
3592
|
+
get functions() {
|
|
3593
|
+
const all = {};
|
|
3594
|
+
for (const k of Object.keys(_fns)) all[k] = _fns[k];
|
|
3595
|
+
for (const k of Object.keys(_customFns)) all[k] = _customFns[k];
|
|
3596
|
+
return all;
|
|
3597
|
+
}
|
|
3598
|
+
};
|
|
3599
|
+
|
|
3032
3600
|
exports.COMPLETION_STRATEGIES = COMPLETION_STRATEGIES;
|
|
3033
3601
|
exports.CONFLICT_STRATEGIES = CONFLICT_STRATEGIES;
|
|
3602
|
+
exports.CardCompute = CardCompute;
|
|
3034
3603
|
exports.DEFAULTS = DEFAULTS;
|
|
3035
3604
|
exports.EXECUTION_MODES = EXECUTION_MODES;
|
|
3036
3605
|
exports.EXECUTION_STATUS = EXECUTION_STATUS;
|
|
@@ -3047,13 +3616,17 @@ exports.addRequires = addRequires;
|
|
|
3047
3616
|
exports.apply = apply;
|
|
3048
3617
|
exports.applyAll = applyAll;
|
|
3049
3618
|
exports.applyEvent = applyEvent;
|
|
3619
|
+
exports.applyInferences = applyInferences;
|
|
3050
3620
|
exports.applyStepResult = applyStepResult;
|
|
3051
3621
|
exports.batch = batch;
|
|
3622
|
+
exports.buildInferencePrompt = buildInferencePrompt;
|
|
3052
3623
|
exports.checkCircuitBreaker = checkCircuitBreaker;
|
|
3053
3624
|
exports.computeAvailableOutputs = computeAvailableOutputs;
|
|
3054
3625
|
exports.computeStepInput = computeStepInput;
|
|
3626
|
+
exports.createCliAdapter = createCliAdapter;
|
|
3055
3627
|
exports.createDefaultTaskState = createDefaultTaskState;
|
|
3056
3628
|
exports.createEngine = createStepMachine;
|
|
3629
|
+
exports.createHttpAdapter = createHttpAdapter;
|
|
3057
3630
|
exports.createInitialExecutionState = createInitialExecutionState;
|
|
3058
3631
|
exports.createInitialState = createInitialState;
|
|
3059
3632
|
exports.createLiveGraph = createLiveGraph;
|
|
@@ -3078,6 +3651,8 @@ exports.getUnreachableTokens = getUnreachableTokens;
|
|
|
3078
3651
|
exports.getUpstream = getUpstream;
|
|
3079
3652
|
exports.graphToMermaid = graphToMermaid;
|
|
3080
3653
|
exports.hasTask = hasTask;
|
|
3654
|
+
exports.inferAndApply = inferAndApply;
|
|
3655
|
+
exports.inferCompletions = inferCompletions;
|
|
3081
3656
|
exports.injectTokens = injectTokens;
|
|
3082
3657
|
exports.inspect = inspect;
|
|
3083
3658
|
exports.isExecutionComplete = isExecutionComplete;
|