()
| 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); |
nothing calls this directly
no test coverage detected