diff options
Diffstat (limited to 'Omni')
| -rw-r--r-- | Omni/Agent/Tools/Calendar.hs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/Omni/Agent/Tools/Calendar.hs b/Omni/Agent/Tools/Calendar.hs index 900785d..805916f 100644 --- a/Omni/Agent/Tools/Calendar.hs +++ b/Omni/Agent/Tools/Calendar.hs @@ -62,12 +62,15 @@ test = defaultCalendars :: [String] defaultCalendars = ["BenSimaShared", "Kate"] -listEvents :: Text -> IO (Either Text Text) -listEvents range = do +listEvents :: Text -> Maybe Text -> IO (Either Text Text) +listEvents range maybeCalendar = do let rangeArg = if Text.null range then "today 7d" else Text.unpack range - calArgs = concatMap (\c -> ["-a", c]) defaultCalendars + calArgs = case maybeCalendar of + Just cal -> ["-a", Text.unpack cal] + Nothing -> concatMap (\c -> ["-a", c]) defaultCalendars + formatArg = ["-f", "[{calendar}] {title} | {start-time} - {end-time}"] result <- - try <| readProcessWithExitCode "khal" (["list"] <> calArgs <> [rangeArg, "-o"]) "" + try <| readProcessWithExitCode "khal" (["list"] <> calArgs <> formatArg <> [rangeArg, "-o"]) "" case result of Left (e :: SomeException) -> pure (Left ("khal error: " <> tshow e)) @@ -130,7 +133,8 @@ calendarListTool = { Engine.toolName = "calendar_list", Engine.toolDescription = "List upcoming calendar events. Use to check what's scheduled. " - <> "Range can be like 'today', 'tomorrow', 'today 7d', 'next week', etc.", + <> "Range can be like 'today', 'tomorrow', 'today 7d', 'next week', etc. " + <> "Available calendars: BenSimaShared, Kate.", Engine.toolJsonSchema = Aeson.object [ "type" .= ("object" :: Text), @@ -140,6 +144,11 @@ calendarListTool = .= Aeson.object [ "type" .= ("string" :: Text), "description" .= ("Time range like 'today 7d', 'tomorrow', 'next week' (default: today 7d)" :: Text) + ], + "calendar" + .= Aeson.object + [ "type" .= ("string" :: Text), + "description" .= ("Filter to specific calendar: 'BenSimaShared' or 'Kate' (default: both)" :: Text) ] ], "required" .= ([] :: [Text]) @@ -152,7 +161,7 @@ executeCalendarList v = case Aeson.fromJSON v of Aeson.Error e -> pure (Aeson.object ["error" .= Text.pack e]) Aeson.Success (args :: CalendarListArgs) -> do - result <- listEvents (clRange args) + result <- listEvents (clRange args) (clCalendar args) case result of Left err -> pure (Aeson.object ["error" .= err]) @@ -164,15 +173,17 @@ executeCalendarList v = ] ) -newtype CalendarListArgs = CalendarListArgs - { clRange :: Text +data CalendarListArgs = CalendarListArgs + { clRange :: Text, + clCalendar :: Maybe Text } deriving (Generic) instance Aeson.FromJSON CalendarListArgs where parseJSON = Aeson.withObject "CalendarListArgs" <| \v -> - CalendarListArgs </ (v .:? "range" .!= "today 7d") + (CalendarListArgs </ (v .:? "range" .!= "today 7d")) + <*> (v .:? "calendar") calendarAddTool :: Engine.Tool calendarAddTool = |
