MCPcopy Create free account
hub / github.com/acoyfellow/cloudbox / runSample

Function runSample

web/src/components/SampleAgent.tsx:57–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55 }, [spec]);
56
57 async function runSample() {
58 if (!computer || running) return;
59 setRunning(true);
60 setError(null);
61 setArtifact(null);
62 setSelectedReceipt(null);
63 setGradeResult(null);
64 try {
65 const id = computer.id;
66 const tools = createCloudboxTools({
67 computerId: id,
68 origin: window.location.origin,
69 fetcher: globalThis.fetch.bind(globalThis),
70 headers: { "x-cloudbox-demo": "1" },
71 });
72 await runCloudboxAgent(runSpec ?? spec, tools);
73 await refresh(id);
74 await sleep(200);
75 const result = await grade(id);
76 setGradeResult(result);
77 const latest = await refresh(id);
78 const artifactPath = expectedArtifact(runSpec ?? spec);
79 if (artifactPath) {
80 const file = await readFile(id, artifactPath);
81 setArtifact({ path: artifactPath, content: file.content });
82 }
83 setSelectedReceipt(latest.at(-1) ?? null);
84 } catch (e) {
85 setError(e instanceof Error ? e.message : String(e));
86 } finally {
87 setRunning(false);
88 }
89 }
90
91 async function refresh(id: string) {
92 const res = await fetchReceipts(id);

Callers

nothing calls this directly

Calls 8

createCloudboxToolsFunction · 0.90
runCloudboxAgentFunction · 0.90
gradeFunction · 0.90
refreshFunction · 0.85
sleepFunction · 0.85
expectedArtifactFunction · 0.85
readFileFunction · 0.85
bindMethod · 0.45

Tested by

no test coverage detected