feat: add avatar (#47)
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { type LoaderFunctionArgs, type MetaFunction } from '@remix-run/cloudflare';
|
||||
import { json, type LoaderFunctionArgs, type MetaFunction } from '@remix-run/cloudflare';
|
||||
import { ClientOnly } from 'remix-utils/client-only';
|
||||
import { BaseChat } from '~/components/chat/BaseChat';
|
||||
import { Chat } from '~/components/chat/Chat.client';
|
||||
import { Header } from '~/components/header/Header';
|
||||
import { handleAuthRequest } from '~/lib/.server/login';
|
||||
import { loadWithAuth } from '~/lib/.server/auth';
|
||||
|
||||
export const meta: MetaFunction = () => {
|
||||
return [{ title: 'Bolt' }, { name: 'description', content: 'Talk with Bolt, an AI assistant from StackBlitz' }];
|
||||
};
|
||||
|
||||
export async function loader(args: LoaderFunctionArgs) {
|
||||
return handleAuthRequest(args);
|
||||
return loadWithAuth(args, async (_args, session) => json({ avatar: session.avatar }));
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { json, type ActionFunctionArgs } from '@remix-run/cloudflare';
|
||||
import { handleWithAuth } from '~/lib/.server/login';
|
||||
import { getSessionData } from '~/lib/.server/sessions';
|
||||
import { actionWithAuth } from '~/lib/.server/auth';
|
||||
import type { Session } from '~/lib/.server/sessions';
|
||||
import { sendEventInternal, type AnalyticsEvent } from '~/lib/analytics';
|
||||
|
||||
async function analyticsAction({ request, context }: ActionFunctionArgs) {
|
||||
async function analyticsAction({ request }: ActionFunctionArgs, session: Session) {
|
||||
const event: AnalyticsEvent = await request.json();
|
||||
const sessionData = await getSessionData(request, context.cloudflare.env);
|
||||
const { success, error } = await sendEventInternal(sessionData, event);
|
||||
const { success, error } = await sendEventInternal(session, event);
|
||||
|
||||
if (!success) {
|
||||
return json({ error }, { status: 500 });
|
||||
@@ -16,5 +15,5 @@ async function analyticsAction({ request, context }: ActionFunctionArgs) {
|
||||
}
|
||||
|
||||
export async function action(args: ActionFunctionArgs) {
|
||||
return handleWithAuth(args, analyticsAction);
|
||||
return actionWithAuth(args, analyticsAction);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { type ActionFunctionArgs } from '@remix-run/cloudflare';
|
||||
import { actionWithAuth } from '~/lib/.server/auth';
|
||||
import { MAX_RESPONSE_SEGMENTS, MAX_TOKENS } from '~/lib/.server/llm/constants';
|
||||
import { CONTINUE_PROMPT } from '~/lib/.server/llm/prompts';
|
||||
import { streamText, type Messages, type StreamingOptions } from '~/lib/.server/llm/stream-text';
|
||||
import SwitchableStream from '~/lib/.server/llm/switchable-stream';
|
||||
import { handleWithAuth } from '~/lib/.server/login';
|
||||
import { getSessionData } from '~/lib/.server/sessions';
|
||||
import type { Session } from '~/lib/.server/sessions';
|
||||
import { AnalyticsAction, AnalyticsTrackEvent, sendEventInternal } from '~/lib/analytics';
|
||||
|
||||
export async function action(args: ActionFunctionArgs) {
|
||||
return handleWithAuth(args, chatAction);
|
||||
return actionWithAuth(args, chatAction);
|
||||
}
|
||||
|
||||
async function chatAction({ context, request }: ActionFunctionArgs) {
|
||||
async function chatAction({ context, request }: ActionFunctionArgs, session: Session) {
|
||||
const { messages } = await request.json<{ messages: Messages }>();
|
||||
|
||||
const stream = new SwitchableStream();
|
||||
@@ -21,9 +21,7 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
|
||||
toolChoice: 'none',
|
||||
onFinish: async ({ text: content, finishReason, usage }) => {
|
||||
if (finishReason !== 'length') {
|
||||
const sessionData = await getSessionData(request, context.cloudflare.env);
|
||||
|
||||
await sendEventInternal(sessionData, {
|
||||
await sendEventInternal(session, {
|
||||
action: AnalyticsAction.Track,
|
||||
payload: {
|
||||
event: AnalyticsTrackEvent.MessageComplete,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { type ActionFunctionArgs } from '@remix-run/cloudflare';
|
||||
import { StreamingTextResponse, parseStreamPart } from 'ai';
|
||||
import { actionWithAuth } from '~/lib/.server/auth';
|
||||
import { streamText } from '~/lib/.server/llm/stream-text';
|
||||
import { handleWithAuth } from '~/lib/.server/login';
|
||||
import { stripIndents } from '~/utils/stripIndent';
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
export async function action(args: ActionFunctionArgs) {
|
||||
return handleWithAuth(args, enhancerAction);
|
||||
return actionWithAuth(args, enhancerAction);
|
||||
}
|
||||
|
||||
async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { LoaderFunctionArgs } from '@remix-run/cloudflare';
|
||||
import { json, type LoaderFunctionArgs } from '@remix-run/cloudflare';
|
||||
import { default as IndexRoute } from './_index';
|
||||
import { handleAuthRequest } from '~/lib/.server/login';
|
||||
import { loadWithAuth } from '~/lib/.server/auth';
|
||||
|
||||
export async function loader(args: LoaderFunctionArgs) {
|
||||
return handleAuthRequest(args, { id: args.params.id });
|
||||
return loadWithAuth(args, async (_args, session) => json({ id: args.params.id, avatar: session.avatar }));
|
||||
}
|
||||
|
||||
export default IndexRoute;
|
||||
|
||||
@@ -16,9 +16,9 @@ import { auth, type AuthAPI } from '~/lib/webcontainer/auth.client';
|
||||
import { logger } from '~/utils/logger';
|
||||
|
||||
export async function loader({ request, context }: LoaderFunctionArgs) {
|
||||
const { authenticated, response } = await isAuthenticated(request, context.cloudflare.env);
|
||||
const { session, response } = await isAuthenticated(request, context.cloudflare.env);
|
||||
|
||||
if (authenticated) {
|
||||
if (session != null) {
|
||||
return redirect('/', response);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user