server.mdx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. ---
  2. title: Server
  3. description: Komunicirajte s opencode serverom preko HTTP-a.
  4. ---
  5. import config from "../../../../config.mjs"
  6. export const typesUrl = `${config.github}/blob/dev/packages/sdk/js/src/gen/types.gen.ts`
  7. Komanda `opencode serve` pokrece headless HTTP server koji izlaže OpenAPI endpoint koji opencode klijent moze koristiti.
  8. ---
  9. ### Korištenje
  10. ```bash
  11. opencode serve [--port <number>] [--hostname <string>] [--cors <origin>]
  12. ```
  13. #### Opcije
  14. | Zastava | Opis | Default |
  15. | --------------- | ----------------------------------- | ---------------- |
  16. | `--port` | Port na kojem slusa | `4096` |
  17. | `--hostname` | Hostname na kojem slusa | `127.0.0.1` |
  18. | `--mdns` | Ukljuci mDNS otkrivanje | `false` |
  19. | `--mdns-domain` | Prilagodeni domen za mDNS servis | `opencode.local` |
  20. | `--cors` | Dodatni browser origin-i koje dozv. | `[]` |
  21. `--cors` mozete navesti vise puta:
  22. ```bash
  23. opencode serve --cors http://localhost:5173 --cors https://app.example.com
  24. ```
  25. ---
  26. ### Autentifikacija
  27. Postavite `OPENCODE_SERVER_PASSWORD` da zastitite server HTTP basic auth mehanizmom. Korisnicko ime je po defaultu `opencode`, ili postavite `OPENCODE_SERVER_USERNAME` za nadjacavanje. Ovo vazi i za `opencode serve` i za `opencode web`.
  28. ```bash
  29. OPENCODE_SERVER_PASSWORD=your-password opencode serve
  30. ```
  31. ---
  32. ### Kako radi
  33. Kada pokrenete `opencode`, pokrecu se TUI i server. TUI je klijent koji komunicira sa serverom. Server izlaže OpenAPI 3.1 spec endpoint koji se koristi i za generisanje [SDK-a](/docs/sdk).
  34. :::tip
  35. Koristite opencode server za programsku interakciju sa opencode-om.
  36. :::
  37. Ova arhitektura omogucava opencode podrsku za vise klijenata i programsku interakciju.
  38. Mozete pokrenuti `opencode serve` da startate standalone server. Ako je opencode TUI vec pokrenut, `opencode serve` ce pokrenuti novi server.
  39. ---
  40. #### Povezivanje na postojeći server
  41. Kada pokrenete TUI, port i hostname se nasumicno dodijele. Umjesto toga, mozete zadati `--hostname` i `--port` [zastave](/docs/cli), pa se povezati na taj server.
  42. Endpoint [`/tui`](#tui) mozete koristiti za upravljanje TUI-jem kroz server. Na primjer, mozete unaprijed popuniti ili pokrenuti prompt. Ovaj setup koriste OpenCode [IDE](/docs/ide) pluginovi.
  43. ---
  44. ## Specifikacija
  45. Server objavljuje OpenAPI 3.1 specifikaciju koju mozete vidjeti na:
  46. ```
  47. http://<hostname>:<port>/doc
  48. ```
  49. Na primjer, `http://localhost:4096/doc`. Koristite specifikaciju da generisete klijente ili pregledate tipove zahtjeva i odgovora. Mozete je otvoriti i u Swagger exploreru.
  50. ---
  51. ## API-ji
  52. opencode server izlaže sljedece API-je.
  53. ---
  54. ### Globalno
  55. | Metoda | Putanja | Opis | Odgovor |
  56. | ------ | ---------------- | ------------------------------ | ------------------------------------ |
  57. | `GET` | `/global/health` | Get server health and version | `{ healthy: true, version: string }` |
  58. | `GET` | `/global/event` | Get global events (SSE stream) | Event stream |
  59. ---
  60. ### Projekt
  61. | Metoda | Putanja | Opis | Odgovor |
  62. | ------ | ------------------ | ----------------------- | --------------------------------------------- |
  63. | `GET` | `/project` | List all projects | <a href={typesUrl}><code>Project[]</code></a> |
  64. | `GET` | `/project/current` | Get the current project | <a href={typesUrl}><code>Project</code></a> |
  65. ---
  66. ### Putanja i VCS
  67. | Metoda | Putanja | Opis | Odgovor |
  68. | ------ | ------- | ------------------------------------ | ------------------------------------------- |
  69. | `GET` | `/path` | Get the current path | <a href={typesUrl}><code>Path</code></a> |
  70. | `GET` | `/vcs` | Get VCS info for the current project | <a href={typesUrl}><code>VcsInfo</code></a> |
  71. ---
  72. ### Instanca
  73. | Metoda | Putanja | Opis | Odgovor |
  74. | ------ | ------------------- | ---------------------------- | --------- |
  75. | `POST` | `/instance/dispose` | Dispose the current instance | `boolean` |
  76. ---
  77. ### Konfiguracija
  78. | Metoda | Putanja | Opis | Odgovor |
  79. | ------- | ------------------- | --------------------------------- | ---------------------------------------------------------------------------------------- |
  80. | `GET` | `/config` | Get config info | <a href={typesUrl}><code>Config</code></a> |
  81. | `PATCH` | `/config` | Update config | <a href={typesUrl}><code>Config</code></a> |
  82. | `GET` | `/config/providers` | List providers and default models | `{ providers: `<a href={typesUrl}>Provider[]</a>`, default: { [key: string]: string } }` |
  83. ---
  84. ### Provajder
  85. | Metoda | Putanja | Opis | Odgovor |
  86. | ------ | -------------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------- |
  87. | `GET` | `/provider` | List all providers | `{ all: `<a href={typesUrl}>Provider[]</a>`, default: {...}, connected: string[] }` |
  88. | `GET` | `/provider/auth` | Get provider authentication methods | `{ [providerID: string]: `<a href={typesUrl}>ProviderAuthMethod[]</a>` }` |
  89. | `POST` | `/provider/{id}/oauth/authorize` | Authorize a provider using OAuth | <a href={typesUrl}><code>ProviderAuthAuthorization</code></a> |
  90. | `POST` | `/provider/{id}/oauth/callback` | Handle OAuth callback for a provider | `boolean` |
  91. ---
  92. ### Sesije
  93. | Metoda | Putanja | Opis | Napomene |
  94. | -------- | ---------------------------------------- | ------------------------------------- | ---------------------------------------------------------------------------------- |
  95. | `GET` | `/session` | List all sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
  96. | `POST` | `/session` | Create a new session | body: `{ parentID?, title? }`, returns <a href={typesUrl}><code>Session</code></a> |
  97. | `GET` | `/session/status` | Get session status for all sessions | Returns `{ [sessionID: string]: `<a href={typesUrl}>SessionStatus</a>` }` |
  98. | `GET` | `/session/:id` | Get session details | Returns <a href={typesUrl}><code>Session</code></a> |
  99. | `DELETE` | `/session/:id` | Delete a session and all its data | Returns `boolean` |
  100. | `PATCH` | `/session/:id` | Update session properties | body: `{ title? }`, returns <a href={typesUrl}><code>Session</code></a> |
  101. | `GET` | `/session/:id/children` | Get a session's child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
  102. | `GET` | `/session/:id/todo` | Get the todo list for a session | Returns <a href={typesUrl}><code>Todo[]</code></a> |
  103. | `POST` | `/session/:id/init` | Analyze app and create `AGENTS.md` | body: `{ messageID, providerID, modelID }`, returns `boolean` |
  104. | `POST` | `/session/:id/fork` | Fork an existing session at a message | body: `{ messageID? }`, returns <a href={typesUrl}><code>Session</code></a> |
  105. | `POST` | `/session/:id/abort` | Abort a running session | Returns `boolean` |
  106. | `POST` | `/session/:id/share` | Share a session | Returns <a href={typesUrl}><code>Session</code></a> |
  107. | `DELETE` | `/session/:id/share` | Unshare a session | Returns <a href={typesUrl}><code>Session</code></a> |
  108. | `GET` | `/session/:id/diff` | Get the diff for this session | query: `messageID?`, returns <a href={typesUrl}><code>FileDiff[]</code></a> |
  109. | `POST` | `/session/:id/summarize` | Summarize the session | body: `{ providerID, modelID }`, returns `boolean` |
  110. | `POST` | `/session/:id/revert` | Revert a message | body: `{ messageID, partID? }`, returns `boolean` |
  111. | `POST` | `/session/:id/unrevert` | Restore all reverted messages | Returns `boolean` |
  112. | `POST` | `/session/:id/permissions/:permissionID` | Respond to a permission request | body: `{ response, remember? }`, returns `boolean` |
  113. ---
  114. ### Poruke
  115. | Metoda | Putanja | Opis | Napomene |
  116. | ------ | --------------------------------- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  117. | `GET` | `/session/:id/message` | List messages in a session | query: `limit?`, returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}[]` |
  118. | `POST` | `/session/:id/message` | Send a message and wait for response | body: `{ messageID?, model?, agent?, noReply?, system?, tools?, parts }`, returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}` |
  119. | `GET` | `/session/:id/message/:messageID` | Get message details | Returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}` |
  120. | `POST` | `/session/:id/prompt_async` | Send a message asynchronously (no wait) | body: same as `/session/:id/message`, returns `204 No Content` |
  121. | `POST` | `/session/:id/command` | Execute a slash command | body: `{ messageID?, agent?, model?, command, arguments }`, returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}` |
  122. | `POST` | `/session/:id/shell` | Run a shell command | body: `{ agent, model?, command }`, returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}` |
  123. ---
  124. ### Naredbe
  125. | Metoda | Putanja | Opis | Odgovor |
  126. | ------ | ---------- | ----------------- | --------------------------------------------- |
  127. | `GET` | `/command` | List all commands | <a href={typesUrl}><code>Command[]</code></a> |
  128. ---
  129. ### Datoteke
  130. | Metoda | Putanja | Opis | Odgovor |
  131. | ------ | ------------------------ | ---------------------------------- | ------------------------------------------------------------------------------------------- |
  132. | `GET` | `/find?pattern=<pat>` | Search for text in files | Array of match objects with `path`, `lines`, `line_number`, `absolute_offset`, `submatches` |
  133. | `GET` | `/find/file?query=<q>` | Find files and directories by name | `string[]` (paths) |
  134. | `GET` | `/find/symbol?query=<q>` | Find workspace symbols | <a href={typesUrl}><code>Symbol[]</code></a> |
  135. | `GET` | `/file?path=<path>` | List files and directories | <a href={typesUrl}><code>FileNode[]</code></a> |
  136. | `GET` | `/file/content?path=<p>` | Read a file | <a href={typesUrl}><code>FileContent</code></a> |
  137. | `GET` | `/file/status` | Get status for tracked files | <a href={typesUrl}><code>File[]</code></a> |
  138. #### `/find/file` parametri upita
  139. - `query` (obavezno) — niz za pretragu (fuzzy podudaranje)
  140. - `type` (opcionalno) — ograniči rezultate na `"file"` ili `"directory"`
  141. - `directory` (opcionalno) — nadjačaj korijen projekta za pretragu
  142. - `limit` (opcionalno) — maksimalni rezultati (1–200)
  143. - `dirs` (opcionalno) — zastarjela zastavica (`"false"` vraća samo datoteke)
  144. ---
  145. ### Alati (Eksperimentalno)
  146. | Metoda | Putanja | Opis | Odgovor |
  147. | ------ | ------------------------------------------- | ---------------------------------------- | -------------------------------------------- |
  148. | `GET` | `/experimental/tool/ids` | List all tool IDs | <a href={typesUrl}><code>ToolIDs</code></a> |
  149. | `GET` | `/experimental/tool?provider=<p>&model=<m>` | List tools with JSON schemas for a model | <a href={typesUrl}><code>ToolList</code></a> |
  150. ---
  151. ### LSP, Formateri & MCP
  152. | Metoda | Putanja | Opis | Odgovor |
  153. | ------ | ------------ | -------------------------- | -------------------------------------------------------- |
  154. | `GET` | `/lsp` | Get LSP server status | <a href={typesUrl}><code>LSPStatus[]</code></a> |
  155. | `GET` | `/formatter` | Get formatter status | <a href={typesUrl}><code>FormatterStatus[]</code></a> |
  156. | `GET` | `/mcp` | Get MCP server status | `{ [name: string]: `<a href={typesUrl}>MCPStatus</a>` }` |
  157. | `POST` | `/mcp` | Add MCP server dynamically | body: `{ name, config }`, returns MCP status object |
  158. ---
  159. ### Agenti
  160. | Metoda | Putanja | Opis | Odgovor |
  161. | ------ | -------- | ------------------------- | ------------------------------------------- |
  162. | `GET` | `/agent` | List all available agents | <a href={typesUrl}><code>Agent[]</code></a> |
  163. ---
  164. ### Bilježenje
  165. | Metoda | Putanja | Opis | Odgovor |
  166. | ------ | ------- | ------------------------------------------------------------ | --------- |
  167. | `POST` | `/log` | Write log entry. Body: `{ service, level, message, extra? }` | `boolean` |
  168. ---
  169. ### TUI
  170. | Metoda | Putanja | Opis | Odgovor |
  171. | ------ | ----------------------- | ------------------------------------------- | ---------------------- |
  172. | `POST` | `/tui/append-prompt` | Append text to the prompt | `boolean` |
  173. | `POST` | `/tui/open-help` | Open the help dialog | `boolean` |
  174. | `POST` | `/tui/open-sessions` | Open the session selector | `boolean` |
  175. | `POST` | `/tui/open-themes` | Open the theme selector | `boolean` |
  176. | `POST` | `/tui/open-models` | Open the model selector | `boolean` |
  177. | `POST` | `/tui/submit-prompt` | Submit the current prompt | `boolean` |
  178. | `POST` | `/tui/clear-prompt` | Clear the prompt | `boolean` |
  179. | `POST` | `/tui/execute-command` | Execute a command (`{ command }`) | `boolean` |
  180. | `POST` | `/tui/show-toast` | Show toast (`{ title?, message, variant }`) | `boolean` |
  181. | `GET` | `/tui/control/next` | Wait for the next control request | Control request object |
  182. | `POST` | `/tui/control/response` | Respond to a control request (`{ body }`) | `boolean` |
  183. ---
  184. ### Autentifikacija
  185. | Metoda | Putanja | Opis | Odgovor |
  186. | ------ | ----------- | --------------------------------------------------------------- | --------- |
  187. | `PUT` | `/auth/:id` | Set authentication credentials. Body must match provider schema | `boolean` |
  188. ---
  189. ### Događaji
  190. | Metoda | Putanja | Opis | Odgovor |
  191. | ------ | -------- | ----------------------------------------------------------------------------- | ------------------------- |
  192. | `GET` | `/event` | Server-sent events stream. First event is `server.connected`, then bus events | Server-sent events stream |
  193. ---
  194. ### Dokumentacija
  195. | Metoda | Putanja | Opis | Odgovor |
  196. | ------ | ------- | ------------------------- | --------------------------- |
  197. | `GET` | `/doc` | OpenAPI 3.1 specification | HTML page with OpenAPI spec |