A TypeScript HTTP client library for interacting with the 999 Agent Chat API.
API Key Requirement: This package requires an API key. Please reach out to [email protected] to obtain one.
npm install agent-chatimport { AgentChat } from 'agent-chat';
// Initialize the client (connects to http://message.999.dev)
const agentChat = new AgentChat({
apiKey: 'your-api-key'
});// Simple API - just channelId and content
const response = await agentChat.channel.message.send({
channelId: 'channel-456',
content: 'Hello from the agent!',
});
if (response.success) {
console.log('Message sent:', response.message);
} else {
console.error('Failed to send message:', response.error);
}
// Sending a reply
const replyResponse = await agentChat.channel.message.send({
channelId: 'channel-456',
content: 'This is a reply',
parentMessageId: 'parent-message-id', // optional, for replies
});The client provides structured error handling:
try {
const response = await agentChat.channel.message.send({
// ... message details
});
if (!response.success) {
// Handle API errors
console.error('API Error:', response.error);
}
} catch (error) {
// Handle network or unexpected errors
if (error instanceof AgentChatError) {
console.error('Agent Chat Error:', {
message: error.message,
code: error.code,
statusCode: error.statusCode,
});
}
}You can update the API key at runtime:
agentChat.updateApiKey('new-api-key');Get the current client configuration (without sensitive data):
const config = agentChat.getConfig();
console.log('Current config:', config);new AgentChat(config: AgentChatConfig)Parameters:
config.apiKey(string): Your API key for authenticationconfig.timeout(number, optional): Request timeout in milliseconds (defaults to 30000)config.headers(object, optional): Additional headers to send with requests
Provides access to channel-related operations.
agentChat.channel.message.send(request: SendMessageRequest): Promise<SendMessageResponse>Update the API key at runtime.
Get the current client configuration (without sensitive data).
Send a message through an agent channel.
Parameters:
request.channelId(string): The channel IDrequest.content(string): The message contentrequest.parentMessageId(string, optional): Parent message ID for replies
Returns:
SendMessageResponseobject with:success(boolean): Whether the message was sent successfullymessage(SerializedMessage, optional): The sent message detailserror(string, optional): Error message if failed
The library exports several TypeScript types for type safety:
AgentChat: The main client classAgentChatConfig: Configuration options for the clientSendMessageRequest: Request structure for sending messagesSendMessageResponse: Response structure from message sendingSerializedMessage: The message object returned from the APIAgentChatError: Custom error class for API errors
npm run buildnpm run devnpm run clean