Validate machine input against its schema; add chat-with-pdf example - #88
Merged
Conversation
XState's `schemas` are types only — it never validates, and it resolves
`schemas.input` to one type shared by `createActor`'s `input` option and
the `context: ({ input })` factory. A field declared with a default was
therefore both absent at runtime and required at the call site.
runAgent/createAgentActor now validate `options.input` against the
machine's registered input schema before the actor starts. The resolved
value (defaults filled, transforms applied) is what reaches the actor,
the replayable init entry, and the `run.start` trace, so a replay
reproduces the run even if a default is computed. Invalid input throws
an AgentError with code `invalid-machine-input`, matching how a
mismatched resume snapshot behaves; omitted input still skips
validation.
Types: `setupAgent` brands the machine's input type with its own schema,
and runAgent's `input` is now `AgentInputFrom<TMachine>`, which reads the
schema's pre-validation side while the context factory keeps the
validated one. The brand is a `~`-prefixed phantom property rather than a
unique symbol — a symbol has to be exported as a runtime value for
declaration emit to name it. Only object-shaped input is branded, since
intersecting a brand into xstate's NonReducibleUnknown collapses members
to never. Standard Schema throughout; no validation library referenced.
Also ports agentcn's chat-with-PDF quiz recipe, where the quiz loop lives
in instructions.md as prose. The sequencing moves into the machine: one
question per entry into `asking`, a refreshEvery guard instead of "after
3-4 questions", covered pages fed back to retrieval as excludePages,
documentId threaded from context, page hints read off the chunk, and an
idle choosingDocument state when the library is ambiguous. Voice and
question formatting stay in the prompt.
🦋 Changeset detectedLatest commit: d857a8a The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
XState's
schemasare types only — it never validates, and it resolvesschemas.inputto one type shared bycreateActor'sinputoption and thecontext: ({ input })factory. A field declared with a default was therefore both absent at runtime and required at the call site.runAgent/createAgentActor now validate
options.inputagainst the machine's registered input schema before the actor starts. The resolved value (defaults filled, transforms applied) is what reaches the actor, the replayable init entry, and therun.starttrace, so a replay reproduces the run even if a default is computed. Invalid input throws an AgentError with codeinvalid-machine-input, matching how a mismatched resume snapshot behaves; omitted input still skips validation.Types:
setupAgentbrands the machine's input type with its own schema, and runAgent'sinputis nowAgentInputFrom<TMachine>, which reads the schema's pre-validation side while the context factory keeps the validated one. The brand is a~-prefixed phantom property rather than a unique symbol — a symbol has to be exported as a runtime value for declaration emit to name it. Only object-shaped input is branded, since intersecting a brand into xstate's NonReducibleUnknown collapses members to never. Standard Schema throughout; no validation library referenced.Also ports agentcn's chat-with-PDF quiz recipe, where the quiz loop lives in instructions.md as prose. The sequencing moves into the machine: one question per entry into
asking, a refreshEvery guard instead of "after 3-4 questions", covered pages fed back to retrieval as excludePages, documentId threaded from context, page hints read off the chunk, and an idle choosingDocument state when the library is ambiguous. Voice and question formatting stay in the prompt.