lex-llm-openai 0.4.8 → 0.4.9

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: 9795e7797d7d5f8ce0994e16625e2ccd6d2ef54299166e9bbec86bd2ce7c002c
4
- data.tar.gz: 4c5eb2fa507ae61c44893be81a7ef2a7b692542fb3bef191ece53e0d061b68e2
3
+ metadata.gz: 137435c2996f9aa9c56c884f616c824561ef2493c30a3c113a2a8261eb37c88c
4
+ data.tar.gz: 81b9d2b79bdeb8f708338ce9bd66d923a5165643f2416be5bfe730db53c41a61
5
5
  SHA512:
6
- metadata.gz: f60720c95320eed7e1a2d02e3fd91857ad290c2ad06c525bf12321a309b09bb7529232bf0461a6ed7dbd38a81c6ac912f7025c6d3de35d3872e90ccc5675b326
7
- data.tar.gz: 435f627775ea601c6d3c41f850d6bf9efcabea039692ac2c06161b990b0efde1b59d7c95ba837e6f2bfffd4ced82a4afe2fef1439fd5200c203e7b4dec7e416a
6
+ metadata.gz: 5cf576c1d1bae53ce4acaae572a984ebe2c02032b570ed720fc596f6b820567905c0de57592d9addbf47ba72d30867847a18213ec11be7a81cf315699c88bc3c
7
+ data.tar.gz: 151b3e313e710f56678eb1a2e042d6208cf35dd3a00a4b93a27107ec11e2aa74200aa5e3b492beba1db89096a5e3dd1b4fb5ae7165a6ce4fa54b84b12ac26d3c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.9] - 2026-07-24
4
+
5
+ ### Fixed
6
+ - **Translator no longer discards content when `finish_reason` is present on SSE chunk.** Previously returned a done chunk immediately when finish_reason was set, silently dropping any content, reasoning, or tool_call data on the same event. Now checks for content fields first and only emits done when the delta is truly empty. Passes `stop_reason` and `usage` through to content/tool_call chunks.
7
+
3
8
  ## [0.4.8] - 2026-06-20
4
9
 
5
10
  ### Fixed
@@ -116,16 +116,26 @@ module Legion
116
116
  finish_reason = choice['finish_reason']
117
117
  usage_raw = data['usage']
118
118
 
119
- return build_done_chunk(data, finish_reason, usage_raw) if finish_reason
119
+ chunk_stop_reason = finish_reason ? map_stop_reason(finish_reason) : nil
120
+ chunk_usage = finish_reason && usage_raw ? parse_usage(usage_raw) : nil
121
+
120
122
  return parse_error_chunk(data) if data['error']
121
123
 
122
124
  reasoning = delta['reasoning_content'] || delta['reasoning']
123
125
  content = delta['content']
124
126
 
125
- return build_thinking_chunk(reasoning, data['id']) if reasoning
126
- return build_text_chunk(content, data['id']) if content
127
+ if reasoning
128
+ return build_thinking_chunk(reasoning, data['id'], stop_reason: chunk_stop_reason,
129
+ usage: chunk_usage)
130
+ end
131
+ return build_text_chunk(content, data['id'], stop_reason: chunk_stop_reason, usage: chunk_usage) if content
132
+
133
+ tc_chunk = parse_tool_call_delta(delta, data, stop_reason: chunk_stop_reason, usage: chunk_usage)
134
+ return tc_chunk if tc_chunk
135
+
136
+ return build_done_chunk(data, finish_reason, usage_raw) if finish_reason
127
137
 
128
- parse_tool_call_delta(delta, data)
138
+ nil
129
139
  rescue StandardError => e
130
140
  handle_exception(e, level: :error, handled: true, operation: 'openai.translator.parse_chunk')
131
141
  Canonical::Chunk.error_chunk(
@@ -403,21 +413,25 @@ module Legion
403
413
  )
404
414
  end
405
415
 
406
- def build_thinking_chunk(reasoning, request_id)
416
+ def build_thinking_chunk(reasoning, request_id, stop_reason: nil, usage: nil)
407
417
  Canonical::Chunk.thinking_delta(
408
418
  delta: reasoning,
409
- request_id: request_id
419
+ request_id: request_id,
420
+ stop_reason: stop_reason,
421
+ usage: usage
410
422
  )
411
423
  end
412
424
 
413
- def build_text_chunk(content, request_id)
425
+ def build_text_chunk(content, request_id, stop_reason: nil, usage: nil)
414
426
  Canonical::Chunk.text_delta(
415
427
  delta: content,
416
- request_id: request_id
428
+ request_id: request_id,
429
+ stop_reason: stop_reason,
430
+ usage: usage
417
431
  )
418
432
  end
419
433
 
420
- def parse_tool_call_delta(delta, data)
434
+ def parse_tool_call_delta(delta, data, stop_reason: nil, usage: nil)
421
435
  raw_tc = delta['tool_calls']
422
436
  return nil unless raw_tc&.any?
423
437
 
@@ -432,7 +446,9 @@ module Legion
432
446
 
433
447
  Canonical::Chunk.tool_call_delta(
434
448
  tool_call: tool_call,
435
- request_id: data['id']
449
+ request_id: data['id'],
450
+ stop_reason: stop_reason,
451
+ usage: usage
436
452
  )
437
453
  end
438
454
 
@@ -4,7 +4,7 @@ module Legion
4
4
  module Extensions
5
5
  module Llm
6
6
  module Openai
7
- VERSION = '0.4.8'
7
+ VERSION = '0.4.9'
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-llm-openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - LegionIO