@opengeni/api-router 6.8.0 → 6.8.1-canary.41842879332001

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/app.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  withDefaultEnabledCapabilityMcpTools,
30
30
  workflowIdForSession,
31
31
  workspaceActorContextExempt
32
- } from "./chunk-A2VKA7K3.js";
32
+ } from "./chunk-HG3ZBJ7P.js";
33
33
  import "./chunk-OGQDXVXY.js";
34
34
  export {
35
35
  API_MAX_REQUEST_BODY_BYTES,
@@ -135800,6 +135800,7 @@ import {
135800
135800
  CreateRecordingLiveSessionRequest,
135801
135801
  CreateRecordingPersonRequest,
135802
135802
  CreateRecordingRequest,
135803
+ UpcomingMeetingsResponse,
135803
135804
  CreateRecordingTranscriptRequest,
135804
135805
  CreateRecordingUploadsRequest,
135805
135806
  RecordingCapturePurpose,
@@ -135877,6 +135878,65 @@ import {
135877
135878
  speechToTextServesMeetings
135878
135879
  } from "@opengeni/core/transcription-service";
135879
135880
 
135881
+ // src/meeting-join-links.ts
135882
+ function hostIs(url, domain) {
135883
+ const host = url.hostname.toLowerCase();
135884
+ return host === domain || host.endsWith(`.${domain}`);
135885
+ }
135886
+ var SERVICES = [
135887
+ {
135888
+ name: "Google Meet",
135889
+ // meet.google.com/abc-defg-hij or a lookup link; not /new, /landing or the home page.
135890
+ matches: (url) => url.hostname.toLowerCase() === "meet.google.com" && /^\/([a-z]{3}-[a-z]{4}-[a-z]{3}|lookup\/[\w-]+)(\/|$)/iu.test(url.pathname)
135891
+ },
135892
+ {
135893
+ name: "Zoom",
135894
+ matches: (url) => (hostIs(url, "zoom.us") || hostIs(url, "zoom.com") || hostIs(url, "zoomgov.com")) && /^\/(j|my|w|wc\/join|s)\//iu.test(url.pathname)
135895
+ },
135896
+ {
135897
+ name: "Microsoft Teams",
135898
+ matches: (url) => (hostIs(url, "teams.microsoft.com") || hostIs(url, "teams.live.com") || hostIs(url, "teams.cloud.microsoft")) && /\/(l\/meetup-join|meet)\//iu.test(url.pathname)
135899
+ },
135900
+ {
135901
+ name: "Webex",
135902
+ // A meeting room or join link, not the site's other pages.
135903
+ matches: (url) => hostIs(url, "webex.com") && /^\/(meet\/|join\/|[\w-]+\/j\.php|j\.php|wbxmjs\/joinservice\/)/iu.test(url.pathname)
135904
+ }
135905
+ ];
135906
+ function meetingJoinLink(value) {
135907
+ if (typeof value !== "string" || value.length > 2048) return null;
135908
+ let url;
135909
+ try {
135910
+ url = new URL(value.trim());
135911
+ } catch {
135912
+ return null;
135913
+ }
135914
+ if (url.protocol !== "https:" || url.username || url.password) return null;
135915
+ const service = SERVICES.find((candidate) => candidate.matches(url));
135916
+ return service ? { url: url.toString(), service: service.name } : null;
135917
+ }
135918
+ var LINK = /https:\/\/[^\s<>"'()[\]{}]+/giu;
135919
+ function meetingJoinLinkIn(text3) {
135920
+ if (typeof text3 !== "string") return null;
135921
+ const plain2 = text3.slice(0, 2e4).replace(/&amp;/giu, "&");
135922
+ for (const match of plain2.matchAll(LINK)) {
135923
+ const found = meetingJoinLink(match[0].replace(/[.,;:!?]+$/u, ""));
135924
+ if (found) return found;
135925
+ }
135926
+ return null;
135927
+ }
135928
+ function firstMeetingJoinLink(links, texts) {
135929
+ for (const link of links) {
135930
+ const found = meetingJoinLink(link);
135931
+ if (found) return found;
135932
+ }
135933
+ for (const text3 of texts) {
135934
+ const found = meetingJoinLinkIn(text3);
135935
+ if (found) return found;
135936
+ }
135937
+ return null;
135938
+ }
135939
+
135880
135940
  // src/meeting-calendar-title.ts
135881
135941
  import {
135882
135942
  buildConnectionTokenResolver as buildConnectionTokenResolver8,
@@ -135890,10 +135950,19 @@ var MICROSOFT_CALENDAR_SCOPES = /* @__PURE__ */ new Set(["calendars.read", "cale
135890
135950
  var MEETING_CALENDAR_LOOKUP_TIMEOUT_MS = 3e3;
135891
135951
  var STARTS_SOON_MS = 10 * 6e4;
135892
135952
  var ENDS_SOON_MS = 6e4;
135893
- function meetingEventAt(events, at) {
135953
+ function nameable(event) {
135954
+ return event.meeting && !event.private && !event.declined && calendarTitle(event.title) !== null && event.end.getTime() > event.start.getTime();
135955
+ }
135956
+ function meetingEventAt(events, at, chosen) {
135957
+ if (chosen) {
135958
+ const found = events.find(
135959
+ (event) => event.id === chosen.id && event.provider === chosen.provider
135960
+ );
135961
+ if (found) return nameable(found) ? found : null;
135962
+ }
135894
135963
  const time = at.getTime();
135895
135964
  const fitting = events.filter(
135896
- (event) => event.meeting && !event.private && !event.declined && calendarTitle(event.title) !== null && event.start.getTime() <= time + STARTS_SOON_MS && event.end.getTime() > time + ENDS_SOON_MS && event.end.getTime() > event.start.getTime()
135965
+ (event) => nameable(event) && event.start.getTime() <= time + STARTS_SOON_MS && event.end.getTime() > time + ENDS_SOON_MS
135897
135966
  );
135898
135967
  fitting.sort(
135899
135968
  (a, b) => Number(a.unanswered === true) - Number(b.unanswered === true) || Math.abs(a.start.getTime() - time) - Math.abs(b.start.getTime() - time) || a.end.getTime() - a.start.getTime() - (b.end.getTime() - b.start.getTime())
@@ -135916,15 +135985,23 @@ function googleCalendarEvents(body6) {
135916
135985
  return [];
135917
135986
  const eventType = typeof item.eventType === "string" ? item.eventType : "default";
135918
135987
  const self = Array.isArray(item.attendees) ? item.attendees.find((attendee) => attendee?.self === true) : void 0;
135988
+ const video = Array.isArray(item.conferenceData?.entryPoints) ? item.conferenceData.entryPoints.filter((entry2) => entry2?.entryPointType === "video").map((entry2) => entry2.uri) : [];
135989
+ const join = firstMeetingJoinLink(
135990
+ [item.hangoutLink, ...video],
135991
+ [item.location, item.description]
135992
+ );
135919
135993
  return [
135920
135994
  {
135995
+ ...typeof item.id === "string" && item.id ? { id: item.id } : {},
135996
+ provider: "google",
135921
135997
  title: item.summary,
135922
135998
  start: start ?? /* @__PURE__ */ new Date(0),
135923
135999
  end: end ?? /* @__PURE__ */ new Date(0),
135924
136000
  meeting: !allDay && (eventType === "default" || eventType === "fromGmail"),
135925
136001
  private: item.visibility === "private" || item.visibility === "confidential",
135926
136002
  declined: item.status === "cancelled" || self?.responseStatus === "declined",
135927
- unanswered: self?.responseStatus === "needsAction"
136003
+ unanswered: self?.responseStatus === "needsAction",
136004
+ ...join ? { joinUrl: join.url, service: join.service } : {}
135928
136005
  }
135929
136006
  ];
135930
136007
  });
@@ -135941,15 +136018,22 @@ function graphCalendarEvents(body6) {
135941
136018
  const start = graphTime(item?.start?.dateTime);
135942
136019
  const end = graphTime(item?.end?.dateTime);
135943
136020
  if (typeof item?.subject !== "string" || !start || !end) return [];
136021
+ const join = firstMeetingJoinLink(
136022
+ [item.onlineMeeting?.joinUrl, item.onlineMeetingUrl, item.location?.locationUri],
136023
+ [item.location?.displayName, item.body?.content]
136024
+ );
135944
136025
  return [
135945
136026
  {
136027
+ ...typeof item.id === "string" && item.id ? { id: item.id } : {},
136028
+ provider: "microsoft",
135946
136029
  title: item.subject,
135947
136030
  start,
135948
136031
  end,
135949
136032
  meeting: item.isAllDay !== true && item.showAs !== "oof" && item.showAs !== "workingElsewhere",
135950
136033
  private: item.sensitivity === "private" || item.sensitivity === "personal" || item.sensitivity === "confidential",
135951
136034
  declined: item.isCancelled === true || item.responseStatus?.response === "declined",
135952
- unanswered: item.responseStatus?.response === "notResponded"
136035
+ unanswered: item.responseStatus?.response === "notResponded",
136036
+ ...join ? { joinUrl: join.url, service: join.service } : {}
135953
136037
  }
135954
136038
  ];
135955
136039
  });
@@ -135970,36 +136054,37 @@ function meetingCalendarConnections(connections, input) {
135970
136054
  return false;
135971
136055
  });
135972
136056
  }
135973
- function eventsRequest(connection, at) {
135974
- const from = new Date(at.getTime() + ENDS_SOON_MS).toISOString();
135975
- const to = new Date(at.getTime() + STARTS_SOON_MS).toISOString();
136057
+ var GOOGLE_FIELDS = "items(id,summary,status,visibility,eventType,start,end,attendees(self,responseStatus))";
136058
+ var GOOGLE_JOIN_FIELDS = "items(id,summary,status,visibility,eventType,start,end,attendees(self,responseStatus),hangoutLink,conferenceData(entryPoints(entryPointType,uri)),location,description)";
136059
+ var GRAPH_SELECT = "id,subject,isAllDay,isCancelled,sensitivity,showAs,start,end,responseStatus";
136060
+ var GRAPH_JOIN_SELECT = `${GRAPH_SELECT},onlineMeeting,onlineMeetingUrl,location,body`;
136061
+ function eventsRequest(connection, window) {
136062
+ const from = window.from.toISOString();
136063
+ const to = window.to.toISOString();
135976
136064
  if (connection.providerDomain.toLowerCase() === GOOGLE_CALENDAR_PROVIDER_DOMAIN) {
135977
136065
  const url2 = new URL(GOOGLE_EVENTS_URL);
135978
136066
  url2.searchParams.set("timeMin", from);
135979
136067
  url2.searchParams.set("timeMax", to);
135980
136068
  url2.searchParams.set("singleEvents", "true");
135981
136069
  url2.searchParams.set("maxResults", "25");
135982
- url2.searchParams.set(
135983
- "fields",
135984
- "items(summary,status,visibility,eventType,start,end,attendees(self,responseStatus))"
135985
- );
136070
+ url2.searchParams.set("fields", window.join ? GOOGLE_JOIN_FIELDS : GOOGLE_FIELDS);
135986
136071
  return { url: url2.toString(), headers: {}, parse: googleCalendarEvents };
135987
136072
  }
135988
136073
  const url = new URL(GRAPH_CALENDAR_VIEW_URL);
135989
136074
  url.searchParams.set("startDateTime", from);
135990
136075
  url.searchParams.set("endDateTime", to);
135991
136076
  url.searchParams.set("$top", "25");
135992
- url.searchParams.set(
135993
- "$select",
135994
- "subject,isAllDay,isCancelled,sensitivity,showAs,start,end,responseStatus"
135995
- );
136077
+ url.searchParams.set("$select", window.join ? GRAPH_JOIN_SELECT : GRAPH_SELECT);
135996
136078
  return {
135997
136079
  url: url.toString(),
135998
- headers: { Prefer: 'outlook.timezone="UTC"' },
136080
+ // The body as text, where a join link written into the invitation is found.
136081
+ headers: {
136082
+ Prefer: window.join ? 'outlook.timezone="UTC", outlook.body-content-type="text"' : 'outlook.timezone="UTC"'
136083
+ },
135999
136084
  parse: graphCalendarEvents
136000
136085
  };
136001
136086
  }
136002
- async function meetingCalendarTitle(lookup, input) {
136087
+ async function readMeetingCalendars(lookup, input) {
136003
136088
  const timeout = AbortSignal.timeout(lookup.timeoutMs ?? MEETING_CALENDAR_LOOKUP_TIMEOUT_MS);
136004
136089
  let settled = false;
136005
136090
  const problem = (providerDomain, reason) => {
@@ -136014,28 +136099,35 @@ async function meetingCalendarTitle(lookup, input) {
136014
136099
  subjectId: input.subjectId,
136015
136100
  googleCalendarEnabled: lookup.googleCalendarEnabled
136016
136101
  });
136017
- if (connections.length === 0) return null;
136102
+ if (connections.length === 0) return { connected: false, complete: true, events: [] };
136103
+ let complete = true;
136018
136104
  const found = await Promise.all(
136019
136105
  connections.map(async (connection) => {
136020
136106
  try {
136021
- const request = eventsRequest(connection, input.at);
136107
+ const request = eventsRequest(connection, input);
136022
136108
  const credential = await lookup.credentialHeaders(connection, request.url);
136023
136109
  if (!credential) {
136110
+ complete = false;
136024
136111
  problem(connection.providerDomain, "credential unavailable");
136025
136112
  return [];
136026
136113
  }
136027
- if (timeout.aborted) return [];
136114
+ if (timeout.aborted) {
136115
+ complete = false;
136116
+ return [];
136117
+ }
136028
136118
  const response = await lookup.fetch(request.url, {
136029
136119
  headers: { ...credential, ...request.headers, Accept: "application/json" },
136030
136120
  redirect: "error",
136031
136121
  signal: timeout
136032
136122
  });
136033
136123
  if (!response.ok) {
136124
+ complete = false;
136034
136125
  problem(connection.providerDomain, `HTTP ${response.status}`);
136035
136126
  return [];
136036
136127
  }
136037
136128
  return request.parse(await response.json());
136038
136129
  } catch (error) {
136130
+ complete = false;
136039
136131
  if (!timeout.aborted) {
136040
136132
  problem(connection.providerDomain, error instanceof Error ? error.name : "failed");
136041
136133
  }
@@ -136043,8 +136135,7 @@ async function meetingCalendarTitle(lookup, input) {
136043
136135
  }
136044
136136
  })
136045
136137
  );
136046
- const event = meetingEventAt(found.flat(), input.at);
136047
- return event ? calendarTitle(event.title) : null;
136138
+ return { connected: true, complete, events: found.flat() };
136048
136139
  };
136049
136140
  const expired = new Promise((resolve2) => {
136050
136141
  timeout.addEventListener(
@@ -136065,6 +136156,58 @@ async function meetingCalendarTitle(lookup, input) {
136065
136156
  settled = true;
136066
136157
  }
136067
136158
  }
136159
+ async function meetingCalendarTitle(lookup, input) {
136160
+ const read = await readMeetingCalendars(lookup, {
136161
+ subjectId: input.subjectId,
136162
+ from: new Date(input.at.getTime() + ENDS_SOON_MS),
136163
+ to: new Date(input.at.getTime() + STARTS_SOON_MS),
136164
+ join: false
136165
+ });
136166
+ const event = read ? meetingEventAt(read.events, input.at, input.event) : null;
136167
+ return event ? calendarTitle(event.title) : null;
136168
+ }
136169
+ var UPCOMING_MEETINGS_AHEAD_MS = 20 * 6e4;
136170
+ var UPCOMING_MEETINGS_STARTED_MS = 5 * 6e4;
136171
+ function upcomingMeetingsAt(events, now) {
136172
+ const time = now.getTime();
136173
+ const seen = /* @__PURE__ */ new Set();
136174
+ return events.filter(
136175
+ (event) => event.meeting && !event.declined && event.id !== void 0 && event.provider !== void 0 && event.joinUrl !== void 0 && event.end.getTime() > time && event.end.getTime() > event.start.getTime() && event.start.getTime() >= time - UPCOMING_MEETINGS_STARTED_MS && event.start.getTime() <= time + UPCOMING_MEETINGS_AHEAD_MS
136176
+ ).sort(
136177
+ (a, b) => a.start.getTime() - b.start.getTime() || Number(a.unanswered === true) - Number(b.unanswered === true) || a.end.getTime() - a.start.getTime() - (b.end.getTime() - b.start.getTime())
136178
+ ).flatMap((event) => {
136179
+ const key2 = `${event.provider}:${event.id}`;
136180
+ if (seen.has(key2)) return [];
136181
+ seen.add(key2);
136182
+ return [
136183
+ {
136184
+ id: event.id,
136185
+ provider: event.provider,
136186
+ title: calendarTitle(event.title) ?? "",
136187
+ private: event.private,
136188
+ startsAt: event.start.toISOString(),
136189
+ endsAt: event.end.toISOString(),
136190
+ joinUrl: event.joinUrl,
136191
+ service: event.service ?? "Meeting",
136192
+ unanswered: event.unanswered === true
136193
+ }
136194
+ ];
136195
+ });
136196
+ }
136197
+ async function upcomingMeetings(lookup, input) {
136198
+ const read = await readMeetingCalendars(lookup, {
136199
+ subjectId: input.subjectId,
136200
+ from: input.now,
136201
+ to: new Date(input.now.getTime() + UPCOMING_MEETINGS_AHEAD_MS),
136202
+ join: true
136203
+ });
136204
+ if (read === null) return { calendar: "connected", complete: false, meetings: [] };
136205
+ return {
136206
+ calendar: read.connected ? "connected" : "none",
136207
+ complete: read.complete,
136208
+ meetings: upcomingMeetingsAt(read.events, input.now)
136209
+ };
136210
+ }
136068
136211
  function meetingCalendarLookup(input) {
136069
136212
  const resolve2 = buildConnectionTokenResolver8(input.db, input.settings);
136070
136213
  return {
@@ -136607,7 +136750,11 @@ function registerRecordingRoutes(app, deps, options = {}) {
136607
136750
  reason: problem.reason
136608
136751
  })
136609
136752
  }),
136610
- { subjectId: actor.subjectId, at: startedAt }
136753
+ {
136754
+ subjectId: actor.subjectId,
136755
+ at: startedAt,
136756
+ ...body6.calendarEvent ? { event: body6.calendarEvent } : {}
136757
+ }
136611
136758
  ) : null
136612
136759
  ]);
136613
136760
  const ownerName = recordingMicrophoneIsOwner(body6.tracks) ? memberName ?? body6.ownerName ?? null : null;
@@ -136619,7 +136766,8 @@ function registerRecordingRoutes(app, deps, options = {}) {
136619
136766
  visibility: body6.visibility ?? settings.defaultVisibility ?? "private",
136620
136767
  startedAt,
136621
136768
  externalRef: body6.externalRef,
136622
- metadata: body6.metadata,
136769
+ // The calendar event it was started for stays with it.
136770
+ metadata: body6.calendarEvent ? { ...body6.metadata, calendarEvent: body6.calendarEvent } : body6.metadata,
136623
136771
  tracks: body6.tracks,
136624
136772
  transcription,
136625
136773
  ownerName
@@ -136635,6 +136783,26 @@ function registerRecordingRoutes(app, deps, options = {}) {
136635
136783
  }
136636
136784
  return c.json(result2.recording, result2.created ? 201 : 200);
136637
136785
  });
136786
+ app.get("/v1/workspaces/:workspaceId/upcoming-meetings", async (c) => {
136787
+ const actor = await actorFor2(c, "sessions:read");
136788
+ const result2 = await upcomingMeetings(
136789
+ meetingCalendarLookup({
136790
+ db,
136791
+ settings: deps.settings,
136792
+ workspaceId: actor.workspaceId,
136793
+ subjectId: actor.subjectId,
136794
+ ...deps.meetingCalendarFetch ? { fetch: deps.meetingCalendarFetch } : {},
136795
+ onProblem: (problem) => observability?.warn("couldn't read the caller's calendar for upcoming meetings", {
136796
+ workspaceId: actor.workspaceId,
136797
+ providerDomain: problem.providerDomain,
136798
+ reason: problem.reason
136799
+ })
136800
+ }),
136801
+ { subjectId: actor.subjectId, now: /* @__PURE__ */ new Date() }
136802
+ );
136803
+ c.header("Cache-Control", "no-store");
136804
+ return c.json(UpcomingMeetingsResponse.parse(result2));
136805
+ });
136638
136806
  app.get(`${base}/:recordingId`, async (c) => {
136639
136807
  const actor = await actorFor2(c, "sessions:read");
136640
136808
  return c.json(
@@ -157431,4 +157599,4 @@ export {
157431
157599
  withDefaultEnabledCapabilityMcpTools,
157432
157600
  workflowIdForSession4 as workflowIdForSession
157433
157601
  };
157434
- //# sourceMappingURL=chunk-A2VKA7K3.js.map
157602
+ //# sourceMappingURL=chunk-HG3ZBJ7P.js.map