Repository navigation
Add the ai package with rules, defaults, and attachments - #339
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
New @emulators/ai package with the pieces that need no server yet: - shared types and error classes - rule validation and matching, with per-rule budgets - deterministic defaults: echo text, schema-valid objects, forced tool calls - attachment decoding that keeps metadata only and strips URL credentials Nothing registers the service yet. index.ts only exports types and errors.
Rules can declare variants instead of one reply, and ai.random.seed sets the seed that picks between them. chunkDelayMs also accepts a list so frames can be paced unevenly. Parsing only; the engine picks and paces in the next change in the stack.
A variant is now either a reply or an error, and the parser requires exactly one of the two. This lets a seeded sequence mix normal replies with failures.
A variant is a full alternative body, so it can differ in how it ends and how it is delivered, not only in its content. Rule-level values stay as the defaults.
Strict response_format and text.format schemas are validated before generation with OpenAI's own error text and param. The keyword sets live per provider in schema-dialects.ts; Anthropic's rules and message are encoded there too. The generator now accepts format, pattern, and oneOf, and fills common string formats with stable sample values instead of failing.
Anthropic's OpenAI compatibility layer keeps OpenAI's error envelope but applies Claude's schema rules, so the provider rules follow the model rather than the endpoint. schemaFailure returns the provider's wording and the codec wraps it in its own envelope.
The package shipped at the previous release version while the repo moved to 0.13.0, so the version check failed for every branch above it.
Use tsc-ts for type-check, oxlint, declaration emit through emit-types, the build tsconfig, and the shared 0.13.1 version, matching the other packages.
Schema sampling now bounds the size of generated strings and refuses const and enum values nested past the depth limit, so a hostile schema cannot make the default reply blow up.
A string of encoded JSON is now rejected at startup and on PUT /_ai/rules with a message pointing at the fix.
lahfir
marked this pull request as ready for review
November 9, 2026 21:16
Railly
approved these changes
Nov 13, 2026
mergeSchema let the branch override its siblings, so a stricter sibling bound next to $ref could be dropped and the sampled value was rejected. It now takes the tighter bound, intersects type and enum, unions required, and merges properties, items and additionalProperties recursively. Keywords that cannot be intersected keep the branch value and the existing matches() check rejects bad samples.
Pattern checks used a shared wall-clock budget and passed the remaining milliseconds as the vm timeout, so scheduling noise could turn a valid patterned schema into a 400. Each check now costs a fixed amount of the existing work budget and every vm run uses the same constant timeout. A catastrophic expression is still stopped by that timeout.
A forced tool whose parameters had no type, such as {} or only
properties, sampled as null and produced arguments "null". The schema
now gets type object when it has none, the same as a missing parameters
field already did.
A sibling multipleOf next to a $ref target with its own multipleOf was overridden, so a satisfiable schema returned 400. It now uses the least common multiple for integers, or the larger value when it is a multiple of the smaller. Two different known formats on both sides cannot both be sampled and matches() does not check format, so the sample could violate the sibling. The merge now yields an unsatisfiable schema for that case.
Each pattern check had its own timeout and the anyOf and oneOf loop treated that as a failed branch, so N catastrophic branches cost N timeouts and blocked the server. A timeout now aborts the whole sample, so one request pays it once. An invalid regular expression now says so instead of reporting a time limit, and a pattern failure inside nested schemas names the property path instead of the root.
A forced tool call sampled whatever its parameters schema allowed, so true, nullable, null, string and array schemas gave null, a string or an array. The schema is now narrowed to an object (nullable and array types are dropped), and a schema that cannot be an object is rejected with a 400 naming tools.<name>.parameters.
sampleAlternative gave up on a oneOf branch when its first sample also matched another branch, even though a value matching only that branch existed (for example "" for minLength 1 versus maxLength 5, or 1.5 for integer versus number). When that happens it now retries the branch with a small fixed set of variants that step outside the other branches: optional properties made required, bounds flipped past the other branch's bounds, enum values, and a half step for numbers. Every candidate still goes through the existing matches check, so a wrong value is never returned, and the failure when no value exists is unchanged. anyOf is untouched.
nullable only widens the type it sits next to. matches() returned true for null as soon as the node had nullable, and mergeSchema copied nullable onto a typed $ref or branch target, so a sibling nullable next to a string target sampled null. matches() now skips only the type check for null, and the merge drops nullable when the other side has a non-nullable type.
# Conflicts: # pnpm-lock.yaml
Railly
approved these changes
Nov 14, 2026
ctate
approved these changes
Nov 14, 2026
Each pattern check already had a timeout and a work cost, but nothing bounded their sum, so many slow checks could block the server for a minute. A sampling now aborts once its pattern checks total more than 2 seconds, through the same path as a timed-out check.
A chat file was rejected by its filename before its data URL type was read, so a declared PDF with no .pdf name failed. The PDF check now runs once, on the type inline attachments already resolve, with the declared type taking precedence over the filename.
The hint always suggested matching-reply, so applying it for a second unmatched model hit a duplicate rule id error. strictMissFailure now takes the configured rule ids and suggests the first free matching-reply id.
PUT /_ai/rules replaces the whole configuration, and the suggested body had no strict field, so sending it turned strict mode off and later misses got default replies. The body now sets strict to true and the message says the request replaces the configuration.
This branch was successfully deployed
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.
Uh oh!
There was an error while loading. Please reload this page.