feat(events): adding start and end times
This commit is contained in:
@ -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 {
|
||||
|
@ -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{}
|
||||
|
@ -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{}
|
||||
|
@ -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_(),
|
||||
|
Reference in New Issue
Block a user