types.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package client
  2. import (
  3. "encoding/json"
  4. "time"
  5. )
  6. // FlexTime is a custom time type that can parse both RFC3339 and ISO8601 without timezone
  7. type FlexTime struct {
  8. time.Time
  9. }
  10. // UnmarshalJSON implements custom JSON unmarshaling for flexible time parsing
  11. func (ft *FlexTime) UnmarshalJSON(b []byte) error {
  12. s := string(b)
  13. // Remove quotes
  14. if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
  15. s = s[1 : len(s)-1]
  16. }
  17. // Try parsing with timezone first (RFC3339)
  18. t, err := time.Parse(time.RFC3339, s)
  19. if err == nil {
  20. ft.Time = t
  21. return nil
  22. }
  23. // Try parsing without timezone
  24. t, err = time.Parse("2006-01-02T15:04:05.999999", s)
  25. if err == nil {
  26. ft.Time = t.UTC()
  27. return nil
  28. }
  29. // Try parsing without microseconds
  30. t, err = time.Parse("2006-01-02T15:04:05", s)
  31. if err == nil {
  32. ft.Time = t.UTC()
  33. return nil
  34. }
  35. return err
  36. }
  37. // MarshalJSON implements custom JSON marshaling
  38. func (ft FlexTime) MarshalJSON() ([]byte, error) {
  39. return json.Marshal(ft.Time)
  40. }
  41. // RecurringSchedule represents a recurring schedule
  42. type RecurringSchedule struct {
  43. ID string `json:"id"`
  44. AgentID string `json:"agent_id"`
  45. Message string `json:"message"`
  46. Role string `json:"role"`
  47. CronString string `json:"cron"`
  48. LastRun *string `json:"last_run,omitempty"`
  49. CreatedAt FlexTime `json:"created_at"`
  50. }
  51. // RecurringScheduleCreate represents the payload to create a recurring schedule
  52. type RecurringScheduleCreate struct {
  53. AgentID string `json:"agent_id"`
  54. Message string `json:"message"`
  55. Role string `json:"role"`
  56. CronString string `json:"cron"`
  57. }
  58. // OneTimeSchedule represents a one-time schedule
  59. type OneTimeSchedule struct {
  60. ID string `json:"id"`
  61. AgentID string `json:"agent_id"`
  62. Message string `json:"message"`
  63. Role string `json:"role"`
  64. ExecuteAt string `json:"execute_at"`
  65. CreatedAt FlexTime `json:"created_at"`
  66. }
  67. // OneTimeScheduleCreate represents the payload to create a one-time schedule
  68. type OneTimeScheduleCreate struct {
  69. AgentID string `json:"agent_id"`
  70. Message string `json:"message"`
  71. Role string `json:"role"`
  72. ExecuteAt string `json:"execute_at"`
  73. }
  74. // ExecutionResult represents the result of a schedule execution
  75. type ExecutionResult struct {
  76. ScheduleID string `json:"schedule_id"`
  77. ScheduleType string `json:"schedule_type"`
  78. RunID string `json:"run_id"`
  79. AgentID string `json:"agent_id"`
  80. Message string `json:"message"`
  81. ExecutedAt string `json:"executed_at"`
  82. }