From 13e82334ca4b68383da34bc7bf13b4c259b60208 Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 31 Mar 2025 17:32:55 +0000 Subject: [PATCH] feat(events): adding start and end times --- backend/agents/event_location_agent.go | 45 ++++++++++++++++++-------- backend/models/events.go | 4 +-- backend/models/locations.go | 4 +-- frontend/src/network/index.ts | 6 +++- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/backend/agents/event_location_agent.go b/backend/agents/event_location_agent.go index 8c139a8..dabe9cd 100644 --- a/backend/agents/event_location_agent.go +++ b/backend/agents/event_location_agent.go @@ -8,6 +8,7 @@ import ( "reflect" "screenmark/screenmark/.gen/haystack/haystack/model" "screenmark/screenmark/models" + "time" "github.com/google/uuid" ) @@ -29,6 +30,8 @@ Do not create an event if you don't see any dates, or a name indicating an event Events can have an associated location, if you think there is a location, then you must either use a location from listLocations or you must create it first. Wherever possible, find the location in the image. + +When possible return a start time as a ISO datetime string, as well as an end date time. ` // TODO: this should be read directly from a file on load. @@ -45,9 +48,6 @@ const TOOLS = ` "name": { "type": "string" }, - "coordinates": { - "type": "string" - }, "address": { "type": "string" } @@ -78,15 +78,20 @@ const TOOLS = ` "name": { "type": "string" }, - "datetime": { - "type": "string" + "startDateTime": { + "type": "string", + "description": "The start time as an ISO string" + }, + "endDateTime": { + "type": "string", + "description": "The end time as an ISO string" }, "locationId": { "type": "string", "description": "The ID of the location, available by listLocations" } }, - "required": ["name"] + "required": ["name", "startDateTime", "endDateTime"] } } }, @@ -126,9 +131,10 @@ type AttachImageLocationArguments struct { } type CreateEventArguments struct { - Name string `json:"name"` - Datetime string `json:"datetime"` - LocationId string `json:"locationId"` + Name string `json:"name"` + StartDateTime string `json:"startDateTime"` + EndDateTime string `json:"endDateTime"` + LocationId string `json:"locationId"` } func (agent EventLocationAgent) GetLocations(userId uuid.UUID, imageId uuid.UUID, imageName string, imageData []byte) error { @@ -286,9 +292,8 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models ctx := context.Background() location, err := agent.locationModel.Save(ctx, info.userId, model.Locations{ - Name: args.Name, - Address: args.Address, - Coordinates: args.Coordinates, + Name: args.Name, + Address: args.Address, }) if err != nil { @@ -312,8 +317,22 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models Fn: func(info ToolHandlerInfo, args CreateEventArguments, call ToolCall) (model.Events, error) { ctx := context.Background() + layout := "2006-01-02T15:04:05" + + startTime, err := time.Parse(layout, args.StartDateTime) + if err != nil { + return model.Events{}, err + } + + endTime, err := time.Parse(layout, args.EndDateTime) + if err != nil { + return model.Events{}, err + } + event, err := agent.eventModel.Save(ctx, info.userId, model.Events{ - Name: args.Name, + Name: args.Name, + StartDateTime: &startTime, + EndDateTime: &endTime, }) if err != nil { diff --git a/backend/models/events.go b/backend/models/events.go index a233d61..a4dc427 100644 --- a/backend/models/events.go +++ b/backend/models/events.go @@ -17,8 +17,8 @@ type EventModel struct { func (m EventModel) Save(ctx context.Context, userId uuid.UUID, event model.Events) (model.Events, error) { // TODO tx here insertEventStmt := Events. - INSERT(Events.Name, Events.Description). - VALUES(event.Name, event.Description). + INSERT(Events.Name, Events.Description, Events.StartDateTime, Events.EndDateTime). + VALUES(event.Name, event.Description, event.StartDateTime, event.EndDateTime). RETURNING(Events.AllColumns) insertedEvent := model.Events{} diff --git a/backend/models/locations.go b/backend/models/locations.go index c419740..7f874c8 100644 --- a/backend/models/locations.go +++ b/backend/models/locations.go @@ -31,8 +31,8 @@ func (m LocationModel) List(ctx context.Context, userId uuid.UUID) ([]model.Loca func (m LocationModel) Save(ctx context.Context, userId uuid.UUID, location model.Locations) (model.Locations, error) { insertLocationStmt := Locations. - INSERT(Locations.Name, Locations.Address, Locations.Coordinates, Locations.Description). - VALUES(location.Name, location.Address, location.Coordinates, location.Description). + INSERT(Locations.Name, Locations.Address, Locations.Description). + VALUES(location.Name, location.Address, location.Description). RETURNING(Locations.AllColumns) insertedLocation := model.Locations{} diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 043cfc6..e278ff1 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -10,6 +10,9 @@ import { uuid, literal, variant, + date, + isoDate, + isoDateTime, } from "valibot"; type BaseRequestParams = Partial<{ @@ -53,13 +56,14 @@ const locationValidator = object({ ID: pipe(string(), uuid()), Name: string(), Address: nullable(string()), - Coordinates: nullable(string()), Description: nullable(string()), }); const eventValidator = object({ ID: pipe(string(), uuid()), Name: string(), + StartDateTime: nullable(pipe(string())), + EndDateTime: nullable(pipe(string())), Description: nullable(string()), LocationID: nullable(pipe(string(), uuid())), Location: null_(),