-- | @\/v1\/chatkit@module OpenAI.V1.ChatKit ( -- * Main types SessionID(..) , ThreadID(..) , CreateChatKitSession(..) , _CreateChatKitSession , ChatSessionObject(..) , CancelChatSession(..) , ThreadObject(..) , ThreadItem(..) -- * Other types , Workflow(..) , ChatKitConfiguration(..) , ExpiresAfter(..) , RateLimits(..) , Tracing(..) , AutomaticThreadTitling(..) , FileUpload(..) , History(..) , Scope(..) , Attachment(..) , UserContent(..) , InferenceOptions(..) , ToolChoice(..) , AssistantContent(..) , Annotation(..) , FileSource(..) , URLSource(..) , Task(..) -- * Servant , API ) whereimport OpenAI.Preludeimport OpenAI.V1.DeletionStatus (DeletionStatus(..))import OpenAI.V1.ListOf (ListOf(..))import OpenAI.V1.Order (Order(..))-- | Session IDnewtype SessionID = SessionID{ text :: Text } deriving newtype (FromJSON, IsString, Show, ToHttpApiData, ToJSON)-- | Thread IDnewtype ThreadID = ThreadID{ text :: Text } deriving newtype (FromJSON, IsString, Show, ToHttpApiData, ToJSON)-- | Request body for @\/v1\/chatkit\/sessions@data CreateChatKitSession = CreateChatKitSession { user :: Text , workflow :: Workflow , chatkit_configuration :: Maybe ChatKitConfiguration , expires_after :: Maybe ExpiresAfter , rate_limits :: Maybe RateLimits } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Default `CreateChatKitSession`_CreateChatKitSession :: CreateChatKitSession_CreateChatKitSession = CreateChatKitSession { chatkit_configuration = Nothing , expires_after = Nothing , rate_limits = Nothing }-- | Workflow that powers the sessiondata Workflow = Workflow { id :: Text , state_variables :: Maybe (Map Text Value) , tracing :: Maybe Tracing , version :: Maybe Text } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Tracing overrides for the workflow invocationdata Tracing = Tracing { enabled :: Maybe Bool } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Overrides for ChatKit runtime configuration featuresdata ChatKitConfiguration = ChatKitConfiguration { automatic_thread_titling :: Maybe AutomaticThreadTitling , file_upload :: Maybe FileUpload , history :: Maybe History } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Configuration for automatic thread titlingdata AutomaticThreadTitling = AutomaticThreadTitling { enabled :: Maybe Bool } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Configuration for file upload enablement and limitsdata FileUpload = FileUpload { enabled :: Maybe Bool , max_file_size :: Maybe Natural , max_files :: Maybe Natural } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Configuration for chat history retentiondata History = History { enabled :: Maybe Bool , recent_threads :: Maybe Natural } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Override for session expiration timingdata ExpiresAfter = Created_At { seconds :: NominalDiffTime } deriving stock (Generic, Show)expiresAfterOptions :: OptionsexpiresAfterOptions = aesonOptions { sumEncoding = TaggedObject { tagFieldName = "expires_after", contentsFieldName = "" } , tagSingleConstructors = True }instance FromJSON ExpiresAfter where parseJSON = genericParseJSON expiresAfterOptionsinstance ToJSON ExpiresAfter where toJSON = genericToJSON expiresAfterOptions-- | Override for per-minute request limitsdata RateLimits = RateLimits { max_requests_per_1_minute :: Maybe Natural } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | A ChatKit sessiondata ChatSessionObject = ChatSessionObject { chatkit_configuration :: ChatKitConfiguration , client_secret :: Text , expires_at :: POSIXTime , id :: SessionID , max_requests_per_1_minute :: Natural , object :: Text , rate_limits :: RateLimits , status :: Text , user :: Text , workflow :: Workflow } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Response body for @\/v1\/chatkit\/sessions\/{session_id}\/cancel@data CancelChatSession = CancelChatSession { id :: SessionID , workflow :: Workflow , scope :: Scope , max_requests_per_1_minute :: Natural , ttl_seconds :: NominalDiffTime , status :: Text , cancelled_at :: POSIXTime } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Scopedata Scope = Scope { customer_id :: Text } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | A ChatKit threaddata ThreadObject = ThreadObject { created_at :: POSIXTime , id :: ThreadID , object :: Text , status :: Status , title :: Maybe Text , user :: Text } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Current status for the threaddata Status = Active deriving stock (Generic, Show)statusOptions :: OptionsstatusOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , tagSingleConstructors = True }instance FromJSON Status where parseJSON = genericParseJSON statusOptionsinstance ToJSON Status where toJSON = genericToJSON statusOptions-- | A thread itemdata ThreadItem = User_Message { attachments :: Vector Attachment , content :: Vector UserContent , created_at :: POSIXTime , id :: Text , inference_options :: InferenceOptions , object :: Text , thread_id :: Text } | Assistant_Message { assistant_content :: Vector AssistantContent , created_at :: POSIXTime , id :: Text , object :: Text , thread_id :: Text } | Widget_Message { created_at :: POSIXTime , id :: Text , object :: Text , thread_id :: Text , widget :: Text } | Client_Tool_Call { arguments :: Text , call_id :: Text , created_at :: POSIXTime , id :: Text , name :: Text , object :: Text , output :: Text , status :: Text , thread_id :: Text } | Task_Item { created_at :: POSIXTime , heading :: Text , id :: Text , object :: Text , summary :: Text , task_type , thread_id :: Text } | Task_Group { created_at :: POSIXTime , id :: Text , object :: Text , tasks :: Vector Task , thread_id :: Text } deriving stock (Generic, Show)threadItemOptions :: OptionsthreadItemOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , tagSingleConstructors = True , fieldLabelModifier = stripPrefix "assistant_" }instance FromJSON ThreadItem where parseJSON = genericParseJSON threadItemOptionsinstance ToJSON ThreadItem where toJSON = genericToJSON threadItemOptions-- | Attachment associated with the user messagedata Attachment = Attachment { id :: Text , mime_type :: Text , name :: Text , preview_url :: Text } deriving stock (Generic, Show)instance FromJSON Attachment where parseJSON = genericParseJSON aesonOptionsinstance ToJSON Attachment where toJSON = genericToJSON aesonOptions-- | Content element supplied by the userdata UserContent = Input_Text{ text :: Text } | Quoted_Text{ text :: Text } deriving stock (Generic, Show)userContentOptions :: OptionsuserContentOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , tagSingleConstructors = True }instance FromJSON UserContent where parseJSON = genericParseJSON userContentOptionsinstance ToJSON UserContent where toJSON = genericToJSON userContentOptions-- | Inference overrides applies to the messagedata InferenceOptions = InferenceOptions { model :: Text , tool_choice :: ToolChoice } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Preferred tool to invokedata ToolChoice = ToolChoice { id :: Text } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Assistant response segmentdata AssistantContent = Output_Text { annotations :: Vector Annotation , text :: Text } deriving stock (Generic, Show)assistantContentOptions :: OptionsassistantContentOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , tagSingleConstructors = True }instance FromJSON AssistantContent where parseJSON = genericParseJSON assistantContentOptionsinstance ToJSON AssistantContent where toJSON = genericToJSON assistantContentOptions-- | Annotationdata Annotation = File { source :: FileSource } | Url { url_source :: URLSource } deriving stock (Generic, Show)annotationOptions :: OptionsannotationOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , tagSingleConstructors = True , fieldLabelModifier = stripPrefix "url_" }instance FromJSON Annotation where parseJSON = genericParseJSON annotationOptionsinstance ToJSON Annotation where toJSON = genericToJSON annotationOptions-- | File attachmentdata FileSource = FileSource_File { filename :: Text } deriving stock (Generic, Show)fileSourceOptions :: OptionsfileSourceOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , constructorTagModifier = stripPrefix "FileSource_" , tagSingleConstructors = True }instance FromJSON FileSource where parseJSON = genericParseJSON fileSourceOptionsinstance ToJSON FileSource where toJSON = genericToJSON fileSourceOptions-- | URLdata URLSource = URLSource_Url { url :: Text } deriving stock (Generic, Show)urlSourceOptions :: OptionsurlSourceOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , constructorTagModifier = stripPrefix "URLSource_" , tagSingleConstructors = True }instance FromJSON URLSource where parseJSON = genericParseJSON urlSourceOptionsinstance ToJSON URLSource where toJSON = genericToJSON urlSourceOptions-- | Taskdata Task = Task { heading :: Text , summary :: Text } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON)-- | Servant APItype API = "chatkit" :> ( ( "sessions" :> ReqBody '[JSON] CreateChatKitSession :> Post '[JSON] ChatSessionObject ) :<|> ( "sessions" :> Capture "session_id" SessionID :> "cancel" :> Post '[JSON] CancelChatSession ) :<|> ( "threads" :> QueryParam "after" Text :> QueryParam "before" Text :> QueryParam "limit" Natural :> QueryParam "order" Order :> QueryParam "user" Text :> Get '[JSON] (ListOf ThreadObject) ) :<|> ( "threads" :> Capture "thread_id" ThreadID :> Get '[JSON] ThreadObject ) :<|> ( "threads" :> Capture "thread_id" ThreadID :> Delete '[JSON] DeletionStatus ) :<|> ( "threads" :> Capture "thread_id" ThreadID :> "items" :> QueryParam "after" Text :> QueryParam "before" Text :> QueryParam "limit" Natural :> QueryParam "order" Order :> Get '[JSON] (ListOf ThreadItem) ) )