Skip to content

Commit

Permalink
build and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 15, 2024
1 parent b9441d2 commit 9ca8f11
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 887 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/node_modules/*
**/coverage/*
**/dist/*
**/types/*
**/types/*
**/scripts/concatenated-output.ts
96 changes: 34 additions & 62 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,36 @@
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'
import { defineConfig } from 'rollup'
import pkg from './package.json'
import json from '@rollup/plugin-json';
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
import typescript from "@rollup/plugin-typescript";
import { defineConfig } from "rollup";
import pkg from "./package.json";

export default defineConfig([
{
input: 'src/index.ts',
output: [
{
file: pkg.unpkg,
format: 'iife',
sourcemap: true,
name: pkg.name,
},
{
file: pkg.browser,
format: 'umd',
sourcemap: true,
name: pkg.name,
},
],
plugins: [
json(),
resolve(),
commonjs(),
typescript(),
replace({
preventAssignment: true,
})
].filter(Boolean),
},
{
input: 'src/index.ts',
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
exports: 'auto',
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
},
],
plugins: [
json(),
typescript(),
replace({
__DEV__: `(process.env.NODE_ENV !== 'production')`,
preventAssignment: true,
})
].filter(Boolean),
},
])
{
input: "src/index.ts",
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
output: [
{
file: pkg.main,
format: "cjs",
sourcemap: true,
exports: "auto",
},
{
file: pkg.module,
format: "es",
sourcemap: true,
},
],
plugins: [
json(),
typescript(),
replace({
__DEV__: `(process.env.NODE_ENV !== 'production')`,
preventAssignment: true,
}),
].filter(Boolean),
},
]);
2 changes: 1 addition & 1 deletion scripts/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const SUPABASE_URL = process.env.SERVER_URL || "https://pronvzrzfwsptkojvudd.sup
const SUPABASE_ANON_KEY = process.env.SERVER_URL || "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InByb252enJ6ZndzcHRrb2p2dWRkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDY4NTYwNDcsImV4cCI6MjAyMjQzMjA0N30.I6_-XrqssUb2SWYg5DjsUqSodNS3_RPoET3-aPdqywM"
// check for --debug flag in 'node example/shell --debug'
const SERVER_URL =
process.env.SERVER_URL || dev
process.env?.SERVER_URL ?? dev
? 'http://localhost:7998'
: 'https://cojourney.shawmakesmagic.workers.dev'

Expand Down
2 changes: 2 additions & 0 deletions src/agents/cj/actions/introduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
export default {
name: "INTRODUCE",
validate: async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_runtime: BgentRuntime,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_message: Message,
): Promise<boolean> => {
return await Promise.resolve(true);
Expand Down
2 changes: 2 additions & 0 deletions src/agents/cj/evaluators/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
export default {
name: "UPDATE_DETAILS",
validate: async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_runtime: BgentRuntime,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_message: Message,
): Promise<boolean> => {
return await Promise.resolve(true);
Expand Down
2 changes: 2 additions & 0 deletions src/agents/cj/evaluators/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ const handler = async (runtime: BgentRuntime, message: Message) => {
export default {
name: "UPDATE_PROFILE",
validate: async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_runtime: BgentRuntime,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_message: Message,
): Promise<boolean> => {
// immediatel resolve true
Expand Down
5 changes: 2 additions & 3 deletions src/agents/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export { fetch as CjWorker } from "./cj";
export { fetch as SimpleWorker } from "./simple";
import { fetch as CjWorker } from "./cj";
import { fetch as SimpleWorker } from "./simple";

export default {
CjWorker,
SimpleWorker,
fetch: CjWorker,
};
33 changes: 1 addition & 32 deletions src/lib/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { type UUID } from "crypto";
import dotenv from "dotenv";
import { getCachedEmbedding, writeCachedEmbedding } from "../../test/cache";
import { createRuntime } from "../../test/createRuntime";
import { GetTellMeAboutYourselfConversationTroll1 } from "../../test/data";
import { getRelationship } from "../relationships";
import { type BgentRuntime } from "../runtime";
import { Content, type Message } from "../types";

dotenv.config();

const zeroUuid = "00000000-0000-0000-0000-000000000000";

describe("User Profile", () => {
describe("Actions", () => {
let user: User;
let runtime: BgentRuntime;
let room_id: UUID;
Expand Down Expand Up @@ -74,35 +72,6 @@ describe("User Profile", () => {
}
}

test("Action handler test: ignore", async () => {
const message: Message = {
senderId: user.id as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: "",
room_id: room_id as UUID,
};

await populateMemories([GetTellMeAboutYourselfConversationTroll1]);

const response = await runtime.handleRequest(message);

const state = await runtime.composeState(message);

console.log(
"*** recentMessagesData",
state.recentMessagesData.map((m) => m.content),
);

console.log("*** response", response);

const lastMessage = state.recentMessagesData[0];

console.log("*** lastMessage", lastMessage.content);

expect((lastMessage.content as Content).action).toBe("IGNORE");
}, 60000);

test("Action handler test: continue", async () => {
// TODO: test action handler with a message that should continue the conversation
// evaluate that the response action is a continue
Expand Down
98 changes: 95 additions & 3 deletions src/lib/actions/__tests__/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { type UUID } from "crypto";
import dotenv from "dotenv";
import { getCachedEmbedding, writeCachedEmbedding } from "../../../test/cache";
import { createRuntime } from "../../../test/createRuntime";
import {
GetTellMeAboutYourselfConversationTroll1,
GetTellMeAboutYourselfConversationTroll2,
Goodbye1,
} from "../../../test/data";
import { getRelationship } from "../../relationships";
import { type BgentRuntime } from "../../runtime";
import { type Message } from "../../types";
import { Content, type Message } from "../../types";
import action from "../continue";

dotenv.config();

const zeroUuid = "00000000-0000-0000-0000-000000000000";

describe("User Profile", () => {
let user: User | null;
let user: User;
let runtime: BgentRuntime;
let room_id: UUID | null;

Expand All @@ -23,7 +28,7 @@ describe("User Profile", () => {

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

const data = await getRelationship({
Expand Down Expand Up @@ -90,4 +95,91 @@ describe("User Profile", () => {
const result = (await handler(runtime, message)) as string[];
expect(result).toBe(true);
}, 60000);

test("Action handler test 1: response should be ignore", async () => {
const message: Message = {
senderId: user.id as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: "",
room_id: room_id as UUID,
};

await populateMemories([GetTellMeAboutYourselfConversationTroll1]);

const response = await runtime.handleRequest(message);

const state = await runtime.composeState(message);

console.log(
"*** recentMessagesData",
state.recentMessagesData.map((m) => m.content),
);

console.log("*** response", response);

const lastMessage = state.recentMessagesData[0];

console.log("*** lastMessage", lastMessage.content);

expect((lastMessage.content as Content).action).toBe("IGNORE");
}, 60000);

test("Action handler test 2: response should be ignore", async () => {
const message: Message = {
senderId: user.id as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: "",
room_id: room_id as UUID,
};

await populateMemories([GetTellMeAboutYourselfConversationTroll2]);

const response = await runtime.handleRequest(message);

const state = await runtime.composeState(message);

console.log(
"*** recentMessagesData",
state.recentMessagesData.map((m) => m.content),
);

console.log("*** response", response);

const lastMessage = state.recentMessagesData[0];

console.log("*** lastMessage", lastMessage.content);

expect((lastMessage.content as Content).action).toBe("IGNORE");
}, 60000);

test("Action handler test 3: response should be ignore", async () => {
const message: Message = {
senderId: user.id as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: "",
room_id: room_id as UUID,
};

await populateMemories([Goodbye1]);

const response = await runtime.handleRequest(message);

const state = await runtime.composeState(message);

console.log(
"*** recentMessagesData",
state.recentMessagesData.map((m) => m.content),
);

console.log("*** response", response);

const lastMessage = state.recentMessagesData[0];

console.log("*** lastMessage", lastMessage.content);

expect((lastMessage.content as Content).action).toBe("IGNORE");
}, 60000);
});
2 changes: 1 addition & 1 deletion src/lib/actions/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Action, type Message } from "../types";

export default {
name: "WAIT",
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
validate: async (_runtime: BgentRuntime, _message: Message) => {
return true;
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const composeContext = ({
template: string;
}) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
// @ts-expect-error match isn't working as expected
const out = template.replace(/{{\w+}}/g, (match) => {
const key = match.replace(/{{|}}/g, "");
return state[key] ?? "";
Expand Down
6 changes: 3 additions & 3 deletions src/lib/evaluators/summarization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ async function handler(runtime: BgentRuntime, message: Message) {
export default {
name: "SUMMARIZE",
validate: async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_runtime: BgentRuntime,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_message: Message,
): Promise<boolean> => {
return await Promise.resolve(true);
Expand All @@ -257,7 +259,5 @@ export default {
condition:
"New factual information was revealed in the recent conversation which should be remembered.",
handler,
examples: [

],
examples: [],
};
Loading

0 comments on commit 9ca8f11

Please sign in to comment.