diff --git a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx index 3270809e81..5d3dc36018 100644 --- a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx @@ -1045,7 +1045,7 @@ function UserMessage(props: { - {ctx.usernameVisible() ? `${sync.data.config.username ?? "You"}` : "You"} + {ctx.usernameVisible() ? `${sync.data.config.username ?? "You "}` : "You "} ${dir}/openapi.json`.cwd(path.resolve(dir, "../../ope await $`rm -rf src/gen` -await createClient({ - input: "./openapi.json", - output: { - path: "./src/gen", - tsConfigPath: path.join(dir, "tsconfig.json"), - clean: true, - }, - plugins: [ - { - name: "@hey-api/typescript", - exportFromIndex: false, - }, - { - name: "@hey-api/sdk", - instance: "OpencodeClient", - exportFromIndex: false, - auth: false, - }, - { - name: "@hey-api/client-fetch", - exportFromIndex: false, - baseUrl: "http://localhost:4096", - }, - ], -}) await createClient({ input: "./openapi.json", output: { diff --git a/packages/sdk/js/src/gen/client.gen.ts b/packages/sdk/js/src/gen/client.gen.ts index 0c110eca39..e7cdb292c6 100644 --- a/packages/sdk/js/src/gen/client.gen.ts +++ b/packages/sdk/js/src/gen/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import { type ClientOptions, type Config, createClient, createConfig } from "./client/index.js" -import type { ClientOptions as ClientOptions2 } from "./types.gen.js" +import type { ClientOptions } from "./types.gen.js" +import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from "./client/index.js" /** * The `createClientConfig()` function will be called on client initialization @@ -11,8 +11,12 @@ import type { ClientOptions as ClientOptions2 } from "./types.gen.js" * `setConfig()`. This is useful for example if you're using Next.js * to ensure your client always has the correct values. */ -export type CreateClientConfig = ( - override?: Config, -) => Config & T> +export type CreateClientConfig = ( + override?: Config, +) => Config & T> -export const client = createClient(createConfig({ baseUrl: "http://localhost:4096" })) +export const client = createClient( + createConfig({ + baseUrl: "http://localhost:4096", + }), +) diff --git a/packages/sdk/js/src/gen/client/client.gen.ts b/packages/sdk/js/src/gen/client/client.gen.ts index 47f1403429..34a8d0bece 100644 --- a/packages/sdk/js/src/gen/client/client.gen.ts +++ b/packages/sdk/js/src/gen/client/client.gen.ts @@ -1,8 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts import { createSseClient } from "../core/serverSentEvents.gen.js" -import type { HttpMethod } from "../core/types.gen.js" -import { getValidRequestBody } from "../core/utils.gen.js" import type { Client, Config, RequestOptions, ResolvedRequestOptions } from "./types.gen.js" import { buildUrl, @@ -51,12 +49,12 @@ export const createClient = (config: Config = {}): Client => { await opts.requestValidator(opts) } - if (opts.body !== undefined && opts.bodySerializer) { + if (opts.body && opts.bodySerializer) { opts.serializedBody = opts.bodySerializer(opts.body) } // remove Content-Type header if body is empty to avoid sending invalid requests - if (opts.body === undefined || opts.serializedBody === "") { + if (opts.serializedBody === undefined || opts.serializedBody === "") { opts.headers.delete("Content-Type") } @@ -71,12 +69,12 @@ export const createClient = (config: Config = {}): Client => { const requestInit: ReqInit = { redirect: "follow", ...opts, - body: getValidRequestBody(opts), + body: opts.serializedBody, } let request = new Request(url, requestInit) - for (const fn of interceptors.request.fns) { + for (const fn of interceptors.request._fns) { if (fn) { request = await fn(request, opts) } @@ -85,37 +83,9 @@ export const createClient = (config: Config = {}): Client => { // fetch must be assigned here, otherwise it would throw the error: // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation const _fetch = opts.fetch! - let response: Response + let response = await _fetch(request) - try { - response = await _fetch(request) - } catch (error) { - // Handle fetch exceptions (AbortError, network errors, etc.) - let finalError = error - - for (const fn of interceptors.error.fns) { - if (fn) { - finalError = (await fn(error, undefined as any, request, opts)) as unknown - } - } - - finalError = finalError || ({} as unknown) - - if (opts.throwOnError) { - throw finalError - } - - // Return error response - return opts.responseStyle === "data" - ? undefined - : { - error: finalError, - request, - response: undefined as any, - } - } - - for (const fn of interceptors.response.fns) { + for (const fn of interceptors.response._fns) { if (fn) { response = await fn(response, request, opts) } @@ -127,36 +97,18 @@ export const createClient = (config: Config = {}): Client => { } if (response.ok) { - const parseAs = - (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json" - if (response.status === 204 || response.headers.get("Content-Length") === "0") { - let emptyData: any - switch (parseAs) { - case "arrayBuffer": - case "blob": - case "text": - emptyData = await response[parseAs]() - break - case "formData": - emptyData = new FormData() - break - case "stream": - emptyData = response.body - break - case "json": - default: - emptyData = {} - break - } return opts.responseStyle === "data" - ? emptyData + ? {} : { - data: emptyData, + data: {}, ...result, } } + const parseAs = + (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json" + let data: any switch (parseAs) { case "arrayBuffer": @@ -205,7 +157,7 @@ export const createClient = (config: Config = {}): Client => { const error = jsonError ?? textError let finalError = error - for (const fn of interceptors.error.fns) { + for (const fn of interceptors.error._fns) { if (fn) { finalError = (await fn(error, response, request, opts)) as string } @@ -226,53 +178,35 @@ export const createClient = (config: Config = {}): Client => { } } - const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => request({ ...options, method }) - - const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { - const { opts, url } = await beforeRequest(options) - return createSseClient({ - ...opts, - body: opts.body as BodyInit | null | undefined, - headers: opts.headers as unknown as Record, - method, - onRequest: async (url, init) => { - let request = new Request(url, init) - for (const fn of interceptors.request.fns) { - if (fn) { - request = await fn(request, opts) - } - } - return request - }, - url, - }) + const makeMethod = (method: Required["method"]) => { + const fn = (options: RequestOptions) => request({ ...options, method }) + fn.sse = async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options) + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + url, + }) + } + return fn } return { buildUrl, - connect: makeMethodFn("CONNECT"), - delete: makeMethodFn("DELETE"), - get: makeMethodFn("GET"), + connect: makeMethod("CONNECT"), + delete: makeMethod("DELETE"), + get: makeMethod("GET"), getConfig, - head: makeMethodFn("HEAD"), + head: makeMethod("HEAD"), interceptors, - options: makeMethodFn("OPTIONS"), - patch: makeMethodFn("PATCH"), - post: makeMethodFn("POST"), - put: makeMethodFn("PUT"), + options: makeMethod("OPTIONS"), + patch: makeMethod("PATCH"), + post: makeMethod("POST"), + put: makeMethod("PUT"), request, setConfig, - sse: { - connect: makeSseFn("CONNECT"), - delete: makeSseFn("DELETE"), - get: makeSseFn("GET"), - head: makeSseFn("HEAD"), - options: makeSseFn("OPTIONS"), - patch: makeSseFn("PATCH"), - post: makeSseFn("POST"), - put: makeSseFn("PUT"), - trace: makeSseFn("TRACE"), - }, - trace: makeMethodFn("TRACE"), + trace: makeMethod("TRACE"), } as Client } diff --git a/packages/sdk/js/src/gen/client/index.ts b/packages/sdk/js/src/gen/client/index.ts index 0af63f3300..06f21e3d80 100644 --- a/packages/sdk/js/src/gen/client/index.ts +++ b/packages/sdk/js/src/gen/client/index.ts @@ -8,7 +8,6 @@ export { urlSearchParamsBodySerializer, } from "../core/bodySerializer.gen.js" export { buildClientParams } from "../core/params.gen.js" -export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js" export { createClient } from "./client.gen.js" export type { Client, @@ -16,6 +15,7 @@ export type { Config, CreateClientConfig, Options, + OptionsLegacyParser, RequestOptions, RequestResult, ResolvedRequestOptions, diff --git a/packages/sdk/js/src/gen/client/types.gen.ts b/packages/sdk/js/src/gen/client/types.gen.ts index e053aa4066..db8e544cfd 100644 --- a/packages/sdk/js/src/gen/client/types.gen.ts +++ b/packages/sdk/js/src/gen/client/types.gen.ts @@ -20,7 +20,7 @@ export interface Config * * @default globalThis.fetch */ - fetch?: typeof fetch + fetch?: (request: Request) => ReturnType /** * Please don't use the Fetch client for Next.js applications. The `next` * options won't have any effect. @@ -128,7 +128,7 @@ export interface ClientOptions { throwOnError?: boolean } -type MethodFn = < +type MethodFnBase = < TData = unknown, TError = unknown, ThrowOnError extends boolean = false, @@ -137,7 +137,7 @@ type MethodFn = < options: Omit, "method">, ) => RequestResult -type SseFn = < +type MethodFnServerSentEvents = < TData = unknown, TError = unknown, ThrowOnError extends boolean = false, @@ -146,6 +146,10 @@ type SseFn = < options: Omit, "method">, ) => Promise> +type MethodFn = MethodFnBase & { + sse: MethodFnServerSentEvents +} + type RequestFn = < TData = unknown, TError = unknown, @@ -164,10 +168,10 @@ type BuildUrlFn = < url: string }, >( - options: TData & Options, + options: Pick & Options, ) => string -export type Client = CoreClient & { +export type Client = CoreClient & { interceptors: Middleware } @@ -199,4 +203,20 @@ export type Options< TResponse = unknown, TResponseStyle extends ResponseStyle = "fields", > = OmitKeys, "body" | "path" | "query" | "url"> & - ([TData] extends [never] ? unknown : Omit) + Omit + +export type OptionsLegacyParser< + TData = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = "fields", +> = TData extends { body?: any } + ? TData extends { headers?: any } + ? OmitKeys, "body" | "headers" | "url"> & TData + : OmitKeys, "body" | "url"> & + TData & + Pick, "headers"> + : TData extends { headers?: any } + ? OmitKeys, "headers" | "url"> & + TData & + Pick, "body"> + : OmitKeys, "url"> & TData diff --git a/packages/sdk/js/src/gen/client/utils.gen.ts b/packages/sdk/js/src/gen/client/utils.gen.ts index 3b1dfb7871..209bfbe8e6 100644 --- a/packages/sdk/js/src/gen/client/utils.gen.ts +++ b/packages/sdk/js/src/gen/client/utils.gen.ts @@ -7,7 +7,7 @@ import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } fr import { getUrl } from "../core/utils.gen.js" import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen.js" -export const createQuerySerializer = ({ parameters = {}, ...args }: QuerySerializerOptions = {}) => { +export const createQuerySerializer = ({ allowReserved, array, object }: QuerySerializerOptions = {}) => { const querySerializer = (queryParams: T) => { const search: string[] = [] if (queryParams && typeof queryParams === "object") { @@ -18,31 +18,29 @@ export const createQuerySerializer = ({ parameters = {}, ...args }: continue } - const options = parameters[name] || args - if (Array.isArray(value)) { const serializedArray = serializeArrayParam({ - allowReserved: options.allowReserved, + allowReserved, explode: true, name, style: "form", value, - ...options.array, + ...array, }) if (serializedArray) search.push(serializedArray) } else if (typeof value === "object") { const serializedObject = serializeObjectParam({ - allowReserved: options.allowReserved, + allowReserved, explode: true, name, style: "deepObject", value: value as Record, - ...options.object, + ...object, }) if (serializedObject) search.push(serializedObject) } else { const serializedPrimitive = serializePrimitiveParam({ - allowReserved: options.allowReserved, + allowReserved, name, value: value as string, }) @@ -164,22 +162,14 @@ export const mergeConfigs = (a: Config, b: Config): Config => { return config } -const headersEntries = (headers: Headers): Array<[string, string]> => { - const entries: Array<[string, string]> = [] - headers.forEach((value, key) => { - entries.push([key, value]) - }) - return entries -} - export const mergeHeaders = (...headers: Array["headers"] | undefined>): Headers => { const mergedHeaders = new Headers() for (const header of headers) { - if (!header) { + if (!header || typeof header !== "object") { continue } - const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header) + const iterator = header instanceof Headers ? header.entries() : Object.entries(header) for (const [key, value] of iterator) { if (value === null) { @@ -210,53 +200,61 @@ type ReqInterceptor = (request: Req, options: Options) => Req | Pr type ResInterceptor = (response: Res, request: Req, options: Options) => Res | Promise class Interceptors { - fns: Array = [] + _fns: (Interceptor | null)[] - clear(): void { - this.fns = [] + constructor() { + this._fns = [] } - eject(id: number | Interceptor): void { - const index = this.getInterceptorIndex(id) - if (this.fns[index]) { - this.fns[index] = null - } - } - - exists(id: number | Interceptor): boolean { - const index = this.getInterceptorIndex(id) - return Boolean(this.fns[index]) + clear() { + this._fns = [] } getInterceptorIndex(id: number | Interceptor): number { if (typeof id === "number") { - return this.fns[id] ? id : -1 + return this._fns[id] ? id : -1 + } else { + return this._fns.indexOf(id) } - return this.fns.indexOf(id) } - - update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + exists(id: number | Interceptor) { const index = this.getInterceptorIndex(id) - if (this.fns[index]) { - this.fns[index] = fn - return id + return !!this._fns[index] + } + + eject(id: number | Interceptor) { + const index = this.getInterceptorIndex(id) + if (this._fns[index]) { + this._fns[index] = null } - return false } - use(fn: Interceptor): number { - this.fns.push(fn) - return this.fns.length - 1 + update(id: number | Interceptor, fn: Interceptor) { + const index = this.getInterceptorIndex(id) + if (this._fns[index]) { + this._fns[index] = fn + return id + } else { + return false + } + } + + use(fn: Interceptor) { + this._fns = [...this._fns, fn] + return this._fns.length - 1 } } +// `createInterceptors()` response, meant for external use as it does not +// expose internals export interface Middleware { - error: Interceptors> - request: Interceptors> - response: Interceptors> + error: Pick>, "eject" | "use"> + request: Pick>, "eject" | "use"> + response: Pick>, "eject" | "use"> } -export const createInterceptors = (): Middleware => ({ +// do not add `Middleware` as return type so we can use _fns internally +export const createInterceptors = () => ({ error: new Interceptors>(), request: new Interceptors>(), response: new Interceptors>(), diff --git a/packages/sdk/js/src/gen/core/bodySerializer.gen.ts b/packages/sdk/js/src/gen/core/bodySerializer.gen.ts index 9678fb08ec..0660616052 100644 --- a/packages/sdk/js/src/gen/core/bodySerializer.gen.ts +++ b/packages/sdk/js/src/gen/core/bodySerializer.gen.ts @@ -6,18 +6,10 @@ export type QuerySerializer = (query: Record) => string export type BodySerializer = (body: any) => any -type QuerySerializerOptionsObject = { +export interface QuerySerializerOptions { allowReserved?: boolean - array?: Partial> - object?: Partial> -} - -export type QuerySerializerOptions = QuerySerializerOptionsObject & { - /** - * Per-parameter serialization overrides. When provided, these settings - * override the global array/object settings for specific parameter names. - */ - parameters?: Record + array?: SerializerOptions + object?: SerializerOptions } const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { diff --git a/packages/sdk/js/src/gen/core/params.gen.ts b/packages/sdk/js/src/gen/core/params.gen.ts index 6e9d0b9add..68ad1a778e 100644 --- a/packages/sdk/js/src/gen/core/params.gen.ts +++ b/packages/sdk/js/src/gen/core/params.gen.ts @@ -23,17 +23,6 @@ export type Field = key?: string map?: string } - | { - /** - * Field name. This is the name we want the user to see and use. - */ - key: string - /** - * Field mapped name. This is the name we want to use in the request. - * If `in` is omitted, `map` aliases `key` to the transport layer. - */ - map: Slot - } export interface Fields { allowExtra?: Partial> @@ -52,14 +41,10 @@ const extraPrefixes = Object.entries(extraPrefixesMap) type KeyMap = Map< string, - | { - in: Slot - map?: string - } - | { - in?: never - map: Slot - } + { + in: Slot + map?: string + } > const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { @@ -75,10 +60,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { map: config.map, }) } - } else if ("key" in config) { - map.set(config.key, { - map: config.map, - }) } else if (config.args) { buildKeyMap(config.args, map) } @@ -127,9 +108,7 @@ export const buildClientParams = (args: ReadonlyArray, fields: FieldsCo if (config.key) { const field = map.get(config.key)! const name = field.map || config.key - if (field.in) { - ;(params[field.in] as Record)[name] = arg - } + ;(params[field.in] as Record)[name] = arg } else { params.body = arg } @@ -138,20 +117,16 @@ export const buildClientParams = (args: ReadonlyArray, fields: FieldsCo const field = map.get(key) if (field) { - if (field.in) { - const name = field.map || key - ;(params[field.in] as Record)[name] = value - } else { - params[field.map] = value - } + const name = field.map || key + ;(params[field.in] as Record)[name] = value } else { const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)) if (extra) { const [prefix, slot] = extra ;(params[slot] as Record)[key.slice(prefix.length)] = value - } else if ("allowExtra" in config && config.allowExtra) { - for (const [slot, allowed] of Object.entries(config.allowExtra)) { + } else { + for (const [slot, allowed] of Object.entries(config.allowExtra ?? {})) { if (allowed) { ;(params[slot as Slot] as Record)[key] = value break diff --git a/packages/sdk/js/src/gen/core/serverSentEvents.gen.ts b/packages/sdk/js/src/gen/core/serverSentEvents.gen.ts index 09ef3fb393..8f7fac549d 100644 --- a/packages/sdk/js/src/gen/core/serverSentEvents.gen.ts +++ b/packages/sdk/js/src/gen/core/serverSentEvents.gen.ts @@ -4,17 +4,6 @@ import type { Config } from "./types.gen.js" export type ServerSentEventsOptions = Omit & Pick & { - /** - * Fetch API implementation. You can use this option to provide a custom - * fetch instance. - * - * @default globalThis.fetch - */ - fetch?: typeof fetch - /** - * Implementing clients can call request interceptors inside this hook. - */ - onRequest?: (url: string, init: RequestInit) => Promise /** * Callback invoked when a network or parsing error occurs during streaming. * @@ -32,7 +21,6 @@ export type ServerSentEventsOptions = Omit) => void - serializedBody?: RequestInit["body"] /** * Default retry delay in milliseconds. * @@ -76,7 +64,6 @@ export type ServerSentEventsResult({ - onRequest, onSseError, onSseEvent, responseTransformer, @@ -112,21 +99,7 @@ export const createSseClient = ({ } try { - const requestInit: RequestInit = { - redirect: "follow", - ...options, - body: options.serializedBody, - headers, - signal, - } - let request = new Request(url, requestInit) - if (onRequest) { - request = await onRequest(url, requestInit) - } - // fetch must be assigned here, otherwise it would throw the error: - // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation - const _fetch = options.fetch ?? globalThis.fetch - const response = await _fetch(request) + const response = await fetch(url, { ...options, headers, signal }) if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`) diff --git a/packages/sdk/js/src/gen/core/types.gen.ts b/packages/sdk/js/src/gen/core/types.gen.ts index bfa77b8acd..16408b2d09 100644 --- a/packages/sdk/js/src/gen/core/types.gen.ts +++ b/packages/sdk/js/src/gen/core/types.gen.ts @@ -3,19 +3,24 @@ import type { Auth, AuthToken } from "./auth.gen.js" import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from "./bodySerializer.gen.js" -export type HttpMethod = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace" - -export type Client = { +export interface Client { /** * Returns the final request URL. */ buildUrl: BuildUrlFn + connect: MethodFn + delete: MethodFn + get: MethodFn getConfig: () => Config + head: MethodFn + options: MethodFn + patch: MethodFn + post: MethodFn + put: MethodFn request: RequestFn setConfig: (config: Config) => Config -} & { - [K in HttpMethod]: MethodFn -} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }) + trace: MethodFn +} export interface Config { /** @@ -42,7 +47,7 @@ export interface Config { * * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} */ - method?: Uppercase + method?: "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" /** * A function for serializing request query parameters. By default, arrays * will be exploded in form style, objects will be exploded in deepObject diff --git a/packages/sdk/js/src/gen/core/utils.gen.ts b/packages/sdk/js/src/gen/core/utils.gen.ts index 8a45f72698..be18c608a5 100644 --- a/packages/sdk/js/src/gen/core/utils.gen.ts +++ b/packages/sdk/js/src/gen/core/utils.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { BodySerializer, QuerySerializer } from "./bodySerializer.gen.js" +import type { QuerySerializer } from "./bodySerializer.gen.js" import { type ArraySeparatorStyle, serializeArrayParam, @@ -107,31 +107,3 @@ export const getUrl = ({ } return url } - -export function getValidRequestBody(options: { - body?: unknown - bodySerializer?: BodySerializer | null - serializedBody?: unknown -}) { - const hasBody = options.body !== undefined - const isSerializedBody = hasBody && options.bodySerializer - - if (isSerializedBody) { - if ("serializedBody" in options) { - const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== "" - - return hasSerializedBody ? options.serializedBody : null - } - - // not all clients implement a serializedBody property (i.e. client-axios) - return options.body !== "" ? options.body : null - } - - // plain/text body - if (hasBody) { - return options.body - } - - // no body was provided - return undefined -} diff --git a/packages/sdk/js/src/gen/sdk.gen.ts b/packages/sdk/js/src/gen/sdk.gen.ts index 57ad066fed..af69b42ffd 100644 --- a/packages/sdk/js/src/gen/sdk.gen.ts +++ b/packages/sdk/js/src/gen/sdk.gen.ts @@ -1,205 +1,205 @@ // This file is auto-generated by @hey-api/openapi-ts -import { client } from "./client.gen.js" -import type { Client, Options as Options2, TDataShape } from "./client/index.js" +import type { Options as ClientOptions, TDataShape, Client } from "./client/index.js" import type { - AppAgentsData, - AppAgentsResponses, - AppLogData, - AppLogErrors, - AppLogResponses, - AuthSetData, - AuthSetErrors, - AuthSetResponses, - CommandListData, - CommandListResponses, + GlobalEventData, + GlobalEventResponses, + ProjectListData, + ProjectListResponses, + ProjectCurrentData, + ProjectCurrentResponses, + PtyListData, + PtyListResponses, + PtyCreateData, + PtyCreateResponses, + PtyCreateErrors, + PtyRemoveData, + PtyRemoveResponses, + PtyRemoveErrors, + PtyGetData, + PtyGetResponses, + PtyGetErrors, + PtyUpdateData, + PtyUpdateResponses, + PtyUpdateErrors, + PtyConnectData, + PtyConnectResponses, + PtyConnectErrors, ConfigGetData, ConfigGetResponses, + ConfigUpdateData, + ConfigUpdateResponses, + ConfigUpdateErrors, + ToolIdsData, + ToolIdsResponses, + ToolIdsErrors, + ToolListData, + ToolListResponses, + ToolListErrors, + InstanceDisposeData, + InstanceDisposeResponses, + PathGetData, + PathGetResponses, + VcsGetData, + VcsGetResponses, + SessionListData, + SessionListResponses, + SessionCreateData, + SessionCreateResponses, + SessionCreateErrors, + SessionStatusData, + SessionStatusResponses, + SessionStatusErrors, + SessionDeleteData, + SessionDeleteResponses, + SessionDeleteErrors, + SessionGetData, + SessionGetResponses, + SessionGetErrors, + SessionUpdateData, + SessionUpdateResponses, + SessionUpdateErrors, + SessionChildrenData, + SessionChildrenResponses, + SessionChildrenErrors, + SessionTodoData, + SessionTodoResponses, + SessionTodoErrors, + SessionInitData, + SessionInitResponses, + SessionInitErrors, + SessionForkData, + SessionForkResponses, + SessionAbortData, + SessionAbortResponses, + SessionAbortErrors, + SessionUnshareData, + SessionUnshareResponses, + SessionUnshareErrors, + SessionShareData, + SessionShareResponses, + SessionShareErrors, + SessionDiffData, + SessionDiffResponses, + SessionDiffErrors, + SessionSummarizeData, + SessionSummarizeResponses, + SessionSummarizeErrors, + SessionMessagesData, + SessionMessagesResponses, + SessionMessagesErrors, + SessionPromptData, + SessionPromptResponses, + SessionPromptErrors, + SessionMessageData, + SessionMessageResponses, + SessionMessageErrors, + SessionPromptAsyncData, + SessionPromptAsyncResponses, + SessionPromptAsyncErrors, + SessionCommandData, + SessionCommandResponses, + SessionCommandErrors, + SessionShellData, + SessionShellResponses, + SessionShellErrors, + SessionRevertData, + SessionRevertResponses, + SessionRevertErrors, + SessionUnrevertData, + SessionUnrevertResponses, + SessionUnrevertErrors, + PostSessionIdPermissionsPermissionIdData, + PostSessionIdPermissionsPermissionIdResponses, + PostSessionIdPermissionsPermissionIdErrors, + CommandListData, + CommandListResponses, ConfigProvidersData, ConfigProvidersResponses, - ConfigUpdateData, - ConfigUpdateErrors, - ConfigUpdateResponses, - EventSubscribeData, - EventSubscribeResponses, + ProviderListData, + ProviderListResponses, + ProviderAuthData, + ProviderAuthResponses, + ProviderOauthAuthorizeData, + ProviderOauthAuthorizeResponses, + ProviderOauthAuthorizeErrors, + ProviderOauthCallbackData, + ProviderOauthCallbackResponses, + ProviderOauthCallbackErrors, + FindTextData, + FindTextResponses, + FindFilesData, + FindFilesResponses, + FindSymbolsData, + FindSymbolsResponses, FileListData, FileListResponses, FileReadData, FileReadResponses, FileStatusData, FileStatusResponses, - FindFilesData, - FindFilesResponses, - FindSymbolsData, - FindSymbolsResponses, - FindTextData, - FindTextResponses, - FormatterStatusData, - FormatterStatusResponses, - GlobalEventData, - GlobalEventResponses, - InstanceDisposeData, - InstanceDisposeResponses, - LspStatusData, - LspStatusResponses, - McpAddData, - McpAddErrors, - McpAddResponses, - McpAuthAuthenticateData, - McpAuthAuthenticateErrors, - McpAuthAuthenticateResponses, - McpAuthCallbackData, - McpAuthCallbackErrors, - McpAuthCallbackResponses, - McpAuthRemoveData, - McpAuthRemoveErrors, - McpAuthRemoveResponses, - McpAuthStartData, - McpAuthStartErrors, - McpAuthStartResponses, + AppLogData, + AppLogResponses, + AppLogErrors, + AppAgentsData, + AppAgentsResponses, McpStatusData, McpStatusResponses, - PathGetData, - PathGetResponses, - PermissionRespondData, - PermissionRespondErrors, - PermissionRespondResponses, - ProjectCurrentData, - ProjectCurrentResponses, - ProjectListData, - ProjectListResponses, - ProviderAuthData, - ProviderAuthResponses, - ProviderListData, - ProviderListResponses, - ProviderOauthAuthorizeData, - ProviderOauthAuthorizeErrors, - ProviderOauthAuthorizeResponses, - ProviderOauthCallbackData, - ProviderOauthCallbackErrors, - ProviderOauthCallbackResponses, - PtyConnectData, - PtyConnectErrors, - PtyConnectResponses, - PtyCreateData, - PtyCreateErrors, - PtyCreateResponses, - PtyGetData, - PtyGetErrors, - PtyGetResponses, - PtyListData, - PtyListResponses, - PtyRemoveData, - PtyRemoveErrors, - PtyRemoveResponses, - PtyUpdateData, - PtyUpdateErrors, - PtyUpdateResponses, - SessionAbortData, - SessionAbortErrors, - SessionAbortResponses, - SessionChildrenData, - SessionChildrenErrors, - SessionChildrenResponses, - SessionCommandData, - SessionCommandErrors, - SessionCommandResponses, - SessionCreateData, - SessionCreateErrors, - SessionCreateResponses, - SessionDeleteData, - SessionDeleteErrors, - SessionDeleteResponses, - SessionDiffData, - SessionDiffErrors, - SessionDiffResponses, - SessionForkData, - SessionForkResponses, - SessionGetData, - SessionGetErrors, - SessionGetResponses, - SessionInitData, - SessionInitErrors, - SessionInitResponses, - SessionListData, - SessionListResponses, - SessionMessageData, - SessionMessageErrors, - SessionMessageResponses, - SessionMessagesData, - SessionMessagesErrors, - SessionMessagesResponses, - SessionPromptAsyncData, - SessionPromptAsyncErrors, - SessionPromptAsyncResponses, - SessionPromptData, - SessionPromptErrors, - SessionPromptResponses, - SessionRevertData, - SessionRevertErrors, - SessionRevertResponses, - SessionShareData, - SessionShareErrors, - SessionShareResponses, - SessionShellData, - SessionShellErrors, - SessionShellResponses, - SessionStatusData, - SessionStatusErrors, - SessionStatusResponses, - SessionSummarizeData, - SessionSummarizeErrors, - SessionSummarizeResponses, - SessionTodoData, - SessionTodoErrors, - SessionTodoResponses, - SessionUnrevertData, - SessionUnrevertErrors, - SessionUnrevertResponses, - SessionUnshareData, - SessionUnshareErrors, - SessionUnshareResponses, - SessionUpdateData, - SessionUpdateErrors, - SessionUpdateResponses, - ToolIdsData, - ToolIdsErrors, - ToolIdsResponses, - ToolListData, - ToolListErrors, - ToolListResponses, + McpAddData, + McpAddResponses, + McpAddErrors, + McpAuthRemoveData, + McpAuthRemoveResponses, + McpAuthRemoveErrors, + McpAuthStartData, + McpAuthStartResponses, + McpAuthStartErrors, + McpAuthCallbackData, + McpAuthCallbackResponses, + McpAuthCallbackErrors, + McpAuthAuthenticateData, + McpAuthAuthenticateResponses, + McpAuthAuthenticateErrors, + LspStatusData, + LspStatusResponses, + FormatterStatusData, + FormatterStatusResponses, TuiAppendPromptData, - TuiAppendPromptErrors, TuiAppendPromptResponses, - TuiClearPromptData, - TuiClearPromptResponses, - TuiControlNextData, - TuiControlNextResponses, - TuiControlResponseData, - TuiControlResponseResponses, - TuiExecuteCommandData, - TuiExecuteCommandErrors, - TuiExecuteCommandResponses, + TuiAppendPromptErrors, TuiOpenHelpData, TuiOpenHelpResponses, - TuiOpenModelsData, - TuiOpenModelsResponses, TuiOpenSessionsData, TuiOpenSessionsResponses, TuiOpenThemesData, TuiOpenThemesResponses, - TuiPublishData, - TuiPublishErrors, - TuiPublishResponses, - TuiShowToastData, - TuiShowToastResponses, + TuiOpenModelsData, + TuiOpenModelsResponses, TuiSubmitPromptData, TuiSubmitPromptResponses, - VcsGetData, - VcsGetResponses, + TuiClearPromptData, + TuiClearPromptResponses, + TuiExecuteCommandData, + TuiExecuteCommandResponses, + TuiExecuteCommandErrors, + TuiShowToastData, + TuiShowToastResponses, + TuiPublishData, + TuiPublishResponses, + TuiPublishErrors, + TuiControlNextData, + TuiControlNextResponses, + TuiControlResponseData, + TuiControlResponseResponses, + AuthSetData, + AuthSetResponses, + AuthSetErrors, + EventSubscribeData, + EventSubscribeResponses, } from "./types.gen.js" +import { client as _heyApiClient } from "./client.gen.js" -export type Options = Options2< +export type Options = ClientOptions< TData, ThrowOnError > & { @@ -216,50 +216,34 @@ export type Options } -class HeyApiClient { - protected client: Client +class _HeyApiClient { + protected _client: Client = _heyApiClient constructor(args?: { client?: Client }) { - this.client = args?.client ?? client - } -} - -class HeyApiRegistry { - private readonly defaultKey = "default" - - private readonly instances: Map = new Map() - - get(key?: string): T { - const instance = this.instances.get(key ?? this.defaultKey) - if (!instance) { - throw new Error(`No SDK client found. Create one with "new OpencodeClient()" to fix this error.`) + if (args?.client) { + this._client = args.client } - return instance - } - - set(value: T, key?: string): void { - this.instances.set(key ?? this.defaultKey, value) } } -export class Global extends HeyApiClient { +class Global extends _HeyApiClient { /** * Get events */ public event(options?: Options) { - return (options?.client ?? this.client).sse.get({ + return (options?.client ?? this._client).get.sse({ url: "/global/event", ...options, }) } } -export class Project extends HeyApiClient { +class Project extends _HeyApiClient { /** * List all projects */ public list(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/project", ...options, }) @@ -269,26 +253,29 @@ export class Project extends HeyApiClient { * Get the current project */ public current(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/project/current", ...options, }) } } -export class Pty extends HeyApiClient { +class Pty extends _HeyApiClient { /** * List all PTY sessions */ public list(options?: Options) { - return (options?.client ?? this.client).get({ url: "/pty", ...options }) + return (options?.client ?? this._client).get({ + url: "/pty", + ...options, + }) } /** * Create a new PTY session */ public create(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/pty", ...options, headers: { @@ -302,8 +289,8 @@ export class Pty extends HeyApiClient { * Remove a PTY session */ public remove(options: Options) { - return (options.client ?? this.client).delete({ - url: "/pty/{ptyID}", + return (options.client ?? this._client).delete({ + url: "/pty/{id}", ...options, }) } @@ -312,8 +299,8 @@ export class Pty extends HeyApiClient { * Get PTY session info */ public get(options: Options) { - return (options.client ?? this.client).get({ - url: "/pty/{ptyID}", + return (options.client ?? this._client).get({ + url: "/pty/{id}", ...options, }) } @@ -322,8 +309,8 @@ export class Pty extends HeyApiClient { * Update PTY session */ public update(options: Options) { - return (options.client ?? this.client).put({ - url: "/pty/{ptyID}", + return (options.client ?? this._client).put({ + url: "/pty/{id}", ...options, headers: { "Content-Type": "application/json", @@ -336,19 +323,19 @@ export class Pty extends HeyApiClient { * Connect to a PTY session */ public connect(options: Options) { - return (options.client ?? this.client).get({ - url: "/pty/{ptyID}/connect", + return (options.client ?? this._client).get({ + url: "/pty/{id}/connect", ...options, }) } } -export class Config extends HeyApiClient { +class Config extends _HeyApiClient { /** * Get config info */ public get(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/config", ...options, }) @@ -358,7 +345,7 @@ export class Config extends HeyApiClient { * Update config */ public update(options?: Options) { - return (options?.client ?? this.client).patch({ + return (options?.client ?? this._client).patch({ url: "/config", ...options, headers: { @@ -372,19 +359,19 @@ export class Config extends HeyApiClient { * List all providers */ public providers(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/config/providers", ...options, }) } } -export class Tool extends HeyApiClient { +class Tool extends _HeyApiClient { /** * List all tool IDs (including built-in and dynamically registered) */ public ids(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/experimental/tool/ids", ...options, }) @@ -394,49 +381,55 @@ export class Tool extends HeyApiClient { * List tools with JSON schema parameters for a provider/model */ public list(options: Options) { - return (options.client ?? this.client).get({ + return (options.client ?? this._client).get({ url: "/experimental/tool", ...options, }) } } -export class Instance extends HeyApiClient { +class Instance extends _HeyApiClient { /** * Dispose the current instance */ public dispose(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/instance/dispose", ...options, }) } } -export class Path extends HeyApiClient { +class Path extends _HeyApiClient { /** * Get the current path */ public get(options?: Options) { - return (options?.client ?? this.client).get({ url: "/path", ...options }) + return (options?.client ?? this._client).get({ + url: "/path", + ...options, + }) } } -export class Vcs extends HeyApiClient { +class Vcs extends _HeyApiClient { /** * Get VCS info for the current instance */ public get(options?: Options) { - return (options?.client ?? this.client).get({ url: "/vcs", ...options }) + return (options?.client ?? this._client).get({ + url: "/vcs", + ...options, + }) } } -export class Session extends HeyApiClient { +class Session extends _HeyApiClient { /** * List all sessions */ public list(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/session", ...options, }) @@ -446,7 +439,7 @@ export class Session extends HeyApiClient { * Create a new session */ public create(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/session", ...options, headers: { @@ -460,7 +453,7 @@ export class Session extends HeyApiClient { * Get session status */ public status(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/session/status", ...options, }) @@ -470,8 +463,8 @@ export class Session extends HeyApiClient { * Delete a session and all its data */ public delete(options: Options) { - return (options.client ?? this.client).delete({ - url: "/session/{sessionID}", + return (options.client ?? this._client).delete({ + url: "/session/{id}", ...options, }) } @@ -480,8 +473,8 @@ export class Session extends HeyApiClient { * Get session */ public get(options: Options) { - return (options.client ?? this.client).get({ - url: "/session/{sessionID}", + return (options.client ?? this._client).get({ + url: "/session/{id}", ...options, }) } @@ -490,8 +483,8 @@ export class Session extends HeyApiClient { * Update session properties */ public update(options: Options) { - return (options.client ?? this.client).patch({ - url: "/session/{sessionID}", + return (options.client ?? this._client).patch({ + url: "/session/{id}", ...options, headers: { "Content-Type": "application/json", @@ -504,8 +497,8 @@ export class Session extends HeyApiClient { * Get a session's children */ public children(options: Options) { - return (options.client ?? this.client).get({ - url: "/session/{sessionID}/children", + return (options.client ?? this._client).get({ + url: "/session/{id}/children", ...options, }) } @@ -514,8 +507,8 @@ export class Session extends HeyApiClient { * Get the todo list for a session */ public todo(options: Options) { - return (options.client ?? this.client).get({ - url: "/session/{sessionID}/todo", + return (options.client ?? this._client).get({ + url: "/session/{id}/todo", ...options, }) } @@ -524,8 +517,8 @@ export class Session extends HeyApiClient { * Analyze the app and create an AGENTS.md file */ public init(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/init", + return (options.client ?? this._client).post({ + url: "/session/{id}/init", ...options, headers: { "Content-Type": "application/json", @@ -538,8 +531,8 @@ export class Session extends HeyApiClient { * Fork an existing session at a specific message */ public fork(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/fork", + return (options.client ?? this._client).post({ + url: "/session/{id}/fork", ...options, headers: { "Content-Type": "application/json", @@ -552,8 +545,8 @@ export class Session extends HeyApiClient { * Abort a session */ public abort(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/abort", + return (options.client ?? this._client).post({ + url: "/session/{id}/abort", ...options, }) } @@ -562,8 +555,8 @@ export class Session extends HeyApiClient { * Unshare the session */ public unshare(options: Options) { - return (options.client ?? this.client).delete({ - url: "/session/{sessionID}/share", + return (options.client ?? this._client).delete({ + url: "/session/{id}/share", ...options, }) } @@ -572,8 +565,8 @@ export class Session extends HeyApiClient { * Share a session */ public share(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/share", + return (options.client ?? this._client).post({ + url: "/session/{id}/share", ...options, }) } @@ -582,8 +575,8 @@ export class Session extends HeyApiClient { * Get the diff for this session */ public diff(options: Options) { - return (options.client ?? this.client).get({ - url: "/session/{sessionID}/diff", + return (options.client ?? this._client).get({ + url: "/session/{id}/diff", ...options, }) } @@ -592,8 +585,8 @@ export class Session extends HeyApiClient { * Summarize the session */ public summarize(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/summarize", + return (options.client ?? this._client).post({ + url: "/session/{id}/summarize", ...options, headers: { "Content-Type": "application/json", @@ -606,8 +599,8 @@ export class Session extends HeyApiClient { * List messages for a session */ public messages(options: Options) { - return (options.client ?? this.client).get({ - url: "/session/{sessionID}/message", + return (options.client ?? this._client).get({ + url: "/session/{id}/message", ...options, }) } @@ -616,8 +609,8 @@ export class Session extends HeyApiClient { * Create and send a new message to a session */ public prompt(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/message", + return (options.client ?? this._client).post({ + url: "/session/{id}/message", ...options, headers: { "Content-Type": "application/json", @@ -630,8 +623,8 @@ export class Session extends HeyApiClient { * Get a message from a session */ public message(options: Options) { - return (options.client ?? this.client).get({ - url: "/session/{sessionID}/message/{messageID}", + return (options.client ?? this._client).get({ + url: "/session/{id}/message/{messageID}", ...options, }) } @@ -640,8 +633,8 @@ export class Session extends HeyApiClient { * Create and send a new message to a session, start if needed and return immediately */ public promptAsync(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/prompt_async", + return (options.client ?? this._client).post({ + url: "/session/{id}/prompt_async", ...options, headers: { "Content-Type": "application/json", @@ -654,8 +647,8 @@ export class Session extends HeyApiClient { * Send a new command to a session */ public command(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/command", + return (options.client ?? this._client).post({ + url: "/session/{id}/command", ...options, headers: { "Content-Type": "application/json", @@ -668,8 +661,8 @@ export class Session extends HeyApiClient { * Run a shell command */ public shell(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/shell", + return (options.client ?? this._client).post({ + url: "/session/{id}/shell", ...options, headers: { "Content-Type": "application/json", @@ -682,8 +675,8 @@ export class Session extends HeyApiClient { * Revert a message */ public revert(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/revert", + return (options.client ?? this._client).post({ + url: "/session/{id}/revert", ...options, headers: { "Content-Type": "application/json", @@ -696,52 +689,36 @@ export class Session extends HeyApiClient { * Restore all reverted messages */ public unrevert(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/unrevert", + return (options.client ?? this._client).post({ + url: "/session/{id}/unrevert", ...options, }) } } -export class Permission extends HeyApiClient { - /** - * Respond to a permission request - */ - public respond(options: Options) { - return (options.client ?? this.client).post({ - url: "/session/{sessionID}/permissions/{permissionID}", - ...options, - headers: { - "Content-Type": "application/json", - ...options.headers, - }, - }) - } -} - -export class Command extends HeyApiClient { +class Command extends _HeyApiClient { /** * List all commands */ public list(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/command", ...options, }) } } -export class Oauth extends HeyApiClient { +class Oauth extends _HeyApiClient { /** * Authorize a provider using OAuth */ public authorize(options: Options) { - return (options.client ?? this.client).post< + return (options.client ?? this._client).post< ProviderOauthAuthorizeResponses, ProviderOauthAuthorizeErrors, ThrowOnError >({ - url: "/provider/{providerID}/oauth/authorize", + url: "/provider/{id}/oauth/authorize", ...options, headers: { "Content-Type": "application/json", @@ -754,12 +731,12 @@ export class Oauth extends HeyApiClient { * Handle OAuth callback for a provider */ public callback(options: Options) { - return (options.client ?? this.client).post< + return (options.client ?? this._client).post< ProviderOauthCallbackResponses, ProviderOauthCallbackErrors, ThrowOnError >({ - url: "/provider/{providerID}/oauth/callback", + url: "/provider/{id}/oauth/callback", ...options, headers: { "Content-Type": "application/json", @@ -769,12 +746,12 @@ export class Oauth extends HeyApiClient { } } -export class Provider extends HeyApiClient { +class Provider extends _HeyApiClient { /** * List all providers */ public list(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/provider", ...options, }) @@ -784,28 +761,30 @@ export class Provider extends HeyApiClient { * Get provider authentication methods */ public auth(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/provider/auth", ...options, }) } - - oauth = new Oauth({ client: this.client }) + oauth = new Oauth({ client: this._client }) } -export class Find extends HeyApiClient { +class Find extends _HeyApiClient { /** * Find text in files */ public text(options: Options) { - return (options.client ?? this.client).get({ url: "/find", ...options }) + return (options.client ?? this._client).get({ + url: "/find", + ...options, + }) } /** * Find files */ public files(options: Options) { - return (options.client ?? this.client).get({ + return (options.client ?? this._client).get({ url: "/find/file", ...options, }) @@ -815,26 +794,29 @@ export class Find extends HeyApiClient { * Find workspace symbols */ public symbols(options: Options) { - return (options.client ?? this.client).get({ + return (options.client ?? this._client).get({ url: "/find/symbol", ...options, }) } } -export class File extends HeyApiClient { +class File extends _HeyApiClient { /** * List files and directories */ public list(options: Options) { - return (options.client ?? this.client).get({ url: "/file", ...options }) + return (options.client ?? this._client).get({ + url: "/file", + ...options, + }) } /** * Read a file */ public read(options: Options) { - return (options.client ?? this.client).get({ + return (options.client ?? this._client).get({ url: "/file/content", ...options, }) @@ -844,19 +826,19 @@ export class File extends HeyApiClient { * Get file status */ public status(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/file/status", ...options, }) } } -export class App extends HeyApiClient { +class App extends _HeyApiClient { /** * Write a log entry to the server logs */ public log(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/log", ...options, headers: { @@ -870,19 +852,19 @@ export class App extends HeyApiClient { * List all agents */ public agents(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/agent", ...options, }) } } -export class Auth extends HeyApiClient { +class Auth extends _HeyApiClient { /** * Remove OAuth credentials for an MCP server */ public remove(options: Options) { - return (options.client ?? this.client).delete({ + return (options.client ?? this._client).delete({ url: "/mcp/{name}/auth", ...options, }) @@ -892,7 +874,7 @@ export class Auth extends HeyApiClient { * Start OAuth authentication flow for an MCP server */ public start(options: Options) { - return (options.client ?? this.client).post({ + return (options.client ?? this._client).post({ url: "/mcp/{name}/auth", ...options, }) @@ -902,7 +884,7 @@ export class Auth extends HeyApiClient { * Complete OAuth authentication with authorization code */ public callback(options: Options) { - return (options.client ?? this.client).post({ + return (options.client ?? this._client).post({ url: "/mcp/{name}/auth/callback", ...options, headers: { @@ -916,18 +898,20 @@ export class Auth extends HeyApiClient { * Start OAuth flow and wait for callback (opens browser) */ public authenticate(options: Options) { - return (options.client ?? this.client).post({ - url: "/mcp/{name}/auth/authenticate", - ...options, - }) + return (options.client ?? this._client).post( + { + url: "/mcp/{name}/auth/authenticate", + ...options, + }, + ) } /** * Set authentication credentials */ public set(options: Options) { - return (options.client ?? this.client).put({ - url: "/auth/{providerID}", + return (options.client ?? this._client).put({ + url: "/auth/{id}", ...options, headers: { "Content-Type": "application/json", @@ -937,19 +921,22 @@ export class Auth extends HeyApiClient { } } -export class Mcp extends HeyApiClient { +class Mcp extends _HeyApiClient { /** * Get MCP server status */ public status(options?: Options) { - return (options?.client ?? this.client).get({ url: "/mcp", ...options }) + return (options?.client ?? this._client).get({ + url: "/mcp", + ...options, + }) } /** * Add MCP server dynamically */ public add(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/mcp", ...options, headers: { @@ -958,37 +945,39 @@ export class Mcp extends HeyApiClient { }, }) } - - auth = new Auth({ client: this.client }) + auth = new Auth({ client: this._client }) } -export class Lsp extends HeyApiClient { +class Lsp extends _HeyApiClient { /** * Get LSP server status */ public status(options?: Options) { - return (options?.client ?? this.client).get({ url: "/lsp", ...options }) + return (options?.client ?? this._client).get({ + url: "/lsp", + ...options, + }) } } -export class Formatter extends HeyApiClient { +class Formatter extends _HeyApiClient { /** * Get formatter status */ public status(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/formatter", ...options, }) } } -export class Control extends HeyApiClient { +class Control extends _HeyApiClient { /** * Get the next TUI request from the queue */ public next(options?: Options) { - return (options?.client ?? this.client).get({ + return (options?.client ?? this._client).get({ url: "/tui/control/next", ...options, }) @@ -998,7 +987,7 @@ export class Control extends HeyApiClient { * Submit a response to the TUI request queue */ public response(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/control/response", ...options, headers: { @@ -1009,12 +998,12 @@ export class Control extends HeyApiClient { } } -export class Tui extends HeyApiClient { +class Tui extends _HeyApiClient { /** * Append prompt to the TUI */ public appendPrompt(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/append-prompt", ...options, headers: { @@ -1028,7 +1017,7 @@ export class Tui extends HeyApiClient { * Open the help dialog */ public openHelp(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/open-help", ...options, }) @@ -1038,7 +1027,7 @@ export class Tui extends HeyApiClient { * Open the session dialog */ public openSessions(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/open-sessions", ...options, }) @@ -1048,7 +1037,7 @@ export class Tui extends HeyApiClient { * Open the theme dialog */ public openThemes(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/open-themes", ...options, }) @@ -1058,7 +1047,7 @@ export class Tui extends HeyApiClient { * Open the model dialog */ public openModels(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/open-models", ...options, }) @@ -1068,7 +1057,7 @@ export class Tui extends HeyApiClient { * Submit the prompt */ public submitPrompt(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/submit-prompt", ...options, }) @@ -1078,7 +1067,7 @@ export class Tui extends HeyApiClient { * Clear the prompt */ public clearPrompt(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/clear-prompt", ...options, }) @@ -1088,7 +1077,7 @@ export class Tui extends HeyApiClient { * Execute a TUI command (e.g. agent_cycle) */ public executeCommand(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/execute-command", ...options, headers: { @@ -1102,7 +1091,7 @@ export class Tui extends HeyApiClient { * Show a toast notification in the TUI */ public showToast(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/show-toast", ...options, headers: { @@ -1116,7 +1105,7 @@ export class Tui extends HeyApiClient { * Publish a TUI event */ public publish(options?: Options) { - return (options?.client ?? this.client).post({ + return (options?.client ?? this._client).post({ url: "/tui/publish", ...options, headers: { @@ -1125,69 +1114,59 @@ export class Tui extends HeyApiClient { }, }) } - - control = new Control({ client: this.client }) + control = new Control({ client: this._client }) } -export class Event extends HeyApiClient { +class Event extends _HeyApiClient { /** * Get events */ public subscribe(options?: Options) { - return (options?.client ?? this.client).sse.get({ + return (options?.client ?? this._client).get.sse({ url: "/event", ...options, }) } } -export class OpencodeClient extends HeyApiClient { - public static readonly __registry = new HeyApiRegistry() - - constructor(args?: { client?: Client; key?: string }) { - super(args) - OpencodeClient.__registry.set(this, args?.key) +export class OpencodeClient extends _HeyApiClient { + /** + * Respond to a permission request + */ + public postSessionIdPermissionsPermissionId( + options: Options, + ) { + return (options.client ?? this._client).post< + PostSessionIdPermissionsPermissionIdResponses, + PostSessionIdPermissionsPermissionIdErrors, + ThrowOnError + >({ + url: "/session/{id}/permissions/{permissionID}", + ...options, + headers: { + "Content-Type": "application/json", + ...options.headers, + }, + }) } - - global = new Global({ client: this.client }) - - project = new Project({ client: this.client }) - - pty = new Pty({ client: this.client }) - - config = new Config({ client: this.client }) - - tool = new Tool({ client: this.client }) - - instance = new Instance({ client: this.client }) - - path = new Path({ client: this.client }) - - vcs = new Vcs({ client: this.client }) - - session = new Session({ client: this.client }) - - permission = new Permission({ client: this.client }) - - command = new Command({ client: this.client }) - - provider = new Provider({ client: this.client }) - - find = new Find({ client: this.client }) - - file = new File({ client: this.client }) - - app = new App({ client: this.client }) - - mcp = new Mcp({ client: this.client }) - - lsp = new Lsp({ client: this.client }) - - formatter = new Formatter({ client: this.client }) - - tui = new Tui({ client: this.client }) - - auth = new Auth({ client: this.client }) - - event = new Event({ client: this.client }) + global = new Global({ client: this._client }) + project = new Project({ client: this._client }) + pty = new Pty({ client: this._client }) + config = new Config({ client: this._client }) + tool = new Tool({ client: this._client }) + instance = new Instance({ client: this._client }) + path = new Path({ client: this._client }) + vcs = new Vcs({ client: this._client }) + session = new Session({ client: this._client }) + command = new Command({ client: this._client }) + provider = new Provider({ client: this._client }) + find = new Find({ client: this._client }) + file = new File({ client: this._client }) + app = new App({ client: this._client }) + mcp = new Mcp({ client: this._client }) + lsp = new Lsp({ client: this._client }) + formatter = new Formatter({ client: this._client }) + tui = new Tui({ client: this._client }) + auth = new Auth({ client: this._client }) + event = new Event({ client: this._client }) } diff --git a/packages/sdk/js/src/gen/types.gen.ts b/packages/sdk/js/src/gen/types.gen.ts index 8bbfa40a32..5267c0e51e 100644 --- a/packages/sdk/js/src/gen/types.gen.ts +++ b/packages/sdk/js/src/gen/types.gen.ts @@ -1,9 +1,5 @@ // This file is auto-generated by @hey-api/openapi-ts -export type ClientOptions = { - baseUrl: `${string}://${string}` | (string & {}) -} - export type EventServerInstanceDisposed = { type: "server.instance.disposed" properties: { @@ -626,20 +622,22 @@ export type EventTuiCommandExecute = { type: "tui.command.execute" properties: { command: - | "session.list" - | "session.new" - | "session.share" - | "session.interrupt" - | "session.compact" - | "session.page.up" - | "session.page.down" - | "session.half.page.up" - | "session.half.page.down" - | "session.first" - | "session.last" - | "prompt.clear" - | "prompt.submit" - | "agent.cycle" + | ( + | "session.list" + | "session.new" + | "session.share" + | "session.interrupt" + | "session.compact" + | "session.page.up" + | "session.page.down" + | "session.half.page.up" + | "session.half.page.down" + | "session.first" + | "session.last" + | "prompt.clear" + | "prompt.submit" + | "agent.cycle" + ) | string } } @@ -979,9 +977,7 @@ export type AgentConfig = { permission?: { edit?: "ask" | "allow" | "deny" bash?: - | "ask" - | "allow" - | "deny" + | ("ask" | "allow" | "deny") | { [key: string]: "ask" | "allow" | "deny" } @@ -997,17 +993,12 @@ export type AgentConfig = { [key: string]: boolean } | boolean - | "subagent" - | "primary" - | "all" - | string + | ("subagent" | "primary" | "all") | number | { edit?: "ask" | "allow" | "deny" bash?: - | "ask" - | "allow" - | "deny" + | ("ask" | "allow" | "deny") | { [key: string]: "ask" | "allow" | "deny" } @@ -1083,7 +1074,7 @@ export type ProviderConfig = { * Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout. */ timeout?: number | false - [key: string]: unknown | string | boolean | number | false | undefined + [key: string]: unknown | string | boolean | (number | false) | undefined } } @@ -1311,9 +1302,7 @@ export type Config = { permission?: { edit?: "ask" | "allow" | "deny" bash?: - | "ask" - | "allow" - | "deny" + | ("ask" | "allow" | "deny") | { [key: string]: "ask" | "allow" | "deny" } @@ -1771,12 +1760,12 @@ export type PtyCreateResponse = PtyCreateResponses[keyof PtyCreateResponses] export type PtyRemoveData = { body?: never path: { - ptyID: string + id: string } query?: { directory?: string } - url: "/pty/{ptyID}" + url: "/pty/{id}" } export type PtyRemoveErrors = { @@ -1800,12 +1789,12 @@ export type PtyRemoveResponse = PtyRemoveResponses[keyof PtyRemoveResponses] export type PtyGetData = { body?: never path: { - ptyID: string + id: string } query?: { directory?: string } - url: "/pty/{ptyID}" + url: "/pty/{id}" } export type PtyGetErrors = { @@ -1835,12 +1824,12 @@ export type PtyUpdateData = { } } path: { - ptyID: string + id: string } query?: { directory?: string } - url: "/pty/{ptyID}" + url: "/pty/{id}" } export type PtyUpdateErrors = { @@ -1864,12 +1853,12 @@ export type PtyUpdateResponse = PtyUpdateResponses[keyof PtyUpdateResponses] export type PtyConnectData = { body?: never path: { - ptyID: string + id: string } query?: { directory?: string } - url: "/pty/{ptyID}/connect" + url: "/pty/{id}/connect" } export type PtyConnectErrors = { @@ -2125,12 +2114,12 @@ export type SessionStatusResponse = SessionStatusResponses[keyof SessionStatusRe export type SessionDeleteData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}" + url: "/session/{id}" } export type SessionDeleteErrors = { @@ -2158,12 +2147,12 @@ export type SessionDeleteResponse = SessionDeleteResponses[keyof SessionDeleteRe export type SessionGetData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}" + url: "/session/{id}" } export type SessionGetErrors = { @@ -2193,12 +2182,12 @@ export type SessionUpdateData = { title?: string } path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}" + url: "/session/{id}" } export type SessionUpdateErrors = { @@ -2226,12 +2215,12 @@ export type SessionUpdateResponse = SessionUpdateResponses[keyof SessionUpdateRe export type SessionChildrenData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/children" + url: "/session/{id}/children" } export type SessionChildrenErrors = { @@ -2262,12 +2251,12 @@ export type SessionTodoData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/todo" + url: "/session/{id}/todo" } export type SessionTodoErrors = { @@ -2302,12 +2291,12 @@ export type SessionInitData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/init" + url: "/session/{id}/init" } export type SessionInitErrors = { @@ -2337,12 +2326,12 @@ export type SessionForkData = { messageID?: string } path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/fork" + url: "/session/{id}/fork" } export type SessionForkResponses = { @@ -2357,12 +2346,12 @@ export type SessionForkResponse = SessionForkResponses[keyof SessionForkResponse export type SessionAbortData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/abort" + url: "/session/{id}/abort" } export type SessionAbortErrors = { @@ -2390,12 +2379,12 @@ export type SessionAbortResponse = SessionAbortResponses[keyof SessionAbortRespo export type SessionUnshareData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/share" + url: "/session/{id}/share" } export type SessionUnshareErrors = { @@ -2423,12 +2412,12 @@ export type SessionUnshareResponse = SessionUnshareResponses[keyof SessionUnshar export type SessionShareData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/share" + url: "/session/{id}/share" } export type SessionShareErrors = { @@ -2459,13 +2448,13 @@ export type SessionDiffData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string messageID?: string } - url: "/session/{sessionID}/diff" + url: "/session/{id}/diff" } export type SessionDiffErrors = { @@ -2499,12 +2488,12 @@ export type SessionSummarizeData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/summarize" + url: "/session/{id}/summarize" } export type SessionSummarizeErrors = { @@ -2535,13 +2524,13 @@ export type SessionMessagesData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string limit?: number } - url: "/session/{sessionID}/message" + url: "/session/{id}/message" } export type SessionMessagesErrors = { @@ -2588,12 +2577,12 @@ export type SessionPromptData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/message" + url: "/session/{id}/message" } export type SessionPromptErrors = { @@ -2627,7 +2616,7 @@ export type SessionMessageData = { /** * Session ID */ - sessionID: string + id: string /** * Message ID */ @@ -2636,7 +2625,7 @@ export type SessionMessageData = { query?: { directory?: string } - url: "/session/{sessionID}/message/{messageID}" + url: "/session/{id}/message/{messageID}" } export type SessionMessageErrors = { @@ -2683,12 +2672,12 @@ export type SessionPromptAsyncData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/prompt_async" + url: "/session/{id}/prompt_async" } export type SessionPromptAsyncErrors = { @@ -2725,12 +2714,12 @@ export type SessionCommandData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/command" + url: "/session/{id}/command" } export type SessionCommandErrors = { @@ -2771,12 +2760,12 @@ export type SessionShellData = { /** * Session ID */ - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/shell" + url: "/session/{id}/shell" } export type SessionShellErrors = { @@ -2807,12 +2796,12 @@ export type SessionRevertData = { partID?: string } path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/revert" + url: "/session/{id}/revert" } export type SessionRevertErrors = { @@ -2840,12 +2829,12 @@ export type SessionRevertResponse = SessionRevertResponses[keyof SessionRevertRe export type SessionUnrevertData = { body?: never path: { - sessionID: string + id: string } query?: { directory?: string } - url: "/session/{sessionID}/unrevert" + url: "/session/{id}/unrevert" } export type SessionUnrevertErrors = { @@ -2870,21 +2859,21 @@ export type SessionUnrevertResponses = { export type SessionUnrevertResponse = SessionUnrevertResponses[keyof SessionUnrevertResponses] -export type PermissionRespondData = { +export type PostSessionIdPermissionsPermissionIdData = { body?: { response: "once" | "always" | "reject" } path: { - sessionID: string + id: string permissionID: string } query?: { directory?: string } - url: "/session/{sessionID}/permissions/{permissionID}" + url: "/session/{id}/permissions/{permissionID}" } -export type PermissionRespondErrors = { +export type PostSessionIdPermissionsPermissionIdErrors = { /** * Bad request */ @@ -2895,16 +2884,18 @@ export type PermissionRespondErrors = { 404: NotFoundError } -export type PermissionRespondError = PermissionRespondErrors[keyof PermissionRespondErrors] +export type PostSessionIdPermissionsPermissionIdError = + PostSessionIdPermissionsPermissionIdErrors[keyof PostSessionIdPermissionsPermissionIdErrors] -export type PermissionRespondResponses = { +export type PostSessionIdPermissionsPermissionIdResponses = { /** * Permission processed successfully */ 200: boolean } -export type PermissionRespondResponse = PermissionRespondResponses[keyof PermissionRespondResponses] +export type PostSessionIdPermissionsPermissionIdResponse = + PostSessionIdPermissionsPermissionIdResponses[keyof PostSessionIdPermissionsPermissionIdResponses] export type CommandListData = { body?: never @@ -3050,12 +3041,12 @@ export type ProviderOauthAuthorizeData = { /** * Provider ID */ - providerID: string + id: string } query?: { directory?: string } - url: "/provider/{providerID}/oauth/authorize" + url: "/provider/{id}/oauth/authorize" } export type ProviderOauthAuthorizeErrors = { @@ -3091,12 +3082,12 @@ export type ProviderOauthCallbackData = { /** * Provider ID */ - providerID: string + id: string } query?: { directory?: string } - url: "/provider/{providerID}/oauth/callback" + url: "/provider/{id}/oauth/callback" } export type ProviderOauthCallbackErrors = { @@ -3800,12 +3791,12 @@ export type TuiControlResponseResponse = TuiControlResponseResponses[keyof TuiCo export type AuthSetData = { body?: Auth path: { - providerID: string + id: string } query?: { directory?: string } - url: "/auth/{providerID}" + url: "/auth/{id}" } export type AuthSetErrors = { @@ -3843,3 +3834,7 @@ export type EventSubscribeResponses = { } export type EventSubscribeResponse = EventSubscribeResponses[keyof EventSubscribeResponses] + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}) +}