Skip to content

Commit 9ce1292

Browse files
authored
Merge branch 'main' into twitter-search-switch
2 parents e7964c3 + ec00fa8 commit 9ce1292

File tree

1 file changed

+46
-35
lines changed

1 file changed

+46
-35
lines changed

packages/client-farcaster/src/interactions.ts

+46-35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
ModelClass,
77
stringToUuid,
88
elizaLogger,
9+
HandlerCallback,
10+
Content,
911
type IAgentRuntime,
1012
} from "@ai16z/eliza";
1113
import type { FarcasterClient } from "./client";
@@ -219,56 +221,65 @@ export class FarcasterInteractionManager {
219221
messageHandlerTemplate,
220222
});
221223

222-
const response = await generateMessageResponse({
224+
const responseContent = await generateMessageResponse({
223225
runtime: this.runtime,
224226
context,
225227
modelClass: ModelClass.LARGE,
226228
});
227229

228-
response.inReplyTo = memoryId;
230+
responseContent.inReplyTo = memoryId;
229231

230-
if (!response.text) return;
232+
if (!responseContent.text) return;
231233

232234
if (this.runtime.getSetting("FARCASTER_DRY_RUN") === "true") {
233235
elizaLogger.info(
234-
`Dry run: would have responded to cast ${cast.hash} with ${response.text}`
236+
`Dry run: would have responded to cast ${cast.hash} with ${responseContent.text}`
235237
);
236238
return;
237239
}
238240

239-
try {
240-
elizaLogger.info(`Replying to cast ${cast.hash}.`);
241-
242-
const results = await sendCast({
243-
runtime: this.runtime,
244-
client: this.client,
245-
signerUuid: this.signerUuid,
246-
profile: cast.profile,
247-
content: response,
248-
roomId: memory.roomId,
249-
inReplyTo: {
250-
fid: cast.authorFid,
251-
hash: cast.hash,
252-
},
253-
});
254-
// sendCast lost response action, so we need to add it back here
255-
results[0].memory.content.action = response.action;
256-
257-
const newState = await this.runtime.updateRecentMessageState(state);
258-
259-
for (const { memory } of results) {
260-
await this.runtime.messageManager.createMemory(memory);
241+
const callback: HandlerCallback = async (
242+
content: Content,
243+
files: any[]
244+
) => {
245+
try {
246+
if (memoryId && !content.inReplyTo) {
247+
content.inReplyTo = memoryId;
248+
}
249+
const results = await sendCast({
250+
runtime: this.runtime,
251+
client: this.client,
252+
signerUuid: this.signerUuid,
253+
profile: cast.profile,
254+
content: content,
255+
roomId: memory.roomId,
256+
inReplyTo: {
257+
fid: cast.authorFid,
258+
hash: cast.hash,
259+
},
260+
});
261+
// sendCast lost response action, so we need to add it back here
262+
results[0].memory.content.action = content.action;
263+
264+
for (const { memory } of results) {
265+
await this.runtime.messageManager.createMemory(memory);
266+
}
267+
return results.map((result) => result.memory);
268+
} catch (error) {
269+
console.error("Error sending response cast:", error);
270+
return [];
261271
}
272+
};
262273

263-
await this.runtime.evaluate(memory, newState);
274+
const responseMessages = await callback(responseContent);
264275

265-
await this.runtime.processActions(
266-
memory,
267-
results.map((result) => result.memory),
268-
newState
269-
);
270-
} catch (error) {
271-
elizaLogger.error(`Error sending response cast: ${error}`);
272-
}
276+
const newState = await this.runtime.updateRecentMessageState(state);
277+
278+
await this.runtime.processActions(
279+
memory,
280+
responseMessages,
281+
newState,
282+
callback
283+
);
273284
}
274285
}

0 commit comments

Comments
 (0)