|
|
@@ -6,11 +6,11 @@ description: Interact with opencode server over HTTP.
|
|
|
import config from "../../../../config.mjs"
|
|
|
export const typesUrl = `${config.github}/blob/dev/packages/sdk/js/src/gen/types.gen.ts`
|
|
|
|
|
|
-The `opencode serve` command runs a headless HTTP server that exposes an API that an opencode client, like the TUI, uses. You can use this to create your own opencode client and even control a currently running TUI.
|
|
|
+The `opencode serve` command runs a headless HTTP server that exposes an OpenAPI endpoint that an opencode client can use.
|
|
|
|
|
|
---
|
|
|
|
|
|
-## Usage
|
|
|
+### Usage
|
|
|
|
|
|
```bash
|
|
|
opencode serve [--port <number>] [--hostname <string>]
|
|
|
@@ -25,7 +25,32 @@ opencode serve [--port <number>] [--hostname <string>]
|
|
|
|
|
|
---
|
|
|
|
|
|
-## Docs
|
|
|
+### How it works
|
|
|
+
|
|
|
+When you run `opencode` it starts a TUI and a server. Where the TUI is the
|
|
|
+client that talks to the server. The server exposes an OpenAPI 3.1 spec
|
|
|
+endpoint. This endpoint is also used to generate an [SDK](/docs/sdk).
|
|
|
+
|
|
|
+:::tip
|
|
|
+Use the opencode server to interact with opencode programmatically.
|
|
|
+:::
|
|
|
+
|
|
|
+This architecture lets opencode support multiple clients and allows you to interact with opencode programmatically.
|
|
|
+
|
|
|
+You can run `opencode serve` to start a standalone server. If you have the
|
|
|
+opencode TUI running, `opencode serve` will start a new server.
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+#### Connect to an existing server
|
|
|
+
|
|
|
+When you start the TUI it randomly assigns a port and hostname. You can instead pass in the `--hostname` and `--port` [flags](/docs/cli). Then use this to connect to its server.
|
|
|
+
|
|
|
+The [`/tui`](#tui) endpoint can be used to drive the TUI through the server. For example, you can prefill or run a prompt. This setup is used by the opencode [IDE](/docs/ide) plugins.
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Spec
|
|
|
|
|
|
The server publishes an OpenAPI 3.1 spec that can be viewed at:
|
|
|
|