Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sso #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ NEXT_PUBLIC_URL=http://localhost:80/chat
NEXT_PUBLIC_URL_2=https://dce9-34-69-225-84.ngrok-free.app/phogpt_stream_chat
NEXT_PUBLIC_URL_3=https://dce9-34-69-225-84.ngrok-free.app/llama_stream_chat

NEXT_PUBLIC_AUTH=http://localhost:80
NEXT_PUBLIC_AUTH=http://localhost:80
NEXT_PUBLIC_KEYCLOAK=http://13.213.77.182
2 changes: 1 addition & 1 deletion Frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
reactStrictMode: false,
}

module.exports = nextConfig
4 changes: 4 additions & 0 deletions Frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
},
"dependencies": {
"@radix-ui/react-scroll-area": "^1.0.5",
"@react-keycloak/ssr": "^3.3.0",
"axios": "^1.6.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cookie": "^0.6.0",
"keycloak-js": "11.0.2",
"lucide-react": "^0.293.0",
"next": "14.0.3",
"react": "^18",
Expand All @@ -22,6 +25,7 @@
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/cookie": "^0.6.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
45 changes: 41 additions & 4 deletions Frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import "@/styles/globals.css";
import type { AppProps, AppContext } from "next/app";
import cookie from "cookie";
import { SSRKeycloakProvider, SSRCookies } from "@react-keycloak/ssr";
import type { IncomingMessage } from "http";

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
const keycloakCfg = {
url: process.env.NEXT_PUBLIC_KEYCLOAK,
realm: "sso",
clientId: "chatbot-dulich",
};

interface InitialProps {
cookies: unknown;
}

function App({ Component, pageProps, cookies }: AppProps & InitialProps) {
return (
<SSRKeycloakProvider
keycloakConfig={keycloakCfg}
persistor={SSRCookies(cookies)}
initOptions={{onLoad: "login-required"}}
>
<Component {...pageProps} />
</SSRKeycloakProvider>
);
}

function parseCookies(req?: IncomingMessage) {
if (!req || !req.headers) {
return {};
}
return cookie.parse(req.headers.cookie || "");
}

App.getInitialProps = async (context: AppContext) => {
// Extract cookies from AppContext
return {
cookies: parseCookies(context?.ctx?.req),
};
};

export default App;
22 changes: 14 additions & 8 deletions Frontend/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Inter } from "next/font/google"
import Input from "@/components/components/Input"
import ConversationItem from "./../components/components/ConversationItem"
import { useState, useRef, useEffect } from "react"
import { useCheckAuth } from "@/api/checkAuth"
import { useRouter } from "next/navigation"
import { useGetListSession } from "@/api/getListSession"
import { saveHistory } from "@/api/saveHistory"
import { newSession } from "@/api/newSession"
import { useGetOldHistory } from "@/api/getOldSessionHistory"
import { useKeycloak } from "@react-keycloak/ssr";

const inter = Inter({ subsets: ["latin"] })

Expand All @@ -17,15 +17,16 @@ const modals = [
{ label: "PhoGPT", link: process.env.NEXT_PUBLIC_URL_2 }
]


export default function Home() {
const router = useRouter()
const { data, isLoading, status } = useCheckAuth()
const { keycloak } = useKeycloak()

const [sessionId, setSessionId] = useState({
sessionId: null,
isInit: true
})
const { data: listSession } = useGetListSession(
data?.data?.id,
keycloak?.idTokenParsed?.sub,
sessionId.sessionId
)
const [input, setInput] = useState("")
Expand Down Expand Up @@ -186,19 +187,23 @@ export default function Home() {
console.log(err)
}
}
if (!isLoading && !data?.data?.id) {
router.push("/sign-in")
}

return (
<main className="flex bg-[#343541]">
<div className="h-screen no-scrollbar overflow-y-scroll pl-3 pt-10 w-[200px] flex flex-col gap-4">
<button
onClick={createNewSession(data?.data?.id)}
onClick={createNewSession(keycloak?.idTokenParsed?.sub)}
className="px-3 py-2 mb-5 bg-gray-800 rounded-2xl hover:!bg-gray-400"
>
Create new session
</button>
<div></div>
<button
className="px-3 py-3 mt-10 bg-gray-800 rounded-2xl hover:!bg-gray-400"
onClick={() => location.replace(`${process.env.NEXT_PUBLIC_KEYCLOAK}/realms/sso/protocol/openid-connect/logout?client_id=chatbot-dulich&post_logout_redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F&id_token_hint=${keycloak?.idToken}`)}
>
Logout
</button>
{listSession?.data?.session_ids?.map((session, index) => (
<button
key={index}
Expand Down Expand Up @@ -230,6 +235,7 @@ export default function Home() {
<a href="http://localhost:5000/">Map</a>
</button>
<div className="flex-1 mb-[148px] w-full">

{conversations?.[modal]?.map((conversation, index) => (
<ConversationItem
key={index}
Expand Down
83 changes: 82 additions & 1 deletion Frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.9.0":
version "7.23.7"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.7.tgz#dd7c88deeb218a0f8bd34d5db1aa242e0f203193"
integrity sha512-w06OXVOFso7LcbzMiDGt+3X7Rh7Ho8MmgPoWU3rarH+8upf+wSU/grlGbWzQyr3DkdN6ZeuMFjpdwW0Q+HxobA==
dependencies:
regenerator-runtime "^0.14.0"

"@eslint-community/eslint-utils@^4.2.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59"
Expand Down Expand Up @@ -270,6 +277,25 @@
dependencies:
"@babel/runtime" "^7.13.10"

"@react-keycloak/core@^3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@react-keycloak/core/-/core-3.2.0.tgz#e46f1951b0d7873f7f2fcd73dd0c270cb0b18db8"
integrity sha512-1yzU7gQzs+6E1v6hGqxy0Q+kpMHg9sEcke2yxZR29WoU8KNE8E50xS6UbI8N7rWsgyYw8r9W1cUPCOF48MYjzw==
dependencies:
react-fast-compare "^3.2.0"

"@react-keycloak/ssr@^3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@react-keycloak/ssr/-/ssr-3.3.0.tgz#e757a686efd3156ecfa3a73b03b2ebb97eeea03c"
integrity sha512-S+QArvPgM34rb84M7/+0jf2nSxOzG3vrAwkuaiXb19FosomMSYBaTrpPjXS45eUzHQuX4IOWdUTx9SZY4EmLTw==
dependencies:
"@babel/runtime" "^7.9.0"
"@react-keycloak/core" "^3.2.0"
detect-node "^2.0.4"
hoist-non-react-statics "^3.3.2"
js-base64 "^3.4.5"
js-cookie "^2.2.1"

"@rushstack/eslint-patch@^1.3.3":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.6.0.tgz#1898e7a7b943680d757417a47fb10f5fcc230b39"
Expand All @@ -282,6 +308,11 @@
dependencies:
tslib "^2.4.0"

"@types/cookie@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5"
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down Expand Up @@ -571,6 +602,11 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

[email protected]:
version "1.3.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
Expand Down Expand Up @@ -701,6 +737,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==

cookie@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051"
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==

cross-spawn@^7.0.2:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
Expand Down Expand Up @@ -772,6 +813,11 @@ dequal@^2.0.3:
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be"
integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==

detect-node@^2.0.4:
version "2.1.0"
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1"
integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==

didyoumean@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.2.tgz#989346ffe9e839b4555ecf5666edea0d3e8ad037"
Expand Down Expand Up @@ -1416,6 +1462,13 @@ hasown@^2.0.0:
dependencies:
function-bind "^1.1.2"

hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

ignore@^5.2.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.0.tgz#67418ae40d34d6999c95ff56016759c718c82f78"
Expand Down Expand Up @@ -1653,6 +1706,21 @@ jiti@^1.19.1:
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.21.0.tgz#7c97f8fe045724e136a397f7340475244156105d"
integrity sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==

js-base64@^3.4.5:
version "3.7.5"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.5.tgz#21e24cf6b886f76d6f5f165bfcd69cc55b9e3fca"
integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==

js-cookie@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.1.tgz#69e106dc5d5806894562902aa5baec3744e9b2b8"
integrity sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==

[email protected]:
version "0.9.0"
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down Expand Up @@ -1697,6 +1765,14 @@ json5@^1.0.2:
object.assign "^4.1.4"
object.values "^1.1.6"

[email protected]:
version "11.0.2"
resolved "https://registry.yarnpkg.com/keycloak-js/-/keycloak-js-11.0.2.tgz#e981c5270e72066e38b2a1bd98f1138d6cd560c1"
integrity sha512-dnvzgTetovu3eTjJtvBQQhxRN4jqvd/DaA2wFaE4aWIFXhwRcoPpZT8ZJ7MwlICDPdCgzbCsOsBjpL8CbYOZsg==
dependencies:
base64-js "1.3.1"
js-sha256 "0.9.0"

keyv@^4.5.3:
version "4.5.4"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93"
Expand Down Expand Up @@ -2124,7 +2200,12 @@ react-dom@^18:
loose-envify "^1.1.0"
scheduler "^0.23.0"

react-is@^16.13.1:
react-fast-compare@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==

react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand Down
Binary file modified ssale/agent/__pycache__/agent.cpython-311.pyc
Binary file not shown.
Binary file modified ssale/agent/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified ssale/agent/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified ssale/agent/__pycache__/tool.cpython-311.pyc
Binary file not shown.
Binary file modified ssale/agent/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file modified ssale/agent/__pycache__/views.cpython-311.pyc
Binary file not shown.
38 changes: 19 additions & 19 deletions ssale/agent/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 4.2.5 on 2023-12-22 04:24
# Generated by Django 4.2.5 on 2024-01-02 03:40

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

Expand All @@ -14,6 +13,24 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='ChatSession',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start_time', models.DateTimeField(auto_now_add=True)),
('end_time', models.DateTimeField(blank=True, null=True)),
('data', models.TextField(default='[]')),
('user_id', models.CharField(max_length=255, unique=True)),
],
),
migrations.CreateModel(
name='Message',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data', models.TextField(default='')),
('session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_sessions', to='agent.chatsession')),
],
),
migrations.CreateModel(
name='User',
fields=[
Expand All @@ -34,21 +51,4 @@ class Migration(migrations.Migration):
'abstract': False,
},
),
migrations.CreateModel(
name='ChatSession',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start_time', models.DateTimeField(auto_now_add=True)),
('end_time', models.DateTimeField(blank=True, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_sessions', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Message',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data', models.TextField(default='')),
('session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_sessions', to='agent.chatsession')),
],
),
]
18 changes: 0 additions & 18 deletions ssale/agent/migrations/0002_chatsession_data.py

This file was deleted.

Loading