@@ -3,10 +3,33 @@ import {
3
3
HandlerCallback ,
4
4
IAgentRuntime ,
5
5
Memory ,
6
+ State ,
6
7
elizaLogger ,
7
8
} from "@ai16z/eliza" ;
8
9
import { TransactionHash } from "genlayer-js/types" ;
9
10
import { ClientProvider } from "../providers/client" ;
11
+ import { getParamsWithLLM } from "../utils/llm" ;
12
+
13
+ const getTransactionTemplate = `
14
+ # Task: Extract the transaction hash from the user's message.
15
+
16
+ # Instructions: The user is requesting transaction details from the GenLayer protocol.
17
+
18
+ <latest user message>
19
+ {{userMessage}}
20
+ </latest user message>
21
+
22
+ <data from recent messages>
23
+ {{recentMessagesData}}
24
+ </data from recent messages>
25
+
26
+ # Your response must be formatted as a JSON block with this structure:
27
+ \`\`\`json
28
+ {
29
+ "hash": "<Transaction Hash>"
30
+ }
31
+ \`\`\`
32
+ ` ;
10
33
11
34
export const getTransactionAction : Action = {
12
35
name : "GET_TRANSACTION" ,
@@ -19,26 +42,36 @@ export const getTransactionAction: Action = {
19
42
handler : async (
20
43
runtime : IAgentRuntime ,
21
44
message : Memory ,
22
- _state : any ,
45
+ state : State ,
23
46
_options : any ,
24
47
callback : HandlerCallback
25
48
) => {
26
49
elizaLogger . info ( "Starting get transaction action" ) ;
27
50
elizaLogger . debug ( "User message:" , message . content . text ) ;
28
51
29
52
const clientProvider = new ClientProvider ( runtime ) ;
30
- // Extract transaction hash from message
31
- const hashMatch = message . content . text . match ( / 0 x [ a - f A - F 0 - 9 ] { 64 } / ) ;
32
- if ( ! hashMatch ) {
53
+
54
+ const options = await getParamsWithLLM < { hash : TransactionHash } > (
55
+ runtime ,
56
+ message ,
57
+ getTransactionTemplate ,
58
+ state
59
+ ) ;
60
+
61
+ if (
62
+ ! options ||
63
+ ! options . hash ||
64
+ ! / ^ 0 x [ a - f A - F 0 - 9 ] { 64 } $ / . test ( options . hash )
65
+ ) {
33
66
elizaLogger . error ( "No valid transaction hash found in message" ) ;
34
67
throw new Error ( "No valid transaction hash found in message" ) ;
35
68
}
36
69
37
70
elizaLogger . info (
38
- `Getting transaction details for hash: ${ hashMatch [ 0 ] } `
71
+ `Getting transaction details for hash: ${ options . hash } `
39
72
) ;
40
73
const result = await clientProvider . client . getTransaction ( {
41
- hash : hashMatch [ 0 ] as TransactionHash ,
74
+ hash : options . hash ,
42
75
} ) ;
43
76
44
77
elizaLogger . success ( "Successfully retrieved transaction details" ) ;
0 commit comments