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" "reflect"
"screenmark/screenmark/.gen/haystack/haystack/model" "screenmark/screenmark/.gen/haystack/haystack/model"
"screenmark/screenmark/models" "screenmark/screenmark/models"
"time"
"github.com/google/uuid" "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. 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. 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. // TODO: this should be read directly from a file on load.
@ -45,9 +48,6 @@ const TOOLS = `
"name": { "name": {
"type": "string" "type": "string"
}, },
"coordinates": {
"type": "string"
},
"address": { "address": {
"type": "string" "type": "string"
} }
@ -78,15 +78,20 @@ const TOOLS = `
"name": { "name": {
"type": "string" "type": "string"
}, },
"datetime": { "startDateTime": {
"type": "string" "type": "string",
"description": "The start time as an ISO string"
},
"endDateTime": {
"type": "string",
"description": "The end time as an ISO string"
}, },
"locationId": { "locationId": {
"type": "string", "type": "string",
"description": "The ID of the location, available by listLocations" "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 { type CreateEventArguments struct {
Name string `json:"name"` Name string `json:"name"`
Datetime string `json:"datetime"` StartDateTime string `json:"startDateTime"`
LocationId string `json:"locationId"` EndDateTime string `json:"endDateTime"`
LocationId string `json:"locationId"`
} }
func (agent EventLocationAgent) GetLocations(userId uuid.UUID, imageId uuid.UUID, imageName string, imageData []byte) error { 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() ctx := context.Background()
location, err := agent.locationModel.Save(ctx, info.userId, model.Locations{ location, err := agent.locationModel.Save(ctx, info.userId, model.Locations{
Name: args.Name, Name: args.Name,
Address: args.Address, Address: args.Address,
Coordinates: args.Coordinates,
}) })
if err != nil { 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) { Fn: func(info ToolHandlerInfo, args CreateEventArguments, call ToolCall) (model.Events, error) {
ctx := context.Background() 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{ event, err := agent.eventModel.Save(ctx, info.userId, model.Events{
Name: args.Name, Name: args.Name,
StartDateTime: &startTime,
EndDateTime: &endTime,
}) })
if err != nil { 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) { func (m EventModel) Save(ctx context.Context, userId uuid.UUID, event model.Events) (model.Events, error) {
// TODO tx here // TODO tx here
insertEventStmt := Events. insertEventStmt := Events.
INSERT(Events.Name, Events.Description). INSERT(Events.Name, Events.Description, Events.StartDateTime, Events.EndDateTime).
VALUES(event.Name, event.Description). VALUES(event.Name, event.Description, event.StartDateTime, event.EndDateTime).
RETURNING(Events.AllColumns) RETURNING(Events.AllColumns)
insertedEvent := model.Events{} 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) { func (m LocationModel) Save(ctx context.Context, userId uuid.UUID, location model.Locations) (model.Locations, error) {
insertLocationStmt := Locations. insertLocationStmt := Locations.
INSERT(Locations.Name, Locations.Address, Locations.Coordinates, Locations.Description). INSERT(Locations.Name, Locations.Address, Locations.Description).
VALUES(location.Name, location.Address, location.Coordinates, location.Description). VALUES(location.Name, location.Address, location.Description).
RETURNING(Locations.AllColumns) RETURNING(Locations.AllColumns)
insertedLocation := model.Locations{} insertedLocation := model.Locations{}

View File

@ -10,6 +10,9 @@ import {
uuid, uuid,
literal, literal,
variant, variant,
date,
isoDate,
isoDateTime,
} from "valibot"; } from "valibot";
type BaseRequestParams = Partial<{ type BaseRequestParams = Partial<{
@ -53,13 +56,14 @@ const locationValidator = object({
ID: pipe(string(), uuid()), ID: pipe(string(), uuid()),
Name: string(), Name: string(),
Address: nullable(string()), Address: nullable(string()),
Coordinates: nullable(string()),
Description: nullable(string()), Description: nullable(string()),
}); });
const eventValidator = object({ const eventValidator = object({
ID: pipe(string(), uuid()), ID: pipe(string(), uuid()),
Name: string(), Name: string(),
StartDateTime: nullable(pipe(string())),
EndDateTime: nullable(pipe(string())),
Description: nullable(string()), Description: nullable(string()),
LocationID: nullable(pipe(string(), uuid())), LocationID: nullable(pipe(string(), uuid())),
Location: null_(), Location: null_(),