breadboard-ai / breadboard

A library for prototyping generative AI applications.
Apache License 2.0
187 stars 26 forks source link

Kit Namespacing #111

Open mattsoulanille opened 1 year ago

mattsoulanille commented 1 year ago

In TypeScript, kits provide a nice intrinsic implementation of namespacing by being separate objects:

const simpleMath = board.addKit(SimpleMath);
const advancedMath = board.addKit(AdvancedMath);
const add = simpleMath.add();
const fft = advancedMath.fourierTransform();

From a user's perspective, there's no issue here if advancedMath also defines the add node, since they always know which one they're using based on which kit object they're referencing.

However, this is not the case for node execution or serialization.

Node execution first concatenates all the NodeHandlers from all the loaded kits into a single object. Then, it looks up each node by type to find its node handler. This means if two kits define a node with the same NodeTypeIdentifier, the last one loaded into Breadboard will be the one that actually gets run, and the first one will always be unused. (Other notes: TraversalMachine takes a GraphDescriptor, which is JSON-serializable).

This also means that serialization doesn't account for NodeTypeIdentifier collisions, since serialization is conveniently just to JSON.stringify the board.

Solving this should not prevent a board from being JSON.stringified, so we can't just change NodeTypeIdentifier to be a reference to the kit's function for that node. Here are a few options:

dglazkov commented 1 year ago

@mattsoulanille I wonder if we could steal some of the logic from XML namespaces?