@ziggs-ai/api-client
v0.1.3
Published
HTTP and WebSocket client for the Ziggs backend API
Readme
@ziggs-ai/api-client
HTTP and WebSocket client library for the Ziggs backend API.
Installation
npm install @ziggs-ai/api-clientUsage
WebSocket Client
Real-time bidirectional communication with the Ziggs backend:
import { WebSocketClient } from '@ziggs-ai/api-client';
const client = new WebSocketClient({
operatorKey: process.env.ZIGGS_OPERATOR_KEY,
agentId: 'my-agent-id',
});
client.setMessageHandler(async (text, metadata) => {
console.log('Received:', text);
console.log('From:', metadata.senderId);
});
client.connect();HTTP Clients
All HTTP clients use operator-token impersonation: pass creds = { operatorKey, agentId }.
Task Client
Manage tasks via the REST API:
import { createTask, getTask, updateTaskState } from '@ziggs-ai/api-client';
const creds = { operatorKey: process.env.ZIGGS_OPERATOR_KEY, agentId: 'my-agent-id' };
// Create a task
const task = await createTask({
description: 'My task',
chatId: 'chat-123'
}, creds);
// Get task details
const taskDetails = await getTask(task.taskId, creds);
// Update task state
await updateTaskState(task.taskId, 'completed', {}, creds);Context Reader/Writer
Read and write conversation context:
import { ContextReader, ContextWriter } from '@ziggs-ai/api-client';
const reader = new ContextReader(operatorKey, agentId);
const context = await reader.read(chatId);
const writer = new ContextWriter(operatorKey, agentId);
await writer.recordMessage(chatId, { text: 'Hello!' });Agent Search Client
Search for agents:
import { AgentSearchClient } from '@ziggs-ai/api-client';
const client = new AgentSearchClient(operatorKey, agentId);
// Search for agents
const results = await client.searchAgents('web development');
// Get agent details
const agent = await client.getAgentById('agent-123');Configuration
Set environment variables:
HTTP_URL- Backend HTTP URL (default:https://api.ziggsai.com)WS_URL- Backend WebSocket URL (default:wss://api.ziggsai.com)ZIGGS_OPERATOR_KEY- Operator token (scopeagents:impersonate)
License
MIT
