feat(events): adding start and end times

This commit is contained in:
2025-03-31 17:32:55 +00:00
parent 59737ca9ac
commit 13e82334ca
4 changed files with 41 additions and 18 deletions

View File

@ -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"]
}
}
},
@ -127,7 +132,8 @@ type AttachImageLocationArguments struct {
type CreateEventArguments struct {
Name string `json:"name"`
Datetime string `json:"datetime"`
StartDateTime string `json:"startDateTime"`
EndDateTime string `json:"endDateTime"`
LocationId string `json:"locationId"`
}
@ -288,7 +294,6 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models
location, err := agent.locationModel.Save(ctx, info.userId, model.Locations{
Name: args.Name,
Address: args.Address,
Coordinates: args.Coordinates,
})
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,
StartDateTime: &startTime,
EndDateTime: &endTime,
})
if err != nil {

View File

@ -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{}

View File

@ -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{}

View File

@ -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_(),