feat: generable() schema builder, callback safety, and formatting tooling#2
Draft
feat: generable() schema builder, callback safety, and formatting tooling#2
Conversation
…ss documentation and code
Add generable() function for declarative structured output schemas with full TypeScript type inference — the TS equivalent of Python SDK's @generable decorator. Also add streaming session reset on early break, FFI type casts for the provider interface, and comprehensive test coverage for schema, session, and compat utils (100% across all metrics).
koffi's str type can coerce null C string pointers to the JS string "null" in callback scenarios. Switch ResponseCallbackProto to void* and decode manually via the new decodeString() helper, which reads without freeing (C side owns callback memory). decodeAndFreeString() now delegates to decodeString() + free.
Expand format scripts from src/ to the entire repo, add .prettierignore for dist, coverage, native, and *.md files. Markdown is excluded because Prettier pads tables.
- README: "TSDM" → "tsfm" in license section - docs/api/errors: add language to fenced code block - docs/guide: fix double spaces, trailing whitespace, missing semicolons in code examples
…tSize, prewarm Add native/extensions/ overlay that injects tsfm-specific Swift bridge functions into Apple's python-apple-fm-sdk at build time. The build script copies extension sources into the Apple source tree before swift build, and merges extension headers into the final FoundationModels.h. New APIs: - SystemLanguageModel.contextSize (back-deployed from macOS 26.4 SDK) - SystemLanguageModel.supportedLanguages - SystemLanguageModel.supportsLocale() - LanguageModelSession.prewarm() - tokenCount() stubbed for macOS 26.4+ runtime Build script prefers Xcode beta when present to unlock back-deployed APIs. Includes docs, changelog, and mock bindings for all new functions.
…ions Update ResponseCbArgs to use NativePointer to match the void* callback proto. Add unit tests for contextSize, supportedLanguages, supportsLocale, prewarm, and stream cancellation to restore 100% coverage.
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.
Summary
generable()— declarative typed schema builder for structured output with full TypeScript type inference, the equivalent of the Python SDK's@generabledecoratorvoid*instead ofstrto prevent koffi from coercing null C string pointers to the JS string"null"FMLanguageModelSessionReset) to prevent stalled subsequent calls*.mdto preserve compact tables), add.prettierignoreas NativePointer,as boolean, etc.)Test plan
npm run format:checkcleannpm run typecheckclean