Skip to content

Commit

Permalink
replace supabase injection with runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 16, 2024
1 parent c98a27f commit 62ebbcd
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/agents/cj/actions/__tests__/introduce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("Introduce Action", () => {
);

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/agents/cj/actions/introduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

if (responseData?.userA && responseData.userB) {
await createRelationship({
supabase: runtime.supabase,
runtime,
userA: responseData.userA,
userB: responseData.userB,
});
Expand Down
2 changes: 1 addition & 1 deletion src/agents/cj/evaluators/__tests__/details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("User Details", () => {
);

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/agents/cj/evaluators/__tests__/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("User Profile", () => {
);

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/agents/cj/evaluators/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const handler = async (runtime: BgentRuntime, message: Message) => {

// find the room_id in 'relationships' where user_a is the agent and user_b is the user, OR vice versa
const relationshipRecord = await getRelationship({
supabase: runtime.supabase,
runtime,
userA,
userB,
});
Expand Down
108 changes: 97 additions & 11 deletions src/lib/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import dotenv from "dotenv";
import { createRuntime } from "../../test/createRuntime";
import { getRelationship } from "../relationships";
import { type BgentRuntime } from "../runtime";
import { populateMemories } from "../../test/populateMemories";

dotenv.config();

Expand All @@ -13,7 +12,7 @@ const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID;
describe("Actions", () => {
let user: User;
let runtime: BgentRuntime;
let room_id: UUID;
// let room_id: UUID;

afterAll(async () => {
await cleanup();
Expand All @@ -24,13 +23,13 @@ describe("Actions", () => {
user = setup.session.user;
runtime = setup.runtime;

const data = await getRelationship({
supabase: runtime.supabase,
userA: user?.id as UUID,
userB: zeroUuid,
});
// const data = await getRelationship({
// runtime,
// userA: user?.id as UUID,
// userB: zeroUuid,
// });

room_id = data?.room_id;
// room_id = data?.room_id;

await cleanup();
});
Expand All @@ -46,9 +45,96 @@ describe("Actions", () => {
]);
}

// TODO: 1. Test that actions are being loaded into context properly
describe("Actions", () => {
let user: User;
let runtime: BgentRuntime;
let room_id: UUID;

afterAll(async () => {
await cleanup();
});

beforeAll(async () => {
const setup = await createRuntime();
user = setup.session.user;
runtime = setup.runtime;

// TODO: 2. Test that actions are validated properply, for example we know that the continue action is always valid
const data = await getRelationship({
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});

room_id = data?.room_id;

await cleanup();
});

// TODO 3. Test that action handlers are being called properly
async function cleanup() {
await runtime.summarizationManager.removeAllMemoriesByUserIds([
user?.id as UUID,
zeroUuid,
]);
await runtime.messageManager.removeAllMemoriesByUserIds([
user?.id as UUID,
zeroUuid,
]);
}

// Test that actions are being loaded into context properly
test("Actions are loaded into context", async () => {
const actions = runtime.getActions();
expect(actions).toBeDefined();
expect(actions.length).toBeGreaterThan(0);
// Ensure the CONTINUE action is part of the loaded actions
const continueAction = actions.find(
(action) => action.name === "CONTINUE",
);
expect(continueAction).toBeDefined();
});

// Test that actions are validated properly
test("Continue action is always valid", async () => {
const continueAction = runtime
.getActions()
.find((action) => action.name === "CONTINUE");
expect(continueAction).toBeDefined();
if (continueAction && continueAction.validate) {
const isValid = await continueAction.validate(runtime, {
agentId: zeroUuid,
senderId: user.id as UUID,
userIds: [user.id as UUID, zeroUuid],
content: "Test message",
room_id: room_id,
});
expect(isValid).toBeTruthy();
} else {
throw new Error(
"Continue action or its validation function is undefined",
);
}
});

// Test that action handlers are being called properly
test("Continue action handler is called", async () => {
const continueAction = runtime
.getActions()
.find((action) => action.name === "CONTINUE");
expect(continueAction).toBeDefined();
if (continueAction && continueAction.handler) {
const mockMessage = {
agentId: zeroUuid,
senderId: user.id as UUID,
userIds: [user.id as UUID, zeroUuid],
content: "Test message for CONTINUE action",
room_id: room_id,
};
const response = await continueAction.handler(runtime, mockMessage);
expect(response).toBeDefined();
// Further assertions can be made based on the expected outcome of the CONTINUE action handler
} else {
throw new Error("Continue action or its handler function is undefined");
}
}, 20000);
});
});
6 changes: 3 additions & 3 deletions src/lib/__tests__/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Memory", () => {
user = result.session.user;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down Expand Up @@ -208,7 +208,7 @@ describe("Memory - Basic tests", () => {
user = result.session.user;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down Expand Up @@ -298,7 +298,7 @@ describe("Memory - Extended Tests", () => {
user = result.session.user;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user.id as UUID,
userB: zeroUuid,
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ describe("Messages Library", () => {
runtime = setup.runtime;
user = setup.session.user;
actors = await getMessageActors({
supabase: runtime.supabase,
runtime,
userIds: [user.id as UUID, "00000000-0000-0000-0000-000000000000"],
});
});

test("getMessageActors should return actors based on given userIds", async () => {
const result = await getMessageActors({
supabase: runtime.supabase,
runtime,
userIds: [user.id as UUID, "00000000-0000-0000-0000-000000000000"],
});
expect(result.length).toBeGreaterThan(0);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/__tests__/relationships.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("Relationships Module", () => {
const userB = zeroUuid;

const relationship = await createRelationship({
supabase: runtime.supabase,
runtime,
userA,
userB,
});
Expand All @@ -40,10 +40,10 @@ describe("Relationships Module", () => {
const userA = user?.id as UUID;
const userB = zeroUuid;

await createRelationship({ supabase: runtime.supabase, userA, userB });
await createRelationship({ runtime, userA, userB });

const relationship = await getRelationship({
supabase: runtime.supabase,
runtime,
userA,
userB,
});
Expand All @@ -56,10 +56,10 @@ describe("Relationships Module", () => {
const userA = user?.id as UUID;
const userB = zeroUuid;

await createRelationship({ supabase: runtime.supabase, userA, userB });
await createRelationship({ runtime, userA, userB });

const relationships = await getRelationships({
supabase: runtime.supabase,
runtime,
userId: userA,
});
expect(relationships).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Agent Runtime", () => {
user = result.session.user;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/actions/__tests__/continue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("User Profile", () => {
runtime = setup.runtime;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user.id,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/actions/__tests__/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("Ignore action tests", () => {
runtime = setup.runtime;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/actions/__tests__/wait.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("Wait Action Behavior", () => {
runtime = setup.runtime;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/evaluators/__tests__/summarization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Factual Summarization", () => {
runtime = setup.runtime;

const data = await getRelationship({
supabase: runtime.supabase,
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});
Expand Down
3 changes: 1 addition & 2 deletions src/lib/evaluators/summarization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ async function handler(runtime: BgentRuntime, message: Message) {

const { userIds, senderId, agentId, room_id } = state;

const actors =
(await getMessageActors({ supabase: runtime.supabase, userIds })) ?? [];
const actors = (await getMessageActors({ runtime, userIds })) ?? [];

const senderName = actors?.find(
(actor: Actor) => actor.id === senderId,
Expand Down
Loading

0 comments on commit 62ebbcd

Please sign in to comment.