From da0867202a7b340e0de4362621e533b45c1afd08 Mon Sep 17 00:00:00 2001 From: jig925 <57284752+jig925@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:03:01 +0100 Subject: [PATCH 1/5] WIP --- package-lock.json | 1 - .../public/graphs/algolia_story_from_id.json | 105 ++++++++++++++++++ .../public/graphs/firebase_story_from_id.json | 102 +++++++++++++++++ .../public/graphs/firebase_top_story_ids.json | 90 +++++++++++++++ .../breadboard-web/public/local-boards.json | 15 +++ .../src/boards/algolia_story_from_id.ts | 74 ++++++++++++ .../src/boards/firebase_story_from_id.ts | 63 +++++++++++ .../src/boards/firebase_top_story_ids.ts | 43 +++++++ 8 files changed, 492 insertions(+), 1 deletion(-) create mode 100644 packages/breadboard-web/public/graphs/algolia_story_from_id.json create mode 100644 packages/breadboard-web/public/graphs/firebase_story_from_id.json create mode 100644 packages/breadboard-web/public/graphs/firebase_top_story_ids.json create mode 100644 packages/breadboard-web/src/boards/algolia_story_from_id.ts create mode 100644 packages/breadboard-web/src/boards/firebase_story_from_id.ts create mode 100644 packages/breadboard-web/src/boards/firebase_top_story_ids.ts diff --git a/package-lock.json b/package-lock.json index c5832f5da72..5f04fcea101 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1277,7 +1277,6 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "extraneous": true, "inBundle": true, "license": "MIT", "engines": { diff --git a/packages/breadboard-web/public/graphs/algolia_story_from_id.json b/packages/breadboard-web/public/graphs/algolia_story_from_id.json new file mode 100644 index 00000000000..545c4ed99ca --- /dev/null +++ b/packages/breadboard-web/public/graphs/algolia_story_from_id.json @@ -0,0 +1,105 @@ +{ + "title": "Algolia Firebase API Story by ID", + "description": "Board which returns story contents", + "version": "0.0.1", + "url": "https://github.com/ExaDev/breadboard-examples/tree/hackerNews-toolworker/src/examples/hackerNews/algolia", + "edges": [ + { + "from": "main", + "to": "output-2", + "out": "output", + "in": "output" + }, + { + "from": "spreadResponse", + "to": "main", + "out": "*", + "in": "" + }, + { + "from": "fetch", + "to": "spreadResponse", + "out": "response", + "in": "object" + }, + { + "from": "urlTemplate", + "to": "fetch", + "out": "url", + "in": "url" + }, + { + "from": "storyID", + "to": "urlTemplate", + "out": "*", + "in": "" + } + ], + "nodes": [ + { + "id": "output-2", + "type": "output", + "configuration": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "string", + "title": "output" + } + } + } + } + }, + { + "id": "main", + "type": "output", + "configuration": {} + }, + { + "id": "spreadResponse", + "type": "runJavascript", + "configuration": { + "code": "const spreadResponse = inputs=>{const object=inputs.object;if(typeof object!==\"object\"){throw new Error(`object is of type ${typeof object} not object`)}return{...object}};", + "name": "spreadResponse", + "raw": true + } + }, + { + "id": "fetch", + "type": "fetch", + "configuration": { + "method": "GET" + } + }, + { + "id": "urlTemplate", + "type": "urlTemplate", + "configuration": { + "template": "https://hn.algolia.com/api/v1/items/{storyID}" + } + }, + { + "id": "storyID", + "type": "input", + "configuration": { + "schema": { + "title": "Hacker News Story", + "properties": { + "storyID": { + "type": "string", + "title": "Story ID", + "default": "39788322", + "description": "HackerNews Story ID to extract" + } + }, + "required": [ + "storyID" + ] + } + } + } + ], + "graphs": {}, + "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json" +} \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/firebase_story_from_id.json b/packages/breadboard-web/public/graphs/firebase_story_from_id.json new file mode 100644 index 00000000000..a3504a7bc99 --- /dev/null +++ b/packages/breadboard-web/public/graphs/firebase_story_from_id.json @@ -0,0 +1,102 @@ +{ + "title": "Hacker News Firebase API Story by ID", + "description": "Board which returns story json", + "version": "0.0.1", + "edges": [ + { + "from": "main", + "to": "output-2", + "out": "output", + "in": "output" + }, + { + "from": "spreadResponse", + "to": "main", + "out": "*", + "in": "" + }, + { + "from": "fetch", + "to": "spreadResponse", + "out": "response", + "in": "object" + }, + { + "from": "urlTemplate", + "to": "fetch", + "out": "url", + "in": "url" + }, + { + "from": "storyid", + "to": "urlTemplate", + "out": "*", + "in": "" + } + ], + "nodes": [ + { + "id": "output-2", + "type": "output", + "configuration": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "string", + "title": "output" + } + } + } + } + }, + { + "id": "main", + "type": "output", + "configuration": {} + }, + { + "id": "spreadResponse", + "type": "runJavascript", + "configuration": { + "code": "const spreadResponse = inputs=>{const object=inputs.object;if(typeof object!==\"object\"){throw new Error(`object is of type ${typeof object} not object`)}return{...object}};", + "name": "spreadResponse", + "raw": true + } + }, + { + "id": "fetch", + "type": "fetch", + "configuration": { + "method": "GET" + } + }, + { + "id": "urlTemplate", + "type": "urlTemplate", + "configuration": { + "template": "https://hacker-news.firebaseio.com/v0/item/{storyid}.json" + } + }, + { + "id": "storyid", + "type": "input", + "configuration": { + "schema": { + "title": "Hacker News Story id", + "properties": { + "storyid": { + "type": "number", + "title": "Story ID", + "default": "39788322", + "description": "HackerNews Story ID to extract" + } + }, + "type": "number" + } + } + } + ], + "graphs": {}, + "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json" +} \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/firebase_top_story_ids.json b/packages/breadboard-web/public/graphs/firebase_top_story_ids.json new file mode 100644 index 00000000000..5a8943a0c35 --- /dev/null +++ b/packages/breadboard-web/public/graphs/firebase_top_story_ids.json @@ -0,0 +1,90 @@ +{ + "title": "Hacker News Firebase API Story IDs", + "description": "Board which returns the top story IDs from Hacker News", + "version": "0.0.1", + "edges": [ + { + "from": "main", + "to": "output-2", + "out": "output", + "in": "output" + }, + { + "from": "fn-3", + "to": "main", + "out": "*", + "in": "" + }, + { + "from": "fetch", + "to": "fn-3", + "out": "response", + "in": "list" + }, + { + "from": "limit", + "to": "fn-3", + "out": "limit", + "in": "limit" + } + ], + "nodes": [ + { + "id": "output-2", + "type": "output", + "configuration": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "string", + "title": "output" + } + } + } + } + }, + { + "id": "main", + "type": "output", + "configuration": {} + }, + { + "id": "fn-3", + "type": "runJavascript", + "configuration": { + "code": "const fn_3 = ({list,limit})=>{return{output:list.slice(0,limit)}};", + "name": "fn_3", + "raw": true + } + }, + { + "id": "fetch", + "type": "fetch", + "configuration": { + "method": "GET", + "url": "https://hacker-news.firebaseio.com/v0/topstories.json" + } + }, + { + "id": "limit", + "type": "input", + "configuration": { + "schema": { + "title": "Hacker News Story", + "properties": { + "limit": { + "type": "number", + "title": "Story Limit", + "default": "1", + "description": "The Number of HackerNews Story ID's to return" + } + } + }, + "type": "number" + } + } + ], + "graphs": {}, + "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json" +} \ No newline at end of file diff --git a/packages/breadboard-web/public/local-boards.json b/packages/breadboard-web/public/local-boards.json index 92e15bd1543..9ff24e5665e 100644 --- a/packages/breadboard-web/public/local-boards.json +++ b/packages/breadboard-web/public/local-boards.json @@ -24,6 +24,11 @@ "url": "/graphs/agent.json", "version": "0.0.3" }, + { + "title": "Algolia Firebase API Story by ID", + "url": "/graphs/algolia_story_from_id.json", + "version": "0.0.1" + }, { "title": "Ask User", "url": "/graphs/ask-user.json", @@ -78,6 +83,16 @@ "title": "Error board", "url": "/graphs/error.json" }, + { + "title": "Hacker News Firebase API Story by ID", + "url": "/graphs/firebase_story_from_id.json", + "version": "0.0.1" + }, + { + "title": "Hacker News Firebase API Story IDs", + "url": "/graphs/firebase_top_story_ids.json", + "version": "0.0.1" + }, { "title": "Gemini Pro Generator", "url": "/graphs/gemini-generator.json", diff --git a/packages/breadboard-web/src/boards/algolia_story_from_id.ts b/packages/breadboard-web/src/boards/algolia_story_from_id.ts new file mode 100644 index 00000000000..0bfd5b1d2fd --- /dev/null +++ b/packages/breadboard-web/src/boards/algolia_story_from_id.ts @@ -0,0 +1,74 @@ +import { board, base, asRuntimeKit, BoardRunner, code} from "@google-labs/breadboard"; + +import Core, { core } from "@google-labs/core-kit"; +import TemplateKit, { templates } from "@google-labs/template-kit"; + +const storyInputSchema = { + type: "string", + title: "Story ID", + default: "39788322", + description: "HackerNews Story ID to extract", +}; + +const spread = code<{ object: object }>((inputs) => { + const object = inputs.object; + if (typeof object !== "object") { + throw new Error(`object is of type ${typeof object} not object`); + } + return { ...object }; +}); + +const boardSchema = "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json"; + +const firebaseBoardStoryFromId = await board(() => { + const input = base.input({ + $id: "storyID", + schema: { + title: "Hacker News Story", + properties: { + storyID: storyInputSchema + }, + required: ["storyID"], + } + }) + + const urlTemplate = templates.urlTemplate({ + $id: "urlTemplate", + template: "https://hn.algolia.com/api/v1/items/{storyID}", + }); + + input.to(urlTemplate); + + const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); + + const output = base.output({ $id: "main" }); + + const response = spread({ $id: "spreadResponse", object: fetchUrl.response }); + + response.to(output) + + return {output} + +}).serialize({ + title: "Algolia Firebase API Story by ID", + description: "Board which returns story contents", + version: "0.0.1", + url: "https://github.com/ExaDev/breadboard-examples/tree/hackerNews-toolworker/src/examples/hackerNews/algolia" +}) + +firebaseBoardStoryFromId.$schema = boardSchema + +const kits = [asRuntimeKit(Core), asRuntimeKit(TemplateKit)] + +const runner = await BoardRunner.fromGraphDescriptor(firebaseBoardStoryFromId); +for await (const stop of runner.run({ kits: kits })) { + if (stop.type === "input") { + stop.inputs = { + storyID: "39788322", + }; + } else if (stop.type === "output") { + console.log(stop.outputs) + } +} + +export default firebaseBoardStoryFromId \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/firebase_story_from_id.ts b/packages/breadboard-web/src/boards/firebase_story_from_id.ts new file mode 100644 index 00000000000..fe1a0009cf2 --- /dev/null +++ b/packages/breadboard-web/src/boards/firebase_story_from_id.ts @@ -0,0 +1,63 @@ +import { board, base, code} from "@google-labs/breadboard"; + +import { core } from "@google-labs/core-kit"; +import { templates } from "@google-labs/template-kit"; + +const storyInputSchema = { + type: "number", + title: "Story ID", + default: "39788322", + description: "HackerNews Story ID to extract", +}; + +const spread = code<{ object: object }>((inputs) => { + const object = inputs.object; + if (typeof object !== "object") { + throw new Error(`object is of type ${typeof object} not object`); + } + return { ...object }; +}); + +const boardSchema = "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json"; + +export const firebaseBoardStoryFromId = await board(() => { + const input = base.input({ + $id: "storyid", + schema: { + title: "Hacker News Story id", + properties: { + storyid: storyInputSchema + }, + type: "number" + } + }) + + const urlTemplate = templates.urlTemplate({ + $id: "urlTemplate", + template: "https://hacker-news.firebaseio.com/v0/item/{storyid}.json", + }); + + input.to(urlTemplate); + + const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); + + const output = base.output({ $id: "main" }); + + const response = spread({ $id: "spreadResponse", object: fetchUrl.response }); + + response.to(output) + + console.log(urlTemplate.url) + + return {output} + +}).serialize({ + title: "Hacker News Firebase API Story by ID", + description: "Board which returns story json", + version: "0.0.1",}) + +firebaseBoardStoryFromId.$schema = boardSchema + + + +export default firebaseBoardStoryFromId \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/firebase_top_story_ids.ts b/packages/breadboard-web/src/boards/firebase_top_story_ids.ts new file mode 100644 index 00000000000..0dbc9eaff17 --- /dev/null +++ b/packages/breadboard-web/src/boards/firebase_top_story_ids.ts @@ -0,0 +1,43 @@ +import { board, base, code } from "@google-labs/breadboard"; +import { core } from "@google-labs/core-kit"; + +const limitInputSchema = { + type: "number", + title: "Story Limit", + default: "1", + description: "The Number of HackerNews Story ID's to return" +} + +const slice = code<{ list: number[], limit: number }>(({ list, limit }) => { + return { output: list.slice(0, limit) } +}) + +const boardSchema = "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json"; + +export const firebaseBoardTopStoryIds = await board(() => { + const input = base.input({ + $id: "limit", + schema: { + title: "Hacker News Story", + properties: { + limit: limitInputSchema + }, + }, + type: "number", + }) + + const { response } = core.fetch({ $id: "fetch", method: "GET", url: "https://hacker-news.firebaseio.com/v0/topstories.json" }); + const output = base.output({ $id: "main" }); + const sliced = slice({ list: response as unknown as number[], limit: input.limit as unknown as number }) + + sliced.to(output) + + return { output } +}).serialize({ + title: "Hacker News Firebase API Story IDs", + description: "Board which returns the top story IDs from Hacker News", + version: "0.0.1",}) + +firebaseBoardTopStoryIds.$schema = boardSchema + +export default firebaseBoardTopStoryIds \ No newline at end of file From 2b0638c3fb5956c1fdfae734cfa68446f5004521 Mon Sep 17 00:00:00 2001 From: jig925 <57284752+jig925@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:28:23 +0100 Subject: [PATCH 2/5] WIP --- .../public/graphs/algolia_search.json | 152 ++++++++++++++++++ .../public/graphs/algolia_story_from_id.json | 11 +- .../public/graphs/firebase_story_from_id.json | 25 ++- .../public/graphs/firebase_top_story_ids.json | 5 +- .../breadboard-web/public/local-boards.json | 5 + .../src/boards/algolia_search.ts | 147 +++++++++++++++++ .../src/boards/algolia_story_from_id.ts | 21 +-- .../src/boards/firebase_story_from_id.ts | 49 +++--- .../src/boards/firebase_top_story_ids.ts | 12 +- 9 files changed, 360 insertions(+), 67 deletions(-) create mode 100644 packages/breadboard-web/public/graphs/algolia_search.json create mode 100644 packages/breadboard-web/src/boards/algolia_search.ts diff --git a/packages/breadboard-web/public/graphs/algolia_search.json b/packages/breadboard-web/public/graphs/algolia_search.json new file mode 100644 index 00000000000..2fe6a3f4406 --- /dev/null +++ b/packages/breadboard-web/public/graphs/algolia_search.json @@ -0,0 +1,152 @@ +{ + "title": "Angolia search ", + "description": "Board which returns api results based on a query", + "version": "0.0.1", + "edges": [ + { + "from": "urlTemplate", + "to": "fetch", + "out": "url", + "in": "url" + }, + { + "from": "urlTemplate", + "to": "output-2", + "out": "url", + "in": "url" + }, + { + "from": "fn-3", + "to": "output-2", + "out": "output", + "in": "output" + }, + { + "from": "query", + "to": "urlTemplate", + "out": "query", + "in": "query" + }, + { + "from": "query", + "to": "urlTemplate", + "out": "page", + "in": "page" + }, + { + "from": "query", + "to": "urlTemplate", + "out": "tags", + "in": "tags" + }, + { + "from": "query", + "to": "fn-3", + "out": "limit", + "in": "limit" + }, + { + "from": "fetch", + "to": "spreadResponse", + "out": "response", + "in": "object" + }, + { + "from": "spreadResponse", + "to": "fn-3", + "out": "hits", + "in": "list" + } + ], + "nodes": [ + { + "id": "output-2", + "type": "output", + "configuration": { + "schema": { + "type": "object", + "properties": { + "url": { + "title": "url", + "description": "The resulting URL that was produced by filling in the placeholders in the template", + "type": "string" + }, + "output": { + "type": "string", + "title": "output" + } + } + } + } + }, + { + "id": "urlTemplate", + "type": "urlTemplate", + "configuration": { + "template": "https://hn.algolia.com/api/v1/search?query={query}&tags={tags}&page={page}" + } + }, + { + "id": "fn-3", + "type": "runJavascript", + "configuration": { + "code": "const fn_3 = ({list,limit})=>{return{output:list.slice(0,limit)}};", + "name": "fn_3", + "raw": true + } + }, + { + "id": "query", + "type": "input", + "configuration": { + "schema": { + "title": "Algolia Limit", + "properties": { + "query": { + "type": "string", + "title": "query", + "default": "JavaScript", + "description": "The query" + }, + "limit": { + "type": "number", + "title": "limit", + "default": "1", + "description": "The limit" + }, + "tags": { + "type": "string", + "title": "tags", + "default": "JavaScript", + "description": "The tags" + }, + "page": { + "type": "string", + "title": "page", + "default": "2", + "description": "the page" + } + } + }, + "type": "string" + } + }, + { + "id": "fetch", + "type": "fetch", + "configuration": { + "method": "GET" + } + }, + { + "id": "spreadResponse", + "type": "runJavascript", + "configuration": { + "code": "const spreadResponse = inputs=>{const object=inputs.object;if(typeof object!==\"object\"){throw new Error(`object is of type ${typeof object} not object`)}return{...object}};", + "name": "spreadResponse", + "raw": true + } + } + ], + "graphs": {} +} \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/algolia_story_from_id.json b/packages/breadboard-web/public/graphs/algolia_story_from_id.json index 545c4ed99ca..02e6e1fbc2a 100644 --- a/packages/breadboard-web/public/graphs/algolia_story_from_id.json +++ b/packages/breadboard-web/public/graphs/algolia_story_from_id.json @@ -28,6 +28,12 @@ "out": "url", "in": "url" }, + { + "from": "storyID", + "to": "urlTemplate", + "out": "storyID", + "in": "storyID" + }, { "from": "storyID", "to": "urlTemplate", @@ -92,10 +98,7 @@ "default": "39788322", "description": "HackerNews Story ID to extract" } - }, - "required": [ - "storyID" - ] + } } } } diff --git a/packages/breadboard-web/public/graphs/firebase_story_from_id.json b/packages/breadboard-web/public/graphs/firebase_story_from_id.json index a3504a7bc99..64303b35416 100644 --- a/packages/breadboard-web/public/graphs/firebase_story_from_id.json +++ b/packages/breadboard-web/public/graphs/firebase_story_from_id.json @@ -1,6 +1,6 @@ { "title": "Hacker News Firebase API Story by ID", - "description": "Board which returns story json", + "description": "Board which returns story contents", "version": "0.0.1", "edges": [ { @@ -28,10 +28,10 @@ "in": "url" }, { - "from": "storyid", + "from": "storyID", "to": "urlTemplate", - "out": "*", - "in": "" + "out": "storyID", + "in": "storyID" } ], "nodes": [ @@ -75,28 +75,27 @@ "id": "urlTemplate", "type": "urlTemplate", "configuration": { - "template": "https://hacker-news.firebaseio.com/v0/item/{storyid}.json" + "template": "https://hn.algolia.com/api/v1/items/{storyID}" } }, { - "id": "storyid", + "id": "storyID", "type": "input", "configuration": { "schema": { - "title": "Hacker News Story id", + "title": "Hacker News Story ID", "properties": { - "storyid": { + "storyID": { "type": "number", "title": "Story ID", "default": "39788322", "description": "HackerNews Story ID to extract" } - }, - "type": "number" - } + } + }, + "type": "number" } } ], - "graphs": {}, - "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json" + "graphs": {} } \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/firebase_top_story_ids.json b/packages/breadboard-web/public/graphs/firebase_top_story_ids.json index 5a8943a0c35..ca5cd771bde 100644 --- a/packages/breadboard-web/public/graphs/firebase_top_story_ids.json +++ b/packages/breadboard-web/public/graphs/firebase_top_story_ids.json @@ -1,6 +1,6 @@ { "title": "Hacker News Firebase API Story IDs", - "description": "Board which returns the top story IDs from Hacker News", + "description": "Board which returns the top story ID from Hacker News", "version": "0.0.1", "edges": [ { @@ -85,6 +85,5 @@ } } ], - "graphs": {}, - "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json" + "graphs": {} } \ No newline at end of file diff --git a/packages/breadboard-web/public/local-boards.json b/packages/breadboard-web/public/local-boards.json index 9ff24e5665e..9cbc0245497 100644 --- a/packages/breadboard-web/public/local-boards.json +++ b/packages/breadboard-web/public/local-boards.json @@ -24,6 +24,11 @@ "url": "/graphs/agent.json", "version": "0.0.3" }, + { + "title": "Angolia search ", + "url": "/graphs/algolia_search.json", + "version": "0.0.1" + }, { "title": "Algolia Firebase API Story by ID", "url": "/graphs/algolia_story_from_id.json", diff --git a/packages/breadboard-web/src/boards/algolia_search.ts b/packages/breadboard-web/src/boards/algolia_search.ts new file mode 100644 index 00000000000..4c3c97f3420 --- /dev/null +++ b/packages/breadboard-web/src/boards/algolia_search.ts @@ -0,0 +1,147 @@ +import { board, base, code, OutputValues } from "@google-labs/breadboard"; + +import { core } from "@google-labs/core-kit"; +import { templates } from "@google-labs/template-kit"; + +export type PostItem = { + author: string; + created_at: string; + created_at_i: number; + id: number; + children: Comment[]; + story_id: number; + type: string; +}; + +export type Comment = PostItem & { + parent_id: number; + text: string; + title: null; +}; + +export type Story = PostItem & { + title: string; + points: number; + url: string; +}; + +export type HackerNewsAlgoliaSearchTags = + | "story" + | "comment" + | "poll" + | "pollopt" + | "show_hn" + | "ask_hn" + | "front_page"; +export type NumericFilterField = "created_at_i" | "points" | "num_comments"; +export type Operator = "<" | "<=" | "=" | ">" | ">="; + +export type HackerNewsSearchNumericFilters = { + operator: Operator; + field: NumericFilterField; + value: number; +}; +export type HackerNewAlgoliaSearchParameters = { + query: string; + tags?: HackerNewsAlgoliaSearchTags[]; + numericFilters?: HackerNewsSearchNumericFilters[]; + page?: number; + limit?: number; +}; + +export type SearchHits = OutputValues & { + hits: PostItem[]; +}; + +const spread = code<{ object: object }>((inputs) => { + const object = inputs.object; + if (typeof object !== "object") { + throw new Error(`object is of type ${typeof object} not object`); + } + return { ...object }; +}); + + +const slice = code<{ list: PostItem[], limit: number }>(({ list, limit }) => { + return { output: list.slice(0, limit) } +}) + +const limitInputSchema = { + type: "number", + title: "limit", + default: "1", + description: "The limit" +} + +const querySchema = { + type: "string", + title: "query", + default: "JavaScript", + description: "The query" +} + +const tagsSchema = { + type: "string", + title: "tags", + default: "JavaScript", + description: "The tags" +} + +const pageSchema = { + type: "string", + title: "page", + default: "2", + description: "the page" +} + +export default await board(() => { + const input = base.input({ + $id: "query", + schema: { + title: "Algolia Limit", + properties: { + query: querySchema, + limit: limitInputSchema, + tags: tagsSchema, + page: pageSchema, + }, + }, + type: "string", + }) + + let baseURL = "https://hn.algolia.com/api/v1/search?query={query}" + + if (input.tags != undefined) { + baseURL = baseURL + "&tags={tags}" + } + + if (input.page != undefined) { + baseURL = baseURL + "&page={page}" + } + + const urlTemplate = templates.urlTemplate({ + $id: "urlTemplate", + template: baseURL, + query:input.query, + page:input.page, + tags:input.tags, + + }); + + //input.to(urlTemplate) + + const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url }); + const response = spread({ $id: "spreadResponse", object: fetchUrl.response }); + + const sliced = slice({ list: response.hits as unknown as PostItem[], limit: input.limit as unknown as number }) + + return { + url: urlTemplate.url, + output: sliced + } + +}).serialize({ + title: "Angolia search ", + description: "Board which returns api results based on a query", + version: "0.0.1", +}) diff --git a/packages/breadboard-web/src/boards/algolia_story_from_id.ts b/packages/breadboard-web/src/boards/algolia_story_from_id.ts index 0bfd5b1d2fd..d666b3d9f93 100644 --- a/packages/breadboard-web/src/boards/algolia_story_from_id.ts +++ b/packages/breadboard-web/src/boards/algolia_story_from_id.ts @@ -1,7 +1,7 @@ -import { board, base, asRuntimeKit, BoardRunner, code} from "@google-labs/breadboard"; +import { board, base, code} from "@google-labs/breadboard"; -import Core, { core } from "@google-labs/core-kit"; -import TemplateKit, { templates } from "@google-labs/template-kit"; +import { core } from "@google-labs/core-kit"; +import { templates } from "@google-labs/template-kit"; const storyInputSchema = { type: "string", @@ -28,13 +28,13 @@ const firebaseBoardStoryFromId = await board(() => { properties: { storyID: storyInputSchema }, - required: ["storyID"], } }) const urlTemplate = templates.urlTemplate({ $id: "urlTemplate", template: "https://hn.algolia.com/api/v1/items/{storyID}", + storyID: input.storyID }); input.to(urlTemplate); @@ -58,17 +58,4 @@ const firebaseBoardStoryFromId = await board(() => { firebaseBoardStoryFromId.$schema = boardSchema -const kits = [asRuntimeKit(Core), asRuntimeKit(TemplateKit)] - -const runner = await BoardRunner.fromGraphDescriptor(firebaseBoardStoryFromId); -for await (const stop of runner.run({ kits: kits })) { - if (stop.type === "input") { - stop.inputs = { - storyID: "39788322", - }; - } else if (stop.type === "output") { - console.log(stop.outputs) - } -} - export default firebaseBoardStoryFromId \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/firebase_story_from_id.ts b/packages/breadboard-web/src/boards/firebase_story_from_id.ts index fe1a0009cf2..367055ecc2b 100644 --- a/packages/breadboard-web/src/boards/firebase_story_from_id.ts +++ b/packages/breadboard-web/src/boards/firebase_story_from_id.ts @@ -1,7 +1,7 @@ -import { board, base, code} from "@google-labs/breadboard"; +import { board, base , code} from "@google-labs/breadboard"; -import { core } from "@google-labs/core-kit"; -import { templates } from "@google-labs/template-kit"; +import { core } from "@google-labs/core-kit"; +import { templates } from "@google-labs/template-kit"; const storyInputSchema = { type: "number", @@ -18,26 +18,25 @@ const spread = code<{ object: object }>((inputs) => { return { ...object }; }); -const boardSchema = "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json"; - -export const firebaseBoardStoryFromId = await board(() => { +export default await board(() => { const input = base.input({ - $id: "storyid", + $id: "storyID", schema: { - title: "Hacker News Story id", + title: "Hacker News Story ID", properties: { - storyid: storyInputSchema + storyID: storyInputSchema, }, - type: "number" - } + }, + type: "number", }) - + const urlTemplate = templates.urlTemplate({ $id: "urlTemplate", - template: "https://hacker-news.firebaseio.com/v0/item/{storyid}.json", + template: "https://hn.algolia.com/api/v1/items/{storyID}", + storyID: input.storyID }); - - input.to(urlTemplate); + // BUG? + //input.to(urlTemplate); const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); @@ -47,17 +46,25 @@ export const firebaseBoardStoryFromId = await board(() => { response.to(output) - console.log(urlTemplate.url) - return {output} }).serialize({ title: "Hacker News Firebase API Story by ID", - description: "Board which returns story json", - version: "0.0.1",}) + description: "Board which returns story contents", + version: "0.0.1" +}) -firebaseBoardStoryFromId.$schema = boardSchema +// const kits = [asRuntimeKit(Core), asRuntimeKit(TemplateKit)] +// const runner = await BoardRunner.fromGraphDescriptor(firebaseBoardStoryFromId); +// for await (const stop of runner.run({ kits: kits })) { +// if (stop.type === "input") { +// stop.inputs = { +// storyID: "39788322", +// }; +// } else if (stop.type === "output") { +// console.log(stop.outputs) +// } +// } -export default firebaseBoardStoryFromId \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/firebase_top_story_ids.ts b/packages/breadboard-web/src/boards/firebase_top_story_ids.ts index 0dbc9eaff17..84ef40f5791 100644 --- a/packages/breadboard-web/src/boards/firebase_top_story_ids.ts +++ b/packages/breadboard-web/src/boards/firebase_top_story_ids.ts @@ -12,9 +12,7 @@ const slice = code<{ list: number[], limit: number }>(({ list, limit }) => { return { output: list.slice(0, limit) } }) -const boardSchema = "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json"; - -export const firebaseBoardTopStoryIds = await board(() => { +export default await board(() => { const input = base.input({ $id: "limit", schema: { @@ -35,9 +33,5 @@ export const firebaseBoardTopStoryIds = await board(() => { return { output } }).serialize({ title: "Hacker News Firebase API Story IDs", - description: "Board which returns the top story IDs from Hacker News", - version: "0.0.1",}) - -firebaseBoardTopStoryIds.$schema = boardSchema - -export default firebaseBoardTopStoryIds \ No newline at end of file + description: "Board which returns the top story ID from Hacker News", + version: "0.0.1",}) \ No newline at end of file From 60eac2418c3d52eff9f982a7c30d1c3a8220b1d5 Mon Sep 17 00:00:00 2001 From: jig925 <57284752+jig925@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:04:07 +0100 Subject: [PATCH 3/5] Hacker News boards --- .../public/graphs/bug_default_bug.json | 62 +++++++++++++++++++ .../public/graphs/bug_wire_all_bug.json | 62 +++++++++++++++++++ ...h.json => hacker_news_algolia_search.json} | 4 +- ...=> hacker_news_algolia_story_from_id.json} | 16 ++--- ...> hacker_news_firebase_story_from_id.json} | 6 +- ...> hacker_news_firebase_top_story_ids.json} | 4 +- .../breadboard-web/public/local-boards.json | 48 ++++++++------ .../src/boards/bug_default_bug.ts | 33 ++++++++++ .../src/boards/bug_wire_all_bug.ts | 34 ++++++++++ ...earch.ts => hacker_news_algolia_search.ts} | 6 +- ...s => hacker_news_algolia_story_from_id.ts} | 19 ++---- ... => hacker_news_firebase_story_from_id.ts} | 23 +------ ... => hacker_news_firebase_top_story_ids.ts} | 4 +- 13 files changed, 242 insertions(+), 79 deletions(-) create mode 100644 packages/breadboard-web/public/graphs/bug_default_bug.json create mode 100644 packages/breadboard-web/public/graphs/bug_wire_all_bug.json rename packages/breadboard-web/public/graphs/{algolia_search.json => hacker_news_algolia_search.json} (95%) rename packages/breadboard-web/public/graphs/{algolia_story_from_id.json => hacker_news_algolia_story_from_id.json} (79%) rename packages/breadboard-web/public/graphs/{firebase_story_from_id.json => hacker_news_firebase_story_from_id.json} (89%) rename packages/breadboard-web/public/graphs/{firebase_top_story_ids.json => hacker_news_firebase_top_story_ids.json} (90%) create mode 100644 packages/breadboard-web/src/boards/bug_default_bug.ts create mode 100644 packages/breadboard-web/src/boards/bug_wire_all_bug.ts rename packages/breadboard-web/src/boards/{algolia_search.ts => hacker_news_algolia_search.ts} (95%) rename packages/breadboard-web/src/boards/{algolia_story_from_id.ts => hacker_news_algolia_story_from_id.ts} (68%) rename packages/breadboard-web/src/boards/{firebase_story_from_id.ts => hacker_news_firebase_story_from_id.ts} (66%) rename packages/breadboard-web/src/boards/{firebase_top_story_ids.ts => hacker_news_firebase_top_story_ids.ts} (86%) diff --git a/packages/breadboard-web/public/graphs/bug_default_bug.json b/packages/breadboard-web/public/graphs/bug_default_bug.json new file mode 100644 index 00000000000..6d9f713144c --- /dev/null +++ b/packages/breadboard-web/public/graphs/bug_default_bug.json @@ -0,0 +1,62 @@ +{ + "title": "Board Not Required Bug", + "description": "Board which demonstrates a bug where breadboard web wont continue without a non required variable", + "edges": [ + { + "from": "urlTemplate", + "to": "output-2", + "out": "url", + "in": "output" + }, + { + "from": "input", + "to": "urlTemplate", + "out": "myNumber", + "in": "myNumber" + } + ], + "nodes": [ + { + "id": "output-2", + "type": "output", + "configuration": { + "schema": { + "type": "object", + "properties": { + "output": { + "title": "url", + "description": "The resulting URL that was produced by filling in the placeholders in the template", + "type": "string" + } + } + } + } + }, + { + "id": "urlTemplate", + "type": "urlTemplate", + "configuration": { + "template": "https://hn.algolia.com/api/v1/items/{myNumber}" + } + }, + { + "id": "input", + "type": "input", + "configuration": { + "schema": { + "title": "My Inputs", + "properties": { + "myNumber": { + "type": "number", + "title": "my Number", + "default": "1", + "description": "myNumber" + } + } + }, + "type": "number" + } + } + ], + "graphs": {} +} \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/bug_wire_all_bug.json b/packages/breadboard-web/public/graphs/bug_wire_all_bug.json new file mode 100644 index 00000000000..6cd59baa3bc --- /dev/null +++ b/packages/breadboard-web/public/graphs/bug_wire_all_bug.json @@ -0,0 +1,62 @@ +{ + "title": "Board Defaults Not Used. urlTemplate Error", + "description": "Board which demonstrates a bug where breadboard web does not use default values and urlTemplate does not error if parameters are missing", + "edges": [ + { + "from": "urlTemplate", + "to": "output-2", + "out": "url", + "in": "output" + }, + { + "from": "input", + "to": "urlTemplate", + "out": "*", + "in": "" + } + ], + "nodes": [ + { + "id": "output-2", + "type": "output", + "configuration": { + "schema": { + "type": "object", + "properties": { + "output": { + "title": "url", + "description": "The resulting URL that was produced by filling in the placeholders in the template", + "type": "string" + } + } + } + } + }, + { + "id": "urlTemplate", + "type": "urlTemplate", + "configuration": { + "template": "https://hn.algolia.com/api/v1/items/{myNumber}" + } + }, + { + "id": "input", + "type": "input", + "configuration": { + "schema": { + "title": "My Inputs", + "properties": { + "myNumber": { + "type": "number", + "title": "my Number", + "default": "1", + "description": "myNumber" + } + } + }, + "type": "number" + } + } + ], + "graphs": {} +} \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/algolia_search.json b/packages/breadboard-web/public/graphs/hacker_news_algolia_search.json similarity index 95% rename from packages/breadboard-web/public/graphs/algolia_search.json rename to packages/breadboard-web/public/graphs/hacker_news_algolia_search.json index 2fe6a3f4406..4d00b5ad6ba 100644 --- a/packages/breadboard-web/public/graphs/algolia_search.json +++ b/packages/breadboard-web/public/graphs/hacker_news_algolia_search.json @@ -1,6 +1,6 @@ { - "title": "Angolia search ", - "description": "Board which returns api results based on a query", + "title": "Hacker News Angolia search ", + "description": "Board which returns API results based on a query using the Hacker News Angolia API", "version": "0.0.1", "edges": [ { diff --git a/packages/breadboard-web/public/graphs/algolia_story_from_id.json b/packages/breadboard-web/public/graphs/hacker_news_algolia_story_from_id.json similarity index 79% rename from packages/breadboard-web/public/graphs/algolia_story_from_id.json rename to packages/breadboard-web/public/graphs/hacker_news_algolia_story_from_id.json index 02e6e1fbc2a..67e6811facd 100644 --- a/packages/breadboard-web/public/graphs/algolia_story_from_id.json +++ b/packages/breadboard-web/public/graphs/hacker_news_algolia_story_from_id.json @@ -1,8 +1,7 @@ { - "title": "Algolia Firebase API Story by ID", - "description": "Board which returns story contents", + "title": "Hacker News Algolia API Story by ID", + "description": "Board which returns story contents using the Hacker News Algolia API", "version": "0.0.1", - "url": "https://github.com/ExaDev/breadboard-examples/tree/hackerNews-toolworker/src/examples/hackerNews/algolia", "edges": [ { "from": "main", @@ -33,12 +32,6 @@ "to": "urlTemplate", "out": "storyID", "in": "storyID" - }, - { - "from": "storyID", - "to": "urlTemplate", - "out": "*", - "in": "" } ], "nodes": [ @@ -96,13 +89,12 @@ "type": "string", "title": "Story ID", "default": "39788322", - "description": "HackerNews Story ID to extract" + "description": "Hacker News Story ID to extract" } } } } } ], - "graphs": {}, - "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json" + "graphs": {} } \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/firebase_story_from_id.json b/packages/breadboard-web/public/graphs/hacker_news_firebase_story_from_id.json similarity index 89% rename from packages/breadboard-web/public/graphs/firebase_story_from_id.json rename to packages/breadboard-web/public/graphs/hacker_news_firebase_story_from_id.json index 64303b35416..387373642a6 100644 --- a/packages/breadboard-web/public/graphs/firebase_story_from_id.json +++ b/packages/breadboard-web/public/graphs/hacker_news_firebase_story_from_id.json @@ -1,6 +1,6 @@ { "title": "Hacker News Firebase API Story by ID", - "description": "Board which returns story contents", + "description": "Board which returns story contents using the Hacker News Firebase API", "version": "0.0.1", "edges": [ { @@ -75,7 +75,7 @@ "id": "urlTemplate", "type": "urlTemplate", "configuration": { - "template": "https://hn.algolia.com/api/v1/items/{storyID}" + "template": "https://hacker-news.firebaseio.com/v0/item/{storyID}.json" } }, { @@ -89,7 +89,7 @@ "type": "number", "title": "Story ID", "default": "39788322", - "description": "HackerNews Story ID to extract" + "description": "Hacker News Story ID to extract" } } }, diff --git a/packages/breadboard-web/public/graphs/firebase_top_story_ids.json b/packages/breadboard-web/public/graphs/hacker_news_firebase_top_story_ids.json similarity index 90% rename from packages/breadboard-web/public/graphs/firebase_top_story_ids.json rename to packages/breadboard-web/public/graphs/hacker_news_firebase_top_story_ids.json index ca5cd771bde..ea9451c3567 100644 --- a/packages/breadboard-web/public/graphs/firebase_top_story_ids.json +++ b/packages/breadboard-web/public/graphs/hacker_news_firebase_top_story_ids.json @@ -1,6 +1,6 @@ { "title": "Hacker News Firebase API Story IDs", - "description": "Board which returns the top story ID from Hacker News", + "description": "Board which returns the top story ID using the Hacker News Firebase API", "version": "0.0.1", "edges": [ { @@ -77,7 +77,7 @@ "type": "number", "title": "Story Limit", "default": "1", - "description": "The Number of HackerNews Story ID's to return" + "description": "The Number of Hacker News Story ID's to return" } } }, diff --git a/packages/breadboard-web/public/local-boards.json b/packages/breadboard-web/public/local-boards.json index 9cbc0245497..fd64e514183 100644 --- a/packages/breadboard-web/public/local-boards.json +++ b/packages/breadboard-web/public/local-boards.json @@ -24,16 +24,6 @@ "url": "/graphs/agent.json", "version": "0.0.3" }, - { - "title": "Angolia search ", - "url": "/graphs/algolia_search.json", - "version": "0.0.1" - }, - { - "title": "Algolia Firebase API Story by ID", - "url": "/graphs/algolia_story_from_id.json", - "version": "0.0.1" - }, { "title": "Ask User", "url": "/graphs/ask-user.json", @@ -59,6 +49,14 @@ "url": "/graphs/board-caller.json", "version": "0.0.6" }, + { + "title": "Board Not Required Bug", + "url": "/graphs/bug_default_bug.json" + }, + { + "title": "Board Defaults Not Used. urlTemplate Error", + "url": "/graphs/bug_wire_all_bug.json" + }, { "title": "Example of @breadboard-ai/build", "url": "/graphs/build-example.json", @@ -88,16 +86,6 @@ "title": "Error board", "url": "/graphs/error.json" }, - { - "title": "Hacker News Firebase API Story by ID", - "url": "/graphs/firebase_story_from_id.json", - "version": "0.0.1" - }, - { - "title": "Hacker News Firebase API Story IDs", - "url": "/graphs/firebase_top_story_ids.json", - "version": "0.0.1" - }, { "title": "Gemini Pro Generator", "url": "/graphs/gemini-generator.json", @@ -113,6 +101,26 @@ "url": "/graphs/gemini-simple.json", "version": "0.0.1" }, + { + "title": "Hacker News Angolia search ", + "url": "/graphs/hacker_news_algolia_search.json", + "version": "0.0.1" + }, + { + "title": "Hacker News Algolia API Story by ID", + "url": "/graphs/hacker_news_algolia_story_from_id.json", + "version": "0.0.1" + }, + { + "title": "Hacker News Firebase API Story by ID", + "url": "/graphs/hacker_news_firebase_story_from_id.json", + "version": "0.0.1" + }, + { + "title": "Hacker News Firebase API Story IDs", + "url": "/graphs/hacker_news_firebase_top_story_ids.json", + "version": "0.0.1" + }, { "title": "Healer", "url": "/graphs/healer.json", diff --git a/packages/breadboard-web/src/boards/bug_default_bug.ts b/packages/breadboard-web/src/boards/bug_default_bug.ts new file mode 100644 index 00000000000..caab4ba1ceb --- /dev/null +++ b/packages/breadboard-web/src/boards/bug_default_bug.ts @@ -0,0 +1,33 @@ +import { board, base } from "@google-labs/breadboard"; +import { templates } from "@google-labs/template-kit"; + +const inputSchema = { + type: "number", + title: "my Number", + default: "1", + description: "myNumber", +}; + +export default await board(() => { + const input = base.input({ + $id: "input", + schema: { + title: "My Inputs", + properties: { + myNumber: inputSchema, + }, + }, + type: "number", + }) + + const urlTemplate = templates.urlTemplate({ + $id: "urlTemplate", + template: "https://hn.algolia.com/api/v1/items/{myNumber}", + myNumber: input.myNumber + }); + + return {output : urlTemplate.url} +}).serialize({ + title: "Board Not Required Bug", + description: "Board which demonstrates a bug where breadboard web wont continue without a non required variable" +}) \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/bug_wire_all_bug.ts b/packages/breadboard-web/src/boards/bug_wire_all_bug.ts new file mode 100644 index 00000000000..fe0624bd6a4 --- /dev/null +++ b/packages/breadboard-web/src/boards/bug_wire_all_bug.ts @@ -0,0 +1,34 @@ +import { board, base } from "@google-labs/breadboard"; +import { templates } from "@google-labs/template-kit"; + +const inputSchema = { + type: "number", + title: "my Number", + default: "1", + description: "myNumber", +}; + +export default await board(() => { + const input = base.input({ + $id: "input", + schema: { + title: "My Inputs", + properties: { + myNumber: inputSchema, + }, + }, + type: "number", + }) + + const urlTemplate = templates.urlTemplate({ + $id: "urlTemplate", + template: "https://hn.algolia.com/api/v1/items/{myNumber}", + }); + + input.to(urlTemplate) + + return {output : urlTemplate.url} +}).serialize({ + title: "Board Defaults Not Used. urlTemplate Error", + description: "Board which demonstrates a bug where breadboard web does not use default values and urlTemplate does not error if parameters are missing" +}) \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/algolia_search.ts b/packages/breadboard-web/src/boards/hacker_news_algolia_search.ts similarity index 95% rename from packages/breadboard-web/src/boards/algolia_search.ts rename to packages/breadboard-web/src/boards/hacker_news_algolia_search.ts index 4c3c97f3420..b420458a0f0 100644 --- a/packages/breadboard-web/src/boards/algolia_search.ts +++ b/packages/breadboard-web/src/boards/hacker_news_algolia_search.ts @@ -128,8 +128,6 @@ export default await board(() => { }); - //input.to(urlTemplate) - const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url }); const response = spread({ $id: "spreadResponse", object: fetchUrl.response }); @@ -141,7 +139,7 @@ export default await board(() => { } }).serialize({ - title: "Angolia search ", - description: "Board which returns api results based on a query", + title: "Hacker News Angolia search ", + description: "Board which returns API results based on a query using the Hacker News Angolia API", version: "0.0.1", }) diff --git a/packages/breadboard-web/src/boards/algolia_story_from_id.ts b/packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts similarity index 68% rename from packages/breadboard-web/src/boards/algolia_story_from_id.ts rename to packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts index d666b3d9f93..cd04a98e1fa 100644 --- a/packages/breadboard-web/src/boards/algolia_story_from_id.ts +++ b/packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts @@ -7,7 +7,7 @@ const storyInputSchema = { type: "string", title: "Story ID", default: "39788322", - description: "HackerNews Story ID to extract", + description: "Hacker News Story ID to extract", }; const spread = code<{ object: object }>((inputs) => { @@ -18,9 +18,7 @@ const spread = code<{ object: object }>((inputs) => { return { ...object }; }); -const boardSchema = "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json"; - -const firebaseBoardStoryFromId = await board(() => { +export default await board(() => { const input = base.input({ $id: "storyID", schema: { @@ -36,9 +34,7 @@ const firebaseBoardStoryFromId = await board(() => { template: "https://hn.algolia.com/api/v1/items/{storyID}", storyID: input.storyID }); - - input.to(urlTemplate); - + const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); const output = base.output({ $id: "main" }); @@ -50,12 +46,7 @@ const firebaseBoardStoryFromId = await board(() => { return {output} }).serialize({ - title: "Algolia Firebase API Story by ID", - description: "Board which returns story contents", + title: "Hacker News Algolia API Story by ID", + description: "Board which returns story contents using the Hacker News Algolia API", version: "0.0.1", - url: "https://github.com/ExaDev/breadboard-examples/tree/hackerNews-toolworker/src/examples/hackerNews/algolia" }) - -firebaseBoardStoryFromId.$schema = boardSchema - -export default firebaseBoardStoryFromId \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/firebase_story_from_id.ts b/packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts similarity index 66% rename from packages/breadboard-web/src/boards/firebase_story_from_id.ts rename to packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts index 367055ecc2b..4a777a011ed 100644 --- a/packages/breadboard-web/src/boards/firebase_story_from_id.ts +++ b/packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts @@ -7,7 +7,7 @@ const storyInputSchema = { type: "number", title: "Story ID", default: "39788322", - description: "HackerNews Story ID to extract", + description: "Hacker News Story ID to extract", }; const spread = code<{ object: object }>((inputs) => { @@ -32,11 +32,9 @@ export default await board(() => { const urlTemplate = templates.urlTemplate({ $id: "urlTemplate", - template: "https://hn.algolia.com/api/v1/items/{storyID}", + template: "https://hacker-news.firebaseio.com/v0/item/{storyID}.json", storyID: input.storyID }); - // BUG? - //input.to(urlTemplate); const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); @@ -50,21 +48,6 @@ export default await board(() => { }).serialize({ title: "Hacker News Firebase API Story by ID", - description: "Board which returns story contents", + description: "Board which returns story contents using the Hacker News Firebase API", version: "0.0.1" }) - - -// const kits = [asRuntimeKit(Core), asRuntimeKit(TemplateKit)] - -// const runner = await BoardRunner.fromGraphDescriptor(firebaseBoardStoryFromId); -// for await (const stop of runner.run({ kits: kits })) { -// if (stop.type === "input") { -// stop.inputs = { -// storyID: "39788322", -// }; -// } else if (stop.type === "output") { -// console.log(stop.outputs) -// } -// } - diff --git a/packages/breadboard-web/src/boards/firebase_top_story_ids.ts b/packages/breadboard-web/src/boards/hacker_news_firebase_top_story_ids.ts similarity index 86% rename from packages/breadboard-web/src/boards/firebase_top_story_ids.ts rename to packages/breadboard-web/src/boards/hacker_news_firebase_top_story_ids.ts index 84ef40f5791..b002645f9d2 100644 --- a/packages/breadboard-web/src/boards/firebase_top_story_ids.ts +++ b/packages/breadboard-web/src/boards/hacker_news_firebase_top_story_ids.ts @@ -5,7 +5,7 @@ const limitInputSchema = { type: "number", title: "Story Limit", default: "1", - description: "The Number of HackerNews Story ID's to return" + description: "The Number of Hacker News Story ID's to return" } const slice = code<{ list: number[], limit: number }>(({ list, limit }) => { @@ -33,5 +33,5 @@ export default await board(() => { return { output } }).serialize({ title: "Hacker News Firebase API Story IDs", - description: "Board which returns the top story ID from Hacker News", + description: "Board which returns the top story ID using the Hacker News Firebase API", version: "0.0.1",}) \ No newline at end of file From f73a2c48f79ffbcdcb6c854254c13a2cdb40b3df Mon Sep 17 00:00:00 2001 From: jig925 <57284752+jig925@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:42:46 +0100 Subject: [PATCH 4/5] deleted bug boards --- .../public/graphs/bug_default_bug.json | 62 ------------------- .../public/graphs/bug_wire_all_bug.json | 62 ------------------- .../breadboard-web/public/local-boards.json | 8 --- .../src/boards/bug_default_bug.ts | 33 ---------- .../src/boards/bug_wire_all_bug.ts | 34 ---------- 5 files changed, 199 deletions(-) delete mode 100644 packages/breadboard-web/public/graphs/bug_default_bug.json delete mode 100644 packages/breadboard-web/public/graphs/bug_wire_all_bug.json delete mode 100644 packages/breadboard-web/src/boards/bug_default_bug.ts delete mode 100644 packages/breadboard-web/src/boards/bug_wire_all_bug.ts diff --git a/packages/breadboard-web/public/graphs/bug_default_bug.json b/packages/breadboard-web/public/graphs/bug_default_bug.json deleted file mode 100644 index 6d9f713144c..00000000000 --- a/packages/breadboard-web/public/graphs/bug_default_bug.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "title": "Board Not Required Bug", - "description": "Board which demonstrates a bug where breadboard web wont continue without a non required variable", - "edges": [ - { - "from": "urlTemplate", - "to": "output-2", - "out": "url", - "in": "output" - }, - { - "from": "input", - "to": "urlTemplate", - "out": "myNumber", - "in": "myNumber" - } - ], - "nodes": [ - { - "id": "output-2", - "type": "output", - "configuration": { - "schema": { - "type": "object", - "properties": { - "output": { - "title": "url", - "description": "The resulting URL that was produced by filling in the placeholders in the template", - "type": "string" - } - } - } - } - }, - { - "id": "urlTemplate", - "type": "urlTemplate", - "configuration": { - "template": "https://hn.algolia.com/api/v1/items/{myNumber}" - } - }, - { - "id": "input", - "type": "input", - "configuration": { - "schema": { - "title": "My Inputs", - "properties": { - "myNumber": { - "type": "number", - "title": "my Number", - "default": "1", - "description": "myNumber" - } - } - }, - "type": "number" - } - } - ], - "graphs": {} -} \ No newline at end of file diff --git a/packages/breadboard-web/public/graphs/bug_wire_all_bug.json b/packages/breadboard-web/public/graphs/bug_wire_all_bug.json deleted file mode 100644 index 6cd59baa3bc..00000000000 --- a/packages/breadboard-web/public/graphs/bug_wire_all_bug.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "title": "Board Defaults Not Used. urlTemplate Error", - "description": "Board which demonstrates a bug where breadboard web does not use default values and urlTemplate does not error if parameters are missing", - "edges": [ - { - "from": "urlTemplate", - "to": "output-2", - "out": "url", - "in": "output" - }, - { - "from": "input", - "to": "urlTemplate", - "out": "*", - "in": "" - } - ], - "nodes": [ - { - "id": "output-2", - "type": "output", - "configuration": { - "schema": { - "type": "object", - "properties": { - "output": { - "title": "url", - "description": "The resulting URL that was produced by filling in the placeholders in the template", - "type": "string" - } - } - } - } - }, - { - "id": "urlTemplate", - "type": "urlTemplate", - "configuration": { - "template": "https://hn.algolia.com/api/v1/items/{myNumber}" - } - }, - { - "id": "input", - "type": "input", - "configuration": { - "schema": { - "title": "My Inputs", - "properties": { - "myNumber": { - "type": "number", - "title": "my Number", - "default": "1", - "description": "myNumber" - } - } - }, - "type": "number" - } - } - ], - "graphs": {} -} \ No newline at end of file diff --git a/packages/breadboard-web/public/local-boards.json b/packages/breadboard-web/public/local-boards.json index fd64e514183..35b1964022e 100644 --- a/packages/breadboard-web/public/local-boards.json +++ b/packages/breadboard-web/public/local-boards.json @@ -49,14 +49,6 @@ "url": "/graphs/board-caller.json", "version": "0.0.6" }, - { - "title": "Board Not Required Bug", - "url": "/graphs/bug_default_bug.json" - }, - { - "title": "Board Defaults Not Used. urlTemplate Error", - "url": "/graphs/bug_wire_all_bug.json" - }, { "title": "Example of @breadboard-ai/build", "url": "/graphs/build-example.json", diff --git a/packages/breadboard-web/src/boards/bug_default_bug.ts b/packages/breadboard-web/src/boards/bug_default_bug.ts deleted file mode 100644 index caab4ba1ceb..00000000000 --- a/packages/breadboard-web/src/boards/bug_default_bug.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { board, base } from "@google-labs/breadboard"; -import { templates } from "@google-labs/template-kit"; - -const inputSchema = { - type: "number", - title: "my Number", - default: "1", - description: "myNumber", -}; - -export default await board(() => { - const input = base.input({ - $id: "input", - schema: { - title: "My Inputs", - properties: { - myNumber: inputSchema, - }, - }, - type: "number", - }) - - const urlTemplate = templates.urlTemplate({ - $id: "urlTemplate", - template: "https://hn.algolia.com/api/v1/items/{myNumber}", - myNumber: input.myNumber - }); - - return {output : urlTemplate.url} -}).serialize({ - title: "Board Not Required Bug", - description: "Board which demonstrates a bug where breadboard web wont continue without a non required variable" -}) \ No newline at end of file diff --git a/packages/breadboard-web/src/boards/bug_wire_all_bug.ts b/packages/breadboard-web/src/boards/bug_wire_all_bug.ts deleted file mode 100644 index fe0624bd6a4..00000000000 --- a/packages/breadboard-web/src/boards/bug_wire_all_bug.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { board, base } from "@google-labs/breadboard"; -import { templates } from "@google-labs/template-kit"; - -const inputSchema = { - type: "number", - title: "my Number", - default: "1", - description: "myNumber", -}; - -export default await board(() => { - const input = base.input({ - $id: "input", - schema: { - title: "My Inputs", - properties: { - myNumber: inputSchema, - }, - }, - type: "number", - }) - - const urlTemplate = templates.urlTemplate({ - $id: "urlTemplate", - template: "https://hn.algolia.com/api/v1/items/{myNumber}", - }); - - input.to(urlTemplate) - - return {output : urlTemplate.url} -}).serialize({ - title: "Board Defaults Not Used. urlTemplate Error", - description: "Board which demonstrates a bug where breadboard web does not use default values and urlTemplate does not error if parameters are missing" -}) \ No newline at end of file From 5f29b5b2203c0f61df95df2a511dd96dc47ff163 Mon Sep 17 00:00:00 2001 From: jig925 <57284752+jig925@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:14:49 +0100 Subject: [PATCH 5/5] formatting --- .../src/boards/hacker_news_algolia_story_from_id.ts | 2 -- .../src/boards/hacker_news_firebase_story_from_id.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts b/packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts index cd04a98e1fa..26a1a0c018b 100644 --- a/packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts +++ b/packages/breadboard-web/src/boards/hacker_news_algolia_story_from_id.ts @@ -36,9 +36,7 @@ export default await board(() => { }); const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); - const output = base.output({ $id: "main" }); - const response = spread({ $id: "spreadResponse", object: fetchUrl.response }); response.to(output) diff --git a/packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts b/packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts index 4a777a011ed..dcf15d6f729 100644 --- a/packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts +++ b/packages/breadboard-web/src/boards/hacker_news_firebase_story_from_id.ts @@ -37,9 +37,7 @@ export default await board(() => { }); const fetchUrl = core.fetch({ $id: "fetch", method: "GET", url: urlTemplate.url}); - const output = base.output({ $id: "main" }); - const response = spread({ $id: "spreadResponse", object: fetchUrl.response }); response.to(output)