Skip to content

feat: generable() schema builder, callback safety, and formatting tooling#2

Draft
codybrom wants to merge 10 commits intomainfrom
feat/generable-and-coverage
Draft

feat: generable() schema builder, callback safety, and formatting tooling#2
codybrom wants to merge 10 commits intomainfrom
feat/generable-and-coverage

Conversation

@codybrom
Copy link
Owner

@codybrom codybrom commented Mar 13, 2026

Summary

  • Add generable() — declarative typed schema builder for structured output with full TypeScript type inference, the equivalent of the Python SDK's @generable decorator
  • Fix streaming callback to receive content as void* instead of str to prevent koffi from coercing null C string pointers to the JS string "null"
  • Add streaming session reset on early break (FMLanguageModelSessionReset) to prevent stalled subsequent calls
  • Widen Prettier scope to entire repo (excluding *.md to preserve compact tables), add .prettierignore
  • Add FFI type casts at all C call sites (as NativePointer, as boolean, etc.)
  • Standardize "Apple Foundation Models" terminology across docs and config
  • Fix markdown typos, whitespace, and missing code fence languages
  • Comprehensive test coverage: schema, session, and compat utils at 100%

Test plan

  • All unit tests passing at 100% coverage (statements, branches, functions, lines)
  • npm run format:check clean
  • npm run typecheck clean
  • Integration tests on macOS 26 with Apple Intelligence

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
@codybrom codybrom changed the title feat: add generable() typed schema builder and improve test coverage feat: generable() schema builder, callback safety, and formatting tooling Mar 13, 2026
@codybrom codybrom self-assigned this Mar 13, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant