Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions modules/prompts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const get_event_information_function = {
"name": "get_event_information",
"description": "Get the event information from the input text.",
"description": "Get the event information from the input text, including recurring event details.",
"parameters": {
"type": "object",
"properties": {
Expand All @@ -23,6 +23,42 @@ const get_event_information_function = {
"description": {
"type": "string",
"description": "The description of the event. Maximum number of characters is 800."
},
"recurrence": {
"type": "object",
"description": "Information about the recurring nature of the event.",
"properties": {
"frequency": {
"type": "string",
"description": "The frequency of the event (e.g., 'weekly', 'daily', 'monthly')."
},
"interval": {
"type": "integer",
"description": "The interval of the recurrence (e.g., 1 for every week, 2 for every other week)."
},
"days": {
"type": "array",
"items": {
"type": "string"
},
"description": "The days of the week the event occurs on (e.g., ['TU'] for Tuesday, ['MO', 'WE', 'FR'] for Monday, Wednesday, Friday)."
},
"start_date": {
"type": "string",
"description": "The start date of the recurrence in YYYYMMDD format."
},
"end_date": {
"type": "string",
"description": "The end date of the recurrence in YYYYMMDD format."
},
"exceptions": {
"type": "array",
"items": {
"type": "string"
},
"description": "Dates to be excluded from the recurrence in YYYYMMDD format."
}
}
}
},
"required": ["title", "start_date", "location", "description"]
Expand Down Expand Up @@ -85,4 +121,4 @@ export function autoSelect(selectionText) {
}

return params;
}
}
32 changes: 29 additions & 3 deletions service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {
const { function_used, event } = parsedResponse;

if (function_used === "get_event_information") {
console.log("get_event_information", event)
// Format the dates
const startDate = event.start_date;
// For untimed events the end date is exclusive, so the end date should be the next day.
Expand All @@ -103,8 +104,33 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {
const location = encodeURIComponent(event.location);
const description = encodeURIComponent(event.description);

// Construct the Google Calendar URL and open a new tab
const calendarURL = `https://www.google.com/calendar/render?action=TEMPLATE&text=${title}&dates=${startDate}/${endDate}&details=${description}&location=${location}`;
// Construct the Google Calendar URL with recurring event information
let calendarURL = `https://www.google.com/calendar/render?action=TEMPLATE&text=${title}&dates=${startDate}/${endDate}&details=${description}&location=${location}`;

// Add recurrence information if available
if (event.recurrence) {
const recur = event.recurrence;
let recurrence = [];

if (recur.frequency) recurrence.push(`FREQ=${recur.frequency.toUpperCase()}`);
if (recur.interval) recurrence.push(`INTERVAL=${recur.interval}`);
if (recur.days && recur.days.length > 0) recurrence.push(`BYDAY=${recur.days.join(',')}`);
if (recur.end_date) recurrence.push(`UNTIL=${recur.end_date.replace(/[-]/g, '')}`);

if (recurrence.length > 0) {
const rrule = `RRULE:${recurrence.join(';')}`;
calendarURL += `&recur=${encodeURIComponent(rrule)}`;
}

// Add exceptions if any
if (recur.exceptions && recur.exceptions.length > 0) {
const exdates = recur.exceptions.map(date => date.replace(/[-]/g, '')).join(',');
calendarURL += `&recurrence=EXDATE:${exdates}`;
}
}

console.log("Calendar URL:", calendarURL);

chrome.tabs.create({
url: calendarURL
});
Expand Down Expand Up @@ -152,4 +178,4 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {
}
});
}
});
});