mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-30 09:46:35 +00:00
ugly but works
This commit is contained in:
@@ -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
packages/plugin/src/jsx-dev-runtime.ts
Normal file
8
packages/plugin/src/jsx-dev-runtime.ts
Normal 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
packages/plugin/src/jsx-runtime.ts
Normal file
7
packages/plugin/src/jsx-runtime.ts
Normal 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
packages/plugin/src/jsx.ts
Normal file
27
packages/plugin/src/jsx.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user