Enhance CalendarTool: include additional event details in output
- Request additional fields for events, including attendees and attachments - Extract and display event end time, location, attendees, attachments, and description in the event listing - Truncate long descriptions for better readability
This commit is contained in:
parent
5d80eab8bd
commit
2e71c21094
@ -714,6 +714,8 @@ class CalendarTool(Tool):
|
|||||||
maxResults=max_results,
|
maxResults=max_results,
|
||||||
singleEvents=True,
|
singleEvents=True,
|
||||||
orderBy="startTime",
|
orderBy="startTime",
|
||||||
|
# Request additional fields to get attendees and attachments
|
||||||
|
fields="items(id,summary,start,end,description,location,attendees(email,responseStatus),attachments(fileUrl,title))",
|
||||||
)
|
)
|
||||||
.execute()
|
.execute()
|
||||||
)
|
)
|
||||||
@ -727,10 +729,17 @@ class CalendarTool(Tool):
|
|||||||
event_ids = []
|
event_ids = []
|
||||||
for idx, event in enumerate(events, 1):
|
for idx, event in enumerate(events, 1):
|
||||||
start = event["start"].get("dateTime", event["start"].get("date"))
|
start = event["start"].get("dateTime", event["start"].get("date"))
|
||||||
|
end = event["end"].get("dateTime", event["end"].get("date"))
|
||||||
title = event.get("summary", "No title")
|
title = event.get("summary", "No title")
|
||||||
event_id = event.get("id", "")
|
event_id = event.get("id", "")
|
||||||
event_ids.append(event_id)
|
event_ids.append(event_id)
|
||||||
|
|
||||||
|
# Extract additional information
|
||||||
|
description = event.get("description", "")
|
||||||
|
location = event.get("location", "")
|
||||||
|
attendees = event.get("attendees", [])
|
||||||
|
attachments = event.get("attachments", [])
|
||||||
|
|
||||||
# Add position indicator - "last" means the one with the latest time (usually the last in list)
|
# Add position indicator - "last" means the one with the latest time (usually the last in list)
|
||||||
position_note = ""
|
position_note = ""
|
||||||
if idx == len(events):
|
if idx == len(events):
|
||||||
@ -739,7 +748,31 @@ class CalendarTool(Tool):
|
|||||||
position_note = " (FIRST - earliest time)"
|
position_note = " (FIRST - earliest time)"
|
||||||
|
|
||||||
# Format: include numbered list with position indicators
|
# Format: include numbered list with position indicators
|
||||||
result.append(f"{idx}. {title} ({start}) [ID: {event_id}]{position_note}")
|
result.append(f"{idx}. {title} ({start} - {end}) [ID: {event_id}]{position_note}")
|
||||||
|
|
||||||
|
# Add location if present
|
||||||
|
if location:
|
||||||
|
result.append(f" Location: {location}")
|
||||||
|
|
||||||
|
# Add attendees if present
|
||||||
|
if attendees:
|
||||||
|
attendee_emails = [att.get("email", "") for att in attendees if att.get("email")]
|
||||||
|
if attendee_emails:
|
||||||
|
result.append(f" Attendees: {', '.join(attendee_emails)}")
|
||||||
|
|
||||||
|
# Add attachments if present
|
||||||
|
if attachments:
|
||||||
|
attachment_info = []
|
||||||
|
for att in attachments:
|
||||||
|
file_name = att.get("fileUrl", "").split("/")[-1] if att.get("fileUrl") else att.get("title", "Unknown file")
|
||||||
|
attachment_info.append(file_name)
|
||||||
|
if attachment_info:
|
||||||
|
result.append(f" Attachments: {', '.join(attachment_info)}")
|
||||||
|
|
||||||
|
# Add description if present (truncate if too long)
|
||||||
|
if description:
|
||||||
|
desc_preview = description[:100] + "..." if len(description) > 100 else description
|
||||||
|
result.append(f" Description: {desc_preview}")
|
||||||
|
|
||||||
# Also include a summary line with all IDs for easy extraction
|
# Also include a summary line with all IDs for easy extraction
|
||||||
result.append(f"\nEvent IDs: {', '.join(event_ids)}")
|
result.append(f"\nEvent IDs: {', '.join(event_ids)}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user