Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Mar 3, 2025
1 parent e174c25 commit 30ff61f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
import type { IToken } from "./types";
import type { TransactionHistory, Portfolio, SentimentContent } from "./providers/birdeye";

export const createRoutes = (runtime: IAgentRuntime): Route[] => [
export const routes: Route[] = [
{
type: "POST",
path: "/trending",
handler: async (_req: any, res: any) => {
handler: async (_req: any, res: any, runtime) => {
try {
const cachedTokens = await runtime.databaseAdapter.getCache<IToken[]>("tokens_solana");
const tokens: IToken[] = cachedTokens ? cachedTokens : [];
Expand All @@ -28,7 +28,7 @@ export const createRoutes = (runtime: IAgentRuntime): Route[] => [
{
type: "POST",
path: "/wallet",
handler: async (_req: any, res: any) => {
handler: async (_req: any, res: any, runtime: IAgentRuntime) => {
try {
// Get transaction history
const cachedTxs = await runtime.databaseAdapter.getCache<TransactionHistory[]>("transaction_history");
Expand All @@ -51,7 +51,7 @@ export const createRoutes = (runtime: IAgentRuntime): Route[] => [
{
type: "GET",
path: "/tweets",
handler: async (_req: any, res: any) => {
handler: async (_req: any, res: any, runtime: IAgentRuntime) => {
try {
const memories = await runtime.messageManager.getMemories({
roomId: createUniqueUuid(runtime, "twitter-feed"),
Expand All @@ -78,7 +78,7 @@ export const createRoutes = (runtime: IAgentRuntime): Route[] => [
{
type: "GET",
path: "/sentiment",
handler: async (_req: any, res: any) => {
handler: async (_req: any, res: any, runtime: IAgentRuntime) => {
try {
const memories = await runtime.messageManager.getMemories({
roomId: createUniqueUuid(runtime, "sentiment-analysis"),
Expand Down Expand Up @@ -118,7 +118,7 @@ export const createRoutes = (runtime: IAgentRuntime): Route[] => [
{
type: "POST",
path: "/signal",
handler: async (_req: any, res: any) => {
handler: async (_req: any, res: any, runtime: IAgentRuntime) => {
try {
const cachedSignal = await runtime.databaseAdapter.getCache<any>("BUY_SIGNAL");
const signal = cachedSignal ? cachedSignal : {};
Expand All @@ -130,4 +130,4 @@ export const createRoutes = (runtime: IAgentRuntime): Route[] => [
}
];

export default createRoutes;
export default routes;
15 changes: 2 additions & 13 deletions packages/core/src/providers/relationships.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import type { IAgentRuntime, Memory, Provider, State, Relationship, UUID } from "../types.ts";

async function getRelationships({
runtime,
userId,
}: {
runtime: IAgentRuntime;
userId: UUID;
}) {
return runtime.databaseAdapter.getRelationships({ userId, agentId: runtime.agentId });
}

async function formatRelationships(runtime: IAgentRuntime, relationships: Relationship[]) {
// Sort relationships by interaction strength (descending)
const sortedRelationships = relationships
Expand All @@ -36,7 +26,7 @@ async function formatRelationships(runtime: IAgentRuntime, relationships: Relati
const targetEntityId = rel.targetEntityId;

// get the entity
const entity = await runtime.getEntity(targetEntityId);
const entity = await runtime.databaseAdapter.getEntityById(targetEntityId as UUID);

if(!entity) {
return null;
Expand All @@ -54,8 +44,7 @@ const relationshipsProvider: Provider = {
name: "relationships",
get: async (runtime: IAgentRuntime, message: Memory, state?: State) => {
// Get all relationships for the current user
const relationships = await getRelationships({
runtime,
const relationships = await runtime.databaseAdapter.getRelationships({
userId: message.userId,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/providers/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const roleProvider: Provider = {
const userRole = roles[userId];

// get the user from the database
const user = await runtime.getEntity(userId as UUID);
const user = await runtime.databaseAdapter.getEntityById(userId as UUID);

const name = user.metadata[room.source]?.name;
const username = user.metadata[room.source]?.username;
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
type Action,
type Actor,
type Adapter,
type Agent,
ChannelType,
type Character,
type Client,
Expand All @@ -44,11 +45,9 @@ import {
type Service,
type ServiceType,
type State,
type Task,
type TaskWorker,
type UUID,
type WorldData,
type Agent
type WorldData
} from "./types.ts";
import { stringToUuid } from "./uuid.ts";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ export type Route = {
type: "GET" | "POST" | "PUT" | "DELETE";
path: string;
// TODO: give me strong types
handler: (req: any, res: any) => Promise<void>;
handler: (req: any, res: any, runtime: IAgentRuntime) => Promise<void>;
};

/**
Expand Down

0 comments on commit 30ff61f

Please sign in to comment.