@reititin/client 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +6 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4,7 +4,7 @@ import axios from 'axios';
4
4
  const FINALIZE_URL = "https://apukone.com/api/finalizeMessage";
5
5
 
6
6
  export const createApukoneClient = ({ agentId, onMessage }) => {
7
- const SSE_ENDPOINT = `/api/agents/messages?agentId=${agentId}`;
7
+ const MESSAGE_ENDPOINT = `/api/agents/messages?agentId=${agentId}`;
8
8
  let buffer = "";
9
9
 
10
10
  const connectSSE = () => {
@@ -12,22 +12,22 @@ export const createApukoneClient = ({ agentId, onMessage }) => {
12
12
  console.log("Waiting for messages.");
13
13
 
14
14
  const client = http2.connect('https://apukone.com');
15
- const req = client.request({ ':method': 'GET', ':path': SSE_ENDPOINT, 'accept': 'text/event-stream' })
15
+ const req = client.request({ ':method': 'GET', ':path': MESSAGE_ENDPOINT, 'accept': 'text/event-stream' })
16
16
  .setEncoding('utf8');
17
17
 
18
18
  req.on('data', chunk => buffer += chunk);
19
19
 
20
20
  req.on('end', async () => {
21
21
  console.log("Received a message.")
22
- const [id, chat_id, agent_id, rawData] = buffer.split('\n')
23
- .map(line => line.split(': ')[1]);
24
-
22
+ const lines = buffer.split('\n').map(line => line.trim());
23
+ const chat_id = lines.find(line => line.startsWith('chat_id:'))?.split(': ')[1];
24
+ const agent_id = lines.find(line => line.startsWith('agent_id:'))?.split(': ')[1];
25
+ const rawData = lines.find(line => line.startsWith('data:'))?.replace('data: ', '');
25
26
  if (onMessage) {
26
27
  const processedMessage = await onMessage(rawData);
27
28
  await axios.post(FINALIZE_URL, { chat_id: chat_id, agent_id: agent_id, message: processedMessage });
28
29
  console.log(`Response sent.`);
29
30
  }
30
-
31
31
  buffer = "";
32
32
  scheduleReconnect();
33
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reititin/client",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Reititin client allows you to connect your LLM system to Reititin platform.",
5
5
  "keywords": [
6
6
  "AI",