diff --git a/.changeset/pre.json b/.changeset/pre.json index 7199d882..4125129d 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -71,6 +71,7 @@ "tidy-agents-run-anywhere", "trajectory-matchers", "typed-tools-union-output-core-helpers", + "validate-machine-input", "versioned-trace-schema", "workflow-json-schema-drift" ] diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ad66468..8dc4714c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # @statelyai/agent +## 2.0.0-alpha.15 + +### Minor Changes + +- [#88](https://github.com/statelyai/agent/pull/88) [`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce) Thanks [@davidkpiano](https://github.com/davidkpiano)! - **Machine input is validated against its schema, and defaulted fields are optional at the call site.** + + 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 declared input schema before the actor starts: defaults are filled and transforms applied, and the resolved value is what reaches the actor, the replayable event log, 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` (like a mismatched resume snapshot; the actor never starts). Omitting `input` entirely still skips validation. + + ```ts + const agent = setupAgent({ + schemas: createAgentSchemas({ + context: z.object({ topic: z.string(), rounds: z.number() }), + input: z.object({ topic: z.string(), rounds: z.number().default(3) }), + }), + }); + + const machine = agent.createMachine({ + // `rounds` arrives filled in — no `?? 3` restating the default here + context: ({ input }) => ({ topic: input.topic, rounds: input.rounds }), + // ... + }); + + // `rounds` is optional at the call site; `topic` (no default) is not + await runAgent(machine, { input: { topic: "otters" } }); + ``` + + Standard Schema throughout — no validation library is referenced, so this works with whatever the machine was declared with. + + Types: `runAgent`'s `input` is now `AgentInputFrom`, which reads the schema's pre-validation side (`~standard.types.input`) while the context factory keeps the validated side. Machines reached through `.provide(...)` lose the brand and fall back to xstate's `InputFrom`. New exported type helpers: `AgentInputFrom`, `InferInput`. + ## 2.0.0-alpha.14 ### Minor Changes diff --git a/demo/CHANGELOG.md b/demo/CHANGELOG.md index 8168428f..a9d6f320 100644 --- a/demo/CHANGELOG.md +++ b/demo/CHANGELOG.md @@ -1,5 +1,12 @@ # @statelyai/agent-demo +## 0.0.1-alpha.3 + +### Patch Changes + +- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]: + - @statelyai/agent@2.0.0-alpha.15 + ## 0.0.1-alpha.2 ### Patch Changes diff --git a/demo/package.json b/demo/package.json index faefadd1..75b4ffb8 100644 --- a/demo/package.json +++ b/demo/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/agent-demo", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.3", "private": true, "type": "module", "scripts": { diff --git a/examples/cloudflare-agent-host/CHANGELOG.md b/examples/cloudflare-agent-host/CHANGELOG.md index 961d0b3e..cba129f1 100644 --- a/examples/cloudflare-agent-host/CHANGELOG.md +++ b/examples/cloudflare-agent-host/CHANGELOG.md @@ -1,5 +1,12 @@ # @statelyai/example-cloudflare-agent-host +## 0.0.1-alpha.3 + +### Patch Changes + +- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]: + - @statelyai/agent@2.0.0-alpha.15 + ## 0.0.1-alpha.2 ### Patch Changes diff --git a/examples/cloudflare-agent-host/package.json b/examples/cloudflare-agent-host/package.json index 88b1dd56..f5b8a96c 100644 --- a/examples/cloudflare-agent-host/package.json +++ b/examples/cloudflare-agent-host/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/example-cloudflare-agent-host", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.3", "private": true, "type": "module", "scripts": { diff --git a/examples/cloudflare-workers-ai-host/CHANGELOG.md b/examples/cloudflare-workers-ai-host/CHANGELOG.md index f75fdddc..f0db09ad 100644 --- a/examples/cloudflare-workers-ai-host/CHANGELOG.md +++ b/examples/cloudflare-workers-ai-host/CHANGELOG.md @@ -1,5 +1,12 @@ # @statelyai/example-cloudflare-workers-ai-host +## 0.0.1-alpha.3 + +### Patch Changes + +- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]: + - @statelyai/agent@2.0.0-alpha.15 + ## 0.0.1-alpha.2 ### Patch Changes diff --git a/examples/cloudflare-workers-ai-host/package.json b/examples/cloudflare-workers-ai-host/package.json index ddc5c822..7b27bdcb 100644 --- a/examples/cloudflare-workers-ai-host/package.json +++ b/examples/cloudflare-workers-ai-host/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/example-cloudflare-workers-ai-host", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.3", "private": true, "type": "module", "scripts": { diff --git a/examples/next-host/CHANGELOG.md b/examples/next-host/CHANGELOG.md index 846e9eb3..d83a9150 100644 --- a/examples/next-host/CHANGELOG.md +++ b/examples/next-host/CHANGELOG.md @@ -1,5 +1,12 @@ # @statelyai/example-next-host +## 0.0.1-alpha.3 + +### Patch Changes + +- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]: + - @statelyai/agent@2.0.0-alpha.15 + ## 0.0.1-alpha.2 ### Patch Changes diff --git a/examples/next-host/package.json b/examples/next-host/package.json index ba905f5e..ec859e4d 100644 --- a/examples/next-host/package.json +++ b/examples/next-host/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/example-next-host", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.3", "private": true, "type": "module", "scripts": { diff --git a/examples/tanstack-ai-stream/CHANGELOG.md b/examples/tanstack-ai-stream/CHANGELOG.md index 394d6109..c29d6e8d 100644 --- a/examples/tanstack-ai-stream/CHANGELOG.md +++ b/examples/tanstack-ai-stream/CHANGELOG.md @@ -1,5 +1,12 @@ # @statelyai/example-tanstack-ai-stream +## 0.0.1-alpha.3 + +### Patch Changes + +- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]: + - @statelyai/agent@2.0.0-alpha.15 + ## 0.0.1-alpha.2 ### Patch Changes diff --git a/examples/tanstack-ai-stream/package.json b/examples/tanstack-ai-stream/package.json index 8064c8e3..e19a4a1f 100644 --- a/examples/tanstack-ai-stream/package.json +++ b/examples/tanstack-ai-stream/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/example-tanstack-ai-stream", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.3", "private": true, "type": "module", "scripts": { diff --git a/examples/tanstack-start-host/CHANGELOG.md b/examples/tanstack-start-host/CHANGELOG.md index 6af38cd3..e00ae61a 100644 --- a/examples/tanstack-start-host/CHANGELOG.md +++ b/examples/tanstack-start-host/CHANGELOG.md @@ -1,5 +1,12 @@ # @statelyai/example-tanstack-start-host +## 0.0.1-alpha.3 + +### Patch Changes + +- Updated dependencies [[`d857a8a`](https://github.com/statelyai/agent/commit/d857a8ae4a16b155d4694f8f556dca55b124c7ce)]: + - @statelyai/agent@2.0.0-alpha.15 + ## 0.0.1-alpha.2 ### Patch Changes diff --git a/examples/tanstack-start-host/package.json b/examples/tanstack-start-host/package.json index f39c655b..733217a4 100644 --- a/examples/tanstack-start-host/package.json +++ b/examples/tanstack-start-host/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/example-tanstack-start-host", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.3", "private": true, "type": "module", "scripts": { diff --git a/package.json b/package.json index 101b8d98..c6e84440 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@statelyai/agent", - "version": "2.0.0-alpha.14", + "version": "2.0.0-alpha.15", "description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.", "type": "module", "main": "dist/index.cjs",