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

[TSK-161] Setup Websat Repo #8

Merged
merged 9 commits into from
Aug 4, 2024
Merged
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
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ NEXTAUTH_URL="http://localhost:3000"
# Next Auth Credentials Provider
PRIMARY_USER_USERNAME="admin"
PRIMARY_USER_PASSWORD="admin"
SECONDARY_USER_USERNAME="guest"
SECONDARY_USER_PASSWORD="guest"

# Kernel Planckster Config
KP_HOST="http://localhost:8000"
Expand Down
19 changes: 19 additions & 0 deletions @types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import NextAuth from "next-auth"
import type { TSession } from "~/lib/core/entity/auth/session"
/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module "next-auth" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Session extends TSession { }

// Optionally, override the User type
// interface User {
// // ...other properties
// role: "user" | "admin";
// }
}
104 changes: 90 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,32 @@
"build": "next build",
"dev": "next dev",
"lint": "next lint",
"start": "next start"
"start": "next start",
"test": "vitest --run --coverage",
"test:ui": "vitest --run --coverage --project ui",
"test:gateway": "vitest --run --coverage --project gateway",
"test:server": "vitest --run --coverage --project server",
"test:client": "vitest --run --coverage --project client"
},
"dependencies": {
"@maany_shr/kernel-planckster-sdk-ts": "^1.0.0-alpha",
"@maany_shr/planckster-ui-kit": "^1.0.0-alpha",
"@preact/signals-react": "^2.1.0",
"@t3-oss/env-nextjs": "^0.9.2",
"@tanstack/react-query": "^5.25.0",
"@tanstack/react-query-devtools": "^5.51.21",
"@trpc/client": "next",
"@trpc/next": "next",
"@trpc/react-query": "next",
"@trpc/server": "next",
"inversify": "^6.0.2",
"next": "^14.1.3",
"next-auth": "^4.24.6",
"node-fetch": "^3.3.2",
"openai": "^4.33.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"reflect-metadata": "^0.2.2",
"server-only": "^0.0.1",
"superjson": "^2.2.1",
"zod": "^3.22.4"
Expand Down
106 changes: 52 additions & 54 deletions src/app/[rc_id]/conversations/[conv_id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,67 @@
import { getServerAuthSession } from "~/server/auth";
import { api } from "~/trpc/server";
import { env } from "~/env";
import { redirect } from "next/navigation";

import { ListMessagesPage } from "../../../_components/list-messages";
import type { ChatMessageProps } from "@maany_shr/planckster-ui-kit";
import { DummySendMessage } from "~/app/_components/dummy-send-message";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import { GATEWAYS, TRPC } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";
import type { TServerComponentAPI } from "~/lib/infrastructure/server/trpc/server-api";

export default async function Home(
{ params }: { params: { conv_id: string } }
) {
const session = await getServerAuthSession();
if (!session?.user) {
redirect("/auth/login");
};
return (
<ListMessages conv_id={params.conv_id} />
export default async function Home({
params,
}: {
params: { conv_id: string };
}) {
const authGateway = serverContainer.get<AuthGatewayOutputPort>(
GATEWAYS.AUTH_GATEWAY,
);
const sessionDTO = await authGateway.getSession();
if (!sessionDTO.success) {
redirect("/auth/login");
}
return <ListMessages conv_id={params.conv_id} />;
}

async function ListMessages({ conv_id }: { conv_id: string }) {
const api: TServerComponentAPI = serverContainer.get(TRPC.REACT_SERVER_COMPONENTS_API);
const conv_id_int = parseInt(conv_id);
const messages = await api.kernel.message.list({
conversationId: conv_id_int,
xAuthToken: env.KP_AUTH_TOKEN,
});

const conv_id_int = parseInt(conv_id);

const session = await getServerAuthSession();
if (!session?.user) return null;

const messages = await api.message.list(
{ conversationId: conv_id_int, xAuthToken: env.KP_AUTH_TOKEN },
);

//const cmProps: ChatMessageProps[] = []
//const cmProps: ChatMessageProps[] = []

//for (const message of messages) {
//for (const message of messages) {

//const role = message.sender_type === "user" ? "user" : "llm"
//const role = message.sender_type === "user" ? "user" : "llm"

//const cmProp: ChatMessageProps = {
//senderName: message.sender,
//message: message.content,
//sentTime: message.timestamp,
//role: role
//}
//const cmProp: ChatMessageProps = {
//senderName: message.sender,
//message: message.content,
//sentTime: message.timestamp,
//role: role
//}

//cmProps.push(cmProp)
//}
//<ListMessagesPage chatMessageProps={cmProps}
///>
//cmProps.push(cmProp)
//}
//<ListMessagesPage chatMessageProps={cmProps}
///>

return (
<div>
<ul>
{messages.map((msg, index) => (
<li key={index}>
{`sender: ${msg.sender} ::: content: ${msg.content}`}
</li>
))}
</ul>
<DummySendMessage
conversationId={conv_id_int}
xAuthToken={env.KP_AUTH_TOKEN}
messageContent="This is a hard-coded test message from websat planckster. Now greet me"
/>
</div>
);


}
return (
<div>
<ul>
{messages.map((msg, index) => (
<li key={index}>
{`sender: ${msg.sender} ::: content: ${msg.content}`}
</li>
))}
</ul>
<DummySendMessage
conversationId={conv_id_int}
xAuthToken={env.KP_AUTH_TOKEN}
messageContent="This is a hard-coded test message from websat planckster. Now greet me"
/>
</div>
);
}
Loading
Loading