feat(session): encrypt data and fix renewal (#38)

This commit is contained in:
Roberto Vidal
2024-08-19 17:39:37 +02:00
committed by GitHub
parent b939a0af2d
commit 44226db359
6 changed files with 170 additions and 50 deletions

View File

@@ -1,12 +1,12 @@
import { json, type ActionFunctionArgs } from '@remix-run/cloudflare';
import { handleWithAuth } from '~/lib/.server/login';
import { getSession } from '~/lib/.server/sessions';
import { getSessionData } from '~/lib/.server/sessions';
import { sendEventInternal, type AnalyticsEvent } from '~/lib/analytics';
async function analyticsAction({ request, context }: ActionFunctionArgs) {
const event: AnalyticsEvent = await request.json();
const { session } = await getSession(request, context.cloudflare.env);
const { success, error } = await sendEventInternal(session.data, event);
const sessionData = await getSessionData(request, context.cloudflare.env);
const { success, error } = await sendEventInternal(sessionData, event);
if (!success) {
return json({ error }, { status: 500 });

View File

@@ -4,7 +4,7 @@ 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 { getSession } from '~/lib/.server/sessions';
import { getSessionData } from '~/lib/.server/sessions';
import { AnalyticsAction, AnalyticsTrackEvent, sendEventInternal } from '~/lib/analytics';
export async function action(args: ActionFunctionArgs) {
@@ -21,9 +21,9 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
toolChoice: 'none',
onFinish: async ({ text: content, finishReason, usage }) => {
if (finishReason !== 'length') {
const { session } = await getSession(request, context.cloudflare.env);
const sessionData = await getSessionData(request, context.cloudflare.env);
await sendEventInternal(session.data, {
await sendEventInternal(sessionData, {
action: AnalyticsAction.Track,
payload: {
event: AnalyticsTrackEvent.MessageComplete,