Skip to content

Commit

Permalink
fix should generate response
Browse files Browse the repository at this point in the history
  • Loading branch information
timolegros committed Jan 6, 2025
1 parent 28e9a58 commit 0f8a133
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/client-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export class CommonClient {

// TODO: fetch user once Common Api Client is published with the new route
// const user = await this.commonApiClient.User.getUser();
const user = { id: 161416, profile: { name: "Eliza Dev 1" } };
const user = { id: parseInt(process.env.COMMON_USER_ID), profile: { name: "Eliza Dev 1" } };
this.commonUserId = user.id;
this.messageManager = new MessageManager(
this.commonApiClient,
this.runtime,
this.commonUserId
this.commonUserId,
user.profile.name,
);

const webhookPath = `/eliza/${user.id}`;
Expand Down Expand Up @@ -108,12 +109,13 @@ export class CommonClient {
// TODO: verify Webhook signature using config.COMMON_WEBHOOK_SIGNING_KEY

// Validate body
const { success, data: body } = AgentMentionedSchema.safeParse(
const { success, data: body, error } = AgentMentionedSchema.safeParse(
req.body
);
if (success === false) {
return res.status(400).send({
error: "Invalid request body",
error: `Invalid request body`,
schemaErrors: error
});
}

Expand Down
8 changes: 6 additions & 2 deletions packages/client-common/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ import {CreateCommentResponse} from "@commonxyz/api-client/api";
export class MessageManager {
private readonly runtime: IAgentRuntime;
private readonly commonApiClient: CommonApiClient;
// TODO: combine into a single Common user with type from common-client GetUser
private readonly commonUserId: number;
private readonly commonProfileName: string;

constructor(
commonApiClient: CommonApiClient,
runtime: IAgentRuntime,
commonUserId: number
commonUserId: number,
commonProfileName: string,
) {
this.runtime = runtime;
this.commonApiClient = commonApiClient;
this.commonUserId = commonUserId;
this.commonProfileName = commonProfileName;
}

private async _shouldRespond(
Expand Down Expand Up @@ -155,7 +159,7 @@ export class MessageManager {
const state = await this.runtime.composeState(memory, {
commonClient: this.commonApiClient,
commonMessage: message,
agentName: this.runtime.character.name,
agentName: this.commonProfileName,
});

if (!(await this._shouldRespond(message, state))) {
Expand Down

0 comments on commit 0f8a133

Please sign in to comment.