diff options
| author | Adam <[email protected]> | 2025-10-03 09:04:28 -0500 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-10-03 09:04:28 -0500 |
| commit | 3fa280d21878ae391674a21758199df3d2d8c3b5 (patch) | |
| tree | f70c6ecafffeecc8e7a59dc9acef66c59a9ea54a /packages/desktop/src/context/sdk.tsx | |
| parent | 1d58b5548287a3e32ffce3abdcf0f2db08fdb155 (diff) | |
| download | opencode-3fa280d21878ae391674a21758199df3d2d8c3b5.tar.gz opencode-3fa280d21878ae391674a21758199df3d2d8c3b5.zip | |
chore: app -> desktop
Diffstat (limited to 'packages/desktop/src/context/sdk.tsx')
| -rw-r--r-- | packages/desktop/src/context/sdk.tsx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/desktop/src/context/sdk.tsx b/packages/desktop/src/context/sdk.tsx new file mode 100644 index 000000000..48595cf9d --- /dev/null +++ b/packages/desktop/src/context/sdk.tsx @@ -0,0 +1,29 @@ +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<typeof init> + +const ctx = createContext<SDKContext>() + +export function SDKProvider(props: ParentProps) { + const value = init() + return <ctx.Provider value={value}>{props.children}</ctx.Provider> +} + +export function useSDK() { + const value = useContext(ctx) + if (!value) { + throw new Error("useSDK must be used within a SDKProvider") + } + return value +} |
