diff --git a/.yarn/cache/@exadev-breadboard-kits-npm-0.9.0-97ea563a9b-1f577b7364.zip b/.yarn/cache/@exadev-breadboard-kits-npm-0.9.1-a61b87c9a2-23cf4794fd.zip similarity index 99% rename from .yarn/cache/@exadev-breadboard-kits-npm-0.9.0-97ea563a9b-1f577b7364.zip rename to .yarn/cache/@exadev-breadboard-kits-npm-0.9.1-a61b87c9a2-23cf4794fd.zip index 038653a..e476fb2 100644 Binary files a/.yarn/cache/@exadev-breadboard-kits-npm-0.9.0-97ea563a9b-1f577b7364.zip and b/.yarn/cache/@exadev-breadboard-kits-npm-0.9.1-a61b87c9a2-23cf4794fd.zip differ diff --git a/.yarn/cache/@xenova-transformers-npm-2.11.0-3f962b83d2-d95d513f52.zip b/.yarn/cache/@xenova-transformers-npm-2.11.0-3f962b83d2-d95d513f52.zip new file mode 100644 index 0000000..b439340 Binary files /dev/null and b/.yarn/cache/@xenova-transformers-npm-2.11.0-3f962b83d2-d95d513f52.zip differ diff --git a/README.md b/README.md index b171823..ac8913a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Breadboard Samples -This repository contains sample code for the [Breadboard](https://github.com/google/labs-prototypes) project. +This repository contains sample code for the [Breadboard](https://github.com/breadboard-ai/breadboard/) project. They will demonstrate how to build complex LLM applications that can be run in the browser and be used for a number of use cases such as: diff --git a/samples/Breadboard Walkthrough/README.md b/samples/Breadboard Walkthrough/README.md index c6b09d0..5f45301 100644 --- a/samples/Breadboard Walkthrough/README.md +++ b/samples/Breadboard Walkthrough/README.md @@ -11,5 +11,6 @@ 9. [Arrow Directions](./src/arrow-directions/README.md) 10. [Custom Kit Node Values and Handlers](./src/custom-kit-node-values-and-handlers/README.md) 11. [Include Board as a Node](./src/include-board-as-a-node/README.md) -12. [Adding Slot to a Board](./src/adding-slot-to-a-board/README.md) -13. [Adding Slot to a Board with JSON](./src/adding-slot-to-a-board-with-json/README.md) \ No newline at end of file +12. [Include Board as a Node with URL](./src/include-board-as-a-node-with-url/README.md) +13. [Adding Slot to a Board](./src/adding-slot-to-a-board/README.md) +14. [Adding Slot to a Board with URL](./src/adding-slot-to-a-board-with-url/README.md) \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/package.json b/samples/Breadboard Walkthrough/package.json index 6704dea..fe2bf09 100644 --- a/samples/Breadboard Walkthrough/package.json +++ b/samples/Breadboard Walkthrough/package.json @@ -1,13 +1,13 @@ { "dependencies": { - "@exadev/breadboard-kits": "^0.8.3", - "@google-labs/breadboard": "^0.5.1" + "@exadev/breadboard-kits": "^0.9.1", + "@google-labs/breadboard": "^0.6.0" }, "devDependencies": { - "@types/node": "^20.9.3", + "@types/node": "^20.10.4", "npm-run-all": "^4.1.5", - "tsx": "^4.2.0", - "typescript": "^5.3.2" + "tsx": "^4.6.2", + "typescript": "^5.3.3" }, "engines": { "node": ">=19" @@ -15,24 +15,36 @@ "engineStrict": true, "name": "breadboard-walkthrough", "scripts": { + "run-adding-slot-to-a-board": "tsx src/adding-slot-to-a-board/index.ts", + "run-adding-slot-to-a-board-with-url": "tsx src/adding-slot-to-a-board-with-url/index.ts", + "run-arrow-directions": "tsx src/arrow-directions/index.ts", + "run-custom-kit-node-values-and-handlers": "tsx src/custom-kit-node-values-and-handlers/index.ts", + "run-hello-world": "tsx src/hello-world/index.ts", + "run-include-board-as-a-node": "tsx src/include-board-as-a-node/index.ts", + "run-include-board-as-a-node-with-url": "tsx src/include-board-as-a-node-with-url/index.ts", + "run-multiple-inputs": "tsx src/multiple-inputs/index.ts", + "run-multiple-inputs-one-output": "tsx src/multiple-inputs-one-output/index.ts", + "run-multiple-outputs": "tsx src/multiple-outputs/index.ts", + "run-naming-wiring-parameters": "tsx src/naming-wiring-parameters/index.ts", + "run-nodes-by-id": "tsx src/nodes-by-id/index.ts", + "run-one-input-multiple-outputs": "tsx src/one-input-multiple-outputs/index.ts", + "run-specific-outputs": "tsx src/specific-outputs/index.ts", "start": "npm-run-all --print-name --serial 'run-*'", "watch": "npm-run-all --print-name --parallel 'watch-*'", - "run-arrow-directions": "tsx src/arrow-directions/index.ts", + "watch-adding-slot-to-a-board": "tsx watch src/adding-slot-to-a-board/index.ts", + "watch-adding-slot-to-a-board-with-url": "tsx watch src/adding-slot-to-a-board-with-url/index.ts", "watch-arrow-directions": "tsx watch src/arrow-directions/index.ts", - "run-hello-world": "tsx src/hello-world/index.ts", + "watch-custom-kit-node-values-and-handlers": "tsx watch src/custom-kit-node-values-and-handlers/index.ts", "watch-hello-world": "tsx watch src/hello-world/index.ts", - "run-multiple-inputs": "tsx src/multiple-inputs/index.ts", + "watch-include-board-as-a-node": "tsx watch src/include-board-as-a-node/index.ts", + "watch-include-board-as-a-node-with-url": "tsx watch src/include-board-as-a-node-with-url/index.ts", "watch-multiple-inputs": "tsx watch src/multiple-inputs/index.ts", - "run-multiple-outputs": "tsx src/multiple-outputs/index.ts", + "watch-multiple-inputs-one-output": "tsx watch src/multiple-inputs-one-output/index.ts", "watch-multiple-outputs": "tsx watch src/multiple-outputs/index.ts", - "run-specific-outputs": "tsx src/specific-outputs/index.ts", - "watch-specific-outputs": "tsx watch src/specific-outputs/index.ts", - "run-nodes-by-id": "tsx src/nodes-by-id/index.ts", + "watch-naming-wiring-parameters": "tsx watch src/naming-wiring-parameters/index.ts", "watch-nodes-by-id": "tsx watch src/nodes-by-id/index.ts", - "run-one-input-multiple-outputs": "tsx src/one-input-multiple-outputs/index.ts", "watch-one-input-multiple-outputs": "tsx watch src/one-input-multiple-outputs/index.ts", - "run-multiple-inputs-one-output": "tsx src/multiple-inputs-one-output/index.ts", - "watch-multiple-inputs-one-output": "tsx watch src/multiple-inputs-one-output/index.ts" + "watch-specific-outputs": "tsx watch src/specific-outputs/index.ts" }, "type": "module" } diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-json/index.ts b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-json/index.ts deleted file mode 100644 index 90285b0..0000000 --- a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-json/index.ts +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env npx -y tsx - -import { Board } from "@google-labs/breadboard"; -import { Core } from "@google-labs/core-kit"; -import fs from "fs"; -import * as url from "url"; -import writeMarkdown from "@exadev/breadboard-kits/util/files/writeMarkdown"; -import path from "path"; - -(async () => { - const main: Board = new Board({ - title: "Adding Slot to a Board", - }); - - const core = main.addKit(Core); - - main - .input({ - $id: "mainInputNode", - }) - .wire( - "mainInput->nestedInput", - core - .slot({ slot: "nested" }) - .wire( - "nestedOutput", - main.output({ $id: "mainOutputNode" }) - ) - ); - - const nested = new Board({ - title: "Nested Board to be Slotted", - }); - - nested - .input({ - $id: "nestedInputNode", - }) - .wire( - "nestedInput->nestedOutput", - nested.output({ $id: "nestedOutputNode" }) - ); - - const filepath = path.resolve("mainboard.json"); - fs.writeFileSync(filepath, JSON.stringify(main, null, "\t")); - - const board = await Board.load(filepath, { - slotted: { nested } - }); - - writeMarkdown({ - filename: "README", - markdown: ["```mermaid", `${board.mermaid()}`, "```"].join("\n"), - dir: url.fileURLToPath(new URL(".", import.meta.url)), - }); - - for await (const runResult of board.run({ - slots: {}, - kits: [core], - })) { - if (runResult.type === "input") { - runResult.inputs = { - mainInput: "Hello World!", - }; - } else if (runResult.type === "output") { - console.log(runResult.node.id, runResult.outputs); - } - } -})(); \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-json/README.md b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/README.md similarity index 100% rename from samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-json/README.md rename to samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/README.md diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/board.json b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/board.json new file mode 100644 index 0000000..1c1d294 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/board.json @@ -0,0 +1,36 @@ +{ + "url": "https://raw.githubusercontent.com/ExaDev-io/breadboard-samples/develop/samples/Breadboard%20Walkthrough/src/adding-slot-to-a-board-with-url/mainboard.json", + "title": "Adding Slot to a Board with URL", + "edges": [ + { + "from": "slot-1", + "to": "mainOutputNode", + "out": "nestedOutput", + "in": "nestedOutput" + }, + { + "from": "mainInputNode", + "to": "slot-1", + "out": "mainInput", + "in": "nestedInput" + } + ], + "nodes": [ + { + "id": "mainInputNode", + "type": "input" + }, + { + "id": "slot-1", + "type": "slot", + "configuration": { + "slot": "nested" + } + }, + { + "id": "mainOutputNode", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/index.ts b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/index.ts new file mode 100644 index 0000000..5561ad8 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/index.ts @@ -0,0 +1,67 @@ +#!/usr/bin/env npx -y tsx + +import writeMarkdown from "@exadev/breadboard-kits/util/files/writeMarkdown"; +import { asRuntimeKit, Board } from "@google-labs/breadboard"; +import { Core } from "@google-labs/core-kit"; +import * as url from "url"; +import fs from "fs"; + +/* + Slot has now been deprecated. +*/ +(async () => { + const BASE = "https://raw.githubusercontent.com"; + const OWNER = "ExaDev-io"; + const REPO = "breadboard-samples"; + const BRANCH = "develop"; + const PATH = + "samples/Breadboard%20Walkthrough/src/adding-slot-to-a-board-with-url"; + + const MAIN_BOARD_URL = [ + BASE, + OWNER, + REPO, + BRANCH, + PATH, + "mainboard.json", + ].join("/"); + + const NESTED_BOARD_URL = [ + BASE, + OWNER, + REPO, + BRANCH, + PATH, + "nestedboard.json", + ].join("/"); + + const nested = await Board.load(NESTED_BOARD_URL); + + const board = await Board.load(MAIN_BOARD_URL, { + slotted: { nested }, + }); + + writeMarkdown({ + filename: "README", + markdown: ["```mermaid", `${board.mermaid()}`, "```"].join("\n"), + dir: url.fileURLToPath(new URL(".", import.meta.url)), + }); + + for await (const run of board.run({ + slots: {}, + kits: [asRuntimeKit(Core)], // The kit needs to be passed because the JSON only contains an identifier of the kit and not the logic + })) { + if (run.type === "input") { + run.inputs = { + mainInput: "Hello World!", + }; + } else if (run.type === "output") { + console.log(run.node.id, run.outputs); + } + } + + fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") + ); +})(); \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/mainboard.json b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/mainboard.json new file mode 100644 index 0000000..e03a084 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/mainboard.json @@ -0,0 +1,39 @@ +{ + "title":"Adding Slot to a Board with URL", + "edges":[ + { + "from":"slot-1", + "to":"mainOutputNode", + "out":"nestedOutput", + "in":"nestedOutput" + }, + { + "from":"mainInputNode", + "to":"slot-1", + "out":"mainInput", + "in":"nestedInput" + } + ], + "nodes":[ + { + "id":"mainInputNode", + "type":"input" + }, + { + "id":"slot-1", + "type":"slot", + "configuration":{ + "slot":"nested" + } + }, + { + "id":"mainOutputNode", + "type":"output" + } + ], + "kits":[ + { + "url":"npm:@google-labs/core-kit" + } + ] + } \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/nestedboard.json b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/nestedboard.json new file mode 100644 index 0000000..e5d301c --- /dev/null +++ b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board-with-url/nestedboard.json @@ -0,0 +1,22 @@ +{ + "title": "Nested Board", + "edges": [ + { + "from": "nestedInputNode", + "to": "nestedOutputNode", + "out": "nestedInput", + "in": "nestedOutput" + } + ], + "nodes": [ + { + "id": "nestedInputNode", + "type": "input" + }, + { + "id": "nestedOutputNode", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/board.json b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/board.json new file mode 100644 index 0000000..b407fb2 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/board.json @@ -0,0 +1,39 @@ +{ + "title": "Adding Slot to a Board", + "edges": [ + { + "from": "slot-1", + "to": "mainOutputNode", + "out": "nestedOutput", + "in": "nestedOutput" + }, + { + "from": "mainInputNode", + "to": "slot-1", + "out": "mainInput", + "in": "nestedInput" + } + ], + "nodes": [ + { + "id": "mainInputNode", + "type": "input" + }, + { + "id": "slot-1", + "type": "slot", + "configuration": { + "slot": "nested" + } + }, + { + "id": "mainOutputNode", + "type": "output" + } + ], + "kits": [ + { + "url": "npm:@google-labs/core-kit" + } + ] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/index.ts b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/index.ts index 8f8f474..948c397 100644 --- a/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/index.ts +++ b/samples/Breadboard Walkthrough/src/adding-slot-to-a-board/index.ts @@ -3,7 +3,12 @@ import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; import { Board } from "@google-labs/breadboard"; import { Core } from "@google-labs/core-kit"; +import fs from "fs"; +import * as url from "url"; +/* + Slot has now been deprecated. +*/ const board: Board = new Board({ title: "Adding Slot to a Board", }); @@ -50,10 +55,14 @@ nested } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/arrow-directions/board.json b/samples/Breadboard Walkthrough/src/arrow-directions/board.json new file mode 100644 index 0000000..3f2596f --- /dev/null +++ b/samples/Breadboard Walkthrough/src/arrow-directions/board.json @@ -0,0 +1,34 @@ +{ + "title": "Arrow Directions", + "edges": [ + { + "from": "input-2", + "to": "output-1", + "out": "inputPartOne", + "in": "inputPartOne" + }, + { + "from": "input-2", + "to": "output-1", + "out": "inputPartTwo", + "in": "inputPartTwo" + }, + { + "from": "input-2", + "to": "output-1", + "out": "inputPartThree", + "in": "inputPartThree" + } + ], + "nodes": [ + { + "id": "output-1", + "type": "output" + }, + { + "id": "input-2", + "type": "input" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/arrow-directions/index.ts b/samples/Breadboard Walkthrough/src/arrow-directions/index.ts index 7730908..0a785ed 100644 --- a/samples/Breadboard Walkthrough/src/arrow-directions/index.ts +++ b/samples/Breadboard Walkthrough/src/arrow-directions/index.ts @@ -2,9 +2,11 @@ import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Arrow Directions" + title: "Arrow Directions", }); const output = board.output(); @@ -23,7 +25,7 @@ output.wire("<-inputPartThree", input); run.inputs = { inputPartOne: "Welcome", inputPartTwo: "To", - inputPartThree: "Breadboard!" + inputPartThree: "Breadboard!", }; } else if (run.type === "output") { console.log(run.outputs); @@ -31,10 +33,14 @@ output.wire("<-inputPartThree", input); } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/board.json b/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/board.json new file mode 100644 index 0000000..8143e6d --- /dev/null +++ b/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/board.json @@ -0,0 +1,82 @@ +{ + "title": "Custom Kit Node Values and Handlers Demo", + "edges": [ + { + "from": "inputNode", + "to": "echo-1", + "out": "inputPartOne", + "in": "inputPartOne" + }, + { + "from": "echo-1", + "to": "echoOutput", + "out": "inputPartOne", + "in": "echoedInput" + }, + { + "from": "inputNode", + "to": "concat-2", + "out": "inputPartOne", + "in": "a" + }, + { + "from": "inputNode", + "to": "concat-2", + "out": "inputPartTwo", + "in": "b" + }, + { + "from": "concat-2", + "to": "concatOutput", + "out": "value", + "in": "concatenatedInput" + }, + { + "from": "inputNode", + "to": "split-3", + "out": "inputPartThree", + "in": "input" + }, + { + "from": "split-3", + "to": "splitOutput", + "out": "value", + "in": "splitInput" + } + ], + "nodes": [ + { + "id": "echo-1", + "type": "echo" + }, + { + "id": "concat-2", + "type": "concat" + }, + { + "id": "split-3", + "type": "split" + }, + { + "id": "inputNode", + "type": "input" + }, + { + "id": "echoOutput", + "type": "output" + }, + { + "id": "concatOutput", + "type": "output" + }, + { + "id": "splitOutput", + "type": "output" + } + ], + "kits": [ + { + "url": "npm:my-custom-kit" + } + ] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/custom-kit-node-values-and-handlers.ts b/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/custom-kit-node-values-and-handlers.ts index 43aa649..1fb580a 100644 --- a/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/custom-kit-node-values-and-handlers.ts +++ b/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/custom-kit-node-values-and-handlers.ts @@ -4,13 +4,13 @@ import { KitBuilder } from "@google-labs/breadboard/kits"; // The NodeValue denotes the value types which can be received and returned by a node export type NodeValue = -| string -| number -| boolean -| null -| undefined -| NodeValue[] -| { [key: string]: NodeValue }; + | string + | number + | boolean + | null + | undefined + | NodeValue[] + | { [key: string]: NodeValue }; export type InputValues = Record; export type OutputValues = Partial>; // This is similiar to the InputValues except all values are optional @@ -19,37 +19,38 @@ const echo = async (inputs) => inputs; // This simple handler will return the gi // This will combine two strings together const concat = async (inputs: InputValues) => { - const { a, b } = inputs; + const { a, b } = inputs; - if (typeof a !== "string" || typeof b !== "string") { - throw new Error("Both values must be strings."); - } + if (typeof a !== "string" || typeof b !== "string") { + throw new Error("Both values must be strings."); + } - return { value: a.concat(b) }; + return { value: a.concat(b) }; }; const builder = new KitBuilder({ - title: "My Custom Kit", - description: "The description of my custom kit", - url: "npm:my-custom-kit", // Additional setup is required to create as an npm package - version: "0.0.1" + title: "My Custom Kit", + description: "The description of my custom kit", + url: "npm:my-custom-kit", // Additional setup is required to create as an npm package + version: "0.0.1", }); export const MyCustomKit = builder.build({ - echo, - concat, - split: async (inputs: InputValues): Promise => { // This splits strings using comma separators - const input = inputs.input; - - if (typeof input !== "string") { - throw new Error("Must provide a string to split.") - } - - const values = input.split(","); - - return { value: values }; - } + echo, + concat, + split: async (inputs: InputValues): Promise => { + // This splits strings using comma separators + const input = inputs.input; + + if (typeof input !== "string") { + throw new Error("Must provide a string to split."); + } + + const values = input.split(","); + + return { value: values }; + }, }); export type myCustomKit = InstanceType; -export default MyCustomKit; \ No newline at end of file +export default MyCustomKit; diff --git a/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/index.ts b/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/index.ts index 648b934..383d6ff 100644 --- a/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/index.ts +++ b/samples/Breadboard Walkthrough/src/custom-kit-node-values-and-handlers/index.ts @@ -1,11 +1,13 @@ #!/usr/bin/env npx -y tsx -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; import MyCustomKit from "./custom-kit-node-values-and-handlers.js"; const board = new Board({ - title: "Custom Kit Node Values and Handlers Demo" + title: "Custom Kit Node Values and Handlers Demo", }); const myCustomKit = board.addKit(MyCustomKit); @@ -15,42 +17,55 @@ const concat = myCustomKit.concat(); const split = myCustomKit.split(); const input = board.input({ - $id: "inputNode" + $id: "inputNode", }); input.wire("inputPartOne", echo); -echo.wire("inputPartOne->echoedInput", board.output({ - $id: "echoOutput" -})); +echo.wire( + "inputPartOne->echoedInput", + board.output({ + $id: "echoOutput", + }) +); input.wire("inputPartOne->a", concat).wire("inputPartTwo->b", concat); -concat.wire("value->concatenatedInput", board.output({ - $id: "concatOutput" -})); +concat.wire( + "value->concatenatedInput", + board.output({ + $id: "concatOutput", + }) +); input.wire("inputPartThree->input", split); -split.wire("value->splitInput", board.output({ - $id: "splitOutput" -})); +split.wire( + "value->splitInput", + board.output({ + $id: "splitOutput", + }) +); (async () => { for await (const run of board.run()) { - if (run.type === "input") { + if (run.type === "input") { run.inputs = { inputPartOne: "Hello", inputPartTwo: "World!", - inputPartThree: "Welcome,to,Breadboard!" - }; + inputPartThree: "Welcome,to,Breadboard!", + }; } else if (run.type === "output") { console.log(run.node.id, run.outputs); } } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/hello-world/board.json b/samples/Breadboard Walkthrough/src/hello-world/board.json new file mode 100644 index 0000000..e7b90e9 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/hello-world/board.json @@ -0,0 +1,21 @@ +{ + "title": "Hello World", + "edges": [ + { + "from": "input-1", + "to": "output-2", + "out": "*" + } + ], + "nodes": [ + { + "id": "input-1", + "type": "input" + }, + { + "id": "output-2", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/hello-world/index.ts b/samples/Breadboard Walkthrough/src/hello-world/index.ts index a46aa34..ce074e8 100644 --- a/samples/Breadboard Walkthrough/src/hello-world/index.ts +++ b/samples/Breadboard Walkthrough/src/hello-world/index.ts @@ -1,8 +1,10 @@ -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Hello World" + title: "Hello World", }); (async () => { @@ -14,10 +16,13 @@ const board = new Board({ ); })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/README.md b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/README.md new file mode 100644 index 0000000..c3c1488 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/README.md @@ -0,0 +1,58 @@ +# Include Board as a Node with URL + +```mermaid +%%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%% +graph TD; +invoke1["invoke
id='invoke-1'"] -- "nestedOutput->nestedOutput" --> mainOutputNode{{"output
id='mainOutputNode'"}}:::output +mainInputNode[/"input
id='mainInputNode'"/]:::input -- "mainInput->nestedInput" --> invoke1["invoke
id='invoke-1'"] +classDef default stroke:#ffab40,fill:#fff2ccff,color:#000 +classDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000 +classDef output stroke:#38761d,fill:#b6d7a8ff,color:#000 +classDef passthrough stroke:#a64d79,fill:#ead1dcff,color:#000 +classDef slot stroke:#a64d79,fill:#ead1dcff,color:#000 +classDef config stroke:#a64d79,fill:#ead1dcff,color:#000 +classDef secrets stroke:#db4437,fill:#f4cccc,color:#000 +classDef slotted stroke:#a64d79 +``` + +```json +{ + "title": "Include Board as a Node with URL", + "edges": [ + { + "from": "invoke-1", + "to": "mainOutputNode", + "out": "nestedOutput", + "in": "nestedOutput" + }, + { + "from": "mainInputNode", + "to": "invoke-1", + "out": "mainInput", + "in": "nestedInput" + } + ], + "nodes": [ + { + "id": "mainInputNode", + "type": "input" + }, + { + "id": "invoke-1", + "type": "invoke", + "configuration": { + "path": "https://raw.githubusercontent.com/ExaDev-io/breadboard-samples/more-demos/samples/Breadboard%20Walkthrough/src/include-board-as-a-node-with-url/nestedboard.json" + } + }, + { + "id": "mainOutputNode", + "type": "output" + } + ], + "kits": [ + { + "url": "npm:@google-labs/core-kit" + } + ] +} +``` \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/board.json b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/board.json new file mode 100644 index 0000000..a217a37 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/board.json @@ -0,0 +1,39 @@ +{ + "title": "Include Board as a Node with URL", + "edges": [ + { + "from": "invoke-1", + "to": "mainOutputNode", + "out": "nestedOutput", + "in": "nestedOutput" + }, + { + "from": "mainInputNode", + "to": "invoke-1", + "out": "mainInput", + "in": "nestedInput" + } + ], + "nodes": [ + { + "id": "mainInputNode", + "type": "input" + }, + { + "id": "invoke-1", + "type": "invoke", + "configuration": { + "path": "https://raw.githubusercontent.com/ExaDev-io/breadboard-samples/more-demos/samples/Breadboard%20Walkthrough/src/include-board-as-a-node-with-url/nestedboard.json" + } + }, + { + "id": "mainOutputNode", + "type": "output" + } + ], + "kits": [ + { + "url": "npm:@google-labs/core-kit" + } + ] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/index.ts b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/index.ts new file mode 100644 index 0000000..9d7d777 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/index.ts @@ -0,0 +1,50 @@ +#!/usr/bin/env npx -y tsx + +import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import { Core } from "@google-labs/core-kit"; +import fs from "fs"; +import * as url from "url"; + +const board = new Board({ + title: "Include Board as a Node with URL", +}); + +const core = board.addKit(Core); + +const NESTED_BOARD_URL = + "https://raw.githubusercontent.com/ExaDev-io/breadboard-samples/more-demos/samples/Breadboard%20Walkthrough/src/include-board-as-a-node-with-url/nestedboard.json"; + +board + .input({ + $id: "mainInputNode", + }) + .wire( + "mainInput->nestedInput", + core + .invoke({ path: NESTED_BOARD_URL }) + .wire("nestedOutput", board.output({ $id: "mainOutputNode" })) + ); + +(async () => { + for await (const run of board.run()) { + if (run.type === "input") { + run.inputs = { + mainInput: "Hello World!", + }; + } else if (run.type === "output") { + console.log(run.node.id, run.outputs); + } + } +})(); + +generateAndWriteCombinedMarkdown({ + board, + filename: "README", + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/nestedboard.json b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/nestedboard.json new file mode 100644 index 0000000..e5d301c --- /dev/null +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node-with-url/nestedboard.json @@ -0,0 +1,22 @@ +{ + "title": "Nested Board", + "edges": [ + { + "from": "nestedInputNode", + "to": "nestedOutputNode", + "out": "nestedInput", + "in": "nestedOutput" + } + ], + "nodes": [ + { + "id": "nestedInputNode", + "type": "input" + }, + { + "id": "nestedOutputNode", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node/README.md b/samples/Breadboard Walkthrough/src/include-board-as-a-node/README.md index b88d3b1..f27a39c 100644 --- a/samples/Breadboard Walkthrough/src/include-board-as-a-node/README.md +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node/README.md @@ -3,8 +3,8 @@ ```mermaid %%{init: 'themeVariables': { 'fontFamily': 'Fira Code, monospace' }}%% graph TD; -include1[["include
id='include-1'"]]:::include -- "nestedOutput->nestedOutput" --> mainOutputNode{{"output
id='mainOutputNode'"}}:::output -mainInputNode[/"input
id='mainInputNode'"/]:::input -- "mainInput->nestedInput" --> include1[["include
id='include-1'"]]:::include +invoke1["invoke
id='invoke-1'"] -- "nestedOutput->nestedOutput" --> mainOutputNode{{"output
id='mainOutputNode'"}}:::output +mainInputNode[/"input
id='mainInputNode'"/]:::input -- "mainInput->nestedInput" --> invoke1["invoke
id='invoke-1'"] classDef default stroke:#ffab40,fill:#fff2ccff,color:#000 classDef input stroke:#3c78d8,fill:#c9daf8ff,color:#000 classDef output stroke:#38761d,fill:#b6d7a8ff,color:#000 @@ -20,14 +20,14 @@ classDef slotted stroke:#a64d79 "title": "Include Board as a Node", "edges": [ { - "from": "include-1", + "from": "invoke-1", "to": "mainOutputNode", "out": "nestedOutput", "in": "nestedOutput" }, { "from": "mainInputNode", - "to": "include-1", + "to": "invoke-1", "out": "mainInput", "in": "nestedInput" } @@ -38,8 +38,8 @@ classDef slotted stroke:#a64d79 "type": "input" }, { - "id": "include-1", - "type": "include", + "id": "invoke-1", + "type": "invoke", "configuration": { "graph": { "title": "Nested Board", diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node/board.json b/samples/Breadboard Walkthrough/src/include-board-as-a-node/board.json new file mode 100644 index 0000000..05ae8e2 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node/board.json @@ -0,0 +1,60 @@ +{ + "title": "Include Board as a Node", + "edges": [ + { + "from": "invoke-1", + "to": "mainOutputNode", + "out": "nestedOutput", + "in": "nestedOutput" + }, + { + "from": "mainInputNode", + "to": "invoke-1", + "out": "mainInput", + "in": "nestedInput" + } + ], + "nodes": [ + { + "id": "mainInputNode", + "type": "input" + }, + { + "id": "invoke-1", + "type": "invoke", + "configuration": { + "graph": { + "title": "Nested Board", + "edges": [ + { + "from": "nestedInputNode", + "to": "nestedOutputNode", + "out": "nestedInput", + "in": "nestedOutput" + } + ], + "nodes": [ + { + "id": "nestedInputNode", + "type": "input" + }, + { + "id": "nestedOutputNode", + "type": "output" + } + ], + "kits": [] + } + } + }, + { + "id": "mainOutputNode", + "type": "output" + } + ], + "kits": [ + { + "url": "npm:@google-labs/core-kit" + } + ] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/include-board-as-a-node/index.ts b/samples/Breadboard Walkthrough/src/include-board-as-a-node/index.ts index 11d142f..23770bc 100644 --- a/samples/Breadboard Walkthrough/src/include-board-as-a-node/index.ts +++ b/samples/Breadboard Walkthrough/src/include-board-as-a-node/index.ts @@ -1,49 +1,60 @@ #!/usr/bin/env npx -y tsx -import { Board, GraphDescriptor } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; -import { Core } from "@google-labs/core-kit" +import { Board, GraphDescriptor } from "@google-labs/breadboard"; +import { Core } from "@google-labs/core-kit"; +import fs from "fs"; +import * as url from "url"; const nestedBoard = new Board({ - title: "Nested Board" + title: "Nested Board", }); -nestedBoard.input({ - $id: "nestedInputNode" -}).wire("nestedInput->nestedOutput", nestedBoard.output({ $id:"nestedOutputNode" })); +nestedBoard + .input({ + $id: "nestedInputNode", + }) + .wire( + "nestedInput->nestedOutput", + nestedBoard.output({ $id: "nestedOutputNode" }) + ); const board = new Board({ - title: "Include Board as a Node" + title: "Include Board as a Node", }); -const coreKit = board.addKit(Core); +const core = board.addKit(Core); board - .input({ - $id: "mainInputNode" - }) - .wire("mainInput->nestedInput", - coreKit - .include({graph: nestedBoard as GraphDescriptor}) - .wire("nestedOutput", board.output({ $id: "mainOutputNode" })) - ); + .input({ + $id: "mainInputNode", + }) + .wire( + "mainInput->nestedInput", + core + .invoke({ graph: nestedBoard as GraphDescriptor }) + .wire("nestedOutput", board.output({ $id: "mainOutputNode" })) + ); (async () => { for await (const run of board.run()) { - if (run.type === "input") { + if (run.type === "input") { run.inputs = { - mainInput: "Hello World!" - }; + mainInput: "Hello World!", + }; } else if (run.type === "output") { console.log(run.node.id, run.outputs); } } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/board.json b/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/board.json new file mode 100644 index 0000000..276032b --- /dev/null +++ b/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/board.json @@ -0,0 +1,32 @@ +{ + "title": "Multiple Inputs One Output", + "edges": [ + { + "from": "inputOne", + "to": "output-1", + "out": "partOne", + "in": "partOne" + }, + { + "from": "inputTwo", + "to": "output-1", + "out": "partTwo", + "in": "partTwo" + } + ], + "nodes": [ + { + "id": "output-1", + "type": "output" + }, + { + "id": "inputOne", + "type": "input" + }, + { + "id": "inputTwo", + "type": "input" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/index.ts b/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/index.ts index 3a4c68c..5baf570 100644 --- a/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/index.ts +++ b/samples/Breadboard Walkthrough/src/multiple-inputs-one-output/index.ts @@ -1,8 +1,10 @@ -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Multiple Inputs One Output" + title: "Multiple Inputs One Output", }); const output = board.output(); @@ -35,10 +37,13 @@ inputTwo.wire("partTwo", output); } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/multiple-inputs/board.json b/samples/Breadboard Walkthrough/src/multiple-inputs/board.json new file mode 100644 index 0000000..1dd3c3f --- /dev/null +++ b/samples/Breadboard Walkthrough/src/multiple-inputs/board.json @@ -0,0 +1,32 @@ +{ + "title": "Multiple Inputs", + "edges": [ + { + "from": "input-2", + "to": "output-1", + "out": "message", + "in": "message" + }, + { + "from": "input-3", + "to": "output-1", + "out": "message", + "in": "message" + } + ], + "nodes": [ + { + "id": "output-1", + "type": "output" + }, + { + "id": "input-2", + "type": "input" + }, + { + "id": "input-3", + "type": "input" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/multiple-inputs/index.ts b/samples/Breadboard Walkthrough/src/multiple-inputs/index.ts index 6adb891..c708179 100644 --- a/samples/Breadboard Walkthrough/src/multiple-inputs/index.ts +++ b/samples/Breadboard Walkthrough/src/multiple-inputs/index.ts @@ -1,8 +1,10 @@ -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Multiple Inputs" + title: "Multiple Inputs", }); const output = board.output(); @@ -27,10 +29,13 @@ let counter = 1; } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/multiple-outputs/board.json b/samples/Breadboard Walkthrough/src/multiple-outputs/board.json new file mode 100644 index 0000000..f278973 --- /dev/null +++ b/samples/Breadboard Walkthrough/src/multiple-outputs/board.json @@ -0,0 +1,32 @@ +{ + "title": "Multiple Outputs", + "edges": [ + { + "from": "input-1", + "to": "outputOne", + "out": "partOne", + "in": "partOne" + }, + { + "from": "input-1", + "to": "outputTwo", + "out": "partTwo", + "in": "partTwo" + } + ], + "nodes": [ + { + "id": "outputOne", + "type": "output" + }, + { + "id": "outputTwo", + "type": "output" + }, + { + "id": "input-1", + "type": "input" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/multiple-outputs/index.ts b/samples/Breadboard Walkthrough/src/multiple-outputs/index.ts index 0aa9116..3789e44 100644 --- a/samples/Breadboard Walkthrough/src/multiple-outputs/index.ts +++ b/samples/Breadboard Walkthrough/src/multiple-outputs/index.ts @@ -1,8 +1,10 @@ -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Multiple Outputs" + title: "Multiple Outputs", }); const outputOne = board.output({ $id: "outputOne", @@ -33,10 +35,13 @@ input.wire("partTwo", outputTwo); } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/naming-wiring-parameters/board.json b/samples/Breadboard Walkthrough/src/naming-wiring-parameters/board.json new file mode 100644 index 0000000..d9f3a8c --- /dev/null +++ b/samples/Breadboard Walkthrough/src/naming-wiring-parameters/board.json @@ -0,0 +1,81 @@ +{ + "title": "Naming Wiring Parameters", + "edges": [ + { + "from": "inputNode", + "to": "outputNode", + "out": "inputPartOne", + "in": "inputPartOne" + }, + { + "from": "inputNode", + "to": "outputNode", + "out": "inputPartTwo", + "in": "inputPartTwo" + }, + { + "from": "inputNode", + "to": "outputNode", + "out": "inputPartThree", + "in": "inputPartThree" + }, + { + "from": "inputNode", + "to": "outputNode", + "out": "inputPartFour", + "in": "inputPartFour" + }, + { + "from": "inputNode", + "to": "outputNode", + "out": "inputPartFive", + "in": "inputPartFive" + }, + { + "from": "inputNode", + "to": "renamedOutputNode", + "out": "inputPartSix", + "in": "renamedOutput" + }, + { + "from": "inputNode", + "to": "outputAll", + "out": "*" + } + ], + "nodes": [ + { + "id": "inputNode", + "type": "input" + }, + { + "id": "outputNode", + "type": "output" + }, + { + "id": "outputNode", + "type": "output" + }, + { + "id": "outputNode", + "type": "output" + }, + { + "id": "outputNode", + "type": "output" + }, + { + "id": "outputNode", + "type": "output" + }, + { + "id": "renamedOutputNode", + "type": "output" + }, + { + "id": "outputAll", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/naming-wiring-parameters/index.ts b/samples/Breadboard Walkthrough/src/naming-wiring-parameters/index.ts index 877bb60..ee9e85a 100644 --- a/samples/Breadboard Walkthrough/src/naming-wiring-parameters/index.ts +++ b/samples/Breadboard Walkthrough/src/naming-wiring-parameters/index.ts @@ -1,72 +1,97 @@ #!/usr/bin/env npx -y tsx -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Naming Wiring Parameters" + title: "Naming Wiring Parameters", }); const input = board.input({ - $id: "inputNode" + $id: "inputNode", }); /** - * The following 4 wires are equivalent because the property names are the identical on both the sending and receiving nodes + * The following 4 wires are equivalent because the property names are the identical on both the sending and receiving nodes */ // This means the parameter name can be on both sides of the arrow... -input.wire("inputPartOne->inputPartOne", board.output({ - $id: "outputNode" -})); +input.wire( + "inputPartOne->inputPartOne", + board.output({ + $id: "outputNode", + }) +); // Or either side of the arrow... -input.wire("inputPartTwo->", board.output({ - $id: "outputNode" -})); -input.wire("->inputPartThree", board.output({ - $id: "outputNode" -})); -// Or the arrow can be omitted entirely, which assumes left-to-right direction by default -input.wire("inputPartFour", board.output({ - $id: "outputNode" -})); +input.wire( + "inputPartTwo->", + board.output({ + $id: "outputNode", + }) +); +input.wire( + "->inputPartThree", + board.output({ + $id: "outputNode", + }) +); +// Or the arrow can be omitted entirely, which assumes left-to-right direction by default +input.wire( + "inputPartFour", + board.output({ + $id: "outputNode", + }) +); // The right-to-left arrow direction can be used to pass values from nodes inside the wire function to outer nodes // The arrow direction must be included here, but the parameter name can be on the left, right or both sides of the arrow -board.output({ - $id: "outputNode" -}).wire("inputPartFive<-inputPartFive", input); +board + .output({ + $id: "outputNode", + }) + .wire("inputPartFive<-inputPartFive", input); // Redirecting a parameter to another name can be useful for when you want to use a node that requires specifically named input(s) -input.wire("inputPartSix->renamedOutput", board.output({ - $id: "renamedOutputNode" -})); +input.wire( + "inputPartSix->renamedOutput", + board.output({ + $id: "renamedOutputNode", + }) +); // Using asterisk (*) will wire all properties -input.wire("*", board.output({ - $id: "outputAll" -})); +input.wire( + "*", + board.output({ + $id: "outputAll", + }) +); (async () => { for await (const run of board.run()) { - if (run.type === "input") { + if (run.type === "input") { run.inputs = { inputPartOne: "Hello", inputPartTwo: "World", inputPartThree: "And", inputPartFour: "Welcome", inputPartFive: "To", - inputPartSix: "Breadboard!" - }; + inputPartSix: "Breadboard!", + }; } else if (run.type === "output") { console.log(run.node.id, run.outputs); } } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/nodes-by-id/board.json b/samples/Breadboard Walkthrough/src/nodes-by-id/board.json new file mode 100644 index 0000000..ec67a0a --- /dev/null +++ b/samples/Breadboard Walkthrough/src/nodes-by-id/board.json @@ -0,0 +1,22 @@ +{ + "title": "index.ts", + "edges": [ + { + "from": "inputOne", + "to": "output-1", + "out": "message", + "in": "message" + } + ], + "nodes": [ + { + "id": "inputOne", + "type": "input" + }, + { + "id": "output-1", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/nodes-by-id/index.ts b/samples/Breadboard Walkthrough/src/nodes-by-id/index.ts index 2522e94..3688891 100644 --- a/samples/Breadboard Walkthrough/src/nodes-by-id/index.ts +++ b/samples/Breadboard Walkthrough/src/nodes-by-id/index.ts @@ -1,6 +1,8 @@ +import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; import { Board } from "@google-labs/breadboard"; +import fs from "fs"; import path from "path"; -import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import * as url from "url"; const board = new Board({ title: path.basename(new URL(import.meta.url).pathname), @@ -33,10 +35,13 @@ input.wire("message", output); } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/board.json b/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/board.json new file mode 100644 index 0000000..495981b --- /dev/null +++ b/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/board.json @@ -0,0 +1,32 @@ +{ + "title": "One Input Multiple Outputs", + "edges": [ + { + "from": "input-1", + "to": "outputOne", + "out": "partOne", + "in": "partOne" + }, + { + "from": "input-1", + "to": "outputTwo", + "out": "partTwo", + "in": "partTwo" + } + ], + "nodes": [ + { + "id": "outputOne", + "type": "output" + }, + { + "id": "outputTwo", + "type": "output" + }, + { + "id": "input-1", + "type": "input" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/index.ts b/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/index.ts index 3de84f9..3c7baa5 100644 --- a/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/index.ts +++ b/samples/Breadboard Walkthrough/src/one-input-multiple-outputs/index.ts @@ -1,8 +1,10 @@ -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "One Input Multiple Outputs" + title: "One Input Multiple Outputs", }); const outputOne = board.output({ $id: "outputOne", @@ -33,10 +35,13 @@ input.wire("partTwo", outputTwo); } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/samples/Breadboard Walkthrough/src/specific-outputs/board.json b/samples/Breadboard Walkthrough/src/specific-outputs/board.json new file mode 100644 index 0000000..13063dd --- /dev/null +++ b/samples/Breadboard Walkthrough/src/specific-outputs/board.json @@ -0,0 +1,32 @@ +{ + "title": "Specific Outputs", + "edges": [ + { + "from": "input-1", + "to": "output1", + "out": "message", + "in": "message" + }, + { + "from": "input-1", + "to": "output2", + "out": "message", + "in": "message" + } + ], + "nodes": [ + { + "id": "input-1", + "type": "input" + }, + { + "id": "output1", + "type": "output" + }, + { + "id": "output2", + "type": "output" + } + ], + "kits": [] +} \ No newline at end of file diff --git a/samples/Breadboard Walkthrough/src/specific-outputs/index.ts b/samples/Breadboard Walkthrough/src/specific-outputs/index.ts index 36994f1..95fd0c2 100644 --- a/samples/Breadboard Walkthrough/src/specific-outputs/index.ts +++ b/samples/Breadboard Walkthrough/src/specific-outputs/index.ts @@ -1,8 +1,10 @@ -import { Board } from "@google-labs/breadboard"; import generateAndWriteCombinedMarkdown from "@exadev/breadboard-kits/util/files/generateAndWriteCombinedMarkdown"; +import { Board } from "@google-labs/breadboard"; +import fs from "fs"; +import * as url from "url"; const board = new Board({ - title: "Specific Outputs" + title: "Specific Outputs", }); const input = board.input(); @@ -41,10 +43,13 @@ input.wire("message", outputTwo); } })(); -import * as url from 'url'; - generateAndWriteCombinedMarkdown({ board, filename: "README", - dir: url.fileURLToPath(new URL('.', import.meta.url)) -}); \ No newline at end of file + dir: url.fileURLToPath(new URL(".", import.meta.url)), +}); + +fs.writeFileSync( + url.fileURLToPath(new URL("board.json", import.meta.url)), + JSON.stringify(board, null, "\t") +); diff --git a/yarn.lock b/yarn.lock index 53e3c6c..59f9ead 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1826,9 +1826,9 @@ __metadata: languageName: node linkType: hard -"@exadev/breadboard-kits@npm:^0.9.0": - version: 0.9.0 - resolution: "@exadev/breadboard-kits@npm:0.9.0" +"@exadev/breadboard-kits@npm:^0.9.0, @exadev/breadboard-kits@npm:^0.9.1": + version: 0.9.1 + resolution: "@exadev/breadboard-kits@npm:0.9.1" dependencies: "@anthropic-ai/sdk": "npm:^0.10.2" "@anthropic-ai/tokenizer": "npm:^0.0.4" @@ -1841,7 +1841,7 @@ __metadata: dotenv: "npm:^16.3.1" js-tiktoken: "npm:^1.0.8" jsonschema: "npm:^1.4.1" - checksum: 1f577b7364fe202a8f7c1d970db5fb3a699859793f96992da9c5b7aa308cffe43b1badac2916035db19da9d5ddff86072b62b0083931b4614344704ec0533d90 + checksum: 23cf4794fde8b8ce932db29c40a6eb56e9c57ed6738737e7efb18fa25d055e47b8d3ad03c571b2e2f0e5bdcb73c368e06c88927f6bedb15c3bfc5601a12de6cd languageName: node linkType: hard @@ -2875,7 +2875,21 @@ __metadata: languageName: node linkType: hard -"@xenova/transformers@npm:^2.10.1, @xenova/transformers@npm:^2.9.0": +"@xenova/transformers@npm:^2.10.1": + version: 2.11.0 + resolution: "@xenova/transformers@npm:2.11.0" + dependencies: + onnxruntime-node: "npm:1.14.0" + onnxruntime-web: "npm:1.14.0" + sharp: "npm:^0.32.0" + dependenciesMeta: + onnxruntime-node: + optional: true + checksum: d95d513f527ae673b78d8b4fae94b8f5a7ef4685f57008622f97d187433c685bd25b9b6e20ac9d4ae8b74e6ce8cc80d16b6fee6a06445056d7bb0790438ab8e0 + languageName: node + linkType: hard + +"@xenova/transformers@npm:^2.9.0": version: 2.10.1 resolution: "@xenova/transformers@npm:2.10.1" dependencies: @@ -3308,12 +3322,12 @@ __metadata: version: 0.0.0-use.local resolution: "breadboard-walkthrough@workspace:samples/Breadboard Walkthrough" dependencies: - "@exadev/breadboard-kits": "npm:^0.8.3" - "@google-labs/breadboard": "npm:^0.5.1" - "@types/node": "npm:^20.9.3" + "@exadev/breadboard-kits": "npm:^0.9.1" + "@google-labs/breadboard": "npm:^0.6.0" + "@types/node": "npm:^20.10.4" npm-run-all: "npm:^4.1.5" - tsx: "npm:^4.2.0" - typescript: "npm:^5.3.2" + tsx: "npm:^4.6.2" + typescript: "npm:^5.3.3" languageName: unknown linkType: soft @@ -8090,7 +8104,7 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.2.0, tsx@npm:^4.4.0, tsx@npm:^4.6.2": +"tsx@npm:^4.4.0, tsx@npm:^4.6.2": version: 4.6.2 resolution: "tsx@npm:4.6.2" dependencies: