Skip to content

Commit 5be6d12

Browse files
feat: Add explicit SSE event names for local v3 streaming
1 parent b4bc8a8 commit 5be6d12

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 8
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-975ca868b31b1e45fb00b31a53d9df1ceec8663f6c2851bf40fdaa84171afadc.yml
3-
openapi_spec_hash: 37891379e0f47e5c69769fbaa1064dab
4-
config_hash: 0209737a4ab2a71afececb0ff7459998
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-a4a5ea048bb50d06460d81d6828b53b12b19e9224121ee6338dcd1f0781e22a1.yml
3+
openapi_spec_hash: 9b81c0ae04576318d13d7a80d4ab7b5a
4+
config_hash: d6c6f623d03971bdba921650e5eb7e5f

lib/stagehand/internal/stream.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@ class Stream
1515
#
1616
# @return [Enumerable<generic<Elem>>]
1717
private def iterator
18-
# rubocop:disable Metrics/BlockLength
1918
@iterator ||= Stagehand::Internal::Util.chain_fused(@stream) do |y|
20-
consume = false
21-
2219
@stream.each do |msg|
23-
next if consume
24-
2520
case msg
26-
in {data: String => data} if data.start_with?("{\"data\":{\"status\":\"finished\"")
27-
consume = true
28-
next
29-
in {data: String => data} if data.start_with?("error")
21+
in {event: "error", data: String => data}
3022
decoded = Kernel.then do
3123
JSON.parse(data, symbolize_names: true)
3224
rescue JSON::ParserError
@@ -41,15 +33,14 @@ class Stream
4133
response: @response
4234
)
4335
raise err
44-
in {event: nil, data: String => data}
36+
in {event: "starting" | "connected" | "running" | "finished", data: String => data}
4537
decoded = JSON.parse(data, symbolize_names: true)
4638
unwrapped = Stagehand::Internal::Util.dig(decoded, @unwrap)
4739
y << Stagehand::Internal::Type::Converter.coerce(@model, unwrapped)
4840
else
4941
end
5042
end
5143
end
52-
# rubocop:enable Metrics/BlockLength
5344
end
5445
end
5546
end

lib/stagehand/models/stream_event.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class StreamEvent < Stagehand::Internal::Type::BaseModel
2222

2323
# @!method initialize(id:, data:, type:)
2424
# Server-Sent Event emitted during streaming responses. Events are sent as
25-
# `data: <JSON>\n\n`. Key order: data (with status first), type, id.
25+
# `event: <status>\ndata: <JSON>\n\n`, where the JSON payload has the shape
26+
# `{ data, type, id }`.
2627
#
2728
# @param id [String] Unique identifier for this event
2829
#

rbi/stagehand/models/stream_event.rbi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module Stagehand
2020
attr_accessor :type
2121

2222
# Server-Sent Event emitted during streaming responses. Events are sent as
23-
# `data: <JSON>\n\n`. Key order: data (with status first), type, id.
23+
# `event: <status>\ndata: <JSON>\n\n`, where the JSON payload has the shape
24+
# `{ data, type, id }`.
2425
sig do
2526
params(
2627
id: String,

0 commit comments

Comments
 (0)