This repository was archived by the owner on Jun 7, 2026. It is now read-only.
fix(sdk): address TypeScript SDK review findings - #48
Merged
Conversation
- Fix KoineError prototype chain for proper instanceof checks - Add textResolved flag to prevent double promise resolution in streams - Log warnings for SSE text parse failures instead of silent swallowing - Add validateConfig() for early config validation with clear errors - Wrap fetch errors in KoineError (TIMEOUT, NETWORK_ERROR codes) - Add AbortSignal support for user-controlled cancellation - Remove internal types from public exports (SSE*, *Response, ErrorResponse) - Add typed KoineErrorCode union for exhaustive error handling - Fix README: add missing timeout param, correct type documentation - Add comprehensive JSDoc to all public functions
API improvements: - Add createKoine() factory for cleaner API: `const koine = createKoine(config)` - Config validated once at creation time, not on each method call - Export KoineClient interface and request/result option types Type safety: - Add readonly modifiers to all response type properties - Add readonly to KoineUsage, KoineStreamResult fields Dependency cleanup: - Remove zod from peerDependencies (kept as bundled dependency) Tests: - Add 5 new tests for createKoine factory - Move SSE helper functions to shared scope for reuse
Split the monolithic client.ts (703 lines) into smaller, focused files: - http.ts: HTTP utilities (safeFetch, error handling) - text.ts: generateText function - stream/sse.ts: SSE parser - stream/index.ts: streamText function - object.ts: generateObject function - client.ts: Factory and re-exports
Split the monolithic test file into separate files mirroring the source code structure: - helpers.ts: Shared test utilities (mocks, config) - text.test.ts: generateText tests - stream.test.ts: streamText tests - object.test.ts: generateObject tests - client.test.ts: KoineError and createKoine factory tests All 42 tests pass. No functionality changed.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This was referenced Dec 25, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
createKoine()factory pattern for cleaner APIChanges
API Improvements
createKoine(config)factory that returns a typed client objectCode Organization
Split
client.ts(703 lines) into focused modules:src/http.tssrc/text.tsgenerateText()implementationsrc/stream/sse.tssrc/stream/index.tsstreamText()implementationsrc/object.tsgenerateObject()implementationsrc/client.tsSplit
client.test.ts(1042 lines) into focused test files:__tests__/helpers.ts__tests__/text.test.ts__tests__/stream.test.ts__tests__/object.test.ts__tests__/client.test.tsTest plan
hello.ts,stream.ts) work correctly