1
1
import * as path from "path" ;
2
+ import type { createReactAgent } from "@langchain/langgraph/prebuilt" ;
2
3
import type { Conversation , DecodedMessage } from "@xmtp/node-sdk" ;
3
4
import * as dotenv from "dotenv" ;
4
5
import { initializeAgent } from "./cdp" ;
5
6
import { handleCommand as processCommand } from "./commands" ;
6
7
import { GameManager } from "./game" ;
7
8
import { initializeStorage } from "./storage" ;
9
+ import type { StorageProvider } from "./types" ;
8
10
import { initializeXmtpClient , startMessageListener } from "./xmtp" ;
9
11
10
12
// Initialize environment variables - make sure this is at the top of the file before any other code
@@ -18,9 +20,9 @@ if (result.error) {
18
20
}
19
21
20
22
// Global CDP agent instance - we'll initialize this at startup for better performance
21
- let cdpAgent : any = null ;
22
- let cdpAgentConfig : any = null ;
23
- let storage : any = null ;
23
+ let cdpAgent : ReturnType < typeof createReactAgent > | null = null ;
24
+ let cdpAgentConfig : { configurable : { thread_id : string } } | null = null ;
25
+ let storage : StorageProvider | null = null ;
24
26
25
27
/**
26
28
* Validates that required environment variables are set
@@ -86,16 +88,16 @@ async function handleMessage(
86
88
// TODO: Fix this
87
89
const address = message . senderInboxId ;
88
90
// Initialize game manager for this request
89
- const gameManager = new GameManager ( storage , address ) ;
91
+ const gameManager = new GameManager ( storage as StorageProvider , address ) ;
90
92
91
93
// Extract command content and process it
92
94
const commandContent = command . replace ( / ^ @ t o s s \s + / i, "" ) . trim ( ) ;
93
95
const response = await processCommand (
94
96
commandContent ,
95
97
address ,
96
98
gameManager ,
97
- cdpAgent ,
98
- cdpAgentConfig ,
99
+ cdpAgent as ReturnType < typeof createReactAgent > ,
100
+ cdpAgentConfig as { configurable : { thread_id : string } } ,
99
101
) ;
100
102
101
103
await conversation . send ( response ) ;
0 commit comments