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
+3 -1
View File
@@ -10,7 +10,9 @@
},
"exports": {
".": "./src/index.ts",
"./tool": "./src/tool.ts"
"./tool": "./src/tool.ts",
"./jsx-runtime": "./src/jsx-runtime.ts",
"./jsx-dev-runtime": "./src/jsx-dev-runtime.ts"
},
"files": [
"dist"
+1
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 = {
+8
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
+7
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
+27
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
}