Skip to content

Commit 6846482

Browse files
authored
feat(events): new request streaming event (#878)
1 parent d8faa04 commit 6846482

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

doc/usage/events.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The events that you can access are:
2020
- `CodeCompanionInlineStarted` - Fired at the start of the Inline strategy
2121
- `CodeCompanionInlineFinished` - Fired at the end of the Inline strategy
2222
- `CodeCompanionRequestStarted` - Fired at the start of any API request
23+
- `CodeCompanionRequestStreaming` - Fired at the start of a streaming API request
2324
- `CodeCompanionRequestFinished` - Fired at the end of any API request
2425
- `CodeCompanionDiffAttached` - Fired when in Diff mode
2526
- `CodeCompanionDiffDetached` - Fired when exiting Diff mode

lua/codecompanion/http.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,15 @@ function Client:request(payload, actions, opts)
149149
-- Turn off plenary's default compression
150150
request_opts["compressed"] = adapter.opts.compress or false
151151

152+
local streaming = false
153+
152154
-- This will be called multiple times until the stream is finished
153155
request_opts["stream"] = self.opts.schedule(function(_, data)
154156
if data and data ~= "" then
157+
if not streaming then
158+
streaming = true
159+
util.fire("RequestStreaming", opts)
160+
end
155161
log:trace("Output data:\n%s", data)
156162
end
157163
cb(nil, data)

0 commit comments

Comments
 (0)