Web SDK
The Agent Platform Web SDK (@koreai/artemis-web-sdk) provides a TypeScript/JavaScript library for embedding agent chat and voice interactions in web applications. The SDK supports vanilla JavaScript, React hooks, and a web component for drop-in integration.
The browser-facing SDK does not send the public pk_* key directly to /ws/sdk. It first exchanges the key for a short-lived SDK session token on POST /api/v1/sdk/init, then authenticates SDK HTTP routes with X-SDK-Token and the SDK WebSocket with Sec-WebSocket-Protocol: sdk-auth,<token>.
Install Web SDK
AgentSDK constructor, chat and voice clients, React provider/hooks/components, custom elements, rich content renderers, attachment upload, feedback, auth challenge UI, and template utilities.
Quick Start
Vanilla JavaScript
React
Web Component
AgentSDK
The main SDK class. Creates and manages connections, chat clients, and voice clients.Constructor
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
projectId | string | Yes | — | Project ID to connect to |
apiKey | string | Yes | — | Public API key (starts with pk_) |
endpoint | string | No | Same origin | Platform base URL |
debug | boolean | No | false | Enable debug logging to console |
Methods
| Method | Returns | Description | |
|---|---|---|---|
connect() | Promise<void> | Establish WebSocket connection to the platform | |
disconnect() | void | Close the connection and clean up resources | |
chat() | ChatClient | Get the chat client instance (created on first call) | |
voice() | VoiceClient | Get the voice client instance (created on first call) | |
isConnected() | boolean | Check if the SDK is connected | |
getSessionId() | `string | null` | Get the current session ID |
Static Methods
| Method | Returns | Description |
|---|---|---|
AgentSDK.init(config) | AgentSDK | Create and store an SDK instance globally (for web components) |
Events
| Event | Payload | Description |
|---|---|---|
connected | void | WebSocket connection established |
disconnected | void | WebSocket connection closed |
error | { error: Error } | Connection or runtime error |
sessionStart | { sessionId: string } | New session started |
sessionEnd | void | Session ended |
ChatClient
Handles text messaging with streaming support. Obtained viasdk.chat().
Methods
| Method | Returns | Description |
|---|---|---|
send(text, options?) | Promise<string> | Send a message. Returns the message ID |
uploadAttachment(file) | Promise<string> | Upload a file attachment. Returns the attachment ID |
getMessages() | Message[] | Get all messages in the conversation |
getIsTyping() | boolean | Check if the agent is currently responding |
clearMessages() | void | Clear the local message history |
send() Options
session.messageMetadata as the canonical prompt/template path. message_metadata remains available as the tool-context alias for context_access.read.
Events
| Event | Payload | Description |
|---|---|---|
message | Message | New message received (user or assistant) |
messageChunk | { messageId: string, chunk: string } | Streaming text chunk from assistant |
typing | { isTyping: boolean } | Agent typing indicator changed |
messageSent | { messageId: string } | User message was sent |
attachmentUploaded | { attachmentId: string, filename: string } | File upload completed |
attachmentError | { filename: string, error: string } | File upload failed |
error | { error: Error } | Chat error |
Message Type
RichContent Type
Multi-format content variants delivered alongside the plain text response:ActionSet Type
Interactive action elements the agent sends for user input:AttachmentRef Type
VoiceClient
Handles voice interactions via WebSocket audio pipeline with optional WebRTC. Obtained viasdk.voice().
The voice client supports two modes:
- Pipeline mode: Client-side VAD (Voice Activity Detection) captures PCM16 audio, sends it via WebSocket for server-side STT/LLM/TTS processing, and plays back MP3 audio responses.
- Realtime mode: Native audio I/O via realtime LLM providers with PCM16 streaming.
Methods
| Method | Returns | Description |
|---|---|---|
start() | Promise<void> | Start voice interaction (requests microphone permission) |
stop() | void | Stop voice interaction and release audio resources |
toggleMute() | boolean | Toggle microphone mute. Returns the new mute state |
getState() | VoiceState | Get the current voice state |
getInfo() | VoiceInfo | Get full voice status information |
Static Methods
| Method | Returns | Description |
|---|---|---|
VoiceClient.isSupported() | boolean | Check if the browser supports voice features |
Voice States
VoiceInfo Type
VoiceClientOptions
Events
| Event | Payload | Description |
|---|---|---|
stateChange | { state: VoiceState, previousState: VoiceState } | Voice state changed |
transcription | { text: string, isFinal: boolean, confidence?: number } | Speech-to-text result |
transcriptionFinal | { text: string, confidence: number } | Final transcription |
responseStart | { messageId: string } | Agent started speaking |
responseChunk | { messageId: string, text: string } | Agent speech text chunk |
responseEnd | { messageId: string, text: string } | Agent finished speaking |
speaking | { isSpeaking: boolean } | Audio playback state changed |
volumeChange | { level: number } | Microphone volume level (0-1) |
ready | void | Voice client is ready |
error | { error: Error } | Voice error |
micPermissionDenied | void | Microphone permission denied |
bargeIn | void | User interrupted agent speech |
vadAvailable | { available: boolean } | VAD availability changed |
React Hooks
The React integration provides a context provider and hooks for state management.AgentProvider
Wrap your application withAgentProvider to initialize the SDK:
useAgent()
Access the full SDK context:useChat()
Access chat-specific state:useVoice()
Access voice-specific state:File Uploads
Upload files for agent processing:Supported File Types
- Images: jpeg, png, gif, webp, svg
- Documents: pdf, docx, xlsx, pptx, txt, csv
- Audio: mp3, wav, ogg, m4a
- Video: mp4, webm
Upload Limits
- Maximum file size: 25 MB per file
- Maximum files per message: 10
Styling and Theming
Widget Theming
Customize the web component appearance:Widget Positions
bottom-right(default)bottom-lefttop-righttop-left
Widget Modes
chat— Text-only chat interfacevoice— Voice-only interfaceunified— Combined chat and voice interface
TypedEventEmitter
All SDK classes extendTypedEventEmitter for type-safe event handling:
WebSocket Message Types
The SDK communicates with the platform over WebSocket. These types are used internally but documented for advanced use cases.Server Message Types
| Type | Description |
|---|---|
response_start | Agent started generating a response |
response_chunk | Incremental text from the agent |
response_end | Agent finished responding (includes fullText, richContent, actions) |
error | Error occurred during processing |
session_start | New session established |
session_end | Session ended |
API Key Management
Public API keys (pk_ prefix) are scoped to a project and provide limited permissions for SDK usage. They are safe to expose in client-side code.
Creating an API Key
- Go to Project > Settings > API Keys.
- Click Create API key.
- Set the allowed origins (for CORS protection).
- Copy the key — it is displayed only once.
Origin Restrictions
Configure allowed origins to prevent unauthorized use of your API key:Origin header on every SDK request and rejects requests from unlisted origins.