tevrocsdk 0.1.75 → 0.1.76

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tevrocsdk",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "JavaScript SDK for the Tevroc API.",
5
5
  "main": "./tevroc-sdk.umd.js",
6
6
  "module": "./tevroc-sdk.esm.js",
package/tevroc-sdk.cjs.js CHANGED
@@ -47258,8 +47258,17 @@ function createAgentNotificationService(client) {
47258
47258
  const notify = (event) => listeners2.forEach((listener) => listener(event));
47259
47259
  const getSessionId = (session) => session.sessionId || session.session_id || session.id;
47260
47260
  const getMessages = async (sessionId, appId) => {
47261
- const result = await client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 });
47262
- return toList(result);
47261
+ const [bySessionId, byLegacySessionId] = await Promise.all([
47262
+ client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 }),
47263
+ client.entities.ChatMessage.query({ filter: { appId, session_id: sessionId }, limit: 100 })
47264
+ ]);
47265
+ const seenMessages = /* @__PURE__ */ new Set();
47266
+ return [...toList(bySessionId), ...toList(byLegacySessionId)].filter((message2) => {
47267
+ const key = message2?.id || `${message2?.createdAt || ""}:${message2?.content || ""}`;
47268
+ if (seenMessages.has(key)) return false;
47269
+ seenMessages.add(key);
47270
+ return true;
47271
+ });
47263
47272
  };
47264
47273
  const publish = (sessionId, payload) => {
47265
47274
  const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
@@ -47311,8 +47320,11 @@ function createAgentNotificationService(client) {
47311
47320
  };
47312
47321
  const dispatchAction = async ({ action, sessionId, reply: text }) => {
47313
47322
  const appId = client.appId;
47314
- const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }));
47315
- const session = sessions[0];
47323
+ const [bySessionId, byLegacySessionId] = await Promise.all([
47324
+ client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }),
47325
+ client.entities.ChatSession.query({ filter: { appId, session_id: sessionId }, limit: 1 })
47326
+ ]);
47327
+ const session = toList(bySessionId)[0] || toList(byLegacySessionId)[0];
47316
47328
  if (!session) return;
47317
47329
  if (action === "open") return notify({ type: "open", sessionId, session });
47318
47330
  if (action === "accept") return accept(session);