iobroker.assistant 1.5.0 → 1.7.0

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 (68) hide show
  1. package/README.md +11 -0
  2. package/admin/custom/.vite/manifest.json +18 -18
  3. package/admin/custom/assets/Components-DGifJGYx.js +2 -0
  4. package/admin/custom/assets/{_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomAssistant__mf_owner__1-fxARoTRS.js → _virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomAssistant__mf_owner__1-Ckpr0MHE.js} +1 -1
  5. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomAssistant__mf_owner__212234797318001__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-CRG5UC4m.js → _virtual_mf___mfe_internal__ConfigCustomAssistant__mf_owner__212234797318001__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-BanHP4Nt.js} +64 -64
  6. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomAssistant__mf_owner__212234797318001__loadShare__shared-CpHul7u9.js → _virtual_mf___mfe_internal__ConfigCustomAssistant__mf_owner__212234797318001__loadShare__shared-BnAYSFON.js} +1 -1
  7. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomAssistant__mf_owner__212234797318001__prebuild___mf_0_iobroker_mf_1_json_mf_2_config__prebuild__-JBzVK-6R.js +122 -0
  8. package/admin/custom/assets/{hostInit-y7sTzQxx.js → hostInit-6JlKIkio.js} +1 -1
  9. package/admin/custom/assets/{lib-DSjTTMgF.js → lib-HGRsyW2B.js} +1 -1
  10. package/admin/custom/assets/{mf-entry-bootstrap-0-b04cc744.js → mf-entry-bootstrap-0-95048639.js} +2 -2
  11. package/admin/custom/assets/{pendingShares-DX6xYXgn.js → pendingShares-BGhHdsEv.js} +1 -1
  12. package/admin/custom/customComponents.js +2 -2
  13. package/admin/custom/i18n/de.json +57 -1
  14. package/admin/custom/i18n/en.json +57 -1
  15. package/admin/custom/i18n/es.json +57 -1
  16. package/admin/custom/i18n/fr.json +57 -1
  17. package/admin/custom/i18n/it.json +57 -1
  18. package/admin/custom/i18n/nl.json +57 -1
  19. package/admin/custom/i18n/pl.json +57 -1
  20. package/admin/custom/i18n/pt.json +57 -1
  21. package/admin/custom/i18n/ru.json +57 -1
  22. package/admin/custom/i18n/uk.json +57 -1
  23. package/admin/custom/i18n/zh-cn.json +57 -1
  24. package/admin/custom/index.html +2 -2
  25. package/admin/custom/mf-manifest.json +1 -1
  26. package/admin/custom/mf-stats.json +1 -1
  27. package/admin/i18n/de.json +23 -3
  28. package/admin/i18n/en.json +23 -3
  29. package/admin/i18n/es.json +23 -3
  30. package/admin/i18n/fr.json +23 -3
  31. package/admin/i18n/it.json +23 -3
  32. package/admin/i18n/nl.json +23 -3
  33. package/admin/i18n/pl.json +23 -3
  34. package/admin/i18n/pt.json +23 -3
  35. package/admin/i18n/ru.json +23 -3
  36. package/admin/i18n/uk.json +23 -3
  37. package/admin/i18n/zh-cn.json +23 -3
  38. package/admin/jsonConfig.json +796 -618
  39. package/build/lib/llm.js +267 -4
  40. package/build/lib/llm.js.map +1 -1
  41. package/build/lib/llmBenchmark.js +139 -0
  42. package/build/lib/llmBenchmark.js.map +1 -0
  43. package/build/lib/llmModels.js +678 -0
  44. package/build/lib/llmModels.js.map +1 -0
  45. package/build/lib/localLlm.js +56 -37
  46. package/build/lib/localLlm.js.map +1 -1
  47. package/build/lib/piAgent.js +33 -0
  48. package/build/lib/piAgent.js.map +1 -1
  49. package/build/lib/systemAi.js +17 -2
  50. package/build/lib/systemAi.js.map +1 -1
  51. package/build/lib/voice/aws.js +9 -2
  52. package/build/lib/voice/aws.js.map +1 -1
  53. package/build/lib/voice/azure.js +6 -2
  54. package/build/lib/voice/azure.js.map +1 -1
  55. package/build/lib/voice/engines.js +34 -2
  56. package/build/lib/voice/engines.js.map +1 -1
  57. package/build/lib/voice/openrouter.js +5 -3
  58. package/build/lib/voice/openrouter.js.map +1 -1
  59. package/build/lib/voice/piper.js +6 -1
  60. package/build/lib/voice/piper.js.map +1 -1
  61. package/build/lib/voice/speechLanguage.js +217 -0
  62. package/build/lib/voice/speechLanguage.js.map +1 -0
  63. package/build/main.js +283 -19
  64. package/build/main.js.map +1 -1
  65. package/io-package.json +30 -27
  66. package/package.json +1 -1
  67. package/admin/custom/assets/Components-BQL6oX_k.js +0 -2
  68. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomAssistant__mf_owner__212234797318001__prebuild___mf_0_iobroker_mf_1_json_mf_2_config__prebuild__-2mXnqS7c.js +0 -122
package/build/main.js CHANGED
@@ -51,6 +51,8 @@ const memory_1 = require("./lib/memory");
51
51
  const weather_1 = require("./lib/weather");
52
52
  const journal_1 = require("./lib/journal");
53
53
  const localLlm_1 = require("./lib/localLlm");
54
+ const llmModels_1 = require("./lib/llmModels");
55
+ const llmBenchmark_1 = require("./lib/llmBenchmark");
54
56
  const credentials_1 = require("./lib/credentials");
55
57
  const context_1 = require("./lib/context");
56
58
  const ask_1 = require("./lib/ask");
@@ -74,6 +76,7 @@ const ttsCache_1 = require("./lib/voice/ttsCache");
74
76
  const captures_1 = require("./lib/voice/captures");
75
77
  const ffmpegStatic_1 = require("./lib/voice/ffmpegStatic");
76
78
  const piAgent_1 = require("./lib/piAgent");
79
+ const speechLanguage_1 = require("./lib/voice/speechLanguage");
77
80
  const installer_1 = require("./lib/installer");
78
81
  const media_1 = require("./lib/media");
79
82
  const systemAi_1 = require("./lib/systemAi");
@@ -141,6 +144,7 @@ const VOICE_FORM_FIELDS = [
141
144
  'awsCredentialId',
142
145
  'awsVoice',
143
146
  'piperVoice',
147
+ 'ttsVoices',
144
148
  ];
145
149
  /** Of those, the protected ones: the browser never gets them, so an empty value there means "keep the saved one" */
146
150
  const VOICE_FORM_SECRETS = [
@@ -337,6 +341,10 @@ class Assistant extends adapter_core_1.Adapter {
337
341
  localLlmLoading = null;
338
342
  /** Last reported local-LLM download percent (to throttle state writes / avoid log spam). */
339
343
  lastLlmPct = -1;
344
+ /** Local models: files, downloads, statistics (created in onReady). */
345
+ models = null;
346
+ /** A benchmark of the active local model is running. */
347
+ benchmarkRunning = false;
340
348
  /** A running "Download ffmpeg" - a second click waits for the same download. */
341
349
  ffmpegDownload = null;
342
350
  /** UDP voice server for satellites (only when voiceEnabled); null otherwise. */
@@ -511,6 +519,7 @@ class Assistant extends adapter_core_1.Adapter {
511
519
  apiKey: this.llm.apiKey,
512
520
  model: this.llm.model,
513
521
  baseUrl: this.llm.baseUrl,
522
+ reasoningEffort: this.llm.reasoningEffort,
514
523
  systemPrompt: cfg.systemPrompt || '',
515
524
  maxTokens: cfg.maxTokens || 1024,
516
525
  tools: tools.map(t => this.journalTool(t)),
@@ -564,6 +573,7 @@ class Assistant extends adapter_core_1.Adapter {
564
573
  : this.piAgent
565
574
  ? `Assistant ready (cloud tier: ${this.piAgent.instance}).`
566
575
  : 'Assistant ready without an LLM provider — answering locally only.');
576
+ this.models = new llmModels_1.ModelManager(this.instanceDataDir(), this.log);
567
577
  if (cfg.useLocalLlm) {
568
578
  void this.ensureLocalLlm(); // background: model load/download must not block onReady
569
579
  }
@@ -749,6 +759,9 @@ class Assistant extends adapter_core_1.Adapter {
749
759
  openrouterTtsModel: (cfg.openrouterTtsModel || '').trim(),
750
760
  decodeAudio: audio => this.decodeAudioBufferToPcm(audio),
751
761
  ttsMaxChars: (0, ttsCache_1.parseTtsMaxChars)(cfg.ttsMaxChars),
762
+ language: String(cfg.voiceLanguage || this.language || ''),
763
+ voicesByLanguage: (0, speechLanguage_1.parseVoiceTable)(cfg.ttsVoices),
764
+ reportedLanguage: text => this.reportedLanguage(text),
752
765
  parakeetInstance: (cfg.parakeetInstance || '').trim().replace(/^system\.adapter\./, ''),
753
766
  sendMessage: (instance, command, message) => this.askInstance(instance, command, message, PARAKEET_TIMEOUT_MS),
754
767
  };
@@ -2647,6 +2660,10 @@ class Assistant extends adapter_core_1.Adapter {
2647
2660
  if (this.installer?.handleMessage(obj.command, obj.message)) {
2648
2661
  return;
2649
2662
  }
2663
+ // Model manager of the local LLM ("Local models" tab).
2664
+ if (await this.handleLocalModelMessage(obj)) {
2665
+ return;
2666
+ }
2650
2667
  // Settings buttons "Install pi-agent" / "Install ai-parakeet".
2651
2668
  if (obj.command === 'installAdapter') {
2652
2669
  const result = await this.installHelperAdapter(obj.message);
@@ -3626,6 +3643,13 @@ class Assistant extends adapter_core_1.Adapter {
3626
3643
  }
3627
3644
  /** Per source: whether its last {@link answer} asked the user something (LLM-signalled via [[LISTEN]]). */
3628
3645
  followUps = new Map();
3646
+ /**
3647
+ * The language the answering tier reported for exactly this answer text (pi-agent ≥ 0.10.1 `language`). The
3648
+ * transports hand the TTS only the text, so the TTS looks the language up by it.
3649
+ */
3650
+ reportedLanguage(text) {
3651
+ return this.piAgent?.languageOf(text) || undefined;
3652
+ }
3629
3653
  /** Per source: when the cloud model last asked back about a script (see {@link cloudOnlyReason}). */
3630
3654
  scriptTopics = new Map();
3631
3655
  /**
@@ -4021,7 +4045,25 @@ class Assistant extends adapter_core_1.Adapter {
4021
4045
  // task) — its `tts` state says it there.
4022
4046
  const satellite = this.requestOrigin.getStore()?.satellite || '';
4023
4047
  const tts = satellite ? `${this.namespace}.satellites.${satellite}.tts` : '';
4024
- return await harness.ask({ text, conversation: source, instructions, language, images, satellite, tts });
4048
+ const answer = await harness.ask({
4049
+ text,
4050
+ conversation: source,
4051
+ instructions,
4052
+ language,
4053
+ images,
4054
+ satellite,
4055
+ tts,
4056
+ });
4057
+ const spokenIn = harness.languageOf(answer);
4058
+ if (spokenIn) {
4059
+ // the voice of the satellite may not speak it: the TTS takes a voice of this language
4060
+ this.journal?.step({
4061
+ stage: 'cloud',
4062
+ title: `${harness.instance} answered in '${spokenIn}'`,
4063
+ data: { language: spokenIn },
4064
+ });
4065
+ }
4066
+ return answer;
4025
4067
  }
4026
4068
  catch (e) {
4027
4069
  if (localFallback) {
@@ -4054,6 +4096,7 @@ class Assistant extends adapter_core_1.Adapter {
4054
4096
  try {
4055
4097
  const ans = await this.localLlm.ask(prompt, timeoutMs);
4056
4098
  const ms = Date.now() - start;
4099
+ this.recordLocalRun(busy ? 'busy' : ans && !(0, localLlm_1.isHandoff)(ans) ? 'answered' : 'handoff', ms);
4057
4100
  if (ans && !(0, localLlm_1.isHandoff)(ans)) {
4058
4101
  this.log.info(`Answered by local LLM (source='${source}').`);
4059
4102
  this.journal?.note({ tier: 'localLlm', detail: name });
@@ -4076,6 +4119,7 @@ class Assistant extends adapter_core_1.Adapter {
4076
4119
  });
4077
4120
  }
4078
4121
  catch (e) {
4122
+ this.recordLocalRun(/timed out/i.test(e.message) ? 'timeout' : 'error', Date.now() - start);
4079
4123
  this.log.info(`Local LLM gave no answer: ${e.message}`);
4080
4124
  this.journal?.step({
4081
4125
  stage: 'localLlm',
@@ -4278,10 +4322,26 @@ class Assistant extends adapter_core_1.Adapter {
4278
4322
  run: args => (this.journal ? this.journal.toolCall(tool.name, args, () => tool.run(args)) : tool.run(args)),
4279
4323
  };
4280
4324
  }
4281
- /** Short name of the local model for the journal ("qwen2.5-1.5b-instruct-q4_k_m"). */
4325
+ /** Short name of the local model for the journal ("Qwen2.5 1.5B (Q4_K_M)"). */
4282
4326
  localLlmName() {
4283
- const url = (this.config.localLlmModelUrl || '').trim() || localLlm_1.DEFAULT_LOCAL_MODEL_URL;
4284
- return (url.split(/[/\\]/).pop() || url).replace(/\?.*$/, '').replace(/\.gguf$/i, '');
4327
+ return (0, llmModels_1.modelDisplayName)(this.activeLocalModel().file);
4328
+ }
4329
+ /**
4330
+ * The local model to load: the one picked in the "Local models" tab, else the file of the legacy
4331
+ * `localLlmModelUrl` (or the built-in default) — that is where older versions stored it.
4332
+ */
4333
+ activeLocalModel() {
4334
+ const chosen = (this.config.localLlmModel || '').trim();
4335
+ if (chosen) {
4336
+ return { file: chosen, url: (0, llmModels_1.presetForFile)(chosen)?.url || '' };
4337
+ }
4338
+ const url = (0, llmModels_1.normalizeModelUrl)(this.config.localLlmModelUrl || '') || localLlm_1.DEFAULT_LOCAL_MODEL_URL;
4339
+ return { file: (0, llmModels_1.modelFileName)(url) || 'model.gguf', url };
4340
+ }
4341
+ /** Directory of the local models (configured or `<data dir>/models`). */
4342
+ localModelDir(override) {
4343
+ const dir = typeof override === 'string' ? override : this.config.localLlmModelDir || '';
4344
+ return (this.models || new llmModels_1.ModelManager(this.instanceDataDir(), this.log)).resolveDir(dir);
4285
4345
  }
4286
4346
  /** Writable per-instance data dir via the adapter-core function (with a fallback for old runtimes). */
4287
4347
  instanceDataDir() {
@@ -4311,6 +4371,18 @@ class Assistant extends adapter_core_1.Adapter {
4311
4371
  },
4312
4372
  native: {},
4313
4373
  });
4374
+ await this.setObjectNotExistsAsync('localLlm.model', {
4375
+ type: 'state',
4376
+ common: {
4377
+ name: 'Active local model',
4378
+ type: 'string',
4379
+ role: 'text',
4380
+ read: true,
4381
+ write: false,
4382
+ def: '',
4383
+ },
4384
+ native: {},
4385
+ });
4314
4386
  await this.setObjectNotExistsAsync('localLlm.progress', {
4315
4387
  type: 'state',
4316
4388
  common: {
@@ -4351,8 +4423,9 @@ class Assistant extends adapter_core_1.Adapter {
4351
4423
  this.log.debug(`local-llm: ${line}`);
4352
4424
  }
4353
4425
  /**
4354
- * Lazily load the local LLM (Tier 1a) when enabled + installed. Runs in the background — the model
4355
- * download can take a while — so callers should not await it on the hot path.
4426
+ * Lazily load the local LLM (Tier 1a) when enabled + installed. Downloads the active model first when
4427
+ * it is missing and its source is known (preset, `models.json`, legacy URL). Runs in the background —
4428
+ * the download can take a while — so callers should not await it on the hot path.
4356
4429
  */
4357
4430
  async ensureLocalLlm() {
4358
4431
  if (this.localLlm) {
@@ -4369,22 +4442,46 @@ class Assistant extends adapter_core_1.Adapter {
4369
4442
  this.log.info('Local LLM is enabled but not installed yet — click "Install local model" in the adapter settings.');
4370
4443
  return;
4371
4444
  }
4372
- const llm = new localLlm_1.LocalLlm({
4373
- dataDir,
4374
- modelUrl: (this.config.localLlmModelUrl || '').trim() || localLlm_1.DEFAULT_LOCAL_MODEL_URL,
4375
- systemPrompt: this.config.systemPrompt || '',
4376
- maxTokens: Math.min(this.config.maxTokens || LOCAL_LLM_MAX_TOKENS, LOCAL_LLM_MAX_TOKENS),
4377
- log: this.log,
4378
- });
4445
+ const models = this.models || (this.models = new llmModels_1.ModelManager(dataDir, this.log));
4446
+ let dir;
4447
+ try {
4448
+ dir = this.localModelDir();
4449
+ }
4450
+ catch (e) {
4451
+ this.setLlmStatus('error');
4452
+ this.log.warn(`Local LLM: ${e.message}`);
4453
+ return;
4454
+ }
4455
+ const active = this.activeLocalModel();
4456
+ const modelPath = models.modelPath(dir, active.file);
4457
+ const preset = (0, llmModels_1.presetForFile)(active.file);
4458
+ this.setStateAsync('localLlm.model', { val: (0, llmModels_1.modelDisplayName)(active.file), ack: true }).catch(() => { });
4379
4459
  this.lastLlmPct = -1;
4380
- this.setLlmStatus('loading');
4381
- this.localLlmLoading = llm
4382
- .load(line => this.onLocalLlmProgress(line))
4383
- .then(() => {
4460
+ this.localLlmLoading = (async () => {
4461
+ if (!fs.existsSync(modelPath)) {
4462
+ const known = (await models.list(dir)).find(m => m.file === active.file);
4463
+ const url = active.url || known?.url || '';
4464
+ if (!url) {
4465
+ throw new Error(`model ${active.file} is not in ${dir} — download it in the "Local models" tab or pick another one`);
4466
+ }
4467
+ this.setLlmStatus('downloading', 0);
4468
+ await this.downloadLocalModel(url, dir);
4469
+ }
4470
+ this.setLlmStatus('loading');
4471
+ const llm = new localLlm_1.LocalLlm({
4472
+ dataDir,
4473
+ modelPath,
4474
+ systemPrompt: this.config.systemPrompt || '',
4475
+ maxTokens: Math.min(this.config.maxTokens || LOCAL_LLM_MAX_TOKENS, LOCAL_LLM_MAX_TOKENS),
4476
+ noThoughts: !!preset?.thinking || /qwen3/i.test(active.file),
4477
+ log: this.log,
4478
+ });
4479
+ await llm.load();
4480
+ await models.recordLoad(active.file, llm.loadMs);
4384
4481
  this.localLlm = llm;
4385
4482
  this.setLlmStatus('ready', 100);
4386
- this.log.info('Local model ready.');
4387
- })
4483
+ this.log.info(`Local model ${(0, llmModels_1.modelDisplayName)(active.file)} ready.`);
4484
+ })()
4388
4485
  .catch(e => {
4389
4486
  this.setLlmStatus('error');
4390
4487
  this.log.warn(`Local LLM load failed: ${e.message}`);
@@ -4394,6 +4491,162 @@ class Assistant extends adapter_core_1.Adapter {
4394
4491
  });
4395
4492
  return this.localLlmLoading;
4396
4493
  }
4494
+ /** Downloads a model through the manager and resolves when it is on disk (progress → `localLlm.*`). */
4495
+ downloadLocalModel(url, dir) {
4496
+ return new Promise((resolve, reject) => {
4497
+ this.models.startDownload(url, dir, (_file, error) => (error ? reject(error) : resolve()), info => {
4498
+ if (info.total) {
4499
+ this.onLocalLlmProgress(`download ${Math.round((100 * info.received) / info.total)}%`);
4500
+ }
4501
+ }).catch(reject);
4502
+ });
4503
+ }
4504
+ /**
4505
+ * sendTo commands of the "Local models" tab. `dir` in a message is the directory from the (maybe unsaved)
4506
+ * form, so the list follows the field before saving. Returns false for other commands.
4507
+ */
4508
+ async handleLocalModelMessage(obj) {
4509
+ const cmds = [
4510
+ 'getLocalModels',
4511
+ 'listLocalModels',
4512
+ 'addLocalModel',
4513
+ 'cancelLocalModelDownload',
4514
+ 'deleteLocalModel',
4515
+ 'resetLocalModelStats',
4516
+ 'benchmarkLocalModel',
4517
+ ];
4518
+ if (!cmds.includes(obj.command)) {
4519
+ return false;
4520
+ }
4521
+ const reply = (result) => {
4522
+ if (obj.callback) {
4523
+ this.sendTo(obj.from, obj.command, result, obj.callback);
4524
+ }
4525
+ };
4526
+ const msg = (obj.message && typeof obj.message === 'object' ? obj.message : {});
4527
+ const models = this.models || (this.models = new llmModels_1.ModelManager(this.instanceDataDir(), this.log));
4528
+ try {
4529
+ const dir = this.localModelDir(msg.dir);
4530
+ const active = (typeof msg.active === 'string' && msg.active) || this.activeLocalModel().file;
4531
+ switch (obj.command) {
4532
+ case 'getLocalModels': {
4533
+ // selectSendTo of the "Active model" field
4534
+ const list = await models.list(dir);
4535
+ const options = list.map(m => ({
4536
+ label: `${m.name}, ${(0, llmModels_1.formatBytes)(m.sizeBytes)}`,
4537
+ value: m.file,
4538
+ }));
4539
+ const chosen = (this.config.localLlmModel || '').trim();
4540
+ if (chosen && !list.some(m => m.file === chosen)) {
4541
+ options.push({ label: `${(0, llmModels_1.modelDisplayName)(chosen)}: not downloaded`, value: chosen });
4542
+ }
4543
+ reply(options);
4544
+ break;
4545
+ }
4546
+ case 'listLocalModels': {
4547
+ const list = await models.list(dir);
4548
+ reply({
4549
+ dir,
4550
+ active,
4551
+ loaded: this.localLlm ? this.activeLocalModel().file : '',
4552
+ engineInstalled: (0, localLlm_1.isLocalLlmInstalled)(this.instanceDataDir()),
4553
+ models: list,
4554
+ totalBytes: list.reduce((sum, m) => sum + m.sizeBytes, 0),
4555
+ disk: await models.disk(dir),
4556
+ downloads: models.listDownloads(),
4557
+ presets: llmModels_1.MODEL_PRESETS,
4558
+ benchmarkRunning: this.benchmarkRunning,
4559
+ language: this.config.voiceLanguage || this.language || 'en',
4560
+ });
4561
+ break;
4562
+ }
4563
+ case 'addLocalModel': {
4564
+ const preset = llmModels_1.MODEL_PRESETS.find(p => p.id === msg.preset);
4565
+ const url = preset ? preset.url : String(msg.url || '');
4566
+ const info = await models.startDownload(url, dir);
4567
+ reply({ result: info });
4568
+ break;
4569
+ }
4570
+ case 'cancelLocalModelDownload':
4571
+ reply({ result: models.cancelDownload(String(msg.file || '')) });
4572
+ break;
4573
+ case 'deleteLocalModel':
4574
+ // the saved active model and the one picked in the unsaved form are both protected
4575
+ if (msg.file === this.activeLocalModel().file && this.localLlm) {
4576
+ throw new Error('the model is loaded; select another model and save first');
4577
+ }
4578
+ await models.delete(dir, String(msg.file || ''), active);
4579
+ reply({ result: true });
4580
+ break;
4581
+ case 'resetLocalModelStats':
4582
+ await models.resetStats(msg.file ? String(msg.file) : undefined);
4583
+ reply({ result: true });
4584
+ break;
4585
+ case 'benchmarkLocalModel':
4586
+ reply({ result: await this.benchmarkLocalModel() });
4587
+ break;
4588
+ }
4589
+ }
4590
+ catch (e) {
4591
+ reply({ error: e.message });
4592
+ }
4593
+ return true;
4594
+ }
4595
+ /**
4596
+ * Runs the benchmark (home questions → hand-off, facts → right answer) on the loaded model. Only the
4597
+ * loaded one: a second model next to it would need its RAM twice — on a Raspberry Pi that is too much.
4598
+ */
4599
+ async benchmarkLocalModel() {
4600
+ const llm = this.localLlm;
4601
+ if (!llm) {
4602
+ throw new Error('no local model is loaded');
4603
+ }
4604
+ if (this.benchmarkRunning) {
4605
+ throw new Error('a benchmark is already running');
4606
+ }
4607
+ this.benchmarkRunning = true;
4608
+ const file = this.activeLocalModel().file;
4609
+ const timeoutMs = Math.max(1, Number(this.config.localLlmTimeoutSec) || LOCAL_LLM_TIMEOUT_SEC) * 1000;
4610
+ const cases = (0, llmBenchmark_1.benchmarkCases)(this.config.voiceLanguage || this.language || 'en');
4611
+ this.log.info(`Benchmark of local model ${(0, llmModels_1.modelDisplayName)(file)}: ${cases.length} questions`);
4612
+ try {
4613
+ const result = await (0, llmBenchmark_1.runBenchmark)(cases, async (question) => {
4614
+ // wait while a real question is answered — the benchmark must not take its place
4615
+ for (let i = 0; i < 600 && llm.running; i++) {
4616
+ await new Promise(r => setTimeout(r, 100));
4617
+ }
4618
+ const answer = await llm.ask(question, timeoutMs);
4619
+ const run = llm.lastRun;
4620
+ return {
4621
+ answer,
4622
+ ms: run?.ms ?? 0,
4623
+ tokens: run?.tokens,
4624
+ genMs: run?.genMs,
4625
+ firstTokenMs: run?.firstTokenMs,
4626
+ };
4627
+ }, (done, total) => this.setLlmStatus('benchmark', Math.round((100 * done) / total)));
4628
+ await this.models.recordBenchmark(file, result);
4629
+ this.log.info(`Benchmark of local model ${(0, llmModels_1.modelDisplayName)(file)}: ${result.correct}/${result.cases} correct, ` +
4630
+ `${result.tokensPerSec} tokens/s, ${result.avgMs} ms per answer`);
4631
+ return result;
4632
+ }
4633
+ finally {
4634
+ this.benchmarkRunning = false;
4635
+ this.setLlmStatus(this.localLlm ? 'ready' : 'error', 100);
4636
+ }
4637
+ }
4638
+ /** Adds one question to the statistics of the active model. */
4639
+ recordLocalRun(outcome, ms) {
4640
+ const run = outcome === 'answered' || outcome === 'handoff' ? this.localLlm?.lastRun : null;
4641
+ void this.models?.recordRun(this.activeLocalModel().file, {
4642
+ outcome,
4643
+ ms,
4644
+ tokens: run?.tokens,
4645
+ genMs: run?.genMs,
4646
+ firstTokenMs: run?.firstTokenMs,
4647
+ promptTokens: run?.promptTokens,
4648
+ });
4649
+ }
4397
4650
  /**
4398
4651
  * Run the rule-based NLU; returns a response string if it produced executable intents, else null.
4399
4652
  * A combined command ("Schalte A an und setze B auf 30 %", "Schalte A und B an") yields several
@@ -7409,6 +7662,10 @@ class Assistant extends adapter_core_1.Adapter {
7409
7662
  const cfg = { ...this.config, sttFallback: '', ttsFallback: '' };
7410
7663
  for (const key of VOICE_FORM_FIELDS) {
7411
7664
  const value = form[key];
7665
+ if (Array.isArray(value)) {
7666
+ cfg[key] = value; // the table "voice per language"
7667
+ continue;
7668
+ }
7412
7669
  if (typeof value !== 'string' || (VOICE_FORM_SECRETS.includes(key) && !value.trim())) {
7413
7670
  continue;
7414
7671
  }
@@ -7632,6 +7889,13 @@ class Assistant extends adapter_core_1.Adapter {
7632
7889
  catch {
7633
7890
  // ignore
7634
7891
  }
7892
+ try {
7893
+ this.models?.cancelAll();
7894
+ await this.models?.flush();
7895
+ }
7896
+ catch {
7897
+ // ignore
7898
+ }
7635
7899
  try {
7636
7900
  await this.localLlm?.dispose();
7637
7901
  }