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.d.cts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { StepMachine as FlowEngine, StepMachine, applyStepResult, checkCircuitBreaker, computeStepInput, createStepMachine as createEngine, createInitialState, createStepMachine, extractReturnData, loadStepFlow, validateStepFlowConfig } from './step-machine/index.cjs';
|
|
2
2
|
export { C as CircuitBreakerConfig, R as RetryConfig, S as StepConfig, a as StepContext, b as StepEvent, c as StepEventListener, d as StepEventType, e as StepFlowConfig, f as StepFlowSettings, g as StepHandler, h as StepInput, i as StepMachineOptions, j as StepMachineResult, k as StepMachineState, l as StepMachineStore, m as StepReducerResult, n as StepResult, T as TerminalStateConfig } from './types-FZ_eyErS.cjs';
|
|
3
|
-
export { C as COMPLETION_STRATEGIES, a as CONFLICT_STRATEGIES, b as CompletionResult, D as DEFAULTS, E as EXECUTION_MODES, c as EXECUTION_STATUS, d as ExecutionPlan, e as ExportOptions, G as GraphIssue, f as GraphValidationResult, I as IssueSeverity, M as MermaidOptions, T as TASK_STATUS, g as addDynamicTask, h as apply, i as applyAll, j as computeAvailableOutputs, k as createDefaultTaskState, l as createInitialExecutionState, m as detectStuckState, n as exportGraphConfig, o as exportGraphConfigToFile, p as flowToMermaid, q as getAllTasks, r as getCandidateTasks, s as getProvides, t as getRequires, u as getTask, v as graphToMermaid, w as hasTask, x as isExecutionComplete, y as isNonActiveTask, z as isRepeatableTask, A as isTaskCompleted, B as isTaskRunning, F as loadGraphConfig, H as next, J as planExecution, K as validateGraph, L as validateGraphConfig } from './constants-
|
|
4
|
-
export { A as AgentActionEvent, C as CompletionStrategy, a as ConflictStrategy, E as ExecutionConfig, b as ExecutionMode, c as ExecutionState, d as ExecutionStatus, G as GraphConfig, e as GraphEvent, f as GraphSettings, T as GraphTaskConfig, I as InjectTokensEvent, S as SchedulerResult, g as StuckDetection, h as TaskCompletedEvent, i as TaskCreationEvent, j as TaskFailedEvent, k as TaskStartedEvent, l as TaskState, m as TaskStatus } from './types-
|
|
3
|
+
export { C as COMPLETION_STRATEGIES, a as CONFLICT_STRATEGIES, b as CompletionResult, D as DEFAULTS, E as EXECUTION_MODES, c as EXECUTION_STATUS, d as ExecutionPlan, e as ExportOptions, G as GraphIssue, f as GraphValidationResult, I as IssueSeverity, M as MermaidOptions, T as TASK_STATUS, g as addDynamicTask, h as apply, i as applyAll, j as computeAvailableOutputs, k as createDefaultTaskState, l as createInitialExecutionState, m as detectStuckState, n as exportGraphConfig, o as exportGraphConfigToFile, p as flowToMermaid, q as getAllTasks, r as getCandidateTasks, s as getProvides, t as getRequires, u as getTask, v as graphToMermaid, w as hasTask, x as isExecutionComplete, y as isNonActiveTask, z as isRepeatableTask, A as isTaskCompleted, B as isTaskRunning, F as loadGraphConfig, H as next, J as planExecution, K as validateGraph, L as validateGraphConfig } from './constants-BNjeIlZ8.cjs';
|
|
4
|
+
export { A as AgentActionEvent, C as CompletionStrategy, a as ConflictStrategy, E as ExecutionConfig, b as ExecutionMode, c as ExecutionState, d as ExecutionStatus, G as GraphConfig, e as GraphEvent, f as GraphSettings, T as GraphTaskConfig, I as InjectTokensEvent, S as SchedulerResult, g as StuckDetection, h as TaskCompletedEvent, i as TaskCreationEvent, j as TaskFailedEvent, k as TaskStartedEvent, l as TaskState, m as TaskStatus } from './types-DAI_a2as.cjs';
|
|
5
5
|
export { MemoryStore } from './stores/memory.cjs';
|
|
6
6
|
export { LocalStorageStore } from './stores/localStorage.cjs';
|
|
7
7
|
export { FileStore } from './stores/file.cjs';
|
|
8
8
|
export { BatchItemResult, BatchOptions, BatchProgress, BatchResult, batch } from './batch/index.cjs';
|
|
9
9
|
export { ConfigTemplates, Variables, resolveConfigTemplates, resolveVariables } from './config/index.cjs';
|
|
10
|
-
export {
|
|
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
|
+
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
|
+
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
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { StepMachine as FlowEngine, StepMachine, applyStepResult, checkCircuitBreaker, computeStepInput, createStepMachine as createEngine, createInitialState, createStepMachine, extractReturnData, loadStepFlow, validateStepFlowConfig } from './step-machine/index.js';
|
|
2
2
|
export { C as CircuitBreakerConfig, R as RetryConfig, S as StepConfig, a as StepContext, b as StepEvent, c as StepEventListener, d as StepEventType, e as StepFlowConfig, f as StepFlowSettings, g as StepHandler, h as StepInput, i as StepMachineOptions, j as StepMachineResult, k as StepMachineState, l as StepMachineStore, m as StepReducerResult, n as StepResult, T as TerminalStateConfig } from './types-FZ_eyErS.js';
|
|
3
|
-
export { C as COMPLETION_STRATEGIES, a as CONFLICT_STRATEGIES, b as CompletionResult, D as DEFAULTS, E as EXECUTION_MODES, c as EXECUTION_STATUS, d as ExecutionPlan, e as ExportOptions, G as GraphIssue, f as GraphValidationResult, I as IssueSeverity, M as MermaidOptions, T as TASK_STATUS, g as addDynamicTask, h as apply, i as applyAll, j as computeAvailableOutputs, k as createDefaultTaskState, l as createInitialExecutionState, m as detectStuckState, n as exportGraphConfig, o as exportGraphConfigToFile, p as flowToMermaid, q as getAllTasks, r as getCandidateTasks, s as getProvides, t as getRequires, u as getTask, v as graphToMermaid, w as hasTask, x as isExecutionComplete, y as isNonActiveTask, z as isRepeatableTask, A as isTaskCompleted, B as isTaskRunning, F as loadGraphConfig, H as next, J as planExecution, K as validateGraph, L as validateGraphConfig } from './constants-
|
|
4
|
-
export { A as AgentActionEvent, C as CompletionStrategy, a as ConflictStrategy, E as ExecutionConfig, b as ExecutionMode, c as ExecutionState, d as ExecutionStatus, G as GraphConfig, e as GraphEvent, f as GraphSettings, T as GraphTaskConfig, I as InjectTokensEvent, S as SchedulerResult, g as StuckDetection, h as TaskCompletedEvent, i as TaskCreationEvent, j as TaskFailedEvent, k as TaskStartedEvent, l as TaskState, m as TaskStatus } from './types-
|
|
3
|
+
export { C as COMPLETION_STRATEGIES, a as CONFLICT_STRATEGIES, b as CompletionResult, D as DEFAULTS, E as EXECUTION_MODES, c as EXECUTION_STATUS, d as ExecutionPlan, e as ExportOptions, G as GraphIssue, f as GraphValidationResult, I as IssueSeverity, M as MermaidOptions, T as TASK_STATUS, g as addDynamicTask, h as apply, i as applyAll, j as computeAvailableOutputs, k as createDefaultTaskState, l as createInitialExecutionState, m as detectStuckState, n as exportGraphConfig, o as exportGraphConfigToFile, p as flowToMermaid, q as getAllTasks, r as getCandidateTasks, s as getProvides, t as getRequires, u as getTask, v as graphToMermaid, w as hasTask, x as isExecutionComplete, y as isNonActiveTask, z as isRepeatableTask, A as isTaskCompleted, B as isTaskRunning, F as loadGraphConfig, H as next, J as planExecution, K as validateGraph, L as validateGraphConfig } from './constants-BEbO2_OK.js';
|
|
4
|
+
export { A as AgentActionEvent, C as CompletionStrategy, a as ConflictStrategy, E as ExecutionConfig, b as ExecutionMode, c as ExecutionState, d as ExecutionStatus, G as GraphConfig, e as GraphEvent, f as GraphSettings, T as GraphTaskConfig, I as InjectTokensEvent, S as SchedulerResult, g as StuckDetection, h as TaskCompletedEvent, i as TaskCreationEvent, j as TaskFailedEvent, k as TaskStartedEvent, l as TaskState, m as TaskStatus } from './types-DAI_a2as.js';
|
|
5
5
|
export { MemoryStore } from './stores/memory.js';
|
|
6
6
|
export { LocalStorageStore } from './stores/localStorage.js';
|
|
7
7
|
export { FileStore } from './stores/file.js';
|
|
8
8
|
export { BatchItemResult, BatchOptions, BatchProgress, BatchResult, batch } from './batch/index.js';
|
|
9
9
|
export { ConfigTemplates, Variables, resolveConfigTemplates, resolveVariables } from './config/index.js';
|
|
10
|
-
export {
|
|
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
|
+
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
|
+
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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
|
|
1
3
|
// src/step-machine/reducer.ts
|
|
2
4
|
function applyStepResult(flow, state, stepName, stepResult) {
|
|
3
5
|
const stepConfig = flow.steps[stepName];
|
|
@@ -251,7 +253,7 @@ var StepMachine = class {
|
|
|
251
253
|
}
|
|
252
254
|
}
|
|
253
255
|
sleep(ms) {
|
|
254
|
-
return new Promise((
|
|
256
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
255
257
|
}
|
|
256
258
|
async run(initialData) {
|
|
257
259
|
const runId = generateRunId();
|
|
@@ -2153,7 +2155,7 @@ async function batch(items, options) {
|
|
|
2153
2155
|
if (total === 0) {
|
|
2154
2156
|
return { items: [], completed: 0, failed: 0, total: 0, durationMs: 0 };
|
|
2155
2157
|
}
|
|
2156
|
-
return new Promise((
|
|
2158
|
+
return new Promise((resolve2) => {
|
|
2157
2159
|
let active = 0;
|
|
2158
2160
|
function tryStartNext() {
|
|
2159
2161
|
while (active < concurrency && nextIndex < total) {
|
|
@@ -2170,7 +2172,7 @@ async function batch(items, options) {
|
|
|
2170
2172
|
failed++;
|
|
2171
2173
|
}
|
|
2172
2174
|
if (active === 0 && completed + failed === total) {
|
|
2173
|
-
|
|
2175
|
+
resolve2({
|
|
2174
2176
|
items: results,
|
|
2175
2177
|
completed,
|
|
2176
2178
|
failed,
|
|
@@ -2209,7 +2211,7 @@ async function batch(items, options) {
|
|
|
2209
2211
|
active--;
|
|
2210
2212
|
onProgress?.(makeProgress(active));
|
|
2211
2213
|
if (completed + failed === total) {
|
|
2212
|
-
|
|
2214
|
+
resolve2({
|
|
2213
2215
|
items: results,
|
|
2214
2216
|
completed,
|
|
2215
2217
|
failed,
|
|
@@ -3027,6 +3029,572 @@ function getDownstream(live, nodeName) {
|
|
|
3027
3029
|
return { nodeName, nodes, tokens: [...tokenSet] };
|
|
3028
3030
|
}
|
|
3029
3031
|
|
|
3030
|
-
|
|
3032
|
+
// src/inference/core.ts
|
|
3033
|
+
var DEFAULT_THRESHOLD = 0.5;
|
|
3034
|
+
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.
|
|
3035
|
+
|
|
3036
|
+
For each task you analyze, provide a JSON response. Be conservative \u2014 only mark tasks as completed when the evidence strongly supports it.`;
|
|
3037
|
+
function buildInferencePrompt(live, options = {}) {
|
|
3038
|
+
const { scope, context, systemPrompt } = options;
|
|
3039
|
+
const graphTasks = getAllTasks(live.config);
|
|
3040
|
+
const { state } = live;
|
|
3041
|
+
const candidates = getAnalyzableCandidates(live, scope);
|
|
3042
|
+
if (candidates.length === 0) {
|
|
3043
|
+
return "";
|
|
3044
|
+
}
|
|
3045
|
+
const lines = [];
|
|
3046
|
+
lines.push(systemPrompt || DEFAULT_SYSTEM_PROMPT);
|
|
3047
|
+
lines.push("");
|
|
3048
|
+
lines.push("## Graph State");
|
|
3049
|
+
lines.push("");
|
|
3050
|
+
lines.push(`Available tokens: ${state.availableOutputs.length > 0 ? state.availableOutputs.join(", ") : "(none)"}`);
|
|
3051
|
+
lines.push("");
|
|
3052
|
+
const completedTasks = Object.entries(state.tasks).filter(([_, ts]) => ts.status === "completed").map(([name]) => name);
|
|
3053
|
+
if (completedTasks.length > 0) {
|
|
3054
|
+
lines.push(`Completed tasks: ${completedTasks.join(", ")}`);
|
|
3055
|
+
lines.push("");
|
|
3056
|
+
}
|
|
3057
|
+
lines.push("## Tasks to Analyze");
|
|
3058
|
+
lines.push("");
|
|
3059
|
+
for (const taskName of candidates) {
|
|
3060
|
+
const taskConfig = graphTasks[taskName];
|
|
3061
|
+
const taskState = state.tasks[taskName];
|
|
3062
|
+
lines.push(`### ${taskName}`);
|
|
3063
|
+
if (taskConfig.description) {
|
|
3064
|
+
lines.push(`Description: ${taskConfig.description}`);
|
|
3065
|
+
}
|
|
3066
|
+
const requires = getRequires(taskConfig);
|
|
3067
|
+
const provides = getProvides(taskConfig);
|
|
3068
|
+
if (requires.length > 0) lines.push(`Requires: ${requires.join(", ")}`);
|
|
3069
|
+
if (provides.length > 0) lines.push(`Provides: ${provides.join(", ")}`);
|
|
3070
|
+
lines.push(`Current status: ${taskState?.status || "not-started"}`);
|
|
3071
|
+
const hints = taskConfig.inference;
|
|
3072
|
+
if (hints) {
|
|
3073
|
+
if (hints.criteria) lines.push(`Completion criteria: ${hints.criteria}`);
|
|
3074
|
+
if (hints.keywords?.length) lines.push(`Keywords: ${hints.keywords.join(", ")}`);
|
|
3075
|
+
if (hints.suggestedChecks?.length) lines.push(`Suggested checks: ${hints.suggestedChecks.join("; ")}`);
|
|
3076
|
+
}
|
|
3077
|
+
lines.push("");
|
|
3078
|
+
}
|
|
3079
|
+
if (context) {
|
|
3080
|
+
lines.push("## Additional Context / Evidence");
|
|
3081
|
+
lines.push("");
|
|
3082
|
+
lines.push(context);
|
|
3083
|
+
lines.push("");
|
|
3084
|
+
}
|
|
3085
|
+
lines.push("## Response Format");
|
|
3086
|
+
lines.push("");
|
|
3087
|
+
lines.push("Respond with a JSON array of objects, one per task you have evidence for:");
|
|
3088
|
+
lines.push("```json");
|
|
3089
|
+
lines.push("[");
|
|
3090
|
+
lines.push(" {");
|
|
3091
|
+
lines.push(' "taskName": "task-name",');
|
|
3092
|
+
lines.push(' "confidence": 0.0 to 1.0,');
|
|
3093
|
+
lines.push(' "reasoning": "explanation of why you believe this task is complete or not"');
|
|
3094
|
+
lines.push(" }");
|
|
3095
|
+
lines.push("]");
|
|
3096
|
+
lines.push("```");
|
|
3097
|
+
lines.push("");
|
|
3098
|
+
lines.push("Rules:");
|
|
3099
|
+
lines.push('- Only include tasks from the "Tasks to Analyze" section');
|
|
3100
|
+
lines.push("- confidence 0.0 = no evidence of completion, 1.0 = certain it is complete");
|
|
3101
|
+
lines.push("- If you have no evidence for a task, omit it from the array");
|
|
3102
|
+
lines.push("- Be conservative \u2014 require clear evidence before high confidence");
|
|
3103
|
+
lines.push("- Respond ONLY with the JSON array, no additional text");
|
|
3104
|
+
return lines.join("\n");
|
|
3105
|
+
}
|
|
3106
|
+
async function inferCompletions(live, adapter, options = {}) {
|
|
3107
|
+
options.threshold ?? DEFAULT_THRESHOLD;
|
|
3108
|
+
const analyzedNodes = getAnalyzableCandidates(live, options.scope);
|
|
3109
|
+
if (analyzedNodes.length === 0) {
|
|
3110
|
+
return { suggestions: [], promptUsed: "", rawResponse: "", analyzedNodes: [] };
|
|
3111
|
+
}
|
|
3112
|
+
const prompt = buildInferencePrompt(live, options);
|
|
3113
|
+
const rawResponse = await adapter.analyze(prompt);
|
|
3114
|
+
const suggestions = parseInferenceResponse(rawResponse, analyzedNodes);
|
|
3115
|
+
return {
|
|
3116
|
+
suggestions,
|
|
3117
|
+
promptUsed: prompt,
|
|
3118
|
+
rawResponse,
|
|
3119
|
+
analyzedNodes
|
|
3120
|
+
};
|
|
3121
|
+
}
|
|
3122
|
+
function applyInferences(live, result, threshold = DEFAULT_THRESHOLD) {
|
|
3123
|
+
let current = live;
|
|
3124
|
+
for (const suggestion of result.suggestions) {
|
|
3125
|
+
if (suggestion.confidence < threshold) continue;
|
|
3126
|
+
const taskState = current.state.tasks[suggestion.taskName];
|
|
3127
|
+
if (!taskState) continue;
|
|
3128
|
+
if (taskState.status === "completed" || taskState.status === "running") continue;
|
|
3129
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3130
|
+
current = applyEvent(current, {
|
|
3131
|
+
type: "task-started",
|
|
3132
|
+
taskName: suggestion.taskName,
|
|
3133
|
+
timestamp: now
|
|
3134
|
+
});
|
|
3135
|
+
current = applyEvent(current, {
|
|
3136
|
+
type: "task-completed",
|
|
3137
|
+
taskName: suggestion.taskName,
|
|
3138
|
+
timestamp: now,
|
|
3139
|
+
result: "llm-inferred"
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
return current;
|
|
3143
|
+
}
|
|
3144
|
+
async function inferAndApply(live, adapter, options = {}) {
|
|
3145
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
3146
|
+
const inference = await inferCompletions(live, adapter, options);
|
|
3147
|
+
const updated = applyInferences(live, inference, threshold);
|
|
3148
|
+
const applied = inference.suggestions.filter((s) => s.confidence >= threshold);
|
|
3149
|
+
const skipped = inference.suggestions.filter((s) => s.confidence < threshold);
|
|
3150
|
+
return {
|
|
3151
|
+
live: updated,
|
|
3152
|
+
inference,
|
|
3153
|
+
applied,
|
|
3154
|
+
skipped
|
|
3155
|
+
};
|
|
3156
|
+
}
|
|
3157
|
+
function getAnalyzableCandidates(live, scope) {
|
|
3158
|
+
const graphTasks = getAllTasks(live.config);
|
|
3159
|
+
const { state } = live;
|
|
3160
|
+
const candidates = [];
|
|
3161
|
+
for (const [name, config] of Object.entries(graphTasks)) {
|
|
3162
|
+
const taskState = state.tasks[name];
|
|
3163
|
+
if (taskState?.status === "completed" || taskState?.status === "running") continue;
|
|
3164
|
+
if (scope) {
|
|
3165
|
+
if (scope.includes(name)) candidates.push(name);
|
|
3166
|
+
} else {
|
|
3167
|
+
if (config.inference?.autoDetectable) candidates.push(name);
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
return candidates;
|
|
3171
|
+
}
|
|
3172
|
+
function parseInferenceResponse(rawResponse, validNodes, _threshold) {
|
|
3173
|
+
const validSet = new Set(validNodes);
|
|
3174
|
+
try {
|
|
3175
|
+
const jsonStr = extractJson(rawResponse);
|
|
3176
|
+
if (!jsonStr) return [];
|
|
3177
|
+
const parsed = JSON.parse(jsonStr);
|
|
3178
|
+
if (!Array.isArray(parsed)) return [];
|
|
3179
|
+
const suggestions = [];
|
|
3180
|
+
for (const item of parsed) {
|
|
3181
|
+
if (!item || typeof item !== "object") continue;
|
|
3182
|
+
if (typeof item.taskName !== "string") continue;
|
|
3183
|
+
if (typeof item.confidence !== "number") continue;
|
|
3184
|
+
if (!validSet.has(item.taskName)) continue;
|
|
3185
|
+
const confidence = Math.max(0, Math.min(1, item.confidence));
|
|
3186
|
+
suggestions.push({
|
|
3187
|
+
taskName: item.taskName,
|
|
3188
|
+
confidence,
|
|
3189
|
+
reasoning: typeof item.reasoning === "string" ? item.reasoning : "",
|
|
3190
|
+
detectionMethod: "llm-inferred"
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
return suggestions;
|
|
3194
|
+
} catch {
|
|
3195
|
+
return [];
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
function extractJson(text) {
|
|
3199
|
+
if (!text || typeof text !== "string") return null;
|
|
3200
|
+
const trimmed = text.trim();
|
|
3201
|
+
const fenceMatch = trimmed.match(/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/);
|
|
3202
|
+
if (fenceMatch) return fenceMatch[1].trim();
|
|
3203
|
+
const firstBracket = trimmed.indexOf("[");
|
|
3204
|
+
const lastBracket = trimmed.lastIndexOf("]");
|
|
3205
|
+
if (firstBracket !== -1 && lastBracket > firstBracket) {
|
|
3206
|
+
return trimmed.slice(firstBracket, lastBracket + 1);
|
|
3207
|
+
}
|
|
3208
|
+
if (trimmed.startsWith("[")) return trimmed;
|
|
3209
|
+
return null;
|
|
3210
|
+
}
|
|
3211
|
+
function createCliAdapter(opts) {
|
|
3212
|
+
const timeout = opts.timeout ?? 6e4;
|
|
3213
|
+
return {
|
|
3214
|
+
analyze: (prompt) => {
|
|
3215
|
+
return new Promise((resolve2, reject) => {
|
|
3216
|
+
const args = opts.args(prompt);
|
|
3217
|
+
const child = execFile(
|
|
3218
|
+
opts.command,
|
|
3219
|
+
opts.stdin ? opts.args("") : args,
|
|
3220
|
+
{
|
|
3221
|
+
timeout,
|
|
3222
|
+
cwd: opts.cwd,
|
|
3223
|
+
env: opts.env ? { ...process.env, ...opts.env } : void 0,
|
|
3224
|
+
maxBuffer: 10 * 1024 * 1024
|
|
3225
|
+
// 10MB
|
|
3226
|
+
},
|
|
3227
|
+
(error, stdout, stderr) => {
|
|
3228
|
+
if (error) {
|
|
3229
|
+
reject(new Error(
|
|
3230
|
+
`CLI adapter failed: ${opts.command} exited with ${error.code ?? "error"}` + (stderr ? `
|
|
3231
|
+
stderr: ${stderr.slice(0, 500)}` : "") + `
|
|
3232
|
+
${error.message}`
|
|
3233
|
+
));
|
|
3234
|
+
} else {
|
|
3235
|
+
resolve2(stdout);
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
);
|
|
3239
|
+
if (opts.stdin && child.stdin) {
|
|
3240
|
+
child.stdin.write(prompt);
|
|
3241
|
+
child.stdin.end();
|
|
3242
|
+
}
|
|
3243
|
+
});
|
|
3244
|
+
}
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
function createHttpAdapter(opts) {
|
|
3248
|
+
const timeout = opts.timeout ?? 6e4;
|
|
3249
|
+
return {
|
|
3250
|
+
analyze: async (prompt) => {
|
|
3251
|
+
const body = opts.buildBody ? opts.buildBody(prompt) : { prompt };
|
|
3252
|
+
const controller = new AbortController();
|
|
3253
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
3254
|
+
try {
|
|
3255
|
+
const response = await fetch(opts.url, {
|
|
3256
|
+
method: "POST",
|
|
3257
|
+
headers: {
|
|
3258
|
+
"Content-Type": "application/json",
|
|
3259
|
+
...opts.headers ?? {}
|
|
3260
|
+
},
|
|
3261
|
+
body: JSON.stringify(body),
|
|
3262
|
+
signal: controller.signal
|
|
3263
|
+
});
|
|
3264
|
+
if (!response.ok) {
|
|
3265
|
+
const text = await response.text().catch(() => "");
|
|
3266
|
+
throw new Error(`HTTP ${response.status}: ${text.slice(0, 500)}`);
|
|
3267
|
+
}
|
|
3268
|
+
const json = await response.json();
|
|
3269
|
+
if (opts.extractResponse) {
|
|
3270
|
+
return opts.extractResponse(json);
|
|
3271
|
+
}
|
|
3272
|
+
if (typeof json.response === "string") return json.response;
|
|
3273
|
+
if (typeof json.text === "string") return json.text;
|
|
3274
|
+
if (typeof json.content === "string") return json.content;
|
|
3275
|
+
return JSON.stringify(json);
|
|
3276
|
+
} finally {
|
|
3277
|
+
clearTimeout(timer);
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
|
|
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 };
|
|
3031
3599
|
//# sourceMappingURL=index.js.map
|
|
3032
3600
|
//# sourceMappingURL=index.js.map
|