Skip to content

Commit

Permalink
start Common client on start-up
Browse files Browse the repository at this point in the history
  • Loading branch information
timolegros committed Jan 3, 2025
1 parent 7cf2ff1 commit e33b6c5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LensAgentClient } from "@elizaos/client-lens";
import { SlackClientInterface } from "@elizaos/client-slack";
import { TelegramClientInterface } from "@elizaos/client-telegram";
import { TwitterClientInterface } from "@elizaos/client-twitter";
import { CommonClientInterface } from '@elizaos/client-common';
import {
AgentRuntime,
CacheManager,
Expand Down Expand Up @@ -416,6 +417,13 @@ export async function initializeClients(
}
}

if (clientTypes.includes(Clients.COMMON)) {
const commonClient = await CommonClientInterface.start(runtime);
if (commonClient) {
clients.common = commonClient;
}
}

if (clientTypes.includes(Clients.FARCASTER)) {
// why is this one different :(
const farcasterClient = new FarcasterAgentClient(runtime);
Expand Down
13 changes: 12 additions & 1 deletion packages/client-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Character, elizaLogger, IAgentRuntime } from "@elizaos/core";
import { Character, elizaLogger, IAgentRuntime, Client } from "@elizaos/core";
import { validateCommonConfig } from "./environment.ts";
import express, { Request, Response, NextFunction } from "express";
import { CommonApiClient } from "@commonxyz/api-client";
Expand Down Expand Up @@ -156,3 +156,14 @@ export class CommonClient {
}
}
}

// TODO: add error handling
export const CommonClientInterface: Client = {
start: async (runtime: IAgentRuntime) => {
const client = new CommonClient(runtime);
await client.start();
},
stop: async (runtime: IAgentRuntime) => {
await runtime.clients.common.stop();
}
}
7 changes: 4 additions & 3 deletions packages/client-common/src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {CommonApiClient} from "@commonxyz/api-client";
import {
Clients,
composeContext, Content,
elizaLogger, generateMessageResponse,
generateShouldRespond,
Expand Down Expand Up @@ -131,7 +132,7 @@ export class MessageManager {
roomId,
undefined,
message.profile_name,
"Common"
Clients.COMMON
);

const memory: Memory = {
Expand All @@ -141,7 +142,7 @@ export class MessageManager {
agentId: this.runtime.agentId,
content: {
text: message.full_object_text,
source: "Common",
source: Clients.COMMON,
url: message.object_url,
// TODO: inReplyTo: undefined,
},
Expand Down Expand Up @@ -188,7 +189,7 @@ export class MessageManager {
agentId: this.runtime.agentId,
content: {
text: res.body,
source: "Common",
source: Clients.COMMON,
content_url: res.content_url,
},
createdAt: new Date(res.created_at).getTime(),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ export type Plugin = {
* Available client platforms
*/
export enum Clients {
COMMON = "common",
DISCORD = "discord",
DIRECT = "direct",
TWITTER = "twitter",
Expand Down

0 comments on commit e33b6c5

Please sign in to comment.