@ghchinoy/litflow 0.2.8 → 0.4.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/CHANGELOG.md +12 -4
- package/dist/breadboard/data/common.d.ts +35 -0
- package/dist/breadboard/data/file-system.d.ts +9 -0
- package/dist/breadboard/data/inline-all-content.d.ts +8 -0
- package/dist/breadboard/data/recent-boards.d.ts +17 -0
- package/dist/breadboard/data/save-outputs-as-file.d.ts +9 -0
- package/dist/breadboard/engine/add-run-module.d.ts +9 -0
- package/dist/breadboard/engine/editor/blank.d.ts +15 -0
- package/dist/breadboard/engine/editor/edge.d.ts +8 -0
- package/dist/breadboard/engine/editor/events.d.ts +34 -0
- package/dist/breadboard/engine/editor/graph.d.ts +18 -0
- package/dist/breadboard/engine/editor/history.d.ts +21 -0
- package/dist/breadboard/engine/editor/index.d.ts +6 -0
- package/dist/breadboard/engine/editor/operations/add-asset.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/add-edge.d.ts +11 -0
- package/dist/breadboard/engine/editor/operations/add-graph.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/add-module.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/add-node.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/change-asset-metadata.d.ts +11 -0
- package/dist/breadboard/engine/editor/operations/change-configuration.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/change-edge-metadata.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/change-edge.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/change-graph-metadata.d.ts +9 -0
- package/dist/breadboard/engine/editor/operations/change-metadata.d.ts +11 -0
- package/dist/breadboard/engine/editor/operations/change-module.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/error.d.ts +9 -0
- package/dist/breadboard/engine/editor/operations/remove-asset.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/remove-edge.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/remove-graph.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/remove-integration.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/remove-module.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/remove-node.d.ts +10 -0
- package/dist/breadboard/engine/editor/operations/replace-graph.d.ts +9 -0
- package/dist/breadboard/engine/editor/operations/toggle-export.d.ts +9 -0
- package/dist/breadboard/engine/editor/operations/upsert-integration.d.ts +10 -0
- package/dist/breadboard/engine/editor/selection.d.ts +16 -0
- package/dist/breadboard/engine/editor/transforms/configure-sidewire.d.ts +15 -0
- package/dist/breadboard/engine/editor/transforms/isolate-selection.d.ts +12 -0
- package/dist/breadboard/engine/editor/transforms/merge-graph.d.ts +12 -0
- package/dist/breadboard/engine/editor/transforms/move-to-graph.d.ts +12 -0
- package/dist/breadboard/engine/editor/transforms/move-to-new-graph.d.ts +12 -0
- package/dist/breadboard/engine/editor/transforms/sidewire-to-new-graph.d.ts +72 -0
- package/dist/breadboard/engine/file-system/blob-transform.d.ts +8 -0
- package/dist/breadboard/engine/file-system/composed-peristent-backend.d.ts +8 -0
- package/dist/breadboard/engine/file-system/ephemeral-blob-store.d.ts +8 -0
- package/dist/breadboard/engine/file-system/in-memory-blob-store.d.ts +18 -0
- package/dist/breadboard/engine/file-system/index.d.ts +22 -0
- package/dist/breadboard/engine/file-system/partial-persistent-backend.d.ts +19 -0
- package/dist/breadboard/engine/file-system/path.d.ts +23 -0
- package/dist/breadboard/engine/file-system/persistent-file.d.ts +19 -0
- package/dist/breadboard/engine/file-system/readable-stream-file.d.ts +17 -0
- package/dist/breadboard/engine/file-system/stub-file-system.d.ts +18 -0
- package/dist/breadboard/engine/file-system/utils.d.ts +9 -0
- package/dist/breadboard/engine/inspector/graph/bubbled-node.d.ts +34 -0
- package/dist/breadboard/engine/inspector/graph/describe-cache.d.ts +15 -0
- package/dist/breadboard/engine/inspector/graph/describe-type-cache.d.ts +15 -0
- package/dist/breadboard/engine/inspector/graph/edge-cache.d.ts +22 -0
- package/dist/breadboard/engine/inspector/graph/edge.d.ts +40 -0
- package/dist/breadboard/engine/inspector/graph/event.d.ts +16 -0
- package/dist/breadboard/engine/inspector/graph/exports-describer.d.ts +13 -0
- package/dist/breadboard/engine/inspector/graph/graph-cache.d.ts +18 -0
- package/dist/breadboard/engine/inspector/graph/graph-describer-manager.d.ts +21 -0
- package/dist/breadboard/engine/inspector/graph/graph-descriptor-handle.d.ts +17 -0
- package/dist/breadboard/engine/inspector/graph/graph-node-type.d.ts +15 -0
- package/dist/breadboard/engine/inspector/graph/graph-queries.d.ts +31 -0
- package/dist/breadboard/engine/inspector/graph/graph.d.ts +37 -0
- package/dist/breadboard/engine/inspector/graph/inspectable-asset.d.ts +17 -0
- package/dist/breadboard/engine/inspector/graph/kits.d.ts +15 -0
- package/dist/breadboard/engine/inspector/graph/module.d.ts +14 -0
- package/dist/breadboard/engine/inspector/graph/mutable-graph.d.ts +26 -0
- package/dist/breadboard/engine/inspector/graph/node-cache.d.ts +20 -0
- package/dist/breadboard/engine/inspector/graph/node-describer-manager.d.ts +25 -0
- package/dist/breadboard/engine/inspector/graph/node-type-describer-manager.d.ts +19 -0
- package/dist/breadboard/engine/inspector/graph/node.d.ts +27 -0
- package/dist/breadboard/engine/inspector/graph/port-cache.d.ts +18 -0
- package/dist/breadboard/engine/inspector/graph/ports.d.ts +16 -0
- package/dist/breadboard/engine/inspector/graph/schemas.d.ts +24 -0
- package/dist/breadboard/engine/inspector/graph/virtual-node.d.ts +35 -0
- package/dist/breadboard/engine/inspector/graph-store.d.ts +45 -0
- package/dist/breadboard/engine/inspector/index.d.ts +7 -0
- package/dist/breadboard/engine/inspector/utils.d.ts +9 -0
- package/dist/breadboard/engine/loader/capability.d.ts +21 -0
- package/dist/breadboard/engine/loader/index.d.ts +7 -0
- package/dist/breadboard/engine/loader/loader.d.ts +29 -0
- package/dist/breadboard/engine/loader/resolve-graph-urls.d.ts +16 -0
- package/dist/breadboard/engine/runtime/bubble.d.ts +23 -0
- package/dist/breadboard/engine/runtime/graph-based-node-handler.d.ts +16 -0
- package/dist/breadboard/engine/runtime/handler.d.ts +27 -0
- package/dist/breadboard/engine/runtime/harness/diagnostics.d.ts +12 -0
- package/dist/breadboard/engine/runtime/harness/events.d.ts +145 -0
- package/dist/breadboard/engine/runtime/harness/index.d.ts +8 -0
- package/dist/breadboard/engine/runtime/harness/local.d.ts +10 -0
- package/dist/breadboard/engine/runtime/harness/plan-runner.d.ts +25 -0
- package/dist/breadboard/engine/runtime/index.d.ts +6 -0
- package/dist/breadboard/engine/runtime/legacy.d.ts +11 -0
- package/dist/breadboard/engine/runtime/run/invoke-graph.d.ts +12 -0
- package/dist/breadboard/engine/runtime/run/node-invoker.d.ts +12 -0
- package/dist/breadboard/engine/runtime/run/run-graph.d.ts +12 -0
- package/dist/breadboard/engine/runtime/run.d.ts +29 -0
- package/dist/breadboard/engine/runtime/sandbox/capabilities-manager.d.ts +15 -0
- package/dist/breadboard/engine/runtime/sandbox/file-system-handler-factory.d.ts +15 -0
- package/dist/breadboard/engine/runtime/sandbox/invoke-describer.d.ts +10 -0
- package/dist/breadboard/engine/runtime/static/condense.d.ts +25 -0
- package/dist/breadboard/engine/runtime/static/create-plan.d.ts +14 -0
- package/dist/breadboard/engine/runtime/static/nodes-to-subgraph.d.ts +18 -0
- package/dist/breadboard/engine/runtime/static/orchestrator.d.ts +72 -0
- package/dist/breadboard/engine/runtime/static/types.d.ts +72 -0
- package/dist/breadboard/engine/runtime/traversal/index.d.ts +20 -0
- package/dist/breadboard/engine/runtime/traversal/iterator.d.ts +12 -0
- package/dist/breadboard/engine/runtime/traversal/machine.d.ts +14 -0
- package/dist/breadboard/engine/runtime/traversal/representation.d.ts +27 -0
- package/dist/breadboard/engine/runtime/traversal/result.d.ts +24 -0
- package/dist/breadboard/engine/runtime/traversal/state.d.ts +34 -0
- package/dist/breadboard/engine/telemetry.d.ts +25 -0
- package/dist/breadboard/engine/types.d.ts +9 -0
- package/dist/breadboard/lit-flow-runner.d.ts +13 -0
- package/dist/breadboard/lit-flow-runner.test.d.ts +1 -0
- package/dist/breadboard/runner.d.ts +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/lit-chiclet.d.ts +9 -0
- package/dist/lit-flow.d.ts +13 -0
- package/dist/lit-schema-node.d.ts +13 -0
- package/dist/lit-schema-node.test.d.ts +1 -0
- package/dist/litflow.js +6173 -658
- package/dist/litflow.js.map +1 -1
- package/package.json +33 -3
- package/src/breadboard/data/common.ts +450 -0
- package/src/breadboard/data/file-system.ts +54 -0
- package/src/breadboard/data/inline-all-content.ts +126 -0
- package/src/breadboard/data/recent-boards.ts +118 -0
- package/src/breadboard/data/save-outputs-as-file.ts +104 -0
- package/src/breadboard/engine/add-run-module.ts +168 -0
- package/src/breadboard/engine/editor/blank.ts +65 -0
- package/src/breadboard/engine/editor/edge.ts +27 -0
- package/src/breadboard/engine/editor/events.ts +64 -0
- package/src/breadboard/engine/editor/graph.ts +383 -0
- package/src/breadboard/engine/editor/history.ts +98 -0
- package/src/breadboard/engine/editor/index.ts +8 -0
- package/src/breadboard/engine/editor/operations/add-asset.ts +45 -0
- package/src/breadboard/engine/editor/operations/add-edge.ts +142 -0
- package/src/breadboard/engine/editor/operations/add-graph.ts +47 -0
- package/src/breadboard/engine/editor/operations/add-module.ts +64 -0
- package/src/breadboard/engine/editor/operations/add-node.ts +86 -0
- package/src/breadboard/engine/editor/operations/change-asset-metadata.ts +70 -0
- package/src/breadboard/engine/editor/operations/change-configuration.ts +82 -0
- package/src/breadboard/engine/editor/operations/change-edge-metadata.ts +58 -0
- package/src/breadboard/engine/editor/operations/change-edge.ts +111 -0
- package/src/breadboard/engine/editor/operations/change-graph-metadata.ts +52 -0
- package/src/breadboard/engine/editor/operations/change-metadata.ts +92 -0
- package/src/breadboard/engine/editor/operations/change-module.ts +64 -0
- package/src/breadboard/engine/editor/operations/error.ts +21 -0
- package/src/breadboard/engine/editor/operations/remove-asset.ts +48 -0
- package/src/breadboard/engine/editor/operations/remove-edge.ts +89 -0
- package/src/breadboard/engine/editor/operations/remove-graph.ts +49 -0
- package/src/breadboard/engine/editor/operations/remove-integration.ts +54 -0
- package/src/breadboard/engine/editor/operations/remove-module.ts +69 -0
- package/src/breadboard/engine/editor/operations/remove-node.ts +86 -0
- package/src/breadboard/engine/editor/operations/replace-graph.ts +52 -0
- package/src/breadboard/engine/editor/operations/toggle-export.ts +72 -0
- package/src/breadboard/engine/editor/operations/upsert-integration.ts +43 -0
- package/src/breadboard/engine/editor/selection.ts +58 -0
- package/src/breadboard/engine/editor/transforms/configure-sidewire.ts +73 -0
- package/src/breadboard/engine/editor/transforms/isolate-selection.ts +54 -0
- package/src/breadboard/engine/editor/transforms/merge-graph.ts +58 -0
- package/src/breadboard/engine/editor/transforms/move-to-graph.ts +102 -0
- package/src/breadboard/engine/editor/transforms/move-to-new-graph.ts +72 -0
- package/src/breadboard/engine/editor/transforms/sidewire-to-new-graph.ts +82 -0
- package/src/breadboard/engine/file-system/blob-transform.ts +44 -0
- package/src/breadboard/engine/file-system/composed-peristent-backend.ts +140 -0
- package/src/breadboard/engine/file-system/ephemeral-blob-store.ts +46 -0
- package/src/breadboard/engine/file-system/in-memory-blob-store.ts +87 -0
- package/src/breadboard/engine/file-system/index.ts +723 -0
- package/src/breadboard/engine/file-system/partial-persistent-backend.ts +109 -0
- package/src/breadboard/engine/file-system/path.ts +125 -0
- package/src/breadboard/engine/file-system/persistent-file.ts +66 -0
- package/src/breadboard/engine/file-system/readable-stream-file.ts +61 -0
- package/src/breadboard/engine/file-system/stub-file-system.ts +47 -0
- package/src/breadboard/engine/file-system/utils.ts +40 -0
- package/src/breadboard/engine/inspector/graph/bubbled-node.ts +162 -0
- package/src/breadboard/engine/inspector/graph/describe-cache.ts +78 -0
- package/src/breadboard/engine/inspector/graph/describe-type-cache.ts +48 -0
- package/src/breadboard/engine/inspector/graph/edge-cache.ts +118 -0
- package/src/breadboard/engine/inspector/graph/edge.ts +133 -0
- package/src/breadboard/engine/inspector/graph/event.ts +35 -0
- package/src/breadboard/engine/inspector/graph/exports-describer.ts +45 -0
- package/src/breadboard/engine/inspector/graph/graph-cache.ts +54 -0
- package/src/breadboard/engine/inspector/graph/graph-describer-manager.ts +338 -0
- package/src/breadboard/engine/inspector/graph/graph-descriptor-handle.ts +73 -0
- package/src/breadboard/engine/inspector/graph/graph-node-type.ts +111 -0
- package/src/breadboard/engine/inspector/graph/graph-queries.ts +256 -0
- package/src/breadboard/engine/inspector/graph/graph.ts +163 -0
- package/src/breadboard/engine/inspector/graph/inspectable-asset.ts +36 -0
- package/src/breadboard/engine/inspector/graph/kits.ts +208 -0
- package/src/breadboard/engine/inspector/graph/module.ts +69 -0
- package/src/breadboard/engine/inspector/graph/mutable-graph.ts +150 -0
- package/src/breadboard/engine/inspector/graph/node-cache.ts +123 -0
- package/src/breadboard/engine/inspector/graph/node-describer-manager.ts +279 -0
- package/src/breadboard/engine/inspector/graph/node-type-describer-manager.ts +122 -0
- package/src/breadboard/engine/inspector/graph/node.ts +149 -0
- package/src/breadboard/engine/inspector/graph/port-cache.ts +80 -0
- package/src/breadboard/engine/inspector/graph/ports.ts +292 -0
- package/src/breadboard/engine/inspector/graph/schemas.ts +131 -0
- package/src/breadboard/engine/inspector/graph/virtual-node.ts +184 -0
- package/src/breadboard/engine/inspector/graph-store.ts +629 -0
- package/src/breadboard/engine/inspector/index.ts +13 -0
- package/src/breadboard/engine/inspector/utils.ts +20 -0
- package/src/breadboard/engine/loader/capability.ts +184 -0
- package/src/breadboard/engine/loader/index.ts +14 -0
- package/src/breadboard/engine/loader/loader.ts +244 -0
- package/src/breadboard/engine/loader/resolve-graph-urls.ts +111 -0
- package/src/breadboard/engine/runtime/bubble.ts +269 -0
- package/src/breadboard/engine/runtime/graph-based-node-handler.ts +174 -0
- package/src/breadboard/engine/runtime/handler.ts +166 -0
- package/src/breadboard/engine/runtime/harness/diagnostics.ts +22 -0
- package/src/breadboard/engine/runtime/harness/events.ts +217 -0
- package/src/breadboard/engine/runtime/harness/index.ts +14 -0
- package/src/breadboard/engine/runtime/harness/local.ts +48 -0
- package/src/breadboard/engine/runtime/harness/plan-runner.ts +759 -0
- package/src/breadboard/engine/runtime/index.ts +8 -0
- package/src/breadboard/engine/runtime/legacy.ts +28 -0
- package/src/breadboard/engine/runtime/run/invoke-graph.ts +79 -0
- package/src/breadboard/engine/runtime/run/node-invoker.ts +137 -0
- package/src/breadboard/engine/runtime/run/run-graph.ts +186 -0
- package/src/breadboard/engine/runtime/run.ts +111 -0
- package/src/breadboard/engine/runtime/sandbox/capabilities-manager.ts +253 -0
- package/src/breadboard/engine/runtime/sandbox/file-system-handler-factory.ts +53 -0
- package/src/breadboard/engine/runtime/sandbox/invoke-describer.ts +125 -0
- package/src/breadboard/engine/runtime/static/condense.ts +155 -0
- package/src/breadboard/engine/runtime/static/create-plan.ts +134 -0
- package/src/breadboard/engine/runtime/static/nodes-to-subgraph.ts +168 -0
- package/src/breadboard/engine/runtime/static/orchestrator.ts +664 -0
- package/src/breadboard/engine/runtime/static/types.ts +77 -0
- package/src/breadboard/engine/runtime/traversal/index.ts +58 -0
- package/src/breadboard/engine/runtime/traversal/iterator.ts +124 -0
- package/src/breadboard/engine/runtime/traversal/machine.ts +58 -0
- package/src/breadboard/engine/runtime/traversal/representation.ts +115 -0
- package/src/breadboard/engine/runtime/traversal/result.ts +72 -0
- package/src/breadboard/engine/runtime/traversal/state.ts +115 -0
- package/src/breadboard/engine/telemetry.ts +121 -0
- package/src/breadboard/engine/types.ts +32 -0
- package/src/breadboard/lit-flow-runner.test.ts +44 -0
- package/src/breadboard/lit-flow-runner.ts +98 -0
- package/src/breadboard/runner.ts +80 -0
- package/src/index.ts +2 -0
- package/src/lit-chiclet.ts +69 -0
- package/src/lit-flow.ts +150 -9
- package/src/lit-node.ts +9 -2
- package/src/lit-schema-node.test.ts +65 -0
- package/src/lit-schema-node.ts +194 -0
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2025 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
AnyClientRunResult,
|
|
10
|
+
BreakpointSpec,
|
|
11
|
+
FileSystemEntry,
|
|
12
|
+
GraphDescriptor,
|
|
13
|
+
HarnessRunner,
|
|
14
|
+
HarnessRunResult,
|
|
15
|
+
InputValues,
|
|
16
|
+
NodeConfiguration,
|
|
17
|
+
NodeHandlerContext,
|
|
18
|
+
NodeIdentifier,
|
|
19
|
+
NodeLifecycleState,
|
|
20
|
+
NodeValue,
|
|
21
|
+
OrchestrationPlan,
|
|
22
|
+
OrchestratorState,
|
|
23
|
+
Outcome,
|
|
24
|
+
PlanNodeInfo,
|
|
25
|
+
Probe,
|
|
26
|
+
RunConfig,
|
|
27
|
+
RunEventTarget,
|
|
28
|
+
Task,
|
|
29
|
+
TraversalResult,
|
|
30
|
+
} from "@breadboard-ai/types";
|
|
31
|
+
|
|
32
|
+
import { asyncGen, err, ok, timestamp } from "@breadboard-ai/utils";
|
|
33
|
+
import { Signal } from "signal-polyfill";
|
|
34
|
+
import { signal } from "signal-utils";
|
|
35
|
+
import { SignalMap } from "signal-utils/map";
|
|
36
|
+
import { NodeInvoker } from "../run/node-invoker.js";
|
|
37
|
+
import { createPlan } from "../static/create-plan.js";
|
|
38
|
+
import { Orchestrator } from "../static/orchestrator.js";
|
|
39
|
+
import {
|
|
40
|
+
EdgeStateChangeEvent,
|
|
41
|
+
NodeStateChangeEvent,
|
|
42
|
+
EndEvent,
|
|
43
|
+
GraphEndEvent,
|
|
44
|
+
GraphStartEvent,
|
|
45
|
+
InputEvent,
|
|
46
|
+
NextEvent,
|
|
47
|
+
NodeEndEvent,
|
|
48
|
+
NodeStartEvent,
|
|
49
|
+
OutputEvent,
|
|
50
|
+
PauseEvent,
|
|
51
|
+
ResumeEvent,
|
|
52
|
+
RunnerErrorEvent,
|
|
53
|
+
SkipEvent,
|
|
54
|
+
StartEvent,
|
|
55
|
+
} from "./events.js";
|
|
56
|
+
|
|
57
|
+
import { fromProbe, fromRunnerResult } from "./local.js";
|
|
58
|
+
import { isLLMContentArray } from "../../../data/common.js";
|
|
59
|
+
|
|
60
|
+
export { PlanRunner };
|
|
61
|
+
|
|
62
|
+
function emptyPlan(): OrchestrationPlan {
|
|
63
|
+
return { stages: [] };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function emptyOrchestratorState(): OrchestratorState {
|
|
67
|
+
return new Map();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class PlanRunner
|
|
71
|
+
extends (EventTarget as RunEventTarget)
|
|
72
|
+
implements HarnessRunner
|
|
73
|
+
{
|
|
74
|
+
#controller: InternalRunStateController | null = null;
|
|
75
|
+
|
|
76
|
+
readonly config: RunConfig;
|
|
77
|
+
#run: AsyncGenerator<AnyClientRunResult, void, unknown> | null = null;
|
|
78
|
+
#pendingResult: HarnessRunResult | null = null;
|
|
79
|
+
#inRun = false;
|
|
80
|
+
#resumeWith: InputValues | undefined;
|
|
81
|
+
|
|
82
|
+
running() {
|
|
83
|
+
return !!this.#run && !this.#pendingResult;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async run(inputs?: InputValues, interactiveMode = false): Promise<boolean> {
|
|
87
|
+
if (this.#inRun) {
|
|
88
|
+
if (!inputs) {
|
|
89
|
+
// This is a situation when the "Start" button is clicked on a run
|
|
90
|
+
// while we're paused. This may happen when the first step is
|
|
91
|
+
// interrupted.
|
|
92
|
+
await this.#controller?.restart();
|
|
93
|
+
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
this.#resumeWith = inputs;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
this.#inRun = true;
|
|
100
|
+
try {
|
|
101
|
+
const eventArgs = {
|
|
102
|
+
inputs,
|
|
103
|
+
timestamp: timestamp(),
|
|
104
|
+
};
|
|
105
|
+
const starting = !this.#run;
|
|
106
|
+
|
|
107
|
+
if (!this.#run) {
|
|
108
|
+
this.#run = this.getGenerator(interactiveMode);
|
|
109
|
+
} else if (this.#pendingResult) {
|
|
110
|
+
this.#pendingResult.reply({ inputs: inputs ?? {} });
|
|
111
|
+
inputs = undefined;
|
|
112
|
+
}
|
|
113
|
+
this.#pendingResult = null;
|
|
114
|
+
|
|
115
|
+
this.dispatchEvent(
|
|
116
|
+
starting ? new StartEvent(eventArgs) : new ResumeEvent(eventArgs)
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
for (;;) {
|
|
120
|
+
console.assert(
|
|
121
|
+
this.#run,
|
|
122
|
+
"Expected run to exist. If not, we might be having a re-entrant run."
|
|
123
|
+
);
|
|
124
|
+
const result = await this.#run.next();
|
|
125
|
+
this.dispatchEvent(new NextEvent(result.value));
|
|
126
|
+
if (result.done) {
|
|
127
|
+
this.#run = null;
|
|
128
|
+
this.#pendingResult = null;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
const { type, data, reply } = result.value;
|
|
132
|
+
switch (type) {
|
|
133
|
+
case "input": {
|
|
134
|
+
if (inputs) {
|
|
135
|
+
// When there are inputs to consume, consume them and
|
|
136
|
+
// continue the run.
|
|
137
|
+
this.dispatchEvent(new InputEvent(true, data));
|
|
138
|
+
reply({ inputs });
|
|
139
|
+
inputs = undefined;
|
|
140
|
+
} else {
|
|
141
|
+
// When there are no inputs to consume, pause the run
|
|
142
|
+
// and wait for the next input.
|
|
143
|
+
this.#pendingResult = result.value;
|
|
144
|
+
this.dispatchEvent(new InputEvent(false, data));
|
|
145
|
+
if (this.#resumeWith) {
|
|
146
|
+
reply({ inputs: this.#resumeWith });
|
|
147
|
+
this.#pendingResult = null;
|
|
148
|
+
this.#resumeWith = undefined;
|
|
149
|
+
} else {
|
|
150
|
+
this.dispatchEvent(
|
|
151
|
+
new PauseEvent(false, {
|
|
152
|
+
timestamp: timestamp(),
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "error": {
|
|
161
|
+
this.dispatchEvent(new RunnerErrorEvent(data));
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "end": {
|
|
165
|
+
this.dispatchEvent(new EndEvent(data));
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case "skip": {
|
|
169
|
+
this.dispatchEvent(new SkipEvent(data));
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case "graphstart": {
|
|
173
|
+
this.dispatchEvent(new GraphStartEvent(data));
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case "graphend": {
|
|
177
|
+
this.dispatchEvent(new GraphEndEvent(data));
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "nodestart": {
|
|
181
|
+
this.dispatchEvent(new NodeStartEvent(data, result.value.result));
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "nodeend": {
|
|
185
|
+
this.dispatchEvent(new NodeEndEvent(data));
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case "output": {
|
|
189
|
+
this.dispatchEvent(new OutputEvent(data));
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} finally {
|
|
195
|
+
this.#inRun = false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* @signal */
|
|
200
|
+
accessor #orchestrator: Orchestrator;
|
|
201
|
+
|
|
202
|
+
/* @signal */
|
|
203
|
+
get state(): OrchestratorState {
|
|
204
|
+
const orchestrator = this.#orchestrator;
|
|
205
|
+
if (orchestrator) {
|
|
206
|
+
return orchestrator.fullState();
|
|
207
|
+
}
|
|
208
|
+
return emptyOrchestratorState();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* @signal */
|
|
212
|
+
get plan() {
|
|
213
|
+
const orchestrator = this.#orchestrator;
|
|
214
|
+
if (orchestrator) {
|
|
215
|
+
return orchestrator.plan;
|
|
216
|
+
}
|
|
217
|
+
return emptyPlan();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* @signal */
|
|
221
|
+
get waiting() {
|
|
222
|
+
const orchestrator = this.#orchestrator;
|
|
223
|
+
if (!orchestrator) return new Map();
|
|
224
|
+
return new Map(orchestrator.allWaiting);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
accessor breakpoints = new SignalMap<NodeIdentifier, BreakpointSpec>();
|
|
228
|
+
|
|
229
|
+
constructor(config: RunConfig) {
|
|
230
|
+
super();
|
|
231
|
+
this.config = config;
|
|
232
|
+
if (!config.runner) {
|
|
233
|
+
throw new Error(
|
|
234
|
+
`Unable to initialize PlanRunner: RunConfig.runner is empty`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
this.#orchestrator = this.#createOrchestrator(config.runner);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#createOrchestrator(graph: GraphDescriptor) {
|
|
241
|
+
const plan = createPlan(graph);
|
|
242
|
+
return new Orchestrator(plan, {
|
|
243
|
+
stateChangedbyOrchestrator: (id, newState, message) => {
|
|
244
|
+
this.#dispatchNodeStateChangeEvent(id, newState, message);
|
|
245
|
+
},
|
|
246
|
+
stateChanged: (newState, info) => {
|
|
247
|
+
this.#updateEdgeState(newState, info);
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#updateEdgeState(state: NodeLifecycleState, info: PlanNodeInfo) {
|
|
253
|
+
switch (state) {
|
|
254
|
+
case "inactive":
|
|
255
|
+
case "skipped":
|
|
256
|
+
this.dispatchEvent(
|
|
257
|
+
new EdgeStateChangeEvent({ edges: info.downstream, state: "initial" })
|
|
258
|
+
);
|
|
259
|
+
break;
|
|
260
|
+
case "working":
|
|
261
|
+
case "waiting":
|
|
262
|
+
this.dispatchEvent(
|
|
263
|
+
new EdgeStateChangeEvent({ edges: info.upstream, state: "consumed" })
|
|
264
|
+
);
|
|
265
|
+
break;
|
|
266
|
+
case "failed":
|
|
267
|
+
case "interrupted":
|
|
268
|
+
this.dispatchEvent(
|
|
269
|
+
new EdgeStateChangeEvent({ edges: info.downstream, state: "initial" })
|
|
270
|
+
);
|
|
271
|
+
break;
|
|
272
|
+
case "ready":
|
|
273
|
+
break;
|
|
274
|
+
case "succeeded":
|
|
275
|
+
this.dispatchEvent(
|
|
276
|
+
new EdgeStateChangeEvent({ edges: info.downstream, state: "stored" })
|
|
277
|
+
);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#dispatchNodeStateChangeEvent(
|
|
283
|
+
id: NodeIdentifier,
|
|
284
|
+
state: NodeLifecycleState,
|
|
285
|
+
message?: NodeValue
|
|
286
|
+
) {
|
|
287
|
+
this.dispatchEvent(new NodeStateChangeEvent({ id, state, message }));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async runNode(id: NodeIdentifier): Promise<Outcome<void>> {
|
|
291
|
+
if (!this.#controller) {
|
|
292
|
+
// First, activate the run
|
|
293
|
+
this.run(undefined, true);
|
|
294
|
+
}
|
|
295
|
+
if (!this.#orchestrator.working) {
|
|
296
|
+
this.dispatchEvent(new ResumeEvent({ timestamp: timestamp() }));
|
|
297
|
+
}
|
|
298
|
+
const outcome = await this.#controller?.runNode(id);
|
|
299
|
+
if (!this.#orchestrator.working) {
|
|
300
|
+
this.dispatchEvent(new PauseEvent(false, { timestamp: timestamp() }));
|
|
301
|
+
}
|
|
302
|
+
return outcome;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async runFrom(id: NodeIdentifier): Promise<Outcome<void>> {
|
|
306
|
+
this.#orchestrator.allWaiting.forEach(([id]) => {
|
|
307
|
+
this.stop(id);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// Stop all nodes from later stages that are currently working
|
|
311
|
+
const nodeStage = this.#orchestrator.getNodeState(id)?.stage;
|
|
312
|
+
if (nodeStage !== undefined) {
|
|
313
|
+
this.#orchestrator.allWorking.forEach(([id, workingNodeState]) => {
|
|
314
|
+
if (workingNodeState.stage > nodeStage) {
|
|
315
|
+
this.stop(id);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (!this.#controller || !this.running()) {
|
|
321
|
+
// If not already running, start a run in interactive mode
|
|
322
|
+
this.run(undefined, true);
|
|
323
|
+
} else if (!this.#orchestrator.working) {
|
|
324
|
+
this.dispatchEvent(new ResumeEvent({ timestamp: timestamp() }));
|
|
325
|
+
}
|
|
326
|
+
return this.#controller?.runFrom(id);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async stop(id: NodeIdentifier): Promise<Outcome<void>> {
|
|
330
|
+
const outcome = this.#controller?.stop(id);
|
|
331
|
+
if (!this.#orchestrator.working) {
|
|
332
|
+
this.dispatchEvent(new PauseEvent(false, { timestamp: timestamp() }));
|
|
333
|
+
}
|
|
334
|
+
return outcome;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
protected async *getGenerator(
|
|
338
|
+
interactiveMode = false
|
|
339
|
+
): AsyncGenerator<HarnessRunResult, void, unknown> {
|
|
340
|
+
this.#controller = null;
|
|
341
|
+
|
|
342
|
+
yield* asyncGen<HarnessRunResult>(async (next) => {
|
|
343
|
+
this.#controller = new InternalRunStateController(
|
|
344
|
+
this.config,
|
|
345
|
+
this.config.runner!,
|
|
346
|
+
this.#orchestrator,
|
|
347
|
+
this.breakpoints,
|
|
348
|
+
() => {
|
|
349
|
+
if (!this.#orchestrator.working) {
|
|
350
|
+
this.dispatchEvent(
|
|
351
|
+
new PauseEvent(false, { timestamp: timestamp() })
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
(inputs) => {
|
|
356
|
+
// Do not restart the run when it's already running. Because this
|
|
357
|
+
// runner may run tasks in parallel, we may have situations where
|
|
358
|
+
// the `resume` is issued multiple times. In this case, we'll run
|
|
359
|
+
// into the case when the runner has already been restarted.
|
|
360
|
+
if (this.running()) return;
|
|
361
|
+
this.run(inputs);
|
|
362
|
+
},
|
|
363
|
+
next
|
|
364
|
+
);
|
|
365
|
+
if (!interactiveMode) {
|
|
366
|
+
// Start the first run.
|
|
367
|
+
await this.#controller.run();
|
|
368
|
+
}
|
|
369
|
+
// Return a promise that never resolves, since plan runner can run
|
|
370
|
+
// nodes even after the first run completes.
|
|
371
|
+
return new Promise((resolve) => {
|
|
372
|
+
this.config.signal?.addEventListener("abort", () => {
|
|
373
|
+
resolve();
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async updateGraph(graph: GraphDescriptor) {
|
|
380
|
+
if (this.#orchestrator.working) {
|
|
381
|
+
this.#controller?.stopAll();
|
|
382
|
+
this.dispatchEvent(new PauseEvent(false, { timestamp: timestamp() }));
|
|
383
|
+
}
|
|
384
|
+
this.#orchestrator = this.#createOrchestrator(graph);
|
|
385
|
+
if (this.#controller) {
|
|
386
|
+
this.#controller.update(this.#orchestrator);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
type TaskStatus = "breakpoint" | "success";
|
|
392
|
+
|
|
393
|
+
class InternalRunStateController {
|
|
394
|
+
#stopControllers: Map<NodeIdentifier, AbortController> = new Map();
|
|
395
|
+
|
|
396
|
+
context: Promise<NodeHandlerContext>;
|
|
397
|
+
|
|
398
|
+
index: number = 0;
|
|
399
|
+
|
|
400
|
+
constructor(
|
|
401
|
+
public readonly config: RunConfig,
|
|
402
|
+
private graph: GraphDescriptor,
|
|
403
|
+
private orchestrator: Orchestrator,
|
|
404
|
+
public readonly breakpoints: Map<NodeIdentifier, BreakpointSpec>,
|
|
405
|
+
public readonly pause: () => void,
|
|
406
|
+
public readonly resume: (inputs?: InputValues) => void,
|
|
407
|
+
public readonly callback: (data: HarnessRunResult) => Promise<void>
|
|
408
|
+
) {
|
|
409
|
+
this.context = this.initializeNodeHandlerContext(callback);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
path(): number[] {
|
|
413
|
+
return [this.index++];
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async error(error: { $error: string }): Promise<{ $error: string }> {
|
|
417
|
+
await this.callback({
|
|
418
|
+
type: "error",
|
|
419
|
+
data: {
|
|
420
|
+
error: error.$error,
|
|
421
|
+
timestamp: timestamp(),
|
|
422
|
+
},
|
|
423
|
+
reply: async () => {},
|
|
424
|
+
});
|
|
425
|
+
return error;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
fromTask(task: Task, config: NodeConfiguration): TraversalResult {
|
|
429
|
+
// This is probably wrong, dig in later.
|
|
430
|
+
return {
|
|
431
|
+
descriptor: task.node,
|
|
432
|
+
inputs: { ...config, ...task.inputs },
|
|
433
|
+
missingInputs: [],
|
|
434
|
+
current: { from: "", to: "" },
|
|
435
|
+
opportunities: [],
|
|
436
|
+
newOpportunities: [],
|
|
437
|
+
partialOutputs: {},
|
|
438
|
+
state: {
|
|
439
|
+
state: new Map(),
|
|
440
|
+
constants: new Map(),
|
|
441
|
+
wireOutputs: () => {},
|
|
442
|
+
getAvailableInputs: () => ({}),
|
|
443
|
+
useInputs: () => {},
|
|
444
|
+
},
|
|
445
|
+
skip: false,
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
async runTask(task: Task): Promise<TaskStatus> {
|
|
450
|
+
const context = await this.context;
|
|
451
|
+
|
|
452
|
+
const id = task.node.id;
|
|
453
|
+
|
|
454
|
+
const breakpoint = this.breakpoints.get(id);
|
|
455
|
+
if (breakpoint) {
|
|
456
|
+
if (breakpoint.once) {
|
|
457
|
+
this.breakpoints.delete(id);
|
|
458
|
+
}
|
|
459
|
+
return "breakpoint";
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const path = this.path();
|
|
463
|
+
this.callback({
|
|
464
|
+
type: "nodestart",
|
|
465
|
+
data: {
|
|
466
|
+
node: task.node,
|
|
467
|
+
inputs: task.inputs,
|
|
468
|
+
path,
|
|
469
|
+
timestamp: timestamp(),
|
|
470
|
+
},
|
|
471
|
+
reply: async () => {},
|
|
472
|
+
});
|
|
473
|
+
const working = this.orchestrator.setWorking(task.node.id);
|
|
474
|
+
if (!ok(working)) {
|
|
475
|
+
console.warn(working.$error);
|
|
476
|
+
}
|
|
477
|
+
const signal = this.#getOrCreateStopController(task.node.id).signal;
|
|
478
|
+
const fileSystem = context.fileSystem?.updateRunFileSystem({
|
|
479
|
+
graphUrl: this.graph.url!,
|
|
480
|
+
assets: assetsFromGraphDescriptor(this.graph),
|
|
481
|
+
env: context.fileSystem.env(),
|
|
482
|
+
});
|
|
483
|
+
const invoker = new NodeInvoker(
|
|
484
|
+
{ ...context, fileSystem, signal, currentStep: task.node },
|
|
485
|
+
{ graph: this.graph },
|
|
486
|
+
async (result) => {
|
|
487
|
+
const harnessResult = fromRunnerResult(result);
|
|
488
|
+
if (harnessResult.type === "input" && harnessResult.data.bubbled) {
|
|
489
|
+
this.orchestrator.setWaiting(task.node.id);
|
|
490
|
+
return this.callback({
|
|
491
|
+
...harnessResult,
|
|
492
|
+
reply: async (inputs) => {
|
|
493
|
+
if (!signal.aborted) {
|
|
494
|
+
this.orchestrator.setWorking(task.node.id);
|
|
495
|
+
}
|
|
496
|
+
return harnessResult.reply(inputs);
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
return this.callback(harnessResult);
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
const nodeConfiguration = getLatestConfig(
|
|
504
|
+
task.node.id,
|
|
505
|
+
this.graph,
|
|
506
|
+
context
|
|
507
|
+
);
|
|
508
|
+
let outputs;
|
|
509
|
+
if (!ok(nodeConfiguration)) {
|
|
510
|
+
outputs = nodeConfiguration as { $error: string };
|
|
511
|
+
console.warn(`Can't get latest config`, outputs.$error);
|
|
512
|
+
} else {
|
|
513
|
+
outputs = await invoker.invokeNode(
|
|
514
|
+
this.fromTask(task, nodeConfiguration),
|
|
515
|
+
path
|
|
516
|
+
);
|
|
517
|
+
if (signal.aborted) {
|
|
518
|
+
const interrupting = this.orchestrator.setInterrupted(task.node.id);
|
|
519
|
+
if (!ok(interrupting)) {
|
|
520
|
+
console.warn(interrupting.$error);
|
|
521
|
+
}
|
|
522
|
+
} else {
|
|
523
|
+
const working = this.orchestrator.setWorking(task.node.id);
|
|
524
|
+
if (!ok(working)) {
|
|
525
|
+
console.warn(working.$error);
|
|
526
|
+
}
|
|
527
|
+
const providing = this.orchestrator.provideOutputs(
|
|
528
|
+
task.node.id,
|
|
529
|
+
outputs
|
|
530
|
+
);
|
|
531
|
+
if (!ok(providing)) {
|
|
532
|
+
console.warn(providing.$error);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
this.callback({
|
|
537
|
+
type: "nodeend",
|
|
538
|
+
data: {
|
|
539
|
+
node: task.node,
|
|
540
|
+
inputs: task.inputs,
|
|
541
|
+
outputs,
|
|
542
|
+
path,
|
|
543
|
+
newOpportunities: [],
|
|
544
|
+
timestamp: timestamp(),
|
|
545
|
+
},
|
|
546
|
+
reply: async () => {},
|
|
547
|
+
});
|
|
548
|
+
return "success";
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
async preamble(): Promise<NodeHandlerContext> {
|
|
552
|
+
const context = await this.context;
|
|
553
|
+
if (this.orchestrator.progress !== "initial") return context;
|
|
554
|
+
await this.callback({
|
|
555
|
+
type: "graphstart",
|
|
556
|
+
data: {
|
|
557
|
+
graph: this.graph,
|
|
558
|
+
graphId: "",
|
|
559
|
+
path: [],
|
|
560
|
+
timestamp: timestamp(),
|
|
561
|
+
},
|
|
562
|
+
reply: async () => {},
|
|
563
|
+
});
|
|
564
|
+
return context;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
async postamble() {
|
|
568
|
+
if (this.orchestrator.progress !== "finished") return;
|
|
569
|
+
if (this.orchestrator.failed) {
|
|
570
|
+
this.pause();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
await this.callback({
|
|
575
|
+
type: "graphend",
|
|
576
|
+
data: {
|
|
577
|
+
path: [],
|
|
578
|
+
timestamp: timestamp(),
|
|
579
|
+
},
|
|
580
|
+
reply: async () => {},
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
await this.callback({
|
|
584
|
+
type: "end",
|
|
585
|
+
data: {
|
|
586
|
+
timestamp: timestamp(),
|
|
587
|
+
},
|
|
588
|
+
reply: async () => {},
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
#getOrCreateStopController(id: NodeIdentifier) {
|
|
593
|
+
let stopController = this.#stopControllers.get(id);
|
|
594
|
+
if (stopController) return stopController;
|
|
595
|
+
|
|
596
|
+
stopController = new AbortController();
|
|
597
|
+
stopController.signal.addEventListener("abort", () => {
|
|
598
|
+
// Find first waiting step. Because of the way asyncGen queues, this will
|
|
599
|
+
// always be the first step that is actually waiting on input.
|
|
600
|
+
const [waitingId] =
|
|
601
|
+
this.orchestrator.allWaiting.find(
|
|
602
|
+
([, nodeState]) => nodeState.state === "waiting"
|
|
603
|
+
) || [];
|
|
604
|
+
if (waitingId !== id) return;
|
|
605
|
+
this.resume({});
|
|
606
|
+
});
|
|
607
|
+
this.#stopControllers.set(id, stopController);
|
|
608
|
+
return stopController;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async run() {
|
|
612
|
+
for (;;) {
|
|
613
|
+
if (this.orchestrator.progress === "finished") break;
|
|
614
|
+
|
|
615
|
+
const tasks = this.orchestrator.currentTasks();
|
|
616
|
+
if (!ok(tasks)) {
|
|
617
|
+
await this.error(tasks);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (tasks.length === 0) return;
|
|
621
|
+
|
|
622
|
+
let breakpoint = false;
|
|
623
|
+
await Promise.all(
|
|
624
|
+
tasks.map(async (task) => {
|
|
625
|
+
const status = await this.runTask(task);
|
|
626
|
+
if (status === "breakpoint") {
|
|
627
|
+
breakpoint = true;
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
);
|
|
631
|
+
if (breakpoint) {
|
|
632
|
+
this.pause();
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
await this.postamble();
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
async runNode(id: NodeIdentifier): Promise<Outcome<void>> {
|
|
640
|
+
const task = this.orchestrator.taskFromId(id);
|
|
641
|
+
if (!ok(task)) return task;
|
|
642
|
+
await this.runTask(task);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
async runFrom(id: NodeIdentifier): Promise<Outcome<void>> {
|
|
646
|
+
this.orchestrator.restartAtNode(id);
|
|
647
|
+
return this.run();
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
async restart(): Promise<Outcome<void>> {
|
|
651
|
+
this.orchestrator.restartAtCurrentStage();
|
|
652
|
+
return this.run();
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
stopAll() {
|
|
656
|
+
[...this.#stopControllers.keys()].forEach((id) => {
|
|
657
|
+
this.stop(id);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
stop(id: NodeIdentifier) {
|
|
662
|
+
const stopController = this.#stopControllers?.get(id);
|
|
663
|
+
if (!stopController) {
|
|
664
|
+
console.warn(`Unable to find stop controller for node "${id}"`);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
stopController.abort(`Interrupt node "${id}"`);
|
|
669
|
+
} catch (e) {
|
|
670
|
+
console.log(e);
|
|
671
|
+
}
|
|
672
|
+
this.#stopControllers?.delete(id);
|
|
673
|
+
this.orchestrator.setInterrupted(id);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
async initializeNodeHandlerContext(
|
|
677
|
+
next: (data: HarnessRunResult) => Promise<void>
|
|
678
|
+
): Promise<NodeHandlerContext> {
|
|
679
|
+
const kits = this.config.kits;
|
|
680
|
+
|
|
681
|
+
const {
|
|
682
|
+
loader,
|
|
683
|
+
fileSystem,
|
|
684
|
+
base,
|
|
685
|
+
signal,
|
|
686
|
+
graphStore,
|
|
687
|
+
fetchWithCreds,
|
|
688
|
+
getProjectRunState,
|
|
689
|
+
clientDeploymentConfiguration,
|
|
690
|
+
flags,
|
|
691
|
+
} = this.config;
|
|
692
|
+
|
|
693
|
+
const probe: Probe = {
|
|
694
|
+
async report(message) {
|
|
695
|
+
next(fromProbe(message));
|
|
696
|
+
},
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
signal?.addEventListener("abort", () => {
|
|
700
|
+
this.#stopControllers.forEach((controller) => {
|
|
701
|
+
controller.abort();
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
return {
|
|
706
|
+
probe,
|
|
707
|
+
kits,
|
|
708
|
+
loader,
|
|
709
|
+
fileSystem,
|
|
710
|
+
base,
|
|
711
|
+
signal,
|
|
712
|
+
graphStore,
|
|
713
|
+
fetchWithCreds,
|
|
714
|
+
getProjectRunState,
|
|
715
|
+
clientDeploymentConfiguration,
|
|
716
|
+
flags,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
update(orchestrator: Orchestrator) {
|
|
721
|
+
const oldOrchestartor = this.orchestrator;
|
|
722
|
+
orchestrator.update(oldOrchestartor);
|
|
723
|
+
this.orchestrator = orchestrator;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function getLatestConfig(
|
|
728
|
+
id: NodeIdentifier,
|
|
729
|
+
graph: GraphDescriptor,
|
|
730
|
+
context: NodeHandlerContext
|
|
731
|
+
): Outcome<NodeConfiguration> {
|
|
732
|
+
const gettingMainGraph = context.graphStore?.getByDescriptor(graph);
|
|
733
|
+
if (!gettingMainGraph?.success) {
|
|
734
|
+
return err(`Can't to find graph "${graph.url}" in graph store`);
|
|
735
|
+
}
|
|
736
|
+
const inspector = context.graphStore?.inspect(gettingMainGraph.result, "");
|
|
737
|
+
if (!inspector) {
|
|
738
|
+
return err(`Can't get inspector for graph "${graph.url}"`);
|
|
739
|
+
}
|
|
740
|
+
const inspectableNode = inspector.nodeById(id);
|
|
741
|
+
if (!inspectableNode) {
|
|
742
|
+
return err(`Unable to find node "${id}`);
|
|
743
|
+
}
|
|
744
|
+
return inspectableNode?.configuration();
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function assetsFromGraphDescriptor(
|
|
748
|
+
descriptor?: GraphDescriptor
|
|
749
|
+
): FileSystemEntry[] {
|
|
750
|
+
const { assets } = descriptor || {};
|
|
751
|
+
if (!assets) return [];
|
|
752
|
+
|
|
753
|
+
return Object.entries(assets)
|
|
754
|
+
.filter(([, asset]) => isLLMContentArray(asset.data))
|
|
755
|
+
.map(([path, asset]) => {
|
|
756
|
+
const data = asset.data;
|
|
757
|
+
return { path: `/assets/${path}`, data } as FileSystemEntry;
|
|
758
|
+
});
|
|
759
|
+
}
|