Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Unreleased
0.3.1 - 2026-03-12
Added
Tool.onCall— optional callback that fires at the start of each tool invocation, beforecall()runs. Useful for showing UI indicators while the model waits for tool results.
0.3.0 - 2026-03-11
Added
- Chat & Responses API layer (
tsfm-sdk/chat) — industry-standard Chat-style and Responses-style APIs- Chat Completions API (
client.chat.completions.create()) with full message history, streaming, structured output (json_schema), and tool calling - Responses API (
client.responses.create()) — string or structured input, function tools, and streaming viaResponseStream - Parameter mapping:
temperature,max_tokens/max_completion_tokens,top_p,seed→ nativeGenerationOptions; unsupported params warned at runtime - Error mapping:
ExceededContextWindowSizeError→finish_reason: "length",GuardrailViolationError→finish_reason: "content_filter",RefusalError→message.refusal,RateLimitedError→ HTTP 429 StreamandResponseStreamasync iterables withtoReadableStream(),close(),Symbol.dispose, andFinalizationRegistrycleanup- Tool calling via structured output with
$defs/$refschemas to prevent parameter name collisions - JSON key reordering utility to match schema-defined property order
- Chat Completions API (
ServiceCrashedError— detects crashedgenerativeexperiencesdservice and provides recovery instructionsSymbol.disposesupport onSystemLanguageModel,LanguageModelSession,Tool, andClientfor TC39 Explicit Resource Management- Typed transcript entries:
TranscriptEntry,TranscriptContent,TranscriptTextContent,TranscriptStructuredContent,TranscriptToolCall,TranscriptEntryRoletypes andtranscript.entries()method JsonSchemaandJsonObjectexported types- Automatic session cleanup on
process.exit,SIGINT, andSIGTERMvia global session tracking - Enhanced
afmSchemaFormat()with recursive normalization for nested objects,$defs/$refsupport, andx-orderfields respondWithJsonSchema()now accepts typedJsonSchemainstead ofRecord<string, unknown>- Tool callback error handling: synchronous errors in
call()now invokeFMBridgedToolFinishCall()with error message to prevent session hang - Enhanced
statusToError(): mapsModelManagerError Code=1041toInvalidGenerationSchemaErrorwith descriptive message - Integration tests for Chat & Responses API layer (chat completions and Responses API)
- Unit tests for all compat modules (~4,300 lines of new test coverage)
- 6 new examples in
examples/compat/demonstrating Chat Completions and Responses API - Retry helper for integration tests (
retryAttempts()) for flaky on-device model responses
Changed
- Renamed model class from internal name to
SystemLanguageModelacross all public APIs and documentation Transcript.toDict()andfromDict()now useJsonObjecttype instead ofRecord<string, unknown>GeneratedContent.toObject()now returnsJsonObjectinstead ofRecord<string, unknown>serializeOptions()uses typedSerializedSamplingandSerializedOptionsinterfaces internally- Integration tests now use
waitUntilAvailable()instead of synchronousisAvailable()
Documentation
- Complete Chat & Responses API guide (505 lines), API reference (568 lines), and examples page (321 lines)
- Docs site visual overhaul: brand colors shifted to teal, Apple-style typography and font rendering, WCAG AA contrast fixes
- Landing page redesigned with code examples and Chat API showcase
- Swift-equivalent references extracted into caption-style info boxes across all guide pages
- Code blocks now word-wrap; inline code uses inherited text color with subtle background
- All guide pages updated with Apple conventions terminology alignment
0.2.3 - 2026-03-10
Fixed
NOTICEfile now included in published npm package
0.2.2 - 2026-03-10
Changed
- Renamed package from
afm-ts-sdktotsfm-sdk - Renamed GitHub repository from
codybrom/afm-ts-sdktocodybrom/tsfm
0.2.1 - 2026-03-09
Added
- Branded
NativePointertype for compile-time C pointer type safety unregisterCallback()utility to centralize callback cleanup logic- Discriminated union for
GenerationGuidedata, enabling exhaustive type checking - Comprehensive JSDoc comments on public APIs (
SystemLanguageModel,LanguageModelSession,Tool,Transcript,SamplingMode) stripInternalin tsconfig to exclude@internalsymbols from.d.tsoutput- Unit tests for error hierarchy and
statusToError()mapping - Integration test suite covering basic responses, streaming, structured output, tools, and transcripts
- GitHub Actions CI workflow (macOS, Node.js 20/22, lint + format + unit tests)
- Organized examples directory with individual READMEs for each example
Changed
- Renamed all internal pointer variables from abbreviations (
ptr,cbPtr) to full names (pointer,callbackPointer,_nativeSession,_nativeTool,_nativeSchema, etc.) InvalidGenerationSchemaErrornow extendsGenerationErrorinstead ofFoundationModelsError- All error-throwing paths now use
FoundationModelsErrororGenerationErrorsubclasses instead of genericError - Replaced
GenerationGuideseparateguideType/valuefields with a singledatadiscriminated union
Removed
- Monolithic
example.tsfile (replaced by organizedexamples/directory)
0.2.0 - 2026-03-08
Added
decodeAndFreeString()utility in bindings to safely decode C string pointers and free memory viaFMFreeString- ESLint (flat config) and Prettier for code linting and formatting
tsxdev dependency for TypeScript execution
Changed
- C function signatures for string-returning functions now declare return type as
void *instead ofstrto retain the pointer for proper memory management - Tool callback error handling now wraps errors in
ToolCallErrorwith proper context - Updated README import paths
Fixed
- Critical memory leak in all string-returning C functions —
koffi'sstrreturn type was copying strings but discarding the original pointer before it could be freed
Removed
- Unused
FMLanguageModelSessionCreateDefaultbinding (sessions always route throughCreateFromSystemLanguageModel) - Unused
FMRetainbinding (all Swift-to-JS transfers usepassRetained, onlyFMReleaseis needed)
0.1.0 - 2026-03-08
Added
- TypeScript/Node.js bindings for Apple's Foundation Models framework via koffi FFI
SystemLanguageModelclass with availability checks andwaitUntilAvailable()LanguageModelSessionwithrespond(),streamResponse(), andrespondWithJsonSchema()for text, streaming, and structured generationGenerationSchemaandGenerationSchemaPropertyfor typed structured output with generation guidesGenerationOptionsandSamplingModefor controlling temperature, token limits, and sampling strategies- Abstract
Toolbase class for function calling with schema-driven arguments Transcriptclass for session history export and import- Error hierarchy matching Python SDK status codes (11 specific error types)
- Prebuilt
libFoundationModels.dylibbundled for npm distribution (no Xcode required) build-native.shscript for building the dylib from vendored Swift sourceverify-native.jspostinstall script for SHA256 verification with automatic rebuild