Skip to content

Commit

Permalink
fix rls and worker agent issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 9, 2024
1 parent 7fd9da6 commit 82895b7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 0 additions & 2 deletions packages/agent/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ export const onMessage = async (message: any, runtime: AgentRuntime) => {
addCustomActions(runtime);
addCustomEvaluators(runtime);

console.log('message is', message)

let {
content: senderContent,
senderId,
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/lib/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class MemoryManager {
count = defaultMatchCount,
userIds = [],
} = opts
console.log('embedding', embedding)

const result = await this.runtime.supabase.rpc('search_memories', {
query_table_name: this.schema.tableName,
query_user_ids: userIds,
Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/Hooks/rooms/useListenToMessagesChanges.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSupabaseClient } from "@supabase/auth-helpers-react";
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
import { useEffect } from "react";
import { showNotification } from "@mantine/notifications";
import { Database } from "../../../types/database.types";
Expand All @@ -19,6 +19,7 @@ const useListenToMessagesChanges = ({ getRoomData }: Props) => {
user: { uid },
currentRoom: { roomData },
} = useGlobalStore();
const session = useSession();

useEffect(() => {
const channel = supabase
Expand Down Expand Up @@ -108,6 +109,8 @@ const useListenToMessagesChanges = ({ getRoomData }: Props) => {
)
.subscribe();

supabase.realtime.accessToken = session?.access_token as any; // THIS IS REQUIRED FOR RLS!!!

return () => {
channel.unsubscribe();
};
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/Hooks/rooms/useListenToUnreadMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const useListenToUnreadMessagesChanges = () => {
)
.subscribe();

supabase.realtime.accessToken = session?.access_token; // THIS IS REQUIRED FOR RLS!!!

// eslint-disable-next-line consistent-return
return () => {
channel.unsubscribe();
Expand Down
1 change: 1 addition & 0 deletions packages/shell/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async function startApplication() {

// get the room_id from the data
const room_id = data[0].id
supabase.realtime.accessToken = session?.access_token; // THIS IS REQUIRED FOR RLS!!!

// Listen to the 'messages' table for new messages in the specific room
const channel = supabase
Expand Down
8 changes: 3 additions & 5 deletions packages/worker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ server.registerHandler({
if (req.method === 'OPTIONS') {
return
}
console.log('responding')
console.log('userId', userId)


// parse the body from the request
const body = await req.json();

Expand All @@ -155,14 +153,14 @@ server.registerHandler({
if(!body.userIds) {
body.userIds = [body.senderId, body.agentId];
}
console.log('calling onMessage')

try {
await onMessage(body, runtime);
} catch (error ){
console.error('error', error)
return new Response(error, { status: 500 });
}
console.log('done')

return new Response('ok', { status: 200 });
}
});
Expand Down

0 comments on commit 82895b7

Please sign in to comment.