Skip to content

Commit

Permalink
Add chatbot helper
Browse files Browse the repository at this point in the history
  • Loading branch information
janslifka committed Sep 19, 2024
1 parent 3b48fa4 commit 8d73902
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 14 deletions.
18 changes: 14 additions & 4 deletions engine-shared/elm/Shared/Auth/Session.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Shared.Auth.Session exposing
, expiresSoon
, init
, setFullscreen
, setRightPanelCollapsed
, setSidebarCollapsed
, setToken
)
Expand All @@ -22,19 +23,21 @@ import Time
type alias Session =
{ token : Token
, sidebarCollapsed : Bool
, rightPanelCollapsed : Bool
, fullscreen : Bool
, apiUrl : String
, v8 : Bool
, v9 : Bool
}


init : String -> Session
init apiUrl =
{ token = Token.empty
, sidebarCollapsed = False
, rightPanelCollapsed = True
, fullscreen = False
, apiUrl = apiUrl
, v8 = True
, v9 = True
}


Expand All @@ -48,6 +51,11 @@ setSidebarCollapsed session collapsed =
{ session | sidebarCollapsed = collapsed }


setRightPanelCollapsed : Session -> Bool -> Session
setRightPanelCollapsed session collapsed =
{ session | rightPanelCollapsed = collapsed }


setFullscreen : Session -> Bool -> Session
setFullscreen session fullscreen =
{ session | fullscreen = fullscreen }
Expand All @@ -58,19 +66,21 @@ decoder =
D.succeed Session
|> D.required "token" Token.decoder
|> D.optional "sidebarCollapsed" D.bool False
|> D.optional "rightPanelCollapsed" D.bool True
|> D.optional "fullscreen" D.bool False
|> D.required "apiUrl" D.string
|> D.required "v8" D.bool
|> D.required "v9" D.bool


encode : Session -> E.Value
encode session =
E.object
[ ( "token", Token.encode session.token )
, ( "sidebarCollapsed", E.bool session.sidebarCollapsed )
, ( "rightPanelCollapsed", E.bool session.rightPanelCollapsed )
, ( "fullscreen", E.bool session.fullscreen )
, ( "apiUrl", E.string session.apiUrl )
, ( "v8", E.bool session.v8 )
, ( "v9", E.bool session.v9 )
]


Expand Down
12 changes: 11 additions & 1 deletion engine-shared/elm/Shared/Markdown.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Shared.Markdown exposing (toHtml, toString)
module Shared.Markdown exposing
( sanitizeHtml
, toHtml
, toString
)

import Html exposing (Html, text)
import Html.Attributes as Attr
Expand All @@ -8,6 +12,12 @@ import Markdown.Parser as Markdown
import Markdown.Renderer


sanitizeHtml : String -> String
sanitizeHtml html =
html
|> String.replace "<" "&lt;"


toHtml : List (Html.Attribute msg) -> String -> Html msg
toHtml attrs markdownInput =
let
Expand Down
12 changes: 11 additions & 1 deletion engine-wizard/elm/Wizard.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module Wizard exposing (main)
import Browser
import Browser.Navigation exposing (Key)
import Json.Decode exposing (Value)
import Shared.Utils exposing (dispatch)
import Shared.Data.BootstrapConfig.Admin as Admin
import Shared.Utils as Taks exposing (dispatch)
import Shared.Utils.Theme as Theme
import Url exposing (Url)
import Wizard.Common.AppState as AppState
import Wizard.Common.Components.AIAssistant as AIAssistant
import Wizard.Common.Time as Time
import Wizard.KnowledgeModels.Routes as KnowledgeModelsRoute
import Wizard.Models exposing (Model, initLocalModel, initialModel, userLoggedIn)
Expand Down Expand Up @@ -48,10 +50,18 @@ init flags location key =

Nothing ->
Cmd.none

aiAssistantCmd =
if Admin.isEnabled appState.config.admin then
Taks.dispatch (Wizard.Msgs.AIAssistantMsg AIAssistant.init)

else
Cmd.none
in
Cmd.batch
[ decideInitialRoute model location route originalRoute
, setThemeCmd
, aiAssistantCmd
, Time.getTime
, Time.getTimeZone
]
Expand Down
6 changes: 6 additions & 0 deletions engine-wizard/elm/Wizard/Common/AppState.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Wizard.Common.AppState exposing
( AppState
, acceptCookies
, getAIAssistantApiUrl
, getClientUrlRoot
, getUserRole
, init
Expand Down Expand Up @@ -206,3 +207,8 @@ sessionRemainingTime appState =
|> String.padLeft 2 '0'
in
timeLeftMin ++ ":" ++ timeLeftSec


getAIAssistantApiUrl : AppState -> String
getAIAssistantApiUrl appState =
String.replace "/wizard" "/ai-assistant" appState.apiUrl
Loading

0 comments on commit 8d73902

Please sign in to comment.