› cavi-ai/
GitHub ↗

@cavi-ai/api-client/providers/opencode

Package subpath: ./providers/opencode

createOpenCodeProviderModule#

Kind: function

ts
export declare function createOpenCodeProviderModule(config: OpenCodeApiClientOptions): OpenCodeProviderModule;

createOpenCodeV2ProviderModule#

Kind: function

ts
/** Select v2 explicitly; the existing OpenCode factory retains its v1 contract. */
export declare function createOpenCodeV2ProviderModule(config: OpenCodeV2ApiClientOptions): RuntimeProviderModule;

encodeOpenCodeSessionId#

Kind: function

ts
/** Validate and URL-encode a dynamic OpenCode session identifier. */
export declare function encodeOpenCodeSessionId(sessionId: unknown): string;

OPENCODE_ENDPOINT_FAMILY#

Kind: variable

ts
/** The route and transport family used by `opencode serve`. */
export declare const OPENCODE_ENDPOINT_FAMILY: "legacy-http-sse";

OPENCODE_OPENAPI_SHA256#

Kind: variable

ts
/** SHA-256 of the verified live OpenCode OpenAPI document. */
export declare const OPENCODE_OPENAPI_SHA256: "46db986090aae41846cd6dbe16225a1d883f0bbcb4c48814008d3f6ce140aa5c";

OPENCODE_RUNTIME_SUPPORT#

Kind: variable

ts
/** Derived from PROVIDER_CAPABILITIES — the single declaration site. */
export declare const OPENCODE_RUNTIME_SUPPORT: Readonly<Partial<Record<"runs" | "streaming" | "media" | "wiki" | "agentConfig" | "teams" | "kanban" | "workspace" | "operator" | "discourse" | "batch", boolean>>>;

OPENCODE_SERVER_VERSION#

Kind: variable

ts
/** The OpenCode server release whose legacy HTTP/SSE contract is supported. */
export declare const OPENCODE_SERVER_VERSION: "1.18.27";

OpenCodeApiClient#

Kind: class

ts
export declare class OpenCodeApiClient extends BaseHttpApiClient implements RuntimeClient {
    readonly request: HttpApiTransport;
    readonly scope: OpenCodeScope;
    private readonly defaultModel?;
    private readonly configuredPassword;
    private readonly authSecrets;
    private readonly runStore;
    private healthPromise?;
    constructor(options: OpenCodeApiClientOptions);
    getRuntimeCapabilities(): Promise<RuntimeCapabilities>;
    probeHealth(): Promise<OpenCodeHealthResponse>;
    private ensureHealth;
    private requestChecked;
    private cleanupSession;
    startRun(body: RuntimeRunStartBody): Promise<RuntimeRunStatus>;
    private modelString;
    getRun(runId: string): Promise<RuntimeRunStatus>;
    cancelRun(runId: string): Promise<{
        status: string;
    }>;
    streamRun(body: RuntimeRunStartBody, handlers: RunEventStreamHandlers, options?: {
        signal?: AbortSignal;
    }): Promise<void>;
}

OpenCodeApiClientOptions#

Kind: type

ts
export type OpenCodeApiClientOptions = {
    baseUrl: string;
    scope: OpenCodeScope;
    username?: string;
    password?: string;
    defaultModel?: string;
    fetchImpl?: typeof fetch;
    onTrace?: HttpApiClientOptions["onTrace"];
    defaultTimeoutMs?: number;
    cache?: RequestCache;
    credentials?: RequestCredentials;
};

OpenCodeScope#

Kind: type

ts
export type OpenCodeScope = {
    directory: string;
    workspace?: string;
};

OpenCodeV2ApiClient#

Kind: class

ts
/** Polling lifecycle for the v2 HTTP API; deliberately does not advertise v1 SSE support. */
export declare class OpenCodeV2ApiClient implements RuntimeClient {
    private readonly http;
    private readonly options;
    constructor(options: OpenCodeV2ApiClientOptions);
    getRuntimeCapabilities(): Promise<RuntimeCapabilities>;
    private session;
    startRun(body: RuntimeRunStartBody): Promise<RuntimeRunStatus>;
    getRun(runId: string): Promise<RuntimeRunStatus>;
    cancelRun(runId: string): Promise<{
        status: string;
    }>;
}

OpenCodeV2ApiClientOptions#

Kind: type

ts
/** OpenCode v2 uses location-scoped sessions. The v1 workspace selector is unsupported. */
export type OpenCodeV2ApiClientOptions = Omit<OpenCodeApiClientOptions, "scope"> & {
    scope: {
        directory: string;
    };
};

validateOpenCodeScope#

Kind: function

ts
/**
 * Validate a request scope while preserving the caller's path strings exactly.
 * Whitespace is used only for presence checks; path normalization is not part
 * of the OpenCode protocol contract.
 */
export declare function validateOpenCodeScope(scope: unknown): OpenCodeScope;