lara-sdk 1.2.1 → 1.4.3

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: 20907c5322ca25cec94d4475f543ba03a04f611c8707711ca5b188b1aac5d708
4
- data.tar.gz: 41f47a2c9a56145711d5275a9f8db3b1dc9a66e3b514d4d4106cbf2fa69bcb8e
3
+ metadata.gz: 99781bcccbdde09ccc8c153f32683bf08e57be3aee65d82a0037f2d3e7daaf3a
4
+ data.tar.gz: 21041bbad4d3d3b2d269d40daded257d3b1879fdf9eea347314cec81b8618dd0
5
5
  SHA512:
6
- metadata.gz: 323a5b9dbe032b6cc66ca30f42cf599ebd451f29b87c9a7fa7ed0f98769b91a952c57ece507d4bf9a9a120159364c6c224059a4b7a4a09b76ec65c3a0e50f078
7
- data.tar.gz: 6123b7826259215d940b6e06e75b912756f9351cf750837e793059488472dac3ff3fc47906a4e6922b966873ea9803e240e588d9e9cf80f8c67509e3798136a0
6
+ metadata.gz: '01785a1e0afe2ce5de1e6f49a617ccd7d43749109e818957c984bca81598e170da652830fbf8662366a6217cf328ded0eafd76cd266d26ab90e31492add28dbf'
7
+ data.tar.gz: 65de8ac4120d2ef3af4e5e584da1bc337b70d6abd8848dc41c3dd21dafe9e511b0519a2a4bc60c7a91b744eb39a0739340c8c18bbe9f20b59b033618d806c616
data/lib/lara/client.rb CHANGED
@@ -228,12 +228,7 @@ module Lara
228
228
  def parse_json(body)
229
229
  return {} if body.nil? || body.empty?
230
230
 
231
- parsed = JSON.parse(body)
232
- if parsed.is_a?(Hash) && parsed.key?("content")
233
- inner = parsed["content"]
234
- return inner if inner.is_a?(Hash) || inner.is_a?(Array)
235
- end
236
- parsed
231
+ JSON.parse(body)
237
232
  end
238
233
 
239
234
  def parse_stream_response(body, &block)
@@ -252,8 +247,7 @@ module Lara
252
247
  next if trimmed_line.empty?
253
248
 
254
249
  begin
255
- parsed = JSON.parse(trimmed_line)
256
- result = parsed["content"] || parsed
250
+ result = JSON.parse(trimmed_line)
257
251
  block.call(result) if block
258
252
  last_result = result
259
253
  rescue JSON::ParserError
@@ -263,8 +257,7 @@ module Lara
263
257
 
264
258
  if !buffer.empty? && buffer.strip != ""
265
259
  begin
266
- parsed = JSON.parse(buffer.strip)
267
- result = parsed["content"] || parsed
260
+ result = JSON.parse(buffer.strip)
268
261
  block.call(result) if block
269
262
  last_result = result
270
263
  rescue JSON::ParserError
data/lib/lara/errors.rb CHANGED
@@ -17,19 +17,14 @@ module Lara
17
17
  class LaraApiError < LaraError
18
18
  attr_reader :type
19
19
 
20
- # Builds an error from an HTTP response with JSON body.
21
- # Supports both { "error": { "type": "...", "message": "..." } }
22
- # and { "type": "...", "message": "..." } response formats.
20
+ # Builds an error from an HTTP response with JSON body { "type": "...", "message": "..." }.
23
21
  def self.from_response(response)
24
22
  data = begin
25
23
  JSON.parse(response.body)
26
24
  rescue StandardError
27
25
  {}
28
26
  end
29
- error = data["error"] || data
30
- error_type = error["type"] || "UnknownError"
31
- error_message = error["message"] || "An unknown error occurred"
32
- new(response.status, error_type, error_message)
27
+ new(response.status, data["type"] || "UnknownError", data["message"] || "An unknown error occurred")
33
28
  end
34
29
 
35
30
  # @param status_code [Integer]
data/lib/lara/memories.rb CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  module Lara
4
4
  class Memories
5
+ # Supported memory export formats
6
+ module ExportFormat
7
+ TMX = "tmx"
8
+ JTM = "jtm"
9
+
10
+ # @return [Array<String>] All supported formats
11
+ def self.all
12
+ [TMX, JTM]
13
+ end
14
+
15
+ # @param format [String] The format to validate
16
+ # @return [Boolean] True if the format is supported
17
+ def self.valid?(format)
18
+ all.include?(format)
19
+ end
20
+ end
21
+
5
22
  def initialize(client)
6
23
  @client = client
7
24
  @polling_interval = 2
@@ -99,7 +116,7 @@ module Lara
99
116
  end
100
117
 
101
118
  # @return [Lara::Models::MemoryImport]
102
- def import_tmx(id, tmx_path)
119
+ def import_tmx(id, tmx_path, callback_url: nil)
103
120
  require "stringio"
104
121
  require "zlib"
105
122
  basename = File.basename(tmx_path)
@@ -111,8 +128,22 @@ module Lara
111
128
  buffer.rewind
112
129
 
113
130
  files = { "tmx" => Faraday::UploadIO.new(buffer, "application/gzip", "#{basename}.gz") }
131
+ body = { "compression" => "gzip" }
132
+ body["callback_url"] = callback_url if callback_url
114
133
  Lara::Models::MemoryImport.new(**@client.post("/v2/memories/#{id}/import",
115
- body: { "compression" => "gzip" }, files: files).transform_keys(&:to_sym))
134
+ body: body, files: files).transform_keys(&:to_sym))
135
+ end
136
+
137
+ # @param format [String,nil] One of Lara::Memories::ExportFormat constants
138
+ # @return [Lara::Models::MemoryExport]
139
+ def export_async(id, format: nil, callback_url:)
140
+ if format && !ExportFormat.valid?(format)
141
+ raise ArgumentError, "Invalid format '#{format}'. Must be one of: #{ExportFormat.all.join(', ')}"
142
+ end
143
+
144
+ params = { callback_url: callback_url }
145
+ params[:format] = format if format
146
+ Lara::Models::MemoryExport.new(**@client.get("/v2/memories/#{id}/export/async", params: params).transform_keys(&:to_sym))
116
147
  end
117
148
 
118
149
  # @return [Lara::Models::MemoryImport]
@@ -16,7 +16,7 @@ module Lara
16
16
  @created_at = Base.parse_time(created_at)
17
17
  @updated_at = Base.parse_time(updated_at)
18
18
  @shared_at = Base.parse_time(shared_at)
19
- @is_personal = is_personal.nil? ? _kwargs[:isPersonal] : is_personal
19
+ @is_personal = is_personal
20
20
  end
21
21
  end
22
22
 
@@ -21,7 +21,7 @@ module Lara
21
21
  @secret = secret
22
22
  @collaborators_count = collaborators_count
23
23
  @shared_at = Base.parse_time(shared_at)
24
- @is_personal = is_personal.nil? ? _kwargs[:isPersonal] : is_personal
24
+ @is_personal = is_personal
25
25
  end
26
26
  end
27
27
 
@@ -38,5 +38,14 @@ module Lara
38
38
  @progress = progress
39
39
  end
40
40
  end
41
+
42
+ class MemoryExport < Base
43
+ attr_reader :job_id
44
+
45
+ def initialize(job_id:, **_kwargs)
46
+ super()
47
+ @job_id = job_id
48
+ end
49
+ end
41
50
  end
42
51
  end
@@ -52,9 +52,9 @@ module Lara
52
52
  end
53
53
 
54
54
  class ProfanityDetectResult < Base
55
- attr_reader :masked_text, :profanities
55
+ attr_reader :masked_text, :profanities, :error
56
56
 
57
- def initialize(masked_text:, profanities: [])
57
+ def initialize(masked_text:, profanities: [], error: nil)
58
58
  super()
59
59
  @masked_text = masked_text
60
60
  @profanities = profanities.map do |p|
@@ -65,6 +65,22 @@ module Lara
65
65
  score: p["score"] || p[:score]
66
66
  )
67
67
  end
68
+ @error = error
69
+ end
70
+ end
71
+
72
+ # Wraps profanity detection results for both target and (optionally) source text.
73
+ # Returned in TextResult#profanities when profanities_detect is set.
74
+ class ProfanitiesResult < Base
75
+ # @return [ProfanityDetectResult, Array<ProfanityDetectResult, nil>, nil]
76
+ attr_reader :target
77
+ # @return [ProfanityDetectResult, Array<ProfanityDetectResult, nil>, nil]
78
+ attr_reader :source
79
+
80
+ def initialize(target: nil, source: nil)
81
+ super()
82
+ @target = target
83
+ @source = source
68
84
  end
69
85
  end
70
86
 
@@ -99,9 +115,10 @@ module Lara
99
115
  end
100
116
 
101
117
  class Styleguide < Base
102
- attr_reader :id, :name, :content, :owner_id, :created_at, :updated_at
118
+ attr_reader :id, :name, :content, :owner_id, :created_at, :updated_at, :is_personal
103
119
 
104
- def initialize(id:, name:, content: nil, owner_id: nil, created_at: nil, updated_at: nil, **_kwargs)
120
+ def initialize(id:, name:, content: nil, owner_id: nil, created_at: nil, updated_at: nil,
121
+ is_personal: nil, **_kwargs)
105
122
  super()
106
123
  @id = id
107
124
  @name = name
@@ -109,6 +126,7 @@ module Lara
109
126
  @owner_id = owner_id
110
127
  @created_at = Base.parse_time(created_at)
111
128
  @updated_at = Base.parse_time(updated_at)
129
+ @is_personal = is_personal
112
130
  end
113
131
 
114
132
  def to_s
@@ -215,11 +233,23 @@ module Lara
215
233
 
216
234
  def convert_profanities(value)
217
235
  return nil if value.nil?
236
+ return nil unless value.is_a?(Hash)
237
+ return nil unless value.key?("target") || value.key?("source")
238
+
239
+ ProfanitiesResult.new(
240
+ target: parse_profanity_value(value["target"]),
241
+ source: parse_profanity_value(value["source"])
242
+ )
243
+ end
244
+
245
+ def parse_profanity_value(value)
246
+ return nil if value.nil?
218
247
 
219
248
  if value.is_a?(Hash)
220
249
  ProfanityDetectResult.new(
221
250
  masked_text: value["masked_text"],
222
- profanities: value["profanities"] || []
251
+ profanities: value["profanities"] || [],
252
+ error: value["error"]
223
253
  )
224
254
  elsif value.is_a?(Array)
225
255
  value.map do |v|
@@ -227,7 +257,8 @@ module Lara
227
257
 
228
258
  ProfanityDetectResult.new(
229
259
  masked_text: v["masked_text"],
230
- profanities: v["profanities"] || []
260
+ profanities: v["profanities"] || [],
261
+ error: v["error"]
231
262
  )
232
263
  end
233
264
  end
@@ -56,14 +56,15 @@ module Lara
56
56
  # @param reasoning [Boolean] When true with a block, yields partial results during reasoning
57
57
  # @param headers [Hash,nil]
58
58
  # @param metadata [String, Hash, nil]
59
- # @param profanity_filter [String,nil] One of "detect", "avoid", "hide"
59
+ # @param profanities_detect [String,nil] One of "target", "source_target"
60
+ # @param profanities_handling [String,nil] One of "detect", "avoid", "hide" (default: "hide" when profanities_detect is set)
60
61
  # @yield [Lara::Models::TextResult] Partial translation result (only when reasoning is true)
61
62
  # @return [Lara::Models::TextResult] Final translation result
62
63
  def translate(text, target:, source: nil, source_hint: nil, adapt_to: nil, glossaries: nil,
63
64
  instructions: nil, content_type: nil, multiline: true, timeout_ms: nil,
64
65
  priority: nil, use_cache: nil, cache_ttl_s: nil, no_trace: false, verbose: false,
65
66
  style: nil, reasoning: false, headers: nil, metadata: nil,
66
- profanity_filter: nil,
67
+ profanities_detect: nil, profanities_handling: nil,
67
68
  styleguide_id: nil, styleguide_reasoning: nil,
68
69
  styleguide_explanation_language: nil, &callback)
69
70
  q = normalize_text_input(text)
@@ -92,7 +93,8 @@ module Lara
92
93
  style: style,
93
94
  reasoning: reasoning,
94
95
  metadata: metadata,
95
- profanity_filter: profanity_filter,
96
+ profanities_detect: profanities_detect,
97
+ profanities_handling: profanities_handling,
96
98
  styleguide_id: styleguide_id,
97
99
  styleguide_reasoning: styleguide_reasoning,
98
100
  styleguide_explanation_language: styleguide_explanation_language
@@ -106,7 +108,7 @@ module Lara
106
108
  ->(partial) { callback.call(Lara::Models::TextResult.from_hash(partial)) }
107
109
  end
108
110
 
109
- result = @client.post("/translate", body: body, headers: request_headers, &stream_callback)
111
+ result = @client.post("/v2/translate", body: body, headers: request_headers, &stream_callback)
110
112
  Lara::Models::TextResult.from_hash(result) if result
111
113
  end
112
114
 
@@ -145,7 +147,8 @@ module Lara
145
147
  result = @client.post("/v2/detect/profanities", body: body)
146
148
  Lara::Models::ProfanityDetectResult.new(
147
149
  masked_text: result["masked_text"],
148
- profanities: result["profanities"] || []
150
+ profanities: result["profanities"] || [],
151
+ error: result["error"]
149
152
  )
150
153
  end
151
154
 
data/lib/lara/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lara
4
- VERSION = "1.2.1"
4
+ VERSION = "1.4.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lara-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Translated
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-21 00:00:00.000000000 Z
11
+ date: 2026-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday