Installation
Install the Nomos TypeScript SDK using npm or yarn:Quick Start
Here’s a simple example to get you started:Authentication
The SDK supports multiple authentication methods:No Authentication
If your Nomos server doesn’t require authentication:JWT Authentication
API Key Authentication
Dynamic Authentication
You can also set authentication after creating the client:Usage Patterns
Session-based Conversations
Session-based conversations allow the server to maintain conversation state:Stateless Chat
Stateless chat allows you to maintain conversation state on the client side:With Authentication
API Reference
NomosClient
Main client class for interacting with Nomos agents.Constructor
config
: Base URL string or configuration object
Methods
healthCheck()
Check the health status of the API server.
createSession(initiate?: boolean)
Create a new session.
sendMessage(sessionId: string, message: string)
Send a message to an existing session.
getSessionHistory(sessionId: string)
Get conversation history for a session.
endSession(sessionId: string)
End a session.
chat(request: ChatRequest, verbose?: boolean)
Send a chat message with optional session data for stateless chat.
setAuth(auth: AuthConfig)
Set authentication configuration.
clearAuth()
Clear authentication configuration.
generateToken(payload: Record<string, unknown>)
Generate a JWT token (development only).
Type Definitions
Message
SessionResponse
SessionData
ChatRequest
ChatResponse
NomosAuthError
Error Handling
The SDK provides specific error types for different scenarios:Environment Variables
For security, use environment variables for sensitive tokens:Examples
Basic Session Example
Stateless Chat Example
Authenticated Example
React Component Example
Node.js CLI Tool
Express.js API Integration
Best Practices
- Handle authentication errors gracefully with proper error checking
- Use environment variables for sensitive tokens and API URLs
- End sessions properly to clean up server resources
- Implement retry logic with exponential backoff for production apps
- Use stateless chat for simple interactions, sessions for complex conversations
- Check server health before making requests in production
- Handle rate limiting by implementing proper backoff strategies
Browser Usage
The SDK works in browser environments with proper CORS configuration:TypeScript Configuration
For optimal TypeScript support:Migration from v0.1.x
If you’re upgrading from version 0.1.x, see our Migration Guide for detailed instructions.Quick Migration
Most v0.1.x code will work without changes:Troubleshooting
Common Issues
Authentication ErrorsContributing
We welcome contributions to the Nomos TypeScript SDK! Please see our contributing guide for more information.Support
For questions and support:Changelog
v0.2.0 (Latest)
- ✅ Added JWT and API key authentication support
- ✅ Enhanced error handling with
NomosAuthError
- ✅ Added health check endpoint
- ✅ Added verbose mode for chat debugging
- ✅ Added token generation for development
- ✅ Improved TypeScript types and documentation
- ✅ Backward compatible with v0.1.x code
v0.1.0
- 🚀 Initial release with basic session and chat functionality