|
9 | 9 | * - mdl_back - back to providers list |
10 | 10 | */ |
11 | 11 | import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime"; |
| 12 | +import { sliceUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime"; |
12 | 13 | import { fitsTelegramCallbackData } from "./approval-callback-data.js"; |
13 | 14 |
|
14 | 15 | export type ButtonRow = Array<{ text: string; callback_data: string }>; |
@@ -41,6 +42,7 @@ export type ModelsKeyboardParams = { |
41 | 42 | }; |
42 | 43 |
|
43 | 44 | const MODELS_PAGE_SIZE = 8; |
| 45 | +const MODEL_BUTTON_LABEL_MAX_LENGTH = 38; |
44 | 46 | const CALLBACK_PREFIX = { |
45 | 47 | providers: "mdl_prov", |
46 | 48 | back: "mdl_back", |
@@ -220,7 +222,7 @@ export function buildModelsKeyboard(params: ModelsKeyboardParams): ButtonRow[] { |
220 | 222 | const isCurrentModel = isCurrentModelSelection({ currentModel, provider, model }); |
221 | 223 | const fallbackLabel = model.includes("/") ? `${provider}/${model}` : model; |
222 | 224 | const displayLabel = modelNames?.get(`${provider}/${model}`) ?? fallbackLabel; |
223 | | - const displayText = truncateModelId(displayLabel, 38); |
| 225 | + const displayText = truncateModelLabel(displayLabel, MODEL_BUTTON_LABEL_MAX_LENGTH); |
224 | 226 | const text = isCurrentModel ? `${displayText} ✓` : displayText; |
225 | 227 |
|
226 | 228 | rows.push([ |
@@ -271,14 +273,13 @@ export function buildBrowseProvidersButton(): ButtonRow[] { |
271 | 273 | } |
272 | 274 |
|
273 | 275 | /** |
274 | | - * Truncate model ID for display, preserving end if too long. |
| 276 | + * Truncate a model label for display, preserving its end if too long. |
275 | 277 | */ |
276 | | -function truncateModelId(modelId: string, maxLen: number): string { |
277 | | - if (modelId.length <= maxLen) { |
278 | | - return modelId; |
| 278 | +function truncateModelLabel(modelLabel: string, maxLen: number): string { |
| 279 | + if (modelLabel.length <= maxLen) { |
| 280 | + return modelLabel; |
279 | 281 | } |
280 | | - // Show last part with ellipsis prefix |
281 | | - return `…${modelId.slice(-(maxLen - 1))}`; |
| 282 | + return `…${sliceUtf16Safe(modelLabel, -(maxLen - 1))}`; |
282 | 283 | } |
283 | 284 |
|
284 | 285 | /** |
|
0 commit comments