yaml-flow 2.4.0 → 2.5.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/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 +259 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +254 -1
- 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 +6 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
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];
|
|
@@ -3027,6 +3029,257 @@ 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((resolve, 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
|
+
resolve(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
|
+
export { COMPLETION_STRATEGIES, CONFLICT_STRATEGIES, DEFAULTS, EXECUTION_MODES, EXECUTION_STATUS, FileStore, StepMachine as FlowEngine, LocalStorageStore, MemoryStore, StepMachine, TASK_STATUS, addDynamicTask, addNode, addProvides, addRequires, apply, applyAll, applyEvent, applyInferences, applyStepResult, batch, buildInferencePrompt, checkCircuitBreaker, computeAvailableOutputs, computeStepInput, createCliAdapter, createDefaultTaskState, createStepMachine as createEngine, createHttpAdapter, createInitialExecutionState, createInitialState, createLiveGraph, createStepMachine, detectStuckState, disableNode, drainTokens, enableNode, exportGraphConfig, exportGraphConfigToFile, extractReturnData, flowToMermaid, getAllTasks, getCandidateTasks, getDownstream, getNode, getProvides, getRequires, getTask, getUnreachableNodes, getUnreachableTokens, getUpstream, graphToMermaid, hasTask, inferAndApply, inferCompletions, injectTokens, inspect, isExecutionComplete, isNonActiveTask, isRepeatableTask, isTaskCompleted, isTaskRunning, loadGraphConfig, loadStepFlow, next, planExecution, removeNode, removeProvides, removeRequires, resetNode, resolveConfigTemplates, resolveVariables, restore, schedule, snapshot, validateGraph, validateGraphConfig, validateStepFlowConfig };
|
|
3031
3284
|
//# sourceMappingURL=index.js.map
|
|
3032
3285
|
//# sourceMappingURL=index.js.map
|