Skip to content

Conversation

dqbd
Copy link
Collaborator

@dqbd dqbd commented Aug 8, 2025

Rethinking the current state of Zod in state definition, I think we can extend the Annotation function instead to accept Standard Schema objects.

Usage:

import { z } from "zod";
import { type } from "arktype";

const graph = new StateGraph(
  Annotation.Root({
    valid: z.boolean(),
    random: type("string"),
    complex: Annotation({
      state: z.string(),
      update: z.union([z.string(), z.array(z.string())]),
      reducer(state, update) {
        if (Array.isArray(update)) return [state, ...update].join(", ");
        return [state, update].join(", ");
      },
      default: () => "[default]",
    }),
  })
);

TODO:

  • Perform actual validation of inputs using the standard schema
  • Use runtime JSON schema generation for Zod
  • Add tests for Arktype, Valibot et all.
  • Consider renaming Annotation to channel
  • Think about getting rid of Annotation.Root

Copy link

changeset-bot bot commented Aug 8, 2025

🦋 Changeset detected

Latest commit: 64b0654

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dqbd dqbd force-pushed the dqbd/standard-schema branch from c38483e to 64b0654 Compare September 2, 2025 13:03
@dqbd dqbd changed the base branch from main to v1 September 5, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant