@iblai/data-layer 1.30.2 → 1.31.0

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/dist/index.js CHANGED
@@ -39950,6 +39950,17 @@ const buildRecentMessagesUrl = (args, pageParam) => {
39950
39950
  appendChatFilterParams(params, args);
39951
39951
  return `/api/ai-mentor/orgs/${args.org}/users/${args.userId}/recent-messages/?${params.toString()}`;
39952
39952
  };
39953
+ /**
39954
+ * The session id of the first recent-messages row, or `null` when there is
39955
+ * none. Assumes the endpoint lists newest first (not yet confirmed by the
39956
+ * backend) — this is the one place to change if that, or the source, changes.
39957
+ */
39958
+ const latestSessionIdFrom = (body) => {
39959
+ var _a;
39960
+ const rows = Array.isArray(body) ? body : body === null || body === void 0 ? void 0 : body.results;
39961
+ const sessionId = (_a = rows === null || rows === void 0 ? void 0 : rows[0]) === null || _a === void 0 ? void 0 : _a.session_id;
39962
+ return typeof sessionId === 'string' && sessionId ? sessionId : null;
39963
+ };
39953
39964
  /**
39954
39965
  * Build the user-wide pin-message list URL. Never carries `session_id` (the
39955
39966
  * endpoint does not accept it); `mentor`/`search` are appended only when non-empty.
@@ -40033,6 +40044,19 @@ const chatApiSlice = react.createApi({
40033
40044
  }),
40034
40045
  }),
40035
40046
  });
40047
+ /**
40048
+ * The user's latest session with an agent, read from page 0 of the same
40049
+ * `getRecentMessages` entry the chat-history sidebar subscribes to (`search: ''`
40050
+ * is its idle search box), so an agent open costs one request, not two.
40051
+ * `forceRefetch` in seconds is the time since `openedAt`: an entry fulfilled
40052
+ * before this open is refetched (another device may have started a chat since),
40053
+ * one fulfilled after it is reused, and one in flight is joined — RTK never
40054
+ * starts a second request for a pending entry.
40055
+ */
40056
+ const fetchLatestMentorSessionId = ({ org, userId, mentor }, openedAt) => async (dispatch) => {
40057
+ const data = await dispatch(chatApiSlice.endpoints.getRecentMessages.initiate({ org, userId, mentor, search: '' }, { forceRefetch: Math.max((Date.now() - openedAt) / 1000, 0.001), subscribe: false })).unwrap();
40058
+ return latestSessionIdFrom(data.pages[0]);
40059
+ };
40036
40060
  const { useLazyGetPinnedMessagesQuery, useUnPinMessageMutation, useDeleteMessageMutation, useGetPinnedMessagesQuery, useAddPinnedMessageMutation, useGetVectorDocumentsQuery, useLazyGetVectorDocumentsQuery, useGetRecentMessageQuery, useLazyGetRecentMessageQuery, useGetRecentMessagesInfiniteQuery, useUpdateMessageFeedbackMutation, useAudioToTextMutation, } = chatApiSlice;
40037
40061
 
40038
40062
  const chatCustomApiSlice = react.createApi({
@@ -43588,9 +43612,10 @@ const reportsApiSlice = react.createApi({
43588
43612
  async queryFn({ key, mentor_id }) {
43589
43613
  var _a, _b;
43590
43614
  try {
43591
- const baseUrl = getServiceUrl(exports.SERVICES.DM);
43615
+ const baseUrl = getServiceUrl(exports.SERVICES.DM).replace(/\/+$/, '');
43616
+ const dmBaseUrl = baseUrl.endsWith('/dm') ? baseUrl : `${baseUrl}/dm`;
43592
43617
  const authHeaders = await getHeaders(exports.SERVICES.DM);
43593
- const url = new URL(`${baseUrl}/dm/api/reports/platforms/${encodeURIComponent(key)}/`);
43618
+ const url = new URL(`${dmBaseUrl}/api/reports/platforms/${encodeURIComponent(key)}/`);
43594
43619
  if (mentor_id) {
43595
43620
  url.searchParams.set('mentor_id', mentor_id);
43596
43621
  }
@@ -50050,6 +50075,7 @@ exports.evaluationsApiSlice = evaluationsApiSlice;
50050
50075
  exports.extractBoundMentorIds = extractBoundMentorIds;
50051
50076
  exports.fakeBaseQueryWithLogging = fakeBaseQueryWithLogging;
50052
50077
  exports.featureTags = featureTags;
50078
+ exports.fetchLatestMentorSessionId = fetchLatestMentorSessionId;
50053
50079
  exports.fetchLearnerCompletion = fetchLearnerCompletion;
50054
50080
  exports.fetchUserLlmUsage = fetchUserLlmUsage;
50055
50081
  exports.filterCourseUserRoles = filterCourseUserRoles;
@@ -50079,6 +50105,7 @@ exports.isSpendCapExceededErrorBody = isSpendCapExceededErrorBody;
50079
50105
  exports.isUserLlmUsageEmpty = isUserLlmUsageEmpty;
50080
50106
  exports.isValidHostPort = isValidHostPort;
50081
50107
  exports.isVirtualMachineEgressNetworked = isVirtualMachineEgressNetworked;
50108
+ exports.latestSessionIdFrom = latestSessionIdFrom;
50082
50109
  exports.llmsApiSlice = llmsApiSlice;
50083
50110
  exports.mcpApiSlice = mcpApiSlice;
50084
50111
  exports.memoryApiSlice = memoryApiSlice;