You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let scope = &mut v8::EscapableHandleScope::new(scope);
21
-
let source = v8::String::new(scope, code).unwrap();
22
-
let script = v8::Script::compile(scope, source,None).unwrap();
23
-
let r = script.run(scope);
24
-
r.map(|v| scope.escape(v))
21
+
let source = v8::String::new(scope, code).ok_or("Failed to create V8 string")?;
22
+
let script = v8::Script::compile(scope, source,None).ok_or("Failed to compile script")?;
23
+
let r = script.run(scope).ok_or("Failed to run script")?;
24
+
Ok(scope.escape(r))
25
25
}
26
26
27
27
staticINIT:Once = Once::new();
@@ -60,12 +60,13 @@ pub struct RunJsResponse {
60
60
61
61
implIntoContentsforRunJsResponse{
62
62
fninto_contents(self) -> Vec<Content>{
63
-
vec![Content::json(
64
-
json!({
65
-
"output":self.output,
66
-
"heap":self.heap,
67
-
})
68
-
).expect("failed to convert run_js response to content")]
63
+
matchContent::json(json!({
64
+
"output":self.output,
65
+
"heap":self.heap,
66
+
})){
67
+
Ok(content) => vec![content],
68
+
Err(e) => vec![Content::text(format!("Failed to convert run_js response to content: {}", e))],
69
+
}
69
70
}
70
71
}
71
72
@@ -81,12 +82,9 @@ impl GenericService {
81
82
82
83
#[tool(description = "run javascript code in v8\n\nparams:\n- code: the javascript code to run\n- heap: the path to the heap file\n\nreturns:\n- output: the output of the javascript code\n- heap: the path to the heap file\n\nyou must send a heap file to the client. \n\n\nThe way the runtime works, is that there is no console.log. If you want the results of an execution, you must return it in the last line of code. \n\neg:\n\n```js\nconst result = 1 + 1;\nresult;\n```\n\nwould return:\n\n```\n2\n```\n\n")]
0 commit comments