1
1
const BITTE_API_URL =
2
2
"https://ai-runtime-446257178793.europe-west1.run.app/chat" ;
3
3
4
- export interface ToolResult {
4
+ export interface ToolResult < T = Record < string , unknown > > {
5
5
toolCallId : string ;
6
6
result : {
7
7
error ?: string ;
8
- data ?: unknown ;
8
+ data ?: T ;
9
9
} ;
10
10
}
11
11
12
- export interface AgentResponse {
12
+ export interface AgentResponse < T = Record < string , unknown > > {
13
13
content : string ;
14
- toolResults : ToolResult [ ] ;
14
+ toolResults : ToolResult < T > [ ] ;
15
15
messageId : string ;
16
16
finishReason : string ;
17
17
agentId : string ;
@@ -38,14 +38,14 @@ export interface ChatPayload {
38
38
config : ChatConfig ;
39
39
}
40
40
41
- export async function callAgent (
41
+ export async function callAgent < T = Record < string , unknown > > (
42
42
accountId : string ,
43
43
message : string ,
44
44
agentId : string ,
45
45
evmAddress : string = "" ,
46
46
suiAddress : string = "" ,
47
47
solanaAddress : string = "" ,
48
- ) : Promise < AgentResponse > {
48
+ ) : Promise < AgentResponse < T > > {
49
49
const chatId = `chat_${ Date . now ( ) } _${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } ` ;
50
50
51
51
const payload : ChatPayload = {
@@ -84,10 +84,7 @@ export async function callAgent(
84
84
let content = "" ;
85
85
let finishReason = "" ;
86
86
let resultAgentId = "" ;
87
- const toolResults : {
88
- toolCallId : string ;
89
- result : { error ?: string ; data ?: unknown } ;
90
- } [ ] = [ ] ;
87
+ const toolResults : ToolResult < T > [ ] = [ ] ;
91
88
92
89
for ( const line of lines ) {
93
90
const prefix = line . substring ( 0 , 2 ) ;
@@ -129,10 +126,7 @@ export async function callAgent(
129
126
130
127
return {
131
128
content : content . trim ( ) ,
132
- toolResults : toolResults . map ( ( toolResult ) => ( {
133
- toolCallId : toolResult . toolCallId ,
134
- result : toolResult . result ,
135
- } ) ) ,
129
+ toolResults,
136
130
messageId,
137
131
finishReason,
138
132
agentId : resultAgentId ,
0 commit comments