breadboard
breadboard copied to clipboard
when a node receives specific properties from one node and `*` properties from another node a race condition is caused
See the lines with comments below.
this is a scenario I've been able to work around in most cases, but in this scenario, the emitted properties from the fetch
node could be ANYTHING.
Essentially, I'd like a way for the to
node to resolve only once it receives one or more properties from the from
node.
If we speak in RegEx terms, I'd like to be able to wire +
properties rather than *
properties.
import { base, board, code } from "@google-labs/breadboard";
import { core } from "@google-labs/core-kit";
import { templates } from "@google-labs/template-kit";
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 graph = board(() => {
const input = base.input({
$id: "query",
schema: {
title: "OpenAlex Search",
properties: {
requestUri: {
type: "string",
title: "Request URI",
default: "works/random",
},
},
type: "object",
required: ["requestUri"],
additionalProperties: false,
},
});
const urlTemplate = templates.urlTemplate({
$id: "urlTemplate",
template: "https://api.openalex.org/{requestUri}",
requestUri: input.requestUri,
});
const fetchUrl = core.fetch({
$id: "fetch",
method: "GET",
url: urlTemplate.url,
});
const response = spread({ $id: "spreadResponse", object: fetchUrl.response });
const output = base.output({
schema: {
type: "object",
properties: {
requestUrl: {
type: "string",
description: "URL to fetch",
title: "URL",
},
},
required: ["url"],
},
$id: "result",
requestUrl: urlTemplate.url,
// id: response.id, // a known property needs to be passed in order to block the `to` node from being resolved until the `from` node is resolved
// ...response, // this does not work alone
});
response.to(output); // this does not work alone
return output;
});
export default await graph.serialize({
title: "Open Alex API Query",
description: "Query the Open Alex API",
version: "0.0.1",
});