calendar event creation

This commit is contained in:
azykov@mail.ru
2026-07-10 21:00:10 +03:00
parent 6bd101cab4
commit d7cd47267a
2 changed files with 53 additions and 4 deletions
+51 -3
View File
@@ -1,5 +1,5 @@
import { ToolDef } from "../types";
import { CaldavServerConnection, CalendarEvent } from "../utils/caldavServerConnection";
import { CaldavServerConnection, CalendarEvent, RecurrenceFreqValues } from "../utils/caldavServerConnection";
import { config } from '../config';
import z from "zod";
@@ -30,7 +30,7 @@ export const caldavGetCalendarEventsForDateRangeTool: ToolDef = {
config: {
description: "Get calendar events for date range",
inputSchema: {
calendarUrl: z.string().describe('Calendar url obtained from caldav-list-calendars method'),
calendarUrl: z.string().describe('Target calendar url. Requires prior call to caldav-list-calendars to obtain'),
start: z.coerce.date().describe('Range start, date or datetime in ISO format'),
end: z.coerce.date().describe('Range end, date or datetime in ISO format'),
}
@@ -66,7 +66,7 @@ export const caldavGetCalendarEventsForTodayTool: ToolDef = {
config: {
description: "Get calendar events for today",
inputSchema: {
calendarUrl: z.string().describe('Calendar url obtained from caldav-list-calendars method'),
calendarUrl: z.string().describe('Target calendar url. Requires prior call to caldav-list-calendars to obtain'),
}
},
handler: async ({ calendarUrl }) => {
@@ -96,3 +96,51 @@ export const caldavGetAllCalendarsEventsForTodayTool: ToolDef = {
return JSON.stringify(events);
},
};
export const caldavGetCalendarEventByIdTool: ToolDef = {
title: "caldav-get-calendar-event-by-id",
config: {
description: "Lookup calendar event by id",
inputSchema: {
calendarUrl: z.string().describe('Target calendar url. Requires prior call to caldav-list-calendars to obtain'),
eventId: z.string().describe('Event id'),
}
},
handler: async ({ calendarUrl, eventId }) => {
const conn = await getCaldavConnection();
const event = await conn.getCalendarEventById(calendarUrl, eventId);
return event ? JSON.stringify(event) : `No event found with id "${eventId}"`;
},
};
export const caldavCreateCalendarEventTool: ToolDef = {
title: "caldav-create-calendar-event",
config: {
description: "Create calendar event. Returns the event created",
inputSchema: {
calendarUrl: z.string().describe('Target calendar url. Requires prior call to caldav-list-calendars to obtain'),
eventInput: z.object({
summary: z.string().describe('Event summary'),
description: z.string().optional().describe('Optional event description'),
location: z.string().optional().describe('Optional event location'),
start: z.coerce.date().describe('Event start date or date and time'),
end: z.coerce.date().describe('Event end date or date and time'),
allDay: z.coerce.boolean().describe('Is fullday event?'),
recurrence: z.object({
freq: z.enum(RecurrenceFreqValues).describe('Frequency'),
interval: z.number().optional().describe('Optional interval'),
count: z.number().optional().describe('Optional repetition count'),
until: z.coerce.date().optional().describe('Optional end date or date and time'),
byDay: z.array(z.string().describe("Day of week, e.g. MO, TU, WE, TH, FR, TU, SU")).optional(),
byMonthDay: z.array(z.number().describe("Day of month")).optional(),
byMonth: z.array(z.number().describe("Month number")).optional(),
}).optional().describe('Optional recurrence rule, if needed'),
}).describe('Event input'),
}
},
handler: async ({ calendarUrl, eventInput }) => {
const conn = await getCaldavConnection();
const event = await conn.createCalendarEvent(calendarUrl, eventInput);
return JSON.stringify(event);
},
};
+2 -1
View File
@@ -45,7 +45,8 @@ export interface CalendarInfo {
color?: string;
}
export type RecurrenceFreq = "DAILY" | "WEEKLY" | "MONTHLY" | "YEARLY";
export const RecurrenceFreqValues = ["DAILY", "WEEKLY", "MONTHLY", "YEARLY"] as const;
export type RecurrenceFreq = typeof RecurrenceFreqValues[number];
export interface RecurrenceRule {
freq: RecurrenceFreq;