Skip to content

Commit

Permalink
Add error handling for goals so we know why things are failing
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Mar 20, 2024
1 parent 40f8a50 commit 1c5f7fc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bgent",
"version": "0.0.46",
"version": "0.1.1",
"private": false,
"description": "bgent. because agent was taken.",
"type": "module",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/__tests__/goals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe("Goals", () => {
onlyInProgress: false,
});

console.log("goals", goals);

const createdGoal = goals.find((goal: Goal) => goal.name === newGoal.name);

expect(createdGoal).toBeDefined();
Expand Down
1 change: 1 addition & 0 deletions src/lib/__tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe("Messages Library", () => {
});

test("formatActors should format actors into a readable string", () => {
console.log("ACTORS:", actors)
const formattedActors = formatActors({ actors });
actors.forEach((actor) => {
expect(formattedActors).toContain(actor.name);
Expand Down
23 changes: 15 additions & 8 deletions src/lib/adapters/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
.select(
`
participants:participants!inner(
user_id:accounts(id, name, details)
account:accounts(id, name, details)
)
`,
)
Expand All @@ -59,7 +59,7 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
return data
.map((room) =>
room.participants.map((participant) => {
const user = participant.user_id[0]; // Assuming user_id is an array with a single object
const user = participant.account as unknown as Actor;
return {
name: user?.name,
details: user?.details,
Expand Down Expand Up @@ -235,10 +235,7 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
}
}

async removeAllMemories(
room_id: UUID,
tableName: string,
): Promise<void> {
async removeAllMemories(room_id: UUID, tableName: string): Promise<void> {
const result = await this.supabase.rpc("remove_memories", {
query_table_name: tableName,
query_room_id: room_id,
Expand Down Expand Up @@ -294,11 +291,21 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
}

async updateGoal(goal: Goal): Promise<void> {
await this.supabase.from("goals").update(goal).match({ id: goal.id });
const { error } = await this.supabase
.from("goals")
.update(goal)
.match({ id: goal.id });
if (error) {
throw new Error(`Error creating goal: ${error.message}`);
}
}

async createGoal(goal: Goal): Promise<void> {
await this.supabase.from("goals").upsert(goal);
console.log("inserting goal:", goal);
const { error } = await this.supabase.from("goals").insert(goal);
if (error) {
throw new Error(`Error creating goal: ${error.message}`);
}
}

async removeGoal(goalId: UUID): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions supabase/migrations/20240318103238_remote_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ CREATE TABLE IF NOT EXISTS "public"."goals" (
"user_id" "uuid",
"room_id" "uuid",
"status" "text",
"name" "text",
"objectives" "jsonb"[] DEFAULT '{}'::"jsonb"[] NOT NULL
);

Expand Down

0 comments on commit 1c5f7fc

Please sign in to comment.