Skip to content

Commit edcfadd

Browse files
committed
fix(search-mcp): continue a person-filtered calendar search on the primary calendar
1 parent 69cbb15 commit edcfadd

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎apps/sim/lib/sim-search/live/google.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ export async function searchCalendar(
593593
input: NativeSearchInput
594594
): Promise<NativePage> {
595595
// Native project names a calendar ID. Without one, query the user's calendar list.
596+
/** Events you organize or attend are on your primary calendar, so `me` searches only it. */
597+
const onlyPrimary = input.involving === 'me' && !input.native?.project
598+
/** One calendar is searched, so its page token continues the search. */
599+
const oneCalendar = Boolean(input.native?.project) || onlyPrimary
596600
const calendars = input.native?.project
597601
? { items: [{ id: input.native.project }] }
598602
: object(
@@ -607,8 +611,7 @@ export async function searchCalendar(
607611
...(row.primary === true ? ['primary'] : []),
608612
])
609613
)
610-
// Events you organize or attend are on your primary calendar.
611-
.filter((row) => input.involving !== 'me' || input.native?.project || row.primary === true)
614+
.filter((row) => !onlyPrimary || row.primary === true)
612615
.slice(0, 20)
613616
.sort((left, right) => Number(right.primary === true) - Number(left.primary === true))
614617
const chronological = hasDateBounds(input.filters) || Boolean(dateSortDirection(input.filters))
@@ -653,9 +656,7 @@ export async function searchCalendar(
653656
...(chronological ? { singleEvents: 'true', orderBy: 'startTime' } : {}),
654657
maxResults: String(input.limit),
655658
showDeleted: 'false',
656-
...(input.native?.cursor && input.native.project
657-
? { pageToken: input.native.cursor }
658-
: {}),
659+
...(input.native?.cursor && oneCalendar ? { pageToken: input.native.cursor } : {}),
659660
},
660661
})
661662
)
@@ -682,7 +683,7 @@ export async function searchCalendar(
682683
const documents = chronological
683684
? perCalendar.flat().sort((left, right) => eventStartTime(left) - eventStartTime(right))
684685
: interleaveByRank(perCalendar)
685-
const single = input.native?.project ? searched[0] : undefined
686+
const single = oneCalendar ? searched[0] : undefined
686687
return {
687688
documents,
688689
partial: Boolean(calendars.nextPageToken) || searched.length < rows.length,

0 commit comments

Comments
 (0)