calendar event creation
This commit is contained in:
+51
-3
@@ -1,5 +1,5 @@
|
|||||||
import { ToolDef } from "../types";
|
import { ToolDef } from "../types";
|
||||||
import { CaldavServerConnection, CalendarEvent } from "../utils/caldavServerConnection";
|
import { CaldavServerConnection, CalendarEvent, RecurrenceFreqValues } from "../utils/caldavServerConnection";
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ export const caldavGetCalendarEventsForDateRangeTool: ToolDef = {
|
|||||||
config: {
|
config: {
|
||||||
description: "Get calendar events for date range",
|
description: "Get calendar events for date range",
|
||||||
inputSchema: {
|
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'),
|
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'),
|
end: z.coerce.date().describe('Range end, date or datetime in ISO format'),
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ export const caldavGetCalendarEventsForTodayTool: ToolDef = {
|
|||||||
config: {
|
config: {
|
||||||
description: "Get calendar events for today",
|
description: "Get calendar events for today",
|
||||||
inputSchema: {
|
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 }) => {
|
handler: async ({ calendarUrl }) => {
|
||||||
@@ -96,3 +96,51 @@ export const caldavGetAllCalendarsEventsForTodayTool: ToolDef = {
|
|||||||
return JSON.stringify(events);
|
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);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ export interface CalendarInfo {
|
|||||||
color?: string;
|
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 {
|
export interface RecurrenceRule {
|
||||||
freq: RecurrenceFreq;
|
freq: RecurrenceFreq;
|
||||||
|
|||||||
Reference in New Issue
Block a user