whoosh 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7276060a2fd0b8ef3edc620c087767b92de6684e6ef54a130f5c3b45f5468a52
4
- data.tar.gz: 98f9f219bbc2e01af9ba63803a525d100fcd70adf397248065db796b28319ae4
3
+ metadata.gz: b74890ede8ed95aadeafdd55439b0a267ec521ecb5c84fd879807f29789a9d9a
4
+ data.tar.gz: aa04e3dbf492846d8f06fe057ef657a137065a6b8069421c24013a4102b63511
5
5
  SHA512:
6
- metadata.gz: a12f5a8f431ff694382192e046072596beeaced996cf47e19633ea3974ebd7bae17bc079118b28cc08b019282219d0ff4cf263291eed418a38d2f32a4021d38a
7
- data.tar.gz: 76c4e804ea925a037ecd60fcc02834800fb0d2ec000d9fdfb48a7a142625c32e37dd3f8bdbf56bae934f1a6ee46a3731a1f0db06cddac660630c4f14bdccd579
6
+ metadata.gz: 884921ba3182cef85545192b08301ced1d992705621ce0860e55e916da2ece5f8d1b122f676a88e0e7b18dcbb9f271e01e2e46bbd5439962cd476bfb73173078
7
+ data.tar.gz: 8dcb16978fa00228a18de47e42cbe29c0e3d8da84c3bf3a6b4b52842ea9ce4cbcc7a5930b1c471c8b2d06065b6793db6574a8ec2392e7f9707e07d73940be0fb
data/lib/whoosh/app.rb CHANGED
@@ -211,29 +211,8 @@ module Whoosh
211
211
  end
212
212
  end
213
213
 
214
- # --- Streaming helpers ---
215
-
216
- def stream(type, &block)
217
- case type
218
- when :sse
219
- body = Streaming::StreamBody.new do |out|
220
- sse = Streaming::SSE.new(out)
221
- block.call(sse)
222
- end
223
- [200, Streaming::SSE.headers, body]
224
- else
225
- raise ArgumentError, "Unknown stream type: #{type}"
226
- end
227
- end
228
-
229
- def stream_llm(&block)
230
- body = Streaming::StreamBody.new do |out|
231
- llm_stream = Streaming::LlmStream.new(out)
232
- block.call(llm_stream)
233
- llm_stream.finish
234
- end
235
- [200, Streaming::LlmStream.headers, body]
236
- end
214
+ # --- Streaming helpers (stream, stream_llm) ---
215
+ include Streaming::Helpers
237
216
 
238
217
  # WebSocket endpoint helper — use in handle_request, returns hijack response
239
218
  def websocket(env, &block)
@@ -622,9 +601,16 @@ module Whoosh
622
601
  # Call handler
623
602
  if handler[:endpoint_class]
624
603
  # Class-based endpoint
625
- endpoint = handler[:endpoint_class].new
626
- context = Endpoint::Context.new(self, request)
627
- result = endpoint.call(context.request)
604
+ endpoint_class = handler[:endpoint_class]
605
+ endpoint = endpoint_class.new
606
+ if endpoint_class.respond_to?(:dependencies)
607
+ endpoint_class.dependencies.each do |dep|
608
+ value = @di.resolve(dep, request: request)
609
+ endpoint.instance_variable_set(:"@#{dep}", value)
610
+ endpoint.define_singleton_method(dep) { instance_variable_get(:"@#{dep}") }
611
+ end
612
+ end
613
+ result = endpoint.call(request)
628
614
  else
629
615
  # Inline block endpoint
630
616
  block = handler[:block]
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Whoosh
4
4
  class Endpoint
5
+ include Streaming::Helpers
6
+
5
7
  class Context
6
8
  attr_reader :request
7
9
 
@@ -35,6 +37,14 @@ module Whoosh
35
37
  @declared_routes
36
38
  end
37
39
 
40
+ def inject(*names)
41
+ @dependencies = names
42
+ end
43
+
44
+ def dependencies
45
+ @dependencies || []
46
+ end
47
+
38
48
  def get(path, **opts)
39
49
  declare_route("GET", path, **opts)
40
50
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whoosh
4
+ module Streaming
5
+ module Helpers
6
+ def stream(type, &block)
7
+ case type
8
+ when :sse
9
+ body = StreamBody.new do |out|
10
+ sse = SSE.new(out)
11
+ block.call(sse)
12
+ end
13
+ [200, SSE.headers, body]
14
+ else
15
+ raise ArgumentError, "Unknown stream type: #{type}"
16
+ end
17
+ end
18
+
19
+ def stream_llm(&block)
20
+ body = StreamBody.new do |out|
21
+ llm_stream = LlmStream.new(out)
22
+ block.call(llm_stream)
23
+ llm_stream.finish
24
+ end
25
+ [200, LlmStream.headers, body]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whoosh
4
- VERSION = "1.7.0"
4
+ VERSION = "1.9.0"
5
5
  end
data/lib/whoosh.rb CHANGED
@@ -66,6 +66,7 @@ module Whoosh
66
66
  autoload :WebSocket, "whoosh/streaming/websocket"
67
67
  autoload :LlmStream, "whoosh/streaming/llm_stream"
68
68
  autoload :StreamBody, "whoosh/streaming/stream_body"
69
+ autoload :Helpers, "whoosh/streaming/helpers"
69
70
  end
70
71
 
71
72
  module OpenAPI
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoosh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Dwi Cahyo
@@ -264,6 +264,7 @@ files:
264
264
  - lib/whoosh/storage.rb
265
265
  - lib/whoosh/storage/local.rb
266
266
  - lib/whoosh/storage/s3.rb
267
+ - lib/whoosh/streaming/helpers.rb
267
268
  - lib/whoosh/streaming/llm_stream.rb
268
269
  - lib/whoosh/streaming/sse.rb
269
270
  - lib/whoosh/streaming/stream_body.rb