socket-sdk-test-v1
v0.0.1
Published
React Native Socket SDK - WebSocket/auth/chat transport for the platform.
Readme
Artemis React Native Socket SDK
WebSocket + auth + chat transport for the Artemis platform, for React Native.
This is a faithful TypeScript port of the Flutter artemis_flutter_socket_sdk.
- Implements: the shared Artemis wire/event/config contract — token bootstrap
(
/api/v1/sdk/init) and refresh (/api/v1/sdk/refresh), WebSocket ticket (/api/v1/sdk/ws-ticket) with legacy subprotocol fallback, the/ws/sdksocket, streaming chat, persisted-history pagination, reconnection with exponential backoff, and pending-message resend. - Public surface: mirrors the Flutter
AgentSDK(initialize,connect,sendMessage,getMessages,getWidgetConfig, event subscriptions).
Consumed by the sibling ../UI SDK.
Architecture
The SDK is split into the same four layers as the Flutter SDK:
| Class | Responsibility |
| ---------------- | --------------------------------------------------------- |
| AgentSDK | Public API, wires the clients together, fans out events. |
| TokenManager | Bootstraps/refreshes short-lived SDK session tokens. |
| SessionManager | Opens the WebSocket, handles session_start, reconnects. |
| ChatClient | Sends messages, parses streaming responses, loads history.|
The SDK relies only on the global WebSocket and fetch that React Native
provides — there are no extra runtime dependencies.
Configuration
Flutter loads configuration from bundled YAML assets. React Native has no
equivalent, so configuration is supplied to initialize as a plain object. The
keys mirror the Flutter sdk_configurations.yaml (snake_case), so an existing
config translates directly:
const config = {
environment: 'dev',
connection: {
project_id: '019ebab0-737a-7661-9c02-d8d416320a1c',
api_key: 'pk_...',
endpoint: 'https://agents-dev.kore.ai',
},
channel: {
channel_id: '019eee30-53a9-7961-afb1-e9303a8c989f',
channel_name: 'RN Demo App',
},
websocket: {
reconnection: {
enabled: true,
max_attempts: 5,
base_delay_ms: 1000,
max_delay_ms: 30000,
exponential_backoff: true,
},
},
chat: {
enable_typing_indicator: true,
enable_thoughts: false,
},
debug: { enabled: true, log_level: 'debug', log_websocket_messages: true },
};Authentication requires either connection.api_key or
connection.bootstrap_token (not both).
Usage
import { AgentSDK } from '@artemis/react-native-socket-sdk';
const sdk = await AgentSDK.initialize({ config });
// Connection lifecycle events
sdk.on('event', (event) => {
switch (event.type) {
case 'connected':
console.log('connected', event.sessionId);
break;
case 'disconnected':
console.log('disconnected', event.reason);
break;
case 'reconnecting':
console.log(`reconnecting ${event.attempt}/${event.maxAttempts}`);
break;
case 'error':
console.warn('sdk error', event.code, event.error);
break;
}
});
// Chat events (streaming, history, typing)
sdk.on('chat', (event) => {
switch (event.type) {
case 'messageStart':
case 'messageChunk':
case 'messageEnd':
case 'messageReceived':
case 'historyLoaded':
setMessages(sdk.getMessages());
break;
case 'typingIndicator':
setTyping(event.isTyping);
break;
case 'thought':
console.log('thought', event.content);
break;
case 'chatError':
console.warn('chat error', event.error);
break;
}
});
const sessionId = await sdk.connect();
await sdk.sendMessage('Hello!');
// Optional: attach data to every outgoing message for this session
sdk.updateCustomData({ plan: 'enterprise' });
// Teardown
await sdk.dispose();Public API
| Member | Description |
| ------------------------------------- | ------------------------------------------------- |
| AgentSDK.initialize({ config, … }) | Parse/validate config and wire up clients. |
| AgentSDK.createWithConfig(config) | Create from an already-parsed SDKConfiguration. |
| connect() | Connect; resolves with the sessionId. |
| disconnect() | Close the socket (no end_session). |
| endSession() | Send end_session, clear custom data, close. |
| isConnected() / getSessionId() | Connection status helpers. |
| getWidgetConfig() | Server-provided widget theming config. |
| sendMessage(text, opts?) | Send a message; resolves with the local id. |
| getMessages() | Locally-stored messages. |
| updateCustomData() / getCustomData() / clearCustomData() | Session-scoped custom data. |
| clearHistory() | Clear the local message store. |
| on('event' \| 'chat', handler) | Subscribe; returns an unsubscribe function. |
| dispose() | Tear down and release all resources. |
Build
npm install
npm run build # tsc -> dist/Examples
- Headless smoke test — connect to the live runtime and send a message:
npm run smoke- React Native app (Android + iOS) — a chat UI that mirrors the Flutter
example. The
example/folder is the app itself; seeexample/README.mdfor run instructions (cd example && npm install && npm run android/npm run ios).
