MCPcopy Create free account
hub / github.com/AI45Lab/Code / script_source_with_host_entrypoint

Function script_source_with_host_entrypoint

core/src/tools/program_tool.rs:350–369  ·  view source on GitHub ↗
(source: &str)

Source from the content-addressed store, hash-verified

348}
349
350fn script_source_with_host_entrypoint(source: &str) -> Result<String> {
351 let rewritten = if source.contains("export default async function run") {
352 source.replacen("export default async function run", "async function run", 1)
353 } else if source.contains("export default function run") {
354 source.replacen("export default function run", "function run", 1)
355 } else if source.contains("async function run") || source.contains("function run") {
356 source.to_string()
357 } else {
358 return Err(anyhow!(
359 "PTC script must define async function run(ctx, inputs)"
360 ));
361 };
362
363 Ok(format!(
364 r#"{rewritten}
365
366globalThis.__a3sResultJson = (async () => JSON.stringify(await run(globalThis.__a3sCtx, globalThis.__a3sInputs)))();
367"#
368 ))
369}
370
371async fn run_embedded_script(
372 source: String,

Calls 1

containsMethod · 0.80