Skip to content

Commit 722ceff

Browse files
feat: Count the user messages in core.send_message rather than with the jobs
1 parent 725e646 commit 722ceff

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

lua/opencode/core.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ function M.send_message(prompt, opts)
146146
params.parts = context.format_message(prompt, opts.context)
147147
M.before_run(opts)
148148

149+
state.user_message_count = state.user_message_count + 1
149150
state.api_client
150151
:create_message(state.active_session.id, params)
151152
:and_then(function(response)
@@ -154,6 +155,7 @@ function M.send_message(prompt, opts)
154155
-- event manager
155156
ui.render_output()
156157
end
158+
state.user_message_count = state.user_message_count - 1
157159

158160
M.after_run(prompt)
159161
end)
@@ -366,7 +368,7 @@ function M.initialize_current_model()
366368
return state.current_model
367369
end
368370

369-
local function on_job_count_change(_, new, old)
371+
local function on_user_message_count_change(_, new, old)
370372
local done_thinking = new == 0 and old > 0
371373
if config.hooks and config.hooks.on_done_thinking and done_thinking then
372374
pcall(config.hooks.on_done_thinking)
@@ -382,7 +384,7 @@ end
382384

383385
function M.setup()
384386
state.subscribe('opencode_server', on_opencode_server)
385-
state.subscribe('user_message_count', on_job_count_change)
387+
state.subscribe('user_message_count', on_user_message_count_change)
386388
state.subscribe('current_permission', on_current_permission_change)
387389

388390
vim.schedule(function()

lua/opencode/server_job.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ end
2727
function M.call_api(url, method, body)
2828
local call_promise = Promise.new()
2929

30-
local function is_user_message()
31-
return method == 'POST' and url:match("/message$") ~= nil
32-
end
33-
3430
state.job_count = state.job_count + 1
35-
if is_user_message() then
36-
state.user_message_count = state.user_message_count + 1
37-
end
3831

3932
local request_entry = { nil, call_promise }
4033
table.insert(M.requests, request_entry)
@@ -43,9 +36,6 @@ function M.call_api(url, method, body)
4336
local function remove_from_requests()
4437
for i, entry in ipairs(M.requests) do
4538
if entry == request_entry then
46-
if is_user_message() then
47-
state.user_message_count = state.user_message_count - 1
48-
end
4939
table.remove(M.requests, i)
5040
break
5141
end

0 commit comments

Comments
 (0)