Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from main #12

Merged
merged 9 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export * from "./ask_claude.ts";
export * from "./follow_room.ts";
export * from "./imageGeneration.ts";
export * from "./mute_room.ts";
export * from "./swap.ts";
export * from "./unfollow_room.ts";
export * from "./unmute_room.ts";
export * from "./mute_room.ts";
export * from "./continue.ts";
export * from "./follow_room.ts";
export * from "./ignore.ts";
export * from "./imageGenerationUtils.ts";
export * from "./pumpfun.ts";
export * from "./swap.ts";
export * from "./swapUtils.ts";
export * from "./take_order.ts";
2 changes: 1 addition & 1 deletion core/src/actions/pumpfun.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnchorProvider } from "@coral-xyz/anchor";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet.js";
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import {
CreateTokenMetadata,
18 changes: 8 additions & 10 deletions core/src/actions/swapUtils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { getAssociatedTokenAddress } from "@solana/spl-token";
import {
PublicKey,
Keypair,
BlockhashWithExpiryBlockHeight,
Connection,
VersionedTransaction,
LAMPORTS_PER_SOL,
Keypair,
PublicKey,
RpcResponseAndContext,
TokenAmount,
SimulatedTransactionResponse,
Blockhash,
BlockhashWithExpiryBlockHeight,
TokenAmount,
VersionedTransaction
} from "@solana/web3.js";
import { getAssociatedTokenAddress } from "@solana/spl-token";
import settings from "../core/settings";
import settings from "../core/settings.ts";

const solAddress = settings.SOL_ADDRESS;
const SLIPPAGE = settings.SLIPPAGE;
const connection = new Connection(settings.RPC_URL!);
const connection = new Connection(settings.RPC_URL || "https://api.mainnet-beta.solana.com");
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

export async function delayedCall<T>(
2 changes: 2 additions & 0 deletions core/src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { PostgresDatabaseAdapter } from "./postgres.ts";
export { SqliteDatabaseAdapter } from "./sqlite.ts";
27 changes: 7 additions & 20 deletions core/src/clients/direct/index.ts
Original file line number Diff line number Diff line change
@@ -144,26 +144,13 @@ class DirectClient {
return;
}

await Promise.all([
runtime.ensureUserExists(
runtime.agentId,
runtime.character.name ?? "Agent",
runtime.character.name ?? "Agent",
"direct"
),
runtime.ensureUserExists(
userId,
req.body.userName ?? "User",
req.body.name ?? "User",
"direct"
),
runtime.ensureRoomExists(roomId),
]);

await Promise.all([
runtime.ensureParticipantInRoom(userId, roomId),
runtime.ensureParticipantInRoom(runtime.agentId, roomId),
]);
await runtime.ensureConnection(
userId,
roomId,
req.body.userName,
req.body.name,
"direct"
);

const text = req.body.text;
const messageId = stringToUuid(Date.now().toString());
68 changes: 17 additions & 51 deletions core/src/clients/discord/index.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import { embeddingZeroVector } from "../../core/memory.ts";
import { MessageManager } from "./messages.ts";
import { VoiceManager } from "./voice.ts";

import { IAgentRuntime } from "../../core/types.ts";
import { Character, IAgentRuntime } from "../../core/types.ts";
import chat_with_attachments from "./actions/chat_with_attachments.ts";
import joinvoice from "./actions/joinvoice.ts";
import leavevoice from "./actions/leavevoice.ts";
@@ -31,7 +31,7 @@ export class DiscordClient extends EventEmitter {
apiToken: string;
private client: Client;
private runtime: IAgentRuntime;
character: any;
character: Character;
private messageManager: MessageManager;
private voiceManager: VoiceManager;

@@ -182,29 +182,16 @@ export class DiscordClient extends EventEmitter {
console.error("Invalid user id or room id");
return;
}
const agentId = this.runtime.agentId;
const userName = reaction.message.author.username;
const name = reaction.message.author.displayName;
await Promise.all([
this.runtime.ensureUserExists(
agentId,
this.client.user.username,
this.runtime.character.name,
"discord"
),
this.runtime.ensureUserExists(
userIdUUID,
userName,
name,
"discord"
),
this.runtime.ensureRoomExists(roomId),
]);

await Promise.all([
this.runtime.ensureParticipantInRoom(userIdUUID, roomId),
this.runtime.ensureParticipantInRoom(agentId, roomId),
]);

await this.runtime.ensureConnection(
userIdUUID,
roomId,
userName,
name,
"discord"
);

// Save the reaction as a message
await this.runtime.messageManager.createMemory({
@@ -259,37 +246,16 @@ export class DiscordClient extends EventEmitter {
`${reaction.message.id}-${user.id}-${emoji}-removed`
);

const agentId = this.runtime.agentId;
const userName = reaction.message.author.username;
const name = reaction.message.author.displayName;

console.log("reactionUUID", reactionUUID);
console.log("userIdUUID", userIdUUID);
console.log("roomId", roomId);
console.log("agentId", agentId);
console.log("userName", userName);
console.log("name", name);

await Promise.all([
this.runtime.ensureUserExists(
agentId,
this.client.user.username,
this.runtime.character.name,
"discord"
),
this.runtime.ensureUserExists(
userIdUUID,
userName,
name,
"discord"
),
this.runtime.ensureRoomExists(roomId),
]);

await Promise.all([
this.runtime.ensureParticipantInRoom(userIdUUID, roomId),
this.runtime.ensureParticipantInRoom(agentId, roomId),
]);
await this.runtime.ensureConnection(
userIdUUID,
roomId,
userName,
name,
"discord"
);

try {
// Save the reaction removal as a message
30 changes: 8 additions & 22 deletions core/src/clients/discord/messages.ts
Original file line number Diff line number Diff line change
@@ -146,28 +146,14 @@ export class MessageManager {

const roomId = stringToUuid(channelId);
const userIdUUID = stringToUuid(userId);
const agentId = this.runtime.agentId;

await Promise.all([
this.runtime.ensureUserExists(
agentId,
this.client.user.username,
this.runtime.character.name,
"discord"
),
this.runtime.ensureUserExists(
userIdUUID,
userName,
name,
"discord"
),
this.runtime.ensureRoomExists(roomId),
]);

await Promise.all([
this.runtime.ensureParticipantInRoom(userIdUUID, roomId),
this.runtime.ensureParticipantInRoom(agentId, roomId),
]);

await this.runtime.ensureConnection(
userIdUUID,
roomId,
userName,
name,
"discord"
);

const messageId = stringToUuid(message.id);

30 changes: 6 additions & 24 deletions core/src/clients/discord/voice.ts
Original file line number Diff line number Diff line change
@@ -304,32 +304,14 @@ export class VoiceManager extends EventEmitter {

const roomId = stringToUuid(channelId);
const userIdUUID = stringToUuid(userId);
await this.runtime.ensureUserExists(
this.runtime.agentId,
this.client.user.username,
this.runtime.character.name,

await this.runtime.ensureConnection(
userIdUUID,
roomId,
userName,
name,
"discord"
);
await Promise.all([
this.runtime.ensureUserExists(
userIdUUID,
userName,
name,
"discord"
),
this.runtime.ensureRoomExists(roomId),
]);

await Promise.all([
this.runtime.ensureParticipantInRoom(
userIdUUID,
roomId
),
this.runtime.ensureParticipantInRoom(
this.runtime.agentId,
roomId
),
]);

let state = await this.runtime.composeState(
{
10 changes: 10 additions & 0 deletions core/src/clients/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import DirectClient from "./direct/index.ts";

export {
TwitterGenerationClient,
TwitterInteractionClient,
TwitterSearchClient,
} from "./twitter/index.ts";
export { TelegramClient } from "./telegram/index.ts";
export { DiscordClient } from "./discord/index.ts";
export { DirectClient };
1 change: 1 addition & 0 deletions core/src/clients/telegram/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TelegramClient } from "./src/index.ts";
34 changes: 11 additions & 23 deletions core/src/clients/telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
@@ -222,11 +222,10 @@ export class MessageManager {
return; // Exit if no message or sender info
}

//@ts-ignore
if (ctx.message.text.startsWith("/")) {
//Handle commands?
return;
}
// TODO: Handle commands?
// if (ctx.message.text?.startsWith("/")) {
// return;
// }

const message = ctx.message;

@@ -239,24 +238,13 @@ export class MessageManager {
const agentId = this.runtime.agentId;
const roomId = chatId;

// Ensure user and room exist
await Promise.all([
this.runtime.ensureUserExists(
agentId,
this.bot.botInfo?.username || "Bot",
this.runtime.character.name,
"telegram"
),
this.runtime.ensureUserExists(
userId,
userName,
userName,
"telegram"
),
this.runtime.ensureRoomExists(roomId),
this.runtime.ensureParticipantInRoom(userId, roomId),
this.runtime.ensureParticipantInRoom(agentId, roomId),
]);
await this.runtime.ensureConnection(
userId,
roomId,
userName,
userName,
"telegram"
);

const messageId = stringToUuid(
message.message_id.toString()
25 changes: 4 additions & 21 deletions core/src/clients/twitter/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

import {
QueryTweetsResponse,
Scraper,
@@ -410,22 +408,13 @@ export class ClientBase extends EventEmitter {
? this.runtime.agentId
: stringToUuid(tweet.userId);

await this.runtime.ensureRoomExists(roomId);
await this.runtime.ensureParticipantExists(
this.runtime.agentId,
roomId
);

await this.runtime.ensureUserExists(
await this.runtime.ensureConnection(
tweetuserId,
roomId,
tweet.username,
tweet.name,
"twitter"
);
await this.runtime.ensureParticipantExists(
tweetuserId,
roomId
);

const content = {
text: tweet.text,
@@ -521,19 +510,13 @@ export class ClientBase extends EventEmitter {
? this.runtime.agentId
: stringToUuid(tweet.userId);

await this.runtime.ensureRoomExists(roomId);
await this.runtime.ensureParticipantExists(
this.runtime.agentId,
roomId
);

await this.runtime.ensureUserExists(
await this.runtime.ensureConnection(
tweetuserId,
roomId,
tweet.username,
tweet.name,
"twitter"
);
await this.runtime.ensureParticipantExists(tweetuserId, roomId);

const content = {
text: tweet.text,
2 changes: 2 additions & 0 deletions core/src/clients/twitter/generate.ts
Original file line number Diff line number Diff line change
@@ -162,11 +162,13 @@ export class TwitterGenerationClient extends ClientBase {
const conversationId = tweet.conversationId;
const roomId = stringToUuid(conversationId);

// make sure the agent is in the room
await this.runtime.ensureRoomExists(roomId);
await this.runtime.ensureParticipantInRoom(
this.runtime.agentId,
roomId
);

await this.cacheTweet(tweet);

await this.runtime.messageManager.createMemory({
3 changes: 3 additions & 0 deletions core/src/clients/twitter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { TwitterGenerationClient } from "./generate.ts";
export { TwitterSearchClient } from "./search.ts";
export { TwitterInteractionClient } from "./interactions.ts";
Loading