import { createContext, useContext, type ParentProps } from "solid-js" import { createOpencodeClient } from "@opencode-ai/sdk/client" const host = import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "127.0.0.1" const port = import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096" function init() { const client = createOpencodeClient({ baseUrl: `http://${host}:${port}`, }) return client } type SDKContext = ReturnType const ctx = createContext() export function SDKProvider(props: ParentProps) { const value = init() return {props.children} } export function useSDK() { const value = useContext(ctx) if (!value) { throw new Error("useSDK must be used within a SDKProvider") } return value }