Skip to content

Commit 6aca7c8

Browse files
Merge branch 'ai16z:main' into main
2 parents dd15ede + 1c9a5a1 commit 6aca7c8

File tree

3 files changed

+67
-38
lines changed

3 files changed

+67
-38
lines changed

.github/workflows/require-develop.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Check pull request source branch
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
- reopened
7+
- synchronize
8+
- edited
9+
jobs:
10+
check-branches:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check branches
14+
run: |
15+
if [ ${{ github.head_ref }} != "develop" ] && [ ${{ github.base_ref }} == "main" ]; then
16+
echo "Merge requests to main branch are only allowed from dev branch."
17+
exit 1
18+
fi

agent/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,14 @@ export async function createAgent(
459459
});
460460
}
461461

462-
function intializeFsCache(baseDir: string, character: Character) {
462+
function initializeFsCache(baseDir: string, character: Character) {
463463
const cacheDir = path.resolve(baseDir, character.id, "cache");
464464

465465
const cache = new CacheManager(new FsCacheAdapter(cacheDir));
466466
return cache;
467467
}
468468

469-
function intializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
469+
function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
470470
const cache = new CacheManager(new DbCacheAdapter(db, character.id));
471471
return cache;
472472
}
@@ -489,7 +489,7 @@ async function startAgent(character: Character, directClient) {
489489

490490
await db.init();
491491

492-
const cache = intializeDbCache(character, db);
492+
const cache = initializeDbCache(character, db);
493493
const runtime = await createAgent(character, db, cache, token);
494494

495495
await runtime.initialize();

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)