Skip to content

Commit

Permalink
chat: move chat to it's own page
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh authored and mitya52 committed Jan 18, 2024
1 parent f43d3a3 commit fd21478
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 93 deletions.
1 change: 0 additions & 1 deletion self_hosting_machinery/webgui/selfhost_lsp_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import json
import httpx


__all__ = ["LspProxy"]


Expand Down
1 change: 0 additions & 1 deletion self_hosting_machinery/webgui/selfhost_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def __init__(self):
{"label": "Server Logs", "tab": "server-logs"},
{"label": "Stats", "tab": "stats"},
{"label": "Credentials", "tab": "settings", "hamburger": True},
{"label": "Chat", "tab": "chat"}
]
self.add_api_route("/list-plugins", self._list_plugins, methods=["GET"])

Expand Down
12 changes: 11 additions & 1 deletion self_hosting_machinery/webgui/selfhost_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class StaticRouter(APIRouter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super().add_api_route("/", self._index, methods=["GET"])
super().add_api_route("/chat", self._chat, methods=["GET"])
super().add_api_route("/{file_path:path}", self._static_file, methods=["GET"])
super().add_api_route("/ping", self._ping_handler, methods=["GET"])
self.static_folders = [
os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
os.path.join(os.path.dirname(os.path.abspath(__file__)), "static"),
os.path.join(os.path.dirname(os.path.abspath(__file__)), "static", "assets")
]

async def _index(self):
Expand All @@ -24,9 +26,17 @@ async def _index(self):
return FileResponse(fn, media_type="text/html")
raise HTTPException(404, "No index.html found")

async def _chat(self):
for spath in self.static_folders:
fn = os.path.join(spath, "chat.html")
if os.path.exists(fn):
return FileResponse(fn, media_type="text/html")
raise HTTPException(404, "No chat.html found")

async def _static_file(self, file_path: str):
if ".." in file_path:
raise HTTPException(404, "Path \"%s\" not found" % file_path)

for spath in self.static_folders:
fn = os.path.join(spath, file_path)
if os.path.exists(fn):
Expand Down

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions self_hosting_machinery/webgui/static/chat.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en" class="light">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Refact.ai Chat</title>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Refact.ai Chat</title>
<!-- TODO: consider using a cdn for hosting these files after integrating with IDEs-->
<script type="module" crossorigin src="/chat/chat.umd.js"></script>
<link rel="stylesheet" crossorigin href="/chat/styles.css">
<link rel="stylesheet" crossorigin href="/chat/theme-config.css">
</head>
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" crossorigin href="/assets/theme-config.css">
<script src="assets/chat.umd.cjs"></script>
<body>
<div id="root"></div>
<div id="refact-chat"></div>
</body>
</html>
<script>
window.onload = function() {
RefactChat(document.getElementById("refact-chat"), "lsp")
}
</script>
</html>
13 changes: 11 additions & 2 deletions self_hosting_machinery/webgui/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="#">
<link rel="icon" type="image/png" href="/favicon.png" />
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
<title>Refact Self Hosting</title>
Expand Down Expand Up @@ -65,6 +66,11 @@
</li>
{{/unless}}
{{/each}}
{{#unless hamburger}}
<li class="nav-item" role="presentation">
<button onclick="window.open('/chat', '_blank')" class="nav-link" id="{{id}}" {{#if disabled}}disabled{{/if}}>Chat</button>
</li>
{{/unless}}
<div class="d-flex ms-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button"
Expand All @@ -91,6 +97,11 @@
</li>
{{/if}}
{{/each}}
{{#if hamburger}}
<li class="nav-item" role="presentation">
<button onclick="window.open('/chat', '_blank')" class="nav-link main-tab-button" id="{{id}}-tab">Chat</button>
</li>
{{/if}}
</ul>
</li>
</div>
Expand All @@ -115,8 +126,6 @@
</div>
<div class="main-tab-pane" id="license">
</div>
<div class="main-tab-pane" id="chat">
</div>
</div>
</div>

Expand Down
13 changes: 0 additions & 13 deletions self_hosting_machinery/webgui/static/tab-chat.html

This file was deleted.

23 changes: 0 additions & 23 deletions self_hosting_machinery/webgui/static/tab-chat.js

This file was deleted.

0 comments on commit fd21478

Please sign in to comment.