[SDK/Factories] Add argsSchema To The Factory Authoring Surface - #2315
[SDK/Factories] Add argsSchema To The Factory Authoring Surface#2315MRayermannMSFT wants to merge 1 commit into
Conversation
FactoryMeta now declares an optional argsSchema, typed as the existing FactoryJsonSchema. The field already crossed the wire because defineFactory snapshots meta whole, so this is additive and type-level: it makes a runtime feature discoverable to extension authors writing against the published types. Without a declared schema nothing validates a caller's args. A malformed call starts a run, takes a user approval, spends credits, and then fails inside the factory body. With one, the CLI rejects it before the run row exists and the model retries against a correction hint. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR adds Scope check: The factory authoring surface ( Verdict: No cross-SDK consistency issues. The change is correctly scoped to the one SDK that exposes the factory authoring API. No updates are needed in the other language SDKs for this PR.
|
There was a problem hiding this comment.
Pull request overview
Exposes factory argument schemas in the Node.js SDK and documents their runtime validation behavior.
Changes:
- Adds optional
FactoryMeta.argsSchema. - Documents supported schema constraints.
- Adds unit and E2E coverage for schema transport.
Show a summary per file
| File | Description |
|---|---|
nodejs/src/types.ts |
Adds the public metadata field. |
nodejs/src/factory.ts |
Expands schema documentation. |
nodejs/docs/factories.md |
Documents argument schemas and usage. |
nodejs/test/factory.test.ts |
Tests freezing, serialization, and documentation. |
nodejs/test/e2e/fixtures/factory-extension.mjs |
Adds a schema to the E2E fixture. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
| phases: [], | ||
| // A declared shape has to survive the SDK boundary and reach the runtime, | ||
| // which validates `args` against it before a run row exists. | ||
| argsSchema: { type: ["object", "null"] }, |
What
FactoryMetanow declares an optionalargsSchema, so an extension author can state the argument shape their factory expects.It reuses the existing
FactoryJsonSchematype. That type already documents the same bounded subset the CLI enforces, and the runtime's own validator points at it as the contract boundary.The field already crossed the wire, because
defineFactorysnapshotsmetawhole rather than cherry-picking fields. This change is additive and type-level. It makes an existing runtime feature discoverable to authors writing against the published types.Docs and JSDoc now describe what a declaration enforces, matching the
run_factorytool description word for word.Why
Almost no factory declares an argument shape, because the SDK never exposed the field. Authors reading the published types cannot tell the feature exists.
That has a real cost. Without a declared schema nothing validates a caller's
args. A malformed call starts a run, takes a user approval, spends credits, and then dies inside the factory body with a confusing error about a missing property.With a declared schema the CLI catches the mismatch before the run starts. The model gets a correction hint and retries. No run row, no permission prompt, no credit spend.
Notes
nodejs/src/types.tsis hand-written, not generated. It already importsJsonValuefromfactory.ts, so importingFactoryJsonSchemaalongside it follows the established convention.argsSchemais optional. A factory that omits it behaves exactly as before, which a unit test asserts.Testing
argsSchemasurvivesdefineFactory, is deep-frozen, serializes to JSON, and reaches thesession.resumeregistration payload. It also asserts an omitting factory carries no such property.run_factorytool cannot drift apart.argument-echoE2E fixture now declares a schema, exercising the field against a live runtime.nodejsunit suite,typecheck,lint, andformat:checkall pass. Threefactory.e2efailures are pre-existing and reproduce identically on a clean tree.