refactor(client): simplify local service lifecycle
This commit is contained in:
parent
4f1298063b
commit
75bc611ef1
51 changed files with 635 additions and 534 deletions
53
packages/client/src/service.ts
Normal file
53
packages/client/src/service.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/** Connection details for a local OpenCode service. */
|
||||
export type Endpoint = {
|
||||
/** Base URL of the service. */
|
||||
readonly url: string
|
||||
/** Authentication required by the service, when configured. */
|
||||
readonly auth?: {
|
||||
/** HTTP authentication scheme. */
|
||||
readonly type: "basic"
|
||||
/** Basic authentication username. */
|
||||
readonly username: string
|
||||
/** Basic authentication password. */
|
||||
readonly password: string
|
||||
}
|
||||
}
|
||||
|
||||
/** Options used to discover the local OpenCode service. */
|
||||
export type DiscoverOptions = {
|
||||
/** Absolute registration file path. Defaults to the XDG state directory. */
|
||||
readonly file?: string
|
||||
/** Required service version. */
|
||||
readonly version?: string
|
||||
}
|
||||
|
||||
/** Reason a new service process must be started. */
|
||||
export type StartReason = "missing" | "version-mismatch"
|
||||
|
||||
/** Options used to ensure the local OpenCode service is running. */
|
||||
export type StartOptions = DiscoverOptions & {
|
||||
/** Service command and arguments. Defaults to `opencode serve --service`. */
|
||||
readonly command?: ReadonlyArray<string>
|
||||
/** Called once before spawning a new service process. */
|
||||
readonly onStart?: (reason: StartReason, previousVersion?: string) => void
|
||||
}
|
||||
|
||||
/** Options used to stop the local OpenCode service. */
|
||||
export type StopOptions = {
|
||||
/** Absolute registration file path. Defaults to the XDG state directory. */
|
||||
readonly file?: string
|
||||
}
|
||||
|
||||
/** Contents of the local service registration file. */
|
||||
export type Info = {
|
||||
/** Unique service instance identifier. */
|
||||
readonly id?: string
|
||||
/** OpenCode version served by the process. */
|
||||
readonly version?: string
|
||||
/** Base URL advertised by the service. */
|
||||
readonly url: string
|
||||
/** Operating system process identifier. */
|
||||
readonly pid: number
|
||||
/** Private service password, when authentication is enabled. */
|
||||
readonly password?: string
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue