diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/AuthenticatedWebsite.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/AuthenticatedWebsite.kt index c525a1b7..66e5b2b9 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/AuthenticatedWebsite.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/AuthenticatedWebsite.kt @@ -62,13 +62,8 @@ open class AuthenticatedWebsite( * @param context the `WebAppContext` to configure */ open fun configure(context: WebAppContext, addFilter: Boolean = true): WebAppContext { - // Create a ServletHolder for the GoogleLoginServlet and add it to the context - val googleServletHolder = ServletHolder("googleLogin", GoogleLoginServlet()) - context.addServlet(googleServletHolder, "/googleLogin") - // Create a ServletHolder for the OAuth2CallbackServlet and add it to the context - val callbackServletHolder = ServletHolder("oauth2callback", OAuth2CallbackServlet()) - context.addServlet(callbackServletHolder, "/oauth2callback") - // Add a SessionIdFilter to the context that intercepts every request + context.addServlet(ServletHolder("googleLogin", GoogleLoginServlet()), "/googleLogin") + context.addServlet(ServletHolder("oauth2callback", OAuth2CallbackServlet()), "/oauth2callback") if(addFilter) context.addFilter(FilterHolder(SessionIdFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)) return context } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt index 55b72091..acc30c13 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt @@ -116,11 +116,12 @@ abstract class SkyenetMacroChat( sessionUI: SessionUI, sessionDiv: SessionDiv, parameters: T, - feedbackFn: (msg: T, t: String) -> Unit, - fns: Map Unit> + feedbackFn: (msg: T, feedback: String) -> Unit, + fns: Map Unit> = mapOf(), + toString: (obj: T) -> String = JsonUtil::toJson ) = sessionDiv.append( """ -
${JsonUtil.toJson(parameters)}
+
${toString(parameters)}

${sessionUI.textInput { feedbackFn(parameters, it) }}
@@ -129,6 +130,7 @@ abstract class SkyenetMacroChat( }} """, false ) + } } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt index b273288a..14c596b1 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt @@ -13,7 +13,7 @@ import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream abstract class SkyenetSessionServerBase( - val applicationName: String, + override val applicationName: String, val oauthConfig: String? = null, resourceBase: String = "simpleSession", val baseURL: String = "http://localhost:8080", diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/WebSocketServer.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/WebSocketServer.kt index 14d80a3c..914f3aac 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/WebSocketServer.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/WebSocketServer.kt @@ -17,6 +17,8 @@ import java.util.* abstract class WebSocketServer(val resourceBase: String) { + abstract val applicationName: String + inner class NewSessionServlet : HttpServlet() { override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) { val sessionId = UUID.randomUUID().toString() diff --git a/webui/src/main/resources/simple/chat.css b/webui/src/main/resources/simple/chat.css deleted file mode 100644 index 2f73a30b..00000000 --- a/webui/src/main/resources/simple/chat.css +++ /dev/null @@ -1,47 +0,0 @@ -#messages { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 40px; - overflow-y: auto; - padding: 10px; -} - -.message { - background-color: #f0f0f0; - border-radius: 5px; - padding: 10px; - margin-bottom: 10px; -} - -#form { - position: absolute; - left: 0; - right: 0; - bottom: 0; - display: flex; - margin: 0; - padding: 5px; -} - -#message { - flex-grow: 1; - margin-right: 5px; -} - -#disconnected-overlay { - display: none; - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - background-color: rgba(0, 0, 0, 0.5); - z-index: 999; - display: flex; - justify-content: center; - align-items: center; - color: white; - font-size: 24px; -} diff --git a/webui/src/main/resources/simple/chat.js b/webui/src/main/resources/simple/chat.js deleted file mode 100644 index 0e9a16b8..00000000 --- a/webui/src/main/resources/simple/chat.js +++ /dev/null @@ -1,56 +0,0 @@ -function getSessionId() { - if (!window.location.hash) { - fetch('/newSession') - .then(response => { - if (response.ok) { - return response.text(); - } else { - throw new Error('Failed to get new session ID'); - } - }) - .then(sessionId => { - window.location.hash = sessionId; - connect(sessionId); - }); - } else { - return window.location.hash.substring(1); - } -} - -let socket; - -function send(message) { - socket.send(message); -} - -function connect(sessionId, customReceiveFunction) { - const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - const host = window.location.hostname; - const port = window.location.port; - - socket = new WebSocket(`${protocol}//${host}:${port}/ws?sessionId=${sessionId}`); - - socket.addEventListener('open', (event) => { - console.log('WebSocket connected:', event); - showDisconnectedOverlay(false); - }); - - socket.addEventListener('message', customReceiveFunction || receive); - - socket.addEventListener('close', (event) => { - console.log('WebSocket closed:', event); - showDisconnectedOverlay(true); - setTimeout(() => { - connect(getSessionId(), customReceiveFunction); - }, 5000); - }); - - socket.addEventListener('error', (event) => { - console.error('WebSocket error:', event); - }); -} - -function showDisconnectedOverlay(show) { - const overlay = document.getElementById('disconnected-overlay'); - overlay.style.display = show ? 'block' : 'none'; -} diff --git a/webui/src/main/resources/simple/index.html b/webui/src/main/resources/simple/index.html deleted file mode 100644 index 12f482d9..00000000 --- a/webui/src/main/resources/simple/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - WebSocket Client - - - - -
-
- - -
- -
-

Disconnected. Attempting to reconnect...

-
- - diff --git a/webui/src/test/kotlin/com/simiacryptus/skyenet/body/TestWebSocketServer.kt b/webui/src/test/kotlin/com/simiacryptus/skyenet/body/TestWebSocketServer.kt deleted file mode 100644 index 9d67348f..00000000 --- a/webui/src/test/kotlin/com/simiacryptus/skyenet/body/TestWebSocketServer.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.simiacryptus.skyenet.body - -import java.awt.Desktop -import java.net.URI - -object TestWebSocketServer { - @JvmStatic - fun main(args: Array) { - val port = 8080 - val server = (object : WebSocketServer("simple") { - override fun newSession(sessionId: String) = object : SessionBase(sessionId) { - override fun onWebSocketText(socket: MessageWebSocket, message: String) { - logger.info("$sessionId - Received message: $message") - send("Server: $message") - } - } - }).start(port) - Desktop.getDesktop().browse(URI("http://localhost:$port/")) - server.join() - } -} \ No newline at end of file