@reititin/client 0.0.6 → 0.0.8

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 +20 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import http2 from 'http2';
2
2
  import axios from 'axios';
3
3
 
4
- export const ReititinClient = ({ agentId, onMessage }) => {
5
- const MESSAGE_ENDPOINT = `/api/agents/messages?agentId=${agentId}`;
6
- const FINALIZE_URL = "https://reititin.com/api/finalizeMessage";
7
- let stayIdle = null;
4
+ export const ReititinClient = ({ token, onMessage }) => {
5
+ const MESSAGE_ENDPOINT = `/api/agents/messages`;
6
+ const FINALIZE_URL = "https://test.reititin.com/api/finalizeMessage";
8
7
  let buffer = "";
9
8
 
10
9
  const connectSSE = () => {
@@ -12,14 +11,13 @@ export const ReititinClient = ({ agentId, onMessage }) => {
12
11
 
13
12
  console.log("Waiting for messages.");
14
13
 
15
- const client = http2.connect('https://reititin.com');
16
- const req = client.request({ ':method': 'GET', ':path': MESSAGE_ENDPOINT, 'accept': 'text/event-stream' })
17
- .setEncoding('utf8');
18
-
19
- stayIdle = setTimeout(() => {
20
- req.close();
21
- client.close();
22
- }, 55 * 60 * 1000);
14
+ const client = http2.connect('https://test.reititin.com');
15
+ const req = client.request({
16
+ ':method': 'GET',
17
+ ':path': MESSAGE_ENDPOINT,
18
+ 'accept': 'text/event-stream',
19
+ 'authorization': `Bearer ${token}`
20
+ }).setEncoding('utf8');
23
21
 
24
22
  req.on('data', chunk => buffer += chunk);
25
23
 
@@ -29,17 +27,24 @@ export const ReititinClient = ({ agentId, onMessage }) => {
29
27
  const chat_id = lines.find(line => line.startsWith('chat_id:'))?.split(': ')[1];
30
28
  const agent_id = lines.find(line => line.startsWith('agent_id:'))?.split(': ')[1];
31
29
  const rawData = lines.find(line => line.startsWith('data:'))?.replace('data: ', '');
32
- if (onMessage) {
30
+ if (onMessage && rawData && agent_id && chat_id) {
33
31
  console.log("Message received. Processing.");
34
32
  const processedMessage = await onMessage(JSON.parse(rawData));
35
- await axios.post(FINALIZE_URL, { chat_id: chat_id, agent_id: agent_id, message: processedMessage });
33
+ await axios.post(
34
+ FINALIZE_URL,
35
+ { chat_id, agent_id, message: processedMessage },
36
+ {
37
+ headers: {
38
+ Authorization: `Bearer ${token}`
39
+ }
40
+ }
41
+ );
36
42
  console.log(`Response sent.`);
37
43
  }
38
44
  buffer = "";
39
45
  } catch(err) {
40
46
  console.log("Reconnecting.");
41
47
  }
42
- stayIdle = null;
43
48
  scheduleReconnect();
44
49
  });
45
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reititin/client",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Reititin client allows you to connect your LLM system to Reititin platform.",
5
5
  "keywords": [
6
6
  "AI",