Repository navigation
feat(author): declare a source's own fields once, as a schema (#230) - #231
Merged
Merged
Conversation
sourceSchema, in zod/mini, is a source's own fields: sourceOf holds each field to it and says its message where the field was written, the Source type is its output, and it is exported, so that a model can be shown the shape of a source before writing one. What one field cannot say alone stays in sourceOf: a content type named loosely, a licence written with its version, a version for a licence that takes none, and fields in the wrong place. The messages are as they were, but every problem of an author is now said at once, and an author written as a name alone is said with the object to write, as Haiku wrote one through the MCP server. zod/mini adds 23 kB minified to a build in a page, where zod's chained API would add 93 kB.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
… an empty one (#230) A schema shown with "params": { "default": {} } had Haiku send an empty params three times in one Interactive Video run, though a build refused each. params is optional, as a build takes it, with no default said, and the Source type has it optional too.
…he caller's own (#230) What cubic found: build.mjs kept its own list of a source's fields beside the schema, so it now takes them from sourceSchema.shape, and the messages for a field no source has and for a source that is no object are said in one place. sourceSchema refuses a field no source has, as a build does, where it dropped one; an app is shown that too. The README says that toJSONSchema comes from a zod of the caller's own, 4.2 or later, since pnpm does not let a package import the author package's copy.
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.
Closes #230.
sourceSchemadeclares a source's own fields once, in zod/mini, inlib/source-schema.mjs. The author package exports it from all three entries, through./core.What changes
sourceOftakes its list of fields from the schema and holds each field to it. Each problem is said where the field was written. The schema rejects any field a source may not have, as a build does, with the build's message, and an app is shownadditionalProperties: false. What one field can't say alone stays in code: a content type named loosely, a licence written with its version, a version for a licence that takes none, and fields in the wrong place (h5p-author: a chat with no skill text spends a round on each layer of a source's outer shape #174).authors[0]: expected an author: write { "name": "Unknown", "role": "Author" }. It used to getauthors[0].name: expected the author's name. Haiku wroteauthors: ["Unknown"]through the MCP server.Sourceis the schema's output type, in place of the hand-written typedef.paramsis optional in it, as a build takes it. The schema states no default forparams: when it showed"default": {}, one Haiku run sent an emptyparamsthree times.design/author.md. The README covers the export andtoJSONSchema, which needs a zod of the caller's own, 4.2 or later: pnpm won't let them import the author package's copy.Testing
Author: 222 tests pass, the browser project included. Every existing message test passes unchanged. The new test covers:
Types:
tscpasses, andpackage-types.tspinssourceSchema, whose output is aSource.Haiku 5.5 in Claude Code, through feat(mcp): a local MCP server that builds, checks and previews packages #227's server with this schema shown (built locally, not pushed). The tasks were the ones feat(mcp): a local MCP server that builds, checks and previews packages #227 was tested with: a quiz with
volcano.png, a Course Presentation, and an Interactive Video fromclip.mp4."authors": ["Unknown"]Every other refusal, with or without the schema, was about the content.
Not here
h5p_buildshows this schema for itssource, as JSON Schema metadata on a field that still takes any object, so the SDK never refuses a source before the build has listed every problem. The commit is ready, four files with tests, and lands with whichever of feat(mcp): a local MCP server that builds, checks and previews packages #227 and this PR merges second.Summary by cubic
Declares a source's own fields once as
sourceSchemain zod/mini, exported from the author package, and holds each field of a source to it insourceOf. The schema is strict, so it refuses a field no source has, and the build takes its field list from the schema's shape, keeping one list.Sourcetype is now the schema's output type, replacing the hand-written typedef.authors[0]: expected an author: write { "name": "Unknown", "role": "Author" }.paramsis shown as optional with no default so the schema no longer suggests sending an emptyparams.zod/minibecause builds run in a page too: it adds 23.2 kB minified (7.6 kB gzipped) against 92.6 kB (26.9 kB gzipped) for zod's chained API.zoddependency and documentssourceSchemain the README anddesign/author.md; the README notestoJSONSchemaneeds a zod of the caller's own, 4.2 or later.Not here
zod/mini(MIT) added to its licence notices at its next pin.Written for commit f64fda4. Summary will update on new commits.