diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/AppServerBase.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/AppServerBase.kt index 2e42c2ba..0dbcf050 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/AppServerBase.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/AppServerBase.kt @@ -4,9 +4,10 @@ package com.simiacryptus.skyenet.servers import com.simiacryptus.openai.OpenAIClient import com.simiacryptus.skyenet.OutputInterceptor import com.simiacryptus.skyenet.util.AwsUtil.decryptResource -import com.simiacryptus.skyenet.webui.AuthenticatedWebsite -import com.simiacryptus.skyenet.webui.ApplicationServerBase -import com.simiacryptus.skyenet.webui.UserInfoServlet +import com.simiacryptus.skyenet.servlet.AuthenticatedWebsite +import com.simiacryptus.skyenet.webui.ApplicationBase +import com.simiacryptus.skyenet.servlet.UserInfoServlet +import com.simiacryptus.skyenet.servlet.UserSettingsServlet import com.simiacryptus.skyenet.webui.WebSocketServer import jakarta.servlet.DispatcherType import jakarta.servlet.Servlet @@ -44,6 +45,7 @@ abstract class AppServerBase( val welcomeResources = Resource.newResource(javaClass.classLoader.getResource("welcome")) val userInfoServlet = UserInfoServlet() + val userSettingsServlet = UserSettingsServlet() protected fun _main(args: Array) { try { @@ -62,6 +64,7 @@ abstract class AppServerBase( port, *(arrayOf( newWebAppContext("/userInfo", userInfoServlet), + newWebAppContext("/userSettings", userSettingsServlet), newWebAppContext("/proxy", ProxyHttpServlet()), authentication.configure( newWebAppContext( @@ -100,12 +103,13 @@ abstract class AppServerBase( val requestURI = req?.requestURI ?: "/" resp?.contentType = when (requestURI) { "/" -> "text/html" - else -> ApplicationServerBase.getMimeType(requestURI) + else -> ApplicationBase.getMimeType(requestURI) } when { requestURI == "/" -> resp?.writer?.write(homepage().trimIndent()) requestURI == "/index.html" -> resp?.writer?.write(homepage().trimIndent()) requestURI.startsWith("/userInfo") -> userInfoServlet.doGet(req!!, resp!!) + requestURI.startsWith("/userSettings") -> userSettingsServlet.doGet(req!!, resp!!) else -> try { val inputStream = welcomeResources.addPath(requestURI)?.inputStream inputStream?.copyTo(resp?.outputStream!!) @@ -114,6 +118,14 @@ abstract class AppServerBase( } } } + + override fun doPost(req: HttpServletRequest?, resp: HttpServletResponse?) { + val requestURI = req?.requestURI ?: "/" + when { + requestURI.startsWith("/userSettings") -> userSettingsServlet.doPost(req!!, resp!!) + else -> resp?.sendError(404) + } + } } @Language("HTML") diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/CodingActorTestApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/CodingActorTestApp.kt index fa294384..c0b2b9f4 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/CodingActorTestApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/CodingActorTestApp.kt @@ -1,7 +1,7 @@ package com.simiacryptus.skyenet.servers import com.simiacryptus.skyenet.actors.CodingActor -import com.simiacryptus.skyenet.webui.MarkdownUtil.renderMarkdown +import com.simiacryptus.skyenet.util.MarkdownUtil.renderMarkdown import com.simiacryptus.skyenet.webui.PersistentSessionBase import com.simiacryptus.skyenet.webui.SessionDiv import com.simiacryptus.skyenet.webui.MacroChat diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ParsedActorTestApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ParsedActorTestApp.kt index 55770ea3..75a3dd6f 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ParsedActorTestApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ParsedActorTestApp.kt @@ -1,7 +1,7 @@ package com.simiacryptus.skyenet.servers import com.simiacryptus.skyenet.actors.ParsedActor -import com.simiacryptus.skyenet.webui.MarkdownUtil.renderMarkdown +import com.simiacryptus.skyenet.util.MarkdownUtil.renderMarkdown import com.simiacryptus.skyenet.webui.PersistentSessionBase import com.simiacryptus.skyenet.webui.SessionDiv import com.simiacryptus.skyenet.webui.MacroChat diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ReadOnlyApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ReadOnlyApp.kt index 7be33f60..79c1e94e 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ReadOnlyApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/ReadOnlyApp.kt @@ -9,7 +9,7 @@ open class ReadOnlyApp( temperature: Double = 0.3, oauthConfig: String? = null, val api: OpenAIClient, -) : ApplicationServerBase( +) : ApplicationBase( applicationName = applicationName, oauthConfig = oauthConfig, temperature = temperature, diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/SimpleActorTestApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/SimpleActorTestApp.kt index 8b3eb6d3..d22622cc 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/SimpleActorTestApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servers/SimpleActorTestApp.kt @@ -2,6 +2,7 @@ package com.simiacryptus.skyenet.servers import com.simiacryptus.skyenet.actors.SimpleActor import com.simiacryptus.skyenet.webui.* +import com.simiacryptus.skyenet.util.MarkdownUtil import org.slf4j.LoggerFactory open class SimpleActorTestApp( diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/AuthenticatedWebsite.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AuthenticatedWebsite.kt similarity index 98% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/AuthenticatedWebsite.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AuthenticatedWebsite.kt index a4059cda..4c1b8d88 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/AuthenticatedWebsite.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AuthenticatedWebsite.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl @@ -129,8 +129,9 @@ open class AuthenticatedWebsite( companion object { private val log = org.slf4j.LoggerFactory.getLogger(AuthenticatedWebsite::class.java) - val users = HashMap() + + val users = java.util.HashMap() fun getUser(req: HttpServletRequest): Userinfo? { val sessionId = req.cookies?.find { it.name == "sessionId" }?.value return if (null == sessionId) null else users[sessionId] diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/FileServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/FileServlet.kt similarity index 90% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/FileServlet.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/FileServlet.kt index 57635a35..a7f3cbc1 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/FileServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/FileServlet.kt @@ -1,5 +1,7 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet +import com.simiacryptus.skyenet.webui.ApplicationBase +import com.simiacryptus.skyenet.webui.SessionDataStorage import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse @@ -18,7 +20,7 @@ class FileServlet(val sessionDataStorage: SessionDataStorage) : HttpServlet() { val file = File(sessionDir, filePath) if (file.isFile) { val filename = file.name - resp.contentType = ApplicationServerBase.getMimeType(filename) + resp.contentType = ApplicationBase.getMimeType(filename) resp.status = HttpServletResponse.SC_OK file.inputStream().use { inputStream -> resp.outputStream.use { outputStream -> diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/NewSessionServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/NewSessionServlet.kt similarity index 81% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/NewSessionServlet.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/NewSessionServlet.kt index c3334140..c6cfc56b 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/NewSessionServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/NewSessionServlet.kt @@ -1,5 +1,6 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet +import com.simiacryptus.skyenet.webui.SessionDataStorage import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/SessionServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionServlet.kt similarity index 92% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/SessionServlet.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionServlet.kt index 1787c564..7ed9b875 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/SessionServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionServlet.kt @@ -1,5 +1,6 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet +import com.simiacryptus.skyenet.webui.SessionDataStorage import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/SettingsServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt similarity index 60% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/SettingsServlet.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt index 3ef0861f..b9480006 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/SettingsServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt @@ -1,12 +1,13 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet +import com.simiacryptus.skyenet.webui.ApplicationBase import com.simiacryptus.util.JsonUtil import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse -class SettingsServlet( - val server: ApplicationServerBase, +class SessionSettingsServlet( + private val server: ApplicationBase, ) : HttpServlet() { override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) { resp.contentType = "text/html" @@ -18,22 +19,24 @@ class SettingsServlet( } else { val settings = server.getSettings(sessionId) val json = if(settings != null) JsonUtil.toJson(settings) else "" + //language=HTML resp.writer.write( """ - | - | - |Settings - | - | - |
- | - | - | - | - |
- | - | - """.trimMargin() + | + | + | Settings + | + | + | + |
+ | + | + | + | + |
+ | + | + """.trimMargin() ) } } @@ -48,7 +51,6 @@ class SettingsServlet( } else { val settings = JsonUtil.fromJson(req.getParameter("settings"), server.settingsClass) server.sessionDataStorage.updateSettings(sessionId, settings) - // Redirect back to ${req.contextPath}/# resp.sendRedirect("${req.contextPath}/#$sessionId") } } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/UserInfoServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt similarity index 93% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/UserInfoServlet.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt index 56fd5c8a..5cc5dbe6 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/UserInfoServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet import com.simiacryptus.util.JsonUtil import jakarta.servlet.http.HttpServlet diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt new file mode 100644 index 00000000..08df2d06 --- /dev/null +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt @@ -0,0 +1,75 @@ +package com.simiacryptus.skyenet.servlet + +import com.google.api.services.oauth2.model.Userinfo +import com.simiacryptus.util.JsonUtil +import jakarta.servlet.http.HttpServlet +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse + +class UserSettingsServlet : HttpServlet() { + public override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) { + resp.contentType = "text/html" + resp.status = HttpServletResponse.SC_OK + val authId = req.cookies?.firstOrNull { it.name == "sessionId" }?.value + if (null == authId) { + resp.status = HttpServletResponse.SC_BAD_REQUEST + } else { + val userinfo = AuthenticatedWebsite.users[authId] + if(null == userinfo) { + resp.status = HttpServletResponse.SC_BAD_REQUEST + } else { + val settings = getUserSettings(userinfo) + val json = if (settings != null) JsonUtil.toJson(settings) else "" + //language=HTML + resp.writer.write( + """ + | + | + | Settings + | + | + | + |
+ | + | + | + | + |
+ | + | + """.trimMargin() + ) + } + } + } + + public override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) { + val userinfo = AuthenticatedWebsite.getUser(req) + if (null == userinfo) { + resp.status = HttpServletResponse.SC_BAD_REQUEST + } else { + val settings = JsonUtil.fromJson(req.getParameter("settings"), UserSettings::class.java) + updateUserSettings(userinfo, settings) + resp.sendRedirect("/") + } + } + + companion object { + val log = org.slf4j.LoggerFactory.getLogger(UserSettingsServlet::class.java) + private val userSettings = HashMap() + + fun getUserSettings(userinfo: Userinfo): UserSettings { + return userSettings.getOrPut(userinfo.id) { + UserSettings() + } + } + + fun updateUserSettings(userinfo: Userinfo, settings: UserSettings) { + userSettings[userinfo.id] = settings + } + + } +} +data class UserSettings( + val apiKey: String = "", +) diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ZipServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/ZipServlet.kt similarity index 94% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ZipServlet.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/ZipServlet.kt index bd1f4c9c..2e5ad56c 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ZipServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/ZipServlet.kt @@ -1,5 +1,6 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.servlet +import com.simiacryptus.skyenet.webui.SessionDataStorage import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ClasspathResource.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/util/ClasspathResource.kt similarity index 98% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ClasspathResource.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/util/ClasspathResource.kt index 11cdc268..355f8ec0 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ClasspathResource.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/util/ClasspathResource.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.util import org.eclipse.jetty.util.URIUtil import org.eclipse.jetty.util.resource.Resource diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MarkdownUtil.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/util/MarkdownUtil.kt similarity index 94% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MarkdownUtil.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/util/MarkdownUtil.kt index 2dfebebe..5686f0b4 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MarkdownUtil.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/util/MarkdownUtil.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.webui +package com.simiacryptus.skyenet.util import com.vladsch.flexmark.ext.tables.TablesExtension import com.vladsch.flexmark.html.HtmlRenderer diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ApplicationServerBase.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ApplicationBase.kt similarity index 76% rename from webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ApplicationServerBase.kt rename to webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ApplicationBase.kt index 94a0a13b..30da884e 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ApplicationServerBase.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ApplicationBase.kt @@ -1,5 +1,6 @@ package com.simiacryptus.skyenet.webui +import com.simiacryptus.skyenet.servlet.* import com.simiacryptus.util.JsonUtil import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest @@ -10,7 +11,7 @@ import org.eclipse.jetty.webapp.WebAppContext import org.slf4j.LoggerFactory import java.io.File -abstract class ApplicationServerBase( +abstract class ApplicationBase( final override val applicationName: String, val oauthConfig: String? = null, resourceBase: String = "simpleSession", @@ -25,7 +26,7 @@ abstract class ApplicationServerBase( @Suppress("UNCHECKED_CAST") var settings: T? = sessionDataStorage.getSettings(sessionId, settingsClass as Class) if (null == settings) { - settings = initSettings(sessionId) + settings = initSettings(sessionId) if (null != settings) { sessionDataStorage.updateSettings(sessionId, settings) } @@ -42,24 +43,24 @@ abstract class ApplicationServerBase( protected open val fileZip = ServletHolder("fileZip", ZipServlet(sessionDataStorage)) protected open val fileIndex = ServletHolder("fileIndex", FileServlet(sessionDataStorage)) protected open val sessionsServlet = ServletHolder("sessionList", SessionServlet(this.sessionDataStorage)) - protected open val settingsServlet = ServletHolder("settings", SettingsServlet(this)) + protected open val sessionSettingsServlet = ServletHolder("settings", SessionSettingsServlet(this)) - override fun configure(context: WebAppContext, prefix: String, baseURL: String) { - super.configure(context, prefix, baseURL) + override fun configure(webAppContext: WebAppContext, prefix: String, baseUrl: String) { + super.configure(webAppContext, prefix, baseUrl) if (null != oauthConfig) (AuthenticatedWebsite( - "$baseURL/oauth2callback", - this@ApplicationServerBase.applicationName + "$baseUrl/oauth2callback", + this@ApplicationBase.applicationName ) { FileUtils.openInputStream(File(oauthConfig)) - }).configure(context) - - context.addServlet(appInfo, prefix + "appInfo") - context.addServlet(userInfo, prefix + "userInfo") - context.addServlet(fileIndex, prefix + "fileIndex/*") - context.addServlet(fileZip, prefix + "fileZip") - context.addServlet(sessionsServlet, prefix + "sessions") - context.addServlet(settingsServlet, prefix + "settings") + }).configure(webAppContext) + + webAppContext.addServlet(appInfo, prefix + "appInfo") + webAppContext.addServlet(userInfo, prefix + "userInfo") + webAppContext.addServlet(fileIndex, prefix + "fileIndex/*") + webAppContext.addServlet(fileZip, prefix + "fileZip") + webAppContext.addServlet(sessionsServlet, prefix + "sessions") + webAppContext.addServlet(sessionSettingsServlet, prefix + "settings") } inner class AppInfoServlet : HttpServlet() { @@ -80,7 +81,7 @@ abstract class ApplicationServerBase( protected open val userInfo = ServletHolder("userInfo", UserInfoServlet()) companion object { - val log = LoggerFactory.getLogger(ApplicationServerBase::class.java) + val log = LoggerFactory.getLogger(ApplicationBase::class.java) val spinner = """
Loading...
""" diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChat.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChat.kt index e6303e2d..e6ba41cd 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChat.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChat.kt @@ -7,7 +7,7 @@ open class BasicChat( oauthConfig: String? = null, val model: OpenAIClient.Model = OpenAIClient.Models.GPT35Turbo, val api: OpenAIClient, -) : ApplicationServerBase( +) : ApplicationBase( applicationName = applicationName, oauthConfig = oauthConfig, ) { diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChatSession.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChatSession.kt index 1c9b4b02..bc22ac0b 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChatSession.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/BasicChatSession.kt @@ -3,7 +3,7 @@ package com.simiacryptus.skyenet.webui import com.simiacryptus.openai.OpenAIClient open class BasicChatSession( - parent: ApplicationServerBase, + parent: ApplicationBase, model: OpenAIClient.Model = OpenAIClient.Models.GPT35Turbo, sessionId: String, visiblePrompt: String = """ diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ChatSession.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ChatSession.kt index c385713e..51c3829f 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ChatSession.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/ChatSession.kt @@ -3,7 +3,7 @@ package com.simiacryptus.skyenet.webui import com.simiacryptus.openai.OpenAIClient abstract class ChatSession( - val parent: ApplicationServerBase, + val parent: ApplicationBase, sessionId: String, var model: OpenAIClient.Model = OpenAIClient.Models.GPT35Turbo, private var visiblePrompt: String, @@ -25,7 +25,7 @@ abstract class ChatSession( override fun run(userMessage: String, socket: MessageWebSocket) { var responseContents = divInitializer() responseContents += """
$userMessage
""" - send("""$responseContents
${ApplicationServerBase.spinner}
""") + send("""$responseContents
${ApplicationBase.spinner}
""") val response = handleMessage(userMessage, responseContents) if(null != response) { responseContents += """
${renderResponse(response)}
""" diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChat.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChat.kt index f7e12e28..66c9ae27 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChat.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChat.kt @@ -6,7 +6,7 @@ abstract class MacroChat( applicationName: String, oauthConfig: String? = null, temperature: Double = 0.1, -) : ApplicationServerBase( +) : ApplicationBase( applicationName = applicationName, oauthConfig = oauthConfig, temperature = temperature, diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChatSession.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChatSession.kt index ea056538..6925a0b1 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChatSession.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MacroChatSession.kt @@ -19,7 +19,7 @@ class MacroChatSession( val session: PersistentSessionBase = this override fun run(userMessage: String, socket: MessageWebSocket) { val operationID = ChatSession.randomID() - val sessionDiv = newSessionDiv(operationID, ApplicationServerBase.spinner) + val sessionDiv = newSessionDiv(operationID, ApplicationBase.spinner) val thread = Thread { playSempaphores[operationID] = Semaphore(0) try { @@ -34,7 +34,7 @@ class MacroChatSession( } inner class SessionImpl(private val operationID: String) : MacroChat.SessionUI { - override val spinner: String get() = """
${ApplicationServerBase.spinner}
""" + override val spinner: String get() = """
${ApplicationBase.spinner}
""" override val playButton: String get() = """""" override val cancelButton: String get() = """""" override val regenButton: String get() = """""" diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MessageWebSocket.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MessageWebSocket.kt index c1d0b139..482cbfb4 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MessageWebSocket.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/MessageWebSocket.kt @@ -1,10 +1,11 @@ package com.simiacryptus.skyenet.webui import com.simiacryptus.openai.OpenAIClient +import com.simiacryptus.skyenet.servlet.AuthenticatedWebsite +import com.simiacryptus.skyenet.servlet.UserSettingsServlet.Companion.getUserSettings import org.eclipse.jetty.websocket.api.Session import org.eclipse.jetty.websocket.api.WebSocketAdapter import org.slf4j.event.Level -import java.net.HttpCookie class MessageWebSocket( val sessionId: String, @@ -13,15 +14,26 @@ class MessageWebSocket( val sessionDataStorage: SessionDataStorage, ) : WebSocketAdapter() { - val api: OpenAIClient get() { - val client = OpenAIClient( - logLevel = Level.DEBUG, - logStreams = mutableListOf( - sessionDataStorage.getSessionDir(sessionId).resolve("openai.log").outputStream().buffered() + val api: OpenAIClient + get() { + val userinfo = AuthenticatedWebsite.users[authId] + val userApi: OpenAIClient? = if (userinfo == null) null else { + val userSettings = getUserSettings(userinfo) + if (userSettings.apiKey.isBlank()) null else OpenAIClient( + key = userSettings.apiKey, + logLevel = Level.DEBUG, + logStreams = mutableListOf( + sessionDataStorage.getSessionDir(sessionId).resolve("openai.log").outputStream().buffered() + ), + ) + } + return userApi ?: OpenAIClient( + logLevel = Level.DEBUG, + logStreams = mutableListOf( + sessionDataStorage.getSessionDir(sessionId).resolve("openai.log").outputStream().buffered() + ) ) - ) - return client - } + } override fun onWebSocketConnect(session: Session) { super.onWebSocketConnect(session) diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/WebSocketServer.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/WebSocketServer.kt index 3f938980..76b5dbd1 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/WebSocketServer.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/webui/WebSocketServer.kt @@ -1,5 +1,6 @@ package com.simiacryptus.skyenet.webui +import com.simiacryptus.skyenet.servlet.NewSessionServlet import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.DefaultServlet import org.eclipse.jetty.servlet.ServletHolder diff --git a/webui/src/main/resources/simpleSession/index.html b/webui/src/main/resources/simpleSession/index.html index 8d51ece4..15b8cc64 100644 --- a/webui/src/main/resources/simpleSession/index.html +++ b/webui/src/main/resources/simpleSession/index.html @@ -7,7 +7,7 @@ - + diff --git a/webui/src/main/resources/simpleSession/main.js b/webui/src/main/resources/simpleSession/main.js index a64d794f..9aef3f05 100644 --- a/webui/src/main/resources/simpleSession/main.js +++ b/webui/src/main/resources/simpleSession/main.js @@ -153,7 +153,7 @@ document.addEventListener('DOMContentLoaded', () => { .then(data => { if (data.name && loginLink) { loginLink.innerHTML = data.name; - loginLink.href = "/userInfo"; + loginLink.href = "/userSettings"; } }) .catch(error => { diff --git a/webui/src/main/resources/welcome/main.js b/webui/src/main/resources/welcome/main.js index 2c52203e..5b94b713 100644 --- a/webui/src/main/resources/welcome/main.js +++ b/webui/src/main/resources/welcome/main.js @@ -46,7 +46,7 @@ document.addEventListener('DOMContentLoaded', () => { .then(data => { if (data.name && loginLink) { loginLink.innerHTML = data.name; - loginLink.href = "/userInfo"; + loginLink.href = "/userSettings"; } }) .catch(error => {