@ghchinoy/litflow 0.2.7 → 0.3.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 +59 -0
- package/dist/breadboard/data/common.d.ts +35 -0
- package/dist/breadboard/engine/loader/capability.d.ts +21 -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/events.d.ts +145 -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/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/create-plan.d.ts +14 -0
- package/dist/breadboard/engine/runtime/static/orchestrator.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/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-schema-node.d.ts +13 -0
- package/dist/lit-schema-node.test.d.ts +1 -0
- package/dist/litflow.js +708 -442
- package/dist/litflow.js.map +1 -1
- package/package.json +18 -4
- 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 +17 -7
- package/src/lit-schema-node.test.ts +65 -0
- package/src/lit-schema-node.ts +194 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
SingleEditResult,
|
|
13
|
+
} from "@breadboard-ai/types";
|
|
14
|
+
|
|
15
|
+
export { AddGraph };
|
|
16
|
+
|
|
17
|
+
class AddGraph implements EditOperation {
|
|
18
|
+
async do(
|
|
19
|
+
edit: EditSpec,
|
|
20
|
+
context: EditOperationContext
|
|
21
|
+
): Promise<SingleEditResult> {
|
|
22
|
+
if (edit.type !== "addgraph") {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Editor API integrity error: expected type "addgraph", received "${edit.type}" instead.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const { id, graph: subgraph } = edit;
|
|
28
|
+
const { graph, mutable } = context;
|
|
29
|
+
|
|
30
|
+
if (graph.graphs?.[id]) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: `Failed to add graph: "${id}" already exists.`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
graph.graphs ??= {};
|
|
37
|
+
graph.graphs[id] = subgraph;
|
|
38
|
+
mutable.addSubgraph(subgraph, id);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
affectedModules: [],
|
|
43
|
+
affectedNodes: [],
|
|
44
|
+
affectedGraphs: [id],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
InspectableGraph,
|
|
13
|
+
ModuleIdentifier,
|
|
14
|
+
SingleEditResult,
|
|
15
|
+
} from "@breadboard-ai/types";
|
|
16
|
+
|
|
17
|
+
export class AddModule implements EditOperation {
|
|
18
|
+
async can(
|
|
19
|
+
id: ModuleIdentifier,
|
|
20
|
+
inspector: InspectableGraph
|
|
21
|
+
): Promise<SingleEditResult> {
|
|
22
|
+
const exists = inspector.moduleById(id);
|
|
23
|
+
if (exists) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
error: `Unable to add module: module with id "${id}" already exists`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
affectedNodes: [],
|
|
32
|
+
affectedModules: [id],
|
|
33
|
+
affectedGraphs: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async do(
|
|
38
|
+
spec: EditSpec,
|
|
39
|
+
context: EditOperationContext
|
|
40
|
+
): Promise<SingleEditResult> {
|
|
41
|
+
if (spec.type !== "addmodule") {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Editor API integrity error: expected type "addmodule", received "${spec.type}" instead.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const { id, module } = spec;
|
|
47
|
+
const { graph, mutable } = context;
|
|
48
|
+
const inspector = mutable.graphs.get("")!;
|
|
49
|
+
const can = await this.can(id, inspector);
|
|
50
|
+
if (!can.success) {
|
|
51
|
+
return can;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
graph.modules ??= {};
|
|
55
|
+
graph.modules[id] = module;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
affectedNodes: [],
|
|
60
|
+
affectedModules: [id],
|
|
61
|
+
affectedGraphs: [],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
EditableNodeSpec,
|
|
13
|
+
InspectableGraph,
|
|
14
|
+
SingleEditResult,
|
|
15
|
+
} from "@breadboard-ai/types";
|
|
16
|
+
import { GraphDescriptorHandle } from "../../inspector/graph/graph-descriptor-handle.js";
|
|
17
|
+
import { errorNoInspect } from "./error.js";
|
|
18
|
+
|
|
19
|
+
export class AddNode implements EditOperation {
|
|
20
|
+
async can(
|
|
21
|
+
spec: EditableNodeSpec,
|
|
22
|
+
inspector: InspectableGraph
|
|
23
|
+
): Promise<SingleEditResult> {
|
|
24
|
+
const duplicate = !!inspector.nodeById(spec.id);
|
|
25
|
+
if (duplicate) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: `Unable to add node: a node with id "${spec.id}" already exists`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const validType = !!inspector.typeById(spec.type);
|
|
33
|
+
if (!validType) {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
error: `Unable to add node: node type "${spec.type}" is not a known type`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
affectedNodes: [],
|
|
43
|
+
affectedModules: [],
|
|
44
|
+
affectedGraphs: [],
|
|
45
|
+
topologyChange: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async do(
|
|
50
|
+
spec: EditSpec,
|
|
51
|
+
context: EditOperationContext
|
|
52
|
+
): Promise<SingleEditResult> {
|
|
53
|
+
if (spec.type !== "addnode") {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Editor API integrity error: expected type "addnode", received "${spec.type}" instead.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const { node, graphId } = spec;
|
|
59
|
+
|
|
60
|
+
const { graph, mutable } = context;
|
|
61
|
+
const inspector = mutable.graphs.get(graphId);
|
|
62
|
+
if (!inspector) {
|
|
63
|
+
return errorNoInspect(graphId);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const handle = GraphDescriptorHandle.create(graph, graphId);
|
|
67
|
+
if (!handle.success) {
|
|
68
|
+
return handle;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const can = await this.can(node, inspector);
|
|
72
|
+
if (!can.success) {
|
|
73
|
+
return can;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
handle.result.graph().nodes.push(node);
|
|
77
|
+
mutable.nodes.add(node, graphId);
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
affectedNodes: [{ id: node.id, graphId }],
|
|
81
|
+
affectedModules: [],
|
|
82
|
+
affectedGraphs: [graphId],
|
|
83
|
+
topologyChange: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2025 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
AssetMetadata,
|
|
10
|
+
EditOperation,
|
|
11
|
+
EditOperationContext,
|
|
12
|
+
EditSpec,
|
|
13
|
+
SingleEditResult,
|
|
14
|
+
} from "@breadboard-ai/types";
|
|
15
|
+
|
|
16
|
+
export { ChangeAssetMetadata };
|
|
17
|
+
|
|
18
|
+
class ChangeAssetMetadata implements EditOperation {
|
|
19
|
+
#isVisualOnly(
|
|
20
|
+
incoming: AssetMetadata,
|
|
21
|
+
existing: AssetMetadata | undefined
|
|
22
|
+
): boolean {
|
|
23
|
+
if (!existing) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
existing.title === incoming.title &&
|
|
28
|
+
existing.description === incoming.description &&
|
|
29
|
+
existing.type === incoming.type &&
|
|
30
|
+
existing.subType == incoming.subType &&
|
|
31
|
+
existing.managed === incoming.managed
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async do(
|
|
36
|
+
spec: EditSpec,
|
|
37
|
+
context: EditOperationContext
|
|
38
|
+
): Promise<SingleEditResult> {
|
|
39
|
+
if (spec.type !== "changeassetmetadata") {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Editor API integrity error: expected type "changeassetmetadata", received "${spec.type}" instead.`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { path, metadata } = spec;
|
|
46
|
+
|
|
47
|
+
const { graph } = context;
|
|
48
|
+
|
|
49
|
+
const asset = graph.assets?.[path];
|
|
50
|
+
|
|
51
|
+
if (!asset) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: `Unable to edit non-existing asset "${path}"`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const visualOnly = this.#isVisualOnly(metadata, asset.metadata);
|
|
59
|
+
|
|
60
|
+
asset.metadata = metadata;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
visualOnly,
|
|
64
|
+
success: true,
|
|
65
|
+
affectedGraphs: [],
|
|
66
|
+
affectedModules: [],
|
|
67
|
+
affectedNodes: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
InspectableGraph,
|
|
13
|
+
NodeIdentifier,
|
|
14
|
+
SingleEditResult,
|
|
15
|
+
} from "@breadboard-ai/types";
|
|
16
|
+
import { errorNoInspect } from "./error.js";
|
|
17
|
+
|
|
18
|
+
export class ChangeConfiguration implements EditOperation {
|
|
19
|
+
async can(
|
|
20
|
+
id: NodeIdentifier,
|
|
21
|
+
inspector: InspectableGraph
|
|
22
|
+
): Promise<SingleEditResult> {
|
|
23
|
+
const node = inspector.nodeById(id);
|
|
24
|
+
if (!node) {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: `Unable to update configuration: node with id "${id}" does not exist`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
success: true,
|
|
32
|
+
affectedNodes: [],
|
|
33
|
+
affectedModules: [],
|
|
34
|
+
affectedGraphs: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async do(
|
|
39
|
+
spec: EditSpec,
|
|
40
|
+
context: EditOperationContext
|
|
41
|
+
): Promise<SingleEditResult> {
|
|
42
|
+
if (spec.type !== "changeconfiguration") {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Editor API integrity error: expected type "changeconfiguration", received "${spec.type}" instead.`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const { id, configuration, graphId, reset = false } = spec;
|
|
48
|
+
if (!configuration) {
|
|
49
|
+
return {
|
|
50
|
+
success: false,
|
|
51
|
+
error: "Configuration wasn't supplied.",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const { mutable } = context;
|
|
55
|
+
const inspector = mutable.graphs.get(graphId);
|
|
56
|
+
if (!inspector) {
|
|
57
|
+
return errorNoInspect(graphId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const can = await this.can(id, inspector);
|
|
61
|
+
if (!can.success) {
|
|
62
|
+
return can;
|
|
63
|
+
}
|
|
64
|
+
const node = inspector.nodeById(id);
|
|
65
|
+
if (node) {
|
|
66
|
+
if (reset) {
|
|
67
|
+
node.descriptor.configuration = configuration;
|
|
68
|
+
} else {
|
|
69
|
+
node.descriptor.configuration = {
|
|
70
|
+
...node.descriptor.configuration,
|
|
71
|
+
...configuration,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
affectedNodes: [{ id, graphId }],
|
|
78
|
+
affectedModules: [],
|
|
79
|
+
affectedGraphs: [graphId],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2025 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
SingleEditResult,
|
|
13
|
+
} from "@breadboard-ai/types";
|
|
14
|
+
import { GraphDescriptorHandle } from "../../inspector/graph/graph-descriptor-handle.js";
|
|
15
|
+
import { findEdgeIndex } from "../edge.js";
|
|
16
|
+
import { error } from "./error.js";
|
|
17
|
+
|
|
18
|
+
export { ChangeEdgeMetadata };
|
|
19
|
+
|
|
20
|
+
class ChangeEdgeMetadata implements EditOperation {
|
|
21
|
+
async do(
|
|
22
|
+
spec: EditSpec,
|
|
23
|
+
context: EditOperationContext
|
|
24
|
+
): Promise<SingleEditResult> {
|
|
25
|
+
if (spec.type !== "changeedgemetadata") {
|
|
26
|
+
return error(
|
|
27
|
+
`Invalid edit operation: expected "changeedgemetadata", got "${spec.type}".`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const { graphId, metadata, edge } = spec;
|
|
31
|
+
const { graph: mainGraph } = context;
|
|
32
|
+
|
|
33
|
+
const handle = GraphDescriptorHandle.create(mainGraph, graphId);
|
|
34
|
+
if (!handle.success) {
|
|
35
|
+
return handle;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const graph = handle.result.graph();
|
|
39
|
+
const index = findEdgeIndex(graph, edge);
|
|
40
|
+
if (index < 0) {
|
|
41
|
+
return error(
|
|
42
|
+
`Unable to find edge between "${edge.from}" and "${edge.to}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const existingEdge = graph.edges[index]!;
|
|
46
|
+
const existingMetadata = existingEdge.metadata || {};
|
|
47
|
+
existingEdge.metadata = {
|
|
48
|
+
...existingMetadata,
|
|
49
|
+
...metadata,
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
success: true,
|
|
53
|
+
affectedGraphs: [graphId],
|
|
54
|
+
affectedNodes: [],
|
|
55
|
+
affectedModules: [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
EditableEdgeSpec,
|
|
13
|
+
GraphIdentifier,
|
|
14
|
+
InspectableGraph,
|
|
15
|
+
SingleEditResult,
|
|
16
|
+
} from "@breadboard-ai/types";
|
|
17
|
+
import { fixUpStarEdge } from "../../inspector/graph/edge.js";
|
|
18
|
+
import { GraphDescriptorHandle } from "../../inspector/graph/graph-descriptor-handle.js";
|
|
19
|
+
import { edgesEqual, findEdgeIndex } from "../edge.js";
|
|
20
|
+
import { AddEdge } from "./add-edge.js";
|
|
21
|
+
import { errorNoInspect } from "./error.js";
|
|
22
|
+
import { RemoveEdge } from "./remove-edge.js";
|
|
23
|
+
|
|
24
|
+
export class ChangeEdge implements EditOperation {
|
|
25
|
+
async can(
|
|
26
|
+
from: EditableEdgeSpec,
|
|
27
|
+
to: EditableEdgeSpec,
|
|
28
|
+
inspector: InspectableGraph,
|
|
29
|
+
graphId: GraphIdentifier
|
|
30
|
+
): Promise<SingleEditResult> {
|
|
31
|
+
if (edgesEqual(from, to)) {
|
|
32
|
+
return {
|
|
33
|
+
success: true,
|
|
34
|
+
affectedNodes: [],
|
|
35
|
+
affectedModules: [],
|
|
36
|
+
affectedGraphs: [graphId],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const canRemoveOp = new RemoveEdge();
|
|
40
|
+
const canRemove = await canRemoveOp.can(from, inspector, graphId);
|
|
41
|
+
if (!canRemove.success) return canRemove;
|
|
42
|
+
const canAddOp = new AddEdge();
|
|
43
|
+
const canAdd = await canAddOp.can(to, inspector, graphId);
|
|
44
|
+
if (!canAdd.success) return canAdd;
|
|
45
|
+
return {
|
|
46
|
+
success: true,
|
|
47
|
+
affectedNodes: [],
|
|
48
|
+
affectedModules: [],
|
|
49
|
+
affectedGraphs: [graphId],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async do(
|
|
54
|
+
spec: EditSpec,
|
|
55
|
+
context: EditOperationContext
|
|
56
|
+
): Promise<SingleEditResult> {
|
|
57
|
+
if (spec.type !== "changeedge") {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Editor API integrity error: expected type "changeedge", received "${spec.type}" instead.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const { from, to, graphId } = spec;
|
|
63
|
+
const { mutable } = context;
|
|
64
|
+
const inspector = mutable.graphs.get(graphId);
|
|
65
|
+
if (!inspector) {
|
|
66
|
+
return errorNoInspect(graphId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const can = await this.can(from, to, inspector, graphId);
|
|
70
|
+
if (!can.success) {
|
|
71
|
+
return can;
|
|
72
|
+
}
|
|
73
|
+
if (edgesEqual(from, to)) {
|
|
74
|
+
return {
|
|
75
|
+
success: true,
|
|
76
|
+
noChange: true,
|
|
77
|
+
affectedNodes: [],
|
|
78
|
+
affectedModules: [],
|
|
79
|
+
affectedGraphs: [],
|
|
80
|
+
topologyChange: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const handle = GraphDescriptorHandle.create(context.graph, graphId);
|
|
84
|
+
if (!handle.success) {
|
|
85
|
+
return handle;
|
|
86
|
+
}
|
|
87
|
+
const graph = handle.result.graph();
|
|
88
|
+
|
|
89
|
+
const fixedUpEdge = fixUpStarEdge(from);
|
|
90
|
+
const edges = graph.edges;
|
|
91
|
+
const index = findEdgeIndex(graph, fixedUpEdge);
|
|
92
|
+
const edge = edges[index];
|
|
93
|
+
edge.from = to.from;
|
|
94
|
+
edge.out = to.out;
|
|
95
|
+
edge.to = to.to;
|
|
96
|
+
edge.in = to.in;
|
|
97
|
+
if (to.constant === true) {
|
|
98
|
+
edge.constant = to.constant;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
affectedNodes: [
|
|
103
|
+
{ id: edge.from, graphId },
|
|
104
|
+
{ id: edge.to, graphId },
|
|
105
|
+
],
|
|
106
|
+
affectedModules: [],
|
|
107
|
+
affectedGraphs: [graphId],
|
|
108
|
+
topologyChange: true,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
SingleEditResult,
|
|
13
|
+
} from "@breadboard-ai/types";
|
|
14
|
+
import { GraphDescriptorHandle } from "../../inspector/graph/graph-descriptor-handle.js";
|
|
15
|
+
|
|
16
|
+
export class ChangeGraphMetadata implements EditOperation {
|
|
17
|
+
async do(
|
|
18
|
+
spec: EditSpec,
|
|
19
|
+
context: EditOperationContext
|
|
20
|
+
): Promise<SingleEditResult> {
|
|
21
|
+
if (spec.type !== "changegraphmetadata") {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Editor API integrity error: expected type "changegraphmetadata", received "${spec.type}" instead.`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const { metadata, graphId, title, description } = spec;
|
|
27
|
+
|
|
28
|
+
const handle = GraphDescriptorHandle.create(context.graph, graphId);
|
|
29
|
+
if (!handle.success) {
|
|
30
|
+
return handle;
|
|
31
|
+
}
|
|
32
|
+
const graph = handle.result.graph();
|
|
33
|
+
|
|
34
|
+
const visualOnly = graph.metadata === metadata && !(title || description);
|
|
35
|
+
if (metadata) {
|
|
36
|
+
graph.metadata = metadata;
|
|
37
|
+
}
|
|
38
|
+
if (title) {
|
|
39
|
+
graph.title = title;
|
|
40
|
+
}
|
|
41
|
+
if (description) {
|
|
42
|
+
graph.description = description;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
visualOnly,
|
|
47
|
+
affectedNodes: [],
|
|
48
|
+
affectedModules: [],
|
|
49
|
+
affectedGraphs: [graphId],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
EditOperation,
|
|
10
|
+
EditOperationContext,
|
|
11
|
+
EditSpec,
|
|
12
|
+
InspectableGraph,
|
|
13
|
+
NodeIdentifier,
|
|
14
|
+
NodeMetadata,
|
|
15
|
+
SingleEditResult,
|
|
16
|
+
} from "@breadboard-ai/types";
|
|
17
|
+
import { errorNoInspect } from "./error.js";
|
|
18
|
+
|
|
19
|
+
export class ChangeMetadata implements EditOperation {
|
|
20
|
+
async can(
|
|
21
|
+
id: NodeIdentifier,
|
|
22
|
+
inspector: InspectableGraph
|
|
23
|
+
): Promise<SingleEditResult> {
|
|
24
|
+
const node = inspector.nodeById(id);
|
|
25
|
+
if (!node) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: `Unable to change metadata: node with id "${id}" does not exist`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
success: true,
|
|
33
|
+
affectedNodes: [],
|
|
34
|
+
affectedModules: [],
|
|
35
|
+
affectedGraphs: [],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#isVisualOnly(incoming: NodeMetadata, existing: NodeMetadata): boolean {
|
|
40
|
+
return (
|
|
41
|
+
existing.title === incoming.title &&
|
|
42
|
+
existing.description === incoming.description &&
|
|
43
|
+
existing.logLevel === incoming.logLevel
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async do(
|
|
48
|
+
spec: EditSpec,
|
|
49
|
+
context: EditOperationContext
|
|
50
|
+
): Promise<SingleEditResult> {
|
|
51
|
+
if (spec.type !== "changemetadata") {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Editor API integrity error: expected type "changemetadata", received "${spec.type}" instead.`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const { id, metadata, graphId, reset = false } = spec;
|
|
57
|
+
const { mutable } = context;
|
|
58
|
+
const inspector = mutable.graphs.get(graphId);
|
|
59
|
+
if (!inspector) {
|
|
60
|
+
return errorNoInspect(graphId);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const can = await this.can(id, inspector);
|
|
64
|
+
if (!can.success) return can;
|
|
65
|
+
const node = inspector.nodeById(id);
|
|
66
|
+
if (!node) {
|
|
67
|
+
const error = `Unknown node with id "${id}"`;
|
|
68
|
+
return { success: false, error };
|
|
69
|
+
}
|
|
70
|
+
const visualOnly = this.#isVisualOnly(
|
|
71
|
+
metadata,
|
|
72
|
+
node.descriptor.metadata || {}
|
|
73
|
+
);
|
|
74
|
+
const oldMetadata = node.descriptor.metadata;
|
|
75
|
+
if (reset) {
|
|
76
|
+
node.descriptor.metadata = metadata;
|
|
77
|
+
} else {
|
|
78
|
+
node.descriptor.metadata = {
|
|
79
|
+
...oldMetadata,
|
|
80
|
+
...metadata,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const affectedNodes = visualOnly ? [] : [{ id, graphId }];
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
visualOnly,
|
|
87
|
+
affectedNodes,
|
|
88
|
+
affectedModules: [],
|
|
89
|
+
affectedGraphs: [graphId],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|