@ihazz/bitrix24 1.1.6 → 1.1.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.
package/src/commands.ts CHANGED
@@ -4,12 +4,21 @@
4
4
  * Standard OpenClaw bot commands registered via imbot.v2.Command.register.
5
5
  */
6
6
 
7
+ import {
8
+ commandDescription,
9
+ commandGroupLabel,
10
+ commandHelpTextLabels,
11
+ commandParams,
12
+ commandRegistrationParams,
13
+ commandRegistrationTitle,
14
+ modelsCommandReplyLabels,
15
+ } from './i18n.js';
16
+ import type { CommandGroup } from './i18n.js';
17
+
7
18
  export interface BotCommandDef {
8
19
  command: string;
9
- en: string;
10
- ru: string;
11
- params?: string;
12
- group: 'status' | 'session' | 'options' | 'management' | 'tools' | 'export';
20
+ hasParams?: boolean;
21
+ group: CommandGroup;
13
22
  }
14
23
 
15
24
  const SHORT_HELP_COMMANDS = new Set(['help', 'status', 'commands', 'new', 'models']);
@@ -17,94 +26,70 @@ const COMMAND_META_COLOR = '#6C788A';
17
26
  const COMMAND_GROUP_ORDER = ['status', 'session', 'options', 'management', 'tools', 'export'] as const;
18
27
  const MODELS_PROVIDER_LINE_RE = /^[•*-]\s+([^()\s]+)\s+\((\d+)\)$/i;
19
28
 
20
- const COMMAND_GROUP_LABELS = {
21
- ru: {
22
- status: 'Справка и статус',
23
- session: 'Сессия',
24
- options: 'Параметры',
25
- management: 'Управление',
26
- tools: 'Инструменты',
27
- export: 'Экспорт',
28
- },
29
- en: {
30
- status: 'Help and status',
31
- session: 'Session',
32
- options: 'Options',
33
- management: 'Management',
34
- tools: 'Tools',
35
- export: 'Export',
36
- },
37
- } as const;
38
-
39
29
  /**
40
30
  * Standard OpenClaw commands.
41
31
  * Excludes: focus/unfocus/agents (Discord-specific), allowlist/bash (text-only scope).
42
32
  */
43
33
  export const OPENCLAW_COMMANDS: BotCommandDef[] = [
44
34
  // ── Status ──
45
- { command: 'help', en: 'Show available commands', ru: 'Показать доступные команды', group: 'status' },
46
- { command: 'commands', en: 'List all slash commands', ru: 'Показать все команды', group: 'status' },
47
- { command: 'status', en: 'Show current status', ru: 'Показать текущий статус', group: 'status' },
48
- { command: 'context', en: 'Explain how context is built', ru: 'Объяснить, как формируется контекст', group: 'status' },
49
- { command: 'whoami', en: 'Show your sender ID', ru: 'Показать ваш ID', group: 'status' },
50
- { command: 'usage', en: 'Usage and cost summary', ru: 'Использование и стоимость', params: 'off | tokens | full | cost', group: 'status' },
35
+ { command: 'help', group: 'status' },
36
+ { command: 'commands', group: 'status' },
37
+ { command: 'status', group: 'status' },
38
+ { command: 'context', group: 'status' },
39
+ { command: 'whoami', group: 'status' },
40
+ { command: 'usage', hasParams: true, group: 'status' },
51
41
 
52
42
  // ── Session ──
53
- { command: 'new', en: 'Start a new session', ru: 'Начать новую сессию', group: 'session' },
54
- { command: 'reset', en: 'Reset the current session', ru: 'Сбросить текущую сессию', group: 'session' },
55
- { command: 'stop', en: 'Stop the current run', ru: 'Остановить текущий запуск', group: 'session' },
56
- { command: 'compact', en: 'Compact the session context', ru: 'Сжать контекст сессии', params: 'instructions', group: 'session' },
57
- { command: 'session', en: 'Manage session settings', ru: 'Настройки сессии', params: 'ttl | ...', group: 'session' },
43
+ { command: 'new', group: 'session' },
44
+ { command: 'reset', group: 'session' },
45
+ { command: 'stop', group: 'session' },
46
+ { command: 'compact', hasParams: true, group: 'session' },
47
+ { command: 'session', hasParams: true, group: 'session' },
58
48
 
59
49
  // ── Options ──
60
- { command: 'model', en: 'Show or set the model', ru: 'Показать или сменить модель', params: 'model name', group: 'options' },
61
- { command: 'models', en: 'List available models', ru: 'Показать модели', params: 'provider', group: 'options' },
62
- { command: 'think', en: 'Set thinking level', ru: 'Уровень размышлений', params: 'off | low | medium | high', group: 'options' },
63
- { command: 'verbose', en: 'Toggle verbose mode', ru: 'Подробный режим', params: 'on | off', group: 'options' },
64
- { command: 'reasoning', en: 'Toggle reasoning visibility', ru: 'Видимость рассуждений', params: 'on | off | stream', group: 'options' },
65
- { command: 'elevated', en: 'Toggle elevated mode', ru: 'Режим с расширенными правами', params: 'on | off | ask | full', group: 'options' },
66
- { command: 'exec', en: 'Set exec defaults', ru: 'Настройки выполнения', params: 'host | security | ask | node', group: 'options' },
67
- { command: 'queue', en: 'Adjust queue settings', ru: 'Настройки очереди', params: 'mode | debounce | cap | drop', group: 'options' },
50
+ { command: 'model', hasParams: true, group: 'options' },
51
+ { command: 'models', hasParams: true, group: 'options' },
52
+ { command: 'think', hasParams: true, group: 'options' },
53
+ { command: 'verbose', hasParams: true, group: 'options' },
54
+ { command: 'reasoning', hasParams: true, group: 'options' },
55
+ { command: 'elevated', hasParams: true, group: 'options' },
56
+ { command: 'exec', hasParams: true, group: 'options' },
57
+ { command: 'queue', hasParams: true, group: 'options' },
68
58
 
69
59
  // ── Management ──
70
- { command: 'config', en: 'Show or set config values', ru: 'Показать или изменить конфигурацию', params: 'show | get | set | unset', group: 'management' },
71
- { command: 'debug', en: 'Set runtime debug overrides', ru: 'Отладочные настройки', params: 'show | reset | set | unset', group: 'management' },
72
- { command: 'approve', en: 'Approve or deny exec requests', ru: 'Одобрить или отклонить запросы', group: 'management' },
73
- { command: 'activation', en: 'Set group activation mode', ru: 'Режим активации в группах', params: 'mention | always', group: 'management' },
74
- { command: 'send', en: 'Set send policy', ru: 'Политика отправки', params: 'on | off | inherit', group: 'management' },
75
- { command: 'subagents', en: 'Manage subagent runs', ru: 'Управление субагентами', group: 'management' },
76
- { command: 'kill', en: 'Kill a running subagent', ru: 'Остановить субагента', params: 'id | all', group: 'management' },
77
- { command: 'steer', en: 'Send guidance to a subagent', ru: 'Направить субагента', params: 'message', group: 'management' },
60
+ { command: 'config', hasParams: true, group: 'management' },
61
+ { command: 'debug', hasParams: true, group: 'management' },
62
+ { command: 'approve', group: 'management' },
63
+ { command: 'activation', hasParams: true, group: 'management' },
64
+ { command: 'send', hasParams: true, group: 'management' },
65
+ { command: 'subagents', group: 'management' },
66
+ { command: 'kill', hasParams: true, group: 'management' },
67
+ { command: 'steer', hasParams: true, group: 'management' },
78
68
 
79
69
  // ── Tools ──
80
- { command: 'skill', en: 'Run a skill by name', ru: 'Запустить навык', params: 'name', group: 'tools' },
81
- { command: 'restart', en: 'Restart OpenClaw', ru: 'Перезапустить OpenClaw', group: 'tools' },
70
+ { command: 'skill', hasParams: true, group: 'tools' },
71
+ { command: 'restart', group: 'tools' },
82
72
 
83
73
  // ── Export ──
84
- { command: 'export-session', en: 'Export session to HTML', ru: 'Экспорт сессии в HTML', group: 'export' },
74
+ { command: 'export-session', group: 'export' },
85
75
  ];
86
76
 
87
77
  export function buildCommandsHelpText(
88
78
  lang: string | undefined,
89
79
  options?: { concise?: boolean },
90
80
  ): string {
91
- const isRu = lang?.toLowerCase().startsWith('ru') ?? false;
92
81
  const concise = options?.concise === true;
93
82
  const defs = concise
94
83
  ? OPENCLAW_COMMANDS.filter((def) => SHORT_HELP_COMMANDS.has(def.command))
95
84
  : OPENCLAW_COMMANDS;
96
- const labels = isRu ? COMMAND_GROUP_LABELS.ru : COMMAND_GROUP_LABELS.en;
85
+ const labels = commandHelpTextLabels(lang);
97
86
  const header = concise
98
- ? (isRu ? '[B]Основные команды[/B]' : '[B]Key commands[/B]')
99
- : (isRu ? '[B]Доступные команды[/B]' : '[B]Available commands[/B]');
87
+ ? `[B]${labels.conciseHeader}[/B]`
88
+ : `[B]${labels.fullHeader}[/B]`;
100
89
  const footer = concise
101
- ? (isRu
102
- ? `[COLOR=${COMMAND_META_COLOR}]Полный список:[/COLOR] ${formatCommandTrigger({
103
- command: 'commands',
104
- })}`
105
- : `[COLOR=${COMMAND_META_COLOR}]Full list:[/COLOR] ${formatCommandTrigger({
106
- command: 'commands',
107
- })}`)
90
+ ? `[COLOR=${COMMAND_META_COLOR}]${labels.fullListLabel}:[/COLOR] ${formatCommandTrigger({
91
+ command: 'commands',
92
+ })}`
108
93
  : '';
109
94
 
110
95
  const sections = COMMAND_GROUP_ORDER
@@ -114,12 +99,12 @@ export function buildCommandsHelpText(
114
99
  return '';
115
100
  }
116
101
 
117
- const lines = groupDefs.map((def) => formatCommandEntry(def, isRu));
102
+ const lines = groupDefs.map((def) => formatCommandEntry(def, lang, labels.paramsLabel));
118
103
  if (concise) {
119
104
  return lines.join('\n');
120
105
  }
121
106
 
122
- return [`[B]${labels[group]}[/B]`, ...lines].join('\n');
107
+ return [`[B]${commandGroupLabel(lang, group)}[/B]`, ...lines].join('\n');
123
108
  })
124
109
  .filter(Boolean);
125
110
 
@@ -150,14 +135,10 @@ export function formatModelsCommandReply(
150
135
  return null;
151
136
  }
152
137
 
153
- const isRu = lang?.toLowerCase().startsWith('ru') ?? false;
154
- const header = isRu ? '[B]Провайдеры[/B]' : '[B]Providers[/B]';
155
- const showModelsLabel = isRu
156
- ? `[COLOR=${COMMAND_META_COLOR}]Модели провайдера:[/COLOR]`
157
- : `[COLOR=${COMMAND_META_COLOR}]Show provider models:[/COLOR]`;
158
- const switchModelLabel = isRu
159
- ? `[COLOR=${COMMAND_META_COLOR}]Сменить модель:[/COLOR]`
160
- : `[COLOR=${COMMAND_META_COLOR}]Switch model:[/COLOR]`;
138
+ const labels = modelsCommandReplyLabels(lang);
139
+ const header = `[B]${labels.header}[/B]`;
140
+ const showModelsLabel = `[COLOR=${COMMAND_META_COLOR}]${labels.showProviderModels}:[/COLOR]`;
141
+ const switchModelLabel = `[COLOR=${COMMAND_META_COLOR}]${labels.switchModel}:[/COLOR]`;
161
142
 
162
143
  const providerLines = providers.map((provider) => {
163
144
  return `• [send=/models ${provider.name}]${provider.name}[/send] [COLOR=${COMMAND_META_COLOR}](${provider.count})[/COLOR]`;
@@ -172,25 +153,38 @@ export function formatModelsCommandReply(
172
153
  ].join('\n');
173
154
  }
174
155
 
175
- function formatCommandEntry(def: BotCommandDef, isRu: boolean): string {
176
- const description = isRu ? def.ru : def.en;
177
- const paramsLabel = isRu ? 'Параметры' : 'Params';
156
+ export function getCommandRegistrationPayload(def: BotCommandDef): {
157
+ title: Record<string, string>;
158
+ params?: Record<string, string>;
159
+ } {
160
+ const title = commandRegistrationTitle(def.command);
161
+ const params = commandRegistrationParams(def.command);
162
+
163
+ return {
164
+ title,
165
+ ...(params ? { params } : {}),
166
+ };
167
+ }
168
+
169
+ function formatCommandEntry(def: BotCommandDef, lang: string | undefined, paramsLabel: string): string {
170
+ const description = commandDescription(lang, def.command);
171
+ const params = commandParams(lang, def.command);
178
172
  const command = formatCommandTrigger(def);
179
173
 
180
- if (!def.params) {
174
+ if (!params) {
181
175
  return `${command} — ${description}`;
182
176
  }
183
177
 
184
178
  return [
185
179
  `${command} — ${description}`,
186
- `[COLOR=${COMMAND_META_COLOR}]${paramsLabel}: ${def.params}[/COLOR]`,
180
+ `[COLOR=${COMMAND_META_COLOR}]${paramsLabel}: ${params}[/COLOR]`,
187
181
  ].join('\n');
188
182
  }
189
183
 
190
- function formatCommandTrigger(def: Pick<BotCommandDef, 'command' | 'params'>): string {
184
+ function formatCommandTrigger(def: Pick<BotCommandDef, 'command' | 'hasParams'>): string {
191
185
  const visibleCommand = `/${def.command}`;
192
186
 
193
- if (!def.params) {
187
+ if (!def.hasParams) {
194
188
  return `[send=/${def.command}]${visibleCommand}[/send]`;
195
189
  }
196
190