@opencode-ai/sdk
Advanced tools
+26
-0
@@ -5,2 +5,27 @@ export * from "./gen/types.gen.js"; | ||
| export { OpencodeClient }; | ||
| function pick(value, fallback) { | ||
| if (!value) | ||
| return; | ||
| if (!fallback) | ||
| return value; | ||
| if (value === fallback) | ||
| return fallback; | ||
| if (value === encodeURIComponent(fallback)) | ||
| return fallback; | ||
| return value; | ||
| } | ||
| function rewrite(request, directory) { | ||
| if (request.method !== "GET" && request.method !== "HEAD") | ||
| return request; | ||
| const value = pick(request.headers.get("x-opencode-directory"), directory); | ||
| if (!value) | ||
| return request; | ||
| const url = new URL(request.url); | ||
| if (!url.searchParams.has("directory")) { | ||
| url.searchParams.set("directory", value); | ||
| } | ||
| const next = new Request(url, request); | ||
| next.headers.delete("x-opencode-directory"); | ||
| return next; | ||
| } | ||
| export function createOpencodeClient(config) { | ||
@@ -25,3 +50,4 @@ if (!config?.fetch) { | ||
| const client = createClient(config); | ||
| client.interceptors.request.use((request) => rewrite(request, config?.directory)); | ||
| return new OpencodeClient({ client }); | ||
| } |
+40
-3
@@ -5,2 +5,37 @@ export * from "./gen/types.gen.js"; | ||
| export { OpencodeClient }; | ||
| function pick(value, fallback, encode) { | ||
| if (!value) | ||
| return; | ||
| if (!fallback) | ||
| return value; | ||
| if (value === fallback) | ||
| return fallback; | ||
| if (encode && value === encode(fallback)) | ||
| return fallback; | ||
| return value; | ||
| } | ||
| function rewrite(request, values) { | ||
| if (request.method !== "GET" && request.method !== "HEAD") | ||
| return request; | ||
| const url = new URL(request.url); | ||
| let changed = false; | ||
| for (const [name, key] of [ | ||
| ["x-opencode-directory", "directory"], | ||
| ["x-opencode-workspace", "workspace"], | ||
| ]) { | ||
| const value = pick(request.headers.get(name), key === "directory" ? values.directory : values.workspace, key === "directory" ? encodeURIComponent : undefined); | ||
| if (!value) | ||
| continue; | ||
| if (!url.searchParams.has(key)) { | ||
| url.searchParams.set(key, value); | ||
| } | ||
| changed = true; | ||
| } | ||
| if (!changed) | ||
| return request; | ||
| const next = new Request(url, request); | ||
| next.headers.delete("x-opencode-directory"); | ||
| next.headers.delete("x-opencode-workspace"); | ||
| return next; | ||
| } | ||
| export function createOpencodeClient(config) { | ||
@@ -19,7 +54,5 @@ if (!config?.fetch) { | ||
| if (config?.directory) { | ||
| const isNonASCII = /[^\x00-\x7F]/.test(config.directory); | ||
| const encodedDirectory = isNonASCII ? encodeURIComponent(config.directory) : config.directory; | ||
| config.headers = { | ||
| ...config.headers, | ||
| "x-opencode-directory": encodedDirectory, | ||
| "x-opencode-directory": encodeURIComponent(config.directory), | ||
| }; | ||
@@ -34,3 +67,7 @@ } | ||
| const client = createClient(config); | ||
| client.interceptors.request.use((request) => rewrite(request, { | ||
| directory: config?.directory, | ||
| workspace: config?.experimental_workspaceID, | ||
| })); | ||
| return new OpencodeClient({ client }); | ||
| } |
+1
-1
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "name": "@opencode-ai/sdk", | ||
| "version": "0.0.0-dev-202603261841", | ||
| "version": "0.0.0-dev-202603261900", | ||
| "type": "module", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
489848
0.41%16404
0.39%