Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lua/opencode/cli/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ end
---@param body table?
---@param on_success fun(response: table)?
---@param on_error fun(code: number, msg: string?)?
---@param opts? { max_time?: number } Optional settings (max_time limits total request time in seconds)
---@return number job_id
local function curl(url, method, body, on_success, on_error)
local function curl(url, method, body, on_success, on_error, opts)
opts = opts or {}
local command = {
"curl",
"-s",
Expand All @@ -64,6 +66,11 @@ local function curl(url, method, body, on_success, on_error)
"-N", -- No buffering, for streaming SSEs
}

if opts.max_time then
table.insert(command, "--max-time")
table.insert(command, tostring(opts.max_time))
end

if body then
table.insert(command, "-d")
table.insert(command, vim.fn.json_encode(body))
Expand Down Expand Up @@ -149,9 +156,10 @@ end
---@param body table?
---@param on_success fun(response: table)?
---@param on_error fun(code: number, msg: string?)?
---@param opts? { max_time?: number } Optional settings (max_time limits total request time in seconds)
---@return number job_id
function M.call(port, path, method, body, on_success, on_error)
return curl("http://localhost:" .. port .. path, method, body, on_success, on_error)
function M.call(port, path, method, body, on_success, on_error, opts)
return curl("http://localhost:" .. port .. path, method, body, on_success, on_error, opts)
end

---@param text string
Expand Down Expand Up @@ -269,7 +277,7 @@ end
---@param on_success fun(response: opencode.cli.client.PathResponse)
---@param on_error fun()
function M.get_path(port, on_success, on_error)
M.call(port, "/path", "GET", nil, on_success, on_error)
M.call(port, "/path", "GET", nil, on_success, on_error, { max_time = 2 })
end

---@class opencode.cli.client.Event
Expand Down