@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.
Files changed (158) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/breadboard/data/common.d.ts +35 -0
  3. package/dist/breadboard/engine/loader/capability.d.ts +21 -0
  4. package/dist/breadboard/engine/loader/loader.d.ts +29 -0
  5. package/dist/breadboard/engine/loader/resolve-graph-urls.d.ts +16 -0
  6. package/dist/breadboard/engine/runtime/bubble.d.ts +23 -0
  7. package/dist/breadboard/engine/runtime/graph-based-node-handler.d.ts +16 -0
  8. package/dist/breadboard/engine/runtime/handler.d.ts +27 -0
  9. package/dist/breadboard/engine/runtime/harness/events.d.ts +145 -0
  10. package/dist/breadboard/engine/runtime/harness/local.d.ts +10 -0
  11. package/dist/breadboard/engine/runtime/harness/plan-runner.d.ts +25 -0
  12. package/dist/breadboard/engine/runtime/run/invoke-graph.d.ts +12 -0
  13. package/dist/breadboard/engine/runtime/run/node-invoker.d.ts +12 -0
  14. package/dist/breadboard/engine/runtime/run/run-graph.d.ts +12 -0
  15. package/dist/breadboard/engine/runtime/run.d.ts +29 -0
  16. package/dist/breadboard/engine/runtime/sandbox/capabilities-manager.d.ts +15 -0
  17. package/dist/breadboard/engine/runtime/sandbox/file-system-handler-factory.d.ts +15 -0
  18. package/dist/breadboard/engine/runtime/sandbox/invoke-describer.d.ts +10 -0
  19. package/dist/breadboard/engine/runtime/static/create-plan.d.ts +14 -0
  20. package/dist/breadboard/engine/runtime/static/orchestrator.d.ts +72 -0
  21. package/dist/breadboard/engine/runtime/traversal/index.d.ts +20 -0
  22. package/dist/breadboard/engine/runtime/traversal/iterator.d.ts +12 -0
  23. package/dist/breadboard/engine/runtime/traversal/machine.d.ts +14 -0
  24. package/dist/breadboard/engine/runtime/traversal/representation.d.ts +27 -0
  25. package/dist/breadboard/engine/runtime/traversal/result.d.ts +24 -0
  26. package/dist/breadboard/engine/runtime/traversal/state.d.ts +34 -0
  27. package/dist/breadboard/lit-flow-runner.d.ts +13 -0
  28. package/dist/breadboard/lit-flow-runner.test.d.ts +1 -0
  29. package/dist/breadboard/runner.d.ts +13 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/lit-chiclet.d.ts +9 -0
  32. package/dist/lit-schema-node.d.ts +13 -0
  33. package/dist/lit-schema-node.test.d.ts +1 -0
  34. package/dist/litflow.js +708 -442
  35. package/dist/litflow.js.map +1 -1
  36. package/package.json +18 -4
  37. package/src/breadboard/data/common.ts +450 -0
  38. package/src/breadboard/data/file-system.ts +54 -0
  39. package/src/breadboard/data/inline-all-content.ts +126 -0
  40. package/src/breadboard/data/recent-boards.ts +118 -0
  41. package/src/breadboard/data/save-outputs-as-file.ts +104 -0
  42. package/src/breadboard/engine/add-run-module.ts +168 -0
  43. package/src/breadboard/engine/editor/blank.ts +65 -0
  44. package/src/breadboard/engine/editor/edge.ts +27 -0
  45. package/src/breadboard/engine/editor/events.ts +64 -0
  46. package/src/breadboard/engine/editor/graph.ts +383 -0
  47. package/src/breadboard/engine/editor/history.ts +98 -0
  48. package/src/breadboard/engine/editor/index.ts +8 -0
  49. package/src/breadboard/engine/editor/operations/add-asset.ts +45 -0
  50. package/src/breadboard/engine/editor/operations/add-edge.ts +142 -0
  51. package/src/breadboard/engine/editor/operations/add-graph.ts +47 -0
  52. package/src/breadboard/engine/editor/operations/add-module.ts +64 -0
  53. package/src/breadboard/engine/editor/operations/add-node.ts +86 -0
  54. package/src/breadboard/engine/editor/operations/change-asset-metadata.ts +70 -0
  55. package/src/breadboard/engine/editor/operations/change-configuration.ts +82 -0
  56. package/src/breadboard/engine/editor/operations/change-edge-metadata.ts +58 -0
  57. package/src/breadboard/engine/editor/operations/change-edge.ts +111 -0
  58. package/src/breadboard/engine/editor/operations/change-graph-metadata.ts +52 -0
  59. package/src/breadboard/engine/editor/operations/change-metadata.ts +92 -0
  60. package/src/breadboard/engine/editor/operations/change-module.ts +64 -0
  61. package/src/breadboard/engine/editor/operations/error.ts +21 -0
  62. package/src/breadboard/engine/editor/operations/remove-asset.ts +48 -0
  63. package/src/breadboard/engine/editor/operations/remove-edge.ts +89 -0
  64. package/src/breadboard/engine/editor/operations/remove-graph.ts +49 -0
  65. package/src/breadboard/engine/editor/operations/remove-integration.ts +54 -0
  66. package/src/breadboard/engine/editor/operations/remove-module.ts +69 -0
  67. package/src/breadboard/engine/editor/operations/remove-node.ts +86 -0
  68. package/src/breadboard/engine/editor/operations/replace-graph.ts +52 -0
  69. package/src/breadboard/engine/editor/operations/toggle-export.ts +72 -0
  70. package/src/breadboard/engine/editor/operations/upsert-integration.ts +43 -0
  71. package/src/breadboard/engine/editor/selection.ts +58 -0
  72. package/src/breadboard/engine/editor/transforms/configure-sidewire.ts +73 -0
  73. package/src/breadboard/engine/editor/transforms/isolate-selection.ts +54 -0
  74. package/src/breadboard/engine/editor/transforms/merge-graph.ts +58 -0
  75. package/src/breadboard/engine/editor/transforms/move-to-graph.ts +102 -0
  76. package/src/breadboard/engine/editor/transforms/move-to-new-graph.ts +72 -0
  77. package/src/breadboard/engine/editor/transforms/sidewire-to-new-graph.ts +82 -0
  78. package/src/breadboard/engine/file-system/blob-transform.ts +44 -0
  79. package/src/breadboard/engine/file-system/composed-peristent-backend.ts +140 -0
  80. package/src/breadboard/engine/file-system/ephemeral-blob-store.ts +46 -0
  81. package/src/breadboard/engine/file-system/in-memory-blob-store.ts +87 -0
  82. package/src/breadboard/engine/file-system/index.ts +723 -0
  83. package/src/breadboard/engine/file-system/partial-persistent-backend.ts +109 -0
  84. package/src/breadboard/engine/file-system/path.ts +125 -0
  85. package/src/breadboard/engine/file-system/persistent-file.ts +66 -0
  86. package/src/breadboard/engine/file-system/readable-stream-file.ts +61 -0
  87. package/src/breadboard/engine/file-system/stub-file-system.ts +47 -0
  88. package/src/breadboard/engine/file-system/utils.ts +40 -0
  89. package/src/breadboard/engine/inspector/graph/bubbled-node.ts +162 -0
  90. package/src/breadboard/engine/inspector/graph/describe-cache.ts +78 -0
  91. package/src/breadboard/engine/inspector/graph/describe-type-cache.ts +48 -0
  92. package/src/breadboard/engine/inspector/graph/edge-cache.ts +118 -0
  93. package/src/breadboard/engine/inspector/graph/edge.ts +133 -0
  94. package/src/breadboard/engine/inspector/graph/event.ts +35 -0
  95. package/src/breadboard/engine/inspector/graph/exports-describer.ts +45 -0
  96. package/src/breadboard/engine/inspector/graph/graph-cache.ts +54 -0
  97. package/src/breadboard/engine/inspector/graph/graph-describer-manager.ts +338 -0
  98. package/src/breadboard/engine/inspector/graph/graph-descriptor-handle.ts +73 -0
  99. package/src/breadboard/engine/inspector/graph/graph-node-type.ts +111 -0
  100. package/src/breadboard/engine/inspector/graph/graph-queries.ts +256 -0
  101. package/src/breadboard/engine/inspector/graph/graph.ts +163 -0
  102. package/src/breadboard/engine/inspector/graph/inspectable-asset.ts +36 -0
  103. package/src/breadboard/engine/inspector/graph/kits.ts +208 -0
  104. package/src/breadboard/engine/inspector/graph/module.ts +69 -0
  105. package/src/breadboard/engine/inspector/graph/mutable-graph.ts +150 -0
  106. package/src/breadboard/engine/inspector/graph/node-cache.ts +123 -0
  107. package/src/breadboard/engine/inspector/graph/node-describer-manager.ts +279 -0
  108. package/src/breadboard/engine/inspector/graph/node-type-describer-manager.ts +122 -0
  109. package/src/breadboard/engine/inspector/graph/node.ts +149 -0
  110. package/src/breadboard/engine/inspector/graph/port-cache.ts +80 -0
  111. package/src/breadboard/engine/inspector/graph/ports.ts +292 -0
  112. package/src/breadboard/engine/inspector/graph/schemas.ts +131 -0
  113. package/src/breadboard/engine/inspector/graph/virtual-node.ts +184 -0
  114. package/src/breadboard/engine/inspector/graph-store.ts +629 -0
  115. package/src/breadboard/engine/inspector/index.ts +13 -0
  116. package/src/breadboard/engine/inspector/utils.ts +20 -0
  117. package/src/breadboard/engine/loader/capability.ts +184 -0
  118. package/src/breadboard/engine/loader/index.ts +14 -0
  119. package/src/breadboard/engine/loader/loader.ts +244 -0
  120. package/src/breadboard/engine/loader/resolve-graph-urls.ts +111 -0
  121. package/src/breadboard/engine/runtime/bubble.ts +269 -0
  122. package/src/breadboard/engine/runtime/graph-based-node-handler.ts +174 -0
  123. package/src/breadboard/engine/runtime/handler.ts +166 -0
  124. package/src/breadboard/engine/runtime/harness/diagnostics.ts +22 -0
  125. package/src/breadboard/engine/runtime/harness/events.ts +217 -0
  126. package/src/breadboard/engine/runtime/harness/index.ts +14 -0
  127. package/src/breadboard/engine/runtime/harness/local.ts +48 -0
  128. package/src/breadboard/engine/runtime/harness/plan-runner.ts +759 -0
  129. package/src/breadboard/engine/runtime/index.ts +8 -0
  130. package/src/breadboard/engine/runtime/legacy.ts +28 -0
  131. package/src/breadboard/engine/runtime/run/invoke-graph.ts +79 -0
  132. package/src/breadboard/engine/runtime/run/node-invoker.ts +137 -0
  133. package/src/breadboard/engine/runtime/run/run-graph.ts +186 -0
  134. package/src/breadboard/engine/runtime/run.ts +111 -0
  135. package/src/breadboard/engine/runtime/sandbox/capabilities-manager.ts +253 -0
  136. package/src/breadboard/engine/runtime/sandbox/file-system-handler-factory.ts +53 -0
  137. package/src/breadboard/engine/runtime/sandbox/invoke-describer.ts +125 -0
  138. package/src/breadboard/engine/runtime/static/condense.ts +155 -0
  139. package/src/breadboard/engine/runtime/static/create-plan.ts +134 -0
  140. package/src/breadboard/engine/runtime/static/nodes-to-subgraph.ts +168 -0
  141. package/src/breadboard/engine/runtime/static/orchestrator.ts +664 -0
  142. package/src/breadboard/engine/runtime/static/types.ts +77 -0
  143. package/src/breadboard/engine/runtime/traversal/index.ts +58 -0
  144. package/src/breadboard/engine/runtime/traversal/iterator.ts +124 -0
  145. package/src/breadboard/engine/runtime/traversal/machine.ts +58 -0
  146. package/src/breadboard/engine/runtime/traversal/representation.ts +115 -0
  147. package/src/breadboard/engine/runtime/traversal/result.ts +72 -0
  148. package/src/breadboard/engine/runtime/traversal/state.ts +115 -0
  149. package/src/breadboard/engine/telemetry.ts +121 -0
  150. package/src/breadboard/engine/types.ts +32 -0
  151. package/src/breadboard/lit-flow-runner.test.ts +44 -0
  152. package/src/breadboard/lit-flow-runner.ts +98 -0
  153. package/src/breadboard/runner.ts +80 -0
  154. package/src/index.ts +2 -0
  155. package/src/lit-chiclet.ts +69 -0
  156. package/src/lit-flow.ts +17 -7
  157. package/src/lit-schema-node.test.ts +65 -0
  158. package/src/lit-schema-node.ts +194 -0
@@ -0,0 +1,109 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2025 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import {
9
+ FileSystemPath,
10
+ FileSystemQueryResult,
11
+ FileSystemWriteResult,
12
+ LLMContent,
13
+ Outcome,
14
+ PersistentBackend,
15
+ } from "@breadboard-ai/types";
16
+ import { err } from "@breadboard-ai/utils";
17
+
18
+ export { PartialPersistentBackend };
19
+
20
+ class PartialPersistentBackend implements PersistentBackend {
21
+ constructor(private readonly backend: Partial<PersistentBackend>) {}
22
+
23
+ async query(
24
+ graphUrl: string,
25
+ path: FileSystemPath
26
+ ): Promise<FileSystemQueryResult> {
27
+ const result = this.backend.query?.(graphUrl, path);
28
+ if (!result) {
29
+ return err(`Method "query" not implemented`);
30
+ }
31
+ return result;
32
+ }
33
+
34
+ async read(
35
+ graphUrl: string,
36
+ path: FileSystemPath,
37
+ inflate: boolean
38
+ ): Promise<Outcome<LLMContent[]>> {
39
+ const result = this.backend.read?.(graphUrl, path, inflate);
40
+ if (!result) {
41
+ return err(`Method "read" not implemented`);
42
+ }
43
+ return result;
44
+ }
45
+
46
+ async write(
47
+ graphUrl: string,
48
+ path: FileSystemPath,
49
+ data: LLMContent[]
50
+ ): Promise<FileSystemWriteResult> {
51
+ const result = this.backend.write?.(graphUrl, path, data);
52
+ if (!result) {
53
+ return err(`Method "write" not implemented`);
54
+ }
55
+ return result;
56
+ }
57
+
58
+ async append(
59
+ graphUrl: string,
60
+ path: FileSystemPath,
61
+ data: LLMContent[]
62
+ ): Promise<FileSystemWriteResult> {
63
+ const result = this.backend.append?.(graphUrl, path, data);
64
+ if (!result) {
65
+ return err(`Method "append" not implemented`);
66
+ }
67
+ return result;
68
+ }
69
+
70
+ async delete(
71
+ graphUrl: string,
72
+ path: FileSystemPath,
73
+ all: boolean
74
+ ): Promise<FileSystemWriteResult> {
75
+ const result = this.backend.delete?.(graphUrl, path, all);
76
+ if (!result) {
77
+ return err(`Method "delete" not implemented`);
78
+ }
79
+ return result;
80
+ }
81
+
82
+ async copy(
83
+ graphUrl: string,
84
+ source: FileSystemPath,
85
+ destination: FileSystemPath
86
+ ): Promise<FileSystemWriteResult> {
87
+ const result = this.backend.copy?.(graphUrl, source, destination);
88
+ if (!result) {
89
+ return err(`Method "copy" not implemented`);
90
+ }
91
+ return result;
92
+ }
93
+
94
+ async move(
95
+ graphUrl: string,
96
+ source: FileSystemPath,
97
+ destination: FileSystemPath
98
+ ): Promise<FileSystemWriteResult> {
99
+ const result = this.backend.move?.(graphUrl, source, destination);
100
+ if (!result) {
101
+ return err(`Method "move" not implemented`);
102
+ }
103
+ return result;
104
+ }
105
+
106
+ async onEndRun(): Promise<void> {
107
+ return this.backend.onEndRun?.();
108
+ }
109
+ }
@@ -0,0 +1,125 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2024 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ FileSystemPath,
10
+ FileSystemReadWritePath,
11
+ Outcome,
12
+ } from "@breadboard-ai/types";
13
+ import { err, ok } from "@breadboard-ai/utils";
14
+
15
+ export { Path };
16
+
17
+ const PATH_SEPARATOR = "/";
18
+
19
+ type RootDirSpec = {
20
+ name: string;
21
+ writable: boolean;
22
+ /**
23
+ * Set to true when the files in this directory are persisted across the
24
+ * lifetime of the FileSystem instance. In other words, they aren't part
25
+ * of FileSystem's in-memory store.
26
+ */
27
+ persistent: boolean;
28
+ /**
29
+ * Set to true when the files in this directory come from mounted sources.
30
+ * These files might not actually be files, but rather file-shaped objects
31
+ * that the system supplies.
32
+ */
33
+ mounted: boolean;
34
+ };
35
+
36
+ const ROOT_DIRS: readonly RootDirSpec[] = [
37
+ { name: "local", writable: true, persistent: true, mounted: false },
38
+ { name: "mnt", writable: true, persistent: false, mounted: true },
39
+ { name: "session", writable: true, persistent: false, mounted: false },
40
+ { name: "run", writable: true, persistent: false, mounted: false },
41
+ { name: "tmp", writable: true, persistent: false, mounted: false },
42
+ { name: "env", writable: false, persistent: false, mounted: false },
43
+ { name: "assets", writable: false, persistent: false, mounted: false },
44
+ ] as const;
45
+
46
+ export function writablePathFromString(
47
+ s: string
48
+ ): Outcome<FileSystemReadWritePath> {
49
+ const path = Path.create(s as FileSystemPath);
50
+ if (!ok(path)) return path;
51
+ if (!path.writable) {
52
+ return err(`Path "${s}" is not writable`);
53
+ }
54
+ return s as FileSystemReadWritePath;
55
+ }
56
+
57
+ class Path {
58
+ static roots = new Set(ROOT_DIRS.map((item) => item.name));
59
+ static writableRoots = new Set(
60
+ ROOT_DIRS.filter((item) => item.writable).map((item) => item.name)
61
+ );
62
+ static persistentRoots = new Set(
63
+ ROOT_DIRS.filter((item) => item.persistent).map((item) => item.name)
64
+ );
65
+ static mountedRoots = new Set(
66
+ ROOT_DIRS.filter((item) => item.mounted).map((item) => item.name)
67
+ );
68
+
69
+ readonly writable: boolean;
70
+ readonly persistent: boolean;
71
+ readonly mounted: boolean;
72
+
73
+ constructor(
74
+ public readonly root: string,
75
+ public readonly path: string[],
76
+ public readonly dir: boolean
77
+ ) {
78
+ this.writable = Path.writableRoots.has(this.root);
79
+ this.persistent = Path.persistentRoots.has(this.root);
80
+ this.mounted = Path.mountedRoots.has(this.root);
81
+ }
82
+
83
+ static createRoots(): Path[] {
84
+ return ROOT_DIRS.map((item) => {
85
+ return new Path(item.name, [], true);
86
+ });
87
+ }
88
+
89
+ static create(path: FileSystemPath): Outcome<Path> {
90
+ const components = path.split(PATH_SEPARATOR);
91
+ const [leading, root, ...rest] = components;
92
+ const isDir = rest.at(-1)?.length === 0;
93
+
94
+ const validationResult = validate();
95
+ if (!ok(validationResult)) {
96
+ return validationResult;
97
+ }
98
+ return new Path(root, isDir ? rest.slice(0, -1) : rest, isDir);
99
+
100
+ function validate(): Outcome<void> {
101
+ if (leading.length !== 0)
102
+ return {
103
+ $error: `Invalid path "${path}": all paths must start with a slash`,
104
+ };
105
+ if (!Path.roots.has(root))
106
+ return {
107
+ $error: `Invalid path "${path}": unknown root directory`,
108
+ };
109
+ if (rest.length === 0)
110
+ return {
111
+ $error: `Invalid path "${path}": when pointing at a root directory, add a slash`,
112
+ };
113
+ for (const [i, fragment] of rest.entries()) {
114
+ if (fragment.length === 0) {
115
+ // Only last fragment can be empty (trailing slash)
116
+ if (i !== rest.length - 1) {
117
+ return {
118
+ $error: `Invalid path "${path}": paths may not contain empty fragments`,
119
+ };
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
@@ -0,0 +1,66 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2024 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ FileSystemFile,
10
+ FileSystemPath,
11
+ FileSystemQueryEntry,
12
+ FileSystemReadResult,
13
+ FileSystemWriteResult,
14
+ LLMContent,
15
+ Outcome,
16
+ PersistentBackend,
17
+ } from "@breadboard-ai/types";
18
+ import { ok } from "@breadboard-ai/utils";
19
+ import { noStreams, readFromStart } from "./utils.js";
20
+
21
+ export { PersistentFile };
22
+
23
+ class PersistentFile implements FileSystemFile {
24
+ constructor(
25
+ public readonly graphUrl: string,
26
+ public readonly path: FileSystemPath,
27
+ public readonly backend: PersistentBackend
28
+ ) {}
29
+
30
+ async read(
31
+ inflate: boolean,
32
+ start: number = 0
33
+ ): Promise<FileSystemReadResult> {
34
+ const reading = await this.backend.read(this.graphUrl, this.path, inflate);
35
+ if (!ok(reading)) {
36
+ return reading;
37
+ }
38
+ return readFromStart(this.path, reading, start);
39
+ }
40
+
41
+ async append(
42
+ data: LLMContent[],
43
+ done: boolean,
44
+ receipt?: boolean
45
+ ): Promise<FileSystemWriteResult> {
46
+ const checkForStreams = noStreams(done, receipt);
47
+ if (!ok(checkForStreams)) {
48
+ return checkForStreams;
49
+ }
50
+ return this.backend.append(this.graphUrl, this.path, data);
51
+ }
52
+
53
+ copy(): Outcome<FileSystemFile> {
54
+ throw new Error("Method not implemented.");
55
+ }
56
+
57
+ queryEntry(_path: FileSystemPath): FileSystemQueryEntry {
58
+ throw new Error("Method not implemented.");
59
+ }
60
+
61
+ delete(): Promise<FileSystemWriteResult> {
62
+ throw new Error("Method not implemented.");
63
+ }
64
+
65
+ data: LLMContent[] = [];
66
+ }
@@ -0,0 +1,61 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2025 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ FileSystemFile,
10
+ FileSystemPath,
11
+ FileSystemQueryEntry,
12
+ FileSystemReadResult,
13
+ FileSystemWriteResult,
14
+ LLMContent,
15
+ Outcome,
16
+ } from "@breadboard-ai/types";
17
+ import { err } from "@breadboard-ai/utils";
18
+
19
+ export { ReadableStreamFile };
20
+
21
+ class ReadableStreamFile implements FileSystemFile {
22
+ readonly data: LLMContent[] = [];
23
+
24
+ constructor(public readonly stream: ReadableStream<LLMContent>) {}
25
+
26
+ async read(_inflate: boolean, start?: number): Promise<FileSystemReadResult> {
27
+ if (start !== undefined && start !== 0) {
28
+ return err(`Reading partial streams is not supported.`);
29
+ }
30
+
31
+ const reader = this.stream.getReader();
32
+ try {
33
+ const { value, done } = await reader.read();
34
+ return { data: value ? [value] : [], done };
35
+ } catch (e) {
36
+ const error = e as Error;
37
+ if (error.name === "AbortError") {
38
+ return err(`Run stopped`);
39
+ }
40
+ return err(`Unable to read stream: ${(e as Error).message}`);
41
+ } finally {
42
+ reader.releaseLock();
43
+ }
44
+ }
45
+
46
+ async append(): Promise<Outcome<void>> {
47
+ return err(`Can't write to a read-only stream`);
48
+ }
49
+
50
+ copy(): Outcome<FileSystemFile> {
51
+ return err(`Copying read-only streams is not supported`);
52
+ }
53
+
54
+ queryEntry(path: FileSystemPath): FileSystemQueryEntry {
55
+ return { path, length: 0, stream: true };
56
+ }
57
+
58
+ async delete(): Promise<FileSystemWriteResult> {
59
+ this.stream.cancel().catch(() => {});
60
+ }
61
+ }
@@ -0,0 +1,47 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2025 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ FileSystem,
10
+ FileSystemEntry,
11
+ FileSystemQueryResult,
12
+ FileSystemReadResult,
13
+ FileSystemWriteResult,
14
+ Outcome,
15
+ } from "@breadboard-ai/types";
16
+
17
+ export { StubFileSystem };
18
+
19
+ class StubFileSystem implements FileSystem {
20
+ query(): Promise<FileSystemQueryResult> {
21
+ throw new Error("Attempting to use stubbed-out file system.");
22
+ }
23
+ read(): Promise<FileSystemReadResult> {
24
+ throw new Error("Attempting to use stubbed-out file system.");
25
+ }
26
+ write(): Promise<FileSystemWriteResult> {
27
+ throw new Error("Attempting to use stubbed-out file system.");
28
+ }
29
+ addStream(): Promise<Outcome<void>> {
30
+ throw new Error("Attempting to use stubbed-out file system.");
31
+ }
32
+ close(): Promise<void> {
33
+ throw new Error("Attempting to use stubbed-out file system.");
34
+ }
35
+ updateRunFileSystem(): FileSystem {
36
+ throw new Error("Attempting to use stubbed-out file system.");
37
+ }
38
+ createRunFileSystem(): FileSystem {
39
+ throw new Error("Attempting to use stubbed-out file system.");
40
+ }
41
+ createModuleFileSystem(): FileSystem {
42
+ throw new Error("Attempting to use stubbed-out file system.");
43
+ }
44
+ env(): FileSystemEntry[] {
45
+ throw new Error("Attempting to use stubbed-out file system.");
46
+ }
47
+ }
@@ -0,0 +1,40 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2024 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ FileSystemPath,
10
+ FileSystemReadResult,
11
+ FileSystemWriteResult,
12
+ LLMContent,
13
+ } from "@breadboard-ai/types";
14
+ import { err } from "@breadboard-ai/utils";
15
+
16
+ export { noStreams, readFromStart };
17
+
18
+ function readFromStart(
19
+ path: FileSystemPath,
20
+ data: LLMContent[] | undefined,
21
+ start: number
22
+ ): FileSystemReadResult {
23
+ if (!data) {
24
+ return err(`File at "${path}" is empty`);
25
+ }
26
+
27
+ if (start >= data.length) {
28
+ return err(`Length of file is lesser than start "${start}"`);
29
+ }
30
+ return {
31
+ data: data.slice(start),
32
+ last: data.length - 1,
33
+ };
34
+ }
35
+
36
+ function noStreams(done: boolean, receipt?: boolean): FileSystemWriteResult {
37
+ if (done || receipt) {
38
+ return err("Can't close the file that isn't a stream");
39
+ }
40
+ }
@@ -0,0 +1,162 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2024 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ InputValues,
10
+ InspectableEdge,
11
+ InspectableNode,
12
+ InspectableNodePorts,
13
+ InspectableNodeType,
14
+ InspectablePortList,
15
+ NodeConfiguration,
16
+ NodeDescriberResult,
17
+ NodeDescriptor,
18
+ NodeMetadata,
19
+ OutputValues,
20
+ } from "@breadboard-ai/types";
21
+ import { filterBySchema } from "@breadboard-ai/utils";
22
+ import { collectPorts } from "./ports.js";
23
+ import { EdgeType, describeInput } from "./schemas.js";
24
+
25
+ /**
26
+ * This is a special kind of an `InspectableNode`, representing a bubbled
27
+ * node instance. Its key difference is that, when it's type = input,
28
+ * it will narrow down the ports and values to only the ones that bubbled up.
29
+ * For instance, the actual input node might have four parameters, but
30
+ * only one of them bubbled up. This node will make sure that it looks as if
31
+ * it only has that one parameter.
32
+ */
33
+ export class BubbledInspectableNode implements InspectableNode {
34
+ descriptor: NodeDescriptor;
35
+ #actual: InspectableNode;
36
+
37
+ constructor(actual: InspectableNode) {
38
+ const descriptor = actual.descriptor;
39
+ if (descriptor.type !== "input" && descriptor.type !== "output") {
40
+ throw new Error(
41
+ "BubbledInspectableNode can only be an input or an output"
42
+ );
43
+ }
44
+ this.#actual = actual;
45
+ this.descriptor = descriptor;
46
+ }
47
+
48
+ title(): string {
49
+ return this.#actual.title();
50
+ }
51
+
52
+ description(): string {
53
+ return this.#actual.description();
54
+ }
55
+
56
+ incoming(): InspectableEdge[] {
57
+ return this.#actual.incoming();
58
+ }
59
+
60
+ outgoing(): InspectableEdge[] {
61
+ return this.#actual.outgoing();
62
+ }
63
+
64
+ isEntry(): boolean {
65
+ return this.#actual.isEntry();
66
+ }
67
+
68
+ isExit(): boolean {
69
+ return this.#actual.isExit();
70
+ }
71
+
72
+ isStart(): boolean {
73
+ return this.#actual.isStart();
74
+ }
75
+
76
+ type(): InspectableNodeType {
77
+ return this.#actual.type();
78
+ }
79
+
80
+ configuration(): NodeConfiguration {
81
+ return this.#actual.configuration();
82
+ }
83
+
84
+ metadata(): NodeMetadata {
85
+ return this.#actual.metadata();
86
+ }
87
+
88
+ async describe(): Promise<NodeDescriberResult> {
89
+ if (this.descriptor.type === "input") {
90
+ return describeInput({ inputs: this.#actual.configuration() });
91
+ }
92
+ return this.#actual.describe();
93
+ }
94
+
95
+ currentDescribe(): NodeDescriberResult {
96
+ if (this.descriptor.type === "input") {
97
+ return describeInput({ inputs: this.#actual.configuration() });
98
+ }
99
+
100
+ return this.#actual.currentDescribe();
101
+ }
102
+
103
+ #portsForInput(inputValues?: InputValues, outputValues?: OutputValues) {
104
+ const described = describeInput({ inputs: inputValues });
105
+
106
+ const bubbledValues = filterBySchema(
107
+ outputValues || {},
108
+ described.outputSchema
109
+ );
110
+ const inputs: InspectablePortList = {
111
+ fixed: described.inputSchema.additionalProperties === false,
112
+ ports: collectPorts(
113
+ EdgeType.In,
114
+ this.incoming(),
115
+ described.inputSchema,
116
+ false,
117
+ true,
118
+ inputValues
119
+ ),
120
+ };
121
+ const outputs: InspectablePortList = {
122
+ fixed: described.outputSchema.additionalProperties === false,
123
+ ports: collectPorts(
124
+ EdgeType.Out,
125
+ [],
126
+ described.outputSchema,
127
+ false,
128
+ false,
129
+ bubbledValues
130
+ ),
131
+ };
132
+ const side: InspectablePortList = {
133
+ fixed: true,
134
+ ports: [],
135
+ };
136
+ return { inputs, outputs, side, updating: false };
137
+ }
138
+
139
+ async ports(
140
+ inputValues?: InputValues | undefined,
141
+ outputValues?: OutputValues | undefined
142
+ ): Promise<InspectableNodePorts> {
143
+ if (this.descriptor.type === "input") {
144
+ return this.#portsForInput(inputValues, outputValues);
145
+ }
146
+ return this.#actual.ports(inputValues, outputValues || undefined);
147
+ }
148
+
149
+ currentPorts(
150
+ inputValues?: InputValues,
151
+ outputValues?: OutputValues
152
+ ): InspectableNodePorts {
153
+ if (this.descriptor.type === "input") {
154
+ return this.#portsForInput(inputValues, outputValues);
155
+ }
156
+ return this.#actual.currentPorts(inputValues, outputValues);
157
+ }
158
+
159
+ deleted(): boolean {
160
+ return this.#actual.deleted();
161
+ }
162
+ }
@@ -0,0 +1,78 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @license
4
+ * Copyright 2024 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ import type {
9
+ AffectedNode,
10
+ DescribeResultCacheArgs,
11
+ GraphIdentifier,
12
+ InspectableDescriberResultCache,
13
+ InspectableDescriberResultCacheEntry,
14
+ NodeDescriberResult,
15
+ NodeIdentifier,
16
+ } from "@breadboard-ai/types";
17
+ import {
18
+ hash,
19
+ SnapshotUpdater,
20
+ SnapshotUpdaterArgs,
21
+ } from "@breadboard-ai/utils";
22
+
23
+ export { DescribeResultCache };
24
+
25
+ type MapItem = SnapshotUpdater<NodeDescriberResult>;
26
+
27
+ class DescribeResultCache implements InspectableDescriberResultCache {
28
+ #map = new Map<number, MapItem>();
29
+
30
+ constructor(public readonly args: DescribeResultCacheArgs) {}
31
+
32
+ #createSnapshotArgs(graphId: GraphIdentifier, nodeId: NodeIdentifier) {
33
+ return {
34
+ initial: () => this.args.initial(graphId, nodeId),
35
+ latest: () => this.args.latest(graphId, nodeId),
36
+ willUpdate: (previous, current) =>
37
+ this.args.willUpdate(previous, current),
38
+ updated: () => {
39
+ this.args.updated(graphId, nodeId);
40
+ },
41
+ } as SnapshotUpdaterArgs<NodeDescriberResult>;
42
+ }
43
+
44
+ get(
45
+ id: NodeIdentifier,
46
+ graphId: GraphIdentifier
47
+ ): InspectableDescriberResultCacheEntry {
48
+ const hash = computeHash({ id, graphId });
49
+ let result = this.#map.get(hash);
50
+ if (result) {
51
+ return result.snapshot();
52
+ }
53
+ result = new SnapshotUpdater(this.#createSnapshotArgs(graphId, id));
54
+ this.#map.set(hash, result);
55
+ return result.snapshot();
56
+ }
57
+
58
+ update(affectedNodes: AffectedNode[]) {
59
+ affectedNodes.forEach((affected) => {
60
+ const hash = computeHash(affected);
61
+ this.#map.get(hash)?.refresh();
62
+ });
63
+ }
64
+
65
+ clear(visualOnly: boolean, affectedNodes: AffectedNode[]) {
66
+ if (visualOnly) {
67
+ return;
68
+ }
69
+ affectedNodes.forEach((node) => {
70
+ const hash = computeHash(node);
71
+ this.#map.delete(hash);
72
+ });
73
+ }
74
+ }
75
+
76
+ function computeHash(node: AffectedNode): number {
77
+ return hash(node);
78
+ }