Skip to content

Commit

Permalink
Merge branch 'main' into feat/ci-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
octoshikari committed Dec 28, 2023
2 parents 6dddc22 + 6728000 commit e2e11af
Show file tree
Hide file tree
Showing 19 changed files with 372 additions and 177 deletions.
16 changes: 16 additions & 0 deletions .env.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
AIDBOX_LICENSE=

PGHOSTPORT=5437
PGUSER=postgres
PGPASSWORD=postgres
PGDATABASE=aidbox

AIDBOX_BASE_URL=http://localhost:8888
AIDBOX_PORT=8888

AIDBOX_CLIENT_SECRET=secret
AIDBOX_ADMIN_PASSWORD=password

BOX_AUTH_KEYS_SECRET=auth-key-secret
BOX_AUTH_KEYS_PRIVATE="-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEApbUYGNmCz1P8G0j/FFOjx1d5GNssJ/jj6xasSwTIbjjt6FtY\nCDw8o7hayOc/u8aUqXCGhK3JD2T9gtKv9/rV30w4YzmHhA8OOuLJE7tfh/PJA4Hn\n4i2JJ30BuoZ7rPTlTRGdc1FS3XFdmBQtnplEkJ7y8qbdrVme3Kbtn+BR1BdtgwSy\nbpNH2yqh3bb6PwpgNSMH7BIkBWL4A6QDpaFf1/9jSNE1vO25ssLC+bhFQNWLYriu\n+HogzEf9NWIrR2W29mI1QiA7wqvEuhg1yx38ylWD8GhCGL6+2QLKBYgp7DIGv6Uo\nTnqcVISatdQ51lVcCPmU6L1BhmcXVti6dWBI+wIDAQABAoIBAFKMOcJbTKpKvLq8\n7PErz1lFDpreyArrlmKsy0ydx9j8vCt1oY+MrmqisnsFk/7PaIxV9XUP+6qTFSUA\nHtAKYVOZLTfk10jmlSCpjCCrxWW9AISiSKkoJPyKbfuE9gRNhRMU9NoXB5Av4r+Z\nQbaRxJHE1OMjVCgAjr592786qJjd+shhY8ZLchrxctpBj6/4T2Rd4Q8ltyEV3hiy\noYaFVp9g332bFw7jZSuxgedZojNO6xPvbparTAgVDDwKB+C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jANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApbUYGNmCz1P8G0j/FFOj\nx1d5GNssJ/jj6xasSwTIbjjt6FtYCDw8o7hayOc/u8aUqXCGhK3JD2T9gtKv9/rV\n30w4YzmHhA8OOuLJE7tfh/PJA4Hn4i2JJ30BuoZ7rPTlTRGdc1FS3XFdmBQtnplE\nkJ7y8qbdrVme3Kbtn+BR1BdtgwSybpNH2yqh3bb6PwpgNSMH7BIkBWL4A6QDpaFf\n1/9jSNE1vO25ssLC+bhFQNWLYriu+HogzEf9NWIrR2W29mI1QiA7wqvEuhg1yx38\nylWD8GhCGL6+2QLKBYgp7DIGv6UoTnqcVISatdQ51lVcCPmU6L1BhmcXVti6dWBI\n+wIDAQAB\n-----END PUBLIC KEY-----\n"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
.env
.lsp
.clj-kondo
pgdata
zen-packages
1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tbd
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
npm run dev
```

# Development


Aidbox uses sci language (minified Clojure). [sci API](https://github.com/babashka/sci/blob/master/API.md) is fully available.

In order to get access to Aidbox functions see [API.md](API.md).






# Deploy

1. Get Aidbox
Expand All @@ -21,3 +33,31 @@ npm run dev
# todo

- [ ] don't sync `.test.js` files in routes directory



```clojure
[:html
#_[:script {:type "module"}
"import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';"]

[:script {:type "module" :src "https://unpkg.com/@hotwired/[email protected]/dist/turbo.es2017-esm.js"}]

[:script {:src "/ui/$dev-mode"}]


[:form {:method "POST" :action "/ui/auth/logout"}
[:input {:type "hidden" :name "_csrf" :value (auth/csrf)}]
[:button "Sign out"]]

[:div "chat"]

[:turbo-frame {:id "chat"}
[:div "message"]]

[:turbo-frame {:id "chat-form"}
[:form {:action "/ui/chat/$send-message" :method "post"}
[:button "Generate new message"]]]

]
```
28 changes: 20 additions & 8 deletions aidbox-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ id: public-ui-chat
resourceType: AccessPolicy
engine: matcho
matcho:
request-method: get
uri:
$one-of:
- "#/ui/chat/.+"
- "/ui/chat"
---
id: ui-chat-user-action
resourceType: AccessPolicy
engine: matcho
matcho:
user:
id: present?
uri:
$one-of:
- "#/ui/chat/.+"
Expand Down Expand Up @@ -122,49 +134,49 @@ participants:

---
id: msg-1
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: john-smith, resourceType: User}
message: ' Good morning, doctor. Can I come in?'
---
id: msg-2
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: null, resourceType: User}
message: ' Good morning. How are you feeling today? You seem a bit under the weather.'
---
id: msg-3
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: john-smith, resourceType: User}
message: ' Indeed, doctor. I’ve been feeling unwell for a few days. I have a headache, a runny nose, and a sore throat.'
---
id: msg-4
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: null, resourceType: User}
message: ' I see. Let''s check your temperature and throat. Have you been in contact with anyone who is sick?'
---
id: msg-5
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: john-smith, resourceType: User}
message: ' Not that I’m aware of, doctor.'
---
id: msg-6
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: null, resourceType: User}
message: ' Well, it seems like you have a flu. It''s important that you rest, hydrate and take the prescribed medication. Also, avoid contact with others to prevent spreading the virus.'
---
id: msg-7
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: john-smith, resourceType: User}
message: ' I will do as you say, doctor. Thank you for your advice.'
---
id: msg-8
resourceType: Chat
resourceType: ChatMessage
chat: {id: chat-1, resourceType: Chat}
user: {id: null, resourceType: User}
message: ' You''re welcome. Get well soon.'
33 changes: 33 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.7'
services:
aidbox-db:
image: healthsamurai/aidboxdb:15.3
pull_policy: always
ports:
- "${PGHOSTPORT}:5432"
volumes:
- "./pgdata:/data"
environment:
POSTGRES_USER: "${PGUSER}"
POSTGRES_PASSWORD: "${PGPASSWORD}"
POSTGRES_DB: "${PGDATABASE}"

aidbox:
image: healthsamurai/aidboxone:edge
pull_policy: always
depends_on: ["aidbox-db"]
ports:
- "${AIDBOX_PORT}:${AIDBOX_PORT}"
volumes:
- "./zrc:/aidbox-project/zrc"
- "./zen-package.edn:/aidbox-project/zen-package.edn"
- "./zen-packages:/aidbox-project/zen-packages"
env_file:
- .env
environment:
BOX_PROJECT_GIT_TARGET__PATH: /aidbox-project
AIDBOX_ZEN_ENTRYPOINT: main/box
AIDBOX_DEV_MODE: "true"
AIDBOX_ZEN_DEV_MODE: "true"
PGPORT: 5432
PGHOST: aidbox-db
9 changes: 8 additions & 1 deletion routes/get.clj
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
[:div "root page"]
[:html
[:h1 "UI operations"]

(for [op (map :resource (box/sql "select * from operation where id like 'aidbox-%'"))]
[:div
(str (:request op))])

]
1 change: 0 additions & 1 deletion routes/ui/audit-officer/events_get.clj

This file was deleted.

6 changes: 6 additions & 0 deletions routes/ui/chat/$new_post.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(box/create
{:resourceType "Chat"
:participants [{:id (:id (auth/user-info))
:resourceType "User"}]})

(box/redirect "/ui/chat")
5 changes: 0 additions & 5 deletions routes/ui/chat/$send-message_post.clj

This file was deleted.

25 changes: 25 additions & 0 deletions routes/ui/chat/:id_$send-message_post.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(box/set-header! "Content-Type" "text/vnd.turbo-stream.html; charset=utf-8")

(when (nil? (box/read {:id (:id (box/route-params)) :resourceType "Chat"}))
(throw (ex-info "Not found" {:id (:id (box/route-params)) :resourceType "Chat"})))

(box/create {:resourceType "ChatMessage"
:chat {:id (:id (box/route-params)) :resourceType "Chat"}
:author {:id (:id (auth/user-info)) :resourceType "User"}
:message (:message (box/form-params))})

[:<>

[:turbo-stream {:action "append" :target "chat"}
[:template
[:div [:span {:style "font-weight: bold;"} (:id (auth/user-info)) ": "]
(:message (box/form-params))]]]

[:turbo-stream {:action "replace" :target "chat-form"}
[:template
[:turbo-frame {:id "chat-form"}
[:form {:action "/ui/chat/$send-message" :method "post"}
[:input {:name "message"}]
[:button "Send"]]]]]

]
77 changes: 48 additions & 29 deletions routes/ui/chat/:id_get.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
(if (nil? (auth/user-info))
(box/redirect "/ui/chat/login")
(box/redirect "/ui/auth/login")

[:html
[:meta {:charset "UTF-8"}]
[:meta
{:name "viewport", :content "width=device-width, initial-scale=1.0"}]
[:title "Chat"]
[:meta {:name "viewport", :content "width=device-width, initial-scale=1.0"}]
[:title "Chat App"]

#_[:script {:src "https://cdn.tailwindcss.com"}]

[:script {:type "module" :src "https://unpkg.com/@hotwired/[email protected]/dist/turbo.es2017-esm.js"}]
[:script {:src "/ui/$dev-mode"}]

[:div "User: " (:id (auth/user-info))
[:form {:method "POST" :action "/ui/auth/logout"
:style "display: inline; margin-left: 8px"}
[:input {:type "hidden" :name "_csrf" :value (auth/csrf)}]
[:button "Sign out"]]
[:hr]]

[:div "id: " (:id (box/route-params))]

[:h1 "Chat"]

(let [messages (map :resource (box/sql ["select resource || jsonb_build_object('id', id) resource from chatmessage where resource#>>'{chat,id}' = ?" (:id (box/route-params))]))]
[:turbo-frame {:id "chat"}
(for [msg messages]
[:div [:span {:style "font-weight: bold;"} (:id (auth/user-info)) ": "]
(:message msg)])])

[:turbo-frame {:id "chat-form"}
[:form {:action (format "/ui/chat/%s/$send-message" (:id (box/route-params))) :method "post"}
#_[:input {:name "chat-id" :type "hidden" :value (:id (box/route-params))}]
[:input {:name "message"}]
[:button "Send"]]]

[:div
[:hr]
[:div {:style "font-family: monospace"} (format "Aidbox version %s" (box/version))]]
])

#_(if (nil? (auth/user-info))
(box/redirect "/ui/auth/login")

[:html
[:meta {:charset "UTF-8"}]
[:meta {:name "viewport", :content "width=device-width, initial-scale=1.0"}]
[:title "Chat..."]

[:script {:src "https://cdn.tailwindcss.com"}]

[:script {:type "module" :src "https://unpkg.com/@hotwired/[email protected]/dist/turbo.es2017-esm.js"}]
Expand All @@ -15,6 +56,7 @@
[:div
{:class
"flex sm:items-center justify-between py-3 border-b-2 border-gray-200"}

[:div
{:class "relative flex items-center space-x-4"}
[:div
Expand All @@ -35,6 +77,7 @@
{:class "text-2xl mt-1 flex items-center"}
[:span {:class "text-gray-700 mr-3"} "Dr. Smith"]]
[:span {:class "text-lg text-gray-600"} "Therapist"]]]

[:div
{:class "flex items-center space-x-2"}
[:button
Expand Down Expand Up @@ -360,32 +403,8 @@
[:path
{:d
"M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z"}]]]]]]]

[:style
".scrollbar-w-2::-webkit-scrollbar {\n width: 0.25rem;\n height: 0.25rem;\n }\n\n .scrollbar-track-blue-lighter::-webkit-scrollbar-track {\n --bg-opacity: 1;\n background-color: #f7fafc;\n background-color: rgba(247, 250, 252, var(--bg-opacity));\n }\n\n .scrollbar-thumb-blue::-webkit-scrollbar-thumb {\n --bg-opacity: 1;\n background-color: #edf2f7;\n background-color: rgba(237, 242, 247, var(--bg-opacity));\n }\n\n .scrollbar-thumb-rounded::-webkit-scrollbar-thumb {\n border-radius: 0.25rem;\n }"]
[:script
"const el = document.getElementById('messages')\n el.scrollTop = el.scrollHeight"]])


#_[:html
#_[:script {:type "module"}
"import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';"]

[:script {:type "module" :src "https://unpkg.com/@hotwired/[email protected]/dist/turbo.es2017-esm.js"}]

[:script {:src "/ui/$dev-mode"}]


[:form {:method "POST" :action "/ui/chat/logout"}
[:input {:type "hidden" :name "_csrf" :value (auth/csrf)}]
[:button "Sign out"]]

[:div "chat"]

[:turbo-frame {:id "chat"}
[:div "message"]]

[:turbo-frame {:id "chat-form"}
[:form {:action "/ui/chat/$send-message" :method "post"}
[:button "Generate new message"]]]

]
Loading

0 comments on commit e2e11af

Please sign in to comment.