v2 SDK HTTP client factory. Like module:sdk/client but also threads an experimental workspace id alongside the project directory onto outgoing requests, and rejects responses that indicate an incompatible server version.

Methods

(static) createClosedcodeClient(configopt) → {OpencodeClient}

Create a typed v2 client for a running closedcode server.

Parameters:
NameTypeAttributesDescription
configObject<optional>

Client configuration.

Properties
NameTypeAttributesDescription
baseUrlstring<optional>

Base URL of the closedcode server.

fetchfunction<optional>

Custom fetch implementation; defaults to global fetch with timeouts disabled.

directorystring<optional>

Project directory to scope requests to; sent as the x-closedcode-directory header / directory query parameter.

experimental_workspaceIDstring<optional>

Experimental workspace id; sent as the x-closedcode-workspace header / workspace query parameter.

headersObject<optional>

Additional headers to send with every request.

Returns:

A configured client instance that rejects responses from incompatible server versions.

Type: 
OpencodeClient

(inner) pick(value, fallback, encodeopt) → {string|undefined}

Return value unless it is merely an (optionally encoded) restatement of fallback, in which case the canonical fallback is preferred.

Parameters:
NameTypeAttributesDescription
valuestring | null | undefined

Candidate value (e.g. from a header).

fallbackstring | undefined

Canonical value to compare against.

encodefunction<optional>

Optional encoder ((input: string) => string) used when comparing against fallback.

Returns:

The resolved value, or undefined when none is set.

Type: 
string | undefined

(inner) rewrite(request, values) → {Request}

Move the x-closedcode-directory / x-closedcode-workspace hints onto the URL as directory / workspace query parameters for GET/HEAD requests, then strip the headers so they are not sent twice.

Parameters:
NameTypeDescription
requestRequest

The outgoing fetch request.

valuesObject

Fallback directory and workspace (both optional) used when the corresponding header is absent.

Returns:

The original request, or a rewritten copy carrying the hints.

Type: 
Request