1
+ use std:: collections:: HashMap ;
1
2
use std:: env;
2
3
use std:: time:: Duration ;
3
4
4
5
use serde_json:: json;
5
6
6
7
use crate :: built_in_tools:: get_tool;
8
+ use crate :: tools:: code_files:: CodeFiles ;
7
9
use crate :: tools:: tool:: Tool ;
8
10
9
11
#[ tokio:: test]
@@ -13,11 +15,11 @@ async fn shinkai_tool_echo() {
13
15
. is_test ( true )
14
16
. try_init ( ) ;
15
17
let tool_definition = get_tool ( "shinkai-tool-echo" ) . unwrap ( ) ;
16
- let tool = Tool :: new (
17
- tool_definition. code . clone ( ) . unwrap ( ) ,
18
- serde_json :: Value :: Null ,
19
- None ,
20
- ) ;
18
+ let code_files = CodeFiles {
19
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
20
+ entrypoint : "main.ts" . to_string ( ) ,
21
+ } ;
22
+ let tool = Tool :: new ( code_files , serde_json :: Value :: Null , None ) ;
21
23
let run_result = tool
22
24
. run ( None , serde_json:: json!( { "message" : "valparaíso" } ) , None )
23
25
. await
@@ -32,8 +34,12 @@ async fn shinkai_tool_weather_by_city() {
32
34
. is_test ( true )
33
35
. try_init ( ) ;
34
36
let tool_definition = get_tool ( "shinkai-tool-weather-by-city" ) . unwrap ( ) ;
37
+ let code_files = CodeFiles {
38
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
39
+ entrypoint : "main.ts" . to_string ( ) ,
40
+ } ;
35
41
let tool = Tool :: new (
36
- tool_definition . code . clone ( ) . unwrap ( ) ,
42
+ code_files ,
37
43
serde_json:: json!( { "apiKey" : "63d35ff6068c3103ccd1227526935675" } ) ,
38
44
None ,
39
45
) ;
@@ -54,7 +60,11 @@ async fn shinkai_tool_inline() {
54
60
return { message: `Hello, ${params.name}!` };
55
61
}
56
62
"# ;
57
- let tool = Tool :: new ( js_code. to_string ( ) , serde_json:: Value :: Null , None ) ;
63
+ let code_files = CodeFiles {
64
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , js_code. to_string ( ) ) ] ) ,
65
+ entrypoint : "main.ts" . to_string ( ) ,
66
+ } ;
67
+ let tool = Tool :: new ( code_files, serde_json:: Value :: Null , None ) ;
58
68
let run_result = tool
59
69
. run ( None , serde_json:: json!( { "name" : "world" } ) , None )
60
70
. await
@@ -73,7 +83,11 @@ async fn shinkai_tool_inline_non_json_return() {
73
83
return 5;
74
84
}
75
85
"# ;
76
- let tool = Tool :: new ( js_code. to_string ( ) , serde_json:: Value :: Null , None ) ;
86
+ let code_files = CodeFiles {
87
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , js_code. to_string ( ) ) ] ) ,
88
+ entrypoint : "main.ts" . to_string ( ) ,
89
+ } ;
90
+ let tool = Tool :: new ( code_files, serde_json:: Value :: Null , None ) ;
77
91
let run_result = tool. run ( None , serde_json:: json!( { } ) , None ) . await . unwrap ( ) ;
78
92
assert_eq ! ( run_result. data, 5 ) ;
79
93
}
@@ -85,11 +99,11 @@ async fn shinkai_tool_web3_eth_balance() {
85
99
. is_test ( true )
86
100
. try_init ( ) ;
87
101
let tool_definition = get_tool ( "shinkai-tool-web3-eth-balance" ) . unwrap ( ) ;
88
- let tool = Tool :: new (
89
- tool_definition. code . clone ( ) . unwrap ( ) ,
90
- serde_json :: Value :: Null ,
91
- None ,
92
- ) ;
102
+ let code_files = CodeFiles {
103
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
104
+ entrypoint : "main.ts" . to_string ( ) ,
105
+ } ;
106
+ let tool = Tool :: new ( code_files , serde_json :: Value :: Null , None ) ;
93
107
let run_result = tool
94
108
. run (
95
109
None ,
@@ -108,11 +122,11 @@ async fn shinkai_tool_web3_eth_uniswap() {
108
122
. is_test ( true )
109
123
. try_init ( ) ;
110
124
let tool_definition = get_tool ( "shinkai-tool-web3-eth-uniswap" ) . unwrap ( ) ;
111
- let tool = Tool :: new (
112
- tool_definition. code . clone ( ) . unwrap ( ) ,
113
- serde_json :: Value :: Null ,
114
- None ,
115
- ) ;
125
+ let code_files = CodeFiles {
126
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
127
+ entrypoint : "main.ts" . to_string ( ) ,
128
+ } ;
129
+ let tool = Tool :: new ( code_files , serde_json :: Value :: Null , None ) ;
116
130
let run_result = tool
117
131
. run (
118
132
None ,
@@ -137,11 +151,11 @@ async fn shinkai_tool_download_page() {
137
151
. is_test ( true )
138
152
. try_init ( ) ;
139
153
let tool_definition = get_tool ( "shinkai-tool-download-pages" ) . unwrap ( ) ;
140
- let tool = Tool :: new (
141
- tool_definition. code . clone ( ) . unwrap ( ) ,
142
- serde_json :: Value :: Null ,
143
- None ,
144
- ) ;
154
+ let code_files = CodeFiles {
155
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
156
+ entrypoint : "main.ts" . to_string ( ) ,
157
+ } ;
158
+ let tool = Tool :: new ( code_files , serde_json :: Value :: Null , None ) ;
145
159
let run_result = tool
146
160
. run (
147
161
None ,
@@ -177,7 +191,11 @@ async fn max_execution_time() {
177
191
return { data: true };
178
192
}
179
193
"# ;
180
- let tool = Tool :: new ( js_code. to_string ( ) , serde_json:: Value :: Null , None ) ;
194
+ let code_files = CodeFiles {
195
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , js_code. to_string ( ) ) ] ) ,
196
+ entrypoint : "main.ts" . to_string ( ) ,
197
+ } ;
198
+ let tool = Tool :: new ( code_files, serde_json:: Value :: Null , None ) ;
181
199
let run_result = tool
182
200
. run (
183
201
None ,
@@ -202,11 +220,14 @@ async fn shinkai_tool_download_page_stack_overflow() {
202
220
tokio:: runtime:: Runtime :: new ( ) . expect ( "Failed to create Tokio runtime" ) ;
203
221
managed_runtime. block_on ( async {
204
222
let tool_definition = get_tool ( "shinkai-tool-download-pages" ) . unwrap ( ) ;
205
- let tool = Tool :: new (
206
- tool_definition. code . clone ( ) . unwrap ( ) ,
207
- serde_json:: Value :: Null ,
208
- None ,
209
- ) ;
223
+ let code_files = CodeFiles {
224
+ files : HashMap :: from ( [ (
225
+ "main.ts" . to_string ( ) ,
226
+ tool_definition. code . clone ( ) . unwrap ( ) ,
227
+ ) ] ) ,
228
+ entrypoint : "main.ts" . to_string ( ) ,
229
+ } ;
230
+ let tool = Tool :: new ( code_files, serde_json:: Value :: Null , None ) ;
210
231
tool. run (
211
232
None ,
212
233
serde_json:: json!( {
@@ -231,11 +252,11 @@ async fn shinkai_tool_leiden() {
231
252
. is_test ( true )
232
253
. try_init ( ) ;
233
254
let tool_definition = get_tool ( "shinkai-tool-leiden" ) . unwrap ( ) ;
234
- let tool = Tool :: new (
235
- tool_definition. code . clone ( ) . unwrap ( ) ,
236
- serde_json :: Value :: Null ,
237
- None ,
238
- ) ;
255
+ let code_files = CodeFiles {
256
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
257
+ entrypoint : "main.ts" . to_string ( ) ,
258
+ } ;
259
+ let tool = Tool :: new ( code_files , serde_json :: Value :: Null , None ) ;
239
260
let edges = vec ! [
240
261
( 2 , 1 , 1 ) ,
241
262
( 3 , 1 , 1 ) ,
@@ -339,11 +360,11 @@ async fn shinkai_tool_duckduckgo_search() {
339
360
. is_test ( true )
340
361
. try_init ( ) ;
341
362
let tool_definition = get_tool ( "shinkai-tool-duckduckgo-search" ) . unwrap ( ) ;
342
- let tool = Tool :: new (
343
- tool_definition. code . clone ( ) . unwrap ( ) ,
344
- serde_json :: Value :: Null ,
345
- None ,
346
- ) ;
363
+ let code_files = CodeFiles {
364
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
365
+ entrypoint : "main.ts" . to_string ( ) ,
366
+ } ;
367
+ let tool = Tool :: new ( code_files , serde_json :: Value :: Null , None ) ;
347
368
let run_result = tool
348
369
. run (
349
370
None ,
@@ -370,8 +391,12 @@ async fn shinkai_tool_playwright_example() {
370
391
. is_test ( true )
371
392
. try_init ( ) ;
372
393
let tool_definition = get_tool ( "shinkai-tool-playwright-example" ) . unwrap ( ) ;
394
+ let code_files = CodeFiles {
395
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
396
+ entrypoint : "main.ts" . to_string ( ) ,
397
+ } ;
373
398
let tool = Tool :: new (
374
- tool_definition . code . clone ( ) . unwrap ( ) ,
399
+ code_files ,
375
400
serde_json:: json!( { "chromePath" : std:: env:: var( "CHROME_PATH" ) . ok( ) . unwrap_or( "" . to_string( ) ) } ) ,
376
401
None ,
377
402
) ;
@@ -401,8 +426,12 @@ async fn shinkai_tool_defillama_lending_tvl_rankings() {
401
426
. is_test ( true )
402
427
. try_init ( ) ;
403
428
let tool_definition = get_tool ( "shinkai-tool-defillama-tvl-rankings" ) . unwrap ( ) ;
429
+ let code_files = CodeFiles {
430
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
431
+ entrypoint : "main.ts" . to_string ( ) ,
432
+ } ;
404
433
let tool = Tool :: new (
405
- tool_definition . code . clone ( ) . unwrap ( ) ,
434
+ code_files ,
406
435
serde_json:: json!( { "chromePath" : std:: env:: var( "CHROME_PATH" ) . ok( ) . unwrap_or( "" . to_string( ) ) } ) ,
407
436
None ,
408
437
) ;
@@ -421,21 +450,26 @@ async fn shinkai_tool_defillama_lending_tvl_rankings() {
421
450
assert_eq ! ( run_result. unwrap( ) . data[ "rowsCount" ] , 43 ) ;
422
451
}
423
452
424
- // TODO: enable this test again when fix the tool
453
+ // // TODO: enable this test again when fix the tool
425
454
// #[tokio::test]
426
455
// async fn shinkai_tool_aave_loan_requester() {
427
456
// let _ = env_logger::builder()
428
457
// .filter_level(log::LevelFilter::Info)
429
458
// .is_test(true)
430
459
// .try_init();
431
460
// let tool_definition = get_tool("shinkai-tool-aave-loan-requester").unwrap();
461
+ // let code_files = CodeFiles {
462
+ // files: HashMap::from([("main.ts".to_string(), tool_definition.code.clone().unwrap())]),
463
+ // entrypoint: "main.ts".to_string(),
464
+ // };
432
465
// let tool = Tool::new(
433
- // tool_definition.code.clone().unwrap() ,
466
+ // code_files ,
434
467
// serde_json::json!({ "chromePath": std::env::var("CHROME_PATH").ok().unwrap_or("".to_string()) }),
435
468
// None,
436
469
// );
437
470
// let run_result = tool
438
471
// .run(
472
+ // None,
439
473
// serde_json::json!({ "inputValue": "0.005", "assetSymbol": "ETH" }),
440
474
// None,
441
475
// )
@@ -459,7 +493,11 @@ async fn shinkai_tool_youtube_summary() {
459
493
serde_json:: json!( { "apiUrl" : "http://127.0.0.1:11434" , "lang" : "en" } )
460
494
} ;
461
495
462
- let tool = Tool :: new ( tool_definition. code . clone ( ) . unwrap ( ) , configurations, None ) ;
496
+ let code_files = CodeFiles {
497
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
498
+ entrypoint : "main.ts" . to_string ( ) ,
499
+ } ;
500
+ let tool = Tool :: new ( code_files, configurations, None ) ;
463
501
let run_result = tool
464
502
. run (
465
503
None ,
@@ -481,14 +519,18 @@ async fn shinkai_tool_json_to_md() {
481
519
. is_test ( true )
482
520
. try_init ( ) ;
483
521
let tool_definition = get_tool ( "shinkai-tool-json-to-md" ) . unwrap ( ) ;
522
+ let code_files = CodeFiles {
523
+ files : HashMap :: from ( [ ( "main.ts" . to_string ( ) , tool_definition. code . clone ( ) . unwrap ( ) ) ] ) ,
524
+ entrypoint : "main.ts" . to_string ( ) ,
525
+ } ;
484
526
let tool = Tool :: new (
485
- tool_definition . code . clone ( ) . unwrap ( ) ,
486
- json ! ( {
527
+ code_files ,
528
+ serde_json :: json!( {
487
529
"only_system" : false
488
530
} ) ,
489
531
None ,
490
532
) ;
491
- let message = json ! ( {
533
+ let message = serde_json :: json!( {
492
534
"relevantSentencesFromText" : [
493
535
{
494
536
"citation_id" : 5 ,
0 commit comments