Skip to main content

Defining a Basic Node

Defining nodes in Uix can be very simple. No methods are necessary to generate a node without vector embeddings, unique indexes, etc.

How to Define a Node

As seen in the Getting Started section, defining nodes can be done using Zod schemas and the defineNodeType function.

  1. Start by importing defineNodeType from "@thinairthings/uix" and z from "Zod"
./src/libs/nodes/GenericNodeType.ts
import { z } from "zod";
import { defineNodeType } from "@thinairthings/uix";
  1. Define your node type and stateSchema using defineNodeType and Zod
./src/libs/nodes/GenericNodeType.ts
import { z } from "zod";
import { defineNodeType } from "@thinairthings/uix";
export const GenericNodeType = defineNodeType(
"Generic",
z.object({
firstName: z.string(),
lastName: z.string().optional(),
job: z.string().catch("Software Engineer"),
age: z.number().catch(18),
email: z.string().email()
}),
)

More Information

Conveniently, Zod methods such as catch() and optional() and other zod validation methods can be used in the stateSchema. This makes optional properties very easy to handle.

Additionally thanks to Zod, using your defined nodes as types is extremely convenient, for example:

import { TypeOf } from "zod";
import { GenericNodeType } from "../../libs/nodes/GenericNodeType.ts"

function doSomethingWithGenericNode(genericNode: TypeOf<typeof GenericNodeType.stateSchema>) {
...
}

In order to use any generated nodes, make sure to add them to your uix.config.ts file like such:

uix.config.ts
import { defineConfig } from "@thinairthings/uix";
import { NullNodeType } from "./src/libs/nodes/NullNodeType";
import { GenericNodeType } from "./src/libs/nodes/GenericNodeType";

export default defineConfig({
type: "Base",
nodeTypeSet: [NullNodeType, GenericNodeType],
});

And that you run the CLI to regenerate your functions using npm run uix

(Note: if you have any issues doing this, please refer back to the getting started section)

What else?

There's a lot more you can do with Uix node definitions than just generating a basic node like such. Let's dive more into that in the next section.