Skip to content

Commit

Permalink
Update Core, Fix Types, Add Support for naming circuit (#55)
Browse files Browse the repository at this point in the history
* update core, fix type

* allow setting the name of the circuit
  • Loading branch information
seveibar authored Dec 31, 2024
1 parent 680be63 commit 36bbb4f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 7 additions & 1 deletion lib/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ export interface WebWorkerConfiguration {
}

export interface InternalWebWorkerApi {
execute: (code: string) => Promise<void>
execute: (
code: string,
opts?: {
name?: string
},
) => Promise<void>
executeWithFsMap(opts: {
entrypoint: string
fsMap: Record<string, string>
name?: string
}): Promise<void>
renderUntilSettled: () => Promise<void>
getCircuitJson: () => Promise<AnyCircuitElement[]>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@babel/standalone": "^7.26.2",
"@biomejs/biome": "^1.9.4",
"@tscircuit/core": "^0.0.241",
"@tscircuit/core": "^0.0.249",
"@tscircuit/prompt-benchmarks": "^0.0.20",
"@types/babel__standalone": "^7.1.9",
"@types/bun": "latest",
Expand Down
15 changes: 12 additions & 3 deletions webworker/execution-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Circuit } from "@tscircuit/core"
import { RootCircuit } from "@tscircuit/core"
import type { WebWorkerConfiguration } from "lib/shared/types"
import * as tscircuitCore from "@tscircuit/core"
import * as React from "react"
Expand All @@ -8,12 +8,21 @@ export interface ExecutionContext extends WebWorkerConfiguration {
fsMap: Record<string, string>
entrypoint: string
preSuppliedImports: Record<string, any>
circuit: Circuit
circuit: RootCircuit
}

export function createExecutionContext(
webWorkerConfiguration: WebWorkerConfiguration,
opts: {
name?: string
} = {},
): ExecutionContext {
const circuit = new RootCircuit()

if (opts.name) {
circuit.name = opts.name
}

return {
fsMap: {},
entrypoint: "",
Expand All @@ -26,7 +35,7 @@ export function createExecutionContext(
// ignore type imports in getImportsFromCode
"@tscircuit/props": {},
},
circuit: new Circuit(),
circuit,
...webWorkerConfiguration,
}
}
10 changes: 7 additions & 3 deletions webworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ const webWorkerApi = {
async executeWithFsMap(opts: {
entrypoint: string
fsMap: Record<string, string>
name?: string
}): Promise<void> {
if (webWorkerConfiguration.verbose) {
console.log("[Worker] executeWithFsMap called with:", {
entrypoint: opts.entrypoint,
fsMapKeys: Object.keys(opts.fsMap),
name: opts.name,
})
}
executionContext = createExecutionContext(webWorkerConfiguration)
executionContext = createExecutionContext(webWorkerConfiguration, {
name: opts.name,
})
executionContext.fsMap = normalizeFsMap(opts.fsMap)
if (!executionContext.fsMap[opts.entrypoint]) {
throw new Error(`Entrypoint "${opts.entrypoint}" not found`)
Expand All @@ -50,11 +54,11 @@ const webWorkerApi = {
await importEvalPath(opts.entrypoint, executionContext)
},

async execute(code: string) {
async execute(code: string, opts: { name?: string } = {}) {
if (webWorkerConfiguration.verbose) {
console.log("[Worker] execute called with code length:", code.length)
}
executionContext = createExecutionContext(webWorkerConfiguration)
executionContext = createExecutionContext(webWorkerConfiguration, opts)
executionContext.fsMap["entrypoint.tsx"] = code
;(globalThis as any).__tscircuit_circuit = executionContext.circuit

Expand Down

0 comments on commit 36bbb4f

Please sign in to comment.