@sentry/junior-google 0.317.0 → 0.319.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.
Files changed (2) hide show
  1. package/dist/index.js +84 -103
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -21,28 +21,11 @@ const GOOGLE_CLIENT_SECRET_ENV = "GOOGLE_CLIENT_SECRET";
21
21
  const GOOGLE_ACCOUNT_EMAIL_ENV = "GOOGLE_WORKSPACE_ACCOUNT_EMAIL";
22
22
  const GOOGLE_ALLOWED_DOMAINS_ENV = "GOOGLE_WORKSPACE_ALLOWED_DOMAINS";
23
23
  /**
24
- * API scopes the tools need. A connected grant must have all of them. Request
25
- * nothing broader.
26
- *
27
- * - `calendar.events.freebusy`: availability for `findMeetingTimes`.
28
- * - `calendar.events.readonly`: events that Junior's account can see on other
29
- * people's calendars, for `listCalendarEvents`. Google sharing settings
30
- * still decide how much detail each calendar shows.
31
- * - `calendar.events.owned`: create and change events on Junior's own
32
- * calendar.
33
- * - `documents`: create Docs and edit Docs that Junior's account can already
34
- * edit, through the Docs API. It gives no access to other Drive files and
35
- * cannot change sharing.
36
- * - `drive.file`: make the requester the owner of a Doc or presentation that
37
- * Junior created, then remove Junior's own access to a Doc. It only covers
38
- * files this OAuth client created, so it cannot change sharing on other
39
- * files. Full `drive` is not needed.
40
- * - `drive.readonly`: search Drive, export Docs, read Sheets and Slides, and
41
- * read comments. The Drive comments API accepts no narrower read scope. The
42
- * Sheets and Slides APIs also accept this scope.
43
- * - `presentations`: create presentations and edit Slides that Junior's
44
- * account can already edit, through the Slides API. Like `documents`, it
45
- * cannot change sharing.
24
+ * API scopes the tools need; a grant must have all and nothing broader.
25
+ * `drive.file` covers only files this client created, so Junior hands over
26
+ * its Docs without sharing rights on other files. `drive.readonly` is the
27
+ * narrowest scope the comments API accepts. `documents` and `presentations`
28
+ * cannot change sharing. Calendar stays at free/busy, read, and own events.
46
29
  */
47
30
  const GOOGLE_API_SCOPES = [
48
31
  "https://www.googleapis.com/auth/calendar.events.freebusy",
@@ -1000,6 +983,15 @@ function googleApiError(operation, response) {
1000
983
  const message = `Google ${operation} failed with HTTP ${response.status}${detail ? `: ${detail}` : ""}`;
1001
984
  return response.status === 400 ? new PluginToolInputError(`${message}. Fix the input that Google names and call the tool again.`) : new Error(message);
1002
985
  }
986
+ // src/inbox-subjects.ts
987
+ /** The subject kinds of Google objects. */
988
+ const GOOGLE_SUBJECT_KINDS = { calendarEvent: "calendar_event" };
989
+ /** The registered kinds and labels, for the plugin registration. */
990
+ const googleInboxSubjectKinds = [{
991
+ kind: GOOGLE_SUBJECT_KINDS.calendarEvent,
992
+ label: "Calendar event",
993
+ owner: "annotation"
994
+ }];
1003
995
  // src/calendar/events.ts
1004
996
  /** Format one interval for people, in the requested time zone. */
1005
997
  function formatInterval(startMs, endMs, timeZone) {
@@ -1094,32 +1086,23 @@ const ownEventSchema = z.object({
1094
1086
  * Shape one event on Junior's calendar for a tool result.
1095
1087
  *
1096
1088
  * Core saves the Calendar event annotation and shows its card with the next
1097
- * reply. The event id is the key, so a change replaces the saved card. The
1098
- * label is the short date for the sidebar; the card shows the full time.
1089
+ * reply. The event id is the key, so a change replaces the saved card.
1099
1090
  */
1100
- function ownEventResult(event, timeZone, accountEmail) {
1091
+ function ownEventResult(event, timeZone, accountEmail, action) {
1101
1092
  const url = event.htmlLink && accountChooserLink(event.htmlLink, accountEmail);
1102
- const startMs = Date.parse(event.start.dateTime);
1103
- const when = formatInterval(startMs, Date.parse(event.end.dateTime), timeZone);
1093
+ const when = formatInterval(Date.parse(event.start.dateTime), Date.parse(event.end.dateTime), timeZone);
1104
1094
  return {
1105
1095
  objectAnnotations: [{
1096
+ action,
1106
1097
  kind: "object",
1107
1098
  key: event.id,
1108
- label: new Intl.DateTimeFormat("en-US", {
1109
- day: "numeric",
1110
- month: "short",
1111
- timeZone
1112
- }).format(startMs),
1099
+ subject: {
1100
+ id: event.id,
1101
+ kind: GOOGLE_SUBJECT_KINDS.calendarEvent
1102
+ },
1113
1103
  objectType: "calendar_event",
1114
1104
  title: (event.summary?.trim() || "Untitled event").slice(0, 512),
1115
- url: url || null,
1116
- description: event.description?.trim().slice(0, 4e3) || void 0,
1117
- sourceUpdatedAt: event.updated,
1118
- facts: {
1119
- type: "calendar_event",
1120
- when,
1121
- attendees: (event.attendees ?? []).filter((attendee) => attendee.resource !== true).slice(0, 5).map((attendee) => (attendee.displayName?.trim() || attendee.email).slice(0, 160))
1122
- }
1105
+ url: url || null
1123
1106
  }],
1124
1107
  attendees: attendeeResults(event.attendees),
1125
1108
  end: event.end.dateTime,
@@ -1284,6 +1267,17 @@ const linkedEventSchema = z.object({
1284
1267
  summary: z.string().optional(),
1285
1268
  updated: z.string().optional()
1286
1269
  });
1270
+ const CALENDAR_HOSTS = /* @__PURE__ */ new Set(["calendar.google.com", "www.google.com"]);
1271
+ /**
1272
+ * Return the Calendar link itself, or the Calendar link that an
1273
+ * AccountChooser link opens. Workspace event links use AccountChooser so
1274
+ * that they open in the right account.
1275
+ */
1276
+ function calendarLink(url) {
1277
+ if (url.hostname !== "accounts.google.com") return url;
1278
+ const link = URL.parse(url.searchParams.get("continue") ?? "");
1279
+ return link?.protocol === "https:" && CALENDAR_HOSTS.has(link.hostname) ? link : void 0;
1280
+ }
1287
1281
  /**
1288
1282
  * Return the event id when the link points to an event on the calendar of
1289
1283
  * `calendarEmail`. The `eid` value is base64 for `<eventId> <calendar>`.
@@ -1323,11 +1317,12 @@ function viewerIsOnEvent(event, viewer) {
1323
1317
  const EVENT_READ_TTL_MS = 1e4;
1324
1318
  /**
1325
1319
  * Read the linked event from Junior's calendar. Nothing for an event on
1326
- * another calendar, or a deleted or cancelled one.
1320
+ * another calendar, or one that Google no longer returns.
1327
1321
  */
1328
1322
  async function readLinkedEvent(ctx, url) {
1329
1323
  const config = readGoogleConfig();
1330
- const eventId = config && parseEventLink(url, config.accountEmail);
1324
+ const link = calendarLink(url);
1325
+ const eventId = config && link && parseEventLink(link, config.accountEmail);
1331
1326
  if (!eventId) return null;
1332
1327
  return await ctx.cache.getOrLoad(`calendar-event:${eventId}`, async () => ({
1333
1328
  value: await fetchLinkedEvent(ctx, eventId),
@@ -1346,7 +1341,7 @@ async function fetchLinkedEvent(ctx, eventId) {
1346
1341
  ].includes(response.status)) return null;
1347
1342
  if (response.status !== 200) throw googleApiError("google.calendar.event.get", response);
1348
1343
  const parsed = linkedEventSchema.safeParse(response.body);
1349
- return parsed.success && parsed.data.status !== "cancelled" ? parsed.data : null;
1344
+ return parsed.success ? parsed.data : null;
1350
1345
  }
1351
1346
  async function canViewGoogleCalendarLink(ctx, url) {
1352
1347
  const event = await readLinkedEvent(ctx, url);
@@ -1360,10 +1355,15 @@ async function resolveGoogleCalendarLink(ctx, url) {
1360
1355
  kind: "object",
1361
1356
  objectType: "calendar_event",
1362
1357
  key: event.id,
1358
+ subject: {
1359
+ id: event.id,
1360
+ kind: GOOGLE_SUBJECT_KINDS.calendarEvent
1361
+ },
1363
1362
  label: title.slice(0, 80),
1364
1363
  title: title.slice(0, 512),
1365
1364
  url: url.href,
1366
1365
  sourceUpdatedAt: event.updated,
1366
+ ...event.status === "cancelled" ? { status: "cancelled" } : void 0,
1367
1367
  facts: {
1368
1368
  type: "calendar_event",
1369
1369
  summary: htmlSummary(event.description),
@@ -1371,27 +1371,36 @@ async function resolveGoogleCalendarLink(ctx, url) {
1371
1371
  }
1372
1372
  };
1373
1373
  }
1374
+ const CALENDAR_EVENT_FILTERS = [
1375
+ {
1376
+ host: "calendar.google.com",
1377
+ path: "/calendar/event"
1378
+ },
1379
+ {
1380
+ host: "www.google.com",
1381
+ path: "/calendar/event"
1382
+ },
1383
+ {
1384
+ host: "calendar.google.com",
1385
+ pathPattern: "/calendar/r/eventedit/*"
1386
+ },
1387
+ {
1388
+ host: "calendar.google.com",
1389
+ pathPattern: "/calendar/u/*/r/eventedit/*"
1390
+ }
1391
+ ];
1374
1392
  /** Google Calendar event links that resolve to Calendar event cards. */
1375
1393
  const googleCalendarLinks = {
1376
- filters: [
1377
- {
1378
- host: "calendar.google.com",
1379
- path: "/calendar/event"
1380
- },
1381
- {
1382
- host: "www.google.com",
1383
- path: "/calendar/event"
1384
- },
1385
- {
1386
- host: "calendar.google.com",
1387
- pathPattern: "/calendar/r/eventedit/*"
1388
- },
1389
- {
1390
- host: "calendar.google.com",
1391
- pathPattern: "/calendar/u/*/r/eventedit/*"
1394
+ filters: [...CALENDAR_EVENT_FILTERS, {
1395
+ host: "accounts.google.com",
1396
+ path: "/AccountChooser",
1397
+ target: {
1398
+ param: "continue",
1399
+ filters: CALENDAR_EVENT_FILTERS
1392
1400
  }
1393
- ],
1401
+ }],
1394
1402
  canView: canViewGoogleCalendarLink,
1403
+ label: (url) => calendarLink(url) ? "Calendar event" : void 0,
1395
1404
  objectTypes: ["calendar_event"],
1396
1405
  resolve: resolveGoogleCalendarLink
1397
1406
  };
@@ -1901,7 +1910,7 @@ const cancelCalendarEventTool = definePluginTool({
1901
1910
  const { event, path } = read;
1902
1911
  const result = {
1903
1912
  target: "cancelCalendarEvent",
1904
- ...ownEventResult(event, timeZone, ctx.accountEmail)
1913
+ ...ownEventResult(event, timeZone, ctx.accountEmail, "changed")
1905
1914
  };
1906
1915
  const response = await googleApiRequest(ctx, {
1907
1916
  operation: "google.calendar.event.delete",
@@ -1911,10 +1920,6 @@ const cancelCalendarEventTool = definePluginTool({
1911
1920
  if (response.status !== 204 && response.status !== 410) throw googleApiError("google.calendar.event.delete", response);
1912
1921
  return {
1913
1922
  ...result,
1914
- objectAnnotations: result.objectAnnotations.map((annotation) => ({
1915
- ...annotation,
1916
- status: "cancelled"
1917
- })),
1918
1923
  cancelled: response.status === 204
1919
1924
  };
1920
1925
  }
@@ -2469,7 +2474,7 @@ const createCalendarEventTool = definePluginTool({
2469
2474
  return {
2470
2475
  target: "createCalendarEvent",
2471
2476
  created,
2472
- ...ownEventResult(ownEventSchema.parse(event.body), timeZone, ctx.accountEmail)
2477
+ ...ownEventResult(ownEventSchema.parse(event.body), timeZone, ctx.accountEmail, "created")
2473
2478
  };
2474
2479
  }
2475
2480
  });
@@ -2610,13 +2615,11 @@ function wallClockMs(startMs, endMs, timeZone) {
2610
2615
  return Date.parse(`${end.date}T00:00:00Z`) - Date.parse(`${start.date}T00:00:00Z`) + (end.minutes - start.minutes) * 6e4;
2611
2616
  }
2612
2617
  /**
2613
- * Learn a person's hours from their past meetings on weekdays.
2614
- *
2615
- * Google does not expose the working hours people set in Calendar. Instead,
2616
- * when at least three past weekdays had a meeting that started before 09:00
2617
- * or ended after 17:00, the hours grow to include that time. They never
2618
- * shrink, because a free morning does not mean the person is away. Meetings
2619
- * that cross local midnight are ignored.
2618
+ * Learn a person's hours from their past weekday meetings, because Google
2619
+ * does not expose Calendar working hours. When `HISTORY_MIN_DAYS` days had a
2620
+ * meeting outside the default workday, the hours grow to include it. They
2621
+ * never shrink, since a free morning is not absence. Meetings that cross
2622
+ * midnight are ignored.
2620
2623
  */
2621
2624
  function workingHoursFromMeetings(input) {
2622
2625
  const format = localFormat(input.timeZone);
@@ -2731,34 +2734,11 @@ function spreadAcrossDays(candidates, max) {
2731
2734
  return result;
2732
2735
  }
2733
2736
  /**
2734
- * Find slots when every required attendee is free, inside their working
2735
- * hours in their own time zone, and rank them by how little they disturb
2736
- * those days.
2737
- *
2738
- * Days on which more attendees already have a meeting come first, so days
2739
- * without meetings stay free. A day without meetings is used only when busy
2740
- * days have too few slots. The requester chose this over pure focus time.
2741
- *
2742
- * Then the rules follow Clockwise's public docs, not its code:
2743
- * - Focus time is the free time in blocks of at least 2 hours, or 1 hour on
2744
- * a day without a 2-hour block. Slots that remove the least focus time,
2745
- * summed over attendees, come first. Optional attendees count half.
2746
- * - Among equal slots, the one that adds the fewest new runs of meetings
2747
- * comes first, so a slot next to a meeting beats an isolated one.
2748
- * - A slot must leave each attendee a free gap of `lunchMinutes` inside
2749
- * their lunch window, if they had one. Set `lunchMinutes` to 0 to allow
2750
- * lunch meetings.
2751
- * - A slot must not make a run of back-to-back meetings longer than
2752
- * `maxBackToBackMinutes`. Gaps under 15 minutes count as back to back.
2753
- *
2754
- * Optional attendees who are busy or break these rules do not block a slot.
2755
- * Slots without such conflicts come first. Inside each group of equal
2756
- * conflicts and meeting days, options are spread across the days of
2757
- * `timeZone`. Results come best first. With `weekdays`, only those
2758
- * days of `timeZone` are searched.
2759
- *
2760
- * Busy intervals come from Google free/busy only, so
2761
- * Junior never sees event titles or details.
2737
+ * Find slots when every required attendee is free in their own working
2738
+ * hours. Days with meetings come first, so free days stay free (the requester
2739
+ * chose this over focus time). Then, per Clockwise's public docs: keep focus
2740
+ * time, add few meeting runs, keep lunch gaps, cap back-to-back runs. Optional
2741
+ * attendees never block. Free/busy only, so Junior sees no event details.
2762
2742
  */
2763
2743
  function findFreeSlots(input) {
2764
2744
  const durationMs = input.durationMinutes * 6e4;
@@ -2777,7 +2757,7 @@ function findFreeSlots(input) {
2777
2757
  return localParts(ms, format);
2778
2758
  };
2779
2759
  const runsByEmail = new Map(input.attendees.map((attendee) => [attendee.email, meetingRuns(attendee.busy)]));
2780
- /** The cost of the slot for one attendee, or undefined if they cannot take it. */
2760
+ /** One attendee's cost for the slot, or undefined if they cannot take it. */
2781
2761
  const assess = (attendee, slot) => {
2782
2762
  const start = partsIn(slot.startMs, attendee.timeZone);
2783
2763
  const end = partsIn(slot.endMs, attendee.timeZone);
@@ -4423,7 +4403,7 @@ const updateCalendarEventTool = definePluginTool({
4423
4403
  if (response.status !== 200) throw googleApiError("google.calendar.event.update", response);
4424
4404
  return {
4425
4405
  target: "updateCalendarEvent",
4426
- ...ownEventResult(ownEventSchema.parse(response.body), timeZone, ctx.accountEmail)
4406
+ ...ownEventResult(ownEventSchema.parse(response.body), timeZone, ctx.accountEmail, "changed")
4427
4407
  };
4428
4408
  }
4429
4409
  });
@@ -4820,6 +4800,7 @@ function googlePlugin() {
4820
4800
  },
4821
4801
  cli: { commands: [createGoogleCliCommand()] },
4822
4802
  userPages: [createGoogleSetupPage()],
4803
+ inboxSubjects: googleInboxSubjectKinds,
4823
4804
  objectLinks: [googleFileLinks, googleCalendarLinks],
4824
4805
  images: googleImages,
4825
4806
  hooks: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-google",
3
- "version": "0.317.0",
3
+ "version": "0.319.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,7 +22,7 @@
22
22
  "migrations"
23
23
  ],
24
24
  "dependencies": {
25
- "@sentry/junior-plugin-api": "0.317.0",
25
+ "@sentry/junior-plugin-api": "0.319.0",
26
26
  "commander": "^14.0.3",
27
27
  "drizzle-orm": "1.0.0-rc.6",
28
28
  "p-limit": "^7.3.3",