ugly but works

This commit is contained in:
Sebastian Herrlinger
2026-03-04 00:08:26 +01:00
parent 7e1d396427
commit 3b38e8dc24
9 changed files with 151 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ import type { BunShell } from "./shell"
import { type ToolDefinition } from "./tool"
export * from "./tool"
export { getTuiJSXRuntime, setTuiJSXRuntime, type TuiJSXRuntime } from "./jsx"
export type { CliRenderer, SlotMode } from "@opentui/core"
export type ProviderContext = {

View File

@@ -0,0 +1,8 @@
import { getTuiJSXRuntime } from "./jsx"
const runtime = getTuiJSXRuntime()
export const Fragment = runtime.Fragment
export const jsx = runtime.jsx
export const jsxs = runtime.jsxs
export const jsxDEV = runtime.jsxDEV ?? runtime.jsx

View File

@@ -0,0 +1,7 @@
import { getTuiJSXRuntime } from "./jsx"
const runtime = getTuiJSXRuntime()
export const Fragment = runtime.Fragment
export const jsx = runtime.jsx
export const jsxs = runtime.jsxs

View File

@@ -0,0 +1,27 @@
type TuiJSXFactory = (...args: unknown[]) => unknown
export type TuiJSXRuntime = {
Fragment: unknown
jsx: TuiJSXFactory
jsxs: TuiJSXFactory
jsxDEV?: TuiJSXFactory
}
const key = Symbol.for("opencode.tui.jsx-runtime")
export function setTuiJSXRuntime(runtime: TuiJSXRuntime) {
;(globalThis as Record<PropertyKey, unknown>)[key] = runtime
}
export function getTuiJSXRuntime() {
const runtime = (globalThis as Record<PropertyKey, unknown>)[key]
if (!runtime || typeof runtime !== "object") {
throw new Error("OpenCode TUI JSX runtime has not been initialized")
}
const jsx = (runtime as Record<string, unknown>).jsx
const jsxs = (runtime as Record<string, unknown>).jsxs
if (typeof jsx !== "function" || typeof jsxs !== "function") {
throw new Error("OpenCode TUI JSX runtime has invalid factories")
}
return runtime as TuiJSXRuntime
}