A-gent-0.11.0.7: src/Agent/Utils/Code.hs
{-# OPTIONS_GHC -Wall -Werror #-}
{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE LambdaCase #-}
--------------------------------------------------------------------------------
-- |
-- Copyright : (c) 2026 SPISE MISU ApS
-- License : SSPL-1.0 OR AGPL-3.0-only
-- Maintainer : SPISE MISU <mail+hackage@spisemisu.com>
-- Stability : experimental
--------------------------------------------------------------------------------
module Agent.Utils.Code
( -- * Files
files
, file
)
where
--------------------------------------------------------------------------------
import Data.Either ( fromRight )
import qualified Agent.IO.Effects as EFF
import qualified Agent.Utils.Common as COM
--------------------------------------------------------------------------------
files
:: EFF.LlmCodeRead rio
=> Maybe String
-> rio [ String ]
files mfilter =
filesHelper mfilter True
file
:: EFF.LlmCodeRead rio
=> Maybe String
-> Int
-> Bool
-> rio (Either String [String])
file mfilter index nums =
filesHelper mfilter False >>= \ fs ->
if length fs > index && index >= 0 then
( \case
Right f -> Right $ COM.file nums f
Left e -> Left e
)
<$> EFF.llmCodeGet (fs !! index)
else
pure $ Left msg
where
msg = "Index (" ++ show index ++ ") is out of bounds. See /last"
--------------------------------------------------------------------------------
-- HELPERS (private)
filesHelper
:: EFF.LlmCodeRead rio
=> Maybe String
-> Bool
-> rio [ String ]
filesHelper mfilter nums =
(COM.files nums) . fromRight [] <$> EFF.llmCodeSeq mfilter