Skip to content

Commit 2ab98e3

Browse files
Merge pull request #22 from vincent99/main
Initial UI
2 parents ce304b7 + b28a7d0 commit 2ab98e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+11486
-3
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
test:
1212
runs-on: ubuntu-22.04
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 1
17-
- uses: actions/setup-go@v4
17+
- uses: actions/setup-go@v5
1818
with:
1919
cache: false
2020
go-version: "1.21"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/bin
22
/.idea
3+
/static/ui

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch file",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "debug",
12+
"program": "main.go",
13+
"args": ["--server"]
14+
}
15+
]
16+
}

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
all: build-ui build
2+
3+
build-ui:
4+
$(MAKE) -C ui
5+
16
build:
27
CGO_ENABLED=0 go build -o bin/gptscript -tags "${GO_TAGS}" -ldflags "-s -w" .
38

pkg/server/server.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ func (s *Server) Connect(session *melody.Session) {
234234
}
235235

236236
func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
237+
isUpgrade := strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade")
238+
isBrowser := strings.Contains(strings.ToLower(req.Header.Get("User-Agent")), "mozilla")
239+
isAjax := req.Header.Get("X-Requested-With") != ""
240+
241+
if req.URL.Path == "/" && isBrowser && !isAjax && !isUpgrade {
242+
rw.Header().Set("Location", "/ui/")
243+
rw.WriteHeader(302)
244+
return
245+
}
246+
247+
if req.URL.Path == "/favicon.ico" {
248+
http.ServeFileFS(rw, req, static.UI, "/ui/favicon.ico")
249+
return
250+
}
251+
237252
if strings.HasPrefix(req.URL.Path, "/ui") {
238253
path := req.URL.Path
239254
if path == "/ui" || path == "/ui/" {
@@ -250,7 +265,7 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
250265
case http.MethodPost:
251266
s.run(rw, req)
252267
case http.MethodGet:
253-
if req.URL.Path == "/" && strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade") {
268+
if req.URL.Path == "/" && isUpgrade {
254269
err := s.melody.HandleRequest(rw, req)
255270
if err != nil {
256271
http.Error(rw, err.Error(), http.StatusInternalServerError)

ui/.ackrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--ignore-dir=.git
2+
--ignore-dir=.nuxt
3+
--ignore-dir=.nuxt-prod
4+
--ignore-dir=.nyc_output
5+
--ignore-dir=.output
6+
--ignore-dir=.vscode
7+
--ignore-dir=coverage
8+
--ignore-dir=dist
9+
--ignore-dir=node_modules
10+
--ignore-dir=tmp
11+
--ignore-dir=vendor
12+
--ignore-file=ext:svg
13+
--ignore-file=is:selection.json
14+
--ignore-file=is:yarn.lock

ui/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.nuxt
3+
.nuxt-prod
4+
.env
5+
.nuxt
6+
.nyc_output
7+
coverage
8+
node_modules

ui/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Nuxt dev/build outputs
2+
.output
3+
.data
4+
.nuxt
5+
.nitro
6+
.cache
7+
dist
8+
9+
# Node dependencies
10+
node_modules
11+
12+
# Logs
13+
logs
14+
*.log
15+
16+
# Misc
17+
.DS_Store
18+
.fleet
19+
.idea
20+
21+
# Local env files
22+
.env
23+
.env.*
24+
!.env.example

ui/.vscode/settings.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": "explicit"
4+
},
5+
"editor.detectIndentation": false,
6+
"editor.insertSpaces": true,
7+
"editor.quickSuggestions": {
8+
"strings": true
9+
},
10+
"editor.tabSize": 2,
11+
"eslint.format.enable": true,
12+
"eslint.run": "onSave",
13+
"eslint.validate": [
14+
"vue",
15+
"html",
16+
"javascript",
17+
"typescript"
18+
],
19+
"files.associations": {
20+
"*.css": "tailwindcss"
21+
},
22+
"files.exclude": {
23+
".ackrc": true,
24+
".dockerignore": true,
25+
".drone.yml": true,
26+
".editorconfig": true,
27+
".eslintcache": true,
28+
".eslintignore": true,
29+
".eslintrc.js": true,
30+
".gitignore": true,
31+
".nuxt*": true,
32+
".nyc_output": true,
33+
"babel.config.js": true,
34+
"coverage": true,
35+
"jsconfig.json": true,
36+
"LICENSE": true,
37+
"yarn-error.log": true
38+
},
39+
"javascript.preferences.importModuleSpecifier": "non-relative",
40+
"prettier.enable": false,
41+
"tailwindCSS.classAttributes": [
42+
"class",
43+
"className",
44+
"ui"
45+
],
46+
"tailwindCSS.experimental.classRegex": [
47+
[
48+
"ui:\\s*{([^)]*)\\s*}",
49+
"[\"'`]([^\"'`]*).*?[\"'`]"
50+
],
51+
[
52+
"/\\*ui\\*/\\s*{([^;]*)}",
53+
":\\s*[\"'`]([^\"'`]*).*?[\"'`]"
54+
]
55+
],
56+
"tailwindCSS.experimental.configFile": "tailwind.config.ts",
57+
"typescript.preferences.importModuleSpecifier": "non-relative"
58+
}

ui/Acornfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
args: {
2+
// Number of replicas
3+
replicas: 1
4+
5+
// API Endpoint
6+
api: "https://localhost:9090/v1"
7+
}
8+
9+
services: default: {
10+
default: true
11+
ports: ["80/http"]
12+
container: "ui"
13+
}
14+
15+
containers: ui: {
16+
scale: args.replicas
17+
build: context: "."
18+
19+
env: {
20+
NUXT_PUBLIC_API: args.api
21+
}
22+
23+
ports: publish: "80/http"
24+
probes: "http://localhost/healthz"
25+
}

0 commit comments

Comments
 (0)