import { getImportsFromCode } from "@tscircuit/prompt-benchmarks/code-runner-utils" import { evalCompiledJs } from "./eval-compiled-js" import type { ExecutionContext } from "./execution-context" import * as Babel from "@babel/standalone" import { importLocalFile } from "./import-local-file" import { importEvalPath } from "./import-eval-path" export async function importSnippet( importName: string, ctx: ExecutionContext, depth = 0, ) { const { preSuppliedImports } = ctx const fullSnippetName = importName.replace("@tsci/", "").replace(".", "/") const { cjs, error } = await fetch(`${ctx.cjsRegistryUrl}/${fullSnippetName}`) .then(async (res) => ({ cjs: await res.text(), error: null })) .catch((e) => ({ error: e, cjs: null })) if (error) { console.error("Error fetching import", importName, error) return } try { preSuppliedImports[importName] = evalCompiledJs( cjs!, preSuppliedImports, ).exports } catch (e) { console.error("Error importing snippet", e) } }