runapi-suno 0.2.7 → 0.2.8

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.
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -14,10 +14,10 @@ module RunApi
14
14
  @http = http
15
15
  end
16
16
 
17
- def run(**params)
17
+ def run(options: nil, **params)
18
18
  params = compact_params(params)
19
19
  validate_params!(params)
20
- request(:post, ENDPOINT, body: params)
20
+ request(:post, ENDPOINT, body: params, options: options)
21
21
  end
22
22
 
23
23
  private
@@ -14,10 +14,10 @@ module RunApi
14
14
  @http = http
15
15
  end
16
16
 
17
- def run(**params)
17
+ def run(options: nil, **params)
18
18
  params = compact_params(params)
19
19
  validate_params!(params)
20
- request(:post, ENDPOINT, body: params)
20
+ request(:post, ENDPOINT, body: params, options: options)
21
21
  end
22
22
 
23
23
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -14,10 +14,10 @@ module RunApi
14
14
  @http = http
15
15
  end
16
16
 
17
- def run(**params)
17
+ def run(options: nil, **params)
18
18
  params = compact_params(params)
19
19
  validate_params!(params)
20
- request(:post, ENDPOINT, body: params)
20
+ request(:post, ENDPOINT, body: params, options: options)
21
21
  end
22
22
 
23
23
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -14,10 +14,10 @@ module RunApi
14
14
  @http = http
15
15
  end
16
16
 
17
- def run(**params)
17
+ def run(options: nil, **params)
18
18
  params = compact_params(params)
19
19
  validate_params!(params)
20
- request(:post, ENDPOINT, body: params)
20
+ request(:post, ENDPOINT, body: params, options: options)
21
21
  end
22
22
 
23
23
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -15,19 +15,19 @@ module RunApi
15
15
  @http = http
16
16
  end
17
17
 
18
- def run(**params)
19
- task = create(**params)
20
- poll_until_complete { get(task.id) }
18
+ def run(options: nil, **params)
19
+ task = create(options: options, **params)
20
+ poll_until_complete { get(task.id, options: options) }
21
21
  end
22
22
 
23
- def create(**params)
23
+ def create(options: nil, **params)
24
24
  params = compact_params(params)
25
25
  validate_params!(params)
26
- request(:post, ENDPOINT, body: params)
26
+ request(:post, ENDPOINT, body: params, options: options)
27
27
  end
28
28
 
29
- def get(id)
30
- request(:get, "#{ENDPOINT}/#{id}")
29
+ def get(id, options: nil)
30
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
31
31
  end
32
32
 
33
33
  private
@@ -5,15 +5,8 @@ module RunApi
5
5
  module Validators
6
6
  module_function
7
7
 
8
- MUSIC_PROMPT_SHAPE_ERROR = "choose a valid vocal_mode: auto_lyrics, exact_lyrics, or instrumental"
9
-
10
8
  def validate_text_to_music!(params, resource)
11
- validate_music_prompt_shape!(params, resource)
12
- require_param!(resource, params, :model)
13
- validate_optional!(resource, params, :vocal_mode, Types::VOCAL_MODES)
14
- validate_optional!(resource, params, :model, Types::MODELS)
15
- validate_optional!(resource, params, :vocal_gender, Types::VOCAL_GENDERS)
16
- validate_optional!(resource, params, :persona_type, Types::PERSONA_TYPES)
9
+ resource.send(:validate_contract!, CONTRACT["text-to-music"], params)
17
10
  end
18
11
 
19
12
  def validate_extend_music!(params, resource)
@@ -40,13 +33,7 @@ module RunApi
40
33
  end
41
34
 
42
35
  def validate_cover_audio!(params, resource)
43
- require_param!(resource, params, :upload_url)
44
- require_param!(resource, params, :model)
45
- validate_music_prompt_shape!(params, resource)
46
- validate_optional!(resource, params, :vocal_mode, Types::VOCAL_MODES)
47
- validate_optional!(resource, params, :model, Types::MODELS)
48
- validate_optional!(resource, params, :vocal_gender, Types::VOCAL_GENDERS)
49
- validate_optional!(resource, params, :persona_type, Types::PERSONA_TYPES)
36
+ resource.send(:validate_contract!, CONTRACT["cover-audio"], params)
50
37
  end
51
38
 
52
39
  def validate_add_instrumental!(params, resource)
@@ -87,10 +74,18 @@ module RunApi
87
74
  end
88
75
 
89
76
  def validate_replace_section!(params, resource)
90
- require_all!(resource, params, :task_id, :audio_id, :lyrics, :tags, :title, :infill_start_time, :infill_end_time)
91
- if param(resource, params, :infill_end_time).to_f <= param(resource, params, :infill_start_time).to_f
77
+ resource.send(:validate_contract!, CONTRACT["replace-section"], params)
78
+ validate_replace_section_source!(params, resource)
79
+ start_time = replace_section_time!(params, resource, :infill_start_time)
80
+ end_time = replace_section_time!(params, resource, :infill_end_time)
81
+ if end_time <= start_time
92
82
  raise Core::ValidationError, "infill_end_time must be greater than infill_start_time"
93
83
  end
84
+
85
+ duration = end_time - start_time
86
+ return if duration.between?(6, 60)
87
+
88
+ raise Core::ValidationError, "replacement duration must be between 6 and 60 seconds"
94
89
  end
95
90
 
96
91
  def validate_create_mashup!(params, resource)
@@ -98,12 +93,7 @@ module RunApi
98
93
  unless upload_url_list.is_a?(Array) && upload_url_list.size == 2
99
94
  raise Core::ValidationError, "upload_url_list must contain exactly 2 URLs"
100
95
  end
101
- require_param!(resource, params, :model)
102
- validate_music_prompt_shape!(params, resource)
103
- validate_optional!(resource, params, :vocal_mode, Types::VOCAL_MODES)
104
- validate_optional!(resource, params, :model, Types::MODELS)
105
- validate_optional!(resource, params, :vocal_gender, Types::VOCAL_GENDERS)
106
- validate_optional!(resource, params, :persona_type, Types::PERSONA_TYPES)
96
+ resource.send(:validate_contract!, CONTRACT["create-mashup"], params)
107
97
  end
108
98
 
109
99
  def validate_text_to_sound!(params, resource)
@@ -148,28 +138,6 @@ module RunApi
148
138
  require_param!(resource, params, :description)
149
139
  end
150
140
 
151
- def validate_music_prompt_shape!(params, resource)
152
- mode = param(resource, params, :vocal_mode).to_s
153
- has_prompt = truthy_presence?(param(resource, params, :prompt))
154
- has_lyrics = truthy_presence?(param(resource, params, :lyrics))
155
- has_style = truthy_presence?(param(resource, params, :style))
156
- has_title = truthy_presence?(param(resource, params, :title))
157
-
158
- valid_shape = case mode
159
- when "auto_lyrics"
160
- has_prompt && !has_lyrics && !has_style && !has_title
161
- when "exact_lyrics"
162
- !has_prompt && has_lyrics && has_style && has_title
163
- when "instrumental"
164
- !has_prompt && !has_lyrics && has_style && has_title
165
- else
166
- false
167
- end
168
- return if valid_shape
169
-
170
- raise Core::ValidationError, MUSIC_PROMPT_SHAPE_ERROR
171
- end
172
-
173
141
  def validate_extend_music_prompt_shape!(params, resource)
174
142
  return unless truthy_presence?(param(resource, params, :lyrics))
175
143
 
@@ -187,6 +155,30 @@ module RunApi
187
155
  raise Core::ValidationError, "lyrics can only be used when extending uploaded audio with custom parameters"
188
156
  end
189
157
 
158
+ def validate_replace_section_source!(params, resource)
159
+ has_existing_source = %i[task_id audio_id].any? { |key| truthy_presence?(param(resource, params, key)) }
160
+ has_uploaded_source = %i[upload_url model].any? { |key| truthy_presence?(param(resource, params, key)) }
161
+
162
+ if has_existing_source && has_uploaded_source
163
+ raise Core::ValidationError, "task_id/audio_id cannot be combined with upload_url/model"
164
+ end
165
+
166
+ if has_existing_source
167
+ require_all!(resource, params, :task_id, :audio_id)
168
+ elsif has_uploaded_source
169
+ require_all!(resource, params, :upload_url, :model)
170
+ else
171
+ raise Core::ValidationError, "task_id and audio_id, or upload_url and model are required"
172
+ end
173
+ end
174
+
175
+ def replace_section_time!(params, resource, key)
176
+ value = param(resource, params, key)
177
+ return value.to_f if value.is_a?(Numeric)
178
+
179
+ raise Core::ValidationError, "#{key} must be a number"
180
+ end
181
+
190
182
  def require_all!(resource, params, *keys)
191
183
  keys.each { |key| require_param!(resource, params, key) }
192
184
  end
data/lib/runapi/suno.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "suno/types"
5
+ require_relative "suno/contract_gen"
5
6
  require_relative "suno/validators"
6
7
  require_relative "suno/resources/text_to_music"
7
8
  require_relative "suno/resources/extend_music"