Feature: AI-Powered Event Creation
Relevant source files
The following files were used as context for generating this wiki page:The AI-Powered Event Creation feature allows users to create calendar events using natural language. By typing a descriptive prompt into the event title field and pressing ⌘↵, the system uses an AI model to parse the text and automatically populate the rest of the event form, including dates, times, and description. This streamlines the event creation process, reducing the need for manual field entry.
This feature is primarily implemented through a specialized title input field, an AI service handler, and a Zod schema that defines the structure of the AI's output. It leverages the Vercel AI SDK and OpenAI's gpt-4.1-mini model to interpret user input and generate structured event data.
Core Architecture
The feature is triggered from the TitleField component. When a user enters a prompt and uses the ⌘↵ hotkey, the generateEventFormData function is invoked. This function sends the user's input along with a detailed system prompt to the OpenAI API. The AI model then returns a structured JSON object, which is used to populate the event creation form.
Sources: apps/web/src/components/event-form/ai-input/title-field.tsx, apps/web/src/components/event-form/ai-input/support/ai-input.ts
Data Flow
The following sequence diagram illustrates the process from user input to form population.
This diagram shows the flow of information, starting with the user's natural language input and ending with the event form being updated with the structured data returned by the AI service.
Sources: apps/web/src/components/event-form/ai-input/support/ai-input.ts:10-37, apps/web/src/components/event-form/ai-input/support/ai-input.ts:40-47
UI Components
TitleField.tsx
This React component serves as the primary user interface for the AI event creation feature. It's an enhanced input field that can switch between a standard <Input> and an expanding <Textarea>.
- AI-Enabled State: A prop
aiEnabledcontrols the visibility of AI-related hints. - Hotkey Hint: When AI is enabled, a hint displaying
⌘↵and a sparkles icon is shown, instructing the user how to trigger the AI parsing. This is handled by theAiInputHintsub-component. - Loading State: An
isLoadingprop displays a visual loading indicator (BorderTrail) while the AI is processing the request. - Expanding Input: It uses the
useExpandingInputcustom hook to manage focus and switch between a single-line input and a multi-line textarea.
Sources: apps/web/src/components/event-form/ai-input/title-field.tsx:16-25, 41-48
aiInputPredicate
This function determines whether the AI submission hotkey has been pressed. It checks for the Enter key in combination with the Meta key (⌘) specifically when the event target is the title input field.
// apps/web/src/components/event-form/ai-input/support/ai-input.ts:39-47
export const aiInputPredicate: KeyboardEventPredicate = (e) => {
if (!(e.target instanceof HTMLElement)) return false;
if (e.target.id === "title") {
const key = e.key ? e.key.toLowerCase() : "";
return key === "enter" && e.metaKey;
}
return false;
};
Sources: apps/web/src/components/event-form/ai-input/support/ai-input.ts:39-47
AI Data Generation
generateEventFormData Function
This asynchronous function is the core of the AI logic. It takes the user's text input and an API key, constructs a request, and calls the OpenAI API to get structured event data.
Key steps:
- It initializes an OpenAI client using the provided
apiKey. - It captures the
CURRENT TIMEto provide temporal context to the AI. - It calls the
generateObjectfunction from the Vercel AI SDK, passing the AI model (gpt-4.1-mini), the targetaiInputSchema, a system prompt, and the user's input. - The
generateObjectfunction ensures that the AI's response conforms to the provided Zod schema.
Sources: apps/web/src/components/event-form/ai-input/support/ai-input.ts:10-37
System Prompt Analysis
A detailed system prompt guides the AI model to ensure accurate and consistent output. The key instructions given to the model are:
- Generate an object matching the
aiInputSchema. - Leave fields blank for unsupported features (e.g., yearly repeats).
- The event title must be concise.
- The description should not repeat the title or date/time info.
- Default to today's date if none is specified.
- Non-all-day events must have both start and end times.
- For repeating events, if the end date is not specified, it should be set to one year after the start date.
- The current time is provided for relative date/time calculations (e.g., "tomorrow").
Sources: apps/web/src/components/event-form/ai-input/support/ai-input.ts:20-35
Data Schemas
The feature relies on Zod schemas to define the shape of the data, both for the AI output and the final event form.
aiInputSchema
This schema defines the expected structure of the object returned by the OpenAI generateObject call. It is a subset of the main baseEventFormSchema, omitting fields that the AI is not expected to generate, such as accountId and selectedParticipants.
The relationship between the schemas is shown below.
This diagram illustrates that aiInputSchema is derived from baseEventFormSchema by omitting certain fields.
Sources: apps/web/src/lib/schemas/event-form.ts:43-46
Schema Definition
The table below details the fields in aiInputSchema.
| Field | Type | Description | Constraints |
|---|---|---|---|
title | string | The event title. | Required, max 60 chars. |
description | string | The event description. | Optional, max 400 chars. |
location | string | Place name or address. | Optional, max 60 chars. |
startTime | string | Event start time. | Nullable, must be a valid time string. |
endTime | string | Event end time. | Nullable, must be a valid time string. |
startDate | string | ISO 8601 date string. | Transformed to PlainDate. |
endDate | string | ISO 8601 date string. | Transformed to PlainDate. |
timezone | string | IANA timezone identifier. | Required. |
isAllDay | boolean | Indicates if it's an all-day event. | Required. |
repeats | boolean | Indicates if the event repeats. | Required. |
repeatType | enum | Type of repetition. | Optional, daily, weekly, or monthly. |
Sources: apps/web/src/lib/schemas/event-form.ts:7-41
Related Event Creation Methods
The Analog application includes other methods for simplified or natural language event creation.
@-Mention Event Creation
The CreateEventInput component provides an alternative way to create events using a Tiptap-based text editor. Users can type a title and use @ mentions to trigger suggestions for dates, times, and durations. For example, a user could type Sales meeting @22:00 @tomorrow.
This method does not use an external AI service but relies on client-side logic and suggestions to parse the input.
Sources: apps/web/src/components/create-event-input.tsx:19-30, 71-79
Google Calendar quickAdd
The application's Google Calendar API client includes a quickAdd method. This function takes a simple text string and uses Google's own natural language processing to create an event. This is a provider-specific feature that achieves a similar goal to the in-app AI implementation.
// packages/google-calendar/src/resources/calendars/events.ts:311-337
/**
* Creates an event based on a simple text string.
*/
quickAdd(
calendarID: string,
params: EventQuickAddParams,
options?: RequestOptions,
): APIPromise<Event> {
const {
text,
// ... other params
} = params;
return this._client.post(path`/calendars/${calendarID}/events/quickAdd`, {
query: {
text,
// ... other params
},
...options,
});
}
Sources: packages/google-calendar/src/resources/calendars/events.ts:311-314
Conclusion
The AI-Powered Event Creation feature is a sophisticated system that enhances user experience by translating natural language into structured calendar data. It integrates a dedicated UI component (TitleField), a powerful AI service handler (generateEventFormData), and a well-defined data schema (aiInputSchema). By leveraging an external AI model, it offloads the complexity of natural language understanding, allowing for a fast and intuitive event creation workflow within the Analog application.