summaryrefslogtreecommitdiffhomepage
path: root/packages/sdk/js/src/v2/client.ts
diff options
context:
space:
mode:
authorDax <[email protected]>2025-12-07 19:04:14 -0500
committerGitHub <[email protected]>2025-12-07 19:04:14 -0500
commitea7ec60f51f9fe3c6382f644c328188a43545b7b (patch)
tree5204cbc059fe10b87c54ffd25782ad83710bdcdb /packages/sdk/js/src/v2/client.ts
parent6667856ba5dac3e5dd77c7008cee2d09be894472 (diff)
downloadopencode-ea7ec60f51f9fe3c6382f644c328188a43545b7b.tar.gz
opencode-ea7ec60f51f9fe3c6382f644c328188a43545b7b.zip
v2 SDK (#5216)
Co-authored-by: GitHub Action <[email protected]>
Diffstat (limited to 'packages/sdk/js/src/v2/client.ts')
-rw-r--r--packages/sdk/js/src/v2/client.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/sdk/js/src/v2/client.ts b/packages/sdk/js/src/v2/client.ts
new file mode 100644
index 000000000..806ad26e5
--- /dev/null
+++ b/packages/sdk/js/src/v2/client.ts
@@ -0,0 +1,30 @@
+export * from "./gen/types.gen.js"
+
+import { createClient } from "./gen/client/client.gen.js"
+import { type Config } from "./gen/client/types.gen.js"
+import { OpencodeClient } from "./gen/sdk.gen.js"
+export { type Config as OpencodeClientConfig, OpencodeClient }
+
+export function createOpencodeClient(config?: Config & { directory?: string }) {
+ if (!config?.fetch) {
+ const customFetch: any = (req: any) => {
+ // @ts-ignore
+ req.timeout = false
+ return fetch(req)
+ }
+ config = {
+ ...config,
+ fetch: customFetch,
+ }
+ }
+
+ if (config?.directory) {
+ config.headers = {
+ ...config.headers,
+ "x-opencode-directory": config.directory,
+ }
+ }
+
+ const client = createClient(config)
+ return new OpencodeClient({ client })
+}