openclacky 1.5.27 → 1.5.28

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.clacky/skills/gem-release/SKILL.md +7 -1
  3. data/CHANGELOG.md +27 -0
  4. data/lib/clacky/billing/platform_billing.rb +7 -0
  5. data/lib/clacky/default_extensions/knowledge/README.md +3 -3
  6. data/lib/clacky/default_extensions/knowledge/README.zh.md +3 -3
  7. data/lib/clacky/default_extensions/knowledge/ext.yml +2 -2
  8. data/lib/clacky/default_extensions/knowledge/lib/index.rb +3 -1
  9. data/lib/clacky/default_extensions/knowledge/lib/knowledge.rb +1 -1
  10. data/lib/clacky/default_extensions/knowledge/lib/t2s.rb +44 -0
  11. data/lib/clacky/default_extensions/knowledge/lib/t2s.txt +3221 -0
  12. data/lib/clacky/default_extensions/knowledge/panels/kb/view.js +25 -7
  13. data/lib/clacky/default_extensions/side-chat/README.md +1 -1
  14. data/lib/clacky/default_extensions/side-chat/README.zh.md +1 -1
  15. data/lib/clacky/default_extensions/side-chat/api/runtime.rb +7 -2
  16. data/lib/clacky/default_extensions/side-chat/panels/side-chat/view.js +58 -16
  17. data/lib/clacky/default_extensions/terminal/README.md +2 -0
  18. data/lib/clacky/default_extensions/terminal/README.zh.md +2 -0
  19. data/lib/clacky/default_extensions/terminal/panels/terminal/view.js +80 -10
  20. data/lib/clacky/default_parsers/deepseek_ocr.rb +275 -0
  21. data/lib/clacky/default_parsers/pdf_parser.rb +39 -10
  22. data/lib/clacky/default_skills/media-gen/SKILL.md +5 -2
  23. data/lib/clacky/media/openai_compat.rb +17 -1
  24. data/lib/clacky/message_format/open_ai.rb +2 -2
  25. data/lib/clacky/message_format/open_ai_responses.rb +8 -2
  26. data/lib/clacky/providers.rb +34 -18
  27. data/lib/clacky/reasoning_levels.rb +2 -2
  28. data/lib/clacky/server/http_server.rb +104 -14
  29. data/lib/clacky/server/session_registry.rb +1 -1
  30. data/lib/clacky/utils/model_pricing.rb +9 -0
  31. data/lib/clacky/version.rb +1 -1
  32. data/lib/clacky/web/components/code-editor.js +45 -0
  33. data/lib/clacky/web/components/custom-select.js +15 -2
  34. data/lib/clacky/web/components/model-picker.js +11 -0
  35. data/lib/clacky/web/components/quote-select.js +7 -2
  36. data/lib/clacky/web/core/ext.js +34 -1
  37. data/lib/clacky/web/features/workspace/view.js +4 -2
  38. data/lib/clacky/web/i18n.js +28 -18
  39. data/lib/clacky/web/index.html +0 -2
  40. data/lib/clacky/web/sessions.js +74 -0
  41. metadata +4 -2
  42. data/lib/clacky/web/vendor/katex/auto-render.min.js +0 -1
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # DeepSeek OCR — upload a whole document once, get every page back as text.
5
+ #
6
+ # Usage:
7
+ # ruby deepseek_ocr.rb <file_path> # text to stdout
8
+ # ruby deepseek_ocr.rb <file_path> <out_file> # text to a file
9
+ #
10
+ # stdout carries only the page text (so `> out.md` works); progress and
11
+ # errors go to stderr.
12
+ #
13
+ # Why this exists
14
+ # ---------------
15
+ # pdftotext only reads embedded text layers. Scanned books have none, so
16
+ # pdf_parser.rb emits a Notice asking the agent to render pages to PNG one
17
+ # at a time. That works for a handful of pages but not for a 300-page book.
18
+ # DeepSeek's OCR endpoint takes the whole file in one multipart request and
19
+ # returns per-page text, billed per page (1.5 CNY per 1000 pages).
20
+ #
21
+ # Upstream limits that shape this script
22
+ # --------------------------------------
23
+ # - 180s hard wall clock per request, no resumption. A request that
24
+ # exceeds it fails and the whole upload is wasted, so page count is
25
+ # checked up front instead of discovering the timeout after paying.
26
+ # - 100 MiB body limit.
27
+ # - 1000 page limit, but 180s binds first.
28
+ #
29
+ # Credentials come from ~/.clacky/config.yml — the file the agent itself
30
+ # reads. The provider marked `type: "default"` is the one the session runs
31
+ # on, so OCR rides that key and no separate credential store exists. Only
32
+ # DeepSeek-hosted base URLs (the openclacky gateway or api.deepseek.com) can
33
+ # serve /v1/tools/ocr; any other default provider is rejected loudly rather
34
+ # than silently billed to a different key.
35
+ #
36
+ # VERSION: 4
37
+
38
+ require "json"
39
+ require "net/http"
40
+ require "open3"
41
+ require "securerandom"
42
+ require "yaml"
43
+
44
+ OCR_HOST = "api.deepseek.com"
45
+ GATEWAY_HOST = "openclacky.com"
46
+ OCR_PATH = "/v1/tools/ocr"
47
+ CONFIG_PATH = File.expand_path("~/.clacky/config.yml")
48
+ RMB_PER_K_PAGE = 1.5
49
+ # Upstream advertises 100 MiB, but its own edge answers 413 past ~50 MiB
50
+ # (45 MiB passes, 50 MiB does not via either the gateway or api.deepseek.com
51
+ # directly). Reject locally instead of uploading bytes that are sure to be
52
+ # thrown away.
53
+ MAX_BYTES = 45 * 1024 * 1024
54
+ READ_TIMEOUT = 240
55
+ # Measured: 111 pages in 21.9s including a 7.7 MB upload (~0.2s/page).
56
+ # The 180s wall leaves room for ~800 pages, but dense table pages burn far
57
+ # more time than prose, so 400 keeps a 2x margin.
58
+ MAX_PAGES = 400
59
+ # Upstream renders a table whose column count it cannot parse as
60
+ # <th>Col1</th>...<th>Col1148</th>, and on other dense layouts it falls into
61
+ # repeating a glyph pair until the token budget runs out ("n m n m …",
62
+ # "二二二…", "6. 6. …"). Both carry no real text.
63
+ COL_NOISE_LIMIT = 20
64
+
65
+ def die(message)
66
+ warn message
67
+ exit 1
68
+ end
69
+
70
+ # Picks the OCR endpoint from the provider the session runs on. config.yml
71
+ # marks exactly one provider as `type: "default"`, which is the only field
72
+ # expressing "the model in use" — so it is read directly instead of scanning
73
+ # the list by hostname. Returns {"error" => ...} when that provider cannot
74
+ # serve OCR, leaving the message to the caller.
75
+ def resolve_provider(config)
76
+ models = config.is_a?(Hash) ? Array(config["models"]) : []
77
+ default = models.find { |m| m.is_a?(Hash) && m["type"] == "default" }
78
+ if default.nil?
79
+ return { "error" => "No provider is marked type: \"default\" in #{CONFIG_PATH}." }
80
+ end
81
+
82
+ api_key = default["api_key"].to_s.strip
83
+ if api_key.empty?
84
+ return { "error" => "The default provider has no api_key in #{CONFIG_PATH}." }
85
+ end
86
+
87
+ base_url = default["base_url"].to_s.strip
88
+ unless base_url.include?(GATEWAY_HOST) || base_url.include?(OCR_HOST)
89
+ return {
90
+ "error" => "The default provider points at #{base_url}, which does not " \
91
+ "serve #{OCR_PATH}. OCR runs on #{GATEWAY_HOST} or #{OCR_HOST} " \
92
+ "only — switch the default model to one of them."
93
+ }
94
+ end
95
+
96
+ {
97
+ "base_url" => base_url,
98
+ "api_key" => api_key,
99
+ "via" => base_url.include?(GATEWAY_HOST) ? "gateway" : "direct"
100
+ }
101
+ end
102
+
103
+ # Reads the resolved endpoint, or exits with the reason it could not be read.
104
+ def provider_config
105
+ config = begin
106
+ YAML.load_file(CONFIG_PATH)
107
+ rescue StandardError
108
+ {}
109
+ end
110
+
111
+ resolved = resolve_provider(config)
112
+ die resolved["error"] if resolved["error"]
113
+ resolved
114
+ end
115
+
116
+ # Builds the OCR URI from a provider base URL, tolerating a trailing /v1 —
117
+ # both api.deepseek.com and api.openclacky.com serve /v1/tools/ocr.
118
+ def ocr_uri(base_url)
119
+ root = base_url.to_s.strip.chomp("/")
120
+ root = "https://#{root}" unless root =~ %r{\Ahttps?://}
121
+ root = root.sub(%r{/v1\z}, "")
122
+ URI("#{root}#{OCR_PATH}")
123
+ end
124
+
125
+ def pdf_page_count(path)
126
+ return nil unless File.extname(path).downcase == ".pdf"
127
+
128
+ output, status = Open3.capture2e("pdfinfo", path)
129
+ return nil unless status.success?
130
+
131
+ output[/^Pages:\s+(\d+)/, 1]&.to_i
132
+ rescue Errno::ENOENT
133
+ nil
134
+ end
135
+
136
+ def multipart_body(file_path, fields)
137
+ boundary = "----ClackyOCR#{SecureRandom.hex(16)}"
138
+ body = +"".b
139
+
140
+ fields.each do |name, value|
141
+ body << "--#{boundary}\r\n".b
142
+ body << "Content-Disposition: form-data; name=\"#{name}\"\r\n\r\n".b
143
+ body << "#{value}\r\n".b
144
+ end
145
+
146
+ body << "--#{boundary}\r\n".b
147
+ body << "Content-Disposition: form-data; name=\"file\"; " \
148
+ "filename=\"#{File.basename(file_path)}\"\r\n".b
149
+ body << "Content-Type: application/octet-stream\r\n\r\n".b
150
+ body << File.binread(file_path)
151
+ body << "\r\n--#{boundary}--\r\n".b
152
+
153
+ [body, "multipart/form-data; boundary=#{boundary}"]
154
+ end
155
+
156
+ def post_file(config, path)
157
+ body, content_type = multipart_body(path, "purpose" => "text_recognition")
158
+ uri = ocr_uri(config["base_url"])
159
+
160
+ http = Net::HTTP.new(uri.host, uri.port)
161
+ http.use_ssl = uri.scheme == "https"
162
+ http.open_timeout = 30
163
+ http.read_timeout = READ_TIMEOUT
164
+ http.write_timeout = 120
165
+
166
+ request = Net::HTTP::Post.new(uri.request_uri)
167
+ request["Authorization"] = "Bearer #{config["api_key"]}"
168
+ request["Content-Type"] = content_type
169
+ request.body = body
170
+ http.request(request)
171
+ end
172
+
173
+ # Uploads the scan to the resolved endpoint.
174
+ def post_ocr(path, config = provider_config)
175
+ warn "Uploading for OCR via the #{config["via"]} (#{ocr_uri(config["base_url"]).host})..."
176
+ post_file(config, path)
177
+ end
178
+
179
+ def error_message(response)
180
+ JSON.parse(response.body).dig("error", "message")
181
+ rescue StandardError
182
+ response.body.to_s[0, 300]
183
+ end
184
+
185
+ # True when the model gave up on the page. Whitespace is stripped first so
186
+ # spaced-out repeats ("n m n m", "地 地 地") are caught the same way as dense
187
+ # ones, and a run has to cover most of the page — a short repeated tail is
188
+ # normal prose punctuation, not a failure.
189
+ def unusable?(text)
190
+ return true if text.scan(/Col\d+/).size > COL_NOISE_LIMIT
191
+
192
+ compact = text.gsub(/\s+/, "")
193
+ return false if compact.size < 200
194
+
195
+ run = compact.match(/(.{1,2}?)\1{19,}/)
196
+ !run.nil? && run[0].size > compact.size * 0.5
197
+ end
198
+
199
+ def page_texts(payload)
200
+ Array(payload["pages"]).map do |page|
201
+ text = page["text"].to_s.strip
202
+ index = page["index"].to_i + 1
203
+ truncated = page["finish_reason"] == "length"
204
+
205
+ next nil if text.empty?
206
+
207
+ if unusable?(text)
208
+ next "--- Page #{index} --- (unreadable table)\n\n" \
209
+ "[layout too dense to transcribe — render this page to PNG and " \
210
+ "read it with file_reader if its content is needed]"
211
+ end
212
+
213
+ marker = truncated ? " (truncated)" : ""
214
+ "--- Page #{index} ---#{marker}\n\n#{text}"
215
+ end.compact
216
+ end
217
+
218
+ def main(argv)
219
+ die "Usage: deepseek_ocr.rb <file_path> [output_file]" if argv.empty?
220
+
221
+ path = argv[0]
222
+ out_path = argv[1]
223
+ die "File not found: #{path}" unless File.file?(path)
224
+
225
+ size = File.size(path)
226
+ die "File is #{(size / 1024.0 / 1024).round(1)} MB, over the 45 MB limit." if size > MAX_BYTES
227
+
228
+ pages = pdf_page_count(path)
229
+ if pages && pages > MAX_PAGES
230
+ die "#{pages} pages exceeds the #{MAX_PAGES}-page cap — the OCR request " \
231
+ "has a 180s wall clock that cannot be resumed, so split the PDF first " \
232
+ "(e.g. `qpdf --pages . 1-200 -- <in> <out1>.pdf`)."
233
+ end
234
+
235
+ megabytes = size / 1024.0 / 1024
236
+ estimate = (megabytes / 2 + pages.to_i * 0.2).ceil
237
+ warn "Checking #{File.basename(path)}... #{pages ? "#{pages} pages, " : ""}" \
238
+ "#{megabytes.round(1)} MB, about #{estimate}s to go"
239
+ warn "The request cannot be resumed once started; if it approaches 180s " \
240
+ "the upstream gives up and the upload is wasted." if estimate > 150
241
+
242
+ started = Time.now
243
+ config = provider_config
244
+ response = post_ocr(path, config)
245
+
246
+ if response.is_a?(Net::HTTPNotFound)
247
+ die "#{ocr_uri(config["base_url"]).host} does not serve #{OCR_PATH} (404). " \
248
+ "The gateway returns this until the OCR route is deployed there."
249
+ end
250
+
251
+ unless response.is_a?(Net::HTTPSuccess)
252
+ die "OCR failed: HTTP #{response.code} — #{error_message(response)}"
253
+ end
254
+
255
+ payload = JSON.parse(response.body)
256
+ chunks = page_texts(payload)
257
+
258
+ die "OCR returned no text — the file may be blank or unreadable." if chunks.empty?
259
+
260
+ total_pages = payload["page_count"] || chunks.size
261
+ cost = total_pages.to_f * RMB_PER_K_PAGE / 1000
262
+ elapsed = (Time.now - started).round(1)
263
+ body = chunks.join("\n\n") + "\n"
264
+
265
+ if out_path
266
+ File.write(out_path, body)
267
+ warn "Done: #{total_pages} pages in #{elapsed}s, ~#{format('%.3f', cost)} CNY"
268
+ warn "Wrote #{out_path} (#{body.bytesize} bytes)"
269
+ else
270
+ warn "Done: #{total_pages} pages in #{elapsed}s, ~#{format('%.3f', cost)} CNY"
271
+ $stdout.write(body)
272
+ end
273
+ end
274
+
275
+ main(ARGV) if __FILE__ == $PROGRAM_NAME
@@ -30,7 +30,7 @@
30
30
  # to waste. The agent decides when (and which page) to OCR based on the
31
31
  # user's actual question.
32
32
  #
33
- # VERSION: 6
33
+ # VERSION: 8
34
34
 
35
35
  require "open3"
36
36
 
@@ -57,6 +57,12 @@ rescue Errno::ENOENT
57
57
  nil
58
58
  end
59
59
 
60
+ def compress_ranges(numbers)
61
+ numbers.chunk_while { |a, b| b == a + 1 }.map do |run|
62
+ run.size > 2 ? "#{run.first}-#{run.last}" : run.join(", ")
63
+ end.join(", ")
64
+ end
65
+
60
66
  def main(argv)
61
67
  die "Usage: pdf_parser.rb <file_path>" if argv.empty?
62
68
  path = argv[0]
@@ -77,22 +83,45 @@ def main(argv)
77
83
  end
78
84
  end
79
85
 
80
- output = body_chunks.join("\n\n")
86
+ # A fully-scanned book would otherwise emit one placeholder per page, which
87
+ # is pure token cost — the Notice below already says every page is an image.
88
+ fully_scanned = !pages.empty? && weak.size == pages.size
89
+ output = if fully_scanned
90
+ +"[This PDF has no text layer on any page — every page is a scanned image.]"
91
+ else
92
+ body_chunks.join("\n\n")
93
+ end
81
94
 
82
95
  if weak.any?
83
96
  abs_path = File.expand_path(path)
97
+ ocr_script = File.join(File.dirname(File.expand_path(__FILE__)), "deepseek_ocr.rb")
84
98
  notice = +"\n\n--- Notice ---\n\n"
85
- notice << "#{weak.size} of #{pages.size} pages have no extractable text layer "
86
- notice << "(likely scanned images).\n"
87
- notice << "Pages without text: #{weak.join(', ')}\n\n"
88
- notice << "To OCR a specific page, render it to PNG via shell, then "
89
- notice << "file_reader the PNG (it will be transcribed via the "
90
- notice << "vision/OCR pipeline):\n\n"
99
+ if fully_scanned
100
+ notice << "All #{pages.size} pages are scanned images with no text layer.\n\n"
101
+ else
102
+ notice << "#{weak.size} of #{pages.size} pages have no extractable text "
103
+ notice << "layer (likely scanned images).\n"
104
+ notice << "Pages without text: #{compress_ranges(weak)}\n\n"
105
+ end
106
+ notice << "If only a few pages are needed, render one to PNG and read it "
107
+ notice << "with file_reader (transcribed by the vision pipeline):\n\n"
91
108
  notice << " pdftoppm -r 150 -f <N> -l <N> -png -singlefile "
92
109
  notice << "#{abs_path.inspect} /tmp/clacky-pdf-page-<N>\n"
93
110
  notice << " # produces /tmp/clacky-pdf-page-<N>.png\n\n"
94
- notice << "Only render pages you actually need. If the user's question "
95
- notice << "is already answered by the extracted text above, skip OCR.\n"
111
+ notice << "If many pages are needed, send the whole file to a cloud OCR "
112
+ notice << "engine instead (DeepSeek, about 1.5 CNY per 1000 pages, strong "
113
+ notice << "on Chinese scans and vertical typesetting):\n\n"
114
+ notice << " ruby #{ocr_script.inspect} #{abs_path.inspect} /tmp/ocr.md\n"
115
+ notice << " # then file_reader /tmp/ocr.md\n\n"
116
+ notice << "That runs at roughly 0.2s per page but gives up past a 180s "
117
+ notice << "wall clock with no resumption, so split books over ~400 pages "
118
+ notice << "(or over 45 MB) first. Pages whose layout is too dense — "
119
+ notice << "wide tables, phonetic charts — come back marked "
120
+ notice << "\"(unreadable table)\"; render those individually if needed.\n\n"
121
+ unless fully_scanned
122
+ notice << "If the user's question is already answered by the extracted "
123
+ notice << "text above, skip OCR entirely.\n"
124
+ end
96
125
  output << notice
97
126
  end
98
127
 
@@ -29,7 +29,7 @@ curl -s http://${CLACKY_SERVER_HOST}:${CLACKY_SERVER_PORT}/api/media/types
29
29
 
30
30
  If the response shows `image.configured = false`, stop and tell the user:
31
31
 
32
- > 还没有配置生图模型。请打开设置页 → 添加模型 → 类型选 `image`(走 openclacky 官方网关时推荐 `or-gemini-3-pro-image` 或 `or-gpt-image-2`)。配好后再让我生图。
32
+ > 还没有配置生图模型。请打开设置页 → 添加模型 → 类型选 `image`(走 openclacky 官方网关时推荐 `or-gemini-nano-banana-2-1` 或 `or-gpt-image-2-6`)。配好后再让我生图。
33
33
 
34
34
  Do NOT try to fall back to `terminal` + a hand-written `curl https://api.openai.com/...` — that bypasses the user's configured backend and won't be billed correctly.
35
35
 
@@ -190,7 +190,7 @@ When the user gives a vague request like "给我配张图", ask one clarifying q
190
190
  - The user wants a **diagram / chart** with specific data — use a charting library (matplotlib, mermaid, etc.) instead; image gen is for illustrations, not data viz
191
191
  - The user asks for **screenshots** of real software — use the browser tool
192
192
 
193
- ## Generating video (Gemini Omni / Veo)
193
+ ## Generating video (Gemini Omni / Veo / Seedance / Wan)
194
194
 
195
195
  The same `/api/media/` namespace serves video generation. The user must
196
196
  configure a `type=video` model in settings (recommended: `or-gemini-omni-flash`).
@@ -198,6 +198,9 @@ configure a `type=video` model in settings (recommended: `or-gemini-omni-flash`)
198
198
  | Model | Duration | Notes |
199
199
  |------------------------|----------|-------|
200
200
  | `or-gemini-omni-flash` | 3–15 s | Default. Newest, ~$0.07/s at 720p. |
201
+ | `or-seedance-2-5` | 4–30 s | ByteDance. Cinematic motion, ~$0.24/s at 720p. See the Seedance section below. |
202
+ | `or-seedance-2-5-flash`| 4–30 s | ByteDance. Faster and cheaper, ~$0.16/s at 720p. |
203
+ | `or-wan-3-0` | 2–30 s | Alibaba. Cheapest per second, ~$0.10/s at 720p; first-frame image-to-video supported. |
201
204
  | `or-veo-3-1` | 4–8 s | Best cinematic quality, ~$0.40/s. |
202
205
  | `or-veo-3-1-fast` | 4–8 s | ~$0.10/s. |
203
206
  | `or-veo-3-1-lite` | 4–8 s | Cheapest, ~$0.05/s. |
@@ -55,7 +55,7 @@ module Clacky
55
55
  DEEPSEEK_TTS_DEFAULT_VOICE = "stella"
56
56
  DEEPSEEK_TTS_MAX_BILLING_CHARS = 2000
57
57
 
58
- def generate_image(prompt:, aspect_ratio: DEFAULT_ASPECT, output_dir: nil, n: 1, image: nil, images: nil, **_kwargs)
58
+ def generate_image(prompt:, aspect_ratio: DEFAULT_ASPECT, output_dir: nil, n: 1, image: nil, images: nil, **kwargs)
59
59
  provider_id = Clacky::Providers.find_by_base_url(@base_url) || "custom"
60
60
  aspect = ASPECT_TO_SIZE.key?(aspect_ratio) ? aspect_ratio : DEFAULT_ASPECT
61
61
  size = ASPECT_TO_SIZE[aspect]
@@ -108,6 +108,11 @@ module Clacky
108
108
  # multi-image edits work; the gateway also accepts a single `image`.
109
109
  payload[:images] = input_images unless input_images.empty?
110
110
 
111
+ # Seedream is billed per image and picks the output bucket from
112
+ # `resolution`; default to the cheapest 1K tier unless the caller asks
113
+ # for more. Other models infer size from `size` and reject the field.
114
+ payload[:resolution] = normalize_image_resolution(kwargs[:resolution]) if seedream_family?(@model)
115
+
111
116
  begin
112
117
  response = connection.post("images/generations") do |req|
113
118
  req.headers["Content-Type"] = "application/json"
@@ -842,6 +847,17 @@ module Clacky
842
847
  model_name.to_s.match?(/gemini|imagen/i)
843
848
  end
844
849
 
850
+ private def seedream_family?(model_name)
851
+ model_name.to_s.match?(/seedream/i)
852
+ end
853
+
854
+ # Seedream accepts "1K" / "1.5K" / "2K". Anything else (including nil)
855
+ # falls back to 1K, the cheapest bucket.
856
+ private def normalize_image_resolution(value)
857
+ resolution = value.to_s.strip.upcase
858
+ %w[1K 1.5K 2K].include?(resolution) ? resolution : "1K"
859
+ end
860
+
845
861
  # Normalise the optional image/edit inputs into an array of data URLs
846
862
  # ("data:<mime>;base64,<payload>") the gateway understands. Each input
847
863
  # may be a local file path, a data URL, or a bare base64 string.
@@ -260,8 +260,8 @@ module Clacky
260
260
  def self.apply_reasoning_params(body, model, reasoning_effort, responses_api: false)
261
261
  effort_str = reasoning_effort.to_s
262
262
 
263
- if model.to_s.match?(/\Aglm-5[-.]3/i)
264
- # GLM-5.3 always thinks: thinking.type "disabled" is rejected with an
263
+ if model.to_s.match?(/\Aglm-5[-.][34]/i)
264
+ # GLM-5.3/5.4 always think: thinking.type "disabled" is rejected with an
265
265
  # error (Z.ai migration guide), so "off" maps to the lightest effort
266
266
  # "low". Effort accepts low/high/max only; server default is max.
267
267
  body[:thinking] = { type: "enabled" }
@@ -123,7 +123,9 @@ module Clacky
123
123
 
124
124
  # Normalize canonical content to Responses API content format.
125
125
  #
126
- # String content passes through as-is.
126
+ # String content passes through as-is, except a blank one: the Responses
127
+ # API has no empty text body, and a quote-only turn sends its text in the
128
+ # following injected message, so use the same placeholder as the block path.
127
129
  # Array content: text blocks -> input_text, image_url -> input_image
128
130
  # (non-vision models get a text placeholder for images).
129
131
  #
@@ -131,7 +133,11 @@ module Clacky
131
133
  # @param vision_supported [Boolean]
132
134
  # @return [String, Array]
133
135
  def normalize_content(content, vision_supported:)
134
- return content.to_s unless content.is_a?(Array)
136
+ unless content.is_a?(Array)
137
+ return [{ type: "input_text", text: "..." }] if content.to_s.empty?
138
+
139
+ return content.to_s
140
+ end
135
141
 
136
142
  blocks = content.map { |b| normalize_block(b, vision_supported: vision_supported) }.compact
137
143
  blocks = [{ type: "input_text", text: "..." }] if blocks.empty?
@@ -72,42 +72,56 @@ module Clacky
72
72
  # provider class handles them. `or-` prefix is a routing alias
73
73
  # only — the platform may dispatch to OpenRouter or Vertex AI
74
74
  # (Gemini Nano Banana family) depending on the model.
75
+ #
76
+ # Retired from the picker once cheaper or faster replacements
77
+ # shipped: Nano Banana 2 (same as 2.1 at twice the price), GPT
78
+ # Image 2.5 sunburst/flare (2.6 is the same price, ~50% faster)
79
+ # and GPT Image 2 (previous gen). The gateway still routes all
80
+ # of them so old configs and old bills keep working.
75
81
  "image_models" => [
76
82
  "or-gemini-nano-banana-2-1",
77
83
  "or-gemini-3-pro-image",
78
- "or-gemini-3-1-flash-image",
79
84
  "or-gemini-3-1-flash-lite-image",
80
- "or-gpt-image-2-5",
81
- "or-gpt-image-2-5-flare",
82
- "or-gpt-image-2"
85
+ "or-gpt-image-2-6",
86
+ "or-gpt-image-2-6-flare",
87
+ "or-seedream-5-5",
88
+ "or-seedream-5-0-flash"
83
89
  ],
84
90
  "image_model_aliases" => {
85
91
  "or-gemini-nano-banana-2-1" => "Nano Banana 2.1",
86
92
  "or-gemini-3-pro-image" => "Nano Banana Pro",
87
- "or-gemini-3-1-flash-image" => "Nano Banana 2",
88
93
  "or-gemini-3-1-flash-lite-image" => "Nano Banana 2 Lite",
89
- "or-gpt-image-2-5" => "GPT Image 2.5",
90
- "or-gpt-image-2-5-flare" => "GPT Image 2.5 Flare",
91
- "or-gpt-image-2" => "GPT Image 2"
94
+ "or-gpt-image-2-6" => "GPT Image 2.6",
95
+ "or-gpt-image-2-6-flare" => "GPT Image 2.6 Flare",
96
+ "or-seedream-5-5" => "Seedream 5.5",
97
+ "or-seedream-5-0-flash" => "Seedream 5.0 Flash"
92
98
  },
93
99
  "default_image_model" => "or-gemini-nano-banana-2-1",
94
100
  # Video generation models served by the openclacky gateway. Gemini
95
101
  # Omni Flash rides Vertex's Interactions API (token-billed, 3–15s);
96
- # the Veo 3.1 family uses async predictLongRunning (per-second, 4–8s).
97
- # The gateway hides the polling and returns the MP4 inline for both.
102
+ # the Veo 3.1 family uses async predictLongRunning (per-second, 4–8s);
103
+ # Seedance and Wan ride OpenRouter's async Video API (per-second,
104
+ # resolution-tiered, up to 30s). The gateway hides the polling and
105
+ # returns the MP4 inline for all of them.
98
106
  # Veo 3 / Veo 3 Fast are still routable server-side for old configs
99
107
  # but no longer offered: same price as 3.1 with older quality.
100
108
  "video_models" => [
101
109
  "or-gemini-omni-flash",
110
+ "or-seedance-2-5",
111
+ "or-seedance-2-5-flash",
112
+ "or-wan-3-0",
102
113
  "or-veo-3-1",
103
114
  "or-veo-3-1-fast",
104
115
  "or-veo-3-1-lite"
105
116
  ],
106
117
  "video_model_aliases" => {
107
- "or-gemini-omni-flash" => "Gemini Omni Flash",
108
- "or-veo-3-1" => "Veo 3.1",
109
- "or-veo-3-1-fast" => "Veo 3.1 Fast",
110
- "or-veo-3-1-lite" => "Veo 3.1 Lite"
118
+ "or-gemini-omni-flash" => "Gemini Omni Flash",
119
+ "or-seedance-2-5" => "Seedance 2.5",
120
+ "or-seedance-2-5-flash" => "Seedance 2.5 Flash",
121
+ "or-wan-3-0" => "Wan 3.0",
122
+ "or-veo-3-1" => "Veo 3.1",
123
+ "or-veo-3-1-fast" => "Veo 3.1 Fast",
124
+ "or-veo-3-1-lite" => "Veo 3.1 Lite"
111
125
  },
112
126
  "default_video_model" => "or-gemini-omni-flash",
113
127
  # Text-to-speech models served by the openclacky gateway. or-tts-
@@ -278,8 +292,8 @@ module Clacky
278
292
  "name" => "GLM (Z.ai / Zhipu)",
279
293
  "base_url" => "https://open.bigmodel.cn/api/paas/v4",
280
294
  "api" => "openai-completions",
281
- "default_model" => "glm-5.3",
282
- "models" => ["glm-5.3", "glm-5.3-flashx", "glm-5.3-flash", "glm-5.2"],
295
+ "default_model" => "glm-5.4",
296
+ "models" => ["glm-5.4", "glm-5.3", "glm-5.3-flashx", "glm-5.3-flash", "glm-5.2"],
283
297
  # Zhipu / Z.ai expose four functionally-equivalent endpoints:
284
298
  # two regional sites (mainland open.bigmodel.cn + international api.z.ai)
285
299
  # each with a general-billing and a Coding-Plan subpath. They share the
@@ -295,10 +309,11 @@ module Clacky
295
309
  { "label" => "International · Pay-as-you-go", "label_key" => "settings.models.baseurl.variant.international_payg", "base_url" => "https://api.z.ai/api/paas/v4", "region" => "intl" }.freeze,
296
310
  { "label" => "International · Coding Plan", "label_key" => "settings.models.baseurl.variant.international_coding","base_url" => "https://api.z.ai/api/coding/paas/v4", "region" => "intl" }.freeze
297
311
  ].freeze,
298
- # GLM models are text-only except the vision-capable SKUs: glm-5v-turbo
299
- # (legacy), glm-5.3-flash, and glm-5.3-flashx.
312
+ # GLM models are text-only except the vision-capable SKUs: glm-5.4,
313
+ # glm-5v-turbo (legacy), glm-5.3-flash, and glm-5.3-flashx.
300
314
  "capabilities" => { "vision" => false }.freeze,
301
315
  "model_capabilities" => {
316
+ "glm-5.4" => { "vision" => true }.freeze,
302
317
  "glm-5v-turbo" => { "vision" => true }.freeze,
303
318
  "glm-5.3-flash" => { "vision" => true }.freeze,
304
319
  "glm-5.3-flashx" => { "vision" => true }.freeze
@@ -625,6 +640,7 @@ module Clacky
625
640
  # offer GLM-5.3. It is available on the Coding/Agent Plan endpoints;
626
641
  # the pay-as-you-go endpoint does not carry it yet (no versioned id),
627
642
  # so no payg alias is registered for it.
643
+ "glm-5.4",
628
644
  "glm-5.3",
629
645
  "glm-5.3-flash",
630
646
  "deepseek-v4.1-flash",
@@ -21,9 +21,9 @@ module Clacky
21
21
  # Matching is anchored and ordered: the first entry that matches wins, so a
22
22
  # narrow family must come before the broader one it belongs to.
23
23
  FAMILIES = [
24
- # GLM-5.3 always thinks and accepts low/high/max only; the adapter maps
24
+ # GLM-5.3/5.4 always think and accept low/high/max only; the adapter maps
25
25
  # off/low/medium onto "low".
26
- [/\Aglm-5[-.]3/i, %w[low high max]],
26
+ [/\Aglm-5[-.][34]/i, %w[low high max]],
27
27
  # Older GLM accepts thinking on/off plus a high/max effort; low and medium
28
28
  # both collapse onto "high".
29
29
  [/\Aglm-[45]/i, %w[off high max]],